f8fd66dbd5a1fc2a764fd40bc186fd5963f128fe
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Create a selection box with installed and activated themes
41 function THEME_SELECTION_BOX ($mod, $act, $wht, $result) {
42         // Construction URL
43         $formAction = "{!URL!}/modules.php?module=".$mod;
44         if (!empty($act)) $formAction .= "&amp;action=".$act;
45         if (!empty($wht)) $formAction .= "&amp;what=".$wht;
46
47         // Initialize array
48         $themesArray = array(
49                 'theme_unix'   => array(), // Unix name from filesystem
50                 'theme_name'   => array()  // Title
51         );
52
53         // Load all themes
54         while ($content = SQL_FETCHARRAY($result)) {
55                 // Load it's theme.php file
56                 $INC = sprintf("theme/%s/theme.php", SQL_ESCAPE($content['theme_path']));
57                 if (INCLUDE_READABLE($INC)) {
58                         // And save all data in array
59                         LOAD_INC($INC);
60                         $themesArray['theme_unix'][] = $content['theme_path'];
61                         $themesArray['theme_name'][] = $THEME_NAME;
62                 } // END - if
63         } // END - while
64
65         // Sort whole array by title
66         array_pk_sort($themesArray, array("theme_name"));
67
68         // Construct selection form for the box template
69         $OUT = "";
70         foreach ($themesArray['theme_unix'] as $key => $theme) {
71                 $OUT .= "  <option value=\"".$theme."\"";
72                 if ($theme == GET_CURR_THEME()) $OUT .= " selected=\"selected\"";
73                 $OUT .= ">".$themesArray['theme_name'][$key]."</option>\n";
74         } // END - foreach
75
76         // Remember content
77         $content = array(
78                 'form_action' => $formAction,
79                 'selection'   => $OUT
80         );
81
82         // Return generated selection
83         return LOAD_TEMPLATE("theme_select_form", true, $content);
84 }
85
86 // Get version from name
87 function THEME_GET_VERSION ($name) {
88         // Is the extension "theme" installed?
89         if (!EXT_IS_ACTIVE("theme")) {
90                 // Then abort here
91                 return "!.!";
92         } // END - if
93
94         // Default version "number"
95         $cver = "?.?";
96
97         // Is the cache entry there?
98         if (isset($GLOBALS['cache_array']['themes']['theme_ver'][$name])) {
99                 // Get the version from cache
100                 $cver = $GLOBALS['cache_array']['themes']['theme_ver'][$name];
101
102                 // Count up
103                 incrementConfigEntry('cache_hits');
104         } elseif (GET_EXT_VERSION("cache") != "0.1.8") {
105                 // Load version from database
106                 $result = SQL_QUERY_ESC("SELECT theme_ver FROM `{!_MYSQL_PREFIX!}_themes` WHERE theme_path='%s' LIMIT 1",
107                         array($name), __FUNCTION__, __LINE__);
108
109                 // Entry found?
110                 if (SQL_NUMROWS($result) == 1) {
111                         // Fetch data
112                         list($cver) = SQL_FETCHROW($result);
113                 } // END - if
114
115                 // Free result
116                 SQL_FREERESULT($result);
117         }
118
119         // Return version
120         return $cver;
121 }
122
123 // Checks wether a theme is found in db
124 function THEME_CHECK_EXIST ($name) {
125         // Get theme and is it not nul?
126         return (THEME_GET_ID($name) > 0);
127 }
128
129 // Checks if a theme is active
130 function THEME_IS_ACTIVE ($name) {
131         // Is the extension "theme" installed?
132         if (!EXT_IS_ACTIVE("theme")) {
133                 // Then abort here
134                 return false;
135         } // END - if
136
137         // Default is nothing active
138         $active = false;
139
140         // Is the cache entry there?
141         if (isset($GLOBALS['cache_array']['themes']['theme_active'][$name])) {
142                 // Get the version from cache
143                 $active = ($GLOBALS['cache_array']['themes']['theme_active'][$name] == "Y");
144
145                 // Count up
146                 incrementConfigEntry('cache_hits');
147         } elseif (GET_EXT_VERSION("cache") != "0.1.8") {
148                 // Check if current theme is already imported or not
149                 $result = SQL_QUERY_ESC("SELECT theme_active FROM `{!_MYSQL_PREFIX!}_themes` WHERE theme_path='%s' AND theme_active='Y' LIMIT 1",
150                         array($name), __FUNCTION__, __LINE__);
151
152                 // Is the theme active and installed?
153                 $active = (SQL_NUMROWS($result) == 1);
154
155                 // Free result
156                 SQL_FREERESULT($result);
157         }
158
159         // Return result
160         return $active;
161 }
162
163 // Gets current human-readable theme name
164 function GET_CURR_THEME_NAME () {
165         // Is the extension "theme" installed?
166         if (!EXT_IS_ACTIVE("theme")) {
167                 // Then abort here
168                 return "default";
169         } // END - if
170
171         // Get the Uni* name
172         $name = GET_CURR_THEME();
173
174         // Is the cache entry there?
175         if (isset($GLOBALS['cache_array']['themes']['theme_name'][$name])) {
176                 // Get the version from cache
177                 $name = $GLOBALS['cache_array']['themes']['theme_name'][$name];
178
179                 // Count up
180                 incrementConfigEntry('cache_hits');
181         } elseif (GET_EXT_VERSION("cache") != "0.1.8") {
182                 // Check if current theme is already imported or not
183                 $result = SQL_QUERY_ESC("SELECT theme_name FROM `{!_MYSQL_PREFIX!}_themes` WHERE theme_path='%s' AND theme_active='Y' LIMIT 1",
184                         array($name), __FUNCTION__, __LINE__);
185
186                 // Load theme name
187                 list($name) = SQL_FETCHROW($result);
188
189                 // Free result
190                 SQL_FREERESULT($result);
191         }
192
193         // Return name
194         return $name;
195 }
196
197 // Initialize variables
198 $GLOBALS['curr_theme'] = GET_CURR_THEME();
199
200 // Check if new theme is selcted
201 if ((REQUEST_ISSET_POST(('new_theme'))) && (REQUEST_POST('new_theme') != $GLOBALS['curr_theme'])) {
202         // Set new theme for guests
203         $newTheme = REQUEST_POST('new_theme');
204
205         // Change to new theme
206         set_session('mxchange_theme', $newTheme);
207
208         // Remove current from array and set new
209         $theme = sprintf("%stheme/%s/theme.php", constant('PATH'), $GLOBALS['curr_theme']);
210         unset($INC_POOL[array_search($theme, $INC_POOL)]);
211         $INC_POOL[] = sprintf("%stheme/%s/theme.php", constant('PATH'), $newTheme);
212 } // END - if
213
214 //
215 ?>