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 define('DEFAULT_RSS_LIMIT', 48);
24 class Rss10Action extends Action {
26 # This will contain the details of each feed item's author and be used to generate SIOC data.
27 var $creators = array();
29 function is_readonly() {
33 function handle($args) {
34 parent::handle($args);
35 $limit = (int) $this->trimmed('limit');
37 $limit = DEFAULT_RSS_LIMIT;
39 $this->show_rss($limit);
46 function get_notices() {
50 function get_channel() {
51 return array('url' => '',
57 function get_image() {
61 function show_rss($limit=0) {
67 $notices = $this->get_notices($limit);
70 $this->show_channel($notices);
73 foreach ($notices as $n) {
77 $this->show_creators();
81 function show_channel($notices) {
83 $channel = $this->get_channel();
84 $image = $this->get_image();
86 common_element_start('channel', array('rdf:about' => $channel['url']));
87 common_element('title', NULL, $channel['title']);
88 common_element('link', NULL, $channel['link']);
89 common_element('description', NULL, $channel['description']);
90 common_element('cc:licence', array('rdf:resource' => common_config('license','url')));
93 common_element('image', array('rdf:resource' => $image));
96 common_element_start('items');
97 common_element_start('rdf:Seq');
99 foreach ($notices as $notice) {
100 common_element('sioct:MicroblogPost', array('rdf:resource' => $notice->uri));
103 common_element_end('rdf:Seq');
104 common_element_end('items');
106 common_element_end('channel');
109 function show_image() {
110 $image = $this->get_image();
112 $channel = $this->get_channel();
113 common_element_start('image', array('rdf:about' => $image));
114 common_element('title', NULL, $channel['title']);
115 common_element('link', NULL, $channel['link']);
116 common_element('url', NULL, $image);
117 common_element_end('image');
121 function show_item($notice) {
122 $profile = Profile::staticGet($notice->profile_id);
123 $nurl = common_local_url('shownotice', array('notice' => $notice->id));
124 $creator_uri = common_profile_uri($profile);
125 common_element_start('item', array('rdf:about' => $notice->uri));
126 $title = $profile->nickname . ': ' . common_xml_safe_str($notice->content);
127 common_element('title', NULL, $title);
128 common_element('link', NULL, $nurl);
129 common_element('description', NULL, $profile->nickname."'s status on ".common_exact_date($notice->created));
130 common_element('dc:date', NULL, common_date_w3dtf($notice->created));
131 common_element('dc:creator', NULL, ($profile->fullname) ? $profile->fullname : $profile->nickname);
132 common_element('sioc:has_creator', array('rdf:resource' => $creator_uri));
133 common_element('laconica:postIcon', array('rdf:resource' => common_profile_avatar_url($profile)));
134 common_element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
135 common_element_start('content:items');
136 common_element_start('rdf:Bag');
137 common_element_start('rdf:li');
138 common_element_start('content:item');
139 common_element('content:format', array('rdf:resource' =>
140 'http://www.w3.org/1999/xhtml'));
141 common_text($notice->rendered);
142 common_element_end('content:item');
143 common_element_end('rdf:li');
144 common_element_start('rdf:li');
145 common_element_start('content:item');
146 common_element('content:format', array('rdf:resource' =>
147 'http://www.isi.edu/in-notes/iana/assignments/media-types/text/plain'));
148 common_text(common_xml_safe_str($notice->content));
149 common_element_end('content:item');
150 common_element_end('rdf:li');
151 common_element_end('rdf:Bag');
152 common_element_end('content:items');
153 common_element_end('item');
154 $this->creators[$creator_uri] = $profile;
157 function show_creators() {
158 foreach ($this->creators as $uri => $profile) {
160 $nickname = $profile->nickname;
161 common_element_start('sioc:User', array('rdf:about' => $uri));
162 common_element('foaf:nick', NULL, $nickname);
163 if ($profile->fullname) {
164 common_element('foaf:name', NULL, $profile->fullname);
166 common_element('sioc:id', NULL, $id);
167 $avatar = common_profile_avatar_url($profile);
168 common_element('sioc:avatar', array('rdf:resource' => $avatar));
169 common_element_end('sioc:User');
173 function init_rss() {
174 $channel = $this->get_channel();
175 header('Content-Type: application/rdf+xml');
178 common_element_start('rdf:RDF', array('xmlns:rdf' =>
179 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
181 'http://purl.org/dc/elements/1.1/',
183 'http://web.resource.org/cc/',
185 'http://purl.org/rss/1.0/modules/content/',
187 'http://xmlns.com/foaf/0.1/',
189 'http://rdfs.org/sioc/ns#',
191 'http://rdfs.org/sioc/types#',
193 'http://laconi.ca/ont/',
194 'xmlns' => 'http://purl.org/rss/1.0/'));
195 common_element_start('sioc:Site', array('rdf:about' => common_root_url()));
196 common_element('sioc:name', NULL, common_config('site', 'name'));
197 common_element_start('sioc:container_of');
198 common_element('sioc:Container', array('rdf:about' =>
200 common_element_end('sioc:container_of');
201 common_element_end('sioc:Site');
205 common_element_end('rdf:RDF');