blacklistadminpanel.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Blacklist 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. * @copyright 2010 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. /**
  33. * Administer blacklist
  34. *
  35. * @category Admin
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
  39. * @link http://status.net/
  40. */
  41. class BlacklistadminpanelAction extends AdminPanelAction
  42. {
  43. /**
  44. * title of the admin panel
  45. *
  46. * @return string title
  47. */
  48. function title()
  49. {
  50. // TRANS: Title of blacklist plugin administration panel.
  51. return _m('TITLE','Blacklist');
  52. }
  53. /**
  54. * Panel instructions
  55. *
  56. * @return string instructions
  57. */
  58. function getInstructions()
  59. {
  60. // TRANS: Instructions for blacklist plugin administration panel.
  61. return _m('Blacklisted URLs and nicknames');
  62. }
  63. /**
  64. * Show the actual form
  65. *
  66. * @return void
  67. *
  68. * @see BlacklistAdminPanelForm
  69. */
  70. function showForm()
  71. {
  72. $form = new BlacklistAdminPanelForm($this);
  73. $form->show();
  74. return;
  75. }
  76. /**
  77. * Save the form settings
  78. *
  79. * @return void
  80. */
  81. function saveSettings()
  82. {
  83. $nickPatterns = $this->splitPatterns($this->trimmed('blacklist-nicknames'));
  84. Nickname_blacklist::saveNew($nickPatterns);
  85. $urlPatterns = $this->splitPatterns($this->trimmed('blacklist-urls'));
  86. Homepage_blacklist::saveNew($urlPatterns);
  87. return;
  88. }
  89. protected function splitPatterns($text)
  90. {
  91. $patterns = array();
  92. foreach (explode("\n", $text) as $raw) {
  93. $trimmed = trim($raw);
  94. if ($trimmed != '') {
  95. $patterns[] = $trimmed;
  96. }
  97. }
  98. return $patterns;
  99. }
  100. /**
  101. * Validate the values
  102. *
  103. * @param array &$values 2d array of values to check
  104. *
  105. * @return boolean success flag
  106. */
  107. function validate(&$values)
  108. {
  109. return true;
  110. }
  111. }
  112. /**
  113. * Admin panel form for blacklist panel
  114. *
  115. * @category Admin
  116. * @package StatusNet
  117. * @author Evan Prodromou <evan@status.net>
  118. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
  119. * @link http://status.net/
  120. */
  121. class BlacklistAdminPanelForm extends Form
  122. {
  123. /**
  124. * ID of the form
  125. *
  126. * @return string ID
  127. */
  128. function id()
  129. {
  130. return 'blacklistadminpanel';
  131. }
  132. /**
  133. * Class of the form
  134. *
  135. * @return string class
  136. */
  137. function formClass()
  138. {
  139. return 'form_settings';
  140. }
  141. /**
  142. * Action we post to
  143. *
  144. * @return string action URL
  145. */
  146. function action()
  147. {
  148. return common_local_url('blacklistadminpanel');
  149. }
  150. /**
  151. * Show the form controls
  152. *
  153. * @return void
  154. */
  155. function formData()
  156. {
  157. $this->out->elementStart('ul', 'form_data');
  158. $this->out->elementStart('li');
  159. $nickPatterns = Nickname_blacklist::getPatterns();
  160. // TRANS: Field label in blacklist plugin administration panel.
  161. $this->out->textarea('blacklist-nicknames', _m('Nicknames'),
  162. implode("\r\n", $nickPatterns),
  163. // TRANS: Field title in blacklist plugin administration panel.
  164. _m('Patterns of nicknames to block, one per line.'));
  165. $this->out->elementEnd('li');
  166. $urlPatterns = Homepage_blacklist::getPatterns();
  167. $this->out->elementStart('li');
  168. // TRANS: Field label in blacklist plugin administration panel.
  169. $this->out->textarea('blacklist-urls', _m('URLs'),
  170. implode("\r\n", $urlPatterns),
  171. // TRANS: Field title in blacklist plugin administration panel.
  172. _m('Patterns of URLs to block, one per line.'));
  173. $this->out->elementEnd('li');
  174. $this->out->elementEnd('ul');
  175. }
  176. /**
  177. * Buttons for submitting
  178. *
  179. * @return void
  180. */
  181. function formActions()
  182. {
  183. $this->out->submit('submit',
  184. // TRANS: Button text in blacklist plugin administration panel to save settings.
  185. _m('BUTTON','Save'),
  186. 'submit',
  187. null,
  188. // TRANS: Button title in blacklist plugin administration panel to save settings.
  189. _m('Save site settings.'));
  190. }
  191. }