From fac76a33df6ea81717fc1b553257adbc7d8f8b39 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 21 Sep 2023 20:43:14 +0000 Subject: [PATCH] Improved timeline menu --- src/Content/Widget.php | 14 ++++-- src/Module/Conversation/Network.php | 13 +---- src/Module/Settings/Display.php | 47 ++++++++++++++++--- .../theme/frio/templates/settings/display.tpl | 22 ++++++++- 4 files changed, 74 insertions(+), 22 deletions(-) diff --git a/src/Content/Widget.php b/src/Content/Widget.php index 486bada7d5..7078c4fe06 100644 --- a/src/Content/Widget.php +++ b/src/Content/Widget.php @@ -560,16 +560,24 @@ class Widget { $channels = []; + $enabled = DI::pConfig()->get($uid, 'system', 'enabled_timelines', []); + foreach (DI::TimelineFactory()->getNetworkFeeds('') as $channel) { - $channels[] = ['ref' => $channel->code, 'name' => $channel->label]; + if (empty($enabled) || in_array($channel->code, $enabled)) { + $channels[] = ['ref' => $channel->code, 'name' => $channel->label]; + } } foreach (DI::TimelineFactory()->getChannelsForUser($uid) as $channel) { - $channels[] = ['ref' => $channel->code, 'name' => $channel->label]; + if (empty($enabled) || in_array($channel->code, $enabled)) { + $channels[] = ['ref' => $channel->code, 'name' => $channel->label]; + } } foreach (DI::TimelineFactory()->getCommunities(true) as $community) { - $channels[] = ['ref' => $community->code, 'name' => $community->label]; + if (empty($enabled) || in_array($community->code, $enabled)) { + $channels[] = ['ref' => $community->code, 'name' => $community->label]; + } } return self::filter( diff --git a/src/Module/Conversation/Network.php b/src/Module/Conversation/Network.php index 656383b706..40a1b731b6 100644 --- a/src/Module/Conversation/Network.php +++ b/src/Module/Conversation/Network.php @@ -118,25 +118,14 @@ class Network extends Timeline $module = 'network'; - $this->page['aside'] .= Widget::channels($module, $this->selectedTab, $this->session->getLocalUserId()); - $this->page['aside'] .= Widget::accountTypes($module, $this->accountTypeString); - $arr = ['query' => $this->args->getQueryString()]; Hook::callAll('network_content_init', $arr); $o = ''; if ($this->timeline->isChannel($this->selectedTab, $this->session->getLocalUserId())) { - if (!in_array($this->selectedTab, [TimelineEntity::FOLLOWERS, TimelineEntity::FORYOU]) && $this->config->get('system', 'community_no_sharer')) { - $this->page['aside'] .= $this->getNoSharerWidget($module); - } - $items = $this->getChannelItems(); } elseif ($this->timeline->isCommunity($this->selectedTab)) { - if ($this->session->getLocalUserId() && $this->config->get('system', 'community_no_sharer')) { - $this->page['aside'] .= $this->getNoSharerWidget($module); - } - $items = $this->getCommunityItems(); } else { $items = $this->getItems(); @@ -146,6 +135,8 @@ class Network extends Timeline $this->page['aside'] .= GroupManager::widget($module . '/group', $this->session->getLocalUserId(), $this->groupContactId); $this->page['aside'] .= Widget::postedByYear($module . '/archive', $this->session->getLocalUserId(), false); $this->page['aside'] .= Widget::networks($module, !$this->groupContactId ? $this->network : ''); + $this->page['aside'] .= Widget::accountTypes($module, $this->accountTypeString); + $this->page['aside'] .= Widget::channels($module, $this->selectedTab, $this->session->getLocalUserId()); $this->page['aside'] .= Widget\SavedSearches::getHTML($this->args->getQueryString()); $this->page['aside'] .= Widget::fileAs('filed', ''); diff --git a/src/Module/Settings/Display.php b/src/Module/Settings/Display.php index 71c4caed59..bbae7d5990 100644 --- a/src/Module/Settings/Display.php +++ b/src/Module/Settings/Display.php @@ -80,7 +80,8 @@ class Display extends BaseSettings $theme = !empty($request['theme']) ? trim($request['theme']) : $user['theme']; $mobile_theme = !empty($request['mobile_theme']) ? trim($request['mobile_theme']) : ''; $enable_smile = !empty($request['enable_smile']) ? intval($request['enable_smile']) : 0; - $network_timelines = !empty($request['network_timelines']) ? $request['network_timelines'] : []; + $enable = !empty($request['enable']) ? $request['enable'] : []; + $bookmark = !empty($request['bookmark']) ? $request['bookmark'] : []; $channel_languages = !empty($request['channel_languages']) ? $request['channel_languages'] : []; $first_day_of_week = !empty($request['first_day_of_week']) ? intval($request['first_day_of_week']) : 0; $calendar_default_view = !empty($request['calendar_default_view']) ? trim($request['calendar_default_view']) : 'month'; @@ -98,6 +99,20 @@ class Display extends BaseSettings } } + $enabled_timelines = []; + foreach ($enable as $code => $enabled) { + if ($enabled) { + $enabled_timelines[] = $code; + } + } + + $network_timelines = []; + foreach ($bookmark as $code => $bookmarked) { + if ($bookmarked) { + $network_timelines[] = $code; + } + } + $itemspage_network = !empty($request['itemspage_network']) ? intval($request['itemspage_network']) : $this->config->get('system', 'itemspage_network'); @@ -127,6 +142,7 @@ class Display extends BaseSettings $this->pConfig->set($uid, 'system', 'preview_mode' , $preview_mode); $this->pConfig->set($uid, 'system', 'network_timelines' , $network_timelines); + $this->pConfig->set($uid, 'system', 'enabled_timelines' , $enabled_timelines); $this->pConfig->set($uid, 'channel', 'languages' , $channel_languages); $this->pConfig->set($uid, 'calendar', 'first_day_of_week' , $first_day_of_week); @@ -224,10 +240,21 @@ class Display extends BaseSettings BBCode::PREVIEW_LARGE => $this->t('Large Image'), ]; - $network_timelines = $this->pConfig->get($uid, 'system', 'network_timelines', array_keys($this->getAvailableTimelines($uid, true))); + $bookmarked_timelines = $this->pConfig->get($uid, 'system', 'network_timelines', array_keys($this->getAvailableTimelines($uid, true))); + $enabled_timelines = $this->pConfig->get($uid, 'system', 'enabled_timelines', array_keys($this->getAvailableTimelines($uid, false))); + $channel_languages = $this->pConfig->get($uid, 'channel', 'languages', [User::getLanguageCode($uid)]); $languages = $this->l10n->getAvailableLanguages(true); - $timelines = $this->getAvailableTimelines($uid); + + $timelines = []; + foreach ($this->getAvailableTimelines($uid) as $code => $timeline) { + $timelines[] = [ + 'label' => $timeline['label'], + 'description' => $timeline['description'], + 'enable' => ["enable[$code]", '', in_array($code, $enabled_timelines)], + 'bookmark' => ["bookmark[$code]", '', in_array($code, $bookmarked_timelines)], + ]; + } $first_day_of_week = $this->pConfig->get($uid, 'calendar', 'first_day_of_week', 0); $weekdays = [ @@ -284,7 +311,13 @@ class Display extends BaseSettings '$stay_local' => ['stay_local' , $this->t('Stay local'), $stay_local, $this->t("Don't go to a remote system when following a contact link.")], '$preview_mode' => ['preview_mode' , $this->t('Link preview mode'), $preview_mode, $this->t('Appearance of the link preview that is added to each post with a link.'), $preview_modes, false], - '$network_timelines' => ['network_timelines[]', $this->t('Timelines for the network page:'), $network_timelines, $this->t('Select all the timelines that you want to see on your network page.'), $timelines, 'multiple'], + '$timeline_label' => $this->t('Label'), + '$timeline_descriptiom' => $this->t('Description'), + '$timeline_enable' => $this->t('Enable'), + '$timeline_bookmark' => $this->t('Bookmark'), + '$timelines' => $timelines, + '$timeline_explanation' => $this->t('Enable timelines that you want to see in the channels widget. Bookmark timelines that you want to see in the top menu.'), + '$channel_languages' => ['channel_languages[]', $this->t('Channel languages:'), $channel_languages, $this->t('Select all languages that you want to see in your channels.'), $languages, 'multiple'], '$first_day_of_week' => ['first_day_of_week' , $this->t('Beginning of week:') , $first_day_of_week , '', $weekdays , false], @@ -297,7 +330,7 @@ class Display extends BaseSettings $timelines = []; foreach ($this->timeline->getNetworkFeeds('') as $channel) { - $timelines[$channel->code] = $this->t('%s: %s', $channel->label, $channel->description); + $timelines[$channel->code] = ['label' => $channel->label, 'description' => $channel->description]; } if ($only_network) { @@ -305,11 +338,11 @@ class Display extends BaseSettings } foreach ($this->timeline->getChannelsForUser($uid) as $channel) { - $timelines[$channel->code] = $this->t('%s: %s', $channel->label, $channel->description); + $timelines[$channel->code] = ['label' => $channel->label, 'description' => $channel->description]; } foreach ($this->timeline->getCommunities(true) as $community) { - $timelines[$community->code] = $this->t('%s: %s', $community->label, $community->description); + $timelines[$community->code] = ['label' => $community->label, 'description' => $community->description]; } return $timelines; diff --git a/view/theme/frio/templates/settings/display.tpl b/view/theme/frio/templates/settings/display.tpl index f361fe9535..41dd11c10b 100644 --- a/view/theme/frio/templates/settings/display.tpl +++ b/view/theme/frio/templates/settings/display.tpl @@ -84,7 +84,27 @@
- {{include file="field_select.tpl" field=$network_timelines}} + {{$timeline_explanation}} + + + + + + + + + + + {{foreach $timelines as $t}} + + + + + + + {{/foreach}} + +
{{$timeline_label}}{{$timeline_descriptiom}}{{$timeline_enable}}{{$timeline_bookmark}}
{{$t.label}}{{$t.description}}{{include file="field_checkbox.tpl" field=$t.enable}}{{include file="field_checkbox.tpl" field=$t.bookmark}}