4 * StatusNet, the distributed open-source microblogging tool
6 * Widget to show a list of groups
10 * LICENCE: This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
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/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
35 require_once INSTALLDIR.'/lib/widget.php';
37 define('GROUPS_PER_PAGE', 20);
40 * Widget to show a list of groups
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/
49 class GroupList extends Widget
51 /** Current group, group query. */
53 /** Owner of this list */
55 /** Action object using us. */
58 function __construct($group, $owner=null, $action=null)
60 parent::__construct($action);
62 $this->group = $group;
63 $this->owner = $owner;
64 $this->action = $action;
69 $this->out->elementStart('ul', 'profiles groups xoxo');
73 while ($this->group->fetch()) {
75 if($cnt > GROUPS_PER_PAGE) {
81 $this->out->elementEnd('ul');
88 $this->out->elementStart('li', array('class' => 'profile hentry',
89 'id' => 'group-' . $this->group->id));
91 $user = common_current_user();
93 $this->out->elementStart('div', 'entity_profile vcard entry-content');
95 $logo = ($this->group->stream_logo) ?
96 $this->group->stream_logo : User_group::defaultLogo(AVATAR_STREAM_SIZE);
98 $this->out->elementStart('a', array('href' => $this->group->homeUrl(),
99 'class' => 'url entry-title',
100 'rel' => 'contact group'));
101 $this->out->element('img', array('src' => $logo,
102 'class' => 'photo avatar',
103 'width' => AVATAR_STREAM_SIZE,
104 'height' => AVATAR_STREAM_SIZE,
106 ($this->group->fullname) ? $this->group->fullname :
107 $this->group->nickname));
108 $hasFN = ($this->group->fullname) ? 'nickname' : 'fn org nickname';
109 $this->out->elementStart('span', $hasFN);
110 $this->out->raw($this->highlight($this->group->nickname));
111 $this->out->elementEnd('span');
112 $this->out->elementEnd('a');
114 if ($this->group->fullname) {
115 $this->out->elementStart('span', 'fn org');
116 $this->out->raw($this->highlight($this->group->fullname));
117 $this->out->elementEnd('span');
119 if ($this->group->location) {
120 $this->out->elementStart('span', 'label');
121 $this->out->raw($this->highlight($this->group->location));
122 $this->out->elementEnd('span');
124 if ($this->group->homepage) {
125 $this->out->elementStart('a', array('href' => $this->group->homepage,
127 $this->out->raw($this->highlight($this->group->homepage));
128 $this->out->elementEnd('a');
130 if ($this->group->description) {
131 $this->out->elementStart('p', 'note');
132 $this->out->raw($this->highlight($this->group->description));
133 $this->out->elementEnd('p');
136 # If we're on a list with an owner (subscriptions or subscribers)...
138 if (!empty($user) && !empty($this->owner) && $user->id == $this->owner->id) {
139 $this->showOwnerControls();
142 $this->out->elementEnd('div');
145 $this->out->elementStart('div', 'entity_actions');
146 $this->out->elementStart('ul');
147 $this->out->elementStart('li', 'entity_subscribe');
148 # XXX: special-case for user looking at own
150 if ($user->isMember($this->group)) {
151 $lf = new LeaveForm($this->out, $this->group);
153 } else if (!Group_block::isBlocked($this->group, $user->getProfile())) {
154 $jf = new JoinForm($this->out, $this->group);
157 $this->out->elementEnd('li');
158 $this->out->elementEnd('ul');
159 $this->out->elementEnd('div');
162 $this->out->elementEnd('li');
165 /* Override this in subclasses. */
167 function showOwnerControls()
172 function highlight($text)
174 return htmlspecialchars($text);