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#',
53 'xmlns' => 'http://purl.org/rss/1.0/'));
55 $notices = $this->get_notices($user, $limit);
56 $this->show_channel($user, $notices);
58 foreach ($notices as $n) {
62 common_element_end('rdf:RDF');
65 function get_notices($user, $limit=0) {
68 $notice = DB_DataObject::factory('notice');
69 $notice->profile_id = $user->id; # user id === profile id
70 $notice->orderBy('created DESC');
72 $notice->limit(0, $limit);
76 while ($notice->fetch()) {
77 $notices[] = clone($notice);
83 function show_channel($user, $notices) {
85 # XXX: this is kind of indirect, eh?
86 $profile = $user->getProfile();
87 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
89 common_element_start('channel', array('rdf:about' =>
90 common_local_url('rss10',
93 common_element('title', NULL, $user->nickname);
94 common_element('link', NULL, $profile->profileurl);
95 common_element('description', NULL, _t('Microblog by ') . $user->nickname);
98 common_element('image', array('rdf:resource' => $avatar->url));
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))));
109 common_element_end('rdf:Seq');
110 common_element_end('items');
111 common_element_end('channel');
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');
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');