]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/rssaction.php
twiddle some parens in imsettings for gettext
[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 define('DEFAULT_RSS_LIMIT', 48);
23
24 class Rss10Action extends Action {
25
26         function handle($args) {
27                 parent::handle($args);
28                 $limit = (int) $this->trimmed('limit');
29                 if ($limit == 0) {
30                         $limit = DEFAULT_RSS_LIMIT;
31                 }
32                 $this->show_rss($limit);
33         }
34
35         function init() {
36                 return true;
37         }
38
39         function get_notices() {
40                 return array();
41         }
42
43         function get_channel() {
44                 return array('url' => '',
45                                          'title' => '',
46                                          'link' => '',
47                                          'description' => '');
48         }
49
50         function get_image() {
51                 return NULL;
52         }
53
54         function show_rss($limit=0) {
55
56                 if (!$this->init()) {
57                         return;
58                 }
59
60                 $notices = $this->get_notices($limit);
61
62                 $this->init_rss();
63                 $this->show_channel($notices);
64                 $this->show_image();
65
66                 foreach ($notices as $n) {
67                         $this->show_item($n);
68                 }
69
70                 $this->end_rss();
71         }
72
73         function show_channel($notices) {
74                 global $config;
75
76                 $channel = $this->get_channel();
77                 $image = $this->get_image();
78
79                 common_element_start('channel', array('rdf:about' => $channel['url']));
80                 common_element('title', NULL, $channel['title']);
81                 common_element('link', NULL, $channel['link']);
82                 common_element('description', NULL, $channel['description']);
83                 common_element('cc:licence', array('rdf:resource' => $config['license']['url']));
84
85                 if ($image) {
86                         common_element('image', array('rdf:resource' => $image));
87                 }
88
89                 common_element_start('items');
90                 common_element_start('rdf:Seq');
91
92                 foreach ($notices as $notice) {
93                         common_element('rdf:li', array('rdf:resource' => $notice->uri));
94                 }
95
96                 common_element_end('rdf:Seq');
97                 common_element_end('items');
98
99                 common_element_end('channel');
100         }
101
102         function show_image() {
103                 $image = $this->get_image();
104                 if ($image) {
105                         $channel = $this->get_channel();
106                         common_element_start('image', array('rdf:about' => $image));
107                         common_element('title', NULL, $channel['title']);
108                         common_element('link', NULL, $channel['link']);
109                         common_element('url', NULL, $image);
110                         common_element_end('image');
111                 }
112         }
113
114         function show_item($notice) {
115                 global $config;
116                 $profile = Profile::staticGet($notice->profile_id);
117                 $nurl = common_local_url('shownotice', array('notice' => $notice->id));
118                 common_element_start('item', array('rdf:about' => $notice->uri));
119                 common_element('title', NULL, $notice->content);
120                 common_element('link', NULL, $nurl);
121                 common_element('description', NULL, $profile->nickname."'s status on ".common_exact_date($notice->created));
122                 common_element('dc:date', NULL, common_date_w3dtf($notice->created));
123                 common_element('dc:creator', NULL, ($profile->fullname) ? $profile->fullname : $profile->nickname);
124                 common_element('cc:licence', array('rdf:resource' => $config['license']['url']));
125                 common_element_end('item');
126         }
127
128         function init_rss() {
129                 header('Content-Type: application/rdf+xml');
130
131                 common_start_xml();
132                 common_element_start('rdf:RDF', array('xmlns:rdf' =>
133                                                                                           'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
134                                                                                           'xmlns:dc' =>
135                                                                                           'http://purl.org/dc/elements/1.1/',
136                                                                                           'xmlns:cc' =>
137                                                                                           'http://web.resource.org/cc/',
138                                                                                           'xmlns' => 'http://purl.org/rss/1.0/'));
139         }
140
141         function end_rss() {
142                 common_element_end('rdf:RDF');
143         }
144 }