⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 feedcreator.php

📁 Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发
💻 PHP
📖 第 1 页 / 共 4 页
字号:
<?php/***************************************************************************FeedCreator class v1.7.3 (unofficial)originally (c) Kai Blankenhornwww.bitfolge.dekaib@bitfolge.dev1.3 work by Scott Reynen (scott@randomchaos.com) and Kai Blankenhornv1.5 OPML support by Dirk Clemensv1.7.2+ On-the-fly feed generation by Fabian Wolf (info@f2w.de)v1.7.3 ATOM 1.0 support by Mohammad Hafiz bin Ismail (mypapit@gmail.com)This library is free software; you can redistribute it and/ormodify it under the terms of the GNU Lesser General PublicLicense as published by the Free Software Foundation; eitherversion 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 ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA****************************************************************************Changelog:1.7.3	10-11-0406-May-2005 Johan Janssens	added generator attribute	added support for custom markup in feeds and items	added Atom 1.0 support	added enclosure support for RSS 2.0/ATOM 1.0v1.7.2+	03-12-05	added output function outputFeed for on-the-fly feed generationv1.7.2	Joomla! 1.015-Sep-2005 Rey Gigataras ^ Added publish date to syndicated feeds output [credit: gharding] ^ Added RSS Enclosure support to feedcreator [credit: Joseph L. LeBlanc] ^ Added Google Sitemap support to feedcreatorv1.7.2	10-11-04	license changed to LGPLv1.7.1	fixed a syntax bug	fixed left over debug codev1.7	07-18-04	added HTML and JavaScript feeds (configurable via CSS) (thanks to Pascal Van Hecke)	added HTML descriptions for all feed formats (thanks to Pascal Van Hecke)	added a switch to select an external stylesheet (thanks to Pascal Van Hecke)	changed default content-type to application/xml	added character encoding setting	fixed numerous smaller bugs (thanks to S锟絩en Fuhrmann of golem.de)	improved changing ATOM versions handling (thanks to August Trometer)	improved the UniversalFeedCreator's useCached method (thanks to S锟絩en Fuhrmann of golem.de)	added charset output in HTTP headers (thanks to S锟絩en Fuhrmann of golem.de)	added Slashdot namespace to RSS 1.0 (thanks to S锟絩en Fuhrmann of golem.de)v1.6	05-10-04	added stylesheet to RSS 1.0 feeds	fixed generator comment (thanks Kevin L. Papendick and Tanguy Pruvot)	fixed RFC822 date bug (thanks Tanguy Pruvot)	added TimeZone customization for RFC8601 (thanks Tanguy Pruvot)	fixed Content-type could be empty (thanks Tanguy Pruvot)	fixed author/creator in RSS1.0 (thanks Tanguy Pruvot)v1.6 beta	02-28-04	added Atom 0.3 support (not all features, though)	improved OPML 1.0 support (hopefully - added more elements)	added support for arbitrary additional elements (use with caution)	code beautification :-)	considered beta due to some internal changesv1.5.1	01-27-04	fixed some RSS 1.0 glitches (thanks to St锟絧hane Vanpoperynghe)	fixed some inconsistencies between documentation and code (thanks to Timothy Martin)v1.5	01-06-04	added support for OPML 1.0	added more documentationv1.4	11-11-03	optional feed saving and caching	improved documentation	minor improvementsv1.3	10-02-03	renamed to FeedCreator, as it not only creates RSS anymore	added support for mbox	tentative support for echo/necho/atom/pie/???v1.2	07-20-03	intelligent auto-truncating of RSS 0.91 attributes	don't create some attributes when they're not set	documentation improved	fixed a real and a possible bug with date conversions	code cleanupv1.1	06-29-03	added images to feeds	now includes most RSS 0.91 attributes	added RSS 2.0 feedsv1.0	06-24-03	initial release***************************************************************************//*** GENERAL USAGE *********************************************************include("feedcreator.class.php");$rss = new UniversalFeedCreator();$rss->useCached(); // use cached version if age<1 hour$rss->title = "PHP news";$rss->description = "daily news from the PHP scripting world";//optional$rss->descriptionTruncSize = 500;$rss->descriptionHtmlSyndicated = true;$rss->link = "http://www.dailyphp.net/news";$rss->syndicationURL = "http://www.dailyphp.net/".$_SERVER["PHP_SELF"];$image = new FeedImage();$image->title = "dailyphp.net logo";$image->url = "http://www.dailyphp.net/images/logo.gif";$image->link = "http://www.dailyphp.net";$image->description = "Feed provided by dailyphp.net. Click to visit.";//optional$image->descriptionTruncSize = 500;$image->descriptionHtmlSyndicated = true;$rss->image = $image;// get your news items from somewhere, e.g. your database:mysql_select_db($dbHost, $dbUser, $dbPass);$res = mysql_query('SELECT * FROM news ORDER BY newsdate DESC');while ($data = mysql_fetch_object($res)) {	$item = new FeedItem();	$item->title = $data->title;	$item->link = $data->url;	$item->description = $data->short;	//optional	item->descriptionTruncSize = 500;    item->descriptionHtmlSyndicated = true;    //optional (enclosure)    $item->enclosure = new EnclosureItem();    $item->enclosure->url='http://http://www.dailyphp.net/media/voice.mp3';    $item->enclosure->length="950230";    $item->enclosure->type='audio/x-mpeg'	$item->date = $data->newsdate;	$item->source = "http://www.dailyphp.net";	$item->author = "John Doe";	$rss->addItem($item);}// valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1 (deprecated),// MBOX, OPML, ATOM, ATOM10, ATOM0.3, HTML, JSecho $rss->saveFeed("RSS1.0", "news/feed.xml");//to generate "on-the-fly"$rss->outputFeed("RSS1.0");****************************************************************************		  A little setup												 ***************************************************************************/// your local timezone, set to "" to disable or for GMTdefine("TIME_ZONE","+01:00");/** * Version string. **/define("FEEDCREATOR_VERSION", "FeedCreator 1.7.3");/** * A FeedItem is a part of a FeedCreator feed. * * @author Kai Blankenhorn <kaib@bitfolge.de> * @since 1.3 */class FeedItem extends HtmlDescribable {	/**	 * Mandatory attributes of an item.	 */	var $title, $description, $link;	/**	 * Optional attributes of an item.	 */	var $author, $authorEmail, $image, $category, $comments, $guid, $source, $creator;	/**	 * Publishing date of an item. May be in one of the following formats:	 *	 *	RFC 822:	 *	"Mon, 20 Jan 03 18:05:41 +0400"	 *	"20 Jan 03 18:05:41 +0000"	 *	 *	ISO 8601:	 *	"2003-01-20T18:05:41+04:00"	 *	 *	Unix:	 *	1043082341	 */	var $date;	/**	 * Add <enclosure> element tag RSS 2.0	 * modified by : Mohammad Hafiz bin Ismail (mypapit@gmail.com)	 *	 *	 * display :	 * <enclosure length="17691" url="http://something.com/picture.jpg" type="image/jpeg" />	 *	 */	var $enclosure;	/**	 * Any additional elements to include as an assiciated array. All $key => $value pairs	 * will be included unencoded in the feed item in the form	 *	 <$key>$value</$key>	 * Again: No encoding will be used! This means you can invalidate or enhance the feed	 * if $value contains markup. This may be abused to embed tags not implemented by	 * the FeedCreator class used.	 */	var $additionalElements = Array();	/**	 * Any additional markup to include as a string.  This can be used in places where	 * $additionalElements isn't sufficient (for example, if you need to add elements with	 * attributes, eg: <element attribute="value" />).	 * @since 1.7.3	 */	 var $additionalMarkup = "";	// Added by Joseph LeBlanc, contact@jlleblanc.com	var $enclosures = Array();	function addEnclosure($url, $length = 0, $type)	{		$this->enclosures[] = array("url" => $url, "length" => $length, "type" => $type);	}	// end add, Joseph LeBlanc	// on hold	// var $source;}class EnclosureItem extends HtmlDescribable {	/*	*	* core variables	*	**/	var $url,$length,$type;	/*	* For use with another extension like Yahoo mRSS	* Warning :	* These variables might not show up in	* later release / not finalize yet!	*	*/	var $width, $height, $title, $description, $keywords, $thumburl;	var $additionalElements = Array();}/** * An FeedImage may be added to a FeedCreator feed. * @author Kai Blankenhorn <kaib@bitfolge.de> * @since 1.3 */class FeedImage extends HtmlDescribable {	/**	 * Mandatory attributes of an image.	 */	var $title, $url, $link;	/**	 * Optional attributes of an image.	 */	var $width, $height, $description;}/** * An HtmlDescribable is an item within a feed that can have a description that may * include HTML markup. */class HtmlDescribable {	/**	 * Indicates whether the description field should be rendered in HTML.	 */	var $descriptionHtmlSyndicated;	/**	 * Indicates whether and to how many characters a description should be truncated.	 */	var $descriptionTruncSize;	/**	 * Returns a formatted description field, depending on descriptionHtmlSyndicated and	 * $descriptionTruncSize properties	 * @return	string	the formatted description	 */	function getDescription() {		$descriptionField = new FeedHtmlField($this->description);		$descriptionField->syndicateHtml = $this->descriptionHtmlSyndicated;		$descriptionField->truncSize = $this->descriptionTruncSize;		return $descriptionField->output();	}}/** * An FeedHtmlField describes and generates * a feed, item or image html field (probably a description). Output is * generated based on $truncSize, $syndicateHtml properties. * @author Pascal Van Hecke <feedcreator.class.php@vanhecke.info> * @version 1.6 */class FeedHtmlField {	/**	 * Mandatory attributes of a FeedHtmlField.	 */	var $rawFieldContent;	/**	 * Optional attributes of a FeedHtmlField.	 *	 */	var $truncSize, $syndicateHtml;	/**	 * Creates a new instance of FeedHtmlField.	 * @param  $string: if given, sets the rawFieldContent property	 */	function FeedHtmlField($parFieldContent) {		if ($parFieldContent) {			$this->rawFieldContent = $parFieldContent;		}	}	/**	 * Creates the right output, depending on $truncSize, $syndicateHtml properties.	 * @return string	the formatted field	 */	function output() {		// when field available and syndicated in html we assume		// - valid html in $rawFieldContent and we enclose in CDATA tags		// - no truncation (truncating risks producing invalid html)		if (!$this->rawFieldContent) {			$result = "";		}	elseif ($this->syndicateHtml) {			$result = "<![CDATA[".$this->rawFieldContent."]]>";		} else {			if ($this->truncSize and is_int($this->truncSize)) {				$result = FeedCreator::iTrunc(htmlspecialchars($this->rawFieldContent),$this->truncSize);			} else {				$result = htmlspecialchars($this->rawFieldContent);			}		}		return $result;	}}/** * UniversalFeedCreator lets you choose during runtime which * format to build. * For general usage of a feed class, see the FeedCreator class * below or the example above. * * @since 1.3 * @author Kai Blankenhorn <kaib@bitfolge.de> */class UniversalFeedCreator extends FeedCreator {	var $_feed;	function _setMIME($format) {		switch (strtoupper($format)) {			case "2.0":				// fall through			case "RSS2.0":				header('Content-type: text/xml', true);				break;			case "1.0":				// fall through			case "RSS1.0":				header('Content-type: text/xml', true);				break;			case "PIE0.1":				header('Content-type: text/xml', true);				break;			case "MBOX":				header('Content-type: text/plain', true);				break;			case "OPML":				header('Content-type: text/xml', true);				break;			case "ATOM":				// fall through: always the latest ATOM version			case "ATOM1.0":				header('Content-type: application/xml', true);				break;			case "ATOM0.3":				header('Content-type: application/xml', true);				break;			case "HTML":				header('Content-type: text/html', true);				break;			case "JS":				// fall through			case "JAVASCRIPT":				header('Content-type: text/javascript', true);				break;			default:			case "0.91":				// fall through			case "RSS0.91":				header('Content-type: text/xml', true);				break;		}	}	function _setFormat($format) {		switch (strtoupper($format)) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -