3 * Laconica, the distributed open-source microblogging tool
5 * Base class for RSS 1.0 feed actions
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@controlyourself.ca>
25 * @author Earle Martin <earle@downlode.org>
26 * @copyright 2008-9 Control Yourself, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://laconi.ca/
31 if (!defined('LACONICA')) { exit(1); }
33 define('DEFAULT_RSS_LIMIT', 48);
35 class Rss10Action extends Action
37 # This will contain the details of each feed item's author and be used to generate SIOC data.
39 var $creators = array();
40 var $limit = DEFAULT_RSS_LIMIT;
45 * Just wraps the Action constructor.
47 * @param string $output URI to output to, default = stdout
48 * @param boolean $indent Whether to indent output, default true
50 * @see Action::__construct
53 function __construct($output='php://output', $indent=true)
55 parent::__construct($output, $indent);
59 * Do we need to write to the database?
61 * @return boolean true
70 * Read arguments and initialize members
72 * @param array $args Arguments from $_REQUEST
73 * @return boolean success
76 function prepare($args)
78 $this->limit = (int) $this->trimmed('limit');
79 if ($this->limit == 0) {
80 $this->limit = DEFAULT_RSS_LIMIT;
88 * @param array $args Arguments from $_REQUEST
93 function handle($args)
95 parent::handle($args);
96 $this->show_rss($limit);
100 * Get the notices to output in this stream
102 * @return array an array of Notice objects sorted in reverse chron
105 function getNotices()
111 * Get a description of the channel
113 * Returns an array with the following
115 function get_channel()
117 return array('url' => '',
120 'description' => '');
128 function show_rss($limit=0)
130 $notices = $this->get_notices($limit);
133 $this->show_channel($notices);
136 foreach ($notices as $n) {
137 $this->show_item($n);
140 $this->show_creators();
144 function show_channel($notices)
147 $channel = $this->get_channel();
148 $image = $this->get_image();
150 common_element_start('channel', array('rdf:about' => $channel['url']));
151 common_element('title', null, $channel['title']);
152 common_element('link', null, $channel['link']);
153 common_element('description', null, $channel['description']);
154 common_element('cc:licence', array('rdf:resource' => common_config('license','url')));
157 common_element('image', array('rdf:resource' => $image));
160 common_element_start('items');
161 common_element_start('rdf:Seq');
163 foreach ($notices as $notice) {
164 common_element('sioct:MicroblogPost', array('rdf:resource' => $notice->uri));
167 common_element_end('rdf:Seq');
168 common_element_end('items');
170 common_element_end('channel');
173 function show_image()
175 $image = $this->get_image();
177 $channel = $this->get_channel();
178 common_element_start('image', array('rdf:about' => $image));
179 common_element('title', null, $channel['title']);
180 common_element('link', null, $channel['link']);
181 common_element('url', null, $image);
182 common_element_end('image');
186 function show_item($notice)
188 $profile = Profile::staticGet($notice->profile_id);
189 $nurl = common_local_url('shownotice', array('notice' => $notice->id));
190 $creator_uri = common_profile_uri($profile);
191 common_element_start('item', array('rdf:about' => $notice->uri));
192 $title = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
193 common_element('title', null, $title);
194 common_element('link', null, $nurl);
195 common_element('description', null, $profile->nickname."'s status on ".common_exact_date($notice->created));
196 common_element('dc:date', null, common_date_w3dtf($notice->created));
197 common_element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname);
198 common_element('sioc:has_creator', array('rdf:resource' => $creator_uri));
199 common_element('laconica:postIcon', array('rdf:resource' => common_profile_avatar_url($profile)));
200 common_element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
201 common_element_end('item');
202 $this->creators[$creator_uri] = $profile;
205 function show_creators()
207 foreach ($this->creators as $uri => $profile) {
209 $nickname = $profile->nickname;
210 common_element_start('sioc:User', array('rdf:about' => $uri));
211 common_element('foaf:nick', null, $nickname);
212 if ($profile->fullname) {
213 common_element('foaf:name', null, $profile->fullname);
215 common_element('sioc:id', null, $id);
216 $avatar = common_profile_avatar_url($profile);
217 common_element('sioc:avatar', array('rdf:resource' => $avatar));
218 common_element_end('sioc:User');
224 $channel = $this->get_channel();
225 header('Content-Type: application/rdf+xml');
228 common_element_start('rdf:RDF', array('xmlns:rdf' =>
229 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
231 'http://purl.org/dc/elements/1.1/',
233 'http://web.resource.org/cc/',
235 'http://purl.org/rss/1.0/modules/content/',
237 'http://xmlns.com/foaf/0.1/',
239 'http://rdfs.org/sioc/ns#',
241 'http://rdfs.org/sioc/types#',
243 'http://laconi.ca/ont/',
244 'xmlns' => 'http://purl.org/rss/1.0/'));
245 common_element_start('sioc:Site', array('rdf:about' => common_root_url()));
246 common_element('sioc:name', null, common_config('site', 'name'));
247 common_element_start('sioc:container_of');
248 common_element('sioc:Container', array('rdf:about' =>
250 common_element_end('sioc:container_of');
251 common_element_end('sioc:Site');
256 common_element_end('rdf:RDF');