From fd8844db834b005b3f1813a354e9f2930bee0a0c Mon Sep 17 00:00:00 2001
From: Hypolite Petovan <hypolite@mrpetovan.com>
Date: Tue, 11 Jun 2019 19:41:11 -0400
Subject: [PATCH 1/2] Redirect remote visitors to their own profile after
 logout

---
 src/Module/Logout.php | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/Module/Logout.php b/src/Module/Logout.php
index 4ccba2d744..1f60e6dc19 100644
--- a/src/Module/Logout.php
+++ b/src/Module/Logout.php
@@ -9,6 +9,8 @@ use Friendica\BaseModule;
 use Friendica\Core\Authentication;
 use Friendica\Core\Hook;
 use Friendica\Core\L10n;
+use Friendica\Core\System;
+use Friendica\Model\Profile;
 
 /**
  * Logout module
@@ -22,9 +24,19 @@ class Logout extends BaseModule
 	 */
 	public static function init()
 	{
+		$visitor_home = null;
+		if (remote_user()) {
+			$visitor_home = Profile::getMyURL();
+		}
+
 		Hook::callAll("logging_out");
 		Authentication::deleteSession();
-		info(L10n::t('Logged out.') . EOL);
-		self::getApp()->internalRedirect();
+
+		if ($visitor_home) {
+			System::externalRedirect($visitor_home);
+		} else {
+			info(L10n::t('Logged out.'));
+			self::getApp()->internalRedirect();
+		}
 	}
 }

From 0af10a42b06e5c968ea8de1b6c10b5ce9571908d Mon Sep 17 00:00:00 2001
From: Hypolite Petovan <hypolite@mrpetovan.com>
Date: Tue, 11 Jun 2019 19:42:08 -0400
Subject: [PATCH 2/2] Normalize logout link behavior across themes

---
 src/Content/Nav.php                           | 8 +++++---
 view/theme/duepuntozero/deriv/darkzero.css    | 5 +++--
 view/theme/duepuntozero/deriv/easterbunny.css | 2 +-
 view/theme/duepuntozero/deriv/greenzero.css   | 5 +++--
 view/theme/duepuntozero/deriv/purplezero.css  | 2 +-
 view/theme/duepuntozero/style.css             | 2 +-
 view/theme/frio/theme.php                     | 2 --
 view/theme/vier/style.css                     | 1 +
 view/theme/vier/templates/nav.tpl             | 5 +++++
 9 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/Content/Nav.php b/src/Content/Nav.php
index a63244e856..690af19353 100644
--- a/src/Content/Nav.php
+++ b/src/Content/Nav.php
@@ -148,9 +148,13 @@ class Nav
 		$nav['usermenu'] = [];
 		$userinfo = null;
 
-		if (local_user()) {
+		if (local_user() || remote_user()) {
 			$nav['logout'] = ['logout', L10n::t('Logout'), '', L10n::t('End this session')];
+		} else {
+			$nav['login'] = ['login', L10n::t('Login'), ($a->module == 'login' ? 'selected' : ''), L10n::t('Sign in')];
+		}
 
+		if (local_user()) {
 			// user menu
 			$nav['usermenu'][] = ['profile/' . $a->user['nickname'], L10n::t('Status'), '', L10n::t('Your posts and conversations')];
 			$nav['usermenu'][] = ['profile/' . $a->user['nickname'] . '?tab=profile', L10n::t('Profile'), '', L10n::t('Your profile page')];
@@ -165,8 +169,6 @@ class Nav
 				'icon' => (DBA::isResult($contact) ? $a->removeBaseURL($contact['micro']) : 'images/person-48.jpg'),
 				'name' => $a->user['username'],
 			];
-		} else {
-			$nav['login'] = ['login', L10n::t('Login'), ($a->module == 'login' ? 'selected' : ''), L10n::t('Sign in')];
 		}
 
 		// "Home" should also take you home from an authenticated remote profile connection
