From 6845869838f27089d6df51e22c6b4fc6463b308b Mon Sep 17 00:00:00 2001 From: Slawomir Boczek Date: Sun, 27 Apr 2025 17:50:57 +0200 Subject: [PATCH 01/14] Hoping for a better appear in search engines.. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 767911d1..e34e806a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # [MyAAC](https://my-aac.org) -MyAAC is a free and open-source Automatic Account Creator (AAC) written in PHP. It is a fork of the [Gesior](https://github.com/gesior/Gesior2012) project. It supports only MySQL databases. +MyAAC is a free and open-source Automatic Account Creator (AAC) for Open Tibia Servers written in PHP. It is a fork of the [Gesior](https://github.com/gesior/Gesior2012) project. It supports only MySQL databases. Official website: https://my-aac.org From d6ac4e8d85a06a40e43d06c0ca9255c765eb86b0 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 3 May 2025 21:04:13 +0200 Subject: [PATCH 02/14] Update index.php --- index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/index.php b/index.php index 4526e892..bc8a3663 100644 --- a/index.php +++ b/index.php @@ -168,6 +168,7 @@ if ($logged && admin()) { 'username' => USE_ACCOUNT_NAME ? $account_logged->getName() : $account_logged->getId() ]); } + $title_full = (isset($title) ? $title . ' - ' : '') . $config['lua']['serverName']; require $template_path . '/' . $template_index; From 113473f2560aab6d364c301cc14a8b5ba8f309f4 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 3 May 2025 22:04:08 +0200 Subject: [PATCH 03/14] Add optional param _page_only for single-page apps etc. --- system/router.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/system/router.php b/system/router.php index e0bcc04f..b87a843d 100644 --- a/system/router.php +++ b/system/router.php @@ -317,6 +317,11 @@ $content .= ob_get_contents(); ob_end_clean(); $hooks->trigger(HOOK_AFTER_PAGE); +if (isset($_REQUEST['_page_only'])) { + echo $content; + die; +} + if(!isset($title)) { $title = str_replace('index.php/', '', $page); $title = ucfirst($title); From 67ab425bb9796d9d123296e3fda542fa8f7f05ee Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 4 May 2025 09:14:30 +0200 Subject: [PATCH 04/14] Add float & double types to the Settings --- system/settings.php | 2 +- system/src/Settings.php | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/system/settings.php b/system/settings.php index d2c2745b..729527c0 100644 --- a/system/settings.php +++ b/system/settings.php @@ -1473,7 +1473,7 @@ Sent by MyAAC,
], 'status_timeout' => [ 'name' => 'Status Timeout', - 'type' => 'number', + 'type' => 'double', 'min' => 0, 'max' => 10, // more than 10 seconds waiting makes no sense 'step' => 0.1, diff --git a/system/src/Settings.php b/system/src/Settings.php index e243687e..0df8fa81 100644 --- a/system/src/Settings.php +++ b/system/src/Settings.php @@ -219,7 +219,7 @@ class Settings implements \ArrayAccess if ($setting['type'] === 'boolean') { $value = ($setting['default'] ? 'true' : 'false'); } - else if (in_array($setting['type'], ['text', 'number', 'email', 'password', 'textarea'])) { + else if (in_array($setting['type'], ['text', 'number', 'float', 'double', 'email', 'password', 'textarea'])) { $value = $setting['default']; } else if ($setting['type'] === 'options') { @@ -245,7 +245,11 @@ class Settings implements \ArrayAccess $checkbox($key, false, $value); } - else if (in_array($setting['type'], ['text', 'number', 'email', 'password'])) { + else if (in_array($setting['type'], ['text', 'number', 'float', 'double', 'email', 'password'])) { + if (in_array($setting['type'], ['float', 'double'])) { + $setting['type'] = 'number'; + } + if ($setting['type'] === 'number') { $min = (isset($setting['min']) ? ' min="' . $setting['min'] . '"' : ''); $max = (isset($setting['max']) ? ' max="' . $setting['max'] . '"' : ''); @@ -351,7 +355,7 @@ class Settings implements \ArrayAccess if ($setting['type'] === 'boolean') { echo ($setting['default'] ? 'Yes' : 'No'); } - else if (in_array($setting['type'], ['text', 'number', 'email', 'password', 'textarea'])) { + else if (in_array($setting['type'], ['text', 'number', 'float', 'double', 'email', 'password', 'textarea'])) { echo $setting['default']; } else if ($setting['type'] === 'options') { @@ -498,9 +502,12 @@ class Settings implements \ArrayAccess break; case 'number': - if (!isset($ret['step']) || (int)$ret['step'] == 1) { - $ret['value'] = (int)$ret['value']; - } + $ret['value'] = (int)$ret['value']; + break; + + case 'double': + case 'float': + $ret['value'] = (double)($ret['value']); break; default: From f09606d01be00e0055012f7cdfaf4c563d030b62 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 4 May 2025 16:54:49 +0200 Subject: [PATCH 05/14] Just testing something --- robots.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/robots.txt b/robots.txt index eb053628..4738d6a9 100644 --- a/robots.txt +++ b/robots.txt @@ -1,2 +1,3 @@ User-agent: * Disallow: + From 5b1bd4f005594a9bf45de72940d3e2f8d8182176 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 4 May 2025 17:00:22 +0200 Subject: [PATCH 06/14] Update robots.txt --- robots.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/robots.txt b/robots.txt index 4738d6a9..eb053628 100644 --- a/robots.txt +++ b/robots.txt @@ -1,3 +1,2 @@ User-agent: * Disallow: - From beb348fe2749358c7059852d62ebdad28261c552 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 4 May 2025 17:20:12 +0200 Subject: [PATCH 07/14] testing something --- robots.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/robots.txt b/robots.txt index eb053628..4738d6a9 100644 --- a/robots.txt +++ b/robots.txt @@ -1,2 +1,3 @@ User-agent: * Disallow: + From 497338c2d68392b1607eb89129d9d28c737d8f23 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 4 May 2025 17:20:23 +0200 Subject: [PATCH 08/14] Update robots.txt --- robots.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/robots.txt b/robots.txt index 4738d6a9..eb053628 100644 --- a/robots.txt +++ b/robots.txt @@ -1,3 +1,2 @@ User-agent: * Disallow: - From 73a5829974ceca3f02d7925d5cfbd5fa50b1bbd2 Mon Sep 17 00:00:00 2001 From: slawkens Date: Mon, 5 May 2025 21:21:54 +0200 Subject: [PATCH 09/14] Better monster images (no image not found anymore) + use cache --- system/compat/base.php | 4 --- system/functions.php | 16 --------- system/libs/pot/OTS_Monster.php | 34 +++++++++++++----- system/pages/monsters.php | 62 +++++++++++++++++++++++++++------ 4 files changed, 76 insertions(+), 40 deletions(-) diff --git a/system/compat/base.php b/system/compat/base.php index d29c9f3a..5a46ecf2 100644 --- a/system/compat/base.php +++ b/system/compat/base.php @@ -74,7 +74,3 @@ function fieldExist($field, $table) global $db; return $db->hasColumn($table, $field); } - -function getCreatureImgPath($creature): string { - return getMonsterImgPath($creature); -} diff --git a/system/functions.php b/system/functions.php index e0ed8f61..1c96d14a 100644 --- a/system/functions.php +++ b/system/functions.php @@ -1572,22 +1572,6 @@ function right($str, $length) { return substr($str, -$length); } -function getMonsterImgPath($monster): string -{ - $monster_path = setting('core.monsters_images_url'); - $monster_gfx_name = trim(strtolower($monster)) . setting('core.monsters_images_extension'); - if (!file_exists($monster_path . $monster_gfx_name)) { - $monster_gfx_name = str_replace(" ", "", $monster_gfx_name); - if (file_exists($monster_path . $monster_gfx_name)) { - return $monster_path . $monster_gfx_name; - } else { - return $monster_path . 'nophoto.png'; - } - } else { - return $monster_path . $monster_gfx_name; - } -} - function between($x, $lim1, $lim2) { if ($lim1 < $lim2) { $lower = $lim1; $upper = $lim2; diff --git a/system/libs/pot/OTS_Monster.php b/system/libs/pot/OTS_Monster.php index 759375f5..ea20c0e1 100644 --- a/system/libs/pot/OTS_Monster.php +++ b/system/libs/pot/OTS_Monster.php @@ -284,7 +284,7 @@ class OTS_Monster extends DOMDocument */ public function getLook() { - $look = array(); + $look = []; $element = $this->documentElement->getElementsByTagName('look')->item(0); @@ -292,14 +292,30 @@ class OTS_Monster extends DOMDocument return $look; } - $look['type'] = $element->getAttribute('type'); - $look['typeex'] = $element->getAttribute('typeex'); - $look['head'] = $element->getAttribute('head'); - $look['body'] = $element->getAttribute('body'); - $look['legs'] = $element->getAttribute('legs'); - $look['feet'] = $element->getAttribute('feet'); - $look['addons'] = $element->getAttribute('addons'); - $look['corpse'] = $element->getAttribute('corpse'); + if ($element->hasAttribute('typeex')) { + $look['typeEx'] = (int) $element->getAttribute('typeex'); + } + if ($element->hasAttribute('type')) { + $look['type'] = (int) $element->getAttribute('type'); + } + if ($element->hasAttribute('head')) { + $look['head'] = (int) $element->getAttribute('head'); + } + if ($element->hasAttribute('body')) { + $look['body'] = (int) $element->getAttribute('body'); + } + if ($element->hasAttribute('legs')) { + $look['legs'] = (int) $element->getAttribute('legs'); + } + if ($element->hasAttribute('feet')) { + $look['feet'] = (int) $element->getAttribute('feet'); + } + if ($element->hasAttribute('addons')) { + $look['addons'] = (int) $element->getAttribute('addons'); + } + if ($element->hasAttribute('corpse')) { + $look['corpse'] = (int) $element->getAttribute('corpse'); + } return $look; } diff --git a/system/pages/monsters.php b/system/pages/monsters.php index 1678291e..a7d94188 100644 --- a/system/pages/monsters.php +++ b/system/pages/monsters.php @@ -16,18 +16,22 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Monsters'; if (empty($_REQUEST['name'])) { - // display list of monsters $preview = setting('core.monsters_images_preview'); - $monsters = Monster::where('hide', '!=', 1)->when(!empty($_REQUEST['boss']), function ($query) { - $query->where('rewardboss', 1); - })->get()->toArray(); - if ($preview) { - foreach($monsters as $key => &$monster) - { - $monster['img_link'] = getMonsterImgPath($monster['name']); + // display list of monsters + $monsters = MyAAC\Cache::remember('monsters', 30 * 60, function () use ($preview) { + $monsters = Monster::where('hide', '!=', 1)->when(!empty($_REQUEST['boss']), function ($query) { + $query->where('rewardboss', 1); + })->get()->toArray(); + + if ($preview) { + foreach($monsters as &$monster) { + $monster['img_link'] = getMonsterImage($monster); + } } - } + + return $monsters; + }); $twig->display('monsters.html.twig', array( 'monsters' => $monsters, @@ -45,7 +49,7 @@ if ($monsterModel && isset($monsterModel->name)) { /** @var array $monster */ $monster = $monsterModel->toArray(); - function sort_by_chance($a, $b) + function sort_by_chance($a, $b): int { if ($a['chance'] == $b['chance']) { return 0; @@ -55,7 +59,7 @@ if ($monsterModel && isset($monsterModel->name)) { $title = $monster['name'] . " - Monsters"; - $monster['img_link']= getMonsterImgPath($monster_name); + $monster['img_link']= getMonsterImage($monster); $voices = json_decode($monster['voices'], true); $summons = json_decode($monster['summons'], true); @@ -89,3 +93,39 @@ if ($monsterModel && isset($monsterModel->name)) { // back button $twig->display('monsters.back_button.html.twig'); + +function getMonsterImage($monster): string +{ + $outfit = json_decode($monster['look'], true); + + if (!empty($outfit['typeEx'])) { + return setting('core.item_images_url') . $outfit['typeEx'] . setting('core.item_images_extension'); + } + + if (isset($outfit['type'])) { + $getValue = function ($val) use ($outfit) { + return (!empty($outfit[$val]) + ? '&' . $val . '=' . $outfit[$val] : ''); + }; + + return setting('core.outfit_images_url') . '?id=' . $outfit['type'] . $getValue('addons') . $getValue('head') . $getValue('body') . $getValue('legs') . $getValue('feet'); + } + + return getMonsterImgPath($monster['name']); +} + +function getMonsterImgPath($name): string +{ + $monster_path = setting('core.monsters_images_url'); + $monster_gfx_name = trim(strtolower($name)) . setting('core.monsters_images_extension'); + if (!file_exists($monster_path . $monster_gfx_name)) { + $monster_gfx_name = str_replace(" ", "", $monster_gfx_name); + if (file_exists($monster_path . $monster_gfx_name)) { + return $monster_path . $monster_gfx_name; + } else { + return $monster_path . 'nophoto.png'; + } + } else { + return $monster_path . $monster_gfx_name; + } +} From 99997eb57dad16301612ce1d71f00b2f95b4633a Mon Sep 17 00:00:00 2001 From: Slawomir Boczek Date: Sun, 9 Mar 2025 21:39:37 +0100 Subject: [PATCH 10/14] Feature/twig hooks filters (#258) * feat: Hooks filters * Cleanup --- system/functions.php | 22 ++++++++++++-------- system/src/Hook.php | 5 +++++ system/src/Hooks.php | 29 +++++++++++++++++++-------- system/src/Twig/EnvironmentBridge.php | 28 ++++++++++++++++++++++++++ system/src/global.php | 5 +++++ system/twig.php | 5 ++--- 6 files changed, 75 insertions(+), 19 deletions(-) create mode 100644 system/src/Twig/EnvironmentBridge.php diff --git a/system/functions.php b/system/functions.php index 1c96d14a..c3fd4199 100644 --- a/system/functions.php +++ b/system/functions.php @@ -545,33 +545,39 @@ function template_header($is_admin = false): string */ function template_footer(): string { - global $views_counter; - $ret = ''; + $footer = []; + if(admin()) { - $ret .= generateLink(ADMIN_URL, 'Admin Panel', true); + $footer[] = generateLink(ADMIN_URL, 'Admin Panel', true); } if(setting('core.visitors_counter')) { global $visitors; $amount = $visitors->getAmountVisitors(); - $ret .= '
Currently there ' . ($amount > 1 ? 'are' : 'is') . ' ' . $amount . ' visitor' . ($amount > 1 ? 's' : '') . '.'; + $footer[] = 'Currently there ' . ($amount > 1 ? 'are' : 'is') . ' ' . $amount . ' visitor' . ($amount > 1 ? 's' : '') . '.'; } if(setting('core.views_counter')) { - $ret .= '
Page has been viewed ' . $views_counter . ' times.'; + global $views_counter; + $footer[] = 'Page has been viewed ' . $views_counter . ' times.'; } if(setting('core.footer_load_time')) { - $ret .= '
Load time: ' . round(microtime(true) - START_TIME, 4) . ' seconds.'; + $footer[] = 'Load time: ' . round(microtime(true) - START_TIME, 4) . ' seconds.'; } $settingFooter = setting('core.footer'); if(isset($settingFooter[0])) { - $ret .= '
' . $settingFooter; + $footer[] = '' . $settingFooter; } // please respect my work and help spreading the word, thanks! - return $ret . '
' . base64_decode('UG93ZXJlZCBieSA8YSBocmVmPSJodHRwOi8vbXktYWFjLm9yZyIgdGFyZ2V0PSJfYmxhbmsiPk15QUFDLjwvYT4='); + $footer[] = base64_decode('UG93ZXJlZCBieSA8YSBocmVmPSJodHRwOi8vbXktYWFjLm9yZyIgdGFyZ2V0PSJfYmxhbmsiPk15QUFDLjwvYT4='); + + global $hooks; + $footer = $hooks->triggerFilter(HOOK_FILTER_THEME_FOOTER, $footer); + + return implode('
', $footer); } function template_ga_code() diff --git a/system/src/Hook.php b/system/src/Hook.php index 73e378fd..9f4b7978 100644 --- a/system/src/Hook.php +++ b/system/src/Hook.php @@ -37,6 +37,11 @@ class Hook return !isset($ret) || $ret == 1 || $ret; } + public function executeFilter(...$args) { + return include BASE . $this->_file; + } + public function name() {return $this->_name;} public function type() {return $this->_type;} + public function file() {return $this->_file;} } diff --git a/system/src/Hooks.php b/system/src/Hooks.php index ee9f3b76..084d5e1a 100644 --- a/system/src/Hooks.php +++ b/system/src/Hooks.php @@ -4,22 +4,23 @@ namespace MyAAC; class Hooks { - private static $_hooks = array(); + private static array $_hooks = []; - public function register($hook, $type = '', $file = null) { + public function register($hook, $type = '', $file = null): void + { if(!($hook instanceof Hook)) $hook = new Hook($hook, $type, $file); self::$_hooks[$hook->type()][] = $hook; } - public function trigger($type, $params = array()) + public function trigger($type, $params = []): bool { $ret = true; - if(isset(self::$_hooks[$type])) - { + + if(isset(self::$_hooks[$type])) { foreach(self::$_hooks[$type] as $name => $hook) { - /** @var $hook Hook */ + /** @var Hook $hook */ if (!$hook->execute($params)) { $ret = false; } @@ -29,11 +30,23 @@ class Hooks return $ret; } - public function exist($type) { + public function triggerFilter($type, $args = []) + { + if(isset(self::$_hooks[$type])) { + foreach(self::$_hooks[$type] as $hook) { + /** @var Hook $hook */ + $args = $hook->executeFilter(...$args); + } + } + + return $args; + } + + public function exist($type): bool { return isset(self::$_hooks[$type]); } - public function load() + public function load(): void { foreach(Plugins::getHooks() as $hook) { $this->register($hook['name'], $hook['type'], $hook['file']); diff --git a/system/src/Twig/EnvironmentBridge.php b/system/src/Twig/EnvironmentBridge.php new file mode 100644 index 00000000..ab54bd25 --- /dev/null +++ b/system/src/Twig/EnvironmentBridge.php @@ -0,0 +1,28 @@ +triggerFilter(HOOK_FILTER_TWIG_DISPLAY, $context); + + parent::display($name, $context); + } + + public function render($name, array $context = []): string + { + global $hooks; + + $context['viewName'] = $name; + $context = $hooks->triggerFilter(HOOK_FILTER_TWIG_RENDER, $context); + + return parent::render($name, $context); + } +} diff --git a/system/src/global.php b/system/src/global.php index 61b887b5..ed9df203 100644 --- a/system/src/global.php +++ b/system/src/global.php @@ -97,6 +97,11 @@ define('HOOK_CACHE_CLEAR', ++$i); define('HOOK_INSTALL_FINISH', ++$i); define('HOOK_INSTALL_FINISH_END', ++$i); +// hook filters +define('HOOK_FILTER_TWIG_DISPLAY', ++$i); +define('HOOK_FILTER_TWIG_RENDER', ++$i); +define('HOOK_FILTER_THEME_FOOTER', ++$i); + const HOOK_FIRST = HOOK_INIT; define('HOOK_LAST', $i); diff --git a/system/twig.php b/system/twig.php index fc3125fe..f59230e3 100644 --- a/system/twig.php +++ b/system/twig.php @@ -9,8 +9,7 @@ */ defined('MYAAC') or die('Direct access not allowed!'); -use MyAAC\CsrfToken; -use Twig\Environment as Twig_Environment; +use MyAAC\Twig\EnvironmentBridge as MyAAC_Twig_EnvironmentBridge; use Twig\Extension\DebugExtension as Twig_DebugExtension; use Twig\Loader\FilesystemLoader as Twig_FilesystemLoader; use Twig\TwigFilter; @@ -20,7 +19,7 @@ global $twig, $twig_loader; $dev_mode = (config('env') === 'dev'); $twig_loader = new Twig_FilesystemLoader(SYSTEM . 'templates'); -$twig = new Twig_Environment($twig_loader, array( +$twig = new MyAAC_Twig_EnvironmentBridge($twig_loader, array( 'cache' => CACHE . 'twig/', 'auto_reload' => $dev_mode, 'debug' => $dev_mode From 5b4b7b8a9754d590abf09b29fa07815d2f1122f8 Mon Sep 17 00:00:00 2001 From: slawkens Date: Thu, 8 May 2025 18:34:36 +0200 Subject: [PATCH 11/14] triggerFilter -> pass by reference (faster x5) --- system/functions.php | 2 +- system/src/Hook.php | 2 +- system/src/Hooks.php | 4 +--- system/src/Twig/EnvironmentBridge.php | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/system/functions.php b/system/functions.php index c3fd4199..6e58ca9d 100644 --- a/system/functions.php +++ b/system/functions.php @@ -575,7 +575,7 @@ function template_footer(): string $footer[] = base64_decode('UG93ZXJlZCBieSA8YSBocmVmPSJodHRwOi8vbXktYWFjLm9yZyIgdGFyZ2V0PSJfYmxhbmsiPk15QUFDLjwvYT4='); global $hooks; - $footer = $hooks->triggerFilter(HOOK_FILTER_THEME_FOOTER, $footer); + $hooks->triggerFilter(HOOK_FILTER_THEME_FOOTER, $footer); return implode('
', $footer); } diff --git a/system/src/Hook.php b/system/src/Hook.php index 9f4b7978..161b2ffc 100644 --- a/system/src/Hook.php +++ b/system/src/Hook.php @@ -37,7 +37,7 @@ class Hook return !isset($ret) || $ret == 1 || $ret; } - public function executeFilter(...$args) { + public function executeFilter(&$args) { return include BASE . $this->_file; } diff --git a/system/src/Hooks.php b/system/src/Hooks.php index 084d5e1a..a7d6cb3a 100644 --- a/system/src/Hooks.php +++ b/system/src/Hooks.php @@ -30,7 +30,7 @@ class Hooks return $ret; } - public function triggerFilter($type, $args = []) + public function triggerFilter($type, &...$args) { if(isset(self::$_hooks[$type])) { foreach(self::$_hooks[$type] as $hook) { @@ -38,8 +38,6 @@ class Hooks $args = $hook->executeFilter(...$args); } } - - return $args; } public function exist($type): bool { diff --git a/system/src/Twig/EnvironmentBridge.php b/system/src/Twig/EnvironmentBridge.php index ab54bd25..4b8423f8 100644 --- a/system/src/Twig/EnvironmentBridge.php +++ b/system/src/Twig/EnvironmentBridge.php @@ -11,7 +11,7 @@ class EnvironmentBridge extends Environment global $hooks; $context['viewName'] = $name; - $context = $hooks->triggerFilter(HOOK_FILTER_TWIG_DISPLAY, $context); + $hooks->triggerFilter(HOOK_FILTER_TWIG_DISPLAY, $context); parent::display($name, $context); } @@ -21,7 +21,7 @@ class EnvironmentBridge extends Environment global $hooks; $context['viewName'] = $name; - $context = $hooks->triggerFilter(HOOK_FILTER_TWIG_RENDER, $context); + $hooks->triggerFilter(HOOK_FILTER_TWIG_RENDER, $context); return parent::render($name, $context); } From 9b75011224f385db8b27e109bfeb28e75b9d779c Mon Sep 17 00:00:00 2001 From: slawkens Date: Thu, 8 May 2025 18:35:03 +0200 Subject: [PATCH 12/14] New filter: HOOK_FILTER_ROUTES --- system/src/Plugins.php | 3 +++ system/src/global.php | 1 + 2 files changed, 4 insertions(+) diff --git a/system/src/Plugins.php b/system/src/Plugins.php index f9d4d5ce..4acca75e 100644 --- a/system/src/Plugins.php +++ b/system/src/Plugins.php @@ -198,6 +198,9 @@ class Plugins { } } + global $hooks; + $hooks->triggerFilter(HOOK_FILTER_ROUTES, $routes); + usort($routes, function ($a, $b) { // key 3 is priority diff --git a/system/src/global.php b/system/src/global.php index ed9df203..62366c1c 100644 --- a/system/src/global.php +++ b/system/src/global.php @@ -98,6 +98,7 @@ define('HOOK_INSTALL_FINISH', ++$i); define('HOOK_INSTALL_FINISH_END', ++$i); // hook filters +define('HOOK_FILTER_ROUTES', ++$i); define('HOOK_FILTER_TWIG_DISPLAY', ++$i); define('HOOK_FILTER_TWIG_RENDER', ++$i); define('HOOK_FILTER_THEME_FOOTER', ++$i); From 620a47da72dbf5e9c891280005f1a5f6c20cc889 Mon Sep 17 00:00:00 2001 From: slawkens Date: Thu, 8 May 2025 19:55:31 +0200 Subject: [PATCH 13/14] Update Hooks.php --- system/src/Hooks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/src/Hooks.php b/system/src/Hooks.php index a7d6cb3a..8dac8eda 100644 --- a/system/src/Hooks.php +++ b/system/src/Hooks.php @@ -30,12 +30,12 @@ class Hooks return $ret; } - public function triggerFilter($type, &...$args) + public function triggerFilter($type, &$args): void { if(isset(self::$_hooks[$type])) { foreach(self::$_hooks[$type] as $hook) { /** @var Hook $hook */ - $args = $hook->executeFilter(...$args); + $hook->executeFilter($args); } } } From c24c580796bccd54bf9e95b864763f4642684d55 Mon Sep 17 00:00:00 2001 From: slawkens Date: Fri, 9 May 2025 13:09:44 +0200 Subject: [PATCH 14/14] Fix installMenus when theme/template was removed from disc --- install/tools/7-finish.php | 7 ++++--- system/migrations/17.php | 9 +++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/install/tools/7-finish.php b/install/tools/7-finish.php index 6620f7d9..6f6b2d30 100644 --- a/install/tools/7-finish.php +++ b/install/tools/7-finish.php @@ -54,12 +54,13 @@ if ($db->hasTable('players')) { } } -Plugins::installMenus('kathrine', require TEMPLATES . 'kathrine/menus.php'); -Plugins::installMenus('tibiacom', require TEMPLATES . 'tibiacom/menus.php'); - DataLoader::setLocale($locale); DataLoader::load(); +// add menus entries +require_once SYSTEM . 'migrations/17.php'; +$up(); + // update config.highscores_ids_hidden require_once SYSTEM . 'migrations/20.php'; $up(); diff --git a/system/migrations/17.php b/system/migrations/17.php index 497e3e3c..c29d277e 100644 --- a/system/migrations/17.php +++ b/system/migrations/17.php @@ -10,8 +10,13 @@ $up = function () use ($db) { $db->exec(file_get_contents(__DIR__ . '/17-menu.sql')); } - Plugins::installMenus('kathrine', require TEMPLATES . 'kathrine/menus.php'); - Plugins::installMenus('tibiacom', require TEMPLATES . 'tibiacom/menus.php'); + $themes = ['kathrine', 'tibiacom',]; + foreach ($themes as $theme) { + $file = TEMPLATES . $theme . '/menus.php'; + if (is_file($file)) { + Plugins::installMenus($theme, require $file); + } + } }; $down = function () use ($db) {