summaryrefslogtreecommitdiff
path: root/lib/omb.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/omb.php')
-rw-r--r--lib/omb.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/omb.php b/lib/omb.php
index 7c7a21cc8..89d0afa9e 100644
--- a/lib/omb.php
+++ b/lib/omb.php
@@ -110,3 +110,63 @@ function omb_local_id($service) {
return $service->parser->content($el);
}
+function omb_broadcast_remote_subscribers($notice) {
+ # First, get remote users subscribed to this profile
+ $sub = new Subscription();
+ $sub->subscribed = $notice->profile_id;
+ $rp = new Remote_profile();
+ $sub->addJoin($rp, 'INNER', NULL, 'subscriber');
+ if ($sub->find()) {
+ $posted = array();
+ while ($sub->fetch()) {
+ if (!$posted[$rp->postnoticeurl]) {
+ if (omb_post_notice($notice, $rp, $sub)) {
+ $posted[$rp->postnoticeurl] = TRUE;
+ }
+ }
+ }
+ }
+}
+
+function omb_post_notice($notice, $remote_profile, $subscription) {
+ global $config; # for license URL
+ $user = User::staticGet('id', $notice->profile_id);
+ $con = omb_oauth_consumer();
+ $token = new OAuthToken($subscription->token, $subscription->secret);
+ $url = $remote_profile->postnoticeurl;
+ $parsed = parse_url($url);
+ $params = array();
+ parse_str($parsed['query'], $params);
+ $req = OAuthRequest::from_consumer_and_token($con, $token,
+ "POST", $url, $params);
+ $req->set_parameter('omb_version', OMB_VERSION_01);
+ $req->set_parameter('omb_listenee', $user->uri);
+ $req->set_parameter('omb_notice', $notice->uri);
+ $req->set_parameter('omb_notice_content', $notice->content);
+ $req->set_parameter('omb_notice_url', common_local_url('shownotice',
+ array('notice' =>
+ $notice->id)));
+ $req->set_parameter('omb_notice_license', $config['license']['url']);
+ $req->sign_request(omb_hmac_sha1(), $con, $tok);
+
+ # We re-use this tool's fetcher, since it's pretty good
+
+ $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
+
+ $result = $fetcher->post($req->get_normalized_http_url(),
+ $req->to_postdata());
+
+ if ($result->status == 403) { # not authorized, don't send again
+ $subscription->delete();
+ return false;
+ } else if ($result->status != 200) {
+ return false;
+ } else { # success!
+ parse_str($result->body, $return);
+ if ($return['omb_version'] == OMB_VERSION_01) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+}