/lib/simplepie/simplepie.test.inc
PHP | 4487 lines | 3815 code | 310 blank | 362 comment | 626 complexity | 553f2dddde77ba9f8e0633fb8cc1f096 MD5 | raw file
Possible License(s): LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
- /****************************************************
- SIMPLEPIE
- A PHP-Based RSS and Atom Feed Framework
- Takes the hard work out of managing a complete RSS/Atom solution.
- Version: "Lemon Meringue"
- Updated: 6 August 2006
- Copyright: 2004-2006 Ryan Parman, Geoffrey Sneddon
- http://simplepie.org
- *****************************************************
- LICENSE:
- GNU Lesser General Public License 2.1 (LGPL)
- http://creativecommons.org/licenses/LGPL/2.1/
- *****************************************************
- Please submit all bug reports and feature requests to the SimplePie forums.
- http://simplepie.org/support/
- ****************************************************/
- class SimplePie
- {
- // SimplePie Info
- var $name = 'SimplePie';
- var $version = 'Lemon Meringue';
- var $build = '20060806';
- var $url = 'http://simplepie.org/';
- var $useragent;
- var $linkback;
-
- // Other objects, instances created here so we can set options on them
- var $sanitize;
-
- // Options
- var $rss_url;
- var $xml_dump = false;
- var $enable_cache = true;
- var $max_minutes = 60;
- var $cache_location = './cache';
- var $order_by_date = true;
-
- // Misc. variables
- var $data;
- var $error;
-
- function SimplePie($feed_url = null, $cache_location = null, $cache_max_minutes = null)
- {
- $this->useragent = $this->name . '/' . $this->version . ' (Feed Parser; ' . $this->url . '; Allow like Gecko) Build/' . $this->build;
- $this->linkback = '<a href="' . $this->url . '" title="' . $this->name . ' ' . $this->version . '">' . $this->name . '</a>';
-
- // Other objects, instances created here so we can set options on them
- $this->sanitize = new SimplePie_Sanitize;
-
- // Parse the feed, if we get the data sent directly here
- if (!is_null($feed_url)) {
- $this->feed_url($feed_url);
- }
- if (!is_null($cache_location)) {
- $this->cache_location($cache_location);
- }
- if (!is_null($cache_max_minutes)) {
- $this->cache_max_minutes($cache_max_minutes);
- }
- // If we've passed an xmldump variable in the URL, snap into XMLdump mode
- if (isset($_GET['xmldump'])) {
- $this->enable_xmldump(true);
- }
- if (!is_null($feed_url)) {
- return $this->init();
- }
- }
-
- function feed_url($url)
- {
- $this->rss_url = SimplePie_Misc::fix_protocol($url, 1);
- }
-
- function enable_xmldump($enable = false)
- {
- $this->xml_dump = (bool) $enable;
- }
-
- function enable_caching($enable = true)
- {
- $this->enable_cache = (bool) $enable;
- }
-
- function cache_max_minutes($minutes = 60)
- {
- $this->max_minutes = (float) $minutes;
- }
-
- function cache_location($location = './cache')
- {
- $this->cache_location = (string) $location;
- }
-
- function order_by_date($enable = true)
- {
- $this->order_by_date = (bool) $enable;
- }
-
- function bypass_image_hotlink($get = 'i')
- {
- $this->sanitize->bypass_image_hotlink($get);
- }
-
- function bypass_image_hotlink_page($page = false)
- {
- $this->sanitize->bypass_image_hotlink_page($page);
- }
-
- function replace_headers($enable = false)
- {
- $this->sanitize->replace_headers($enable);
- }
-
- function remove_div($enable = true)
- {
- $this->sanitize->remove_div($enable);
- }
-
- function strip_ads($enable = true)
- {
- $this->sanitize->strip_ads($enable);
- }
-
- function strip_htmltags($tags = array('blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'), $encode = null)
- {
- $this->sanitize->strip_htmltags($tags);
- if (!is_null($encode))
- {
- $this->sanitize->encode_instead_of_strip($tags);
- }
- }
-
- function encode_instead_of_strip($enable = true)
- {
- $this->sanitize->encode_instead_of_strip($enable);
- }
-
- function strip_attributes($attribs = array('class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur'))
- {
- $this->sanitize->strip_attributes($attribs);
- }
-
- function init()
- {
- if ($this->sanitize->bypass_image_hotlink && !empty($_GET[$this->sanitize->bypass_image_hotlink]))
- {
- if (get_magic_quotes_gpc())
- {
- $_GET[$this->sanitize->bypass_image_hotlink] = stripslashes($_GET[$this->sanitize->bypass_image_hotlink]);
- }
- SimplePie_Misc::display_file($_GET[$this->sanitize->bypass_image_hotlink], 10, $this->useragent);
- }
-
- if (isset($_GET['js']))
- {
- $embed = <<<EOT
- function embed_odeo(link) {document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="440" height="80" align="middle"><param name="movie" value="http://odeo.com/flash/audio_player_fullsize.swf" /><param name="allowScriptAccess" value="any" /><param name="quality" value="high"><param name="wmode" value="transparent"><param name="flashvars" value="valid_sample_rate=true&external_url='+link+'" /><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></object>');}
- function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {document.writeln('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" style="cursor:hand; cursor:pointer;" type="'+type+'" codebase="http://www.apple.com/qtactivex/qtplugin.cab" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'"><param name="href" value="'+link+'" /><param name="src" value="'+placeholder+'" /><param name="autoplay" value="false" /><param name="target" value="myself" /><param name="controller" value="false" /><param name="loop" value="'+loop+'" /><param name="scale" value="aspect" /><param name="bgcolor" value="'+bgcolor+'"><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></object>');}
- function embed_flash(bgcolor, width, height, link, loop, type) {document.writeln('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'"><param name="movie" value="'+link+'"><param name="quality" value="high"><param name="loop" value="'+loop+'"><param name="bgcolor" value="'+bgcolor+'"><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></object>');}
- function embed_wmedia(width, height, link) {document.writeln('<object classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" type="application/x-oleobject" width="'+width+'" height="'+height+'" standby="Loading Windows Media Player..."><param name="FileName" value="'+link+'"><param name="autosize" value="true"><param name="ShowControls" value="true"><param name="ShowStatusBar" value="false"><param name="ShowDisplay" value="false"><param name="autostart" value="false"><embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed></object>');}
- EOT;
- ob_start('ob_gzhandler');
- header('Content-type: text/javascript; charset: UTF-8');
- header('Cache-Control: must-revalidate');
- header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 86400) . ' GMT');
- echo $embed;
- exit;
- }
-
- if (!empty($this->rss_url))
- {
- $this->data = array();
- if ($this->enable_cache && preg_match('/^http(s)?:\/\//i', $this->rss_url))
- {
- $cache = new SimplePie_Cache($this->cache_location, sha1($this->rss_url), 'spc');
- }
- else
- {
- $cache = false;
- }
- if ($cache && !$this->xml_dump)
- {
- $this->data = $cache->load();
- if (!empty($this->data))
- {
- if (!empty($this->data['feed_url']))
- {
- $this->rss_url = $this->data['feed_url'];
- return $this->init();
- }
- else if ($cache->mtime() + $this->max_minutes * 60 < time())
- {
- if (!empty($this->data['last-modified']) || !empty($this->data['etag']))
- {
- $headers = array();
- if (!empty($this->data['last-modified']))
- {
- $headers['if-modified-since'] = $this->data['last-modified'];
- }
- if (!empty($this->data['etag']))
- {
- $headers['if-none-match'] = $this->data['etag'];
- }
- $file = new SimplePie_File($this->rss_url, 1, 5, $headers, $this->useragent);
- if ($file->success)
- {
- $headers = $file->headers();
- if ($headers['status']['code'] == 304)
- {
- $cache->touch();
- return true;
- }
- }
- unset($file);
- }
- else
- {
- $cache->unlink();
- }
- }
- else
- {
- return true;
- }
- }
- else
- {
- $cache->unlink();
- }
- }
- $this->data = array();
- if (!isset($file))
- {
- $file = new SimplePie_File($this->rss_url, 10, 5, null, $this->useragent);
- }
- if (!$file->success)
- {
- return false;
- }
-
- if (!SimplePie_Locator::is_feed($file))
- {
- $locate = new SimplePie_Locator($file);
- $feed = $locate->find();
- if ($feed)
- {
- if ($cache && !$cache->save(array('feed_url' => $feed)))
- {
- $this->error = "$cache->name is not writeable";
- SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
- }
- $this->rss_url = $feed;
- return $this->init();
- }
- else
- {
- $this->error = "A feed could not be found at $this->rss_url";
- SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
- return false;
- }
- }
-
- $headers = $file->headers();
- $data = trim($file->body());
- $file->close();
- unset($file);
-
- // First try HTTP headers
- if (!empty($headers['content-type']) && preg_match('/charset=(.*)/i', $headers['content-type'], $charset))
- {
- $encoding = SimplePie_Misc::encoding($charset[1]);
- }
- // Then prolog, if at the very start of the document
- else if (preg_match('/^<\?xml(.*)?>/msiU', $data, $prolog) && preg_match('/encoding\s*=\s*["|\'](.*)["|\']/Ui', $prolog[1], $encoding))
- {
- $encoding = SimplePie_Misc::encoding($encoding[1]);
- }
- // UTF-32 Big Endian BOM
- else if (strpos($data, sprintf('%c%c%c%c', 0x00, 0x00, 0xFE, 0xFF)) === 0)
- {
- $encoding = SimplePie_Misc::encoding('UTF-32be');
- }
- // UTF-32 Little Endian BOM
- else if (strpos($data, sprintf('%c%c%c%c', 0xFF, 0xFE, 0x00, 0x00)) === 0)
- {
- $encoding = SimplePie_Misc::encoding('UTF-32');
- }
- // UTF-16 Big Endian BOM
- else if (strpos($data, sprintf('%c%c', 0xFE, 0xFF)) === 0)
- {
- $encoding = SimplePie_Misc::encoding('UTF-16be');
- }
- // UTF-16 Little Endian BOM
- else if (strpos($data, sprintf('%c%c', 0xFF, 0xFE)) === 0)
- {
- $encoding = SimplePie_Misc::encoding('UTF-16le');
- }
- // UTF-8 BOM
- else if (strpos($data, sprintf('%c%c%c', 0xEF, 0xBB, 0xBF)) === 0)
- {
- $encoding = SimplePie_Misc::encoding('UTF-8');
- }
- // Fallback to the default
- else
- {
- $encoding = SimplePie_Misc::encoding(null);
- }
-
- if (function_exists('iconv') && $encoding['use_iconv'] && iconv($encoding['encoding'], 'UTF-8//TRANSLIT', $data))
- {
- $data = iconv($encoding['encoding'], 'UTF-8//TRANSLIT', $data);
- $encoding['encoding'] = 'UTF-8';
- }
- else if (function_exists('iconv') && $encoding['use_iconv'] && iconv($encoding['encoding'], 'UTF-8', $data))
- {
- $data = iconv($encoding['encoding'], 'UTF-8', $data);
- $encoding['encoding'] = 'UTF-8';
- }
- else if (function_exists('mb_convert_encoding') && $encoding['use_mbstring'])
- {
- $data = mb_convert_encoding($data, 'UTF-8', $encoding['encoding']);
- $encoding['encoding'] = 'UTF-8';
- }
- else if ($encoding['encoding'] == 'ISO-8859-1')
- {
- $data = utf8_encode($data);
- $encoding['encoding'] = 'UTF-8';
- }
- else
- {
- $encoding['encoding'] = 'UTF-8';
- }
-
- $data = new SimplePie_Parser($data, 'UTF-8', $this->xml_dump);
- if ($this->xml_dump)
- {
- header('Content-type: text/xml; charset=UTF-8');
- echo $data->data;
- exit;
- }
- else if (!$data->error_code)
- {
- $this->sanitize->parse_data_array($data->data);
- unset($data);
- $this->data['feedinfo'] = $this->sanitize->feedinfo;
- $this->data['info'] = $this->sanitize->info;
- $this->data['items'] = $this->sanitize->items;
- unset($this->sanitize);
- $this->data['feedinfo']['encoding'] = 'UTF-8';
- if (!empty($headers['last-modified']))
- {
- $this->data['last-modified'] = $headers['last-modified'];
- }
- if (!empty($headers['etag']))
- {
- $this->data['etag'] = $headers['etag'];
- }
- if ($this->order_by_date && !empty($this->data['items']))
- {
- $do_sort = true;
- foreach ($this->data['items'] as $item)
- {
- if (!isset($item->date))
- {
- $do_sort = false;
- break;
- }
- }
- if ($do_sort)
- {
- usort($this->data['items'], create_function('$a,$b', 'if ($a->date == $b->date) return 0; return ($a->date < $b->date) ? 1 : -1;'));
- }
- }
- if ($cache && !$cache->save($this->data))
- {
- $this->error = "$cache->name is not writeable";
- SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
- }
- return true;
- }
- else
- {
- $this->error = "XML error: $data->error_string at line $data->current_line, column $data->current_column";
- SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
- return false;
- }
- }
- }
-
- function get_encoding()
- {
- if (!empty($this->data['feedinfo']['encoding']))
- {
- return $this->data['feedinfo']['encoding'];
- }
- else
- {
- return false;
- }
- }
-
- function handle_content_type($mime='text/html')
- {
- if (!headers_sent())
- {
- $header = "Content-type: $mime;";
- if ($this->get_encoding())
- {
- $header .= ' charset=' . $this->get_encoding();
- }
- else
- {
- $header .= ' charset=UTF-8';
- }
- header($header);
- }
- }
-
- function get_type()
- {
- if (!empty($this->data['feedinfo']['type']))
- {
- return $this->data['feedinfo']['type'];
- }
- else
- {
- return false;
- }
- }
-
- function get_version()
- {
- if (!empty($this->data['feedinfo']['version']))
- {
- return $this->data['feedinfo']['version'];
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_url()
- {
- if (!empty($this->rss_url))
- {
- return $this->rss_url;
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_feed()
- {
- if (!empty($this->rss_url))
- {
- return SimplePie_Misc::fix_protocol($this->rss_url, 2);
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_outlook()
- {
- if (!empty($this->rss_url))
- {
- return 'outlook' . SimplePie_Misc::fix_protocol($this->rss_url, 2);
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_podcast()
- {
- if (!empty($this->rss_url))
- {
- return SimplePie_Misc::fix_protocol($this->rss_url, 3);
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_aol()
- {
- if ($this->subscribe_url())
- {
- return 'http://feeds.my.aol.com/add.jsp?url=' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_bloglines()
- {
- if ($this->subscribe_url())
- {
- return 'http://www.bloglines.com/sub/' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_eskobo()
- {
- if ($this->subscribe_url())
- {
- return 'http://www.eskobo.com/?AddToMyPage=' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_feedfeeds()
- {
- if ($this->subscribe_url())
- {
- return 'http://www.feedfeeds.com/add?feed=' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_feedlounge()
- {
- if ($this->subscribe_url())
- {
- return 'http://my.feedlounge.com/external/subscribe?url=' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_feedster()
- {
- if ($this->subscribe_url())
- {
- return 'http://www.feedster.com/myfeedster.php?action=addrss&confirm=no&rssurl=' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_google()
- {
- if ($this->subscribe_url())
- {
- return 'http://fusion.google.com/add?feedurl=' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_gritwire()
- {
- if ($this->subscribe_url())
- {
- return 'http://my.gritwire.com/feeds/addExternalFeed.aspx?FeedUrl=' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_msn()
- {
- if ($this->subscribe_url())
- {
- $url = 'http://my.msn.com/addtomymsn.armx?id=rss&ut=' . rawurlencode($this->subscribe_url());
- if ($this->get_feed_link())
- {
- $url .= '&ru=' . rawurlencode($this->get_feed_link());
- }
- return $url;
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_netvibes()
- {
- if ($this->subscribe_url())
- {
- return 'http://www.netvibes.com/subscribe.php?url=' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_newsburst()
- {
- if ($this->subscribe_url())
- {
- return 'http://www.newsburst.com/Source/?add=' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_newsgator()
- {
- if ($this->subscribe_url())
- {
- return 'http://www.newsgator.com/ngs/subscriber/subext.aspx?url=' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_odeo()
- {
- if ($this->subscribe_url())
- {
- return 'http://www.odeo.com/listen/subscribe?feed=' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_pluck()
- {
- if ($this->subscribe_url())
- {
- return 'http://client.pluck.com/pluckit/prompt.aspx?GCID=C12286x053&a=' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_podnova()
- {
- if ($this->subscribe_url())
- {
- return 'http://www.podnova.com/index_your_podcasts.srf?action=add&url=' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_rojo()
- {
- if ($this->subscribe_url())
- {
- return 'http://www.rojo.com/add-subscription?resource=' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function subscribe_yahoo()
- {
- if ($this->subscribe_url())
- {
- return 'http://add.my.yahoo.com/rss?url=' . rawurlencode($this->subscribe_url());
- }
- else
- {
- return false;
- }
- }
-
- function get_feed_title()
- {
- if (!empty($this->data['info']['title']))
- {
- return $this->data['info']['title'];
- }
- else
- {
- return false;
- }
- }
-
- function get_feed_link()
- {
- if (!empty($this->data['info']['link']['alternate'][0]))
- {
- return $this->data['info']['link']['alternate'][0];
- }
- else
- {
- return false;
- }
- }
-
- function get_feed_links()
- {
- if (!empty($this->data['info']['link']))
- {
- return $this->data['info']['link'];
- }
- else
- {
- return false;
- }
- }
-
- function get_feed_description()
- {
- if (!empty($this->data['info']['description']))
- {
- return $this->data['info']['description'];
- }
- else if (!empty($this->data['info']['dc:description']))
- {
- return $this->data['info']['dc:description'];
- }
- else if (!empty($this->data['info']['tagline']))
- {
- return $this->data['info']['tagline'];
- }
- else if (!empty($this->data['info']['subtitle']))
- {
- return $this->data['info']['subtitle'];
- }
- else
- {
- return false;
- }
- }
-
- function get_feed_copyright()
- {
- if (!empty($this->data['info']['copyright']))
- {
- return $this->data['info']['copyright'];
- }
- else
- {
- return false;
- }
- }
-
- function get_feed_language()
- {
- if (!empty($this->data['info']['language']))
- {
- return $this->data['info']['language'];
- }
- else if (!empty($this->data['info']['xml:lang']))
- {
- return $this->data['info']['xml:lang'];
- }
- else
- {
- return false;
- }
- }
-
- function get_image_exist()
- {
- if (!empty($this->data['info']['image']['url']) || !empty($this->data['info']['image']['logo']))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- function get_image_title()
- {
- if (!empty($this->data['info']['image']['title']))
- {
- return $this->data['info']['image']['title'];
- }
- else
- {
- return false;
- }
- }
-
- function get_image_url()
- {
- if (!empty($this->data['info']['image']['url']))
- {
- return $this->data['info']['image']['url'];
- }
- else if (!empty($this->data['info']['image']['logo']))
- {
- return $this->data['info']['image']['logo'];
- }
- else
- {
- return false;
- }
- }
-
- function get_image_link()
- {
- if (!empty($this->data['info']['image']['link']))
- {
- return $this->data['info']['image']['link'];
- }
- else
- {
- return false;
- }
- }
-
- function get_image_width()
- {
- if (!empty($this->data['info']['image']['width']))
- {
- return $this->data['info']['image']['width'];
- }
- else
- {
- return false;
- }
- }
-
- function get_image_height()
- {
- if (!empty($this->data['info']['image']['height']))
- {
- return $this->data['info']['image']['height'];
- }
- else
- {
- return false;
- }
- }
-
- function get_item_quantity($max = 0)
- {
- if (!empty($this->data['items']))
- {
- $qty = sizeof($this->data['items']);
- }
- else
- {
- $qty = 0;
- }
- if ($max == 0)
- {
- return $qty;
- }
- else
- {
- return ($qty > $max) ? $max : $qty;
- }
- }
-
- function get_item($key = 0)
- {
- if (!empty($this->data['items'][$key]))
- {
- return $this->data['items'][$key];
- }
- else
- {
- return false;
- }
- }
-
- function get_items($start = 0, $end = 0)
- {
- if ($end == 0)
- {
- return array_slice($this->data['items'], $start);
- }
- else
- {
- return array_slice($this->data['items'], $start, $end);
- }
- }
- }
- class SimplePie_Item
- {
- var $data;
-
- function SimplePie_Item($data)
- {
- $this->data =& $data;
- }
-
- function get_id()
- {
- if (!empty($this->data['guid']['data']))
- {
- return $this->data['guid']['data'];
- }
- else if (!empty($this->data['id']))
- {
- return $this->data['id'];
- }
- else
- {
- return false;
- }
- }
-
- function get_title()
- {
- if (!empty($this->data['title']))
- {
- return $this->data['title'];
- }
- else if (!empty($this->data['dc:title']))
- {
- return $this->data['dc:title'];
- }
- else
- {
- return false;
- }
- }
-
- function get_description()
- {
- if (!empty($this->data['content']))
- {
- return $this->data['content'];
- }
- else if (!empty($this->data['encoded']))
- {
- return $this->data['encoded'];
- }
- else if (!empty($this->data['summary']))
- {
- return $this->data['summary'];
- }
- else if (!empty($this->data['description']))
- {
- return $this->data['description'];
- }
- else if (!empty($this->data['dc:description']))
- {
- return $this->data['dc:description'];
- }
- else if (!empty($this->data['longdesc']))
- {
- return $this->data['longdesc'];
- }
- else
- {
- return false;
- }
- }
-
- function get_category($key = 0)
- {
- $categories = $this->get_categories();
- if (!empty($categories[$key]))
- {
- return $categories[$key];
- }
- else
- {
- return false;
- }
- }
-
- function get_categories()
- {
- $categories = array();
- if (!empty($this->data['category']))
- {
- $categories = array_merge($categories, $this->data['category']);
- }
- if (!empty($this->data['subject']))
- {
- $categories = array_merge($categories, $this->data['subject']);
- }
- if (!empty($categories))
- {
- return array_unique($categories);
- }
- else
- {
- return false;
- }
- }
-
- function get_author($key = 0)
- {
- $authors = $this->get_authors();
- if (!empty($authors[$key]))
- {
- return $authors[$key];
- }
- else
- {
- return false;
- }
- }
-
- function get_authors()
- {
- $authors = array();
- if (!empty($this->data['author']))
- {
- $authors = array_merge($authors, $this->data['author']);
- }
- if (!empty($this->data['creator']))
- {
- $authors = array_merge($authors, $this->data['creator']);
- }
- if (!empty($authors))
- {
- return array_unique($authors);
- }
- else
- {
- return false;
- }
- }
-
- function get_date($date_format = 'j F Y, g:i a')
- {
- if (!empty($this->data['pubdate']))
- {
- return date($date_format, $this->data['pubdate']);
- }
- else if (!empty($this->data['dc:date']))
- {
- return date($date_format, $this->data['dc:date']);
- }
- else if (!empty($this->data['issued']))
- {
- return date($date_format, $this->data['issued']);
- }
- else if (!empty($this->data['published']))
- {
- return date($date_format, $this->data['published']);
- }
- else if (!empty($this->data['modified']))
- {
- return date($date_format, $this->data['modified']);
- }
- else if (!empty($this->data['updated']))
- {
- return date($date_format, $this->data['updated']);
- }
- else
- {
- return false;
- }
- }
-
- function get_permalink()
- {
- $link = $this->get_link(0);
- $enclosure = $this->get_enclosure(0);
- if (!empty($link))
- {
- return $link;
- }
- else if (!empty($enclosure))
- {
- return $enclosure->get_link();
- }
- else
- {
- return false;
- }
- }
-
- function get_link($key = 0, $rel = 'alternate')
- {
- $links = $this->get_links($rel);
- if (!empty($links[$key]))
- {
- return $links[$key];
- }
- else
- {
- return false;
- }
- }
-
- function get_links($rel = 'alternate')
- {
- if (!empty($this->data['link'][$rel]))
- {
- return $this->data['link'][$rel];
- }
- else
- {
- return false;
- }
- }
-
- function get_enclosure($key = 0)
- {
- $enclosures = $this->get_enclosures();
- if (!empty($enclosures[$key]))
- {
- return $enclosures[$key];
- }
- else
- {
- return false;
- }
- }
-
- function get_enclosures()
- {
- $enclosures = array();
- $links = $this->get_links('enclosure');
- if (!empty($this->data['enclosures']))
- {
- $enclosures = array_merge($enclosures, $this->data['enclosures']);
- }
- if (!empty($links))
- {
- $enclosures = array_merge($enclosures, $links);
- }
- if (!empty($enclosures))
- {
- return array_unique($enclosures);
- }
- else
- {
- return false;
- }
- }
-
- function add_to_blinklist()
- {
- if ($this->get_permalink())
- {
- $url = 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&Url=' . rawurlencode($this->get_permalink());
- if ($this->get_title())
- {
- $url .= '&Title=' . rawurlencode($this->get_title());
- }
- return $url;
- }
- else
- {
- return false;
- }
- }
-
- function add_to_blogmarks()
- {
- if ($this->get_permalink())
- {
- $url = 'http://blogmarks.net/my/new.php?mini=1&simple=1&url=' . rawurlencode($this->get_permalink());
- if ($this->get_title())
- {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- }
- else
- {
- return false;
- }
- }
-
- function add_to_delicious()
- {
- if ($this->get_permalink())
- {
- $url = 'http://del.icio.us/post/?v=3&url=' . rawurlencode($this->get_permalink());
- if ($this->get_title())
- {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- }
- else
- {
- return false;
- }
- }
-
- function add_to_digg()
- {
- if ($this->get_permalink())
- {
- return 'http://digg.com/submit?phase=2&URL=' . rawurlencode($this->get_permalink());
- }
- else
- {
- return false;
- }
- }
-
- function add_to_furl()
- {
- if ($this->get_permalink())
- {
- $url = 'http://www.furl.net/storeIt.jsp?u=' . rawurlencode($this->get_permalink());
- if ($this->get_title())
- {
- $url .= '&t=' . rawurlencode($this->get_title());
- }
- return $url;
- }
- else
- {
- return false;
- }
- }
-
- function add_to_magnolia()
- {
- if ($this->get_permalink())
- {
- $url = 'http://ma.gnolia.com/bookmarklet/add?url=' . rawurlencode($this->get_permalink());
- if ($this->get_title())
- {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- }
- else
- {
- return false;
- }
- }
-
- function add_to_myweb20()
- {
- if ($this->get_permalink())
- {
- $url = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=' . rawurlencode($this->get_permalink());
- if ($this->get_title())
- {
- $url .= '&t=' . rawurlencode($this->get_title());
- }
- return $url;
- }
- else
- {
- return false;
- }
- }
-
- function add_to_newsvine()
- {
- if ($this->get_permalink())
- {
- $url = 'http://www.newsvine.com/_wine/save?u=' . rawurlencode($this->get_permalink());
- if ($this->get_title())
- {
- $url .= '&h=' . rawurlencode($this->get_title());
- }
- return $url;
- }
- else
- {
- return false;
- }
- }
-
- function add_to_reddit()
- {
- if ($this->get_permalink())
- {
- $url = 'http://reddit.com/submit?url=' . rawurlencode($this->get_permalink());
- if ($this->get_title())
- {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- }
- else
- {
- return false;
- }
- }
-
- function add_to_segnalo()
- {
- if ($this->get_permalink())
- {
- $url = 'http://segnalo.com/post.html.php?url=' . rawurlencode($this->get_permalink());
- if ($this->get_title())
- {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- }
- else
- {
- return false;
- }
- }
-
- function add_to_simpy()
- {
- if ($this->get_permalink())
- {
- $url = 'http://www.simpy.com/simpy/LinkAdd.do?href=' . rawurlencode($this->get_permalink());
- if ($this->get_title())
- {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- }
- else
- {
- return false;
- }
- }
-
- function add_to_smarking()
- {
- if ($this->get_permalink())
- {
- return 'http://smarking.com/editbookmark/?url=' . rawurlencode($this->get_permalink());
- }
- else
- {
- return false;
- }
- }
-
- function add_to_spurl()
- {
- if ($this->get_permalink())
- {
- $url = 'http://www.spurl.net/spurl.php?v=3&url=' . rawurlencode($this->get_permalink());
- if ($this->get_title())
- {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- }
- else
- {
- return false;
- }
- }
-
- function add_to_wists()
- {
- if ($this->get_permalink())
- {
- $url = 'http://wists.com/r.php?c=&r=' . rawurlencode($this->get_permalink());
- if ($this->get_title())
- {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- }
- else
- {
- return false;
- }
- }
-
- function search_technorati()
- {
- if ($this->get_permalink())
- {
- return 'http://www.technorati.com/search/' . rawurlencode($this->get_permalink());
- }
- else
- {
- return false;
- }
- }
- }
- class SimplePie_Author
- {
- var $name;
- var $link;
- var $email;
-
- // Constructor, used to input the data
- function SimplePie_Author($name, $link, $email) {
- $this->name = $name;
- $this->link = $link;
- $this->email = $email;
- }
-
- function get_name() {
- return (empty($this->name)) ? false : $this->name;
- }
-
- function get_link() {
- return (empty($this->link)) ? false : $this->link;
- }
-
- function get_email() {
- return (empty($this->email)) ? false : $this->email;
- }
- }
- class SimplePie_Enclosure
- {
- var $link;
- var $type;
- var $length;
- // Constructor, used to input the data
- function SimplePie_Enclosure($link, $type, $length) {
- $this->link = $link;
- $this->type = $type;
- $this->length = $length;
- }
- function get_link() {
- return (empty($this->link)) ? false : $this->link;
- }
- function get_extension() {
- if (!empty($this->link)) {
- return pathinfo($this->link, PATHINFO_EXTENSION);
- } else {
- return false;
- }
- }
- function get_type() {
- return (empty($this->type)) ? false : $this->type;
- }
- function get_length() {
- return (empty($this->length)) ? false : $this->length;
- }
- function get_size() {
- return (empty($this->length)) ? false : round(($this->length/1048576), 2);
- }
- function embed($options) {
- // Set up defaults
- $audio='';
- $video='';
- $alt='';
- $altclass='';
- $loop='false';
- $width='auto';
- $height='auto';
- $bgcolor='#ffffff';
- $embed='';
- // Process options and reassign values as necessary
- $options = explode(',', $options);
- foreach($options as $option) {
- $opt = explode(':', trim($option));
- if ($opt[0] == 'audio') $audio=$opt[1];
- else if ($opt[0] == 'video') $video=$opt[1];
- else if ($opt[0] == 'alt') $alt=$opt[1];
- else if ($opt[0] == 'altclass') $altclass=$opt[1];
- else if ($opt[0] == 'loop') $loop=$opt[1];
- else if ($opt[0] == 'width') $width=$opt[1];
- else if ($opt[0] == 'height') $height=$opt[1];
- else if ($opt[0] == 'bgcolor') $bgcolor=$opt[1];
- }
- // Process values for 'auto'
- if ($width == 'auto') {
- if (stristr($this->type, 'audio/')) $width='100%';
- else if (stristr($this->type, 'video/')) $width='320';
- else $width='100%';
- }
- if ($height == 'auto') {
- if (stristr($this->type, 'audio/')) $height=0;
- else if (stristr($this->type, 'video/')) $height=240;
- else $height=256;
- }
- // Set proper placeholder value
- if (stristr($this->type, 'audio/')) $placeholder=$audio;
- else if (stristr($this->type, 'video/')) $placeholder=$video;
- // Make sure the JS library is included
- // (I know it'll be included multiple times, but I can't think of a better way to do this automatically)
- $embed.='<script type="text/javascript" src="?js"></script>';
- // Odeo Feed MP3's
- if (substr(strtolower($this->link), 0, 15) == 'http://odeo.com') {
- $embed.='<script type="text/javascript">embed_odeo("'.$this->link.'");</script>';
- }
- // QuickTime 7 file types. Need to test with QuickTime 6.
- else if ($this->type == 'audio/3gpp' || $this->type == 'audio/3gpp2' || $this->type == 'audio/aac' || $this->type == 'audio/x-aac' || $this->type == 'audio/aiff' || $this->type == 'audio/x-aiff' || $this->type == 'audio/mid' || $this->type == 'audio/midi' || $this->type == 'audio/x-midi' || $this->type == 'audio/mpeg' || $this->type == 'audio/x-mpeg' || $this->type == 'audio/mp3' || $this->type == 'x-audio/mp3' || $this->type == 'audio/mp4' || $this->type == 'audio/m4a' || $this->type == 'audio/x-m4a' || $this->type == 'audio/wav' || $this->type == 'audio/x-wav' || $this->type == 'video/3gpp' || $this->type == 'video/3gpp2' || $this->type == 'video/m4v' || $this->type == 'video/x-m4v' || $this->type == 'video/mp4' || $this->type == 'video/mpeg' || $this->type == 'video/x-mpeg' || $this->type == 'video/quicktime' || $this->type == 'video/sd-video') {
- $height+=16;
- $embed.='<script type="text/javascript">embed_quicktime("'.$this->type.'", "'.$bgcolor.'", "'.$width.'", "'.$height.'", "'.$this->link.'", "'.$placeholder.'", "'.$loop.'");</script>';
- }
- // Flash
- else if ($this->type == 'application/x-shockwave-flash' || $this->type == 'application/futuresplash') {
- $embed.='<script type="text/javascript">embed_flash("'.$bgcolor.'", "'.$width.'", "'.$height.'", "'.$this->link.'", "'.$loop.'", "'.$this->type.'");</script>';
- }
- // Windows Media
- else if ($this->type == 'application/asx' || $this->type == 'application/x-mplayer2' || $this->type == 'audio/x-ms-wma' || $this->type == 'audio/x-ms-wax' || $this->type == 'video/x-ms-asf-plugin' || $this->type == 'video/x-ms-asf' || $this->type == 'video/x-ms-wm' || $this->type == 'video/x-ms-wmv' || $this->type == 'video/x-ms-wvx') {
- $height+=45;
- $embed.='<script type="text/javascript">embed_wmedia("'.$width.'", "'.$height.'", "'.$this->link.'");</script>';
- }
- // Everything else
- else $embed.='<a href="' . $this->link . '" class="' . $altclass . '">' . $alt . '</a>';
- return $embed;
- }
- }
- class SimplePie_File
- {
- var $url;
- var $useragent;
- var $success = true;
- var $headers = array();
- var $body;
- var $fp;
- var $redirects = 0;
-
- function SimplePie_File($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null)
- {
- if (class_exists('idna_convert'))
- {
- $idn = new idna_convert;
- $url = $idn->encode($url);
- }
- $this->url = $url;
- $this->useragent = $useragent;
- if (preg_match('/^http(s)?:\/\//i', $url))
- {
- if (empty($useragent))
- {
- $useragent = ini_get('user_agent');
- $this->useragent = $useragent;
- }
- if (!is_array($headers))
- {
- $headers = array();
- }
- if (extension_loaded('curl'))
- {
- $fp = curl_init();
- $headers2 = array();
- foreach ($headers as $key => $value)
- {
- $headers2[] = "$key: $value";
- }
- if (version_compare(SimplePie_Misc::get_curl_version(), '7.10', '>='))
- {
- curl_setopt($fp, CURLOPT_ENCODING, '');
- }
- else if (extension_loaded('zlib') && function_exists('gzinflate'))
- {
- $headers2[] = 'Accept-Encoding: gzip,deflate';
- }
- curl_setopt($fp, CURLOPT_URL, $url);
- curl_setopt($fp, CURLOPT_HEADER, 1);
- curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
- curl_setopt($fp, CURLOPT_REFERER, $url);
- curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
- curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
- curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
- $this->headers = trim(curl_exec($fp));
- if (curl_errno($fp))
- {
- $this->success = false;
- return false;
- }
- else
- {
- $info = curl_getinfo($fp);
- $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 2);
- $this->body = array_pop($this->headers);
- $this->headers = array_pop($this->headers);
- $this->headers = $this->parse_headers($this->headers);
- }
- }
- else
- {
- $url_parts = parse_url($url);
- if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) == 'https')
- {
- $url_parts['host'] = "ssl://$url_parts[host]";
- $url_parts['port'] = 443;
- }
- if (!isset($url_parts['port']))
- {
- $url_parts['port'] = 80;
- }
- $this->fp = fsockopen($url_parts['host'], $url_parts['port'], $errno, $errstr, $timeout);
- if (!$this->fp)
- {
- $this->success = false;
- return false;
- }
- else
- {
- stream_set_timeout($this->fp, $timeout);
- $get = (isset($url_parts['query'])) ? "$url_parts[path]?$url_parts[query]" : $url_parts['path'];
- $out = "GET $get HTTP/1.0\r\n";
- $out .= "Host: $url_parts[host]\r\n";
- $out .= "User-Agent: $useragent\r\n";
- if (extension_loaded('zlib') && function_exists('gzinflate'))
- {
- $out .= "Accept-Encoding: gzip,deflate\r\n";
- }
- if (!empty($url_parts['user']) && !empty($url_parts['pass']))
- {
- $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
- }
- foreach ($headers as $key => $value)
- {
- $out .= "$key: $value\r\n";
- }
- $out .= "Connection: Close\r\n\r\n";
- fwrite($this->fp, $out);
-
- $info = stream_get_meta_data($this->fp);
- $data = '';
- while (strpos($data, "\r\n\r\n") === false && $info['timed_out'] === false)
- {
- $data .= fgets($this->fp, 128);
- $info = stream_get_meta_data($this->fp);
- }
- if ($info['timed_out'] === false)
- {
- $this->headers = $this->parse_headers($data);
- 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)
- {
- $this->redirects++;
- return $this->__construct($this->headers['location'], $timeout, $redirects, $headers, $useragent);
- }
- }
- else
- {
- $this->close();
- $this->success = false;
- return false;
- }
- }
- }
- return $this->headers['status']['code'];
- }
- else
- {
- if ($this->fp = fopen($url, 'r'))
- {
- return true;
- }
- else
- {
- $this->success = false;
- return false;
- }
- }
- }
-
- function headers()
- {
- return $this->headers;
- }
-
- function body()
- {
- if (is_null($this->body))
- {
- if ($this->fp)
- {
- $this->body = '';
- while (!feof($this->fp))
- {
- $this->body .= fread($this->fp, 1024);
- }
- $this->body = trim($this->body);
- $this->close();
- }
- else
- {
- return false;
- }
- }
- return $this->body;
- }
-
- function close()
- {
- if (!is_null($this->fp))
- {
- if (fclose($this->fp))
- {
- $this->fp = null;
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
-
- function parse_headers($headers)
- {
- $headers = explode("\r\n", trim($headers));
- $status = array_shift($headers);
- foreach ($headers as $header)
- {
- $data = explode(':', $header, 2);
- $head[strtolower(trim($data[0]))] = trim($data[1]);
- }
- if (preg_match('/HTTP\/[0-9\.]+ ([0-9]+)(.*)$/i', $status, $matches))
- {
- if (isset($head['status']))
- {
- unset($head['status']);
- }
- $head['status']['code'] = $matches[1];
- $head['status']['name'] = trim($matches[2]);
- }
- return $head;
- }
- }
- class SimplePie_Cache
- {
- var $location;
- var $filename;
- var $extension;
- var $name;
-
- function SimplePie_Cache($location, $filename, $extension)
- {
- $this->location = $location;
- $this->filename = rawurlencode($filename);
- $this->extension = rawurlencode($extension);
- $this->name = "$location/$this->filename.$this->extension";
- }
-
- function save($data)
- {
- if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
- {
- $fp = fopen($this->name, 'w');
- if ($fp)
- {
- fwrite($fp, serialize($data));
- fclose($fp);
- return true;
- }
- }
- return false;
- }
-
- function load()
- {
- if (file_exists($this->name) && is_readable($this->name))
- {
- return unserialize(file_get_contents($this->name));
- }
- return false;
- }
-
- function atime()
- {
- if (file_exists($this->name))
- {
- return fileatime($this->name);
- }
- return false;
- }
-
- function ctime()
- {
- if (file_exists($this->name))
- {
- return filectime($this->name);
- }
- return false;
- }
-
- function mtime()
- {
- if (file_exists($this->name))
- {
- return filemtime($this->name);
- }
- return false;
- }
-
- function touch()
- {
- if (file_exists($this->name))
- {
- return touch($this->name);
- }
- return false;
- }
-
- function unlink()
- {
- if (file_exists($this->name))
- {
- return unlink($this->name);
- }
- return false;
- }
-
- function clear($expire)
- {
- foreach (glob("$this->location/*.$this->extension") as $file)
- {
- if (time() - filemtime($file) > $expire)
- {
- unlink($file);
- }
- }
- }
- }
- class SimplePie_Misc
- {
- function absolutize_url($href, $location)
- {
- $href_parts = @parse_url($href);
- if (!empty($href_parts['scheme']))
- {
- return $href;
- }
- else
- {
- if (isset($location['host']))
- {
- $full_url = $location['scheme'] . '://' . $location['host'];
- }
- else
- {
- $full_url = '';
- }
- if (isset($location['port']))
- {
- $full_url .= ':' . $location['port'];
- }
- if (!empty($href_parts['path']))
- {
- if (substr($href_parts['path'], 0, 1) == '/')
- {
- $full_url .= $href_parts['path'];
- }
- else if (!empty($location['path']))
- {
- $full_url .= dirname($location['path'] . 'a') . '/' . $href_parts['path'];
- }
- else
- {
- $full_url .= $href_parts['path'];
- }
- }
- else if (!empty($location['path']))
- {
- $full_url .= $location['path'];
- }
- else
- {
- $full_url .= '/';
- }
- if (!empty($href_parts['query']))
- {
- $full_url .= '?' . $href_parts['query'];
- }
- else if (!empty($location['query']))
- {
- $full_url .= '?' . $location['query'];
- }
- if (!empty($href_parts['fragment']))
- {
- $full_url .= '#' . $href_parts['fragment'];
- }
- else if (!empty($location['fragment']))
- {
- $full_url .= '#' . $location['fragment'];
- }
- return $full_url;
- }
- }
-
- function get_element($realname, $string)
- {
- $return = array();
- $name = preg_quote($realname, '/');
- preg_match_all("/<($name)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'|(.*)))*)\s*(\/>|>(.*)<\/$name>)/msiU", $string, $matches, PREG_SET_ORDER);
- for ($i = 0; $i < count($matches); $i++)
- {
- $return[$i]['tag'] = $realname;
- $return[$i]['full'] = $matches[$i][0];
- if (strlen($matches[$i][10]) == 2)
- {
- $return[$i]['self_closing'] = true;
- }
- else
- {
- $return[$i]['self_closing'] = false;
- $return[$i]['content'] = $matches[$i][11];
- }
- $return[$i]['attribs'] = array();
- if (!empty($matches[$i][2]))
- {
- preg_match_all('/\s((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(\S+))\s/msiU', " $matches[$i][2] ", $attribs, PREG_SET_ORDER);
- for ($j = 0; $j < count($attribs); $j++)
- {
- $return[$i]['attribs'][strtoupper($attribs[$j][1])]['data'] = $attribs[$j][count($attribs[$j])-1];
- $first = substr($attribs[$j][2], 0, 1);
- $return[$i]['attribs'][strtoupper($attribs[$j][1])]['split'] = ($first == '"' || $first == "'") ? $first : '"';
- }
- }
- }
- return $return;
- }
-
- function element_implode($element)
- {
- $full = "<$element[tag]";
- foreach ($element['attribs'] as $key => $value)
- {
- $key = strtolower($key);
- $full .= " $key=$value[split]$value[data]$value[split]";
- }
- if ($element['self_closing'])
- {
- $full .= ' />';
- }
- else
- {
- $full .= ">$element[content]</$element[tag]>";
- }
- return $full;
- }
-
- function error($message, $level, $file, $line)
- {
- switch ($level)
- {
- case E_USER_ERROR:
- $note = 'PHP Error';
- break;
- case E_USER_WARNING:
- $note = 'PHP Warning';
- break;
- case E_USER_NOTICE:
- $note = 'PHP Notice';
- break;
- default:
- $note = 'Unknown Error';
- break;
- }
- error_log("$note: $message in $file on line $line", 0);
- return $message;
- }
-
- function display_file($url, $timeout = 10, $useragent = null)
- {
- $file = new SimplePie_File($url, $timeout, 5, null, $useragent);
- $headers = $file->headers();
- if ($file->body() !== false)
- {
- header('Content-type: ' . $headers['content-type']);
- echo $file->body();
- exit;
- }
- }
-
- /****************************************************
- FIX PROTOCOL
- Convert feed:// and no-protocol URL's to http://
- Feed is allowed to have no protocol. Local files are toggled in init().
- This is an internal function and is not intended to be used publically.
- $http=1, http://www.domain.com/feed.xml (absolute)
- $http=2, feed://www.domain.com/feed.xml (absolute)
- $http=3, podcast://www.domain.com/feed.xml (absolute)
- ****************************************************/
- function fix_protocol($url, $http = 1)
- {
- $url = preg_replace('/^http:\/\/photocast.mac.com/i', 'http://web.mac.com', $url);
- $url = preg_replace('/^(p(od)?cast|feed)[:]?[\/]*(http(s)?:\/\/)?/i', 'http://', $url);
- //$url = preg_replace('/^(.*)(s)?:\/\//i', 'http\\2://', $url);
- if ($http != 1 && strstr($url, 'http://'))
- {
- if ($http == 2)
- {
- $url = substr_replace($url, 'feed', 0, 4);
- }
- else if ($http == 3)
- {
- $url = substr_replace($url, 'podcast', 0, 4);
- }
- }
- return $url;
- }
-
- function encoding($encoding)
- {
- $return['use_mbstring'] = false;
- $return['use_iconv'] = false;
- switch (strtolower($encoding))
- {
- // 7bit
- case '7bit':
- case '7-bit':
- $return['encoding'] = '7bit';
- $return['use_mbstring'] = true;
- break;
- // 8bit
- case '8bit':
- case '8-bit':
- $return['encoding'] = '8bit';
- $return['use_mbstring'] = true;
- break;
- // ARMSCII-8
- case 'armscii-8':
- case 'armscii':
- $return['encoding'] = 'ARMSCII-8';
- $return['use_iconv'] = true;
- break;
- // ASCII
- case 'us-ascii':
- case 'ascii':
- $return['encoding'] = 'US-ASCII';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
- // BASE64
- case 'base64':
- case 'base-64':
- $return['encoding'] = 'BASE64';
- $return['use_mbstring'] = true;
- break;
- // Big5 - Traditional Chinese, mainly used in Taiwan
- case 'big5':
- case '950':
- $return['encoding'] = 'BIG5';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
- // Big5 with Hong Kong extensions, Traditional Chinese
- case 'big5-hkscs':
- $return['encoding'] = 'BIG5-HKSCS';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
- // byte2be
- case 'byte2be':
- $return['encoding'] = 'byte2be';
- $return['use_mbstring'] = true;
- break;
- // byte2le
- case 'byte2le':
- $return['encoding'] = 'byte2le';
- $return['use_mbstring'] = true;
- break;
- // byte4be
- case 'byte4be':
- $return['encoding'] = 'byte4be';
- $return['use_mbstring'] = true;
- break;
- // byte4le
- case 'byte4le':
- $return['encoding'] = 'byte4le';
- $return['use_mbstring'] = true;
- break;
- // EUC-CN
- case 'euc-cn':
- case 'euccn':
- $return['encoding'] = 'EUC-CN';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
- // EUC-JISX0213
- case 'euc-jisx0213':
- case 'eucjisx0213':
- $return['encoding'] = 'EUC-JISX0213';
- $return['use_iconv'] = true;
- break;
- // EUC-JP
- case 'euc-jp':
- case 'eucjp':
- $return['encoding'] = 'EUC-JP';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
- // EUCJP-win
- case 'euc-jp-win':
- case 'eucjp-win':
- case 'eucjpwin':
- $return['encoding'] = 'EUCJP-win';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
- // EUC-KR
- case 'euc-kr':
- case 'euckr':
- $return['encoding'] = 'EUC-KR';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
- // EUC-TW
- case 'euc-tw':
- case 'euctw':
- $return['encoding'] = 'EUC-TW';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
- // GB18030 - Simplified Chinese, national standard character set
- case 'gb18030-2000':
- case 'gb18030':
- $return['encoding'] = 'GB18030';
- $return['use_iconv'] = true;
- break;
- // GB2312 - Simplified Chinese, national standard character set
- case 'gb2312':
- case '936':
- $return['encoding'] = 'GB2312';
- $return…
Large files files are truncated, but you can click here to view the full file