]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/omb.php
Revert "fixed up some invalid comment syntax - this is ANSI SQL"
[quix0rs-gnu-social.git] / lib / omb.php
index 8199b0679d20d8e286c63ae468c2c2ccd9c6d5f7..7dca760c6951da3c72e2e71132d7c6c133d12400 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
- * Laconica - a distributed open-source microblogging tool
- * Copyright (C) 2008, Controlez-Vous, Inc.
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008, 2009, StatusNet, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
@@ -17,7 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('LACONICA')) { exit(1); }
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
 
 require_once('OAuth.php');
 require_once(INSTALLDIR.'/lib/oauthstore.php');
@@ -43,7 +43,8 @@ define('OAUTH_AUTH_HEADER', OAUTH_NAMESPACE.'parameters/auth-header');
 define('OAUTH_POST_BODY', OAUTH_NAMESPACE.'parameters/post-body');
 define('OAUTH_HMAC_SHA1', OAUTH_NAMESPACE.'signature/HMAC-SHA1');
 
-function omb_oauth_consumer() {
+function omb_oauth_consumer()
+{
     static $con = null;
     if (!$con) {
         $con = new OAuthConsumer(common_root_url(), '');
@@ -51,7 +52,8 @@ function omb_oauth_consumer() {
     return $con;
 }
 
-function omb_oauth_server() {
+function omb_oauth_server()
+{
     static $server = null;
     if (!$server) {
         $server = new OAuthServer(omb_oauth_datastore());
@@ -60,15 +62,17 @@ function omb_oauth_server() {
     return $server;
 }
 
-function omb_oauth_datastore() {
+function omb_oauth_datastore()
+{
     static $store = null;
     if (!$store) {
-        $store = new LaconicaOAuthDataStore();
+        $store = new StatusNetOAuthDataStore();
     }
     return $store;
 }
 
-function omb_hmac_sha1() {
+function omb_hmac_sha1()
+{
     static $hmac_method = null;
     if (!$hmac_method) {
         $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
@@ -76,20 +80,24 @@ function omb_hmac_sha1() {
     return $hmac_method;
 }
 
-function omb_get_services($xrd, $type) {
+function omb_get_services($xrd, $type)
+{
     return $xrd->services(array(omb_service_filter($type)));
 }
 
-function omb_service_filter($type) {
+function omb_service_filter($type)
+{
     return create_function('$s',
                            'return omb_match_service($s, \''.$type.'\');');
 }
 
-function omb_match_service($service, $type) {
+function omb_match_service($service, $type)
+{
     return in_array($type, $service->getTypes());
 }
 
-function omb_service_uri($service) {
+function omb_service_uri($service)
+{
     if (!$service) {
         return null;
     }
@@ -100,7 +108,8 @@ function omb_service_uri($service) {
     return $uris[0];
 }
 
-function omb_local_id($service) {
+function omb_local_id($service)
+{
     if (!$service) {
         return null;
     }
@@ -112,7 +121,8 @@ function omb_local_id($service) {
     return $service->parser->content($el);
 }
 
-function omb_broadcast_remote_subscribers($notice) {
+function omb_broadcast_remote_subscribers($notice)
+{
 
     # First, get remote users subscribed to this profile
     $rp = new Remote_profile();
@@ -125,11 +135,11 @@ function omb_broadcast_remote_subscribers($notice) {
     $posted = array();
 
     while ($rp->fetch()) {
-        if (!$posted[$rp->postnoticeurl]) {
+        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;
+                $posted[$rp->postnoticeurl] = true;
             } else {
                 common_log(LOG_DEBUG, 'Failed posting to ' . $rp->postnoticeurl);
             }
@@ -142,18 +152,16 @@ function omb_broadcast_remote_subscribers($notice) {
     return true;
 }
 
-function omb_post_notice($notice, $remote_profile, $subscription) {
+function omb_post_notice($notice, $remote_profile, $subscription)
+{
     return omb_post_notice_keys($notice, $remote_profile->postnoticeurl, $subscription->token, $subscription->secret);
 }
 
-function omb_post_notice_keys($notice, $postnoticeurl, $tk, $secret) {
-
-    common_debug('Posting notice ' . $notice->id . ' to ' . $postnoticeurl, __FILE__);
-
+function omb_post_notice_keys($notice, $postnoticeurl, $tk, $secret)
+{
     $user = User::staticGet('id', $notice->profile_id);
 
     if (!$user) {
-        common_debug('Failed to get user for notice ' . $notice->id . ', profile = ' . $notice->profile_id, __FILE__);
         return false;
     }
 
@@ -194,9 +202,7 @@ function omb_post_notice_keys($notice, $postnoticeurl, $tk, $secret) {
 
     $result = $fetcher->post($req->get_normalized_http_url(),
                              $req->to_postdata(),
-                             array('User-Agent' => 'Laconica/' . LACONICA_VERSION));
-
-    common_debug('Got HTTP result "'.print_r($result,TRUE).'"', __FILE__);
+                             array('User-Agent: StatusNet/' . STATUSNET_VERSION));
 
     if ($result->status == 403) { # not authorized, don't send again
         common_debug('403 result, deleting subscription', __FILE__);
@@ -216,7 +222,8 @@ function omb_post_notice_keys($notice, $postnoticeurl, $tk, $secret) {
     }
 }
 
-function omb_broadcast_profile($profile) {
+function omb_broadcast_profile($profile)
+{
     # First, get remote users subscribed to this profile
     # XXX: use a join here rather than looping through results
     $sub = new Subscription();
@@ -226,9 +233,9 @@ function omb_broadcast_profile($profile) {
         while ($sub->fetch()) {
             $rp = Remote_profile::staticGet('id', $sub->subscriber);
             if ($rp) {
-                if (!$updated[$rp->updateprofileurl]) {
+                if (!array_key_exists($rp->updateprofileurl, $updated)) {
                     if (omb_update_profile($profile, $rp, $sub)) {
-                        $updated[$rp->updateprofileurl] = TRUE;
+                        $updated[$rp->updateprofileurl] = true;
                     }
                 }
             }
@@ -236,8 +243,8 @@ function omb_broadcast_profile($profile) {
     }
 }
 
-function omb_update_profile($profile, $remote_profile, $subscription) {
-    global $config; # for license URL
+function omb_update_profile($profile, $remote_profile, $subscription)
+{
     $user = User::staticGet($profile->id);
     $con = omb_oauth_consumer();
     $token = new OAuthToken($subscription->token, $subscription->secret);
@@ -273,15 +280,13 @@ function omb_update_profile($profile, $remote_profile, $subscription) {
 
     $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
 
-    common_debug('request URL = '.$req->get_normalized_http_url(), __FILE__);
-    common_debug('postdata = '.$req->to_postdata(), __FILE__);
     $result = $fetcher->post($req->get_normalized_http_url(),
                              $req->to_postdata(),
-                             array('User-Agent' => 'Laconica/' . LACONICA_VERSION));
+                             array('User-Agent: StatusNet/' . STATUSNET_VERSION));
 
-    common_debug('Got HTTP result "'.print_r($result,TRUE).'"', __FILE__);
-
-    if ($result->status == 403) { # not authorized, don't send again
+    if (empty($result) || !$result) {
+        common_debug("Unable to contact " . $req->get_normalized_http_url());
+    } else if ($result->status == 403) { # not authorized, don't send again
         common_debug('403 result, deleting subscription', __FILE__);
         $subscription->delete();
         return false;
@@ -290,7 +295,7 @@ function omb_update_profile($profile, $remote_profile, $subscription) {
         return false;
     } else { # success!
         parse_str($result->body, $return);
-        if ($return['omb_version'] == OMB_VERSION_01) {
+        if (isset($return['omb_version']) && $return['omb_version'] === OMB_VERSION_01) {
             return true;
         } else {
             return false;