peopletagsbyuser.php 10.2 KB
Newer Older
Shashi Gowda's avatar
Shashi Gowda committed
1 2 3 4
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
5
 * Lists by a user
Shashi Gowda's avatar
Shashi Gowda committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * PHP version 5
 *
 * LICENCE: 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/>.
 *
 * @category  Personal
 * @package   StatusNet
 * @author    Shashi Gowda <connect2shashi@gmail.com>
25
 * @copyright 2008-2011 StatusNet, Inc.
Shashi Gowda's avatar
Shashi Gowda committed
26 27 28 29 30 31 32 33 34 35
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

if (!defined('STATUSNET') && !defined('LACONICA')) {
    exit(1);
}

require_once INSTALLDIR.'/lib/peopletaglist.php';

36
class PeopletagsbyuserAction extends Action
Shashi Gowda's avatar
Shashi Gowda committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
{
    var $page = null;
    var $tagger = null;
    var $tags = null;

    function isReadOnly($args)
    {
        return true;
    }

    function title()
    {
        if ($this->page == 1) {
            if ($this->isOwner()) {
                if ($this->arg('private')) {
52 53
                    // TRANS: Title for lists by a user page for a private tag.
                    return _('Private lists by you');
Shashi Gowda's avatar
Shashi Gowda committed
54
                } else if ($this->arg('public')) {
55 56
                    // TRANS: Title for lists by a user page for a public tag.
                    return _('Public lists by you');
Shashi Gowda's avatar
Shashi Gowda committed
57
                }
58 59
                // TRANS: Title for lists by a user page.
                return _('Lists by you');
Shashi Gowda's avatar
Shashi Gowda committed
60
            }
61
            // TRANS: Title for lists by a user page.
62
            // TRANS: %s is a user nickname.
63
            return sprintf(_('Lists by %s'), $this->tagger->nickname);
Shashi Gowda's avatar
Shashi Gowda committed
64
        } else {
65
            // TRANS: Title for lists by a user page.
66
            // TRANS: %1$s is a user nickname, %2$d is a page number.
67
            return sprintf(_('Lists by %1$s, page %2$d'), $this->tagger->nickname, $this->page);
Shashi Gowda's avatar
Shashi Gowda committed
68 69 70 71 72 73 74 75 76 77 78
        }
    }

    function prepare($args)
    {
        parent::prepare($args);

        if ($this->arg('public') && $this->arg('private')) {
            $this->args['public'] = $this->args['private'] = false;
        }

79 80 81 82 83 84
        if (common_config('singleuser', 'enabled')) {
            $nickname_arg = User::singleUserNickname();
        } else {
            $nickname_arg = $this->arg('nickname');
        }

Shashi Gowda's avatar
Shashi Gowda committed
85 86 87 88 89 90 91 92 93 94 95 96
        $nickname = common_canonical_nickname($nickname_arg);

        // Permanent redirect on non-canonical nickname

        if ($nickname_arg != $nickname) {
            $args = $this->getSelfUrlArgs();
            if ($this->arg('page') && $this->arg('page') != 1) {
                $args['page'] = $this->arg['page'];
            }
            common_redirect(common_local_url('peopletagsbyuser', $args), 301);
        }

97
        $this->user = User::getKV('nickname', $nickname);
Shashi Gowda's avatar
Shashi Gowda committed
98 99

        if (!$this->user) {
100
            // TRANS: Client error displayed trying to perform an action related to a non-existing user.
Shashi Gowda's avatar
Shashi Gowda committed
101 102 103 104 105 106
            $this->clientError(_('No such user.'), 404);
        }

        $this->tagger = $this->user->getProfile();

        if (!$this->tagger) {
107
            // TRANS: Error message displayed when referring to a user without a profile.
Shashi Gowda's avatar
Shashi Gowda committed
108 109 110 111 112 113 114 115 116 117 118
            $this->serverError(_('User has no profile.'));
        }

        $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;


        $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE;
        $limit  = PEOPLETAGS_PER_PAGE + 1;

        $user = common_current_user();
        if ($this->arg('public')) {
119
            $this->tags = $this->tagger->getLists(null, $offset, $limit);
Shashi Gowda's avatar
Shashi Gowda committed
120 121
        } else if ($this->arg('private')) {
            if (empty($user)) {
122 123
                // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
                $this->clientError(_('Not logged in.'), 403);
Shashi Gowda's avatar
Shashi Gowda committed
124 125 126 127 128
            }

            if ($this->isOwner()) {
                $this->tags = $this->tagger->getPrivateTags($offset, $limit);
            } else {
129 130
                // TRANS: Client error displayed when trying view another user's private lists.
                $this->clientError(_('You cannot view others\' private lists'), 403);
Shashi Gowda's avatar
Shashi Gowda committed
131 132
            }
        } else {
133
            $this->tags = $this->tagger->getLists($this->scoped, $offset, $limit);
Shashi Gowda's avatar
Shashi Gowda committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
        }
        return true;
    }

    function handle($args)
    {
        parent::handle($args);

		# Post from the tag dropdown; redirect to a GET

		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
		    common_redirect(common_local_url('peopletagsbyuser', $this->getSelfUrlArgs()), 303);
		}

        $this->showPage();
    }

    function showModeSelector()
    {
        $this->elementStart('dl', array('id'=>'filter_tags'));
154
        // TRANS: Mode selector label.
Shashi Gowda's avatar
Shashi Gowda committed
155 156 157 158 159 160 161 162 163
        $this->element('dt', null, _('Mode'));
        $this->elementStart('dd');
        $this->elementStart('ul');
        $this->elementStart('li', array('id' => 'filter_tags_for',
                                         'class' => 'child_1'));
        $this->element('a',
                       array('href' =>
                             common_local_url('peopletagsforuser',
                                              array('nickname' => $this->user->nickname))),
164 165
                       // TRANS: Link text to show lists for user %s.
                       sprintf(_('Lists for %s'), $this->tagger->nickname));
Shashi Gowda's avatar
Shashi Gowda committed
166 167 168 169 170 171 172 173 174 175
        $this->elementEnd('li');

        if ($this->isOwner()) {
            $this->elementStart('li', array('id'=>'filter_tags_item'));
            $this->elementStart('form', array('name' => 'modeselector',
                                               'id' => 'form_filter_bymode',
                                               'action' => common_local_url('peopletagsbyuser',
                                                    array('nickname' => $this->tagger->nickname)),
                                               'method' => 'post'));
            $this->elementStart('fieldset');
176
            // TRANS: Fieldset legend.
Shashi Gowda's avatar
Shashi Gowda committed
177 178 179 180 181 182 183 184
            $this->element('legend', null, _('Select tag to filter'));

            $priv = $this->arg('private');
            $pub  = $this->arg('public');

            if (!$priv && !$pub) {
                $priv = $pub = true;
            }
185 186 187 188 189 190 191 192
            // TRANS: Checkbox label to show private tags.
            $this->checkbox('private', _m('LABEL','Private'), $priv,
                                // TRANS: Checkbox title.
                                _('Show private tags.'));
            // TRANS: Checkbox label to show public tags.
            $this->checkbox('public', _m('LABEL','Public'), $pub,
                                // TRANS: Checkbox title.
                                _('Show public tags.'));
Shashi Gowda's avatar
Shashi Gowda committed
193
            $this->hidden('nickname', $this->user->nickname);
194 195
            // TRANS: Submit button text for tag filter form.
            $this->submit('submit', _m('BUTTON','Go'));
Shashi Gowda's avatar
Shashi Gowda committed
196 197 198 199 200 201 202 203 204 205 206 207
            $this->elementEnd('fieldset');
            $this->elementEnd('form');
            $this->elementEnd('li');
        }
        $this->elementEnd('ul');
        $this->elementEnd('dd');
        $this->elementEnd('dl');
    }

    function showAnonymousMessage()
    {
        $notice =
208
          // TRANS: Message displayed for anonymous users on page that displays lists by a user.
209 210
          // TRANS: This message contains Markdown links in the form [description](links).
          // TRANS: %s is a tagger nickname.
211 212
          sprintf(_('These are lists created by **%s**. ' .
                    'Lists are how you sort similar ' .
Shashi Gowda's avatar
Shashi Gowda committed
213 214 215 216
                    'people on %%%%site.name%%%%, a [micro-blogging]' .
                    '(http://en.wikipedia.org/wiki/Micro-blogging) service ' .
                    'based on the Free Software [StatusNet](http://status.net/) tool. ' .
                    'You can easily keep track of what they ' .
Siebrand Mazeland's avatar
Siebrand Mazeland committed
217
                    'are doing by subscribing to the list\'s timeline.' ), $this->tagger->nickname);
Shashi Gowda's avatar
Shashi Gowda committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
        $this->elementStart('div', array('id' => 'anon_notice'));
        $this->raw(common_markup_to_html($notice));
        $this->elementEnd('div');
    }

    function showPageNotice()
    {
        $this->elementStart('div', 'instructions');
        $this->showModeSelector();
        $this->elementEnd('div');
    }

    function showContent()
    {
        #TODO: controls here.

        $pl = new PeopletagList($this->tags, $this);
        $cnt = $pl->show();

        if ($cnt == 0) {
            $this->showEmptyListMessage();
        }
        $this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE,
                          $this->page, 'peopletagsbyuser', $this->getSelfUrlArgs());
    }

    function getSelfUrlArgs()
    {
        $args = array();
        if ($this->arg('private')) {
            $args['private'] = 1;
        } else if ($this->arg('public')) {
            $args['public'] = 1;
        }
        $args['nickname'] = $this->trimmed('nickname');

        return $args;
    }

    function isOwner()
    {
        $user = common_current_user();
        return !empty($user) && $user->id == $this->tagger->id;
    }

263 264 265 266 267 268
    function showObjectNav()
    {
        $nav = new PeopletagNav($this, $this->tagger);
        $nav->show();
    }

Shashi Gowda's avatar
Shashi Gowda committed
269 270
    function showEmptyListMessage()
    {
271
          // TRANS: Message displayed on page that displays lists by a user when there are none.
272 273
          // TRANS: This message contains Markdown links in the form [description](links).
          // TRANS: %s is a tagger nickname.
274
        $message = sprintf(_('%s has not created any [lists](%%%%doc.lists%%%%) yet.'), $this->tagger->nickname);
Shashi Gowda's avatar
Shashi Gowda committed
275 276 277 278 279
        $this->elementStart('div', 'guide');
        $this->raw(common_markup_to_html($message));
        $this->elementEnd('div');
    }

280 281 282 283 284 285
    function showProfileBlock()
    {
        $block = new AccountProfileBlock($this, $this->tagger);
        $block->show();
    }

Shashi Gowda's avatar
Shashi Gowda committed
286 287 288 289 290 291
    function showSections()
    {
        #TODO: tags with most subscribers
        #TODO: tags with most "members"
    }
}