3 if ( ! class_exists( 'SimplePie', false ) )
4 require_once( ABSPATH . WPINC . '/class-simplepie.php' );
6 class WP_Feed_Cache extends SimplePie_Cache {
8 * Create a new SimplePie_Cache object
13 * @param string $location URL location (scheme is used to determine handler).
14 * @param string $filename Unique identifier for cache object.
15 * @param string $extension 'spi' or 'spc'.
16 * @return WP_Feed_Cache_Transient Feed cache handler object that uses transients.
18 public function create($location, $filename, $extension) {
19 return new WP_Feed_Cache_Transient($location, $filename, $extension);
23 class WP_Feed_Cache_Transient {
26 public $lifetime = 43200; //Default lifetime in cache of 12 hours
31 * @param string $location URL location (scheme is used to determine handler).
32 * @param string $filename Unique identifier for cache object.
33 * @param string $extension 'spi' or 'spc'.
35 public function __construct($location, $filename, $extension) {
36 $this->name = 'feed_' . $filename;
37 $this->mod_name = 'feed_mod_' . $filename;
39 $lifetime = $this->lifetime;
41 * Filter the transient lifetime of the feed cache.
45 * @param int $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours).
46 * @param string $filename Unique identifier for the cache object.
48 $this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename);
54 * @param SimplePie $data Data to save.
55 * @return true Always true.
57 public function save($data) {
58 if ( $data instanceof SimplePie ) {
62 set_transient($this->name, $data, $this->lifetime);
63 set_transient($this->mod_name, time(), $this->lifetime);
70 public function load() {
71 return get_transient($this->name);
77 public function mtime() {
78 return get_transient($this->mod_name);
84 public function touch() {
85 return set_transient($this->mod_name, time(), $this->lifetime);
91 public function unlink() {
92 delete_transient($this->name);
93 delete_transient($this->mod_name);
98 class WP_SimplePie_File extends SimplePie_File {
100 public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) {
102 $this->timeout = $timeout;
103 $this->redirects = $redirects;
104 $this->headers = $headers;
105 $this->useragent = $useragent;
107 $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
109 if ( preg_match('/^http(s)?:\/\//i', $url) ) {
111 'timeout' => $this->timeout,
112 'redirection' => $this->redirects,
115 if ( !empty($this->headers) )
116 $args['headers'] = $this->headers;
118 if ( SIMPLEPIE_USERAGENT != $this->useragent ) //Use default WP user agent unless custom has been specified
119 $args['user-agent'] = $this->useragent;
121 $res = wp_safe_remote_request($url, $args);
123 if ( is_wp_error($res) ) {
124 $this->error = 'WP HTTP Error: ' . $res->get_error_message();
125 $this->success = false;
127 $this->headers = wp_remote_retrieve_headers( $res );
128 $this->body = wp_remote_retrieve_body( $res );
129 $this->status_code = wp_remote_retrieve_response_code( $res );
133 $this->success = false;
139 * WordPress SimplePie Sanitization Class
141 * Extension of the SimplePie_Sanitize class to use KSES, because
142 * we cannot universally count on DOMDocument being available
147 class WP_SimplePie_Sanitize_KSES extends SimplePie_Sanitize {
148 public function sanitize( $data, $type, $base = '' ) {
149 $data = trim( $data );
150 if ( $type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML ) {
151 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)) {
152 $type |= SIMPLEPIE_CONSTRUCT_HTML;
155 $type |= SIMPLEPIE_CONSTRUCT_TEXT;
158 if ( $type & SIMPLEPIE_CONSTRUCT_BASE64 ) {
159 $data = base64_decode( $data );
161 if ( $type & ( SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML ) ) {
162 $data = wp_kses_post( $data );
163 if ( $this->output_encoding !== 'UTF-8' ) {
164 $data = $this->registry->call( 'Misc', 'change_encoding', array( $data, 'UTF-8', $this->output_encoding ) );
168 return parent::sanitize( $data, $type, $base );