]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - _darcs/pristine/lib/rssaction.php
move opening brace of class declaration to next line
[quix0rs-gnu-social.git] / _darcs / pristine / lib / rssaction.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 define('DEFAULT_RSS_LIMIT', 48);
23
24 class Rss10Action extends Action
25 {
26
27     # This will contain the details of each feed item's author and be used to generate SIOC data.
28     var $creators = array();
29
30     function is_readonly()
31     {
32         return true;
33     }
34
35     function handle($args)
36     {
37         parent::handle($args);
38         $limit = (int) $this->trimmed('limit');
39         if ($limit == 0) {
40             $limit = DEFAULT_RSS_LIMIT;
41         }
42         $this->show_rss($limit);
43     }
44
45     function init()
46     {
47         return true;
48     }
49
50     function get_notices()
51     {
52         return array();
53     }
54
55     function get_channel()
56     {
57         return array('url' => '',
58                      'title' => '',
59                      'link' => '',
60                      'description' => '');
61     }
62
63     function get_image()
64     {
65         return null;
66     }
67
68     function show_rss($limit=0)
69     {
70
71         if (!$this->init()) {
72             return;
73         }
74
75         $notices = $this->get_notices($limit);
76
77         $this->init_rss();
78         $this->show_channel($notices);
79         $this->show_image();
80
81         foreach ($notices as $n) {
82             $this->show_item($n);
83         }
84
85         $this->show_creators();
86         $this->end_rss();
87     }
88
89     function show_channel($notices)
90     {
91
92         $channel = $this->get_channel();
93         $image = $this->get_image();
94
95         common_element_start('channel', array('rdf:about' => $channel['url']));
96         common_element('title', null, $channel['title']);
97         common_element('link', null, $channel['link']);
98         common_element('description', null, $channel['description']);
99         common_element('cc:licence', array('rdf:resource' => common_config('license','url')));
100
101         if ($image) {
102             common_element('image', array('rdf:resource' => $image));
103         }
104
105         common_element_start('items');
106         common_element_start('rdf:Seq');
107
108         foreach ($notices as $notice) {
109             common_element('sioct:MicroblogPost', array('rdf:resource' => $notice->uri));
110         }
111
112         common_element_end('rdf:Seq');
113         common_element_end('items');
114
115         common_element_end('channel');
116     }
117
118     function show_image()
119     {
120         $image = $this->get_image();
121         if ($image) {
122             $channel = $this->get_channel();
123             common_element_start('image', array('rdf:about' => $image));
124             common_element('title', null, $channel['title']);
125             common_element('link', null, $channel['link']);
126             common_element('url', null, $image);
127             common_element_end('image');
128         }
129     }
130
131     function show_item($notice)
132     {
133         $profile = Profile::staticGet($notice->profile_id);
134         $nurl = common_local_url('shownotice', array('notice' => $notice->id));
135         $creator_uri = common_profile_uri($profile);
136         common_element_start('item', array('rdf:about' => $notice->uri));
137         $title = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
138         common_element('title', null, $title);
139         common_element('link', null, $nurl);
140         common_element('description', null, $profile->nickname."'s status on ".common_exact_date($notice->created));
141         common_element('dc:date', null, common_date_w3dtf($notice->created));
142         common_element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname);
143         common_element('sioc:has_creator', array('rdf:resource' => $creator_uri));
144         common_element('laconica:postIcon', array('rdf:resource' => common_profile_avatar_url($profile)));
145         common_element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
146         common_element_end('item');
147         $this->creators[$creator_uri] = $profile;
148     }
149
150     function show_creators()
151     {
152         foreach ($this->creators as $uri => $profile) {
153             $id = $profile->id;
154             $nickname = $profile->nickname;
155             common_element_start('sioc:User', array('rdf:about' => $uri));
156             common_element('foaf:nick', null, $nickname);
157             if ($profile->fullname) {
158                 common_element('foaf:name', null, $profile->fullname);
159             }
160             common_element('sioc:id', null, $id);
161             $avatar = common_profile_avatar_url($profile);
162             common_element('sioc:avatar', array('rdf:resource' => $avatar));
163             common_element_end('sioc:User');
164         }
165     }
166
167     function init_rss()
168     {
169         $channel = $this->get_channel();
170         header('Content-Type: application/rdf+xml');
171
172         common_start_xml();
173         common_element_start('rdf:RDF', array('xmlns:rdf' =>
174                                               'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
175                                               'xmlns:dc' =>
176                                               'http://purl.org/dc/elements/1.1/',
177                                               'xmlns:cc' =>
178                                               'http://web.resource.org/cc/',
179                                               'xmlns:content' =>
180                                               'http://purl.org/rss/1.0/modules/content/',
181                                               'xmlns:foaf' =>
182                                               'http://xmlns.com/foaf/0.1/',
183                                               'xmlns:sioc' =>
184                                               'http://rdfs.org/sioc/ns#',
185                                               'xmlns:sioct' =>
186                                               'http://rdfs.org/sioc/types#',
187                                               'xmlns:laconica' =>
188                                               'http://laconi.ca/ont/',
189                                               'xmlns' => 'http://purl.org/rss/1.0/'));
190         common_element_start('sioc:Site', array('rdf:about' => common_root_url()));
191         common_element('sioc:name', null, common_config('site', 'name'));
192         common_element_start('sioc:container_of');
193         common_element('sioc:Container', array('rdf:about' =>
194                                                $channel['url']));
195         common_element_end('sioc:container_of');
196         common_element_end('sioc:Site');
197     }
198
199     function end_rss()
200     {
201         common_element_end('rdf:RDF');
202     }
203 }