mirror of
https://github.com/vichan-devel/vichan.git
synced 2025-01-19 01:24:05 +01:00
Merge pull request #797 from Zankaria/function-themes
Split the theme functions from functions.php
This commit is contained in:
commit
90dead0394
@ -37,6 +37,7 @@
|
||||
"inc/functions/net.php",
|
||||
"inc/functions/num.php",
|
||||
"inc/functions/format.php",
|
||||
"inc/functions/theme.php",
|
||||
"inc/driver/http-driver.php",
|
||||
"inc/driver/log-driver.php",
|
||||
"inc/service/captcha-queries.php"
|
||||
|
12
inc/bans.php
12
inc/bans.php
@ -15,7 +15,7 @@ class Bans {
|
||||
$query->bindValue(':id', $ban_ids[0], PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error());
|
||||
|
||||
rebuildThemes('bans');
|
||||
Vichan\Functions\Theme\rebuild_themes('bans');
|
||||
} elseif ($len >= 1) {
|
||||
// Build the query.
|
||||
$query = 'DELETE FROM ``bans`` WHERE `id` IN (';
|
||||
@ -33,7 +33,7 @@ class Bans {
|
||||
|
||||
$query->execute() or error(db_error());
|
||||
|
||||
rebuildThemes('bans');
|
||||
Vichan\Functions\Theme\rebuild_themes('bans');
|
||||
}
|
||||
}
|
||||
|
||||
@ -343,7 +343,7 @@ class Bans {
|
||||
|
||||
static public function seen($ban_id) {
|
||||
$query = query("UPDATE ``bans`` SET `seen` = 1 WHERE `id` = " . (int)$ban_id) or error(db_error());
|
||||
rebuildThemes('bans');
|
||||
Vichan\Functions\Theme\rebuild_themes('bans');
|
||||
}
|
||||
|
||||
static public function purge($require_seen, $moratorium) {
|
||||
@ -358,7 +358,7 @@ class Bans {
|
||||
|
||||
$affected = $query->rowCount();
|
||||
if ($affected > 0) {
|
||||
rebuildThemes('bans');
|
||||
Vichan\Functions\Theme\rebuild_themes('bans');
|
||||
}
|
||||
return $affected;
|
||||
}
|
||||
@ -386,7 +386,7 @@ class Bans {
|
||||
|
||||
query("DELETE FROM ``bans`` WHERE `id` = " . (int)$ban_id) or error(db_error());
|
||||
|
||||
if (!$dont_rebuild) rebuildThemes('bans');
|
||||
if (!$dont_rebuild) Vichan\Functions\Theme\rebuild_themes('bans');
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -465,7 +465,7 @@ class Bans {
|
||||
|
||||
modLog("Created a new $ban_len ban on $ban_board for $ban_ip (<small># $ban_id </small>) with $ban_reason");
|
||||
|
||||
rebuildThemes('bans');
|
||||
Vichan\Functions\Theme\rebuild_themes('bans');
|
||||
|
||||
return $pdo->lastInsertId();
|
||||
}
|
||||
|
@ -85,24 +85,24 @@ function sb_api($b) { global $config, $build_pages;
|
||||
}
|
||||
|
||||
function sb_ukko() {
|
||||
rebuildTheme("ukko", "post-thread");
|
||||
Vichan\Functions\Theme\rebuild_theme("ukko", "post-thread");
|
||||
return true;
|
||||
}
|
||||
|
||||
function sb_catalog($b) {
|
||||
if (!openBoard($b)) return false;
|
||||
|
||||
rebuildTheme("catalog", "post-thread", $b);
|
||||
Vichan\Functions\Theme\rebuild_theme("catalog", "post-thread", $b);
|
||||
return true;
|
||||
}
|
||||
|
||||
function sb_recent() {
|
||||
rebuildTheme("recent", "post-thread");
|
||||
Vichan\Functions\Theme\rebuild_theme("recent", "post-thread");
|
||||
return true;
|
||||
}
|
||||
|
||||
function sb_sitemap() {
|
||||
rebuildTheme("sitemap", "all");
|
||||
Vichan\Functions\Theme\rebuild_theme("sitemap", "all");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -397,108 +397,6 @@ function create_antibot($board, $thread = null) {
|
||||
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 = '%') {
|
||||
$replaces = array();
|
||||
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 rebuild_themes(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']."... ";
|
||||
}
|
||||
|
||||
rebuild_theme($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 load_theme_config($_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 rebuild_theme($theme, string $action, $board = false) {
|
||||
global $config, $_theme;
|
||||
$_theme = $theme;
|
||||
|
||||
$theme = load_theme_config($_theme);
|
||||
|
||||
if (file_exists($config['dir']['themes'] . '/' . $_theme . '/theme.php')) {
|
||||
require_once $config['dir']['themes'] . '/' . $_theme . '/theme.php';
|
||||
|
||||
$theme['build_function']($action, theme_settings($_theme), $board);
|
||||
}
|
||||
}
|
||||
|
||||
function theme_settings($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;
|
||||
}
|
@ -442,7 +442,7 @@ function mod_edit_board($boardName) {
|
||||
cache::delete('all_boards');
|
||||
}
|
||||
|
||||
rebuildThemes('boards');
|
||||
Vichan\Functions\Theme\rebuild_themes('boards');
|
||||
|
||||
header('Location: ?/', true, $config['redirect_http']);
|
||||
} else {
|
||||
@ -514,7 +514,7 @@ function mod_new_board() {
|
||||
// Build the board
|
||||
buildIndex();
|
||||
|
||||
rebuildThemes('boards');
|
||||
Vichan\Functions\Theme\rebuild_themes('boards');
|
||||
|
||||
header('Location: ?/' . $board['uri'] . '/' . $config['file_index'], true, $config['redirect_http']);
|
||||
}
|
||||
@ -617,7 +617,7 @@ function mod_news($page_no = 1) {
|
||||
|
||||
modLog('Posted a news entry');
|
||||
|
||||
rebuildThemes('news');
|
||||
Vichan\Functions\Theme\rebuild_themes('news');
|
||||
|
||||
header('Location: ?/edit_news#' . $pdo->lastInsertId(), true, $config['redirect_http']);
|
||||
}
|
||||
@ -1013,7 +1013,7 @@ function mod_bans() {
|
||||
foreach ($unban as $id) {
|
||||
Bans::delete($id, true, $mod['boards'], true);
|
||||
}
|
||||
rebuildThemes('bans');
|
||||
Vichan\Functions\Theme\rebuild_themes('bans');
|
||||
header('Location: ?/bans', true, $config['redirect_http']);
|
||||
return;
|
||||
}
|
||||
@ -1281,7 +1281,7 @@ function mod_move_reply($originBoard, $postID) {
|
||||
buildThread($newID);
|
||||
|
||||
// trigger themes
|
||||
rebuildThemes('post', $targetBoard);
|
||||
Vichan\Functions\Theme\rebuild_themes('post', $targetBoard);
|
||||
// mod log
|
||||
modLog("Moved post #{$postID} to " . sprintf($config['board_abbreviation'], $targetBoard) . " (#{$newID})", $originBoard);
|
||||
|
||||
@ -1469,7 +1469,7 @@ function mod_move($originBoard, $postID) {
|
||||
buildIndex();
|
||||
|
||||
// trigger themes
|
||||
rebuildThemes('post', $targetBoard);
|
||||
Vichan\Functions\Theme\rebuild_themes('post', $targetBoard);
|
||||
|
||||
$newboard = $board;
|
||||
|
||||
@ -1576,7 +1576,7 @@ function mod_ban_post($board, $delete, $post, $token = false) {
|
||||
// Rebuild board
|
||||
buildIndex();
|
||||
// Rebuild themes
|
||||
rebuildThemes('post-delete', $board);
|
||||
Vichan\Functions\Theme\rebuild_themes('post-delete', $board);
|
||||
}
|
||||
|
||||
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
|
||||
@ -1651,7 +1651,7 @@ function mod_edit_post($board, $edit_raw_html, $postID) {
|
||||
|
||||
buildIndex();
|
||||
|
||||
rebuildThemes('post', $board);
|
||||
Vichan\Functions\Theme\rebuild_themes('post', $board);
|
||||
|
||||
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['dir']['res'] . link_for($post) . '#' . $postID, true, $config['redirect_http']);
|
||||
} else {
|
||||
@ -1689,7 +1689,7 @@ function mod_delete($board, $post) {
|
||||
// Rebuild board
|
||||
buildIndex();
|
||||
// Rebuild themes
|
||||
rebuildThemes('post-delete', $board);
|
||||
Vichan\Functions\Theme\rebuild_themes('post-delete', $board);
|
||||
// Redirect
|
||||
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
|
||||
}
|
||||
@ -1711,7 +1711,7 @@ function mod_deletefile($board, $post, $file) {
|
||||
// Rebuild board
|
||||
buildIndex();
|
||||
// Rebuild themes
|
||||
rebuildThemes('post-delete', $board);
|
||||
Vichan\Functions\Theme\rebuild_themes('post-delete', $board);
|
||||
|
||||
// Redirect
|
||||
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
|
||||
@ -1756,7 +1756,7 @@ function mod_spoiler_image($board, $post, $file) {
|
||||
buildIndex();
|
||||
|
||||
// Rebuild themes
|
||||
rebuildThemes('post-delete', $board);
|
||||
Vichan\Functions\Theme\rebuild_themes('post-delete', $board);
|
||||
|
||||
// Redirect
|
||||
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
|
||||
@ -1807,7 +1807,7 @@ function mod_deletebyip($boardName, $post, $global = false) {
|
||||
|
||||
deletePost($post['id'], false, false);
|
||||
|
||||
rebuildThemes('post-delete', $board['uri']);
|
||||
Vichan\Functions\Theme\rebuild_themes('post-delete', $board['uri']);
|
||||
|
||||
buildIndex();
|
||||
|
||||
@ -2233,7 +2233,7 @@ function mod_rebuild() {
|
||||
|
||||
if (isset($_POST['rebuild_themes'])) {
|
||||
$log[] = 'Regenerating theme files';
|
||||
rebuildThemes('all');
|
||||
Vichan\Functions\Theme\rebuild_themes('all');
|
||||
}
|
||||
|
||||
if (isset($_POST['rebuild_javascript'])) {
|
||||
@ -2622,7 +2622,7 @@ function mod_themes_list() {
|
||||
$themes = array();
|
||||
while ($file = readdir($dir)) {
|
||||
if ($file[0] != '.' && is_dir($config['dir']['themes'] . '/' . $file)) {
|
||||
$themes[$file] = loadThemeConfig($file);
|
||||
$themes[$file] = Vichan\Functions\Theme\load_theme_config($file);
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
@ -2644,7 +2644,7 @@ function mod_theme_configure($theme_name) {
|
||||
if (!hasPermission($config['mod']['themes']))
|
||||
error($config['error']['noaccess']);
|
||||
|
||||
if (!$theme = loadThemeConfig($theme_name)) {
|
||||
if (!$theme = Vichan\Functions\Theme\load_theme_config($theme_name)) {
|
||||
error($config['error']['invalidtheme']);
|
||||
}
|
||||
|
||||
@ -2682,7 +2682,7 @@ function mod_theme_configure($theme_name) {
|
||||
$result = true;
|
||||
$message = false;
|
||||
if (isset($theme['install_callback'])) {
|
||||
$ret = $theme['install_callback'](themeSettings($theme_name));
|
||||
$ret = $theme['install_callback'](Vichan\Functions\Theme\theme_settings($theme_name));
|
||||
if ($ret && !empty($ret)) {
|
||||
if (is_array($ret) && count($ret) == 2) {
|
||||
$result = $ret[0];
|
||||
@ -2699,7 +2699,7 @@ function mod_theme_configure($theme_name) {
|
||||
}
|
||||
|
||||
// Build themes
|
||||
rebuildThemes('all');
|
||||
Vichan\Functions\Theme\rebuild_themes('all');
|
||||
|
||||
mod_page(sprintf(_($result ? 'Installed theme: %s' : 'Installation failed: %s'), $theme['name']), $config['file_mod_theme_installed'], array(
|
||||
'theme_name' => $theme_name,
|
||||
@ -2710,7 +2710,7 @@ function mod_theme_configure($theme_name) {
|
||||
return;
|
||||
}
|
||||
|
||||
$settings = themeSettings($theme_name);
|
||||
$settings = Vichan\Functions\Theme\theme_settings($theme_name);
|
||||
|
||||
mod_page(sprintf(_('Configuring theme: %s'), $theme['name']), $config['file_mod_theme_config'], array(
|
||||
'theme_name' => $theme_name,
|
||||
@ -2743,7 +2743,7 @@ function mod_theme_rebuild($theme_name) {
|
||||
if (!hasPermission($config['mod']['themes']))
|
||||
error($config['error']['noaccess']);
|
||||
|
||||
rebuildTheme($theme_name, 'all');
|
||||
Vichan\Functions\Theme\rebuild_theme($theme_name, 'all');
|
||||
|
||||
mod_page(sprintf(_('Rebuilt theme: %s'), $theme_name), $config['file_mod_theme_rebuilt'], array(
|
||||
'theme_name' => $theme_name,
|
||||
|
6
post.php
6
post.php
@ -477,7 +477,7 @@ if (isset($_POST['delete'])) {
|
||||
if (function_exists('fastcgi_finish_request'))
|
||||
@fastcgi_finish_request();
|
||||
|
||||
rebuildThemes('post-delete', $board['uri']);
|
||||
Vichan\Functions\Theme\rebuild_themes('post-delete', $board['uri']);
|
||||
|
||||
} elseif (isset($_POST['report'])) {
|
||||
if (!isset($_POST['board'], $_POST['reason']))
|
||||
@ -1429,9 +1429,9 @@ if (isset($_POST['delete'])) {
|
||||
@fastcgi_finish_request();
|
||||
|
||||
if ($post['op'])
|
||||
rebuildThemes('post-thread', $board['uri']);
|
||||
Vichan\Functions\Theme\rebuild_themes('post-thread', $board['uri']);
|
||||
else
|
||||
rebuildThemes('post', $board['uri']);
|
||||
Vichan\Functions\Theme\rebuild_themes('post', $board['uri']);
|
||||
|
||||
} elseif (isset($_POST['appeal'])) {
|
||||
if (!isset($_POST['ban_id']))
|
||||
|
Loading…
x
Reference in New Issue
Block a user