Файл: upload/core/template_loader.php
Строк: 41
<?php
$THEMES = [];
/**
* Загрузка всех тем из /templates
*/
function load_themes() {
global $THEMES;
$base = __DIR__ . '/templates';
// Темы, которые есть в БД
$dbThemes = DataFetchAll(dbquery("SELECT id FROM themes"));
$dbThemes = array_column($dbThemes, 'id');
// Активная тема
$activeTheme = DataFetchColumn(dbquery("SELECT id FROM themes WHERE is_active = 1"));
// Найденные на диске
$foundThemes = [];
foreach (glob($base . '/*', GLOB_ONLYDIR) as $themeDir) {
$themeFile = $themeDir . '/theme.php';
if (!file_exists($themeFile)) continue;
$config = include $themeFile;
// Проверка обязательных полей
if (empty($config['id']) || empty($config['name'])) continue;
$themeId = $config['id'];
$foundThemes[] = $themeId;
// Проверяем наличие в БД
$exists = DataFetchColumn(dbquery("SELECT id FROM themes WHERE id = ?", [$themeId]));
if (!$exists) {
// Создаём запись
dbquery("
INSERT INTO themes (id, name, description, is_active)
VALUES (?, ?, ?, 0)
", [
$themeId,
$config['name'],
$config['description']
]);
}
// Загружаем конфиг темы
$THEMES[$themeId] = $config;
// Если тема активна — запускаем init()
if ($activeTheme === $themeId) {
if (!empty($config['init']) && is_callable($config['init'])) {
$config['init']();
}
}
}
// Удаляем из БД темы, которых нет на диске
foreach ($dbThemes as $themeId) {
if (!in_array($themeId, $foundThemes)) {
dbquery("DELETE FROM themes WHERE id = ?", [$themeId]);
}
}
}
function StyleLink() {
global $theme;
$link = homeLink() . '/core/templates/' . $theme;
return $link;
}
?>