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