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 $cnt = $this->profile->N;
89 $profiles = $this->profile->fetchAll();
91 $max = min($cnt, $this->maxProfiles());
93 for ($i = 0; $i < $max; $i++) {
94 $pli = $this->newListItem($profiles[$i]);
101 function newListItem($profile)
103 return new ProfileListItem($profile, $this->action);
106 function maxProfiles()
108 return PROFILES_PER_PAGE;
111 function avatarSize()
113 return AVATAR_STREAM_SIZE;
117 class ProfileListItem extends Widget
119 /** Current profile. */
121 /** Action object using us. */
124 function __construct($profile, $action)
126 parent::__construct($action);
128 $this->profile = $profile;
129 $this->action = $action;
134 if (Event::handle('StartProfileListItem', array($this))) {
136 if (Event::handle('StartProfileListItemProfile', array($this))) {
137 $this->showProfile();
138 Event::handle('EndProfileListItemProfile', array($this));
140 if (Event::handle('StartProfileListItemActions', array($this))) {
141 $this->showActions();
142 Event::handle('EndProfileListItemActions', array($this));
145 Event::handle('EndProfileListItem', array($this));
151 $this->out->elementStart('li', array('class' => 'profile hentry',
152 'id' => 'profile-' . $this->profile->id));
155 function showProfile()
157 $this->startProfile();
158 if (Event::handle('StartProfileListItemProfileElements', array($this))) {
159 if (Event::handle('StartProfileListItemAvatar', array($this))) {
161 Event::handle('EndProfileListItemAvatar', array($this));
163 if (Event::handle('StartProfileListItemFullName', array($this))) {
164 $this->showFullName();
165 Event::handle('EndProfileListItemFullName', array($this));
167 if (Event::handle('StartProfileListItemLocation', array($this))) {
168 $this->showLocation();
169 Event::handle('EndProfileListItemLocation', array($this));
171 if (Event::handle('StartProfileListItemHomepage', array($this))) {
172 $this->showHomepage();
173 Event::handle('EndProfileListItemHomepage', array($this));
175 if (Event::handle('StartProfileListItemBio', array($this))) {
177 Event::handle('EndProfileListItemBio', array($this));
179 if (Event::handle('StartProfileListItemTags', array($this))) {
181 Event::handle('EndProfileListItemTags', array($this));
183 Event::handle('EndProfileListItemProfileElements', array($this));
188 function startProfile()
190 $this->out->elementStart('div', 'entity_profile vcard entry-content');
193 function showAvatar()
195 $avatarUrl = $this->profile->avatarUrl(AVATAR_STREAM_SIZE);
196 $aAttrs = $this->linkAttributes();
197 $this->out->elementStart('a', $aAttrs);
198 $this->out->element('img', array('src' => $avatarUrl,
199 'class' => 'photo avatar',
200 'width' => AVATAR_STREAM_SIZE,
201 'height' => AVATAR_STREAM_SIZE,
203 ($this->profile->fullname) ? $this->profile->fullname :
204 $this->profile->nickname));
205 $this->out->text(' ');
206 $hasFN = (!empty($this->profile->fullname)) ? 'nickname' : 'fn nickname';
207 $this->out->elementStart('span', $hasFN);
208 $this->out->raw($this->highlight($this->profile->nickname));
209 $this->out->elementEnd('span');
210 $this->out->elementEnd('a');
213 function showFullName()
215 if (!empty($this->profile->fullname)) {
216 $this->out->text(' ');
217 $this->out->elementStart('span', 'fn');
218 $this->out->raw($this->highlight($this->profile->fullname));
219 $this->out->elementEnd('span');
223 function showLocation()
225 if (!empty($this->profile->location)) {
226 $this->out->text(' ');
227 $this->out->elementStart('span', 'label');
228 $this->out->raw($this->highlight($this->profile->location));
229 $this->out->elementEnd('span');
233 function showHomepage()
235 if (!empty($this->profile->homepage)) {
236 $this->out->text(' ');
237 $aAttrs = $this->homepageAttributes();
238 $this->out->elementStart('a', $aAttrs);
239 $this->out->raw($this->highlight($this->profile->homepage));
240 $this->out->elementEnd('a');
246 if (!empty($this->profile->bio)) {
247 $this->out->elementStart('p', 'note');
248 $this->out->raw($this->highlight($this->profile->bio));
249 $this->out->elementEnd('p');
255 $user = common_current_user();
257 if ($user->id == $this->profile->id) {
258 $tags = new SelftagsWidget($this->out, $user, $this->profile);
260 } else if ($user->getProfile()->canTag($this->profile)) {
261 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
267 function endProfile()
269 $this->out->elementEnd('div');
272 function showActions()
274 $this->startActions();
275 if (Event::handle('StartProfileListItemActionElements', array($this))) {
276 $this->showSubscribeButton();
277 Event::handle('EndProfileListItemActionElements', array($this));
282 function startActions()
284 $this->out->elementStart('div', 'entity_actions');
285 $this->out->elementStart('ul');
288 function showSubscribeButton()
290 // Is this a logged-in user, looking at someone else's
293 $user = common_current_user();
295 if (!empty($user) && $this->profile->id != $user->id) {
296 $this->out->elementStart('li', 'entity_subscribe');
297 if ($user->isSubscribed($this->profile)) {
298 $usf = new UnsubscribeForm($this->out, $this->profile);
301 if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
302 $sf = new SubscribeForm($this->out, $this->profile);
304 Event::handle('EndShowProfileListSubscribeButton', array($this));
307 $this->out->elementEnd('li');
311 function endActions()
313 $this->out->elementEnd('ul');
314 $this->out->elementEnd('div');
319 $this->out->elementEnd('li');
322 function highlight($text)
324 return htmlspecialchars($text);
327 function linkAttributes()
329 return array('href' => $this->profile->profileurl,
330 'class' => 'url entry-title',
334 function homepageAttributes()
336 return array('href' => $this->profile->homepage,