00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 class SimplePie
00025 {
00026
00027 var $name = 'SimplePie';
00028 var $version = '1.0 b3.2';
00029 var $build = '20061124';
00030 var $url = 'http://simplepie.org/';
00031 var $useragent;
00032 var $linkback;
00033
00034
00035 var $sanitize;
00036
00037
00038 var $rss_url;
00039 var $file;
00040 var $timeout = 10;
00041 var $xml_dump = false;
00042 var $enable_cache = true;
00043 var $max_minutes = 60;
00044 var $cache_location = './cache';
00045 var $order_by_date = true;
00046 var $input_encoding = false;
00047 var $cache_class = 'SimplePie_Cache';
00048 var $locator_class = 'SimplePie_Locator';
00049 var $parser_class = 'SimplePie_Parser';
00050 var $file_class = 'SimplePie_File';
00051 var $force_fsockopen = false;
00052 var $cache_name_type = 'sha1';
00053
00054
00055 var $data;
00056 var $error;
00057
00058 function SimplePie($feed_url = null, $cache_location = null, $cache_max_minutes = null)
00059 {
00060
00061 $this->useragent = $this->name . '/' . $this->version . ' (Feed Parser; ' . $this->url . '; Allow like Gecko) Build/' . $this->build;
00062 $this->linkback = '<a href="' . $this->url . '" title="' . $this->name . ' ' . $this->version . '">' . $this->name . '</a>';
00063
00064
00065 $this->sanitize = new SimplePie_Sanitize;
00066
00067
00068 if (!is_null($feed_url))
00069 {
00070 $this->feed_url($feed_url);
00071 }
00072
00073 if (!is_null($cache_location))
00074 {
00075 $this->cache_location($cache_location);
00076 }
00077
00078 if (!is_null($cache_max_minutes))
00079 {
00080 $this->cache_max_minutes($cache_max_minutes);
00081 }
00082
00083
00084 if (isset($_GET['xmldump']))
00085 {
00086 $this->enable_xmldump(true);
00087 }
00088
00089
00090 if (!is_null($feed_url))
00091 {
00092 return $this->init();
00093 }
00094 }
00095
00096 function feed_url($url)
00097 {
00098 $this->rss_url = SimplePie_Misc::fix_protocol($url, 1);
00099 }
00100
00101 function set_file(&$file)
00102 {
00103 if (is_a($file, 'SimplePie_File'))
00104 {
00105 $this->rss_url = $file->url;
00106 $this->file =& $file;
00107 }
00108 }
00109
00110 function set_timeout($timeout = 10)
00111 {
00112 $this->timeout = (int) $timeout;
00113 }
00114
00115 function set_raw_data($data)
00116 {
00117 $this->raw_data = trim((string) $data);
00118 }
00119
00120 function enable_xmldump($enable = false)
00121 {
00122 $this->xml_dump = (bool) $enable;
00123 }
00124
00125 function enable_caching($enable = true)
00126 {
00127 $this->enable_cache = (bool) $enable;
00128 }
00129
00130 function cache_max_minutes($minutes = 60)
00131 {
00132 $this->max_minutes = (float) $minutes;
00133 }
00134
00135 function cache_location($location = './cache')
00136 {
00137 $this->cache_location = (string) $location;
00138 }
00139
00140 function order_by_date($enable = true)
00141 {
00142 $this->order_by_date = (bool) $enable;
00143 }
00144
00145 function input_encoding($encoding = false)
00146 {
00147 if ($encoding)
00148 {
00149 $this->input_encoding = (string) $encoding;
00150 }
00151 else
00152 {
00153 $this->input_encoding = false;
00154 }
00155 }
00156
00157 function set_cache_class($class = 'SimplePie_Cache')
00158 {
00159 if (SimplePie_Misc::is_a_class($class, 'SimplePie_Cache'))
00160 {
00161 $this->cache_class = $class;
00162 return true;
00163 }
00164 return false;
00165 }
00166
00167 function set_locator_class($class = 'SimplePie_Locator')
00168 {
00169 if (SimplePie_Misc::is_a_class($class, 'SimplePie_Locator'))
00170 {
00171 $this->locator_class = $class;
00172 return true;
00173 }
00174 return false;
00175 }
00176
00177 function set_parser_class($class = 'SimplePie_Parser')
00178 {
00179 if (SimplePie_Misc::is_a_class($class, 'SimplePie_Parser'))
00180 {
00181 $this->parser_class = $class;
00182 return true;
00183 }
00184 return false;
00185 }
00186
00187 function set_file_class($class = 'SimplePie_File')
00188 {
00189 if (SimplePie_Misc::is_a_class($class, 'SimplePie_File'))
00190 {
00191 $this->file_class = $class;
00192 return true;
00193 }
00194 return false;
00195 }
00196
00197 function set_sanitize_class($object = 'SimplePie_Sanitize')
00198 {
00199 if (class_exists($object))
00200 {
00201 $this->sanitize = new $object;
00202 return true;
00203 }
00204 return false;
00205 }
00206
00207 function set_useragent($ua)
00208 {
00209 $this->useragent = (string) $ua;
00210 }
00211
00212 function force_fsockopen($enable = false)
00213 {
00214 $this->force_fsockopen = (bool) $enable;
00215 }
00216
00217 function set_cache_name_type($type = 'sha1')
00218 {
00219 $type = strtolower(trim($type));
00220 switch ($type)
00221 {
00222 case 'crc32':
00223 $this->cache_name_type = 'crc32';
00224 break;
00225
00226 case 'md5':
00227 $this->cache_name_type = 'md5';
00228 break;
00229
00230 case 'rawurlencode':
00231 $this->cache_name_type = 'rawurlencode';
00232 break;
00233
00234 case 'urlencode':
00235 $this->cache_name_type = 'urlencode';
00236 break;
00237
00238 default:
00239 $this->cache_name_type = 'sha1';
00240 break;
00241 }
00242 }
00243
00244 function bypass_image_hotlink($get = false)
00245 {
00246 $this->sanitize->bypass_image_hotlink($get);
00247 }
00248
00249 function bypass_image_hotlink_page($page = false)
00250 {
00251 $this->sanitize->bypass_image_hotlink_page($page);
00252 }
00253
00254 function replace_headers($enable = false)
00255 {
00256 $this->sanitize->replace_headers($enable);
00257 }
00258
00259 function remove_div($enable = true)
00260 {
00261 $this->sanitize->remove_div($enable);
00262 }
00263
00264 function strip_ads($enable = false)
00265 {
00266 $this->sanitize->strip_ads($enable);
00267 }
00268
00269 function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'), $encode = null)
00270 {
00271 $this->sanitize->strip_htmltags($tags);
00272 if (!is_null($encode))
00273 {
00274 $this->sanitize->encode_instead_of_strip($tags);
00275 }
00276 }
00277
00278 function encode_instead_of_strip($enable = true)
00279 {
00280 $this->sanitize->encode_instead_of_strip($enable);
00281 }
00282
00283 function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur'))
00284 {
00285 $this->sanitize->strip_attributes($attribs);
00286 }
00287
00288 function output_encoding($encoding = 'UTF-8')
00289 {
00290 $this->sanitize->output_encoding($encoding);
00291 }
00292
00293 function set_item_class($class = 'SimplePie_Item')
00294 {
00295 return $this->sanitize->set_item_class($class);
00296 }
00297
00298 function set_author_class($class = 'SimplePie_Author')
00299 {
00300 return $this->sanitize->set_author_class($class);
00301 }
00302
00303 function set_enclosure_class($class = 'SimplePie_Enclosure')
00304 {
00305 return $this->sanitize->set_enclosure_class($class);
00306 }
00307
00308 function init()
00309 {
00310 if (!(function_exists('version_compare') && ((version_compare(phpversion(), '4.3.2', '>=') && version_compare(phpversion(), '5', '<')) || version_compare(phpversion(), '5.0.3', '>='))) || !extension_loaded('xml') || !extension_loaded('pcre'))
00311 {
00312 return false;
00313 }
00314 if ($this->sanitize->bypass_image_hotlink && !empty($_GET[$this->sanitize->bypass_image_hotlink]))
00315 {
00316 if (get_magic_quotes_gpc())
00317 {
00318 $_GET[$this->sanitize->bypass_image_hotlink] = stripslashes($_GET[$this->sanitize->bypass_image_hotlink]);
00319 }
00320 SimplePie_Misc::display_file($_GET[$this->sanitize->bypass_image_hotlink], 10, $this->useragent);
00321 }
00322
00323 if (isset($_GET['js']))
00324 {
00325 $embed = <<<EOT
00326 function embed_odeo(link) {
00327 document.writeln('<embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="440" height="80" wmode="transparent" allowScriptAccess="any" flashvars="valid_sample_rate=true&external_url='+link+'"></embed>');
00328 }
00329
00330 function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {
00331 if (placeholder != '') {
00332 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>');
00333 }
00334 else {
00335 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>');
00336 }
00337 }
00338
00339 function embed_flash(bgcolor, width, height, link, loop, type) {
00340 document.writeln('<embed src="'+link+'" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="'+type+'" quality="high" width="'+width+'" height="'+height+'" bgcolor="'+bgcolor+'" loop="'+loop+'"></embed>');
00341 }
00342
00343 function embed_wmedia(width, height, link) {
00344 document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>');
00345 }
00346 EOT;
00347
00348 if (function_exists('ob_gzhandler'))
00349 {
00350 ob_start('ob_gzhandler');
00351 }
00352 header('Content-type: text/javascript; charset: UTF-8');
00353 header('Cache-Control: must-revalidate');
00354 header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 86400) . ' GMT');
00355 echo $embed;
00356 exit;
00357 }
00358
00359 if (!empty($this->rss_url) || !empty($this->raw_data))
00360 {
00361 $this->data = array();
00362 $cache = false;
00363
00364 if (!empty($this->rss_url))
00365 {
00366
00367 if ($this->enable_cache && preg_match('/^http(s)?:\/\//i', $this->rss_url))
00368 {
00369 $cache = new $this->cache_class($this->cache_location, call_user_func($this->cache_name_type, $this->rss_url), 'spc');
00370 }
00371
00372 if ($cache && !$this->xml_dump)
00373 {
00374
00375 $this->data = $cache->load();
00376 if (!empty($this->data))
00377 {
00378
00379 if (isset($this->data['url']) && $this->data['url'] != $this->rss_url)
00380 {
00381 $cache = false;
00382 }
00383
00384 else if (!empty($this->data['feed_url']))
00385 {
00386 if ($this->data['feed_url'] == $this->data['url'])
00387 {
00388 $cache->unlink();
00389 }
00390 else
00391 {
00392 $this->feed_url($this->data['feed_url']);
00393 return $this->init();
00394 }
00395 }
00396
00397 else if ($cache->mtime() + $this->max_minutes * 60 < time())
00398 {
00399
00400 if (!empty($this->data['last-modified']) || !empty($this->data['etag']))
00401 {
00402 $headers = array();
00403 if (!empty($this->data['last-modified']))
00404 {
00405 $headers['if-modified-since'] = $this->data['last-modified'];
00406 }
00407 if (!empty($this->data['etag']))
00408 {
00409 $headers['if-none-match'] = $this->data['etag'];
00410 }
00411 $file = new $this->file_class($this->rss_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen);
00412 if ($file->success)
00413 {
00414 $headers = $file->headers();
00415 if ($headers['status']['code'] == 304)
00416 {
00417 $cache->touch();
00418 return true;
00419 }
00420 }
00421 else
00422 {
00423 unset($file);
00424 }
00425 }
00426
00427 else
00428 {
00429 $cache->unlink();
00430 }
00431 }
00432
00433 else
00434 {
00435 return true;
00436 }
00437 }
00438
00439 else
00440 {
00441 $cache->unlink();
00442 }
00443 }
00444 $this->data = array();
00445
00446 if (!isset($file))
00447 {
00448 if (is_a($this->file, 'SimplePie_File') && $this->file->url == $this->rss_url)
00449 {
00450 $file =& $this->file;
00451 }
00452 else
00453 {
00454 $file = new $this->file_class($this->rss_url, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen);
00455 }
00456 }
00457
00458 if (!$file->success)
00459 {
00460 $this->error = $file->error;
00461 return false;
00462 }
00463
00464
00465 $locate = new $this->locator_class($file, $this->timeout, $this->useragent);
00466 if (!$locate->is_feed($file))
00467 {
00468 $feed = $locate->find();
00469 if ($feed)
00470 {
00471 if ($cache && !$cache->save(array('url' => $this->rss_url, 'feed_url' => $feed)))
00472 {
00473 $this->error = "$cache->name is not writeable";
00474 SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
00475 }
00476 $this->rss_url = $feed;
00477 return $this->init();
00478 }
00479 else
00480 {
00481 $this->error = "A feed could not be found at $this->rss_url";
00482 SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
00483 return false;
00484 }
00485 }
00486
00487 $headers = $file->headers();
00488 $data = trim($file->body());
00489 $file->close();
00490 unset($file);
00491 }
00492 else
00493 {
00494 $data = $this->raw_data;
00495 }
00496
00497
00498 if (!empty($this->input_encoding))
00499 {
00500 $encoding = $this->input_encoding;
00501 }
00502
00503 else if (!empty($headers['content-type']) && preg_match('/charset\s*=\s*([^;]*)/i', $headers['content-type'], $charset))
00504 {
00505 $encoding = $charset[1];
00506 }
00507
00508 else if (preg_match('/^<\?xml(.*)?>/msiU', $data, $prolog) && preg_match('/encoding\s*=\s*("([^"]*)"|\'([^\']*)\')/Ui', $prolog[1], $encoding))
00509 {
00510 $encoding = substr($encoding[1], 1, -1);
00511 }
00512
00513 else if (strpos($data, sprintf('%c%c%c%c', 0x00, 0x00, 0xFE, 0xFF)) === 0)
00514 {
00515 $encoding = 'UTF-32be';
00516 }
00517
00518 else if (strpos($data, sprintf('%c%c%c%c', 0xFF, 0xFE, 0x00, 0x00)) === 0)
00519 {
00520 $encoding = 'UTF-32';
00521 }
00522
00523 else if (strpos($data, sprintf('%c%c', 0xFE, 0xFF)) === 0)
00524 {
00525 $encoding = 'UTF-16be';
00526 }
00527
00528 else if (strpos($data, sprintf('%c%c', 0xFF, 0xFE)) === 0)
00529 {
00530 $encoding = 'UTF-16le';
00531 }
00532
00533 else if (strpos($data, sprintf('%c%c%c', 0xEF, 0xBB, 0xBF)) === 0)
00534 {
00535 $encoding = 'UTF-8';
00536 }
00537
00538 else
00539 {
00540 $encoding = null;
00541 }
00542
00543
00544 $data = SimplePie_Misc::change_encoding($data, $encoding, 'UTF-8');
00545
00546
00547 if (version_compare(phpversion(), '5', '<'))
00548 {
00549 if (function_exists('iconv'))
00550 {
00551 $data = iconv('UTF-8', 'UTF-8//IGNORE', $data);
00552 }
00553 else if (function_exists('mb_convert_encoding'))
00554 {
00555 $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8');
00556 }
00557 else
00558 {
00559 $data = SimplePie_Misc::utf8_bad_replace($data);
00560 }
00561 }
00562
00563
00564 $data = new $this->parser_class($data, 'UTF-8', $this->xml_dump);
00565
00566 if ($this->xml_dump)
00567 {
00568 header('Content-type: text/xml; charset=UTF-8');
00569 echo $data->data;
00570 exit;
00571 }
00572
00573 else if (!$data->error_code)
00574 {
00575
00576 $this->sanitize->parse_data_array($data->data, $this->rss_url);
00577 unset($data);
00578
00579 $this->data['feedinfo'] = $this->sanitize->feedinfo;
00580 unset($this->sanitize->feedinfo);
00581 $this->data['info'] = $this->sanitize->info;
00582 unset($this->sanitize->info);
00583 $this->data['items'] = $this->sanitize->items;
00584 unset($this->sanitize->items);
00585 $this->data['feedinfo']['encoding'] = $this->sanitize->output_encoding;
00586 $this->data['url'] = $this->rss_url;
00587
00588
00589 if (!empty($headers['last-modified']))
00590 {
00591 $this->data['last-modified'] = $headers['last-modified'];
00592 }
00593 if (!empty($headers['etag']))
00594 {
00595 $this->data['etag'] = $headers['etag'];
00596 }
00597
00598
00599 if ($this->order_by_date && !empty($this->data['items']))
00600 {
00601 $do_sort = true;
00602 foreach ($this->data['items'] as $item)
00603 {
00604 if (!$item->get_date('U'))
00605 {
00606 $do_sort = false;
00607 break;
00608 }
00609 }
00610 if ($do_sort)
00611 {
00612 usort($this->data['items'], create_function('$a, $b', 'if ($a->get_date(\'U\') == $b->get_date(\'U\')) return 1; return ($a->get_date(\'U\') < $b->get_date(\'U\')) ? 1 : -1;'));
00613 }
00614 }
00615
00616
00617 if ($cache && !$cache->save($this->data))
00618 {
00619 $this->error = "$cache->name is not writeable";
00620 SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
00621 }
00622 return true;
00623 }
00624
00625 else
00626 {
00627 $this->error = "XML error: $data->error_string at line $data->current_line, column $data->current_column";
00628 SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
00629 return false;
00630 }
00631 }
00632 }
00633
00634 function get_encoding()
00635 {
00636 if (!empty($this->data['feedinfo']['encoding']))
00637 {
00638 return $this->data['feedinfo']['encoding'];
00639 }
00640 else
00641 {
00642 return false;
00643 }
00644 }
00645
00646 function handle_content_type($mime = 'text/html')
00647 {
00648 if (!headers_sent())
00649 {
00650 $header = "Content-type: $mime;";
00651 if ($this->get_encoding())
00652 {
00653 $header .= ' charset=' . $this->get_encoding();
00654 }
00655 else
00656 {
00657 $header .= ' charset=UTF-8';
00658 }
00659 header($header);
00660 }
00661 }
00662
00663 function get_type()
00664 {
00665 if (!empty($this->data['feedinfo']['type']))
00666 {
00667 return $this->data['feedinfo']['type'];
00668 }
00669 else
00670 {
00671 return false;
00672 }
00673 }
00674
00675 function get_version()
00676 {
00677 if (!empty($this->data['feedinfo']['version']))
00678 {
00679 return $this->data['feedinfo']['version'];
00680 }
00681 else
00682 {
00683 return false;
00684 }
00685 }
00686
00687 function get_favicon($check = false, $alternate = null)
00688 {
00689 if (!empty($this->data['info']['link']['alternate'][0]))
00690 {
00691 $favicon = SimplePie_Misc::absolutize_url('/favicon.ico', $this->get_feed_link());
00692
00693 if ($check)
00694 {
00695 $file = new $this->file_class($favicon, $this->timeout/10, 5, null, $this->useragent, $this->force_fsockopen);
00696 $headers = $file->headers();
00697 $file->close();
00698
00699 if ($headers['status']['code'] == 200)
00700 {
00701 return $favicon;
00702 }
00703 }
00704 else
00705 {
00706 return $favicon;
00707 }
00708 }
00709 if (!is_null($alternate))
00710 {
00711 return $alternate;
00712 }
00713 else
00714 {
00715 return false;
00716 }
00717 }
00718
00719 function subscribe_url()
00720 {
00721 if (!empty($this->rss_url))
00722 {
00723 return $this->rss_url;
00724 }
00725 else
00726 {
00727 return false;
00728 }
00729 }
00730
00731 function subscribe_feed()
00732 {
00733 if (!empty($this->rss_url))
00734 {
00735 return SimplePie_Misc::fix_protocol($this->rss_url, 2);
00736 }
00737 else
00738 {
00739 return false;
00740 }
00741 }
00742
00743 function subscribe_outlook()
00744 {
00745 if (!empty($this->rss_url))
00746 {
00747 return 'outlook' . SimplePie_Misc::fix_protocol($this->rss_url, 2);
00748 }
00749 else
00750 {
00751 return false;
00752 }
00753 }
00754
00755 function subscribe_podcast()
00756 {
00757 if (!empty($this->rss_url))
00758 {
00759 return SimplePie_Misc::fix_protocol($this->rss_url, 3);
00760 }
00761 else
00762 {
00763 return false;
00764 }
00765 }
00766
00767 function subscribe_aol()
00768 {
00769 if ($this->subscribe_url())
00770 {
00771 return 'http://feeds.my.aol.com/add.jsp?url=' . rawurlencode($this->subscribe_url());
00772 }
00773 else
00774 {
00775 return false;
00776 }
00777 }
00778
00779 function subscribe_bloglines()
00780 {
00781 if ($this->subscribe_url())
00782 {
00783 return 'http://www.bloglines.com/sub/' . rawurlencode($this->subscribe_url());
00784 }
00785 else
00786 {
00787 return false;
00788 }
00789 }
00790
00791 function subscribe_eskobo()
00792 {
00793 if ($this->subscribe_url())
00794 {
00795 return 'http://www.eskobo.com/?AddToMyPage=' . rawurlencode($this->subscribe_url());
00796 }
00797 else
00798 {
00799 return false;
00800 }
00801 }
00802
00803 function subscribe_feedfeeds()
00804 {
00805 if ($this->subscribe_url())
00806 {
00807 return 'http://www.feedfeeds.com/add?feed=' . rawurlencode($this->subscribe_url());
00808 }
00809 else
00810 {
00811 return false;
00812 }
00813 }
00814
00815 function subscribe_feedlounge()
00816 {
00817 if ($this->subscribe_url())
00818 {
00819 return 'http://my.feedlounge.com/external/subscribe?url=' . rawurlencode($this->subscribe_url());
00820 }
00821 else
00822 {
00823 return false;
00824 }
00825 }
00826
00827 function subscribe_feedster()
00828 {
00829 if ($this->subscribe_url())
00830 {
00831 return 'http://www.feedster.com/myfeedster.php?action=addrss&confirm=no&rssurl=' . rawurlencode($this->subscribe_url());
00832 }
00833 else
00834 {
00835 return false;
00836 }
00837 }
00838
00839 function subscribe_google()
00840 {
00841 if ($this->subscribe_url())
00842 {
00843 return 'http://fusion.google.com/add?feedurl=' . rawurlencode($this->subscribe_url());
00844 }
00845 else
00846 {
00847 return false;
00848 }
00849 }
00850
00851 function subscribe_gritwire()
00852 {
00853 if ($this->subscribe_url())
00854 {
00855 return 'http://my.gritwire.com/feeds/addExternalFeed.aspx?FeedUrl=' . rawurlencode($this->subscribe_url());
00856 }
00857 else
00858 {
00859 return false;
00860 }
00861 }
00862
00863 function subscribe_msn()
00864 {
00865 if ($this->subscribe_url())
00866 {
00867 $url = 'http://my.msn.com/addtomymsn.armx?id=rss&ut=' . rawurlencode($this->subscribe_url());
00868 if ($this->get_feed_link())
00869 {
00870 $url .= '&ru=' . rawurlencode($this->get_feed_link());
00871 }
00872 return $url;
00873 }
00874 else
00875 {
00876 return false;
00877 }
00878 }
00879
00880 function subscribe_netvibes()
00881 {
00882 if ($this->subscribe_url())
00883 {
00884 return 'http://www.netvibes.com/subscribe.php?url=' . rawurlencode($this->subscribe_url());
00885 }
00886 else
00887 {
00888 return false;
00889 }
00890 }
00891
00892 function subscribe_newsburst()
00893 {
00894 if ($this->subscribe_url())
00895 {
00896 return 'http://www.newsburst.com/Source/?add=' . rawurlencode($this->subscribe_url());
00897 }
00898 else
00899 {
00900 return false;
00901 }
00902 }
00903
00904 function subscribe_newsgator()
00905 {
00906 if ($this->subscribe_url())
00907 {
00908 return 'http://www.newsgator.com/ngs/subscriber/subext.aspx?url=' . rawurlencode($this->subscribe_url());
00909 }
00910 else
00911 {
00912 return false;
00913 }
00914 }
00915
00916 function subscribe_odeo()
00917 {
00918 if ($this->subscribe_url())
00919 {
00920 return 'http://www.odeo.com/listen/subscribe?feed=' . rawurlencode($this->subscribe_url());
00921 }
00922 else
00923 {
00924 return false;
00925 }
00926 }
00927
00928 function subscribe_pluck()
00929 {
00930 if ($this->subscribe_url())
00931 {
00932 return 'http://client.pluck.com/pluckit/prompt.aspx?GCID=C12286x053&a=' . rawurlencode($this->subscribe_url());
00933 }
00934 else
00935 {
00936 return false;
00937 }
00938 }
00939
00940 function subscribe_podnova()
00941 {
00942 if ($this->subscribe_url())
00943 {
00944 return 'http://www.podnova.com/index_your_podcasts.srf?action=add&url=' . rawurlencode($this->subscribe_url());
00945 }
00946 else
00947 {
00948 return false;
00949 }
00950 }
00951
00952 function subscribe_rojo()
00953 {
00954 if ($this->subscribe_url())
00955 {
00956 return 'http://www.rojo.com/add-subscription?resource=' . rawurlencode($this->subscribe_url());
00957 }
00958 else
00959 {
00960 return false;
00961 }
00962 }
00963
00964 function subscribe_yahoo()
00965 {
00966 if ($this->subscribe_url())
00967 {
00968 return 'http://add.my.yahoo.com/rss?url=' . rawurlencode($this->subscribe_url());
00969 }
00970 else
00971 {
00972 return false;
00973 }
00974 }
00975
00976 function get_feed_title()
00977 {
00978 if (!empty($this->data['info']['title']))
00979 {
00980 return $this->data['info']['title'];
00981 }
00982 else
00983 {
00984 return false;
00985 }
00986 }
00987
00988 function get_feed_link()
00989 {
00990 if (!empty($this->data['info']['link']['alternate'][0]))
00991 {
00992 return $this->data['info']['link']['alternate'][0];
00993 }
00994 else
00995 {
00996 return false;
00997 }
00998 }
00999
01000 function get_feed_links()
01001 {
01002 if (!empty($this->data['info']['link']))
01003 {
01004 return $this->data['info']['link'];
01005 }
01006 else
01007 {
01008 return false;
01009 }
01010 }
01011
01012 function get_feed_description()
01013 {
01014 if (!empty($this->data['info']['description']))
01015 {
01016 return $this->data['info']['description'];
01017 }
01018 else if (!empty($this->data['info']['dc:description']))
01019 {
01020 return $this->data['info']['dc:description'];
01021 }
01022 else if (!empty($this->data['info']['tagline']))
01023 {
01024 return $this->data['info']['tagline'];
01025 }
01026 else if (!empty($this->data['info']['subtitle']))
01027 {
01028 return $this->data['info']['subtitle'];
01029 }
01030 else
01031 {
01032 return false;
01033 }
01034 }
01035
01036 function get_feed_copyright()
01037 {
01038 if (!empty($this->data['info']['copyright']))
01039 {
01040 return $this->data['info']['copyright'];
01041 }
01042 else
01043 {
01044 return false;
01045 }
01046 }
01047
01048 function get_feed_language()
01049 {
01050 if (!empty($this->data['info']['language']))
01051 {
01052 return $this->data['info']['language'];
01053 }
01054 else if (!empty($this->data['info']['xml:lang']))
01055 {
01056 return $this->data['info']['xml:lang'];
01057 }
01058 else
01059 {
01060 return false;
01061 }
01062 }
01063
01064 function get_image_exist()
01065 {
01066 if (!empty($this->data['info']['image']['url']) || !empty($this->data['info']['image']['logo']))
01067 {
01068 return true;
01069 }
01070 else
01071 {
01072 return false;
01073 }
01074 }
01075
01076 function get_image_title()
01077 {
01078 if (!empty($this->data['info']['image']['title']))
01079 {
01080 return $this->data['info']['image']['title'];
01081 }
01082 else
01083 {
01084 return false;
01085 }
01086 }
01087
01088 function get_image_url()
01089 {
01090 if (!empty($this->data['info']['image']['url']))
01091 {
01092 return $this->data['info']['image']['url'];
01093 }
01094 else if (!empty($this->data['info']['image']['logo']))
01095 {
01096 return $this->data['info']['image']['logo'];
01097 }
01098 else
01099 {
01100 return false;
01101 }
01102 }
01103
01104 function get_image_link()
01105 {
01106 if (!empty($this->data['info']['image']['link']))
01107 {
01108 return $this->data['info']['image']['link'];
01109 }
01110 else
01111 {
01112 return false;
01113 }
01114 }
01115
01116 function get_image_width()
01117 {
01118 if (!empty($this->data['info']['image']['width']))
01119 {
01120 return $this->data['info']['image']['width'];
01121 }
01122 else
01123 {
01124 return false;
01125 }
01126 }
01127
01128 function get_image_height()
01129 {
01130 if (!empty($this->data['info']['image']['height']))
01131 {
01132 return $this->data['info']['image']['height'];
01133 }
01134 else
01135 {
01136 return false;
01137 }
01138 }
01139
01140 function get_item_quantity($max = 0)
01141 {
01142 if (!empty($this->data['items']))
01143 {
01144 $qty = sizeof($this->data['items']);
01145 }
01146 else
01147 {
01148 $qty = 0;
01149 }
01150 if ($max == 0)
01151 {
01152 return $qty;
01153 }
01154 else
01155 {
01156 return ($qty > $max) ? $max : $qty;
01157 }
01158 }
01159
01160 function get_item($key = 0)
01161 {
01162 if (!empty($this->data['items'][$key]))
01163 {
01164 return $this->data['items'][$key];
01165 }
01166 else
01167 {
01168 return false;
01169 }
01170 }
01171
01172 function get_items($start = 0, $end = 0)
01173 {
01174 if ($this->get_item_quantity() > 0)
01175 {
01176 if ($end == 0)
01177 {
01178 return array_slice($this->data['items'], $start);
01179 }
01180 else
01181 {
01182 return array_slice($this->data['items'], $start, $end);
01183 }
01184 }
01185 else
01186 {
01187 return false;
01188 }
01189 }
01190 }
01191
01192 class SimplePie_Item
01193 {
01194 var $data;
01195
01196 function SimplePie_Item($data)
01197 {
01198 $this->data =& $data;
01199 }
01200
01201 function get_id()
01202 {
01203 if (!empty($this->data['guid']['data']))
01204 {
01205 return $this->data['guid']['data'];
01206 }
01207 else if (!empty($this->data['id']))
01208 {
01209 return $this->data['id'];
01210 }
01211 else
01212 {
01213 return false;
01214 }
01215 }
01216
01217 function get_title()
01218 {
01219 if (!empty($this->data['title']))
01220 {
01221 return $this->data['title'];
01222 }
01223 else if (!empty($this->data['dc:title']))
01224 {
01225 return $this->data['dc:title'];
01226 }
01227 else
01228 {
01229 return false;
01230 }
01231 }
01232
01233 function get_description()
01234 {
01235 if (!empty($this->data['content']))
01236 {
01237 return $this->data['content'];
01238 }
01239 else if (!empty($this->data['encoded']))
01240 {
01241 return $this->data['encoded'];
01242 }
01243 else if (!empty($this->data['summary']))
01244 {
01245 return $this->data['summary'];
01246 }
01247 else if (!empty($this->data['description']))
01248 {
01249 return $this->data['description'];
01250 }
01251 else if (!empty($this->data['dc:description']))
01252 {
01253 return $this->data['dc:description'];
01254 }
01255 else if (!empty($this->data['longdesc']))
01256 {
01257 return $this->data['longdesc'];
01258 }
01259 else
01260 {
01261 return false;
01262 }
01263 }
01264
01265 function get_category($key = 0)
01266 {
01267 $categories = $this->get_categories();
01268 if (!empty($categories[$key]))
01269 {
01270 return $categories[$key];
01271 }
01272 else
01273 {
01274 return false;
01275 }
01276 }
01277
01278 function get_categories()
01279 {
01280 $categories = array();
01281 if (!empty($this->data['category']))
01282 {
01283 $categories = array_merge($categories, $this->data['category']);
01284 }
01285 if (!empty($this->data['subject']))
01286 {
01287 $categories = array_merge($categories, $this->data['subject']);
01288 }
01289 if (!empty($this->data['term']))
01290 {
01291 $categories = array_merge($categories, $this->data['term']);
01292 }
01293 if (!empty($categories))
01294 {
01295 return array_unique($categories);
01296 }
01297 else
01298 {
01299 return false;
01300 }
01301 }
01302
01303 function get_author($key = 0)
01304 {
01305 $authors = $this->get_authors();
01306 if (!empty($authors[$key]))
01307 {
01308 return $authors[$key];
01309 }
01310 else
01311 {
01312 return false;
01313 }
01314 }
01315
01316 function get_authors()
01317 {
01318 $authors = array();
01319 if (!empty($this->data['author']))
01320 {
01321 $authors = array_merge($authors, $this->data['author']);
01322 }
01323 if (!empty($this->data['creator']))
01324 {
01325 $authors = array_merge($authors, $this->data['creator']);
01326 }
01327 if (!empty($authors))
01328 {
01329 return array_unique($authors);
01330 }
01331 else
01332 {
01333 return false;
01334 }
01335 }
01336
01337 function get_date($date_format = 'j F Y, g:i a')
01338 {
01339 if (!empty($this->data['pubdate']))
01340 {
01341 return date($date_format, $this->data['pubdate']);
01342 }
01343 else if (!empty($this->data['dc:date']))
01344 {
01345 return date($date_format, $this->data['dc:date']);
01346 }
01347 else if (!empty($this->data['issued']))
01348 {
01349 return date($date_format, $this->data['issued']);
01350 }
01351 else if (!empty($this->data['published']))
01352 {
01353 return date($date_format, $this->data['published']);
01354 }
01355 else if (!empty($this->data['modified']))
01356 {
01357 return date($date_format, $this->data['modified']);
01358 }
01359 else if (!empty($this->data['updated']))
01360 {
01361 return date($date_format, $this->data['updated']);
01362 }
01363 else
01364 {
01365 return false;
01366 }
01367 }
01368
01369 function get_permalink()
01370 {
01371 $link = $this->get_link(0);
01372 $enclosure = $this->get_enclosure(0);
01373 if (!empty($link))
01374 {
01375 return $link;
01376 }
01377 else if (!empty($enclosure))
01378 {
01379 return $enclosure->get_link();
01380 }
01381 else
01382 {
01383 return false;
01384 }
01385 }
01386
01387 function get_link($key = 0, $rel = 'alternate')
01388 {
01389 $links = $this->get_links($rel);
01390 if (!empty($links[$key]))
01391 {
01392 return $links[$key];
01393 }
01394 else
01395 {
01396 return false;
01397 }
01398 }
01399
01400 function get_links($rel = 'alternate')
01401 {
01402 if ($rel == 'alternate')
01403 {
01404 $links = array();
01405 if (!empty($this->data['link'][$rel]))
01406 {
01407 $links = $this->data['link'][$rel];
01408 }
01409 if (!empty($this->data['guid']['data']) && $this->data['guid']['permalink'] == true)
01410 {
01411 $links[] = $this->data['guid']['data'];
01412 }
01413 return $links;
01414 }
01415 else if (!empty($this->data['link'][$rel]))
01416 {
01417 return $this->data['link'][$rel];
01418 }
01419 else
01420 {
01421 return false;
01422 }
01423 }
01424
01425 function get_enclosure($key = 0)
01426 {
01427 $enclosures = $this->get_enclosures();
01428 if (!empty($enclosures[$key]))
01429 {
01430 return $enclosures[$key];
01431 }
01432 else
01433 {
01434 return false;
01435 }
01436 }
01437
01438 function get_enclosures()
01439 {
01440 $enclosures = array();
01441 $links = $this->get_links('enclosure');
01442 if (!empty($this->data['enclosures']))
01443 {
01444 $enclosures = array_merge($enclosures, $this->data['enclosures']);
01445 }
01446 if (!empty($links))
01447 {
01448 $enclosures = array_merge($enclosures, $links);
01449 }
01450 if (!empty($enclosures))
01451 {
01452 return array_unique($enclosures);
01453 }
01454 else
01455 {
01456 return false;
01457 }
01458 }
01459
01460 function add_to_blinklist()
01461 {
01462 if ($this->get_permalink())
01463 {
01464 $url = 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&Url=' . rawurlencode($this->get_permalink());
01465 if ($this->get_title())
01466 {
01467 $url .= '&Title=' . rawurlencode($this->get_title());
01468 }
01469 return $url;
01470 }
01471 else
01472 {
01473 return false;
01474 }
01475 }
01476
01477 function add_to_blogmarks()
01478 {
01479 if ($this->get_permalink())
01480 {
01481 $url = 'http://blogmarks.net/my/new.php?mini=1&simple=1&url=' . rawurlencode($this->get_permalink());
01482 if ($this->get_title())
01483 {
01484 $url .= '&title=' . rawurlencode($this->get_title());
01485 }
01486 return $url;
01487 }
01488 else
01489 {
01490 return false;
01491 }
01492 }
01493
01494 function add_to_delicious()
01495 {
01496 if ($this->get_permalink())
01497 {
01498 $url = 'http://del.icio.us/post/?v=3&url=' . rawurlencode($this->get_permalink());
01499 if ($this->get_title())
01500 {
01501 $url .= '&title=' . rawurlencode($this->get_title());
01502 }
01503 return $url;
01504 }
01505 else
01506 {
01507 return false;
01508 }
01509 }
01510
01511 function add_to_digg()
01512 {
01513 if ($this->get_permalink())
01514 {
01515 return 'http://digg.com/submit?phase=2&URL=' . rawurlencode($this->get_permalink());
01516 }
01517 else
01518 {
01519 return false;
01520 }
01521 }
01522
01523 function add_to_furl()
01524 {
01525 if ($this->get_permalink())
01526 {
01527 $url = 'http://www.furl.net/storeIt.jsp?u=' . rawurlencode($this->get_permalink());
01528 if ($this->get_title())
01529 {
01530 $url .= '&t=' . rawurlencode($this->get_title());
01531 }
01532 return $url;
01533 }
01534 else
01535 {
01536 return false;
01537 }
01538 }
01539
01540 function add_to_magnolia()
01541 {
01542 if ($this->get_permalink())
01543 {
01544 $url = 'http://ma.gnolia.com/bookmarklet/add?url=' . rawurlencode($this->get_permalink());
01545 if ($this->get_title())
01546 {
01547 $url .= '&title=' . rawurlencode($this->get_title());
01548 }
01549 return $url;
01550 }
01551 else
01552 {
01553 return false;
01554 }
01555 }
01556
01557 function add_to_myweb20()
01558 {
01559 if ($this->get_permalink())
01560 {
01561 $url = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=' . rawurlencode($this->get_permalink());
01562 if ($this->get_title())
01563 {
01564 $url .= '&t=' . rawurlencode($this->get_title());
01565 }
01566 return $url;
01567 }
01568 else
01569 {
01570 return false;
01571 }
01572 }
01573
01574 function add_to_newsvine()
01575 {
01576 if ($this->get_permalink())
01577 {
01578 $url = 'http://www.newsvine.com/_wine/save?u=' . rawurlencode($this->get_permalink());
01579 if ($this->get_title())
01580 {
01581 $url .= '&h=' . rawurlencode($this->get_title());
01582 }
01583 return $url;
01584 }
01585 else
01586 {
01587 return false;
01588 }
01589 }
01590
01591 function add_to_reddit()
01592 {
01593 if ($this->get_permalink())
01594 {
01595 $url = 'http://reddit.com/submit?url=' . rawurlencode($this->get_permalink());
01596 if ($this->get_title())
01597 {
01598 $url .= '&title=' . rawurlencode($this->get_title());
01599 }
01600 return $url;
01601 }
01602 else
01603 {
01604 return false;
01605 }
01606 }
01607
01608 function add_to_segnalo()
01609 {
01610 if ($this->get_permalink())
01611 {
01612 $url = 'http://segnalo.com/post.html.php?url=' . rawurlencode($this->get_permalink());
01613 if ($this->get_title())
01614 {
01615 $url .= '&title=' . rawurlencode($this->get_title());
01616 }
01617 return $url;
01618 }
01619 else
01620 {
01621 return false;
01622 }
01623 }
01624
01625 function add_to_simpy()
01626 {
01627 if ($this->get_permalink())
01628 {
01629 $url = 'http://www.simpy.com/simpy/LinkAdd.do?href=' . rawurlencode($this->get_permalink());
01630 if ($this->get_title())
01631 {
01632 $url .= '&title=' . rawurlencode($this->get_title());
01633 }
01634 return $url;
01635 }
01636 else
01637 {
01638 return false;
01639 }
01640 }
01641
01642 function add_to_smarking()
01643 {
01644 if ($this->get_permalink())
01645 {
01646 return 'http://smarking.com/editbookmark/?url=' . rawurlencode($this->get_permalink());
01647 }
01648 else
01649 {
01650 return false;
01651 }
01652 }
01653
01654 function add_to_spurl()
01655 {
01656 if ($this->get_permalink())
01657 {
01658 $url = 'http://www.spurl.net/spurl.php?v=3&url=' . rawurlencode($this->get_permalink());
01659 if ($this->get_title())
01660 {
01661 $url .= '&title=' . rawurlencode($this->get_title());
01662 }
01663 return $url;
01664 }
01665 else
01666 {
01667 return false;
01668 }
01669 }
01670
01671 function add_to_wists()
01672 {
01673 if ($this->get_permalink())
01674 {
01675 $url = 'http://wists.com/r.php?c=&r=' . rawurlencode($this->get_permalink());
01676 if ($this->get_title())
01677 {
01678 $url .= '&title=' . rawurlencode($this->get_title());
01679 }
01680 return $url;
01681 }
01682 else
01683 {
01684 return false;
01685 }
01686 }
01687
01688 function search_technorati()
01689 {
01690 if ($this->get_permalink())
01691 {
01692 return 'http://www.technorati.com/search/' . rawurlencode($this->get_permalink());
01693 }
01694 else
01695 {
01696 return false;
01697 }
01698 }
01699 }
01700
01701 class SimplePie_Author
01702 {
01703 var $name;
01704 var $link;
01705 var $email;
01706
01707
01708 function SimplePie_Author($name, $link, $email)
01709 {
01710 $this->name = $name;
01711 $this->link = $link;
01712 $this->email = $email;
01713 }
01714
01715 function get_name()
01716 {
01717 if (!empty($this->name))
01718 {
01719 return $this->name;
01720 }
01721 else
01722 {
01723 return false;
01724 }
01725 }
01726
01727 function get_link()
01728 {
01729 if (!empty($this->link))
01730 {
01731 return $this->link;
01732 }
01733 else
01734 {
01735 return false;
01736 }
01737 }
01738
01739 function get_email()
01740 {
01741 if (!empty($this->email))
01742 {
01743 return $this->email;
01744 }
01745 else
01746 {
01747 return false;
01748 }
01749 }
01750 }
01751
01752 class SimplePie_Enclosure
01753 {
01754 var $link;
01755 var $type;
01756 var $length;
01757
01758
01759 function SimplePie_Enclosure($link, $type, $length)
01760 {
01761 $this->link = $link;
01762 $this->type = $type;
01763 $this->length = $length;
01764 }
01765
01766 function get_link()
01767 {
01768 if (!empty($this->link))
01769 {
01770 if (class_exists('idna_convert'))
01771 {
01772 $idn = new idna_convert;
01773 $this->link = $idn->encode($this->link);
01774 }
01775 return $this->link;
01776 }
01777 else
01778 {
01779 return false;
01780 }
01781 }
01782
01783 function get_extension()
01784 {
01785 if (!empty($this->link))
01786 {
01787 return pathinfo($this->link, PATHINFO_EXTENSION);
01788 }
01789 else
01790 {
01791 return false;
01792 }
01793 }
01794
01795 function get_type()
01796 {
01797 if (!empty($this->type))
01798 {
01799 return $this->type;
01800 }
01801 else
01802 {
01803 return false;
01804 }
01805 }
01806
01807 function get_length()
01808 {
01809 if (!empty($this->length))
01810 {
01811 return $this->length;
01812 }
01813 else
01814 {
01815 return false;
01816 }
01817 }
01818
01819 function get_size()
01820 {
01821 $length = $this->get_length();
01822 if (!empty($length))
01823 {
01824 return round($length/1048576, 2);
01825 }
01826 else
01827 {
01828 return false;
01829 }
01830 }
01831
01832 function native_embed($options='')
01833 {
01834 return $this->embed($options, true);
01835 }
01836
01837 function embed($options = '', $native = false)
01838 {
01839
01840 $audio = '';
01841 $video = '';
01842 $alt = '';
01843 $altclass = '';
01844 $loop = 'false';
01845 $width = 'auto';
01846 $height = 'auto';
01847 $bgcolor = '#ffffff';
01848
01849
01850 if (is_array($options))
01851 {
01852 extract($options);
01853 }
01854 else
01855 {
01856 $options = explode(',', $options);
01857 foreach($options as $option)
01858 {
01859 $opt = explode(':', $option, 2);
01860 if (isset($opt[0], $opt[1]))
01861 {
01862 $opt[0] = trim($opt[0]);
01863 $opt[1] = trim($opt[1]);
01864 switch ($opt[0])
01865 {
01866 case 'audio':
01867 $audio = $opt[1];
01868 break;
01869
01870 case 'video':
01871 $video = $opt[1];
01872 break;
01873
01874 case 'alt':
01875 $alt = $opt[1];
01876 break;
01877
01878 case 'altclass':
01879 $altclass = $opt[1];
01880 break;
01881
01882 case 'loop':
01883 $loop = $opt[1];
01884 break;
01885
01886 case 'width':
01887 $width = $opt[1];
01888 break;
01889
01890 case 'height':
01891 $height = $opt[1];
01892 break;
01893
01894 case 'bgcolor':
01895 $bgcolor = $opt[1];
01896 break;
01897 }
01898 }
01899 }
01900 }
01901
01902 $type = strtolower($this->get_type());
01903
01904
01905 if (!in_array($type, array('audio/3gpp', 'audio/3gpp2', 'audio/aac', 'audio/x-aac', 'audio/aiff', 'audio/x-aiff', 'audio/mid', 'audio/midi', 'audio/x-midi', 'audio/mpeg', 'audio/x-mpeg', 'audio/mp3', 'x-audio/mp3', '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', 'application/x-shockwave-flash', 'application/futuresplash', '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')))
01906 {
01907 switch (strtolower($this->get_extension()))
01908 {
01909
01910 case 'aac':
01911 case 'adts':
01912 $type = 'audio/acc';
01913 break;
01914
01915 case 'aif':
01916 case 'aifc':
01917 case 'aiff':
01918 case 'cdda':
01919 $type = 'audio/aiff';
01920 break;
01921
01922 case 'bwf':
01923 $type = 'audio/wav';
01924 break;
01925
01926 case 'kar':
01927 case 'mid':
01928 case 'midi':
01929 case 'smf':
01930 $type = 'audio/midi';
01931 break;
01932
01933 case 'm4a':
01934 $type = 'audio/x-m4a';
01935 break;
01936
01937 case 'mp3':
01938 case 'swa':
01939 $type = 'audio/mp3';
01940 break;
01941
01942 case 'wav':
01943 $type = 'audio/wav';
01944 break;
01945
01946 case 'wax':
01947 $type = 'audio/x-ms-wax';
01948 break;
01949
01950 case 'wma':
01951 $type = 'audio/x-ms-wma';
01952 break;
01953
01954
01955 case '3gp':
01956 case '3gpp':
01957 $type = 'video/3gpp';
01958 break;
01959
01960 case '3g2':
01961 case '3gp2':
01962 $type = 'video/3gpp2';
01963 break;
01964
01965 case 'asf':
01966 $type = 'video/x-ms-asf';
01967 break;
01968
01969 case 'm1a':
01970 case 'm1s':
01971 case 'm1v':
01972 case 'm15':
01973 case 'm75':
01974 case 'mp2':
01975 case 'mpa':
01976 case 'mpeg':
01977 case 'mpg':
01978 case 'mpm':
01979 case 'mpv':
01980 $type = 'video/mpeg';
01981 break;
01982
01983 case 'm4v':
01984 $type = 'video/x-m4v';
01985 break;
01986
01987 case 'mov':
01988 case 'qt':
01989 $type = 'video/quicktime';
01990 break;
01991
01992 case 'mp4':
01993 case 'mpg4':
01994 $type = 'video/mp4';
01995 break;
01996
01997 case 'sdv':
01998 $type = 'video/sd-video';
01999 break;
02000
02001 case 'wm':
02002 $type = 'video/x-ms-wm';
02003 break;
02004
02005 case 'wmv':
02006 $type = 'video/x-ms-wmv';
02007 break;
02008
02009 case 'wvx':
02010 $type = 'video/x-ms-wvx';
02011 break;
02012
02013
02014 case 'spl':
02015 $type = 'application/futuresplash';
02016 break;
02017
02018 case 'swf':
02019 $type = 'application/x-shockwave-flash';
02020 break;
02021 }
02022 }
02023
02024 $mime = explode('/', $type, 2);
02025 $mime = $mime[0];
02026
02027
02028 if ($width == 'auto')
02029 {
02030 if ($mime == 'video')
02031 {
02032 $width = '320';
02033 }
02034 else
02035 {
02036 $width = '100%';
02037 }
02038 }
02039 if ($height == 'auto')
02040 {
02041 if ($mime == 'audio')
02042 {
02043 $height = 0;
02044 }
02045 else if ($mime == 'video')
02046 {
02047 $height = 240;
02048 }
02049 else
02050 {
02051 $height = 256;
02052 }
02053 }
02054
02055
02056 if ($mime == 'audio')
02057 {
02058 $placeholder = $audio;
02059 }
02060 else if ($mime == 'video')
02061 {
02062 $placeholder = $video;
02063 }
02064
02065 $embed = '';
02066
02067
02068
02069 if (!$native)
02070 {
02071 $embed .= '<script type="text/javascript" src="?js"></script>';
02072 }
02073
02074
02075 if (substr(strtolower($this->get_link()), 0, 15) == 'http://odeo.com') {
02076 if ($native)
02077 {
02078 $embed .= '<embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="440" height="80" wmode="transparent" allowScriptAccess="any" flashvars="valid_sample_rate=true&external_url=' . $this->get_link() . '"></embed>';
02079 }
02080 else
02081 {
02082 $embed .= '<script type="text/javascript">embed_odeo("' . $this->get_link() . '");</script>';
02083 }
02084 }
02085
02086
02087 else if (in_array($type, array('audio/3gpp', 'audio/3gpp2', 'audio/aac', 'audio/x-aac', 'audio/aiff', 'audio/x-aiff', 'audio/mid', 'audio/midi', 'audio/x-midi', 'audio/mpeg', 'audio/x-mpeg', 'audio/mp3', 'x-audio/mp3', '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')))
02088 {
02089 $height += 16;
02090 if ($native)
02091 {
02092 if ($placeholder != "") {
02093 $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://www.apple.com/quicktime/download/\"></embed>";
02094 }
02095 else {
02096 $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://www.apple.com/quicktime/download/\"></embed>";
02097 }
02098 }
02099 else
02100 {
02101 $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>";
02102 }
02103 }
02104
02105
02106 else if (in_array($type, array('application/x-shockwave-flash', 'application/futuresplash')))
02107 {
02108 if ($native)
02109 {
02110 $embed .= "<embed src=\"" . $this->get_link() . "\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"$type\" quality=\"high\" width=\"$width\" height=\"$height\" bgcolor=\"$bgcolor\" loop=\"$loop\"></embed>";
02111 }
02112 else
02113 {
02114 $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>";
02115 }
02116 }
02117
02118
02119 else if (in_array($type, 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')))
02120 {
02121 $height += 45;
02122 if ($native)
02123 {
02124 $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>";
02125 }
02126 else
02127 {
02128 $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>";
02129 }
02130 }
02131
02132
02133 else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>';
02134
02135 return $embed;
02136 }
02137 }
02138
02139 class SimplePie_File
02140 {
02141 var $url;
02142 var $useragent;
02143 var $success = true;
02144 var $headers = array();
02145 var $body;
02146 var $fp;
02147 var $redirects = 0;
02148 var $error;
02149 var $method;
02150
02151 function SimplePie_File($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
02152 {
02153 if (class_exists('idna_convert'))
02154 {
02155 $idn = new idna_convert;
02156 $url = $idn->encode($url);
02157 }
02158 $this->url = $url;
02159 $this->useragent = $useragent;
02160 if (preg_match('/^http(s)?:\/\//i', $url))
02161 {
02162 if (empty($useragent))
02163 {
02164 $useragent = ini_get('user_agent');
02165 $this->useragent = $useragent;
02166 }
02167 if (!is_array($headers))
02168 {
02169 $headers = array();
02170 }
02171 if (extension_loaded('curl') && version_compare(SimplePie_Misc::get_curl_version(), '7.10.5', '>=') && !$force_fsockopen)
02172 {
02173 $this->method = 'curl';
02174 $fp = curl_init();
02175 $headers2 = array();
02176 foreach ($headers as $key => $value)
02177 {
02178 $headers2[] = "$key: $value";
02179 }
02180 curl_setopt($fp, CURLOPT_ENCODING, '');
02181 curl_setopt($fp, CURLOPT_URL, $url);
02182 curl_setopt($fp, CURLOPT_HEADER, 1);
02183 curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
02184 curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
02185 curl_setopt($fp, CURLOPT_REFERER, $url);
02186 curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
02187 curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
02188 if (!ini_get('open_basedir') && !ini_get('safe_mode'))
02189 {
02190 curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
02191 curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
02192 }
02193
02194 $this->headers = trim(curl_exec($fp));
02195 if (curl_errno($fp) == 23 || curl_errno($fp) == 61)
02196 {
02197 curl_setopt($fp, CURLOPT_ENCODING, 'none');
02198 $this->headers = trim(curl_exec($fp));
02199 }
02200 if (curl_errno($fp))
02201 {
02202 $this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
02203 $this->success = false;
02204 return false;
02205 }
02206 $info = curl_getinfo($fp);
02207 $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 2);
02208 if (count($this->headers) == $info['redirect_count'] + 1)
02209 {
02210 $this->headers = array_pop($this->headers);
02211 $this->body = '';
02212 }
02213 else
02214 {
02215 $this->body = array_pop($this->headers);
02216 $this->headers = array_pop($this->headers);
02217 }
02218 $this->headers = $this->parse_headers($this->headers);
02219 if (($this->headers['status']['code'] == 301 || $this->headers['status']['code'] == 302 || $this->headers['status']['code'] == 303 || $this->headers['status']['code'] == 307) && !empty($this->headers['location']) && $this->redirects < $redirects)
02220 {
02221 $this->redirects++;
02222 return $this->SimplePie_File($this->headers['location'], $timeout, $redirects, $headers, $useragent, $force_fsockopen);
02223 }
02224 }
02225 else
02226 {
02227 $this->method = 'fsockopen';
02228 $url_parts = parse_url($url);
02229 if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) == 'https')
02230 {
02231 $url_parts['host'] = "ssl://$url_parts[host]";
02232 $url_parts['port'] = 443;
02233 }
02234 if (!isset($url_parts['port']))
02235 {
02236 $url_parts['port'] = 80;
02237 }
02238 $this->fp = fsockopen($url_parts['host'], $url_parts['port'], $errno, $errstr, $timeout);
02239 if (!$this->fp)
02240 {
02241 $this->error = 'fsockopen error: ' . $errstr;
02242 $this->success = false;
02243 return false;
02244 }
02245 else
02246 {
02247 stream_set_timeout($this->fp, $timeout);
02248 $get = (isset($url_parts['query'])) ? "$url_parts[path]?$url_parts[query]" : $url_parts['path'];
02249 $out = "GET $get HTTP/1.0\r\n";
02250 $out .= "Host: $url_parts[host]\r\n";
02251 $out .= "User-Agent: $useragent\r\n";
02252 if (function_exists('gzinflate'))
02253 {
02254 $out .= "Accept-Encoding: gzip,deflate\r\n";
02255 }
02256
02257 if (!empty($url_parts['user']) && !empty($url_parts['pass']))
02258 {
02259 $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
02260 }
02261 foreach ($headers as $key => $value)
02262 {
02263 $out .= "$key: $value\r\n";
02264 }
02265 $out .= "Connection: Close\r\n\r\n";
02266 fwrite($this->fp, $out);
02267
02268 $info = stream_get_meta_data($this->fp);
02269 $data = '';
02270 while (strpos($data, "\r\n\r\n") === false && !$info['timed_out'])
02271 {
02272 $data .= fgets($this->fp, 128);
02273 $info = stream_get_meta_data($this->fp);
02274 }
02275 if (!$info['timed_out'])
02276 {
02277 $this->headers = $this->parse_headers($data);
02278 if (($this->headers['status']['code'] == 301 || $this->headers['status']['code'] == 302 || $this->headers['status']['code'] == 303 || $this->headers['status']['code'] == 307) && !empty($this->headers['location']) && $this->redirects < $redirects)
02279 {
02280 $this->redirects++;
02281 return $this->SimplePie_File($this->headers['location'], $timeout, $redirects, $headers, $useragent, $force_fsockopen);
02282 }
02283 }
02284 else
02285 {
02286 $this->close();
02287 $this->error = 'fsocket timed out';
02288 $this->success = false;
02289 return false;
02290 }
02291 }
02292 }
02293 return $this->headers['status']['code'];
02294 }
02295 else
02296 {
02297 $this->method = 'fopen';
02298 if ($this->fp = fopen($url, 'r'))
02299 {
02300 return true;
02301 }
02302 else
02303 {
02304 $this->error = 'fopen could not open the file';
02305 $this->success = false;
02306 return false;
02307 }
02308 }
02309 }
02310
02311 function headers()
02312 {
02313 return $this->headers;
02314 }
02315
02316 function body()
02317 {
02318 if (is_null($this->body))
02319 {
02320 if ($this->fp)
02321 {
02322 $info = stream_get_meta_data($this->fp);
02323 $this->body = '';
02324 while (!$info['eof'] && !$info['timed_out'])
02325 {
02326 $this->body .= fread($this->fp, 1024);
02327 $info = stream_get_meta_data($this->fp);
02328 }
02329 if (!$info['timed_out'])
02330 {
02331 $this->body = trim($this->body);
02332 if ($this->method == 'fsockopen' && !empty($this->headers['content-encoding']) && ($this->headers['content-encoding'] == 'gzip' || $this->headers['content-encoding'] == 'deflate'))
02333 {
02334 if (substr($this->body, 0, 8) == "\x1f\x8b\x08\x00\x00\x00\x00\x00")
02335 {
02336 $this->body = substr($this->body, 10);
02337 }
02338 $this->body = gzinflate($this->body);
02339 }
02340 $this->close();
02341 }
02342 else
02343 {
02344 return false;
02345 }
02346 }
02347 else
02348 {
02349 return false;
02350 }
02351 }
02352 return $this->body;
02353 }
02354
02355 function close()
02356 {
02357 if (!is_null($this->fp))
02358 {
02359 if (fclose($this->fp))
02360 {
02361 $this->fp = null;
02362 return true;
02363 }
02364 else
02365 {
02366 return false;
02367 }
02368 }
02369 else
02370 {
02371 return false;
02372 }
02373 }
02374
02375 function parse_headers($headers)
02376 {
02377 $headers = explode("\r\n", trim($headers));
02378 $status = array_shift($headers);
02379 foreach ($headers as $header)
02380 {
02381 $data = explode(':', $header, 2);
02382 $head[strtolower(trim($data[0]))] = trim($data[1]);
02383 }
02384 if (preg_match('/HTTP\/[0-9\.]+ ([0-9]+)(.*)$/i', $status, $matches))
02385 {
02386 if (isset($head['status']))
02387 {
02388 unset($head['status']);
02389 }
02390 $head['status']['code'] = $matches[1];
02391 $head['status']['name'] = trim($matches[2]);
02392 }
02393 return $head;
02394 }
02395 }
02396
02397 class SimplePie_Cache
02398 {
02399 var $location;
02400 var $filename;
02401 var $extension;
02402 var $name;
02403
02404 function SimplePie_Cache($location, $filename, $extension)
02405 {
02406 $this->location = $location;
02407 $this->filename = rawurlencode($filename);
02408 $this->extension = rawurlencode($extension);
02409 $this->name = "$location/$this->filename.$this->extension";
02410 }
02411
02412 function save($data)
02413 {
02414 if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
02415 {
02416 $fp = fopen($this->name, 'w');
02417 if ($fp)
02418 {
02419 fwrite($fp, serialize($data));
02420 fclose($fp);
02421 return true;
02422 }
02423 }
02424 return false;
02425 }
02426
02427 function load()
02428 {
02429 if (file_exists($this->name) && is_readable($this->name))
02430 {
02431 return unserialize(file_get_contents($this->name));
02432 }
02433 return false;
02434 }
02435
02436 function mtime()
02437 {
02438 if (file_exists($this->name))
02439 {
02440 return filemtime($this->name);
02441 }
02442 return false;
02443 }
02444
02445 function touch()
02446 {
02447 if (file_exists($this->name))
02448 {
02449 return touch($this->name);
02450 }
02451 return false;
02452 }
02453
02454 function unlink()
02455 {
02456 if (file_exists($this->name))
02457 {
02458 return unlink($this->name);
02459 }
02460 return false;
02461 }
02462 }
02463
02464 class SimplePie_Misc
02465 {
02466 function absolutize_url($relative, $base)
02467 {
02468 $relative = trim($relative);
02469 $base = trim($base);
02470 if (!empty($relative))
02471 {
02472 $relative = SimplePie_Misc::parse_url($relative, false);
02473 $relative = array('scheme' => $relative[2], 'authority' => $relative[3], 'path' => $relative[5], 'query' => $relative[7], 'fragment' => $relative[9]);
02474 if (!empty($relative['scheme']))
02475 {
02476 $target = $relative;
02477 }
02478 else if (!empty($base))
02479 {
02480 $base = SimplePie_Misc::parse_url($base, false);
02481 $base = array('scheme' => $base[2], 'authority' => $base[3], 'path' => $base[5], 'query' => $base[7], 'fragment' => $base[9]);
02482 $target['scheme'] = $base['scheme'];
02483 if (!empty($relative['authority']))
02484 {
02485 $target = array_merge($relative, $target);
02486 }
02487 else
02488 {
02489 $target['authority'] = $base['authority'];
02490 if (!empty($relative['path']))
02491 {
02492 if (strpos($relative['path'], '/') === 0)
02493 {
02494 $target['path'] = $relative['path'];
02495 }
02496 else
02497 {
02498 if (!empty($base['path']))
02499 {
02500 $target['path'] = dirname("$base[path].") . '/' . $relative['path'];
02501 }
02502 else
02503 {
02504 $target['path'] = '/' . $relative['path'];
02505 }
02506 }
02507 if (!empty($relative['query']))
02508 {
02509 $target['query'] = $relative['query'];
02510 }
02511 $input = $target['path'];
02512 $target['path'] = '';
02513 while (!empty($input))
02514 {
02515 if (strpos($input, '../') === 0)
02516 {
02517 $input = substr($input, 3);
02518 }
02519 else if (strpos($input, './') === 0)
02520 {
02521 $input = substr($input, 2);
02522 }
02523 else if (strpos($input, '/./') === 0)
02524 {
02525 $input = substr_replace($input, '/', 0, 3);
02526 }
02527 else if (strpos($input, '/.') === 0 && SimplePie_Misc::strendpos($input, '/.') === 0)
02528 {
02529 $input = substr_replace($input, '/', -2);
02530 }
02531 else if (strpos($input, '/../') === 0)
02532 {
02533 $input = substr_replace($input, '/', 0, 4);
02534 $target['path'] = preg_replace('/(\/)?([^\/]+)$/msiU', '', $target['path']);
02535 }
02536 else if (strpos($input, '/..') === 0 && SimplePie_Misc::strendpos($input, '/..') === 0)
02537 {
02538 $input = substr_replace($input, '/', 0, 3);
02539 $target['path'] = preg_replace('/(\/)?([^\/]+)$/msiU', '', $target['path']);
02540 }
02541 else if ($input == '.' || $input == '..')
02542 {
02543 $input = '';
02544 }
02545 else
02546 {
02547 if (preg_match('/^(.+)(\/|$)/msiU', $input, $match))
02548 {
02549 $target['path'] .= $match[1];
02550 $input = substr_replace($input, '', 0, strlen($match[1]));
02551 }
02552 }
02553 }
02554 }
02555 else
02556 {
02557 if (!empty($base['path']))
02558 {
02559 $target['path'] = $base['path'];
02560 }
02561 else
02562 {
02563 $target['path'] = '/';
02564 }
02565 if (!empty($relative['query']))
02566 {
02567 $target['query'] = $relative['query'];
02568 }
02569 else if (!empty($base['query']))
02570 {
02571 $target['query'] = $base['query'];
02572 }
02573 }
02574 }
02575 if (!empty($relative['fragment']))
02576 {
02577 $target['fragment'] = $relative['fragment'];
02578 }
02579 }
02580 else
02581 {
02582 return false;
02583 }
02584 $return = '';
02585 if (!empty($target['scheme']))
02586 {
02587 $return .= "$target[scheme]:";
02588 }
02589 if (!empty($target['authority']))
02590 {
02591 $return .= $target['authority'];
02592 }
02593 if (!empty($target['path']))
02594 {
02595 $return .= $target['path'];
02596 }
02597 if (!empty($target['query']))
02598 {
02599 $return .= "?$target[query]";
02600 }
02601 if (!empty($target['fragment']))
02602 {
02603 $return .= "#$target[fragment]";
02604 }
02605 }
02606 else
02607 {
02608 $return = $base;
02609 }
02610 return $return;
02611 }
02612
02613 function strendpos($haystack, $needle)
02614 {
02615 return strlen($haystack) - strpos($haystack, $needle) - strlen($needle);
02616 }
02617
02618 function get_element($realname, $string)
02619 {
02620 $return = array();
02621 $name = preg_quote($realname, '/');
02622 preg_match_all("/<($name)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'|(.*)))*)\s*((\/)?>|>(.*)<\/$name>)/msiU", $string, $matches, PREG_SET_ORDER);
02623 for ($i = 0; $i < count($matches); $i++)
02624 {
02625 $return[$i]['tag'] = $realname;
02626 $return[$i]['full'] = $matches[$i][0];
02627 if (strlen($matches[$i][10]) <= 2)
02628 {
02629 $return[$i]['self_closing'] = true;
02630 }
02631 else
02632 {
02633 $return[$i]['self_closing'] = false;
02634 $return[$i]['content'] = $matches[$i][12];
02635 }
02636 $return[$i]['attribs'] = array();
02637 if (!empty($matches[$i][2]))
02638 {
02639 preg_match_all('/((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(\S+))\s/msiU', ' ' . $matches[$i][2] . ' ', $attribs, PREG_SET_ORDER);
02640 for ($j = 0; $j < count($attribs); $j++)
02641 {
02642 $return[$i]['attribs'][strtoupper($attribs[$j][1])]['data'] = $attribs[$j][count($attribs[$j])-1];
02643 $first = substr($attribs[$j][2], 0, 1);
02644 $return[$i]['attribs'][strtoupper($attribs[$j][1])]['split'] = ($first == '"' || $first == "'") ? $first : '"';
02645 }
02646 }
02647 }
02648 return $return;
02649 }
02650
02651 function element_implode($element)
02652 {
02653 $full = "<$element[tag]";
02654 foreach ($element['attribs'] as $key => $value)
02655 {
02656 $key = strtolower($key);
02657 $full .= " $key=$value[split]$value[data]$value[split]";
02658 }
02659 if ($element['self_closing'])
02660 {
02661 $full .= ' />';
02662 }
02663 else
02664 {
02665 $full .= ">$element[content]</$element[tag]>";
02666 }
02667 return $full;
02668 }
02669
02670 function error($message, $level, $file, $line)
02671 {
02672 switch ($level)
02673 {
02674 case E_USER_ERROR:
02675 $note = 'PHP Error';
02676 break;
02677 case E_USER_WARNING:
02678 $note = 'PHP Warning';
02679 break;
02680 case E_USER_NOTICE:
02681 $note = 'PHP Notice';
02682 break;
02683 default:
02684 $note = 'Unknown Error';
02685 break;
02686 }
02687 error_log("$note: $message in $file on line $line", 0);
02688 return $message;
02689 }
02690
02691 function display_file($url, $timeout = 10, $useragent = null)
02692 {
02693 $file = new SimplePie_File($url, $timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $useragent);
02694 $headers = $file->headers();
02695 if ($file->body() !== false)
02696 {
02697 header('Content-type: ' . $headers['content-type']);
02698 echo $file->body();
02699 exit;
02700 }
02701 }
02702
02703 function fix_protocol($url, $http = 1)
02704 {
02705 $parsed = SimplePie_Misc::parse_url($url);
02706 if (!empty($parsed['scheme']) && strtolower($parsed['scheme']) != 'http' && strtolower($parsed['scheme']) != 'https')
02707 {
02708 return SimplePie_Misc::fix_protocol("$parsed[authority]$parsed[path]$parsed[query]$parsed[fragment]", $http);
02709 }
02710 if (!file_exists($url) && empty($parsed['scheme']))
02711 {
02712 return SimplePie_Misc::fix_protocol("http://$url", $http);
02713 }
02714
02715 if ($http == 2 && !empty($parsed['scheme']))
02716 {
02717 return "feed:$url";
02718 }
02719 else if ($http == 3 && strtolower($parsed['scheme']) == 'http')
02720 {
02721 return substr_replace($url, 'podcast', 0, 4);
02722 }
02723 else
02724 {
02725 return $url;
02726 }
02727 }
02728
02729 function parse_url($url, $parse_match = true)
02730 {
02731 preg_match('/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/i', $url, $match);
02732 if (empty($match[0]))
02733 {
02734 return false;
02735 }
02736 else
02737 {
02738 for ($i = 6; $i < 10; $i++)
02739 {
02740 if (!isset($match[$i]))
02741 {
02742 $match[$i] = '';
02743 }
02744 }
02745 if ($parse_match)
02746 {
02747 $match = array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => $match[6], 'fragment' => $match[8]);
02748 }
02749 return $match;
02750 }
02751 }
02752
02764 function utf8_bad_replace($str)
02765 {
02766 $UTF8_BAD =
02767 '([\x00-\x7F]' . # ASCII (including control chars)
02768 '|[\xC2-\xDF][\x80-\xBF]' . # non-overlong 2-byte
02769 '|\xE0[\xA0-\xBF][\x80-\xBF]' . # excluding overlongs
02770 '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' . # straight 3-byte
02771 '|\xED[\x80-\x9F][\x80-\xBF]' . # excluding surrogates
02772 '|\xF0[\x90-\xBF][\x80-\xBF]{2}' . # planes 1-3
02773 '|[\xF1-\xF3][\x80-\xBF]{3}' . # planes 4-15
02774 '|\xF4[\x80-\x8F][\x80-\xBF]{2}' . # plane 16
02775 '|(.{1}))'; # invalid byte
02776 $output = '';
02777 while (preg_match('/' . $UTF8_BAD . '/S', $str, $matches))
02778 {
02779 if (!isset($matches[2]))
02780 {
02781 $output .= $matches[0];
02782 }
02783 $str = substr($str, strlen($matches[0]));
02784 }
02785 return $output;
02786 }
02787
02788 function change_encoding($data, $input, $output)
02789 {
02790 $input = SimplePie_Misc::encoding($input);
02791 $output = SimplePie_Misc::encoding($output);
02792
02793 if ($input != $output)
02794 {
02795 if (function_exists('iconv') && $input['use_iconv'] && $output['use_iconv'] && iconv($input['encoding'], "$output[encoding]//TRANSLIT", $data))
02796 {
02797 return iconv($input['encoding'], "$output[encoding]//TRANSLIT", $data);
02798 }
02799 else if (function_exists('iconv') && $input['use_iconv'] && $output['use_iconv'] && iconv($input['encoding'], $output['encoding'], $data))
02800 {
02801 return iconv($input['encoding'], $output['encoding'], $data);
02802 }
02803 else if (function_exists('mb_convert_encoding') && $input['use_mbstring'] && $output['use_mbstring'])
02804 {
02805 return mb_convert_encoding($data, $output['encoding'], $input['encoding']);
02806 }
02807 else if ($input['encoding'] == 'ISO-8859-1' && $output['encoding'] == 'UTF-8')
02808 {
02809 return utf8_encode($data);
02810 }
02811 else if ($input['encoding'] == 'UTF-8' && $output['encoding'] == 'ISO-8859-1')
02812 {
02813 return utf8_decode($data);
02814 }
02815 }
02816 return $data;
02817 }
02818
02819 function encoding($encoding)
02820 {
02821 $return['use_mbstring'] = false;
02822 $return['use_iconv'] = false;
02823 switch (strtolower($encoding))
02824 {
02825
02826
02827 case '7bit':
02828 case '7-bit':
02829 $return['encoding'] = '7bit';
02830 $return['use_mbstring'] = true;
02831 break;
02832
02833
02834 case '8bit':
02835 case '8-bit':
02836 $return['encoding'] = '8bit';
02837 $return['use_mbstring'] = true;
02838 break;
02839
02840
02841 case 'armscii-8':
02842 case 'armscii':
02843 $return['encoding'] = 'ARMSCII-8';
02844 $return['use_iconv'] = true;
02845 break;
02846
02847
02848 case 'us-ascii':
02849 case 'ascii':
02850 $return['encoding'] = 'US-ASCII';
02851 $return['use_iconv'] = true;
02852 $return['use_mbstring'] = true;
02853 break;
02854
02855
02856 case 'base64':
02857 case 'base-64':
02858 $return['encoding'] = 'BASE64';
02859 $return['use_mbstring'] = true;
02860 break;
02861
02862
02863 case 'big5':
02864 case '950':
02865 $return['encoding'] = 'BIG5';
02866 $return['use_iconv'] = true;
02867 $return['use_mbstring'] = true;
02868 break;
02869
02870
02871 case 'big5-hkscs':
02872 $return['encoding'] = 'BIG5-HKSCS';
02873 $return['use_iconv'] = true;
02874 $return['use_mbstring'] = true;
02875 break;
02876
02877
02878 case 'byte2be':
02879 $return['encoding'] = 'byte2be';
02880 $return['use_mbstring'] = true;
02881 break;
02882
02883
02884 case 'byte2le':
02885 $return['encoding'] = 'byte2le';
02886 $return['use_mbstring'] = true;
02887 break;
02888
02889
02890 case 'byte4be':
02891 $return['encoding'] = 'byte4be';
02892 $return['use_mbstring'] = true;
02893 break;
02894
02895
02896 case 'byte4le':
02897 $return['encoding'] = 'byte4le';
02898 $return['use_mbstring'] = true;
02899 break;
02900
02901
02902 case 'euc-cn':
02903 case 'euccn':
02904 $return['encoding'] = 'EUC-CN';
02905 $return['use_iconv'] = true;
02906 $return['use_mbstring'] = true;
02907 break;
02908
02909
02910 case 'euc-jisx0213':
02911 case 'eucjisx0213':
02912 $return['encoding'] = 'EUC-JISX0213';
02913 $return['use_iconv'] = true;
02914 break;
02915
02916
02917 case 'euc-jp':
02918 case 'eucjp':
02919 $return['encoding'] = 'EUC-JP';
02920 $return['use_iconv'] = true;
02921 $return['use_mbstring'] = true;
02922 break;
02923
02924
02925 case 'euc-jp-win':
02926 case 'eucjp-win':
02927 case 'eucjpwin':
02928 $return['encoding'] = 'EUCJP-win';
02929 $return['use_iconv'] = true;
02930 $return['use_mbstring'] = true;
02931 break;
02932
02933
02934 case 'euc-kr':
02935 case 'euckr':
02936 $return['encoding'] = 'EUC-KR';
02937 $return['use_iconv'] = true;
02938 $return['use_mbstring'] = true;
02939 break;
02940
02941
02942 case 'euc-tw':
02943 case 'euctw':
02944 $return['encoding'] = 'EUC-TW';
02945 $return['use_iconv'] = true;
02946 $return['use_mbstring'] = true;
02947 break;
02948
02949
02950 case 'gb18030-2000':
02951 case 'gb18030':
02952 $return['encoding'] = 'GB18030';
02953 $return['use_iconv'] = true;
02954 break;
02955
02956
02957 case 'gb2312':
02958 case '936':
02959 $return['encoding'] = 'GB2312';
02960 $return['use_mbstring'] = true;
02961 break;
02962
02963
02964 case 'gbk':
02965 $return['encoding'] = 'GBK';
02966 $return['use_iconv'] = true;
02967 break;
02968
02969
02970 case 'georgian-academy':
02971 $return['encoding'] = 'Georgian-Academy';
02972 $return['use_iconv'] = true;
02973 break;
02974
02975
02976 case 'georgian-ps':
02977 $return['encoding'] = 'Georgian-PS';
02978 $return['use_iconv'] = true;
02979 break;
02980
02981
02982 case 'html-entities':
02983 case 'htmlentities':
02984 $return['encoding'] = 'HTML-ENTITIES';
02985 $return['use_mbstring'] = true;
02986 break;
02987
02988
02989 case 'hz':
02990 $return['encoding'] = 'HZ';
02991 $return['use_iconv'] = true;
02992 $return['use_mbstring'] = true;
02993 break;
02994
02995
02996 case 'iso-2022-cn':
02997 case 'iso2022-cn':
02998 case 'iso2022cn':
02999 $return['encoding'] = 'ISO-2022-CN';
03000 $return['use_iconv'] = true;
03001 break;
03002
03003
03004 case 'iso-2022-cn-ext':
03005 case 'iso2022-cn-ext':
03006 case 'iso2022cn-ext':
03007 case 'iso2022cnext':
03008 $return['encoding'] = 'ISO-2022-CN';
03009 $return['use_iconv'] = true;
03010 break;
03011
03012
03013 case 'iso-2022-jp':
03014 case 'iso2022-jp':
03015 case 'iso2022jp':
03016 $return['encoding'] = 'ISO-2022-JP';
03017 $return['use_iconv'] = true;
03018 $return['use_mbstring'] = true;
03019 break;
03020
03021
03022 case 'iso-2022-jp-1':
03023 case 'iso2022-jp-1':
03024 case 'iso2022jp-1':
03025 case 'iso2022jp1':
03026 $return['encoding'] = 'ISO-2022-JP-1';
03027 $return['use_iconv'] = true;
03028 break;
03029
03030
03031 case 'iso-2022-jp-2':
03032 case 'iso2022-jp-2':
03033 case 'iso2022jp-2':
03034 case 'iso2022jp2':
03035 $return['encoding'] = 'ISO-2022-JP-2';
03036 $return['use_iconv'] = true;
03037 break;
03038
03039
03040 case 'iso-2022-jp-3':
03041 case 'iso2022-jp-3':
03042 case 'iso2022jp-3':
03043 case 'iso2022jp3':
03044 $return['encoding'] = 'ISO-2022-JP-3';
03045 $return['use_iconv'] = true;
03046 break;
03047
03048
03049 case 'iso-2022-kr':
03050 case 'iso2022-kr':
03051 case 'iso2022kr':
03052 $return['encoding'] = 'ISO-2022-KR';
03053 $return['use_iconv'] = true;
03054 $return['use_mbstring'] = true;
03055 break;
03056
03057
03058 case 'iso-8859-1':
03059 case 'iso8859-1':
03060 $return['encoding'] = 'ISO-8859-1';
03061 $return['use_iconv'] = true;
03062 $return['use_mbstring'] = true;
03063 break;
03064
03065
03066 case 'iso-8859-2':
03067 case 'iso8859-2':
03068 $return['encoding'] = 'ISO-8859-2';
03069 $return['use_iconv'] = true;
03070 $return['use_mbstring'] = true;
03071 break;
03072
03073
03074 case 'iso-8859-3':
03075 case 'iso8859-3':
03076 $return['encoding'] = 'ISO-8859-3';
03077 $return['use_iconv'] = true;
03078 $return['use_mbstring'] = true;
03079 break;
03080
03081
03082 case 'iso-8859-4':
03083 case 'iso8859-4':
03084 $return['encoding'] = 'ISO-8859-4';
03085 $return['use_iconv'] = true;
03086 $return['use_mbstring'] = true;
03087 break;
03088
03089
03090 case 'iso-8859-5':
03091 case 'iso8859-5':
03092 $return['encoding'] = 'ISO-8859-5';
03093 $return['use_iconv'] = true;
03094 $return['use_mbstring'] = true;
03095 break;
03096
03097
03098 case 'iso-8859-6':
03099 case 'iso8859-6':
03100 $return['encoding'] = 'ISO-8859-6';
03101 $return['use_iconv'] = true;
03102 $return['use_mbstring'] = true;
03103 break;
03104
03105
03106 case 'iso-8859-7':
03107 case 'iso8859-7':
03108 $return['encoding'] = 'ISO-8859-7';
03109 $return['use_iconv'] = true;
03110 $return['use_mbstring'] = true;
03111 break;
03112
03113
03114 case 'iso-8859-8':
03115 case 'iso8859-8':
03116 $return['encoding'] = 'ISO-8859-8';
03117 $return['use_iconv'] = true;
03118 $return['use_mbstring'] = true;
03119 break;
03120
03121
03122 case 'iso-8859-9':
03123 case 'iso8859-9':
03124 $return['encoding'] = 'ISO-8859-9';
03125 $return['use_iconv'] = true;
03126 $return['use_mbstring'] = true;
03127 break;
03128
03129
03130 case 'iso-8859-10':
03131 case 'iso8859-10':
03132 $return['encoding'] = 'ISO-8859-10';
03133 $return['use_iconv'] = true;
03134 $return['use_mbstring'] = true;
03135 break;
03136
03137
03138
03139
03140 case 'iso-8859-13':
03141 case 'iso8859-13':
03142 $return['encoding'] = 'ISO-8859-13';
03143 $return['use_iconv'] = true;
03144 $return['use_mbstring'] = true;
03145 break;
03146
03147
03148 case 'iso-8859-14':
03149 case 'iso8859-14':
03150 $return['encoding'] = 'ISO-8859-14';
03151 $return['use_iconv'] = true;
03152 $return['use_mbstring'] = true;
03153 break;
03154
03155
03156 case 'iso-8859-15':
03157 case 'iso8859-15':
03158 $return['encoding'] = 'ISO-8859-15';
03159 $return['use_iconv'] = true;
03160 $return['use_mbstring'] = true;
03161 break;
03162
03163
03164 case 'iso-8859-16':
03165 case 'iso8859-16':
03166 $return['encoding'] = 'ISO-8859-16';
03167 $return['use_iconv'] = true;
03168 break;
03169
03170
03171 case 'jis':
03172 $return['encoding'] = 'JIS';
03173 $return['use_mbstring'] = true;
03174 break;
03175
03176
03177 case 'johab':
03178 $return['encoding'] = 'JOHAB';
03179 $return['use_iconv'] = true;
03180 break;
03181
03182
03183 case 'koi8-r':
03184 case 'koi8r':
03185 $return['encoding'] = 'KOI8-R';
03186 $return['use_iconv'] = true;
03187 $return['use_mbstring'] = true;
03188 break;
03189
03190
03191 case 'koi8-t':
03192 case 'koi8t':
03193 $return['encoding'] = 'KOI8-T';
03194 $return['use_iconv'] = true;
03195 break;
03196
03197
03198 case 'koi8-u':
03199 case 'koi8u':
03200 $return['encoding'] = 'KOI8-U';
03201 $return['use_iconv'] = true;
03202 break;
03203
03204
03205 case 'koi8-ru':
03206 case 'koi8ru':
03207 $return['encoding'] = 'KOI8-RU';
03208 $return['use_iconv'] = true;
03209 break;
03210
03211
03212 case 'macintosh':
03213 $return['encoding'] = 'Macintosh';
03214 $return['use_iconv'] = true;
03215 break;
03216
03217
03218 case 'macarabic':
03219 $return['encoding'] = 'MacArabic';
03220 $return['use_iconv'] = true;
03221 break;
03222
03223
03224 case 'maccentraleurope':
03225 $return['encoding'] = 'MacCentralEurope';
03226 $return['use_iconv'] = true;
03227 break;
03228
03229
03230 case 'maccroatian':
03231 $return['encoding'] = 'MacCroatian';
03232 $return['use_iconv'] = true;
03233 break;
03234
03235
03236 case 'maccyrillic':
03237 $return['encoding'] = 'MacCyrillic';
03238 $return['use_iconv'] = true;
03239 break;
03240
03241
03242 case 'macgreek':
03243 $return['encoding'] = 'MacGreek';
03244 $return['use_iconv'] = true;
03245 break;
03246
03247
03248 case 'machebrew':
03249 $return['encoding'] = 'MacHebrew';
03250 $return['use_iconv'] = true;
03251 break;
03252
03253
03254 case 'maciceland':
03255 $return['encoding'] = 'MacIceland';
03256 $return['use_iconv'] = true;
03257 break;
03258
03259
03260 case 'macroman':
03261 $return['encoding'] = 'MacRoman';
03262 $return['use_iconv'] = true;
03263 break;
03264
03265
03266 case 'macromania':
03267 $return['encoding'] = 'MacRomania';
03268 $return['use_iconv'] = true;
03269 break;
03270
03271
03272 case 'macthai':
03273 $return['encoding'] = 'MacThai';
03274 $return['use_iconv'] = true;
03275 break;
03276
03277
03278 case 'macturkish':
03279 $return['encoding'] = 'MacTurkish';
03280 $return['use_iconv'] = true;
03281 break;
03282
03283
03284 case 'macukraine':
03285 $return['encoding'] = 'MacUkraine';
03286 $return['use_iconv'] = true;
03287 break;
03288
03289
03290 case 'mulelao-1':
03291 case 'mulelao1':
03292 $return['encoding'] = 'MuleLao-1';
03293 $return['use_iconv'] = true;
03294 break;
03295
03296
03297 case 'shift_jis':
03298 case 'sjis':
03299 case '932':
03300 $return['encoding'] = 'Shift_JIS';
03301 $return['use_iconv'] = true;
03302 $return['use_mbstring'] = true;
03303 break;
03304
03305
03306 case 'shift-jisx0213':
03307 case 'shiftjisx0213':
03308 $return['encoding'] = 'Shift_JISX0213';
03309 $return['use_iconv'] = true;
03310 break;
03311
03312
03313 case 'sjis-win':
03314 case 'sjiswin':
03315 case 'shift_jis-win':
03316 $return['encoding'] = 'SJIS-win';
03317 $return['use_iconv'] = true;
03318 $return['use_mbstring'] = true;
03319 break;
03320
03321
03322 case 'tcvn':
03323 $return['encoding'] = 'TCVN';
03324 $return['use_iconv'] = true;
03325 break;
03326
03327
03328 case 'tds565':
03329 $return['encoding'] = 'TDS565';
03330 $return['use_iconv'] = true;
03331 break;
03332
03333
03334 case 'tis-620':
03335 case 'tis620':
03336 $return['encoding'] = 'TIS-620';
03337 $return['use_iconv'] = true;
03338 $return['use_mbstring'] = true;
03339 break;
03340
03341
03342 case 'ucs-2':
03343 case 'ucs2':
03344 case 'utf-16':
03345 case 'utf16':
03346 $return['encoding'] = 'UCS-2';
03347 $return['use_iconv'] = true;
03348 $return['use_mbstring'] = true;
03349 break;
03350
03351
03352 case 'ucs-2be':
03353 case 'ucs2be':
03354 case 'utf-16be':
03355 case 'utf16be':
03356 $return['encoding'] = 'UCS-2BE';
03357 $return['use_iconv'] = true;
03358 $return['use_mbstring'] = true;
03359 break;
03360
03361
03362 case 'ucs-2le':
03363 case 'ucs2le':
03364 case 'utf-16le':
03365 case 'utf16le':
03366 $return['encoding'] = 'UCS-2LE';
03367 $return['use_iconv'] = true;
03368 $return['use_mbstring'] = true;
03369 break;
03370
03371
03372 case 'ucs-2-internal':
03373 case 'ucs2internal':
03374 $return['encoding'] = 'UCS-2-INTERNAL';
03375 $return['use_iconv'] = true;
03376 break;
03377
03378
03379 case 'ucs-4':
03380 case 'ucs4':
03381 case 'utf-32':
03382 case 'utf32':
03383 $return['encoding'] = 'UCS-4';
03384 $return['use_iconv'] = true;
03385 $return['use_mbstring'] = true;
03386 break;
03387
03388
03389 case 'ucs-4be':
03390 case 'ucs4be':
03391 case 'utf-32be':
03392 case 'utf32be':
03393 $return['encoding'] = 'UCS-4BE';
03394 $return['use_iconv'] = true;
03395 $return['use_mbstring'] = true;
03396 break;
03397
03398
03399 case 'ucs-4le':
03400 case 'ucs4le':
03401 case 'utf-32le':
03402 case 'utf32le':
03403 $return['encoding'] = 'UCS-4LE';
03404 $return['use_iconv'] = true;
03405 $return['use_mbstring'] = true;
03406 break;
03407
03408
03409 case 'ucs-4-internal':
03410 case 'ucs4internal':
03411 $return['encoding'] = 'UCS-4-INTERNAL';
03412 $return['use_iconv'] = true;
03413 break;
03414
03415
03416 case 'ucs-16':
03417 case 'ucs16':
03418 $return['encoding'] = 'UCS-16';
03419 $return['use_iconv'] = true;
03420 $return['use_mbstring'] = true;
03421 break;
03422
03423
03424 case 'ucs-16be':
03425 case 'ucs16be':
03426 $return['encoding'] = 'UCS-16BE';
03427 $return['use_iconv'] = true;
03428 $return['use_mbstring'] = true;
03429 break;
03430
03431
03432 case 'ucs-16le':
03433 case 'ucs16le':
03434 $return['encoding'] = 'UCS-16LE';
03435 $return['use_iconv'] = true;
03436 $return['use_mbstring'] = true;
03437 break;
03438
03439
03440 case 'ucs-32':
03441 case 'ucs32':
03442 $return['encoding'] = 'UCS-32';
03443 $return['use_iconv'] = true;
03444 $return['use_mbstring'] = true;
03445 break;
03446
03447
03448 case 'ucs-32be':
03449 case 'ucs32be':
03450 $return['encoding'] = 'UCS-32BE';
03451 $return['use_iconv'] = true;
03452 $return['use_mbstring'] = true;
03453 break;
03454
03455
03456 case 'ucs-32le':
03457 case 'ucs32le':
03458 $return['encoding'] = 'UCS-32LE';
03459 $return['use_iconv'] = true;
03460 $return['use_mbstring'] = true;
03461 break;
03462
03463
03464 case 'utf-7':
03465 case 'utf7':
03466 $return['encoding'] = 'UTF-7';
03467 $return['use_iconv'] = true;
03468 $return['use_mbstring'] = true;
03469 break;
03470
03471
03472 case 'utf-7-imap':
03473 case 'utf7-imap':
03474 case 'utf7imap':
03475 $return['encoding'] = 'UTF7-IMAP';
03476 $return['use_mbstring'] = true;
03477 break;
03478
03479
03480 case 'viscii':
03481 $return['encoding'] = 'VISCII';
03482 $return['use_iconv'] = true;
03483 break;
03484
03485
03486 case 'cp1250':
03487 case 'windows-1250':
03488 case 'win-1250':
03489 case '1250':
03490 $return['encoding'] = 'Windows-1250';
03491 $return['use_iconv'] = true;
03492 break;
03493
03494
03495 case 'cp1251':
03496 case 'windows-1251':
03497 case 'win-1251':
03498 case '1251':
03499 $return['encoding'] = 'Windows-1251';
03500 $return['use_iconv'] = true;
03501 $return['use_mbstring'] = true;
03502 break;
03503
03504
03505 case 'cp1252':
03506 case 'windows-1252':
03507 case '1252':
03508 $return['encoding'] = 'Windows-1252';
03509 $return['use_iconv'] = true;
03510 $return['use_mbstring'] = true;
03511 break;
03512
03513
03514 case 'cp1253':
03515 case 'windows-1253':
03516 case '1253':
03517 $return['encoding'] = 'Windows-1253';
03518 $return['use_iconv'] = true;
03519 break;
03520
03521
03522 case 'cp1254':
03523 case 'windows-1254':
03524 case '1254':
03525 $return['encoding'] = 'Windows-1254';
03526 $return['use_iconv'] = true;
03527 break;
03528
03529
03530 case 'cp1255':
03531 case 'windows-1255':
03532 case '1255':
03533 $return['encoding'] = 'Windows-1255';
03534 $return['use_iconv'] = true;
03535 break;
03536
03537
03538 case 'cp1256':
03539 case 'windows-1256':
03540 case '1256':
03541 $return['encoding'] = 'Windows-1256';
03542 $return['use_iconv'] = true;
03543 break;
03544
03545
03546 case 'cp1257':
03547 case 'windows-1257':
03548 case '1257':
03549 $return['encoding'] = 'Windows-1257';
03550 $return['use_iconv'] = true;
03551 break;
03552
03553
03554 case 'cp1258':
03555 case 'windows-1258':
03556 case '1258':
03557 $return['encoding'] = 'Windows-1258';
03558 $return['use_iconv'] = true;
03559 break;
03560
03561
03562 default:
03563 $return['encoding'] = 'UTF-8';
03564 $return['use_iconv'] = true;
03565 $return['use_mbstring'] = true;
03566 break;
03567 }
03568
03569
03570 return $return;
03571 }
03572
03573 function get_curl_version()
03574 {
03575 $curl = 0;
03576 if (is_array(curl_version()))
03577 {
03578 $curl = curl_version();
03579 $curl = $curl['version'];
03580 }
03581 else
03582 {
03583 $curl = curl_version();
03584 $curl = explode(' ', $curl);
03585 $curl = explode('/', $curl[0]);
03586 $curl = $curl[1];
03587 }
03588 return $curl;
03589 }
03590
03591 function is_a_class($class1, $class2)
03592 {
03593 if (class_exists($class1))
03594 {
03595 $classes = array(strtolower($class1));
03596 while ($class1 = get_parent_class($class1))
03597 {
03598 $classes[] = strtolower($class1);
03599 }
03600 return in_array(strtolower($class2), $classes);
03601 }
03602 else
03603 {
03604 return false;
03605 }
03606 }
03607 }
03608
03609 class SimplePie_Locator
03610 {
03611 var $useragent;
03612 var $timeout;
03613 var $file;
03614 var $local;
03615 var $elsewhere;
03616 var $file_class = 'SimplePie_File';
03617
03618 function SimplePie_Locator(&$file, $timeout = 10, $useragent = null, $file_class = 'SimplePie_File')
03619 {
03620 if (!is_a($file, 'SimplePie_File'))
03621 {
03622 $this->file = new $this->file_class($file, $timeout, $useragent);
03623 }
03624 else
03625 {
03626 $this->file =& $file;
03627 }
03628 $this->file_class = $file_class;
03629 $this->useragent = $useragent;
03630 $this->timeout = $timeout;
03631 }
03632
03633
03634 function find()
03635 {
03636 if ($this->is_feed($this->file))
03637 {
03638 return $this->file->url;
03639 }
03640
03641 $autodiscovery = $this->autodiscovery($this->file);
03642 if ($autodiscovery)
03643 {
03644 return $autodiscovery;
03645 }
03646
03647 if ($this->get_links($this->file))
03648 {
03649 if (!empty($this->local))
03650 {
03651 $extension_local = $this->extension($this->local);
03652 if ($extension_local)
03653 {
03654 return $extension_local;
03655 }
03656
03657 $body_local = $this->body($this->local);
03658 if ($body_local)
03659 {
03660 return $body_local;
03661 }
03662 }
03663
03664 if (!empty($this->elsewhere))
03665 {
03666 $extension_elsewhere = $this->extension($this->elsewhere);
03667 if ($extension_elsewhere)
03668 {
03669 return $extension_elsewhere;
03670 }
03671
03672 $body_elsewhere = $this->body($this->elsewhere);
03673 if ($body_elsewhere)
03674 {
03675 return $body_elsewhere;
03676 }
03677 }
03678 }
03679 return false;
03680 }
03681
03682 function is_feed(&$file)
03683 {
03684 if (!is_a($file, 'SimplePie_File'))
03685 {
03686 if (isset($this))
03687 {
03688 $file2 = new $this->file_class($file, $this->timeout, 5, null, $this->useragent);
03689 }
03690 else
03691 {
03692 $file2 = new $this->file_class($file);
03693 }
03694 $file2->body();
03695 $file2->close();
03696 }
03697 else
03698 {
03699 $file2 =& $file;
03700 }
03701 $body = preg_replace('/<\!-(.*)->/msiU', '', $file2->body());
03702 if (preg_match('/<(\w+\:)?rss/msiU', $body) || preg_match('/<(\w+\:)?RDF/mi', $body) || preg_match('/<(\w+\:)?feed/mi', $body))
03703 {
03704 return true;
03705 }
03706 return false;
03707 }
03708
03709 function autodiscovery(&$file)
03710 {
03711 $links = SimplePie_Misc::get_element('link', $file->body());
03712 $done = array();
03713 foreach ($links as $link)
03714 {
03715 if (!empty($link['attribs']['TYPE']['data']) && !empty($link['attribs']['HREF']['data']) && !empty($link['attribs']['REL']['data']))
03716 {
03717 $rel = preg_split('/\s+/', strtolower(trim($link['attribs']['REL']['data'])));
03718 $type = preg_match('/^(application\/rss\+xml|application\/atom\+xml|application\/rdf\+xml|application\/xml\+rss|application\/xml\+atom|application\/xml\+rdf|application\/xml|application\/x\.atom\+xml|text\/xml)(;|$)/msiU', trim($link['attribs']['TYPE']['data']));
03719 $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['HREF']['data']), $this->file->url);
03720 if (!in_array($href, $done) && in_array('alternate', $rel) && $type)
03721 {
03722 $feed = $this->is_feed($href);
03723 if ($feed)
03724 {
03725 return $href;
03726 }
03727 }
03728 $done[] = $href;
03729 }
03730 }
03731 return false;
03732 }
03733
03734 function get_links(&$file)
03735 {
03736 $links = SimplePie_Misc::get_element('a', $file->body());
03737 foreach ($links as $link)
03738 {
03739 if (!empty($link['attribs']['HREF']['data']))
03740 {
03741 $href = trim($link['attribs']['HREF']['data']);
03742 $parsed = SimplePie_Misc::parse_url($href);
03743 if (empty($parsed['scheme']) || $parsed['scheme'] != 'javascript')
03744 {
03745 $current = SimplePie_Misc::parse_url($this->file->url);
03746 if (empty($parsed['authority']) || $parsed['authority'] == $current['authority'])
03747 {
03748 $this->local[] = SimplePie_Misc::absolutize_url($href, $this->file->url);
03749 }
03750 else
03751 {
03752 $this->elsewhere[] = SimplePie_Misc::absolutize_url($href, $this->file->url);
03753 }
03754 }
03755 }
03756 }
03757 if (!empty($this->local))
03758 {
03759 $this->local = array_unique($this->local);
03760 }
03761 if (!empty($this->elsewhere))
03762 {
03763 $this->elsewhere = array_unique($this->elsewhere);
03764 }
03765 if (!empty($this->local) || !empty($this->elsewhere))
03766 {
03767 return true;
03768 }
03769 return false;
03770 }
03771
03772 function extension(&$array)
03773 {
03774 foreach ($array as $key => $value)
03775 {
03776 $value = SimplePie_Misc::absolutize_url($value, $this->file->url);
03777 if (in_array(strrchr($value, '.'), array('.rss', '.rdf', '.atom', '.xml')))
03778 {
03779 if ($this->is_feed($value))
03780 {
03781 return $value;
03782 }
03783 else
03784 {
03785 unset($array[$key]);
03786 }
03787 }
03788 }
03789 return false;
03790 }
03791
03792 function body(&$array)
03793 {
03794 foreach ($array as $key => $value)
03795 {
03796 $value = SimplePie_Misc::absolutize_url($value, $this->file->url);
03797 if (preg_match('/(rss|rdf|atom|xml)/i', $value))
03798 {
03799 if ($this->is_feed($value))
03800 {
03801 return $value;
03802 }
03803 else
03804 {
03805 unset($array[$key]);
03806 }
03807 }
03808 }
03809 return false;
03810 }
03811 }
03812
03813 class SimplePie_Parser
03814 {
03815 var $encoding;
03816 var $data;
03817 var $namespaces = array('xml' => 'HTTP://WWW.W3.ORG/XML/1998/NAMESPACE', 'atom' => 'ATOM', 'rss2' => 'RSS', 'rdf' => 'RDF', 'rss1' => 'RSS', 'dc' => 'DC', 'xhtml' => 'XHTML', 'content' => 'CONTENT');
03818 var $xml;
03819 var $error_code;
03820 var $error_string;
03821 var $current_line;
03822 var $current_column;
03823 var $current_byte;
03824 var $tag_name;
03825 var $inside_item;
03826 var $item_number = 0;
03827 var $inside_channel;
03828 var $author_number= 0;
03829 var $category_number = 0;
03830 var $enclosure_number = 0;
03831 var $link_number = 0;
03832 var $item_link_number = 0;
03833 var $inside_image;
03834 var $attribs;
03835 var $is_first;
03836 var $inside_author;
03837 var $depth_inside_item = 0;
03838
03839 function SimplePie_Parser($data, $encoding, $return_xml = false)
03840 {
03841 $this->encoding = $encoding;
03842
03843
03844
03845 if (strpos($data, sprintf('%c%c%c%c', 0x00, 0x00, 0xFE, 0xFF)) === 0)
03846 {
03847 $data = substr($data, 4);
03848 }
03849
03850 else if (strpos($data, sprintf('%c%c%c%c', 0xFF, 0xFE, 0x00, 0x00)) === 0)
03851 {
03852 $data = substr($data, 4);
03853 }
03854
03855 else if (strpos($data, sprintf('%c%c', 0xFE, 0xFF)) === 0)
03856 {
03857 $data = substr($data, 2);
03858 }
03859
03860 else if (strpos($data, sprintf('%c%c', 0xFF, 0xFE)) === 0)
03861 {
03862 $data = substr($data, 2);
03863 }
03864
03865 else if (strpos($data, sprintf('%c%c%c', 0xEF, 0xBB, 0xBF)) === 0)
03866 {
03867 $data = substr($data, 3);
03868 }
03869
03870
03871 if (preg_match('/^<\?xml(.*)?>/msiU', $data, $prolog))
03872 {
03873 $data = substr_replace($data, '', 0, strlen($prolog[0]));
03874 }
03875 $data = "<?xml version='1.0' encoding='$encoding'?>\n" . $data;
03876
03877
03878
03879 if ((stristr($data, '<rss') || preg_match('/<([a-z0-9]+\:)?RDF/mi', $data)) && (preg_match('/<([a-z0-9]+\:)?channel/mi', $data) || preg_match('/<([a-z0-9]+\:)?item/mi', $data)))
03880 {
03881 $sp_elements = array(
03882 'author',
03883 'category',
03884 'copyright',
03885 'description',
03886 'docs',
03887 'generator',
03888 'guid',
03889 'language',
03890 'lastBuildDate',
03891 'link',
03892 'managingEditor',
03893 'pubDate',
03894 'title',
03895 'url',
03896 'webMaster',
03897 );
03898 }
03899
03900 else
03901 {
03902 $sp_elements = array(
03903 'content',
03904 'copyright',
03905 'name',
03906 'subtitle',
03907 'summary',
03908 'tagline',
03909 'title',
03910 );
03911 }
03912 foreach ($sp_elements as $full)
03913 {
03914 $data = preg_replace_callback("/<($full)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'))*)\s*(\/>|>(.*)<\/$full>)/msiU", array(&$this, 'add_cdata'), $data);
03915 }
03916 foreach ($sp_elements as $full)
03917 {
03918
03919 $data = preg_replace_callback("/<($full)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'))*)\s*(\/>|><!\[CDATA\[(.*)\]\]><\/$full>)/msiU", array(&$this, 'cdata_in_cdata'), $data);
03920 }
03921
03922
03923 if ($return_xml)
03924 {
03925 $this->data =& $data;
03926 return;
03927 }
03928
03929
03930 $this->xml = xml_parser_create_ns($encoding);
03931 xml_parser_set_option($this->xml, XML_OPTION_SKIP_WHITE, 1);
03932 xml_set_object($this->xml, $this);
03933 xml_set_character_data_handler($this->xml, 'data_handler');
03934 xml_set_element_handler($this->xml, 'start_handler', 'end_handler');
03935 xml_set_start_namespace_decl_handler($this->xml, 'start_name_space');
03936 xml_set_end_namespace_decl_handler($this->xml, 'end_name_space');
03937
03938
03939 if (!xml_parse($this->xml, $data))
03940 {
03941 $this->data = null;
03942 $this->error_code = xml_get_error_code($this->xml);
03943 $this->error_string = xml_error_string($this->error_code);
03944 }
03945 $this->current_line = xml_get_current_line_number($this->xml);
03946 $this->current_column = xml_get_current_column_number($this->xml);
03947 $this->current_byte = xml_get_current_byte_index($this->xml);
03948 xml_parser_free($this->xml);
03949 return;
03950 }
03951
03952 function add_cdata($match)
03953 {
03954 if (isset($match[10]))
03955 {
03956 return "<$match[1]$match[2]><![CDATA[$match[10]]]></$match[1]>";
03957 }
03958 return $match[0];
03959 }
03960
03961 function cdata_in_cdata($match)
03962 {
03963 if (isset($match[10]))
03964 {
03965 $match[10] = preg_replace_callback('/<!\[CDATA\[(.*)\]\]>/msiU', array(&$this, 'real_cdata_in_cdata'), $match[10]);
03966 return "<$match[1]$match[2]><![CDATA[$match[10]]]></$match[1]>";
03967 }
03968 return $match[0];
03969 }
03970
03971 function real_cdata_in_cdata($match)
03972 {
03973 return htmlspecialchars($match[1], ENT_NOQUOTES);
03974 }
03975
03976 function do_add_content(&$array, $data)
03977 {
03978 if ($this->is_first)
03979 {
03980 $array['data'] = $data;
03981 $array['attribs'] = $this->attribs;
03982 }
03983 else
03984 {
03985 $array['data'] .= $data;
03986 }
03987 }
03988
03989 function start_handler($parser, $name, $attribs)
03990 {
03991 $this->tag_name = $name;
03992 $this->attribs = $attribs;
03993 $this->is_first = true;
03994
03995 if ($this->inside_item)
03996 {
03997 $this->depth_inside_item++;
03998 }
03999
04000 switch ($this->tag_name)
04001 {
04002 case 'ITEM':
04003 case $this->namespaces['rss2'] . ':ITEM':
04004 case $this->namespaces['rss1'] . ':ITEM':
04005 case 'ENTRY':
04006 case $this->namespaces['atom'] . ':ENTRY':
04007 $this->inside_item = true;
04008 $this->do_add_content($this->data['items'][$this->item_number], '');
04009 break;
04010
04011 case 'CHANNEL':
04012 case $this->namespaces['rss2'] . ':CHANNEL':
04013 case $this->namespaces['rss1'] . ':CHANNEL':
04014 $this->inside_channel = true;
04015 break;
04016
04017 case 'RSS':
04018 case $this->namespaces['rss2'] . ':RSS':
04019 $this->data['feedinfo']['type'] = 'RSS';
04020 $this->do_add_content($this->data['feeddata'], '');
04021 if (!empty($attribs['VERSION']))
04022 {
04023 $this->data['feedinfo']['version'] = trim($attribs['VERSION']);
04024 }
04025 break;
04026
04027 case $this->namespaces['rdf'] . ':RDF':
04028 $this->data['feedinfo']['type'] = 'RSS';
04029 $this->do_add_content($this->data['feeddata'], '');
04030 $this->data['feedinfo']['version'] = 1;
04031 break;
04032
04033 case 'FEED':
04034 case $this->namespaces['atom'] . ':FEED':
04035 $this->data['feedinfo']['type'] = 'Atom';
04036 $this->do_add_content($this->data['feeddata'], '');
04037 if (!empty($attribs['VERSION']))
04038 {
04039 $this->data['feedinfo']['version'] = trim($attribs['VERSION']);
04040 }
04041 break;
04042
04043 case 'IMAGE':
04044 case $this->namespaces['rss2'] . ':IMAGE':
04045 case $this->namespaces['rss1'] . ':IMAGE':
04046 if ($this->inside_channel)
04047 {
04048 $this->inside_image = true;
04049 }
04050 break;
04051 }
04052
04053 if (!empty($this->data['feedinfo']['type']) && $this->data['feedinfo']['type'] == 'Atom' && ($this->tag_name == 'AUTHOR' || $this->tag_name == $this->namespaces['atom'] . ':AUTHOR'))
04054 {
04055 $this->inside_author = true;
04056 }
04057 $this->data_handler($this->xml, '');
04058 }
04059
04060 function data_handler($parser, $data)
04061 {
04062 if ($this->inside_item && $this->depth_inside_item == 1)
04063 {
04064 switch ($this->tag_name)
04065 {
04066 case 'TITLE':
04067 case $this->namespaces['rss1'] . ':TITLE':
04068 case $this->namespaces['rss2'] . ':TITLE':
04069 case $this->namespaces['atom'] . ':TITLE':
04070 $this->do_add_content($this->data['items'][$this->item_number]['title'], $data);
04071 break;
04072
04073 case $this->namespaces['dc'] . ':TITLE':
04074 $this->do_add_content($this->data['items'][$this->item_number]['dc:title'], $data);
04075 break;
04076
04077 case 'CONTENT':
04078 case $this->namespaces['atom'] . ':CONTENT':
04079 $this->do_add_content($this->data['items'][$this->item_number]['content'], $data);
04080 break;
04081
04082 case $this->namespaces['content'] . ':ENCODED':
04083 $this->do_add_content($this->data['items'][$this->item_number]['encoded'], $data);
04084 break;
04085
04086 case 'SUMMARY':
04087 case $this->namespaces['atom'] . ':SUMMARY':
04088 $this->do_add_content($this->data['items'][$this->item_number]['summary'], $data);
04089 break;
04090
04091 case 'LONGDESC':
04092 $this->do_add_content($this->data['items'][$this->item_number]['longdesc'], $data);
04093 break;
04094
04095 case 'DESCRIPTION':
04096 case $this->namespaces['rss1'] . ':DESCRIPTION':
04097 case $this->namespaces['rss2'] . ':DESCRIPTION':
04098 $this->do_add_content($this->data['items'][$this->item_number]['description'], $data);
04099 break;
04100
04101 case $this->namespaces['dc'] . ':DESCRIPTION':
04102 $this->do_add_content($this->data['items'][$this->item_number]['dc:description'], $data);
04103 break;
04104
04105 case 'LINK':
04106 case $this->namespaces['rss1'] . ':LINK':
04107 case $this->namespaces['rss2'] . ':LINK':
04108 case $this->namespaces['atom'] . ':LINK':
04109 $this->do_add_content($this->data['items'][$this->item_number]['link'][$this->item_link_number], $data);
04110 break;
04111
04112 case 'ENCLOSURE':
04113 case $this->namespaces['rss1'] . ':ENCLOSURE':
04114 case $this->namespaces['rss2'] . ':ENCLOSURE':
04115 case $this->namespaces['atom'] . ':ENCLOSURE':
04116 $this->do_add_content($this->data['items'][$this->item_number]['enclosure'][$this->enclosure_number], $data);
04117 break;
04118
04119 case 'GUID':
04120 case $this->namespaces['rss1'] . ':GUID':
04121 case $this->namespaces['rss2'] . ':GUID':
04122 $this->do_add_content($this->data['items'][$this->item_number]['guid'], $data);
04123 break;
04124
04125 case 'ID':
04126 case $this->namespaces['atom'] . ':ID':
04127 $this->do_add_content($this->data['items'][$this->item_number]['id'], $data);
04128 break;
04129
04130 case 'PUBDATE':
04131 case $this->namespaces['rss1'] . ':PUBDATE':
04132 case $this->namespaces['rss2'] . ':PUBDATE':
04133 $this->do_add_content($this->data['items'][$this->item_number]['pubdate'], $data);
04134 break;
04135
04136 case $this->namespaces['dc'] . ':DATE':
04137 $this->do_add_content($this->data['items'][$this->item_number]['dc:date'], $data);
04138 break;
04139
04140 case 'ISSUED':
04141 case $this->namespaces['atom'] . ':ISSUED':
04142 $this->do_add_content($this->data['items'][$this->item_number]['issued'], $data);
04143 break;
04144
04145 case 'PUBLISHED':
04146 case $this->namespaces['atom'] . ':PUBLISHED':
04147 $this->do_add_content($this->data['items'][$this->item_number]['published'], $data);
04148 break;
04149
04150 case 'MODIFIED':
04151 case $this->namespaces['atom'] . ':MODIFIED':
04152 $this->do_add_content($this->data['items'][$this->item_number]['modified'], $data);
04153 break;
04154
04155 case 'UPDATED':
04156 case $this->namespaces['atom'] . ':UPDATED':
04157 $this->do_add_content($this->data['items'][$this->item_number]['updated'], $data);
04158 break;
04159
04160 case 'CATEGORY':
04161 case $this->namespaces['rss1'] . ':CATEGORY':
04162 case $this->namespaces['rss2'] . ':CATEGORY':
04163 case $this->namespaces['atom'] . ':CATEGORY':
04164 $this->do_add_content($this->data['items'][$this->item_number]['category'][$this->category_number], $data);
04165 break;
04166
04167 case $this->namespaces['dc'] . ':SUBJECT':
04168 $this->do_add_content($this->data['items'][$this->item_number]['subject'][$this->category_number], $data);
04169 break;
04170
04171 case $this->namespaces['dc'] . ':CREATOR':
04172 $this->do_add_content($this->data['items'][$this->item_number]['creator'][$this->author_number], $data);
04173 break;
04174
04175 case 'AUTHOR':
04176 case $this->namespaces['rss1'] . ':AUTHOR':
04177 case $this->namespaces['rss2'] . ':AUTHOR':
04178 $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['rss'], $data);
04179 break;
04180 }
04181
04182 if ($this->inside_author)
04183 {
04184 switch ($this->tag_name)
04185 {
04186 case 'NAME':
04187 case $this->namespaces['atom'] . ':NAME':
04188 $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['name'], $data);
04189 break;
04190
04191 case 'URL':
04192 case $this->namespaces['atom'] . ':URL':
04193 $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['url'], $data);
04194 break;
04195
04196 case 'URI':
04197 case $this->namespaces['atom'] . ':URI':
04198 $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['uri'], $data);
04199 break;
04200
04201 case 'HOMEPAGE':
04202 case $this->namespaces['atom'] . ':HOMEPAGE':
04203 $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['homepage'], $data);
04204 break;
04205
04206 case 'EMAIL':
04207 case $this->namespaces['atom'] . ':EMAIL':
04208 $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['email'], $data);
04209 break;
04210 }
04211 }
04212 }
04213
04214 else if (($this->inside_channel && !$this->inside_image) || (isset($this->data['feedinfo']['type']) && $this->data['feedinfo']['type'] == 'Atom'))
04215 {
04216 switch ($this->tag_name)
04217 {
04218 case 'TITLE':
04219 case $this->namespaces['rss1'] . ':TITLE':
04220 case $this->namespaces['rss2'] . ':TITLE':
04221 case $this->namespaces['atom'] . ':TITLE':
04222 $this->do_add_content($this->data['info']['title'], $data);
04223 break;
04224
04225 case 'LINK':
04226 case $this->namespaces['rss1'] . ':LINK':
04227 case $this->namespaces['rss2'] . ':LINK':
04228 case $this->namespaces['atom'] . ':LINK':
04229 $this->do_add_content($this->data['info']['link'][$this->link_number], $data);
04230 break;
04231
04232 case 'DESCRIPTION':
04233 case $this->namespaces['rss1'] . ':DESCRIPTION':
04234 case $this->namespaces['rss2'] . ':DESCRIPTION':
04235 $this->do_add_content($this->data['info']['description'], $data);
04236 break;
04237
04238 case $this->namespaces['dc'] . ':DESCRIPTION':
04239 $this->do_add_content($this->data['info']['dc:description'], $data);
04240 break;
04241
04242 case 'TAGLINE':
04243 case $this->namespaces['atom'] . ':TAGLINE':
04244 $this->do_add_content($this->data['info']['tagline'], $data);
04245 break;
04246
04247 case 'SUBTITLE':
04248 case $this->namespaces['atom'] . ':SUBTITLE':
04249 $this->do_add_content($this->data['info']['subtitle'], $data);
04250 break;
04251
04252 case 'COPYRIGHT':
04253 case $this->namespaces['rss1'] . ':COPYRIGHT':
04254 case $this->namespaces['rss2'] . ':COPYRIGHT':
04255 case $this->namespaces['atom'] . ':COPYRIGHT':
04256 $this->do_add_content($this->data['info']['copyright'], $data);
04257 break;
04258
04259 case 'LANGUAGE':
04260 case $this->namespaces['rss1'] . ':LANGUAGE':
04261 case $this->namespaces['rss2'] . ':LANGUAGE':
04262 $this->do_add_content($this->data['info']['language'], $data);
04263 break;
04264
04265 case 'LOGO':
04266 case $this->namespaces['atom'] . ':LOGO':
04267 $this->do_add_content($this->data['info']['logo'], $data);
04268 break;
04269
04270 }
04271 }
04272
04273 else if ($this->inside_channel && $this->inside_image)
04274 {
04275 switch ($this->tag_name)
04276 {
04277 case 'TITLE':
04278 case $this->namespaces['rss1'] . ':TITLE':
04279 case $this->namespaces['rss2'] . ':TITLE':
04280 $this->do_add_content($this->data['info']['image']['title'], $data);
04281 break;
04282
04283 case 'URL':
04284 case $this->namespaces['rss1'] . ':URL':
04285 case $this->namespaces['rss2'] . ':URL':
04286 $this->do_add_content($this->data['info']['image']['url'], $data);
04287 break;
04288
04289 case 'LINK':
04290 case $this->namespaces['rss1'] . ':LINK':
04291 case $this->namespaces['rss2'] . ':LINK':
04292 $this->do_add_content($this->data['info']['image']['link'], $data);
04293 break;
04294
04295 case 'WIDTH':
04296 case $this->namespaces['rss1'] . ':WIDTH':
04297 case $this->namespaces['rss2'] . ':WIDTH':
04298 $this->do_add_content($this->data['info']['image']['width'], $data);
04299 break;
04300
04301 case 'HEIGHT':
04302 case $this->namespaces['rss1'] . ':HEIGHT':
04303 case $this->namespaces['rss2'] . ':HEIGHT':
04304 $this->do_add_content($this->data['info']['image']['height'], $data);
04305 break;
04306 }
04307 }
04308 $this->is_first = false;
04309 }
04310
04311 function end_handler($parser, $name)
04312 {
04313 $this->tag_name = '';
04314 switch ($name)
04315 {
04316 case 'ITEM':
04317 case $this->namespaces['rss1'] . ':ITEM':
04318 case $this->namespaces['rss2'] . ':ITEM':
04319 case 'ENTRY':
04320 case $this->namespaces['atom'] . ':ENTRY':
04321 $this->inside_item = false;
04322 $this->item_number++;
04323 $this->author_number = 0;
04324 $this->category_number = 0;
04325 $this->enclosure_number = 0;
04326 $this->item_link_number = 0;
04327 break;
04328
04329 case 'CHANNEL':
04330 case $this->namespaces['rss1'] . ':CHANNEL':
04331 case $this->namespaces['rss2'] . ':CHANNEL':
04332 $this->inside_channel = false;
04333 break;
04334
04335 case 'IMAGE':
04336 case $this->namespaces['rss1'] . ':IMAGE':
04337 case $this->namespaces['rss2'] . ':IMAGE':
04338 $this->inside_image = false;
04339 break;
04340
04341 case 'AUTHOR':
04342 case $this->namespaces['rss1'] . ':AUTHOR':
04343 case $this->namespaces['rss2'] . ':AUTHOR':
04344 case $this->namespaces['atom'] . ':AUTHOR':
04345 $this->author_number++;
04346 $this->inside_author = false;
04347 break;
04348
04349 case 'CATEGORY':
04350 case $this->namespaces['rss1'] . ':CATEGORY':
04351 case $this->namespaces['rss2'] . ':CATEGORY':
04352 case $this->namespaces['atom'] . ':CATEGORY':
04353 case $this->namespaces['dc'] . ':SUBJECT':
04354 $this->category_number++;
04355 break;
04356
04357 case 'ENCLOSURE':
04358 case $this->namespaces['rss1'] . ':ENCLOSURE':
04359 case $this->namespaces['rss2'] . ':ENCLOSURE':
04360 $this->enclosure_number++;
04361 break;
04362
04363 case 'LINK':
04364 case $this->namespaces['rss1'] . ':LINK':
04365 case $this->namespaces['rss2'] . ':LINK':
04366 case $this->namespaces['atom'] . ':LINK':
04367 if ($this->inside_item)
04368 {
04369 $this->item_link_number++;
04370 }
04371 else
04372 {
04373 $this->link_number++;
04374 }
04375 break;
04376 }
04377 if ($this->inside_item)
04378 {
04379 $this->depth_inside_item--;
04380 }
04381 }
04382
04383 function start_name_space($parser, $prefix, $uri = null)
04384 {
04385 $prefix = strtoupper($prefix);
04386 $uri = strtoupper($uri);
04387 if ($prefix == 'ATOM' || $uri == 'HTTP://WWW.W3.ORG/2005/ATOM' || $uri == 'HTTP://PURL.ORG/ATOM/NS#')
04388 {
04389 $this->namespaces['atom'] = $uri;
04390 }
04391 else if ($prefix == 'RSS2' || $uri == 'HTTP://BACKEND.USERLAND.COM/RSS2')
04392 {
04393 $this->namespaces['rss2'] = $uri;
04394 }
04395 else if ($prefix == 'RDF' || $uri == 'HTTP://WWW.W3.ORG/1999/02/22-RDF-SYNTAX-NS#')
04396 {
04397 $this->namespaces['rdf'] = $uri;
04398 }
04399 else if ($prefix == 'RSS' || $uri == 'HTTP://PURL.ORG/RSS/1.0/' || $uri == 'HTTP://MY.NETSCAPE.COM/RDF/SIMPLE/0.9/')
04400 {
04401 $this->namespaces['rss1'] = $uri;
04402 }
04403 else if ($prefix == 'DC' || $uri == 'HTTP://PURL.ORG/DC/ELEMENTS/1.1/')
04404 {
04405 $this->namespaces['dc'] = $uri;
04406 }
04407 else if ($prefix == 'XHTML' || $uri == 'HTTP://WWW.W3.ORG/1999/XHTML')
04408 {
04409 $this->namespaces['xhtml'] = $uri;
04410 $this->xhtml_prefix = $prefix;
04411 }
04412 else if ($prefix == 'CONTENT' || $uri == 'HTTP://PURL.ORG/RSS/1.0/MODULES/CONTENT/')
04413 {
04414 $this->namespaces['content'] = $uri;
04415 }
04416 }
04417
04418 function end_name_space($parser, $prefix)
04419 {
04420 if ($key = array_search(strtoupper($prefix), $this->namespaces))
04421 {
04422 if ($key == 'atom')
04423 {
04424 $this->namespaces['atom'] = 'ATOM';
04425 }
04426 else if ($key == 'rss2')
04427 {
04428 $this->namespaces['rss2'] = 'RSS';
04429 }
04430 else if ($key == 'rdf')
04431 {
04432 $this->namespaces['rdf'] = 'RDF';
04433 }
04434 else if ($key == 'rss1')
04435 {
04436 $this->namespaces['rss1'] = 'RSS';
04437 }
04438 else if ($key == 'dc')
04439 {
04440 $this->namespaces['dc'] = 'DC';
04441 }
04442 else if ($key == 'xhtml')
04443 {
04444 $this->namespaces['xhtml'] = 'XHTML';
04445 $this->xhtml_prefix = 'XHTML';
04446 }
04447 else if ($key == 'content')
04448 {
04449 $this->namespaces['content'] = 'CONTENT';
04450 }
04451 }
04452 }
04453 }
04454
04455 class SimplePie_Sanitize
04456 {
04457
04458 var $feedinfo;
04459 var $info;
04460 var $items;
04461 var $feed_xmlbase;
04462 var $item_xmlbase;
04463 var $attribs;
04464 var $cached_entities;
04465 var $cache_convert_entities;
04466
04467
04468 var $remove_div = true;
04469 var $strip_ads = false;
04470 var $replace_headers = false;
04471 var $bypass_image_hotlink = false;
04472 var $bypass_image_hotlink_page = false;
04473 var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
04474 var $encode_instead_of_strip = false;
04475 var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur');
04476 var $input_encoding = 'UTF-8';
04477 var $output_encoding = 'UTF-8';
04478 var $item_class = 'SimplePie_Item';
04479 var $author_class = 'SimplePie_Author';
04480 var $enclosure_class = 'SimplePie_Enclosure';
04481
04482 function remove_div($enable = true)
04483 {
04484 $this->remove_div = (bool) $enable;
04485 }
04486
04487 function strip_ads($enable = false)
04488 {
04489 $this->strip_ads = (bool) $enable;
04490 }
04491
04492 function replace_headers($enable = false)
04493 {
04494 $this->enable_headers = (bool) $enable;
04495 }
04496
04497 function bypass_image_hotlink($get = false)
04498 {
04499 if ($get)
04500 {
04501 $this->bypass_image_hotlink = (string) $get;
04502 }
04503 else
04504 {
04505 $this->bypass_image_hotlink = false;
04506 }
04507 }
04508
04509 function bypass_image_hotlink_page($page = false)
04510 {
04511 if ($page)
04512 {
04513 $this->bypass_image_hotlink_page = (string) $page;
04514 }
04515 else
04516 {
04517 $this->bypass_image_hotlink_page = false;
04518 }
04519 }
04520
04521 function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'))
04522 {
04523 if ($tags)
04524 {
04525 if (is_array($tags))
04526 {
04527 $this->strip_htmltags = $tags;
04528 }
04529 else
04530 {
04531 $this->strip_htmltags = explode(',', $tags);
04532 }
04533 }
04534 else
04535 {
04536 $this->strip_htmltags = false;
04537 }
04538 }
04539
04540 function encode_instead_of_strip($enable = false)
04541 {
04542 $this->encode_instead_of_strip = (bool) $enable;
04543 }
04544
04545 function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur'))
04546 {
04547 if ($attribs)
04548 {
04549 if (is_array($attribs))
04550 {
04551 $this->strip_attributes = $attribs;
04552 }
04553 else
04554 {
04555 $this->strip_attributes = explode(',', $attribs);
04556 }
04557 }
04558 else
04559 {
04560 $this->strip_attributes = false;
04561 }
04562 }
04563
04564 function input_encoding($encoding = 'UTF-8')
04565 {
04566 $this->input_encoding = (string) $encoding;
04567 }
04568
04569 function output_encoding($encoding = 'UTF-8')
04570 {
04571 $this->output_encoding = (string) $encoding;
04572 }
04573
04574 function set_item_class($class = 'SimplePie_Item')
04575 {
04576 if (SimplePie_Misc::is_a_class($class, 'SimplePie_Item'))
04577 {
04578 $this->item_class = $class;
04579 return true;
04580 }
04581 return false;
04582 }
04583
04584 function set_author_class($class = 'SimplePie_Author')
04585 {
04586 if (SimplePie_Misc::is_a_class($class, 'SimplePie_Author'))
04587 {
04588 $this->author_class = $class;
04589 return true;
04590 }
04591 return false;
04592 }
04593
04594 function set_enclosure_class($class = 'SimplePie_Enclosure')
04595 {
04596 if (SimplePie_Misc::is_a_class($class, 'SimplePie_Enclosure'))
04597 {
04598 $this->enclosure_class = $class;
04599 return true;
04600 }
04601 return false;
04602 }
04603
04604 function parse_data_array(&$data, $url)
04605 {
04606
04607 if (!empty($data['feedinfo']['type']))
04608 {
04609 $this->feedinfo = $data['feedinfo'];
04610 }
04611
04612
04613 if (!empty($data['feeddata']['attribs']['XML:BASE']))
04614 {
04615 $this->feed_xmlbase = $data['feeddata']['attribs']['XML:BASE'];
04616 }
04617 else if (!empty($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE']))
04618 {
04619 $this->feed_xmlbase = $data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'];
04620 }
04621
04622 else if (strpos($url, 'http://feeds.feedburner.com/') !== 0)
04623 {
04624 $this->feed_xmlbase = SimplePie_Misc::parse_url($url);
04625 if (empty($this->feed_xmlbase['authority']))
04626 {
04627 $this->feed_xmlbase = preg_replace('/^' . preg_quote(realpath($_SERVER['DOCUMENT_ROOT']), '/') . '/', '', realpath($url));
04628 }
04629 else
04630 {
04631 $this->feed_xmlbase = $url;
04632 }
04633 }
04634
04635
04636
04637 if (!empty($data['info']['link']))
04638 {
04639 foreach ($data['info']['link'] as $link)
04640 {
04641 if (empty($link['attribs']['REL']))
04642 {
04643 $rel = 'alternate';
04644 }
04645 else
04646 {
04647 $rel = strtolower($link['attribs']['REL']);
04648 }
04649 if ($rel == 'enclosure')
04650 {
04651 $href = null;
04652 $type = null;
04653 $length = null;
04654 if (!empty($link['data']))
04655 {
04656 $href = $this->sanitize($link['data'], $link['attribs'], true);
04657 }
04658 else if (!empty($link['attribs']['HREF']))
04659 {
04660 $href = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
04661 }
04662 if (!empty($link['attribs']['TYPE'])) {
04663 $type = $this->sanitize($link['attribs']['TYPE'], $link['attribs']);
04664 }
04665 if (!empty($link['attribs']['LENGTH'])) {
04666 $length = $this->sanitize($link['attribs']['LENGTH'], $link['attribs']);
04667 }
04668 $this->info['link']['enclosure'][] = new $this->enclosure_class($href, $type, $length);
04669 }
04670 else
04671 {
04672 if (!empty($link['data']))
04673 {
04674 $this->info['link'][$rel][] = $this->sanitize($link['data'], $link['attribs'], true);
04675 }
04676 else if (!empty($link['attribs']['HREF']))
04677 {
04678 $this->info['link'][$rel][] = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
04679 }
04680 }
04681 }
04682 }
04683
04684
04685 if (empty($this->feed_xmlbase) && !empty($this->info['link']['alternate'][0]))
04686 {
04687 $this->feed_xmlbase = $this->info['link']['alternate'][0];
04688 }
04689
04690
04691 if (!empty($data['info']['title']['data']))
04692 {
04693 $this->info['title'] = $this->sanitize($data['info']['title']['data'], $data['info']['title']['attribs']);
04694 }
04695
04696
04697 if (!empty($data['info']['description']['data']))
04698 {
04699 $this->info['description'] = $this->sanitize($data['info']['description']['data'], $data['info']['description']['attribs'], false, true);
04700 }
04701 if (!empty($data['info']['dc:description']['data']))
04702 {
04703 $this->info['dc:description'] = $this->sanitize($data['info']['dc:description']['data'], $data['info']['dc:description']['attribs']);
04704 }
04705 if (!empty($data['info']['tagline']['data']))
04706 {
04707 $this->info['tagline'] = $this->sanitize($data['info']['tagline']['data'], $data['info']['tagline']['attribs']);
04708 }
04709 if (!empty($data['info']['subtitle']['data']))
04710 {
04711 $this->info['subtitle'] = $this->sanitize($data['info']['subtitle']['data'], $data['info']['subtitle']['attribs']);
04712 }
04713
04714
04715 if (!empty($data['info']['language']['data']))
04716 {
04717 $this->info['language'] = $this->sanitize($data['info']['language']['data'], $data['info']['language']['attribs']);
04718 }
04719 if (!empty($data['feeddata']['attribs']['XML:LANG']))
04720 {
04721 $this->info['xml:lang'] = $this->sanitize($data['feeddata']['attribs']['XML:LANG'], null);
04722 }
04723 else if (!empty($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:LANG']))
04724 {
04725 $this->info['xml:lang'] = $this->sanitize($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:LANG'], null);
04726 }
04727
04728
04729 if (!empty($data['info']['copyright']['data']))
04730 {
04731 $this->info['copyright'] = $this->sanitize($data['info']['copyright']['data'], $data['info']['copyright']['attribs']);
04732 }
04733
04734
04735 if (!empty($data['info']['image']['title']['data']))
04736 {
04737 $this->info['image']['title'] = $this->sanitize($data['info']['image']['title']['data'], $data['info']['image']['title']['attribs']);
04738 }
04739 if (!empty($data['info']['image']['url']['data']))
04740 {
04741 $this->info['image']['url'] = $this->sanitize($data['info']['image']['url']['data'], $data['info']['image']['url']['attribs'], true);
04742 }
04743 if (!empty($data['info']['logo']['data']))
04744 {
04745 $this->info['image']['logo'] = $this->sanitize($data['info']['logo']['data'], $data['info']['logo']['attribs'], true);
04746 }
04747 if (!empty($data['info']['image']['link']['data']))
04748 {
04749 $this->info['image']['link'] = $this->sanitize($data['info']['image']['link']['data'], $data['info']['image']['link']['attribs'], true);
04750 }
04751 if (!empty($data['info']['image']['width']['data']))
04752 {
04753 $this->info['image']['width'] = $this->sanitize($data['info']['image']['width']['data'], $data['info']['image']['width']['attribs']);
04754 }
04755 if (!empty($data['info']['image']['height']['data']))
04756 {
04757 $this->info['image']['height'] = $this->sanitize($data['info']['image']['height']['data'], $data['info']['image']['height']['attribs']);
04758 }
04759
04760
04761 if (!empty($data['items']))
04762 {
04763 foreach ($data['items'] as $key => $item)
04764 {
04765 $newitem = null;
04766
04767
04768 if (!empty($item['attribs']['XML:BASE']))
04769 {
04770 $this->item_xmlbase = SimplePie_Misc::absolutize_url($item['attribs']['XML:BASE'], $this->feed_xmlbase);
04771 }
04772 else if (!empty($item['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE']))
04773 {
04774 $this->item_xmlbase = SimplePie_Misc::absolutize_url($item['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'], $this->feed_xmlbase);
04775 }
04776 else
04777 {
04778 $this->item_xmlbase = null;
04779 }
04780
04781
04782 if (!empty($item['title']['data'])) {
04783 $newitem['title'] = $this->sanitize($item['title']['data'], $item['title']['attribs']);
04784 }
04785 if (!empty($item['dc:title']['data']))
04786 {
04787 $newitem['dc:title'] = $this->sanitize($item['dc:title']['data'], $item['dc:title']['attribs']);
04788 }
04789
04790
04791 if (!empty($item['content']['data']))
04792 {
04793 $newitem['content'] = $this->sanitize($item['content']['data'], $item['content']['attribs']);
04794 }
04795 if (!empty($item['encoded']['data']))
04796 {
04797 $newitem['encoded'] = $this->sanitize($item['encoded']['data'], $item['encoded']['attribs']);
04798 }
04799 if (!empty($item['summary']['data']))
04800 {
04801 $newitem['summary'] = $this->sanitize($item['summary']['data'], $item['summary']['attribs']);
04802 }
04803 if (!empty($item['description']['data']))
04804 {
04805 $newitem['description'] = $this->sanitize($item['description']['data'], $item['description']['attribs'], false, true);
04806 }
04807 if (!empty($item['dc:description']['data']))
04808 {
04809 $newitem['dc:description'] = $this->sanitize($item['dc:description']['data'], $item['dc:description']['attribs']);
04810 }
04811 if (!empty($item['longdesc']['data']))
04812 {
04813 $newitem['longdesc'] = $this->sanitize($item['longdesc']['data'], $item['longdesc']['attribs']);
04814 }
04815
04816
04817 if (!empty($item['link']))
04818 {
04819 foreach ($item['link'] as $link)
04820 {
04821 if (empty($link['attribs']['REL']))
04822 {
04823 $rel = 'alternate';
04824 }
04825 else
04826 {
04827 $rel = strtolower($link['attribs']['REL']);
04828 }
04829 if ($rel == 'enclosure')
04830 {
04831 $href = null;
04832 $type = null;
04833 $length = null;
04834 if (!empty($link['data']))
04835 {
04836 $href = $this->sanitize($link['data'], $link['attribs'], true);
04837 }
04838 else if (!empty($link['attribs']['HREF']))
04839 {
04840 $href = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
04841 }
04842 if (!empty($link['attribs']['TYPE'])) {
04843 $type = $this->sanitize($link['attribs']['TYPE'], $link['attribs']);
04844 }
04845 if (!empty($link['attribs']['LENGTH'])) {
04846 $length = $this->sanitize($link['attribs']['LENGTH'], $link['attribs']);
04847 }
04848 if (!empty($href))
04849 {
04850 $newitem['link'][$rel][] = new $this->enclosure_class($href, $type, $length);
04851 }
04852 }
04853 else
04854 {
04855 if (!empty($link['data']))
04856 {
04857 $newitem['link'][$rel][] = $this->sanitize($link['data'], $link['attribs'], true);
04858 }
04859 else if (!empty($link['attribs']['HREF']))
04860 {
04861 $newitem['link'][$rel][] = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
04862 }
04863 }
04864 }
04865 }
04866
04867
04868 if (!empty($item['enclosure']))
04869 {
04870 foreach ($item['enclosure'] as $enclosure)
04871 {
04872 if (!empty($enclosure['attribs']['URL']))
04873 {
04874 $type = null;
04875 $length = null;
04876 $href = $this->sanitize($enclosure['attribs']['URL'], $enclosure['attribs'], true);
04877 if (!empty($enclosure['attribs']['TYPE']))
04878 {
04879 $type = $this->sanitize($enclosure['attribs']['TYPE'], $enclosure['attribs']);
04880 }
04881 if (!empty($enclosure['attribs']['LENGTH']))
04882 {
04883 $length = $this->sanitize($enclosure['attribs']['LENGTH'], $enclosure['attribs']);
04884 }
04885 $newitem['enclosures'][] = new $this->enclosure_class($href, $type, $length);
04886 }
04887 }
04888 }
04889
04890
04891 if (!empty($item['guid']['data']))
04892 {
04893 if (!empty($item['guid']['attribs']['ISPERMALINK']) && strtolower($item['guid']['attribs']['ISPERMALINK']) == 'false')
04894 {
04895 $newitem['guid']['permalink'] = false;
04896 }
04897 else
04898 {
04899 $newitem['guid']['permalink'] = true;
04900 }
04901 $newitem['guid']['data'] = $this->sanitize($item['guid']['data'], $item['guid']['attribs']);
04902 }
04903 if (!empty($item['id']['data']))
04904 {
04905 $newitem['id'] = $this->sanitize($item['id']['data'], $item['id']['attribs']);
04906 }
04907
04908
04909 if (!empty($item['pubdate']['data']))
04910 {
04911 $newitem['pubdate'] = $this->parse_date($this->sanitize($item['pubdate']['data'], $item['pubdate']['attribs']));
04912 }
04913 if (!empty($item['dc:date']['data']))
04914 {
04915 $newitem['dc:date'] = $this->parse_date($this->sanitize($item['dc:date']['data'], $item['dc:date']['attribs']));
04916 }
04917 if (!empty($item['issued']['data']))
04918 {
04919 $newitem['issued'] = $this->parse_date($this->sanitize($item['issued']['data'], $item['issued']['attribs']));
04920 }
04921 if (!empty($item['published']['data']))
04922 {
04923 $newitem['published'] = $this->parse_date($this->sanitize($item['published']['data'], $item['published']['attribs']));
04924 }
04925 if (!empty($item['modified']['data']))
04926 {
04927 $newitem['modified'] = $this->parse_date($this->sanitize($item['modified']['data'], $item['modified']['attribs']));
04928 }
04929 if (!empty($item['updated']['data']))
04930 {
04931 $newitem['updated'] = $this->parse_date($this->sanitize($item['updated']['data'], $item['updated']['attribs']));
04932 }
04933
04934
04935 if (!empty($item['category']))
04936 {
04937 foreach ($item['category'] as $category)
04938 {
04939 if (!empty($category['data']))
04940 {
04941 $newitem['category'][] = $this->sanitize($category['data'], $category['attribs']);
04942 }
04943 else if (!empty($category['attribs']['TERM']))
04944 {
04945 $newitem['term'][] = $this->sanitize($category['attribs']['TERM'], $category['attribs']);
04946 }
04947 }
04948 }
04949 if (!empty($item['subject']))
04950 {
04951 foreach ($item['subject'] as $category)
04952 {
04953 if (!empty($category['data']))
04954 {
04955 $newitem['subject'][] = $this->sanitize($category['data'], $category['attribs']);
04956 }
04957 }
04958 }
04959
04960
04961 if (!empty($item['creator']))
04962 {
04963 foreach ($item['creator'] as $creator)
04964 {
04965 if (!empty($creator['data']))
04966 {
04967 $newitem['creator'][] = new $this->author_class($this->sanitize($creator['data'], $creator['attribs']), null, null);
04968 }
04969 }
04970 }
04971 if (!empty($item['author']))
04972 {
04973 foreach ($item['author'] as $author)
04974 {
04975 $name = null;
04976 $link = null;
04977 $email = null;
04978 if (!empty($author['rss']))
04979 {
04980 $sane = $this->sanitize($author['rss']['data'], $author['rss']['attribs']);
04981 if (preg_match('/(.*)@(.*) \((.*)\)/msiU', $sane, $matches)) {
04982 $name = trim($matches[3]);
04983 $email = trim("$matches[1]@$matches[2]");
04984 } else {
04985 $email = $sane;
04986 }
04987 }
04988 else
04989 {
04990 if (!empty($author['name']))
04991 {
04992 $name = $this->sanitize($author['name']['data'], $author['name']['attribs']);
04993 }
04994 if (!empty($author['url']))
04995 {
04996 $link = $this->sanitize($author['url']['data'], $author['url']['attribs'], true);
04997 }
04998 else if (!empty($author['uri']))
04999 {
05000 $link = $this->sanitize($author['uri']['data'], $author['uri']['attribs'], true);
05001 }
05002 else if (!empty($author['homepage']))
05003 {
05004 $link = $this->sanitize($author['homepage']['data'], $author['homepage']['attribs'], true);
05005 }
05006 if (!empty($author['email'])) {
05007 $email = $this->sanitize($author['email']['data'], $author['email']['attribs']);
05008 }
05009 }
05010 $newitem['author'][] = new $this->author_class($name, $link, $email);
05011 }
05012 }
05013 unset($data['items'][$key]);
05014 $this->items[] = new $this->item_class($newitem);
05015 }
05016 }
05017 }
05018
05019 function sanitize($data, $attribs, $is_url = false, $force_decode = false)
05020 {
05021 $this->attribs = $attribs;
05022 if (isset($this->feedinfo['type']) && $this->feedinfo['type'] == 'Atom')
05023 {
05024 if ((!empty($attribs['MODE']) && $attribs['MODE'] == 'base64') || (!empty($attribs['TYPE']) && $attribs['TYPE'] == 'application/octet-stream'))
05025 {
05026 $data = trim($data);
05027 $data = base64_decode($data);
05028 }
05029 else if ((!empty($attribs['MODE']) && $attribs['MODE'] == 'escaped' || !empty($attribs['TYPE']) && ($attribs['TYPE'] == 'html' || $attribs['TYPE'] == 'text/html')))
05030 {
05031 $data = $this->entities_decode($data);
05032 }
05033 if (!empty($attribs['TYPE']) && ($attribs['TYPE'] == 'xhtml' || $attribs['TYPE'] == 'application/xhtml+xml'))
05034 {
05035 if ($this->remove_div)
05036 {
05037 $data = preg_replace('/<div( .*)?>/msiU', '', strrev(preg_replace('/>vid\/</i', '', strrev($data), 1)), 1);
05038 }
05039 else
05040 {
05041 $data = preg_replace('/<div( .*)?>/msiU', '<div>', $data, 1);
05042 }
05043 $data = $this->convert_entities($data);
05044 }
05045 }
05046 else
05047 {
05048 $data = $this->convert_entities($data);
05049 }
05050 if ($force_decode)
05051 {
05052 $data = $this->entities_decode($data);
05053 }
05054 $data = trim($data);
05055 $data = preg_replace('/<\!--([^-]|-[^-])*-->/msiU', '', $data);
05056
05057
05058 if ($this->strip_ads)
05059 {
05060 $data = preg_replace('/<a (.*)href=(.*)click\.phdo\?s=(.*)<\/a>/msiU', '', $data);
05061 $data = preg_replace('/<p(.*)>(.*)<a href="http:\/\/ad.doubleclick.net\/jump\/(.*)<\/p>/msiU', '', $data);
05062 $data = preg_replace('/<p><map (.*)name=(.*)google_ad_map(.*)<\/p>/msiU', '', $data);
05063
05064 }
05065
05066
05067
05068
05069 if ($this->replace_headers)
05070 {
05071 $data = preg_replace('/<h[1-3]((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(.*)))*)\s*>/msiU', '<h4\\1>', $data);
05072 $data = preg_replace('/<\/h[1-3]>/i', '</h4>', $data);
05073 }
05074
05075 if ($is_url)
05076 {
05077 $data = $this->replace_urls($data, true);
05078 }
05079 else
05080 {
05081 $data = preg_replace_callback('/<(\S+)((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(.*)))*)\s*(\/>|>(.*)<\/\S+>)/msiU', array(&$this, 'replace_urls'), $data);
05082 }
05083
05084
05085 if ($this->bypass_image_hotlink)
05086 {
05087 $images = SimplePie_Misc::get_element('img', $data);
05088 foreach ($images as $img)
05089 {
05090 if (!empty($img['attribs']['SRC']['data']))
05091 {
05092 $pre = '';
05093 if ($this->bypass_image_hotlink_page)
05094 {
05095 $pre = $this->bypass_image_hotlink_page;
05096 }
05097 $pre .= "?$this->bypass_image_hotlink=";
05098 $img['attribs']['SRC']['data'] = $pre . rawurlencode(strtr($img['attribs']['SRC']['data'], array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES))));
05099 $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data);
05100 }
05101 }
05102 }
05103
05104
05105
05106
05107 if ($this->strip_htmltags)
05108 {
05109 foreach ($this->strip_htmltags as $tag)
05110 {
05111 $data = preg_replace_callback("/<($tag)((\s*((\w+:)?\w+)(\s*=\s*(\"([^\"]*)\"|'([^']*)'|(.*)))?)*)\s*(\/>|>(.*)<\/($tag)((\s*((\w+:)?\w+)(\s*=\s*(\"([^\"]*)\"|'([^']*)'|(.*)))?)*)\s*>)/msiU", array(&$this, 'do_strip_htmltags'), $data);
05112 }
05113 }
05114
05115 if ($this->strip_attributes)
05116 {
05117 foreach ($this->strip_attributes as $attrib)
05118 {
05119 $data = preg_replace('/ '. trim($attrib) .'=("|")(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\'|'|<|>|\+|{|})*("|")/i', '', $data);
05120 $data = preg_replace('/ '. trim($attrib) .'=(\'|')(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|"|"|<|>|\+|{|})*(\'|')/i', '', $data);
05121 $data = preg_replace('/ '. trim($attrib) .'=(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\+|{|})*/i', '', $data);
05122 }
05123 }
05124
05125
05126 $data = SimplePie_Misc::change_encoding($data, $this->input_encoding, $this->output_encoding);
05127
05128 return $data;
05129 }
05130
05131 function do_strip_htmltags($match)
05132 {
05133 if ($this->encode_instead_of_strip)
05134 {
05135 if (isset($match[12]) && !in_array(strtolower($match[1]), array('script', 'style')))
05136 {
05137 return "<$match[1]$match[2]>$match[12]</$match[1]>";
05138 }
05139 else if (isset($match[12]))
05140 {
05141 return "<$match[1]$match[2]></$match[1]>";
05142 }
05143 else
05144 {
05145 return "<$match[1]$match[2]/>";
05146 }
05147 }
05148 else
05149 {
05150 if (isset($match[12]) && !in_array(strtolower($match[1]), array('script', 'style')))
05151 {
05152 return $match[12];
05153 }
05154 else
05155 {
05156 return '';
05157 }
05158 }
05159 }
05160
05161 function replace_urls($data, $raw_url = false)
05162 {
05163 if (!empty($this->attribs['XML:BASE']))
05164 {
05165 $xmlbase = $attribs['XML:BASE'];
05166 }
05167 else if (!empty($this->attribs['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE']))
05168 {
05169 $xmlbase = $this->attribs['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'];
05170 }
05171 if (!empty($xmlbase))
05172 {
05173 if (!empty($this->item_xmlbase))
05174 {
05175 $xmlbase = SimplePie_Misc::absolutize_url($xmlbase, $this->item_xmlbase);
05176 }
05177 else
05178 {
05179 $xmlbase = SimplePie_Misc::absolutize_url($xmlbase, $this->feed_xmlbase);
05180 }
05181 }
05182 else if (!empty($this->item_xmlbase))
05183 {
05184 $xmlbase = $this->item_xmlbase;
05185 }
05186 else
05187 {
05188 $xmlbase = $this->feed_xmlbase;
05189 }
05190
05191 if ($raw_url)
05192 {
05193 return SimplePie_Misc::absolutize_url($data, $xmlbase);
05194 }
05195 else
05196 {
05197 $attributes = array(
05198 'background',
05199 'href',
05200 'src',
05201 'longdesc',
05202 'usemap',
05203 'codebase',
05204 'data',
05205 'classid',
05206 'cite',
05207 'action',
05208 'profile',
05209 'for'
05210 );
05211 foreach ($attributes as $attribute)
05212 {
05213 if (preg_match("/$attribute='(.*)'/siU", $data[0], $attrib) || preg_match("/$attribute=\"(.*)\"/siU", $data[0], $attrib) || preg_match("/$attribute=(.*)[ |\/|>]/siU", $data[0], $attrib))
05214 {
05215 $new_tag = str_replace($attrib[1], SimplePie_Misc::absolutize_url($attrib[1], $xmlbase), $attrib[0]);
05216 $data[0] = str_replace($attrib[0], $new_tag, $data[0]);
05217 }
05218 }
05219 return $data[0];
05220 }
05221 }
05222
05223 function entities_decode($data)
05224 {
05225 return preg_replace_callback('/&(#)?(x)?([0-9a-z]+);/mi', array(&$this, 'do_entites_decode'), $data);
05226 }
05227
05228 function do_entites_decode($data)
05229 {
05230 if (isset($this->cached_entities[$data[0]]))
05231 {
05232 return $this->cached_entities[$data[0]];
05233 }
05234 else
05235 {
05236 $return = SimplePie_Misc::change_encoding(html_entity_decode($data[0], ENT_QUOTES), 'ISO-8859-1', $this->input_encoding);
05237 if ($return == $data[0])
05238 {
05239 $return = SimplePie_Misc::change_encoding(preg_replace_callback('/&#([x]?[0-9a-f]+);/mi', array(&$this, 'replace_num_entity'), $data[0]), 'UTF-8', $this->input_encoding);
05240 }
05241 $this->cached_entities[$data[0]] = $return;
05242 return $return;
05243 }
05244 }
05245
05246 function convert_entities($data)
05247 {
05248 return preg_replace_callback('/&#(x)?([0-9a-z]+);/mi', array(&$this, 'do_convert_entities'), $data);
05249 }
05250
05251 function do_convert_entities($data)
05252 {
05253 if (isset($this->cache_convert_entities[$data[0]]))
05254 {
05255 return $this->cache_convert_entities[$data[0]];
05256 }
05257 else if (isset($this->cached_entities[$data[0]]))
05258 {
05259 $return = htmlentities($this->cached_entities[$data[0]], ENT_QUOTES, 'UTF-8');
05260 }
05261 else
05262 {
05263 $return = htmlentities(preg_replace_callback('/&#([x]?[0-9a-f]+);/mi', array(&$this, 'replace_num_entity'), $data[0]), ENT_QUOTES, 'UTF-8');
05264 }
05265 $this->cache_convert_entities[$data[0]] = $return;
05266 return $return;
05267 }
05268
05269
05270
05271
05272
05273
05274
05275
05276
05277
05278
05279 function replace_num_entity($ord)
05280 {
05281 $ord = $ord[1];
05282 if (preg_match('/^x([0-9a-f]+)$/i', $ord, $match))
05283 {
05284 $ord = hexdec($match[1]);
05285 }
05286 else
05287 {
05288 $ord = intval($ord);
05289 }
05290
05291 $no_bytes = 0;
05292 $byte = array();
05293 if ($ord < 128)
05294 {
05295 return chr($ord);
05296 }
05297 if ($ord < 2048)
05298 {
05299 $no_bytes = 2;
05300 }
05301 else if ($ord < 65536)
05302 {
05303 $no_bytes = 3;
05304 }
05305 else if ($ord < 1114112)
05306 {
05307 $no_bytes = 4;
05308 }
05309 else
05310 {
05311 return;
05312 }
05313 switch ($no_bytes)
05314 {
05315 case 2:
05316 $prefix = array(31, 192);
05317 break;
05318
05319 case 3:
05320 $prefix = array(15, 224);
05321 break;
05322
05323 case 4:
05324 $prefix = array(7, 240);
05325 break;
05326 }
05327
05328 for ($i = 0; $i < $no_bytes; $i++)
05329 {
05330 $byte[$no_bytes-$i-1] = (($ord & (63 * pow(2,6*$i))) / pow(2,6*$i)) & 63 | 128;
05331 }
05332 $byte[0] = ($byte[0] & $prefix[0]) | $prefix[1];
05333
05334 $ret = '';
05335 for ($i = 0; $i < $no_bytes; $i++)
05336 {
05337 $ret .= chr($byte[$i]);
05338 }
05339 return $ret;
05340 }
05341
05342 function parse_date($date)
05343 {
05344 $military_timezone = array('A' => '-0100', 'B' => '-0200', 'C' => '-0300', 'D' => '-0400', 'E' => '-0500', 'F' => '-0600', 'G' => '-0700', 'H' => '-0800', 'I' => '-0900', 'K' => '-1000', 'L' => '-1100', 'M' => '-1200', 'N' => '+0100', 'O' => '+0200', 'P' => '+0300', 'Q' => '+0400', 'R' => '+0500', 'S' => '+0600', 'T' => '+0700', 'U' => '+0800', 'V' => '+0900', 'W' => '+1000', 'X' => '+1100', 'Y' => '+1200', 'Z' => '-0000');
05345 $north_american_timezone = array('GMT' => '-0000', 'EST' => '-0500', 'EDT' => '-0400', 'CST' => '-0600', 'CDT' => '-0500', 'MST' => '-0700', 'MDT' => '-0600', 'PST' => '-0800', 'PDT' => '-0700');
05346 if (preg_match('/([0-9]{2,4})-?([0-9]{2})-?([0-9]{2})T([0-9]{2}):?([0-9]{2})(:?([0-9]{2}(\.[0-9]*)?))?(UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[a-z]|(\\+|-)[0-9]{4}|(\\+|-)[0-9]{2}:[0-9]{2})?/i', $date, $matches))
05347 {
05348 if (!isset($matches[7]))
05349 {
05350 $matches[7] = '';
05351 }
05352 if (!isset($matches[9]))
05353 {
05354 $matches[9] = '';
05355 }
05356 $matches[7] = str_pad(round($matches[7]), 2, '0', STR_PAD_LEFT);
05357 switch (strlen($matches[9]))
05358 {
05359 case 0:
05360 $timezone = '';
05361 break;
05362
05363 case 1:
05364 $timezone = $military_timezone[strtoupper($matches[9])];
05365 break;
05366
05367 case 2:
05368 $timezone = '-0000';
05369 break;
05370
05371 case 3:
05372 $timezone = $north_american_timezone[strtoupper($matches[9])];
05373 break;
05374
05375 case 5:
05376 $timezone = $matches[9];
05377 break;
05378
05379 case 6:
05380 $timezone = substr_replace($matches[9], '', 3, 1);
05381 break;
05382 }
05383 $date = strtotime("$matches[1]-$matches[2]-$matches[3] $matches[4]:$matches[5]:$matches[7] $timezone");
05384 }
05385 else if (preg_match('/([0-9]{1,2})\s*(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s*([0-9]{2}|[0-9]{4})\s*([0-9]{2}):([0-9]{2})(:([0-9]{2}(\.[0-9]*)?))?\s*(UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[a-z]|(\\+|-)[0-9]{4}|(\\+|-)[0-9]{2}:[0-9]{2})?/i', $date, $matches))
05386 {
05387 $three_month = array('Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12);
05388 $month = $three_month[$matches[2]];
05389 if (strlen($matches[3]) == 2)
05390 {
05391 $year = ($matches[3] < 70) ? "20$matches[3]" : "19$matches[3]";
05392 }
05393 else
05394 {
05395 $year = $matches[3];
05396 }
05397 if (!isset($matches[7]))
05398 {
05399 $matches[7] = '';
05400 }
05401 if (!isset($matches[9]))
05402 {
05403 $matches[9] = '';
05404 }
05405 $second = str_pad(round($matches[7]), 2, '0', STR_PAD_LEFT);
05406 switch (strlen($matches[9]))
05407 {
05408 case 0:
05409 $timezone = '';
05410 break;
05411
05412 case 1:
05413 $timezone = $military_timezone[strtoupper($matches[9])];
05414 break;
05415
05416 case 2:
05417 $timezone = '-0000';
05418 break;
05419
05420 case 3:
05421 $timezone = $north_american_timezone[strtoupper($matches[9])];
05422 break;
05423
05424 case 5:
05425 $timezone = $matches[9];
05426 break;
05427
05428 case 6:
05429 $timezone = substr_replace($matches[9], '', 3, 1);
05430 break;
05431 }
05432 $date = strtotime("$year-$month-$matches[1] $matches[4]:$matches[5]:$second $timezone");
05433 }
05434 else
05435 {
05436 $date = strtotime($date);
05437 }
05438 if ($date !== false && $date !== -1)
05439 {
05440 return $date;
05441 }
05442 else
05443 {
05444 return false;
05445 }
05446 }
05447 }
05448
05449 ?>