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 parent::prepare($args);
79 $this->limit = (int) $this->trimmed('limit');
80 if ($this->limit == 0) {
81 $this->limit = DEFAULT_RSS_LIMIT;
89 * @param array $args Arguments from $_REQUEST
94 function handle($args)
96 parent::handle($args);
97 $this->showRss($this->limit);
101 * Get the notices to output in this stream
103 * @return array an array of Notice objects sorted in reverse chron
106 function getNotices()
112 * Get a description of the channel
114 * Returns an array with the following
118 function getChannel()
120 return array('url' => '',
123 'description' => '');
131 function showRss($limit=0)
133 $notices = $this->getNotices($limit);
136 $this->showChannel($notices);
139 foreach ($notices as $n) {
143 $this->showCreators();
147 function showChannel($notices)
150 $channel = $this->getChannel();
151 $image = $this->getImage();
153 $this->elementStart('channel', array('rdf:about' => $channel['url']));
154 $this->element('title', null, $channel['title']);
155 $this->element('link', null, $channel['link']);
156 $this->element('description', null, $channel['description']);
157 $this->element('cc:licence', array('rdf:resource' => common_config('license','url')));
160 $this->element('image', array('rdf:resource' => $image));
163 $this->elementStart('items');
164 $this->elementStart('rdf:Seq');
166 foreach ($notices as $notice) {
167 $this->element('sioct:MicroblogPost', array('rdf:resource' => $notice->uri));
170 $this->elementEnd('rdf:Seq');
171 $this->elementEnd('items');
173 $this->elementEnd('channel');
178 $image = $this->getImage();
180 $channel = $this->getChannel();
181 $this->elementStart('image', array('rdf:about' => $image));
182 $this->element('title', null, $channel['title']);
183 $this->element('link', null, $channel['link']);
184 $this->element('url', null, $image);
185 $this->elementEnd('image');
189 function showItem($notice)
191 $profile = Profile::staticGet($notice->profile_id);
192 $nurl = common_local_url('shownotice', array('notice' => $notice->id));
193 $creator_uri = common_profile_uri($profile);
194 $this->elementStart('item', array('rdf:about' => $notice->uri));
195 $title = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
196 $this->element('title', null, $title);
197 $this->element('link', null, $nurl);
198 $this->element('description', null, $profile->nickname."'s status on ".common_exact_date($notice->created));
199 $this->element('dc:date', null, common_date_w3dtf($notice->created));
200 $this->element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname);
201 $this->element('sioc:has_creator', array('rdf:resource' => $creator_uri));
202 $this->element('laconica:postIcon', array('rdf:resource' => $profile->avatarUrl()));
203 $this->element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
204 $this->elementEnd('item');
205 $this->creators[$creator_uri] = $profile;
208 function showCreators()
210 foreach ($this->creators as $uri => $profile) {
212 $nickname = $profile->nickname;
213 $this->elementStart('sioc:User', array('rdf:about' => $uri));
214 $this->element('foaf:nick', null, $nickname);
215 if ($profile->fullname) {
216 $this->element('foaf:name', null, $profile->fullname);
218 $this->element('sioc:id', null, $id);
219 $avatar = $profile->avatarUrl();
220 $this->element('sioc:avatar', array('rdf:resource' => $avatar));
221 $this->elementEnd('sioc:User');
227 $channel = $this->getChannel();
228 header('Content-Type: application/rdf+xml');
231 $this->elementStart('rdf:RDF', array('xmlns:rdf' =>
232 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
234 'http://purl.org/dc/elements/1.1/',
236 'http://web.resource.org/cc/',
238 'http://purl.org/rss/1.0/modules/content/',
240 'http://xmlns.com/foaf/0.1/',
242 'http://rdfs.org/sioc/ns#',
244 'http://rdfs.org/sioc/types#',
246 'http://laconi.ca/ont/',
247 'xmlns' => 'http://purl.org/rss/1.0/'));
248 $this->elementStart('sioc:Site', array('rdf:about' => common_root_url()));
249 $this->element('sioc:name', null, common_config('site', 'name'));
250 $this->elementStart('sioc:container_of');
251 $this->element('sioc:Container', array('rdf:about' =>
253 $this->elementEnd('sioc:container_of');
254 $this->elementEnd('sioc:Site');
259 $this->elementEnd('rdf:RDF');