From 966c418634fea94f41f2af870448396981e59893 Mon Sep 17 00:00:00 2001 From: Tadhg Boyle Date: Thu, 23 Mar 2023 20:02:10 -0700 Subject: [PATCH] init work --- .../Default/assets/css/custom.css | 5 + .../panel_templates/Default/forum/forums.tpl | 211 ++++++++++++------ .../Default/forum/forums_new_step_1.tpl | 5 +- .../Default/forum/forums_new_step_2.tpl | 4 +- modules/Forum/classes/Forum.php | 18 +- modules/Forum/pages/panel/forums.php | 124 ++++++---- 6 files changed, 250 insertions(+), 117 deletions(-) diff --git a/custom/panel_templates/Default/assets/css/custom.css b/custom/panel_templates/Default/assets/css/custom.css index 4b7ea5f0ab..a68379d0f4 100644 --- a/custom/panel_templates/Default/assets/css/custom.css +++ b/custom/panel_templates/Default/assets/css/custom.css @@ -469,3 +469,8 @@ footer.sticky-footer { height: 16px; width: 16px; } + +/* Make buttons dimmed when parent table row is not hovered */ +.forumEditingRow:not(:hover) .btn { + opacity: 0.5; +} diff --git a/custom/panel_templates/Default/forum/forums.tpl b/custom/panel_templates/Default/forum/forums.tpl index cc4a40c619..878e31f128 100644 --- a/custom/panel_templates/Default/forum/forums.tpl +++ b/custom/panel_templates/Default/forum/forums.tpl @@ -36,56 +36,123 @@
- {$NEW_FORUM} - {if !count($FORUMS_ARRAY)} -
+ + {$NEW_CATEGORY} + + {if count($CATEGORIES_ARRAY)} +
{/if} {include file='includes/alerts.tpl'} - {if count($FORUMS_ARRAY)} -
- - - {foreach from=$FORUMS_ARRAY item=item name=forum_array} - - - + + + {foreach from=$category.subforums item=subforum} + + + + + {/foreach} + +
- {$item.title}{if $item.parent_forum} - | {$item.parent_forum}{/if}
{$item.description} -
-
- {if $item.up_link} -
- - -
+ {if count($CATEGORIES_ARRAY)} + {foreach from=$CATEGORIES_ARRAY item=category} + + + + + - {/foreach} - -
+ {$category.title} + {if $category.description} +
+ + {$category.description} + {/if} - {if $item.down_link} -
- - -
+
+ + {$NEW_FORUM} + + + {$EDIT} + + {if count($CATEGORIES_ARRAY) > 1} + {/if} - - - -
-
+ + + + +
+ {$subforum.title} + {if $subforum.description} +
+ + {$subforum.description} + + {/if} +
+ + Edit + + {if count($category.subforums) > 1} + + {/if} + + + +
+ {/foreach} {else} -

{$NO_FORUMS}

+

{$NO_FORUMS}

