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('GNUSOCIAL')) { exit(1); }
32 class ProfileListItem extends Widget
34 /** Current profile. */
36 /** Action object using us. */
39 function __construct($profile, $action)
41 parent::__construct($action);
43 $this->profile = $profile;
44 $this->action = $action;
49 if (Event::handle('StartProfileListItem', array($this))) {
51 if (Event::handle('StartProfileListItemProfile', array($this))) {
53 Event::handle('EndProfileListItemProfile', array($this));
55 if (Event::handle('StartProfileListItemActions', array($this))) {
57 Event::handle('EndProfileListItemActions', array($this));
60 Event::handle('EndProfileListItem', array($this));
66 $this->out->elementStart('li', array('class' => 'profile',
67 'id' => 'profile-' . $this->profile->id));
70 function showProfile()
72 $this->startProfile();
73 if (Event::handle('StartProfileListItemProfileElements', array($this))) {
74 if (Event::handle('StartProfileListItemAvatar', array($this))) {
75 $aAttrs = $this->linkAttributes();
76 $this->out->elementStart('a', $aAttrs);
77 $this->showAvatar($this->profile);
78 $this->out->elementEnd('a');
79 Event::handle('EndProfileListItemAvatar', array($this));
81 if (Event::handle('StartProfileListItemNickname', array($this))) {
82 $this->showNickname();
83 Event::handle('EndProfileListItemNickname', array($this));
85 if (Event::handle('StartProfileListItemFullName', array($this))) {
86 $this->showFullName();
87 Event::handle('EndProfileListItemFullName', array($this));
89 if (Event::handle('StartProfileListItemLocation', array($this))) {
90 $this->showLocation();
91 Event::handle('EndProfileListItemLocation', array($this));
93 if (Event::handle('StartProfileListItemHomepage', array($this))) {
94 $this->showHomepage();
95 Event::handle('EndProfileListItemHomepage', array($this));
97 if (Event::handle('StartProfileListItemBio', array($this))) {
99 Event::handle('EndProfileListItemBio', array($this));
101 if (Event::handle('StartProfileListItemTags', array($this))) {
103 Event::handle('EndProfileListItemTags', array($this));
105 Event::handle('EndProfileListItemProfileElements', array($this));
110 function startProfile()
112 $this->out->elementStart('div', 'entity_profile h-card');
115 function showNickname()
117 $this->out->element('a', array('href'=>$this->profile->getUrl(),
118 'class'=>'p-nickname'),
119 $this->profile->getNickname());
122 function showFullName()
124 if (!empty($this->profile->fullname)) {
125 $this->out->element('span', 'p-name', $this->profile->fullname);
129 function showLocation()
131 if (!empty($this->profile->location)) {
132 $this->out->element('span', 'label p-locality', $this->profile->location);
136 function showHomepage()
138 if (!empty($this->profile->homepage)) {
139 $this->out->text(' ');
140 $aAttrs = $this->homepageAttributes();
141 $this->out->elementStart('a', $aAttrs);
142 $this->out->raw($this->highlight($this->profile->homepage));
143 $this->out->elementEnd('a');
149 if (!empty($this->profile->bio)) {
150 $this->out->elementStart('p', 'note');
151 $this->out->raw($this->highlight($this->profile->bio));
152 $this->out->elementEnd('p');
158 $user = common_current_user();
160 if ($user->id == $this->profile->id) {
161 $tags = new SelftagsWidget($this->out, $user, $this->profile);
163 } else if ($user->getProfile()->canTag($this->profile)) {
164 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
170 function endProfile()
172 $this->out->elementEnd('div');
175 function showActions()
177 $this->startActions();
178 if (Event::handle('StartProfileListItemActionElements', array($this))) {
179 $this->showSubscribeButton();
180 Event::handle('EndProfileListItemActionElements', array($this));
185 function startActions()
187 $this->out->elementStart('div', 'entity_actions');
188 $this->out->elementStart('ul');
191 function showSubscribeButton()
193 // Is this a logged-in user, looking at someone else's
196 $user = common_current_user();
198 if (!empty($user) && $this->profile->id != $user->id) {
199 $this->out->elementStart('li', 'entity_subscribe');
200 if ($user->isSubscribed($this->profile)) {
201 $usf = new UnsubscribeForm($this->out, $this->profile);
204 if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
205 $sf = new SubscribeForm($this->out, $this->profile);
207 Event::handle('EndShowProfileListSubscribeButton', array($this));
210 $this->out->elementEnd('li');
214 function endActions()
216 $this->out->elementEnd('ul');
217 $this->out->elementEnd('div');
222 $this->out->elementEnd('li');
225 function highlight($text)
227 return htmlspecialchars($text);
230 function linkAttributes()
232 return array('href' => $this->profile->profileurl,
237 function homepageAttributes()
239 return array('href' => $this->profile->homepage,