Make WordPress Core

Ticket #2864: rss.3.php

File rss.3.php, 1.5 KB (added by link92, 17 years ago)

Fix breach of WP coding standards in rss.2.php

Line 
1<?php
2
3require_once('simplepie.inc');
4
5class 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
51function 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?>