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. */
35 protected $target = null;
37 /** Action object using us. */
40 // FIXME: Directory plugin sends a User_group here, but should send a Profile and handle User_group specifics itself
41 function __construct($target, HTMLOutputter $action)
43 parent::__construct($action);
45 $this->target = $target;
46 $this->profile = $this->target;
47 $this->action = $action;
57 if (Event::handle('StartProfileListItem', array($this))) {
59 if (Event::handle('StartProfileListItemProfile', array($this))) {
61 Event::handle('EndProfileListItemProfile', array($this));
63 if (Event::handle('StartProfileListItemActions', array($this))) {
65 Event::handle('EndProfileListItemActions', array($this));
68 Event::handle('EndProfileListItem', array($this));
74 $this->out->elementStart('li', array('class' => 'profile',
75 'id' => 'profile-' . $this->profile->id));
78 function showProfile()
80 $this->startProfile();
81 if (Event::handle('StartProfileListItemProfileElements', array($this))) {
82 if (Event::handle('StartProfileListItemAvatar', array($this))) {
83 $aAttrs = $this->linkAttributes();
84 $this->out->elementStart('a', $aAttrs);
85 $this->showAvatar($this->profile);
86 $this->out->elementEnd('a');
87 Event::handle('EndProfileListItemAvatar', array($this));
89 if (Event::handle('StartProfileListItemNickname', array($this))) {
90 $this->showNickname();
91 Event::handle('EndProfileListItemNickname', array($this));
93 if (Event::handle('StartProfileListItemFullName', array($this))) {
94 $this->showFullName();
95 Event::handle('EndProfileListItemFullName', array($this));
97 if (Event::handle('StartProfileListItemLocation', array($this))) {
98 $this->showLocation();
99 Event::handle('EndProfileListItemLocation', array($this));
101 if (Event::handle('StartProfileListItemHomepage', array($this))) {
102 $this->showHomepage();
103 Event::handle('EndProfileListItemHomepage', array($this));
105 if (Event::handle('StartProfileListItemBio', array($this))) {
107 Event::handle('EndProfileListItemBio', array($this));
109 if (Event::handle('StartProfileListItemTags', array($this))) {
111 Event::handle('EndProfileListItemTags', array($this));
113 Event::handle('EndProfileListItemProfileElements', array($this));
118 function startProfile()
120 $this->out->elementStart('div', 'entity_profile h-card');
123 function showNickname()
125 $this->out->element('a', array('href'=>$this->profile->getUrl(),
126 'class'=>'p-nickname'),
127 $this->profile->getNickname());
130 function showFullName()
132 if (!empty($this->profile->fullname)) {
133 $this->out->element('span', 'p-name', $this->profile->fullname);
137 function showLocation()
139 if (!empty($this->profile->location)) {
140 $this->out->element('span', 'label p-locality', $this->profile->location);
144 function showHomepage()
146 if (!empty($this->profile->homepage)) {
147 $this->out->text(' ');
148 $aAttrs = $this->homepageAttributes();
149 $this->out->elementStart('a', $aAttrs);
150 $this->out->raw($this->highlight($this->profile->homepage));
151 $this->out->elementEnd('a');
157 if (!empty($this->profile->bio)) {
158 $this->out->elementStart('p', 'note');
159 $this->out->raw($this->highlight($this->profile->bio));
160 $this->out->elementEnd('p');
166 $user = common_current_user();
168 if ($user->id == $this->profile->id) {
169 $tags = new SelftagsWidget($this->out, $user, $this->profile);
171 } else if ($user->getProfile()->canTag($this->profile)) {
172 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
178 function endProfile()
180 $this->out->elementEnd('div');
183 function showActions()
185 $this->startActions();
186 if (Event::handle('StartProfileListItemActionElements', array($this))) {
187 $this->showSubscribeButton();
188 Event::handle('EndProfileListItemActionElements', array($this));
193 function startActions()
195 $this->out->elementStart('div', 'entity_actions');
196 $this->out->elementStart('ul');
199 function showSubscribeButton()
201 // Is this a logged-in user, looking at someone else's
204 $user = common_current_user();
206 if (!empty($user) && $this->profile->id != $user->id) {
207 $this->out->elementStart('li', 'entity_subscribe');
208 if ($user->isSubscribed($this->profile)) {
209 $usf = new UnsubscribeForm($this->out, $this->profile);
212 if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
213 $sf = new SubscribeForm($this->out, $this->profile);
215 Event::handle('EndShowProfileListSubscribeButton', array($this));
218 $this->out->elementEnd('li');
222 function endActions()
224 $this->out->elementEnd('ul');
225 $this->out->elementEnd('div');
230 $this->out->elementEnd('li');
233 function highlight($text)
235 return htmlspecialchars($text);
238 function linkAttributes()
240 return array('href' => $this->profile->profileurl,
245 function homepageAttributes()
247 return array('href' => $this->profile->homepage,