]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/rssaction.php
use a static rather than a constant for code chars
[quix0rs-gnu-social.git] / lib / rssaction.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 class Rss10Action extends Action {
23
24         function handle($args) {
25                 parent::handle($args);
26                 $limit = (int) $this->trimmed('limit');
27                 $this->show_rss($limit);
28         }
29
30         function init() {
31                 return true;
32         }
33         
34         function get_notices() {
35                 return array();
36         }
37
38         function get_channel() {
39                 return array('url' => '',
40                                          'title' => '',
41                                          'link' => '',
42                                          'description' => '');
43         }
44         
45         function get_image() {
46                 return NULL;
47         }
48         
49         function show_rss($limit=0) {
50                 
51                 if (!$this->init()) {
52                         return;
53                 }
54                 
55                 $notices = $this->get_notices($limit);
56                 
57                 $this->init_rss();
58                 $this->show_channel($notices);
59                 $this->show_image();
60                 
61                 foreach ($notices as $n) {
62                         $this->show_item($n);
63                 }
64                 
65                 $this->end_rss();
66         }
67
68         function show_channel($notices) {
69                 global $config;
70
71                 $channel = $this->get_channel();
72                 $image = $this->get_image();
73                 
74                 common_element_start('channel', array('rdf:about' => $channel['url']));
75                 common_element('title', NULL, $channel['title']);
76                 common_element('link', NULL, $channel['link']);
77                 common_element('description', NULL, $channel['description']);
78                 common_element('cc:licence', array('rdf:resource' => $config['license']['url']));
79
80                 if ($image) {
81                         common_element('image', array('rdf:resource' => $image));
82                 }
83
84                 common_element_start('items');
85                 common_element_start('rdf:Seq');
86                 
87                 foreach ($notices as $notice) {
88                         common_element('rdf:li', array('rdf:resource' => $notice->uri));
89                 }
90                 
91                 common_element_end('rdf:Seq');
92                 common_element_end('items');
93                 
94                 common_element_end('channel');
95         }
96
97         function show_image() {
98                 $image = $this->get_image();
99                 if ($image) {
100                         $channel = $this->get_channel();
101                         common_element_start('image', array('rdf:about' => $image));
102                         common_element('title', NULL, $channel['title']);
103                         common_element('link', NULL, $channel['link']);
104                         common_element('url', NULL, $image);
105                         common_element_end('image');
106                 }
107         }
108         
109         function show_item($notice) {
110                 global $config;
111                 $profile = Profile::staticGet($notice->profile_id);
112                 $nurl = common_local_url('shownotice', array('notice' => $notice->id));
113                 common_element_start('item', array('rdf:about' => $notice->uri));
114                 common_element('title', NULL, $profile->nickname."'s status on ".common_date_string($notice->created));
115                 common_element('link', NULL, $nurl);
116                 common_element('description', NULL, $notice->content);
117                 common_element('dc:date', NULL, common_date_w3dtf($notice->created));
118                 common_element('dc:creator', NULL, ($profile->fullname) ? $profile->fullname : $profile->nickname);
119                 common_element('cc:licence', array('rdf:resource' => $config['license']['url']));
120                 common_element_end('item');
121         }
122         
123         function init_rss() {
124                 header('Content-Type: application/rdf+xml');
125
126                 common_start_xml();
127                 common_element_start('rdf:RDF', array('xmlns:rdf' =>
128                                                                                           'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
129                                                                                           'xmlns:dc' =>
130                                                                                           'http://purl.org/dc/elements/1.1/',
131                                                                                           'xmlns:cc' =>
132                                                                                           'http://web.resource.org/cc/',
133                                                                                           'xmlns' => 'http://purl.org/rss/1.0/'));
134         }
135         
136         function end_rss() {            
137                 common_element_end('rdf:RDF');
138         }
139 }