The official, canonical postActiv repository. http://www.postactiv.com

sessionsadminpanel.php 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. // !TODO: I WRITE HTML, REFACTOR FOR SMARTY
  3. /* ============================================================================
  4. * Title: SessionsAdminPanel
  5. * Sessions administration panel
  6. *
  7. * postActiv:
  8. * the micro-blogging software
  9. *
  10. * Copyright:
  11. * Copyright (C) 2016-2018, Maiyannah Bishop
  12. *
  13. * Derived from code copyright various sources:
  14. * o GNU Social (C) 2013-2016, Free Software Foundation, Inc
  15. * o StatusNet (C) 2008-2012, StatusNet, Inc
  16. * ----------------------------------------------------------------------------
  17. * License:
  18. * This program is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License as published by
  20. * the Free Software Foundation, either version 3 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU Affero General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Affero General Public License
  29. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. *
  31. * <https://www.gnu.org/licenses/agpl.html>
  32. * ----------------------------------------------------------------------------
  33. * About:
  34. * Sessions administration panel
  35. *
  36. * PHP version:
  37. * Tested with PHP 7.0
  38. * ----------------------------------------------------------------------------
  39. * File Authors:
  40. * o Zach Copley
  41. * o Siebrand Mazeland <s.mazeland@xs4all.nl>
  42. * o Maiyannah Bishop <maiyannah.bishop@postactiv.com>
  43. *
  44. * Web:
  45. * o postActiv <http://www.postactiv.com>
  46. * o GNU social <https://www.gnu.org/s/social/>
  47. * ============================================================================
  48. */
  49. // This file is formatted so that it provides useful documentation output in
  50. // NaturalDocs. Please be considerate of this before changing formatting.
  51. if (!defined('POSTACTIV')) { exit(1); }
  52. /**
  53. * Admin site sessions
  54. */
  55. class SessionsadminpanelAction extends AdminPanelAction
  56. {
  57. /**
  58. * Returns the page title
  59. *
  60. * @return string page title
  61. */
  62. function title()
  63. {
  64. // TRANS: Title for the sessions administration panel.
  65. return _m('TITLE','Sessions');
  66. }
  67. /**
  68. * Instructions for using this form.
  69. *
  70. * @return string instructions
  71. */
  72. function getInstructions()
  73. {
  74. // TRANS: Instructions for the sessions administration panel.
  75. return _('Session settings for this StatusNet site');
  76. }
  77. /**
  78. * Show the site admin panel form
  79. *
  80. * @return void
  81. */
  82. function showForm()
  83. {
  84. $form = new SessionsAdminPanelForm($this);
  85. $form->show();
  86. return;
  87. }
  88. /**
  89. * Save settings from the form
  90. *
  91. * @return void
  92. */
  93. function saveSettings()
  94. {
  95. static $booleans = array('sessions' => array('handle', 'debug'));
  96. $values = array();
  97. foreach ($booleans as $section => $parts) {
  98. foreach ($parts as $setting) {
  99. $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0;
  100. }
  101. }
  102. // This throws an exception on validation errors
  103. $this->validate($values);
  104. // assert(all values are valid);
  105. $config = new Config();
  106. $config->query('BEGIN');
  107. foreach ($booleans as $section => $parts) {
  108. foreach ($parts as $setting) {
  109. Config::save($section, $setting, $values[$section][$setting]);
  110. }
  111. }
  112. $config->query('COMMIT');
  113. return;
  114. }
  115. function validate(&$values)
  116. {
  117. // stub
  118. }
  119. }
  120. // @todo FIXME: Class documentation missing.
  121. class SessionsAdminPanelForm extends AdminForm
  122. {
  123. /**
  124. * ID of the form
  125. *
  126. * @return int ID of the form
  127. */
  128. function id()
  129. {
  130. return 'sessionsadminpanel';
  131. }
  132. /**
  133. * class of the form
  134. *
  135. * @return string class of the form
  136. */
  137. function formClass()
  138. {
  139. return 'form_settings';
  140. }
  141. /**
  142. * Action of the form
  143. *
  144. * @return string URL of the action
  145. */
  146. function action()
  147. {
  148. return common_local_url('sessionsadminpanel');
  149. }
  150. /**
  151. * Data elements of the form
  152. *
  153. * @return void
  154. */
  155. function formData()
  156. {
  157. $this->out->elementStart('fieldset', array('id' => 'settings_user_sessions'));
  158. // TRANS: Fieldset legend on the sessions administration panel.
  159. $this->out->element('legend', null, _m('LEGEND','Sessions'));
  160. $this->out->elementStart('ul', 'form_data');
  161. $this->li();
  162. // TRANS: Checkbox title on the sessions administration panel.
  163. // TRANS: Indicates if StatusNet should handle session administration.
  164. $this->out->checkbox('handle', _('Handle sessions'),
  165. (bool) $this->value('handle', 'sessions'),
  166. // TRANS: Checkbox title on the sessions administration panel.
  167. // TRANS: Indicates if StatusNet should handle session administration.
  168. _('Handle sessions ourselves.'));
  169. $this->unli();
  170. $this->li();
  171. // TRANS: Checkbox label on the sessions administration panel.
  172. // TRANS: Indicates if StatusNet should write session debugging output.
  173. $this->out->checkbox('debug', _('Session debugging'),
  174. (bool) $this->value('debug', 'sessions'),
  175. // TRANS: Checkbox title on the sessions administration panel.
  176. _('Enable debugging output for sessions.'));
  177. $this->unli();
  178. $this->out->elementEnd('ul');
  179. $this->out->elementEnd('fieldset');
  180. }
  181. /**
  182. * Action elements
  183. *
  184. * @return void
  185. */
  186. function formActions()
  187. {
  188. $this->out->submit('submit',
  189. // TRANS: Submit button text on the sessions administration panel.
  190. _m('BUTTON','Save'),
  191. 'submit',
  192. null,
  193. // TRANS: Title for submit button on the sessions administration panel.
  194. _('Save session settings'));
  195. }
  196. }
  197. // END OF FILE
  198. // ============================================================================
  199. ?>