48 define(
'SIMPLEPIE_NAME',
'SimplePie');
49 define(
'SIMPLEPIE_VERSION',
'1.3.1');
50 define(
'SIMPLEPIE_BUILD',
'20121030175911');
51 define(
'SIMPLEPIE_URL',
'http://simplepie.org');
54 define(
'SIMPLEPIE_LOCATOR_NONE', 0);
55 define(
'SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1);
56 define(
'SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2);
57 define(
'SIMPLEPIE_LOCATOR_LOCAL_BODY', 4);
58 define(
'SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8);
59 define(
'SIMPLEPIE_LOCATOR_REMOTE_BODY', 16);
60 define(
'SIMPLEPIE_LOCATOR_ALL', 31);
61 define(
'SIMPLEPIE_TYPE_NONE', 0);
62 define(
'SIMPLEPIE_TYPE_RSS_090', 1);
63 define(
'SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2);
64 define(
'SIMPLEPIE_TYPE_RSS_091_USERLAND', 4);
65 define(
'SIMPLEPIE_TYPE_RSS_091', 6);
66 define(
'SIMPLEPIE_TYPE_RSS_092', 8);
67 define(
'SIMPLEPIE_TYPE_RSS_093', 16);
68 define(
'SIMPLEPIE_TYPE_RSS_094', 32);
69 define(
'SIMPLEPIE_TYPE_RSS_10', 64);
70 define(
'SIMPLEPIE_TYPE_RSS_20', 128);
71 define(
'SIMPLEPIE_TYPE_RSS_RDF', 65);
72 define(
'SIMPLEPIE_TYPE_RSS_SYNDICATION', 190);
73 define(
'SIMPLEPIE_TYPE_RSS_ALL', 255);
74 define(
'SIMPLEPIE_TYPE_ATOM_03', 256);
75 define(
'SIMPLEPIE_TYPE_ATOM_10', 512);
76 define(
'SIMPLEPIE_TYPE_ATOM_ALL', 768);
77 define(
'SIMPLEPIE_TYPE_ALL', 1023);
78 define(
'SIMPLEPIE_CONSTRUCT_NONE', 0);
79 define(
'SIMPLEPIE_CONSTRUCT_TEXT', 1);
80 define(
'SIMPLEPIE_CONSTRUCT_HTML', 2);
81 define(
'SIMPLEPIE_CONSTRUCT_XHTML', 4);
82 define(
'SIMPLEPIE_CONSTRUCT_BASE64', 8);
83 define(
'SIMPLEPIE_CONSTRUCT_IRI', 16);
84 define(
'SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32);
85 define(
'SIMPLEPIE_CONSTRUCT_ALL', 63);
86 define(
'SIMPLEPIE_SAME_CASE', 1);
87 define(
'SIMPLEPIE_LOWERCASE', 2);
88 define(
'SIMPLEPIE_UPPERCASE', 4);
89 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]*');
90 define(
'SIMPLEPIE_PCRE_XML_ATTRIBUTE',
'((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*');
91 define(
'SIMPLEPIE_NAMESPACE_XML',
'http://www.w3.org/XML/1998/namespace');
92 define(
'SIMPLEPIE_NAMESPACE_ATOM_10',
'http://www.w3.org/2005/Atom');
93 define(
'SIMPLEPIE_NAMESPACE_ATOM_03',
'http://purl.org/atom/ns#');
94 define(
'SIMPLEPIE_NAMESPACE_RDF',
'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
95 define(
'SIMPLEPIE_NAMESPACE_RSS_090',
'http://my.netscape.com/rdf/simple/0.9/');
96 define(
'SIMPLEPIE_NAMESPACE_RSS_10',
'http://purl.org/rss/1.0/');
97 define(
'SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT',
'http://purl.org/rss/1.0/modules/content/');
98 define(
'SIMPLEPIE_NAMESPACE_RSS_20',
'');
99 define(
'SIMPLEPIE_NAMESPACE_DC_10',
'http://purl.org/dc/elements/1.0/');
100 define(
'SIMPLEPIE_NAMESPACE_DC_11',
'http://purl.org/dc/elements/1.1/');
101 define(
'SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO',
'http://www.w3.org/2003/01/geo/wgs84_pos#');
102 define(
'SIMPLEPIE_NAMESPACE_GEORSS',
'http://www.georss.org/georss');
103 define(
'SIMPLEPIE_NAMESPACE_MEDIARSS',
'http://search.yahoo.com/mrss/');
104 define(
'SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG',
'http://search.yahoo.com/mrss');
105 define(
'SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2',
'http://video.search.yahoo.com/mrss');
106 define(
'SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3',
'http://video.search.yahoo.com/mrss/');
107 define(
'SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4',
'http://www.rssboard.org/media-rss');
108 define(
'SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5',
'http://www.rssboard.org/media-rss/');
109 define(
'SIMPLEPIE_NAMESPACE_ITUNES',
'http://www.itunes.com/dtds/podcast-1.0.dtd');
110 define(
'SIMPLEPIE_NAMESPACE_XHTML',
'http://www.w3.org/1999/xhtml');
111 define(
'SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY',
'http://www.iana.org/assignments/relation/');
112 define(
'SIMPLEPIE_FILE_SOURCE_NONE', 0);
113 define(
'SIMPLEPIE_FILE_SOURCE_REMOTE', 1);
114 define(
'SIMPLEPIE_FILE_SOURCE_LOCAL', 2);
115 define(
'SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4);
116 define(
'SIMPLEPIE_FILE_SOURCE_CURL', 8);
117 define(
'SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16);
173 public $strip_attributes = array(
'bgsound',
'class',
'expr',
'id',
'style',
'onclick',
'onerror',
'onfinish',
'onmouseover',
'onmouseout',
'onfocus',
'onblur',
'lowsrc',
'dynsrc');
175 public $strip_htmltags = array(
'base',
'blink',
'body',
'doctype',
'embed',
'font',
'form',
'frame',
'frameset',
'html',
'iframe',
'input',
'marquee',
'meta',
'noscript',
'object',
'param',
'script',
'style');
179 if (version_compare(PHP_VERSION,
'5.2',
'<'))
181 trigger_error(
'PHP 4.x, 5.0 and 5.1 are no longer supported. Please upgrade to PHP 5.2 or newer.');
187 if (func_num_args() > 0)
189 $level = defined(
'E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
190 trigger_error(
'Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly.', $level);
191 $args = func_get_args();
192 switch (count($args)) {
206 return md5(serialize($this->data));
211 if ((version_compare(PHP_VERSION,
'5.3',
'<') || !gc_enabled()) && !ini_get(
'zend.ze1_compatibility_mode'))
213 if (!empty($this->data[
'items']))
215 foreach ($this->data[
'items'] as $item)
219 unset($item, $this->data[
'items']);
221 if (!empty($this->data[
'ordered_items']))
223 foreach ($this->data[
'ordered_items'] as $item)
227 unset($item, $this->data[
'ordered_items']);
239 $this->multifeed_url = array();
242 foreach (
$url as $value)
244 $this->multifeed_url[] = $this->registry->call(
'Misc',
'fix_protocol', array($value, 1));
249 $this->feed_url = $this->registry->call(
'Misc',
'fix_protocol', array(
$url, 1));
257 $this->feed_url =
$file->url;
258 $this->file =&
$file;
266 $this->raw_data =
$data;
281 $this->cache = (bool) $enable;
286 $this->cache_duration = (int) $seconds;
291 $this->autodiscovery_cache_duration = (int) $seconds;
296 $this->cache_location = (string) $location;
301 $this->order_by_date = (bool) $enable;
308 $this->input_encoding = (string) $encoding;
312 $this->input_encoding =
false;
318 $this->autodiscovery = (int) $level;
329 return $this->registry->register(
'Cache',
$class,
true);
334 return $this->registry->register(
'Locator',
$class,
true);
339 return $this->registry->register(
'Parser',
$class,
true);
344 return $this->registry->register(
'File',
$class,
true);
349 return $this->registry->register(
'Sanitize',
$class,
true);
354 return $this->registry->register(
'Item',
$class,
true);
359 return $this->registry->register(
'Author',
$class,
true);
364 return $this->registry->register(
'Category',
$class,
true);
369 return $this->registry->register(
'Enclosure',
$class,
true);
374 return $this->registry->register(
'Caption',
$class,
true);
379 return $this->registry->register(
'Copyright',
$class,
true);
384 return $this->registry->register(
'Credit',
$class,
true);
389 return $this->registry->register(
'Rating',
$class,
true);
394 return $this->registry->register(
'Restriction',
$class,
true);
399 return $this->registry->register(
'Content_Type_Sniffer',
$class,
true);
404 return $this->registry->register(
'Source',
$class,
true);
410 $this->useragent = (string) $ua;
415 if (is_callable($function))
417 $this->cache_name_function = $function;
436 $this->max_checked_feeds = (int) $max;
440 $this->
sanitize->remove_div($enable);
448 $this->
sanitize->strip_htmltags($tags);
449 if ($encode !== null)
451 $this->
sanitize->encode_instead_of_strip($tags);
456 $this->
sanitize->encode_instead_of_strip($enable);
464 $this->
sanitize->strip_attributes($attribs);
469 $this->
sanitize->set_output_encoding($encoding);
473 $this->
sanitize->strip_comments($strip);
478 $this->
sanitize->set_url_replacements($element_attribute);
485 $this->
sanitize->set_image_handler($page .
'?' . $qs .
'=');
489 $this->image_handler =
'';
495 $this->item_limit = (int) $limit;
501 if (!extension_loaded(
'xml') || !extension_loaded(
'pcre'))
506 elseif (!extension_loaded(
'xmlreader'))
508 static $xml_is_sane = null;
509 if ($xml_is_sane === null)
511 $parser_check = xml_parser_create();
512 xml_parse_into_struct($parser_check,
'<foo>&</foo>', $values);
513 xml_parser_free($parser_check);
514 $xml_is_sane = isset($values[0][
'value']);
521 if (method_exists($this->
sanitize,
'set_registry'))
523 $this->
sanitize->set_registry($this->registry);
527 $this->
sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class(
'Cache'));
529 if (!empty($this->multifeed_url))
533 $this->multifeed_objects = array();
534 $this->
error = array();
535 foreach ($this->multifeed_url as
$url)
537 $this->multifeed_objects[
$i] = clone $this;
538 $this->multifeed_objects[
$i]->set_feed_url($url);
539 $single_success = $this->multifeed_objects[
$i]->init();
540 $success |= $single_success;
541 if (!$single_success)
543 $this->
error[
$i] = $this->multifeed_objects[
$i]->error();
547 return (
bool) $success;
549 elseif ($this->feed_url === null && $this->raw_data === null)
554 $this->data = array();
555 $this->multifeed_objects = array();
557 if ($this->feed_url !== null)
559 $parsed_feed_url = $this->registry->call(
'Misc',
'parse_url', array($this->feed_url));
561 if ($this->cache && $parsed_feed_url[
'scheme'] !==
'')
563 $cache = $this->registry->call(
'Cache',
'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url),
'spc'));
570 elseif ($fetched ===
false) {
573 list($headers, $sniffed) = $fetched;
576 $encodings = array();
578 if ($this->input_encoding !==
false)
582 $application_types = array(
'application/xml',
'application/xml-dtd',
'application/xml-external-parsed-entity');
583 $text_types = array(
'text/xml',
'text/xml-external-parsed-entity');
587 if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) ===
'application/' && substr($sniffed, -4) ===
'+xml')
589 if (isset($headers[
'content-type']) && preg_match(
'/;\x20?charset=([^;]*)/i', $headers[
'content-type'], $charset))
591 $encodings[] = strtoupper($charset[1]);
593 $encodings = array_merge($encodings, $this->registry->call(
'Misc',
'xml_encoding', array($this->raw_data, &$this->registry)));
594 $encodings[] =
'UTF-8';
596 elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) ===
'text/' && substr($sniffed, -4) ===
'+xml')
598 if (isset($headers[
'content-type']) && preg_match(
'/;\x20?charset=([^;]*)/i', $headers[
'content-type'], $charset))
600 $encodings[] = $charset[1];
602 $encodings[] =
'US-ASCII';
605 elseif (substr($sniffed, 0, 5) ===
'text/')
607 $encodings[] =
'US-ASCII';
611 $encodings = array_merge($encodings, $this->registry->call(
'Misc',
'xml_encoding', array($this->raw_data, &$this->registry)));
612 $encodings[] =
'UTF-8';
613 $encodings[] =
'ISO-8859-1';
615 $encodings = array_unique($encodings);
617 foreach ($encodings as $encoding)
620 if ($utf8_data = $this->registry->call(
'Misc',
'change_encoding', array($this->raw_data, $encoding,
'UTF-8')))
623 $parser = $this->registry->create(
'Parser');
625 if ($parser->parse($utf8_data,
'UTF-8'))
627 $this->data = $parser->get_data();
630 $this->
error =
"A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";
631 $this->registry->call(
'Misc',
'error', array($this->
error, E_USER_NOTICE, __FILE__, __LINE__));
636 $this->data[
'headers'] = $headers;
642 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);
651 $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());
655 $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.';
657 $this->registry->call(
'Misc',
'error', array($this->
error, E_USER_NOTICE, __FILE__, __LINE__));
667 $this->data =
$cache->load();
668 if (!empty($this->data))
671 if (!isset($this->data[
'build']) || $this->data[
'build'] !==
SIMPLEPIE_BUILD)
674 $this->data = array();
677 elseif (isset($this->data[
'url']) && $this->data[
'url'] !== $this->feed_url)
680 $this->data = array();
683 elseif (isset($this->data[
'feed_url']))
686 if (
$cache->mtime() + $this->autodiscovery_cache_duration > time())
689 if ($this->data[
'feed_url'] !== $this->data[
'url'])
692 return $this->
init();
695 $this->data = array();
699 elseif (
$cache->mtime() + $this->cache_duration < time())
702 if (isset($this->data[
'headers'][
'last-modified']) || isset($this->data[
'headers'][
'etag']))
705 'Accept' =>
'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
707 if (isset($this->data[
'headers'][
'last-modified']))
709 $headers[
'if-modified-since'] = $this->data[
'headers'][
'last-modified'];
711 if (isset($this->data[
'headers'][
'etag']))
713 $headers[
'if-none-match'] = $this->data[
'headers'][
'etag'];
715 $file = $this->registry->create(
'File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->
force_fsockopen));
718 if (
$file->status_code === 304)
733 $this->raw_data =
false;
741 $this->data = array();
747 if ($this->file instanceof
SimplePie_File && $this->file->url === $this->feed_url)
754 'Accept' =>
'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
756 $file = $this->registry->create(
'File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->
force_fsockopen));
763 return !empty($this->data);
768 $locate = $this->registry->create(
'Locator', array(&
$file, $this->timeout, $this->useragent, $this->max_checked_feeds));
769 if (!$locate->is_feed(
$file))
775 if (!(
$file = $locate->find($this->autodiscovery, $this->all_discovered_feeds)))
777 $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.";
778 $this->registry->call(
'Misc',
'error', array($this->
error, E_USER_NOTICE, __FILE__, __LINE__));
785 $this->
error = $e->getMessage();
786 $this->registry->call(
'Misc',
'error', array($this->
error, E_USER_NOTICE, $e->getFile(), $e->getLine()));
791 $this->data = array(
'url' => $this->feed_url,
'feed_url' =>
$file->url,
'build' =>
SIMPLEPIE_BUILD);
794 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);
796 $cache = $this->registry->call(
'Cache',
'get_handler', array($this->cache_location, call_user_func($this->cache_name_function,
$file->url),
'spc'));
798 $this->feed_url =
$file->url;
802 $this->raw_data =
$file->body;
803 $headers =
$file->headers;
804 $sniffer = $this->registry->create(
'Content_Type_Sniffer', array(&
$file));
805 $sniffed = $sniffer->get_type();
806 return array($headers, $sniffed);
821 return $this->
sanitize->output_encoding;
828 $header =
"Content-type: $mime;";
835 $header .=
' charset=UTF-8';
843 if (!isset($this->data[
'type']))
857 || isset($this->data[
'child'][SIMPLEPIE_NAMESPACE_RDF][
'RDF'][0][
'child'][SIMPLEPIE_NAMESPACE_RSS_10][
'image'])
858 || isset($this->data[
'child'][SIMPLEPIE_NAMESPACE_RDF][
'RDF'][0][
'child'][SIMPLEPIE_NAMESPACE_RSS_10][
'item'])
859 || isset($this->data[
'child'][SIMPLEPIE_NAMESPACE_RDF][
'RDF'][0][
'child'][SIMPLEPIE_NAMESPACE_RSS_10][
'textinput']))
864 || isset($this->data[
'child'][SIMPLEPIE_NAMESPACE_RDF][
'RDF'][0][
'child'][SIMPLEPIE_NAMESPACE_RSS_090][
'image'])
865 || isset($this->data[
'child'][SIMPLEPIE_NAMESPACE_RDF][
'RDF'][0][
'child'][SIMPLEPIE_NAMESPACE_RSS_090][
'item'])
866 || isset($this->data[
'child'][SIMPLEPIE_NAMESPACE_RDF][
'RDF'][0][
'child'][SIMPLEPIE_NAMESPACE_RSS_090][
'textinput']))
874 if (isset($this->data[
'child'][SIMPLEPIE_NAMESPACE_RSS_20][
'rss'][0][
'attribs'][
''][
'version']))
876 switch (trim($this->data[
'child'][SIMPLEPIE_NAMESPACE_RSS_20][
'rss'][0][
'attribs'][
''][
'version']))
880 if (isset($this->data[
'child'][SIMPLEPIE_NAMESPACE_RSS_20][
'rss'][0][
'child'][SIMPLEPIE_NAMESPACE_RSS_20][
'skiphours'][
'hour'][0][
'data']))
882 switch (trim($this->data[
'child'][SIMPLEPIE_NAMESPACE_RSS_20][
'rss'][0][
'child'][SIMPLEPIE_NAMESPACE_RSS_20][
'skiphours'][
'hour'][0][
'data']))
913 return $this->data[
'type'];
918 if ($this->feed_url !== null)
976 if (isset($channel[0][
'child'][$namespace][$tag]))
978 return $channel[0][
'child'][$namespace][$tag];
986 if (isset($channel[0][
'child'][$namespace][$tag]))
988 return $channel[0][
'child'][$namespace][$tag];
996 if (isset($channel[0][
'child'][$namespace][$tag]))
998 return $channel[0][
'child'][$namespace][$tag];
1012 if (isset($image[0][
'child'][$namespace][$tag]))
1014 return $image[0][
'child'][$namespace][$tag];
1022 if (isset($image[0][
'child'][$namespace][$tag]))
1024 return $image[0][
'child'][$namespace][$tag];
1032 if (isset($image[0][
'child'][$namespace][$tag]))
1034 return $image[0][
'child'][$namespace][$tag];
1045 return $element[
'xml_base'];
1066 return $this->
sanitize($return[0][
'data'], $this->registry->call(
'Misc',
'atom_10_construct_type', array($return[0][
'attribs'])), $this->
get_base($return[0]));
1070 return $this->
sanitize($return[0][
'data'], $this->registry->call(
'Misc',
'atom_03_construct_type', array($return[0][
'attribs'])), $this->
get_base($return[0]));
1101 if (isset($categories[$key]))
1103 return $categories[$key];
1113 $categories = array();
1119 if (isset($category[
'attribs'][
''][
'term']))
1123 if (isset($category[
'attribs'][
''][
'scheme']))
1127 if (isset($category[
'attribs'][
''][
'label']))
1131 $categories[] = $this->registry->create(
'Category', array($term, $scheme, $label));
1138 if (isset($category[
'attribs'][
''][
'domain']))
1146 $categories[] = $this->registry->create(
'Category', array($term, $scheme, null));
1156 if (!empty($categories))
1158 return array_unique($categories);
1169 if (isset($authors[$key]))
1171 return $authors[$key];
1191 if (isset($author[
'child'][SIMPLEPIE_NAMESPACE_ATOM_10][
'uri'][0][
'data']))
1195 if (isset($author[
'child'][SIMPLEPIE_NAMESPACE_ATOM_10][
'email'][0][
'data']))
1199 if ($name !== null || $email !== null || $uri !== null)
1201 $authors[] = $this->registry->create(
'Author', array($name, $uri, $email));
1213 if (isset($author[0][
'child'][SIMPLEPIE_NAMESPACE_ATOM_03][
'url'][0][
'data']))
1217 if (isset($author[0][
'child'][SIMPLEPIE_NAMESPACE_ATOM_03][
'email'][0][
'data']))
1221 if ($name !== null || $email !== null ||
$url !== null)
1223 $authors[] = $this->registry->create(
'Author', array($name,
$url, $email));
1238 if (!empty($authors))
1240 return array_unique($authors);
1251 if (isset($contributors[$key]))
1253 return $contributors[$key];
1263 $contributors = array();
1273 if (isset($contributor[
'child'][SIMPLEPIE_NAMESPACE_ATOM_10][
'uri'][0][
'data']))
1275 $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]));
1277 if (isset($contributor[
'child'][SIMPLEPIE_NAMESPACE_ATOM_10][
'email'][0][
'data']))
1281 if ($name !== null || $email !== null || $uri !== null)
1283 $contributors[] = $this->registry->create(
'Author', array($name, $uri, $email));
1295 if (isset($contributor[
'child'][SIMPLEPIE_NAMESPACE_ATOM_03][
'url'][0][
'data']))
1299 if (isset($contributor[
'child'][SIMPLEPIE_NAMESPACE_ATOM_03][
'email'][0][
'data']))
1303 if ($name !== null || $email !== null ||
$url !== null)
1305 $contributors[] = $this->registry->create(
'Author', array($name,
$url, $email));
1308 if (!empty($contributors))
1310 return array_unique($contributors);
1321 if (isset($links[$key]))
1323 return $links[$key];
1338 if (!isset($this->data[
'links']))
1340 $this->data[
'links'] = array();
1343 foreach ($links as $link)
1345 if (isset($link[
'attribs'][
''][
'href']))
1347 $link_rel = (isset($link[
'attribs'][
''][
'rel'])) ? $link[
'attribs'][
''][
'rel'] :
'alternate';
1354 foreach ($links as $link)
1356 if (isset($link[
'attribs'][
''][
'href']))
1358 $link_rel = (isset($link[
'attribs'][
''][
'rel'])) ? $link[
'attribs'][
''][
'rel'] :
'alternate';
1375 $keys = array_keys($this->data[
'links']);
1376 foreach ($keys as $key)
1378 if ($this->registry->call(
'Misc',
'is_isegment_nz_nc', array($key)))
1392 $this->data[
'links'][substr($key, 41)] =& $this->data[
'links'][$key];
1394 $this->data[
'links'][$key] = array_unique($this->data[
'links'][$key]);
1397 if (isset($this->data[
'links'][$rel]))
1399 return $this->data[
'links'][$rel];
1415 return $this->
sanitize($return[0][
'data'], $this->registry->call(
'Misc',
'atom_10_construct_type', array($return[0][
'attribs'])), $this->
get_base($return[0]));
1419 return $this->
sanitize($return[0][
'data'], $this->registry->call(
'Misc',
'atom_03_construct_type', array($return[0][
'attribs'])), $this->
get_base($return[0]));
1459 return $this->
sanitize($return[0][
'data'], $this->registry->call(
'Misc',
'atom_10_construct_type', array($return[0][
'attribs'])), $this->
get_base($return[0]));
1463 return $this->
sanitize($return[0][
'data'], $this->registry->call(
'Misc',
'atom_03_construct_type', array($return[0][
'attribs'])), $this->
get_base($return[0]));
1509 elseif (isset($this->data[
'headers'][
'content-language']))
1523 return (
float) $return[0][
'data'];
1527 return (
float)
$match[1];
1539 return (
float) $return[0][
'data'];
1543 return (
float) $return[0][
'data'];
1547 return (
float)
$match[2];
1639 return round($return[0][
'data']);
1655 return round($return[0][
'data']);
1677 return ($qty > $max) ? $max : $qty;
1684 if (isset($items[$key]))
1686 return $items[$key];
1696 if (!isset($this->data[
'items']))
1698 if (!empty($this->multifeed_objects))
1704 $this->data[
'items'] = array();
1707 $keys = array_keys($items);
1708 foreach ($keys as $key)
1710 $this->data[
'items'][] = $this->registry->create(
'Item', array($this, $items[$key]));
1715 $keys = array_keys($items);
1716 foreach ($keys as $key)
1718 $this->data[
'items'][] = $this->registry->create(
'Item', array($this, $items[$key]));
1723 $keys = array_keys($items);
1724 foreach ($keys as $key)
1726 $this->data[
'items'][] = $this->registry->create(
'Item', array($this, $items[$key]));
1731 $keys = array_keys($items);
1732 foreach ($keys as $key)
1734 $this->data[
'items'][] = $this->registry->create(
'Item', array($this, $items[$key]));
1739 $keys = array_keys($items);
1740 foreach ($keys as $key)
1742 $this->data[
'items'][] = $this->registry->create(
'Item', array($this, $items[$key]));
1747 if (!empty($this->data[
'items']))
1750 if ($this->order_by_date && empty($this->multifeed_objects))
1752 if (!isset($this->data[
'ordered_items']))
1755 foreach ($this->data[
'items'] as $item)
1757 if (!$item->get_date(
'U'))
1764 $this->data[
'ordered_items'] = $this->data[
'items'];
1767 usort($this->data[
'ordered_items'], array(get_class($this),
'sort_items'));
1770 $items = $this->data[
'ordered_items'];
1774 $items = $this->data[
'items'];
1779 return array_slice($items,
$start);
1783 return array_slice($items,
$start, $end);
1794 $level = defined(
'E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
1795 trigger_error(
'Favicon handling has been removed, please use your own handling', $level);
1801 $level = defined(
'E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
1802 trigger_error(
'Favicon handling has been removed, please use your own handling', $level);
1805 return 'http://g.etfv.co/' . urlencode(
$url);
1812 if (strpos($method,
'subscribe_') === 0)
1814 $level = defined(
'E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
1815 trigger_error(
'subscribe_*() has been deprecated, implement the callback yourself', $level);
1818 if ($method ===
'enable_xml_dump')
1820 $level = defined(
'E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
1821 trigger_error(
'enable_xml_dump() has been deprecated, use get_raw_data() instead', $level);
1824 $class = get_class($this);
1825 $trace = debug_backtrace();
1826 $file = $trace[0][
'file'];
1827 $line = $trace[0][
'line'];
1828 trigger_error(
"Call to undefined method $class::$method() in $file on line $line", E_USER_ERROR);
1833 return $a->get_date(
'U') <= $b->get_date(
'U');
1838 if (is_array($urls) &&
sizeof($urls) > 0)
1841 foreach ($urls as $arg)
1845 $items = array_merge($items, $arg->get_items(0, $limit));
1849 trigger_error(
'Arguments must be SimplePie objects', E_USER_WARNING);
1853 foreach ($items as $item)
1855 if (!$item->get_date(
'U'))
1864 usort($items, array(get_class($urls[0]),
'sort_items'));
1868 return array_slice($items,
$start);
1872 return array_slice($items,
$start, $end);
1877 trigger_error(
'Cannot merge zero SimplePie objects', E_USER_WARNING);
1891 public function __construct($name = null, $link = null, $email = null)
1893 $this->name =
$name;
1894 $this->link =
$link;
1901 return md5(serialize($this));
1906 if ($this->name !== null)
1918 if ($this->link !== null)
1930 if ($this->email !== null)
1947 public function __construct($location, $name, $type);
1951 public function load();
1953 public function mtime();
1955 public function touch();
1957 public function unlink();
1964 $items =
$data->get_items();
1965 $items_by_id = array();
1968 foreach ($items as $item)
1970 $items_by_id[$item->get_id()] = $item;
1972 if (count($items_by_id) !== count($items))
1974 $items_by_id = array();
1975 foreach ($items as $item)
1977 $items_by_id[$item->get_id(
true)] = $item;
2000 if ($channel !== null)
2004 unset($channel[
'child'][SIMPLEPIE_NAMESPACE_ATOM_10][
'entry']);
2008 unset($channel[
'child'][SIMPLEPIE_NAMESPACE_ATOM_03][
'entry']);
2012 unset($channel[
'child'][SIMPLEPIE_NAMESPACE_RSS_10][
'item']);
2016 unset($channel[
'child'][SIMPLEPIE_NAMESPACE_RSS_090][
'item']);
2018 if (isset($channel[
'child'][SIMPLEPIE_NAMESPACE_RSS_20][
'item']))
2020 unset($channel[
'child'][SIMPLEPIE_NAMESPACE_RSS_20][
'item']);
2023 if (isset(
$data->data[
'items']))
2025 unset(
$data->data[
'items']);
2027 if (isset(
$data->data[
'ordered_items']))
2029 unset(
$data->data[
'ordered_items']);
2032 return array(serialize(
$data->data), $items_by_id);
2049 $this->filename =
$name;
2050 $this->extension = $type;
2051 $this->name =
"$this->location/$this->filename.$this->extension";
2056 if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
2063 return (
bool) file_put_contents($this->name,
$data);
2070 if (file_exists($this->name) && is_readable($this->name))
2072 return unserialize(file_get_contents($this->name));
2079 if (file_exists($this->name))
2081 return filemtime($this->name);
2088 if (file_exists($this->name))
2090 return touch($this->name);
2097 if (file_exists($this->name))
2099 return unlink($this->name);
2115 $this->options = array(
2116 'host' =>
'127.0.0.1',
2120 'prefix' =>
'simplepie_',
2124 $this->options[
'host'] = empty($parsed[
'host']) ? $this->options[
'host'] : $parsed[
'host'];
2125 $this->options[
'port'] = empty($parsed[
'port']) ? $this->options[
'port'] : $parsed[
'port'];
2126 $this->options[
'extras'] = array_merge($this->options[
'extras'], $parsed[
'extras']);
2127 $this->name = $this->options[
'extras'][
'prefix'] . md5(
"$name:$type");
2128 $this->cache =
new Memcache();
2129 $this->cache->addServer($this->options[
'host'], (
int) $this->options[
'port']);
2138 return $this->cache->set($this->name, serialize(
$data), MEMCACHE_COMPRESSED, (
int) $this->options[
'extras'][
'timeout']);
2143 $data = $this->cache->get($this->name);
2144 if (
$data !==
false)
2146 return unserialize(
$data);
2153 $data = $this->cache->get($this->name);
2154 if (
$data !==
false)
2164 $data = $this->cache->get($this->name);
2165 if (
$data !==
false)
2167 return $this->cache->set($this->name,
$data, MEMCACHE_COMPRESSED, (
int) $this->duration);
2174 return $this->cache->delete($this->name, 0);
2188 $this->options = array(
2191 'host' =>
'127.0.0.1',
2200 $this->options[
'dbname'] = substr($this->options[
'path'], 1);
2203 $this->mysql =
new PDO(
"mysql:dbname={$this->options['dbname']};host={$this->options['host']};port={$this->options['port']}", $this->options[
'user'], $this->options[
'pass'], array(PDO::MYSQL_ATTR_INIT_COMMAND =>
'SET NAMES utf8'));
2205 catch (PDOException $e)
2207 $this->mysql = null;
2210 $this->
id = $name . $type;
2211 if (!
$query = $this->mysql->query(
'SHOW TABLES'))
2213 $this->mysql = null;
2217 while ($row =
$query->fetchColumn())
2221 if (!in_array($this->options[
'extras'][
'prefix'] .
'cache_data', $db))
2223 $query = $this->mysql->exec(
'CREATE TABLE `' . $this->options[
'extras'][
'prefix'] .
'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)))');
2226 $this->mysql = null;
2229 if (!in_array($this->options[
'extras'][
'prefix'] .
'items', $db))
2231 $query = $this->mysql->exec(
'CREATE TABLE `' . $this->options[
'extras'][
'prefix'] .
'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)))');
2234 $this->mysql = null;
2241 if ($this->mysql === null)
2248 $prepared = self::prepare_simplepie_object_for_cache($data);
2249 $query = $this->mysql->prepare(
'SELECT COUNT(*) FROM `' . $this->options[
'extras'][
'prefix'] .
'cache_data` WHERE `id` = :feed');
2250 $query->bindValue(
':feed', $this->
id);
2253 if (
$query->fetchColumn() > 0)
2255 $items = count($prepared[1]);
2258 $sql =
'UPDATE `' . $this->options[
'extras'][
'prefix'] .
'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed';
2260 $query->bindValue(
':items', $items);
2264 $sql =
'UPDATE `' . $this->options[
'extras'][
'prefix'] .
'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed';
2267 $query->bindValue(
':data', $prepared[0]);
2268 $query->bindValue(
':time', time());
2269 $query->bindValue(
':feed', $this->
id);
2277 $query = $this->mysql->prepare(
'INSERT INTO `' . $this->options[
'extras'][
'prefix'] .
'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:feed, :count, :data, :time)');
2278 $query->bindValue(
':feed', $this->
id);
2279 $query->bindValue(
':count', count($prepared[1]));
2280 $query->bindValue(
':data', $prepared[0]);
2281 $query->bindValue(
':time', time());
2287 $ids = array_keys($prepared[1]);
2290 foreach ($ids as
$id)
2292 $database_ids[] = $this->mysql->quote($id);
2294 $query = $this->mysql->prepare(
'SELECT `id` FROM `' . $this->options[
'extras'][
'prefix'] .
'items` WHERE `id` = ' . implode(
' OR `id` = ', $database_ids) .
' AND `feed_id` = :feed');
2295 $query->bindValue(
':feed', $this->
id);
2298 $existing_ids = array();
2299 while ($row =
$query->fetchColumn())
2301 $existing_ids[] = $row;
2303 $new_ids = array_diff($ids, $existing_ids);
2304 foreach ($new_ids as $new_id)
2306 if (!($date = $prepared[1][$new_id]->get_date(
'U')))
2310 $query = $this->mysql->prepare(
'INSERT INTO `' . $this->options[
'extras'][
'prefix'] .
'items` (`feed_id`, `id`, `data`, `posted`) VALUES(:feed, :id, :data, :date)');
2311 $query->bindValue(
':feed', $this->
id);
2312 $query->bindValue(
':id', $new_id);
2313 $query->bindValue(
':data', serialize($prepared[1][$new_id]->data));
2314 $query->bindValue(
':date', $date);
2331 $query = $this->mysql->prepare(
'SELECT `id` FROM `' . $this->options[
'extras'][
'prefix'] .
'cache_data` WHERE `id` = :feed');
2332 $query->bindValue(
':feed', $this->
id);
2335 if (
$query->rowCount() > 0)
2337 $query = $this->mysql->prepare(
'UPDATE `' . $this->options[
'extras'][
'prefix'] .
'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed');
2339 $query->bindValue(
':time', time());
2340 $query->bindValue(
':feed', $this->
id);
2341 if ($this->execute())
2348 $query = $this->mysql->prepare(
'INSERT INTO `' . $this->options[
'extras'][
'prefix'] .
'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:id, 0, :data, :time)');
2349 $query->bindValue(
':id', $this->
id);
2351 $query->bindValue(
':time', time());
2364 if ($this->mysql === null)
2368 $query = $this->mysql->prepare(
'SELECT `items`, `data` FROM `' . $this->options[
'extras'][
'prefix'] .
'cache_data` WHERE `id` = :id');
2369 $query->bindValue(
':id', $this->
id);
2372 $data = unserialize($row[1]);
2373 if (isset($this->options[
'items'][0]))
2375 $items = (int) $this->options[
'items'][0];
2379 $items = (int) $row[0];
2405 $sql =
'SELECT `data` FROM `' . $this->options[
'extras'][
'prefix'] .
'items` WHERE `feed_id` = :feed ORDER BY `posted` DESC';
2408 $sql .=
' LIMIT ' . $items;
2411 $query->bindValue(
':feed', $this->
id);
2414 while ($row =
$query->fetchColumn())
2432 if ($this->mysql === null)
2436 $query = $this->mysql->prepare(
'SELECT `mtime` FROM `' . $this->options[
'extras'][
'prefix'] .
'cache_data` WHERE `id` = :id');
2437 $query->bindValue(
':id', $this->
id);
2438 if (
$query->execute() && ($time =
$query->fetchColumn()))
2450 if ($this->mysql === null)
2454 $query = $this->mysql->prepare(
'UPDATE `' . $this->options[
'extras'][
'prefix'] .
'cache_data` SET `mtime` = :time WHERE `id` = :id');
2455 $query->bindValue(
':time', time());
2456 $query->bindValue(
':id', $this->
id);
2469 if ($this->mysql === null)
2473 $query = $this->mysql->prepare(
'DELETE FROM `' . $this->options[
'extras'][
'prefix'] .
'cache_data` WHERE `id` = :id');
2474 $query->bindValue(
':id', $this->
id);
2475 $query2 = $this->mysql->prepare(
'DELETE FROM `' . $this->options[
'extras'][
'prefix'] .
'items` WHERE `feed_id` = :id');
2476 $query2->bindValue(
':id', $this->
id);
2477 if (
$query->execute() && $query2->execute())
2491 'mysql' =>
'SimplePie_Cache_MySQL',
2492 'memcache' =>
'SimplePie_Cache_Memcache',
2495 private function __construct() { }
2499 $type = explode(
':', $location, 2);
2501 if (!empty(self::$handlers[$type]))
2503 $class = self::$handlers[$type];
2511 trigger_error(
'Cache::create() has been replaced with Cache::get_handler(). Switch to the registry system to use this.', E_USER_DEPRECATED);
2515 public static function register($type,
$class)
2517 self::$handlers[$type] =
$class;
2522 $params = parse_url(
$url);
2523 $params[
'extras'] = array();
2524 if (isset($params[
'query']))
2526 parse_str($params[
'query'], $params[
'extras']);
2544 public function __construct($type = null, $lang = null, $startTime = null, $endTime = null, $text = null)
2546 $this->type =
$type;
2547 $this->lang =
$lang;
2550 $this->text =
$text;
2556 return md5(serialize($this));
2561 if ($this->endTime !== null)
2573 if ($this->lang !== null)
2585 if ($this->startTime !== null)
2597 if ($this->text !== null)
2609 if ($this->type !== null)
2628 public function __construct($term = null, $scheme = null, $label = null)
2630 $this->term =
$term;
2638 return md5(serialize($this));
2643 if ($this->term !== null)
2655 if ($this->scheme !== null)
2667 if ($this->label !== null)
2684 $this->file =
$file;
2689 if (isset($this->file->headers[
'content-type']))
2691 if (!isset($this->file->headers[
'content-encoding'])
2692 && ($this->file->headers[
'content-type'] ===
'text/plain'
2693 || $this->file->headers[
'content-type'] ===
'text/plain; charset=ISO-8859-1'
2694 || $this->file->headers[
'content-type'] ===
'text/plain; charset=iso-8859-1'
2695 || $this->file->headers[
'content-type'] ===
'text/plain; charset=UTF-8'))
2699 if (($pos = strpos($this->file->headers[
'content-type'],
';')) !==
false)
2701 $official = substr($this->file->headers[
'content-type'], 0, $pos);
2705 $official = $this->file->headers[
'content-type'];
2707 $official = trim(strtolower($official));
2708 if ($official ===
'unknown/unknown'
2709 || $official ===
'application/unknown')
2713 elseif (substr($official, -4) ===
'+xml'
2714 || $official ===
'text/xml'
2715 || $official ===
'application/xml')
2719 elseif (substr($official, 0, 6) ===
'image/')
2721 if ($return = $this->
image())
2730 elseif ($official ===
'text/html')
2747 if (substr($this->file->body, 0, 2) ===
"\xFE\xFF"
2748 || substr($this->file->body, 0, 2) ===
"\xFF\xFE"
2749 || substr($this->file->body, 0, 4) ===
"\x00\x00\xFE\xFF"
2750 || substr($this->file->body, 0, 3) ===
"\xEF\xBB\xBF")
2752 return 'text/plain';
2754 elseif (preg_match(
'/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body))
2756 return 'application/octect-stream';
2760 return 'text/plain';
2766 $ws = strspn($this->file->body,
"\x09\x0A\x0B\x0C\x0D\x20");
2767 if (strtolower(substr($this->file->body, $ws, 14)) ===
'<!doctype html'
2768 || strtolower(substr($this->file->body, $ws, 5)) ===
'<html'
2769 || strtolower(substr($this->file->body, $ws, 7)) ===
'<script')
2773 elseif (substr($this->file->body, 0, 5) ===
'%PDF-')
2775 return 'application/pdf';
2777 elseif (substr($this->file->body, 0, 11) ===
'%!PS-Adobe-')
2779 return 'application/postscript';
2781 elseif (substr($this->file->body, 0, 6) ===
'GIF87a'
2782 || substr($this->file->body, 0, 6) ===
'GIF89a')
2786 elseif (substr($this->file->body, 0, 8) ===
"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
2790 elseif (substr($this->file->body, 0, 3) ===
"\xFF\xD8\xFF")
2792 return 'image/jpeg';
2794 elseif (substr($this->file->body, 0, 2) ===
"\x42\x4D")
2798 elseif (substr($this->file->body, 0, 4) ===
"\x00\x00\x01\x00")
2800 return 'image/vnd.microsoft.icon';
2810 if (substr($this->file->body, 0, 6) ===
'GIF87a'
2811 || substr($this->file->body, 0, 6) ===
'GIF89a')
2815 elseif (substr($this->file->body, 0, 8) ===
"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
2819 elseif (substr($this->file->body, 0, 3) ===
"\xFF\xD8\xFF")
2821 return 'image/jpeg';
2823 elseif (substr($this->file->body, 0, 2) ===
"\x42\x4D")
2827 elseif (substr($this->file->body, 0, 4) ===
"\x00\x00\x01\x00")
2829 return 'image/vnd.microsoft.icon';
2839 $len = strlen($this->file->body);
2840 $pos = strspn($this->file->body,
"\x09\x0A\x0D\x20");
2843 switch ($this->file->body[$pos])
2849 $pos += strspn($this->file->body,
"\x09\x0A\x0D\x20", $pos);
2857 if (substr($this->file->body, $pos, 3) ===
'!--')
2860 if ($pos < $len && ($pos = strpos($this->file->body,
'-->', $pos)) !==
false)
2869 elseif (substr($this->file->body, $pos, 1) ===
'!')
2871 if ($pos < $len && ($pos = strpos($this->file->body,
'>', $pos)) !==
false)
2880 elseif (substr($this->file->body, $pos, 1) ===
'?')
2882 if ($pos < $len && ($pos = strpos($this->file->body,
'?>', $pos)) !==
false)
2891 elseif (substr($this->file->body, $pos, 3) ===
'rss'
2892 || substr($this->file->body, $pos, 7) ===
'rdf:RDF')
2894 return 'application/rss+xml';
2896 elseif (substr($this->file->body, $pos, 4) ===
'feed')
2898 return 'application/atom+xml';
2924 return md5(serialize($this));
2929 if ($this->url !== null)
2941 if ($this->label !== null)
2963 public function __construct($role = null, $scheme = null, $name = null)
2965 $this->role =
$role;
2967 $this->name =
$name;
2973 return md5(serialize($this));
2978 if ($this->role !== null)
2990 if ($this->scheme !== null)
3002 if ($this->name !== null)
3023 $this->data =
$data;
3028 while (($this->position = strpos($this->data,
'&', $this->position)) !==
false)
3032 $this->consumed =
'';
3039 if (isset($this->data[$this->position]))
3042 return $this->data[$this->position++];
3052 if ($len = strspn($this->data, $chars, $this->position))
3054 $data = substr($this->data, $this->position, $len);
3055 $this->consumed .=
$data;
3056 $this->position += $len;
3067 $this->consumed = substr($this->consumed, 0, -1);
3090 $range =
'0123456789ABCDEFabcdef';
3094 $range =
'0123456789';
3101 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");
3104 $codepoint = hexdec($codepoint);
3108 $codepoint = intval($codepoint);
3110 if (isset($windows_1252_specials[$codepoint]))
3112 $replacement = $windows_1252_specials[$codepoint];
3118 if (!in_array($this->
consume(), array(
';',
false),
true))
3122 $consumed_length = strlen($this->consumed);
3123 $this->data = substr_replace($this->data, $replacement, $this->position - $consumed_length, $consumed_length);
3124 $this->position += strlen($replacement) - $consumed_length;
3128 static $entities = array(
3129 'Aacute' =>
"\xC3\x81",
3130 'aacute' =>
"\xC3\xA1",
3131 'Aacute;' =>
"\xC3\x81",
3132 'aacute;' =>
"\xC3\xA1",
3133 'Acirc' =>
"\xC3\x82",
3134 'acirc' =>
"\xC3\xA2",
3135 'Acirc;' =>
"\xC3\x82",
3136 'acirc;' =>
"\xC3\xA2",
3137 'acute' =>
"\xC2\xB4",
3138 'acute;' =>
"\xC2\xB4",
3139 'AElig' =>
"\xC3\x86",
3140 'aelig' =>
"\xC3\xA6",
3141 'AElig;' =>
"\xC3\x86",
3142 'aelig;' =>
"\xC3\xA6",
3143 'Agrave' =>
"\xC3\x80",
3144 'agrave' =>
"\xC3\xA0",
3145 'Agrave;' =>
"\xC3\x80",
3146 'agrave;' =>
"\xC3\xA0",
3147 'alefsym;' =>
"\xE2\x84\xB5",
3148 'Alpha;' =>
"\xCE\x91",
3149 'alpha;' =>
"\xCE\xB1",
3154 'and;' =>
"\xE2\x88\xA7",
3155 'ang;' =>
"\xE2\x88\xA0",
3157 'Aring' =>
"\xC3\x85",
3158 'aring' =>
"\xC3\xA5",
3159 'Aring;' =>
"\xC3\x85",
3160 'aring;' =>
"\xC3\xA5",
3161 'asymp;' =>
"\xE2\x89\x88",
3162 'Atilde' =>
"\xC3\x83",
3163 'atilde' =>
"\xC3\xA3",
3164 'Atilde;' =>
"\xC3\x83",
3165 'atilde;' =>
"\xC3\xA3",
3166 'Auml' =>
"\xC3\x84",
3167 'auml' =>
"\xC3\xA4",
3168 'Auml;' =>
"\xC3\x84",
3169 'auml;' =>
"\xC3\xA4",
3170 'bdquo;' =>
"\xE2\x80\x9E",
3171 'Beta;' =>
"\xCE\x92",
3172 'beta;' =>
"\xCE\xB2",
3173 'brvbar' =>
"\xC2\xA6",
3174 'brvbar;' =>
"\xC2\xA6",
3175 'bull;' =>
"\xE2\x80\xA2",
3176 'cap;' =>
"\xE2\x88\xA9",
3177 'Ccedil' =>
"\xC3\x87",
3178 'ccedil' =>
"\xC3\xA7",
3179 'Ccedil;' =>
"\xC3\x87",
3180 'ccedil;' =>
"\xC3\xA7",
3181 'cedil' =>
"\xC2\xB8",
3182 'cedil;' =>
"\xC2\xB8",
3183 'cent' =>
"\xC2\xA2",
3184 'cent;' =>
"\xC2\xA2",
3185 'Chi;' =>
"\xCE\xA7",
3186 'chi;' =>
"\xCF\x87",
3187 'circ;' =>
"\xCB\x86",
3188 'clubs;' =>
"\xE2\x99\xA3",
3189 'cong;' =>
"\xE2\x89\x85",
3190 'COPY' =>
"\xC2\xA9",
3191 'copy' =>
"\xC2\xA9",
3192 'COPY;' =>
"\xC2\xA9",
3193 'copy;' =>
"\xC2\xA9",
3194 'crarr;' =>
"\xE2\x86\xB5",
3195 'cup;' =>
"\xE2\x88\xAA",
3196 'curren' =>
"\xC2\xA4",
3197 'curren;' =>
"\xC2\xA4",
3198 'Dagger;' =>
"\xE2\x80\xA1",
3199 'dagger;' =>
"\xE2\x80\xA0",
3200 'dArr;' =>
"\xE2\x87\x93",
3201 'darr;' =>
"\xE2\x86\x93",
3202 'deg' =>
"\xC2\xB0",
3203 'deg;' =>
"\xC2\xB0",
3204 'Delta;' =>
"\xCE\x94",
3205 'delta;' =>
"\xCE\xB4",
3206 'diams;' =>
"\xE2\x99\xA6",
3207 'divide' =>
"\xC3\xB7",
3208 'divide;' =>
"\xC3\xB7",
3209 'Eacute' =>
"\xC3\x89",
3210 'eacute' =>
"\xC3\xA9",
3211 'Eacute;' =>
"\xC3\x89",
3212 'eacute;' =>
"\xC3\xA9",
3213 'Ecirc' =>
"\xC3\x8A",
3214 'ecirc' =>
"\xC3\xAA",
3215 'Ecirc;' =>
"\xC3\x8A",
3216 'ecirc;' =>
"\xC3\xAA",
3217 'Egrave' =>
"\xC3\x88",
3218 'egrave' =>
"\xC3\xA8",
3219 'Egrave;' =>
"\xC3\x88",
3220 'egrave;' =>
"\xC3\xA8",
3221 'empty;' =>
"\xE2\x88\x85",
3222 'emsp;' =>
"\xE2\x80\x83",
3223 'ensp;' =>
"\xE2\x80\x82",
3224 'Epsilon;' =>
"\xCE\x95",
3225 'epsilon;' =>
"\xCE\xB5",
3226 'equiv;' =>
"\xE2\x89\xA1",
3227 'Eta;' =>
"\xCE\x97",
3228 'eta;' =>
"\xCE\xB7",
3229 'ETH' =>
"\xC3\x90",
3230 'eth' =>
"\xC3\xB0",
3231 'ETH;' =>
"\xC3\x90",
3232 'eth;' =>
"\xC3\xB0",
3233 'Euml' =>
"\xC3\x8B",
3234 'euml' =>
"\xC3\xAB",
3235 'Euml;' =>
"\xC3\x8B",
3236 'euml;' =>
"\xC3\xAB",
3237 'euro;' =>
"\xE2\x82\xAC",
3238 'exist;' =>
"\xE2\x88\x83",
3239 'fnof;' =>
"\xC6\x92",
3240 'forall;' =>
"\xE2\x88\x80",
3241 'frac12' =>
"\xC2\xBD",
3242 'frac12;' =>
"\xC2\xBD",
3243 'frac14' =>
"\xC2\xBC",
3244 'frac14;' =>
"\xC2\xBC",
3245 'frac34' =>
"\xC2\xBE",
3246 'frac34;' =>
"\xC2\xBE",
3247 'frasl;' =>
"\xE2\x81\x84",
3248 'Gamma;' =>
"\xCE\x93",
3249 'gamma;' =>
"\xCE\xB3",
3250 'ge;' =>
"\xE2\x89\xA5",
3255 'hArr;' =>
"\xE2\x87\x94",
3256 'harr;' =>
"\xE2\x86\x94",
3257 'hearts;' =>
"\xE2\x99\xA5",
3258 'hellip;' =>
"\xE2\x80\xA6",
3259 'Iacute' =>
"\xC3\x8D",
3260 'iacute' =>
"\xC3\xAD",
3261 'Iacute;' =>
"\xC3\x8D",
3262 'iacute;' =>
"\xC3\xAD",
3263 'Icirc' =>
"\xC3\x8E",
3264 'icirc' =>
"\xC3\xAE",
3265 'Icirc;' =>
"\xC3\x8E",
3266 'icirc;' =>
"\xC3\xAE",
3267 'iexcl' =>
"\xC2\xA1",
3268 'iexcl;' =>
"\xC2\xA1",
3269 'Igrave' =>
"\xC3\x8C",
3270 'igrave' =>
"\xC3\xAC",
3271 'Igrave;' =>
"\xC3\x8C",
3272 'igrave;' =>
"\xC3\xAC",
3273 'image;' =>
"\xE2\x84\x91",
3274 'infin;' =>
"\xE2\x88\x9E",
3275 'int;' =>
"\xE2\x88\xAB",
3276 'Iota;' =>
"\xCE\x99",
3277 'iota;' =>
"\xCE\xB9",
3278 'iquest' =>
"\xC2\xBF",
3279 'iquest;' =>
"\xC2\xBF",
3280 'isin;' =>
"\xE2\x88\x88",
3281 'Iuml' =>
"\xC3\x8F",
3282 'iuml' =>
"\xC3\xAF",
3283 'Iuml;' =>
"\xC3\x8F",
3284 'iuml;' =>
"\xC3\xAF",
3285 'Kappa;' =>
"\xCE\x9A",
3286 'kappa;' =>
"\xCE\xBA",
3287 'Lambda;' =>
"\xCE\x9B",
3288 'lambda;' =>
"\xCE\xBB",
3289 'lang;' =>
"\xE3\x80\x88",
3290 'laquo' =>
"\xC2\xAB",
3291 'laquo;' =>
"\xC2\xAB",
3292 'lArr;' =>
"\xE2\x87\x90",
3293 'larr;' =>
"\xE2\x86\x90",
3294 'lceil;' =>
"\xE2\x8C\x88",
3295 'ldquo;' =>
"\xE2\x80\x9C",
3296 'le;' =>
"\xE2\x89\xA4",
3297 'lfloor;' =>
"\xE2\x8C\x8A",
3298 'lowast;' =>
"\xE2\x88\x97",
3299 'loz;' =>
"\xE2\x97\x8A",
3300 'lrm;' =>
"\xE2\x80\x8E",
3301 'lsaquo;' =>
"\xE2\x80\xB9",
3302 'lsquo;' =>
"\xE2\x80\x98",
3307 'macr' =>
"\xC2\xAF",
3308 'macr;' =>
"\xC2\xAF",
3309 'mdash;' =>
"\xE2\x80\x94",
3310 'micro' =>
"\xC2\xB5",
3311 'micro;' =>
"\xC2\xB5",
3312 'middot' =>
"\xC2\xB7",
3313 'middot;' =>
"\xC2\xB7",
3314 'minus;' =>
"\xE2\x88\x92",
3315 'Mu;' =>
"\xCE\x9C",
3316 'mu;' =>
"\xCE\xBC",
3317 'nabla;' =>
"\xE2\x88\x87",
3318 'nbsp' =>
"\xC2\xA0",
3319 'nbsp;' =>
"\xC2\xA0",
3320 'ndash;' =>
"\xE2\x80\x93",
3321 'ne;' =>
"\xE2\x89\xA0",
3322 'ni;' =>
"\xE2\x88\x8B",
3323 'not' =>
"\xC2\xAC",
3324 'not;' =>
"\xC2\xAC",
3325 'notin;' =>
"\xE2\x88\x89",
3326 'nsub;' =>
"\xE2\x8A\x84",
3327 'Ntilde' =>
"\xC3\x91",
3328 'ntilde' =>
"\xC3\xB1",
3329 'Ntilde;' =>
"\xC3\x91",
3330 'ntilde;' =>
"\xC3\xB1",
3331 'Nu;' =>
"\xCE\x9D",
3332 'nu;' =>
"\xCE\xBD",
3333 'Oacute' =>
"\xC3\x93",
3334 'oacute' =>
"\xC3\xB3",
3335 'Oacute;' =>
"\xC3\x93",
3336 'oacute;' =>
"\xC3\xB3",
3337 'Ocirc' =>
"\xC3\x94",
3338 'ocirc' =>
"\xC3\xB4",
3339 'Ocirc;' =>
"\xC3\x94",
3340 'ocirc;' =>
"\xC3\xB4",
3341 'OElig;' =>
"\xC5\x92",
3342 'oelig;' =>
"\xC5\x93",
3343 'Ograve' =>
"\xC3\x92",
3344 'ograve' =>
"\xC3\xB2",
3345 'Ograve;' =>
"\xC3\x92",
3346 'ograve;' =>
"\xC3\xB2",
3347 'oline;' =>
"\xE2\x80\xBE",
3348 'Omega;' =>
"\xCE\xA9",
3349 'omega;' =>
"\xCF\x89",
3350 'Omicron;' =>
"\xCE\x9F",
3351 'omicron;' =>
"\xCE\xBF",
3352 'oplus;' =>
"\xE2\x8A\x95",
3353 'or;' =>
"\xE2\x88\xA8",
3354 'ordf' =>
"\xC2\xAA",
3355 'ordf;' =>
"\xC2\xAA",
3356 'ordm' =>
"\xC2\xBA",
3357 'ordm;' =>
"\xC2\xBA",
3358 'Oslash' =>
"\xC3\x98",
3359 'oslash' =>
"\xC3\xB8",
3360 'Oslash;' =>
"\xC3\x98",
3361 'oslash;' =>
"\xC3\xB8",
3362 'Otilde' =>
"\xC3\x95",
3363 'otilde' =>
"\xC3\xB5",
3364 'Otilde;' =>
"\xC3\x95",
3365 'otilde;' =>
"\xC3\xB5",
3366 'otimes;' =>
"\xE2\x8A\x97",
3367 'Ouml' =>
"\xC3\x96",
3368 'ouml' =>
"\xC3\xB6",
3369 'Ouml;' =>
"\xC3\x96",
3370 'ouml;' =>
"\xC3\xB6",
3371 'para' =>
"\xC2\xB6",
3372 'para;' =>
"\xC2\xB6",
3373 'part;' =>
"\xE2\x88\x82",
3374 'permil;' =>
"\xE2\x80\xB0",
3375 'perp;' =>
"\xE2\x8A\xA5",
3376 'Phi;' =>
"\xCE\xA6",
3377 'phi;' =>
"\xCF\x86",
3378 'Pi;' =>
"\xCE\xA0",
3379 'pi;' =>
"\xCF\x80",
3380 'piv;' =>
"\xCF\x96",
3381 'plusmn' =>
"\xC2\xB1",
3382 'plusmn;' =>
"\xC2\xB1",
3383 'pound' =>
"\xC2\xA3",
3384 'pound;' =>
"\xC2\xA3",
3385 'Prime;' =>
"\xE2\x80\xB3",
3386 'prime;' =>
"\xE2\x80\xB2",
3387 'prod;' =>
"\xE2\x88\x8F",
3388 'prop;' =>
"\xE2\x88\x9D",
3389 'Psi;' =>
"\xCE\xA8",
3390 'psi;' =>
"\xCF\x88",
3395 'radic;' =>
"\xE2\x88\x9A",
3396 'rang;' =>
"\xE3\x80\x89",
3397 'raquo' =>
"\xC2\xBB",
3398 'raquo;' =>
"\xC2\xBB",
3399 'rArr;' =>
"\xE2\x87\x92",
3400 'rarr;' =>
"\xE2\x86\x92",
3401 'rceil;' =>
"\xE2\x8C\x89",
3402 'rdquo;' =>
"\xE2\x80\x9D",
3403 'real;' =>
"\xE2\x84\x9C",
3404 'REG' =>
"\xC2\xAE",
3405 'reg' =>
"\xC2\xAE",
3406 'REG;' =>
"\xC2\xAE",
3407 'reg;' =>
"\xC2\xAE",
3408 'rfloor;' =>
"\xE2\x8C\x8B",
3409 'Rho;' =>
"\xCE\xA1",
3410 'rho;' =>
"\xCF\x81",
3411 'rlm;' =>
"\xE2\x80\x8F",
3412 'rsaquo;' =>
"\xE2\x80\xBA",
3413 'rsquo;' =>
"\xE2\x80\x99",
3414 'sbquo;' =>
"\xE2\x80\x9A",
3415 'Scaron;' =>
"\xC5\xA0",
3416 'scaron;' =>
"\xC5\xA1",
3417 'sdot;' =>
"\xE2\x8B\x85",
3418 'sect' =>
"\xC2\xA7",
3419 'sect;' =>
"\xC2\xA7",
3420 'shy' =>
"\xC2\xAD",
3421 'shy;' =>
"\xC2\xAD",
3422 'Sigma;' =>
"\xCE\xA3",
3423 'sigma;' =>
"\xCF\x83",
3424 'sigmaf;' =>
"\xCF\x82",
3425 'sim;' =>
"\xE2\x88\xBC",
3426 'spades;' =>
"\xE2\x99\xA0",
3427 'sub;' =>
"\xE2\x8A\x82",
3428 'sube;' =>
"\xE2\x8A\x86",
3429 'sum;' =>
"\xE2\x88\x91",
3430 'sup;' =>
"\xE2\x8A\x83",
3431 'sup1' =>
"\xC2\xB9",
3432 'sup1;' =>
"\xC2\xB9",
3433 'sup2' =>
"\xC2\xB2",
3434 'sup2;' =>
"\xC2\xB2",
3435 'sup3' =>
"\xC2\xB3",
3436 'sup3;' =>
"\xC2\xB3",
3437 'supe;' =>
"\xE2\x8A\x87",
3438 'szlig' =>
"\xC3\x9F",
3439 'szlig;' =>
"\xC3\x9F",
3440 'Tau;' =>
"\xCE\xA4",
3441 'tau;' =>
"\xCF\x84",
3442 'there4;' =>
"\xE2\x88\xB4",
3443 'Theta;' =>
"\xCE\x98",
3444 'theta;' =>
"\xCE\xB8",
3445 'thetasym;' =>
"\xCF\x91",
3446 'thinsp;' =>
"\xE2\x80\x89",
3447 'THORN' =>
"\xC3\x9E",
3448 'thorn' =>
"\xC3\xBE",
3449 'THORN;' =>
"\xC3\x9E",
3450 'thorn;' =>
"\xC3\xBE",
3451 'tilde;' =>
"\xCB\x9C",
3452 'times' =>
"\xC3\x97",
3453 'times;' =>
"\xC3\x97",
3454 'TRADE;' =>
"\xE2\x84\xA2",
3455 'trade;' =>
"\xE2\x84\xA2",
3456 'Uacute' =>
"\xC3\x9A",
3457 'uacute' =>
"\xC3\xBA",
3458 'Uacute;' =>
"\xC3\x9A",
3459 'uacute;' =>
"\xC3\xBA",
3460 'uArr;' =>
"\xE2\x87\x91",
3461 'uarr;' =>
"\xE2\x86\x91",
3462 'Ucirc' =>
"\xC3\x9B",
3463 'ucirc' =>
"\xC3\xBB",
3464 'Ucirc;' =>
"\xC3\x9B",
3465 'ucirc;' =>
"\xC3\xBB",
3466 'Ugrave' =>
"\xC3\x99",
3467 'ugrave' =>
"\xC3\xB9",
3468 'Ugrave;' =>
"\xC3\x99",
3469 'ugrave;' =>
"\xC3\xB9",
3470 'uml' =>
"\xC2\xA8",
3471 'uml;' =>
"\xC2\xA8",
3472 'upsih;' =>
"\xCF\x92",
3473 'Upsilon;' =>
"\xCE\xA5",
3474 'upsilon;' =>
"\xCF\x85",
3475 'Uuml' =>
"\xC3\x9C",
3476 'uuml' =>
"\xC3\xBC",
3477 'Uuml;' =>
"\xC3\x9C",
3478 'uuml;' =>
"\xC3\xBC",
3479 'weierp;' =>
"\xE2\x84\x98",
3480 'Xi;' =>
"\xCE\x9E",
3481 'xi;' =>
"\xCE\xBE",
3482 'Yacute' =>
"\xC3\x9D",
3483 'yacute' =>
"\xC3\xBD",
3484 'Yacute;' =>
"\xC3\x9D",
3485 'yacute;' =>
"\xC3\xBD",
3486 'yen' =>
"\xC2\xA5",
3487 'yen;' =>
"\xC2\xA5",
3488 'yuml' =>
"\xC3\xBF",
3489 'Yuml;' =>
"\xC5\xB8",
3490 'yuml;' =>
"\xC3\xBF",
3491 'Zeta;' =>
"\xCE\x96",
3492 'zeta;' =>
"\xCE\xB6",
3493 'zwj;' =>
"\xE2\x80\x8D",
3494 'zwnj;' =>
"\xE2\x80\x8C"
3498 $consumed = substr($this->consumed, 1);
3499 if (isset($entities[$consumed]))
3506 $this->data = substr_replace($this->data, $entities[
$match], $this->position - strlen($consumed) - 1, strlen($match) + 1);
3507 $this->position += strlen($entities[$match]) - strlen($consumed) - 1;
3570 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)
3585 $this->lang =
$lang;
3587 $this->link =
$link;
3595 $this->type =
$type;
3597 if (class_exists(
'idna_convert'))
3599 $idn =
new idna_convert();
3609 return md5(serialize($this));
3614 if ($this->bitrate !== null)
3627 if (isset($captions[$key]))
3629 return $captions[$key];
3639 if ($this->captions !== null)
3652 if (isset($categories[$key]))
3654 return $categories[$key];
3664 if ($this->categories !== null)
3676 if ($this->channels !== null)
3688 if ($this->copyright !== null)
3701 if (isset($credits[$key]))
3703 return $credits[$key];
3713 if ($this->credits !== null)
3725 if ($this->description !== null)
3737 if ($this->duration !== null)
3757 if ($this->expression !== null)
3769 if ($this->link !== null)
3772 if (
$url[
'path'] !==
'')
3774 return pathinfo(
$url[
'path'], PATHINFO_EXTENSION);
3782 if ($this->framerate !== null)
3800 if (isset($hashes[$key]))
3802 return $hashes[$key];
3812 if ($this->hashes !== null)
3824 if ($this->height !== null)
3836 if ($this->lang !== null)
3849 if (isset($keywords[$key]))
3851 return $keywords[$key];
3861 if ($this->keywords !== null)
3873 if ($this->length !== null)
3885 if ($this->link !== null)
3887 return urldecode($this->link);
3897 if ($this->medium !== null)
3909 if ($this->player !== null)
3922 if (isset($ratings[$key]))
3924 return $ratings[$key];
3934 if ($this->ratings !== null)
3947 if (isset($restrictions[$key]))
3949 return $restrictions[$key];
3959 if ($this->restrictions !== null)
3971 if ($this->samplingrate !== null)
3984 if ($length !== null)
3986 return round($length/1048576, 2);
3997 if (isset($thumbnails[$key]))
3999 return $thumbnails[$key];
4009 if ($this->thumbnails !== null)
4021 if ($this->title !== null)
4033 if ($this->type !== null)
4045 if ($this->width !== null)
4057 return $this->
embed($options,
true);
4060 public function embed($options =
'', $native =
false)
4070 $bgcolor =
'#ffffff';
4072 $widescreen =
false;
4076 if (is_array($options))
4082 $options = explode(
',', $options);
4083 foreach($options as $option)
4085 $opt = explode(
':', $option, 2);
4086 if (isset($opt[0], $opt[1]))
4088 $opt[0] = trim($opt[0]);
4089 $opt[1] = trim($opt[1]);
4102 $altclass = $opt[1];
4117 $mediaplayer = $opt[1];
4120 $widescreen = $opt[1];
4126 $mime = explode(
'/', $type, 2);
4129 if ($width ===
'auto')
4131 if ($mime ===
'video')
4133 if ($height ===
'auto')
4139 $width = round((intval($height)/9)*16);
4143 $width = round((intval($height)/3)*4);
4151 if ($height ===
'auto')
4153 if ($mime ===
'audio')
4157 elseif ($mime ===
'video')
4159 if ($width ===
'auto')
4172 $height = round((intval($width)/16)*9);
4176 $height = round((intval($width)/4)*3);
4184 elseif ($mime ===
'audio')
4189 if ($mime ===
'audio')
4191 $placeholder = $audio;
4193 elseif ($mime ===
'video')
4195 $placeholder = $video;
4199 if ($handler ===
'flash')
4203 $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>";
4207 $embed .=
"<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->
get_link() .
"', '$loop', '$type');</script>";
4212 elseif ($handler ===
'fmedia' || ($handler ===
'mp3' && $mediaplayer !==
''))
4217 $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>";
4221 $embed .=
"<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->
get_link().
'?file_extension=.'.$this->
get_extension()) .
"', '$placeholder', '$loop', '$mediaplayer');</script>";
4226 elseif ($handler ===
'quicktime' || ($handler ===
'mp3' && $mediaplayer ===
''))
4231 if ($placeholder !==
'')
4233 $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>";
4237 $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>";
4242 $embed .=
"<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->
get_link() .
"', '$placeholder', '$loop');</script>";
4246 elseif ($handler ===
'wmedia')
4251 $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>";
4255 $embed .=
"<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->
get_link() .
"');</script>";
4259 else $embed .=
'<a href="' . $this->
get_link() .
'" class="' . $altclass .
'">' . $alt .
'</a>';
4266 $types_flash = array(
'application/x-shockwave-flash',
'application/futuresplash');
4267 $types_fmedia = array(
'video/flv',
'video/x-flv',
'flv-application/octet-stream');
4268 $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');
4269 $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');
4270 $types_mp3 = array(
'audio/mp3',
'audio/x-mp3',
'audio/mpeg',
'audio/x-mpeg');
4273 $type = strtolower($this->type);
4280 if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3)))
4287 $type =
'audio/acc';
4293 $type =
'audio/aiff';
4296 $type =
'audio/wav';
4302 $type =
'audio/midi';
4305 $type =
'audio/x-m4a';
4309 $type =
'audio/mp3';
4312 $type =
'audio/wav';
4315 $type =
'audio/x-ms-wax';
4318 $type =
'audio/x-ms-wma';
4323 $type =
'video/3gpp';
4327 $type =
'video/3gpp2';
4330 $type =
'video/x-ms-asf';
4333 $type =
'video/x-flv';
4346 $type =
'video/mpeg';
4349 $type =
'video/x-m4v';
4353 $type =
'video/quicktime';
4357 $type =
'video/mp4';
4360 $type =
'video/sd-video';
4363 $type =
'video/x-ms-wm';
4366 $type =
'video/x-ms-wmv';
4369 $type =
'video/x-ms-wvx';
4373 $type =
'application/futuresplash';
4376 $type =
'application/x-shockwave-flash';
4382 if (in_array($type, $types_flash))
4386 elseif (in_array($type, $types_fmedia))
4390 elseif (in_array($type, $types_quicktime))
4394 elseif (in_array($type, $types_wmedia))
4398 elseif (in_array($type, $types_mp3))
4427 public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen =
false)
4429 if (class_exists(
'idna_convert'))
4431 $idn =
new idna_convert();
4437 if (preg_match(
'/^http(s)?:\/\//i', $url))
4439 if ($useragent === null)
4441 $useragent = ini_get(
'user_agent');
4444 if (!is_array($headers))
4448 if (!$force_fsockopen && function_exists(
'curl_exec'))
4452 $headers2 = array();
4453 foreach ($headers as $key => $value)
4455 $headers2[] =
"$key: $value";
4459 curl_setopt(
$fp, CURLOPT_ENCODING,
'');
4461 curl_setopt(
$fp, CURLOPT_URL, $url);
4462 curl_setopt(
$fp, CURLOPT_HEADER, 1);
4463 curl_setopt(
$fp, CURLOPT_RETURNTRANSFER, 1);
4464 curl_setopt(
$fp, CURLOPT_TIMEOUT, $timeout);
4465 curl_setopt(
$fp, CURLOPT_CONNECTTIMEOUT, $timeout);
4466 curl_setopt(
$fp, CURLOPT_REFERER, $url);
4467 curl_setopt(
$fp, CURLOPT_USERAGENT, $useragent);
4468 curl_setopt(
$fp, CURLOPT_HTTPHEADER, $headers2);
4471 curl_setopt(
$fp, CURLOPT_FOLLOWLOCATION, 1);
4472 curl_setopt(
$fp, CURLOPT_MAXREDIRS, $redirects);
4474 $this->headers = curl_exec(
$fp);
4475 if (curl_errno(
$fp) === 23 || curl_errno(
$fp) === 61)
4477 curl_setopt(
$fp, CURLOPT_ENCODING,
'none');
4478 $this->headers = curl_exec(
$fp);
4480 if (curl_errno(
$fp))
4482 $this->error =
'cURL error ' . curl_errno(
$fp) .
': ' . curl_error(
$fp);
4483 $this->success =
false;
4487 $info = curl_getinfo(
$fp);
4489 $this->headers = explode(
"\r\n\r\n", $this->headers, $info[
'redirect_count'] + 1);
4490 $this->headers = array_pop($this->headers);
4492 if ($parser->parse())
4494 $this->headers = $parser->headers;
4495 $this->body = $parser->body;
4496 $this->status_code = $parser->status_code;
4497 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)
4501 return $this->
__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
4509 $url_parts = parse_url($url);
4510 $socket_host = $url_parts[
'host'];
4511 if (isset($url_parts[
'scheme']) && strtolower($url_parts[
'scheme']) ===
'https')
4513 $socket_host =
"ssl://$url_parts[host]";
4514 $url_parts[
'port'] = 443;
4516 if (!isset($url_parts[
'port']))
4518 $url_parts[
'port'] = 80;
4520 $fp = @fsockopen($socket_host, $url_parts[
'port'], $errno, $errstr, $timeout);
4523 $this->error =
'fsockopen error: ' . $errstr;
4524 $this->success =
false;
4528 stream_set_timeout(
$fp, $timeout);
4529 if (isset($url_parts[
'path']))
4531 if (isset($url_parts[
'query']))
4533 $get =
"$url_parts[path]?$url_parts[query]";
4537 $get = $url_parts[
'path'];
4544 $out =
"GET $get HTTP/1.1\r\n";
4545 $out .=
"Host: $url_parts[host]\r\n";
4546 $out .=
"User-Agent: $useragent\r\n";
4547 if (extension_loaded(
'zlib'))
4549 $out .=
"Accept-Encoding: x-gzip,gzip,deflate\r\n";
4551 if (isset($url_parts[
'user']) && isset($url_parts[
'pass']))
4553 $out .=
"Authorization: Basic " . base64_encode(
"$url_parts[user]:$url_parts[pass]") .
"\r\n";
4555 foreach ($headers as $key => $value)
4557 $out .=
"$key: $value\r\n";
4559 $out .=
"Connection: Close\r\n\r\n";
4561 $info = stream_get_meta_data(
$fp);
4562 $this->headers =
'';
4563 while (!$info[
'eof'] && !$info[
'timed_out'])
4565 $this->headers .= fread(
$fp, 1160);
4566 $info = stream_get_meta_data(
$fp);
4568 if (!$info[
'timed_out'])
4571 if ($parser->parse())
4573 $this->headers = $parser->headers;
4574 $this->body = $parser->body;
4575 $this->status_code = $parser->status_code;
4576 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)
4580 return $this->
__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
4582 if (isset($this->headers[
'content-encoding']))
4585 switch (strtolower(trim($this->headers[
'content-encoding'],
"\x09\x0A\x0D\x20")))
4590 if (!$decoder->parse())
4592 $this->error =
'Unable to decode HTTP "gzip" stream';
4593 $this->success =
false;
4597 $this->body = $decoder->data;
4601 if (($decompressed = gzinflate($this->body)) !==
false)
4603 $this->body = $decompressed;
4605 else if (($decompressed = gzuncompress($this->body)) !==
false)
4607 $this->body = $decompressed;
4609 else if (function_exists(
'gzdecode') && ($decompressed = gzdecode($this->body)) !==
false)
4611 $this->body = $decompressed;
4615 $this->error =
'Unable to decode HTTP "deflate" stream';
4616 $this->success =
false;
4620 $this->error =
'Unknown content coding';
4621 $this->success =
false;
4628 $this->error =
'fsocket timed out';
4629 $this->success =
false;
4638 if (!$this->body = file_get_contents($url))
4640 $this->error =
'file_get_contents could not read the file';
4641 $this->success =
false;
4679 trigger_error(
"Cannot write property $name", E_USER_ERROR);
4684 $this->compressed_data =
$data;
4685 $this->compressed_size = strlen($data);
4690 if ($this->compressed_size >= $this->min_compressed_size)
4693 if (substr($this->compressed_data, 0, 3) !==
"\x1F\x8B\x08")
4698 $this->flags = ord($this->compressed_data[3]);
4700 if ($this->flags > 0x1F)
4705 $this->position += 4;
4707 $mtime = substr($this->compressed_data, $this->position, 4);
4709 if (current(unpack(
'S',
"\x00\x01")) === 1)
4711 $mtime = strrev($mtime);
4713 $this->MTIME = current(unpack(
'l', $mtime));
4714 $this->position += 4;
4716 $this->XFL = ord($this->compressed_data[$this->position++]);
4718 $this->OS = ord($this->compressed_data[$this->position++]);
4720 if ($this->flags & 4)
4723 $this->SI1 = $this->compressed_data[$this->position++];
4724 $this->SI2 = $this->compressed_data[$this->position++];
4726 if ($this->SI2 ===
"\x00")
4731 $len = current(unpack(
'v', substr($this->compressed_data, $this->position, 2)));
4732 $this->position += 2;
4734 $this->min_compressed_size += $len + 4;
4735 if ($this->compressed_size >= $this->min_compressed_size)
4738 $this->extra_field = substr($this->compressed_data, $this->position, $len);
4739 $this->position += $len;
4747 if ($this->flags & 8)
4750 $len = strcspn($this->compressed_data,
"\x00", $this->position);
4752 $this->min_compressed_size += $len + 1;
4753 if ($this->compressed_size >= $this->min_compressed_size)
4756 $this->filename = substr($this->compressed_data, $this->position, $len);
4757 $this->position += $len + 1;
4765 if ($this->flags & 16)
4768 $len = strcspn($this->compressed_data,
"\x00", $this->position);
4770 $this->min_compressed_size += $len + 1;
4771 if ($this->compressed_size >= $this->min_compressed_size)
4774 $this->comment = substr($this->compressed_data, $this->position, $len);
4775 $this->position += $len + 1;
4783 if ($this->flags & 2)
4786 $this->min_compressed_size += $len + 2;
4787 if ($this->compressed_size >= $this->min_compressed_size)
4790 $crc = current(unpack(
'v', substr($this->compressed_data, $this->position, 2)));
4792 if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc)
4794 $this->position += 2;
4807 if (($this->data = gzinflate(substr($this->compressed_data, $this->position, -8))) ===
false)
4813 $this->position = $this->compressed_size - 8;
4816 $crc = current(unpack(
'V', substr($this->compressed_data, $this->position, 4)));
4817 $this->position += 4;
4823 $isize = current(unpack(
'V', substr($this->compressed_data, $this->position, 4)));
4824 $this->position += 4;
4825 if (sprintf(
'%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf(
'%u', $isize))
4865 $this->data =
$data;
4866 $this->data_length = strlen($this->data);
4871 while ($this->state && $this->state !==
'emit' && $this->
has_data())
4877 if ($this->state ===
'emit' || $this->state ===
'body')
4884 $this->status_code =
'';
4886 $this->headers = array();
4902 && isset($this->data[$this->position + 1])
4903 && ($this->data[$this->position + 1] ===
"\x09" || $this->data[$this->position + 1] ===
"\x20")));
4908 if (strpos($this->data,
"\x0A") !==
false && strtoupper(substr($this->data, 0, 5)) ===
'HTTP/')
4910 $len = strspn($this->data,
'0123456789.', 5);
4912 $this->position += 5 + $len;
4916 $this->position += strspn($this->data,
"\x09\x20", $this->position);
4917 $this->state =
'status';
4921 $this->state =
false;
4926 $this->state =
false;
4932 if ($len = strspn($this->data,
'0123456789', $this->position))
4934 $this->status_code = (int) substr($this->data, $this->position, $len);
4935 $this->position += $len;
4936 $this->state =
'reason';
4940 $this->state =
false;
4946 $len = strcspn($this->data,
"\x0A", $this->position);
4947 $this->
reason = trim(substr($this->data, $this->position, $len),
"\x09\x0D\x20");
4948 $this->position += $len + 1;
4949 $this->state =
'new_line';
4954 $this->
value = trim($this->
value,
"\x0D\x20");
4955 if ($this->
name !==
'' && $this->
value !==
'')
4957 $this->
name = strtolower($this->
name);
4959 if (isset($this->headers[$this->
name]) && $this->name !==
'content-type')
4970 if (substr($this->data[$this->position], 0, 2) ===
"\x0D\x0A")
4972 $this->position += 2;
4973 $this->state =
'body';
4975 elseif ($this->data[$this->position] ===
"\x0A")
4978 $this->state =
'body';
4982 $this->state =
'name';
4988 $len = strcspn($this->data,
"\x0A:", $this->position);
4989 if (isset($this->data[$this->position + $len]))
4991 if ($this->data[$this->position + $len] ===
"\x0A")
4993 $this->position += $len;
4994 $this->state =
'new_line';
4998 $this->
name = substr($this->data, $this->position, $len);
4999 $this->position += $len + 1;
5000 $this->state =
'value';
5005 $this->state =
false;
5013 if (substr($this->data, $this->position, 2) ===
"\x0D\x0A")
5015 $this->position += 2;
5017 elseif ($this->data[$this->position] ===
"\x0A")
5021 $this->position += strspn($this->data,
"\x09\x20", $this->position);
5023 $this->
value .=
"\x20";
5034 switch ($this->data[$this->position])
5039 if (strtolower($this->
name) ===
'etag')
5041 $this->
value .=
'"';
5043 $this->state =
'value_char';
5047 $this->state =
'quote';
5051 $this->state =
'new_line';
5054 $this->state =
'value_char';
5062 $len = strcspn($this->data,
"\x09\x20\x0A\"", $this->position);
5063 $this->
value .= substr($this->data, $this->position, $len);
5064 $this->position += $len;
5065 $this->state =
'value';
5076 switch ($this->data[$this->position])
5080 $this->state =
'value';
5084 $this->state =
'new_line';
5088 $this->state =
'quote_escaped';
5091 $this->state =
'quote_char';
5099 $len = strcspn($this->data,
"\x09\x20\x0A\"\\", $this->position);
5100 $this->
value .= substr($this->data, $this->position, $len);
5101 $this->position += $len;
5102 $this->state =
'value';
5109 $this->state =
'quote';
5114 $this->
body = substr($this->data, $this->position);
5115 if (!empty($this->headers[
'transfer-encoding']))
5117 unset($this->headers[
'transfer-encoding']);
5118 $this->state =
'chunked';
5122 $this->state =
'emit';
5128 if (!preg_match(
'/^([0-9a-f]+)[^\r\n]*\r\n/i', trim($this->
body)))
5130 $this->state =
'emit';
5137 $is_chunked = (bool) preg_match(
'/^([0-9a-f]+)[^\r\n]*\r\n/i', $encoded, $matches );
5141 $this->state =
'emit';
5144 $length = hexdec(trim($matches[1]));
5148 $this->state =
'emit';
5149 $this->
body = $decoded;
5152 $chunk_length = strlen($matches[0]);
5153 $decoded .= $part = substr($encoded, $chunk_length, $length);
5154 $encoded = substr($encoded, $chunk_length + $length + 2);
5155 if (trim($encoded) ===
'0' || empty($encoded))
5157 $this->state =
'emit';
5158 $this->
body = $decoded;
5189 'ihost' =>
'localhost'
5208 if (method_exists($this,
'set_' . $name))
5210 call_user_func(array($this,
'set_' . $name), $value);
5213 $name ===
'iauthority'
5214 || $name ===
'iuserinfo'
5215 || $name ===
'ihost'
5216 || $name ===
'ipath'
5217 || $name ===
'iquery'
5218 || $name ===
'ifragment'
5221 call_user_func(array($this,
'set_' . substr($name, 1)), $value);
5229 $props = get_object_vars($this);
5233 $name ===
'iauthority' ||
5234 $name ===
'authority'
5237 $return = $this->{
"get_$name"}();
5239 elseif (array_key_exists($name, $props))
5241 $return = $this->$name;
5244 elseif (($prop =
'i' . $name) && array_key_exists($prop, $props))
5247 $return = $this->$prop;
5250 elseif (($prop = substr($name, 1)) && array_key_exists($prop, $props))
5253 $return = $this->$prop;
5257 trigger_error(
'Undefined property: ' . get_class($this) .
'::' . $name, E_USER_NOTICE);
5260 if ($return === null && isset($this->normalization[$this->scheme][$name]))
5272 if (method_exists($this,
'get_' . $name) || isset($this->$name))
5284 if (method_exists($this,
'set_' . $name))
5286 call_user_func(array($this,
'set_' . $name),
'');
5299 $relative =
new SimplePie_IRI($relative);
5301 if (!$relative->is_valid())
5305 elseif ($relative->scheme !== null)
5307 return clone $relative;
5311 if (!($base instanceof SimplePie_IRI))
5313 $base =
new SimplePie_IRI($base);
5315 if ($base->scheme !== null && $base->is_valid())
5317 if ($relative->get_iri() !==
'')
5319 if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null)
5321 $target = clone $relative;
5322 $target->scheme = $base->scheme;
5326 $target =
new SimplePie_IRI;
5327 $target->scheme = $base->scheme;
5328 $target->iuserinfo = $base->iuserinfo;
5329 $target->ihost = $base->ihost;
5330 $target->port = $base->port;
5331 if ($relative->ipath !==
'')
5333 if ($relative->ipath[0] ===
'/')
5335 $target->ipath = $relative->ipath;
5337 elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath ===
'')
5339 $target->ipath =
'/' . $relative->ipath;
5341 elseif (($last_segment = strrpos($base->ipath,
'/')) !==
false)
5343 $target->ipath = substr($base->ipath, 0, $last_segment + 1) . $relative->ipath;
5347 $target->ipath = $relative->ipath;
5349 $target->ipath = $target->remove_dot_segments($target->ipath);
5350 $target->iquery = $relative->iquery;
5354 $target->ipath = $base->ipath;
5355 if ($relative->iquery !== null)
5357 $target->iquery = $relative->iquery;
5359 elseif ($base->iquery !== null)
5361 $target->iquery = $base->iquery;
5364 $target->ifragment = $relative->ifragment;
5369 $target = clone $base;
5370 $target->ifragment = null;
5372 $target->scheme_normalization();
5384 $iri = trim($iri,
"\x20\x09\x0A\x0C\x0D");
5385 if (preg_match(
'/^((?P<scheme>[^:\/?#]+):)?(\/\/(?P<authority>[^\/?#]*))?(?P<path>[^?#]*)(\?(?P<query>[^#]*))?(#(?P<fragment>.*))?$/', $iri,
$match))
5393 $match[
'authority'] = null;
5405 $match[
'fragment'] = null;
5419 while (strpos($input,
'./') !==
false || strpos($input,
'/.') !==
false || $input ===
'.' || $input ===
'..')
5422 if (strpos($input,
'../') === 0)
5424 $input = substr($input, 3);
5426 elseif (strpos($input,
'./') === 0)
5428 $input = substr($input, 2);
5431 elseif (strpos($input,
'/./') === 0)
5433 $input = substr($input, 2);
5440 elseif (strpos($input,
'/../') === 0)
5442 $input = substr($input, 3);
5445 elseif ($input ===
'/..')
5451 elseif ($input ===
'.' || $input ===
'..')
5456 elseif (($pos = strpos($input,
'/', 1)) !==
false)
5458 $output .= substr($input, 0, $pos);
5459 $input = substr_replace($input,
'', 0, $pos);
5473 $string = preg_replace_callback(
'/(?:%[A-Fa-f0-9]{2})+/', array($this,
'remove_iunreserved_percent_encoded'), $string);
5475 $string = preg_replace(
'/%(?![A-Fa-f0-9]{2})/',
'%25', $string);
5478 $extra_chars .=
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~%';
5481 $strlen = strlen($string);
5482 while (($position += strspn($string, $extra_chars, $position)) < $strlen)
5484 $value = ord($string[$position]);
5491 if (($value & 0xE0) === 0xC0)
5493 $character = ($value & 0x1F) << 6;
5498 elseif (($value & 0xF0) === 0xE0)
5500 $character = ($value & 0x0F) << 12;
5505 elseif (($value & 0xF8) === 0xF0)
5507 $character = ($value & 0x07) << 18;
5520 if ($position + $length <= $strlen)
5522 for ($position++; $remaining; $position++)
5524 $value = ord($string[$position]);
5526 if (($value & 0xC0) === 0x80)
5528 $character |= ($value & 0x3F) << (--$remaining * 6);
5541 $position = $strlen - 1;
5550 || $length > 1 && $character <= 0x7F
5551 || $length > 2 && $character <= 0x7FF
5552 || $length > 3 && $character <= 0xFFFF
5555 || ($character & 0xFFFE) === 0xFFFE
5556 || $character >= 0xFDD0 && $character <= 0xFDEF
5559 $character > 0xD7FF && $character < 0xF900
5560 || $character < 0xA0
5561 || $character > 0xEFFFD
5566 || $character < 0xE000
5567 || $character > 0x10FFFD
5574 for ($j =
$start; $j <= $position; $j++)
5576 $string = substr_replace($string, sprintf(
'%%%02X', ord($string[$j])), $j, 1);
5590 $bytes = explode(
'%',
$match[0]);
5597 for (
$i = 1, $len = count($bytes);
$i < $len;
$i++)
5599 $value = hexdec($bytes[
$i]);
5610 $character = $value;
5614 elseif (($value & 0xE0) === 0xC0)
5616 $character = ($value & 0x1F) << 6;
5621 elseif (($value & 0xF0) === 0xE0)
5623 $character = ($value & 0x0F) << 12;
5628 elseif (($value & 0xF8) === 0xF0)
5630 $character = ($value & 0x07) << 18;
5645 if (($value & 0xC0) === 0x80)
5648 $character |= ($value & 0x3F) << ($remaining * 6);
5666 || $length > 1 && $character <= 0x7F
5667 || $length > 2 && $character <= 0x7FF
5668 || $length > 3 && $character <= 0xFFFF
5670 || $character < 0x2D
5671 || $character > 0xEFFFD
5673 || ($character & 0xFFFE) === 0xFFFE
5674 || $character >= 0xFDD0 && $character <= 0xFDEF
5676 || $character === 0x2F
5677 || $character > 0x39 && $character < 0x41
5678 || $character > 0x5A && $character < 0x61
5679 || $character > 0x7A && $character < 0x7E
5680 || $character > 0x7E && $character < 0xA0
5681 || $character > 0xD7FF && $character < 0xF900
5686 $string .=
'%' . strtoupper($bytes[$j]);
5693 $string .= chr(hexdec($bytes[$j]));
5702 for ($j =
$start; $j < $len; $j++)
5704 $string .=
'%' . strtoupper($bytes[$j]);
5711 if (isset($this->normalization[$this->scheme][
'iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme][
'iuserinfo'])
5713 $this->iuserinfo = null;
5715 if (isset($this->normalization[$this->scheme][
'ihost']) && $this->ihost === $this->normalization[$this->scheme][
'ihost'])
5717 $this->ihost = null;
5719 if (isset($this->normalization[$this->scheme][
'port']) && $this->port === $this->normalization[$this->scheme][
'port'])
5723 if (isset($this->normalization[$this->scheme][
'ipath']) && $this->ipath === $this->normalization[$this->scheme][
'ipath'])
5727 if (isset($this->normalization[$this->scheme][
'iquery']) && $this->iquery === $this->normalization[$this->scheme][
'iquery'])
5729 $this->iquery = null;
5731 if (isset($this->normalization[$this->scheme][
'ifragment']) && $this->ifragment === $this->normalization[$this->scheme][
'ifragment'])