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 ImsettingsAction extends SettingsAction {
26 function show_top($arr) {
30 $this->message($msg, $success);
32 common_element('div', 'instructions',
33 _t('You can send and receive notices through '.
34 'Jabber/GTalk instant messages. Configure '.
35 'your address and settings below.'));
37 $this->settings_menu();
40 function show_form($msg=NULL, $success=false) {
41 $user = common_current_user();
42 common_show_header(_t('IM settings'), NULL, array($msg, $success),
43 array($this, 'show_top'));
45 common_element_start('form', array('method' => 'POST',
48 common_local_url('imsettings')));
49 # too much common patterns here... abstractable?
50 common_input('jabber', _t('IM Address'),
51 ($this->arg('jabber')) ? $this->arg('jabber') : $user->jabber,
52 _t('Jabber or GTalk address, like "UserName@example.org"'));
53 common_checkbox('jabbernotify',
54 _t('Send me notices through Jabber/GTalk.'));
55 common_checkbox('updatefrompresence',
56 _t('Post a notice when my Jabber/GTalk status changes.'));
57 common_submit('submit', _t('Save'));
58 common_element_end('form');
62 function handle_post() {
64 $jabber = jabber_normalize_jid($this->trimmed('jabber'));
65 $jabbernotify = $this->boolean('jabbernotify');
66 $updatefrompresence = $this->boolean('updatefrompresence');
68 if (!jabber_valid_base_jid($jabber)) {
69 $this->show_form(_('Not a valid Jabber ID'));
71 } else if ($this->jabber_exists($jabber)) {
72 $this->show_form(_('Not a valid Jabber ID'));
78 $user = common_current_user();
80 assert(!is_null($user)); # should already be checked
82 $user->query('BEGIN');
84 $original = clone($user);
86 $user->jabber = $jabber;
87 $user->jabbernotify = $jabbernotify;
88 $user->updatefrompresence = $updatefrompresence;
90 $result = $user->updateKeys($original); # For key columns
92 if ($result === FALSE) {
93 common_log_db_error($user, 'UPDATE', __FILE__);
94 common_server_error(_t('Couldnt update user.'));
98 $result = $user->update($original); # For non-key columns
100 if ($result === FALSE) {
101 common_log_db_error($user, 'UPDATE', __FILE__);
102 common_server_error(_t('Couldnt update user.'));
106 $user->query('COMMIT');
108 $this->show_form(_t('Settings saved.'), TRUE);
111 function jabber_exists($jabber) {
112 $user = common_current_user();
113 $other = User::staticGet('jabber', $jabber);
117 return $other->id != $user->id;