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;
15 function hovercard_init(App $a)
17 // Just for testing purposes
18 $_GET['mode'] = 'minimal';
21 function hovercard_content()
23 $profileurl = defaults($_REQUEST, 'profileurl', '');
24 $datatype = defaults($_REQUEST, 'datatype' , 'json');
26 // Get out if the system doesn't have public access allowed
27 if (intval(Config::get('system', 'block_public'))) {
28 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 its own module. Maybe we could make more templates accessible.
34 // (We need to discuss possible security leaks 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)
45 if (local_user() && strpos($profileurl, 'redir/') === 0) {
46 $cid = intval(substr($profileurl, 6));
47 $r = dba::select('contact', array('nurl'), array('id' => $cid), array('limit' => 1));
48 $profileurl = defaults($r, 'nurl', '');
52 // if it's the url containing https it should be converted to http
53 $nurl = normalise_link(GContact::cleanContactUrl($profileurl));
55 // Search for contact data
56 $contact = Contact::getDetailsByURL($nurl);
58 if (!count($contact)) {
62 // Get the photo_menu - the menu if possible contact actions
64 $actions = Contact::photoMenu($contact);
67 // Move the contact data to the profile array so we can deliver it to
69 'name' => $contact['name'],
70 'nick' => $contact['nick'],
71 'addr' => defaults($contact, 'addr', $contact['url']),
72 'thumb' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB),
73 'url' => $cid ? ('redir/' . $cid) : zrl($contact['url']),
74 'nurl' => $contact['nurl'], // We additionally store the nurl as identifier
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 'bd' => $contact['birthday'] <= '0001-01-01' ? '' : $contact['birthday'],
81 'account_type' => Contact::getAccountType($contact),
82 'actions' => $actions,
84 if ($datatype == 'html') {
85 $tpl = get_markup_template('hovercard.tpl');
86 $o = replace_macros($tpl, array(
87 '$profile' => $profile,
92 json_return_and_die($profile);
97 * @brief Get the raw content of a template file
99 * @param string $template The name of the template
100 * @param string $root Directory of the template
102 * @return string|bool Output the raw content if existent, otherwise false
104 function get_template_content($template, $root = '')
106 // We load the whole template system to get the filename.
107 // Maybe we can do it a little bit smarter if I get time.
108 $t = get_markup_template($template, $root);
109 $filename = $t->filename;
111 // Get the content of the template file
112 if (file_exists($filename)) {
113 $content = file_get_contents($filename);