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