From ddb093ec48ea0beaedab6b7b13113b56415a88c1 Mon Sep 17 00:00:00 2001 From: slawkens Date: Wed, 19 Jul 2023 11:57:26 +0200 Subject: [PATCH 1/4] Fix highscores if there is only 1 record --- system/pages/highscores.php | 1 - system/templates/highscores.html.twig | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/system/pages/highscores.php b/system/pages/highscores.php index 95647893..dd2efa7b 100644 --- a/system/pages/highscores.php +++ b/system/pages/highscores.php @@ -311,7 +311,6 @@ if(config('highscores_balance')) /** @var Twig\Environment $twig */ $twig->display('highscores.html.twig', [ 'highscores' => $highscores, - 'totalRows' => $i - 1, 'list' => $list, 'skill' => $skill, 'skillName' => ($skill == SKILL_FRAGS ? 'Frags' : ($skill == SKILL_BALANCE ? 'Balance' : getSkillName($skill))), diff --git a/system/templates/highscores.html.twig b/system/templates/highscores.html.twig index 3b9224e2..2e32b7de 100644 --- a/system/templates/highscores.html.twig +++ b/system/templates/highscores.html.twig @@ -48,7 +48,7 @@ {% endif %} - {% if totalRows < 1 %} + {% if highscores|length < 1 %} No records yet. {% else %} {% set row = 0 %} From 99c53c75f28f5d9f871c1f9200f750a37f0a223e Mon Sep 17 00:00:00 2001 From: slawkens Date: Wed, 19 Jul 2023 22:26:47 +0200 Subject: [PATCH 2/4] New guild hooks, for some upcoming big feature ;) --- system/hooks.php | 4 ++++ system/templates/guilds.view.html.twig | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/system/hooks.php b/system/hooks.php index f089b102..69bdcfbd 100644 --- a/system/hooks.php +++ b/system/hooks.php @@ -69,6 +69,10 @@ define('HOOK_ADMIN_LOGIN_AFTER_PASSWORD', ++$i); define('HOOK_ADMIN_LOGIN_AFTER_SIGN_IN', ++$i); define('HOOK_ADMIN_ACCOUNTS_SAVE_POST', ++$i); define('HOOK_EMAIL_CONFIRMED', ++$i); +define('HOOK_GUILDS_BEFORE_GUILD_HEADER', ++$i); +define('HOOK_GUILDS_AFTER_GUILD_HEADER', ++$i); +define('HOOK_GUILDS_AFTER_GUILD_INFORMATION', ++$i); +define('HOOK_GUILDS_AFTER_GUILD_MEMBERS', ++$i); define('HOOK_GUILDS_AFTER_INVITED_CHARACTERS', ++$i); const HOOK_FIRST = HOOK_STARTUP; diff --git a/system/templates/guilds.view.html.twig b/system/templates/guilds.view.html.twig index 5fef92e7..494b803d 100644 --- a/system/templates/guilds.view.html.twig +++ b/system/templates/guilds.view.html.twig @@ -1,6 +1,7 @@
+ {{ hook('HOOK_GUILDS_BEFORE_GUILD_HEADER') }} @@ -16,7 +17,9 @@
-
+
+ + {{ hook('HOOK_GUILDS_AFTER_GUILD_HEADER') }} @@ -83,8 +86,10 @@
+
+ + {{ hook('HOOK_GUILDS_AFTER_GUILD_INFORMATION') }} -
@@ -193,7 +198,9 @@
-
+
+ + {{ hook('HOOK_GUILDS_AFTER_GUILD_MEMBERS') }}
@@ -263,9 +270,9 @@
-
+
- {{ hook(constant('HOOK_GUILDS_AFTER_INVITED_CHARACTERS'), { 'guild': guild, 'isLeader': isLeader }) }} + {{ hook('HOOK_GUILDS_AFTER_INVITED_CHARACTERS') }}
From 9f67cab5036a4eb623927f0b7c11aaddb6ce0908 Mon Sep 17 00:00:00 2001 From: slawkens Date: Wed, 19 Jul 2023 22:40:11 +0200 Subject: [PATCH 3/4] Add twig context for twig hook() function Allows to use variables from template inside the hook file with usage of $context variable --- system/twig.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/system/twig.php b/system/twig.php index 65e6ded0..4fc7c5ec 100644 --- a/system/twig.php +++ b/system/twig.php @@ -90,15 +90,16 @@ $function = new TwigFunction('truncate', function ($s, $n) { }); $twig->addFunction($function); -$function = new TwigFunction('hook', function ($hook, array $params = []) { +$function = new TwigFunction('hook', function ($context, $hook, array $params = []) { global $hooks; if(is_string($hook)) { $hook = constant($hook); } + $params['context'] = $context; $hooks->trigger($hook, $params); -}); +}, ['needs_context' => true]); $twig->addFunction($function); $function = new TwigFunction('config', function ($key) { From e14df529c0a0c01a18907c112ff09d140bc1a896 Mon Sep 17 00:00:00 2001 From: slawkens Date: Wed, 19 Jul 2023 22:40:39 +0200 Subject: [PATCH 4/4] Revert some change --- system/templates/guilds.view.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/templates/guilds.view.html.twig b/system/templates/guilds.view.html.twig index 494b803d..f3da843e 100644 --- a/system/templates/guilds.view.html.twig +++ b/system/templates/guilds.view.html.twig @@ -272,7 +272,7 @@
- {{ hook('HOOK_GUILDS_AFTER_INVITED_CHARACTERS') }} + {{ hook('HOOK_GUILDS_AFTER_INVITED_CHARACTERS', { 'guild': guild, 'isLeader': isLeader }) }}