]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/RSSWriter091.php
Whitespace only
[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 include_once 'lib/RssWriter.php';
25 class RSSWriter091 extends RSSWriter
26 {
27     function RSSWriter091()
28     {
29         $this->XmlElement('rss', array('version' => "0.91"));
30         $this->_items = array();
31     }
32   /**
33    * Finish construction of RSS.
34    */
35     function finish()
36     {
37         if (isset($this->_finished))
38             return;
39
40         $channel = &$this->_channel;
41         $items = &$this->_items;
42
43         if ($items)
44             {
45         foreach ($items as $i)
46                     $channel->pushContent($i);
47             }
48         $this->pushContent($channel);
49         $this->__spew();
50         $this->_finished = true;
51     }
52
53     /**
54      * Create a new RDF <em>typedNode</em>.
55      */
56     function __node($type, $properties, $uri = false) {
57     return new XmlElement($type, '',
58                               $this->__elementize($properties));
59     }
60
61     /**
62      * Write output to HTTP client.
63      */
64     function __spew() {
65         header("Content-Type: application/xml; charset=" . RSS_ENCODING);
66         printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", RSS_ENCODING);
67         print("<!DOCTYPE rss PUBLIC \"-//Netscape Communications//DTD RSS 0.91//EN\"\n");
68         print("\"http://my.netscape.com/publish/formats/rss-0.91.dtd\">\n\n");
69         $this->printXML();
70     }
71
72 }
73
74 class _RecentChanges_RssFormatter091
75 extends _RecentChanges_RSSFormatter
76 // This class should probably go at then of RecentChanges.php
77 {
78     function format ($changes)
79     {
80         //    include_once('lib/RssWriter.php');
81         $rss = new RssWriter091;
82
83         $rss->channel($this->channel_properties());
84
85         if (($props = $this->image_properties()))
86             $rss->image($props);
87         if (($props = $this->textinput_properties()))
88             $rss->textinput($props);
89
90         while ($rev = $changes->next()) {
91             $rss->addItem($this->item_properties($rev),
92                           $this->pageURI($rev));
93         }
94
95         global $request;
96         $request->discardOutput();
97         $rss->finish();
98         $request->finish();             // NORETURN!!!!
99     }
100
101     function channel_properties ()
102     {
103         global $request;
104
105         $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
106
107         return array('title' => WIKI_NAME,
108                      'description' => _("RecentChanges"),
109                      'link' => $rc_url,
110                      'language' => 'en-US');
111
112         /* FIXME: language should come from $LANG (or other config variable). */
113
114         /* FIXME: other things one might like in <channel>:
115          * managingEditor
116          * webmaster
117          * lastBuildDate
118          * copyright
119          */
120     }
121
122     function item_properties ($rev)
123     {
124         $page = $rev->getPage();
125         $pagename = $page->getName();
126
127         return array( 'title'        => SplitPagename($pagename),
128                       'description'    => $this->summary($rev),
129                       'link'        => $this->pageURL($rev)
130                       );
131     }
132 }
133
134 // Local Variables:
135 // mode: php
136 // tab-width: 8
137 // c-basic-offset: 4
138 // c-hanging-comment-ender-p: nil
139 // indent-tabs-mode: nil
140 // End: