]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Blacklist/blacklistadminpanel.php
Fix for error output on invalid user ID to api groups list
[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 = array();
92
93         $rawNickPatterns = explode("\n", $this->trimmed('blacklist-nicknames'));
94
95         foreach ($rawNickPatterns as $raw) {
96             $nickPatterns[] = trim($raw);
97         }
98
99         Nickname_blacklist::saveNew($nickPatterns);
100
101         $rawUrlPatterns = explode("\n", $this->trimmed('blacklist-urls'));
102         $urlPatterns  = array();
103
104         foreach ($rawUrlPatterns as $raw) {
105             $urlPatterns[] = trim($raw);
106         }
107
108         Homepage_blacklist::saveNew($urlPatterns);
109
110         return;
111     }
112
113     /**
114      * Validate the values
115      *
116      * @param array &$values 2d array of values to check
117      *
118      * @return boolean success flag
119      */
120
121     function validate(&$values)
122     {
123         return true;
124     }
125 }
126
127 /**
128  * Admin panel form for blacklist panel
129  *
130  * @category Admin
131  * @package  StatusNet
132  * @author   Evan Prodromou <evan@status.net>
133  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
134  * @link     http://status.net/
135  */
136
137 class BlacklistAdminPanelForm extends Form
138 {
139     /**
140      * ID of the form
141      *
142      * @return string ID
143      */
144
145     function id()
146     {
147         return 'blacklistadminpanel';
148     }
149
150     /**
151      * Class of the form
152      *
153      * @return string class
154      */
155
156     function formClass()
157     {
158         return 'form_settings';
159     }
160
161     /**
162      * Action we post to
163      *
164      * @return string action URL
165      */
166
167     function action()
168     {
169         return common_local_url('blacklistadminpanel');
170     }
171
172     /**
173      * Show the form controls
174      *
175      * @return void
176      */
177
178     function formData()
179     {
180         $this->out->elementStart('ul', 'form_data');
181
182         $this->out->elementStart('li');
183
184         $nickPatterns = Nickname_blacklist::getPatterns();
185
186         $this->out->textarea('blacklist-nicknames', _m('Nicknames'),
187                              implode("\r\n", $nickPatterns),
188                              _('Patterns of nicknames to block, one per line'));
189         $this->out->elementEnd('li');
190
191         $urlPatterns = Homepage_blacklist::getPatterns();
192
193         $this->out->elementStart('li');
194         $this->out->textarea('blacklist-urls', _m('URLs'),
195                              implode("\r\n", $urlPatterns),
196                              _('Patterns of URLs to block, one per line'));
197         $this->out->elementEnd('li');
198
199         $this->out->elementEnd('ul');
200     }
201
202     /**
203      * Buttons for submitting
204      *
205      * @return void
206      */
207
208     function formActions()
209     {
210         $this->out->submit('submit',
211                            _('Save'),
212                            'submit',
213                            null,
214                            _('Save site settings'));
215     }
216 }