4 * StatusNet, the distributed open-source microblogging tool
6 * Widget to show a list of profiles
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';
36 require_once INSTALLDIR.'/lib/peopletags.php';
39 * Widget to show a list of profiles
43 * @author Zach Copley <zach@status.net>
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 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()
92 while ($this->profile->fetch()) {
94 if($cnt > PROFILES_PER_PAGE) {
97 $pli = $this->newListItem($this->profile);
104 function newListItem($profile)
106 return new ProfileListItem($this->profile, $this->action);
110 class ProfileListItem extends Widget
112 /** Current profile. */
114 /** Action object using us. */
117 function __construct($profile, $action)
119 parent::__construct($action);
121 $this->profile = $profile;
122 $this->action = $action;
127 if (Event::handle('StartProfileListItem', array($this))) {
129 if (Event::handle('StartProfileListItemProfile', array($this))) {
130 $this->showProfile();
131 Event::handle('EndProfileListItemProfile', array($this));
133 if (Event::handle('StartProfileListItemActions', array($this))) {
134 $this->showActions();
135 Event::handle('EndProfileListItemActions', array($this));
138 Event::handle('EndProfileListItem', array($this));
144 $this->out->elementStart('li', array('class' => 'profile hentry',
145 'id' => 'profile-' . $this->profile->id));
148 function showProfile()
150 $this->startProfile();
151 if (Event::handle('StartProfileListItemProfileElements', array($this))) {
152 if (Event::handle('StartProfileListItemAvatar', array($this))) {
154 Event::handle('EndProfileListItemAvatar', array($this));
156 if (Event::handle('StartProfileListItemFullName', array($this))) {
157 $this->showFullName();
158 Event::handle('EndProfileListItemFullName', array($this));
160 if (Event::handle('StartProfileListItemLocation', array($this))) {
161 $this->showLocation();
162 Event::handle('EndProfileListItemLocation', array($this));
164 if (Event::handle('StartProfileListItemHomepage', array($this))) {
165 $this->showHomepage();
166 Event::handle('EndProfileListItemHomepage', array($this));
168 if (Event::handle('StartProfileListItemBio', array($this))) {
170 Event::handle('EndProfileListItemBio', array($this));
172 if (Event::handle('StartProfileListItemTags', array($this))) {
174 Event::handle('EndProfileListItemTags', array($this));
176 Event::handle('EndProfileListItemProfileElements', array($this));
181 function startProfile()
183 $this->out->elementStart('div', 'entity_profile vcard entry-content');
186 function showAvatar()
188 $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
189 $aAttrs = $this->linkAttributes();
190 $this->out->elementStart('a', $aAttrs);
191 $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
192 'class' => 'photo avatar',
193 'width' => AVATAR_STREAM_SIZE,
194 'height' => AVATAR_STREAM_SIZE,
196 ($this->profile->fullname) ? $this->profile->fullname :
197 $this->profile->nickname));
198 $this->out->text(' ');
199 $hasFN = (!empty($this->profile->fullname)) ? 'nickname' : 'fn nickname';
200 $this->out->elementStart('span', $hasFN);
201 $this->out->raw($this->highlight($this->profile->nickname));
202 $this->out->elementEnd('span');
203 $this->out->elementEnd('a');
206 function showFullName()
208 if (!empty($this->profile->fullname)) {
209 $this->out->text(' ');
210 $this->out->elementStart('span', 'fn');
211 $this->out->raw($this->highlight($this->profile->fullname));
212 $this->out->elementEnd('span');
216 function showLocation()
218 if (!empty($this->profile->location)) {
219 $this->out->text(' ');
220 $this->out->elementStart('span', 'label');
221 $this->out->raw($this->highlight($this->profile->location));
222 $this->out->elementEnd('span');
226 function showHomepage()
228 if (!empty($this->profile->homepage)) {
229 $this->out->text(' ');
230 $aAttrs = $this->homepageAttributes();
231 $this->out->elementStart('a', $aAttrs);
232 $this->out->raw($this->highlight($this->profile->homepage));
233 $this->out->elementEnd('a');
239 if (!empty($this->profile->bio)) {
240 $this->out->elementStart('p', 'note');
241 $this->out->raw($this->highlight($this->profile->bio));
242 $this->out->elementEnd('p');
248 $user = common_current_user();
250 if ($user->id == $this->profile->id) {
251 $tags = new SelftagsWidget($this->out, $user, $this->profile);
253 } else if ($user->getProfile()->canTag($this->profile)) {
254 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
260 function endProfile()
262 $this->out->elementEnd('div');
265 function showActions()
267 $this->startActions();
268 if (Event::handle('StartProfileListItemActionElements', array($this))) {
269 $this->showSubscribeButton();
270 Event::handle('EndProfileListItemActionElements', array($this));
275 function startActions()
277 $this->out->elementStart('div', 'entity_actions');
278 $this->out->elementStart('ul');
281 function showSubscribeButton()
283 // Is this a logged-in user, looking at someone else's
286 $user = common_current_user();
288 if (!empty($user) && $this->profile->id != $user->id) {
289 $this->out->elementStart('li', 'entity_subscribe');
290 if ($user->isSubscribed($this->profile)) {
291 $usf = new UnsubscribeForm($this->out, $this->profile);
294 // We can't initiate sub for a remote OMB profile.
295 $remote = Remote_profile::staticGet('id', $this->profile->id);
296 if (empty($remote)) {
297 $sf = new SubscribeForm($this->out, $this->profile);
301 $this->out->elementEnd('li');
305 function endActions()
307 $this->out->elementEnd('ul');
308 $this->out->elementEnd('div');
313 $this->out->elementEnd('li');
316 function highlight($text)
318 return htmlspecialchars($text);
321 function linkAttributes()
323 return array('href' => $this->profile->profileurl,
324 'class' => 'url entry-title',
328 function homepageAttributes()
330 return array('href' => $this->profile->homepage,