author | Anthony Ly <anthonyly.com@gmail.com> |
Wed, 19 Dec 2012 17:46:52 -0800 | |
changeset 204 | 09a1c134465b |
parent 194 | 32102edaa81b |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
||
3 |
if ( !class_exists('SimplePie') ) |
|
4 |
require_once (ABSPATH . WPINC . '/class-simplepie.php'); |
|
5 |
||
6 |
class WP_Feed_Cache extends SimplePie_Cache { |
|
7 |
/** |
|
8 |
* Create a new SimplePie_Cache object |
|
9 |
* |
|
10 |
* @static |
|
11 |
* @access public |
|
12 |
*/ |
|
13 |
function create($location, $filename, $extension) { |
|
14 |
return new WP_Feed_Cache_Transient($location, $filename, $extension); |
|
15 |
} |
|
16 |
} |
|
17 |
||
18 |
class WP_Feed_Cache_Transient { |
|
19 |
var $name; |
|
20 |
var $mod_name; |
|
21 |
var $lifetime = 43200; //Default lifetime in cache of 12 hours |
|
22 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
23 |
function __construct($location, $filename, $extension) { |
136 | 24 |
$this->name = 'feed_' . $filename; |
25 |
$this->mod_name = 'feed_mod_' . $filename; |
|
26 |
$this->lifetime = apply_filters('wp_feed_cache_transient_lifetime', $this->lifetime, $filename); |
|
27 |
} |
|
28 |
||
29 |
function save($data) { |
|
30 |
if ( is_a($data, 'SimplePie') ) |
|
31 |
$data = $data->data; |
|
32 |
||
33 |
set_transient($this->name, $data, $this->lifetime); |
|
34 |
set_transient($this->mod_name, time(), $this->lifetime); |
|
35 |
return true; |
|
36 |
} |
|
37 |
||
38 |
function load() { |
|
39 |
return get_transient($this->name); |
|
40 |
} |
|
41 |
||
42 |
function mtime() { |
|
43 |
return get_transient($this->mod_name); |
|
44 |
} |
|
45 |
||
46 |
function touch() { |
|
47 |
return set_transient($this->mod_name, time(), $this->lifetime); |
|
48 |
} |
|
49 |
||
50 |
function unlink() { |
|
51 |
delete_transient($this->name); |
|
52 |
delete_transient($this->mod_name); |
|
53 |
return true; |
|
54 |
} |
|
55 |
} |
|
56 |
||
57 |
class WP_SimplePie_File extends SimplePie_File { |
|
58 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
59 |
function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) { |
136 | 60 |
$this->url = $url; |
61 |
$this->timeout = $timeout; |
|
62 |
$this->redirects = $redirects; |
|
63 |
$this->headers = $headers; |
|
64 |
$this->useragent = $useragent; |
|
65 |
||
66 |
$this->method = SIMPLEPIE_FILE_SOURCE_REMOTE; |
|
67 |
||
68 |
if ( preg_match('/^http(s)?:\/\//i', $url) ) { |
|
69 |
$args = array( 'timeout' => $this->timeout, 'redirection' => $this->redirects); |
|
70 |
||
71 |
if ( !empty($this->headers) ) |
|
72 |
$args['headers'] = $this->headers; |
|
73 |
||
74 |
if ( SIMPLEPIE_USERAGENT != $this->useragent ) //Use default WP user agent unless custom has been specified |
|
75 |
$args['user-agent'] = $this->useragent; |
|
76 |
||
77 |
$res = wp_remote_request($url, $args); |
|
78 |
||
79 |
if ( is_wp_error($res) ) { |
|
80 |
$this->error = 'WP HTTP Error: ' . $res->get_error_message(); |
|
81 |
$this->success = false; |
|
82 |
} else { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
83 |
$this->headers = wp_remote_retrieve_headers( $res ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
84 |
$this->body = wp_remote_retrieve_body( $res ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
85 |
$this->status_code = wp_remote_retrieve_response_code( $res ); |
136 | 86 |
} |
87 |
} else { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
88 |
if ( ! file_exists($url) || ( ! $this->body = file_get_contents($url) ) ) { |
136 | 89 |
$this->error = 'file_get_contents could not read the file'; |
90 |
$this->success = false; |
|
91 |
} |
|
92 |
} |
|
93 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
94 |
} |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
95 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
96 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
97 |
* WordPress SimplePie Sanitization Class |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
98 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
99 |
* Extension of the SimplePie_Sanitize class to use KSES, because |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
100 |
* we cannot universally count on DOMDocument being available |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
101 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
102 |
* @package WordPress |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
103 |
* @since 3.5.0 |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
104 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
105 |
class WP_SimplePie_Sanitize_KSES extends SimplePie_Sanitize { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
106 |
public function sanitize( $data, $type, $base = '' ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
107 |
$data = trim( $data ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
108 |
if ( $type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
109 |
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)) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
110 |
$type |= SIMPLEPIE_CONSTRUCT_HTML; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
111 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
112 |
else { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
113 |
$type |= SIMPLEPIE_CONSTRUCT_TEXT; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
114 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
115 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
116 |
if ( $type & SIMPLEPIE_CONSTRUCT_BASE64 ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
117 |
$data = base64_decode( $data ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
118 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
119 |
if ( $type & ( SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
120 |
$data = wp_kses_post( $data ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
121 |
if ( $this->output_encoding !== 'UTF-8' ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
122 |
$data = $this->registry->call( 'Misc', 'change_encoding', array( $data, 'UTF-8', $this->output_encoding ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
123 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
124 |
return $data; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
125 |
} else { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
126 |
return parent::sanitize( $data, $type, $base ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
127 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
128 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
129 |
} |