summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSavetheinternet <savetheinternet@n0v4.com>2011-04-14 20:43:34 +1000
committerSavetheinternet <savetheinternet@n0v4.com>2011-04-14 20:43:34 +1000
commit641f925dfebf2540a6d7e94e23e302c4a30dc58b (patch)
treef40d984c1de2fb914f64ee5e209aee2b1aed81d6
parent757b09dec938c541dc5c858474b07c47b25248dc (diff)
better rebuilding system for themes
-rw-r--r--inc/functions.php14
-rw-r--r--mod.php22
-rw-r--r--templates/homepage/basic/theme.php14
-rw-r--r--templates/homepage/frameset/theme.php22
-rw-r--r--templates/homepage/frameset/thumb.pngbin12142 -> 7571 bytes
5 files changed, 54 insertions, 18 deletions
diff --git a/inc/functions.php b/inc/functions.php
index b90abe1b..cec25137 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -104,13 +104,13 @@
return $theme;
}
- function rebuildTheme() {
+ function rebuildTheme($action) {
$query = query("SELECT `value` AS `theme` FROM `theme_settings` WHERE `name` = 'theme'") or error(db_error());
if($theme = $query->fetch()) {
// A theme is installed
$theme = loadThemeConfig($theme['theme']);
- $theme['build_function'](themeSettings());
+ $theme['build_function']($action, themeSettings());
}
}
@@ -799,10 +799,16 @@
$content .= '<div style="display:none"><input type="text" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . '" /></div>';
break;
case 6:
- $content .= '<textarea style="display:none" name="' . htmlspecialchars($name) . '">' . htmlspecialchars($value) . '</textarea>';
+ if(!empty($value))
+ $content .= '<textarea style="display:none" name="' . htmlspecialchars($name) . '">' . htmlspecialchars($value) . '</textarea>';
+ else
+ $content .= '<input type="hidden" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . '" />';
break;
case 7:
- $content .= '<textarea name="' . htmlspecialchars($name) . '" style="display:none">' . htmlspecialchars($value) . '</textarea>';
+ if(!empty($value))
+ $content .= '<textarea name="' . htmlspecialchars($name) . '" style="display:none">' . htmlspecialchars($value) . '</textarea>';
+ else
+ $content .= '<input type="hidden" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . '" />';
break;
case 8:
$content .= '<div style="display:none"><textarea name="' . htmlspecialchars($name) . '" style="display:none">' . htmlspecialchars($value) . '</textarea></div>';
diff --git a/mod.php b/mod.php
index 8a27a44d..14bed8d1 100644
--- a/mod.php
+++ b/mod.php
@@ -304,7 +304,15 @@
$query->execute() or error(db_error($query));
// Build theme
- $theme['build_function'](themeSettings());
+ rebuildTheme('all');
+
+ echo Element('page.html', Array(
+ 'config'=>$config,
+ 'title'=>'Installed "' . htmlentities($theme['name']) . '"',
+ 'body'=>'<p style="text-align:center">Successfully installed and built theme.</p>',
+ 'mod'=>true
+ )
+ );
} else {
$body = '<form action="" method="post">';
@@ -481,7 +489,7 @@
$query->bindValue(':id', $match[1], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
- rebuildTheme();
+ rebuildTheme('news');
header('Location: ?/news', true, $config['redirect_http']);
} elseif(preg_match('/^\/news$/', $query)) {
@@ -504,7 +512,7 @@
$query->bindValue(':body', $_POST['body']);
$query->execute() or error(db_error($query));
- rebuildTheme();
+ rebuildTheme('news');
}
$body .= '<fieldset><legend>New post</legend><form style="display:inline" action="" method="post"><table>' .
@@ -1197,6 +1205,8 @@
$query->bindValue(':id', $board['id'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
+ rebuildTheme('boards');
+
header('Location: ?/', true, $config['redirect_http']);
} else {
if(isset($_POST['title']) && isset($_POST['subtitle'])) {
@@ -1211,6 +1221,8 @@
$query->bindValue(':id', $board['id'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
+ rebuildTheme('boards');
+
openBoard($board['uri']);
}
@@ -1364,7 +1376,7 @@
$body = '<div class="ban"><h2>Rebuilding…</h2><p>';
$body .= 'Regenerating theme files…<br/>';
- rebuildTheme();
+ rebuildTheme('all');
$body .= 'Generating Javascript file…<br/>';
buildJavascript();
@@ -1510,6 +1522,8 @@
// Build the board
buildIndex();
+ rebuildTheme('boards');
+
header('Location: ?/board/' . $board['uri'], true, $config['redirect_http']);
} else {
diff --git a/templates/homepage/basic/theme.php b/templates/homepage/basic/theme.php
index 1251cfff..6a6f0bfa 100644
--- a/templates/homepage/basic/theme.php
+++ b/templates/homepage/basic/theme.php
@@ -25,16 +25,22 @@
// Unique function name for building everything
$theme['build_function'] = 'basic_build';
- function basic_build($settings) {
- Basic::build($settings);
+ function basic_build($action, $settings) {
+ // Possible values for $action:
+ // - all (rebuild everything, initialization)
+ // - news (news has been updated)
+ // - boards (board list changed)
+
+ Basic::build($action, $settings);
}
// Wrap functions in a class so they don't interfere with normal Tinyboard operations
class Basic {
- public static function build($settings) {
+ public static function build($action, $settings) {
global $config;
- file_put_contents($config['dir']['home'] . $config['file_index'], Basic::homepage($settings));
+ if($action == 'all' || $action == 'news')
+ file_put_contents($config['dir']['home'] . $config['file_index'], Basic::homepage($settings));
}
// Build news page
diff --git a/templates/homepage/frameset/theme.php b/templates/homepage/frameset/theme.php
index 8b96402d..6c82f0b1 100644
--- a/templates/homepage/frameset/theme.php
+++ b/templates/homepage/frameset/theme.php
@@ -28,18 +28,28 @@ Users never have to leave the homepage; they can do all their browsing from the
// Unique function name for building everything
$theme['build_function'] = 'frameset_build';
- function frameset_build($settings) {
- Frameset::build($settings);
+ function frameset_build($action, $settings) {
+ // Possible values for $action:
+ // - all (rebuild everything, initialization)
+ // - news (news has been updated)
+ // - boards (board list changed)
+
+ Frameset::build($action, $settings);
}
// Wrap functions in a class so they don't interfere with normal Tinyboard operations
class Frameset {
- public static function build($settings) {
+ public static function build($action, $settings) {
global $config;
- file_put_contents($config['dir']['home'] . $config['file_index'], Frameset::homepage($settings));
- file_put_contents($config['dir']['home'] . 'sidebar.html', Frameset::sidebar($settings));
- file_put_contents($config['dir']['home'] . 'news.html', Frameset::news($settings));
+ if($action == 'all')
+ file_put_contents($config['dir']['home'] . $config['file_index'], Frameset::homepage($settings));
+
+ if($action == 'all' || $action == 'boards')
+ file_put_contents($config['dir']['home'] . 'sidebar.html', Frameset::sidebar($settings));
+
+ if($action == 'all' || $action == 'news')
+ file_put_contents($config['dir']['home'] . 'news.html', Frameset::news($settings));
}
// Build homepage
diff --git a/templates/homepage/frameset/thumb.png b/templates/homepage/frameset/thumb.png
index fd912d1a..df18a8e9 100644
--- a/templates/homepage/frameset/thumb.png
+++ b/templates/homepage/frameset/thumb.png
Binary files differ