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