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'])
139 $values['snapshot']['reporturl'],
140 array('allowed_schemes' => array('http', 'https')
143 // TRANS: Client error displayed on admin panel for snapshots when providing an invalid report URL.
144 $this->clientError(_('Invalid snapshot report URL.'));
149 // @todo FIXME: add documentation
150 class SnapshotAdminPanelForm extends AdminForm
155 * @return int ID of the form
159 return 'form_snapshot_admin_panel';
165 * @return string class of the form
169 return 'form_settings';
175 * @return string URL of the action
179 return common_local_url('snapshotadminpanel');
183 * Data elements of the form
189 $this->out->elementStart(
191 array('id' => 'settings_admin_snapshots')
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');
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')
205 $this->out->dropdown(
207 // TRANS: Dropdown label for snapshot method in admin panel for snapshots.
210 // TRANS: Dropdown title for snapshot method in admin panel for snapshots.
211 _('When to send statistical data to status.net servers.'),
213 $this->value('run', 'snapshot')
220 // TRANS: Input field label for snapshot frequency in admin panel for snapshots.
222 // TRANS: Input field title for snapshot frequency in admin panel for snapshots.
223 _('Snapshots will be sent once every N web hits.'),
231 // TRANS: Input field label for snapshot report URL in admin panel for snapshots.
233 // TRANS: Input field title for snapshot report URL in admin panel for snapshots.
234 _('Snapshots will be sent to this URL.'),
238 $this->out->elementEnd('ul');
239 $this->out->elementEnd('fieldset');
247 function formActions()
251 // TRANS: Button text to save snapshot settings.
255 // TRANS: Button title to save snapshot settings.
256 _('Save snapshot settings.')