]> git.mxchange.org Git - friendica.git/blob - mod/p.php
Merge pull request #2132 from rabuzarus/0112_vier_css
[friendica.git] / mod / p.php
1 <?php
2 /*
3 This file is part of the Diaspora protocol. It is used for fetching single public posts.
4 */
5 require_once("include/diaspora.php");
6
7 function p_init($a){
8         if ($a->argc != 2) {
9                 header($_SERVER["SERVER_PROTOCOL"].' 510 '.t('Not Extended'));
10                 killme();
11         }
12
13         $guid = $a->argv[1];
14
15         if (strtolower(substr($guid, -4)) != ".xml") {
16                 header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found'));
17                 killme();
18         }
19
20         $guid = strtolower(substr($guid, 0, -4));
21
22         $item = q("SELECT `title`, `body`, `guid`, `contact-id`, `private`, `created`, `app` FROM `item` WHERE `uid` = 0 AND `guid` = '%s' AND `network` IN ('%s', '%s') LIMIT 1",
23                 dbesc($guid), NETWORK_DFRN, NETWORK_DIASPORA);
24         if (!$item) {
25                 header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found'));
26                 killme();
27         }
28
29         $post = array();
30
31         $reshared = diaspora_is_reshare($item[0]["body"]);
32
33         if ($reshared) {
34                 $nodename = "reshare";
35                 $post["root_diaspora_id"] = $reshared["root_handle"];
36                 $post["root_guid"] = $reshared["root_guid"];
37                 $post["guid"] = $item[0]["guid"];
38                 $post["diaspora_handle"] = diaspora_handle_from_contact($item[0]["contact-id"]);
39                 $post["public"] = (!$item[0]["private"] ? 'true':'false');
40                 $post["created_at"] = datetime_convert('UTC','UTC',$item[0]["created"]);
41         } else {
42
43                 $body = bb2diaspora($item[0]["body"]);
44
45                 if(strlen($item[0]["title"]))
46                         $body = "## ".html_entity_decode($item[0]["title"])."\n\n".$body;
47
48                 $nodename = "status_message";
49                 $post["raw_message"] = str_replace("&", "&amp;", $body);
50                 $post["guid"] = $item[0]["guid"];
51                 $post["diaspora_handle"] = diaspora_handle_from_contact($item[0]["contact-id"]);
52                 $post["public"] = (!$item[0]["private"] ? 'true':'false');
53                 $post["created_at"] = datetime_convert('UTC','UTC',$item[0]["created"]);
54                 $post["provider_display_name"] = $item[0]["app"];
55         }
56
57         $dom = new DOMDocument("1.0");
58         $root = $dom->createElement("XML");
59         $dom->appendChild($root);
60         $postelement = $dom->createElement("post");
61         $root->appendChild($postelement);
62         $statuselement = $dom->createElement($nodename);
63         $postelement->appendChild($statuselement);
64
65         foreach($post AS $index => $value) {
66                 $postnode = $dom->createElement($index, $value);
67                 $statuselement->appendChild($postnode);
68         }
69
70         header("Content-Type: application/xml; charset=utf-8");
71         $xml = $dom->saveXML();
72
73         // Diaspora doesn't send the XML header, so we remove them as well.
74         // So we avoid possible compatibility problems.
75         if (substr($xml, 0, 21) == '<?xml version="1.0"?>')
76                 $xml = trim(substr($xml, 21));
77
78         echo $xml;
79
80         killme();
81 }