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 * 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
51 $formAction = "{?URL?}/modules.php?module=" . $mod;
52 if (!empty($what)) $formAction .= "&what=" . $what;
56 'theme_unix' => array(), // Unix name from filesystem
57 'theme_name' => array() // Title
60 // Only activated themes for the user
61 $add = " WHERE `theme_active`='Y'";
64 if (isAdmin()) $add = '';
66 // Select all themes we want
67 $result = SQL_QUERY("SELECT
68 `theme_path`, `theme_name`
70 `{?_MYSQL_PREFIX?}_themes`
73 `theme_name` ASC", __FILE__, __LINE__);
76 while ($content = SQL_FETCHARRAY($result)) {
77 // Construct relative include file name
78 $inc = sprintf("theme/%s/theme.php", secureString($content['theme_path']));
80 // Load it's theme.php file if found
81 if (isIncludeReadable($inc)) {
82 // And save all data in array
84 $themesArray['theme_unix'][] = $content['theme_path'];
85 $themesArray['theme_name'][] = $GLOBALS['theme_data']['name'];
90 SQL_FREERESULT($result);
92 // Construct selection form for the box template
94 foreach ($themesArray['theme_unix'] as $key => $theme) {
95 $OUT .= " <option value=\"".$theme."\"";
96 if ($theme == getCurrentTheme()) $OUT .= ' selected="selected"';
97 $OUT .= ">".$themesArray['theme_name'][$key]."</option>\n";
102 'form_action' => $formAction,
106 // Return generated selection
107 return loadTemplate('theme_select_form', true, $content);
110 // Get version from name
111 function getThemeVersion ($name) {
112 // Is the extension 'theme' installed?
113 if (!isExtensionActive('theme')) {
118 // Default version 'number'
121 // Is the cache entry there?
122 if (isset($GLOBALS['cache_array']['themes']['theme_ver'][$name])) {
123 // Get the version from cache
124 $cver = $GLOBALS['cache_array']['themes']['theme_ver'][$name];
127 incrementStatsEntry('cache_hits');
128 } elseif (getExtensionVersion('cache') != '0.1.8') {
129 // Load version from database
130 $result = SQL_QUERY_ESC("SELECT `theme_ver` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' LIMIT 1",
131 array($name), __FUNCTION__, __LINE__);
134 if (SQL_NUMROWS($result) == 1) {
136 list($cver) = SQL_FETCHROW($result);
140 SQL_FREERESULT($result);
147 // Checks wether a theme is found in db
148 function ifThemeExists ($name) {
149 // Get theme and is it not nul?
150 return ((isExtensionActive('theme')) && (getThemeId($name) > 0));
153 // Checks if a theme is active
154 function isThemeActive ($name) {
155 // Is the extension 'theme' installed?
156 if (!isExtensionActive('theme')) {
161 // Default is nothing active
164 // Is the cache entry there?
165 if (isset($GLOBALS['cache_array']['themes']['theme_active'][$name])) {
166 // Get the version from cache
167 $active = ($GLOBALS['cache_array']['themes']['theme_active'][$name] == 'Y');
170 incrementStatsEntry('cache_hits');
171 } elseif (getExtensionVersion('cache') != '0.1.8') {
172 // Check if current theme is already imported or not
173 $result = SQL_QUERY_ESC("SELECT `theme_active` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
174 array($name), __FUNCTION__, __LINE__);
176 // Is the theme active and installed?
177 $active = (SQL_NUMROWS($result) == 1);
180 SQL_FREERESULT($result);
187 // Gets current human-readable theme name
188 function getCurrentThemeName () {
189 // Is the extension 'theme' installed?
190 if (!isExtensionActive('theme')) {
196 $name = getCurrentTheme();
198 // Is the cache entry there?
199 if (isset($GLOBALS['cache_array']['themes']['theme_name'][$name])) {
200 // Get the version from cache
201 $name = $GLOBALS['cache_array']['themes']['theme_name'][$name];
204 incrementStatsEntry('cache_hits');
205 } elseif (getExtensionVersion('cache') != '0.1.8') {
206 // Check if current theme is already imported or not
207 $result = SQL_QUERY_ESC("SELECT `theme_name` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
208 array($name), __FUNCTION__, __LINE__);
211 list($name) = SQL_FETCHROW($result);
214 SQL_FREERESULT($result);
221 // Get current theme name
222 function getActualTheme () {
223 // The default theme is 'default'... ;-)
226 // Load default theme if not empty from configuration
227 if ((isConfigEntrySet('default_theme')) && (getConfig('default_theme') != '')) $ret = getConfig('default_theme');
229 if (!isSessionVariableSet('mxchange_theme')) {
232 } elseif ((isSessionVariableSet('mxchange_theme')) && (isExtensionInstalledAndNewer('sql_patches', '0.1.4'))) {
233 //die("<pre>".print_r($GLOBALS['cache_array']['themes'], true)."</pre>");
234 // Get theme from cookie
235 $ret = getSession('mxchange_theme');
238 if ((!isExtensionActive('theme')) || (getThemeId($ret) == '0')) {
242 } elseif ((!isInstalled()) && ((isInstalling()) || (getOutputMode() == true)) && ((isGetRequestElementSet('theme')) || (isPostRequestElementSet('theme')))) {
243 // Prepare filename for checking
244 $themeFile = sprintf("theme/%s/theme.php", getRequestElement('theme'));
246 // Installation mode active
247 if ((isGetRequestElementSet('theme')) && (isIncludeReadable($theme))) {
248 // Set cookie from URL data
249 setTheme(getRequestElement('theme'));
250 } elseif (isIncludeReadable(sprintf("theme/%s/theme.php", secureString(postRequestElement('theme'))))) {
251 // Set cookie from posted data
252 setTheme(secureString(postRequestElement('theme')));
256 $ret = getSession('mxchange_theme');
258 // Invalid design, reset cookie
262 // Return theme value
266 // Setter for theme in session
267 function setTheme ($newTheme) {
268 setSession('mxchange_theme', $newTheme);
272 function getThemeId ($name) {
276 // Is the cache entry there?
277 if (isset($GLOBALS['cache_array']['themes']['id'][$name])) {
278 // Get the version from cache
279 $id = $GLOBALS['cache_array']['themes']['id'][$name];
282 incrementStatsEntry('cache_hits');
283 } elseif (isExtensionInstalledAndNewer('cache', '0.1.8')) {
284 // Check if current theme is already imported or not
285 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' LIMIT 1",
286 array($name), __FUNCTION__, __LINE__);
289 if (SQL_NUMROWS($result) == 1) {
291 list($id) = SQL_FETCHROW($result);
295 SQL_FREERESULT($result);
302 ///////////////////////////////////////////////////////////////////////////////
303 // Only filter functions
304 ///////////////////////////////////////////////////////////////////////////////
306 // Filter for generic handling of theme change
307 function FILTER_HANDLE_THEME_CHANGE () {
308 // Check if new theme is selcted
309 if ((isPostRequestElementSet('new_theme')) && (postRequestElement('new_theme') != getCurrentTheme())) {
310 // Set new theme for guests
311 $newTheme = postRequestElement('new_theme');
313 // Change to new theme
316 // Remove current from array
317 removeIncludeFromPool('theme', sprintf("theme/%s/theme.php", getCurrentTheme()));
320 addIncludeToPool('theme', sprintf("theme/%s/theme.php", $newTheme));
324 // Filter for settings theme from user profile, must be executed only if FILTER_FETCH_USER_DATA() ran before
325 function FILTER_SET_USERS_THEME () {
326 // Is the user data valid?
328 // Do only run for logged in members
329 debug_report_bug('Please only run this filter for logged in users.');
332 // Change to new theme
333 setTheme(getUserData('curr_theme'));