accountprofileblock.php 12 KB

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