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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2013 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Create a selection box with installed and activated themes or all if admin
44 function generateThemeSelectionBox () {
45 // Init variables and fill them if set
50 $formAction = 'modules.php?module='. $mod;
51 if (!empty($what)) $formAction .= '&what=' . $what;
55 'theme_unix' => array(), // Unix name from filesystem
56 'theme_name' => array() // Title
59 // Only activated themes for the user
60 $add = " WHERE `theme_active`='Y'";
64 // Then display all themes
68 // Select all themes we want
69 $result = sqlQuery('SELECT
73 `{?_MYSQL_PREFIX?}_themes`
76 `theme_name` ASC', __FUNCTION__, __LINE__);
79 while ($row = sqlFetchArray($result)) {
80 // Construct relative include file name
81 $inc = sprintf("theme/%s/theme.php", secureString($row['theme_path']));
83 // Load it's theme.php file if found
84 if (isIncludeReadable($inc)) {
85 // And save all data in array
87 array_push($themesArray['theme_unix'], $row['theme_path']);
88 array_push($themesArray['theme_name'], $row['theme_name']);
93 sqlFreeResult($result);
95 // Construct selection form for the box template
96 // @TODO Can't this be rewritten to an API function?
98 foreach ($themesArray['theme_unix'] as $key => $theme) {
99 $OUT .= ' <option value="' . $theme . '"';
100 if ($theme == getCurrentTheme()) $OUT .= ' selected="selected"';
101 $OUT .= '>' . $themesArray['theme_name'][$key] . '</option>';
106 'form_action' => $formAction,
111 $out = loadTemplate('theme_select_form', TRUE, $content);
113 // Return generated selection
117 // Get version from name
118 function getThemeVersion ($name) {
119 // Is the extension 'theme' installed?
120 if (!isExtensionActive('theme')) {
125 // Default version 'number'
128 // Is the cache entry there?
129 if (isset($GLOBALS['cache_array']['themes']['theme_version'][$name])) {
130 // Get the version from cache
131 $cver = $GLOBALS['cache_array']['themes']['theme_version'][$name];
134 incrementStatsEntry('cache_hits');
135 } elseif (isExtensionInstalledAndNewer('cache', '0.1.8')) {
136 // Load version from database
137 $result = sqlQueryEscaped("SELECT `theme_ver` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' LIMIT 1",
138 array($name), __FUNCTION__, __LINE__);
141 if (sqlNumRows($result) == 1) {
143 list($cver) = sqlFetchRow($result);
147 sqlFreeResult($result);
154 // Checks whether a theme is found in db
155 function ifThemeExists ($name) {
156 // Get theme and is it not nul?
157 return (((isExtensionActive('theme')) || (getModule() == 'admin')) && (isValidId(getThemeId($name))));
160 // Checks if a theme is active
161 function isThemeActive ($name) {
162 // Is the extension 'theme' installed?
163 if (!isExtensionActive('theme')) {
168 // Default is nothing active
171 // Is the cache entry there?
172 if (isset($GLOBALS['cache_array']['themes']['theme_active'][$name])) {
173 // Get the version from cache
174 $active = ($GLOBALS['cache_array']['themes']['theme_active'][$name] == 'Y');
177 incrementStatsEntry('cache_hits');
178 } elseif (isExtensionInstalledAndNewer('cache', '0.1.8')) {
179 // Check if current theme is already imported or not
180 $result = sqlQueryEscaped("SELECT `theme_active` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
181 array($name), __FUNCTION__, __LINE__);
183 // Is the theme active and installed?
184 $active = (sqlNumRows($result) == 1);
187 sqlFreeResult($result);
194 // Gets current human-readable theme name
195 function getCurrentThemeName () {
196 // Is the extension 'theme' installed?
197 if (!isExtensionActive('theme')) {
203 $name = getCurrentTheme();
205 // Is the cache entry there?
206 if (isset($GLOBALS['cache_array']['themes']['theme_name'][$name])) {
207 // Get the version from cache
208 $name = $GLOBALS['cache_array']['themes']['theme_name'][$name];
211 incrementStatsEntry('cache_hits');
212 } elseif (isExtensionInstalledAndNewer('cache', '0.1.8')) {
213 // Check if current theme is already imported or not
214 $result = sqlQueryEscaped("SELECT `theme_name` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
215 array($name), __FUNCTION__, __LINE__);
218 list($name) = sqlFetchRow($result);
221 sqlFreeResult($result);
228 // Get current theme name
229 function getActualTheme () {
230 // The default theme is 'default'... ;-)
233 // Load default theme if not empty from configuration
234 if ((isConfigEntrySet('default_theme')) && (getConfig('default_theme') != '')) {
235 $ret = getConfig('default_theme');
238 if (!isMailerThemeSet()) {
240 setMailerTheme($ret);
241 } elseif ((isMailerThemeSet()) && (isExtensionInstalledAndNewer('sql_patches', '0.1.4'))) {
242 //die("<pre>".print_r($GLOBALS['cache_array']['themes'], TRUE)."</pre>");
243 // Get theme from cookie
244 $ret = getSession('mailer_theme');
247 if ((!isExtensionActive('theme')) || (getThemeId($ret) == '0')) {
251 } elseif ((!isInstalled()) && ((isInstalling()) || (isHtmlOutputMode())) && ((isGetRequestElementSet('theme')) || (isPostRequestElementSet('theme')))) {
252 // Prepare filename for checking
253 $themeFile = sprintf("theme/%s/theme.php", getRequestElement('theme'));
255 // Installation mode active
256 if ((isGetRequestElementSet('theme')) && (isIncludeReadable($theme))) {
257 // Set cookie from URL data
258 setMailerTheme(getRequestElement('theme'));
259 } elseif (isIncludeReadable(sprintf("theme/%s/theme.php", postRequestElement('theme')))) {
260 // Set cookie from posted data
261 setMailerTheme(postRequestElement('theme'));
265 $ret = getSession('mailer_theme');
267 // Invalid design, reset cookie
268 setMailerTheme($ret);
271 // Return theme value
276 function getThemeId ($name) {
280 // Is the cache entry there?
281 if (isset($GLOBALS['cache_array']['themes']['id'][$name])) {
282 // Get the version from cache
283 $id = $GLOBALS['cache_array']['themes']['id'][$name];
286 incrementStatsEntry('cache_hits');
287 } elseif (isExtensionInstalledAndNewer('cache', '0.1.8')) {
288 // Check if current theme is already imported or not
289 $result = sqlQueryEscaped("SELECT `id` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_path`='%s' LIMIT 1",
290 array($name), __FUNCTION__, __LINE__);
293 if (sqlNumRows($result) == 1) {
295 list($id) = sqlFetchRow($result);
299 sqlFreeResult($result);