| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | require_once('simplepie.inc');
|
|---|
| 4 |
|
|---|
| 5 | class WordPress_SimplePie_Cache extends SimplePie_Cache {
|
|---|
| 6 | var $name;
|
|---|
| 7 |
|
|---|
| 8 | function WordPress_SimplePie_Cache($location, $filename, $extension) {
|
|---|
| 9 | $this->name = rawurlencode($filename);
|
|---|
| 10 | }
|
|---|
| 11 |
|
|---|
| 12 | function save($data) {
|
|---|
| 13 | $cache_option = "rss_$this->name";
|
|---|
| 14 | $cache_timestamp = $cache_option . '_ts';
|
|---|
| 15 | if ( false !== get_option($cache_option) ) {
|
|---|
| 16 | update_option($cache_option, $data);
|
|---|
| 17 | } else {
|
|---|
| 18 | add_option($cache_option, $data, '', 'no');
|
|---|
| 19 | }
|
|---|
| 20 | if ( false !== get_option($cache_timestamp) ) {
|
|---|
| 21 | update_option($cache_timestamp, time());
|
|---|
| 22 | } else {
|
|---|
| 23 | add_option($cache_timestamp, time(), '', 'no');
|
|---|
| 24 | }
|
|---|
| 25 | return true;
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | function load() {
|
|---|
| 29 | return get_option("rss_$this->name");
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | function mtime() {
|
|---|
| 33 | return get_option('rss_' . $this->name . '_ts');
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | function touch() {
|
|---|
| 37 | $cache_timestamp = 'rss_' . $this->name . '_ts';
|
|---|
| 38 | if ( false !== get_option($cache_timestamp) ) {
|
|---|
| 39 | update_option($cache_timestamp, time());
|
|---|
| 40 | } else {
|
|---|
| 41 | add_option($cache_timestamp, time(), '', 'no');
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | function unlink() {
|
|---|
| 46 | delete_option("rss_$this->name");
|
|---|
| 47 | delete_option('rss_' . $this->name . '_ts');
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | function fetch_simplepie ($url) {
|
|---|
| 52 | $feed = new SimplePie;
|
|---|
| 53 | $feed->feed_url($url);
|
|---|
| 54 | $feed->set_cache_class('WordPress_SimplePie_Cache');
|
|---|
| 55 | $feed->strip_htmltags(false);
|
|---|
| 56 | $feed->strip_attributes(false);
|
|---|
| 57 | $feed->output_encoding(get_option('blog_charset'));
|
|---|
| 58 | $feed->cache_max_minutes(720);
|
|---|
| 59 | $feed->set_useragent('WordPress/' . $wp_version);
|
|---|
| 60 | if ($feed->init()) {
|
|---|
| 61 | return $feed;
|
|---|
| 62 | } else {
|
|---|
| 63 | return false;
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | ?>
|
|---|