]> git.mxchange.org Git - friendica.git/commitdiff
Move "View As" form at the bottom of the profile page
authorHypolite Petovan <hypolite@mrpetovan.com>
Tue, 28 Jul 2020 15:40:14 +0000 (11:40 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Tue, 28 Jul 2020 15:40:14 +0000 (11:40 -0400)
src/Module/Profile/Profile.php
view/templates/profile/index.tpl

index c187281d333dfa711a2ca168f7bc999f1d174183..b1e0673b242496ce8366511466dfbb4a5ff5b92c 100644 (file)
@@ -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 <b>%s</b> <a href="%s" class="btn btn-sm pull-right">Cancel</a>',
+                                       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);
index 60bf46b992e0d89d528c30d3d9bcdaeb4cdb4591..36b64ffbb81a51d250d0ae4d436fa8d1126cd711 100644 (file)
@@ -1,3 +1,8 @@
+{{if $view_as_contact_alert}}
+<div class="alert alert-info" role="alert">
+       {{$view_as_contact_alert nofilter}}
+</div>
+{{/if}}
 <div id="profile-page" class="generic-page-wrapper">
     {{include file="section_title.tpl"}}
 
                                        <i class="fa fa-pencil-square-o" aria-hidden="true"></i>&nbsp;{{$edit_link.label}}
                                </a>
                        </li>
-               {{if count($view_as_contacts)}}
                        <li class="pull-right">
-                               <form action="{{$query_string}}" method="get">
-                                       <button type="submit" class="btn btn-sm">{{$view_as}}</button>
-                                       <select name="viewas" class="input-sm">
-                                               <option value="0">Yourself</option>
-                               {{foreach $view_as_contacts as $contact}}
-                                               <option value="{{$contact.id}}"{{if $contact.id == $view_as_contact_id}} selected{{/if}}>{{$contact.name}}</option>
-                               {{/foreach}}
-                                       </select>
-
-                               </form>
+                               <a class="btn btn-link btn-sm" type="button" id="profile-viewas-link" href="{{$viewas_link.url}}" title="{{$viewas_link.title}}">
+                                       <i class="fa fa-eye" aria-hidden="true"></i>&nbsp;{{$viewas_link.label}}
+                               </a>
                        </li>
-               {{/if}}
                </ul>
                <div class="clear"></div>
        </div>
        </dl>
 {{/foreach}}
 </div>
+{{if $is_owner}}
+<form action="{{$query_string}}" method="get" id="viewas" class="panel panel-default form-inline">
+       <fieldset class="panel-body">
+               <label for="viewas-select">{{$view_as}}</label>
+               <select name="viewas" id="viewas-select" class="form-control">
+                       <option value="0">Yourself</option>
+                       {{foreach $view_as_contacts as $contact}}
+                               <option value="{{$contact.id}}"{{if $contact.id == $view_as_contact_id}} selected{{/if}}>{{$contact.name}}</option>
+                       {{/foreach}}
+               </select>
+               <button type="submit" class="btn btn-primary">{{$submit}}</button>
+       </fieldset>
+</form>
+{{/if}}