removepeopletag.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2008-2010, StatusNet, Inc.
  5. *
  6. * Subscription action.
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * PHP version 5
  22. *
  23. * @category Action
  24. * @package StatusNet
  25. * @author Shashi Gowda <connect2shashi@gmail.com>
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. require_once INSTALLDIR . '/lib/account/togglepeopletag.php';
  33. /**
  34. * Subscription action
  35. *
  36. * Subscribing to a profile. Does not work for OMB 0.1 remote subscriptions,
  37. * but may work for other remote subscription protocols, like OStatus.
  38. *
  39. * Takes parameters:
  40. *
  41. * - subscribeto: a profile ID
  42. * - token: session token to prevent CSRF attacks
  43. * - ajax: boolean; whether to return Ajax or full-browser results
  44. *
  45. * Only works if the current user is logged in.
  46. *
  47. * @category Action
  48. * @package StatusNet
  49. * @author Shashi Gowda <connect2shashi@gmail.com>
  50. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
  51. * @link http://status.net/
  52. */
  53. class RemovepeopletagAction extends Action
  54. {
  55. var $user;
  56. var $tagged;
  57. var $peopletag;
  58. /**
  59. * Check pre-requisites and instantiate attributes
  60. *
  61. * @param Array $args array of arguments (URL, GET, POST)
  62. *
  63. * @return boolean success flag
  64. */
  65. function prepare(array $args = array())
  66. {
  67. parent::prepare($args);
  68. // CSRF protection
  69. $token = $this->trimmed('token');
  70. if (!$token || $token != common_session_token()) {
  71. // TRANS: Client error displayed when the session token does not match or is not given.
  72. $this->clientError(_('There was a problem with your session token.'.
  73. ' Try again, please.'));
  74. }
  75. // Only for logged-in users
  76. $this->user = common_current_user();
  77. if (empty($this->user)) {
  78. // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
  79. $this->clientError(_('Not logged in.'));
  80. }
  81. // Profile to subscribe to
  82. $tagged_id = $this->arg('tagged');
  83. $this->tagged = Profile::getKV('id', $tagged_id);
  84. if (empty($this->tagged)) {
  85. // TRANS: Client error displayed when referring to a non-existing profile.
  86. $this->clientError(_('No such profile.'));
  87. }
  88. $id = $this->arg('peopletag_id');
  89. $this->peopletag = Profile_list::getKV('id', $id);
  90. if (empty($this->peopletag)) {
  91. // TRANS: Client error displayed trying to reference a non-existing list.
  92. $this->clientError(_('No such list.'));
  93. }
  94. return true;
  95. }
  96. /**
  97. * Handle request
  98. *
  99. * Does the subscription and returns results.
  100. *
  101. * @param Array $args unused.
  102. *
  103. * @return void
  104. */
  105. function handle()
  106. {
  107. // Throws exception on error
  108. $ptag = Profile_tag::unTag($this->user->id, $this->tagged->id,
  109. $this->peopletag->tag);
  110. if (!$ptag) {
  111. $user = User::getKV('id', $this->tagged->id);
  112. if ($user) {
  113. $this->clientError(
  114. // TRANS: Client error displayed when an unknown error occurs while delisting a user.
  115. // TRANS: %s is a username.
  116. sprintf(_('There was an unexpected error while delisting %s.'),
  117. $user->nickname));
  118. } else {
  119. // TRANS: Client error displayed when an unknown error occurs while listing a user.
  120. // TRANS: %s is a profile URL.
  121. $this->clientError(sprintf(_('There was a problem listing %s. ' .
  122. 'The remote server is probably not responding correctly, ' .
  123. 'please try retrying later.'), $this->profile->profileurl));
  124. }
  125. }
  126. if ($this->boolean('ajax')) {
  127. $this->startHTML('text/xml;charset=utf-8');
  128. $this->elementStart('head');
  129. // TRANS: Title after removing a user from a list.
  130. $this->element('title', null, _('Unlisted'));
  131. $this->elementEnd('head');
  132. $this->elementStart('body');
  133. $unsubscribe = new TagButton($this, $this->tagged, $this->peopletag);
  134. $unsubscribe->show();
  135. $this->elementEnd('body');
  136. $this->endHTML();
  137. } else {
  138. $url = common_local_url('subscriptions',
  139. array('nickname' => $this->user->nickname));
  140. common_redirect($url, 303);
  141. }
  142. }
  143. }