]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Profile.php
Merge pull request #7726 from tobiasd/20191010-uexport
[friendica.git] / src / Model / Profile.php
index 01c585139238678a62c52f6ec4771fae3ae17929..eb274a6405bcbc0488123204e66aecdc69a8e249 100644 (file)
@@ -20,8 +20,10 @@ use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
 use Friendica\Core\Session;
 use Friendica\Core\System;
+use Friendica\Core\Theme;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
+use Friendica\Protocol\Activity;
 use Friendica\Protocol\Diaspora;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
@@ -89,7 +91,7 @@ class Profile
                        $location .= $profile['locality'];
                }
 
-               if (!empty($profile['region']) && (defaults($profile, 'locality', '') != $profile['region'])) {
+               if (!empty($profile['region']) && (($profile['locality'] ?? '') != $profile['region'])) {
                        if ($location) {
                                $location .= ', ';
                        }
@@ -189,11 +191,10 @@ class Profile
                $a->page['title'] = $a->profile['name'] . ' @ ' . Config::get('config', 'sitename');
 
                if (!$profiledata && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
-                       $_SESSION['theme'] = $a->profile['theme'];
+                       $a->setCurrentTheme($a->profile['theme']);
+                       $a->setCurrentMobileTheme($a->profile['mobile-theme']);
                }
 
-               $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
-
                /*
                * load/reload current theme info
                */
@@ -322,7 +323,7 @@ class Profile
                        return $o;
                }
 
-               $profile['picdate'] = urlencode(defaults($profile, 'picdate', ''));
+               $profile['picdate'] = urlencode($profile['picdate'] ?? '');
 
                if (($profile['network'] != '') && ($profile['network'] != Protocol::DFRN)) {
                        $profile['network_link'] = Strings::formatNetworkName($profile['network'], $profile['url']);
@@ -384,7 +385,7 @@ class Profile
 
                        if (Contact::canReceivePrivateMessages($profile)) {
                                if ($visitor_is_followed || $visitor_is_following) {
-                                       $wallmessage_link = $visitor_base_path . '/message/new/' . base64_encode(defaults($profile, 'addr', ''));
+                                       $wallmessage_link = $visitor_base_path . '/message/new/' . base64_encode($profile['addr'] ?? '');
                                } elseif ($visitor_is_authenticated && !empty($profile['unkmail'])) {
                                        $wallmessage_link = 'wallmessage/' . $profile['nickname'];
                                }
@@ -460,14 +461,14 @@ class Profile
                        $diaspora = [
                                'guid' => $profile['guid'],
                                'podloc' => System::baseUrl(),
-                               'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
+                               'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false'),
                                'nickname' => $profile['nickname'],
                                'fullname' => $profile['name'],
                                'firstname' => $firstname,
                                'lastname' => $lastname,
-                               'photo300' => defaults($profile, 'contact_photo', ''),
-                               'photo100' => defaults($profile, 'contact_thumb', ''),
-                               'photo50' => defaults($profile, 'contact_micro', ''),
+                               'photo300' => $profile['contact_photo'] ?? '',
+                               'photo100' => $profile['contact_thumb'] ?? '',
+                               'photo50' => $profile['contact_micro'] ?? '',
                        ];
                } else {
                        $diaspora = false;
@@ -530,7 +531,7 @@ class Profile
                        $p['photo'] = ProxyUtils::proxifyUrl($p['photo'], false, ProxyUtils::SIZE_SMALL);
                }
 
-               $p['url'] = Contact::magicLink(defaults($p, 'url', $profile_url));
+               $p['url'] = Contact::magicLink(($p['url'] ?? '') ?: $profile_url);
 
                $tpl = Renderer::getMarkupTemplate('profile_vcard.tpl');
                $o .= Renderer::replaceMacros($tpl, [
@@ -692,7 +693,7 @@ class Profile
 
                        while ($rr = DBA::fetch($s)) {
                                $condition = ['parent-uri' => $rr['uri'], 'uid' => $rr['uid'], 'author-id' => public_contact(),
-                                       'activity' => [Item::activityToIndex(ACTIVITY_ATTEND), Item::activityToIndex(ACTIVITY_ATTENDMAYBE)],
+                                       'activity' => [Item::activityToIndex( Activity::ATTEND), Item::activityToIndex(Activity::ATTENDMAYBE)],
                                        'visible' => true, 'deleted' => false];
                                if (!Item::exists($condition)) {
                                        continue;
@@ -823,51 +824,51 @@ class Profile
                                $profile['religion'] = [L10n::t('Religion:'), $a->profile['religion']];
                        }
 
-                       if ($txt = prepare_text($a->profile['about'])) {
+                       if ($txt = BBCode::convert($a->profile['about'])) {
                                $profile['about'] = [L10n::t('About:'), $txt];
                        }
 
-                       if ($txt = prepare_text($a->profile['interest'])) {
+                       if ($txt = BBCode::convert($a->profile['interest'])) {
                                $profile['interest'] = [L10n::t('Hobbies/Interests:'), $txt];
                        }
 
-                       if ($txt = prepare_text($a->profile['likes'])) {
+                       if ($txt = BBCode::convert($a->profile['likes'])) {
                                $profile['likes'] = [L10n::t('Likes:'), $txt];
                        }
 
-                       if ($txt = prepare_text($a->profile['dislikes'])) {
+                       if ($txt = BBCode::convert($a->profile['dislikes'])) {
                                $profile['dislikes'] = [L10n::t('Dislikes:'), $txt];
                        }
 
-                       if ($txt = prepare_text($a->profile['contact'])) {
+                       if ($txt = BBCode::convert($a->profile['contact'])) {
                                $profile['contact'] = [L10n::t('Contact information and Social Networks:'), $txt];
                        }
 
-                       if ($txt = prepare_text($a->profile['music'])) {
+                       if ($txt = BBCode::convert($a->profile['music'])) {
                                $profile['music'] = [L10n::t('Musical interests:'), $txt];
                        }
 
-                       if ($txt = prepare_text($a->profile['book'])) {
+                       if ($txt = BBCode::convert($a->profile['book'])) {
                                $profile['book'] = [L10n::t('Books, literature:'), $txt];
                        }
 
-                       if ($txt = prepare_text($a->profile['tv'])) {
+                       if ($txt = BBCode::convert($a->profile['tv'])) {
                                $profile['tv'] = [L10n::t('Television:'), $txt];
                        }
 
-                       if ($txt = prepare_text($a->profile['film'])) {
+                       if ($txt = BBCode::convert($a->profile['film'])) {
                                $profile['film'] = [L10n::t('Film/dance/culture/entertainment:'), $txt];
                        }
 
-                       if ($txt = prepare_text($a->profile['romance'])) {
+                       if ($txt = BBCode::convert($a->profile['romance'])) {
                                $profile['romance'] = [L10n::t('Love/Romance:'), $txt];
                        }
 
-                       if ($txt = prepare_text($a->profile['work'])) {
+                       if ($txt = BBCode::convert($a->profile['work'])) {
                                $profile['work'] = [L10n::t('Work/employment:'), $txt];
                        }
 
-                       if ($txt = prepare_text($a->profile['education'])) {
+                       if ($txt = BBCode::convert($a->profile['education'])) {
                                $profile['education'] = [L10n::t('School/education:'), $txt];
                        }
 
@@ -1024,6 +1025,12 @@ class Profile
         *
         * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/include/channel.php
         *
+        * The implementation for Friendica sadly differs in some points from the one for Hubzilla:
+        * - Hubzilla uses the "zid" parameter, while for Friendica it had been replaced with "zrl"
+        * - There seem to be some reverse authentication (rmagic) that isn't implemented in Friendica at all
+        *
+        * It would be favourable to harmonize the two implementations.
+        *
         * @param App $a Application instance.
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
@@ -1037,6 +1044,8 @@ class Profile
                        return;
                }
 
+               $addr = $_GET['addr'] ?? $my_url;
+
                $arr = ['zrl' => $my_url, 'url' => $a->cmd];
                Hook::callAll('zrl_init', $arr);
 
@@ -1067,19 +1076,19 @@ class Profile
 
                Worker::add(PRIORITY_LOW, 'GProbe', $my_url);
 
-               // Try to avoid recursion - but send them home to do a proper magic auth.
-               $query = str_replace(array('?zrl=', '&zid='), array('?rzrl=', '&rzrl='), $a->query_string);
+               // Remove the "addr" parameter from the destination. It is later added as separate parameter again.
+               $addr_request = 'addr=' . urlencode($addr);
+               $query = rtrim(str_replace($addr_request, '', $a->query_string), '?&');
+
                // The other instance needs to know where to redirect.
                $dest = urlencode($a->getBaseURL() . '/' . $query);
 
                // We need to extract the basebath from the profile url
                // to redirect the visitors '/magic' module.
-               // Note: We should have the basepath of a contact also in the contact table.
-               $urlarr = explode('/profile/', $contact['url']);
-               $basepath = $urlarr[0];
+               $basepath = Contact::getBasepath($contact['url']);
 
-               if ($basepath != $a->getBaseURL() && !strstr($dest, '/magic') && !strstr($dest, '/rmagic')) {
-                       $magic_path = $basepath . '/magic' . '?f=&owa=1&dest=' . $dest;
+               if ($basepath != $a->getBaseURL() && !strstr($dest, '/magic')) {
+                       $magic_path = $basepath . '/magic' . '?owa=1&dest=' . $dest . '&' . $addr_request;
 
                        // We have to check if the remote server does understand /magic without invoking something
                        $serverret = Network::curl($basepath . '/magic');
@@ -1178,7 +1187,7 @@ class Profile
                if (!strlen($s)) {
                        return $s;
                }
-               if ((!strpos($s, '/profile/')) && (!$force)) {
+               if (!strpos($s, '/profile/') && !$force) {
                        return $s;
                }
                if ($force && substr($s, -1, 1) !== '/') {
@@ -1235,7 +1244,7 @@ class Profile
 
                if (!empty($search)) {
                        $searchTerm = '%' . $search . '%';
-                       $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` 
+                       $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total`
                                FROM `profile`
                                LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
                                WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed`
@@ -1257,7 +1266,7 @@ class Profile
                                $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm,
                                $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm);
                } else {
-                       $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` 
+                       $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total`
                                FROM `profile`
                                LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
                                WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed`");