/third-party/simplepie.php
PHP | 15123 lines | 12746 code | 713 blank | 1664 comment | 1019 complexity | 5498f0e31ca5c00c663d1a60f15474a6 MD5 | raw file
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.
- *
- * Copyright (c) 2004-2010, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * * Neither the name of the SimplePie Team nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
- * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * @package SimplePie
- * @version 1.3-dev
- * @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
- * @author Ryan Parman
- * @author Geoffrey Sneddon
- * @author Ryan McCue
- * @link http://simplepie.org/ SimplePie
- * @license http://www.opensource.org/licenses/bsd-license.php BSD License
- * @todo phpDoc comments
- */
- /**
- * SimplePie class.
- *
- * Class for backward compatibility.
- *
- * @package SimplePie
- */
- class SimplePie extends SimplePie_Core
- {
- }
- class SimplePie_Author
- {
- var $name;
- var $link;
- var $email;
- // Constructor, used to input the data
- public function __construct($name = null, $link = null, $email = null)
- {
- $this->name = $name;
- $this->link = $link;
- $this->email = $email;
- }
- public function __toString()
- {
- // There is no $this->data here
- return md5(serialize($this));
- }
- public function get_name()
- {
- if ($this->name !== null)
- {
- return $this->name;
- }
- else
- {
- return null;
- }
- }
- public function get_link()
- {
- if ($this->link !== null)
- {
- return $this->link;
- }
- else
- {
- return null;
- }
- }
- public function get_email()
- {
- if ($this->email !== null)
- {
- return $this->email;
- }
- else
- {
- return null;
- }
- }
- }
- interface SimplePie_Cache_Base
- {
- /**
- * Feed cache type
- */
- const TYPE_FEED = 'spc';
- /**
- * Image cache type
- */
- const TYPE_IMAGE = 'spi';
- /**
- * Create a new cache object
- *
- * @param string $location Location string (from SimplePie::$cache_location)
- * @param string $name Unique ID for the cache
- * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
- */
- public function __construct($location, $name, $type);
- /**
- * Save data to the cache
- *
- * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
- */
- public function save($data);
- /**
- * Retrieve the data saved to the cache
- *
- * @return array Data for SimplePie::$data
- */
- public function load();
- /**
- * Retrieve the last modified time for the cache
- *
- * @return int Timestamp
- */
- public function mtime();
- /**
- * Set the last modified time to the current time
- *
- * @return bool Success status
- */
- public function touch();
- /**
- * Remove the cache
- *
- * @return bool Success status
- */
- public function unlink();
- }
- abstract class SimplePie_Cache_DB implements SimplePie_Cache_Base
- {
- protected static function prepare_simplepie_object_for_cache(&$data)
- {
- $items = $data->get_items();
- $items_by_id = array();
- if (!empty($items))
- {
- foreach ($items as $item)
- {
- $items_by_id[$item->get_id()] = $item;
- }
- if (count($items_by_id) !== count($items))
- {
- $items_by_id = array();
- foreach ($items as $item)
- {
- $items_by_id[$item->get_id(true)] = $item;
- }
- }
- if (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
- {
- $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
- }
- elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
- {
- $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
- }
- elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
- {
- $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
- }
- elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0]))
- {
- $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0];
- }
- else
- {
- $channel = null;
- }
- if ($channel !== null)
- {
- if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']))
- {
- unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']);
- }
- if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']))
- {
- unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']);
- }
- if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']))
- {
- unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']);
- }
- if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']))
- {
- unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']);
- }
- if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']))
- {
- unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']);
- }
- }
- if (isset($data->data['items']))
- {
- unset($data->data['items']);
- }
- if (isset($data->data['ordered_items']))
- {
- unset($data->data['ordered_items']);
- }
- }
- return array(serialize($data->data), $items_by_id);
- }
- }
- class SimplePie_Cache_File implements SimplePie_Cache_Base
- {
- protected $location;
- protected $filename;
- protected $extension;
- protected $name;
- public function __construct($location, $filename, $extension)
- {
- $this->location = $location;
- $this->filename = $filename;
- $this->extension = $extension;
- $this->name = "$this->location/$this->filename.$this->extension";
- }
- public function save($data)
- {
- if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
- {
- if (is_a($data, 'SimplePie'))
- {
- $data = $data->data;
- }
- $data = serialize($data);
- return (bool) file_put_contents($this->name, $data);
- }
- return false;
- }
- public function load()
- {
- if (file_exists($this->name) && is_readable($this->name))
- {
- return unserialize(file_get_contents($this->name));
- }
- return false;
- }
- public function mtime()
- {
- if (file_exists($this->name))
- {
- return filemtime($this->name);
- }
- return false;
- }
- public function touch()
- {
- if (file_exists($this->name))
- {
- return touch($this->name);
- }
- return false;
- }
- public function unlink()
- {
- if (file_exists($this->name))
- {
- return unlink($this->name);
- }
- return false;
- }
- }
- class SimplePie_Cache_Memcache implements SimplePie_Cache_Base
- {
- protected $cache;
- protected $options;
- protected $name;
- public function __construct($url, $filename, $extension)
- {
- $this->options = array(
- 'host' => '127.0.0.1',
- 'port' => 11211,
- 'extras' => array(
- 'timeout' => 3600, // one hour
- 'prefix' => 'simplepie_',
- ),
- );
- $this->options = array_merge_recursive($this->options, SimplePie_Cache::parse_URL($url));
- $this->name = $this->options['extras']['prefix'] . md5("$filename:$extension");
- $this->cache = new Memcache();
- $this->cache->addServer($this->options['host'], (int) $this->options['port']);
- }
- public function save($data)
- {
- if (is_a($data, 'SimplePie'))
- {
- $data = $data->data;
- }
- return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
- }
- public function load()
- {
- $data = $this->cache->get($this->name);
- if ($data !== false)
- {
- return unserialize($data);
- }
- return false;
- }
- public function mtime()
- {
- $data = $this->cache->get($this->name);
- if ($data !== false)
- {
- // essentially ignore the mtime because Memcache expires on it's own
- return time();
- }
- return false;
- }
- public function touch()
- {
- $data = $this->cache->get($this->name);
- if ($data !== false)
- {
- return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->duration);
- }
- return false;
- }
- public function unlink()
- {
- return $this->cache->delete($this->name, 0);
- }
- }
- class SimplePie_Cache_MySQL extends SimplePie_Cache_DB
- {
- protected $mysql;
- protected $options;
- protected $id;
- public function __construct($url, $name, $extension)
- {
- $this->options = array(
- 'user' => null,
- 'pass' => null,
- 'host' => '127.0.0.1',
- 'port' => '3306',
- 'path' => '',
- 'extras' => array(
- 'prefix' => '',
- ),
- );
- $this->options = array_merge_recursive($this->options, SimplePie_Cache::parse_URL($url));
- // Path is prefixed with a "/"
- $this->options['dbname'] = substr($this->options['path'], 1);
- try
- {
- $this->mysql = new PDO("mysql:dbname={$this->options['dbname']};host={$this->options['host']};port={$this->options['port']}", $this->options['user'], $this->options['pass'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
- }
- catch (PDOException $e)
- {
- $this->mysql = null;
- return;
- }
- $this->id = $name . $extension;
- if (!$query = $this->mysql->query('SHOW TABLES'))
- {
- $this->mysql = null;
- return;
- }
- $db = array();
- while ($row = $query->fetchColumn())
- {
- $db[] = $row;
- }
- if (!in_array($this->options['extras']['prefix'] . 'cache_data', $db))
- {
- $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'cache_data` (`id` TEXT CHARACTER SET utf8 NOT NULL, `items` SMALLINT NOT NULL DEFAULT 0, `data` BLOB NOT NULL, `mtime` INT UNSIGNED NOT NULL, UNIQUE (`id`(125)))');
- if ($query === false)
- {
- $this->mysql = null;
- }
- }
- if (!in_array($this->options['extras']['prefix'] . 'items', $db))
- {
- $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` TEXT CHARACTER SET utf8 NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))');
- if ($query === false)
- {
- $this->mysql = null;
- }
- }
- }
- public function save($data)
- {
- if ($this->mysql === null)
- {
- return false;
- }
- if (is_a($data, 'SimplePie'))
- {
- $data = clone $data;
- $prepared = self::prepare_simplepie_object_for_cache($data);
- $query = $this->mysql->prepare('SELECT COUNT(*) FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
- $query->bindValue(':feed', $this->id);
- if ($query->execute())
- {
- if ($query->fetchColumn() > 0)
- {
- $items = count($prepared[1]);
- if ($items)
- {
- $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed';
- $query = $this->mysql->prepare($sql);
- $query->bindValue(':items', $items);
- }
- else
- {
- $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed';
- $query = $this->mysql->prepare($sql);
- }
- $query->bindValue(':data', $prepared[0]);
- $query->bindValue(':time', time());
- $query->bindValue(':feed', $this->id);
- if (!$query->execute())
- {
- return false;
- }
- }
- else
- {
- $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:feed, :count, :data, :time)');
- $query->bindValue(':feed', $this->id);
- $query->bindValue(':count', count($prepared[1]));
- $query->bindValue(':data', $prepared[0]);
- $query->bindValue(':time', time());
- if (!$query->execute())
- {
- return false;
- }
- }
- $ids = array_keys($prepared[1]);
- if (!empty($ids))
- {
- foreach ($ids as $id)
- {
- $database_ids[] = $this->mysql->quote($id);
- }
- $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `id` = ' . implode(' OR `id` = ', $database_ids) . ' AND `feed_id` = :feed');
- $query->bindValue(':feed', $this->id);
- if ($query->execute())
- {
- $existing_ids = array();
- while ($row = $query->fetchColumn())
- {
- $existing_ids[] = $row;
- }
- $new_ids = array_diff($ids, $existing_ids);
- foreach ($new_ids as $new_id)
- {
- if (!($date = $prepared[1][$new_id]->get_date('U')))
- {
- $date = time();
- }
- $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(:feed, :id, :data, :date)');
- $query->bindValue(':feed', $this->id);
- $query->bindValue(':id', $new_id);
- $query->bindValue(':data', serialize($prepared[1][$new_id]->data));
- $query->bindValue(':date', $date);
- if (!$query->execute())
- {
- return false;
- }
- }
- return true;
- }
- }
- else
- {
- return true;
- }
- }
- }
- else
- {
- $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
- $query->bindValue(':feed', $this->id);
- if ($query->execute())
- {
- if ($query->rowCount() > 0)
- {
- $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed');
- $query->bindValue(':data', serialize($data));
- $query->bindValue(':time', time());
- $query->bindValue(':feed', $this->id);
- if ($this->execute())
- {
- return true;
- }
- }
- else
- {
- $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:id, 0, :data, :time)');
- $query->bindValue(':id', $this->id);
- $query->bindValue(':data', serialize($data));
- $query->bindValue(':time', time());
- if ($query->execute())
- {
- return true;
- }
- }
- }
- }
- return false;
- }
- public function load()
- {
- if ($this->mysql === null)
- {
- return false;
- }
- $query = $this->mysql->prepare('SELECT `items`, `data` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
- $query->bindValue(':id', $this->id);
- if ($query->execute() && ($row = $query->fetch()))
- {
- $data = unserialize($row[1]);
- if (isset($this->options['items'][0]))
- {
- $items = (int) $this->options['items'][0];
- }
- else
- {
- $items = (int) $row[0];
- }
- if ($items !== 0)
- {
- if (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
- {
- $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
- }
- elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
- {
- $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
- }
- elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
- {
- $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
- }
- elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]))
- {
- $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0];
- }
- else
- {
- $feed = null;
- }
- if ($feed !== null)
- {
- $sql = 'SELECT `data` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :feed ORDER BY `posted` DESC';
- if ($items > 0)
- {
- $sql .= ' LIMIT ' . $items;
- }
- $query = $this->mysql->prepare($sql);
- $query->bindValue(':feed', $this->id);
- if ($query->execute())
- {
- while ($row = $query->fetchColumn())
- {
- $feed['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'][] = unserialize($row);
- }
- }
- else
- {
- return false;
- }
- }
- }
- return $data;
- }
- return false;
- }
- public function mtime()
- {
- if ($this->mysql === null)
- {
- return false;
- }
- $query = $this->mysql->prepare('SELECT `mtime` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
- $query->bindValue(':id', $this->id);
- if ($query->execute() && ($time = $query->fetchColumn()))
- {
- return $time;
- }
- else
- {
- return false;
- }
- }
- public function touch()
- {
- if ($this->mysql === null)
- {
- return false;
- }
- $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `mtime` = :time WHERE `id` = :id');
- $query->bindValue(':time', time());
- $query->bindValue(':id', $this->id);
- if ($query->execute() && $query->rowCount() > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public function unlink()
- {
- if ($this->mysql === null)
- {
- return false;
- }
- $query = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
- $query->bindValue(':id', $this->id);
- $query2 = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :id');
- $query2->bindValue(':id', $this->id);
- if ($query->execute() && $query2->execute())
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- class SimplePie_Cache
- {
- /**
- * Cache handler classes
- *
- * These receive 3 parameters to their constructor, as documented in
- * {@see register()}
- * @var array
- */
- protected static $handlers = array(
- 'mysql' => 'SimplePie_Cache_MySQL',
- 'memcache' => 'SimplePie_Cache_Memcache',
- );
- /**
- * Don't call the constructor. Please.
- */
- private function __construct() { }
- /**
- * Create a new SimplePie_Cache object
- */
- public static function create($location, $filename, $extension)
- {
- $type = explode(':', $location, 2);
- $type = $type[0];
- if (!empty(self::$handlers[$type]))
- {
- $class = self::$handlers[$type];
- return new $class($location, $filename, $extension);
- }
- return new SimplePie_Cache_File($location, $filename, $extension);
- }
- /**
- * Register a handler
- *
- * @param string $type DSN type to register for
- * @param string $class Name of handler class. Must implement SimplePie_Cache_Base
- */
- public static function register($type, $class)
- {
- self::$handlers[$type] = $class;
- }
- /**
- * Parse a URL into an array
- *
- * @param string $url
- * @return array
- */
- public static function parse_URL($url)
- {
- $params = parse_url($url);
- $params['extras'] = array();
- if (isset($params['query']))
- {
- parse_str($params['query'], $params['extras']);
- }
- return $params;
- }
- }
- class SimplePie_Caption
- {
- var $type;
- var $lang;
- var $startTime;
- var $endTime;
- var $text;
- // Constructor, used to input the data
- public function __construct($type = null, $lang = null, $startTime = null, $endTime = null, $text = null)
- {
- $this->type = $type;
- $this->lang = $lang;
- $this->startTime = $startTime;
- $this->endTime = $endTime;
- $this->text = $text;
- }
- public function __toString()
- {
- // There is no $this->data here
- return md5(serialize($this));
- }
- public function get_endtime()
- {
- if ($this->endTime !== null)
- {
- return $this->endTime;
- }
- else
- {
- return null;
- }
- }
- public function get_language()
- {
- if ($this->lang !== null)
- {
- return $this->lang;
- }
- else
- {
- return null;
- }
- }
- public function get_starttime()
- {
- if ($this->startTime !== null)
- {
- return $this->startTime;
- }
- else
- {
- return null;
- }
- }
- public function get_text()
- {
- if ($this->text !== null)
- {
- return $this->text;
- }
- else
- {
- return null;
- }
- }
- public function get_type()
- {
- if ($this->type !== null)
- {
- return $this->type;
- }
- else
- {
- return null;
- }
- }
- }
- class SimplePie_Category
- {
- var $term;
- var $scheme;
- var $label;
- // Constructor, used to input the data
- public function __construct($term = null, $scheme = null, $label = null)
- {
- $this->term = $term;
- $this->scheme = $scheme;
- $this->label = $label;
- }
- public function __toString()
- {
- // There is no $this->data here
- return md5(serialize($this));
- }
- public function get_term()
- {
- if ($this->term !== null)
- {
- return $this->term;
- }
- else
- {
- return null;
- }
- }
- public function get_scheme()
- {
- if ($this->scheme !== null)
- {
- return $this->scheme;
- }
- else
- {
- return null;
- }
- }
- public function get_label()
- {
- if ($this->label !== null)
- {
- return $this->label;
- }
- else
- {
- return $this->get_term();
- }
- }
- }
- /**
- * Content-type sniffing
- *
- * Based on the rules in http://tools.ietf.org/html/draft-abarth-mime-sniff-06
- * @package SimplePie
- */
- class SimplePie_Content_Type_Sniffer
- {
- /**
- * File object
- *
- * @var SimplePie_File
- */
- var $file;
- /**
- * Create an instance of the class with the input file
- *
- * @param SimplePie_Content_Type_Sniffer $file Input file
- */
- public function __construct($file)
- {
- $this->file = $file;
- }
- /**
- * Get the Content-Type of the specified file
- *
- * @return string Actual Content-Type
- */
- public function get_type()
- {
- if (isset($this->file->headers['content-type']))
- {
- if (!isset($this->file->headers['content-encoding'])
- && ($this->file->headers['content-type'] === 'text/plain'
- || $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1'
- || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1'
- || $this->file->headers['content-type'] === 'text/plain; charset=UTF-8'))
- {
- return $this->text_or_binary();
- }
- if (($pos = strpos($this->file->headers['content-type'], ';')) !== false)
- {
- $official = substr($this->file->headers['content-type'], 0, $pos);
- }
- else
- {
- $official = $this->file->headers['content-type'];
- }
- $official = trim(strtolower($official));
- if ($official === 'unknown/unknown'
- || $official === 'application/unknown')
- {
- return $this->unknown();
- }
- elseif (substr($official, -4) === '+xml'
- || $official === 'text/xml'
- || $official === 'application/xml')
- {
- return $official;
- }
- elseif (substr($official, 0, 6) === 'image/')
- {
- if ($return = $this->image())
- {
- return $return;
- }
- else
- {
- return $official;
- }
- }
- elseif ($official === 'text/html')
- {
- return $this->feed_or_html();
- }
- else
- {
- return $official;
- }
- }
- else
- {
- return $this->unknown();
- }
- }
- /**
- * Sniff text or binary
- *
- * @return string Actual Content-Type
- */
- public function text_or_binary()
- {
- if (substr($this->file->body, 0, 2) === "\xFE\xFF"
- || substr($this->file->body, 0, 2) === "\xFF\xFE"
- || substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF"
- || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF")
- {
- return 'text/plain';
- }
- elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body))
- {
- return 'application/octect-stream';
- }
- else
- {
- return 'text/plain';
- }
- }
- /**
- * Sniff unknown
- *
- * @return string Actual Content-Type
- */
- public function unknown()
- {
- $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
- if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html'
- || strtolower(substr($this->file->body, $ws, 5)) === '<html'
- || strtolower(substr($this->file->body, $ws, 7)) === '<script')
- {
- return 'text/html';
- }
- elseif (substr($this->file->body, 0, 5) === '%PDF-')
- {
- return 'application/pdf';
- }
- elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-')
- {
- return 'application/postscript';
- }
- elseif (substr($this->file->body, 0, 6) === 'GIF87a'
- || substr($this->file->body, 0, 6) === 'GIF89a')
- {
- return 'image/gif';
- }
- elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
- {
- return 'image/png';
- }
- elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
- {
- return 'image/jpeg';
- }
- elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
- {
- return 'image/bmp';
- }
- elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
- {
- return 'image/vnd.microsoft.icon';
- }
- else
- {
- return $this->text_or_binary();
- }
- }
- /**
- * Sniff images
- *
- * @return string Actual Content-Type
- */
- public function image()
- {
- if (substr($this->file->body, 0, 6) === 'GIF87a'
- || substr($this->file->body, 0, 6) === 'GIF89a')
- {
- return 'image/gif';
- }
- elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
- {
- return 'image/png';
- }
- elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
- {
- return 'image/jpeg';
- }
- elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
- {
- return 'image/bmp';
- }
- elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
- {
- return 'image/vnd.microsoft.icon';
- }
- else
- {
- return false;
- }
- }
- /**
- * Sniff HTML
- *
- * @return string Actual Content-Type
- */
- public function feed_or_html()
- {
- $len = strlen($this->file->body);
- $pos = strspn($this->file->body, "\x09\x0A\x0D\x20");
- while ($pos < $len)
- {
- switch ($this->file->body[$pos])
- {
- case "\x09":
- case "\x0A":
- case "\x0D":
- case "\x20":
- $pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos);
- continue 2;
- case '<':
- $pos++;
- break;
- default:
- return 'text/html';
- }
- if (substr($this->file->body, $pos, 3) === '!--')
- {
- $pos += 3;
- if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false)
- {
- $pos += 3;
- }
- else
- {
- return 'text/html';
- }
- }
- elseif (substr($this->file->body, $pos, 1) === '!')
- {
- if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false)
- {
- $pos++;
- }
- else
- {
- return 'text/html';
- }
- }
- elseif (substr($this->file->body, $pos, 1) === '?')
- {
- if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false)
- {
- $pos += 2;
- }
- else
- {
- return 'text/html';
- }
- }
- elseif (substr($this->file->body, $pos, 3) === 'rss'
- || substr($this->file->body, $pos, 7) === 'rdf:RDF')
- {
- return 'application/rss+xml';
- }
- elseif (substr($this->file->body, $pos, 4) === 'feed')
- {
- return 'application/atom+xml';
- }
- else
- {
- return 'text/html';
- }
- }
- return 'text/html';
- }
- }
- class SimplePie_Copyright
- {
- var $url;
- var $label;
- // Constructor, used to input the data
- public function __construct($url = null, $label = null)
- {
- $this->url = $url;
- $this->label = $label;
- }
- public function __toString()
- {
- // There is no $this->data here
- return md5(serialize($this));
- }
- public function get_url()
- {
- if ($this->url !== null)
- {
- return $this->url;
- }
- else
- {
- return null;
- }
- }
- public function get_attribution()
- {
- if ($this->label !== null)
- {
- return $this->label;
- }
- else
- {
- return null;
- }
- }
- }
- /**
- * SimplePie Name
- */
- define('SIMPLEPIE_NAME', 'SimplePie');
- /**
- * SimplePie Version
- */
- define('SIMPLEPIE_VERSION', '1.3-dev');
- /**
- * SimplePie Build
- * @todo Hardcode for release (there's no need to have to call SimplePie_Misc::get_build() only every load of simplepie.inc)
- */
- define('SIMPLEPIE_BUILD', gmdate('YmdHis', SimplePie_Misc::get_build()));
- /**
- * SimplePie Website URL
- */
- define('SIMPLEPIE_URL', 'http://simplepie.org');
- /**
- * SimplePie Useragent
- * @see SimplePie::set_useragent()
- */
- define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD);
- /**
- * SimplePie Linkback
- */
- define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>');
- /**
- * No Autodiscovery
- * @see SimplePie::set_autodiscovery_level()
- */
- define('SIMPLEPIE_LOCATOR_NONE', 0);
- /**
- * Feed Link Element Autodiscovery
- * @see SimplePie::set_autodiscovery_level()
- */
- define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1);
- /**
- * Local Feed Extension Autodiscovery
- * @see SimplePie::set_autodiscovery_level()
- */
- define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2);
- /**
- * Local Feed Body Autodiscovery
- * @see SimplePie::set_autodiscovery_level()
- */
- define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4);
- /**
- * Remote Feed Extension Autodiscovery
- * @see SimplePie::set_autodiscovery_level()
- */
- define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8);
- /**
- * Remote Feed Body Autodiscovery
- * @see SimplePie::set_autodiscovery_level()
- */
- define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16);
- /**
- * All Feed Autodiscovery
- * @see SimplePie::set_autodiscovery_level()
- */
- define('SIMPLEPIE_LOCATOR_ALL', 31);
- /**
- * No known feed type
- */
- define('SIMPLEPIE_TYPE_NONE', 0);
- /**
- * RSS 0.90
- */
- define('SIMPLEPIE_TYPE_RSS_090', 1);
- /**
- * RSS 0.91 (Netscape)
- */
- define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2);
- /**
- * RSS 0.91 (Userland)
- */
- define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4);
- /**
- * RSS 0.91 (both Netscape and Userland)
- */
- define('SIMPLEPIE_TYPE_RSS_091', 6);
- /**
- * RSS 0.92
- */
- define('SIMPLEPIE_TYPE_RSS_092', 8);
- /**
- * RSS 0.93
- */
- define('SIMPLEPIE_TYPE_RSS_093', 16);
- /**
- * RSS 0.94
- */
- define('SIMPLEPIE_TYPE_RSS_094', 32);
- /**
- * RSS 1.0
- */
- define('SIMPLEPIE_TYPE_RSS_10', 64);
- /**
- * RSS 2.0
- */
- define('SIMPLEPIE_TYPE_RSS_20', 128);
- /**
- * RDF-based RSS
- */
- define('SIMPLEPIE_TYPE_RSS_RDF', 65);
- /**
- * Non-RDF-based RSS (truly intended as syndication format)
- */
- define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190);
- /**
- * All RSS
- */
- define('SIMPLEPIE_TYPE_RSS_ALL', 255);
- /**
- * Atom 0.3
- */
- define('SIMPLEPIE_TYPE_ATOM_03', 256);
- /**
- * Atom 1.0
- */
- define('SIMPLEPIE_TYPE_ATOM_10', 512);
- /**
- * All Atom
- */
- define('SIMPLEPIE_TYPE_ATOM_ALL', 768);
- /**
- * All feed types
- */
- define('SIMPLEPIE_TYPE_ALL', 1023);
- /**
- * No construct
- */
- define('SIMPLEPIE_CONSTRUCT_NONE', 0);
- /**
- * Text construct
- */
- define('SIMPLEPIE_CONSTRUCT_TEXT', 1);
- /**
- * HTML construct
- */
- define('SIMPLEPIE_CONSTRUCT_HTML', 2);
- /**
- * XHTML construct
- */
- define('SIMPLEPIE_CONSTRUCT_XHTML', 4);
- /**
- * base64-encoded construct
- */
- define('SIMPLEPIE_CONSTRUCT_BASE64', 8);
- /**
- * IRI construct
- */
- define('SIMPLEPIE_CONSTRUCT_IRI', 16);
- /**
- * A construct that might be HTML
- */
- define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32);
- /**
- * All constructs
- */
- define('SIMPLEPIE_CONSTRUCT_ALL', 63);
- /**
- * Don't change case
- */
- define('SIMPLEPIE_SAME_CASE', 1);
- /**
- * Change to lowercase
- */
- define('SIMPLEPIE_LOWERCASE', 2);
- /**
- * Change to uppercase
- */
- define('SIMPLEPIE_UPPERCASE', 4);
- /**
- * PCRE for HTML attributes
- */
- define('SIMPLEPIE_PCRE_HTML_ATTRIBUTE', '((?:[\x09\x0A\x0B\x0C\x0D\x20]+[^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?)*)[\x09\x0A\x0B\x0C\x0D\x20]*');
- /**
- * PCRE for XML attributes
- */
- define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*');
- /**
- * XML Namespace
- */
- define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace');
- /**
- * Atom 1.0 Namespace
- */
- define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom');
- /**
- * Atom 0.3 Namespace
- */
- define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#');
- /**
- * RDF Namespace
- */
- define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
- /**
- * RSS 0.90 Namespace
- */
- define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/');
- /**
- * RSS 1.0 Namespace
- */
- define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/');
- /**
- * RSS 1.0 Content Module Namespace
- */
- define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/');
- /**
- * RSS 2.0 Namespace
- * (Stupid, I know, but I'm certain it will confuse people less with support.)
- */
- define('SIMPLEPIE_NAMESPACE_RSS_20', '');
- /**
- * DC 1.0 Namespace
- */
- define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/');
- /**
- * DC 1.1 Namespace
- */
- define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/');
- /**
- * W3C Basic Geo (WGS84 lat/long) Vocabulary Namespace
- */
- define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#');
- /**
- * GeoRSS Namespace
- */
- define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss');
- /**
- * Media RSS Namespace
- */
- define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/');
- /**
- * Wrong Media RSS Namespace. Caused by a long-standing typo in the spec.
- */
- define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss');
- /**
- * Wrong Media RSS Namespace #2. New namespace introduced in Media RSS 1.5.
- */
- define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2', 'http://video.search.yahoo.com/mrss');
- /**
- * Wrong Media RSS Namespace #3. A possible typo of the Media RSS 1.5 namespace.
- */
- define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3', 'http://video.search.yahoo.com/mrss/');
- /**
- * Wrong Media RSS Namespace #4. New spec location after the RSS Advisory Board takes it over, but not a valid namespace.
- */
- define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4', 'http://www.rssboard.org/media-rss');
- /**
- * Wrong Media RSS Namespace #5. A possible typo of the RSS Advisory Board URL.
- */
- define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5', 'http://www.rssboard.org/media-rss/');
- /**
- * iTunes RSS Namespace
- */
- define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
- /**
- * XHTML Namespace
- */
- define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml');
- /**
- * IANA Link Relations Registry
- */
- define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/');
- /**
- * Whether we're running on PHP5
- */
- define('SIMPLEPIE_PHP5', version_compare(PHP_VERSION, '5.0.0', '>='));
- /**
- * No file source
- */
- define('SIMPLEPIE_FILE_SOURCE_NONE', 0);
- /**
- * Remote file source
- */
- define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1);
- /**
- * Local file source
- */
- define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2);
- /**
- * fsockopen() file source
- */
- define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4);
- /**
- * cURL file source
- */
- define('SIMPLEPIE_FILE_SOURCE_CURL', 8);
- /**
- * file_get_contents() file source
- */
- define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16);
- /**
- * SimplePie
- *
- * @package SimplePie
- */
- class SimplePie_Core
- {
- /**
- * @var array Raw data
- * @access private
- */
- public $data = array();
- /**
- * @var mixed Error string
- * @access private
- */
- public $error;
- /**
- * @var object Instance of SimplePie_Sanitize (or other class)
- * @see SimplePie::set_sanitize_class()
- * @access private
- */
- public $sanitize;
- /**
- * @var string SimplePie Useragent
- * @see SimplePie::set_useragent()
- * @access private
- */
- public $useragent = SIMPLEPIE_USERAGENT;
- /**
- * @var string Feed URL
- * @see SimplePie::set_feed_url()
- * @access private
- */
- public $feed_url;
- /**
- * @var object Instance of SimplePie_File to use as a feed
- * @see SimplePie::set_file()
- * @access private
- */
- public $file;
- /**
- * @var string Raw feed data
- * @see SimplePie::set_raw_data()
- * @access private
- */
- public $raw_data;
- /**
- * @var int Timeout for fetching remote files
- * @see SimplePie::set_timeout()
- * @access private
- */
- public $timeout = 10;
- /**
- * @var bool Forces fsockopen() to be used for remote files instead
- * of cURL, even if a new enough version is installed
- * @see SimplePie::force_fsockopen()
- * @access private
- */
- public $force_fsockopen = false;
- /**
- * @var bool Force the given data/URL to be treated as a feed no matter what
- * it appears like
- * @see SimplePie::force_feed()
- * @access private
- */
- public $force_feed = false;
- /**
- * @var bool Enable/Disable XML dump
- * @see SimplePie::enable_xml_dump()
- * @access private
- */
- public $xml_dump = false;
- /**
- * @var bool Enable/Disable Caching
- * @see SimplePie::enable_cache()
- * @access private
- */
- public $cache = true;
- /**
- * @var int Cache duration (in seconds)
- * @see SimplePie::set_cache_duration()
- * @access private
- */
- public $cache_duration = 3600;
- /**
- * @var int Auto-discovery cache duration (in seconds)
- * @see SimplePie::set_autodiscovery_cache_duration()
- * @access private
- */
- public $autodiscovery_cache_duration = 604800; // 7 Days.
- /**
- * @var string Cache location (relative to executing script)
- * @see SimplePie::set_cache_location()
- * @access private
- */
- public $cache_location = './cache';
- /**
- * @var string Function that creates the cache filename
- * @see SimplePie::set_cache_name_function()
- * @access private
- */
- public $cache_name_function = 'md5';
- /**
- * @var bool Reorder feed by date descending
- * @see SimplePie::enable_order_by_date()
- * @access private
- */
- public $order_by_date = true;
- /**
- * @var mixed Force input encoding to be set to the follow value
- * (false, or anything type-cast to false, disables this feature)
- * @see SimplePie::set_input_encoding()
- * @access private
- */
- public $input_encoding = false;
- /**
- * @var int Feed Autodiscovery Level
- * @see SimplePie::set_autodiscovery_level()
- * @access private
- */
- public $autodiscovery = SIMPLEPIE_LOCATOR_ALL;
- /**
- * @var string Class used for caching feeds
- * @see SimplePie::set_cache_class()
- * @access private
- */
- public $cache_class = 'SimplePie_Cache';
- /**
- * @var string Class used for locating feeds
- * @see SimplePie::set_locator_class()
- * @access private
- */
- public $locator_class = 'SimplePie_Locator';
- /**
- * @var string Class used for parsing feeds
- * @see SimplePie::set_parser_class()
- * @access private
- */
- public $parser_class = 'SimplePie_Parser';
- /**
- * @var string Class used for fetching feeds
- * @see SimplePie::set_file_class()
- * @access private
- */
- public $file_class = 'SimplePie_File';
- /**
- * @var string Class used for items
- * @see SimplePie::set_item_class()
- * @access private
- */
- public $item_class = 'SimplePie_Item';
- /**
- * @var string Class used for authors
- * @see SimplePie::set_author_class()
- * @access private
- */
- public $author_class = 'SimplePie_Author';
- /**
- * @var string Class used for categories
- * @see SimplePie::set_category_class()
- * @access private
- */
- public $category_class = 'SimplePie_Category';
- /**
- * @var string Class used for enclosures
- * @see SimplePie::set_enclosures_class()
- * @access private
- */
- public $enclosure_class = 'SimplePie_Enclosure';
- /**
- * @var string Class used for Media RSS <media:text> captions
- * @see SimplePie::set_caption_class()
- * @access private
- */
- public $caption_class = 'SimplePie_Caption';
- /**
- * @var string Class used for Media RSS <media:copyright>
- * @see SimplePie::set_copyright_class()
- * @access private
- */
- public $copyright_class = 'SimplePie_Copyright';
- /**
- * @var string Class used for Media RSS <media:credit>
- * @see SimplePie::set_credit_class()
- * @access private
- */
- public $credit_class = 'SimplePie_Credit';
- /**
- * @var string Class used for Media RSS <media:rating>
- * @see SimplePie::set_rating_class()
- * @access private
- */
- public $rating_class = 'SimplePie_Rating';
- /**
- * @var string Class used for Media RSS <media:restriction>
- * @see SimplePie::set_restriction_class()
- * @access private
- */
- public $restriction_class = 'SimplePie_Restriction';
- /**
- * @var string Class used for content-type sniffing
- * @see SimplePie::set_content_type_sniffer_class()
- * @access private
- */
- public $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer';
- /**
- * @var string Class used for item sources.
- * @see SimplePie::set_source_class()
- * @access private
- */
- public $source_class = 'SimplePie_Source';
- /**
- * @var int Maximum number of feeds to check with autodiscovery
- * @see SimplePie::set_max_checked_feeds()
- * @access private
- */
- public $max_checked_feeds = 10;
- /**
- * @var array All the feeds found during the autodiscovery process
- * @see SimplePie::get_all_discovered_feeds()
- * @access private
- */
- public $all_discovered_feeds = array();
- /**
- * @var string Web-accessible path to the handler_image.php file.
- * @see SimplePie::set_image_handler()
- * @access private
- */
- public $image_handler = '';
- /**
- * @var array Stores the URLs when multiple feeds are being initialized.
- * @see SimplePie::set_feed_url()
- * @access private
- */
- public $multifeed_url = array();
- /**
- * @var array Stores SimplePie objects when multiple feeds initialized.
- * @access private
- */
- public $multifeed_objects = array();
- /**
- * @var array Stores the get_object_vars() array for use with multifeeds.
- * @see SimplePie::set_feed_url()
- * @access private
- */
- public $config_settings = null;
- /**
- * @var integer Stores the number of items to return per-feed with multifeeds.
- * @see SimplePie::set_item_limit()
- * @access private
- */
- public $item_limit = 0;
- /**
- * @var array Stores the default attributes to be stripped by strip_attributes().
- * @see SimplePie::strip_attributes()
- * @access private
- */
- public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
- /**
- * @var array Stores the default tags to be stripped by strip_htmltags().
- * @see SimplePie::strip_htmltags()
- * @access private
- */
- public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
- /**
- * The SimplePie class contains feed level data and options
- *
- * There are two ways that you can create a new SimplePie object. The first
- * is by passing a feed URL as a parameter to the SimplePie constructor
- * (as well as optionally setting the cache location and cache expiry). This
- * will initialise the whole feed with all of the default settings, and you
- * can begin accessing methods and properties immediately.
- *
- * The second way is to create the SimplePie object with no parameters
- * at all. This will enable you to set configuration options. After setting
- * them, you must initialise the feed using $feed->init(). At that point the
- * object's methods and properties will be available to you. This format is
- * what is used throughout this documentation.
- *
- * @access public
- * @since 1.0 Preview Release
- */
- public function __construct()
- {
- if (version_compare(PHP_VERSION, '5.0', '<'))
- {
- trigger_error('PHP 4.x is no longer supported. Please upgrade to PHP 5.2 or newer.');
- die();
- }
- // Other objects, instances created here so we can set options on them
- $this->sanitize = new SimplePie_Sanitize();
- if (func_num_args() > 0)
- {
- trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly.');
- }
- }
- /**
- * Used for converting object to a string
- */
- public function __toString()
- {
- return md5(serialize($this->data));
- }
- /**
- * Remove items that link back to this before destroying this object
- */
- public function __destruct()
- {
- if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
- {
- if (!empty($this->data['items']))
- {
- foreach ($this->data['items'] as $item)
- {
- $item->__destruct();
- }
- unset($item, $this->data['items']);
- }
- if (!empty($this->data['ordered_items']))
- {
- foreach ($this->data['ordered_items'] as $item)
- {
- $item->__destruct();
- }
- unset($item, $this->data['ordered_items']);
- }
- }
- }
- /**
- * Force the given data/URL to be treated as a feed no matter what it
- * appears like
- *
- * @access public
- * @since 1.1
- * @param bool $enable Force the given data/URL to be treated as a feed
- */
- public function force_feed($enable = false)
- {
- $this->force_feed = (bool) $enable;
- }
- /**
- * This is the URL of the feed you want to parse.
- *
- * This allows you to enter the URL of the feed you want to parse, or the
- * website you want to try to use auto-discovery on. This takes priority
- * over any set raw data.
- *
- * You can set multiple feeds to mash together by passing an array instead
- * of a string for the $url. Remember that with each additional feed comes
- * additional processing and resources.
- *
- * @access public
- * @since 1.0 Preview Release
- * @param mixed $url This is the URL (or array of URLs) that you want to parse.
- * @see SimplePie::set_raw_data()
- */
- public function set_feed_url($url)
- {
- if (is_array($url))
- {
- $this->multifeed_url = array();
- foreach ($url as $value)
- {
- $this->multifeed_url[] = SimplePie_Misc::fix_protocol($value, 1);
- }
- }
- else
- {
- $this->feed_url = SimplePie_Misc::fix_protocol($url, 1);
- }
- }
- /**
- * Provides an instance of SimplePie_File to use as a feed
- *
- * @access public
- * @param object &$file Instance of SimplePie_File (or subclass)
- * @return bool True on success, false on failure
- */
- public function set_file(&$file)
- {
- if (is_a($file, 'SimplePie_File'))
- {
- $this->feed_url = $file->url;
- $this->file =& $file;
- return true;
- }
- return false;
- }
- /**
- * Allows you to use a string of RSS/Atom data instead of a remote feed.
- *
- * If you have a feed available as a string in PHP, you can tell SimplePie
- * to parse that data string instead of a remote feed. Any set feed URL
- * takes precedence.
- *
- * @access public
- * @since 1.0 Beta 3
- * @param string $data RSS or Atom data as a string.
- * @see SimplePie::set_feed_url()
- */
- public function set_raw_data($data)
- {
- $this->raw_data = $data;
- }
- /**
- * Allows you to override the default timeout for fetching remote feeds.
- *
- * This allows you to change the maximum time the feed's server to respond
- * and send the feed back.
- *
- * @access public
- * @since 1.0 Beta 3
- * @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed.
- */
- public function set_timeout($timeout = 10)
- {
- $this->timeout = (int) $timeout;
- }
- /**
- * Forces SimplePie to use fsockopen() instead of the preferred cURL
- * functions.
- *
- * @access public
- * @since 1.0 Beta 3
- * @param bool $enable Force fsockopen() to be used
- */
- public function force_fsockopen($enable = false)
- {
- $this->force_fsockopen = (bool) $enable;
- }
- /**
- * Enables/disables caching in SimplePie.
- *
- * This option allows you to disable caching all-together in SimplePie.
- * However, disabling the cache can lead to longer load times.
- *
- * @access public
- * @since 1.0 Preview Release
- * @param bool $enable Enable caching
- */
- public function enable_cache($enable = true)
- {
- $this->cache = (bool) $enable;
- }
- /**
- * Set the length of time (in seconds) that the contents of a feed
- * will be cached.
- *
- * @access public
- * @param int $seconds The feed content cache duration.
- */
- public function set_cache_duration($seconds = 3600)
- {
- $this->cache_duration = (int) $seconds;
- }
- /**
- * Set the length of time (in seconds) that the autodiscovered feed
- * URL will be cached.
- *
- * @access public
- * @param int $seconds The autodiscovered feed URL cache duration.
- */
- public function set_autodiscovery_cache_duration($seconds = 604800)
- {
- $this->autodiscovery_cache_duration = (int) $seconds;
- }
- /**
- * Set the file system location where the cached files should be stored.
- *
- * @access public
- * @param string $location The file system location.
- */
- public function set_cache_location($location = './cache')
- {
- $this->cache_location = (string) $location;
- }
- /**
- * Determines whether feed items should be sorted into reverse chronological order.
- *
- * @access public
- * @param bool $enable Sort as reverse chronological order.
- */
- public function enable_order_by_date($enable = true)
- {
- $this->order_by_date = (bool) $enable;
- }
- /**
- * Allows you to override the character encoding reported by the feed.
- *
- * @access public
- * @param string $encoding Character encoding.
- */
- public function set_input_encoding($encoding = false)
- {
- if ($encoding)
- {
- $this->input_encoding = (string) $encoding;
- }
- else
- {
- $this->input_encoding = false;
- }
- }
- /**
- * Set how much feed autodiscovery to do
- *
- * @access public
- * @see SIMPLEPIE_LOCATOR_NONE
- * @see SIMPLEPIE_LOCATOR_AUTODISCOVERY
- * @see SIMPLEPIE_LOCATOR_LOCAL_EXTENSION
- * @see SIMPLEPIE_LOCATOR_LOCAL_BODY
- * @see SIMPLEPIE_LOCATOR_REMOTE_EXTENSION
- * @see SIMPLEPIE_LOCATOR_REMOTE_BODY
- * @see SIMPLEPIE_LOCATOR_ALL
- * @param int $level Feed Autodiscovery Level (level can be a
- * combination of the above constants, see bitwise OR operator)
- */
- public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL)
- {
- $this->autodiscovery = (int) $level;
- }
- /**
- * Allows you to change which class SimplePie uses for caching.
- * Useful when you are overloading or extending SimplePie's default classes.
- *
- …
Large files files are truncated, but you can click here to view the full file