3 namespace Friendica\Module\Contact;
5 use Friendica\BaseModule;
6 use Friendica\Core\Config;
7 use Friendica\Core\Renderer;
8 use Friendica\Core\Session;
9 use Friendica\Database\DBA;
10 use Friendica\Model\Contact;
11 use Friendica\Model\GContact;
12 use Friendica\Network\HTTPException;
13 use Friendica\Util\Strings;
14 use Friendica\Util\Proxy;
17 * Asynchronous HTML fragment provider for frio contact hovercards
19 class Hovercard extends BaseModule
21 public static function rawContent(array $parameters = [])
23 $contact_url = $_REQUEST['url'] ?? '';
25 // Get out if the system doesn't have public access allowed
26 if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
27 throw new HTTPException\ForbiddenException();
30 // If a contact is connected the url is internally changed to 'redir/CID'. We need the pure url to search for
31 // the contact. So we strip out the contact id from the internal url and look in the contact table for
32 // the real url (nurl)
33 if (strpos($contact_url, 'redir/') === 0) {
34 $cid = intval(substr($contact_url, 6));
35 $remote_contact = Contact::selectFirst(['nurl'], ['id' => $cid]);
36 $contact_url = $remote_contact['nurl'] ?? '';
41 // if it's the url containing https it should be converted to http
42 $contact_nurl = Strings::normaliseLink(GContact::cleanContactUrl($contact_url));
44 throw new HTTPException\BadRequestException();
47 // Search for contact data
48 // Look if the local user has got the contact
49 if (Session::isAuthenticated()) {
50 $contact = Contact::getDetailsByURL($contact_nurl, local_user());
53 // If not then check the global user
54 if (!count($contact)) {
55 $contact = Contact::getDetailsByURL($contact_nurl);
58 // Feeds url could have been destroyed through "cleanContactUrl", so we now use the original url
59 if (!count($contact) && Session::isAuthenticated()) {
60 $contact_nurl = Strings::normaliseLink($contact_url);
61 $contact = Contact::getDetailsByURL($contact_nurl, local_user());
64 if (!count($contact)) {
65 $contact_nurl = Strings::normaliseLink($contact_url);
66 $contact = Contact::getDetailsByURL($contact_nurl);
69 if (!count($contact)) {
70 throw new HTTPException\NotFoundException();
73 // Get the photo_menu - the menu if possible contact actions
74 if (Session::isAuthenticated()) {
75 $actions = Contact::photoMenu($contact);
80 // Move the contact data to the profile array so we can deliver it to
81 $tpl = Renderer::getMarkupTemplate('hovercard.tpl');
82 $o = Renderer::replaceMacros($tpl, [
84 'name' => $contact['name'],
85 'nick' => $contact['nick'],
86 'addr' => $contact['addr'] ?: $contact['url'],
87 'thumb' => Proxy::proxifyUrl($contact['thumb'], false, Proxy::SIZE_THUMB),
88 'url' => Contact::magicLink($contact['url']),
89 'nurl' => $contact['nurl'],
90 'location' => $contact['location'],
91 'gender' => $contact['gender'],
92 'about' => $contact['about'],
93 'network_link' => Strings::formatNetworkName($contact['network'], $contact['url']),
94 'tags' => $contact['keywords'],
95 'bd' => $contact['birthday'] <= DBA::NULL_DATE ? '' : $contact['birthday'],
96 'account_type' => Contact::getAccountType($contact),
97 'actions' => $actions,