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