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',
89 'id' => 'group-' . $this->group->id));
91 $user = common_current_user();
93 $this->out->elementStart('div', 'entity_profile vcard');
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(),
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 url uid' : 'fn org nickname url uid';
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('dl', 'entity_fn');
116 $this->out->element('dt', null, 'Full name');
117 $this->out->elementStart('dd');
118 $this->out->elementStart('span', 'fn org');
119 $this->out->raw($this->highlight($this->group->fullname));
120 $this->out->elementEnd('span');
121 $this->out->elementEnd('dd');
122 $this->out->elementEnd('dl');
124 if ($this->group->location) {
125 $this->out->elementStart('dl', 'entity_location');
126 $this->out->element('dt', null, _('Location'));
127 $this->out->elementStart('dd', 'label');
128 $this->out->raw($this->highlight($this->group->location));
129 $this->out->elementEnd('dd');
130 $this->out->elementEnd('dl');
132 if ($this->group->homepage) {
133 $this->out->elementStart('dl', 'entity_url');
134 $this->out->element('dt', null, _('URL'));
135 $this->out->elementStart('dd');
136 $this->out->elementStart('a', array('href' => $this->group->homepage,
138 $this->out->raw($this->highlight($this->group->homepage));
139 $this->out->elementEnd('a');
140 $this->out->elementEnd('dd');
141 $this->out->elementEnd('dl');
143 if ($this->group->description) {
144 $this->out->elementStart('dl', 'entity_note');
145 $this->out->element('dt', null, _('Note'));
146 $this->out->elementStart('dd', 'note');
147 $this->out->raw($this->highlight($this->group->description));
148 $this->out->elementEnd('dd');
149 $this->out->elementEnd('dl');
152 # If we're on a list with an owner (subscriptions or subscribers)...
154 if (!empty($user) && !empty($this->owner) && $user->id == $this->owner->id) {
155 $this->showOwnerControls();
158 $this->out->elementEnd('div');
161 $this->out->elementStart('div', 'entity_actions');
162 $this->out->elementStart('ul');
163 $this->out->elementStart('li', 'entity_subscribe');
164 # XXX: special-case for user looking at own
166 if ($user->isMember($this->group)) {
167 $lf = new LeaveForm($this->out, $this->group);
169 } else if (!Group_block::isBlocked($this->group, $user->getProfile())) {
170 $jf = new JoinForm($this->out, $this->group);
173 $this->out->elementEnd('li');
174 $this->out->elementEnd('ul');
175 $this->out->elementEnd('div');
178 $this->out->elementEnd('li');
181 /* Override this in subclasses. */
183 function showOwnerControls()
188 function highlight($text)
190 return htmlspecialchars($text);