Several more constants rewritten to getConfig()
[mailer.git] / inc / libs / theme_functions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 12/03/2004 *
4  * ===============                              Last change: 12/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : theme-manager.php                                *
8  * -------------------------------------------------------------------- *
9  * Short description : Theme manager                                    *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Themen-Manager                                   *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Create a selection box with installed and activated themes or all if admin
46 function generateThemeSelectionBox () {
47         // Init variables and fill them if set
48         $what = '';
49         $mod = getModule();
50         if (isWhatSet()) {
51                 $what = getWhat();
52         } // END - if
53
54         // Construction URL
55         $formAction = "{?URL?}/modules.php?module=" . $mod;
56         if (!empty($what)) $formAction .= "&amp;what=" . $what;
57
58         // Initialize array
59         $themesArray = array(
60                 'theme_unix'   => array(), // Unix name from filesystem
61                 'theme_name'   => array()  // Title
62         );
63
64         // Only activated themes for the user
65         $add = " WHERE `theme_active`='Y'";
66
67         // Do we have admin?
68         if (IS_ADMIN()) $add = '';
69
70         // Select all themes we want
71         $result = SQL_QUERY("SELECT `theme_path`, `theme_name` FROM `{!_MYSQL_PREFIX!}_themes`".$add." ORDER BY `theme_name` ASC", __FILE__, __LINE__);
72
73         // Load all themes
74         while ($content = SQL_FETCHARRAY($result)) {
75                 // Construct relative include file name
76                 $INC = sprintf("theme/%s/theme.php", SQL_ESCAPE($content['theme_path']));
77
78                 // Load it's theme.php file if found
79                 if (isIncludeReadable($INC)) {
80                         // And save all data in array
81                         loadInclude($INC);
82                         $themesArray['theme_unix'][] = $content['theme_path'];
83                         $themesArray['theme_name'][] = $GLOBALS['theme_data']['name'];
84                 } // END - if
85         } // END - while
86
87         // Free the result
88         SQL_FREERESULT($result);
89
90         // Construct selection form for the box template
91         $OUT = '';
92         foreach ($themesArray['theme_unix'] as $key => $theme) {
93                 $OUT .= "  <option value=\"".$theme."\"";
94                 if ($theme == getCurrentTheme()) $OUT .= ' selected="selected"';
95                 $OUT .= ">".$themesArray['theme_name'][$key]."</option>\n";
96         } // END - foreach
97
98         // Remember content
99         $content = array(
100                 'form_action' => $formAction,
101                 'selection'   => $OUT
102         );
103
104         // Return generated selection
105         return LOAD_TEMPLATE('theme_select_form', true, $content);
106 }
107
108 // Get version from name
109 function THEME_GET_VERSION ($name) {
110         // Is the extension 'theme' installed?
111         if (!EXT_IS_ACTIVE('theme')) {
112                 // Then abort here
113                 return '!.!';
114         } // END - if
115
116         // Default version 'number'
117         $cver = '?.?';
118
119         // Is the cache entry there?
120         if (isset($GLOBALS['cache_array']['themes']['theme_ver'][$name])) {
121                 // Get the version from cache
122                 $cver = $GLOBALS['cache_array']['themes']['theme_ver'][$name];
123
124                 // Count up
125                 incrementConfigEntry('cache_hits');
126         } elseif (GET_EXT_VERSION('cache') != '0.1.8') {
127                 // Load version from database
128                 $result = SQL_QUERY_ESC("SELECT `theme_ver` FROM `{!_MYSQL_PREFIX!}_themes` WHERE `theme_path`='%s' LIMIT 1",
129                         array($name), __FUNCTION__, __LINE__);
130
131                 // Entry found?
132                 if (SQL_NUMROWS($result) == 1) {
133                         // Fetch data
134                         list($cver) = SQL_FETCHROW($result);
135                 } // END - if
136
137                 // Free result
138                 SQL_FREERESULT($result);
139         }
140
141         // Return version
142         return $cver;
143 }
144
145 // Checks wether a theme is found in db
146 function ifThemeExists ($name) {
147         // Get theme and is it not nul?
148         return (getThemeId($name) > 0);
149 }
150
151 // Checks if a theme is active
152 function isThemeActive ($name) {
153         // Is the extension 'theme' installed?
154         if (!EXT_IS_ACTIVE('theme')) {
155                 // Then abort here
156                 return false;
157         } // END - if
158
159         // Default is nothing active
160         $active = false;
161
162         // Is the cache entry there?
163         if (isset($GLOBALS['cache_array']['themes']['theme_active'][$name])) {
164                 // Get the version from cache
165                 $active = ($GLOBALS['cache_array']['themes']['theme_active'][$name] == 'Y');
166
167                 // Count up
168                 incrementConfigEntry('cache_hits');
169         } elseif (GET_EXT_VERSION('cache') != '0.1.8') {
170                 // Check if current theme is already imported or not
171                 $result = SQL_QUERY_ESC("SELECT `theme_active` FROM `{!_MYSQL_PREFIX!}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
172                         array($name), __FUNCTION__, __LINE__);
173
174                 // Is the theme active and installed?
175                 $active = (SQL_NUMROWS($result) == 1);
176
177                 // Free result
178                 SQL_FREERESULT($result);
179         }
180
181         // Return result
182         return $active;
183 }
184
185 // Gets current human-readable theme name
186 function getCurrentThemeName () {
187         // Is the extension 'theme' installed?
188         if (!EXT_IS_ACTIVE('theme')) {
189                 // Then abort here
190                 return 'default';
191         } // END - if
192
193         // Get the Uni* name
194         $name = getCurrentTheme();
195
196         // Is the cache entry there?
197         if (isset($GLOBALS['cache_array']['themes']['theme_name'][$name])) {
198                 // Get the version from cache
199                 $name = $GLOBALS['cache_array']['themes']['theme_name'][$name];
200
201                 // Count up
202                 incrementConfigEntry('cache_hits');
203         } elseif (GET_EXT_VERSION('cache') != '0.1.8') {
204                 // Check if current theme is already imported or not
205                 $result = SQL_QUERY_ESC("SELECT `theme_name` FROM `{!_MYSQL_PREFIX!}_themes` WHERE `theme_path`='%s' AND `theme_active`='Y' LIMIT 1",
206                         array($name), __FUNCTION__, __LINE__);
207
208                 // Load theme name
209                 list($name) = SQL_FETCHROW($result);
210
211                 // Free result
212                 SQL_FREERESULT($result);
213         }
214
215         // Return name
216         return $name;
217 }
218
219 // Initialize variables
220 $GLOBALS['curr_theme'] = getCurrentTheme();
221
222 // Check if new theme is selcted
223 if ((REQUEST_ISSET_POST('new_theme')) && (REQUEST_POST('new_theme') != $GLOBALS['curr_theme'])) {
224         // Set new theme for guests
225         $newTheme = REQUEST_POST('new_theme');
226
227         // Change to new theme
228         setSession('mxchange_theme', $newTheme);
229
230         // Remove current from array
231         REMOVE_INC_FROM_POOL(sprintf("theme/%s/theme.php", $GLOBALS['curr_theme']));
232
233         // Add new theme
234         ADD_INC_TO_POOL(sprintf("theme/%s/theme.php", $newTheme));
235 } // END - if
236
237 // [EOF]
238 ?>