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');
139 function validate(&$values)
141 // Validate consumer key and secret (can't be too long)
143 if (mb_strlen($values['twitter']['consumer_key']) > 255) {
145 _m("Invalid consumer key. Max length is 255 characters.")
149 if (mb_strlen($values['twitter']['consumer_secret']) > 255) {
151 _m("Invalid consumer secret. Max length is 255 characters.")
156 function isImportEnabled()
158 // Since daemon setup isn't automated yet...
159 // @todo: if merged into main queues, detect presence of daemon config
164 class TwitterAdminPanelForm extends AdminForm
169 * @return int ID of the form
173 return 'twitteradminpanel';
179 * @return string class of the form
183 return 'form_settings';
189 * @return string URL of the action
193 return common_local_url('twitteradminpanel');
197 * Data elements of the form
203 $this->out->elementStart(
205 array('id' => 'settings_twitter-application')
207 $this->out->element('legend', null, _m('Twitter application settings'));
208 $this->out->elementStart('ul', 'form_data');
214 _m('Consumer key assigned by Twitter'),
222 _m('Consumer secret'),
223 _m('Consumer secret assigned by Twitter'),
228 $globalConsumerKey = common_config('twitter', 'global_consumer_key');
229 $globalConsumerSec = common_config('twitter', 'global_consumer_secret');
231 if (!empty($globalConsumerKey) && !empty($globalConsumerSec)) {
233 $this->out->element('p', 'form_guide', _m('Note: a global consumer key and secret are set.'));
240 _m('Integration source'),
241 _m('Name of your Twitter application'),
246 $this->out->elementEnd('ul');
247 $this->out->elementEnd('fieldset');
249 $this->out->elementStart(
251 array('id' => 'settings_twitter-options')
253 $this->out->element('legend', null, _m('Options'));
255 $this->out->elementStart('ul', 'form_data');
259 $this->out->checkbox(
260 'signin', _m('Enable "Sign-in with Twitter"'),
261 (bool) $this->value('signin', 'twitter'),
262 _m('Allow users to login with their Twitter credentials')
266 if (Event::handle('TwitterBridgeAdminImportControl')) {
268 $this->out->checkbox(
269 'enabled', _m('Enable Twitter import'),
270 (bool) $this->value('enabled', 'twitterimport'),
271 _m('Allow users to import their Twitter friends\' timelines. Requires daemons to be manually configured.')
276 $this->out->elementEnd('ul');
278 $this->out->elementEnd('fieldset');
286 function formActions()
288 $this->out->submit('submit', _m('Save'), 'submit', null, _m('Save Twitter settings'));