]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/sitenoticeadminpanel.php
Introduced common_location_shared() to check if location sharing is always,
[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 class SitenoticeadminpanelAction extends AdminPanelAction
46 {
47     /**
48      * Returns the page title
49      *
50      * @return string page title
51      */
52     function title()
53     {
54         // TRANS: Page title for site-wide notice tab in admin panel.
55         return _('Site Notice');
56     }
57
58     /**
59      * Instructions for using this form.
60      *
61      * @return string instructions
62      */
63     function getInstructions()
64     {
65         // TRANS: Instructions for site-wide notice tab in admin panel.
66         return _('Edit site-wide message');
67     }
68
69     /**
70      * Show the site notice admin panel form
71      *
72      * @return void
73      */
74     function showForm()
75     {
76         $form = new SiteNoticeAdminPanelForm($this);
77         $form->show();
78         return;
79     }
80
81     /**
82      * Save settings from the form
83      *
84      * @return void
85      */
86     function saveSettings()
87     {
88         $siteNotice = $this->trimmed('site-notice');
89
90         // assert(all values are valid);
91         // This throws an exception on validation errors
92
93         $this->validate($siteNotice);
94
95         $config = new Config();
96
97         $result = Config::save('site', 'notice', $siteNotice);
98
99         if (!$result) {
100             // TRANS: Server error displayed when saving a site-wide notice was impossible.
101             $this->ServerError(_('Unable to save site notice.'));
102         }
103     }
104
105     function validate(&$siteNotice)
106     {
107         // Validate notice text
108
109         if (mb_strlen($siteNotice) > 255)  {
110             $this->clientError(
111                 // TRANS: Client error displayed when a site-wide notice was longer than allowed.
112                 _('Maximum length for the site-wide notice is 255 characters.')
113             );
114         }
115
116         // scrub HTML input
117
118         $config = array(
119             'safe' => 1,
120             'deny_attribute' => 'id,style,on*'
121         );
122
123         $siteNotice = htmLawed($siteNotice, $config);
124     }
125 }
126
127 class SiteNoticeAdminPanelForm extends AdminForm
128 {
129     /**
130      * ID of the form
131      *
132      * @return int ID of the form
133      */
134
135     function id()
136     {
137         return 'form_site_notice_admin_panel';
138     }
139
140     /**
141      * class of the form
142      *
143      * @return string class of the form
144      */
145
146     function formClass()
147     {
148         return 'form_settings';
149     }
150
151     /**
152      * Action of the form
153      *
154      * @return string URL of the action
155      */
156
157     function action()
158     {
159         return common_local_url('sitenoticeadminpanel');
160     }
161
162     /**
163      * Data elements of the form
164      *
165      * @return void
166      */
167
168     function formData()
169     {
170         $this->out->elementStart('ul', 'form_data');
171
172         $this->out->elementStart('li');
173         $this->out->textarea(
174             'site-notice',
175             // TRANS: Label for site-wide notice text field in admin panel.
176             _('Site notice text'),
177             common_config('site', 'notice'),
178             // TRANS: Tooltip for site-wide notice text field in admin panel.
179             _('Site-wide notice text (255 characters maximum; HTML allowed)')
180         );
181         $this->out->elementEnd('li');
182
183         $this->out->elementEnd('ul');
184     }
185
186     /**
187      * Action elements
188      *
189      * @return void
190      */
191
192     function formActions()
193     {
194         $this->out->submit(
195             'submit',
196             // TRANS: Button text for saving site notice in admin panel.
197             _m('BUTTON','Save'),
198             'submit',
199             null,
200             // TRANS: Button title to save site notice in admin panel.
201             _('Save site notice.')
202         );
203     }
204 }