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