Diaspora: Support for new fetch functionality (replacement for /p/)
This commit is contained in:
parent
3a5d98507d
commit
2d72e2d932
|
@ -2287,10 +2287,10 @@ class diaspora {
|
||||||
$sig = base64url_encode($signature);
|
$sig = base64url_encode($signature);
|
||||||
|
|
||||||
$xmldata = array("diaspora" => array("header" => array("author_id" => $handle),
|
$xmldata = array("diaspora" => array("header" => array("author_id" => $handle),
|
||||||
"me:env" => array("me:encoding" => "base64url",
|
"me:env" => array("me:encoding" => $encoding,
|
||||||
"me:alg" => "RSA-SHA256",
|
"me:alg" => $alg,
|
||||||
"me:data" => $data,
|
"me:data" => $data,
|
||||||
"@attributes" => array("type" => "application/xml"),
|
"@attributes" => array("type" => $type),
|
||||||
"me:sig" => $sig)));
|
"me:sig" => $sig)));
|
||||||
|
|
||||||
$namespaces = array("" => "https://joindiaspora.com/protocol",
|
$namespaces = array("" => "https://joindiaspora.com/protocol",
|
||||||
|
@ -2377,10 +2377,10 @@ class diaspora {
|
||||||
$cipher_json = base64_encode($encrypted_header_json_object);
|
$cipher_json = base64_encode($encrypted_header_json_object);
|
||||||
|
|
||||||
$xmldata = array("diaspora" => array("encrypted_header" => $cipher_json,
|
$xmldata = array("diaspora" => array("encrypted_header" => $cipher_json,
|
||||||
"me:env" => array("me:encoding" => "base64url",
|
"me:env" => array("me:encoding" => $encoding,
|
||||||
"me:alg" => "RSA-SHA256",
|
"me:alg" => $alg,
|
||||||
"me:data" => $data,
|
"me:data" => $data,
|
||||||
"@attributes" => array("type" => "application/xml"),
|
"@attributes" => array("type" => $type),
|
||||||
"me:sig" => $sig)));
|
"me:sig" => $sig)));
|
||||||
|
|
||||||
$namespaces = array("" => "https://joindiaspora.com/protocol",
|
$namespaces = array("" => "https://joindiaspora.com/protocol",
|
||||||
|
|
|
@ -132,17 +132,24 @@ function notifier_run(&$argv, &$argc){
|
||||||
$recipients[] = $suggest[0]['cid'];
|
$recipients[] = $suggest[0]['cid'];
|
||||||
$item = $suggest[0];
|
$item = $suggest[0];
|
||||||
} elseif($cmd === 'removeme') {
|
} elseif($cmd === 'removeme') {
|
||||||
$r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($item_id));
|
$r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`,
|
||||||
|
`user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`,
|
||||||
|
`user`.`page-flags`, `user`.`prvnets`
|
||||||
|
FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
|
||||||
|
WHERE `contact`.`uid` = %d AND `contact`.`self` LIMIT 1",
|
||||||
|
intval($item_id));
|
||||||
if (!$r)
|
if (!$r)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$user = $r[0];
|
$user = $r[0];
|
||||||
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($item_id));
|
|
||||||
|
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($item_id));
|
||||||
if (!$r)
|
if (!$r)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$self = $r[0];
|
$self = $r[0];
|
||||||
$r = q("SELECT * FROM `contact` WHERE `self` = 0 AND `uid` = %d", intval($item_id));
|
|
||||||
|
$r = q("SELECT * FROM `contact` WHERE NOT `self` AND `uid` = %d", intval($item_id));
|
||||||
if(!$r)
|
if(!$r)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ class xml {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($array as $key => $value) {
|
foreach($array as $key => $value) {
|
||||||
if ($key == "@attributes") {
|
if (substr($key, 0, 11) == "@attributes") {
|
||||||
if (!isset($element) OR !is_array($value))
|
if (!isset($element) OR !is_array($value))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
88
mod/fetch.php
Normal file
88
mod/fetch.php
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
This file is part of the Diaspora protocol. It is used for fetching single public posts.
|
||||||
|
*/
|
||||||
|
require_once("include/diaspora.php");
|
||||||
|
|
||||||
|
function fetch_init($a){
|
||||||
|
|
||||||
|
if (($a->argc != 3) OR (!in_array($a->argv[1], array("post", "status_message", "reshare")))) {
|
||||||
|
header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found'));
|
||||||
|
killme();
|
||||||
|
}
|
||||||
|
|
||||||
|
$guid = $a->argv[2];
|
||||||
|
|
||||||
|
$item = q("SELECT `uid`, `title`, `body`, `guid`, `contact-id`, `private`, `created`, `app`, `location`
|
||||||
|
FROM `item` WHERE `wall` AND NOT `private` AND `guid` = '%s' AND `network` IN ('%s', '%s') AND `id` = `parent` LIMIT 1",
|
||||||
|
dbesc($guid), NETWORK_DFRN, NETWORK_DIASPORA);
|
||||||
|
if (!$item) {
|
||||||
|
header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found'));
|
||||||
|
killme();
|
||||||
|
}
|
||||||
|
$post = array();
|
||||||
|
|
||||||
|
$reshared = diaspora::is_reshare($item[0]["body"]);
|
||||||
|
|
||||||
|
if ($reshared) {
|
||||||
|
$nodename = "reshare";
|
||||||
|
$post["root_diaspora_id"] = $reshared["root_handle"];
|
||||||
|
$post["root_guid"] = $reshared["root_guid"];
|
||||||
|
$post["guid"] = $item[0]["guid"];
|
||||||
|
$post["diaspora_handle"] = diaspora::handle_from_contact($item[0]["contact-id"]);
|
||||||
|
$post["public"] = (!$item[0]["private"] ? 'true':'false');
|
||||||
|
$post["created_at"] = datetime_convert('UTC','UTC',$item[0]["created"]);
|
||||||
|
} else {
|
||||||
|
$body = bb2diaspora($item[0]["body"]);
|
||||||
|
|
||||||
|
if(strlen($item[0]["title"]))
|
||||||
|
$body = "## ".html_entity_decode($item[0]["title"])."\n\n".$body;
|
||||||
|
|
||||||
|
$nodename = "status_message";
|
||||||
|
$post["raw_message"] = str_replace("&", "&", $body);
|
||||||
|
$post["location"] = $item[0]["location"];
|
||||||
|
$post["guid"] = $item[0]["guid"];
|
||||||
|
$post["diaspora_handle"] = diaspora::handle_from_contact($item[0]["contact-id"]);
|
||||||
|
$post["public"] = (!$item[0]["private"] ? 'true':'false');
|
||||||
|
$post["created_at"] = datetime_convert('UTC','UTC',$item[0]["created"]);
|
||||||
|
$post["provider_display_name"] = $item[0]["app"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = array("XML" => array("post" => array($nodename => $post)));
|
||||||
|
$xml = xml::from_array($data, $xmlobj);
|
||||||
|
|
||||||
|
$r = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d", intval($item[0]["uid"]));
|
||||||
|
if (!$r) {
|
||||||
|
header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found'));
|
||||||
|
killme();
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $r[0];
|
||||||
|
|
||||||
|
$key_id = "";
|
||||||
|
|
||||||
|
$b64url_data = base64url_encode($xml);
|
||||||
|
$data = str_replace(array("\n", "\r", " ", "\t"), array("", "", "", ""), $b64url_data);
|
||||||
|
|
||||||
|
$type = "application/xml";
|
||||||
|
$encoding = "base64url";
|
||||||
|
$alg = "RSA-SHA256";
|
||||||
|
$signable_data = $data.".".base64url_encode($type).".".base64url_encode($encoding).".".base64url_encode($alg);
|
||||||
|
$signature = rsa_sign($signable_data, $user["prvkey"]);
|
||||||
|
$sig = base64url_encode($signature);
|
||||||
|
|
||||||
|
$xmldata = array("me:env" => array("me:data" => $data,
|
||||||
|
"@attributes" => array("type" => $type),
|
||||||
|
"me:encoding" => $encoding,
|
||||||
|
"me:alg" => $alg,
|
||||||
|
"me:sig" => $sig,
|
||||||
|
"@attributes2" => array("key_id" => $key_id)));
|
||||||
|
|
||||||
|
$namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env");
|
||||||
|
|
||||||
|
$envelope = xml::from_array($xmldata, $xml, false, $namespaces);
|
||||||
|
header("Content-Type: application/xml; charset=utf-8");
|
||||||
|
echo $envelope;
|
||||||
|
|
||||||
|
killme();
|
||||||
|
}
|
Loading…
Reference in a new issue