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;
66 $cnt = $this->showProfiles();
73 $this->out->elementStart('ul', 'profiles');
78 $this->out->elementEnd('ul');
81 function showProfiles()
85 while ($this->profile->fetch()) {
87 if($cnt > PROFILES_PER_PAGE) {
90 $pli = $this->newListItem($this->profile);
97 function newListItem($profile)
99 return new ProfileListItem($this->profile, $this->action);
103 class ProfileListItem extends Widget
105 /** Current profile. */
107 /** Action object using us. */
110 function __construct($profile, $action)
112 parent::__construct($action);
114 $this->profile = $profile;
115 $this->action = $action;
121 $this->showProfile();
122 $this->showActions();
128 $this->out->elementStart('li', array('class' => 'profile',
129 'id' => 'profile-' . $this->profile->id));
132 function showProfile()
134 $this->startProfile();
136 $this->showFullName();
137 $this->showLocation();
138 $this->showHomepage();
143 function startProfile()
145 $this->out->elementStart('div', 'entity_profile vcard');
148 function showAvatar()
150 $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
151 $this->out->elementStart('a', array('href' => $this->profile->profileurl,
153 $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
154 'class' => 'photo avatar',
155 'width' => AVATAR_STREAM_SIZE,
156 'height' => AVATAR_STREAM_SIZE,
158 ($this->profile->fullname) ? $this->profile->fullname :
159 $this->profile->nickname));
160 $hasFN = ($this->profile->fullname !== '') ? 'nickname' : 'fn nickname';
161 $this->out->elementStart('span', $hasFN);
162 $this->out->raw($this->highlight($this->profile->nickname));
163 $this->out->elementEnd('span');
164 $this->out->elementEnd('a');
167 function showFullName()
169 if (!empty($this->profile->fullname)) {
170 $this->out->elementStart('dl', 'entity_fn');
171 $this->out->element('dt', null, 'Full name');
172 $this->out->elementStart('dd');
173 $this->out->elementStart('span', 'fn');
174 $this->out->raw($this->highlight($this->profile->fullname));
175 $this->out->elementEnd('span');
176 $this->out->elementEnd('dd');
177 $this->out->elementEnd('dl');
181 function showLocation()
183 if (!empty($this->profile->location)) {
184 $this->out->elementStart('dl', 'entity_location');
185 $this->out->element('dt', null, _('Location'));
186 $this->out->elementStart('dd', 'label');
187 $this->out->raw($this->highlight($this->profile->location));
188 $this->out->elementEnd('dd');
189 $this->out->elementEnd('dl');
193 function showHomepage()
195 if (!empty($this->profile->homepage)) {
196 $this->out->elementStart('dl', 'entity_url');
197 $this->out->element('dt', null, _('URL'));
198 $this->out->elementStart('dd');
199 $this->out->elementStart('a', array('href' => $this->profile->homepage,
201 $this->out->raw($this->highlight($this->profile->homepage));
202 $this->out->elementEnd('a');
203 $this->out->elementEnd('dd');
204 $this->out->elementEnd('dl');
210 if (!empty($this->profile->bio)) {
211 $this->out->elementStart('dl', 'entity_note');
212 $this->out->element('dt', null, _('Note'));
213 $this->out->elementStart('dd', 'note');
214 $this->out->raw($this->highlight($this->profile->bio));
215 $this->out->elementEnd('dd');
216 $this->out->elementEnd('dl');
220 function endProfile()
222 $this->out->elementEnd('div');
225 function showActions()
227 $this->startActions();
228 $this->showSubscribeButton();
232 function startActions()
234 $this->out->elementStart('div', 'entity_actions');
235 $this->out->elementStart('ul');
238 function showSubscribeButton()
240 // Is this a logged-in user, looking at someone else's
243 $user = common_current_user();
245 if (!empty($user) && $this->profile->id != $user->id) {
246 $this->out->elementStart('li', 'entity_subscribe');
247 if ($user->isSubscribed($this->profile)) {
248 $usf = new UnsubscribeForm($this->out, $this->profile);
251 // Is it a local user? can't remote sub from a list
252 // XXX: make that possible!
253 $other = User::staticGet('id', $this->profile->id);
254 if (!empty($other)) {
255 $sf = new SubscribeForm($this->out, $this->profile);
259 $this->out->elementEnd('li');
263 function endActions()
265 $this->out->elementEnd('ul');
266 $this->out->elementEnd('div');
271 $this->out->elementEnd('li');
274 function highlight($text)
276 return htmlspecialchars($text);