flagprofile.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * Add a flag to a profile
  4. *
  5. * PHP version 5
  6. *
  7. * @category Action
  8. * @package StatusNet
  9. *
  10. * @author Evan Prodromou <evan@status.net>
  11. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  12. *
  13. * @see http://status.net/
  14. *
  15. * StatusNet - the distributed open-source microblogging tool
  16. * Copyright (C) 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('STATUSNET')) {
  32. exit(1);
  33. }
  34. /**
  35. * Action to flag a profile.
  36. *
  37. * @category Action
  38. * @package StatusNet
  39. *
  40. * @author Evan Prodromou <evan@status.net>
  41. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  42. *
  43. * @see http://status.net/
  44. */
  45. class FlagprofileAction extends ProfileFormAction
  46. {
  47. /**
  48. * Take arguments for running
  49. *
  50. * @param array $args $_REQUEST args
  51. *
  52. * @return bool success flag
  53. */
  54. public function prepare(array $args = [])
  55. {
  56. if (!parent::prepare($args)) {
  57. return false;
  58. }
  59. $user = common_current_user();
  60. assert(!empty($user)); // checked above
  61. assert(!empty($this->profile)); // checked above
  62. return true;
  63. }
  64. /**
  65. * Handle request
  66. *
  67. * Overriding the base Action's handle() here to deal check
  68. * for Ajax and return an HXR response if necessary
  69. *
  70. * @param array $args $_REQUEST args; handled in prepare()
  71. *
  72. * @return void
  73. */
  74. public function handle()
  75. {
  76. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  77. $this->handlePost();
  78. if (!$this->boolean('ajax')) {
  79. $this->returnToPrevious();
  80. }
  81. }
  82. }
  83. /**
  84. * Handle POST
  85. *
  86. * @return void
  87. */
  88. public function handlePost()
  89. {
  90. $user = common_current_user();
  91. assert(!empty($user));
  92. assert(!empty($this->profile));
  93. // throws an exception on error
  94. if (User_flag_profile::exists($this->profile->id,
  95. $user->id)) {
  96. // We'll return to the profile page (or return the updated AJAX form)
  97. // showing the current state, so no harm done.
  98. } else {
  99. User_flag_profile::create($user->id, $this->profile->id);
  100. }
  101. if ($this->boolean('ajax')) {
  102. $this->ajaxResults();
  103. }
  104. }
  105. /**
  106. * Return results as AJAX message
  107. *
  108. * @return void
  109. */
  110. public function ajaxResults()
  111. {
  112. $this->startHTML('text/xml;charset=utf-8');
  113. $this->elementStart('head');
  114. // TRANS: AJAX form title for a flagged profile.
  115. $this->element('title', null, _m('Flagged for review'));
  116. $this->elementEnd('head');
  117. $this->elementStart('body');
  118. // TRANS: Body text for AJAX form when a profile has been flagged for review.
  119. $this->element('p', 'flagged', _m('Flagged'));
  120. $this->elementEnd('body');
  121. $this->endHTML();
  122. }
  123. }