X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fjabber.php;h=d666fcbb3838899e14486bcf930ec49e044794da;hb=5ab709b73977131813884558bf56d97172a7aa26;hp=6196bc9e1d92a0a59315f4ac705a3f69bf4402c9;hpb=04b3add162674df2ebdb4e4e347b7dbea934580b;p=quix0rs-gnu-social.git diff --git a/lib/jabber.php b/lib/jabber.php index 6196bc9e1d..d666fcbb38 100644 --- a/lib/jabber.php +++ b/lib/jabber.php @@ -1,6 +1,6 @@ . * * @category Network - * @package Laconica - * @author Evan Prodromou - * @copyright 2008 Control Yourself, Inc. + * @package StatusNet + * @author Evan Prodromou + * @copyright 2008 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ + * @link http://status.net/ */ -if (!defined('LACONICA')) { +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } @@ -67,7 +67,7 @@ function jabber_normalize_jid($jid) } /** - * the JID of the Jabber daemon for this Laconica instance + * the JID of the Jabber daemon for this StatusNet instance * * @return string JID of the Jabber daemon */ @@ -77,6 +77,14 @@ function jabber_daemon_address() return common_config('xmpp', 'user') . '@' . common_config('xmpp', 'server'); } +class Sharing_XMPP extends XMPPHP_XMPP +{ + function getSocket() + { + return $this->socket; + } +} + /** * connect the configured Jabber account to the configured server * @@ -89,7 +97,7 @@ function jabber_connect($resource=null) { static $conn = null; if (!$conn) { - $conn = new XMPPHP_XMPP(common_config('xmpp', 'host') ? + $conn = new Sharing_XMPP(common_config('xmpp', 'host') ? common_config('xmpp', 'host') : common_config('xmpp', 'server'), common_config('xmpp', 'port'), @@ -114,7 +122,7 @@ function jabber_connect($resource=null) try { $conn->connect(true); // true = persistent connection } catch (XMPPHP_Exception $e) { - common_log(LOG_ERROR, $e->getMessage()); + common_log(LOG_ERR, $e->getMessage()); return false; } @@ -163,45 +171,31 @@ function jabber_send_notice($to, $notice) 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\n"; - $entry .= "\n"; - $entry .= "" . $profile->nickname . " - " . common_config('site', 'name') . "\n"; - $entry .= "\n"; - $entry .= "\n"; - $entry .= "" . $profile->nickname . "\n"; - $entry .= "" . common_profile_avatar_url($profile, AVATAR_PROFILE_SIZE) . "\n"; - $entry .= "\n"; - $entry .= "" . htmlspecialchars($msg) . "\n"; - $entry .= "" . htmlspecialchars($msg) . "\n"; - $entry .= "\n"; - $entry .= "". $notice->uri . "\n"; - $entry .= "".common_date_w3dtf($notice->created)."\n"; - $entry .= "".common_date_w3dtf($notice->modified)."\n"; - $entry .= "\n"; - - $html = "\n\n"; - $html .= "\n"; - $html .= "".$profile->nickname.": "; - $html .= ($notice->rendered) ? $notice->rendered : common_render_content($notice->content, $notice); - $html .= "\n\n"; - $html .= "\n\n"; - - $address = "\n"; - $address .= "
\n"; - $address .= "\n"; - - // FIXME: include a pubsub event, too. - - return $html . $entry . $address; + $entry = $notice->asAtomEntry(true, true); + + $xs = new XMLStringer(); + $xs->elementStart('html', array('xmlns' => 'http://jabber.org/protocol/xhtml-im')); + $xs->elementStart('body', array('xmlns' => 'http://www.w3.org/1999/xhtml')); + $xs->element("img", array('src'=> $profile->avatarUrl(AVATAR_MINI_SIZE) , 'alt' => $profile->nickname)); + $xs->element('a', array('href' => $profile->profileurl), + $profile->nickname); + $xs->text(": "); + if (!empty($notice->rendered)) { + $xs->raw($notice->rendered); + } else { + $xs->raw(common_render_content($notice->content, $notice)); + } + $xs->raw(" "); + $xs->element('a', array( + 'href'=>common_local_url('conversation', + array('id' => $notice->conversation)).'#notice-'.$notice->id + ),sprintf(_('notice id: %s'),$notice->id)); + $xs->elementEnd('body'); + $xs->elementEnd('html'); + + $html = $xs->getString(); + + return $html . ' ' . $entry; } /** @@ -321,7 +315,7 @@ function jabber_special_presence($type, $to=null, $show=null, $status=null) * who have Jabber addresses, and have Jabber notification enabled, and * have this subscription enabled for Jabber. It also sends the notice to * all recipients of @-replies who have Jabber addresses and Jabber notification - * enabled. This is really the heart of Jabber distribution in Laconica. + * enabled. This is really the heart of Jabber distribution in StatusNet. * * @param Notice $notice The notice to broadcast * @@ -354,12 +348,13 @@ function jabber_broadcast_notice($notice) // First, get users to whom this is a direct reply $user = new User(); - $user->query('SELECT user.id, user.jabber ' . - 'FROM user JOIN reply ON user.id = reply.profile_id ' . + $UT = common_config('db','type')=='pgsql'?'"user"':'user'; + $user->query("SELECT $UT.id, $UT.jabber " . + "FROM $UT JOIN reply ON $UT.id = reply.profile_id " . 'WHERE reply.notice_id = ' . $notice->id . ' ' . - 'AND user.jabber is not null ' . - 'AND user.jabbernotify = 1 ' . - 'AND user.jabberreplies = 1 '); + "AND $UT.jabber is not null " . + "AND $UT.jabbernotify = 1 " . + "AND $UT.jabberreplies = 1 "); while ($user->fetch()) { common_log(LOG_INFO, @@ -375,12 +370,12 @@ function jabber_broadcast_notice($notice) // Now, get users subscribed to this profile $user = new User(); - $user->query('SELECT user.id, user.jabber ' . - 'FROM user JOIN subscription ' . - 'ON user.id = subscription.subscriber ' . + $user->query("SELECT $UT.id, $UT.jabber " . + "FROM $UT JOIN subscription " . + "ON $UT.id = subscription.subscriber " . 'WHERE subscription.subscribed = ' . $notice->profile_id . ' ' . - 'AND user.jabber is not null ' . - 'AND user.jabbernotify = 1 ' . + "AND $UT.jabber is not null " . + "AND $UT.jabbernotify = 1 " . 'AND subscription.jabber = 1 '); while ($user->fetch()) { @@ -399,13 +394,13 @@ function jabber_broadcast_notice($notice) // Now, get users who have it in their inbox because of groups $user = new User(); - $user->query('SELECT user.id, user.jabber ' . - 'FROM user JOIN notice_inbox ' . - 'ON user.id = notice_inbox.user_id ' . + $user->query("SELECT $UT.id, $UT.jabber " . + "FROM $UT JOIN notice_inbox " . + "ON $UT.id = notice_inbox.user_id " . 'WHERE notice_inbox.notice_id = ' . $notice->id . ' ' . 'AND notice_inbox.source = 2 ' . - 'AND user.jabber is not null ' . - 'AND user.jabbernotify = 1 '); + "AND $UT.jabber is not null " . + "AND $UT.jabbernotify = 1 "); while ($user->fetch()) { if (!array_key_exists($user->id, $sent_to)) { @@ -442,7 +437,7 @@ function jabber_public_notice($notice) $public = common_config('xmpp', 'public'); - // FIXME PRIV don't send out private messages here + // FIXME PRIV do not send out private messages here // XXX: should we send out non-local messages if public,localonly // = false? I think not