]> git.mxchange.org Git - friendica.git/commitdiff
the rest of pubsubhubbub except for the UI that actually turns it on
authorMike Macgirvin <mike@macgirvin.com>
Fri, 1 Oct 2010 04:38:45 +0000 (21:38 -0700)
committerMike Macgirvin <mike@macgirvin.com>
Fri, 1 Oct 2010 04:38:45 +0000 (21:38 -0700)
include/items.php
include/notifier.php
include/poller.php
mod/pubsub.php

index 688ef244ab63ed625e5c5fc64ed519b8ef8f76a0..d726e961c91d4375961c68b36db2b04603074a7c 100644 (file)
@@ -577,7 +577,7 @@ function dfrn_deliver($contact,$atom,$debugging = false) {
 }
 
 
-function consume_feed($xml,$importer,$contact) {
+function consume_feed($xml,$importer,$contact, &$hub) {
 
        require_once('simplepie/simplepie.inc');
 
@@ -593,6 +593,12 @@ function consume_feed($xml,$importer,$contact) {
        $photo_timestamp = '';
        $photo_url = '';
 
+
+       $foundhub = $feed->get_link(0,'hub');
+
+       if(strlen($foundhub))
+               $hub = $foundhub;
+
        $rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
        if($rawtags) {
                $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
@@ -808,4 +814,37 @@ function consume_feed($xml,$importer,$contact) {
                }
        }
 
+}
+
+
+function subscribe_to_hub($url,$importer,$contact) {
+
+       if(is_array($importer)) {
+               $r = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1",
+                       intval($importer['uid'])
+               );
+       }
+       if(! count($r))
+               return;
+
+       $params = array();
+
+       $push_url = get_config('system','url') . '/pubsub/' . $r[0]['nickname'] . '/' . $contact['id'];
+
+       $verify_token = random_string();
+
+       $params['hub.mode'] = 'subscribe';
+       $params['hub.callback'] = urlencode($push_url);
+       $params['hub.topic'] = urlencode($contact['poll']);
+       $params['hub.verify'] = 'async';
+       $params['hub.verify_token'] = $verify_token;
+
+       $r = q("UPDATE `contact` SET `hub-verify` = '%s' WHERE `id` = %d LIMIT 1",
+               dbesc($verify_token),
+               intval($contact['id'])
+       );
+
+       post_url($url,$params);                 
+       return;
+
 }
\ No newline at end of file
index c339d2fb38954fc569ee9d8ae3b174075a943669..b8b07ab5807378774e34335a89aef15a6edf5be7 100644 (file)
        }
 
        if((strlen($hub)) && ($cmd !== 'mail') && (followup == false)) {
-               $params = array('hub.mode' => 'publish', 'hub.url' => $a->get_baseurl() . '/dfrn_poll/' . $owner['nickname'] );
+               $params = array('hub.mode' => 'publish', 'hub.url' => urlencode($a->get_baseurl() . '/dfrn_poll/' . $owner['nickname'] ));
                post_url($hub,$params);
        }
 
index b9ef0d93a9e54881a7a3c4652c3def19176074fd..fc77946f924fc4e4ef12c30c816b70284e53eec4 100644 (file)
                        continue;
 
 
-               consume_feed($xml,$importer,$contact);
+               consume_feed($xml,$importer,$contact,$hub);
+               
+
+               if($contact['usehub'] && strlen($hub)) {
+                       subscribe_to_hub($hub,$importer,$contact);
+               }
+
 
                $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
                        dbesc(datetime_convert()),
index 1e6add9355ff155f072b191a86b91f15e4338b1f..fa092049f41295511c69055d644297158fce25de 100644 (file)
@@ -102,7 +102,8 @@ function pubsub_post(&$a) {
 
        $contact = $r[0];
 
-       consume_feed($xml,$importer,$contact);
+       $feedhub = '';
+       consume_feed($xml,$importer,$contact,$feedhub);
 
        hub_post_return();