3 * StatusNet, the distributed open-source microblogging tool
5 * Twitter bridge 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')) {
35 * Administer global Twitter bridge settings
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 TwitteradminpanelAction extends AdminPanelAction
46 * Returns the page title
48 * @return string page title
52 // TRANS: Page title for Twitter administration panel.
53 return _m('TITLE','Twitter');
57 * Instructions for using this form.
59 * @return string instructions
61 function getInstructions()
63 // TRANS: Instructions for Twitter bridge administration page.
64 return _m('Twitter bridge settings');
68 * Show the Twitter admin panel form
74 $form = new TwitterAdminPanelForm($this);
80 * Save settings from the form
84 function saveSettings()
86 static $settings = array(
87 'twitter' => array('consumer_key', 'consumer_secret'),
88 'integration' => array('source')
91 static $booleans = array(
92 'twitter' => array('signin')
94 if (Event::handle('TwitterBridgeAdminImportControl')) {
95 $booleans['twitterimport'] = array('enabled');
100 foreach ($settings as $section => $parts) {
101 foreach ($parts as $setting) {
102 $values[$section][$setting]
103 = $this->trimmed($setting);
107 foreach ($booleans as $section => $parts) {
108 foreach ($parts as $setting) {
109 $values[$section][$setting]
110 = ($this->boolean($setting)) ? 1 : 0;
114 // This throws an exception on validation errors
116 $this->validate($values);
118 // assert(all values are valid);
120 $config = new Config();
122 $config->query('BEGIN');
124 foreach ($settings as $section => $parts) {
125 foreach ($parts as $setting) {
126 Config::save($section, $setting, $values[$section][$setting]);
130 foreach ($booleans as $section => $parts) {
131 foreach ($parts as $setting) {
132 Config::save($section, $setting, $values[$section][$setting]);
136 $config->query('COMMIT');
138 // Flush the router cache: we may have enabled/disabled bridging,
139 // which will add or remove some actions.
140 $cache = Cache::instance();
141 $cache->delete(Router::cacheKey());
146 function validate(&$values)
148 // Validate consumer key and secret (can't be too long)
150 if (mb_strlen($values['twitter']['consumer_key']) > 255) {
152 // TRANS: Client error displayed when a consumer key is invalid because it is too long.
153 _m('Invalid consumer key. Maximum length is 255 characters.')
157 if (mb_strlen($values['twitter']['consumer_secret']) > 255) {
159 // TRANS: Client error displayed when a consumer secret is invalid because it is too long.
160 _m('Invalid consumer secret. Maximum length is 255 characters.')
165 function isImportEnabled()
167 // Since daemon setup isn't automated yet...
168 // @todo: if merged into main queues, detect presence of daemon config
173 class TwitterAdminPanelForm extends AdminForm
178 * @return int ID of the form
182 return 'twitteradminpanel';
188 * @return string class of the form
192 return 'form_settings';
198 * @return string URL of the action
202 return common_local_url('twitteradminpanel');
206 * Data elements of the form
212 $this->out->elementStart(
214 array('id' => 'settings_twitter-application')
216 // TRANS: Fieldset legend for Twitter application settings.
217 $this->out->element('legend', null, _m('Twitter application settings'));
218 $this->out->elementStart('ul', 'form_data');
223 // TRANS: Field label for Twitter assigned consumer key.
225 // TRANS: Field title for Twitter assigned consumer key.
226 _m('The consumer key assigned by Twitter.'),
234 // TRANS: Field label for Twitter assigned consumer secret.
235 _m('Consumer secret'),
236 // TRANS: Field title for Twitter assigned consumer secret.
237 _m('The consumer secret assigned by Twitter.'),
242 $globalConsumerKey = common_config('twitter', 'global_consumer_key');
243 $globalConsumerSec = common_config('twitter', 'global_consumer_secret');
245 if (!empty($globalConsumerKey) && !empty($globalConsumerSec)) {
247 // TRANS: Form guide displayed when two required fields have already been provided.
248 $this->out->element('p', 'form_guide', _m('Note: A global consumer key and secret are set.'));
255 // TRANS: Field label for Twitter application name.
256 _m('Integration source'),
257 // TRANS: Field title for Twitter application name.
258 _m('The name of your Twitter application.'),
263 $this->out->elementEnd('ul');
264 $this->out->elementEnd('fieldset');
266 $this->out->elementStart(
268 array('id' => 'settings_twitter-options')
270 // TRANS: Fieldset legend for Twitter integration options.
271 $this->out->element('legend', null, _m('Options'));
273 $this->out->elementStart('ul', 'form_data');
277 $this->out->checkbox(
278 // TRANS: Checkbox label for global setting.
279 'signin', _m('Enable "Sign-in with Twitter"'),
280 (bool) $this->value('signin', 'twitter'),
281 // TRANS: Checkbox title.
282 _m('This allow users to login with their Twitter credentials.')
286 if (Event::handle('TwitterBridgeAdminImportControl')) {
288 $this->out->checkbox(
289 // TRANS: Checkbox label for global setting.
290 'enabled', _m('Enable Twitter import'),
291 (bool) $this->value('enabled', 'twitterimport'),
292 // TRANS: Checkbox title for global setting.
293 _m('Allow users to import their Twitter friends\' timelines. Requires daemons to be manually configured.')
298 $this->out->elementEnd('ul');
300 $this->out->elementEnd('fieldset');
308 function formActions()
310 // TRANS: Button text for saving the administrative Twitter bridge settings.
311 $this->out->submit('submit', _m('BUTTON','Save'), 'submit', null,
312 // TRANS: Button title for saving the administrative Twitter bridge settings.
313 _m('Save the Twitter bridge settings.'));