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 $profiles = $this->profile->fetchAll();
90 $cnt = count($profiles);
92 $max = min($cnt, $this->maxProfiles());
94 for ($i = 0; $i < $max; $i++) {
95 $pli = $this->newListItem($profiles[$i]);
102 function newListItem($profile)
104 return new ProfileListItem($profile, $this->action);
107 function maxProfiles()
109 return PROFILES_PER_PAGE;
112 function avatarSize()
114 return AVATAR_STREAM_SIZE;
118 class ProfileListItem extends Widget
120 /** Current profile. */
122 /** Action object using us. */
125 function __construct($profile, $action)
127 parent::__construct($action);
129 $this->profile = $profile;
130 $this->action = $action;
135 if (Event::handle('StartProfileListItem', array($this))) {
137 if (Event::handle('StartProfileListItemProfile', array($this))) {
138 $this->showProfile();
139 Event::handle('EndProfileListItemProfile', array($this));
141 if (Event::handle('StartProfileListItemActions', array($this))) {
142 $this->showActions();
143 Event::handle('EndProfileListItemActions', array($this));
146 Event::handle('EndProfileListItem', array($this));
152 $this->out->elementStart('li', array('class' => 'profile hentry',
153 'id' => 'profile-' . $this->profile->id));
156 function showProfile()
158 $this->startProfile();
159 if (Event::handle('StartProfileListItemProfileElements', array($this))) {
160 if (Event::handle('StartProfileListItemAvatar', array($this))) {
162 Event::handle('EndProfileListItemAvatar', array($this));
164 if (Event::handle('StartProfileListItemFullName', array($this))) {
165 $this->showFullName();
166 Event::handle('EndProfileListItemFullName', array($this));
168 if (Event::handle('StartProfileListItemLocation', array($this))) {
169 $this->showLocation();
170 Event::handle('EndProfileListItemLocation', array($this));
172 if (Event::handle('StartProfileListItemHomepage', array($this))) {
173 $this->showHomepage();
174 Event::handle('EndProfileListItemHomepage', array($this));
176 if (Event::handle('StartProfileListItemBio', array($this))) {
178 Event::handle('EndProfileListItemBio', array($this));
180 if (Event::handle('StartProfileListItemTags', array($this))) {
182 Event::handle('EndProfileListItemTags', array($this));
184 Event::handle('EndProfileListItemProfileElements', array($this));
189 function startProfile()
191 $this->out->elementStart('div', 'entity_profile vcard entry-content');
194 function showAvatar()
196 $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
197 $aAttrs = $this->linkAttributes();
198 $this->out->elementStart('a', $aAttrs);
199 $this->out->element('img', array('src' => (!empty($avatar)) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
200 'class' => 'photo avatar',
201 'width' => AVATAR_STREAM_SIZE,
202 'height' => AVATAR_STREAM_SIZE,
204 ($this->profile->fullname) ? $this->profile->fullname :
205 $this->profile->nickname));
206 $this->out->text(' ');
207 $hasFN = (!empty($this->profile->fullname)) ? 'nickname' : 'fn nickname';
208 $this->out->elementStart('span', $hasFN);
209 $this->out->raw($this->highlight($this->profile->nickname));
210 $this->out->elementEnd('span');
211 $this->out->elementEnd('a');
214 function showFullName()
216 if (!empty($this->profile->fullname)) {
217 $this->out->text(' ');
218 $this->out->elementStart('span', 'fn');
219 $this->out->raw($this->highlight($this->profile->fullname));
220 $this->out->elementEnd('span');
224 function showLocation()
226 if (!empty($this->profile->location)) {
227 $this->out->text(' ');
228 $this->out->elementStart('span', 'label');
229 $this->out->raw($this->highlight($this->profile->location));
230 $this->out->elementEnd('span');
234 function showHomepage()
236 if (!empty($this->profile->homepage)) {
237 $this->out->text(' ');
238 $aAttrs = $this->homepageAttributes();
239 $this->out->elementStart('a', $aAttrs);
240 $this->out->raw($this->highlight($this->profile->homepage));
241 $this->out->elementEnd('a');
247 if (!empty($this->profile->bio)) {
248 $this->out->elementStart('p', 'note');
249 $this->out->raw($this->highlight($this->profile->bio));
250 $this->out->elementEnd('p');
256 $user = common_current_user();
258 if ($user->id == $this->profile->id) {
259 $tags = new SelftagsWidget($this->out, $user, $this->profile);
261 } else if ($user->getProfile()->canTag($this->profile)) {
262 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
268 function endProfile()
270 $this->out->elementEnd('div');
273 function showActions()
275 $this->startActions();
276 if (Event::handle('StartProfileListItemActionElements', array($this))) {
277 $this->showSubscribeButton();
278 Event::handle('EndProfileListItemActionElements', array($this));
283 function startActions()
285 $this->out->elementStart('div', 'entity_actions');
286 $this->out->elementStart('ul');
289 function showSubscribeButton()
291 // Is this a logged-in user, looking at someone else's
294 $user = common_current_user();
296 if (!empty($user) && $this->profile->id != $user->id) {
297 $this->out->elementStart('li', 'entity_subscribe');
298 if ($user->isSubscribed($this->profile)) {
299 $usf = new UnsubscribeForm($this->out, $this->profile);
302 if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
303 $sf = new SubscribeForm($this->out, $this->profile);
305 Event::handle('EndShowProfileListSubscribeButton', array($this));
308 $this->out->elementEnd('li');
312 function endActions()
314 $this->out->elementEnd('ul');
315 $this->out->elementEnd('div');
320 $this->out->elementEnd('li');
323 function highlight($text)
325 return htmlspecialchars($text);
328 function linkAttributes()
330 return array('href' => $this->profile->profileurl,
331 'class' => 'url entry-title',
335 function homepageAttributes()
337 return array('href' => $this->profile->homepage,