forked from GithubBackups/vichan
theme.php: extract theme functions from functions.php
This commit is contained in:
parent
e16dc142b7
commit
b2df2ab2a5
@ -397,108 +397,6 @@ function create_antibot($board, $thread = null) {
|
|||||||
return _create_antibot($board, $thread);
|
return _create_antibot($board, $thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
function rebuildThemes($action, $boardname = false) {
|
|
||||||
global $config, $board, $current_locale;
|
|
||||||
|
|
||||||
// Save the global variables
|
|
||||||
$_config = $config;
|
|
||||||
$_board = $board;
|
|
||||||
|
|
||||||
// List themes
|
|
||||||
if ($themes = Cache::get("themes")) {
|
|
||||||
// OK, we already have themes loaded
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$query = query("SELECT `theme` FROM ``theme_settings`` WHERE `name` IS NULL AND `value` IS NULL") or error(db_error());
|
|
||||||
|
|
||||||
$themes = array();
|
|
||||||
|
|
||||||
while ($theme = $query->fetch(PDO::FETCH_ASSOC)) {
|
|
||||||
$themes[] = $theme;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cache::set("themes", $themes);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($themes as $theme) {
|
|
||||||
// Restore them
|
|
||||||
$config = $_config;
|
|
||||||
$board = $_board;
|
|
||||||
|
|
||||||
// Reload the locale
|
|
||||||
if ($config['locale'] != $current_locale) {
|
|
||||||
$current_locale = $config['locale'];
|
|
||||||
init_locale($config['locale']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PHP_SAPI === 'cli') {
|
|
||||||
echo "Rebuilding theme ".$theme['theme']."... ";
|
|
||||||
}
|
|
||||||
|
|
||||||
rebuildTheme($theme['theme'], $action, $boardname);
|
|
||||||
|
|
||||||
if (PHP_SAPI === 'cli') {
|
|
||||||
echo "done\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore them again
|
|
||||||
$config = $_config;
|
|
||||||
$board = $_board;
|
|
||||||
|
|
||||||
// Reload the locale
|
|
||||||
if ($config['locale'] != $current_locale) {
|
|
||||||
$current_locale = $config['locale'];
|
|
||||||
init_locale($config['locale']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function loadThemeConfig($_theme) {
|
|
||||||
global $config;
|
|
||||||
|
|
||||||
if (!file_exists($config['dir']['themes'] . '/' . $_theme . '/info.php'))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Load theme information into $theme
|
|
||||||
include $config['dir']['themes'] . '/' . $_theme . '/info.php';
|
|
||||||
|
|
||||||
return $theme;
|
|
||||||
}
|
|
||||||
|
|
||||||
function rebuildTheme($theme, $action, $board = false) {
|
|
||||||
global $config, $_theme;
|
|
||||||
$_theme = $theme;
|
|
||||||
|
|
||||||
$theme = loadThemeConfig($_theme);
|
|
||||||
|
|
||||||
if (file_exists($config['dir']['themes'] . '/' . $_theme . '/theme.php')) {
|
|
||||||
require_once $config['dir']['themes'] . '/' . $_theme . '/theme.php';
|
|
||||||
|
|
||||||
$theme['build_function']($action, themeSettings($_theme), $board);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function themeSettings($theme) {
|
|
||||||
if ($settings = Cache::get("theme_settings_".$theme)) {
|
|
||||||
return $settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = prepare("SELECT `name`, `value` FROM ``theme_settings`` WHERE `theme` = :theme AND `name` IS NOT NULL");
|
|
||||||
$query->bindValue(':theme', $theme);
|
|
||||||
$query->execute() or error(db_error($query));
|
|
||||||
|
|
||||||
$settings = array();
|
|
||||||
while ($s = $query->fetch(PDO::FETCH_ASSOC)) {
|
|
||||||
$settings[$s['name']] = $s['value'];
|
|
||||||
}
|
|
||||||
|
|
||||||
Cache::set("theme_settings_".$theme, $settings);
|
|
||||||
|
|
||||||
return $settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
function sprintf3($str, $vars, $delim = '%') {
|
function sprintf3($str, $vars, $delim = '%') {
|
||||||
$replaces = array();
|
$replaces = array();
|
||||||
foreach ($vars as $k => $v) {
|
foreach ($vars as $k => $v) {
|
||||||
|
98
inc/functions/theme.php
Normal file
98
inc/functions/theme.php
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
<?php
|
||||||
|
namespace Vichan\Functions\Theme;
|
||||||
|
|
||||||
|
|
||||||
|
function rebuildThemes(string $action, $boardname = false): void {
|
||||||
|
global $config, $board, $current_locale;
|
||||||
|
|
||||||
|
// Save the global variables
|
||||||
|
$_config = $config;
|
||||||
|
$_board = $board;
|
||||||
|
|
||||||
|
// List themes
|
||||||
|
if ($themes = \Cache::get("themes")) {
|
||||||
|
// OK, we already have themes loaded
|
||||||
|
} else {
|
||||||
|
$query = query("SELECT `theme` FROM ``theme_settings`` WHERE `name` IS NULL AND `value` IS NULL") or error(db_error());
|
||||||
|
$themes = $query->fetchAll(\PDO::FETCH_NUM);
|
||||||
|
|
||||||
|
\Cache::set("themes", $themes);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($themes as $theme) {
|
||||||
|
// Restore them
|
||||||
|
$config = $_config;
|
||||||
|
$board = $_board;
|
||||||
|
|
||||||
|
// Reload the locale
|
||||||
|
if ($config['locale'] != $current_locale) {
|
||||||
|
$current_locale = $config['locale'];
|
||||||
|
init_locale($config['locale']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PHP_SAPI === 'cli') {
|
||||||
|
echo "Rebuilding theme ".$theme['theme']."... ";
|
||||||
|
}
|
||||||
|
|
||||||
|
rebuildTheme($theme['theme'], $action, $boardname);
|
||||||
|
|
||||||
|
if (PHP_SAPI === 'cli') {
|
||||||
|
echo "done\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore them again
|
||||||
|
$config = $_config;
|
||||||
|
$board = $_board;
|
||||||
|
|
||||||
|
// Reload the locale
|
||||||
|
if ($config['locale'] != $current_locale) {
|
||||||
|
$current_locale = $config['locale'];
|
||||||
|
init_locale($config['locale']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadThemeConfig($_theme) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if (!file_exists($config['dir']['themes'] . '/' . $_theme . '/info.php')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load theme information into $theme
|
||||||
|
include $config['dir']['themes'] . '/' . $_theme . '/info.php';
|
||||||
|
|
||||||
|
return $theme;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rebuildTheme($theme, string $action, $board = false) {
|
||||||
|
global $config, $_theme;
|
||||||
|
$_theme = $theme;
|
||||||
|
|
||||||
|
$theme = loadThemeConfig($_theme);
|
||||||
|
|
||||||
|
if (file_exists($config['dir']['themes'] . '/' . $_theme . '/theme.php')) {
|
||||||
|
require_once $config['dir']['themes'] . '/' . $_theme . '/theme.php';
|
||||||
|
|
||||||
|
$theme['build_function']($action, themeSettings($_theme), $board);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function themeSettings($theme): array {
|
||||||
|
if ($settings = \Cache::get("theme_settings_" . $theme)) {
|
||||||
|
return $settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = prepare("SELECT `name`, `value` FROM ``theme_settings`` WHERE `theme` = :theme AND `name` IS NOT NULL");
|
||||||
|
$query->bindValue(':theme', $theme);
|
||||||
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
|
$settings = [];
|
||||||
|
while ($s = $query->fetch(\PDO::FETCH_ASSOC)) {
|
||||||
|
$settings[$s['name']] = $s['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
\Cache::set("theme_settings_".$theme, $settings);
|
||||||
|
|
||||||
|
return $settings;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user