mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-30 18:24:29 +01:00
Some sort of theme/homepage start
This commit is contained in:
parent
b895102563
commit
459f442b57
@ -208,6 +208,13 @@
|
|||||||
//$config['dir']['static'] = $config['root'] . 'static/';
|
//$config['dir']['static'] = $config['root'] . 'static/';
|
||||||
// Where to store the .html templates. This folder and templates must exist or fatal errors will be thrown.
|
// Where to store the .html templates. This folder and templates must exist or fatal errors will be thrown.
|
||||||
$config['dir']['template'] = getcwd() . '/templates';
|
$config['dir']['template'] = getcwd() . '/templates';
|
||||||
|
// For the homepage generation files (themes, etc.)
|
||||||
|
$config['dir']['homepage'] = getcwd() . '/templates/homepage';
|
||||||
|
// Same as above, but a URI (accessable by web interface, not locally)
|
||||||
|
$config['dir']['homepage_uri'] = 'templates/homepage';
|
||||||
|
// Homepage directory
|
||||||
|
$config['dir']['home'] = '';
|
||||||
|
|
||||||
// Static images
|
// Static images
|
||||||
// These can be URLs OR base64 (data URI scheme)
|
// These can be URLs OR base64 (data URI scheme)
|
||||||
//$config['image_sticky'] = $config['dir']['static'] . 'sticky.gif';
|
//$config['image_sticky'] = $config['dir']['static'] . 'sticky.gif';
|
||||||
@ -393,6 +400,8 @@
|
|||||||
$config['mod']['noticeboard_delete'] = ADMIN;
|
$config['mod']['noticeboard_delete'] = ADMIN;
|
||||||
// Public ban messages; attached to posts
|
// Public ban messages; attached to posts
|
||||||
$config['mod']['public_ban'] = MOD;
|
$config['mod']['public_ban'] = MOD;
|
||||||
|
// Manage and install themes for homepage
|
||||||
|
$config['mod']['themes'] = ADMIN;
|
||||||
|
|
||||||
// Mod links (full HTML)
|
// Mod links (full HTML)
|
||||||
// Correspond to above permission directives
|
// Correspond to above permission directives
|
||||||
|
@ -93,6 +93,25 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadThemeConfig($_theme) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
// Load theme information into $theme
|
||||||
|
include $config['dir']['homepage'] . '/' . $_theme . '/theme.php';
|
||||||
|
return $theme;
|
||||||
|
}
|
||||||
|
|
||||||
|
function themeSettings() {
|
||||||
|
$query = query("SELECT * FROM `theme_settings`") or error(db_error());
|
||||||
|
$settings = Array();
|
||||||
|
|
||||||
|
while($s = $query->fetch()) {
|
||||||
|
$settings[$s['name']] = $s['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $settings;
|
||||||
|
}
|
||||||
|
|
||||||
function sprintf3($str, $vars, $delim = '%') {
|
function sprintf3($str, $vars, $delim = '%') {
|
||||||
$replaces = array();
|
$replaces = array();
|
||||||
foreach($vars as $k => $v) {
|
foreach($vars as $k => $v) {
|
||||||
|
125
mod.php
125
mod.php
@ -247,6 +247,131 @@
|
|||||||
'mod'=>true
|
'mod'=>true
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
} elseif(preg_match('/^\/themes(\/(\w+))?$/', $query, $match)) {
|
||||||
|
if($mod['type'] < $config['mod']['themes']) error($config['error']['noaccess']);
|
||||||
|
|
||||||
|
if(!is_dir($config['dir']['homepage']))
|
||||||
|
error('Homepage directory doesn\'t exist!');
|
||||||
|
if(!$dir = opendir($config['dir']['homepage']))
|
||||||
|
error('Cannot open homepage directory; check permissions.');
|
||||||
|
|
||||||
|
if(isset($match[2])) {
|
||||||
|
$_theme = $match[2];
|
||||||
|
|
||||||
|
$theme = loadThemeConfig($_theme);
|
||||||
|
|
||||||
|
if(isset($_POST['install'])) {
|
||||||
|
// Check if everything is submitted
|
||||||
|
foreach($theme['config'] as &$c) {
|
||||||
|
if(!isset($_POST[$c['name']]) && $c['type'] != 'checkbox')
|
||||||
|
error(spritnf($config['error']['required'], $c['title']));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear previous settings
|
||||||
|
query("TRUNCATE TABLE `theme_settings`") or error(db_error());
|
||||||
|
|
||||||
|
foreach($theme['config'] as &$c) {
|
||||||
|
$query = prepare("INSERT INTO `theme_settings` VALUES(:name, :value)");
|
||||||
|
$query->bindValue(':name', $c['name']);
|
||||||
|
$query->bindValue(':value', $_POST[$c['name']]);
|
||||||
|
$query->execute() or error(db_error($query));
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = prepare("INSERT INTO `theme_settings` VALUES('theme', :value)");
|
||||||
|
$query->bindValue(':value', $_theme);
|
||||||
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
|
// Build theme
|
||||||
|
$config['build_function'](themeSettings());
|
||||||
|
} else {
|
||||||
|
$body = '<form action="" method="post">';
|
||||||
|
|
||||||
|
if(!isset($theme['config']) || empty($theme['config'])) {
|
||||||
|
$body .= '<p style="text-align:center" class="unimportant">(No configuration required.)</p>';
|
||||||
|
} else {
|
||||||
|
$body .= '<table>';
|
||||||
|
foreach($theme['config'] as &$c) {
|
||||||
|
$body .= '<tr><th>' . $c['title'] . '</th><td>';
|
||||||
|
switch($c['type']) {
|
||||||
|
case 'text':
|
||||||
|
default:
|
||||||
|
$body .= '<input type="text" name="' . $c['name'] . '" />';
|
||||||
|
}
|
||||||
|
$body .= '</td></tr>';
|
||||||
|
}
|
||||||
|
$body .= '</table>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$body .= '<p style="text-align:center"><input name="install" type="submit" value="Install theme" /></p></form>';
|
||||||
|
|
||||||
|
echo Element('page.html', Array(
|
||||||
|
'config'=>$config,
|
||||||
|
'title'=>'Installing "' . htmlentities($theme['name']) . '"',
|
||||||
|
'body'=>$body,
|
||||||
|
'mod'=>true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Scan directory for themes
|
||||||
|
$themes = Array();
|
||||||
|
while($file = readdir($dir)) {
|
||||||
|
if($file[0] != '.' && is_dir($config['dir']['homepage'] . '/' . $file)) {
|
||||||
|
$themes[] = $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($dir);
|
||||||
|
|
||||||
|
$body = '';
|
||||||
|
if(empty($themes)) {
|
||||||
|
$body = '<p style="text-align:center" class="unimportant">(No themes installed.)</p>';
|
||||||
|
} else {
|
||||||
|
$body .= '<table class="modlog">';
|
||||||
|
foreach($themes as &$_theme) {
|
||||||
|
$theme = loadThemeConfig($_theme);
|
||||||
|
|
||||||
|
markup($theme['description']);
|
||||||
|
|
||||||
|
$body .= '<tr>' .
|
||||||
|
'<th class="minimal">Name</th>' .
|
||||||
|
'<td>' . htmlentities($theme['name']) . '</td>' .
|
||||||
|
'</tr>' .
|
||||||
|
'<tr>' .
|
||||||
|
'<th class="minimal">Version</th>' .
|
||||||
|
'<td>' . htmlentities($theme['version']) . '</td>' .
|
||||||
|
'</tr>' .
|
||||||
|
'<tr>' .
|
||||||
|
'<th class="minimal">Description</th>' .
|
||||||
|
'<td>' . $theme['description'] . '</td>' .
|
||||||
|
'</tr>' .
|
||||||
|
'<tr>' .
|
||||||
|
'<th class="minimal">Thumbnail</th>' .
|
||||||
|
'<td><img style="float:none;margin:4px" src="' . $config['dir']['homepage_uri'] . '/' . $_theme . '/thumb.png" /></td>' .
|
||||||
|
'</tr>' .
|
||||||
|
'<tr>' .
|
||||||
|
'<th class="minimal">Actions</th>' .
|
||||||
|
'<td><ul style="padding:0 20px">' .
|
||||||
|
'<li>' .
|
||||||
|
'<a title="Use theme" href="?/themes/frameset">Use</a>' .
|
||||||
|
'</li>' .
|
||||||
|
'<li>' .
|
||||||
|
confirmLink('Remove', 'Uninstall theme', 'Are you sure you want to permanently remove this theme?', 'themes/' . $_theme . '/uninstall') .
|
||||||
|
'</li>' .
|
||||||
|
'</ul></td>' .
|
||||||
|
'</tr>' .
|
||||||
|
'</tr>';
|
||||||
|
}
|
||||||
|
$body .= '</table>';
|
||||||
|
}
|
||||||
|
echo Element('page.html', Array(
|
||||||
|
'config'=>$config,
|
||||||
|
'title'=>'Select theme',
|
||||||
|
'body'=>$body,
|
||||||
|
'mod'=>true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
} elseif(preg_match('/^\/noticeboard\/delete\/(\d+)$/', $query, $match)) {
|
} elseif(preg_match('/^\/noticeboard\/delete\/(\d+)$/', $query, $match)) {
|
||||||
if($mod['type'] < $config['mod']['noticeboard_delete']) error($config['error']['noaccess']);
|
if($mod['type'] < $config['mod']['noticeboard_delete']) error($config['error']['noaccess']);
|
||||||
|
|
||||||
|
89
templates/homepage/frameset/theme.php
Normal file
89
templates/homepage/frameset/theme.php
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
$theme = Array();
|
||||||
|
|
||||||
|
// Theme name
|
||||||
|
$theme['name'] = 'Frameset';
|
||||||
|
// Description (you can use Tinyboard markup here)
|
||||||
|
$theme['description'] =
|
||||||
|
'Use a basic frameset layout, with a list of boards and pages on a sidebar to the left of the page.
|
||||||
|
|
||||||
|
Users never have to leave the homepage; they can do all their browsing from the one page.';
|
||||||
|
$theme['version'] = 'v0.1';
|
||||||
|
|
||||||
|
// Theme configuration
|
||||||
|
$theme['config'] = Array();
|
||||||
|
$theme['config'][] = Array(
|
||||||
|
'title' => 'Page title',
|
||||||
|
'name' => 'title',
|
||||||
|
'type' => 'text'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Unique function name for building everything
|
||||||
|
$config['build_function'] = 'frameset_build';
|
||||||
|
|
||||||
|
function frameset_build($settings) {
|
||||||
|
Frameset::build($settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrap functions in a class so they don't interfere with normal Tinyboard operations
|
||||||
|
class Frameset {
|
||||||
|
public static function build($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));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build homepage
|
||||||
|
public static function homepage($settings) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
// HTML5
|
||||||
|
return '<!DOCTYPE html><html>'
|
||||||
|
. '<head>'
|
||||||
|
. '<link rel="stylesheet" media="screen" href="' . $config['url_stylesheet'] . '"/>'
|
||||||
|
. '<style type="text/css">'
|
||||||
|
. 'iframe{border:none;margin:0;padding:0;height:99%;position:absolute}'
|
||||||
|
. 'iframe#sidebar{left:0;top:0;width:15%}'
|
||||||
|
. 'iframe#main{border-left:1px solid black;left:15%;top:0;width:85%}'
|
||||||
|
. '</style>'
|
||||||
|
. '<title>' . $settings['title'] . '</title>'
|
||||||
|
. '</head><body>'
|
||||||
|
// Sidebar
|
||||||
|
. '<iframe src="sidebar.html" id="sidebar"></iframe>'
|
||||||
|
// Main
|
||||||
|
. '<iframe src="b" id="main"></iframe>'
|
||||||
|
// Finish page
|
||||||
|
. '</body></html>';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build sidebar
|
||||||
|
public static function sidebar($settings) {
|
||||||
|
global $config, $board;
|
||||||
|
|
||||||
|
$body = '<!DOCTYPE html><html>'
|
||||||
|
. '<head>'
|
||||||
|
. '<style type="text/css">'
|
||||||
|
. ''
|
||||||
|
. '</style>'
|
||||||
|
. '<base target="main" />'
|
||||||
|
. '<title>' . $settings['title'] . '</title>'
|
||||||
|
. '</head><body><h2>Boards</h2><ul>';
|
||||||
|
|
||||||
|
$boards = listBoards();
|
||||||
|
foreach($boards as &$_board) {
|
||||||
|
openBoard($_board['uri']);
|
||||||
|
$body .= '<li><a href="' .
|
||||||
|
sprintf($config['board_path'], $board['uri']) .
|
||||||
|
'">' . $board['name'] . '</a></li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$body .= '</ul>'
|
||||||
|
// Finish page
|
||||||
|
. '</body></html>';
|
||||||
|
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
?>
|
BIN
templates/homepage/frameset/thumb.PNG
Normal file
BIN
templates/homepage/frameset/thumb.PNG
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
templates/homepage/frameset/thumb.png
Normal file
BIN
templates/homepage/frameset/thumb.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
Loading…
Reference in New Issue
Block a user