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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
45 // Create a selection box with installed and activated themes or all if admin
46 function generateThemeSelectionBox () {
47 // Init variables and fill them if set
52 $formAction = '{%url=modules.php?module='. $mod;
53 if (!empty($what)) $formAction .= '&what=' . $what;
58 'theme_unix' => array(), // Unix name from filesystem
59 'theme_name' => array() // Title
62 // Only activated themes for the user
63 $add = " WHERE `theme_active`='Y'";
66 if (isAdmin()) $add = '';
68 // Select all themes we want
69 $result = SQL_QUERY("SELECT
70 `theme_path`, `theme_name`
72 `{?_MYSQL_PREFIX?}_themes`
75 `theme_name` ASC", __FUNCTION__, __LINE__);
78 while ($content = SQL_FETCHARRAY($result)) {
79 // Construct relative include file name
80 $inc = sprintf("theme/%s/theme.php", secureString($content['theme_path']));
82 // Load it's theme.php file if found
83 if (isIncludeReadable($inc)) {
84 // And save all data in array
86 $themesArray['theme_unix'][] = $content['theme_path'];
87 $themesArray['theme_name'][] = $GLOBALS['theme_data']['name'];
92 SQL_FREERESULT($result);
94 // Construct selection form for the box template
95 // @TODO Can't this be rewritten to an API function?
97 foreach ($themesArray['theme_unix'] as $key => $theme) {
98 $OUT .= ' <option value="' . $theme . '"';
99 if ($theme == getCurrentTheme()) $OUT .= ' selected="selected"';
100 $OUT .= '>' . $themesArray['theme_name'][$key] . '</option>';
105 'form_action' => $formAction,
109 // Return generated selection
110 return loadTemplate('theme_select_form', true, $content);
113 // Get version from name
114 function getThemeVersion ($name) {
115 // Is the extension 'theme' installed?
116 if (!isExtensionActive('theme')) {
121 // Default version 'number'
124 // Is the cache entry there?
125 if (isset($GLOBALS['cache_array']['themes']['theme_ver'][$name])) {
126 // Get the version from cache
127 $cver = $GLOBALS['cache_array']['themes']['theme_ver'][$name];
130 incrementStatsEntry('cache_hits');
131 } elseif (isExtensionInstalledAndNewer('cache', '0.1.8')) {
132 // Load version from database
133 $result = SQL_QUERY_ESC("SELECT `theme_ver` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' LIMIT 1",
134 array($name), __FUNCTION__, __LINE__);
137 if (SQL_NUMROWS($result) == 1) {
139 list($cver) = SQL_FETCHROW($result);
143 SQL_FREERESULT($result);
150 // Checks wether a theme is found in db
151 function ifThemeExists ($name) {
152 // Get theme and is it not nul?
153 return ((isExtensionActive('theme')) && (getThemeId($name) > 0));
156 // Checks if a theme is active
157 function isThemeActive ($name) {
158 // Is the extension 'theme' installed?
159 if (!isExtensionActive('theme')) {
164 // Default is nothing active
167 // Is the cache entry there?
168 if (isset($GLOBALS['cache_array']['themes']['theme_active'][$name])) {
169 // Get the version from cache
170 $active = ($GLOBALS['cache_array']['themes']['theme_active'][$name] == 'Y');
173 incrementStatsEntry('cache_hits');
174 } elseif (isExtensionInstalledAndNewer('cache', '0.1.8')) {
175 // Check if current theme is already imported or not
176 $result = SQL_QUERY_ESC("SELECT `theme_active` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
177 array($name), __FUNCTION__, __LINE__);
179 // Is the theme active and installed?
180 $active = (SQL_NUMROWS($result) == 1);
183 SQL_FREERESULT($result);
190 // Gets current human-readable theme name
191 function getCurrentThemeName () {
192 // Is the extension 'theme' installed?
193 if (!isExtensionActive('theme')) {
199 $name = getCurrentTheme();
201 // Is the cache entry there?
202 if (isset($GLOBALS['cache_array']['themes']['theme_name'][$name])) {
203 // Get the version from cache
204 $name = $GLOBALS['cache_array']['themes']['theme_name'][$name];
207 incrementStatsEntry('cache_hits');
208 } elseif (isExtensionInstalledAndNewer('cache', '0.1.8')) {
209 // Check if current theme is already imported or not
210 $result = SQL_QUERY_ESC("SELECT `theme_name` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
211 array($name), __FUNCTION__, __LINE__);
214 list($name) = SQL_FETCHROW($result);
217 SQL_FREERESULT($result);
224 // Get current theme name
225 function getActualTheme () {
226 // The default theme is 'default'... ;-)
229 // Load default theme if not empty from configuration
230 if ((isConfigEntrySet('default_theme')) && (getConfig('default_theme') != '')) $ret = getConfig('default_theme');
232 if (!isSessionVariableSet('mxchange_theme')) {
235 } elseif ((isSessionVariableSet('mxchange_theme')) && (isExtensionInstalledAndNewer('sql_patches', '0.1.4'))) {
236 //die("<pre>".print_r($GLOBALS['cache_array']['themes'], true)."</pre>");
237 // Get theme from cookie
238 $ret = getSession('mxchange_theme');
241 if ((!isExtensionActive('theme')) || (getThemeId($ret) == '0')) {
245 } elseif ((!isInstalled()) && ((isInstalling()) || (getOutputMode() == true)) && ((isGetRequestParameterSet('theme')) || (isPostRequestParameterSet('theme')))) {
246 // Prepare filename for checking
247 $themeFile = sprintf("theme/%s/theme.php", getRequestParameter('theme'));
249 // Installation mode active
250 if ((isGetRequestParameterSet('theme')) && (isIncludeReadable($theme))) {
251 // Set cookie from URL data
252 setTheme(getRequestParameter('theme'));
253 } elseif (isIncludeReadable(sprintf("theme/%s/theme.php", secureString(postRequestParameter('theme'))))) {
254 // Set cookie from posted data
255 setTheme(secureString(postRequestParameter('theme')));
259 $ret = getSession('mxchange_theme');
261 // Invalid design, reset cookie
265 // Return theme value
269 // Setter for theme in session
270 function setTheme ($newTheme) {
271 setSession('mxchange_theme', $newTheme);
275 function getThemeId ($name) {
279 // Is the cache entry there?
280 if (isset($GLOBALS['cache_array']['themes']['id'][$name])) {
281 // Get the version from cache
282 $id = $GLOBALS['cache_array']['themes']['id'][$name];
285 incrementStatsEntry('cache_hits');
286 } elseif (isExtensionInstalledAndNewer('cache', '0.1.8')) {
287 // Check if current theme is already imported or not
288 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' LIMIT 1",
289 array($name), __FUNCTION__, __LINE__);
292 if (SQL_NUMROWS($result) == 1) {
294 list($id) = SQL_FETCHROW($result);
298 SQL_FREERESULT($result);
305 ///////////////////////////////////////////////////////////////////////////////
306 // Only filter functions
307 ///////////////////////////////////////////////////////////////////////////////
309 // Filter for generic handling of theme change
310 function FILTER_HANDLE_THEME_CHANGE () {
311 // Check if new theme is selcted
312 if ((isPostRequestParameterSet('new_theme')) && (postRequestParameter('new_theme') != getCurrentTheme())) {
313 // Set new theme for guests
314 $newTheme = postRequestParameter('new_theme');
316 // Change to new theme
319 // Remove current from array
320 removeIncludeFromPool('theme', sprintf("theme/%s/theme.php", getCurrentTheme()));
323 addIncludeToPool('theme', sprintf("theme/%s/theme.php", $newTheme));
325 // Redirect to same URL
326 redirectToRequestUri();
330 // Filter for settings theme from user profile, must be executed only if FILTER_FETCH_USER_DATA() ran before
331 function FILTER_SET_USERS_THEME () {
332 // Is the user data valid?
334 // Do only run for logged in members
335 debug_report_bug(__FUNCTION__, __LINE__, 'Please only run this filter for logged in users.');
338 // Change to new theme
339 setTheme(getUserData('curr_theme'));