From 28a2b34cc16ec4f1b94b70021e3d923e7264bc49 Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 12 Nov 2024 22:19:21 +0100 Subject: [PATCH 01/13] Update account.management.html.twig --- templates/tibiacom/account.management.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/tibiacom/account.management.html.twig b/templates/tibiacom/account.management.html.twig index 6ce10274..5125f3ed 100644 --- a/templates/tibiacom/account.management.html.twig +++ b/templates/tibiacom/account.management.html.twig @@ -291,7 +291,7 @@ -{% set title = 'Account logs' %} +{% set title = 'Account Logs' %} {% set tableClass = 'Table3' %} {% set content %} From 84d37c5a8f2c4535a41c8aa8264752969d3f3a3d Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 17 Nov 2024 18:07:10 +0100 Subject: [PATCH 02/13] Allow OTS_Player to be passed as object to getPlayerLink --- system/functions.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/system/functions.php b/system/functions.php index f177d997..09f122fe 100644 --- a/system/functions.php +++ b/system/functions.php @@ -89,13 +89,18 @@ function getForumBoardLink($board_id, $page = NULL): string { function getPlayerLink($name, $generate = true, bool $colored = false): string { - $player = new OTS_Player(); - - if(is_numeric($name)) { - $player->load((int)$name); + if (is_object($name) and $name instanceof OTS_Player) { + $player = $name; } else { - $player->find($name); + $player = new OTS_Player(); + + if(is_numeric($name)) { + $player->load((int)$name); + } + else { + $player->find($name); + } } if (!$player->isLoaded()) { From d0b4065ccf862d58c8aedd3bcdd279f20decc61e Mon Sep 17 00:00:00 2001 From: slawkens Date: Mon, 18 Nov 2024 15:04:53 +0100 Subject: [PATCH 03/13] Optimise news management --- admin/pages/news.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/admin/pages/news.php b/admin/pages/news.php index d74d6405..61571597 100644 --- a/admin/pages/news.php +++ b/admin/pages/news.php @@ -26,7 +26,7 @@ if (!hasFlag(FLAG_CONTENT_PAGES) && !superAdmin()) { header('X-XSS-Protection:0'); -// some constants, used mainly by database (cannot by modified without schema changes) +// some constants, used mainly by database (cannot be modified without schema changes) const NEWS_TITLE_LIMIT = 100; const NEWS_BODY_LIMIT = 65535; // maximum news body length const ARTICLE_TEXT_LIMIT = 300; @@ -136,9 +136,18 @@ if($action == 'edit' || $action == 'new') { $query = $db->query('SELECT * FROM ' . $db->tableName(TABLE_PREFIX . 'news')); $newses = array(); + +$cachePlayers = []; foreach ($query as $_news) { - $_player = new OTS_Player(); - $_player->load($_news['player_id']); + $playerId = $_news['player_id']; + if (isset($cachePlayers[$playerId])) { + $_player = $cachePlayers[$playerId]; + } + else { + $_player = new OTS_Player(); + $_player->load($playerId); + $cachePlayers[$playerId] = $_player; + } $newses[$_news['type']][] = array( 'id' => $_news['id'], @@ -147,7 +156,7 @@ foreach ($query as $_news) { 'title' => $_news['title'], 'date' => $_news['date'], 'player_name' => $_player->isLoaded() ? $_player->getName() : '', - 'player_link' => $_player->isLoaded() ? getPlayerLink($_player->getName(), false) : '', + 'player_link' => $_player->isLoaded() ? getPlayerLink($_player, false) : '', ); } From a2fadc5945fe0a5e39f740827f6ffbda1bb501e2 Mon Sep 17 00:00:00 2001 From: slawkens Date: Mon, 18 Nov 2024 23:48:03 +0100 Subject: [PATCH 04/13] Fixes to installMenus function --- system/src/Plugins.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/system/src/Plugins.php b/system/src/Plugins.php index fbaa5e40..4bb1cc15 100644 --- a/system/src/Plugins.php +++ b/system/src/Plugins.php @@ -770,15 +770,14 @@ class Plugins { */ public static function installMenus($templateName, $categories, $clearOld = true) { - global $db; - if (!$db->hasTable(TABLE_PREFIX . 'menu')) { - return; - } - if ($clearOld) { Menu::where('template', $templateName)->delete(); } + if (Menu::count()) { + return; + } + foreach ($categories as $category => $menus) { $i = 0; foreach ($menus as $name => $link) { From 8ae22accc9b945161e19d5a56b97962dde5de0d4 Mon Sep 17 00:00:00 2001 From: slawkens Date: Mon, 18 Nov 2024 23:49:26 +0100 Subject: [PATCH 05/13] Fix for console displaying REQUEST_URI --- system/libs/pot/OTS_DB_MySQL.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/libs/pot/OTS_DB_MySQL.php b/system/libs/pot/OTS_DB_MySQL.php index 5ca7d28b..318f2e9f 100644 --- a/system/libs/pot/OTS_DB_MySQL.php +++ b/system/libs/pot/OTS_DB_MySQL.php @@ -165,7 +165,8 @@ class OTS_DB_MySQL extends OTS_Base_DB } if($this->logged) { - log_append('database.log', $_SERVER['REQUEST_URI'] . PHP_EOL . $this->getLog()); + $currentScript = $_SERVER['REQUEST_URI'] ?? $_SERVER['SCRIPT_FILENAME']; + log_append('database.log', $currentScript . PHP_EOL . $this->getLog()); } } From 1e6892971b471957c1beb55b2e6cd472054741ca Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 19 Nov 2024 07:03:06 +0100 Subject: [PATCH 06/13] Change spaces to tabs --- system/libs/pot/OTS_DB_MySQL.php | 114 +++++++++++++++---------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/system/libs/pot/OTS_DB_MySQL.php b/system/libs/pot/OTS_DB_MySQL.php index 318f2e9f..89e8dd0d 100644 --- a/system/libs/pot/OTS_DB_MySQL.php +++ b/system/libs/pot/OTS_DB_MySQL.php @@ -53,49 +53,49 @@ class OTS_DB_MySQL extends OTS_Base_DB * @param array $params Connection parameters. * @throws PDOException On PDO operation error. */ - public function __construct($params) - { - $user = null; - $password = null; - $dns = array(); + public function __construct($params) + { + $user = null; + $password = null; + $dns = array(); - // host:port support - if( strpos(':', $params['host']) !== false) - { - $host = explode(':', $params['host'], 2); + // host:port support + if( strpos(':', $params['host']) !== false) + { + $host = explode(':', $params['host'], 2); - $params['host'] = $host[0]; - $params['port'] = $host[1]; - } + $params['host'] = $host[0]; + $params['port'] = $host[1]; + } - if( isset($params['database']) ) - { - $dns[] = 'dbname=' . $params['database']; - } + if( isset($params['database']) ) + { + $dns[] = 'dbname=' . $params['database']; + } - if( isset($params['user']) ) - { - $user = $params['user']; - } + if( isset($params['user']) ) + { + $user = $params['user']; + } - if( isset($params['password']) ) - { - $password = $params['password']; - } + if( isset($params['password']) ) + { + $password = $params['password']; + } - if( isset($params['prefix']) ) - { - $this->prefix = $params['prefix']; - } + if( isset($params['prefix']) ) + { + $this->prefix = $params['prefix']; + } - if( isset($params['log']) && $params['log'] ) - { - $this->logged = true; - } + if( isset($params['log']) && $params['log'] ) + { + $this->logged = true; + } - if( !isset($params['persistent']) ) { - $params['persistent'] = false; - } + if( !isset($params['persistent']) ) { + $params['persistent'] = false; + } global $config; $cache = Cache::getInstance(); @@ -144,10 +144,10 @@ class OTS_DB_MySQL extends OTS_Base_DB } parent::__construct('mysql:' . implode(';', $dns), $user, $password, $driverAttributes); - } + } public function __destruct() - { + { global $config; $cache = Cache::getInstance(); @@ -176,10 +176,10 @@ class OTS_DB_MySQL extends OTS_Base_DB * @param string $name Field name. * @return string Quoted name. */ - public function fieldName($name) - { - return '`' . $name . '`'; - } + public function fieldName($name) + { + return '`' . $name . '`'; + } /** * LIMIT/OFFSET clause for queries. @@ -188,26 +188,26 @@ class OTS_DB_MySQL extends OTS_Base_DB * @param int|bool $offset Number of rows to be skipped before applying query effects (false if no offset). * @return string LIMIT/OFFSET SQL clause for query. */ - public function limit($limit = false, $offset = false) - { - // by default this is empty part - $sql = ''; + public function limit($limit = false, $offset = false) + { + // by default this is empty part + $sql = ''; - if($limit !== false) - { - $sql = ' LIMIT '; + if($limit !== false) + { + $sql = ' LIMIT '; - // OFFSET has no effect if there is no LIMIT - if($offset !== false) - { - $sql .= $offset . ', '; - } + // OFFSET has no effect if there is no LIMIT + if($offset !== false) + { + $sql .= $offset . ', '; + } - $sql .= $limit; - } + $sql .= $limit; + } - return $sql; - } + return $sql; + } public function hasTable($name) { if(isset($this->has_table_cache[$name])) { From 12d8faa3eda5e798f97b71e941c035187daad96e Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 19 Nov 2024 07:05:27 +0100 Subject: [PATCH 07/13] Do not clear menus by default --- system/src/Plugins.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Plugins.php b/system/src/Plugins.php index 4bb1cc15..5932ebb9 100644 --- a/system/src/Plugins.php +++ b/system/src/Plugins.php @@ -768,7 +768,7 @@ class Plugins { * @param string $templateName * @param array $categories */ - public static function installMenus($templateName, $categories, $clearOld = true) + public static function installMenus($templateName, $categories, $clearOld = false) { if ($clearOld) { Menu::where('template', $templateName)->delete(); From 64e4c089509c29fca11def4fd814a83a46cec024 Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 19 Nov 2024 07:19:43 +0100 Subject: [PATCH 08/13] MyAAC\Cache --- system/src/Cache.php | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 system/src/Cache.php diff --git a/system/src/Cache.php b/system/src/Cache.php new file mode 100644 index 00000000..42ca597f --- /dev/null +++ b/system/src/Cache.php @@ -0,0 +1,5 @@ + Date: Tue, 19 Nov 2024 07:48:52 +0100 Subject: [PATCH 09/13] Fix installMenus function --- system/src/Plugins.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Plugins.php b/system/src/Plugins.php index 5932ebb9..6e518b48 100644 --- a/system/src/Plugins.php +++ b/system/src/Plugins.php @@ -774,7 +774,7 @@ class Plugins { Menu::where('template', $templateName)->delete(); } - if (Menu::count()) { + if (Menu::where('template', $templateName)->count()) { return; } From 95343cec02d04d549ca876dc532a1a29e7b3303c Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 19 Nov 2024 14:08:24 +0100 Subject: [PATCH 10/13] Change to str_contains --- system/init.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/system/init.php b/system/init.php index b489dd38..1102fb56 100644 --- a/system/init.php +++ b/system/init.php @@ -14,7 +14,6 @@ use MyAAC\CsrfToken; use MyAAC\Hooks; use MyAAC\Models\Town; use MyAAC\Settings; -use MyAAC\Towns; defined('MYAAC') or die('Direct access not allowed!'); @@ -39,7 +38,7 @@ if($config['server_path'][strlen($config['server_path']) - 1] !== '/') $config['server_path'] .= '/'; // enable gzip compression if supported by the browser -if(isset($config['gzip_output']) && $config['gzip_output'] && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false && function_exists('ob_gzhandler')) +if(isset($config['gzip_output']) && $config['gzip_output'] && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && str_contains($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('ob_gzhandler')) ob_start('ob_gzhandler'); // cache From 6f58df04671afcc6e12c9c35428ef9c44324673d Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 19 Nov 2024 14:08:27 +0100 Subject: [PATCH 11/13] Update twig.php --- system/twig.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/twig.php b/system/twig.php index 9176c371..1268f292 100644 --- a/system/twig.php +++ b/system/twig.php @@ -16,6 +16,8 @@ use Twig\Loader\FilesystemLoader as Twig_FilesystemLoader; use Twig\TwigFilter; use Twig\TwigFunction; +global $twig, $twig_loader; + $dev_mode = (config('env') === 'dev'); $twig_loader = new Twig_FilesystemLoader(SYSTEM . 'templates'); $twig = new Twig_Environment($twig_loader, array( From afb055f2dcec3eb3b604a462200bbcaf3aaf0786 Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 19 Nov 2024 14:21:15 +0100 Subject: [PATCH 12/13] More obvious name for parameter in -> installMenus --- system/src/Plugins.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/src/Plugins.php b/system/src/Plugins.php index 6e518b48..00515139 100644 --- a/system/src/Plugins.php +++ b/system/src/Plugins.php @@ -766,9 +766,9 @@ class Plugins { * Helper function for plugins * * @param string $templateName - * @param array $categories + * @param array $menus */ - public static function installMenus($templateName, $categories, $clearOld = false) + public static function installMenus($templateName, $menus, $clearOld = false) { if ($clearOld) { Menu::where('template', $templateName)->delete(); @@ -778,9 +778,9 @@ class Plugins { return; } - foreach ($categories as $category => $menus) { + foreach ($menus as $category => $_menus) { $i = 0; - foreach ($menus as $name => $link) { + foreach ($_menus as $name => $link) { $color = ''; $blank = 0; From 38e699ba4b40f64a2f57d12da349b8395c394b0b Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 19 Nov 2024 14:21:31 +0100 Subject: [PATCH 13/13] PHP 8.1 is required --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 47d68dbe..de66b921 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "require": { - "php": "^8.0", + "php": "^8.1", "ext-pdo": "*", "ext-pdo_mysql": "*", "ext-json": "*",