Make WordPress Core

Ticket #2864: rss.2.php

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

SimplePie-clad wp-includes/rss.php

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