profileformaction.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * Superclass for actions that operate on a user
  4. *
  5. * PHP version 5
  6. *
  7. * StatusNet - the distributed open-source microblogging tool
  8. * Copyright (C) 2009, StatusNet, Inc.
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @category Action
  24. * @package StatusNet
  25. * @author Evan Prodromou <evan@status.net>
  26. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. /**
  33. * Superclass for actions that operate on a user
  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 ProfileFormAction extends RedirectingAction
  42. {
  43. public $widgetOpts;
  44. public $scoped;
  45. var $profile = null;
  46. /**
  47. * Take arguments for running
  48. *
  49. * @param array $args $_REQUEST args
  50. *
  51. * @return boolean success flag
  52. */
  53. function prepare(array $args = array())
  54. {
  55. parent::prepare($args);
  56. $this->checkSessionToken();
  57. if (!common_logged_in()) {
  58. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  59. // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
  60. $this->clientError(_('Not logged in.'));
  61. } else {
  62. // Redirect to login.
  63. common_set_returnto($this->selfUrl());
  64. $user = common_current_user();
  65. if (Event::handle('RedirectToLogin', array($this, $user))) {
  66. common_redirect(common_local_url('login'), 303);
  67. }
  68. }
  69. return false;
  70. }
  71. $id = $this->trimmed('profileid');
  72. if (!$id) {
  73. // TRANS: Client error displayed when trying to change user options without specifying a user to work on.
  74. $this->clientError(_('No profile specified.'));
  75. }
  76. $this->profile = Profile::getKV('id', $id);
  77. if (!$this->profile) {
  78. // TRANS: Client error displayed when trying to change user options without specifying an existing user to work on.
  79. $this->clientError(_('No profile with that ID.'));
  80. }
  81. return true;
  82. }
  83. /**
  84. * Handle request
  85. *
  86. * @param array $args $_REQUEST args; handled in prepare()
  87. *
  88. * @return void
  89. */
  90. function handle()
  91. {
  92. parent::handle();
  93. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  94. try {
  95. $this->handlePost();
  96. } catch (AlreadyFulfilledException $e) {
  97. // 'tis alright
  98. }
  99. $this->returnToPrevious();
  100. }
  101. }
  102. /**
  103. * handle a POST request
  104. *
  105. * sub-classes should overload this request
  106. *
  107. * @return void
  108. */
  109. function handlePost()
  110. {
  111. // TRANS: Server error displayed when using an unimplemented method.
  112. $this->serverError(_("Unimplemented method."));
  113. }
  114. }