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
46 function THEME_SELECTION_BOX ($mod, $act, $wht, $result) {
48 $formAction = "{!URL!}/modules.php?module=".$mod;
49 if (!empty($act)) $formAction .= "&action=".$act;
50 if (!empty($wht)) $formAction .= "&what=".$wht;
54 'theme_unix' => array(), // Unix name from filesystem
55 'theme_name' => array() // Title
59 while ($content = SQL_FETCHARRAY($result)) {
60 // Load it's theme.php file
61 $INC = sprintf("theme/%s/theme.php", SQL_ESCAPE($content['theme_path']));
62 if (INCLUDE_READABLE($INC)) {
63 // And save all data in array
65 $themesArray['theme_unix'][] = $content['theme_path'];
66 $themesArray['theme_name'][] = $THEME_NAME;
70 // Sort whole array by title
71 array_pk_sort($themesArray, array("theme_name"));
73 // Construct selection form for the box template
75 foreach ($themesArray['theme_unix'] as $key => $theme) {
76 $OUT .= " <option value=\"".$theme."\"";
77 if ($theme == GET_CURR_THEME()) $OUT .= " selected=\"selected\"";
78 $OUT .= ">".$themesArray['theme_name'][$key]."</option>\n";
83 'form_action' => $formAction,
87 // Return generated selection
88 return LOAD_TEMPLATE("theme_select_form", true, $content);
91 // Get version from name
92 function THEME_GET_VERSION ($name) {
93 // Is the extension "theme" installed?
94 if (!EXT_IS_ACTIVE("theme")) {
99 // Default version "number"
102 // Is the cache entry there?
103 if (isset($GLOBALS['cache_array']['themes']['theme_ver'][$name])) {
104 // Get the version from cache
105 $cver = $GLOBALS['cache_array']['themes']['theme_ver'][$name];
108 incrementConfigEntry('cache_hits');
109 } elseif (GET_EXT_VERSION("cache") != "0.1.8") {
110 // Load version from database
111 $result = SQL_QUERY_ESC("SELECT theme_ver FROM `{!_MYSQL_PREFIX!}_themes` WHERE theme_path='%s' LIMIT 1",
112 array($name), __FUNCTION__, __LINE__);
115 if (SQL_NUMROWS($result) == 1) {
117 list($cver) = SQL_FETCHROW($result);
121 SQL_FREERESULT($result);
128 // Checks wether a theme is found in db
129 function THEME_CHECK_EXIST ($name) {
130 // Get theme and is it not nul?
131 return (THEME_GET_ID($name) > 0);
134 // Checks if a theme is active
135 function THEME_IS_ACTIVE ($name) {
136 // Is the extension "theme" installed?
137 if (!EXT_IS_ACTIVE("theme")) {
142 // Default is nothing active
145 // Is the cache entry there?
146 if (isset($GLOBALS['cache_array']['themes']['theme_active'][$name])) {
147 // Get the version from cache
148 $active = ($GLOBALS['cache_array']['themes']['theme_active'][$name] == "Y");
151 incrementConfigEntry('cache_hits');
152 } elseif (GET_EXT_VERSION("cache") != "0.1.8") {
153 // Check if current theme is already imported or not
154 $result = SQL_QUERY_ESC("SELECT theme_active FROM `{!_MYSQL_PREFIX!}_themes` WHERE theme_path='%s' AND theme_active='Y' LIMIT 1",
155 array($name), __FUNCTION__, __LINE__);
157 // Is the theme active and installed?
158 $active = (SQL_NUMROWS($result) == 1);
161 SQL_FREERESULT($result);
168 // Gets current human-readable theme name
169 function GET_CURR_THEME_NAME () {
170 // Is the extension "theme" installed?
171 if (!EXT_IS_ACTIVE("theme")) {
177 $name = GET_CURR_THEME();
179 // Is the cache entry there?
180 if (isset($GLOBALS['cache_array']['themes']['theme_name'][$name])) {
181 // Get the version from cache
182 $name = $GLOBALS['cache_array']['themes']['theme_name'][$name];
185 incrementConfigEntry('cache_hits');
186 } elseif (GET_EXT_VERSION("cache") != "0.1.8") {
187 // Check if current theme is already imported or not
188 $result = SQL_QUERY_ESC("SELECT theme_name FROM `{!_MYSQL_PREFIX!}_themes` WHERE theme_path='%s' AND theme_active='Y' LIMIT 1",
189 array($name), __FUNCTION__, __LINE__);
192 list($name) = SQL_FETCHROW($result);
195 SQL_FREERESULT($result);
202 // Initialize variables
203 $GLOBALS['curr_theme'] = GET_CURR_THEME();
205 // Check if new theme is selcted
206 if ((REQUEST_ISSET_POST(('new_theme'))) && (REQUEST_POST('new_theme') != $GLOBALS['curr_theme'])) {
207 // Set new theme for guests
208 $newTheme = REQUEST_POST('new_theme');
210 // Change to new theme
211 set_session('mxchange_theme', $newTheme);
213 // Remove current from array and set new
214 $theme = sprintf("%stheme/%s/theme.php", constant('PATH'), $GLOBALS['curr_theme']);
215 REMOVE_INC_FROM_POOL($theme);
216 ADD_INC_TO_POOL(sprintf("%stheme/%s/theme.php", constant('PATH'), $newTheme));