]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/allrss.php
0313ef61144f8f1d60b86bfb9d9da081612b9ad4
[quix0rs-gnu-social.git] / actions / allrss.php
1 <?php
2
3 /**
4  * RSS feed for user and friends timeline action class.
5  *
6  * PHP version 5
7  *
8  * @category Action
9  * @package  StatusNet
10  * @author   Evan Prodromou <evan@status.net>
11  * @author   Robin Millette <millette@status.net>
12  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13  * @link     http://status.net/
14  *
15  * StatusNet - the distributed open-source microblogging tool
16  * Copyright (C) 2008, 2009, StatusNet, Inc.
17  *
18  * This program is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU Affero General Public License as published by
20  * the Free Software Foundation, either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU Affero General Public License for more details.
27  *
28  * You should have received a copy of the GNU Affero General Public License
29  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30  */
31
32 if (!defined('LACONICA')) {
33     exit(1);
34 }
35
36 require_once INSTALLDIR.'/lib/rssaction.php';
37
38 /**
39  * RSS feed for user and friends timeline.
40  *
41  * Formatting of RSS handled by Rss10Action
42  *
43  * @category Action
44  * @package  StatusNet
45  * @author   Evan Prodromou <evan@status.net>
46  * @author   Robin Millette <millette@status.net>
47  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
48  * @link     http://status.net/
49  */
50 class AllrssAction extends Rss10Action
51 {
52     var $user = null;
53
54     /**
55      * Initialization.
56      *
57      * @param array $args Web and URL arguments
58      *
59      * @return boolean false if user doesn't exist
60      */
61     function prepare($args)
62     {
63         parent::prepare($args);
64         $nickname   = $this->trimmed('nickname');
65         $this->user = User::staticGet('nickname', $nickname);
66
67         if (!$this->user) {
68             $this->clientError(_('No such user.'));
69             return false;
70         } else {
71             return true;
72         }
73     }
74
75     /**
76      * Get notices
77      *
78      * @param integer $limit max number of notices to return
79      *
80      * @return array notices
81      */
82     function getNotices($limit=0)
83     {
84         $cur = common_current_user();
85
86         if (!empty($cur) && $cur->id == $user->id) {
87             $notice = $this->user->noticeInbox(0, $limit);
88         } else {
89             $notice = $this->user->noticesWithFriends(0, $limit);
90         }
91
92         $user    = $this->user;
93         $notice  = $user->noticesWithFriends(0, $limit);
94         $notices = array();
95
96         while ($notice->fetch()) {
97             $notices[] = clone($notice);
98         }
99
100         return $notices;
101     }
102
103      /**
104      * Get channel.
105      *
106      * @return array associative array on channel information
107      */
108     function getChannel()
109     {
110         $user = $this->user;
111         $c    = array('url' => common_local_url('allrss',
112                                              array('nickname' =>
113                                                    $user->nickname)),
114                    'title' => sprintf(_('%s and friends'), $user->nickname),
115                    'link' => common_local_url('all',
116                                              array('nickname' =>
117                                                    $user->nickname)),
118                    'description' => sprintf(_('Updates from %1$s and friends on %2$s!'),
119                                             $user->nickname, common_config('site', 'name')));
120         return $c;
121     }
122
123     /**
124      * Get image.
125      *
126      * @return string user avatar URL or null
127     */
128     function getImage()
129     {
130         $user    = $this->user;
131         $profile = $user->getProfile();
132         if (!$profile) {
133             return null;
134         }
135         $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
136         return $avatar ? $avatar->url : null;
137     }
138 }
139