From 09268e75c807b17b042f85977b2c3cac4ef884b2 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 7 Oct 2011 00:00:13 +1100 Subject: [PATCH] theme error handling --- mod.php | 23 +++++++++++++++++++---- templates/themes/categories/info.php | 12 ++++++++++++ templates/themes/categories/theme.php | 34 +++++++++++++++++++--------------- 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/mod.php b/mod.php index 62edac7c..792efbb0 100644 --- a/mod.php +++ b/mod.php @@ -374,21 +374,36 @@ $query->bindValue(':theme', $_theme); $query->execute() or error(db_error($query)); + $result = true; $body = ''; if(isset($theme['install_callback'])) { $ret = $theme['install_callback']($theme['config']); - if($ret && !empty($ret)) + if($ret && !empty($ret)) { + if(is_array($ret) && count($ret) == 2) { + $result = $ret[0]; + $ret = $ret[1]; + } $body .= '
' . $ret . '
'; + } } - $body .= '

Successfully installed and built theme.

' . - '

Go back to themes.

'; + + if($result) { + $body .= '

Successfully installed and built theme.

'; + } else { + // install failed + $query = prepare("DELETE FROM `theme_settings` WHERE `theme` = :theme"); + $query->bindValue(':theme', $_theme); + $query->execute() or error(db_error($query)); + } + + $body .= '

Go back to themes.

'; // Build themes rebuildThemes('all'); echo Element('page.html', Array( 'config'=>$config, - 'title'=>'Installed "' . utf8tohtml($theme['name']) . '"', + 'title'=>($result ? 'Installed "' . utf8tohtml($theme['name']) . '"' : 'Installation failed!'), 'body'=>$body, 'mod'=>true ) diff --git a/templates/themes/categories/info.php b/templates/themes/categories/info.php index 0090f39d..108cc254 100644 --- a/templates/themes/categories/info.php +++ b/templates/themes/categories/info.php @@ -27,4 +27,16 @@ Requires $config[\'boards\'] and $config[\'categories\'].'; // Unique function name for building everything $theme['build_function'] = 'categories_build'; + + $theme['install_callback'] = 'categories_install'; + if(!function_exists('categories_install')) { + function categories_install($settings) { + global $config; + + if(!isset($config['boards']) || !isset($config['categories'])) { + return Array(false, '

Prerequisites not met!

' . + 'This theme requires $config[\'boards\'] and $config[\'categories\'] to be set.'); + } + } + } ?> diff --git a/templates/themes/categories/theme.php b/templates/themes/categories/theme.php index de1b4a5b..d48c150a 100644 --- a/templates/themes/categories/theme.php +++ b/templates/themes/categories/theme.php @@ -121,27 +121,31 @@ '
  • [Remove Frames]
  • ' . ''; - for($cat = 0; $cat < count($config['categories']); $cat++) { - $body .= '
    ' . $config['categories'][$cat] . '
    '; } - foreach($config['custom_categories'] as $name => &$group) { - $body .= '
    ' . $name . '
    '; } // Finish page