2016-05-29 15:28:31 +02: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 06:07:00 +02:00
|
|
|
use Friendica\App;
|
2017-11-07 03:22:52 +01:00
|
|
|
use Friendica\Core\Config;
|
2018-01-27 17:59:10 +01:00
|
|
|
use Friendica\Core\System;
|
2017-12-07 15:04:24 +01:00
|
|
|
use Friendica\Model\Contact;
|
2017-12-07 15:09:28 +01:00
|
|
|
use Friendica\Model\GContact;
|
2018-01-15 03:38:26 +01:00
|
|
|
use Friendica\Model\Profile;
|
2016-05-29 15:28:31 +02:00
|
|
|
|
2018-01-01 22:27:01 +01:00
|
|
|
function hovercard_init(App $a)
|
|
|
|
{
|
2016-05-29 15:28:31 +02:00
|
|
|
// Just for testing purposes
|
2018-01-01 22:27:01 +01:00
|
|
|
$_GET['mode'] = 'minimal';
|
2016-05-29 15:28:31 +02:00
|
|
|
}
|
2017-04-30 06:01:26 +02:00
|
|
|
|
2018-01-01 22:27:01 +01:00
|
|
|
function hovercard_content()
|
|
|
|
{
|
|
|
|
$profileurl = defaults($_REQUEST, 'profileurl', '');
|
|
|
|
$datatype = defaults($_REQUEST, 'datatype' , 'json');
|
2016-05-29 15:28:31 +02:00
|
|
|
|
|
|
|
// Get out if the system doesn't have public access allowed
|
2018-01-01 22:27:01 +01:00
|
|
|
if (intval(Config::get('system', 'block_public'))) {
|
2018-01-27 17:59:10 +01:00
|
|
|
System::httpExit(401);
|
2018-01-01 22:27:01 +01:00
|
|
|
}
|
2016-05-29 15:28:31 +02:00
|
|
|
|
|
|
|
// Return the raw content of the template. We use this to make templates usable for js functions.
|
|
|
|
// Look at hovercard.js (function getHoverCardTemplate()).
|
2018-01-01 22:27:01 +01:00
|
|
|
// This part should be moved in its own module. Maybe we could make more templates accessible.
|
|
|
|
// (We need to discuss possible security leaks before doing this)
|
|
|
|
if ($datatype == 'tpl') {
|
|
|
|
$templatecontent = get_template_content('hovercard.tpl');
|
2016-05-29 15:28:31 +02:00
|
|
|
echo $templatecontent;
|
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
2018-01-01 22:27:01 +01:00
|
|
|
// If a contact is connected the url is internally changed to 'redir/CID'. We need the pure url to search for
|
2016-05-29 15:28:31 +02:00
|
|
|
// the contact. So we strip out the contact id from the internal url and look in the contact table for
|
|
|
|
// the real url (nurl)
|
2018-01-01 22:27:01 +01:00
|
|
|
$cid = 0;
|
|
|
|
if (local_user() && strpos($profileurl, 'redir/') === 0) {
|
2016-05-29 15:28:31 +02:00
|
|
|
$cid = intval(substr($profileurl, 6));
|
2018-01-11 09:26:30 +01:00
|
|
|
$remote_contact = dba::selectFirst('contact', ['nurl'], ['id' => $cid]);
|
|
|
|
$profileurl = defaults($remote_contact, 'nurl', '');
|
2016-05-29 15:28:31 +02:00
|
|
|
}
|
|
|
|
|
2018-01-01 22:27:01 +01:00
|
|
|
$contact = [];
|
2016-05-29 15:28:31 +02:00
|
|
|
// if it's the url containing https it should be converted to http
|
2017-12-07 15:09:28 +01:00
|
|
|
$nurl = normalise_link(GContact::cleanContactUrl($profileurl));
|
2018-01-01 22:27:01 +01:00
|
|
|
if ($nurl) {
|
2016-05-29 15:28:31 +02:00
|
|
|
// Search for contact data
|
2017-11-19 23:03:39 +01:00
|
|
|
$contact = Contact::getDetailsByURL($nurl);
|
2016-05-29 15:28:31 +02:00
|
|
|
}
|
2018-01-01 22:27:01 +01:00
|
|
|
if (!count($contact)) {
|
2016-05-29 15:28:31 +02:00
|
|
|
return;
|
2018-01-01 22:27:01 +01:00
|
|
|
}
|
2016-05-29 15:28:31 +02:00
|
|
|
|
|
|
|
// Get the photo_menu - the menu if possible contact actions
|
2018-01-01 22:27:01 +01:00
|
|
|
if (local_user()) {
|
2017-11-19 23:03:39 +01:00
|
|
|
$actions = Contact::photoMenu($contact);
|
2018-01-01 22:27:01 +01:00
|
|
|
}
|
2016-05-29 15:28:31 +02:00
|
|
|
|
|
|
|
// Move the contact data to the profile array so we can deliver it to
|
2018-01-15 14:05:12 +01:00
|
|
|
$profile = [
|
2018-01-01 22:27:01 +01:00
|
|
|
'name' => $contact['name'],
|
|
|
|
'nick' => $contact['nick'],
|
|
|
|
'addr' => defaults($contact, 'addr', $contact['url']),
|
|
|
|
'thumb' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB),
|
2018-01-15 03:22:39 +01:00
|
|
|
'url' => $cid ? ('redir/' . $cid) : Profile::zrl($contact['url']),
|
2018-01-01 22:27:01 +01:00
|
|
|
'nurl' => $contact['nurl'], // We additionally store the nurl as identifier
|
|
|
|
'location' => $contact['location'],
|
|
|
|
'gender' => $contact['gender'],
|
|
|
|
'about' => $contact['about'],
|
|
|
|
'network' => format_network_name($contact['network'], $contact['url']),
|
|
|
|
'tags' => $contact['keywords'],
|
|
|
|
'bd' => $contact['birthday'] <= '0001-01-01' ? '' : $contact['birthday'],
|
2017-11-19 23:03:39 +01:00
|
|
|
'account_type' => Contact::getAccountType($contact),
|
2018-01-01 22:27:01 +01:00
|
|
|
'actions' => $actions,
|
2018-01-15 14:05:12 +01:00
|
|
|
];
|
2018-01-01 22:27:01 +01:00
|
|
|
if ($datatype == 'html') {
|
|
|
|
$tpl = get_markup_template('hovercard.tpl');
|
2018-01-15 14:05:12 +01:00
|
|
|
$o = replace_macros($tpl, [
|
2016-05-29 15:28:31 +02:00
|
|
|
'$profile' => $profile,
|
2018-01-15 14:05:12 +01:00
|
|
|
]);
|
2016-05-29 15:28:31 +02:00
|
|
|
|
|
|
|
return $o;
|
|
|
|
} else {
|
2018-01-27 17:59:10 +01:00
|
|
|
System::jsonExit($profile);
|
2016-05-29 15:28:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the raw content of a template file
|
2017-01-09 13:14:25 +01:00
|
|
|
*
|
2016-05-29 15:28:31 +02:00
|
|
|
* @param string $template The name of the template
|
|
|
|
* @param string $root Directory of the template
|
2017-01-09 13:14:25 +01:00
|
|
|
*
|
2016-05-29 15:28:31 +02:00
|
|
|
* @return string|bool Output the raw content if existent, otherwise false
|
|
|
|
*/
|
2018-01-01 22:27:01 +01:00
|
|
|
function get_template_content($template, $root = '')
|
|
|
|
{
|
2016-05-29 15:28:31 +02:00
|
|
|
// 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
|
2018-01-01 22:27:01 +01:00
|
|
|
if (file_exists($filename)) {
|
2016-05-29 15:28:31 +02:00
|
|
|
$content = file_get_contents($filename);
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|