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;
46 * Just wraps the Action constructor.
48 * @param string $output URI to output to, default = stdout
49 * @param boolean $indent Whether to indent output, default true
51 * @see Action::__construct
54 function __construct($output='php://output', $indent=true)
56 parent::__construct($output, $indent);
60 * Do we need to write to the database?
62 * @return boolean true
71 * Read arguments and initialize members
73 * @param array $args Arguments from $_REQUEST
74 * @return boolean success
77 function prepare($args)
79 parent::prepare($args);
80 $this->limit = (int) $this->trimmed('limit');
81 if ($this->limit == 0) {
82 $this->limit = DEFAULT_RSS_LIMIT;
90 * @param array $args Arguments from $_REQUEST
95 function handle($args)
97 // Get the list of notices
98 $this->notices = $this->getNotices();
99 // Parent handling, including cache check
100 parent::handle($args);
101 $this->showRss($this->limit);
105 * Get the notices to output in this stream
107 * @return array an array of Notice objects sorted in reverse chron
110 function getNotices()
116 * Get a description of the channel
118 * Returns an array with the following
122 function getChannel()
124 return array('url' => '',
127 'description' => '');
135 function showRss($limit=0)
137 $notices = $this->getNotices($limit);
140 $this->showChannel($notices);
143 foreach ($notices as $n) {
147 $this->showCreators();
151 function showChannel($notices)
154 $channel = $this->getChannel();
155 $image = $this->getImage();
157 $this->elementStart('channel', array('rdf:about' => $channel['url']));
158 $this->element('title', null, $channel['title']);
159 $this->element('link', null, $channel['link']);
160 $this->element('description', null, $channel['description']);
161 $this->element('cc:licence', array('rdf:resource' => common_config('license','url')));
164 $this->element('image', array('rdf:resource' => $image));
167 $this->elementStart('items');
168 $this->elementStart('rdf:Seq');
170 foreach ($notices as $notice) {
171 $this->element('sioct:MicroblogPost', array('rdf:resource' => $notice->uri));
174 $this->elementEnd('rdf:Seq');
175 $this->elementEnd('items');
177 $this->elementEnd('channel');
182 $image = $this->getImage();
184 $channel = $this->getChannel();
185 $this->elementStart('image', array('rdf:about' => $image));
186 $this->element('title', null, $channel['title']);
187 $this->element('link', null, $channel['link']);
188 $this->element('url', null, $image);
189 $this->elementEnd('image');
193 function showItem($notice)
195 $profile = Profile::staticGet($notice->profile_id);
196 $nurl = common_local_url('shownotice', array('notice' => $notice->id));
197 $creator_uri = common_profile_uri($profile);
198 $this->elementStart('item', array('rdf:about' => $notice->uri));
199 $title = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
200 $this->element('title', null, $title);
201 $this->element('link', null, $nurl);
202 $this->element('description', null, $profile->nickname."'s status on ".common_exact_date($notice->created));
203 $this->element('dc:date', null, common_date_w3dtf($notice->created));
204 $this->element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname);
205 $this->element('sioc:has_creator', array('rdf:resource' => $creator_uri));
206 $this->element('laconica:postIcon', array('rdf:resource' => $profile->avatarUrl()));
207 $this->element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
208 $this->elementEnd('item');
209 $this->creators[$creator_uri] = $profile;
212 function showCreators()
214 foreach ($this->creators as $uri => $profile) {
216 $nickname = $profile->nickname;
217 $this->elementStart('sioc:User', array('rdf:about' => $uri));
218 $this->element('foaf:nick', null, $nickname);
219 if ($profile->fullname) {
220 $this->element('foaf:name', null, $profile->fullname);
222 $this->element('sioc:id', null, $id);
223 $avatar = $profile->avatarUrl();
224 $this->element('sioc:avatar', array('rdf:resource' => $avatar));
225 $this->elementEnd('sioc:User');
231 $channel = $this->getChannel();
232 header('Content-Type: application/rdf+xml');
235 $this->elementStart('rdf:RDF', array('xmlns:rdf' =>
236 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
238 'http://purl.org/dc/elements/1.1/',
240 'http://web.resource.org/cc/',
242 'http://purl.org/rss/1.0/modules/content/',
244 'http://xmlns.com/foaf/0.1/',
246 'http://rdfs.org/sioc/ns#',
248 'http://rdfs.org/sioc/types#',
250 'http://laconi.ca/ont/',
251 'xmlns' => 'http://purl.org/rss/1.0/'));
252 $this->elementStart('sioc:Site', array('rdf:about' => common_root_url()));
253 $this->element('sioc:name', null, common_config('site', 'name'));
254 $this->elementStart('sioc:container_of');
255 $this->element('sioc:Container', array('rdf:about' =>
257 $this->elementEnd('sioc:container_of');
258 $this->elementEnd('sioc:Site');
263 $this->elementEnd('rdf:RDF');
267 * When was this page last modified?
271 function lastModified()
273 if (empty($this->notices)) {
277 if (count($this->notices) == 0) {
281 // FIXME: doesn't handle modified profiles, avatars, deleted notices
283 return strtotime($this->notices[0]->created);