]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/omb.php
Merge branch 'master' into testing
[quix0rs-gnu-social.git] / lib / omb.php
index 9133af7a05ee93345abad7d79935169f92ff5b27..db60fa0ef2d0a122a65805cffe1154713df02658 100644 (file)
@@ -29,11 +29,9 @@ require_once 'Auth/Yadis/Yadis.php';
 
 function omb_oauth_consumer()
 {
-    static $con = null;
-    if (is_null($con)) {
-        $con = new OAuthConsumer(common_root_url(), '');
-    }
-    return $con;
+    // Don't try to make this static. Leads to issues in
+    // multi-site setups - Z
+    return new OAuthConsumer(common_root_url(), '');
 }
 
 function omb_oauth_server()
@@ -67,12 +65,19 @@ function omb_hmac_sha1()
 function omb_broadcast_notice($notice)
 {
 
-    $omb_notice = notice_to_omb_notice($notice);
+    try {
+        $omb_notice = notice_to_omb_notice($notice);
+    } catch (Exception $e) {
+        // @fixme we should clean up or highlight the problem item
+        common_log(LOG_ERR, 'Invalid OMB outgoing notice for notice ' . $notice->id);
+        common_log(LOG_ERR, 'Error status '.$e);
+        return true;
+    }
 
     /* Get remote users subscribed to this profile. */
     $rp = new Remote_profile();
 
-    $rp->query('SELECT postnoticeurl, token, secret ' .
+    $rp->query('SELECT remote_profile.*, secret, token ' .
                'FROM subscription JOIN remote_profile ' .
                'ON subscription.subscriber = remote_profile.id ' .
                'WHERE subscription.subscribed = ' . $notice->profile_id . ' ');
@@ -80,20 +85,16 @@ function omb_broadcast_notice($notice)
     $posted = array();
 
     while ($rp->fetch()) {
-        if (!array_key_exists($rp->postnoticeurl, $posted)) {
-            common_log(LOG_DEBUG, 'Posting to ' . $rp->postnoticeurl);
-            if (omb_post_notice_keys($notice, $rp->postnoticeurl, $rp->token, $rp->secret)) {
-                common_log(LOG_DEBUG, 'Finished to ' . $rp->postnoticeurl);
-                $posted[$rp->postnoticeurl] = true;
-            } else {
-                common_log(LOG_DEBUG, 'Failed posting to ' . $rp->postnoticeurl);
-            }
+        if (isset($posted[$rp->postnoticeurl])) {
+            /* We already posted to this url. */
+            continue;
         }
         common_debug('Posting to ' . $rp->postnoticeurl, __FILE__);
 
         /* Post notice. */
-        $service = new Laconica_OMB_Service_Consumer(
-                     array(OMB_ENDPOINT_POSTNOTICE => $rp->postnoticeurl));
+        $service = new StatusNet_OMB_Service_Consumer(
+                     array(OMB_ENDPOINT_POSTNOTICE => $rp->postnoticeurl),
+                                                      $rp->uri);
         try {
             $service->setToken($rp->token, $rp->secret);
             $service->postNotice($omb_notice);
@@ -107,7 +108,7 @@ function omb_broadcast_notice($notice)
         common_debug('Finished to ' . $rp->postnoticeurl, __FILE__);
     }
 
-    return;
+    return true;
 }
 
 function omb_broadcast_profile($profile)
@@ -125,7 +126,7 @@ function omb_broadcast_profile($profile)
     /* Get remote users subscribed to this profile. */
     $rp = new Remote_profile();
 
-    $rp->query('SELECT updateprofileurl, token, secret ' .
+    $rp->query('SELECT remote_profile.*, secret, token ' .
                'FROM subscription JOIN remote_profile ' .
                'ON subscription.subscriber = remote_profile.id ' .
                'WHERE subscription.subscribed = ' . $profile->id . ' ');
@@ -141,7 +142,8 @@ function omb_broadcast_profile($profile)
 
         /* Update profile. */
         $service = new StatusNet_OMB_Service_Consumer(
-                     array(OMB_ENDPOINT_UPDATEPROFILE => $rp->updateprofileurl));
+                     array(OMB_ENDPOINT_UPDATEPROFILE => $rp->updateprofileurl),
+                                                      $rp->uri);
         try {
             $service->setToken($rp->token, $rp->secret);
             $service->updateProfile($omb_profile);
@@ -159,12 +161,14 @@ function omb_broadcast_profile($profile)
 }
 
 class StatusNet_OMB_Service_Consumer extends OMB_Service_Consumer {
-    public function __construct($urls)
+    public function __construct($urls, $listener_uri=null)
     {
         $this->services       = $urls;
         $this->datastore      = omb_oauth_datastore();
         $this->oauth_consumer = omb_oauth_consumer();
         $this->fetcher        = Auth_Yadis_Yadis::getHTTPFetcher();
+        $this->fetcher->timeout = intval(common_config('omb', 'timeout'));
+        $this->listener_uri   = $listener_uri;
     }
 
 }