allrss.php 4.01 KB
Newer Older
1
<?php
Robin Millette's avatar
Robin Millette committed
2
/**
Robin Millette's avatar
Robin Millette committed
3
 * RSS feed for user and friends timeline action class.
Robin Millette's avatar
Robin Millette committed
4 5 6 7
 *
 * PHP version 5
 *
 * @category Action
8
 * @package  StatusNet
9 10
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
Robin Millette's avatar
Robin Millette committed
11
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12
 * @link     http://status.net/
Robin Millette's avatar
Robin Millette committed
13
 *
14
 * StatusNet - the distributed open-source microblogging tool
15
 * Copyright (C) 2008, 2009, StatusNet, Inc.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

31
if (!defined('STATUSNET') && !defined('LACONICA')) {
Robin Millette's avatar
Robin Millette committed
32 33
    exit(1);
}
34

Robin Millette's avatar
Robin Millette committed
35
require_once INSTALLDIR.'/lib/rssaction.php';
36

Robin Millette's avatar
Robin Millette committed
37 38 39 40 41 42
/**
 * RSS feed for user and friends timeline.
 *
 * Formatting of RSS handled by Rss10Action
 *
 * @category Action
43
 * @package  StatusNet
44 45
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
Robin Millette's avatar
Robin Millette committed
46
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
47
 * @link     http://status.net/
Robin Millette's avatar
Robin Millette committed
48
 */
49 50
class AllrssAction extends Rss10Action
{
Evan Prodromou's avatar
Evan Prodromou committed
51
    var $user = null;
52

Robin Millette's avatar
Robin Millette committed
53 54
    /**
     * Initialization.
55 56 57
     *
     * @param array $args Web and URL arguments
     *
58
     * @return boolean false if user doesn't exist
59 60
     *
     */
61
    function prepare($args)
62
    {
63
        parent::prepare($args);
Robin Millette's avatar
Robin Millette committed
64
        $nickname   = $this->trimmed('nickname');
65
        $this->user = User::staticGet('nickname', $nickname);
66

67
        if (!$this->user) {
Siebrand Mazeland's avatar
Siebrand Mazeland committed
68
            // TRANS: Client error when user not found for an rss related action.
69
            $this->clientError(_('No such user.'));
70 71
            return false;
        } else {
72
            $this->notices = $this->getNotices($this->limit);
73 74 75
            return true;
        }
    }
76

Robin Millette's avatar
Robin Millette committed
77 78 79 80 81 82 83 84
    /**
     * Get notices
     *
     * @param integer $limit max number of notices to return
     *
     * @return array notices
     */
    function getNotices($limit=0)
85
    {
86 87
        $stream = new InboxNoticeStream($this->user);
        $notice = $stream->getNotices(0, $limit, null, null);
88

Adrian Lang's avatar
Adrian Lang committed
89
        $notices = array();
90

91 92 93
        while ($notice->fetch()) {
            $notices[] = clone($notice);
        }
94

95 96
        return $notices;
    }
97

Robin Millette's avatar
Robin Millette committed
98 99 100 101 102 103
     /**
     * Get channel.
     *
     * @return array associative array on channel information
     */
    function getChannel()
104
    {
105
        $user = $this->user;
Robin Millette's avatar
Robin Millette committed
106
        $c    = array('url' => common_local_url('allrss',
107 108
                                             array('nickname' =>
                                                   $user->nickname)),
109
                   // TRANS: Message is used as link title. %s is a user nickname.
110 111 112 113
                   'title' => sprintf(_('%s and friends'), $user->nickname),
                   'link' => common_local_url('all',
                                             array('nickname' =>
                                                   $user->nickname)),
114
                   // TRANS: Message is used as link description. %1$s is a username, %2$s is a site name.
115 116
                   'description' => sprintf(_('Updates from %1$s and friends on %2$s!'),
                                            $user->nickname, common_config('site', 'name')));
117 118
        return $c;
    }
119

Robin Millette's avatar
Robin Millette committed
120 121 122 123
    /**
     * Get image.
     *
     * @return string user avatar URL or null
Siebrand Mazeland's avatar
Siebrand Mazeland committed
124
     */
Robin Millette's avatar
Robin Millette committed
125
    function getImage()
126
    {
Robin Millette's avatar
Robin Millette committed
127
        $user    = $this->user;
128 129
        $profile = $user->getProfile();
        if (!$profile) {
Evan Prodromou's avatar
Evan Prodromou committed
130
            return null;
131 132
        }
        $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
Robin Millette's avatar
Robin Millette committed
133
        return $avatar ? $avatar->url : null;
134
    }
Robin Millette's avatar
Robin Millette committed
135
}