]> git.mxchange.org Git - friendica.git/blob - mod/hovercard.php
Improve Console/Config display for array values
[friendica.git] / mod / hovercard.php
1 <?php
2
3 /**
4  * Name: Frio Hovercard
5  * Description: Hovercard addon for the frio theme
6  * Version: 0.1
7  * Author: Rabuzarus <https://github.com/rabuzarus>
8  * License: GNU AFFERO GENERAL PUBLIC LICENSE (Version 3)
9  */
10 use Friendica\App;
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;
16
17 function hovercard_init(App $a)
18 {
19         // Just for testing purposes
20         $_GET['mode'] = 'minimal';
21 }
22
23 function hovercard_content()
24 {
25         $profileurl = defaults($_REQUEST, 'profileurl', '');
26         $datatype   = defaults($_REQUEST, 'datatype'  , 'json');
27
28         // Get out if the system doesn't have public access allowed
29         if (intval(Config::get('system', 'block_public'))) {
30                 System::httpExit(401);
31         }
32
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;
40                 killme();
41         }
42
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)
46         $cid = 0;
47         if (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', '');
51         }
52
53         $contact = [];
54         // if it's the url containing https it should be converted to http
55         $nurl = normalise_link(GContact::cleanContactUrl($profileurl));
56         if ($nurl) {
57                 // Search for contact data
58                 $contact = Contact::getDetailsByURL($nurl);
59         }
60         if (!count($contact)) {
61                 return;
62         }
63
64         // Get the photo_menu - the menu if possible contact actions
65         if (local_user()) {
66                 $actions = Contact::photoMenu($contact);
67         }
68
69         // Move the contact data to the profile array so we can deliver it to
70         $profile = [
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'      => Contact::magicLink($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,
85         ];
86         if ($datatype == 'html') {
87                 $tpl = get_markup_template('hovercard.tpl');
88                 $o = replace_macros($tpl, [
89                         '$profile' => $profile,
90                 ]);
91
92                 return $o;
93         } else {
94                 System::jsonExit($profile);
95         }
96 }
97
98 /**
99  * @brief Get the raw content of a template file
100  *
101  * @param string $template The name of the template
102  * @param string $root Directory of the template
103  *
104  * @return string|bool Output the raw content if existent, otherwise false
105  */
106 function get_template_content($template, $root = '')
107 {
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;
112
113         // Get the content of the template file
114         if (file_exists($filename)) {
115                 $content = file_get_contents($filename);
116
117                 return $content;
118         }
119
120         return false;
121 }