Browse Source

function EnableTheme()

Signed-off-by: Suki <[email protected]>
Suki 10 years ago
parent
commit
05d2acfbda
2 changed files with 33 additions and 45 deletions
  1. 1 6
      Sources/Subs-Themes.php
  2. 32 39
      Sources/Themes.php

+ 1 - 6
Sources/Subs-Themes.php

@@ -100,11 +100,6 @@ function get_all_themes()
 	foreach ($context['themes'] as $i => $theme)
 	{
 		$context['themes'][$i]['theme_dir'] = realpath($context['themes'][$i]['theme_dir']);
-
-		// Fetch some more info directly form the xml file.
-		if (file_exists($context['themes'][$i]['theme_dir'] . '/theme_info.xml'))
-			$context['themes'][$i] += get_theme_info($context['themes'][$i]['theme_dir']);}
-
 		$context['themes'][$i]['valid_path'] = file_exists($context['themes'][$i]['theme_dir']) && is_dir($context['themes'][$i]['theme_dir']);
 	}
 
@@ -372,7 +367,7 @@ function remove_dir($path)
 	rmdir($path);
 }
 
-function disable_theme($themeID)
+function remove_theme($themeID)
 {
 	global $smcFunc, $modSetting;
 

+ 32 - 39
Sources/Themes.php

@@ -68,6 +68,7 @@ function ThemesMain()
 		'remove' => 'RemoveTheme',
 		'pick' => 'PickTheme',
 		'edit' => 'EditTheme',
+		'enable' => 'EnableTheme',
 		'copy' => 'CopyTemplate',
 	);
 
@@ -832,54 +833,46 @@ function RemoveTheme()
 	if ($_GET['th'] == 1)
 		fatal_lang_error('no_access', false);
 
-	$known = explode(',', $modSettings['knownThemes']);
+	$theme_info = get_single_theme($themeID);
 
-	// Remove it from the list of known themes.
-	for ($i = 0, $n = count($known); $i < $n; $i++)
-		if ($known[$i] == $themeID)
-			unset($known[$i]);
+	// Remove it from the DB.
+	remove_theme($themeID);
 
-	// Remove it from the themes table.
-	$smcFunc['db_query']('', '
-		DELETE FROM {db_prefix}themes
-		WHERE id_theme = {int:current_theme}',
-		array(
-			'current_theme' => $themeID,
-		)
-	);
+	// And remove all its files and folders too.
+	if (!empty($theme_info) && !empty($theme_info['theme_dir']))
+		remove_dir($theme_info['theme_dir']);
 
-	// Update users preferences.
-	$smcFunc['db_query']('', '
-		UPDATE {db_prefix}members
-		SET id_theme = {int:default_theme}
-		WHERE id_theme = {int:current_theme}',
-		array(
-			'default_theme' => 0,
-			'current_theme' => $themeID,
-		)
-	);
+	// Go back to the list page.
+	redirectexit('action=admin;area=theme;sa=list;' . $context['session_var'] . '=' . $context['session_id']);
+}
+
+function EnableTheme()
+{
+	checkSession('get');
+
+	isAllowedTo('admin_forum');
+	validateToken('admin-tre', 'request');
+
+	$enable = '1';
+
+	// The theme's ID must be an integer.
+	$themeID = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
 
-	// Some boards may have it as preferred theme.
+	// Are we disabling it?
+	if (isset($_GET['disabled']))
+		$enable = '0';
+
+	// Make the query.
 	$smcFunc['db_query']('', '
-		UPDATE {db_prefix}boards
-		SET id_theme = {int:default_theme}
-		WHERE id_theme = {int:current_theme}',
+		UPDATE {db_prefix}themes
+		SET value = {string:enable}
+		WHERE id_theme = {int:theme}',
 		array(
-			'default_theme' => 0,
-			'current_theme' => $themeID,
+			'enable' => $enable,
+			'theme' => $themeID,
 		)
 	);
 
-	$known = strtr(implode(',', $known), array(',,' => ','));
-
-	// Fix it if the theme was the overall default theme.
-	if ($modSettings['theme_guests'] == $themeID)
-		updateSettings(array('theme_guests' => '1', 'knownThemes' => $known));
-
-	else
-		updateSettings(array('knownThemes' => $known));
-
-	// Go back to the list page.
 	redirectexit('action=admin;area=theme;sa=list;' . $context['session_var'] . '=' . $context['session_id']);
 }