]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/sitenoticeadminpanel.php
[CORE] Fixed bug where the http connection was using the wrong size for thumbnails...
[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         $siteNotice = common_purify($siteNotice);
114     }
115 }
116
117 class SiteNoticeAdminPanelForm extends AdminForm
118 {
119     /**
120      * ID of the form
121      *
122      * @return int ID of the form
123      */
124
125     function id()
126     {
127         return 'form_site_notice_admin_panel';
128     }
129
130     /**
131      * class of the form
132      *
133      * @return string class of the form
134      */
135
136     function formClass()
137     {
138         return 'form_settings';
139     }
140
141     /**
142      * Action of the form
143      *
144      * @return string URL of the action
145      */
146
147     function action()
148     {
149         return common_local_url('sitenoticeadminpanel');
150     }
151
152     /**
153      * Data elements of the form
154      *
155      * @return void
156      */
157
158     function formData()
159     {
160         $this->out->elementStart('ul', 'form_data');
161
162         $this->out->elementStart('li');
163         $this->out->textarea(
164             'site-notice',
165             // TRANS: Label for site-wide notice text field in admin panel.
166             _('Site notice text'),
167             common_config('site', 'notice'),
168             // TRANS: Tooltip for site-wide notice text field in admin panel.
169             _('Site-wide notice text (255 characters maximum; HTML allowed)')
170         );
171         $this->out->elementEnd('li');
172
173         $this->out->elementEnd('ul');
174     }
175
176     /**
177      * Action elements
178      *
179      * @return void
180      */
181
182     function formActions()
183     {
184         $this->out->submit(
185             'submit',
186             // TRANS: Button text for saving site notice in admin panel.
187             _m('BUTTON','Save'),
188             'submit',
189             null,
190             // TRANS: Button title to save site notice in admin panel.
191             _('Save site notice.')
192         );
193     }
194 }