accessadminpanel.php 6.4 KB

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