]> git.mxchange.org Git - friendica.git/blobdiff - mod/hovercard.php
Use minimal mode to change site theme settings
[friendica.git] / mod / hovercard.php
index 334bf228abe74ddb253c79ccb5d1b253ef69f593..101ebd5af2e4e1b9068e9550368ef7bad137565c 100644 (file)
@@ -7,11 +7,16 @@
  * Author: Rabuzarus <https://github.com/rabuzarus>
  * License: GNU AFFERO GENERAL PUBLIC LICENSE (Version 3)
  */
+
 use Friendica\App;
 use Friendica\Core\Config;
+use Friendica\Core\Renderer;
+use Friendica\Core\System;
+use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
-use Friendica\Model\Profile;
+use Friendica\Util\Proxy as ProxyUtils;
+use Friendica\Util\Strings;
 
 function hovercard_init(App $a)
 {
@@ -26,7 +31,7 @@ function hovercard_content()
 
        // Get out if the system doesn't have public access allowed
        if (intval(Config::get('system', 'block_public'))) {
-               http_status_exit(401);
+               System::httpExit(401);
        }
 
        // Return the raw content of the template. We use this to make templates usable for js functions.
@@ -43,19 +48,41 @@ function hovercard_content()
        // the contact. So we strip out the contact id from the internal url and look in the contact table for
        // the real url (nurl)
        $cid = 0;
-       if (local_user() && strpos($profileurl, 'redir/') === 0) {
+       if (strpos($profileurl, 'redir/') === 0) {
                $cid = intval(substr($profileurl, 6));
-               $remote_contact = dba::selectFirst('contact', ['nurl'], ['id' => $cid]);
+               $remote_contact = DBA::selectFirst('contact', ['nurl'], ['id' => $cid]);
                $profileurl = defaults($remote_contact, 'nurl', '');
        }
 
        $contact = [];
        // if it's the url containing https it should be converted to http
-       $nurl = normalise_link(GContact::cleanContactUrl($profileurl));
-       if ($nurl) {
-               // Search for contact data
+       $nurl = Strings::normaliseLink(GContact::cleanContactUrl($profileurl));
+       if (!$nurl) {
+               return;
+       }
+
+       // Search for contact data
+       // Look if the local user has got the contact
+       if (local_user()) {
+               $contact = Contact::getDetailsByURL($nurl, local_user());
+       }
+
+       // If not then check the global user
+       if (!count($contact)) {
                $contact = Contact::getDetailsByURL($nurl);
        }
+
+       // Feeds url could have been destroyed through "cleanContactUrl", so we now use the original url
+       if (!count($contact) && local_user()) {
+               $nurl = Strings::normaliseLink($profileurl);
+               $contact = Contact::getDetailsByURL($nurl, local_user());
+       }
+
+       if (!count($contact)) {
+               $nurl = Strings::normaliseLink($profileurl);
+               $contact = Contact::getDetailsByURL($nurl);
+       }
+
        if (!count($contact)) {
                return;
        }
@@ -63,34 +90,36 @@ function hovercard_content()
        // Get the photo_menu - the menu if possible contact actions
        if (local_user()) {
                $actions = Contact::photoMenu($contact);
+       } else {
+               $actions = [];
        }
 
        // Move the contact data to the profile array so we can deliver it to
        $profile = [
-               'name'     => $contact['name'],
-               'nick'     => $contact['nick'],
-               'addr'     => defaults($contact, 'addr', $contact['url']),
-               'thumb'    => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB),
-               'url'      => $cid ? ('redir/' . $cid) : Profile::zrl($contact['url']),
-               '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'],
+               'name'         => $contact['name'],
+               'nick'         => $contact['nick'],
+               'addr'         => defaults($contact, 'addr', $contact['url']),
+               'thumb'        => ProxyUtils::proxifyUrl($contact['thumb'], false, ProxyUtils::SIZE_THUMB),
+               'url'          => Contact::magicLink($contact['url']),
+               'nurl'         => $contact['nurl'], // We additionally store the nurl as identifier
+               'location'     => $contact['location'],
+               'gender'       => $contact['gender'],
+               'about'        => $contact['about'],
+               'network_link' => Strings::formatNetworkName($contact['network'], $contact['url']),
+               'tags'         => $contact['keywords'],
+               'bd'           => $contact['birthday'] <= DBA::NULL_DATE ? '' : $contact['birthday'],
                'account_type' => Contact::getAccountType($contact),
-               'actions'  => $actions,
+               'actions'      => $actions,
        ];
        if ($datatype == 'html') {
-               $tpl = get_markup_template('hovercard.tpl');
-               $o = replace_macros($tpl, [
+               $tpl = Renderer::getMarkupTemplate('hovercard.tpl');
+               $o = Renderer::replaceMacros($tpl, [
                        '$profile' => $profile,
                ]);
 
                return $o;
        } else {
-               json_return_and_die($profile);
+               System::jsonExit($profile);
        }
 }
 
@@ -106,7 +135,7 @@ 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);
+       $t = Renderer::getMarkupTemplate($template, $root);
        $filename = $t->filename;
 
        // Get the content of the template file