grouplist.php 5.49 KB
Newer Older
1 2 3
<?php

/**
4
 * StatusNet, the distributed open-source microblogging tool
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * Widget to show a list of groups
 *
 * 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  Public
24
 * @package   StatusNet
25
 * @author    Evan Prodromou <evan@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 35 36 37 38 39 40
    exit(1);
}

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

/**
 * Widget to show a list of groups
 *
 * @category Public
41
 * @package  StatusNet
42
 * @author   Evan Prodromou <evan@status.net>
43
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44
 * @link     http://status.net/
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
 */

class GroupList extends Widget
{
    /** Current group, group query. */
    var $group = null;
    /** Owner of this list */
    var $owner = null;
    /** Action object using us. */
    var $action = null;

    function __construct($group, $owner=null, $action=null)
    {
        parent::__construct($action);

        $this->group = $group;
        $this->owner = $owner;
        $this->action = $action;
    }

    function show()
    {
67
        $this->out->elementStart('ul', 'profiles groups xoxo');
68 69 70 71 72

        $cnt = 0;

        while ($this->group->fetch()) {
            $cnt++;
73
            if($cnt > GROUPS_PER_PAGE) {
74 75 76 77 78 79 80 81 82 83 84 85
                break;
            }
            $this->showgroup();
        }

        $this->out->elementEnd('ul');

        return $cnt;
    }

    function showGroup()
    {
mmn's avatar
mmn committed
86
        $this->out->elementStart('li', array('class' => 'profile h-card',
87 88 89 90
                                             'id' => 'group-' . $this->group->id));

        $user = common_current_user();

mmn's avatar
mmn committed
91
        $this->out->elementStart('div', 'entity_profile');
92

mmn's avatar
mmn committed
93
        $logo = $this->group->stream_logo ?: User_group::defaultLogo(AVATAR_STREAM_SIZE);
94 95

        $this->out->elementStart('a', array('href' => $this->group->homeUrl(),
mmn's avatar
mmn committed
96
                                            'class' => 'u-url p-nickname',
Sarven Capadisli's avatar
Sarven Capadisli committed
97
                                            'rel' => 'contact group'));
98
        $this->out->element('img', array('src' => $logo,
mmn's avatar
mmn committed
99
                                         'class' => 'avatar u-photo',
100 101
                                         'width' => AVATAR_STREAM_SIZE,
                                         'height' => AVATAR_STREAM_SIZE,
mmn's avatar
mmn committed
102 103
                                         'alt' => $this->group->getBestName()));
        $this->out->text($this->group->getNickname());
104 105 106
        $this->out->elementEnd('a');

        if ($this->group->fullname) {
107
            $this->out->text(' ');
mmn's avatar
mmn committed
108
            $this->out->elementStart('span', 'p-name');
109 110 111 112
            $this->out->raw($this->highlight($this->group->fullname));
            $this->out->elementEnd('span');
        }
        if ($this->group->location) {
113
            $this->out->text(' ');
Sarven Capadisli's avatar
Sarven Capadisli committed
114
            $this->out->elementStart('span', 'label');
115
            $this->out->raw($this->highlight($this->group->location));
116
            $this->out->elementEnd('span');
117 118
        }
        if ($this->group->homepage) {
119
            $this->out->text(' ');
120
            $this->out->elementStart('a', array('href' => $this->group->homepage,
mmn's avatar
mmn committed
121
                                                'class' => 'u-url'));
122 123 124 125
            $this->out->raw($this->highlight($this->group->homepage));
            $this->out->elementEnd('a');
        }
        if ($this->group->description) {
Sarven Capadisli's avatar
Sarven Capadisli committed
126
            $this->out->elementStart('p', 'note');
127
            $this->out->raw($this->highlight($this->group->description));
Sarven Capadisli's avatar
Sarven Capadisli committed
128
            $this->out->elementEnd('p');
129 130
        }

131
        // If we're on a list with an owner (subscriptions or subscribers)...
132

133
        if (!empty($user) && !empty($this->owner) && $user->id == $this->owner->id) {
134 135 136 137 138 139
            $this->showOwnerControls();
        }

        $this->out->elementEnd('div');

        if ($user) {
140 141 142
            $this->out->elementStart('div', 'entity_actions');
            $this->out->elementStart('ul');
            $this->out->elementStart('li', 'entity_subscribe');
143 144
            // XXX: special-case for user looking at own
            // subscriptions page
145 146 147
            if ($user->isMember($this->group)) {
                $lf = new LeaveForm($this->out, $this->group);
                $lf->show();
148
            } else if (!Group_block::isBlocked($this->group, $user->getProfile())) {
149
                $jf = new JoinForm($this->out, $this->group);
150 151
                $jf->show();
            }
152 153 154
            $this->out->elementEnd('li');
            $this->out->elementEnd('ul');
            $this->out->elementEnd('div');
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
        }

        $this->out->elementEnd('li');
    }

    /* Override this in subclasses. */

    function showOwnerControls()
    {
        return;
    }

    function highlight($text)
    {
        return htmlspecialchars($text);
    }
}