PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/accountprofileblock.php

https://gitlab.com/otharwa/gnu-social
PHP | 299 lines | 200 code | 42 blank | 57 comment | 38 complexity | 7b7ea07d67f49726d70efe92ddfc4c74 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, GPL-2.0
  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. if (!defined('STATUSNET')) {
  31. // This check helps protect against security problems;
  32. // your code file can't be executed directly from the web.
  33. exit(1);
  34. }
  35. require_once INSTALLDIR.'/lib/peopletags.php';
  36. /**
  37. * Profile block to show for an account
  38. *
  39. * @category Widget
  40. * @package StatusNet
  41. * @author Evan Prodromou <evan@status.net>
  42. * @copyright 2011 StatusNet, Inc.
  43. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  44. * @link http://status.net/
  45. */
  46. class AccountProfileBlock extends ProfileBlock
  47. {
  48. protected $profile = null;
  49. protected $user = null;
  50. function __construct(Action $out, Profile $profile)
  51. {
  52. parent::__construct($out);
  53. $this->profile = $profile;
  54. try {
  55. $this->user = $this->profile->getUser();
  56. } catch (NoSuchUserException $e) {
  57. // The profile presented is non-local
  58. assert(!$this->profile->isLocal());
  59. }
  60. }
  61. function name()
  62. {
  63. return $this->profile->getBestName();
  64. }
  65. function url()
  66. {
  67. return $this->profile->profileurl;
  68. }
  69. function location()
  70. {
  71. return $this->profile->location;
  72. }
  73. function homepage()
  74. {
  75. return $this->profile->homepage;
  76. }
  77. function description()
  78. {
  79. return $this->profile->bio;
  80. }
  81. function otherProfiles()
  82. {
  83. $others = array();
  84. Event::handle('OtherAccountProfiles', array($this->profile, &$others));
  85. return $others;
  86. }
  87. function showTags()
  88. {
  89. $cur = common_current_user();
  90. $self_tags = new SelftagsWidget($this->out, $this->profile, $this->profile);
  91. $self_tags->show();
  92. if ($cur) {
  93. // don't show self-tags again
  94. if ($cur->id != $this->profile->id && $cur->getProfile()->canTag($this->profile)) {
  95. $tags = new PeopletagsWidget($this->out, $cur, $this->profile);
  96. $tags->show();
  97. }
  98. }
  99. }
  100. function showActions()
  101. {
  102. if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
  103. if ($this->profile->hasRole(Profile_role::DELETED)) {
  104. $this->out->elementStart('div', 'entity_actions');
  105. // TRANS: H2 for user actions in a profile.
  106. $this->out->element('h2', null, _('User actions'));
  107. $this->out->elementStart('ul');
  108. $this->out->elementStart('p', array('class' => 'profile_deleted'));
  109. // TRANS: Text shown in user profile of not yet compeltely deleted users.
  110. $this->out->text(_('User deletion in progress...'));
  111. $this->out->elementEnd('p');
  112. $this->out->elementEnd('ul');
  113. $this->out->elementEnd('div');
  114. return;
  115. }
  116. $cur = common_current_user();
  117. $this->out->elementStart('div', 'entity_actions');
  118. // TRANS: H2 for entity actions in a profile.
  119. $this->out->element('h2', null, _('User actions'));
  120. $this->out->elementStart('ul');
  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. Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
  125. }
  126. } else {
  127. if ($cur->id == $this->profile->id) { // your own page
  128. $this->out->elementStart('li', 'entity_edit');
  129. $this->out->element('a', array('href' => common_local_url('profilesettings'),
  130. // TRANS: Link title for link on user profile.
  131. 'title' => _('Edit profile settings.')),
  132. // TRANS: Link text for link on user profile.
  133. _m('BUTTON','Edit'));
  134. $this->out->elementEnd('li');
  135. } else { // someone else's page
  136. // subscribe/unsubscribe button
  137. $this->out->elementStart('li', 'entity_subscribe');
  138. if ($cur->isSubscribed($this->profile)) {
  139. $usf = new UnsubscribeForm($this->out, $this->profile);
  140. $usf->show();
  141. } else if ($cur->hasPendingSubscription($this->profile)) {
  142. $sf = new CancelSubscriptionForm($this->out, $this->profile);
  143. $sf->show();
  144. } else {
  145. $sf = new SubscribeForm($this->out, $this->profile);
  146. $sf->show();
  147. }
  148. $this->out->elementEnd('li');
  149. if ($this->profile->isLocal() && $cur->mutuallySubscribed($this->profile)) {
  150. // nudge
  151. if ($this->user->email && $this->user->emailnotifynudge) {
  152. $this->out->elementStart('li', 'entity_nudge');
  153. $nf = new NudgeForm($this->out, $this->user);
  154. $nf->show();
  155. $this->out->elementEnd('li');
  156. }
  157. }
  158. // return-to args, so we don't have to keep re-writing them
  159. list($action, $r2args) = $this->out->returnToArgs();
  160. // push the action into the list
  161. $r2args['action'] = $action;
  162. // block/unblock
  163. $blocked = $cur->hasBlocked($this->profile);
  164. $this->out->elementStart('li', 'entity_block');
  165. if ($blocked) {
  166. $ubf = new UnblockForm($this->out, $this->profile, $r2args);
  167. $ubf->show();
  168. } else {
  169. $bf = new BlockForm($this->out, $this->profile, $r2args);
  170. $bf->show();
  171. }
  172. $this->out->elementEnd('li');
  173. // Some actions won't be applicable to non-local users.
  174. $isLocal = !empty($this->user);
  175. if ($cur->hasRight(Right::SANDBOXUSER) ||
  176. $cur->hasRight(Right::SILENCEUSER) ||
  177. $cur->hasRight(Right::DELETEUSER)) {
  178. $this->out->elementStart('li', 'entity_moderation');
  179. // TRANS: Label text on user profile to select a user role.
  180. $this->out->element('p', null, _('Moderate'));
  181. $this->out->elementStart('ul');
  182. if ($cur->hasRight(Right::SANDBOXUSER)) {
  183. $this->out->elementStart('li', 'entity_sandbox');
  184. if ($this->profile->isSandboxed()) {
  185. $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
  186. $usf->show();
  187. } else {
  188. $sf = new SandboxForm($this->out, $this->profile, $r2args);
  189. $sf->show();
  190. }
  191. $this->out->elementEnd('li');
  192. }
  193. if ($cur->hasRight(Right::SILENCEUSER)) {
  194. $this->out->elementStart('li', 'entity_silence');
  195. if ($this->profile->isSilenced()) {
  196. $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
  197. $usf->show();
  198. } else {
  199. $sf = new SilenceForm($this->out, $this->profile, $r2args);
  200. $sf->show();
  201. }
  202. $this->out->elementEnd('li');
  203. }
  204. if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
  205. $this->out->elementStart('li', 'entity_delete');
  206. $df = new DeleteUserForm($this->out, $this->profile, $r2args);
  207. $df->show();
  208. $this->out->elementEnd('li');
  209. }
  210. $this->out->elementEnd('ul');
  211. $this->out->elementEnd('li');
  212. }
  213. if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
  214. $this->out->elementStart('li', 'entity_role');
  215. // TRANS: Label text on user profile to select a user role.
  216. $this->out->element('p', null, _('User role'));
  217. $this->out->elementStart('ul');
  218. // TRANS: Role that can be set for a user profile.
  219. $this->roleButton('administrator', _m('role', 'Administrator'));
  220. // TRANS: Role that can be set for a user profile.
  221. $this->roleButton('moderator', _m('role', 'Moderator'));
  222. $this->out->elementEnd('ul');
  223. $this->out->elementEnd('li');
  224. }
  225. }
  226. }
  227. Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
  228. }
  229. $this->out->elementEnd('ul');
  230. $this->out->elementEnd('div');
  231. Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
  232. }
  233. }
  234. function roleButton($role, $label)
  235. {
  236. list($action, $r2args) = $this->out->returnToArgs();
  237. $r2args['action'] = $action;
  238. $this->out->elementStart('li', "entity_role_$role");
  239. if ($this->profile->hasRole($role)) {
  240. $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
  241. $rf->show();
  242. } else {
  243. $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
  244. $rf->show();
  245. }
  246. $this->out->elementEnd('li');
  247. }
  248. function show()
  249. {
  250. $this->out->elementStart('div', 'profile_block account_profile_block section');
  251. if (Event::handle('StartShowAccountProfileBlock', array($this->out, $this->profile))) {
  252. parent::show();
  253. Event::handle('EndShowAccountProfileBlock', array($this->out, $this->profile));
  254. }
  255. $this->out->elementEnd('div');
  256. }
  257. }