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/
44 class TwitteradminpanelAction extends AdminPanelAction
47 * Returns the page title
49 * @return string page title
58 * Instructions for using this form.
60 * @return string instructions
63 function getInstructions()
65 return _m('Twitter bridge settings');
69 * Show the Twitter admin panel form
76 $form = new TwitterAdminPanelForm($this);
82 * Save settings from the form
87 function saveSettings()
89 static $settings = array(
90 'twitter' => array('consumer_key', 'consumer_secret'),
91 'integration' => array('source')
94 static $booleans = array(
95 'twitter' => array('signin')
97 if (Event::handle('TwitterBridgeAdminImportControl')) {
98 $booleans['twitterimport'] = array('enabled');
103 foreach ($settings as $section => $parts) {
104 foreach ($parts as $setting) {
105 $values[$section][$setting]
106 = $this->trimmed($setting);
110 foreach ($booleans as $section => $parts) {
111 foreach ($parts as $setting) {
112 $values[$section][$setting]
113 = ($this->boolean($setting)) ? 1 : 0;
117 // This throws an exception on validation errors
119 $this->validate($values);
121 // assert(all values are valid);
123 $config = new Config();
125 $config->query('BEGIN');
127 foreach ($settings as $section => $parts) {
128 foreach ($parts as $setting) {
129 Config::save($section, $setting, $values[$section][$setting]);
133 foreach ($booleans as $section => $parts) {
134 foreach ($parts as $setting) {
135 Config::save($section, $setting, $values[$section][$setting]);
139 $config->query('COMMIT');
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
179 return 'twitteradminpanel';
185 * @return string class of the form
190 return 'form_settings';
196 * @return string URL of the action
201 return common_local_url('twitteradminpanel');
205 * Data elements of the form
212 $this->out->elementStart(
214 array('id' => 'settings_twitter-application')
216 $this->out->element('legend', null, _m('Twitter application settings'));
217 $this->out->elementStart('ul', 'form_data');
223 _m('Consumer key assigned by Twitter'),
231 _m('Consumer secret'),
232 _m('Consumer secret assigned by Twitter'),
237 $globalConsumerKey = common_config('twitter', 'global_consumer_key');
238 $globalConsumerSec = common_config('twitter', 'global_consumer_secret');
240 if (!empty($globalConsumerKey) && !empty($globalConsumerSec)) {
242 $this->out->element('p', 'form_guide', _('Note: a global consumer key and secret are set.'));
249 _m('Integration source'),
250 _m('Name of your Twitter application'),
255 $this->out->elementEnd('ul');
256 $this->out->elementEnd('fieldset');
258 $this->out->elementStart(
260 array('id' => 'settings_twitter-options')
262 $this->out->element('legend', null, _m('Options'));
264 $this->out->elementStart('ul', 'form_data');
268 $this->out->checkbox(
269 'signin', _m('Enable "Sign-in with Twitter"'),
270 (bool) $this->value('signin', 'twitter'),
271 _m('Allow users to login with their Twitter credentials')
275 if (Event::handle('TwitterBridgeAdminImportControl')) {
277 $this->out->checkbox(
278 'enabled', _m('Enable Twitter import'),
279 (bool) $this->value('enabled', 'twitterimport'),
280 _m('Allow users to import their Twitter friends\' timelines. Requires daemons to be manually configured.')
285 $this->out->elementEnd('ul');
287 $this->out->elementEnd('fieldset');
296 function formActions()
298 $this->out->submit('submit', _('Save'), 'submit', null, _('Save Twitter settings'));