Compare commits
No commits in common. "30ea7ff5c0c18f6560341ef5c2ded913f44b5a35" and "37566b512227eabf91f636737d4c91e94b957f8e" have entirely different histories.
30ea7ff5c0
...
37566b5122
|
@ -23,7 +23,6 @@ class Theme
|
||||||
*/
|
*/
|
||||||
private static $config;
|
private static $config;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the theme configuration
|
* Get the theme configuration
|
||||||
*
|
*
|
||||||
|
@ -36,13 +35,11 @@ class Theme
|
||||||
return self::$config;
|
return self::$config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string Current theme name
|
* @var string Current theme name
|
||||||
*/
|
*/
|
||||||
private static $currentTheme;
|
private static $currentTheme;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the theme system
|
* Initialize the theme system
|
||||||
*/
|
*/
|
||||||
|
@ -55,7 +52,6 @@ class Theme
|
||||||
self::$currentTheme = self::getCurrentThemeName();
|
self::$currentTheme = self::getCurrentThemeName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current theme name
|
* Get the current theme name
|
||||||
*
|
*
|
||||||
|
@ -73,55 +69,20 @@ class Theme
|
||||||
return self::$currentTheme;
|
return self::$currentTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to get from session first
|
// Get from session if available
|
||||||
$sessionTheme = Session::get('theme');
|
if (Session::isValidSession() && isset($_SESSION['user_theme'])) {
|
||||||
if ($sessionTheme && isset(self::$config['available_themes'][$sessionTheme])) {
|
$theme = $_SESSION['user_theme'];
|
||||||
self::$currentTheme = $sessionTheme;
|
if (self::themeExists($theme)) {
|
||||||
} else {
|
self::$currentTheme = $theme;
|
||||||
// Fall back to default theme
|
return $theme;
|
||||||
self::$currentTheme = self::$config['active_theme'];
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$currentTheme;
|
// Default to 'default' theme which uses app/templates
|
||||||
|
self::$currentTheme = 'default';
|
||||||
|
return 'default';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the URL for a theme asset
|
|
||||||
*
|
|
||||||
* @param string $themeId Theme ID
|
|
||||||
* @param string $assetPath Path to the asset relative to theme directory (e.g., 'css/style.css')
|
|
||||||
* @return string|null URL to the asset or null if not found
|
|
||||||
*/
|
|
||||||
public static function getAssetUrl($themeId, $assetPath = '')
|
|
||||||
{
|
|
||||||
// Clean and validate the asset path
|
|
||||||
$assetPath = ltrim($assetPath, '/');
|
|
||||||
if (empty($assetPath)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only allow alphanumeric, hyphen, underscore, dot, and forward slash
|
|
||||||
if (!preg_match('/^[a-zA-Z0-9_\-\.\/]+$/', $assetPath)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prevent directory traversal
|
|
||||||
if (strpos($assetPath, '..') !== false) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$fullPath = __DIR__ . "/../../themes/$themeId/$assetPath";
|
|
||||||
if (!file_exists($fullPath) || !is_readable($fullPath)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the router to generate the URL
|
|
||||||
global $app_root;
|
|
||||||
return "$app_root/app/helpers/theme-asset.php?theme=" . urlencode($themeId) . "&path=" . urlencode($assetPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the current theme for the session
|
* Set the current theme for the session
|
||||||
*
|
*
|
||||||
|
@ -164,7 +125,6 @@ class Theme
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a theme exists
|
* Check if a theme exists
|
||||||
*
|
*
|
||||||
|
@ -182,7 +142,6 @@ class Theme
|
||||||
return is_dir($themePath) && file_exists("$themePath/config.php");
|
return is_dir($themePath) && file_exists("$themePath/config.php");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the path to a theme
|
* Get the path to a theme
|
||||||
*
|
*
|
||||||
|
@ -196,7 +155,6 @@ class Theme
|
||||||
return rtrim($config['paths']['themes'], '/') . "/$themeName";
|
return rtrim($config['paths']['themes'], '/') . "/$themeName";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the URL for a theme asset
|
* Get the URL for a theme asset
|
||||||
*
|
*
|
||||||
|
@ -227,7 +185,6 @@ class Theme
|
||||||
return $baseUrl . $assetPath;
|
return $baseUrl . $assetPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Include a theme template file
|
* Include a theme template file
|
||||||
*
|
*
|
||||||
|
@ -269,7 +226,6 @@ class Theme
|
||||||
error_log("Template not found: {$template} in theme: {$themeName}");
|
error_log("Template not found: {$template} in theme: {$themeName}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all available themes
|
* Get all available themes
|
||||||
*
|
*
|
||||||
|
|
|
@ -53,7 +53,7 @@ $themeData = [];
|
||||||
foreach ($themes as $id => $name) {
|
foreach ($themes as $id => $name) {
|
||||||
$themeData[$id] = [
|
$themeData[$id] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'screenshotUrl' => \App\Helpers\Theme::getAssetUrl($id, 'screenshot.png'),
|
'screenshotUrl' => \App\Helpers\Theme::getScreenshotUrl($id),
|
||||||
'isActive' => $id === $currentTheme
|
'isActive' => $id === $currentTheme
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue