searchunsub.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. defined('GNUSOCIAL') || die();
  17. /**
  18. * Search unsubscription action
  19. *
  20. * Takes parameters:
  21. *
  22. * - token: session token to prevent CSRF attacks
  23. * - ajax: boolean; whether to return Ajax or full-browser results
  24. *
  25. * Only works if the current user is logged in.
  26. *
  27. * @category Plugin
  28. * @package SearchSubPlugin
  29. * @author Evan Prodromou <evan@status.net>
  30. * @author Brion Vibber <brion@status.net>
  31. * @copyright 2011-2019 Free Software Foundation, Inc http://www.fsf.org
  32. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  33. */
  34. class SearchunsubAction extends SearchsubAction
  35. {
  36. /**
  37. * Handle request
  38. *
  39. * Does the subscription and returns results.
  40. *
  41. * @return void
  42. * @throws ClientException
  43. */
  44. public function handle()
  45. {
  46. // Throws exception on error
  47. SearchSub::cancel(
  48. $this->user->getProfile(),
  49. $this->search
  50. );
  51. if ($this->boolean('ajax')) {
  52. $this->startHTML('text/xml;charset=utf-8');
  53. $this->elementStart('head');
  54. // TRANS: Page title when search unsubscription succeeded.
  55. $this->element('title', null, _m('Unsubscribed'));
  56. $this->elementEnd('head');
  57. $this->elementStart('body');
  58. $subscribe = new SearchSubForm($this, $this->search);
  59. $subscribe->show();
  60. $this->elementEnd('body');
  61. $this->endHTML();
  62. } else {
  63. $url = common_local_url(
  64. 'search',
  65. array('search' => $this->search)
  66. );
  67. common_redirect($url, 303);
  68. }
  69. }
  70. }