]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/RSSWriter091.php
only cosmetics
[SourceForge/phpwiki.git] / lib / RSSWriter091.php
1 <?php
2 // ----------------------------------------------------------------------
3 // phpWiki
4 // ----------------------------------------------------------------------
5 // LICENSE
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License (GPL)
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16 //
17 // To read the license please visit http://www.gnu.org/copyleft/gpl.html
18 // ----------------------------------------------------------------------
19 // Original Author of file: Lawrence Akka
20 // Purpose of file: Plugin and associated classes
21 // for outputting RecentChanges in RSS 0.91 format
22 // ----------------------------------------------------------------------
23
24 rcs_id('$Id: RSSWriter091.php,v 1.10 2005-08-06 13:06:22 rurban Exp $');
25
26 include_once("lib/RssWriter.php");
27 class RSSWriter091 extends RSSWriter
28 {
29     function RSSWriter091()
30     {
31         $this->XmlElement('rss', array('version' => "0.91"));
32         $this->_items = array();
33     }
34   /**
35    * Finish construction of RSS.
36    */   
37     function finish() 
38     {
39         if (isset($this->_finished))
40             return;
41         
42         $channel = &$this->_channel;
43         $items = &$this->_items;
44         
45         if ($items)
46             {
47                 foreach ($items as $i)
48                     $channel->pushContent($i);
49             }
50         $this->pushContent($channel);
51         $this->__spew();
52         $this->_finished = true;
53     }
54
55     /**
56      * Create a new RDF <em>typedNode</em>.
57      */
58     function __node($type, $properties, $uri = false) {
59         return new XmlElement($type, '',
60                               $this->__elementize($properties));
61     }
62
63     /**
64      * Write output to HTTP client.
65      */
66     function __spew() {
67         header("Content-Type: application/xml; charset=" . RSS_ENCODING);
68         printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", RSS_ENCODING);
69                 print("<!DOCTYPE rss PUBLIC \"-//Netscape Communications//DTD RSS 0.91//EN\"\n");
70                 print("\"http://my.netscape.com/publish/formats/rss-0.91.dtd\">\n\n");
71         $this->printXML();
72     }
73         
74         
75 }
76
77 class _RecentChanges_RssFormatter091
78 extends _RecentChanges_RSSFormatter
79 // This class should probably go at then of RecentChanges.php
80 {
81     function format ($changes) 
82     {
83         //    include_once('lib/RssWriter.php');
84         $rss = new RssWriter091;
85
86         $rss->channel($this->channel_properties());
87
88         if (($props = $this->image_properties()))
89             $rss->image($props);
90         if (($props = $this->textinput_properties()))
91             $rss->textinput($props);
92
93         while ($rev = $changes->next()) {
94             $rss->addItem($this->item_properties($rev),
95                           $this->pageURI($rev));
96         }
97
98         global $request;
99         $request->discardOutput();
100         $rss->finish();
101         printf("\n<!-- Generated by PhpWiki:\n%s-->\n", $GLOBALS['RCS_IDS']);
102         $request->finish();             // NORETURN!!!!
103     }
104
105
106     function channel_properties () 
107     {
108         global $request;
109
110         $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
111
112         return array('title' => WIKI_NAME,
113                      'description' => _("RecentChanges"),
114                      'link' => $rc_url,
115                      'language' => 'en-US');
116
117         /* FIXME: language should come from $LANG (or other config variable). */
118         
119         /* FIXME: other things one might like in <channel>:                   
120          * managingEditor
121          * webmaster
122          * lastBuildDate
123          * copyright
124          */
125     }
126     
127         
128     function item_properties ($rev)
129     {
130         $page = $rev->getPage();
131         $pagename = $page->getName();
132         
133         return array( 'title'           => SplitPagename($pagename),
134                       'description'     => $this->summary($rev),
135                       'link'            => $this->pageURL($rev)                  
136                       );
137     }
138 }
139
140 // (c-file-style: "gnu")
141 // Local Variables:
142 // mode: php
143 // tab-width: 8
144 // c-basic-offset: 4
145 // c-hanging-comment-ender-p: nil
146 // indent-tabs-mode: nil
147 // End:   
148 ?>