accessadminpanel.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. * Site access 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. * Administer site access settings
  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 AccessadminpanelAction extends AdminPanelAction
  35. {
  36. /**
  37. * Returns the page title
  38. *
  39. * @return string page title
  40. */
  41. public function title()
  42. {
  43. // TRANS: Page title for Access admin panel that allows configuring site access.
  44. return _('Access');
  45. }
  46. /**
  47. * Instructions for using this form.
  48. *
  49. * @return string instructions
  50. */
  51. public function getInstructions()
  52. {
  53. // TRANS: Page notice.
  54. return _('Site access settings');
  55. }
  56. /**
  57. * Show the site admin panel form
  58. *
  59. * @return void
  60. */
  61. public function showForm()
  62. {
  63. $form = new AccessAdminPanelForm($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('site' => array('private', 'inviteonly', 'closed'),
  75. 'public' => array('localonly'));
  76. foreach ($booleans as $section => $parts) {
  77. foreach ($parts as $setting) {
  78. $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0;
  79. }
  80. }
  81. $config = new Config();
  82. $config->query('START TRANSACTION');
  83. foreach ($booleans as $section => $parts) {
  84. foreach ($parts as $setting) {
  85. Config::save($section, $setting, $values[$section][$setting]);
  86. }
  87. }
  88. $config->query('COMMIT');
  89. return;
  90. }
  91. }
  92. class AccessAdminPanelForm extends AdminForm
  93. {
  94. /**
  95. * ID of the form
  96. *
  97. * @return int ID of the form
  98. */
  99. public function id()
  100. {
  101. return 'form_site_admin_panel';
  102. }
  103. /**
  104. * class of the form
  105. *
  106. * @return string class of the form
  107. */
  108. public function formClass()
  109. {
  110. return 'form_settings';
  111. }
  112. /**
  113. * Action of the form
  114. *
  115. * @return string URL of the action
  116. */
  117. public function action()
  118. {
  119. return common_local_url('accessadminpanel');
  120. }
  121. /**
  122. * Data elements of the form
  123. *
  124. * @return void
  125. */
  126. public function formData()
  127. {
  128. $this->out->elementStart('fieldset', array('id' => 'settings_admin_account_access'));
  129. // TRANS: Form legend for registration form.
  130. $this->out->element('legend', null, _('Registration'));
  131. $this->out->elementStart('ul', 'form_data');
  132. $this->li();
  133. // TRANS: Checkbox instructions for admin setting "Invite only".
  134. $instructions = _('Make registration invitation only.');
  135. // TRANS: Checkbox label for configuring site as invite only.
  136. $this->out->checkbox(
  137. 'inviteonly',
  138. _('Invite only'),
  139. (bool) $this->value('inviteonly'),
  140. $instructions
  141. );
  142. $this->unli();
  143. $this->li();
  144. // TRANS: Checkbox instructions for admin setting "Closed" (no new registrations).
  145. $instructions = _('Disable new registrations.');
  146. // TRANS: Checkbox label for disabling new user registrations.
  147. $this->out->checkbox(
  148. 'closed',
  149. _('Closed'),
  150. (bool) $this->value('closed'),
  151. $instructions
  152. );
  153. $this->unli();
  154. $this->out->elementEnd('ul');
  155. $this->out->elementEnd('fieldset');
  156. // Public access settings (login requirements for feeds etc.)
  157. $this->out->elementStart('fieldset', ['id' => 'settings_admin_public_access']);
  158. // TRANS: Form legend for registration form.
  159. $this->out->element('legend', null, _('Feed access'));
  160. $this->out->elementStart('ul', 'form_data');
  161. $this->li();
  162. // TRANS: Checkbox instructions for admin setting "Private".
  163. $instructions = _('Prohibit anonymous users (not logged in) from viewing site?');
  164. // TRANS: Checkbox label for prohibiting anonymous users from viewing site.
  165. $this->out->checkbox(
  166. 'private',
  167. _m('LABEL', 'Private'),
  168. (bool) $this->value('private'),
  169. $instructions
  170. );
  171. $this->unli();
  172. $this->li();
  173. // TRANS: Description of the full network notice stream views..
  174. $instructions = _('The full network view includes (public) remote notices which may be unrelated to local conversations.');
  175. // TRANS: Checkbox label for hiding remote network posts if they have not been interacted with locally.
  176. $this->out->checkbox(
  177. 'localonly',
  178. _('Restrict full network view to accounts'),
  179. (bool) $this->value('localonly', 'public'),
  180. $instructions
  181. );
  182. $this->unli();
  183. $this->out->elementEnd('ul');
  184. $this->out->elementEnd('fieldset');
  185. }
  186. /**
  187. * Action elements
  188. *
  189. * @return void
  190. */
  191. public function formActions()
  192. {
  193. // TRANS: Button title to save access settings in site admin panel.
  194. $title = _('Save access settings.');
  195. // TRANS: Button text to save access settings in site admin panel.
  196. $this->out->submit('submit', _m('BUTTON', 'Save'), 'submit', null, $title);
  197. }
  198. }