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
56 * Instructions for using this form.
58 * @return string instructions
60 function getInstructions()
62 return _m('Twitter bridge settings');
66 * Show the Twitter admin panel form
72 $form = new TwitterAdminPanelForm($this);
78 * Save settings from the form
82 function saveSettings()
84 static $settings = array(
85 'twitter' => array('consumer_key', 'consumer_secret'),
86 'integration' => array('source')
89 static $booleans = array(
90 'twitter' => array('signin')
92 if (Event::handle('TwitterBridgeAdminImportControl')) {
93 $booleans['twitterimport'] = array('enabled');
98 foreach ($settings as $section => $parts) {
99 foreach ($parts as $setting) {
100 $values[$section][$setting]
101 = $this->trimmed($setting);
105 foreach ($booleans as $section => $parts) {
106 foreach ($parts as $setting) {
107 $values[$section][$setting]
108 = ($this->boolean($setting)) ? 1 : 0;
112 // This throws an exception on validation errors
114 $this->validate($values);
116 // assert(all values are valid);
118 $config = new Config();
120 $config->query('BEGIN');
122 foreach ($settings as $section => $parts) {
123 foreach ($parts as $setting) {
124 Config::save($section, $setting, $values[$section][$setting]);
128 foreach ($booleans as $section => $parts) {
129 foreach ($parts as $setting) {
130 Config::save($section, $setting, $values[$section][$setting]);
134 $config->query('COMMIT');
136 // Flush the router cache: we may have enabled/disabled bridging,
137 // which will add or remove some actions.
138 $cache = Cache::instance();
139 $cache->delete(Router::cacheKey());
144 function validate(&$values)
146 // Validate consumer key and secret (can't be too long)
148 if (mb_strlen($values['twitter']['consumer_key']) > 255) {
150 _m("Invalid consumer key. Max length is 255 characters.")
154 if (mb_strlen($values['twitter']['consumer_secret']) > 255) {
156 _m("Invalid consumer secret. Max length is 255 characters.")
161 function isImportEnabled()
163 // Since daemon setup isn't automated yet...
164 // @todo: if merged into main queues, detect presence of daemon config
169 class TwitterAdminPanelForm extends AdminForm
174 * @return int ID of the form
178 return 'twitteradminpanel';
184 * @return string class of the form
188 return 'form_settings';
194 * @return string URL of the action
198 return common_local_url('twitteradminpanel');
202 * Data elements of the form
208 $this->out->elementStart(
210 array('id' => 'settings_twitter-application')
212 $this->out->element('legend', null, _m('Twitter application settings'));
213 $this->out->elementStart('ul', 'form_data');
219 _m('Consumer key assigned by Twitter'),
227 _m('Consumer secret'),
228 _m('Consumer secret assigned by Twitter'),
233 $globalConsumerKey = common_config('twitter', 'global_consumer_key');
234 $globalConsumerSec = common_config('twitter', 'global_consumer_secret');
236 if (!empty($globalConsumerKey) && !empty($globalConsumerSec)) {
238 $this->out->element('p', 'form_guide', _m('Note: a global consumer key and secret are set.'));
245 _m('Integration source'),
246 _m('Name of your Twitter application'),
251 $this->out->elementEnd('ul');
252 $this->out->elementEnd('fieldset');
254 $this->out->elementStart(
256 array('id' => 'settings_twitter-options')
258 $this->out->element('legend', null, _m('Options'));
260 $this->out->elementStart('ul', 'form_data');
264 $this->out->checkbox(
265 'signin', _m('Enable "Sign-in with Twitter"'),
266 (bool) $this->value('signin', 'twitter'),
267 _m('Allow users to login with their Twitter credentials')
271 if (Event::handle('TwitterBridgeAdminImportControl')) {
273 $this->out->checkbox(
274 'enabled', _m('Enable Twitter import'),
275 (bool) $this->value('enabled', 'twitterimport'),
276 _m('Allow users to import their Twitter friends\' timelines. Requires daemons to be manually configured.')
281 $this->out->elementEnd('ul');
283 $this->out->elementEnd('fieldset');
291 function formActions()
293 $this->out->submit('submit', _m('Save'), 'submit', null, _m('Save Twitter settings'));