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', 'profiles 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 hentry',
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);
157 $this->out->elementEnd('a');
158 Event::handle('EndProfileListItemAvatar', array($this));
160 if (Event::handle('StartProfileListItemFullName', array($this))) {
161 $this->showFullName();
162 Event::handle('EndProfileListItemFullName', array($this));
164 if (Event::handle('StartProfileListItemLocation', array($this))) {
165 $this->showLocation();
166 Event::handle('EndProfileListItemLocation', array($this));
168 if (Event::handle('StartProfileListItemHomepage', array($this))) {
169 $this->showHomepage();
170 Event::handle('EndProfileListItemHomepage', array($this));
172 if (Event::handle('StartProfileListItemBio', array($this))) {
174 Event::handle('EndProfileListItemBio', array($this));
176 if (Event::handle('StartProfileListItemTags', array($this))) {
178 Event::handle('EndProfileListItemTags', array($this));
180 Event::handle('EndProfileListItemProfileElements', array($this));
185 function startProfile()
187 $this->out->elementStart('div', 'entity_profile vcard entry-content');
190 function showFullName()
192 if (!empty($this->profile->fullname)) {
193 $this->out->text(' ');
194 $this->out->elementStart('span', 'fn');
195 $this->out->raw($this->highlight($this->profile->fullname));
196 $this->out->elementEnd('span');
200 function showLocation()
202 if (!empty($this->profile->location)) {
203 $this->out->text(' ');
204 $this->out->elementStart('span', 'label');
205 $this->out->raw($this->highlight($this->profile->location));
206 $this->out->elementEnd('span');
210 function showHomepage()
212 if (!empty($this->profile->homepage)) {
213 $this->out->text(' ');
214 $aAttrs = $this->homepageAttributes();
215 $this->out->elementStart('a', $aAttrs);
216 $this->out->raw($this->highlight($this->profile->homepage));
217 $this->out->elementEnd('a');
223 if (!empty($this->profile->bio)) {
224 $this->out->elementStart('p', 'note');
225 $this->out->raw($this->highlight($this->profile->bio));
226 $this->out->elementEnd('p');
232 $user = common_current_user();
234 if ($user->id == $this->profile->id) {
235 $tags = new SelftagsWidget($this->out, $user, $this->profile);
237 } else if ($user->getProfile()->canTag($this->profile)) {
238 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
244 function endProfile()
246 $this->out->elementEnd('div');
249 function showActions()
251 $this->startActions();
252 if (Event::handle('StartProfileListItemActionElements', array($this))) {
253 $this->showSubscribeButton();
254 Event::handle('EndProfileListItemActionElements', array($this));
259 function startActions()
261 $this->out->elementStart('div', 'entity_actions');
262 $this->out->elementStart('ul');
265 function showSubscribeButton()
267 // Is this a logged-in user, looking at someone else's
270 $user = common_current_user();
272 if (!empty($user) && $this->profile->id != $user->id) {
273 $this->out->elementStart('li', 'entity_subscribe');
274 if ($user->isSubscribed($this->profile)) {
275 $usf = new UnsubscribeForm($this->out, $this->profile);
278 if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
279 $sf = new SubscribeForm($this->out, $this->profile);
281 Event::handle('EndShowProfileListSubscribeButton', array($this));
284 $this->out->elementEnd('li');
288 function endActions()
290 $this->out->elementEnd('ul');
291 $this->out->elementEnd('div');
296 $this->out->elementEnd('li');
299 function highlight($text)
301 return htmlspecialchars($text);
304 function linkAttributes()
306 return array('href' => $this->profile->profileurl,
307 'class' => 'url entry-title',
311 function homepageAttributes()
313 return array('href' => $this->profile->homepage,