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()
90 while ($this->profile->fetch()) {
92 if($cnt > PROFILES_PER_PAGE) {
95 $pli = $this->newListItem($this->profile);
102 function newListItem($profile)
104 return new ProfileListItem($this->profile, $this->action);
108 class ProfileListItem extends Widget
110 /** Current profile. */
112 /** Action object using us. */
115 function __construct($profile, $action)
117 parent::__construct($action);
119 $this->profile = $profile;
120 $this->action = $action;
125 if (Event::handle('StartProfileListItem', array($this))) {
127 if (Event::handle('StartProfileListItemProfile', array($this))) {
128 $this->showProfile();
129 Event::handle('EndProfileListItemProfile', array($this));
131 if (Event::handle('StartProfileListItemActions', array($this))) {
132 $this->showActions();
133 Event::handle('EndProfileListItemActions', array($this));
136 Event::handle('EndProfileListItem', array($this));
142 $this->out->elementStart('li', array('class' => 'profile hentry',
143 'id' => 'profile-' . $this->profile->id));
146 function showProfile()
148 $this->startProfile();
149 if (Event::handle('StartProfileListItemProfileElements', array($this))) {
150 if (Event::handle('StartProfileListItemAvatar', array($this))) {
152 Event::handle('EndProfileListItemAvatar', array($this));
154 if (Event::handle('StartProfileListItemFullName', array($this))) {
155 $this->showFullName();
156 Event::handle('EndProfileListItemFullName', array($this));
158 if (Event::handle('StartProfileListItemLocation', array($this))) {
159 $this->showLocation();
160 Event::handle('EndProfileListItemLocation', array($this));
162 if (Event::handle('StartProfileListItemHomepage', array($this))) {
163 $this->showHomepage();
164 Event::handle('EndProfileListItemHomepage', array($this));
166 if (Event::handle('StartProfileListItemBio', array($this))) {
168 Event::handle('EndProfileListItemBio', array($this));
170 if (Event::handle('StartProfileListItemTags', array($this))) {
172 Event::handle('EndProfileListItemTags', array($this));
174 Event::handle('EndProfileListItemProfileElements', array($this));
179 function startProfile()
181 $this->out->elementStart('div', 'entity_profile vcard entry-content');
184 function showAvatar()
186 $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
187 $aAttrs = $this->linkAttributes();
188 $this->out->elementStart('a', $aAttrs);
189 $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
190 'class' => 'photo avatar',
191 'width' => AVATAR_STREAM_SIZE,
192 'height' => AVATAR_STREAM_SIZE,
194 ($this->profile->fullname) ? $this->profile->fullname :
195 $this->profile->nickname));
196 $this->out->text(' ');
197 $hasFN = (!empty($this->profile->fullname)) ? 'nickname' : 'fn nickname';
198 $this->out->elementStart('span', $hasFN);
199 $this->out->raw($this->highlight($this->profile->nickname));
200 $this->out->elementEnd('span');
201 $this->out->elementEnd('a');
204 function showFullName()
206 if (!empty($this->profile->fullname)) {
207 $this->out->text(' ');
208 $this->out->elementStart('span', 'fn');
209 $this->out->raw($this->highlight($this->profile->fullname));
210 $this->out->elementEnd('span');
214 function showLocation()
216 if (!empty($this->profile->location)) {
217 $this->out->text(' ');
218 $this->out->elementStart('span', 'label');
219 $this->out->raw($this->highlight($this->profile->location));
220 $this->out->elementEnd('span');
224 function showHomepage()
226 if (!empty($this->profile->homepage)) {
227 $this->out->text(' ');
228 $aAttrs = $this->homepageAttributes();
229 $this->out->elementStart('a', $aAttrs);
230 $this->out->raw($this->highlight($this->profile->homepage));
231 $this->out->elementEnd('a');
237 if (!empty($this->profile->bio)) {
238 $this->out->elementStart('p', 'note');
239 $this->out->raw($this->highlight($this->profile->bio));
240 $this->out->elementEnd('p');
246 $user = common_current_user();
248 if ($user->id == $this->profile->id) {
249 $tags = new SelftagsWidget($this->out, $user, $this->profile);
251 } else if ($user->getProfile()->canTag($this->profile)) {
252 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
258 function endProfile()
260 $this->out->elementEnd('div');
263 function showActions()
265 $this->startActions();
266 if (Event::handle('StartProfileListItemActionElements', array($this))) {
267 $this->showSubscribeButton();
268 Event::handle('EndProfileListItemActionElements', array($this));
273 function startActions()
275 $this->out->elementStart('div', 'entity_actions');
276 $this->out->elementStart('ul');
279 function showSubscribeButton()
281 // Is this a logged-in user, looking at someone else's
284 $user = common_current_user();
286 if (!empty($user) && $this->profile->id != $user->id) {
287 $this->out->elementStart('li', 'entity_subscribe');
288 if ($user->isSubscribed($this->profile)) {
289 $usf = new UnsubscribeForm($this->out, $this->profile);
292 // We can't initiate sub for a remote OMB profile.
293 $remote = Remote_profile::staticGet('id', $this->profile->id);
294 if (empty($remote)) {
295 $sf = new SubscribeForm($this->out, $this->profile);
299 $this->out->elementEnd('li');
303 function endActions()
305 $this->out->elementEnd('ul');
306 $this->out->elementEnd('div');
311 $this->out->elementEnd('li');
314 function highlight($text)
316 return htmlspecialchars($text);
319 function linkAttributes()
321 return array('href' => $this->profile->profileurl,
322 'class' => 'url entry-title',
326 function homepageAttributes()
328 return array('href' => $this->profile->homepage,