disfavor.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Disfavor action.
  4. *
  5. * PHP version 5
  6. *
  7. * @category Action
  8. * @package GNUsocial
  9. * @author Evan Prodromou <evan@status.net>
  10. * @author Robin Millette <millette@status.net>
  11. * @author Mikael Nordfeldth <mmn@hethane.se>
  12. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  13. * @link http://www.gnu.org/software/social/
  14. *
  15. * StatusNet - the distributed open-source microblogging tool
  16. * Copyright (C) 2008, 2009, StatusNet, Inc.
  17. *
  18. * This program is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License as published by
  20. * the Free Software Foundation, either version 3 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU Affero General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Affero General Public License
  29. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. */
  31. if (!defined('GNUSOCIAL')) { exit(1); }
  32. /**
  33. * DisfavorAction class.
  34. *
  35. * @category Action
  36. * @package GNUsocial
  37. * @author Evan Prodromou <evan@status.net>
  38. * @author Robin Millette <millette@status.net>
  39. * @author Mikael Nordfeldth <mmn@hethane.se>
  40. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  41. * @link http://www.gnu.org/software/social/
  42. */
  43. class DisfavorAction extends FormAction
  44. {
  45. public function showForm($msg=null, $success=false)
  46. {
  47. if ($success) {
  48. common_redirect(common_local_url('showfavorites',
  49. array('nickname' => $this->scoped->nickname)), 303);
  50. }
  51. parent::showForm($msg, $success);
  52. }
  53. protected function handlePost()
  54. {
  55. $id = $this->trimmed('notice');
  56. $notice = Notice::getKV($id);
  57. if (!$notice instanceof Notice) {
  58. $this->serverError(_('Notice not found'));
  59. }
  60. $fave = new Fave();
  61. $fave->user_id = $this->scoped->id;
  62. $fave->notice_id = $notice->id;
  63. if (!$fave->find(true)) {
  64. throw new NoResultException($fave);
  65. }
  66. $result = $fave->delete();
  67. if (!$result) {
  68. common_log_db_error($fave, 'DELETE', __FILE__);
  69. // TRANS: Server error displayed when removing a favorite from the database fails.
  70. $this->serverError(_('Could not delete favorite.'));
  71. }
  72. Fave::blowCacheForProfileId($this->scoped->id);
  73. if (StatusNet::isAjax()) {
  74. $this->startHTML('text/xml;charset=utf-8');
  75. $this->elementStart('head');
  76. // TRANS: Title for page on which favorites can be added.
  77. $this->element('title', null, _('Add to favorites'));
  78. $this->elementEnd('head');
  79. $this->elementStart('body');
  80. $favor = new FavorForm($this, $notice);
  81. $favor->show();
  82. $this->elementEnd('body');
  83. $this->endHTML();
  84. exit;
  85. }
  86. }
  87. }