1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-12-02 19:17:21 +01:00

theme.php: rename functions to snake_case

This commit is contained in:
Zankaria 2024-08-16 18:32:32 +02:00
parent 453ae795f5
commit d408ed0413
5 changed files with 39 additions and 39 deletions

View File

@ -15,7 +15,7 @@ class Bans {
$query->bindValue(':id', $ban_ids[0], PDO::PARAM_INT); $query->bindValue(':id', $ban_ids[0], PDO::PARAM_INT);
$query->execute() or error(db_error()); $query->execute() or error(db_error());
rebuildThemes('bans'); Vichan\Functions\Theme\rebuild_themes('bans');
} elseif ($len >= 1) { } elseif ($len >= 1) {
// Build the query. // Build the query.
$query = 'DELETE FROM ``bans`` WHERE `id` IN ('; $query = 'DELETE FROM ``bans`` WHERE `id` IN (';
@ -33,7 +33,7 @@ class Bans {
$query->execute() or error(db_error()); $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) { static public function seen($ban_id) {
$query = query("UPDATE ``bans`` SET `seen` = 1 WHERE `id` = " . (int)$ban_id) or error(db_error()); $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) { static public function purge($require_seen, $moratorium) {
@ -358,7 +358,7 @@ class Bans {
$affected = $query->rowCount(); $affected = $query->rowCount();
if ($affected > 0) { if ($affected > 0) {
rebuildThemes('bans'); Vichan\Functions\Theme\rebuild_themes('bans');
} }
return $affected; return $affected;
} }
@ -386,7 +386,7 @@ class Bans {
query("DELETE FROM ``bans`` WHERE `id` = " . (int)$ban_id) or error(db_error()); 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; 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"); 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(); return $pdo->lastInsertId();
} }

View File

@ -85,24 +85,24 @@ function sb_api($b) { global $config, $build_pages;
} }
function sb_ukko() { function sb_ukko() {
rebuildTheme("ukko", "post-thread"); Vichan\Functions\Theme\rebuild_theme("ukko", "post-thread");
return true; return true;
} }
function sb_catalog($b) { function sb_catalog($b) {
if (!openBoard($b)) return false; if (!openBoard($b)) return false;
rebuildTheme("catalog", "post-thread", $b); Vichan\Functions\Theme\rebuild_theme("catalog", "post-thread", $b);
return true; return true;
} }
function sb_recent() { function sb_recent() {
rebuildTheme("recent", "post-thread"); Vichan\Functions\Theme\rebuild_theme("recent", "post-thread");
return true; return true;
} }
function sb_sitemap() { function sb_sitemap() {
rebuildTheme("sitemap", "all"); Vichan\Functions\Theme\rebuild_theme("sitemap", "all");
return true; return true;
} }

View File

@ -2,7 +2,7 @@
namespace Vichan\Functions\Theme; namespace Vichan\Functions\Theme;
function rebuildThemes(string $action, $boardname = false): void { function rebuild_themes(string $action, $boardname = false): void {
global $config, $board, $current_locale; global $config, $board, $current_locale;
// Save the global variables // Save the global variables
@ -34,7 +34,7 @@ function rebuildThemes(string $action, $boardname = false): void {
echo "Rebuilding theme ".$theme['theme']."... "; echo "Rebuilding theme ".$theme['theme']."... ";
} }
rebuildTheme($theme['theme'], $action, $boardname); rebuild_theme($theme['theme'], $action, $boardname);
if (PHP_SAPI === 'cli') { if (PHP_SAPI === 'cli') {
echo "done\n"; echo "done\n";
@ -52,7 +52,7 @@ function rebuildThemes(string $action, $boardname = false): void {
} }
} }
function loadThemeConfig($_theme) { function load_theme_config($_theme) {
global $config; global $config;
if (!file_exists($config['dir']['themes'] . '/' . $_theme . '/info.php')) { if (!file_exists($config['dir']['themes'] . '/' . $_theme . '/info.php')) {
@ -65,20 +65,20 @@ function loadThemeConfig($_theme) {
return $theme; return $theme;
} }
function rebuildTheme($theme, string $action, $board = false) { function rebuild_theme($theme, string $action, $board = false) {
global $config, $_theme; global $config, $_theme;
$_theme = $theme; $_theme = $theme;
$theme = loadThemeConfig($_theme); $theme = load_theme_config($_theme);
if (file_exists($config['dir']['themes'] . '/' . $_theme . '/theme.php')) { if (file_exists($config['dir']['themes'] . '/' . $_theme . '/theme.php')) {
require_once $config['dir']['themes'] . '/' . $_theme . '/theme.php'; require_once $config['dir']['themes'] . '/' . $_theme . '/theme.php';
$theme['build_function']($action, themeSettings($_theme), $board); $theme['build_function']($action, theme_settings($_theme), $board);
} }
} }
function themeSettings($theme): array { function theme_settings($theme): array {
if ($settings = \Cache::get("theme_settings_" . $theme)) { if ($settings = \Cache::get("theme_settings_" . $theme)) {
return $settings; return $settings;
} }

View File

@ -442,7 +442,7 @@ function mod_edit_board($boardName) {
cache::delete('all_boards'); cache::delete('all_boards');
} }
rebuildThemes('boards'); Vichan\Functions\Theme\rebuild_themes('boards');
header('Location: ?/', true, $config['redirect_http']); header('Location: ?/', true, $config['redirect_http']);
} else { } else {
@ -514,7 +514,7 @@ function mod_new_board() {
// Build the board // Build the board
buildIndex(); buildIndex();
rebuildThemes('boards'); Vichan\Functions\Theme\rebuild_themes('boards');
header('Location: ?/' . $board['uri'] . '/' . $config['file_index'], true, $config['redirect_http']); 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'); modLog('Posted a news entry');
rebuildThemes('news'); Vichan\Functions\Theme\rebuild_themes('news');
header('Location: ?/edit_news#' . $pdo->lastInsertId(), true, $config['redirect_http']); header('Location: ?/edit_news#' . $pdo->lastInsertId(), true, $config['redirect_http']);
} }
@ -1013,7 +1013,7 @@ function mod_bans() {
foreach ($unban as $id) { foreach ($unban as $id) {
Bans::delete($id, true, $mod['boards'], true); Bans::delete($id, true, $mod['boards'], true);
} }
rebuildThemes('bans'); Vichan\Functions\Theme\rebuild_themes('bans');
header('Location: ?/bans', true, $config['redirect_http']); header('Location: ?/bans', true, $config['redirect_http']);
return; return;
} }
@ -1281,7 +1281,7 @@ function mod_move_reply($originBoard, $postID) {
buildThread($newID); buildThread($newID);
// trigger themes // trigger themes
rebuildThemes('post', $targetBoard); Vichan\Functions\Theme\rebuild_themes('post', $targetBoard);
// mod log // mod log
modLog("Moved post #{$postID} to " . sprintf($config['board_abbreviation'], $targetBoard) . " (#{$newID})", $originBoard); modLog("Moved post #{$postID} to " . sprintf($config['board_abbreviation'], $targetBoard) . " (#{$newID})", $originBoard);
@ -1469,7 +1469,7 @@ function mod_move($originBoard, $postID) {
buildIndex(); buildIndex();
// trigger themes // trigger themes
rebuildThemes('post', $targetBoard); Vichan\Functions\Theme\rebuild_themes('post', $targetBoard);
$newboard = $board; $newboard = $board;
@ -1576,7 +1576,7 @@ function mod_ban_post($board, $delete, $post, $token = false) {
// Rebuild board // Rebuild board
buildIndex(); buildIndex();
// Rebuild themes // 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']); 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(); 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']); header('Location: ?/' . sprintf($config['board_path'], $board) . $config['dir']['res'] . link_for($post) . '#' . $postID, true, $config['redirect_http']);
} else { } else {
@ -1689,7 +1689,7 @@ function mod_delete($board, $post) {
// Rebuild board // Rebuild board
buildIndex(); buildIndex();
// Rebuild themes // Rebuild themes
rebuildThemes('post-delete', $board); Vichan\Functions\Theme\rebuild_themes('post-delete', $board);
// Redirect // Redirect
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); 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 // Rebuild board
buildIndex(); buildIndex();
// Rebuild themes // Rebuild themes
rebuildThemes('post-delete', $board); Vichan\Functions\Theme\rebuild_themes('post-delete', $board);
// Redirect // Redirect
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); 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(); buildIndex();
// Rebuild themes // Rebuild themes
rebuildThemes('post-delete', $board); Vichan\Functions\Theme\rebuild_themes('post-delete', $board);
// Redirect // Redirect
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); 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); deletePost($post['id'], false, false);
rebuildThemes('post-delete', $board['uri']); Vichan\Functions\Theme\rebuild_themes('post-delete', $board['uri']);
buildIndex(); buildIndex();
@ -2233,7 +2233,7 @@ function mod_rebuild() {
if (isset($_POST['rebuild_themes'])) { if (isset($_POST['rebuild_themes'])) {
$log[] = 'Regenerating theme files'; $log[] = 'Regenerating theme files';
rebuildThemes('all'); Vichan\Functions\Theme\rebuild_themes('all');
} }
if (isset($_POST['rebuild_javascript'])) { if (isset($_POST['rebuild_javascript'])) {
@ -2622,7 +2622,7 @@ function mod_themes_list() {
$themes = array(); $themes = array();
while ($file = readdir($dir)) { while ($file = readdir($dir)) {
if ($file[0] != '.' && is_dir($config['dir']['themes'] . '/' . $file)) { if ($file[0] != '.' && is_dir($config['dir']['themes'] . '/' . $file)) {
$themes[$file] = loadThemeConfig($file); $themes[$file] = Vichan\Functions\Theme\load_theme_config($file);
} }
} }
closedir($dir); closedir($dir);
@ -2644,7 +2644,7 @@ function mod_theme_configure($theme_name) {
if (!hasPermission($config['mod']['themes'])) if (!hasPermission($config['mod']['themes']))
error($config['error']['noaccess']); error($config['error']['noaccess']);
if (!$theme = loadThemeConfig($theme_name)) { if (!$theme = Vichan\Functions\Theme\load_theme_config($theme_name)) {
error($config['error']['invalidtheme']); error($config['error']['invalidtheme']);
} }
@ -2682,7 +2682,7 @@ function mod_theme_configure($theme_name) {
$result = true; $result = true;
$message = false; $message = false;
if (isset($theme['install_callback'])) { 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 ($ret && !empty($ret)) {
if (is_array($ret) && count($ret) == 2) { if (is_array($ret) && count($ret) == 2) {
$result = $ret[0]; $result = $ret[0];
@ -2699,7 +2699,7 @@ function mod_theme_configure($theme_name) {
} }
// Build themes // 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( mod_page(sprintf(_($result ? 'Installed theme: %s' : 'Installation failed: %s'), $theme['name']), $config['file_mod_theme_installed'], array(
'theme_name' => $theme_name, 'theme_name' => $theme_name,
@ -2710,7 +2710,7 @@ function mod_theme_configure($theme_name) {
return; 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( mod_page(sprintf(_('Configuring theme: %s'), $theme['name']), $config['file_mod_theme_config'], array(
'theme_name' => $theme_name, 'theme_name' => $theme_name,
@ -2743,7 +2743,7 @@ function mod_theme_rebuild($theme_name) {
if (!hasPermission($config['mod']['themes'])) if (!hasPermission($config['mod']['themes']))
error($config['error']['noaccess']); 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( mod_page(sprintf(_('Rebuilt theme: %s'), $theme_name), $config['file_mod_theme_rebuilt'], array(
'theme_name' => $theme_name, 'theme_name' => $theme_name,

View File

@ -477,7 +477,7 @@ if (isset($_POST['delete'])) {
if (function_exists('fastcgi_finish_request')) if (function_exists('fastcgi_finish_request'))
@fastcgi_finish_request(); @fastcgi_finish_request();
rebuildThemes('post-delete', $board['uri']); Vichan\Functions\Theme\rebuild_themes('post-delete', $board['uri']);
} elseif (isset($_POST['report'])) { } elseif (isset($_POST['report'])) {
if (!isset($_POST['board'], $_POST['reason'])) if (!isset($_POST['board'], $_POST['reason']))
@ -1429,9 +1429,9 @@ if (isset($_POST['delete'])) {
@fastcgi_finish_request(); @fastcgi_finish_request();
if ($post['op']) if ($post['op'])
rebuildThemes('post-thread', $board['uri']); Vichan\Functions\Theme\rebuild_themes('post-thread', $board['uri']);
else else
rebuildThemes('post', $board['uri']); Vichan\Functions\Theme\rebuild_themes('post', $board['uri']);
} elseif (isset($_POST['appeal'])) { } elseif (isset($_POST['appeal'])) {
if (!isset($_POST['ban_id'])) if (!isset($_POST['ban_id']))