diff --git a/src/Module/Profile/Profile.php b/src/Module/Profile/Profile.php index c187281d3..b1e0673b2 100644 --- a/src/Module/Profile/Profile.php +++ b/src/Module/Profile/Profile.php @@ -112,6 +112,7 @@ class Profile extends BaseProfile $view_as_contacts = []; $view_as_contact_id = 0; + $view_as_contact_alert = ''; if ($is_owner) { $view_as_contact_id = intval($_GET['viewas'] ?? 0); @@ -122,10 +123,20 @@ class Profile extends BaseProfile 'blocked' => false, ]); + $view_as_contact_ids = array_column($view_as_contacts, 'id'); + // User manually provided a contact ID they aren't privy to, silently defaulting to their own view - if (!in_array($view_as_contact_id, array_column($view_as_contacts, 'id'))) { + if (!in_array($view_as_contact_id, $view_as_contact_ids)) { $view_as_contact_id = 0; } + + if (($key = array_search($view_as_contact_id, $view_as_contact_ids)) !== false) { + $view_as_contact_alert = DI::l10n()->t( + 'You\'re currently viewing your profile as %s Cancel', + htmlentities($view_as_contacts[$key]['name'], ENT_COMPAT, 'UTF-8'), + 'profile/' . $parameters['nickname'] . '/profile' + ); + } } $basic_fields = []; @@ -225,7 +236,9 @@ class Profile extends BaseProfile '$title' => DI::l10n()->t('Profile'), '$view_as_contacts' => $view_as_contacts, '$view_as_contact_id' => $view_as_contact_id, + '$view_as_contact_alert' => $view_as_contact_alert, '$view_as' => DI::l10n()->t('View profile as:'), + '$submit' => DI::l10n()->t('Submit'), '$basic' => DI::l10n()->t('Basic'), '$advanced' => DI::l10n()->t('Advanced'), '$is_owner' => $a->profile_uid == local_user(), @@ -238,6 +251,11 @@ class Profile extends BaseProfile 'title' => '', 'label' => DI::l10n()->t('Edit profile') ], + '$viewas_link' => [ + 'url' => DI::args()->getQueryString() . '#viewas', + 'title' => '', + 'label' => DI::l10n()->t('View as') + ], ]); Hook::callAll('profile_advanced', $o); diff --git a/view/templates/profile/index.tpl b/view/templates/profile/index.tpl index 60bf46b99..36b64ffbb 100644 --- a/view/templates/profile/index.tpl +++ b/view/templates/profile/index.tpl @@ -1,3 +1,8 @@ +{{if $view_as_contact_alert}} + +{{/if}}
{{include file="section_title.tpl"}} @@ -10,20 +15,11 @@  {{$edit_link.label}} - {{if count($view_as_contacts)}}
  • -
    - - - -
    + +  {{$viewas_link.label}} +
  • - {{/if}}
    @@ -101,3 +97,17 @@ {{/foreach}} +{{if $is_owner}} +
    +
    + + + +
    +
    +{{/if}}