We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

usergroups.php 6.01 KB
Newer Older
1 2
<?php
/**
3
 * StatusNet, the distributed open-source microblogging tool
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * User groups information
 *
 * 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
23
 * @package   StatusNet
24 25
 * @author    Evan Prodromou <evan@status.net>
 * @author    Sarven Capadisli <csarven@status.net>
26
 * @copyright 2008-2009 StatusNet, Inc.
27
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28
 * @link      http://status.net/
29 30
 */

31
if (!defined('STATUSNET') && !defined('LACONICA')) {
32 33 34
    exit(1);
}

35
require_once INSTALLDIR.'/lib/grouplist.php';
36 37 38 39 40 41 42

/**
 * User groups page
 *
 * Show the groups a user belongs to
 *
 * @category Personal
43
 * @package  StatusNet
44
 * @author   Evan Prodromou <evan@status.net>
45
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46
 * @link     http://status.net/
47
 */
48
class UsergroupsAction extends ProfileAction
49 50 51 52
{
    var $page = null;
    var $profile = null;

53
    function isReadOnly($args)
Evan Prodromou's avatar
Evan Prodromou committed
54 55 56 57
    {
        return true;
    }

58 59 60
    function title()
    {
        if ($this->page == 1) {
61 62
            // TRANS: Page title for first page of groups for a user.
            // TRANS: %s is a nickname.
63
            return sprintf(_('%s groups'), $this->user->nickname);
64
        } else {
65 66
            // TRANS: Page title for all but the first page of groups for a user.
            // TRANS: %1$s is a nickname, %2$d is a page number.
67
            return sprintf(_('%1$s groups, page %2$d'),
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
                           $this->user->nickname,
                           $this->page);
        }
    }

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

        $nickname_arg = $this->arg('nickname');
        $nickname = common_canonical_nickname($nickname_arg);

        // Permanent redirect on non-canonical nickname

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

        $this->user = User::staticGet('nickname', $nickname);

        if (!$this->user) {
94
            // TRANS: Client error displayed requesting groups for a non-existing user.
95 96 97 98 99 100 101
            $this->clientError(_('No such user.'), 404);
            return false;
        }

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

        if (!$this->profile) {
102
            // TRANS: Error message displayed when referring to a user without a profile.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
            $this->serverError(_('User has no profile.'));
            return false;
        }

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

        return true;
    }

    function handle($args)
    {
        parent::handle($args);
        $this->showPage();
    }

    function showContent()
    {
120
        $this->elementStart('p', array('id' => 'new_group'));
121
        $this->element('a', array('href' => common_local_url('newgroup'),
122
                                  'class' => 'more'),
123
                       // TRANS: Link text on group page to create a new group.
124
                       _('Create a new group'));
125
        $this->elementEnd('p');
126

127 128 129
        $this->elementStart('p', array('id' => 'group_search'));
        $this->element('a', array('href' => common_local_url('groupsearch'),
                                  'class' => 'more'),
130
                       // TRANS: Link text on group page to search for groups.
131 132 133
                       _('Search for more groups'));
        $this->elementEnd('p');

134 135 136 137 138 139 140 141 142 143 144 145 146
        if (Event::handle('StartShowUserGroupsContent', array($this))) {
            $offset = ($this->page-1) * GROUPS_PER_PAGE;
            $limit =  GROUPS_PER_PAGE + 1;

            $groups = $this->user->getGroups($offset, $limit);

            if ($groups) {
                $gl = new GroupList($groups, $this->user, $this);
                $cnt = $gl->show();
                if (0 == $cnt) {
                    $this->showEmptyListMessage();
                }
            }
147

148 149 150
            $this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE,
                              $this->page, 'usergroups',
                              array('nickname' => $this->user->nickname));
151

152
            Event::handle('EndShowUserGroupsContent', array($this));
153 154
        }
    }
155 156 157

    function showEmptyListMessage()
    {
158 159
        // TRANS: Text on group page for a user that is not a member of any group.
        // TRANS: %s is a user nickname.
160 161 162 163 164
        $message = sprintf(_('%s is not a member of any group.'), $this->user->nickname) . ' ';

        if (common_logged_in()) {
            $current_user = common_current_user();
            if ($this->user->id === $current_user->id) {
165 166
                // TRANS: Text on group page for a user that is not a member of any group. This message contains
                // TRANS: a Markdown link in the form [link text](link) and a variable that should not be changed.
167 168 169 170 171 172 173
                $message .= _('Try [searching for groups](%%action.groupsearch%%) and joining them.');
            }
        }
        $this->elementStart('div', 'guide');
        $this->raw(common_markup_to_html($message));
        $this->elementEnd('div');
    }
174 175 176 177 178 179

    function showProfileBlock()
    {
        $block = new AccountProfileBlock($this, $this->profile);
        $block->show();
    }
180
}