]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/rss10.php
add w3dtf date to rss 1.0 items
[quix0rs-gnu-social.git] / actions / rss10.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                 
27                 $nickname = $this->trimmed('nickname');
28                 
29                 if (!$nickname) {
30                         common_user_error(_t('No nickname provided.'));
31                 }
32                 
33                 $user = User::staticGet('nickname', $nickname);
34                 
35                 if (!$user) {
36                         common_user_error(_t('No such nickname.'));
37                 }
38                 
39                 $limit = (int) $this->trimmed('limit');
40                 
41                 $this->show_rss($user, $limit);
42         }
43         
44         function show_rss($user, $limit=0) {
45                 
46                 global $config;
47                 
48                 header('Content-Type: application/rdf+xml');
49
50                 common_start_xml();
51                 common_element_start('rdf:RDF', array('xmlns:rdf' =>
52                                                                                           'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
53                                                                                           'xmlns:dc' =>
54                                                                                           'http://purl.org/dc/elements/1.1/',
55                                                                                           'xmlns' => 'http://purl.org/rss/1.0/'));
56
57                 $notices = $this->get_notices($user, $limit);
58                 $this->show_channel($user, $notices);
59                 
60                 foreach ($notices as $n) {
61                         $this->show_item($n);
62                 }
63                 
64                 common_element_end('rdf:RDF');
65         }
66         
67         function get_notices($user, $limit=0) {
68                 $notices = array();
69                 
70                 $notice = DB_DataObject::factory('notice');
71                 $notice->profile_id = $user->id; # user id === profile id
72                 $notice->orderBy('created DESC');
73                 if ($limit != 0) {
74                         $notice->limit(0, $limit);
75                 }
76                 $notice->find();
77                 
78                 while ($notice->fetch()) {
79                         $notices[] = clone($notice);
80                 }
81                 
82                 return $notices;
83         }
84         
85         function show_channel($user, $notices) {
86                 
87                 # XXX: this is kind of indirect, eh?
88                 $profile = $user->getProfile();
89                 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
90                 
91                 common_element_start('channel', array('rdf:about' =>
92                                                                                           common_local_url('rss10',
93                                                                                                                            array('nickname' => 
94                                                                                                                                          $user->nickname))));
95                 common_element('title', NULL, $user->nickname);
96                 common_element('link', NULL, $profile->profileurl);
97                 common_element('description', NULL, _t('Microblog by ') . $user->nickname);
98
99                 if ($avatar) {
100                         common_element('image', array('rdf:resource' => $avatar->url));
101                 }
102
103                 common_element_start('items');
104                 common_element_start('rdf:Seq');
105                 foreach ($notices as $n) {
106                         common_element('rdf:li', array('rdf:resource' =>
107                                                                                    common_local_url('shownotice',
108                                                                                                                         array('notice' => $n->id))));
109                 }
110                 
111                 common_element_end('rdf:Seq');
112                 common_element_end('items');
113                 common_element_end('channel');
114                 
115                 if ($avatar) {
116                         common_element_start('image', array('rdf:about' => $avatar->url));
117                         common_element('title', NULL, $user->nickname);
118                         common_element('link', NULL, $profile->profileurl);
119                         common_element('url', NULL, $avatar->url);
120                         common_element_end('image');
121                 }
122         }
123         
124         function show_item($notice) {
125                 $nurl = common_local_url('shownotice', array('notice' => $notice->id));
126                 common_element_start('item', array('rdf:about' => $nurl));
127                 common_element('title', NULL, $notice->created);
128                 common_element('link', NULL, $nurl);
129                 common_element('description', NULL, common_render_content($notice->content));
130                 common_element('dc:date', NULL, common_date_w3dtf($notice->created));
131                 common_element_end('item');
132         }
133 }