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 require_once("include/socgraph.php");
12 require_once("include/Contact.php");
14 function frio_hovercard_install() {
15 logger("installed frio-hovercard");
18 function frio_hovercard_uninstall() {
19 logger("uninstalled frio-hovercard");
21 function frio_hovercard_module() {
24 function frio_hovercard_content() {
25 $profileurl = (x($_REQUEST,'profileurl') ? $_REQUEST['profileurl'] : "");
26 $datatype = (x($_REQUEST,'datatype') ?$_REQUEST['datatype'] : "json");
28 // Get out if the system doesn't have public access allowed
29 if(intval(get_config('system','block_public')))
30 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 it's own module. Maybe we could make more templates accessabel.
35 // (We need to discuss possible security lacks before doing this)
36 if ($datatype == "tpl") {
37 $templatecontent = get_template_content("hovercard.tpl", "addon/frio_hovercard/");
38 return $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)
44 if(local_user() && strpos($profileurl, "redir/") === 0) {
45 $cid = intval(substr($profileurl, 6));
46 $r = q("SELECT `nurl`, `self` FROM `contact` WHERE `id` = '%d' LIMIT 1", intval($cid));
47 $profileurl = ($r[0]["nurl"] ? $r[0]["nurl"] : "");
48 $self = ($r[0]["self"] ? $r[0]["self"] : "");
51 // if it's the url containing https it should be converted to http
52 $nurl = normalise_link(clean_contact_url($profileurl));
54 // Search for contact data
55 $contact = get_contact_details_by_url($nurl);
57 // Get_contact_details_by_url() doesn't provide the nurl but we
58 // need it for the photo_menu, so we copy it to the contact array
59 if (!isset($contact["nurl"]))
60 $contact["nurl"] = $nurl;
63 if(!is_array($contact))
66 // Get the photo_menu - the menu if possible contact actions
67 $actions = contact_photo_menu($contact);
70 // Move the contact data to the profile array so we can deliver it to
73 'name' => $contact["name"],
74 'nick' => $contact["nick"],
75 'addr' => (($contact["addr"] != "") ? $contact["addr"] : $contact["url"]),
76 'thumb' => proxy_url($contact["photo"], false, PROXY_SIZE_THUMB),
77 'url' => ($cid ? ("redir/".$cid) : zrl($contact["url"])),
78 // 'alias' => $contact["alias"],
79 'location' => $contact["location"],
80 'gender' => $contact["gender"],
81 'about' => $contact["about"],
82 'network' => format_network_name($contact["network"]),
83 'tags' => intval($contact["keywords"]),
84 // 'nsfw' => intval($contact["nsfw"]),
85 // 'server_url' => $contact["server_url"],
86 'bd' => (($contact["birthday"] == "0000-00-00") ? "" : $contact["birthday"]),
87 // 'generation' => $contact["generation"],
88 'account_type' => ($contact['community'] ? t("Forum") : ""),
89 'actions' => $actions,
92 if($datatype == "html") {
93 $t = get_markup_template("hovercard.tpl", "addon/frio_hovercard/");
95 $o = replace_macros($t, array(
96 '$profile' => $profile,
102 json_return_and_die($profile);
107 * @brief Get the raw content of a template file
109 * @param string $template The name of the template
110 * @param string $root Directory of the template
112 * @return string|bool Output the raw content if existent, otherwise false
114 function get_template_content($template, $root = "") {
115 // We load the whole template system to get the filename.
116 // Maybe we can do it a little bit smarter if I get time.
117 $t = get_markup_template($template, $root);
118 $filename = $t->filename;
120 // Get the content of the template file
121 if(file_exists($filename)) {
122 $content = file_get_contents($filename);
131 function save_this_query() {
132 $contacts = q("SELECT * FROM `gcontact`
133 WHERE ((NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
134 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
135 (`gcontact`.`addr` = '%s' OR `gcontact`.`nurl` = '%s')
137 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
138 dbesc(escape_tags($url))