clearflag.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Clear all flags for a profile
  4. *
  5. * PHP version 5
  6. *
  7. * @category Action
  8. * @package StatusNet
  9. * @author Evan Prodromou <evan@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) 2009, 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('STATUSNET')) {
  30. exit(1);
  31. }
  32. /**
  33. * Action to clear flags for a profile
  34. *
  35. * @category Action
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  39. * @link http://status.net/
  40. */
  41. class ClearflagAction extends ProfileFormAction
  42. {
  43. /**
  44. * Take arguments for running
  45. *
  46. * @param array $args $_REQUEST args
  47. *
  48. * @return boolean success flag
  49. */
  50. function prepare($args)
  51. {
  52. if (!parent::prepare($args)) {
  53. return false;
  54. }
  55. $user = common_current_user();
  56. assert(!empty($user)); // checked above
  57. assert(!empty($this->profile)); // checked above
  58. return true;
  59. }
  60. /**
  61. * Handle request
  62. *
  63. * Overriding the base Action's handle() here to deal check
  64. * for Ajax and return an HXR response if necessary
  65. *
  66. * @param array $args $_REQUEST args; handled in prepare()
  67. *
  68. * @return void
  69. */
  70. function handle($args)
  71. {
  72. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  73. $this->handlePost();
  74. if (!$this->boolean('ajax')) {
  75. $this->returnToPrevious();
  76. }
  77. }
  78. }
  79. /**
  80. * Handle POST
  81. *
  82. * Executes the actions; deletes all flags
  83. *
  84. * @return void
  85. */
  86. function handlePost()
  87. {
  88. $ufp = new User_flag_profile();
  89. $result = $ufp->query('UPDATE user_flag_profile ' .
  90. 'SET cleared = now() ' .
  91. 'WHERE cleared is null ' .
  92. 'AND profile_id = ' . $this->profile->id);
  93. if ($result == false) {
  94. // TRANS: Server exception given when flags could not be cleared.
  95. // TRANS: %s is a profile nickname.
  96. $msg = sprintf(_m('Could not clear flags for profile "%s".'),
  97. $this->profile->nickname);
  98. throw new ServerException($msg);
  99. }
  100. $ufp->free();
  101. if ($this->boolean('ajax')) {
  102. $this->ajaxResults();
  103. }
  104. }
  105. /**
  106. * Return results in ajax form
  107. *
  108. * @return void
  109. */
  110. function ajaxResults()
  111. {
  112. $this->startHTML('text/xml;charset=utf-8');
  113. $this->elementStart('head');
  114. // TRANS: Title for AJAX form to indicated that flags were removed.
  115. $this->element('title', null, _m('Flags cleared'));
  116. $this->elementEnd('head');
  117. $this->elementStart('body');
  118. // TRANS: Body element for "flags cleared" form.
  119. $this->element('p', 'cleared', _m('Cleared'));
  120. $this->elementEnd('body');
  121. $this->endHTML();
  122. }
  123. }