anonfavor.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Anonyous favor 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 favor 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 AnonFavorAction 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. // TRANS: Client error.
  54. $this->clientError(_m('Could not favor notice! Please make sure your browser has cookies enabled.'));
  55. }
  56. $id = $this->trimmed('notice');
  57. $notice = Notice::getKV($id);
  58. $token = $this->checkSessionToken();
  59. if (Fave::existsForProfile($notice, $profile)) {
  60. // TRANS: Client error.
  61. throw new AlreadyFulfilledException(_m('This notice is already a favorite!'));
  62. }
  63. // Throws exception
  64. $stored = Fave::addNew($profile, $notice);
  65. if ($this->boolean('ajax')) {
  66. $this->startHTML('text/xml;charset=utf-8');
  67. $this->elementStart('head');
  68. // TRANS: Title.
  69. $this->element('title', null, _m('Disfavor favorite'));
  70. $this->elementEnd('head');
  71. $this->elementStart('body');
  72. $disfavor = new AnonDisFavorForm($this, $notice);
  73. $disfavor->show();
  74. $this->elementEnd('body');
  75. $this->endHTML();
  76. } else {
  77. $this->returnToPrevious();
  78. }
  79. }
  80. /**
  81. * If returnto not set, return to the public stream.
  82. *
  83. * @return string URL
  84. */
  85. function defaultReturnTo()
  86. {
  87. $returnto = common_get_returnto();
  88. if (empty($returnto)) {
  89. return common_local_url('public');
  90. } else {
  91. return $returnto;
  92. }
  93. }
  94. }