reset scroll position when setting selection FS#1707
[dokuwiki/radio.git] / inc / feedcreator.class.php
blobbf66a568d9bfec3d53feca5c9754bf0f2f5258c2
1 <?php
2 /***************************************************************************
3 * FeedCreator class v1.7.2-ppt
4 * originally (c) Kai Blankenhorn
5 * www.bitfolge.de
6 * kaib@bitfolge.de
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
28 * Changelog:
30 * this version contains some smaller modifications for DokuWiki as well
32 * v1.7.2-ppt 11-21-05
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!
37 * v1.7.2-mod 03-12-05
38 * added output function outputFeed for on-the-fly feed generation
40 * v1.7.2 10-11-04
41 * license changed to LGPL
43 * v1.7.1
44 * fixed a syntax bug
45 * fixed left over debug code
47 * v1.7 07-18-04
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()));
67 /**
68 * Version string.
69 **/
71 define("FEEDCREATOR_VERSION", "FeedCreator 1.7.2-ppt DokuWiki");
75 /**
76 * A FeedItem is a part of a FeedCreator feed.
78 * @author Kai Blankenhorn <kaib@bitfolge.de>
79 * @since 1.3
81 class FeedItem extends HtmlDescribable {
82 /**
83 * Mandatory attributes of an item.
85 var $title, $description, $link;
87 /**
88 * Optional attributes of an item.
90 var $author, $authorEmail, $image, $category, $comments, $guid, $source, $creator;
92 /**
93 * Publishing date of an item. May be in one of the following formats:
95 * RFC 822:
96 * "Mon, 20 Jan 03 18:05:41 +0400"
97 * "20 Jan 03 18:05:41 +0000"
99 * ISO 8601:
100 * "2003-01-20T18:05:41+04:00"
102 * Unix:
103 * 1043082341
105 var $date;
108 * Add <enclosure> element tag RSS 2.0
109 * modified by : Mohammad Hafiz bin Ismail (mypapit@gmail.com)
112 * display :
113 * <enclosure length="17691" url="http://something.com/picture.jpg" type="image/jpeg" />
116 var $enclosure;
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();
128 // on hold
129 // var $source;
132 class EnclosureItem extends HtmlDescribable {
135 * core variables
138 var $url,$length,$type;
141 * For use with another extension like Yahoo mRSS
142 * Warning :
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>
157 * @since 1.3
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>
209 * @version 1.6
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
238 function output() {
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) {
243 $result = "";
244 } elseif ($this->syndicateHtml) {
245 $result = "<![CDATA[".$this->rawFieldContent."]]>";
246 } else {
247 if ($this->truncSize and is_int($this->truncSize)) {
248 $result = FeedCreator::iTrunc(htmlspecialchars($this->rawFieldContent),$this->truncSize);
249 } else {
250 $result = htmlspecialchars($this->rawFieldContent);
253 return $result;
261 * UniversalFeedCreator lets you choose during runtime which
262 * format to build.
263 * For general usage of a feed class, see the FeedCreator class
264 * below or the example above.
266 * @since 1.3
267 * @author Kai Blankenhorn <kaib@bitfolge.de>
269 class UniversalFeedCreator extends FeedCreator {
270 var $_feed;
272 function _setFormat($format) {
273 switch (strtoupper($format)) {
275 case "2.0":
276 // fall through
277 case "RSS2.0":
278 $this->_feed = new RSSCreator20();
279 break;
281 case "1.0":
282 // fall through
283 case "RSS1.0":
284 $this->_feed = new RSSCreator10();
285 break;
287 case "0.91":
288 // fall through
289 case "RSS0.91":
290 $this->_feed = new RSSCreator091();
291 break;
293 case "PIE0.1":
294 $this->_feed = new PIECreator01();
295 break;
297 case "MBOX":
298 $this->_feed = new MBOXCreator();
299 break;
301 case "OPML":
302 $this->_feed = new OPMLCreator();
303 break;
305 case "ATOM":
306 // fall through: always the latest ATOM version
307 case "ATOM1.0":
308 $this->_feed = new AtomCreator10();
309 break;
311 case "ATOM0.3":
312 $this->_feed = new AtomCreator03();
313 break;
315 case "HTML":
316 $this->_feed = new HTMLCreator();
317 break;
319 case "JS":
320 // fall through
321 case "JAVASCRIPT":
322 $this->_feed = new JSCreator();
323 break;
325 default:
326 $this->_feed = new RSSCreator091();
327 break;
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($format) {
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.
359 * @since 1.4
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);
398 $this->_sendMIME($format);
399 $this->_feed->outputFeed();
407 * FeedCreator is the abstract base implementation for concrete
408 * implementations that implement a specific format of syndication.
410 * @abstract
411 * @author Kai Blankenhorn <kaib@bitfolge.de>
412 * @since 1.4
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 = "";
435 * @access private
437 var $items = Array();
441 * This feed's MIME content type.
442 * @since 1.4
443 * @access private
445 var $contentType = "application/xml";
449 * This feed's character encoding.
450 * @since 1.6.1
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.
470 * @access public
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.
484 * @static
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) {
491 return $string;
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
520 * Syndic8.com.
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="") {
535 $ae = "";
536 if (is_array($elements)) {
537 foreach($elements AS $key => $value) {
538 $ae.= $indentString."<$key>$value</$key>\n";
541 return $ae;
544 function _createStylesheetReferences() {
545 $xml = "";
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";
548 return $xml;
553 * Builds the feed's text.
554 * @abstract
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.
562 * For example:
564 * echo $_SERVER["PHP_SELF"]."\n";
565 * echo FeedCreator::_generateFilename();
567 * would produce:
569 * /rss/latestnews.php
570 * latestnews.xml
572 * @return string the feed cache filename
573 * @since 1.4
574 * @access private
576 function _generateFilename() {
577 $fileInfo = pathinfo($_SERVER["PHP_SELF"]);
578 return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".xml";
583 * @since 1.4
584 * @access private
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=".basename($filename));
601 header("Content-Disposition: inline; filename=".basename($filename));
602 readfile($filename, "r");
603 die();
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).
612 * @since 1.4
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;
618 if ($filename=="") {
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.
630 * @since 1.4
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) {
636 if ($filename=="") {
637 $filename = $this->_generateFilename();
639 $feedFile = fopen($filename, "w+");
640 if ($feedFile) {
641 fputs($feedFile,$this->createFeed());
642 fclose($feedFile);
643 if ($displayContents) {
644 $this->_redirect($filename);
646 } else {
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
653 * @since 1.7.2-mod
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.
669 class FeedDate {
670 var $unix;
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;
682 return;
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 = (substr($matches[7],0,3) * 60 + substr($matches[7],-2)) * 60;
689 } else {
690 if (strlen($matches[7])==1) {
691 $oneHour = 3600;
692 $ord = ord($matches[7]);
693 if ($ord < ord("M")) {
694 $tzOffset = (ord("A") - $ord - 1) * $oneHour;
695 } elseif ($ord >= ord("M") AND $matches[7]!="Z") {
696 $tzOffset = ($ord - ord("M")) * $oneHour;
697 } elseif ($matches[7]=="Z") {
698 $tzOffset = 0;
701 switch ($matches[7]) {
702 case "UT":
703 case "GMT": $tzOffset = 0;
706 $this->unix += $tzOffset;
707 return;
709 if (preg_match("~(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(.*)~",$dateString,$matches)) {
710 $this->unix = mktime($matches[4],$matches[5],$matches[6],$matches[2],$matches[3],$matches[1]);
711 if (substr($matches[7],0,1)=='+' OR substr($matches[7],0,1)=='-') {
712 $tzOffset = (substr($matches[7],0,3) * 60 + substr($matches[7],-2)) * 60;
713 } else {
714 if ($matches[7]=="Z") {
715 $tzOffset = 0;
718 $this->unix += $tzOffset;
719 return;
721 $this->unix = 0;
725 * Gets the date stored in this FeedDate as an RFC 822 date.
727 * @return a date in RFC 822 format
729 function rfc822() {
730 //return gmdate("r",$this->unix);
731 $date = gmdate("D, d M Y H:i:s", $this->unix);
732 if (TIME_ZONE!="") $date .= " ".str_replace(":","",TIME_ZONE);
733 return $date;
737 * Gets the date stored in this FeedDate as an ISO 8601 date.
739 * @return a date in ISO 8601 (RFC 3339) format
741 function iso8601() {
742 $date = gmdate("Y-m-d\TH:i:sO",$this->unix);
743 if (TIME_ZONE!="") $date = str_replace("+0000",TIME_ZONE,$date);
744 $date = substr($date,0,22) . ':' . substr($date,-2);
745 return $date;
750 * Gets the date stored in this FeedDate as unix time stamp.
752 * @return a date as a unix time stamp
754 function unix() {
755 return $this->unix;
761 * RSSCreator10 is a FeedCreator that implements RDF Site Summary (RSS) 1.0.
763 * @see http://www.purl.org/rss/1.0/
764 * @since 1.3
765 * @author Kai Blankenhorn <kaib@bitfolge.de>
767 class RSSCreator10 extends FeedCreator {
770 * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0.
771 * The feed will contain all items previously added in the same order.
772 * @return string the feed's complete text
774 function createFeed() {
775 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
776 $feed.= $this->_createGeneratorComment();
777 if ($this->cssStyleSheet=="") {
778 $cssStyleSheet = "http://www.w3.org/2000/08/w3c-synd/style.css";
780 $feed.= $this->_createStylesheetReferences();
781 $feed.= "<rdf:RDF\n";
782 $feed.= " xmlns=\"http://purl.org/rss/1.0/\"\n";
783 $feed.= " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n";
784 $feed.= " xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\"\n";
785 $feed.= " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";
786 $feed.= " <channel rdf:about=\"".$this->syndicationURL."\">\n";
787 $feed.= " <title>".htmlspecialchars($this->title)."</title>\n";
788 $feed.= " <description>".htmlspecialchars($this->description)."</description>\n";
789 $feed.= " <link>".$this->link."</link>\n";
790 if ($this->image!=null) {
791 $feed.= " <image rdf:resource=\"".$this->image->url."\" />\n";
793 $now = new FeedDate();
794 $feed.= " <dc:date>".htmlspecialchars($now->iso8601())."</dc:date>\n";
795 $feed.= " <items>\n";
796 $feed.= " <rdf:Seq>\n";
797 for ($i=0;$i<count($this->items);$i++) {
798 $feed.= " <rdf:li rdf:resource=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n";
800 $feed.= " </rdf:Seq>\n";
801 $feed.= " </items>\n";
802 $feed.= " </channel>\n";
803 if ($this->image!=null) {
804 $feed.= " <image rdf:about=\"".$this->image->url."\">\n";
805 $feed.= " <title>".htmlspecialchars($this->image->title)."</title>\n";
806 $feed.= " <link>".$this->image->link."</link>\n";
807 $feed.= " <url>".$this->image->url."</url>\n";
808 $feed.= " </image>\n";
810 $feed.= $this->_createAdditionalElements($this->additionalElements, " ");
812 for ($i=0;$i<count($this->items);$i++) {
813 $feed.= " <item rdf:about=\"".htmlspecialchars($this->items[$i]->link)."\">\n";
814 //$feed.= " <dc:type>Posting</dc:type>\n";
815 $feed.= " <dc:format>text/html</dc:format>\n";
816 if ($this->items[$i]->date!=null) {
817 $itemDate = new FeedDate($this->items[$i]->date);
818 $feed.= " <dc:date>".htmlspecialchars($itemDate->iso8601())."</dc:date>\n";
820 if ($this->items[$i]->source!="") {
821 $feed.= " <dc:source>".htmlspecialchars($this->items[$i]->source)."</dc:source>\n";
823 if ($this->items[$i]->author!="") {
824 $feed.= " <dc:creator>".htmlspecialchars($this->items[$i]->author)."</dc:creator>\n";
826 $feed.= " <title>".htmlspecialchars(strip_tags(strtr($this->items[$i]->title,"\n\r"," ")))."</title>\n";
827 $feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n";
828 $feed.= " <description>".htmlspecialchars($this->items[$i]->description)."</description>\n";
829 $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");
830 $feed.= " </item>\n";
832 $feed.= "</rdf:RDF>\n";
833 return $feed;
840 * RSSCreator091 is a FeedCreator that implements RSS 0.91 Spec, revision 3.
842 * @see http://my.netscape.com/publish/formats/rss-spec-0.91.html
843 * @since 1.3
844 * @author Kai Blankenhorn <kaib@bitfolge.de>
846 class RSSCreator091 extends FeedCreator {
849 * Stores this RSS feed's version number.
850 * @access private
852 var $RSSVersion;
854 function RSSCreator091() {
855 $this->_setRSSVersion("0.91");
856 $this->contentType = "application/rss+xml";
860 * Sets this RSS feed's version number.
861 * @access private
863 function _setRSSVersion($version) {
864 $this->RSSVersion = $version;
868 * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0.
869 * The feed will contain all items previously added in the same order.
870 * @return string the feed's complete text
872 function createFeed() {
873 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
874 $feed.= $this->_createGeneratorComment();
875 $feed.= $this->_createStylesheetReferences();
876 $feed.= "<rss version=\"".$this->RSSVersion."\">\n";
877 $feed.= " <channel>\n";
878 $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</title>\n";
879 $this->descriptionTruncSize = 500;
880 $feed.= " <description>".$this->getDescription()."</description>\n";
881 $feed.= " <link>".$this->link."</link>\n";
882 $now = new FeedDate();
883 $feed.= " <lastBuildDate>".htmlspecialchars($now->rfc822())."</lastBuildDate>\n";
884 $feed.= " <generator>".FEEDCREATOR_VERSION."</generator>\n";
886 if ($this->image!=null) {
887 $feed.= " <image>\n";
888 $feed.= " <url>".$this->image->url."</url>\n";
889 $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->image->title),100)."</title>\n";
890 $feed.= " <link>".$this->image->link."</link>\n";
891 if ($this->image->width!="") {
892 $feed.= " <width>".$this->image->width."</width>\n";
894 if ($this->image->height!="") {
895 $feed.= " <height>".$this->image->height."</height>\n";
897 if ($this->image->description!="") {
898 $feed.= " <description>".$this->image->getDescription()."</description>\n";
900 $feed.= " </image>\n";
902 if ($this->language!="") {
903 $feed.= " <language>".$this->language."</language>\n";
905 if ($this->copyright!="") {
906 $feed.= " <copyright>".FeedCreator::iTrunc(htmlspecialchars($this->copyright),100)."</copyright>\n";
908 if ($this->editor!="") {
909 $feed.= " <managingEditor>".FeedCreator::iTrunc(htmlspecialchars($this->editor),100)."</managingEditor>\n";
911 if ($this->webmaster!="") {
912 $feed.= " <webMaster>".FeedCreator::iTrunc(htmlspecialchars($this->webmaster),100)."</webMaster>\n";
914 if ($this->pubDate!="") {
915 $pubDate = new FeedDate($this->pubDate);
916 $feed.= " <pubDate>".htmlspecialchars($pubDate->rfc822())."</pubDate>\n";
918 if ($this->category!="") {
919 // Changed for DokuWiki: multiple categories are possible
920 if(is_array($this->category)) foreach($this->category as $cat){
921 $feed.= " <category>".htmlspecialchars($cat)."</category>\n";
922 }else{
923 $feed.= " <category>".htmlspecialchars($this->category)."</category>\n";
926 if ($this->docs!="") {
927 $feed.= " <docs>".FeedCreator::iTrunc(htmlspecialchars($this->docs),500)."</docs>\n";
929 if ($this->ttl!="") {
930 $feed.= " <ttl>".htmlspecialchars($this->ttl)."</ttl>\n";
932 if ($this->rating!="") {
933 $feed.= " <rating>".FeedCreator::iTrunc(htmlspecialchars($this->rating),500)."</rating>\n";
935 if ($this->skipHours!="") {
936 $feed.= " <skipHours>".htmlspecialchars($this->skipHours)."</skipHours>\n";
938 if ($this->skipDays!="") {
939 $feed.= " <skipDays>".htmlspecialchars($this->skipDays)."</skipDays>\n";
941 $feed.= $this->_createAdditionalElements($this->additionalElements, " ");
943 for ($i=0;$i<count($this->items);$i++) {
944 $feed.= " <item>\n";
945 $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100)."</title>\n";
946 $feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n";
947 $feed.= " <description>".$this->items[$i]->getDescription()."</description>\n";
949 if ($this->items[$i]->author!="") {
950 $feed.= " <author>".htmlspecialchars($this->items[$i]->author)."</author>\n";
953 // on hold
954 if ($this->items[$i]->source!="") {
955 $feed.= " <source>".htmlspecialchars($this->items[$i]->source)."</source>\n";
958 if ($this->items[$i]->category!="") {
959 // Changed for DokuWiki: multiple categories are possible
960 if(is_array($this->items[$i]->category)) foreach($this->items[$i]->category as $cat){
961 $feed.= " <category>".htmlspecialchars($cat)."</category>\n";
962 }else{
963 $feed.= " <category>".htmlspecialchars($this->items[$i]->category)."</category>\n";
967 if ($this->items[$i]->comments!="") {
968 $feed.= " <comments>".htmlspecialchars($this->items[$i]->comments)."</comments>\n";
970 if ($this->items[$i]->date!="") {
971 $itemDate = new FeedDate($this->items[$i]->date);
972 $feed.= " <pubDate>".htmlspecialchars($itemDate->rfc822())."</pubDate>\n";
974 if ($this->items[$i]->guid!="") {
975 $feed.= " <guid>".htmlspecialchars($this->items[$i]->guid)."</guid>\n";
977 $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");
979 if ($this->RSSVersion == "2.0" && $this->items[$i]->enclosure != NULL)
981 $feed.= " <enclosure url=\"";
982 $feed.= $this->items[$i]->enclosure->url;
983 $feed.= "\" length=\"";
984 $feed.= $this->items[$i]->enclosure->length;
985 $feed.= "\" type=\"";
986 $feed.= $this->items[$i]->enclosure->type;
987 $feed.= "\"/>\n";
992 $feed.= " </item>\n";
995 $feed.= " </channel>\n";
996 $feed.= "</rss>\n";
997 return $feed;
1004 * RSSCreator20 is a FeedCreator that implements RDF Site Summary (RSS) 2.0.
1006 * @see http://backend.userland.com/rss
1007 * @since 1.3
1008 * @author Kai Blankenhorn <kaib@bitfolge.de>
1010 class RSSCreator20 extends RSSCreator091 {
1012 function RSSCreator20() {
1013 parent::_setRSSVersion("2.0");
1020 * PIECreator01 is a FeedCreator that implements the emerging PIE specification,
1021 * as in http://intertwingly.net/wiki/pie/Syntax.
1023 * @deprecated
1024 * @since 1.3
1025 * @author Scott Reynen <scott@randomchaos.com> and Kai Blankenhorn <kaib@bitfolge.de>
1027 class PIECreator01 extends FeedCreator {
1029 function PIECreator01() {
1030 $this->encoding = "utf-8";
1033 function createFeed() {
1034 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
1035 $feed.= $this->_createStylesheetReferences();
1036 $feed.= "<feed version=\"0.1\" xmlns=\"http://example.com/newformat#\">\n";
1037 $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</title>\n";
1038 $this->truncSize = 500;
1039 $feed.= " <subtitle>".$this->getDescription()."</subtitle>\n";
1040 $feed.= " <link>".$this->link."</link>\n";
1041 for ($i=0;$i<count($this->items);$i++) {
1042 $feed.= " <entry>\n";
1043 $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100)."</title>\n";
1044 $feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n";
1045 $itemDate = new FeedDate($this->items[$i]->date);
1046 $feed.= " <created>".htmlspecialchars($itemDate->iso8601())."</created>\n";
1047 $feed.= " <issued>".htmlspecialchars($itemDate->iso8601())."</issued>\n";
1048 $feed.= " <modified>".htmlspecialchars($itemDate->iso8601())."</modified>\n";
1049 $feed.= " <id>".htmlspecialchars($this->items[$i]->guid)."</id>\n";
1050 if ($this->items[$i]->author!="") {
1051 $feed.= " <author>\n";
1052 $feed.= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n";
1053 if ($this->items[$i]->authorEmail!="") {
1054 $feed.= " <email>".$this->items[$i]->authorEmail."</email>\n";
1056 $feed.=" </author>\n";
1058 $feed.= " <content type=\"text/html\" xml:lang=\"en-us\">\n";
1059 $feed.= " <div xmlns=\"http://www.w3.org/1999/xhtml\">".$this->items[$i]->getDescription()."</div>\n";
1060 $feed.= " </content>\n";
1061 $feed.= " </entry>\n";
1063 $feed.= "</feed>\n";
1064 return $feed;
1069 * AtomCreator10 is a FeedCreator that implements the atom specification,
1070 * as in http://www.atomenabled.org/developers/syndication/atom-format-spec.php
1071 * Please note that just by using AtomCreator10 you won't automatically
1072 * produce valid atom files. For example, you have to specify either an editor
1073 * for the feed or an author for every single feed item.
1075 * Some elements have not been implemented yet. These are (incomplete list):
1076 * author URL, item author's email and URL, item contents, alternate links,
1077 * other link content types than text/html. Some of them may be created with
1078 * AtomCreator10::additionalElements.
1080 * @see FeedCreator#additionalElements
1081 * @since 1.7.2-mod (modified)
1082 * @author Mohammad Hafiz Ismail (mypapit@gmail.com)
1084 class AtomCreator10 extends FeedCreator {
1086 function AtomCreator10() {
1087 $this->contentType = "application/atom+xml";
1088 $this->encoding = "utf-8";
1091 function createFeed() {
1092 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
1093 $feed.= $this->_createGeneratorComment();
1094 $feed.= $this->_createStylesheetReferences();
1095 $feed.= "<feed xmlns=\"http://www.w3.org/2005/Atom\"";
1096 if ($this->language!="") {
1097 $feed.= " xml:lang=\"".$this->language."\"";
1099 $feed.= ">\n";
1100 $feed.= " <title>".htmlspecialchars($this->title)."</title>\n";
1101 $feed.= " <subtitle>".htmlspecialchars($this->description)."</subtitle>\n";
1102 $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->link)."\"/>\n";
1103 $feed.= " <id>".htmlspecialchars($this->link)."</id>\n";
1104 $now = new FeedDate();
1105 $feed.= " <updated>".htmlspecialchars($now->iso8601())."</updated>\n";
1106 if ($this->editor!="") {
1107 $feed.= " <author>\n";
1108 $feed.= " <name>".$this->editor."</name>\n";
1109 if ($this->editorEmail!="") {
1110 $feed.= " <email>".$this->editorEmail."</email>\n";
1112 $feed.= " </author>\n";
1114 $feed.= " <generator>".FEEDCREATOR_VERSION."</generator>\n";
1115 $feed.= "<link rel=\"self\" type=\"application/atom+xml\" href=\"". $this->syndicationURL . "\" />\n";
1116 $feed.= $this->_createAdditionalElements($this->additionalElements, " ");
1117 for ($i=0;$i<count($this->items);$i++) {
1118 $feed.= " <entry>\n";
1119 $feed.= " <title>".htmlspecialchars(strip_tags($this->items[$i]->title))."</title>\n";
1120 $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n";
1121 if ($this->items[$i]->date=="") {
1122 $this->items[$i]->date = time();
1124 $itemDate = new FeedDate($this->items[$i]->date);
1125 $feed.= " <published>".htmlspecialchars($itemDate->iso8601())."</published>\n";
1126 $feed.= " <updated>".htmlspecialchars($itemDate->iso8601())."</updated>\n";
1127 $feed.= " <id>".htmlspecialchars($this->items[$i]->link)."</id>\n";
1128 $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");
1129 if ($this->items[$i]->author!="") {
1130 $feed.= " <author>\n";
1131 $feed.= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n";
1132 $feed.= " </author>\n";
1134 if ($this->items[$i]->description!="") {
1135 $feed.= " <summary>".htmlspecialchars($this->items[$i]->description)."</summary>\n";
1137 if ($this->items[$i]->enclosure != NULL) {
1138 $feed.=" <link rel=\"enclosure\" href=\"". $this->items[$i]->enclosure->url ."\" type=\"". $this->items[$i]->enclosure->type."\" length=\"". $this->items[$i]->enclosure->length . "\" />\n";
1140 $feed.= " </entry>\n";
1142 $feed.= "</feed>\n";
1143 return $feed;
1151 * AtomCreator03 is a FeedCreator that implements the atom specification,
1152 * as in http://www.intertwingly.net/wiki/pie/FrontPage.
1153 * Please note that just by using AtomCreator03 you won't automatically
1154 * produce valid atom files. For example, you have to specify either an editor
1155 * for the feed or an author for every single feed item.
1157 * Some elements have not been implemented yet. These are (incomplete list):
1158 * author URL, item author's email and URL, item contents, alternate links,
1159 * other link content types than text/html. Some of them may be created with
1160 * AtomCreator03::additionalElements.
1162 * @see FeedCreator#additionalElements
1163 * @since 1.6
1164 * @author Kai Blankenhorn <kaib@bitfolge.de>, Scott Reynen <scott@randomchaos.com>
1166 class AtomCreator03 extends FeedCreator {
1168 function AtomCreator03() {
1169 $this->contentType = "application/atom+xml";
1170 $this->encoding = "utf-8";
1173 function createFeed() {
1174 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
1175 $feed.= $this->_createGeneratorComment();
1176 $feed.= $this->_createStylesheetReferences();
1177 $feed.= "<feed version=\"0.3\" xmlns=\"http://purl.org/atom/ns#\"";
1178 if ($this->language!="") {
1179 $feed.= " xml:lang=\"".$this->language."\"";
1181 $feed.= ">\n";
1182 $feed.= " <title>".htmlspecialchars($this->title)."</title>\n";
1183 $feed.= " <tagline>".htmlspecialchars($this->description)."</tagline>\n";
1184 $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->link)."\"/>\n";
1185 $feed.= " <id>".htmlspecialchars($this->link)."</id>\n";
1186 $now = new FeedDate();
1187 $feed.= " <modified>".htmlspecialchars($now->iso8601())."</modified>\n";
1188 if ($this->editor!="") {
1189 $feed.= " <author>\n";
1190 $feed.= " <name>".$this->editor."</name>\n";
1191 if ($this->editorEmail!="") {
1192 $feed.= " <email>".$this->editorEmail."</email>\n";
1194 $feed.= " </author>\n";
1196 $feed.= " <generator>".FEEDCREATOR_VERSION."</generator>\n";
1197 $feed.= $this->_createAdditionalElements($this->additionalElements, " ");
1198 for ($i=0;$i<count($this->items);$i++) {
1199 $feed.= " <entry>\n";
1200 $feed.= " <title>".htmlspecialchars(strip_tags($this->items[$i]->title))."</title>\n";
1201 $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n";
1202 if ($this->items[$i]->date=="") {
1203 $this->items[$i]->date = time();
1205 $itemDate = new FeedDate($this->items[$i]->date);
1206 $feed.= " <created>".htmlspecialchars($itemDate->iso8601())."</created>\n";
1207 $feed.= " <issued>".htmlspecialchars($itemDate->iso8601())."</issued>\n";
1208 $feed.= " <modified>".htmlspecialchars($itemDate->iso8601())."</modified>\n";
1209 $feed.= " <id>".htmlspecialchars($this->items[$i]->link)."</id>\n";
1210 $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");
1211 if ($this->items[$i]->author!="") {
1212 $feed.= " <author>\n";
1213 $feed.= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n";
1214 $feed.= " </author>\n";
1216 if ($this->items[$i]->description!="") {
1217 $feed.= " <summary>".htmlspecialchars($this->items[$i]->description)."</summary>\n";
1219 $feed.= " </entry>\n";
1221 $feed.= "</feed>\n";
1222 return $feed;
1228 * MBOXCreator is a FeedCreator that implements the mbox format
1229 * as described in http://www.qmail.org/man/man5/mbox.html
1231 * @since 1.3
1232 * @author Kai Blankenhorn <kaib@bitfolge.de>
1234 class MBOXCreator extends FeedCreator {
1236 function MBOXCreator() {
1237 $this->contentType = "text/plain";
1238 $this->encoding = "utf-8";
1241 function qp_enc($input = "", $line_max = 76) {
1242 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
1243 $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
1244 $eol = "\r\n";
1245 $escape = "=";
1246 $output = "";
1247 while( list(, $line) = each($lines) ) {
1248 //$line = rtrim($line); // remove trailing white space -> no =20\r\n necessary
1249 $linlen = strlen($line);
1250 $newline = "";
1251 for($i = 0; $i < $linlen; $i++) {
1252 $c = substr($line, $i, 1);
1253 $dec = ord($c);
1254 if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only
1255 $c = "=20";
1256 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
1257 $h2 = floor($dec/16); $h1 = floor($dec%16);
1258 $c = $escape.$hex["$h2"].$hex["$h1"];
1260 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
1261 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
1262 $newline = "";
1264 $newline .= $c;
1265 } // end of for
1266 $output .= $newline.$eol;
1268 return trim($output);
1273 * Builds the MBOX contents.
1274 * @return string the feed's complete text
1276 function createFeed() {
1277 for ($i=0;$i<count($this->items);$i++) {
1278 if ($this->items[$i]->author!="") {
1279 $from = $this->items[$i]->author;
1280 } else {
1281 $from = $this->title;
1283 $itemDate = new FeedDate($this->items[$i]->date);
1284 $feed.= "From ".strtr(MBOXCreator::qp_enc($from)," ","_")." ".date("D M d H:i:s Y",$itemDate->unix())."\n";
1285 $feed.= "Content-Type: text/plain;\n";
1286 $feed.= " charset=\"".$this->encoding."\"\n";
1287 $feed.= "Content-Transfer-Encoding: quoted-printable\n";
1288 $feed.= "Content-Type: text/plain\n";
1289 $feed.= "From: \"".MBOXCreator::qp_enc($from)."\"\n";
1290 $feed.= "Date: ".$itemDate->rfc822()."\n";
1291 $feed.= "Subject: ".MBOXCreator::qp_enc(FeedCreator::iTrunc($this->items[$i]->title,100))."\n";
1292 $feed.= "\n";
1293 $body = chunk_split(MBOXCreator::qp_enc($this->items[$i]->description));
1294 $feed.= preg_replace("~\nFrom ([^\n]*)(\n?)~","\n>From $1$2\n",$body);
1295 $feed.= "\n";
1296 $feed.= "\n";
1298 return $feed;
1302 * Generate a filename for the feed cache file. Overridden from FeedCreator to prevent XML data types.
1303 * @return string the feed cache filename
1304 * @since 1.4
1305 * @access private
1307 function _generateFilename() {
1308 $fileInfo = pathinfo($_SERVER["PHP_SELF"]);
1309 return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".mbox";
1315 * OPMLCreator is a FeedCreator that implements OPML 1.0.
1317 * @see http://opml.scripting.com/spec
1318 * @author Dirk Clemens, Kai Blankenhorn
1319 * @since 1.5
1321 class OPMLCreator extends FeedCreator {
1323 function OPMLCreator() {
1324 $this->encoding = "utf-8";
1327 function createFeed() {
1328 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
1329 $feed.= $this->_createGeneratorComment();
1330 $feed.= $this->_createStylesheetReferences();
1331 $feed.= "<opml xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n";
1332 $feed.= " <head>\n";
1333 $feed.= " <title>".htmlspecialchars($this->title)."</title>\n";
1334 if ($this->pubDate!="") {
1335 $date = new FeedDate($this->pubDate);
1336 $feed.= " <dateCreated>".$date->rfc822()."</dateCreated>\n";
1338 if ($this->lastBuildDate!="") {
1339 $date = new FeedDate($this->lastBuildDate);
1340 $feed.= " <dateModified>".$date->rfc822()."</dateModified>\n";
1342 if ($this->editor!="") {
1343 $feed.= " <ownerName>".$this->editor."</ownerName>\n";
1345 if ($this->editorEmail!="") {
1346 $feed.= " <ownerEmail>".$this->editorEmail."</ownerEmail>\n";
1348 $feed.= " </head>\n";
1349 $feed.= " <body>\n";
1350 for ($i=0;$i<count($this->items);$i++) {
1351 $feed.= " <outline type=\"rss\" ";
1352 $title = htmlspecialchars(strip_tags(strtr($this->items[$i]->title,"\n\r"," ")));
1353 $feed.= " title=\"".$title."\"";
1354 $feed.= " text=\"".$title."\"";
1355 //$feed.= " description=\"".htmlspecialchars($this->items[$i]->description)."\"";
1356 $feed.= " url=\"".htmlspecialchars($this->items[$i]->link)."\"";
1357 $feed.= "/>\n";
1359 $feed.= " </body>\n";
1360 $feed.= "</opml>\n";
1361 return $feed;
1368 * HTMLCreator is a FeedCreator that writes an HTML feed file to a specific
1369 * location, overriding the createFeed method of the parent FeedCreator.
1370 * The HTML produced can be included over http by scripting languages, or serve
1371 * as the source for an IFrame.
1372 * All output by this class is embedded in <div></div> tags to enable formatting
1373 * using CSS.
1375 * @author Pascal Van Hecke
1376 * @since 1.7
1378 class HTMLCreator extends FeedCreator {
1380 var $contentType = "text/html";
1383 * Contains HTML to be output at the start of the feed's html representation.
1385 var $header;
1388 * Contains HTML to be output at the end of the feed's html representation.
1390 var $footer ;
1393 * Contains HTML to be output between entries. A separator is only used in
1394 * case of multiple entries.
1396 var $separator;
1399 * Used to prefix the stylenames to make sure they are unique
1400 * and do not clash with stylenames on the users' page.
1402 var $stylePrefix;
1405 * Determines whether the links open in a new window or not.
1407 var $openInNewWindow = true;
1409 var $imageAlign ="right";
1412 * In case of very simple output you may want to get rid of the style tags,
1413 * hence this variable. There's no equivalent on item level, but of course you can
1414 * add strings to it while iterating over the items ($this->stylelessOutput .= ...)
1415 * and when it is non-empty, ONLY the styleless output is printed, the rest is ignored
1416 * in the function createFeed().
1418 var $stylelessOutput ="";
1421 * Writes the HTML.
1422 * @return string the scripts's complete text
1424 function createFeed() {
1425 // if there is styleless output, use the content of this variable and ignore the rest
1426 if ($this->stylelessOutput!="") {
1427 return $this->stylelessOutput;
1430 //if no stylePrefix is set, generate it yourself depending on the script name
1431 if ($this->stylePrefix=="") {
1432 $this->stylePrefix = str_replace(".", "_", $this->_generateFilename())."_";
1435 //set an openInNewWindow_token_to be inserted or not
1436 if ($this->openInNewWindow) {
1437 $targetInsert = " target='_blank'";
1440 // use this array to put the lines in and implode later with "document.write" javascript
1441 $feedArray = array();
1442 if ($this->image!=null) {
1443 $imageStr = "<a href='".$this->image->link."'".$targetInsert.">".
1444 "<img src='".$this->image->url."' border='0' alt='".
1445 FeedCreator::iTrunc(htmlspecialchars($this->image->title),100).
1446 "' align='".$this->imageAlign."' ";
1447 if ($this->image->width) {
1448 $imageStr .=" width='".$this->image->width. "' ";
1450 if ($this->image->height) {
1451 $imageStr .=" height='".$this->image->height."' ";
1453 $imageStr .="/></a>";
1454 $feedArray[] = $imageStr;
1457 if ($this->title) {
1458 $feedArray[] = "<div class='".$this->stylePrefix."title'><a href='".$this->link."' ".$targetInsert." class='".$this->stylePrefix."title'>".
1459 FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</a></div>";
1461 if ($this->getDescription()) {
1462 $feedArray[] = "<div class='".$this->stylePrefix."description'>".
1463 str_replace("]]>", "", str_replace("<![CDATA[", "", $this->getDescription())).
1464 "</div>";
1467 if ($this->header) {
1468 $feedArray[] = "<div class='".$this->stylePrefix."header'>".$this->header."</div>";
1471 for ($i=0;$i<count($this->items);$i++) {
1472 if ($this->separator and $i > 0) {
1473 $feedArray[] = "<div class='".$this->stylePrefix."separator'>".$this->separator."</div>";
1476 if ($this->items[$i]->title) {
1477 if ($this->items[$i]->link) {
1478 $feedArray[] =
1479 "<div class='".$this->stylePrefix."item_title'><a href='".$this->items[$i]->link."' class='".$this->stylePrefix.
1480 "item_title'".$targetInsert.">".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100).
1481 "</a></div>";
1482 } else {
1483 $feedArray[] =
1484 "<div class='".$this->stylePrefix."item_title'>".
1485 FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100).
1486 "</div>";
1489 if ($this->items[$i]->getDescription()) {
1490 $feedArray[] =
1491 "<div class='".$this->stylePrefix."item_description'>".
1492 str_replace("]]>", "", str_replace("<![CDATA[", "", $this->items[$i]->getDescription())).
1493 "</div>";
1496 if ($this->footer) {
1497 $feedArray[] = "<div class='".$this->stylePrefix."footer'>".$this->footer."</div>";
1500 $feed= "".join($feedArray, "\r\n");
1501 return $feed;
1505 * Overrrides parent to produce .html extensions
1507 * @return string the feed cache filename
1508 * @since 1.4
1509 * @access private
1511 function _generateFilename() {
1512 $fileInfo = pathinfo($_SERVER["PHP_SELF"]);
1513 return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".html";
1519 * JSCreator is a class that writes a js file to a specific
1520 * location, overriding the createFeed method of the parent HTMLCreator.
1522 * @author Pascal Van Hecke
1524 class JSCreator extends HTMLCreator {
1525 var $contentType = "text/javascript";
1528 * writes the javascript
1529 * @return string the scripts's complete text
1531 function createFeed()
1533 $feed = parent::createFeed();
1534 $feedArray = explode("\n",$feed);
1536 $jsFeed = "";
1537 foreach ($feedArray as $value) {
1538 $jsFeed .= "document.write('".trim(addslashes($value))."');\n";
1540 return $jsFeed;
1544 * Overrrides parent to produce .js extensions
1546 * @return string the feed cache filename
1547 * @since 1.4
1548 * @access private
1550 function _generateFilename() {
1551 $fileInfo = pathinfo($_SERVER["PHP_SELF"]);
1552 return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".js";
1558 * This class allows to override the hardcoded charset
1560 * @author Andreas Gohr <andi@splitbrain.org>
1562 class DokuWikiFeedCreator extends UniversalFeedCreator{
1563 function createFeed($format = "RSS0.91",$encoding='iso-8859-15') {
1564 $this->_setFormat($format);
1565 $this->_feed->encoding = $encoding;
1566 return $this->_feed->createFeed();
1572 //Setup VIM: ex: et ts=4 enc=utf-8 :