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.

122 line
3.8KB

  1. <?php
  2. /**
  3. * Name: Frio Hovercard
  4. * Description: Hovercard addon for the frio theme
  5. * Version: 0.1
  6. * Author: Rabuzarus <https://github.com/rabuzarus>
  7. * License: GNU AFFERO GENERAL PUBLIC LICENSE (Version 3)
  8. */
  9. require_once("include/socgraph.php");
  10. require_once("include/Contact.php");
  11. function hovercard_init(App $a) {
  12. // Just for testing purposes
  13. $_GET["mode"] = "minimal";
  14. }
  15. function hovercard_content() {
  16. $profileurl = (x($_REQUEST,'profileurl') ? $_REQUEST['profileurl'] : "");
  17. $datatype = (x($_REQUEST,'datatype') ?$_REQUEST['datatype'] : "json");
  18. // Get out if the system doesn't have public access allowed
  19. if(intval(get_config('system','block_public')))
  20. http_status_exit(401);
  21. // Return the raw content of the template. We use this to make templates usable for js functions.
  22. // Look at hovercard.js (function getHoverCardTemplate()).
  23. // This part should be moved in it's own module. Maybe we could make more templates accessabel.
  24. // (We need to discuss possible security lacks before doing this)
  25. if ($datatype == "tpl") {
  26. $templatecontent = get_template_content("hovercard.tpl");
  27. echo $templatecontent;
  28. killme();
  29. }
  30. // If a contact is connected the url is internally changed to "redir/CID". We need the pure url to search for
  31. // the contact. So we strip out the contact id from the internal url and look in the contact table for
  32. // the real url (nurl)
  33. if(local_user() && strpos($profileurl, "redir/") === 0) {
  34. $cid = intval(substr($profileurl, 6));
  35. $r = q("SELECT `nurl`, `self` FROM `contact` WHERE `id` = '%d' LIMIT 1", intval($cid));
  36. $profileurl = ($r[0]["nurl"] ? $r[0]["nurl"] : "");
  37. $self = ($r[0]["self"] ? $r[0]["self"] : "");
  38. }
  39. // if it's the url containing https it should be converted to http
  40. $nurl = normalise_link(clean_contact_url($profileurl));
  41. if($nurl) {
  42. // Search for contact data
  43. $contact = get_contact_details_by_url($nurl);
  44. }
  45. if(!is_array($contact))
  46. return;
  47. // Get the photo_menu - the menu if possible contact actions
  48. if(local_user())
  49. $actions = contact_photo_menu($contact);
  50. // Move the contact data to the profile array so we can deliver it to
  51. //
  52. $profile = array(
  53. 'name' => $contact["name"],
  54. 'nick' => $contact["nick"],
  55. 'addr' => (($contact["addr"] != "") ? $contact["addr"] : $contact["url"]),
  56. 'thumb' => proxy_url($contact["thumb"], false, PROXY_SIZE_THUMB),
  57. 'url' => ($cid ? ("redir/".$cid) : zrl($contact["url"])),
  58. 'nurl' => $contact["nurl"], // We additionally store the nurl as identifier
  59. // 'alias' => $contact["alias"],
  60. 'location' => $contact["location"],
  61. 'gender' => $contact["gender"],
  62. 'about' => $contact["about"],
  63. 'network' => format_network_name($contact["network"], $contact["url"]),
  64. 'tags' => $contact["keywords"],
  65. // 'nsfw' => intval($contact["nsfw"]),
  66. // 'server_url' => $contact["server_url"],
  67. 'bd' => (($contact["birthday"] <= '0001-01-01') ? "" : $contact["birthday"]),
  68. // 'generation' => $contact["generation"],
  69. 'account_type' => account_type($contact),
  70. 'actions' => $actions,
  71. );
  72. if($datatype == "html") {
  73. $t = get_markup_template("hovercard.tpl");
  74. $o = replace_macros($t, array(
  75. '$profile' => $profile,
  76. ));
  77. return $o;
  78. } else {
  79. json_return_and_die($profile);
  80. }
  81. }
  82. /**
  83. * @brief Get the raw content of a template file
  84. *
  85. * @param string $template The name of the template
  86. * @param string $root Directory of the template
  87. *
  88. * @return string|bool Output the raw content if existent, otherwise false
  89. */
  90. function get_template_content($template, $root = "") {
  91. // We load the whole template system to get the filename.
  92. // Maybe we can do it a little bit smarter if I get time.
  93. $t = get_markup_template($template, $root);
  94. $filename = $t->filename;
  95. // Get the content of the template file
  96. if(file_exists($filename)) {
  97. $content = file_get_contents($filename);
  98. return $content;
  99. }
  100. return false;
  101. }