3 if ( !class_exists('SimplePie') )
4 require_once (ABSPATH . WPINC . '/class-simplepie.php');
6 class WP_Feed_Cache extends SimplePie_Cache {
8 * Create a new SimplePie_Cache object
13 function create($location, $filename, $extension) {
14 return new WP_Feed_Cache_Transient($location, $filename, $extension);
18 class WP_Feed_Cache_Transient {
21 var $lifetime = 43200; //Default lifetime in cache of 12 hours
23 function __construct($location, $filename, $extension) {
24 $this->name = 'feed_' . $filename;
25 $this->mod_name = 'feed_mod_' . $filename;
26 $this->lifetime = apply_filters('wp_feed_cache_transient_lifetime', $this->lifetime, $filename);
29 function save($data) {
30 if ( is_a($data, 'SimplePie') )
33 set_transient($this->name, $data, $this->lifetime);
34 set_transient($this->mod_name, time(), $this->lifetime);
39 return get_transient($this->name);
43 return get_transient($this->mod_name);
47 return set_transient($this->mod_name, time(), $this->lifetime);
51 delete_transient($this->name);
52 delete_transient($this->mod_name);
57 class WP_SimplePie_File extends SimplePie_File {
59 function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) {
61 $this->timeout = $timeout;
62 $this->redirects = $redirects;
63 $this->headers = $headers;
64 $this->useragent = $useragent;
66 $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
68 if ( preg_match('/^http(s)?:\/\//i', $url) ) {
70 'timeout' => $this->timeout,
71 'redirection' => $this->redirects,
72 'reject_unsafe_urls' => true,
75 if ( !empty($this->headers) )
76 $args['headers'] = $this->headers;
78 if ( SIMPLEPIE_USERAGENT != $this->useragent ) //Use default WP user agent unless custom has been specified
79 $args['user-agent'] = $this->useragent;
81 $res = wp_remote_request($url, $args);
83 if ( is_wp_error($res) ) {
84 $this->error = 'WP HTTP Error: ' . $res->get_error_message();
85 $this->success = false;
87 $this->headers = wp_remote_retrieve_headers( $res );
88 $this->body = wp_remote_retrieve_body( $res );
89 $this->status_code = wp_remote_retrieve_response_code( $res );
93 $this->success = false;
99 * WordPress SimplePie Sanitization Class
101 * Extension of the SimplePie_Sanitize class to use KSES, because
102 * we cannot universally count on DOMDocument being available
107 class WP_SimplePie_Sanitize_KSES extends SimplePie_Sanitize {
108 public function sanitize( $data, $type, $base = '' ) {
109 $data = trim( $data );
110 if ( $type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML ) {
111 if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data)) {
112 $type |= SIMPLEPIE_CONSTRUCT_HTML;
115 $type |= SIMPLEPIE_CONSTRUCT_TEXT;
118 if ( $type & SIMPLEPIE_CONSTRUCT_BASE64 ) {
119 $data = base64_decode( $data );
121 if ( $type & ( SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML ) ) {
122 $data = wp_kses_post( $data );
123 if ( $this->output_encoding !== 'UTF-8' ) {
124 $data = $this->registry->call( 'Misc', 'change_encoding', array( $data, 'UTF-8', $this->output_encoding ) );
128 return parent::sanitize( $data, $type, $base );