]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/userrss.php
20e65b083b9df7045bffe4bf9e7ff66476fcd20b
[quix0rs-gnu-social.git] / actions / userrss.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, 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 require_once(INSTALLDIR.'/lib/rssaction.php');
23
24 // Formatting of RSS handled by Rss10Action
25
26 class UserrssAction extends Rss10Action
27 {
28     var $user = null;
29     var $tag  = null;
30
31     function prepare($args)
32     {
33         parent::prepare($args);
34         $nickname   = $this->trimmed('nickname');
35         $this->user = User::staticGet('nickname', $nickname);
36         $this->tag  = $this->trimmed('tag');
37
38         if (!$this->user) {
39             $this->clientError(_('No such user.'));
40             return false;
41         } else {
42             return true;
43         }
44     }
45
46     function getTaggedNotices($tag = null, $limit=0)
47     {
48         $user = $this->user;
49
50         if (is_null($user)) {
51             return null;
52         }
53
54         $notice = $user->getTaggedNotices(0, ($limit == 0) ? NOTICES_PER_PAGE : $limit, 0, 0, null, $tag);
55
56         $notices = array();
57         while ($notice->fetch()) {
58             $notices[] = clone($notice);
59         }
60
61         return $notices;
62     }
63
64
65     function getNotices($limit=0)
66     {
67
68         $user = $this->user;
69
70         if (is_null($user)) {
71             return null;
72         }
73
74         $notice = $user->getNotices(0, ($limit == 0) ? NOTICES_PER_PAGE : $limit);
75
76         $notices = array();
77         while ($notice->fetch()) {
78             $notices[] = clone($notice);
79         }
80
81         return $notices;
82     }
83
84     function getChannel()
85     {
86         $user = $this->user;
87         $profile = $user->getProfile();
88         $c = array('url' => common_local_url('userrss',
89                                              array('nickname' =>
90                                                    $user->nickname)),
91                    'title' => sprintf(_('%s timeline'), $user->nickname),
92                    'link' => $profile->profileurl,
93                    'description' => sprintf(_('Updates from %1$s on %2$s!'),
94                                             $user->nickname, common_config('site', 'name')));
95         return $c;
96     }
97
98     function getImage()
99     {
100         $user = $this->user;
101         $profile = $user->getProfile();
102         if (!$profile) {
103             common_log_db_error($user, 'SELECT', __FILE__);
104             $this->serverError(_('User without matching profile'));
105             return null;
106         }
107         $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
108         return ($avatar) ? $avatar->url : null;
109     }
110
111     # override parent to add X-SUP-ID URL
112
113     function initRss($limit=0)
114     {
115         $url = common_local_url('sup', null, null, $this->user->id);
116         header('X-SUP-ID: '.$url);
117         parent::initRss($limit);
118     }
119
120     function isReadOnly($args)
121     {
122         return true;
123     }
124 }