all.php 5.25 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1
<?php
Evan Prodromou's avatar
Evan Prodromou committed
2
/*
3
 * StatusNet - the distributed open-source microblogging tool
4
 * Copyright (C) 2008, 2009, StatusNet, Inc.
Evan Prodromou's avatar
Evan Prodromou committed
5
 *
Evan Prodromou's avatar
Evan Prodromou committed
6 7 8 9
 * 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.
Evan Prodromou's avatar
Evan Prodromou committed
10
 *
Evan Prodromou's avatar
Evan Prodromou committed
11 12 13 14
 * 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.
Evan Prodromou's avatar
Evan Prodromou committed
15
 *
Evan Prodromou's avatar
Evan Prodromou committed
16 17 18 19
 * 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); }
Evan Prodromou's avatar
Evan Prodromou committed
21

22 23 24
require_once INSTALLDIR.'/lib/personalgroupnav.php';
require_once INSTALLDIR.'/lib/noticelist.php';
require_once INSTALLDIR.'/lib/feedlist.php';
Evan Prodromou's avatar
Evan Prodromou committed
25

26
class AllAction extends ProfileAction
27
{
28 29
    var $notice;

30
    function isReadOnly($args)
31 32 33
    {
        return true;
    }
34

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
    function prepare($args)
    {
        parent::prepare($args);
        $cur = common_current_user();

        if (!empty($cur) && $cur->id == $this->user->id) {
            $this->notice = $this->user->noticeInbox(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
        } else {
            $this->notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
        }

        if($this->page > 1 && $this->notice->N == 0){
            $this->serverError(_('No such page'),$code=404);
        }

        return true;
    }

53 54
    function handle($args)
    {
55
        parent::handle($args);
56

57
        if (!$this->user) {
58
            $this->clientError(_('No such user.'));
59 60
            return;
        }
61 62

        $this->showPage();
63
    }
64

65 66
    function title()
    {
67 68 69 70 71
        if ($this->page > 1) {
            return sprintf(_("%s and friends, page %d"), $this->user->nickname, $this->page);
        } else {
            return sprintf(_("%s and friends"), $this->user->nickname);
        }
72
    }
73

74
    function getFeeds()
75
    {
76 77 78 79 80 81
        return array(new Feed(Feed::RSS1,
                              common_local_url('allrss', array('nickname' =>
                                                               $this->user->nickname)),
                              sprintf(_('Feed for friends of %s (RSS 1.0)'), $this->user->nickname)),
                     new Feed(Feed::RSS2,
                              common_local_url('api', array('apiaction' => 'statuses',
82
                                                            'method' => 'friends_timeline',
83 84 85 86
                                                            'argument' => $this->user->nickname.'.rss')),
                              sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->user->nickname)),
                     new Feed(Feed::ATOM,
                              common_local_url('api', array('apiaction' => 'statuses',
87
                                                            'method' => 'friends_timeline',
88 89
                                                            'argument' => $this->user->nickname.'.atom')),
                              sprintf(_('Feed for friends of %s (Atom)'), $this->user->nickname)));
90
    }
91

92
    function showLocalNav()
93
    {
94 95
        $nav = new PersonalGroupNav($this);
        $nav->show();
96
    }
97

98
    function showEmptyListMessage()
99
    {
100
        $message = sprintf(_('This is the timeline for %s and friends but no one has posted anything yet.'), $this->user->nickname) . ' ';
101 102 103 104

        if (common_logged_in()) {
            $current_user = common_current_user();
            if ($this->user->id === $current_user->id) {
105
                $message .= _('Try subscribing to more people, [join a group](%%action.groups%%) or post something yourself.');
106
            } else {
107
                $message .= sprintf(_('You can try to [nudge %s](../%s) from his profile or [post something to his or her attention](%%%%action.newnotice%%%%?status_textarea=%s).'), $this->user->nickname, $this->user->nickname, '@' . $this->user->nickname);
108 109 110
            }
        }
        else {
111 112 113
            $message .= sprintf(_('Why not [register an account](%%%%action.%s%%%%) and then nudge %s or post a notice to his or her attention.'),
                                (!common_config('site','openidonly')) ? 'register' : 'openidlogin',
                                $this->user->nickname);
114 115
        }

116
        $this->elementStart('div', 'guide');
117 118 119 120
        $this->raw(common_markup_to_html($message));
        $this->elementEnd('div');
    }

121 122
    function showContent()
    {
123
        $nl = new NoticeList($this->notice, $this);
124 125

        $cnt = $nl->show();
126

127 128 129 130
        if (0 == $cnt) {
            $this->showEmptyListMessage();
        }

131 132
        $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
                          $this->page, 'all', array('nickname' => $this->user->nickname));
133
    }
134 135 136 137 138 139

    function showPageTitle()
    {
        $user =& common_current_user();
        if ($user && ($user->id == $this->user->id)) {
            $this->element('h1', NULL, _("You and friends"));
140
        } else {
141 142 143 144
            $this->element('h1', NULL, sprintf(_('%s and friends'), $this->user->nickname));
        }
    }

Evan Prodromou's avatar
Evan Prodromou committed
145
}