X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fjabber.php;h=bd7d6b7074d38acbeb713a124d67178812eebfbc;hb=dd4c0ebaa8717012e8bae58088c1a2760152bc41;hp=a0f5080d0fb9faeb641010704a3949eee606d02f;hpb=03a84f45fd05f42c642392e9fe6916dc2790f396;p=quix0rs-gnu-social.git
diff --git a/lib/jabber.php b/lib/jabber.php
index a0f5080d0f..bd7d6b7074 100644
--- a/lib/jabber.php
+++ b/lib/jabber.php
@@ -21,30 +21,6 @@ if (!defined('LACONICA')) { exit(1); }
require_once('XMPPHP/XMPP.php');
-# XXX: something of a hack to work around problems with the XMPPHP lib
-
-class Laconica_XMPP extends XMPPHP_XMPP {
-
- function messageplus($to, $body, $type = 'chat', $subject = null, $payload = null) {
- $to = htmlspecialchars($to);
- $body = htmlspecialchars($body);
- $subject = htmlspecialchars($subject);
-
- $jid = jabber_daemon_address();
-
- $out = "";
- if($subject) $out .= "$subject";
- $out .= "$body";
- if($payload) $out .= $payload;
- $out .= "";
-
- $cnt = strlen($out);
- common_log(LOG_DEBUG, "Sending $cnt chars to $to");
- $this->send($out);
- common_log(LOG_DEBUG, 'Done.');
- }
-}
-
function jabber_valid_base_jid($jid) {
# Cheap but effective
return Validate::email($jid);
@@ -54,7 +30,6 @@ function jabber_normalize_jid($jid) {
if (preg_match("/(?:([^\@]+)\@)?([^\/]+)(?:\/(.*))?$/", $jid, $matches)) {
$node = $matches[1];
$server = $matches[2];
- $resource = $matches[3];
return strtolower($node.'@'.$server);
} else {
return NULL;
@@ -68,7 +43,7 @@ function jabber_daemon_address() {
function jabber_connect($resource=NULL) {
static $conn = NULL;
if (!$conn) {
- $conn = new Laconica_XMPP(common_config('xmpp', 'host') ?
+ $conn = new XMPPHP_XMPP(common_config('xmpp', 'host') ?
common_config('xmpp', 'host') :
common_config('xmpp', 'server'),
common_config('xmpp', 'port'),
@@ -82,15 +57,21 @@ function jabber_connect($resource=NULL) {
common_config('xmpp', 'debug') ?
XMPPHP_Log::LEVEL_VERBOSE : NULL
);
- $conn->autoSubscribe();
if (!$conn) {
return false;
}
- $conn->connect(true); # true = persistent connection
- if ($conn->isDisconnected()) {
+
+ $conn->autoSubscribe();
+ $conn->useEncryption(common_config('xmpp', 'encryption'));
+
+ try {
+ $conn->connect(true); # true = persistent connection
+ } catch (XMPPHP_Exception $e) {
+ common_log(LOG_ERROR, $e->getMessage());
return false;
}
+
$conn->processUntil('session_start');
}
return $conn;
@@ -110,21 +91,24 @@ function jabber_send_notice($to, $notice) {
}
$msg = jabber_format_notice($profile, $notice);
$entry = jabber_format_entry($profile, $notice);
- $conn->messageplus($to, $msg, 'chat', NULL, $entry);
+ $conn->message($to, $msg, 'chat', NULL, $entry);
+ $profile->free();
return true;
}
# Extra stuff defined by Twitter, needed by twitter clients
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);
$entry = "\n\n";
$entry .= "\n";
$entry .= "" . $profile->nickname . " - " . common_config('site', 'name') . "\n";
- $entry .= "\n";
+ $entry .= "\n";
$entry .= " $profile->nickname)) . "'/>\n";
$entry .= "" . $profile->nickname . "\n";
$entry .= "" . common_profile_avatar_url($profile, AVATAR_PROFILE_SIZE) . "\n";
@@ -143,16 +127,14 @@ function jabber_format_entry($profile, $notice) {
$html .= ($notice->rendered) ? $notice->rendered : common_render_content($notice->content, $notice);
$html .= "\n