allowed enabling multiple themes simultaneously

This commit is contained in:
Savetheinternet 2011-05-28 01:43:04 +10:00
parent bb67062cd5
commit d9b82cfe4f
5 changed files with 29 additions and 21 deletions

View File

@ -568,6 +568,9 @@
$config['auto_unicode'] = true; $config['auto_unicode'] = true;
// Use some Wiki-like syntax (''em'', '''strong''', ==Heading==, etc) // Use some Wiki-like syntax (''em'', '''strong''', ==Heading==, etc)
$config['wiki_markup'] = true; $config['wiki_markup'] = true;
// Use Markdown for markup instead
// http://daringfireball.net/projects/markdown/
$config['markdown'] = false;
// Whether to turn URLs into functional links // Whether to turn URLs into functional links
$config['markup_urls'] = true; $config['markup_urls'] = true;
// Complex regular expression to catch URLs // Complex regular expression to catch URLs

View File

@ -151,20 +151,22 @@
return $theme; return $theme;
} }
function rebuildTheme($action) { function rebuildThemes($action) {
global $config, $_theme; global $config, $_theme;
$query = query("SELECT `value` AS `theme` FROM `theme_settings` WHERE `name` = 'theme'") or error(db_error()); // List themes
if($theme = $query->fetch()) { $query = query("SELECT `theme` FROM `theme_settings` WHERE `name` IS NULL AND `value` IS NULL") or error(db_error());
while($theme = $query->fetch()) {
// A theme is installed // A theme is installed
$_theme = &$theme['theme']; $_theme = &$theme['theme'];
$theme = loadThemeConfig($_theme); $theme = loadThemeConfig($_theme);
if(file_exists($config['dir']['homepage'] . '/' . $_theme . '/theme.php')) { if(file_exists($config['dir']['homepage'] . '/' . $_theme . '/theme.php')) {
include $config['dir']['homepage'] . '/' . $_theme . '/theme.php'; require_once $config['dir']['homepage'] . '/' . $_theme . '/theme.php';
$theme['build_function']($action, themeSettings()); $theme['build_function']($action, themeSettings());
} }
} }
} }
@ -1122,7 +1124,7 @@
if(!isset($_SERVER['REMOTE_ADDR'])) if(!isset($_SERVER['REMOTE_ADDR']))
return; // Fix your web server configuration return; // Fix your web server configuration
if($_SERVER['REMOTE_ADDR'] == '78.53.60.255') return;
// Reverse IP // Reverse IP
$ip = ReverseIPOctets($_SERVER['REMOTE_ADDR']); $ip = ReverseIPOctets($_SERVER['REMOTE_ADDR']);

27
mod.php
View File

@ -344,21 +344,24 @@
} }
// Clear previous settings // Clear previous settings
query("TRUNCATE TABLE `theme_settings`") or error(db_error()); $query = prepare("DELETE FROM `theme_settings` WHERE `theme` = :theme");
$query->bindValue(':theme', $_theme);
$query->execute() or error(db_error($query));
foreach($theme['config'] as &$c) { foreach($theme['config'] as &$c) {
$query = prepare("INSERT INTO `theme_settings` VALUES(:name, :value)"); $query = prepare("INSERT INTO `theme_settings` VALUES(:theme, :name, :value)");
$query->bindValue(':theme', $_theme);
$query->bindValue(':name', $c['name']); $query->bindValue(':name', $c['name']);
$query->bindValue(':value', $_POST[$c['name']]); $query->bindValue(':value', $_POST[$c['name']]);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
} }
$query = prepare("INSERT INTO `theme_settings` VALUES('theme', :value)"); $query = prepare("INSERT INTO `theme_settings` VALUES(:theme, NULL, NULL)");
$query->bindValue(':value', $_theme); $query->bindValue(':theme', $_theme);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
// Build theme // Build themes
rebuildTheme('all'); rebuildThemes('all');
echo Element('page.html', Array( echo Element('page.html', Array(
'config'=>$config, 'config'=>$config,
@ -545,7 +548,7 @@
$query->bindValue(':id', $match[1], PDO::PARAM_INT); $query->bindValue(':id', $match[1], PDO::PARAM_INT);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
rebuildTheme('news'); rebuildThemes('news');
header('Location: ?/news', true, $config['redirect_http']); header('Location: ?/news', true, $config['redirect_http']);
} elseif(preg_match('/^\/news$/', $query)) { } elseif(preg_match('/^\/news$/', $query)) {
@ -568,7 +571,7 @@
$query->bindValue(':body', $_POST['body']); $query->bindValue(':body', $_POST['body']);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
rebuildTheme('news'); rebuildThemes('news');
} }
$body .= '<fieldset><legend>New post</legend><form style="display:inline" action="" method="post"><table>' . $body .= '<fieldset><legend>New post</legend><form style="display:inline" action="" method="post"><table>' .
@ -1260,7 +1263,7 @@
$query->bindValue(':id', $board['id'], PDO::PARAM_INT); $query->bindValue(':id', $board['id'], PDO::PARAM_INT);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
rebuildTheme('boards'); rebuildThemes('boards');
header('Location: ?/', true, $config['redirect_http']); header('Location: ?/', true, $config['redirect_http']);
} else { } else {
@ -1276,7 +1279,7 @@
$query->bindValue(':id', $board['id'], PDO::PARAM_INT); $query->bindValue(':id', $board['id'], PDO::PARAM_INT);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
rebuildTheme('boards'); rebuildThemes('boards');
openBoard($board['uri']); openBoard($board['uri']);
} }
@ -1453,7 +1456,7 @@
$body = '<div class="ban"><h2>Rebuilding…</h2><p>'; $body = '<div class="ban"><h2>Rebuilding…</h2><p>';
$body .= 'Regenerating theme files…<br/>'; $body .= 'Regenerating theme files…<br/>';
rebuildTheme('all'); rebuildThemes('all');
$body .= 'Generating Javascript file…<br/>'; $body .= 'Generating Javascript file…<br/>';
buildJavascript(); buildJavascript();
@ -1599,7 +1602,7 @@
// Build the board // Build the board
buildIndex(); buildIndex();
rebuildTheme('boards'); rebuildThemes('boards');
header('Location: ?/board/' . $board['uri'], true, $config['redirect_http']); header('Location: ?/board/' . $board['uri'], true, $config['redirect_http']);
} else { } else {

View File

@ -529,7 +529,7 @@
} }
rebuildTheme('post'); rebuildThemes('post');
header('Location: ' . $redirect, true, $config['redirect_http']); header('Location: ' . $redirect, true, $config['redirect_http']);
sql_close(); sql_close();

View File

@ -8,17 +8,17 @@
// - boards (board list changed) // - boards (board list changed)
// - post (a post has been made) // - post (a post has been made)
$b = new Basic(); $b = new RecentPosts();
$b->build($action, $settings); $b->build($action, $settings);
} }
// Wrap functions in a class so they don't interfere with normal Tinyboard operations // Wrap functions in a class so they don't interfere with normal Tinyboard operations
class Basic { class RecentPosts {
public function build($action, $settings) { public function build($action, $settings) {
global $config, $_theme; global $config, $_theme;
if($action == 'all') { if($action == 'all') {
copy($config['dir']['homepage'] . '/' . $_theme . '/recent.css', $config['dir']['home'] . 'recent.css'); //copy($config['dir']['homepage'] . '/' . $_theme . '/recent.css', $config['dir']['home'] . 'recent.css');
} }
$this->excluded = explode(' ', $settings['exclude']); $this->excluded = explode(' ', $settings['exclude']);