+ $user->query('COMMIT');
+
+ $this->show_form(_t('Preferences saved.'), true);
+ }
+
+ function add_address() {
+
+ $user = common_current_user();
+
+ $jabber = $this->trimmed('jabber');
+
+ # Some validation
+
+ if (!$jabber) {
+ $this->show_form(_t('No Jabber ID.'));
+ return;
+ }
+
+ $jabber = jabber_normalize_jid($jabber);
+
+ if (!$jabber) {
+ $this->show_form(_('Cannot normalize that Jabber ID'));
+ return;
+ }
+ if (!jabber_valid_base_jid($jabber)) {
+ $this->show_form(_('Not a valid Jabber ID'));
+ return;
+ } else if ($user->jabber == $jabber) {
+ $this->show_form(_('That is already your Jabber ID.'));
+ return;
+ } else if ($this->jabber_exists($jabber)) {
+ $this->show_form(_('Jabber ID already belongs to another user.'));
+ return;
+ }
+
+ $confirm = new Confirm_address();
+ $confirm->address = $jabber;
+ $confirm->address_type = 'jabber';
+ $confirm->user_id = $user->id;
+ $confirm->code = common_confirmation_code(64);
+
+ $result = $confirm->insert();
+
+ if ($result === FALSE) {
+ common_log_db_error($confirm, 'INSERT', __FILE__);
+ common_server_error(_t('Couldnt insert confirmation code.'));
+ return;
+ }
+
+ # XXX: optionally queue for offline sending
+
+ if (!jabber_is_subscribed($jabber)) {
+ jabber_special_presence('subscribe', $jabber);
+ } else {
+ jabber_confirm_address($confirm->code,
+ $user->nickname,
+ $jabber);
+ }
+
+ $this->show_form(_t('A confirmation code was ' .
+ ' sent to the IM address you added. ' .
+ ' You must approve ' . jabber_daemon_address() .
+ ' for sending messages to you.'),
+ TRUE);
+ }
+
+ function cancel_confirmation() {
+ $jabber = $this->arg('jabber');
+ $confirm = $this->get_confirmation();
+ if (!$confirm) {
+ $this->show_form(_t('No pending confirmation to cancel.'));
+ return;
+ }
+ if ($confirm->address != $jabber) {
+ $this->show_form(_t('That is the wrong IM address.'));
+ return;
+ }
+
+ $result = $confirm->delete();
+
+ if (!$result) {
+ common_log_db_error($confirm, 'DELETE', __FILE__);
+ $this->server_error(_t('Couldn\'t delete email confirmation.'));
+ return;
+ }
+
+ $this->show_form(_t('Confirmation cancelled.'), TRUE);
+ }
+
+ function remove_address() {
+
+ $user = common_current_user();
+ $jabber = $this->arg('jabber');
+
+ # Maybe an old tab open...?
+