anonfavor.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. // Throws exception
  60. $stored = Fave::addNew($profile, $notice);
  61. if ($this->boolean('ajax')) {
  62. $this->startHTML('text/xml;charset=utf-8');
  63. $this->elementStart('head');
  64. // TRANS: Title.
  65. $this->element('title', null, _m('Disfavor favorite'));
  66. $this->elementEnd('head');
  67. $this->elementStart('body');
  68. $disfavor = new AnonDisFavorForm($this, $notice);
  69. $disfavor->show();
  70. $this->elementEnd('body');
  71. $this->endHTML();
  72. } else {
  73. $this->returnToPrevious();
  74. }
  75. }
  76. /**
  77. * If returnto not set, return to the public stream.
  78. *
  79. * @return string URL
  80. */
  81. function defaultReturnTo()
  82. {
  83. $returnto = common_get_returnto();
  84. if (empty($returnto)) {
  85. return common_local_url('public');
  86. } else {
  87. return $returnto;
  88. }
  89. }
  90. }