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 use Friendica\Core\Config;
12 use Friendica\Core\System;
13 use Friendica\Model\Contact;
14 use Friendica\Model\GContact;
15 use Friendica\Model\Profile;
17 function hovercard_init(App $a)
19 // Just for testing purposes
20 $_GET['mode'] = 'minimal';
23 function hovercard_content()
25 $profileurl = defaults($_REQUEST, 'profileurl', '');
26 $datatype = defaults($_REQUEST, 'datatype' , 'json');
28 // Get out if the system doesn't have public access allowed
29 if (intval(Config::get('system', 'block_public'))) {
30 System::httpExit(401);
33 // Return the raw content of the template. We use this to make templates usable for js functions.
34 // Look at hovercard.js (function getHoverCardTemplate()).
35 // This part should be moved in its own module. Maybe we could make more templates accessible.
36 // (We need to discuss possible security leaks before doing this)
37 if ($datatype == 'tpl') {
38 $templatecontent = get_template_content('hovercard.tpl');
39 echo $templatecontent;
43 // If a contact is connected the url is internally changed to 'redir/CID'. We need the pure url to search for
44 // the contact. So we strip out the contact id from the internal url and look in the contact table for
45 // the real url (nurl)
47 if (local_user() && strpos($profileurl, 'redir/') === 0) {
48 $cid = intval(substr($profileurl, 6));
49 $remote_contact = dba::selectFirst('contact', ['nurl'], ['id' => $cid]);
50 $profileurl = defaults($remote_contact, 'nurl', '');
54 // if it's the url containing https it should be converted to http
55 $nurl = normalise_link(GContact::cleanContactUrl($profileurl));
57 // Search for contact data
58 $contact = Contact::getDetailsByURL($nurl);
60 if (!count($contact)) {
64 // Get the photo_menu - the menu if possible contact actions
66 $actions = Contact::photoMenu($contact);
69 // Move the contact data to the profile array so we can deliver it to
71 'name' => $contact['name'],
72 'nick' => $contact['nick'],
73 'addr' => defaults($contact, 'addr', $contact['url']),
74 'thumb' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB),
75 'url' => $cid ? ('redir/' . $cid) : Profile::zrl($contact['url']),
76 'nurl' => $contact['nurl'], // We additionally store the nurl as identifier
77 'location' => $contact['location'],
78 'gender' => $contact['gender'],
79 'about' => $contact['about'],
80 'network' => format_network_name($contact['network'], $contact['url']),
81 'tags' => $contact['keywords'],
82 'bd' => $contact['birthday'] <= '0001-01-01' ? '' : $contact['birthday'],
83 'account_type' => Contact::getAccountType($contact),
84 'actions' => $actions,
86 if ($datatype == 'html') {
87 $tpl = get_markup_template('hovercard.tpl');
88 $o = replace_macros($tpl, [
89 '$profile' => $profile,
94 System::jsonExit($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);