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