Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.0KB

  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. function p_init($a){
  7. if ($a->argc != 2) {
  8. header($_SERVER["SERVER_PROTOCOL"].' 510 '.t('Not Extended'));
  9. killme();
  10. }
  11. $guid = $a->argv[1];
  12. if (strtolower(substr($guid, -4)) != ".xml") {
  13. header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found'));
  14. killme();
  15. }
  16. $guid = strtolower(substr($guid, 0, -4));
  17. // Fetch the item
  18. $item = q("SELECT `uid`, `title`, `body`, `guid`, `contact-id`, `private`, `created`, `app`, `location`, `coord`
  19. FROM `item` WHERE `wall` AND NOT `private` AND `guid` = '%s' AND `network` IN ('%s', '%s') AND `id` = `parent` LIMIT 1",
  20. dbesc($guid), NETWORK_DFRN, NETWORK_DIASPORA);
  21. if (!$item) {
  22. $r = q("SELECT `author-link`
  23. FROM `item` WHERE `uid` = 0 AND `guid` = '%s' AND `network` IN ('%s', '%s') AND `id` = `parent` LIMIT 1",
  24. dbesc($guid), NETWORK_DFRN, NETWORK_DIASPORA);
  25. if ($r) {
  26. $parts = parse_url($r[0]["author-link"]);
  27. $host = $parts["scheme"]."://".$parts["host"];
  28. if (normalise_link($host) != normalise_link($a->get_baseurl())) {
  29. $location = $host."/p/".urlencode($guid).".xml";
  30. header("HTTP/1.1 301 Moved Permanently");
  31. header("Location:".$location);
  32. killme();
  33. }
  34. }
  35. header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found'));
  36. killme();
  37. }
  38. // Fetch some data from the author (We could combine both queries - but I think this is more readable)
  39. $r = q("SELECT `user`.`prvkey`, `contact`.`addr`, `user`.`nickname`, `contact`.`nick` FROM `user`
  40. INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid`
  41. WHERE `user`.`uid` = %d", intval($item[0]["uid"]));
  42. if (!$r) {
  43. header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found'));
  44. killme();
  45. }
  46. $user = $r[0];
  47. $status = diaspora::build_status($item[0], $user);
  48. $xml = diaspora::build_post_xml($status["type"], $status["message"]);
  49. header("Content-Type: application/xml; charset=utf-8");
  50. echo $xml;
  51. killme();
  52. }