PluginProbe
FeedWordPress / 2013.0503
FeedWordPress v2013.0503
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 +30 -39 trunk2013.0503 View file →
@@ -4,23 +4,18 @@
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 15 var $credentials = NULL;
21 16 var $_cache_uri = NULL;
22 -
17 +
23 18 var $verify = FALSE;
24 19 var $fallbacks = 3;
25 20
26 21 var $_response = NULL;
@@ -33,9 +28,9 @@
33 28 'application/rss+xml',
34 29 'text/xml',
35 30 'application/atom+xml',
36 31 'application/x.atom+xml',
37 - 'application/x-atom+xml',
32 + 'application/x-atom+xml'
38 33 );
39 34 var $_feed_markers = array('\\<feed', '\\<rss', 'xmlns="http://purl.org/rss/1.0');
40 35 var $_html_markers = array('\\<html');
41 36 var $_opml_markers = array('\\<opml', '\\<outline');
@@ -41,13 +36,13 @@
41 36 var $_opml_markers = array('\\<opml', '\\<outline');
42 37 var $_obvious_feed_url = array('[./]rss', '[./]rdf', '[./]atom', '[./]feed', '\.xml');
43 38 var $_maybe_feed_url = array ('rss', 'rdf', 'atom', 'feed', 'xml');
44 39
45 - function __construct( $uri = NULL, $params = array(), $fallbacks = 3 ) {
40 + function FeedFinder ($uri = NULL, $params = array(), $fallbacks = 3) {
46 41 if (is_bool($params)) :
47 42 $params = array("verify" => $params);
48 43 endif;
49 -
44 +
50 45 $params = wp_parse_args($params, array(
51 46 "verify" => true,
52 47 "authentication" => NULL,
53 48 "username" => NULL,
@@ -58,17 +53,13 @@
58 53 "authentication" => $params['authentication'],
59 54 "username" => $params['username'],
60 55 "password" => $params['password'],
61 56 );
62 -
57 +
63 58 $this->uri = $uri; $this->verify = $verify;
64 59 $this->fallbacks = $fallbacks;
65 60 } /* FeedFinder::FeedFinder () */
66 61
67 - function FeedFinder( $uri = NULL, $params = array(), $fallbacks = 3 ) {
68 - self::__construct( $uri, $params, $fallbacks );
69 - }
70 -
71 62 function find ($uri = NULL, $params = array()) {
72 63 $params = wp_parse_args($params, array( // Defaults
73 64 "authentication" => -1,
74 65 "username" => NULL,
@@ -73,9 +64,9 @@
73 64 "authentication" => -1,
74 65 "username" => NULL,
75 66 "password" => NULL,
76 67 ));
77 -
68 +
78 69 // Equivalents
79 70 if ($params['authentication']=='-') :
80 71 $params['authentication'] = NULL;
81 72 $params['username'] = NULL;
@@ -80,9 +71,9 @@
80 71 $params['authentication'] = NULL;
81 72 $params['username'] = NULL;
82 73 $params['password'] = NULL;
83 74 endif;
84 -
75 +
85 76 // Set/reset
86 77 if ($params['authentication'] != -1) :
87 78 $this->credentials = array(
88 79 "authentication" => $params['authentication'],
@@ -89,11 +80,11 @@
89 80 "username" => $params['username'],
90 81 "password" => $params['password'],
91 82 );
92 83 endif;
93 -
84 +
94 85 $ret = array ();
95 - if ( !is_null($this->data($uri))) :
86 + if (!is_null($this->data($uri))) :
96 87 if ($this->is_opml($uri)) :
97 88 $href = $this->_opml_rss_uris();
98 89 else :
99 90 if ($this->is_feed($uri)) :
@@ -101,14 +92,14 @@
101 92 else :
102 93 // Assume that we have HTML or XHTML (even if we don't, who's
103 94 // it gonna hurt?) Autodiscovery is the preferred method.
104 95 $href = $this->_link_rel_feeds();
105 -
96 +
106 97 // ... but we'll also take the little orange buttons
107 98 if ($this->fallbacks > 0) :
108 99 $href = array_merge($href, $this->_a_href_feeds(TRUE));
109 100 endif;
110 -
101 +
111 102 // If all that failed, look harder
112 103 if ($this->fallbacks > 1) :
113 104 if (count($href) == 0) :
114 105 $href = $this->_a_href_feeds(FALSE);
@@ -113,9 +104,9 @@
113 104 if (count($href) == 0) :
114 105 $href = $this->_a_href_feeds(FALSE);
115 106 endif;
116 107 endif;
117 -
108 +
118 109 // Our search may turn up duplicate URIs. We only need to do
119 110 // any given URI once. Props to Camilo <http://projects.radgeek.com/2008/12/14/feedwordpress-20081214/#comment-20090122160414>
120 111 $href = array_unique($href);
121 112 endif;
@@ -124,9 +115,9 @@
124 115 if ($this->fallbacks > 2) :
125 116 $href = array_merge($href, $this->_url_manipulation_feeds());
126 117 endif;
127 118 endif;
128 -
119 +
129 120 $href = array_unique($href);
130 121
131 122 // Verify feeds and resolve relative URIs
132 123 foreach ($href as $u) :
@@ -145,9 +136,9 @@
145 136 $ret = array_merge(array(
146 137 new WP_Error('http_request_failed', '401 Not authorized', array("uri" => $this->uri, "status" => 401)),
147 138 ), $ret);
148 139 endif;
149 -
140 +
150 141 return array_values($ret);
151 142 } /* FeedFinder::find () */
152 143
153 144 function data ($uri = NULL) {
@@ -158,13 +149,13 @@
158 149 function upload_data ($data) {
159 150 $this->uri = 'tag:localhost';
160 151 $this->_data = $data;
161 152 } /* FeedFinder::upload_data () */
162 -
153 +
163 154 function status ($uri = NULL) {
164 155 $this->_get($uri);
165 -
166 - if ( !is_wp_error($this->_response) and isset($this->_response['response']['code'])) :
156 +
157 + if (!is_wp_error($this->_response) and isset($this->_response['response']['code'])) :
167 158 $ret = $this->_response['response']['code'];
168 159 else :
169 160 $ret = NULL;
170 161 endif;
@@ -181,13 +172,13 @@
181 172 endif;
182 173 endif;
183 174 return $message;
184 175 }
185 -
176 +
186 177 function is_401 ($uri = NULL) {
187 178 return (intval($this->status($uri))==401);
188 179 } /* FeedFinder::is_401 () */
189 -
180 +
190 181 function is_feed ($uri = NULL) {
191 182 $data = $this->data($uri);
192 183
193 184 return (
@@ -247,9 +238,9 @@
247 238 function _opml_rss_uris () {
248 239 // Really we should parse the XML and use the structure to
249 240 // return something intelligent to programs that want to use it
250 241 // Oh babe! maybe some day...
251 -
242 +
252 243 $opml = $this->data();
253 244
254 245 $rx = FeedWordPressHTML::attributeRegex('outline', 'xmlUrl');
255 246 if (preg_match_all($rx, $opml, $matches, PREG_SET_ORDER)) :
@@ -303,9 +294,9 @@
303 294 $newQuery = preg_replace('/([?&=])(rss2?|atom|rdf)/i', '$1'.$format, $bits['query']);
304 295 else :
305 296 $newQuery = NULL;
306 297 endif;
307 -
298 +
308 299 if (isset($bits['path']) and (strlen($bits['path']) > 0)) :
309 300 $newPath = preg_replace('!([/.])(rss2?|atom|rdf)!i', '$1'.$format, $bits['path']);
310 301 else :
311 302 $newPath = NULL;
@@ -319,21 +310,21 @@
319 310 $credentials .= ':'.$bits['pass'];
320 311 endif;
321 312 $credentials .= '@';
322 313 endif;
323 -
314 +
324 315 // Variations on a theme
325 316 $newUrl[0] = (''
326 317 .(isset($bits['scheme']) ? $bits['scheme'].':' : '')
327 318 .(isset($bits['host']) ? '//'.$credentials.$bits['host'] : '')
328 - .( !is_null($newPath) ? $newPath : '')
329 - .( !is_null($newQuery) ? '?'.$newQuery : '')
319 + .(!is_null($newPath) ? $newPath : '')
320 + .(!is_null($newQuery) ? '?'.$newQuery : '')
330 321 .(isset($bits['fragment']) ? '#'.$bits['fragment'] : '')
331 322 );
332 323 $newUrl[1] = (''
333 324 .(isset($bits['scheme']) ? $bits['scheme'].':' : '')
334 325 .(isset($bits['host']) ? '//'.$credentials.$bits['host'] : '')
335 - .( !is_null($newPath) ? $newPath : '')
326 + .(!is_null($newPath) ? $newPath : '')
336 327 .(isset($bits['query']) ? '?'.$bits['query'] : '')
337 328 .(isset($bits['fragment']) ? '#'.$bits['fragment'] : '')
338 329 );
339 330 $newUrl[2] = (''
@@ -339,9 +330,9 @@
339 330 $newUrl[2] = (''
340 331 .(isset($bits['scheme']) ? $bits['scheme'].':' : '')
341 332 .(isset($bits['host']) ? '//'.$credentials.$bits['host'] : '')
342 333 .(isset($bits['path']) ? $bits['path'] : '')
343 - .( !is_null($newQuery) ? '?'.$newQuery : '')
334 + .(!is_null($newQuery) ? '?'.$newQuery : '')
344 335 .(isset($bits['fragment']) ? '#'.$bits['fragment'] : '')
345 336 );
346 337 $href = array_merge($href, $newUrl);
347 338 endforeach;
@@ -349,9 +340,9 @@
349 340 } /* FeedFinder::_url_manipulation_feeds () */
350 341
351 342 function _tags ($tag) {
352 343 $html = $this->data();
353 -
344 +
354 345 // search through the HTML, save all <link> tags
355 346 // and store each link's attributes in an associative array
356 347 preg_match_all('/<'.$tag.'\s+(.*?)\s*\/?>/si', $html, $matches);
357 348 $links = $matches[1];