PEEL Shopping
Open source ecommerce : PEEL Shopping
Simplepie.php
Go to the documentation of this file.
1 <?php
48 define('SIMPLEPIE_NAME', 'SimplePie');
49 define('SIMPLEPIE_VERSION', '1.3.1');
50 define('SIMPLEPIE_BUILD', '20121030175911');
51 define('SIMPLEPIE_URL', 'http://simplepie.org');
52 define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD);
53 define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>');
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);
119 {
120 
121  public $data = array();
122 
123  public $error;
124 
125  public $sanitize;
126 
128 
129  public $feed_url;
130 
131  public $file;
132 
133  public $raw_data;
134 
135  public $timeout = 10;
136 
137  public $force_fsockopen = false;
138 
139  public $force_feed = false;
140 
141  public $cache = true;
142 
143  public $cache_duration = 3600;
144 
145  public $autodiscovery_cache_duration = 604800; // 7 Days.
146 
147  public $cache_location = './cache';
148 
149  public $cache_name_function = 'md5';
150 
151  public $order_by_date = true;
152 
153  public $input_encoding = false;
154 
156 
157  public $registry;
158 
159  public $max_checked_feeds = 10;
160 
161  public $all_discovered_feeds = array();
162 
163  public $image_handler = '';
164 
165  public $multifeed_url = array();
166 
167  public $multifeed_objects = array();
168 
169  public $config_settings = null;
170 
171  public $item_limit = 0;
172 
173  public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
174 
175  public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
176 
177  public function __construct()
178  {
179  if (version_compare(PHP_VERSION, '5.2', '<'))
180  {
181  trigger_error('PHP 4.x, 5.0 and 5.1 are no longer supported. Please upgrade to PHP 5.2 or newer.');
182  die();
183  }
184  // Other objects, instances created here so we can set options on them
185  $this->sanitize = new SimplePie_Sanitize();
186  $this->registry = new SimplePie_Registry();
187  if (func_num_args() > 0)
188  {
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)) {
193  case 3:
194  $this->set_cache_duration($args[2]);
195  case 2:
196  $this->set_cache_location($args[1]);
197  case 1:
198  $this->set_feed_url($args[0]);
199  $this->init();
200  }
201  }
202  }
203 
204  public function __toString()
205  {
206  return md5(serialize($this->data));
207  }
208 
209  public function __destruct()
210  {
211  if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
212  {
213  if (!empty($this->data['items']))
214  {
215  foreach ($this->data['items'] as $item)
216  {
217  $item->__destruct();
218  }
219  unset($item, $this->data['items']);
220  }
221  if (!empty($this->data['ordered_items']))
222  {
223  foreach ($this->data['ordered_items'] as $item)
224  {
225  $item->__destruct();
226  }
227  unset($item, $this->data['ordered_items']);
228  }
229  }
230  }
231 
232  public function force_feed($enable = false)
233  {
234  $this->force_feed = (bool) $enable;
235  }
236 
237  public function set_feed_url($url)
238  {
239  $this->multifeed_url = array();
240  if (is_array($url))
241  {
242  foreach ($url as $value)
243  {
244  $this->multifeed_url[] = $this->registry->call('Misc', 'fix_protocol', array($value, 1));
245  }
246  }
247  else
248  {
249  $this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1));
250  }
251  }
252 
253  public function set_file(&$file)
254  {
255  if ($file instanceof SimplePie_File)
256  {
257  $this->feed_url = $file->url;
258  $this->file =& $file;
259  return true;
260  }
261  return false;
262  }
263 
264  public function set_raw_data($data)
265  {
266  $this->raw_data = $data;
267  }
268 
269  public function set_timeout($timeout = 10)
270  {
271  $this->timeout = (int) $timeout;
272  }
273 
274  public function force_fsockopen($enable = false)
275  {
276  $this->force_fsockopen = (bool) $enable;
277  }
278 
279  public function enable_cache($enable = true)
280  {
281  $this->cache = (bool) $enable;
282  }
283 
284  public function set_cache_duration($seconds = 3600)
285  {
286  $this->cache_duration = (int) $seconds;
287  }
288 
289  public function set_autodiscovery_cache_duration($seconds = 604800)
290  {
291  $this->autodiscovery_cache_duration = (int) $seconds;
292  }
293 
294  public function set_cache_location($location = './cache')
295  {
296  $this->cache_location = (string) $location;
297  }
298 
299  public function enable_order_by_date($enable = true)
300  {
301  $this->order_by_date = (bool) $enable;
302  }
303 
304  public function set_input_encoding($encoding = false)
305  {
306  if ($encoding)
307  {
308  $this->input_encoding = (string) $encoding;
309  }
310  else
311  {
312  $this->input_encoding = false;
313  }
314  }
315 
317  {
318  $this->autodiscovery = (int) $level;
319  }
320 
321  public function &get_registry()
322  {
323  return $this->registry;
324  }
325 
326 
327  public function set_cache_class($class = 'SimplePie_Cache')
328  {
329  return $this->registry->register('Cache', $class, true);
330  }
331 
332  public function set_locator_class($class = 'SimplePie_Locator')
333  {
334  return $this->registry->register('Locator', $class, true);
335  }
336 
337  public function set_parser_class($class = 'SimplePie_Parser')
338  {
339  return $this->registry->register('Parser', $class, true);
340  }
341 
342  public function set_file_class($class = 'SimplePie_File')
343  {
344  return $this->registry->register('File', $class, true);
345  }
346 
347  public function set_sanitize_class($class = 'SimplePie_Sanitize')
348  {
349  return $this->registry->register('Sanitize', $class, true);
350  }
351 
352  public function set_item_class($class = 'SimplePie_Item')
353  {
354  return $this->registry->register('Item', $class, true);
355  }
356 
357  public function set_author_class($class = 'SimplePie_Author')
358  {
359  return $this->registry->register('Author', $class, true);
360  }
361 
362  public function set_category_class($class = 'SimplePie_Category')
363  {
364  return $this->registry->register('Category', $class, true);
365  }
366 
367  public function set_enclosure_class($class = 'SimplePie_Enclosure')
368  {
369  return $this->registry->register('Enclosure', $class, true);
370  }
371 
372  public function set_caption_class($class = 'SimplePie_Caption')
373  {
374  return $this->registry->register('Caption', $class, true);
375  }
376 
377  public function set_copyright_class($class = 'SimplePie_Copyright')
378  {
379  return $this->registry->register('Copyright', $class, true);
380  }
381 
382  public function set_credit_class($class = 'SimplePie_Credit')
383  {
384  return $this->registry->register('Credit', $class, true);
385  }
386 
387  public function set_rating_class($class = 'SimplePie_Rating')
388  {
389  return $this->registry->register('Rating', $class, true);
390  }
391 
392  public function set_restriction_class($class = 'SimplePie_Restriction')
393  {
394  return $this->registry->register('Restriction', $class, true);
395  }
396 
397  public function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer')
398  {
399  return $this->registry->register('Content_Type_Sniffer', $class, true);
400  }
401 
402  public function set_source_class($class = 'SimplePie_Source')
403  {
404  return $this->registry->register('Source', $class, true);
405  }
406 
407 
408  public function set_useragent($ua = SIMPLEPIE_USERAGENT)
409  {
410  $this->useragent = (string) $ua;
411  }
412 
413  public function set_cache_name_function($function = 'md5')
414  {
415  if (is_callable($function))
416  {
417  $this->cache_name_function = $function;
418  }
419  }
420 
421  public function set_stupidly_fast($set = false)
422  {
423  if ($set)
424  {
425  $this->enable_order_by_date(false);
426  $this->remove_div(false);
427  $this->strip_comments(false);
428  $this->strip_htmltags(false);
429  $this->strip_attributes(false);
430  $this->set_image_handler(false);
431  }
432  }
433 
434  public function set_max_checked_feeds($max = 10)
435  {
436  $this->max_checked_feeds = (int) $max;
437  }
438  public function remove_div($enable = true)
439  {
440  $this->sanitize->remove_div($enable);
441  }
442  public function strip_htmltags($tags = '', $encode = null)
443  {
444  if ($tags === '')
445  {
446  $tags = $this->strip_htmltags;
447  }
448  $this->sanitize->strip_htmltags($tags);
449  if ($encode !== null)
450  {
451  $this->sanitize->encode_instead_of_strip($tags);
452  }
453  }
454  public function encode_instead_of_strip($enable = true)
455  {
456  $this->sanitize->encode_instead_of_strip($enable);
457  }
458  public function strip_attributes($attribs = '')
459  {
460  if ($attribs === '')
461  {
462  $attribs = $this->strip_attributes;
463  }
464  $this->sanitize->strip_attributes($attribs);
465  }
466 
467  public function set_output_encoding($encoding = 'UTF-8')
468  {
469  $this->sanitize->set_output_encoding($encoding);
470  }
471  public function strip_comments($strip = false)
472  {
473  $this->sanitize->strip_comments($strip);
474  }
475 
476  public function set_url_replacements($element_attribute = null)
477  {
478  $this->sanitize->set_url_replacements($element_attribute);
479  }
480 
481  public function set_image_handler($page = false, $qs = 'i')
482  {
483  if ($page !== false)
484  {
485  $this->sanitize->set_image_handler($page . '?' . $qs . '=');
486  }
487  else
488  {
489  $this->image_handler = '';
490  }
491  }
492 
493  public function set_item_limit($limit = 0)
494  {
495  $this->item_limit = (int) $limit;
496  }
497 
498  public function init()
499  {
500  // Check absolute bare minimum requirements.
501  if (!extension_loaded('xml') || !extension_loaded('pcre'))
502  {
503  return false;
504  }
505  // 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.
506  elseif (!extension_loaded('xmlreader'))
507  {
508  static $xml_is_sane = null;
509  if ($xml_is_sane === null)
510  {
511  $parser_check = xml_parser_create();
512  xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
513  xml_parser_free($parser_check);
514  $xml_is_sane = isset($values[0]['value']);
515  }
516  if (!$xml_is_sane)
517  {
518  return false;
519  }
520  }
521  if (method_exists($this->sanitize, 'set_registry'))
522  {
523  $this->sanitize->set_registry($this->registry);
524  }
525  // Pass whatever was set with config options over to the sanitizer.
526  // Pass the classes in for legacy support; new classes should use the registry instead
527  $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache'));
528  $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen);
529  if (!empty($this->multifeed_url))
530  {
531  $i = 0;
532  $success = 0;
533  $this->multifeed_objects = array();
534  $this->error = array();
535  foreach ($this->multifeed_url as $url)
536  {
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)
542  {
543  $this->error[$i] = $this->multifeed_objects[$i]->error();
544  }
545  $i++;
546  }
547  return (bool) $success;
548  }
549  elseif ($this->feed_url === null && $this->raw_data === null)
550  {
551  return false;
552  }
553  $this->error = null;
554  $this->data = array();
555  $this->multifeed_objects = array();
556  $cache = false;
557  if ($this->feed_url !== null)
558  {
559  $parsed_feed_url = $this->registry->call('Misc', 'parse_url', array($this->feed_url));
560  // Decide whether to enable caching
561  if ($this->cache && $parsed_feed_url['scheme'] !== '')
562  {
563  $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc'));
564  }
565  // Fetch the data via SimplePie_File into $this->raw_data
566  if (($fetched = $this->fetch_data($cache)) === true)
567  {
568  return true;
569  }
570  elseif ($fetched === false) {
571  return false;
572  }
573  list($headers, $sniffed) = $fetched;
574  }
575  // Set up array of possible encodings
576  $encodings = array();
577  // First check to see if input has been overridden.
578  if ($this->input_encoding !== false)
579  {
580  $encodings[] = $this->input_encoding;
581  }
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');
584  // RFC 3023 (only applies to sniffed content)
585  if (isset($sniffed))
586  {
587  if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml')
588  {
589  if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
590  {
591  $encodings[] = strtoupper($charset[1]);
592  }
593  $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
594  $encodings[] = 'UTF-8';
595  }
596  elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
597  {
598  if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
599  {
600  $encodings[] = $charset[1];
601  }
602  $encodings[] = 'US-ASCII';
603  }
604  // Text MIME-type default
605  elseif (substr($sniffed, 0, 5) === 'text/')
606  {
607  $encodings[] = 'US-ASCII';
608  }
609  }
610  // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
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';
614  // There's no point in trying an encoding twice
615  $encodings = array_unique($encodings);
616  // Loop through each possible encoding, till we return something, or run out of possibilities
617  foreach ($encodings as $encoding)
618  {
619  // Change the encoding to UTF-8 (as we always use UTF-8 internally)
620  if ($utf8_data = $this->registry->call('Misc', 'change_encoding', array($this->raw_data, $encoding, 'UTF-8')))
621  {
622  // Create new parser
623  $parser = $this->registry->create('Parser');
624  // If it's parsed fine
625  if ($parser->parse($utf8_data, 'UTF-8'))
626  {
627  $this->data = $parser->get_data();
628  if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE))
629  {
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__));
632  return false;
633  }
634  if (isset($headers))
635  {
636  $this->data['headers'] = $headers;
637  }
638  $this->data['build'] = SIMPLEPIE_BUILD;
639  // Cache the file if caching is enabled
640  if ($cache && !$cache->save($this))
641  {
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);
643  }
644  return true;
645  }
646  }
647  }
648  if (isset($parser))
649  {
650  // We have an error, just set SimplePie_Misc::error to it and quit
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());
652  }
653  else
654  {
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.';
656  }
657  $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
658  return false;
659  }
660 
661  protected function fetch_data(&$cache)
662  {
663  // If it's enabled, use the cache
664  if ($cache)
665  {
666  // Load the Cache
667  $this->data = $cache->load();
668  if (!empty($this->data))
669  {
670  // If the cache is for an outdated build of SimplePie
671  if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD)
672  {
673  $cache->unlink();
674  $this->data = array();
675  }
676  // If we've hit a collision just rerun it with caching disabled
677  elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url)
678  {
679  $cache = false;
680  $this->data = array();
681  }
682  // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL.
683  elseif (isset($this->data['feed_url']))
684  {
685  // If the autodiscovery cache is still valid use it.
686  if ($cache->mtime() + $this->autodiscovery_cache_duration > time())
687  {
688  // Do not need to do feed autodiscovery yet.
689  if ($this->data['feed_url'] !== $this->data['url'])
690  {
691  $this->set_feed_url($this->data['feed_url']);
692  return $this->init();
693  }
694  $cache->unlink();
695  $this->data = array();
696  }
697  }
698  // Check if the cache has been updated
699  elseif ($cache->mtime() + $this->cache_duration < time())
700  {
701  // If we have last-modified and/or etag set
702  if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag']))
703  {
704  $headers = array(
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',
706  );
707  if (isset($this->data['headers']['last-modified']))
708  {
709  $headers['if-modified-since'] = $this->data['headers']['last-modified'];
710  }
711  if (isset($this->data['headers']['etag']))
712  {
713  $headers['if-none-match'] = $this->data['headers']['etag'];
714  }
715  $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen));
716  if ($file->success)
717  {
718  if ($file->status_code === 304)
719  {
720  $cache->touch();
721  return true;
722  }
723  }
724  else
725  {
726  unset($file);
727  }
728  }
729  }
730  // If the cache is still valid, just return true
731  else
732  {
733  $this->raw_data = false;
734  return true;
735  }
736  }
737  // If the cache is empty, delete it
738  else
739  {
740  $cache->unlink();
741  $this->data = array();
742  }
743  }
744  // 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.
745  if (!isset($file))
746  {
747  if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url)
748  {
749  $file =& $this->file;
750  }
751  else
752  {
753  $headers = array(
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',
755  );
756  $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen));
757  }
758  }
759  // If the file connection has an error, set SimplePie::error to that and quit
760  if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
761  {
762  $this->error = $file->error;
763  return !empty($this->data);
764  }
765  if (!$this->force_feed)
766  {
767  // Check if the supplied URL is a feed, if it isn't, look for it.
768  $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds));
769  if (!$locate->is_feed($file))
770  {
771  // We need to unset this so that if SimplePie::set_file() has been called that object is untouched
772  unset($file);
773  try
774  {
775  if (!($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds)))
776  {
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__));
779  return false;
780  }
781  }
782  catch (SimplePie_Exception $e)
783  {
784  // This is usually because DOMDocument doesn't exist
785  $this->error = $e->getMessage();
786  $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, $e->getFile(), $e->getLine()));
787  return false;
788  }
789  if ($cache)
790  {
791  $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
792  if (!$cache->save($this))
793  {
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);
795  }
796  $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc'));
797  }
798  $this->feed_url = $file->url;
799  }
800  $locate = null;
801  }
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);
807  }
808 
809  public function error()
810  {
811  return $this->error;
812  }
813 
814  public function get_raw_data()
815  {
816  return $this->raw_data;
817  }
818 
819  public function get_encoding()
820  {
821  return $this->sanitize->output_encoding;
822  }
823 
824  public function handle_content_type($mime = 'text/html')
825  {
826  if (!headers_sent())
827  {
828  $header = "Content-type: $mime;";
829  if ($this->get_encoding())
830  {
831  $header .= ' charset=' . $this->get_encoding();
832  }
833  else
834  {
835  $header .= ' charset=UTF-8';
836  }
837  header($header);
838  }
839  }
840 
841  public function get_type()
842  {
843  if (!isset($this->data['type']))
844  {
845  $this->data['type'] = SIMPLEPIE_TYPE_ALL;
846  if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed']))
847  {
848  $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;
849  }
850  elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed']))
851  {
852  $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;
853  }
854  elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF']))
855  {
856  if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel'])
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']))
860  {
861  $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10;
862  }
863  if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel'])
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']))
867  {
868  $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;
869  }
870  }
871  elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss']))
872  {
873  $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;
874  if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
875  {
876  switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
877  {
878  case '0.91':
879  $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091;
880  if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
881  {
882  switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
883  {
884  case '0':
885  $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE;
886  break;
887  case '24':
888  $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND;
889  break;
890  }
891  }
892  break;
893  case '0.92':
894  $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092;
895  break;
896  case '0.93':
897  $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093;
898  break;
899  case '0.94':
900  $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094;
901  break;
902  case '2.0':
903  $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20;
904  break;
905  }
906  }
907  }
908  else
909  {
910  $this->data['type'] = SIMPLEPIE_TYPE_NONE;
911  }
912  }
913  return $this->data['type'];
914  }
915 
916  public function subscribe_url()
917  {
918  if ($this->feed_url !== null)
919  {
920  return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI);
921  }
922  else
923  {
924  return null;
925  }
926  }
927 
928  public function get_feed_tags($namespace, $tag)
929  {
930  $type = $this->get_type();
931  if ($type & SIMPLEPIE_TYPE_ATOM_10)
932  {
933  if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]))
934  {
935  return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag];
936  }
937  }
938  if ($type & SIMPLEPIE_TYPE_ATOM_03)
939  {
940  if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]))
941  {
942  return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag];
943  }
944  }
945  if ($type & SIMPLEPIE_TYPE_RSS_RDF)
946  {
947  if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]))
948  {
949  return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag];
950  }
951  }
952  if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
953  {
954  if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag]))
955  {
956  return $this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag];
957  }
958  }
959  return null;
960  }
961 
962  public function get_channel_tags($namespace, $tag)
963  {
964  $type = $this->get_type();
965  if ($type & SIMPLEPIE_TYPE_ATOM_ALL)
966  {
967  if ($return = $this->get_feed_tags($namespace, $tag))
968  {
969  return $return;
970  }
971  }
972  if ($type & SIMPLEPIE_TYPE_RSS_10)
973  {
974  if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel'))
975  {
976  if (isset($channel[0]['child'][$namespace][$tag]))
977  {
978  return $channel[0]['child'][$namespace][$tag];
979  }
980  }
981  }
982  if ($type & SIMPLEPIE_TYPE_RSS_090)
983  {
984  if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel'))
985  {
986  if (isset($channel[0]['child'][$namespace][$tag]))
987  {
988  return $channel[0]['child'][$namespace][$tag];
989  }
990  }
991  }
992  if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
993  {
994  if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'channel'))
995  {
996  if (isset($channel[0]['child'][$namespace][$tag]))
997  {
998  return $channel[0]['child'][$namespace][$tag];
999  }
1000  }
1001  }
1002  return null;
1003  }
1004 
1005  public function get_image_tags($namespace, $tag)
1006  {
1007  $type = $this->get_type();
1008  if ($type & SIMPLEPIE_TYPE_RSS_10)
1009  {
1010  if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image'))
1011  {
1012  if (isset($image[0]['child'][$namespace][$tag]))
1013  {
1014  return $image[0]['child'][$namespace][$tag];
1015  }
1016  }
1017  }
1018  if ($type & SIMPLEPIE_TYPE_RSS_090)
1019  {
1020  if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image'))
1021  {
1022  if (isset($image[0]['child'][$namespace][$tag]))
1023  {
1024  return $image[0]['child'][$namespace][$tag];
1025  }
1026  }
1027  }
1028  if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
1029  {
1030  if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'image'))
1031  {
1032  if (isset($image[0]['child'][$namespace][$tag]))
1033  {
1034  return $image[0]['child'][$namespace][$tag];
1035  }
1036  }
1037  }
1038  return null;
1039  }
1040 
1041  public function get_base($element = array())
1042  {
1043  if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
1044  {
1045  return $element['xml_base'];
1046  }
1047  elseif ($this->get_link() !== null)
1048  {
1049  return $this->get_link();
1050  }
1051  else
1052  {
1053  return $this->subscribe_url();
1054  }
1055  }
1056 
1057  public function sanitize($data, $type, $base = '')
1058  {
1059  return $this->sanitize->sanitize($data, $type, $base);
1060  }
1061 
1062  public function get_title()
1063  {
1064  if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
1065  {
1066  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
1067  }
1068  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
1069  {
1070  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
1071  }
1072  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
1073  {
1074  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
1075  }
1076  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
1077  {
1078  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
1079  }
1080  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
1081  {
1082  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
1083  }
1084  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
1085  {
1086  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1087  }
1088  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
1089  {
1090  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1091  }
1092  else
1093  {
1094  return null;
1095  }
1096  }
1097 
1098  public function get_category($key = 0)
1099  {
1100  $categories = $this->get_categories();
1101  if (isset($categories[$key]))
1102  {
1103  return $categories[$key];
1104  }
1105  else
1106  {
1107  return null;
1108  }
1109  }
1110 
1111  public function get_categories()
1112  {
1113  $categories = array();
1114  foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
1115  {
1116  $term = null;
1117  $scheme = null;
1118  $label = null;
1119  if (isset($category['attribs']['']['term']))
1120  {
1121  $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
1122  }
1123  if (isset($category['attribs']['']['scheme']))
1124  {
1125  $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
1126  }
1127  if (isset($category['attribs']['']['label']))
1128  {
1129  $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
1130  }
1131  $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
1132  }
1133  foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
1134  {
1135  // This is really the label, but keep this as the term also for BC.
1136  // Label will also work on retrieving because that falls back to term.
1137  $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1138  if (isset($category['attribs']['']['domain']))
1139  {
1140  $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
1141  }
1142  else
1143  {
1144  $scheme = null;
1145  }
1146  $categories[] = $this->registry->create('Category', array($term, $scheme, null));
1147  }
1148  foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
1149  {
1150  $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
1151  }
1152  foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
1153  {
1154  $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
1155  }
1156  if (!empty($categories))
1157  {
1158  return array_unique($categories);
1159  }
1160  else
1161  {
1162  return null;
1163  }
1164  }
1165 
1166  public function get_author($key = 0)
1167  {
1168  $authors = $this->get_authors();
1169  if (isset($authors[$key]))
1170  {
1171  return $authors[$key];
1172  }
1173  else
1174  {
1175  return null;
1176  }
1177  }
1178 
1179  public function get_authors()
1180  {
1181  $authors = array();
1182  foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
1183  {
1184  $name = null;
1185  $uri = null;
1186  $email = null;
1187  if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
1188  {
1189  $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1190  }
1191  if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
1192  {
1193  $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]));
1194  }
1195  if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
1196  {
1197  $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1198  }
1199  if ($name !== null || $email !== null || $uri !== null)
1200  {
1201  $authors[] = $this->registry->create('Author', array($name, $uri, $email));
1202  }
1203  }
1204  if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
1205  {
1206  $name = null;
1207  $url = null;
1208  $email = null;
1209  if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
1210  {
1211  $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1212  }
1213  if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
1214  {
1215  $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]));
1216  }
1217  if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
1218  {
1219  $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1220  }
1221  if ($name !== null || $email !== null || $url !== null)
1222  {
1223  $authors[] = $this->registry->create('Author', array($name, $url, $email));
1224  }
1225  }
1226  foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
1227  {
1228  $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
1229  }
1230  foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
1231  {
1232  $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
1233  }
1234  foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
1235  {
1236  $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
1237  }
1238  if (!empty($authors))
1239  {
1240  return array_unique($authors);
1241  }
1242  else
1243  {
1244  return null;
1245  }
1246  }
1247 
1248  public function get_contributor($key = 0)
1249  {
1250  $contributors = $this->get_contributors();
1251  if (isset($contributors[$key]))
1252  {
1253  return $contributors[$key];
1254  }
1255  else
1256  {
1257  return null;
1258  }
1259  }
1260 
1261  public function get_contributors()
1262  {
1263  $contributors = array();
1264  foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
1265  {
1266  $name = null;
1267  $uri = null;
1268  $email = null;
1269  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
1270  {
1271  $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1272  }
1273  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
1274  {
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]));
1276  }
1277  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
1278  {
1279  $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1280  }
1281  if ($name !== null || $email !== null || $uri !== null)
1282  {
1283  $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
1284  }
1285  }
1286  foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
1287  {
1288  $name = null;
1289  $url = null;
1290  $email = null;
1291  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
1292  {
1293  $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1294  }
1295  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
1296  {
1297  $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]));
1298  }
1299  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
1300  {
1301  $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1302  }
1303  if ($name !== null || $email !== null || $url !== null)
1304  {
1305  $contributors[] = $this->registry->create('Author', array($name, $url, $email));
1306  }
1307  }
1308  if (!empty($contributors))
1309  {
1310  return array_unique($contributors);
1311  }
1312  else
1313  {
1314  return null;
1315  }
1316  }
1317 
1318  public function get_link($key = 0, $rel = 'alternate')
1319  {
1320  $links = $this->get_links($rel);
1321  if (isset($links[$key]))
1322  {
1323  return $links[$key];
1324  }
1325  else
1326  {
1327  return null;
1328  }
1329  }
1330 
1331  public function get_permalink()
1332  {
1333  return $this->get_link(0);
1334  }
1335 
1336  public function get_links($rel = 'alternate')
1337  {
1338  if (!isset($this->data['links']))
1339  {
1340  $this->data['links'] = array();
1341  if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
1342  {
1343  foreach ($links as $link)
1344  {
1345  if (isset($link['attribs']['']['href']))
1346  {
1347  $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
1348  $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
1349  }
1350  }
1351  }
1352  if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
1353  {
1354  foreach ($links as $link)
1355  {
1356  if (isset($link['attribs']['']['href']))
1357  {
1358  $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
1359  $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
1360  }
1361  }
1362  }
1363  if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
1364  {
1365  $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
1366  }
1367  if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
1368  {
1369  $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
1370  }
1371  if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
1372  {
1373  $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
1374  }
1375  $keys = array_keys($this->data['links']);
1376  foreach ($keys as $key)
1377  {
1378  if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
1379  {
1380  if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
1381  {
1382  $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
1383  $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
1384  }
1385  else
1386  {
1387  $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
1388  }
1389  }
1390  elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
1391  {
1392  $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
1393  }
1394  $this->data['links'][$key] = array_unique($this->data['links'][$key]);
1395  }
1396  }
1397  if (isset($this->data['links'][$rel]))
1398  {
1399  return $this->data['links'][$rel];
1400  }
1401  else
1402  {
1403  return null;
1404  }
1405  }
1406  public function get_all_discovered_feeds()
1407  {
1409  }
1410 
1411  public function get_description()
1412  {
1413  if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
1414  {
1415  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
1416  }
1417  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
1418  {
1419  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
1420  }
1421  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
1422  {
1423  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
1424  }
1425  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
1426  {
1427  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
1428  }
1429  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
1430  {
1431  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
1432  }
1433  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
1434  {
1435  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1436  }
1437  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
1438  {
1439  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1440  }
1441  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
1442  {
1443  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
1444  }
1445  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
1446  {
1447  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
1448  }
1449  else
1450  {
1451  return null;
1452  }
1453  }
1454 
1455  public function get_copyright()
1456  {
1457  if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
1458  {
1459  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
1460  }
1461  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
1462  {
1463  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
1464  }
1465  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
1466  {
1467  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1468  }
1469  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
1470  {
1471  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1472  }
1473  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
1474  {
1475  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1476  }
1477  else
1478  {
1479  return null;
1480  }
1481  }
1482 
1483  public function get_language()
1484  {
1485  if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
1486  {
1487  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1488  }
1489  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
1490  {
1491  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1492  }
1493  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
1494  {
1495  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1496  }
1497  elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang']))
1498  {
1499  return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
1500  }
1501  elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang']))
1502  {
1503  return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
1504  }
1505  elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang']))
1506  {
1507  return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
1508  }
1509  elseif (isset($this->data['headers']['content-language']))
1510  {
1511  return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT);
1512  }
1513  else
1514  {
1515  return null;
1516  }
1517  }
1518 
1519  public function get_latitude()
1520  {
1521  if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
1522  {
1523  return (float) $return[0]['data'];
1524  }
1525  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))
1526  {
1527  return (float) $match[1];
1528  }
1529  else
1530  {
1531  return null;
1532  }
1533  }
1534 
1535  public function get_longitude()
1536  {
1537  if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
1538  {
1539  return (float) $return[0]['data'];
1540  }
1541  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
1542  {
1543  return (float) $return[0]['data'];
1544  }
1545  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))
1546  {
1547  return (float) $match[2];
1548  }
1549  else
1550  {
1551  return null;
1552  }
1553  }
1554 
1555  public function get_image_title()
1556  {
1557  if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
1558  {
1559  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1560  }
1561  elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
1562  {
1563  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1564  }
1565  elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
1566  {
1567  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1568  }
1569  elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
1570  {
1571  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1572  }
1573  elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
1574  {
1575  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1576  }
1577  else
1578  {
1579  return null;
1580  }
1581  }
1582 
1583  public function get_image_url()
1584  {
1585  if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
1586  {
1587  return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
1588  }
1589  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
1590  {
1591  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
1592  }
1593  elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
1594  {
1595  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
1596  }
1597  elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url'))
1598  {
1599  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
1600  }
1601  elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url'))
1602  {
1603  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
1604  }
1605  elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
1606  {
1607  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
1608  }
1609  else
1610  {
1611  return null;
1612  }
1613  }
1614 
1615  public function get_image_link()
1616  {
1617  if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
1618  {
1619  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
1620  }
1621  elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
1622  {
1623  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
1624  }
1625  elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
1626  {
1627  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
1628  }
1629  else
1630  {
1631  return null;
1632  }
1633  }
1634 
1635  public function get_image_width()
1636  {
1637  if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width'))
1638  {
1639  return round($return[0]['data']);
1640  }
1642  {
1643  return 88.0;
1644  }
1645  else
1646  {
1647  return null;
1648  }
1649  }
1650 
1651  public function get_image_height()
1652  {
1653  if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'height'))
1654  {
1655  return round($return[0]['data']);
1656  }
1658  {
1659  return 31.0;
1660  }
1661  else
1662  {
1663  return null;
1664  }
1665  }
1666 
1667  public function get_item_quantity($max = 0)
1668  {
1669  $max = (int) $max;
1670  $qty = count($this->get_items());
1671  if ($max === 0)
1672  {
1673  return $qty;
1674  }
1675  else
1676  {
1677  return ($qty > $max) ? $max : $qty;
1678  }
1679  }
1680 
1681  public function get_item($key = 0)
1682  {
1683  $items = $this->get_items();
1684  if (isset($items[$key]))
1685  {
1686  return $items[$key];
1687  }
1688  else
1689  {
1690  return null;
1691  }
1692  }
1693 
1694  public function get_items($start = 0, $end = 0)
1695  {
1696  if (!isset($this->data['items']))
1697  {
1698  if (!empty($this->multifeed_objects))
1699  {
1700  $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit);
1701  }
1702  else
1703  {
1704  $this->data['items'] = array();
1705  if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry'))
1706  {
1707  $keys = array_keys($items);
1708  foreach ($keys as $key)
1709  {
1710  $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
1711  }
1712  }
1713  if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry'))
1714  {
1715  $keys = array_keys($items);
1716  foreach ($keys as $key)
1717  {
1718  $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
1719  }
1720  }
1721  if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item'))
1722  {
1723  $keys = array_keys($items);
1724  foreach ($keys as $key)
1725  {
1726  $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
1727  }
1728  }
1729  if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item'))
1730  {
1731  $keys = array_keys($items);
1732  foreach ($keys as $key)
1733  {
1734  $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
1735  }
1736  }
1737  if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item'))
1738  {
1739  $keys = array_keys($items);
1740  foreach ($keys as $key)
1741  {
1742  $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
1743  }
1744  }
1745  }
1746  }
1747  if (!empty($this->data['items']))
1748  {
1749  // If we want to order it by date, check if all items have a date, and then sort it
1750  if ($this->order_by_date && empty($this->multifeed_objects))
1751  {
1752  if (!isset($this->data['ordered_items']))
1753  {
1754  $do_sort = true;
1755  foreach ($this->data['items'] as $item)
1756  {
1757  if (!$item->get_date('U'))
1758  {
1759  $do_sort = false;
1760  break;
1761  }
1762  }
1763  $item = null;
1764  $this->data['ordered_items'] = $this->data['items'];
1765  if ($do_sort)
1766  {
1767  usort($this->data['ordered_items'], array(get_class($this), 'sort_items'));
1768  }
1769  }
1770  $items = $this->data['ordered_items'];
1771  }
1772  else
1773  {
1774  $items = $this->data['items'];
1775  }
1776  // Slice the data as desired
1777  if ($end === 0)
1778  {
1779  return array_slice($items, $start);
1780  }
1781  else
1782  {
1783  return array_slice($items, $start, $end);
1784  }
1785  }
1786  else
1787  {
1788  return array();
1789  }
1790  }
1791 
1792  public function set_favicon_handler($page = false, $qs = 'i')
1793  {
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);
1796  return false;
1797  }
1798 
1799  public function get_favicon()
1800  {
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);
1803  if (($url = $this->get_link()) !== null)
1804  {
1805  return 'http://g.etfv.co/' . urlencode($url);
1806  }
1807  return false;
1808  }
1809 
1810  public function __call($method, $args)
1811  {
1812  if (strpos($method, 'subscribe_') === 0)
1813  {
1814  $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
1815  trigger_error('subscribe_*() has been deprecated, implement the callback yourself', $level);
1816  return '';
1817  }
1818  if ($method === 'enable_xml_dump')
1819  {
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);
1822  return false;
1823  }
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);
1829  }
1830 
1831  public static function sort_items($a, $b)
1832  {
1833  return $a->get_date('U') <= $b->get_date('U');
1834  }
1835 
1836  public static function merge_items($urls, $start = 0, $end = 0, $limit = 0)
1837  {
1838  if (is_array($urls) && sizeof($urls) > 0)
1839  {
1840  $items = array();
1841  foreach ($urls as $arg)
1842  {
1843  if ($arg instanceof SimplePie)
1844  {
1845  $items = array_merge($items, $arg->get_items(0, $limit));
1846  }
1847  else
1848  {
1849  trigger_error('Arguments must be SimplePie objects', E_USER_WARNING);
1850  }
1851  }
1852  $do_sort = true;
1853  foreach ($items as $item)
1854  {
1855  if (!$item->get_date('U'))
1856  {
1857  $do_sort = false;
1858  break;
1859  }
1860  }
1861  $item = null;
1862  if ($do_sort)
1863  {
1864  usort($items, array(get_class($urls[0]), 'sort_items'));
1865  }
1866  if ($end === 0)
1867  {
1868  return array_slice($items, $start);
1869  }
1870  else
1871  {
1872  return array_slice($items, $start, $end);
1873  }
1874  }
1875  else
1876  {
1877  trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING);
1878  return array();
1879  }
1880  }
1881 }
1883 {
1884 
1885  var $name;
1886 
1887  var $link;
1888 
1889  var $email;
1890 
1891  public function __construct($name = null, $link = null, $email = null)
1892  {
1893  $this->name = $name;
1894  $this->link = $link;
1895  $this->email = $email;
1896  }
1897 
1898  public function __toString()
1899  {
1900  // There is no $this->data here
1901  return md5(serialize($this));
1902  }
1903 
1904  public function get_name()
1905  {
1906  if ($this->name !== null)
1907  {
1908  return $this->name;
1909  }
1910  else
1911  {
1912  return null;
1913  }
1914  }
1915 
1916  public function get_link()
1917  {
1918  if ($this->link !== null)
1919  {
1920  return $this->link;
1921  }
1922  else
1923  {
1924  return null;
1925  }
1926  }
1927 
1928  public function get_email()
1929  {
1930  if ($this->email !== null)
1931  {
1932  return $this->email;
1933  }
1934  else
1935  {
1936  return null;
1937  }
1938  }
1939 }
1941 {
1942 
1943  const TYPE_FEED = 'spc';
1944 
1945  const TYPE_IMAGE = 'spi';
1946 
1947  public function __construct($location, $name, $type);
1948 
1949  public function save($data);
1950 
1951  public function load();
1952 
1953  public function mtime();
1954 
1955  public function touch();
1956 
1957  public function unlink();
1958 }
1959 abstract class SimplePie_Cache_DB implements SimplePie_Cache_Base
1960 {
1961 
1962  protected static function prepare_simplepie_object_for_cache($data)
1963  {
1964  $items = $data->get_items();
1965  $items_by_id = array();
1966  if (!empty($items))
1967  {
1968  foreach ($items as $item)
1969  {
1970  $items_by_id[$item->get_id()] = $item;
1971  }
1972  if (count($items_by_id) !== count($items))
1973  {
1974  $items_by_id = array();
1975  foreach ($items as $item)
1976  {
1977  $items_by_id[$item->get_id(true)] = $item;
1978  }
1979  }
1980  if (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
1981  {
1982  $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
1983  }
1984  elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
1985  {
1986  $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
1987  }
1988  elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
1989  {
1990  $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
1991  }
1992  elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0]))
1993  {
1994  $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0];
1995  }
1996  else
1997  {
1998  $channel = null;
1999  }
2000  if ($channel !== null)
2001  {
2002  if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']))
2003  {
2004  unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']);
2005  }
2006  if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']))
2007  {
2008  unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']);
2009  }
2010  if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']))
2011  {
2012  unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']);
2013  }
2014  if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']))
2015  {
2016  unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']);
2017  }
2018  if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']))
2019  {
2020  unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']);
2021  }
2022  }
2023  if (isset($data->data['items']))
2024  {
2025  unset($data->data['items']);
2026  }
2027  if (isset($data->data['ordered_items']))
2028  {
2029  unset($data->data['ordered_items']);
2030  }
2031  }
2032  return array(serialize($data->data), $items_by_id);
2033  }
2034 }
2036 {
2037 
2038  protected $location;
2039 
2040  protected $filename;
2041 
2042  protected $extension;
2043 
2044  protected $name;
2045 
2046  public function __construct($location, $name, $type)
2047  {
2048  $this->location = $location;
2049  $this->filename = $name;
2050  $this->extension = $type;
2051  $this->name = "$this->location/$this->filename.$this->extension";
2052  }
2053 
2054  public function save($data)
2055  {
2056  if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
2057  {
2058  if ($data instanceof SimplePie)
2059  {
2060  $data = $data->data;
2061  }
2062  $data = serialize($data);
2063  return (bool) file_put_contents($this->name, $data);
2064  }
2065  return false;
2066  }
2067 
2068  public function load()
2069  {
2070  if (file_exists($this->name) && is_readable($this->name))
2071  {
2072  return unserialize(file_get_contents($this->name));
2073  }
2074  return false;
2075  }
2076 
2077  public function mtime()
2078  {
2079  if (file_exists($this->name))
2080  {
2081  return filemtime($this->name);
2082  }
2083  return false;
2084  }
2085 
2086  public function touch()
2087  {
2088  if (file_exists($this->name))
2089  {
2090  return touch($this->name);
2091  }
2092  return false;
2093  }
2094 
2095  public function unlink()
2096  {
2097  if (file_exists($this->name))
2098  {
2099  return unlink($this->name);
2100  }
2101  return false;
2102  }
2103 }
2105 {
2106 
2107  protected $cache;
2108 
2109  protected $options;
2110 
2111  protected $name;
2112 
2113  public function __construct($location, $name, $type)
2114  {
2115  $this->options = array(
2116  'host' => '127.0.0.1',
2117  'port' => 11211,
2118  'extras' => array(
2119  'timeout' => 3600, // one hour
2120  'prefix' => 'simplepie_',
2121  ),
2122  );
2123  $parsed = SimplePie_Cache::parse_URL($location);
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']);
2130  }
2131 
2132  public function save($data)
2133  {
2134  if ($data instanceof SimplePie)
2135  {
2136  $data = $data->data;
2137  }
2138  return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
2139  }
2140 
2141  public function load()
2142  {
2143  $data = $this->cache->get($this->name);
2144  if ($data !== false)
2145  {
2146  return unserialize($data);
2147  }
2148  return false;
2149  }
2150 
2151  public function mtime()
2152  {
2153  $data = $this->cache->get($this->name);
2154  if ($data !== false)
2155  {
2156  // essentially ignore the mtime because Memcache expires on it's own
2157  return time();
2158  }
2159  return false;
2160  }
2161 
2162  public function touch()
2163  {
2164  $data = $this->cache->get($this->name);
2165  if ($data !== false)
2166  {
2167  return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->duration);
2168  }
2169  return false;
2170  }
2171 
2172  public function unlink()
2173  {
2174  return $this->cache->delete($this->name, 0);
2175  }
2176 }
2178 {
2179 
2180  protected $mysql;
2181 
2182  protected $options;
2183 
2184  protected $id;
2185 
2186  public function __construct($location, $name, $type)
2187  {
2188  $this->options = array(
2189  'user' => null,
2190  'pass' => null,
2191  'host' => '127.0.0.1',
2192  'port' => '3306',
2193  'path' => '',
2194  'extras' => array(
2195  'prefix' => '',
2196  ),
2197  );
2198  $this->options = array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));
2199  // Path is prefixed with a "/"
2200  $this->options['dbname'] = substr($this->options['path'], 1);
2201  try
2202  {
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'));
2204  }
2205  catch (PDOException $e)
2206  {
2207  $this->mysql = null;
2208  return;
2209  }
2210  $this->id = $name . $type;
2211  if (!$query = $this->mysql->query('SHOW TABLES'))
2212  {
2213  $this->mysql = null;
2214  return;
2215  }
2216  $db = array();
2217  while ($row = $query->fetchColumn())
2218  {
2219  $db[] = $row;
2220  }
2221  if (!in_array($this->options['extras']['prefix'] . 'cache_data', $db))
2222  {
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)))');
2224  if ($query === false)
2225  {
2226  $this->mysql = null;
2227  }
2228  }
2229  if (!in_array($this->options['extras']['prefix'] . 'items', $db))
2230  {
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)))');
2232  if ($query === false)
2233  {
2234  $this->mysql = null;
2235  }
2236  }
2237  }
2238 
2239  public function save($data)
2240  {
2241  if ($this->mysql === null)
2242  {
2243  return false;
2244  }
2245  if ($data instanceof SimplePie)
2246  {
2247  $data = clone $data;
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);
2251  if ($query->execute())
2252  {
2253  if ($query->fetchColumn() > 0)
2254  {
2255  $items = count($prepared[1]);
2256  if ($items)
2257  {
2258  $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed';
2259  $query = $this->mysql->prepare($sql);
2260  $query->bindValue(':items', $items);
2261  }
2262  else
2263  {
2264  $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed';
2265  $query = $this->mysql->prepare($sql);
2266  }
2267  $query->bindValue(':data', $prepared[0]);
2268  $query->bindValue(':time', time());
2269  $query->bindValue(':feed', $this->id);
2270  if (!$query->execute())
2271  {
2272  return false;
2273  }
2274  }
2275  else
2276  {
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());
2282  if (!$query->execute())
2283  {
2284  return false;
2285  }
2286  }
2287  $ids = array_keys($prepared[1]);
2288  if (!empty($ids))
2289  {
2290  foreach ($ids as $id)
2291  {
2292  $database_ids[] = $this->mysql->quote($id);
2293  }
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);
2296  if ($query->execute())
2297  {
2298  $existing_ids = array();
2299  while ($row = $query->fetchColumn())
2300  {
2301  $existing_ids[] = $row;
2302  }
2303  $new_ids = array_diff($ids, $existing_ids);
2304  foreach ($new_ids as $new_id)
2305  {
2306  if (!($date = $prepared[1][$new_id]->get_date('U')))
2307  {
2308  $date = time();
2309  }
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);
2315  if (!$query->execute())
2316  {
2317  return false;
2318  }
2319  }
2320  return true;
2321  }
2322  }
2323  else
2324  {
2325  return true;
2326  }
2327  }
2328  }
2329  else
2330  {
2331  $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
2332  $query->bindValue(':feed', $this->id);
2333  if ($query->execute())
2334  {
2335  if ($query->rowCount() > 0)
2336  {
2337  $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed');
2338  $query->bindValue(':data', serialize($data));
2339  $query->bindValue(':time', time());
2340  $query->bindValue(':feed', $this->id);
2341  if ($this->execute())
2342  {
2343  return true;
2344  }
2345  }
2346  else
2347  {
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);
2350  $query->bindValue(':data', serialize($data));
2351  $query->bindValue(':time', time());
2352  if ($query->execute())
2353  {
2354  return true;
2355  }
2356  }
2357  }
2358  }
2359  return false;
2360  }
2361 
2362  public function load()
2363  {
2364  if ($this->mysql === null)
2365  {
2366  return false;
2367  }
2368  $query = $this->mysql->prepare('SELECT `items`, `data` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
2369  $query->bindValue(':id', $this->id);
2370  if ($query->execute() && ($row = $query->fetch()))
2371  {
2372  $data = unserialize($row[1]);
2373  if (isset($this->options['items'][0]))
2374  {
2375  $items = (int) $this->options['items'][0];
2376  }
2377  else
2378  {
2379  $items = (int) $row[0];
2380  }
2381  if ($items !== 0)
2382  {
2383  if (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
2384  {
2385  $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
2386  }
2387  elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
2388  {
2389  $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
2390  }
2391  elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
2392  {
2393  $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
2394  }
2395  elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]))
2396  {
2397  $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0];
2398  }
2399  else
2400  {
2401  $feed = null;
2402  }
2403  if ($feed !== null)
2404  {
2405  $sql = 'SELECT `data` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :feed ORDER BY `posted` DESC';
2406  if ($items > 0)
2407  {
2408  $sql .= ' LIMIT ' . $items;
2409  }
2410  $query = $this->mysql->prepare($sql);
2411  $query->bindValue(':feed', $this->id);
2412  if ($query->execute())
2413  {
2414  while ($row = $query->fetchColumn())
2415  {
2416  $feed['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'][] = unserialize($row);
2417  }
2418  }
2419  else
2420  {
2421  return false;
2422  }
2423  }
2424  }
2425  return $data;
2426  }
2427  return false;
2428  }
2429 
2430  public function mtime()
2431  {
2432  if ($this->mysql === null)
2433  {
2434  return false;
2435  }
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()))
2439  {
2440  return $time;
2441  }
2442  else
2443  {
2444  return false;
2445  }
2446  }
2447 
2448  public function touch()
2449  {
2450  if ($this->mysql === null)
2451  {
2452  return false;
2453  }
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);
2457  if ($query->execute() && $query->rowCount() > 0)
2458  {
2459  return true;
2460  }
2461  else
2462  {
2463  return false;
2464  }
2465  }
2466 
2467  public function unlink()
2468  {
2469  if ($this->mysql === null)
2470  {
2471  return false;
2472  }
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())
2478  {
2479  return true;
2480  }
2481  else
2482  {
2483  return false;
2484  }
2485  }
2486 }
2488 {
2489 
2490  protected static $handlers = array(
2491  'mysql' => 'SimplePie_Cache_MySQL',
2492  'memcache' => 'SimplePie_Cache_Memcache',
2493  );
2494 
2495  private function __construct() { }
2496 
2497  public static function get_handler($location, $filename, $extension)
2498  {
2499  $type = explode(':', $location, 2);
2500  $type = $type[0];
2501  if (!empty(self::$handlers[$type]))
2502  {
2503  $class = self::$handlers[$type];
2504  return new $class($location, $filename, $extension);
2505  }
2506  return new SimplePie_Cache_File($location, $filename, $extension);
2507  }
2508 
2509  public function create($location, $filename, $extension)
2510  {
2511  trigger_error('Cache::create() has been replaced with Cache::get_handler(). Switch to the registry system to use this.', E_USER_DEPRECATED);
2512  return self::get_handler($location, $filename, $extension);
2513  }
2514 
2515  public static function register($type, $class)
2516  {
2517  self::$handlers[$type] = $class;
2518  }
2519 
2520  public static function parse_URL($url)
2521  {
2522  $params = parse_url($url);
2523  $params['extras'] = array();
2524  if (isset($params['query']))
2525  {
2526  parse_str($params['query'], $params['extras']);
2527  }
2528  return $params;
2529  }
2530 }
2532 {
2533 
2534  var $type;
2535 
2536  var $lang;
2537 
2539 
2541 
2542  var $text;
2543 
2544  public function __construct($type = null, $lang = null, $startTime = null, $endTime = null, $text = null)
2545  {
2546  $this->type = $type;
2547  $this->lang = $lang;
2548  $this->startTime = $startTime;
2549  $this->endTime = $endTime;
2550  $this->text = $text;
2551  }
2552 
2553  public function __toString()
2554  {
2555  // There is no $this->data here
2556  return md5(serialize($this));
2557  }
2558 
2559  public function get_endtime()
2560  {
2561  if ($this->endTime !== null)
2562  {
2563  return $this->endTime;
2564  }
2565  else
2566  {
2567  return null;
2568  }
2569  }
2570 
2571  public function get_language()
2572  {
2573  if ($this->lang !== null)
2574  {
2575  return $this->lang;
2576  }
2577  else
2578  {
2579  return null;
2580  }
2581  }
2582 
2583  public function get_starttime()
2584  {
2585  if ($this->startTime !== null)
2586  {
2587  return $this->startTime;
2588  }
2589  else
2590  {
2591  return null;
2592  }
2593  }
2594 
2595  public function get_text()
2596  {
2597  if ($this->text !== null)
2598  {
2599  return $this->text;
2600  }
2601  else
2602  {
2603  return null;
2604  }
2605  }
2606 
2607  public function get_type()
2608  {
2609  if ($this->type !== null)
2610  {
2611  return $this->type;
2612  }
2613  else
2614  {
2615  return null;
2616  }
2617  }
2618 }
2620 {
2621 
2622  var $term;
2623 
2624  var $scheme;
2625 
2626  var $label;
2627 
2628  public function __construct($term = null, $scheme = null, $label = null)
2629  {
2630  $this->term = $term;
2631  $this->scheme = $scheme;
2632  $this->label = $label;
2633  }
2634 
2635  public function __toString()
2636  {
2637  // There is no $this->data here
2638  return md5(serialize($this));
2639  }
2640 
2641  public function get_term()
2642  {
2643  if ($this->term !== null)
2644  {
2645  return $this->term;
2646  }
2647  else
2648  {
2649  return null;
2650  }
2651  }
2652 
2653  public function get_scheme()
2654  {
2655  if ($this->scheme !== null)
2656  {
2657  return $this->scheme;
2658  }
2659  else
2660  {
2661  return null;
2662  }
2663  }
2664 
2665  public function get_label()
2666  {
2667  if ($this->label !== null)
2668  {
2669  return $this->label;
2670  }
2671  else
2672  {
2673  return $this->get_term();
2674  }
2675  }
2676 }
2678 {
2679 
2680  var $file;
2681 
2682  public function __construct($file)
2683  {
2684  $this->file = $file;
2685  }
2686 
2687  public function get_type()
2688  {
2689  if (isset($this->file->headers['content-type']))
2690  {
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'))
2696  {
2697  return $this->text_or_binary();
2698  }
2699  if (($pos = strpos($this->file->headers['content-type'], ';')) !== false)
2700  {
2701  $official = substr($this->file->headers['content-type'], 0, $pos);
2702  }
2703  else
2704  {
2705  $official = $this->file->headers['content-type'];
2706  }
2707  $official = trim(strtolower($official));
2708  if ($official === 'unknown/unknown'
2709  || $official === 'application/unknown')
2710  {
2711  return $this->unknown();
2712  }
2713  elseif (substr($official, -4) === '+xml'
2714  || $official === 'text/xml'
2715  || $official === 'application/xml')
2716  {
2717  return $official;
2718  }
2719  elseif (substr($official, 0, 6) === 'image/')
2720  {
2721  if ($return = $this->image())
2722  {
2723  return $return;
2724  }
2725  else
2726  {
2727  return $official;
2728  }
2729  }
2730  elseif ($official === 'text/html')
2731  {
2732  return $this->feed_or_html();
2733  }
2734  else
2735  {
2736  return $official;
2737  }
2738  }
2739  else
2740  {
2741  return $this->unknown();
2742  }
2743  }
2744 
2745  public function text_or_binary()
2746  {
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")
2751  {
2752  return 'text/plain';
2753  }
2754  elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body))
2755  {
2756  return 'application/octect-stream';
2757  }
2758  else
2759  {
2760  return 'text/plain';
2761  }
2762  }
2763 
2764  public function unknown()
2765  {
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')
2770  {
2771  return 'text/html';
2772  }
2773  elseif (substr($this->file->body, 0, 5) === '%PDF-')
2774  {
2775  return 'application/pdf';
2776  }
2777  elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-')
2778  {
2779  return 'application/postscript';
2780  }
2781  elseif (substr($this->file->body, 0, 6) === 'GIF87a'
2782  || substr($this->file->body, 0, 6) === 'GIF89a')
2783  {
2784  return 'image/gif';
2785  }
2786  elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
2787  {
2788  return 'image/png';
2789  }
2790  elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
2791  {
2792  return 'image/jpeg';
2793  }
2794  elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
2795  {
2796  return 'image/bmp';
2797  }
2798  elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
2799  {
2800  return 'image/vnd.microsoft.icon';
2801  }
2802  else
2803  {
2804  return $this->text_or_binary();
2805  }
2806  }
2807 
2808  public function image()
2809  {
2810  if (substr($this->file->body, 0, 6) === 'GIF87a'
2811  || substr($this->file->body, 0, 6) === 'GIF89a')
2812  {
2813  return 'image/gif';
2814  }
2815  elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
2816  {
2817  return 'image/png';
2818  }
2819  elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
2820  {
2821  return 'image/jpeg';
2822  }
2823  elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
2824  {
2825  return 'image/bmp';
2826  }
2827  elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
2828  {
2829  return 'image/vnd.microsoft.icon';
2830  }
2831  else
2832  {
2833  return false;
2834  }
2835  }
2836 
2837  public function feed_or_html()
2838  {
2839  $len = strlen($this->file->body);
2840  $pos = strspn($this->file->body, "\x09\x0A\x0D\x20");
2841  while ($pos < $len)
2842  {
2843  switch ($this->file->body[$pos])
2844  {
2845  case "\x09":
2846  case "\x0A":
2847  case "\x0D":
2848  case "\x20":
2849  $pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos);
2850  continue 2;
2851  case '<':
2852  $pos++;
2853  break;
2854  default:
2855  return 'text/html';
2856  }
2857  if (substr($this->file->body, $pos, 3) === '!--')
2858  {
2859  $pos += 3;
2860  if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false)
2861  {
2862  $pos += 3;
2863  }
2864  else
2865  {
2866  return 'text/html';
2867  }
2868  }
2869  elseif (substr($this->file->body, $pos, 1) === '!')
2870  {
2871  if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false)
2872  {
2873  $pos++;
2874  }
2875  else
2876  {
2877  return 'text/html';
2878  }
2879  }
2880  elseif (substr($this->file->body, $pos, 1) === '?')
2881  {
2882  if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false)
2883  {
2884  $pos += 2;
2885  }
2886  else
2887  {
2888  return 'text/html';
2889  }
2890  }
2891  elseif (substr($this->file->body, $pos, 3) === 'rss'
2892  || substr($this->file->body, $pos, 7) === 'rdf:RDF')
2893  {
2894  return 'application/rss+xml';
2895  }
2896  elseif (substr($this->file->body, $pos, 4) === 'feed')
2897  {
2898  return 'application/atom+xml';
2899  }
2900  else
2901  {
2902  return 'text/html';
2903  }
2904  }
2905  return 'text/html';
2906  }
2907 }
2909 {
2910 
2911  var $url;
2912 
2913  var $label;
2914 
2915  public function __construct($url = null, $label = null)
2916  {
2917  $this->url = $url;
2918  $this->label = $label;
2919  }
2920 
2921  public function __toString()
2922  {
2923  // There is no $this->data here
2924  return md5(serialize($this));
2925  }
2926 
2927  public function get_url()
2928  {
2929  if ($this->url !== null)
2930  {
2931  return $this->url;
2932  }
2933  else
2934  {
2935  return null;
2936  }
2937  }
2938 
2939  public function get_attribution()
2940  {
2941  if ($this->label !== null)
2942  {
2943  return $this->label;
2944  }
2945  else
2946  {
2947  return null;
2948  }
2949  }
2950 }
2952 {
2953 }
2955 {
2956 
2957  var $role;
2958 
2959  var $scheme;
2960 
2961  var $name;
2962 
2963  public function __construct($role = null, $scheme = null, $name = null)
2964  {
2965  $this->role = $role;
2966  $this->scheme = $scheme;
2967  $this->name = $name;
2968  }
2969 
2970  public function __toString()
2971  {
2972  // There is no $this->data here
2973  return md5(serialize($this));
2974  }
2975 
2976  public function get_role()
2977  {
2978  if ($this->role !== null)
2979  {
2980  return $this->role;
2981  }
2982  else
2983  {
2984  return null;
2985  }
2986  }
2987 
2988  public function get_scheme()
2989  {
2990  if ($this->scheme !== null)
2991  {
2992  return $this->scheme;
2993  }
2994  else
2995  {
2996  return null;
2997  }
2998  }
2999 
3000  public function get_name()
3001  {
3002  if ($this->name !== null)
3003  {
3004  return $this->name;
3005  }
3006  else
3007  {
3008  return null;
3009  }
3010  }
3011 }
3013 {
3014 
3015  var $data = '';
3016 
3017  var $consumed = '';
3018 
3019  var $position = 0;
3020 
3021  public function __construct($data)
3022  {
3023  $this->data = $data;
3024  }
3025 
3026  public function parse()
3027  {
3028  while (($this->position = strpos($this->data, '&', $this->position)) !== false)
3029  {
3030  $this->consume();
3031  $this->entity();
3032  $this->consumed = '';
3033  }
3034  return $this->data;
3035  }
3036 
3037  public function consume()
3038  {
3039  if (isset($this->data[$this->position]))
3040  {
3041  $this->consumed .= $this->data[$this->position];
3042  return $this->data[$this->position++];
3043  }
3044  else
3045  {
3046  return false;
3047  }
3048  }
3049 
3050  public function consume_range($chars)
3051  {
3052  if ($len = strspn($this->data, $chars, $this->position))
3053  {
3054  $data = substr($this->data, $this->position, $len);
3055  $this->consumed .= $data;
3056  $this->position += $len;
3057  return $data;
3058  }
3059  else
3060  {
3061  return false;
3062  }
3063  }
3064 
3065  public function unconsume()
3066  {
3067  $this->consumed = substr($this->consumed, 0, -1);
3068  $this->position--;
3069  }
3070 
3071  public function entity()
3072  {
3073  switch ($this->consume())
3074  {
3075  case "\x09":
3076  case "\x0A":
3077  case "\x0B":
3078  case "\x0B":
3079  case "\x0C":
3080  case "\x20":
3081  case "\x3C":
3082  case "\x26":
3083  case false:
3084  break;
3085  case "\x23":
3086  switch ($this->consume())
3087  {
3088  case "\x78":
3089  case "\x58":
3090  $range = '0123456789ABCDEFabcdef';
3091  $hex = true;
3092  break;
3093  default:
3094  $range = '0123456789';
3095  $hex = false;
3096  $this->unconsume();
3097  break;
3098  }
3099  if ($codepoint = $this->consume_range($range))
3100  {
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");
3102  if ($hex)
3103  {
3104  $codepoint = hexdec($codepoint);
3105  }
3106  else
3107  {
3108  $codepoint = intval($codepoint);
3109  }
3110  if (isset($windows_1252_specials[$codepoint]))
3111  {
3112  $replacement = $windows_1252_specials[$codepoint];
3113  }
3114  else
3115  {
3116  $replacement = SimplePie_Misc::codepoint_to_utf8($codepoint);
3117  }
3118  if (!in_array($this->consume(), array(';', false), true))
3119  {
3120  $this->unconsume();
3121  }
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;
3125  }
3126  break;
3127  default:
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",
3150  'AMP' => "\x26",
3151  'amp' => "\x26",
3152  'AMP;' => "\x26",
3153  'amp;' => "\x26",
3154  'and;' => "\xE2\x88\xA7",
3155  'ang;' => "\xE2\x88\xA0",
3156  'apos;' => "\x27",
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",
3251  'GT' => "\x3E",
3252  'gt' => "\x3E",
3253  'GT;' => "\x3E",
3254  'gt;' => "\x3E",
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",
3303  'LT' => "\x3C",
3304  'lt' => "\x3C",
3305  'LT;' => "\x3C",
3306  'lt;' => "\x3C",
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",
3391  'QUOT' => "\x22",
3392  'quot' => "\x22",
3393  'QUOT;' => "\x22",
3394  'quot;' => "\x22",
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"
3495  );
3496  for ($i = 0, $match = null; $i < 9 && $this->consume() !== false; $i++)
3497  {
3498  $consumed = substr($this->consumed, 1);
3499  if (isset($entities[$consumed]))
3500  {
3501  $match = $consumed;
3502  }
3503  }
3504  if ($match !== null)
3505  {
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;
3508  }
3509  break;
3510  }
3511  }
3512 }
3514 {
3515 
3517 
3519 
3521 
3523 
3525 
3527 
3529 
3531 
3533 
3535 
3537 
3538  var $hashes;
3539 
3540  var $height;
3541 
3543 
3545 
3546  var $lang;
3547 
3548  var $length;
3549 
3550  var $link;
3551 
3552  var $medium;
3553 
3554  var $player;
3555 
3557 
3559 
3561 
3563 
3564  var $title;
3565 
3566  var $type;
3567 
3568  var $width;
3569 
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)
3571  {
3572  $this->bitrate = $bitrate;
3573  $this->captions = $captions;
3574  $this->categories = $categories;
3575  $this->channels = $channels;
3576  $this->copyright = $copyright;
3577  $this->credits = $credits;
3578  $this->description = $description;
3579  $this->duration = $duration;
3580  $this->expression = $expression;
3581  $this->framerate = $framerate;
3582  $this->hashes = $hashes;
3583  $this->height = $height;
3584  $this->keywords = $keywords;
3585  $this->lang = $lang;
3586  $this->length = $length;
3587  $this->link = $link;
3588  $this->medium = $medium;
3589  $this->player = $player;
3590  $this->ratings = $ratings;
3591  $this->restrictions = $restrictions;
3592  $this->samplingrate = $samplingrate;
3593  $this->thumbnails = $thumbnails;
3594  $this->title = $title;
3595  $this->type = $type;
3596  $this->width = $width;
3597  if (class_exists('idna_convert'))
3598  {
3599  $idn = new idna_convert();
3600  $parsed = SimplePie_Misc::parse_url($link);
3601  $this->link = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
3602  }
3603  $this->handler = $this->get_handler(); // Needs to load last
3604  }
3605 
3606  public function __toString()
3607  {
3608  // There is no $this->data here
3609  return md5(serialize($this));
3610  }
3611 
3612  public function get_bitrate()
3613  {
3614  if ($this->bitrate !== null)
3615  {
3616  return $this->bitrate;
3617  }
3618  else
3619  {
3620  return null;
3621  }
3622  }
3623 
3624  public function get_caption($key = 0)
3625  {
3626  $captions = $this->get_captions();
3627  if (isset($captions[$key]))
3628  {
3629  return $captions[$key];
3630  }
3631  else
3632  {
3633  return null;
3634  }
3635  }
3636 
3637  public function get_captions()
3638  {
3639  if ($this->captions !== null)
3640  {
3641  return $this->captions;
3642  }
3643  else
3644  {
3645  return null;
3646  }
3647  }
3648 
3649  public function get_category($key = 0)
3650  {
3651  $categories = $this->get_categories();
3652  if (isset($categories[$key]))
3653  {
3654  return $categories[$key];
3655  }
3656  else
3657  {
3658  return null;
3659  }
3660  }
3661 
3662  public function get_categories()
3663  {
3664  if ($this->categories !== null)
3665  {
3666  return $this->categories;
3667  }
3668  else
3669  {
3670  return null;
3671  }
3672  }
3673 
3674  public function get_channels()
3675  {
3676  if ($this->channels !== null)
3677  {
3678  return $this->channels;
3679  }
3680  else
3681  {
3682  return null;
3683  }
3684  }
3685 
3686  public function get_copyright()
3687  {
3688  if ($this->copyright !== null)
3689  {
3690  return $this->copyright;
3691  }
3692  else
3693  {
3694  return null;
3695  }
3696  }
3697 
3698  public function get_credit($key = 0)
3699  {
3700  $credits = $this->get_credits();
3701  if (isset($credits[$key]))
3702  {
3703  return $credits[$key];
3704  }
3705  else
3706  {
3707  return null;
3708  }
3709  }
3710 
3711  public function get_credits()
3712  {
3713  if ($this->credits !== null)
3714  {
3715  return $this->credits;
3716  }
3717  else
3718  {
3719  return null;
3720  }
3721  }
3722 
3723  public function get_description()
3724  {
3725  if ($this->description !== null)
3726  {
3727  return $this->description;
3728  }
3729  else
3730  {
3731  return null;
3732  }
3733  }
3734 
3735  public function get_duration($convert = false)
3736  {
3737  if ($this->duration !== null)
3738  {
3739  if ($convert)
3740  {
3741  $time = SimplePie_Misc::time_hms($this->duration);
3742  return $time;
3743  }
3744  else
3745  {
3746  return $this->duration;
3747  }
3748  }
3749  else
3750  {
3751  return null;
3752  }
3753  }
3754 
3755  public function get_expression()
3756  {
3757  if ($this->expression !== null)
3758  {
3759  return $this->expression;
3760  }
3761  else
3762  {
3763  return 'full';
3764  }
3765  }
3766 
3767  public function get_extension()
3768  {
3769  if ($this->link !== null)
3770  {
3771  $url = SimplePie_Misc::parse_url($this->link);
3772  if ($url['path'] !== '')
3773  {
3774  return pathinfo($url['path'], PATHINFO_EXTENSION);
3775  }
3776  }
3777  return null;
3778  }
3779 
3780  public function get_framerate()
3781  {
3782  if ($this->framerate !== null)
3783  {
3784  return $this->framerate;
3785  }
3786  else
3787  {
3788  return null;
3789  }
3790  }
3791 
3792  public function get_handler()
3793  {
3794  return $this->get_real_type(true);
3795  }
3796 
3797  public function get_hash($key = 0)
3798  {
3799  $hashes = $this->get_hashes();
3800  if (isset($hashes[$key]))
3801  {
3802  return $hashes[$key];
3803  }
3804  else
3805  {
3806  return null;
3807  }
3808  }
3809 
3810  public function get_hashes()
3811  {
3812  if ($this->hashes !== null)
3813  {
3814  return $this->hashes;
3815  }
3816  else
3817  {
3818  return null;
3819  }
3820  }
3821 
3822  public function get_height()
3823  {
3824  if ($this->height !== null)
3825  {
3826  return $this->height;
3827  }
3828  else
3829  {
3830  return null;
3831  }
3832  }
3833 
3834  public function get_language()
3835  {
3836  if ($this->lang !== null)
3837  {
3838  return $this->lang;
3839  }
3840  else
3841  {
3842  return null;
3843  }
3844  }
3845 
3846  public function get_keyword($key = 0)
3847  {
3848  $keywords = $this->get_keywords();
3849  if (isset($keywords[$key]))
3850  {
3851  return $keywords[$key];
3852  }
3853  else
3854  {
3855  return null;
3856  }
3857  }
3858 
3859  public function get_keywords()
3860  {
3861  if ($this->keywords !== null)
3862  {
3863  return $this->keywords;
3864  }
3865  else
3866  {
3867  return null;
3868  }
3869  }
3870 
3871  public function get_length()
3872  {
3873  if ($this->length !== null)
3874  {
3875  return $this->length;
3876  }
3877  else
3878  {
3879  return null;
3880  }
3881  }
3882 
3883  public function get_link()
3884  {
3885  if ($this->link !== null)
3886  {
3887  return urldecode($this->link);
3888  }
3889  else
3890  {
3891  return null;
3892  }
3893  }
3894 
3895  public function get_medium()
3896  {
3897  if ($this->medium !== null)
3898  {
3899  return $this->medium;
3900  }
3901  else
3902  {
3903  return null;
3904  }
3905  }
3906 
3907  public function get_player()
3908  {
3909  if ($this->player !== null)
3910  {
3911  return $this->player;
3912  }
3913  else
3914  {
3915  return null;
3916  }
3917  }
3918 
3919  public function get_rating($key = 0)
3920  {
3921  $ratings = $this->get_ratings();
3922  if (isset($ratings[$key]))
3923  {
3924  return $ratings[$key];
3925  }
3926  else
3927  {
3928  return null;
3929  }
3930  }
3931 
3932  public function get_ratings()
3933  {
3934  if ($this->ratings !== null)
3935  {
3936  return $this->ratings;
3937  }
3938  else
3939  {
3940  return null;
3941  }
3942  }
3943 
3944  public function get_restriction($key = 0)
3945  {
3946  $restrictions = $this->get_restrictions();
3947  if (isset($restrictions[$key]))
3948  {
3949  return $restrictions[$key];
3950  }
3951  else
3952  {
3953  return null;
3954  }
3955  }
3956 
3957  public function get_restrictions()
3958  {
3959  if ($this->restrictions !== null)
3960  {
3961  return $this->restrictions;
3962  }
3963  else
3964  {
3965  return null;
3966  }
3967  }
3968 
3969  public function get_sampling_rate()
3970  {
3971  if ($this->samplingrate !== null)
3972  {
3973  return $this->samplingrate;
3974  }
3975  else
3976  {
3977  return null;
3978  }
3979  }
3980 
3981  public function get_size()
3982  {
3983  $length = $this->get_length();
3984  if ($length !== null)
3985  {
3986  return round($length/1048576, 2);
3987  }
3988  else
3989  {
3990  return null;
3991  }
3992  }
3993 
3994  public function get_thumbnail($key = 0)
3995  {
3996  $thumbnails = $this->get_thumbnails();
3997  if (isset($thumbnails[$key]))
3998  {
3999  return $thumbnails[$key];
4000  }
4001  else
4002  {
4003  return null;
4004  }
4005  }
4006 
4007  public function get_thumbnails()
4008  {
4009  if ($this->thumbnails !== null)
4010  {
4011  return $this->thumbnails;
4012  }
4013  else
4014  {
4015  return null;
4016  }
4017  }
4018 
4019  public function get_title()
4020  {
4021  if ($this->title !== null)
4022  {
4023  return $this->title;
4024  }
4025  else
4026  {
4027  return null;
4028  }
4029  }
4030 
4031  public function get_type()
4032  {
4033  if ($this->type !== null)
4034  {
4035  return $this->type;
4036  }
4037  else
4038  {
4039  return null;
4040  }
4041  }
4042 
4043  public function get_width()
4044  {
4045  if ($this->width !== null)
4046  {
4047  return $this->width;
4048  }
4049  else
4050  {
4051  return null;
4052  }
4053  }
4054 
4055  public function native_embed($options='')
4056  {
4057  return $this->embed($options, true);
4058  }
4059 
4060  public function embed($options = '', $native = false)
4061  {
4062  // Set up defaults
4063  $audio = '';
4064  $video = '';
4065  $alt = '';
4066  $altclass = '';
4067  $loop = 'false';
4068  $width = 'auto';
4069  $height = 'auto';
4070  $bgcolor = '#ffffff';
4071  $mediaplayer = '';
4072  $widescreen = false;
4073  $handler = $this->get_handler();
4074  $type = $this->get_real_type();
4075  // Process options and reassign values as necessary
4076  if (is_array($options))
4077  {
4078  extract($options);
4079  }
4080  else
4081  {
4082  $options = explode(',', $options);
4083  foreach($options as $option)
4084  {
4085  $opt = explode(':', $option, 2);
4086  if (isset($opt[0], $opt[1]))
4087  {
4088  $opt[0] = trim($opt[0]);
4089  $opt[1] = trim($opt[1]);
4090  switch ($opt[0])
4091  {
4092  case 'audio':
4093  $audio = $opt[1];
4094  break;
4095  case 'video':
4096  $video = $opt[1];
4097  break;
4098  case 'alt':
4099  $alt = $opt[1];
4100  break;
4101  case 'altclass':
4102  $altclass = $opt[1];
4103  break;
4104  case 'loop':
4105  $loop = $opt[1];
4106  break;
4107  case 'width':
4108  $width = $opt[1];
4109  break;
4110  case 'height':
4111  $height = $opt[1];
4112  break;
4113  case 'bgcolor':
4114  $bgcolor = $opt[1];
4115  break;
4116  case 'mediaplayer':
4117  $mediaplayer = $opt[1];
4118  break;
4119  case 'widescreen':
4120  $widescreen = $opt[1];
4121  break;
4122  }
4123  }
4124  }
4125  }
4126  $mime = explode('/', $type, 2);
4127  $mime = $mime[0];
4128  // Process values for 'auto'
4129  if ($width === 'auto')
4130  {
4131  if ($mime === 'video')
4132  {
4133  if ($height === 'auto')
4134  {
4135  $width = 480;
4136  }
4137  elseif ($widescreen)
4138  {
4139  $width = round((intval($height)/9)*16);
4140  }
4141  else
4142  {
4143  $width = round((intval($height)/3)*4);
4144  }
4145  }
4146  else
4147  {
4148  $width = '100%';
4149  }
4150  }
4151  if ($height === 'auto')
4152  {
4153  if ($mime === 'audio')
4154  {
4155  $height = 0;
4156  }
4157  elseif ($mime === 'video')
4158  {
4159  if ($width === 'auto')
4160  {
4161  if ($widescreen)
4162  {
4163  $height = 270;
4164  }
4165  else
4166  {
4167  $height = 360;
4168  }
4169  }
4170  elseif ($widescreen)
4171  {
4172  $height = round((intval($width)/16)*9);
4173  }
4174  else
4175  {
4176  $height = round((intval($width)/4)*3);
4177  }
4178  }
4179  else
4180  {
4181  $height = 376;
4182  }
4183  }
4184  elseif ($mime === 'audio')
4185  {
4186  $height = 0;
4187  }
4188  // Set proper placeholder value
4189  if ($mime === 'audio')
4190  {
4191  $placeholder = $audio;
4192  }
4193  elseif ($mime === 'video')
4194  {
4195  $placeholder = $video;
4196  }
4197  $embed = '';
4198  // Flash
4199  if ($handler === 'flash')
4200  {
4201  if ($native)
4202  {
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>";
4204  }
4205  else
4206  {
4207  $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>";
4208  }
4209  }
4210  // Flash Media Player file types.
4211  // Preferred handler for MP3 file types.
4212  elseif ($handler === 'fmedia' || ($handler === 'mp3' && $mediaplayer !== ''))
4213  {
4214  $height += 20;
4215  if ($native)
4216  {
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>";
4218  }
4219  else
4220  {
4221  $embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>";
4222  }
4223  }
4224  // QuickTime 7 file types. Need to test with QuickTime 6.
4225  // Only handle MP3's if the Flash Media Player is not present.
4226  elseif ($handler === 'quicktime' || ($handler === 'mp3' && $mediaplayer === ''))
4227  {
4228  $height += 16;
4229  if ($native)
4230  {
4231  if ($placeholder !== '')
4232  {
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>";
4234  }
4235  else
4236  {
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>";
4238  }
4239  }
4240  else
4241  {
4242  $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>";
4243  }
4244  }
4245  // Windows Media
4246  elseif ($handler === 'wmedia')
4247  {
4248  $height += 45;
4249  if ($native)
4250  {
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>";
4252  }
4253  else
4254  {
4255  $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>";
4256  }
4257  }
4258  // Everything else
4259  else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>';
4260  return $embed;
4261  }
4262 
4263  public function get_real_type($find_handler = false)
4264  {
4265  // Mime-types by handler.
4266  $types_flash = array('application/x-shockwave-flash', 'application/futuresplash'); // Flash
4267  $types_fmedia = array('video/flv', 'video/x-flv','flv-application/octet-stream'); // Flash Media Player
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'); // QuickTime
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'); // Windows Media
4270  $types_mp3 = array('audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg'); // MP3
4271  if ($this->get_type() !== null)
4272  {
4273  $type = strtolower($this->type);
4274  }
4275  else
4276  {
4277  $type = null;
4278  }
4279  // If we encounter an unsupported mime-type, check the file extension and guess intelligently.
4280  if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3)))
4281  {
4282  switch (strtolower($this->get_extension()))
4283  {
4284  // Audio mime-types
4285  case 'aac':
4286  case 'adts':
4287  $type = 'audio/acc';
4288  break;
4289  case 'aif':
4290  case 'aifc':
4291  case 'aiff':
4292  case 'cdda':
4293  $type = 'audio/aiff';
4294  break;
4295  case 'bwf':
4296  $type = 'audio/wav';
4297  break;
4298  case 'kar':
4299  case 'mid':
4300  case 'midi':
4301  case 'smf':
4302  $type = 'audio/midi';
4303  break;
4304  case 'm4a':
4305  $type = 'audio/x-m4a';
4306  break;
4307  case 'mp3':
4308  case 'swa':
4309  $type = 'audio/mp3';
4310  break;
4311  case 'wav':
4312  $type = 'audio/wav';
4313  break;
4314  case 'wax':
4315  $type = 'audio/x-ms-wax';
4316  break;
4317  case 'wma':
4318  $type = 'audio/x-ms-wma';
4319  break;
4320  // Video mime-types
4321  case '3gp':
4322  case '3gpp':
4323  $type = 'video/3gpp';
4324  break;
4325  case '3g2':
4326  case '3gp2':
4327  $type = 'video/3gpp2';
4328  break;
4329  case 'asf':
4330  $type = 'video/x-ms-asf';
4331  break;
4332  case 'flv':
4333  $type = 'video/x-flv';
4334  break;
4335  case 'm1a':
4336  case 'm1s':
4337  case 'm1v':
4338  case 'm15':
4339  case 'm75':
4340  case 'mp2':
4341  case 'mpa':
4342  case 'mpeg':
4343  case 'mpg':
4344  case 'mpm':
4345  case 'mpv':
4346  $type = 'video/mpeg';
4347  break;
4348  case 'm4v':
4349  $type = 'video/x-m4v';
4350  break;
4351  case 'mov':
4352  case 'qt':
4353  $type = 'video/quicktime';
4354  break;
4355  case 'mp4':
4356  case 'mpg4':
4357  $type = 'video/mp4';
4358  break;
4359  case 'sdv':
4360  $type = 'video/sd-video';
4361  break;
4362  case 'wm':
4363  $type = 'video/x-ms-wm';
4364  break;
4365  case 'wmv':
4366  $type = 'video/x-ms-wmv';
4367  break;
4368  case 'wvx':
4369  $type = 'video/x-ms-wvx';
4370  break;
4371  // Flash mime-types
4372  case 'spl':
4373  $type = 'application/futuresplash';
4374  break;
4375  case 'swf':
4376  $type = 'application/x-shockwave-flash';
4377  break;
4378  }
4379  }
4380  if ($find_handler)
4381  {
4382  if (in_array($type, $types_flash))
4383  {
4384  return 'flash';
4385  }
4386  elseif (in_array($type, $types_fmedia))
4387  {
4388  return 'fmedia';
4389  }
4390  elseif (in_array($type, $types_quicktime))
4391  {
4392  return 'quicktime';
4393  }
4394  elseif (in_array($type, $types_wmedia))
4395  {
4396  return 'wmedia';
4397  }
4398  elseif (in_array($type, $types_mp3))
4399  {
4400  return 'mp3';
4401  }
4402  else
4403  {
4404  return null;
4405  }
4406  }
4407  else
4408  {
4409  return $type;
4410  }
4411  }
4412 }
4413 class SimplePie_Exception extends Exception
4414 {
4415 }
4417 {
4418  var $url;
4420  var $success = true;
4421  var $headers = array();
4422  var $body;
4424  var $redirects = 0;
4425  var $error;
4427  public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
4428  {
4429  if (class_exists('idna_convert'))
4430  {
4431  $idn = new idna_convert();
4432  $parsed = SimplePie_Misc::parse_url($url);
4433  $url = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
4434  }
4435  $this->url = $url;
4436  $this->useragent = $useragent;
4437  if (preg_match('/^http(s)?:\/\//i', $url))
4438  {
4439  if ($useragent === null)
4440  {
4441  $useragent = ini_get('user_agent');
4442  $this->useragent = $useragent;
4443  }
4444  if (!is_array($headers))
4445  {
4446  $headers = array();
4447  }
4448  if (!$force_fsockopen && function_exists('curl_exec'))
4449  {
4451  $fp = curl_init();
4452  $headers2 = array();
4453  foreach ($headers as $key => $value)
4454  {
4455  $headers2[] = "$key: $value";
4456  }
4457  if (version_compare(SimplePie_Misc::get_curl_version(), '7.10.5', '>='))
4458  {
4459  curl_setopt($fp, CURLOPT_ENCODING, '');
4460  }
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);
4469  if (!ini_get('open_basedir') && !ini_get('safe_mode') && version_compare(SimplePie_Misc::get_curl_version(), '7.15.2', '>='))
4470  {
4471  curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
4472  curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
4473  }
4474  $this->headers = curl_exec($fp);
4475  if (curl_errno($fp) === 23 || curl_errno($fp) === 61)
4476  {
4477  curl_setopt($fp, CURLOPT_ENCODING, 'none');
4478  $this->headers = curl_exec($fp);
4479  }
4480  if (curl_errno($fp))
4481  {
4482  $this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
4483  $this->success = false;
4484  }
4485  else
4486  {
4487  $info = curl_getinfo($fp);
4488  curl_close($fp);
4489  $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 1);
4490  $this->headers = array_pop($this->headers);
4491  $parser = new SimplePie_HTTP_Parser($this->headers);
4492  if ($parser->parse())
4493  {
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)
4498  {
4499  $this->redirects++;
4500  $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
4501  return $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
4502  }
4503  }
4504  }
4505  }
4506  else
4507  {
4509  $url_parts = parse_url($url);
4510  $socket_host = $url_parts['host'];
4511  if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https')
4512  {
4513  $socket_host = "ssl://$url_parts[host]";
4514  $url_parts['port'] = 443;
4515  }
4516  if (!isset($url_parts['port']))
4517  {
4518  $url_parts['port'] = 80;
4519  }
4520  $fp = @fsockopen($socket_host, $url_parts['port'], $errno, $errstr, $timeout);
4521  if (!$fp)
4522  {
4523  $this->error = 'fsockopen error: ' . $errstr;
4524  $this->success = false;
4525  }
4526  else
4527  {
4528  stream_set_timeout($fp, $timeout);
4529  if (isset($url_parts['path']))
4530  {
4531  if (isset($url_parts['query']))
4532  {
4533  $get = "$url_parts[path]?$url_parts[query]";
4534  }
4535  else
4536  {
4537  $get = $url_parts['path'];
4538  }
4539  }
4540  else
4541  {
4542  $get = '/';
4543  }
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'))
4548  {
4549  $out .= "Accept-Encoding: x-gzip,gzip,deflate\r\n";
4550  }
4551  if (isset($url_parts['user']) && isset($url_parts['pass']))
4552  {
4553  $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
4554  }
4555  foreach ($headers as $key => $value)
4556  {
4557  $out .= "$key: $value\r\n";
4558  }
4559  $out .= "Connection: Close\r\n\r\n";
4560  fwrite($fp, $out);
4561  $info = stream_get_meta_data($fp);
4562  $this->headers = '';
4563  while (!$info['eof'] && !$info['timed_out'])
4564  {
4565  $this->headers .= fread($fp, 1160);
4566  $info = stream_get_meta_data($fp);
4567  }
4568  if (!$info['timed_out'])
4569  {
4570  $parser = new SimplePie_HTTP_Parser($this->headers);
4571  if ($parser->parse())
4572  {
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)
4577  {
4578  $this->redirects++;
4579  $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
4580  return $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
4581  }
4582  if (isset($this->headers['content-encoding']))
4583  {
4584  // Hey, we act dumb elsewhere, so let's do that here too
4585  switch (strtolower(trim($this->headers['content-encoding'], "\x09\x0A\x0D\x20")))
4586  {
4587  case 'gzip':
4588  case 'x-gzip':
4589  $decoder = new SimplePie_gzdecode($this->body);
4590  if (!$decoder->parse())
4591  {
4592  $this->error = 'Unable to decode HTTP "gzip" stream';
4593  $this->success = false;
4594  }
4595  else
4596  {
4597  $this->body = $decoder->data;
4598  }
4599  break;
4600  case 'deflate':
4601  if (($decompressed = gzinflate($this->body)) !== false)
4602  {
4603  $this->body = $decompressed;
4604  }
4605  else if (($decompressed = gzuncompress($this->body)) !== false)
4606  {
4607  $this->body = $decompressed;
4608  }
4609  else if (function_exists('gzdecode') && ($decompressed = gzdecode($this->body)) !== false)
4610  {
4611  $this->body = $decompressed;
4612  }
4613  else
4614  {
4615  $this->error = 'Unable to decode HTTP "deflate" stream';
4616  $this->success = false;
4617  }
4618  break;
4619  default:
4620  $this->error = 'Unknown content coding';
4621  $this->success = false;
4622  }
4623  }
4624  }
4625  }
4626  else
4627  {
4628  $this->error = 'fsocket timed out';
4629  $this->success = false;
4630  }
4631  fclose($fp);
4632  }
4633  }
4634  }
4635  else
4636  {
4638  if (!$this->body = file_get_contents($url))
4639  {
4640  $this->error = 'file_get_contents could not read the file';
4641  $this->success = false;
4642  }
4643  }
4644  }
4645 }
4647 {
4648 
4650 
4652 
4654 
4655  var $position = 0;
4656 
4657  var $flags;
4658 
4659  var $data;
4660 
4661  var $MTIME;
4662 
4663  var $XFL;
4664 
4665  var $OS;
4666 
4667  var $SI1;
4668 
4669  var $SI2;
4670 
4672 
4674 
4676 
4677  public function __set($name, $value)
4678  {
4679  trigger_error("Cannot write property $name", E_USER_ERROR);
4680  }
4681 
4682  public function __construct($data)
4683  {
4684  $this->compressed_data = $data;
4685  $this->compressed_size = strlen($data);
4686  }
4687 
4688  public function parse()
4689  {
4690  if ($this->compressed_size >= $this->min_compressed_size)
4691  {
4692  // Check ID1, ID2, and CM
4693  if (substr($this->compressed_data, 0, 3) !== "\x1F\x8B\x08")
4694  {
4695  return false;
4696  }
4697  // Get the FLG (FLaGs)
4698  $this->flags = ord($this->compressed_data[3]);
4699  // FLG bits above (1 << 4) are reserved
4700  if ($this->flags > 0x1F)
4701  {
4702  return false;
4703  }
4704  // Advance the pointer after the above
4705  $this->position += 4;
4706  // MTIME
4707  $mtime = substr($this->compressed_data, $this->position, 4);
4708  // Reverse the string if we're on a big-endian arch because l is the only signed long and is machine endianness
4709  if (current(unpack('S', "\x00\x01")) === 1)
4710  {
4711  $mtime = strrev($mtime);
4712  }
4713  $this->MTIME = current(unpack('l', $mtime));
4714  $this->position += 4;
4715  // Get the XFL (eXtra FLags)
4716  $this->XFL = ord($this->compressed_data[$this->position++]);
4717  // Get the OS (Operating System)
4718  $this->OS = ord($this->compressed_data[$this->position++]);
4719  // Parse the FEXTRA
4720  if ($this->flags & 4)
4721  {
4722  // Read subfield IDs
4723  $this->SI1 = $this->compressed_data[$this->position++];
4724  $this->SI2 = $this->compressed_data[$this->position++];
4725  // SI2 set to zero is reserved for future use
4726  if ($this->SI2 === "\x00")
4727  {
4728  return false;
4729  }
4730  // Get the length of the extra field
4731  $len = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
4732  $this->position += 2;
4733  // Check the length of the string is still valid
4734  $this->min_compressed_size += $len + 4;
4735  if ($this->compressed_size >= $this->min_compressed_size)
4736  {
4737  // Set the extra field to the given data
4738  $this->extra_field = substr($this->compressed_data, $this->position, $len);
4739  $this->position += $len;
4740  }
4741  else
4742  {
4743  return false;
4744  }
4745  }
4746  // Parse the FNAME
4747  if ($this->flags & 8)
4748  {
4749  // Get the length of the filename
4750  $len = strcspn($this->compressed_data, "\x00", $this->position);
4751  // Check the length of the string is still valid
4752  $this->min_compressed_size += $len + 1;
4753  if ($this->compressed_size >= $this->min_compressed_size)
4754  {
4755  // Set the original filename to the given string
4756  $this->filename = substr($this->compressed_data, $this->position, $len);
4757  $this->position += $len + 1;
4758  }
4759  else
4760  {
4761  return false;
4762  }
4763  }
4764  // Parse the FCOMMENT
4765  if ($this->flags & 16)
4766  {
4767  // Get the length of the comment
4768  $len = strcspn($this->compressed_data, "\x00", $this->position);
4769  // Check the length of the string is still valid
4770  $this->min_compressed_size += $len + 1;
4771  if ($this->compressed_size >= $this->min_compressed_size)
4772  {
4773  // Set the original comment to the given string
4774  $this->comment = substr($this->compressed_data, $this->position, $len);
4775  $this->position += $len + 1;
4776  }
4777  else
4778  {
4779  return false;
4780  }
4781  }
4782  // Parse the FHCRC
4783  if ($this->flags & 2)
4784  {
4785  // Check the length of the string is still valid
4786  $this->min_compressed_size += $len + 2;
4787  if ($this->compressed_size >= $this->min_compressed_size)
4788  {
4789  // Read the CRC
4790  $crc = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
4791  // Check the CRC matches
4792  if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc)
4793  {
4794  $this->position += 2;
4795  }
4796  else
4797  {
4798  return false;
4799  }
4800  }
4801  else
4802  {
4803  return false;
4804  }
4805  }
4806  // Decompress the actual data
4807  if (($this->data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false)
4808  {
4809  return false;
4810  }
4811  else
4812  {
4813  $this->position = $this->compressed_size - 8;
4814  }
4815  // Check CRC of data
4816  $crc = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
4817  $this->position += 4;
4818  /*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc))
4819  {
4820  return false;
4821  }*/
4822  // Check ISIZE of data
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))
4826  {
4827  return false;
4828  }
4829  // Wow, against all odds, we've actually got a valid gzip string
4830  return true;
4831  }
4832  else
4833  {
4834  return false;
4835  }
4836  }
4837 }
4839 {
4840 
4841  public $http_version = 0.0;
4842 
4843  public $status_code = 0;
4844 
4845  public $reason = '';
4846 
4847  public $headers = array();
4848 
4849  public $body = '';
4850 
4851  protected $state = 'http_version';
4852 
4853  protected $data = '';
4854 
4855  protected $data_length = 0;
4856 
4857  protected $position = 0;
4858 
4859  protected $name = '';
4860 
4861  protected $value = '';
4862 
4863  public function __construct($data)
4864  {
4865  $this->data = $data;
4866  $this->data_length = strlen($this->data);
4867  }
4868 
4869  public function parse()
4870  {
4871  while ($this->state && $this->state !== 'emit' && $this->has_data())
4872  {
4873  $state = $this->state;
4874  $this->$state();
4875  }
4876  $this->data = '';
4877  if ($this->state === 'emit' || $this->state === 'body')
4878  {
4879  return true;
4880  }
4881  else
4882  {
4883  $this->http_version = '';
4884  $this->status_code = '';
4885  $this->reason = '';
4886  $this->headers = array();
4887  $this->body = '';
4888  return false;
4889  }
4890  }
4891 
4892  protected function has_data()
4893  {
4894  return (bool) ($this->position < $this->data_length);
4895  }
4896 
4897  protected function is_linear_whitespace()
4898  {
4899  return (bool) ($this->data[$this->position] === "\x09"
4900  || $this->data[$this->position] === "\x20"
4901  || ($this->data[$this->position] === "\x0A"
4902  && isset($this->data[$this->position + 1])
4903  && ($this->data[$this->position + 1] === "\x09" || $this->data[$this->position + 1] === "\x20")));
4904  }
4905 
4906  protected function http_version()
4907  {
4908  if (strpos($this->data, "\x0A") !== false && strtoupper(substr($this->data, 0, 5)) === 'HTTP/')
4909  {
4910  $len = strspn($this->data, '0123456789.', 5);
4911  $this->http_version = substr($this->data, 5, $len);
4912  $this->position += 5 + $len;
4913  if (substr_count($this->http_version, '.') <= 1)
4914  {
4915  $this->http_version = (float) $this->http_version;
4916  $this->position += strspn($this->data, "\x09\x20", $this->position);
4917  $this->state = 'status';
4918  }
4919  else
4920  {
4921  $this->state = false;
4922  }
4923  }
4924  else
4925  {
4926  $this->state = false;
4927  }
4928  }
4929 
4930  protected function status()
4931  {
4932  if ($len = strspn($this->data, '0123456789', $this->position))
4933  {
4934  $this->status_code = (int) substr($this->data, $this->position, $len);
4935  $this->position += $len;
4936  $this->state = 'reason';
4937  }
4938  else
4939  {
4940  $this->state = false;
4941  }
4942  }
4943 
4944  protected function reason()
4945  {
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';
4950  }
4951 
4952  protected function new_line()
4953  {
4954  $this->value = trim($this->value, "\x0D\x20");
4955  if ($this->name !== '' && $this->value !== '')
4956  {
4957  $this->name = strtolower($this->name);
4958  // We should only use the last Content-Type header. c.f. issue #1
4959  if (isset($this->headers[$this->name]) && $this->name !== 'content-type')
4960  {
4961  $this->headers[$this->name] .= ', ' . $this->value;
4962  }
4963  else
4964  {
4965  $this->headers[$this->name] = $this->value;
4966  }
4967  }
4968  $this->name = '';
4969  $this->value = '';
4970  if (substr($this->data[$this->position], 0, 2) === "\x0D\x0A")
4971  {
4972  $this->position += 2;
4973  $this->state = 'body';
4974  }
4975  elseif ($this->data[$this->position] === "\x0A")
4976  {
4977  $this->position++;
4978  $this->state = 'body';
4979  }
4980  else
4981  {
4982  $this->state = 'name';
4983  }
4984  }
4985 
4986  protected function name()
4987  {
4988  $len = strcspn($this->data, "\x0A:", $this->position);
4989  if (isset($this->data[$this->position + $len]))
4990  {
4991  if ($this->data[$this->position + $len] === "\x0A")
4992  {
4993  $this->position += $len;
4994  $this->state = 'new_line';
4995  }
4996  else
4997  {
4998  $this->name = substr($this->data, $this->position, $len);
4999  $this->position += $len + 1;
5000  $this->state = 'value';
5001  }
5002  }
5003  else
5004  {
5005  $this->state = false;
5006  }
5007  }
5008 
5009  protected function linear_whitespace()
5010  {
5011  do
5012  {
5013  if (substr($this->data, $this->position, 2) === "\x0D\x0A")
5014  {
5015  $this->position += 2;
5016  }
5017  elseif ($this->data[$this->position] === "\x0A")
5018  {
5019  $this->position++;
5020  }
5021  $this->position += strspn($this->data, "\x09\x20", $this->position);
5022  } while ($this->has_data() && $this->is_linear_whitespace());
5023  $this->value .= "\x20";
5024  }
5025 
5026  protected function value()
5027  {
5028  if ($this->is_linear_whitespace())
5029  {
5030  $this->linear_whitespace();
5031  }
5032  else
5033  {
5034  switch ($this->data[$this->position])
5035  {
5036  case '"':
5037  // Workaround for ETags: we have to include the quotes as
5038  // part of the tag.
5039  if (strtolower($this->name) === 'etag')
5040  {
5041  $this->value .= '"';
5042  $this->position++;
5043  $this->state = 'value_char';
5044  break;
5045  }
5046  $this->position++;
5047  $this->state = 'quote';
5048  break;
5049  case "\x0A":
5050  $this->position++;
5051  $this->state = 'new_line';
5052  break;
5053  default:
5054  $this->state = 'value_char';
5055  break;
5056  }
5057  }
5058  }
5059 
5060  protected function value_char()
5061  {
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';
5066  }
5067 
5068  protected function quote()
5069  {
5070  if ($this->is_linear_whitespace())
5071  {
5072  $this->linear_whitespace();
5073  }
5074  else
5075  {
5076  switch ($this->data[$this->position])
5077  {
5078  case '"':
5079  $this->position++;
5080  $this->state = 'value';
5081  break;
5082  case "\x0A":
5083  $this->position++;
5084  $this->state = 'new_line';
5085  break;
5086  case '\\':
5087  $this->position++;
5088  $this->state = 'quote_escaped';
5089  break;
5090  default:
5091  $this->state = 'quote_char';
5092  break;
5093  }
5094  }
5095  }
5096 
5097  protected function quote_char()
5098  {
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';
5103  }
5104 
5105  protected function quote_escaped()
5106  {
5107  $this->value .= $this->data[$this->position];
5108  $this->position++;
5109  $this->state = 'quote';
5110  }
5111 
5112  protected function body()
5113  {
5114  $this->body = substr($this->data, $this->position);
5115  if (!empty($this->headers['transfer-encoding']))
5116  {
5117  unset($this->headers['transfer-encoding']);
5118  $this->state = 'chunked';
5119  }
5120  else
5121  {
5122  $this->state = 'emit';
5123  }
5124  }
5125 
5126  protected function chunked()
5127  {
5128  if (!preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', trim($this->body)))
5129  {
5130  $this->state = 'emit';
5131  return;
5132  }
5133  $decoded = '';
5134  $encoded = $this->body;
5135  while (true)
5136  {
5137  $is_chunked = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $encoded, $matches );
5138  if (!$is_chunked)
5139  {
5140  // Looks like it's not chunked after all
5141  $this->state = 'emit';
5142  return;
5143  }
5144  $length = hexdec(trim($matches[1]));
5145  if ($length === 0)
5146  {
5147  // Ignore trailer headers
5148  $this->state = 'emit';
5149  $this->body = $decoded;
5150  return;
5151  }
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))
5156  {
5157  $this->state = 'emit';
5158  $this->body = $decoded;
5159  return;
5160  }
5161  }
5162  }
5163 }
5165 {
5166 
5167  protected $scheme = null;
5168 
5169  protected $iuserinfo = null;
5170 
5171  protected $ihost = null;
5172 
5173  protected $port = null;
5174 
5175  protected $ipath = '';
5176 
5177  protected $iquery = null;
5178 
5179  protected $ifragment = null;
5180 
5181  protected $normalization = array(
5182  'acap' => array(
5183  'port' => 674
5184  ),
5185  'dict' => array(
5186  'port' => 2628
5187  ),
5188  'file' => array(
5189  'ihost' => 'localhost'
5190  ),
5191  'http' => array(
5192  'port' => 80,
5193  'ipath' => '/'
5194  ),
5195  'https' => array(
5196  'port' => 443,
5197  'ipath' => '/'
5198  ),
5199  );
5200 
5201  public function __toString()
5202  {
5203  return $this->get_iri();
5204  }
5205 
5206  public function __set($name, $value)
5207  {
5208  if (method_exists($this, 'set_' . $name))
5209  {
5210  call_user_func(array($this, 'set_' . $name), $value);
5211  }
5212  elseif (
5213  $name === 'iauthority'
5214  || $name === 'iuserinfo'
5215  || $name === 'ihost'
5216  || $name === 'ipath'
5217  || $name === 'iquery'
5218  || $name === 'ifragment'
5219  )
5220  {
5221  call_user_func(array($this, 'set_' . substr($name, 1)), $value);
5222  }
5223  }
5224 
5225  public function __get($name)
5226  {
5227  // isset() returns false for null, we don't want to do that
5228  // Also why we use array_key_exists below instead of isset()
5229  $props = get_object_vars($this);
5230  if (
5231  $name === 'iri' ||
5232  $name === 'uri' ||
5233  $name === 'iauthority' ||
5234  $name === 'authority'
5235  )
5236  {
5237  $return = $this->{"get_$name"}();
5238  }
5239  elseif (array_key_exists($name, $props))
5240  {
5241  $return = $this->$name;
5242  }
5243  // host -> ihost
5244  elseif (($prop = 'i' . $name) && array_key_exists($prop, $props))
5245  {
5246  $name = $prop;
5247  $return = $this->$prop;
5248  }
5249  // ischeme -> scheme
5250  elseif (($prop = substr($name, 1)) && array_key_exists($prop, $props))
5251  {
5252  $name = $prop;
5253  $return = $this->$prop;
5254  }
5255  else
5256  {
5257  trigger_error('Undefined property: ' . get_class($this) . '::' . $name, E_USER_NOTICE);
5258  $return = null;
5259  }
5260  if ($return === null && isset($this->normalization[$this->scheme][$name]))
5261  {
5262  return $this->normalization[$this->scheme][$name];
5263  }
5264  else
5265  {
5266  return $return;
5267  }
5268  }
5269 
5270  public function __isset($name)
5271  {
5272  if (method_exists($this, 'get_' . $name) || isset($this->$name))
5273  {
5274  return true;
5275  }
5276  else
5277  {
5278  return false;
5279  }
5280  }
5281 
5282  public function __unset($name)
5283  {
5284  if (method_exists($this, 'set_' . $name))
5285  {
5286  call_user_func(array($this, 'set_' . $name), '');
5287  }
5288  }
5289 
5290  public function __construct($iri = null)
5291  {
5292  $this->set_iri($iri);
5293  }
5294 
5295  public static function absolutize($base, $relative)
5296  {
5297  if (!($relative instanceof SimplePie_IRI))
5298  {
5299  $relative = new SimplePie_IRI($relative);
5300  }
5301  if (!$relative->is_valid())
5302  {
5303  return false;
5304  }
5305  elseif ($relative->scheme !== null)
5306  {
5307  return clone $relative;
5308  }
5309  else
5310  {
5311  if (!($base instanceof SimplePie_IRI))
5312  {
5313  $base = new SimplePie_IRI($base);
5314  }
5315  if ($base->scheme !== null && $base->is_valid())
5316  {
5317  if ($relative->get_iri() !== '')
5318  {
5319  if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null)
5320  {
5321  $target = clone $relative;
5322  $target->scheme = $base->scheme;
5323  }
5324  else
5325  {
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 !== '')
5332  {
5333  if ($relative->ipath[0] === '/')
5334  {
5335  $target->ipath = $relative->ipath;
5336  }
5337  elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath === '')
5338  {
5339  $target->ipath = '/' . $relative->ipath;
5340  }
5341  elseif (($last_segment = strrpos($base->ipath, '/')) !== false)
5342  {
5343  $target->ipath = substr($base->ipath, 0, $last_segment + 1) . $relative->ipath;
5344  }
5345  else
5346  {
5347  $target->ipath = $relative->ipath;
5348  }
5349  $target->ipath = $target->remove_dot_segments($target->ipath);
5350  $target->iquery = $relative->iquery;
5351  }
5352  else
5353  {
5354  $target->ipath = $base->ipath;
5355  if ($relative->iquery !== null)
5356  {
5357  $target->iquery = $relative->iquery;
5358  }
5359  elseif ($base->iquery !== null)
5360  {
5361  $target->iquery = $base->iquery;
5362  }
5363  }
5364  $target->ifragment = $relative->ifragment;
5365  }
5366  }
5367  else
5368  {
5369  $target = clone $base;
5370  $target->ifragment = null;
5371  }
5372  $target->scheme_normalization();
5373  return $target;
5374  }
5375  else
5376  {
5377  return false;
5378  }
5379  }
5380  }
5381 
5382  protected function parse_iri($iri)
5383  {
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))
5386  {
5387  if ($match[1] === '')
5388  {
5389  $match['scheme'] = null;
5390  }
5391  if (!isset($match[3]) || $match[3] === '')
5392  {
5393  $match['authority'] = null;
5394  }
5395  if (!isset($match[5]))
5396  {
5397  $match['path'] = '';
5398  }
5399  if (!isset($match[6]) || $match[6] === '')
5400  {
5401  $match['query'] = null;
5402  }
5403  if (!isset($match[8]) || $match[8] === '')
5404  {
5405  $match['fragment'] = null;
5406  }
5407  return $match;
5408  }
5409  else
5410  {
5411  // This can occur when a paragraph is accidentally parsed as a URI
5412  return false;
5413  }
5414  }
5415 
5416  protected function remove_dot_segments($input)
5417  {
5418  $output = '';
5419  while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..')
5420  {
5421  // A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise,
5422  if (strpos($input, '../') === 0)
5423  {
5424  $input = substr($input, 3);
5425  }
5426  elseif (strpos($input, './') === 0)
5427  {
5428  $input = substr($input, 2);
5429  }
5430  // 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,
5431  elseif (strpos($input, '/./') === 0)
5432  {
5433  $input = substr($input, 2);
5434  }
5435  elseif ($input === '/.')
5436  {
5437  $input = '/';
5438  }
5439  // 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,
5440  elseif (strpos($input, '/../') === 0)
5441  {
5442  $input = substr($input, 3);
5443  $output = substr_replace($output, '', strrpos($output, '/'));
5444  }
5445  elseif ($input === '/..')
5446  {
5447  $input = '/';
5448  $output = substr_replace($output, '', strrpos($output, '/'));
5449  }
5450  // D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise,
5451  elseif ($input === '.' || $input === '..')
5452  {
5453  $input = '';
5454  }
5455  // 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
5456  elseif (($pos = strpos($input, '/', 1)) !== false)
5457  {
5458  $output .= substr($input, 0, $pos);
5459  $input = substr_replace($input, '', 0, $pos);
5460  }
5461  else
5462  {
5463  $output .= $input;
5464  $input = '';
5465  }
5466  }
5467  return $output . $input;
5468  }
5469 
5470  protected function replace_invalid_with_pct_encoding($string, $extra_chars, $iprivate = false)
5471  {
5472  // Normalize as many pct-encoded sections as possible
5473  $string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', array($this, 'remove_iunreserved_percent_encoded'), $string);
5474  // Replace invalid percent characters
5475  $string = preg_replace('/%(?![A-Fa-f0-9]{2})/', '%25', $string);
5476  // Add unreserved and % to $extra_chars (the latter is safe because all
5477  // pct-encoded sections are now valid).
5478  $extra_chars .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~%';
5479  // Now replace any bytes that aren't allowed with their pct-encoded versions
5480  $position = 0;
5481  $strlen = strlen($string);
5482  while (($position += strspn($string, $extra_chars, $position)) < $strlen)
5483  {
5484  $value = ord($string[$position]);
5485  // Start position
5486  $start = $position;
5487  // By default we are valid
5488  $valid = true;
5489  // No one byte sequences are valid due to the while.
5490  // Two byte sequence:
5491  if (($value & 0xE0) === 0xC0)
5492  {
5493  $character = ($value & 0x1F) << 6;
5494  $length = 2;
5495  $remaining = 1;
5496  }
5497  // Three byte sequence:
5498  elseif (($value & 0xF0) === 0xE0)
5499  {
5500  $character = ($value & 0x0F) << 12;
5501  $length = 3;
5502  $remaining = 2;
5503  }
5504  // Four byte sequence:
5505  elseif (($value & 0xF8) === 0xF0)
5506  {
5507  $character = ($value & 0x07) << 18;
5508  $length = 4;
5509  $remaining = 3;
5510  }
5511  // Invalid byte:
5512  else
5513  {
5514  $valid = false;
5515  $length = 1;
5516  $remaining = 0;
5517  }
5518  if ($remaining)
5519  {
5520  if ($position + $length <= $strlen)
5521  {
5522  for ($position++; $remaining; $position++)
5523  {
5524  $value = ord($string[$position]);
5525  // Check that the byte is valid, then add it to the character:
5526  if (($value & 0xC0) === 0x80)
5527  {
5528  $character |= ($value & 0x3F) << (--$remaining * 6);
5529  }
5530  // If it is invalid, count the sequence as invalid and reprocess the current byte:
5531  else
5532  {
5533  $valid = false;
5534  $position--;
5535  break;
5536  }
5537  }
5538  }
5539  else
5540  {
5541  $position = $strlen - 1;
5542  $valid = false;
5543  }
5544  }
5545  // Percent encode anything invalid or not in ucschar
5546  if (
5547  // Invalid sequences
5548  !$valid
5549  // Non-shortest form sequences are invalid
5550  || $length > 1 && $character <= 0x7F
5551  || $length > 2 && $character <= 0x7FF
5552  || $length > 3 && $character <= 0xFFFF
5553  // Outside of range of ucschar codepoints
5554  // Noncharacters
5555  || ($character & 0xFFFE) === 0xFFFE
5556  || $character >= 0xFDD0 && $character <= 0xFDEF
5557  || (
5558  // Everything else not in ucschar
5559  $character > 0xD7FF && $character < 0xF900
5560  || $character < 0xA0
5561  || $character > 0xEFFFD
5562  )
5563  && (
5564  // Everything not in iprivate, if it applies
5565  !$iprivate
5566  || $character < 0xE000
5567  || $character > 0x10FFFD
5568  )
5569  )
5570  {
5571  // If we were a character, pretend we weren't, but rather an error.
5572  if ($valid)
5573  $position--;
5574  for ($j = $start; $j <= $position; $j++)
5575  {
5576  $string = substr_replace($string, sprintf('%%%02X', ord($string[$j])), $j, 1);
5577  $j += 2;
5578  $position += 2;
5579  $strlen += 2;
5580  }
5581  }
5582  }
5583  return $string;
5584  }
5585 
5587  {
5588  // As we just have valid percent encoded sequences we can just explode
5589  // and ignore the first member of the returned array (an empty string).
5590  $bytes = explode('%', $match[0]);
5591  // Initialize the new string (this is what will be returned) and that
5592  // there are no bytes remaining in the current sequence (unsurprising
5593  // at the first byte!).
5594  $string = '';
5595  $remaining = 0;
5596  // Loop over each and every byte, and set $value to its value
5597  for ($i = 1, $len = count($bytes); $i < $len; $i++)
5598  {
5599  $value = hexdec($bytes[$i]);
5600  // If we're the first byte of sequence:
5601  if (!$remaining)
5602  {
5603  // Start position
5604  $start = $i;
5605  // By default we are valid
5606  $valid = true;
5607  // One byte sequence:
5608  if ($value <= 0x7F)
5609  {
5610  $character = $value;
5611  $length = 1;
5612  }
5613  // Two byte sequence:
5614  elseif (($value & 0xE0) === 0xC0)
5615  {
5616  $character = ($value & 0x1F) << 6;
5617  $length = 2;
5618  $remaining = 1;
5619  }
5620  // Three byte sequence:
5621  elseif (($value & 0xF0) === 0xE0)
5622  {
5623  $character = ($value & 0x0F) << 12;
5624  $length = 3;
5625  $remaining = 2;
5626  }
5627  // Four byte sequence:
5628  elseif (($value & 0xF8) === 0xF0)
5629  {
5630  $character = ($value & 0x07) << 18;
5631  $length = 4;
5632  $remaining = 3;
5633  }
5634  // Invalid byte:
5635  else
5636  {
5637  $valid = false;
5638  $remaining = 0;
5639  }
5640  }
5641  // Continuation byte:
5642  else
5643  {
5644  // Check that the byte is valid, then add it to the character:
5645  if (($value & 0xC0) === 0x80)
5646  {
5647  $remaining--;
5648  $character |= ($value & 0x3F) << ($remaining * 6);
5649  }
5650  // If it is invalid, count the sequence as invalid and reprocess the current byte as the start of a sequence:
5651  else
5652  {
5653  $valid = false;
5654  $remaining = 0;
5655  $i--;
5656  }
5657  }
5658  // If we've reached the end of the current byte sequence, append it to Unicode::$data
5659  if (!$remaining)
5660  {
5661  // Percent encode anything invalid or not in iunreserved
5662  if (
5663  // Invalid sequences
5664  !$valid
5665  // Non-shortest form sequences are invalid
5666  || $length > 1 && $character <= 0x7F
5667  || $length > 2 && $character <= 0x7FF
5668  || $length > 3 && $character <= 0xFFFF
5669  // Outside of range of iunreserved codepoints
5670  || $character < 0x2D
5671  || $character > 0xEFFFD
5672  // Noncharacters
5673  || ($character & 0xFFFE) === 0xFFFE
5674  || $character >= 0xFDD0 && $character <= 0xFDEF
5675  // Everything else not in iunreserved (this is all BMP)
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
5682  )
5683  {
5684  for ($j = $start; $j <= $i; $j++)
5685  {
5686  $string .= '%' . strtoupper($bytes[$j]);
5687  }
5688  }
5689  else
5690  {
5691  for ($j = $start; $j <= $i; $j++)
5692  {
5693  $string .= chr(hexdec($bytes[$j]));
5694  }
5695  }
5696  }
5697  }
5698  // If we have any bytes left over they are invalid (i.e., we are
5699  // mid-way through a multi-byte sequence)
5700  if ($remaining)
5701  {
5702  for ($j = $start; $j < $len; $j++)
5703  {
5704  $string .= '%' . strtoupper($bytes[$j]);
5705  }
5706  }
5707  return $string;
5708  }
5709  protected function scheme_normalization()
5710  {
5711  if (isset($this->normalization[$this->scheme]['iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme]['iuserinfo'])
5712  {
5713  $this->iuserinfo = null;
5714  }
5715  if (isset($this->normalization[$this->scheme]['ihost']) && $this->ihost === $this->normalization[$this->scheme]['ihost'])
5716  {
5717  $this->ihost = null;
5718  }
5719  if (isset($this->normalization[$this->scheme]['port']) && $this->port === $this->normalization[$this->scheme]['port'])
5720  {
5721  $this->port = null;
5722  }
5723  if (isset($this->normalization[$this->scheme]['ipath']) && $this->ipath === $this->normalization[$this->scheme]['ipath'])
5724  {
5725  $this->ipath = '';
5726  }
5727  if (isset($this->normalization[$this->scheme]['iquery']) && $this->iquery === $this->normalization[$this->scheme]['iquery'])
5728  {
5729  $this->iquery = null;
5730  }
5731  if (isset($this->normalization[$this->scheme]['ifragment']) && $this->ifragment === $this->normalization[$this->scheme]['ifragment'])
5732  {
5733  $this->ifragment = null;
5734  }
5735  }
5736 
5737  public function is_valid()
5738  {
5739  $isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null;
5740  if ($this->ipath !== '' &&
5741  (
5742  $isauthority && (
5743  $this->ipath[0] !== '/' ||
5744  substr($this->ipath, 0, 2) === '//'
5745  ) ||
5746  (
5747  $this->scheme === null &&
5748  !$isauthority &&
5749  strpos($this->ipath, ':') !== false &&
5750  (strpos($this->ipath, '/') === false ? true : strpos($this->ipath, ':') < strpos($this->ipath, '/'))
5751  )
5752  )
5753  )
5754  {
5755  return false;
5756  }
5757  return true;
5758  }
5759 
5760  public function set_iri($iri)
5761  {
5762  static $cache;
5763  if (!$cache)
5764  {
5765  $cache = array();
5766  }
5767  if ($iri === null)
5768  {
5769  return true;
5770  }
5771  elseif (isset($cache[$iri]))
5772  {
5773  list($this->scheme,
5774  $this->iuserinfo,
5775  $this->ihost,
5776  $this->port,
5777  $this->ipath,
5778  $this->iquery,
5779  $this->ifragment,
5780  $return) = $cache[$iri];
5781  return $return;
5782  }
5783  else
5784  {
5785  $parsed = $this->parse_iri((string) $iri);
5786  if (!$parsed)
5787  {
5788  return false;
5789  }
5790  $return = $this->set_scheme($parsed['scheme'])
5791  && $this->set_authority($parsed['authority'])
5792  && $this->set_path($parsed['path'])
5793  && $this->set_query($parsed['query'])
5794  && $this->set_fragment($parsed['fragment']);
5795  $cache[$iri] = array($this->scheme,
5796  $this->iuserinfo,
5797  $this->ihost,
5798  $this->port,
5799  $this->ipath,
5800  $this->iquery,
5801  $this->ifragment,
5802  $return);
5803  return $return;
5804  }
5805  }
5806 
5807  public function set_scheme($scheme)
5808  {
5809  if ($scheme === null)
5810  {
5811  $this->scheme = null;
5812  }
5813  elseif (!preg_match('/^[A-Za-z][0-9A-Za-z+\-.]*$/', $scheme))
5814  {
5815  $this->scheme = null;
5816  return false;
5817  }
5818  else
5819  {
5820  $this->scheme = strtolower($scheme);
5821  }
5822  return true;
5823  }
5824 
5825  public function set_authority($authority)
5826  {
5827  static $cache;
5828  if (!$cache)
5829  $cache = array();
5830  if ($authority === null)
5831  {
5832  $this->iuserinfo = null;
5833  $this->ihost = null;
5834  $this->port = null;
5835  return true;
5836  }
5837  elseif (isset($cache[$authority]))
5838  {
5839  list($this->iuserinfo,
5840  $this->ihost,
5841  $this->port,
5842  $return) = $cache[$authority];
5843  return $return;
5844  }
5845  else
5846  {
5847  $remaining = $authority;
5848  if (($iuserinfo_end = strrpos($remaining, '@')) !== false)
5849  {
5850  $iuserinfo = substr($remaining, 0, $iuserinfo_end);
5851  $remaining = substr($remaining, $iuserinfo_end + 1);
5852  }
5853  else
5854  {
5855  $iuserinfo = null;
5856  }
5857  if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false)
5858  {
5859  if (($port = substr($remaining, $port_start + 1)) === false)
5860  {
5861  $port = null;
5862  }
5863  $remaining = substr($remaining, 0, $port_start);
5864  }
5865  else
5866  {
5867  $port = null;
5868  }
5869  $return = $this->set_userinfo($iuserinfo) &&
5870  $this->set_host($remaining) &&
5871  $this->set_port($port);
5872  $cache[$authority] = array($this->iuserinfo,
5873  $this->ihost,
5874  $this->port,
5875  $return);
5876  return $return;
5877  }
5878  }
5879 
5880  public function set_userinfo($iuserinfo)
5881  {
5882  if ($iuserinfo === null)
5883  {
5884  $this->iuserinfo = null;
5885  }
5886  else
5887  {
5888  $this->iuserinfo = $this->replace_invalid_with_pct_encoding($iuserinfo, '!$&\'()*+,;=:');
5889  $this->scheme_normalization();
5890  }
5891  return true;
5892  }
5893 
5894  public function set_host($ihost)
5895  {
5896  if ($ihost === null)
5897  {
5898  $this->ihost = null;
5899  return true;
5900  }
5901  elseif (substr($ihost, 0, 1) === '[' && substr($ihost, -1) === ']')
5902  {
5903  if (SimplePie_Net_IPv6::check_ipv6(substr($ihost, 1, -1)))
5904  {
5905  $this->ihost = '[' . SimplePie_Net_IPv6::compress(substr($ihost, 1, -1)) . ']';
5906  }
5907  else
5908  {
5909  $this->ihost = null;
5910  return false;
5911  }
5912  }
5913  else
5914  {
5915  $ihost = $this->replace_invalid_with_pct_encoding($ihost, '!$&\'()*+,;=');
5916  // Lowercase, but ignore pct-encoded sections (as they should
5917  // remain uppercase). This must be done after the previous step
5918  // as that can add unescaped characters.
5919  $position = 0;
5920  $strlen = strlen($ihost);
5921  while (($position += strcspn($ihost, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ%', $position)) < $strlen)
5922  {
5923  if ($ihost[$position] === '%')
5924  {
5925  $position += 3;
5926  }
5927  else
5928  {
5929  $ihost[$position] = strtolower($ihost[$position]);
5930  $position++;
5931  }
5932  }
5933  $this->ihost = $ihost;
5934  }
5935  $this->scheme_normalization();
5936  return true;
5937  }
5938 
5939  public function set_port($port)
5940  {
5941  if ($port === null)
5942  {
5943  $this->port = null;
5944  return true;
5945  }
5946  elseif (strspn($port, '0123456789') === strlen($port))
5947  {
5948  $this->port = (int) $port;
5949  $this->scheme_normalization();
5950  return true;
5951  }
5952  else
5953  {
5954  $this->port = null;
5955  return false;
5956  }
5957  }
5958 
5959  public function set_path($ipath)
5960  {
5961  static $cache;
5962  if (!$cache)
5963  {
5964  $cache = array();
5965  }
5966  $ipath = (string) $ipath;
5967  if (isset($cache[$ipath]))
5968  {
5969  $this->ipath = $cache[$ipath][(int) ($this->scheme !== null)];
5970  }
5971  else
5972  {
5973  $valid = $this->replace_invalid_with_pct_encoding($ipath, '!$&\'()*+,;=@:/');
5974  $removed = $this->remove_dot_segments($valid);
5975  $cache[$ipath] = array($valid, $removed);
5976  $this->ipath = ($this->scheme !== null) ? $removed : $valid;
5977  }
5978  $this->scheme_normalization();
5979  return true;
5980  }
5981 
5982  public function set_query($iquery)
5983  {
5984  if ($iquery === null)
5985  {
5986  $this->iquery = null;
5987  }
5988  else
5989  {
5990  $this->iquery = $this->replace_invalid_with_pct_encoding($iquery, '!$&\'()*+,;=:@/?', true);
5991  $this->scheme_normalization();
5992  }
5993  return true;
5994  }
5995 
5996  public function set_fragment($ifragment)
5997  {
5998  if ($ifragment === null)
5999  {
6000  $this->ifragment = null;
6001  }
6002  else
6003  {
6004  $this->ifragment = $this->replace_invalid_with_pct_encoding($ifragment, '!$&\'()*+,;=:@/?');
6005  $this->scheme_normalization();
6006  }
6007  return true;
6008  }
6009 
6010  public function to_uri($string)
6011  {
6012  static $non_ascii;
6013  if (!$non_ascii)
6014  {
6015  $non_ascii = implode('', range("\x80", "\xFF"));
6016  }
6017  $position = 0;
6018  $strlen = strlen($string);
6019  while (($position += strcspn($string, $non_ascii, $position)) < $strlen)
6020  {
6021  $string = substr_replace($string, sprintf('%%%02X', ord($string[$position])), $position, 1);
6022  $position += 3;
6023  $strlen += 2;
6024  }
6025  return $string;
6026  }
6027 
6028  public function get_iri()
6029  {
6030  if (!$this->is_valid())
6031  {
6032  return false;
6033  }
6034  $iri = '';
6035  if ($this->scheme !== null)
6036  {
6037  $iri .= $this->scheme . ':';
6038  }
6039  if (($iauthority = $this->get_iauthority()) !== null)
6040  {
6041  $iri .= '//' . $iauthority;
6042  }
6043  if ($this->ipath !== '')
6044  {
6045  $iri .= $this->ipath;
6046  }
6047  elseif (!empty($this->normalization[$this->scheme]['ipath']) && $iauthority !== null && $iauthority !== '')
6048  {
6049  $iri .= $this->normalization[$this->scheme]['ipath'];
6050  }
6051  if ($this->iquery !== null)
6052  {
6053  $iri .= '?' . $this->iquery;
6054  }
6055  if ($this->ifragment !== null)
6056  {
6057  $iri .= '#' . $this->ifragment;
6058  }
6059  return $iri;
6060  }
6061 
6062  public function get_uri()
6063  {
6064  return $this->to_uri($this->get_iri());
6065  }
6066 
6067  protected function get_iauthority()
6068  {
6069  if ($this->iuserinfo !== null || $this->ihost !== null || $this->port !== null)
6070  {
6071  $iauthority = '';
6072  if ($this->iuserinfo !== null)
6073  {
6074  $iauthority .= $this->iuserinfo . '@';
6075  }
6076  if ($this->ihost !== null)
6077  {
6078  $iauthority .= $this->ihost;
6079  }
6080  if ($this->port !== null)
6081  {
6082  $iauthority .= ':' . $this->port;
6083  }
6084  return $iauthority;
6085  }
6086  else
6087  {
6088  return null;
6089  }
6090  }
6091 
6092  protected function get_authority()
6093  {
6094  $iauthority = $this->get_iauthority();
6095  if (is_string($iauthority))
6096  return $this->to_uri($iauthority);
6097  else
6098  return $iauthority;
6099  }
6100 }
6102 {
6103 
6104  var $feed;
6105 
6106  var $data = array();
6107 
6108  protected $registry;
6109 
6110  public function __construct($feed, $data)
6111  {
6112  $this->feed = $feed;
6113  $this->data = $data;
6114  }
6115 
6117  {
6118  $this->registry = $registry;
6119  }
6120 
6121  public function __toString()
6122  {
6123  return md5(serialize($this->data));
6124  }
6125 
6126  public function __destruct()
6127  {
6128  if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
6129  {
6130  unset($this->feed);
6131  }
6132  }
6133 
6134  public function get_item_tags($namespace, $tag)
6135  {
6136  if (isset($this->data['child'][$namespace][$tag]))
6137  {
6138  return $this->data['child'][$namespace][$tag];
6139  }
6140  else
6141  {
6142  return null;
6143  }
6144  }
6145 
6146  public function get_base($element = array())
6147  {
6148  return $this->feed->get_base($element);
6149  }
6150 
6151  public function sanitize($data, $type, $base = '')
6152  {
6153  return $this->feed->sanitize($data, $type, $base);
6154  }
6155 
6156  public function get_feed()
6157  {
6158  return $this->feed;
6159  }
6160 
6161  public function get_id($hash = false)
6162  {
6163  if (!$hash)
6164  {
6165  if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'))
6166  {
6167  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6168  }
6169  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id'))
6170  {
6171  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6172  }
6173  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
6174  {
6175  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6176  }
6177  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier'))
6178  {
6179  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6180  }
6181  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier'))
6182  {
6183  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6184  }
6185  elseif (isset($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about']))
6186  {
6187  return $this->sanitize($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about'], SIMPLEPIE_CONSTRUCT_TEXT);
6188  }
6189  elseif (($return = $this->get_permalink()) !== null)
6190  {
6191  return $return;
6192  }
6193  elseif (($return = $this->get_title()) !== null)
6194  {
6195  return $return;
6196  }
6197  }
6198  if ($this->get_permalink() !== null || $this->get_title() !== null)
6199  {
6200  return md5($this->get_permalink() . $this->get_title());
6201  }
6202  else
6203  {
6204  return md5(serialize($this->data));
6205  }
6206  }
6207 
6208  public function get_title()
6209  {
6210  if (!isset($this->data['title']))
6211  {
6212  if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
6213  {
6214  $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
6215  }
6216  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
6217  {
6218  $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
6219  }
6220  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
6221  {
6222  $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
6223  }
6224  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
6225  {
6226  $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
6227  }
6228  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
6229  {
6230  $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
6231  }
6232  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
6233  {
6234  $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6235  }
6236  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
6237  {
6238  $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6239  }
6240  else
6241  {
6242  $this->data['title'] = null;
6243  }
6244  }
6245  return $this->data['title'];
6246  }
6247 
6248  public function get_description($description_only = false)
6249  {
6250  if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary'))
6251  {
6252  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
6253  }
6254  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary'))
6255  {
6256  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
6257  }
6258  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
6259  {
6260  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
6261  }
6262  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
6263  {
6264  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
6265  }
6266  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
6267  {
6268  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6269  }
6270  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
6271  {
6272  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6273  }
6274  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
6275  {
6276  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
6277  }
6278  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
6279  {
6280  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6281  }
6282  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
6283  {
6284  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
6285  }
6286  elseif (!$description_only)
6287  {
6288  return $this->get_content(true);
6289  }
6290  else
6291  {
6292  return null;
6293  }
6294  }
6295 
6296  public function get_content($content_only = false)
6297  {
6298  if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content'))
6299  {
6300  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_content_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
6301  }
6302  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content'))
6303  {
6304  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
6305  }
6306  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded'))
6307  {
6308  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
6309  }
6310  elseif (!$content_only)
6311  {
6312  return $this->get_description(true);
6313  }
6314  else
6315  {
6316  return null;
6317  }
6318  }
6319 
6320  public function get_category($key = 0)
6321  {
6322  $categories = $this->get_categories();
6323  if (isset($categories[$key]))
6324  {
6325  return $categories[$key];
6326  }
6327  else
6328  {
6329  return null;
6330  }
6331  }
6332 
6333  public function get_categories()
6334  {
6335  $categories = array();
6336  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
6337  {
6338  $term = null;
6339  $scheme = null;
6340  $label = null;
6341  if (isset($category['attribs']['']['term']))
6342  {
6343  $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
6344  }
6345  if (isset($category['attribs']['']['scheme']))
6346  {
6347  $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
6348  }
6349  if (isset($category['attribs']['']['label']))
6350  {
6351  $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
6352  }
6353  $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
6354  }
6355  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
6356  {
6357  // This is really the label, but keep this as the term also for BC.
6358  // Label will also work on retrieving because that falls back to term.
6359  $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6360  if (isset($category['attribs']['']['domain']))
6361  {
6362  $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
6363  }
6364  else
6365  {
6366  $scheme = null;
6367  }
6368  $categories[] = $this->registry->create('Category', array($term, $scheme, null));
6369  }
6370  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
6371  {
6372  $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
6373  }
6374  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
6375  {
6376  $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
6377  }
6378  if (!empty($categories))
6379  {
6380  return array_unique($categories);
6381  }
6382  else
6383  {
6384  return null;
6385  }
6386  }
6387 
6388  public function get_author($key = 0)
6389  {
6390  $authors = $this->get_authors();
6391  if (isset($authors[$key]))
6392  {
6393  return $authors[$key];
6394  }
6395  else
6396  {
6397  return null;
6398  }
6399  }
6400 
6401  public function get_contributor($key = 0)
6402  {
6403  $contributors = $this->get_contributors();
6404  if (isset($contributors[$key]))
6405  {
6406  return $contributors[$key];
6407  }
6408  else
6409  {
6410  return null;
6411  }
6412  }
6413 
6414  public function get_contributors()
6415  {
6416  $contributors = array();
6417  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
6418  {
6419  $name = null;
6420  $uri = null;
6421  $email = null;
6422  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
6423  {
6424  $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6425  }
6426  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
6427  {
6428  $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]));
6429  }
6430  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
6431  {
6432  $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6433  }
6434  if ($name !== null || $email !== null || $uri !== null)
6435  {
6436  $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
6437  }
6438  }
6439  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
6440  {
6441  $name = null;
6442  $url = null;
6443  $email = null;
6444  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
6445  {
6446  $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6447  }
6448  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
6449  {
6450  $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]));
6451  }
6452  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
6453  {
6454  $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6455  }
6456  if ($name !== null || $email !== null || $url !== null)
6457  {
6458  $contributors[] = $this->registry->create('Author', array($name, $url, $email));
6459  }
6460  }
6461  if (!empty($contributors))
6462  {
6463  return array_unique($contributors);
6464  }
6465  else
6466  {
6467  return null;
6468  }
6469  }
6470 
6471  public function get_authors()
6472  {
6473  $authors = array();
6474  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
6475  {
6476  $name = null;
6477  $uri = null;
6478  $email = null;
6479  if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
6480  {
6481  $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6482  }
6483  if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
6484  {
6485  $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]));
6486  }
6487  if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
6488  {
6489  $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6490  }
6491  if ($name !== null || $email !== null || $uri !== null)
6492  {
6493  $authors[] = $this->registry->create('Author', array($name, $uri, $email));
6494  }
6495  }
6496  if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
6497  {
6498  $name = null;
6499  $url = null;
6500  $email = null;
6501  if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
6502  {
6503  $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6504  }
6505  if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
6506  {
6507  $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]));
6508  }
6509  if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
6510  {
6511  $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6512  }
6513  if ($name !== null || $email !== null || $url !== null)
6514  {
6515  $authors[] = $this->registry->create('Author', array($name, $url, $email));
6516  }
6517  }
6518  if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'author'))
6519  {
6520  $authors[] = $this->registry->create('Author', array(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)));
6521  }
6522  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
6523  {
6524  $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
6525  }
6526  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
6527  {
6528  $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
6529  }
6530  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
6531  {
6532  $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
6533  }
6534  if (!empty($authors))
6535  {
6536  return array_unique($authors);
6537  }
6538  elseif (($source = $this->get_source()) && ($authors = $source->get_authors()))
6539  {
6540  return $authors;
6541  }
6542  elseif ($authors = $this->feed->get_authors())
6543  {
6544  return $authors;
6545  }
6546  else
6547  {
6548  return null;
6549  }
6550  }
6551 
6552  public function get_copyright()
6553  {
6554  if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
6555  {
6556  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
6557  }
6558  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
6559  {
6560  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6561  }
6562  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
6563  {
6564  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6565  }
6566  else
6567  {
6568  return null;
6569  }
6570  }
6571 
6572  public function get_date($date_format = 'j F Y, g:i a')
6573  {
6574  if (!isset($this->data['date']))
6575  {
6576  if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'))
6577  {
6578  $this->data['date']['raw'] = $return[0]['data'];
6579  }
6580  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
6581  {
6582  $this->data['date']['raw'] = $return[0]['data'];
6583  }
6584  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued'))
6585  {
6586  $this->data['date']['raw'] = $return[0]['data'];
6587  }
6588  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created'))
6589  {
6590  $this->data['date']['raw'] = $return[0]['data'];
6591  }
6592  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified'))
6593  {
6594  $this->data['date']['raw'] = $return[0]['data'];
6595  }
6596  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'pubDate'))
6597  {
6598  $this->data['date']['raw'] = $return[0]['data'];
6599  }
6600  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date'))
6601  {
6602  $this->data['date']['raw'] = $return[0]['data'];
6603  }
6604  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date'))
6605  {
6606  $this->data['date']['raw'] = $return[0]['data'];
6607  }
6608  if (!empty($this->data['date']['raw']))
6609  {
6610  $parser = $this->registry->call('Parse_Date', 'get');
6611  $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']);
6612  }
6613  else
6614  {
6615  $this->data['date'] = null;
6616  }
6617  }
6618  if ($this->data['date'])
6619  {
6620  $date_format = (string) $date_format;
6621  switch ($date_format)
6622  {
6623  case '':
6624  return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
6625  case 'U':
6626  return $this->data['date']['parsed'];
6627  default:
6628  return date($date_format, $this->data['date']['parsed']);
6629  }
6630  }
6631  else
6632  {
6633  return null;
6634  }
6635  }
6636 
6637  public function get_updated_date($date_format = 'j F Y, g:i a')
6638  {
6639  if (!isset($this->data['updated']))
6640  {
6641  if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
6642  {
6643  $this->data['updated']['raw'] = $return[0]['data'];
6644  }
6645  if (!empty($this->data['updated']['raw']))
6646  {
6647  $parser = $this->registry->call('Parse_Date', 'get');
6648  $this->data['updated']['parsed'] = $parser->parse($this->data['date']['raw']);
6649  }
6650  else
6651  {
6652  $this->data['updated'] = null;
6653  }
6654  }
6655  if ($this->data['updated'])
6656  {
6657  $date_format = (string) $date_format;
6658  switch ($date_format)
6659  {
6660  case '':
6661  return $this->sanitize($this->data['updated']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
6662  case 'U':
6663  return $this->data['updated']['parsed'];
6664  default:
6665  return date($date_format, $this->data['updated']['parsed']);
6666  }
6667  }
6668  else
6669  {
6670  return null;
6671  }
6672  }
6673 
6674  public function get_local_date($date_format = '%c')
6675  {
6676  if (!$date_format)
6677  {
6678  return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT);
6679  }
6680  elseif (($date = $this->get_date('U')) !== null && $date !== false)
6681  {
6682  return strftime($date_format, $date);
6683  }
6684  else
6685  {
6686  return null;
6687  }
6688  }
6689 
6690  public function get_gmdate($date_format = 'j F Y, g:i a')
6691  {
6692  $date = $this->get_date('U');
6693  if ($date === null)
6694  {
6695  return null;
6696  }
6697  return gmdate($date_format, $date);
6698  }
6699 
6700  public function get_updated_gmdate($date_format = 'j F Y, g:i a')
6701  {
6702  $date = $this->get_updated_date('U');
6703  if ($date === null)
6704  {
6705  return null;
6706  }
6707  return gmdate($date_format, $date);
6708  }
6709 
6710  public function get_permalink()
6711  {
6712  $link = $this->get_link();
6713  $enclosure = $this->get_enclosure(0);
6714  if ($link !== null)
6715  {
6716  return $link;
6717  }
6718  elseif ($enclosure !== null)
6719  {
6720  return $enclosure->get_link();
6721  }
6722  else
6723  {
6724  return null;
6725  }
6726  }
6727 
6728  public function get_link($key = 0, $rel = 'alternate')
6729  {
6730  $links = $this->get_links($rel);
6731  if ($links[$key] !== null)
6732  {
6733  return $links[$key];
6734  }
6735  else
6736  {
6737  return null;
6738  }
6739  }
6740 
6741  public function get_links($rel = 'alternate')
6742  {
6743  if (!isset($this->data['links']))
6744  {
6745  $this->data['links'] = array();
6746  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
6747  {
6748  if (isset($link['attribs']['']['href']))
6749  {
6750  $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
6751  $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
6752  }
6753  }
6754  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
6755  {
6756  if (isset($link['attribs']['']['href']))
6757  {
6758  $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
6759  $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
6760  }
6761  }
6762  if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
6763  {
6764  $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
6765  }
6766  if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
6767  {
6768  $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
6769  }
6770  if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
6771  {
6772  $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
6773  }
6774  if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
6775  {
6776  if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true')
6777  {
6778  $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
6779  }
6780  }
6781  $keys = array_keys($this->data['links']);
6782  foreach ($keys as $key)
6783  {
6784  if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
6785  {
6786  if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
6787  {
6788  $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
6789  $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
6790  }
6791  else
6792  {
6793  $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
6794  }
6795  }
6796  elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
6797  {
6798  $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
6799  }
6800  $this->data['links'][$key] = array_unique($this->data['links'][$key]);
6801  }
6802  }
6803  if (isset($this->data['links'][$rel]))
6804  {
6805  return $this->data['links'][$rel];
6806  }
6807  else
6808  {
6809  return null;
6810  }
6811  }
6812 
6813  public function get_enclosure($key = 0, $prefer = null)
6814  {
6815  $enclosures = $this->get_enclosures();
6816  if (isset($enclosures[$key]))
6817  {
6818  return $enclosures[$key];
6819  }
6820  else
6821  {
6822  return null;
6823  }
6824  }
6825 
6826  public function get_enclosures()
6827  {
6828  if (!isset($this->data['enclosures']))
6829  {
6830  $this->data['enclosures'] = array();
6831  // Elements
6832  $captions_parent = null;
6833  $categories_parent = null;
6834  $copyrights_parent = null;
6835  $credits_parent = null;
6836  $description_parent = null;
6837  $duration_parent = null;
6838  $hashes_parent = null;
6839  $keywords_parent = null;
6840  $player_parent = null;
6841  $ratings_parent = null;
6842  $restrictions_parent = null;
6843  $thumbnails_parent = null;
6844  $title_parent = null;
6845  // Let's do the channel and item-level ones first, and just re-use them if we need to.
6846  $parent = $this->get_feed();
6847  // CAPTIONS
6848  if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
6849  {
6850  foreach ($captions as $caption)
6851  {
6852  $caption_type = null;
6853  $caption_lang = null;
6854  $caption_startTime = null;
6855  $caption_endTime = null;
6856  $caption_text = null;
6857  if (isset($caption['attribs']['']['type']))
6858  {
6859  $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
6860  }
6861  if (isset($caption['attribs']['']['lang']))
6862  {
6863  $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
6864  }
6865  if (isset($caption['attribs']['']['start']))
6866  {
6867  $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
6868  }
6869  if (isset($caption['attribs']['']['end']))
6870  {
6871  $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
6872  }
6873  if (isset($caption['data']))
6874  {
6875  $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6876  }
6877  $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
6878  }
6879  }
6880  elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
6881  {
6882  foreach ($captions as $caption)
6883  {
6884  $caption_type = null;
6885  $caption_lang = null;
6886  $caption_startTime = null;
6887  $caption_endTime = null;
6888  $caption_text = null;
6889  if (isset($caption['attribs']['']['type']))
6890  {
6891  $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
6892  }
6893  if (isset($caption['attribs']['']['lang']))
6894  {
6895  $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
6896  }
6897  if (isset($caption['attribs']['']['start']))
6898  {
6899  $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
6900  }
6901  if (isset($caption['attribs']['']['end']))
6902  {
6903  $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
6904  }
6905  if (isset($caption['data']))
6906  {
6907  $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6908  }
6909  $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
6910  }
6911  }
6912  if (is_array($captions_parent))
6913  {
6914  $captions_parent = array_values(array_unique($captions_parent));
6915  }
6916  // CATEGORIES
6917  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
6918  {
6919  $term = null;
6920  $scheme = null;
6921  $label = null;
6922  if (isset($category['data']))
6923  {
6924  $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6925  }
6926  if (isset($category['attribs']['']['scheme']))
6927  {
6928  $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
6929  }
6930  else
6931  {
6932  $scheme = 'http://search.yahoo.com/mrss/category_schema';
6933  }
6934  if (isset($category['attribs']['']['label']))
6935  {
6936  $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
6937  }
6938  $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
6939  }
6940  foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
6941  {
6942  $term = null;
6943  $scheme = null;
6944  $label = null;
6945  if (isset($category['data']))
6946  {
6947  $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
6948  }
6949  if (isset($category['attribs']['']['scheme']))
6950  {
6951  $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
6952  }
6953  else
6954  {
6955  $scheme = 'http://search.yahoo.com/mrss/category_schema';
6956  }
6957  if (isset($category['attribs']['']['label']))
6958  {
6959  $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
6960  }
6961  $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
6962  }
6963  foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category)
6964  {
6965  $term = null;
6966  $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
6967  $label = null;
6968  if (isset($category['attribs']['']['text']))
6969  {
6970  $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
6971  }
6972  $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
6973  if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category']))
6974  {
6975  foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory)
6976  {
6977  if (isset($subcategory['attribs']['']['text']))
6978  {
6979  $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
6980  }
6981  $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
6982  }
6983  }
6984  }
6985  if (is_array($categories_parent))
6986  {
6987  $categories_parent = array_values(array_unique($categories_parent));
6988  }
6989  // COPYRIGHT
6990  if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
6991  {
6992  $copyright_url = null;
6993  $copyright_label = null;
6994  if (isset($copyright[0]['attribs']['']['url']))
6995  {
6996  $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
6997  }
6998  if (isset($copyright[0]['data']))
6999  {
7000  $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7001  }
7002  $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
7003  }
7004  elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
7005  {
7006  $copyright_url = null;
7007  $copyright_label = null;
7008  if (isset($copyright[0]['attribs']['']['url']))
7009  {
7010  $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
7011  }
7012  if (isset($copyright[0]['data']))
7013  {
7014  $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7015  }
7016  $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
7017  }
7018  // CREDITS
7019  if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
7020  {
7021  foreach ($credits as $credit)
7022  {
7023  $credit_role = null;
7024  $credit_scheme = null;
7025  $credit_name = null;
7026  if (isset($credit['attribs']['']['role']))
7027  {
7028  $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
7029  }
7030  if (isset($credit['attribs']['']['scheme']))
7031  {
7032  $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
7033  }
7034  else
7035  {
7036  $credit_scheme = 'urn:ebu';
7037  }
7038  if (isset($credit['data']))
7039  {
7040  $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7041  }
7042  $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
7043  }
7044  }
7045  elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
7046  {
7047  foreach ($credits as $credit)
7048  {
7049  $credit_role = null;
7050  $credit_scheme = null;
7051  $credit_name = null;
7052  if (isset($credit['attribs']['']['role']))
7053  {
7054  $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
7055  }
7056  if (isset($credit['attribs']['']['scheme']))
7057  {
7058  $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
7059  }
7060  else
7061  {
7062  $credit_scheme = 'urn:ebu';
7063  }
7064  if (isset($credit['data']))
7065  {
7066  $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7067  }
7068  $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
7069  }
7070  }
7071  if (is_array($credits_parent))
7072  {
7073  $credits_parent = array_values(array_unique($credits_parent));
7074  }
7075  // DESCRIPTION
7076  if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
7077  {
7078  if (isset($description_parent[0]['data']))
7079  {
7080  $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7081  }
7082  }
7083  elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
7084  {
7085  if (isset($description_parent[0]['data']))
7086  {
7087  $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7088  }
7089  }
7090  // DURATION
7091  if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration'))
7092  {
7093  $seconds = null;
7094  $minutes = null;
7095  $hours = null;
7096  if (isset($duration_parent[0]['data']))
7097  {
7098  $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
7099  if (sizeof($temp) > 0)
7100  {
7101  $seconds = (int) array_pop($temp);
7102  }
7103  if (sizeof($temp) > 0)
7104  {
7105  $minutes = (int) array_pop($temp);
7106  $seconds += $minutes * 60;
7107  }
7108  if (sizeof($temp) > 0)
7109  {
7110  $hours = (int) array_pop($temp);
7111  $seconds += $hours * 3600;
7112  }
7113  unset($temp);
7114  $duration_parent = $seconds;
7115  }
7116  }
7117  // HASHES
7118  if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
7119  {
7120  foreach ($hashes_iterator as $hash)
7121  {
7122  $value = null;
7123  $algo = null;
7124  if (isset($hash['data']))
7125  {
7126  $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7127  }
7128  if (isset($hash['attribs']['']['algo']))
7129  {
7130  $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
7131  }
7132  else
7133  {
7134  $algo = 'md5';
7135  }
7136  $hashes_parent[] = $algo.':'.$value;
7137  }
7138  }
7139  elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
7140  {
7141  foreach ($hashes_iterator as $hash)
7142  {
7143  $value = null;
7144  $algo = null;
7145  if (isset($hash['data']))
7146  {
7147  $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7148  }
7149  if (isset($hash['attribs']['']['algo']))
7150  {
7151  $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
7152  }
7153  else
7154  {
7155  $algo = 'md5';
7156  }
7157  $hashes_parent[] = $algo.':'.$value;
7158  }
7159  }
7160  if (is_array($hashes_parent))
7161  {
7162  $hashes_parent = array_values(array_unique($hashes_parent));
7163  }
7164  // KEYWORDS
7165  if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
7166  {
7167  if (isset($keywords[0]['data']))
7168  {
7169  $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
7170  foreach ($temp as $word)
7171  {
7172  $keywords_parent[] = trim($word);
7173  }
7174  }
7175  unset($temp);
7176  }
7177  elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
7178  {
7179  if (isset($keywords[0]['data']))
7180  {
7181  $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
7182  foreach ($temp as $word)
7183  {
7184  $keywords_parent[] = trim($word);
7185  }
7186  }
7187  unset($temp);
7188  }
7189  elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
7190  {
7191  if (isset($keywords[0]['data']))
7192  {
7193  $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
7194  foreach ($temp as $word)
7195  {
7196  $keywords_parent[] = trim($word);
7197  }
7198  }
7199  unset($temp);
7200  }
7201  elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
7202  {
7203  if (isset($keywords[0]['data']))
7204  {
7205  $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
7206  foreach ($temp as $word)
7207  {
7208  $keywords_parent[] = trim($word);
7209  }
7210  }
7211  unset($temp);
7212  }
7213  if (is_array($keywords_parent))
7214  {
7215  $keywords_parent = array_values(array_unique($keywords_parent));
7216  }
7217  // PLAYER
7218  if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
7219  {
7220  if (isset($player_parent[0]['attribs']['']['url']))
7221  {
7222  $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
7223  }
7224  }
7225  elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
7226  {
7227  if (isset($player_parent[0]['attribs']['']['url']))
7228  {
7229  $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
7230  }
7231  }
7232  // RATINGS
7233  if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
7234  {
7235  foreach ($ratings as $rating)
7236  {
7237  $rating_scheme = null;
7238  $rating_value = null;
7239  if (isset($rating['attribs']['']['scheme']))
7240  {
7241  $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
7242  }
7243  else
7244  {
7245  $rating_scheme = 'urn:simple';
7246  }
7247  if (isset($rating['data']))
7248  {
7249  $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7250  }
7251  $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
7252  }
7253  }
7254  elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
7255  {
7256  foreach ($ratings as $rating)
7257  {
7258  $rating_scheme = 'urn:itunes';
7259  $rating_value = null;
7260  if (isset($rating['data']))
7261  {
7262  $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7263  }
7264  $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
7265  }
7266  }
7267  elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
7268  {
7269  foreach ($ratings as $rating)
7270  {
7271  $rating_scheme = null;
7272  $rating_value = null;
7273  if (isset($rating['attribs']['']['scheme']))
7274  {
7275  $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
7276  }
7277  else
7278  {
7279  $rating_scheme = 'urn:simple';
7280  }
7281  if (isset($rating['data']))
7282  {
7283  $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7284  }
7285  $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
7286  }
7287  }
7288  elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
7289  {
7290  foreach ($ratings as $rating)
7291  {
7292  $rating_scheme = 'urn:itunes';
7293  $rating_value = null;
7294  if (isset($rating['data']))
7295  {
7296  $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7297  }
7298  $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
7299  }
7300  }
7301  if (is_array($ratings_parent))
7302  {
7303  $ratings_parent = array_values(array_unique($ratings_parent));
7304  }
7305  // RESTRICTIONS
7306  if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
7307  {
7308  foreach ($restrictions as $restriction)
7309  {
7310  $restriction_relationship = null;
7311  $restriction_type = null;
7312  $restriction_value = null;
7313  if (isset($restriction['attribs']['']['relationship']))
7314  {
7315  $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
7316  }
7317  if (isset($restriction['attribs']['']['type']))
7318  {
7319  $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
7320  }
7321  if (isset($restriction['data']))
7322  {
7323  $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7324  }
7325  $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
7326  }
7327  }
7328  elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
7329  {
7330  foreach ($restrictions as $restriction)
7331  {
7332  $restriction_relationship = 'allow';
7333  $restriction_type = null;
7334  $restriction_value = 'itunes';
7335  if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
7336  {
7337  $restriction_relationship = 'deny';
7338  }
7339  $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
7340  }
7341  }
7342  elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
7343  {
7344  foreach ($restrictions as $restriction)
7345  {
7346  $restriction_relationship = null;
7347  $restriction_type = null;
7348  $restriction_value = null;
7349  if (isset($restriction['attribs']['']['relationship']))
7350  {
7351  $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
7352  }
7353  if (isset($restriction['attribs']['']['type']))
7354  {
7355  $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
7356  }
7357  if (isset($restriction['data']))
7358  {
7359  $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7360  }
7361  $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
7362  }
7363  }
7364  elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
7365  {
7366  foreach ($restrictions as $restriction)
7367  {
7368  $restriction_relationship = 'allow';
7369  $restriction_type = null;
7370  $restriction_value = 'itunes';
7371  if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
7372  {
7373  $restriction_relationship = 'deny';
7374  }
7375  $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
7376  }
7377  }
7378  if (is_array($restrictions_parent))
7379  {
7380  $restrictions_parent = array_values(array_unique($restrictions_parent));
7381  }
7382  else
7383  {
7384  $restrictions_parent = array(new SimplePie_Restriction('allow', null, 'default'));
7385  }
7386  // THUMBNAILS
7387  if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
7388  {
7389  foreach ($thumbnails as $thumbnail)
7390  {
7391  if (isset($thumbnail['attribs']['']['url']))
7392  {
7393  $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
7394  }
7395  }
7396  }
7397  elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
7398  {
7399  foreach ($thumbnails as $thumbnail)
7400  {
7401  if (isset($thumbnail['attribs']['']['url']))
7402  {
7403  $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
7404  }
7405  }
7406  }
7407  // TITLES
7408  if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
7409  {
7410  if (isset($title_parent[0]['data']))
7411  {
7412  $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7413  }
7414  }
7415  elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
7416  {
7417  if (isset($title_parent[0]['data']))
7418  {
7419  $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7420  }
7421  }
7422  // Clear the memory
7423  unset($parent);
7424  // Attributes
7425  $bitrate = null;
7426  $channels = null;
7427  $duration = null;
7428  $expression = null;
7429  $framerate = null;
7430  $height = null;
7431  $javascript = null;
7432  $lang = null;
7433  $length = null;
7434  $medium = null;
7435  $samplingrate = null;
7436  $type = null;
7437  $url = null;
7438  $width = null;
7439  // Elements
7440  $captions = null;
7441  $categories = null;
7442  $copyrights = null;
7443  $credits = null;
7444  $description = null;
7445  $hashes = null;
7446  $keywords = null;
7447  $player = null;
7448  $ratings = null;
7449  $restrictions = null;
7450  $thumbnails = null;
7451  $title = null;
7452  // If we have media:group tags, loop through them.
7453  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group)
7454  {
7455  if(isset($group['child']) && isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
7456  {
7457  // If we have media:content tags, loop through them.
7458  foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
7459  {
7460  if (isset($content['attribs']['']['url']))
7461  {
7462  // Attributes
7463  $bitrate = null;
7464  $channels = null;
7465  $duration = null;
7466  $expression = null;
7467  $framerate = null;
7468  $height = null;
7469  $javascript = null;
7470  $lang = null;
7471  $length = null;
7472  $medium = null;
7473  $samplingrate = null;
7474  $type = null;
7475  $url = null;
7476  $width = null;
7477  // Elements
7478  $captions = null;
7479  $categories = null;
7480  $copyrights = null;
7481  $credits = null;
7482  $description = null;
7483  $hashes = null;
7484  $keywords = null;
7485  $player = null;
7486  $ratings = null;
7487  $restrictions = null;
7488  $thumbnails = null;
7489  $title = null;
7490  // Start checking the attributes of media:content
7491  if (isset($content['attribs']['']['bitrate']))
7492  {
7493  $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
7494  }
7495  if (isset($content['attribs']['']['channels']))
7496  {
7497  $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
7498  }
7499  if (isset($content['attribs']['']['duration']))
7500  {
7501  $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
7502  }
7503  else
7504  {
7505  $duration = $duration_parent;
7506  }
7507  if (isset($content['attribs']['']['expression']))
7508  {
7509  $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
7510  }
7511  if (isset($content['attribs']['']['framerate']))
7512  {
7513  $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
7514  }
7515  if (isset($content['attribs']['']['height']))
7516  {
7517  $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
7518  }
7519  if (isset($content['attribs']['']['lang']))
7520  {
7521  $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
7522  }
7523  if (isset($content['attribs']['']['fileSize']))
7524  {
7525  $length = ceil($content['attribs']['']['fileSize']);
7526  }
7527  if (isset($content['attribs']['']['medium']))
7528  {
7529  $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
7530  }
7531  if (isset($content['attribs']['']['samplingrate']))
7532  {
7533  $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
7534  }
7535  if (isset($content['attribs']['']['type']))
7536  {
7537  $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
7538  }
7539  if (isset($content['attribs']['']['width']))
7540  {
7541  $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
7542  }
7543  $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
7544  // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
7545  // CAPTIONS
7546  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
7547  {
7548  foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
7549  {
7550  $caption_type = null;
7551  $caption_lang = null;
7552  $caption_startTime = null;
7553  $caption_endTime = null;
7554  $caption_text = null;
7555  if (isset($caption['attribs']['']['type']))
7556  {
7557  $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
7558  }
7559  if (isset($caption['attribs']['']['lang']))
7560  {
7561  $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
7562  }
7563  if (isset($caption['attribs']['']['start']))
7564  {
7565  $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
7566  }
7567  if (isset($caption['attribs']['']['end']))
7568  {
7569  $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
7570  }
7571  if (isset($caption['data']))
7572  {
7573  $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7574  }
7575  $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
7576  }
7577  if (is_array($captions))
7578  {
7579  $captions = array_values(array_unique($captions));
7580  }
7581  }
7582  elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
7583  {
7584  foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
7585  {
7586  $caption_type = null;
7587  $caption_lang = null;
7588  $caption_startTime = null;
7589  $caption_endTime = null;
7590  $caption_text = null;
7591  if (isset($caption['attribs']['']['type']))
7592  {
7593  $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
7594  }
7595  if (isset($caption['attribs']['']['lang']))
7596  {
7597  $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
7598  }
7599  if (isset($caption['attribs']['']['start']))
7600  {
7601  $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
7602  }
7603  if (isset($caption['attribs']['']['end']))
7604  {
7605  $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
7606  }
7607  if (isset($caption['data']))
7608  {
7609  $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7610  }
7611  $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
7612  }
7613  if (is_array($captions))
7614  {
7615  $captions = array_values(array_unique($captions));
7616  }
7617  }
7618  else
7619  {
7620  $captions = $captions_parent;
7621  }
7622  // CATEGORIES
7623  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
7624  {
7625  foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
7626  {
7627  $term = null;
7628  $scheme = null;
7629  $label = null;
7630  if (isset($category['data']))
7631  {
7632  $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7633  }
7634  if (isset($category['attribs']['']['scheme']))
7635  {
7636  $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
7637  }
7638  else
7639  {
7640  $scheme = 'http://search.yahoo.com/mrss/category_schema';
7641  }
7642  if (isset($category['attribs']['']['label']))
7643  {
7644  $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
7645  }
7646  $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
7647  }
7648  }
7649  if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
7650  {
7651  foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
7652  {
7653  $term = null;
7654  $scheme = null;
7655  $label = null;
7656  if (isset($category['data']))
7657  {
7658  $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7659  }
7660  if (isset($category['attribs']['']['scheme']))
7661  {
7662  $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
7663  }
7664  else
7665  {
7666  $scheme = 'http://search.yahoo.com/mrss/category_schema';
7667  }
7668  if (isset($category['attribs']['']['label']))
7669  {
7670  $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
7671  }
7672  $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
7673  }
7674  }
7675  if (is_array($categories) && is_array($categories_parent))
7676  {
7677  $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
7678  }
7679  elseif (is_array($categories))
7680  {
7681  $categories = array_values(array_unique($categories));
7682  }
7683  elseif (is_array($categories_parent))
7684  {
7685  $categories = array_values(array_unique($categories_parent));
7686  }
7687  // COPYRIGHTS
7688  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
7689  {
7690  $copyright_url = null;
7691  $copyright_label = null;
7692  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
7693  {
7694  $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
7695  }
7696  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
7697  {
7698  $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7699  }
7700  $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
7701  }
7702  elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
7703  {
7704  $copyright_url = null;
7705  $copyright_label = null;
7706  if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
7707  {
7708  $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
7709  }
7710  if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
7711  {
7712  $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7713  }
7714  $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
7715  }
7716  else
7717  {
7718  $copyrights = $copyrights_parent;
7719  }
7720  // CREDITS
7721  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
7722  {
7723  foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
7724  {
7725  $credit_role = null;
7726  $credit_scheme = null;
7727  $credit_name = null;
7728  if (isset($credit['attribs']['']['role']))
7729  {
7730  $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
7731  }
7732  if (isset($credit['attribs']['']['scheme']))
7733  {
7734  $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
7735  }
7736  else
7737  {
7738  $credit_scheme = 'urn:ebu';
7739  }
7740  if (isset($credit['data']))
7741  {
7742  $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7743  }
7744  $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
7745  }
7746  if (is_array($credits))
7747  {
7748  $credits = array_values(array_unique($credits));
7749  }
7750  }
7751  elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
7752  {
7753  foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
7754  {
7755  $credit_role = null;
7756  $credit_scheme = null;
7757  $credit_name = null;
7758  if (isset($credit['attribs']['']['role']))
7759  {
7760  $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
7761  }
7762  if (isset($credit['attribs']['']['scheme']))
7763  {
7764  $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
7765  }
7766  else
7767  {
7768  $credit_scheme = 'urn:ebu';
7769  }
7770  if (isset($credit['data']))
7771  {
7772  $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7773  }
7774  $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
7775  }
7776  if (is_array($credits))
7777  {
7778  $credits = array_values(array_unique($credits));
7779  }
7780  }
7781  else
7782  {
7783  $credits = $credits_parent;
7784  }
7785  // DESCRIPTION
7786  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
7787  {
7788  $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7789  }
7790  elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
7791  {
7792  $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7793  }
7794  else
7795  {
7796  $description = $description_parent;
7797  }
7798  // HASHES
7799  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
7800  {
7801  foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
7802  {
7803  $value = null;
7804  $algo = null;
7805  if (isset($hash['data']))
7806  {
7807  $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7808  }
7809  if (isset($hash['attribs']['']['algo']))
7810  {
7811  $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
7812  }
7813  else
7814  {
7815  $algo = 'md5';
7816  }
7817  $hashes[] = $algo.':'.$value;
7818  }
7819  if (is_array($hashes))
7820  {
7821  $hashes = array_values(array_unique($hashes));
7822  }
7823  }
7824  elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
7825  {
7826  foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
7827  {
7828  $value = null;
7829  $algo = null;
7830  if (isset($hash['data']))
7831  {
7832  $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7833  }
7834  if (isset($hash['attribs']['']['algo']))
7835  {
7836  $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
7837  }
7838  else
7839  {
7840  $algo = 'md5';
7841  }
7842  $hashes[] = $algo.':'.$value;
7843  }
7844  if (is_array($hashes))
7845  {
7846  $hashes = array_values(array_unique($hashes));
7847  }
7848  }
7849  else
7850  {
7851  $hashes = $hashes_parent;
7852  }
7853  // KEYWORDS
7854  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
7855  {
7856  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
7857  {
7858  $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
7859  foreach ($temp as $word)
7860  {
7861  $keywords[] = trim($word);
7862  }
7863  unset($temp);
7864  }
7865  if (is_array($keywords))
7866  {
7867  $keywords = array_values(array_unique($keywords));
7868  }
7869  }
7870  elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
7871  {
7872  if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
7873  {
7874  $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
7875  foreach ($temp as $word)
7876  {
7877  $keywords[] = trim($word);
7878  }
7879  unset($temp);
7880  }
7881  if (is_array($keywords))
7882  {
7883  $keywords = array_values(array_unique($keywords));
7884  }
7885  }
7886  else
7887  {
7888  $keywords = $keywords_parent;
7889  }
7890  // PLAYER
7891  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
7892  {
7893  $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
7894  }
7895  elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
7896  {
7897  $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
7898  }
7899  else
7900  {
7901  $player = $player_parent;
7902  }
7903  // RATINGS
7904  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
7905  {
7906  foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
7907  {
7908  $rating_scheme = null;
7909  $rating_value = null;
7910  if (isset($rating['attribs']['']['scheme']))
7911  {
7912  $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
7913  }
7914  else
7915  {
7916  $rating_scheme = 'urn:simple';
7917  }
7918  if (isset($rating['data']))
7919  {
7920  $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7921  }
7922  $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
7923  }
7924  if (is_array($ratings))
7925  {
7926  $ratings = array_values(array_unique($ratings));
7927  }
7928  }
7929  elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
7930  {
7931  foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
7932  {
7933  $rating_scheme = null;
7934  $rating_value = null;
7935  if (isset($rating['attribs']['']['scheme']))
7936  {
7937  $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
7938  }
7939  else
7940  {
7941  $rating_scheme = 'urn:simple';
7942  }
7943  if (isset($rating['data']))
7944  {
7945  $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7946  }
7947  $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
7948  }
7949  if (is_array($ratings))
7950  {
7951  $ratings = array_values(array_unique($ratings));
7952  }
7953  }
7954  else
7955  {
7956  $ratings = $ratings_parent;
7957  }
7958  // RESTRICTIONS
7959  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
7960  {
7961  foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
7962  {
7963  $restriction_relationship = null;
7964  $restriction_type = null;
7965  $restriction_value = null;
7966  if (isset($restriction['attribs']['']['relationship']))
7967  {
7968  $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
7969  }
7970  if (isset($restriction['attribs']['']['type']))
7971  {
7972  $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
7973  }
7974  if (isset($restriction['data']))
7975  {
7976  $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
7977  }
7978  $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
7979  }
7980  if (is_array($restrictions))
7981  {
7982  $restrictions = array_values(array_unique($restrictions));
7983  }
7984  }
7985  elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
7986  {
7987  foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
7988  {
7989  $restriction_relationship = null;
7990  $restriction_type = null;
7991  $restriction_value = null;
7992  if (isset($restriction['attribs']['']['relationship']))
7993  {
7994  $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
7995  }
7996  if (isset($restriction['attribs']['']['type']))
7997  {
7998  $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
7999  }
8000  if (isset($restriction['data']))
8001  {
8002  $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
8003  }
8004  $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
8005  }
8006  if (is_array($restrictions))
8007  {
8008  $restrictions = array_values(array_unique($restrictions));
8009  }
8010  }
8011  else
8012  {
8013  $restrictions = $restrictions_parent;
8014  }
8015  // THUMBNAILS
8016  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
8017  {
8018  foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
8019  {
8020  $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
8021  }
8022  if (is_array($thumbnails))
8023  {
8024  $thumbnails = array_values(array_unique($thumbnails));
8025  }
8026  }
8027  elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
8028  {
8029  foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
8030  {
8031  $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
8032  }
8033  if (is_array($thumbnails))
8034  {
8035  $thumbnails = array_values(array_unique($thumbnails));
8036  }
8037  }
8038  else
8039  {
8040  $thumbnails = $thumbnails_parent;
8041  }
8042  // TITLES
8043  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
8044  {
8045  $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
8046  }
8047  elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
8048  {
8049  $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
8050  }
8051  else
8052  {
8053  $title = $title_parent;
8054  }
8055  $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width));
8056  }
8057  }
8058  }
8059  }
8060  // If we have standalone media:content tags, loop through them.
8061  if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
8062  {
8063  foreach ((array) $this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
8064  {
8065  if (isset($content['attribs']['']['url']) || isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
8066  {
8067  // Attributes
8068  $bitrate = null;
8069  $channels = null;
8070  $duration = null;
8071  $expression = null;
8072  $framerate = null;
8073  $height = null;
8074  $javascript = null;
8075  $lang = null;
8076  $length = null;
8077  $medium = null;
8078  $samplingrate = null;
8079  $type = null;
8080  $url = null;
8081  $width = null;
8082  // Elements
8083  $captions = null;
8084  $categories = null;
8085  $copyrights = null;
8086  $credits = null;
8087  $description = null;
8088  $hashes = null;
8089  $keywords = null;
8090  $player = null;
8091  $ratings = null;
8092  $restrictions = null;
8093  $thumbnails = null;
8094  $title = null;
8095  // Start checking the attributes of media:content
8096  if (isset($content['attribs']['']['bitrate']))
8097  {
8098  $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
8099  }
8100  if (isset($content['attribs']['']['channels']))
8101  {
8102  $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
8103  }
8104  if (isset($content['attribs']['']['duration']))
8105  {
8106  $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
8107  }
8108  else
8109  {
8110  $duration = $duration_parent;
8111  }
8112  if (isset($content['attribs']['']['expression']))
8113  {
8114  $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
8115  }
8116  if (isset($content['attribs']['']['framerate']))
8117  {
8118  $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
8119  }
8120  if (isset($content['attribs']['']['height']))
8121  {
8122  $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
8123  }
8124  if (isset($content['attribs']['']['lang']))
8125  {
8126  $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
8127  }
8128  if (isset($content['attribs']['']['fileSize']))
8129  {
8130  $length = ceil($content['attribs']['']['fileSize']);
8131  }
8132  if (isset($content['attribs']['']['medium']))
8133  {
8134  $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
8135  }
8136  if (isset($content['attribs']['']['samplingrate']))
8137  {
8138  $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
8139  }
8140  if (isset($content['attribs']['']['type']))
8141  {
8142  $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
8143  }
8144  if (isset($content['attribs']['']['width']))
8145  {
8146  $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
8147  }
8148  if (isset($content['attribs']['']['url']))
8149  {
8150  $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
8151  }
8152  // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
8153  // CAPTIONS
8154  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
8155  {
8156  foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
8157  {
8158  $caption_type = null;
8159  $caption_lang = null;
8160  $caption_startTime = null;
8161  $caption_endTime = null;
8162  $caption_text = null;
8163  if (isset($caption['attribs']['']['type']))
8164  {
8165  $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
8166  }
8167  if (isset($caption['attribs']['']['lang']))
8168  {
8169  $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
8170  }
8171  if (isset($caption['attribs']['']['start']))
8172  {
8173  $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
8174  }
8175  if (isset($caption['attribs']['']['end']))
8176  {
8177  $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
8178  }
8179  if (isset($caption['data']))
8180  {
8181  $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
8182  }
8183  $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
8184  }
8185  if (is_array($captions))
8186  {
8187  $captions = array_values(array_unique($captions));
8188  }
8189  }
8190  else
8191  {
8192  $captions = $captions_parent;
8193  }
8194  // CATEGORIES
8195  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
8196  {
8197  foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
8198  {
8199  $term = null;
8200  $scheme = null;
8201  $label = null;
8202  if (isset($category['data']))
8203  {
8204  $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
8205  }
8206  if (isset($category['attribs']['']['scheme']))
8207  {
8208  $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
8209  }
8210  else
8211  {
8212  $scheme = 'http://search.yahoo.com/mrss/category_schema';
8213  }
8214  if (isset($category['attribs']['']['label']))
8215  {
8216  $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
8217  }
8218  $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
8219  }
8220  }
8221  if (is_array($categories) && is_array($categories_parent))
8222  {
8223  $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
8224  }
8225  elseif (is_array($categories))
8226  {
8227  $categories = array_values(array_unique($categories));
8228  }
8229  elseif (is_array($categories_parent))
8230  {
8231  $categories = array_values(array_unique($categories_parent));
8232  }
8233  else
8234  {
8235  $categories = null;
8236  }
8237  // COPYRIGHTS
8238  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
8239  {
8240  $copyright_url = null;
8241  $copyright_label = null;
8242  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
8243  {
8244  $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
8245  }
8246  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
8247  {
8248  $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
8249  }
8250  $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
8251  }
8252  else
8253  {
8254  $copyrights = $copyrights_parent;
8255  }
8256  // CREDITS
8257  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
8258  {
8259  foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
8260  {
8261  $credit_role = null;
8262  $credit_scheme = null;
8263  $credit_name = null;
8264  if (isset($credit['attribs']['']['role']))
8265  {
8266  $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
8267  }
8268  if (isset($credit['attribs']['']['scheme']))
8269  {
8270  $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
8271  }
8272  else
8273  {
8274  $credit_scheme = 'urn:ebu';
8275  }
8276  if (isset($credit['data']))
8277  {
8278  $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
8279  }
8280  $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
8281  }
8282  if (is_array($credits))
8283  {
8284  $credits = array_values(array_unique($credits));
8285  }
8286  }
8287  else
8288  {
8289  $credits = $credits_parent;
8290  }
8291  // DESCRIPTION
8292  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
8293  {
8294  $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
8295  }
8296  else
8297  {
8298  $description = $description_parent;
8299  }
8300  // HASHES
8301  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
8302  {
8303  foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
8304  {
8305  $value = null;
8306  $algo = null;
8307  if (isset($hash['data']))
8308  {
8309  $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
8310  }
8311  if (isset($hash['attribs']['']['algo']))
8312  {
8313  $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
8314  }
8315  else
8316  {
8317  $algo = 'md5';
8318  }
8319  $hashes[] = $algo.':'.$value;
8320  }
8321  if (is_array($hashes))
8322  {
8323  $hashes = array_values(array_unique($hashes));
8324  }
8325  }
8326  else
8327  {
8328  $hashes = $hashes_parent;
8329  }
8330  // KEYWORDS
8331  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
8332  {
8333  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
8334  {
8335  $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
8336  foreach ($temp as $word)
8337  {
8338  $keywords[] = trim($word);
8339  }
8340  unset($temp);
8341  }
8342  if (is_array($keywords))
8343  {
8344  $keywords = array_values(array_unique($keywords));
8345  }
8346  }
8347  else
8348  {
8349  $keywords = $keywords_parent;
8350  }
8351  // PLAYER
8352  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
8353  {
8354  $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
8355  }
8356  else
8357  {
8358  $player = $player_parent;
8359  }
8360  // RATINGS
8361  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
8362  {
8363  foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
8364  {
8365  $rating_scheme = null;
8366  $rating_value = null;
8367  if (isset($rating['attribs']['']['scheme']))
8368  {
8369  $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
8370  }
8371  else
8372  {
8373  $rating_scheme = 'urn:simple';
8374  }
8375  if (isset($rating['data']))
8376  {
8377  $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
8378  }
8379  $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
8380  }
8381  if (is_array($ratings))
8382  {
8383  $ratings = array_values(array_unique($ratings));
8384  }
8385  }
8386  else
8387  {
8388  $ratings = $ratings_parent;
8389  }
8390  // RESTRICTIONS
8391  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
8392  {
8393  foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
8394  {
8395  $restriction_relationship = null;
8396  $restriction_type = null;
8397  $restriction_value = null;
8398  if (isset($restriction['attribs']['']['relationship']))
8399  {
8400  $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
8401  }
8402  if (isset($restriction['attribs']['']['type']))
8403  {
8404  $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
8405  }
8406  if (isset($restriction['data']))
8407  {
8408  $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
8409  }
8410  $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
8411  }
8412  if (is_array($restrictions))
8413  {
8414  $restrictions = array_values(array_unique($restrictions));
8415  }
8416  }
8417  else
8418  {
8419  $restrictions = $restrictions_parent;
8420  }
8421  // THUMBNAILS
8422  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
8423  {
8424  foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
8425  {
8426  $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
8427  }
8428  if (is_array($thumbnails))
8429  {
8430  $thumbnails = array_values(array_unique($thumbnails));
8431  }
8432  }
8433  else
8434  {
8435  $thumbnails = $thumbnails_parent;
8436  }
8437  // TITLES
8438  if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
8439  {
8440  $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
8441  }
8442  else
8443  {
8444  $title = $title_parent;
8445  }
8446  $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width));
8447  }
8448  }
8449  }
8450  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
8451  {
8452  if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
8453  {
8454  // Attributes
8455  $bitrate = null;
8456  $channels = null;
8457  $duration = null;
8458  $expression = null;
8459  $framerate = null;
8460  $height = null;
8461  $javascript = null;
8462  $lang = null;
8463  $length = null;
8464  $medium = null;
8465  $samplingrate = null;
8466  $type = null;
8467  $url = null;
8468  $width = null;
8469  $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
8470  if (isset($link['attribs']['']['type']))
8471  {
8472  $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
8473  }
8474  if (isset($link['attribs']['']['length']))
8475  {
8476  $length = ceil($link['attribs']['']['length']);
8477  }
8478  // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
8479  $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
8480  }
8481  }
8482  foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
8483  {
8484  if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
8485  {
8486  // Attributes
8487  $bitrate = null;
8488  $channels = null;
8489  $duration = null;
8490  $expression = null;
8491  $framerate = null;
8492  $height = null;
8493  $javascript = null;
8494  $lang = null;
8495  $length = null;
8496  $medium = null;
8497  $samplingrate = null;
8498  $type = null;
8499  $url = null;
8500  $width = null;
8501  $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
8502  if (isset($link['attribs']['']['type']))
8503  {
8504  $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
8505  }
8506  if (isset($link['attribs']['']['length']))
8507  {
8508  $length = ceil($link['attribs']['']['length']);
8509  }
8510  // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
8511  $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
8512  }
8513  }
8514  if ($enclosure = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'enclosure'))
8515  {
8516  if (isset($enclosure[0]['attribs']['']['url']))
8517  {
8518  // Attributes
8519  $bitrate = null;
8520  $channels = null;
8521  $duration = null;
8522  $expression = null;
8523  $framerate = null;
8524  $height = null;
8525  $javascript = null;
8526  $lang = null;
8527  $length = null;
8528  $medium = null;
8529  $samplingrate = null;
8530  $type = null;
8531  $url = null;
8532  $width = null;
8533  $url = $this->sanitize($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure[0]));
8534  if (isset($enclosure[0]['attribs']['']['type']))
8535  {
8536  $type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
8537  }
8538  if (isset($enclosure[0]['attribs']['']['length']))
8539  {
8540  $length = ceil($enclosure[0]['attribs']['']['length']);
8541  }
8542  // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
8543  $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
8544  }
8545  }
8546  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))
8547  {
8548  // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
8549  $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
8550  }
8551  $this->data['enclosures'] = array_values(array_unique($this->data['enclosures']));
8552  }
8553  if (!empty($this->data['enclosures']))
8554  {
8555  return $this->data['enclosures'];
8556  }
8557  else
8558  {
8559  return null;
8560  }
8561  }
8562 
8563  public function get_latitude()
8564  {
8565  if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
8566  {
8567  return (float) $return[0]['data'];
8568  }
8569  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))
8570  {
8571  return (float) $match[1];
8572  }
8573  else
8574  {
8575  return null;
8576  }
8577  }
8578 
8579  public function get_longitude()
8580  {
8581  if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
8582  {
8583  return (float) $return[0]['data'];
8584  }
8585  elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
8586  {
8587  return (float) $return[0]['data'];
8588  }
8589  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))
8590  {
8591  return (float) $match[2];
8592  }
8593  else
8594  {
8595  return null;
8596  }
8597  }
8598 
8599  public function get_source()
8600  {
8601  if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'source'))
8602  {
8603  return $this->registry->create('Source', array($this, $return[0]));
8604  }
8605  else
8606  {
8607  return null;
8608  }
8609  }
8610 }
8612 {
8615  var $file;
8616  var $local = array();
8617  var $elsewhere = array();
8618  var $cached_entities = array();
8620  var $base;
8624  protected $registry;
8625  public function __construct(SimplePie_File $file, $timeout = 10, $useragent = null, $max_checked_feeds = 10)
8626  {
8627  $this->file = $file;
8628  $this->useragent = $useragent;
8629  $this->timeout = $timeout;
8630  $this->max_checked_feeds = $max_checked_feeds;
8631  if (class_exists('DOMDocument'))
8632  {
8633  $this->dom = new DOMDocument();
8634  set_error_handler(array('SimplePie_Misc', 'silence_errors'));
8635  $this->dom->loadHTML($this->file->body);
8636  restore_error_handler();
8637  }
8638  else
8639  {
8640  $this->dom = null;
8641  }
8642  }
8644  {
8645  $this->registry = $registry;
8646  }
8647  public function find($type = SIMPLEPIE_LOCATOR_ALL, &$working)
8648  {
8649  if ($this->is_feed($this->file))
8650  {
8651  return $this->file;
8652  }
8653  if ($this->file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
8654  {
8655  $sniffer = $this->registry->create('Content_Type_Sniffer', array($this->file));
8656  if ($sniffer->get_type() !== 'text/html')
8657  {
8658  return null;
8659  }
8660  }
8661  if ($type & ~SIMPLEPIE_LOCATOR_NONE)
8662  {
8663  $this->get_base();
8664  }
8665  if ($type & SIMPLEPIE_LOCATOR_AUTODISCOVERY && $working = $this->autodiscovery())
8666  {
8667  return $working[0];
8668  }
8670  {
8671  if ($type & SIMPLEPIE_LOCATOR_LOCAL_EXTENSION && $working = $this->extension($this->local))
8672  {
8673  return $working;
8674  }
8675  if ($type & SIMPLEPIE_LOCATOR_LOCAL_BODY && $working = $this->body($this->local))
8676  {
8677  return $working;
8678  }
8679  if ($type & SIMPLEPIE_LOCATOR_REMOTE_EXTENSION && $working = $this->extension($this->elsewhere))
8680  {
8681  return $working;
8682  }
8683  if ($type & SIMPLEPIE_LOCATOR_REMOTE_BODY && $working = $this->body($this->elsewhere))
8684  {
8685  return $working;
8686  }
8687  }
8688  return null;
8689  }
8690  public function is_feed($file)
8691  {
8692  if ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
8693  {
8694  $sniffer = $this->registry->create('Content_Type_Sniffer', array($file));
8695  $sniffed = $sniffer->get_type();
8696  if (in_array($sniffed, array('application/rss+xml', 'application/rdf+xml', 'text/rdf', 'application/atom+xml', 'text/xml', 'application/xml')))
8697  {
8698  return true;
8699  }
8700  else
8701  {
8702  return false;
8703  }
8704  }
8705  elseif ($file->method & SIMPLEPIE_FILE_SOURCE_LOCAL)
8706  {
8707  return true;
8708  }
8709  else
8710  {
8711  return false;
8712  }
8713  }
8714  public function get_base()
8715  {
8716  if ($this->dom === null)
8717  {
8718  throw new SimplePie_Exception('DOMDocument not found, unable to use locator');
8719  }
8720  $this->http_base = $this->file->url;
8721  $this->base = $this->http_base;
8722  $elements = $this->dom->getElementsByTagName('base');
8723  foreach ($elements as $element)
8724  {
8725  if ($element->hasAttribute('href'))
8726  {
8727  $base = $this->registry->call('Misc', 'absolutize_url', array(trim($element->getAttribute('href')), $this->http_base));
8728  if ($base === false)
8729  {
8730  continue;
8731  }
8732  $this->base = $base;
8733  $this->base_location = method_exists($element, 'getLineNo') ? $element->getLineNo() : 0;
8734  break;
8735  }
8736  }
8737  }
8738  public function autodiscovery()
8739  {
8740  $done = array();
8741  $feeds = array();
8742  $feeds = array_merge($feeds, $this->search_elements_by_tag('link', $done, $feeds));
8743  $feeds = array_merge($feeds, $this->search_elements_by_tag('a', $done, $feeds));
8744  $feeds = array_merge($feeds, $this->search_elements_by_tag('area', $done, $feeds));
8745  if (!empty($feeds))
8746  {
8747  return array_values($feeds);
8748  }
8749  else
8750  {
8751  return null;
8752  }
8753  }
8754  protected function search_elements_by_tag($name, &$done, $feeds)
8755  {
8756  if ($this->dom === null)
8757  {
8758  throw new SimplePie_Exception('DOMDocument not found, unable to use locator');
8759  }
8760  $links = $this->dom->getElementsByTagName($name);
8761  foreach ($links as $link)
8762  {
8763  if ($this->checked_feeds === $this->max_checked_feeds)
8764  {
8765  break;
8766  }
8767  if ($link->hasAttribute('href') && $link->hasAttribute('rel'))
8768  {
8769  $rel = array_unique($this->registry->call('Misc', 'space_seperated_tokens', array(strtolower($link->getAttribute('rel')))));
8770  $line = method_exists($link, 'getLineNo') ? $link->getLineNo() : 1;
8771  if ($this->base_location < $line)
8772  {
8773  $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->base));
8774  }
8775  else
8776  {
8777  $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->http_base));
8778  }
8779  if ($href === false)
8780  {
8781  continue;
8782  }
8783  if (!in_array($href, $done) && in_array('feed', $rel) || (in_array('alternate', $rel) && !in_array('stylesheet', $rel) && $link->hasAttribute('type') && in_array(strtolower($this->registry->call('Misc', 'parse_mime', array($link->getAttribute('type')))), array('application/rss+xml', 'application/atom+xml'))) && !isset($feeds[$href]))
8784  {
8785  $this->checked_feeds++;
8786  $headers = array(
8787  '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',
8788  );
8789  $feed = $this->registry->create('File', array($href, $this->timeout, 5, $headers, $this->useragent));
8790  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))
8791  {
8792  $feeds[$href] = $feed;
8793  }
8794  }
8795  $done[] = $href;
8796  }
8797  }
8798  return $feeds;
8799  }
8800  public function get_links()
8801  {
8802  if ($this->dom === null)
8803  {
8804  throw new SimplePie_Exception('DOMDocument not found, unable to use locator');
8805  }
8806  $links = $this->dom->getElementsByTagName('a');
8807  foreach ($links as $link)
8808  {
8809  if ($link->hasAttribute('href'))
8810  {
8811  $href = trim($link->getAttribute('href'));
8812  $parsed = $this->registry->call('Misc', 'parse_url', array($href));
8813  if ($parsed['scheme'] === '' || preg_match('/^(http(s)|feed)?$/i', $parsed['scheme']))
8814  {
8815  if ($this->base_location < $link->getLineNo())
8816  {
8817  $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->base));
8818  }
8819  else
8820  {
8821  $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->http_base));
8822  }
8823  if ($href === false)
8824  {
8825  continue;
8826  }
8827  $current = $this->registry->call('Misc', 'parse_url', array($this->file->url));
8828  if ($parsed['authority'] === '' || $parsed['authority'] === $current['authority'])
8829  {
8830  $this->local[] = $href;
8831  }
8832  else
8833  {
8834  $this->elsewhere[] = $href;
8835  }
8836  }
8837  }
8838  }
8839  $this->local = array_unique($this->local);
8840  $this->elsewhere = array_unique($this->elsewhere);
8841  if (!empty($this->local) || !empty($this->elsewhere))
8842  {
8843  return true;
8844  }
8845  return null;
8846  }
8847  public function extension(&$array)
8848  {
8849  foreach ($array as $key => $value)
8850  {
8851  if ($this->checked_feeds === $this->max_checked_feeds)
8852  {
8853  break;
8854  }
8855  if (in_array(strtolower(strrchr($value, '.')), array('.rss', '.rdf', '.atom', '.xml')))
8856  {
8857  $this->checked_feeds++;
8858  $headers = array(
8859  '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',
8860  );
8861  $feed = $this->registry->create('File', array($value, $this->timeout, 5, $headers, $this->useragent));
8862  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))
8863  {
8864  return $feed;
8865  }
8866  else
8867  {
8868  unset($array[$key]);
8869  }
8870  }
8871  }
8872  return null;
8873  }
8874  public function body(&$array)
8875  {
8876  foreach ($array as $key => $value)
8877  {
8878  if ($this->checked_feeds === $this->max_checked_feeds)
8879  {
8880  break;
8881  }
8882  if (preg_match('/(rss|rdf|atom|xml)/i', $value))
8883  {
8884  $this->checked_feeds++;
8885  $headers = array(
8886  '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',
8887  );
8888  $feed = $this->registry->create('File', array($value, $this->timeout, 5, null, $this->useragent));
8889  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))
8890  {
8891  return $feed;
8892  }
8893  else
8894  {
8895  unset($array[$key]);
8896  }
8897  }
8898  }
8899  return null;
8900  }
8901 }
8903 {
8904  public static function time_hms($seconds)
8905  {
8906  $time = '';
8907  $hours = floor($seconds / 3600);
8908  $remainder = $seconds % 3600;
8909  if ($hours > 0)
8910  {
8911  $time .= $hours.':';
8912  }
8913  $minutes = floor($remainder / 60);
8914  $seconds = $remainder % 60;
8915  if ($minutes < 10 && $hours > 0)
8916  {
8917  $minutes = '0' . $minutes;
8918  }
8919  if ($seconds < 10)
8920  {
8921  $seconds = '0' . $seconds;
8922  }
8923  $time .= $minutes.':';
8924  $time .= $seconds;
8925  return $time;
8926  }
8927  public static function absolutize_url($relative, $base)
8928  {
8929  $iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative);
8930  if ($iri === false)
8931  {
8932  return false;
8933  }
8934  return $iri->get_uri();
8935  }
8936 
8937  public static function get_element($realname, $string)
8938  {
8939  $return = array();
8940  $name = preg_quote($realname, '/');
8941  if (preg_match_all("/<($name)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$name>|(\/)?>)/siU", $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE))
8942  {
8943  for ($i = 0, $total_matches = count($matches); $i < $total_matches; $i++)
8944  {
8945  $return[$i]['tag'] = $realname;
8946  $return[$i]['full'] = $matches[$i][0][0];
8947  $return[$i]['offset'] = $matches[$i][0][1];
8948  if (strlen($matches[$i][3][0]) <= 2)
8949  {
8950  $return[$i]['self_closing'] = true;
8951  }
8952  else
8953  {
8954  $return[$i]['self_closing'] = false;
8955  $return[$i]['content'] = $matches[$i][4][0];
8956  }
8957  $return[$i]['attribs'] = array();
8958  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))
8959  {
8960  for ($j = 0, $total_attribs = count($attribs); $j < $total_attribs; $j++)
8961  {
8962  if (count($attribs[$j]) === 2)
8963  {
8964  $attribs[$j][2] = $attribs[$j][1];
8965  }
8966  $return[$i]['attribs'][strtolower($attribs[$j][1])]['data'] = SimplePie_Misc::entities_decode(end($attribs[$j]), 'UTF-8');
8967  }
8968  }
8969  }
8970  }
8971  return $return;
8972  }
8973  public static function element_implode($element)
8974  {
8975  $full = "<$element[tag]";
8976  foreach ($element['attribs'] as $key => $value)
8977  {
8978  $key = strtolower($key);
8979  $full .= " $key=\"" . htmlspecialchars($value['data']) . '"';
8980  }
8981  if ($element['self_closing'])
8982  {
8983  $full .= ' />';
8984  }
8985  else
8986  {
8987  $full .= ">$element[content]</$element[tag]>";
8988  }
8989  return $full;
8990  }
8991  public static function error($message, $level, $file, $line)
8992  {
8993  if ((ini_get('error_reporting') & $level) > 0)
8994  {
8995  switch ($level)
8996  {
8997  case E_USER_ERROR:
8998  $note = 'PHP Error';
8999  break;
9000  case E_USER_WARNING:
9001  $note = 'PHP Warning';
9002  break;
9003  case E_USER_NOTICE:
9004  $note = 'PHP Notice';
9005  break;
9006  default:
9007  $note = 'Unknown Error';
9008  break;
9009  }
9010  $log_error = true;
9011  if (!function_exists('error_log'))
9012  {
9013  $log_error = false;
9014  }
9015  $log_file = @ini_get('error_log');
9016  if (!empty($log_file) && ('syslog' !== $log_file) && !@is_writable($log_file))
9017  {
9018  $log_error = false;
9019  }
9020  if ($log_error)
9021  {
9022  @error_log("$note: $message in $file on line $line", 0);
9023  }
9024  }
9025  return $message;
9026  }
9027  public static function fix_protocol($url, $http = 1)
9028  {
9030  $parsed = SimplePie_Misc::parse_url($url);
9031  if ($parsed['scheme'] !== '' && $parsed['scheme'] !== 'http' && $parsed['scheme'] !== 'https')
9032  {
9033  return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['authority'], $parsed['path'], $parsed['query'], $parsed['fragment']), $http);
9034  }
9035  if ($parsed['scheme'] === '' && $parsed['authority'] === '' && !file_exists($url))
9036  {
9037  return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['path'], '', $parsed['query'], $parsed['fragment']), $http);
9038  }
9039  if ($http === 2 && $parsed['scheme'] !== '')
9040  {
9041  return "feed:$url";
9042  }
9043  elseif ($http === 3 && strtolower($parsed['scheme']) === 'http')
9044  {
9045  return substr_replace($url, 'podcast', 0, 4);
9046  }
9047  elseif ($http === 4 && strtolower($parsed['scheme']) === 'http')
9048  {
9049  return substr_replace($url, 'itpc', 0, 4);
9050  }
9051  else
9052  {
9053  return $url;
9054  }
9055  }
9056  public static function parse_url($url)
9057  {
9058  $iri = new SimplePie_IRI($url);
9059  return array(
9060  'scheme' => (string) $iri->scheme,
9061  'authority' => (string) $iri->authority,
9062  'path' => (string) $iri->path,
9063  'query' => (string) $iri->query,
9064  'fragment' => (string) $iri->fragment
9065  );
9066  }
9067  public static function compress_parse_url($scheme = '', $authority = '', $path = '', $query = '', $fragment = '')
9068  {
9069  $iri = new SimplePie_IRI('');
9070  $iri->scheme = $scheme;
9071  $iri->authority = $authority;
9072  $iri->path = $path;
9073  $iri->query = $query;
9074  $iri->fragment = $fragment;
9075  return $iri->get_uri();
9076  }
9077  public static function normalize_url($url)
9078  {
9079  $iri = new SimplePie_IRI($url);
9080  return $iri->get_uri();
9081  }
9082  public static function percent_encoding_normalization($match)
9083  {
9084  $integer = hexdec($match[1]);
9085  if ($integer >= 0x41 && $integer <= 0x5A || $integer >= 0x61 && $integer <= 0x7A || $integer >= 0x30 && $integer <= 0x39 || $integer === 0x2D || $integer === 0x2E || $integer === 0x5F || $integer === 0x7E)
9086  {
9087  return chr($integer);
9088  }
9089  else
9090  {
9091  return strtoupper($match[0]);
9092  }
9093  }
9094 
9095  public static function windows_1252_to_utf8($string)
9096  {
9097  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");
9098  return strtr($string, $convert_table);
9099  }
9100 
9101  public static function change_encoding($data, $input, $output)
9102  {
9103  $input = SimplePie_Misc::encoding($input);
9105  // We fail to fail on non US-ASCII bytes
9106  if ($input === 'US-ASCII')
9107  {
9108  static $non_ascii_octects = '';
9109  if (!$non_ascii_octects)
9110  {
9111  for ($i = 0x80; $i <= 0xFF; $i++)
9112  {
9113  $non_ascii_octects .= chr($i);
9114  }
9115  }
9116  $data = substr($data, 0, strcspn($data, $non_ascii_octects));
9117  }
9118  // This is first, as behaviour of this is completely predictable
9119  if ($input === 'windows-1252' && $output === 'UTF-8')
9120  {
9122  }
9123  // This is second, as behaviour of this varies only with PHP version (the middle part of this expression checks the encoding is supported).
9124  elseif (function_exists('mb_convert_encoding') && ($return = SimplePie_Misc::change_encoding_mbstring($data, $input, $output)))
9125  {
9126  return $return;
9127  }
9128  // This is last, as behaviour of this varies with OS userland and PHP version
9129  elseif (function_exists('iconv') && ($return = SimplePie_Misc::change_encoding_iconv($data, $input, $output)))
9130  {
9131  return $return;
9132  }
9133  // If we can't do anything, just fail
9134  else
9135  {
9136  return false;
9137  }
9138  }
9139  protected static function change_encoding_mbstring($data, $input, $output)
9140  {
9141  if ($input === 'windows-949')
9142  {
9143  $input = 'EUC-KR';
9144  }
9145  if ($output === 'windows-949')
9146  {
9147  $output = 'EUC-KR';
9148  }
9149  if ($input === 'Windows-31J')
9150  {
9151  $input = 'SJIS';
9152  }
9153  if ($output === 'Windows-31J')
9154  {
9155  $output = 'SJIS';
9156  }
9157  // Check that the encoding is supported
9158  if (@mb_convert_encoding("\x80", 'UTF-16BE', $input) === "\x00\x80")
9159  {
9160  return false;
9161  }
9162  if (!in_array($input, mb_list_encodings()))
9163  {
9164  return false;
9165  }
9166  // Let's do some conversion
9167  if ($return = @mb_convert_encoding($data, $output, $input))
9168  {
9169  return $return;
9170  }
9171  return false;
9172  }
9173  protected static function change_encoding_iconv($data, $input, $output)
9174  {
9175  return @iconv($input, $output, $data);
9176  }
9177 
9178  public static function encoding($charset)
9179  {
9180  // Normalization from UTS #22
9181  switch (strtolower(preg_replace('/(?:[^a-zA-Z0-9]+|([^0-9])0+)/', '\1', $charset)))
9182  {
9183  case 'adobestandardencoding':
9184  case 'csadobestandardencoding':
9185  return 'Adobe-Standard-Encoding';
9186  case 'adobesymbolencoding':
9187  case 'cshppsmath':
9188  return 'Adobe-Symbol-Encoding';
9189  case 'ami1251':
9190  case 'amiga1251':
9191  return 'Amiga-1251';
9192  case 'ansix31101983':
9193  case 'csat5001983':
9194  case 'csiso99naplps':
9195  case 'isoir99':
9196  case 'naplps':
9197  return 'ANSI_X3.110-1983';
9198  case 'arabic7':
9199  case 'asmo449':
9200  case 'csiso89asmo449':
9201  case 'iso9036':
9202  case 'isoir89':
9203  return 'ASMO_449';
9204  case 'big5':
9205  case 'csbig5':
9206  return 'Big5';
9207  case 'big5hkscs':
9208  return 'Big5-HKSCS';
9209  case 'bocu1':
9210  case 'csbocu1':
9211  return 'BOCU-1';
9212  case 'brf':
9213  case 'csbrf':
9214  return 'BRF';
9215  case 'bs4730':
9216  case 'csiso4unitedkingdom':
9217  case 'gb':
9218  case 'iso646gb':
9219  case 'isoir4':
9220  case 'uk':
9221  return 'BS_4730';
9222  case 'bsviewdata':
9223  case 'csiso47bsviewdata':
9224  case 'isoir47':
9225  return 'BS_viewdata';
9226  case 'cesu8':
9227  case 'cscesu8':
9228  return 'CESU-8';
9229  case 'ca':
9230  case 'csa71':
9231  case 'csaz243419851':
9232  case 'csiso121canadian1':
9233  case 'iso646ca':
9234  case 'isoir121':
9235  return 'CSA_Z243.4-1985-1';
9236  case 'csa72':
9237  case 'csaz243419852':
9238  case 'csiso122canadian2':
9239  case 'iso646ca2':
9240  case 'isoir122':
9241  return 'CSA_Z243.4-1985-2';
9242  case 'csaz24341985gr':
9243  case 'csiso123csaz24341985gr':
9244  case 'isoir123':
9245  return 'CSA_Z243.4-1985-gr';
9246  case 'csiso139csn369103':
9247  case 'csn369103':
9248  case 'isoir139':
9249  return 'CSN_369103';
9250  case 'csdecmcs':
9251  case 'dec':
9252  case 'decmcs':
9253  return 'DEC-MCS';
9254  case 'csiso21german':
9255  case 'de':
9256  case 'din66003':
9257  case 'iso646de':
9258  case 'isoir21':
9259  return 'DIN_66003';
9260  case 'csdkus':
9261  case 'dkus':
9262  return 'dk-us';
9263  case 'csiso646danish':
9264  case 'dk':
9265  case 'ds2089':
9266  case 'iso646dk':
9267  return 'DS_2089';
9268  case 'csibmebcdicatde':
9269  case 'ebcdicatde':
9270  return 'EBCDIC-AT-DE';
9271  case 'csebcdicatdea':
9272  case 'ebcdicatdea':
9273  return 'EBCDIC-AT-DE-A';
9274  case 'csebcdiccafr':
9275  case 'ebcdiccafr':
9276  return 'EBCDIC-CA-FR';
9277  case 'csebcdicdkno':
9278  case 'ebcdicdkno':
9279  return 'EBCDIC-DK-NO';
9280  case 'csebcdicdknoa':
9281  case 'ebcdicdknoa':
9282  return 'EBCDIC-DK-NO-A';
9283  case 'csebcdices':
9284  case 'ebcdices':
9285  return 'EBCDIC-ES';
9286  case 'csebcdicesa':
9287  case 'ebcdicesa':
9288  return 'EBCDIC-ES-A';
9289  case 'csebcdicess':
9290  case 'ebcdicess':
9291  return 'EBCDIC-ES-S';
9292  case 'csebcdicfise':
9293  case 'ebcdicfise':
9294  return 'EBCDIC-FI-SE';
9295  case 'csebcdicfisea':
9296  case 'ebcdicfisea':
9297  return 'EBCDIC-FI-SE-A';
9298  case 'csebcdicfr':
9299  case 'ebcdicfr':
9300  return 'EBCDIC-FR';
9301  case 'csebcdicit':
9302  case 'ebcdicit':
9303  return 'EBCDIC-IT';
9304  case 'csebcdicpt':
9305  case 'ebcdicpt':
9306  return 'EBCDIC-PT';
9307  case 'csebcdicuk':
9308  case 'ebcdicuk':
9309  return 'EBCDIC-UK';
9310  case 'csebcdicus':
9311  case 'ebcdicus':
9312  return 'EBCDIC-US';
9313  case 'csiso111ecmacyrillic':
9314  case 'ecmacyrillic':
9315  case 'isoir111':
9316  case 'koi8e':
9317  return 'ECMA-cyrillic';
9318  case 'csiso17spanish':
9319  case 'es':
9320  case 'iso646es':
9321  case 'isoir17':
9322  return 'ES';
9323  case 'csiso85spanish2':
9324  case 'es2':
9325  case 'iso646es2':
9326  case 'isoir85':
9327  return 'ES2';
9328  case 'cseucpkdfmtjapanese':
9329  case 'eucjp':
9330  case 'extendedunixcodepackedformatforjapanese':
9331  return 'EUC-JP';
9332  case 'cseucfixwidjapanese':
9333  case 'extendedunixcodefixedwidthforjapanese':
9334  return 'Extended_UNIX_Code_Fixed_Width_for_Japanese';
9335  case 'gb18030':
9336  return 'GB18030';
9337  case 'chinese':
9338  case 'cp936':
9339  case 'csgb2312':
9340  case 'csiso58gb231280':
9341  case 'gb2312':
9342  case 'gb231280':
9343  case 'gbk':
9344  case 'isoir58':
9345  case 'ms936':
9346  case 'windows936':
9347  return 'GBK';
9348  case 'cn':
9349  case 'csiso57gb1988':
9350  case 'gb198880':
9351  case 'iso646cn':
9352  case 'isoir57':
9353  return 'GB_1988-80';
9354  case 'csiso153gost1976874':
9355  case 'gost1976874':
9356  case 'isoir153':
9357  case 'stsev35888':
9358  return 'GOST_19768-74';
9359  case 'csiso150':
9360  case 'csiso150greekccitt':
9361  case 'greekccitt':
9362  case 'isoir150':
9363  return 'greek-ccitt';
9364  case 'csiso88greek7':
9365  case 'greek7':
9366  case 'isoir88':
9367  return 'greek7';
9368  case 'csiso18greek7old':
9369  case 'greek7old':
9370  case 'isoir18':
9371  return 'greek7-old';
9372  case 'cshpdesktop':
9373  case 'hpdesktop':
9374  return 'HP-DeskTop';
9375  case 'cshplegal':
9376  case 'hplegal':
9377  return 'HP-Legal';
9378  case 'cshpmath8':
9379  case 'hpmath8':
9380  return 'HP-Math8';
9381  case 'cshppifont':
9382  case 'hppifont':
9383  return 'HP-Pi-font';
9384  case 'cshproman8':
9385  case 'hproman8':
9386  case 'r8':
9387  case 'roman8':
9388  return 'hp-roman8';
9389  case 'hzgb2312':
9390  return 'HZ-GB-2312';
9391  case 'csibmsymbols':
9392  case 'ibmsymbols':
9393  return 'IBM-Symbols';
9394  case 'csibmthai':
9395  case 'ibmthai':
9396  return 'IBM-Thai';
9397  case 'cp37':
9398  case 'csibm37':
9399  case 'ebcdiccpca':
9400  case 'ebcdiccpnl':
9401  case 'ebcdiccpus':
9402  case 'ebcdiccpwt':
9403  case 'ibm37':
9404  return 'IBM037';
9405  case 'cp38':
9406  case 'csibm38':
9407  case 'ebcdicint':
9408  case 'ibm38':
9409  return 'IBM038';
9410  case 'cp273':
9411  case 'csibm273':
9412  case 'ibm273':
9413  return 'IBM273';
9414  case 'cp274':
9415  case 'csibm274':
9416  case 'ebcdicbe':
9417  case 'ibm274':
9418  return 'IBM274';
9419  case 'cp275':
9420  case 'csibm275':
9421  case 'ebcdicbr':
9422  case 'ibm275':
9423  return 'IBM275';
9424  case 'csibm277':
9425  case 'ebcdiccpdk':
9426  case 'ebcdiccpno':
9427  case 'ibm277':
9428  return 'IBM277';
9429  case 'cp278':
9430  case 'csibm278':
9431  case 'ebcdiccpfi':
9432  case 'ebcdiccpse':
9433  case 'ibm278':
9434  return 'IBM278';
9435  case 'cp280':
9436  case 'csibm280':
9437  case 'ebcdiccpit':
9438  case 'ibm280':
9439  return 'IBM280';
9440  case 'cp281':
9441  case 'csibm281':
9442  case 'ebcdicjpe':
9443  case 'ibm281':
9444  return 'IBM281';
9445  case 'cp284':
9446  case 'csibm284':
9447  case 'ebcdiccpes':
9448  case 'ibm284':
9449  return 'IBM284';
9450  case 'cp285':
9451  case 'csibm285':
9452  case 'ebcdiccpgb':
9453  case 'ibm285':
9454  return 'IBM285';
9455  case 'cp290':
9456  case 'csibm290':
9457  case 'ebcdicjpkana':
9458  case 'ibm290':
9459  return 'IBM290';
9460  case 'cp297':
9461  case 'csibm297':
9462  case 'ebcdiccpfr':
9463  case 'ibm297':
9464  return 'IBM297';
9465  case 'cp420':
9466  case 'csibm420':
9467  case 'ebcdiccpar1':
9468  case 'ibm420':
9469  return 'IBM420';
9470  case 'cp423':
9471  case 'csibm423':
9472  case 'ebcdiccpgr':
9473  case 'ibm423':
9474  return 'IBM423';
9475  case 'cp424':
9476  case 'csibm424':
9477  case 'ebcdiccphe':
9478  case 'ibm424':
9479  return 'IBM424';
9480  case '437':
9481  case 'cp437':
9482  case 'cspc8codepage437':
9483  case 'ibm437':
9484  return 'IBM437';
9485  case 'cp500':
9486  case 'csibm500':
9487  case 'ebcdiccpbe':
9488  case 'ebcdiccpch':
9489  case 'ibm500':
9490  return 'IBM500';
9491  case 'cp775':
9492  case 'cspc775baltic':
9493  case 'ibm775':
9494  return 'IBM775';
9495  case '850':
9496  case 'cp850':
9497  case 'cspc850multilingual':
9498  case 'ibm850':
9499  return 'IBM850';
9500  case '851':
9501  case 'cp851':
9502  case 'csibm851':
9503  case 'ibm851':
9504  return 'IBM851';
9505  case '852':
9506  case 'cp852':
9507  case 'cspcp852':
9508  case 'ibm852':
9509  return 'IBM852';
9510  case '855':
9511  case 'cp855':
9512  case 'csibm855':
9513  case 'ibm855':
9514  return 'IBM855';
9515  case '857':
9516  case 'cp857':
9517  case 'csibm857':
9518  case 'ibm857':
9519  return 'IBM857';
9520  case 'ccsid858':
9521  case 'cp858':
9522  case 'ibm858':
9523  case 'pcmultilingual850euro':
9524  return 'IBM00858';
9525  case '860':
9526  case 'cp860':
9527  case 'csibm860':
9528  case 'ibm860':
9529  return 'IBM860';
9530  case '861':
9531  case 'cp861':
9532  case 'cpis':
9533  case 'csibm861':
9534  case 'ibm861':
9535  return 'IBM861';
9536  case '862':
9537  case 'cp862':
9538  case 'cspc862latinhebrew':
9539  case 'ibm862':
9540  return 'IBM862';
9541  case '863':
9542  case 'cp863':
9543  case 'csibm863':
9544  case 'ibm863':
9545  return 'IBM863';
9546  case 'cp864':
9547  case 'csibm864':
9548  case 'ibm864':
9549  return 'IBM864';
9550  case '865':
9551  case 'cp865':
9552  case 'csibm865':
9553  case 'ibm865':
9554  return 'IBM865';
9555  case '866':
9556  case 'cp866':
9557  case 'csibm866':
9558  case 'ibm866':
9559  return 'IBM866';
9560  case 'cp868':
9561  case 'cpar':
9562  case 'csibm868':
9563  case 'ibm868':
9564  return 'IBM868';
9565  case '869':
9566  case 'cp869':
9567  case 'cpgr':
9568  case 'csibm869':
9569  case 'ibm869':
9570  return 'IBM869';
9571  case 'cp870':
9572  case 'csibm870':
9573  case 'ebcdiccproece':
9574  case 'ebcdiccpyu':
9575  case 'ibm870':
9576  return 'IBM870';
9577  case 'cp871':
9578  case 'csibm871':
9579  case 'ebcdiccpis':
9580  case 'ibm871':
9581  return 'IBM871';
9582  case 'cp880':
9583  case 'csibm880':
9584  case 'ebcdiccyrillic':
9585  case 'ibm880':
9586  return 'IBM880';
9587  case 'cp891':
9588  case 'csibm891':
9589  case 'ibm891':
9590  return 'IBM891';
9591  case 'cp903':
9592  case 'csibm903':
9593  case 'ibm903':
9594  return 'IBM903';
9595  case '904':
9596  case 'cp904':
9597  case 'csibbm904':
9598  case 'ibm904':
9599  return 'IBM904';
9600  case 'cp905':
9601  case 'csibm905':
9602  case 'ebcdiccptr':
9603  case 'ibm905':
9604  return 'IBM905';
9605  case 'cp918':
9606  case 'csibm918':
9607  case 'ebcdiccpar2':
9608  case 'ibm918':
9609  return 'IBM918';
9610  case 'ccsid924':
9611  case 'cp924':
9612  case 'ebcdiclatin9euro':
9613  case 'ibm924':
9614  return 'IBM00924';
9615  case 'cp1026':
9616  case 'csibm1026':
9617  case 'ibm1026':
9618  return 'IBM1026';
9619  case 'ibm1047':
9620  return 'IBM1047';
9621  case 'ccsid1140':
9622  case 'cp1140':
9623  case 'ebcdicus37euro':
9624  case 'ibm1140':
9625  return 'IBM01140';
9626  case 'ccsid1141':
9627  case 'cp1141':
9628  case 'ebcdicde273euro':
9629  case 'ibm1141':
9630  return 'IBM01141';
9631  case 'ccsid1142':
9632  case 'cp1142':
9633  case 'ebcdicdk277euro':
9634  case 'ebcdicno277euro':
9635  case 'ibm1142':
9636  return 'IBM01142';
9637  case 'ccsid1143':
9638  case 'cp1143':
9639  case 'ebcdicfi278euro':
9640  case 'ebcdicse278euro':
9641  case 'ibm1143':
9642  return 'IBM01143';
9643  case 'ccsid1144':
9644  case 'cp1144':
9645  case 'ebcdicit280euro':
9646  case 'ibm1144':
9647  return 'IBM01144';
9648  case 'ccsid1145':
9649  case 'cp1145':
9650  case 'ebcdices284euro':
9651  case 'ibm1145':
9652  return 'IBM01145';
9653  case 'ccsid1146':
9654  case 'cp1146':
9655  case 'ebcdicgb285euro':
9656  case 'ibm1146':
9657  return 'IBM01146';
9658  case 'ccsid1147':
9659  case 'cp1147':
9660  case 'ebcdicfr297euro':
9661  case 'ibm1147':
9662  return 'IBM01147';
9663  case 'ccsid1148':
9664  case 'cp1148':
9665  case 'ebcdicinternational500euro':
9666  case 'ibm1148':
9667  return 'IBM01148';
9668  case 'ccsid1149':
9669  case 'cp1149':
9670  case 'ebcdicis871euro':
9671  case 'ibm1149':
9672  return 'IBM01149';
9673  case 'csiso143iecp271':
9674  case 'iecp271':
9675  case 'isoir143':
9676  return 'IEC_P27-1';
9677  case 'csiso49inis':
9678  case 'inis':
9679  case 'isoir49':
9680  return 'INIS';
9681  case 'csiso50inis8':
9682  case 'inis8':
9683  case 'isoir50':
9684  return 'INIS-8';
9685  case 'csiso51iniscyrillic':
9686  case 'iniscyrillic':
9687  case 'isoir51':
9688  return 'INIS-cyrillic';
9689  case 'csinvariant':
9690  case 'invariant':
9691  return 'INVARIANT';
9692  case 'iso2022cn':
9693  return 'ISO-2022-CN';
9694  case 'iso2022cnext':
9695  return 'ISO-2022-CN-EXT';
9696  case 'csiso2022jp':
9697  case 'iso2022jp':
9698  return 'ISO-2022-JP';
9699  case 'csiso2022jp2':
9700  case 'iso2022jp2':
9701  return 'ISO-2022-JP-2';
9702  case 'csiso2022kr':
9703  case 'iso2022kr':
9704  return 'ISO-2022-KR';
9705  case 'cswindows30latin1':
9706  case 'iso88591windows30latin1':
9707  return 'ISO-8859-1-Windows-3.0-Latin-1';
9708  case 'cswindows31latin1':
9709  case 'iso88591windows31latin1':
9710  return 'ISO-8859-1-Windows-3.1-Latin-1';
9711  case 'csisolatin2':
9712  case 'iso88592':
9713  case 'iso885921987':
9714  case 'isoir101':
9715  case 'l2':
9716  case 'latin2':
9717  return 'ISO-8859-2';
9718  case 'cswindows31latin2':
9719  case 'iso88592windowslatin2':
9720  return 'ISO-8859-2-Windows-Latin-2';
9721  case 'csisolatin3':
9722  case 'iso88593':
9723  case 'iso885931988':
9724  case 'isoir109':
9725  case 'l3':
9726  case 'latin3':
9727  return 'ISO-8859-3';
9728  case 'csisolatin4':
9729  case 'iso88594':
9730  case 'iso885941988':
9731  case 'isoir110':
9732  case 'l4':
9733  case 'latin4':
9734  return 'ISO-8859-4';
9735  case 'csisolatincyrillic':
9736  case 'cyrillic':
9737  case 'iso88595':
9738  case 'iso885951988':
9739  case 'isoir144':
9740  return 'ISO-8859-5';
9741  case 'arabic':
9742  case 'asmo708':
9743  case 'csisolatinarabic':
9744  case 'ecma114':
9745  case 'iso88596':
9746  case 'iso885961987':
9747  case 'isoir127':
9748  return 'ISO-8859-6';
9749  case 'csiso88596e':
9750  case 'iso88596e':
9751  return 'ISO-8859-6-E';
9752  case 'csiso88596i':
9753  case 'iso88596i':
9754  return 'ISO-8859-6-I';
9755  case 'csisolatingreek':
9756  case 'ecma118':
9757  case 'elot928':
9758  case 'greek':
9759  case 'greek8':
9760  case 'iso88597':
9761  case 'iso885971987':
9762  case 'isoir126':
9763  return 'ISO-8859-7';
9764  case 'csisolatinhebrew':
9765  case 'hebrew':
9766  case 'iso88598':
9767  case 'iso885981988':
9768  case 'isoir138':
9769  return 'ISO-8859-8';
9770  case 'csiso88598e':
9771  case 'iso88598e':
9772  return 'ISO-8859-8-E';
9773  case 'csiso88598i':
9774  case 'iso88598i':
9775  return 'ISO-8859-8-I';
9776  case 'cswindows31latin5':
9777  case 'iso88599windowslatin5':
9778  return 'ISO-8859-9-Windows-Latin-5';
9779  case 'csisolatin6':
9780  case 'iso885910':
9781  case 'iso8859101992':
9782  case 'isoir157':
9783  case 'l6':
9784  case 'latin6':
9785  return 'ISO-8859-10';
9786  case 'iso885913':
9787  return 'ISO-8859-13';
9788  case 'iso885914':
9789  case 'iso8859141998':
9790  case 'isoceltic':
9791  case 'isoir199':
9792  case 'l8':
9793  case 'latin8':
9794  return 'ISO-8859-14';
9795  case 'iso885915':
9796  case 'latin9':
9797  return 'ISO-8859-15';
9798  case 'iso885916':
9799  case 'iso8859162001':
9800  case 'isoir226':
9801  case 'l10':
9802  case 'latin10':
9803  return 'ISO-8859-16';
9804  case 'iso10646j1':
9805  return 'ISO-10646-J-1';
9806  case 'csunicode':
9807  case 'iso10646ucs2':
9808  return 'ISO-10646-UCS-2';
9809  case 'csucs4':
9810  case 'iso10646ucs4':
9811  return 'ISO-10646-UCS-4';
9812  case 'csunicodeascii':
9813  case 'iso10646ucsbasic':
9814  return 'ISO-10646-UCS-Basic';
9815  case 'csunicodelatin1':
9816  case 'iso10646':
9817  case 'iso10646unicodelatin1':
9818  return 'ISO-10646-Unicode-Latin1';
9819  case 'csiso10646utf1':
9820  case 'iso10646utf1':
9821  return 'ISO-10646-UTF-1';
9822  case 'csiso115481':
9823  case 'iso115481':
9824  case 'isotr115481':
9825  return 'ISO-11548-1';
9826  case 'csiso90':
9827  case 'isoir90':
9828  return 'iso-ir-90';
9829  case 'csunicodeibm1261':
9830  case 'isounicodeibm1261':
9831  return 'ISO-Unicode-IBM-1261';
9832  case 'csunicodeibm1264':
9833  case 'isounicodeibm1264':
9834  return 'ISO-Unicode-IBM-1264';
9835  case 'csunicodeibm1265':
9836  case 'isounicodeibm1265':
9837  return 'ISO-Unicode-IBM-1265';
9838  case 'csunicodeibm1268':
9839  case 'isounicodeibm1268':
9840  return 'ISO-Unicode-IBM-1268';
9841  case 'csunicodeibm1276':
9842  case 'isounicodeibm1276':
9843  return 'ISO-Unicode-IBM-1276';
9844  case 'csiso646basic1983':
9845  case 'iso646basic1983':
9846  case 'ref':
9847  return 'ISO_646.basic:1983';
9848  case 'csiso2intlrefversion':
9849  case 'irv':
9850  case 'iso646irv1983':
9851  case 'isoir2':
9852  return 'ISO_646.irv:1983';
9853  case 'csiso2033':
9854  case 'e13b':
9855  case 'iso20331983':
9856  case 'isoir98':
9857  return 'ISO_2033-1983';
9858  case 'csiso5427cyrillic':
9859  case 'iso5427':
9860  case 'isoir37':
9861  return 'ISO_5427';
9862  case 'iso5427cyrillic1981':
9863  case 'iso54271981':
9864  case 'isoir54':
9865  return 'ISO_5427:1981';
9866  case 'csiso5428greek':
9867  case 'iso54281980':
9868  case 'isoir55':
9869  return 'ISO_5428:1980';
9870  case 'csiso6937add':
9871  case 'iso6937225':
9872  case 'isoir152':
9873  return 'ISO_6937-2-25';
9874  case 'csisotextcomm':
9875  case 'iso69372add':
9876  case 'isoir142':
9877  return 'ISO_6937-2-add';
9878  case 'csiso8859supp':
9879  case 'iso8859supp':
9880  case 'isoir154':
9881  case 'latin125':
9882  return 'ISO_8859-supp';
9883  case 'csiso10367box':
9884  case 'iso10367box':
9885  case 'isoir155':
9886  return 'ISO_10367-box';
9887  case 'csiso15italian':
9888  case 'iso646it':
9889  case 'isoir15':
9890  case 'it':
9891  return 'IT';
9892  case 'csiso13jisc6220jp':
9893  case 'isoir13':
9894  case 'jisc62201969':
9895  case 'jisc62201969jp':
9896  case 'katakana':
9897  case 'x2017':
9898  return 'JIS_C6220-1969-jp';
9899  case 'csiso14jisc6220ro':
9900  case 'iso646jp':
9901  case 'isoir14':
9902  case 'jisc62201969ro':
9903  case 'jp':
9904  return 'JIS_C6220-1969-ro';
9905  case 'csiso42jisc62261978':
9906  case 'isoir42':
9907  case 'jisc62261978':
9908  return 'JIS_C6226-1978';
9909  case 'csiso87jisx208':
9910  case 'isoir87':
9911  case 'jisc62261983':
9912  case 'jisx2081983':
9913  case 'x208':
9914  return 'JIS_C6226-1983';
9915  case 'csiso91jisc62291984a':
9916  case 'isoir91':
9917  case 'jisc62291984a':
9918  case 'jpocra':
9919  return 'JIS_C6229-1984-a';
9920  case 'csiso92jisc62991984b':
9921  case 'iso646jpocrb':
9922  case 'isoir92':
9923  case 'jisc62291984b':
9924  case 'jpocrb':
9925  return 'JIS_C6229-1984-b';
9926  case 'csiso93jis62291984badd':
9927  case 'isoir93':
9928  case 'jisc62291984badd':
9929  case 'jpocrbadd':
9930  return 'JIS_C6229-1984-b-add';
9931  case 'csiso94jis62291984hand':
9932  case 'isoir94':
9933  case 'jisc62291984hand':
9934  case 'jpocrhand':
9935  return 'JIS_C6229-1984-hand';
9936  case 'csiso95jis62291984handadd':
9937  case 'isoir95':
9938  case 'jisc62291984handadd':
9939  case 'jpocrhandadd':
9940  return 'JIS_C6229-1984-hand-add';
9941  case 'csiso96jisc62291984kana':
9942  case 'isoir96':
9943  case 'jisc62291984kana':
9944  return 'JIS_C6229-1984-kana';
9945  case 'csjisencoding':
9946  case 'jisencoding':
9947  return 'JIS_Encoding';
9948  case 'cshalfwidthkatakana':
9949  case 'jisx201':
9950  case 'x201':
9951  return 'JIS_X0201';
9952  case 'csiso159jisx2121990':
9953  case 'isoir159':
9954  case 'jisx2121990':
9955  case 'x212':
9956  return 'JIS_X0212-1990';
9957  case 'csiso141jusib1002':
9958  case 'iso646yu':
9959  case 'isoir141':
9960  case 'js':
9961  case 'jusib1002':
9962  case 'yu':
9963  return 'JUS_I.B1.002';
9964  case 'csiso147macedonian':
9965  case 'isoir147':
9966  case 'jusib1003mac':
9967  case 'macedonian':
9968  return 'JUS_I.B1.003-mac';
9969  case 'csiso146serbian':
9970  case 'isoir146':
9971  case 'jusib1003serb':
9972  case 'serbian':
9973  return 'JUS_I.B1.003-serb';
9974  case 'koi7switched':
9975  return 'KOI7-switched';
9976  case 'cskoi8r':
9977  case 'koi8r':
9978  return 'KOI8-R';
9979  case 'koi8u':
9980  return 'KOI8-U';
9981  case 'csksc5636':
9982  case 'iso646kr':
9983  case 'ksc5636':
9984  return 'KSC5636';
9985  case 'cskz1048':
9986  case 'kz1048':
9987  case 'rk1048':
9988  case 'strk10482002':
9989  return 'KZ-1048';
9990  case 'csiso19latingreek':
9991  case 'isoir19':
9992  case 'latingreek':
9993  return 'latin-greek';
9994  case 'csiso27latingreek1':
9995  case 'isoir27':
9996  case 'latingreek1':
9997  return 'Latin-greek-1';
9998  case 'csiso158lap':
9999  case 'isoir158':
10000  case 'lap':
10001  case 'latinlap':
10002  return 'latin-lap';
10003  case 'csmacintosh':
10004  case 'mac':
10005  case 'macintosh':
10006  return 'macintosh';
10007  case 'csmicrosoftpublishing':
10008  case 'microsoftpublishing':
10009  return 'Microsoft-Publishing';
10010  case 'csmnem':
10011  case 'mnem':
10012  return 'MNEM';
10013  case 'csmnemonic':
10014  case 'mnemonic':
10015  return 'MNEMONIC';
10016  case 'csiso86hungarian':
10017  case 'hu':
10018  case 'iso646hu':
10019  case 'isoir86':
10020  case 'msz77953':
10021  return 'MSZ_7795.3';
10022  case 'csnatsdano':
10023  case 'isoir91':
10024  case 'natsdano':
10025  return 'NATS-DANO';
10026  case 'csnatsdanoadd':
10027  case 'isoir92':
10028  case 'natsdanoadd':
10029  return 'NATS-DANO-ADD';
10030  case 'csnatssefi':
10031  case 'isoir81':
10032  case 'natssefi':
10033  return 'NATS-SEFI';
10034  case 'csnatssefiadd':
10035  case 'isoir82':
10036  case 'natssefiadd':
10037  return 'NATS-SEFI-ADD';
10038  case 'csiso151cuba':
10039  case 'cuba':
10040  case 'iso646cu':
10041  case 'isoir151':
10042  case 'ncnc1081':
10043  return 'NC_NC00-10:81';
10044  case 'csiso69french':
10045  case 'fr':
10046  case 'iso646fr':
10047  case 'isoir69':
10048  case 'nfz62010':
10049  return 'NF_Z_62-010';
10050  case 'csiso25french':
10051  case 'iso646fr1':
10052  case 'isoir25':
10053  case 'nfz620101973':
10054  return 'NF_Z_62-010_(1973)';
10055  case 'csiso60danishnorwegian':
10056  case 'csiso60norwegian1':
10057  case 'iso646no':
10058  case 'isoir60':
10059  case 'no':
10060  case 'ns45511':
10061  return 'NS_4551-1';
10062  case 'csiso61norwegian2':
10063  case 'iso646no2':
10064  case 'isoir61':
10065  case 'no2':
10066  case 'ns45512':
10067  return 'NS_4551-2';
10068  case 'osdebcdicdf3irv':
10069  return 'OSD_EBCDIC_DF03_IRV';
10070  case 'osdebcdicdf41':
10071  return 'OSD_EBCDIC_DF04_1';
10072  case 'osdebcdicdf415':
10073  return 'OSD_EBCDIC_DF04_15';
10074  case 'cspc8danishnorwegian':
10075  case 'pc8danishnorwegian':
10076  return 'PC8-Danish-Norwegian';
10077  case 'cspc8turkish':
10078  case 'pc8turkish':
10079  return 'PC8-Turkish';
10080  case 'csiso16portuguese':
10081  case 'iso646pt':
10082  case 'isoir16':
10083  case 'pt':
10084  return 'PT';
10085  case 'csiso84portuguese2':
10086  case 'iso646pt2':
10087  case 'isoir84':
10088  case 'pt2':
10089  return 'PT2';
10090  case 'cp154':
10091  case 'csptcp154':
10092  case 'cyrillicasian':
10093  case 'pt154':
10094  case 'ptcp154':
10095  return 'PTCP154';
10096  case 'scsu':
10097  return 'SCSU';
10098  case 'csiso10swedish':
10099  case 'fi':
10100  case 'iso646fi':
10101  case 'iso646se':
10102  case 'isoir10':
10103  case 'se':
10104  case 'sen850200b':
10105  return 'SEN_850200_B';
10106  case 'csiso11swedishfornames':
10107  case 'iso646se2':
10108  case 'isoir11':
10109  case 'se2':
10110  case 'sen850200c':
10111  return 'SEN_850200_C';
10112  case 'csiso102t617bit':
10113  case 'isoir102':
10114  case 't617bit':
10115  return 'T.61-7bit';
10116  case 'csiso103t618bit':
10117  case 'isoir103':
10118  case 't61':
10119  case 't618bit':
10120  return 'T.61-8bit';
10121  case 'csiso128t101g2':
10122  case 'isoir128':
10123  case 't101g2':
10124  return 'T.101-G2';
10125  case 'cstscii':
10126  case 'tscii':
10127  return 'TSCII';
10128  case 'csunicode11':
10129  case 'unicode11':
10130  return 'UNICODE-1-1';
10131  case 'csunicode11utf7':
10132  case 'unicode11utf7':
10133  return 'UNICODE-1-1-UTF-7';
10134  case 'csunknown8bit':
10135  case 'unknown8bit':
10136  return 'UNKNOWN-8BIT';
10137  case 'ansix341968':
10138  case 'ansix341986':
10139  case 'ascii':
10140  case 'cp367':
10141  case 'csascii':
10142  case 'ibm367':
10143  case 'iso646irv1991':
10144  case 'iso646us':
10145  case 'isoir6':
10146  case 'us':
10147  case 'usascii':
10148  return 'US-ASCII';
10149  case 'csusdk':
10150  case 'usdk':
10151  return 'us-dk';
10152  case 'utf7':
10153  return 'UTF-7';
10154  case 'utf8':
10155  return 'UTF-8';
10156  case 'utf16':
10157  return 'UTF-16';
10158  case 'utf16be':
10159  return 'UTF-16BE';
10160  case 'utf16le':
10161  return 'UTF-16LE';
10162  case 'utf32':
10163  return 'UTF-32';
10164  case 'utf32be':
10165  return 'UTF-32BE';
10166  case 'utf32le':
10167  return 'UTF-32LE';
10168  case 'csventurainternational':
10169  case 'venturainternational':
10170  return 'Ventura-International';
10171  case 'csventuramath':
10172  case 'venturamath':
10173  return 'Ventura-Math';
10174  case 'csventuraus':
10175  case 'venturaus':
10176  return 'Ventura-US';
10177  case 'csiso70videotexsupp1':
10178  case 'isoir70':
10179  case 'videotexsuppl':
10180  return 'videotex-suppl';
10181  case 'csviqr':
10182  case 'viqr':
10183  return 'VIQR';
10184  case 'csviscii':
10185  case 'viscii':
10186  return 'VISCII';
10187  case 'csshiftjis':
10188  case 'cswindows31j':
10189  case 'mskanji':
10190  case 'shiftjis':
10191  case 'windows31j':
10192  return 'Windows-31J';
10193  case 'iso885911':
10194  case 'tis620':
10195  return 'windows-874';
10196  case 'cseuckr':
10197  case 'csksc56011987':
10198  case 'euckr':
10199  case 'isoir149':
10200  case 'korean':
10201  case 'ksc5601':
10202  case 'ksc56011987':
10203  case 'ksc56011989':
10204  case 'windows949':
10205  return 'windows-949';
10206  case 'windows1250':
10207  return 'windows-1250';
10208  case 'windows1251':
10209  return 'windows-1251';
10210  case 'cp819':
10211  case 'csisolatin1':
10212  case 'ibm819':
10213  case 'iso88591':
10214  case 'iso885911987':
10215  case 'isoir100':
10216  case 'l1':
10217  case 'latin1':
10218  case 'windows1252':
10219  return 'windows-1252';
10220  case 'windows1253':
10221  return 'windows-1253';
10222  case 'csisolatin5':
10223  case 'iso88599':
10224  case 'iso885991989':
10225  case 'isoir148':
10226  case 'l5':
10227  case 'latin5':
10228  case 'windows1254':
10229  return 'windows-1254';
10230  case 'windows1255':
10231  return 'windows-1255';
10232  case 'windows1256':
10233  return 'windows-1256';
10234  case 'windows1257':
10235  return 'windows-1257';
10236  case 'windows1258':
10237  return 'windows-1258';
10238  default:
10239  return $charset;
10240  }
10241  }
10242  public static function get_curl_version()
10243  {
10244  if (is_array($curl = curl_version()))
10245  {
10246  $curl = $curl['version'];
10247  }
10248  elseif (substr($curl, 0, 5) === 'curl/')
10249  {
10250  $curl = substr($curl, 5, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 5));
10251  }
10252  elseif (substr($curl, 0, 8) === 'libcurl/')
10253  {
10254  $curl = substr($curl, 8, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 8));
10255  }
10256  else
10257  {
10258  $curl = 0;
10259  }
10260  return $curl;
10261  }
10262 
10263  public static function strip_comments($data)
10264  {
10265  $output = '';
10266  while (($start = strpos($data, '<!--')) !== false)
10267  {
10268  $output .= substr($data, 0, $start);
10269  if (($end = strpos($data, '-->', $start)) !== false)
10270  {
10271  $data = substr_replace($data, '', 0, $end + 3);
10272  }
10273  else
10274  {
10275  $data = '';
10276  }
10277  }
10278  return $output . $data;
10279  }
10280  public static function parse_date($dt)
10281  {
10282  $parser = SimplePie_Parse_Date::get();
10283  return $parser->parse($dt);
10284  }
10285 
10286  public static function entities_decode($data)
10287  {
10288  $decoder = new SimplePie_Decode_HTML_Entities($data);
10289  return $decoder->parse();
10290  }
10291 
10292  public static function uncomment_rfc822($string)
10293  {
10294  $string = (string) $string;
10295  $position = 0;
10296  $length = strlen($string);
10297  $depth = 0;
10298  $output = '';
10299  while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
10300  {
10301  $output .= substr($string, $position, $pos - $position);
10302  $position = $pos + 1;
10303  if ($string[$pos - 1] !== '\\')
10304  {
10305  $depth++;
10306  while ($depth && $position < $length)
10307  {
10308  $position += strcspn($string, '()', $position);
10309  if ($string[$position - 1] === '\\')
10310  {
10311  $position++;
10312  continue;
10313  }
10314  elseif (isset($string[$position]))
10315  {
10316  switch ($string[$position])
10317  {
10318  case '(':
10319  $depth++;
10320  break;
10321  case ')':
10322  $depth--;
10323  break;
10324  }
10325  $position++;
10326  }
10327  else
10328  {
10329  break;
10330  }
10331  }
10332  }
10333  else
10334  {
10335  $output .= '(';
10336  }
10337  }
10338  $output .= substr($string, $position);
10339  return $output;
10340  }
10341  public static function parse_mime($mime)
10342  {
10343  if (($pos = strpos($mime, ';')) === false)
10344  {
10345  return trim($mime);
10346  }
10347  else
10348  {
10349  return trim(substr($mime, 0, $pos));
10350  }
10351  }
10352  public static function atom_03_construct_type($attribs)
10353  {
10354  if (isset($attribs['']['mode']) && strtolower(trim($attribs['']['mode']) === 'base64'))
10355  {
10357  }
10358  else
10359  {
10361  }
10362  if (isset($attribs['']['type']))
10363  {
10364  switch (strtolower(trim($attribs['']['type'])))
10365  {
10366  case 'text':
10367  case 'text/plain':
10369  case 'html':
10370  case 'text/html':
10372  case 'xhtml':
10373  case 'application/xhtml+xml':
10375  default:
10377  }
10378  }
10379  else
10380  {
10382  }
10383  }
10384  public static function atom_10_construct_type($attribs)
10385  {
10386  if (isset($attribs['']['type']))
10387  {
10388  switch (strtolower(trim($attribs['']['type'])))
10389  {
10390  case 'text':
10391  return SIMPLEPIE_CONSTRUCT_TEXT;
10392  case 'html':
10393  return SIMPLEPIE_CONSTRUCT_HTML;
10394  case 'xhtml':
10396  default:
10397  return SIMPLEPIE_CONSTRUCT_NONE;
10398  }
10399  }
10400  return SIMPLEPIE_CONSTRUCT_TEXT;
10401  }
10402  public static function atom_10_content_construct_type($attribs)
10403  {
10404  if (isset($attribs['']['type']))
10405  {
10406  $type = strtolower(trim($attribs['']['type']));
10407  switch ($type)
10408  {
10409  case 'text':
10410  return SIMPLEPIE_CONSTRUCT_TEXT;
10411  case 'html':
10412  return SIMPLEPIE_CONSTRUCT_HTML;
10413  case 'xhtml':
10415  }
10416  if (in_array(substr($type, -4), array('+xml', '/xml')) || substr($type, 0, 5) === 'text/')
10417  {
10418  return SIMPLEPIE_CONSTRUCT_NONE;
10419  }
10420  else
10421  {
10423  }
10424  }
10425  else
10426  {
10427  return SIMPLEPIE_CONSTRUCT_TEXT;
10428  }
10429  }
10430  public static function is_isegment_nz_nc($string)
10431  {
10432  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);
10433  }
10434  public static function space_seperated_tokens($string)
10435  {
10436  $space_characters = "\x20\x09\x0A\x0B\x0C\x0D";
10437  $string_length = strlen($string);
10438  $position = strspn($string, $space_characters);
10439  $tokens = array();
10440  while ($position < $string_length)
10441  {
10442  $len = strcspn($string, $space_characters, $position);
10443  $tokens[] = substr($string, $position, $len);
10444  $position += $len;
10445  $position += strspn($string, $space_characters, $position);
10446  }
10447  return $tokens;
10448  }
10449 
10450  public static function codepoint_to_utf8($codepoint)
10451  {
10452  $codepoint = (int) $codepoint;
10453  if ($codepoint < 0)
10454  {
10455  return false;
10456  }
10457  else if ($codepoint <= 0x7f)
10458  {
10459  return chr($codepoint);
10460  }
10461  else if ($codepoint <= 0x7ff)
10462  {
10463  return chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f));
10464  }
10465  else if ($codepoint <= 0xffff)
10466  {
10467  return chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
10468  }
10469  else if ($codepoint <= 0x10ffff)
10470  {
10471  return chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
10472  }
10473  else
10474  {
10475  // U+FFFD REPLACEMENT CHARACTER
10476  return "\xEF\xBF\xBD";
10477  }
10478  }
10479 
10480  public static function parse_str($str)
10481  {
10482  $return = array();
10483  $str = explode('&', $str);
10484  foreach ($str as $section)
10485  {
10486  if (strpos($section, '=') !== false)
10487  {
10488  list($name, $value) = explode('=', $section, 2);
10489  $return[urldecode($name)][] = urldecode($value);
10490  }
10491  else
10492  {
10493  $return[urldecode($section)][] = null;
10494  }
10495  }
10496  return $return;
10497  }
10498 
10499  public static function xml_encoding($data, $registry)
10500  {
10501  // UTF-32 Big Endian BOM
10502  if (substr($data, 0, 4) === "\x00\x00\xFE\xFF")
10503  {
10504  $encoding[] = 'UTF-32BE';
10505  }
10506  // UTF-32 Little Endian BOM
10507  elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00")
10508  {
10509  $encoding[] = 'UTF-32LE';
10510  }
10511  // UTF-16 Big Endian BOM
10512  elseif (substr($data, 0, 2) === "\xFE\xFF")
10513  {
10514  $encoding[] = 'UTF-16BE';
10515  }
10516  // UTF-16 Little Endian BOM
10517  elseif (substr($data, 0, 2) === "\xFF\xFE")
10518  {
10519  $encoding[] = 'UTF-16LE';
10520  }
10521  // UTF-8 BOM
10522  elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
10523  {
10524  $encoding[] = 'UTF-8';
10525  }
10526  // UTF-32 Big Endian Without BOM
10527  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")
10528  {
10529  if ($pos = strpos($data, "\x00\x00\x00\x3F\x00\x00\x00\x3E"))
10530  {
10531  $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32BE', 'UTF-8')));
10532  if ($parser->parse())
10533  {
10534  $encoding[] = $parser->encoding;
10535  }
10536  }
10537  $encoding[] = 'UTF-32BE';
10538  }
10539  // UTF-32 Little Endian Without BOM
10540  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")
10541  {
10542  if ($pos = strpos($data, "\x3F\x00\x00\x00\x3E\x00\x00\x00"))
10543  {
10544  $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32LE', 'UTF-8')));
10545  if ($parser->parse())
10546  {
10547  $encoding[] = $parser->encoding;
10548  }
10549  }
10550  $encoding[] = 'UTF-32LE';
10551  }
10552  // UTF-16 Big Endian Without BOM
10553  elseif (substr($data, 0, 10) === "\x00\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C")
10554  {
10555  if ($pos = strpos($data, "\x00\x3F\x00\x3E"))
10556  {
10557  $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16BE', 'UTF-8')));
10558  if ($parser->parse())
10559  {
10560  $encoding[] = $parser->encoding;
10561  }
10562  }
10563  $encoding[] = 'UTF-16BE';
10564  }
10565  // UTF-16 Little Endian Without BOM
10566  elseif (substr($data, 0, 10) === "\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C\x00")
10567  {
10568  if ($pos = strpos($data, "\x3F\x00\x3E\x00"))
10569  {
10570  $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16LE', 'UTF-8')));
10571  if ($parser->parse())
10572  {
10573  $encoding[] = $parser->encoding;
10574  }
10575  }
10576  $encoding[] = 'UTF-16LE';
10577  }
10578  // US-ASCII (or superset)
10579  elseif (substr($data, 0, 5) === "\x3C\x3F\x78\x6D\x6C")
10580  {
10581  if ($pos = strpos($data, "\x3F\x3E"))
10582  {
10583  $parser = $registry->create('XML_Declaration_Parser', array(substr($data, 5, $pos - 5)));
10584  if ($parser->parse())
10585  {
10586  $encoding[] = $parser->encoding;
10587  }
10588  }
10589  $encoding[] = 'UTF-8';
10590  }
10591  // Fallback to UTF-8
10592  else
10593  {
10594  $encoding[] = 'UTF-8';
10595  }
10596  return $encoding;
10597  }
10598  public static function output_javascript()
10599  {
10600  if (function_exists('ob_gzhandler'))
10601  {
10602  ob_start('ob_gzhandler');
10603  }
10604  header('Content-type: text/javascript; charset: UTF-8');
10605  header('Cache-Control: must-revalidate');
10606  header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days
10607  ?>
10608 function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {
10609  if (placeholder != '') {
10610  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>');
10611  }
10612  else {
10613  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>');
10614  }
10615 }
10616 function embed_flash(bgcolor, width, height, link, loop, type) {
10617  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>');
10618 }
10619 function embed_flv(width, height, link, placeholder, loop, player) {
10620  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>');
10621 }
10622 function embed_wmedia(width, height, link) {
10623  document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>');
10624 }
10625  <?php
10626  }
10627 
10628  public static function get_build()
10629  {
10630  $root = dirname(dirname(__FILE__));
10631  if (file_exists($root . '/.git/index'))
10632  {
10633  return filemtime($root . '/.git/index');
10634  }
10635  elseif (file_exists($root . '/SimplePie'))
10636  {
10637  $time = 0;
10638  foreach (glob($root . '/SimplePie/*.php') as $file)
10639  {
10640  if (($mtime = filemtime($file)) > $time)
10641  {
10642  $time = $mtime;
10643  }
10644  }
10645  return $time;
10646  }
10647  elseif (file_exists(dirname(__FILE__) . '/Core.php'))
10648  {
10649  return filemtime(dirname(__FILE__) . '/Core.php');
10650  }
10651  else
10652  {
10653  return filemtime(__FILE__);
10654  }
10655  }
10656 
10657  public static function debug(&$sp)
10658  {
10659  $info = 'SimplePie ' . SIMPLEPIE_VERSION . ' Build ' . SIMPLEPIE_BUILD . "\n";
10660  $info .= 'PHP ' . PHP_VERSION . "\n";
10661  if ($sp->error() !== null)
10662  {
10663  $info .= 'Error occurred: ' . $sp->error() . "\n";
10664  }
10665  else
10666  {
10667  $info .= "No error found.\n";
10668  }
10669  $info .= "Extensions:\n";
10670  $extensions = array('pcre', 'curl', 'zlib', 'mbstring', 'iconv', 'xmlreader', 'xml');
10671  foreach ($extensions as $ext)
10672  {
10673  if (extension_loaded($ext))
10674  {
10675  $info .= " $ext loaded\n";
10676  switch ($ext)
10677  {
10678  case 'pcre':
10679  $info .= ' Version ' . PCRE_VERSION . "\n";
10680  break;
10681  case 'curl':
10682  $version = curl_version();
10683  $info .= ' Version ' . $version['version'] . "\n";
10684  break;
10685  case 'mbstring':
10686  $info .= ' Overloading: ' . mb_get_info('func_overload') . "\n";
10687  break;
10688  case 'iconv':
10689  $info .= ' Version ' . ICONV_VERSION . "\n";
10690  break;
10691  case 'xml':
10692  $info .= ' Version ' . LIBXML_DOTTED_VERSION . "\n";
10693  break;
10694  }
10695  }
10696  else
10697  {
10698  $info .= " $ext not loaded\n";
10699  }
10700  }
10701  return $info;
10702  }
10703  public static function silence_errors($num, $str)
10704  {
10705  // No-op
10706  }
10707 }
10709 {
10710 
10711  public static function uncompress($ip)
10712  {
10713  $c1 = -1;
10714  $c2 = -1;
10715  if (substr_count($ip, '::') === 1)
10716  {
10717  list($ip1, $ip2) = explode('::', $ip);
10718  if ($ip1 === '')
10719  {
10720  $c1 = -1;
10721  }
10722  else
10723  {
10724  $c1 = substr_count($ip1, ':');
10725  }
10726  if ($ip2 === '')
10727  {
10728  $c2 = -1;
10729  }
10730  else
10731  {
10732  $c2 = substr_count($ip2, ':');
10733  }
10734  if (strpos($ip2, '.') !== false)
10735  {
10736  $c2++;
10737  }
10738  // ::
10739  if ($c1 === -1 && $c2 === -1)
10740  {
10741  $ip = '0:0:0:0:0:0:0:0';
10742  }
10743  // ::xxx
10744  else if ($c1 === -1)
10745  {
10746  $fill = str_repeat('0:', 7 - $c2);
10747  $ip = str_replace('::', $fill, $ip);
10748  }
10749  // xxx::
10750  else if ($c2 === -1)
10751  {
10752  $fill = str_repeat(':0', 7 - $c1);
10753  $ip = str_replace('::', $fill, $ip);
10754  }
10755  // xxx::xxx
10756  else
10757  {
10758  $fill = ':' . str_repeat('0:', 6 - $c2 - $c1);
10759  $ip = str_replace('::', $fill, $ip);
10760  }
10761  }
10762  return $ip;
10763  }
10764 
10765  public static function compress($ip)
10766  {
10767  // Prepare the IP to be compressed
10768  $ip = self::uncompress($ip);
10769  $ip_parts = self::split_v6_v4($ip);
10770  // Replace all leading zeros
10771  $ip_parts[0] = preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]);
10772  // Find bunches of zeros
10773  if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE))
10774  {
10775  $max = 0;
10776  $pos = null;
10777  foreach ($matches[0] as $match)
10778  {
10779  if (strlen($match[0]) > $max)
10780  {
10781  $max = strlen($match[0]);
10782  $pos = $match[1];
10783  }
10784  }
10785  $ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max);
10786  }
10787  if ($ip_parts[1] !== '')
10788  {
10789  return implode(':', $ip_parts);
10790  }
10791  else
10792  {
10793  return $ip_parts[0];
10794  }
10795  }
10796 
10797  private static function split_v6_v4($ip)
10798  {
10799  if (strpos($ip, '.') !== false)
10800  {
10801  $pos = strrpos($ip, ':');
10802  $ipv6_part = substr($ip, 0, $pos);
10803  $ipv4_part = substr($ip, $pos + 1);
10804  return array($ipv6_part, $ipv4_part);
10805  }
10806  else
10807  {
10808  return array($ip, '');
10809  }
10810  }
10811 
10812  public static function check_ipv6($ip)
10813  {
10814  $ip = self::uncompress($ip);
10815  list($ipv6, $ipv4) = self::split_v6_v4($ip);
10816  $ipv6 = explode(':', $ipv6);
10817  $ipv4 = explode('.', $ipv4);
10818  if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4)
10819  {
10820  foreach ($ipv6 as $ipv6_part)
10821  {
10822  // The section can't be empty
10823  if ($ipv6_part === '')
10824  return false;
10825  // Nor can it be over four characters
10826  if (strlen($ipv6_part) > 4)
10827  return false;
10828  // Remove leading zeros (this is safe because of the above)
10829  $ipv6_part = ltrim($ipv6_part, '0');
10830  if ($ipv6_part === '')
10831  $ipv6_part = '0';
10832  // Check the value is valid
10833  $value = hexdec($ipv6_part);
10834  if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF)
10835  return false;
10836  }
10837  if (count($ipv4) === 4)
10838  {
10839  foreach ($ipv4 as $ipv4_part)
10840  {
10841  $value = (int) $ipv4_part;
10842  if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF)
10843  return false;
10844  }
10845  }
10846  return true;
10847  }
10848  else
10849  {
10850  return false;
10851  }
10852  }
10853 
10854  public static function checkIPv6($ip)
10855  {
10856  return self::check_ipv6($ip);
10857  }
10858 }
10860 {
10861 
10862  var $date;
10863 
10864  var $day = array(
10865  // English
10866  'mon' => 1,
10867  'monday' => 1,
10868  'tue' => 2,
10869  'tuesday' => 2,
10870  'wed' => 3,
10871  'wednesday' => 3,
10872  'thu' => 4,
10873  'thursday' => 4,
10874  'fri' => 5,
10875  'friday' => 5,
10876  'sat' => 6,
10877  'saturday' => 6,
10878  'sun' => 7,
10879  'sunday' => 7,
10880  // Dutch
10881  'maandag' => 1,
10882  'dinsdag' => 2,
10883  'woensdag' => 3,
10884  'donderdag' => 4,
10885  'vrijdag' => 5,
10886  'zaterdag' => 6,
10887  'zondag' => 7,
10888  // French
10889  'lundi' => 1,
10890  'mardi' => 2,
10891  'mercredi' => 3,
10892  'jeudi' => 4,
10893  'vendredi' => 5,
10894  'samedi' => 6,
10895  'dimanche' => 7,
10896  // German
10897  'montag' => 1,
10898  'dienstag' => 2,
10899  'mittwoch' => 3,
10900  'donnerstag' => 4,
10901  'freitag' => 5,
10902  'samstag' => 6,
10903  'sonnabend' => 6,
10904  'sonntag' => 7,
10905  // Italian
10906  'lunedì' => 1,
10907  'martedì' => 2,
10908  'mercoledì' => 3,
10909  'giovedì' => 4,
10910  'venerdì' => 5,
10911  'sabato' => 6,
10912  'domenica' => 7,
10913  // Spanish
10914  'lunes' => 1,
10915  'martes' => 2,
10916  'miércoles' => 3,
10917  'jueves' => 4,
10918  'viernes' => 5,
10919  'sábado' => 6,
10920  'domingo' => 7,
10921  // Finnish
10922  'maanantai' => 1,
10923  'tiistai' => 2,
10924  'keskiviikko' => 3,
10925  'torstai' => 4,
10926  'perjantai' => 5,
10927  'lauantai' => 6,
10928  'sunnuntai' => 7,
10929  // Hungarian
10930  'hétfő' => 1,
10931  'kedd' => 2,
10932  'szerda' => 3,
10933  'csütörtok' => 4,
10934  'péntek' => 5,
10935  'szombat' => 6,
10936  'vasárnap' => 7,
10937  // Greek
10938  'Δευ' => 1,
10939  'Τρι' => 2,
10940  'Τετ' => 3,
10941  'Πεμ' => 4,
10942  'Παρ' => 5,
10943  'Σαβ' => 6,
10944  'Κυρ' => 7,
10945  );
10946 
10947  var $month = array(
10948  // English
10949  'jan' => 1,
10950  'january' => 1,
10951  'feb' => 2,
10952  'february' => 2,
10953  'mar' => 3,
10954  'march' => 3,
10955  'apr' => 4,
10956  'april' => 4,
10957  'may' => 5,
10958  // No long form of May
10959  'jun' => 6,
10960  'june' => 6,
10961  'jul' => 7,
10962  'july' => 7,
10963  'aug' => 8,
10964  'august' => 8,
10965  'sep' => 9,
10966  'september' => 8,
10967  'oct' => 10,
10968  'october' => 10,
10969  'nov' => 11,
10970  'november' => 11,
10971  'dec' => 12,
10972  'december' => 12,
10973  // Dutch
10974  'januari' => 1,
10975  'februari' => 2,
10976  'maart' => 3,
10977  'april' => 4,
10978  'mei' => 5,
10979  'juni' => 6,
10980  'juli' => 7,
10981  'augustus' => 8,
10982  'september' => 9,
10983  'oktober' => 10,
10984  'november' => 11,
10985  'december' => 12,
10986  // French
10987  'janvier' => 1,
10988  'février' => 2,
10989  'mars' => 3,
10990  'avril' => 4,
10991  'mai' => 5,
10992  'juin' => 6,
10993  'juillet' => 7,
10994  'août' => 8,
10995  'septembre' => 9,
10996  'octobre' => 10,
10997  'novembre' => 11,
10998  'décembre' => 12,
10999  // German
11000  'januar' => 1,
11001  'februar' => 2,
11002  'märz' => 3,
11003  'april' => 4,
11004  'mai' => 5,
11005  'juni' => 6,
11006  'juli' => 7,
11007  'august' => 8,
11008  'september' => 9,
11009  'oktober' => 10,
11010  'november' => 11,
11011  'dezember' => 12,
11012  // Italian
11013  'gennaio' => 1,
11014  'febbraio' => 2,
11015  'marzo' => 3,
11016  'aprile' => 4,
11017  'maggio' => 5,
11018  'giugno' => 6,
11019  'luglio' => 7,
11020  'agosto' => 8,
11021  'settembre' => 9,
11022  'ottobre' => 10,
11023  'novembre' => 11,
11024  'dicembre' => 12,
11025  // Spanish
11026  'enero' => 1,
11027  'febrero' => 2,
11028  'marzo' => 3,
11029  'abril' => 4,
11030  'mayo' => 5,
11031  'junio' => 6,
11032  'julio' => 7,
11033  'agosto' => 8,
11034  'septiembre' => 9,
11035  'setiembre' => 9,
11036  'octubre' => 10,
11037  'noviembre' => 11,
11038  'diciembre' => 12,
11039  // Finnish
11040  'tammikuu' => 1,
11041  'helmikuu' => 2,
11042  'maaliskuu' => 3,
11043  'huhtikuu' => 4,
11044  'toukokuu' => 5,
11045  'kesäkuu' => 6,
11046  'heinäkuu' => 7,
11047  'elokuu' => 8,
11048  'suuskuu' => 9,
11049  'lokakuu' => 10,
11050  'marras' => 11,
11051  'joulukuu' => 12,
11052  // Hungarian
11053  'január' => 1,
11054  'február' => 2,
11055  'március' => 3,
11056  'április' => 4,
11057  'május' => 5,
11058  'június' => 6,
11059  'július' => 7,
11060  'augusztus' => 8,
11061  'szeptember' => 9,
11062  'október' => 10,
11063  'november' => 11,
11064  'december' => 12,
11065  // Greek
11066  'Ιαν' => 1,
11067  'Φεβ' => 2,
11068  'Μάώ' => 3,
11069  'Μαώ' => 3,
11070  'Απρ' => 4,
11071  'Μάι' => 5,
11072  'Μαϊ' => 5,
11073  'Μαι' => 5,
11074  'Ιούν' => 6,
11075  'Ιον' => 6,
11076  'Ιούλ' => 7,
11077  'Ιολ' => 7,
11078  'Αύγ' => 8,
11079  'Αυγ' => 8,
11080  'Σεπ' => 9,
11081  'Οκτ' => 10,
11082  'Νοέ' => 11,
11083  'Δεκ' => 12,
11084  );
11085 
11086  var $timezone = array(
11087  'ACDT' => 37800,
11088  'ACIT' => 28800,
11089  'ACST' => 34200,
11090  'ACT' => -18000,
11091  'ACWDT' => 35100,
11092  'ACWST' => 31500,
11093  'AEDT' => 39600,
11094  'AEST' => 36000,
11095  'AFT' => 16200,
11096  'AKDT' => -28800,
11097  'AKST' => -32400,
11098  'AMDT' => 18000,
11099  'AMT' => -14400,
11100  'ANAST' => 46800,
11101  'ANAT' => 43200,
11102  'ART' => -10800,
11103  'AZOST' => -3600,
11104  'AZST' => 18000,
11105  'AZT' => 14400,
11106  'BIOT' => 21600,
11107  'BIT' => -43200,
11108  'BOT' => -14400,
11109  'BRST' => -7200,
11110  'BRT' => -10800,
11111  'BST' => 3600,
11112  'BTT' => 21600,
11113  'CAST' => 18000,
11114  'CAT' => 7200,
11115  'CCT' => 23400,
11116  'CDT' => -18000,
11117  'CEDT' => 7200,
11118  'CET' => 3600,
11119  'CGST' => -7200,
11120  'CGT' => -10800,
11121  'CHADT' => 49500,
11122  'CHAST' => 45900,
11123  'CIST' => -28800,
11124  'CKT' => -36000,
11125  'CLDT' => -10800,
11126  'CLST' => -14400,
11127  'COT' => -18000,
11128  'CST' => -21600,
11129  'CVT' => -3600,
11130  'CXT' => 25200,
11131  'DAVT' => 25200,
11132  'DTAT' => 36000,
11133  'EADT' => -18000,
11134  'EAST' => -21600,
11135  'EAT' => 10800,
11136  'ECT' => -18000,
11137  'EDT' => -14400,
11138  'EEST' => 10800,
11139  'EET' => 7200,
11140  'EGT' => -3600,
11141  'EKST' => 21600,
11142  'EST' => -18000,
11143  'FJT' => 43200,
11144  'FKDT' => -10800,
11145  'FKST' => -14400,
11146  'FNT' => -7200,
11147  'GALT' => -21600,
11148  'GEDT' => 14400,
11149  'GEST' => 10800,
11150  'GFT' => -10800,
11151  'GILT' => 43200,
11152  'GIT' => -32400,
11153  'GST' => 14400,
11154  'GST' => -7200,
11155  'GYT' => -14400,
11156  'HAA' => -10800,
11157  'HAC' => -18000,
11158  'HADT' => -32400,
11159  'HAE' => -14400,
11160  'HAP' => -25200,
11161  'HAR' => -21600,
11162  'HAST' => -36000,
11163  'HAT' => -9000,
11164  'HAY' => -28800,
11165  'HKST' => 28800,
11166  'HMT' => 18000,
11167  'HNA' => -14400,
11168  'HNC' => -21600,
11169  'HNE' => -18000,
11170  'HNP' => -28800,
11171  'HNR' => -25200,
11172  'HNT' => -12600,
11173  'HNY' => -32400,
11174  'IRDT' => 16200,
11175  'IRKST' => 32400,
11176  'IRKT' => 28800,
11177  'IRST' => 12600,
11178  'JFDT' => -10800,
11179  'JFST' => -14400,
11180  'JST' => 32400,
11181  'KGST' => 21600,
11182  'KGT' => 18000,
11183  'KOST' => 39600,
11184  'KOVST' => 28800,
11185  'KOVT' => 25200,
11186  'KRAST' => 28800,
11187  'KRAT' => 25200,
11188  'KST' => 32400,
11189  'LHDT' => 39600,
11190  'LHST' => 37800,
11191  'LINT' => 50400,
11192  'LKT' => 21600,
11193  'MAGST' => 43200,
11194  'MAGT' => 39600,
11195  'MAWT' => 21600,
11196  'MDT' => -21600,
11197  'MESZ' => 7200,
11198  'MEZ' => 3600,
11199  'MHT' => 43200,
11200  'MIT' => -34200,
11201  'MNST' => 32400,
11202  'MSDT' => 14400,
11203  'MSST' => 10800,
11204  'MST' => -25200,
11205  'MUT' => 14400,
11206  'MVT' => 18000,
11207  'MYT' => 28800,
11208  'NCT' => 39600,
11209  'NDT' => -9000,
11210  'NFT' => 41400,
11211  'NMIT' => 36000,
11212  'NOVST' => 25200,
11213  'NOVT' => 21600,
11214  'NPT' => 20700,
11215  'NRT' => 43200,
11216  'NST' => -12600,
11217  'NUT' => -39600,
11218  'NZDT' => 46800,
11219  'NZST' => 43200,
11220  'OMSST' => 25200,
11221  'OMST' => 21600,
11222  'PDT' => -25200,
11223  'PET' => -18000,
11224  'PETST' => 46800,
11225  'PETT' => 43200,
11226  'PGT' => 36000,
11227  'PHOT' => 46800,
11228  'PHT' => 28800,
11229  'PKT' => 18000,
11230  'PMDT' => -7200,
11231  'PMST' => -10800,
11232  'PONT' => 39600,
11233  'PST' => -28800,
11234  'PWT' => 32400,
11235  'PYST' => -10800,
11236  'PYT' => -14400,
11237  'RET' => 14400,
11238  'ROTT' => -10800,
11239  'SAMST' => 18000,
11240  'SAMT' => 14400,
11241  'SAST' => 7200,
11242  'SBT' => 39600,
11243  'SCDT' => 46800,
11244  'SCST' => 43200,
11245  'SCT' => 14400,
11246  'SEST' => 3600,
11247  'SGT' => 28800,
11248  'SIT' => 28800,
11249  'SRT' => -10800,
11250  'SST' => -39600,
11251  'SYST' => 10800,
11252  'SYT' => 7200,
11253  'TFT' => 18000,
11254  'THAT' => -36000,
11255  'TJT' => 18000,
11256  'TKT' => -36000,
11257  'TMT' => 18000,
11258  'TOT' => 46800,
11259  'TPT' => 32400,
11260  'TRUT' => 36000,
11261  'TVT' => 43200,
11262  'TWT' => 28800,
11263  'UYST' => -7200,
11264  'UYT' => -10800,
11265  'UZT' => 18000,
11266  'VET' => -14400,
11267  'VLAST' => 39600,
11268  'VLAT' => 36000,
11269  'VOST' => 21600,
11270  'VUT' => 39600,
11271  'WAST' => 7200,
11272  'WAT' => 3600,
11273  'WDT' => 32400,
11274  'WEST' => 3600,
11275  'WFT' => 43200,
11276  'WIB' => 25200,
11277  'WIT' => 32400,
11278  'WITA' => 28800,
11279  'WKST' => 18000,
11280  'WST' => 28800,
11281  'YAKST' => 36000,
11282  'YAKT' => 32400,
11283  'YAPT' => 36000,
11284  'YEKST' => 21600,
11285  'YEKT' => 18000,
11286  );
11287 
11289 
11291 
11292  var $built_in = array();
11293 
11294  var $user = array();
11295 
11296  public function __construct()
11297  {
11298  $this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')';
11299  $this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')';
11300  static $cache;
11301  if (!isset($cache[get_class($this)]))
11302  {
11303  $all_methods = get_class_methods($this);
11304  foreach ($all_methods as $method)
11305  {
11306  if (strtolower(substr($method, 0, 5)) === 'date_')
11307  {
11308  $cache[get_class($this)][] = $method;
11309  }
11310  }
11311  }
11312  foreach ($cache[get_class($this)] as $method)
11313  {
11314  $this->built_in[] = $method;
11315  }
11316  }
11317 
11318  public static function get()
11319  {
11320  static $object;
11321  if (!$object)
11322  {
11323  $object = new SimplePie_Parse_Date;
11324  }
11325  return $object;
11326  }
11327 
11328  public function parse($date)
11329  {
11330  foreach ($this->user as $method)
11331  {
11332  if (($returned = call_user_func($method, $date)) !== false)
11333  {
11334  return $returned;
11335  }
11336  }
11337  foreach ($this->built_in as $method)
11338  {
11339  if (($returned = call_user_func(array($this, $method), $date)) !== false)
11340  {
11341  return $returned;
11342  }
11343  }
11344  return false;
11345  }
11346 
11347  public function add_callback($callback)
11348  {
11349  if (is_callable($callback))
11350  {
11351  $this->user[] = $callback;
11352  }
11353  else
11354  {
11355  trigger_error('User-supplied function must be a valid callback', E_USER_WARNING);
11356  }
11357  }
11358 
11359  public function date_w3cdtf($date)
11360  {
11361  static $pcre;
11362  if (!$pcre)
11363  {
11364  $year = '([0-9]{4})';
11365  $month = $day = $hour = $minute = $second = '([0-9]{2})';
11366  $decimal = '([0-9]*)';
11367  $zone = '(?:(Z)|([+\-])([0-9]{1,2}):?([0-9]{1,2}))';
11368  $pcre = '/^' . $year . '(?:-?' . $month . '(?:-?' . $day . '(?:[Tt\x09\x20]+' . $hour . '(?::?' . $minute . '(?::?' . $second . '(?:.' . $decimal . ')?)?)?' . $zone . ')?)?)?$/';
11369  }
11370  if (preg_match($pcre, $date, $match))
11371  {
11372  /*
11373  Capturing subpatterns:
11374  1: Year
11375  2: Month
11376  3: Day
11377  4: Hour
11378  5: Minute
11379  6: Second
11380  7: Decimal fraction of a second
11381  8: Zulu
11382  9: Timezone ±
11383  10: Timezone hours
11384  11: Timezone minutes
11385  */
11386  // Fill in empty matches
11387  for ($i = count($match); $i <= 3; $i++)
11388  {
11389  $match[$i] = '1';
11390  }
11391  for ($i = count($match); $i <= 7; $i++)
11392  {
11393  $match[$i] = '0';
11394  }
11395  // Numeric timezone
11396  if (isset($match[9]) && $match[9] !== '')
11397  {
11398  $timezone = $match[10] * 3600;
11399  $timezone += $match[11] * 60;
11400  if ($match[9] === '-')
11401  {
11402  $timezone = 0 - $timezone;
11403  }
11404  }
11405  else
11406  {
11407  $timezone = 0;
11408  }
11409  // Convert the number of seconds to an integer, taking decimals into account
11410  $second = round($match[6] + $match[7] / pow(10, strlen($match[7])));
11411  return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone;
11412  }
11413  else
11414  {
11415  return false;
11416  }
11417  }
11418 
11419  public function remove_rfc2822_comments($string)
11420  {
11421  $string = (string) $string;
11422  $position = 0;
11423  $length = strlen($string);
11424  $depth = 0;
11425  $output = '';
11426  while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
11427  {
11428  $output .= substr($string, $position, $pos - $position);
11429  $position = $pos + 1;
11430  if ($string[$pos - 1] !== '\\')
11431  {
11432  $depth++;
11433  while ($depth && $position < $length)
11434  {
11435  $position += strcspn($string, '()', $position);
11436  if ($string[$position - 1] === '\\')
11437  {
11438  $position++;
11439  continue;
11440  }
11441  elseif (isset($string[$position]))
11442  {
11443  switch ($string[$position])
11444  {
11445  case '(':
11446  $depth++;
11447  break;
11448  case ')':
11449  $depth--;
11450  break;
11451  }
11452  $position++;
11453  }
11454  else
11455  {
11456  break;
11457  }
11458  }
11459  }
11460  else
11461  {
11462  $output .= '(';
11463  }
11464  }
11465  $output .= substr($string, $position);
11466  return $output;
11467  }
11468 
11469  public function date_rfc2822($date)
11470  {
11471  static $pcre;
11472  if (!$pcre)
11473  {
11474  $wsp = '[\x09\x20]';
11475  $fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
11476  $optional_fws = $fws . '?';
11477  $day_name = $this->day_pcre;
11478  $month = $this->month_pcre;
11479  $day = '([0-9]{1,2})';
11480  $hour = $minute = $second = '([0-9]{2})';
11481  $year = '([0-9]{2,4})';
11482  $num_zone = '([+\-])([0-9]{2})([0-9]{2})';
11483  $character_zone = '([A-Z]{1,5})';
11484  $zone = '(?:' . $num_zone . '|' . $character_zone . ')';
11485  $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';
11486  }
11487  if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match))
11488  {
11489  /*
11490  Capturing subpatterns:
11491  1: Day name
11492  2: Day
11493  3: Month
11494  4: Year
11495  5: Hour
11496  6: Minute
11497  7: Second
11498  8: Timezone ±
11499  9: Timezone hours
11500  10: Timezone minutes
11501  11: Alphabetic timezone
11502  */
11503  // Find the month number
11504  $month = $this->month[strtolower($match[3])];
11505  // Numeric timezone
11506  if ($match[8] !== '')
11507  {
11508  $timezone = $match[9] * 3600;
11509  $timezone += $match[10] * 60;
11510  if ($match[8] === '-')
11511  {
11512  $timezone = 0 - $timezone;
11513  }
11514  }
11515  // Character timezone
11516  elseif (isset($this->timezone[strtoupper($match[11])]))
11517  {
11518  $timezone = $this->timezone[strtoupper($match[11])];
11519  }
11520  // Assume everything else to be -0000
11521  else
11522  {
11523  $timezone = 0;
11524  }
11525  // Deal with 2/3 digit years
11526  if ($match[4] < 50)
11527  {
11528  $match[4] += 2000;
11529  }
11530  elseif ($match[4] < 1000)
11531  {
11532  $match[4] += 1900;
11533  }
11534  // Second is optional, if it is empty set it to zero
11535  if ($match[7] !== '')
11536  {
11537  $second = $match[7];
11538  }
11539  else
11540  {
11541  $second = 0;
11542  }
11543  return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone;
11544  }
11545  else
11546  {
11547  return false;
11548  }
11549  }
11550 
11551  public function date_rfc850($date)
11552  {
11553  static $pcre;
11554  if (!$pcre)
11555  {
11556  $space = '[\x09\x20]+';
11557  $day_name = $this->day_pcre;
11558  $month = $this->month_pcre;
11559  $day = '([0-9]{1,2})';
11560  $year = $hour = $minute = $second = '([0-9]{2})';
11561  $zone = '([A-Z]{1,5})';
11562  $pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i';
11563  }
11564  if (preg_match($pcre, $date, $match))
11565  {
11566  /*
11567  Capturing subpatterns:
11568  1: Day name
11569  2: Day
11570  3: Month
11571  4: Year
11572  5: Hour
11573  6: Minute
11574  7: Second
11575  8: Timezone
11576  */
11577  // Month
11578  $month = $this->month[strtolower($match[3])];
11579  // Character timezone
11580  if (isset($this->timezone[strtoupper($match[8])]))
11581  {
11582  $timezone = $this->timezone[strtoupper($match[8])];
11583  }
11584  // Assume everything else to be -0000
11585  else
11586  {
11587  $timezone = 0;
11588  }
11589  // Deal with 2 digit year
11590  if ($match[4] < 50)
11591  {
11592  $match[4] += 2000;
11593  }
11594  else
11595  {
11596  $match[4] += 1900;
11597  }
11598  return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone;
11599  }
11600  else
11601  {
11602  return false;
11603  }
11604  }
11605 
11606  public function date_asctime($date)
11607  {
11608  static $pcre;
11609  if (!$pcre)
11610  {
11611  $space = '[\x09\x20]+';
11612  $wday_name = $this->day_pcre;
11613  $mon_name = $this->month_pcre;
11614  $day = '([0-9]{1,2})';
11615  $hour = $sec = $min = '([0-9]{2})';
11616  $year = '([0-9]{4})';
11617  $terminator = '\x0A?\x00?';
11618  $pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i';
11619  }
11620  if (preg_match($pcre, $date, $match))
11621  {
11622  /*
11623  Capturing subpatterns:
11624  1: Day name
11625  2: Month
11626  3: Day
11627  4: Hour
11628  5: Minute
11629  6: Second
11630  7: Year
11631  */
11632  $month = $this->month[strtolower($match[2])];
11633  return gmmktime($match[4], $match[5], $match[6], $month, $match[3], $match[7]);
11634  }
11635  else
11636  {
11637  return false;
11638  }
11639  }
11640 
11641  public function date_strtotime($date)
11642  {
11643  $strtotime = strtotime($date);
11644  if ($strtotime === -1 || $strtotime === false)
11645  {
11646  return false;
11647  }
11648  else
11649  {
11650  return $strtotime;
11651  }
11652  }
11653 }
11655 {
11661  var $separator = ' ';
11662  var $namespace = array('');
11663  var $element = array('');
11664  var $xml_base = array('');
11665  var $xml_base_explicit = array(false);
11666  var $xml_lang = array('');
11667  var $data = array();
11668  var $datas = array(array());
11671  protected $registry;
11673  {
11674  $this->registry = $registry;
11675  }
11676  public function parse(&$data, $encoding)
11677  {
11678  // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
11679  if (strtoupper($encoding) === 'US-ASCII')
11680  {
11681  $this->encoding = 'UTF-8';
11682  }
11683  else
11684  {
11685  $this->encoding = $encoding;
11686  }
11687  // Strip BOM:
11688  // UTF-32 Big Endian BOM
11689  if (substr($data, 0, 4) === "\x00\x00\xFE\xFF")
11690  {
11691  $data = substr($data, 4);
11692  }
11693  // UTF-32 Little Endian BOM
11694  elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00")
11695  {
11696  $data = substr($data, 4);
11697  }
11698  // UTF-16 Big Endian BOM
11699  elseif (substr($data, 0, 2) === "\xFE\xFF")
11700  {
11701  $data = substr($data, 2);
11702  }
11703  // UTF-16 Little Endian BOM
11704  elseif (substr($data, 0, 2) === "\xFF\xFE")
11705  {
11706  $data = substr($data, 2);
11707  }
11708  // UTF-8 BOM
11709  elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
11710  {
11711  $data = substr($data, 3);
11712  }
11713  if (substr($data, 0, 5) === '<?xml' && strspn(substr($data, 5, 1), "\x09\x0A\x0D\x20") && ($pos = strpos($data, '?>')) !== false)
11714  {
11715  $declaration = $this->registry->create('XML_Declaration_Parser', array(substr($data, 5, $pos - 5)));
11716  if ($declaration->parse())
11717  {
11718  $data = substr($data, $pos + 2);
11719  $data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . $data;
11720  }
11721  else
11722  {
11723  $this->error_string = 'SimplePie bug! Please report this!';
11724  return false;
11725  }
11726  }
11727  $return = true;
11728  static $xml_is_sane = null;
11729  if ($xml_is_sane === null)
11730  {
11731  $parser_check = xml_parser_create();
11732  xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
11733  xml_parser_free($parser_check);
11734  $xml_is_sane = isset($values[0]['value']);
11735  }
11736  // Create the parser
11737  if ($xml_is_sane)
11738  {
11739  $xml = xml_parser_create_ns($this->encoding, $this->separator);
11740  xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
11741  xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
11742  xml_set_object($xml, $this);
11743  xml_set_character_data_handler($xml, 'cdata');
11744  xml_set_element_handler($xml, 'tag_open', 'tag_close');
11745  // Parse!
11746  if (!xml_parse($xml, $data, true))
11747  {
11748  $this->error_code = xml_get_error_code($xml);
11749  $this->error_string = xml_error_string($this->error_code);
11750  $return = false;
11751  }
11752  $this->current_line = xml_get_current_line_number($xml);
11753  $this->current_column = xml_get_current_column_number($xml);
11754  $this->current_byte = xml_get_current_byte_index($xml);
11755  xml_parser_free($xml);
11756  return $return;
11757  }
11758  else
11759  {
11760  libxml_clear_errors();
11761  $xml = new XMLReader();
11762  $xml->xml($data);
11763  while (@$xml->read())
11764  {
11765  switch ($xml->nodeType)
11766  {
11767  case constant('XMLReader::END_ELEMENT'):
11768  if ($xml->namespaceURI !== '')
11769  {
11770  $tagName = $xml->namespaceURI . $this->separator . $xml->localName;
11771  }
11772  else
11773  {
11774  $tagName = $xml->localName;
11775  }
11776  $this->tag_close(null, $tagName);
11777  break;
11778  case constant('XMLReader::ELEMENT'):
11779  $empty = $xml->isEmptyElement;
11780  if ($xml->namespaceURI !== '')
11781  {
11782  $tagName = $xml->namespaceURI . $this->separator . $xml->localName;
11783  }
11784  else
11785  {
11786  $tagName = $xml->localName;
11787  }
11788  $attributes = array();
11789  while ($xml->moveToNextAttribute())
11790  {
11791  if ($xml->namespaceURI !== '')
11792  {
11793  $attrName = $xml->namespaceURI . $this->separator . $xml->localName;
11794  }
11795  else
11796  {
11797  $attrName = $xml->localName;
11798  }
11799  $attributes[$attrName] = $xml->value;
11800  }
11801  $this->tag_open(null, $tagName, $attributes);
11802  if ($empty)
11803  {
11804  $this->tag_close(null, $tagName);
11805  }
11806  break;
11807  case constant('XMLReader::TEXT'):
11808  case constant('XMLReader::CDATA'):
11809  $this->cdata(null, $xml->value);
11810  break;
11811  }
11812  }
11813  if ($error = libxml_get_last_error())
11814  {
11815  $this->error_code = $error->code;
11816  $this->error_string = $error->message;
11817  $this->current_line = $error->line;
11818  $this->current_column = $error->column;
11819  return false;
11820  }
11821  else
11822  {
11823  return true;
11824  }
11825  }
11826  }
11827  public function get_error_code()
11828  {
11829  return $this->error_code;
11830  }
11831  public function get_error_string()
11832  {
11833  return $this->error_string;
11834  }
11835  public function get_current_line()
11836  {
11837  return $this->current_line;
11838  }
11839  public function get_current_column()
11840  {
11841  return $this->current_column;
11842  }
11843  public function get_current_byte()
11844  {
11845  return $this->current_byte;
11846  }
11847  public function get_data()
11848  {
11849  return $this->data;
11850  }
11851  public function tag_open($parser, $tag, $attributes)
11852  {
11853  list($this->namespace[], $this->element[]) = $this->split_ns($tag);
11854  $attribs = array();
11855  foreach ($attributes as $name => $value)
11856  {
11857  list($attrib_namespace, $attribute) = $this->split_ns($name);
11858  $attribs[$attrib_namespace][$attribute] = $value;
11859  }
11860  if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['base']))
11861  {
11862  $base = $this->registry->call('Misc', 'absolutize_url', array($attribs[SIMPLEPIE_NAMESPACE_XML]['base'], end($this->xml_base)));
11863  if ($base !== false)
11864  {
11865  $this->xml_base[] = $base;
11866  $this->xml_base_explicit[] = true;
11867  }
11868  }
11869  else
11870  {
11871  $this->xml_base[] = end($this->xml_base);
11872  $this->xml_base_explicit[] = end($this->xml_base_explicit);
11873  }
11874  if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['lang']))
11875  {
11876  $this->xml_lang[] = $attribs[SIMPLEPIE_NAMESPACE_XML]['lang'];
11877  }
11878  else
11879  {
11880  $this->xml_lang[] = end($this->xml_lang);
11881  }
11882  if ($this->current_xhtml_construct >= 0)
11883  {
11884  $this->current_xhtml_construct++;
11885  if (end($this->namespace) === SIMPLEPIE_NAMESPACE_XHTML)
11886  {
11887  $this->data['data'] .= '<' . end($this->element);
11888  if (isset($attribs['']))
11889  {
11890  foreach ($attribs[''] as $name => $value)
11891  {
11892  $this->data['data'] .= ' ' . $name . '="' . htmlspecialchars($value, ENT_COMPAT, $this->encoding) . '"';
11893  }
11894  }
11895  $this->data['data'] .= '>';
11896  }
11897  }
11898  else
11899  {
11900  $this->datas[] =& $this->data;
11901  $this->data =& $this->data['child'][end($this->namespace)][end($this->element)][];
11902  $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));
11903  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')
11904  || (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')
11905  || (end($this->namespace) === SIMPLEPIE_NAMESPACE_RSS_20 && in_array(end($this->element), array('title')))
11906  || (end($this->namespace) === SIMPLEPIE_NAMESPACE_RSS_090 && in_array(end($this->element), array('title')))
11907  || (end($this->namespace) === SIMPLEPIE_NAMESPACE_RSS_10 && in_array(end($this->element), array('title'))))
11908  {
11909  $this->current_xhtml_construct = 0;
11910  }
11911  }
11912  }
11913  public function cdata($parser, $cdata)
11914  {
11915  if ($this->current_xhtml_construct >= 0)
11916  {
11917  $this->data['data'] .= htmlspecialchars($cdata, ENT_QUOTES, $this->encoding);
11918  }
11919  else
11920  {
11921  $this->data['data'] .= $cdata;
11922  }
11923  }
11924  public function tag_close($parser, $tag)
11925  {
11926  if ($this->current_xhtml_construct >= 0)
11927  {
11928  $this->current_xhtml_construct--;
11929  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')))
11930  {
11931  $this->data['data'] .= '</' . end($this->element) . '>';
11932  }
11933  }
11934  if ($this->current_xhtml_construct === -1)
11935  {
11936  $this->data =& $this->datas[count($this->datas) - 1];
11937  array_pop($this->datas);
11938  }
11939  array_pop($this->element);
11940  array_pop($this->namespace);
11941  array_pop($this->xml_base);
11942  array_pop($this->xml_base_explicit);
11943  array_pop($this->xml_lang);
11944  }
11945  public function split_ns($string)
11946  {
11947  static $cache = array();
11948  if (!isset($cache[$string]))
11949  {
11950  if ($pos = strpos($string, $this->separator))
11951  {
11952  static $separator_length;
11953  if (!$separator_length)
11954  {
11955  $separator_length = strlen($this->separator);
11956  }
11957  $namespace = substr($string, 0, $pos);
11958  $local_name = substr($string, $pos + $separator_length);
11959  if (strtolower($namespace) === SIMPLEPIE_NAMESPACE_ITUNES)
11960  {
11961  $namespace = SIMPLEPIE_NAMESPACE_ITUNES;
11962  }
11963  // Normalize the Media RSS namespaces
11964  if ($namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG ||
11965  $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2 ||
11966  $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3 ||
11967  $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4 ||
11968  $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5 )
11969  {
11970  $namespace = SIMPLEPIE_NAMESPACE_MEDIARSS;
11971  }
11972  $cache[$string] = array($namespace, $local_name);
11973  }
11974  else
11975  {
11976  $cache[$string] = array('', $string);
11977  }
11978  }
11979  return $cache[$string];
11980  }
11981 }
11983 {
11984 
11985  var $scheme;
11986 
11987  var $value;
11988 
11989  public function __construct($scheme = null, $value = null)
11990  {
11991  $this->scheme = $scheme;
11992  $this->value = $value;
11993  }
11994 
11995  public function __toString()
11996  {
11997  // There is no $this->data here
11998  return md5(serialize($this));
11999  }
12000 
12001  public function get_scheme()
12002  {
12003  if ($this->scheme !== null)
12004  {
12005  return $this->scheme;
12006  }
12007  else
12008  {
12009  return null;
12010  }
12011  }
12012 
12013  public function get_value()
12014  {
12015  if ($this->value !== null)
12016  {
12017  return $this->value;
12018  }
12019  else
12020  {
12021  return null;
12022  }
12023  }
12024 }
12026 {
12027 
12028  protected $default = array(
12029  'Cache' => 'SimplePie_Cache',
12030  'Locator' => 'SimplePie_Locator',
12031  'Parser' => 'SimplePie_Parser',
12032  'File' => 'SimplePie_File',
12033  'Sanitize' => 'SimplePie_Sanitize',
12034  'Item' => 'SimplePie_Item',
12035  'Author' => 'SimplePie_Author',
12036  'Category' => 'SimplePie_Category',
12037  'Enclosure' => 'SimplePie_Enclosure',
12038  'Caption' => 'SimplePie_Caption',
12039  'Copyright' => 'SimplePie_Copyright',
12040  'Credit' => 'SimplePie_Credit',
12041  'Rating' => 'SimplePie_Rating',
12042  'Restriction' => 'SimplePie_Restriction',
12043  'Content_Type_Sniffer' => 'SimplePie_Content_Type_Sniffer',
12044  'Source' => 'SimplePie_Source',
12045  'Misc' => 'SimplePie_Misc',
12046  'XML_Declaration_Parser' => 'SimplePie_XML_Declaration_Parser',
12047  'Parse_Date' => 'SimplePie_Parse_Date',
12048  );
12049 
12050  protected $classes = array();
12051 
12052  protected $legacy = array();
12053 
12054  public function __construct() { }
12055 
12056  public function register($type, $class, $legacy = false)
12057  {
12058  if (!is_subclass_of($class, $this->default[$type]))
12059  {
12060  return false;
12061  }
12062  $this->classes[$type] = $class;
12063  if ($legacy)
12064  {
12065  $this->legacy[] = $class;
12066  }
12067  return true;
12068  }
12069 
12070  public function get_class($type)
12071  {
12072  if (!empty($this->classes[$type]))
12073  {
12074  return $this->classes[$type];
12075  }
12076  if (!empty($this->default[$type]))
12077  {
12078  return $this->default[$type];
12079  }
12080  return null;
12081  }
12082 
12083  public function &create($type, $parameters = array())
12084  {
12085  $class = $this->get_class($type);
12086  if (in_array($class, $this->legacy))
12087  {
12088  switch ($type)
12089  {
12090  case 'locator':
12091  // Legacy: file, timeout, useragent, file_class, max_checked_feeds, content_type_sniffer_class
12092  // Specified: file, timeout, useragent, max_checked_feeds
12093  $replacement = array($this->get_class('file'), $parameters[3], $this->get_class('content_type_sniffer'));
12094  array_splice($parameters, 3, 1, $replacement);
12095  break;
12096  }
12097  }
12098  if (!method_exists($class, '__construct'))
12099  {
12100  $instance = new $class;
12101  }
12102  else
12103  {
12104  $reflector = new ReflectionClass($class);
12105  $instance = $reflector->newInstanceArgs($parameters);
12106  }
12107  if (method_exists($instance, 'set_registry'))
12108  {
12109  $instance->set_registry($this);
12110  }
12111  return $instance;
12112  }
12113 
12114  public function &call($type, $method, $parameters = array())
12115  {
12116  $class = $this->get_class($type);
12117  if (in_array($class, $this->legacy))
12118  {
12119  switch ($type)
12120  {
12121  case 'Cache':
12122  // For backwards compatibility with old non-static
12123  // Cache::create() methods
12124  if ($method === 'get_handler')
12125  {
12126  $result = @call_user_func_array(array($class, 'create'), $parameters);
12127  return $result;
12128  }
12129  break;
12130  }
12131  }
12132  $result = call_user_func_array(array($class, $method), $parameters);
12133  return $result;
12134  }
12135 }
12137 {
12138 
12140 
12141  var $type;
12142 
12143  var $value;
12144 
12145  public function __construct($relationship = null, $type = null, $value = null)
12146  {
12147  $this->relationship = $relationship;
12148  $this->type = $type;
12149  $this->value = $value;
12150  }
12151 
12152  public function __toString()
12153  {
12154  // There is no $this->data here
12155  return md5(serialize($this));
12156  }
12157 
12158  public function get_relationship()
12159  {
12160  if ($this->relationship !== null)
12161  {
12162  return $this->relationship;
12163  }
12164  else
12165  {
12166  return null;
12167  }
12168  }
12169 
12170  public function get_type()
12171  {
12172  if ($this->type !== null)
12173  {
12174  return $this->type;
12175  }
12176  else
12177  {
12178  return null;
12179  }
12180  }
12181 
12182  public function get_value()
12183  {
12184  if ($this->value !== null)
12185  {
12186  return $this->value;
12187  }
12188  else
12189  {
12190  return null;
12191  }
12192  }
12193 }
12195 {
12196  // Private vars
12197  var $base;
12198  // Options
12199  var $remove_div = true;
12200  var $image_handler = '';
12201  var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
12203  var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
12204  var $strip_comments = false;
12205  var $output_encoding = 'UTF-8';
12206  var $enable_cache = true;
12207  var $cache_location = './cache';
12209  var $timeout = 10;
12210  var $useragent = '';
12211  var $force_fsockopen = false;
12213  public function __construct()
12214  {
12215  // Set defaults
12216  $this->set_url_replacements(null);
12217  }
12218  public function remove_div($enable = true)
12219  {
12220  $this->remove_div = (bool) $enable;
12221  }
12222  public function set_image_handler($page = false)
12223  {
12224  if ($page)
12225  {
12226  $this->image_handler = (string) $page;
12227  }
12228  else
12229  {
12230  $this->image_handler = false;
12231  }
12232  }
12233  public function set_registry(SimplePie_Registry $registry)
12234  {
12235  $this->registry = $registry;
12236  }
12237  public function pass_cache_data($enable_cache = true, $cache_location = './cache', $cache_name_function = 'md5', $cache_class = 'SimplePie_Cache')
12238  {
12239  if (isset($enable_cache))
12240  {
12241  $this->enable_cache = (bool) $enable_cache;
12242  }
12243  if ($cache_location)
12244  {
12245  $this->cache_location = (string) $cache_location;
12246  }
12247  if ($cache_name_function)
12248  {
12249  $this->cache_name_function = (string) $cache_name_function;
12250  }
12251  }
12252  public function pass_file_data($file_class = 'SimplePie_File', $timeout = 10, $useragent = '', $force_fsockopen = false)
12253  {
12254  if ($timeout)
12255  {
12256  $this->timeout = (string) $timeout;
12257  }
12258  if ($useragent)
12259  {
12260  $this->useragent = (string) $useragent;
12261  }
12262  if ($force_fsockopen)
12263  {
12264  $this->force_fsockopen = (string) $force_fsockopen;
12265  }
12266  }
12267  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'))
12268  {
12269  if ($tags)
12270  {
12271  if (is_array($tags))
12272  {
12273  $this->strip_htmltags = $tags;
12274  }
12275  else
12276  {
12277  $this->strip_htmltags = explode(',', $tags);
12278  }
12279  }
12280  else
12281  {
12282  $this->strip_htmltags = false;
12283  }
12284  }
12285  public function encode_instead_of_strip($encode = false)
12286  {
12287  $this->encode_instead_of_strip = (bool) $encode;
12288  }
12289  public function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'))
12290  {
12291  if ($attribs)
12292  {
12293  if (is_array($attribs))
12294  {
12295  $this->strip_attributes = $attribs;
12296  }
12297  else
12298  {
12299  $this->strip_attributes = explode(',', $attribs);
12300  }
12301  }
12302  else
12303  {
12304  $this->strip_attributes = false;
12305  }
12306  }
12307  public function strip_comments($strip = false)
12308  {
12309  $this->strip_comments = (bool) $strip;
12310  }
12311  public function set_output_encoding($encoding = 'UTF-8')
12312  {
12313  $this->output_encoding = (string) $encoding;
12314  }
12315 
12316  public function set_url_replacements($element_attribute = null)
12317  {
12318  if ($element_attribute === null)
12319  {
12320  $element_attribute = array(
12321  'a' => 'href',
12322  'area' => 'href',
12323  'blockquote' => 'cite',
12324  'del' => 'cite',
12325  'form' => 'action',
12326  'img' => array(
12327  'longdesc',
12328  'src'
12329  ),
12330  'input' => 'src',
12331  'ins' => 'cite',
12332  'q' => 'cite'
12333  );
12334  }
12335  $this->replace_url_attributes = (array) $element_attribute;
12336  }
12337  public function sanitize($data, $type, $base = '')
12338  {
12339  $data = trim($data);
12340  if ($data !== '' || $type & SIMPLEPIE_CONSTRUCT_IRI)
12341  {
12342  if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML)
12343  {
12344  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))
12345  {
12346  $type |= SIMPLEPIE_CONSTRUCT_HTML;
12347  }
12348  else
12349  {
12350  $type |= SIMPLEPIE_CONSTRUCT_TEXT;
12351  }
12352  }
12353  if ($type & SIMPLEPIE_CONSTRUCT_BASE64)
12354  {
12355  $data = base64_decode($data);
12356  }
12358  {
12359  $document = new DOMDocument();
12360  $document->encoding = 'UTF-8';
12361  $data = $this->preprocess($data, $type);
12362  set_error_handler(array('SimplePie_Misc', 'silence_errors'));
12363  $document->loadHTML($data);
12364  restore_error_handler();
12365  // Strip comments
12366  if ($this->strip_comments)
12367  {
12368  $xpath = new DOMXPath($document);
12369  $comments = $xpath->query('//comment()');
12370  foreach ($comments as $comment)
12371  {
12372  $comment->parentNode->removeChild($comment);
12373  }
12374  }
12375  // Strip out HTML tags and attributes that might cause various security problems.
12376  // Based on recommendations by Mark Pilgrim at:
12377  // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
12378  if ($this->strip_htmltags)
12379  {
12380  foreach ($this->strip_htmltags as $tag)
12381  {
12382  $this->strip_tag($tag, $document, $type);
12383  }
12384  }
12385  if ($this->strip_attributes)
12386  {
12387  foreach ($this->strip_attributes as $attrib)
12388  {
12389  $this->strip_attr($attrib, $document);
12390  }
12391  }
12392  // Replace relative URLs
12393  $this->base = $base;
12394  foreach ($this->replace_url_attributes as $element => $attributes)
12395  {
12396  $this->replace_urls($document, $element, $attributes);
12397  }
12398  // If image handling (caching, etc.) is enabled, cache and rewrite all the image tags.
12399  if (isset($this->image_handler) && ((string) $this->image_handler) !== '' && $this->enable_cache)
12400  {
12401  $images = $document->getElementsByTagName('img');
12402  foreach ($images as $img)
12403  {
12404  if ($img->hasAttribute('src'))
12405  {
12406  $image_url = call_user_func($this->cache_name_function, $img->getAttribute('src'));
12407  $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, $image_url, 'spi'));
12408  if ($cache->load())
12409  {
12410  $img->setAttribute('src', $this->image_handler . $image_url);
12411  }
12412  else
12413  {
12414  $file = $this->registry->create('File', array($img['attribs']['src']['data'], $this->timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen));
12415  $headers = $file->headers;
12416  if ($file->success && ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
12417  {
12418  if ($cache->save(array('headers' => $file->headers, 'body' => $file->body)))
12419  {
12420  $img->setAttribute('src', $this->image_handler . $image_url);
12421  }
12422  else
12423  {
12424  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);
12425  }
12426  }
12427  }
12428  }
12429  }
12430  }
12431  // Remove the DOCTYPE
12432  // Seems to cause segfaulting if we don't do this
12433  if ($document->firstChild instanceof DOMDocumentType)
12434  {
12435  $document->removeChild($document->firstChild);
12436  }
12437  // Move everything from the body to the root
12438  $real_body = $document->getElementsByTagName('body')->item(0)->childNodes->item(0);
12439  $document->replaceChild($real_body, $document->firstChild);
12440  // Finally, convert to a HTML string
12441  $data = trim($document->saveHTML());
12442  if ($this->remove_div)
12443  {
12444  $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '', $data);
12445  $data = preg_replace('/<\/div>$/', '', $data);
12446  }
12447  else
12448  {
12449  $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '<div>', $data);
12450  }
12451  }
12452  if ($type & SIMPLEPIE_CONSTRUCT_IRI)
12453  {
12454  $absolute = $this->registry->call('Misc', 'absolutize_url', array($data, $base));
12455  if ($absolute !== false)
12456  {
12457  $data = $absolute;
12458  }
12459  }
12460  if ($type & (SIMPLEPIE_CONSTRUCT_TEXT | SIMPLEPIE_CONSTRUCT_IRI))
12461  {
12462  $data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
12463  }
12464  if ($this->output_encoding !== 'UTF-8')
12465  {
12466  $data = $this->registry->call('Misc', 'change_encoding', array($data, 'UTF-8', $this->output_encoding));
12467  }
12468  }
12469  return $data;
12470  }
12471  protected function preprocess($html, $type)
12472  {
12473  $ret = '';
12474  if ($type & ~SIMPLEPIE_CONSTRUCT_XHTML)
12475  {
12476  // Atom XHTML constructs are wrapped with a div by default
12477  // Note: No protection if $html contains a stray </div>!
12478  $html = '<div>' . $html . '</div>';
12479  $ret .= '<!DOCTYPE html>';
12480  $content_type = 'text/html';
12481  }
12482  else
12483  {
12484  $ret .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
12485  $content_type = 'application/xhtml+xml';
12486  }
12487  $ret .= '<html><head>';
12488  $ret .= '<meta http-equiv="Content-Type" content="' . $content_type . '; charset=utf-8" />';
12489  $ret .= '</head><body>' . $html . '</body></html>';
12490  return $ret;
12491  }
12492  public function replace_urls($document, $tag, $attributes)
12493  {
12494  if (!is_array($attributes))
12495  {
12496  $attributes = array($attributes);
12497  }
12498  if (!is_array($this->strip_htmltags) || !in_array($tag, $this->strip_htmltags))
12499  {
12500  $elements = $document->getElementsByTagName($tag);
12501  foreach ($elements as $element)
12502  {
12503  foreach ($attributes as $attribute)
12504  {
12505  if ($element->hasAttribute($attribute))
12506  {
12507  $value = $this->registry->call('Misc', 'absolutize_url', array($element->getAttribute($attribute), $this->base));
12508  if ($value !== false)
12509  {
12510  $element->setAttribute($attribute, $value);
12511  }
12512  }
12513  }
12514  }
12515  }
12516  }
12517  public function do_strip_htmltags($match)
12518  {
12519  if ($this->encode_instead_of_strip)
12520  {
12521  if (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
12522  {
12523  $match[1] = htmlspecialchars($match[1], ENT_COMPAT, 'UTF-8');
12524  $match[2] = htmlspecialchars($match[2], ENT_COMPAT, 'UTF-8');
12525  return "&lt;$match[1]$match[2]&gt;$match[3]&lt;/$match[1]&gt;";
12526  }
12527  else
12528  {
12529  return htmlspecialchars($match[0], ENT_COMPAT, 'UTF-8');
12530  }
12531  }
12532  elseif (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
12533  {
12534  return $match[4];
12535  }
12536  else
12537  {
12538  return '';
12539  }
12540  }
12541  protected function strip_tag($tag, $document, $type)
12542  {
12543  $xpath = new DOMXPath($document);
12544  $elements = $xpath->query('body//' . $tag);
12545  if ($this->encode_instead_of_strip)
12546  {
12547  foreach ($elements as $element)
12548  {
12549  $fragment = $document->createDocumentFragment();
12550  // For elements which aren't script or style, include the tag itself
12551  if (!in_array($tag, array('script', 'style')))
12552  {
12553  $text = '<' . $tag;
12554  if ($element->hasAttributes())
12555  {
12556  $attrs = array();
12557  foreach ($element->attributes as $name => $attr)
12558  {
12559  $value = $attr->value;
12560  // In XHTML, empty values should never exist, so we repeat the value
12561  if (empty($value) && ($type & SIMPLEPIE_CONSTRUCT_XHTML))
12562  {
12563  $value = $name;
12564  }
12565  // For HTML, empty is fine
12566  elseif (empty($value) && ($type & SIMPLEPIE_CONSTRUCT_HTML))
12567  {
12568  $attrs[] = $name;
12569  continue;
12570  }
12571  // Standard attribute text
12572  $attrs[] = $name . '="' . $attr->value . '"';
12573  }
12574  $text .= ' ' . implode(' ', $attrs);
12575  }
12576  $text .= '>';
12577  $fragment->appendChild(new DOMText($text));
12578  }
12579  $number = $element->childNodes->length;
12580  for ($i = $number; $i > 0; $i--)
12581  {
12582  $child = $element->childNodes->item(0);
12583  $fragment->appendChild($child);
12584  }
12585  if (!in_array($tag, array('script', 'style')))
12586  {
12587  $fragment->appendChild(new DOMText('</' . $tag . '>'));
12588  }
12589  $element->parentNode->replaceChild($fragment, $element);
12590  }
12591  return;
12592  }
12593  elseif (in_array($tag, array('script', 'style')))
12594  {
12595  foreach ($elements as $element)
12596  {
12597  $element->parentNode->removeChild($element);
12598  }
12599  return;
12600  }
12601  else
12602  {
12603  foreach ($elements as $element)
12604  {
12605  $fragment = $document->createDocumentFragment();
12606  $number = $element->childNodes->length;
12607  for ($i = $number; $i > 0; $i--)
12608  {
12609  $child = $element->childNodes->item(0);
12610  $fragment->appendChild($child);
12611  }
12612  $element->parentNode->replaceChild($fragment, $element);
12613  }
12614  }
12615  }
12616  protected function strip_attr($attrib, $document)
12617  {
12618  $xpath = new DOMXPath($document);
12619  $elements = $xpath->query('//*[@' . $attrib . ']');
12620  foreach ($elements as $element)
12621  {
12622  $element->removeAttribute($attrib);
12623  }
12624  }
12625 }
12627 {
12628  var $item;
12629  var $data = array();
12630  protected $registry;
12631  public function __construct($item, $data)
12632  {
12633  $this->item = $item;
12634  $this->data = $data;
12635  }
12637  {
12638  $this->registry = $registry;
12639  }
12640  public function __toString()
12641  {
12642  return md5(serialize($this->data));
12643  }
12644  public function get_source_tags($namespace, $tag)
12645  {
12646  if (isset($this->data['child'][$namespace][$tag]))
12647  {
12648  return $this->data['child'][$namespace][$tag];
12649  }
12650  else
12651  {
12652  return null;
12653  }
12654  }
12655  public function get_base($element = array())
12656  {
12657  return $this->item->get_base($element);
12658  }
12659  public function sanitize($data, $type, $base = '')
12660  {
12661  return $this->item->sanitize($data, $type, $base);
12662  }
12663  public function get_item()
12664  {
12665  return $this->item;
12666  }
12667  public function get_title()
12668  {
12669  if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
12670  {
12671  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
12672  }
12673  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
12674  {
12675  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
12676  }
12677  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
12678  {
12679  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
12680  }
12681  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
12682  {
12683  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
12684  }
12685  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
12686  {
12687  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
12688  }
12689  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
12690  {
12691  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
12692  }
12693  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
12694  {
12695  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
12696  }
12697  else
12698  {
12699  return null;
12700  }
12701  }
12702  public function get_category($key = 0)
12703  {
12704  $categories = $this->get_categories();
12705  if (isset($categories[$key]))
12706  {
12707  return $categories[$key];
12708  }
12709  else
12710  {
12711  return null;
12712  }
12713  }
12714  public function get_categories()
12715  {
12716  $categories = array();
12717  foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
12718  {
12719  $term = null;
12720  $scheme = null;
12721  $label = null;
12722  if (isset($category['attribs']['']['term']))
12723  {
12724  $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
12725  }
12726  if (isset($category['attribs']['']['scheme']))
12727  {
12728  $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
12729  }
12730  if (isset($category['attribs']['']['label']))
12731  {
12732  $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
12733  }
12734  $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
12735  }
12736  foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
12737  {
12738  // This is really the label, but keep this as the term also for BC.
12739  // Label will also work on retrieving because that falls back to term.
12740  $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
12741  if (isset($category['attribs']['']['domain']))
12742  {
12743  $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
12744  }
12745  else
12746  {
12747  $scheme = null;
12748  }
12749  $categories[] = $this->registry->create('Category', array($term, $scheme, null));
12750  }
12751  foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
12752  {
12753  $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
12754  }
12755  foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
12756  {
12757  $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
12758  }
12759  if (!empty($categories))
12760  {
12761  return array_unique($categories);
12762  }
12763  else
12764  {
12765  return null;
12766  }
12767  }
12768  public function get_author($key = 0)
12769  {
12770  $authors = $this->get_authors();
12771  if (isset($authors[$key]))
12772  {
12773  return $authors[$key];
12774  }
12775  else
12776  {
12777  return null;
12778  }
12779  }
12780  public function get_authors()
12781  {
12782  $authors = array();
12783  foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
12784  {
12785  $name = null;
12786  $uri = null;
12787  $email = null;
12788  if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
12789  {
12790  $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
12791  }
12792  if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
12793  {
12794  $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]));
12795  }
12796  if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
12797  {
12798  $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
12799  }
12800  if ($name !== null || $email !== null || $uri !== null)
12801  {
12802  $authors[] = $this->registry->create('Author', array($name, $uri, $email));
12803  }
12804  }
12805  if ($author = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
12806  {
12807  $name = null;
12808  $url = null;
12809  $email = null;
12810  if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
12811  {
12812  $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
12813  }
12814  if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
12815  {
12816  $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]));
12817  }
12818  if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
12819  {
12820  $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
12821  }
12822  if ($name !== null || $email !== null || $url !== null)
12823  {
12824  $authors[] = $this->registry->create('Author', array($name, $url, $email));
12825  }
12826  }
12827  foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
12828  {
12829  $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
12830  }
12831  foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
12832  {
12833  $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
12834  }
12835  foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
12836  {
12837  $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
12838  }
12839  if (!empty($authors))
12840  {
12841  return array_unique($authors);
12842  }
12843  else
12844  {
12845  return null;
12846  }
12847  }
12848  public function get_contributor($key = 0)
12849  {
12850  $contributors = $this->get_contributors();
12851  if (isset($contributors[$key]))
12852  {
12853  return $contributors[$key];
12854  }
12855  else
12856  {
12857  return null;
12858  }
12859  }
12860  public function get_contributors()
12861  {
12862  $contributors = array();
12863  foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
12864  {
12865  $name = null;
12866  $uri = null;
12867  $email = null;
12868  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
12869  {
12870  $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
12871  }
12872  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
12873  {
12874  $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]));
12875  }
12876  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
12877  {
12878  $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
12879  }
12880  if ($name !== null || $email !== null || $uri !== null)
12881  {
12882  $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
12883  }
12884  }
12885  foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
12886  {
12887  $name = null;
12888  $url = null;
12889  $email = null;
12890  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
12891  {
12892  $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
12893  }
12894  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
12895  {
12896  $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]));
12897  }
12898  if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
12899  {
12900  $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
12901  }
12902  if ($name !== null || $email !== null || $url !== null)
12903  {
12904  $contributors[] = $this->registry->create('Author', array($name, $url, $email));
12905  }
12906  }
12907  if (!empty($contributors))
12908  {
12909  return array_unique($contributors);
12910  }
12911  else
12912  {
12913  return null;
12914  }
12915  }
12916  public function get_link($key = 0, $rel = 'alternate')
12917  {
12918  $links = $this->get_links($rel);
12919  if (isset($links[$key]))
12920  {
12921  return $links[$key];
12922  }
12923  else
12924  {
12925  return null;
12926  }
12927  }
12928 
12929  public function get_permalink()
12930  {
12931  return $this->get_link(0);
12932  }
12933  public function get_links($rel = 'alternate')
12934  {
12935  if (!isset($this->data['links']))
12936  {
12937  $this->data['links'] = array();
12938  if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
12939  {
12940  foreach ($links as $link)
12941  {
12942  if (isset($link['attribs']['']['href']))
12943  {
12944  $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
12945  $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
12946  }
12947  }
12948  }
12949  if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
12950  {
12951  foreach ($links as $link)
12952  {
12953  if (isset($link['attribs']['']['href']))
12954  {
12955  $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
12956  $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
12957  }
12958  }
12959  }
12960  if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
12961  {
12962  $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
12963  }
12964  if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
12965  {
12966  $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
12967  }
12968  if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
12969  {
12970  $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
12971  }
12972  $keys = array_keys($this->data['links']);
12973  foreach ($keys as $key)
12974  {
12975  if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
12976  {
12977  if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
12978  {
12979  $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
12980  $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
12981  }
12982  else
12983  {
12984  $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
12985  }
12986  }
12987  elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
12988  {
12989  $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
12990  }
12991  $this->data['links'][$key] = array_unique($this->data['links'][$key]);
12992  }
12993  }
12994  if (isset($this->data['links'][$rel]))
12995  {
12996  return $this->data['links'][$rel];
12997  }
12998  else
12999  {
13000  return null;
13001  }
13002  }
13003  public function get_description()
13004  {
13005  if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
13006  {
13007  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
13008  }
13009  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
13010  {
13011  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
13012  }
13013  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
13014  {
13015  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
13016  }
13017  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
13018  {
13019  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
13020  }
13021  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
13022  {
13023  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
13024  }
13025  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
13026  {
13027  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
13028  }
13029  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
13030  {
13031  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
13032  }
13033  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
13034  {
13035  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
13036  }
13037  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
13038  {
13039  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
13040  }
13041  else
13042  {
13043  return null;
13044  }
13045  }
13046  public function get_copyright()
13047  {
13048  if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
13049  {
13050  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
13051  }
13052  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
13053  {
13054  return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
13055  }
13056  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
13057  {
13058  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
13059  }
13060  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
13061  {
13062  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
13063  }
13064  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
13065  {
13066  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
13067  }
13068  else
13069  {
13070  return null;
13071  }
13072  }
13073  public function get_language()
13074  {
13075  if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
13076  {
13077  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
13078  }
13079  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
13080  {
13081  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
13082  }
13083  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
13084  {
13085  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
13086  }
13087  elseif (isset($this->data['xml_lang']))
13088  {
13089  return $this->sanitize($this->data['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
13090  }
13091  else
13092  {
13093  return null;
13094  }
13095  }
13096  public function get_latitude()
13097  {
13098  if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
13099  {
13100  return (float) $return[0]['data'];
13101  }
13102  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))
13103  {
13104  return (float) $match[1];
13105  }
13106  else
13107  {
13108  return null;
13109  }
13110  }
13111  public function get_longitude()
13112  {
13113  if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
13114  {
13115  return (float) $return[0]['data'];
13116  }
13117  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
13118  {
13119  return (float) $return[0]['data'];
13120  }
13121  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))
13122  {
13123  return (float) $match[2];
13124  }
13125  else
13126  {
13127  return null;
13128  }
13129  }
13130  public function get_image_url()
13131  {
13132  if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
13133  {
13134  return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
13135  }
13136  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
13137  {
13138  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
13139  }
13140  elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
13141  {
13142  return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
13143  }
13144  else
13145  {
13146  return null;
13147  }
13148  }
13149 }
13151 {
13152 
13153  var $version = '1.0';
13154 
13155  var $encoding = 'UTF-8';
13156 
13157  var $standalone = false;
13158 
13159  var $state = 'before_version_name';
13160 
13161  var $data = '';
13162 
13163  var $data_length = 0;
13164 
13165  var $position = 0;
13166 
13167  public function __construct($data)
13168  {
13169  $this->data = $data;
13170  $this->data_length = strlen($this->data);
13171  }
13172 
13173  public function parse()
13174  {
13175  while ($this->state && $this->state !== 'emit' && $this->has_data())
13176  {
13177  $state = $this->state;
13178  $this->$state();
13179  }
13180  $this->data = '';
13181  if ($this->state === 'emit')
13182  {
13183  return true;
13184  }
13185  else
13186  {
13187  $this->version = '';
13188  $this->encoding = '';
13189  $this->standalone = '';
13190  return false;
13191  }
13192  }
13193 
13194  public function has_data()
13195  {
13196  return (bool) ($this->position < $this->data_length);
13197  }
13198 
13199  public function skip_whitespace()
13200  {
13201  $whitespace = strspn($this->data, "\x09\x0A\x0D\x20", $this->position);
13202  $this->position += $whitespace;
13203  return $whitespace;
13204  }
13205 
13206  public function get_value()
13207  {
13208  $quote = substr($this->data, $this->position, 1);
13209  if ($quote === '"' || $quote === "'")
13210  {
13211  $this->position++;
13212  $len = strcspn($this->data, $quote, $this->position);
13213  if ($this->has_data())
13214  {
13215  $value = substr($this->data, $this->position, $len);
13216  $this->position += $len + 1;
13217  return $value;
13218  }
13219  }
13220  return false;
13221  }
13222  public function before_version_name()
13223  {
13224  if ($this->skip_whitespace())
13225  {
13226  $this->state = 'version_name';
13227  }
13228  else
13229  {
13230  $this->state = false;
13231  }
13232  }
13233  public function version_name()
13234  {
13235  if (substr($this->data, $this->position, 7) === 'version')
13236  {
13237  $this->position += 7;
13238  $this->skip_whitespace();
13239  $this->state = 'version_equals';
13240  }
13241  else
13242  {
13243  $this->state = false;
13244  }
13245  }
13246  public function version_equals()
13247  {
13248  if (substr($this->data, $this->position, 1) === '=')
13249  {
13250  $this->position++;
13251  $this->skip_whitespace();
13252  $this->state = 'version_value';
13253  }
13254  else
13255  {
13256  $this->state = false;
13257  }
13258  }
13259  public function version_value()
13260  {
13261  if ($this->version = $this->get_value())
13262  {
13263  $this->skip_whitespace();
13264  if ($this->has_data())
13265  {
13266  $this->state = 'encoding_name';
13267  }
13268  else
13269  {
13270  $this->state = 'emit';
13271  }
13272  }
13273  else
13274  {
13275  $this->state = false;
13276  }
13277  }
13278  public function encoding_name()
13279  {
13280  if (substr($this->data, $this->position, 8) === 'encoding')
13281  {
13282  $this->position += 8;
13283  $this->skip_whitespace();
13284  $this->state = 'encoding_equals';
13285  }
13286  else
13287  {
13288  $this->state = 'standalone_name';
13289  }
13290  }
13291  public function encoding_equals()
13292  {
13293  if (substr($this->data, $this->position, 1) === '=')
13294  {
13295  $this->position++;
13296  $this->skip_whitespace();
13297  $this->state = 'encoding_value';
13298  }
13299  else
13300  {
13301  $this->state = false;
13302  }
13303  }
13304  public function encoding_value()
13305  {
13306  if ($this->encoding = $this->get_value())
13307  {
13308  $this->skip_whitespace();
13309  if ($this->has_data())
13310  {
13311  $this->state = 'standalone_name';
13312  }
13313  else
13314  {
13315  $this->state = 'emit';
13316  }
13317  }
13318  else
13319  {
13320  $this->state = false;
13321  }
13322  }
13323  public function standalone_name()
13324  {
13325  if (substr($this->data, $this->position, 10) === 'standalone')
13326  {
13327  $this->position += 10;
13328  $this->skip_whitespace();
13329  $this->state = 'standalone_equals';
13330  }
13331  else
13332  {
13333  $this->state = false;
13334  }
13335  }
13336  public function standalone_equals()
13337  {
13338  if (substr($this->data, $this->position, 1) === '=')
13339  {
13340  $this->position++;
13341  $this->skip_whitespace();
13342  $this->state = 'standalone_value';
13343  }
13344  else
13345  {
13346  $this->state = false;
13347  }
13348  }
13349  public function standalone_value()
13350  {
13351  if ($standalone = $this->get_value())
13352  {
13353  switch ($standalone)
13354  {
13355  case 'yes':
13356  $this->standalone = true;
13357  break;
13358  case 'no':
13359  $this->standalone = false;
13360  break;
13361  default:
13362  $this->state = false;
13363  return;
13364  }
13365  $this->skip_whitespace();
13366  if ($this->has_data())
13367  {
13368  $this->state = false;
13369  }
13370  else
13371  {
13372  $this->state = 'emit';
13373  }
13374  }
13375  else
13376  {
13377  $this->state = false;
13378  }
13379  }
13380 }
const SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO
Definition: Simplepie.php:101
set_cache_location($location= './cache')
Definition: Simplepie.php:294
set_copyright_class($class= 'SimplePie_Copyright')
Definition: Simplepie.php:377
get_source_tags($namespace, $tag)
get_image_link()
Definition: Simplepie.php:1615
foreach(array('date1', 'date2', 'type', 'renewals', 'width') as $item) $data
Definition: chart-data.php:29
const SIMPLEPIE_CONSTRUCT_NONE
Definition: Simplepie.php:78
const SIMPLEPIE_FILE_SOURCE_FSOCKOPEN
Definition: Simplepie.php:115
get_base($element=array())
Definition: Simplepie.php:6146
set_caption_class($class= 'SimplePie_Caption')
Definition: Simplepie.php:372
tag_open($parser, $tag, $attributes)
SimplePie.
set_registry(SimplePie_Registry $registry)
cdata($parser, $cdata)
remove_div($enable=true)
set_url_replacements($element_attribute=null)
strip_comments($strip=false)
Definition: Simplepie.php:471
static silence_errors($num, $str)
preprocess($html, $type)
const SIMPLEPIE_NAMESPACE_MEDIARSS
Definition: Simplepie.php:103
strip_htmltags($tags=array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'))
$lang
Definition: spellchecker.php:9
static fix_protocol($url, $http=1)
Definition: Simplepie.php:9027
const SIMPLEPIE_LOCATOR_REMOTE_EXTENSION
Definition: Simplepie.php:58
remove_dot_segments($input)
Definition: Simplepie.php:5416
parse(&$data, $encoding)
const SIMPLEPIE_NAMESPACE_RSS_10
Definition: Simplepie.php:96
get_description()
Definition: Simplepie.php:1411
static get_build()
static sort_items($a, $b)
Definition: Simplepie.php:1831
$result
set_query($iquery)
Definition: Simplepie.php:5982
const SIMPLEPIE_CONSTRUCT_BASE64
Definition: Simplepie.php:82
get_encoding()
Definition: Simplepie.php:819
get_content($content_only=false)
Definition: Simplepie.php:6296
const SIMPLEPIE_TYPE_RSS_092
Definition: Simplepie.php:66
get_item_tags($namespace, $tag)
Definition: Simplepie.php:6134
get_base($element=array())
Definition: Simplepie.php:1041
const SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3
Definition: Simplepie.php:106
static atom_03_construct_type($attribs)
sanitize($data, $type, $base= '')
Definition: Simplepie.php:1057
const SIMPLEPIE_NAMESPACE_DC_11
Definition: Simplepie.php:100
get_link($key=0, $rel= 'alternate')
Definition: Simplepie.php:1318
set_authority($authority)
Definition: Simplepie.php:5825
static get_element($realname, $string)
Definition: Simplepie.php:8937
strip_attributes($attribs= '')
Definition: Simplepie.php:458
& create($type, $parameters=array())
get_item($key=0)
Definition: Simplepie.php:1681
subscribe_url()
Definition: Simplepie.php:916
__construct($location, $name, $type)
Definition: Simplepie.php:2113
get_links($rel= 'alternate')
Definition: Simplepie.php:6741
__construct($name=null, $link=null, $email=null)
Definition: Simplepie.php:1891
const SIMPLEPIE_LOCATOR_ALL
Definition: Simplepie.php:60
const SIMPLEPIE_LOCATOR_AUTODISCOVERY
Definition: Simplepie.php:55
static absolutize_url($relative, $base)
Definition: Simplepie.php:8927
get_local_date($date_format= '%c')
Definition: Simplepie.php:6674
if($rub=fetch_assoc($rub_query)) if(check_if_module_active('url_rewriting')) $class
Definition: index.php:68
__set($name, $value)
Definition: Simplepie.php:4677
encode_instead_of_strip($enable=true)
Definition: Simplepie.php:454
const SIMPLEPIE_NAMESPACE_RSS_090
Definition: Simplepie.php:95
set_registry(SimplePie_Registry $registry)
Definition: Simplepie.php:8643
__construct($item, $data)
const SIMPLEPIE_NAMESPACE_RSS_20
Definition: Simplepie.php:98
set_item_class($class= 'SimplePie_Item')
Definition: Simplepie.php:352
set_raw_data($data)
Definition: Simplepie.php:264
set_output_encoding($encoding= 'UTF-8')
Definition: Simplepie.php:467
const SIMPLEPIE_TYPE_RSS_10
Definition: Simplepie.php:69
static parse_date($dt)
static change_encoding_mbstring($data, $input, $output)
Definition: Simplepie.php:9139
set_cache_duration($seconds=3600)
Definition: Simplepie.php:284
__construct($iri=null)
Definition: Simplepie.php:5290
set_url_replacements($element_attribute=null)
Definition: Simplepie.php:476
$autodiscovery_cache_duration
Definition: Simplepie.php:145
static entities_decode($data)
get_contributor($key=0)
Definition: Simplepie.php:6401
if(!select_db($_SESSION['session_install_choixbase'], $GLOBALS['database_object'], true)) $error
Definition: verifdroits.php:33
$extension
__construct($type=null, $lang=null, $startTime=null, $endTime=null, $text=null)
Definition: Simplepie.php:2544
get_links($rel= 'alternate')
Definition: Simplepie.php:1336
get_link($key=0, $rel= 'alternate')
const SIMPLEPIE_TYPE_ALL
Definition: Simplepie.php:77
const SIMPLEPIE_TYPE_ATOM_10
Definition: Simplepie.php:75
set_max_checked_feeds($max=10)
Definition: Simplepie.php:434
get_link($key=0, $rel= 'alternate')
Definition: Simplepie.php:6728
get_image_height()
Definition: Simplepie.php:1651
extension(&$array)
Definition: Simplepie.php:8847
pass_cache_data($enable_cache=true, $cache_location= './cache', $cache_name_function= 'md5', $cache_class= 'SimplePie_Cache')
get_contributors()
Definition: Simplepie.php:1261
get_item_quantity($max=0)
Definition: Simplepie.php:1667
get_image_title()
Definition: Simplepie.php:1555
const SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS
Definition: Simplepie.php:117
sanitize($data, $type, $base= '')
set_input_encoding($encoding=false)
Definition: Simplepie.php:304
$mode
const SIMPLEPIE_TYPE_RSS_SYNDICATION
Definition: Simplepie.php:72
set_output_encoding($encoding= 'UTF-8')
set_registry(SimplePie_Registry $registry)
Definition: Simplepie.php:6116
remove_div($enable=true)
Definition: Simplepie.php:438
const SIMPLEPIE_LOCATOR_NONE
Definition: Simplepie.php:54
const SIMPLEPIE_TYPE_RSS_093
Definition: Simplepie.php:67
static percent_encoding_normalization($match)
Definition: Simplepie.php:9082
static compress_parse_url($scheme= '', $authority= '', $path= '', $query= '', $fragment= '')
Definition: Simplepie.php:9067
tag_close($parser, $tag)
search_elements_by_tag($name, &$done, $feeds)
Definition: Simplepie.php:8754
remove_iunreserved_percent_encoded($match)
Definition: Simplepie.php:5586
set_image_handler($page=false, $qs= 'i')
Definition: Simplepie.php:481
set_source_class($class= 'SimplePie_Source')
Definition: Simplepie.php:402
static uncomment_rfc822($string)
static debug(&$sp)
to_uri($string)
Definition: Simplepie.php:6010
set_autodiscovery_cache_duration($seconds=604800)
Definition: Simplepie.php:289
set_item_limit($limit=0)
Definition: Simplepie.php:493
set_registry(SimplePie_Registry $registry)
static space_seperated_tokens($string)
create($location, $filename, $extension)
Definition: Simplepie.php:2509
const SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5
Definition: Simplepie.php:108
set_locator_class($class= 'SimplePie_Locator')
Definition: Simplepie.php:332
const SIMPLEPIE_TYPE_NONE
Definition: Simplepie.php:61
native_embed($options='')
Definition: Simplepie.php:4055
encode_instead_of_strip($encode=false)
const SIMPLEPIE_PCRE_XML_ATTRIBUTE
Definition: Simplepie.php:90
$start
Definition: attributs.php:22
const SIMPLEPIE_FILE_SOURCE_NONE
Definition: Simplepie.php:112
get_date($date_format= 'j F Y, g:i a')
Definition: Simplepie.php:6572
set_restriction_class($class= 'SimplePie_Restriction')
Definition: Simplepie.php:392
const SIMPLEPIE_TYPE_RSS_090
Definition: Simplepie.php:62
const SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG
Definition: Simplepie.php:104
const SIMPLEPIE_FILE_SOURCE_REMOTE
Definition: Simplepie.php:113
static time_hms($seconds)
Definition: Simplepie.php:8904
__construct($url, $timeout=10, $redirects=5, $headers=null, $useragent=null, $force_fsockopen=false)
Definition: Simplepie.php:4427
get_image_width()
Definition: Simplepie.php:1635
set_cache_class($class= 'SimplePie_Cache')
Definition: Simplepie.php:327
get_category($key=0)
Definition: Simplepie.php:6320
static error($message, $level, $file, $line)
Definition: Simplepie.php:8991
static absolutize($base, $relative)
Definition: Simplepie.php:5295
const SIMPLEPIE_CONSTRUCT_TEXT
Definition: Simplepie.php:79
find($type=SIMPLEPIE_LOCATOR_ALL, &$working)
Definition: Simplepie.php:8647
static parse_URL($url)
Definition: Simplepie.php:2520
get_contributor($key=0)
Definition: Simplepie.php:1248
const SIMPLEPIE_TYPE_ATOM_ALL
Definition: Simplepie.php:76
const SIMPLEPIE_LOCATOR_LOCAL_EXTENSION
Definition: Simplepie.php:56
static normalize_url($url)
Definition: Simplepie.php:9077
get_links($rel= 'alternate')
set_autodiscovery_level($level=SIMPLEPIE_LOCATOR_ALL)
Definition: Simplepie.php:316
static compress($ip)
force_fsockopen($enable=false)
Definition: Simplepie.php:274
__construct($location, $name, $type)
Definition: Simplepie.php:2186
const SIMPLEPIE_CONSTRUCT_MAYBE_HTML
Definition: Simplepie.php:84
strip_tag($tag, $document, $type)
enable_order_by_date($enable=true)
Definition: Simplepie.php:299
replace_invalid_with_pct_encoding($string, $extra_chars, $iprivate=false)
Definition: Simplepie.php:5470
__construct($location, $name, $type)
get_real_type($find_handler=false)
Definition: Simplepie.php:4263
get_category($key=0)
Definition: Simplepie.php:1098
static atom_10_construct_type($attribs)
get_description($description_only=false)
Definition: Simplepie.php:6248
const SIMPLEPIE_TYPE_RSS_20
Definition: Simplepie.php:70
const SIMPLEPIE_LOCATOR_REMOTE_BODY
Definition: Simplepie.php:59
const SIMPLEPIE_NAMESPACE_RDF
Definition: Simplepie.php:94
const SIMPLEPIE_FILE_SOURCE_CURL
Definition: Simplepie.php:116
set_enclosure_class($class= 'SimplePie_Enclosure')
Definition: Simplepie.php:367
const SIMPLEPIE_NAMESPACE_ATOM_03
Definition: Simplepie.php:93
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
Definition: chart-data.php:160
set_file(&$file)
Definition: Simplepie.php:253
enable_cache($enable=true)
Definition: Simplepie.php:279
get_base($element=array())
handle_content_type($mime= 'text/html')
Definition: Simplepie.php:824
static get_curl_version()
static encoding($charset)
Definition: Simplepie.php:9178
static parse_mime($mime)
static parse_str($str)
set_favicon_handler($page=false, $qs= 'i')
Definition: Simplepie.php:1792
const SIMPLEPIE_FILE_SOURCE_LOCAL
Definition: Simplepie.php:114
static merge_items($urls, $start=0, $end=0, $limit=0)
Definition: Simplepie.php:1836
static get_handler($location, $filename, $extension)
Definition: Simplepie.php:2497
get_category($key=0)
__call($method, $args)
Definition: Simplepie.php:1810
add_callback($callback)
get_items($start=0, $end=0)
Definition: Simplepie.php:1694
get_image_tags($namespace, $tag)
Definition: Simplepie.php:1005
__construct(SimplePie_File $file, $timeout=10, $useragent=null, $max_checked_feeds=10)
Definition: Simplepie.php:8625
const SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
Definition: Simplepie.php:111
__construct($role=null, $scheme=null, $name=null)
Definition: Simplepie.php:2963
do_strip_htmltags($match)
set_parser_class($class= 'SimplePie_Parser')
Definition: Simplepie.php:337
strip_attr($attrib, $document)
set_fragment($ifragment)
Definition: Simplepie.php:5996
static xml_encoding($data, $registry)
const SIMPLEPIE_CONSTRUCT_IRI
Definition: Simplepie.php:83
const SIMPLEPIE_TYPE_RSS_091
Definition: Simplepie.php:65
set_credit_class($class= 'SimplePie_Credit')
Definition: Simplepie.php:382
const SIMPLEPIE_NAME
Definition: Simplepie.php:48
& get_registry()
Definition: Simplepie.php:321
strip_htmltags($tags= '', $encode=null)
Definition: Simplepie.php:442
set_timeout($timeout=10)
Definition: Simplepie.php:269
pass_file_data($file_class= 'SimplePie_File', $timeout=10, $useragent= '', $force_fsockopen=false)
__construct($relationship=null, $type=null, $value=null)
set_host($ihost)
Definition: Simplepie.php:5894
__construct($scheme=null, $value=null)
set_image_handler($page=false)
__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)
Definition: Simplepie.php:3570
replace_urls($document, $tag, $attributes)
__construct($term=null, $scheme=null, $label=null)
Definition: Simplepie.php:2628
const SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2
Definition: Simplepie.php:105
const SIMPLEPIE_LOCATOR_LOCAL_BODY
Definition: Simplepie.php:57
const SIMPLEPIE_TYPE_ATOM_03
Definition: Simplepie.php:74
const SIMPLEPIE_PCRE_HTML_ATTRIBUTE
Definition: Simplepie.php:89
const SIMPLEPIE_TYPE_RSS_091_NETSCAPE
Definition: Simplepie.php:63
const SIMPLEPIE_NAMESPACE_XHTML
Definition: Simplepie.php:110
set_port($port)
Definition: Simplepie.php:5939
__construct($feed, $data)
Definition: Simplepie.php:6110
$max_checked_feeds
Definition: Simplepie.php:159
get_categories()
Definition: Simplepie.php:1111
const SIMPLEPIE_NAMESPACE_ATOM_10
Definition: Simplepie.php:92
& call($type, $method, $parameters=array())
const SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4
Definition: Simplepie.php:107
get_raw_data()
Definition: Simplepie.php:814
get_contributor($key=0)
set_file_class($class= 'SimplePie_File')
Definition: Simplepie.php:342
get_author($key=0)
Definition: Simplepie.php:1166
static change_encoding_iconv($data, $input, $output)
Definition: Simplepie.php:9173
const SIMPLEPIE_USERAGENT
Definition: Simplepie.php:52
const SIMPLEPIE_CONSTRUCT_HTML
Definition: Simplepie.php:80
get_channel_tags($namespace, $tag)
Definition: Simplepie.php:962
set_path($ipath)
Definition: Simplepie.php:5959
const SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT
Definition: Simplepie.php:97
static atom_10_content_construct_type($attribs)
get_feed_tags($namespace, $tag)
Definition: Simplepie.php:928
__unset($name)
Definition: Simplepie.php:5282
static change_encoding($data, $input, $output)
Definition: Simplepie.php:9101
set_useragent($ua=SIMPLEPIE_USERAGENT)
Definition: Simplepie.php:408
get_author($key=0)
Definition: Simplepie.php:6388
$all_discovered_feeds
Definition: Simplepie.php:161
strip_attributes($attribs=array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'))
get_gmdate($date_format= 'j F Y, g:i a')
Definition: Simplepie.php:6690
static prepare_simplepie_object_for_cache($data)
Definition: Simplepie.php:1962
set_registry(SimplePie_Registry $registry)
get_updated_gmdate($date_format= 'j F Y, g:i a')
Definition: Simplepie.php:6700
get_id($hash=false)
Definition: Simplepie.php:6161
const SIMPLEPIE_URL
Definition: Simplepie.php:51
set_sanitize_class($class= 'SimplePie_Sanitize')
Definition: Simplepie.php:347
const SIMPLEPIE_TYPE_RSS_RDF
Definition: Simplepie.php:71
sanitize($data, $type, $base= '')
Definition: Simplepie.php:6151
$filename
$match
Definition: search.php:86
static check_ipv6($ip)
get_duration($convert=false)
Definition: Simplepie.php:3735
const SIMPLEPIE_CONSTRUCT_XHTML
Definition: Simplepie.php:81
set_category_class($class= 'SimplePie_Category')
Definition: Simplepie.php:362
set_userinfo($iuserinfo)
Definition: Simplepie.php:5880
embed($options= '', $native=false)
Definition: Simplepie.php:4060
remove_rfc2822_comments($string)
set_stupidly_fast($set=false)
Definition: Simplepie.php:421
get_updated_date($date_format= 'j F Y, g:i a')
Definition: Simplepie.php:6637
$multifeed_objects
Definition: Simplepie.php:167
static strip_comments($data)
get_all_discovered_feeds()
Definition: Simplepie.php:1406
force_feed($enable=false)
Definition: Simplepie.php:232
static element_implode($element)
Definition: Simplepie.php:8973
static uncompress($ip)
const SIMPLEPIE_TYPE_RSS_091_USERLAND
Definition: Simplepie.php:64
fetch_data(&$cache)
Definition: Simplepie.php:661
set_author_class($class= 'SimplePie_Author')
Definition: Simplepie.php:357
set_rating_class($class= 'SimplePie_Rating')
Definition: Simplepie.php:387
set_content_type_sniffer_class($class= 'SimplePie_Content_Type_Sniffer')
Definition: Simplepie.php:397
strip_comments($strip=false)
sanitize($data, $type, $base= '')
static windows_1252_to_utf8($string)
Definition: Simplepie.php:9095
set_scheme($scheme)
Definition: Simplepie.php:5807
get_enclosure($key=0, $prefer=null)
Definition: Simplepie.php:6813
set_cache_name_function($function= 'md5')
Definition: Simplepie.php:413
const SIMPLEPIE_NAMESPACE_XML
Definition: Simplepie.php:91
const SIMPLEPIE_BUILD
Definition: Simplepie.php:50
const SIMPLEPIE_TYPE_RSS_ALL
Definition: Simplepie.php:73
static parse_url($url)
Definition: Simplepie.php:9056
const SIMPLEPIE_TYPE_RSS_094
Definition: Simplepie.php:68
__set($name, $value)
Definition: Simplepie.php:5206
__construct($location, $name, $type)
Definition: Simplepie.php:2046
__isset($name)
Definition: Simplepie.php:5270
static output_javascript()
static codepoint_to_utf8($codepoint)
const SIMPLEPIE_VERSION
Definition: Simplepie.php:49
$cache_name_function
Definition: Simplepie.php:149
const SIMPLEPIE_NAMESPACE_DC_10
Definition: Simplepie.php:99
static is_isegment_nz_nc($string)
set_feed_url($url)
Definition: Simplepie.php:237
const SIMPLEPIE_NAMESPACE_ITUNES
Definition: Simplepie.php:109
const SIMPLEPIE_NAMESPACE_GEORSS
Definition: Simplepie.php:102
static checkIPv6($ip)

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:30:07 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.