Browse Source

Changes and fixes on get_theme_info() and InstallFile()

Signed-off-by: Suki <[email protected]>
Suki 10 years ago
parent
commit
55c82e6e2b
2 changed files with 16 additions and 10 deletions
  1. 13 10
      Sources/Subs-Themes.php
  2. 3 0
      Sources/Themes.php

+ 13 - 10
Sources/Subs-Themes.php

@@ -120,7 +120,8 @@ function get_all_themes()
 
 function get_theme_info($path)
 {
-	global $sourcedir, $forum_version, $explicit_images;
+	global $sourcedir, $forum_version, $txt, $scripturl, $context;
+	global $explicit_images;
 
 	if (empty($path))
 		return false;
@@ -128,6 +129,15 @@ function get_theme_info($path)
 	$xml_data = array();
 	$explicit_images = false;
 
+	// Perhaps they are trying to install a mod, lets tell them nicely this is the wrong function.
+	if (file_exists($path . '/package-info.xml'))
+	{
+		loadLanguage('Errors');
+
+		$txt['package_get_error_is_mod'] = str_replace('{MANAGEMODURL}', $scripturl . '?action=admin;area=packages;' . $context['session_var'] . '=' . $context['session_id'], $txt['package_get_error_is_mod']);
+		fatal_lang_error('package_theme_upload_error_broken', false, $txt['package_get_error_is_mod']);
+	}
+
 	// Parse theme-info.xml into an xmlArray.
 	require_once($sourcedir . '/Class-Package.php');
 	$theme_info_xml = new xmlArray(file_get_contents($path . '/theme_info.xml'));
@@ -181,8 +191,8 @@ function get_theme_info($path)
 
 function theme_install($to_install = array())
 {
-	global $smcFunc, $txt, $context, $themedir, $themeurl;
-	global $settings, $explicit_images, $modSettings;
+	global $smcFunc, $context, $themedir, $themeurl, $modSettings;
+	global $settings, $explicit_images;
 
 	// External use? no problem!
 	if ($to_install)
@@ -192,13 +202,6 @@ function theme_install($to_install = array())
 	if (empty($context['to_install']['theme_dir']) || basename($context['to_install']['theme_dir']) == 'Themes')
 		fatal_lang_error('theme_install_invalid_dir', false);
 
-	// Perhaps they are trying to install a mod, lets tell them nicely this is the wrong function.
-	if (file_exists($context['to_install']['theme_dir'] . '/package-info.xml'))
-	{
-		$txt['package_get_error_is_mod'] = str_replace('{MANAGEMODURL}', $scripturl . '?action=admin;area=packages;' . $context['session_var'] . '=' . $context['session_id'], $txt['package_get_error_is_mod']);
-		fatal_lang_error('package_theme_upload_error_broken', false, $txt['package_get_error_is_mod']);
-	}
-
 	// OK, is this a newer version of an already installed theme?
 	if (!empty($context['to_install']['version']))
 	{

+ 3 - 0
Sources/Themes.php

@@ -1304,6 +1304,8 @@ function InstallFile()
 	$context['to_install'] = array(
 		'theme_dir' => $themedir . '/' . $name,
 		'theme_url' => $themeurl . '/' . $name,
+		'images_url' => $themeurl . '/' . $name . '/images',
+		'name' => $name,
 	);
 
 	// Extract the file on the proper themes dir.
@@ -1312,6 +1314,7 @@ function InstallFile()
 	if ($extracted)
 	{
 		// Read its info form the XML file.
+		$theme_info = get_theme_info($context['to_install']['theme_dir']);
 		$context['to_install'] += $theme_info;
 
 		// Install the theme. theme_install() will take care of possible errors.