diff options
| -rw-r--r-- | inc/config.php | 9 | ||||
| -rw-r--r-- | inc/functions.php | 19 | ||||
| -rw-r--r-- | mod.php | 125 | ||||
| -rw-r--r-- | templates/homepage/frameset/theme.php | 89 | ||||
| -rw-r--r-- | templates/homepage/frameset/thumb.PNG | bin | 0 -> 12142 bytes | |||
| -rw-r--r-- | templates/homepage/frameset/thumb.png | bin | 0 -> 19329 bytes |
6 files changed, 242 insertions, 0 deletions
diff --git a/inc/config.php b/inc/config.php index 58b6a860..020120e3 100644 --- a/inc/config.php +++ b/inc/config.php @@ -208,6 +208,13 @@ //$config['dir']['static'] = $config['root'] . 'static/'; // Where to store the .html templates. This folder and templates must exist or fatal errors will be thrown. $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 // These can be URLs OR base64 (data URI scheme) //$config['image_sticky'] = $config['dir']['static'] . 'sticky.gif'; @@ -393,6 +400,8 @@ $config['mod']['noticeboard_delete'] = ADMIN; // Public ban messages; attached to posts $config['mod']['public_ban'] = MOD; + // Manage and install themes for homepage + $config['mod']['themes'] = ADMIN; // Mod links (full HTML) // Correspond to above permission directives diff --git a/inc/functions.php b/inc/functions.php index 7ec58e79..144cdec1 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -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 = '%') { $replaces = array(); foreach($vars as $k => $v) { @@ -247,6 +247,131 @@ '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)) { if($mod['type'] < $config['mod']['noticeboard_delete']) error($config['error']['noaccess']); diff --git a/templates/homepage/frameset/theme.php b/templates/homepage/frameset/theme.php new file mode 100644 index 00000000..3964a469 --- /dev/null +++ b/templates/homepage/frameset/theme.php @@ -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; + } + }; + +?>
\ No newline at end of file diff --git a/templates/homepage/frameset/thumb.PNG b/templates/homepage/frameset/thumb.PNG Binary files differnew file mode 100644 index 00000000..fd912d1a --- /dev/null +++ b/templates/homepage/frameset/thumb.PNG diff --git a/templates/homepage/frameset/thumb.png b/templates/homepage/frameset/thumb.png Binary files differnew file mode 100644 index 00000000..918ec5e6 --- /dev/null +++ b/templates/homepage/frameset/thumb.png |
