2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 12/03/2004 *
4 * =================== Last change: 12/13/2004 *
6 * -------------------------------------------------------------------- *
7 * File : theme manager.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Theme manager *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Themen-Manager *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
44 // Create a selection box with installed and activated themes or all if admin
45 function generateThemeSelectionBox () {
46 // Init variables and fill them if set
51 $formAction = "{%url=modules.php?module=" . $mod;
52 if (!empty($what)) $formAction .= "&what=" . $what;
57 'theme_unix' => array(), // Unix name from filesystem
58 'theme_name' => array() // Title
61 // Only activated themes for the user
62 $add = " WHERE `theme_active`='Y'";
65 if (isAdmin()) $add = '';
67 // Select all themes we want
68 $result = SQL_QUERY("SELECT
69 `theme_path`, `theme_name`
71 `{?_MYSQL_PREFIX?}_themes`
74 `theme_name` ASC", __FILE__, __LINE__);
77 while ($content = SQL_FETCHARRAY($result)) {
78 // Construct relative include file name
79 $inc = sprintf("theme/%s/theme.php", secureString($content['theme_path']));
81 // Load it's theme.php file if found
82 if (isIncludeReadable($inc)) {
83 // And save all data in array
85 $themesArray['theme_unix'][] = $content['theme_path'];
86 $themesArray['theme_name'][] = $GLOBALS['theme_data']['name'];
91 SQL_FREERESULT($result);
93 // Construct selection form for the box template
95 foreach ($themesArray['theme_unix'] as $key => $theme) {
96 $OUT .= " <option value=\"".$theme."\"";
97 if ($theme == getCurrentTheme()) $OUT .= ' selected="selected"';
98 $OUT .= ">".$themesArray['theme_name'][$key]."</option>\n";
103 'form_action' => $formAction,
107 // Return generated selection
108 return loadTemplate('theme_select_form', true, $content);
111 // Get version from name
112 function getThemeVersion ($name) {
113 // Is the extension 'theme' installed?
114 if (!isExtensionActive('theme')) {
119 // Default version 'number'
122 // Is the cache entry there?
123 if (isset($GLOBALS['cache_array']['themes']['theme_ver'][$name])) {
124 // Get the version from cache
125 $cver = $GLOBALS['cache_array']['themes']['theme_ver'][$name];
128 incrementStatsEntry('cache_hits');
129 } elseif (getExtensionVersion('cache') != '0.1.8') {
130 // Load version from database
131 $result = SQL_QUERY_ESC("SELECT `theme_ver` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' LIMIT 1",
132 array($name), __FUNCTION__, __LINE__);
135 if (SQL_NUMROWS($result) == 1) {
137 list($cver) = SQL_FETCHROW($result);
141 SQL_FREERESULT($result);
148 // Checks wether a theme is found in db
149 function ifThemeExists ($name) {
150 // Get theme and is it not nul?
151 return ((isExtensionActive('theme')) && (getThemeId($name) > 0));
154 // Checks if a theme is active
155 function isThemeActive ($name) {
156 // Is the extension 'theme' installed?
157 if (!isExtensionActive('theme')) {
162 // Default is nothing active
165 // Is the cache entry there?
166 if (isset($GLOBALS['cache_array']['themes']['theme_active'][$name])) {
167 // Get the version from cache
168 $active = ($GLOBALS['cache_array']['themes']['theme_active'][$name] == 'Y');
171 incrementStatsEntry('cache_hits');
172 } elseif (getExtensionVersion('cache') != '0.1.8') {
173 // Check if current theme is already imported or not
174 $result = SQL_QUERY_ESC("SELECT `theme_active` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
175 array($name), __FUNCTION__, __LINE__);
177 // Is the theme active and installed?
178 $active = (SQL_NUMROWS($result) == 1);
181 SQL_FREERESULT($result);
188 // Gets current human-readable theme name
189 function getCurrentThemeName () {
190 // Is the extension 'theme' installed?
191 if (!isExtensionActive('theme')) {
197 $name = getCurrentTheme();
199 // Is the cache entry there?
200 if (isset($GLOBALS['cache_array']['themes']['theme_name'][$name])) {
201 // Get the version from cache
202 $name = $GLOBALS['cache_array']['themes']['theme_name'][$name];
205 incrementStatsEntry('cache_hits');
206 } elseif (getExtensionVersion('cache') != '0.1.8') {
207 // Check if current theme is already imported or not
208 $result = SQL_QUERY_ESC("SELECT `theme_name` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
209 array($name), __FUNCTION__, __LINE__);
212 list($name) = SQL_FETCHROW($result);
215 SQL_FREERESULT($result);
222 // Get current theme name
223 function getActualTheme () {
224 // The default theme is 'default'... ;-)
227 // Load default theme if not empty from configuration
228 if ((isConfigEntrySet('default_theme')) && (getConfig('default_theme') != '')) $ret = getConfig('default_theme');
230 if (!isSessionVariableSet('mxchange_theme')) {
233 } elseif ((isSessionVariableSet('mxchange_theme')) && (isExtensionInstalledAndNewer('sql_patches', '0.1.4'))) {
234 //die("<pre>".print_r($GLOBALS['cache_array']['themes'], true)."</pre>");
235 // Get theme from cookie
236 $ret = getSession('mxchange_theme');
239 if ((!isExtensionActive('theme')) || (getThemeId($ret) == '0')) {
243 } elseif ((!isInstalled()) && ((isInstalling()) || (getOutputMode() == true)) && ((isGetRequestParameterSet('theme')) || (isPostRequestParameterSet('theme')))) {
244 // Prepare filename for checking
245 $themeFile = sprintf("theme/%s/theme.php", getRequestParameter('theme'));
247 // Installation mode active
248 if ((isGetRequestParameterSet('theme')) && (isIncludeReadable($theme))) {
249 // Set cookie from URL data
250 setTheme(getRequestParameter('theme'));
251 } elseif (isIncludeReadable(sprintf("theme/%s/theme.php", secureString(postRequestParameter('theme'))))) {
252 // Set cookie from posted data
253 setTheme(secureString(postRequestParameter('theme')));
257 $ret = getSession('mxchange_theme');
259 // Invalid design, reset cookie
263 // Return theme value
267 // Setter for theme in session
268 function setTheme ($newTheme) {
269 setSession('mxchange_theme', $newTheme);
273 function getThemeId ($name) {
277 // Is the cache entry there?
278 if (isset($GLOBALS['cache_array']['themes']['id'][$name])) {
279 // Get the version from cache
280 $id = $GLOBALS['cache_array']['themes']['id'][$name];
283 incrementStatsEntry('cache_hits');
284 } elseif (isExtensionInstalledAndNewer('cache', '0.1.8')) {
285 // Check if current theme is already imported or not
286 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' LIMIT 1",
287 array($name), __FUNCTION__, __LINE__);
290 if (SQL_NUMROWS($result) == 1) {
292 list($id) = SQL_FETCHROW($result);
296 SQL_FREERESULT($result);
303 ///////////////////////////////////////////////////////////////////////////////
304 // Only filter functions
305 ///////////////////////////////////////////////////////////////////////////////
307 // Filter for generic handling of theme change
308 function FILTER_HANDLE_THEME_CHANGE () {
309 // Check if new theme is selcted
310 if ((isPostRequestParameterSet('new_theme')) && (postRequestParameter('new_theme') != getCurrentTheme())) {
311 // Set new theme for guests
312 $newTheme = postRequestParameter('new_theme');
314 // Change to new theme
317 // Remove current from array
318 removeIncludeFromPool('theme', sprintf("theme/%s/theme.php", getCurrentTheme()));
321 addIncludeToPool('theme', sprintf("theme/%s/theme.php", $newTheme));
325 // Filter for settings theme from user profile, must be executed only if FILTER_FETCH_USER_DATA() ran before
326 function FILTER_SET_USERS_THEME () {
327 // Is the user data valid?
329 // Do only run for logged in members
330 debug_report_bug('Please only run this filter for logged in users.');
333 // Change to new theme
334 setTheme(getUserData('curr_theme'));