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\Contact;
14 use Friendica\Model\GContact;
16 function hovercard_init(App $a) {
17 // Just for testing purposes
18 $_GET["mode"] = "minimal";
21 function hovercard_content() {
22 $profileurl = (x($_REQUEST,'profileurl') ? $_REQUEST['profileurl'] : "");
23 $datatype = (x($_REQUEST,'datatype') ?$_REQUEST['datatype'] : "json");
25 // Get out if the system doesn't have public access allowed
26 if(intval(Config::get('system','block_public')))
27 http_status_exit(401);
29 // Return the raw content of the template. We use this to make templates usable for js functions.
30 // Look at hovercard.js (function getHoverCardTemplate()).
31 // This part should be moved in it's own module. Maybe we could make more templates accessabel.
32 // (We need to discuss possible security lacks before doing this)
33 if ($datatype == "tpl") {
34 $templatecontent = get_template_content("hovercard.tpl");
35 echo $templatecontent;
39 // If a contact is connected the url is internally changed to "redir/CID". We need the pure url to search for
40 // the contact. So we strip out the contact id from the internal url and look in the contact table for
41 // the real url (nurl)
42 if (local_user() && strpos($profileurl, "redir/") === 0) {
43 $cid = intval(substr($profileurl, 6));
44 $r = dba::select('contact', array('nurl', 'self'), array('id' => $cid), array('limit' => 1));
45 $profileurl = ($r["nurl"] ? $r["nurl"] : "");
46 $self = ($r["self"] ? $r["self"] : "");
49 // if it's the url containing https it should be converted to http
50 $nurl = normalise_link(GContact::cleanContactUrl($profileurl));
52 // Search for contact data
53 $contact = Contact::getDetailsByURL($nurl);
55 if(!is_array($contact))
58 // Get the photo_menu - the menu if possible contact actions
60 $actions = Contact::photoMenu($contact);
63 // Move the contact data to the profile array so we can deliver it to
66 'name' => $contact["name"],
67 'nick' => $contact["nick"],
68 'addr' => (($contact["addr"] != "") ? $contact["addr"] : $contact["url"]),
69 'thumb' => proxy_url($contact["thumb"], false, PROXY_SIZE_THUMB),
70 'url' => ($cid ? ("redir/".$cid) : zrl($contact["url"])),
71 'nurl' => $contact["nurl"], // We additionally store the nurl as identifier
72 // 'alias' => $contact["alias"],
73 'location' => $contact["location"],
74 'gender' => $contact["gender"],
75 'about' => $contact["about"],
76 'network' => format_network_name($contact["network"], $contact["url"]),
77 'tags' => $contact["keywords"],
78 // 'nsfw' => intval($contact["nsfw"]),
79 // 'server_url' => $contact["server_url"],
80 'bd' => (($contact["birthday"] <= '0001-01-01') ? "" : $contact["birthday"]),
81 // 'generation' => $contact["generation"],
82 'account_type' => Contact::getAccountType($contact),
83 'actions' => $actions,
85 if($datatype == "html") {
86 $t = get_markup_template("hovercard.tpl");
88 $o = replace_macros($t, array(
89 '$profile' => $profile,
95 json_return_and_die($profile);
100 * @brief Get the raw content of a template file
102 * @param string $template The name of the template
103 * @param string $root Directory of the template
105 * @return string|bool Output the raw content if existent, otherwise false
107 function get_template_content($template, $root = "") {
109 // We load the whole template system to get the filename.
110 // Maybe we can do it a little bit smarter if I get time.
111 $t = get_markup_template($template, $root);
112 $filename = $t->filename;
114 // Get the content of the template file
115 if(file_exists($filename)) {
116 $content = file_get_contents($filename);