]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/omb.php
Update copyright dates in files modified in 2009
[quix0rs-gnu-social.git] / lib / omb.php
index 94ccc2ecd2b1aceee4d8a5cf3ea3b5e59718bd33..4f6a9609541ded863edcc62edef1ffcff10f4283 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  * Laconica - a distributed open-source microblogging tool
- * Copyright (C) 2008, Controlez-Vous, Inc.
+ * Copyright (C) 2008, 2009, Control Yourself, 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
@@ -43,15 +43,17 @@ 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() {
-    static $con = NULL;
+function omb_oauth_consumer()
+{
+    static $con = null;
     if (!$con) {
         $con = new OAuthConsumer(common_root_url(), '');
     }
     return $con;
 }
 
-function omb_oauth_server() {
+function omb_oauth_server()
+{
     static $server = null;
     if (!$server) {
         $server = new OAuthServer(omb_oauth_datastore());
@@ -60,59 +62,67 @@ function omb_oauth_server() {
     return $server;
 }
 
-function omb_oauth_datastore() {
-    static $store = NULL;
+function omb_oauth_datastore()
+{
+    static $store = null;
     if (!$store) {
         $store = new LaconicaOAuthDataStore();
     }
     return $store;
 }
 
-function omb_hmac_sha1() {
-    static $hmac_method = NULL;
+function omb_hmac_sha1()
+{
+    static $hmac_method = null;
     if (!$hmac_method) {
         $hmac_method = new OAuthSignatureMethod_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;
+        return null;
     }
     $uris = $service->getURIs();
     if (!$uris) {
-        return NULL;
+        return null;
     }
     return $uris[0];
 }
 
-function omb_local_id($service) {
+function omb_local_id($service)
+{
     if (!$service) {
-        return NULL;
+        return null;
     }
     $els = $service->getElements('xrd:LocalID');
     if (!$els) {
-        return NULL;
+        return null;
     }
     $el = $els[0];
     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();
@@ -129,7 +139,7 @@ function omb_broadcast_remote_subscribers($notice) {
             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: Laconica/' . LACONICA_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-AgentLaconica/' . LACONICA_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;