2
0
Эх сурвалжийг харах

Themes.php now uses the class xmlArray to read theme-info - Thanks to Arantor for the rant :P
fixed an undefined index error when uploading a theme and the admin session is gone

Signed-off-by: emanuele <[email protected]>

emanuele 12 жил өмнө
parent
commit
486291cff8

+ 19 - 7
Sources/Themes.php

@@ -1435,7 +1435,9 @@ function ThemeInstall()
 		if (!is_writable($boarddir . '/Themes'))
 			fatal_lang_error('theme_install_write_error', 'critical');
 
-		require_once($sourcedir . '/Subs-Package.php');
+		// This happens when the admin session is gone and the user has to login again
+		if (empty($_FILES['theme_gz']) && empty($_REQUEST['theme_gz']))
+			redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
 
 		// Set the default settings...
 		$theme_name = strtok(basename(isset($_FILES['theme_gz']) ? $_FILES['theme_gz']['name'] : $_REQUEST['theme_gz']), '.');
@@ -1470,6 +1472,15 @@ function ThemeInstall()
 		if (file_exists($theme_dir . '/theme_info.xml'))
 		{
 			$theme_info = file_get_contents($theme_dir . '/theme_info.xml');
+			// Parse theme-info.xml into an xmlArray.
+			require_once($sourcedir . '/Class-Package.php');
+			$theme_info_xml = new xmlArray($theme_info);
+			// @todo Error message of some sort?
+			if (!$theme_info_xml->exists('theme-info[0]'))
+				return 'package_get_error_packageinfo_corrupt';
+
+			$theme_info_xml = $theme_info_xml->path('theme-info[0]');
+			$theme_info_xml = $theme_info_xml->to_array();
 
 			$xml_elements = array(
 				'name' => 'name',
@@ -1479,17 +1490,18 @@ function ThemeInstall()
 			);
 			foreach ($xml_elements as $var => $name)
 			{
-				if (preg_match('~<' . $name . '>(?:<!\[CDATA\[)?(.+?)(?:\]\]>)?</' . $name . '>~', $theme_info, $match) == 1)
-					$install_info[$var] = $match[1];
+				if (!empty($theme_info_xml[$name]))
+					$install_info[$var] = $theme_info_xml[$name];
 			}
 
-			if (preg_match('~<images>(?:<!\[CDATA\[)?(.+?)(?:\]\]>)?</images>~', $theme_info, $match) == 1)
+			if (!empty($theme_info_xml['images']))
 			{
-				$install_info['images_url'] = $install_info['theme_url'] . '/' . $match[1];
+				$install_info['images_url'] = $install_info['theme_url'] . '/' . $theme_info_xml['images'];
 				$explicit_images = true;
 			}
-			if (preg_match('~<extra>(?:<!\[CDATA\[)?(.+?)(?:\]\]>)?</extra>~', $theme_info, $match) == 1)
-				$install_info += unserialize($match[1]);
+
+			if (!empty($theme_info_xml['extra']))
+				$install_info += unserialize($theme_info_xml['extra']);
 		}
 
 		if (isset($install_info['based_on']))

+ 1 - 1
Themes/default/Themes.template.php

@@ -167,7 +167,7 @@ function template_main()
 					</dl>
 					<hr class="hrcolor" />
 					<input type="submit" name="save" value="', $txt['theme_install_go'], '" class="button_submit" />
-					</br class="clear_right" />
+					<br class="clear_right" />
 				</div>
 				<span class="botslice"><span></span></span>
 			</div>