sessionsadminpanel.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Sessions administration panel
  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 Zach Copley <zach@status.net>
  25. * @copyright 2010 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')) {
  30. exit(1);
  31. }
  32. /**
  33. * Admin site sessions
  34. *
  35. * @category Admin
  36. * @package StatusNet
  37. * @author Zach Copley <zach@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. class SessionsadminpanelAction extends AdminPanelAction
  42. {
  43. /**
  44. * Returns the page title
  45. *
  46. * @return string page title
  47. */
  48. function title()
  49. {
  50. // TRANS: Title for the sessions administration panel.
  51. return _m('TITLE','Sessions');
  52. }
  53. /**
  54. * Instructions for using this form.
  55. *
  56. * @return string instructions
  57. */
  58. function getInstructions()
  59. {
  60. // TRANS: Instructions for the sessions administration panel.
  61. return _('Session settings for this StatusNet site');
  62. }
  63. /**
  64. * Show the site admin panel form
  65. *
  66. * @return void
  67. */
  68. function showForm()
  69. {
  70. $form = new SessionsAdminPanelForm($this);
  71. $form->show();
  72. return;
  73. }
  74. /**
  75. * Save settings from the form
  76. *
  77. * @return void
  78. */
  79. function saveSettings()
  80. {
  81. static $booleans = array('sessions' => array('handle', 'debug'));
  82. $values = array();
  83. foreach ($booleans as $section => $parts) {
  84. foreach ($parts as $setting) {
  85. $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0;
  86. }
  87. }
  88. // This throws an exception on validation errors
  89. $this->validate($values);
  90. // assert(all values are valid);
  91. $config = new Config();
  92. $config->query('BEGIN');
  93. foreach ($booleans as $section => $parts) {
  94. foreach ($parts as $setting) {
  95. Config::save($section, $setting, $values[$section][$setting]);
  96. }
  97. }
  98. $config->query('COMMIT');
  99. return;
  100. }
  101. function validate(&$values)
  102. {
  103. // stub
  104. }
  105. }
  106. // @todo FIXME: Class documentation missing.
  107. class SessionsAdminPanelForm extends AdminForm
  108. {
  109. /**
  110. * ID of the form
  111. *
  112. * @return int ID of the form
  113. */
  114. function id()
  115. {
  116. return 'sessionsadminpanel';
  117. }
  118. /**
  119. * class of the form
  120. *
  121. * @return string class of the form
  122. */
  123. function formClass()
  124. {
  125. return 'form_settings';
  126. }
  127. /**
  128. * Action of the form
  129. *
  130. * @return string URL of the action
  131. */
  132. function action()
  133. {
  134. return common_local_url('sessionsadminpanel');
  135. }
  136. /**
  137. * Data elements of the form
  138. *
  139. * @return void
  140. */
  141. function formData()
  142. {
  143. $this->out->elementStart('fieldset', array('id' => 'settings_user_sessions'));
  144. // TRANS: Fieldset legend on the sessions administration panel.
  145. $this->out->element('legend', null, _m('LEGEND','Sessions'));
  146. $this->out->elementStart('ul', 'form_data');
  147. $this->li();
  148. // TRANS: Checkbox title on the sessions administration panel.
  149. // TRANS: Indicates if StatusNet should handle session administration.
  150. $this->out->checkbox('handle', _('Handle sessions'),
  151. (bool) $this->value('handle', 'sessions'),
  152. // TRANS: Checkbox title on the sessions administration panel.
  153. // TRANS: Indicates if StatusNet should handle session administration.
  154. _('Handle sessions ourselves.'));
  155. $this->unli();
  156. $this->li();
  157. // TRANS: Checkbox label on the sessions administration panel.
  158. // TRANS: Indicates if StatusNet should write session debugging output.
  159. $this->out->checkbox('debug', _('Session debugging'),
  160. (bool) $this->value('debug', 'sessions'),
  161. // TRANS: Checkbox title on the sessions administration panel.
  162. _('Enable debugging output for sessions.'));
  163. $this->unli();
  164. $this->out->elementEnd('ul');
  165. $this->out->elementEnd('fieldset');
  166. }
  167. /**
  168. * Action elements
  169. *
  170. * @return void
  171. */
  172. function formActions()
  173. {
  174. $this->out->submit('submit',
  175. // TRANS: Submit button text on the sessions administration panel.
  176. _m('BUTTON','Save'),
  177. 'submit',
  178. null,
  179. // TRANS: Title for submit button on the sessions administration panel.
  180. _('Save session settings'));
  181. }
  182. }