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 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 function THEME_SELECTION_BOX($mod, $act, $wht, $result) {
42 $FORM = "{!URL!}/modules.php?module=".$mod;
43 if (!empty($act)) $FORM .= "&action=".$act;
44 if (!empty($wht)) $FORM .= "&what=".$wht;
45 define('__FORM_VALUE', $FORM);
49 'theme_unix' => array(), // Unix name from filesystem
50 'theme_name' => array() // Title
54 while (list($theme) = SQL_FETCHROW($result)) {
55 // Load it's theme.php file
56 $INC = sprintf("theme/%s/theme.php", SQL_ESCAPE($theme));
57 if (INCLUDE_READABLE($INC)) {
58 // And save all data in array
60 $THEMES['theme_unix'][] = $theme;
61 $THEMES['theme_name'][] = $THEME_NAME;
65 // Sort whole array by title
66 array_pk_sort($THEMES, array("theme_name"));
68 // Construct selection form for the box template
70 foreach ($THEMES['theme_unix'] as $key => $theme) {
71 $OUT .= " <option value=\"".$theme."\"";
72 if ($theme == GET_CURR_THEME()) $OUT .= " selected=\"selected\"";
73 $OUT .= ">".$THEMES['theme_name'][$key]."</option>\n";
76 // Return generated selection
77 define('__THEME_SELECTION_OPTIONS', $OUT);
78 $OUT = LOAD_TEMPLATE("theme_select_form", true);
82 // Get version from name
83 function THEME_GET_VERSION ($name) {
84 // Is the extension "theme" installed?
85 if (!EXT_IS_ACTIVE("theme")) {
90 // Default version "number"
93 // Is the cache entry there?
94 if (isset($GLOBALS['cache_array']['themes']['theme_ver'][$name])) {
95 // Get the version from cache
96 $cver = $GLOBALS['cache_array']['themes']['theme_ver'][$name];
99 incrementConfigEntry('cache_hits');
100 } elseif (GET_EXT_VERSION("cache") != "0.1.8") {
101 // Load version from database
102 $result = SQL_QUERY_ESC("SELECT theme_ver FROM `{!_MYSQL_PREFIX!}_themes` WHERE theme_path='%s' LIMIT 1",
103 array($name), __FILE__, __LINE__);
106 if (SQL_NUMROWS($result) == 1) {
108 list($cver) = SQL_FETCHROW($result);
112 SQL_FREERESULT($result);
119 // Checks wether a theme is found in db
120 function THEME_CHECK_EXIST ($name) {
121 // Get theme and is it not nul?
122 return (THEME_GET_ID($name) > 0);
125 // Checks if a theme is active
126 function THEME_IS_ACTIVE ($name) {
127 // Is the extension "theme" installed?
128 if (!EXT_IS_ACTIVE("theme")) {
133 // Default is nothing active
136 // Is the cache entry there?
137 if (isset($GLOBALS['cache_array']['themes']['theme_active'][$name])) {
138 // Get the version from cache
139 $active = ($GLOBALS['cache_array']['themes']['theme_active'][$name] == "Y");
142 incrementConfigEntry('cache_hits');
143 } elseif (GET_EXT_VERSION("cache") != "0.1.8") {
144 // Check if current theme is already imported or not
145 $result = SQL_QUERY_ESC("SELECT theme_active FROM `{!_MYSQL_PREFIX!}_themes` WHERE theme_path='%s' AND theme_active='Y' LIMIT 1",
146 array($name), __FILE__, __LINE__);
148 // Is the theme active and installed?
149 $active = (SQL_NUMROWS($result) == 1);
152 SQL_FREERESULT($result);
159 // Gets current human-readable theme name
160 function GET_CURR_THEME_NAME () {
161 // Is the extension "theme" installed?
162 if (!EXT_IS_ACTIVE("theme")) {
168 $name = GET_CURR_THEME();
170 // Is the cache entry there?
171 if (isset($GLOBALS['cache_array']['themes']['theme_name'][$name])) {
172 // Get the version from cache
173 $name = $GLOBALS['cache_array']['themes']['theme_name'][$name];
176 incrementConfigEntry('cache_hits');
177 } elseif (GET_EXT_VERSION("cache") != "0.1.8") {
178 // Check if current theme is already imported or not
179 $result = SQL_QUERY_ESC("SELECT theme_name FROM `{!_MYSQL_PREFIX!}_themes` WHERE theme_path='%s' AND theme_active='Y' LIMIT 1",
180 array($name), __FILE__, __LINE__);
183 list($name) = SQL_FETCHROW($result);
186 SQL_FREERESULT($result);
193 // Initialize variables
194 $GLOBALS['curr_theme'] = GET_CURR_THEME();
196 // Check if new theme is selcted
197 if ((!empty($_POST['new_theme'])) && ($_POST['new_theme'] != $GLOBALS['curr_theme'])) {
198 // Set new theme for guests
199 $newTheme = $_POST['new_theme'];
201 // Change to new theme
202 set_session('mxchange_theme', $newTheme);
204 // Remove current from array and set new
205 $theme = sprintf("%stheme/%s/theme.php", constant('PATH'), $GLOBALS['curr_theme']);
206 unset($INC_POOL[array_search($theme, $INC_POOL)]);
207 $INC_POOL[] = sprintf("%stheme/%s/theme.php", constant('PATH'), $newTheme);