]> git.mxchange.org Git - friendica.git/blob - mod/hovercard.php
Merge pull request #3906 from zeroadam/Global-Poco-#3878
[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
11 use Friendica\App;
12 use Friendica\Core\Config;
13 use Friendica\Model\GlobalContact;
14
15 require_once "include/Contact.php";
16
17 function hovercard_init(App $a) {
18         // Just for testing purposes
19         $_GET["mode"] = "minimal";
20 }
21
22 function hovercard_content() {
23         $profileurl     =       (x($_REQUEST,'profileurl')      ? $_REQUEST['profileurl']       : "");
24         $datatype       =       (x($_REQUEST,'datatype')        ?$_REQUEST['datatype']          : "json");
25
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);
29
30         // Return the raw content of the template. We use this to make templates usable for js functions.
31         // Look at hovercard.js (function getHoverCardTemplate()).
32         // This part should be moved in it's own module. Maybe we could make more templates accessabel.
33         // (We need to discuss possible security lacks before doing this)
34         if ($datatype == "tpl") {
35                 $templatecontent = get_template_content("hovercard.tpl");
36                 echo $templatecontent;
37                 killme();
38         }
39
40         // If a contact is connected the url is internally changed to "redir/CID". We need the pure url to search for
41         // the contact. So we strip out the contact id from the internal url and look in the contact table for
42         // the real url (nurl)
43         if (local_user() && strpos($profileurl, "redir/") === 0) {
44                 $cid = intval(substr($profileurl, 6));
45                 $r = dba::select('contact', array('nurl', 'self'), array('id' => $cid), array('limit' => 1));
46                 $profileurl = ($r["nurl"] ? $r["nurl"] : "");
47                 $self = ($r["self"] ? $r["self"] : "");
48         }
49
50         // if it's the url containing https it should be converted to http
51         $nurl = normalise_link(GlobalContact::cleanContactUrl($profileurl));
52         if($nurl) {
53                 // Search for contact data
54                 $contact = get_contact_details_by_url($nurl);
55         }
56         if(!is_array($contact))
57                 return;
58
59         // Get the photo_menu - the menu if possible contact actions
60         if(local_user())
61                 $actions = contact_photo_menu($contact);
62
63
64         // Move the contact data to the profile array so we can deliver it to
65         //
66         $profile = array(
67                 'name' => $contact["name"],
68                 'nick'  => $contact["nick"],
69                 'addr'  => (($contact["addr"] != "") ? $contact["addr"] : $contact["url"]),
70                 'thumb' => proxy_url($contact["thumb"], false, PROXY_SIZE_THUMB),
71                 'url' => ($cid ? ("redir/".$cid) : zrl($contact["url"])),
72                 'nurl' => $contact["nurl"], // We additionally store the nurl as identifier
73 //              'alias' => $contact["alias"],
74                 'location' => $contact["location"],
75                 'gender' => $contact["gender"],
76                 'about' => $contact["about"],
77                 'network' => format_network_name($contact["network"], $contact["url"]),
78                 'tags' => $contact["keywords"],
79 //              'nsfw' => intval($contact["nsfw"]),
80 //              'server_url' => $contact["server_url"],
81                 'bd' => (($contact["birthday"] <= '0001-01-01') ? "" : $contact["birthday"]),
82 //              'generation' => $contact["generation"],
83                 'account_type' => account_type($contact),
84                 'actions' => $actions,
85         );
86         if($datatype == "html") {
87                 $t = get_markup_template("hovercard.tpl");
88
89                 $o = replace_macros($t, array(
90                         '$profile' => $profile,
91                 ));
92
93                 return $o;
94
95         } else {
96                 json_return_and_die($profile);
97         }
98 }
99
100 /**
101  * @brief Get the raw content of a template file
102  *
103  * @param string $template The name of the template
104  * @param string $root Directory of the template
105  *
106  * @return string|bool Output the raw content if existent, otherwise false
107  */
108 function get_template_content($template, $root = "") {
109
110         // We load the whole template system to get the filename.
111         // Maybe we can do it a little bit smarter if I get time.
112         $t = get_markup_template($template, $root);
113         $filename = $t->filename;
114
115         // Get the content of the template file
116         if(file_exists($filename)) {
117                 $content = file_get_contents($filename);
118
119                 return $content;
120         }
121
122         return false;
123 }