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');
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: trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly.');
640: }
641: }
642:
643: 644: 645:
646: public function __toString()
647: {
648: return md5(serialize($this->data));
649: }
650:
651: 652: 653:
654: public function __destruct()
655: {
656: if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
657: {
658: if (!empty($this->data['items']))
659: {
660: foreach ($this->data['items'] as $item)
661: {
662: $item->__destruct();
663: }
664: unset($item, $this->data['items']);
665: }
666: if (!empty($this->data['ordered_items']))
667: {
668: foreach ($this->data['ordered_items'] as $item)
669: {
670: $item->__destruct();
671: }
672: unset($item, $this->data['ordered_items']);
673: }
674: }
675: }
676:
677: 678: 679: 680: 681: 682: 683: 684: 685:
686: public function force_feed($enable = false)
687: {
688: $this->force_feed = (bool) $enable;
689: }
690:
691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705:
706: public function set_feed_url($url)
707: {
708: $this->multifeed_url = array();
709: if (is_array($url))
710: {
711: foreach ($url as $value)
712: {
713: $this->multifeed_url[] = $this->registry->call('Misc', 'fix_protocol', array($value, 1));
714: }
715: }
716: else
717: {
718: $this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1));
719: }
720: }
721:
722: 723: 724: 725: 726: 727:
728: public function set_file(&$file)
729: {
730: if ($file instanceof SimplePie_File)
731: {
732: $this->feed_url = $file->url;
733: $this->file =& $file;
734: return true;
735: }
736: return false;
737: }
738:
739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751:
752: public function set_raw_data($data)
753: {
754: $this->raw_data = $data;
755: }
756:
757: 758: 759: 760: 761: 762: 763: 764: 765:
766: public function set_timeout($timeout = 10)
767: {
768: $this->timeout = (int) $timeout;
769: }
770:
771: 772: 773: 774: 775: 776:
777: public function force_fsockopen($enable = false)
778: {
779: $this->force_fsockopen = (bool) $enable;
780: }
781:
782: 783: 784: 785: 786: 787: 788: 789: 790:
791: public function enable_cache($enable = true)
792: {
793: $this->cache = (bool) $enable;
794: }
795:
796: 797: 798: 799: 800: 801:
802: public function set_cache_duration($seconds = 3600)
803: {
804: $this->cache_duration = (int) $seconds;
805: }
806:
807: 808: 809: 810: 811: 812:
813: public function set_autodiscovery_cache_duration($seconds = 604800)
814: {
815: $this->autodiscovery_cache_duration = (int) $seconds;
816: }
817:
818: 819: 820: 821: 822:
823: public function set_cache_location($location = './cache')
824: {
825: $this->cache_location = (string) $location;
826: }
827:
828: 829: 830: 831: 832:
833: public function enable_order_by_date($enable = true)
834: {
835: $this->order_by_date = (bool) $enable;
836: }
837:
838: 839: 840: 841: 842: 843: 844: 845:
846: public function set_input_encoding($encoding = false)
847: {
848: if ($encoding)
849: {
850: $this->input_encoding = (string) $encoding;
851: }
852: else
853: {
854: $this->input_encoding = false;
855: }
856: }
857:
858: 859: 860: 861: 862: 863: 864: 865: 866: 867: 868: 869:
870: public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL)
871: {
872: $this->autodiscovery = (int) $level;
873: }
874:
875: 876: 877: 878: 879: 880: 881:
882: public function &get_registry()
883: {
884: return $this->registry;
885: }
886:
887: 888: 889: 890: 891: 892: 893: 894:
895: 896: 897:
898: public function set_cache_class($class = 'SimplePie_Cache')
899: {
900: return $this->registry->register('Cache', $class, true);
901: }
902:
903: 904: 905:
906: public function set_locator_class($class = 'SimplePie_Locator')
907: {
908: return $this->registry->register('Locator', $class, true);
909: }
910:
911: 912: 913:
914: public function set_parser_class($class = 'SimplePie_Parser')
915: {
916: return $this->registry->register('Parser', $class, true);
917: }
918:
919: 920: 921:
922: public function set_file_class($class = 'SimplePie_File')
923: {
924: return $this->registry->register('File', $class, true);
925: }
926:
927: 928: 929:
930: public function set_sanitize_class($class = 'SimplePie_Sanitize')
931: {
932: return $this->registry->register('Sanitize', $class, true);
933: }
934:
935: 936: 937:
938: public function set_item_class($class = 'SimplePie_Item')
939: {
940: return $this->registry->register('Item', $class, true);
941: }
942:
943: 944: 945:
946: public function set_author_class($class = 'SimplePie_Author')
947: {
948: return $this->registry->register('Author', $class, true);
949: }
950:
951: 952: 953:
954: public function set_category_class($class = 'SimplePie_Category')
955: {
956: return $this->registry->register('Category', $class, true);
957: }
958:
959: 960: 961:
962: public function set_enclosure_class($class = 'SimplePie_Enclosure')
963: {
964: return $this->registry->register('Enclosure', $class, true);
965: }
966:
967: 968: 969:
970: public function set_caption_class($class = 'SimplePie_Caption')
971: {
972: return $this->registry->register('Caption', $class, true);
973: }
974:
975: 976: 977:
978: public function set_copyright_class($class = 'SimplePie_Copyright')
979: {
980: return $this->registry->register('Copyright', $class, true);
981: }
982:
983: 984: 985:
986: public function set_credit_class($class = 'SimplePie_Credit')
987: {
988: return $this->registry->register('Credit', $class, true);
989: }
990:
991: 992: 993:
994: public function set_rating_class($class = 'SimplePie_Rating')
995: {
996: return $this->registry->register('Rating', $class, true);
997: }
998:
999: 1000: 1001:
1002: public function set_restriction_class($class = 'SimplePie_Restriction')
1003: {
1004: return $this->registry->register('Restriction', $class, true);
1005: }
1006:
1007: 1008: 1009:
1010: public function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer')
1011: {
1012: return $this->registry->register('Content_Type_Sniffer', $class, true);
1013: }
1014:
1015: 1016: 1017:
1018: public function set_source_class($class = 'SimplePie_Source')
1019: {
1020: return $this->registry->register('Source', $class, true);
1021: }
1022:
1023:
1024: 1025: 1026: 1027: 1028:
1029: public function set_useragent($ua = SIMPLEPIE_USERAGENT)
1030: {
1031: $this->useragent = (string) $ua;
1032: }
1033:
1034: 1035: 1036: 1037: 1038:
1039: public function set_cache_name_function($function = 'md5')
1040: {
1041: if (is_callable($function))
1042: {
1043: $this->cache_name_function = $function;
1044: }
1045: }
1046:
1047: 1048: 1049: 1050: 1051: 1052: 1053: 1054:
1055: public function set_stupidly_fast($set = false)
1056: {
1057: if ($set)
1058: {
1059: $this->enable_order_by_date(false);
1060: $this->remove_div(false);
1061: $this->strip_comments(false);
1062: $this->strip_htmltags(false);
1063: $this->strip_attributes(false);
1064: $this->set_image_handler(false);
1065: }
1066: }
1067:
1068: 1069: 1070: 1071: 1072:
1073: public function set_max_checked_feeds($max = 10)
1074: {
1075: $this->max_checked_feeds = (int) $max;
1076: }
1077:
1078: public function remove_div($enable = true)
1079: {
1080: $this->sanitize->remove_div($enable);
1081: }
1082:
1083: public function strip_htmltags($tags = '', $encode = null)
1084: {
1085: if ($tags === '')
1086: {
1087: $tags = $this->strip_htmltags;
1088: }
1089: $this->sanitize->strip_htmltags($tags);
1090: if ($encode !== null)
1091: {
1092: $this->sanitize->encode_instead_of_strip($tags);
1093: }
1094: }
1095:
1096: public function encode_instead_of_strip($enable = true)
1097: {
1098: $this->sanitize->encode_instead_of_strip($enable);
1099: }
1100:
1101: public function strip_attributes($attribs = '')
1102: {
1103: if ($attribs === '')
1104: {
1105: $attribs = $this->strip_attributes;
1106: }
1107: $this->sanitize->strip_attributes($attribs);
1108: }
1109:
1110: 1111: 1112: 1113: 1114: 1115: 1116: 1117: 1118: 1119: 1120: 1121: 1122: 1123: 1124: 1125: 1126: 1127: 1128: 1129: 1130: 1131:
1132: public function set_output_encoding($encoding = 'UTF-8')
1133: {
1134: $this->sanitize->set_output_encoding($encoding);
1135: }
1136:
1137: public function strip_comments($strip = false)
1138: {
1139: $this->sanitize->strip_comments($strip);
1140: }
1141:
1142: 1143: 1144: 1145: 1146: 1147: 1148: 1149: 1150: 1151: 1152:
1153: public function set_url_replacements($element_attribute = null)
1154: {
1155: $this->sanitize->set_url_replacements($element_attribute);
1156: }
1157:
1158: 1159: 1160: 1161: 1162: 1163:
1164: public function set_image_handler($page = false, $qs = 'i')
1165: {
1166: if ($page !== false)
1167: {
1168: $this->sanitize->set_image_handler($page . '?' . $qs . '=');
1169: }
1170: else
1171: {
1172: $this->image_handler = '';
1173: }
1174: }
1175:
1176: 1177: 1178: 1179: 1180:
1181: public function set_item_limit($limit = 0)
1182: {
1183: $this->item_limit = (int) $limit;
1184: }
1185:
1186: 1187: 1188: 1189: 1190: 1191: 1192: 1193: 1194:
1195: public function init()
1196: {
1197:
1198: if (!extension_loaded('xml') || !extension_loaded('pcre'))
1199: {
1200: return false;
1201: }
1202:
1203: elseif (!extension_loaded('xmlreader'))
1204: {
1205: static $xml_is_sane = null;
1206: if ($xml_is_sane === null)
1207: {
1208: $parser_check = xml_parser_create();
1209: xml_parse_into_struct($parser_check, '<foo>&</foo>', $values);
1210: xml_parser_free($parser_check);
1211: $xml_is_sane = isset($values[0]['value']);
1212: }
1213: if (!$xml_is_sane)
1214: {
1215: return false;
1216: }
1217: }
1218:
1219: if (method_exists($this->sanitize, 'set_registry'))
1220: {
1221: $this->sanitize->set_registry($this->registry);
1222: }
1223:
1224:
1225:
1226: $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache'));
1227: $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen);
1228:
1229: if (!empty($this->multifeed_url))
1230: {
1231: $i = 0;
1232: $success = 0;
1233: $this->multifeed_objects = array();
1234: $this->error = array();
1235: foreach ($this->multifeed_url as $url)
1236: {
1237: $this->multifeed_objects[$i] = clone $this;
1238: $this->multifeed_objects[$i]->set_feed_url($url);
1239: $single_success = $this->multifeed_objects[$i]->init();
1240: $success |= $single_success;
1241: if (!$single_success)
1242: {
1243: $this->error[$i] = $this->multifeed_objects[$i]->error();
1244: }
1245: $i++;
1246: }
1247: return (bool) $success;
1248: }
1249: elseif ($this->feed_url === null && $this->raw_data === null)
1250: {
1251: return false;
1252: }
1253:
1254: $this->error = null;
1255: $this->data = array();
1256: $this->multifeed_objects = array();
1257: $cache = false;
1258:
1259: if ($this->feed_url !== null)
1260: {
1261: $parsed_feed_url = $this->registry->call('Misc', 'parse_url', array($this->feed_url));
1262:
1263:
1264: if ($this->cache && $parsed_feed_url['scheme'] !== '')
1265: {
1266: $cache = $this->registry->call('Cache', 'create', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc'));
1267: }
1268:
1269:
1270: if (($fetched = $this->fetch_data($cache)) === true)
1271: {
1272: return true;
1273: }
1274: elseif ($fetched === false) {
1275: return false;
1276: }
1277:
1278: list($headers, $sniffed) = $fetched;
1279: }
1280:
1281:
1282: $encodings = array();
1283:
1284:
1285: if ($this->input_encoding !== false)
1286: {
1287: $encodings[] = $this->input_encoding;
1288: }
1289:
1290: $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
1291: $text_types = array('text/xml', 'text/xml-external-parsed-entity');
1292:
1293:
1294: if (isset($sniffed))
1295: {
1296: if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml')
1297: {
1298: if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
1299: {
1300: $encodings[] = strtoupper($charset[1]);
1301: }
1302: $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
1303: $encodings[] = 'UTF-8';
1304: }
1305: elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
1306: {
1307: if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
1308: {
1309: $encodings[] = $charset[1];
1310: }
1311: $encodings[] = 'US-ASCII';
1312: }
1313:
1314: elseif (substr($sniffed, 0, 5) === 'text/')
1315: {
1316: $encodings[] = 'US-ASCII';
1317: }
1318: }
1319:
1320:
1321: $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
1322: $encodings[] = 'UTF-8';
1323: $encodings[] = 'ISO-8859-1';
1324:
1325:
1326: $encodings = array_unique($encodings);
1327:
1328:
1329: foreach ($encodings as $encoding)
1330: {
1331:
1332: if ($utf8_data = $this->registry->call('Misc', 'change_encoding', array($this->raw_data, $encoding, 'UTF-8')))
1333: {
1334:
1335: $parser = $this->registry->create('Parser');
1336:
1337:
1338: if ($parser->parse($utf8_data, 'UTF-8'))
1339: {
1340: $this->data = $parser->get_data();
1341: if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE))
1342: {
1343: $this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";
1344: $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
1345: return false;
1346: }
1347:
1348: if (isset($headers))
1349: {
1350: $this->data['headers'] = $headers;
1351: }
1352: $this->data['build'] = SIMPLEPIE_BUILD;
1353:
1354:
1355: if ($cache && !$cache->save($this))
1356: {
1357: 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);
1358: }
1359: return true;
1360: }
1361: }
1362: }
1363:
1364: if (isset($parser))
1365: {
1366:
1367: $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());
1368: }
1369: else
1370: {
1371: $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.';
1372: }
1373:
1374: $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
1375:
1376: return false;
1377: }
1378:
1379: 1380: 1381: 1382: 1383: 1384: 1385:
1386: protected function fetch_data(&$cache)
1387: {
1388:
1389: if ($cache)
1390: {
1391:
1392: $this->data = $cache->load();
1393: if (!empty($this->data))
1394: {
1395:
1396: if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD)
1397: {
1398: $cache->unlink();
1399: $this->data = array();
1400: }
1401:
1402: elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url)
1403: {
1404: $cache = false;
1405: $this->data = array();
1406: }
1407:
1408: elseif (isset($this->data['feed_url']))
1409: {
1410:
1411: if ($cache->mtime() + $this->autodiscovery_cache_duration > time())
1412: {
1413:
1414: if ($this->data['feed_url'] !== $this->data['url'])
1415: {
1416: $this->set_feed_url($this->data['feed_url']);
1417: return $this->init();
1418: }
1419:
1420: $cache->unlink();
1421: $this->data = array();
1422: }
1423: }
1424:
1425: elseif ($cache->mtime() + $this->cache_duration < time())
1426: {
1427:
1428: if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag']))
1429: {
1430: $headers = array(
1431: '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',
1432: );
1433: if (isset($this->data['headers']['last-modified']))
1434: {
1435: $headers['if-modified-since'] = $this->data['headers']['last-modified'];
1436: }
1437: if (isset($this->data['headers']['etag']))
1438: {
1439: $headers['if-none-match'] = $this->data['headers']['etag'];
1440: }
1441:
1442: $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen));
1443:
1444: if ($file->success)
1445: {
1446: if ($file->status_code === 304)
1447: {
1448: $cache->touch();
1449: return true;
1450: }
1451: }
1452: else
1453: {
1454: unset($file);
1455: }
1456: }
1457: }
1458:
1459: else
1460: {
1461: $this->raw_data = false;
1462: return true;
1463: }
1464: }
1465:
1466: else
1467: {
1468: $cache->unlink();
1469: $this->data = array();
1470: }
1471: }
1472:
1473: if (!isset($file))
1474: {
1475: if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url)
1476: {
1477: $file =& $this->file;
1478: }
1479: else
1480: {
1481: $headers = array(
1482: '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',
1483: );
1484: $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen));
1485: }
1486: }
1487:
1488: if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
1489: {
1490: $this->error = $file->error;
1491: return !empty($this->data);
1492: }
1493:
1494: if (!$this->force_feed)
1495: {
1496:
1497: $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds));
1498:
1499: if (!$locate->is_feed($file))
1500: {
1501:
1502: unset($file);
1503: if (!($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds)))
1504: {
1505: $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.";
1506: $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
1507: return false;
1508: }
1509: if ($cache)
1510: {
1511: $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
1512: if (!$cache->save($this))
1513: {
1514: 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);
1515: }
1516: $cache = $this->registry->call('Cache', 'create', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc'));
1517: }
1518: $this->feed_url = $file->url;
1519: }
1520: $locate = null;
1521: }
1522:
1523: $this->raw_data = $file->body;
1524:
1525: $headers = $file->headers;
1526: $sniffer = $this->registry->create('Content_Type_Sniffer', array(&$file));
1527: $sniffed = $sniffer->get_type();
1528:
1529: return array($headers, $sniffed);
1530: }
1531:
1532: 1533: 1534: 1535: 1536:
1537: public function error()
1538: {
1539: return $this->error;
1540: }
1541:
1542: 1543: 1544: 1545: 1546: 1547: 1548: 1549:
1550: public function get_raw_data()
1551: {
1552: return $this->raw_data;
1553: }
1554:
1555: 1556: 1557: 1558: 1559: 1560:
1561: public function get_encoding()
1562: {
1563: return $this->sanitize->output_encoding;
1564: }
1565:
1566: 1567: 1568: 1569: 1570: 1571: 1572: 1573: 1574: 1575: 1576: 1577: 1578: 1579: 1580: 1581: 1582: 1583: 1584:
1585: public function handle_content_type($mime = 'text/html')
1586: {
1587: if (!headers_sent())
1588: {
1589: $header = "Content-type: $mime;";
1590: if ($this->get_encoding())
1591: {
1592: $header .= ' charset=' . $this->get_encoding();
1593: }
1594: else
1595: {
1596: $header .= ' charset=UTF-8';
1597: }
1598: header($header);
1599: }
1600: }
1601:
1602: 1603: 1604: 1605: 1606: 1607: 1608: 1609: 1610: 1611: 1612: 1613: 1614: 1615: 1616: 1617: 1618: 1619: 1620: 1621: 1622: 1623: 1624: 1625: 1626: 1627:
1628: public function get_type()
1629: {
1630: if (!isset($this->data['type']))
1631: {
1632: $this->data['type'] = SIMPLEPIE_TYPE_ALL;
1633: if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed']))
1634: {
1635: $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;
1636: }
1637: elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed']))
1638: {
1639: $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;
1640: }
1641: elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF']))
1642: {
1643: if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel'])
1644: || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image'])
1645: || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])
1646: || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput']))
1647: {
1648: $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10;
1649: }
1650: if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel'])
1651: || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image'])
1652: || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])
1653: || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput']))
1654: {
1655: $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;
1656: }
1657: }
1658: elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss']))
1659: {
1660: $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;
1661: if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
1662: {
1663: switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
1664: {
1665: case '0.91':
1666: $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091;
1667: if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
1668: {
1669: switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
1670: {
1671: case '0':
1672: $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE;
1673: break;
1674:
1675: case '24':
1676: $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND;
1677: break;
1678: }
1679: }
1680: break;
1681:
1682: case '0.92':
1683: $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092;
1684: break;
1685:
1686: case '0.93':
1687: $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093;
1688: break;
1689:
1690: case '0.94':
1691: $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094;
1692: break;
1693:
1694: case '2.0':
1695: $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20;
1696: break;
1697: }
1698: }
1699: }
1700: else
1701: {
1702: $this->data['type'] = SIMPLEPIE_TYPE_NONE;
1703: }
1704: }
1705: return $this->data['type'];
1706: }
1707:
1708: 1709: 1710: 1711: 1712: 1713: 1714: 1715: 1716: 1717: 1718: 1719:
1720: public function subscribe_url()
1721: {
1722: if ($this->feed_url !== null)
1723: {
1724: return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI);
1725: }
1726: else
1727: {
1728: return null;
1729: }
1730: }
1731:
1732: 1733: 1734: 1735: 1736: 1737: 1738: 1739: 1740: 1741: 1742: 1743: 1744: 1745: 1746: 1747: 1748: 1749: 1750: 1751: 1752: 1753: 1754: 1755: 1756: 1757: 1758: 1759: 1760: 1761: 1762:
1763: public function get_feed_tags($namespace, $tag)
1764: {
1765: $type = $this->get_type();
1766: if ($type & SIMPLEPIE_TYPE_ATOM_10)
1767: {
1768: if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]))
1769: {
1770: return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag];
1771: }
1772: }
1773: if ($type & SIMPLEPIE_TYPE_ATOM_03)
1774: {
1775: if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]))
1776: {
1777: return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag];
1778: }
1779: }
1780: if ($type & SIMPLEPIE_TYPE_RSS_RDF)
1781: {
1782: if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]))
1783: {
1784: return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag];
1785: }
1786: }
1787: if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
1788: {
1789: if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag]))
1790: {
1791: return $this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag];
1792: }
1793: }
1794: return null;
1795: }
1796:
1797: 1798: 1799: 1800: 1801: 1802: 1803: 1804: 1805: 1806: 1807: 1808: 1809: 1810:
1811: public function get_channel_tags($namespace, $tag)
1812: {
1813: $type = $this->get_type();
1814: if ($type & SIMPLEPIE_TYPE_ATOM_ALL)
1815: {
1816: if ($return = $this->get_feed_tags($namespace, $tag))
1817: {
1818: return $return;
1819: }
1820: }
1821: if ($type & SIMPLEPIE_TYPE_RSS_10)
1822: {
1823: if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel'))
1824: {
1825: if (isset($channel[0]['child'][$namespace][$tag]))
1826: {
1827: return $channel[0]['child'][$namespace][$tag];
1828: }
1829: }
1830: }
1831: if ($type & SIMPLEPIE_TYPE_RSS_090)
1832: {
1833: if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel'))
1834: {
1835: if (isset($channel[0]['child'][$namespace][$tag]))
1836: {
1837: return $channel[0]['child'][$namespace][$tag];
1838: }
1839: }
1840: }
1841: if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
1842: {
1843: if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'channel'))
1844: {
1845: if (isset($channel[0]['child'][$namespace][$tag]))
1846: {
1847: return $channel[0]['child'][$namespace][$tag];
1848: }
1849: }
1850: }
1851: return null;
1852: }
1853:
1854: 1855: 1856: 1857: 1858: 1859: 1860: 1861: 1862: 1863: 1864: 1865: 1866: 1867:
1868: public function get_image_tags($namespace, $tag)
1869: {
1870: $type = $this->get_type();
1871: if ($type & SIMPLEPIE_TYPE_RSS_10)
1872: {
1873: if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image'))
1874: {
1875: if (isset($image[0]['child'][$namespace][$tag]))
1876: {
1877: return $image[0]['child'][$namespace][$tag];
1878: }
1879: }
1880: }
1881: if ($type & SIMPLEPIE_TYPE_RSS_090)
1882: {
1883: if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image'))
1884: {
1885: if (isset($image[0]['child'][$namespace][$tag]))
1886: {
1887: return $image[0]['child'][$namespace][$tag];
1888: }
1889: }
1890: }
1891: if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
1892: {
1893: if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'image'))
1894: {
1895: if (isset($image[0]['child'][$namespace][$tag]))
1896: {
1897: return $image[0]['child'][$namespace][$tag];
1898: }
1899: }
1900: }
1901: return null;
1902: }
1903:
1904: 1905: 1906: 1907: 1908: 1909: 1910: 1911: 1912: 1913: 1914: 1915:
1916: public function get_base($element = array())
1917: {
1918: if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
1919: {
1920: return $element['xml_base'];
1921: }
1922: elseif ($this->get_link() !== null)
1923: {
1924: return $this->get_link();
1925: }
1926: else
1927: {
1928: return $this->subscribe_url();
1929: }
1930: }
1931:
1932: 1933: 1934: 1935: 1936: 1937: 1938: 1939: 1940: 1941:
1942: public function sanitize($data, $type, $base = '')
1943: {
1944: return $this->sanitize->sanitize($data, $type, $base);
1945: }
1946:
1947: 1948: 1949: 1950: 1951: 1952: 1953: 1954:
1955: public function get_title()
1956: {
1957: if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
1958: {
1959: return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
1960: }
1961: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
1962: {
1963: return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
1964: }
1965: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
1966: {
1967: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
1968: }
1969: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
1970: {
1971: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
1972: }
1973: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
1974: {
1975: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
1976: }
1977: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
1978: {
1979: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1980: }
1981: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
1982: {
1983: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1984: }
1985: else
1986: {
1987: return null;
1988: }
1989: }
1990:
1991: 1992: 1993: 1994: 1995: 1996: 1997:
1998: public function get_category($key = 0)
1999: {
2000: $categories = $this->get_categories();
2001: if (isset($categories[$key]))
2002: {
2003: return $categories[$key];
2004: }
2005: else
2006: {
2007: return null;
2008: }
2009: }
2010:
2011: 2012: 2013: 2014: 2015: 2016: 2017: 2018:
2019: public function get_categories()
2020: {
2021: $categories = array();
2022:
2023: foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
2024: {
2025: $term = null;
2026: $scheme = null;
2027: $label = null;
2028: if (isset($category['attribs']['']['term']))
2029: {
2030: $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
2031: }
2032: if (isset($category['attribs']['']['scheme']))
2033: {
2034: $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
2035: }
2036: if (isset($category['attribs']['']['label']))
2037: {
2038: $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
2039: }
2040: $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
2041: }
2042: foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
2043: {
2044:
2045:
2046: $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2047: if (isset($category['attribs']['']['domain']))
2048: {
2049: $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
2050: }
2051: else
2052: {
2053: $scheme = null;
2054: }
2055: $categories[] = $this->registry->create('Category', array($term, $scheme, null));
2056: }
2057: foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
2058: {
2059: $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2060: }
2061: foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
2062: {
2063: $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2064: }
2065:
2066: if (!empty($categories))
2067: {
2068: return array_unique($categories);
2069: }
2070: else
2071: {
2072: return null;
2073: }
2074: }
2075:
2076: 2077: 2078: 2079: 2080: 2081: 2082:
2083: public function get_author($key = 0)
2084: {
2085: $authors = $this->get_authors();
2086: if (isset($authors[$key]))
2087: {
2088: return $authors[$key];
2089: }
2090: else
2091: {
2092: return null;
2093: }
2094: }
2095:
2096: 2097: 2098: 2099: 2100: 2101: 2102: 2103:
2104: public function get_authors()
2105: {
2106: $authors = array();
2107: foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
2108: {
2109: $name = null;
2110: $uri = null;
2111: $email = null;
2112: if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
2113: {
2114: $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2115: }
2116: if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
2117: {
2118: $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]));
2119: }
2120: if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
2121: {
2122: $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2123: }
2124: if ($name !== null || $email !== null || $uri !== null)
2125: {
2126: $authors[] = $this->registry->create('Author', array($name, $uri, $email));
2127: }
2128: }
2129: if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
2130: {
2131: $name = null;
2132: $url = null;
2133: $email = null;
2134: if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
2135: {
2136: $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2137: }
2138: if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
2139: {
2140: $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]));
2141: }
2142: if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
2143: {
2144: $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2145: }
2146: if ($name !== null || $email !== null || $url !== null)
2147: {
2148: $authors[] = $this->registry->create('Author', array($name, $url, $email));
2149: }
2150: }
2151: foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
2152: {
2153: $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2154: }
2155: foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
2156: {
2157: $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2158: }
2159: foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
2160: {
2161: $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2162: }
2163:
2164: if (!empty($authors))
2165: {
2166: return array_unique($authors);
2167: }
2168: else
2169: {
2170: return null;
2171: }
2172: }
2173:
2174: 2175: 2176: 2177: 2178: 2179: 2180:
2181: public function get_contributor($key = 0)
2182: {
2183: $contributors = $this->get_contributors();
2184: if (isset($contributors[$key]))
2185: {
2186: return $contributors[$key];
2187: }
2188: else
2189: {
2190: return null;
2191: }
2192: }
2193:
2194: 2195: 2196: 2197: 2198: 2199: 2200: 2201:
2202: public function get_contributors()
2203: {
2204: $contributors = array();
2205: foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
2206: {
2207: $name = null;
2208: $uri = null;
2209: $email = null;
2210: if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
2211: {
2212: $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2213: }
2214: if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
2215: {
2216: $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]));
2217: }
2218: if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
2219: {
2220: $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2221: }
2222: if ($name !== null || $email !== null || $uri !== null)
2223: {
2224: $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
2225: }
2226: }
2227: foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
2228: {
2229: $name = null;
2230: $url = null;
2231: $email = null;
2232: if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
2233: {
2234: $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2235: }
2236: if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
2237: {
2238: $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]));
2239: }
2240: if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
2241: {
2242: $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2243: }
2244: if ($name !== null || $email !== null || $url !== null)
2245: {
2246: $contributors[] = $this->registry->create('Author', array($name, $url, $email));
2247: }
2248: }
2249:
2250: if (!empty($contributors))
2251: {
2252: return array_unique($contributors);
2253: }
2254: else
2255: {
2256: return null;
2257: }
2258: }
2259:
2260: 2261: 2262: 2263: 2264: 2265: 2266: 2267:
2268: public function get_link($key = 0, $rel = 'alternate')
2269: {
2270: $links = $this->get_links($rel);
2271: if (isset($links[$key]))
2272: {
2273: return $links[$key];
2274: }
2275: else
2276: {
2277: return null;
2278: }
2279: }
2280:
2281: 2282: 2283: 2284: 2285: 2286: 2287: 2288: 2289: 2290: 2291:
2292: public function get_permalink()
2293: {
2294: return $this->get_link(0);
2295: }
2296:
2297: 2298: 2299: 2300: 2301: 2302: 2303: 2304: 2305:
2306: public function get_links($rel = 'alternate')
2307: {
2308: if (!isset($this->data['links']))
2309: {
2310: $this->data['links'] = array();
2311: if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
2312: {
2313: foreach ($links as $link)
2314: {
2315: if (isset($link['attribs']['']['href']))
2316: {
2317: $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
2318: $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
2319: }
2320: }
2321: }
2322: if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
2323: {
2324: foreach ($links as $link)
2325: {
2326: if (isset($link['attribs']['']['href']))
2327: {
2328: $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
2329: $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
2330:
2331: }
2332: }
2333: }
2334: if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
2335: {
2336: $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
2337: }
2338: if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
2339: {
2340: $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
2341: }
2342: if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
2343: {
2344: $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
2345: }
2346:
2347: $keys = array_keys($this->data['links']);
2348: foreach ($keys as $key)
2349: {
2350: if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
2351: {
2352: if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
2353: {
2354: $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
2355: $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
2356: }
2357: else
2358: {
2359: $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
2360: }
2361: }
2362: elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
2363: {
2364: $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
2365: }
2366: $this->data['links'][$key] = array_unique($this->data['links'][$key]);
2367: }
2368: }
2369:
2370: if (isset($this->data['links'][$rel]))
2371: {
2372: return $this->data['links'][$rel];
2373: }
2374: else
2375: {
2376: return null;
2377: }
2378: }
2379:
2380: public function get_all_discovered_feeds()
2381: {
2382: return $this->all_discovered_feeds;
2383: }
2384:
2385: 2386: 2387: 2388: 2389: 2390: 2391: 2392: 2393:
2394: public function get_description()
2395: {
2396: if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
2397: {
2398: return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2399: }
2400: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
2401: {
2402: return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2403: }
2404: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
2405: {
2406: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2407: }
2408: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
2409: {
2410: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2411: }
2412: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
2413: {
2414: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
2415: }
2416: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
2417: {
2418: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2419: }
2420: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
2421: {
2422: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2423: }
2424: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
2425: {
2426: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
2427: }
2428: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
2429: {
2430: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
2431: }
2432: else
2433: {
2434: return null;
2435: }
2436: }
2437:
2438: 2439: 2440: 2441: 2442: 2443: 2444: 2445:
2446: public function get_copyright()
2447: {
2448: if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
2449: {
2450: return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2451: }
2452: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
2453: {
2454: return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2455: }
2456: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
2457: {
2458: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2459: }
2460: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
2461: {
2462: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2463: }
2464: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
2465: {
2466: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2467: }
2468: else
2469: {
2470: return null;
2471: }
2472: }
2473:
2474: 2475: 2476: 2477: 2478: 2479: 2480: 2481:
2482: public function get_language()
2483: {
2484: if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
2485: {
2486: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2487: }
2488: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
2489: {
2490: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2491: }
2492: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
2493: {
2494: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2495: }
2496: elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang']))
2497: {
2498: return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2499: }
2500: elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang']))
2501: {
2502: return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2503: }
2504: elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang']))
2505: {
2506: return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2507: }
2508: elseif (isset($this->data['headers']['content-language']))
2509: {
2510: return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT);
2511: }
2512: else
2513: {
2514: return null;
2515: }
2516: }
2517:
2518: 2519: 2520: 2521: 2522: 2523: 2524: 2525: 2526: 2527: 2528: 2529:
2530: public function get_latitude()
2531: {
2532:
2533: if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
2534: {
2535: return (float) $return[0]['data'];
2536: }
2537: 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))
2538: {
2539: return (float) $match[1];
2540: }
2541: else
2542: {
2543: return null;
2544: }
2545: }
2546:
2547: 2548: 2549: 2550: 2551: 2552: 2553: 2554: 2555: 2556: 2557: 2558:
2559: public function get_longitude()
2560: {
2561: if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
2562: {
2563: return (float) $return[0]['data'];
2564: }
2565: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
2566: {
2567: return (float) $return[0]['data'];
2568: }
2569: 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))
2570: {
2571: return (float) $match[2];
2572: }
2573: else
2574: {
2575: return null;
2576: }
2577: }
2578:
2579: 2580: 2581: 2582: 2583: 2584: 2585: 2586: 2587:
2588: public function get_image_title()
2589: {
2590: if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
2591: {
2592: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2593: }
2594: elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
2595: {
2596: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2597: }
2598: elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
2599: {
2600: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2601: }
2602: elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
2603: {
2604: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2605: }
2606: elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
2607: {
2608: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2609: }
2610: else
2611: {
2612: return null;
2613: }
2614: }
2615:
2616: 2617: 2618: 2619: 2620: 2621: 2622: 2623: 2624: 2625: 2626:
2627: public function get_image_url()
2628: {
2629: if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
2630: {
2631: return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
2632: }
2633: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
2634: {
2635: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2636: }
2637: elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
2638: {
2639: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2640: }
2641: elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url'))
2642: {
2643: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2644: }
2645: elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url'))
2646: {
2647: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2648: }
2649: elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2650: {
2651: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2652: }
2653: else
2654: {
2655: return null;
2656: }
2657: }
2658:
2659:
2660: 2661: 2662: 2663: 2664: 2665: 2666: 2667: 2668: 2669: 2670:
2671: public function get_image_link()
2672: {
2673: if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
2674: {
2675: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2676: }
2677: elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
2678: {
2679: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2680: }
2681: elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
2682: {
2683: return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2684: }
2685: else
2686: {
2687: return null;
2688: }
2689: }
2690:
2691: 2692: 2693: 2694: 2695: 2696: 2697: 2698: 2699: 2700:
2701: public function get_image_width()
2702: {
2703: if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width'))
2704: {
2705: return round($return[0]['data']);
2706: }
2707: elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2708: {
2709: return 88.0;
2710: }
2711: else
2712: {
2713: return null;
2714: }
2715: }
2716:
2717: 2718: 2719: 2720: 2721: 2722: 2723: 2724: 2725: 2726:
2727: public function get_image_height()
2728: {
2729: if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'height'))
2730: {
2731: return round($return[0]['data']);
2732: }
2733: elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2734: {
2735: return 31.0;
2736: }
2737: else
2738: {
2739: return null;
2740: }
2741: }
2742:
2743: 2744: 2745: 2746: 2747: 2748: 2749: 2750: 2751:
2752: public function get_item_quantity($max = 0)
2753: {
2754: $max = (int) $max;
2755: $qty = count($this->get_items());
2756: if ($max === 0)
2757: {
2758: return $qty;
2759: }
2760: else
2761: {
2762: return ($qty > $max) ? $max : $qty;
2763: }
2764: }
2765:
2766: 2767: 2768: 2769: 2770: 2771: 2772: 2773: 2774: 2775: 2776: 2777:
2778: public function get_item($key = 0)
2779: {
2780: $items = $this->get_items();
2781: if (isset($items[$key]))
2782: {
2783: return $items[$key];
2784: }
2785: else
2786: {
2787: return null;
2788: }
2789: }
2790:
2791: 2792: 2793: 2794: 2795: 2796: 2797: 2798: 2799: 2800: 2801: 2802: 2803:
2804: public function get_items($start = 0, $end = 0)
2805: {
2806: if (!isset($this->data['items']))
2807: {
2808: if (!empty($this->multifeed_objects))
2809: {
2810: $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit);
2811: }
2812: else
2813: {
2814: $this->data['items'] = array();
2815: if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry'))
2816: {
2817: $keys = array_keys($items);
2818: foreach ($keys as $key)
2819: {
2820: $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
2821: }
2822: }
2823: if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry'))
2824: {
2825: $keys = array_keys($items);
2826: foreach ($keys as $key)
2827: {
2828: $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
2829: }
2830: }
2831: if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item'))
2832: {
2833: $keys = array_keys($items);
2834: foreach ($keys as $key)
2835: {
2836: $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
2837: }
2838: }
2839: if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item'))
2840: {
2841: $keys = array_keys($items);
2842: foreach ($keys as $key)
2843: {
2844: $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
2845: }
2846: }
2847: if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item'))
2848: {
2849: $keys = array_keys($items);
2850: foreach ($keys as $key)
2851: {
2852: $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
2853: }
2854: }
2855: }
2856: }
2857:
2858: if (!empty($this->data['items']))
2859: {
2860:
2861: if ($this->order_by_date && empty($this->multifeed_objects))
2862: {
2863: if (!isset($this->data['ordered_items']))
2864: {
2865: $do_sort = true;
2866: foreach ($this->data['items'] as $item)
2867: {
2868: if (!$item->get_date('U'))
2869: {
2870: $do_sort = false;
2871: break;
2872: }
2873: }
2874: $item = null;
2875: $this->data['ordered_items'] = $this->data['items'];
2876: if ($do_sort)
2877: {
2878: usort($this->data['ordered_items'], array(get_class($this), 'sort_items'));
2879: }
2880: }
2881: $items = $this->data['ordered_items'];
2882: }
2883: else
2884: {
2885: $items = $this->data['items'];
2886: }
2887:
2888:
2889: if ($end === 0)
2890: {
2891: return array_slice($items, $start);
2892: }
2893: else
2894: {
2895: return array_slice($items, $start, $end);
2896: }
2897: }
2898: else
2899: {
2900: return array();
2901: }
2902: }
2903:
2904: 2905: 2906: 2907: 2908: 2909: 2910: 2911:
2912: public static function sort_items($a, $b)
2913: {
2914: return $a->get_date('U') <= $b->get_date('U');
2915: }
2916:
2917: 2918: 2919: 2920: 2921: 2922: 2923: 2924: 2925: 2926: 2927: 2928: 2929:
2930: public static function merge_items($urls, $start = 0, $end = 0, $limit = 0)
2931: {
2932: if (is_array($urls) && sizeof($urls) > 0)
2933: {
2934: $items = array();
2935: foreach ($urls as $arg)
2936: {
2937: if ($arg instanceof SimplePie)
2938: {
2939: $items = array_merge($items, $arg->get_items(0, $limit));
2940: }
2941: else
2942: {
2943: trigger_error('Arguments must be SimplePie objects', E_USER_WARNING);
2944: }
2945: }
2946:
2947: $do_sort = true;
2948: foreach ($items as $item)
2949: {
2950: if (!$item->get_date('U'))
2951: {
2952: $do_sort = false;
2953: break;
2954: }
2955: }
2956: $item = null;
2957: if ($do_sort)
2958: {
2959: usort($items, array(get_class($urls[0]), 'sort_items'));
2960: }
2961:
2962: if ($end === 0)
2963: {
2964: return array_slice($items, $start);
2965: }
2966: else
2967: {
2968: return array_slice($items, $start, $end);
2969: }
2970: }
2971: else
2972: {
2973: trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING);
2974: return array();
2975: }
2976: }
2977: }
2978: