Browse Source

disable_theme($themeID)

Signed-off-by: Suki <[email protected]>
Suki 10 years ago
parent
commit
f0d02f3c74
1 changed files with 57 additions and 0 deletions
  1. 57 0
      Sources/Subs-Themes.php

+ 57 - 0
Sources/Subs-Themes.php

@@ -372,4 +372,61 @@ function remove_dir($path)
 	rmdir($path);
 }
 
+function disable_theme($themeID)
+{
+	global $smcFunc, $modSetting;
+
+	if (empty($themeID))
+		return false;
+
+	$known = explode(',', $modSettings['knownThemes']);
+
+	// 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 themes table.
+	$smcFunc['db_query']('', '
+		DELETE FROM {db_prefix}themes
+		WHERE id_theme = {int:current_theme}',
+		array(
+			'current_theme' => $themeID,
+		)
+	);
+
+	// 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,
+		)
+	);
+
+	// Some boards may have it as preferred theme.
+	$smcFunc['db_query']('', '
+		UPDATE {db_prefix}boards
+		SET id_theme = {int:default_theme}
+		WHERE id_theme = {int:current_theme}',
+		array(
+			'default_theme' => 0,
+			'current_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));
+
+	return true;
+}
+
 ?>