2 /***************************************************************************
3 * FeedCreator class v1.7.2-ppt
4 * originally (c) Kai Blankenhorn
7 * v1.3 work by Scott Reynen (scott@randomchaos.com) and Kai Blankenhorn
8 * v1.5 OPML support by Dirk Clemens
9 * v1.7.2-mod on-the-fly feed generation by Fabian Wolf (info@f2w.de)
10 * v1.7.2-ppt ATOM 1.0 support by Mohammad Hafiz bin Ismail (mypapit@gmail.com)
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * @author www.bitfolge.de
30 * this version contains some smaller modifications for DokuWiki as well
33 * added Atom 1.0 support
34 * added enclosure support for RSS 2.0/ATOM 1.0
35 * added docs for v1.7.2-ppt only!
38 * added output function outputFeed for on-the-fly feed generation
41 * license changed to LGPL
45 * fixed left over debug code
48 * added HTML and JavaScript feeds (configurable via CSS) (thanks to Pascal Van Hecke)
49 * added HTML descriptions for all feed formats (thanks to Pascal Van Hecke)
50 * added a switch to select an external stylesheet (thanks to Pascal Van Hecke)
51 * changed default content-type to application/xml
52 * added character encoding setting
53 * fixed numerous smaller bugs (thanks to Sören Fuhrmann of golem.de)
54 * improved changing ATOM versions handling (thanks to August Trometer)
55 * improved the UniversalFeedCreator's useCached method (thanks to Sören Fuhrmann of golem.de)
56 * added charset output in HTTP headers (thanks to Sören Fuhrmann of golem.de)
57 * added Slashdot namespace to RSS 1.0 (thanks to Sören Fuhrmann of golem.de)
59 * See www.bitfolge.de for additional changelog info
61 // your local timezone, set to "" to disable or for GMT
62 define("TIME_ZONE",date("O", time()));
71 define("FEEDCREATOR_VERSION", "FeedCreator 1.7.2-ppt DokuWiki");
76 * A FeedItem is a part of a FeedCreator feed.
78 * @author Kai Blankenhorn <kaib@bitfolge.de>
81 class FeedItem extends HtmlDescribable {
83 * Mandatory attributes of an item.
85 var $title, $description, $link;
88 * Optional attributes of an item.
90 var $author, $authorEmail, $image, $category, $comments, $guid, $source, $creator;
93 * Publishing date of an item. May be in one of the following formats:
96 * "Mon, 20 Jan 03 18:05:41 +0400"
97 * "20 Jan 03 18:05:41 +0000"
100 * "2003-01-20T18:05:41+04:00"
108 * Add <enclosure> element tag RSS 2.0
109 * modified by : Mohammad Hafiz bin Ismail (mypapit@gmail.com)
113 * <enclosure length="17691" url="http://something.com/picture.jpg" type="image/jpeg" />
119 * Any additional elements to include as an assiciated array. All $key => $value pairs
120 * will be included unencoded in the feed item in the form
121 * <$key>$value</$key>
122 * Again: No encoding will be used! This means you can invalidate or enhance the feed
123 * if $value contains markup. This may be abused to embed tags not implemented by
124 * the FeedCreator class used.
126 var $additionalElements = Array();
132 class EnclosureItem extends HtmlDescribable {
138 var $url,$length,$type;
141 * For use with another extension like Yahoo mRSS
143 * These variables might not show up in
144 * later release / not finalize yet!
147 var $width, $height, $title, $description, $keywords, $thumburl;
149 var $additionalElements = Array();
155 * An FeedImage may be added to a FeedCreator feed.
156 * @author Kai Blankenhorn <kaib@bitfolge.de>
159 class FeedImage extends HtmlDescribable {
161 * Mandatory attributes of an image.
163 var $title, $url, $link;
166 * Optional attributes of an image.
168 var $width, $height, $description;
174 * An HtmlDescribable is an item within a feed that can have a description that may
175 * include HTML markup.
177 class HtmlDescribable {
179 * Indicates whether the description field should be rendered in HTML.
181 var $descriptionHtmlSyndicated;
184 * Indicates whether and to how many characters a description should be truncated.
186 var $descriptionTruncSize;
189 * Returns a formatted description field, depending on descriptionHtmlSyndicated and
190 * $descriptionTruncSize properties
191 * @return string the formatted description
193 function getDescription() {
194 $descriptionField = new FeedHtmlField($this->description);
195 $descriptionField->syndicateHtml = $this->descriptionHtmlSyndicated;
196 $descriptionField->truncSize = $this->descriptionTruncSize;
197 return $descriptionField->output();
205 * An FeedHtmlField describes and generates
206 * a feed, item or image html field (probably a description). Output is
207 * generated based on $truncSize, $syndicateHtml properties.
208 * @author Pascal Van Hecke <feedcreator.class.php@vanhecke.info>
211 class FeedHtmlField {
213 * Mandatory attributes of a FeedHtmlField.
215 var $rawFieldContent;
218 * Optional attributes of a FeedHtmlField.
221 var $truncSize, $syndicateHtml;
224 * Creates a new instance of FeedHtmlField.
225 * @param $string: if given, sets the rawFieldContent property
227 function FeedHtmlField($parFieldContent) {
228 if ($parFieldContent) {
229 $this->rawFieldContent = $parFieldContent;
235 * Creates the right output, depending on $truncSize, $syndicateHtml properties.
236 * @return string the formatted field
239 // when field available and syndicated in html we assume
240 // - valid html in $rawFieldContent and we enclose in CDATA tags
241 // - no truncation (truncating risks producing invalid html)
242 if (!$this->rawFieldContent) {
244 } elseif ($this->syndicateHtml) {
245 $result = "<![CDATA[".$this->rawFieldContent."]]>";
247 if ($this->truncSize and is_int($this->truncSize)) {
248 $result = FeedCreator::iTrunc(htmlspecialchars($this->rawFieldContent),$this->truncSize);
250 $result = htmlspecialchars($this->rawFieldContent);
261 * UniversalFeedCreator lets you choose during runtime which
263 * For general usage of a feed class, see the FeedCreator class
264 * below or the example above.
267 * @author Kai Blankenhorn <kaib@bitfolge.de>
269 class UniversalFeedCreator extends FeedCreator {
272 function _setFormat($format) {
273 switch (strtoupper($format)) {
278 $this->_feed = new RSSCreator20();
284 $this->_feed = new RSSCreator10();
290 $this->_feed = new RSSCreator091();
294 $this->_feed = new PIECreator01();
298 $this->_feed = new MBOXCreator();
302 $this->_feed = new OPMLCreator();
306 // fall through: always the latest ATOM version
308 $this->_feed = new AtomCreator10();
312 $this->_feed = new AtomCreator03();
316 $this->_feed = new HTMLCreator();
322 $this->_feed = new JSCreator();
326 $this->_feed = new RSSCreator091();
330 $vars = get_object_vars($this);
331 foreach ($vars as $key => $value) {
332 // prevent overwriting of properties "contentType", "encoding"; do not copy "_feed" itself
333 if (!in_array($key, array("_feed", "contentType", "encoding"))) {
334 $this->_feed->{$key} = $this->{$key};
339 function _sendMIME() {
340 header('Content-Type: '.$this->contentType.'; charset='.$this->encoding, true);
344 * Creates a syndication feed based on the items previously added.
346 * @see FeedCreator::addItem()
347 * @param string format format the feed should comply to. Valid values are:
348 * "PIE0.1", "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3", "HTML", "JS"
349 * @return string the contents of the feed.
351 function createFeed($format = "RSS0.91") {
352 $this->_setFormat($format);
353 return $this->_feed->createFeed();
357 * Saves this feed as a file on the local disk. After the file is saved, an HTTP redirect
358 * header may be sent to redirect the use to the newly created file.
361 * @param string format format the feed should comply to. Valid values are:
362 * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM", "ATOM0.3", "HTML", "JS"
363 * @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()).
364 * @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.
366 function saveFeed($format="RSS0.91", $filename="", $displayContents=true) {
367 $this->_setFormat($format);
368 $this->_feed->saveFeed($filename, $displayContents);
373 * Turns on caching and checks if there is a recent version of this feed in the cache.
374 * If there is, an HTTP redirect header is sent.
375 * To effectively use caching, you should create the FeedCreator object and call this method
376 * before anything else, especially before you do the time consuming task to build the feed
377 * (web fetching, for example).
379 * @param string format format the feed should comply to. Valid values are:
380 * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3".
381 * @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()).
382 * @param timeout int optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour)
384 function useCached($format="RSS0.91", $filename="", $timeout=3600) {
385 $this->_setFormat($format);
386 $this->_feed->useCached($filename, $timeout);
391 * Outputs feed to the browser - needed for on-the-fly feed generation (like it is done in WordPress, etc.)
393 * @param format string format the feed should comply to. Valid values are:
394 * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3".
396 function outputFeed($format='RSS0.91') {
397 $this->_setFormat($format);
399 $this->_feed->outputFeed();
407 * FeedCreator is the abstract base implementation for concrete
408 * implementations that implement a specific format of syndication.
411 * @author Kai Blankenhorn <kaib@bitfolge.de>
414 class FeedCreator extends HtmlDescribable {
417 * Mandatory attributes of a feed.
419 var $title, $description, $link;
423 * Optional attributes of a feed.
425 var $syndicationURL, $image, $language, $copyright, $pubDate, $lastBuildDate, $editor, $editorEmail, $webmaster, $category, $docs, $ttl, $rating, $skipHours, $skipDays;
428 * The url of the external xsl stylesheet used to format the naked rss feed.
429 * Ignored in the output when empty.
431 var $xslStyleSheet = "";
437 var $items = Array();
441 * This feed's MIME content type.
445 var $contentType = "application/xml";
449 * This feed's character encoding.
452 var $encoding = "utf-8";
456 * Any additional elements to include as an assiciated array. All $key => $value pairs
457 * will be included unencoded in the feed in the form
458 * <$key>$value</$key>
459 * Again: No encoding will be used! This means you can invalidate or enhance the feed
460 * if $value contains markup. This may be abused to embed tags not implemented by
461 * the FeedCreator class used.
463 var $additionalElements = Array();
467 * Adds an FeedItem to the feed.
469 * @param object FeedItem $item The FeedItem to add to the feed.
472 function addItem($item) {
473 $this->items[] = $item;
478 * Truncates a string to a certain length at the most sensible point.
479 * First, if there's a '.' character near the end of the string, the string is truncated after this character.
480 * If there is no '.', the string is truncated after the last ' ' character.
481 * If the string is truncated, " ..." is appended.
482 * If the string is already shorter than $length, it is returned unchanged.
485 * @param string string A string to be truncated.
486 * @param int length the maximum length the string should be truncated to
487 * @return string the truncated string
489 function iTrunc($string, $length) {
490 if (strlen($string)<=$length) {
494 $pos = strrpos($string,".");
495 if ($pos>=$length-4) {
496 $string = substr($string,0,$length-4);
497 $pos = strrpos($string,".");
499 if ($pos>=$length*0.4) {
500 return substr($string,0,$pos+1)." ...";
503 $pos = strrpos($string," ");
504 if ($pos>=$length-4) {
505 $string = substr($string,0,$length-4);
506 $pos = strrpos($string," ");
508 if ($pos>=$length*0.4) {
509 return substr($string,0,$pos)." ...";
512 return substr($string,0,$length-4)." ...";
518 * Creates a comment indicating the generator of this feed.
519 * The format of this comment seems to be recognized by
522 function _createGeneratorComment() {
523 return "<!-- generator=\"".FEEDCREATOR_VERSION."\" -->\n";
528 * Creates a string containing all additional elements specified in
529 * $additionalElements.
530 * @param elements array an associative array containing key => value pairs
531 * @param indentString string a string that will be inserted before every generated line
532 * @return string the XML tags corresponding to $additionalElements
534 function _createAdditionalElements($elements, $indentString="") {
536 if (is_array($elements)) {
537 foreach($elements AS $key => $value) {
538 $ae.= $indentString."<$key>$value</$key>\n";
544 function _createStylesheetReferences() {
546 if ($this->cssStyleSheet) $xml .= "<?xml-stylesheet href=\"".$this->cssStyleSheet."\" type=\"text/css\"?>\n";
547 if ($this->xslStyleSheet) $xml .= "<?xml-stylesheet href=\"".$this->xslStyleSheet."\" type=\"text/xsl\"?>\n";
553 * Builds the feed's text.
555 * @return string the feed's complete text
557 function createFeed() {
561 * Generate a filename for the feed cache file. The result will be $_SERVER["PHP_SELF"] with the extension changed to .xml.
564 * echo $_SERVER["PHP_SELF"]."\n";
565 * echo FeedCreator::_generateFilename();
569 * /rss/latestnews.php
572 * @return string the feed cache filename
576 function _generateFilename() {
577 $fileInfo = pathinfo($_SERVER["PHP_SELF"]);
578 return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".xml";
586 function _redirect($filename) {
587 // attention, heavily-commented-out-area
589 // maybe use this in addition to file time checking
590 //Header("Expires: ".date("r",time()+$this->_timeout));
592 /* no caching at all, doesn't seem to work as good:
593 Header("Cache-Control: no-cache");
594 Header("Pragma: no-cache");
597 // HTTP redirect, some feed readers' simple HTTP implementations don't follow it
598 //Header("Location: ".$filename);
600 header("Content-Type: ".$this->contentType."; charset=".$this->encoding."; filename=".utf8_basename($filename));
601 header("Content-Disposition: inline; filename=".utf8_basename($filename));
602 readfile($filename, "r");
607 * Turns on caching and checks if there is a recent version of this feed in the cache.
608 * If there is, an HTTP redirect header is sent.
609 * To effectively use caching, you should create the FeedCreator object and call this method
610 * before anything else, especially before you do the time consuming task to build the feed
611 * (web fetching, for example).
613 * @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()).
614 * @param timeout int optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour)
616 function useCached($filename="", $timeout=3600) {
617 $this->_timeout = $timeout;
619 $filename = $this->_generateFilename();
621 if (file_exists($filename) AND (time()-filemtime($filename) < $timeout)) {
622 $this->_redirect($filename);
628 * Saves this feed as a file on the local disk. After the file is saved, a redirect
629 * header may be sent to redirect the user to the newly created file.
632 * @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()).
633 * @param redirect boolean optional send an HTTP redirect header or not. If true, the user will be automatically redirected to the created file.
635 function saveFeed($filename="", $displayContents=true) {
637 $filename = $this->_generateFilename();
639 $feedFile = fopen($filename, "w+");
641 fputs($feedFile,$this->createFeed());
643 if ($displayContents) {
644 $this->_redirect($filename);
647 echo "<br /><b>Error creating feed file, please check write permissions.</b><br />";
652 * Outputs this feed directly to the browser - for on-the-fly feed generation
655 * still missing: proper header output - currently you have to add it manually
657 function outputFeed() {
658 echo $this->createFeed();
666 * FeedDate is an internal class that stores a date for a feed or feed item.
667 * Usually, you won't need to use this.
673 * Creates a new instance of FeedDate representing a given date.
674 * Accepts RFC 822, ISO 8601 date formats as well as unix time stamps.
675 * @param mixed $dateString optional the date this FeedDate will represent. If not specified, the current date and time is used.
677 function FeedDate($dateString="") {
678 if ($dateString=="") $dateString = date("r");
680 if (is_numeric($dateString)) {
681 $this->unix = $dateString;
684 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)) {
685 $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);
686 $this->unix = mktime($matches[4],$matches[5],$matches[6],$months[$matches[2]],$matches[1],$matches[3]);
687 if (substr($matches[7],0,1)=='+' OR substr($matches[7],0,1)=='-') {
688 $tzOffset = (((int) substr($matches[7],0,3) * 60) +
689 (int) substr($matches[7],-2)) * 60;
691 if (strlen($matches[7])==1) {
693 $ord = ord($matches[7]);
694 if ($ord < ord("M")) {
695 $tzOffset = (ord("A") - $ord - 1) * $oneHour;
696 } elseif ($ord >= ord("M") AND $matches[7]!="Z") {
697 $tzOffset = ($ord - ord("M")) * $oneHour;
698 } elseif ($matches[7]=="Z") {
702 switch ($matches[7]) {
704 case "GMT": $tzOffset = 0;
707 $this->unix += $tzOffset;
710 if (preg_match("~(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(.*)~",$dateString,$matches)) {
711 $this->unix = mktime($matches[4],$matches[5],$matches[6],$matches[2],$matches[3],$matches[1]);
712 if (substr($matches[7],0,1)=='+' OR substr($matches[7],0,1)=='-') {
713 $tzOffset = (((int) substr($matches[7],0,3) * 60) +
714 (int) substr($matches[7],-2)) * 60;
716 if ($matches[7]=="Z") {
720 $this->unix += $tzOffset;
727 * Gets the date stored in this FeedDate as an RFC 822 date.
729 * @return a date in RFC 822 format
732 //return gmdate("r",$this->unix);
733 $date = gmdate("D, d M Y H:i:s", $this->unix);
734 if (TIME_ZONE!="") $date .= " ".str_replace(":","",TIME_ZONE);
739 * Gets the date stored in this FeedDate as an ISO 8601 date.
741 * @return a date in ISO 8601 (RFC 3339) format
744 $date = gmdate("Y-m-d\TH:i:sO",$this->unix);
745 if (TIME_ZONE!="") $date = str_replace("+0000",TIME_ZONE,$date);
746 $date = substr($date,0,22) . ':' . substr($date,-2);
752 * Gets the date stored in this FeedDate as unix time stamp.
754 * @return a date as a unix time stamp
763 * RSSCreator10 is a FeedCreator that implements RDF Site Summary (RSS) 1.0.
765 * @see http://www.purl.org/rss/1.0/
767 * @author Kai Blankenhorn <kaib@bitfolge.de>
769 class RSSCreator10 extends FeedCreator {
772 * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0.
773 * The feed will contain all items previously added in the same order.
774 * @return string the feed's complete text
776 function createFeed() {
777 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
778 $feed.= $this->_createGeneratorComment();
779 if ($this->cssStyleSheet=="") {
780 $cssStyleSheet = "http://www.w3.org/2000/08/w3c-synd/style.css";
782 $feed.= $this->_createStylesheetReferences();
783 $feed.= "<rdf:RDF\n";
784 $feed.= " xmlns=\"http://purl.org/rss/1.0/\"\n";
785 $feed.= " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n";
786 $feed.= " xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\"\n";
787 $feed.= " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";
788 $feed.= " <channel rdf:about=\"".$this->syndicationURL."\">\n";
789 $feed.= " <title>".htmlspecialchars($this->title)."</title>\n";
790 $feed.= " <description>".htmlspecialchars($this->description)."</description>\n";
791 $feed.= " <link>".$this->link."</link>\n";
792 if ($this->image!=null) {
793 $feed.= " <image rdf:resource=\"".$this->image->url."\" />\n";
795 $now = new FeedDate();
796 $feed.= " <dc:date>".htmlspecialchars($now->iso8601())."</dc:date>\n";
797 $feed.= " <items>\n";
798 $feed.= " <rdf:Seq>\n";
799 $icnt = count($this->items);
800 for ($i=0; $i<$icnt; $i++) {
801 $feed.= " <rdf:li rdf:resource=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n";
803 $feed.= " </rdf:Seq>\n";
804 $feed.= " </items>\n";
805 $feed.= " </channel>\n";
806 if ($this->image!=null) {
807 $feed.= " <image rdf:about=\"".$this->image->url."\">\n";
808 $feed.= " <title>".htmlspecialchars($this->image->title)."</title>\n";
809 $feed.= " <link>".$this->image->link."</link>\n";
810 $feed.= " <url>".$this->image->url."</url>\n";
811 $feed.= " </image>\n";
813 $feed.= $this->_createAdditionalElements($this->additionalElements, " ");
815 $icnt = count($this->items);
816 for ($i=0; $i<$icnt; $i++) {
817 $feed.= " <item rdf:about=\"".htmlspecialchars($this->items[$i]->link)."\">\n";
818 //$feed.= " <dc:type>Posting</dc:type>\n";
819 $feed.= " <dc:format>text/html</dc:format>\n";
820 if ($this->items[$i]->date!=null) {
821 $itemDate = new FeedDate($this->items[$i]->date);
822 $feed.= " <dc:date>".htmlspecialchars($itemDate->iso8601())."</dc:date>\n";
824 if ($this->items[$i]->source!="") {
825 $feed.= " <dc:source>".htmlspecialchars($this->items[$i]->source)."</dc:source>\n";
827 if ($this->items[$i]->author!="") {
828 $feed.= " <dc:creator>".htmlspecialchars($this->items[$i]->author)."</dc:creator>\n";
830 $feed.= " <title>".htmlspecialchars(strip_tags(strtr($this->items[$i]->title,"\n\r"," ")))."</title>\n";
831 $feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n";
832 $feed.= " <description>".htmlspecialchars($this->items[$i]->description)."</description>\n";
833 $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");
834 $feed.= " </item>\n";
836 $feed.= "</rdf:RDF>\n";
844 * RSSCreator091 is a FeedCreator that implements RSS 0.91 Spec, revision 3.
846 * @see http://my.netscape.com/publish/formats/rss-spec-0.91.html
848 * @author Kai Blankenhorn <kaib@bitfolge.de>
850 class RSSCreator091 extends FeedCreator {
853 * Stores this RSS feed's version number.
858 function RSSCreator091() {
859 $this->_setRSSVersion("0.91");
860 $this->contentType = "application/rss+xml";
864 * Sets this RSS feed's version number.
867 function _setRSSVersion($version) {
868 $this->RSSVersion = $version;
872 * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0.
873 * The feed will contain all items previously added in the same order.
874 * @return string the feed's complete text
876 function createFeed() {
877 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
878 $feed.= $this->_createGeneratorComment();
879 $feed.= $this->_createStylesheetReferences();
880 $feed.= "<rss version=\"".$this->RSSVersion."\">\n";
881 $feed.= " <channel>\n";
882 $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</title>\n";
883 $this->descriptionTruncSize = 500;
884 $feed.= " <description>".$this->getDescription()."</description>\n";
885 $feed.= " <link>".$this->link."</link>\n";
886 $now = new FeedDate();
887 $feed.= " <lastBuildDate>".htmlspecialchars($now->rfc822())."</lastBuildDate>\n";
888 $feed.= " <generator>".FEEDCREATOR_VERSION."</generator>\n";
890 if ($this->image!=null) {
891 $feed.= " <image>\n";
892 $feed.= " <url>".$this->image->url."</url>\n";
893 $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->image->title),100)."</title>\n";
894 $feed.= " <link>".$this->image->link."</link>\n";
895 if ($this->image->width!="") {
896 $feed.= " <width>".$this->image->width."</width>\n";
898 if ($this->image->height!="") {
899 $feed.= " <height>".$this->image->height."</height>\n";
901 if ($this->image->description!="") {
902 $feed.= " <description>".$this->image->getDescription()."</description>\n";
904 $feed.= " </image>\n";
906 if ($this->language!="") {
907 $feed.= " <language>".$this->language."</language>\n";
909 if ($this->copyright!="") {
910 $feed.= " <copyright>".FeedCreator::iTrunc(htmlspecialchars($this->copyright),100)."</copyright>\n";
912 if ($this->editor!="") {
913 $feed.= " <managingEditor>".FeedCreator::iTrunc(htmlspecialchars($this->editor),100)."</managingEditor>\n";
915 if ($this->webmaster!="") {
916 $feed.= " <webMaster>".FeedCreator::iTrunc(htmlspecialchars($this->webmaster),100)."</webMaster>\n";
918 if ($this->pubDate!="") {
919 $pubDate = new FeedDate($this->pubDate);
920 $feed.= " <pubDate>".htmlspecialchars($pubDate->rfc822())."</pubDate>\n";
922 if ($this->category!="") {
923 // Changed for DokuWiki: multiple categories are possible
924 if(is_array($this->category)) foreach($this->category as $cat){
925 $feed.= " <category>".htmlspecialchars($cat)."</category>\n";
927 $feed.= " <category>".htmlspecialchars($this->category)."</category>\n";
930 if ($this->docs!="") {
931 $feed.= " <docs>".FeedCreator::iTrunc(htmlspecialchars($this->docs),500)."</docs>\n";
933 if ($this->ttl!="") {
934 $feed.= " <ttl>".htmlspecialchars($this->ttl)."</ttl>\n";
936 if ($this->rating!="") {
937 $feed.= " <rating>".FeedCreator::iTrunc(htmlspecialchars($this->rating),500)."</rating>\n";
939 if ($this->skipHours!="") {
940 $feed.= " <skipHours>".htmlspecialchars($this->skipHours)."</skipHours>\n";
942 if ($this->skipDays!="") {
943 $feed.= " <skipDays>".htmlspecialchars($this->skipDays)."</skipDays>\n";
945 $feed.= $this->_createAdditionalElements($this->additionalElements, " ");
947 $icnt = count($this->items);
948 for ($i=0; $i<$icnt; $i++) {
950 $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100)."</title>\n";
951 $feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n";
952 $feed.= " <description>".$this->items[$i]->getDescription()."</description>\n";
954 if ($this->items[$i]->author!="") {
955 $feed.= " <author>".htmlspecialchars($this->items[$i]->author)."</author>\n";
959 if ($this->items[$i]->source!="") {
960 $feed.= " <source>".htmlspecialchars($this->items[$i]->source)."</source>\n";
963 if ($this->items[$i]->category!="") {
964 // Changed for DokuWiki: multiple categories are possible
965 if(is_array($this->items[$i]->category)) foreach($this->items[$i]->category as $cat){
966 $feed.= " <category>".htmlspecialchars($cat)."</category>\n";
968 $feed.= " <category>".htmlspecialchars($this->items[$i]->category)."</category>\n";
972 if ($this->items[$i]->comments!="") {
973 $feed.= " <comments>".htmlspecialchars($this->items[$i]->comments)."</comments>\n";
975 if ($this->items[$i]->date!="") {
976 $itemDate = new FeedDate($this->items[$i]->date);
977 $feed.= " <pubDate>".htmlspecialchars($itemDate->rfc822())."</pubDate>\n";
979 if ($this->items[$i]->guid!="") {
980 $feed.= " <guid>".htmlspecialchars($this->items[$i]->guid)."</guid>\n";
982 $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");
984 if ($this->RSSVersion == "2.0" && $this->items[$i]->enclosure != null) {
985 $feed.= " <enclosure url=\"";
986 $feed.= $this->items[$i]->enclosure->url;
987 $feed.= "\" length=\"";
988 $feed.= $this->items[$i]->enclosure->length;
989 $feed.= "\" type=\"";
990 $feed.= $this->items[$i]->enclosure->type;
994 $feed.= " </item>\n";
997 $feed.= " </channel>\n";
1006 * RSSCreator20 is a FeedCreator that implements RDF Site Summary (RSS) 2.0.
1008 * @see http://backend.userland.com/rss
1010 * @author Kai Blankenhorn <kaib@bitfolge.de>
1012 class RSSCreator20 extends RSSCreator091 {
1014 function RSSCreator20() {
1015 parent::_setRSSVersion("2.0");
1022 * PIECreator01 is a FeedCreator that implements the emerging PIE specification,
1023 * as in http://intertwingly.net/wiki/pie/Syntax.
1027 * @author Scott Reynen <scott@randomchaos.com> and Kai Blankenhorn <kaib@bitfolge.de>
1029 class PIECreator01 extends FeedCreator {
1031 function PIECreator01() {
1032 $this->encoding = "utf-8";
1035 function createFeed() {
1036 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
1037 $feed.= $this->_createStylesheetReferences();
1038 $feed.= "<feed version=\"0.1\" xmlns=\"http://example.com/newformat#\">\n";
1039 $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</title>\n";
1040 $this->truncSize = 500;
1041 $feed.= " <subtitle>".$this->getDescription()."</subtitle>\n";
1042 $feed.= " <link>".$this->link."</link>\n";
1043 $icnt = count($this->items);
1044 for ($i=0; $i<$icnt; $i++) {
1045 $feed.= " <entry>\n";
1046 $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100)."</title>\n";
1047 $feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n";
1048 $itemDate = new FeedDate($this->items[$i]->date);
1049 $feed.= " <created>".htmlspecialchars($itemDate->iso8601())."</created>\n";
1050 $feed.= " <issued>".htmlspecialchars($itemDate->iso8601())."</issued>\n";
1051 $feed.= " <modified>".htmlspecialchars($itemDate->iso8601())."</modified>\n";
1052 $feed.= " <id>".htmlspecialchars($this->items[$i]->guid)."</id>\n";
1053 if ($this->items[$i]->author!="") {
1054 $feed.= " <author>\n";
1055 $feed.= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n";
1056 if ($this->items[$i]->authorEmail!="") {
1057 $feed.= " <email>".$this->items[$i]->authorEmail."</email>\n";
1059 $feed.=" </author>\n";
1061 $feed.= " <content type=\"text/html\" xml:lang=\"en-us\">\n";
1062 $feed.= " <div xmlns=\"http://www.w3.org/1999/xhtml\">".$this->items[$i]->getDescription()."</div>\n";
1063 $feed.= " </content>\n";
1064 $feed.= " </entry>\n";
1066 $feed.= "</feed>\n";
1072 * AtomCreator10 is a FeedCreator that implements the atom specification,
1073 * as in http://www.atomenabled.org/developers/syndication/atom-format-spec.php
1074 * Please note that just by using AtomCreator10 you won't automatically
1075 * produce valid atom files. For example, you have to specify either an editor
1076 * for the feed or an author for every single feed item.
1078 * Some elements have not been implemented yet. These are (incomplete list):
1079 * author URL, item author's email and URL, item contents, alternate links,
1080 * other link content types than text/html. Some of them may be created with
1081 * AtomCreator10::additionalElements.
1083 * @see FeedCreator#additionalElements
1084 * @since 1.7.2-mod (modified)
1085 * @author Mohammad Hafiz Ismail (mypapit@gmail.com)
1087 class AtomCreator10 extends FeedCreator {
1089 function AtomCreator10() {
1090 $this->contentType = "application/atom+xml";
1091 $this->encoding = "utf-8";
1094 function createFeed() {
1095 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
1096 $feed.= $this->_createGeneratorComment();
1097 $feed.= $this->_createStylesheetReferences();
1098 $feed.= "<feed xmlns=\"http://www.w3.org/2005/Atom\"";
1099 if ($this->language!="") {
1100 $feed.= " xml:lang=\"".$this->language."\"";
1103 $feed.= " <title>".htmlspecialchars($this->title)."</title>\n";
1104 $feed.= " <subtitle>".htmlspecialchars($this->description)."</subtitle>\n";
1105 $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->link)."\"/>\n";
1106 $feed.= " <id>".htmlspecialchars($this->link)."</id>\n";
1107 $now = new FeedDate();
1108 $feed.= " <updated>".htmlspecialchars($now->iso8601())."</updated>\n";
1109 if ($this->editor!="") {
1110 $feed.= " <author>\n";
1111 $feed.= " <name>".$this->editor."</name>\n";
1112 if ($this->editorEmail!="") {
1113 $feed.= " <email>".$this->editorEmail."</email>\n";
1115 $feed.= " </author>\n";
1117 $feed.= " <generator>".FEEDCREATOR_VERSION."</generator>\n";
1118 $feed.= "<link rel=\"self\" type=\"application/atom+xml\" href=\"". $this->syndicationURL . "\" />\n";
1119 $feed.= $this->_createAdditionalElements($this->additionalElements, " ");
1120 $icnt = count($this->items);
1121 for ($i=0; $i<$icnt; $i++) {
1122 $feed.= " <entry>\n";
1123 $feed.= " <title>".htmlspecialchars(strip_tags($this->items[$i]->title))."</title>\n";
1124 $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n";
1125 if ($this->items[$i]->date=="") {
1126 $this->items[$i]->date = time();
1128 $itemDate = new FeedDate($this->items[$i]->date);
1129 $feed.= " <published>".htmlspecialchars($itemDate->iso8601())."</published>\n";
1130 $feed.= " <updated>".htmlspecialchars($itemDate->iso8601())."</updated>\n";
1131 $feed.= " <id>".htmlspecialchars($this->items[$i]->link)."</id>\n";
1132 $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");
1133 if ($this->items[$i]->author!="") {
1134 $feed.= " <author>\n";
1135 $feed.= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n";
1136 $feed.= " </author>\n";
1138 if ($this->items[$i]->description!="") {
1139 $feed.= " <summary>".htmlspecialchars($this->items[$i]->description)."</summary>\n";
1141 if ($this->items[$i]->enclosure != null) {
1142 $feed.=" <link rel=\"enclosure\" href=\"". $this->items[$i]->enclosure->url ."\" type=\"". $this->items[$i]->enclosure->type."\" length=\"". $this->items[$i]->enclosure->length . "\" />\n";
1144 $feed.= " </entry>\n";
1146 $feed.= "</feed>\n";
1155 * AtomCreator03 is a FeedCreator that implements the atom specification,
1156 * as in http://www.intertwingly.net/wiki/pie/FrontPage.
1157 * Please note that just by using AtomCreator03 you won't automatically
1158 * produce valid atom files. For example, you have to specify either an editor
1159 * for the feed or an author for every single feed item.
1161 * Some elements have not been implemented yet. These are (incomplete list):
1162 * author URL, item author's email and URL, item contents, alternate links,
1163 * other link content types than text/html. Some of them may be created with
1164 * AtomCreator03::additionalElements.
1166 * @see FeedCreator#additionalElements
1168 * @author Kai Blankenhorn <kaib@bitfolge.de>, Scott Reynen <scott@randomchaos.com>
1170 class AtomCreator03 extends FeedCreator {
1172 function AtomCreator03() {
1173 $this->contentType = "application/atom+xml";
1174 $this->encoding = "utf-8";
1177 function createFeed() {
1178 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
1179 $feed.= $this->_createGeneratorComment();
1180 $feed.= $this->_createStylesheetReferences();
1181 $feed.= "<feed version=\"0.3\" xmlns=\"http://purl.org/atom/ns#\"";
1182 if ($this->language!="") {
1183 $feed.= " xml:lang=\"".$this->language."\"";
1186 $feed.= " <title>".htmlspecialchars($this->title)."</title>\n";
1187 $feed.= " <tagline>".htmlspecialchars($this->description)."</tagline>\n";
1188 $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->link)."\"/>\n";
1189 $feed.= " <id>".htmlspecialchars($this->link)."</id>\n";
1190 $now = new FeedDate();
1191 $feed.= " <modified>".htmlspecialchars($now->iso8601())."</modified>\n";
1192 if ($this->editor!="") {
1193 $feed.= " <author>\n";
1194 $feed.= " <name>".$this->editor."</name>\n";
1195 if ($this->editorEmail!="") {
1196 $feed.= " <email>".$this->editorEmail."</email>\n";
1198 $feed.= " </author>\n";
1200 $feed.= " <generator>".FEEDCREATOR_VERSION."</generator>\n";
1201 $feed.= $this->_createAdditionalElements($this->additionalElements, " ");
1202 $icnt = count($this->items);
1203 for ($i=0; $i<$icnt; $i++) {
1204 $feed.= " <entry>\n";
1205 $feed.= " <title>".htmlspecialchars(strip_tags($this->items[$i]->title))."</title>\n";
1206 $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n";
1207 if ($this->items[$i]->date=="") {
1208 $this->items[$i]->date = time();
1210 $itemDate = new FeedDate($this->items[$i]->date);
1211 $feed.= " <created>".htmlspecialchars($itemDate->iso8601())."</created>\n";
1212 $feed.= " <issued>".htmlspecialchars($itemDate->iso8601())."</issued>\n";
1213 $feed.= " <modified>".htmlspecialchars($itemDate->iso8601())."</modified>\n";
1214 $feed.= " <id>".htmlspecialchars($this->items[$i]->link)."</id>\n";
1215 $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");
1216 if ($this->items[$i]->author!="") {
1217 $feed.= " <author>\n";
1218 $feed.= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n";
1219 $feed.= " </author>\n";
1221 if ($this->items[$i]->description!="") {
1222 $feed.= " <summary>".htmlspecialchars($this->items[$i]->description)."</summary>\n";
1224 $feed.= " </entry>\n";
1226 $feed.= "</feed>\n";
1233 * MBOXCreator is a FeedCreator that implements the mbox format
1234 * as described in http://www.qmail.org/man/man5/mbox.html
1237 * @author Kai Blankenhorn <kaib@bitfolge.de>
1239 class MBOXCreator extends FeedCreator {
1241 function MBOXCreator() {
1242 $this->contentType = "text/plain";
1243 $this->encoding = "utf-8";
1246 function qp_enc($input = "", $line_max = 76) {
1247 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
1248 $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
1252 while( list(, $line) = each($lines) ) {
1253 //$line = rtrim($line); // remove trailing white space -> no =20\r\n necessary
1254 $linlen = strlen($line);
1256 for($i = 0; $i < $linlen; $i++) {
1257 $c = substr($line, $i, 1);
1259 if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only
1261 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
1262 $h2 = floor($dec/16);
1263 $h1 = floor($dec%16);
1264 $c = $escape.$hex["$h2"].$hex["$h1"];
1266 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
1267 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
1272 $output .= $newline.$eol;
1274 return trim($output);
1279 * Builds the MBOX contents.
1280 * @return string the feed's complete text
1282 function createFeed() {
1283 $icnt = count($this->items);
1284 for ($i=0; $i<$icnt; $i++) {
1285 if ($this->items[$i]->author!="") {
1286 $from = $this->items[$i]->author;
1288 $from = $this->title;
1290 $itemDate = new FeedDate($this->items[$i]->date);
1291 $feed.= "From ".strtr(MBOXCreator::qp_enc($from)," ","_")." ".date("D M d H:i:s Y",$itemDate->unix())."\n";
1292 $feed.= "Content-Type: text/plain;\n";
1293 $feed.= " charset=\"".$this->encoding."\"\n";
1294 $feed.= "Content-Transfer-Encoding: quoted-printable\n";
1295 $feed.= "Content-Type: text/plain\n";
1296 $feed.= "From: \"".MBOXCreator::qp_enc($from)."\"\n";
1297 $feed.= "Date: ".$itemDate->rfc822()."\n";
1298 $feed.= "Subject: ".MBOXCreator::qp_enc(FeedCreator::iTrunc($this->items[$i]->title,100))."\n";
1300 $body = chunk_split(MBOXCreator::qp_enc($this->items[$i]->description));
1301 $feed.= preg_replace("~\nFrom ([^\n]*)(\n?)~","\n>From $1$2\n",$body);
1309 * Generate a filename for the feed cache file. Overridden from FeedCreator to prevent XML data types.
1310 * @return string the feed cache filename
1314 function _generateFilename() {
1315 $fileInfo = pathinfo($_SERVER["PHP_SELF"]);
1316 return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".mbox";
1322 * OPMLCreator is a FeedCreator that implements OPML 1.0.
1324 * @see http://opml.scripting.com/spec
1325 * @author Dirk Clemens, Kai Blankenhorn
1328 class OPMLCreator extends FeedCreator {
1330 function OPMLCreator() {
1331 $this->encoding = "utf-8";
1334 function createFeed() {
1335 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
1336 $feed.= $this->_createGeneratorComment();
1337 $feed.= $this->_createStylesheetReferences();
1338 $feed.= "<opml xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n";
1339 $feed.= " <head>\n";
1340 $feed.= " <title>".htmlspecialchars($this->title)."</title>\n";
1341 if ($this->pubDate!="") {
1342 $date = new FeedDate($this->pubDate);
1343 $feed.= " <dateCreated>".$date->rfc822()."</dateCreated>\n";
1345 if ($this->lastBuildDate!="") {
1346 $date = new FeedDate($this->lastBuildDate);
1347 $feed.= " <dateModified>".$date->rfc822()."</dateModified>\n";
1349 if ($this->editor!="") {
1350 $feed.= " <ownerName>".$this->editor."</ownerName>\n";
1352 if ($this->editorEmail!="") {
1353 $feed.= " <ownerEmail>".$this->editorEmail."</ownerEmail>\n";
1355 $feed.= " </head>\n";
1356 $feed.= " <body>\n";
1357 $icnt = count($this->items);
1358 for ($i=0;$i<$icnt; $i++) {
1359 $feed.= " <outline type=\"rss\" ";
1360 $title = htmlspecialchars(strip_tags(strtr($this->items[$i]->title,"\n\r"," ")));
1361 $feed.= " title=\"".$title."\"";
1362 $feed.= " text=\"".$title."\"";
1363 //$feed.= " description=\"".htmlspecialchars($this->items[$i]->description)."\"";
1364 $feed.= " url=\"".htmlspecialchars($this->items[$i]->link)."\"";
1367 $feed.= " </body>\n";
1368 $feed.= "</opml>\n";
1376 * HTMLCreator is a FeedCreator that writes an HTML feed file to a specific
1377 * location, overriding the createFeed method of the parent FeedCreator.
1378 * The HTML produced can be included over http by scripting languages, or serve
1379 * as the source for an IFrame.
1380 * All output by this class is embedded in <div></div> tags to enable formatting
1383 * @author Pascal Van Hecke
1386 class HTMLCreator extends FeedCreator {
1388 var $contentType = "text/html";
1391 * Contains HTML to be output at the start of the feed's html representation.
1396 * Contains HTML to be output at the end of the feed's html representation.
1401 * Contains HTML to be output between entries. A separator is only used in
1402 * case of multiple entries.
1407 * Used to prefix the stylenames to make sure they are unique
1408 * and do not clash with stylenames on the users' page.
1413 * Determines whether the links open in a new window or not.
1415 var $openInNewWindow = true;
1417 var $imageAlign ="right";
1420 * In case of very simple output you may want to get rid of the style tags,
1421 * hence this variable. There's no equivalent on item level, but of course you can
1422 * add strings to it while iterating over the items ($this->stylelessOutput .= ...)
1423 * and when it is non-empty, ONLY the styleless output is printed, the rest is ignored
1424 * in the function createFeed().
1426 var $stylelessOutput ="";
1430 * @return string the scripts's complete text
1432 function createFeed() {
1433 // if there is styleless output, use the content of this variable and ignore the rest
1434 if ($this->stylelessOutput!="") {
1435 return $this->stylelessOutput;
1438 //if no stylePrefix is set, generate it yourself depending on the script name
1439 if ($this->stylePrefix=="") {
1440 $this->stylePrefix = str_replace(".", "_", $this->_generateFilename())."_";
1443 //set an openInNewWindow_token_to be inserted or not
1444 if ($this->openInNewWindow) {
1445 $targetInsert = " target='_blank'";
1448 // use this array to put the lines in and implode later with "document.write" javascript
1449 $feedArray = array();
1450 if ($this->image!=null) {
1451 $imageStr = "<a href='".$this->image->link."'".$targetInsert.">".
1452 "<img src='".$this->image->url."' border='0' alt='".
1453 FeedCreator::iTrunc(htmlspecialchars($this->image->title),100).
1454 "' align='".$this->imageAlign."' ";
1455 if ($this->image->width) {
1456 $imageStr .=" width='".$this->image->width. "' ";
1458 if ($this->image->height) {
1459 $imageStr .=" height='".$this->image->height."' ";
1461 $imageStr .="/></a>";
1462 $feedArray[] = $imageStr;
1466 $feedArray[] = "<div class='".$this->stylePrefix."title'><a href='".$this->link."' ".$targetInsert." class='".$this->stylePrefix."title'>".
1467 FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</a></div>";
1469 if ($this->getDescription()) {
1470 $feedArray[] = "<div class='".$this->stylePrefix."description'>".
1471 str_replace("]]>", "", str_replace("<![CDATA[", "", $this->getDescription())).
1475 if ($this->header) {
1476 $feedArray[] = "<div class='".$this->stylePrefix."header'>".$this->header."</div>";
1479 $icnt = count($this->items);
1480 for ($i=0; $i<$icnt; $i++) {
1481 if ($this->separator and $i > 0) {
1482 $feedArray[] = "<div class='".$this->stylePrefix."separator'>".$this->separator."</div>";
1485 if ($this->items[$i]->title) {
1486 if ($this->items[$i]->link) {
1488 "<div class='".$this->stylePrefix."item_title'><a href='".$this->items[$i]->link."' class='".$this->stylePrefix.
1489 "item_title'".$targetInsert.">".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100).
1493 "<div class='".$this->stylePrefix."item_title'>".
1494 FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100).
1498 if ($this->items[$i]->getDescription()) {
1500 "<div class='".$this->stylePrefix."item_description'>".
1501 str_replace("]]>", "", str_replace("<![CDATA[", "", $this->items[$i]->getDescription())).
1505 if ($this->footer) {
1506 $feedArray[] = "<div class='".$this->stylePrefix."footer'>".$this->footer."</div>";
1509 $feed= "".join($feedArray, "\r\n");
1514 * Overrrides parent to produce .html extensions
1516 * @return string the feed cache filename
1520 function _generateFilename() {
1521 $fileInfo = pathinfo($_SERVER["PHP_SELF"]);
1522 return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".html";
1528 * JSCreator is a class that writes a js file to a specific
1529 * location, overriding the createFeed method of the parent HTMLCreator.
1531 * @author Pascal Van Hecke
1533 class JSCreator extends HTMLCreator {
1534 var $contentType = "text/javascript";
1537 * writes the javascript
1538 * @return string the scripts's complete text
1540 function createFeed() {
1541 $feed = parent::createFeed();
1542 $feedArray = explode("\n",$feed);
1545 foreach ($feedArray as $value) {
1546 $jsFeed .= "document.write('".trim(addslashes($value))."');\n";
1552 * Overrrides parent to produce .js extensions
1554 * @return string the feed cache filename
1558 function _generateFilename() {
1559 $fileInfo = pathinfo($_SERVER["PHP_SELF"]);
1560 return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".js";
1566 * This class allows to override the hardcoded charset
1568 * @author Andreas Gohr <andi@splitbrain.org>
1570 class DokuWikiFeedCreator extends UniversalFeedCreator{
1571 function createFeed($format = "RSS0.91",$encoding='iso-8859-15') {
1572 $this->_setFormat($format);
1573 $this->_feed->encoding = $encoding;
1574 return $this->_feed->createFeed();
1580 //Setup VIM: ex: et ts=4 :