X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FProfile.php;h=765fed791a35f6afaf7698fafa58dfc8452ec160;hb=b9dba631aadf6c25a97b679808c684276b3dd76a;hp=ab9b7fd00f50bb16ca280cc73fdafad9f83378b5;hpb=6a376c29d85cb3e3b5ccf99bc604da472a7191c7;p=friendica.git diff --git a/src/Model/Profile.php b/src/Model/Profile.php index ab9b7fd00f..765fed791a 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -20,8 +20,9 @@ use Friendica\Core\Protocol; use Friendica\Core\Renderer; use Friendica\Core\Session; use Friendica\Core\System; -use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; +use Friendica\Protocol\Activity; use Friendica\Protocol\Diaspora; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; @@ -89,7 +90,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 .= ', '; } @@ -141,7 +142,7 @@ class Profile $user = DBA::selectFirst('user', ['uid'], ['nickname' => $nickname, 'account_removed' => false]); if (!DBA::isResult($user) && empty($profiledata)) { - Logger::log('profile error: ' . $a->query_string, Logger::DEBUG); + Logger::log('profile error: ' . DI::args()->getQueryString(), Logger::DEBUG); return; } @@ -152,7 +153,7 @@ class Profile } // Add profile data to sidebar - $a->page['aside'] .= self::sidebar($a, $profiledata, true, $show_connect); + DI::page()['aside'] .= self::sidebar($a, $profiledata, true, $show_connect); if (!DBA::isResult($user)) { return; @@ -162,7 +163,7 @@ class Profile $pdata = self::getByNickname($nickname, $user['uid'], $profile); if (empty($pdata) && empty($profiledata)) { - Logger::log('profile error: ' . $a->query_string, Logger::DEBUG); + Logger::log('profile error: ' . DI::args()->getQueryString(), Logger::DEBUG); return; } @@ -186,14 +187,13 @@ class Profile $a->profile['mobile-theme'] = PConfig::get($a->profile['profile_uid'], 'system', 'mobile_theme'); $a->profile['network'] = Protocol::DFRN; - $a->page['title'] = $a->profile['name'] . ' @ ' . Config::get('config', 'sitename'); + DI::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 */ @@ -206,7 +206,7 @@ class Profile } if (local_user() && local_user() == $a->profile['uid'] && $profiledata) { - $a->page['aside'] .= Renderer::replaceMacros( + DI::page()['aside'] .= Renderer::replaceMacros( Renderer::getMarkupTemplate('profile_edlink.tpl'), [ '$editprofile' => L10n::t('Edit profile'), @@ -215,7 +215,7 @@ class Profile ); } - $block = ((Config::get('system', 'block_public') && !local_user() && !remote_user()) ? true : false); + $block = ((Config::get('system', 'block_public') && !Session::isAuthenticated()) ? true : false); /** * @todo @@ -223,7 +223,7 @@ class Profile * But: When this profile was on the same server, then we could display the contacts */ if (!$profiledata) { - $a->page['aside'] .= self::sidebar($a, $a->profile, $block, $show_connect); + DI::page()['aside'] .= self::sidebar($a, $a->profile, $block, $show_connect); } return; @@ -248,15 +248,10 @@ class Profile */ public static function getByNickname($nickname, $uid = 0, $profile_id = 0) { - if (remote_user($uid) && !empty($_SESSION['remote'])) { - foreach ($_SESSION['remote'] as $visitor) { - if ($visitor['uid'] == $uid) { - $contact = DBA::selectFirst('contact', ['profile-id'], ['id' => $visitor['cid']]); - if (DBA::isResult($contact)) { - $profile_id = $contact['profile-id']; - } - break; - } + if (!empty(Session::getRemoteContactID($uid))) { + $contact = DBA::selectFirst('contact', ['profile-id'], ['id' => Session::getRemoteContactID($uid)]); + if (DBA::isResult($contact)) { + $profile_id = $contact['profile-id']; } } @@ -327,7 +322,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']); @@ -340,7 +335,7 @@ class Profile if (isset($profile['url'])) { $profile_url = $profile['url']; } else { - $profile_url = $a->getBaseURL() . '/profile/' . $profile['nickname']; + $profile_url = DI::baseUrl()->get() . '/profile/' . $profile['nickname']; } $follow_link = null; @@ -389,7 +384,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']; } @@ -399,7 +394,7 @@ class Profile // show edit profile to yourself if (!$is_contact && $local_user_is_self) { if (Feature::isEnabled(local_user(), 'multi_profiles')) { - $profile['edit'] = [System::baseUrl() . '/profiles', L10n::t('Profiles'), '', L10n::t('Manage/edit profiles')]; + $profile['edit'] = [DI::baseUrl() . '/profiles', L10n::t('Profiles'), '', L10n::t('Manage/edit profiles')]; $r = q( "SELECT * FROM `profile` WHERE `uid` = %d", local_user() @@ -425,7 +420,7 @@ class Profile } } } else { - $profile['edit'] = [System::baseUrl() . '/profiles/' . $profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')]; + $profile['edit'] = [DI::baseUrl() . '/profiles/' . $profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')]; $profile['menu'] = [ 'chg_photo' => L10n::t('Change profile photo'), 'cr_new' => null, @@ -453,7 +448,7 @@ class Profile $about = !empty($profile['about']) ? L10n::t('About:') : false; $xmpp = !empty($profile['xmpp']) ? L10n::t('XMPP:') : false; - if ((!empty($profile['hidewall']) || $block) && !local_user() && !remote_user()) { + if ((!empty($profile['hidewall']) || $block) && !Session::isAuthenticated()) { $location = $gender = $marital = $homepage = $about = false; } @@ -464,15 +459,15 @@ class Profile if (!empty($profile['guid'])) { $diaspora = [ 'guid' => $profile['guid'], - 'podloc' => System::baseUrl(), - 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ), + 'podloc' => DI::baseUrl(), + '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; @@ -535,7 +530,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, [ @@ -574,7 +569,7 @@ class Profile $a = \get_app(); $o = ''; - if (!local_user() || $a->is_mobile || $a->is_tablet) { + if (!local_user() || DI::mode()->isMobile() || DI::mode()->isMobile()) { return $o; } @@ -671,7 +666,7 @@ class Profile $a = \get_app(); $o = ''; - if (!local_user() || $a->is_mobile || $a->is_tablet) { + if (!local_user() || DI::mode()->isMobile() || DI::mode()->isMobile()) { return $o; } @@ -697,7 +692,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; @@ -828,51 +823,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]; } @@ -882,7 +877,7 @@ class Profile } if ($a->profile['uid'] == local_user()) { - $profile['edit'] = [System::baseUrl() . '/profiles/' . $a->profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')]; + $profile['edit'] = [DI::baseUrl() . '/profiles/' . $a->profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')]; } return Renderer::replaceMacros($tpl, [ @@ -910,7 +905,7 @@ class Profile $nickname = $a->user['nickname']; } - $baseProfileUrl = System::baseUrl() . '/profile/' . $nickname; + $baseProfileUrl = DI::baseUrl() . '/profile/' . $nickname; $tabs = [ [ @@ -931,7 +926,7 @@ class Profile ], [ 'label' => L10n::t('Photos'), - 'url' => System::baseUrl() . '/photos/' . $nickname, + 'url' => DI::baseUrl() . '/photos/' . $nickname, 'sel' => $current == 'photos' ? 'active' : '', 'title' => L10n::t('Photo Albums'), 'id' => 'photo-tab', @@ -939,7 +934,7 @@ class Profile ], [ 'label' => L10n::t('Videos'), - 'url' => System::baseUrl() . '/videos/' . $nickname, + 'url' => DI::baseUrl() . '/videos/' . $nickname, 'sel' => $current == 'videos' ? 'active' : '', 'title' => L10n::t('Videos'), 'id' => 'video-tab', @@ -951,7 +946,7 @@ class Profile if ($is_owner && $a->theme_events_in_profile) { $tabs[] = [ 'label' => L10n::t('Events'), - 'url' => System::baseUrl() . '/events', + 'url' => DI::baseUrl() . '/events', 'sel' => $current == 'events' ? 'active' : '', 'title' => L10n::t('Events and Calendar'), 'id' => 'events-tab', @@ -962,7 +957,7 @@ class Profile } elseif (!$is_owner) { $tabs[] = [ 'label' => L10n::t('Events'), - 'url' => System::baseUrl() . '/cal/' . $nickname, + 'url' => DI::baseUrl() . '/cal/' . $nickname, 'sel' => $current == 'cal' ? 'active' : '', 'title' => L10n::t('Events and Calendar'), 'id' => 'events-tab', @@ -973,7 +968,7 @@ class Profile if ($is_owner) { $tabs[] = [ 'label' => L10n::t('Personal Notes'), - 'url' => System::baseUrl() . '/notes', + 'url' => DI::baseUrl() . '/notes', 'sel' => $current == 'notes' ? 'active' : '', 'title' => L10n::t('Only You Can See This'), 'id' => 'notes-tab', @@ -984,7 +979,7 @@ class Profile if (!empty($_SESSION['new_member']) && $is_owner) { $tabs[] = [ 'label' => L10n::t('Tips for New Members'), - 'url' => System::baseUrl() . '/newmember', + 'url' => DI::baseUrl() . '/newmember', 'sel' => false, 'title' => L10n::t('Tips for New Members'), 'id' => 'newmember-tab', @@ -1029,6 +1024,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 @@ -1042,7 +1043,9 @@ class Profile return; } - $arr = ['zrl' => $my_url, 'url' => $a->cmd]; + $addr = $_GET['addr'] ?? $my_url; + + $arr = ['zrl' => $my_url, 'url' => DI::args()->getCommand()]; Hook::callAll('zrl_init', $arr); // Try to find the public contact entry of the visitor. @@ -1070,21 +1073,19 @@ class Profile Logger::log('Not authenticated. Invoking reverse magic-auth for ' . $my_url, Logger::DEBUG); - Worker::add(PRIORITY_LOW, 'GProbe', $my_url); + // 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, '', DI::args()->getQueryString()), '?&'); - // 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); // The other instance needs to know where to redirect. - $dest = urlencode($a->getBaseURL() . '/' . $query); + $dest = urlencode(DI::baseUrl()->get() . '/' . $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 != DI::baseUrl()->get() && !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'); @@ -1121,17 +1122,7 @@ class Profile $_SESSION['visitor_home'] = $visitor['url']; $_SESSION['my_url'] = $visitor['url']; - /// @todo replace this and the query for this variable with some cleaner functionality - $_SESSION['remote'] = []; - - $remote_contacts = DBA::select('contact', ['id', 'uid'], ['nurl' => $visitor['nurl'], 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]); - while ($contact = DBA::fetch($remote_contacts)) { - if (($contact['uid'] == 0) || Contact::isBlockedByUser($visitor['id'], $contact['uid'])) { - continue; - } - - $_SESSION['remote'][$contact['uid']] = ['cid' => $contact['id'], 'uid' => $contact['uid']]; - } + Session::setVisitorsContacts(); $a->contact = $visitor; @@ -1171,7 +1162,7 @@ class Profile $arr = [ 'visitor' => $visitor, - 'url' => $a->query_string + 'url' => DI::args()->getQueryString() ]; /** * @hooks magic_auth_success @@ -1183,7 +1174,7 @@ class Profile $a->contact = $arr['visitor']; - info(L10n::t('OpenWebAuth: %1$s welcomes %2$s', $a->getHostName(), $visitor['name'])); + info(L10n::t('OpenWebAuth: %1$s welcomes %2$s', DI::baseUrl()->getHostname(), $visitor['name'])); Logger::log('OpenWebAuth: auth success from ' . $visitor['addr'], Logger::DEBUG); } @@ -1193,7 +1184,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) !== '/') { @@ -1250,7 +1241,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` @@ -1272,7 +1263,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`");