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\Model\Contact;
13 use Friendica\Model\GContact;
14 use Friendica\Model\Profile;
16 function hovercard_init(App $a)
18 // Just for testing purposes
19 $_GET['mode'] = 'minimal';
22 function hovercard_content()
24 $profileurl = defaults($_REQUEST, 'profileurl', '');
25 $datatype = defaults($_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);
32 // Return the raw content of the template. We use this to make templates usable for js functions.
33 // Look at hovercard.js (function getHoverCardTemplate()).
34 // This part should be moved in its own module. Maybe we could make more templates accessible.
35 // (We need to discuss possible security leaks before doing this)
36 if ($datatype == 'tpl') {
37 $templatecontent = get_template_content('hovercard.tpl');
38 echo $templatecontent;
42 // If a contact is connected the url is internally changed to 'redir/CID'. We need the pure url to search for
43 // the contact. So we strip out the contact id from the internal url and look in the contact table for
44 // the real url (nurl)
46 if (local_user() && strpos($profileurl, 'redir/') === 0) {
47 $cid = intval(substr($profileurl, 6));
48 $remote_contact = dba::selectFirst('contact', ['nurl'], ['id' => $cid]);
49 $profileurl = defaults($remote_contact, 'nurl', '');
53 // if it's the url containing https it should be converted to http
54 $nurl = normalise_link(GContact::cleanContactUrl($profileurl));
56 // Search for contact data
57 $contact = Contact::getDetailsByURL($nurl);
59 if (!count($contact)) {
63 // Get the photo_menu - the menu if possible contact actions
65 $actions = Contact::photoMenu($contact);
68 // Move the contact data to the profile array so we can deliver it to
70 'name' => $contact['name'],
71 'nick' => $contact['nick'],
72 'addr' => defaults($contact, 'addr', $contact['url']),
73 'thumb' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB),
74 'url' => $cid ? ('redir/' . $cid) : Profile::zrl($contact['url']),
75 'nurl' => $contact['nurl'], // We additionally store the nurl as identifier
76 'location' => $contact['location'],
77 'gender' => $contact['gender'],
78 'about' => $contact['about'],
79 'network' => format_network_name($contact['network'], $contact['url']),
80 'tags' => $contact['keywords'],
81 'bd' => $contact['birthday'] <= '0001-01-01' ? '' : $contact['birthday'],
82 'account_type' => Contact::getAccountType($contact),
83 'actions' => $actions,
85 if ($datatype == 'html') {
86 $tpl = get_markup_template('hovercard.tpl');
87 $o = replace_macros($tpl, [
88 '$profile' => $profile,
93 json_return_and_die($profile);
98 * @brief Get the raw content of a template file
100 * @param string $template The name of the template
101 * @param string $root Directory of the template
103 * @return string|bool Output the raw content if existent, otherwise false
105 function get_template_content($template, $root = '')
107 // We load the whole template system to get the filename.
108 // Maybe we can do it a little bit smarter if I get time.
109 $t = get_markup_template($template, $root);
110 $filename = $t->filename;
112 // Get the content of the template file
113 if (file_exists($filename)) {
114 $content = file_get_contents($filename);