1
1
Fork 0

Fix undefined variables in nav.tpl

- Reworked the nav_info hook to include the rest of the array keys defined in Nav::getInfo
- Replaced the theme-specific template variable nav.userinfo with the regular userinfo in frio nav.tpl
- Initialized all the nav array keys
This commit is contained in:
Hypolite Petovan 2021-05-10 19:03:33 -04:00
parent abc0616d33
commit 43638fa29b
3 changed files with 55 additions and 44 deletions

View file

@ -144,9 +144,9 @@ class Nav
* array 'userinfo' => Array of user information (name, icon) * array 'userinfo' => Array of user information (name, icon)
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
private static function getInfo(App $a) private static function getInfo(App $a): array
{ {
$ssl_state = ((local_user()) ? true : false); $ssl_state = (bool) local_user();
/* /*
* Our network is distributed, and as you visit friends some of the * Our network is distributed, and as you visit friends some of the
@ -158,13 +158,27 @@ class Nav
$sitelocation = $myident . substr(DI::baseUrl()->get($ssl_state), strpos(DI::baseUrl()->get($ssl_state), '//') + 2); $sitelocation = $myident . substr(DI::baseUrl()->get($ssl_state), strpos(DI::baseUrl()->get($ssl_state), '//') + 2);
// nav links: array of array('href', 'text', 'extra css classes', 'title') $nav = [
$nav = []; 'admin' => null,
'apps' => null,
'community' => null,
'home' => null,
'events' => null,
'login' => null,
'logout' => null,
'langselector' => null,
'messages' => null,
'network' => null,
'notifications' => null,
'remote' => null,
'search' => null,
'usermenu' => [],
];
// Display login or logout // Display login or logout
$nav['usermenu'] = [];
$userinfo = null; $userinfo = null;
// nav links: array of array('href', 'text', 'extra css classes', 'title')
if (Session::isAuthenticated()) { if (Session::isAuthenticated()) {
$nav['logout'] = ['logout', DI::l10n()->t('Logout'), '', DI::l10n()->t('End this session')]; $nav['logout'] = ['logout', DI::l10n()->t('Logout'), '', DI::l10n()->t('End this session')];
} else { } else {
@ -297,13 +311,15 @@ class Nav
$banner = '<a href="https://friendi.ca"><img id="logo-img" src="images/friendica-32.png" alt="logo" /></a><span id="logo-text"><a href="https://friendi.ca">Friendica</a></span>'; $banner = '<a href="https://friendi.ca"><img id="logo-img" src="images/friendica-32.png" alt="logo" /></a><span id="logo-text"><a href="https://friendi.ca">Friendica</a></span>';
} }
Hook::callAll('nav_info', $nav); $nav_info = [
return [
'sitelocation' => $sitelocation,
'nav' => $nav,
'banner' => $banner, 'banner' => $banner,
'nav' => $nav,
'sitelocation' => $sitelocation,
'userinfo' => $userinfo, 'userinfo' => $userinfo,
]; ];
Hook::callAll('nav_info', $nav_info);
return $nav_info;
} }
} }

View file

@ -1,11 +1,11 @@
{{* we have modified the navmenu (look at function frio_remote_nav() ) to have remote links. $nav.userinfo is a new variable and replaces the original $userinfo variable *}} {{* we have modified the navmenu (look at function frio_remote_nav() ) to have remote links. *}}
{{if $nav.userinfo}} {{if $userinfo}}
<header> <header>
{{* {{$langselector}} *}} {{* {{$langselector}} *}}
<div id="site-location">{{$sitelocation}}</div> <div id="site-location">{{$sitelocation}}</div>
<div id="banner" class="hidden-sm hidden-xs"> <div id="banner" class="hidden-sm hidden-xs">
{{* show on remote/visitor connections an other logo which symols that fact*}} {{* show on remote/visitor connections an other logo which symbols that fact*}}
{{if $nav.remote}} {{if $nav.remote}}
<a href="{{$baseurl}}"> <a href="{{$baseurl}}">
<div id="remote-logo-img" aria-label="{{$home}}"></div> <div id="remote-logo-img" aria-label="{{$home}}"></div>
@ -141,7 +141,6 @@
{{if $nav.search}} {{if $nav.search}}
<li id="search-box" class="hidden-xs"> <li id="search-box" class="hidden-xs">
<form class="navbar-form" role="search" method="get" action="{{$nav.search.0}}"> <form class="navbar-form" role="search" method="get" action="{{$nav.search.0}}">
<!-- <img class="hidden-xs" src="{{$nav.userinfo.icon}}" alt="{{$nav.userinfo.name}}" style="max-width:33px; max-height:33px; min-width:33px; min-height:33px; width:33px; height:33px;"> -->
<div class="form-group form-group-search"> <div class="form-group form-group-search">
<input accesskey="s" id="nav-search-input-field" class="form-control form-search" <input accesskey="s" id="nav-search-input-field" class="form-control form-search"
type="text" name="q" data-toggle="tooltip" title="{{$search_hint}}" type="text" name="q" data-toggle="tooltip" title="{{$search_hint}}"
@ -154,17 +153,17 @@
{{/if}} {{/if}}
{{* The user dropdown menu *}} {{* The user dropdown menu *}}
{{if $nav.userinfo}} {{if $userinfo}}
<li id="nav-user-linkmenu" class="dropdown account nav-menu hidden-xs"> <li id="nav-user-linkmenu" class="dropdown account nav-menu hidden-xs">
<button accesskey="u" id="main-menu" class="btn-link dropdown-toggle nav-avatar" <button accesskey="u" id="main-menu" class="btn-link dropdown-toggle nav-avatar"
data-toggle="dropdown" type="button" aria-haspopup="true" aria-expanded="false" data-toggle="dropdown" type="button" aria-haspopup="true" aria-expanded="false"
aria-controls="nav-user-menu"> aria-controls="nav-user-menu">
<div aria-hidden="true" class="user-title pull-left hidden-xs hidden-sm hidden-md"> <div aria-hidden="true" class="user-title pull-left hidden-xs hidden-sm hidden-md">
<strong>{{$nav.userinfo.name}}</strong><br> <strong>{{$userinfo.name}}</strong><br>
{{if $nav.remote}}<span class="trunctate">{{$nav.remote}}</span>{{/if}} {{if $nav.remote}}<span class="trunctate">{{$nav.remote}}</span>{{/if}}
</div> </div>
<img id="avatar" src="{{$nav.userinfo.icon}}" alt="{{$nav.userinfo.name}}"> <img id="avatar" src="{{$userinfo.icon}}" alt="{{$userinfo.name}}">
<span class="caret"></span> <span class="caret"></span>
</button> </button>
@ -300,9 +299,9 @@
{{/if}} {{/if}}
{{/if}} {{/if}}
<li role="presentation" class="list-group-item"> <li role="presentation" class="list-group-item">
<img src="{{$nav.userinfo.icon}}" alt="{{$nav.userinfo.name}}" <img src="{{$userinfo.icon}}" alt="{{$userinfo.name}}"
style="max-width:15px; max-height:15px; min-width:15px; min-height:15px; width:15px; height:15px;"> style="max-width:15px; max-height:15px; min-width:15px; min-height:15px; width:15px; height:15px;">
{{$nav.userinfo.name}}{{if $nav.remote}} ({{$nav.remote}}){{/if}} {{$userinfo.name}}{{if $nav.remote}} ({{$nav.remote}}){{/if}}
</li> </li>
{{foreach $nav.usermenu as $usermenu}} {{foreach $nav.usermenu as $usermenu}}
<li role="menuitem" class="list-group-item"><a role="menuitem" class="{{$usermenu.2}}" <li role="menuitem" class="list-group-item"><a role="menuitem" class="{{$usermenu.2}}"
@ -369,11 +368,8 @@
</div><!-- end of div for navbar width--> </div><!-- end of div for navbar width-->
</div><!-- /.container --> </div><!-- /.container -->
</nav><!-- /.navbar --> </nav><!-- /.navbar -->
{{/if}} {{else}}
{{* The navbar for users which are not logged in *}}
{{* The navbar for users which are not logged in *}}
{{if $nav.userinfo == ''}}
<nav class="navbar navbar-fixed-top"> <nav class="navbar navbar-fixed-top">
<div class="container"> <div class="container">
<div class="navbar-header pull-left"> <div class="navbar-header pull-left">
@ -402,14 +398,12 @@
</div> </div>
</div> </div>
</nav> </nav>
{{/if}} {{/if}}
{{* provide a a search input for mobile view, which expands by pressing the search icon *}} {{* provide a a search input for mobile view, which expands by pressing the search icon *}}
<div id="search-mobile" class="hidden-lg hidden-md hidden-sm collapse row well"> <div id="search-mobile" class="hidden-lg hidden-md hidden-sm collapse row well">
<div class="col-xs-12"> <div class="col-xs-12">
<form class="navbar-form" role="search" method="get" action="{{$nav.search.0}}"> <form class="navbar-form" role="search" method="get" action="{{$nav.search.0}}">
<!-- <img class="hidden-xs" src="{{$nav.userinfo.icon}}" alt="{{$nav.userinfo.name}}" style="max-width:33px; max-height:33px; min-width:33px; min-height:33px; width:33px; height:33px;"> -->
<div class="form-group form-group-search"> <div class="form-group form-group-search">
<input id="nav-search-input-field-mobile" class="form-control form-search" type="text" name="q" <input id="nav-search-input-field-mobile" class="form-control form-search" type="text" name="q"
data-toggle="tooltip" title="{{$search_hint}}" placeholder="{{$nav.search.1}}"> data-toggle="tooltip" title="{{$search_hint}}" placeholder="{{$nav.search.1}}">

View file

@ -187,9 +187,10 @@ function frio_contact_photo_menu(App $a, &$args)
* local page (these pages are: search, community, help, apps, directory). * local page (these pages are: search, community, help, apps, directory).
* *
* @param App $a The App class * @param App $a The App class
* @param array $nav The original nav menu * @param array $nav_info The original nav info array: nav, banner, userinfo, sitelocation
* @throws Exception
*/ */
function frio_remote_nav(App $a, array &$nav) function frio_remote_nav(App $a, array &$nav_info)
{ {
// get the homelink from $_XSESSION // get the homelink from $_XSESSION
$homelink = Model\Profile::getMyURL(); $homelink = Model\Profile::getMyURL();
@ -204,16 +205,16 @@ function frio_remote_nav(App $a, array &$nav)
$remoteUser = Contact::selectFirst($fields, ['uid' => $a->user['uid'], 'self' => true]); $remoteUser = Contact::selectFirst($fields, ['uid' => $a->user['uid'], 'self' => true]);
} elseif (!local_user() && remote_user()) { } elseif (!local_user() && remote_user()) {
$remoteUser = Contact::getById(remote_user(), $fields); $remoteUser = Contact::getById(remote_user(), $fields);
$nav['remote'] = DI::l10n()->t('Guest'); $nav_info['nav']['remote'] = DI::l10n()->t('Guest');
} elseif (Model\Profile::getMyURL()) { } elseif (Model\Profile::getMyURL()) {
$remoteUser = Contact::getByURL($homelink, null, $fields); $remoteUser = Contact::getByURL($homelink, null, $fields);
$nav['remote'] = DI::l10n()->t('Visitor'); $nav_info['nav']['remote'] = DI::l10n()->t('Visitor');
} else { } else {
$remoteUser = null; $remoteUser = null;
} }
if (DBA::isResult($remoteUser)) { if (DBA::isResult($remoteUser)) {
$nav['userinfo'] = [ $nav_info['userinfo'] = [
'icon' => Contact::getMicro($remoteUser), 'icon' => Contact::getMicro($remoteUser),
'name' => $remoteUser['name'], 'name' => $remoteUser['name'],
]; ];
@ -222,19 +223,19 @@ function frio_remote_nav(App $a, array &$nav)
if (!local_user() && !empty($server_url) && !is_null($remoteUser)) { if (!local_user() && !empty($server_url) && !is_null($remoteUser)) {
// user menu // user menu
$nav['usermenu'][] = [$server_url . '/profile/' . $remoteUser['nick'], DI::l10n()->t('Status'), '', DI::l10n()->t('Your posts and conversations')]; $nav_info['nav']['usermenu'][] = [$server_url . '/profile/' . $remoteUser['nick'], DI::l10n()->t('Status'), '', DI::l10n()->t('Your posts and conversations')];
$nav['usermenu'][] = [$server_url . '/profile/' . $remoteUser['nick'] . '/profile', DI::l10n()->t('Profile'), '', DI::l10n()->t('Your profile page')]; $nav_info['nav']['usermenu'][] = [$server_url . '/profile/' . $remoteUser['nick'] . '/profile', DI::l10n()->t('Profile'), '', DI::l10n()->t('Your profile page')];
$nav['usermenu'][] = [$server_url . '/photos/' . $remoteUser['nick'], DI::l10n()->t('Photos'), '', DI::l10n()->t('Your photos')]; $nav_info['nav']['usermenu'][] = [$server_url . '/photos/' . $remoteUser['nick'], DI::l10n()->t('Photos'), '', DI::l10n()->t('Your photos')];
$nav['usermenu'][] = [$server_url . '/videos/' . $remoteUser['nick'], DI::l10n()->t('Videos'), '', DI::l10n()->t('Your videos')]; $nav_info['nav']['usermenu'][] = [$server_url . '/videos/' . $remoteUser['nick'], DI::l10n()->t('Videos'), '', DI::l10n()->t('Your videos')];
$nav['usermenu'][] = [$server_url . '/events/', DI::l10n()->t('Events'), '', DI::l10n()->t('Your events')]; $nav_info['nav']['usermenu'][] = [$server_url . '/events/', DI::l10n()->t('Events'), '', DI::l10n()->t('Your events')];
// navbar links // navbar links
$nav['network'] = [$server_url . '/network', DI::l10n()->t('Network'), '', DI::l10n()->t('Conversations from your friends')]; $nav_info['nav']['network'] = [$server_url . '/network', DI::l10n()->t('Network'), '', DI::l10n()->t('Conversations from your friends')];
$nav['events'] = [$server_url . '/events', DI::l10n()->t('Events'), '', DI::l10n()->t('Events and Calendar')]; $nav_info['nav']['events'] = [$server_url . '/events', DI::l10n()->t('Events'), '', DI::l10n()->t('Events and Calendar')];
$nav['messages'] = [$server_url . '/message', DI::l10n()->t('Messages'), '', DI::l10n()->t('Private mail')]; $nav_info['nav']['messages'] = [$server_url . '/message', DI::l10n()->t('Messages'), '', DI::l10n()->t('Private mail')];
$nav['settings'] = [$server_url . '/settings', DI::l10n()->t('Settings'), '', DI::l10n()->t('Account settings')]; $nav_info['nav']['settings'] = [$server_url . '/settings', DI::l10n()->t('Settings'), '', DI::l10n()->t('Account settings')];
$nav['contacts'] = [$server_url . '/contact', DI::l10n()->t('Contacts'), '', DI::l10n()->t('Manage/edit friends and contacts')]; $nav_info['nav']['contacts'] = [$server_url . '/contact', DI::l10n()->t('Contacts'), '', DI::l10n()->t('Manage/edit friends and contacts')];
$nav['sitename'] = DI::config()->get('config', 'sitename'); $nav_info['nav']['sitename'] = DI::config()->get('config', 'sitename');
} }
} }