Huge script change, see http://forum.mxchange.org/topic-458.html for details:
[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 - 2009 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         die();
42 }
43
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
47         $what = '';
48         $mod = getModule();
49         if (isWhatSet()) {
50                 $what = getWhat();
51         } // END - if
52
53         // Construction URL
54         $formAction = "{?URL?}/modules.php?module=" . $mod;
55         if (!empty($what)) $formAction .= "&amp;what=" . $what;
56
57         // Initialize array
58         $themesArray = array(
59                 'theme_unix'   => array(), // Unix name from filesystem
60                 'theme_name'   => array()  // Title
61         );
62
63         // Only activated themes for the user
64         $add = " WHERE `theme_active`='Y'";
65
66         // Do we have admin?
67         if (isAdmin()) $add = '';
68
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__);
71
72         // Load all themes
73         while ($content = SQL_FETCHARRAY($result)) {
74                 // Construct relative include file name
75                 $inc = sprintf("theme/%s/theme.php", SQL_ESCAPE($content['theme_path']));
76
77                 // Load it's theme.php file if found
78                 if (isIncludeReadable($inc)) {
79                         // And save all data in array
80                         loadInclude($inc);
81                         $themesArray['theme_unix'][] = $content['theme_path'];
82                         $themesArray['theme_name'][] = $GLOBALS['theme_data']['name'];
83                 } // END - if
84         } // END - while
85
86         // Free the result
87         SQL_FREERESULT($result);
88
89         // Construct selection form for the box template
90         $OUT = '';
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";
95         } // END - foreach
96
97         // Remember content
98         $content = array(
99                 'form_action' => $formAction,
100                 'selection'   => $OUT
101         );
102
103         // Return generated selection
104         return loadTemplate('theme_select_form', true, $content);
105 }
106
107 // Get version from name
108 function getThemeVersion ($name) {
109         // Is the extension 'theme' installed?
110         if (!isExtensionActive('theme')) {
111                 // Then abort here
112                 return '!.!';
113         } // END - if
114
115         // Default version 'number'
116         $cver = '?.?';
117
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];
122
123                 // Count up
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__);
129
130                 // Entry found?
131                 if (SQL_NUMROWS($result) == 1) {
132                         // Fetch data
133                         list($cver) = SQL_FETCHROW($result);
134                 } // END - if
135
136                 // Free result
137                 SQL_FREERESULT($result);
138         }
139
140         // Return version
141         return $cver;
142 }
143
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);
148 }
149
150 // Checks if a theme is active
151 function isThemeActive ($name) {
152         // Is the extension 'theme' installed?
153         if (!isExtensionActive('theme')) {
154                 // Then abort here
155                 return false;
156         } // END - if
157
158         // Default is nothing active
159         $active = false;
160
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');
165
166                 // Count up
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__);
172
173                 // Is the theme active and installed?
174                 $active = (SQL_NUMROWS($result) == 1);
175
176                 // Free result
177                 SQL_FREERESULT($result);
178         }
179
180         // Return result
181         return $active;
182 }
183
184 // Gets current human-readable theme name
185 function getCurrentThemeName () {
186         // Is the extension 'theme' installed?
187         if (!isExtensionActive('theme')) {
188                 // Then abort here
189                 return 'default';
190         } // END - if
191
192         // Get the Uni* name
193         $name = getCurrentTheme();
194
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];
199
200                 // Count up
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__);
206
207                 // Load theme name
208                 list($name) = SQL_FETCHROW($result);
209
210                 // Free result
211                 SQL_FREERESULT($result);
212         }
213
214         // Return name
215         return $name;
216 }
217
218 // Initialize variables
219 $GLOBALS['curr_theme'] = getCurrentTheme();
220
221 // Check if new theme is selcted
222 if ((isPostRequestElementSet('new_theme')) && (postRequestElement('new_theme') != $GLOBALS['curr_theme'])) {
223         // Set new theme for guests
224         $newTheme = postRequestElement('new_theme');
225
226         // Change to new theme
227         setTheme($newTheme);
228
229         // Remove current from array
230         removeIncludeFromPool('theme', sprintf("theme/%s/theme.php", $GLOBALS['curr_theme']));
231
232         // Add new theme
233         addIncludeToPool('theme', sprintf("theme/%s/theme.php", $newTheme));
234 } // END - if
235
236 // [EOF]
237 ?>