Changeset 47733 for trunk/src/wp-includes/SimplePie/Item.php
- Timestamp:
- 05/01/2020 02:24:42 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/SimplePie/Item.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 … … 123 122 public function __destruct() 124 123 { 125 if ( (version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))124 if (!gc_enabled()) 126 125 { 127 126 unset($this->feed); … … 149 148 return $this->data['child'][$namespace][$tag]; 150 149 } 151 else 152 { 153 return null; 154 } 150 151 return null; 155 152 } 156 153 … … 204 201 * Uses `<atom:id>`, `<guid>`, `<dc:identifier>` or the `about` attribute 205 202 * for RDF. If none of these are supplied (or `$hash` is true), creates an 206 * MD5 hash based on the permalink and title. If either of those are not 207 * supplied, creates a hash based on the full feed data. 203 * MD5 hash based on the permalink, title and content. 208 204 * 209 205 * @since Beta 2 210 206 * @param boolean $hash Should we force using a hash instead of the supplied ID? 211 * @return string 212 */ 213 public function get_id($hash = false) 207 * @param string|false $fn User-supplied function to generate an hash 208 * @return string|null 209 */ 210 public function get_id($hash = false, $fn = 'md5') 214 211 { 215 212 if (!$hash) … … 239 236 return $this->sanitize($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about'], SIMPLEPIE_CONSTRUCT_TEXT); 240 237 } 241 elseif (($return = $this->get_permalink()) !== null) 242 { 243 return $return; 244 } 245 elseif (($return = $this->get_title()) !== null) 246 { 247 return $return; 248 } 249 } 250 if ($this->get_permalink() !== null || $this->get_title() !== null) 251 { 252 return md5($this->get_permalink() . $this->get_title()); 253 } 254 else 255 { 256 return md5(serialize($this->data)); 257 } 238 } 239 if ($fn === false) 240 { 241 return null; 242 } 243 elseif (!is_callable($fn)) 244 { 245 trigger_error('User-supplied function $fn must be callable', E_USER_WARNING); 246 $fn = 'md5'; 247 } 248 return call_user_func($fn, 249 $this->get_permalink().$this->get_title().$this->get_content()); 258 250 } 259 251 … … 323 315 public function get_description($description_only = false) 324 316 { 325 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary')) 326 { 327 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 328 } 329 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary')) 330 { 331 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 332 } 333 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) 334 { 335 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 336 } 337 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) 338 { 339 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 340 } 341 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) 342 { 343 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 344 } 345 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) 346 { 347 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 348 } 349 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) 350 { 351 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 352 } 353 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) 354 { 355 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 356 } 357 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) 358 { 359 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML); 317 if (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary')) && 318 ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0])))) 319 { 320 return $return; 321 } 322 elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary')) && 323 ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0])))) 324 { 325 return $return; 326 } 327 elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) && 328 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($tags[0])))) 329 { 330 return $return; 331 } 332 elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) && 333 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($tags[0])))) 334 { 335 return $return; 336 } 337 elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) && 338 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT))) 339 { 340 return $return; 341 } 342 elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) && 343 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT))) 344 { 345 return $return; 346 } 347 elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) && 348 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($tags[0])))) 349 { 350 return $return; 351 } 352 elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) && 353 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT))) 354 { 355 return $return; 356 } 357 elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) && 358 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML))) 359 { 360 return $return; 360 361 } 361 362 … … 364 365 return $this->get_content(true); 365 366 } 366 else 367 { 368 return null; 369 } 367 368 return null; 370 369 } 371 370 … … 386 385 public function get_content($content_only = false) 387 386 { 388 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content')) 389 { 390 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_content_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 391 } 392 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content')) 393 { 394 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 395 } 396 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded')) 397 { 398 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 387 if (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content')) && 388 ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_10_content_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0])))) 389 { 390 return $return; 391 } 392 elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content')) && 393 ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0])))) 394 { 395 return $return; 396 } 397 elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded')) && 398 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($tags[0])))) 399 { 400 return $return; 399 401 } 400 402 elseif (!$content_only) … … 402 404 return $this->get_description(true); 403 405 } 404 else 405 { 406 return null; 407 } 406 407 return null; 408 } 409 410 /** 411 * Get the media:thumbnail of the item 412 * 413 * Uses `<media:thumbnail>` 414 * 415 * 416 * @return array|null 417 */ 418 public function get_thumbnail() 419 { 420 if (!isset($this->data['thumbnail'])) 421 { 422 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail')) 423 { 424 $this->data['thumbnail'] = $return[0]['attribs']['']; 425 } 426 else 427 { 428 $this->data['thumbnail'] = null; 429 } 430 } 431 return $this->data['thumbnail']; 408 432 } 409 433 … … 422 446 return $categories[$key]; 423 447 } 424 else 425 { 426 return null; 427 } 448 449 return null; 428 450 } 429 451 … … 434 456 * 435 457 * @since Beta 3 436 * @return array|null List of {@see SimplePie_Category} objects458 * @return SimplePie_Category[]|null List of {@see SimplePie_Category} objects 437 459 */ 438 460 public function get_categories() … … 440 462 $categories = array(); 441 463 442 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category) 464 $type = 'category'; 465 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, $type) as $category) 443 466 { 444 467 $term = null; … … 457 480 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); 458 481 } 459 $categories[] = $this->registry->create('Category', array($term, $scheme, $label ));460 } 461 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)482 $categories[] = $this->registry->create('Category', array($term, $scheme, $label, $type)); 483 } 484 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, $type) as $category) 462 485 { 463 486 // This is really the label, but keep this as the term also for BC. … … 472 495 $scheme = null; 473 496 } 474 $categories[] = $this->registry->create('Category', array($term, $scheme, null)); 475 } 476 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category) 477 { 478 $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 479 } 480 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category) 481 { 482 $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 497 $categories[] = $this->registry->create('Category', array($term, $scheme, null, $type)); 498 } 499 500 $type = 'subject'; 501 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, $type) as $category) 502 { 503 $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null, $type)); 504 } 505 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, $type) as $category) 506 { 507 $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null, $type)); 483 508 } 484 509 … … 487 512 return array_unique($categories); 488 513 } 489 else 490 { 491 return null; 492 } 514 515 return null; 493 516 } 494 517 … … 507 530 return $authors[$key]; 508 531 } 509 else 510 { 511 return null; 512 } 532 533 return null; 513 534 } 514 535 … … 527 548 return $contributors[$key]; 528 549 } 529 else 530 { 531 return null; 532 } 550 551 return null; 533 552 } 534 553 … … 539 558 * 540 559 * @since 1.1 541 * @return array|null List of {@see SimplePie_Author} objects560 * @return SimplePie_Author[]|null List of {@see SimplePie_Author} objects 542 561 */ 543 562 public function get_contributors() … … 593 612 return array_unique($contributors); 594 613 } 595 else 596 { 597 return null; 598 } 614 615 return null; 599 616 } 600 617 … … 605 622 * 606 623 * @since Beta 2 607 * @return array|null List of {@see SimplePie_Author} objects624 * @return SimplePie_Author[]|null List of {@see SimplePie_Author} objects 608 625 */ 609 626 public function get_authors() … … 683 700 return $authors; 684 701 } 685 else 686 { 687 return null; 688 } 702 703 return null; 689 704 } 690 705 … … 711 726 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 712 727 } 713 else 714 { 715 return null; 716 } 728 729 return null; 717 730 } 718 731 … … 739 752 $this->data['date']['raw'] = $return[0]['data']; 740 753 } 754 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'pubDate')) 755 { 756 $this->data['date']['raw'] = $return[0]['data']; 757 } 758 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date')) 759 { 760 $this->data['date']['raw'] = $return[0]['data']; 761 } 762 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date')) 763 { 764 $this->data['date']['raw'] = $return[0]['data']; 765 } 741 766 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated')) 742 767 { … … 752 777 } 753 778 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified')) 754 {755 $this->data['date']['raw'] = $return[0]['data'];756 }757 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'pubDate'))758 {759 $this->data['date']['raw'] = $return[0]['data'];760 }761 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date'))762 {763 $this->data['date']['raw'] = $return[0]['data'];764 }765 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date'))766 779 { 767 780 $this->data['date']['raw'] = $return[0]['data']; … … 793 806 } 794 807 } 795 else 796 { 797 return null; 798 } 808 809 return null; 799 810 } 800 811 … … 822 833 { 823 834 $parser = $this->registry->call('Parse_Date', 'get'); 824 $this->data['updated']['parsed'] = $parser->parse($this->data[' date']['raw']);835 $this->data['updated']['parsed'] = $parser->parse($this->data['updated']['raw']); 825 836 } 826 837 else … … 844 855 } 845 856 } 846 else 847 { 848 return null; 849 } 857 858 return null; 850 859 } 851 860 … … 873 882 return strftime($date_format, $date); 874 883 } 875 else 876 { 877 return null; 878 } 884 885 return null; 879 886 } 880 887 … … 937 944 return $enclosure->get_link(); 938 945 } 939 else 940 { 941 return null; 942 } 946 947 return null; 943 948 } 944 949 … … 954 959 { 955 960 $links = $this->get_links($rel); 956 if ($links [$key] !== null)961 if ($links && $links[$key] !== null) 957 962 { 958 963 return $links[$key]; 959 964 } 960 else 961 { 962 return null; 963 } 965 966 return null; 964 967 } 965 968 … … 1041 1044 return $this->data['links'][$rel]; 1042 1045 } 1043 else 1044 { 1045 return null; 1046 } 1046 1047 return null; 1047 1048 } 1048 1049 … … 1064 1065 return $enclosures[$key]; 1065 1066 } 1066 else 1067 { 1068 return null; 1069 } 1067 1068 return null; 1070 1069 } 1071 1070 … … 1081 1080 * @since Beta 2 1082 1081 * @todo Add support for end-user defined sorting of enclosures by type/handler (so we can prefer the faster-loading FLV over MP4). 1083 * @todo If an element exists at a level, but it 's value is empty, we should fall back to the value from the parent (if it exists).1084 * @return array|null List of SimplePie_Enclosure items1082 * @todo If an element exists at a level, but its value is empty, we should fall back to the value from the parent (if it exists). 1083 * @return SimplePie_Enclosure[]|null List of SimplePie_Enclosure items 1085 1084 */ 1086 1085 public function get_enclosures() … … 2659 2658 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'])) 2660 2659 { 2661 $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 2660 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'])) { 2661 $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 2662 } 2662 2663 } 2663 2664 else … … 2734 2735 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) 2735 2736 { 2736 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 2737 if (isset($thumbnail['attribs']['']['url'])) { 2738 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 2739 } 2737 2740 } 2738 2741 if (is_array($thumbnails)) … … 2790 2793 $length = ceil($link['attribs']['']['length']); 2791 2794 } 2795 if (isset($link['attribs']['']['title'])) 2796 { 2797 $title = $this->sanitize($link['attribs']['']['title'], SIMPLEPIE_CONSTRUCT_TEXT); 2798 } 2799 else 2800 { 2801 $title = $title_parent; 2802 } 2792 2803 2793 2804 // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor 2794 $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title _parent, $width));2805 $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title, $width)); 2795 2806 } 2796 2807 } … … 2878 2889 return $this->data['enclosures']; 2879 2890 } 2880 else 2881 { 2882 return null; 2883 } 2891 2892 return null; 2884 2893 } 2885 2894 … … 2906 2915 return (float) $match[1]; 2907 2916 } 2908 else 2909 { 2910 return null; 2911 } 2917 2918 return null; 2912 2919 } 2913 2920 … … 2938 2945 return (float) $match[2]; 2939 2946 } 2940 else 2941 { 2942 return null; 2943 } 2947 2948 return null; 2944 2949 } 2945 2950 … … 2956 2961 return $this->registry->create('Source', array($this, $return[0])); 2957 2962 } 2958 else 2959 { 2960 return null; 2961 } 2963 2964 return null; 2962 2965 } 2963 2966 } 2964
Note: See TracChangeset
for help on using the changeset viewer.