]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/sitenoticeadminpanel.php
Merge branch 'master' into testing
[quix0rs-gnu-social.git] / actions / sitenoticeadminpanel.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Site notice 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    Zach Copley <zach@status.net>
25  * @copyright 2010 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/extlib/htmLawed/htmLawed.php';
35
36 /**
37  * Update the site-wide notice text
38  *
39  * @category Admin
40  * @package  StatusNet
41  * @author   Zach Copley <zach@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43  * @link     http://status.net/
44  */
45
46 class SitenoticeadminpanelAction extends AdminPanelAction
47 {
48     /**
49      * Returns the page title
50      *
51      * @return string page title
52      */
53
54     function title()
55     {
56         return _('Site Notice');
57     }
58
59     /**
60      * Instructions for using this form.
61      *
62      * @return string instructions
63      */
64
65     function getInstructions()
66     {
67         return _('Edit site-wide message');
68     }
69
70     /**
71      * Show the site notice admin panel form
72      *
73      * @return void
74      */
75
76     function showForm()
77     {
78         $form = new SiteNoticeAdminPanelForm($this);
79         $form->show();
80         return;
81     }
82
83     /**
84      * Save settings from the form
85      *
86      * @return void
87      */
88
89     function saveSettings()
90     {
91         $siteNotice = $this->trimmed('site-notice');
92
93         // assert(all values are valid);
94         // This throws an exception on validation errors
95
96         $this->validate($siteNotice);
97
98         $config = new Config();
99
100         $result = Config::save('site', 'notice', $siteNotice);
101
102         if (!$result) {
103             $this->ServerError(_("Unable to save site notice."));
104         }
105     }
106
107     function validate(&$siteNotice)
108     {
109         // Validate notice text
110
111         if (mb_strlen($siteNotice) > 255)  {
112             $this->clientError(
113                 _('Max length for the site-wide notice is 255 chars.')
114             );
115         }
116
117         // scrub HTML input
118
119         $config = array(
120             'safe' => 1,
121             'deny_attribute' => 'id,style,on*'
122         );
123
124         $siteNotice = htmLawed($siteNotice, $config);
125     }
126 }
127
128 class SiteNoticeAdminPanelForm extends AdminForm
129 {
130     /**
131      * ID of the form
132      *
133      * @return int ID of the form
134      */
135
136     function id()
137     {
138         return 'form_site_notice_admin_panel';
139     }
140
141     /**
142      * class of the form
143      *
144      * @return string class of the form
145      */
146
147     function formClass()
148     {
149         return 'form_settings';
150     }
151
152     /**
153      * Action of the form
154      *
155      * @return string URL of the action
156      */
157
158     function action()
159     {
160         return common_local_url('sitenoticeadminpanel');
161     }
162
163     /**
164      * Data elements of the form
165      *
166      * @return void
167      */
168
169     function formData()
170     {
171         $this->out->elementStart('ul', 'form_data');
172
173         $this->out->elementStart('li');
174         $this->out->textarea(
175             'site-notice',
176             _('Site notice text'),
177             common_config('site', 'notice'),
178             _('Site-wide notice text (255 chars max; HTML okay)')
179         );
180         $this->out->elementEnd('li');
181
182         $this->out->elementEnd('ul');
183     }
184
185     /**
186      * Action elements
187      *
188      * @return void
189      */
190
191     function formActions()
192     {
193         $this->out->submit(
194             'submit',
195             _('Save'),
196             'submit',
197             null,
198             _('Save site notice')
199         );
200     }
201 }