|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00049 define('SIMPLEPIE_NAME', 'SimplePie'); 00050 00054 define('SIMPLEPIE_VERSION', '1.3-dev'); 00055 00060 define('SIMPLEPIE_BUILD', gmdate('YmdHis', SimplePie_Misc::parse_date(substr('$Date$', 7, 25)) ? SimplePie_Misc::parse_date(substr('$Date$', 7, 25)) : filemtime(__FILE__))); 00061 00065 define('SIMPLEPIE_URL', 'http://simplepie.org'); 00066 00071 define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD); 00072 00076 define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>'); 00077 00082 define('SIMPLEPIE_LOCATOR_NONE', 0); 00083 00088 define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1); 00089 00094 define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2); 00095 00100 define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4); 00101 00106 define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8); 00107 00112 define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16); 00113 00118 define('SIMPLEPIE_LOCATOR_ALL', 31); 00119 00123 define('SIMPLEPIE_TYPE_NONE', 0); 00124 00128 define('SIMPLEPIE_TYPE_RSS_090', 1); 00129 00133 define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2); 00134 00138 define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4); 00139 00143 define('SIMPLEPIE_TYPE_RSS_091', 6); 00144 00148 define('SIMPLEPIE_TYPE_RSS_092', 8); 00149 00153 define('SIMPLEPIE_TYPE_RSS_093', 16); 00154 00158 define('SIMPLEPIE_TYPE_RSS_094', 32); 00159 00163 define('SIMPLEPIE_TYPE_RSS_10', 64); 00164 00168 define('SIMPLEPIE_TYPE_RSS_20', 128); 00169 00173 define('SIMPLEPIE_TYPE_RSS_RDF', 65); 00174 00178 define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190); 00179 00183 define('SIMPLEPIE_TYPE_RSS_ALL', 255); 00184 00188 define('SIMPLEPIE_TYPE_ATOM_03', 256); 00189 00193 define('SIMPLEPIE_TYPE_ATOM_10', 512); 00194 00198 define('SIMPLEPIE_TYPE_ATOM_ALL', 768); 00199 00203 define('SIMPLEPIE_TYPE_ALL', 1023); 00204 00208 define('SIMPLEPIE_CONSTRUCT_NONE', 0); 00209 00213 define('SIMPLEPIE_CONSTRUCT_TEXT', 1); 00214 00218 define('SIMPLEPIE_CONSTRUCT_HTML', 2); 00219 00223 define('SIMPLEPIE_CONSTRUCT_XHTML', 4); 00224 00228 define('SIMPLEPIE_CONSTRUCT_BASE64', 8); 00229 00233 define('SIMPLEPIE_CONSTRUCT_IRI', 16); 00234 00238 define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32); 00239 00243 define('SIMPLEPIE_CONSTRUCT_ALL', 63); 00244 00248 define('SIMPLEPIE_SAME_CASE', 1); 00249 00253 define('SIMPLEPIE_LOWERCASE', 2); 00254 00258 define('SIMPLEPIE_UPPERCASE', 4); 00259 00263 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]*'); 00264 00268 define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*'); 00269 00273 define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace'); 00274 00278 define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom'); 00279 00283 define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#'); 00284 00288 define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); 00289 00293 define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/'); 00294 00298 define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/'); 00299 00303 define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/'); 00304 00309 define('SIMPLEPIE_NAMESPACE_RSS_20', ''); 00310 00314 define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/'); 00315 00319 define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/'); 00320 00324 define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#'); 00325 00329 define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss'); 00330 00334 define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/'); 00335 00339 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss'); 00340 00344 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2', 'http://video.search.yahoo.com/mrss'); 00345 00349 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3', 'http://video.search.yahoo.com/mrss/'); 00350 00354 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4', 'http://www.rssboard.org/media-rss'); 00355 00359 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5', 'http://www.rssboard.org/media-rss/'); 00360 00364 define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd'); 00365 00369 define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml'); 00370 00374 define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/'); 00375 00379 define('SIMPLEPIE_PHP5', version_compare(PHP_VERSION, '5.0.0', '>=')); 00380 00384 define('SIMPLEPIE_FILE_SOURCE_NONE', 0); 00385 00389 define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1); 00390 00394 define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2); 00395 00399 define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4); 00400 00404 define('SIMPLEPIE_FILE_SOURCE_CURL', 8); 00405 00409 define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16); 00410 00416 class SimplePie 00417 { 00422 public $data = array(); 00423 00428 public $error; 00429 00435 public $sanitize; 00436 00442 public $useragent = SIMPLEPIE_USERAGENT; 00443 00449 public $feed_url; 00450 00456 public $file; 00457 00463 public $raw_data; 00464 00470 public $timeout = 10; 00471 00478 public $force_fsockopen = false; 00479 00486 public $force_feed = false; 00487 00493 public $xml_dump = false; 00494 00500 public $cache = true; 00501 00507 public $cache_duration = 3600; 00508 00514 public $autodiscovery_cache_duration = 604800; // 7 Days. 00515 00521 public $cache_location = './cache'; 00522 00528 public $cache_name_function = 'md5'; 00529 00535 public $order_by_date = true; 00536 00543 public $input_encoding = false; 00544 00550 public $autodiscovery = SIMPLEPIE_LOCATOR_ALL; 00551 00557 public $cache_class = 'SimplePie_Cache'; 00558 00564 public $locator_class = 'SimplePie_Locator'; 00565 00571 public $parser_class = 'SimplePie_Parser'; 00572 00578 public $file_class = 'SimplePie_File'; 00579 00585 public $item_class = 'SimplePie_Item'; 00586 00592 public $author_class = 'SimplePie_Author'; 00593 00599 public $category_class = 'SimplePie_Category'; 00600 00606 public $enclosure_class = 'SimplePie_Enclosure'; 00607 00613 public $caption_class = 'SimplePie_Caption'; 00614 00620 public $copyright_class = 'SimplePie_Copyright'; 00621 00627 public $credit_class = 'SimplePie_Credit'; 00628 00634 public $rating_class = 'SimplePie_Rating'; 00635 00641 public $restriction_class = 'SimplePie_Restriction'; 00642 00648 public $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer'; 00649 00655 public $source_class = 'SimplePie_Source'; 00656 00663 public $javascript = 'js'; 00664 00670 public $max_checked_feeds = 10; 00671 00677 public $all_discovered_feeds = array(); 00678 00684 public $image_handler = ''; 00685 00691 public $multifeed_url = array(); 00692 00697 public $multifeed_objects = array(); 00698 00704 public $config_settings = null; 00705 00711 public $item_limit = 0; 00712 00718 public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'); 00719 00725 public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'); 00726 00745 public function __construct() 00746 { 00747 if (version_compare(PHP_VERSION, '5.0', '<')) 00748 { 00749 trigger_error('PHP 4.x is no longer supported. Please upgrade to PHP 5.2 or newer.'); 00750 die(); 00751 } 00752 00753 // Other objects, instances created here so we can set options on them 00754 $this->sanitize = new SimplePie_Sanitize(); 00755 00756 if (func_num_args() > 0) 00757 { 00758 trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly.'); 00759 } 00760 } 00761 00765 public function __toString() 00766 { 00767 return md5(serialize($this->data)); 00768 } 00769 00773 public function __destruct() 00774 { 00775 if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode')) 00776 { 00777 if (!empty($this->data['items'])) 00778 { 00779 foreach ($this->data['items'] as $item) 00780 { 00781 $item->__destruct(); 00782 } 00783 unset($item, $this->data['items']); 00784 } 00785 if (!empty($this->data['ordered_items'])) 00786 { 00787 foreach ($this->data['ordered_items'] as $item) 00788 { 00789 $item->__destruct(); 00790 } 00791 unset($item, $this->data['ordered_items']); 00792 } 00793 } 00794 } 00795 00804 public function force_feed($enable = false) 00805 { 00806 $this->force_feed = (bool) $enable; 00807 } 00808 00825 public function set_feed_url($url) 00826 { 00827 if (is_array($url)) 00828 { 00829 $this->multifeed_url = array(); 00830 foreach ($url as $value) 00831 { 00832 $this->multifeed_url[] = SimplePie_Misc::fix_protocol($value, 1); 00833 } 00834 } 00835 else 00836 { 00837 $this->feed_url = SimplePie_Misc::fix_protocol($url, 1); 00838 } 00839 } 00840 00848 public function set_file(&$file) 00849 { 00850 if (is_a($file, 'SimplePie_File')) 00851 { 00852 $this->feed_url = $file->url; 00853 $this->file =& $file; 00854 return true; 00855 } 00856 return false; 00857 } 00858 00871 public function set_raw_data($data) 00872 { 00873 $this->raw_data = $data; 00874 } 00875 00886 public function set_timeout($timeout = 10) 00887 { 00888 $this->timeout = (int) $timeout; 00889 } 00890 00899 public function force_fsockopen($enable = false) 00900 { 00901 $this->force_fsockopen = (bool) $enable; 00902 } 00903 00914 public function enable_cache($enable = true) 00915 { 00916 $this->cache = (bool) $enable; 00917 } 00918 00926 public function set_cache_duration($seconds = 3600) 00927 { 00928 $this->cache_duration = (int) $seconds; 00929 } 00930 00938 public function set_autodiscovery_cache_duration($seconds = 604800) 00939 { 00940 $this->autodiscovery_cache_duration = (int) $seconds; 00941 } 00942 00949 public function set_cache_location($location = './cache') 00950 { 00951 $this->cache_location = (string) $location; 00952 } 00953 00960 public function enable_order_by_date($enable = true) 00961 { 00962 $this->order_by_date = (bool) $enable; 00963 } 00964 00971 public function set_input_encoding($encoding = false) 00972 { 00973 if ($encoding) 00974 { 00975 $this->input_encoding = (string) $encoding; 00976 } 00977 else 00978 { 00979 $this->input_encoding = false; 00980 } 00981 } 00982 00997 public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL) 00998 { 00999 $this->autodiscovery = (int) $level; 01000 } 01001 01010 public function set_cache_class($class = 'SimplePie_Cache') 01011 { 01012 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Cache')) 01013 { 01014 $this->cache_class = $class; 01015 return true; 01016 } 01017 return false; 01018 } 01019 01028 public function set_locator_class($class = 'SimplePie_Locator') 01029 { 01030 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Locator')) 01031 { 01032 $this->locator_class = $class; 01033 return true; 01034 } 01035 return false; 01036 } 01037 01046 public function set_parser_class($class = 'SimplePie_Parser') 01047 { 01048 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Parser')) 01049 { 01050 $this->parser_class = $class; 01051 return true; 01052 } 01053 return false; 01054 } 01055 01064 public function set_file_class($class = 'SimplePie_File') 01065 { 01066 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_File')) 01067 { 01068 $this->file_class = $class; 01069 return true; 01070 } 01071 return false; 01072 } 01073 01082 public function set_sanitize_class($class = 'SimplePie_Sanitize') 01083 { 01084 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Sanitize')) 01085 { 01086 $this->sanitize = new $class(); 01087 return true; 01088 } 01089 return false; 01090 } 01091 01100 public function set_item_class($class = 'SimplePie_Item') 01101 { 01102 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Item')) 01103 { 01104 $this->item_class = $class; 01105 return true; 01106 } 01107 return false; 01108 } 01109 01118 public function set_author_class($class = 'SimplePie_Author') 01119 { 01120 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Author')) 01121 { 01122 $this->author_class = $class; 01123 return true; 01124 } 01125 return false; 01126 } 01127 01136 public function set_category_class($class = 'SimplePie_Category') 01137 { 01138 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Category')) 01139 { 01140 $this->category_class = $class; 01141 return true; 01142 } 01143 return false; 01144 } 01145 01154 public function set_enclosure_class($class = 'SimplePie_Enclosure') 01155 { 01156 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Enclosure')) 01157 { 01158 $this->enclosure_class = $class; 01159 return true; 01160 } 01161 return false; 01162 } 01163 01172 public function set_caption_class($class = 'SimplePie_Caption') 01173 { 01174 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Caption')) 01175 { 01176 $this->caption_class = $class; 01177 return true; 01178 } 01179 return false; 01180 } 01181 01190 public function set_copyright_class($class = 'SimplePie_Copyright') 01191 { 01192 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Copyright')) 01193 { 01194 $this->copyright_class = $class; 01195 return true; 01196 } 01197 return false; 01198 } 01199 01208 public function set_credit_class($class = 'SimplePie_Credit') 01209 { 01210 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Credit')) 01211 { 01212 $this->credit_class = $class; 01213 return true; 01214 } 01215 return false; 01216 } 01217 01226 public function set_rating_class($class = 'SimplePie_Rating') 01227 { 01228 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Rating')) 01229 { 01230 $this->rating_class = $class; 01231 return true; 01232 } 01233 return false; 01234 } 01235 01244 public function set_restriction_class($class = 'SimplePie_Restriction') 01245 { 01246 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Restriction')) 01247 { 01248 $this->restriction_class = $class; 01249 return true; 01250 } 01251 return false; 01252 } 01253 01262 public function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer') 01263 { 01264 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Content_Type_Sniffer')) 01265 { 01266 $this->content_type_sniffer_class = $class; 01267 return true; 01268 } 01269 return false; 01270 } 01271 01280 public function set_source_class($class = 'SimplePie_Source') 01281 { 01282 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Source')) 01283 { 01284 $this->source_class = $class; 01285 return true; 01286 } 01287 return false; 01288 } 01289 01296 public function set_useragent($ua = SIMPLEPIE_USERAGENT) 01297 { 01298 $this->useragent = (string) $ua; 01299 } 01300 01307 public function set_cache_name_function($function = 'md5') 01308 { 01309 if (is_callable($function)) 01310 { 01311 $this->cache_name_function = $function; 01312 } 01313 } 01314 01321 public function set_javascript($get = 'js') 01322 { 01323 if ($get) 01324 { 01325 $this->javascript = (string) $get; 01326 } 01327 else 01328 { 01329 $this->javascript = false; 01330 } 01331 } 01332 01340 public function set_stupidly_fast($set = false) 01341 { 01342 if ($set) 01343 { 01344 $this->enable_order_by_date(false); 01345 $this->remove_div(false); 01346 $this->strip_comments(false); 01347 $this->strip_htmltags(false); 01348 $this->strip_attributes(false); 01349 $this->set_image_handler(false); 01350 } 01351 } 01352 01359 public function set_max_checked_feeds($max = 10) 01360 { 01361 $this->max_checked_feeds = (int) $max; 01362 } 01363 01364 public function remove_div($enable = true) 01365 { 01366 $this->sanitize->remove_div($enable); 01367 } 01368 01369 public function strip_htmltags($tags = '', $encode = null) 01370 { 01371 if ($tags === '') 01372 { 01373 $tags = $this->strip_htmltags; 01374 } 01375 $this->sanitize->strip_htmltags($tags); 01376 if ($encode !== null) 01377 { 01378 $this->sanitize->encode_instead_of_strip($tags); 01379 } 01380 } 01381 01382 public function encode_instead_of_strip($enable = true) 01383 { 01384 $this->sanitize->encode_instead_of_strip($enable); 01385 } 01386 01387 public function strip_attributes($attribs = '') 01388 { 01389 if ($attribs === '') 01390 { 01391 $attribs = $this->strip_attributes; 01392 } 01393 $this->sanitize->strip_attributes($attribs); 01394 } 01395 01396 public function set_output_encoding($encoding = 'UTF-8') 01397 { 01398 $this->sanitize->set_output_encoding($encoding); 01399 } 01400 01401 public function strip_comments($strip = false) 01402 { 01403 $this->sanitize->strip_comments($strip); 01404 } 01405 01414 public function set_url_replacements($element_attribute = array('a' => 'href', 'area' => 'href', 'blockquote' => 'cite', 'del' => 'cite', 'form' => 'action', 'img' => array('longdesc', 'src'), 'input' => 'src', 'ins' => 'cite', 'q' => 'cite')) 01415 { 01416 $this->sanitize->set_url_replacements($element_attribute); 01417 } 01418 01426 public function set_image_handler($page = false, $qs = 'i') 01427 { 01428 if ($page !== false) 01429 { 01430 $this->sanitize->set_image_handler($page . '?' . $qs . '='); 01431 } 01432 else 01433 { 01434 $this->image_handler = ''; 01435 } 01436 } 01437 01444 public function set_item_limit($limit = 0) 01445 { 01446 $this->item_limit = (int) $limit; 01447 } 01448 01449 public function init() 01450 { 01451 // Check absolute bare minimum requirements. 01452 if ((function_exists('version_compare') && version_compare(PHP_VERSION, '5.0', '<')) || !extension_loaded('xml') || !extension_loaded('pcre')) 01453 { 01454 return false; 01455 } 01456 // Then check the xml extension is sane (i.e., libxml 2.7.x issue on PHP < 5.2.9 and libxml 2.7.0 to 2.7.2 on any version) if we don't have xmlreader. 01457 elseif (!extension_loaded('xmlreader')) 01458 { 01459 static $xml_is_sane = null; 01460 if ($xml_is_sane === null) 01461 { 01462 $parser_check = xml_parser_create(); 01463 xml_parse_into_struct($parser_check, '<foo>&</foo>', $values); 01464 xml_parser_free($parser_check); 01465 $xml_is_sane = isset($values[0]['value']); 01466 } 01467 if (!$xml_is_sane) 01468 { 01469 return false; 01470 } 01471 } 01472 01473 if (isset($_GET[$this->javascript])) 01474 { 01475 SimplePie_Misc::output_javascript(); 01476 exit; 01477 } 01478 01479 // Pass whatever was set with config options over to the sanitizer. 01480 $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->cache_class); 01481 $this->sanitize->pass_file_data($this->file_class, $this->timeout, $this->useragent, $this->force_fsockopen); 01482 01483 if ($this->feed_url !== null || $this->raw_data !== null) 01484 { 01485 $this->error = null; 01486 $this->data = array(); 01487 $this->multifeed_objects = array(); 01488 $cache = false; 01489 01490 if ($this->feed_url !== null) 01491 { 01492 $parsed_feed_url = SimplePie_Misc::parse_url($this->feed_url); 01493 // Decide whether to enable caching 01494 if ($this->cache && $parsed_feed_url['scheme'] !== '') 01495 { 01496 $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc'); 01497 } 01498 // If it's enabled and we don't want an XML dump, use the cache 01499 if ($cache && !$this->xml_dump) 01500 { 01501 // Load the Cache 01502 $this->data = $cache->load(); 01503 if (!empty($this->data)) 01504 { 01505 // If the cache is for an outdated build of SimplePie 01506 if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD) 01507 { 01508 $cache->unlink(); 01509 $this->data = array(); 01510 } 01511 // If we've hit a collision just rerun it with caching disabled 01512 elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url) 01513 { 01514 $cache = false; 01515 $this->data = array(); 01516 } 01517 // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL. 01518 elseif (isset($this->data['feed_url'])) 01519 { 01520 // If the autodiscovery cache is still valid use it. 01521 if ($cache->mtime() + $this->autodiscovery_cache_duration > time()) 01522 { 01523 // Do not need to do feed autodiscovery yet. 01524 if ($this->data['feed_url'] === $this->data['url']) 01525 { 01526 $cache->unlink(); 01527 $this->data = array(); 01528 } 01529 else 01530 { 01531 $this->set_feed_url($this->data['feed_url']); 01532 return $this->init(); 01533 } 01534 } 01535 } 01536 // Check if the cache has been updated 01537 elseif ($cache->mtime() + $this->cache_duration < time()) 01538 { 01539 // If we have last-modified and/or etag set 01540 if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag'])) 01541 { 01542 $headers = array(); 01543 if (isset($this->data['headers']['last-modified'])) 01544 { 01545 $headers['if-modified-since'] = $this->data['headers']['last-modified']; 01546 } 01547 if (isset($this->data['headers']['etag'])) 01548 { 01549 $headers['if-none-match'] = '"' . $this->data['headers']['etag'] . '"'; 01550 } 01551 01552 $file = new $this->file_class($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen); 01553 01554 if ($file->success) 01555 { 01556 if ($file->status_code === 304) 01557 { 01558 $cache->touch(); 01559 return true; 01560 } 01561 else 01562 { 01563 $headers = $file->headers; 01564 } 01565 } 01566 else 01567 { 01568 unset($file); 01569 } 01570 } 01571 } 01572 // If the cache is still valid, just return true 01573 else 01574 { 01575 return true; 01576 } 01577 } 01578 // If the cache is empty, delete it 01579 else 01580 { 01581 $cache->unlink(); 01582 $this->data = array(); 01583 } 01584 } 01585 // If we don't already have the file (it'll only exist if we've opened it to check if the cache has been modified), open it. 01586 if (!isset($file)) 01587 { 01588 if (is_a($this->file, 'SimplePie_File') && $this->file->url === $this->feed_url) 01589 { 01590 $file =& $this->file; 01591 } 01592 else 01593 { 01594 $file = new $this->file_class($this->feed_url, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen); 01595 } 01596 } 01597 // If the file connection has an error, set SimplePie::error to that and quit 01598 if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300))) 01599 { 01600 $this->error = $file->error; 01601 if (!empty($this->data)) 01602 { 01603 return true; 01604 } 01605 else 01606 { 01607 return false; 01608 } 01609 } 01610 01611 if (!$this->force_feed) 01612 { 01613 // Check if the supplied URL is a feed, if it isn't, look for it. 01614 $locate = new $this->locator_class($file, $this->timeout, $this->useragent, $this->file_class, $this->max_checked_feeds, $this->content_type_sniffer_class); 01615 01616 if (!$locate->is_feed($file)) 01617 { 01618 // We need to unset this so that if SimplePie::set_file() has been called that object is untouched 01619 unset($file); 01620 if ($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds)) 01621 { 01622 if ($cache) 01623 { 01624 $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD); 01625 if (!$cache->save($this)) 01626 { 01627 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); 01628 } 01629 $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc'); 01630 } 01631 $this->feed_url = $file->url; 01632 } 01633 else 01634 { 01635 $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."; 01636 SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__); 01637 return false; 01638 } 01639 } 01640 $locate = null; 01641 } 01642 01643 $headers = $file->headers; 01644 $data = $file->body; 01645 $sniffer = new $this->content_type_sniffer_class($file); 01646 $sniffed = $sniffer->get_type(); 01647 } 01648 else 01649 { 01650 $data = $this->raw_data; 01651 } 01652 01653 // Set up array of possible encodings 01654 $encodings = array(); 01655 01656 // First check to see if input has been overridden. 01657 if ($this->input_encoding !== false) 01658 { 01659 $encodings[] = $this->input_encoding; 01660 } 01661 01662 $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity'); 01663 $text_types = array('text/xml', 'text/xml-external-parsed-entity'); 01664 01665 // RFC 3023 (only applies to sniffed content) 01666 if (isset($sniffed)) 01667 { 01668 if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml') 01669 { 01670 if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) 01671 { 01672 $encodings[] = strtoupper($charset[1]); 01673 } 01674 $encodings = array_merge($encodings, SimplePie_Misc::xml_encoding($data)); 01675 $encodings[] = 'UTF-8'; 01676 } 01677 elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml') 01678 { 01679 if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) 01680 { 01681 $encodings[] = $charset[1]; 01682 } 01683 $encodings[] = 'US-ASCII'; 01684 } 01685 // Text MIME-type default 01686 elseif (substr($sniffed, 0, 5) === 'text/') 01687 { 01688 $encodings[] = 'US-ASCII'; 01689 } 01690 } 01691 01692 // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1 01693 $encodings = array_merge($encodings, SimplePie_Misc::xml_encoding($data)); 01694 $encodings[] = 'UTF-8'; 01695 $encodings[] = 'ISO-8859-1'; 01696 01697 // There's no point in trying an encoding twice 01698 $encodings = array_unique($encodings); 01699 01700 // If we want the XML, just output that with the most likely encoding and quit 01701 if ($this->xml_dump) 01702 { 01703 header('Content-type: text/xml; charset=' . $encodings[0]); 01704 echo $data; 01705 exit; 01706 } 01707 01708 // Loop through each possible encoding, till we return something, or run out of possibilities 01709 foreach ($encodings as $encoding) 01710 { 01711 // Change the encoding to UTF-8 (as we always use UTF-8 internally) 01712 if ($utf8_data = SimplePie_Misc::change_encoding($data, $encoding, 'UTF-8')) 01713 { 01714 // Create new parser 01715 $parser = new $this->parser_class(); 01716 01717 // If it's parsed fine 01718 if ($parser->parse($utf8_data, 'UTF-8')) 01719 { 01720 $this->data = $parser->get_data(); 01721 if ($this->get_type() & ~SIMPLEPIE_TYPE_NONE) 01722 { 01723 if (isset($headers)) 01724 { 01725 $this->data['headers'] = $headers; 01726 } 01727 $this->data['build'] = SIMPLEPIE_BUILD; 01728 01729 // Cache the file if caching is enabled 01730 if ($cache && !$cache->save($this)) 01731 { 01732 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); 01733 } 01734 return true; 01735 } 01736 else 01737 { 01738 $this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed."; 01739 SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__); 01740 return false; 01741 } 01742 } 01743 } 01744 } 01745 01746 if (isset($parser)) 01747 { 01748 // We have an error, just set SimplePie_Misc::error to it and quit 01749 $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()); 01750 } 01751 else 01752 { 01753 $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.'; 01754 } 01755 01756 SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__); 01757 01758 return false; 01759 } 01760 elseif (!empty($this->multifeed_url)) 01761 { 01762 $i = 0; 01763 $success = 0; 01764 $this->multifeed_objects = array(); 01765 foreach ($this->multifeed_url as $url) 01766 { 01767 $this->multifeed_objects[$i] = clone $this; 01768 $this->multifeed_objects[$i]->set_feed_url($url); 01769 $success |= $this->multifeed_objects[$i]->init(); 01770 $i++; 01771 } 01772 return (bool) $success; 01773 } 01774 else 01775 { 01776 return false; 01777 } 01778 } 01779 01786 public function error() 01787 { 01788 return $this->error; 01789 } 01790 01791 public function get_encoding() 01792 { 01793 return $this->sanitize->output_encoding; 01794 } 01795 01796 public function handle_content_type($mime = 'text/html') 01797 { 01798 if (!headers_sent()) 01799 { 01800 $header = "Content-type: $mime;"; 01801 if ($this->get_encoding()) 01802 { 01803 $header .= ' charset=' . $this->get_encoding(); 01804 } 01805 else 01806 { 01807 $header .= ' charset=UTF-8'; 01808 } 01809 header($header); 01810 } 01811 } 01812 01813 public function get_type() 01814 { 01815 if (!isset($this->data['type'])) 01816 { 01817 $this->data['type'] = SIMPLEPIE_TYPE_ALL; 01818 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'])) 01819 { 01820 $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10; 01821 } 01822 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'])) 01823 { 01824 $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03; 01825 } 01826 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'])) 01827 { 01828 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel']) 01829 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image']) 01830 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']) 01831 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput'])) 01832 { 01833 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10; 01834 } 01835 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel']) 01836 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image']) 01837 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']) 01838 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput'])) 01839 { 01840 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090; 01841 } 01842 } 01843 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'])) 01844 { 01845 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL; 01846 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version'])) 01847 { 01848 switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version'])) 01849 { 01850 case '0.91': 01851 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091; 01852 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data'])) 01853 { 01854 switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data'])) 01855 { 01856 case '0': 01857 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE; 01858 break; 01859 01860 case '24': 01861 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND; 01862 break; 01863 } 01864 } 01865 break; 01866 01867 case '0.92': 01868 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092; 01869 break; 01870 01871 case '0.93': 01872 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093; 01873 break; 01874 01875 case '0.94': 01876 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094; 01877 break; 01878 01879 case '2.0': 01880 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20; 01881 break; 01882 } 01883 } 01884 } 01885 else 01886 { 01887 $this->data['type'] = SIMPLEPIE_TYPE_NONE; 01888 } 01889 } 01890 return $this->data['type']; 01891 } 01892 01898 public function subscribe_url() 01899 { 01900 if ($this->feed_url !== null) 01901 { 01902 return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI); 01903 } 01904 else 01905 { 01906 return null; 01907 } 01908 } 01909 01910 public function get_feed_tags($namespace, $tag) 01911 { 01912 $type = $this->get_type(); 01913 if ($type & SIMPLEPIE_TYPE_ATOM_10) 01914 { 01915 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag])) 01916 { 01917 return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]; 01918 } 01919 } 01920 if ($type & SIMPLEPIE_TYPE_ATOM_03) 01921 { 01922 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag])) 01923 { 01924 return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]; 01925 } 01926 } 01927 if ($type & SIMPLEPIE_TYPE_RSS_RDF) 01928 { 01929 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag])) 01930 { 01931 return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]; 01932 } 01933 } 01934 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION) 01935 { 01936 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag])) 01937 { 01938 return $this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag]; 01939 } 01940 } 01941 return null; 01942 } 01943 01944 public function get_channel_tags($namespace, $tag) 01945 { 01946 $type = $this->get_type(); 01947 if ($type & SIMPLEPIE_TYPE_ATOM_ALL) 01948 { 01949 if ($return = $this->get_feed_tags($namespace, $tag)) 01950 { 01951 return $return; 01952 } 01953 } 01954 if ($type & SIMPLEPIE_TYPE_RSS_10) 01955 { 01956 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel')) 01957 { 01958 if (isset($channel[0]['child'][$namespace][$tag])) 01959 { 01960 return $channel[0]['child'][$namespace][$tag]; 01961 } 01962 } 01963 } 01964 if ($type & SIMPLEPIE_TYPE_RSS_090) 01965 { 01966 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel')) 01967 { 01968 if (isset($channel[0]['child'][$namespace][$tag])) 01969 { 01970 return $channel[0]['child'][$namespace][$tag]; 01971 } 01972 } 01973 } 01974 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION) 01975 { 01976 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'channel')) 01977 { 01978 if (isset($channel[0]['child'][$namespace][$tag])) 01979 { 01980 return $channel[0]['child'][$namespace][$tag]; 01981 } 01982 } 01983 } 01984 return null; 01985 } 01986 01987 public function get_image_tags($namespace, $tag) 01988 { 01989 $type = $this->get_type(); 01990 if ($type & SIMPLEPIE_TYPE_RSS_10) 01991 { 01992 if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image')) 01993 { 01994 if (isset($image[0]['child'][$namespace][$tag])) 01995 { 01996 return $image[0]['child'][$namespace][$tag]; 01997 } 01998 } 01999 } 02000 if ($type & SIMPLEPIE_TYPE_RSS_090) 02001 { 02002 if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image')) 02003 { 02004 if (isset($image[0]['child'][$namespace][$tag])) 02005 { 02006 return $image[0]['child'][$namespace][$tag]; 02007 } 02008 } 02009 } 02010 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION) 02011 { 02012 if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'image')) 02013 { 02014 if (isset($image[0]['child'][$namespace][$tag])) 02015 { 02016 return $image[0]['child'][$namespace][$tag]; 02017 } 02018 } 02019 } 02020 return null; 02021 } 02022 02023 public function get_base($element = array()) 02024 { 02025 if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base'])) 02026 { 02027 return $element['xml_base']; 02028 } 02029 elseif ($this->get_link() !== null) 02030 { 02031 return $this->get_link(); 02032 } 02033 else 02034 { 02035 return $this->subscribe_url(); 02036 } 02037 } 02038 02039 public function sanitize($data, $type, $base = '') 02040 { 02041 return $this->sanitize->sanitize($data, $type, $base); 02042 } 02043 02044 public function get_title() 02045 { 02046 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title')) 02047 { 02048 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0])); 02049 } 02050 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) 02051 { 02052 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0])); 02053 } 02054 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) 02055 { 02056 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 02057 } 02058 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) 02059 { 02060 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 02061 } 02062 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) 02063 { 02064 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 02065 } 02066 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) 02067 { 02068 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02069 } 02070 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) 02071 { 02072 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02073 } 02074 else 02075 { 02076 return null; 02077 } 02078 } 02079 02080 public function get_category($key = 0) 02081 { 02082 $categories = $this->get_categories(); 02083 if (isset($categories[$key])) 02084 { 02085 return $categories[$key]; 02086 } 02087 else 02088 { 02089 return null; 02090 } 02091 } 02092 02093 public function get_categories() 02094 { 02095 $categories = array(); 02096 02097 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category) 02098 { 02099 $term = null; 02100 $scheme = null; 02101 $label = null; 02102 if (isset($category['attribs']['']['term'])) 02103 { 02104 $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT); 02105 } 02106 if (isset($category['attribs']['']['scheme'])) 02107 { 02108 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 02109 } 02110 if (isset($category['attribs']['']['label'])) 02111 { 02112 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); 02113 } 02114 $categories[] = new $this->category_class($term, $scheme, $label); 02115 } 02116 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category) 02117 { 02118 // This is really the label, but keep this as the term also for BC. 02119 // Label will also work on retrieving because that falls back to term. 02120 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02121 if (isset($category['attribs']['']['domain'])) 02122 { 02123 $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT); 02124 } 02125 else 02126 { 02127 $scheme = null; 02128 } 02129 $categories[] = new $this->category_class($term, $scheme, null); 02130 } 02131 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category) 02132 { 02133 $categories[] = new $this->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 02134 } 02135 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category) 02136 { 02137 $categories[] = new $this->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 02138 } 02139 02140 if (!empty($categories)) 02141 { 02142 return SimplePie_Misc::array_unique($categories); 02143 } 02144 else 02145 { 02146 return null; 02147 } 02148 } 02149 02150 public function get_author($key = 0) 02151 { 02152 $authors = $this->get_authors(); 02153 if (isset($authors[$key])) 02154 { 02155 return $authors[$key]; 02156 } 02157 else 02158 { 02159 return null; 02160 } 02161 } 02162 02163 public function get_authors() 02164 { 02165 $authors = array(); 02166 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author) 02167 { 02168 $name = null; 02169 $uri = null; 02170 $email = null; 02171 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) 02172 { 02173 $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02174 } 02175 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) 02176 { 02177 $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])); 02178 } 02179 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) 02180 { 02181 $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02182 } 02183 if ($name !== null || $email !== null || $uri !== null) 02184 { 02185 $authors[] = new $this->author_class($name, $uri, $email); 02186 } 02187 } 02188 if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author')) 02189 { 02190 $name = null; 02191 $url = null; 02192 $email = null; 02193 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) 02194 { 02195 $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02196 } 02197 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) 02198 { 02199 $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])); 02200 } 02201 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) 02202 { 02203 $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02204 } 02205 if ($name !== null || $email !== null || $url !== null) 02206 { 02207 $authors[] = new $this->author_class($name, $url, $email); 02208 } 02209 } 02210 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author) 02211 { 02212 $authors[] = new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 02213 } 02214 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author) 02215 { 02216 $authors[] = new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 02217 } 02218 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author) 02219 { 02220 $authors[] = new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 02221 } 02222 02223 if (!empty($authors)) 02224 { 02225 return SimplePie_Misc::array_unique($authors); 02226 } 02227 else 02228 { 02229 return null; 02230 } 02231 } 02232 02233 public function get_contributor($key = 0) 02234 { 02235 $contributors = $this->get_contributors(); 02236 if (isset($contributors[$key])) 02237 { 02238 return $contributors[$key]; 02239 } 02240 else 02241 { 02242 return null; 02243 } 02244 } 02245 02246 public function get_contributors() 02247 { 02248 $contributors = array(); 02249 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor) 02250 { 02251 $name = null; 02252 $uri = null; 02253 $email = null; 02254 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) 02255 { 02256 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02257 } 02258 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) 02259 { 02260 $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])); 02261 } 02262 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) 02263 { 02264 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02265 } 02266 if ($name !== null || $email !== null || $uri !== null) 02267 { 02268 $contributors[] = new $this->author_class($name, $uri, $email); 02269 } 02270 } 02271 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor) 02272 { 02273 $name = null; 02274 $url = null; 02275 $email = null; 02276 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) 02277 { 02278 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02279 } 02280 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) 02281 { 02282 $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])); 02283 } 02284 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) 02285 { 02286 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02287 } 02288 if ($name !== null || $email !== null || $url !== null) 02289 { 02290 $contributors[] = new $this->author_class($name, $url, $email); 02291 } 02292 } 02293 02294 if (!empty($contributors)) 02295 { 02296 return SimplePie_Misc::array_unique($contributors); 02297 } 02298 else 02299 { 02300 return null; 02301 } 02302 } 02303 02304 public function get_link($key = 0, $rel = 'alternate') 02305 { 02306 $links = $this->get_links($rel); 02307 if (isset($links[$key])) 02308 { 02309 return $links[$key]; 02310 } 02311 else 02312 { 02313 return null; 02314 } 02315 } 02316 02320 public function get_permalink() 02321 { 02322 return $this->get_link(0); 02323 } 02324 02325 public function get_links($rel = 'alternate') 02326 { 02327 if (!isset($this->data['links'])) 02328 { 02329 $this->data['links'] = array(); 02330 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link')) 02331 { 02332 foreach ($links as $link) 02333 { 02334 if (isset($link['attribs']['']['href'])) 02335 { 02336 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 02337 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 02338 } 02339 } 02340 } 02341 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link')) 02342 { 02343 foreach ($links as $link) 02344 { 02345 if (isset($link['attribs']['']['href'])) 02346 { 02347 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 02348 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 02349 02350 } 02351 } 02352 } 02353 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) 02354 { 02355 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 02356 } 02357 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) 02358 { 02359 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 02360 } 02361 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) 02362 { 02363 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 02364 } 02365 02366 $keys = array_keys($this->data['links']); 02367 foreach ($keys as $key) 02368 { 02369 if (SimplePie_Misc::is_isegment_nz_nc($key)) 02370 { 02371 if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key])) 02372 { 02373 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]); 02374 $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]; 02375 } 02376 else 02377 { 02378 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key]; 02379 } 02380 } 02381 elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) 02382 { 02383 $this->data['links'][substr($key, 41)] =& $this->data['links'][$key]; 02384 } 02385 $this->data['links'][$key] = array_unique($this->data['links'][$key]); 02386 } 02387 } 02388 02389 if (isset($this->data['links'][$rel])) 02390 { 02391 return $this->data['links'][$rel]; 02392 } 02393 else 02394 { 02395 return null; 02396 } 02397 } 02398 02399 public function get_all_discovered_feeds() 02400 { 02401 return $this->all_discovered_feeds; 02402 } 02403 02404 public function get_description() 02405 { 02406 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle')) 02407 { 02408 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0])); 02409 } 02410 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline')) 02411 { 02412 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0])); 02413 } 02414 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) 02415 { 02416 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 02417 } 02418 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) 02419 { 02420 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 02421 } 02422 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) 02423 { 02424 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 02425 } 02426 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) 02427 { 02428 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02429 } 02430 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) 02431 { 02432 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02433 } 02434 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) 02435 { 02436 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 02437 } 02438 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) 02439 { 02440 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 02441 } 02442 else 02443 { 02444 return null; 02445 } 02446 } 02447 02448 public function get_copyright() 02449 { 02450 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights')) 02451 { 02452 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0])); 02453 } 02454 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright')) 02455 { 02456 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0])); 02457 } 02458 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright')) 02459 { 02460 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02461 } 02462 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights')) 02463 { 02464 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02465 } 02466 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights')) 02467 { 02468 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02469 } 02470 else 02471 { 02472 return null; 02473 } 02474 } 02475 02476 public function get_language() 02477 { 02478 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language')) 02479 { 02480 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02481 } 02482 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language')) 02483 { 02484 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02485 } 02486 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language')) 02487 { 02488 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02489 } 02490 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'])) 02491 { 02492 return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); 02493 } 02494 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'])) 02495 { 02496 return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); 02497 } 02498 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'])) 02499 { 02500 return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); 02501 } 02502 elseif (isset($this->data['headers']['content-language'])) 02503 { 02504 return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT); 02505 } 02506 else 02507 { 02508 return null; 02509 } 02510 } 02511 02512 public function get_latitude() 02513 { 02514 02515 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat')) 02516 { 02517 return (float) $return[0]['data']; 02518 } 02519 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)) 02520 { 02521 return (float) $match[1]; 02522 } 02523 else 02524 { 02525 return null; 02526 } 02527 } 02528 02529 public function get_longitude() 02530 { 02531 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long')) 02532 { 02533 return (float) $return[0]['data']; 02534 } 02535 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon')) 02536 { 02537 return (float) $return[0]['data']; 02538 } 02539 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)) 02540 { 02541 return (float) $match[2]; 02542 } 02543 else 02544 { 02545 return null; 02546 } 02547 } 02548 02549 public function get_image_title() 02550 { 02551 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) 02552 { 02553 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02554 } 02555 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) 02556 { 02557 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02558 } 02559 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) 02560 { 02561 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02562 } 02563 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) 02564 { 02565 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02566 } 02567 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) 02568 { 02569 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02570 } 02571 else 02572 { 02573 return null; 02574 } 02575 } 02576 02577 public function get_image_url() 02578 { 02579 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image')) 02580 { 02581 return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI); 02582 } 02583 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo')) 02584 { 02585 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 02586 } 02587 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon')) 02588 { 02589 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 02590 } 02591 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url')) 02592 { 02593 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 02594 } 02595 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url')) 02596 { 02597 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 02598 } 02599 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) 02600 { 02601 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 02602 } 02603 else 02604 { 02605 return null; 02606 } 02607 } 02608 02609 public function get_image_link() 02610 { 02611 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) 02612 { 02613 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 02614 } 02615 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) 02616 { 02617 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 02618 } 02619 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) 02620 { 02621 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 02622 } 02623 else 02624 { 02625 return null; 02626 } 02627 } 02628 02629 public function get_image_width() 02630 { 02631 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width')) 02632 { 02633 return round($return[0]['data']); 02634 } 02635 elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) 02636 { 02637 return 88.0; 02638 } 02639 else 02640 { 02641 return null; 02642 } 02643 } 02644 02645 public function get_image_height() 02646 { 02647 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'height')) 02648 { 02649 return round($return[0]['data']); 02650 } 02651 elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) 02652 { 02653 return 31.0; 02654 } 02655 else 02656 { 02657 return null; 02658 } 02659 } 02660 02661 public function get_item_quantity($max = 0) 02662 { 02663 $max = (int) $max; 02664 $qty = count($this->get_items()); 02665 if ($max === 0) 02666 { 02667 return $qty; 02668 } 02669 else 02670 { 02671 return ($qty > $max) ? $max : $qty; 02672 } 02673 } 02674 02675 public function get_item($key = 0) 02676 { 02677 $items = $this->get_items(); 02678 if (isset($items[$key])) 02679 { 02680 return $items[$key]; 02681 } 02682 else 02683 { 02684 return null; 02685 } 02686 } 02687 02688 public function get_items($start = 0, $end = 0) 02689 { 02690 if (!isset($this->data['items'])) 02691 { 02692 if (!empty($this->multifeed_objects)) 02693 { 02694 $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit); 02695 } 02696 else 02697 { 02698 $this->data['items'] = array(); 02699 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry')) 02700 { 02701 $keys = array_keys($items); 02702 foreach ($keys as $key) 02703 { 02704 $this->data['items'][] = new $this->item_class($this, $items[$key]); 02705 } 02706 } 02707 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry')) 02708 { 02709 $keys = array_keys($items); 02710 foreach ($keys as $key) 02711 { 02712 $this->data['items'][] = new $this->item_class($this, $items[$key]); 02713 } 02714 } 02715 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item')) 02716 { 02717 $keys = array_keys($items); 02718 foreach ($keys as $key) 02719 { 02720 $this->data['items'][] = new $this->item_class($this, $items[$key]); 02721 } 02722 } 02723 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item')) 02724 { 02725 $keys = array_keys($items); 02726 foreach ($keys as $key) 02727 { 02728 $this->data['items'][] = new $this->item_class($this, $items[$key]); 02729 } 02730 } 02731 if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item')) 02732 { 02733 $keys = array_keys($items); 02734 foreach ($keys as $key) 02735 { 02736 $this->data['items'][] = new $this->item_class($this, $items[$key]); 02737 } 02738 } 02739 } 02740 } 02741 02742 if (!empty($this->data['items'])) 02743 { 02744 // If we want to order it by date, check if all items have a date, and then sort it 02745 if ($this->order_by_date && empty($this->multifeed_objects)) 02746 { 02747 if (!isset($this->data['ordered_items'])) 02748 { 02749 $do_sort = true; 02750 foreach ($this->data['items'] as $item) 02751 { 02752 if (!$item->get_date('U')) 02753 { 02754 $do_sort = false; 02755 break; 02756 } 02757 } 02758 $item = null; 02759 $this->data['ordered_items'] = $this->data['items']; 02760 if ($do_sort) 02761 { 02762 usort($this->data['ordered_items'], array(&$this, 'sort_items')); 02763 } 02764 } 02765 $items = $this->data['ordered_items']; 02766 } 02767 else 02768 { 02769 $items = $this->data['items']; 02770 } 02771 02772 // Slice the data as desired 02773 if ($end === 0) 02774 { 02775 return array_slice($items, $start); 02776 } 02777 else 02778 { 02779 return array_slice($items, $start, $end); 02780 } 02781 } 02782 else 02783 { 02784 return array(); 02785 } 02786 } 02787 02791 public function sort_items($a, $b) 02792 { 02793 return $a->get_date('U') <= $b->get_date('U'); 02794 } 02795 02799 public function merge_items($urls, $start = 0, $end = 0, $limit = 0) 02800 { 02801 if (is_array($urls) && sizeof($urls) > 0) 02802 { 02803 $items = array(); 02804 foreach ($urls as $arg) 02805 { 02806 if (is_a($arg, 'SimplePie')) 02807 { 02808 $items = array_merge($items, $arg->get_items(0, $limit)); 02809 } 02810 else 02811 { 02812 trigger_error('Arguments must be SimplePie objects', E_USER_WARNING); 02813 } 02814 } 02815 02816 $do_sort = true; 02817 foreach ($items as $item) 02818 { 02819 if (!$item->get_date('U')) 02820 { 02821 $do_sort = false; 02822 break; 02823 } 02824 } 02825 $item = null; 02826 if ($do_sort) 02827 { 02828 usort($items, array('SimplePie', 'sort_items')); 02829 } 02830 02831 if ($end === 0) 02832 { 02833 return array_slice($items, $start); 02834 } 02835 else 02836 { 02837 return array_slice($items, $start, $end); 02838 } 02839 } 02840 else 02841 { 02842 trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING); 02843 return array(); 02844 } 02845 } 02846 } 02847 02848 class SimplePie_Item 02849 { 02850 var $feed; 02851 var $data = array(); 02852 02853 public function __construct($feed, $data) 02854 { 02855 $this->feed = $feed; 02856 $this->data = $data; 02857 } 02858 02859 public function __toString() 02860 { 02861 return md5(serialize($this->data)); 02862 } 02863 02867 public function __destruct() 02868 { 02869 if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode')) 02870 { 02871 unset($this->feed); 02872 } 02873 } 02874 02875 public function get_item_tags($namespace, $tag) 02876 { 02877 if (isset($this->data['child'][$namespace][$tag])) 02878 { 02879 return $this->data['child'][$namespace][$tag]; 02880 } 02881 else 02882 { 02883 return null; 02884 } 02885 } 02886 02887 public function get_base($element = array()) 02888 { 02889 return $this->feed->get_base($element); 02890 } 02891 02892 public function sanitize($data, $type, $base = '') 02893 { 02894 return $this->feed->sanitize($data, $type, $base); 02895 } 02896 02897 public function get_feed() 02898 { 02899 return $this->feed; 02900 } 02901 02902 public function get_id($hash = false) 02903 { 02904 if (!$hash) 02905 { 02906 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id')) 02907 { 02908 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02909 } 02910 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id')) 02911 { 02912 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02913 } 02914 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid')) 02915 { 02916 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02917 } 02918 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier')) 02919 { 02920 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02921 } 02922 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier')) 02923 { 02924 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02925 } 02926 elseif (($return = $this->get_permalink()) !== null) 02927 { 02928 return $return; 02929 } 02930 elseif (($return = $this->get_title()) !== null) 02931 { 02932 return $return; 02933 } 02934 } 02935 if ($this->get_permalink() !== null || $this->get_title() !== null) 02936 { 02937 return md5($this->get_permalink() . $this->get_title()); 02938 } 02939 else 02940 { 02941 return md5(serialize($this->data)); 02942 } 02943 } 02944 02945 public function get_title() 02946 { 02947 if (!isset($this->data['title'])) 02948 { 02949 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title')) 02950 { 02951 $this->data['title'] = $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0])); 02952 } 02953 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) 02954 { 02955 $this->data['title'] = $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0])); 02956 } 02957 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) 02958 { 02959 $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 02960 } 02961 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) 02962 { 02963 $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 02964 } 02965 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) 02966 { 02967 $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 02968 } 02969 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) 02970 { 02971 $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02972 } 02973 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) 02974 { 02975 $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 02976 } 02977 else 02978 { 02979 $this->data['title'] = null; 02980 } 02981 } 02982 return $this->data['title']; 02983 } 02984 02985 public function get_description($description_only = false) 02986 { 02987 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary')) 02988 { 02989 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0])); 02990 } 02991 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary')) 02992 { 02993 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0])); 02994 } 02995 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) 02996 { 02997 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 02998 } 02999 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) 03000 { 03001 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 03002 } 03003 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) 03004 { 03005 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03006 } 03007 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) 03008 { 03009 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03010 } 03011 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) 03012 { 03013 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 03014 } 03015 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) 03016 { 03017 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03018 } 03019 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) 03020 { 03021 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML); 03022 } 03023 03024 elseif (!$description_only) 03025 { 03026 return $this->get_content(true); 03027 } 03028 else 03029 { 03030 return null; 03031 } 03032 } 03033 03034 public function get_content($content_only = false) 03035 { 03036 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content')) 03037 { 03038 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_content_construct_type($return[0]['attribs']), $this->get_base($return[0])); 03039 } 03040 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content')) 03041 { 03042 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0])); 03043 } 03044 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded')) 03045 { 03046 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 03047 } 03048 elseif (!$content_only) 03049 { 03050 return $this->get_description(true); 03051 } 03052 else 03053 { 03054 return null; 03055 } 03056 } 03057 03058 public function get_category($key = 0) 03059 { 03060 $categories = $this->get_categories(); 03061 if (isset($categories[$key])) 03062 { 03063 return $categories[$key]; 03064 } 03065 else 03066 { 03067 return null; 03068 } 03069 } 03070 03071 public function get_categories() 03072 { 03073 $categories = array(); 03074 03075 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category) 03076 { 03077 $term = null; 03078 $scheme = null; 03079 $label = null; 03080 if (isset($category['attribs']['']['term'])) 03081 { 03082 $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT); 03083 } 03084 if (isset($category['attribs']['']['scheme'])) 03085 { 03086 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 03087 } 03088 if (isset($category['attribs']['']['label'])) 03089 { 03090 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); 03091 } 03092 $categories[] = new $this->feed->category_class($term, $scheme, $label); 03093 } 03094 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category) 03095 { 03096 // This is really the label, but keep this as the term also for BC. 03097 // Label will also work on retrieving because that falls back to term. 03098 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03099 if (isset($category['attribs']['']['domain'])) 03100 { 03101 $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT); 03102 } 03103 else 03104 { 03105 $scheme = null; 03106 } 03107 $categories[] = new $this->feed->category_class($term, $scheme, null); 03108 } 03109 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category) 03110 { 03111 $categories[] = new $this->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 03112 } 03113 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category) 03114 { 03115 $categories[] = new $this->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 03116 } 03117 03118 if (!empty($categories)) 03119 { 03120 return SimplePie_Misc::array_unique($categories); 03121 } 03122 else 03123 { 03124 return null; 03125 } 03126 } 03127 03128 public function get_author($key = 0) 03129 { 03130 $authors = $this->get_authors(); 03131 if (isset($authors[$key])) 03132 { 03133 return $authors[$key]; 03134 } 03135 else 03136 { 03137 return null; 03138 } 03139 } 03140 03141 public function get_contributor($key = 0) 03142 { 03143 $contributors = $this->get_contributors(); 03144 if (isset($contributors[$key])) 03145 { 03146 return $contributors[$key]; 03147 } 03148 else 03149 { 03150 return null; 03151 } 03152 } 03153 03154 public function get_contributors() 03155 { 03156 $contributors = array(); 03157 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor) 03158 { 03159 $name = null; 03160 $uri = null; 03161 $email = null; 03162 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) 03163 { 03164 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03165 } 03166 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) 03167 { 03168 $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])); 03169 } 03170 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) 03171 { 03172 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03173 } 03174 if ($name !== null || $email !== null || $uri !== null) 03175 { 03176 $contributors[] = new $this->feed->author_class($name, $uri, $email); 03177 } 03178 } 03179 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor) 03180 { 03181 $name = null; 03182 $url = null; 03183 $email = null; 03184 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) 03185 { 03186 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03187 } 03188 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) 03189 { 03190 $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])); 03191 } 03192 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) 03193 { 03194 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03195 } 03196 if ($name !== null || $email !== null || $url !== null) 03197 { 03198 $contributors[] = new $this->feed->author_class($name, $url, $email); 03199 } 03200 } 03201 03202 if (!empty($contributors)) 03203 { 03204 return SimplePie_Misc::array_unique($contributors); 03205 } 03206 else 03207 { 03208 return null; 03209 } 03210 } 03211 03212 public function get_authors() 03213 { 03214 $authors = array(); 03215 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author) 03216 { 03217 $name = null; 03218 $uri = null; 03219 $email = null; 03220 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) 03221 { 03222 $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03223 } 03224 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) 03225 { 03226 $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])); 03227 } 03228 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) 03229 { 03230 $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03231 } 03232 if ($name !== null || $email !== null || $uri !== null) 03233 { 03234 $authors[] = new $this->feed->author_class($name, $uri, $email); 03235 } 03236 } 03237 if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author')) 03238 { 03239 $name = null; 03240 $url = null; 03241 $email = null; 03242 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) 03243 { 03244 $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03245 } 03246 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) 03247 { 03248 $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])); 03249 } 03250 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) 03251 { 03252 $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03253 } 03254 if ($name !== null || $email !== null || $url !== null) 03255 { 03256 $authors[] = new $this->feed->author_class($name, $url, $email); 03257 } 03258 } 03259 if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'author')) 03260 { 03261 $authors[] = new $this->feed->author_class(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); 03262 } 03263 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author) 03264 { 03265 $authors[] = new $this->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 03266 } 03267 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author) 03268 { 03269 $authors[] = new $this->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 03270 } 03271 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author) 03272 { 03273 $authors[] = new $this->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 03274 } 03275 03276 if (!empty($authors)) 03277 { 03278 return SimplePie_Misc::array_unique($authors); 03279 } 03280 elseif (($source = $this->get_source()) && ($authors = $source->get_authors())) 03281 { 03282 return $authors; 03283 } 03284 elseif ($authors = $this->feed->get_authors()) 03285 { 03286 return $authors; 03287 } 03288 else 03289 { 03290 return null; 03291 } 03292 } 03293 03294 public function get_copyright() 03295 { 03296 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights')) 03297 { 03298 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0])); 03299 } 03300 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights')) 03301 { 03302 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03303 } 03304 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights')) 03305 { 03306 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03307 } 03308 else 03309 { 03310 return null; 03311 } 03312 } 03313 03314 public function get_date($date_format = 'j F Y, g:i a') 03315 { 03316 if (!isset($this->data['date'])) 03317 { 03318 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published')) 03319 { 03320 $this->data['date']['raw'] = $return[0]['data']; 03321 } 03322 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated')) 03323 { 03324 $this->data['date']['raw'] = $return[0]['data']; 03325 } 03326 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued')) 03327 { 03328 $this->data['date']['raw'] = $return[0]['data']; 03329 } 03330 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created')) 03331 { 03332 $this->data['date']['raw'] = $return[0]['data']; 03333 } 03334 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified')) 03335 { 03336 $this->data['date']['raw'] = $return[0]['data']; 03337 } 03338 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'pubDate')) 03339 { 03340 $this->data['date']['raw'] = $return[0]['data']; 03341 } 03342 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date')) 03343 { 03344 $this->data['date']['raw'] = $return[0]['data']; 03345 } 03346 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date')) 03347 { 03348 $this->data['date']['raw'] = $return[0]['data']; 03349 } 03350 03351 if (!empty($this->data['date']['raw'])) 03352 { 03353 $parser = SimplePie_Parse_Date::get(); 03354 $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']); 03355 } 03356 else 03357 { 03358 $this->data['date'] = null; 03359 } 03360 } 03361 if ($this->data['date']) 03362 { 03363 $date_format = (string) $date_format; 03364 switch ($date_format) 03365 { 03366 case '': 03367 return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT); 03368 03369 case 'U': 03370 return $this->data['date']['parsed']; 03371 03372 default: 03373 return date($date_format, $this->data['date']['parsed']); 03374 } 03375 } 03376 else 03377 { 03378 return null; 03379 } 03380 } 03381 03382 public function get_local_date($date_format = '%c') 03383 { 03384 if (!$date_format) 03385 { 03386 return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT); 03387 } 03388 elseif (($date = $this->get_date('U')) !== null && $date !== false) 03389 { 03390 return strftime($date_format, $date); 03391 } 03392 else 03393 { 03394 return null; 03395 } 03396 } 03397 03398 public function get_permalink() 03399 { 03400 $link = $this->get_link(); 03401 $enclosure = $this->get_enclosure(0); 03402 if ($link !== null) 03403 { 03404 return $link; 03405 } 03406 elseif ($enclosure !== null) 03407 { 03408 return $enclosure->get_link(); 03409 } 03410 else 03411 { 03412 return null; 03413 } 03414 } 03415 03416 public function get_link($key = 0, $rel = 'alternate') 03417 { 03418 $links = $this->get_links($rel); 03419 if ($links[$key] !== null) 03420 { 03421 return $links[$key]; 03422 } 03423 else 03424 { 03425 return null; 03426 } 03427 } 03428 03429 public function get_links($rel = 'alternate') 03430 { 03431 if (!isset($this->data['links'])) 03432 { 03433 $this->data['links'] = array(); 03434 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link) 03435 { 03436 if (isset($link['attribs']['']['href'])) 03437 { 03438 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 03439 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 03440 03441 } 03442 } 03443 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link) 03444 { 03445 if (isset($link['attribs']['']['href'])) 03446 { 03447 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 03448 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 03449 } 03450 } 03451 if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) 03452 { 03453 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 03454 } 03455 if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) 03456 { 03457 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 03458 } 03459 if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) 03460 { 03461 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 03462 } 03463 if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid')) 03464 { 03465 if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true') 03466 { 03467 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 03468 } 03469 } 03470 03471 $keys = array_keys($this->data['links']); 03472 foreach ($keys as $key) 03473 { 03474 if (SimplePie_Misc::is_isegment_nz_nc($key)) 03475 { 03476 if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key])) 03477 { 03478 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]); 03479 $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]; 03480 } 03481 else 03482 { 03483 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key]; 03484 } 03485 } 03486 elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) 03487 { 03488 $this->data['links'][substr($key, 41)] =& $this->data['links'][$key]; 03489 } 03490 $this->data['links'][$key] = array_unique($this->data['links'][$key]); 03491 } 03492 } 03493 if (isset($this->data['links'][$rel])) 03494 { 03495 return $this->data['links'][$rel]; 03496 } 03497 else 03498 { 03499 return null; 03500 } 03501 } 03502 03506 public function get_enclosure($key = 0, $prefer = null) 03507 { 03508 $enclosures = $this->get_enclosures(); 03509 if (isset($enclosures[$key])) 03510 { 03511 return $enclosures[$key]; 03512 } 03513 else 03514 { 03515 return null; 03516 } 03517 } 03518 03529 public function get_enclosures() 03530 { 03531 if (!isset($this->data['enclosures'])) 03532 { 03533 $this->data['enclosures'] = array(); 03534 03535 // Elements 03536 $captions_parent = null; 03537 $categories_parent = null; 03538 $copyrights_parent = null; 03539 $credits_parent = null; 03540 $description_parent = null; 03541 $duration_parent = null; 03542 $hashes_parent = null; 03543 $keywords_parent = null; 03544 $player_parent = null; 03545 $ratings_parent = null; 03546 $restrictions_parent = null; 03547 $thumbnails_parent = null; 03548 $title_parent = null; 03549 03550 // Let's do the channel and item-level ones first, and just re-use them if we need to. 03551 $parent = $this->get_feed(); 03552 03553 // CAPTIONS 03554 if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text')) 03555 { 03556 foreach ($captions as $caption) 03557 { 03558 $caption_type = null; 03559 $caption_lang = null; 03560 $caption_startTime = null; 03561 $caption_endTime = null; 03562 $caption_text = null; 03563 if (isset($caption['attribs']['']['type'])) 03564 { 03565 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 03566 } 03567 if (isset($caption['attribs']['']['lang'])) 03568 { 03569 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT); 03570 } 03571 if (isset($caption['attribs']['']['start'])) 03572 { 03573 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT); 03574 } 03575 if (isset($caption['attribs']['']['end'])) 03576 { 03577 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT); 03578 } 03579 if (isset($caption['data'])) 03580 { 03581 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03582 } 03583 $captions_parent[] = new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text); 03584 } 03585 } 03586 elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text')) 03587 { 03588 foreach ($captions as $caption) 03589 { 03590 $caption_type = null; 03591 $caption_lang = null; 03592 $caption_startTime = null; 03593 $caption_endTime = null; 03594 $caption_text = null; 03595 if (isset($caption['attribs']['']['type'])) 03596 { 03597 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 03598 } 03599 if (isset($caption['attribs']['']['lang'])) 03600 { 03601 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT); 03602 } 03603 if (isset($caption['attribs']['']['start'])) 03604 { 03605 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT); 03606 } 03607 if (isset($caption['attribs']['']['end'])) 03608 { 03609 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT); 03610 } 03611 if (isset($caption['data'])) 03612 { 03613 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03614 } 03615 $captions_parent[] = new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text); 03616 } 03617 } 03618 if (is_array($captions_parent)) 03619 { 03620 $captions_parent = array_values(SimplePie_Misc::array_unique($captions_parent)); 03621 } 03622 03623 // CATEGORIES 03624 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category) 03625 { 03626 $term = null; 03627 $scheme = null; 03628 $label = null; 03629 if (isset($category['data'])) 03630 { 03631 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03632 } 03633 if (isset($category['attribs']['']['scheme'])) 03634 { 03635 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 03636 } 03637 else 03638 { 03639 $scheme = 'http://search.yahoo.com/mrss/category_schema'; 03640 } 03641 if (isset($category['attribs']['']['label'])) 03642 { 03643 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); 03644 } 03645 $categories_parent[] = new $this->feed->category_class($term, $scheme, $label); 03646 } 03647 foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category) 03648 { 03649 $term = null; 03650 $scheme = null; 03651 $label = null; 03652 if (isset($category['data'])) 03653 { 03654 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03655 } 03656 if (isset($category['attribs']['']['scheme'])) 03657 { 03658 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 03659 } 03660 else 03661 { 03662 $scheme = 'http://search.yahoo.com/mrss/category_schema'; 03663 } 03664 if (isset($category['attribs']['']['label'])) 03665 { 03666 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); 03667 } 03668 $categories_parent[] = new $this->feed->category_class($term, $scheme, $label); 03669 } 03670 foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category) 03671 { 03672 $term = null; 03673 $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd'; 03674 $label = null; 03675 if (isset($category['attribs']['']['text'])) 03676 { 03677 $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT); 03678 } 03679 $categories_parent[] = new $this->feed->category_class($term, $scheme, $label); 03680 03681 if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'])) 03682 { 03683 foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory) 03684 { 03685 if (isset($subcategory['attribs']['']['text'])) 03686 { 03687 $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT); 03688 } 03689 $categories_parent[] = new $this->feed->category_class($term, $scheme, $label); 03690 } 03691 } 03692 } 03693 if (is_array($categories_parent)) 03694 { 03695 $categories_parent = array_values(SimplePie_Misc::array_unique($categories_parent)); 03696 } 03697 03698 // COPYRIGHT 03699 if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright')) 03700 { 03701 $copyright_url = null; 03702 $copyright_label = null; 03703 if (isset($copyright[0]['attribs']['']['url'])) 03704 { 03705 $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT); 03706 } 03707 if (isset($copyright[0]['data'])) 03708 { 03709 $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03710 } 03711 $copyrights_parent = new $this->feed->copyright_class($copyright_url, $copyright_label); 03712 } 03713 elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright')) 03714 { 03715 $copyright_url = null; 03716 $copyright_label = null; 03717 if (isset($copyright[0]['attribs']['']['url'])) 03718 { 03719 $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT); 03720 } 03721 if (isset($copyright[0]['data'])) 03722 { 03723 $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03724 } 03725 $copyrights_parent = new $this->feed->copyright_class($copyright_url, $copyright_label); 03726 } 03727 03728 // CREDITS 03729 if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit')) 03730 { 03731 foreach ($credits as $credit) 03732 { 03733 $credit_role = null; 03734 $credit_scheme = null; 03735 $credit_name = null; 03736 if (isset($credit['attribs']['']['role'])) 03737 { 03738 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT); 03739 } 03740 if (isset($credit['attribs']['']['scheme'])) 03741 { 03742 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 03743 } 03744 else 03745 { 03746 $credit_scheme = 'urn:ebu'; 03747 } 03748 if (isset($credit['data'])) 03749 { 03750 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03751 } 03752 $credits_parent[] = new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name); 03753 } 03754 } 03755 elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit')) 03756 { 03757 foreach ($credits as $credit) 03758 { 03759 $credit_role = null; 03760 $credit_scheme = null; 03761 $credit_name = null; 03762 if (isset($credit['attribs']['']['role'])) 03763 { 03764 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT); 03765 } 03766 if (isset($credit['attribs']['']['scheme'])) 03767 { 03768 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 03769 } 03770 else 03771 { 03772 $credit_scheme = 'urn:ebu'; 03773 } 03774 if (isset($credit['data'])) 03775 { 03776 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03777 } 03778 $credits_parent[] = new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name); 03779 } 03780 } 03781 if (is_array($credits_parent)) 03782 { 03783 $credits_parent = array_values(SimplePie_Misc::array_unique($credits_parent)); 03784 } 03785 03786 // DESCRIPTION 03787 if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description')) 03788 { 03789 if (isset($description_parent[0]['data'])) 03790 { 03791 $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03792 } 03793 } 03794 elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description')) 03795 { 03796 if (isset($description_parent[0]['data'])) 03797 { 03798 $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03799 } 03800 } 03801 03802 // DURATION 03803 if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration')) 03804 { 03805 $seconds = null; 03806 $minutes = null; 03807 $hours = null; 03808 if (isset($duration_parent[0]['data'])) 03809 { 03810 $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); 03811 if (sizeof($temp) > 0) 03812 { 03813 $seconds = (int) array_pop($temp); 03814 } 03815 if (sizeof($temp) > 0) 03816 { 03817 $minutes = (int) array_pop($temp); 03818 $seconds += $minutes * 60; 03819 } 03820 if (sizeof($temp) > 0) 03821 { 03822 $hours = (int) array_pop($temp); 03823 $seconds += $hours * 3600; 03824 } 03825 unset($temp); 03826 $duration_parent = $seconds; 03827 } 03828 } 03829 03830 // HASHES 03831 if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash')) 03832 { 03833 foreach ($hashes_iterator as $hash) 03834 { 03835 $value = null; 03836 $algo = null; 03837 if (isset($hash['data'])) 03838 { 03839 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03840 } 03841 if (isset($hash['attribs']['']['algo'])) 03842 { 03843 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT); 03844 } 03845 else 03846 { 03847 $algo = 'md5'; 03848 } 03849 $hashes_parent[] = $algo.':'.$value; 03850 } 03851 } 03852 elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash')) 03853 { 03854 foreach ($hashes_iterator as $hash) 03855 { 03856 $value = null; 03857 $algo = null; 03858 if (isset($hash['data'])) 03859 { 03860 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03861 } 03862 if (isset($hash['attribs']['']['algo'])) 03863 { 03864 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT); 03865 } 03866 else 03867 { 03868 $algo = 'md5'; 03869 } 03870 $hashes_parent[] = $algo.':'.$value; 03871 } 03872 } 03873 if (is_array($hashes_parent)) 03874 { 03875 $hashes_parent = array_values(SimplePie_Misc::array_unique($hashes_parent)); 03876 } 03877 03878 // KEYWORDS 03879 if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords')) 03880 { 03881 if (isset($keywords[0]['data'])) 03882 { 03883 $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); 03884 foreach ($temp as $word) 03885 { 03886 $keywords_parent[] = trim($word); 03887 } 03888 } 03889 unset($temp); 03890 } 03891 elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords')) 03892 { 03893 if (isset($keywords[0]['data'])) 03894 { 03895 $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); 03896 foreach ($temp as $word) 03897 { 03898 $keywords_parent[] = trim($word); 03899 } 03900 } 03901 unset($temp); 03902 } 03903 elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords')) 03904 { 03905 if (isset($keywords[0]['data'])) 03906 { 03907 $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); 03908 foreach ($temp as $word) 03909 { 03910 $keywords_parent[] = trim($word); 03911 } 03912 } 03913 unset($temp); 03914 } 03915 elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords')) 03916 { 03917 if (isset($keywords[0]['data'])) 03918 { 03919 $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); 03920 foreach ($temp as $word) 03921 { 03922 $keywords_parent[] = trim($word); 03923 } 03924 } 03925 unset($temp); 03926 } 03927 if (is_array($keywords_parent)) 03928 { 03929 $keywords_parent = array_values(SimplePie_Misc::array_unique($keywords_parent)); 03930 } 03931 03932 // PLAYER 03933 if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player')) 03934 { 03935 if (isset($player_parent[0]['attribs']['']['url'])) 03936 { 03937 $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 03938 } 03939 } 03940 elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player')) 03941 { 03942 if (isset($player_parent[0]['attribs']['']['url'])) 03943 { 03944 $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 03945 } 03946 } 03947 03948 // RATINGS 03949 if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating')) 03950 { 03951 foreach ($ratings as $rating) 03952 { 03953 $rating_scheme = null; 03954 $rating_value = null; 03955 if (isset($rating['attribs']['']['scheme'])) 03956 { 03957 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 03958 } 03959 else 03960 { 03961 $rating_scheme = 'urn:simple'; 03962 } 03963 if (isset($rating['data'])) 03964 { 03965 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03966 } 03967 $ratings_parent[] = new $this->feed->rating_class($rating_scheme, $rating_value); 03968 } 03969 } 03970 elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit')) 03971 { 03972 foreach ($ratings as $rating) 03973 { 03974 $rating_scheme = 'urn:itunes'; 03975 $rating_value = null; 03976 if (isset($rating['data'])) 03977 { 03978 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT); 03979 } 03980 $ratings_parent[] = new $this->feed->rating_class($rating_scheme, $rating_value); 03981 } 03982 } 03983 elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating')) 03984 { 03985 foreach ($ratings as $rating) 03986 { 03987 $rating_scheme = null; 03988 $rating_value = null; 03989 if (isset($rating['attribs']['']['scheme'])) 03990 { 03991 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 03992 } 03993 else 03994 { 03995 $rating_scheme = 'urn:simple'; 03996 } 03997 if (isset($rating['data'])) 03998 { 03999 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04000 } 04001 $ratings_parent[] = new $this->feed->rating_class($rating_scheme, $rating_value); 04002 } 04003 } 04004 elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit')) 04005 { 04006 foreach ($ratings as $rating) 04007 { 04008 $rating_scheme = 'urn:itunes'; 04009 $rating_value = null; 04010 if (isset($rating['data'])) 04011 { 04012 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04013 } 04014 $ratings_parent[] = new $this->feed->rating_class($rating_scheme, $rating_value); 04015 } 04016 } 04017 if (is_array($ratings_parent)) 04018 { 04019 $ratings_parent = array_values(SimplePie_Misc::array_unique($ratings_parent)); 04020 } 04021 04022 // RESTRICTIONS 04023 if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction')) 04024 { 04025 foreach ($restrictions as $restriction) 04026 { 04027 $restriction_relationship = null; 04028 $restriction_type = null; 04029 $restriction_value = null; 04030 if (isset($restriction['attribs']['']['relationship'])) 04031 { 04032 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT); 04033 } 04034 if (isset($restriction['attribs']['']['type'])) 04035 { 04036 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 04037 } 04038 if (isset($restriction['data'])) 04039 { 04040 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04041 } 04042 $restrictions_parent[] = new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value); 04043 } 04044 } 04045 elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block')) 04046 { 04047 foreach ($restrictions as $restriction) 04048 { 04049 $restriction_relationship = 'allow'; 04050 $restriction_type = null; 04051 $restriction_value = 'itunes'; 04052 if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes') 04053 { 04054 $restriction_relationship = 'deny'; 04055 } 04056 $restrictions_parent[] = new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value); 04057 } 04058 } 04059 elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction')) 04060 { 04061 foreach ($restrictions as $restriction) 04062 { 04063 $restriction_relationship = null; 04064 $restriction_type = null; 04065 $restriction_value = null; 04066 if (isset($restriction['attribs']['']['relationship'])) 04067 { 04068 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT); 04069 } 04070 if (isset($restriction['attribs']['']['type'])) 04071 { 04072 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 04073 } 04074 if (isset($restriction['data'])) 04075 { 04076 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04077 } 04078 $restrictions_parent[] = new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value); 04079 } 04080 } 04081 elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block')) 04082 { 04083 foreach ($restrictions as $restriction) 04084 { 04085 $restriction_relationship = 'allow'; 04086 $restriction_type = null; 04087 $restriction_value = 'itunes'; 04088 if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes') 04089 { 04090 $restriction_relationship = 'deny'; 04091 } 04092 $restrictions_parent[] = new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value); 04093 } 04094 } 04095 if (is_array($restrictions_parent)) 04096 { 04097 $restrictions_parent = array_values(SimplePie_Misc::array_unique($restrictions_parent)); 04098 } 04099 04100 // THUMBNAILS 04101 if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail')) 04102 { 04103 foreach ($thumbnails as $thumbnail) 04104 { 04105 if (isset($thumbnail['attribs']['']['url'])) 04106 { 04107 $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 04108 } 04109 } 04110 } 04111 elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail')) 04112 { 04113 foreach ($thumbnails as $thumbnail) 04114 { 04115 if (isset($thumbnail['attribs']['']['url'])) 04116 { 04117 $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 04118 } 04119 } 04120 } 04121 04122 // TITLES 04123 if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title')) 04124 { 04125 if (isset($title_parent[0]['data'])) 04126 { 04127 $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04128 } 04129 } 04130 elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title')) 04131 { 04132 if (isset($title_parent[0]['data'])) 04133 { 04134 $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04135 } 04136 } 04137 04138 // Clear the memory 04139 unset($parent); 04140 04141 // Attributes 04142 $bitrate = null; 04143 $channels = null; 04144 $duration = null; 04145 $expression = null; 04146 $framerate = null; 04147 $height = null; 04148 $javascript = null; 04149 $lang = null; 04150 $length = null; 04151 $medium = null; 04152 $samplingrate = null; 04153 $type = null; 04154 $url = null; 04155 $width = null; 04156 04157 // Elements 04158 $captions = null; 04159 $categories = null; 04160 $copyrights = null; 04161 $credits = null; 04162 $description = null; 04163 $hashes = null; 04164 $keywords = null; 04165 $player = null; 04166 $ratings = null; 04167 $restrictions = null; 04168 $thumbnails = null; 04169 $title = null; 04170 04171 // If we have media:group tags, loop through them. 04172 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group) 04173 { 04174 if(isset($group['child']) && isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'])) 04175 { 04176 // If we have media:content tags, loop through them. 04177 foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content) 04178 { 04179 if (isset($content['attribs']['']['url'])) 04180 { 04181 // Attributes 04182 $bitrate = null; 04183 $channels = null; 04184 $duration = null; 04185 $expression = null; 04186 $framerate = null; 04187 $height = null; 04188 $javascript = null; 04189 $lang = null; 04190 $length = null; 04191 $medium = null; 04192 $samplingrate = null; 04193 $type = null; 04194 $url = null; 04195 $width = null; 04196 04197 // Elements 04198 $captions = null; 04199 $categories = null; 04200 $copyrights = null; 04201 $credits = null; 04202 $description = null; 04203 $hashes = null; 04204 $keywords = null; 04205 $player = null; 04206 $ratings = null; 04207 $restrictions = null; 04208 $thumbnails = null; 04209 $title = null; 04210 04211 // Start checking the attributes of media:content 04212 if (isset($content['attribs']['']['bitrate'])) 04213 { 04214 $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT); 04215 } 04216 if (isset($content['attribs']['']['channels'])) 04217 { 04218 $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT); 04219 } 04220 if (isset($content['attribs']['']['duration'])) 04221 { 04222 $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT); 04223 } 04224 else 04225 { 04226 $duration = $duration_parent; 04227 } 04228 if (isset($content['attribs']['']['expression'])) 04229 { 04230 $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT); 04231 } 04232 if (isset($content['attribs']['']['framerate'])) 04233 { 04234 $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT); 04235 } 04236 if (isset($content['attribs']['']['height'])) 04237 { 04238 $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT); 04239 } 04240 if (isset($content['attribs']['']['lang'])) 04241 { 04242 $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT); 04243 } 04244 if (isset($content['attribs']['']['fileSize'])) 04245 { 04246 $length = ceil($content['attribs']['']['fileSize']); 04247 } 04248 if (isset($content['attribs']['']['medium'])) 04249 { 04250 $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT); 04251 } 04252 if (isset($content['attribs']['']['samplingrate'])) 04253 { 04254 $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT); 04255 } 04256 if (isset($content['attribs']['']['type'])) 04257 { 04258 $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 04259 } 04260 if (isset($content['attribs']['']['width'])) 04261 { 04262 $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT); 04263 } 04264 $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 04265 04266 // Checking the other optional media: elements. Priority: media:content, media:group, item, channel 04267 04268 // CAPTIONS 04269 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'])) 04270 { 04271 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption) 04272 { 04273 $caption_type = null; 04274 $caption_lang = null; 04275 $caption_startTime = null; 04276 $caption_endTime = null; 04277 $caption_text = null; 04278 if (isset($caption['attribs']['']['type'])) 04279 { 04280 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 04281 } 04282 if (isset($caption['attribs']['']['lang'])) 04283 { 04284 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT); 04285 } 04286 if (isset($caption['attribs']['']['start'])) 04287 { 04288 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT); 04289 } 04290 if (isset($caption['attribs']['']['end'])) 04291 { 04292 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT); 04293 } 04294 if (isset($caption['data'])) 04295 { 04296 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04297 } 04298 $captions[] = new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text); 04299 } 04300 if (is_array($captions)) 04301 { 04302 $captions = array_values(SimplePie_Misc::array_unique($captions)); 04303 } 04304 } 04305 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'])) 04306 { 04307 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption) 04308 { 04309 $caption_type = null; 04310 $caption_lang = null; 04311 $caption_startTime = null; 04312 $caption_endTime = null; 04313 $caption_text = null; 04314 if (isset($caption['attribs']['']['type'])) 04315 { 04316 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 04317 } 04318 if (isset($caption['attribs']['']['lang'])) 04319 { 04320 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT); 04321 } 04322 if (isset($caption['attribs']['']['start'])) 04323 { 04324 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT); 04325 } 04326 if (isset($caption['attribs']['']['end'])) 04327 { 04328 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT); 04329 } 04330 if (isset($caption['data'])) 04331 { 04332 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04333 } 04334 $captions[] = new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text); 04335 } 04336 if (is_array($captions)) 04337 { 04338 $captions = array_values(SimplePie_Misc::array_unique($captions)); 04339 } 04340 } 04341 else 04342 { 04343 $captions = $captions_parent; 04344 } 04345 04346 // CATEGORIES 04347 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'])) 04348 { 04349 foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category) 04350 { 04351 $term = null; 04352 $scheme = null; 04353 $label = null; 04354 if (isset($category['data'])) 04355 { 04356 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04357 } 04358 if (isset($category['attribs']['']['scheme'])) 04359 { 04360 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 04361 } 04362 else 04363 { 04364 $scheme = 'http://search.yahoo.com/mrss/category_schema'; 04365 } 04366 if (isset($category['attribs']['']['label'])) 04367 { 04368 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); 04369 } 04370 $categories[] = new $this->feed->category_class($term, $scheme, $label); 04371 } 04372 } 04373 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'])) 04374 { 04375 foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category) 04376 { 04377 $term = null; 04378 $scheme = null; 04379 $label = null; 04380 if (isset($category['data'])) 04381 { 04382 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04383 } 04384 if (isset($category['attribs']['']['scheme'])) 04385 { 04386 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 04387 } 04388 else 04389 { 04390 $scheme = 'http://search.yahoo.com/mrss/category_schema'; 04391 } 04392 if (isset($category['attribs']['']['label'])) 04393 { 04394 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); 04395 } 04396 $categories[] = new $this->feed->category_class($term, $scheme, $label); 04397 } 04398 } 04399 if (is_array($categories) && is_array($categories_parent)) 04400 { 04401 $categories = array_values(SimplePie_Misc::array_unique(array_merge($categories, $categories_parent))); 04402 } 04403 elseif (is_array($categories)) 04404 { 04405 $categories = array_values(SimplePie_Misc::array_unique($categories)); 04406 } 04407 elseif (is_array($categories_parent)) 04408 { 04409 $categories = array_values(SimplePie_Misc::array_unique($categories_parent)); 04410 } 04411 04412 // COPYRIGHTS 04413 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'])) 04414 { 04415 $copyright_url = null; 04416 $copyright_label = null; 04417 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'])) 04418 { 04419 $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT); 04420 } 04421 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'])) 04422 { 04423 $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04424 } 04425 $copyrights = new $this->feed->copyright_class($copyright_url, $copyright_label); 04426 } 04427 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'])) 04428 { 04429 $copyright_url = null; 04430 $copyright_label = null; 04431 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'])) 04432 { 04433 $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT); 04434 } 04435 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'])) 04436 { 04437 $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04438 } 04439 $copyrights = new $this->feed->copyright_class($copyright_url, $copyright_label); 04440 } 04441 else 04442 { 04443 $copyrights = $copyrights_parent; 04444 } 04445 04446 // CREDITS 04447 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'])) 04448 { 04449 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit) 04450 { 04451 $credit_role = null; 04452 $credit_scheme = null; 04453 $credit_name = null; 04454 if (isset($credit['attribs']['']['role'])) 04455 { 04456 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT); 04457 } 04458 if (isset($credit['attribs']['']['scheme'])) 04459 { 04460 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 04461 } 04462 else 04463 { 04464 $credit_scheme = 'urn:ebu'; 04465 } 04466 if (isset($credit['data'])) 04467 { 04468 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04469 } 04470 $credits[] = new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name); 04471 } 04472 if (is_array($credits)) 04473 { 04474 $credits = array_values(SimplePie_Misc::array_unique($credits)); 04475 } 04476 } 04477 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'])) 04478 { 04479 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit) 04480 { 04481 $credit_role = null; 04482 $credit_scheme = null; 04483 $credit_name = null; 04484 if (isset($credit['attribs']['']['role'])) 04485 { 04486 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT); 04487 } 04488 if (isset($credit['attribs']['']['scheme'])) 04489 { 04490 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 04491 } 04492 else 04493 { 04494 $credit_scheme = 'urn:ebu'; 04495 } 04496 if (isset($credit['data'])) 04497 { 04498 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04499 } 04500 $credits[] = new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name); 04501 } 04502 if (is_array($credits)) 04503 { 04504 $credits = array_values(SimplePie_Misc::array_unique($credits)); 04505 } 04506 } 04507 else 04508 { 04509 $credits = $credits_parent; 04510 } 04511 04512 // DESCRIPTION 04513 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'])) 04514 { 04515 $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04516 } 04517 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'])) 04518 { 04519 $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04520 } 04521 else 04522 { 04523 $description = $description_parent; 04524 } 04525 04526 // HASHES 04527 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'])) 04528 { 04529 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash) 04530 { 04531 $value = null; 04532 $algo = null; 04533 if (isset($hash['data'])) 04534 { 04535 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04536 } 04537 if (isset($hash['attribs']['']['algo'])) 04538 { 04539 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT); 04540 } 04541 else 04542 { 04543 $algo = 'md5'; 04544 } 04545 $hashes[] = $algo.':'.$value; 04546 } 04547 if (is_array($hashes)) 04548 { 04549 $hashes = array_values(SimplePie_Misc::array_unique($hashes)); 04550 } 04551 } 04552 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'])) 04553 { 04554 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash) 04555 { 04556 $value = null; 04557 $algo = null; 04558 if (isset($hash['data'])) 04559 { 04560 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04561 } 04562 if (isset($hash['attribs']['']['algo'])) 04563 { 04564 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT); 04565 } 04566 else 04567 { 04568 $algo = 'md5'; 04569 } 04570 $hashes[] = $algo.':'.$value; 04571 } 04572 if (is_array($hashes)) 04573 { 04574 $hashes = array_values(SimplePie_Misc::array_unique($hashes)); 04575 } 04576 } 04577 else 04578 { 04579 $hashes = $hashes_parent; 04580 } 04581 04582 // KEYWORDS 04583 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'])) 04584 { 04585 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'])) 04586 { 04587 $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); 04588 foreach ($temp as $word) 04589 { 04590 $keywords[] = trim($word); 04591 } 04592 unset($temp); 04593 } 04594 if (is_array($keywords)) 04595 { 04596 $keywords = array_values(SimplePie_Misc::array_unique($keywords)); 04597 } 04598 } 04599 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'])) 04600 { 04601 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'])) 04602 { 04603 $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); 04604 foreach ($temp as $word) 04605 { 04606 $keywords[] = trim($word); 04607 } 04608 unset($temp); 04609 } 04610 if (is_array($keywords)) 04611 { 04612 $keywords = array_values(SimplePie_Misc::array_unique($keywords)); 04613 } 04614 } 04615 else 04616 { 04617 $keywords = $keywords_parent; 04618 } 04619 04620 // PLAYER 04621 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'])) 04622 { 04623 $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 04624 } 04625 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'])) 04626 { 04627 $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 04628 } 04629 else 04630 { 04631 $player = $player_parent; 04632 } 04633 04634 // RATINGS 04635 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'])) 04636 { 04637 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating) 04638 { 04639 $rating_scheme = null; 04640 $rating_value = null; 04641 if (isset($rating['attribs']['']['scheme'])) 04642 { 04643 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 04644 } 04645 else 04646 { 04647 $rating_scheme = 'urn:simple'; 04648 } 04649 if (isset($rating['data'])) 04650 { 04651 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04652 } 04653 $ratings[] = new $this->feed->rating_class($rating_scheme, $rating_value); 04654 } 04655 if (is_array($ratings)) 04656 { 04657 $ratings = array_values(SimplePie_Misc::array_unique($ratings)); 04658 } 04659 } 04660 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'])) 04661 { 04662 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating) 04663 { 04664 $rating_scheme = null; 04665 $rating_value = null; 04666 if (isset($rating['attribs']['']['scheme'])) 04667 { 04668 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 04669 } 04670 else 04671 { 04672 $rating_scheme = 'urn:simple'; 04673 } 04674 if (isset($rating['data'])) 04675 { 04676 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04677 } 04678 $ratings[] = new $this->feed->rating_class($rating_scheme, $rating_value); 04679 } 04680 if (is_array($ratings)) 04681 { 04682 $ratings = array_values(SimplePie_Misc::array_unique($ratings)); 04683 } 04684 } 04685 else 04686 { 04687 $ratings = $ratings_parent; 04688 } 04689 04690 // RESTRICTIONS 04691 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'])) 04692 { 04693 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction) 04694 { 04695 $restriction_relationship = null; 04696 $restriction_type = null; 04697 $restriction_value = null; 04698 if (isset($restriction['attribs']['']['relationship'])) 04699 { 04700 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT); 04701 } 04702 if (isset($restriction['attribs']['']['type'])) 04703 { 04704 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 04705 } 04706 if (isset($restriction['data'])) 04707 { 04708 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04709 } 04710 $restrictions[] = new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value); 04711 } 04712 if (is_array($restrictions)) 04713 { 04714 $restrictions = array_values(SimplePie_Misc::array_unique($restrictions)); 04715 } 04716 } 04717 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'])) 04718 { 04719 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction) 04720 { 04721 $restriction_relationship = null; 04722 $restriction_type = null; 04723 $restriction_value = null; 04724 if (isset($restriction['attribs']['']['relationship'])) 04725 { 04726 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT); 04727 } 04728 if (isset($restriction['attribs']['']['type'])) 04729 { 04730 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 04731 } 04732 if (isset($restriction['data'])) 04733 { 04734 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04735 } 04736 $restrictions[] = new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value); 04737 } 04738 if (is_array($restrictions)) 04739 { 04740 $restrictions = array_values(SimplePie_Misc::array_unique($restrictions)); 04741 } 04742 } 04743 else 04744 { 04745 $restrictions = $restrictions_parent; 04746 } 04747 04748 // THUMBNAILS 04749 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'])) 04750 { 04751 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) 04752 { 04753 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 04754 } 04755 if (is_array($thumbnails)) 04756 { 04757 $thumbnails = array_values(SimplePie_Misc::array_unique($thumbnails)); 04758 } 04759 } 04760 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'])) 04761 { 04762 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) 04763 { 04764 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 04765 } 04766 if (is_array($thumbnails)) 04767 { 04768 $thumbnails = array_values(SimplePie_Misc::array_unique($thumbnails)); 04769 } 04770 } 04771 else 04772 { 04773 $thumbnails = $thumbnails_parent; 04774 } 04775 04776 // TITLES 04777 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'])) 04778 { 04779 $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04780 } 04781 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'])) 04782 { 04783 $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04784 } 04785 else 04786 { 04787 $title = $title_parent; 04788 } 04789 04790 $this->data['enclosures'][] = new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width); 04791 } 04792 } 04793 } 04794 } 04795 04796 // If we have standalone media:content tags, loop through them. 04797 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'])) 04798 { 04799 foreach ((array) $this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content) 04800 { 04801 if (isset($content['attribs']['']['url']) || isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'])) 04802 { 04803 // Attributes 04804 $bitrate = null; 04805 $channels = null; 04806 $duration = null; 04807 $expression = null; 04808 $framerate = null; 04809 $height = null; 04810 $javascript = null; 04811 $lang = null; 04812 $length = null; 04813 $medium = null; 04814 $samplingrate = null; 04815 $type = null; 04816 $url = null; 04817 $width = null; 04818 04819 // Elements 04820 $captions = null; 04821 $categories = null; 04822 $copyrights = null; 04823 $credits = null; 04824 $description = null; 04825 $hashes = null; 04826 $keywords = null; 04827 $player = null; 04828 $ratings = null; 04829 $restrictions = null; 04830 $thumbnails = null; 04831 $title = null; 04832 04833 // Start checking the attributes of media:content 04834 if (isset($content['attribs']['']['bitrate'])) 04835 { 04836 $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT); 04837 } 04838 if (isset($content['attribs']['']['channels'])) 04839 { 04840 $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT); 04841 } 04842 if (isset($content['attribs']['']['duration'])) 04843 { 04844 $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT); 04845 } 04846 else 04847 { 04848 $duration = $duration_parent; 04849 } 04850 if (isset($content['attribs']['']['expression'])) 04851 { 04852 $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT); 04853 } 04854 if (isset($content['attribs']['']['framerate'])) 04855 { 04856 $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT); 04857 } 04858 if (isset($content['attribs']['']['height'])) 04859 { 04860 $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT); 04861 } 04862 if (isset($content['attribs']['']['lang'])) 04863 { 04864 $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT); 04865 } 04866 if (isset($content['attribs']['']['fileSize'])) 04867 { 04868 $length = ceil($content['attribs']['']['fileSize']); 04869 } 04870 if (isset($content['attribs']['']['medium'])) 04871 { 04872 $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT); 04873 } 04874 if (isset($content['attribs']['']['samplingrate'])) 04875 { 04876 $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT); 04877 } 04878 if (isset($content['attribs']['']['type'])) 04879 { 04880 $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 04881 } 04882 if (isset($content['attribs']['']['width'])) 04883 { 04884 $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT); 04885 } 04886 if (isset($content['attribs']['']['url'])) 04887 { 04888 $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 04889 } 04890 // Checking the other optional media: elements. Priority: media:content, media:group, item, channel 04891 04892 // CAPTIONS 04893 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'])) 04894 { 04895 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption) 04896 { 04897 $caption_type = null; 04898 $caption_lang = null; 04899 $caption_startTime = null; 04900 $caption_endTime = null; 04901 $caption_text = null; 04902 if (isset($caption['attribs']['']['type'])) 04903 { 04904 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 04905 } 04906 if (isset($caption['attribs']['']['lang'])) 04907 { 04908 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT); 04909 } 04910 if (isset($caption['attribs']['']['start'])) 04911 { 04912 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT); 04913 } 04914 if (isset($caption['attribs']['']['end'])) 04915 { 04916 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT); 04917 } 04918 if (isset($caption['data'])) 04919 { 04920 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04921 } 04922 $captions[] = new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text); 04923 } 04924 if (is_array($captions)) 04925 { 04926 $captions = array_values(SimplePie_Misc::array_unique($captions)); 04927 } 04928 } 04929 else 04930 { 04931 $captions = $captions_parent; 04932 } 04933 04934 // CATEGORIES 04935 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'])) 04936 { 04937 foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category) 04938 { 04939 $term = null; 04940 $scheme = null; 04941 $label = null; 04942 if (isset($category['data'])) 04943 { 04944 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04945 } 04946 if (isset($category['attribs']['']['scheme'])) 04947 { 04948 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 04949 } 04950 else 04951 { 04952 $scheme = 'http://search.yahoo.com/mrss/category_schema'; 04953 } 04954 if (isset($category['attribs']['']['label'])) 04955 { 04956 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); 04957 } 04958 $categories[] = new $this->feed->category_class($term, $scheme, $label); 04959 } 04960 } 04961 if (is_array($categories) && is_array($categories_parent)) 04962 { 04963 $categories = array_values(SimplePie_Misc::array_unique(array_merge($categories, $categories_parent))); 04964 } 04965 elseif (is_array($categories)) 04966 { 04967 $categories = array_values(SimplePie_Misc::array_unique($categories)); 04968 } 04969 elseif (is_array($categories_parent)) 04970 { 04971 $categories = array_values(SimplePie_Misc::array_unique($categories_parent)); 04972 } 04973 else 04974 { 04975 $categories = null; 04976 } 04977 04978 // COPYRIGHTS 04979 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'])) 04980 { 04981 $copyright_url = null; 04982 $copyright_label = null; 04983 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'])) 04984 { 04985 $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT); 04986 } 04987 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'])) 04988 { 04989 $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 04990 } 04991 $copyrights = new $this->feed->copyright_class($copyright_url, $copyright_label); 04992 } 04993 else 04994 { 04995 $copyrights = $copyrights_parent; 04996 } 04997 04998 // CREDITS 04999 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'])) 05000 { 05001 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit) 05002 { 05003 $credit_role = null; 05004 $credit_scheme = null; 05005 $credit_name = null; 05006 if (isset($credit['attribs']['']['role'])) 05007 { 05008 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT); 05009 } 05010 if (isset($credit['attribs']['']['scheme'])) 05011 { 05012 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 05013 } 05014 else 05015 { 05016 $credit_scheme = 'urn:ebu'; 05017 } 05018 if (isset($credit['data'])) 05019 { 05020 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05021 } 05022 $credits[] = new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name); 05023 } 05024 if (is_array($credits)) 05025 { 05026 $credits = array_values(SimplePie_Misc::array_unique($credits)); 05027 } 05028 } 05029 else 05030 { 05031 $credits = $credits_parent; 05032 } 05033 05034 // DESCRIPTION 05035 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'])) 05036 { 05037 $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05038 } 05039 else 05040 { 05041 $description = $description_parent; 05042 } 05043 05044 // HASHES 05045 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'])) 05046 { 05047 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash) 05048 { 05049 $value = null; 05050 $algo = null; 05051 if (isset($hash['data'])) 05052 { 05053 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05054 } 05055 if (isset($hash['attribs']['']['algo'])) 05056 { 05057 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT); 05058 } 05059 else 05060 { 05061 $algo = 'md5'; 05062 } 05063 $hashes[] = $algo.':'.$value; 05064 } 05065 if (is_array($hashes)) 05066 { 05067 $hashes = array_values(SimplePie_Misc::array_unique($hashes)); 05068 } 05069 } 05070 else 05071 { 05072 $hashes = $hashes_parent; 05073 } 05074 05075 // KEYWORDS 05076 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'])) 05077 { 05078 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'])) 05079 { 05080 $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); 05081 foreach ($temp as $word) 05082 { 05083 $keywords[] = trim($word); 05084 } 05085 unset($temp); 05086 } 05087 if (is_array($keywords)) 05088 { 05089 $keywords = array_values(SimplePie_Misc::array_unique($keywords)); 05090 } 05091 } 05092 else 05093 { 05094 $keywords = $keywords_parent; 05095 } 05096 05097 // PLAYER 05098 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'])) 05099 { 05100 $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 05101 } 05102 else 05103 { 05104 $player = $player_parent; 05105 } 05106 05107 // RATINGS 05108 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'])) 05109 { 05110 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating) 05111 { 05112 $rating_scheme = null; 05113 $rating_value = null; 05114 if (isset($rating['attribs']['']['scheme'])) 05115 { 05116 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 05117 } 05118 else 05119 { 05120 $rating_scheme = 'urn:simple'; 05121 } 05122 if (isset($rating['data'])) 05123 { 05124 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05125 } 05126 $ratings[] = new $this->feed->rating_class($rating_scheme, $rating_value); 05127 } 05128 if (is_array($ratings)) 05129 { 05130 $ratings = array_values(SimplePie_Misc::array_unique($ratings)); 05131 } 05132 } 05133 else 05134 { 05135 $ratings = $ratings_parent; 05136 } 05137 05138 // RESTRICTIONS 05139 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'])) 05140 { 05141 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction) 05142 { 05143 $restriction_relationship = null; 05144 $restriction_type = null; 05145 $restriction_value = null; 05146 if (isset($restriction['attribs']['']['relationship'])) 05147 { 05148 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT); 05149 } 05150 if (isset($restriction['attribs']['']['type'])) 05151 { 05152 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 05153 } 05154 if (isset($restriction['data'])) 05155 { 05156 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05157 } 05158 $restrictions[] = new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value); 05159 } 05160 if (is_array($restrictions)) 05161 { 05162 $restrictions = array_values(SimplePie_Misc::array_unique($restrictions)); 05163 } 05164 } 05165 else 05166 { 05167 $restrictions = $restrictions_parent; 05168 } 05169 05170 // THUMBNAILS 05171 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'])) 05172 { 05173 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) 05174 { 05175 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 05176 } 05177 if (is_array($thumbnails)) 05178 { 05179 $thumbnails = array_values(SimplePie_Misc::array_unique($thumbnails)); 05180 } 05181 } 05182 else 05183 { 05184 $thumbnails = $thumbnails_parent; 05185 } 05186 05187 // TITLES 05188 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'])) 05189 { 05190 $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05191 } 05192 else 05193 { 05194 $title = $title_parent; 05195 } 05196 05197 $this->data['enclosures'][] = new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width); 05198 } 05199 } 05200 } 05201 05202 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link) 05203 { 05204 if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure') 05205 { 05206 // Attributes 05207 $bitrate = null; 05208 $channels = null; 05209 $duration = null; 05210 $expression = null; 05211 $framerate = null; 05212 $height = null; 05213 $javascript = null; 05214 $lang = null; 05215 $length = null; 05216 $medium = null; 05217 $samplingrate = null; 05218 $type = null; 05219 $url = null; 05220 $width = null; 05221 05222 $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 05223 if (isset($link['attribs']['']['type'])) 05224 { 05225 $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 05226 } 05227 if (isset($link['attribs']['']['length'])) 05228 { 05229 $length = ceil($link['attribs']['']['length']); 05230 } 05231 05232 // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor 05233 $this->data['enclosures'][] = new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width); 05234 } 05235 } 05236 05237 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link) 05238 { 05239 if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure') 05240 { 05241 // Attributes 05242 $bitrate = null; 05243 $channels = null; 05244 $duration = null; 05245 $expression = null; 05246 $framerate = null; 05247 $height = null; 05248 $javascript = null; 05249 $lang = null; 05250 $length = null; 05251 $medium = null; 05252 $samplingrate = null; 05253 $type = null; 05254 $url = null; 05255 $width = null; 05256 05257 $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 05258 if (isset($link['attribs']['']['type'])) 05259 { 05260 $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 05261 } 05262 if (isset($link['attribs']['']['length'])) 05263 { 05264 $length = ceil($link['attribs']['']['length']); 05265 } 05266 05267 // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor 05268 $this->data['enclosures'][] = new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width); 05269 } 05270 } 05271 05272 if ($enclosure = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'enclosure')) 05273 { 05274 if (isset($enclosure[0]['attribs']['']['url'])) 05275 { 05276 // Attributes 05277 $bitrate = null; 05278 $channels = null; 05279 $duration = null; 05280 $expression = null; 05281 $framerate = null; 05282 $height = null; 05283 $javascript = null; 05284 $lang = null; 05285 $length = null; 05286 $medium = null; 05287 $samplingrate = null; 05288 $type = null; 05289 $url = null; 05290 $width = null; 05291 05292 $url = $this->sanitize($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure[0])); 05293 if (isset($enclosure[0]['attribs']['']['type'])) 05294 { 05295 $type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 05296 } 05297 if (isset($enclosure[0]['attribs']['']['length'])) 05298 { 05299 $length = ceil($enclosure[0]['attribs']['']['length']); 05300 } 05301 05302 // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor 05303 $this->data['enclosures'][] = new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width); 05304 } 05305 } 05306 05307 if (sizeof($this->data['enclosures']) === 0 && ($url || $type || $length || $bitrate || $captions_parent || $categories_parent || $channels || $copyrights_parent || $credits_parent || $description_parent || $duration_parent || $expression || $framerate || $hashes_parent || $height || $keywords_parent || $lang || $medium || $player_parent || $ratings_parent || $restrictions_parent || $samplingrate || $thumbnails_parent || $title_parent || $width)) 05308 { 05309 // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor 05310 $this->data['enclosures'][] = new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width); 05311 } 05312 05313 $this->data['enclosures'] = array_values(SimplePie_Misc::array_unique($this->data['enclosures'])); 05314 } 05315 if (!empty($this->data['enclosures'])) 05316 { 05317 return $this->data['enclosures']; 05318 } 05319 else 05320 { 05321 return null; 05322 } 05323 } 05324 05325 public function get_latitude() 05326 { 05327 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat')) 05328 { 05329 return (float) $return[0]['data']; 05330 } 05331 elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) 05332 { 05333 return (float) $match[1]; 05334 } 05335 else 05336 { 05337 return null; 05338 } 05339 } 05340 05341 public function get_longitude() 05342 { 05343 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long')) 05344 { 05345 return (float) $return[0]['data']; 05346 } 05347 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon')) 05348 { 05349 return (float) $return[0]['data']; 05350 } 05351 elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) 05352 { 05353 return (float) $match[2]; 05354 } 05355 else 05356 { 05357 return null; 05358 } 05359 } 05360 05361 public function get_source() 05362 { 05363 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'source')) 05364 { 05365 return new $this->feed->source_class($this, $return[0]); 05366 } 05367 else 05368 { 05369 return null; 05370 } 05371 } 05372 } 05373 05374 class SimplePie_Source 05375 { 05376 var $item; 05377 var $data = array(); 05378 05379 public function __construct($item, $data) 05380 { 05381 $this->item = $item; 05382 $this->data = $data; 05383 } 05384 05385 public function __toString() 05386 { 05387 return md5(serialize($this->data)); 05388 } 05389 05390 public function get_source_tags($namespace, $tag) 05391 { 05392 if (isset($this->data['child'][$namespace][$tag])) 05393 { 05394 return $this->data['child'][$namespace][$tag]; 05395 } 05396 else 05397 { 05398 return null; 05399 } 05400 } 05401 05402 public function get_base($element = array()) 05403 { 05404 return $this->item->get_base($element); 05405 } 05406 05407 public function sanitize($data, $type, $base = '') 05408 { 05409 return $this->item->sanitize($data, $type, $base); 05410 } 05411 05412 public function get_item() 05413 { 05414 return $this->item; 05415 } 05416 05417 public function get_title() 05418 { 05419 if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title')) 05420 { 05421 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0])); 05422 } 05423 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) 05424 { 05425 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0])); 05426 } 05427 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) 05428 { 05429 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 05430 } 05431 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) 05432 { 05433 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 05434 } 05435 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) 05436 { 05437 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 05438 } 05439 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) 05440 { 05441 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05442 } 05443 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) 05444 { 05445 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05446 } 05447 else 05448 { 05449 return null; 05450 } 05451 } 05452 05453 public function get_category($key = 0) 05454 { 05455 $categories = $this->get_categories(); 05456 if (isset($categories[$key])) 05457 { 05458 return $categories[$key]; 05459 } 05460 else 05461 { 05462 return null; 05463 } 05464 } 05465 05466 public function get_categories() 05467 { 05468 $categories = array(); 05469 05470 foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category) 05471 { 05472 $term = null; 05473 $scheme = null; 05474 $label = null; 05475 if (isset($category['attribs']['']['term'])) 05476 { 05477 $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT); 05478 } 05479 if (isset($category['attribs']['']['scheme'])) 05480 { 05481 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 05482 } 05483 if (isset($category['attribs']['']['label'])) 05484 { 05485 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); 05486 } 05487 $categories[] = new $this->item->feed->category_class($term, $scheme, $label); 05488 } 05489 foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category) 05490 { 05491 // This is really the label, but keep this as the term also for BC. 05492 // Label will also work on retrieving because that falls back to term. 05493 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05494 if (isset($category['attribs']['']['domain'])) 05495 { 05496 $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT); 05497 } 05498 else 05499 { 05500 $scheme = null; 05501 } 05502 $categories[] = new $this->item->feed->category_class($term, $scheme, null); 05503 } 05504 foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category) 05505 { 05506 $categories[] = new $this->item->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 05507 } 05508 foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category) 05509 { 05510 $categories[] = new $this->item->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 05511 } 05512 05513 if (!empty($categories)) 05514 { 05515 return SimplePie_Misc::array_unique($categories); 05516 } 05517 else 05518 { 05519 return null; 05520 } 05521 } 05522 05523 public function get_author($key = 0) 05524 { 05525 $authors = $this->get_authors(); 05526 if (isset($authors[$key])) 05527 { 05528 return $authors[$key]; 05529 } 05530 else 05531 { 05532 return null; 05533 } 05534 } 05535 05536 public function get_authors() 05537 { 05538 $authors = array(); 05539 foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author) 05540 { 05541 $name = null; 05542 $uri = null; 05543 $email = null; 05544 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) 05545 { 05546 $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05547 } 05548 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) 05549 { 05550 $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])); 05551 } 05552 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) 05553 { 05554 $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05555 } 05556 if ($name !== null || $email !== null || $uri !== null) 05557 { 05558 $authors[] = new $this->item->feed->author_class($name, $uri, $email); 05559 } 05560 } 05561 if ($author = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author')) 05562 { 05563 $name = null; 05564 $url = null; 05565 $email = null; 05566 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) 05567 { 05568 $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05569 } 05570 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) 05571 { 05572 $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])); 05573 } 05574 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) 05575 { 05576 $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05577 } 05578 if ($name !== null || $email !== null || $url !== null) 05579 { 05580 $authors[] = new $this->item->feed->author_class($name, $url, $email); 05581 } 05582 } 05583 foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author) 05584 { 05585 $authors[] = new $this->item->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 05586 } 05587 foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author) 05588 { 05589 $authors[] = new $this->item->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 05590 } 05591 foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author) 05592 { 05593 $authors[] = new $this->item->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 05594 } 05595 05596 if (!empty($authors)) 05597 { 05598 return SimplePie_Misc::array_unique($authors); 05599 } 05600 else 05601 { 05602 return null; 05603 } 05604 } 05605 05606 public function get_contributor($key = 0) 05607 { 05608 $contributors = $this->get_contributors(); 05609 if (isset($contributors[$key])) 05610 { 05611 return $contributors[$key]; 05612 } 05613 else 05614 { 05615 return null; 05616 } 05617 } 05618 05619 public function get_contributors() 05620 { 05621 $contributors = array(); 05622 foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor) 05623 { 05624 $name = null; 05625 $uri = null; 05626 $email = null; 05627 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) 05628 { 05629 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05630 } 05631 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) 05632 { 05633 $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])); 05634 } 05635 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) 05636 { 05637 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05638 } 05639 if ($name !== null || $email !== null || $uri !== null) 05640 { 05641 $contributors[] = new $this->item->feed->author_class($name, $uri, $email); 05642 } 05643 } 05644 foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor) 05645 { 05646 $name = null; 05647 $url = null; 05648 $email = null; 05649 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) 05650 { 05651 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05652 } 05653 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) 05654 { 05655 $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])); 05656 } 05657 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) 05658 { 05659 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05660 } 05661 if ($name !== null || $email !== null || $url !== null) 05662 { 05663 $contributors[] = new $this->item->feed->author_class($name, $url, $email); 05664 } 05665 } 05666 05667 if (!empty($contributors)) 05668 { 05669 return SimplePie_Misc::array_unique($contributors); 05670 } 05671 else 05672 { 05673 return null; 05674 } 05675 } 05676 05677 public function get_link($key = 0, $rel = 'alternate') 05678 { 05679 $links = $this->get_links($rel); 05680 if (isset($links[$key])) 05681 { 05682 return $links[$key]; 05683 } 05684 else 05685 { 05686 return null; 05687 } 05688 } 05689 05693 public function get_permalink() 05694 { 05695 return $this->get_link(0); 05696 } 05697 05698 public function get_links($rel = 'alternate') 05699 { 05700 if (!isset($this->data['links'])) 05701 { 05702 $this->data['links'] = array(); 05703 if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link')) 05704 { 05705 foreach ($links as $link) 05706 { 05707 if (isset($link['attribs']['']['href'])) 05708 { 05709 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 05710 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 05711 } 05712 } 05713 } 05714 if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link')) 05715 { 05716 foreach ($links as $link) 05717 { 05718 if (isset($link['attribs']['']['href'])) 05719 { 05720 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 05721 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 05722 05723 } 05724 } 05725 } 05726 if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) 05727 { 05728 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 05729 } 05730 if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) 05731 { 05732 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 05733 } 05734 if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) 05735 { 05736 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 05737 } 05738 05739 $keys = array_keys($this->data['links']); 05740 foreach ($keys as $key) 05741 { 05742 if (SimplePie_Misc::is_isegment_nz_nc($key)) 05743 { 05744 if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key])) 05745 { 05746 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]); 05747 $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]; 05748 } 05749 else 05750 { 05751 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key]; 05752 } 05753 } 05754 elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) 05755 { 05756 $this->data['links'][substr($key, 41)] =& $this->data['links'][$key]; 05757 } 05758 $this->data['links'][$key] = array_unique($this->data['links'][$key]); 05759 } 05760 } 05761 05762 if (isset($this->data['links'][$rel])) 05763 { 05764 return $this->data['links'][$rel]; 05765 } 05766 else 05767 { 05768 return null; 05769 } 05770 } 05771 05772 public function get_description() 05773 { 05774 if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle')) 05775 { 05776 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0])); 05777 } 05778 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline')) 05779 { 05780 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0])); 05781 } 05782 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) 05783 { 05784 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 05785 } 05786 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) 05787 { 05788 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 05789 } 05790 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) 05791 { 05792 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 05793 } 05794 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) 05795 { 05796 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05797 } 05798 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) 05799 { 05800 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05801 } 05802 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) 05803 { 05804 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 05805 } 05806 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) 05807 { 05808 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 05809 } 05810 else 05811 { 05812 return null; 05813 } 05814 } 05815 05816 public function get_copyright() 05817 { 05818 if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights')) 05819 { 05820 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0])); 05821 } 05822 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright')) 05823 { 05824 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0])); 05825 } 05826 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright')) 05827 { 05828 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05829 } 05830 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights')) 05831 { 05832 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05833 } 05834 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights')) 05835 { 05836 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05837 } 05838 else 05839 { 05840 return null; 05841 } 05842 } 05843 05844 public function get_language() 05845 { 05846 if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language')) 05847 { 05848 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05849 } 05850 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language')) 05851 { 05852 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05853 } 05854 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language')) 05855 { 05856 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 05857 } 05858 elseif (isset($this->data['xml_lang'])) 05859 { 05860 return $this->sanitize($this->data['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); 05861 } 05862 else 05863 { 05864 return null; 05865 } 05866 } 05867 05868 public function get_latitude() 05869 { 05870 if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat')) 05871 { 05872 return (float) $return[0]['data']; 05873 } 05874 elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) 05875 { 05876 return (float) $match[1]; 05877 } 05878 else 05879 { 05880 return null; 05881 } 05882 } 05883 05884 public function get_longitude() 05885 { 05886 if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long')) 05887 { 05888 return (float) $return[0]['data']; 05889 } 05890 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon')) 05891 { 05892 return (float) $return[0]['data']; 05893 } 05894 elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) 05895 { 05896 return (float) $match[2]; 05897 } 05898 else 05899 { 05900 return null; 05901 } 05902 } 05903 05904 public function get_image_url() 05905 { 05906 if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image')) 05907 { 05908 return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI); 05909 } 05910 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo')) 05911 { 05912 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 05913 } 05914 elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon')) 05915 { 05916 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 05917 } 05918 else 05919 { 05920 return null; 05921 } 05922 } 05923 } 05924 05925 class SimplePie_Author 05926 { 05927 var $name; 05928 var $link; 05929 var $email; 05930 05931 // Constructor, used to input the data 05932 public function __construct($name = null, $link = null, $email = null) 05933 { 05934 $this->name = $name; 05935 $this->link = $link; 05936 $this->email = $email; 05937 } 05938 05939 public function __toString() 05940 { 05941 // There is no $this->data here 05942 return md5(serialize($this)); 05943 } 05944 05945 public function get_name() 05946 { 05947 if ($this->name !== null) 05948 { 05949 return $this->name; 05950 } 05951 else 05952 { 05953 return null; 05954 } 05955 } 05956 05957 public function get_link() 05958 { 05959 if ($this->link !== null) 05960 { 05961 return $this->link; 05962 } 05963 else 05964 { 05965 return null; 05966 } 05967 } 05968 05969 public function get_email() 05970 { 05971 if ($this->email !== null) 05972 { 05973 return $this->email; 05974 } 05975 else 05976 { 05977 return null; 05978 } 05979 } 05980 } 05981 05982 class SimplePie_Category 05983 { 05984 var $term; 05985 var $scheme; 05986 var $label; 05987 05988 // Constructor, used to input the data 05989 public function __construct($term = null, $scheme = null, $label = null) 05990 { 05991 $this->term = $term; 05992 $this->scheme = $scheme; 05993 $this->label = $label; 05994 } 05995 05996 public function __toString() 05997 { 05998 // There is no $this->data here 05999 return md5(serialize($this)); 06000 } 06001 06002 public function get_term() 06003 { 06004 if ($this->term !== null) 06005 { 06006 return $this->term; 06007 } 06008 else 06009 { 06010 return null; 06011 } 06012 } 06013 06014 public function get_scheme() 06015 { 06016 if ($this->scheme !== null) 06017 { 06018 return $this->scheme; 06019 } 06020 else 06021 { 06022 return null; 06023 } 06024 } 06025 06026 public function get_label() 06027 { 06028 if ($this->label !== null) 06029 { 06030 return $this->label; 06031 } 06032 else 06033 { 06034 return $this->get_term(); 06035 } 06036 } 06037 } 06038 06039 class SimplePie_Enclosure 06040 { 06041 var $bitrate; 06042 var $captions; 06043 var $categories; 06044 var $channels; 06045 var $copyright; 06046 var $credits; 06047 var $description; 06048 var $duration; 06049 var $expression; 06050 var $framerate; 06051 var $handler; 06052 var $hashes; 06053 var $height; 06054 var $javascript; 06055 var $keywords; 06056 var $lang; 06057 var $length; 06058 var $link; 06059 var $medium; 06060 var $player; 06061 var $ratings; 06062 var $restrictions; 06063 var $samplingrate; 06064 var $thumbnails; 06065 var $title; 06066 var $type; 06067 var $width; 06068 06069 // Constructor, used to input the data 06070 public function __construct($link = null, $type = null, $length = null, $javascript = null, $bitrate = null, $captions = null, $categories = null, $channels = null, $copyright = null, $credits = null, $description = null, $duration = null, $expression = null, $framerate = null, $hashes = null, $height = null, $keywords = null, $lang = null, $medium = null, $player = null, $ratings = null, $restrictions = null, $samplingrate = null, $thumbnails = null, $title = null, $width = null) 06071 { 06072 $this->bitrate = $bitrate; 06073 $this->captions = $captions; 06074 $this->categories = $categories; 06075 $this->channels = $channels; 06076 $this->copyright = $copyright; 06077 $this->credits = $credits; 06078 $this->description = $description; 06079 $this->duration = $duration; 06080 $this->expression = $expression; 06081 $this->framerate = $framerate; 06082 $this->hashes = $hashes; 06083 $this->height = $height; 06084 $this->javascript = $javascript; 06085 $this->keywords = $keywords; 06086 $this->lang = $lang; 06087 $this->length = $length; 06088 $this->link = $link; 06089 $this->medium = $medium; 06090 $this->player = $player; 06091 $this->ratings = $ratings; 06092 $this->restrictions = $restrictions; 06093 $this->samplingrate = $samplingrate; 06094 $this->thumbnails = $thumbnails; 06095 $this->title = $title; 06096 $this->type = $type; 06097 $this->width = $width; 06098 06099 if (class_exists('idna_convert')) 06100 { 06101 $idn = new idna_convert(); 06102 $parsed = SimplePie_Misc::parse_url($link); 06103 $this->link = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']); 06104 } 06105 $this->handler = $this->get_handler(); // Needs to load last 06106 } 06107 06108 public function __toString() 06109 { 06110 // There is no $this->data here 06111 return md5(serialize($this)); 06112 } 06113 06114 public function get_bitrate() 06115 { 06116 if ($this->bitrate !== null) 06117 { 06118 return $this->bitrate; 06119 } 06120 else 06121 { 06122 return null; 06123 } 06124 } 06125 06126 public function get_caption($key = 0) 06127 { 06128 $captions = $this->get_captions(); 06129 if (isset($captions[$key])) 06130 { 06131 return $captions[$key]; 06132 } 06133 else 06134 { 06135 return null; 06136 } 06137 } 06138 06139 public function get_captions() 06140 { 06141 if ($this->captions !== null) 06142 { 06143 return $this->captions; 06144 } 06145 else 06146 { 06147 return null; 06148 } 06149 } 06150 06151 public function get_category($key = 0) 06152 { 06153 $categories = $this->get_categories(); 06154 if (isset($categories[$key])) 06155 { 06156 return $categories[$key]; 06157 } 06158 else 06159 { 06160 return null; 06161 } 06162 } 06163 06164 public function get_categories() 06165 { 06166 if ($this->categories !== null) 06167 { 06168 return $this->categories; 06169 } 06170 else 06171 { 06172 return null; 06173 } 06174 } 06175 06176 public function get_channels() 06177 { 06178 if ($this->channels !== null) 06179 { 06180 return $this->channels; 06181 } 06182 else 06183 { 06184 return null; 06185 } 06186 } 06187 06188 public function get_copyright() 06189 { 06190 if ($this->copyright !== null) 06191 { 06192 return $this->copyright; 06193 } 06194 else 06195 { 06196 return null; 06197 } 06198 } 06199 06200 public function get_credit($key = 0) 06201 { 06202 $credits = $this->get_credits(); 06203 if (isset($credits[$key])) 06204 { 06205 return $credits[$key]; 06206 } 06207 else 06208 { 06209 return null; 06210 } 06211 } 06212 06213 public function get_credits() 06214 { 06215 if ($this->credits !== null) 06216 { 06217 return $this->credits; 06218 } 06219 else 06220 { 06221 return null; 06222 } 06223 } 06224 06225 public function get_description() 06226 { 06227 if ($this->description !== null) 06228 { 06229 return $this->description; 06230 } 06231 else 06232 { 06233 return null; 06234 } 06235 } 06236 06237 public function get_duration($convert = false) 06238 { 06239 if ($this->duration !== null) 06240 { 06241 if ($convert) 06242 { 06243 $time = SimplePie_Misc::time_hms($this->duration); 06244 return $time; 06245 } 06246 else 06247 { 06248 return $this->duration; 06249 } 06250 } 06251 else 06252 { 06253 return null; 06254 } 06255 } 06256 06257 public function get_expression() 06258 { 06259 if ($this->expression !== null) 06260 { 06261 return $this->expression; 06262 } 06263 else 06264 { 06265 return 'full'; 06266 } 06267 } 06268 06269 public function get_extension() 06270 { 06271 if ($this->link !== null) 06272 { 06273 $url = SimplePie_Misc::parse_url($this->link); 06274 if ($url['path'] !== '') 06275 { 06276 return pathinfo($url['path'], PATHINFO_EXTENSION); 06277 } 06278 } 06279 return null; 06280 } 06281 06282 public function get_framerate() 06283 { 06284 if ($this->framerate !== null) 06285 { 06286 return $this->framerate; 06287 } 06288 else 06289 { 06290 return null; 06291 } 06292 } 06293 06294 public function get_handler() 06295 { 06296 return $this->get_real_type(true); 06297 } 06298 06299 public function get_hash($key = 0) 06300 { 06301 $hashes = $this->get_hashes(); 06302 if (isset($hashes[$key])) 06303 { 06304 return $hashes[$key]; 06305 } 06306 else 06307 { 06308 return null; 06309 } 06310 } 06311 06312 public function get_hashes() 06313 { 06314 if ($this->hashes !== null) 06315 { 06316 return $this->hashes; 06317 } 06318 else 06319 { 06320 return null; 06321 } 06322 } 06323 06324 public function get_height() 06325 { 06326 if ($this->height !== null) 06327 { 06328 return $this->height; 06329 } 06330 else 06331 { 06332 return null; 06333 } 06334 } 06335 06336 public function get_language() 06337 { 06338 if ($this->lang !== null) 06339 { 06340 return $this->lang; 06341 } 06342 else 06343 { 06344 return null; 06345 } 06346 } 06347 06348 public function get_keyword($key = 0) 06349 { 06350 $keywords = $this->get_keywords(); 06351 if (isset($keywords[$key])) 06352 { 06353 return $keywords[$key]; 06354 } 06355 else 06356 { 06357 return null; 06358 } 06359 } 06360 06361 public function get_keywords() 06362 { 06363 if ($this->keywords !== null) 06364 { 06365 return $this->keywords; 06366 } 06367 else 06368 { 06369 return null; 06370 } 06371 } 06372 06373 public function get_length() 06374 { 06375 if ($this->length !== null) 06376 { 06377 return $this->length; 06378 } 06379 else 06380 { 06381 return null; 06382 } 06383 } 06384 06385 public function get_link() 06386 { 06387 if ($this->link !== null) 06388 { 06389 return urldecode($this->link); 06390 } 06391 else 06392 { 06393 return null; 06394 } 06395 } 06396 06397 public function get_medium() 06398 { 06399 if ($this->medium !== null) 06400 { 06401 return $this->medium; 06402 } 06403 else 06404 { 06405 return null; 06406 } 06407 } 06408 06409 public function get_player() 06410 { 06411 if ($this->player !== null) 06412 { 06413 return $this->player; 06414 } 06415 else 06416 { 06417 return null; 06418 } 06419 } 06420 06421 public function get_rating($key = 0) 06422 { 06423 $ratings = $this->get_ratings(); 06424 if (isset($ratings[$key])) 06425 { 06426 return $ratings[$key]; 06427 } 06428 else 06429 { 06430 return null; 06431 } 06432 } 06433 06434 public function get_ratings() 06435 { 06436 if ($this->ratings !== null) 06437 { 06438 return $this->ratings; 06439 } 06440 else 06441 { 06442 return null; 06443 } 06444 } 06445 06446 public function get_restriction($key = 0) 06447 { 06448 $restrictions = $this->get_restrictions(); 06449 if (isset($restrictions[$key])) 06450 { 06451 return $restrictions[$key]; 06452 } 06453 else 06454 { 06455 return null; 06456 } 06457 } 06458 06459 public function get_restrictions() 06460 { 06461 if ($this->restrictions !== null) 06462 { 06463 return $this->restrictions; 06464 } 06465 else 06466 { 06467 return null; 06468 } 06469 } 06470 06471 public function get_sampling_rate() 06472 { 06473 if ($this->samplingrate !== null) 06474 { 06475 return $this->samplingrate; 06476 } 06477 else 06478 { 06479 return null; 06480 } 06481 } 06482 06483 public function get_size() 06484 { 06485 $length = $this->get_length(); 06486 if ($length !== null) 06487 { 06488 return round($length/1048576, 2); 06489 } 06490 else 06491 { 06492 return null; 06493 } 06494 } 06495 06496 public function get_thumbnail($key = 0) 06497 { 06498 $thumbnails = $this->get_thumbnails(); 06499 if (isset($thumbnails[$key])) 06500 { 06501 return $thumbnails[$key]; 06502 } 06503 else 06504 { 06505 return null; 06506 } 06507 } 06508 06509 public function get_thumbnails() 06510 { 06511 if ($this->thumbnails !== null) 06512 { 06513 return $this->thumbnails; 06514 } 06515 else 06516 { 06517 return null; 06518 } 06519 } 06520 06521 public function get_title() 06522 { 06523 if ($this->title !== null) 06524 { 06525 return $this->title; 06526 } 06527 else 06528 { 06529 return null; 06530 } 06531 } 06532 06533 public function get_type() 06534 { 06535 if ($this->type !== null) 06536 { 06537 return $this->type; 06538 } 06539 else 06540 { 06541 return null; 06542 } 06543 } 06544 06545 public function get_width() 06546 { 06547 if ($this->width !== null) 06548 { 06549 return $this->width; 06550 } 06551 else 06552 { 06553 return null; 06554 } 06555 } 06556 06557 public function native_embed($options='') 06558 { 06559 return $this->embed($options, true); 06560 } 06561 06565 public function embed($options = '', $native = false) 06566 { 06567 // Set up defaults 06568 $audio = ''; 06569 $video = ''; 06570 $alt = ''; 06571 $altclass = ''; 06572 $loop = 'false'; 06573 $width = 'auto'; 06574 $height = 'auto'; 06575 $bgcolor = '#ffffff'; 06576 $mediaplayer = ''; 06577 $widescreen = false; 06578 $handler = $this->get_handler(); 06579 $type = $this->get_real_type(); 06580 06581 // Process options and reassign values as necessary 06582 if (is_array($options)) 06583 { 06584 extract($options); 06585 } 06586 else 06587 { 06588 $options = explode(',', $options); 06589 foreach($options as $option) 06590 { 06591 $opt = explode(':', $option, 2); 06592 if (isset($opt[0], $opt[1])) 06593 { 06594 $opt[0] = trim($opt[0]); 06595 $opt[1] = trim($opt[1]); 06596 switch ($opt[0]) 06597 { 06598 case 'audio': 06599 $audio = $opt[1]; 06600 break; 06601 06602 case 'video': 06603 $video = $opt[1]; 06604 break; 06605 06606 case 'alt': 06607 $alt = $opt[1]; 06608 break; 06609 06610 case 'altclass': 06611 $altclass = $opt[1]; 06612 break; 06613 06614 case 'loop': 06615 $loop = $opt[1]; 06616 break; 06617 06618 case 'width': 06619 $width = $opt[1]; 06620 break; 06621 06622 case 'height': 06623 $height = $opt[1]; 06624 break; 06625 06626 case 'bgcolor': 06627 $bgcolor = $opt[1]; 06628 break; 06629 06630 case 'mediaplayer': 06631 $mediaplayer = $opt[1]; 06632 break; 06633 06634 case 'widescreen': 06635 $widescreen = $opt[1]; 06636 break; 06637 } 06638 } 06639 } 06640 } 06641 06642 $mime = explode('/', $type, 2); 06643 $mime = $mime[0]; 06644 06645 // Process values for 'auto' 06646 if ($width === 'auto') 06647 { 06648 if ($mime === 'video') 06649 { 06650 if ($height === 'auto') 06651 { 06652 $width = 480; 06653 } 06654 elseif ($widescreen) 06655 { 06656 $width = round((intval($height)/9)*16); 06657 } 06658 else 06659 { 06660 $width = round((intval($height)/3)*4); 06661 } 06662 } 06663 else 06664 { 06665 $width = '100%'; 06666 } 06667 } 06668 06669 if ($height === 'auto') 06670 { 06671 if ($mime === 'audio') 06672 { 06673 $height = 0; 06674 } 06675 elseif ($mime === 'video') 06676 { 06677 if ($width === 'auto') 06678 { 06679 if ($widescreen) 06680 { 06681 $height = 270; 06682 } 06683 else 06684 { 06685 $height = 360; 06686 } 06687 } 06688 elseif ($widescreen) 06689 { 06690 $height = round((intval($width)/16)*9); 06691 } 06692 else 06693 { 06694 $height = round((intval($width)/4)*3); 06695 } 06696 } 06697 else 06698 { 06699 $height = 376; 06700 } 06701 } 06702 elseif ($mime === 'audio') 06703 { 06704 $height = 0; 06705 } 06706 06707 // Set proper placeholder value 06708 if ($mime === 'audio') 06709 { 06710 $placeholder = $audio; 06711 } 06712 elseif ($mime === 'video') 06713 { 06714 $placeholder = $video; 06715 } 06716 06717 $embed = ''; 06718 06719 // Make sure the JS library is included 06720 if (!$native) 06721 { 06722 static $javascript_outputted = null; 06723 if (!$javascript_outputted && $this->javascript) 06724 { 06725 $embed .= '<script type="text/javascript" src="?' . htmlspecialchars($this->javascript) . '"></script>'; 06726 $javascript_outputted = true; 06727 } 06728 } 06729 06730 // Odeo Feed MP3's 06731 if ($handler === 'odeo') 06732 { 06733 if ($native) 06734 { 06735 $embed .= '<embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://adobe.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="440" height="80" wmode="transparent" allowScriptAccess="any" flashvars="valid_sample_rate=true&external_url=' . $this->get_link() . '"></embed>'; 06736 } 06737 else 06738 { 06739 $embed .= '<script type="text/javascript">embed_odeo("' . $this->get_link() . '");</script>'; 06740 } 06741 } 06742 06743 // Flash 06744 elseif ($handler === 'flash') 06745 { 06746 if ($native) 06747 { 06748 $embed .= "<embed src=\"" . $this->get_link() . "\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"$type\" quality=\"high\" width=\"$width\" height=\"$height\" bgcolor=\"$bgcolor\" loop=\"$loop\"></embed>"; 06749 } 06750 else 06751 { 06752 $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>"; 06753 } 06754 } 06755 06756 // Flash Media Player file types. 06757 // Preferred handler for MP3 file types. 06758 elseif ($handler === 'fmedia' || ($handler === 'mp3' && $mediaplayer !== '')) 06759 { 06760 $height += 20; 06761 if ($native) 06762 { 06763 $embed .= "<embed src=\"$mediaplayer\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" quality=\"high\" width=\"$width\" height=\"$height\" wmode=\"transparent\" flashvars=\"file=" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "&autostart=false&repeat=$loop&showdigits=true&showfsbutton=false\"></embed>"; 06764 } 06765 else 06766 { 06767 $embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>"; 06768 } 06769 } 06770 06771 // QuickTime 7 file types. Need to test with QuickTime 6. 06772 // Only handle MP3's if the Flash Media Player is not present. 06773 elseif ($handler === 'quicktime' || ($handler === 'mp3' && $mediaplayer === '')) 06774 { 06775 $height += 16; 06776 if ($native) 06777 { 06778 if ($placeholder !== '') 06779 { 06780 $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" href=\"" . $this->get_link() . "\" src=\"$placeholder\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"false\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>"; 06781 } 06782 else 06783 { 06784 $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" src=\"" . $this->get_link() . "\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"true\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>"; 06785 } 06786 } 06787 else 06788 { 06789 $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>"; 06790 } 06791 } 06792 06793 // Windows Media 06794 elseif ($handler === 'wmedia') 06795 { 06796 $height += 45; 06797 if ($native) 06798 { 06799 $embed .= "<embed type=\"application/x-mplayer2\" src=\"" . $this->get_link() . "\" autosize=\"1\" width=\"$width\" height=\"$height\" showcontrols=\"1\" showstatusbar=\"0\" showdisplay=\"0\" autostart=\"0\"></embed>"; 06800 } 06801 else 06802 { 06803 $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>"; 06804 } 06805 } 06806 06807 // Everything else 06808 else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>'; 06809 06810 return $embed; 06811 } 06812 06813 public function get_real_type($find_handler = false) 06814 { 06815 // If it's Odeo, let's get it out of the way. 06816 if (substr(strtolower($this->get_link()), 0, 15) === 'http://odeo.com') 06817 { 06818 return 'odeo'; 06819 } 06820 06821 // Mime-types by handler. 06822 $types_flash = array('application/x-shockwave-flash', 'application/futuresplash'); // Flash 06823 $types_fmedia = array('video/flv', 'video/x-flv','flv-application/octet-stream'); // Flash Media Player 06824 $types_quicktime = array('audio/3gpp', 'audio/3gpp2', 'audio/aac', 'audio/x-aac', 'audio/aiff', 'audio/x-aiff', 'audio/mid', 'audio/midi', 'audio/x-midi', 'audio/mp4', 'audio/m4a', 'audio/x-m4a', 'audio/wav', 'audio/x-wav', 'video/3gpp', 'video/3gpp2', 'video/m4v', 'video/x-m4v', 'video/mp4', 'video/mpeg', 'video/x-mpeg', 'video/quicktime', 'video/sd-video'); // QuickTime 06825 $types_wmedia = array('application/asx', 'application/x-mplayer2', 'audio/x-ms-wma', 'audio/x-ms-wax', 'video/x-ms-asf-plugin', 'video/x-ms-asf', 'video/x-ms-wm', 'video/x-ms-wmv', 'video/x-ms-wvx'); // Windows Media 06826 $types_mp3 = array('audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg'); // MP3 06827 06828 if ($this->get_type() !== null) 06829 { 06830 $type = strtolower($this->type); 06831 } 06832 else 06833 { 06834 $type = null; 06835 } 06836 06837 // If we encounter an unsupported mime-type, check the file extension and guess intelligently. 06838 if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3))) 06839 { 06840 switch (strtolower($this->get_extension())) 06841 { 06842 // Audio mime-types 06843 case 'aac': 06844 case 'adts': 06845 $type = 'audio/acc'; 06846 break; 06847 06848 case 'aif': 06849 case 'aifc': 06850 case 'aiff': 06851 case 'cdda': 06852 $type = 'audio/aiff'; 06853 break; 06854 06855 case 'bwf': 06856 $type = 'audio/wav'; 06857 break; 06858 06859 case 'kar': 06860 case 'mid': 06861 case 'midi': 06862 case 'smf': 06863 $type = 'audio/midi'; 06864 break; 06865 06866 case 'm4a': 06867 $type = 'audio/x-m4a'; 06868 break; 06869 06870 case 'mp3': 06871 case 'swa': 06872 $type = 'audio/mp3'; 06873 break; 06874 06875 case 'wav': 06876 $type = 'audio/wav'; 06877 break; 06878 06879 case 'wax': 06880 $type = 'audio/x-ms-wax'; 06881 break; 06882 06883 case 'wma': 06884 $type = 'audio/x-ms-wma'; 06885 break; 06886 06887 // Video mime-types 06888 case '3gp': 06889 case '3gpp': 06890 $type = 'video/3gpp'; 06891 break; 06892 06893 case '3g2': 06894 case '3gp2': 06895 $type = 'video/3gpp2'; 06896 break; 06897 06898 case 'asf': 06899 $type = 'video/x-ms-asf'; 06900 break; 06901 06902 case 'flv': 06903 $type = 'video/x-flv'; 06904 break; 06905 06906 case 'm1a': 06907 case 'm1s': 06908 case 'm1v': 06909 case 'm15': 06910 case 'm75': 06911 case 'mp2': 06912 case 'mpa': 06913 case 'mpeg': 06914 case 'mpg': 06915 case 'mpm': 06916 case 'mpv': 06917 $type = 'video/mpeg'; 06918 break; 06919 06920 case 'm4v': 06921 $type = 'video/x-m4v'; 06922 break; 06923 06924 case 'mov': 06925 case 'qt': 06926 $type = 'video/quicktime'; 06927 break; 06928 06929 case 'mp4': 06930 case 'mpg4': 06931 $type = 'video/mp4'; 06932 break; 06933 06934 case 'sdv': 06935 $type = 'video/sd-video'; 06936 break; 06937 06938 case 'wm': 06939 $type = 'video/x-ms-wm'; 06940 break; 06941 06942 case 'wmv': 06943 $type = 'video/x-ms-wmv'; 06944 break; 06945 06946 case 'wvx': 06947 $type = 'video/x-ms-wvx'; 06948 break; 06949 06950 // Flash mime-types 06951 case 'spl': 06952 $type = 'application/futuresplash'; 06953 break; 06954 06955 case 'swf': 06956 $type = 'application/x-shockwave-flash'; 06957 break; 06958 } 06959 } 06960 06961 if ($find_handler) 06962 { 06963 if (in_array($type, $types_flash)) 06964 { 06965 return 'flash'; 06966 } 06967 elseif (in_array($type, $types_fmedia)) 06968 { 06969 return 'fmedia'; 06970 } 06971 elseif (in_array($type, $types_quicktime)) 06972 { 06973 return 'quicktime'; 06974 } 06975 elseif (in_array($type, $types_wmedia)) 06976 { 06977 return 'wmedia'; 06978 } 06979 elseif (in_array($type, $types_mp3)) 06980 { 06981 return 'mp3'; 06982 } 06983 else 06984 { 06985 return null; 06986 } 06987 } 06988 else 06989 { 06990 return $type; 06991 } 06992 } 06993 } 06994 06995 class SimplePie_Caption 06996 { 06997 var $type; 06998 var $lang; 06999 var $startTime; 07000 var $endTime; 07001 var $text; 07002 07003 // Constructor, used to input the data 07004 public function __construct($type = null, $lang = null, $startTime = null, $endTime = null, $text = null) 07005 { 07006 $this->type = $type; 07007 $this->lang = $lang; 07008 $this->startTime = $startTime; 07009 $this->endTime = $endTime; 07010 $this->text = $text; 07011 } 07012 07013 public function __toString() 07014 { 07015 // There is no $this->data here 07016 return md5(serialize($this)); 07017 } 07018 07019 public function get_endtime() 07020 { 07021 if ($this->endTime !== null) 07022 { 07023 return $this->endTime; 07024 } 07025 else 07026 { 07027 return null; 07028 } 07029 } 07030 07031 public function get_language() 07032 { 07033 if ($this->lang !== null) 07034 { 07035 return $this->lang; 07036 } 07037 else 07038 { 07039 return null; 07040 } 07041 } 07042 07043 public function get_starttime() 07044 { 07045 if ($this->startTime !== null) 07046 { 07047 return $this->startTime; 07048 } 07049 else 07050 { 07051 return null; 07052 } 07053 } 07054 07055 public function get_text() 07056 { 07057 if ($this->text !== null) 07058 { 07059 return $this->text; 07060 } 07061 else 07062 { 07063 return null; 07064 } 07065 } 07066 07067 public function get_type() 07068 { 07069 if ($this->type !== null) 07070 { 07071 return $this->type; 07072 } 07073 else 07074 { 07075 return null; 07076 } 07077 } 07078 } 07079 07080 class SimplePie_Credit 07081 { 07082 var $role; 07083 var $scheme; 07084 var $name; 07085 07086 // Constructor, used to input the data 07087 public function __construct($role = null, $scheme = null, $name = null) 07088 { 07089 $this->role = $role; 07090 $this->scheme = $scheme; 07091 $this->name = $name; 07092 } 07093 07094 public function __toString() 07095 { 07096 // There is no $this->data here 07097 return md5(serialize($this)); 07098 } 07099 07100 public function get_role() 07101 { 07102 if ($this->role !== null) 07103 { 07104 return $this->role; 07105 } 07106 else 07107 { 07108 return null; 07109 } 07110 } 07111 07112 public function get_scheme() 07113 { 07114 if ($this->scheme !== null) 07115 { 07116 return $this->scheme; 07117 } 07118 else 07119 { 07120 return null; 07121 } 07122 } 07123 07124 public function get_name() 07125 { 07126 if ($this->name !== null) 07127 { 07128 return $this->name; 07129 } 07130 else 07131 { 07132 return null; 07133 } 07134 } 07135 } 07136 07137 class SimplePie_Copyright 07138 { 07139 var $url; 07140 var $label; 07141 07142 // Constructor, used to input the data 07143 public function __construct($url = null, $label = null) 07144 { 07145 $this->url = $url; 07146 $this->label = $label; 07147 } 07148 07149 public function __toString() 07150 { 07151 // There is no $this->data here 07152 return md5(serialize($this)); 07153 } 07154 07155 public function get_url() 07156 { 07157 if ($this->url !== null) 07158 { 07159 return $this->url; 07160 } 07161 else 07162 { 07163 return null; 07164 } 07165 } 07166 07167 public function get_attribution() 07168 { 07169 if ($this->label !== null) 07170 { 07171 return $this->label; 07172 } 07173 else 07174 { 07175 return null; 07176 } 07177 } 07178 } 07179 07180 class SimplePie_Rating 07181 { 07182 var $scheme; 07183 var $value; 07184 07185 // Constructor, used to input the data 07186 public function __construct($scheme = null, $value = null) 07187 { 07188 $this->scheme = $scheme; 07189 $this->value = $value; 07190 } 07191 07192 public function __toString() 07193 { 07194 // There is no $this->data here 07195 return md5(serialize($this)); 07196 } 07197 07198 public function get_scheme() 07199 { 07200 if ($this->scheme !== null) 07201 { 07202 return $this->scheme; 07203 } 07204 else 07205 { 07206 return null; 07207 } 07208 } 07209 07210 public function get_value() 07211 { 07212 if ($this->value !== null) 07213 { 07214 return $this->value; 07215 } 07216 else 07217 { 07218 return null; 07219 } 07220 } 07221 } 07222 07223 class SimplePie_Restriction 07224 { 07225 var $relationship; 07226 var $type; 07227 var $value; 07228 07229 // Constructor, used to input the data 07230 public function __construct($relationship = null, $type = null, $value = null) 07231 { 07232 $this->relationship = $relationship; 07233 $this->type = $type; 07234 $this->value = $value; 07235 } 07236 07237 public function __toString() 07238 { 07239 // There is no $this->data here 07240 return md5(serialize($this)); 07241 } 07242 07243 public function get_relationship() 07244 { 07245 if ($this->relationship !== null) 07246 { 07247 return $this->relationship; 07248 } 07249 else 07250 { 07251 return null; 07252 } 07253 } 07254 07255 public function get_type() 07256 { 07257 if ($this->type !== null) 07258 { 07259 return $this->type; 07260 } 07261 else 07262 { 07263 return null; 07264 } 07265 } 07266 07267 public function get_value() 07268 { 07269 if ($this->value !== null) 07270 { 07271 return $this->value; 07272 } 07273 else 07274 { 07275 return null; 07276 } 07277 } 07278 } 07279 07283 class SimplePie_File 07284 { 07285 var $url; 07286 var $useragent; 07287 var $success = true; 07288 var $headers = array(); 07289 var $body; 07290 var $status_code; 07291 var $redirects = 0; 07292 var $error; 07293 var $method = SIMPLEPIE_FILE_SOURCE_NONE; 07294 07295 public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) 07296 { 07297 if (class_exists('idna_convert')) 07298 { 07299 $idn = new idna_convert(); 07300 $parsed = SimplePie_Misc::parse_url($url); 07301 $url = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']); 07302 } 07303 $this->url = $url; 07304 $this->useragent = $useragent; 07305 if (preg_match('/^http(s)?:\/\//i', $url)) 07306 { 07307 if ($useragent === null) 07308 { 07309 $useragent = ini_get('user_agent'); 07310 $this->useragent = $useragent; 07311 } 07312 if (!is_array($headers)) 07313 { 07314 $headers = array(); 07315 } 07316 if (!$force_fsockopen && function_exists('curl_exec')) 07317 { 07318 $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL; 07319 $fp = curl_init(); 07320 $headers2 = array(); 07321 foreach ($headers as $key => $value) 07322 { 07323 $headers2[] = "$key: $value"; 07324 } 07325 if (version_compare(SimplePie_Misc::get_curl_version(), '7.10.5', '>=')) 07326 { 07327 curl_setopt($fp, CURLOPT_ENCODING, ''); 07328 } 07329 curl_setopt($fp, CURLOPT_URL, $url); 07330 curl_setopt($fp, CURLOPT_HEADER, 1); 07331 curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1); 07332 curl_setopt($fp, CURLOPT_TIMEOUT, $timeout); 07333 curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout); 07334 curl_setopt($fp, CURLOPT_REFERER, $url); 07335 curl_setopt($fp, CURLOPT_USERAGENT, $useragent); 07336 curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2); 07337 if (!ini_get('open_basedir') && !ini_get('safe_mode') && version_compare(SimplePie_Misc::get_curl_version(), '7.15.2', '>=')) 07338 { 07339 curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1); 07340 curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects); 07341 } 07342 07343 $this->headers = curl_exec($fp); 07344 if (curl_errno($fp) === 23 || curl_errno($fp) === 61) 07345 { 07346 curl_setopt($fp, CURLOPT_ENCODING, 'none'); 07347 $this->headers = curl_exec($fp); 07348 } 07349 if (curl_errno($fp)) 07350 { 07351 $this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp); 07352 $this->success = false; 07353 } 07354 else 07355 { 07356 $info = curl_getinfo($fp); 07357 curl_close($fp); 07358 $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 1); 07359 $this->headers = array_pop($this->headers); 07360 $parser = new SimplePie_HTTP_Parser($this->headers); 07361 if ($parser->parse()) 07362 { 07363 $this->headers = $parser->headers; 07364 $this->body = $parser->body; 07365 $this->status_code = $parser->status_code; 07366 if ((in_array($this->status_code, array(300, 301, 302, 303, 307)) || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects) 07367 { 07368 $this->redirects++; 07369 $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url); 07370 return $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen); 07371 } 07372 } 07373 } 07374 } 07375 else 07376 { 07377 $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_FSOCKOPEN; 07378 $url_parts = parse_url($url); 07379 if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https') 07380 { 07381 $url_parts['host'] = "ssl://$url_parts[host]"; 07382 $url_parts['port'] = 443; 07383 } 07384 if (!isset($url_parts['port'])) 07385 { 07386 $url_parts['port'] = 80; 07387 } 07388 $fp = @fsockopen($url_parts['host'], $url_parts['port'], $errno, $errstr, $timeout); 07389 if (!$fp) 07390 { 07391 $this->error = 'fsockopen error: ' . $errstr; 07392 $this->success = false; 07393 } 07394 else 07395 { 07396 stream_set_timeout($fp, $timeout); 07397 if (isset($url_parts['path'])) 07398 { 07399 if (isset($url_parts['query'])) 07400 { 07401 $get = "$url_parts[path]?$url_parts[query]"; 07402 } 07403 else 07404 { 07405 $get = $url_parts['path']; 07406 } 07407 } 07408 else 07409 { 07410 $get = '/'; 07411 } 07412 $out = "GET $get HTTP/1.0\r\n"; 07413 $out .= "Host: $url_parts[host]\r\n"; 07414 $out .= "User-Agent: $useragent\r\n"; 07415 if (extension_loaded('zlib')) 07416 { 07417 $out .= "Accept-Encoding: x-gzip,gzip,deflate\r\n"; 07418 } 07419 07420 if (isset($url_parts['user']) && isset($url_parts['pass'])) 07421 { 07422 $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n"; 07423 } 07424 foreach ($headers as $key => $value) 07425 { 07426 $out .= "$key: $value\r\n"; 07427 } 07428 $out .= "Connection: Close\r\n\r\n"; 07429 fwrite($fp, $out); 07430 07431 $info = stream_get_meta_data($fp); 07432 07433 $this->headers = ''; 07434 while (!$info['eof'] && !$info['timed_out']) 07435 { 07436 $this->headers .= fread($fp, 1160); 07437 $info = stream_get_meta_data($fp); 07438 } 07439 if (!$info['timed_out']) 07440 { 07441 $parser = new SimplePie_HTTP_Parser($this->headers); 07442 if ($parser->parse()) 07443 { 07444 $this->headers = $parser->headers; 07445 $this->body = $parser->body; 07446 $this->status_code = $parser->status_code; 07447 if ((in_array($this->status_code, array(300, 301, 302, 303, 307)) || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects) 07448 { 07449 $this->redirects++; 07450 $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url); 07451 return $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen); 07452 } 07453 if (isset($this->headers['content-encoding'])) 07454 { 07455 // Hey, we act dumb elsewhere, so let's do that here too 07456 switch (strtolower(trim($this->headers['content-encoding'], "\x09\x0A\x0D\x20"))) 07457 { 07458 case 'gzip': 07459 case 'x-gzip': 07460 $decoder = new SimplePie_gzdecode($this->body); 07461 if (!$decoder->parse()) 07462 { 07463 $this->error = 'Unable to decode HTTP "gzip" stream'; 07464 $this->success = false; 07465 } 07466 else 07467 { 07468 $this->body = $decoder->data; 07469 } 07470 break; 07471 07472 case 'deflate': 07473 if (($body = gzuncompress($this->body)) === false) 07474 { 07475 if (($body = gzinflate($this->body)) === false) 07476 { 07477 $this->error = 'Unable to decode HTTP "deflate" stream'; 07478 $this->success = false; 07479 } 07480 } 07481 $this->body = $body; 07482 break; 07483 07484 default: 07485 $this->error = 'Unknown content coding'; 07486 $this->success = false; 07487 } 07488 } 07489 } 07490 } 07491 else 07492 { 07493 $this->error = 'fsocket timed out'; 07494 $this->success = false; 07495 } 07496 fclose($fp); 07497 } 07498 } 07499 } 07500 else 07501 { 07502 $this->method = SIMPLEPIE_FILE_SOURCE_LOCAL | SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS; 07503 if (!$this->body = file_get_contents($url)) 07504 { 07505 $this->error = 'file_get_contents could not read the file'; 07506 $this->success = false; 07507 } 07508 } 07509 } 07510 } 07511 07517 class SimplePie_HTTP_Parser 07518 { 07525 var $http_version = 0.0; 07526 07533 var $status_code = 0; 07534 07541 var $reason = ''; 07542 07549 var $headers = array(); 07550 07557 var $body = ''; 07558 07565 var $state = 'http_version'; 07566 07573 var $data = ''; 07574 07581 var $data_length = 0; 07582 07589 var $position = 0; 07590 07597 var $name = ''; 07598 07605 var $value = ''; 07606 07613 public function __construct($data) 07614 { 07615 $this->data = $data; 07616 $this->data_length = strlen($this->data); 07617 } 07618 07625 public function parse() 07626 { 07627 while ($this->state && $this->state !== 'emit' && $this->has_data()) 07628 { 07629 $state = $this->state; 07630 $this->$state(); 07631 } 07632 $this->data = ''; 07633 if ($this->state === 'emit' || $this->state === 'body') 07634 { 07635 return true; 07636 } 07637 else 07638 { 07639 $this->http_version = ''; 07640 $this->status_code = ''; 07641 $this->reason = ''; 07642 $this->headers = array(); 07643 $this->body = ''; 07644 return false; 07645 } 07646 } 07647 07654 public function has_data() 07655 { 07656 return (bool) ($this->position < $this->data_length); 07657 } 07658 07665 public function is_linear_whitespace() 07666 { 07667 return (bool) ($this->data[$this->position] === "\x09" 07668 || $this->data[$this->position] === "\x20" 07669 || ($this->data[$this->position] === "\x0A" 07670 && isset($this->data[$this->position + 1]) 07671 && ($this->data[$this->position + 1] === "\x09" || $this->data[$this->position + 1] === "\x20"))); 07672 } 07673 07679 public function http_version() 07680 { 07681 if (strpos($this->data, "\x0A") !== false && strtoupper(substr($this->data, 0, 5)) === 'HTTP/') 07682 { 07683 $len = strspn($this->data, '0123456789.', 5); 07684 $this->http_version = substr($this->data, 5, $len); 07685 $this->position += 5 + $len; 07686 if (substr_count($this->http_version, '.') <= 1) 07687 { 07688 $this->http_version = (float) $this->http_version; 07689 $this->position += strspn($this->data, "\x09\x20", $this->position); 07690 $this->state = 'status'; 07691 } 07692 else 07693 { 07694 $this->state = false; 07695 } 07696 } 07697 else 07698 { 07699 $this->state = false; 07700 } 07701 } 07702 07708 public function status() 07709 { 07710 if ($len = strspn($this->data, '0123456789', $this->position)) 07711 { 07712 $this->status_code = (int) substr($this->data, $this->position, $len); 07713 $this->position += $len; 07714 $this->state = 'reason'; 07715 } 07716 else 07717 { 07718 $this->state = false; 07719 } 07720 } 07721 07727 public function reason() 07728 { 07729 $len = strcspn($this->data, "\x0A", $this->position); 07730 $this->reason = trim(substr($this->data, $this->position, $len), "\x09\x0D\x20"); 07731 $this->position += $len + 1; 07732 $this->state = 'new_line'; 07733 } 07734 07740 public function new_line() 07741 { 07742 $this->value = trim($this->value, "\x0D\x20"); 07743 if ($this->name !== '' && $this->value !== '') 07744 { 07745 $this->name = strtolower($this->name); 07746 if (isset($this->headers[$this->name])) 07747 { 07748 $this->headers[$this->name] .= ', ' . $this->value; 07749 } 07750 else 07751 { 07752 $this->headers[$this->name] = $this->value; 07753 } 07754 } 07755 $this->name = ''; 07756 $this->value = ''; 07757 if (substr($this->data[$this->position], 0, 2) === "\x0D\x0A") 07758 { 07759 $this->position += 2; 07760 $this->state = 'body'; 07761 } 07762 elseif ($this->data[$this->position] === "\x0A") 07763 { 07764 $this->position++; 07765 $this->state = 'body'; 07766 } 07767 else 07768 { 07769 $this->state = 'name'; 07770 } 07771 } 07772 07778 public function name() 07779 { 07780 $len = strcspn($this->data, "\x0A:", $this->position); 07781 if (isset($this->data[$this->position + $len])) 07782 { 07783 if ($this->data[$this->position + $len] === "\x0A") 07784 { 07785 $this->position += $len; 07786 $this->state = 'new_line'; 07787 } 07788 else 07789 { 07790 $this->name = substr($this->data, $this->position, $len); 07791 $this->position += $len + 1; 07792 $this->state = 'value'; 07793 } 07794 } 07795 else 07796 { 07797 $this->state = false; 07798 } 07799 } 07800 07806 public function linear_whitespace() 07807 { 07808 do 07809 { 07810 if (substr($this->data, $this->position, 2) === "\x0D\x0A") 07811 { 07812 $this->position += 2; 07813 } 07814 elseif ($this->data[$this->position] === "\x0A") 07815 { 07816 $this->position++; 07817 } 07818 $this->position += strspn($this->data, "\x09\x20", $this->position); 07819 } while ($this->has_data() && $this->is_linear_whitespace()); 07820 $this->value .= "\x20"; 07821 } 07822 07828 public function value() 07829 { 07830 if ($this->is_linear_whitespace()) 07831 { 07832 $this->linear_whitespace(); 07833 } 07834 else 07835 { 07836 switch ($this->data[$this->position]) 07837 { 07838 case '"': 07839 $this->position++; 07840 $this->state = 'quote'; 07841 break; 07842 07843 case "\x0A": 07844 $this->position++; 07845 $this->state = 'new_line'; 07846 break; 07847 07848 default: 07849 $this->state = 'value_char'; 07850 break; 07851 } 07852 } 07853 } 07854 07860 public function value_char() 07861 { 07862 $len = strcspn($this->data, "\x09\x20\x0A\"", $this->position); 07863 $this->value .= substr($this->data, $this->position, $len); 07864 $this->position += $len; 07865 $this->state = 'value'; 07866 } 07867 07873 public function quote() 07874 { 07875 if ($this->is_linear_whitespace()) 07876 { 07877 $this->linear_whitespace(); 07878 } 07879 else 07880 { 07881 switch ($this->data[$this->position]) 07882 { 07883 case '"': 07884 $this->position++; 07885 $this->state = 'value'; 07886 break; 07887 07888 case "\x0A": 07889 $this->position++; 07890 $this->state = 'new_line'; 07891 break; 07892 07893 case '\\': 07894 $this->position++; 07895 $this->state = 'quote_escaped'; 07896 break; 07897 07898 default: 07899 $this->state = 'quote_char'; 07900 break; 07901 } 07902 } 07903 } 07904 07910 public function quote_char() 07911 { 07912 $len = strcspn($this->data, "\x09\x20\x0A\"\\", $this->position); 07913 $this->value .= substr($this->data, $this->position, $len); 07914 $this->position += $len; 07915 $this->state = 'value'; 07916 } 07917 07923 public function quote_escaped() 07924 { 07925 $this->value .= $this->data[$this->position]; 07926 $this->position++; 07927 $this->state = 'quote'; 07928 } 07929 07935 public function body() 07936 { 07937 $this->body = substr($this->data, $this->position); 07938 $this->state = 'emit'; 07939 } 07940 } 07941 07947 class SimplePie_gzdecode 07948 { 07955 var $compressed_data; 07956 07962 var $compressed_size; 07963 07969 var $min_compressed_size = 18; 07970 07976 var $position = 0; 07977 07983 var $flags; 07984 07991 var $data; 07992 07998 var $MTIME; 07999 08005 var $XFL; 08006 08012 var $OS; 08013 08021 var $SI1; 08022 08030 var $SI2; 08031 08039 var $extra_field; 08040 08046 var $filename; 08047 08053 var $comment; 08054 08060 public function __set($name, $value) 08061 { 08062 trigger_error("Cannot write property $name", E_USER_ERROR); 08063 } 08064 08070 public function __construct($data) 08071 { 08072 $this->compressed_data = $data; 08073 $this->compressed_size = strlen($data); 08074 } 08075 08081 public function parse() 08082 { 08083 if ($this->compressed_size >= $this->min_compressed_size) 08084 { 08085 // Check ID1, ID2, and CM 08086 if (substr($this->compressed_data, 0, 3) !== "\x1F\x8B\x08") 08087 { 08088 return false; 08089 } 08090 08091 // Get the FLG (FLaGs) 08092 $this->flags = ord($this->compressed_data[3]); 08093 08094 // FLG bits above (1 << 4) are reserved 08095 if ($this->flags > 0x1F) 08096 { 08097 return false; 08098 } 08099 08100 // Advance the pointer after the above 08101 $this->position += 4; 08102 08103 // MTIME 08104 $mtime = substr($this->compressed_data, $this->position, 4); 08105 // Reverse the string if we're on a big-endian arch because l is the only signed long and is machine endianness 08106 if (current(unpack('S', "\x00\x01")) === 1) 08107 { 08108 $mtime = strrev($mtime); 08109 } 08110 $this->MTIME = current(unpack('l', $mtime)); 08111 $this->position += 4; 08112 08113 // Get the XFL (eXtra FLags) 08114 $this->XFL = ord($this->compressed_data[$this->position++]); 08115 08116 // Get the OS (Operating System) 08117 $this->OS = ord($this->compressed_data[$this->position++]); 08118 08119 // Parse the FEXTRA 08120 if ($this->flags & 4) 08121 { 08122 // Read subfield IDs 08123 $this->SI1 = $this->compressed_data[$this->position++]; 08124 $this->SI2 = $this->compressed_data[$this->position++]; 08125 08126 // SI2 set to zero is reserved for future use 08127 if ($this->SI2 === "\x00") 08128 { 08129 return false; 08130 } 08131 08132 // Get the length of the extra field 08133 $len = current(unpack('v', substr($this->compressed_data, $this->position, 2))); 08134 $position += 2; 08135 08136 // Check the length of the string is still valid 08137 $this->min_compressed_size += $len + 4; 08138 if ($this->compressed_size >= $this->min_compressed_size) 08139 { 08140 // Set the extra field to the given data 08141 $this->extra_field = substr($this->compressed_data, $this->position, $len); 08142 $this->position += $len; 08143 } 08144 else 08145 { 08146 return false; 08147 } 08148 } 08149 08150 // Parse the FNAME 08151 if ($this->flags & 8) 08152 { 08153 // Get the length of the filename 08154 $len = strcspn($this->compressed_data, "\x00", $this->position); 08155 08156 // Check the length of the string is still valid 08157 $this->min_compressed_size += $len + 1; 08158 if ($this->compressed_size >= $this->min_compressed_size) 08159 { 08160 // Set the original filename to the given string 08161 $this->filename = substr($this->compressed_data, $this->position, $len); 08162 $this->position += $len + 1; 08163 } 08164 else 08165 { 08166 return false; 08167 } 08168 } 08169 08170 // Parse the FCOMMENT 08171 if ($this->flags & 16) 08172 { 08173 // Get the length of the comment 08174 $len = strcspn($this->compressed_data, "\x00", $this->position); 08175 08176 // Check the length of the string is still valid 08177 $this->min_compressed_size += $len + 1; 08178 if ($this->compressed_size >= $this->min_compressed_size) 08179 { 08180 // Set the original comment to the given string 08181 $this->comment = substr($this->compressed_data, $this->position, $len); 08182 $this->position += $len + 1; 08183 } 08184 else 08185 { 08186 return false; 08187 } 08188 } 08189 08190 // Parse the FHCRC 08191 if ($this->flags & 2) 08192 { 08193 // Check the length of the string is still valid 08194 $this->min_compressed_size += $len + 2; 08195 if ($this->compressed_size >= $this->min_compressed_size) 08196 { 08197 // Read the CRC 08198 $crc = current(unpack('v', substr($this->compressed_data, $this->position, 2))); 08199 08200 // Check the CRC matches 08201 if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc) 08202 { 08203 $this->position += 2; 08204 } 08205 else 08206 { 08207 return false; 08208 } 08209 } 08210 else 08211 { 08212 return false; 08213 } 08214 } 08215 08216 // Decompress the actual data 08217 if (($this->data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false) 08218 { 08219 return false; 08220 } 08221 else 08222 { 08223 $this->position = $this->compressed_size - 8; 08224 } 08225 08226 // Check CRC of data 08227 $crc = current(unpack('V', substr($this->compressed_data, $this->position, 4))); 08228 $this->position += 4; 08229 /*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc)) 08230 { 08231 return false; 08232 }*/ 08233 08234 // Check ISIZE of data 08235 $isize = current(unpack('V', substr($this->compressed_data, $this->position, 4))); 08236 $this->position += 4; 08237 if (sprintf('%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf('%u', $isize)) 08238 { 08239 return false; 08240 } 08241 08242 // Wow, against all odds, we've actually got a valid gzip string 08243 return true; 08244 } 08245 else 08246 { 08247 return false; 08248 } 08249 } 08250 } 08251 08252 class SimplePie_Cache 08253 { 08259 private function __construct() 08260 { 08261 trigger_error('Please call SimplePie_Cache::create() instead of the constructor', E_USER_ERROR); 08262 } 08263 08270 public static function create($location, $filename, $extension) 08271 { 08272 $location_iri = new SimplePie_IRI($location); 08273 switch ($location_iri->get_scheme()) 08274 { 08275 case 'mysql': 08276 if (extension_loaded('mysql')) 08277 { 08278 return new SimplePie_Cache_MySQL($location_iri, $filename, $extension); 08279 } 08280 break; 08281 08282 default: 08283 return new SimplePie_Cache_File($location, $filename, $extension); 08284 } 08285 } 08286 } 08287 08288 class SimplePie_Cache_File 08289 { 08290 var $location; 08291 var $filename; 08292 var $extension; 08293 var $name; 08294 08295 public function __construct($location, $filename, $extension) 08296 { 08297 $this->location = $location; 08298 $this->filename = $filename; 08299 $this->extension = $extension; 08300 $this->name = "$this->location/$this->filename.$this->extension"; 08301 } 08302 08303 public function save($data) 08304 { 08305 if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location)) 08306 { 08307 if (is_a($data, 'SimplePie')) 08308 { 08309 $data = $data->data; 08310 } 08311 08312 $data = serialize($data); 08313 return (bool) file_put_contents($this->name, $data); 08314 } 08315 return false; 08316 } 08317 08318 public function load() 08319 { 08320 if (file_exists($this->name) && is_readable($this->name)) 08321 { 08322 return unserialize(file_get_contents($this->name)); 08323 } 08324 return false; 08325 } 08326 08327 public function mtime() 08328 { 08329 if (file_exists($this->name)) 08330 { 08331 return filemtime($this->name); 08332 } 08333 return false; 08334 } 08335 08336 public function touch() 08337 { 08338 if (file_exists($this->name)) 08339 { 08340 return touch($this->name); 08341 } 08342 return false; 08343 } 08344 08345 public function unlink() 08346 { 08347 if (file_exists($this->name)) 08348 { 08349 return unlink($this->name); 08350 } 08351 return false; 08352 } 08353 } 08354 08355 class SimplePie_Cache_DB 08356 { 08357 public function prepare_simplepie_object_for_cache($data) 08358 { 08359 $items = $data->get_items(); 08360 $items_by_id = array(); 08361 08362 if (!empty($items)) 08363 { 08364 foreach ($items as $item) 08365 { 08366 $items_by_id[$item->get_id()] = $item; 08367 } 08368 08369 if (count($items_by_id) !== count($items)) 08370 { 08371 $items_by_id = array(); 08372 foreach ($items as $item) 08373 { 08374 $items_by_id[$item->get_id(true)] = $item; 08375 } 08376 } 08377 08378 if (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0])) 08379 { 08380 $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]; 08381 } 08382 elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0])) 08383 { 08384 $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]; 08385 } 08386 elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0])) 08387 { 08388 $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]; 08389 } 08390 elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0])) 08391 { 08392 $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0]; 08393 } 08394 else 08395 { 08396 $channel = null; 08397 } 08398 08399 if ($channel !== null) 08400 { 08401 if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'])) 08402 { 08403 unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']); 08404 } 08405 if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry'])) 08406 { 08407 unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']); 08408 } 08409 if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])) 08410 { 08411 unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']); 08412 } 08413 if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])) 08414 { 08415 unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']); 08416 } 08417 if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item'])) 08418 { 08419 unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']); 08420 } 08421 } 08422 if (isset($data->data['items'])) 08423 { 08424 unset($data->data['items']); 08425 } 08426 if (isset($data->data['ordered_items'])) 08427 { 08428 unset($data->data['ordered_items']); 08429 } 08430 } 08431 return array(serialize($data->data), $items_by_id); 08432 } 08433 } 08434 08435 class SimplePie_Cache_MySQL extends SimplePie_Cache_DB 08436 { 08437 var $mysql; 08438 var $options; 08439 var $id; 08440 08441 public function __construct($mysql_location, $name, $extension) 08442 { 08443 $host = $mysql_location->get_host(); 08444 if (stripos($host, 'unix(') === 0 && substr($host, -1) === ')') 08445 { 08446 $server = ':' . substr($host, 5, -1); 08447 } 08448 else 08449 { 08450 $server = $host; 08451 if ($mysql_location->get_port() !== null) 08452 { 08453 $server .= ':' . $mysql_location->get_port(); 08454 } 08455 } 08456 08457 if (strpos($mysql_location->get_userinfo(), ':') !== false) 08458 { 08459 list($username, $password) = explode(':', $mysql_location->get_userinfo(), 2); 08460 } 08461 else 08462 { 08463 $username = $mysql_location->get_userinfo(); 08464 $password = null; 08465 } 08466 08467 if ($this->mysql = mysql_connect($server, $username, $password)) 08468 { 08469 $this->id = $name . $extension; 08470 $this->options = SimplePie_Misc::parse_str($mysql_location->get_query()); 08471 if (!isset($this->options['prefix'][0])) 08472 { 08473 $this->options['prefix'][0] = ''; 08474 } 08475 08476 if (mysql_select_db(ltrim($mysql_location->get_path(), '/')) 08477 && mysql_query('SET NAMES utf8') 08478 && ($query = mysql_unbuffered_query('SHOW TABLES'))) 08479 { 08480 $db = array(); 08481 while ($row = mysql_fetch_row($query)) 08482 { 08483 $db[] = $row[0]; 08484 } 08485 08486 if (!in_array($this->options['prefix'][0] . 'cache_data', $db)) 08487 { 08488 if (!mysql_query('CREATE TABLE `' . $this->options['prefix'][0] . 'cache_data` (`id` TEXT CHARACTER SET utf8 NOT NULL, `items` SMALLINT NOT NULL DEFAULT 0, `data` BLOB NOT NULL, `mtime` INT UNSIGNED NOT NULL, UNIQUE (`id`(125)))')) 08489 { 08490 $this->mysql = null; 08491 } 08492 } 08493 08494 if (!in_array($this->options['prefix'][0] . 'items', $db)) 08495 { 08496 if (!mysql_query('CREATE TABLE `' . $this->options['prefix'][0] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` TEXT CHARACTER SET utf8 NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))')) 08497 { 08498 $this->mysql = null; 08499 } 08500 } 08501 } 08502 else 08503 { 08504 $this->mysql = null; 08505 } 08506 } 08507 } 08508 08509 public function save($data) 08510 { 08511 if ($this->mysql) 08512 { 08513 $feed_id = "'" . mysql_real_escape_string($this->id) . "'"; 08514 08515 if (is_a($data, 'SimplePie')) 08516 { 08517 $data = clone $data; 08518 08519 $prepared = $this->prepare_simplepie_object_for_cache($data); 08520 08521 if ($query = mysql_query('SELECT `id` FROM `' . $this->options['prefix'][0] . 'cache_data` WHERE `id` = ' . $feed_id, $this->mysql)) 08522 { 08523 if (mysql_num_rows($query)) 08524 { 08525 $items = count($prepared[1]); 08526 if ($items) 08527 { 08528 $sql = 'UPDATE `' . $this->options['prefix'][0] . 'cache_data` SET `items` = ' . $items . ', `data` = \'' . mysql_real_escape_string($prepared[0]) . '\', `mtime` = ' . time() . ' WHERE `id` = ' . $feed_id; 08529 } 08530 else 08531 { 08532 $sql = 'UPDATE `' . $this->options['prefix'][0] . 'cache_data` SET `data` = \'' . mysql_real_escape_string($prepared[0]) . '\', `mtime` = ' . time() . ' WHERE `id` = ' . $feed_id; 08533 } 08534 08535 if (!mysql_query($sql, $this->mysql)) 08536 { 08537 return false; 08538 } 08539 } 08540 elseif (!mysql_query('INSERT INTO `' . $this->options['prefix'][0] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(' . $feed_id . ', ' . count($prepared[1]) . ', \'' . mysql_real_escape_string($prepared[0]) . '\', ' . time() . ')', $this->mysql)) 08541 { 08542 return false; 08543 } 08544 08545 $ids = array_keys($prepared[1]); 08546 if (!empty($ids)) 08547 { 08548 foreach ($ids as $id) 08549 { 08550 $database_ids[] = mysql_real_escape_string($id); 08551 } 08552 08553 if ($query = mysql_unbuffered_query('SELECT `id` FROM `' . $this->options['prefix'][0] . 'items` WHERE `id` = \'' . implode('\' OR `id` = \'', $database_ids) . '\' AND `feed_id` = ' . $feed_id, $this->mysql)) 08554 { 08555 $existing_ids = array(); 08556 while ($row = mysql_fetch_row($query)) 08557 { 08558 $existing_ids[] = $row[0]; 08559 } 08560 08561 $new_ids = array_diff($ids, $existing_ids); 08562 08563 foreach ($new_ids as $new_id) 08564 { 08565 if (!($date = $prepared[1][$new_id]->get_date('U'))) 08566 { 08567 $date = time(); 08568 } 08569 08570 if (!mysql_query('INSERT INTO `' . $this->options['prefix'][0] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(' . $feed_id . ', \'' . mysql_real_escape_string($new_id) . '\', \'' . mysql_real_escape_string(serialize($prepared[1][$new_id]->data)) . '\', ' . $date . ')', $this->mysql)) 08571 { 08572 return false; 08573 } 08574 } 08575 return true; 08576 } 08577 } 08578 else 08579 { 08580 return true; 08581 } 08582 } 08583 } 08584 elseif ($query = mysql_query('SELECT `id` FROM `' . $this->options['prefix'][0] . 'cache_data` WHERE `id` = ' . $feed_id, $this->mysql)) 08585 { 08586 if (mysql_num_rows($query)) 08587 { 08588 if (mysql_query('UPDATE `' . $this->options['prefix'][0] . 'cache_data` SET `items` = 0, `data` = \'' . mysql_real_escape_string(serialize($data)) . '\', `mtime` = ' . time() . ' WHERE `id` = ' . $feed_id, $this->mysql)) 08589 { 08590 return true; 08591 } 08592 } 08593 elseif (mysql_query('INSERT INTO `' . $this->options['prefix'][0] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(\'' . mysql_real_escape_string($this->id) . '\', 0, \'' . mysql_real_escape_string(serialize($data)) . '\', ' . time() . ')', $this->mysql)) 08594 { 08595 return true; 08596 } 08597 } 08598 } 08599 return false; 08600 } 08601 08602 public function load() 08603 { 08604 if ($this->mysql && ($query = mysql_query('SELECT `items`, `data` FROM `' . $this->options['prefix'][0] . 'cache_data` WHERE `id` = \'' . mysql_real_escape_string($this->id) . "'", $this->mysql)) && ($row = mysql_fetch_row($query))) 08605 { 08606 $data = unserialize($row[1]); 08607 08608 if (isset($this->options['items'][0])) 08609 { 08610 $items = (int) $this->options['items'][0]; 08611 } 08612 else 08613 { 08614 $items = (int) $row[0]; 08615 } 08616 08617 if ($items !== 0) 08618 { 08619 if (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0])) 08620 { 08621 $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]; 08622 } 08623 elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0])) 08624 { 08625 $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]; 08626 } 08627 elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0])) 08628 { 08629 $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]; 08630 } 08631 elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0])) 08632 { 08633 $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]; 08634 } 08635 else 08636 { 08637 $feed = null; 08638 } 08639 08640 if ($feed !== null) 08641 { 08642 $sql = 'SELECT `data` FROM `' . $this->options['prefix'][0] . 'items` WHERE `feed_id` = \'' . mysql_real_escape_string($this->id) . '\' ORDER BY `posted` DESC'; 08643 if ($items > 0) 08644 { 08645 $sql .= ' LIMIT ' . $items; 08646 } 08647 08648 if ($query = mysql_unbuffered_query($sql, $this->mysql)) 08649 { 08650 while ($row = mysql_fetch_row($query)) 08651 { 08652 $feed['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'][] = unserialize($row[0]); 08653 } 08654 } 08655 else 08656 { 08657 return false; 08658 } 08659 } 08660 } 08661 return $data; 08662 } 08663 return false; 08664 } 08665 08666 public function mtime() 08667 { 08668 if ($this->mysql && ($query = mysql_query('SELECT `mtime` FROM `' . $this->options['prefix'][0] . 'cache_data` WHERE `id` = \'' . mysql_real_escape_string($this->id) . "'", $this->mysql)) && ($row = mysql_fetch_row($query))) 08669 { 08670 return $row[0]; 08671 } 08672 else 08673 { 08674 return false; 08675 } 08676 } 08677 08678 public function touch() 08679 { 08680 if ($this->mysql && ($query = mysql_query('UPDATE `' . $this->options['prefix'][0] . 'cache_data` SET `mtime` = ' . time() . ' WHERE `id` = \'' . mysql_real_escape_string($this->id) . "'", $this->mysql)) && mysql_affected_rows($this->mysql)) 08681 { 08682 return true; 08683 } 08684 else 08685 { 08686 return false; 08687 } 08688 } 08689 08690 public function unlink() 08691 { 08692 if ($this->mysql && ($query = mysql_query('DELETE FROM `' . $this->options['prefix'][0] . 'cache_data` WHERE `id` = \'' . mysql_real_escape_string($this->id) . "'", $this->mysql)) && ($query2 = mysql_query('DELETE FROM `' . $this->options['prefix'][0] . 'items` WHERE `feed_id` = \'' . mysql_real_escape_string($this->id) . "'", $this->mysql))) 08693 { 08694 return true; 08695 } 08696 else 08697 { 08698 return false; 08699 } 08700 } 08701 } 08702 08703 class SimplePie_Misc 08704 { 08705 public static function time_hms($seconds) 08706 { 08707 $time = ''; 08708 08709 $hours = floor($seconds / 3600); 08710 $remainder = $seconds % 3600; 08711 if ($hours > 0) 08712 { 08713 $time .= $hours.':'; 08714 } 08715 08716 $minutes = floor($remainder / 60); 08717 $seconds = $remainder % 60; 08718 if ($minutes < 10 && $hours > 0) 08719 { 08720 $minutes = '0' . $minutes; 08721 } 08722 if ($seconds < 10) 08723 { 08724 $seconds = '0' . $seconds; 08725 } 08726 08727 $time .= $minutes.':'; 08728 $time .= $seconds; 08729 08730 return $time; 08731 } 08732 08733 public static function absolutize_url($relative, $base) 08734 { 08735 $iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative); 08736 return $iri->get_iri(); 08737 } 08738 08739 public static function remove_dot_segments($input) 08740 { 08741 $output = ''; 08742 while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..') 08743 { 08744 // A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise, 08745 if (strpos($input, '../') === 0) 08746 { 08747 $input = substr($input, 3); 08748 } 08749 elseif (strpos($input, './') === 0) 08750 { 08751 $input = substr($input, 2); 08752 } 08753 // B: if the input buffer begins with a prefix of "/./" or "/.", where "." is a complete path segment, then replace that prefix with "/" in the input buffer; otherwise, 08754 elseif (strpos($input, '/./') === 0) 08755 { 08756 $input = substr_replace($input, '/', 0, 3); 08757 } 08758 elseif ($input === '/.') 08759 { 08760 $input = '/'; 08761 } 08762 // C: if the input buffer begins with a prefix of "/../" or "/..", where ".." is a complete path segment, then replace that prefix with "/" in the input buffer and remove the last segment and its preceding "/" (if any) from the output buffer; otherwise, 08763 elseif (strpos($input, '/../') === 0) 08764 { 08765 $input = substr_replace($input, '/', 0, 4); 08766 $output = substr_replace($output, '', strrpos($output, '/')); 08767 } 08768 elseif ($input === '/..') 08769 { 08770 $input = '/'; 08771 $output = substr_replace($output, '', strrpos($output, '/')); 08772 } 08773 // D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise, 08774 elseif ($input === '.' || $input === '..') 08775 { 08776 $input = ''; 08777 } 08778 // E: move the first path segment in the input buffer to the end of the output buffer, including the initial "/" character (if any) and any subsequent characters up to, but not including, the next "/" character or the end of the input buffer 08779 elseif (($pos = strpos($input, '/', 1)) !== false) 08780 { 08781 $output .= substr($input, 0, $pos); 08782 $input = substr_replace($input, '', 0, $pos); 08783 } 08784 else 08785 { 08786 $output .= $input; 08787 $input = ''; 08788 } 08789 } 08790 return $output . $input; 08791 } 08792 08793 public static function get_element($realname, $string) 08794 { 08795 $return = array(); 08796 $name = preg_quote($realname, '/'); 08797 if (preg_match_all("/<($name)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$name>|(\/)?>)/siU", $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) 08798 { 08799 for ($i = 0, $total_matches = count($matches); $i < $total_matches; $i++) 08800 { 08801 $return[$i]['tag'] = $realname; 08802 $return[$i]['full'] = $matches[$i][0][0]; 08803 $return[$i]['offset'] = $matches[$i][0][1]; 08804 if (strlen($matches[$i][3][0]) <= 2) 08805 { 08806 $return[$i]['self_closing'] = true; 08807 } 08808 else 08809 { 08810 $return[$i]['self_closing'] = false; 08811 $return[$i]['content'] = $matches[$i][4][0]; 08812 } 08813 $return[$i]['attribs'] = array(); 08814 if (isset($matches[$i][2][0]) && preg_match_all('/[\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]*)?))?/', ' ' . $matches[$i][2][0] . ' ', $attribs, PREG_SET_ORDER)) 08815 { 08816 for ($j = 0, $total_attribs = count($attribs); $j < $total_attribs; $j++) 08817 { 08818 if (count($attribs[$j]) === 2) 08819 { 08820 $attribs[$j][2] = $attribs[$j][1]; 08821 } 08822 $return[$i]['attribs'][strtolower($attribs[$j][1])]['data'] = SimplePie_Misc::entities_decode(end($attribs[$j]), 'UTF-8'); 08823 } 08824 } 08825 } 08826 } 08827 return $return; 08828 } 08829 08830 public static function element_implode($element) 08831 { 08832 $full = "<$element[tag]"; 08833 foreach ($element['attribs'] as $key => $value) 08834 { 08835 $key = strtolower($key); 08836 $full .= " $key=\"" . htmlspecialchars($value['data']) . '"'; 08837 } 08838 if ($element['self_closing']) 08839 { 08840 $full .= ' />'; 08841 } 08842 else 08843 { 08844 $full .= ">$element[content]</$element[tag]>"; 08845 } 08846 return $full; 08847 } 08848 08849 public static function error($message, $level, $file, $line) 08850 { 08851 if ((ini_get('error_reporting') & $level) > 0) 08852 { 08853 switch ($level) 08854 { 08855 case E_USER_ERROR: 08856 $note = 'PHP Error'; 08857 break; 08858 case E_USER_WARNING: 08859 $note = 'PHP Warning'; 08860 break; 08861 case E_USER_NOTICE: 08862 $note = 'PHP Notice'; 08863 break; 08864 default: 08865 $note = 'Unknown Error'; 08866 break; 08867 } 08868 08869 $log_error = true; 08870 if (!function_exists('error_log')) 08871 { 08872 $log_error = false; 08873 } 08874 08875 $log_file = @ini_get('error_log'); 08876 if (!empty($log_file) && ('syslog' != $log_file) && !@is_writable($log_file)) 08877 { 08878 $log_error = false; 08879 } 08880 08881 if ($log_error) 08882 { 08883 @error_log("$note: $message in $file on line $line", 0); 08884 } 08885 } 08886 08887 return $message; 08888 } 08889 08890 public static function fix_protocol($url, $http = 1) 08891 { 08892 $url = SimplePie_Misc::normalize_url($url); 08893 $parsed = SimplePie_Misc::parse_url($url); 08894 if ($parsed['scheme'] !== '' && $parsed['scheme'] !== 'http' && $parsed['scheme'] !== 'https') 08895 { 08896 return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['authority'], $parsed['path'], $parsed['query'], $parsed['fragment']), $http); 08897 } 08898 08899 if ($parsed['scheme'] === '' && $parsed['authority'] === '' && !file_exists($url)) 08900 { 08901 return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['path'], '', $parsed['query'], $parsed['fragment']), $http); 08902 } 08903 08904 if ($http === 2 && $parsed['scheme'] !== '') 08905 { 08906 return "feed:$url"; 08907 } 08908 elseif ($http === 3 && strtolower($parsed['scheme']) === 'http') 08909 { 08910 return substr_replace($url, 'podcast', 0, 4); 08911 } 08912 elseif ($http === 4 && strtolower($parsed['scheme']) === 'http') 08913 { 08914 return substr_replace($url, 'itpc', 0, 4); 08915 } 08916 else 08917 { 08918 return $url; 08919 } 08920 } 08921 08922 public static function parse_url($url) 08923 { 08924 $iri = new SimplePie_IRI($url); 08925 return array( 08926 'scheme' => (string) $iri->get_scheme(), 08927 'authority' => (string) $iri->get_authority(), 08928 'path' => (string) $iri->get_path(), 08929 'query' => (string) $iri->get_query(), 08930 'fragment' => (string) $iri->get_fragment() 08931 ); 08932 } 08933 08934 public static function compress_parse_url($scheme = '', $authority = '', $path = '', $query = '', $fragment = '') 08935 { 08936 $iri = new SimplePie_IRI(''); 08937 $iri->set_scheme($scheme); 08938 $iri->set_authority($authority); 08939 $iri->set_path($path); 08940 $iri->set_query($query); 08941 $iri->set_fragment($fragment); 08942 return $iri->get_iri(); 08943 } 08944 08945 public static function normalize_url($url) 08946 { 08947 $iri = new SimplePie_IRI($url); 08948 return $iri->get_iri(); 08949 } 08950 08951 public static function percent_encoding_normalization($match) 08952 { 08953 $integer = hexdec($match[1]); 08954 if ($integer >= 0x41 && $integer <= 0x5A || $integer >= 0x61 && $integer <= 0x7A || $integer >= 0x30 && $integer <= 0x39 || $integer === 0x2D || $integer === 0x2E || $integer === 0x5F || $integer === 0x7E) 08955 { 08956 return chr($integer); 08957 } 08958 else 08959 { 08960 return strtoupper($match[0]); 08961 } 08962 } 08963 08972 public static function windows_1252_to_utf8($string) 08973 { 08974 static $convert_table = array("\x80" => "\xE2\x82\xAC", "\x81" => "\xEF\xBF\xBD", "\x82" => "\xE2\x80\x9A", "\x83" => "\xC6\x92", "\x84" => "\xE2\x80\x9E", "\x85" => "\xE2\x80\xA6", "\x86" => "\xE2\x80\xA0", "\x87" => "\xE2\x80\xA1", "\x88" => "\xCB\x86", "\x89" => "\xE2\x80\xB0", "\x8A" => "\xC5\xA0", "\x8B" => "\xE2\x80\xB9", "\x8C" => "\xC5\x92", "\x8D" => "\xEF\xBF\xBD", "\x8E" => "\xC5\xBD", "\x8F" => "\xEF\xBF\xBD", "\x90" => "\xEF\xBF\xBD", "\x91" => "\xE2\x80\x98", "\x92" => "\xE2\x80\x99", "\x93" => "\xE2\x80\x9C", "\x94" => "\xE2\x80\x9D", "\x95" => "\xE2\x80\xA2", "\x96" => "\xE2\x80\x93", "\x97" => "\xE2\x80\x94", "\x98" => "\xCB\x9C", "\x99" => "\xE2\x84\xA2", "\x9A" => "\xC5\xA1", "\x9B" => "\xE2\x80\xBA", "\x9C" => "\xC5\x93", "\x9D" => "\xEF\xBF\xBD", "\x9E" => "\xC5\xBE", "\x9F" => "\xC5\xB8", "\xA0" => "\xC2\xA0", "\xA1" => "\xC2\xA1", "\xA2" => "\xC2\xA2", "\xA3" => "\xC2\xA3", "\xA4" => "\xC2\xA4", "\xA5" => "\xC2\xA5", "\xA6" => "\xC2\xA6", "\xA7" => "\xC2\xA7", "\xA8" => "\xC2\xA8", "\xA9" => "\xC2\xA9", "\xAA" => "\xC2\xAA", "\xAB" => "\xC2\xAB", "\xAC" => "\xC2\xAC", "\xAD" => "\xC2\xAD", "\xAE" => "\xC2\xAE", "\xAF" => "\xC2\xAF", "\xB0" => "\xC2\xB0", "\xB1" => "\xC2\xB1", "\xB2" => "\xC2\xB2", "\xB3" => "\xC2\xB3", "\xB4" => "\xC2\xB4", "\xB5" => "\xC2\xB5", "\xB6" => "\xC2\xB6", "\xB7" => "\xC2\xB7", "\xB8" => "\xC2\xB8", "\xB9" => "\xC2\xB9", "\xBA" => "\xC2\xBA", "\xBB" => "\xC2\xBB", "\xBC" => "\xC2\xBC", "\xBD" => "\xC2\xBD", "\xBE" => "\xC2\xBE", "\xBF" => "\xC2\xBF", "\xC0" => "\xC3\x80", "\xC1" => "\xC3\x81", "\xC2" => "\xC3\x82", "\xC3" => "\xC3\x83", "\xC4" => "\xC3\x84", "\xC5" => "\xC3\x85", "\xC6" => "\xC3\x86", "\xC7" => "\xC3\x87", "\xC8" => "\xC3\x88", "\xC9" => "\xC3\x89", "\xCA" => "\xC3\x8A", "\xCB" => "\xC3\x8B", "\xCC" => "\xC3\x8C", "\xCD" => "\xC3\x8D", "\xCE" => "\xC3\x8E", "\xCF" => "\xC3\x8F", "\xD0" => "\xC3\x90", "\xD1" => "\xC3\x91", "\xD2" => "\xC3\x92", "\xD3" => "\xC3\x93", "\xD4" => "\xC3\x94", "\xD5" => "\xC3\x95", "\xD6" => "\xC3\x96", "\xD7" => "\xC3\x97", "\xD8" => "\xC3\x98", "\xD9" => "\xC3\x99", "\xDA" => "\xC3\x9A", "\xDB" => "\xC3\x9B", "\xDC" => "\xC3\x9C", "\xDD" => "\xC3\x9D", "\xDE" => "\xC3\x9E", "\xDF" => "\xC3\x9F", "\xE0" => "\xC3\xA0", "\xE1" => "\xC3\xA1", "\xE2" => "\xC3\xA2", "\xE3" => "\xC3\xA3", "\xE4" => "\xC3\xA4", "\xE5" => "\xC3\xA5", "\xE6" => "\xC3\xA6", "\xE7" => "\xC3\xA7", "\xE8" => "\xC3\xA8", "\xE9" => "\xC3\xA9", "\xEA" => "\xC3\xAA", "\xEB" => "\xC3\xAB", "\xEC" => "\xC3\xAC", "\xED" => "\xC3\xAD", "\xEE" => "\xC3\xAE", "\xEF" => "\xC3\xAF", "\xF0" => "\xC3\xB0", "\xF1" => "\xC3\xB1", "\xF2" => "\xC3\xB2", "\xF3" => "\xC3\xB3", "\xF4" => "\xC3\xB4", "\xF5" => "\xC3\xB5", "\xF6" => "\xC3\xB6", "\xF7" => "\xC3\xB7", "\xF8" => "\xC3\xB8", "\xF9" => "\xC3\xB9", "\xFA" => "\xC3\xBA", "\xFB" => "\xC3\xBB", "\xFC" => "\xC3\xBC", "\xFD" => "\xC3\xBD", "\xFE" => "\xC3\xBE", "\xFF" => "\xC3\xBF"); 08975 08976 return strtr($string, $convert_table); 08977 } 08978 08979 public static function change_encoding($data, $input, $output) 08980 { 08981 $input = SimplePie_Misc::encoding($input); 08982 $output = SimplePie_Misc::encoding($output); 08983 08984 // We fail to fail on non US-ASCII bytes 08985 if ($input === 'US-ASCII') 08986 { 08987 static $non_ascii_octects = ''; 08988 if (!$non_ascii_octects) 08989 { 08990 for ($i = 0x80; $i <= 0xFF; $i++) 08991 { 08992 $non_ascii_octects .= chr($i); 08993 } 08994 } 08995 $data = substr($data, 0, strcspn($data, $non_ascii_octects)); 08996 } 08997 08998 // This is first, as behaviour of this is completely predictable 08999 if ($input === 'windows-1252' && $output === 'UTF-8') 09000 { 09001 return SimplePie_Misc::windows_1252_to_utf8($data); 09002 } 09003 // This is second, as behaviour of this varies only with PHP version (the middle part of this expression checks the encoding is supported). 09004 elseif (function_exists('mb_convert_encoding') && @mb_convert_encoding("\x80", 'UTF-16BE', $input) !== "\x00\x80" && ($return = @mb_convert_encoding($data, $output, $input))) 09005 { 09006 return $return; 09007 } 09008 // This is last, as behaviour of this varies with OS userland and PHP version 09009 elseif (function_exists('iconv') && ($return = @iconv($input, $output, $data))) 09010 { 09011 return $return; 09012 } 09013 // If we can't do anything, just fail 09014 else 09015 { 09016 return false; 09017 } 09018 } 09019 09031 public static function encoding($charset) 09032 { 09033 // Normalization from UTS #22 09034 switch (strtolower(preg_replace('/(?:[^a-zA-Z0-9]+|([^0-9])0+)/', '\1', $charset))) 09035 { 09036 case 'adobestandardencoding': 09037 case 'csadobestandardencoding': 09038 return 'Adobe-Standard-Encoding'; 09039 09040 case 'adobesymbolencoding': 09041 case 'cshppsmath': 09042 return 'Adobe-Symbol-Encoding'; 09043 09044 case 'ami1251': 09045 case 'amiga1251': 09046 return 'Amiga-1251'; 09047 09048 case 'ansix31101983': 09049 case 'csat5001983': 09050 case 'csiso99naplps': 09051 case 'isoir99': 09052 case 'naplps': 09053 return 'ANSI_X3.110-1983'; 09054 09055 case 'arabic7': 09056 case 'asmo449': 09057 case 'csiso89asmo449': 09058 case 'iso9036': 09059 case 'isoir89': 09060 return 'ASMO_449'; 09061 09062 case 'big5': 09063 case 'csbig5': 09064 return 'Big5'; 09065 09066 case 'big5hkscs': 09067 return 'Big5-HKSCS'; 09068 09069 case 'bocu1': 09070 case 'csbocu1': 09071 return 'BOCU-1'; 09072 09073 case 'brf': 09074 case 'csbrf': 09075 return 'BRF'; 09076 09077 case 'bs4730': 09078 case 'csiso4unitedkingdom': 09079 case 'gb': 09080 case 'iso646gb': 09081 case 'isoir4': 09082 case 'uk': 09083 return 'BS_4730'; 09084 09085 case 'bsviewdata': 09086 case 'csiso47bsviewdata': 09087 case 'isoir47': 09088 return 'BS_viewdata'; 09089 09090 case 'cesu8': 09091 case 'cscesu8': 09092 return 'CESU-8'; 09093 09094 case 'ca': 09095 case 'csa71': 09096 case 'csaz243419851': 09097 case 'csiso121canadian1': 09098 case 'iso646ca': 09099 case 'isoir121': 09100 return 'CSA_Z243.4-1985-1'; 09101 09102 case 'csa72': 09103 case 'csaz243419852': 09104 case 'csiso122canadian2': 09105 case 'iso646ca2': 09106 case 'isoir122': 09107 return 'CSA_Z243.4-1985-2'; 09108 09109 case 'csaz24341985gr': 09110 case 'csiso123csaz24341985gr': 09111 case 'isoir123': 09112 return 'CSA_Z243.4-1985-gr'; 09113 09114 case 'csiso139csn369103': 09115 case 'csn369103': 09116 case 'isoir139': 09117 return 'CSN_369103'; 09118 09119 case 'csdecmcs': 09120 case 'dec': 09121 case 'decmcs': 09122 return 'DEC-MCS'; 09123 09124 case 'csiso21german': 09125 case 'de': 09126 case 'din66003': 09127 case 'iso646de': 09128 case 'isoir21': 09129 return 'DIN_66003'; 09130 09131 case 'csdkus': 09132 case 'dkus': 09133 return 'dk-us'; 09134 09135 case 'csiso646danish': 09136 case 'dk': 09137 case 'ds2089': 09138 case 'iso646dk': 09139 return 'DS_2089'; 09140 09141 case 'csibmebcdicatde': 09142 case 'ebcdicatde': 09143 return 'EBCDIC-AT-DE'; 09144 09145 case 'csebcdicatdea': 09146 case 'ebcdicatdea': 09147 return 'EBCDIC-AT-DE-A'; 09148 09149 case 'csebcdiccafr': 09150 case 'ebcdiccafr': 09151 return 'EBCDIC-CA-FR'; 09152 09153 case 'csebcdicdkno': 09154 case 'ebcdicdkno': 09155 return 'EBCDIC-DK-NO'; 09156 09157 case 'csebcdicdknoa': 09158 case 'ebcdicdknoa': 09159 return 'EBCDIC-DK-NO-A'; 09160 09161 case 'csebcdices': 09162 case 'ebcdices': 09163 return 'EBCDIC-ES'; 09164 09165 case 'csebcdicesa': 09166 case 'ebcdicesa': 09167 return 'EBCDIC-ES-A'; 09168 09169 case 'csebcdicess': 09170 case 'ebcdicess': 09171 return 'EBCDIC-ES-S'; 09172 09173 case 'csebcdicfise': 09174 case 'ebcdicfise': 09175 return 'EBCDIC-FI-SE'; 09176 09177 case 'csebcdicfisea': 09178 case 'ebcdicfisea': 09179 return 'EBCDIC-FI-SE-A'; 09180 09181 case 'csebcdicfr': 09182 case 'ebcdicfr': 09183 return 'EBCDIC-FR'; 09184 09185 case 'csebcdicit': 09186 case 'ebcdicit': 09187 return 'EBCDIC-IT'; 09188 09189 case 'csebcdicpt': 09190 case 'ebcdicpt': 09191 return 'EBCDIC-PT'; 09192 09193 case 'csebcdicuk': 09194 case 'ebcdicuk': 09195 return 'EBCDIC-UK'; 09196 09197 case 'csebcdicus': 09198 case 'ebcdicus': 09199 return 'EBCDIC-US'; 09200 09201 case 'csiso111ecmacyrillic': 09202 case 'ecmacyrillic': 09203 case 'isoir111': 09204 case 'koi8e': 09205 return 'ECMA-cyrillic'; 09206 09207 case 'csiso17spanish': 09208 case 'es': 09209 case 'iso646es': 09210 case 'isoir17': 09211 return 'ES'; 09212 09213 case 'csiso85spanish2': 09214 case 'es2': 09215 case 'iso646es2': 09216 case 'isoir85': 09217 return 'ES2'; 09218 09219 case 'cseucpkdfmtjapanese': 09220 case 'eucjp': 09221 case 'extendedunixcodepackedformatforjapanese': 09222 return 'EUC-JP'; 09223 09224 case 'cseucfixwidjapanese': 09225 case 'extendedunixcodefixedwidthforjapanese': 09226 return 'Extended_UNIX_Code_Fixed_Width_for_Japanese'; 09227 09228 case 'gb18030': 09229 return 'GB18030'; 09230 09231 case 'chinese': 09232 case 'cp936': 09233 case 'csgb2312': 09234 case 'csiso58gb231280': 09235 case 'gb2312': 09236 case 'gb231280': 09237 case 'gbk': 09238 case 'isoir58': 09239 case 'ms936': 09240 case 'windows936': 09241 return 'GBK'; 09242 09243 case 'cn': 09244 case 'csiso57gb1988': 09245 case 'gb198880': 09246 case 'iso646cn': 09247 case 'isoir57': 09248 return 'GB_1988-80'; 09249 09250 case 'csiso153gost1976874': 09251 case 'gost1976874': 09252 case 'isoir153': 09253 case 'stsev35888': 09254 return 'GOST_19768-74'; 09255 09256 case 'csiso150': 09257 case 'csiso150greekccitt': 09258 case 'greekccitt': 09259 case 'isoir150': 09260 return 'greek-ccitt'; 09261 09262 case 'csiso88greek7': 09263 case 'greek7': 09264 case 'isoir88': 09265 return 'greek7'; 09266 09267 case 'csiso18greek7old': 09268 case 'greek7old': 09269 case 'isoir18': 09270 return 'greek7-old'; 09271 09272 case 'cshpdesktop': 09273 case 'hpdesktop': 09274 return 'HP-DeskTop'; 09275 09276 case 'cshplegal': 09277 case 'hplegal': 09278 return 'HP-Legal'; 09279 09280 case 'cshpmath8': 09281 case 'hpmath8': 09282 return 'HP-Math8'; 09283 09284 case 'cshppifont': 09285 case 'hppifont': 09286 return 'HP-Pi-font'; 09287 09288 case 'cshproman8': 09289 case 'hproman8': 09290 case 'r8': 09291 case 'roman8': 09292 return 'hp-roman8'; 09293 09294 case 'hzgb2312': 09295 return 'HZ-GB-2312'; 09296 09297 case 'csibmsymbols': 09298 case 'ibmsymbols': 09299 return 'IBM-Symbols'; 09300 09301 case 'csibmthai': 09302 case 'ibmthai': 09303 return 'IBM-Thai'; 09304 09305 case 'cp37': 09306 case 'csibm37': 09307 case 'ebcdiccpca': 09308 case 'ebcdiccpnl': 09309 case 'ebcdiccpus': 09310 case 'ebcdiccpwt': 09311 case 'ibm37': 09312 return 'IBM037'; 09313 09314 case 'cp38': 09315 case 'csibm38': 09316 case 'ebcdicint': 09317 case 'ibm38': 09318 return 'IBM038'; 09319 09320 case 'cp273': 09321 case 'csibm273': 09322 case 'ibm273': 09323 return 'IBM273'; 09324 09325 case 'cp274': 09326 case 'csibm274': 09327 case 'ebcdicbe': 09328 case 'ibm274': 09329 return 'IBM274'; 09330 09331 case 'cp275': 09332 case 'csibm275': 09333 case 'ebcdicbr': 09334 case 'ibm275': 09335 return 'IBM275'; 09336 09337 case 'csibm277': 09338 case 'ebcdiccpdk': 09339 case 'ebcdiccpno': 09340 case 'ibm277': 09341 return 'IBM277'; 09342 09343 case 'cp278': 09344 case 'csibm278': 09345 case 'ebcdiccpfi': 09346 case 'ebcdiccpse': 09347 case 'ibm278': 09348 return 'IBM278'; 09349 09350 case 'cp280': 09351 case 'csibm280': 09352 case 'ebcdiccpit': 09353 case 'ibm280': 09354 return 'IBM280'; 09355 09356 case 'cp281': 09357 case 'csibm281': 09358 case 'ebcdicjpe': 09359 case 'ibm281': 09360 return 'IBM281'; 09361 09362 case 'cp284': 09363 case 'csibm284': 09364 case 'ebcdiccpes': 09365 case 'ibm284': 09366 return 'IBM284'; 09367 09368 case 'cp285': 09369 case 'csibm285': 09370 case 'ebcdiccpgb': 09371 case 'ibm285': 09372 return 'IBM285'; 09373 09374 case 'cp290': 09375 case 'csibm290': 09376 case 'ebcdicjpkana': 09377 case 'ibm290': 09378 return 'IBM290'; 09379 09380 case 'cp297': 09381 case 'csibm297': 09382 case 'ebcdiccpfr': 09383 case 'ibm297': 09384 return 'IBM297'; 09385 09386 case 'cp420': 09387 case 'csibm420': 09388 case 'ebcdiccpar1': 09389 case 'ibm420': 09390 return 'IBM420'; 09391 09392 case 'cp423': 09393 case 'csibm423': 09394 case 'ebcdiccpgr': 09395 case 'ibm423': 09396 return 'IBM423'; 09397 09398 case 'cp424': 09399 case 'csibm424': 09400 case 'ebcdiccphe': 09401 case 'ibm424': 09402 return 'IBM424'; 09403 09404 case '437': 09405 case 'cp437': 09406 case 'cspc8codepage437': 09407 case 'ibm437': 09408 return 'IBM437'; 09409 09410 case 'cp500': 09411 case 'csibm500': 09412 case 'ebcdiccpbe': 09413 case 'ebcdiccpch': 09414 case 'ibm500': 09415 return 'IBM500'; 09416 09417 case 'cp775': 09418 case 'cspc775baltic': 09419 case 'ibm775': 09420 return 'IBM775'; 09421 09422 case '850': 09423 case 'cp850': 09424 case 'cspc850multilingual': 09425 case 'ibm850': 09426 return 'IBM850'; 09427 09428 case '851': 09429 case 'cp851': 09430 case 'csibm851': 09431 case 'ibm851': 09432 return 'IBM851'; 09433 09434 case '852': 09435 case 'cp852': 09436 case 'cspcp852': 09437 case 'ibm852': 09438 return 'IBM852'; 09439 09440 case '855': 09441 case 'cp855': 09442 case 'csibm855': 09443 case 'ibm855': 09444 return 'IBM855'; 09445 09446 case '857': 09447 case 'cp857': 09448 case 'csibm857': 09449 case 'ibm857': 09450 return 'IBM857'; 09451 09452 case 'ccsid858': 09453 case 'cp858': 09454 case 'ibm858': 09455 case 'pcmultilingual850euro': 09456 return 'IBM00858'; 09457 09458 case '860': 09459 case 'cp860': 09460 case 'csibm860': 09461 case 'ibm860': 09462 return 'IBM860'; 09463 09464 case '861': 09465 case 'cp861': 09466 case 'cpis': 09467 case 'csibm861': 09468 case 'ibm861': 09469 return 'IBM861'; 09470 09471 case '862': 09472 case 'cp862': 09473 case 'cspc862latinhebrew': 09474 case 'ibm862': 09475 return 'IBM862'; 09476 09477 case '863': 09478 case 'cp863': 09479 case 'csibm863': 09480 case 'ibm863': 09481 return 'IBM863'; 09482 09483 case 'cp864': 09484 case 'csibm864': 09485 case 'ibm864': 09486 return 'IBM864'; 09487 09488 case '865': 09489 case 'cp865': 09490 case 'csibm865': 09491 case 'ibm865': 09492 return 'IBM865'; 09493 09494 case '866': 09495 case 'cp866': 09496 case 'csibm866': 09497 case 'ibm866': 09498 return 'IBM866'; 09499 09500 case 'cp868': 09501 case 'cpar': 09502 case 'csibm868': 09503 case 'ibm868': 09504 return 'IBM868'; 09505 09506 case '869': 09507 case 'cp869': 09508 case 'cpgr': 09509 case 'csibm869': 09510 case 'ibm869': 09511 return 'IBM869'; 09512 09513 case 'cp870': 09514 case 'csibm870': 09515 case 'ebcdiccproece': 09516 case 'ebcdiccpyu': 09517 case 'ibm870': 09518 return 'IBM870'; 09519 09520 case 'cp871': 09521 case 'csibm871': 09522 case 'ebcdiccpis': 09523 case 'ibm871': 09524 return 'IBM871'; 09525 09526 case 'cp880': 09527 case 'csibm880': 09528 case 'ebcdiccyrillic': 09529 case 'ibm880': 09530 return 'IBM880'; 09531 09532 case 'cp891': 09533 case 'csibm891': 09534 case 'ibm891': 09535 return 'IBM891'; 09536 09537 case 'cp903': 09538 case 'csibm903': 09539 case 'ibm903': 09540 return 'IBM903'; 09541 09542 case '904': 09543 case 'cp904': 09544 case 'csibbm904': 09545 case 'ibm904': 09546 return 'IBM904'; 09547 09548 case 'cp905': 09549 case 'csibm905': 09550 case 'ebcdiccptr': 09551 case 'ibm905': 09552 return 'IBM905'; 09553 09554 case 'cp918': 09555 case 'csibm918': 09556 case 'ebcdiccpar2': 09557 case 'ibm918': 09558 return 'IBM918'; 09559 09560 case 'ccsid924': 09561 case 'cp924': 09562 case 'ebcdiclatin9euro': 09563 case 'ibm924': 09564 return 'IBM00924'; 09565 09566 case 'cp1026': 09567 case 'csibm1026': 09568 case 'ibm1026': 09569 return 'IBM1026'; 09570 09571 case 'ibm1047': 09572 return 'IBM1047'; 09573 09574 case 'ccsid1140': 09575 case 'cp1140': 09576 case 'ebcdicus37euro': 09577 case 'ibm1140': 09578 return 'IBM01140'; 09579 09580 case 'ccsid1141': 09581 case 'cp1141': 09582 case 'ebcdicde273euro': 09583 case 'ibm1141': 09584 return 'IBM01141'; 09585 09586 case 'ccsid1142': 09587 case 'cp1142': 09588 case 'ebcdicdk277euro': 09589 case 'ebcdicno277euro': 09590 case 'ibm1142': 09591 return 'IBM01142'; 09592 09593 case 'ccsid1143': 09594 case 'cp1143': 09595 case 'ebcdicfi278euro': 09596 case 'ebcdicse278euro': 09597 case 'ibm1143': 09598 return 'IBM01143'; 09599 09600 case 'ccsid1144': 09601 case 'cp1144': 09602 case 'ebcdicit280euro': 09603 case 'ibm1144': 09604 return 'IBM01144'; 09605 09606 case 'ccsid1145': 09607 case 'cp1145': 09608 case 'ebcdices284euro': 09609 case 'ibm1145': 09610 return 'IBM01145'; 09611 09612 case 'ccsid1146': 09613 case 'cp1146': 09614 case 'ebcdicgb285euro': 09615 case 'ibm1146': 09616 return 'IBM01146'; 09617 09618 case 'ccsid1147': 09619 case 'cp1147': 09620 case 'ebcdicfr297euro': 09621 case 'ibm1147': 09622 return 'IBM01147'; 09623 09624 case 'ccsid1148': 09625 case 'cp1148': 09626 case 'ebcdicinternational500euro': 09627 case 'ibm1148': 09628 return 'IBM01148'; 09629 09630 case 'ccsid1149': 09631 case 'cp1149': 09632 case 'ebcdicis871euro': 09633 case 'ibm1149': 09634 return 'IBM01149'; 09635 09636 case 'csiso143iecp271': 09637 case 'iecp271': 09638 case 'isoir143': 09639 return 'IEC_P27-1'; 09640 09641 case 'csiso49inis': 09642 case 'inis': 09643 case 'isoir49': 09644 return 'INIS'; 09645 09646 case 'csiso50inis8': 09647 case 'inis8': 09648 case 'isoir50': 09649 return 'INIS-8'; 09650 09651 case 'csiso51iniscyrillic': 09652 case 'iniscyrillic': 09653 case 'isoir51': 09654 return 'INIS-cyrillic'; 09655 09656 case 'csinvariant': 09657 case 'invariant': 09658 return 'INVARIANT'; 09659 09660 case 'iso2022cn': 09661 return 'ISO-2022-CN'; 09662 09663 case 'iso2022cnext': 09664 return 'ISO-2022-CN-EXT'; 09665 09666 case 'csiso2022jp': 09667 case 'iso2022jp': 09668 return 'ISO-2022-JP'; 09669 09670 case 'csiso2022jp2': 09671 case 'iso2022jp2': 09672 return 'ISO-2022-JP-2'; 09673 09674 case 'csiso2022kr': 09675 case 'iso2022kr': 09676 return 'ISO-2022-KR'; 09677 09678 case 'cswindows30latin1': 09679 case 'iso88591windows30latin1': 09680 return 'ISO-8859-1-Windows-3.0-Latin-1'; 09681 09682 case 'cswindows31latin1': 09683 case 'iso88591windows31latin1': 09684 return 'ISO-8859-1-Windows-3.1-Latin-1'; 09685 09686 case 'csisolatin2': 09687 case 'iso88592': 09688 case 'iso885921987': 09689 case 'isoir101': 09690 case 'l2': 09691 case 'latin2': 09692 return 'ISO-8859-2'; 09693 09694 case 'cswindows31latin2': 09695 case 'iso88592windowslatin2': 09696 return 'ISO-8859-2-Windows-Latin-2'; 09697 09698 case 'csisolatin3': 09699 case 'iso88593': 09700 case 'iso885931988': 09701 case 'isoir109': 09702 case 'l3': 09703 case 'latin3': 09704 return 'ISO-8859-3'; 09705 09706 case 'csisolatin4': 09707 case 'iso88594': 09708 case 'iso885941988': 09709 case 'isoir110': 09710 case 'l4': 09711 case 'latin4': 09712 return 'ISO-8859-4'; 09713 09714 case 'csisolatincyrillic': 09715 case 'cyrillic': 09716 case 'iso88595': 09717 case 'iso885951988': 09718 case 'isoir144': 09719 return 'ISO-8859-5'; 09720 09721 case 'arabic': 09722 case 'asmo708': 09723 case 'csisolatinarabic': 09724 case 'ecma114': 09725 case 'iso88596': 09726 case 'iso885961987': 09727 case 'isoir127': 09728 return 'ISO-8859-6'; 09729 09730 case 'csiso88596e': 09731 case 'iso88596e': 09732 return 'ISO-8859-6-E'; 09733 09734 case 'csiso88596i': 09735 case 'iso88596i': 09736 return 'ISO-8859-6-I'; 09737 09738 case 'csisolatingreek': 09739 case 'ecma118': 09740 case 'elot928': 09741 case 'greek': 09742 case 'greek8': 09743 case 'iso88597': 09744 case 'iso885971987': 09745 case 'isoir126': 09746 return 'ISO-8859-7'; 09747 09748 case 'csisolatinhebrew': 09749 case 'hebrew': 09750 case 'iso88598': 09751 case 'iso885981988': 09752 case 'isoir138': 09753 return 'ISO-8859-8'; 09754 09755 case 'csiso88598e': 09756 case 'iso88598e': 09757 return 'ISO-8859-8-E'; 09758 09759 case 'csiso88598i': 09760 case 'iso88598i': 09761 return 'ISO-8859-8-I'; 09762 09763 case 'cswindows31latin5': 09764 case 'iso88599windowslatin5': 09765 return 'ISO-8859-9-Windows-Latin-5'; 09766 09767 case 'csisolatin6': 09768 case 'iso885910': 09769 case 'iso8859101992': 09770 case 'isoir157': 09771 case 'l6': 09772 case 'latin6': 09773 return 'ISO-8859-10'; 09774 09775 case 'iso885913': 09776 return 'ISO-8859-13'; 09777 09778 case 'iso885914': 09779 case 'iso8859141998': 09780 case 'isoceltic': 09781 case 'isoir199': 09782 case 'l8': 09783 case 'latin8': 09784 return 'ISO-8859-14'; 09785 09786 case 'iso885915': 09787 case 'latin9': 09788 return 'ISO-8859-15'; 09789 09790 case 'iso885916': 09791 case 'iso8859162001': 09792 case 'isoir226': 09793 case 'l10': 09794 case 'latin10': 09795 return 'ISO-8859-16'; 09796 09797 case 'iso10646j1': 09798 return 'ISO-10646-J-1'; 09799 09800 case 'csunicode': 09801 case 'iso10646ucs2': 09802 return 'ISO-10646-UCS-2'; 09803 09804 case 'csucs4': 09805 case 'iso10646ucs4': 09806 return 'ISO-10646-UCS-4'; 09807 09808 case 'csunicodeascii': 09809 case 'iso10646ucsbasic': 09810 return 'ISO-10646-UCS-Basic'; 09811 09812 case 'csunicodelatin1': 09813 case 'iso10646': 09814 case 'iso10646unicodelatin1': 09815 return 'ISO-10646-Unicode-Latin1'; 09816 09817 case 'csiso10646utf1': 09818 case 'iso10646utf1': 09819 return 'ISO-10646-UTF-1'; 09820 09821 case 'csiso115481': 09822 case 'iso115481': 09823 case 'isotr115481': 09824 return 'ISO-11548-1'; 09825 09826 case 'csiso90': 09827 case 'isoir90': 09828 return 'iso-ir-90'; 09829 09830 case 'csunicodeibm1261': 09831 case 'isounicodeibm1261': 09832 return 'ISO-Unicode-IBM-1261'; 09833 09834 case 'csunicodeibm1264': 09835 case 'isounicodeibm1264': 09836 return 'ISO-Unicode-IBM-1264'; 09837 09838 case 'csunicodeibm1265': 09839 case 'isounicodeibm1265': 09840 return 'ISO-Unicode-IBM-1265'; 09841 09842 case 'csunicodeibm1268': 09843 case 'isounicodeibm1268': 09844 return 'ISO-Unicode-IBM-1268'; 09845 09846 case 'csunicodeibm1276': 09847 case 'isounicodeibm1276': 09848 return 'ISO-Unicode-IBM-1276'; 09849 09850 case 'csiso646basic1983': 09851 case 'iso646basic1983': 09852 case 'ref': 09853 return 'ISO_646.basic:1983'; 09854 09855 case 'csiso2intlrefversion': 09856 case 'irv': 09857 case 'iso646irv1983': 09858 case 'isoir2': 09859 return 'ISO_646.irv:1983'; 09860 09861 case 'csiso2033': 09862 case 'e13b': 09863 case 'iso20331983': 09864 case 'isoir98': 09865 return 'ISO_2033-1983'; 09866 09867 case 'csiso5427cyrillic': 09868 case 'iso5427': 09869 case 'isoir37': 09870 return 'ISO_5427'; 09871 09872 case 'iso5427cyrillic1981': 09873 case 'iso54271981': 09874 case 'isoir54': 09875 return 'ISO_5427:1981'; 09876 09877 case 'csiso5428greek': 09878 case 'iso54281980': 09879 case 'isoir55': 09880 return 'ISO_5428:1980'; 09881 09882 case 'csiso6937add': 09883 case 'iso6937225': 09884 case 'isoir152': 09885 return 'ISO_6937-2-25'; 09886 09887 case 'csisotextcomm': 09888 case 'iso69372add': 09889 case 'isoir142': 09890 return 'ISO_6937-2-add'; 09891 09892 case 'csiso8859supp': 09893 case 'iso8859supp': 09894 case 'isoir154': 09895 case 'latin125': 09896 return 'ISO_8859-supp'; 09897 09898 case 'csiso10367box': 09899 case 'iso10367box': 09900 case 'isoir155': 09901 return 'ISO_10367-box'; 09902 09903 case 'csiso15italian': 09904 case 'iso646it': 09905 case 'isoir15': 09906 case 'it': 09907 return 'IT'; 09908 09909 case 'csiso13jisc6220jp': 09910 case 'isoir13': 09911 case 'jisc62201969': 09912 case 'jisc62201969jp': 09913 case 'katakana': 09914 case 'x2017': 09915 return 'JIS_C6220-1969-jp'; 09916 09917 case 'csiso14jisc6220ro': 09918 case 'iso646jp': 09919 case 'isoir14': 09920 case 'jisc62201969ro': 09921 case 'jp': 09922 return 'JIS_C6220-1969-ro'; 09923 09924 case 'csiso42jisc62261978': 09925 case 'isoir42': 09926 case 'jisc62261978': 09927 return 'JIS_C6226-1978'; 09928 09929 case 'csiso87jisx208': 09930 case 'isoir87': 09931 case 'jisc62261983': 09932 case 'jisx2081983': 09933 case 'x208': 09934 return 'JIS_C6226-1983'; 09935 09936 case 'csiso91jisc62291984a': 09937 case 'isoir91': 09938 case 'jisc62291984a': 09939 case 'jpocra': 09940 return 'JIS_C6229-1984-a'; 09941 09942 case 'csiso92jisc62991984b': 09943 case 'iso646jpocrb': 09944 case 'isoir92': 09945 case 'jisc62291984b': 09946 case 'jpocrb': 09947 return 'JIS_C6229-1984-b'; 09948 09949 case 'csiso93jis62291984badd': 09950 case 'isoir93': 09951 case 'jisc62291984badd': 09952 case 'jpocrbadd': 09953 return 'JIS_C6229-1984-b-add'; 09954 09955 case 'csiso94jis62291984hand': 09956 case 'isoir94': 09957 case 'jisc62291984hand': 09958 case 'jpocrhand': 09959 return 'JIS_C6229-1984-hand'; 09960 09961 case 'csiso95jis62291984handadd': 09962 case 'isoir95': 09963 case 'jisc62291984handadd': 09964 case 'jpocrhandadd': 09965 return 'JIS_C6229-1984-hand-add'; 09966 09967 case 'csiso96jisc62291984kana': 09968 case 'isoir96': 09969 case 'jisc62291984kana': 09970 return 'JIS_C6229-1984-kana'; 09971 09972 case 'csjisencoding': 09973 case 'jisencoding': 09974 return 'JIS_Encoding'; 09975 09976 case 'cshalfwidthkatakana': 09977 case 'jisx201': 09978 case 'x201': 09979 return 'JIS_X0201'; 09980 09981 case 'csiso159jisx2121990': 09982 case 'isoir159': 09983 case 'jisx2121990': 09984 case 'x212': 09985 return 'JIS_X0212-1990'; 09986 09987 case 'csiso141jusib1002': 09988 case 'iso646yu': 09989 case 'isoir141': 09990 case 'js': 09991 case 'jusib1002': 09992 case 'yu': 09993 return 'JUS_I.B1.002'; 09994 09995 case 'csiso147macedonian': 09996 case 'isoir147': 09997 case 'jusib1003mac': 09998 case 'macedonian': 09999 return 'JUS_I.B1.003-mac'; 10000 10001 case 'csiso146serbian': 10002 case 'isoir146': 10003 case 'jusib1003serb': 10004 case 'serbian': 10005 return 'JUS_I.B1.003-serb'; 10006 10007 case 'koi7switched': 10008 return 'KOI7-switched'; 10009 10010 case 'cskoi8r': 10011 case 'koi8r': 10012 return 'KOI8-R'; 10013 10014 case 'koi8u': 10015 return 'KOI8-U'; 10016 10017 case 'csksc5636': 10018 case 'iso646kr': 10019 case 'ksc5636': 10020 return 'KSC5636'; 10021 10022 case 'cskz1048': 10023 case 'kz1048': 10024 case 'rk1048': 10025 case 'strk10482002': 10026 return 'KZ-1048'; 10027 10028 case 'csiso19latingreek': 10029 case 'isoir19': 10030 case 'latingreek': 10031 return 'latin-greek'; 10032 10033 case 'csiso27latingreek1': 10034 case 'isoir27': 10035 case 'latingreek1': 10036 return 'Latin-greek-1'; 10037 10038 case 'csiso158lap': 10039 case 'isoir158': 10040 case 'lap': 10041 case 'latinlap': 10042 return 'latin-lap'; 10043 10044 case 'csmacintosh': 10045 case 'mac': 10046 case 'macintosh': 10047 return 'macintosh'; 10048 10049 case 'csmicrosoftpublishing': 10050 case 'microsoftpublishing': 10051 return 'Microsoft-Publishing'; 10052 10053 case 'csmnem': 10054 case 'mnem': 10055 return 'MNEM'; 10056 10057 case 'csmnemonic': 10058 case 'mnemonic': 10059 return 'MNEMONIC'; 10060 10061 case 'csiso86hungarian': 10062 case 'hu': 10063 case 'iso646hu': 10064 case 'isoir86': 10065 case 'msz77953': 10066 return 'MSZ_7795.3'; 10067 10068 case 'csnatsdano': 10069 case 'isoir91': 10070 case 'natsdano': 10071 return 'NATS-DANO'; 10072 10073 case 'csnatsdanoadd': 10074 case 'isoir92': 10075 case 'natsdanoadd': 10076 return 'NATS-DANO-ADD'; 10077 10078 case 'csnatssefi': 10079 case 'isoir81': 10080 case 'natssefi': 10081 return 'NATS-SEFI'; 10082 10083 case 'csnatssefiadd': 10084 case 'isoir82': 10085 case 'natssefiadd': 10086 return 'NATS-SEFI-ADD'; 10087 10088 case 'csiso151cuba': 10089 case 'cuba': 10090 case 'iso646cu': 10091 case 'isoir151': 10092 case 'ncnc1081': 10093 return 'NC_NC00-10:81'; 10094 10095 case 'csiso69french': 10096 case 'fr': 10097 case 'iso646fr': 10098 case 'isoir69': 10099 case 'nfz62010': 10100 return 'NF_Z_62-010'; 10101 10102 case 'csiso25french': 10103 case 'iso646fr1': 10104 case 'isoir25': 10105 case 'nfz620101973': 10106 return 'NF_Z_62-010_(1973)'; 10107 10108 case 'csiso60danishnorwegian': 10109 case 'csiso60norwegian1': 10110 case 'iso646no': 10111 case 'isoir60': 10112 case 'no': 10113 case 'ns45511': 10114 return 'NS_4551-1'; 10115 10116 case 'csiso61norwegian2': 10117 case 'iso646no2': 10118 case 'isoir61': 10119 case 'no2': 10120 case 'ns45512': 10121 return 'NS_4551-2'; 10122 10123 case 'osdebcdicdf3irv': 10124 return 'OSD_EBCDIC_DF03_IRV'; 10125 10126 case 'osdebcdicdf41': 10127 return 'OSD_EBCDIC_DF04_1'; 10128 10129 case 'osdebcdicdf415': 10130 return 'OSD_EBCDIC_DF04_15'; 10131 10132 case 'cspc8danishnorwegian': 10133 case 'pc8danishnorwegian': 10134 return 'PC8-Danish-Norwegian'; 10135 10136 case 'cspc8turkish': 10137 case 'pc8turkish': 10138 return 'PC8-Turkish'; 10139 10140 case 'csiso16portuguese': 10141 case 'iso646pt': 10142 case 'isoir16': 10143 case 'pt': 10144 return 'PT'; 10145 10146 case 'csiso84portuguese2': 10147 case 'iso646pt2': 10148 case 'isoir84': 10149 case 'pt2': 10150 return 'PT2'; 10151 10152 case 'cp154': 10153 case 'csptcp154': 10154 case 'cyrillicasian': 10155 case 'pt154': 10156 case 'ptcp154': 10157 return 'PTCP154'; 10158 10159 case 'scsu': 10160 return 'SCSU'; 10161 10162 case 'csiso10swedish': 10163 case 'fi': 10164 case 'iso646fi': 10165 case 'iso646se': 10166 case 'isoir10': 10167 case 'se': 10168 case 'sen850200b': 10169 return 'SEN_850200_B'; 10170 10171 case 'csiso11swedishfornames': 10172 case 'iso646se2': 10173 case 'isoir11': 10174 case 'se2': 10175 case 'sen850200c': 10176 return 'SEN_850200_C'; 10177 10178 case 'csiso102t617bit': 10179 case 'isoir102': 10180 case 't617bit': 10181 return 'T.61-7bit'; 10182 10183 case 'csiso103t618bit': 10184 case 'isoir103': 10185 case 't61': 10186 case 't618bit': 10187 return 'T.61-8bit'; 10188 10189 case 'csiso128t101g2': 10190 case 'isoir128': 10191 case 't101g2': 10192 return 'T.101-G2'; 10193 10194 case 'cstscii': 10195 case 'tscii': 10196 return 'TSCII'; 10197 10198 case 'csunicode11': 10199 case 'unicode11': 10200 return 'UNICODE-1-1'; 10201 10202 case 'csunicode11utf7': 10203 case 'unicode11utf7': 10204 return 'UNICODE-1-1-UTF-7'; 10205 10206 case 'csunknown8bit': 10207 case 'unknown8bit': 10208 return 'UNKNOWN-8BIT'; 10209 10210 case 'ansix341968': 10211 case 'ansix341986': 10212 case 'ascii': 10213 case 'cp367': 10214 case 'csascii': 10215 case 'ibm367': 10216 case 'iso646irv1991': 10217 case 'iso646us': 10218 case 'isoir6': 10219 case 'us': 10220 case 'usascii': 10221 return 'US-ASCII'; 10222 10223 case 'csusdk': 10224 case 'usdk': 10225 return 'us-dk'; 10226 10227 case 'utf7': 10228 return 'UTF-7'; 10229 10230 case 'utf8': 10231 return 'UTF-8'; 10232 10233 case 'utf16': 10234 return 'UTF-16'; 10235 10236 case 'utf16be': 10237 return 'UTF-16BE'; 10238 10239 case 'utf16le': 10240 return 'UTF-16LE'; 10241 10242 case 'utf32': 10243 return 'UTF-32'; 10244 10245 case 'utf32be': 10246 return 'UTF-32BE'; 10247 10248 case 'utf32le': 10249 return 'UTF-32LE'; 10250 10251 case 'csventurainternational': 10252 case 'venturainternational': 10253 return 'Ventura-International'; 10254 10255 case 'csventuramath': 10256 case 'venturamath': 10257 return 'Ventura-Math'; 10258 10259 case 'csventuraus': 10260 case 'venturaus': 10261 return 'Ventura-US'; 10262 10263 case 'csiso70videotexsupp1': 10264 case 'isoir70': 10265 case 'videotexsuppl': 10266 return 'videotex-suppl'; 10267 10268 case 'csviqr': 10269 case 'viqr': 10270 return 'VIQR'; 10271 10272 case 'csviscii': 10273 case 'viscii': 10274 return 'VISCII'; 10275 10276 case 'csshiftjis': 10277 case 'cswindows31j': 10278 case 'mskanji': 10279 case 'shiftjis': 10280 case 'windows31j': 10281 return 'Windows-31J'; 10282 10283 case 'iso885911': 10284 case 'tis620': 10285 return 'windows-874'; 10286 10287 case 'cseuckr': 10288 case 'csksc56011987': 10289 case 'euckr': 10290 case 'isoir149': 10291 case 'korean': 10292 case 'ksc5601': 10293 case 'ksc56011987': 10294 case 'ksc56011989': 10295 case 'windows949': 10296 return 'windows-949'; 10297 10298 case 'windows1250': 10299 return 'windows-1250'; 10300 10301 case 'windows1251': 10302 return 'windows-1251'; 10303 10304 case 'cp819': 10305 case 'csisolatin1': 10306 case 'ibm819': 10307 case 'iso88591': 10308 case 'iso885911987': 10309 case 'isoir100': 10310 case 'l1': 10311 case 'latin1': 10312 case 'windows1252': 10313 return 'windows-1252'; 10314 10315 case 'windows1253': 10316 return 'windows-1253'; 10317 10318 case 'csisolatin5': 10319 case 'iso88599': 10320 case 'iso885991989': 10321 case 'isoir148': 10322 case 'l5': 10323 case 'latin5': 10324 case 'windows1254': 10325 return 'windows-1254'; 10326 10327 case 'windows1255': 10328 return 'windows-1255'; 10329 10330 case 'windows1256': 10331 return 'windows-1256'; 10332 10333 case 'windows1257': 10334 return 'windows-1257'; 10335 10336 case 'windows1258': 10337 return 'windows-1258'; 10338 10339 default: 10340 return $charset; 10341 } 10342 } 10343 10344 public static function get_curl_version() 10345 { 10346 if (is_array($curl = curl_version())) 10347 { 10348 $curl = $curl['version']; 10349 } 10350 elseif (substr($curl, 0, 5) === 'curl/') 10351 { 10352 $curl = substr($curl, 5, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 5)); 10353 } 10354 elseif (substr($curl, 0, 8) === 'libcurl/') 10355 { 10356 $curl = substr($curl, 8, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 8)); 10357 } 10358 else 10359 { 10360 $curl = 0; 10361 } 10362 return $curl; 10363 } 10364 10365 public static function is_subclass_of($class1, $class2) 10366 { 10367 if (func_num_args() !== 2) 10368 { 10369 trigger_error('Wrong parameter count for SimplePie_Misc::is_subclass_of()', E_USER_WARNING); 10370 } 10371 elseif (version_compare(PHP_VERSION, '5.0.3', '>=') || is_object($class1)) 10372 { 10373 return is_subclass_of($class1, $class2); 10374 } 10375 elseif (is_string($class1) && is_string($class2)) 10376 { 10377 if (class_exists($class1)) 10378 { 10379 if (class_exists($class2)) 10380 { 10381 $class2 = strtolower($class2); 10382 while ($class1 = strtolower(get_parent_class($class1))) 10383 { 10384 if ($class1 === $class2) 10385 { 10386 return true; 10387 } 10388 } 10389 } 10390 } 10391 else 10392 { 10393 trigger_error('Unknown class passed as parameter', E_USER_WARNNG); 10394 } 10395 } 10396 return false; 10397 } 10398 10406 public static function strip_comments($data) 10407 { 10408 $output = ''; 10409 while (($start = strpos($data, '<!--')) !== false) 10410 { 10411 $output .= substr($data, 0, $start); 10412 if (($end = strpos($data, '-->', $start)) !== false) 10413 { 10414 $data = substr_replace($data, '', 0, $end + 3); 10415 } 10416 else 10417 { 10418 $data = ''; 10419 } 10420 } 10421 return $output . $data; 10422 } 10423 10424 public static function parse_date($dt) 10425 { 10426 $parser = SimplePie_Parse_Date::get(); 10427 return $parser->parse($dt); 10428 } 10429 10438 public static function entities_decode($data) 10439 { 10440 $decoder = new SimplePie_Decode_HTML_Entities($data); 10441 return $decoder->parse(); 10442 } 10443 10451 public static function uncomment_rfc822($string) 10452 { 10453 $string = (string) $string; 10454 $position = 0; 10455 $length = strlen($string); 10456 $depth = 0; 10457 10458 $output = ''; 10459 10460 while ($position < $length && ($pos = strpos($string, '(', $position)) !== false) 10461 { 10462 $output .= substr($string, $position, $pos - $position); 10463 $position = $pos + 1; 10464 if ($string[$pos - 1] !== '\\') 10465 { 10466 $depth++; 10467 while ($depth && $position < $length) 10468 { 10469 $position += strcspn($string, '()', $position); 10470 if ($string[$position - 1] === '\\') 10471 { 10472 $position++; 10473 continue; 10474 } 10475 elseif (isset($string[$position])) 10476 { 10477 switch ($string[$position]) 10478 { 10479 case '(': 10480 $depth++; 10481 break; 10482 10483 case ')': 10484 $depth--; 10485 break; 10486 } 10487 $position++; 10488 } 10489 else 10490 { 10491 break; 10492 } 10493 } 10494 } 10495 else 10496 { 10497 $output .= '('; 10498 } 10499 } 10500 $output .= substr($string, $position); 10501 10502 return $output; 10503 } 10504 10505 public static function parse_mime($mime) 10506 { 10507 if (($pos = strpos($mime, ';')) === false) 10508 { 10509 return trim($mime); 10510 } 10511 else 10512 { 10513 return trim(substr($mime, 0, $pos)); 10514 } 10515 } 10516 10517 public static function htmlspecialchars_decode($string, $quote_style) 10518 { 10519 if (function_exists('htmlspecialchars_decode')) 10520 { 10521 return htmlspecialchars_decode($string, $quote_style); 10522 } 10523 else 10524 { 10525 return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style))); 10526 } 10527 } 10528 10529 public static function atom_03_construct_type($attribs) 10530 { 10531 if (isset($attribs['']['mode']) && strtolower(trim($attribs['']['mode']) === 'base64')) 10532 { 10533 $mode = SIMPLEPIE_CONSTRUCT_BASE64; 10534 } 10535 else 10536 { 10537 $mode = SIMPLEPIE_CONSTRUCT_NONE; 10538 } 10539 if (isset($attribs['']['type'])) 10540 { 10541 switch (strtolower(trim($attribs['']['type']))) 10542 { 10543 case 'text': 10544 case 'text/plain': 10545 return SIMPLEPIE_CONSTRUCT_TEXT | $mode; 10546 10547 case 'html': 10548 case 'text/html': 10549 return SIMPLEPIE_CONSTRUCT_HTML | $mode; 10550 10551 case 'xhtml': 10552 case 'application/xhtml+xml': 10553 return SIMPLEPIE_CONSTRUCT_XHTML | $mode; 10554 10555 default: 10556 return SIMPLEPIE_CONSTRUCT_NONE | $mode; 10557 } 10558 } 10559 else 10560 { 10561 return SIMPLEPIE_CONSTRUCT_TEXT | $mode; 10562 } 10563 } 10564 10565 public static function atom_10_construct_type($attribs) 10566 { 10567 if (isset($attribs['']['type'])) 10568 { 10569 switch (strtolower(trim($attribs['']['type']))) 10570 { 10571 case 'text': 10572 return SIMPLEPIE_CONSTRUCT_TEXT; 10573 10574 case 'html': 10575 return SIMPLEPIE_CONSTRUCT_HTML; 10576 10577 case 'xhtml': 10578 return SIMPLEPIE_CONSTRUCT_XHTML; 10579 10580 default: 10581 return SIMPLEPIE_CONSTRUCT_NONE; 10582 } 10583 } 10584 return SIMPLEPIE_CONSTRUCT_TEXT; 10585 } 10586 10587 public static function atom_10_content_construct_type($attribs) 10588 { 10589 if (isset($attribs['']['type'])) 10590 { 10591 $type = strtolower(trim($attribs['']['type'])); 10592 switch ($type) 10593 { 10594 case 'text': 10595 return SIMPLEPIE_CONSTRUCT_TEXT; 10596 10597 case 'html': 10598 return SIMPLEPIE_CONSTRUCT_HTML; 10599 10600 case 'xhtml': 10601 return SIMPLEPIE_CONSTRUCT_XHTML; 10602 } 10603 if (in_array(substr($type, -4), array('+xml', '/xml')) || substr($type, 0, 5) === 'text/') 10604 { 10605 return SIMPLEPIE_CONSTRUCT_NONE; 10606 } 10607 else 10608 { 10609 return SIMPLEPIE_CONSTRUCT_BASE64; 10610 } 10611 } 10612 else 10613 { 10614 return SIMPLEPIE_CONSTRUCT_TEXT; 10615 } 10616 } 10617 10618 public static function is_isegment_nz_nc($string) 10619 { 10620 return (bool) preg_match('/^([A-Za-z0-9\-._~\x{A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}\x{10000}-\x{1FFFD}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}\x{40000}-\x{4FFFD}\x{50000}-\x{5FFFD}\x{60000}-\x{6FFFD}\x{70000}-\x{7FFFD}\x{80000}-\x{8FFFD}\x{90000}-\x{9FFFD}\x{A0000}-\x{AFFFD}\x{B0000}-\x{BFFFD}\x{C0000}-\x{CFFFD}\x{D0000}-\x{DFFFD}\x{E1000}-\x{EFFFD}!$&\'()*+,;=@]|(%[0-9ABCDEF]{2}))+$/u', $string); 10621 } 10622 10623 public static function space_seperated_tokens($string) 10624 { 10625 $space_characters = "\x20\x09\x0A\x0B\x0C\x0D"; 10626 $string_length = strlen($string); 10627 10628 $position = strspn($string, $space_characters); 10629 $tokens = array(); 10630 10631 while ($position < $string_length) 10632 { 10633 $len = strcspn($string, $space_characters, $position); 10634 $tokens[] = substr($string, $position, $len); 10635 $position += $len; 10636 $position += strspn($string, $space_characters, $position); 10637 } 10638 10639 return $tokens; 10640 } 10641 10642 public static function array_unique($array) 10643 { 10644 if (version_compare(PHP_VERSION, '5.2', '>=')) 10645 { 10646 return array_unique($array); 10647 } 10648 else 10649 { 10650 $array = (array) $array; 10651 $new_array = array(); 10652 $new_array_strings = array(); 10653 foreach ($array as $key => $value) 10654 { 10655 if (is_object($value)) 10656 { 10657 if (method_exists($value, '__toString')) 10658 { 10659 $cmp = $value->__toString(); 10660 } 10661 else 10662 { 10663 trigger_error('Object of class ' . get_class($value) . ' could not be converted to string', E_USER_ERROR); 10664 } 10665 } 10666 elseif (is_array($value)) 10667 { 10668 $cmp = (string) reset($value); 10669 } 10670 else 10671 { 10672 $cmp = (string) $value; 10673 } 10674 if (!in_array($cmp, $new_array_strings)) 10675 { 10676 $new_array[$key] = $value; 10677 $new_array_strings[] = $cmp; 10678 } 10679 } 10680 return $new_array; 10681 } 10682 } 10683 10692 public static function codepoint_to_utf8($codepoint) 10693 { 10694 $codepoint = (int) $codepoint; 10695 if ($codepoint < 0) 10696 { 10697 return false; 10698 } 10699 else if ($codepoint <= 0x7f) 10700 { 10701 return chr($codepoint); 10702 } 10703 else if ($codepoint <= 0x7ff) 10704 { 10705 return chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f)); 10706 } 10707 else if ($codepoint <= 0xffff) 10708 { 10709 return chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f)); 10710 } 10711 else if ($codepoint <= 0x10ffff) 10712 { 10713 return chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f)); 10714 } 10715 else 10716 { 10717 // U+FFFD REPLACEMENT CHARACTER 10718 return "\xEF\xBF\xBD"; 10719 } 10720 } 10721 10733 public static function parse_str($str) 10734 { 10735 $return = array(); 10736 $str = explode('&', $str); 10737 10738 foreach ($str as $section) 10739 { 10740 if (strpos($section, '=') !== false) 10741 { 10742 list($name, $value) = explode('=', $section, 2); 10743 $return[urldecode($name)][] = urldecode($value); 10744 } 10745 else 10746 { 10747 $return[urldecode($section)][] = null; 10748 } 10749 } 10750 10751 return $return; 10752 } 10753 10761 public static function xml_encoding($data) 10762 { 10763 // UTF-32 Big Endian BOM 10764 if (substr($data, 0, 4) === "\x00\x00\xFE\xFF") 10765 { 10766 $encoding[] = 'UTF-32BE'; 10767 } 10768 // UTF-32 Little Endian BOM 10769 elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00") 10770 { 10771 $encoding[] = 'UTF-32LE'; 10772 } 10773 // UTF-16 Big Endian BOM 10774 elseif (substr($data, 0, 2) === "\xFE\xFF") 10775 { 10776 $encoding[] = 'UTF-16BE'; 10777 } 10778 // UTF-16 Little Endian BOM 10779 elseif (substr($data, 0, 2) === "\xFF\xFE") 10780 { 10781 $encoding[] = 'UTF-16LE'; 10782 } 10783 // UTF-8 BOM 10784 elseif (substr($data, 0, 3) === "\xEF\xBB\xBF") 10785 { 10786 $encoding[] = 'UTF-8'; 10787 } 10788 // UTF-32 Big Endian Without BOM 10789 elseif (substr($data, 0, 20) === "\x00\x00\x00\x3C\x00\x00\x00\x3F\x00\x00\x00\x78\x00\x00\x00\x6D\x00\x00\x00\x6C") 10790 { 10791 if ($pos = strpos($data, "\x00\x00\x00\x3F\x00\x00\x00\x3E")) 10792 { 10793 $parser = new SimplePie_XML_Declaration_Parser(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32BE', 'UTF-8')); 10794 if ($parser->parse()) 10795 { 10796 $encoding[] = $parser->encoding; 10797 } 10798 } 10799 $encoding[] = 'UTF-32BE'; 10800 } 10801 // UTF-32 Little Endian Without BOM 10802 elseif (substr($data, 0, 20) === "\x3C\x00\x00\x00\x3F\x00\x00\x00\x78\x00\x00\x00\x6D\x00\x00\x00\x6C\x00\x00\x00") 10803 { 10804 if ($pos = strpos($data, "\x3F\x00\x00\x00\x3E\x00\x00\x00")) 10805 { 10806 $parser = new SimplePie_XML_Declaration_Parser(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32LE', 'UTF-8')); 10807 if ($parser->parse()) 10808 { 10809 $encoding[] = $parser->encoding; 10810 } 10811 } 10812 $encoding[] = 'UTF-32LE'; 10813 } 10814 // UTF-16 Big Endian Without BOM 10815 elseif (substr($data, 0, 10) === "\x00\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C") 10816 { 10817 if ($pos = strpos($data, "\x00\x3F\x00\x3E")) 10818 { 10819 $parser = new SimplePie_XML_Declaration_Parser(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16BE', 'UTF-8')); 10820 if ($parser->parse()) 10821 { 10822 $encoding[] = $parser->encoding; 10823 } 10824 } 10825 $encoding[] = 'UTF-16BE'; 10826 } 10827 // UTF-16 Little Endian Without BOM 10828 elseif (substr($data, 0, 10) === "\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C\x00") 10829 { 10830 if ($pos = strpos($data, "\x3F\x00\x3E\x00")) 10831 { 10832 $parser = new SimplePie_XML_Declaration_Parser(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16LE', 'UTF-8')); 10833 if ($parser->parse()) 10834 { 10835 $encoding[] = $parser->encoding; 10836 } 10837 } 10838 $encoding[] = 'UTF-16LE'; 10839 } 10840 // US-ASCII (or superset) 10841 elseif (substr($data, 0, 5) === "\x3C\x3F\x78\x6D\x6C") 10842 { 10843 if ($pos = strpos($data, "\x3F\x3E")) 10844 { 10845 $parser = new SimplePie_XML_Declaration_Parser(substr($data, 5, $pos - 5)); 10846 if ($parser->parse()) 10847 { 10848 $encoding[] = $parser->encoding; 10849 } 10850 } 10851 $encoding[] = 'UTF-8'; 10852 } 10853 // Fallback to UTF-8 10854 else 10855 { 10856 $encoding[] = 'UTF-8'; 10857 } 10858 return $encoding; 10859 } 10860 10861 public static function output_javascript() 10862 { 10863 if (function_exists('ob_gzhandler')) 10864 { 10865 ob_start('ob_gzhandler'); 10866 } 10867 header('Content-type: text/javascript; charset: UTF-8'); 10868 header('Cache-Control: must-revalidate'); 10869 header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days 10870 ?> 10871 function embed_odeo(link) { 10872 document.writeln('<embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="440" height="80" wmode="transparent" allowScriptAccess="any" flashvars="valid_sample_rate=true&external_url='+link+'"></embed>'); 10873 } 10874 10875 function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) { 10876 if (placeholder != '') { 10877 document.writeln('<embed type="'+type+'" style="cursor:hand; cursor:pointer;" href="'+link+'" src="'+placeholder+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="false" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed>'); 10878 } 10879 else { 10880 document.writeln('<embed type="'+type+'" style="cursor:hand; cursor:pointer;" src="'+link+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="true" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed>'); 10881 } 10882 } 10883 10884 function embed_flash(bgcolor, width, height, link, loop, type) { 10885 document.writeln('<embed src="'+link+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="'+type+'" quality="high" width="'+width+'" height="'+height+'" bgcolor="'+bgcolor+'" loop="'+loop+'"></embed>'); 10886 } 10887 10888 function embed_flv(width, height, link, placeholder, loop, player) { 10889 document.writeln('<embed src="'+player+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="'+width+'" height="'+height+'" wmode="transparent" flashvars="file='+link+'&autostart=false&repeat='+loop+'&showdigits=true&showfsbutton=false"></embed>'); 10890 } 10891 10892 function embed_wmedia(width, height, link) { 10893 document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>'); 10894 } 10895 <?php 10896 } 10897 } 10898 10906 class SimplePie_Decode_HTML_Entities 10907 { 10914 var $data = ''; 10915 10922 var $consumed = ''; 10923 10930 var $position = 0; 10931 10938 public function __construct($data) 10939 { 10940 $this->data = $data; 10941 } 10942 10949 public function parse() 10950 { 10951 while (($this->position = strpos($this->data, '&', $this->position)) !== false) 10952 { 10953 $this->consume(); 10954 $this->entity(); 10955 $this->consumed = ''; 10956 } 10957 return $this->data; 10958 } 10959 10966 public function consume() 10967 { 10968 if (isset($this->data[$this->position])) 10969 { 10970 $this->consumed .= $this->data[$this->position]; 10971 return $this->data[$this->position++]; 10972 } 10973 else 10974 { 10975 return false; 10976 } 10977 } 10978 10986 public function consume_range($chars) 10987 { 10988 if ($len = strspn($this->data, $chars, $this->position)) 10989 { 10990 $data = substr($this->data, $this->position, $len); 10991 $this->consumed .= $data; 10992 $this->position += $len; 10993 return $data; 10994 } 10995 else 10996 { 10997 return false; 10998 } 10999 } 11000 11006 public function unconsume() 11007 { 11008 $this->consumed = substr($this->consumed, 0, -1); 11009 $this->position--; 11010 } 11011 11017 public function entity() 11018 { 11019 switch ($this->consume()) 11020 { 11021 case "\x09": 11022 case "\x0A": 11023 case "\x0B": 11024 case "\x0B": 11025 case "\x0C": 11026 case "\x20": 11027 case "\x3C": 11028 case "\x26": 11029 case false: 11030 break; 11031 11032 case "\x23": 11033 switch ($this->consume()) 11034 { 11035 case "\x78": 11036 case "\x58": 11037 $range = '0123456789ABCDEFabcdef'; 11038 $hex = true; 11039 break; 11040 11041 default: 11042 $range = '0123456789'; 11043 $hex = false; 11044 $this->unconsume(); 11045 break; 11046 } 11047 11048 if ($codepoint = $this->consume_range($range)) 11049 { 11050 static $windows_1252_specials = array(0x0D => "\x0A", 0x80 => "\xE2\x82\xAC", 0x81 => "\xEF\xBF\xBD", 0x82 => "\xE2\x80\x9A", 0x83 => "\xC6\x92", 0x84 => "\xE2\x80\x9E", 0x85 => "\xE2\x80\xA6", 0x86 => "\xE2\x80\xA0", 0x87 => "\xE2\x80\xA1", 0x88 => "\xCB\x86", 0x89 => "\xE2\x80\xB0", 0x8A => "\xC5\xA0", 0x8B => "\xE2\x80\xB9", 0x8C => "\xC5\x92", 0x8D => "\xEF\xBF\xBD", 0x8E => "\xC5\xBD", 0x8F => "\xEF\xBF\xBD", 0x90 => "\xEF\xBF\xBD", 0x91 => "\xE2\x80\x98", 0x92 => "\xE2\x80\x99", 0x93 => "\xE2\x80\x9C", 0x94 => "\xE2\x80\x9D", 0x95 => "\xE2\x80\xA2", 0x96 => "\xE2\x80\x93", 0x97 => "\xE2\x80\x94", 0x98 => "\xCB\x9C", 0x99 => "\xE2\x84\xA2", 0x9A => "\xC5\xA1", 0x9B => "\xE2\x80\xBA", 0x9C => "\xC5\x93", 0x9D => "\xEF\xBF\xBD", 0x9E => "\xC5\xBE", 0x9F => "\xC5\xB8"); 11051 11052 if ($hex) 11053 { 11054 $codepoint = hexdec($codepoint); 11055 } 11056 else 11057 { 11058 $codepoint = intval($codepoint); 11059 } 11060 11061 if (isset($windows_1252_specials[$codepoint])) 11062 { 11063 $replacement = $windows_1252_specials[$codepoint]; 11064 } 11065 else 11066 { 11067 $replacement = SimplePie_Misc::codepoint_to_utf8($codepoint); 11068 } 11069 11070 if (!in_array($this->consume(), array(';', false), true)) 11071 { 11072 $this->unconsume(); 11073 } 11074 11075 $consumed_length = strlen($this->consumed); 11076 $this->data = substr_replace($this->data, $replacement, $this->position - $consumed_length, $consumed_length); 11077 $this->position += strlen($replacement) - $consumed_length; 11078 } 11079 break; 11080 11081 default: 11082 static $entities = array('Aacute' => "\xC3\x81", 'aacute' => "\xC3\xA1", 'Aacute;' => "\xC3\x81", 'aacute;' => "\xC3\xA1", 'Acirc' => "\xC3\x82", 'acirc' => "\xC3\xA2", 'Acirc;' => "\xC3\x82", 'acirc;' => "\xC3\xA2", 'acute' => "\xC2\xB4", 'acute;' => "\xC2\xB4", 'AElig' => "\xC3\x86", 'aelig' => "\xC3\xA6", 'AElig;' => "\xC3\x86", 'aelig;' => "\xC3\xA6", 'Agrave' => "\xC3\x80", 'agrave' => "\xC3\xA0", 'Agrave;' => "\xC3\x80", 'agrave;' => "\xC3\xA0", 'alefsym;' => "\xE2\x84\xB5", 'Alpha;' => "\xCE\x91", 'alpha;' => "\xCE\xB1", 'AMP' => "\x26", 'amp' => "\x26", 'AMP;' => "\x26", 'amp;' => "\x26", 'and;' => "\xE2\x88\xA7", 'ang;' => "\xE2\x88\xA0", 'apos;' => "\x27", 'Aring' => "\xC3\x85", 'aring' => "\xC3\xA5", 'Aring;' => "\xC3\x85", 'aring;' => "\xC3\xA5", 'asymp;' => "\xE2\x89\x88", 'Atilde' => "\xC3\x83", 'atilde' => "\xC3\xA3", 'Atilde;' => "\xC3\x83", 'atilde;' => "\xC3\xA3", 'Auml' => "\xC3\x84", 'auml' => "\xC3\xA4", 'Auml;' => "\xC3\x84", 'auml;' => "\xC3\xA4", 'bdquo;' => "\xE2\x80\x9E", 'Beta;' => "\xCE\x92", 'beta;' => "\xCE\xB2", 'brvbar' => "\xC2\xA6", 'brvbar;' => "\xC2\xA6", 'bull;' => "\xE2\x80\xA2", 'cap;' => "\xE2\x88\xA9", 'Ccedil' => "\xC3\x87", 'ccedil' => "\xC3\xA7", 'Ccedil;' => "\xC3\x87", 'ccedil;' => "\xC3\xA7", 'cedil' => "\xC2\xB8", 'cedil;' => "\xC2\xB8", 'cent' => "\xC2\xA2", 'cent;' => "\xC2\xA2", 'Chi;' => "\xCE\xA7", 'chi;' => "\xCF\x87", 'circ;' => "\xCB\x86", 'clubs;' => "\xE2\x99\xA3", 'cong;' => "\xE2\x89\x85", 'COPY' => "\xC2\xA9", 'copy' => "\xC2\xA9", 'COPY;' => "\xC2\xA9", 'copy;' => "\xC2\xA9", 'crarr;' => "\xE2\x86\xB5", 'cup;' => "\xE2\x88\xAA", 'curren' => "\xC2\xA4", 'curren;' => "\xC2\xA4", 'Dagger;' => "\xE2\x80\xA1", 'dagger;' => "\xE2\x80\xA0", 'dArr;' => "\xE2\x87\x93", 'darr;' => "\xE2\x86\x93", 'deg' => "\xC2\xB0", 'deg;' => "\xC2\xB0", 'Delta;' => "\xCE\x94", 'delta;' => "\xCE\xB4", 'diams;' => "\xE2\x99\xA6", 'divide' => "\xC3\xB7", 'divide;' => "\xC3\xB7", 'Eacute' => "\xC3\x89", 'eacute' => "\xC3\xA9", 'Eacute;' => "\xC3\x89", 'eacute;' => "\xC3\xA9", 'Ecirc' => "\xC3\x8A", 'ecirc' => "\xC3\xAA", 'Ecirc;' => "\xC3\x8A", 'ecirc;' => "\xC3\xAA", 'Egrave' => "\xC3\x88", 'egrave' => "\xC3\xA8", 'Egrave;' => "\xC3\x88", 'egrave;' => "\xC3\xA8", 'empty;' => "\xE2\x88\x85", 'emsp;' => "\xE2\x80\x83", 'ensp;' => "\xE2\x80\x82", 'Epsilon;' => "\xCE\x95", 'epsilon;' => "\xCE\xB5", 'equiv;' => "\xE2\x89\xA1", 'Eta;' => "\xCE\x97", 'eta;' => "\xCE\xB7", 'ETH' => "\xC3\x90", 'eth' => "\xC3\xB0", 'ETH;' => "\xC3\x90", 'eth;' => "\xC3\xB0", 'Euml' => "\xC3\x8B", 'euml' => "\xC3\xAB", 'Euml;' => "\xC3\x8B", 'euml;' => "\xC3\xAB", 'euro;' => "\xE2\x82\xAC", 'exist;' => "\xE2\x88\x83", 'fnof;' => "\xC6\x92", 'forall;' => "\xE2\x88\x80", 'frac12' => "\xC2\xBD", 'frac12;' => "\xC2\xBD", 'frac14' => "\xC2\xBC", 'frac14;' => "\xC2\xBC", 'frac34' => "\xC2\xBE", 'frac34;' => "\xC2\xBE", 'frasl;' => "\xE2\x81\x84", 'Gamma;' => "\xCE\x93", 'gamma;' => "\xCE\xB3", 'ge;' => "\xE2\x89\xA5", 'GT' => "\x3E", 'gt' => "\x3E", 'GT;' => "\x3E", 'gt;' => "\x3E", 'hArr;' => "\xE2\x87\x94", 'harr;' => "\xE2\x86\x94", 'hearts;' => "\xE2\x99\xA5", 'hellip;' => "\xE2\x80\xA6", 'Iacute' => "\xC3\x8D", 'iacute' => "\xC3\xAD", 'Iacute;' => "\xC3\x8D", 'iacute;' => "\xC3\xAD", 'Icirc' => "\xC3\x8E", 'icirc' => "\xC3\xAE", 'Icirc;' => "\xC3\x8E", 'icirc;' => "\xC3\xAE", 'iexcl' => "\xC2\xA1", 'iexcl;' => "\xC2\xA1", 'Igrave' => "\xC3\x8C", 'igrave' => "\xC3\xAC", 'Igrave;' => "\xC3\x8C", 'igrave;' => "\xC3\xAC", 'image;' => "\xE2\x84\x91", 'infin;' => "\xE2\x88\x9E", 'int;' => "\xE2\x88\xAB", 'Iota;' => "\xCE\x99", 'iota;' => "\xCE\xB9", 'iquest' => "\xC2\xBF", 'iquest;' => "\xC2\xBF", 'isin;' => "\xE2\x88\x88", 'Iuml' => "\xC3\x8F", 'iuml' => "\xC3\xAF", 'Iuml;' => "\xC3\x8F", 'iuml;' => "\xC3\xAF", 'Kappa;' => "\xCE\x9A", 'kappa;' => "\xCE\xBA", 'Lambda;' => "\xCE\x9B", 'lambda;' => "\xCE\xBB", 'lang;' => "\xE3\x80\x88", 'laquo' => "\xC2\xAB", 'laquo;' => "\xC2\xAB", 'lArr;' => "\xE2\x87\x90", 'larr;' => "\xE2\x86\x90", 'lceil;' => "\xE2\x8C\x88", 'ldquo;' => "\xE2\x80\x9C", 'le;' => "\xE2\x89\xA4", 'lfloor;' => "\xE2\x8C\x8A", 'lowast;' => "\xE2\x88\x97", 'loz;' => "\xE2\x97\x8A", 'lrm;' => "\xE2\x80\x8E", 'lsaquo;' => "\xE2\x80\xB9", 'lsquo;' => "\xE2\x80\x98", 'LT' => "\x3C", 'lt' => "\x3C", 'LT;' => "\x3C", 'lt;' => "\x3C", 'macr' => "\xC2\xAF", 'macr;' => "\xC2\xAF", 'mdash;' => "\xE2\x80\x94", 'micro' => "\xC2\xB5", 'micro;' => "\xC2\xB5", 'middot' => "\xC2\xB7", 'middot;' => "\xC2\xB7", 'minus;' => "\xE2\x88\x92", 'Mu;' => "\xCE\x9C", 'mu;' => "\xCE\xBC", 'nabla;' => "\xE2\x88\x87", 'nbsp' => "\xC2\xA0", 'nbsp;' => "\xC2\xA0", 'ndash;' => "\xE2\x80\x93", 'ne;' => "\xE2\x89\xA0", 'ni;' => "\xE2\x88\x8B", 'not' => "\xC2\xAC", 'not;' => "\xC2\xAC", 'notin;' => "\xE2\x88\x89", 'nsub;' => "\xE2\x8A\x84", 'Ntilde' => "\xC3\x91", 'ntilde' => "\xC3\xB1", 'Ntilde;' => "\xC3\x91", 'ntilde;' => "\xC3\xB1", 'Nu;' => "\xCE\x9D", 'nu;' => "\xCE\xBD", 'Oacute' => "\xC3\x93", 'oacute' => "\xC3\xB3", 'Oacute;' => "\xC3\x93", 'oacute;' => "\xC3\xB3", 'Ocirc' => "\xC3\x94", 'ocirc' => "\xC3\xB4", 'Ocirc;' => "\xC3\x94", 'ocirc;' => "\xC3\xB4", 'OElig;' => "\xC5\x92", 'oelig;' => "\xC5\x93", 'Ograve' => "\xC3\x92", 'ograve' => "\xC3\xB2", 'Ograve;' => "\xC3\x92", 'ograve;' => "\xC3\xB2", 'oline;' => "\xE2\x80\xBE", 'Omega;' => "\xCE\xA9", 'omega;' => "\xCF\x89", 'Omicron;' => "\xCE\x9F", 'omicron;' => "\xCE\xBF", 'oplus;' => "\xE2\x8A\x95", 'or;' => "\xE2\x88\xA8", 'ordf' => "\xC2\xAA", 'ordf;' => "\xC2\xAA", 'ordm' => "\xC2\xBA", 'ordm;' => "\xC2\xBA", 'Oslash' => "\xC3\x98", 'oslash' => "\xC3\xB8", 'Oslash;' => "\xC3\x98", 'oslash;' => "\xC3\xB8", 'Otilde' => "\xC3\x95", 'otilde' => "\xC3\xB5", 'Otilde;' => "\xC3\x95", 'otilde;' => "\xC3\xB5", 'otimes;' => "\xE2\x8A\x97", 'Ouml' => "\xC3\x96", 'ouml' => "\xC3\xB6", 'Ouml;' => "\xC3\x96", 'ouml;' => "\xC3\xB6", 'para' => "\xC2\xB6", 'para;' => "\xC2\xB6", 'part;' => "\xE2\x88\x82", 'permil;' => "\xE2\x80\xB0", 'perp;' => "\xE2\x8A\xA5", 'Phi;' => "\xCE\xA6", 'phi;' => "\xCF\x86", 'Pi;' => "\xCE\xA0", 'pi;' => "\xCF\x80", 'piv;' => "\xCF\x96", 'plusmn' => "\xC2\xB1", 'plusmn;' => "\xC2\xB1", 'pound' => "\xC2\xA3", 'pound;' => "\xC2\xA3", 'Prime;' => "\xE2\x80\xB3", 'prime;' => "\xE2\x80\xB2", 'prod;' => "\xE2\x88\x8F", 'prop;' => "\xE2\x88\x9D", 'Psi;' => "\xCE\xA8", 'psi;' => "\xCF\x88", 'QUOT' => "\x22", 'quot' => "\x22", 'QUOT;' => "\x22", 'quot;' => "\x22", 'radic;' => "\xE2\x88\x9A", 'rang;' => "\xE3\x80\x89", 'raquo' => "\xC2\xBB", 'raquo;' => "\xC2\xBB", 'rArr;' => "\xE2\x87\x92", 'rarr;' => "\xE2\x86\x92", 'rceil;' => "\xE2\x8C\x89", 'rdquo;' => "\xE2\x80\x9D", 'real;' => "\xE2\x84\x9C", 'REG' => "\xC2\xAE", 'reg' => "\xC2\xAE", 'REG;' => "\xC2\xAE", 'reg;' => "\xC2\xAE", 'rfloor;' => "\xE2\x8C\x8B", 'Rho;' => "\xCE\xA1", 'rho;' => "\xCF\x81", 'rlm;' => "\xE2\x80\x8F", 'rsaquo;' => "\xE2\x80\xBA", 'rsquo;' => "\xE2\x80\x99", 'sbquo;' => "\xE2\x80\x9A", 'Scaron;' => "\xC5\xA0", 'scaron;' => "\xC5\xA1", 'sdot;' => "\xE2\x8B\x85", 'sect' => "\xC2\xA7", 'sect;' => "\xC2\xA7", 'shy' => "\xC2\xAD", 'shy;' => "\xC2\xAD", 'Sigma;' => "\xCE\xA3", 'sigma;' => "\xCF\x83", 'sigmaf;' => "\xCF\x82", 'sim;' => "\xE2\x88\xBC", 'spades;' => "\xE2\x99\xA0", 'sub;' => "\xE2\x8A\x82", 'sube;' => "\xE2\x8A\x86", 'sum;' => "\xE2\x88\x91", 'sup;' => "\xE2\x8A\x83", 'sup1' => "\xC2\xB9", 'sup1;' => "\xC2\xB9", 'sup2' => "\xC2\xB2", 'sup2;' => "\xC2\xB2", 'sup3' => "\xC2\xB3", 'sup3;' => "\xC2\xB3", 'supe;' => "\xE2\x8A\x87", 'szlig' => "\xC3\x9F", 'szlig;' => "\xC3\x9F", 'Tau;' => "\xCE\xA4", 'tau;' => "\xCF\x84", 'there4;' => "\xE2\x88\xB4", 'Theta;' => "\xCE\x98", 'theta;' => "\xCE\xB8", 'thetasym;' => "\xCF\x91", 'thinsp;' => "\xE2\x80\x89", 'THORN' => "\xC3\x9E", 'thorn' => "\xC3\xBE", 'THORN;' => "\xC3\x9E", 'thorn;' => "\xC3\xBE", 'tilde;' => "\xCB\x9C", 'times' => "\xC3\x97", 'times;' => "\xC3\x97", 'TRADE;' => "\xE2\x84\xA2", 'trade;' => "\xE2\x84\xA2", 'Uacute' => "\xC3\x9A", 'uacute' => "\xC3\xBA", 'Uacute;' => "\xC3\x9A", 'uacute;' => "\xC3\xBA", 'uArr;' => "\xE2\x87\x91", 'uarr;' => "\xE2\x86\x91", 'Ucirc' => "\xC3\x9B", 'ucirc' => "\xC3\xBB", 'Ucirc;' => "\xC3\x9B", 'ucirc;' => "\xC3\xBB", 'Ugrave' => "\xC3\x99", 'ugrave' => "\xC3\xB9", 'Ugrave;' => "\xC3\x99", 'ugrave;' => "\xC3\xB9", 'uml' => "\xC2\xA8", 'uml;' => "\xC2\xA8", 'upsih;' => "\xCF\x92", 'Upsilon;' => "\xCE\xA5", 'upsilon;' => "\xCF\x85", 'Uuml' => "\xC3\x9C", 'uuml' => "\xC3\xBC", 'Uuml;' => "\xC3\x9C", 'uuml;' => "\xC3\xBC", 'weierp;' => "\xE2\x84\x98", 'Xi;' => "\xCE\x9E", 'xi;' => "\xCE\xBE", 'Yacute' => "\xC3\x9D", 'yacute' => "\xC3\xBD", 'Yacute;' => "\xC3\x9D", 'yacute;' => "\xC3\xBD", 'yen' => "\xC2\xA5", 'yen;' => "\xC2\xA5", 'yuml' => "\xC3\xBF", 'Yuml;' => "\xC5\xB8", 'yuml;' => "\xC3\xBF", 'Zeta;' => "\xCE\x96", 'zeta;' => "\xCE\xB6", 'zwj;' => "\xE2\x80\x8D", 'zwnj;' => "\xE2\x80\x8C"); 11083 11084 for ($i = 0, $match = null; $i < 9 && $this->consume() !== false; $i++) 11085 { 11086 $consumed = substr($this->consumed, 1); 11087 if (isset($entities[$consumed])) 11088 { 11089 $match = $consumed; 11090 } 11091 } 11092 11093 if ($match !== null) 11094 { 11095 $this->data = substr_replace($this->data, $entities[$match], $this->position - strlen($consumed) - 1, strlen($match) + 1); 11096 $this->position += strlen($entities[$match]) - strlen($consumed) - 1; 11097 } 11098 break; 11099 } 11100 } 11101 } 11102 11108 class SimplePie_IRI 11109 { 11116 var $scheme; 11117 11124 var $userinfo; 11125 11132 var $host; 11133 11140 var $port; 11141 11148 var $path; 11149 11156 var $query; 11157 11164 var $fragment; 11165 11172 var $valid = array(); 11173 11180 public function __toString() 11181 { 11182 return $this->get_iri(); 11183 } 11184 11192 public function __construct($iri) 11193 { 11194 $iri = (string) $iri; 11195 if ($iri !== '') 11196 { 11197 $parsed = $this->parse_iri($iri); 11198 $this->set_scheme($parsed['scheme']); 11199 $this->set_authority($parsed['authority']); 11200 $this->set_path($parsed['path']); 11201 $this->set_query($parsed['query']); 11202 $this->set_fragment($parsed['fragment']); 11203 } 11204 } 11205 11215 public static function absolutize($base, $relative) 11216 { 11217 $relative = (string) $relative; 11218 if ($relative !== '') 11219 { 11220 $relative = new SimplePie_IRI($relative); 11221 if ($relative->get_scheme() !== null) 11222 { 11223 $target = $relative; 11224 } 11225 elseif ($base->get_iri() !== null) 11226 { 11227 if ($relative->get_authority() !== null) 11228 { 11229 $target = $relative; 11230 $target->set_scheme($base->get_scheme()); 11231 } 11232 else 11233 { 11234 $target = new SimplePie_IRI(''); 11235 $target->set_scheme($base->get_scheme()); 11236 $target->set_userinfo($base->get_userinfo()); 11237 $target->set_host($base->get_host()); 11238 $target->set_port($base->get_port()); 11239 if ($relative->get_path() !== null) 11240 { 11241 if (strpos($relative->get_path(), '/') === 0) 11242 { 11243 $target->set_path($relative->get_path()); 11244 } 11245 elseif (($base->get_userinfo() !== null || $base->get_host() !== null || $base->get_port() !== null) && $base->get_path() === null) 11246 { 11247 $target->set_path('/' . $relative->get_path()); 11248 } 11249 elseif (($last_segment = strrpos($base->get_path(), '/')) !== false) 11250 { 11251 $target->set_path(substr($base->get_path(), 0, $last_segment + 1) . $relative->get_path()); 11252 } 11253 else 11254 { 11255 $target->set_path($relative->get_path()); 11256 } 11257 $target->set_query($relative->get_query()); 11258 } 11259 else 11260 { 11261 $target->set_path($base->get_path()); 11262 if ($relative->get_query() !== null) 11263 { 11264 $target->set_query($relative->get_query()); 11265 } 11266 elseif ($base->get_query() !== null) 11267 { 11268 $target->set_query($base->get_query()); 11269 } 11270 } 11271 } 11272 $target->set_fragment($relative->get_fragment()); 11273 } 11274 else 11275 { 11276 // No base URL, just return the relative URL 11277 $target = $relative; 11278 } 11279 } 11280 else 11281 { 11282 $target = $base; 11283 } 11284 return $target; 11285 } 11286 11294 public function parse_iri($iri) 11295 { 11296 preg_match('/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/', $iri, $match); 11297 for ($i = count($match); $i <= 9; $i++) 11298 { 11299 $match[$i] = ''; 11300 } 11301 return array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => $match[7], 'fragment' => $match[9]); 11302 } 11303 11311 public function remove_dot_segments($input) 11312 { 11313 $output = ''; 11314 while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..') 11315 { 11316 // A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise, 11317 if (strpos($input, '../') === 0) 11318 { 11319 $input = substr($input, 3); 11320 } 11321 elseif (strpos($input, './') === 0) 11322 { 11323 $input = substr($input, 2); 11324 } 11325 // B: if the input buffer begins with a prefix of "/./" or "/.", where "." is a complete path segment, then replace that prefix with "/" in the input buffer; otherwise, 11326 elseif (strpos($input, '/./') === 0) 11327 { 11328 $input = substr_replace($input, '/', 0, 3); 11329 } 11330 elseif ($input === '/.') 11331 { 11332 $input = '/'; 11333 } 11334 // C: if the input buffer begins with a prefix of "/../" or "/..", where ".." is a complete path segment, then replace that prefix with "/" in the input buffer and remove the last segment and its preceding "/" (if any) from the output buffer; otherwise, 11335 elseif (strpos($input, '/../') === 0) 11336 { 11337 $input = substr_replace($input, '/', 0, 4); 11338 $output = substr_replace($output, '', strrpos($output, '/')); 11339 } 11340 elseif ($input === '/..') 11341 { 11342 $input = '/'; 11343 $output = substr_replace($output, '', strrpos($output, '/')); 11344 } 11345 // D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise, 11346 elseif ($input === '.' || $input === '..') 11347 { 11348 $input = ''; 11349 } 11350 // E: move the first path segment in the input buffer to the end of the output buffer, including the initial "/" character (if any) and any subsequent characters up to, but not including, the next "/" character or the end of the input buffer 11351 elseif (($pos = strpos($input, '/', 1)) !== false) 11352 { 11353 $output .= substr($input, 0, $pos); 11354 $input = substr_replace($input, '', 0, $pos); 11355 } 11356 else 11357 { 11358 $output .= $input; 11359 $input = ''; 11360 } 11361 } 11362 return $output . $input; 11363 } 11364 11374 public function replace_invalid_with_pct_encoding($string, $valid_chars, $case = SIMPLEPIE_SAME_CASE) 11375 { 11376 // Normalise case 11377 if ($case & SIMPLEPIE_LOWERCASE) 11378 { 11379 $string = strtolower($string); 11380 } 11381 elseif ($case & SIMPLEPIE_UPPERCASE) 11382 { 11383 $string = strtoupper($string); 11384 } 11385 11386 // Store position and string length (to avoid constantly recalculating this) 11387 $position = 0; 11388 $strlen = strlen($string); 11389 11390 // Loop as long as we have invalid characters, advancing the position to the next invalid character 11391 while (($position += strspn($string, $valid_chars, $position)) < $strlen) 11392 { 11393 // If we have a % character 11394 if ($string[$position] === '%') 11395 { 11396 // If we have a pct-encoded section 11397 if ($position + 2 < $strlen && strspn($string, '0123456789ABCDEFabcdef', $position + 1, 2) === 2) 11398 { 11399 // Get the the represented character 11400 $chr = chr(hexdec(substr($string, $position + 1, 2))); 11401 11402 // If the character is valid, replace the pct-encoded with the actual character while normalising case 11403 if (strpos($valid_chars, $chr) !== false) 11404 { 11405 if ($case & SIMPLEPIE_LOWERCASE) 11406 { 11407 $chr = strtolower($chr); 11408 } 11409 elseif ($case & SIMPLEPIE_UPPERCASE) 11410 { 11411 $chr = strtoupper($chr); 11412 } 11413 $string = substr_replace($string, $chr, $position, 3); 11414 $strlen -= 2; 11415 $position++; 11416 } 11417 11418 // Otherwise just normalise the pct-encoded to uppercase 11419 else 11420 { 11421 $string = substr_replace($string, strtoupper(substr($string, $position + 1, 2)), $position + 1, 2); 11422 $position += 3; 11423 } 11424 } 11425 // If we don't have a pct-encoded section, just replace the % with its own esccaped form 11426 else 11427 { 11428 $string = substr_replace($string, '%25', $position, 1); 11429 $strlen += 2; 11430 $position += 3; 11431 } 11432 } 11433 // If we have an invalid character, change into its pct-encoded form 11434 else 11435 { 11436 $replacement = sprintf("%%%02X", ord($string[$position])); 11437 $string = str_replace($string[$position], $replacement, $string); 11438 $strlen = strlen($string); 11439 } 11440 } 11441 return $string; 11442 } 11443 11450 public function is_valid() 11451 { 11452 return array_sum($this->valid) === count($this->valid); 11453 } 11454 11463 public function set_scheme($scheme) 11464 { 11465 if ($scheme === null || $scheme === '') 11466 { 11467 $this->scheme = null; 11468 } 11469 else 11470 { 11471 $len = strlen($scheme); 11472 switch (true) 11473 { 11474 case $len > 1: 11475 if (!strspn($scheme, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-.', 1)) 11476 { 11477 $this->scheme = null; 11478 $this->valid[__FUNCTION__] = false; 11479 return false; 11480 } 11481 11482 case $len > 0: 11483 if (!strspn($scheme, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 0, 1)) 11484 { 11485 $this->scheme = null; 11486 $this->valid[__FUNCTION__] = false; 11487 return false; 11488 } 11489 } 11490 $this->scheme = strtolower($scheme); 11491 } 11492 $this->valid[__FUNCTION__] = true; 11493 return true; 11494 } 11495 11504 public function set_authority($authority) 11505 { 11506 if (($userinfo_end = strrpos($authority, '@')) !== false) 11507 { 11508 $userinfo = substr($authority, 0, $userinfo_end); 11509 $authority = substr($authority, $userinfo_end + 1); 11510 } 11511 else 11512 { 11513 $userinfo = null; 11514 } 11515 11516 if (($port_start = strpos($authority, ':')) !== false) 11517 { 11518 $port = substr($authority, $port_start + 1); 11519 $authority = substr($authority, 0, $port_start); 11520 } 11521 else 11522 { 11523 $port = null; 11524 } 11525 11526 return $this->set_userinfo($userinfo) && $this->set_host($authority) && $this->set_port($port); 11527 } 11528 11536 public function set_userinfo($userinfo) 11537 { 11538 if ($userinfo === null || $userinfo === '') 11539 { 11540 $this->userinfo = null; 11541 } 11542 else 11543 { 11544 $this->userinfo = $this->replace_invalid_with_pct_encoding($userinfo, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$&\'()*+,;=:'); 11545 } 11546 $this->valid[__FUNCTION__] = true; 11547 return true; 11548 } 11549 11558 public function set_host($host) 11559 { 11560 if ($host === null || $host === '') 11561 { 11562 $this->host = null; 11563 $this->valid[__FUNCTION__] = true; 11564 return true; 11565 } 11566 elseif ($host[0] === '[' && substr($host, -1) === ']') 11567 { 11568 if (Net_IPv6::checkIPv6(substr($host, 1, -1))) 11569 { 11570 $this->host = $host; 11571 $this->valid[__FUNCTION__] = true; 11572 return true; 11573 } 11574 else 11575 { 11576 $this->host = null; 11577 $this->valid[__FUNCTION__] = false; 11578 return false; 11579 } 11580 } 11581 else 11582 { 11583 $this->host = $this->replace_invalid_with_pct_encoding($host, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$&\'()*+,;=', SIMPLEPIE_LOWERCASE); 11584 $this->valid[__FUNCTION__] = true; 11585 return true; 11586 } 11587 } 11588 11597 public function set_port($port) 11598 { 11599 if ($port === null || $port === '') 11600 { 11601 $this->port = null; 11602 $this->valid[__FUNCTION__] = true; 11603 return true; 11604 } 11605 elseif (strspn($port, '0123456789') === strlen($port)) 11606 { 11607 $this->port = (int) $port; 11608 $this->valid[__FUNCTION__] = true; 11609 return true; 11610 } 11611 else 11612 { 11613 $this->port = null; 11614 $this->valid[__FUNCTION__] = false; 11615 return false; 11616 } 11617 } 11618 11626 public function set_path($path) 11627 { 11628 if ($path === null || $path === '') 11629 { 11630 $this->path = null; 11631 $this->valid[__FUNCTION__] = true; 11632 return true; 11633 } 11634 elseif (substr($path, 0, 2) === '//' && $this->userinfo === null && $this->host === null && $this->port === null) 11635 { 11636 $this->path = null; 11637 $this->valid[__FUNCTION__] = false; 11638 return false; 11639 } 11640 else 11641 { 11642 $this->path = $this->replace_invalid_with_pct_encoding($path, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$&\'()*+,;=@/'); 11643 if ($this->scheme !== null) 11644 { 11645 $this->path = $this->remove_dot_segments($this->path); 11646 } 11647 $this->valid[__FUNCTION__] = true; 11648 return true; 11649 } 11650 } 11651 11659 public function set_query($query) 11660 { 11661 if ($query === null || $query === '') 11662 { 11663 $this->query = null; 11664 } 11665 else 11666 { 11667 $this->query = $this->replace_invalid_with_pct_encoding($query, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$\'()*+,;:@/?&='); 11668 } 11669 $this->valid[__FUNCTION__] = true; 11670 return true; 11671 } 11672 11680 public function set_fragment($fragment) 11681 { 11682 if ($fragment === null || $fragment === '') 11683 { 11684 $this->fragment = null; 11685 } 11686 else 11687 { 11688 $this->fragment = $this->replace_invalid_with_pct_encoding($fragment, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$&\'()*+,;=:@/?'); 11689 } 11690 $this->valid[__FUNCTION__] = true; 11691 return true; 11692 } 11693 11700 public function get_iri() 11701 { 11702 $iri = ''; 11703 if ($this->scheme !== null) 11704 { 11705 $iri .= $this->scheme . ':'; 11706 } 11707 if (($authority = $this->get_authority()) !== null) 11708 { 11709 $iri .= '//' . $authority; 11710 } 11711 if ($this->path !== null) 11712 { 11713 $iri .= $this->path; 11714 } 11715 if ($this->query !== null) 11716 { 11717 $iri .= '?' . $this->query; 11718 } 11719 if ($this->fragment !== null) 11720 { 11721 $iri .= '#' . $this->fragment; 11722 } 11723 11724 if ($iri !== '') 11725 { 11726 return $iri; 11727 } 11728 else 11729 { 11730 return null; 11731 } 11732 } 11733 11740 public function get_scheme() 11741 { 11742 return $this->scheme; 11743 } 11744 11751 public function get_authority() 11752 { 11753 $authority = ''; 11754 if ($this->userinfo !== null) 11755 { 11756 $authority .= $this->userinfo . '@'; 11757 } 11758 if ($this->host !== null) 11759 { 11760 $authority .= $this->host; 11761 } 11762 if ($this->port !== null) 11763 { 11764 $authority .= ':' . $this->port; 11765 } 11766 11767 if ($authority !== '') 11768 { 11769 return $authority; 11770 } 11771 else 11772 { 11773 return null; 11774 } 11775 } 11776 11783 public function get_userinfo() 11784 { 11785 return $this->userinfo; 11786 } 11787 11794 public function get_host() 11795 { 11796 return $this->host; 11797 } 11798 11805 public function get_port() 11806 { 11807 return $this->port; 11808 } 11809 11816 public function get_path() 11817 { 11818 return $this->path; 11819 } 11820 11827 public function get_query() 11828 { 11829 return $this->query; 11830 } 11831 11838 public function get_fragment() 11839 { 11840 return $this->fragment; 11841 } 11842 } 11843 11856 class SimplePie_Net_IPv6 11857 { 11867 public static function removeNetmaskSpec($ip) 11868 { 11869 if (strpos($ip, '/') !== false) 11870 { 11871 list($addr, $nm) = explode('/', $ip); 11872 } 11873 else 11874 { 11875 $addr = $ip; 11876 } 11877 return $addr; 11878 } 11879 11895 public static function Uncompress($ip) 11896 { 11897 $uip = SimplePie_Net_IPv6::removeNetmaskSpec($ip); 11898 $c1 = -1; 11899 $c2 = -1; 11900 if (strpos($ip, '::') !== false) 11901 { 11902 list($ip1, $ip2) = explode('::', $ip); 11903 if ($ip1 === '') 11904 { 11905 $c1 = -1; 11906 } 11907 else 11908 { 11909 $pos = 0; 11910 if (($pos = substr_count($ip1, ':')) > 0) 11911 { 11912 $c1 = $pos; 11913 } 11914 else 11915 { 11916 $c1 = 0; 11917 } 11918 } 11919 if ($ip2 === '') 11920 { 11921 $c2 = -1; 11922 } 11923 else 11924 { 11925 $pos = 0; 11926 if (($pos = substr_count($ip2, ':')) > 0) 11927 { 11928 $c2 = $pos; 11929 } 11930 else 11931 { 11932 $c2 = 0; 11933 } 11934 } 11935 if (strstr($ip2, '.')) 11936 { 11937 $c2++; 11938 } 11939 // :: 11940 if ($c1 === -1 && $c2 === -1) 11941 { 11942 $uip = '0:0:0:0:0:0:0:0'; 11943 } 11944 // ::xxx 11945 else if ($c1 === -1) 11946 { 11947 $fill = str_repeat('0:', 7 - $c2); 11948 $uip = str_replace('::', $fill, $uip); 11949 } 11950 // xxx:: 11951 else if ($c2 === -1) 11952 { 11953 $fill = str_repeat(':0', 7 - $c1); 11954 $uip = str_replace('::', $fill, $uip); 11955 } 11956 // xxx::xxx 11957 else 11958 { 11959 $fill = str_repeat(':0:', 6 - $c2 - $c1); 11960 $uip = str_replace('::', $fill, $uip); 11961 $uip = str_replace('::', ':', $uip); 11962 } 11963 } 11964 return $uip; 11965 } 11966 11981 public static function SplitV64($ip) 11982 { 11983 $ip = SimplePie_Net_IPv6::Uncompress($ip); 11984 if (strstr($ip, '.')) 11985 { 11986 $pos = strrpos($ip, ':'); 11987 $ip[$pos] = '_'; 11988 $ipPart = explode('_', $ip); 11989 return $ipPart; 11990 } 11991 else 11992 { 11993 return array($ip, ''); 11994 } 11995 } 11996 12007 public static function checkIPv6($ip) 12008 { 12009 $ipPart = SimplePie_Net_IPv6::SplitV64($ip); 12010 $count = 0; 12011 if (!empty($ipPart[0])) 12012 { 12013 $ipv6 = explode(':', $ipPart[0]); 12014 for ($i = 0; $i < count($ipv6); $i++) 12015 { 12016 $dec = hexdec($ipv6[$i]); 12017 $hex = strtoupper(preg_replace('/^[0]{1,3}(.*[0-9a-fA-F])$/', '\\1', $ipv6[$i])); 12018 if ($ipv6[$i] >= 0 && $dec <= 65535 && $hex === strtoupper(dechex($dec))) 12019 { 12020 $count++; 12021 } 12022 } 12023 if ($count === 8) 12024 { 12025 return true; 12026 } 12027 elseif ($count === 6 && !empty($ipPart[1])) 12028 { 12029 $ipv4 = explode('.', $ipPart[1]); 12030 $count = 0; 12031 foreach ($ipv4 as $ipv4_part) 12032 { 12033 if ($ipv4_part >= 0 && $ipv4_part <= 255 && preg_match('/^\d{1,3}$/', $ipv4_part)) 12034 { 12035 $count++; 12036 } 12037 } 12038 if ($count === 4) 12039 { 12040 return true; 12041 } 12042 } 12043 else 12044 { 12045 return false; 12046 } 12047 12048 } 12049 else 12050 { 12051 return false; 12052 } 12053 } 12054 } 12055 12061 class SimplePie_Parse_Date 12062 { 12069 var $date; 12070 12077 var $day = array( 12078 // English 12079 'mon' => 1, 12080 'monday' => 1, 12081 'tue' => 2, 12082 'tuesday' => 2, 12083 'wed' => 3, 12084 'wednesday' => 3, 12085 'thu' => 4, 12086 'thursday' => 4, 12087 'fri' => 5, 12088 'friday' => 5, 12089 'sat' => 6, 12090 'saturday' => 6, 12091 'sun' => 7, 12092 'sunday' => 7, 12093 // Dutch 12094 'maandag' => 1, 12095 'dinsdag' => 2, 12096 'woensdag' => 3, 12097 'donderdag' => 4, 12098 'vrijdag' => 5, 12099 'zaterdag' => 6, 12100 'zondag' => 7, 12101 // French 12102 'lundi' => 1, 12103 'mardi' => 2, 12104 'mercredi' => 3, 12105 'jeudi' => 4, 12106 'vendredi' => 5, 12107 'samedi' => 6, 12108 'dimanche' => 7, 12109 // German 12110 'montag' => 1, 12111 'dienstag' => 2, 12112 'mittwoch' => 3, 12113 'donnerstag' => 4, 12114 'freitag' => 5, 12115 'samstag' => 6, 12116 'sonnabend' => 6, 12117 'sonntag' => 7, 12118 // Italian 12119 'lunedì' => 1, 12120 'martedì' => 2, 12121 'mercoledì' => 3, 12122 'giovedì' => 4, 12123 'venerdì' => 5, 12124 'sabato' => 6, 12125 'domenica' => 7, 12126 // Spanish 12127 'lunes' => 1, 12128 'martes' => 2, 12129 'miércoles' => 3, 12130 'jueves' => 4, 12131 'viernes' => 5, 12132 'sábado' => 6, 12133 'domingo' => 7, 12134 // Finnish 12135 'maanantai' => 1, 12136 'tiistai' => 2, 12137 'keskiviikko' => 3, 12138 'torstai' => 4, 12139 'perjantai' => 5, 12140 'lauantai' => 6, 12141 'sunnuntai' => 7, 12142 // Hungarian 12143 'hétfő' => 1, 12144 'kedd' => 2, 12145 'szerda' => 3, 12146 'csütörtok' => 4, 12147 'péntek' => 5, 12148 'szombat' => 6, 12149 'vasárnap' => 7, 12150 // Greek 12151 'Δευ' => 1, 12152 'Τρι' => 2, 12153 'Τετ' => 3, 12154 'Πεμ' => 4, 12155 'Παρ' => 5, 12156 'Σαβ' => 6, 12157 'Κυρ' => 7, 12158 ); 12159 12166 var $month = array( 12167 // English 12168 'jan' => 1, 12169 'january' => 1, 12170 'feb' => 2, 12171 'february' => 2, 12172 'mar' => 3, 12173 'march' => 3, 12174 'apr' => 4, 12175 'april' => 4, 12176 'may' => 5, 12177 // No long form of May 12178 'jun' => 6, 12179 'june' => 6, 12180 'jul' => 7, 12181 'july' => 7, 12182 'aug' => 8, 12183 'august' => 8, 12184 'sep' => 9, 12185 'september' => 8, 12186 'oct' => 10, 12187 'october' => 10, 12188 'nov' => 11, 12189 'november' => 11, 12190 'dec' => 12, 12191 'december' => 12, 12192 // Dutch 12193 'januari' => 1, 12194 'februari' => 2, 12195 'maart' => 3, 12196 'april' => 4, 12197 'mei' => 5, 12198 'juni' => 6, 12199 'juli' => 7, 12200 'augustus' => 8, 12201 'september' => 9, 12202 'oktober' => 10, 12203 'november' => 11, 12204 'december' => 12, 12205 // French 12206 'janvier' => 1, 12207 'février' => 2, 12208 'mars' => 3, 12209 'avril' => 4, 12210 'mai' => 5, 12211 'juin' => 6, 12212 'juillet' => 7, 12213 'août' => 8, 12214 'septembre' => 9, 12215 'octobre' => 10, 12216 'novembre' => 11, 12217 'décembre' => 12, 12218 // German 12219 'januar' => 1, 12220 'februar' => 2, 12221 'märz' => 3, 12222 'april' => 4, 12223 'mai' => 5, 12224 'juni' => 6, 12225 'juli' => 7, 12226 'august' => 8, 12227 'september' => 9, 12228 'oktober' => 10, 12229 'november' => 11, 12230 'dezember' => 12, 12231 // Italian 12232 'gennaio' => 1, 12233 'febbraio' => 2, 12234 'marzo' => 3, 12235 'aprile' => 4, 12236 'maggio' => 5, 12237 'giugno' => 6, 12238 'luglio' => 7, 12239 'agosto' => 8, 12240 'settembre' => 9, 12241 'ottobre' => 10, 12242 'novembre' => 11, 12243 'dicembre' => 12, 12244 // Spanish 12245 'enero' => 1, 12246 'febrero' => 2, 12247 'marzo' => 3, 12248 'abril' => 4, 12249 'mayo' => 5, 12250 'junio' => 6, 12251 'julio' => 7, 12252 'agosto' => 8, 12253 'septiembre' => 9, 12254 'setiembre' => 9, 12255 'octubre' => 10, 12256 'noviembre' => 11, 12257 'diciembre' => 12, 12258 // Finnish 12259 'tammikuu' => 1, 12260 'helmikuu' => 2, 12261 'maaliskuu' => 3, 12262 'huhtikuu' => 4, 12263 'toukokuu' => 5, 12264 'kesäkuu' => 6, 12265 'heinäkuu' => 7, 12266 'elokuu' => 8, 12267 'suuskuu' => 9, 12268 'lokakuu' => 10, 12269 'marras' => 11, 12270 'joulukuu' => 12, 12271 // Hungarian 12272 'január' => 1, 12273 'február' => 2, 12274 'március' => 3, 12275 'április' => 4, 12276 'május' => 5, 12277 'június' => 6, 12278 'július' => 7, 12279 'augusztus' => 8, 12280 'szeptember' => 9, 12281 'október' => 10, 12282 'november' => 11, 12283 'december' => 12, 12284 // Greek 12285 'Ιαν' => 1, 12286 'Φεβ' => 2, 12287 'Μάώ' => 3, 12288 'Μαώ' => 3, 12289 'Απρ' => 4, 12290 'Μάι' => 5, 12291 'Μαϊ' => 5, 12292 'Μαι' => 5, 12293 'Ιούν' => 6, 12294 'Ιον' => 6, 12295 'Ιούλ' => 7, 12296 'Ιολ' => 7, 12297 'Αύγ' => 8, 12298 'Αυγ' => 8, 12299 'Σεπ' => 9, 12300 'Οκτ' => 10, 12301 'Νοέ' => 11, 12302 'Δεκ' => 12, 12303 ); 12304 12311 var $timezone = array( 12312 'ACDT' => 37800, 12313 'ACIT' => 28800, 12314 'ACST' => 34200, 12315 'ACT' => -18000, 12316 'ACWDT' => 35100, 12317 'ACWST' => 31500, 12318 'AEDT' => 39600, 12319 'AEST' => 36000, 12320 'AFT' => 16200, 12321 'AKDT' => -28800, 12322 'AKST' => -32400, 12323 'AMDT' => 18000, 12324 'AMT' => -14400, 12325 'ANAST' => 46800, 12326 'ANAT' => 43200, 12327 'ART' => -10800, 12328 'AZOST' => -3600, 12329 'AZST' => 18000, 12330 'AZT' => 14400, 12331 'BIOT' => 21600, 12332 'BIT' => -43200, 12333 'BOT' => -14400, 12334 'BRST' => -7200, 12335 'BRT' => -10800, 12336 'BST' => 3600, 12337 'BTT' => 21600, 12338 'CAST' => 18000, 12339 'CAT' => 7200, 12340 'CCT' => 23400, 12341 'CDT' => -18000, 12342 'CEDT' => 7200, 12343 'CET' => 3600, 12344 'CGST' => -7200, 12345 'CGT' => -10800, 12346 'CHADT' => 49500, 12347 'CHAST' => 45900, 12348 'CIST' => -28800, 12349 'CKT' => -36000, 12350 'CLDT' => -10800, 12351 'CLST' => -14400, 12352 'COT' => -18000, 12353 'CST' => -21600, 12354 'CVT' => -3600, 12355 'CXT' => 25200, 12356 'DAVT' => 25200, 12357 'DTAT' => 36000, 12358 'EADT' => -18000, 12359 'EAST' => -21600, 12360 'EAT' => 10800, 12361 'ECT' => -18000, 12362 'EDT' => -14400, 12363 'EEST' => 10800, 12364 'EET' => 7200, 12365 'EGT' => -3600, 12366 'EKST' => 21600, 12367 'EST' => -18000, 12368 'FJT' => 43200, 12369 'FKDT' => -10800, 12370 'FKST' => -14400, 12371 'FNT' => -7200, 12372 'GALT' => -21600, 12373 'GEDT' => 14400, 12374 'GEST' => 10800, 12375 'GFT' => -10800, 12376 'GILT' => 43200, 12377 'GIT' => -32400, 12378 'GST' => 14400, 12379 'GST' => -7200, 12380 'GYT' => -14400, 12381 'HAA' => -10800, 12382 'HAC' => -18000, 12383 'HADT' => -32400, 12384 'HAE' => -14400, 12385 'HAP' => -25200, 12386 'HAR' => -21600, 12387 'HAST' => -36000, 12388 'HAT' => -9000, 12389 'HAY' => -28800, 12390 'HKST' => 28800, 12391 'HMT' => 18000, 12392 'HNA' => -14400, 12393 'HNC' => -21600, 12394 'HNE' => -18000, 12395 'HNP' => -28800, 12396 'HNR' => -25200, 12397 'HNT' => -12600, 12398 'HNY' => -32400, 12399 'IRDT' => 16200, 12400 'IRKST' => 32400, 12401 'IRKT' => 28800, 12402 'IRST' => 12600, 12403 'JFDT' => -10800, 12404 'JFST' => -14400, 12405 'JST' => 32400, 12406 'KGST' => 21600, 12407 'KGT' => 18000, 12408 'KOST' => 39600, 12409 'KOVST' => 28800, 12410 'KOVT' => 25200, 12411 'KRAST' => 28800, 12412 'KRAT' => 25200, 12413 'KST' => 32400, 12414 'LHDT' => 39600, 12415 'LHST' => 37800, 12416 'LINT' => 50400, 12417 'LKT' => 21600, 12418 'MAGST' => 43200, 12419 'MAGT' => 39600, 12420 'MAWT' => 21600, 12421 'MDT' => -21600, 12422 'MESZ' => 7200, 12423 'MEZ' => 3600, 12424 'MHT' => 43200, 12425 'MIT' => -34200, 12426 'MNST' => 32400, 12427 'MSDT' => 14400, 12428 'MSST' => 10800, 12429 'MST' => -25200, 12430 'MUT' => 14400, 12431 'MVT' => 18000, 12432 'MYT' => 28800, 12433 'NCT' => 39600, 12434 'NDT' => -9000, 12435 'NFT' => 41400, 12436 'NMIT' => 36000, 12437 'NOVST' => 25200, 12438 'NOVT' => 21600, 12439 'NPT' => 20700, 12440 'NRT' => 43200, 12441 'NST' => -12600, 12442 'NUT' => -39600, 12443 'NZDT' => 46800, 12444 'NZST' => 43200, 12445 'OMSST' => 25200, 12446 'OMST' => 21600, 12447 'PDT' => -25200, 12448 'PET' => -18000, 12449 'PETST' => 46800, 12450 'PETT' => 43200, 12451 'PGT' => 36000, 12452 'PHOT' => 46800, 12453 'PHT' => 28800, 12454 'PKT' => 18000, 12455 'PMDT' => -7200, 12456 'PMST' => -10800, 12457 'PONT' => 39600, 12458 'PST' => -28800, 12459 'PWT' => 32400, 12460 'PYST' => -10800, 12461 'PYT' => -14400, 12462 'RET' => 14400, 12463 'ROTT' => -10800, 12464 'SAMST' => 18000, 12465 'SAMT' => 14400, 12466 'SAST' => 7200, 12467 'SBT' => 39600, 12468 'SCDT' => 46800, 12469 'SCST' => 43200, 12470 'SCT' => 14400, 12471 'SEST' => 3600, 12472 'SGT' => 28800, 12473 'SIT' => 28800, 12474 'SRT' => -10800, 12475 'SST' => -39600, 12476 'SYST' => 10800, 12477 'SYT' => 7200, 12478 'TFT' => 18000, 12479 'THAT' => -36000, 12480 'TJT' => 18000, 12481 'TKT' => -36000, 12482 'TMT' => 18000, 12483 'TOT' => 46800, 12484 'TPT' => 32400, 12485 'TRUT' => 36000, 12486 'TVT' => 43200, 12487 'TWT' => 28800, 12488 'UYST' => -7200, 12489 'UYT' => -10800, 12490 'UZT' => 18000, 12491 'VET' => -14400, 12492 'VLAST' => 39600, 12493 'VLAT' => 36000, 12494 'VOST' => 21600, 12495 'VUT' => 39600, 12496 'WAST' => 7200, 12497 'WAT' => 3600, 12498 'WDT' => 32400, 12499 'WEST' => 3600, 12500 'WFT' => 43200, 12501 'WIB' => 25200, 12502 'WIT' => 32400, 12503 'WITA' => 28800, 12504 'WKST' => 18000, 12505 'WST' => 28800, 12506 'YAKST' => 36000, 12507 'YAKT' => 32400, 12508 'YAPT' => 36000, 12509 'YEKST' => 21600, 12510 'YEKT' => 18000, 12511 ); 12512 12519 var $day_pcre; 12520 12527 var $month_pcre; 12528 12535 var $built_in = array(); 12536 12543 var $user = array(); 12544 12551 public function __construct() 12552 { 12553 $this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')'; 12554 $this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')'; 12555 12556 static $cache; 12557 if (!isset($cache[get_class($this)])) 12558 { 12559 $all_methods = get_class_methods($this); 12560 12561 foreach ($all_methods as $method) 12562 { 12563 if (strtolower(substr($method, 0, 5)) === 'date_') 12564 { 12565 $cache[get_class($this)][] = $method; 12566 } 12567 } 12568 } 12569 12570 foreach ($cache[get_class($this)] as $method) 12571 { 12572 $this->built_in[] = $method; 12573 } 12574 } 12575 12581 public static function get() 12582 { 12583 static $object; 12584 if (!$object) 12585 { 12586 $object = new SimplePie_Parse_Date; 12587 } 12588 return $object; 12589 } 12590 12599 public function parse($date) 12600 { 12601 foreach ($this->user as $method) 12602 { 12603 if (($returned = call_user_func($method, $date)) !== false) 12604 { 12605 return $returned; 12606 } 12607 } 12608 12609 foreach ($this->built_in as $method) 12610 { 12611 if (($returned = call_user_func(array(&$this, $method), $date)) !== false) 12612 { 12613 return $returned; 12614 } 12615 } 12616 12617 return false; 12618 } 12619 12627 public function add_callback($callback) 12628 { 12629 if (is_callable($callback)) 12630 { 12631 $this->user[] = $callback; 12632 } 12633 else 12634 { 12635 trigger_error('User-supplied function must be a valid callback', E_USER_WARNING); 12636 } 12637 } 12638 12647 public function date_w3cdtf($date) 12648 { 12649 static $pcre; 12650 if (!$pcre) 12651 { 12652 $year = '([0-9]{4})'; 12653 $month = $day = $hour = $minute = $second = '([0-9]{2})'; 12654 $decimal = '([0-9]*)'; 12655 $zone = '(?:(Z)|([+\-])([0-9]{1,2}):?([0-9]{1,2}))'; 12656 $pcre = '/^' . $year . '(?:-?' . $month . '(?:-?' . $day . '(?:[Tt\x09\x20]+' . $hour . '(?::?' . $minute . '(?::?' . $second . '(?:.' . $decimal . ')?)?)?' . $zone . ')?)?)?$/'; 12657 } 12658 if (preg_match($pcre, $date, $match)) 12659 { 12660 /* 12661 Capturing subpatterns: 12662 1: Year 12663 2: Month 12664 3: Day 12665 4: Hour 12666 5: Minute 12667 6: Second 12668 7: Decimal fraction of a second 12669 8: Zulu 12670 9: Timezone ± 12671 10: Timezone hours 12672 11: Timezone minutes 12673 */ 12674 12675 // Fill in empty matches 12676 for ($i = count($match); $i <= 3; $i++) 12677 { 12678 $match[$i] = '1'; 12679 } 12680 12681 for ($i = count($match); $i <= 7; $i++) 12682 { 12683 $match[$i] = '0'; 12684 } 12685 12686 // Numeric timezone 12687 if (isset($match[9]) && $match[9] !== '') 12688 { 12689 $timezone = $match[10] * 3600; 12690 $timezone += $match[11] * 60; 12691 if ($match[9] === '-') 12692 { 12693 $timezone = 0 - $timezone; 12694 } 12695 } 12696 else 12697 { 12698 $timezone = 0; 12699 } 12700 12701 // Convert the number of seconds to an integer, taking decimals into account 12702 $second = round($match[6] + $match[7] / pow(10, strlen($match[7]))); 12703 12704 return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone; 12705 } 12706 else 12707 { 12708 return false; 12709 } 12710 } 12711 12719 public function remove_rfc2822_comments($string) 12720 { 12721 $string = (string) $string; 12722 $position = 0; 12723 $length = strlen($string); 12724 $depth = 0; 12725 12726 $output = ''; 12727 12728 while ($position < $length && ($pos = strpos($string, '(', $position)) !== false) 12729 { 12730 $output .= substr($string, $position, $pos - $position); 12731 $position = $pos + 1; 12732 if ($string[$pos - 1] !== '\\') 12733 { 12734 $depth++; 12735 while ($depth && $position < $length) 12736 { 12737 $position += strcspn($string, '()', $position); 12738 if ($string[$position - 1] === '\\') 12739 { 12740 $position++; 12741 continue; 12742 } 12743 elseif (isset($string[$position])) 12744 { 12745 switch ($string[$position]) 12746 { 12747 case '(': 12748 $depth++; 12749 break; 12750 12751 case ')': 12752 $depth--; 12753 break; 12754 } 12755 $position++; 12756 } 12757 else 12758 { 12759 break; 12760 } 12761 } 12762 } 12763 else 12764 { 12765 $output .= '('; 12766 } 12767 } 12768 $output .= substr($string, $position); 12769 12770 return $output; 12771 } 12772 12779 public function date_rfc2822($date) 12780 { 12781 static $pcre; 12782 if (!$pcre) 12783 { 12784 $wsp = '[\x09\x20]'; 12785 $fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)'; 12786 $optional_fws = $fws . '?'; 12787 $day_name = $this->day_pcre; 12788 $month = $this->month_pcre; 12789 $day = '([0-9]{1,2})'; 12790 $hour = $minute = $second = '([0-9]{2})'; 12791 $year = '([0-9]{2,4})'; 12792 $num_zone = '([+\-])([0-9]{2})([0-9]{2})'; 12793 $character_zone = '([A-Z]{1,5})'; 12794 $zone = '(?:' . $num_zone . '|' . $character_zone . ')'; 12795 $pcre = '/(?:' . $optional_fws . $day_name . $optional_fws . ',)?' . $optional_fws . $day . $fws . $month . $fws . $year . $fws . $hour . $optional_fws . ':' . $optional_fws . $minute . '(?:' . $optional_fws . ':' . $optional_fws . $second . ')?' . $fws . $zone . '/i'; 12796 } 12797 if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match)) 12798 { 12799 /* 12800 Capturing subpatterns: 12801 1: Day name 12802 2: Day 12803 3: Month 12804 4: Year 12805 5: Hour 12806 6: Minute 12807 7: Second 12808 8: Timezone ± 12809 9: Timezone hours 12810 10: Timezone minutes 12811 11: Alphabetic timezone 12812 */ 12813 12814 // Find the month number 12815 $month = $this->month[strtolower($match[3])]; 12816 12817 // Numeric timezone 12818 if ($match[8] !== '') 12819 { 12820 $timezone = $match[9] * 3600; 12821 $timezone += $match[10] * 60; 12822 if ($match[8] === '-') 12823 { 12824 $timezone = 0 - $timezone; 12825 } 12826 } 12827 // Character timezone 12828 elseif (isset($this->timezone[strtoupper($match[11])])) 12829 { 12830 $timezone = $this->timezone[strtoupper($match[11])]; 12831 } 12832 // Assume everything else to be -0000 12833 else 12834 { 12835 $timezone = 0; 12836 } 12837 12838 // Deal with 2/3 digit years 12839 if ($match[4] < 50) 12840 { 12841 $match[4] += 2000; 12842 } 12843 elseif ($match[4] < 1000) 12844 { 12845 $match[4] += 1900; 12846 } 12847 12848 // Second is optional, if it is empty set it to zero 12849 if ($match[7] !== '') 12850 { 12851 $second = $match[7]; 12852 } 12853 else 12854 { 12855 $second = 0; 12856 } 12857 12858 return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone; 12859 } 12860 else 12861 { 12862 return false; 12863 } 12864 } 12865 12872 public function date_rfc850($date) 12873 { 12874 static $pcre; 12875 if (!$pcre) 12876 { 12877 $space = '[\x09\x20]+'; 12878 $day_name = $this->day_pcre; 12879 $month = $this->month_pcre; 12880 $day = '([0-9]{1,2})'; 12881 $year = $hour = $minute = $second = '([0-9]{2})'; 12882 $zone = '([A-Z]{1,5})'; 12883 $pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i'; 12884 } 12885 if (preg_match($pcre, $date, $match)) 12886 { 12887 /* 12888 Capturing subpatterns: 12889 1: Day name 12890 2: Day 12891 3: Month 12892 4: Year 12893 5: Hour 12894 6: Minute 12895 7: Second 12896 8: Timezone 12897 */ 12898 12899 // Month 12900 $month = $this->month[strtolower($match[3])]; 12901 12902 // Character timezone 12903 if (isset($this->timezone[strtoupper($match[8])])) 12904 { 12905 $timezone = $this->timezone[strtoupper($match[8])]; 12906 } 12907 // Assume everything else to be -0000 12908 else 12909 { 12910 $timezone = 0; 12911 } 12912 12913 // Deal with 2 digit year 12914 if ($match[4] < 50) 12915 { 12916 $match[4] += 2000; 12917 } 12918 else 12919 { 12920 $match[4] += 1900; 12921 } 12922 12923 return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone; 12924 } 12925 else 12926 { 12927 return false; 12928 } 12929 } 12930 12937 public function date_asctime($date) 12938 { 12939 static $pcre; 12940 if (!$pcre) 12941 { 12942 $space = '[\x09\x20]+'; 12943 $wday_name = $this->day_pcre; 12944 $mon_name = $this->month_pcre; 12945 $day = '([0-9]{1,2})'; 12946 $hour = $sec = $min = '([0-9]{2})'; 12947 $year = '([0-9]{4})'; 12948 $terminator = '\x0A?\x00?'; 12949 $pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i'; 12950 } 12951 if (preg_match($pcre, $date, $match)) 12952 { 12953 /* 12954 Capturing subpatterns: 12955 1: Day name 12956 2: Month 12957 3: Day 12958 4: Hour 12959 5: Minute 12960 6: Second 12961 7: Year 12962 */ 12963 12964 $month = $this->month[strtolower($match[2])]; 12965 return gmmktime($match[4], $match[5], $match[6], $month, $match[3], $match[7]); 12966 } 12967 else 12968 { 12969 return false; 12970 } 12971 } 12972 12979 public function date_strtotime($date) 12980 { 12981 $strtotime = strtotime($date); 12982 if ($strtotime === -1 || $strtotime === false) 12983 { 12984 return false; 12985 } 12986 else 12987 { 12988 return $strtotime; 12989 } 12990 } 12991 } 12992 12998 class SimplePie_Content_Type_Sniffer 12999 { 13006 var $file; 13007 13014 public function __construct($file) 13015 { 13016 $this->file = $file; 13017 } 13018 13025 public function get_type() 13026 { 13027 if (isset($this->file->headers['content-type'])) 13028 { 13029 if (!isset($this->file->headers['content-encoding']) 13030 && ($this->file->headers['content-type'] === 'text/plain' 13031 || $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1' 13032 || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1')) 13033 { 13034 return $this->text_or_binary(); 13035 } 13036 13037 if (($pos = strpos($this->file->headers['content-type'], ';')) !== false) 13038 { 13039 $official = substr($this->file->headers['content-type'], 0, $pos); 13040 } 13041 else 13042 { 13043 $official = $this->file->headers['content-type']; 13044 } 13045 $official = strtolower($official); 13046 13047 if ($official === 'unknown/unknown' 13048 || $official === 'application/unknown') 13049 { 13050 return $this->unknown(); 13051 } 13052 elseif (substr($official, -4) === '+xml' 13053 || $official === 'text/xml' 13054 || $official === 'application/xml') 13055 { 13056 return $official; 13057 } 13058 elseif (substr($official, 0, 6) === 'image/') 13059 { 13060 if ($return = $this->image()) 13061 { 13062 return $return; 13063 } 13064 else 13065 { 13066 return $official; 13067 } 13068 } 13069 elseif ($official === 'text/html') 13070 { 13071 return $this->feed_or_html(); 13072 } 13073 else 13074 { 13075 return $official; 13076 } 13077 } 13078 else 13079 { 13080 return $this->unknown(); 13081 } 13082 } 13083 13090 public function text_or_binary() 13091 { 13092 if (substr($this->file->body, 0, 2) === "\xFE\xFF" 13093 || substr($this->file->body, 0, 2) === "\xFF\xFE" 13094 || substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF" 13095 || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF") 13096 { 13097 return 'text/plain'; 13098 } 13099 elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body)) 13100 { 13101 return 'application/octect-stream'; 13102 } 13103 else 13104 { 13105 return 'text/plain'; 13106 } 13107 } 13108 13115 public function unknown() 13116 { 13117 $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20"); 13118 if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html' 13119 || strtolower(substr($this->file->body, $ws, 5)) === '<html' 13120 || strtolower(substr($this->file->body, $ws, 7)) === '<script') 13121 { 13122 return 'text/html'; 13123 } 13124 elseif (substr($this->file->body, 0, 5) === '%PDF-') 13125 { 13126 return 'application/pdf'; 13127 } 13128 elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-') 13129 { 13130 return 'application/postscript'; 13131 } 13132 elseif (substr($this->file->body, 0, 6) === 'GIF87a' 13133 || substr($this->file->body, 0, 6) === 'GIF89a') 13134 { 13135 return 'image/gif'; 13136 } 13137 elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") 13138 { 13139 return 'image/png'; 13140 } 13141 elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF") 13142 { 13143 return 'image/jpeg'; 13144 } 13145 elseif (substr($this->file->body, 0, 2) === "\x42\x4D") 13146 { 13147 return 'image/bmp'; 13148 } 13149 else 13150 { 13151 return $this->text_or_binary(); 13152 } 13153 } 13154 13161 public function image() 13162 { 13163 if (substr($this->file->body, 0, 6) === 'GIF87a' 13164 || substr($this->file->body, 0, 6) === 'GIF89a') 13165 { 13166 return 'image/gif'; 13167 } 13168 elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") 13169 { 13170 return 'image/png'; 13171 } 13172 elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF") 13173 { 13174 return 'image/jpeg'; 13175 } 13176 elseif (substr($this->file->body, 0, 2) === "\x42\x4D") 13177 { 13178 return 'image/bmp'; 13179 } 13180 else 13181 { 13182 return false; 13183 } 13184 } 13185 13192 public function feed_or_html() 13193 { 13194 $len = strlen($this->file->body); 13195 $pos = strspn($this->file->body, "\x09\x0A\x0D\x20"); 13196 13197 while ($pos < $len) 13198 { 13199 switch ($this->file->body[$pos]) 13200 { 13201 case "\x09": 13202 case "\x0A": 13203 case "\x0D": 13204 case "\x20": 13205 $pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos); 13206 continue 2; 13207 13208 case '<': 13209 $pos++; 13210 break; 13211 13212 default: 13213 return 'text/html'; 13214 } 13215 13216 if (substr($this->file->body, $pos, 3) === '!--') 13217 { 13218 $pos += 3; 13219 if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false) 13220 { 13221 $pos += 3; 13222 } 13223 else 13224 { 13225 return 'text/html'; 13226 } 13227 } 13228 elseif (substr($this->file->body, $pos, 1) === '!') 13229 { 13230 if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false) 13231 { 13232 $pos++; 13233 } 13234 else 13235 { 13236 return 'text/html'; 13237 } 13238 } 13239 elseif (substr($this->file->body, $pos, 1) === '?') 13240 { 13241 if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false) 13242 { 13243 $pos += 2; 13244 } 13245 else 13246 { 13247 return 'text/html'; 13248 } 13249 } 13250 elseif (substr($this->file->body, $pos, 3) === 'rss' 13251 || substr($this->file->body, $pos, 7) === 'rdf:RDF') 13252 { 13253 return 'application/rss+xml'; 13254 } 13255 elseif (substr($this->file->body, $pos, 4) === 'feed') 13256 { 13257 return 'application/atom+xml'; 13258 } 13259 else 13260 { 13261 return 'text/html'; 13262 } 13263 } 13264 13265 return 'text/html'; 13266 } 13267 } 13268 13274 class SimplePie_XML_Declaration_Parser 13275 { 13282 var $version = '1.0'; 13283 13290 var $encoding = 'UTF-8'; 13291 13298 var $standalone = false; 13299 13306 var $state = 'before_version_name'; 13307 13314 var $data = ''; 13315 13322 var $data_length = 0; 13323 13330 var $position = 0; 13331 13338 public function __construct($data) 13339 { 13340 $this->data = $data; 13341 $this->data_length = strlen($this->data); 13342 } 13343 13350 public function parse() 13351 { 13352 while ($this->state && $this->state !== 'emit' && $this->has_data()) 13353 { 13354 $state = $this->state; 13355 $this->$state(); 13356 } 13357 $this->data = ''; 13358 if ($this->state === 'emit') 13359 { 13360 return true; 13361 } 13362 else 13363 { 13364 $this->version = ''; 13365 $this->encoding = ''; 13366 $this->standalone = ''; 13367 return false; 13368 } 13369 } 13370 13377 public function has_data() 13378 { 13379 return (bool) ($this->position < $this->data_length); 13380 } 13381 13387 public function skip_whitespace() 13388 { 13389 $whitespace = strspn($this->data, "\x09\x0A\x0D\x20", $this->position); 13390 $this->position += $whitespace; 13391 return $whitespace; 13392 } 13393 13397 public function get_value() 13398 { 13399 $quote = substr($this->data, $this->position, 1); 13400 if ($quote === '"' || $quote === "'") 13401 { 13402 $this->position++; 13403 $len = strcspn($this->data, $quote, $this->position); 13404 if ($this->has_data()) 13405 { 13406 $value = substr($this->data, $this->position, $len); 13407 $this->position += $len + 1; 13408 return $value; 13409 } 13410 } 13411 return false; 13412 } 13413 13414 public function before_version_name() 13415 { 13416 if ($this->skip_whitespace()) 13417 { 13418 $this->state = 'version_name'; 13419 } 13420 else 13421 { 13422 $this->state = false; 13423 } 13424 } 13425 13426 public function version_name() 13427 { 13428 if (substr($this->data, $this->position, 7) === 'version') 13429 { 13430 $this->position += 7; 13431 $this->skip_whitespace(); 13432 $this->state = 'version_equals'; 13433 } 13434 else 13435 { 13436 $this->state = false; 13437 } 13438 } 13439 13440 public function version_equals() 13441 { 13442 if (substr($this->data, $this->position, 1) === '=') 13443 { 13444 $this->position++; 13445 $this->skip_whitespace(); 13446 $this->state = 'version_value'; 13447 } 13448 else 13449 { 13450 $this->state = false; 13451 } 13452 } 13453 13454 public function version_value() 13455 { 13456 if ($this->version = $this->get_value()) 13457 { 13458 $this->skip_whitespace(); 13459 if ($this->has_data()) 13460 { 13461 $this->state = 'encoding_name'; 13462 } 13463 else 13464 { 13465 $this->state = 'emit'; 13466 } 13467 } 13468 else 13469 { 13470 $this->state = false; 13471 } 13472 } 13473 13474 public function encoding_name() 13475 { 13476 if (substr($this->data, $this->position, 8) === 'encoding') 13477 { 13478 $this->position += 8; 13479 $this->skip_whitespace(); 13480 $this->state = 'encoding_equals'; 13481 } 13482 else 13483 { 13484 $this->state = 'standalone_name'; 13485 } 13486 } 13487 13488 public function encoding_equals() 13489 { 13490 if (substr($this->data, $this->position, 1) === '=') 13491 { 13492 $this->position++; 13493 $this->skip_whitespace(); 13494 $this->state = 'encoding_value'; 13495 } 13496 else 13497 { 13498 $this->state = false; 13499 } 13500 } 13501 13502 public function encoding_value() 13503 { 13504 if ($this->encoding = $this->get_value()) 13505 { 13506 $this->skip_whitespace(); 13507 if ($this->has_data()) 13508 { 13509 $this->state = 'standalone_name'; 13510 } 13511 else 13512 { 13513 $this->state = 'emit'; 13514 } 13515 } 13516 else 13517 { 13518 $this->state = false; 13519 } 13520 } 13521 13522 public function standalone_name() 13523 { 13524 if (substr($this->data, $this->position, 10) === 'standalone') 13525 { 13526 $this->position += 10; 13527 $this->skip_whitespace(); 13528 $this->state = 'standalone_equals'; 13529 } 13530 else 13531 { 13532 $this->state = false; 13533 } 13534 } 13535 13536 public function standalone_equals() 13537 { 13538 if (substr($this->data, $this->position, 1) === '=') 13539 { 13540 $this->position++; 13541 $this->skip_whitespace(); 13542 $this->state = 'standalone_value'; 13543 } 13544 else 13545 { 13546 $this->state = false; 13547 } 13548 } 13549 13550 public function standalone_value() 13551 { 13552 if ($standalone = $this->get_value()) 13553 { 13554 switch ($standalone) 13555 { 13556 case 'yes': 13557 $this->standalone = true; 13558 break; 13559 13560 case 'no': 13561 $this->standalone = false; 13562 break; 13563 13564 default: 13565 $this->state = false; 13566 return; 13567 } 13568 13569 $this->skip_whitespace(); 13570 if ($this->has_data()) 13571 { 13572 $this->state = false; 13573 } 13574 else 13575 { 13576 $this->state = 'emit'; 13577 } 13578 } 13579 else 13580 { 13581 $this->state = false; 13582 } 13583 } 13584 } 13585 13586 class SimplePie_Locator 13587 { 13588 var $useragent; 13589 var $timeout; 13590 var $file; 13591 var $local = array(); 13592 var $elsewhere = array(); 13593 var $file_class = 'SimplePie_File'; 13594 var $cached_entities = array(); 13595 var $http_base; 13596 var $base; 13597 var $base_location = 0; 13598 var $checked_feeds = 0; 13599 var $max_checked_feeds = 10; 13600 var $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer'; 13601 13602 public function __construct(&$file, $timeout = 10, $useragent = null, $file_class = 'SimplePie_File', $max_checked_feeds = 10, $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer') 13603 { 13604 $this->file =& $file; 13605 $this->file_class = $file_class; 13606 $this->useragent = $useragent; 13607 $this->timeout = $timeout; 13608 $this->max_checked_feeds = $max_checked_feeds; 13609 $this->content_type_sniffer_class = $content_type_sniffer_class; 13610 } 13611 13612 public function find($type = SIMPLEPIE_LOCATOR_ALL, &$working) 13613 { 13614 if ($this->is_feed($this->file)) 13615 { 13616 return $this->file; 13617 } 13618 13619 if ($this->file->method & SIMPLEPIE_FILE_SOURCE_REMOTE) 13620 { 13621 $sniffer = new $this->content_type_sniffer_class($this->file); 13622 if ($sniffer->get_type() !== 'text/html') 13623 { 13624 return null; 13625 } 13626 } 13627 13628 if ($type & ~SIMPLEPIE_LOCATOR_NONE) 13629 { 13630 $this->get_base(); 13631 } 13632 13633 if ($type & SIMPLEPIE_LOCATOR_AUTODISCOVERY && $working = $this->autodiscovery()) 13634 { 13635 return $working[0]; 13636 } 13637 13638 if ($type & (SIMPLEPIE_LOCATOR_LOCAL_EXTENSION | SIMPLEPIE_LOCATOR_LOCAL_BODY | SIMPLEPIE_LOCATOR_REMOTE_EXTENSION | SIMPLEPIE_LOCATOR_REMOTE_BODY) && $this->get_links()) 13639 { 13640 if ($type & SIMPLEPIE_LOCATOR_LOCAL_EXTENSION && $working = $this->extension($this->local)) 13641 { 13642 return $working; 13643 } 13644 13645 if ($type & SIMPLEPIE_LOCATOR_LOCAL_BODY && $working = $this->body($this->local)) 13646 { 13647 return $working; 13648 } 13649 13650 if ($type & SIMPLEPIE_LOCATOR_REMOTE_EXTENSION && $working = $this->extension($this->elsewhere)) 13651 { 13652 return $working; 13653 } 13654 13655 if ($type & SIMPLEPIE_LOCATOR_REMOTE_BODY && $working = $this->body($this->elsewhere)) 13656 { 13657 return $working; 13658 } 13659 } 13660 return null; 13661 } 13662 13663 public function is_feed(&$file) 13664 { 13665 if ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE) 13666 { 13667 $sniffer = new $this->content_type_sniffer_class($file); 13668 $sniffed = $sniffer->get_type(); 13669 if (in_array($sniffed, array('application/rss+xml', 'application/rdf+xml', 'text/rdf', 'application/atom+xml', 'text/xml', 'application/xml'))) 13670 { 13671 return true; 13672 } 13673 else 13674 { 13675 return false; 13676 } 13677 } 13678 elseif ($file->method & SIMPLEPIE_FILE_SOURCE_LOCAL) 13679 { 13680 return true; 13681 } 13682 else 13683 { 13684 return false; 13685 } 13686 } 13687 13688 public function get_base() 13689 { 13690 $this->http_base = $this->file->url; 13691 $this->base = $this->http_base; 13692 $elements = SimplePie_Misc::get_element('base', $this->file->body); 13693 foreach ($elements as $element) 13694 { 13695 if ($element['attribs']['href']['data'] !== '') 13696 { 13697 $this->base = SimplePie_Misc::absolutize_url(trim($element['attribs']['href']['data']), $this->http_base); 13698 $this->base_location = $element['offset']; 13699 break; 13700 } 13701 } 13702 } 13703 13704 public function autodiscovery() 13705 { 13706 $links = array_merge(SimplePie_Misc::get_element('link', $this->file->body), SimplePie_Misc::get_element('a', $this->file->body), SimplePie_Misc::get_element('area', $this->file->body)); 13707 $done = array(); 13708 $feeds = array(); 13709 foreach ($links as $link) 13710 { 13711 if ($this->checked_feeds === $this->max_checked_feeds) 13712 { 13713 break; 13714 } 13715 if (isset($link['attribs']['href']['data']) && isset($link['attribs']['rel']['data'])) 13716 { 13717 $rel = array_unique(SimplePie_Misc::space_seperated_tokens(strtolower($link['attribs']['rel']['data']))); 13718 13719 if ($this->base_location < $link['offset']) 13720 { 13721 $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->base); 13722 } 13723 else 13724 { 13725 $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->http_base); 13726 } 13727 13728 if (!in_array($href, $done) && in_array('feed', $rel) || (in_array('alternate', $rel) && !empty($link['attribs']['type']['data']) && in_array(strtolower(SimplePie_Misc::parse_mime($link['attribs']['type']['data'])), array('application/rss+xml', 'application/atom+xml'))) && !isset($feeds[$href])) 13729 { 13730 $this->checked_feeds++; 13731 $feed = new $this->file_class($href, $this->timeout, 5, null, $this->useragent); 13732 if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed)) 13733 { 13734 $feeds[$href] = $feed; 13735 } 13736 } 13737 $done[] = $href; 13738 } 13739 } 13740 13741 if (!empty($feeds)) 13742 { 13743 return array_values($feeds); 13744 } 13745 else { 13746 return null; 13747 } 13748 } 13749 13750 public function get_links() 13751 { 13752 $links = SimplePie_Misc::get_element('a', $this->file->body); 13753 foreach ($links as $link) 13754 { 13755 if (isset($link['attribs']['href']['data'])) 13756 { 13757 $href = trim($link['attribs']['href']['data']); 13758 $parsed = SimplePie_Misc::parse_url($href); 13759 if ($parsed['scheme'] === '' || preg_match('/^(http(s)|feed)?$/i', $parsed['scheme'])) 13760 { 13761 if ($this->base_location < $link['offset']) 13762 { 13763 $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->base); 13764 } 13765 else 13766 { 13767 $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->http_base); 13768 } 13769 13770 $current = SimplePie_Misc::parse_url($this->file->url); 13771 13772 if ($parsed['authority'] === '' || $parsed['authority'] === $current['authority']) 13773 { 13774 $this->local[] = $href; 13775 } 13776 else 13777 { 13778 $this->elsewhere[] = $href; 13779 } 13780 } 13781 } 13782 } 13783 $this->local = array_unique($this->local); 13784 $this->elsewhere = array_unique($this->elsewhere); 13785 if (!empty($this->local) || !empty($this->elsewhere)) 13786 { 13787 return true; 13788 } 13789 return null; 13790 } 13791 13792 public function extension(&$array) 13793 { 13794 foreach ($array as $key => $value) 13795 { 13796 if ($this->checked_feeds === $this->max_checked_feeds) 13797 { 13798 break; 13799 } 13800 if (in_array(strtolower(strrchr($value, '.')), array('.rss', '.rdf', '.atom', '.xml'))) 13801 { 13802 $this->checked_feeds++; 13803 $feed = new $this->file_class($value, $this->timeout, 5, null, $this->useragent); 13804 if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed)) 13805 { 13806 return $feed; 13807 } 13808 else 13809 { 13810 unset($array[$key]); 13811 } 13812 } 13813 } 13814 return null; 13815 } 13816 13817 public function body(&$array) 13818 { 13819 foreach ($array as $key => $value) 13820 { 13821 if ($this->checked_feeds === $this->max_checked_feeds) 13822 { 13823 break; 13824 } 13825 if (preg_match('/(rss|rdf|atom|xml)/i', $value)) 13826 { 13827 $this->checked_feeds++; 13828 $feed = new $this->file_class($value, $this->timeout, 5, null, $this->useragent); 13829 if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed)) 13830 { 13831 return $feed; 13832 } 13833 else 13834 { 13835 unset($array[$key]); 13836 } 13837 } 13838 } 13839 return null; 13840 } 13841 } 13842 13843 class SimplePie_Parser 13844 { 13845 var $error_code; 13846 var $error_string; 13847 var $current_line; 13848 var $current_column; 13849 var $current_byte; 13850 var $separator = ' '; 13851 var $namespace = array(''); 13852 var $element = array(''); 13853 var $xml_base = array(''); 13854 var $xml_base_explicit = array(false); 13855 var $xml_lang = array(''); 13856 var $data = array(); 13857 var $datas = array(array()); 13858 var $current_xhtml_construct = -1; 13859 var $encoding; 13860 13861 public function parse(&$data, $encoding) 13862 { 13863 // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character 13864 if (strtoupper($encoding) === 'US-ASCII') 13865 { 13866 $this->encoding = 'UTF-8'; 13867 } 13868 else 13869 { 13870 $this->encoding = $encoding; 13871 } 13872 13873 // Strip BOM: 13874 // UTF-32 Big Endian BOM 13875 if (substr($data, 0, 4) === "\x00\x00\xFE\xFF") 13876 { 13877 $data = substr($data, 4); 13878 } 13879 // UTF-32 Little Endian BOM 13880 elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00") 13881 { 13882 $data = substr($data, 4); 13883 } 13884 // UTF-16 Big Endian BOM 13885 elseif (substr($data, 0, 2) === "\xFE\xFF") 13886 { 13887 $data = substr($data, 2); 13888 } 13889 // UTF-16 Little Endian BOM 13890 elseif (substr($data, 0, 2) === "\xFF\xFE") 13891 { 13892 $data = substr($data, 2); 13893 } 13894 // UTF-8 BOM 13895 elseif (substr($data, 0, 3) === "\xEF\xBB\xBF") 13896 { 13897 $data = substr($data, 3); 13898 } 13899 13900 if (substr($data, 0, 5) === '<?xml' && strspn(substr($data, 5, 1), "\x09\x0A\x0D\x20") && ($pos = strpos($data, '?>')) !== false) 13901 { 13902 $declaration = new SimplePie_XML_Declaration_Parser(substr($data, 5, $pos - 5)); 13903 if ($declaration->parse()) 13904 { 13905 $data = substr($data, $pos + 2); 13906 $data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . $data; 13907 } 13908 else 13909 { 13910 $this->error_string = 'SimplePie bug! Please report this!'; 13911 return false; 13912 } 13913 } 13914 13915 $return = true; 13916 13917 static $xml_is_sane = null; 13918 if ($xml_is_sane === null) 13919 { 13920 $parser_check = xml_parser_create(); 13921 xml_parse_into_struct($parser_check, '<foo>&</foo>', $values); 13922 xml_parser_free($parser_check); 13923 $xml_is_sane = isset($values[0]['value']); 13924 } 13925 13926 // Create the parser 13927 if ($xml_is_sane) 13928 { 13929 $xml = xml_parser_create_ns($this->encoding, $this->separator); 13930 xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1); 13931 xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0); 13932 xml_set_object($xml, $this); 13933 xml_set_character_data_handler($xml, 'cdata'); 13934 xml_set_element_handler($xml, 'tag_open', 'tag_close'); 13935 13936 // Parse! 13937 if (!xml_parse($xml, $data, true)) 13938 { 13939 $this->error_code = xml_get_error_code($xml); 13940 $this->error_string = xml_error_string($this->error_code); 13941 $return = false; 13942 } 13943 $this->current_line = xml_get_current_line_number($xml); 13944 $this->current_column = xml_get_current_column_number($xml); 13945 $this->current_byte = xml_get_current_byte_index($xml); 13946 xml_parser_free($xml); 13947 return $return; 13948 } 13949 else 13950 { 13951 libxml_clear_errors(); 13952 $xml = new XMLReader(); 13953 $xml->xml($data); 13954 while (@$xml->read()) 13955 { 13956 switch ($xml->nodeType) 13957 { 13958 13959 case constant('XMLReader::END_ELEMENT'): 13960 if ($xml->namespaceURI !== '') 13961 { 13962 $tagName = $xml->namespaceURI . $this->separator . $xml->localName; 13963 } 13964 else 13965 { 13966 $tagName = $xml->localName; 13967 } 13968 $this->tag_close(null, $tagName); 13969 break; 13970 case constant('XMLReader::ELEMENT'): 13971 $empty = $xml->isEmptyElement; 13972 if ($xml->namespaceURI !== '') 13973 { 13974 $tagName = $xml->namespaceURI . $this->separator . $xml->localName; 13975 } 13976 else 13977 { 13978 $tagName = $xml->localName; 13979 } 13980 $attributes = array(); 13981 while ($xml->moveToNextAttribute()) 13982 { 13983 if ($xml->namespaceURI !== '') 13984 { 13985 $attrName = $xml->namespaceURI . $this->separator . $xml->localName; 13986 } 13987 else 13988 { 13989 $attrName = $xml->localName; 13990 } 13991 $attributes[$attrName] = $xml->value; 13992 } 13993 $this->tag_open(null, $tagName, $attributes); 13994 if ($empty) 13995 { 13996 $this->tag_close(null, $tagName); 13997 } 13998 break; 13999 case constant('XMLReader::TEXT'): 14000 14001 case constant('XMLReader::CDATA'): 14002 $this->cdata(null, $xml->value); 14003 break; 14004 } 14005 } 14006 if ($error = libxml_get_last_error()) 14007 { 14008 $this->error_code = $error->code; 14009 $this->error_string = $error->message; 14010 $this->current_line = $error->line; 14011 $this->current_column = $error->column; 14012 return false; 14013 } 14014 else 14015 { 14016 return true; 14017 } 14018 } 14019 } 14020 14021 public function get_error_code() 14022 { 14023 return $this->error_code; 14024 } 14025 14026 public function get_error_string() 14027 { 14028 return $this->error_string; 14029 } 14030 14031 public function get_current_line() 14032 { 14033 return $this->current_line; 14034 } 14035 14036 public function get_current_column() 14037 { 14038 return $this->current_column; 14039 } 14040 14041 public function get_current_byte() 14042 { 14043 return $this->current_byte; 14044 } 14045 14046 public function get_data() 14047 { 14048 return $this->data; 14049 } 14050 14051 public function tag_open($parser, $tag, $attributes) 14052 { 14053 list($this->namespace[], $this->element[]) = $this->split_ns($tag); 14054 14055 $attribs = array(); 14056 foreach ($attributes as $name => $value) 14057 { 14058 list($attrib_namespace, $attribute) = $this->split_ns($name); 14059 $attribs[$attrib_namespace][$attribute] = $value; 14060 } 14061 14062 if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['base'])) 14063 { 14064 $this->xml_base[] = SimplePie_Misc::absolutize_url($attribs[SIMPLEPIE_NAMESPACE_XML]['base'], end($this->xml_base)); 14065 $this->xml_base_explicit[] = true; 14066 } 14067 else 14068 { 14069 $this->xml_base[] = end($this->xml_base); 14070 $this->xml_base_explicit[] = end($this->xml_base_explicit); 14071 } 14072 14073 if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['lang'])) 14074 { 14075 $this->xml_lang[] = $attribs[SIMPLEPIE_NAMESPACE_XML]['lang']; 14076 } 14077 else 14078 { 14079 $this->xml_lang[] = end($this->xml_lang); 14080 } 14081 14082 if ($this->current_xhtml_construct >= 0) 14083 { 14084 $this->current_xhtml_construct++; 14085 if (end($this->namespace) === SIMPLEPIE_NAMESPACE_XHTML) 14086 { 14087 $this->data['data'] .= '<' . end($this->element); 14088 if (isset($attribs[''])) 14089 { 14090 foreach ($attribs[''] as $name => $value) 14091 { 14092 $this->data['data'] .= ' ' . $name . '="' . htmlspecialchars($value, ENT_COMPAT, $this->encoding) . '"'; 14093 } 14094 } 14095 $this->data['data'] .= '>'; 14096 } 14097 } 14098 else 14099 { 14100 $this->datas[] =& $this->data; 14101 $this->data =& $this->data['child'][end($this->namespace)][end($this->element)][]; 14102 $this->data = array('data' => '', 'attribs' => $attribs, 'xml_base' => end($this->xml_base), 'xml_base_explicit' => end($this->xml_base_explicit), 'xml_lang' => end($this->xml_lang)); 14103 if ((end($this->namespace) === SIMPLEPIE_NAMESPACE_ATOM_03 && in_array(end($this->element), array('title', 'tagline', 'copyright', 'info', 'summary', 'content')) && isset($attribs['']['mode']) && $attribs['']['mode'] === 'xml') 14104 || (end($this->namespace) === SIMPLEPIE_NAMESPACE_ATOM_10 && in_array(end($this->element), array('rights', 'subtitle', 'summary', 'info', 'title', 'content')) && isset($attribs['']['type']) && $attribs['']['type'] === 'xhtml')) 14105 { 14106 $this->current_xhtml_construct = 0; 14107 } 14108 } 14109 } 14110 14111 public function cdata($parser, $cdata) 14112 { 14113 if ($this->current_xhtml_construct >= 0) 14114 { 14115 $this->data['data'] .= htmlspecialchars($cdata, ENT_QUOTES, $this->encoding); 14116 } 14117 else 14118 { 14119 $this->data['data'] .= $cdata; 14120 } 14121 } 14122 14123 public function tag_close($parser, $tag) 14124 { 14125 if ($this->current_xhtml_construct >= 0) 14126 { 14127 $this->current_xhtml_construct--; 14128 if (end($this->namespace) === SIMPLEPIE_NAMESPACE_XHTML && !in_array(end($this->element), array('area', 'base', 'basefont', 'br', 'col', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param'))) 14129 { 14130 $this->data['data'] .= '</' . end($this->element) . '>'; 14131 } 14132 } 14133 if ($this->current_xhtml_construct === -1) 14134 { 14135 $this->data =& $this->datas[count($this->datas) - 1]; 14136 array_pop($this->datas); 14137 } 14138 14139 array_pop($this->element); 14140 array_pop($this->namespace); 14141 array_pop($this->xml_base); 14142 array_pop($this->xml_base_explicit); 14143 array_pop($this->xml_lang); 14144 } 14145 14146 public function split_ns($string) 14147 { 14148 static $cache = array(); 14149 if (!isset($cache[$string])) 14150 { 14151 if ($pos = strpos($string, $this->separator)) 14152 { 14153 static $separator_length; 14154 if (!$separator_length) 14155 { 14156 $separator_length = strlen($this->separator); 14157 } 14158 $namespace = substr($string, 0, $pos); 14159 $local_name = substr($string, $pos + $separator_length); 14160 if (strtolower($namespace) === SIMPLEPIE_NAMESPACE_ITUNES) 14161 { 14162 $namespace = SIMPLEPIE_NAMESPACE_ITUNES; 14163 } 14164 14165 // Normalize the Media RSS namespaces 14166 if ($namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG || 14167 $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2 || 14168 $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3 || 14169 $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4 || 14170 $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5 ) 14171 { 14172 $namespace = SIMPLEPIE_NAMESPACE_MEDIARSS; 14173 } 14174 $cache[$string] = array($namespace, $local_name); 14175 } 14176 else 14177 { 14178 $cache[$string] = array('', $string); 14179 } 14180 } 14181 return $cache[$string]; 14182 } 14183 } 14184 14188 class SimplePie_Sanitize 14189 { 14190 // Private vars 14191 var $base; 14192 14193 // Options 14194 var $remove_div = true; 14195 var $image_handler = ''; 14196 var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'); 14197 var $encode_instead_of_strip = false; 14198 var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'); 14199 var $strip_comments = false; 14200 var $output_encoding = 'UTF-8'; 14201 var $enable_cache = true; 14202 var $cache_location = './cache'; 14203 var $cache_name_function = 'md5'; 14204 var $cache_class = 'SimplePie_Cache'; 14205 var $file_class = 'SimplePie_File'; 14206 var $timeout = 10; 14207 var $useragent = ''; 14208 var $force_fsockopen = false; 14209 14210 var $replace_url_attributes = array( 14211 'a' => 'href', 14212 'area' => 'href', 14213 'blockquote' => 'cite', 14214 'del' => 'cite', 14215 'form' => 'action', 14216 'img' => array('longdesc', 'src'), 14217 'input' => 'src', 14218 'ins' => 'cite', 14219 'q' => 'cite' 14220 ); 14221 14222 public function remove_div($enable = true) 14223 { 14224 $this->remove_div = (bool) $enable; 14225 } 14226 14227 public function set_image_handler($page = false) 14228 { 14229 if ($page) 14230 { 14231 $this->image_handler = (string) $page; 14232 } 14233 else 14234 { 14235 $this->image_handler = false; 14236 } 14237 } 14238 14239 public function pass_cache_data($enable_cache = true, $cache_location = './cache', $cache_name_function = 'md5', $cache_class = 'SimplePie_Cache') 14240 { 14241 if (isset($enable_cache)) 14242 { 14243 $this->enable_cache = (bool) $enable_cache; 14244 } 14245 14246 if ($cache_location) 14247 { 14248 $this->cache_location = (string) $cache_location; 14249 } 14250 14251 if ($cache_name_function) 14252 { 14253 $this->cache_name_function = (string) $cache_name_function; 14254 } 14255 14256 if ($cache_class) 14257 { 14258 $this->cache_class = (string) $cache_class; 14259 } 14260 } 14261 14262 public function pass_file_data($file_class = 'SimplePie_File', $timeout = 10, $useragent = '', $force_fsockopen = false) 14263 { 14264 if ($file_class) 14265 { 14266 $this->file_class = (string) $file_class; 14267 } 14268 14269 if ($timeout) 14270 { 14271 $this->timeout = (string) $timeout; 14272 } 14273 14274 if ($useragent) 14275 { 14276 $this->useragent = (string) $useragent; 14277 } 14278 14279 if ($force_fsockopen) 14280 { 14281 $this->force_fsockopen = (string) $force_fsockopen; 14282 } 14283 } 14284 14285 public function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style')) 14286 { 14287 if ($tags) 14288 { 14289 if (is_array($tags)) 14290 { 14291 $this->strip_htmltags = $tags; 14292 } 14293 else 14294 { 14295 $this->strip_htmltags = explode(',', $tags); 14296 } 14297 } 14298 else 14299 { 14300 $this->strip_htmltags = false; 14301 } 14302 } 14303 14304 public function encode_instead_of_strip($encode = false) 14305 { 14306 $this->encode_instead_of_strip = (bool) $encode; 14307 } 14308 14309 public function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc')) 14310 { 14311 if ($attribs) 14312 { 14313 if (is_array($attribs)) 14314 { 14315 $this->strip_attributes = $attribs; 14316 } 14317 else 14318 { 14319 $this->strip_attributes = explode(',', $attribs); 14320 } 14321 } 14322 else 14323 { 14324 $this->strip_attributes = false; 14325 } 14326 } 14327 14328 public function strip_comments($strip = false) 14329 { 14330 $this->strip_comments = (bool) $strip; 14331 } 14332 14333 public function set_output_encoding($encoding = 'UTF-8') 14334 { 14335 $this->output_encoding = (string) $encoding; 14336 } 14337 14346 public function set_url_replacements($element_attribute = array('a' => 'href', 'area' => 'href', 'blockquote' => 'cite', 'del' => 'cite', 'form' => 'action', 'img' => array('longdesc', 'src'), 'input' => 'src', 'ins' => 'cite', 'q' => 'cite')) 14347 { 14348 $this->replace_url_attributes = (array) $element_attribute; 14349 } 14350 14351 public function sanitize($data, $type, $base = '') 14352 { 14353 $data = trim($data); 14354 if ($data !== '' || $type & SIMPLEPIE_CONSTRUCT_IRI) 14355 { 14356 if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML) 14357 { 14358 if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data)) 14359 { 14360 $type |= SIMPLEPIE_CONSTRUCT_HTML; 14361 } 14362 else 14363 { 14364 $type |= SIMPLEPIE_CONSTRUCT_TEXT; 14365 } 14366 } 14367 14368 if ($type & SIMPLEPIE_CONSTRUCT_BASE64) 14369 { 14370 $data = base64_decode($data); 14371 } 14372 14373 if ($type & SIMPLEPIE_CONSTRUCT_XHTML) 14374 { 14375 if ($this->remove_div) 14376 { 14377 $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '', $data); 14378 $data = preg_replace('/<\/div>$/', '', $data); 14379 } 14380 else 14381 { 14382 $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '<div>', $data); 14383 } 14384 } 14385 14386 if ($type & (SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML)) 14387 { 14388 // Strip comments 14389 if ($this->strip_comments) 14390 { 14391 $data = SimplePie_Misc::strip_comments($data); 14392 } 14393 14394 // Strip out HTML tags and attributes that might cause various security problems. 14395 // Based on recommendations by Mark Pilgrim at: 14396 // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely 14397 if ($this->strip_htmltags) 14398 { 14399 foreach ($this->strip_htmltags as $tag) 14400 { 14401 $pcre = "/<($tag)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$tag" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>|(\/)?>)/siU'; 14402 while (preg_match($pcre, $data)) 14403 { 14404 $data = preg_replace_callback($pcre, array(&$this, 'do_strip_htmltags'), $data); 14405 } 14406 } 14407 } 14408 14409 if ($this->strip_attributes) 14410 { 14411 foreach ($this->strip_attributes as $attrib) 14412 { 14413 $data = preg_replace('/(<[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*)' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . trim($attrib) . '(?:\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>/', '\1\2\3>', $data); 14414 } 14415 } 14416 14417 // Replace relative URLs 14418 $this->base = $base; 14419 foreach ($this->replace_url_attributes as $element => $attributes) 14420 { 14421 $data = $this->replace_urls($data, $element, $attributes); 14422 } 14423 14424 // If image handling (caching, etc.) is enabled, cache and rewrite all the image tags. 14425 if (isset($this->image_handler) && ((string) $this->image_handler) !== '' && $this->enable_cache) 14426 { 14427 $images = SimplePie_Misc::get_element('img', $data); 14428 foreach ($images as $img) 14429 { 14430 if (isset($img['attribs']['src']['data'])) 14431 { 14432 $image_url = call_user_func($this->cache_name_function, $img['attribs']['src']['data']); 14433 $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, $image_url, 'spi'); 14434 14435 if ($cache->load()) 14436 { 14437 $img['attribs']['src']['data'] = $this->image_handler . $image_url; 14438 $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data); 14439 } 14440 else 14441 { 14442 $file = new $this->file_class($img['attribs']['src']['data'], $this->timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen); 14443 $headers = $file->headers; 14444 14445 if ($file->success && ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300))) 14446 { 14447 if ($cache->save(array('headers' => $file->headers, 'body' => $file->body))) 14448 { 14449 $img['attribs']['src']['data'] = $this->image_handler . $image_url; 14450 $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data); 14451 } 14452 else 14453 { 14454 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); 14455 } 14456 } 14457 } 14458 } 14459 } 14460 } 14461 14462 // Having (possibly) taken stuff out, there may now be whitespace at the beginning/end of the data 14463 $data = trim($data); 14464 } 14465 14466 if ($type & SIMPLEPIE_CONSTRUCT_IRI) 14467 { 14468 $data = SimplePie_Misc::absolutize_url($data, $base); 14469 } 14470 14471 if ($type & (SIMPLEPIE_CONSTRUCT_TEXT | SIMPLEPIE_CONSTRUCT_IRI)) 14472 { 14473 $data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8'); 14474 } 14475 14476 if ($this->output_encoding !== 'UTF-8') 14477 { 14478 $data = SimplePie_Misc::change_encoding($data, 'UTF-8', $this->output_encoding); 14479 } 14480 } 14481 return $data; 14482 } 14483 14484 public function replace_urls($data, $tag, $attributes) 14485 { 14486 if (!is_array($this->strip_htmltags) || !in_array($tag, $this->strip_htmltags)) 14487 { 14488 $elements = SimplePie_Misc::get_element($tag, $data); 14489 foreach ($elements as $element) 14490 { 14491 if (is_array($attributes)) 14492 { 14493 foreach ($attributes as $attribute) 14494 { 14495 if (isset($element['attribs'][$attribute]['data'])) 14496 { 14497 $element['attribs'][$attribute]['data'] = SimplePie_Misc::absolutize_url($element['attribs'][$attribute]['data'], $this->base); 14498 $new_element = SimplePie_Misc::element_implode($element); 14499 $data = str_replace($element['full'], $new_element, $data); 14500 $element['full'] = $new_element; 14501 } 14502 } 14503 } 14504 elseif (isset($element['attribs'][$attributes]['data'])) 14505 { 14506 $element['attribs'][$attributes]['data'] = SimplePie_Misc::absolutize_url($element['attribs'][$attributes]['data'], $this->base); 14507 $data = str_replace($element['full'], SimplePie_Misc::element_implode($element), $data); 14508 } 14509 } 14510 } 14511 return $data; 14512 } 14513 14514 public function do_strip_htmltags($match) 14515 { 14516 if ($this->encode_instead_of_strip) 14517 { 14518 if (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style'))) 14519 { 14520 $match[1] = htmlspecialchars($match[1], ENT_COMPAT, 'UTF-8'); 14521 $match[2] = htmlspecialchars($match[2], ENT_COMPAT, 'UTF-8'); 14522 return "<$match[1]$match[2]>$match[3]</$match[1]>"; 14523 } 14524 else 14525 { 14526 return htmlspecialchars($match[0], ENT_COMPAT, 'UTF-8'); 14527 } 14528 } 14529 elseif (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style'))) 14530 { 14531 return $match[4]; 14532 } 14533 else 14534 { 14535 return ''; 14536 } 14537 } 14538 }