profileformaction.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. var $profile = null;
  44. /**
  45. * Take arguments for running
  46. *
  47. * @param array $args $_REQUEST args
  48. *
  49. * @return boolean success flag
  50. */
  51. function prepare(array $args = array())
  52. {
  53. parent::prepare($args);
  54. $this->checkSessionToken();
  55. if (!common_logged_in()) {
  56. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  57. // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
  58. $this->clientError(_('Not logged in.'));
  59. } else {
  60. // Redirect to login.
  61. common_set_returnto($this->selfUrl());
  62. $user = common_current_user();
  63. if (Event::handle('RedirectToLogin', array($this, $user))) {
  64. common_redirect(common_local_url('login'), 303);
  65. }
  66. }
  67. return false;
  68. }
  69. $id = $this->trimmed('profileid');
  70. if (!$id) {
  71. // TRANS: Client error displayed when trying to change user options without specifying a user to work on.
  72. $this->clientError(_('No profile specified.'));
  73. }
  74. $this->profile = Profile::getKV('id', $id);
  75. if (!$this->profile) {
  76. // TRANS: Client error displayed when trying to change user options without specifying an existing user to work on.
  77. $this->clientError(_('No profile with that ID.'));
  78. }
  79. return true;
  80. }
  81. /**
  82. * Handle request
  83. *
  84. * @param array $args $_REQUEST args; handled in prepare()
  85. *
  86. * @return void
  87. */
  88. function handle()
  89. {
  90. parent::handle();
  91. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  92. try {
  93. $this->handlePost();
  94. } catch (AlreadyFulfilledException $e) {
  95. // 'tis alright
  96. }
  97. $this->returnToPrevious();
  98. }
  99. }
  100. /**
  101. * handle a POST request
  102. *
  103. * sub-classes should overload this request
  104. *
  105. * @return void
  106. */
  107. function handlePost()
  108. {
  109. // TRANS: Server error displayed when using an unimplemented method.
  110. $this->serverError(_("Unimplemented method."));
  111. }
  112. }