3 * StatusNet, the distributed open-source microblogging tool
5 * Widget to show a list of profiles
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @copyright 2008-2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 require_once INSTALLDIR.'/lib/widget.php';
35 require_once INSTALLDIR.'/lib/peopletags.php';
38 * Widget to show a list of profiles
42 * @author Zach Copley <zach@status.net>
43 * @author Evan Prodromou <evan@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://status.net/
47 class ProfileList extends Widget
49 /** Current profile, profile query. */
51 /** Action object using us. */
54 function __construct($profile, $action=null)
56 parent::__construct($action);
58 $this->profile = $profile;
59 $this->action = $action;
66 if (Event::handle('StartProfileList', array($this))) {
68 $cnt = $this->showProfiles();
70 Event::handle('EndProfileList', array($this));
78 $this->out->elementStart('ul', 'profiles xoxo');
83 $this->out->elementEnd('ul');
86 function showProfiles()
88 // Note: we don't use fetchAll() because it's borked with query()
92 while ($this->profile->fetch()) {
93 $profiles[] = clone($this->profile);
96 $cnt = count($profiles);
98 $max = min($cnt, $this->maxProfiles());
100 for ($i = 0; $i < $max; $i++) {
101 $pli = $this->newListItem($profiles[$i]);
108 function newListItem($profile)
110 return new ProfileListItem($profile, $this->action);
113 function maxProfiles()
115 return PROFILES_PER_PAGE;
118 function avatarSize()
120 return AVATAR_STREAM_SIZE;
124 class ProfileListItem extends Widget
126 /** Current profile. */
128 /** Action object using us. */
131 function __construct($profile, $action)
133 parent::__construct($action);
135 $this->profile = $profile;
136 $this->action = $action;
141 if (Event::handle('StartProfileListItem', array($this))) {
143 if (Event::handle('StartProfileListItemProfile', array($this))) {
144 $this->showProfile();
145 Event::handle('EndProfileListItemProfile', array($this));
147 if (Event::handle('StartProfileListItemActions', array($this))) {
148 $this->showActions();
149 Event::handle('EndProfileListItemActions', array($this));
152 Event::handle('EndProfileListItem', array($this));
158 $this->out->elementStart('li', array('class' => 'profile hentry',
159 'id' => 'profile-' . $this->profile->id));
162 function showProfile()
164 $this->startProfile();
165 if (Event::handle('StartProfileListItemProfileElements', array($this))) {
166 if (Event::handle('StartProfileListItemAvatar', array($this))) {
168 Event::handle('EndProfileListItemAvatar', array($this));
170 if (Event::handle('StartProfileListItemFullName', array($this))) {
171 $this->showFullName();
172 Event::handle('EndProfileListItemFullName', array($this));
174 if (Event::handle('StartProfileListItemLocation', array($this))) {
175 $this->showLocation();
176 Event::handle('EndProfileListItemLocation', array($this));
178 if (Event::handle('StartProfileListItemHomepage', array($this))) {
179 $this->showHomepage();
180 Event::handle('EndProfileListItemHomepage', array($this));
182 if (Event::handle('StartProfileListItemBio', array($this))) {
184 Event::handle('EndProfileListItemBio', array($this));
186 if (Event::handle('StartProfileListItemTags', array($this))) {
188 Event::handle('EndProfileListItemTags', array($this));
190 Event::handle('EndProfileListItemProfileElements', array($this));
195 function startProfile()
197 $this->out->elementStart('div', 'entity_profile vcard entry-content');
200 function showAvatar()
202 $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
203 $aAttrs = $this->linkAttributes();
204 $this->out->elementStart('a', $aAttrs);
205 $this->out->element('img', array('src' => (!empty($avatar)) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
206 'class' => 'photo avatar',
207 'width' => AVATAR_STREAM_SIZE,
208 'height' => AVATAR_STREAM_SIZE,
210 ($this->profile->fullname) ? $this->profile->fullname :
211 $this->profile->nickname));
212 $this->out->text(' ');
213 $hasFN = (!empty($this->profile->fullname)) ? 'nickname' : 'fn nickname';
214 $this->out->elementStart('span', $hasFN);
215 $this->out->raw($this->highlight($this->profile->nickname));
216 $this->out->elementEnd('span');
217 $this->out->elementEnd('a');
220 function showFullName()
222 if (!empty($this->profile->fullname)) {
223 $this->out->text(' ');
224 $this->out->elementStart('span', 'fn');
225 $this->out->raw($this->highlight($this->profile->fullname));
226 $this->out->elementEnd('span');
230 function showLocation()
232 if (!empty($this->profile->location)) {
233 $this->out->text(' ');
234 $this->out->elementStart('span', 'label');
235 $this->out->raw($this->highlight($this->profile->location));
236 $this->out->elementEnd('span');
240 function showHomepage()
242 if (!empty($this->profile->homepage)) {
243 $this->out->text(' ');
244 $aAttrs = $this->homepageAttributes();
245 $this->out->elementStart('a', $aAttrs);
246 $this->out->raw($this->highlight($this->profile->homepage));
247 $this->out->elementEnd('a');
253 if (!empty($this->profile->bio)) {
254 $this->out->elementStart('p', 'note');
255 $this->out->raw($this->highlight($this->profile->bio));
256 $this->out->elementEnd('p');
262 $user = common_current_user();
264 if ($user->id == $this->profile->id) {
265 $tags = new SelftagsWidget($this->out, $user, $this->profile);
267 } else if ($user->getProfile()->canTag($this->profile)) {
268 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
274 function endProfile()
276 $this->out->elementEnd('div');
279 function showActions()
281 $this->startActions();
282 if (Event::handle('StartProfileListItemActionElements', array($this))) {
283 $this->showSubscribeButton();
284 Event::handle('EndProfileListItemActionElements', array($this));
289 function startActions()
291 $this->out->elementStart('div', 'entity_actions');
292 $this->out->elementStart('ul');
295 function showSubscribeButton()
297 // Is this a logged-in user, looking at someone else's
300 $user = common_current_user();
302 if (!empty($user) && $this->profile->id != $user->id) {
303 $this->out->elementStart('li', 'entity_subscribe');
304 if ($user->isSubscribed($this->profile)) {
305 $usf = new UnsubscribeForm($this->out, $this->profile);
308 if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
309 $sf = new SubscribeForm($this->out, $this->profile);
311 Event::handle('EndShowProfileListSubscribeButton', array($this));
314 $this->out->elementEnd('li');
318 function endActions()
320 $this->out->elementEnd('ul');
321 $this->out->elementEnd('div');
326 $this->out->elementEnd('li');
329 function highlight($text)
331 return htmlspecialchars($text);
334 function linkAttributes()
336 return array('href' => $this->profile->profileurl,
337 'class' => 'url entry-title',
341 function homepageAttributes()
343 return array('href' => $this->profile->homepage,