flagprofile.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * Add a flag to 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 flag 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 FlagprofileAction 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(array $args = array())
  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()
  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. * @return void
  83. */
  84. function handlePost()
  85. {
  86. $user = common_current_user();
  87. assert(!empty($user));
  88. assert(!empty($this->profile));
  89. // throws an exception on error
  90. if (User_flag_profile::exists($this->profile->id,
  91. $user->id)) {
  92. // We'll return to the profile page (or return the updated AJAX form)
  93. // showing the current state, so no harm done.
  94. } else {
  95. User_flag_profile::create($user->id, $this->profile->id);
  96. }
  97. if ($this->boolean('ajax')) {
  98. $this->ajaxResults();
  99. }
  100. }
  101. /**
  102. * Return results as AJAX message
  103. *
  104. * @return void
  105. */
  106. function ajaxResults()
  107. {
  108. $this->startHTML('text/xml;charset=utf-8');
  109. $this->elementStart('head');
  110. // TRANS: AJAX form title for a flagged profile.
  111. $this->element('title', null, _m('Flagged for review'));
  112. $this->elementEnd('head');
  113. $this->elementStart('body');
  114. // TRANS: Body text for AJAX form when a profile has been flagged for review.
  115. $this->element('p', 'flagged', _m('Flagged'));
  116. $this->elementEnd('body');
  117. $this->endHTML();
  118. }
  119. }