sitenoticeadminpanel.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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('STATUSNET')) {
  30. exit(1);
  31. }
  32. require_once INSTALLDIR.'/extlib/htmLawed/htmLawed.php';
  33. /**
  34. * Update the site-wide notice text
  35. *
  36. * @category Admin
  37. * @package StatusNet
  38. * @author Zach Copley <zach@status.net>
  39. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  40. * @link http://status.net/
  41. */
  42. class SitenoticeadminpanelAction extends AdminPanelAction
  43. {
  44. /**
  45. * Returns the page title
  46. *
  47. * @return string page title
  48. */
  49. function title()
  50. {
  51. // TRANS: Page title for site-wide notice tab in admin panel.
  52. return _('Site Notice');
  53. }
  54. /**
  55. * Instructions for using this form.
  56. *
  57. * @return string instructions
  58. */
  59. function getInstructions()
  60. {
  61. // TRANS: Instructions for site-wide notice tab in admin panel.
  62. return _('Edit site-wide message');
  63. }
  64. /**
  65. * Show the site notice admin panel form
  66. *
  67. * @return void
  68. */
  69. function showForm()
  70. {
  71. $form = new SiteNoticeAdminPanelForm($this);
  72. $form->show();
  73. return;
  74. }
  75. /**
  76. * Save settings from the form
  77. *
  78. * @return void
  79. */
  80. function saveSettings()
  81. {
  82. $siteNotice = $this->trimmed('site-notice');
  83. // assert(all values are valid);
  84. // This throws an exception on validation errors
  85. $this->validate($siteNotice);
  86. $config = new Config();
  87. $result = Config::save('site', 'notice', $siteNotice);
  88. if (!$result) {
  89. // TRANS: Server error displayed when saving a site-wide notice was impossible.
  90. $this->ServerError(_('Unable to save site notice.'));
  91. }
  92. }
  93. function validate(&$siteNotice)
  94. {
  95. // Validate notice text
  96. if (mb_strlen($siteNotice) > 255) {
  97. $this->clientError(
  98. // TRANS: Client error displayed when a site-wide notice was longer than allowed.
  99. _('Maximum length for the site-wide notice is 255 characters.')
  100. );
  101. }
  102. // scrub HTML input
  103. $config = array(
  104. 'safe' => 1,
  105. 'deny_attribute' => 'id,style,on*'
  106. );
  107. $siteNotice = htmLawed($siteNotice, $config);
  108. }
  109. }
  110. class SiteNoticeAdminPanelForm extends AdminForm
  111. {
  112. /**
  113. * ID of the form
  114. *
  115. * @return int ID of the form
  116. */
  117. function id()
  118. {
  119. return 'form_site_notice_admin_panel';
  120. }
  121. /**
  122. * class of the form
  123. *
  124. * @return string class of the form
  125. */
  126. function formClass()
  127. {
  128. return 'form_settings';
  129. }
  130. /**
  131. * Action of the form
  132. *
  133. * @return string URL of the action
  134. */
  135. function action()
  136. {
  137. return common_local_url('sitenoticeadminpanel');
  138. }
  139. /**
  140. * Data elements of the form
  141. *
  142. * @return void
  143. */
  144. function formData()
  145. {
  146. $this->out->elementStart('ul', 'form_data');
  147. $this->out->elementStart('li');
  148. $this->out->textarea(
  149. 'site-notice',
  150. // TRANS: Label for site-wide notice text field in admin panel.
  151. _('Site notice text'),
  152. common_config('site', 'notice'),
  153. // TRANS: Tooltip for site-wide notice text field in admin panel.
  154. _('Site-wide notice text (255 characters maximum; HTML allowed)')
  155. );
  156. $this->out->elementEnd('li');
  157. $this->out->elementEnd('ul');
  158. }
  159. /**
  160. * Action elements
  161. *
  162. * @return void
  163. */
  164. function formActions()
  165. {
  166. $this->out->submit(
  167. 'submit',
  168. // TRANS: Button text for saving site notice in admin panel.
  169. _m('BUTTON','Save'),
  170. 'submit',
  171. null,
  172. // TRANS: Button title to save site notice in admin panel.
  173. _('Save site notice.')
  174. );
  175. }
  176. }