2016-05-29 09:28:31 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name: Frio Hovercard
|
|
|
|
* Description: Hovercard addon for the frio theme
|
|
|
|
* Version: 0.1
|
|
|
|
* Author: Rabuzarus <https://github.com/rabuzarus>
|
|
|
|
* License: GNU AFFERO GENERAL PUBLIC LICENSE (Version 3)
|
|
|
|
*/
|
|
|
|
|
2017-04-30 00:07:00 -04:00
|
|
|
use Friendica\App;
|
2017-11-06 21:22:52 -05:00
|
|
|
use Friendica\Core\Config;
|
2017-12-07 09:04:24 -05:00
|
|
|
use Friendica\Model\Contact;
|
2017-11-15 09:47:28 -05:00
|
|
|
use Friendica\Model\GlobalContact;
|
2016-05-29 09:28:31 -04:00
|
|
|
|
2017-01-09 07:14:25 -05:00
|
|
|
function hovercard_init(App $a) {
|
2016-05-29 09:28:31 -04:00
|
|
|
// Just for testing purposes
|
|
|
|
$_GET["mode"] = "minimal";
|
|
|
|
}
|
2017-04-30 00:01:26 -04:00
|
|
|
|
2016-05-29 09:28:31 -04:00
|
|
|
function hovercard_content() {
|
|
|
|
$profileurl = (x($_REQUEST,'profileurl') ? $_REQUEST['profileurl'] : "");
|
|
|
|
$datatype = (x($_REQUEST,'datatype') ?$_REQUEST['datatype'] : "json");
|
|
|
|
|
|
|
|
// Get out if the system doesn't have public access allowed
|
2017-11-06 21:22:52 -05:00
|
|
|
if(intval(Config::get('system','block_public')))
|
2016-05-29 09:28:31 -04:00
|
|
|
http_status_exit(401);
|
|
|
|
|
|
|
|
// Return the raw content of the template. We use this to make templates usable for js functions.
|
|
|
|
// Look at hovercard.js (function getHoverCardTemplate()).
|
|
|
|
// This part should be moved in it's own module. Maybe we could make more templates accessabel.
|
|
|
|
// (We need to discuss possible security lacks before doing this)
|
|
|
|
if ($datatype == "tpl") {
|
|
|
|
$templatecontent = get_template_content("hovercard.tpl");
|
|
|
|
echo $templatecontent;
|
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a contact is connected the url is internally changed to "redir/CID". We need the pure url to search for
|
|
|
|
// the contact. So we strip out the contact id from the internal url and look in the contact table for
|
|
|
|
// the real url (nurl)
|
2017-08-14 16:17:17 -04:00
|
|
|
if (local_user() && strpos($profileurl, "redir/") === 0) {
|
2016-05-29 09:28:31 -04:00
|
|
|
$cid = intval(substr($profileurl, 6));
|
2017-05-07 16:52:00 -04:00
|
|
|
$r = dba::select('contact', array('nurl', 'self'), array('id' => $cid), array('limit' => 1));
|
|
|
|
$profileurl = ($r["nurl"] ? $r["nurl"] : "");
|
|
|
|
$self = ($r["self"] ? $r["self"] : "");
|
2016-05-29 09:28:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// if it's the url containing https it should be converted to http
|
2017-11-15 09:47:28 -05:00
|
|
|
$nurl = normalise_link(GlobalContact::cleanContactUrl($profileurl));
|
2017-03-21 12:02:59 -04:00
|
|
|
if($nurl) {
|
2016-05-29 09:28:31 -04:00
|
|
|
// Search for contact data
|
2017-11-19 17:03:39 -05:00
|
|
|
$contact = Contact::getDetailsByURL($nurl);
|
2016-05-29 09:28:31 -04:00
|
|
|
}
|
2017-03-21 12:02:59 -04:00
|
|
|
if(!is_array($contact))
|
2016-05-29 09:28:31 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Get the photo_menu - the menu if possible contact actions
|
2017-03-21 12:02:59 -04:00
|
|
|
if(local_user())
|
2017-11-19 17:03:39 -05:00
|
|
|
$actions = Contact::photoMenu($contact);
|
2016-05-29 09:28:31 -04:00
|
|
|
|
|
|
|
|
|
|
|
// Move the contact data to the profile array so we can deliver it to
|
|
|
|
//
|
|
|
|
$profile = array(
|
|
|
|
'name' => $contact["name"],
|
|
|
|
'nick' => $contact["nick"],
|
|
|
|
'addr' => (($contact["addr"] != "") ? $contact["addr"] : $contact["url"]),
|
2016-06-05 07:57:11 -04:00
|
|
|
'thumb' => proxy_url($contact["thumb"], false, PROXY_SIZE_THUMB),
|
2016-05-29 09:28:31 -04:00
|
|
|
'url' => ($cid ? ("redir/".$cid) : zrl($contact["url"])),
|
|
|
|
'nurl' => $contact["nurl"], // We additionally store the nurl as identifier
|
|
|
|
// 'alias' => $contact["alias"],
|
|
|
|
'location' => $contact["location"],
|
|
|
|
'gender' => $contact["gender"],
|
|
|
|
'about' => $contact["about"],
|
|
|
|
'network' => format_network_name($contact["network"], $contact["url"]),
|
2016-06-27 05:57:47 -04:00
|
|
|
'tags' => $contact["keywords"],
|
2016-05-29 09:28:31 -04:00
|
|
|
// 'nsfw' => intval($contact["nsfw"]),
|
|
|
|
// 'server_url' => $contact["server_url"],
|
2017-04-11 17:00:45 -04:00
|
|
|
'bd' => (($contact["birthday"] <= '0001-01-01') ? "" : $contact["birthday"]),
|
2016-05-29 09:28:31 -04:00
|
|
|
// 'generation' => $contact["generation"],
|
2017-11-19 17:03:39 -05:00
|
|
|
'account_type' => Contact::getAccountType($contact),
|
2016-05-29 09:28:31 -04:00
|
|
|
'actions' => $actions,
|
|
|
|
);
|
2017-03-21 12:02:59 -04:00
|
|
|
if($datatype == "html") {
|
2016-05-29 09:28:31 -04:00
|
|
|
$t = get_markup_template("hovercard.tpl");
|
|
|
|
|
|
|
|
$o = replace_macros($t, array(
|
|
|
|
'$profile' => $profile,
|
|
|
|
));
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
json_return_and_die($profile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the raw content of a template file
|
2017-01-09 07:14:25 -05:00
|
|
|
*
|
2016-05-29 09:28:31 -04:00
|
|
|
* @param string $template The name of the template
|
|
|
|
* @param string $root Directory of the template
|
2017-01-09 07:14:25 -05:00
|
|
|
*
|
2016-05-29 09:28:31 -04:00
|
|
|
* @return string|bool Output the raw content if existent, otherwise false
|
|
|
|
*/
|
|
|
|
function get_template_content($template, $root = "") {
|
|
|
|
|
|
|
|
// We load the whole template system to get the filename.
|
|
|
|
// Maybe we can do it a little bit smarter if I get time.
|
|
|
|
$t = get_markup_template($template, $root);
|
|
|
|
$filename = $t->filename;
|
|
|
|
|
|
|
|
// Get the content of the template file
|
2017-03-21 12:02:59 -04:00
|
|
|
if(file_exists($filename)) {
|
2016-05-29 09:28:31 -04:00
|
|
|
$content = file_get_contents($filename);
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|