1 <?php
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
44
45 46 47
48 define('SIMPLEPIE_NAME', 'SimplePie');
49
50 51 52
53 define('SIMPLEPIE_VERSION', '1.3.1');
54
55 56 57 58
59 define('SIMPLEPIE_BUILD', gmdate('YmdHis', SimplePie_Misc::get_build()));
60
61 62 63
64 define('SIMPLEPIE_URL', 'http://simplepie.org');
65
66 67 68 69
70 define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD);
71
72 73 74
75 define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>');
76
77 78 79 80
81 define('SIMPLEPIE_LOCATOR_NONE', 0);
82
83 84 85 86
87 define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1);
88
89 90 91 92
93 define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2);
94
95 96 97 98
99 define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4);
100
101 102 103 104
105 define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8);
106
107 108 109 110
111 define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16);
112
113 114 115 116
117 define('SIMPLEPIE_LOCATOR_ALL', 31);
118
119 120 121
122 define('SIMPLEPIE_TYPE_NONE', 0);
123
124 125 126
127 define('SIMPLEPIE_TYPE_RSS_090', 1);
128
129 130 131
132 define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2);
133
134 135 136
137 define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4);
138
139 140 141
142 define('SIMPLEPIE_TYPE_RSS_091', 6);
143
144 145 146
147 define('SIMPLEPIE_TYPE_RSS_092', 8);
148
149 150 151
152 define('SIMPLEPIE_TYPE_RSS_093', 16);
153
154 155 156
157 define('SIMPLEPIE_TYPE_RSS_094', 32);
158
159 160 161
162 define('SIMPLEPIE_TYPE_RSS_10', 64);
163
164 165 166
167 define('SIMPLEPIE_TYPE_RSS_20', 128);
168
169 170 171
172 define('SIMPLEPIE_TYPE_RSS_RDF', 65);
173
174 175 176
177 define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190);
178
179 180 181
182 define('SIMPLEPIE_TYPE_RSS_ALL', 255);
183
184 185 186
187 define('SIMPLEPIE_TYPE_ATOM_03', 256);
188
189 190 191
192 define('SIMPLEPIE_TYPE_ATOM_10', 512);
193
194 195 196
197 define('SIMPLEPIE_TYPE_ATOM_ALL', 768);
198
199 200 201
202 define('SIMPLEPIE_TYPE_ALL', 1023);
203
204 205 206
207 define('SIMPLEPIE_CONSTRUCT_NONE', 0);
208
209 210 211
212 define('SIMPLEPIE_CONSTRUCT_TEXT', 1);
213
214 215 216
217 define('SIMPLEPIE_CONSTRUCT_HTML', 2);
218
219 220 221
222 define('SIMPLEPIE_CONSTRUCT_XHTML', 4);
223
224 225 226
227 define('SIMPLEPIE_CONSTRUCT_BASE64', 8);
228
229 230 231
232 define('SIMPLEPIE_CONSTRUCT_IRI', 16);
233
234 235 236
237 define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32);
238
239 240 241
242 define('SIMPLEPIE_CONSTRUCT_ALL', 63);
243
244 245 246
247 define('SIMPLEPIE_SAME_CASE', 1);
248
249 250 251
252 define('SIMPLEPIE_LOWERCASE', 2);
253
254 255 256
257 define('SIMPLEPIE_UPPERCASE', 4);
258
259 260 261
262 define('SIMPLEPIE_PCRE_HTML_ATTRIBUTE', '((?:[\x09\x0A\x0B\x0C\x0D\x20]+[^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?)*)[\x09\x0A\x0B\x0C\x0D\x20]*');
263
264 265 266
267 define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*');
268
269 270 271
272 define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace');
273
274 275 276
277 define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom');
278
279 280 281
282 define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#');
283
284 285 286
287 define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
288
289 290 291
292 define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/');
293
294 295 296
297 define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/');
298
299 300 301
302 define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/');
303
304 305 306 307
308 define('SIMPLEPIE_NAMESPACE_RSS_20', '');
309
310 311 312
313 define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/');
314
315 316 317
318 define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/');
319
320 321 322
323 define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#');
324
325 326 327
328 define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss');
329
330 331 332
333 define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/');
334
335 336 337
338 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss');
339
340 341 342
343 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2', 'http://video.search.yahoo.com/mrss');
344
345 346 347
348 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3', 'http://video.search.yahoo.com/mrss/');
349
350 351 352
353 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4', 'http://www.rssboard.org/media-rss');
354
355 356 357
358 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5', 'http://www.rssboard.org/media-rss/');
359
360 361 362
363 define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
364
365 366 367
368 define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml');
369
370 371 372
373 define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/');
374
375 376 377
378 define('SIMPLEPIE_FILE_SOURCE_NONE', 0);
379
380 381 382
383 define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1);
384
385 386 387
388 define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2);
389
390 391 392
393 define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4);
394
395 396 397
398 define('SIMPLEPIE_FILE_SOURCE_CURL', 8);
399
400 401 402
403 define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16);
404
405
406
407 408 409 410 411 412
413 class SimplePie
414 {
415 416 417 418
419 public $data = array();
420
421 422 423 424
425 public $error;
426
427 428 429 430 431
432 public $sanitize;
433
434 435 436 437 438
439 public $useragent = SIMPLEPIE_USERAGENT;
440
441 442 443 444 445
446 public $feed_url;
447
448 449 450 451 452
453 public $file;
454
455 456 457 458 459
460 public $raw_data;
461
462 463 464 465 466
467 public $timeout = 10;
468
469 470 471 472 473 474
475 public $force_fsockopen = false;
476
477 478 479 480 481 482
483 public $force_feed = false;
484
485 486 487 488 489
490 public $cache = true;
491
492 493 494 495 496
497 public $cache_duration = 3600;
498
499 500 501 502 503
504 public $autodiscovery_cache_duration = 604800;
505
506 507 508 509 510
511 public $cache_location = './cache';
512
513 514 515 516 517
518 public $cache_name_function = 'md5';
519
520 521 522 523 524
525 public $order_by_date = true;
526
527 528 529 530 531 532
533 public $input_encoding = false;
534
535 536 537 538 539
540 public $autodiscovery = SIMPLEPIE_LOCATOR_ALL;
541
542 543 544 545 546
547 public $registry;
548
549 550 551 552 553
554 public $max_checked_feeds = 10;
555
556 557 558 559 560
561 public $all_discovered_feeds = array();
562
563 564 565 566 567
568 public $image_handler = '';
569
570 571 572 573 574
575 public $multifeed_url = array();
576
577 578 579 580
581 public $multifeed_objects = array();
582
583 584 585 586 587
588 public $config_settings = null;
589
590 591 592 593 594
595 public $item_limit = 0;
596
597 598 599 600 601
602 public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
603
604 605 606 607 608
609 public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
610
611 612 613 614 615 616 617 618 619 620 621 622 623 624
625 public function __construct()
626 {
627 if (version_compare(PHP_VERSION, '5.2', '<'))
628 {
629 trigger_error('PHP 4.x, 5.0 and 5.1 are no longer supported. Please upgrade to PHP 5.2 or newer.');
630 die();
631 }
632
633
634 $this->sanitize = new SimplePie_Sanitize();
635 $this->registry = new SimplePie_Registry();
636
637 if (func_num_args() > 0)
638 {
639 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
640 trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly.', $level);
641
642 $args = func_get_args();
643 switch (count($args)) {
644 case 3:
645 $this->set_cache_duration($args[2]);
646 case 2:
647 $this->set_cache_location($args[1]);
648 case 1:
649 $this->set_feed_url($args[0]);
650 $this->init();
651 }
652 }
653 }
654
655 656 657
658 public function __toString()
659 {
660 return md5(serialize($this->data));
661 }
662
663 664 665
666 public function __destruct()
667 {
668 if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
669 {
670 if (!empty($this->data['items']))
671 {
672 foreach ($this->data['items'] as $item)
673 {
674 $item->__destruct();
675 }
676 unset($item, $this->data['items']);
677 }
678 if (!empty($this->data['ordered_items']))
679 {
680 foreach ($this->data['ordered_items'] as $item)
681 {
682 $item->__destruct();
683 }
684 unset($item, $this->data['ordered_items']);
685 }
686 }
687 }
688
689 690 691 692 693 694 695 696 697
698 public function force_feed($enable = false)
699 {
700 $this->force_feed = (bool) $enable;
701 }
702
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717
718 public function set_feed_url($url)
719 {
720 $this->multifeed_url = array();
721 if (is_array($url))
722 {
723 foreach ($url as $value)
724 {
725 $this->multifeed_url[] = $this->registry->call('Misc', 'fix_protocol', array($value, 1));
726 }
727 }
728 else
729 {
730 $this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1));
731 }
732 }
733
734 735 736 737 738 739
740 public function set_file(&$file)
741 {
742 if ($file instanceof SimplePie_File)
743 {
744 $this->feed_url = $file->url;
745 $this->file =& $file;
746 return true;
747 }
748 return false;
749 }
750
751 752 753 754 755 756 757 758 759 760 761 762 763
764 public function set_raw_data($data)
765 {
766 $this->raw_data = $data;
767 }
768
769 770 771 772 773 774 775 776 777
778 public function set_timeout($timeout = 10)
779 {
780 $this->timeout = (int) $timeout;
781 }
782
783 784 785 786 787 788
789 public function force_fsockopen($enable = false)
790 {
791 $this->force_fsockopen = (bool) $enable;
792 }
793
794 795 796 797 798 799 800 801 802
803 public function enable_cache($enable = true)
804 {
805 $this->cache = (bool) $enable;
806 }
807
808 809 810 811 812 813
814 public function set_cache_duration($seconds = 3600)
815 {
816 $this->cache_duration = (int) $seconds;
817 }
818
819 820 821 822 823 824
825 public function set_autodiscovery_cache_duration($seconds = 604800)
826 {
827 $this->autodiscovery_cache_duration = (int) $seconds;
828 }
829
830 831 832 833 834
835 public function set_cache_location($location = './cache')
836 {
837 $this->cache_location = (string) $location;
838 }
839
840 841 842 843 844
845 public function enable_order_by_date($enable = true)
846 {
847 $this->order_by_date = (bool) $enable;
848 }
849
850 851 852 853 854 855 856 857
858 public function set_input_encoding($encoding = false)
859 {
860 if ($encoding)
861 {
862 $this->input_encoding = (string) $encoding;
863 }
864 else
865 {
866 $this->input_encoding = false;
867 }
868 }
869
870 871 872 873 874 875 876 877 878 879 880 881
882 public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL)
883 {
884 $this->autodiscovery = (int) $level;
885 }
886
887 888 889 890 891 892 893
894 public function &get_registry()
895 {
896 return $this->registry;
897 }
898
899 900 901 902 903 904 905 906
907 908 909
910 public function set_cache_class($class = 'SimplePie_Cache')
911 {
912 return $this->registry->register('Cache', $class, true);
913 }
914
915 916 917
918 public function set_locator_class($class = 'SimplePie_Locator')
919 {
920 return $this->registry->register('Locator', $class, true);
921 }
922
923 924 925
926 public function set_parser_class($class = 'SimplePie_Parser')
927 {
928 return $this->registry->register('Parser', $class, true);
929 }
930
931 932 933
934 public function set_file_class($class = 'SimplePie_File')
935 {
936 return $this->registry->register('File', $class, true);
937 }
938
939 940 941
942 public function set_sanitize_class($class = 'SimplePie_Sanitize')
943 {
944 return $this->registry->register('Sanitize', $class, true);
945 }
946
947 948 949
950 public function set_item_class($class = 'SimplePie_Item')
951 {
952 return $this->registry->register('Item', $class, true);
953 }
954
955 956 957
958 public function set_author_class($class = 'SimplePie_Author')
959 {
960 return $this->registry->register('Author', $class, true);
961 }
962
963 964 965
966 public function set_category_class($class = 'SimplePie_Category')
967 {
968 return $this->registry->register('Category', $class, true);
969 }
970
971 972 973
974 public function set_enclosure_class($class = 'SimplePie_Enclosure')
975 {
976 return $this->registry->register('Enclosure', $class, true);
977 }
978
979 980 981
982 public function set_caption_class($class = 'SimplePie_Caption')
983 {
984 return $this->registry->register('Caption', $class, true);
985 }
986
987 988 989
990 public function set_copyright_class($class = 'SimplePie_Copyright')
991 {
992 return $this->registry->register('Copyright', $class, true);
993 }
994
995 996 997
998 public function set_credit_class($class = 'SimplePie_Credit')
999 {
1000 return $this->registry->register('Credit', $class, true);
1001 }
1002
1003 1004 1005
1006 public function set_rating_class($class = 'SimplePie_Rating')
1007 {
1008 return $this->registry->register('Rating', $class, true);
1009 }
1010
1011 1012 1013
1014 public function set_restriction_class($class = 'SimplePie_Restriction')
1015 {
1016 return $this->registry->register('Restriction', $class, true);
1017 }
1018
1019 1020 1021
1022 public function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer')
1023 {
1024 return $this->registry->register('Content_Type_Sniffer', $class, true);
1025 }
1026
1027 1028 1029
1030 public function set_source_class($class = 'SimplePie_Source')
1031 {
1032 return $this->registry->register('Source', $class, true);
1033 }
1034
1035
1036 1037 1038 1039 1040
1041 public function set_useragent($ua = SIMPLEPIE_USERAGENT)
1042 {
1043 $this->useragent = (string) $ua;
1044 }
1045
1046 1047 1048 1049 1050
1051 public function set_cache_name_function($function = 'md5')
1052 {
1053 if (is_callable($function))
1054 {
1055 $this->cache_name_function = $function;
1056 }
1057 }
1058
1059 1060 1061 1062 1063 1064 1065 1066
1067 public function set_stupidly_fast($set = false)
1068 {
1069 if ($set)
1070 {
1071 $this->enable_order_by_date(false);
1072 $this->remove_div(false);
1073 $this->strip_comments(false);
1074 $this->strip_htmltags(false);
1075 $this->strip_attributes(false);
1076 $this->set_image_handler(false);
1077 }
1078 }
1079
1080 1081 1082 1083 1084
1085 public function set_max_checked_feeds($max = 10)
1086 {
1087 $this->max_checked_feeds = (int) $max;
1088 }
1089
1090 public function remove_div($enable = true)
1091 {
1092 $this->sanitize->remove_div($enable);
1093 }
1094
1095 public function strip_htmltags($tags = '', $encode = null)
1096 {
1097 if ($tags === '')
1098 {
1099 $tags = $this->strip_htmltags;
1100 }
1101 $this->sanitize->strip_htmltags($tags);
1102 if ($encode !== null)
1103 {
1104 $this->sanitize->encode_instead_of_strip($tags);
1105 }
1106 }
1107
1108 public function encode_instead_of_strip($enable = true)
1109 {
1110 $this->sanitize->encode_instead_of_strip($enable);
1111 }
1112
1113 public function strip_attributes($attribs = '')
1114 {
1115 if ($attribs === '')
1116 {
1117 $attribs = $this->strip_attributes;
1118 }
1119 $this->sanitize->strip_attributes($attribs);
1120 }
1121
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
1144 public function set_output_encoding($encoding = 'UTF-8')
1145 {
1146 $this->sanitize->set_output_encoding($encoding);
1147 }
1148
1149 public function ($strip = false)
1150 {
1151 $this->sanitize->strip_comments($strip);
1152 }
1153
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
1165 public function set_url_replacements($element_attribute = null)
1166 {
1167 $this->sanitize->set_url_replacements($element_attribute);
1168 }
1169
1170 1171 1172 1173 1174 1175
1176 public function set_image_handler($page = false, $qs = 'i')
1177 {
1178 if ($page !== false)
1179 {
1180 $this->sanitize->set_image_handler($page . '?' . $qs . '=');
1181 }
1182 else
1183 {
1184 $this->image_handler = '';
1185 }
1186 }
1187
1188 1189 1190 1191 1192
1193 public function set_item_limit($limit = 0)
1194 {
1195 $this->item_limit = (int) $limit;
1196 }
1197
1198 1199 1200 1201 1202 1203 1204 1205 1206
1207 public function init()
1208 {
1209
1210 if (!extension_loaded('xml') || !extension_loaded('pcre'))
1211 {
1212 return false;
1213 }
1214
1215 elseif (!extension_loaded('xmlreader'))
1216 {
1217 static $xml_is_sane = null;
1218 if ($xml_is_sane === null)
1219 {
1220 $parser_check = xml_parser_create();
1221 xml_parse_into_struct($parser_check, '<foo>&</foo>', $values);
1222 xml_parser_free($parser_check);
1223 $xml_is_sane = isset($values[0]['value']);
1224 }
1225 if (!$xml_is_sane)
1226 {
1227 return false;
1228 }
1229 }
1230
1231 if (method_exists($this->sanitize, 'set_registry'))
1232 {
1233 $this->sanitize->set_registry($this->registry);
1234 }
1235
1236
1237
1238 $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache'));
1239 $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen);
1240
1241 if (!empty($this->multifeed_url))
1242 {
1243 $i = 0;
1244 $success = 0;
1245 $this->multifeed_objects = array();
1246 $this->error = array();
1247 foreach ($this->multifeed_url as $url)
1248 {
1249 $this->multifeed_objects[$i] = clone $this;
1250 $this->multifeed_objects[$i]->set_feed_url($url);
1251 $single_success = $this->multifeed_objects[$i]->init();
1252 $success |= $single_success;
1253 if (!$single_success)
1254 {
1255 $this->error[$i] = $this->multifeed_objects[$i]->error();
1256 }
1257 $i++;
1258 }
1259 return (bool) $success;
1260 }
1261 elseif ($this->feed_url === null && $this->raw_data === null)
1262 {
1263 return false;
1264 }
1265
1266 $this->error = null;
1267 $this->data = array();
1268 $this->multifeed_objects = array();
1269 $cache = false;
1270
1271 if ($this->feed_url !== null)
1272 {
1273 $parsed_feed_url = $this->registry->call('Misc', 'parse_url', array($this->feed_url));
1274
1275
1276 if ($this->cache && $parsed_feed_url['scheme'] !== '')
1277 {
1278 $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc'));
1279 }
1280
1281
1282 if (($fetched = $this->fetch_data($cache)) === true)
1283 {
1284 return true;
1285 }
1286 elseif ($fetched === false) {
1287 return false;
1288 }
1289
1290 list($headers, $sniffed) = $fetched;
1291 }
1292
1293
1294 $encodings = array();
1295
1296
1297 if ($this->input_encoding !== false)
1298 {
1299 $encodings[] = $this->input_encoding;
1300 }
1301
1302 $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
1303 $text_types = array('text/xml', 'text/xml-external-parsed-entity');
1304
1305
1306 if (isset($sniffed))
1307 {
1308 if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml')
1309 {
1310 if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
1311 {
1312 $encodings[] = strtoupper($charset[1]);
1313 }
1314 $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
1315 $encodings[] = 'UTF-8';
1316 }
1317 elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
1318 {
1319 if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
1320 {
1321 $encodings[] = $charset[1];
1322 }
1323 $encodings[] = 'US-ASCII';
1324 }
1325
1326 elseif (substr($sniffed, 0, 5) === 'text/')
1327 {
1328 $encodings[] = 'US-ASCII';
1329 }
1330 }
1331
1332
1333 $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
1334 $encodings[] = 'UTF-8';
1335 $encodings[] = 'ISO-8859-1';
1336
1337
1338 $encodings = array_unique($encodings);
1339
1340
1341 foreach ($encodings as $encoding)
1342 {
1343
1344 if ($utf8_data = $this->registry->call('Misc', 'change_encoding', array($this->raw_data, $encoding, 'UTF-8')))
1345 {
1346
1347 $parser = $this->registry->create('Parser');
1348
1349
1350 if ($parser->parse($utf8_data, 'UTF-8'))
1351 {
1352 $this->data = $parser->get_data();
1353 if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE))
1354 {
1355 $this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";
1356 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
1357 return false;
1358 }
1359
1360 if (isset($headers))
1361 {
1362 $this->data['headers'] = $headers;
1363 }
1364 $this->data['build'] = SIMPLEPIE_BUILD;
1365
1366
1367 if ($cache && !$cache->save($this))
1368 {
1369 trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
1370 }
1371 return true;
1372 }
1373 }
1374 }
1375
1376 if (isset($parser))
1377 {
1378
1379 $this->error = sprintf('This XML document is invalid, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column());
1380 }
1381 else
1382 {
1383 $this->error = 'The data could not be converted to UTF-8. You MUST have either the iconv or mbstring extension installed. Upgrading to PHP 5.x (which includes iconv) is highly recommended.';
1384 }
1385
1386 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
1387
1388 return false;
1389 }
1390
1391 1392 1393 1394 1395 1396 1397
1398 protected function fetch_data(&$cache)
1399 {
1400
1401 if ($cache)
1402 {
1403
1404 $this->data = $cache->load();
1405 if (!empty($this->data))
1406 {
1407
1408 if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD)
1409 {
1410 $cache->unlink();
1411 $this->data = array();
1412 }
1413
1414 elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url)
1415 {
1416 $cache = false;
1417 $this->data = array();
1418 }
1419
1420 elseif (isset($this->data['feed_url']))
1421 {
1422
1423 if ($cache->mtime() + $this->autodiscovery_cache_duration > time())
1424 {
1425
1426 if ($this->data['feed_url'] !== $this->data['url'])
1427 {
1428 $this->set_feed_url($this->data['feed_url']);
1429 return $this->init();
1430 }
1431
1432 $cache->unlink();
1433 $this->data = array();
1434 }
1435 }
1436
1437 elseif ($cache->mtime() + $this->cache_duration < time())
1438 {
1439
1440 if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag']))
1441 {
1442 $headers = array(
1443 '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',
1444 );
1445 if (isset($this->data['headers']['last-modified']))
1446 {
1447 $headers['if-modified-since'] = $this->data['headers']['last-modified'];
1448 }
1449 if (isset($this->data['headers']['etag']))
1450 {
1451 $headers['if-none-match'] = $this->data['headers']['etag'];
1452 }
1453
1454 $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen));
1455
1456 if ($file->success)
1457 {
1458 if ($file->status_code === 304)
1459 {
1460 $cache->touch();
1461 return true;
1462 }
1463 }
1464 else
1465 {
1466 unset($file);
1467 }
1468 }
1469 }
1470
1471 else
1472 {
1473 $this->raw_data = false;
1474 return true;
1475 }
1476 }
1477
1478 else
1479 {
1480 $cache->unlink();
1481 $this->data = array();
1482 }
1483 }
1484
1485 if (!isset($file))
1486 {
1487 if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url)
1488 {
1489 $file =& $this->file;
1490 }
1491 else
1492 {
1493 $headers = array(
1494 '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',
1495 );
1496 $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen));
1497 }
1498 }
1499
1500 if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
1501 {
1502 $this->error = $file->error;
1503 return !empty($this->data);
1504 }
1505
1506 if (!$this->force_feed)
1507 {
1508
1509 $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds));
1510
1511 if (!$locate->is_feed($file))
1512 {
1513
1514 unset($file);
1515 try
1516 {
1517 if (!($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds)))
1518 {
1519 $this->error = "A feed could not be found at $this->feed_url. A feed with an invalid mime type may fall victim to this error, or " . SIMPLEPIE_NAME . " was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed.";
1520 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
1521 return false;
1522 }
1523 }
1524 catch (SimplePie_Exception $e)
1525 {
1526
1527 $this->error = $e->getMessage();
1528 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, $e->getFile(), $e->getLine()));
1529 return false;
1530 }
1531 if ($cache)
1532 {
1533 $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
1534 if (!$cache->save($this))
1535 {
1536 trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
1537 }
1538 $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc'));
1539 }
1540 $this->feed_url = $file->url;
1541 }
1542 $locate = null;
1543 }
1544
1545 $this->raw_data = $file->body;
1546
1547 $headers = $file->headers;
1548 $sniffer = $this->registry->create('Content_Type_Sniffer', array(&$file));
1549 $sniffed = $sniffer->get_type();
1550
1551 return array($headers, $sniffed);
1552 }
1553
1554 1555 1556 1557 1558
1559 public function error()
1560 {
1561 return $this->error;
1562 }
1563
1564 1565 1566 1567 1568 1569 1570 1571
1572 public function get_raw_data()
1573 {
1574 return $this->raw_data;
1575 }
1576
1577 1578 1579 1580 1581 1582
1583 public function get_encoding()
1584 {
1585 return $this->sanitize->output_encoding;
1586 }
1587
1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606
1607 public function handle_content_type($mime = 'text/html')
1608 {
1609 if (!headers_sent())
1610 {
1611 $header = "Content-type: $mime;";
1612 if ($this->get_encoding())
1613 {
1614 $header .= ' charset=' . $this->get_encoding();
1615 }
1616 else
1617 {
1618 $header .= ' charset=UTF-8';
1619 }
1620 header($header);
1621 }
1622 }
1623
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649
1650 public function get_type()
1651 {
1652 if (!isset($this->data['type']))
1653 {
1654 $this->data['type'] = SIMPLEPIE_TYPE_ALL;
1655 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed']))
1656 {
1657 $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;
1658 }
1659 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed']))
1660 {
1661 $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;
1662 }
1663 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF']))
1664 {
1665 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel'])
1666 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image'])
1667 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])
1668 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput']))
1669 {
1670 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10;
1671 }
1672 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel'])
1673 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image'])
1674 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])
1675 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput']))
1676 {
1677 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;
1678 }
1679 }
1680 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss']))
1681 {
1682 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;
1683 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
1684 {
1685 switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
1686 {
1687 case '0.91':
1688 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091;
1689 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
1690 {
1691 switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
1692 {
1693 case '0':
1694 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE;
1695 break;
1696
1697 case '24':
1698 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND;
1699 break;
1700 }
1701 }
1702 break;
1703
1704 case '0.92':
1705 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092;
1706 break;
1707
1708 case '0.93':
1709 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093;
1710 break;
1711
1712 case '0.94':
1713 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094;
1714 break;
1715
1716 case '2.0':
1717 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20;
1718 break;
1719 }
1720 }
1721 }
1722 else
1723 {
1724 $this->data['type'] = SIMPLEPIE_TYPE_NONE;
1725 }
1726 }
1727 return $this->data['type'];
1728 }
1729
1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741
1742 public function subscribe_url()
1743 {
1744 if ($this->feed_url !== null)
1745 {
1746 return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI);
1747 }
1748 else
1749 {
1750 return null;
1751 }
1752 }
1753
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784
1785 public function get_feed_tags($namespace, $tag)
1786 {
1787 $type = $this->get_type();
1788 if ($type & SIMPLEPIE_TYPE_ATOM_10)
1789 {
1790 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]))
1791 {
1792 return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag];
1793 }
1794 }
1795 if ($type & SIMPLEPIE_TYPE_ATOM_03)
1796 {
1797 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]))
1798 {
1799 return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag];
1800 }
1801 }
1802 if ($type & SIMPLEPIE_TYPE_RSS_RDF)
1803 {
1804 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]))
1805 {
1806 return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag];
1807 }
1808 }
1809 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
1810 {
1811 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag]))
1812 {
1813 return $this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag];
1814 }
1815 }
1816 return null;
1817 }
1818
1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832
1833 public function get_channel_tags($namespace, $tag)
1834 {
1835 $type = $this->get_type();
1836 if ($type & SIMPLEPIE_TYPE_ATOM_ALL)
1837 {
1838 if ($return = $this->get_feed_tags($namespace, $tag))
1839 {
1840 return $return;
1841 }
1842 }
1843 if ($type & SIMPLEPIE_TYPE_RSS_10)
1844 {
1845 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel'))
1846 {
1847 if (isset($channel[0]['child'][$namespace][$tag]))
1848 {
1849 return $channel[0]['child'][$namespace][$tag];
1850 }
1851 }
1852 }
1853 if ($type & SIMPLEPIE_TYPE_RSS_090)
1854 {
1855 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel'))
1856 {
1857 if (isset($channel[0]['child'][$namespace][$tag]))
1858 {
1859 return $channel[0]['child'][$namespace][$tag];
1860 }
1861 }
1862 }
1863 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
1864 {
1865 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'channel'))
1866 {
1867 if (isset($channel[0]['child'][$namespace][$tag]))
1868 {
1869 return $channel[0]['child'][$namespace][$tag];
1870 }
1871 }
1872 }
1873 return null;
1874 }
1875
1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889
1890 public function get_image_tags($namespace, $tag)
1891 {
1892 $type = $this->get_type();
1893 if ($type & SIMPLEPIE_TYPE_RSS_10)
1894 {
1895 if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image'))
1896 {
1897 if (isset($image[0]['child'][$namespace][$tag]))
1898 {
1899 return $image[0]['child'][$namespace][$tag];
1900 }
1901 }
1902 }
1903 if ($type & SIMPLEPIE_TYPE_RSS_090)
1904 {
1905 if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image'))
1906 {
1907 if (isset($image[0]['child'][$namespace][$tag]))
1908 {
1909 return $image[0]['child'][$namespace][$tag];
1910 }
1911 }
1912 }
1913 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
1914 {
1915 if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'image'))
1916 {
1917 if (isset($image[0]['child'][$namespace][$tag]))
1918 {
1919 return $image[0]['child'][$namespace][$tag];
1920 }
1921 }
1922 }
1923 return null;
1924 }
1925
1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937
1938 public function get_base($element = array())
1939 {
1940 if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
1941 {
1942 return $element['xml_base'];
1943 }
1944 elseif ($this->get_link() !== null)
1945 {
1946 return $this->get_link();
1947 }
1948 else
1949 {
1950 return $this->subscribe_url();
1951 }
1952 }
1953
1954 1955 1956 1957 1958 1959 1960 1961 1962 1963
1964 public function sanitize($data, $type, $base = '')
1965 {
1966 return $this->sanitize->sanitize($data, $type, $base);
1967 }
1968
1969 1970 1971 1972 1973 1974 1975 1976
1977 public function get_title()
1978 {
1979 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
1980 {
1981 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
1982 }
1983 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
1984 {
1985 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
1986 }
1987 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
1988 {
1989 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
1990 }
1991 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
1992 {
1993 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
1994 }
1995 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
1996 {
1997 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
1998 }
1999 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
2000 {
2001 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2002 }
2003 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
2004 {
2005 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2006 }
2007 else
2008 {
2009 return null;
2010 }
2011 }
2012
2013 2014 2015 2016 2017 2018 2019
2020 public function get_category($key = 0)
2021 {
2022 $categories = $this->get_categories();
2023 if (isset($categories[$key]))
2024 {
2025 return $categories[$key];
2026 }
2027 else
2028 {
2029 return null;
2030 }
2031 }
2032
2033 2034 2035 2036 2037 2038 2039 2040
2041 public function get_categories()
2042 {
2043 $categories = array();
2044
2045 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
2046 {
2047 $term = null;
2048 $scheme = null;
2049 $label = null;
2050 if (isset($category['attribs']['']['term']))
2051 {
2052 $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
2053 }
2054 if (isset($category['attribs']['']['scheme']))
2055 {
2056 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
2057 }
2058 if (isset($category['attribs']['']['label']))
2059 {
2060 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
2061 }
2062 $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
2063 }
2064 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
2065 {
2066
2067
2068 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2069 if (isset($category['attribs']['']['domain']))
2070 {
2071 $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
2072 }
2073 else
2074 {
2075 $scheme = null;
2076 }
2077 $categories[] = $this->registry->create('Category', array($term, $scheme, null));
2078 }
2079 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
2080 {
2081 $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2082 }
2083 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
2084 {
2085 $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2086 }
2087
2088 if (!empty($categories))
2089 {
2090 return array_unique($categories);
2091 }
2092 else
2093 {
2094 return null;
2095 }
2096 }
2097
2098 2099 2100 2101 2102 2103 2104
2105 public function get_author($key = 0)
2106 {
2107 $authors = $this->get_authors();
2108 if (isset($authors[$key]))
2109 {
2110 return $authors[$key];
2111 }
2112 else
2113 {
2114 return null;
2115 }
2116 }
2117
2118 2119 2120 2121 2122 2123 2124 2125
2126 public function get_authors()
2127 {
2128 $authors = array();
2129 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
2130 {
2131 $name = null;
2132 $uri = null;
2133 $email = null;
2134 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
2135 {
2136 $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2137 }
2138 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
2139 {
2140 $uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
2141 }
2142 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
2143 {
2144 $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2145 }
2146 if ($name !== null || $email !== null || $uri !== null)
2147 {
2148 $authors[] = $this->registry->create('Author', array($name, $uri, $email));
2149 }
2150 }
2151 if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
2152 {
2153 $name = null;
2154 $url = null;
2155 $email = null;
2156 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
2157 {
2158 $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2159 }
2160 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
2161 {
2162 $url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
2163 }
2164 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
2165 {
2166 $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2167 }
2168 if ($name !== null || $email !== null || $url !== null)
2169 {
2170 $authors[] = $this->registry->create('Author', array($name, $url, $email));
2171 }
2172 }
2173 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
2174 {
2175 $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2176 }
2177 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
2178 {
2179 $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2180 }
2181 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
2182 {
2183 $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2184 }
2185
2186 if (!empty($authors))
2187 {
2188 return array_unique($authors);
2189 }
2190 else
2191 {
2192 return null;
2193 }
2194 }
2195
2196 2197 2198 2199 2200 2201 2202
2203 public function get_contributor($key = 0)
2204 {
2205 $contributors = $this->get_contributors();
2206 if (isset($contributors[$key]))
2207 {
2208 return $contributors[$key];
2209 }
2210 else
2211 {
2212 return null;
2213 }
2214 }
2215
2216 2217 2218 2219 2220 2221 2222 2223
2224 public function get_contributors()
2225 {
2226 $contributors = array();
2227 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
2228 {
2229 $name = null;
2230 $uri = null;
2231 $email = null;
2232 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
2233 {
2234 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2235 }
2236 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
2237 {
2238 $uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
2239 }
2240 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
2241 {
2242 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2243 }
2244 if ($name !== null || $email !== null || $uri !== null)
2245 {
2246 $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
2247 }
2248 }
2249 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
2250 {
2251 $name = null;
2252 $url = null;
2253 $email = null;
2254 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
2255 {
2256 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2257 }
2258 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
2259 {
2260 $url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
2261 }
2262 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
2263 {
2264 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2265 }
2266 if ($name !== null || $email !== null || $url !== null)
2267 {
2268 $contributors[] = $this->registry->create('Author', array($name, $url, $email));
2269 }
2270 }
2271
2272 if (!empty($contributors))
2273 {
2274 return array_unique($contributors);
2275 }
2276 else
2277 {
2278 return null;
2279 }
2280 }
2281
2282 2283 2284 2285 2286 2287 2288 2289
2290 public function get_link($key = 0, $rel = 'alternate')
2291 {
2292 $links = $this->get_links($rel);
2293 if (isset($links[$key]))
2294 {
2295 return $links[$key];
2296 }
2297 else
2298 {
2299 return null;
2300 }
2301 }
2302
2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313
2314 public function get_permalink()
2315 {
2316 return $this->get_link(0);
2317 }
2318
2319 2320 2321 2322 2323 2324 2325 2326 2327
2328 public function get_links($rel = 'alternate')
2329 {
2330 if (!isset($this->data['links']))
2331 {
2332 $this->data['links'] = array();
2333 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
2334 {
2335 foreach ($links as $link)
2336 {
2337 if (isset($link['attribs']['']['href']))
2338 {
2339 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
2340 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
2341 }
2342 }
2343 }
2344 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
2345 {
2346 foreach ($links as $link)
2347 {
2348 if (isset($link['attribs']['']['href']))
2349 {
2350 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
2351 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
2352
2353 }
2354 }
2355 }
2356 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
2357 {
2358 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
2359 }
2360 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
2361 {
2362 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
2363 }
2364 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
2365 {
2366 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
2367 }
2368
2369 $keys = array_keys($this->data['links']);
2370 foreach ($keys as $key)
2371 {
2372 if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
2373 {
2374 if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
2375 {
2376 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
2377 $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
2378 }
2379 else
2380 {
2381 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
2382 }
2383 }
2384 elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
2385 {
2386 $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
2387 }
2388 $this->data['links'][$key] = array_unique($this->data['links'][$key]);
2389 }
2390 }
2391
2392 if (isset($this->data['links'][$rel]))
2393 {
2394 return $this->data['links'][$rel];
2395 }
2396 else
2397 {
2398 return null;
2399 }
2400 }
2401
2402 public function get_all_discovered_feeds()
2403 {
2404 return $this->all_discovered_feeds;
2405 }
2406
2407 2408 2409 2410 2411 2412 2413 2414 2415
2416 public function get_description()
2417 {
2418 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
2419 {
2420 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2421 }
2422 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
2423 {
2424 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2425 }
2426 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
2427 {
2428 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2429 }
2430 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
2431 {
2432 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2433 }
2434 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
2435 {
2436 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
2437 }
2438 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
2439 {
2440 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2441 }
2442 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
2443 {
2444 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2445 }
2446 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
2447 {
2448 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
2449 }
2450 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
2451 {
2452 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
2453 }
2454 else
2455 {
2456 return null;
2457 }
2458 }
2459
2460 2461 2462 2463 2464 2465 2466 2467
2468 public function get_copyright()
2469 {
2470 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
2471 {
2472 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2473 }
2474 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
2475 {
2476 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2477 }
2478 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
2479 {
2480 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2481 }
2482 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
2483 {
2484 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2485 }
2486 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
2487 {
2488 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2489 }
2490 else
2491 {
2492 return null;
2493 }
2494 }
2495
2496 2497 2498 2499 2500 2501 2502 2503
2504 public function get_language()
2505 {
2506 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
2507 {
2508 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2509 }
2510 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
2511 {
2512 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2513 }
2514 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
2515 {
2516 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2517 }
2518 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang']))
2519 {
2520 return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2521 }
2522 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang']))
2523 {
2524 return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2525 }
2526 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang']))
2527 {
2528 return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2529 }
2530 elseif (isset($this->data['headers']['content-language']))
2531 {
2532 return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT);
2533 }
2534 else
2535 {
2536 return null;
2537 }
2538 }
2539
2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551
2552 public function get_latitude()
2553 {
2554
2555 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
2556 {
2557 return (float) $return[0]['data'];
2558 }
2559 elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
2560 {
2561 return (float) $match[1];
2562 }
2563 else
2564 {
2565 return null;
2566 }
2567 }
2568
2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580
2581 public function get_longitude()
2582 {
2583 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
2584 {
2585 return (float) $return[0]['data'];
2586 }
2587 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
2588 {
2589 return (float) $return[0]['data'];
2590 }
2591 elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
2592 {
2593 return (float) $match[2];
2594 }
2595 else
2596 {
2597 return null;
2598 }
2599 }
2600
2601 2602 2603 2604 2605 2606 2607 2608 2609
2610 public function get_image_title()
2611 {
2612 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
2613 {
2614 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2615 }
2616 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
2617 {
2618 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2619 }
2620 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
2621 {
2622 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2623 }
2624 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
2625 {
2626 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2627 }
2628 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
2629 {
2630 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2631 }
2632 else
2633 {
2634 return null;
2635 }
2636 }
2637
2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648
2649 public function get_image_url()
2650 {
2651 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
2652 {
2653 return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
2654 }
2655 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
2656 {
2657 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2658 }
2659 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
2660 {
2661 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2662 }
2663 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url'))
2664 {
2665 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2666 }
2667 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url'))
2668 {
2669 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2670 }
2671 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2672 {
2673 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2674 }
2675 else
2676 {
2677 return null;
2678 }
2679 }
2680
2681
2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692
2693 public function get_image_link()
2694 {
2695 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
2696 {
2697 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2698 }
2699 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
2700 {
2701 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2702 }
2703 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
2704 {
2705 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2706 }
2707 else
2708 {
2709 return null;
2710 }
2711 }
2712
2713 2714 2715 2716 2717 2718 2719 2720 2721 2722
2723 public function get_image_width()
2724 {
2725 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width'))
2726 {
2727 return round($return[0]['data']);
2728 }
2729 elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2730 {
2731 return 88.0;
2732 }
2733 else
2734 {
2735 return null;
2736 }
2737 }
2738
2739 2740 2741 2742 2743 2744 2745 2746 2747 2748
2749 public function get_image_height()
2750 {
2751 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'height'))
2752 {
2753 return round($return[0]['data']);
2754 }
2755 elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2756 {
2757 return 31.0;
2758 }
2759 else
2760 {
2761 return null;
2762 }
2763 }
2764
2765 2766 2767 2768 2769 2770 2771 2772 2773
2774 public function get_item_quantity($max = 0)
2775 {
2776 $max = (int) $max;
2777 $qty = count($this->get_items());
2778 if ($max === 0)
2779 {
2780 return $qty;
2781 }
2782 else
2783 {
2784 return ($qty > $max) ? $max : $qty;
2785 }
2786 }
2787
2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799
2800 public function get_item($key = 0)
2801 {
2802 $items = $this->get_items();
2803 if (isset($items[$key]))
2804 {
2805 return $items[$key];
2806 }
2807 else
2808 {
2809 return null;
2810 }
2811 }
2812
2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825
2826 public function get_items($start = 0, $end = 0)
2827 {
2828 if (!isset($this->data['items']))
2829 {
2830 if (!empty($this->multifeed_objects))
2831 {
2832 $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit);
2833 }
2834 else
2835 {
2836 $this->data['items'] = array();
2837 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry'))
2838 {
2839 $keys = array_keys($items);
2840 foreach ($keys as $key)
2841 {
2842 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
2843 }
2844 }
2845 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry'))
2846 {
2847 $keys = array_keys($items);
2848 foreach ($keys as $key)
2849 {
2850 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
2851 }
2852 }
2853 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item'))
2854 {
2855 $keys = array_keys($items);
2856 foreach ($keys as $key)
2857 {
2858 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
2859 }
2860 }
2861 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item'))
2862 {
2863 $keys = array_keys($items);
2864 foreach ($keys as $key)
2865 {
2866 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
2867 }
2868 }
2869 if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item'))
2870 {
2871 $keys = array_keys($items);
2872 foreach ($keys as $key)
2873 {
2874 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
2875 }
2876 }
2877 }
2878 }
2879
2880 if (!empty($this->data['items']))
2881 {
2882
2883 if ($this->order_by_date && empty($this->multifeed_objects))
2884 {
2885 if (!isset($this->data['ordered_items']))
2886 {
2887 $do_sort = true;
2888 foreach ($this->data['items'] as $item)
2889 {
2890 if (!$item->get_date('U'))
2891 {
2892 $do_sort = false;
2893 break;
2894 }
2895 }
2896 $item = null;
2897 $this->data['ordered_items'] = $this->data['items'];
2898 if ($do_sort)
2899 {
2900 usort($this->data['ordered_items'], array(get_class($this), 'sort_items'));
2901 }
2902 }
2903 $items = $this->data['ordered_items'];
2904 }
2905 else
2906 {
2907 $items = $this->data['items'];
2908 }
2909
2910
2911 if ($end === 0)
2912 {
2913 return array_slice($items, $start);
2914 }
2915 else
2916 {
2917 return array_slice($items, $start, $end);
2918 }
2919 }
2920 else
2921 {
2922 return array();
2923 }
2924 }
2925
2926 2927 2928 2929 2930
2931 public function set_favicon_handler($page = false, $qs = 'i')
2932 {
2933 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
2934 trigger_error('Favicon handling has been removed, please use your own handling', $level);
2935 return false;
2936 }
2937
2938 2939 2940 2941 2942
2943 public function get_favicon()
2944 {
2945 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
2946 trigger_error('Favicon handling has been removed, please use your own handling', $level);
2947
2948 if (($url = $this->get_link()) !== null)
2949 {
2950 return 'http://g.etfv.co/' . urlencode($url);
2951 }
2952
2953 return false;
2954 }
2955
2956 2957 2958 2959 2960 2961 2962
2963 public function __call($method, $args)
2964 {
2965 if (strpos($method, 'subscribe_') === 0)
2966 {
2967 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
2968 trigger_error('subscribe_*() has been deprecated, implement the callback yourself', $level);
2969 return '';
2970 }
2971 if ($method === 'enable_xml_dump')
2972 {
2973 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
2974 trigger_error('enable_xml_dump() has been deprecated, use get_raw_data() instead', $level);
2975 return false;
2976 }
2977
2978 $class = get_class($this);
2979 $trace = debug_backtrace();
2980 $file = $trace[0]['file'];
2981 $line = $trace[0]['line'];
2982 trigger_error("Call to undefined method $class::$method() in $file on line $line", E_USER_ERROR);
2983 }
2984
2985 2986 2987 2988 2989 2990 2991 2992
2993 public static function sort_items($a, $b)
2994 {
2995 return $a->get_date('U') <= $b->get_date('U');
2996 }
2997
2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010
3011 public static function merge_items($urls, $start = 0, $end = 0, $limit = 0)
3012 {
3013 if (is_array($urls) && sizeof($urls) > 0)
3014 {
3015 $items = array();
3016 foreach ($urls as $arg)
3017 {
3018 if ($arg instanceof SimplePie)
3019 {
3020 $items = array_merge($items, $arg->get_items(0, $limit));
3021 }
3022 else
3023 {
3024 trigger_error('Arguments must be SimplePie objects', E_USER_WARNING);
3025 }
3026 }
3027
3028 $do_sort = true;
3029 foreach ($items as $item)
3030 {
3031 if (!$item->get_date('U'))
3032 {
3033 $do_sort = false;
3034 break;
3035 }
3036 }
3037 $item = null;
3038 if ($do_sort)
3039 {
3040 usort($items, array(get_class($urls[0]), 'sort_items'));
3041 }
3042
3043 if ($end === 0)
3044 {
3045 return array_slice($items, $start);
3046 }
3047 else
3048 {
3049 return array_slice($items, $start, $end);
3050 }
3051 }
3052 else
3053 {
3054 trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING);
3055 return array();
3056 }
3057 }
3058 }
3059