Author: roidelapluie Date: 2008-08-18 23:32:08 +0200 (Mon, 18 Aug 2008) New Revision: 10259
Added: www-website/planet/ www-website/planet/LICENSE www-website/planet/VERSION www-website/planet/app/ www-website/planet/app/classes/ www-website/planet/app/classes/Planet.class.php www-website/planet/app/lib/ www-website/planet/app/lib/Cache.php www-website/planet/app/lib/Duration.php www-website/planet/app/lib/lib.String.php www-website/planet/app/lib/lib.http.php www-website/planet/app/lib/lib.opml.php www-website/planet/app/lib/simplepie/ www-website/planet/app/lib/simplepie/LGPL.txt www-website/planet/app/lib/simplepie/README.txt www-website/planet/app/lib/simplepie/simplepie.inc www-website/planet/app/lib/spyc-0.2.3/ www-website/planet/app/lib/spyc-0.2.3/spyc.php www-website/planet/cache/ www-website/planet/custom/ www-website/planet/custom/config.yml www-website/planet/custom/img/ www-website/planet/custom/img/feed.png www-website/planet/custom/img/gajim.png www-website/planet/custom/people.opml www-website/planet/custom/style/ www-website/planet/custom/style/dark.css www-website/planet/custom/style/default.css www-website/planet/custom/style/light.css www-website/planet/custom/tpl/ www-website/planet/custom/tpl/atom10.tpl.php www-website/planet/custom/tpl/cheese.tpl.php www-website/planet/custom/tpl/footer.tpl.php www-website/planet/custom/tpl/head.tpl.php www-website/planet/custom/tpl/index.tpl.php www-website/planet/custom/tpl/rss10.tpl.php www-website/planet/custom/tpl/sidebar.tpl.php www-website/planet/custom/tpl/top.tpl.php www-website/planet/gajim.png www-website/planet/index.php Log: Test: add a planet
Added: www-website/planet/LICENSE =================================================================== --- www-website/planet/LICENSE (rev 0) +++ www-website/planet/LICENSE 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,31 @@ +Copyright (c) 2006, Maurice Svay +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 Maurice Svay 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 OWNER +OR 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. + +Contributors: +Fran�ois Granger +Pep, http://www.callmepep.org/ \ No newline at end of file
Added: www-website/planet/VERSION =================================================================== --- www-website/planet/VERSION (rev 0) +++ www-website/planet/VERSION 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1 @@ +moonmoon-0.2-beta \ No newline at end of file
Added: www-website/planet/app/classes/Planet.class.php =================================================================== --- www-website/planet/app/classes/Planet.class.php (rev 0) +++ www-website/planet/app/classes/Planet.class.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,314 @@ +<?php +/* +Copyright (c) 2006, Maurice Svay +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 Maurice Svay 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 OWNER +OR 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. +*/ + +include_once(dirname(__FILE__).'/../lib/simplepie/simplepie.inc'); +include_once(dirname(__FILE__).'/../lib/lib.String.php'); +include_once(dirname(__FILE__).'/../lib/spyc-0.2.3/spyc.php'); + +/** + * Planet configuration class + */ +class PlanetConfig{ + var $conf; + + function PlanetConfig($array){ + $defaultConfig = Array( + 'url' => 'http://www.example.com/', + 'name' => '', + 'items' => 10, + 'shuffle' => 0, + 'refresh' => 240, + 'cache' => 10, + 'nohtml' => 0, + 'postmaxlength' => 0 + ); + + //User config + $this->conf = $array; + + //Complete config with default config + foreach ($defaultConfig as $key => $value){ + if (!isset($this->conf[$key])){ + $this->conf[$key] = $value; + } + } + } + + function getUrl(){ + return $this->conf['url']; + } + + function getName(){ + return $this->conf['name']; + } + + function setName($name){ + $this->conf['name'] = $name; + } + + function getCacheTimeout(){ + return $this->conf['refresh']; + } + + function getOutputTimeout(){ + return $this->conf['cache']; + } + + function getShuffle(){ + return $this->conf['shuffle']; + } + + function getMaxDisplay(){ + return $this->conf['items']; + } + + function getNoHTML(){ + return $this->conf['nohtml']; + } + + function getPostMaxLength(){ + return $this->conf['postmaxlength']; + } + + function toYaml(){ + return Spyc::YAMLDump($this->conf,4); + } +} + +/** + * Planet person + */ +class PlanetPerson{ + var $name; + var $feed; + var $website; + + function PlanetPerson($name, $feed, $website){ + $this->name = $name; + $this->feed = $feed; + $this->website = $website; + } + + function getFeed(){ + return $this->feed; + } + + function getName(){ + return $this->name; + } + + function getWebsite(){ + return $this->website; + } + + function compare($person1, $person2){ + return strcasecmp($person1->name, $person2->name); + } +} + +/** + * Planet item + */ +class PlanetItem{ + var $url; + var $title; + var $date; + var $author; + var $content; + var $owner; + + function PlanetItem($url, $title, $date, $author, $content, &$owner){ + $this->url = $url; + $this->title = $title; + $this->date = $date; + $this->author = $author; + $this->content = $content; + $this->owner = $owner; + } + + /** + * Returns item permalink + * @return string Item permalink (URL) + */ + function getUrl(){ + return $this->url; + } + + /** + * Returns item title + * @return string Item title + */ + function getTitle(){ + return $this->title; + } + + /** + * Returns item date as timestamp + * @return int Item date timestamp + */ + function getDate(){ + return $this->date; + } + + /** + * Returns item author name + * @return string Item author name + */ + function getAuthor(){ + return $this->author; + } + + /** + * Returns item content + * @return string Item content + */ + function getContent(){ + return $this->content; + } + + /** + * Return item owner + * @return PlanetPerson Item owner + */ + function getOwner(){ + return $this->owner; + } + + function compare($item1, $item2){ + if ($item1->date == $item2->date){ + return 0; + } + else if ($item1->date < $item2->date){ + return 1; + } + return -1; + } +} + +/** + * Planet, main app class + */ +class Planet{ + var $config; + var $items; + var $people; + var $simplepie; + + function Planet($config=null){ + if ($config == null){ + $this->config = new PlanetConfig(); + } + else{ + $this->config = $config; + } + } + + /** + * Adds a person to the planet + * @param PlanetPerson person + */ + function addPerson(&$person){ + $this->people[] = $person; + } + + /** + * Load feeds + */ + /**/ + function loadFeeds(){ + foreach ($this->people as $person){ + $this->simplepie = new SimplePie(); + $this->simplepie->feed_url($person->getFeed()); + $this->simplepie->cache_max_minutes($this->config->getCacheTimeout()+rand(0,30)); //add some random to avoid mass download + $this->simplepie->init(); + if (($this->simplepie->data) && ($this->simplepie->get_item_quantity() > 0)){ + $items = $this->simplepie->get_items(); + foreach ($items as $item) { + $content = ''; + $item_authors = $item->get_authors(); + $authors = Array(); + if (is_array($item_authors)){ + foreach ($item_authors as $author){ + if (trim($author->get_name()) != ''){ + $authors[] = $author->get_name(); + }else{ + $authors[] = $person->getName(); + } + } + } + else{ + $authors[] = $person->getName(); + } + + //Strip HTML + if ($this->config->getNoHTML() == 1){ + $content = strip_tags($item->get_description()); + }else{ + $content = $item->get_description(); + } + + //Truncate content + if ($this->config->getPostMaxLength() > 0){ + $content = smarty_modifier_html_substr( + $content, + $this->config->getPostMaxLength(), + '…' + ); + } + + $this->items[] = new PlanetItem( + $item->get_permalink(), + $item->get_title(), + $item->get_date('U'), + implode(',',$authors), + $content, + $person + ); + } + } + unset($this->simplepie); + } + usort($this->items, array('PlanetItem','compare')); + } + + /** + * Returns feed items + */ + function getItems(){ + return $this->items; + } + + function getPeople(){ + return $this->people; + } +} + +?> \ No newline at end of file
Added: www-website/planet/app/lib/Cache.php =================================================================== --- www-website/planet/app/lib/Cache.php (rev 0) +++ www-website/planet/app/lib/Cache.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,254 @@ +<?php +/** +* This library is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this software; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* � Copyright 2005 Richard Heyes +*/ + +/** +* Caching Libraries for PHP5 +* +* Handles data and output caching. Defaults to /dev/shm +* (shared memory). All methods are static. +* +* Eg: (output caching) +* +* if (!OutputCache::Start('group', 'unique id', 600)) { +* +* // ... Output +* +* OutputCache::End(); +* } +* +* Eg: (data caching) +* +* if (!$data = DataCache::Get('group', 'unique id')) { +* +* $data = time(); +* +* DataCache::Put('group', 'unique id', 10, $data); +* } +* +* echo $data; +*/ + class Cache + { + /** + * Whether caching is enabled + * @var bool + */ + public static $enabled = true; + + /** + * Place to store the cache files + * @var string + */ + protected static $store = '/dev/shm/'; + + /** + * Prefix to use on cache files + * @var string + */ + protected static $prefix = 'cache_'; + + /** + * Stores data + * + * @param string $group Group to store data under + * @param string $id Unique ID of this data + * @param int $ttl How long to cache for (in seconds) + */ + protected static function write($group, $id, $ttl, $data) + { + $filename = self::getFilename($group, $id); + + if ($fp = fopen($filename, 'xb')) { + + if (flock($fp, LOCK_EX)) { + fwrite($fp, $data); + } + fclose($fp); + + // Set filemtime + touch($filename, time() + $ttl); + } + } + + /** + * Reads data + * + * @param string $group Group to store data under + * @param string $id Unique ID of this data + */ + protected static function read($group, $id) + { + $filename = self::getFilename($group, $id); + + return file_get_contents($filename); + } + + /** + * Determines if an entry is cached + * + * @param string $group Group to store data under + * @param string $id Unique ID of this data + */ + protected static function isCached($group, $id) + { + $filename = self::getFilename($group, $id); + + if (self::$enabled && file_exists($filename) && filemtime($filename) > time()) { + return true; + } + + @unlink($filename); + + return false; + } + + /** + * Builds a filename/path from group, id and + * store. + * + * @param string $group Group to store data under + * @param string $id Unique ID of this data + */ + protected static function getFilename($group, $id) + { + $id = md5($id); + + return self::$store . self::$prefix . "{$group}_{$id}"; + } + + /** + * Sets the filename prefix to use + * + * @param string $prefix Filename Prefix to use + */ + public static function setPrefix($prefix) + { + self::$prefix = $prefix; + } + + /** + * Sets the store for cache files. Defaults to + * /dev/shm. Must have trailing slash. + * + * @param string $store The dir to store the cache data in + */ + public static function setStore($store) + { + self::$store = $store; + } + } + + /** + * Output Cache extension of base caching class + */ + class OutputCache extends Cache + { + /** + * Group of currently being recorded data + * @var string + */ + private static $group; + + /** + * ID of currently being recorded data + * @var string + */ + private static $id; + + /** + * Ttl of currently being recorded data + * @var int + */ + private static $ttl; + + /** + * Starts caching off. Returns true if cached, and dumps + * the output. False if not cached and start output buffering. + * + * @param string $group Group to store data under + * @param string $id Unique ID of this data + * @param int $ttl How long to cache for (in seconds) + * @return bool True if cached, false if not + */ + public static function Start($group, $id, $ttl) + { + if (self::isCached($group, $id)) { + echo self::read($group, $id); + return true; + + } else { + + ob_start(); + + self::$group = $group; + self::$id = $id; + self::$ttl = $ttl; + + return false; + } + } + + /** + * Ends caching. Writes data to disk. + */ + public static function End() + { + $data = ob_get_contents(); + ob_end_flush(); + + self::write(self::$group, self::$id, self::$ttl, $data); + } + } + + /** + * Data cache extension of base caching class + */ + class DataCache extends Cache + { + + /** + * Retrieves data from the cache + * + * @param string $group Group this data belongs to + * @param string $id Unique ID of the data + * @return mixed Either the resulting data, or null + */ + public static function Get($group, $id) + { + if (self::isCached($group, $id)) { + return unserialize(self::read($group, $id)); + } + + return null; + } + + /** + * Stores data in the cache + * + * @param string $group Group this data belongs to + * @param string $id Unique ID of the data + * @param int $ttl How long to cache for (in seconds) + * @param mixed $data The data to store + */ + public static function Put($group, $id, $ttl, $data) + { + self::write($group, $id, $ttl, serialize($data)); + } + } +?> \ No newline at end of file
Added: www-website/planet/app/lib/Duration.php =================================================================== --- www-website/planet/app/lib/Duration.php (rev 0) +++ www-website/planet/app/lib/Duration.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,114 @@ +<?php +/** + * A class for making time periods readable. + * + * This class allows for the conversion of an integer + * number of seconds into a readable string. + * For example, '121' into '2 minutes, 1 second'. + * + * If an array is passed to the class, the associative + * keys are used for the names of the time segments. + * For example, array('seconds' => 12, 'minutes' => 1) + * into '1 minute, 12 seconds'. + * + * This class is plural aware. Time segments with values + * other than 1 will have an 's' appended. + * For example, '1 second' not '1 seconds'. + * + * @author Aidan Lister <aidan@php.net> + * @version 1.2.1 + * @link http://aidanlister.com/repos/v/Duration.php + */ +class Duration +{ + /** + * All in one method + * + * @param int|array $duration Array of time segments or a number of seconds + * @return string + */ + function toString ($duration, $periods = null) + { + if (!is_array($duration)) { + $duration = Duration::int2array($duration, $periods); + } + + return Duration::array2string($duration); + } + + + /** + * Return an array of date segments. + * + * @param int $seconds Number of seconds to be parsed + * @return mixed An array containing named segments + */ + function int2array ($seconds, $periods = null) + { + // Define time periods + if (!is_array($periods)) { + $periods = array ( + 'years' => 31556926, + 'months' => 2629743, + 'weeks' => 604800, + 'days' => 86400, + 'hours' => 3600, + 'minutes' => 60, + 'seconds' => 1 + ); + } + + // Loop + $seconds = (float) $seconds; + foreach ($periods as $period => $value) { + $count = floor($seconds / $value); + + if ($count == 0) { + continue; + } + + $values[$period] = $count; + $seconds = $seconds % $value; + } + + // Return + if (empty($values)) { + $values = null; + } + + return $values; + } + + + /** + * Return a string of time periods. + * + * @package Duration + * @param mixed $duration An array of named segments + * @return string + */ + function array2string ($duration) + { + if (!is_array($duration)) { + return false; + } + + foreach ($duration as $key => $value) { + $segment_name = substr($key, 0, -1); + $segment = $value . ' ' . $segment_name; + + // Plural + if ($value != 1) { + $segment .= 's'; + } + + $array[] = $segment; + } + + $str = implode(', ', $array); + return $str; + } + +} + +?> \ No newline at end of file
Added: www-website/planet/app/lib/lib.String.php =================================================================== --- www-website/planet/app/lib/lib.String.php (rev 0) +++ www-website/planet/app/lib/lib.String.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,134 @@ +<?php +/* +* Smarty plugin +* +------------------------------------------------------------- +* File: modifier.html_substr.php +* Type: modifier +* Name: html_substr +* Version: 1.0 +* Date: June 19th, 2003 +* Purpose: Cut a string preserving any tag nesting and matching. +* Install: Drop into the plugin directory. +* Author: Original Javascript Code: Benjamin Lupu <lupufr@aol.com> +* Translation to PHP & Smarty: Edward Dale <scompt@scompt.com> +* Modification to add a string: Sebastian Kuhlmann <sebastiankuhlmann@web.de> +* +------------------------------------------------------------- +*/ +function smarty_modifier_html_substr($string, $length, $addstring="") +{ + $addstring = " " . $addstring; + + if (strlen($string) > $length) { + if( !empty( $string ) && $length>0 ) { + $addtext = false; + $isText = true; + $ret = ""; + $i = 0; + + $currentChar = ""; + $lastSpacePosition = -1; + $lastChar = ""; + + $tagsArray = array(); + $currentTag = ""; + $tagLevel = 0; + + $noTagLength = strlen( strip_tags( $string ) ); + + // Parser loop + for( $j=0; $j<strlen( $string ); $j++ ) { + + $currentChar = substr( $string, $j, 1 ); + $ret .= $currentChar; + + // Lesser than event + if( $currentChar == "<") $isText = false; + + // Character handler + if( $isText ) { + + // Memorize last space position + if( $currentChar == " " ) { $lastSpacePosition = $j; } + else { $lastChar = $currentChar; } + + $i++; + } else { + $currentTag .= $currentChar; + } + + // Greater than event + if( $currentChar == ">" ) { + $isText = true; + + // Opening tag handler + if( ( strpos( $currentTag, "<" ) !== FALSE ) && + ( strpos( $currentTag, "/>" ) === FALSE ) && + ( strpos( $currentTag, "</") === FALSE ) ) { + + // Tag has attribute(s) + if( strpos( $currentTag, " " ) !== FALSE ) { + $currentTag = substr( $currentTag, 1, strpos( $currentTag, " " ) - 1 ); + } else { + // Tag doesn't have attribute(s) + $currentTag = substr( $currentTag, 1, -1 ); + } + + array_push( $tagsArray, $currentTag ); + + } else if( strpos( $currentTag, "</" ) !== FALSE ) { + array_pop( $tagsArray ); + } + + $currentTag = ""; + } + + if( $i >= $length) { + $addtext = true; + break; + } + } + + // Cut HTML string at last space position + if( $length < $noTagLength ) { + if( $lastSpacePosition != -1 ) { + $ret = substr( $string, 0, $lastSpacePosition ); + } else { + $ret = substr( $string, 0, $j ); + } + } + + // Close broken XHTML elements + while( sizeof( $tagsArray ) != 0 ) { + $aTag = array_pop( $tagsArray ); + $ret .= "</" . $aTag . ">\n"; + } + + } else { + $ret = ""; + } + + // only add string if text was cut + if ( $addtext ) { + return( $ret.$addstring ); + } + else { + return ( $ret ); + } + } else { + return ( $string ); + } +} + +//truncate a string +function string_truncate($string, $length){ + if (strlen($string) < $length){ + return $string; + } + else{ + return substr($string, 0, $length)."…"; + } +} + +?> \ No newline at end of file
Added: www-website/planet/app/lib/lib.http.php =================================================================== --- www-website/planet/app/lib/lib.http.php (rev 0) +++ www-website/planet/app/lib/lib.http.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,21 @@ +<?php +/** + * Send HTTP 304 when needed, set ETag and Last-Modified else + * Source : http://annevankesteren.nl/2005/05/http-304 + */ +function http_modified($last_modified, $identifier){ + $etag = '"'.md5($last_modified.$identifier).'"'; + $client_etag = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false; + $client_last_modified = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? trim($_SERVER['HTTP_IF_MODIFIED_SINCE']) : 0; + $client_last_modified_timestamp = strtotime($client_last_modified); + $last_modified_timestamp = strtotime($last_modified); + + if(($client_last_modified && $client_etag) ? (($client_last_modified_timestamp == $last_modified_timestamp) && ($client_etag == $etag)) : (($client_last_modified_timestamp == $last_modified_timestamp) || ($client_etag == $etag))){ + header('Not Modified',true,304); + exit(); + }else{ + header('Last-Modified:'.$last_modified); + header('ETag:'.$etag); + } +} +?> \ No newline at end of file
Added: www-website/planet/app/lib/lib.opml.php =================================================================== --- www-website/planet/app/lib/lib.opml.php (rev 0) +++ www-website/planet/app/lib/lib.opml.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,90 @@ +<?php +class opml +{ + var $_xml = null; + var $_currentTag = ''; + + var $title = ''; + var $entries = array(); + var $map = + array( + 'URL' => 'website', + 'HTMLURL' => 'website', + 'TEXT' => 'name', + 'TITLE' => 'name', + 'XMLURL' => 'feed', + 'DESCRIPTION' => 'description' + ); + + + function parse($data) + { + $this->_xml = xml_parser_create('UTF-8'); + //xml_parser_set_option($this->_xml, XML_OPTION_CASE_FOLDING, false); + //xml_parser_set_option($this->_xml, XML_OPTION_SKIP_WHITE, true); + xml_set_object($this->_xml, $this); + xml_set_element_handler($this->_xml,'_openTag','_closeTag'); + xml_set_character_data_handler ($this->_xml, '_cData'); + + xml_parse($this->_xml,$data); + xml_parser_free($this->_xml); + return $this->entries; + } + + + function _openTag($p,$tag,$attrs) + { + $this->_currentTag = $tag; + + if ($tag == 'OUTLINE') + { + $i = count($this->entries); + foreach (array_keys($this->map) as $key) + { + if (isset($attrs[$key])) { + $this->entries[$i][$this->map[$key]] = $attrs[$key]; + } + } + } + } + + function _closeTag($p, $tag){ + $this->_currentTag = ''; + } + + function _cData($p, $cdata){ + if ($this->_currentTag == 'TITLE'){ + $this->title = $cdata; + } + } + + function getTitle(){ + return $this->title; + } + + function getPeople(){ + return $this->entries; + } +} + +class opmlImporter +{ + function load($file) + { + if (@file_exists($file)) + { + $opml = new opml(); + + //Remove BOM if needed + $BOM = '/^/'; + $fileContent = file_get_contents($file); + $fileContent = preg_replace($BOM, '', $fileContent, 1); + + //Parse + $opml->parse($fileContent); + + return $opml; + } + } +} +?>
Added: www-website/planet/app/lib/simplepie/LGPL.txt =================================================================== --- www-website/planet/app/lib/simplepie/LGPL.txt (rev 0) +++ www-website/planet/app/lib/simplepie/LGPL.txt 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + <one line to give the library's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + <signature of Ty Coon>, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + +
Added: www-website/planet/app/lib/simplepie/README.txt =================================================================== --- www-website/planet/app/lib/simplepie/README.txt (rev 0) +++ www-website/planet/app/lib/simplepie/README.txt 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,34 @@ +************************************************************ +SIMPLEPIE 1.0 BETA 3 +http://simplepie.org + +By Ryan Parman and Geoffrey Sneddon +A product of Skyzyx Technologies + + +************************************************************ +LICENSE: + +GNU Lesser General Public License 2.1 (LGPL) +http://creativecommons.org/licenses/LGPL/2.1/ +************************************************************ + + +TO START THE DEMO: +1) Upload this package to your webserver. +2) Make sure that the cache folder inside of the demo folder is server-writable. +3) Navigate your browser to the demo folder. + + +************************************************************ +SUPPORT: + +For further setup and install documentation, function references, etc., visit: +http://simplepie.org/docs/ + +For bug reports, feature requests and other support, visit: +http://simplepie.org/support/ + +For more insight on SimplePie development, visit: +http://simplepie.org/blog/ +************************************************************
Added: www-website/planet/app/lib/simplepie/simplepie.inc =================================================================== --- www-website/planet/app/lib/simplepie/simplepie.inc (rev 0) +++ www-website/planet/app/lib/simplepie/simplepie.inc 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,5449 @@ +<?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: 24 November 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 = '1.0 b3.2'; + var $build = '20061124'; + 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 $timeout = 10; + 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; + var $cache_class = 'SimplePie_Cache'; + var $locator_class = 'SimplePie_Locator'; + var $parser_class = 'SimplePie_Parser'; + var $file_class = 'SimplePie_File'; + var $force_fsockopen = false; + var $cache_name_type = 'sha1'; + + // Misc. variables + var $data; + var $error; + + function SimplePie($feed_url = null, $cache_location = null, $cache_max_minutes = null) + { + // Couple of variables built up from other variables + $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; + + // Set options if they're passed to the constructor + 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); + } + + // Only init the script if we're passed a feed URL + 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 set_timeout($timeout = 10) + { + $this->timeout = (int) $timeout; + } + + function set_raw_data($data) + { + $this->raw_data = trim((string) $data); + } + + 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 set_cache_class($class = 'SimplePie_Cache') + { + if (SimplePie_Misc::is_a_class($class, 'SimplePie_Cache')) + { + $this->cache_class = $class; + return true; + } + return false; + } + + function set_locator_class($class = 'SimplePie_Locator') + { + if (SimplePie_Misc::is_a_class($class, 'SimplePie_Locator')) + { + $this->locator_class = $class; + return true; + } + return false; + } + + function set_parser_class($class = 'SimplePie_Parser') + { + if (SimplePie_Misc::is_a_class($class, 'SimplePie_Parser')) + { + $this->parser_class = $class; + return true; + } + return false; + } + + function set_file_class($class = 'SimplePie_File') + { + if (SimplePie_Misc::is_a_class($class, 'SimplePie_File')) + { + $this->file_class = $class; + return true; + } + return false; + } + + function set_sanitize_class($object = 'SimplePie_Sanitize') + { + if (class_exists($object)) + { + $this->sanitize = new $object; + return true; + } + return false; + } + + function set_useragent($ua) + { + $this->useragent = (string) $ua; + } + + function force_fsockopen($enable = false) + { + $this->force_fsockopen = (bool) $enable; + } + + function set_cache_name_type($type = 'sha1') + { + $type = strtolower(trim($type)); + switch ($type) + { + case 'crc32': + $this->cache_name_type = 'crc32'; + break; + + case 'md5': + $this->cache_name_type = 'md5'; + break; + + case 'rawurlencode': + $this->cache_name_type = 'rawurlencode'; + break; + + case 'urlencode': + $this->cache_name_type = 'urlencode'; + break; + + default: + $this->cache_name_type = 'sha1'; + break; + } + } + + 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 = false) + { + $this->sanitize->strip_ads($enable); + } + + function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'), $encode = null) + { + $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 set_item_class($class = 'SimplePie_Item') + { + return $this->sanitize->set_item_class($class); + } + + function set_author_class($class = 'SimplePie_Author') + { + return $this->sanitize->set_author_class($class); + } + + function set_enclosure_class($class = 'SimplePie_Enclosure') + { + return $this->sanitize->set_enclosure_class($class); + } + + function init() + { + if (!(function_exists('version_compare') && ((version_compare(phpversion(), '4.3.2', '>=') && version_compare(phpversion(), '5', '<')) || version_compare(phpversion(), '5.0.3', '>='))) || !extension_loaded('xml') || !extension_loaded('pcre')) + { + return false; + } + 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('<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>'); +} + +function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) { + if (placeholder != '') { + document.writeln('<embed type="'+type+'" style="cursor:hand; cursor:pointer;" href="'+link+'" src="'+placeholder+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="false" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed>'); + } + else { + document.writeln('<embed type="'+type+'" style="cursor:hand; cursor:pointer;" src="'+link+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="true" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed>'); + } +} + +function embed_flash(bgcolor, width, height, link, loop, type) { + document.writeln('<embed src="'+link+'" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="'+type+'" quality="high" width="'+width+'" height="'+height+'" bgcolor="'+bgcolor+'" loop="'+loop+'"></embed>'); +} + +function embed_wmedia(width, height, link) { + document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>'); +} +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) || !empty($this->raw_data)) + { + $this->data = array(); + $cache = false; + + if (!empty($this->rss_url)) + { + // Decide whether to enable caching + if ($this->enable_cache && preg_match('/^http(s)?:\/\//i', $this->rss_url)) + { + $cache = new $this->cache_class($this->cache_location, call_user_func($this->cache_name_type, $this->rss_url), 'spc'); + } + // If it's enabled and we don't want an XML dump, use the cache + if ($cache && !$this->xml_dump) + { + // Load the Cache + $this->data = $cache->load(); + if (!empty($this->data)) + { + // If we've hit a collision just rerun it with caching disabled + if (isset($this->data['url']) && $this->data['url'] != $this->rss_url) + { + $cache = false; + } + // If we've got a feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL + else if (!empty($this->data['feed_url'])) + { + if ($this->data['feed_url'] == $this->data['url']) + { + $cache->unlink(); + } + else + { + $this->feed_url($this->data['feed_url']); + return $this->init(); + } + } + // If the cache is new enough + else if ($cache->mtime() + $this->max_minutes * 60 < time()) + { + // If we have last-modified and/or etag set + 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 $this->file_class($this->rss_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen); + if ($file->success) + { + $headers = $file->headers(); + if ($headers['status']['code'] == 304) + { + $cache->touch(); + return true; + } + } + else + { + unset($file); + } + } + // If we don't have last-modified or etag set, just clear the cache + else + { + $cache->unlink(); + } + } + // If the cache is still valid, just return true + else + { + return true; + } + } + // If the cache is empty, delete it + else + { + $cache->unlink(); + } + } + $this->data = array(); + // If we don't already have the file (it'll only exist if we've opened it to check if the cache has been modified), open it. + if (!isset($file)) + { + if (is_a($this->file, 'SimplePie_File') && $this->file->url == $this->rss_url) + { + $file =& $this->file; + } + else + { + $file = new $this->file_class($this->rss_url, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen); + } + } + // If the file connection has an error, set SimplePie::error to that and quit + if (!$file->success) + { + $this->error = $file->error; + return false; + } + + // Check if the supplied URL is a feed, if it isn't, look for it. + $locate = new $this->locator_class($file, $this->timeout, $this->useragent); + if (!$locate->is_feed($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); + } + else + { + $data = $this->raw_data; + } + + // 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; + } + + // Change the encoding to UTF-8 (as we always use UTF-8 internally) + $data = SimplePie_Misc::change_encoding($data, $encoding, 'UTF-8'); + + // Strip illegal characters (if on less than PHP5, as on PHP5 expat can manage fine) + if (version_compare(phpversion(), '5', '<')) + { + if (function_exists('iconv')) + { + $data = iconv('UTF-8', 'UTF-8//IGNORE', $data); + } + else if (function_exists('mb_convert_encoding')) + { + $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8'); + } + else + { + $data = SimplePie_Misc::utf8_bad_replace($data); + } + } + + // Start parsing + $data = new $this->parser_class($data, 'UTF-8', $this->xml_dump); + // If we want the XML, just output that and quit + if ($this->xml_dump) + { + header('Content-type: text/xml; charset=UTF-8'); + echo $data->data; + exit; + } + // If it's parsed fine + else if (!$data->error_code) + { + // Parse the data, and make it sane + $this->sanitize->parse_data_array($data->data, $this->rss_url); + unset($data); + // Get the sane data + $this->data['feedinfo'] = $this->sanitize->feedinfo; + unset($this->sanitize->feedinfo); + $this->data['info'] = $this->sanitize->info; + unset($this->sanitize->info); + $this->data['items'] = $this->sanitize->items; + unset($this->sanitize->items); + $this->data['feedinfo']['encoding'] = $this->sanitize->output_encoding; + $this->data['url'] = $this->rss_url; + + // Store the headers that we need + if (!empty($headers['last-modified'])) + { + $this->data['last-modified'] = $headers['last-modified']; + } + if (!empty($headers['etag'])) + { + $this->data['etag'] = $headers['etag']; + } + + // If we want to order it by date, check if all items have a date, and then sort it + if ($this->order_by_date && !empty($this->data['items'])) + { + $do_sort = true; + foreach ($this->data['items'] as $item) + { + if (!$item->get_date('U')) + { + $do_sort = false; + break; + } + } + if ($do_sort) + { + usort($this->data['items'], create_function('$a, $b', 'if ($a->get_date('U') == $b->get_date('U')) return 1; return ($a->get_date('U') < $b->get_date('U')) ? 1 : -1;')); + } + } + + // Cache the file if caching is enabled + 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; + } + // If we have an error, just set SimplePie::error to it and quit + 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 = null) + { + if (!empty($this->data['info']['link']['alternate'][0])) + { + $favicon = SimplePie_Misc::absolutize_url('/favicon.ico', $this->get_feed_link()); + + if ($check) + { + $file = new $this->file_class($favicon, $this->timeout/10, 5, null, $this->useragent, $this->force_fsockopen); + $headers = $file->headers(); + $file->close(); + + if ($headers['status']['code'] == 200) + { + return $favicon; + } + } + else + { + return $favicon; + } + } + if (!is_null($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&rssu...' . 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 ($this->get_item_quantity() > 0) + { + if ($end == 0) + { + return array_slice($this->data['items'], $start); + } + else + { + return array_slice($this->data['items'], $start, $end); + } + } + else + { + return false; + } + } +} + +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($this->data['term'])) + { + $categories = array_merge($categories, $this->data['term']); + } + 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 ($rel == 'alternate') + { + $links = array(); + if (!empty($this->data['link'][$rel])) + { + $links = $this->data['link'][$rel]; + } + if (!empty($this->data['guid']['data']) && $this->data['guid']['permalink'] == true) + { + $links[] = $this->data['guid']['data']; + } + return $links; + } + else 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...' . 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)) + { + if (class_exists('idna_convert')) + { + $idn = new idna_convert; + $this->link = $idn->encode($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 native_embed($options='') + { + return $this->embed($options, true); + } + + function embed($options = '', $native = false) + { + // 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; + } + + $embed = ''; + + // 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) + if (!$native) + { + $embed .= '<script type="text/javascript" src="?js"></script>'; + } + + // Odeo Feed MP3's + if (substr(strtolower($this->get_link()), 0, 15) == 'http://odeo.com') { + if ($native) + { + $embed .= '<embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="440" height="80" wmode="transparent" allowScriptAccess="any" flashvars="valid_sample_rate=true&external_url=' . $this->get_link() . '"></embed>'; + } + else + { + $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; + if ($native) + { + if ($placeholder != "") { + $embed .= "<embed type="$type" style="cursor:hand; cursor:pointer;" href="" . $this->get_link() . "" src="$placeholder" width="$width" height="$height" autoplay="false" target="myself" controller="false" loop="$loop" scale="aspect" bgcolor="$bgcolor" pluginspage="http://www.apple.com/quicktime/download/%5C%22%3E</embed>"; + } + else { + $embed .= "<embed type="$type" style="cursor:hand; cursor:pointer;" src="" . $this->get_link() . "" width="$width+" height="$height" autoplay="false" target="myself" controller="true" loop="$loop" scale="aspect" bgcolor="$bgcolor" pluginspage="http://www.apple.com/quicktime/download/%5C%22%3E</embed>"; + } + } + else + { + $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'))) + { + if ($native) + { + $embed .= "<embed src="" . $this->get_link() . "" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=Shock..." type="$type" quality="high" width="$width" height="$height" bgcolor="$bgcolor" loop="$loop"></embed>"; + } + else + { + $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; + if ($native) + { + $embed .= "<embed type="application/x-mplayer2" src="" . $this->get_link() . "" autosize="1" width="$width" height="$height" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>"; + } + else + { + $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, $force_fsockopen = false) + { + 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.5', '>=') && !$force_fsockopen) + { + $this->method = 'curl'; + $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_HTTPHEADER, $headers2); + if (!ini_get('open_basedir') && !ini_get('safe_mode')) + { + curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1); + curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects); + } + + $this->headers = trim(curl_exec($fp)); + if (curl_errno($fp) == 23 || curl_errno($fp) == 61) + { + curl_setopt($fp, CURLOPT_ENCODING, 'none'); + $this->headers = trim(curl_exec($fp)); + } + if (curl_errno($fp)) + { + $this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp); + $this->success = false; + return false; + } + $info = curl_getinfo($fp); + $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 2); + if (count($this->headers) == $info['redirect_count'] + 1) + { + $this->headers = array_pop($this->headers); + $this->body = ''; + } + else + { + $this->body = array_pop($this->headers); + $this->headers = array_pop($this->headers); + } + $this->headers = $this->parse_headers($this->headers); + 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->SimplePie_File($this->headers['location'], $timeout, $redirects, $headers, $useragent, $force_fsockopen); + } + } + else + { + $this->method = 'fsockopen'; + $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 = 'fsockopen error: ' . $errstr; + $this->success = false; + return false; + } + else + { + stream_set_timeout($this->fp, $timeout); + $get = (isset($url_parts['query'])) ? "$url_parts[path]?$url_parts[query]" : $url_parts['path']; + $out = "GET $get HTTP/1.0\r\n"; + $out .= "Host: $url_parts[host]\r\n"; + $out .= "User-Agent: $useragent\r\n"; + if (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']) + { + $data .= fgets($this->fp, 128); + $info = stream_get_meta_data($this->fp); + } + if (!$info['timed_out']) + { + $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->SimplePie_File($this->headers['location'], $timeout, $redirects, $headers, $useragent, $force_fsockopen); + } + } + else + { + $this->close(); + $this->error = 'fsocket timed out'; + $this->success = false; + return false; + } + } + } + return $this->headers['status']['code']; + } + else + { + $this->method = 'fopen'; + if ($this->fp = fopen($url, 'r')) + { + return true; + } + else + { + $this->error = 'fopen 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) + { + $info = stream_get_meta_data($this->fp); + $this->body = ''; + while (!$info['eof'] && !$info['timed_out']) + { + $this->body .= fread($this->fp, 1024); + $info = stream_get_meta_data($this->fp); + } + if (!$info['timed_out']) + { + $this->body = trim($this->body); + if ($this->method == 'fsockopen' && !empty($this->headers['content-encoding']) && ($this->headers['content-encoding'] == 'gzip' || $this->headers['content-encoding'] == 'deflate')) + { + if (substr($this->body, 0, 8) == "\x1f\x8b\x08\x00\x00\x00\x00\x00") + { + $this->body = substr($this->body, 10); + } + $this->body = gzinflate($this->body); + } + $this->close(); + } + else + { + return false; + } + } + 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 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; + } +} + +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('/(/)?([^/]+)$/msiU', '', $target['path']); + } + else if (strpos($input, '/..') === 0 && SimplePie_Misc::strendpos($input, '/..') === 0) + { + $input = substr_replace($input, '/', 0, 3); + $target['path'] = preg_replace('/(/)?([^/]+)$/msiU', '', $target['path']); + } + else if ($input == '.' || $input == '..') + { + $input = ''; + } + else + { + if (preg_match('/^(.+)(/|$)/msiU', $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 = ''; + if (!empty($target['scheme'])) + { + $return .= "$target[scheme]:"; + } + if (!empty($target['authority'])) + { + $return .= $target['authority']; + } + if (!empty($target['path'])) + { + $return .= $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(); + $name = preg_quote($realname, '/'); + preg_match_all("/<($name)((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|'([^']*)'|(.*)))*)\s*((/)?>|>(.*)</$name>)/msiU", $string, $matches, PREG_SET_ORDER); + for ($i = 0; $i < count($matches); $i++) + { + $return[$i]['tag'] = $realname; + $return[$i]['full'] = $matches[$i][0]; + if (strlen($matches[$i][10]) <= 2) + { + $return[$i]['self_closing'] = true; + } + else + { + $return[$i]['self_closing'] = false; + $return[$i]['content'] = $matches[$i][12]; + } + $return[$i]['attribs'] = array(); + if (!empty($matches[$i][2])) + { + preg_match_all('/((\w+:)?\w+)\s*=\s*("([^"]*)"|'([^']*)'|(\S+))\s/msiU', ' ' . $matches[$i][2] . ' ', $attribs, PREG_SET_ORDER); + for ($j = 0; $j < count($attribs); $j++) + { + $return[$i]['attribs'][strtoupper($attribs[$j][1])]['data'] = $attribs[$j][count($attribs[$j])-1]; + $first = substr($attribs[$j][2], 0, 1); + $return[$i]['attribs'][strtoupper($attribs[$j][1])]['split'] = ($first == '"' || $first == "'") ? $first : '"'; + } + } + } + return $return; + } + + function element_implode($element) + { + $full = "<$element[tag]"; + foreach ($element['attribs'] as $key => $value) + { + $key = strtolower($key); + $full .= " $key=$value[split]$value[data]$value[split]"; + } + if ($element['self_closing']) + { + $full .= ' />'; + } + else + { + $full .= ">$element[content]</$element[tag]>"; + } + return $full; + } + + function error($message, $level, $file, $line) + { + switch ($level) + { + case E_USER_ERROR: + $note = 'PHP Error'; + break; + case E_USER_WARNING: + $note = 'PHP Warning'; + break; + case E_USER_NOTICE: + $note = 'PHP Notice'; + break; + default: + $note = 'Unknown Error'; + break; + } + error_log("$note: $message in $file on line $line", 0); + return $message; + } + + function display_file($url, $timeout = 10, $useragent = null) + { + $file = new SimplePie_File($url, $timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $useragent); + $headers = $file->headers(); + if ($file->body() !== false) + { + header('Content-type: ' . $headers['content-type']); + echo $file->body(); + exit; + } + } + + function fix_protocol($url, $http = 1) + { + $parsed = SimplePie_Misc::parse_url($url); + if (!empty($parsed['scheme']) && strtolower($parsed['scheme']) != 'http' && strtolower($parsed['scheme']) != 'https') + { + return SimplePie_Misc::fix_protocol("$parsed[authority]$parsed[path]$parsed[query]$parsed[fragment]", $http); + } + if (!file_exists($url) && empty($parsed['scheme'])) + { + return SimplePie_Misc::fix_protocol("http://$url", $http); + } + + if ($http == 2 && !empty($parsed['scheme'])) + { + return "feed:$url"; + } + else if ($http == 3 && strtolower($parsed['scheme']) == 'http') + { + return substr_replace($url, 'podcast', 0, 4); + } + else + { + return $url; + } + } + + function parse_url($url, $parse_match = true) + { + preg_match('/^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(?([^#]*))?(#(.*))?/i', $url, $match); + if (empty($match[0])) + { + return false; + } + else + { + for ($i = 6; $i < 10; $i++) + { + if (!isset($match[$i])) + { + $match[$i] = ''; + } + } + if ($parse_match) + { + $match = array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => $match[6], 'fragment' => $match[8]); + } + return $match; + } + } + + /** + * Replace bad bytes + * + * PCRE Pattern to locate bad bytes in a UTF-8 string + * Comes from W3 FAQ: Multilingual Forms + * Note: modified to include full ASCII range including control chars + * + * Modified by Geoffrey Sneddon 2006-11-19 to remove functionality + * to choose what the replace string is, and to use a variable for + * the output instead of PHP's output buffer + */ + function utf8_bad_replace($str) + { + $UTF8_BAD = + '([\x00-\x7F]' . # ASCII (including control chars) + '|[\xC2-\xDF][\x80-\xBF]' . # non-overlong 2-byte + '|\xE0[\xA0-\xBF][\x80-\xBF]' . # excluding overlongs + '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' . # straight 3-byte + '|\xED[\x80-\x9F][\x80-\xBF]' . # excluding surrogates + '|\xF0[\x90-\xBF][\x80-\xBF]{2}' . # planes 1-3 + '|[\xF1-\xF3][\x80-\xBF]{3}' . # planes 4-15 + '|\xF4[\x80-\x8F][\x80-\xBF]{2}' . # plane 16 + '|(.{1}))'; # invalid byte + $output = ''; + while (preg_match('/' . $UTF8_BAD . '/S', $str, $matches)) + { + if (!isset($matches[2])) + { + $output .= $matches[0]; + } + $str = substr($str, strlen($matches[0])); + } + return $output; + } + + function change_encoding($data, $input, $output) + { + $input = SimplePie_Misc::encoding($input); + $output = SimplePie_Misc::encoding($output); + + if ($input != $output) + { + if (function_exists('iconv') && $input['use_iconv'] && $output['use_iconv'] && iconv($input['encoding'], "$output[encoding]//TRANSLIT", $data)) + { + return iconv($input['encoding'], "$output[encoding]//TRANSLIT", $data); + } + else if (function_exists('iconv') && $input['use_iconv'] && $output['use_iconv'] && iconv($input['encoding'], $output['encoding'], $data)) + { + return iconv($input['encoding'], $output['encoding'], $data); + } + else if (function_exists('mb_convert_encoding') && $input['use_mbstring'] && $output['use_mbstring']) + { + return mb_convert_encoding($data, $output['encoding'], $input['encoding']); + } + else if ($input['encoding'] == 'ISO-8859-1' && $output['encoding'] == 'UTF-8') + { + return utf8_encode($data); + } + else if ($input['encoding'] == 'UTF-8' && $output['encoding'] == 'ISO-8859-1') + { + return utf8_decode($data); + } + } + return $data; + } + + function encoding($encoding) + { + $return['use_mbstring'] = false; + $return['use_iconv'] = false; + switch (strtolower($encoding)) + { + + // 7bit + case '7bit': + case '7-bit': + $return['encoding'] = '7bit'; + $return['use_mbstring'] = true; + break; + + // 8bit + case '8bit': + case '8-bit': + $return['encoding'] = '8bit'; + $return['use_mbstring'] = true; + break; + + // ARMSCII-8 + case 'armscii-8': + case 'armscii': + $return['encoding'] = 'ARMSCII-8'; + $return['use_iconv'] = true; + break; + + // ASCII + case 'us-ascii': + case 'ascii': + $return['encoding'] = 'US-ASCII'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // BASE64 + case 'base64': + case 'base-64': + $return['encoding'] = 'BASE64'; + $return['use_mbstring'] = true; + break; + + // Big5 - Traditional Chinese, mainly used in Taiwan + case 'big5': + case '950': + $return['encoding'] = 'BIG5'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // Big5 with Hong Kong extensions, Traditional Chinese + case 'big5-hkscs': + $return['encoding'] = 'BIG5-HKSCS'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // byte2be + case 'byte2be': + $return['encoding'] = 'byte2be'; + $return['use_mbstring'] = true; + break; + + // byte2le + case 'byte2le': + $return['encoding'] = 'byte2le'; + $return['use_mbstring'] = true; + break; + + // byte4be + case 'byte4be': + $return['encoding'] = 'byte4be'; + $return['use_mbstring'] = true; + break; + + // byte4le + case 'byte4le': + $return['encoding'] = 'byte4le'; + $return['use_mbstring'] = true; + break; + + // EUC-CN + case 'euc-cn': + case 'euccn': + $return['encoding'] = 'EUC-CN'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // EUC-JISX0213 + case 'euc-jisx0213': + case 'eucjisx0213': + $return['encoding'] = 'EUC-JISX0213'; + $return['use_iconv'] = true; + break; + + // EUC-JP + case 'euc-jp': + case 'eucjp': + $return['encoding'] = 'EUC-JP'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // EUCJP-win + case 'euc-jp-win': + case 'eucjp-win': + case 'eucjpwin': + $return['encoding'] = 'EUCJP-win'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // EUC-KR + case 'euc-kr': + case 'euckr': + $return['encoding'] = 'EUC-KR'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // EUC-TW + case 'euc-tw': + case 'euctw': + $return['encoding'] = 'EUC-TW'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // GB18030 - Simplified Chinese, national standard character set + case 'gb18030-2000': + case 'gb18030': + $return['encoding'] = 'GB18030'; + $return['use_iconv'] = true; + break; + + // GB2312 - Simplified Chinese, national standard character set + case 'gb2312': + case '936': + $return['encoding'] = 'GB2312'; + $return['use_mbstring'] = true; + break; + + // GBK + case 'gbk': + $return['encoding'] = 'GBK'; + $return['use_iconv'] = true; + break; + + // Georgian-Academy + case 'georgian-academy': + $return['encoding'] = 'Georgian-Academy'; + $return['use_iconv'] = true; + break; + + // Georgian-PS + case 'georgian-ps': + $return['encoding'] = 'Georgian-PS'; + $return['use_iconv'] = true; + break; + + // HTML-ENTITIES + case 'html-entities': + case 'htmlentities': + $return['encoding'] = 'HTML-ENTITIES'; + $return['use_mbstring'] = true; + break; + + // HZ + case 'hz': + $return['encoding'] = 'HZ'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // ISO-2022-CN + case 'iso-2022-cn': + case 'iso2022-cn': + case 'iso2022cn': + $return['encoding'] = 'ISO-2022-CN'; + $return['use_iconv'] = true; + break; + + // ISO-2022-CN-EXT + case 'iso-2022-cn-ext': + case 'iso2022-cn-ext': + case 'iso2022cn-ext': + case 'iso2022cnext': + $return['encoding'] = 'ISO-2022-CN'; + $return['use_iconv'] = true; + break; + + // ISO-2022-JP + case 'iso-2022-jp': + case 'iso2022-jp': + case 'iso2022jp': + $return['encoding'] = 'ISO-2022-JP'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // ISO-2022-JP-1 + case 'iso-2022-jp-1': + case 'iso2022-jp-1': + case 'iso2022jp-1': + case 'iso2022jp1': + $return['encoding'] = 'ISO-2022-JP-1'; + $return['use_iconv'] = true; + break; + + // ISO-2022-JP-2 + case 'iso-2022-jp-2': + case 'iso2022-jp-2': + case 'iso2022jp-2': + case 'iso2022jp2': + $return['encoding'] = 'ISO-2022-JP-2'; + $return['use_iconv'] = true; + break; + + // ISO-2022-JP-3 + case 'iso-2022-jp-3': + case 'iso2022-jp-3': + case 'iso2022jp-3': + case 'iso2022jp3': + $return['encoding'] = 'ISO-2022-JP-3'; + $return['use_iconv'] = true; + break; + + // ISO-2022-KR + case 'iso-2022-kr': + case 'iso2022-kr': + case 'iso2022kr': + $return['encoding'] = 'ISO-2022-KR'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // ISO-8859-1 + case 'iso-8859-1': + case 'iso8859-1': + $return['encoding'] = 'ISO-8859-1'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // ISO-8859-2 + case 'iso-8859-2': + case 'iso8859-2': + $return['encoding'] = 'ISO-8859-2'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // ISO-8859-3 + case 'iso-8859-3': + case 'iso8859-3': + $return['encoding'] = 'ISO-8859-3'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // ISO-8859-4 + case 'iso-8859-4': + case 'iso8859-4': + $return['encoding'] = 'ISO-8859-4'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // ISO-8859-5 + case 'iso-8859-5': + case 'iso8859-5': + $return['encoding'] = 'ISO-8859-5'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // ISO-8859-6 + case 'iso-8859-6': + case 'iso8859-6': + $return['encoding'] = 'ISO-8859-6'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // ISO-8859-7 + case 'iso-8859-7': + case 'iso8859-7': + $return['encoding'] = 'ISO-8859-7'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // ISO-8859-8 + case 'iso-8859-8': + case 'iso8859-8': + $return['encoding'] = 'ISO-8859-8'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // ISO-8859-9 + case 'iso-8859-9': + case 'iso8859-9': + $return['encoding'] = 'ISO-8859-9'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // ISO-8859-10 + case 'iso-8859-10': + case 'iso8859-10': + $return['encoding'] = 'ISO-8859-10'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // mbstring/iconv functions don't appear to support 11 & 12 + + // ISO-8859-13 + case 'iso-8859-13': + case 'iso8859-13': + $return['encoding'] = 'ISO-8859-13'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // ISO-8859-14 + case 'iso-8859-14': + case 'iso8859-14': + $return['encoding'] = 'ISO-8859-14'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // ISO-8859-15 + case 'iso-8859-15': + case 'iso8859-15': + $return['encoding'] = 'ISO-8859-15'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // ISO-8859-16 + case 'iso-8859-16': + case 'iso8859-16': + $return['encoding'] = 'ISO-8859-16'; + $return['use_iconv'] = true; + break; + + // JIS + case 'jis': + $return['encoding'] = 'JIS'; + $return['use_mbstring'] = true; + break; + + // JOHAB - Korean + case 'johab': + $return['encoding'] = 'JOHAB'; + $return['use_iconv'] = true; + break; + + // Russian + case 'koi8-r': + case 'koi8r': + $return['encoding'] = 'KOI8-R'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // Turkish + case 'koi8-t': + case 'koi8t': + $return['encoding'] = 'KOI8-T'; + $return['use_iconv'] = true; + break; + + // Ukrainian + case 'koi8-u': + case 'koi8u': + $return['encoding'] = 'KOI8-U'; + $return['use_iconv'] = true; + break; + + // Russian+Ukrainian + case 'koi8-ru': + case 'koi8ru': + $return['encoding'] = 'KOI8-RU'; + $return['use_iconv'] = true; + break; + + // Macintosh (Mac OS Classic) + case 'macintosh': + $return['encoding'] = 'Macintosh'; + $return['use_iconv'] = true; + break; + + // MacArabic (Mac OS Classic) + case 'macarabic': + $return['encoding'] = 'MacArabic'; + $return['use_iconv'] = true; + break; + + // MacCentralEurope (Mac OS Classic) + case 'maccentraleurope': + $return['encoding'] = 'MacCentralEurope'; + $return['use_iconv'] = true; + break; + + // MacCroatian (Mac OS Classic) + case 'maccroatian': + $return['encoding'] = 'MacCroatian'; + $return['use_iconv'] = true; + break; + + // MacCyrillic (Mac OS Classic) + case 'maccyrillic': + $return['encoding'] = 'MacCyrillic'; + $return['use_iconv'] = true; + break; + + // MacGreek (Mac OS Classic) + case 'macgreek': + $return['encoding'] = 'MacGreek'; + $return['use_iconv'] = true; + break; + + // MacHebrew (Mac OS Classic) + case 'machebrew': + $return['encoding'] = 'MacHebrew'; + $return['use_iconv'] = true; + break; + + // MacIceland (Mac OS Classic) + case 'maciceland': + $return['encoding'] = 'MacIceland'; + $return['use_iconv'] = true; + break; + + // MacRoman (Mac OS Classic) + case 'macroman': + $return['encoding'] = 'MacRoman'; + $return['use_iconv'] = true; + break; + + // MacRomania (Mac OS Classic) + case 'macromania': + $return['encoding'] = 'MacRomania'; + $return['use_iconv'] = true; + break; + + // MacThai (Mac OS Classic) + case 'macthai': + $return['encoding'] = 'MacThai'; + $return['use_iconv'] = true; + break; + + // MacTurkish (Mac OS Classic) + case 'macturkish': + $return['encoding'] = 'MacTurkish'; + $return['use_iconv'] = true; + break; + + // MacUkraine (Mac OS Classic) + case 'macukraine': + $return['encoding'] = 'MacUkraine'; + $return['use_iconv'] = true; + break; + + // MuleLao-1 + case 'mulelao-1': + case 'mulelao1': + $return['encoding'] = 'MuleLao-1'; + $return['use_iconv'] = true; + break; + + // Shift_JIS + case 'shift_jis': + case 'sjis': + case '932': + $return['encoding'] = 'Shift_JIS'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // Shift_JISX0213 + case 'shift-jisx0213': + case 'shiftjisx0213': + $return['encoding'] = 'Shift_JISX0213'; + $return['use_iconv'] = true; + break; + + // SJIS-win + case 'sjis-win': + case 'sjiswin': + case 'shift_jis-win': + $return['encoding'] = 'SJIS-win'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // TCVN - Vietnamese + case 'tcvn': + $return['encoding'] = 'TCVN'; + $return['use_iconv'] = true; + break; + + // TDS565 - Turkish + case 'tds565': + $return['encoding'] = 'TDS565'; + $return['use_iconv'] = true; + break; + + // TIS-620 Thai + case 'tis-620': + case 'tis620': + $return['encoding'] = 'TIS-620'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // UCS-2 + case 'ucs-2': + case 'ucs2': + case 'utf-16': + case 'utf16': + $return['encoding'] = 'UCS-2'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // UCS-2BE + case 'ucs-2be': + case 'ucs2be': + case 'utf-16be': + case 'utf16be': + $return['encoding'] = 'UCS-2BE'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // UCS-2LE + case 'ucs-2le': + case 'ucs2le': + case 'utf-16le': + case 'utf16le': + $return['encoding'] = 'UCS-2LE'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // UCS-2-INTERNAL + case 'ucs-2-internal': + case 'ucs2internal': + $return['encoding'] = 'UCS-2-INTERNAL'; + $return['use_iconv'] = true; + break; + + // UCS-4 + case 'ucs-4': + case 'ucs4': + case 'utf-32': + case 'utf32': + $return['encoding'] = 'UCS-4'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // UCS-4BE + case 'ucs-4be': + case 'ucs4be': + case 'utf-32be': + case 'utf32be': + $return['encoding'] = 'UCS-4BE'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // UCS-4LE + case 'ucs-4le': + case 'ucs4le': + case 'utf-32le': + case 'utf32le': + $return['encoding'] = 'UCS-4LE'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // UCS-4-INTERNAL + case 'ucs-4-internal': + case 'ucs4internal': + $return['encoding'] = 'UCS-4-INTERNAL'; + $return['use_iconv'] = true; + break; + + // UCS-16 + case 'ucs-16': + case 'ucs16': + $return['encoding'] = 'UCS-16'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // UCS-16BE + case 'ucs-16be': + case 'ucs16be': + $return['encoding'] = 'UCS-16BE'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // UCS-16LE + case 'ucs-16le': + case 'ucs16le': + $return['encoding'] = 'UCS-16LE'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // UCS-32 + case 'ucs-32': + case 'ucs32': + $return['encoding'] = 'UCS-32'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // UCS-32BE + case 'ucs-32be': + case 'ucs32be': + $return['encoding'] = 'UCS-32BE'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // UCS-32LE + case 'ucs-32le': + case 'ucs32le': + $return['encoding'] = 'UCS-32LE'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // UTF-7 + case 'utf-7': + case 'utf7': + $return['encoding'] = 'UTF-7'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // UTF7-IMAP + case 'utf-7-imap': + case 'utf7-imap': + case 'utf7imap': + $return['encoding'] = 'UTF7-IMAP'; + $return['use_mbstring'] = true; + break; + + // VISCII - Vietnamese ASCII + case 'viscii': + $return['encoding'] = 'VISCII'; + $return['use_iconv'] = true; + break; + + // Windows-specific Central & Eastern Europe + case 'cp1250': + case 'windows-1250': + case 'win-1250': + case '1250': + $return['encoding'] = 'Windows-1250'; + $return['use_iconv'] = true; + break; + + // Windows-specific Cyrillic + case 'cp1251': + case 'windows-1251': + case 'win-1251': + case '1251': + $return['encoding'] = 'Windows-1251'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // Windows-specific Western Europe + case 'cp1252': + case 'windows-1252': + case '1252': + $return['encoding'] = 'Windows-1252'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + + // Windows-specific Greek + case 'cp1253': + case 'windows-1253': + case '1253': + $return['encoding'] = 'Windows-1253'; + $return['use_iconv'] = true; + break; + + // Windows-specific Turkish + case 'cp1254': + case 'windows-1254': + case '1254': + $return['encoding'] = 'Windows-1254'; + $return['use_iconv'] = true; + break; + + // Windows-specific Hebrew + case 'cp1255': + case 'windows-1255': + case '1255': + $return['encoding'] = 'Windows-1255'; + $return['use_iconv'] = true; + break; + + // Windows-specific Arabic + case 'cp1256': + case 'windows-1256': + case '1256': + $return['encoding'] = 'Windows-1256'; + $return['use_iconv'] = true; + break; + + // Windows-specific Baltic + case 'cp1257': + case 'windows-1257': + case '1257': + $return['encoding'] = 'Windows-1257'; + $return['use_iconv'] = true; + break; + + // Windows-specific Vietnamese + case 'cp1258': + case 'windows-1258': + case '1258': + $return['encoding'] = 'Windows-1258'; + $return['use_iconv'] = true; + break; + + // Default to UTF-8 + default: + $return['encoding'] = 'UTF-8'; + $return['use_iconv'] = true; + $return['use_mbstring'] = true; + break; + } + + // Then, return it. + return $return; + } + + function get_curl_version() + { + $curl = 0; + if (is_array(curl_version())) + { + $curl = curl_version(); + $curl = $curl['version']; + } + else + { + $curl = curl_version(); + $curl = explode(' ', $curl); + $curl = explode('/', $curl[0]); + $curl = $curl[1]; + } + return $curl; + } + + function is_a_class($class1, $class2) + { + if (class_exists($class1)) + { + $classes = array(strtolower($class1)); + while ($class1 = get_parent_class($class1)) + { + $classes[] = strtolower($class1); + } + return in_array(strtolower($class2), $classes); + } + else + { + return false; + } + } +} + +class SimplePie_Locator +{ + var $useragent; + var $timeout; + var $file; + var $local; + var $elsewhere; + var $file_class = 'SimplePie_File'; + + function SimplePie_Locator(&$file, $timeout = 10, $useragent = null, $file_class = 'SimplePie_File') + { + if (!is_a($file, 'SimplePie_File')) + { + $this->file = new $this->file_class($file, $timeout, $useragent); + } + else + { + $this->file =& $file; + } + $this->file_class = $file_class; + $this->useragent = $useragent; + $this->timeout = $timeout; + } + + + function find() + { + if ($this->is_feed($this->file)) + { + return $this->file->url; + } + + $autodiscovery = $this->autodiscovery($this->file); + if ($autodiscovery) + { + return $autodiscovery; + } + + if ($this->get_links($this->file)) + { + if (!empty($this->local)) + { + $extension_local = $this->extension($this->local); + if ($extension_local) + { + return $extension_local; + } + + $body_local = $this->body($this->local); + if ($body_local) + { + return $body_local; + } + } + + if (!empty($this->elsewhere)) + { + $extension_elsewhere = $this->extension($this->elsewhere); + if ($extension_elsewhere) + { + return $extension_elsewhere; + } + + $body_elsewhere = $this->body($this->elsewhere); + if ($body_elsewhere) + { + return $body_elsewhere; + } + } + } + return false; + } + + function is_feed(&$file) + { + if (!is_a($file, 'SimplePie_File')) + { + if (isset($this)) + { + $file2 = new $this->file_class($file, $this->timeout, 5, null, $this->useragent); + } + else + { + $file2 = new $this->file_class($file); + } + $file2->body(); + $file2->close(); + } + else + { + $file2 =& $file; + } + $body = preg_replace('/<!-(.*)->/msiU', '', $file2->body()); + if (preg_match('/<(\w+:)?rss/msiU', $body) || preg_match('/<(\w+:)?RDF/mi', $body) || preg_match('/<(\w+:)?feed/mi', $body)) + { + return true; + } + return false; + } + + function autodiscovery(&$file) + { + $links = SimplePie_Misc::get_element('link', $file->body()); + $done = array(); + foreach ($links as $link) + { + if (!empty($link['attribs']['TYPE']['data']) && !empty($link['attribs']['HREF']['data']) && !empty($link['attribs']['REL']['data'])) + { + $rel = preg_split('/\s+/', strtolower(trim($link['attribs']['REL']['data']))); + $type = preg_match('/^(application/rss+xml|application/atom+xml|application/rdf+xml|application/xml+rss|application/xml+atom|application/xml+rdf|application/xml|application/x.atom+xml|text/xml)(;|$)/msiU', trim($link['attribs']['TYPE']['data'])); + $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['HREF']['data']), $this->file->url); + if (!in_array($href, $done) && in_array('alternate', $rel) && $type) + { + $feed = $this->is_feed($href); + if ($feed) + { + return $href; + } + } + $done[] = $href; + } + } + return false; + } + + function get_links(&$file) + { + $links = SimplePie_Misc::get_element('a', $file->body()); + foreach ($links as $link) + { + if (!empty($link['attribs']['HREF']['data'])) + { + $href = trim($link['attribs']['HREF']['data']); + $parsed = SimplePie_Misc::parse_url($href); + if (empty($parsed['scheme']) || $parsed['scheme'] != 'javascript') + { + $current = SimplePie_Misc::parse_url($this->file->url); + if (empty($parsed['authority']) || $parsed['authority'] == $current['authority']) + { + $this->local[] = SimplePie_Misc::absolutize_url($href, $this->file->url); + } + else + { + $this->elsewhere[] = SimplePie_Misc::absolutize_url($href, $this->file->url); + } + } + } + } + if (!empty($this->local)) + { + $this->local = array_unique($this->local); + } + if (!empty($this->elsewhere)) + { + $this->elsewhere = array_unique($this->elsewhere); + } + if (!empty($this->local) || !empty($this->elsewhere)) + { + return true; + } + return false; + } + + function extension(&$array) + { + foreach ($array as $key => $value) + { + $value = SimplePie_Misc::absolutize_url($value, $this->file->url); + if (in_array(strrchr($value, '.'), array('.rss', '.rdf', '.atom', '.xml'))) + { + if ($this->is_feed($value)) + { + return $value; + } + else + { + unset($array[$key]); + } + } + } + return false; + } + + function body(&$array) + { + foreach ($array as $key => $value) + { + $value = SimplePie_Misc::absolutize_url($value, $this->file->url); + if (preg_match('/(rss|rdf|atom|xml)/i', $value)) + { + if ($this->is_feed($value)) + { + return $value; + } + else + { + unset($array[$key]); + } + } + } + return false; + } +} + +class SimplePie_Parser +{ + var $encoding; + var $data; + var $namespaces = array('xml' => 'HTTP://WWW.W3.ORG/XML/1998/NAMESPACE', 'atom' => 'ATOM', 'rss2' => 'RSS', 'rdf' => 'RDF', 'rss1' => 'RSS', 'dc' => 'DC', 'xhtml' => 'XHTML', 'content' => 'CONTENT'); + var $xml; + var $error_code; + var $error_string; + var $current_line; + var $current_column; + var $current_byte; + var $tag_name; + var $inside_item; + var $item_number = 0; + var $inside_channel; + var $author_number= 0; + var $category_number = 0; + var $enclosure_number = 0; + var $link_number = 0; + var $item_link_number = 0; + var $inside_image; + var $attribs; + var $is_first; + var $inside_author; + var $depth_inside_item = 0; + + function SimplePie_Parser($data, $encoding, $return_xml = false) + { + $this->encoding = $encoding; + + // Strip BOM: + // UTF-32 Big Endian BOM + if (strpos($data, sprintf('%c%c%c%c', 0x00, 0x00, 0xFE, 0xFF)) === 0) + { + $data = substr($data, 4); + } + // UTF-32 Little Endian BOM + else if (strpos($data, sprintf('%c%c%c%c', 0xFF, 0xFE, 0x00, 0x00)) === 0) + { + $data = substr($data, 4); + } + // UTF-16 Big Endian BOM + else if (strpos($data, sprintf('%c%c', 0xFE, 0xFF)) === 0) + { + $data = substr($data, 2); + } + // UTF-16 Little Endian BOM + else if (strpos($data, sprintf('%c%c', 0xFF, 0xFE)) === 0) + { + $data = substr($data, 2); + } + // UTF-8 BOM + else if (strpos($data, sprintf('%c%c%c', 0xEF, 0xBB, 0xBF)) === 0) + { + $data = substr($data, 3); + } + + // Make sure the XML prolog is sane and has the correct encoding + if (preg_match('/^<?xml(.*)?>/msiU', $data, $prolog)) + { + $data = substr_replace($data, '', 0, strlen($prolog[0])); + } + $data = "<?xml version='1.0' encoding='$encoding'?>\n" . $data; + + // Put some data into CDATA blocks + // If we're RSS + if ((stristr($data, '<rss') || preg_match('/<([a-z0-9]+:)?RDF/mi', $data)) && (preg_match('/<([a-z0-9]+:)?channel/mi', $data) || preg_match('/<([a-z0-9]+:)?item/mi', $data))) + { + $sp_elements = array( + 'author', + 'category', + 'copyright', + 'description', + 'docs', + 'generator', + 'guid', + 'language', + 'lastBuildDate', + 'link', + 'managingEditor', + 'pubDate', + 'title', + 'url', + 'webMaster', + ); + } + // Or if we're Atom + else + { + $sp_elements = array( + 'content', + 'copyright', + 'name', + 'subtitle', + 'summary', + 'tagline', + 'title', + ); + } + foreach ($sp_elements as $full) + { + $data = preg_replace_callback("/<($full)((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|'([^']*)'))*)\s*(/>|>(.*)</$full>)/msiU", array(&$this, 'add_cdata'), $data); + } + foreach ($sp_elements as $full) + { + // Deal with CDATA within CDATA (this can be caused by us inserting CDATA above) + $data = preg_replace_callback("/<($full)((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|'([^']*)'))*)\s*(/>|><![CDATA[(.*)]]></$full>)/msiU", array(&$this, 'cdata_in_cdata'), $data); + } + + // Return the XML, if so desired + if ($return_xml) + { + $this->data =& $data; + return; + } + + // Create the parser + $this->xml = xml_parser_create_ns($encoding); + xml_parser_set_option($this->xml, XML_OPTION_SKIP_WHITE, 1); + xml_set_object($this->xml, $this); + xml_set_character_data_handler($this->xml, 'data_handler'); + xml_set_element_handler($this->xml, 'start_handler', 'end_handler'); + xml_set_start_namespace_decl_handler($this->xml, 'start_name_space'); + xml_set_end_namespace_decl_handler($this->xml, 'end_name_space'); + + // Parse! + if (!xml_parse($this->xml, $data)) + { + $this->data = null; + $this->error_code = xml_get_error_code($this->xml); + $this->error_string = xml_error_string($this->error_code); + } + $this->current_line = xml_get_current_line_number($this->xml); + $this->current_column = xml_get_current_column_number($this->xml); + $this->current_byte = xml_get_current_byte_index($this->xml); + xml_parser_free($this->xml); + return; + } + + function add_cdata($match) + { + if (isset($match[10])) + { + return "<$match[1]$match[2]><![CDATA[$match[10]]]></$match[1]>"; + } + return $match[0]; + } + + function cdata_in_cdata($match) + { + if (isset($match[10])) + { + $match[10] = preg_replace_callback('/<![CDATA[(.*)]]>/msiU', array(&$this, 'real_cdata_in_cdata'), $match[10]); + return "<$match[1]$match[2]><![CDATA[$match[10]]]></$match[1]>"; + } + return $match[0]; + } + + function real_cdata_in_cdata($match) + { + return htmlspecialchars($match[1], ENT_NOQUOTES); + } + + function do_add_content(&$array, $data) + { + if ($this->is_first) + { + $array['data'] = $data; + $array['attribs'] = $this->attribs; + } + else + { + $array['data'] .= $data; + } + } + + function start_handler($parser, $name, $attribs) + { + $this->tag_name = $name; + $this->attribs = $attribs; + $this->is_first = true; + + if ($this->inside_item) + { + $this->depth_inside_item++; + } + + switch ($this->tag_name) + { + case 'ITEM': + case $this->namespaces['rss2'] . ':ITEM': + case $this->namespaces['rss1'] . ':ITEM': + case 'ENTRY': + case $this->namespaces['atom'] . ':ENTRY': + $this->inside_item = true; + $this->do_add_content($this->data['items'][$this->item_number], ''); + break; + + case 'CHANNEL': + case $this->namespaces['rss2'] . ':CHANNEL': + case $this->namespaces['rss1'] . ':CHANNEL': + $this->inside_channel = true; + break; + + case 'RSS': + case $this->namespaces['rss2'] . ':RSS': + $this->data['feedinfo']['type'] = 'RSS'; + $this->do_add_content($this->data['feeddata'], ''); + if (!empty($attribs['VERSION'])) + { + $this->data['feedinfo']['version'] = trim($attribs['VERSION']); + } + break; + + case $this->namespaces['rdf'] . ':RDF': + $this->data['feedinfo']['type'] = 'RSS'; + $this->do_add_content($this->data['feeddata'], ''); + $this->data['feedinfo']['version'] = 1; + break; + + case 'FEED': + case $this->namespaces['atom'] . ':FEED': + $this->data['feedinfo']['type'] = 'Atom'; + $this->do_add_content($this->data['feeddata'], ''); + if (!empty($attribs['VERSION'])) + { + $this->data['feedinfo']['version'] = trim($attribs['VERSION']); + } + break; + + case 'IMAGE': + case $this->namespaces['rss2'] . ':IMAGE': + case $this->namespaces['rss1'] . ':IMAGE': + if ($this->inside_channel) + { + $this->inside_image = true; + } + break; + } + + if (!empty($this->data['feedinfo']['type']) && $this->data['feedinfo']['type'] == 'Atom' && ($this->tag_name == 'AUTHOR' || $this->tag_name == $this->namespaces['atom'] . ':AUTHOR')) + { + $this->inside_author = true; + } + $this->data_handler($this->xml, ''); + } + + function data_handler($parser, $data) + { + if ($this->inside_item && $this->depth_inside_item == 1) + { + switch ($this->tag_name) + { + case 'TITLE': + case $this->namespaces['rss1'] . ':TITLE': + case $this->namespaces['rss2'] . ':TITLE': + case $this->namespaces['atom'] . ':TITLE': + $this->do_add_content($this->data['items'][$this->item_number]['title'], $data); + break; + + case $this->namespaces['dc'] . ':TITLE': + $this->do_add_content($this->data['items'][$this->item_number]['dc:title'], $data); + break; + + case 'CONTENT': + case $this->namespaces['atom'] . ':CONTENT': + $this->do_add_content($this->data['items'][$this->item_number]['content'], $data); + break; + + case $this->namespaces['content'] . ':ENCODED': + $this->do_add_content($this->data['items'][$this->item_number]['encoded'], $data); + break; + + case 'SUMMARY': + case $this->namespaces['atom'] . ':SUMMARY': + $this->do_add_content($this->data['items'][$this->item_number]['summary'], $data); + break; + + case 'LONGDESC': + $this->do_add_content($this->data['items'][$this->item_number]['longdesc'], $data); + break; + + case 'DESCRIPTION': + case $this->namespaces['rss1'] . ':DESCRIPTION': + case $this->namespaces['rss2'] . ':DESCRIPTION': + $this->do_add_content($this->data['items'][$this->item_number]['description'], $data); + break; + + case $this->namespaces['dc'] . ':DESCRIPTION': + $this->do_add_content($this->data['items'][$this->item_number]['dc:description'], $data); + break; + + case 'LINK': + case $this->namespaces['rss1'] . ':LINK': + case $this->namespaces['rss2'] . ':LINK': + case $this->namespaces['atom'] . ':LINK': + $this->do_add_content($this->data['items'][$this->item_number]['link'][$this->item_link_number], $data); + break; + + case 'ENCLOSURE': + case $this->namespaces['rss1'] . ':ENCLOSURE': + case $this->namespaces['rss2'] . ':ENCLOSURE': + case $this->namespaces['atom'] . ':ENCLOSURE': + $this->do_add_content($this->data['items'][$this->item_number]['enclosure'][$this->enclosure_number], $data); + break; + + case 'GUID': + case $this->namespaces['rss1'] . ':GUID': + case $this->namespaces['rss2'] . ':GUID': + $this->do_add_content($this->data['items'][$this->item_number]['guid'], $data); + break; + + case 'ID': + case $this->namespaces['atom'] . ':ID': + $this->do_add_content($this->data['items'][$this->item_number]['id'], $data); + break; + + case 'PUBDATE': + case $this->namespaces['rss1'] . ':PUBDATE': + case $this->namespaces['rss2'] . ':PUBDATE': + $this->do_add_content($this->data['items'][$this->item_number]['pubdate'], $data); + break; + + case $this->namespaces['dc'] . ':DATE': + $this->do_add_content($this->data['items'][$this->item_number]['dc:date'], $data); + break; + + case 'ISSUED': + case $this->namespaces['atom'] . ':ISSUED': + $this->do_add_content($this->data['items'][$this->item_number]['issued'], $data); + break; + + case 'PUBLISHED': + case $this->namespaces['atom'] . ':PUBLISHED': + $this->do_add_content($this->data['items'][$this->item_number]['published'], $data); + break; + + case 'MODIFIED': + case $this->namespaces['atom'] . ':MODIFIED': + $this->do_add_content($this->data['items'][$this->item_number]['modified'], $data); + break; + + case 'UPDATED': + case $this->namespaces['atom'] . ':UPDATED': + $this->do_add_content($this->data['items'][$this->item_number]['updated'], $data); + break; + + case 'CATEGORY': + case $this->namespaces['rss1'] . ':CATEGORY': + case $this->namespaces['rss2'] . ':CATEGORY': + case $this->namespaces['atom'] . ':CATEGORY': + $this->do_add_content($this->data['items'][$this->item_number]['category'][$this->category_number], $data); + break; + + case $this->namespaces['dc'] . ':SUBJECT': + $this->do_add_content($this->data['items'][$this->item_number]['subject'][$this->category_number], $data); + break; + + case $this->namespaces['dc'] . ':CREATOR': + $this->do_add_content($this->data['items'][$this->item_number]['creator'][$this->author_number], $data); + break; + + case 'AUTHOR': + case $this->namespaces['rss1'] . ':AUTHOR': + case $this->namespaces['rss2'] . ':AUTHOR': + $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['rss'], $data); + break; + } + + if ($this->inside_author) + { + switch ($this->tag_name) + { + case 'NAME': + case $this->namespaces['atom'] . ':NAME': + $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['name'], $data); + break; + + case 'URL': + case $this->namespaces['atom'] . ':URL': + $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['url'], $data); + break; + + case 'URI': + case $this->namespaces['atom'] . ':URI': + $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['uri'], $data); + break; + + case 'HOMEPAGE': + case $this->namespaces['atom'] . ':HOMEPAGE': + $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['homepage'], $data); + break; + + case 'EMAIL': + case $this->namespaces['atom'] . ':EMAIL': + $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['email'], $data); + break; + } + } + } + + else if (($this->inside_channel && !$this->inside_image) || (isset($this->data['feedinfo']['type']) && $this->data['feedinfo']['type'] == 'Atom')) + { + switch ($this->tag_name) + { + case 'TITLE': + case $this->namespaces['rss1'] . ':TITLE': + case $this->namespaces['rss2'] . ':TITLE': + case $this->namespaces['atom'] . ':TITLE': + $this->do_add_content($this->data['info']['title'], $data); + break; + + case 'LINK': + case $this->namespaces['rss1'] . ':LINK': + case $this->namespaces['rss2'] . ':LINK': + case $this->namespaces['atom'] . ':LINK': + $this->do_add_content($this->data['info']['link'][$this->link_number], $data); + break; + + case 'DESCRIPTION': + case $this->namespaces['rss1'] . ':DESCRIPTION': + case $this->namespaces['rss2'] . ':DESCRIPTION': + $this->do_add_content($this->data['info']['description'], $data); + break; + + case $this->namespaces['dc'] . ':DESCRIPTION': + $this->do_add_content($this->data['info']['dc:description'], $data); + break; + + case 'TAGLINE': + case $this->namespaces['atom'] . ':TAGLINE': + $this->do_add_content($this->data['info']['tagline'], $data); + break; + + case 'SUBTITLE': + case $this->namespaces['atom'] . ':SUBTITLE': + $this->do_add_content($this->data['info']['subtitle'], $data); + break; + + case 'COPYRIGHT': + case $this->namespaces['rss1'] . ':COPYRIGHT': + case $this->namespaces['rss2'] . ':COPYRIGHT': + case $this->namespaces['atom'] . ':COPYRIGHT': + $this->do_add_content($this->data['info']['copyright'], $data); + break; + + case 'LANGUAGE': + case $this->namespaces['rss1'] . ':LANGUAGE': + case $this->namespaces['rss2'] . ':LANGUAGE': + $this->do_add_content($this->data['info']['language'], $data); + break; + + case 'LOGO': + case $this->namespaces['atom'] . ':LOGO': + $this->do_add_content($this->data['info']['logo'], $data); + break; + + } + } + + else if ($this->inside_channel && $this->inside_image) + { + switch ($this->tag_name) + { + case 'TITLE': + case $this->namespaces['rss1'] . ':TITLE': + case $this->namespaces['rss2'] . ':TITLE': + $this->do_add_content($this->data['info']['image']['title'], $data); + break; + + case 'URL': + case $this->namespaces['rss1'] . ':URL': + case $this->namespaces['rss2'] . ':URL': + $this->do_add_content($this->data['info']['image']['url'], $data); + break; + + case 'LINK': + case $this->namespaces['rss1'] . ':LINK': + case $this->namespaces['rss2'] . ':LINK': + $this->do_add_content($this->data['info']['image']['link'], $data); + break; + + case 'WIDTH': + case $this->namespaces['rss1'] . ':WIDTH': + case $this->namespaces['rss2'] . ':WIDTH': + $this->do_add_content($this->data['info']['image']['width'], $data); + break; + + case 'HEIGHT': + case $this->namespaces['rss1'] . ':HEIGHT': + case $this->namespaces['rss2'] . ':HEIGHT': + $this->do_add_content($this->data['info']['image']['height'], $data); + break; + } + } + $this->is_first = false; + } + + function end_handler($parser, $name) + { + $this->tag_name = ''; + switch ($name) + { + case 'ITEM': + case $this->namespaces['rss1'] . ':ITEM': + case $this->namespaces['rss2'] . ':ITEM': + case 'ENTRY': + case $this->namespaces['atom'] . ':ENTRY': + $this->inside_item = false; + $this->item_number++; + $this->author_number = 0; + $this->category_number = 0; + $this->enclosure_number = 0; + $this->item_link_number = 0; + break; + + case 'CHANNEL': + case $this->namespaces['rss1'] . ':CHANNEL': + case $this->namespaces['rss2'] . ':CHANNEL': + $this->inside_channel = false; + break; + + case 'IMAGE': + case $this->namespaces['rss1'] . ':IMAGE': + case $this->namespaces['rss2'] . ':IMAGE': + $this->inside_image = false; + break; + + case 'AUTHOR': + case $this->namespaces['rss1'] . ':AUTHOR': + case $this->namespaces['rss2'] . ':AUTHOR': + case $this->namespaces['atom'] . ':AUTHOR': + $this->author_number++; + $this->inside_author = false; + break; + + case 'CATEGORY': + case $this->namespaces['rss1'] . ':CATEGORY': + case $this->namespaces['rss2'] . ':CATEGORY': + case $this->namespaces['atom'] . ':CATEGORY': + case $this->namespaces['dc'] . ':SUBJECT': + $this->category_number++; + break; + + case 'ENCLOSURE': + case $this->namespaces['rss1'] . ':ENCLOSURE': + case $this->namespaces['rss2'] . ':ENCLOSURE': + $this->enclosure_number++; + break; + + case 'LINK': + case $this->namespaces['rss1'] . ':LINK': + case $this->namespaces['rss2'] . ':LINK': + case $this->namespaces['atom'] . ':LINK': + if ($this->inside_item) + { + $this->item_link_number++; + } + else + { + $this->link_number++; + } + break; + } + if ($this->inside_item) + { + $this->depth_inside_item--; + } + } + + function start_name_space($parser, $prefix, $uri = null) + { + $prefix = strtoupper($prefix); + $uri = strtoupper($uri); + if ($prefix == 'ATOM' || $uri == 'HTTP://WWW.W3.ORG/2005/ATOM' || $uri == 'HTTP://PURL.ORG/ATOM/NS#') + { + $this->namespaces['atom'] = $uri; + } + else if ($prefix == 'RSS2' || $uri == 'HTTP://BACKEND.USERLAND.COM/RSS2') + { + $this->namespaces['rss2'] = $uri; + } + else if ($prefix == 'RDF' || $uri == 'HTTP://WWW.W3.ORG/1999/02/22-RDF-SYNTAX-NS#') + { + $this->namespaces['rdf'] = $uri; + } + else if ($prefix == 'RSS' || $uri == 'HTTP://PURL.ORG/RSS/1.0/' || $uri == 'HTTP://MY.NETSCAPE.COM/RDF/SIMPLE/0.9/') + { + $this->namespaces['rss1'] = $uri; + } + else if ($prefix == 'DC' || $uri == 'HTTP://PURL.ORG/DC/ELEMENTS/1.1/') + { + $this->namespaces['dc'] = $uri; + } + else if ($prefix == 'XHTML' || $uri == 'HTTP://WWW.W3.ORG/1999/XHTML') + { + $this->namespaces['xhtml'] = $uri; + $this->xhtml_prefix = $prefix; + } + else if ($prefix == 'CONTENT' || $uri == 'HTTP://PURL.ORG/RSS/1.0/MODULES/CONTENT/') + { + $this->namespaces['content'] = $uri; + } + } + + function end_name_space($parser, $prefix) + { + if ($key = array_search(strtoupper($prefix), $this->namespaces)) + { + if ($key == 'atom') + { + $this->namespaces['atom'] = 'ATOM'; + } + else if ($key == 'rss2') + { + $this->namespaces['rss2'] = 'RSS'; + } + else if ($key == 'rdf') + { + $this->namespaces['rdf'] = 'RDF'; + } + else if ($key == 'rss1') + { + $this->namespaces['rss1'] = 'RSS'; + } + else if ($key == 'dc') + { + $this->namespaces['dc'] = 'DC'; + } + else if ($key == 'xhtml') + { + $this->namespaces['xhtml'] = 'XHTML'; + $this->xhtml_prefix = 'XHTML'; + } + else if ($key == 'content') + { + $this->namespaces['content'] = 'CONTENT'; + } + } + } +} + +class SimplePie_Sanitize +{ + // Private vars + var $feedinfo; + var $info; + var $items; + var $feed_xmlbase; + var $item_xmlbase; + var $attribs; + var $cached_entities; + var $cache_convert_entities; + + // Options + var $remove_div = true; + var $strip_ads = false; + var $replace_headers = false; + var $bypass_image_hotlink = false; + var $bypass_image_hotlink_page = false; + var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'); + var $encode_instead_of_strip = false; + var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur'); + var $input_encoding = 'UTF-8'; + var $output_encoding = 'UTF-8'; + var $item_class = 'SimplePie_Item'; + var $author_class = 'SimplePie_Author'; + var $enclosure_class = 'SimplePie_Enclosure'; + + function remove_div($enable = true) + { + $this->remove_div = (bool) $enable; + } + + function strip_ads($enable = false) + { + $this->strip_ads = (bool) $enable; + } + + function replace_headers($enable = false) + { + $this->enable_headers = (bool) $enable; + } + + function bypass_image_hotlink($get = false) + { + if ($get) + { + $this->bypass_image_hotlink = (string) $get; + } + else + { + $this->bypass_image_hotlink = false; + } + } + + function bypass_image_hotlink_page($page = false) + { + if ($page) + { + $this->bypass_image_hotlink_page = (string) $page; + } + else + { + $this->bypass_image_hotlink_page = false; + } + } + + function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style')) + { + if ($tags) + { + if (is_array($tags)) + { + $this->strip_htmltags = $tags; + } + else + { + $this->strip_htmltags = explode(',', $tags); + } + } + else + { + $this->strip_htmltags = false; + } + } + + function encode_instead_of_strip($enable = false) + { + $this->encode_instead_of_strip = (bool) $enable; + } + + function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur')) + { + if ($attribs) + { + if (is_array($attribs)) + { + $this->strip_attributes = $attribs; + } + else + { + $this->strip_attributes = explode(',', $attribs); + } + } + else + { + $this->strip_attributes = false; + } + } + + function input_encoding($encoding = 'UTF-8') + { + $this->input_encoding = (string) $encoding; + } + + function output_encoding($encoding = 'UTF-8') + { + $this->output_encoding = (string) $encoding; + } + + function set_item_class($class = 'SimplePie_Item') + { + if (SimplePie_Misc::is_a_class($class, 'SimplePie_Item')) + { + $this->item_class = $class; + return true; + } + return false; + } + + function set_author_class($class = 'SimplePie_Author') + { + if (SimplePie_Misc::is_a_class($class, 'SimplePie_Author')) + { + $this->author_class = $class; + return true; + } + return false; + } + + function set_enclosure_class($class = 'SimplePie_Enclosure') + { + if (SimplePie_Misc::is_a_class($class, 'SimplePie_Enclosure')) + { + $this->enclosure_class = $class; + return true; + } + return false; + } + + function parse_data_array(&$data, $url) + { + // Feed Info (Type and Version) + if (!empty($data['feedinfo']['type'])) + { + $this->feedinfo = $data['feedinfo']; + } + + // Feed level xml:base + if (!empty($data['feeddata']['attribs']['XML:BASE'])) + { + $this->feed_xmlbase = $data['feeddata']['attribs']['XML:BASE']; + } + else if (!empty($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'])) + { + $this->feed_xmlbase = $data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE']; + } + // FeedBurner feeds use alternate link + else if (strpos($url, 'http://feeds.feedburner.com/') !== 0) + { + $this->feed_xmlbase = SimplePie_Misc::parse_url($url); + if (empty($this->feed_xmlbase['authority'])) + { + $this->feed_xmlbase = preg_replace('/^' . preg_quote(realpath($_SERVER['DOCUMENT_ROOT']), '/') . '/', '', realpath($url)); + } + else + { + $this->feed_xmlbase = $url; + } + } + + + // Feed link(s) + if (!empty($data['info']['link'])) + { + foreach ($data['info']['link'] as $link) + { + if (empty($link['attribs']['REL'])) + { + $rel = 'alternate'; + } + else + { + $rel = strtolower($link['attribs']['REL']); + } + if ($rel == 'enclosure') + { + $href = null; + $type = null; + $length = null; + if (!empty($link['data'])) + { + $href = $this->sanitize($link['data'], $link['attribs'], true); + } + else if (!empty($link['attribs']['HREF'])) + { + $href = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true); + } + if (!empty($link['attribs']['TYPE'])) { + $type = $this->sanitize($link['attribs']['TYPE'], $link['attribs']); + } + if (!empty($link['attribs']['LENGTH'])) { + $length = $this->sanitize($link['attribs']['LENGTH'], $link['attribs']); + } + $this->info['link']['enclosure'][] = new $this->enclosure_class($href, $type, $length); + } + else + { + if (!empty($link['data'])) + { + $this->info['link'][$rel][] = $this->sanitize($link['data'], $link['attribs'], true); + } + else if (!empty($link['attribs']['HREF'])) + { + $this->info['link'][$rel][] = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true); + } + } + } + } + + // Use the first alternate link if we don't have any feed xml:base + if (empty($this->feed_xmlbase) && !empty($this->info['link']['alternate'][0])) + { + $this->feed_xmlbase = $this->info['link']['alternate'][0]; + } + + // Feed Title + if (!empty($data['info']['title']['data'])) + { + $this->info['title'] = $this->sanitize($data['info']['title']['data'], $data['info']['title']['attribs']); + } + + // Feed Descriptions + if (!empty($data['info']['description']['data'])) + { + $this->info['description'] = $this->sanitize($data['info']['description']['data'], $data['info']['description']['attribs'], false, true); + } + if (!empty($data['info']['dc:description']['data'])) + { + $this->info['dc:description'] = $this->sanitize($data['info']['dc:description']['data'], $data['info']['dc:description']['attribs']); + } + if (!empty($data['info']['tagline']['data'])) + { + $this->info['tagline'] = $this->sanitize($data['info']['tagline']['data'], $data['info']['tagline']['attribs']); + } + if (!empty($data['info']['subtitle']['data'])) + { + $this->info['subtitle'] = $this->sanitize($data['info']['subtitle']['data'], $data['info']['subtitle']['attribs']); + } + + // Feed Language + if (!empty($data['info']['language']['data'])) + { + $this->info['language'] = $this->sanitize($data['info']['language']['data'], $data['info']['language']['attribs']); + } + if (!empty($data['feeddata']['attribs']['XML:LANG'])) + { + $this->info['xml:lang'] = $this->sanitize($data['feeddata']['attribs']['XML:LANG'], null); + } + else if (!empty($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:LANG'])) + { + $this->info['xml:lang'] = $this->sanitize($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:LANG'], null); + } + + // Feed Copyright + if (!empty($data['info']['copyright']['data'])) + { + $this->info['copyright'] = $this->sanitize($data['info']['copyright']['data'], $data['info']['copyright']['attribs']); + } + + // Feed Image + if (!empty($data['info']['image']['title']['data'])) + { + $this->info['image']['title'] = $this->sanitize($data['info']['image']['title']['data'], $data['info']['image']['title']['attribs']); + } + if (!empty($data['info']['image']['url']['data'])) + { + $this->info['image']['url'] = $this->sanitize($data['info']['image']['url']['data'], $data['info']['image']['url']['attribs'], true); + } + if (!empty($data['info']['logo']['data'])) + { + $this->info['image']['logo'] = $this->sanitize($data['info']['logo']['data'], $data['info']['logo']['attribs'], true); + } + if (!empty($data['info']['image']['link']['data'])) + { + $this->info['image']['link'] = $this->sanitize($data['info']['image']['link']['data'], $data['info']['image']['link']['attribs'], true); + } + if (!empty($data['info']['image']['width']['data'])) + { + $this->info['image']['width'] = $this->sanitize($data['info']['image']['width']['data'], $data['info']['image']['width']['attribs']); + } + if (!empty($data['info']['image']['height']['data'])) + { + $this->info['image']['height'] = $this->sanitize($data['info']['image']['height']['data'], $data['info']['image']['height']['attribs']); + } + + // Items + if (!empty($data['items'])) + { + foreach ($data['items'] as $key => $item) + { + $newitem = null; + + // Item level xml:base + if (!empty($item['attribs']['XML:BASE'])) + { + $this->item_xmlbase = SimplePie_Misc::absolutize_url($item['attribs']['XML:BASE'], $this->feed_xmlbase); + } + else if (!empty($item['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'])) + { + $this->item_xmlbase = SimplePie_Misc::absolutize_url($item['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'], $this->feed_xmlbase); + } + else + { + $this->item_xmlbase = null; + } + + // Title + if (!empty($item['title']['data'])) { + $newitem['title'] = $this->sanitize($item['title']['data'], $item['title']['attribs']); + } + if (!empty($item['dc:title']['data'])) + { + $newitem['dc:title'] = $this->sanitize($item['dc:title']['data'], $item['dc:title']['attribs']); + } + + // Description + if (!empty($item['content']['data'])) + { + $newitem['content'] = $this->sanitize($item['content']['data'], $item['content']['attribs']); + } + if (!empty($item['encoded']['data'])) + { + $newitem['encoded'] = $this->sanitize($item['encoded']['data'], $item['encoded']['attribs']); + } + if (!empty($item['summary']['data'])) + { + $newitem['summary'] = $this->sanitize($item['summary']['data'], $item['summary']['attribs']); + } + if (!empty($item['description']['data'])) + { + $newitem['description'] = $this->sanitize($item['description']['data'], $item['description']['attribs'], false, true); + } + if (!empty($item['dc:description']['data'])) + { + $newitem['dc:description'] = $this->sanitize($item['dc:description']['data'], $item['dc:description']['attribs']); + } + if (!empty($item['longdesc']['data'])) + { + $newitem['longdesc'] = $this->sanitize($item['longdesc']['data'], $item['longdesc']['attribs']); + } + + // Link(s) + if (!empty($item['link'])) + { + foreach ($item['link'] as $link) + { + if (empty($link['attribs']['REL'])) + { + $rel = 'alternate'; + } + else + { + $rel = strtolower($link['attribs']['REL']); + } + if ($rel == 'enclosure') + { + $href = null; + $type = null; + $length = null; + if (!empty($link['data'])) + { + $href = $this->sanitize($link['data'], $link['attribs'], true); + } + else if (!empty($link['attribs']['HREF'])) + { + $href = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true); + } + if (!empty($link['attribs']['TYPE'])) { + $type = $this->sanitize($link['attribs']['TYPE'], $link['attribs']); + } + if (!empty($link['attribs']['LENGTH'])) { + $length = $this->sanitize($link['attribs']['LENGTH'], $link['attribs']); + } + if (!empty($href)) + { + $newitem['link'][$rel][] = new $this->enclosure_class($href, $type, $length); + } + } + else + { + if (!empty($link['data'])) + { + $newitem['link'][$rel][] = $this->sanitize($link['data'], $link['attribs'], true); + } + else if (!empty($link['attribs']['HREF'])) + { + $newitem['link'][$rel][] = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true); + } + } + } + } + + // Enclosure(s) + if (!empty($item['enclosure'])) + { + foreach ($item['enclosure'] as $enclosure) + { + if (!empty($enclosure['attribs']['URL'])) + { + $type = null; + $length = null; + $href = $this->sanitize($enclosure['attribs']['URL'], $enclosure['attribs'], true); + if (!empty($enclosure['attribs']['TYPE'])) + { + $type = $this->sanitize($enclosure['attribs']['TYPE'], $enclosure['attribs']); + } + if (!empty($enclosure['attribs']['LENGTH'])) + { + $length = $this->sanitize($enclosure['attribs']['LENGTH'], $enclosure['attribs']); + } + $newitem['enclosures'][] = new $this->enclosure_class($href, $type, $length); + } + } + } + + // ID + if (!empty($item['guid']['data'])) + { + if (!empty($item['guid']['attribs']['ISPERMALINK']) && strtolower($item['guid']['attribs']['ISPERMALINK']) == 'false') + { + $newitem['guid']['permalink'] = false; + } + else + { + $newitem['guid']['permalink'] = true; + } + $newitem['guid']['data'] = $this->sanitize($item['guid']['data'], $item['guid']['attribs']); + } + if (!empty($item['id']['data'])) + { + $newitem['id'] = $this->sanitize($item['id']['data'], $item['id']['attribs']); + } + + // Date + if (!empty($item['pubdate']['data'])) + { + $newitem['pubdate'] = $this->parse_date($this->sanitize($item['pubdate']['data'], $item['pubdate']['attribs'])); + } + if (!empty($item['dc:date']['data'])) + { + $newitem['dc:date'] = $this->parse_date($this->sanitize($item['dc:date']['data'], $item['dc:date']['attribs'])); + } + if (!empty($item['issued']['data'])) + { + $newitem['issued'] = $this->parse_date($this->sanitize($item['issued']['data'], $item['issued']['attribs'])); + } + if (!empty($item['published']['data'])) + { + $newitem['published'] = $this->parse_date($this->sanitize($item['published']['data'], $item['published']['attribs'])); + } + if (!empty($item['modified']['data'])) + { + $newitem['modified'] = $this->parse_date($this->sanitize($item['modified']['data'], $item['modified']['attribs'])); + } + if (!empty($item['updated']['data'])) + { + $newitem['updated'] = $this->parse_date($this->sanitize($item['updated']['data'], $item['updated']['attribs'])); + } + + // Categories + if (!empty($item['category'])) + { + foreach ($item['category'] as $category) + { + if (!empty($category['data'])) + { + $newitem['category'][] = $this->sanitize($category['data'], $category['attribs']); + } + else if (!empty($category['attribs']['TERM'])) + { + $newitem['term'][] = $this->sanitize($category['attribs']['TERM'], $category['attribs']); + } + } + } + if (!empty($item['subject'])) + { + foreach ($item['subject'] as $category) + { + if (!empty($category['data'])) + { + $newitem['subject'][] = $this->sanitize($category['data'], $category['attribs']); + } + } + } + + // Author + if (!empty($item['creator'])) + { + foreach ($item['creator'] as $creator) + { + if (!empty($creator['data'])) + { + $newitem['creator'][] = new $this->author_class($this->sanitize($creator['data'], $creator['attribs']), null, null); + } + } + } + if (!empty($item['author'])) + { + foreach ($item['author'] as $author) + { + $name = null; + $link = null; + $email = null; + if (!empty($author['rss'])) + { + $sane = $this->sanitize($author['rss']['data'], $author['rss']['attribs']); + if (preg_match('/(.*)@(.*) ((.*))/msiU', $sane, $matches)) { + $name = trim($matches[3]); + $email = trim("$matches[1]@$matches[2]"); + } else { + $email = $sane; + } + } + else + { + if (!empty($author['name'])) + { + $name = $this->sanitize($author['name']['data'], $author['name']['attribs']); + } + if (!empty($author['url'])) + { + $link = $this->sanitize($author['url']['data'], $author['url']['attribs'], true); + } + else if (!empty($author['uri'])) + { + $link = $this->sanitize($author['uri']['data'], $author['uri']['attribs'], true); + } + else if (!empty($author['homepage'])) + { + $link = $this->sanitize($author['homepage']['data'], $author['homepage']['attribs'], true); + } + if (!empty($author['email'])) { + $email = $this->sanitize($author['email']['data'], $author['email']['attribs']); + } + } + $newitem['author'][] = new $this->author_class($name, $link, $email); + } + } + unset($data['items'][$key]); + $this->items[] = new $this->item_class($newitem); + } + } + } + + function sanitize($data, $attribs, $is_url = false, $force_decode = false) + { + $this->attribs = $attribs; + if (isset($this->feedinfo['type']) && $this->feedinfo['type'] == 'Atom') + { + if ((!empty($attribs['MODE']) && $attribs['MODE'] == 'base64') || (!empty($attribs['TYPE']) && $attribs['TYPE'] == 'application/octet-stream')) + { + $data = trim($data); + $data = base64_decode($data); + } + else if ((!empty($attribs['MODE']) && $attribs['MODE'] == 'escaped' || !empty($attribs['TYPE']) && ($attribs['TYPE'] == 'html' || $attribs['TYPE'] == 'text/html'))) + { + $data = $this->entities_decode($data); + } + if (!empty($attribs['TYPE']) && ($attribs['TYPE'] == 'xhtml' || $attribs['TYPE'] == 'application/xhtml+xml')) + { + if ($this->remove_div) + { + $data = preg_replace('/<div( .*)?>/msiU', '', strrev(preg_replace('/>vid/</i', '', strrev($data), 1)), 1); + } + else + { + $data = preg_replace('/<div( .*)?>/msiU', '<div>', $data, 1); + } + $data = $this->convert_entities($data); + } + } + else + { + $data = $this->convert_entities($data); + } + if ($force_decode) + { + $data = $this->entities_decode($data); + } + $data = trim($data); + $data = preg_replace('/<!--([^-]|-[^-])*-->/msiU', '', $data); + + // If Strip Ads is enabled, strip them. + if ($this->strip_ads) + { + $data = preg_replace('/<a (.*)href=(.*)click.phdo?s=(.*)</a>/msiU', '', $data); // Pheedo links (tested with Dooce.com) + $data = preg_replace('/<p(.*)>(.*)<a href="http://ad.doubleclick.net/jump/(.*)</p>/msiU', '', $data); // Doubleclick links (tested with InfoWorld.com) + $data = preg_replace('/<p><map (.*)name=(.*)google_ad_map(.*)</p>/msiU', '', $data); // Google AdSense for Feeds (tested with tuaw.com). + // Feedflare, from Feedburner + } + + // Replace H1, H2, and H3 tags with the less important H4 tags. + // This is because on a site, the more important headers might make sense, + // but it most likely doesn't fit in the context of RSS-in-a-webpage. + if ($this->replace_headers) + { + $data = preg_replace('/<h[1-3]((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|'([^']*)'|(.*)))*)\s*>/msiU', '<h4\1>', $data); + $data = preg_replace('/</h[1-3]>/i', '</h4>', $data); + } + + if ($is_url) + { + $data = $this->replace_urls($data, true); + } + else + { + $data = preg_replace_callback('/<(\S+)((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|'([^']*)'|(.*)))*)\s*(/>|>(.*)</\S+>)/msiU', array(&$this, 'replace_urls'), $data); + } + + // If Bypass Image Hotlink is enabled, rewrite all the image tags. + if ($this->bypass_image_hotlink) + { + $images = SimplePie_Misc::get_element('img', $data); + foreach ($images as $img) + { + if (!empty($img['attribs']['SRC']['data'])) + { + $pre = ''; + if ($this->bypass_image_hotlink_page) + { + $pre = $this->bypass_image_hotlink_page; + } + $pre .= "?$this->bypass_image_hotlink="; + $img['attribs']['SRC']['data'] = $pre . rawurlencode(strtr($img['attribs']['SRC']['data'], array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)))); + $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data); + } + } + } + + // Strip out HTML tags and attributes that might cause various security problems. + // Based on recommendations by Mark Pilgrim at: + // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely + if ($this->strip_htmltags) + { + foreach ($this->strip_htmltags as $tag) + { + $data = preg_replace_callback("/<($tag)((\s*((\w+:)?\w+)(\s*=\s*("([^"]*)"|'([^']*)'|(.*)))?)*)\s*(/>|>(.*)</($tag)((\s*((\w+:)?\w+)(\s*=\s*("([^"]*)"|'([^']*)'|(.*)))?)*)\s*>)/msiU", array(&$this, 'do_strip_htmltags'), $data); + } + } + + if ($this->strip_attributes) + { + foreach ($this->strip_attributes as $attrib) + { + $data = preg_replace('/ '. trim($attrib) .'=("|")(\w|\s|=|-|:|;|/|.|?|&|,|#|!|(|)|'|'|<|>|+|{|})*("|")/i', '', $data); + $data = preg_replace('/ '. trim($attrib) .'=('|')(\w|\s|=|-|:|;|/|.|?|&|,|#|!|(|)|"|"|<|>|+|{|})*('|')/i', '', $data); + $data = preg_replace('/ '. trim($attrib) .'=(\w|\s|=|-|:|;|/|.|?|&|,|#|!|(|)|+|{|})*/i', '', $data); + } + } + + // Convert encoding + $data = SimplePie_Misc::change_encoding($data, $this->input_encoding, $this->output_encoding); + + return $data; + } + + function do_strip_htmltags($match) + { + if ($this->encode_instead_of_strip) + { + if (isset($match[12]) && !in_array(strtolower($match[1]), array('script', 'style'))) + { + return "<$match[1]$match[2]>$match[12]</$match[1]>"; + } + else if (isset($match[12])) + { + return "<$match[1]$match[2]></$match[1]>"; + } + else + { + return "<$match[1]$match[2]/>"; + } + } + else + { + if (isset($match[12]) && !in_array(strtolower($match[1]), array('script', 'style'))) + { + return $match[12]; + } + else + { + return ''; + } + } + } + + function replace_urls($data, $raw_url = false) + { + if (!empty($this->attribs['XML:BASE'])) + { + $xmlbase = $attribs['XML:BASE']; + } + else if (!empty($this->attribs['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'])) + { + $xmlbase = $this->attribs['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE']; + } + if (!empty($xmlbase)) + { + if (!empty($this->item_xmlbase)) + { + $xmlbase = SimplePie_Misc::absolutize_url($xmlbase, $this->item_xmlbase); + } + else + { + $xmlbase = SimplePie_Misc::absolutize_url($xmlbase, $this->feed_xmlbase); + } + } + else if (!empty($this->item_xmlbase)) + { + $xmlbase = $this->item_xmlbase; + } + else + { + $xmlbase = $this->feed_xmlbase; + } + + if ($raw_url) + { + return SimplePie_Misc::absolutize_url($data, $xmlbase); + } + else + { + $attributes = array( + 'background', + 'href', + 'src', + 'longdesc', + 'usemap', + 'codebase', + 'data', + 'classid', + 'cite', + 'action', + 'profile', + 'for' + ); + foreach ($attributes as $attribute) + { + if (preg_match("/$attribute='(.*)'/siU", $data[0], $attrib) || preg_match("/$attribute="(.*)"/siU", $data[0], $attrib) || preg_match("/$attribute=(.*)[ |/|>]/siU", $data[0], $attrib)) + { + $new_tag = str_replace($attrib[1], SimplePie_Misc::absolutize_url($attrib[1], $xmlbase), $attrib[0]); + $data[0] = str_replace($attrib[0], $new_tag, $data[0]); + } + } + return $data[0]; + } + } + + function entities_decode($data) + { + return preg_replace_callback('/&(#)?(x)?([0-9a-z]+);/mi', array(&$this, 'do_entites_decode'), $data); + } + + function do_entites_decode($data) + { + if (isset($this->cached_entities[$data[0]])) + { + return $this->cached_entities[$data[0]]; + } + else + { + $return = SimplePie_Misc::change_encoding(html_entity_decode($data[0], ENT_QUOTES), 'ISO-8859-1', $this->input_encoding); + if ($return == $data[0]) + { + $return = SimplePie_Misc::change_encoding(preg_replace_callback('/&#([x]?[0-9a-f]+);/mi', array(&$this, 'replace_num_entity'), $data[0]), 'UTF-8', $this->input_encoding); + } + $this->cached_entities[$data[0]] = $return; + return $return; + } + } + + function convert_entities($data) + { + return preg_replace_callback('/&#(x)?([0-9a-z]+);/mi', array(&$this, 'do_convert_entities'), $data); + } + + function do_convert_entities($data) + { + if (isset($this->cache_convert_entities[$data[0]])) + { + return $this->cache_convert_entities[$data[0]]; + } + else if (isset($this->cached_entities[$data[0]])) + { + $return = htmlentities($this->cached_entities[$data[0]], ENT_QUOTES, 'UTF-8'); + } + else + { + $return = htmlentities(preg_replace_callback('/&#([x]?[0-9a-f]+);/mi', array(&$this, 'replace_num_entity'), $data[0]), ENT_QUOTES, 'UTF-8'); + } + $this->cache_convert_entities[$data[0]] = $return; + return $return; + } + + /* + * Escape numeric entities + * From a PHP Manual note (on html_entity_decode()) + * Copyright (c) 2005 by "php dot net at c dash ovidiu dot tk", + * "emilianomartinezluque at yahoo dot com" and "hurricane at cyberworldz dot org". + * + * This material may be distributed only subject to the terms and conditions set forth in + * the Open Publication License, v1.0 or later (the latest version is presently available at + * http://www.opencontent.org/openpub/). + */ + function replace_num_entity($ord) + { + $ord = $ord[1]; + if (preg_match('/^x([0-9a-f]+)$/i', $ord, $match)) + { + $ord = hexdec($match[1]); + } + else + { + $ord = intval($ord); + } + + $no_bytes = 0; + $byte = array(); + if ($ord < 128) + { + return chr($ord); + } + if ($ord < 2048) + { + $no_bytes = 2; + } + else if ($ord < 65536) + { + $no_bytes = 3; + } + else if ($ord < 1114112) + { + $no_bytes = 4; + } + else + { + return; + } + switch ($no_bytes) + { + case 2: + $prefix = array(31, 192); + break; + + case 3: + $prefix = array(15, 224); + break; + + case 4: + $prefix = array(7, 240); + break; + } + + for ($i = 0; $i < $no_bytes; $i++) + { + $byte[$no_bytes-$i-1] = (($ord & (63 * pow(2,6*$i))) / pow(2,6*$i)) & 63 | 128; + } + $byte[0] = ($byte[0] & $prefix[0]) | $prefix[1]; + + $ret = ''; + for ($i = 0; $i < $no_bytes; $i++) + { + $ret .= chr($byte[$i]); + } + return $ret; + } + + function parse_date($date) + { + $military_timezone = array('A' => '-0100', 'B' => '-0200', 'C' => '-0300', 'D' => '-0400', 'E' => '-0500', 'F' => '-0600', 'G' => '-0700', 'H' => '-0800', 'I' => '-0900', 'K' => '-1000', 'L' => '-1100', 'M' => '-1200', 'N' => '+0100', 'O' => '+0200', 'P' => '+0300', 'Q' => '+0400', 'R' => '+0500', 'S' => '+0600', 'T' => '+0700', 'U' => '+0800', 'V' => '+0900', 'W' => '+1000', 'X' => '+1100', 'Y' => '+1200', 'Z' => '-0000'); + $north_american_timezone = array('GMT' => '-0000', 'EST' => '-0500', 'EDT' => '-0400', 'CST' => '-0600', 'CDT' => '-0500', 'MST' => '-0700', 'MDT' => '-0600', 'PST' => '-0800', 'PDT' => '-0700'); + if (preg_match('/([0-9]{2,4})-?([0-9]{2})-?([0-9]{2})T([0-9]{2}):?([0-9]{2})(:?([0-9]{2}(.[0-9]*)?))?(UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[a-z]|(\+|-)[0-9]{4}|(\+|-)[0-9]{2}:[0-9]{2})?/i', $date, $matches)) + { + if (!isset($matches[7])) + { + $matches[7] = ''; + } + if (!isset($matches[9])) + { + $matches[9] = ''; + } + $matches[7] = str_pad(round($matches[7]), 2, '0', STR_PAD_LEFT); + switch (strlen($matches[9])) + { + case 0: + $timezone = ''; + break; + + case 1: + $timezone = $military_timezone[strtoupper($matches[9])]; + break; + + case 2: + $timezone = '-0000'; + break; + + case 3: + $timezone = $north_american_timezone[strtoupper($matches[9])]; + break; + + case 5: + $timezone = $matches[9]; + break; + + case 6: + $timezone = substr_replace($matches[9], '', 3, 1); + break; + } + $date = strtotime("$matches[1]-$matches[2]-$matches[3] $matches[4]:$matches[5]:$matches[7] $timezone"); + } + else if (preg_match('/([0-9]{1,2})\s*(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s*([0-9]{2}|[0-9]{4})\s*([0-9]{2}):([0-9]{2})(:([0-9]{2}(.[0-9]*)?))?\s*(UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[a-z]|(\+|-)[0-9]{4}|(\+|-)[0-9]{2}:[0-9]{2})?/i', $date, $matches)) + { + $three_month = array('Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12); + $month = $three_month[$matches[2]]; + if (strlen($matches[3]) == 2) + { + $year = ($matches[3] < 70) ? "20$matches[3]" : "19$matches[3]"; + } + else + { + $year = $matches[3]; + } + if (!isset($matches[7])) + { + $matches[7] = ''; + } + if (!isset($matches[9])) + { + $matches[9] = ''; + } + $second = str_pad(round($matches[7]), 2, '0', STR_PAD_LEFT); + switch (strlen($matches[9])) + { + case 0: + $timezone = ''; + break; + + case 1: + $timezone = $military_timezone[strtoupper($matches[9])]; + break; + + case 2: + $timezone = '-0000'; + break; + + case 3: + $timezone = $north_american_timezone[strtoupper($matches[9])]; + break; + + case 5: + $timezone = $matches[9]; + break; + + case 6: + $timezone = substr_replace($matches[9], '', 3, 1); + break; + } + $date = strtotime("$year-$month-$matches[1] $matches[4]:$matches[5]:$second $timezone"); + } + else + { + $date = strtotime($date); + } + if ($date !== false && $date !== -1) + { + return $date; + } + else + { + return false; + } + } +} + +?> \ No newline at end of file
Added: www-website/planet/app/lib/spyc-0.2.3/spyc.php =================================================================== --- www-website/planet/app/lib/spyc-0.2.3/spyc.php (rev 0) +++ www-website/planet/app/lib/spyc-0.2.3/spyc.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,853 @@ +<?php + /** + * Spyc -- A Simple PHP YAML Class + * @version 0.2.3 -- 2006-02-04 + * @author Chris Wanstrath <chris@ozmm.org> + * @link http://spyc.sourceforge.net/ + * @copyright Copyright 2005-2006 Chris Wanstrath + * @license http://www.opensource.org/licenses/mit-license.php MIT License + * @package Spyc + */ + + /** + * A node, used by Spyc for parsing YAML. + * @package Spyc + */ + class YAMLNode { + /**#@+ + * @access public + * @var string + */ + var $parent; + var $id; + /**#@+*/ + /** + * @access public + * @var mixed + */ + var $data; + /** + * @access public + * @var int + */ + var $indent; + /** + * @access public + * @var bool + */ + var $children = false; + + /** + * The constructor assigns the node a unique ID. + * @access public + * @return void + */ + function YAMLNode() { + $this->id = uniqid(''); + } + } + + /** + * The Simple PHP YAML Class. + * + * This class can be used to read a YAML file and convert its contents + * into a PHP array. It currently supports a very limited subsection of + * the YAML spec. + * + * Usage: + * <code> + * $parser = new Spyc; + * $array = $parser->load($file); + * </code> + * @package Spyc + */ + class Spyc { + + /** + * Load YAML into a PHP array statically + * + * The load method, when supplied with a YAML stream (string or file), + * will do its best to convert YAML in a file into a PHP array. Pretty + * simple. + * Usage: + * <code> + * $array = Spyc::YAMLLoad('lucky.yml'); + * print_r($array); + * </code> + * @access public + * @return array + * @param string $input Path of YAML file or string containing YAML + */ + function YAMLLoad($input) { + $spyc = new Spyc; + return $spyc->load($input); + } + + /** + * Dump YAML from PHP array statically + * + * The dump method, when supplied with an array, will do its best + * to convert the array into friendly YAML. Pretty simple. Feel free to + * save the returned string as nothing.yml and pass it around. + * + * Oh, and you can decide how big the indent is and what the wordwrap + * for folding is. Pretty cool -- just pass in 'false' for either if + * you want to use the default. + * + * Indent's default is 2 spaces, wordwrap's default is 40 characters. And + * you can turn off wordwrap by passing in 0. + * + * @access public + * @return string + * @param array $array PHP array + * @param int $indent Pass in false to use the default, which is 2 + * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40) + */ + function YAMLDump($array,$indent = false,$wordwrap = false) { + $spyc = new Spyc; + return $spyc->dump($array,$indent,$wordwrap); + } + + /** + * Load YAML into a PHP array from an instantiated object + * + * The load method, when supplied with a YAML stream (string or file path), + * will do its best to convert the YAML into a PHP array. Pretty simple. + * Usage: + * <code> + * $parser = new Spyc; + * $array = $parser->load('lucky.yml'); + * print_r($array); + * </code> + * @access public + * @return array + * @param string $input Path of YAML file or string containing YAML + */ + function load($input) { + // See what type of input we're talking about + // If it's not a file, assume it's a string + if (!empty($input) && (strpos($input, "\n") === false) + && file_exists($input)) { + $yaml = file($input); + } else { + $yaml = explode("\n",$input); + } + // Initiate some objects and values + $base = new YAMLNode; + $base->indent = 0; + $this->_lastIndent = 0; + $this->_lastNode = $base->id; + $this->_inBlock = false; + $this->_isInline = false; + + foreach ($yaml as $linenum => $line) { + $ifchk = trim($line); + + // If the line starts with a tab (instead of a space), throw a fit. + if (preg_match('/^(\t)+(\w+)/', $line)) { + $err = 'ERROR: Line '. ($linenum + 1) .' in your input YAML begins'. + ' with a tab. YAML only recognizes spaces. Please reformat.'; + die($err); + } + + if ($this->_inBlock === false && empty($ifchk)) { + continue; + } elseif ($this->_inBlock == true && empty($ifchk)) { + $last =& $this->_allNodes[$this->_lastNode]; + $last->data[key($last->data)] .= "\n"; + } elseif ($ifchk{0} != '#' && substr($ifchk,0,3) != '---') { + // Create a new node and get its indent + $node = new YAMLNode; + $node->indent = $this->_getIndent($line); + + // Check where the node lies in the hierarchy + if ($this->_lastIndent == $node->indent) { + // If we're in a block, add the text to the parent's data + if ($this->_inBlock === true) { + $parent =& $this->_allNodes[$this->_lastNode]; + $parent->data[key($parent->data)] .= trim($line).$this->_blockEnd; + } else { + // The current node's parent is the same as the previous node's + if (isset($this->_allNodes[$this->_lastNode])) { + $node->parent = $this->_allNodes[$this->_lastNode]->parent; + } + } + } elseif ($this->_lastIndent < $node->indent) { + if ($this->_inBlock === true) { + $parent =& $this->_allNodes[$this->_lastNode]; + $parent->data[key($parent->data)] .= trim($line).$this->_blockEnd; + } elseif ($this->_inBlock === false) { + // The current node's parent is the previous node + $node->parent = $this->_lastNode; + + // If the value of the last node's data was > or | we need to + // start blocking i.e. taking in all lines as a text value until + // we drop our indent. + $parent =& $this->_allNodes[$node->parent]; + $this->_allNodes[$node->parent]->children = true; + if (is_array($parent->data)) { + $chk = $parent->data[key($parent->data)]; + if ($chk === '>') { + $this->_inBlock = true; + $this->_blockEnd = ' '; + $parent->data[key($parent->data)] = + str_replace('>','',$parent->data[key($parent->data)]); + $parent->data[key($parent->data)] .= trim($line).' '; + $this->_allNodes[$node->parent]->children = false; + $this->_lastIndent = $node->indent; + } elseif ($chk === '|') { + $this->_inBlock = true; + $this->_blockEnd = "\n"; + $parent->data[key($parent->data)] = + str_replace('|','',$parent->data[key($parent->data)]); + $parent->data[key($parent->data)] .= trim($line)."\n"; + $this->_allNodes[$node->parent]->children = false; + $this->_lastIndent = $node->indent; + } + } + } + } elseif ($this->_lastIndent > $node->indent) { + // Any block we had going is dead now + if ($this->_inBlock === true) { + $this->_inBlock = false; + if ($this->_blockEnd = "\n") { + $last =& $this->_allNodes[$this->_lastNode]; + $last->data[key($last->data)] = + trim($last->data[key($last->data)]); + } + } + + // We don't know the parent of the node so we have to find it + // foreach ($this->_allNodes as $n) { + foreach ($this->_indentSort[$node->indent] as $n) { + if ($n->indent == $node->indent) { + $node->parent = $n->parent; + } + } + } + + if ($this->_inBlock === false) { + // Set these properties with information from our current node + $this->_lastIndent = $node->indent; + // Set the last node + $this->_lastNode = $node->id; + // Parse the YAML line and return its data + $node->data = $this->_parseLine($line); + // Add the node to the master list + $this->_allNodes[$node->id] = $node; + // Add a reference to the node in an indent array + $this->_indentSort[$node->indent][] =& $this->_allNodes[$node->id]; + // Add a reference to the node in a References array if this node + // has a YAML reference in it. + if ( + ( (is_array($node->data)) && + isset($node->data[key($node->data)]) && + (!is_array($node->data[key($node->data)])) ) + && + ( (preg_match('/^&([^ ]+)/',$node->data[key($node->data)])) + || + (preg_match('/^\*([^ ]+)/',$node->data[key($node->data)])) ) + ) { + $this->_haveRefs[] =& $this->_allNodes[$node->id]; + } elseif ( + ( (is_array($node->data)) && + isset($node->data[key($node->data)]) && + (is_array($node->data[key($node->data)])) ) + ) { + // Incomplete reference making code. Ugly, needs cleaned up. + foreach ($node->data[key($node->data)] as $d) { + if ( !is_array($d) && + ( (preg_match('/^&([^ ]+)/',$d)) + || + (preg_match('/^\*([^ ]+)/',$d)) ) + ) { + $this->_haveRefs[] =& $this->_allNodes[$node->id]; + } + } + } + } + } + } + unset($node); + + // Here we travel through node-space and pick out references (& and *) + $this->_linkReferences(); + + // Build the PHP array out of node-space + $trunk = $this->_buildArray(); + return $trunk; + } + + /** + * Dump PHP array to YAML + * + * The dump method, when supplied with an array, will do its best + * to convert the array into friendly YAML. Pretty simple. Feel free to + * save the returned string as tasteful.yml and pass it around. + * + * Oh, and you can decide how big the indent is and what the wordwrap + * for folding is. Pretty cool -- just pass in 'false' for either if + * you want to use the default. + * + * Indent's default is 2 spaces, wordwrap's default is 40 characters. And + * you can turn off wordwrap by passing in 0. + * + * @access public + * @return string + * @param array $array PHP array + * @param int $indent Pass in false to use the default, which is 2 + * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40) + */ + function dump($array,$indent = false,$wordwrap = false) { + // Dumps to some very clean YAML. We'll have to add some more features + // and options soon. And better support for folding. + + // New features and options. + if ($indent === false or !is_numeric($indent)) { + $this->_dumpIndent = 2; + } else { + $this->_dumpIndent = $indent; + } + + if ($wordwrap === false or !is_numeric($wordwrap)) { + $this->_dumpWordWrap = 40; + } else { + $this->_dumpWordWrap = $wordwrap; + } + + // New YAML document + $string = "---\n"; + + // Start at the base of the array and move through it. + foreach ($array as $key => $value) { + $string .= $this->_yamlize($key,$value,0); + } + return $string; + } + + /**** Private Properties ****/ + + /**#@+ + * @access private + * @var mixed + */ + var $_haveRefs; + var $_allNodes; + var $_lastIndent; + var $_lastNode; + var $_inBlock; + var $_isInline; + var $_dumpIndent; + var $_dumpWordWrap; + /**#@+*/ + + /**** Private Methods ****/ + + /** + * Attempts to convert a key / value array item to YAML + * @access private + * @return string + * @param $key The name of the key + * @param $value The value of the item + * @param $indent The indent of the current node + */ + function _yamlize($key,$value,$indent) { + if (is_array($value)) { + // It has children. What to do? + // Make it the right kind of item + $string = $this->_dumpNode($key,NULL,$indent); + // Add the indent + $indent += $this->_dumpIndent; + // Yamlize the array + $string .= $this->_yamlizeArray($value,$indent); + } elseif (!is_array($value)) { + // It doesn't have children. Yip. + $string = $this->_dumpNode($key,$value,$indent); + } + return $string; + } + + /** + * Attempts to convert an array to YAML + * @access private + * @return string + * @param $array The array you want to convert + * @param $indent The indent of the current level + */ + function _yamlizeArray($array,$indent) { + if (is_array($array)) { + $string = ''; + foreach ($array as $key => $value) { + $string .= $this->_yamlize($key,$value,$indent); + } + return $string; + } else { + return false; + } + } + + /** + * Returns YAML from a key and a value + * @access private + * @return string + * @param $key The name of the key + * @param $value The value of the item + * @param $indent The indent of the current node + */ + function _dumpNode($key,$value,$indent) { + // do some folding here, for blocks + if (strpos($value,"\n")) { + $value = $this->_doLiteralBlock($value,$indent); + } else { + $value = $this->_doFolding($value,$indent); + } + + $spaces = str_repeat(' ',$indent); + + if (is_int($key)) { + // It's a sequence + $string = $spaces.'- '.$value."\n"; + } else { + // It's mapped + $string = $spaces.$key.': '.$value."\n"; + } + return $string; + } + + /** + * Creates a literal block for dumping + * @access private + * @return string + * @param $value + * @param $indent int The value of the indent + */ + function _doLiteralBlock($value,$indent) { + $exploded = explode("\n",$value); + $newValue = '|'; + $indent += $this->_dumpIndent; + $spaces = str_repeat(' ',$indent); + foreach ($exploded as $line) { + $newValue .= "\n" . $spaces . trim($line); + } + return $newValue; + } + + /** + * Folds a string of text, if necessary + * @access private + * @return string + * @param $value The string you wish to fold + */ + function _doFolding($value,$indent) { + // Don't do anything if wordwrap is set to 0 + if ($this->_dumpWordWrap === 0) { + return $value; + } + + if (strlen($value) > $this->_dumpWordWrap) { + $indent += $this->_dumpIndent; + $indent = str_repeat(' ',$indent); + $wrapped = wordwrap($value,$this->_dumpWordWrap,"\n$indent"); + $value = ">\n".$indent.$wrapped; + } + return $value; + } + + /* Methods used in loading */ + + /** + * Finds and returns the indentation of a YAML line + * @access private + * @return int + * @param string $line A line from the YAML file + */ + function _getIndent($line) { + preg_match('/^\s{1,}/',$line,$match); + if (!empty($match[0])) { + $indent = substr_count($match[0],' '); + } else { + $indent = 0; + } + return $indent; + } + + /** + * Parses YAML code and returns an array for a node + * @access private + * @return array + * @param string $line A line from the YAML file + */ + function _parseLine($line) { + $line = trim($line); + + $array = array(); + + if (preg_match('/^-(.*):$/',$line)) { + // It's a mapped sequence + $key = trim(substr(substr($line,1),0,-1)); + $array[$key] = ''; + } elseif ($line[0] == '-' && substr($line,0,3) != '---') { + // It's a list item but not a new stream + if (strlen($line) > 1) { + $value = trim(substr($line,1)); + // Set the type of the value. Int, string, etc + $value = $this->_toType($value); + $array[] = $value; + } else { + $array[] = array(); + } + } elseif (preg_match('/^(.+):/',$line,$key)) { + // It's a key/value pair most likely + // If the key is in double quotes pull it out + if (preg_match('/^(["\'](.*)["\'](\s)*:)/',$line,$matches)) { + $value = trim(str_replace($matches[1],'',$line)); + $key = $matches[2]; + } else { + // Do some guesswork as to the key and the value + $explode = explode(':',$line); + $key = trim($explode[0]); + array_shift($explode); + $value = trim(implode(':',$explode)); + } + + // Set the type of the value. Int, string, etc + $value = $this->_toType($value); + if (empty($key)) { + $array[] = $value; + } else { + $array[$key] = $value; + } + } + return $array; + } + + /** + * Finds the type of the passed value, returns the value as the new type. + * @access private + * @param string $value + * @return mixed + */ + function _toType($value) { + if (preg_match('/^("(.*)"|\'(.*)\')/',$value,$matches)) { + $value = (string)preg_replace('/(\'\'|\\\\\')/',"'",end($matches)); + $value = preg_replace('/\\\\"/','"',$value); + } elseif (preg_match('/^\\[(.+)\\]$/',$value,$matches)) { + // Inline Sequence + + // Take out strings sequences and mappings + $explode = $this->_inlineEscape($matches[1]); + + // Propogate value array + $value = array(); + foreach ($explode as $v) { + $value[] = $this->_toType($v); + } + } elseif (strpos($value,': ')!==false && !preg_match('/^{(.+)/',$value)) { + // It's a map + $array = explode(': ',$value); + $key = trim($array[0]); + array_shift($array); + $value = trim(implode(': ',$array)); + $value = $this->_toType($value); + $value = array($key => $value); + } elseif (preg_match("/{(.+)}$/",$value,$matches)) { + // Inline Mapping + + // Take out strings sequences and mappings + $explode = $this->_inlineEscape($matches[1]); + + // Propogate value array + $array = array(); + foreach ($explode as $v) { + $array = $array + $this->_toType($v); + } + $value = $array; + } elseif (strtolower($value) == 'null' or $value == '' or $value == '~') { + $value = NULL; + } elseif (ctype_digit($value)) { + $value = (int)$value; + } elseif (in_array(strtolower($value), + array('true', 'on', '+', 'yes', 'y'))) { + $value = TRUE; + } elseif (in_array(strtolower($value), + array('false', 'off', '-', 'no', 'n'))) { + $value = FALSE; + } elseif (is_numeric($value)) { + $value = (float)$value; + } else { + // Just a normal string, right? + $value = trim(preg_replace('/#(.+)$/','',$value)); + } + + return $value; + } + + /** + * Used in inlines to check for more inlines or quoted strings + * @access private + * @return array + */ + function _inlineEscape($inline) { + // There's gotta be a cleaner way to do this... + // While pure sequences seem to be nesting just fine, + // pure mappings and mappings with sequences inside can't go very + // deep. This needs to be fixed. + + // Check for strings + $regex = '/(?:(")|(?:\'))((?(1)[^"]+|[^\']+))(?(1)"|\')/'; + if (preg_match_all($regex,$inline,$strings)) { + $saved_strings[] = $strings[0][0]; + $inline = preg_replace($regex,'YAMLString',$inline); + } + unset($regex); + + // Check for sequences + if (preg_match_all('/\[(.+)\]/U',$inline,$seqs)) { + $inline = preg_replace('/\[(.+)\]/U','YAMLSeq',$inline); + $seqs = $seqs[0]; + } + + // Check for mappings + if (preg_match_all('/{(.+)}/U',$inline,$maps)) { + $inline = preg_replace('/{(.+)}/U','YAMLMap',$inline); + $maps = $maps[0]; + } + + $explode = explode(', ',$inline); + + // Re-add the strings + if (!empty($saved_strings)) { + $i = 0; + foreach ($explode as $key => $value) { + if (strpos($value,'YAMLString')) { + $explode[$key] = str_replace('YAMLString',$saved_strings[$i],$value); + ++$i; + } + } + } + + // Re-add the sequences + if (!empty($seqs)) { + $i = 0; + foreach ($explode as $key => $value) { + if (strpos($value,'YAMLSeq') !== false) { + $explode[$key] = str_replace('YAMLSeq',$seqs[$i],$value); + ++$i; + } + } + } + + // Re-add the mappings + if (!empty($maps)) { + $i = 0; + foreach ($explode as $key => $value) { + if (strpos($value,'YAMLMap') !== false) { + $explode[$key] = str_replace('YAMLMap',$maps[$i],$value); + ++$i; + } + } + } + + return $explode; + } + + /** + * Builds the PHP array from all the YAML nodes we've gathered + * @access private + * @return array + */ + function _buildArray() { + $trunk = array(); + + if (!isset($this->_indentSort[0])) { + return $trunk; + } + + foreach ($this->_indentSort[0] as $n) { + if (empty($n->parent)) { + $this->_nodeArrayizeData($n); + // Check for references and copy the needed data to complete them. + $this->_makeReferences($n); + // Merge our data with the big array we're building + $trunk = $this->_array_kmerge($trunk,$n->data); + } + } + + return $trunk; + } + + /** + * Traverses node-space and sets references (& and *) accordingly + * @access private + * @return bool + */ + function _linkReferences() { + if (is_array($this->_haveRefs)) { + foreach ($this->_haveRefs as $node) { + if (!empty($node->data)) { + $key = key($node->data); + // If it's an array, don't check. + if (is_array($node->data[$key])) { + foreach ($node->data[$key] as $k => $v) { + $this->_linkRef($node,$key,$k,$v); + } + } else { + $this->_linkRef($node,$key); + } + } + } + } + return true; + } + + function _linkRef(&$n,$key,$k = NULL,$v = NULL) { + if (empty($k) && empty($v)) { + // Look for &refs + if (preg_match('/^&([^ ]+)/',$n->data[$key],$matches)) { + // Flag the node so we know it's a reference + $this->_allNodes[$n->id]->ref = substr($matches[0],1); + $this->_allNodes[$n->id]->data[$key] = + substr($n->data[$key],strlen($matches[0])+1); + // Look for *refs + } elseif (preg_match('/^\*([^ ]+)/',$n->data[$key],$matches)) { + $ref = substr($matches[0],1); + // Flag the node as having a reference + $this->_allNodes[$n->id]->refKey = $ref; + } + } elseif (!empty($k) && !empty($v)) { + if (preg_match('/^&([^ ]+)/',$v,$matches)) { + // Flag the node so we know it's a reference + $this->_allNodes[$n->id]->ref = substr($matches[0],1); + $this->_allNodes[$n->id]->data[$key][$k] = + substr($v,strlen($matches[0])+1); + // Look for *refs + } elseif (preg_match('/^\*([^ ]+)/',$v,$matches)) { + $ref = substr($matches[0],1); + // Flag the node as having a reference + $this->_allNodes[$n->id]->refKey = $ref; + } + } + } + + /** + * Finds the children of a node and aids in the building of the PHP array + * @access private + * @param int $nid The id of the node whose children we're gathering + * @return array + */ + function _gatherChildren($nid) { + $return = array(); + $node =& $this->_allNodes[$nid]; + foreach ($this->_allNodes as $z) { + if ($z->parent == $node->id) { + // We found a child + $this->_nodeArrayizeData($z); + // Check for references + $this->_makeReferences($z); + // Merge with the big array we're returning + // The big array being all the data of the children of our parent node + $return = $this->_array_kmerge($return,$z->data); + } + } + return $return; + } + + /** + * Turns a node's data and its children's data into a PHP array + * + * @access private + * @param array $node The node which you want to arrayize + * @return boolean + */ + function _nodeArrayizeData(&$node) { + if (is_array($node->data) && $node->children == true) { + // This node has children, so we need to find them + $childs = $this->_gatherChildren($node->id); + // We've gathered all our children's data and are ready to use it + $key = key($node->data); + $key = empty($key) ? 0 : $key; + // If it's an array, add to it of course + if (is_array($node->data[$key])) { + $node->data[$key] = $this->_array_kmerge($node->data[$key],$childs); + } else { + $node->data[$key] = $childs; + } + } elseif (!is_array($node->data) && $node->children == true) { + // Same as above, find the children of this node + $childs = $this->_gatherChildren($node->id); + $node->data = array(); + $node->data[] = $childs; + } + + // We edited $node by reference, so just return true + return true; + } + + /** + * Traverses node-space and copies references to / from this object. + * @access private + * @param object $z A node whose references we wish to make real + * @return bool + */ + function _makeReferences(&$z) { + // It is a reference + if (isset($z->ref)) { + $key = key($z->data); + // Copy the data to this object for easy retrieval later + $this->ref[$z->ref] =& $z->data[$key]; + // It has a reference + } elseif (isset($z->refKey)) { + if (isset($this->ref[$z->refKey])) { + $key = key($z->data); + // Copy the data from this object to make the node a real reference + $z->data[$key] =& $this->ref[$z->refKey]; + } + } + return true; + } + + + /** + * Merges arrays and maintains numeric keys. + * + * An ever-so-slightly modified version of the array_kmerge() function posted + * to php.net by mail at nospam dot iaindooley dot com on 2004-04-08. + * + * http://us3.php.net/manual/en/function.array-merge.php#41394 + * + * @access private + * @param array $arr1 + * @param array $arr2 + * @return array + */ + function _array_kmerge($arr1,$arr2) { + if(!is_array($arr1)) + $arr1 = array(); + + if(!is_array($arr2)) + $arr2 = array(); + + $keys1 = array_keys($arr1); + $keys2 = array_keys($arr2); + $keys = array_merge($keys1,$keys2); + $vals1 = array_values($arr1); + $vals2 = array_values($arr2); + $vals = array_merge($vals1,$vals2); + $ret = array(); + + foreach($keys as $key) { + list($unused,$val) = each($vals); + // This is the good part! If a key already exists, but it's part of a + // sequence (an int), just keep addin numbers until we find a fresh one. + if (isset($ret[$key]) and is_int($key)) { + while (array_key_exists($key, $ret)) { + $key++; + } + } + $ret[$key] = $val; + } + + return $ret; + } + } +?> \ No newline at end of file
Added: www-website/planet/custom/config.yml =================================================================== --- www-website/planet/custom/config.yml (rev 0) +++ www-website/planet/custom/config.yml 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,29 @@ +# General ###################################################################### +#moonmoon url +url: "http://devel.gajim.org/planet/" + +#moonmoon title +name: Gajim + +# Display ###################################################################### + +# Number of items to display (default: 10) +items: 10 + +# Remove HTML (default: 0, preserve HTML) +nohtml: 0 + +# Post max length (default: 0, full length) +postmaxlength: 0 + +# Performances ################################################################# + +# Feeds cache: +# Time to wait before loading new items +# in minutes (default: 240) +refresh: 240 + +# Output cache: +# Time to wait before regenerating pages or feeds +# in minutes (default: 10) +cache: 10
Added: www-website/planet/custom/img/feed.png =================================================================== (Binary files differ)
Property changes on: www-website/planet/custom/img/feed.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream
Added: www-website/planet/custom/img/gajim.png =================================================================== (Binary files differ)
Property changes on: www-website/planet/custom/img/gajim.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream
Added: www-website/planet/custom/people.opml =================================================================== --- www-website/planet/custom/people.opml (rev 0) +++ www-website/planet/custom/people.opml 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,13 @@ +<?xml version="1.0"?> +<opml version="1.0"> + <head> + <title>Liferea Feed List Export</title> + </head> + <body> + <outline title="Asterix" text="Asterix" description="Asterix" type="rss" htmlUrl="http://blog.lagaule.org" xmlUrl="http://blog.lagaule.org/?feed=rss2"/> + <outline title="roidelapluie" text="roidelapluie" description="roidelapluie" type="rss" htmlUrl="http://4526.free.fr/julien" xmlUrl="http://4526.free.fr/julien/?feed=rss2"/> + <outline title="TomK" text="TomK" description="TomK" type="pie" htmlUrl="http://tomk-soc08.blogspot.com/" xmlUrl="http://tomk-soc08.blogspot.com/feeds/posts/default"/> + <outline title="vArDo" text="vArDo" description="vArDo" type="rss" htmlUrl="http://blog.bilinski.it" xmlUrl="http://feeds.feedburner.com/FreshGaleOfBits?format=xml"/> + <outline title="Liori" text="Liori" description="Liori" type="rss" htmlUrl="http://liori.jogger.pl/" xmlUrl="http://liori.jogger.pl/rss/content/html/20/"/> + </body> +</opml>
Added: www-website/planet/custom/style/dark.css =================================================================== --- www-website/planet/custom/style/dark.css (rev 0) +++ www-website/planet/custom/style/dark.css 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,125 @@ +html{ + font-family: Arial, sans-serif; + color: #FFF; + background: #333; + font-size: 62,5%; +} + +body{ + margin: 0; + padding: 0; + font-size: 0.8em; + line-height: 1.5em; +} + +a{ + color: #CCC; +} + +a:visited{ + color: #AAA; +} + +a:hover{ + color: #FFF; +} + +a img{ + border: none; +} + +pre, code{ + font-size: 1.2em; +} +/* Top +*******************************************************************************/ +#page{ + width: 640px; + margin: 0 auto; +} +/* Top +*******************************************************************************/ +#top{ + padding: 2%; + margin: 3em; + line-height: 2em; + color: #FFF; + text-align: center; +} + + #top h1{ + margin: 0; + letter-spacing: -1px; + font-family: Georgia, serif; + } + +/* Top +*******************************************************************************/ +#content{ + width: 66%; + padding: 0 2%; + margin: 0; + float: right; +} + +.post{ + margin-bottom: 3em; +} + +.post-title, .post-title a{ + font-family: Georgia, serif; + color: #CCC; + text-decoration: none; +} + +.post-title{ + padding-bottom: 0.5em; + border-bottom: 1px solid #444; +} + +.post-info{ + color: #999; + margin-top: -1em; +} + +.post-info a{ + color: #999; + text-decoration : none; +} + +/* Top +*******************************************************************************/ +#sidebar{ + width: 26%; + padding: 0 2%; + margin: 0; + float: left; +} + + #sidebar div{ + font-size: 0.8em; + } + + #sidebar h2{ + font-family: Georgia, serif; + color: #999; + } + + #sidebar a{ + text-decoration: none; + } + + #sidebar ul{ + margin: 0; + padding: 0; + list-style: none; + } + +/* Footer +*******************************************************************************/ +#footer{ + padding: 1ex 1em; + clear: both; + border-top: 1px solid #444; + color: #999; +} \ No newline at end of file
Added: www-website/planet/custom/style/default.css =================================================================== --- www-website/planet/custom/style/default.css (rev 0) +++ www-website/planet/custom/style/default.css 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,132 @@ +html{ + font-family: "Lucida Grande", Tahoma, sans-serif; + color: #333; + background: #DFC; + font-size: 62,5%; +} + +body{ + margin: 0; + padding: 0; + font-size: 0.8em; + line-height: 1.5em; +} + +a{ + color: #669; +} + +a:visited{ + color: #444; +} + +a:hover{ + color: #000; +} + +a img{ + border: none; +} + +pre, code{ + font-size: 1.2em; +} +/* Top +*******************************************************************************/ +#page{ + width: 60em; + margin: 0 auto; + background: #FFF; +} +/* Top +*******************************************************************************/ +#top{ + padding: 1.5em; + margin: 0; + background: #99cc33; + color: #FFF; + height:128px; + background-image:url('../img/gajim.png'); + background-position:center; + background-repeat:no-repeat; + border-top: 3px solid #7A2; +} + + #top h1{ + margin: 0; + } + + #top h1 a{ + color: #FFF; + text-decoration: none; + } + +/* Top +*******************************************************************************/ +#content{ + width: 38em; + padding: 0 2em; + margin: 2em 0; + float: left; + overflow: hidden; +} + +.post{ + margin-bottom: 3em; +} + +.post-title, .post-title a{ + color: #77AA22; + text-decoration: none; +} + +.post-info{ + color: #666; + margin-top: -1em; +} + +.post-info a{ + color: #669; + text-decoration : none; +} + +/* Top +*******************************************************************************/ +#sidebar{ + width: 13em; + padding: 0 2em; + margin: 2em 0; + float: right; +} + + #sidebar div{ + font-size: 0.8em; + } + + #sidebar h2{ + color: #99CC33; + } + + #sidebar a{ + text-decoration: none; + border-bottom: 1px solid #DDD; + } + + #sidebar ul{ + margin: 0; + padding: 0; + list-style: none; + } + + #sidebar li{ + margin: 0.5ex 0; + } + +/* Footer +*******************************************************************************/ +#footer{ + padding: 1ex 1em; + clear: both; + border-top: 1px dotted #CCC; + color: #999; +}
Added: www-website/planet/custom/style/light.css =================================================================== --- www-website/planet/custom/style/light.css (rev 0) +++ www-website/planet/custom/style/light.css 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,124 @@ +html{ + font-family: Arial, sans-serif; + color: #333; + background: #FFF; + font-size: 62,5%; +} + +body{ + margin: 0; + padding: 0; + font-size: 0.8em; + line-height: 1.5em; +} + +a{ + color: #669; +} + +a:visited{ + color: #444; +} + +a:hover{ + color: #000; +} + +a img{ + border: none; +} + +pre, code{ + font-size: 1.2em; +} +/* Top +*******************************************************************************/ +#page{ + margin: 0; + background: #FFF; +} +/* Top +*******************************************************************************/ +#top{ + padding: 2%; + margin: 0; + background: #CCC; + color: #FFF; + + border-top: 5px solid #999; +} + + #top h1{ + margin: 0; + letter-spacing: -1px; + } + +/* Top +*******************************************************************************/ +#content{ + width: 66%; + padding: 0 2%; + margin: 0; + float: left; +} + +.post{ + margin-bottom: 3em; +} + +.post-title, .post-title a{ + color: #666; + text-decoration: none; +} + +.post-title{ + padding-bottom: 0.5em; + border-bottom: 1px dotted #CCC; +} + +.post-info{ + color: #666; + margin-top: -1em; +} + +.post-info a{ + color: #666; + text-decoration : none; +} + +/* Top +*******************************************************************************/ +#sidebar{ + width: 26%; + padding: 0 2%; + margin: 0; + float: right; +} + + #sidebar div{ + font-size: 0.8em; + } + + #sidebar h2{ + color: #999; + } + + #sidebar a{ + text-decoration: none; + border-bottom: 1px solid #DDD; + } + + #sidebar ul{ + margin: 0; + padding: 0; + list-style: none; + } + +/* Footer +*******************************************************************************/ +#footer{ + padding: 1ex 1em; + clear: both; + border-top: 1px dotted #CCC; + color: #999; +} \ No newline at end of file
Added: www-website/planet/custom/tpl/atom10.tpl.php =================================================================== --- www-website/planet/custom/tpl/atom10.tpl.php (rev 0) +++ www-website/planet/custom/tpl/atom10.tpl.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,29 @@ +<?php +$all_items = &$Planet->getItems(); +$limit = $PlanetConfig->getMaxDisplay(); +$count = 0; +?> +<feed xmlns="http://www.w3.org/2005/Atom"> + <title><?php echo $PlanetConfig->getName(); ?></title> + <subtitle></subtitle> + <id><?php echo $PlanetConfig->getUrl(); ?></id> + <link rel="self" type="text/html" href="<?php echo $PlanetConfig->getUrl(); ?>?type=atom10" /> + <link rel="alternate" type="text/html" href="<?php echo $PlanetConfig->getUrl(); ?>" /> + <updated><?php echo date("Y-m-d\TH:i:s\Z") ?></updated> + <author><name>Author</name></author> + + <?php $count = 0; ?> + <?php foreach ($all_items as $item): ?> + <entry xmlns="http://www.w3.org/2005/Atom"> + <title type="html"><?php echo htmlspecialchars($item->getAuthor()); ?> : <?php echo htmlspecialchars($item->getTitle());?></title> + <id><?php echo htmlspecialchars($item->getUrl());?></id> + <link rel="alternate" href="<?php echo htmlspecialchars($item->getUrl());?>"/> + <published><?php echo date('Y-m-d\\TH:i:s+00:00',$item->getDate()); ?></published> + <updated><?php echo date('Y-m-d\\TH:i:s+00:00',$item->getDate()); ?></updated> + <author><name><?php echo htmlspecialchars($item->getAuthor()) ?></name></author> + + <content type="html"><![CDATA[<?php echo $item->getContent();?>]]></content> + </entry> + <?php if (++$count == $limit) { break; } ?> + <?php endforeach; ?> +</feed> \ No newline at end of file
Added: www-website/planet/custom/tpl/cheese.tpl.php =================================================================== --- www-website/planet/custom/tpl/cheese.tpl.php (rev 0) +++ www-website/planet/custom/tpl/cheese.tpl.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,47 @@ +<?php +$all_items = &$Planet->getItems(); +$current_date = date('d/m/Y', time()); +?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta http-equiv="Content-Script-Type" content="text/javascript" /> + <meta http-equiv="Content-Style-Type" content="text/css" /> + + <title><?php echo $PlanetConfig->getName(); ?></title> + <?php include(dirname(__FILE__).'/head.tpl.php'); ?> +</head> + +<body> + <div id="page"> + <?php include(dirname(__FILE__).'/top.tpl.php'); ?> + + <div id="content"> + <h2>Today</h2> + <ul class="cheese"> + <?php foreach ($all_items as $item): ?> + <?php + if (($item_date = date('d/m/Y',$item->getDate())) != $current_date){ + $current_date = $item_date; + echo '</ul>'; + echo '<h2>'.$item_date.'</h2>'; + echo '<ul>'; + } + ?> + <?php $owner = $item->getOwner(); ?> + <li> + <a href="<?php echo $owner->getWebsite(); ?>"><?php echo $owner->getName(); ?></a> : + <a href="<?php echo $item->getUrl(); ?>" title="Go to original place"><?php echo $item->getTitle(); ?></a> + </li> + <?php endforeach; ?> + </ul> + </div> + + <?php include_once(dirname(__FILE__).'/sidebar.tpl.php'); ?> + + <?php include(dirname(__FILE__).'/footer.tpl.php'); ?> + </div> +</body> +</html> \ No newline at end of file
Added: www-website/planet/custom/tpl/footer.tpl.php =================================================================== --- www-website/planet/custom/tpl/footer.tpl.php (rev 0) +++ www-website/planet/custom/tpl/footer.tpl.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,3 @@ + <div id="footer"> + <p>Feeds are updated every <?php echo Duration::toString($PlanetConfig->getCacheTimeout()*60); ?></p> + </div> \ No newline at end of file
Added: www-website/planet/custom/tpl/head.tpl.php =================================================================== --- www-website/planet/custom/tpl/head.tpl.php (rev 0) +++ www-website/planet/custom/tpl/head.tpl.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,4 @@ + <link rel="stylesheet" media="screen" type="text/css" href="custom/style/default.css" title="Default" /> + + <link rel="alternate" type="application/atom+xml" title="ATOM" href="?type=atom10" /> + <link rel="alternate" type="application/rss+xml" title="RSS" href="?type=rss10" /> \ No newline at end of file
Added: www-website/planet/custom/tpl/index.tpl.php =================================================================== --- www-website/planet/custom/tpl/index.tpl.php (rev 0) +++ www-website/planet/custom/tpl/index.tpl.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,48 @@ +<?php +$all_items = &$Planet->getItems(); +$limit = $PlanetConfig->getMaxDisplay(); +$count = 0; +?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta http-equiv="Content-Script-Type" content="text/javascript" /> + <meta http-equiv="Content-Style-Type" content="text/css" /> + + <title><?php echo $PlanetConfig->getName(); ?></title> + <?php include(dirname(__FILE__).'/head.tpl.php'); ?> +</head> + +<body> + <div id="page"> + <?php include(dirname(__FILE__).'/top.tpl.php'); ?> + + <div id="content"> + <?php foreach ($all_items as $item): ?> + <div class="post"> + <h2 class="post-title"><a href="<?php echo $item->getUrl(); ?>" title="Go to original place"><?php echo $item->getTitle(); ?></a></h2> + <p class="post-info"> + <?php echo $item->getAuthor(); ?>, + <?php + $ago = time() - $item->getDate(); + echo '<span title="'.Duration::toString($ago).' ago">'.date('d/m/Y', $item->getDate()).'</span>'; + ?> | + <?php $owner = $item->getOwner(); ?> + <a href="<?php echo $owner->getWebsite(); ?>"><?php echo $owner->getName(); ?></a> + </p> + <div class="post-content"> + <?php echo $item->getContent(); ?> + </div> + </div> + <?php if (++$count == $limit) { break; } ?> + <?php endforeach; ?> + </div> + + <?php include_once(dirname(__FILE__).'/sidebar.tpl.php'); ?> + + <?php include(dirname(__FILE__).'/footer.tpl.php'); ?> + </div> +</body> +</html> \ No newline at end of file
Added: www-website/planet/custom/tpl/rss10.tpl.php =================================================================== --- www-website/planet/custom/tpl/rss10.tpl.php (rev 0) +++ www-website/planet/custom/tpl/rss10.tpl.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,50 @@ +<?php +$all_items = &$Planet->getItems(); +$limit = $PlanetConfig->getMaxDisplay(); +$count = 0; +?> +<rdf:RDF + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" + xmlns:admin="http://webns.net/mvcb/" + xmlns:cc="http://web.resource.org/cc/" + xmlns:content="http://purl.org/rss/1.0/modules/content/" + xmlns="http://purl.org/rss/1.0/%22%3E + + <channel rdf:about="<?php echo $PlanetConfig->getUrl(); ?>"> + <title><?php echo $PlanetConfig->getName(); ?></title> + <description></description> + <link><?php echo $PlanetConfig->getUrl(); ?></link> + dc:language</dc:language> + dc:creator</dc:creator> + dc:rights</dc:rights> + dc:date<?php echo date('Y-m-d\\TH:i:s+00:00'); ?></dc:date> + <admin:generatorAgent rdf:resource="http://moonmoon.inertie.org/" /> + + <items> + rdf:Seq + <?php foreach ($all_items as $item): ?> + <rdf:li rdf:resource="<?php echo $item->getUrl();?>"/> + <?php if (++$count == $limit) { break; } ?> + <?php endforeach; ?> + </rdf:Seq> + </items> + </channel> + + <?php $count = 0; ?> + <?php foreach ($all_items as $item): ?> + <item rdf:about="<?php echo $item->getUrl();?>"> + <title><?php echo htmlspecialchars($item->getAuthor()) ?> : <?php echo htmlspecialchars($item->getTitle());?></title> + <link><?php echo htmlspecialchars($item->getUrl());?></link> + dc:date<?php echo date('Y-m-d\\TH:i:s+00:00',$item->getDate()); ?></dc:date> + dc:languagefr</dc:language> + dc:creator<?php echo htmlspecialchars($item->getAuthor()) ?></dc:creator> + dc:subject</dc:subject> + <description><?php echo htmlspecialchars($item->getContent()); ?></description> + content:encoded<![CDATA[<?php echo $item->getContent();?>]]></content:encoded> + </item> + <?php if (++$count == $limit) { break; } ?> + <?php endforeach; ?> + +</rdf:RDF> \ No newline at end of file
Added: www-website/planet/custom/tpl/sidebar.tpl.php =================================================================== --- www-website/planet/custom/tpl/sidebar.tpl.php (rev 0) +++ www-website/planet/custom/tpl/sidebar.tpl.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,35 @@ +<?php +$all_people = &$Planet->getPeople(); +usort($all_people, array('PlanetPerson', 'compare')); +?> +<div id="sidebar"> + <div id="sidebar-people"> + <h2>People (<?php echo count($all_people); ?>)</h2> + <ul> + <?php foreach ($all_people as $person) : ?> + <li> + <a href="<?php echo htmlspecialchars($person->getFeed(), ENT_QUOTES, 'UTF-8'); ?>" title="Feed"><img src="custom/img/feed.png" alt="feed" height="12" width="12" /></a> + <a href="<?php echo $person->getWebsite(); ?>" title="Website"><?php echo htmlspecialchars($person->getName(), ENT_QUOTES, 'UTF-8'); ?></a> + </li> + <?php endforeach; ?> + </ul> + <p> + <a href="custom/people.opml">All feeds in OPML format</a> + </p> + </div> + + <div> + <h2>Syndicate</h2> + <ul> + <li><img src="custom/img/feed.png" alt="feed" height="12" width="12" /> <a href="?type=rss10">RSS 1.0</a></li> + <li><img src="custom/img/feed.png" alt="feed" height="12" width="12" /> <a href="?type=atom10">ATOM 1.0</a></li> + </ul> + </div> + + <div> + <h2>Archives</h2> + <ul> + <li><a href="?type=cheese">Let's dig the moon for cheese</a></li> + </ul> + </div> +</div> \ No newline at end of file
Added: www-website/planet/custom/tpl/top.tpl.php =================================================================== --- www-website/planet/custom/tpl/top.tpl.php (rev 0) +++ www-website/planet/custom/tpl/top.tpl.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,3 @@ + <div id="top"> + <h1> </h1> + </div>
Added: www-website/planet/gajim.png =================================================================== (Binary files differ)
Property changes on: www-website/planet/gajim.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream
Added: www-website/planet/index.php =================================================================== --- www-website/planet/index.php (rev 0) +++ www-website/planet/index.php 2008-08-18 21:32:08 UTC (rev 10259) @@ -0,0 +1,105 @@ +<?php +error_reporting(E_ALL); +include_once(dirname(__FILE__).'/app/classes/Planet.class.php'); +include_once(dirname(__FILE__).'/app/lib/spyc-0.2.3/spyc.php'); +require_once dirname(__FILE__).'/app/lib/lib.opml.php'; +include_once(dirname(__FILE__).'/app/lib/Duration.php'); +include_once(dirname(__FILE__).'/app/lib/Cache.php'); +include_once(dirname(__FILE__).'/app/lib/lib.http.php'); + +Cache::setStore(dirname(__FILE__).'/cache/'); + +//Basic check +if (!is_file(dirname(__FILE__).'/custom/config.yml')){ + die('Config file (custom/config.yml) is missing.'); +} + +if (!is_file(dirname(__FILE__).'/custom/people.opml')){ + die('People file (custom/people.opml) is missing.'); +} + +//Load system files (config and OPML) +$conf = Spyc::YAMLLoad(dirname(__FILE__).'/custom/config.yml'); +$opml = opmlImporter::load(dirname(__FILE__).'/custom/people.opml'); + +//Build config object +//Use OPML title if no title defined in the config file +$PlanetConfig = new PlanetConfig($conf); +if ($PlanetConfig->getName() === '') { + $PlanetConfig->setName($opml->getTitle()); +} + +//Instantiate app +$Planet = new Planet($PlanetConfig); + +//Populate app with people +$opml_people = $opml->getPeople(); +foreach ($opml_people as $opml_person){ + if (!isset($opml_person['feed'])){ + continue; + } + + if (!isset($opml_person['website'])){ + //use dirname as website, doesn't work with RSS proxies like feedburner + $opml_person['website'] = dirname($opml_person['feed']); + } + + if (!isset($opml_person['name'])){ + //use url as screen name + $opml_person['name'] = $opml_person['website']; + } + + $Planet->addPerson( + new PlanetPerson( + $opml_person['name'], + $opml_person['feed'], + $opml_person['website'] + ) + ); +} + +//Load feeds +$Planet->loadFeeds(); +$first_item_url = $Planet->items[0]->getUrl(); +$first_item_date = gmdate("r", $Planet->items[0]->getDate()); + +//HTTP conditional get +http_modified($first_item_date, $first_item_url); + +//Go display +$output_cache = $PlanetConfig->getOutputTimeout()*60; +if (array_key_exists('type', $_GET) && $_GET['type'] == 'rss10'){ + //Serve RSS 1.0 + header('Content-Type: text/xml; charset=UTF-8') ; + if (!OutputCache::Start('rss10', $first_item_url, $output_cache)) { + echo '<?xml version="1.0" encoding="UTF-8" ?>'."\n"; + include_once(dirname(__FILE__).'/custom/tpl/rss10.tpl.php'); + OutputCache::End(); + } +} +elseif (array_key_exists('type', $_GET) && $_GET['type'] == 'atom10'){ + //Serve ATOM 1.0 + header('Content-Type: text/xml; charset=UTF-8') ; + if (!OutputCache::Start('atom10', $first_item_url, $output_cache)) { + echo '<?xml version="1.0" encoding="UTF-8" ?>'."\n"; + include_once(dirname(__FILE__).'/custom/tpl/atom10.tpl.php'); + OutputCache::End(); + } +} +elseif (array_key_exists('type', $_GET) && $_GET['type'] == 'cheese'){ + //Serve full cache content + header('Content-type: text/html; charset=UTF-8'); + if (!OutputCache::Start('cheese', $first_item_url, $output_cache)) { + include_once(dirname(__FILE__).'/custom/tpl/cheese.tpl.php'); + OutputCache::End(); + } +} +else{ + //Serve regular moonmoon + header('Content-type: text/html; charset=UTF-8'); + if (!OutputCache::Start('moonmoon', $first_item_url, $output_cache)) { + include_once(dirname(__FILE__).'/custom/tpl/index.tpl.php'); + OutputCache::End(); + } +} +?> \ No newline at end of file