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
96 foreach ($themesArray['theme_unix'] as $key => $theme) {
97 $OUT .= " <option value=\"".$theme."\"";
98 if ($theme == getCurrentTheme()) $OUT .= ' selected="selected"';
99 $OUT .= ">".$themesArray['theme_name'][$key]."</option>\n";
104 'form_action' => $formAction,
108 // Return generated selection
109 return loadTemplate('theme_select_form', true, $content);
112 // Get version from name
113 function getThemeVersion ($name) {
114 // Is the extension 'theme' installed?
115 if (!isExtensionActive('theme')) {
120 // Default version 'number'
123 // Is the cache entry there?
124 if (isset($GLOBALS['cache_array']['themes']['theme_ver'][$name])) {
125 // Get the version from cache
126 $cver = $GLOBALS['cache_array']['themes']['theme_ver'][$name];
129 incrementStatsEntry('cache_hits');
130 } elseif (isExtensionInstalledAndNewer('cache', '0.1.8')) {
131 // Load version from database
132 $result = SQL_QUERY_ESC("SELECT `theme_ver` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' LIMIT 1",
133 array($name), __FUNCTION__, __LINE__);
136 if (SQL_NUMROWS($result) == 1) {
138 list($cver) = SQL_FETCHROW($result);
142 SQL_FREERESULT($result);
149 // Checks wether a theme is found in db
150 function ifThemeExists ($name) {
151 // Get theme and is it not nul?
152 return ((isExtensionActive('theme')) && (getThemeId($name) > 0));
155 // Checks if a theme is active
156 function isThemeActive ($name) {
157 // Is the extension 'theme' installed?
158 if (!isExtensionActive('theme')) {
163 // Default is nothing active
166 // Is the cache entry there?
167 if (isset($GLOBALS['cache_array']['themes']['theme_active'][$name])) {
168 // Get the version from cache
169 $active = ($GLOBALS['cache_array']['themes']['theme_active'][$name] == 'Y');
172 incrementStatsEntry('cache_hits');
173 } elseif (isExtensionInstalledAndNewer('cache', '0.1.8')) {
174 // Check if current theme is already imported or not
175 $result = SQL_QUERY_ESC("SELECT `theme_active` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
176 array($name), __FUNCTION__, __LINE__);
178 // Is the theme active and installed?
179 $active = (SQL_NUMROWS($result) == 1);
182 SQL_FREERESULT($result);
189 // Gets current human-readable theme name
190 function getCurrentThemeName () {
191 // Is the extension 'theme' installed?
192 if (!isExtensionActive('theme')) {
198 $name = getCurrentTheme();
200 // Is the cache entry there?
201 if (isset($GLOBALS['cache_array']['themes']['theme_name'][$name])) {
202 // Get the version from cache
203 $name = $GLOBALS['cache_array']['themes']['theme_name'][$name];
206 incrementStatsEntry('cache_hits');
207 } elseif (isExtensionInstalledAndNewer('cache', '0.1.8')) {
208 // Check if current theme is already imported or not
209 $result = SQL_QUERY_ESC("SELECT `theme_name` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
210 array($name), __FUNCTION__, __LINE__);
213 list($name) = SQL_FETCHROW($result);
216 SQL_FREERESULT($result);
223 // Get current theme name
224 function getActualTheme () {
225 // The default theme is 'default'... ;-)
228 // Load default theme if not empty from configuration
229 if ((isConfigEntrySet('default_theme')) && (getConfig('default_theme') != '')) $ret = getConfig('default_theme');
231 if (!isSessionVariableSet('mxchange_theme')) {
234 } elseif ((isSessionVariableSet('mxchange_theme')) && (isExtensionInstalledAndNewer('sql_patches', '0.1.4'))) {
235 //die("<pre>".print_r($GLOBALS['cache_array']['themes'], true)."</pre>");
236 // Get theme from cookie
237 $ret = getSession('mxchange_theme');
240 if ((!isExtensionActive('theme')) || (getThemeId($ret) == '0')) {
244 } elseif ((!isInstalled()) && ((isInstalling()) || (getOutputMode() == true)) && ((isGetRequestParameterSet('theme')) || (isPostRequestParameterSet('theme')))) {
245 // Prepare filename for checking
246 $themeFile = sprintf("theme/%s/theme.php", getRequestParameter('theme'));
248 // Installation mode active
249 if ((isGetRequestParameterSet('theme')) && (isIncludeReadable($theme))) {
250 // Set cookie from URL data
251 setTheme(getRequestParameter('theme'));
252 } elseif (isIncludeReadable(sprintf("theme/%s/theme.php", secureString(postRequestParameter('theme'))))) {
253 // Set cookie from posted data
254 setTheme(secureString(postRequestParameter('theme')));
258 $ret = getSession('mxchange_theme');
260 // Invalid design, reset cookie
264 // Return theme value
268 // Setter for theme in session
269 function setTheme ($newTheme) {
270 setSession('mxchange_theme', $newTheme);
274 function getThemeId ($name) {
278 // Is the cache entry there?
279 if (isset($GLOBALS['cache_array']['themes']['id'][$name])) {
280 // Get the version from cache
281 $id = $GLOBALS['cache_array']['themes']['id'][$name];
284 incrementStatsEntry('cache_hits');
285 } elseif (isExtensionInstalledAndNewer('cache', '0.1.8')) {
286 // Check if current theme is already imported or not
287 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' LIMIT 1",
288 array($name), __FUNCTION__, __LINE__);
291 if (SQL_NUMROWS($result) == 1) {
293 list($id) = SQL_FETCHROW($result);
297 SQL_FREERESULT($result);
304 ///////////////////////////////////////////////////////////////////////////////
305 // Only filter functions
306 ///////////////////////////////////////////////////////////////////////////////
308 // Filter for generic handling of theme change
309 function FILTER_HANDLE_THEME_CHANGE () {
310 // Check if new theme is selcted
311 if ((isPostRequestParameterSet('new_theme')) && (postRequestParameter('new_theme') != getCurrentTheme())) {
312 // Set new theme for guests
313 $newTheme = postRequestParameter('new_theme');
315 // Change to new theme
318 // Remove current from array
319 removeIncludeFromPool('theme', sprintf("theme/%s/theme.php", getCurrentTheme()));
322 addIncludeToPool('theme', sprintf("theme/%s/theme.php", $newTheme));
324 // Redirect to same URL
325 redirectToRequestUri();
329 // Filter for settings theme from user profile, must be executed only if FILTER_FETCH_USER_DATA() ran before
330 function FILTER_SET_USERS_THEME () {
331 // Is the user data valid?
333 // Do only run for logged in members
334 debug_report_bug(__FUNCTION__, __LINE__, 'Please only run this filter for logged in users.');
337 // Change to new theme
338 setTheme(getUserData('curr_theme'));