3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/settingsaction.php');
24 class OthersettingsAction extends SettingsAction {
26 function get_instructions() {
27 return _('Manage various other options.');
30 function show_form($msg=NULL, $success=false) {
31 $user = common_current_user();
33 $this->form_header(_('Other Settings'), $msg, $success);
35 common_element_start('form', array('method' => 'post',
36 'id' => 'othersettings',
38 common_local_url('othersettings')));
39 common_hidden('token', common_session_token());
41 common_element('h2', NULL, _('URL Auto-shortening'));
44 'ur1.ca' => 'ur1.ca (free service)',
45 '2tu.us' => '2tu.us (free service)',
46 'ptiturl.com' => 'ptiturl.com',
48 'tinyurl.com' => 'tinyurl.com',
50 'snipr.com' => 'snipr.com',
51 'metamark.net' => 'metamark.net'
54 common_dropdown('urlshorteningservice', _('Service'), $services, _('Shortening service to use when notices exceed the 140 character limit.'), FALSE, $user->urlshorteningservice);
56 common_submit('save', _('Save'));
58 common_element_end('form');
62 function handle_post() {
65 $token = $this->trimmed('token');
66 if (!$token || $token != common_session_token()) {
67 $this->show_form(_('There was a problem with your session token. Try again, please.'));
71 if ($this->arg('save')) {
72 $this->save_preferences();
74 $this->show_form(_('Unexpected form submission.'));
78 function save_preferences() {
80 $urlshorteningservice = $this->trimmed('urlshorteningservice');
82 if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) {
83 $this->show_form(_('URL shortening service is too long (max 50 chars).'));
87 $user = common_current_user();
89 assert(!is_null($user)); # should already be checked
91 $user->query('BEGIN');
93 $original = clone($user);
95 $user->urlshorteningservice = $urlshorteningservice;
97 $result = $user->update($original);
99 if ($result === FALSE) {
100 common_log_db_error($user, 'UPDATE', __FILE__);
101 common_server_error(_('Couldn\'t update user.'));
105 $user->query('COMMIT');
107 $this->show_form(_('Preferences saved.'), true);