Bugfixes theme helper
parent
4715a26af7
commit
4867df89a1
|
@ -12,6 +12,10 @@ namespace App\Helpers;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
|
// Include Session class
|
||||||
|
require_once __DIR__ . '/../classes/session.php';
|
||||||
|
use Session;
|
||||||
|
|
||||||
class Theme
|
class Theme
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -19,6 +23,19 @@ class Theme
|
||||||
*/
|
*/
|
||||||
private static $config;
|
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
|
* @var string Current theme name
|
||||||
*/
|
*/
|
||||||
|
@ -134,41 +151,35 @@ class Theme
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Include a theme template
|
* Include a theme template file
|
||||||
*
|
*
|
||||||
* @param string $template
|
* @param string $template Template name without .php extension
|
||||||
* @param array $data
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function include($template, $data = [])
|
public static function include($template)
|
||||||
{
|
{
|
||||||
$themeName = self::getCurrentThemeName();
|
$themeName = self::getCurrentThemeName();
|
||||||
$config = self::getConfig();
|
$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') {
|
if ($themeName !== 'default') {
|
||||||
$themePath = $config['paths']['themes'] . '/' . $themeName . '/views/' . $template . '.php';
|
$themePath = $config['paths']['themes'] . '/' . $themeName . '/views/' . $template . '.php';
|
||||||
if (file_exists($themePath)) {
|
if (file_exists($themePath)) {
|
||||||
extract($data);
|
|
||||||
include $themePath;
|
include $themePath;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Fallback to default theme if template not found in custom theme
|
// Fallback to default template location
|
||||||
$legacyPath = $config['paths']['templates'] . '/' . $template . '.php';
|
$defaultPath = $config['paths']['templates'] . '/' . $template . '.php';
|
||||||
if (file_exists($legacyPath)) {
|
if (file_exists($defaultPath)) {
|
||||||
extract($data);
|
include $defaultPath;
|
||||||
include $legacyPath;
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Default theme uses app/templates
|
|
||||||
$legacyPath = $config['paths']['templates'] . '/' . $template . '.php';
|
|
||||||
if (file_exists($legacyPath)) {
|
|
||||||
extract($data);
|
|
||||||
include $legacyPath;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log error if template not found
|
// Log error if template not found
|
||||||
|
|
Loading…
Reference in New Issue