1*572dd708SAndreas Gohr<?php 2*572dd708SAndreas Gohr// your local timezone, set to "" to disable or for GMT 3*572dd708SAndreas Gohrif (!defined('TIME_ZONE')) { 4*572dd708SAndreas Gohr define("TIME_ZONE", date("O", time())); 5*572dd708SAndreas Gohr} 6*572dd708SAndreas Gohr 7*572dd708SAndreas Gohr/** 8*572dd708SAndreas Gohr * Version string. 9*572dd708SAndreas Gohr */ 10*572dd708SAndreas Gohrdefine("FEEDCREATOR_VERSION", "FeedCreator 1.8"); 11*572dd708SAndreas Gohr 12*572dd708SAndreas Gohr/** 13*572dd708SAndreas Gohr * UniversalFeedCreator lets you choose during runtime which 14*572dd708SAndreas Gohr * format to build. 15*572dd708SAndreas Gohr * For general usage of a feed class, see the FeedCreator class 16*572dd708SAndreas Gohr * below or the example above. 17*572dd708SAndreas Gohr * 18*572dd708SAndreas Gohr * @since 1.3 19*572dd708SAndreas Gohr * @author Kai Blankenhorn <kaib@bitfolge.de> 20*572dd708SAndreas Gohr * @package de.bitfolge.feedcreator 21*572dd708SAndreas Gohr */ 22*572dd708SAndreas Gohrclass UniversalFeedCreator extends FeedCreator 23*572dd708SAndreas Gohr{ 24*572dd708SAndreas Gohr /** @var FeedCreator */ 25*572dd708SAndreas Gohr protected $_feed; 26*572dd708SAndreas Gohr 27*572dd708SAndreas Gohr /** 28*572dd708SAndreas Gohr * @param string $format 29*572dd708SAndreas Gohr */ 30*572dd708SAndreas Gohr protected function _setFormat($format) 31*572dd708SAndreas Gohr { 32*572dd708SAndreas Gohr switch (strtoupper($format)) { 33*572dd708SAndreas Gohr 34*572dd708SAndreas Gohr case "BASE": 35*572dd708SAndreas Gohr $this->format = $format; 36*572dd708SAndreas Gohr case "2.0": 37*572dd708SAndreas Gohr // fall through 38*572dd708SAndreas Gohr case "RSS2.0": 39*572dd708SAndreas Gohr $this->_feed = new RSSCreator20(); 40*572dd708SAndreas Gohr break; 41*572dd708SAndreas Gohr 42*572dd708SAndreas Gohr case "GEOPHOTORSS": 43*572dd708SAndreas Gohr case "PHOTORSS": 44*572dd708SAndreas Gohr case "GEORSS": 45*572dd708SAndreas Gohr $this->format = $format; 46*572dd708SAndreas Gohr case "1.0": 47*572dd708SAndreas Gohr // fall through 48*572dd708SAndreas Gohr case "RSS1.0": 49*572dd708SAndreas Gohr $this->_feed = new RSSCreator10(); 50*572dd708SAndreas Gohr break; 51*572dd708SAndreas Gohr 52*572dd708SAndreas Gohr case "0.91": 53*572dd708SAndreas Gohr // fall through 54*572dd708SAndreas Gohr case "RSS0.91": 55*572dd708SAndreas Gohr $this->_feed = new RSSCreator091(); 56*572dd708SAndreas Gohr break; 57*572dd708SAndreas Gohr 58*572dd708SAndreas Gohr case "PIE0.1": 59*572dd708SAndreas Gohr $this->_feed = new PIECreator01(); 60*572dd708SAndreas Gohr break; 61*572dd708SAndreas Gohr 62*572dd708SAndreas Gohr case "MBOX": 63*572dd708SAndreas Gohr $this->_feed = new MBOXCreator(); 64*572dd708SAndreas Gohr break; 65*572dd708SAndreas Gohr 66*572dd708SAndreas Gohr case "OPML": 67*572dd708SAndreas Gohr $this->_feed = new OPMLCreator(); 68*572dd708SAndreas Gohr break; 69*572dd708SAndreas Gohr 70*572dd708SAndreas Gohr case "TOOLBAR": 71*572dd708SAndreas Gohr $this->format = $format; 72*572dd708SAndreas Gohr 73*572dd708SAndreas Gohr case "ATOM": 74*572dd708SAndreas Gohr // fall through: always the latest ATOM version 75*572dd708SAndreas Gohr case "ATOM1.0": 76*572dd708SAndreas Gohr $this->_feed = new AtomCreator10(); 77*572dd708SAndreas Gohr break; 78*572dd708SAndreas Gohr 79*572dd708SAndreas Gohr case "ATOM0.3": 80*572dd708SAndreas Gohr $this->_feed = new AtomCreator03(); 81*572dd708SAndreas Gohr break; 82*572dd708SAndreas Gohr 83*572dd708SAndreas Gohr case "HTML": 84*572dd708SAndreas Gohr $this->_feed = new HTMLCreator(); 85*572dd708SAndreas Gohr break; 86*572dd708SAndreas Gohr 87*572dd708SAndreas Gohr case "PHP": 88*572dd708SAndreas Gohr $this->_feed = new PHPCreator(); 89*572dd708SAndreas Gohr break; 90*572dd708SAndreas Gohr case "GPX": 91*572dd708SAndreas Gohr $this->_feed = new GPXCreator(); 92*572dd708SAndreas Gohr break; 93*572dd708SAndreas Gohr case "KML": 94*572dd708SAndreas Gohr $this->_feed = new KMLCreator(); 95*572dd708SAndreas Gohr break; 96*572dd708SAndreas Gohr case "JS": 97*572dd708SAndreas Gohr // fall through 98*572dd708SAndreas Gohr case "JAVASCRIPT": 99*572dd708SAndreas Gohr $this->_feed = new JSCreator(); 100*572dd708SAndreas Gohr break; 101*572dd708SAndreas Gohr 102*572dd708SAndreas Gohr default: 103*572dd708SAndreas Gohr $this->_feed = new RSSCreator091(); 104*572dd708SAndreas Gohr break; 105*572dd708SAndreas Gohr } 106*572dd708SAndreas Gohr 107*572dd708SAndreas Gohr $vars = get_object_vars($this); 108*572dd708SAndreas Gohr foreach ($vars as $key => $value) { 109*572dd708SAndreas Gohr // prevent overwriting of properties "contentType", "encoding"; do not copy "_feed" itself 110*572dd708SAndreas Gohr if (!in_array($key, array("_feed", "contentType", "encoding"))) { 111*572dd708SAndreas Gohr $this->_feed->{$key} = $this->{$key}; 112*572dd708SAndreas Gohr } 113*572dd708SAndreas Gohr } 114*572dd708SAndreas Gohr } 115*572dd708SAndreas Gohr 116*572dd708SAndreas Gohr /** 117*572dd708SAndreas Gohr * Creates a syndication feed based on the items previously added. 118*572dd708SAndreas Gohr * 119*572dd708SAndreas Gohr * @see FeedCreator::addItem() 120*572dd708SAndreas Gohr * @param string $format format the feed should comply to. Valid values are: 121*572dd708SAndreas Gohr * "PIE0.1", "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3", "HTML", "JS" 122*572dd708SAndreas Gohr * @return string the contents of the feed. 123*572dd708SAndreas Gohr */ 124*572dd708SAndreas Gohr public function createFeed($format = "RSS0.91") 125*572dd708SAndreas Gohr { 126*572dd708SAndreas Gohr $this->_setFormat($format); 127*572dd708SAndreas Gohr 128*572dd708SAndreas Gohr return $this->_feed->createFeed(); 129*572dd708SAndreas Gohr } 130*572dd708SAndreas Gohr 131*572dd708SAndreas Gohr /** 132*572dd708SAndreas Gohr * Saves this feed as a file on the local disk. After the file is saved, an HTTP redirect 133*572dd708SAndreas Gohr * header may be sent to redirect the use to the newly created file. 134*572dd708SAndreas Gohr * 135*572dd708SAndreas Gohr * @since 1.4 136*572dd708SAndreas Gohr * @param string $format format the feed should comply to. Valid values are: 137*572dd708SAndreas Gohr * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM", 138*572dd708SAndreas Gohr * "ATOM0.3", "HTML", "JS" 139*572dd708SAndreas Gohr * @param string $filename optional the filename where a recent version of the feed is saved. If not 140*572dd708SAndreas Gohr * specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to 141*572dd708SAndreas Gohr * .xml (see _generateFilename()). 142*572dd708SAndreas Gohr * @param boolean $displayContents optional send the content of the file or not. If true, the file will be sent 143*572dd708SAndreas Gohr * in the body of the response. 144*572dd708SAndreas Gohr */ 145*572dd708SAndreas Gohr public function saveFeed($format = "RSS0.91", $filename = "", $displayContents = true) 146*572dd708SAndreas Gohr { 147*572dd708SAndreas Gohr $this->_setFormat($format); 148*572dd708SAndreas Gohr $this->_feed->saveFeed($filename, $displayContents); 149*572dd708SAndreas Gohr } 150*572dd708SAndreas Gohr 151*572dd708SAndreas Gohr /** 152*572dd708SAndreas Gohr * Turns on caching and checks if there is a recent version of this feed in the cache. 153*572dd708SAndreas Gohr * If there is, an HTTP redirect header is sent. 154*572dd708SAndreas Gohr * To effectively use caching, you should create the FeedCreator object and call this method 155*572dd708SAndreas Gohr * before anything else, especially before you do the time consuming task to build the feed 156*572dd708SAndreas Gohr * (web fetching, for example). 157*572dd708SAndreas Gohr * 158*572dd708SAndreas Gohr * @param string $format format the feed should comply to. Valid values are: 159*572dd708SAndreas Gohr * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3". 160*572dd708SAndreas Gohr * @param string $filename optional the filename where a recent version of the feed is saved. If not specified, the 161*572dd708SAndreas Gohr * filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see 162*572dd708SAndreas Gohr * _generateFilename()). 163*572dd708SAndreas Gohr * @param int $timeout optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 164*572dd708SAndreas Gohr * 1 hour) 165*572dd708SAndreas Gohr */ 166*572dd708SAndreas Gohr public function useCached($format = "RSS0.91", $filename = "", $timeout = 3600) 167*572dd708SAndreas Gohr { 168*572dd708SAndreas Gohr $this->_setFormat($format); 169*572dd708SAndreas Gohr $this->_feed->useCached($filename, $timeout); 170*572dd708SAndreas Gohr } 171*572dd708SAndreas Gohr} 172