2 /************************************************************************
3 * MXChange v0.2.1 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 - 2008 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')) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
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
55 $formAction = "{!URL!}/modules.php?module=" . $mod;
56 if (!empty($what)) $formAction .= "&what=" . $what;
60 'theme_unix' => array(), // Unix name from filesystem
61 'theme_name' => array() // Title
64 // Only activated themes for the user
65 $add = " WHERE `theme_active`='Y'";
68 if (IS_ADMIN()) $add = '';
70 // Select all themes we want
71 $result = SQL_QUERY("SELECT `theme_path`, `theme_name` FROM `{!_MYSQL_PREFIX!}_themes`".$add." ORDER BY `theme_name` ASC", __FILE__, __LINE__);
74 while ($content = SQL_FETCHARRAY($result)) {
75 // Construct relative include file name
76 $INC = sprintf("theme/%s/theme.php", SQL_ESCAPE($content['theme_path']));
78 // Load it's theme.php file if found
79 if (isIncludeReadable($INC)) {
80 // And save all data in array
82 $themesArray['theme_unix'][] = $content['theme_path'];
83 $themesArray['theme_name'][] = $GLOBALS['theme_data']['name'];
88 SQL_FREERESULT($result);
90 // Construct selection form for the box template
92 foreach ($themesArray['theme_unix'] as $key => $theme) {
93 $OUT .= " <option value=\"".$theme."\"";
94 if ($theme == getCurrentTheme()) $OUT .= ' selected="selected"';
95 $OUT .= ">".$themesArray['theme_name'][$key]."</option>\n";
100 'form_action' => $formAction,
104 // Return generated selection
105 return LOAD_TEMPLATE('theme_select_form', true, $content);
108 // Get version from name
109 function THEME_GET_VERSION ($name) {
110 // Is the extension 'theme' installed?
111 if (!EXT_IS_ACTIVE('theme')) {
116 // Default version 'number'
119 // Is the cache entry there?
120 if (isset($GLOBALS['cache_array']['themes']['theme_ver'][$name])) {
121 // Get the version from cache
122 $cver = $GLOBALS['cache_array']['themes']['theme_ver'][$name];
125 incrementConfigEntry('cache_hits');
126 } elseif (GET_EXT_VERSION('cache') != '0.1.8') {
127 // Load version from database
128 $result = SQL_QUERY_ESC("SELECT `theme_ver` FROM `{!_MYSQL_PREFIX!}_themes` WHERE `theme_path`='%s' LIMIT 1",
129 array($name), __FUNCTION__, __LINE__);
132 if (SQL_NUMROWS($result) == 1) {
134 list($cver) = SQL_FETCHROW($result);
138 SQL_FREERESULT($result);
145 // Checks wether a theme is found in db
146 function ifThemeExists ($name) {
147 // Get theme and is it not nul?
148 return (getThemeId($name) > 0);
151 // Checks if a theme is active
152 function isThemeActive ($name) {
153 // Is the extension 'theme' installed?
154 if (!EXT_IS_ACTIVE('theme')) {
159 // Default is nothing active
162 // Is the cache entry there?
163 if (isset($GLOBALS['cache_array']['themes']['theme_active'][$name])) {
164 // Get the version from cache
165 $active = ($GLOBALS['cache_array']['themes']['theme_active'][$name] == 'Y');
168 incrementConfigEntry('cache_hits');
169 } elseif (GET_EXT_VERSION('cache') != '0.1.8') {
170 // Check if current theme is already imported or not
171 $result = SQL_QUERY_ESC("SELECT `theme_active` FROM `{!_MYSQL_PREFIX!}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
172 array($name), __FUNCTION__, __LINE__);
174 // Is the theme active and installed?
175 $active = (SQL_NUMROWS($result) == 1);
178 SQL_FREERESULT($result);
185 // Gets current human-readable theme name
186 function getCurrentThemeName () {
187 // Is the extension 'theme' installed?
188 if (!EXT_IS_ACTIVE('theme')) {
194 $name = getCurrentTheme();
196 // Is the cache entry there?
197 if (isset($GLOBALS['cache_array']['themes']['theme_name'][$name])) {
198 // Get the version from cache
199 $name = $GLOBALS['cache_array']['themes']['theme_name'][$name];
202 incrementConfigEntry('cache_hits');
203 } elseif (GET_EXT_VERSION('cache') != '0.1.8') {
204 // Check if current theme is already imported or not
205 $result = SQL_QUERY_ESC("SELECT `theme_name` FROM `{!_MYSQL_PREFIX!}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
206 array($name), __FUNCTION__, __LINE__);
209 list($name) = SQL_FETCHROW($result);
212 SQL_FREERESULT($result);
219 // Initialize variables
220 $GLOBALS['curr_theme'] = getCurrentTheme();
222 // Check if new theme is selcted
223 if ((REQUEST_ISSET_POST('new_theme')) && (REQUEST_POST('new_theme') != $GLOBALS['curr_theme'])) {
224 // Set new theme for guests
225 $newTheme = REQUEST_POST('new_theme');
227 // Change to new theme
228 setSession('mxchange_theme', $newTheme);
230 // Remove current from array and set new
231 $theme = sprintf("%stheme/%s/theme.php", constant('PATH'), $GLOBALS['curr_theme']);
232 REMOVE_INC_FROM_POOL($theme);
233 ADD_INC_TO_POOL(sprintf("%stheme/%s/theme.php", constant('PATH'), $newTheme));