From 4867df89a17737ffb07cc958e52a6cda796a1a9b Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Fri, 23 May 2025 09:58:50 +0300 Subject: [PATCH] Bugfixes theme helper --- app/helpers/theme.php | 53 ++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/app/helpers/theme.php b/app/helpers/theme.php index a069513..7ac4b09 100644 --- a/app/helpers/theme.php +++ b/app/helpers/theme.php @@ -12,6 +12,10 @@ namespace App\Helpers; use Exception; +// Include Session class +require_once __DIR__ . '/../classes/session.php'; +use Session; + class Theme { /** @@ -19,6 +23,19 @@ class Theme */ private static $config; + /** + * Get the theme configuration + * + * @return array + */ + public static function getConfig() + { + if (self::$config === null) { + self::init(); + } + return self::$config; + } + /** * @var string Current theme name */ @@ -134,41 +151,35 @@ class Theme } /** - * Include a theme template + * Include a theme template file * - * @param string $template - * @param array $data + * @param string $template Template name without .php extension * @return void */ - public static function include($template, $data = []) + public static function include($template) { $themeName = self::getCurrentThemeName(); $config = self::getConfig(); - // For non-default themes, look in the theme directory + // Import all global variables into local scope + // We need this here, otherwise because this helper + // between index and the views breaks the session vars + extract($GLOBALS, EXTR_SKIP | EXTR_REFS); + + // For non-default themes, look in the theme directory first if ($themeName !== 'default') { $themePath = $config['paths']['themes'] . '/' . $themeName . '/views/' . $template . '.php'; if (file_exists($themePath)) { - extract($data); include $themePath; return; } + } - // Fallback to default theme if template not found in custom theme - $legacyPath = $config['paths']['templates'] . '/' . $template . '.php'; - if (file_exists($legacyPath)) { - extract($data); - include $legacyPath; - return; - } - } else { - // Default theme uses app/templates - $legacyPath = $config['paths']['templates'] . '/' . $template . '.php'; - if (file_exists($legacyPath)) { - extract($data); - include $legacyPath; - return; - } + // Fallback to default template location + $defaultPath = $config['paths']['templates'] . '/' . $template . '.php'; + if (file_exists($defaultPath)) { + include $defaultPath; + return; } // Log error if template not found