/lib/simplepie/simplepie_060828.inc
PHP | 4982 lines | 2182 code | 202 blank | 2598 comment | 325 complexity | b3c867e494b5080c2b9c08639e47beb0 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: 28 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 = '20060828';
- 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 $file;
- var $xml_dump = false;
- var $enable_cache = true;
- var $max_minutes = 60;
- var $cache_location = './cache';
- var $order_by_date = true;
- var $input_encoding = false;
-
- // 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 set_file(&$file)
- {
- if (is_a($file, 'SimplePie_File'))
- {
- $this->rss_url = $file->url;
- $this->file =& $file;
- }
- }
-
- 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 input_encoding($encoding = false)
- {
- if ($encoding)
- {
- $this->input_encoding = (string) $encoding;
- }
- else
- {
- $this->input_encoding = false;
- }
- }
-
- function bypass_image_hotlink($get = false)
- {
- $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('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur'))
- {
- $this->sanitize->strip_attributes($attribs);
- }
-
- function output_encoding($encoding = 'UTF-8')
- {
- $this->sanitize->output_encoding($encoding);
- }
-
- 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;
- if (function_exists('ob_gzhandler'))
- {
- 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 (isset($this->data['url']) && $this->data['url'] != $this->rss_url)
- {
- $this->enable_caching(false);
- return $this->init();
- }
- else 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))
- {
- if (is_a($this->file, 'SimplePie_File') && $this->file->url == $this->rss_url)
- {
- $file =& $this->file;
- }
- else
- {
- $file = new SimplePie_File($this->rss_url, 10, 5, null, $this->useragent);
- }
- }
- if (!$file->success)
- {
- $this->error = $file->error;
- return false;
- }
-
- if (!SimplePie_Locator::is_feed($file))
- {
- $locate = new SimplePie_Locator($file);
- $feed = $locate->find();
- if ($feed)
- {
- if ($cache && !$cache->save(array('url' => $this->rss_url, '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 check to see if input has been overridden.
- if (!empty($this->input_encoding))
- {
- $encoding = $this->input_encoding;
- }
- // Second try HTTP headers
- else if (!empty($headers['content-type']) && preg_match('/charset\s*=\s*([^;]*)/i', $headers['content-type'], $charset))
- {
- $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 = substr($encoding[1], 1, -1);
- }
- // UTF-32 Big Endian BOM
- else if (strpos($data, sprintf('%c%c%c%c', 0x00, 0x00, 0xFE, 0xFF)) === 0)
- {
- $encoding = 'UTF-32be';
- }
- // UTF-32 Little Endian BOM
- else if (strpos($data, sprintf('%c%c%c%c', 0xFF, 0xFE, 0x00, 0x00)) === 0)
- {
- $encoding = 'UTF-32';
- }
- // UTF-16 Big Endian BOM
- else if (strpos($data, sprintf('%c%c', 0xFE, 0xFF)) === 0)
- {
- $encoding = 'UTF-16be';
- }
- // UTF-16 Little Endian BOM
- else if (strpos($data, sprintf('%c%c', 0xFF, 0xFE)) === 0)
- {
- $encoding = 'UTF-16le';
- }
- // UTF-8 BOM
- else if (strpos($data, sprintf('%c%c%c', 0xEF, 0xBB, 0xBF)) === 0)
- {
- $encoding = 'UTF-8';
- }
- // Fallback to the default
- else
- {
- $encoding = null;
- }
-
- $data = SimplePie_Misc::change_encoding($data, $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, $this->rss_url);
- unset($data);
- $this->data['feedinfo'] = $this->sanitize->feedinfo;
- $this->data['info'] = $this->sanitize->info;
- $this->data['items'] = $this->sanitize->items;
- $this->data['feedinfo']['encoding'] = $this->sanitize->output_encoding;
- unset($this->sanitize);
- $this->data['url'] = $this->rss_url;
- 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 get_favicon($check = false, $alternate = false)
- {
- if (!empty($this->data['info']['link']['alternate'][0]))
- {
- $favicon = SimplePie_Misc::absolutize_url('/favicon.ico', $this->data['info']['link']['alternate'][0]);
- if ($check)
- {
- $file = new SimplePie_File($favicon);
- $headers = $file->headers();
- $file->close();
- if ($headers['status']['code'] == 200)
- {
- return $favicon;
- }
- }
- else
- {
- return $favicon;
- }
- }
- if ($alternate)
- {
- return $alternate;
- }
- 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()
- {
- if (!empty($this->name))
- {
- return $this->name;
- }
- else
- {
- return false;
- }
- }
-
- function get_link()
- {
- if (!empty($this->link))
- {
- return $this->link;
- }
- else
- {
- return false;
- }
- }
-
- function get_email()
- {
- if (!empty($this->email))
- {
- return $this->email;
- }
- else
- {
- return false;
- }
- }
- }
- 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()
- {
- if (!empty($this->link))
- {
- return $this->link;
- }
- else
- {
- return false;
- }
- }
- function get_extension()
- {
- if (!empty($this->link))
- {
- return pathinfo($this->link, PATHINFO_EXTENSION);
- }
- else
- {
- return false;
- }
- }
- function get_type()
- {
- if (!empty($this->type))
- {
- return $this->type;
- }
- else
- {
- return false;
- }
- }
- function get_length()
- {
- if (!empty($this->length))
- {
- return $this->length;
- }
- else
- {
- return false;
- }
- }
- function get_size()
- {
- $length = $this->get_length();
- if (!empty($length))
- {
- return round($length/1048576, 2);
- }
- else
- {
- return false;
- }
- }
- function embed($options)
- {
- // Set up defaults
- $audio = '';
- $video = '';
- $alt = '';
- $altclass = '';
- $loop = 'false';
- $width = 'auto';
- $height = 'auto';
- $bgcolor = '#ffffff';
- // Process options and reassign values as necessary
- if (is_array($options))
- {
- extract($options);
- }
- else
- {
- $options = explode(',', $options);
- foreach($options as $option)
- {
- $opt = explode(':', $option, 2);
- if (isset($opt[0], $opt[1]))
- {
- $opt[0] = trim($opt[0]);
- $opt[1] = trim($opt[1]);
- switch ($opt[0])
- {
- case 'audio':
- $audio = $opt[1];
- break;
-
- case 'video':
- $video = $opt[1];
- break;
-
- case 'alt':
- $alt = $opt[1];
- break;
-
- case 'altclass':
- $altclass = $opt[1];
- break;
-
- case 'loop':
- $loop = $opt[1];
- break;
-
- case 'width':
- $width = $opt[1];
- break;
-
- case 'height':
- $height = $opt[1];
- break;
-
- case 'bgcolor':
- $bgcolor = $opt[1];
- break;
- }
- }
- }
- }
-
- $type = strtolower($this->get_type());
- // If we encounter an unsupported mime-type, check the file extension and guess intelligently.
- 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')))
- {
- switch (strtolower($this->get_extension()))
- {
- // Audio mime-types
- case 'aac':
- case 'adts':
- $type = 'audio/acc';
- break;
-
- case 'aif':
- case 'aifc':
- case 'aiff':
- case 'cdda':
- $type = 'audio/aiff';
- break;
-
- case 'bwf':
- $type = 'audio/wav';
- break;
-
- case 'kar':
- case 'mid':
- case 'midi':
- case 'smf':
- $type = 'audio/midi';
- break;
-
- case 'm4a':
- $type = 'audio/x-m4a';
- break;
-
- case 'mp3':
- case 'swa':
- $type = 'audio/mp3';
- break;
-
- case 'wav':
- $type = 'audio/wav';
- break;
-
- case 'wax':
- $type = 'audio/x-ms-wax';
- break;
-
- case 'wma':
- $type = 'audio/x-ms-wma';
- break;
-
- // Video mime-types
- case '3gp':
- case '3gpp':
- $type = 'video/3gpp';
- break;
- case '3g2':
- case '3gp2':
- $type = 'video/3gpp2';
- break;
- case 'asf':
- $type = 'video/x-ms-asf';
- break;
- case 'm1a':
- case 'm1s':
- case 'm1v':
- case 'm15':
- case 'm75':
- case 'mp2':
- case 'mpa':
- case 'mpeg':
- case 'mpg':
- case 'mpm':
- case 'mpv':
- $type = 'video/mpeg';
- break;
- case 'm4v':
- $type = 'video/x-m4v';
- break;
- case 'mov':
- case 'qt':
- $type = 'video/quicktime';
- break;
- case 'mp4':
- case 'mpg4':
- $type = 'video/mp4';
- break;
- case 'sdv':
- $type = 'video/sd-video';
- break;
- case 'wm':
- $type = 'video/x-ms-wm';
- break;
- case 'wmv':
- $type = 'video/x-ms-wmv';
- break;
- case 'wvx':
- $type = 'video/x-ms-wvx';
- break;
-
- // Flash mime-types
- case 'spl':
- $type = 'application/futuresplash';
- break;
- case 'swf':
- $type = 'application/x-shockwave-flash';
- break;
- }
- }
- $mime = explode('/', $type, 2);
- $mime = $mime[0];
-
- // Process values for 'auto'
- if ($width == 'auto')
- {
- if ($mime == 'video')
- {
- $width = '320';
- }
- else
- {
- $width = '100%';
- }
- }
- if ($height == 'auto')
- {
- if ($mime == 'audio')
- {
- $height = 0;
- }
- else if ($mime == 'video')
- {
- $height = 240;
- }
- else
- {
- $height = 256;
- }
- }
- // Set proper placeholder value
- if ($mime == 'audio')
- {
- $placeholder = $audio;
- }
- else if ($mime == '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->get_link()), 0, 15) == 'http://odeo.com') {
- $embed .= '<script type="text/javascript">embed_odeo("' . $this->get_link() . '");</script>';
- }
- // QuickTime 7 file types. Need to test with QuickTime 6.
- 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')))
- {
- $height += 16;
- $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>";
- }
- // Flash
- else if (in_array($type, array('application/x-shockwave-flash', 'application/futuresplash')))
- {
- $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>";
- }
- // Windows Media
- 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')))
- {
- $height += 45;
- $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>";
- }
- // Everything else
- else $embed .= '<a href="' . $this->get_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;
- var $error;
- var $method;
-
- 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') && version_compare(SimplePie_Misc::get_curl_version(), '7.10', '>='))
- {
- $fp = curl_init();
- $headers2 = array();
- foreach ($headers as $key => $value)
- {
- $headers2[] = "$key: $value";
- }
- curl_setopt($fp, CURLOPT_ENCODING, '');
- 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->error = curl_error($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);
- $this->method = 'curl';
- }
- }
- 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->error = $errstr;
- $this->success = false;
- return false;
- }
- else
- {
- $this->method = 'fsockopen';
- 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->error = 'Timeout';
- $this->success = false;
- return false;
- }
- }
- }
- return $this->headers['status']['code'];
- }
- else
- {
- if ($this->fp = fopen($url, 'r'))
- {
- $this->method = 'fopen';
- return true;
- }
- else
- {
- $this->error = 'Could not open the file';
- $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);
- if ($this->method == 'fsockopen' && !empty($this->headers['content-encoding']) && $this->headers['content-encoding'] == 'gzip')
- {
- $this->body = substr($this->body, 10);
- $this->body = gzinflate($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($relative, $base)
- {
- $relative = trim($relative);
- $base = trim($base);
- if (!empty($relative))
- {
- $relative = SimplePie_Misc::parse_url($relative, false);
- $relative = array('scheme' => $relative[2], 'authority' => $relative[3], 'path' => $relative[5], 'query' => $relative[7], 'fragment' => $relative[9]);
- if (!empty($relative['scheme']))
- {
- $target = $relative;
- }
- else if (!empty($base))
- {
- $base = SimplePie_Misc::parse_url($base, false);
- $base = array('scheme' => $base[2], 'authority' => $base[3], 'path' => $base[5], 'query' => $base[7], 'fragment' => $base[9]);
- $target['scheme'] = $base['scheme'];
- if (!empty($relative['authority']))
- {
- $target = array_merge($relative, $target);
- }
- else
- {
- $target['authority'] = $base['authority'];
- if (!empty($relative['path']))
- {
- if (strpos($relative['path'], '/') === 0)
- {
- $target['path'] = $relative['path'];
- }
- else
- {
- if (!empty($base['path']))
- {
- $target['path'] = dirname("$base[path].") . '/' . $relative['path'];
- }
- else
- {
- $target['path'] = '/' . $relative['path'];
- }
- }
- if (!empty($relative['query']))
- {
- $target['query'] = $relative['query'];
- }
- $input = $target['path'];
- $target['path'] = '';
- while (!empty($input))
- {
- if (strpos($input, '../') === 0)
- {
- $input = substr($input, 3);
- }
- else if (strpos($input, './') === 0)
- {
- $input = substr($input, 2);
- }
- else if (strpos($input, '/./') === 0)
- {
- $input = substr_replace($input, '/', 0, 3);
- }
- else if (strpos($input, '/.') === 0 && SimplePie_Misc::strendpos($input, '/.') === 0)
- {
- $input = substr_replace($input, '/', -2);
- }
- else if (strpos($input, '/../') === 0)
- {
- $input = substr_replace($input, '/', 0, 4);
- $target['path'] = preg_replace('/(\/)?([^\/]+)$/U', '', $target['path']);
- }
- else if (strpos($input, '/..') === 0 && SimplePie_Misc::strendpos($input, '/..') === 0)
- {
- $input = substr_replace($input, '/', 0, 3);
- $target['path'] = preg_replace('/(\/)?([^\/]+)$/U', '', $target['path']);
- }
- else if ($input == '.' || $input == '..')
- {
- $input = '';
- }
- else
- {
- if (preg_match('/^(.+)(\/|$)/U', $input, $match))
- {
- $target['path'] .= $match[1];
- $input = substr_replace($input, '', 0, strlen($match[1]));
- }
- }
- }
- }
- else
- {
- if (!empty($base['path']))
- {
- $target['path'] = $base['path'];
- }
- else
- {
- $target['path'] = '/';
- }
- if (!empty($relative['query']))
- {
- $target['query'] = $relative['query'];
- }
- else if (!empty($base['query']))
- {
- $target['query'] = $base['query'];
- }
- }
- }
- if (!empty($relative['fragment']))
- {
- $target['fragment'] = $relative['fragment'];
- }
- }
- else
- {
- return false;
- }
- $return = "$target[scheme]:$target[authority]$target[path]";
- if (!empty($target['query']))
- {
- $return .= "?$target[query]";
- }
- if (!empty($target['fragment']))
- {
- $return .= "#$target[fragment]";
- }
- }
- else
- {
- $return = $base;
- }
- return $return;
- }
-
- function strendpos($haystack, $needle)
- {
- return strlen($haystack) - strpos($haystack, $needle) - strlen($needle);
- }
-
- function get_element($realname, $string)
- {
- $return = array();
- $nam…
Large files files are truncated, but you can click here to view the full file