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.

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