diff --git a/view/theme/duepuntozero/deriv/darkzero.css b/view/theme/duepuntozero/deriv/darkzero.css
index 3b6fa92e3b..60e2d9c456 100644
--- a/view/theme/duepuntozero/deriv/darkzero.css
+++ b/view/theme/duepuntozero/deriv/darkzero.css
@@ -50,9 +50,10 @@ nav #banner #logo-text a { color: #ffffff; }
 .photo-album-image-wrapper .caption { background-color: rgba(51, 51, 51, 0.8); color: #FFFFFF; }
 
 .nav-selected.nav-link { color: #ffffff!important; border-bottom: 0px}
-.nav-commlink, .nav-login-link {background-color: #b7bab3;}
+.nav-commlink, .nav-login-link, .nav-logout-link {background-color: #b7bab3;}
 .nav-commlink:link, .nav-commlink:visited,
-.nav-login-link:link, .nav-login-link:visited{
+.nav-login-link:link, .nav-login-link:visited,
+.nav-logout-link:link, .nav-logout-link:visited {
 	color: #ffffff;
 }
 
diff --git a/view/theme/duepuntozero/deriv/easterbunny.css b/view/theme/duepuntozero/deriv/easterbunny.css
index 34bf58f460..4542c285a9 100644
--- a/view/theme/duepuntozero/deriv/easterbunny.css
+++ b/view/theme/duepuntozero/deriv/easterbunny.css
@@ -33,7 +33,7 @@ aside {	background-image: url('imgeasterbunny/border.jpg'); }
 div.wall-item-content-wrapper.shiny {  background-image: url('imgeasterbunny/shiny.png'); }
 
 
-.nav-commlink, .nav-login-link {
+.nav-commlink, .nav-login-link, .nav-logout-link {
 	background-color: #aed3b2;
 
 }
diff --git a/view/theme/duepuntozero/deriv/greenzero.css b/view/theme/duepuntozero/deriv/greenzero.css
index d446a61611..315e8dc6a0 100644
--- a/view/theme/duepuntozero/deriv/greenzero.css
+++ b/view/theme/duepuntozero/deriv/greenzero.css
@@ -4,9 +4,10 @@ a:link, a:visited { color: #549f4f; text-decoration: none; }
 a:hover {text-decoration: underline; }
 
 .nav-selected.nav-link { color: #549f4f!important; border-bottom: 0px}
-.nav-commlink, .nav-login-link {background-color: #aed3b2;}
+.nav-commlink, .nav-login-link, .nav-logout-link {background-color: #aed3b2;}
 .nav-commlink:link, .nav-commlink:visited,
-.nav-login-link:link, .nav-login-link:visited{
+.nav-login-link:link, .nav-login-link:visited,
+.nav-logout-link:link, .nav-logout-link:visited{
 	color: #ffffff;
 }
 
diff --git a/view/theme/duepuntozero/deriv/purplezero.css b/view/theme/duepuntozero/deriv/purplezero.css
index 2971857683..6426bb9257 100644
--- a/view/theme/duepuntozero/deriv/purplezero.css
+++ b/view/theme/duepuntozero/deriv/purplezero.css
@@ -10,7 +10,7 @@ section { 	background-image: url('imgpurplezero/border.jpg'); }
 div.wall-item-content-wrapper.shiny {  background-image: url('imgpurplezero/shiny.png'); }
 
 
-.nav-commlink, .nav-login-link {
+.nav-commlink, .nav-login-link, .nav-logout-link {
 	background-color: #aed3b2;
 
 }
diff --git a/view/theme/duepuntozero/style.css b/view/theme/duepuntozero/style.css
index 7e66570ad5..412899fc77 100644
--- a/view/theme/duepuntozero/style.css
+++ b/view/theme/duepuntozero/style.css
@@ -159,7 +159,7 @@ nav #banner #logo-text a {
 nav #banner #logo-text a:hover { text-decoration: none; }
 
 
-.nav-commlink, .nav-login-link {
+.nav-commlink, .nav-login-link, .nav-logout-link {
 	display: block;
 	height: 15px;
 	margin-top: 67px;
diff --git a/view/theme/frio/theme.php b/view/theme/frio/theme.php
index 9434b340d2..9c4205c886 100644
--- a/view/theme/frio/theme.php
+++ b/view/theme/frio/theme.php
@@ -256,8 +256,6 @@ function frio_remote_nav($a, &$nav)
 	}
 
 	if (!local_user() && !empty($server_url) && !is_null($remoteUser)) {
-		$nav['logout'] = [$server_url . '/logout', L10n::t('Logout'), '', L10n::t('End this session')];
-
 		// user menu
 		$nav['usermenu'][] = [$server_url . '/profile/' . $remoteUser['nick'], L10n::t('Status'), '', L10n::t('Your posts and conversations')];
 		$nav['usermenu'][] = [$server_url . '/profile/' . $remoteUser['nick'] . '?tab=profile', L10n::t('Profile'), '', L10n::t('Your profile page')];
diff --git a/view/theme/vier/style.css b/view/theme/vier/style.css
index 3dc9b46491..6506dadc16 100644
--- a/view/theme/vier/style.css
+++ b/view/theme/vier/style.css
@@ -763,6 +763,7 @@ nav #nav-directory-link,
 nav #nav-apps-link,
 nav #nav-apps-link,
 nav #nav-login-link,
+nav #nav-logout-link,
 nav #nav-messages-linkmenu,
 nav #nav-notifications-linkmenu,
 nav #nav-site-linkmenu,
diff --git a/view/theme/vier/templates/nav.tpl b/view/theme/vier/templates/nav.tpl
index db883433e6..f600b9f615 100644
--- a/view/theme/vier/templates/nav.tpl
+++ b/view/theme/vier/templates/nav.tpl
@@ -102,6 +102,11 @@
 				<a class="{{$nav.login.2}}" href="{{$nav.login.0}}" title="{{$nav.login.3}}" >{{$nav.login.1}}</a>
 			</li>
 		{{/if}}
+		{{if $nav.logout}}
+			<li role="menuitem" id="nav-logout-link" class="nav-menu">
+				<a class="{{$nav.logout.2}}" href="{{$nav.logout.0}}" title="{{$nav.logout.3}}" >{{$nav.logout.1}}</a>
+			</li>
+		{{/if}}
 
 		{{if $nav.search}}
 			<li role="search" id="nav-search-box">