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