Kaynağa Gözat

No point in calling get_theme_info() when installing a copy from default theme.

Signed-off-by: Suki <[email protected]>
Suki 11 yıl önce
ebeveyn
işleme
e9a6608752
2 değiştirilmiş dosya ile 25 ekleme ve 14 silme
  1. 13 6
      Sources/Subs-Themes.php
  2. 12 8
      Sources/Themes.php

+ 13 - 6
Sources/Subs-Themes.php

@@ -33,7 +33,7 @@ function get_single_theme($id)
 	$request = $smcFunc['db_query']('', '
 	$request = $smcFunc['db_query']('', '
 		SELECT id_theme, variable, value
 		SELECT id_theme, variable, value
 		FROM {db_prefix}themes
 		FROM {db_prefix}themes
-		WHERE variable IN ({string:theme_dir}, {string:theme_url}, {string:images_url}, {string:name}, {string:theme_layers}, {string:theme_templates}, {string:version}, {string:install_for})
+		WHERE variable IN ({string:theme_dir}, {string:theme_url}, {string:images_url}, {string:name}, {string:theme_layers}, {string:theme_templates}, {string:version}, {string:install_for}, {string:based_on})
 			AND id_theme = {int:id_theme}
 			AND id_theme = {int:id_theme}
 			AND id_member = {int:no_member}',
 			AND id_member = {int:no_member}',
 		array(
 		array(
@@ -47,6 +47,7 @@ function get_single_theme($id)
 			'theme_templates' => 'theme_templates',
 			'theme_templates' => 'theme_templates',
 			'version' => 'version',
 			'version' => 'version',
 			'install_for' => 'install_for',
 			'install_for' => 'install_for',
+			'based_on' => 'based_on',
 		)
 		)
 	);
 	);
 
 
@@ -66,15 +67,19 @@ function get_all_themes()
 	$request = $smcFunc['db_query']('', '
 	$request = $smcFunc['db_query']('', '
 		SELECT id_theme, variable, value
 		SELECT id_theme, variable, value
 		FROM {db_prefix}themes
 		FROM {db_prefix}themes
-		WHERE variable IN ({string:name}, {string:version}, {string:theme_dir}, {string:theme_url}, {string:images_url})
+		WHERE variable IN ({string:theme_dir}, {string:theme_url}, {string:images_url}, {string:name}, {string:theme_layers}, {string:theme_templates}, {string:version}, {string:install_for}, {string:based_on})
 			AND id_member = {int:no_member}',
 			AND id_member = {int:no_member}',
 		array(
 		array(
 			'no_member' => 0,
 			'no_member' => 0,
-			'name' => 'name',
-			'version' => 'version',
 			'theme_dir' => 'theme_dir',
 			'theme_dir' => 'theme_dir',
-			'theme_url' => 'theme_url',
 			'images_url' => 'images_url',
 			'images_url' => 'images_url',
+			'theme_url' => 'theme_url',
+			'name' => 'name',
+			'theme_layers' => 'theme_layers',
+			'theme_templates' => 'theme_templates',
+			'version' => 'version',
+			'install_for' => 'install_for',
+			'based_on' => 'based_on',
 		)
 		)
 	);
 	);
 	$context['themes'] = array();
 	$context['themes'] = array();
