3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
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.
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.
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/>.
20 if (!defined('LACONICA')) { exit(1); }
22 class Rss10Action extends Action {
24 function handle($args) {
25 parent::handle($args);
27 $nickname = $this->trimmed('nickname');
30 common_user_error(_t('No nickname provided.'));
33 $user = User::staticGet('nickname', $nickname);
36 common_user_error(_t('No such nickname.'));
39 $limit = (int) $this->trimmed('limit');
41 $this->show_rss($user, $limit);
44 function show_rss($user, $limit=0) {
48 header('Content-Type: application/rdf+xml');
51 common_element_start('rdf:RDF', array('xmlns:rdf' =>
52 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
54 'http://purl.org/dc/elements/1.1/',
55 'xmlns' => 'http://purl.org/rss/1.0/'));
57 $notices = $this->get_notices($user, $limit);
58 $this->show_channel($user, $notices);
60 foreach ($notices as $n) {
64 common_element_end('rdf:RDF');
67 function get_notices($user, $limit=0) {
70 $notice = DB_DataObject::factory('notice');
71 $notice->profile_id = $user->id; # user id === profile id
72 $notice->orderBy('created DESC');
74 $notice->limit(0, $limit);
78 while ($notice->fetch()) {
79 $notices[] = clone($notice);
85 function show_channel($user, $notices) {
87 # XXX: this is kind of indirect, eh?
88 $profile = $user->getProfile();
89 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
91 common_element_start('channel', array('rdf:about' =>
92 common_local_url('rss10',
95 common_element('title', NULL, $user->nickname);
96 common_element('link', NULL, $profile->profileurl);
97 common_element('description', NULL, _t('Microblog by ') . $user->nickname);
100 common_element('image', array('rdf:resource' => $avatar->url));
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))));
111 common_element_end('rdf:Seq');
112 common_element_end('items');
113 common_element_end('channel');
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');
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');