]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/snapshotadminpanel.php
Update translator documentation.
[quix0rs-gnu-social.git] / actions / snapshotadminpanel.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Snapshots 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 /**
35  * Manage snapshots
36  *
37  * @category Admin
38  * @package  StatusNet
39  * @author   Zach Copley <zach@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://status.net/
42  */
43 class SnapshotadminpanelAction extends AdminPanelAction
44 {
45     /**
46      * Returns the page title
47      *
48      * @return string page title
49      */
50     function title()
51     {
52         // TRANS: Title for admin panel to configure snapshots.
53         return _m('TITLE','Snapshots');
54     }
55
56     /**
57      * Instructions for using this form.
58      *
59      * @return string instructions
60      */
61     function getInstructions()
62     {
63         // TRANS: Instructions for admin panel to configure snapshots.
64         return _('Manage snapshot configuration');
65     }
66
67     /**
68      * Show the snapshots admin panel form
69      *
70      * @return void
71      */
72     function showForm()
73     {
74         $form = new SnapshotAdminPanelForm($this);
75         $form->show();
76         return;
77     }
78
79     /**
80      * Save settings from the form
81      *
82      * @return void
83      */
84     function saveSettings()
85     {
86         static $settings = array(
87             'snapshot' => array('run', 'reporturl', 'frequency')
88         );
89
90         $values = array();
91
92         foreach ($settings as $section => $parts) {
93             foreach ($parts as $setting) {
94                 $values[$section][$setting] = $this->trimmed($setting);
95             }
96         }
97
98         // This throws an exception on validation errors
99
100         $this->validate($values);
101
102         // assert(all values are valid);
103
104         $config = new Config();
105
106         $config->query('BEGIN');
107
108         foreach ($settings as $section => $parts) {
109             foreach ($parts as $setting) {
110                 Config::save($section, $setting, $values[$section][$setting]);
111             }
112         }
113
114         $config->query('COMMIT');
115
116         return;
117     }
118
119     function validate(&$values)
120     {
121         // Validate snapshot run value
122
123         if (!in_array($values['snapshot']['run'], array('web', 'cron', 'never'))) {
124             // TRANS: Client error displayed on admin panel for snapshots when providing an invalid run value.
125             $this->clientError(_('Invalid snapshot run value.'));
126         }
127
128         // Validate snapshot frequency value
129
130         if (!Validate::number($values['snapshot']['frequency'])) {
131             // TRANS: Client error displayed on admin panel for snapshots when providing an invalid value for frequency.
132             $this->clientError(_('Snapshot frequency must be a number.'));
133         }
134
135         // Validate report URL
136
137         if (!is_null($values['snapshot']['reporturl'])
138             && !Validate::uri(
139                 $values['snapshot']['reporturl'],
140                 array('allowed_schemes' => array('http', 'https')
141             )
142         )) {
143             // TRANS: Client error displayed on admin panel for snapshots when providing an invalid report URL.
144             $this->clientError(_('Invalid snapshot report URL.'));
145         }
146     }
147 }
148
149 // @todo FIXME: add documentation
150 class SnapshotAdminPanelForm extends AdminForm
151 {
152     /**
153      * ID of the form
154      *
155      * @return int ID of the form
156      */
157     function id()
158     {
159         return 'form_snapshot_admin_panel';
160     }
161
162     /**
163      * class of the form
164      *
165      * @return string class of the form
166      */
167     function formClass()
168     {
169         return 'form_settings';
170     }
171
172     /**
173      * Action of the form
174      *
175      * @return string URL of the action
176      */
177     function action()
178     {
179         return common_local_url('snapshotadminpanel');
180     }
181
182     /**
183      * Data elements of the form
184      *
185      * @return void
186      */
187     function formData()
188     {
189         $this->out->elementStart(
190             'fieldset',
191             array('id' => 'settings_admin_snapshots')
192         );
193         // TRANS: Fieldset legend on admin panel for snapshots.
194         $this->out->element('legend', null, _m('LEGEND','Snapshots'));
195         $this->out->elementStart('ul', 'form_data');
196         $this->li();
197         $snapshot = array(
198             // TRANS: Option in dropdown for snapshot method in admin panel for snapshots.
199             'web' => _('Randomly during web hit'),
200             // TRANS: Option in dropdown for snapshot method in admin panel for snapshots.
201             'cron'  => _('In a scheduled job'),
202             // TRANS: Option in dropdown for snapshot method in admin panel for snapshots.
203             'never' => _('Never')
204         );
205         $this->out->dropdown(
206             'run',
207             // TRANS: Dropdown label for snapshot method in admin panel for snapshots.
208             _('Data snapshots'),
209             $snapshot,
210             // TRANS: Dropdown title for snapshot method in admin panel for snapshots.
211             _('When to send statistical data to status.net servers.'),
212             false,
213             $this->value('run', 'snapshot')
214         );
215         $this->unli();
216
217         $this->li();
218         $this->input(
219             'frequency',
220             // TRANS: Input field label for snapshot frequency in admin panel for snapshots.
221             _('Frequency'),
222             // TRANS: Input field title for snapshot frequency in admin panel for snapshots.
223             _('Snapshots will be sent once every N web hits.'),
224             'snapshot'
225         );
226         $this->unli();
227
228         $this->li();
229         $this->input(
230             'reporturl',
231             // TRANS: Input field label for snapshot report URL in admin panel for snapshots.
232             _('Report URL'),
233             // TRANS: Input field title for snapshot report URL in admin panel for snapshots.
234             _('Snapshots will be sent to this URL.'),
235             'snapshot'
236         );
237         $this->unli();
238         $this->out->elementEnd('ul');
239         $this->out->elementEnd('fieldset');
240     }
241
242     /**
243      * Action elements
244      *
245      * @return void
246      */
247     function formActions()
248     {
249         $this->out->submit(
250             'submit',
251             // TRANS: Button text to save snapshot settings.
252             _m('BUTTON','Save'),
253             'submit',
254             null,
255             // TRANS: Title for button to save snapshot settings.
256             _('Save snapshot settings.')
257         );
258     }
259 }