Browse Source

Simpler code

Signed-off-by: Suki <[email protected]>
Suki 10 years ago
parent
commit
4019f7fcdb
3 changed files with 23 additions and 26 deletions
  1. 7 10
      Sources/Subs-Themes.php
  2. 15 14
      Sources/Themes.php
  3. 1 2
      Themes/default/languages/Themes.english.php

+ 7 - 10
Sources/Subs-Themes.php

@@ -405,16 +405,6 @@ function remove_theme($themeID)
 	$known = explode(',', $modSettings['knownThemes']);
 	$enable = explode(',', $modSettings['enableThemes']);
 
-	// Remove it from the list of known themes.
-	for ($i = 0, $n = count($known); $i < $n; $i++)
-		if ($known[$i] == $themeID)
-			unset($known[$i]);
-
-	// And the enable list too.
-	for ($i = 0, $n = count($enable); $i < $n; $i++)
-		if ($enable[$i] == $themeID)
-			unset($enable[$i]);
-
 	// Remove it from the themes table.
 	$smcFunc['db_query']('', '
 		DELETE FROM {db_prefix}themes
@@ -446,6 +436,13 @@ function remove_theme($themeID)
 		)
 	);
 
+	// Remove it from the list of known themes.
+	$known = array_diff($known, array($themeID));
+
+	// And the enable list too.
+	$enable = array_diff($enable, array($themeID));
+
+	// Back to good old comma separated string.
 	$known = strtr(implode(',', $known), array(',,' => ','));
 	$enable = strtr(implode(',', $enable), array(',,' => ','));
 

+ 15 - 14
Sources/Themes.php

@@ -188,7 +188,7 @@ function ThemeList()
 		checkSession();
 		validateToken('admin-tl');
 
-		$themes = get_all_themes();
+		$themes = get_all_themes(false);
 
 		$setValues = array();
 		foreach ($themes as $id => $theme)
@@ -226,7 +226,7 @@ function ThemeList()
 	loadTemplate('Themes');
 
 	// Get all installed themes.
-	get_all_themes();
+	get_all_themes(false);
 
 	$context['reset_dir'] = realpath($boarddir . '/Themes');
 	$context['reset_url'] = $boardurl . '/Themes';
@@ -831,29 +831,30 @@ function RemoveTheme()
 
 function EnableTheme()
 {
+	global $modSettings, $context;
+
 	checkSession('get');
 
 	isAllowedTo('admin_forum');
 	validateToken('admin-tre', 'request');
 
-	// The theme's ID must be an integer.
-	$themeID = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
+	// The theme's ID must be an string.
+	$themeID = isset($_GET['th']) ? (string) trim($_GET['th']) : (string) trim($_GET['id']);
 
 	// Get the current list.
-	$enable = explode(',', $modSettings['enableThemes']);
+	$enableThemes = explode(',', $modSettings['enableThemes']);
 
 	// Are we disabling it?
 	if (isset($_GET['disabled']))
-	{
-		for ($i = 0, $n = count($enable); $i < $n; $i++)
-			if ($enable[$i] == $themeID)
-				unset($enable[$i]);
-
-		updateSettings(array('knownThemes' => $enable));
-	}
+		$enableThemes = array_diff($enableThemes, array($themeID));
 
 	// Nope? then enable it!
-	updateSettings(array('enableThemes' => strtr($modSettings['enableThemes'] . ',' . $themeID, array(',,' => ','))));
+	else
+		$enableThemes[] = (string) $themeID;
+
+	// Update the setting.
+	$enableThemes = strtr(implode(',', $enableThemes), array(',,' => ','));
+	updateSettings(array('enableThemes' => $enableThemes));
 
 	// Done!
 	redirectexit('action=admin;area=theme;sa=list;' . $context['session_var'] . '=' . $context['session_id']);
@@ -898,7 +899,7 @@ function PickTheme()
 			$_GET['vrt'] = $_POST['vrt'][$k];
 	}
 
-	// Have we made a desicion, or are we just browsing?
+	// Have we made a decision, or are we just browsing?
 	if (isset($_GET['th']))
 	{
 		checkSession('get');

+ 1 - 2
Themes/default/languages/Themes.english.php

@@ -15,8 +15,7 @@ $txt['theme_enable'] = 'enable';
 $txt['theme_disable'] = 'disable';
 $txt['theme_remove_confirm'] = 'Are you sure you want to permanently remove this theme?';
 $txt['theme_enable_confirm'] = 'Are you sure you want to enable this theme?';
-$txt['theme_disable_confirm'] = 'Are you sure you want to disablethis theme?';
-
+$txt['theme_disable_confirm'] = 'Are you sure you want to disable this theme?';
 
 $txt['theme_install'] = 'Install a New Theme';
 $txt['theme_install_file'] = 'From an archive (e.g. .zip, .tar.gz)';