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 xoxo');
84 $this->out->elementEnd('ul');
87 function showProfiles()
89 $log = strtolower(get_class($this)) == 'subscriberslist' && $this->owner->nickname == 'petercook';
92 if ($log) common_log(LOG_INFO, "subbug: starting with {$this->profile->N}");
93 while ($this->profile->fetch()) {
95 if($cnt > PROFILES_PER_PAGE) {
96 if ($log) common_log(LOG_INFO, "subbug: breaking at $cnt");
99 if ($log) common_log(LOG_INFO, "subbug: showing at $cnt");
100 $pli = $this->newListItem($this->profile);
103 if ($log) common_log(LOG_INFO, "subbug: ended at $cnt");
108 function newListItem($profile)
110 return new ProfileListItem($this->profile, $this->action);
114 class ProfileListItem extends Widget
116 /** Current profile. */
118 /** Action object using us. */
121 function __construct($profile, $action)
123 parent::__construct($action);
125 $this->profile = $profile;
126 $this->action = $action;
131 if (Event::handle('StartProfileListItem', array($this))) {
133 if (Event::handle('StartProfileListItemProfile', array($this))) {
134 $this->showProfile();
135 Event::handle('EndProfileListItemProfile', array($this));
137 if (Event::handle('StartProfileListItemActions', array($this))) {
138 $this->showActions();
139 Event::handle('EndProfileListItemActions', array($this));
142 Event::handle('EndProfileListItem', array($this));
148 $this->out->elementStart('li', array('class' => 'profile hentry',
149 'id' => 'profile-' . $this->profile->id));
152 function showProfile()
154 $this->startProfile();
155 if (Event::handle('StartProfileListItemProfileElements', array($this))) {
156 if (Event::handle('StartProfileListItemAvatar', array($this))) {
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 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 $this->out->elementStart('a', array('href' => $this->profile->profileurl,
190 'class' => 'url entry-title',
191 'rel' => 'contact'));
192 $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
193 'class' => 'photo avatar',
194 'width' => AVATAR_STREAM_SIZE,
195 'height' => AVATAR_STREAM_SIZE,
197 ($this->profile->fullname) ? $this->profile->fullname :
198 $this->profile->nickname));
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->elementStart('span', 'fn');
210 $this->out->raw($this->highlight($this->profile->fullname));
211 $this->out->elementEnd('span');
215 function showLocation()
217 if (!empty($this->profile->location)) {
218 $this->out->elementStart('span', 'location');
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->elementStart('a', array('href' => $this->profile->homepage,
229 $this->out->raw($this->highlight($this->profile->homepage));
230 $this->out->elementEnd('a');
236 if (!empty($this->profile->bio)) {
237 $this->out->elementStart('p', 'note');
238 $this->out->raw($this->highlight($this->profile->bio));
239 $this->out->elementEnd('p');
243 function endProfile()
245 $this->out->elementEnd('div');
248 function showActions()
250 $this->startActions();
251 if (Event::handle('StartProfileListItemActionElements', array($this))) {
252 $this->showSubscribeButton();
253 Event::handle('EndProfileListItemActionElements', array($this));
258 function startActions()
260 $this->out->elementStart('div', 'entity_actions');
261 $this->out->elementStart('ul');
264 function showSubscribeButton()
266 // Is this a logged-in user, looking at someone else's
269 $user = common_current_user();
271 if (!empty($user) && $this->profile->id != $user->id) {
272 $this->out->elementStart('li', 'entity_subscribe');
273 if ($user->isSubscribed($this->profile)) {
274 $usf = new UnsubscribeForm($this->out, $this->profile);
277 // Is it a local user? can't remote sub from a list
278 // XXX: make that possible!
279 $other = User::staticGet('id', $this->profile->id);
280 if (!empty($other)) {
281 $sf = new SubscribeForm($this->out, $this->profile);
285 $this->out->elementEnd('li');
289 function endActions()
291 $this->out->elementEnd('ul');
292 $this->out->elementEnd('div');
297 $this->out->elementEnd('li');
300 function highlight($text)
302 return htmlspecialchars($text);