]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/rssaction.php
lcase tname
[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 # This will contain the details of each feed item's author and be used to generate SIOC data.
25 $creators = array();
26
27 class Rss10Action extends Action {
28
29         function handle($args) {
30                 parent::handle($args);
31                 $limit = (int) $this->trimmed('limit');
32                 if ($limit == 0) {
33                         $limit = DEFAULT_RSS_LIMIT;
34                 }
35                 $this->show_rss($limit);
36         }
37
38         function init() {
39                 return true;
40         }
41
42         function get_notices() {
43                 return array();
44         }
45
46         function get_channel() {
47                 return array('url' => '',
48                                          'title' => '',
49                                          'link' => '',
50                                          'description' => '');
51         }
52
53         function get_image() {
54                 return NULL;
55         }
56
57         function show_rss($limit=0) {
58
59                 if (!$this->init()) {
60                         return;
61                 }
62
63                 $notices = $this->get_notices($limit);
64
65                 $this->init_rss();
66                 $this->show_channel($notices);
67                 $this->show_image();
68
69                 foreach ($notices as $n) {
70                         $this->show_item($n);
71                 }
72
73                 $this->show_creators();
74                 $this->end_rss();
75         }
76
77         function show_channel($notices) {
78                 global $config;
79
80                 $channel = $this->get_channel();
81                 $image = $this->get_image();
82
83                 common_element_start('channel', array('rdf:about' => $channel['url']));
84                 common_element('title', NULL, $channel['title']);
85                 common_element('link', NULL, $channel['link']);
86                 common_element('description', NULL, $channel['description']);
87                 common_element('cc:licence', array('rdf:resource' => $config['license']['url']));
88
89                 if ($image) {
90                         common_element('image', array('rdf:resource' => $image));
91                 }
92
93                 common_element_start('items');
94                 common_element_start('rdf:Seq');
95
96                 foreach ($notices as $notice) {
97                         common_element('sioct:MicroblogPost', array('rdf:resource' => $notice->uri));
98                 }
99
100                 common_element_end('rdf:Seq');
101                 common_element_end('items');
102
103                 common_element_end('channel');
104         }
105
106         function show_image() {
107                 $image = $this->get_image();
108                 if ($image) {
109                         $channel = $this->get_channel();
110                         common_element_start('image', array('rdf:about' => $image));
111                         common_element('title', NULL, $channel['title']);
112                         common_element('link', NULL, $channel['link']);
113                         common_element('url', NULL, $image);
114                         common_element_end('image');
115                 }
116         }
117
118         function show_item($notice) {
119                 global $config, $creators;
120                 $profile = Profile::staticGet($notice->profile_id);
121                 $nurl = common_local_url('shownotice', array('notice' => $notice->id));
122                 common_element_start('item', array('rdf:about' => $notice->uri));
123                 $title = $profile->nickname . ': ' . $notice->content;
124                 common_element('title', NULL, $title);
125                 common_element('link', NULL, $nurl);
126                 common_element('description', NULL, $profile->nickname."'s status on ".common_exact_date($notice->created));
127                 common_element('dc:date', NULL, common_date_w3dtf($notice->created));
128                 common_element('dc:creator', NULL, ($profile->fullname) ? $profile->fullname : $profile->nickname);
129                 common_element('sioc:has_creator', array('rdf:resource' =>
130                                                          common_local_url('userbyid', array('id' => $profile->id))
131                                                                ));
132                 common_element('cc:licence', array('rdf:resource' => $config['license']['url']));
133                 common_element_end('item');
134                 $creators[$nurl] = $profile;
135         }
136
137         function show_creators() {
138                 global $creators;
139                 
140                 foreach ($creators as $nurl => $profile) {
141                         $id = $profile->id;
142                         $nickname = $profile->nickname;
143                         
144                         common_element_start('sioc:User', array('rdf:about' =>
145                                                                 common_local_url('userbyid', array('id' => $id))
146                                               ));
147                         common_element('foaf:nick', NULL, $nickname);                                                
148                         if ($profile->fullname) {
149                                 common_element('foaf:name', NULL, $profile->fullname);
150                         }
151                         common_element('sioc:id', NULL, $id);
152                         common_element('sioc:avatar', array('rdf:resource' =>
153                                                             common_local_url('avatarbynickname', 
154                                                                              array('nickname' => $nickname,
155                                                                                                                                            'size' => 48
156                                                                                                                              ))
157                                                                                   ));
158                         common_element_end('sioc:User');
159                 }
160         }
161         
162         function init_rss() {
163                 global $config;
164                 $channel = $this->get_channel();
165                 
166                 header('Content-Type: application/rdf+xml');
167
168                 common_start_xml();
169                 common_element_start('rdf:RDF', array('xmlns:rdf' =>
170                                                                                           'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
171                                                                                           'xmlns:dc' =>
172                                                                                           'http://purl.org/dc/elements/1.1/',
173                                                                                           'xmlns:cc' =>
174                                                                                           'http://web.resource.org/cc/',
175                                                                                           'xmlns:foaf' =>
176                                                                                           'http://xmlns.com/foaf/0.1/',
177                                                                                           'xmlns:sioc' =>
178                                                                                           'http://rdfs.org/sioc/ns#',
179                                                       'xmlns:sioct' =>
180                                                       'http://rdfs.org/sioc/types#',
181                                                                                           'xmlns' => 'http://purl.org/rss/1.0/'));
182                 
183                 common_element_start('sioc:Site', array('rdf:about' =>
184                                                         'http://identi.ca/'));
185                 common_element('sioc:name', NULL, $config['site']['name']);
186                 common_element_start('sioc:container_of');
187                 common_element('sioc:Container', array('rdf:about' =>
188                                                        $channel['url']));
189                 common_element_end('sioc:container_of');
190                 common_element_end('sioc:Site');
191         }
192
193         function end_rss() {
194                 common_element_end('rdf:RDF');
195         }
196 }