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