anondisfavor.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Anonymous disfavor action
  4. *
  5. * PHP version 5
  6. *
  7. * @category Action
  8. * @package StatusNet
  9. * @author Zach Copley <zach@status.net>
  10. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  11. * @link http://status.net/
  12. *
  13. * StatusNet - the distributed open-source microblogging tool
  14. * Copyright (C) 2010, StatusNet, Inc.
  15. *
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License as published by
  18. * the Free Software Foundation, either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. */
  29. if (!defined('GNUSOCIAL')) { exit(1); }
  30. /**
  31. * Anonymous disfavor class
  32. *
  33. * @category Action
  34. * @package StatusNet
  35. * @author Zach Copley <zach@status.net>
  36. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  37. * @link http://status.net/
  38. */
  39. class AnonDisfavorAction extends RedirectingAction
  40. {
  41. /**
  42. * Class handler.
  43. *
  44. * @param array $args query arguments
  45. *
  46. * @return void
  47. */
  48. function handle($args)
  49. {
  50. parent::handle($args);
  51. $profile = AnonymousFavePlugin::getAnonProfile();
  52. if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
  53. $this->clientError(
  54. // TRANS: Client error.
  55. _m('Could not disfavor notice! Please make sure your browser has cookies enabled.')
  56. );
  57. }
  58. $id = $this->trimmed('notice');
  59. $notice = Notice::getKV($id);
  60. $token = $this->checkSessionToken();
  61. $fave = new Fave();
  62. $fave->user_id = $profile->id;
  63. $fave->notice_id = $notice->id;
  64. if (!$fave->find(true)) {
  65. throw new NoResultException($fave);
  66. }
  67. $result = $fave->delete();
  68. if (!$result) {
  69. common_log_db_error($fave, 'DELETE', __FILE__);
  70. // TRANS: Server error.
  71. $this->serverError(_m('Could not delete favorite.'));
  72. }
  73. Fave::blowCacheForProfileId($profile->id);
  74. if ($this->boolean('ajax')) {
  75. $this->startHTML('text/xml;charset=utf-8');
  76. $this->elementStart('head');
  77. // TRANS: Title.
  78. $this->element('title', null, _m('Add to favorites'));
  79. $this->elementEnd('head');
  80. $this->elementStart('body');
  81. $favor = new AnonFavorForm($this, $notice);
  82. $favor->show();
  83. $this->elementEnd('body');
  84. $this->endHTML();
  85. } else {
  86. $this->returnToPrevious();
  87. }
  88. }
  89. /**
  90. * If returnto not set, return to the public stream.
  91. *
  92. * @return string URL
  93. */
  94. function defaultReturnTo()
  95. {
  96. $returnto = common_get_returnto();
  97. if (empty($returnto)) {
  98. return common_local_url('public');
  99. } else {
  100. return $returnto;
  101. }
  102. }
  103. }