make nav menu available for remote user and friendica visitors

This commit is contained in:
rabuzarus 2016-04-19 02:06:02 +02:00
parent 9dafe525c8
commit 7d175324ee
3 changed files with 114 additions and 14 deletions

View File

@ -186,7 +186,8 @@ header #banner {
font-weight: bold;
whitespace: nowrap;
}
header #banner #logo-img {
header #banner #logo-img,
.navbar-brand #logo-img {
mask: url('img/friendica-logo.svg#logo_mask');
mask-image: url('img/friendica-25.png');
-webkit-mask-image: url('img/friendica-25.png');
@ -196,6 +197,12 @@ header #banner #logo-img {
margin-left: auto;
margin-right: auto;
}
#navbrand-container {
display: flex;
}
#navbrand-container #navbar-brand-text {
padding-left: 5px;
}
/* NavBar */
.topbar {

View File

@ -1,10 +1,16 @@
{{if $userinfo}}
{{* 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 *}}
{{if $nav.userinfo}}
<header>
{{* {{$langselector}} *}}
<div id="site-location">{{$sitelocation}}</div>
<div id="banner" class="hidden-sm hidden-xs">
{{* show on remote/visitor connections an other logo which symols that fact*}}
{{if $nav.remote}}
<a href="{{$baseurl}}"><div id="remote-logo-img"></div></a>
{{else}}
<a href="{{$baseurl}}"><div id="logo-img"></div></a>
{{/if}}
</div>
</header>
<nav id="topbar-first" class="topbar">
@ -97,7 +103,7 @@
{{if $nav.search}}
<li id="search-box" class="hidden-xs">
<form class="navbar-form" role="search" method="get" action="{{$nav.search.0}}">
<!-- <img class="hidden-xs" src="{{$userinfo.icon}}" alt="{{$userinfo.name}}" style="max-width:33px; max-height:33px; min-width:33px; min-height:33px; width:33px; height:33px;"> -->
<!-- <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">
<input id="nav-search-input-field" class="form-control form-search" type="text" name="search" placeholder="Search">
<button class="btn btn-default btn-sm form-button-search" type="submit">Search</button>
@ -107,15 +113,15 @@
{{/if}}
{{* The user dropdown menu *}}
{{if $userinfo}}
{{if $nav.userinfo}}
<li id="nav-user-linkmenu" class="dropdown account nav-menu hidden-xs">
<a href="#" id="main-menu" class="dropdown-toggle nav-avatar " data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<div class="user-title pull-left hidden-xs hidden-sm hidden-md">
<strong>{{$userinfo.name}}</strong>
<strong>{{$nav.userinfo.name}}</strong>
<span id="intro-update" class="nav-intro-badge badge nav-notify"></span>
</div>
<img id="avatar" src="{{$userinfo.icon}}" alt="{{$userinfo.name}}">
<img id="avatar" src="{{$nav.userinfo.icon}}" alt="{{$nav.userinfo.name}}">
<span class="caret"></span>
</a>
@ -159,8 +165,7 @@
<li class="divider"></li>
{{if $nav.logout}}
<li role="menuitem"><a id="nav-logout-link" class="nav-link {{$nav.logout.2}}" href="{{$nav.logout.0}}" title="{{$nav.logout.3}}" ><i class="fa fa fa-sign-out fa-fw"></i> {{$nav.logout.1}}</a></li>
{{/if}}
{{if $nav.login}}
{{else}}
<li role="menuitem"><a id="nav-login-link" class="nav-login-link {{$nav.login.2}}" href="{{$nav.login.0}}" title="{{$nav.login.3}}" ><i class="fa fa-power-off fa-fw"></i> {{$nav.login.1}}</a></li>
{{/if}}
</ul>
@ -177,7 +182,7 @@
<div id="myNavmenu" class="navmenu navmenu-default navmenu-fixed-right offcanvas">
<div class="nav-container">
<div class="list-group">
<li class="list-group-item"><img src="{{$userinfo.icon}}" alt="{{$userinfo.name}}" style="max-width:15px; max-height:15px; min-width:15px; min-height:15px; width:15px; height:15px;"> {{$userinfo.name}}</li>
<li class="list-group-item"><img src="{{$nav.userinfo.icon}}" alt="{{$nav.userinfo.name}}" style="max-width:15px; max-height:15px; min-width:15px; min-height:15px; width:15px; height:15px;"> {{$nav.userinfo.name}}</li>
{{foreach $nav.usermenu as $usermenu}}
<a class="{{$usermenu.2}} list-group-item" href="{{$usermenu.0}}" title="{{$usermenu.3}}">{{$usermenu.1}}</a>
{{/foreach}}
@ -201,8 +206,7 @@
{{/if}}
{{if $nav.logout}}
<a class="nav-link {{$nav.logout.2}} list-group-item" href="{{$nav.logout.0}}" title="{{$nav.logout.3}}" ><i class="fa fa fa-sign-out fa-fw"></i> {{$nav.logout.1}}</a>
{{/if}}
{{if $nav.login}}
{{else}}
<a class="nav-login-link {{$nav.login.2}} list-group-item" href="{{$nav.login.0}}" title="{{$nav.login.3}}" ><i class="fa fa-power-off fa-fw"></i> {{$nav.login.1}}</a>
{{/if}}
</div>
@ -215,12 +219,13 @@
{{* The navbar for users which are not logged in *}}
{{if $userinfo == ''}}
{{if $nav.userinfo == ''}}
<nav class="navbar navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<span><img alt="Brand" src="./view/theme/frio/img/logo.png" width="25" height="25"> Friendica</span>
<a class="navbar-brand" href="#"><div id="navbrand-container">
<div id="logo-img"></div>
<div id="navbar-brand-text"> Friendica</div></div>
</a>
</div>
<div class="hidden-sm hidden-xs">

View File

@ -32,6 +32,7 @@ function frio_init(&$a) {
function frio_install() {
register_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
register_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
register_hook('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
logger("installed theme frio");
}
@ -104,3 +105,90 @@ function frio_item_photo_menu($a, &$arr){
}
$args = array('item' => $item, 'menu' => $menu);
}
/**
* @brief Construct remote nav menu
*
* It creates a remote baseurl form $_SESSION for remote users and friendica
* visitors. This url will be added to some of the nav links. With this behaviour
* the user will come back to her/his own pages on his/her friendica server.
* Not all possible links are available (notifications, administrator, manage,
* notes aren't available because we have no way the check remote permissions)..
* Some links will point to the local pages because the user would expect
* local page (these pages are: search, community, help, apps, directory).
*
* @param app $a The App class
* @param array $nav The original nav menu
*/
function frio_remote_nav($a,&$nav) {
// get the homelink from $_XSESSION
$homelink = get_my_url();
if(! $homelink)
$homelink = ((x($_SESSION,'visitor_home')) ? $_SESSION['visitor_home'] : '');
// split up the url in it's parts (protocol,domain/directory, /profile/, nickname
// I'm not familiar with regex, so someone might find a better solutionen
//
// E.g $homelink = 'https://friendica.domain.com/profile/mickey' should result in an array
// with 0 => 'https://friendica.domain.com/profile/mickey' 1 => 'https://',
// 2 => 'friendica.domain.com' 3 => '/profile/' 4 => 'mickey'
//
//$server_url = preg_match('/^(https?:\/\/.*?)\/profile\//2', $homelink);
preg_match('/^(https?:\/\/)?(.*?)(\/profile\/)(.*)/', $homelink, $url_parts);
// Construct the server url of the visitor. So we could link back to his/her own menu.
// And construct a webbie (e.g. mickey@friendica.domain.com for the search in gcontact
// We use the webbie for search in gcontact because we don't know if gcontact table stores
// the right value if its http or https protocol
if(count($url_parts)) {
$server_url = $url_parts[1] . $url_parts[2];
$webbie = $url_parts[4] . '@' . $url_parts[2];
}
// since $userinfo isn't available for the hook we write it to the nav array
// this isn't optimal because the contact query will be done now twice
if(local_user()) {
// empty the server url for local user because we won't need it
$server_url = '';
// user info
$r = q("SELECT `micro` FROM `contact` WHERE `uid` = %d AND `self` = 1", intval($a->user['uid']));
$r[0]['photo'] = (count($r) ? $a->remove_baseurl($r[0]['micro']) : "images/person-48.jpg");
$r[0]['name'] = $a->user['username'];
} elseif(!local_user() && remote_user()) {
$r = q("SELECT `name`, `nick`, `micro` AS `photo` FROM `contact` WHERE `id` = %d", intval(remote_user()));
$nav['remote'] = 1;
} elseif(get_my_url ()) {
$r = q("SELECT `name`, `nick`, `photo` FROM `gcontact`
WHERE `addr` = '%s' AND `network` = 'dfrn'",
dbesc($webbie));
$nav['remote'] = 1;
}
if(count($r)){
$nav['userinfo'] = array(
'icon' => (count($r) ? $r[0]['photo'] : "images/person-48.jpg"),
'name' => $r['name'],
);
}
if(!local_user() && !empty($server_url)) {
$nav['logout'] = Array($server_url . '/logout',t('Logout'), "", t('End this session'));
// user menu
$nav['usermenu'][] = Array($server_url . '/profile/' . $a->user['nickname'], t('Status'), "", t('Your posts and conversations'));
$nav['usermenu'][] = Array($server_url . '/profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
$nav['usermenu'][] = Array($server_url . '/photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
$nav['usermenu'][] = Array($server_url . '/videos/' . $a->user['nickname'], t('Videos'), "", t('Your videos'));
$nav['usermenu'][] = Array($server_url . '/events/', t('Events'), "", t('Your events'));
// navbar links
$nav['network'] = array($server_url . '/network', t('Network'), "", t('Conversations from your friends'));
$nav['events'] = Array($server_url . '/events', t('Events'), "", t('Events and Calendar'));
$nav['messages'] = array($server_url . '/message', t('Messages'), "", t('Private mail'));
$nav['settings'] = array($server_url . '/settings', t('Settings'),"", t('Account settings'));
$nav['contacts'] = array($server_url . '/contacts', t('Contacts'),"", t('Manage/edit friends and contacts'));
}
}