<?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
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());
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();
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);
}
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;
}
$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__);
}
}
-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();
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;
}
}
}
}
}
-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);
$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: Laconica/' . 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;
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;