Browse Source

Don't install a theme if the based on one isn't already installed

Signed-off-by: Suki <[email protected]>
Suki 11 years ago
parent
commit
3aa1c9575f
2 changed files with 12 additions and 3 deletions
  1. 9 3
      Sources/Themes.php
  2. 3 0
      Themes/default/languages/Errors.english.php

+ 9 - 3
Sources/Themes.php

@@ -1518,11 +1518,10 @@ function ThemeInstall()
 				'theme_templates' => 'templates',
 				'based_on' => 'based-on',
 			);
+
 			foreach ($xml_elements as $var => $name)
-			{
 				if (!empty($theme_info_xml[$name]))
 					$install_info[$var] = $theme_info_xml[$name];
-			}
 
 			if (!empty($theme_info_xml['images']))
 			{
@@ -1536,11 +1535,14 @@ function ThemeInstall()
 
 		if (isset($install_info['based_on']))
 		{
+			// No need for elaborated stuff when the theme is based on the default one.
 			if ($install_info['based_on'] == 'default')
 			{
 				$install_info['theme_url'] = $settings['default_theme_url'];
 				$install_info['images_url'] = $settings['default_images_url'];
 			}
+
+			// Custom theme based on another custom theme, lets get some info.
 			elseif ($install_info['based_on'] != '')
 			{
 				$install_info['based_on'] = preg_replace('~[^A-Za-z0-9\-_ ]~', '', $install_info['based_on']);
@@ -1570,7 +1572,7 @@ function ThemeInstall()
 				$temp = $smcFunc['db_fetch_assoc']($request);
 				$smcFunc['db_free_result']($request);
 
-				// @todo An error otherwise?
+				// Found the based on theme info, add it to the current one being installed.
 				if (is_array($temp))
 				{
 					$install_info = $temp + $install_info;
@@ -1578,6 +1580,10 @@ function ThemeInstall()
 					if (empty($explicit_images) && !empty($install_info['base_theme_url']))
 						$install_info['theme_url'] = $install_info['base_theme_url'];
 				}
+
+				// Nope, sorry, couldn't find any theme already installed.
+				else
+					fatal_lang_error('package_get_error_theme_no_based_on_found', false, $install_info['based_on']);
 			}
 
 			unset($install_info['based_on']);

+ 3 - 0
Themes/default/languages/Errors.english.php

@@ -301,6 +301,9 @@ $txt['package_get_error_packageinfo_corrupt'] = 'SMF was unable to find any vali
 $txt['package_get_error_is_theme'] = 'You can\'t install a Theme from this section, please use the <a href="{MANAGETHEMEURL}">Themes and Layout</a> management page to upload it';
 $txt['package_get_error_is_mod'] = 'You can\'t install a mod from this section, please use the <a href="{MANAGEMODURL}">Package manager</a> page to upload it';
 $txt['package_get_error_theme_not_compatible'] = 'Your theme does not show it has compatibility with %1$s. Please contact the theme author.';
+$txt['package_get_error_theme_no_based_on_found'] = 'The theme you\'re trying to install depends on another theme: %1$s, you need to install that theme first.';
+
+
 $txt['no_membergroup_selected'] = 'No membergroup selected';
 $txt['membergroup_does_not_exist'] = 'The membergroup doesn\'t exist or is invalid.';