/** * Sends a confirmation to the address given * * Stores a confirmation record and sends out a * Jabber message with the confirmation info. * * @return void */ function addAddress() { $user = common_current_user(); $jabber = $this->trimmed('jabber'); // Some validation if (!$jabber) { $this->showForm(_('No Jabber ID.')); return; } $jabber = jabber_normalize_jid($jabber); if (!$jabber) { $this->showForm(_('Cannot normalize that Jabber ID')); return; } if (!jabber_valid_base_jid($jabber)) { $this->showForm(_('Not a valid Jabber ID')); return; } else { if ($user->jabber == $jabber) { $this->showForm(_('That is already your Jabber ID.')); return; } else { if ($this->jabberExists($jabber)) { $this->showForm(_('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__); $this->serverError(_('Couldn\'t insert confirmation code.')); return; } if (!common_config('queue', 'enabled')) { jabber_confirm_address($confirm->code, $user->nickname, $jabber); } $msg = sprintf(_('A confirmation code was sent ' . 'to the IM address you added. ' . 'You must approve %s for ' . 'sending messages to you.'), jabber_daemon_address()); $this->showForm($msg, true); }
/** * Sends a confirmation to the address given * * Stores a confirmation record and sends out a * Jabber message with the confirmation info. * * @return void */ function addAddress() { $user = common_current_user(); $jabber = $this->trimmed('jabber'); // Some validation if (!$jabber) { // TRANS: Message given saving IM address without having provided one. $this->showForm(_('No Jabber ID.')); return; } $jabber = jabber_normalize_jid($jabber); if (!$jabber) { // TRANS: Message given saving IM address that cannot be normalised. $this->showForm(_('Cannot normalize that Jabber ID')); return; } if (!jabber_valid_base_jid($jabber, common_config('email', 'domain_check'))) { // TRANS: Message given saving IM address that not valid. $this->showForm(_('Not a valid Jabber ID')); return; } else { if ($user->jabber == $jabber) { // TRANS: Message given saving IM address that is already set. $this->showForm(_('That is already your Jabber ID.')); return; } else { if ($this->jabberExists($jabber)) { // TRANS: Message given saving IM address that is already set for another user. $this->showForm(_('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); $confirm->sent = common_sql_now(); $confirm->claimed = common_sql_now(); $result = $confirm->insert(); if ($result === false) { common_log_db_error($confirm, 'INSERT', __FILE__); // TRANS: Server error thrown on database error adding IM confirmation code. $this->serverError(_('Couldn\'t insert confirmation code.')); return; } jabber_confirm_address($confirm->code, $user->nickname, $jabber); // TRANS: Message given saving valid IM address that is to be confirmed. // TRANS: %s is the IM address set for the site. $msg = sprintf(_('A confirmation code was sent ' . 'to the IM address you added. ' . 'You must approve %s for ' . 'sending messages to you.'), jabber_daemon_address()); $this->showForm($msg, true); }
function listener() { if (common_config('xmpp', 'listener')) { return common_config('xmpp', 'listener'); } else { return jabber_daemon_address() . '/' . common_config('xmpp', 'resource') . '-listener'; } }
function is_self($from) { return preg_match('/^' . strtolower(jabber_daemon_address()) . '/', strtolower($from)); }
/** * extra information for XMPP messages, as defined by Twitter * * @param Profile $profile Profile of the sending user * @param Notice $notice Notice being sent * * @return string Extra information (Atom, HTML, addresses) in string format */ function jabber_format_entry($profile, $notice) { // FIXME: notice url might be remote $noticeurl = common_local_url('shownotice', array('notice' => $notice->id)); $msg = jabber_format_notice($profile, $notice); $self_url = common_local_url('userrss', array('nickname' => $profile->nickname)); $entry = "\n<entry xmlns='http://www.w3.org/2005/Atom'>\n"; $entry .= "<source>\n"; $entry .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n"; $entry .= "<link href='" . htmlspecialchars($profile->profileurl) . "'/>\n"; $entry .= "<link rel='self' type='application/rss+xml' href='" . $self_url . "'/>\n"; $entry .= "<author><name>" . $profile->nickname . "</name></author>\n"; $entry .= "<icon>" . $profile->avatarUrl(AVATAR_PROFILE_SIZE) . "</icon>\n"; $entry .= "</source>\n"; $entry .= "<title>" . htmlspecialchars($msg) . "</title>\n"; $entry .= "<summary>" . htmlspecialchars($msg) . "</summary>\n"; $entry .= "<link rel='alternate' href='" . $noticeurl . "' />\n"; $entry .= "<id>" . $notice->uri . "</id>\n"; $entry .= "<published>" . common_date_w3dtf($notice->created) . "</published>\n"; $entry .= "<updated>" . common_date_w3dtf($notice->modified) . "</updated>\n"; if ($notice->reply_to) { $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to)); $entry .= "<link rel='related' href='" . $replyurl . "'/>\n"; } $entry .= "</entry>\n"; $html = "\n<html xmlns='http://jabber.org/protocol/xhtml-im'>\n"; $html .= "<body xmlns='http://www.w3.org/1999/xhtml'>\n"; $html .= "<a href='" . htmlspecialchars($profile->profileurl) . "'>" . $profile->nickname . "</a>: "; $html .= $notice->rendered ? $notice->rendered : common_render_content($notice->content, $notice); $html .= "\n</body>\n"; $html .= "\n</html>\n"; $address = "<addresses xmlns='http://jabber.org/protocol/address'>\n"; $address .= "<address type='replyto' jid='" . jabber_daemon_address() . "' />\n"; $address .= "</addresses>\n"; // FIXME: include a pubsub event, too. return $html . $entry . $address; }