sessionsadminpanel.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Sessions administration panel
  18. *
  19. * @category Settings
  20. * @package GNUsocial
  21. * @author Zach Copley <zach@status.net>
  22. * @copyright 2010 StatusNet, Inc.
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. defined('GNUSOCIAL') || die();
  26. /**
  27. * Admin site sessions
  28. *
  29. * @category Admin
  30. * @package GNUsocial
  31. * @author Zach Copley <zach@status.net>
  32. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  33. */
  34. class SessionsadminpanelAction extends AdminPanelAction
  35. {
  36. /**
  37. * Returns the page title
  38. *
  39. * @return string page title
  40. */
  41. public function title()
  42. {
  43. // TRANS: Title for the sessions administration panel.
  44. return _m('TITLE', 'Sessions');
  45. }
  46. /**
  47. * Instructions for using this form.
  48. *
  49. * @return string instructions
  50. */
  51. public function getInstructions()
  52. {
  53. // TRANS: Instructions for the sessions administration panel.
  54. return _('Session settings for this StatusNet site');
  55. }
  56. /**
  57. * Show the site admin panel form
  58. *
  59. * @return void
  60. */
  61. public function showForm()
  62. {
  63. $form = new SessionsAdminPanelForm($this);
  64. $form->show();
  65. return;
  66. }
  67. /**
  68. * Save settings from the form
  69. *
  70. * @return void
  71. */
  72. public function saveSettings()
  73. {
  74. static $booleans = array('sessions' => array('handle', 'debug'));
  75. $values = array();
  76. foreach ($booleans as $section => $parts) {
  77. foreach ($parts as $setting) {
  78. $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0;
  79. }
  80. }
  81. // This throws an exception on validation errors
  82. $this->validate($values);
  83. // assert(all values are valid);
  84. $config = new Config();
  85. $config->query('START TRANSACTION');
  86. foreach ($booleans as $section => $parts) {
  87. foreach ($parts as $setting) {
  88. Config::save($section, $setting, $values[$section][$setting]);
  89. }
  90. }
  91. $config->query('COMMIT');
  92. return;
  93. }
  94. public function validate(&$values)
  95. {
  96. // stub
  97. }
  98. }
  99. // @todo FIXME: Class documentation missing.
  100. class SessionsAdminPanelForm extends AdminForm
  101. {
  102. /**
  103. * ID of the form
  104. *
  105. * @return int ID of the form
  106. */
  107. public function id()
  108. {
  109. return 'sessionsadminpanel';
  110. }
  111. /**
  112. * class of the form
  113. *
  114. * @return string class of the form
  115. */
  116. public function formClass()
  117. {
  118. return 'form_settings';
  119. }
  120. /**
  121. * Action of the form
  122. *
  123. * @return string URL of the action
  124. */
  125. public function action()
  126. {
  127. return common_local_url('sessionsadminpanel');
  128. }
  129. /**
  130. * Data elements of the form
  131. *
  132. * @return void
  133. */
  134. public function formData()
  135. {
  136. $this->out->elementStart('fieldset', array('id' => 'settings_user_sessions'));
  137. // TRANS: Fieldset legend on the sessions administration panel.
  138. $this->out->element('legend', null, _m('LEGEND', 'Sessions'));
  139. $this->out->elementStart('ul', 'form_data');
  140. $this->li();
  141. // TRANS: Checkbox title on the sessions administration panel.
  142. // TRANS: Indicates if StatusNet should handle session administration.
  143. $this->out->checkbox(
  144. 'handle',
  145. _('Handle sessions'),
  146. (bool) $this->value('handle', 'sessions'),
  147. // TRANS: Checkbox title on the sessions administration panel.
  148. // TRANS: Indicates if StatusNet should handle session administration.
  149. _('Handle sessions ourselves.')
  150. );
  151. $this->unli();
  152. $this->li();
  153. // TRANS: Checkbox label on the sessions administration panel.
  154. // TRANS: Indicates if StatusNet should write session debugging output.
  155. $this->out->checkbox(
  156. 'debug',
  157. _('Session debugging'),
  158. (bool) $this->value('debug', 'sessions'),
  159. // TRANS: Checkbox title on the sessions administration panel.
  160. _('Enable debugging output for sessions.')
  161. );
  162. $this->unli();
  163. $this->out->elementEnd('ul');
  164. $this->out->elementEnd('fieldset');
  165. }
  166. /**
  167. * Action elements
  168. *
  169. * @return void
  170. */
  171. public function formActions()
  172. {
  173. $this->out->submit(
  174. '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. }
  183. }