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 - 2009 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')) {
44 // Create a selection box with installed and activated themes or all if admin
45 function generateThemeSelectionBox () {
46 // Init variables and fill them if set
54 $formAction = "{?URL?}/modules.php?module=" . $mod;
55 if (!empty($what)) $formAction .= "&what=" . $what;
59 'theme_unix' => array(), // Unix name from filesystem
60 'theme_name' => array() // Title
63 // Only activated themes for the user
64 $add = " WHERE `theme_active`='Y'";
67 if (isAdmin()) $add = '';
69 // Select all themes we want
70 $result = SQL_QUERY("SELECT `theme_path`, `theme_name` FROM `{?_MYSQL_PREFIX?}_themes`".$add." ORDER BY `theme_name` ASC", __FILE__, __LINE__);
73 while ($content = SQL_FETCHARRAY($result)) {
74 // Construct relative include file name
75 $inc = sprintf("theme/%s/theme.php", SQL_ESCAPE($content['theme_path']));
77 // Load it's theme.php file if found
78 if (isIncludeReadable($inc)) {
79 // And save all data in array
81 $themesArray['theme_unix'][] = $content['theme_path'];
82 $themesArray['theme_name'][] = $GLOBALS['theme_data']['name'];
87 SQL_FREERESULT($result);
89 // Construct selection form for the box template
91 foreach ($themesArray['theme_unix'] as $key => $theme) {
92 $OUT .= " <option value=\"".$theme."\"";
93 if ($theme == getCurrentTheme()) $OUT .= ' selected="selected"';
94 $OUT .= ">".$themesArray['theme_name'][$key]."</option>\n";
99 'form_action' => $formAction,
103 // Return generated selection
104 return loadTemplate('theme_select_form', true, $content);
107 // Get version from name
108 function getThemeVersion ($name) {
109 // Is the extension 'theme' installed?
110 if (!isExtensionActive('theme')) {
115 // Default version 'number'
118 // Is the cache entry there?
119 if (isset($GLOBALS['cache_array']['themes']['theme_ver'][$name])) {
120 // Get the version from cache
121 $cver = $GLOBALS['cache_array']['themes']['theme_ver'][$name];
124 incrementStatsEntry('cache_hits');
125 } elseif (getExtensionVersion('cache') != '0.1.8') {
126 // Load version from database
127 $result = SQL_QUERY_ESC("SELECT `theme_ver` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' LIMIT 1",
128 array($name), __FUNCTION__, __LINE__);
131 if (SQL_NUMROWS($result) == 1) {
133 list($cver) = SQL_FETCHROW($result);
137 SQL_FREERESULT($result);
144 // Checks wether a theme is found in db
145 function ifThemeExists ($name) {
146 // Get theme and is it not nul?
147 return (getThemeId($name) > 0);
150 // Checks if a theme is active
151 function isThemeActive ($name) {
152 // Is the extension 'theme' installed?
153 if (!isExtensionActive('theme')) {
158 // Default is nothing active
161 // Is the cache entry there?
162 if (isset($GLOBALS['cache_array']['themes']['theme_active'][$name])) {
163 // Get the version from cache
164 $active = ($GLOBALS['cache_array']['themes']['theme_active'][$name] == 'Y');
167 incrementStatsEntry('cache_hits');
168 } elseif (getExtensionVersion('cache') != '0.1.8') {
169 // Check if current theme is already imported or not
170 $result = SQL_QUERY_ESC("SELECT `theme_active` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
171 array($name), __FUNCTION__, __LINE__);
173 // Is the theme active and installed?
174 $active = (SQL_NUMROWS($result) == 1);
177 SQL_FREERESULT($result);
184 // Gets current human-readable theme name
185 function getCurrentThemeName () {
186 // Is the extension 'theme' installed?
187 if (!isExtensionActive('theme')) {
193 $name = getCurrentTheme();
195 // Is the cache entry there?
196 if (isset($GLOBALS['cache_array']['themes']['theme_name'][$name])) {
197 // Get the version from cache
198 $name = $GLOBALS['cache_array']['themes']['theme_name'][$name];
201 incrementStatsEntry('cache_hits');
202 } elseif (getExtensionVersion('cache') != '0.1.8') {
203 // Check if current theme is already imported or not
204 $result = SQL_QUERY_ESC("SELECT `theme_name` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
205 array($name), __FUNCTION__, __LINE__);
208 list($name) = SQL_FETCHROW($result);
211 SQL_FREERESULT($result);
218 // @TODO Move this code block into a filter and register it with 'init'
219 // Check if new theme is selcted
220 if ((isPostRequestElementSet('new_theme')) && (postRequestElement('new_theme') != getCurrentTheme())) {
221 // Set new theme for guests
222 $newTheme = postRequestElement('new_theme');
224 // Change to new theme
227 // Remove current from array
228 removeIncludeFromPool('theme', sprintf("theme/%s/theme.php", getCurrentTheme()));
231 addIncludeToPool('theme', sprintf("theme/%s/theme.php", $newTheme));