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 function __construct(Profile $target, HTMLOutputter $action)
42 parent::__construct($action);
44 $this->target = $target;
45 $this->profile = $this->target;
46 $this->action = $action;
56 if (Event::handle('StartProfileListItem', array($this))) {
58 if (Event::handle('StartProfileListItemProfile', array($this))) {
60 Event::handle('EndProfileListItemProfile', array($this));
62 if (Event::handle('StartProfileListItemActions', array($this))) {
64 Event::handle('EndProfileListItemActions', array($this));
67 Event::handle('EndProfileListItem', array($this));
73 $this->out->elementStart('li', array('class' => 'profile',
74 'id' => 'profile-' . $this->profile->id));
77 function showProfile()
79 $this->startProfile();
80 if (Event::handle('StartProfileListItemProfileElements', array($this))) {
81 if (Event::handle('StartProfileListItemAvatar', array($this))) {
82 $aAttrs = $this->linkAttributes();
83 $this->out->elementStart('a', $aAttrs);
84 $this->showAvatar($this->profile);
85 $this->out->elementEnd('a');
86 Event::handle('EndProfileListItemAvatar', array($this));
88 if (Event::handle('StartProfileListItemNickname', array($this))) {
89 $this->showNickname();
90 Event::handle('EndProfileListItemNickname', array($this));
92 if (Event::handle('StartProfileListItemFullName', array($this))) {
93 $this->showFullName();
94 Event::handle('EndProfileListItemFullName', array($this));
96 if (Event::handle('StartProfileListItemLocation', array($this))) {
97 $this->showLocation();
98 Event::handle('EndProfileListItemLocation', array($this));
100 if (Event::handle('StartProfileListItemHomepage', array($this))) {
101 $this->showHomepage();
102 Event::handle('EndProfileListItemHomepage', array($this));
104 if (Event::handle('StartProfileListItemBio', array($this))) {
106 Event::handle('EndProfileListItemBio', array($this));
108 if (Event::handle('StartProfileListItemTags', array($this))) {
110 Event::handle('EndProfileListItemTags', array($this));
112 Event::handle('EndProfileListItemProfileElements', array($this));
117 function startProfile()
119 $this->out->elementStart('div', 'entity_profile h-card');
122 function showNickname()
124 $this->out->element('a', array('href'=>$this->profile->getUrl(),
125 'class'=>'p-nickname'),
126 $this->profile->getNickname());
129 function showFullName()
131 if (!empty($this->profile->fullname)) {
132 $this->out->element('span', 'p-name', $this->profile->fullname);
136 function showLocation()
138 if (!empty($this->profile->location)) {
139 $this->out->element('span', 'label p-locality', $this->profile->location);
143 function showHomepage()
145 if (!empty($this->profile->homepage)) {
146 $this->out->text(' ');
147 $aAttrs = $this->homepageAttributes();
148 $this->out->elementStart('a', $aAttrs);
149 $this->out->raw($this->highlight($this->profile->homepage));
150 $this->out->elementEnd('a');
156 if (!empty($this->profile->bio)) {
157 $this->out->elementStart('p', 'note');
158 $this->out->raw($this->highlight($this->profile->bio));
159 $this->out->elementEnd('p');
165 $user = common_current_user();
167 if ($user->id == $this->profile->id) {
168 $tags = new SelftagsWidget($this->out, $user, $this->profile);
170 } else if ($user->getProfile()->canTag($this->profile)) {
171 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
177 function endProfile()
179 $this->out->elementEnd('div');
182 function showActions()
184 $this->startActions();
185 if (Event::handle('StartProfileListItemActionElements', array($this))) {
186 $this->showSubscribeButton();
187 Event::handle('EndProfileListItemActionElements', array($this));
192 function startActions()
194 $this->out->elementStart('div', 'entity_actions');
195 $this->out->elementStart('ul');
198 function showSubscribeButton()
200 // Is this a logged-in user, looking at someone else's
203 $user = common_current_user();
205 if (!empty($user) && $this->profile->id != $user->id) {
206 $this->out->elementStart('li', 'entity_subscribe');
207 if ($user->isSubscribed($this->profile)) {
208 $usf = new UnsubscribeForm($this->out, $this->profile);
211 if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
212 $sf = new SubscribeForm($this->out, $this->profile);
214 Event::handle('EndShowProfileListSubscribeButton', array($this));
217 $this->out->elementEnd('li');
221 function endActions()
223 $this->out->elementEnd('ul');
224 $this->out->elementEnd('div');
229 $this->out->elementEnd('li');
232 function highlight($text)
234 return htmlspecialchars($text);
237 function linkAttributes()
239 return array('href' => $this->profile->profileurl,
244 function homepageAttributes()
246 return array('href' => $this->profile->homepage,