3 This file is part of the Diaspora protocol. It is used for fetching single public posts.
5 require_once("include/diaspora.php");
7 function fetch_init($a){
9 if (($a->argc != 3) OR (!in_array($a->argv[1], array("post", "status_message", "reshare")))) {
10 header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found'));
16 $item = q("SELECT `uid`, `title`, `body`, `guid`, `contact-id`, `private`, `created`, `app`, `location`
17 FROM `item` WHERE `wall` AND NOT `private` AND `guid` = '%s' AND `network` IN ('%s', '%s') AND `id` = `parent` LIMIT 1",
18 dbesc($guid), NETWORK_DFRN, NETWORK_DIASPORA);
20 header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found'));
25 $reshared = diaspora::is_reshare($item[0]["body"]);
28 $nodename = "reshare";
29 $post["root_diaspora_id"] = $reshared["root_handle"];
30 $post["root_guid"] = $reshared["root_guid"];
31 $post["guid"] = $item[0]["guid"];
32 $post["diaspora_handle"] = diaspora::handle_from_contact($item[0]["contact-id"]);
33 $post["public"] = (!$item[0]["private"] ? 'true':'false');
34 $post["created_at"] = datetime_convert('UTC','UTC',$item[0]["created"]);
36 $body = bb2diaspora($item[0]["body"]);
38 if(strlen($item[0]["title"]))
39 $body = "## ".html_entity_decode($item[0]["title"])."\n\n".$body;
41 $nodename = "status_message";
42 $post["raw_message"] = str_replace("&", "&", $body);
43 $post["location"] = $item[0]["location"];
44 $post["guid"] = $item[0]["guid"];
45 $post["diaspora_handle"] = diaspora::handle_from_contact($item[0]["contact-id"]);
46 $post["public"] = (!$item[0]["private"] ? 'true':'false');
47 $post["created_at"] = datetime_convert('UTC','UTC',$item[0]["created"]);
48 $post["provider_display_name"] = $item[0]["app"];
51 $data = array("XML" => array("post" => array($nodename => $post)));
52 $xml = xml::from_array($data, $xmlobj);
54 $r = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d", intval($item[0]["uid"]));
56 header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found'));
64 $b64url_data = base64url_encode($xml);
65 $data = str_replace(array("\n", "\r", " ", "\t"), array("", "", "", ""), $b64url_data);
67 $type = "application/xml";
68 $encoding = "base64url";
70 $signable_data = $data.".".base64url_encode($type).".".base64url_encode($encoding).".".base64url_encode($alg);
71 $signature = rsa_sign($signable_data, $user["prvkey"]);
72 $sig = base64url_encode($signature);
74 $xmldata = array("me:env" => array("me:data" => $data,
75 "@attributes" => array("type" => $type),
76 "me:encoding" => $encoding,
79 "@attributes2" => array("key_id" => $key_id)));
81 $namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env");
83 $envelope = xml::from_array($xmldata, $xml, false, $namespaces);
84 header("Content-Type: application/xml; charset=utf-8");