3 * StatusNet, the distributed open-source microblogging tool
5 * Snapshots administration panel
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.
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.
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/>.
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/
30 if (!defined('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/
43 class SnapshotadminpanelAction extends AdminPanelAction
46 * Returns the page title
48 * @return string page title
52 // TRANS: Title for admin panel to configure snapshots.
53 return _m('TITLE','Snapshots');
57 * Instructions for using this form.
59 * @return string instructions
61 function getInstructions()
63 // TRANS: Instructions for admin panel to configure snapshots.
64 return _('Manage snapshot configuration');
68 * Show the snapshots admin panel form
74 $form = new SnapshotAdminPanelForm($this);
80 * Save settings from the form
84 function saveSettings()
86 static $settings = array(
87 'snapshot' => array('run', 'reporturl', 'frequency')
92 foreach ($settings as $section => $parts) {
93 foreach ($parts as $setting) {
94 $values[$section][$setting] = $this->trimmed($setting);
98 // This throws an exception on validation errors
100 $this->validate($values);
102 // assert(all values are valid);
104 $config = new Config();
106 $config->query('BEGIN');
108 foreach ($settings as $section => $parts) {
109 foreach ($parts as $setting) {
110 Config::save($section, $setting, $values[$section][$setting]);
114 $config->query('COMMIT');
119 function validate(&$values)
121 // Validate snapshot run value
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.'));
128 // Validate snapshot frequency value
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.'));
135 // Validate report URL
137 if (!is_null($values['snapshot']['reporturl'])
138 && !common_valid_http_url($values['snapshot']['reporturl'])) {
139 // TRANS: Client error displayed on admin panel for snapshots when providing an invalid report URL.
140 $this->clientError(_('Invalid snapshot report URL.'));
145 // @todo FIXME: add documentation
146 class SnapshotAdminPanelForm extends AdminForm
151 * @return int ID of the form
155 return 'form_snapshot_admin_panel';
161 * @return string class of the form
165 return 'form_settings';
171 * @return string URL of the action
175 return common_local_url('snapshotadminpanel');
179 * Data elements of the form
185 $this->out->elementStart(
187 array('id' => 'settings_admin_snapshots')
189 // TRANS: Fieldset legend on admin panel for snapshots.
190 $this->out->element('legend', null, _m('LEGEND','Snapshots'));
191 $this->out->elementStart('ul', 'form_data');
194 // TRANS: Option in dropdown for snapshot method in admin panel for snapshots.
195 'web' => _('Randomly during web hit'),
196 // TRANS: Option in dropdown for snapshot method in admin panel for snapshots.
197 'cron' => _('In a scheduled job'),
198 // TRANS: Option in dropdown for snapshot method in admin panel for snapshots.
199 'never' => _('Never')
201 $this->out->dropdown(
203 // TRANS: Dropdown label for snapshot method in admin panel for snapshots.
206 // TRANS: Dropdown title for snapshot method in admin panel for snapshots.
207 _('When to send statistical data to status.net servers.'),
209 $this->value('run', 'snapshot')
216 // TRANS: Input field label for snapshot frequency in admin panel for snapshots.
218 // TRANS: Input field title for snapshot frequency in admin panel for snapshots.
219 _('Snapshots will be sent once every N web hits.'),
227 // TRANS: Input field label for snapshot report URL in admin panel for snapshots.
229 // TRANS: Input field title for snapshot report URL in admin panel for snapshots.
230 _('Snapshots will be sent to this URL.'),
234 $this->out->elementEnd('ul');
235 $this->out->elementEnd('fieldset');
243 function formActions()
247 // TRANS: Button text to save snapshot settings.
251 // TRANS: Button title to save snapshot settings.
252 _('Save snapshot settings.')