settingsaction.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Base class for settings actions
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Settings
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2008-2009 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. /**
  33. * Base class for settings group of actions
  34. *
  35. * @category Settings
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  39. * @link http://status.net/
  40. *
  41. * @see Widget
  42. */
  43. class SettingsAction extends Action
  44. {
  45. /**
  46. * A message for the user.
  47. */
  48. var $msg = null;
  49. /**
  50. * Whether the message is a good one or a bad one.
  51. */
  52. var $success = false;
  53. /**
  54. * Handle input and output a page
  55. *
  56. * @param array $args $_REQUEST arguments
  57. *
  58. * @return void
  59. */
  60. function handle($args)
  61. {
  62. parent::handle($args);
  63. if (!common_logged_in()) {
  64. // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
  65. $this->clientError(_('Not logged in.'));
  66. } else if (!common_is_real_login()) {
  67. // Cookie theft means that automatic logins can't
  68. // change important settings or see private info, and
  69. // _all_ our settings are important
  70. common_set_returnto($this->selfUrl());
  71. $user = common_current_user();
  72. if (Event::handle('RedirectToLogin', array($this, $user))) {
  73. common_redirect(common_local_url('login'), 303);
  74. }
  75. } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  76. $this->handlePost();
  77. } else {
  78. $this->showForm();
  79. }
  80. }
  81. /**
  82. * Handle a POST request
  83. *
  84. * @return boolean success flag
  85. */
  86. function handlePost()
  87. {
  88. return false;
  89. }
  90. /**
  91. * show the settings form
  92. *
  93. * @param string $msg an extra message for the user
  94. * @param string $success good message or bad message?
  95. *
  96. * @return void
  97. */
  98. function showForm($msg=null, $success=false)
  99. {
  100. $this->msg = $msg;
  101. $this->success = $success;
  102. $this->showPage();
  103. }
  104. /**
  105. * show human-readable instructions for the page
  106. *
  107. * @return void
  108. */
  109. function showPageNotice()
  110. {
  111. if ($this->msg) {
  112. $this->element('div', ($this->success) ? 'success' : 'error',
  113. $this->msg);
  114. } else {
  115. $inst = $this->getInstructions();
  116. $output = common_markup_to_html($inst);
  117. $this->elementStart('div', 'instructions');
  118. $this->raw($output);
  119. $this->elementEnd('div');
  120. }
  121. }
  122. /**
  123. * instructions recipe for sub-classes
  124. *
  125. * Subclasses should override this to return readable instructions. They'll
  126. * be processed by common_markup_to_html().
  127. *
  128. * @return string instructions text
  129. */
  130. function getInstructions()
  131. {
  132. return '';
  133. }
  134. /**
  135. * Show the local navigation menu
  136. *
  137. * This is the same for all settings, so we show it here.
  138. *
  139. * @return void
  140. */
  141. function showLocalNav()
  142. {
  143. $menu = new SettingsNav($this);
  144. $menu->show();
  145. }
  146. /**
  147. * Show notice form.
  148. *
  149. * @return nothing
  150. */
  151. function showNoticeForm()
  152. {
  153. return;
  154. }
  155. function showProfileBlock()
  156. {
  157. }
  158. }