From 459f442b5764497e30dcf6c00394addc052420f2 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Wed, 13 Apr 2011 23:47:47 +1000 Subject: Some sort of theme/homepage start --- mod.php | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 2c112d57..90872734 100644 --- a/mod.php +++ b/mod.php @@ -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 = '
'; + + if(!isset($theme['config']) || empty($theme['config'])) { + $body .= '

(No configuration required.)

'; + } else { + $body .= ''; + foreach($theme['config'] as &$c) { + $body .= ''; + } + $body .= '
' . $c['title'] . ''; + switch($c['type']) { + case 'text': + default: + $body .= ''; + } + $body .= '
'; + } + + $body .= '

'; + + 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 = '

(No themes installed.)

'; + } else { + $body .= ''; + foreach($themes as &$_theme) { + $theme = loadThemeConfig($_theme); + + markup($theme['description']); + + $body .= '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + ''; + } + $body .= '
Name' . htmlentities($theme['name']) . '
Version' . htmlentities($theme['version']) . '
Description' . $theme['description'] . '
Thumbnail
Actions
    ' . + '
  • ' . + 'Use' . + '
  • ' . + '
  • ' . + confirmLink('Remove', 'Uninstall theme', 'Are you sure you want to permanently remove this theme?', 'themes/' . $_theme . '/uninstall') . + '
  • ' . + '
'; + } + 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']); -- cgit v1.3