+++ /dev/null
-<?php\r
-/***************************************************************************\r
-\r
-FeedCreator class v1.7.2\r
-originally (c) Kai Blankenhorn\r
-www.bitfolge.de\r
-kaib@bitfolge.de\r
-v1.3 work by Scott Reynen (scott@randomchaos.com) and Kai Blankenhorn\r
-v1.5 OPML support by Dirk Clemens\r
-\r
-This library is free software; you can redistribute it and/or\r
-modify it under the terms of the GNU Lesser General Public\r
-License as published by the Free Software Foundation; either\r
-version 2.1 of the License, or (at your option) any later version.\r
-\r
-This library is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
-Lesser General Public License for more details.\r
-\r
-You should have received a copy of the GNU Lesser General Public\r
-License along with this library; if not, write to the Free Software\r
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
-\r
-****************************************************************************\r
-\r
-\r
-Changelog:\r
-\r
-v1.7.2 10-11-04\r
- license changed to LGPL\r
-\r
-v1.7.1\r
- fixed a syntax bug\r
- fixed left over debug code\r
-\r
-v1.7 07-18-04\r
- added HTML and JavaScript feeds (configurable via CSS) (thanks to Pascal Van Hecke)\r
- added HTML descriptions for all feed formats (thanks to Pascal Van Hecke)\r
- added a switch to select an external stylesheet (thanks to Pascal Van Hecke)\r
- changed default content-type to application/xml\r
- added character encoding setting\r
- fixed numerous smaller bugs (thanks to Sören Fuhrmann of golem.de)\r
- improved changing ATOM versions handling (thanks to August Trometer)\r
- improved the UniversalFeedCreator's useCached method (thanks to Sören Fuhrmann of golem.de)\r
- added charset output in HTTP headers (thanks to Sören Fuhrmann of golem.de)\r
- added Slashdot namespace to RSS 1.0 (thanks to Sören Fuhrmann of golem.de)\r
-\r
-v1.6 05-10-04\r
- added stylesheet to RSS 1.0 feeds\r
- fixed generator comment (thanks Kevin L. Papendick and Tanguy Pruvot)\r
- fixed RFC822 date bug (thanks Tanguy Pruvot)\r
- added TimeZone customization for RFC8601 (thanks Tanguy Pruvot)\r
- fixed Content-type could be empty (thanks Tanguy Pruvot)\r
- fixed author/creator in RSS1.0 (thanks Tanguy Pruvot)\r
-\r
-v1.6 beta 02-28-04\r
- added Atom 0.3 support (not all features, though)\r
- improved OPML 1.0 support (hopefully - added more elements)\r
- added support for arbitrary additional elements (use with caution)\r
- code beautification :-)\r
- considered beta due to some internal changes\r
-\r
-v1.5.1 01-27-04\r
- fixed some RSS 1.0 glitches (thanks to Stéphane Vanpoperynghe)\r
- fixed some inconsistencies between documentation and code (thanks to Timothy Martin)\r
-\r
-v1.5 01-06-04\r
- added support for OPML 1.0\r
- added more documentation\r
-\r
-v1.4 11-11-03\r
- optional feed saving and caching\r
- improved documentation\r
- minor improvements\r
-\r
-v1.3 10-02-03\r
- renamed to FeedCreator, as it not only creates RSS anymore\r
- added support for mbox\r
- tentative support for echo/necho/atom/pie/???\r
- \r
-v1.2 07-20-03\r
- intelligent auto-truncating of RSS 0.91 attributes\r
- don't create some attributes when they're not set\r
- documentation improved\r
- fixed a real and a possible bug with date conversions\r
- code cleanup\r
-\r
-v1.1 06-29-03\r
- added images to feeds\r
- now includes most RSS 0.91 attributes\r
- added RSS 2.0 feeds\r
-\r
-v1.0 06-24-03\r
- initial release\r
-\r
-\r
-\r
-***************************************************************************/\r
-\r
-/*** GENERAL USAGE *********************************************************\r
-\r
-include("feedcreator.class.php"); \r
-\r
-$rss = new UniversalFeedCreator(); \r
-$rss->useCached(); // use cached version if age<1 hour\r
-$rss->title = "PHP news"; \r
-$rss->description = "daily news from the PHP scripting world"; \r
-\r
-//optional\r
-$rss->descriptionTruncSize = 500;\r
-$rss->descriptionHtmlSyndicated = true;\r
-\r
-$rss->link = "http://www.dailyphp.net/news"; \r
-$rss->syndicationURL = "http://www.dailyphp.net/".$_SERVER["PHP_SELF"]; \r
-\r
-$image = new FeedImage(); \r
-$image->title = "dailyphp.net logo"; \r
-$image->url = "http://www.dailyphp.net/images/logo.gif"; \r
-$image->link = "http://www.dailyphp.net"; \r
-$image->description = "Feed provided by dailyphp.net. Click to visit."; \r
-\r
-//optional\r
-$image->descriptionTruncSize = 500;\r
-$image->descriptionHtmlSyndicated = true;\r
-\r
-$rss->image = $image; \r
-\r
-// get your news items from somewhere, e.g. your database: \r
-mysql_select_db($dbHost, $dbUser, $dbPass); \r
-$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC"); \r
-while ($data = mysql_fetch_object($res)) { \r
- $item = new FeedItem(); \r
- $item->title = $data->title; \r
- $item->link = $data->url; \r
- $item->description = $data->short; \r
- \r
- //optional\r
- item->descriptionTruncSize = 500;\r
- item->descriptionHtmlSyndicated = true;\r
-\r
- $item->date = $data->newsdate; \r
- $item->source = "http://www.dailyphp.net"; \r
- $item->author = "John Doe"; \r
- \r
- $rss->addItem($item); \r
-} \r
-\r
-// valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1 (deprecated),\r
-// MBOX, OPML, ATOM, ATOM0.3, HTML, JS\r
-echo $rss->saveFeed("RSS1.0", "news/feed.xml");\r
-\r
-\r
-***************************************************************************\r
-* A little setup *\r
-**************************************************************************/\r
-\r
-// your local timezone, set to "" to disable or for GMT\r
-define("TIME_ZONE","+01:00");\r
-\r
-\r
-\r
-\r
-/**\r
- * Version string.\r
- **/\r
-define("FEEDCREATOR_VERSION", "FeedCreator 1.7.2");\r
-\r
-\r
-\r
-/**\r
- * A FeedItem is a part of a FeedCreator feed.\r
- *\r
- * @author Kai Blankenhorn <kaib@bitfolge.de>\r
- * @since 1.3\r
- */\r
-class FeedItem extends HtmlDescribable {\r
- /**\r
- * Mandatory attributes of an item.\r
- */\r
- var $title, $description, $link;\r
- \r
- /**\r
- * Optional attributes of an item.\r
- */\r
- var $author, $authorEmail, $image, $category, $comments, $guid, $source, $creator;\r
- \r
- /**\r
- * Publishing date of an item. May be in one of the following formats:\r
- *\r
- * RFC 822:\r
- * "Mon, 20 Jan 03 18:05:41 +0400"\r
- * "20 Jan 03 18:05:41 +0000"\r
- *\r
- * ISO 8601:\r
- * "2003-01-20T18:05:41+04:00"\r
- *\r
- * Unix:\r
- * 1043082341\r
- */\r
- var $date;\r
- \r
- /**\r
- * Any additional elements to include as an assiciated array. All $key => $value pairs\r
- * will be included unencoded in the feed item in the form\r
- * <$key>$value</$key>\r
- * Again: No encoding will be used! This means you can invalidate or enhance the feed\r
- * if $value contains markup. This may be abused to embed tags not implemented by\r
- * the FeedCreator class used.\r
- */\r
- var $additionalElements = Array();\r
-\r
- // on hold\r
- // var $source;\r
-}\r
-\r
-\r
-\r
-/**\r
- * An FeedImage may be added to a FeedCreator feed.\r
- * @author Kai Blankenhorn <kaib@bitfolge.de>\r
- * @since 1.3\r
- */\r
-class FeedImage extends HtmlDescribable {\r
- /**\r
- * Mandatory attributes of an image.\r
- */\r
- var $title, $url, $link;\r
- \r
- /**\r
- * Optional attributes of an image.\r
- */\r
- var $width, $height, $description;\r
-}\r
-\r
-\r
-\r
-/**\r
- * An HtmlDescribable is an item within a feed that can have a description that may\r
- * include HTML markup.\r
- */\r
-class HtmlDescribable {\r
- /**\r
- * Indicates whether the description field should be rendered in HTML.\r
- */\r
- var $descriptionHtmlSyndicated;\r
- \r
- /**\r
- * Indicates whether and to how many characters a description should be truncated.\r
- */\r
- var $descriptionTruncSize;\r
- \r
- /**\r
- * Returns a formatted description field, depending on descriptionHtmlSyndicated and\r
- * $descriptionTruncSize properties\r
- * @return string the formatted description \r
- */\r
- function getDescription() {\r
- $descriptionField = new FeedHtmlField($this->description);\r
- $descriptionField->syndicateHtml = $this->descriptionHtmlSyndicated;\r
- $descriptionField->truncSize = $this->descriptionTruncSize;\r
- return $descriptionField->output();\r
- }\r
-\r
-}\r
-\r
-\r
-/**\r
- * An FeedHtmlField describes and generates\r
- * a feed, item or image html field (probably a description). Output is \r
- * generated based on $truncSize, $syndicateHtml properties.\r
- * @author Pascal Van Hecke <feedcreator.class.php@vanhecke.info>\r
- * @version 1.6\r
- */\r
-class FeedHtmlField {\r
- /**\r
- * Mandatory attributes of a FeedHtmlField.\r
- */\r
- var $rawFieldContent;\r
- \r
- /**\r
- * Optional attributes of a FeedHtmlField.\r
- * \r
- */\r
- var $truncSize, $syndicateHtml;\r
- \r
- /**\r
- * Creates a new instance of FeedHtmlField.\r
- * @param $string: if given, sets the rawFieldContent property\r
- */\r
- function FeedHtmlField($parFieldContent) {\r
- if ($parFieldContent) {\r
- $this->rawFieldContent = $parFieldContent;\r
- }\r
- }\r
- \r
- \r
- /**\r
- * Creates the right output, depending on $truncSize, $syndicateHtml properties.\r
- * @return string the formatted field\r
- */\r
- function output() {\r
- // when field available and syndicated in html we assume \r
- // - valid html in $rawFieldContent and we enclose in CDATA tags\r
- // - no truncation (truncating risks producing invalid html)\r
- if (!$this->rawFieldContent) {\r
- $result = "";\r
- } elseif ($this->syndicateHtml) {\r
- $result = "<![CDATA[".$this->rawFieldContent."]]>";\r
- } else {\r
- if ($this->truncSize and is_int($this->truncSize)) {\r
- $result = FeedCreator::iTrunc(htmlspecialchars($this->rawFieldContent),$this->truncSize);\r
- } else {\r
- $result = htmlspecialchars($this->rawFieldContent);\r
- }\r
- }\r
- return $result;\r
- }\r
-\r
-}\r
-\r
-\r
-\r
-/**\r
- * UniversalFeedCreator lets you choose during runtime which\r
- * format to build.\r
- * For general usage of a feed class, see the FeedCreator class\r
- * below or the example above.\r
- *\r
- * @since 1.3\r
- * @author Kai Blankenhorn <kaib@bitfolge.de>\r
- */\r
-class UniversalFeedCreator extends FeedCreator {\r
- var $_feed;\r
- \r
- function _setFormat($format) {\r
- switch (strtoupper($format)) {\r
- \r
- case "2.0":\r
- // fall through\r
- case "RSS2.0":\r
- $this->_feed = new RSSCreator20();\r
- break;\r
- \r
- case "1.0":\r
- // fall through\r
- case "RSS1.0":\r
- $this->_feed = new RSSCreator10();\r
- break;\r
- \r
- case "0.91":\r
- // fall through\r
- case "RSS0.91":\r
- $this->_feed = new RSSCreator091();\r
- break;\r
- \r
- case "PIE0.1":\r
- $this->_feed = new PIECreator01();\r
- break;\r
- \r
- case "MBOX":\r
- $this->_feed = new MBOXCreator();\r
- break;\r
- \r
- case "OPML":\r
- $this->_feed = new OPMLCreator();\r
- break;\r
- \r
- case "ATOM":\r
- // fall through: always the latest ATOM version\r
- \r
- case "ATOM0.3":\r
- $this->_feed = new AtomCreator03();\r
- break;\r
- \r
- case "HTML":\r
- $this->_feed = new HTMLCreator();\r
- break;\r
- \r
- case "JS":\r
- // fall through\r
- case "JAVASCRIPT":\r
- $this->_feed = new JSCreator();\r
- break;\r
- \r
- default:\r
- $this->_feed = new RSSCreator091();\r
- break;\r
- }\r
- \r
- $vars = get_object_vars($this);\r
- foreach ($vars as $key => $value) {\r
- // prevent overwriting of properties "contentType", "encoding"; do not copy "_feed" itself\r
- if (!in_array($key, array("_feed", "contentType", "encoding"))) {\r
- $this->_feed->{$key} = $this->{$key};\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * Creates a syndication feed based on the items previously added.\r
- *\r
- * @see FeedCreator::addItem()\r
- * @param string format format the feed should comply to. Valid values are:\r
- * "PIE0.1", "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3", "HTML", "JS"\r
- * @return string the contents of the feed.\r
- */\r
- function createFeed($format = "RSS0.91") {\r
- $this->_setFormat($format);\r
- return $this->_feed->createFeed();\r
- }\r
- \r
- \r
- \r
- /**\r
- * Saves this feed as a file on the local disk. After the file is saved, an HTTP redirect\r
- * header may be sent to redirect the use to the newly created file.\r
- * @since 1.4\r
- * \r
- * @param string format format the feed should comply to. Valid values are:\r
- * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM", "ATOM0.3", "HTML", "JS"\r
- * @param string filename optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()).\r
- * @param boolean displayContents optional send the content of the file or not. If true, the file will be sent in the body of the response.\r
- */\r
- function saveFeed($format="RSS0.91", $filename="", $displayContents=true) {\r
- $this->_setFormat($format);\r
- $this->_feed->saveFeed($filename, $displayContents);\r
- }\r
-\r
-\r
- /**\r
- * Turns on caching and checks if there is a recent version of this feed in the cache.\r
- * If there is, an HTTP redirect header is sent.\r
- * To effectively use caching, you should create the FeedCreator object and call this method\r
- * before anything else, especially before you do the time consuming task to build the feed\r
- * (web fetching, for example).\r
- *\r
- * @param string format format the feed should comply to. Valid values are:\r
- * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3".\r
- * @param filename string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()).\r
- * @param timeout int optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour)\r
- */\r
- function useCached($format="RSS0.91", $filename="", $timeout=3600) {\r
- $this->_setFormat($format);\r
- $this->_feed->useCached($filename, $timeout);\r
- }\r
-\r
-}\r
-\r
-\r
-/**\r
- * FeedCreator is the abstract base implementation for concrete\r
- * implementations that implement a specific format of syndication.\r
- *\r
- * @abstract\r
- * @author Kai Blankenhorn <kaib@bitfolge.de>\r
- * @since 1.4\r
- */\r
-class FeedCreator extends HtmlDescribable {\r
-\r
- /**\r
- * Mandatory attributes of a feed.\r
- */\r
- var $title, $description, $link;\r
- \r
- \r
- /**\r
- * Optional attributes of a feed.\r
- */\r
- var $syndicationURL, $image, $language, $copyright, $pubDate, $lastBuildDate, $editor, $editorEmail, $webmaster, $category, $docs, $ttl, $rating, $skipHours, $skipDays;\r
-\r
- /**\r
- * The url of the external xsl stylesheet used to format the naked rss feed.\r
- * Ignored in the output when empty.\r
- */\r
- var $xslStyleSheet = "";\r
- \r
- \r
- /**\r
- * @access private\r
- */\r
- var $items = Array();\r
- \r
- \r
- /**\r
- * This feed's MIME content type.\r
- * @since 1.4\r
- * @access private\r
- */\r
- var $contentType = "application/xml";\r
- \r
- \r
- /**\r
- * This feed's character encoding.\r
- * @since 1.6.1\r
- **/\r
- var $encoding = "utf-8";\r
- \r
- \r
- /**\r
- * Any additional elements to include as an assiciated array. All $key => $value pairs\r
- * will be included unencoded in the feed in the form\r
- * <$key>$value</$key>\r
- * Again: No encoding will be used! This means you can invalidate or enhance the feed\r
- * if $value contains markup. This may be abused to embed tags not implemented by\r
- * the FeedCreator class used.\r
- */\r
- var $additionalElements = Array();\r
- \r
- \r
- /**\r
- * Adds an FeedItem to the feed.\r
- *\r
- * @param object FeedItem $item The FeedItem to add to the feed.\r
- * @access public\r
- */\r
- function addItem($item) {\r
- $this->items[] = $item;\r
- }\r
- \r
- \r
- /**\r
- * Truncates a string to a certain length at the most sensible point.\r
- * First, if there's a '.' character near the end of the string, the string is truncated after this character.\r
- * If there is no '.', the string is truncated after the last ' ' character.\r
- * If the string is truncated, " ..." is appended.\r
- * If the string is already shorter than $length, it is returned unchanged.\r
- * \r
- * @static\r
- * @param string string A string to be truncated.\r
- * @param int length the maximum length the string should be truncated to\r
- * @return string the truncated string\r
- */\r
- function iTrunc($string, $length) {\r
- if (strlen($string)<=$length) {\r
- return $string;\r
- }\r
- \r
- $pos = strrpos($string,".");\r
- if ($pos>=$length-4) {\r
- $string = substr($string,0,$length-4);\r
- $pos = strrpos($string,".");\r
- }\r
- if ($pos>=$length*0.4) {\r
- return substr($string,0,$pos+1)." ...";\r
- }\r
- \r
- $pos = strrpos($string," ");\r
- if ($pos>=$length-4) {\r
- $string = substr($string,0,$length-4);\r
- $pos = strrpos($string," ");\r
- }\r
- if ($pos>=$length*0.4) {\r
- return substr($string,0,$pos)." ...";\r
- }\r
- \r
- return substr($string,0,$length-4)." ...";\r
- \r
- }\r
- \r
- \r
- /**\r
- * Creates a comment indicating the generator of this feed.\r
- * The format of this comment seems to be recognized by\r
- * Syndic8.com.\r
- */\r
- function _createGeneratorComment() {\r
- return "<!-- generator=\"".FEEDCREATOR_VERSION."\" -->\n";\r
- }\r
- \r
- \r
- /**\r
- * Creates a string containing all additional elements specified in\r
- * $additionalElements.\r
- * @param elements array an associative array containing key => value pairs\r
- * @param indentString string a string that will be inserted before every generated line\r
- * @return string the XML tags corresponding to $additionalElements\r
- */\r
- function _createAdditionalElements($elements, $indentString="") {\r
- $ae = "";\r
- if (is_array($elements)) {\r
- foreach($elements AS $key => $value) {\r
- $ae.= $indentString."<$key>$value</$key>\n";\r
- }\r
- }\r
- return $ae;\r
- }\r
- \r
- function _createStylesheetReferences() {\r
- $xml = "";\r
- if ($this->cssStyleSheet) $xml .= "<?xml-stylesheet href=\"".$this->cssStyleSheet."\" type=\"text/css\"?>\n";\r
- if ($this->xslStyleSheet) $xml .= "<?xml-stylesheet href=\"".$this->xslStyleSheet."\" type=\"text/xsl\"?>\n";\r
- return $xml;\r
- }\r
- \r
- \r
- /**\r
- * Builds the feed's text.\r
- * @abstract\r
- * @return string the feed's complete text \r
- */\r
- function createFeed() {\r
- }\r
- \r
- /**\r
- * Generate a filename for the feed cache file. The result will be $_SERVER["PHP_SELF"] with the extension changed to .xml.\r
- * For example:\r
- * \r
- * echo $_SERVER["PHP_SELF"]."\n";\r
- * echo FeedCreator::_generateFilename();\r
- * \r
- * would produce:\r
- * \r
- * /rss/latestnews.php\r
- * latestnews.xml\r
- *\r
- * @return string the feed cache filename\r
- * @since 1.4\r
- * @access private\r
- */\r
- function _generateFilename() {\r
- $fileInfo = pathinfo($_SERVER["PHP_SELF"]);\r
- return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".xml";\r
- }\r
- \r
- \r
- /**\r
- * @since 1.4\r
- * @access private\r
- */\r
- function _redirect($filename) {\r
- // attention, heavily-commented-out-area\r
- \r
- // maybe use this in addition to file time checking\r
- //Header("Expires: ".date("r",time()+$this->_timeout));\r
- \r
- /* no caching at all, doesn't seem to work as good:\r
- Header("Cache-Control: no-cache");\r
- Header("Pragma: no-cache");\r
- */\r
- \r
- // HTTP redirect, some feed readers' simple HTTP implementations don't follow it\r
- //Header("Location: ".$filename);\r
-\r
- Header("Content-Type: ".$this->contentType."; charset=".$this->encoding."; filename=".basename($filename));\r
- Header("Content-Disposition: inline; filename=".basename($filename));\r
- readfile($filename, "r");\r
- die();\r
- }\r
- \r
- /**\r
- * Turns on caching and checks if there is a recent version of this feed in the cache.\r
- * If there is, an HTTP redirect header is sent.\r
- * To effectively use caching, you should create the FeedCreator object and call this method\r
- * before anything else, especially before you do the time consuming task to build the feed\r
- * (web fetching, for example).\r
- * @since 1.4\r
- * @param filename string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()).\r
- * @param timeout int optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour)\r
- */\r
- function useCached($filename="", $timeout=3600) {\r
- $this->_timeout = $timeout;\r
- if ($filename=="") {\r
- $filename = $this->_generateFilename();\r
- }\r
- if (file_exists($filename) AND (time()-filemtime($filename) < $timeout)) {\r
- $this->_redirect($filename);\r
- }\r
- }\r
- \r
- \r
- /**\r
- * Saves this feed as a file on the local disk. After the file is saved, a redirect\r
- * header may be sent to redirect the user to the newly created file.\r
- * @since 1.4\r
- * \r
- * @param filename string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()).\r
- * @param redirect boolean optional send an HTTP redirect header or not. If true, the user will be automatically redirected to the created file.\r
- */\r
- function saveFeed($filename="", $displayContents=true) {\r
- if ($filename=="") {\r
- $filename = $this->_generateFilename();\r
- }\r
- $feedFile = fopen($filename, "w+");\r
- if ($feedFile) {\r
- fputs($feedFile,$this->createFeed());\r
- fclose($feedFile);\r
- if ($displayContents) {\r
- $this->_redirect($filename);\r
- }\r
- } else {\r
- echo "<br /><b>Error creating feed file, please check write permissions.</b><br />";\r
- }\r
- }\r
- \r
-}\r
-\r
-\r
-/**\r
- * FeedDate is an internal class that stores a date for a feed or feed item.\r
- * Usually, you won't need to use this.\r
- */\r
-class FeedDate {\r
- var $unix;\r
- \r
- /**\r
- * Creates a new instance of FeedDate representing a given date.\r
- * Accepts RFC 822, ISO 8601 date formats as well as unix time stamps.\r
- * @param mixed $dateString optional the date this FeedDate will represent. If not specified, the current date and time is used.\r
- */\r
- function FeedDate($dateString="") {\r
- if ($dateString=="") $dateString = date("r");\r
- \r
- if (is_integer($dateString)) {\r
- $this->unix = $dateString;\r
- return;\r
- }\r
- if (preg_match("~(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),\\s+)?(\\d{1,2})\\s+([a-zA-Z]{3})\\s+(\\d{4})\\s+(\\d{2}):(\\d{2}):(\\d{2})\\s+(.*)~",$dateString,$matches)) {\r
- $months = 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);\r
- $this->unix = mktime($matches[4],$matches[5],$matches[6],$months[$matches[2]],$matches[1],$matches[3]);\r
- if (substr($matches[7],0,1)=='+' OR substr($matches[7],0,1)=='-') {\r
- $tzOffset = (substr($matches[7],0,3) * 60 + substr($matches[7],-2)) * 60;\r
- } else {\r
- if (strlen($matches[7])==1) {\r
- $oneHour = 3600;\r
- $ord = ord($matches[7]);\r
- if ($ord < ord("M")) {\r
- $tzOffset = (ord("A") - $ord - 1) * $oneHour;\r
- } elseif ($ord >= ord("M") AND $matches[7]!="Z") {\r
- $tzOffset = ($ord - ord("M")) * $oneHour;\r
- } elseif ($matches[7]=="Z") {\r
- $tzOffset = 0;\r
- }\r
- }\r
- switch ($matches[7]) {\r
- case "UT":\r
- case "GMT": $tzOffset = 0;\r
- }\r
- }\r
- $this->unix += $tzOffset;\r
- return;\r
- }\r
- if (preg_match("~(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(.*)~",$dateString,$matches)) {\r
- $this->unix = mktime($matches[4],$matches[5],$matches[6],$matches[2],$matches[3],$matches[1]);\r
- if (substr($matches[7],0,1)=='+' OR substr($matches[7],0,1)=='-') {\r
- $tzOffset = (substr($matches[7],0,3) * 60 + substr($matches[7],-2)) * 60;\r
- } else {\r
- if ($matches[7]=="Z") {\r
- $tzOffset = 0;\r
- }\r
- }\r
- $this->unix += $tzOffset;\r
- return;\r
- }\r
- $this->unix = 0;\r
- }\r
-\r
- /**\r
- * Gets the date stored in this FeedDate as an RFC 822 date.\r
- *\r
- * @return a date in RFC 822 format\r
- */\r
- function rfc822() {\r
- //return gmdate("r",$this->unix);\r
- $date = gmdate("D, d M Y H:i:s", $this->unix);\r
- if (TIME_ZONE!="") $date .= " ".str_replace(":","",TIME_ZONE);\r
- return $date;\r
- }\r
- \r
- /**\r
- * Gets the date stored in this FeedDate as an ISO 8601 date.\r
- *\r
- * @return a date in ISO 8601 format\r
- */\r
- function iso8601() {\r
- $date = gmdate("Y-m-d\TH:i:sO",$this->unix);\r
- $date = substr($date,0,22) . ':' . substr($date,-2);\r
- if (TIME_ZONE!="") $date = str_replace("+00:00",TIME_ZONE,$date);\r
- return $date;\r
- }\r
- \r
- /**\r
- * Gets the date stored in this FeedDate as unix time stamp.\r
- *\r
- * @return a date as a unix time stamp\r
- */\r
- function unix() {\r
- return $this->unix;\r
- }\r
-}\r
-\r
-\r
-/**\r
- * RSSCreator10 is a FeedCreator that implements RDF Site Summary (RSS) 1.0.\r
- *\r
- * @see http://www.purl.org/rss/1.0/\r
- * @since 1.3\r
- * @author Kai Blankenhorn <kaib@bitfolge.de>\r
- */\r
-class RSSCreator10 extends FeedCreator {\r
-\r
- /**\r
- * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0.\r
- * The feed will contain all items previously added in the same order.\r
- * @return string the feed's complete text \r
- */\r
- function createFeed() { \r
- $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";\r
- $feed.= $this->_createGeneratorComment();\r
- if ($this->cssStyleSheet=="") {\r
- $cssStyleSheet = "http://www.w3.org/2000/08/w3c-synd/style.css";\r
- }\r
- $feed.= $this->_createStylesheetReferences();\r
- $feed.= "<rdf:RDF\n";\r
- $feed.= " xmlns=\"http://purl.org/rss/1.0/\"\n";\r
- $feed.= " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"; \r
- $feed.= " xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\"\n";\r
- $feed.= " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";\r
- $feed.= " <channel rdf:about=\"".$this->syndicationURL."\">\n";\r
- $feed.= " <title>".htmlspecialchars($this->title)."</title>\n";\r
- $feed.= " <description>".htmlspecialchars($this->description)."</description>\n";\r
- $feed.= " <link>".$this->link."</link>\n";\r
- if ($this->image!=null) {\r
- $feed.= " <image rdf:resource=\"".$this->image->url."\" />\n";\r
- }\r
- $now = new FeedDate();\r
- $feed.= " <dc:date>".htmlspecialchars($now->iso8601())."</dc:date>\n";\r
- $feed.= " <items>\n";\r
- $feed.= " <rdf:Seq>\n";\r
- for ($i=0;$i<count($this->items);$i++) {\r
- $feed.= " <rdf:li rdf:resource=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n";\r
- }\r
- $feed.= " </rdf:Seq>\n";\r
- $feed.= " </items>\n";\r
- $feed.= " </channel>\n";\r
- if ($this->image!=null) {\r
- $feed.= " <image rdf:about=\"".$this->image->url."\">\n";\r
- $feed.= " <title>".$this->image->title."</title>\n";\r
- $feed.= " <link>".$this->image->link."</link>\n";\r
- $feed.= " <url>".$this->image->url."</url>\n";\r
- $feed.= " </image>\n";\r
- }\r
- $feed.= $this->_createAdditionalElements($this->additionalElements, " ");\r
- \r
- for ($i=0;$i<count($this->items);$i++) {\r
- $feed.= " <item rdf:about=\"".htmlspecialchars($this->items[$i]->link)."\">\n";\r
- //$feed.= " <dc:type>Posting</dc:type>\n";\r
- $feed.= " <dc:format>text/html</dc:format>\n";\r
- if ($this->items[$i]->date!=null) {\r
- $itemDate = new FeedDate($this->items[$i]->date);\r
- $feed.= " <dc:date>".htmlspecialchars($itemDate->iso8601())."</dc:date>\n";\r
- }\r
- if ($this->items[$i]->source!="") {\r
- $feed.= " <dc:source>".htmlspecialchars($this->items[$i]->source)."</dc:source>\n";\r
- }\r
- if ($this->items[$i]->author!="") {\r
- $feed.= " <dc:creator>".htmlspecialchars($this->items[$i]->author)."</dc:creator>\n";\r
- }\r
- $feed.= " <title>".htmlspecialchars(strip_tags(strtr($this->items[$i]->title,"\n\r"," ")))."</title>\n";\r
- $feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n";\r
- $feed.= " <description>".htmlspecialchars($this->items[$i]->description)."</description>\n";\r
- $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");\r
- $feed.= " </item>\n";\r
- }\r
- $feed.= "</rdf:RDF>\n";\r
- return $feed;\r
- }\r
-}\r
-\r
-\r
-\r
-/**\r
- * RSSCreator091 is a FeedCreator that implements RSS 0.91 Spec, revision 3.\r
- *\r
- * @see http://my.netscape.com/publish/formats/rss-spec-0.91.html\r
- * @since 1.3\r
- * @author Kai Blankenhorn <kaib@bitfolge.de>\r
- */\r
-class RSSCreator091 extends FeedCreator {\r
-\r
- /**\r
- * Stores this RSS feed's version number.\r
- * @access private\r
- */\r
- var $RSSVersion;\r
-\r
- function RSSCreator091() {\r
- $this->_setRSSVersion("0.91");\r
- $this->contentType = "application/rss+xml";\r
- }\r
- \r
- /**\r
- * Sets this RSS feed's version number.\r
- * @access private\r
- */\r
- function _setRSSVersion($version) {\r
- $this->RSSVersion = $version;\r
- }\r
-\r
- /**\r
- * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0.\r
- * The feed will contain all items previously added in the same order.\r
- * @return string the feed's complete text \r
- */\r
- function createFeed() {\r
- $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";\r
- $feed.= $this->_createGeneratorComment();\r
- $feed.= $this->_createStylesheetReferences();\r
- $feed.= "<rss version=\"".$this->RSSVersion."\">\n"; \r
- $feed.= " <channel>\n";\r
- $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</title>\n";\r
- $this->descriptionTruncSize = 500;\r
- $feed.= " <description>".$this->getDescription()."</description>\n";\r
- $feed.= " <link>".$this->link."</link>\n";\r
- $now = new FeedDate();\r
- $feed.= " <lastBuildDate>".htmlspecialchars($now->rfc822())."</lastBuildDate>\n";\r
- $feed.= " <generator>".FEEDCREATOR_VERSION."</generator>\n";\r
-\r
- if ($this->image!=null) {\r
- $feed.= " <image>\n";\r
- $feed.= " <url>".$this->image->url."</url>\n"; \r
- $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->image->title),100)."</title>\n"; \r
- $feed.= " <link>".$this->image->link."</link>\n";\r
- if ($this->image->width!="") {\r
- $feed.= " <width>".$this->image->width."</width>\n";\r
- }\r
- if ($this->image->height!="") {\r
- $feed.= " <height>".$this->image->height."</height>\n";\r
- }\r
- if ($this->image->description!="") {\r
- $feed.= " <description>".$this->image->getDescription()."</description>\n";\r
- }\r
- $feed.= " </image>\n";\r
- }\r
- if ($this->language!="") {\r
- $feed.= " <language>".$this->language."</language>\n";\r
- }\r
- if ($this->copyright!="") {\r
- $feed.= " <copyright>".FeedCreator::iTrunc(htmlspecialchars($this->copyright),100)."</copyright>\n";\r
- }\r
- if ($this->editor!="") {\r
- $feed.= " <managingEditor>".FeedCreator::iTrunc(htmlspecialchars($this->editor),100)."</managingEditor>\n";\r
- }\r
- if ($this->webmaster!="") {\r
- $feed.= " <webMaster>".FeedCreator::iTrunc(htmlspecialchars($this->webmaster),100)."</webMaster>\n";\r
- }\r
- if ($this->pubDate!="") {\r
- $pubDate = new FeedDate($this->pubDate);\r
- $feed.= " <pubDate>".htmlspecialchars($pubDate->rfc822())."</pubDate>\n";\r
- }\r
- if ($this->category!="") {\r
- $feed.= " <category>".htmlspecialchars($this->category)."</category>\n";\r
- }\r
- if ($this->docs!="") {\r
- $feed.= " <docs>".FeedCreator::iTrunc(htmlspecialchars($this->docs),500)."</docs>\n";\r
- }\r
- if ($this->ttl!="") {\r
- $feed.= " <ttl>".htmlspecialchars($this->ttl)."</ttl>\n";\r
- }\r
- if ($this->rating!="") {\r
- $feed.= " <rating>".FeedCreator::iTrunc(htmlspecialchars($this->rating),500)."</rating>\n";\r
- }\r
- if ($this->skipHours!="") {\r
- $feed.= " <skipHours>".htmlspecialchars($this->skipHours)."</skipHours>\n";\r
- }\r
- if ($this->skipDays!="") {\r
- $feed.= " <skipDays>".htmlspecialchars($this->skipDays)."</skipDays>\n";\r
- }\r
- $feed.= $this->_createAdditionalElements($this->additionalElements, " ");\r
-\r
- for ($i=0;$i<count($this->items);$i++) {\r
- $feed.= " <item>\n";\r
- $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100)."</title>\n";\r
- $feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n";\r
- $feed.= " <description>".$this->items[$i]->getDescription()."</description>\n";\r
- \r
- if ($this->items[$i]->author!="") {\r
- $feed.= " <author>".htmlspecialchars($this->items[$i]->author)."</author>\n";\r
- }\r
- /*\r
- // on hold\r
- if ($this->items[$i]->source!="") {\r
- $feed.= " <source>".htmlspecialchars($this->items[$i]->source)."</source>\n";\r
- }\r
- */\r
- if ($this->items[$i]->category!="") {\r
- $feed.= " <category>".htmlspecialchars($this->items[$i]->category)."</category>\n";\r
- }\r
- if ($this->items[$i]->comments!="") {\r
- $feed.= " <comments>".htmlspecialchars($this->items[$i]->comments)."</comments>\n";\r
- }\r
- if ($this->items[$i]->date!="") {\r
- $itemDate = new FeedDate($this->items[$i]->date);\r
- $feed.= " <pubDate>".htmlspecialchars($itemDate->rfc822())."</pubDate>\n";\r
- }\r
- if ($this->items[$i]->guid!="") {\r
- $feed.= " <guid>".htmlspecialchars($this->items[$i]->guid)."</guid>\n";\r
- }\r
- $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");\r
- $feed.= " </item>\n";\r
- }\r
- $feed.= " </channel>\n";\r
- $feed.= "</rss>\n";\r
- return $feed;\r
- }\r
-}\r
-\r
-\r
-\r
-/**\r
- * RSSCreator20 is a FeedCreator that implements RDF Site Summary (RSS) 2.0.\r
- *\r
- * @see http://backend.userland.com/rss\r
- * @since 1.3\r
- * @author Kai Blankenhorn <kaib@bitfolge.de>\r
- */\r
-class RSSCreator20 extends RSSCreator091 {\r
-\r
- function RSSCreator20() {\r
- parent::_setRSSVersion("2.0");\r
- }\r
- \r
-}\r
-\r
-\r
-/**\r
- * PIECreator01 is a FeedCreator that implements the emerging PIE specification,\r
- * as in http://intertwingly.net/wiki/pie/Syntax.\r
- *\r
- * @deprecated\r
- * @since 1.3\r
- * @author Scott Reynen <scott@randomchaos.com> and Kai Blankenhorn <kaib@bitfolge.de>\r
- */\r
-class PIECreator01 extends FeedCreator {\r
- \r
- function PIECreator01() {\r
- $this->encoding = "utf-8";\r
- }\r
- \r
- function createFeed() {\r
- $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";\r
- $feed.= $this->_createStylesheetReferences();\r
- $feed.= "<feed version=\"0.1\" xmlns=\"http://example.com/newformat#\">\n"; \r
- $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</title>\n";\r
- $this->truncSize = 500;\r
- $feed.= " <subtitle>".$this->getDescription()."</subtitle>\n";\r
- $feed.= " <link>".$this->link."</link>\n";\r
- for ($i=0;$i<count($this->items);$i++) {\r
- $feed.= " <entry>\n";\r
- $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100)."</title>\n";\r
- $feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n";\r
- $itemDate = new FeedDate($this->items[$i]->date);\r
- $feed.= " <created>".htmlspecialchars($itemDate->iso8601())."</created>\n";\r
- $feed.= " <issued>".htmlspecialchars($itemDate->iso8601())."</issued>\n";\r
- $feed.= " <modified>".htmlspecialchars($itemDate->iso8601())."</modified>\n";\r
- $feed.= " <id>".htmlspecialchars($this->items[$i]->guid)."</id>\n";\r
- if ($this->items[$i]->author!="") {\r
- $feed.= " <author>\n";\r
- $feed.= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n";\r
- if ($this->items[$i]->authorEmail!="") {\r
- $feed.= " <email>".$this->items[$i]->authorEmail."</email>\n";\r
- }\r
- $feed.=" </author>\n";\r
- }\r
- $feed.= " <content type=\"text/html\" xml:lang=\"en-us\">\n";\r
- $feed.= " <div xmlns=\"http://www.w3.org/1999/xhtml\">".$this->items[$i]->getDescription()."</div>\n";\r
- $feed.= " </content>\n";\r
- $feed.= " </entry>\n";\r
- }\r
- $feed.= "</feed>\n";\r
- return $feed;\r
- }\r
-}\r
-\r
-\r
-/**\r
- * AtomCreator03 is a FeedCreator that implements the atom specification,\r
- * as in http://www.intertwingly.net/wiki/pie/FrontPage.\r
- * Please note that just by using AtomCreator03 you won't automatically\r
- * produce valid atom files. For example, you have to specify either an editor\r
- * for the feed or an author for every single feed item.\r
- *\r
- * Some elements have not been implemented yet. These are (incomplete list):\r
- * author URL, item author's email and URL, item contents, alternate links, \r
- * other link content types than text/html. Some of them may be created with\r
- * AtomCreator03::additionalElements.\r
- *\r
- * @see FeedCreator#additionalElements\r
- * @since 1.6\r
- * @author Kai Blankenhorn <kaib@bitfolge.de>, Scott Reynen <scott@randomchaos.com>\r
- */\r
-class AtomCreator03 extends FeedCreator {\r
-\r
- function AtomCreator03() {\r
- $this->contentType = "application/atom+xml";\r
- $this->encoding = "utf-8";\r
- }\r
- \r
- function createFeed() {\r
- $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";\r
- $feed.= $this->_createGeneratorComment();\r
- $feed.= $this->_createStylesheetReferences();\r
- $feed.= "<feed version=\"0.3\" xmlns=\"http://purl.org/atom/ns#\"";\r
- if ($this->language!="") {\r
- $feed.= " xml:lang=\"".$this->language."\"";\r
- }\r
- $feed.= ">\n"; \r
- $feed.= " <title>".htmlspecialchars($this->title)."</title>\n";\r
- $feed.= " <tagline>".htmlspecialchars($this->description)."</tagline>\n";\r
- $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->link)."\"/>\n";\r
- $feed.= " <id>".htmlspecialchars($this->link)."</id>\n";\r
- $now = new FeedDate();\r
- $feed.= " <modified>".htmlspecialchars($now->iso8601())."</modified>\n";\r
- if ($this->editor!="") {\r
- $feed.= " <author>\n";\r
- $feed.= " <name>".$this->editor."</name>\n";\r
- if ($this->editorEmail!="") {\r
- $feed.= " <email>".$this->editorEmail."</email>\n";\r
- }\r
- $feed.= " </author>\n";\r
- }\r
- $feed.= " <generator>".FEEDCREATOR_VERSION."</generator>\n";\r
- $feed.= $this->_createAdditionalElements($this->additionalElements, " ");\r
- for ($i=0;$i<count($this->items);$i++) {\r
- $feed.= " <entry>\n";\r
- $feed.= " <title>".htmlspecialchars(strip_tags($this->items[$i]->title))."</title>\n";\r
- $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n";\r
- if ($this->items[$i]->date=="") {\r
- $this->items[$i]->date = time();\r
- }\r
- $itemDate = new FeedDate($this->items[$i]->date);\r
- $feed.= " <created>".htmlspecialchars($itemDate->iso8601())."</created>\n";\r
- $feed.= " <issued>".htmlspecialchars($itemDate->iso8601())."</issued>\n";\r
- $feed.= " <modified>".htmlspecialchars($itemDate->iso8601())."</modified>\n";\r
- $feed.= " <id>".htmlspecialchars($this->items[$i]->link)."</id>\n";\r
- $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");\r
- if ($this->items[$i]->author!="") {\r
- $feed.= " <author>\n";\r
- $feed.= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n";\r
- $feed.= " </author>\n";\r
- }\r
- if ($this->items[$i]->description!="") {\r
- $feed.= " <summary>".htmlspecialchars($this->items[$i]->description)."</summary>\n";\r
- }\r
- $feed.= " </entry>\n";\r
- }\r
- $feed.= "</feed>\n";\r
- return $feed;\r
- }\r
-}\r
-\r
-\r
-/**\r
- * MBOXCreator is a FeedCreator that implements the mbox format\r
- * as described in http://www.qmail.org/man/man5/mbox.html\r
- *\r
- * @since 1.3\r
- * @author Kai Blankenhorn <kaib@bitfolge.de>\r
- */\r
-class MBOXCreator extends FeedCreator {\r
-\r
- function MBOXCreator() {\r
- $this->contentType = "text/plain";\r
- $this->encoding = "ISO-8859-15";\r
- }\r
- \r
- function qp_enc($input = "", $line_max = 76) { \r
- $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); \r
- $lines = preg_split("/(?:\r\n|\r|\n)/", $input); \r
- $eol = "\r\n"; \r
- $escape = "="; \r
- $output = ""; \r
- while( list(, $line) = each($lines) ) { \r
- //$line = rtrim($line); // remove trailing white space -> no =20\r\n necessary \r
- $linlen = strlen($line); \r
- $newline = ""; \r
- for($i = 0; $i < $linlen; $i++) { \r
- $c = substr($line, $i, 1); \r
- $dec = ord($c); \r
- if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only \r
- $c = "=20"; \r
- } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required \r
- $h2 = floor($dec/16); $h1 = floor($dec%16); \r
- $c = $escape.$hex["$h2"].$hex["$h1"]; \r
- } \r
- if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted \r
- $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay \r
- $newline = ""; \r
- } \r
- $newline .= $c; \r
- } // end of for \r
- $output .= $newline.$eol; \r
- } \r
- return trim($output); \r
- }\r
- \r
-\r
- /**\r
- * Builds the MBOX contents.\r
- * @return string the feed's complete text \r
- */\r
- function createFeed() {\r
- for ($i=0;$i<count($this->items);$i++) {\r
- if ($this->items[$i]->author!="") {\r
- $from = $this->items[$i]->author;\r
- } else {\r
- $from = $this->title;\r
- }\r
- $itemDate = new FeedDate($this->items[$i]->date);\r
- $feed.= "From ".strtr(MBOXCreator::qp_enc($from)," ","_")." ".date("D M d H:i:s Y",$itemDate->unix())."\n";\r
- $feed.= "Content-Type: text/plain;\n";\r
- $feed.= " charset=\"".$this->encoding."\"\n";\r
- $feed.= "Content-Transfer-Encoding: quoted-printable\n";\r
- $feed.= "Content-Type: text/plain\n";\r
- $feed.= "From: \"".MBOXCreator::qp_enc($from)."\"\n";\r
- $feed.= "Date: ".$itemDate->rfc822()."\n";\r
- $feed.= "Subject: ".MBOXCreator::qp_enc(FeedCreator::iTrunc($this->items[$i]->title,100))."\n";\r
- $feed.= "\n";\r
- $body = chunk_split(MBOXCreator::qp_enc($this->items[$i]->description));\r
- $feed.= preg_replace("~\nFrom ([^\n]*)(\n?)~","\n>From $1$2\n",$body);\r
- $feed.= "\n";\r
- $feed.= "\n";\r
- }\r
- return $feed;\r
- }\r
- \r
- /**\r
- * Generate a filename for the feed cache file. Overridden from FeedCreator to prevent XML data types.\r
- * @return string the feed cache filename\r
- * @since 1.4\r
- * @access private\r
- */\r
- function _generateFilename() {\r
- $fileInfo = pathinfo($_SERVER["PHP_SELF"]);\r
- return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".mbox";\r
- }\r
-}\r
-\r
-\r
-/**\r
- * OPMLCreator is a FeedCreator that implements OPML 1.0.\r
- * \r
- * @see http://opml.scripting.com/spec\r
- * @author Dirk Clemens, Kai Blankenhorn\r
- * @since 1.5\r
- */\r
-class OPMLCreator extends FeedCreator {\r
-\r
- function OPMLCreator() {\r
- $this->encoding = "utf-8";\r
- }\r
- \r
- function createFeed() { \r
- $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";\r
- $feed.= $this->_createGeneratorComment();\r
- $feed.= $this->_createStylesheetReferences();\r
- $feed.= "<opml xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n";\r
- $feed.= " <head>\n";\r
- $feed.= " <title>".htmlspecialchars($this->title)."</title>\n";\r
- if ($this->pubDate!="") {\r
- $date = new FeedDate($this->pubDate);\r
- $feed.= " <dateCreated>".$date->rfc822()."</dateCreated>\n";\r
- }\r
- if ($this->lastBuildDate!="") {\r
- $date = new FeedDate($this->lastBuildDate);\r
- $feed.= " <dateModified>".$date->rfc822()."</dateModified>\n";\r
- }\r
- if ($this->editor!="") {\r
- $feed.= " <ownerName>".$this->editor."</ownerName>\n";\r
- }\r
- if ($this->editorEmail!="") {\r
- $feed.= " <ownerEmail>".$this->editorEmail."</ownerEmail>\n";\r
- }\r
- $feed.= " </head>\n";\r
- $feed.= " <body>\n";\r
- for ($i=0;$i<count($this->items);$i++) {\r
- $feed.= " <outline type=\"rss\" ";\r
- $title = htmlspecialchars(strip_tags(strtr($this->items[$i]->title,"\n\r"," ")));\r
- $feed.= " title=\"".$title."\"";\r
- $feed.= " text=\"".$title."\"";\r
- //$feed.= " description=\"".htmlspecialchars($this->items[$i]->description)."\"";\r
- $feed.= " url=\"".htmlspecialchars($this->items[$i]->link)."\"";\r
- $feed.= "/>\n";\r
- }\r
- $feed.= " </body>\n";\r
- $feed.= "</opml>\n";\r
- return $feed;\r
- }\r
-}\r
-\r
-\r
-\r
-/**\r
- * HTMLCreator is a FeedCreator that writes an HTML feed file to a specific \r
- * location, overriding the createFeed method of the parent FeedCreator.\r
- * The HTML produced can be included over http by scripting languages, or serve\r
- * as the source for an IFrame.\r
- * All output by this class is embedded in <div></div> tags to enable formatting\r
- * using CSS. \r
- *\r
- * @author Pascal Van Hecke\r
- * @since 1.7\r
- */\r
-class HTMLCreator extends FeedCreator {\r
-\r
- var $contentType = "text/html";\r
- \r
- /**\r
- * Contains HTML to be output at the start of the feed's html representation.\r
- */\r
- var $header;\r
- \r
- /**\r
- * Contains HTML to be output at the end of the feed's html representation.\r
- */\r
- var $footer ;\r
- \r
- /**\r
- * Contains HTML to be output between entries. A separator is only used in \r
- * case of multiple entries.\r
- */\r
- var $separator;\r
- \r
- /**\r
- * Used to prefix the stylenames to make sure they are unique \r
- * and do not clash with stylenames on the users' page.\r
- */\r
- var $stylePrefix;\r
- \r
- /**\r
- * Determines whether the links open in a new window or not.\r
- */\r
- var $openInNewWindow = true;\r
- \r
- var $imageAlign ="right";\r
- \r
- /**\r
- * In case of very simple output you may want to get rid of the style tags,\r
- * hence this variable. There's no equivalent on item level, but of course you can \r
- * add strings to it while iterating over the items ($this->stylelessOutput .= ...)\r
- * and when it is non-empty, ONLY the styleless output is printed, the rest is ignored\r
- * in the function createFeed().\r
- */\r
- var $stylelessOutput ="";\r
-\r
- /**\r
- * Writes the HTML.\r
- * @return string the scripts's complete text \r
- */\r
- function createFeed() {\r
- // if there is styleless output, use the content of this variable and ignore the rest\r
- if ($this->stylelessOutput!="") {\r
- return $this->stylelessOutput;\r
- }\r
- \r
- //if no stylePrefix is set, generate it yourself depending on the script name\r
- if ($this->stylePrefix=="") {\r
- $this->stylePrefix = str_replace(".", "_", $this->_generateFilename())."_";\r
- }\r
-\r
- //set an openInNewWindow_token_to be inserted or not\r
- if ($this->openInNewWindow) {\r
- $targetInsert = " target='_blank'";\r
- }\r
- \r
- // use this array to put the lines in and implode later with "document.write" javascript\r
- $feedArray = array();\r
- if ($this->image!=null) {\r
- $imageStr = "<a href='".$this->image->link."'".$targetInsert.">".\r
- "<img src='".$this->image->url."' border='0' alt='".\r
- FeedCreator::iTrunc(htmlspecialchars($this->image->title),100).\r
- "' align='".$this->imageAlign."' ";\r
- if ($this->image->width) {\r
- $imageStr .=" width='".$this->image->width. "' ";\r
- }\r
- if ($this->image->height) {\r
- $imageStr .=" height='".$this->image->height."' ";\r
- }\r
- $imageStr .="/></a>";\r
- $feedArray[] = $imageStr;\r
- }\r
- \r
- if ($this->title) {\r
- $feedArray[] = "<div class='".$this->stylePrefix."title'><a href='".$this->link."' ".$targetInsert." class='".$this->stylePrefix."title'>".\r
- FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</a></div>";\r
- }\r
- if ($this->getDescription()) {\r
- $feedArray[] = "<div class='".$this->stylePrefix."description'>".\r
- str_replace("]]>", "", str_replace("<![CDATA[", "", $this->getDescription())).\r
- "</div>";\r
- }\r
- \r
- if ($this->header) {\r
- $feedArray[] = "<div class='".$this->stylePrefix."header'>".$this->header."</div>";\r
- }\r
- \r
- for ($i=0;$i<count($this->items);$i++) {\r
- if ($this->separator and $i > 0) {\r
- $feedArray[] = "<div class='".$this->stylePrefix."separator'>".$this->separator."</div>";\r
- }\r
- \r
- if ($this->items[$i]->title) {\r
- if ($this->items[$i]->link) {\r
- $feedArray[] = \r
- "<div class='".$this->stylePrefix."item_title'><a href='".$this->items[$i]->link."' class='".$this->stylePrefix.\r
- "item_title'".$targetInsert.">".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100).\r
- "</a></div>";\r
- } else {\r
- $feedArray[] = \r
- "<div class='".$this->stylePrefix."item_title'>".\r
- FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100).\r
- "</div>";\r
- }\r
- }\r
- if ($this->items[$i]->getDescription()) {\r
- $feedArray[] = \r
- "<div class='".$this->stylePrefix."item_description'>".\r
- str_replace("]]>", "", str_replace("<![CDATA[", "", $this->items[$i]->getDescription())).\r
- "</div>";\r
- }\r
- }\r
- if ($this->footer) {\r
- $feedArray[] = "<div class='".$this->stylePrefix."footer'>".$this->footer."</div>";\r
- }\r
- \r
- $feed= "".join($feedArray, "\r\n");\r
- return $feed;\r
- }\r
- \r
- /**\r
- * Overrrides parent to produce .html extensions\r
- *\r
- * @return string the feed cache filename\r
- * @since 1.4\r
- * @access private\r
- */\r
- function _generateFilename() {\r
- $fileInfo = pathinfo($_SERVER["PHP_SELF"]);\r
- return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".html";\r
- }\r
-} \r
-\r
-\r
-/**\r
- * JSCreator is a class that writes a js file to a specific \r
- * location, overriding the createFeed method of the parent HTMLCreator.\r
- *\r
- * @author Pascal Van Hecke\r
- */\r
-class JSCreator extends HTMLCreator {\r
- var $contentType = "text/javascript";\r
- \r
- /**\r
- * writes the javascript\r
- * @return string the scripts's complete text \r
- */\r
- function createFeed() \r
- {\r
- $feed = parent::createFeed();\r
- $feedArray = explode("\n",$feed);\r
- \r
- $jsFeed = "";\r
- foreach ($feedArray as $value) {\r
- $jsFeed .= "document.write('".trim(addslashes($value))."');\n";\r
- }\r
- return $jsFeed;\r
- }\r
- \r
- /**\r
- * Overrrides parent to produce .js extensions\r
- *\r
- * @return string the feed cache filename\r
- * @since 1.4\r
- * @access private\r
- */\r
- function _generateFilename() {\r
- $fileInfo = pathinfo($_SERVER["PHP_SELF"]);\r
- return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".js";\r
- }\r
- \r
-} \r
-\r
-\r
-\r
-/*** TEST SCRIPT *********************************************************\r
-\r
-//include("feedcreator.class.php"); \r
-\r
-$rss = new UniversalFeedCreator(); \r
-$rss->useCached(); \r
-$rss->title = "PHP news"; \r
-$rss->description = "daily news from the PHP scripting world"; \r
-\r
-//optional\r
-//$rss->descriptionTruncSize = 500;\r
-//$rss->descriptionHtmlSyndicated = true;\r
-//$rss->xslStyleSheet = "http://feedster.com/rss20.xsl";\r
-\r
-$rss->link = "http://www.dailyphp.net/news"; \r
-$rss->feedURL = "http://www.dailyphp.net/".$PHP_SELF; \r
-\r
-$image = new FeedImage(); \r
-$image->title = "dailyphp.net logo"; \r
-$image->url = "http://www.dailyphp.net/images/logo.gif"; \r
-$image->link = "http://www.dailyphp.net"; \r
-$image->description = "Feed provided by dailyphp.net. Click to visit."; \r
-\r
-//optional\r
-$image->descriptionTruncSize = 500;\r
-$image->descriptionHtmlSyndicated = true;\r
-\r
-$rss->image = $image; \r
-\r
-// get your news items from somewhere, e.g. your database: \r
-//mysql_select_db($dbHost, $dbUser, $dbPass); \r
-//$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC"); \r
-//while ($data = mysql_fetch_object($res)) { \r
- $item = new FeedItem(); \r
- $item->title = "This is an the test title of an item"; \r
- $item->link = "http://localhost/item/"; \r
- $item->description = "<b>description in </b><br/>HTML"; \r
- \r
- //optional\r
- //item->descriptionTruncSize = 500;\r
- $item->descriptionHtmlSyndicated = true;\r
- \r
- $item->date = time(); \r
- $item->source = "http://www.dailyphp.net"; \r
- $item->author = "John Doe"; \r
- \r
- $rss->addItem($item); \r
-//} \r
-\r
-// valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1, MBOX, OPML, ATOM0.3, HTML, JS\r
-echo $rss->saveFeed("RSS0.91", "feed.xml"); \r
-\r
-\r
-\r
-***************************************************************************/\r
-\r
-?>\r