]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/jabber.php
Correction to previous commit
[quix0rs-gnu-social.git] / lib / jabber.php
index 3fbb3e1ab9ee0c04c9ad263cc3ba43654b97a39b..a821856a8b004c92e1b00879bbf15eba3fd5228c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Laconica, the distributed open-source microblogging tool
+ * StatusNet, the distributed open-source microblogging tool
  *
  * utility functions for Jabber/GTalk/XMPP messages
  *
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * @category  Network
- * @package   Laconica
- * @author    Evan Prodromou <evan@controlyourself.ca>
- * @copyright 2008 Control Yourself, Inc.
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @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'),
@@ -163,50 +171,30 @@ 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<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 = $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('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));
     }
-    $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";
+    $xs->text(" ");
+    $xs->element('a', array(
+        'href'=>common_local_url('conversation',
+            array('id' => $notice->conversation)).'#notice-'.$notice->id
+         ),sprintf(_('[%s]'),$notice->id));
+    $xs->elementEnd('body');
+    $xs->elementEnd('html');
 
-    $address  = "<addresses xmlns='http://jabber.org/protocol/address'>\n";
-    $address .= "<address type='replyto' jid='" . jabber_daemon_address() . "' />\n";
-    $address .= "</addresses>\n";
+    $html = $xs->getString();
 
-    // FIXME: include a pubsub event, too.
-
-    return $html . $entry . $address;
+    return $html . ' ' . $entry;
 }
 
 /**
@@ -326,7 +314,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
  *
@@ -410,8 +398,8 @@ function jabber_broadcast_notice($notice)
                  "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)) {
@@ -452,7 +440,7 @@ function jabber_public_notice($notice)
     // XXX: should we send out non-local messages if public,localonly
     // = false? I think not
 
-    if ($public && $notice->is_local) {
+    if ($public && $notice->is_local == Notice::LOCAL_PUBLIC) {
         $profile = Profile::staticGet($notice->profile_id);
 
         if (!$profile) {
@@ -492,5 +480,5 @@ function jabber_public_notice($notice)
 
 function jabber_format_notice(&$profile, &$notice)
 {
-    return $profile->nickname . ': ' . $notice->content;
+    return $profile->nickname . ': ' . $notice->content . ' [' . $notice->id . ']';
 }