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