44363a8c7cc42d1f8ebb72afc8e975ae7d4d5f09
[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
46 function generateThemeSelectionBox ($mod, $act, $wht, $result) {
47         // Construction URL
48         $formAction = "{!URL!}/modules.php?module=".$mod;
49         if (!empty($act)) $formAction .= "&amp;action=".$act;
50         if (!empty($wht)) $formAction .= "&amp;what=".$wht;
51
52         // Initialize array
53         $themesArray = array(
54                 'theme_unix'   => array(), // Unix name from filesystem
55                 'theme_name'   => array()  // Title
56         );
57
58         // Load all themes
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 (isIncludeReadable($INC)) {
63                         // And save all data in array
64                         loadInclude($INC);
65                         $themesArray['theme_unix'][] = $content['theme_path'];
66                         $themesArray['theme_name'][] = $GLOBALS['theme_data']['name'];
67                 } // END - if
68         } // END - while
69
70         // Sort whole array by title
71         array_pk_sort($themesArray, array('theme_name'));
72
73         // Construct selection form for the box template
74         $OUT = '';
75         foreach ($themesArray['theme_unix'] as $key => $theme) {
76                 $OUT .= "  <option value=\"".$theme."\"";
77                 if ($theme == getCurrentTheme()) $OUT .= ' selected="selected"';
78                 $OUT .= ">".$themesArray['theme_name'][$key]."</option>\n";
79         } // END - foreach
80
81         // Remember content
82         $content = array(
83                 'form_action' => $formAction,
84                 'selection'   => $OUT
85         );
86
87         // Return generated selection
88         return LOAD_TEMPLATE('theme_select_form', true, $content);
89 }
90
91 // Get version from name
92 function THEME_GET_VERSION ($name) {
93         // Is the extension 'theme' installed?
94         if (!EXT_IS_ACTIVE('theme')) {
95                 // Then abort here
96                 return '!.!';
97         } // END - if
98
99         // Default version 'number'
100         $cver = '?.?';
101
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];
106
107                 // Count up
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__);
113
114                 // Entry found?
115                 if (SQL_NUMROWS($result) == 1) {
116                         // Fetch data
117                         list($cver) = SQL_FETCHROW($result);
118                 } // END - if
119
120                 // Free result
121                 SQL_FREERESULT($result);
122         }
123
124         // Return version
125         return $cver;
126 }
127
128 // Checks wether a theme is found in db
129 function ifThemeExists ($name) {
130         // Get theme and is it not nul?
131         return (getThemeId($name) > 0);
132 }
133
134 // Checks if a theme is active
135 function isThemeActive ($name) {
136         // Is the extension 'theme' installed?
137         if (!EXT_IS_ACTIVE('theme')) {
138                 // Then abort here
139                 return false;
140         } // END - if
141
142         // Default is nothing active
143         $active = false;
144
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');
149
150                 // Count up
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__);
156
157                 // Is the theme active and installed?
158                 $active = (SQL_NUMROWS($result) == 1);
159
160                 // Free result
161                 SQL_FREERESULT($result);
162         }
163
164         // Return result
165         return $active;
166 }
167
168 // Gets current human-readable theme name
169 function getCurrentThemeName () {
170         // Is the extension 'theme' installed?
171         if (!EXT_IS_ACTIVE('theme')) {
172                 // Then abort here
173                 return 'default';
174         } // END - if
175
176         // Get the Uni* name
177         $name = getCurrentTheme();
178
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];
183
184                 // Count up
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__);
190
191                 // Load theme name
192                 list($name) = SQL_FETCHROW($result);
193
194                 // Free result
195                 SQL_FREERESULT($result);
196         }
197
198         // Return name
199         return $name;
200 }
201
202 // Initialize variables
203 $GLOBALS['curr_theme'] = getCurrentTheme();
204
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');
209
210         // Change to new theme
211         setSession('mxchange_theme', $newTheme);
212
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));
217 } // END - if
218
219 // [EOF]
220 ?>