Browse Source

better rebuilding system for themes

pull/40/head
Savetheinternet 13 years ago
parent
commit
641f925dfe
  1. 14
      inc/functions.php
  2. 22
      mod.php
  3. 14
      templates/homepage/basic/theme.php
  4. 22
      templates/homepage/frameset/theme.php
  5. BIN
      templates/homepage/frameset/thumb.png

14
inc/functions.php

@ -104,13 +104,13 @@
return $theme; return $theme;
} }
function rebuildTheme() { function rebuildTheme($action) {
$query = query("SELECT `value` AS `theme` FROM `theme_settings` WHERE `name` = 'theme'") or error(db_error()); $query = query("SELECT `value` AS `theme` FROM `theme_settings` WHERE `name` = 'theme'") or error(db_error());
if($theme = $query->fetch()) { if($theme = $query->fetch()) {
// A theme is installed // A theme is installed
$theme = loadThemeConfig($theme['theme']); $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>'; $content .= '<div style="display:none"><input type="text" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . '" /></div>';
break; break;
case 6: 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; break;
case 7: 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; break;
case 8: case 8:
$content .= '<div style="display:none"><textarea name="' . htmlspecialchars($name) . '" style="display:none">' . htmlspecialchars($value) . '</textarea></div>'; $content .= '<div style="display:none"><textarea name="' . htmlspecialchars($name) . '" style="display:none">' . htmlspecialchars($value) . '</textarea></div>';

22
mod.php

@ -304,7 +304,15 @@
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
// Build theme // 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 { } else {
$body = '<form action="" method="post">'; $body = '<form action="" method="post">';
@ -481,7 +489,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(); rebuildTheme('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)) {
@ -504,7 +512,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(); rebuildTheme('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>' .
@ -1197,6 +1205,8 @@
$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');
header('Location: ?/', true, $config['redirect_http']); header('Location: ?/', true, $config['redirect_http']);
} else { } else {
if(isset($_POST['title']) && isset($_POST['subtitle'])) { if(isset($_POST['title']) && isset($_POST['subtitle'])) {
@ -1211,6 +1221,8 @@
$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');
openBoard($board['uri']); openBoard($board['uri']);
} }
@ -1364,7 +1376,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(); rebuildTheme('all');
$body .= 'Generating Javascript file…<br/>'; $body .= 'Generating Javascript file…<br/>';
buildJavascript(); buildJavascript();
@ -1510,6 +1522,8 @@
// Build the board // Build the board
buildIndex(); buildIndex();
rebuildTheme('boards');
header('Location: ?/board/' . $board['uri'], true, $config['redirect_http']); header('Location: ?/board/' . $board['uri'], true, $config['redirect_http']);
} else { } else {

14
templates/homepage/basic/theme.php

@ -25,16 +25,22 @@
// Unique function name for building everything // Unique function name for building everything
$theme['build_function'] = 'basic_build'; $theme['build_function'] = 'basic_build';
function basic_build($settings) { function basic_build($action, $settings) {
Basic::build($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 // Wrap functions in a class so they don't interfere with normal Tinyboard operations
class Basic { class Basic {
public static function build($settings) { public static function build($action, $settings) {
global $config; 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 // Build news page

22
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 // Unique function name for building everything
$theme['build_function'] = 'frameset_build'; $theme['build_function'] = 'frameset_build';
function frameset_build($settings) { function frameset_build($action, $settings) {
Frameset::build($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 // Wrap functions in a class so they don't interfere with normal Tinyboard operations
class Frameset { class Frameset {
public static function build($settings) { public static function build($action, $settings) {
global $config; global $config;
file_put_contents($config['dir']['home'] . $config['file_index'], Frameset::homepage($settings)); if($action == 'all')
file_put_contents($config['dir']['home'] . 'sidebar.html', Frameset::sidebar($settings)); file_put_contents($config['dir']['home'] . $config['file_index'], Frameset::homepage($settings));
file_put_contents($config['dir']['home'] . 'news.html', Frameset::news($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 // Build homepage

BIN
templates/homepage/frameset/thumb.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

Loading…
Cancel
Save