subscribepeopletag.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Subscribe to a peopletag
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Peopletag
  23. * @package StatusNet
  24. * @author Shashi Gowda <connect2shashi@gmail.com>
  25. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  26. * @link http://status.net/
  27. */
  28. if (!defined('STATUSNET') && !defined('LACONICA')) {
  29. exit(1);
  30. }
  31. /**
  32. * Subscribe to a peopletag
  33. *
  34. * This is the action for subscribing to a peopletag. It works more or less like the join action
  35. * for groups.
  36. *
  37. * @category Peopletag
  38. * @package StatusNet
  39. * @author Shashi Gowda <connect2shashi@gmail.com>
  40. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  41. * @link http://status.net/
  42. */
  43. class SubscribepeopletagAction extends Action
  44. {
  45. var $peopletag = null;
  46. var $tagger = null;
  47. /**
  48. * Prepare to run
  49. */
  50. function prepare(array $args = array())
  51. {
  52. parent::prepare($args);
  53. if (!common_logged_in()) {
  54. // TRANS: Client error displayed when trying to perform an action while not logged in.
  55. $this->clientError(_('You must be logged in to unsubscribe from a list.'));
  56. }
  57. // Only allow POST requests
  58. if ($_SERVER['REQUEST_METHOD'] != 'POST') {
  59. // TRANS: Client error displayed when trying to use another method than POST.
  60. $this->clientError(_('This action only accepts POST requests.'));
  61. }
  62. // CSRF protection
  63. $token = $this->trimmed('token');
  64. if (!$token || $token != common_session_token()) {
  65. // TRANS: Client error displayed when the session token does not match or is not given.
  66. $this->clientError(_('There was a problem with your session token.'.
  67. ' Try again, please.'));
  68. }
  69. $tagger_arg = $this->trimmed('tagger');
  70. $tag_arg = $this->trimmed('tag');
  71. $id = intval($this->arg('id'));
  72. if ($id) {
  73. $this->peopletag = Profile_list::getKV('id', $id);
  74. } else {
  75. // TRANS: Client error displayed when trying to perform an action without providing an ID.
  76. $this->clientError(_('No ID given.'), 404);
  77. }
  78. if (!$this->peopletag || $this->peopletag->private) {
  79. // TRANS: Client error displayed trying to reference a non-existing list.
  80. $this->clientError(_('No such list.'), 404);
  81. }
  82. $this->tagger = Profile::getKV('id', $this->peopletag->tagger);
  83. return true;
  84. }
  85. /**
  86. * Handle the request
  87. *
  88. * On POST, add the current user to the group
  89. *
  90. * @param array $args unused
  91. *
  92. * @return void
  93. */
  94. function handle()
  95. {
  96. parent::handle();
  97. $cur = common_current_user();
  98. try {
  99. Profile_tag_subscription::add($this->peopletag, $cur);
  100. } catch (Exception $e) {
  101. // TRANS: Server error displayed subscribing to a list fails.
  102. // TRANS: %1$s is a user nickname, %2$s is a list, %3$s is the error message (no period).
  103. $this->serverError(sprintf(_('Could not subscribe user %1$s to list %2$s: %3$s'),
  104. $cur->nickname, $this->peopletag->tag), $e->getMessage());
  105. }
  106. if ($this->boolean('ajax')) {
  107. $this->startHTML('text/xml;charset=utf-8');
  108. $this->elementStart('head');
  109. // TRANS: Title of form to subscribe to a list.
  110. // TRANS: %1%s is a user nickname, %2$s is a list, %3$s is a tagger nickname.
  111. $this->element('title', null, sprintf(_('%1$s subscribed to list %2$s by %3$s'),
  112. $cur->nickname,
  113. $this->peopletag->tag,
  114. $this->tagger->nickname));
  115. $this->elementEnd('head');
  116. $this->elementStart('body');
  117. $lf = new UnsubscribePeopletagForm($this, $this->peopletag);
  118. $lf->show();
  119. $this->elementEnd('body');
  120. $this->endHTML();
  121. } else {
  122. common_redirect(common_local_url('peopletagsubscribers',
  123. array('tagger' => $this->tagger->nickname,
  124. 'tag' =>$this->peopletag->tag)),
  125. 303);
  126. }
  127. }
  128. }