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