sitenoticeadminpanel.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. require_once INSTALLDIR.'/extlib/HTMLPurifier/HTMLPurifier.auto.php';
  101. $purifier = new HTMLPurifier();
  102. $siteNotice = $purifier->purify($siteNotice);
  103. }
  104. }
  105. class SiteNoticeAdminPanelForm extends AdminForm
  106. {
  107. /**
  108. * ID of the form
  109. *
  110. * @return int ID of the form
  111. */
  112. function id()
  113. {
  114. return 'form_site_notice_admin_panel';
  115. }
  116. /**
  117. * class of the form
  118. *
  119. * @return string class of the form
  120. */
  121. function formClass()
  122. {
  123. return 'form_settings';
  124. }
  125. /**
  126. * Action of the form
  127. *
  128. * @return string URL of the action
  129. */
  130. function action()
  131. {
  132. return common_local_url('sitenoticeadminpanel');
  133. }
  134. /**
  135. * Data elements of the form
  136. *
  137. * @return void
  138. */
  139. function formData()
  140. {
  141. $this->out->elementStart('ul', 'form_data');
  142. $this->out->elementStart('li');
  143. $this->out->textarea(
  144. 'site-notice',
  145. // TRANS: Label for site-wide notice text field in admin panel.
  146. _('Site notice text'),
  147. common_config('site', 'notice'),
  148. // TRANS: Tooltip for site-wide notice text field in admin panel.
  149. _('Site-wide notice text (255 characters maximum; HTML allowed)')
  150. );
  151. $this->out->elementEnd('li');
  152. $this->out->elementEnd('ul');
  153. }
  154. /**
  155. * Action elements
  156. *
  157. * @return void
  158. */
  159. function formActions()
  160. {
  161. $this->out->submit(
  162. 'submit',
  163. // TRANS: Button text for saving site notice in admin panel.
  164. _m('BUTTON','Save'),
  165. 'submit',
  166. null,
  167. // TRANS: Button title to save site notice in admin panel.
  168. _('Save site notice.')
  169. );
  170. }
  171. }