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 function jabber_valid_base_jid($jid) {
24 return Validate::email($jid);
27 function jabber_normalize_jid($jid) {
28 preg_match("/(?:([^\@]+)\@)?([^\/]+)(?:\/(.*))?$/", $jid, $matches);
30 $server = $matches[2];
31 $resource = $matches[3];
32 return strtolower($node.'@'.$server);
35 function jabber_connect($resource=NULL) {
38 $conn = new XMPP(common_config('xmpp', 'server'),
39 common_config('xmpp', 'port'),
40 common_config('xmpp', 'user'),
41 common_config('xmpp', 'password'),
42 ($resource) ? $resource :
43 common_config('xmpp', 'resource'));
48 $conn->connect(true); # try to get a persistent connection
49 if ($conn->disconnected) {
52 $conn->processUntil('session_start');
57 function jabber_send_message($to, $body, $type='chat', $subject=NULL) {
58 $conn = jabber_connect();
62 $conn->message($to, $body, $type, $subject);
66 function jabber_send_presence($status=Null, $show='available', $to=Null) {
67 $conn = jabber_connect();
71 $conn->presence($status, $show, $to);
75 function jabber_confirm_address($code, $nickname, $address) {
77 # FIXME: do we have to request presence first?
79 $body = "Hey, $nickname.";
81 $body .= 'Someone just entered this IM address on ';
82 $body .= common_config('site', 'name') . '.';
84 $body .= 'If it was you, and you want to confirm your entry, ';
85 $body .= 'use the URL below:';
87 $body .= "\t".common_local_url('confirmaddress',
88 array('code' => $code));
90 $body .= 'If not, just ignore this message.';
92 $body .= 'Thanks for your time, ';
94 $body .= common_config('site', 'name');
97 jabber_send_message($address, $body);