PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/accountprofileblock.php

https://gitlab.com/windigo-gs/windigos-gnu-social
PHP | 315 lines | 209 code | 46 blank | 60 comment | 38 complexity | a3f2289a40febe11eba150af34d4e4e7 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(HTMLOutputter $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 avatar()
  62. {
  63. return $this->profile->avatarUrl(AVATAR_PROFILE_SIZE);
  64. }
  65. function name()
  66. {
  67. return $this->profile->getBestName();
  68. }
  69. function url()
  70. {
  71. return $this->profile->profileurl;
  72. }
  73. function location()
  74. {
  75. return $this->profile->location;
  76. }
  77. function homepage()
  78. {
  79. return $this->profile->homepage;
  80. }
  81. function description()
  82. {
  83. return $this->profile->bio;
  84. }
  85. function otherProfiles()
  86. {
  87. $others = array();
  88. Event::handle('OtherAccountProfiles', array($this->profile, &$others));
  89. return $others;
  90. }
  91. function showTags()
  92. {
  93. $cur = common_current_user();
  94. $self_tags = new SelftagsWidget($this->out, $this->profile, $this->profile);
  95. $self_tags->show();
  96. if ($cur) {
  97. // don't show self-tags again
  98. if ($cur->id != $this->profile->id && $cur->getProfile()->canTag($this->profile)) {
  99. $tags = new PeopletagsWidget($this->out, $cur, $this->profile);
  100. $tags->show();
  101. }
  102. }
  103. }
  104. function showActions()
  105. {
  106. if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
  107. if ($this->profile->hasRole(Profile_role::DELETED)) {
  108. $this->out->elementStart('div', 'entity_actions');
  109. // TRANS: H2 for user actions in a profile.
  110. $this->out->element('h2', null, _('User actions'));
  111. $this->out->elementStart('ul');
  112. $this->out->elementStart('p', array('class' => 'profile_deleted'));
  113. // TRANS: Text shown in user profile of not yet compeltely deleted users.
  114. $this->out->text(_('User deletion in progress...'));
  115. $this->out->elementEnd('p');
  116. $this->out->elementEnd('ul');
  117. $this->out->elementEnd('div');
  118. return;
  119. }
  120. $cur = common_current_user();
  121. $this->out->elementStart('div', 'entity_actions');
  122. // TRANS: H2 for entity actions in a profile.
  123. $this->out->element('h2', null, _('User actions'));
  124. $this->out->elementStart('ul');
  125. if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
  126. if (empty($cur)) { // not logged in
  127. if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
  128. Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
  129. }
  130. } else {
  131. if ($cur->id == $this->profile->id) { // your own page
  132. $this->out->elementStart('li', 'entity_edit');
  133. $this->out->element('a', array('href' => common_local_url('profilesettings'),
  134. // TRANS: Link title for link on user profile.
  135. 'title' => _('Edit profile settings.')),
  136. // TRANS: Link text for link on user profile.
  137. _m('BUTTON','Edit'));
  138. $this->out->elementEnd('li');
  139. } else { // someone else's page
  140. // subscribe/unsubscribe button
  141. $this->out->elementStart('li', 'entity_subscribe');
  142. if ($cur->isSubscribed($this->profile)) {
  143. $usf = new UnsubscribeForm($this->out, $this->profile);
  144. $usf->show();
  145. } else if ($cur->hasPendingSubscription($this->profile)) {
  146. $sf = new CancelSubscriptionForm($this->out, $this->profile);
  147. $sf->show();
  148. } else {
  149. $sf = new SubscribeForm($this->out, $this->profile);
  150. $sf->show();
  151. }
  152. $this->out->elementEnd('li');
  153. if ($this->profile->isLocal() && $cur->mutuallySubscribed($this->profile)) {
  154. // message
  155. $this->out->elementStart('li', 'entity_send-a-message');
  156. $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
  157. // TRANS: Link title for link on user profile.
  158. 'title' => _('Send a direct message to this user.')),
  159. // TRANS: Link text for link on user profile.
  160. _m('BUTTON','Message'));
  161. $this->out->elementEnd('li');
  162. // nudge
  163. if ($this->user->email && $this->user->emailnotifynudge) {
  164. $this->out->elementStart('li', 'entity_nudge');
  165. $nf = new NudgeForm($this->out, $this->user);
  166. $nf->show();
  167. $this->out->elementEnd('li');
  168. }
  169. }
  170. // return-to args, so we don't have to keep re-writing them
  171. list($action, $r2args) = $this->out->returnToArgs();
  172. // push the action into the list
  173. $r2args['action'] = $action;
  174. // block/unblock
  175. $blocked = $cur->hasBlocked($this->profile);
  176. $this->out->elementStart('li', 'entity_block');
  177. if ($blocked) {
  178. $ubf = new UnblockForm($this->out, $this->profile, $r2args);
  179. $ubf->show();
  180. } else {
  181. $bf = new BlockForm($this->out, $this->profile, $r2args);
  182. $bf->show();
  183. }
  184. $this->out->elementEnd('li');
  185. // Some actions won't be applicable to non-local users.
  186. $isLocal = !empty($this->user);
  187. if ($cur->hasRight(Right::SANDBOXUSER) ||
  188. $cur->hasRight(Right::SILENCEUSER) ||
  189. $cur->hasRight(Right::DELETEUSER)) {
  190. $this->out->elementStart('li', 'entity_moderation');
  191. // TRANS: Label text on user profile to select a user role.
  192. $this->out->element('p', null, _('Moderate'));
  193. $this->out->elementStart('ul');
  194. if ($cur->hasRight(Right::SANDBOXUSER)) {
  195. $this->out->elementStart('li', 'entity_sandbox');
  196. if ($this->profile->isSandboxed()) {
  197. $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
  198. $usf->show();
  199. } else {
  200. $sf = new SandboxForm($this->out, $this->profile, $r2args);
  201. $sf->show();
  202. }
  203. $this->out->elementEnd('li');
  204. }
  205. if ($cur->hasRight(Right::SILENCEUSER)) {
  206. $this->out->elementStart('li', 'entity_silence');
  207. if ($this->profile->isSilenced()) {
  208. $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
  209. $usf->show();
  210. } else {
  211. $sf = new SilenceForm($this->out, $this->profile, $r2args);
  212. $sf->show();
  213. }
  214. $this->out->elementEnd('li');
  215. }
  216. if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
  217. $this->out->elementStart('li', 'entity_delete');
  218. $df = new DeleteUserForm($this->out, $this->profile, $r2args);
  219. $df->show();
  220. $this->out->elementEnd('li');
  221. }
  222. $this->out->elementEnd('ul');
  223. $this->out->elementEnd('li');
  224. }
  225. if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
  226. $this->out->elementStart('li', 'entity_role');
  227. // TRANS: Label text on user profile to select a user role.
  228. $this->out->element('p', null, _('User role'));
  229. $this->out->elementStart('ul');
  230. // TRANS: Role that can be set for a user profile.
  231. $this->roleButton('administrator', _m('role', 'Administrator'));
  232. // TRANS: Role that can be set for a user profile.
  233. $this->roleButton('moderator', _m('role', 'Moderator'));
  234. $this->out->elementEnd('ul');
  235. $this->out->elementEnd('li');
  236. }
  237. }
  238. }
  239. Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
  240. }
  241. $this->out->elementEnd('ul');
  242. $this->out->elementEnd('div');
  243. Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
  244. }
  245. }
  246. function roleButton($role, $label)
  247. {
  248. list($action, $r2args) = $this->out->returnToArgs();
  249. $r2args['action'] = $action;
  250. $this->out->elementStart('li', "entity_role_$role");
  251. if ($this->profile->hasRole($role)) {
  252. $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
  253. $rf->show();
  254. } else {
  255. $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
  256. $rf->show();
  257. }
  258. $this->out->elementEnd('li');
  259. }
  260. function show()
  261. {
  262. $this->out->elementStart('div', 'profile_block account_profile_block section');
  263. if (Event::handle('StartShowAccountProfileBlock', array($this->out, $this->profile))) {
  264. parent::show();
  265. Event::handle('EndShowAccountProfileBlock', array($this->out, $this->profile));
  266. }
  267. $this->out->elementEnd('div');
  268. }
  269. }