-// @TODO Move this code block into a filter and register it with 'init'
-// Check if new theme is selcted
-if ((isPostRequestElementSet('new_theme')) && (postRequestElement('new_theme') != getCurrentTheme())) {
- // Set new theme for guests
- $newTheme = postRequestElement('new_theme');
+// Get current theme name
+function getActualTheme () {
+ // The default theme is 'default'... ;-)
+ $ret = 'default';
+
+ // Load default theme if not empty from configuration
+ if ((isConfigEntrySet('default_theme')) && (getConfig('default_theme') != '')) $ret = getConfig('default_theme');
+
+ if (!isSessionVariableSet('mailer_theme')) {
+ // Set default theme
+ setTheme($ret);
+ } elseif ((isSessionVariableSet('mailer_theme')) && (isExtensionInstalledAndNewer('sql_patches', '0.1.4'))) {
+ //die("<pre>".print_r($GLOBALS['cache_array']['themes'], true)."</pre>");
+ // Get theme from cookie
+ $ret = getSession('mailer_theme');
+
+ // Is it valid?
+ if ((!isExtensionActive('theme')) || (getThemeId($ret) == '0')) {
+ // Fix it to default
+ $ret = 'default';
+ } // END - if
+ } elseif ((!isInstalled()) && ((isInstalling()) || (isHtmlOutputMode())) && ((isGetRequestParameterSet('theme')) || (isPostRequestParameterSet('theme')))) {
+ // Prepare filename for checking
+ $themeFile = sprintf("theme/%s/theme.php", getRequestParameter('theme'));
+
+ // Installation mode active
+ if ((isGetRequestParameterSet('theme')) && (isIncludeReadable($theme))) {
+ // Set cookie from URL data
+ setTheme(getRequestParameter('theme'));
+ } elseif (isIncludeReadable(sprintf("theme/%s/theme.php", postRequestParameter('theme')))) {
+ // Set cookie from posted data
+ setTheme(postRequestParameter('theme'));
+ }
+
+ // Set return value
+ $ret = getSession('mailer_theme');
+ } else {
+ // Invalid design, reset cookie
+ setTheme($ret);
+ }
+
+ // Return theme value
+ return $ret;
+}
+
+/**
+ * Setter for theme in session (This setter does return the success of
+ * setSession() which is required e.g. for destroySponsorSession().
+ */
+function setTheme ($newTheme) {
+ return setSession('mailer_theme', $newTheme);
+}