X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FProfile.php;h=10bd3a1d7542843aaad239c512c4e892bba45b80;hb=c34204cf50ced68a14d220706c4dc6ef93eb94c9;hp=36a33876e722dc523dd8ddf494d9283cda91752f;hpb=1c6bf7d25aeb850ed4072ed80291c94c025d5b47;p=friendica.git diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 36a33876e7..10bd3a1d75 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -18,6 +18,7 @@ use Friendica\Core\Logger; use Friendica\Core\PConfig; use Friendica\Core\Protocol; use Friendica\Core\Renderer; +use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; @@ -116,6 +117,11 @@ class Profile } if (count($profiledata) > 0) { + // Ensure to have a "nickname" field + if (empty($profiledata['nickname']) && !empty($profiledata['nick'])) { + $profiledata['nickname'] = $profiledata['nick']; + } + // Add profile data to sidebar $a->page['aside'] .= self::sidebar($a, $profiledata, true, $show_connect); @@ -302,127 +308,102 @@ class Profile Hook::callAll('profile_sidebar_enter', $profile); - - // don't show connect link to yourself - $connect = $profile['uid'] != local_user() ? L10n::t('Connect') : false; - - // don't show connect link to authenticated visitors either - if (remote_user() && !empty($_SESSION['remote'])) { - foreach ($_SESSION['remote'] as $visitor) { - if ($visitor['uid'] == $profile['uid']) { - $connect = false; - break; - } - } - } - - if (!$show_connect) { - $connect = false; + if (isset($profile['url'])) { + $profile_url = $profile['url']; + } else { + $profile_url = $a->getBaseURL() . '/profile/' . $profile['nickname']; } - $profile_url = ''; - - // Is the local user already connected to that user? - if ($connect && local_user()) { - if (isset($profile['url'])) { - $profile_url = Strings::normaliseLink($profile['url']); - } else { - $profile_url = Strings::normaliseLink(System::baseUrl() . '/profile/' . $profile['nickname']); - } - - if (DBA::exists('contact', ['pending' => false, 'uid' => local_user(), 'nurl' => $profile_url])) { - $connect = false; - } - } + $follow_link = null; + $unfollow_link = null; + $subscribe_feed_link = null; + $wallmessage_link = null; - // Is the remote user already connected to that user? - if ($connect && Contact::isFollower(remote_user(), $profile['uid'])) { - $connect = false; - } - if ($connect && ($profile['network'] != Protocol::DFRN) && !isset($profile['remoteconnect'])) { - $connect = false; - } - $remoteconnect = null; - if (isset($profile['remoteconnect'])) { - $remoteconnect = $profile['remoteconnect']; + $visitor_contact = []; + if (!empty($profile['uid']) && self::getMyURL()) { + $visitor_contact = Contact::selectFirst(['rel'], ['uid' => $profile['uid'], 'nurl' => Strings::normaliseLink(self::getMyURL())]); } - if ($connect && ($profile['network'] == Protocol::DFRN) && !isset($remoteconnect)) { - $subscribe_feed = L10n::t('Atom feed'); - } else { - $subscribe_feed = false; + $profile_contact = []; + if (!empty($profile['cid']) && self::getMyURL()) { + $profile_contact = Contact::selectFirst(['rel'], ['id' => $profile['cid']]); } - $wallmessage = false; - $wallmessage_link = false; + $profile_is_dfrn = $profile['network'] == Protocol::DFRN; + $profile_is_native = in_array($profile['network'], Protocol::NATIVE_SUPPORT); + $local_user_is_self = local_user() && local_user() == ($profile['profile_uid'] ?? 0); + $visitor_is_authenticated = (bool)self::getMyURL(); + $visitor_is_following = + in_array($visitor_contact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND]) + || in_array($profile_contact['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND]); + $visitor_is_followed = + in_array($visitor_contact['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND]) + || in_array($profile_contact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND]); + $visitor_base_path = self::getMyURL() ? preg_replace('=/profile/(.*)=ism', '', self::getMyURL()) : ''; - // See issue https://github.com/friendica/friendica/issues/3838 - // Either we remove the message link for remote users or we enable creating messages from remote users - if (remote_user() || (self::getMyURL() && !empty($profile['unkmail']) && ($profile['uid'] != local_user()))) { - $wallmessage = L10n::t('Message'); + if (!$local_user_is_self && $show_connect) { + if (!$visitor_is_authenticated) { + $follow_link = 'dfrn_request/' . $profile['nickname']; + } elseif ($profile_is_native) { + if ($visitor_is_following) { + $unfollow_link = $visitor_base_path . '/unfollow?url=' . urlencode($profile_url); + } else { + $follow_link = $visitor_base_path .'/follow?url=' . urlencode($profile_url); + } + } - if (remote_user()) { - $r = q( - "SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d", - intval($profile['uid']), - intval(remote_user()), - intval(Contact::FRIEND) - ); - } else { - $r = q( - "SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d", - intval($profile['uid']), - DBA::escape(Strings::normaliseLink(self::getMyURL())), - intval(Contact::FRIEND) - ); + if ($profile_is_dfrn) { + $subscribe_feed_link = 'dfrn_poll/' . $profile['nickname']; } - if ($r) { - $remote_url = $r[0]['url']; - $message_path = preg_replace('=(.*)/profile/(.*)=ism', '$1/message/new/', $remote_url); - $wallmessage_link = $message_path . base64_encode(defaults($profile, 'addr', '')); - } else if (!empty($profile['nickname'])) { - $wallmessage_link = 'wallmessage/' . $profile['nickname']; + + if (Contact::canReceivePrivateMessages($profile)) { + if ($visitor_is_followed || $visitor_is_following) { + $wallmessage_link = $visitor_base_path . '/message/new/' . base64_encode(defaults($profile, 'addr', '')); + } elseif ($visitor_is_authenticated && !empty($profile['unkmail'])) { + $wallmessage_link = 'wallmessage/' . $profile['nickname']; + } } } // show edit profile to yourself - if (!$is_contact && $profile['uid'] == local_user() && Feature::isEnabled(local_user(), 'multi_profiles')) { - $profile['edit'] = [System::baseUrl() . '/profiles', L10n::t('Profiles'), '', L10n::t('Manage/edit profiles')]; - $r = q( - "SELECT * FROM `profile` WHERE `uid` = %d", - local_user() - ); + 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')]; + $r = q( + "SELECT * FROM `profile` WHERE `uid` = %d", + local_user() + ); - $profile['menu'] = [ - 'chg_photo' => L10n::t('Change profile photo'), - 'cr_new' => L10n::t('Create New Profile'), - 'entries' => [], - ]; + $profile['menu'] = [ + 'chg_photo' => L10n::t('Change profile photo'), + 'cr_new' => L10n::t('Create New Profile'), + 'entries' => [], + ]; - if (DBA::isResult($r)) { - foreach ($r as $rr) { - $profile['menu']['entries'][] = [ - 'photo' => $rr['thumb'], - 'id' => $rr['id'], - 'alt' => L10n::t('Profile Image'), - 'profile_name' => $rr['profile-name'], - 'isdefault' => $rr['is-default'], - 'visibile_to_everybody' => L10n::t('visible to everybody'), - 'edit_visibility' => L10n::t('Edit visibility'), - ]; + if (DBA::isResult($r)) { + foreach ($r as $rr) { + $profile['menu']['entries'][] = [ + 'photo' => $rr['thumb'], + 'id' => $rr['id'], + 'alt' => L10n::t('Profile Image'), + 'profile_name' => $rr['profile-name'], + 'isdefault' => $rr['is-default'], + 'visibile_to_everybody' => L10n::t('visible to everybody'), + 'edit_visibility' => L10n::t('Edit visibility'), + ]; + } } + } else { + $profile['edit'] = [System::baseUrl() . '/profiles/' . $profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')]; + $profile['menu'] = [ + 'chg_photo' => L10n::t('Change profile photo'), + 'cr_new' => null, + 'entries' => [], + ]; } } - if (!$is_contact && $profile['uid'] == local_user() && !Feature::isEnabled(local_user(), 'multi_profiles')) { - $profile['edit'] = [System::baseUrl() . '/profiles/' . $profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')]; - $profile['menu'] = [ - 'chg_photo' => L10n::t('Change profile photo'), - 'cr_new' => null, - 'entries' => [], - ]; - } // Fetch the account type $account_type = Contact::getAccountType($profile); @@ -490,7 +471,7 @@ class Profile 'pending' => false, 'hidden' => false, 'archive' => false, - 'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA], + 'network' => Protocol::FEDERATED, ]); } } @@ -523,10 +504,13 @@ class Profile $o .= Renderer::replaceMacros($tpl, [ '$profile' => $p, '$xmpp' => $xmpp, - '$connect' => $connect, - '$remoteconnect' => $remoteconnect, - '$subscribe_feed' => $subscribe_feed, - '$wallmessage' => $wallmessage, + '$follow' => L10n::t('Follow'), + '$follow_link' => $follow_link, + '$unfollow' => L10n::t('Unfollow'), + '$unfollow_link' => $unfollow_link, + '$subscribe_feed' => L10n::t('Atom feed'), + '$subscribe_feed_link' => $subscribe_feed_link, + '$wallmessage' => L10n::t('Message'), '$wallmessage_link' => $wallmessage_link, '$account_type' => $account_type, '$location' => $location, @@ -996,10 +980,7 @@ class Profile */ public static function getMyURL() { - if (!empty($_SESSION['my_url'])) { - return $_SESSION['my_url']; - } - return null; + return Session::get('my_url'); } /**