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';
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/
48 class ProfileList extends Widget
50 /** Current profile, profile query. */
52 /** Action object using us. */
55 function __construct($profile, $action=null)
57 parent::__construct($action);
59 $this->profile = $profile;
60 $this->action = $action;
67 if (Event::handle('StartProfileList', array($this))) {
69 $cnt = $this->showProfiles();
71 Event::handle('EndProfileList', array($this));
79 $this->out->elementStart('ul', 'profiles');
84 $this->out->elementEnd('ul');
87 function showProfiles()
91 while ($this->profile->fetch()) {
93 if($cnt > PROFILES_PER_PAGE) {
96 $pli = $this->newListItem($this->profile);
103 function newListItem($profile)
105 return new ProfileListItem($this->profile, $this->action);
109 class ProfileListItem extends Widget
111 /** Current profile. */
113 /** Action object using us. */
116 function __construct($profile, $action)
118 parent::__construct($action);
120 $this->profile = $profile;
121 $this->action = $action;
126 if (Event::handle('StartProfileListItem', array($this))) {
128 if (Event::handle('StartProfileListItemProfile', array($this))) {
129 $this->showProfile();
130 Event::handle('EndProfileListItemProfile', array($this));
132 if (Event::handle('StartProfileListItemActions', array($this))) {
133 $this->showActions();
134 Event::handle('EndProfileListItemActions', array($this));
137 Event::handle('EndProfileListItem', array($this));
143 $this->out->elementStart('li', array('class' => 'profile',
144 'id' => 'profile-' . $this->profile->id));
147 function showProfile()
149 $this->startProfile();
150 if (Event::handle('StartProfileListItemProfileElements', array($this))) {
151 if (Event::handle('StartProfileListItemAvatar', array($this))) {
153 Event::handle('EndProfileListItemAvatar', array($this));
155 if (Event::handle('StartProfileListItemFullName', array($this))) {
156 $this->showFullName();
157 Event::handle('EndProfileListItemFullName', array($this));
159 if (Event::handle('StartProfileListItemLocation', array($this))) {
160 $this->showLocation();
161 Event::handle('EndProfileListItemLocation', array($this));
163 if (Event::handle('StartProfileListItemHomepage', array($this))) {
164 $this->showHomepage();
165 Event::handle('EndProfileListItemHomepage', array($this));
167 if (Event::handle('StartProfileListItemBio', array($this))) {
169 Event::handle('EndProfileListItemBio', array($this));
171 Event::handle('EndProfileListItemProfileElements', array($this));
176 function startProfile()
178 $this->out->elementStart('div', 'entity_profile vcard');
181 function showAvatar()
183 $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
184 $this->out->elementStart('a', array('href' => $this->profile->profileurl,
186 $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
187 'class' => 'photo avatar',
188 'width' => AVATAR_STREAM_SIZE,
189 'height' => AVATAR_STREAM_SIZE,
191 ($this->profile->fullname) ? $this->profile->fullname :
192 $this->profile->nickname));
193 $hasFN = ($this->profile->fullname !== '') ? 'nickname' : 'fn nickname';
194 $this->out->elementStart('span', $hasFN);
195 $this->out->raw($this->highlight($this->profile->nickname));
196 $this->out->elementEnd('span');
197 $this->out->elementEnd('a');
200 function showFullName()
202 if (!empty($this->profile->fullname)) {
203 $this->out->elementStart('dl', 'entity_fn');
204 $this->out->element('dt', null, 'Full name');
205 $this->out->elementStart('dd');
206 $this->out->elementStart('span', 'fn');
207 $this->out->raw($this->highlight($this->profile->fullname));
208 $this->out->elementEnd('span');
209 $this->out->elementEnd('dd');
210 $this->out->elementEnd('dl');
214 function showLocation()
216 if (!empty($this->profile->location)) {
217 $this->out->elementStart('dl', 'entity_location');
218 $this->out->element('dt', null, _('Location'));
219 $this->out->elementStart('dd', 'label');
220 $this->out->raw($this->highlight($this->profile->location));
221 $this->out->elementEnd('dd');
222 $this->out->elementEnd('dl');
226 function showHomepage()
228 if (!empty($this->profile->homepage)) {
229 $this->out->elementStart('dl', 'entity_url');
230 $this->out->element('dt', null, _('URL'));
231 $this->out->elementStart('dd');
232 $this->out->elementStart('a', array('href' => $this->profile->homepage,
234 $this->out->raw($this->highlight($this->profile->homepage));
235 $this->out->elementEnd('a');
236 $this->out->elementEnd('dd');
237 $this->out->elementEnd('dl');
243 if (!empty($this->profile->bio)) {
244 $this->out->elementStart('dl', 'entity_note');
245 $this->out->element('dt', null, _('Note'));
246 $this->out->elementStart('dd', 'note');
247 $this->out->raw($this->highlight($this->profile->bio));
248 $this->out->elementEnd('dd');
249 $this->out->elementEnd('dl');
253 function endProfile()
255 $this->out->elementEnd('div');
258 function showActions()
260 $this->startActions();
261 if (Event::handle('StartProfileListItemActionElements', array($this))) {
262 $this->showSubscribeButton();
263 Event::handle('EndProfileListItemActionElements', array($this));
268 function startActions()
270 $this->out->elementStart('div', 'entity_actions');
271 $this->out->elementStart('ul');
274 function showSubscribeButton()
276 // Is this a logged-in user, looking at someone else's
279 $user = common_current_user();
281 if (!empty($user) && $this->profile->id != $user->id) {
282 $this->out->elementStart('li', 'entity_subscribe');
283 if ($user->isSubscribed($this->profile)) {
284 $usf = new UnsubscribeForm($this->out, $this->profile);
287 // Is it a local user? can't remote sub from a list
288 // XXX: make that possible!
289 $other = User::staticGet('id', $this->profile->id);
290 if (!empty($other)) {
291 $sf = new SubscribeForm($this->out, $this->profile);
295 $this->out->elementEnd('li');
299 function endActions()
301 $this->out->elementEnd('ul');
302 $this->out->elementEnd('div');
307 $this->out->elementEnd('li');
310 function highlight($text)
312 return htmlspecialchars($text);