From 5dd426f5260bd8bbc74450b1ecc55b132f8dcb14 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 30 Sep 2020 17:30:26 +0000 Subject: [PATCH] Added option to stay on the local machine when clicking on a contact link --- include/conversation.php | 2 +- src/Model/Contact.php | 10 +++++++++- src/Model/Item.php | 4 +--- src/Module/Contact/Hovercard.php | 7 +++++++ src/Module/Settings/Display.php | 5 +++++ view/templates/settings/display.tpl | 1 + view/theme/frio/templates/settings/display.tpl | 1 + 7 files changed, 25 insertions(+), 5 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index b984c3da2..996d02d02 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -734,7 +734,7 @@ function conversation_fetch_comments($thread_items, $pinned) { $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')]; break; case Item::PT_ANNOUNCEMENT: - if (!empty($row['causer-id']) && DI::pConfig()->get(local_user(), 'system', 'display_resharer') ) { + if (!empty($row['causer-id']) && DI::pConfig()->get(local_user(), 'system', 'display_resharer')) { $row['owner-link'] = $row['causer-link']; $row['owner-avatar'] = $row['causer-avatar']; $row['owner-name'] = $row['causer-name']; diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 1ec1424dd..f89945ae3 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -2578,7 +2578,7 @@ class Contact { $destination = $url ?: $contact['url']; // Equivalent to ($url != '') ? $url : $contact['url']; - if (!Session::isAuthenticated() || ($contact['network'] != Protocol::DFRN)) { + if (!Session::isAuthenticated()) { return $destination; } @@ -2587,6 +2587,14 @@ class Contact return $url; } + if (DI::pConfig()->get(local_user(), 'system', 'stay_local') && ($url == '')) { + return 'contact/' . $contact['id'] . '/conversations'; + } + + if ($contact['network'] != Protocol::DFRN) { + return $destination; + } + if (!empty($contact['uid'])) { return self::magicLink($contact['url'], $url); } diff --git a/src/Model/Item.php b/src/Model/Item.php index 1c307c699..c384eb4f9 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -3595,11 +3595,9 @@ class Item DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('videos_head.tpl')); } - $url_parts = explode('/', $the_url); - $id = end($url_parts); $as .= Renderer::replaceMacros(Renderer::getMarkupTemplate('video_top.tpl'), [ '$video' => [ - 'id' => $id, + 'id' => $item['author-id'], 'title' => DI::l10n()->t('View Video'), 'src' => $the_url, 'mime' => $mime, diff --git a/src/Module/Contact/Hovercard.php b/src/Module/Contact/Hovercard.php index 1d2fe8567..c67d6d247 100644 --- a/src/Module/Contact/Hovercard.php +++ b/src/Module/Contact/Hovercard.php @@ -49,6 +49,13 @@ class Hovercard extends BaseModule // the real url (nurl) if (strpos($contact_url, 'redir/') === 0) { $cid = intval(substr($contact_url, 6)); + } + + if (strpos($contact_url, 'contact/') === 0) { + $cid = intval(substr($contact_url, 8)); + } + + if (!empty($cid)) { $remote_contact = Contact::selectFirst(['nurl'], ['id' => $cid]); $contact_url = $remote_contact['nurl'] ?? ''; } diff --git a/src/Module/Settings/Display.php b/src/Module/Settings/Display.php index 443385394..cdafbb1c0 100644 --- a/src/Module/Settings/Display.php +++ b/src/Module/Settings/Display.php @@ -53,6 +53,7 @@ class Display extends BaseSettings $no_smart_threading = !empty($_POST['no_smart_threading']) ? intval($_POST['no_smart_threading']) : 0; $hide_dislike = !empty($_POST['hide_dislike']) ? intval($_POST['hide_dislike']) : 0; $display_resharer = !empty($_POST['display_resharer']) ? intval($_POST['display_resharer']) : 0; + $stay_local = !empty($_POST['stay_local']) ? intval($_POST['stay_local']) : 0; $browser_update = !empty($_POST['browser_update']) ? intval($_POST['browser_update']) : 0; if ($browser_update != -1) { $browser_update = $browser_update * 1000; @@ -87,6 +88,7 @@ class Display extends BaseSettings DI::pConfig()->set(local_user(), 'system', 'no_smart_threading' , $no_smart_threading); DI::pConfig()->set(local_user(), 'system', 'hide_dislike' , $hide_dislike); DI::pConfig()->set(local_user(), 'system', 'display_resharer' , $display_resharer); + DI::pConfig()->set(local_user(), 'system', 'stay_local' , $stay_local); DI::pConfig()->set(local_user(), 'system', 'first_day_of_week' , $first_day_of_week); if (in_array($theme, Theme::getAllowedList())) { @@ -169,6 +171,8 @@ class Display extends BaseSettings $no_smart_threading = DI::pConfig()->get(local_user(), 'system', 'no_smart_threading', 0); $hide_dislike = DI::pConfig()->get(local_user(), 'system', 'hide_dislike', 0); $display_resharer = DI::pConfig()->get(local_user(), 'system', 'display_resharer', 0); + $stay_local = DI::pConfig()->get(local_user(), 'system', 'stay_local', 0); + $first_day_of_week = DI::pConfig()->get(local_user(), 'system', 'first_day_of_week', 0); $weekdays = [0 => DI::l10n()->t("Sunday"), 1 => DI::l10n()->t("Monday")]; @@ -206,6 +210,7 @@ class Display extends BaseSettings '$no_smart_threading' => ['no_smart_threading' , DI::l10n()->t('Disable Smart Threading'), $no_smart_threading, DI::l10n()->t('Disable the automatic suppression of extraneous thread indentation.')], '$hide_dislike' => ['hide_dislike' , DI::l10n()->t('Hide the Dislike feature'), $hide_dislike, DI::l10n()->t('Hides the Dislike button and dislike reactions on posts and comments.')], '$display_resharer' => ['display_resharer' , DI::l10n()->t('Display the resharer'), $display_resharer, DI::l10n()->t('Display the first resharer as icon and text on a reshared item.')], + '$stay_local' => ['stay_local' , DI::l10n()->t('Stay local'), $stay_local, DI::l10n()->t("Don't go to a remote system when following a contact link.")], '$first_day_of_week' => ['first_day_of_week', DI::l10n()->t('Beginning of week:'), $first_day_of_week, '', $weekdays, false], ]); diff --git a/view/templates/settings/display.tpl b/view/templates/settings/display.tpl index 3700c4f54..3d7690830 100644 --- a/view/templates/settings/display.tpl +++ b/view/templates/settings/display.tpl @@ -19,6 +19,7 @@ {{include file="field_checkbox.tpl" field=$no_smart_threading}} {{include file="field_checkbox.tpl" field=$hide_dislike}} {{include file="field_checkbox.tpl" field=$display_resharer}} + {{include file="field_checkbox.tpl" field=$stay_local}}

{{$calendar_title}}

{{include file="field_select.tpl" field=$first_day_of_week}} diff --git a/view/theme/frio/templates/settings/display.tpl b/view/theme/frio/templates/settings/display.tpl index 4ba751836..6e018dfc9 100644 --- a/view/theme/frio/templates/settings/display.tpl +++ b/view/theme/frio/templates/settings/display.tpl @@ -66,6 +66,7 @@ {{include file="field_checkbox.tpl" field=$no_smart_threading}} {{include file="field_checkbox.tpl" field=$hide_dislike}} {{include file="field_checkbox.tpl" field=$display_resharer}} + {{include file="field_checkbox.tpl" field=$stay_local}}