{/if} +{* {if count($FORUMS_ARRAY)}*} +{*
*} +{* *} +{* *} +{* {foreach from=$FORUMS_ARRAY item=item name=forum_array}*} +{* *} +{* *} +{* *} +{* *} +{* {/foreach}*} +{* *} +{*
*} +{* {$item.title}{if $item.parent_forum}*} +{* | {$item.parent_forum}{/if}
{$item.description}*} +{*
*} +{*
*} +{* {if $item.up_link}*} +{*
*} +{* *} +{* *} +{*
*} +{* {/if}*} +{* {if $item.down_link}*} +{*
*} +{* *} +{* *} +{*
*} +{* {/if}*} +{* *} +{*
*} +{*
*} +{*
*} +{* {else}*} +{*

{$NO_FORUMS}

*} +{* {/if}*} +
@@ -109,38 +176,38 @@ {include file='scripts.tpl'} diff --git a/custom/panel_templates/Default/forum/forums_new_step_1.tpl b/custom/panel_templates/Default/forum/forums_new_step_1.tpl index 13ffbbbcbf..c1bfc984f3 100644 --- a/custom/panel_templates/Default/forum/forums_new_step_1.tpl +++ b/custom/panel_templates/Default/forum/forums_new_step_1.tpl @@ -78,6 +78,9 @@
+ {if $PRESELECTED_CATEGORY} + + {/if}
@@ -132,4 +135,4 @@ - \ No newline at end of file + diff --git a/custom/panel_templates/Default/forum/forums_new_step_2.tpl b/custom/panel_templates/Default/forum/forums_new_step_2.tpl index a16c7069c9..adb4684c40 100644 --- a/custom/panel_templates/Default/forum/forums_new_step_2.tpl +++ b/custom/panel_templates/Default/forum/forums_new_step_2.tpl @@ -55,7 +55,7 @@ @@ -152,4 +152,4 @@ - \ No newline at end of file + diff --git a/modules/Forum/classes/Forum.php b/modules/Forum/classes/Forum.php index 1c8b862457..1c7c951028 100644 --- a/modules/Forum/classes/Forum.php +++ b/modules/Forum/classes/Forum.php @@ -796,11 +796,11 @@ public function getAnySubforums( * @return array An array of the ids of the labels the user has access to */ public static function getAccessibleLabels(array $labels, array $user_groups): array { - return array_reduce($labels, function(&$prev, $topic_label) use ($user_groups) { + return array_reduce($labels, static function (&$prev, $topic_label) use ($user_groups) { $label = DB::getInstance()->get('forums_topic_labels', ['id', $topic_label])->first(); if ($label) { $label_group_ids = explode(',', $label->gids); - $hasPerm = array_reduce($user_groups, fn($prev, $group_id) => $prev || in_array($group_id, $label_group_ids)); + $hasPerm = array_reduce($user_groups, static fn ($prev, $group_id) => $prev || in_array($group_id, $label_group_ids)); if ($hasPerm) { $prev[] = $label->id; } @@ -808,4 +808,18 @@ public static function getAccessibleLabels(array $labels, array $user_groups): a return $prev; }, []); } + + public function recursiveGetSubForums(int $parent_id, array $current = []): array { + $forums = $this->_db->query( + 'SELECT * FROM nl2_forums WHERE parent = ? ORDER BY forum_order', + [$parent_id] + ); + if ($forums->count()) { + foreach ($forums->results() as $forum) { + $current[$parent_id][] = $forum; + $current = $this->recursiveGetSubForums($forum->id, $current); + } + } + return $current; + } } diff --git a/modules/Forum/pages/panel/forums.php b/modules/Forum/pages/panel/forums.php index 8667c67857..e3e5823f30 100644 --- a/modules/Forum/pages/panel/forums.php +++ b/modules/Forum/pages/panel/forums.php @@ -20,56 +20,87 @@ const PANEL_PAGE = 'forums'; $page_title = $forum_language->get('forum', 'forums'); require_once(ROOT_PATH . '/core/templates/backend_init.php'); +$forum = new Forum(); if (!isset($_GET['action']) && !isset($_GET['forum'])) { - $forums = DB::getInstance()->orderAll('forums', 'forum_order', 'ASC')->results(); - $template_array = []; - - if (count($forums)) { - $i = 1; - $count = count($forums); - foreach ($forums as $item) { - if ($item->parent > 0) { - $parent_forum_query = DB::getInstance()->get('forums', ['id', $item->parent])->results(); - if (count($parent_forum_query)) { - $parent_forum_count = 1; - $parent_forum = $forum_language->get('forum', 'parent_forum_x', ['forum' => Output::getClean($parent_forum_query[0]->forum_title)]); - $id = $parent_forum_query[0]->parent; - - while ($parent_forum_count < 100 && $id > 0) { - $parent_forum_query = DB::getInstance()->get('forums', ['id', $parent_forum_query[0]->parent])->results(); - $id = $parent_forum_query[0]->parent; - $parent_forum_count++; - } - } else { - $parent_forum = null; - $parent_forum_count = 0; - } - } else { - $parent_forum_count = 0; - } - - $template_array[] = [ - 'edit_link' => URL::build('/panel/forums/', 'forum=' . Output::getClean($item->id)), - 'delete_link' => URL::build('/panel/forums/', 'action=delete&fid=' . Output::getClean($item->id)), - 'up_link' => ($i > 1 ? URL::build('/panel/forums/', 'action=order&dir=up&fid=' . Output::getClean($item->id)) : null), - 'down_link' => ($i < $count ? URL::build('/panel/forums/', 'action=order&dir=down&fid=' . Output::getClean($item->id)) : null), - 'title' => Output::getClean($item->forum_title), - 'description' => Output::getPurified($item->forum_description), - 'id' => Output::getClean($item->id), - 'parent_forum' => (($item->parent > 0) ? $parent_forum : null), - 'parent_forum_count' => $parent_forum_count + $categories_array = []; + $categories = DB::getInstance()->query("SELECT * FROM nl2_forums WHERE forum_type = 'category' AND parent = 0 ORDER BY forum_order")->results(); + foreach ($categories as $category) { + $subforums = $forum->recursiveGetSubForums($category->id); + $subforums_array = []; + + foreach ($subforums as $parent_id => $subforum) { + $subforum = $subforum[0]; + $subforums_array[] = [ + 'title' => $subforum->forum_title, + 'description' => $subforum->forum_description, + 'edit_link' => URL::build('/panel/forums/', 'forum=' . $subforum->id), + 'delete_link' => URL::build('/panel/forums/', 'action=delete&fid=' . $subforum->id), ]; - $i++; } + + $categories_array[] = [ + 'title' => $category->forum_title, + 'description' => $category->forum_description, + 'subforums' => $subforums_array, + 'new_forum_link' => URL::build('/panel/forums/', 'action=new&category=' . $category->id), + 'edit_link' => URL::build('/panel/forums/', 'forum=' . $category->id), + 'delete_link' => URL::build('/panel/forums/', 'action=delete&fid=' . $category->id), + ]; } + $smarty->assign([ + 'CATEGORIES_ARRAY' => $categories_array, + ]); + +// $forums = DB::getInstance()->orderAll('forums', 'forum_order', 'ASC')->results(); +// $template_array = []; +// $i = 1; +// $count = count($forums); +// +// foreach ($forums as $item) { +// if ($item->parent > 0) { +// $parent_forum_query = DB::getInstance()->get('forums', ['id', $item->parent])->results(); +// if (count($parent_forum_query)) { +// $parent_forum_count = 1; +// $parent_forum = $forum_language->get('forum', 'parent_forum_x', ['forum' => Output::getClean($parent_forum_query[0]->forum_title)]); +// $id = $parent_forum_query[0]->parent; +// +// while ($parent_forum_count < 100 && $id > 0) { +// $parent_forum_query = DB::getInstance()->get('forums', ['id', $parent_forum_query[0]->parent])->results(); +// $id = $parent_forum_query[0]->parent; +// $parent_forum_count++; +// } +// } else { +// $parent_forum = null; +// $parent_forum_count = 0; +// } +// } else { +// $parent_forum_count = 0; +// } +// +// $template_array[] = [ +// 'edit_link' => URL::build('/panel/forums/', 'forum=' . Output::getClean($item->id)), +// 'delete_link' => URL::build('/panel/forums/', 'action=delete&fid=' . Output::getClean($item->id)), +// 'up_link' => ($i > 1 ? URL::build('/panel/forums/', 'action=order&dir=up&fid=' . Output::getClean($item->id)) : null), +// 'down_link' => ($i < $count ? URL::build('/panel/forums/', 'action=order&dir=down&fid=' . Output::getClean($item->id)) : null), +// 'title' => Output::getClean($item->forum_title), +// 'description' => Output::getPurified($item->forum_description), +// 'id' => Output::getClean($item->id), +// 'parent_forum' => (($item->parent > 0) ? $parent_forum : null), +// 'parent_forum_count' => $parent_forum_count +// ]; +// $i++; +// } + $forum_reactions = Util::getSetting('forum_reactions'); $smarty->assign([ + 'NEW_CATEGORY' => $forum_language->get('forum', 'new_category'), + 'NEW_CATEGORY_LINK' => URL::build('/panel/forums/', 'action=new_category'), 'NEW_FORUM' => $forum_language->get('forum', 'new_forum'), - 'NEW_FORUM_LINK' => URL::build('/panel/forums/', 'action=new'), - 'FORUMS_ARRAY' => $template_array, + 'EDIT' => $language->get('general', 'edit'), + // 'FORUMS_ARRAY' => $template_array, 'NO_FORUMS' => $forum_language->get('forum', 'no_forums'), 'REORDER_DRAG_URL' => URL::build('/panel/forums') ]); @@ -143,6 +174,12 @@ } } + if (isset($_GET['category'])) { + $smarty->assign([ + 'PRESELECTED_CATEGORY' => $_GET['category'] + ]); + } + $smarty->assign([ 'FORUM_TYPE' => $forum_language->get('forum', 'forum_type'), 'FORUM_TYPE_FORUM' => $forum_language->get('forum', 'forum_type_forum'), @@ -246,6 +283,13 @@ } } } + + if (isset($_POST['preselected_category'])) { + $smarty->assign([ + 'PRESELECTED_CATEGORY' => $_POST['preselected_category'] + ]); + } + $smarty->assign([ 'SELECT_PARENT_FORUM' => $forum_language->get('forum', 'select_a_parent_forum'), 'PARENT_FORUMS' => $template_array,