PluginProbe
FeedWordPress / 2010.0903
FeedWordPress v2010.0903
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
← All changes | feedfinder.class.php +32 -94 trunk2010.0903 View file →
@@ -4,23 +4,17 @@
4 4 * @version 2010.0622
5 5 * @uses SimplePie_Misc
6 6 */
7 7
8 -if ( ! class_exists( 'SimplePie' ) ) :
9 - require_once ABSPATH . WPINC . '/class-simplepie.php';
8 +if (!class_exists('SimplePie')) :
9 + require_once(ABSPATH . WPINC . '/class-simplepie.php');
10 10 endif;
11 -require_once dirname( __FILE__ ) . '/feedwordpresshtml.class.php';
11 +require_once(dirname(__FILE__).'/feedwordpresshtml.class.php');
12 12
13 -/**
14 - * FeedFinder attempts to get all possible RSS/Atom feeds from a site.
15 - *
16 - * @see SimplePie_Misc
17 - */
18 13 class FeedFinder {
19 14 var $uri = NULL;
20 - var $credentials = NULL;
21 15 var $_cache_uri = NULL;
22 -
16 +
23 17 var $verify = FALSE;
24 18 var $fallbacks = 3;
25 19
26 20 var $_response = NULL;
@@ -33,9 +27,9 @@
33 27 'application/rss+xml',
34 28 'text/xml',
35 29 'application/atom+xml',
36 30 'application/x.atom+xml',
37 - 'application/x-atom+xml',
31 + 'application/x-atom+xml'
38 32 );
39 33 var $_feed_markers = array('\\<feed', '\\<rss', 'xmlns="http://purl.org/rss/1.0');
40 34 var $_html_markers = array('\\<html');
41 35 var $_opml_markers = array('\\<opml', '\\<outline');
@@ -41,59 +35,16 @@
41 35 var $_opml_markers = array('\\<opml', '\\<outline');
42 36 var $_obvious_feed_url = array('[./]rss', '[./]rdf', '[./]atom', '[./]feed', '\.xml');
43 37 var $_maybe_feed_url = array ('rss', 'rdf', 'atom', 'feed', 'xml');
44 38
45 - function __construct( $uri = NULL, $params = array(), $fallbacks = 3 ) {
46 - if (is_bool($params)) :
47 - $params = array("verify" => $params);
48 - endif;
49 -
50 - $params = wp_parse_args($params, array(
51 - "verify" => true,
52 - "authentication" => NULL,
53 - "username" => NULL,
54 - "password" => NULL,
55 - ));
56 - $verify = $params['verify'];
57 - $this->credentials = array(
58 - "authentication" => $params['authentication'],
59 - "username" => $params['username'],
60 - "password" => $params['password'],
61 - );
62 -
39 + function FeedFinder ($uri = NULL, $verify = TRUE, $fallbacks = 3) {
63 40 $this->uri = $uri; $this->verify = $verify;
64 41 $this->fallbacks = $fallbacks;
65 42 } /* FeedFinder::FeedFinder () */
66 43
67 - function FeedFinder( $uri = NULL, $params = array(), $fallbacks = 3 ) {
68 - self::__construct( $uri, $params, $fallbacks );
69 - }
70 -
71 - function find ($uri = NULL, $params = array()) {
72 - $params = wp_parse_args($params, array( // Defaults
73 - "authentication" => -1,
74 - "username" => NULL,
75 - "password" => NULL,
76 - ));
77 -
78 - // Equivalents
79 - if ($params['authentication']=='-') :
80 - $params['authentication'] = NULL;
81 - $params['username'] = NULL;
82 - $params['password'] = NULL;
83 - endif;
84 -
85 - // Set/reset
86 - if ($params['authentication'] != -1) :
87 - $this->credentials = array(
88 - "authentication" => $params['authentication'],
89 - "username" => $params['username'],
90 - "password" => $params['password'],
91 - );
92 - endif;
93 -
44 + function find ($uri = NULL) {
94 45 $ret = array ();
95 - if ( !is_null($this->data($uri))) :
46 + if (!is_null($this->data($uri))) :
96 47 if ($this->is_opml($uri)) :
97 48 $href = $this->_opml_rss_uris();
98 49 else :
99 50 if ($this->is_feed($uri)) :
@@ -98,17 +49,17 @@
98 49 else :
99 50 if ($this->is_feed($uri)) :
100 51 $href = array($this->uri);
101 52 else :
102 - // Assume that we have HTML or XHTML (even if we don't, who's
103 - // it gonna hurt?) Autodiscovery is the preferred method.
53 + // Assume that we have HTML or XHTML (even if we don't, who's it gonna hurt?)
54 + // Autodiscovery is the preferred method
104 55 $href = $this->_link_rel_feeds();
105 -
56 +
106 57 // ... but we'll also take the little orange buttons
107 58 if ($this->fallbacks > 0) :
108 59 $href = array_merge($href, $this->_a_href_feeds(TRUE));
109 60 endif;
110 -
61 +
111 62 // If all that failed, look harder
112 63 if ($this->fallbacks > 1) :
113 64 if (count($href) == 0) :
114 65 $href = $this->_a_href_feeds(FALSE);
@@ -113,11 +64,11 @@
113 64 if (count($href) == 0) :
114 65 $href = $this->_a_href_feeds(FALSE);
115 66 endif;
116 67 endif;
117 -
118 - // Our search may turn up duplicate URIs. We only need to do
119 - // any given URI once. Props to Camilo <http://projects.radgeek.com/2008/12/14/feedwordpress-20081214/#comment-20090122160414>
68 +
69 + // Our search may turn up duplicate URIs. We only need to do any given URI once.
70 + // Props to Camilo <http://projects.radgeek.com/2008/12/14/feedwordpress-20081214/#comment-20090122160414>
120 71 $href = array_unique($href);
121 72 endif;
122 73
123 74 // Try some clever URL little tricks before we go
@@ -124,9 +75,9 @@
124 75 if ($this->fallbacks > 2) :
125 76 $href = array_merge($href, $this->_url_manipulation_feeds());
126 77 endif;
127 78 endif;
128 -
79 +
129 80 $href = array_unique($href);
130 81
131 82 // Verify feeds and resolve relative URIs
132 83 foreach ($href as $u) :
@@ -131,9 +82,9 @@
131 82 // Verify feeds and resolve relative URIs
132 83 foreach ($href as $u) :
133 84 $the_uri = SimplePie_Misc::absolutize_url($u, $this->uri);
134 85 if ($this->verify and ($u != $this->uri and $the_uri != $this->uri)) :
135 - $feed = new FeedFinder($the_uri, $this->credentials);
86 + $feed = new FeedFinder($the_uri);
136 87 if ($feed->is_feed()) : $ret[] = $the_uri; endif;
137 88 unset($feed);
138 89 else :
139 90 $ret[] = $the_uri;
@@ -139,15 +90,9 @@
139 90 $ret[] = $the_uri;
140 91 endif;
141 92 endforeach;
142 93 endif;
143 -
144 - if ($this->is_401($uri)) :
145 - $ret = array_merge(array(
146 - new WP_Error('http_request_failed', '401 Not authorized', array("uri" => $this->uri, "status" => 401)),
147 - ), $ret);
148 - endif;
149 -
94 +
150 95 return array_values($ret);
151 96 } /* FeedFinder::find () */
152 97
153 98 function data ($uri = NULL) {
@@ -158,13 +103,13 @@
158 103 function upload_data ($data) {
159 104 $this->uri = 'tag:localhost';
160 105 $this->_data = $data;
161 106 } /* FeedFinder::upload_data () */
162 -
107 +
163 108 function status ($uri = NULL) {
164 109 $this->_get($uri);
165 -
166 - if ( !is_wp_error($this->_response) and isset($this->_response['response']['code'])) :
110 +
111 + if (!is_wp_error($this->_response) and isset($this->_response['response']['code'])) :
167 112 $ret = $this->_response['response']['code'];
168 113 else :
169 114 $ret = NULL;
170 115 endif;
@@ -181,13 +126,9 @@
181 126 endif;
182 127 endif;
183 128 return $message;
184 129 }
185 -
186 - function is_401 ($uri = NULL) {
187 - return (intval($this->status($uri))==401);
188 - } /* FeedFinder::is_401 () */
189 -
130 +
190 131 function is_feed ($uri = NULL) {
191 132 $data = $this->data($uri);
192 133
193 134 return (
@@ -221,14 +162,11 @@
221 162 $headers['Accept'] = 'application/atom+xml application/rdf+xml application/rss+xml application/xml text/html */*';
222 163 $headers['User-Agent'] = 'feedfinder/1.2 (compatible; PHP FeedFinder) +http://projects.radgeek.com/feedwordpress';
223 164
224 165 // Use WordPress API function
225 - $client = wp_remote_request($this->uri, array_merge(
226 - $this->credentials,
227 - array(
166 + $client = wp_remote_request($this->uri, array(
228 167 'headers' => $headers,
229 - 'timeout' => FeedWordPress::fetch_timeout(),
230 - )
168 + 'timeout' => FEEDWORDPRESS_FETCH_TIME_OUT,
231 169 ));
232 170
233 171 $this->_response = $client;
234 172 if (is_wp_error($client)) :
@@ -247,9 +185,9 @@
247 185 function _opml_rss_uris () {
248 186 // Really we should parse the XML and use the structure to
249 187 // return something intelligent to programs that want to use it
250 188 // Oh babe! maybe some day...
251 -
189 +
252 190 $opml = $this->data();
253 191
254 192 $rx = FeedWordPressHTML::attributeRegex('outline', 'xmlUrl');
255 193 if (preg_match_all($rx, $opml, $matches, PREG_SET_ORDER)) :
@@ -303,9 +241,9 @@
303 241 $newQuery = preg_replace('/([?&=])(rss2?|atom|rdf)/i', '$1'.$format, $bits['query']);
304 242 else :
305 243 $newQuery = NULL;
306 244 endif;
307 -
245 +
308 246 if (isset($bits['path']) and (strlen($bits['path']) > 0)) :
309 247 $newPath = preg_replace('!([/.])(rss2?|atom|rdf)!i', '$1'.$format, $bits['path']);
310 248 else :
311 249 $newPath = NULL;
@@ -319,21 +257,21 @@
319 257 $credentials .= ':'.$bits['pass'];
320 258 endif;
321 259 $credentials .= '@';
322 260 endif;
323 -
261 +
324 262 // Variations on a theme
325 263 $newUrl[0] = (''
326 264 .(isset($bits['scheme']) ? $bits['scheme'].':' : '')
327 265 .(isset($bits['host']) ? '//'.$credentials.$bits['host'] : '')
328 - .( !is_null($newPath) ? $newPath : '')
329 - .( !is_null($newQuery) ? '?'.$newQuery : '')
266 + .(!is_null($newPath) ? $newPath : '')
267 + .(!is_null($newQuery) ? '?'.$newQuery : '')
330 268 .(isset($bits['fragment']) ? '#'.$bits['fragment'] : '')
331 269 );
332 270 $newUrl[1] = (''
333 271 .(isset($bits['scheme']) ? $bits['scheme'].':' : '')
334 272 .(isset($bits['host']) ? '//'.$credentials.$bits['host'] : '')
335 - .( !is_null($newPath) ? $newPath : '')
273 + .(!is_null($newPath) ? $newPath : '')
336 274 .(isset($bits['query']) ? '?'.$bits['query'] : '')
337 275 .(isset($bits['fragment']) ? '#'.$bits['fragment'] : '')
338 276 );
339 277 $newUrl[2] = (''
@@ -339,9 +277,9 @@
339 277 $newUrl[2] = (''
340 278 .(isset($bits['scheme']) ? $bits['scheme'].':' : '')
341 279 .(isset($bits['host']) ? '//'.$credentials.$bits['host'] : '')
342 280 .(isset($bits['path']) ? $bits['path'] : '')
343 - .( !is_null($newQuery) ? '?'.$newQuery : '')
281 + .(!is_null($newQuery) ? '?'.$newQuery : '')
344 282 .(isset($bits['fragment']) ? '#'.$bits['fragment'] : '')
345 283 );
346 284 $href = array_merge($href, $newUrl);
347 285 endforeach;
@@ -349,9 +287,9 @@
349 287 } /* FeedFinder::_url_manipulation_feeds () */
350 288
351 289 function _tags ($tag) {
352 290 $html = $this->data();
353 -
291 +
354 292 // search through the HTML, save all <link> tags
355 293 // and store each link's attributes in an associative array
356 294 preg_match_all('/<'.$tag.'\s+(.*?)\s*\/?>/si', $html, $matches);
357 295 $links = $matches[1];