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';
37 define('MINILIST_PER_PAGE', 12);
40 * Widget to show a list of profiles
44 * @author Zach Copley <zach@status.net>
45 * @author Evan Prodromou <evan@status.net>
46 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47 * @link http://status.net/
49 class ProfileList extends Widget
51 /** Current profile, profile query. */
53 /** Action object using us. */
56 function __construct($profile, $action=null)
58 parent::__construct($action);
60 $this->profile = $profile;
61 $this->action = $action;
68 if (Event::handle('StartProfileList', array($this))) {
70 $cnt = $this->showProfiles();
72 Event::handle('EndProfileList', array($this));
80 $this->out->elementStart('ul', 'profiles xoxo');
85 $this->out->elementEnd('ul');
88 function showProfiles()
90 $cnt = $this->profile->N;
91 $profiles = $this->profile->fetchAll();
93 $max = min($cnt, $this->maxProfiles());
95 for ($i = 0; $i < $max; $i++) {
96 $pli = $this->newListItem($profiles[$i]);
103 function newListItem($profile)
105 return new ProfileListItem($profile, $this->action);
108 function maxProfiles()
110 return PROFILES_PER_PAGE;
113 function avatarSize()
115 return AVATAR_STREAM_SIZE;
119 class ProfileListItem extends Widget
121 /** Current profile. */
123 /** Action object using us. */
126 function __construct($profile, $action)
128 parent::__construct($action);
130 $this->profile = $profile;
131 $this->action = $action;
136 if (Event::handle('StartProfileListItem', array($this))) {
138 if (Event::handle('StartProfileListItemProfile', array($this))) {
139 $this->showProfile();
140 Event::handle('EndProfileListItemProfile', array($this));
142 if (Event::handle('StartProfileListItemActions', array($this))) {
143 $this->showActions();
144 Event::handle('EndProfileListItemActions', array($this));
147 Event::handle('EndProfileListItem', array($this));
153 $this->out->elementStart('li', array('class' => 'profile hentry',
154 'id' => 'profile-' . $this->profile->id));
157 function showProfile()
159 $this->startProfile();
160 if (Event::handle('StartProfileListItemProfileElements', array($this))) {
161 if (Event::handle('StartProfileListItemAvatar', array($this))) {
163 Event::handle('EndProfileListItemAvatar', array($this));
165 if (Event::handle('StartProfileListItemFullName', array($this))) {
166 $this->showFullName();
167 Event::handle('EndProfileListItemFullName', array($this));
169 if (Event::handle('StartProfileListItemLocation', array($this))) {
170 $this->showLocation();
171 Event::handle('EndProfileListItemLocation', array($this));
173 if (Event::handle('StartProfileListItemHomepage', array($this))) {
174 $this->showHomepage();
175 Event::handle('EndProfileListItemHomepage', array($this));
177 if (Event::handle('StartProfileListItemBio', array($this))) {
179 Event::handle('EndProfileListItemBio', array($this));
181 if (Event::handle('StartProfileListItemTags', array($this))) {
183 Event::handle('EndProfileListItemTags', array($this));
185 Event::handle('EndProfileListItemProfileElements', array($this));
190 function startProfile()
192 $this->out->elementStart('div', 'entity_profile vcard entry-content');
195 function showAvatar()
197 $avatarUrl = $this->profile->avatarUrl(AVATAR_STREAM_SIZE);
198 $aAttrs = $this->linkAttributes();
199 $this->out->elementStart('a', $aAttrs);
200 $this->out->element('img', array('src' => $avatarUrl,
201 'class' => 'photo avatar',
202 'width' => AVATAR_STREAM_SIZE,
203 'height' => AVATAR_STREAM_SIZE,
205 ($this->profile->fullname) ? $this->profile->fullname :
206 $this->profile->nickname));
207 $this->out->text(' ');
208 $hasFN = (!empty($this->profile->fullname)) ? 'nickname' : 'fn nickname';
209 $this->out->elementStart('span', $hasFN);
210 $this->out->raw($this->highlight($this->profile->nickname));
211 $this->out->elementEnd('span');
212 $this->out->elementEnd('a');
215 function showFullName()
217 if (!empty($this->profile->fullname)) {
218 $this->out->text(' ');
219 $this->out->elementStart('span', 'fn');
220 $this->out->raw($this->highlight($this->profile->fullname));
221 $this->out->elementEnd('span');
225 function showLocation()
227 if (!empty($this->profile->location)) {
228 $this->out->text(' ');
229 $this->out->elementStart('span', 'label');
230 $this->out->raw($this->highlight($this->profile->location));
231 $this->out->elementEnd('span');
235 function showHomepage()
237 if (!empty($this->profile->homepage)) {
238 $this->out->text(' ');
239 $aAttrs = $this->homepageAttributes();
240 $this->out->elementStart('a', $aAttrs);
241 $this->out->raw($this->highlight($this->profile->homepage));
242 $this->out->elementEnd('a');
248 if (!empty($this->profile->bio)) {
249 $this->out->elementStart('p', 'note');
250 $this->out->raw($this->highlight($this->profile->bio));
251 $this->out->elementEnd('p');
257 $user = common_current_user();
259 if ($user->id == $this->profile->id) {
260 $tags = new SelftagsWidget($this->out, $user, $this->profile);
262 } else if ($user->getProfile()->canTag($this->profile)) {
263 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
269 function endProfile()
271 $this->out->elementEnd('div');
274 function showActions()
276 $this->startActions();
277 if (Event::handle('StartProfileListItemActionElements', array($this))) {
278 $this->showSubscribeButton();
279 Event::handle('EndProfileListItemActionElements', array($this));
284 function startActions()
286 $this->out->elementStart('div', 'entity_actions');
287 $this->out->elementStart('ul');
290 function showSubscribeButton()
292 // Is this a logged-in user, looking at someone else's
295 $user = common_current_user();
297 if (!empty($user) && $this->profile->id != $user->id) {
298 $this->out->elementStart('li', 'entity_subscribe');
299 if ($user->isSubscribed($this->profile)) {
300 $usf = new UnsubscribeForm($this->out, $this->profile);
303 if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
304 $sf = new SubscribeForm($this->out, $this->profile);
306 Event::handle('EndShowProfileListSubscribeButton', array($this));
309 $this->out->elementEnd('li');
313 function endActions()
315 $this->out->elementEnd('ul');
316 $this->out->elementEnd('div');
321 $this->out->elementEnd('li');
324 function highlight($text)
326 return htmlspecialchars($text);
329 function linkAttributes()
331 return array('href' => $this->profile->profileurl,
332 'class' => 'url entry-title',
336 function homepageAttributes()
338 return array('href' => $this->profile->homepage,