]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/rss10.php
rss feed plus
[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' => 'http://purl.org/rss/1.0/'));
54
55                 $notices = $this->get_notices($user, $limit);
56                 $this->show_channel($user, $notices);
57                 
58                 foreach ($notices as $n) {
59                         $this->show_item($n);
60                 }
61                 
62                 common_element_end('rdf:RDF');
63         }
64         
65         function get_notices($user, $limit=0) {
66                 $notices = array();
67                 
68                 $notice = DB_DataObject::factory('notice');
69                 $notice->profile_id = $user->id; # user id === profile id
70                 $notice->orderBy('created DESC');
71                 if ($limit != 0) {
72                         $notice->limit(0, $limit);
73                 }
74                 $notice->find();
75                 
76                 while ($notice->fetch()) {
77                         $notices[] = clone($notice);
78                 }
79                 
80                 return $notices;
81         }
82         
83         function show_channel($user, $notices) {
84                 
85                 # XXX: this is kind of indirect, eh?
86                 $profile = $user->getProfile();
87                 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
88                 
89                 common_element_start('channel', array('rdf:about' =>
90                                                                                           common_local_url('rss10',
91                                                                                                                            array('nickname' => 
92                                                                                                                                          $user->nickname))));
93                 common_element('title', NULL, $user->nickname);
94                 common_element('link', NULL, $profile->profileurl);
95                 common_element('description', NULL, _t('Microblog by ') . $user->nickname);
96
97                 if ($avatar) {
98                         common_element('image', array('rdf:resource' => $avatar->url));
99                 }
100
101                 common_element_start('items');
102                 common_element_start('rdf:Seq');
103                 foreach ($notices as $n) {
104                         common_element('rdf:li', array('rdf:resource' =>
105                                                                                    common_local_url('shownotice',
106                                                                                                                         array('notice' => $n->id))));
107                 }
108                 
109                 common_element_end('rdf:Seq');
110                 common_element_end('items');
111                 common_element_end('channel');
112                 
113                 if ($avatar) {
114                         common_element_start('image', array('rdf:about' => $avatar->url));
115                         common_element('title', NULL, $user->nickname);
116                         common_element('link', NULL, $profile->profileurl);
117                         common_element('url', NULL, $avatar->url);
118                         common_element_end('image');
119                 }
120         }
121         
122         function show_item($notice) {
123                 $nurl = common_local_url('shownotice', array('notice' => $n->id));
124                 common_element_start('item', array('rdf:about' => $nurl));
125                 common_element('title', NULL, $notice->created);
126                 common_element('link', NULL, $nurl);
127                 common_element('description', NULL, common_render_content($notice->content));
128                 common_element_end('item');
129         }
130 }