siteadminpanel.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Site 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 Evan Prodromou <evan@status.net>
  25. * @author Zach Copley <zach@status.net>
  26. * @author Sarven Capadisli <csarven@status.net>
  27. * @copyright 2008-2011 StatusNet, Inc.
  28. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  29. * @link http://status.net/
  30. */
  31. if (!defined('STATUSNET')) {
  32. exit(1);
  33. }
  34. /**
  35. * Administer site settings
  36. *
  37. * @category Admin
  38. * @package StatusNet
  39. * @author Evan Prodromou <evan@status.net>
  40. * @author Zach Copley <zach@status.net>
  41. * @author Sarven Capadisli <csarven@status.net>
  42. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  43. * @link http://status.net/
  44. */
  45. class SiteadminpanelAction extends AdminPanelAction
  46. {
  47. /**
  48. * Returns the page title
  49. *
  50. * @return string page title
  51. */
  52. function title()
  53. {
  54. // TRANS: Title for site administration panel.
  55. return _m('TITLE','Site');
  56. }
  57. /**
  58. * Instructions for using this form.
  59. *
  60. * @return string instructions
  61. */
  62. function getInstructions()
  63. {
  64. // TRANS: Instructions for site administration panel.
  65. return _('Basic settings for this StatusNet site');
  66. }
  67. /**
  68. * Show the site admin panel form
  69. *
  70. * @return void
  71. */
  72. function showForm()
  73. {
  74. $form = new SiteAdminPanelForm($this);
  75. $form->show();
  76. return;
  77. }
  78. /**
  79. * Save settings from the form
  80. *
  81. * @return void
  82. */
  83. function saveSettings()
  84. {
  85. static $settings = array(
  86. 'site' => array(
  87. 'name',
  88. 'broughtby',
  89. 'broughtbyurl',
  90. 'email',
  91. 'timezone',
  92. 'language',
  93. 'site',
  94. 'textlimit',
  95. 'dupelimit',
  96. 'logo',
  97. 'ssllogo'
  98. )
  99. );
  100. $values = array();
  101. foreach ($settings as $section => $parts) {
  102. foreach ($parts as $setting) {
  103. $values[$section][$setting] = $this->trimmed($setting);
  104. }
  105. }
  106. // This throws an exception on validation errors
  107. $this->validate($values);
  108. // assert(all values are valid);
  109. $config = new Config();
  110. $config->query('BEGIN');
  111. foreach ($settings as $section => $parts) {
  112. foreach ($parts as $setting) {
  113. Config::save($section, $setting, $values[$section][$setting]);
  114. }
  115. }
  116. $config->query('COMMIT');
  117. return;
  118. }
  119. function validate(&$values)
  120. {
  121. // Validate site name
  122. if (empty($values['site']['name'])) {
  123. // TRANS: Client error displayed trying to save an empty site name.
  124. $this->clientError(_('Site name must have non-zero length.'));
  125. }
  126. // Validate email
  127. $values['site']['email'] = common_canonical_email($values['site']['email']);
  128. if (empty($values['site']['email'])) {
  129. // TRANS: Client error displayed trying to save site settings without a contact address.
  130. $this->clientError(_('You must have a valid contact email address.'));
  131. }
  132. if (!Validate::email($values['site']['email'], common_config('email', 'check_domain'))) {
  133. // TRANS: Client error displayed trying to save site settings without a valid contact address.
  134. $this->clientError(_('Not a valid email address.'));
  135. }
  136. // Validate logos
  137. if (!empty($values['site']['logo']) &&
  138. !common_valid_http_url($values['site']['logo'])) {
  139. // TRANS: Client error displayed when a logo URL is not valid.
  140. $this->clientError(_('Invalid logo URL.'));
  141. }
  142. if (!empty($values['site']['ssllogo']) &&
  143. !common_valid_http_url($values['site']['ssllogo'], true)) {
  144. // TRANS: Client error displayed when a SSL logo URL is invalid.
  145. $this->clientError(_('Invalid SSL logo URL.'));
  146. }
  147. // Validate timezone
  148. if (is_null($values['site']['timezone']) ||
  149. !in_array($values['site']['timezone'], DateTimeZone::listIdentifiers())) {
  150. // TRANS: Client error displayed trying to save site settings without a timezone.
  151. $this->clientError(_('Timezone not selected.'));
  152. }
  153. // Validate language
  154. if (!is_null($values['site']['language']) &&
  155. !in_array($values['site']['language'], array_keys(get_nice_language_list()))) {
  156. // TRANS: Client error displayed trying to save site settings with an invalid language code.
  157. // TRANS: %s is the invalid language code.
  158. $this->clientError(sprintf(_('Unknown language "%s".'), $values['site']['language']));
  159. }
  160. // Validate text limit
  161. if (!Validate::number($values['site']['textlimit'], array('min' => 0))) {
  162. // TRANS: Client error displayed trying to save site settings with a text limit below 0.
  163. $this->clientError(_('Minimum text limit is 0 (unlimited).'));
  164. }
  165. // Validate dupe limit
  166. if (!Validate::number($values['site']['dupelimit'], array('min' => 1))) {
  167. // TRANS: Client error displayed trying to save site settings with a text limit below 1.
  168. $this->clientError(_('Dupe limit must be one or more seconds.'));
  169. }
  170. }
  171. }
  172. // @todo FIXME: Class documentation missing.
  173. class SiteAdminPanelForm extends AdminForm
  174. {
  175. /**
  176. * ID of the form
  177. *
  178. * @return int ID of the form
  179. */
  180. function id()
  181. {
  182. return 'form_site_admin_panel';
  183. }
  184. /**
  185. * class of the form
  186. *
  187. * @return string class of the form
  188. */
  189. function formClass()
  190. {
  191. return 'form_settings';
  192. }
  193. /**
  194. * Action of the form
  195. *
  196. * @return string URL of the action
  197. */
  198. function action()
  199. {
  200. return common_local_url('siteadminpanel');
  201. }
  202. /**
  203. * Data elements of the form
  204. *
  205. * @return void
  206. */
  207. function formData()
  208. {
  209. $this->out->elementStart('fieldset', array('id' => 'settings_admin_general'));
  210. // TRANS: Fieldset legend on site settings panel.
  211. $this->out->element('legend', null, _m('LEGEND','General'));
  212. $this->out->elementStart('ul', 'form_data');
  213. $this->li();
  214. // TRANS: Field label on site settings panel.
  215. $this->input('name', _m('LABEL','Site name'),
  216. // TRANS: Field title on site settings panel.
  217. _('The name of your site, like "Yourcompany Microblog".'));
  218. $this->unli();
  219. $this->li();
  220. // TRANS: Field label on site settings panel.
  221. $this->input('broughtby', _('Brought by'),
  222. // TRANS: Field title on site settings panel.
  223. _('Text used for credits link in footer of each page.'));
  224. $this->unli();
  225. $this->li();
  226. // TRANS: Field label on site settings panel.
  227. $this->input('broughtbyurl', _('Brought by URL'),
  228. // TRANS: Field title on site settings panel.
  229. _('URL used for credits link in footer of each page.'));
  230. $this->unli();
  231. $this->li();
  232. // TRANS: Field label on site settings panel.
  233. $this->input('email', _('Email'),
  234. // TRANS: Field title on site settings panel.
  235. _('Contact email address for your site.'));
  236. $this->unli();
  237. $this->out->elementEnd('ul');
  238. $this->out->elementEnd('fieldset');
  239. $this->showLogo();
  240. $this->out->elementStart('fieldset', array('id' => 'settings_admin_local'));
  241. // TRANS: Fieldset legend on site settings panel.
  242. $this->out->element('legend', null, _m('LEGEND','Local'));
  243. $this->out->elementStart('ul', 'form_data');
  244. $timezones = array();
  245. foreach (DateTimeZone::listIdentifiers() as $k => $v) {
  246. $timezones[$v] = $v;
  247. }
  248. asort($timezones);
  249. $this->li();
  250. // TRANS: Dropdown label on site settings panel.
  251. $this->out->dropdown('timezone', _('Default timezone'),
  252. // TRANS: Dropdown title on site settings panel.
  253. $timezones, _('Default timezone for the site; usually UTC.'),
  254. true, $this->value('timezone'));
  255. $this->unli();
  256. $this->li();
  257. $this->out->dropdown('language',
  258. // TRANS: Dropdown label on site settings panel.
  259. _('Default language'),
  260. get_nice_language_list(),
  261. // TRANS: Dropdown title on site settings panel.
  262. _('The site language when autodetection from browser settings is not available.'),
  263. false, $this->value('language'));
  264. $this->unli();
  265. $this->out->elementEnd('ul');
  266. $this->out->elementEnd('fieldset');
  267. $this->out->elementStart('fieldset', array('id' => 'settings_admin_limits'));
  268. // TRANS: Fieldset legend on site settings panel.
  269. $this->out->element('legend', null, _m('LEGEND','Limits'));
  270. $this->out->elementStart('ul', 'form_data');
  271. $this->li();
  272. $this->input('textlimit',
  273. // TRANS: Field label on site settings panel.
  274. _('Text limit'),
  275. // TRANS: Field title on site settings panel.
  276. _('Maximum number of characters for notices.'));
  277. $this->unli();
  278. $this->li();
  279. $this->input('dupelimit',
  280. // TRANS: Field label on site settings panel.
  281. _('Dupe limit'),
  282. // TRANS: Field title on site settings panel.
  283. _('How long users must wait (in seconds) to post the same thing again.'));
  284. $this->unli();
  285. $this->out->elementEnd('ul');
  286. $this->out->elementEnd('fieldset');
  287. }
  288. function showLogo()
  289. {
  290. $this->out->elementStart('fieldset', array('id' => 'settings_site_logo'));
  291. // TRANS: Fieldset legend for form to change logo.
  292. $this->out->element('legend', null, _('Logo'));
  293. $this->out->elementStart('ul', 'form_data');
  294. $this->li();
  295. $this->input('logo',
  296. // TRANS: Field label for StatusNet site logo.
  297. _('Site logo'),
  298. // TRANS: Title for field label for StatusNet site logo.
  299. 'Logo for the site (full URL).');
  300. $this->unli();
  301. $this->li();
  302. $this->input('ssllogo',
  303. // TRANS: Field label for SSL StatusNet site logo.
  304. _('SSL logo'),
  305. // TRANS: Title for field label for SSL StatusNet site logo.
  306. 'Logo to show on SSL pages (full URL).');
  307. $this->unli();
  308. $this->out->elementEnd('ul');
  309. $this->out->elementEnd('fieldset');
  310. }
  311. /**
  312. * Action elements
  313. *
  314. * @return void
  315. */
  316. function formActions()
  317. {
  318. $this->out->submit('submit',
  319. // TRANS: Button text for saving site settings.
  320. _m('BUTTON','Save'),
  321. 'submit',
  322. null,
  323. // TRANS: Button title for saving site settings.
  324. _('Save the site settings.'));
  325. }
  326. }