Merge pull request #3649 from annando/pleroma2
Enhanced OStatus compatibility
This commit is contained in:
commit
32a8a28b2c
|
@ -504,7 +504,7 @@ class dfrn {
|
||||||
|
|
||||||
if ($public) {
|
if ($public) {
|
||||||
// DFRN itself doesn't uses this. But maybe someone else wants to subscribe to the public feed.
|
// 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"]);
|
$attributes = array("rel" => "salmon", "href" => App::get_baseurl()."/salmon/".$owner["nick"]);
|
||||||
xml::add_element($doc, $root, "link", "", $attributes);
|
xml::add_element($doc, $root, "link", "", $attributes);
|
||||||
|
|
|
@ -1470,7 +1470,7 @@ class ostatus {
|
||||||
/// "type" => "application/json");
|
/// "type" => "application/json");
|
||||||
/// xml::add_element($doc, $root, "link", "", $attributes);
|
/// 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");
|
$attributes = array("href" => App::get_baseurl()."/salmon/".$owner["nick"], "rel" => "salmon");
|
||||||
xml::add_element($doc, $root, "link", "", $attributes);
|
xml::add_element($doc, $root, "link", "", $attributes);
|
||||||
|
@ -1494,7 +1494,7 @@ class ostatus {
|
||||||
* @param object $doc XML document
|
* @param object $doc XML document
|
||||||
* @param object $root XML root element where the hub links are added
|
* @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');
|
$hub = get_config('system','huburl');
|
||||||
|
|
||||||
$hubxml = '';
|
$hubxml = '';
|
||||||
|
@ -1505,8 +1505,9 @@ class ostatus {
|
||||||
$h = trim($h);
|
$h = trim($h);
|
||||||
if (! strlen($h))
|
if (! strlen($h))
|
||||||
continue;
|
continue;
|
||||||
if ($h === '[internal]')
|
if ($h === '[internal]') {
|
||||||
$h = App::get_baseurl() . '/pubsubhubbub';
|
$h = App::get_baseurl() . '/pubsubhubbub/'.$nick;
|
||||||
|
}
|
||||||
xml::add_element($doc, $root, "link", "", array("href" => $h, "rel" => "hub"));
|
xml::add_element($doc, $root, "link", "", array("href" => $h, "rel" => "hub"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2226,10 +2227,11 @@ class ostatus {
|
||||||
* @param App $a The application class
|
* @param App $a The application class
|
||||||
* @param string $owner_nick Nickname of the feed owner
|
* @param string $owner_nick Nickname of the feed owner
|
||||||
* @param string $last_update Date of the last update
|
* @param string $last_update Date of the last update
|
||||||
|
* @param integer $max_items Number of maximum items to fetch
|
||||||
*
|
*
|
||||||
* @return string XML feed
|
* @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);
|
$stamp = microtime(true);
|
||||||
|
|
||||||
$cachekey = "ostatus:feed:".$owner_nick.":".$last_update;
|
$cachekey = "ostatus:feed:".$owner_nick.":".$last_update;
|
||||||
|
@ -2266,10 +2268,10 @@ class ostatus {
|
||||||
`item`.`author-id` = %d AND `item`.`created` > '%s' AND
|
`item`.`author-id` = %d AND `item`.`created` > '%s' AND
|
||||||
NOT `item`.`deleted` AND NOT `item`.`private` AND
|
NOT `item`.`deleted` AND NOT `item`.`private` AND
|
||||||
`thread`.`network` IN ('%s', '%s')
|
`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($owner["uid"]), intval($owner["id"]),
|
||||||
intval($authorid), dbesc($check_date),
|
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 = new DOMDocument('1.0', 'utf-8');
|
||||||
$doc->formatOutput = true;
|
$doc->formatOutput = true;
|
||||||
|
|
|
@ -54,7 +54,7 @@ function handle_pubsubhubbub($id) {
|
||||||
|
|
||||||
$headers = array("Content-type: application/atom+xml",
|
$headers = array("Content-type: application/atom+xml",
|
||||||
sprintf("Link: <%s>;rel=hub,<%s>;rel=self",
|
sprintf("Link: <%s>;rel=hub,<%s>;rel=self",
|
||||||
App::get_baseurl().'/pubsubhubbub',
|
App::get_baseurl().'/pubsubhubbub/'.$rr['nickname'],
|
||||||
$rr['topic']),
|
$rr['topic']),
|
||||||
"X-Hub-Signature: sha1=".$hmac_sig);
|
"X-Hub-Signature: sha1=".$hmac_sig);
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ use Friendica\Core\Config;
|
||||||
|
|
||||||
require_once("mod/hostxrd.php");
|
require_once("mod/hostxrd.php");
|
||||||
require_once("mod/nodeinfo.php");
|
require_once("mod/nodeinfo.php");
|
||||||
|
require_once("mod/xrd.php");
|
||||||
|
|
||||||
function _well_known_init(App $a) {
|
function _well_known_init(App $a) {
|
||||||
if ($a->argc > 1) {
|
if ($a->argc > 1) {
|
||||||
|
@ -18,6 +19,9 @@ function _well_known_init(App $a) {
|
||||||
case "nodeinfo":
|
case "nodeinfo":
|
||||||
nodeinfo_wellknown($a);
|
nodeinfo_wellknown($a);
|
||||||
break;
|
break;
|
||||||
|
case "webfinger":
|
||||||
|
xrd_init($a);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
http_status_exit(404);
|
http_status_exit(404);
|
||||||
|
|
|
@ -5,6 +5,7 @@ use Friendica\App;
|
||||||
require_once('include/items.php');
|
require_once('include/items.php');
|
||||||
require_once('include/auth.php');
|
require_once('include/auth.php');
|
||||||
require_once('include/dfrn.php');
|
require_once('include/dfrn.php');
|
||||||
|
require_once('include/ostatus.php');
|
||||||
|
|
||||||
function dfrn_poll_init(App $a) {
|
function dfrn_poll_init(App $a) {
|
||||||
$dfrn_id = ((x($_GET,'dfrn_id')) ? $_GET['dfrn_id'] : '');
|
$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');
|
$perm = ((x($_GET,'perm')) ? $_GET['perm'] : 'r');
|
||||||
$quiet = ((x($_GET,'quiet')) ? true : false);
|
$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, 10);
|
||||||
|
killme();
|
||||||
|
}
|
||||||
|
|
||||||
$direction = (-1);
|
$direction = (-1);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -160,6 +160,3 @@ function pubsub_post(App $a) {
|
||||||
hub_post_return();
|
hub_post_return();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,14 +16,14 @@ function pubsubhubbub_init(App $a) {
|
||||||
// Subscription request from subscriber
|
// Subscription request from subscriber
|
||||||
// https://pubsubhubbub.googlecode.com/git/pubsubhubbub-core-0.4.html#anchor4
|
// https://pubsubhubbub.googlecode.com/git/pubsubhubbub-core-0.4.html#anchor4
|
||||||
// Example from GNU Social:
|
// Example from GNU Social:
|
||||||
// [hub_mode] => subscribe
|
// [hub_mode] => subscribe
|
||||||
// [hub_callback] => http://status.local/main/push/callback/1
|
// [hub_callback] => http://status.local/main/push/callback/1
|
||||||
// [hub_verify] => sync
|
// [hub_verify] => sync
|
||||||
// [hub_verify_token] => af11...
|
// [hub_verify_token] => af11...
|
||||||
// [hub_secret] => af11...
|
// [hub_secret] => af11...
|
||||||
// [hub_topic] => http://friendica.local/dfrn_poll/sazius
|
// [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_mode = post_var('hub_mode');
|
||||||
$hub_callback = post_var('hub_callback');
|
$hub_callback = post_var('hub_callback');
|
||||||
$hub_verify = post_var('hub_verify');
|
$hub_verify = post_var('hub_verify');
|
||||||
|
@ -34,7 +34,7 @@ function pubsubhubbub_init(App $a) {
|
||||||
// check for valid hub_mode
|
// check for valid hub_mode
|
||||||
if ($hub_mode === 'subscribe') {
|
if ($hub_mode === 'subscribe') {
|
||||||
$subscribe = 1;
|
$subscribe = 1;
|
||||||
} else if ($hub_mode === 'unsubscribe') {
|
} elseif ($hub_mode === 'unsubscribe') {
|
||||||
$subscribe = 0;
|
$subscribe = 0;
|
||||||
} else {
|
} else {
|
||||||
logger("pubsubhubbub: invalid hub_mode=$hub_mode, ignoring.");
|
logger("pubsubhubbub: invalid hub_mode=$hub_mode, ignoring.");
|
||||||
|
@ -44,9 +44,14 @@ function pubsubhubbub_init(App $a) {
|
||||||
logger("pubsubhubbub: $hub_mode request from " .
|
logger("pubsubhubbub: $hub_mode request from " .
|
||||||
$_SERVER['REMOTE_ADDR']);
|
$_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);
|
$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) {
|
if (!$nick) {
|
||||||
logger('pubsubhubbub: bad hub_topic=$hub_topic, ignoring.');
|
logger('pubsubhubbub: bad hub_topic=$hub_topic, ignoring.');
|
||||||
http_status_exit(404);
|
http_status_exit(404);
|
||||||
|
@ -83,7 +88,7 @@ function pubsubhubbub_init(App $a) {
|
||||||
$contact = $r[0];
|
$contact = $r[0];
|
||||||
|
|
||||||
// sanity check that topic URLs are the same
|
// 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 . ' != ' .
|
logger('pubsubhubbub: hub topic ' . $hub_topic . ' != ' .
|
||||||
$contact['poll']);
|
$contact['poll']);
|
||||||
http_status_exit(404);
|
http_status_exit(404);
|
||||||
|
|
|
@ -8,6 +8,10 @@ function xrd_init(App $a) {
|
||||||
|
|
||||||
$uri = urldecode(notags(trim($_GET['uri'])));
|
$uri = urldecode(notags(trim($_GET['uri'])));
|
||||||
|
|
||||||
|
if ($uri == "") {
|
||||||
|
$uri = urldecode(notags(trim($_GET['resource'])));
|
||||||
|
}
|
||||||
|
|
||||||
if(substr($uri,0,4) === 'http') {
|
if(substr($uri,0,4) === 'http') {
|
||||||
$acct = false;
|
$acct = false;
|
||||||
$name = basename($uri);
|
$name = basename($uri);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user