3 if ( !class_exists('SimplePie') )
4 require_once (ABSPATH . WPINC . '/class-simplepie.php');
6 class WP_Feed_Cache extends SimplePie_Cache {
8 * Don't call the constructor. Please.
12 function WP_Feed_Cache() {
13 trigger_error('Please call SimplePie_Cache::create() instead of the constructor', E_USER_ERROR);
17 * Create a new SimplePie_Cache object
22 function create($location, $filename, $extension) {
23 return new WP_Feed_Cache_Transient($location, $filename, $extension);
27 class WP_Feed_Cache_Transient {
30 var $lifetime = 43200; //Default lifetime in cache of 12 hours
32 function WP_Feed_Cache_Transient($location, $filename, $extension) {
33 $this->name = 'feed_' . $filename;
34 $this->mod_name = 'feed_mod_' . $filename;
35 $this->lifetime = apply_filters('wp_feed_cache_transient_lifetime', $this->lifetime, $filename);
38 function save($data) {
39 if ( is_a($data, 'SimplePie') )
42 set_transient($this->name, $data, $this->lifetime);
43 set_transient($this->mod_name, time(), $this->lifetime);
48 return get_transient($this->name);
52 return get_transient($this->mod_name);
56 return set_transient($this->mod_name, time(), $this->lifetime);
60 delete_transient($this->name);
61 delete_transient($this->mod_name);
66 class WP_SimplePie_File extends SimplePie_File {
68 function WP_SimplePie_File($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) {
70 $this->timeout = $timeout;
71 $this->redirects = $redirects;
72 $this->headers = $headers;
73 $this->useragent = $useragent;
75 $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
77 if ( preg_match('/^http(s)?:\/\//i', $url) ) {
78 $args = array( 'timeout' => $this->timeout, 'redirection' => $this->redirects);
80 if ( !empty($this->headers) )
81 $args['headers'] = $this->headers;
83 if ( SIMPLEPIE_USERAGENT != $this->useragent ) //Use default WP user agent unless custom has been specified
84 $args['user-agent'] = $this->useragent;
86 $res = wp_remote_request($url, $args);
88 if ( is_wp_error($res) ) {
89 $this->error = 'WP HTTP Error: ' . $res->get_error_message();
90 $this->success = false;
92 $this->headers = $res['headers'];
93 $this->body = $res['body'];
94 $this->status_code = $res['response']['code'];
97 if ( ! $this->body = file_get_contents($url) ) {
98 $this->error = 'file_get_contents could not read the file';
99 $this->success = false;