+// Get id from theme
+function getThemeId ($name) {
+ // Default id
+ $id = '0';
+
+ // Is the cache entry there?
+ if (isset($GLOBALS['cache_array']['themes']['id'][$name])) {
+ // Get the version from cache
+ $id = $GLOBALS['cache_array']['themes']['id'][$name];
+
+ // Count up
+ incrementStatsEntry('cache_hits');
+ } elseif (isExtensionInstalledAndNewer('cache', '0.1.8')) {
+ // Check if current theme is already imported or not
+ $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' LIMIT 1",
+ array($name), __FUNCTION__, __LINE__);
+
+ // Entry found?
+ if (SQL_NUMROWS($result) == 1) {
+ // Fetch data
+ list($id) = SQL_FETCHROW($result);
+ } // END - if
+
+ // Free result
+ SQL_FREERESULT($result);
+ }
+
+ // Return id
+ return $id;
+}
+
+//-----------------------------------------------------------------------------
+// Only filter functions
+//-----------------------------------------------------------------------------
+
+// Filter for generic handling of theme change
+function FILTER_HANDLE_THEME_CHANGE () {
+ // Check if new theme is selcted
+ if ((isPostRequestParameterSet('new_theme')) && (postRequestParameter('new_theme') != getCurrentTheme())) {
+ // Set new theme for guests
+ $newTheme = postRequestParameter('new_theme');
+
+ // Change to new theme
+ setTheme($newTheme);
+
+ // Remove current from array
+ removeIncludeFromPool('theme', sprintf("theme/%s/theme.php", getCurrentTheme()));
+
+ // Add new theme
+ addIncludeToPool('theme', sprintf("theme/%s/theme.php", $newTheme));
+
+ // Redirect to same URL
+ redirectToRequestUri();
+ } // END - if
+}
+
+// Filter for settings theme from user profile, must be executed only if FILTER_FETCH_USER_DATA() ran before
+function FILTER_SET_USERS_THEME () {
+ // Is the user data valid?
+ if (!isMember()) {
+ // Do only run for logged in members
+ debug_report_bug(__FUNCTION__, __LINE__, 'Please only run this filter for logged in users.');
+ } // END - if
+
+ // Change to new theme
+ setTheme(getUserData('curr_theme'));
+}