]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/accountprofileblock.php
Blend people tags UI into the new theme!
[quix0rs-gnu-social.git] / lib / accountprofileblock.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * Profile block to show for an account
7  *
8  * PHP version 5
9  *
10  * 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.
14  *
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.
19  *
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/>.
22  *
23  * @category  Widget
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2011 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 require_once INSTALLDIR.'/lib/peopletags.php';
38
39 /**
40  * Profile block to show for an account
41  *
42  * @category  Widget
43  * @package   StatusNet
44  * @author    Evan Prodromou <evan@status.net>
45  * @copyright 2011 StatusNet, Inc.
46  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
47  * @link      http://status.net/
48  */
49
50 class AccountProfileBlock extends ProfileBlock
51 {
52     protected $profile = null;
53     protected $user    = null;
54
55     function __construct($out, $profile)
56     {
57         parent::__construct($out);
58         $this->profile = $profile;
59         $this->user    = User::staticGet('id', $profile->id);
60     }
61
62     function avatar()
63     {
64         $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
65         if (empty($avatar)) {
66             $avatar = $this->profile->getAvatar(73);
67         }
68         return (!empty($avatar)) ?
69             $avatar->displayUrl() :
70             Avatar::defaultImage(AVATAR_PROFILE_SIZE);
71     }
72
73     function name()
74     {
75         return $this->profile->getBestName();
76     }
77
78     function url()
79     {
80         return $this->profile->profileurl;
81     }
82
83     function location()
84     {
85         return $this->profile->location;
86     }
87
88     function homepage()
89     {
90         return $this->profile->homepage;
91     }
92
93     function description()
94     {
95         return $this->profile->bio;
96     }
97
98     function showTags()
99     {
100         $cur = common_current_user();
101
102         $self_tags = new SelftagsWidget($this->out, $this->profile, $this->profile);
103         $self_tags->show();
104
105         if ($cur) {
106             // don't show self-tags again
107             if ($cur->id != $this->profile->id && $cur->getProfile()->canTag($this->profile)) {
108                 $tags = new PeopletagsWidget($this->out, $cur, $this->profile);
109                 $tags->show();
110             }
111         }
112     }
113
114     function showActions()
115     {
116         if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
117
118             if ($this->profile->hasRole(Profile_role::DELETED)) {
119                 $this->out->elementStart('div', 'entity_actions');
120                 // TRANS: H2 for user actions in a profile.
121                 $this->out->element('h2', null, _('User actions'));
122                 $this->out->elementStart('ul');
123                 $this->out->elementStart('p', array('class' => 'profile_deleted'));
124                 // TRANS: Text shown in user profile of not yet compeltely deleted users.
125                 $this->out->text(_('User deletion in progress...'));
126                 $this->out->elementEnd('p');
127                 $this->out->elementEnd('ul');
128                 $this->out->elementEnd('div');
129                 return;
130             }
131
132             $cur = common_current_user();
133
134             $this->out->elementStart('div', 'entity_actions');
135             // TRANS: H2 for entity actions in a profile.
136             $this->out->element('h2', null, _('User actions'));
137             $this->out->elementStart('ul');
138
139             if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
140                 if (empty($cur)) { // not logged in
141                     if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
142                         $this->out->elementStart('li', 'entity_subscribe');
143                         $this->showRemoteSubscribeLink();
144                         $this->out->elementEnd('li');
145                         Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
146                     }
147                 } else {
148                     if ($cur->id == $this->profile->id) { // your own page
149                         $this->out->elementStart('li', 'entity_edit');
150                         $this->out->element('a', array('href' => common_local_url('profilesettings'),
151                                                   // TRANS: Link title for link on user profile.
152                                                   'title' => _('Edit profile settings')),
153                                        // TRANS: Link text for link on user profile.
154                                        _('Edit'));
155                         $this->out->elementEnd('li');
156                     } else { // someone else's page
157
158                         // subscribe/unsubscribe button
159
160                         $this->out->elementStart('li', 'entity_subscribe');
161
162                         if ($cur->isSubscribed($this->profile)) {
163                             $usf = new UnsubscribeForm($this->out, $this->profile);
164                             $usf->show();
165                         } else {
166                             $sf = new SubscribeForm($this->out, $this->profile);
167                             $sf->show();
168                         }
169                         $this->out->elementEnd('li');
170
171                         if ($cur->mutuallySubscribed($this->profile)) {
172
173                             // message
174
175                             $this->out->elementStart('li', 'entity_send-a-message');
176                             $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
177                                                       // TRANS: Link title for link on user profile.
178                                                       'title' => _('Send a direct message to this user')),
179                                            // TRANS: Link text for link on user profile.
180                                            _('Message'));
181                             $this->out->elementEnd('li');
182
183                             // nudge
184
185                             if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
186                                 $this->out->elementStart('li', 'entity_nudge');
187                                 $nf = new NudgeForm($this->out, $this->user);
188                                 $nf->show();
189                                 $this->out->elementEnd('li');
190                             }
191                         }
192
193                         // return-to args, so we don't have to keep re-writing them
194
195                         list($action, $r2args) = $this->out->returnToArgs();
196
197                         // push the action into the list
198
199                         $r2args['action'] = $action;
200
201                         // block/unblock
202
203                         $blocked = $cur->hasBlocked($this->profile);
204                         $this->out->elementStart('li', 'entity_block');
205                         if ($blocked) {
206                             $ubf = new UnblockForm($this->out, $this->profile, $r2args);
207                             $ubf->show();
208                         } else {
209                             $bf = new BlockForm($this->out, $this->profile, $r2args);
210                             $bf->show();
211                         }
212                         $this->out->elementEnd('li');
213
214                         // Some actions won't be applicable to non-local users.
215                         $isLocal = !empty($this->user);
216
217                         if ($cur->hasRight(Right::SANDBOXUSER) ||
218                             $cur->hasRight(Right::SILENCEUSER) ||
219                             $cur->hasRight(Right::DELETEUSER)) {
220                             $this->out->elementStart('li', 'entity_moderation');
221                             // TRANS: Label text on user profile to select a user role.
222                             $this->out->element('p', null, _('Moderate'));
223                             $this->out->elementStart('ul');
224                             if ($cur->hasRight(Right::SANDBOXUSER)) {
225                                 $this->out->elementStart('li', 'entity_sandbox');
226                                 if ($this->profile->isSandboxed()) {
227                                     $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
228                                     $usf->show();
229                                 } else {
230                                     $sf = new SandboxForm($this->out, $this->profile, $r2args);
231                                     $sf->show();
232                                 }
233                                 $this->out->elementEnd('li');
234                             }
235
236                             if ($cur->hasRight(Right::SILENCEUSER)) {
237                                 $this->out->elementStart('li', 'entity_silence');
238                                 if ($this->profile->isSilenced()) {
239                                     $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
240                                     $usf->show();
241                                 } else {
242                                     $sf = new SilenceForm($this->out, $this->profile, $r2args);
243                                     $sf->show();
244                                 }
245                                 $this->out->elementEnd('li');
246                             }
247
248                             if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
249                                 $this->out->elementStart('li', 'entity_delete');
250                                 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
251                                 $df->show();
252                                 $this->out->elementEnd('li');
253                             }
254                             $this->out->elementEnd('ul');
255                             $this->out->elementEnd('li');
256                         }
257
258                         if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
259                             $this->out->elementStart('li', 'entity_role');
260                             // TRANS: Label text on user profile to select a user role.
261                             $this->out->element('p', null, _('User role'));
262                             $this->out->elementStart('ul');
263                             // TRANS: Role that can be set for a user profile.
264                             $this->roleButton('administrator', _m('role', 'Administrator'));
265                             // TRANS: Role that can be set for a user profile.
266                             $this->roleButton('moderator', _m('role', 'Moderator'));
267                             $this->out->elementEnd('ul');
268                             $this->out->elementEnd('li');
269                         }
270                     }
271                 }
272
273                 Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
274             }
275
276             $this->out->elementEnd('ul');
277             $this->out->elementEnd('div');
278
279             Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
280         }
281     }
282
283     function roleButton($role, $label)
284     {
285         list($action, $r2args) = $this->out->returnToArgs();
286         $r2args['action'] = $action;
287
288         $this->out->elementStart('li', "entity_role_$role");
289         if ($this->profile->hasRole($role)) {
290             $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
291             $rf->show();
292         } else {
293             $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
294             $rf->show();
295         }
296         $this->out->elementEnd('li');
297     }
298
299     function showRemoteSubscribeLink()
300     {
301         $url = common_local_url('remotesubscribe',
302                                 array('nickname' => $this->profile->nickname));
303         $this->out->element('a', array('href' => $url,
304                                   'class' => 'entity_remote_subscribe'),
305                        // TRANS: Link text for link that will subscribe to a remote profile.
306                        _('Subscribe'));
307     }
308 }