]> git.mxchange.org Git - mailer.git/blob - inc/theme-manager.php
Some template fixes, width='600' removed from many templates, surfbar admin extended...
[mailer.git] / inc / theme-manager.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 (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40
41 // Always make sure the session management is initialized first
42 require_once(PATH."inc/session.php");
43
44 //
45 function GET_CURR_THEME() {
46         global $INC_POOL, $_CONFIG, $CSS;
47
48         // The default theme is 'default'... ;-)
49         $ret = "default";
50
51         // Load default theme if not empty from configuration
52         if (!empty($_CONFIG['default_theme'])) $ret = $_CONFIG['default_theme'];
53
54         if (!isSessionVariableSet('mxchange_theme')) {
55                 // Set default theme
56                 set_session("mxchange_theme", $ret);
57         } elseif ((isSessionVariableSet('mxchange_theme')) && (GET_EXT_VERSION("sql_patches") >= "0.1.4")) {
58                 // Get theme from cookie
59                 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_themes WHERE theme_path='%s' LIMIT 1", array(get_session('mxchange_theme')), __FILE__, __LINE__);
60                 if (SQL_NUMROWS($result) == 1) {
61                         // Design is valid!
62                         $ret = get_session('mxchange_theme');
63                 }
64
65                 // Free memory
66                 SQL_FREERESULT($result);
67         } elseif ((!isBooleanConstantAndTrue('mxchange_installed')) && ((isBooleanConstantAndTrue('mxchange_installing')) || ($CSS == true)) && ((!empty($_GET['theme'])) || (!empty($_POST['theme'])))) {
68                 // Prepare FQFN for checking
69                 $theme = sprintf("%stheme/%s/theme.php", PATH, $_GET['theme']);
70
71                 // Installation mode active
72                 if ((!empty($_GET['theme'])) && (file_exists($theme)) && (is_readable($theme))) {
73                         // Set cookie from URL data
74                         set_session("mxchange_theme", $_GET['theme']);
75                 } elseif (file_exists(PATH."theme/".$_POST['theme']."/theme.php")) {
76                         // Set cookie from posted data
77                         set_session("mxchange_theme", $_POST['theme']);
78                 }
79
80                 // Set return value
81                 $ret = get_session('mxchange_theme');
82         } else {
83                 // Invalid design, reset cookie
84                 set_session("mxchange_theme", $ret);
85         }
86
87         // Add (maybe) found theme.php file to inclusion list
88         $theme = sprintf("%stheme/%s/theme.php", PATH, SQL_ESCAPE($ret));
89
90         // Try to load the requested include file
91         if ((@file_exists($theme)) && (is_readable($theme))) $INC_POOL[] = $theme;
92
93         // Return theme value
94         return $ret;
95 }
96
97 function THEME_SELECTION_BOX($mod, $act, $wht, $result)
98 {
99         // Construction URL
100         global $currTheme;
101         $FORM = URL."/modules.php?module=".$mod;
102         if (!empty($act)) $FORM .= "&amp;action=".$act;
103         if (!empty($wht))   $FORM .= "&amp;what=".$wht;
104         define('__FORM_VALUE', $FORM);
105
106         // Initialize array
107         $THEMES = array(
108                 'theme_unix'   => array(), // Unix name from filesystem
109                 'theme_name'   => array()  // Title
110         );
111
112         // Load all themes
113         while(list($theme) = SQL_FETCHROW($result))
114         {
115                 // Load it's theme.php file
116                 $INC = PATH."theme/".$theme."/theme.php";
117                 if (file_exists($INC))
118                 {
119                         // And save all data in array
120                         include($INC);
121                         $THEMES['theme_unix'][] = $theme;
122                         $THEMES['theme_name'][] = $THEME_NAME;
123                 }
124         }
125
126         // Sort whole array by title
127         array_pk_sort($THEMES, array("theme_name"));
128
129         // Construct selection form for the box template
130         $OUT = "";
131         foreach ($THEMES['theme_unix'] as $key=>$theme)
132         {
133                 $OUT .= "  <OPTION value=\"".$theme."\"";
134                 if ($theme == $currTheme) $OUT .= " selected=\"selected\"";
135                 $OUT .= ">".$THEMES['theme_name'][$key]."</OPTION>\n";
136         }
137
138         // Return generated selection
139         define('__THEME_SELECTION_OPTIONS', $OUT);
140         $OUT = LOAD_TEMPLATE("theme_select_form", true);
141         return $OUT;
142 }
143
144 // Initialize variables
145 $currTheme = GET_CURR_THEME();
146 if (empty($_POST['new_theme'])) $_POST['new_theme'] = "";
147
148 // Check if new theme is selcted
149 if ((!empty($_POST['new_theme'])) && ($_POST['new_theme'] != $currTheme))
150 {
151         // Set new theme for guests
152         $NewTheme = $_POST['new_theme'];
153
154         // Change to new theme
155         set_session("mxchange_theme", $NewTheme);
156
157         // Remove current from array and set new
158         $theme = PATH."theme/".$currTheme."/theme.php";
159         unset($INC_POOL[array_search($theme, $INC_POOL)]);
160         $INC_POOL[] = PATH."theme/".$NewTheme."/theme.php";
161 }
162
163 // Remove variable again
164 unset($_POST['new_theme']);
165
166 //
167 ?>