From e607a9dcda71f72f8240d1772ee4a627382e7bd5 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 22 Aug 2017 10:18:07 +0000 Subject: [PATCH 1/4] Our user feeds now look more like OStatus --- mod/_well_known.php | 4 ++++ mod/dfrn_poll.php | 9 +++++++++ mod/xrd.php | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/mod/_well_known.php b/mod/_well_known.php index 45c1da494..d75f43fbe 100644 --- a/mod/_well_known.php +++ b/mod/_well_known.php @@ -5,6 +5,7 @@ use Friendica\Core\Config; require_once("mod/hostxrd.php"); require_once("mod/nodeinfo.php"); +require_once("mod/xrd.php"); function _well_known_init(App $a) { if ($a->argc > 1) { @@ -18,6 +19,9 @@ function _well_known_init(App $a) { case "nodeinfo": nodeinfo_wellknown($a); break; + case "webfinger": + xrd_init($a); + break; } } http_status_exit(404); diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index ba845e41f..f02539b00 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -5,6 +5,7 @@ use Friendica\App; require_once('include/items.php'); require_once('include/auth.php'); require_once('include/dfrn.php'); +require_once('include/ostatus.php'); function dfrn_poll_init(App $a) { $dfrn_id = ((x($_GET,'dfrn_id')) ? $_GET['dfrn_id'] : ''); @@ -17,6 +18,14 @@ function dfrn_poll_init(App $a) { $perm = ((x($_GET,'perm')) ? $_GET['perm'] : 'r'); $quiet = ((x($_GET,'quiet')) ? true : false); + // Possibly it is an OStatus compatible server that requests a user feed + if (($a->argc > 1) && ($dfrn_id == '') && !strstr($_SERVER["HTTP_USER_AGENT"], 'Friendica')) { + $nickname = $a->argv[1]; + header("Content-type: application/atom+xml"); + echo ostatus::feed($a, $nickname, $last_update); + killme(); + } + $direction = (-1); diff --git a/mod/xrd.php b/mod/xrd.php index bfb889258..acde4d9f3 100644 --- a/mod/xrd.php +++ b/mod/xrd.php @@ -8,6 +8,10 @@ function xrd_init(App $a) { $uri = urldecode(notags(trim($_GET['uri']))); + if ($uri == "") { + $uri = urldecode(notags(trim($_GET['resource']))); + } + if(substr($uri,0,4) === 'http') { $acct = false; $name = basename($uri); From b378f5fb018bf78331f29b6e6e8f21f023b5408d Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 23 Aug 2017 05:01:15 +0000 Subject: [PATCH 2/4] The "hub" url now contains the nickname --- include/dfrn.php | 2 +- include/ostatus.php | 9 +++++---- include/pubsubpublish.php | 2 +- mod/pubsubhubbub.php | 25 +++++++++++++++---------- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 8484f7c61..c2b599ce2 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -504,7 +504,7 @@ class dfrn { if ($public) { // DFRN itself doesn't uses this. But maybe someone else wants to subscribe to the public feed. - ostatus::hublinks($doc, $root); + ostatus::hublinks($doc, $root, $owner["nick"]); $attributes = array("rel" => "salmon", "href" => App::get_baseurl()."/salmon/".$owner["nick"]); xml::add_element($doc, $root, "link", "", $attributes); diff --git a/include/ostatus.php b/include/ostatus.php index 3e27bc5d5..892d24993 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -1470,7 +1470,7 @@ class ostatus { /// "type" => "application/json"); /// xml::add_element($doc, $root, "link", "", $attributes); - self::hublinks($doc, $root); + self::hublinks($doc, $root, $owner["nick"]); $attributes = array("href" => App::get_baseurl()."/salmon/".$owner["nick"], "rel" => "salmon"); xml::add_element($doc, $root, "link", "", $attributes); @@ -1494,7 +1494,7 @@ class ostatus { * @param object $doc XML document * @param object $root XML root element where the hub links are added */ - public static function hublinks($doc, $root) { + public static function hublinks($doc, $root, $nick) { $hub = get_config('system','huburl'); $hubxml = ''; @@ -1505,8 +1505,9 @@ class ostatus { $h = trim($h); if (! strlen($h)) continue; - if ($h === '[internal]') - $h = App::get_baseurl() . '/pubsubhubbub'; + if ($h === '[internal]') { + $h = App::get_baseurl() . '/pubsubhubbub/'.$nick; + } xml::add_element($doc, $root, "link", "", array("href" => $h, "rel" => "hub")); } } diff --git a/include/pubsubpublish.php b/include/pubsubpublish.php index 2527963d4..6702a2149 100644 --- a/include/pubsubpublish.php +++ b/include/pubsubpublish.php @@ -54,7 +54,7 @@ function handle_pubsubhubbub($id) { $headers = array("Content-type: application/atom+xml", sprintf("Link: <%s>;rel=hub,<%s>;rel=self", - App::get_baseurl().'/pubsubhubbub', + App::get_baseurl().'/pubsubhubbub/'.$rr['nickname'], $rr['topic']), "X-Hub-Signature: sha1=".$hmac_sig); diff --git a/mod/pubsubhubbub.php b/mod/pubsubhubbub.php index da2f94748..477d1e296 100644 --- a/mod/pubsubhubbub.php +++ b/mod/pubsubhubbub.php @@ -16,14 +16,14 @@ function pubsubhubbub_init(App $a) { // Subscription request from subscriber // https://pubsubhubbub.googlecode.com/git/pubsubhubbub-core-0.4.html#anchor4 // Example from GNU Social: - // [hub_mode] => subscribe - // [hub_callback] => http://status.local/main/push/callback/1 - // [hub_verify] => sync - // [hub_verify_token] => af11... - // [hub_secret] => af11... - // [hub_topic] => http://friendica.local/dfrn_poll/sazius + // [hub_mode] => subscribe + // [hub_callback] => http://status.local/main/push/callback/1 + // [hub_verify] => sync + // [hub_verify_token] => af11... + // [hub_secret] => af11... + // [hub_topic] => http://friendica.local/dfrn_poll/sazius - if($_SERVER['REQUEST_METHOD'] === 'POST') { + if ($_SERVER['REQUEST_METHOD'] === 'POST') { $hub_mode = post_var('hub_mode'); $hub_callback = post_var('hub_callback'); $hub_verify = post_var('hub_verify'); @@ -34,7 +34,7 @@ function pubsubhubbub_init(App $a) { // check for valid hub_mode if ($hub_mode === 'subscribe') { $subscribe = 1; - } else if ($hub_mode === 'unsubscribe') { + } elseif ($hub_mode === 'unsubscribe') { $subscribe = 0; } else { logger("pubsubhubbub: invalid hub_mode=$hub_mode, ignoring."); @@ -44,9 +44,14 @@ function pubsubhubbub_init(App $a) { logger("pubsubhubbub: $hub_mode request from " . $_SERVER['REMOTE_ADDR']); - // get the nick name from the topic, a bit hacky but needed + // get the nick name from the topic, a bit hacky but needed as a fallback $nick = substr(strrchr($hub_topic, "/"), 1); + // Normally the url should now contain the nick name as last part of the url + if ($a->argc > 1) { + $nick = $a->argv[1]; + } + if (!$nick) { logger('pubsubhubbub: bad hub_topic=$hub_topic, ignoring.'); http_status_exit(404); @@ -83,7 +88,7 @@ function pubsubhubbub_init(App $a) { $contact = $r[0]; // sanity check that topic URLs are the same - if(!link_compare($hub_topic, $contact['poll'])) { + if (!link_compare($hub_topic, $contact['poll'])) { logger('pubsubhubbub: hub topic ' . $hub_topic . ' != ' . $contact['poll']); http_status_exit(404); From 2293757a36270db102a4d7ee34e2678b049a8686 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 23 Aug 2017 20:33:32 +0000 Subject: [PATCH 3/4] Just some empty lines --- mod/pubsub.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/mod/pubsub.php b/mod/pubsub.php index ba5e05b0e..60df449b5 100644 --- a/mod/pubsub.php +++ b/mod/pubsub.php @@ -160,6 +160,3 @@ function pubsub_post(App $a) { hub_post_return(); } - - - From 6998897a34e67d125466bbd7e3b51d810fa959be Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 23 Aug 2017 23:01:37 +0000 Subject: [PATCH 4/4] Limit the number of feed entries (Can solve resub problems) --- include/ostatus.php | 7 ++++--- mod/dfrn_poll.php | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index 892d24993..0f7ecd11d 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -2227,10 +2227,11 @@ class ostatus { * @param App $a The application class * @param string $owner_nick Nickname of the feed owner * @param string $last_update Date of the last update + * @param integer $max_items Number of maximum items to fetch * * @return string XML feed */ - public static function feed(App $a, $owner_nick, &$last_update) { + public static function feed(App $a, $owner_nick, &$last_update, $max_items = 300) { $stamp = microtime(true); $cachekey = "ostatus:feed:".$owner_nick.":".$last_update; @@ -2267,10 +2268,10 @@ class ostatus { `item`.`author-id` = %d AND `item`.`created` > '%s' AND NOT `item`.`deleted` AND NOT `item`.`private` AND `thread`.`network` IN ('%s', '%s') - ORDER BY `item`.`created` DESC LIMIT 300", + ORDER BY `item`.`created` DESC LIMIT %d", intval($owner["uid"]), intval($owner["id"]), intval($authorid), dbesc($check_date), - dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); + dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN), intval($max_items)); $doc = new DOMDocument('1.0', 'utf-8'); $doc->formatOutput = true; diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index f02539b00..e6196accc 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -22,7 +22,7 @@ function dfrn_poll_init(App $a) { if (($a->argc > 1) && ($dfrn_id == '') && !strstr($_SERVER["HTTP_USER_AGENT"], 'Friendica')) { $nickname = $a->argv[1]; header("Content-type: application/atom+xml"); - echo ostatus::feed($a, $nickname, $last_update); + echo ostatus::feed($a, $nickname, $last_update, 10); killme(); }