sitenoticeadminpanel.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Site notice 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. * Update the site-wide notice text
  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 SitenoticeadminpanelAction 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 site-wide notice tab in admin panel.
  49. return _('Site Notice');
  50. }
  51. /**
  52. * Instructions for using this form.
  53. *
  54. * @return string instructions
  55. */
  56. function getInstructions()
  57. {
  58. // TRANS: Instructions for site-wide notice tab in admin panel.
  59. return _('Edit site-wide message');
  60. }
  61. /**
  62. * Show the site notice admin panel form
  63. *
  64. * @return void
  65. */
  66. function showForm()
  67. {
  68. $form = new SiteNoticeAdminPanelForm($this);
  69. $form->show();
  70. return;
  71. }
  72. /**
  73. * Save settings from the form
  74. *
  75. * @return void
  76. */
  77. function saveSettings()
  78. {
  79. $siteNotice = $this->trimmed('site-notice');
  80. // assert(all values are valid);
  81. // This throws an exception on validation errors
  82. $this->validate($siteNotice);
  83. $config = new Config();
  84. $result = Config::save('site', 'notice', $siteNotice);
  85. if (!$result) {
  86. // TRANS: Server error displayed when saving a site-wide notice was impossible.
  87. $this->ServerError(_('Unable to save site notice.'));
  88. }
  89. }
  90. function validate(&$siteNotice)
  91. {
  92. // Validate notice text
  93. if (mb_strlen($siteNotice) > 255) {
  94. $this->clientError(
  95. // TRANS: Client error displayed when a site-wide notice was longer than allowed.
  96. _('Maximum length for the site-wide notice is 255 characters.')
  97. );
  98. }
  99. // scrub HTML input
  100. $siteNotice = common_purify($siteNotice);
  101. }
  102. }
  103. class SiteNoticeAdminPanelForm extends AdminForm
  104. {
  105. /**
  106. * ID of the form
  107. *
  108. * @return int ID of the form
  109. */
  110. function id()
  111. {
  112. return 'form_site_notice_admin_panel';
  113. }
  114. /**
  115. * class of the form
  116. *
  117. * @return string class of the form
  118. */
  119. function formClass()
  120. {
  121. return 'form_settings';
  122. }
  123. /**
  124. * Action of the form
  125. *
  126. * @return string URL of the action
  127. */
  128. function action()
  129. {
  130. return common_local_url('sitenoticeadminpanel');
  131. }
  132. /**
  133. * Data elements of the form
  134. *
  135. * @return void
  136. */
  137. function formData()
  138. {
  139. $this->out->elementStart('ul', 'form_data');
  140. $this->out->elementStart('li');
  141. $this->out->textarea(
  142. 'site-notice',
  143. // TRANS: Label for site-wide notice text field in admin panel.
  144. _('Site notice text'),
  145. common_config('site', 'notice'),
  146. // TRANS: Tooltip for site-wide notice text field in admin panel.
  147. _('Site-wide notice text (255 characters maximum; HTML allowed)')
  148. );
  149. $this->out->elementEnd('li');
  150. $this->out->elementEnd('ul');
  151. }
  152. /**
  153. * Action elements
  154. *
  155. * @return void
  156. */
  157. function formActions()
  158. {
  159. $this->out->submit(
  160. 'submit',
  161. // TRANS: Button text for saving site notice in admin panel.
  162. _m('BUTTON','Save'),
  163. 'submit',
  164. null,
  165. // TRANS: Button title to save site notice in admin panel.
  166. _('Save site notice.')
  167. );
  168. }
  169. }