qvitteradminsettings.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. /* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
  3. · ·
  4. · ·
  5. · Q V I T T E R ·
  6. · ·
  7. · https://git.gnu.io/h2p/Qvitter ·
  8. · ·
  9. · ·
  10. · <o) ·
  11. · /_//// ·
  12. · (____/ ·
  13. · (o< ·
  14. · o> \\\\_\ ·
  15. · \\) \____) ·
  16. · ·
  17. · ·
  18. · ·
  19. · Qvitter is free software: you can redistribute it and / or modify it ·
  20. · under the terms of the GNU Affero General Public License as published by ·
  21. · the Free Software Foundation, either version three of the License or (at ·
  22. · your option) any later version. ·
  23. · ·
  24. · Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
  25. · WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
  26. · FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
  27. · more details. ·
  28. · ·
  29. · You should have received a copy of the GNU Affero General Public License ·
  30. · along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
  31. · ·
  32. · Contact h@nnesmannerhe.im if you have any questions. ·
  33. · ·
  34. · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
  35. if (!defined('STATUSNET') && !defined('LACONICA')) {
  36. exit(1);
  37. }
  38. class QvitterAdminSettingsAction extends AdminPanelAction
  39. {
  40. /**
  41. * Returns the page title
  42. *
  43. * @return string page title
  44. */
  45. function title()
  46. {
  47. // TRANS: Page title for site-wide notice tab in admin panel.
  48. return _('Qvitter Sidebar Notice');
  49. }
  50. /**
  51. * Instructions for using this form.
  52. *
  53. * @return string instructions
  54. */
  55. function getInstructions()
  56. {
  57. // TRANS: Instructions for site-wide notice tab in admin panel.
  58. return _('Edit notice in Qvitter\'s sidebar');
  59. }
  60. /**
  61. * Show the site notice admin panel form
  62. *
  63. * @return void
  64. */
  65. function showForm()
  66. {
  67. $form = new QvitterNoticeAdminPanelForm($this);
  68. $form->show();
  69. return;
  70. }
  71. /**
  72. * Save settings from the form
  73. *
  74. * @return void
  75. */
  76. function saveSettings()
  77. {
  78. $qvitterNotice = $this->trimmed('qvitter-notice');
  79. $qvitterNoticeLoggedOut = $this->trimmed('qvitter-notice-logged-out');
  80. // assert(all values are valid);
  81. // This throws an exception on validation errors
  82. $this->validate($qvitterNotice);
  83. $this->validate($qvitterNoticeLoggedOut);
  84. $config = new Config();
  85. $result = Config::save('site', 'qvitternotice', $qvitterNotice);
  86. $result = Config::save('site', 'qvitternoticeloggedout', $qvitterNoticeLoggedOut);
  87. if (!$result) {
  88. // TRANS: Server error displayed when saving a sidebar notice was impossible.
  89. $this->ServerError(_('Unable to save qvitter sidebar notice.'));
  90. }
  91. }
  92. function validate(&$qvitterNotice)
  93. {
  94. // Validate notice text
  95. //The column 'value' in table 'config' is TEXT
  96. if (mb_strlen($qvitterNotice) > 21844) {
  97. $this->clientError(
  98. // TRANS: Client error displayed when a sidebar notice was longer than allowed.
  99. _('Maximum length for the sidebar notice is 21844 characters.')
  100. );
  101. }
  102. }
  103. }
  104. class QvitterNoticeAdminPanelForm extends AdminForm
  105. {
  106. /**
  107. * ID of the form
  108. *
  109. * @return int ID of the form
  110. */
  111. function id()
  112. {
  113. return 'form_qvitter_notice_admin_panel';
  114. }
  115. /**
  116. * class of the form
  117. *
  118. * @return string class of the form
  119. */
  120. function formClass()
  121. {
  122. return 'form_settings';
  123. }
  124. /**
  125. * Action of the form
  126. *
  127. * @return string URL of the action
  128. */
  129. function action()
  130. {
  131. return common_local_url('qvitteradminsettings');
  132. }
  133. /**
  134. * Data elements of the form
  135. *
  136. * @return void
  137. */
  138. function formData()
  139. {
  140. $this->out->elementStart('ul', 'form_data');
  141. $this->out->elementStart('li');
  142. $this->out->textarea(
  143. 'qvitter-notice',
  144. // TRANS: Label for sidebar notice text field in admin panel.
  145. _('Qvitter sidebar notice text'),
  146. common_config('site', 'qvitternotice'),
  147. // TRANS: Tooltip for sidebar notice text field in admin panel.
  148. _('Qvitter\'s sidebar notice text (21,844 characters maximum; HTML allowed)')
  149. );
  150. $this->out->elementEnd('li');
  151. $this->out->elementEnd('ul');
  152. $this->out->elementStart('ul', 'form_data');
  153. $this->out->elementStart('li');
  154. $this->out->textarea(
  155. 'qvitter-notice-logged-out',
  156. // TRANS: Label for sidebar notice text field in admin panel.
  157. _('Qvitter sidebar notice text (logged out)'),
  158. common_config('site', 'qvitternoticeloggedout'),
  159. // TRANS: Tooltip for sidebar notice text field in admin panel.
  160. _('Qvitter\'s sidebar notice text, when logged out (21,844 characters maximum; HTML allowed)')
  161. );
  162. $this->out->elementEnd('li');
  163. $this->out->elementEnd('ul');
  164. }
  165. /**
  166. * Action elements
  167. *
  168. * @return void
  169. */
  170. function formActions()
  171. {
  172. $this->out->submit(
  173. 'submit',
  174. // TRANS: Button text for saving sidebar notice in admin panel.
  175. _m('BUTTON','Save'),
  176. 'submit',
  177. null,
  178. // TRANS: Button title to save sidebar notice in admin panel.
  179. _('Save sidebar notice.')
  180. );
  181. }
  182. }