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