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'),
96 'twitterimport' => array('enabled')
101 foreach ($settings as $section => $parts) {
102 foreach ($parts as $setting) {
103 $values[$section][$setting]
104 = $this->trimmed($setting);
108 foreach ($booleans as $section => $parts) {
109 foreach ($parts as $setting) {
110 $values[$section][$setting]
111 = ($this->boolean($setting)) ? 1 : 0;
115 // This throws an exception on validation errors
117 $this->validate($values);
119 // assert(all values are valid);
121 $config = new Config();
123 $config->query('BEGIN');
125 foreach ($settings as $section => $parts) {
126 foreach ($parts as $setting) {
127 Config::save($section, $setting, $values[$section][$setting]);
131 foreach ($booleans as $section => $parts) {
132 foreach ($parts as $setting) {
133 Config::save($section, $setting, $values[$section][$setting]);
137 $config->query('COMMIT');
142 function validate(&$values)
144 // Validate consumer key and secret (can't be too long)
146 if (mb_strlen($values['twitter']['consumer_key']) > 255) {
148 _m("Invalid consumer key. Max length is 255 characters.")
152 if (mb_strlen($values['twitter']['consumer_secret']) > 255) {
154 _m("Invalid consumer secret. Max length is 255 characters.")
160 class TwitterAdminPanelForm extends AdminForm
165 * @return int ID of the form
170 return 'twitteradminpanel';
176 * @return string class of the form
181 return 'form_settings';
187 * @return string URL of the action
192 return common_local_url('twitteradminpanel');
196 * 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', _('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')
267 $this->out->checkbox(
268 'enabled', _m('Enable Twitter import'),
269 (bool) $this->value('enabled', 'twitterimport'),
270 _m('Allow users to import their Twitter friends\' timelines')
274 $this->out->elementEnd('ul');
276 $this->out->elementEnd('fieldset');
285 function formActions()
287 $this->out->submit('submit', _('Save'), 'submit', null, _('Save Twitter settings'));