accountprofileblock.php 12 KB

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