@@ -147,7 +152,6 @@ function get_theme_info($path)
 	$theme_info_xml = $theme_info_xml->to_array();
 	$theme_info_xml = $theme_info_xml->to_array();
 
 
 	$xml_elements = array(
 	$xml_elements = array(
-		'name' => 'name',
 		'theme_layers' => 'layers',
 		'theme_layers' => 'layers',
 		'theme_templates' => 'templates',
 		'theme_templates' => 'templates',
 		'based_on' => 'based-on',
 		'based_on' => 'based-on',
@@ -159,6 +163,9 @@ function get_theme_info($path)
 		if (!empty($theme_info_xml[$name]))
 		if (!empty($theme_info_xml[$name]))
 			$xml_data[$var] = $theme_info_xml[$name];
 			$xml_data[$var] = $theme_info_xml[$name];
 
 
+	// Add the supported versions.
+	$xml_data['install_for'] = $install_versions;
+
 	// Overwrite the default images folder.
 	// Overwrite the default images folder.
 	if (!empty($theme_info_xml['images']))
 	if (!empty($theme_info_xml['images']))
 	{
 	{

+ 12 - 8
Sources/Themes.php

@@ -1337,11 +1337,15 @@ function InstallCopy()
 	// Get a cleaner version.
 	// Get a cleaner version.
 	$name = preg_replace('~[^A-Za-z0-9_\- ]~', '', $_REQUEST['copy']);
 	$name = preg_replace('~[^A-Za-z0-9_\- ]~', '', $_REQUEST['copy']);
 
 
+	// This is a brand new theme so set all possible values.
 	$context['to_install'] = array(
 	$context['to_install'] = array(
 		'dir' => $themedir . '/' . $name,
 		'dir' => $themedir . '/' . $name,
 		'url' => $themeurl . '/' . $name,
 		'url' => $themeurl . '/' . $name,
 		'name' => $name,
 		'name' => $name,
 		'images_url' => $themeurl . '/' . $name . '/images',
 		'images_url' => $themeurl . '/' . $name . '/images',
+		'version' => '1.0',
+		'install_for' => '2.1 - 2.1.99, '. strtr($forum_version, array('SMF ' => '')) .'',
+		'based_on' => '',
 	);
 	);
 
 
 	// Create the specific dir.
 	// Create the specific dir.
@@ -1397,6 +1401,11 @@ function InstallCopy()
 
 
 	$smcFunc['db_free_result']($request);
 	$smcFunc['db_free_result']($request);
 
 
+	$context['to_install'] += array(
+		'theme_layers' => empty($theme_layers) ? 'html,body' : $theme_layers,
+		'theme_templates' => empty($theme_templates) ? 'index' : $theme_templates,
+	);
+
 	// Lets add a theme_info.xml to this theme.
 	// Lets add a theme_info.xml to this theme.
 	$xml_info = '<' . '?xml version="1.0"?' . '>
 	$xml_info = '<' . '?xml version="1.0"?' . '>
 <theme-info xmlns="http://www.simplemachines.org/xml/theme-info" xmlns:smf="http://www.simplemachines.org/">
 <theme-info xmlns="http://www.simplemachines.org/xml/theme-info" xmlns:smf="http://www.simplemachines.org/">
@@ -1405,7 +1414,7 @@ function InstallCopy()
 <!-- The theme\'s version, please try to use semantic versioning. -->
 <!-- The theme\'s version, please try to use semantic versioning. -->
 <version>1.0</version>
 <version>1.0</version>
 <!-- Install for, the SMF versions this theme was designed for. Uses the same wildcards used in the packager manager. This field is mandatory. -->
 <!-- Install for, the SMF versions this theme was designed for. Uses the same wildcards used in the packager manager. This field is mandatory. -->
-<install for="2.1 - 2.1.99, '. strtr($forum_version, array('SMF ' => '')) .'" />
+<install for="'. $context['to_install']['install_for'] .'" />
 <!-- Theme name, used purely for aesthetics. -->
 <!-- Theme name, used purely for aesthetics. -->
 <name>' . $context['to_install']['name'] . '</name>
 <name>' . $context['to_install']['name'] . '</name>
 <!-- Author: your email address or contact information. The name attribute is optional. -->
 <!-- Author: your email address or contact information. The name attribute is optional. -->
@@ -1413,9 +1422,9 @@ function InstallCopy()
 <!-- Website... where to get updates and more information. -->
 <!-- Website... where to get updates and more information. -->
 <website>http://www.simplemachines.org/</website>
 <website>http://www.simplemachines.org/</website>
 <!-- Template layers to use, defaults to "html,body". -->
 <!-- Template layers to use, defaults to "html,body". -->
-<layers>' . (empty($theme_layers) ? 'html,body' : $theme_layers) . '</layers>
+<layers>' . $context['to_install']['theme_layers'] . '</layers>
 <!-- Templates to load on startup. Default is "index". -->
 <!-- Templates to load on startup. Default is "index". -->
-<templates>' . (empty($theme_templates) ? 'index' : $theme_templates) . '</templates>
+<templates>' . $context['to_install']['theme_templates'] . '</templates>
 <!-- Base this theme off another? Default is blank, or no. It could be "default". -->
 <!-- Base this theme off another? Default is blank, or no. It could be "default". -->
 <based-on></based-on>
 <based-on></based-on>
 </theme-info>';
 </theme-info>';
@@ -1428,11 +1437,6 @@ function InstallCopy()
 		fclose($fp);
 		fclose($fp);
 	}
 	}
 
 
-	// Read its info form the XML file.
-	$theme_info = get_theme_info($context['to_install']['dir']);
-
-	$context['to_install'] += $theme_info;
-
 	// Install the theme. theme_install() will take care of possible errors.
 	// Install the theme. theme_install() will take care of possible errors.
 	$id = theme_install($context['to_install']);
 	$id = theme_install($context['to_install']);