Changeset 47733 for trunk/src/wp-includes/SimplePie/Locator.php
- Timestamp:
- 05/01/2020 02:24:42 PM (6 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/SimplePie/Locator.php (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/SimplePie/Locator.php
r22798 r47733 6 6 * Takes the hard work out of managing a complete RSS/Atom solution. 7 7 * 8 * Copyright (c) 2004-201 2, Ryan Parman, GeoffreySneddon, Ryan McCue, and contributors8 * Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 9 * All rights reserved. 10 10 * … … 34 34 * 35 35 * @package SimplePie 36 * @version 1.3.1 37 * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue 36 * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue 38 37 * @author Ryan Parman 39 * @author GeoffreySneddon38 * @author Sam Sneddon 40 39 * @author Ryan McCue 41 40 * @link http://simplepie.org/ SimplePie … … 64 63 var $checked_feeds = 0; 65 64 var $max_checked_feeds = 10; 65 var $force_fsockopen = false; 66 var $curl_options = array(); 66 67 protected $registry; 67 68 68 public function __construct(SimplePie_File $file, $timeout = 10, $useragent = null, $max_checked_feeds = 10 )69 public function __construct(SimplePie_File $file, $timeout = 10, $useragent = null, $max_checked_feeds = 10, $force_fsockopen = false, $curl_options = array()) 69 70 { 70 71 $this->file = $file; … … 72 73 $this->timeout = $timeout; 73 74 $this->max_checked_feeds = $max_checked_feeds; 75 $this->force_fsockopen = $force_fsockopen; 76 $this->curl_options = $curl_options; 74 77 75 78 if (class_exists('DOMDocument')) … … 122 125 if ($type & SIMPLEPIE_LOCATOR_LOCAL_EXTENSION && $working = $this->extension($this->local)) 123 126 { 124 return $working ;127 return $working[0]; 125 128 } 126 129 127 130 if ($type & SIMPLEPIE_LOCATOR_LOCAL_BODY && $working = $this->body($this->local)) 128 131 { 129 return $working ;132 return $working[0]; 130 133 } 131 134 132 135 if ($type & SIMPLEPIE_LOCATOR_REMOTE_EXTENSION && $working = $this->extension($this->elsewhere)) 133 136 { 134 return $working ;137 return $working[0]; 135 138 } 136 139 137 140 if ($type & SIMPLEPIE_LOCATOR_REMOTE_BODY && $working = $this->body($this->elsewhere)) 138 141 { 139 return $working ;140 } 141 } 142 return null; 143 } 144 145 public function is_feed($file )142 return $working[0]; 143 } 144 } 145 return null; 146 } 147 148 public function is_feed($file, $check_html = false) 146 149 { 147 150 if ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE) … … 149 152 $sniffer = $this->registry->create('Content_Type_Sniffer', array($file)); 150 153 $sniffed = $sniffer->get_type(); 151 if (in_array($sniffed, array('application/rss+xml', 'application/rdf+xml', 'text/rdf', 'application/atom+xml', 'text/xml', 'application/xml'))) 152 { 153 return true; 154 } 155 else 156 { 157 return false; 158 } 154 $mime_types = array('application/rss+xml', 'application/rdf+xml', 155 'text/rdf', 'application/atom+xml', 'text/xml', 156 'application/xml', 'application/x-rss+xml'); 157 if ($check_html) 158 { 159 $mime_types[] = 'text/html'; 160 } 161 162 return in_array($sniffed, $mime_types); 159 163 } 160 164 elseif ($file->method & SIMPLEPIE_FILE_SOURCE_LOCAL) … … 205 209 return array_values($feeds); 206 210 } 207 else 208 { 209 return null; 210 } 211 212 return null; 211 213 } 212 214 … … 227 229 if ($link->hasAttribute('href') && $link->hasAttribute('rel')) 228 230 { 229 $rel = array_unique($this->registry->call('Misc', 'space_sep erated_tokens', array(strtolower($link->getAttribute('rel')))));231 $rel = array_unique($this->registry->call('Misc', 'space_separated_tokens', array(strtolower($link->getAttribute('rel'))))); 230 232 $line = method_exists($link, 'getLineNo') ? $link->getLineNo() : 1; 231 233 … … 243 245 } 244 246 245 if (!in_array($href, $done) && in_array('feed', $rel) || (in_array('alternate', $rel) && !in_array('stylesheet', $rel) && $link->hasAttribute('type') && in_array(strtolower($this->registry->call('Misc', 'parse_mime', array($link->getAttribute('type')))), array(' application/rss+xml', 'application/atom+xml'))) && !isset($feeds[$href]))247 if (!in_array($href, $done) && in_array('feed', $rel) || (in_array('alternate', $rel) && !in_array('stylesheet', $rel) && $link->hasAttribute('type') && in_array(strtolower($this->registry->call('Misc', 'parse_mime', array($link->getAttribute('type')))), array('text/html', 'application/rss+xml', 'application/atom+xml'))) && !isset($feeds[$href])) 246 248 { 247 249 $this->checked_feeds++; … … 249 251 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1', 250 252 ); 251 $feed = $this->registry->create('File', array($href, $this->timeout, 5, $headers, $this->useragent ));252 if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed ))253 $feed = $this->registry->create('File', array($href, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options)); 254 if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed, true)) 253 255 { 254 256 $feeds[$href] = $feed; … … 276 278 $href = trim($link->getAttribute('href')); 277 279 $parsed = $this->registry->call('Misc', 'parse_url', array($href)); 278 if ($parsed['scheme'] === '' || preg_match('/^(http (s)|feed)?$/i', $parsed['scheme']))280 if ($parsed['scheme'] === '' || preg_match('/^(https?|feed)?$/i', $parsed['scheme'])) 279 281 { 280 282 if (method_exists($link, 'getLineNo') && $this->base_location < $link->getLineNo()) … … 313 315 } 314 316 317 public function get_rel_link($rel) 318 { 319 if ($this->dom === null) 320 { 321 throw new SimplePie_Exception('DOMDocument not found, unable to use '. 322 'locator'); 323 } 324 if (!class_exists('DOMXpath')) 325 { 326 throw new SimplePie_Exception('DOMXpath not found, unable to use '. 327 'get_rel_link'); 328 } 329 330 $xpath = new DOMXpath($this->dom); 331 $query = '//a[@rel and @href] | //link[@rel and @href]'; 332 foreach ($xpath->query($query) as $link) 333 { 334 $href = trim($link->getAttribute('href')); 335 $parsed = $this->registry->call('Misc', 'parse_url', array($href)); 336 if ($parsed['scheme'] === '' || 337 preg_match('/^https?$/i', $parsed['scheme'])) 338 { 339 if (method_exists($link, 'getLineNo') && 340 $this->base_location < $link->getLineNo()) 341 { 342 $href = 343 $this->registry->call('Misc', 'absolutize_url', 344 array(trim($link->getAttribute('href')), 345 $this->base)); 346 } 347 else 348 { 349 $href = 350 $this->registry->call('Misc', 'absolutize_url', 351 array(trim($link->getAttribute('href')), 352 $this->http_base)); 353 } 354 if ($href === false) 355 { 356 return null; 357 } 358 $rel_values = explode(' ', strtolower($link->getAttribute('rel'))); 359 if (in_array($rel, $rel_values)) 360 { 361 return $href; 362 } 363 } 364 } 365 return null; 366 } 367 315 368 public function extension(&$array) 316 369 { … … 328 381 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1', 329 382 ); 330 $feed = $this->registry->create('File', array($value, $this->timeout, 5, $headers, $this->useragent ));383 $feed = $this->registry->create('File', array($value, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options)); 331 384 if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed)) 332 385 { 333 return $feed;386 return array($feed); 334 387 } 335 388 else … … 350 403 break; 351 404 } 352 if (preg_match('/( rss|rdf|atom|xml)/i', $value))405 if (preg_match('/(feed|rss|rdf|atom|xml)/i', $value)) 353 406 { 354 407 $this->checked_feeds++; … … 356 409 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1', 357 410 ); 358 $feed = $this->registry->create('File', array($value, $this->timeout, 5, null, $this->useragent ));411 $feed = $this->registry->create('File', array($value, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen, $this->curl_options)); 359 412 if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed)) 360 413 { 361 return $feed;414 return array($feed); 362 415 } 363 416 else … … 370 423 } 371 424 } 372
Note: See TracChangeset
for help on using the changeset viewer.