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/peopletags.php';
37 * Widget to show a list of profiles
41 * @author Zach Copley <zach@status.net>
42 * @author Evan Prodromou <evan@status.net>
43 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44 * @link http://status.net/
46 class ProfileList extends Widget
48 /** Current profile, profile query. */
50 /** Action object using us. */
53 function __construct($profile, $action=null)
55 parent::__construct($action);
57 $this->profile = $profile;
58 $this->action = $action;
65 if (Event::handle('StartProfileList', array($this))) {
67 $cnt = $this->showProfiles();
69 Event::handle('EndProfileList', array($this));
77 $this->out->elementStart('ul', 'profile_list xoxo');
82 $this->out->elementEnd('ul');
85 function showProfiles()
87 $cnt = $this->profile->N;
88 $profiles = $this->profile->fetchAll();
90 $max = min($cnt, $this->maxProfiles());
92 for ($i = 0; $i < $max; $i++) {
93 $pli = $this->newListItem($profiles[$i]);
100 function newListItem($profile)
102 return new ProfileListItem($profile, $this->action);
105 function maxProfiles()
107 return PROFILES_PER_PAGE;
111 class ProfileListItem extends Widget
113 /** Current profile. */
115 /** Action object using us. */
118 function __construct($profile, $action)
120 parent::__construct($action);
122 $this->profile = $profile;
123 $this->action = $action;
128 if (Event::handle('StartProfileListItem', array($this))) {
130 if (Event::handle('StartProfileListItemProfile', array($this))) {
131 $this->showProfile();
132 Event::handle('EndProfileListItemProfile', array($this));
134 if (Event::handle('StartProfileListItemActions', array($this))) {
135 $this->showActions();
136 Event::handle('EndProfileListItemActions', array($this));
139 Event::handle('EndProfileListItem', array($this));
145 $this->out->elementStart('li', array('class' => 'profile',
146 'id' => 'profile-' . $this->profile->id));
149 function showProfile()
151 $this->startProfile();
152 if (Event::handle('StartProfileListItemProfileElements', array($this))) {
153 if (Event::handle('StartProfileListItemAvatar', array($this))) {
154 $aAttrs = $this->linkAttributes();
155 $this->out->elementStart('a', $aAttrs);
156 $this->showAvatar($this->profile);
157 $this->out->elementEnd('a');
158 Event::handle('EndProfileListItemAvatar', array($this));
160 if (Event::handle('StartProfileListItemNickname', array($this))) {
161 $this->showNickname();
162 Event::handle('EndProfileListItemNickname', 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 h-card');
194 function showNickname()
196 $this->out->element('a', array('href'=>$this->profile->getUrl(),
197 'class'=>'p-nickname'),
198 $this->profile->getNickname());
201 function showFullName()
203 if (!empty($this->profile->fullname)) {
204 $this->out->element('span', 'p-name', $this->profile->fullname);
208 function showLocation()
210 if (!empty($this->profile->location)) {
211 $this->out->element('span', 'label p-locality', $this->profile->location);
215 function showHomepage()
217 if (!empty($this->profile->homepage)) {
218 $this->out->text(' ');
219 $aAttrs = $this->homepageAttributes();
220 $this->out->elementStart('a', $aAttrs);
221 $this->out->raw($this->highlight($this->profile->homepage));
222 $this->out->elementEnd('a');
228 if (!empty($this->profile->bio)) {
229 $this->out->elementStart('p', 'note');
230 $this->out->raw($this->highlight($this->profile->bio));
231 $this->out->elementEnd('p');
237 $user = common_current_user();
239 if ($user->id == $this->profile->id) {
240 $tags = new SelftagsWidget($this->out, $user, $this->profile);
242 } else if ($user->getProfile()->canTag($this->profile)) {
243 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
249 function endProfile()
251 $this->out->elementEnd('div');
254 function showActions()
256 $this->startActions();
257 if (Event::handle('StartProfileListItemActionElements', array($this))) {
258 $this->showSubscribeButton();
259 Event::handle('EndProfileListItemActionElements', array($this));
264 function startActions()
266 $this->out->elementStart('div', 'entity_actions');
267 $this->out->elementStart('ul');
270 function showSubscribeButton()
272 // Is this a logged-in user, looking at someone else's
275 $user = common_current_user();
277 if (!empty($user) && $this->profile->id != $user->id) {
278 $this->out->elementStart('li', 'entity_subscribe');
279 if ($user->isSubscribed($this->profile)) {
280 $usf = new UnsubscribeForm($this->out, $this->profile);
283 if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
284 $sf = new SubscribeForm($this->out, $this->profile);
286 Event::handle('EndShowProfileListSubscribeButton', array($this));
289 $this->out->elementEnd('li');
293 function endActions()
295 $this->out->elementEnd('ul');
296 $this->out->elementEnd('div');
301 $this->out->elementEnd('li');
304 function highlight($text)
306 return htmlspecialchars($text);
309 function linkAttributes()
311 return array('href' => $this->profile->profileurl,
316 function homepageAttributes()
318 return array('href' => $this->profile->homepage,