userrss.php 3.89 KB
Newer Older
1 2
<?php
/*
3
 * StatusNet - the distributed open-source microblogging tool
4
 * Copyright (C) 2008, 2009, StatusNet, Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * 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/>.
 */

20
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
21 22 23 24 25

require_once(INSTALLDIR.'/lib/rssaction.php');

// Formatting of RSS handled by Rss10Action

26 27
class UserrssAction extends Rss10Action
{
Robin Millette's avatar
Robin Millette committed
28
    var $tag  = null;
29

Robin Millette's avatar
Robin Millette committed
30
    function prepare($args)
31
    {
32 33
        common_debug("UserrssAction");

Robin Millette's avatar
Robin Millette committed
34
        parent::prepare($args);
Robin Millette's avatar
Robin Millette committed
35
        $nickname   = $this->trimmed('nickname');
36
        $this->user = User::staticGet('nickname', $nickname);
Robin Millette's avatar
Robin Millette committed
37
        $this->tag  = $this->trimmed('tag');
38

39
        if (!$this->user) {
40
            // TRANS: Client error displayed when user not found for an action.
41
            $this->clientError(_('No such user.'));
42 43
            return false;
        } else {
44
            if (!empty($this->tag)) {
45
                $this->notices = $this->getTaggedNotices();
46
            } else {
47
                $this->notices = $this->getNotices();
48
            }
49 50 51
            return true;
        }
    }
52

53
    function getTaggedNotices()
Robin Millette's avatar
Robin Millette committed
54
    {
55 56 57 58 59 60 61
        $notice = $this->user->getTaggedNotices(
            $this->tag,
            0,
            ($this->limit == 0) ? NOTICES_PER_PAGE : $this->limit,
            0,
            0
        );
Robin Millette's avatar
Robin Millette committed
62 63 64 65 66 67 68 69 70 71

        $notices = array();
        while ($notice->fetch()) {
            $notices[] = clone($notice);
        }

        return $notices;
    }


72
    function getNotices()
73
    {
74 75
        $notice = $this->user->getNotices(
            0,
76
            ($this->limit == 0) ? NOTICES_PER_PAGE : $this->limit
77
        );
78

Adrian Lang's avatar
Adrian Lang committed
79
        $notices = array();
80 81 82
        while ($notice->fetch()) {
            $notices[] = clone($notice);
        }
83

84 85
        return $notices;
    }
86

Robin Millette's avatar
Robin Millette committed
87
    function getChannel()
88
    {
89 90 91 92 93
        $user = $this->user;
        $profile = $user->getProfile();
        $c = array('url' => common_local_url('userrss',
                                             array('nickname' =>
                                                   $user->nickname)),
94
                   // TRANS: Message is used as link title. %s is a user nickname.
95
                   'title' => sprintf(_('%s timeline'), $user->nickname),
96
                   'link' => $profile->profileurl,
97
                   // TRANS: Message is used as link description. %1$s is a username, %2$s is a site name.
98 99
                   'description' => sprintf(_('Updates from %1$s on %2$s!'),
                                            $user->nickname, common_config('site', 'name')));
100 101
        return $c;
    }
102

Robin Millette's avatar
Robin Millette committed
103
    function getImage()
104
    {
105 106 107 108
        $user = $this->user;
        $profile = $user->getProfile();
        if (!$profile) {
            common_log_db_error($user, 'SELECT', __FILE__);
109 110
            // TRANS: Error message displayed when referring to a user without a profile.
            $this->serverError(_('User has no profile.'));
Evan Prodromou's avatar
Evan Prodromou committed
111
            return null;
112 113
        }
        $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
Evan Prodromou's avatar
Evan Prodromou committed
114
        return ($avatar) ? $avatar->url : null;
115
    }
Evan Prodromou's avatar
Evan Prodromou committed
116

117
    // override parent to add X-SUP-ID URL
118

Robin Millette's avatar
Robin Millette committed
119
    function initRss($limit=0)
120
    {
121
        $url = common_local_url('sup', null, null, $this->user->id);
122
        header('X-SUP-ID: '.$url);
Robin Millette's avatar
Robin Millette committed
123
        parent::initRss($limit);
124
    }
125

126
    function isReadOnly($args)
127 128 129
    {
        return true;
    }
Robin Millette's avatar
Robin Millette committed
130
}