433
|
1 |
<?php
|
|
2 |
|
|
3 |
/*
|
|
4 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
|
1081
745200a9cc2a
Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Dan Fuhry
|
433
|
6 |
*
|
|
7 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
|
|
8 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
11 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
|
|
12 |
*/
|
|
13 |
|
465
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
14 |
function page_Admin_ThemeManager($force_no_json = false)
|
433
|
15 |
{
|
|
16 |
global $db, $session, $paths, $template, $plugins; // Common objects
|
|
17 |
global $lang;
|
976
|
18 |
global $cache;
|
|
19 |
|
433
|
20 |
if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
|
|
21 |
{
|
|
22 |
$login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
|
|
23 |
echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
|
|
24 |
echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
|
|
25 |
return;
|
|
26 |
}
|
|
27 |
|
471
7906fb190fc1
Implemented all security features on theme disabling and ACLs; added clean_key mode to login API to clean unused encryption keys
Dan
diff
changeset
|
28 |
$system_themes =& $template->system_themes;
|
433
|
29 |
|
|
30 |
// Obtain the list of themes (both available and already installed) and the styles available for each
|
|
31 |
$dh = @opendir(ENANO_ROOT . '/themes');
|
|
32 |
if ( !$dh )
|
|
33 |
die('Couldn\'t open themes directory');
|
|
34 |
$themes = array();
|
|
35 |
while ( $dr = @readdir($dh) )
|
|
36 |
{
|
|
37 |
if ( $dr == '.' || $dr == '..' )
|
|
38 |
continue;
|
|
39 |
if ( !is_dir(ENANO_ROOT . "/themes/$dr") )
|
|
40 |
continue;
|
|
41 |
if ( !file_exists(ENANO_ROOT . "/themes/$dr/theme.cfg") || !is_dir(ENANO_ROOT . "/themes/$dr/css") )
|
|
42 |
continue;
|
|
43 |
$cdh = @opendir(ENANO_ROOT . "/themes/$dr/css");
|
|
44 |
if ( !$cdh )
|
|
45 |
continue;
|
|
46 |
|
|
47 |
require(ENANO_ROOT . "/themes/$dr/theme.cfg");
|
|
48 |
global $theme;
|
|
49 |
|
|
50 |
$themes[$dr] = array(
|
|
51 |
'css' => array(),
|
|
52 |
'theme_name' => $theme['theme_name']
|
|
53 |
);
|
|
54 |
while ( $cdr = @readdir($cdh) )
|
|
55 |
{
|
|
56 |
if ( $cdr == '.' || $cdr == '..' )
|
|
57 |
continue;
|
|
58 |
if ( preg_match('/\.css$/i', $cdr) )
|
|
59 |
$themes[$dr]['css'][] = substr($cdr, 0, -4);
|
|
60 |
}
|
|
61 |
}
|
|
62 |
|
|
63 |
// Decide which themes are not installed
|
|
64 |
$installable = array_flip(array_keys($themes));
|
|
65 |
// FIXME: sanitize directory names or check with preg_match()
|
|
66 |
$where_clause = 'theme_id = \'' . implode('\' OR theme_id = \'', array_flip($installable)) . '\'';
|
|
67 |
$q = $db->sql_query('SELECT theme_id, theme_name, enabled FROM ' . table_prefix . "themes WHERE $where_clause;");
|
|
68 |
if ( !$q )
|
|
69 |
$db->_die();
|
|
70 |
|
|
71 |
while ( $row = $db->fetchrow() )
|
|
72 |
{
|
|
73 |
$tid =& $row['theme_id'];
|
|
74 |
unset($installable[$tid]);
|
|
75 |
$themes[$tid]['theme_name'] = $row['theme_name'];
|
|
76 |
$themes[$tid]['enabled'] = ( $row['enabled'] == 1 );
|
|
77 |
}
|
|
78 |
|
|
79 |
foreach ( $system_themes as $st )
|
|
80 |
{
|
|
81 |
unset($installable[$st]);
|
|
82 |
}
|
|
83 |
|
|
84 |
$installable = array_flip($installable);
|
|
85 |
|
|
86 |
// AJAX code
|
465
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
87 |
if ( $paths->getParam(0) === 'action.json' && !$force_no_json )
|
433
|
88 |
{
|
|
89 |
return ajaxServlet_Admin_ThemeManager($themes);
|
|
90 |
}
|
|
91 |
|
|
92 |
// List installed themes
|
|
93 |
?>
|
|
94 |
<div style="float: right;">
|
|
95 |
<a href="#" id="systheme_toggler" onclick="ajaxToggleSystemThemes(); return false;"><?php echo $lang->get('acptm_btn_system_themes_show'); ?></a>
|
|
96 |
</div>
|
|
97 |
<?php
|
|
98 |
echo '<h3>' . $lang->get('acptm_heading_edit_themes') . '</h3>';
|
|
99 |
echo '<div id="theme_list_edit">';
|
|
100 |
foreach ( $themes as $theme_id => $theme_data )
|
|
101 |
{
|
|
102 |
if ( in_array($theme_id, $installable) )
|
|
103 |
continue;
|
|
104 |
if ( file_exists(ENANO_ROOT . "/themes/$theme_id/preview.png") )
|
|
105 |
{
|
|
106 |
$preview_path = scriptPath . "/themes/$theme_id/preview.png";
|
|
107 |
}
|
|
108 |
else
|
|
109 |
{
|
|
110 |
$preview_path = scriptPath . "/images/themepreview.png";
|
|
111 |
}
|
|
112 |
$d = ( @$theme_data['enabled'] ) ? '' : ' themebutton_theme_disabled';
|
|
113 |
$st = ( in_array($theme_id, $system_themes) ) ? ' themebutton_theme_system' : '';
|
|
114 |
echo '<div class="themebutton' . $st . '' . $d . '" id="themebtn_edit_' . $theme_id . '" style="background-image: url(' . $preview_path . ');">';
|
|
115 |
if ( in_array($theme_id, $system_themes) )
|
|
116 |
{
|
|
117 |
echo '<a class="tb-inner" href="#" onclick="return false;">
|
|
118 |
' . $lang->get('acptm_btn_theme_system') . '
|
|
119 |
<span class="themename">' . htmlspecialchars($theme_data['theme_name']) . '</span>
|
|
120 |
</a>';
|
|
121 |
}
|
|
122 |
else
|
|
123 |
{
|
|
124 |
echo '<a class="tb-inner" href="#" onclick="ajaxEditTheme(\'' . $theme_id . '\'); return false;">
|
|
125 |
' . $lang->get('acptm_btn_theme_edit') . '
|
|
126 |
<span class="themename">' . htmlspecialchars($theme_data['theme_name']) . '</span>
|
|
127 |
</a>';
|
|
128 |
}
|
|
129 |
echo '</div>';
|
|
130 |
}
|
|
131 |
echo '</div>';
|
|
132 |
echo '<span class="menuclear"></span>';
|
|
133 |
|
|
134 |
if ( count($installable) > 0 )
|
|
135 |
{
|
|
136 |
echo '<h3>' . $lang->get('acptm_heading_install_themes') . '</h3>';
|
|
137 |
|
|
138 |
echo '<div id="theme_list_install">';
|
|
139 |
foreach ( $installable as $i => $theme_id )
|
|
140 |
{
|
|
141 |
if ( file_exists(ENANO_ROOT . "/themes/$theme_id/preview.png") )
|
|
142 |
{
|
|
143 |
$preview_path = scriptPath . "/themes/$theme_id/preview.png";
|
|
144 |
}
|
|
145 |
else
|
|
146 |
{
|
|
147 |
$preview_path = scriptPath . "/images/themepreview.png";
|
|
148 |
}
|
|
149 |
echo '<div class="themebutton" id="themebtn_install_' . $theme_id . '" enano:themename="' . htmlspecialchars($themes[$theme_id]['theme_name']) . '" style="background-image: url(' . $preview_path . ');">';
|
|
150 |
echo '<a class="tb-inner" href="#" onclick="ajaxInstallTheme(\'' . $theme_id . '\'); return false;">
|
|
151 |
' . $lang->get('acptm_btn_theme_install') . '
|
|
152 |
<span class="themename">' . htmlspecialchars($themes[$theme_id]['theme_name']) . '</span>
|
|
153 |
</a>';
|
|
154 |
echo '</div>';
|
|
155 |
}
|
|
156 |
echo '</div>';
|
|
157 |
echo '<span class="menuclear"></span>';
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
function ajaxServlet_Admin_ThemeManager(&$themes)
|
|
162 |
{
|
|
163 |
global $db, $session, $paths, $template, $plugins; // Common objects
|
|
164 |
global $lang;
|
976
|
165 |
global $cache;
|
|
166 |
|
433
|
167 |
if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
|
|
168 |
{
|
|
169 |
$login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
|
|
170 |
echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
|
|
171 |
echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
|
|
172 |
return;
|
|
173 |
}
|
|
174 |
|
|
175 |
if ( !isset($_POST['r']) )
|
|
176 |
return false;
|
|
177 |
|
|
178 |
try
|
|
179 |
{
|
|
180 |
$request = enano_json_decode($_POST['r']);
|
|
181 |
}
|
|
182 |
catch ( Exception $e )
|
|
183 |
{
|
|
184 |
die('Exception in JSON parser, probably invalid input.');
|
|
185 |
}
|
|
186 |
|
|
187 |
if ( !isset($request['mode']) )
|
|
188 |
{
|
|
189 |
die('No mode specified in JSON request.');
|
|
190 |
}
|
|
191 |
|
|
192 |
switch ( $request['mode'] )
|
|
193 |
{
|
|
194 |
case 'fetch_theme':
|
|
195 |
$theme_id = $db->escape($request['theme_id']);
|
|
196 |
if ( empty($theme_id) )
|
|
197 |
die('Invalid theme_id');
|
|
198 |
|
|
199 |
$q = $db->sql_query("SELECT theme_id, theme_name, default_style, enabled, group_policy, group_list FROM " . table_prefix . "themes WHERE theme_id = '$theme_id';");
|
|
200 |
if ( !$q )
|
|
201 |
$db->die_json();
|
|
202 |
|
|
203 |
if ( $db->numrows() < 1 )
|
|
204 |
die('BUG: no theme with that theme_id installed.');
|
|
205 |
|
|
206 |
$row = $db->fetchrow();
|
|
207 |
$row['enabled'] = ( $row['enabled'] == 1 );
|
|
208 |
$row['css'] = @$themes[$theme_id]['css'];
|
|
209 |
$row['default_style'] = preg_replace('/\.css$/', '', $row['default_style']);
|
|
210 |
$row['is_default'] = ( getConfig('theme_default') === $theme_id );
|
|
211 |
$row['group_list'] = ( empty($row['group_list']) ) ? array() : enano_json_decode($row['group_list']);
|
|
212 |
|
|
213 |
// Build a list of group names
|
|
214 |
$row['group_names'] = array();
|
465
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
215 |
$q = $db->sql_query('SELECT group_id, group_name FROM ' . table_prefix . 'groups;');
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
216 |
if ( !$q )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
217 |
$db->die_json();
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
218 |
while ( $gr = $db->fetchrow() )
|
433
|
219 |
{
|
465
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
220 |
$row['group_names'][ intval($gr['group_id']) ] = $gr['group_name'];
|
433
|
221 |
}
|
465
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
222 |
$db->free_result();
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
223 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
224 |
// Build a list of usernames
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
225 |
$row['usernames'] = array();
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
226 |
foreach ( $row['group_list'] as $el )
|
433
|
227 |
{
|
465
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
228 |
if ( !preg_match('/^u:([0-9]+)$/', $el, $match) )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
229 |
continue;
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
230 |
$uid =& $match[1];
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
231 |
$q = $db->sql_query('SELECT username FROM ' . table_prefix . "users WHERE user_id = $uid;");
|
433
|
232 |
if ( !$q )
|
|
233 |
$db->die_json();
|
465
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
234 |
if ( $db->numrows() < 1 )
|
433
|
235 |
{
|
465
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
236 |
$db->free_result();
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
237 |
continue;
|
433
|
238 |
}
|
465
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
239 |
list($username) = $db->fetchrow_num();
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
240 |
$row['usernames'][$uid] = $username;
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
241 |
$db->free_result();
|
433
|
242 |
}
|
|
243 |
|
|
244 |
echo enano_json_encode($row);
|
|
245 |
break;
|
465
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
246 |
case 'uid_lookup':
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
247 |
$username = @$request['username'];
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
248 |
if ( empty($username) )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
249 |
{
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
250 |
die(enano_json_encode(array(
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
251 |
'mode' => 'error',
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
252 |
'error' => $lang->get('acptm_err_invalid_username')
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
253 |
)));
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
254 |
}
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
255 |
$username = $db->escape(strtolower($username));
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
256 |
$q = $db->sql_query('SELECT user_id, username FROM ' . table_prefix . "users WHERE " . ENANO_SQLFUNC_LOWERCASE . "(username) = '$username';");
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
257 |
if ( !$q )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
258 |
$db->die_json();
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
259 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
260 |
if ( $db->numrows() < 1 )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
261 |
{
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
262 |
die(enano_json_encode(array(
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
263 |
'mode' => 'error',
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
264 |
'error' => $lang->get('acptm_err_username_not_found')
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
265 |
)));
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
266 |
}
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
267 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
268 |
list($uid, $username_real) = $db->fetchrow_num();
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
269 |
$db->free_result();
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
270 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
271 |
echo enano_json_encode(array(
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
272 |
'uid' => $uid,
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
273 |
'username' => $username_real
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
274 |
));
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
275 |
break;
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
276 |
case 'save_theme':
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
277 |
if ( !isset($request['theme_data']) )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
278 |
{
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
279 |
die(enano_json_encode(array(
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
280 |
'mode' => 'error',
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
281 |
'error' => 'No theme data in request'
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
282 |
)));
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
283 |
}
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
284 |
$theme_data =& $request['theme_data'];
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
285 |
// Perform integrity check on theme data
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
286 |
$chk_theme_exists = isset($themes[@$theme_data['theme_id']]);
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
287 |
$theme_data['theme_name'] = trim(@$theme_data['theme_name']);
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
288 |
$chk_name_good = !empty($theme_data['theme_name']);
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
289 |
$chk_policy_good = in_array(@$theme_data['group_policy'], array('allow_all', 'whitelist', 'blacklist'));
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
290 |
$chk_grouplist_good = true;
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
291 |
foreach ( $theme_data['group_list'] as $acl_entry )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
292 |
{
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
293 |
if ( !preg_match('/^(u|g):[0-9]+$/', $acl_entry) )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
294 |
{
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
295 |
$chk_grouplist_good = false;
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
296 |
break;
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
297 |
}
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
298 |
}
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
299 |
$chk_style_good = @in_array(@$theme_data['default_style'], @$themes[@$theme_data['theme_id']]['css']);
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
300 |
if ( !$chk_theme_exists || !$chk_name_good || !$chk_policy_good || !$chk_grouplist_good || !$chk_style_good )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
301 |
{
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
302 |
die(enano_json_encode(array(
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
303 |
'mode' => 'error',
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
304 |
'error' => $lang->get('acptm_err_save_validation_failed')
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
305 |
)));
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
306 |
}
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
307 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
308 |
$enable = ( $theme_data['enabled'] ) ? '1' : '0';
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
309 |
$theme_default = getConfig('theme_default');
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
310 |
$warn_default = ( $theme_default === $theme_data['theme_id'] || $theme_data['make_default'] ) ?
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
311 |
' ' . $lang->get('acptm_warn_access_with_default') . ' ' :
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
312 |
' ';
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
313 |
if ( $enable == 0 && ( $theme_default === $theme_data['theme_id'] || $theme_data['make_default'] ) )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
314 |
{
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
315 |
$enable = '1';
|
471
7906fb190fc1
Implemented all security features on theme disabling and ACLs; added clean_key mode to login API to clean unused encryption keys
Dan
diff
changeset
|
316 |
$warn_default .= '<b>' . $lang->get('acptm_warn_cant_disable_default') . '</b>';
|
465
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
317 |
}
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
318 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
319 |
// We're good. Update the theme...
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
320 |
$q = $db->sql_query('UPDATE ' . table_prefix . 'themes SET
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
321 |
theme_name = \'' . $db->escape($theme_data['theme_name']) . '\',
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
322 |
default_style = \'' . $db->escape($theme_data['default_style']) . '\',
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
323 |
group_list = \'' . $db->escape(enano_json_encode($theme_data['group_list'])) . '\',
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
324 |
group_policy = \'' . $db->escape($theme_data['group_policy']) . '\',
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
325 |
enabled = ' . $enable . '
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
326 |
WHERE theme_id = \'' . $db->escape($theme_data['theme_id']) . '\';');
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
327 |
if ( !$q )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
328 |
$db->die_json();
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
329 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
330 |
if ( $theme_data['make_default'] )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
331 |
{
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
332 |
setConfig('theme_default', $theme_data['theme_id']);
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
333 |
}
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
334 |
|
976
|
335 |
$cache->purge('themes');
|
|
336 |
|
465
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
337 |
echo '<div class="info-box"><b>' . $lang->get('acptm_msg_save_success') . '</b>' . $warn_default . '</div>';
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
338 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
339 |
page_Admin_ThemeManager(true);
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
340 |
break;
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
341 |
case 'install':
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
342 |
$theme_id =& $request['theme_id'];
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
343 |
if ( !isset($themes[$theme_id]) )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
344 |
{
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
345 |
die(enano_json_encode(array(
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
346 |
'mode' => 'error',
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
347 |
'error' => 'Theme was deleted from themes/ directory or couldn\'t read theme metadata from filesystem'
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
348 |
)));
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
349 |
}
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
350 |
if ( !isset($themes[$theme_id]['css'][0]) )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
351 |
{
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
352 |
die(enano_json_encode(array(
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
353 |
'mode' => 'error',
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
354 |
'error' => 'Theme doesn\'t have any files in css/, thus it can\'t be installed. (translators: l10n?)'
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
355 |
)));
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
356 |
}
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
357 |
// build dataset
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
358 |
$theme_name = $db->escape($themes[$theme_id]['theme_name']);
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
359 |
$default_style = $db->escape($themes[$theme_id]['css'][0]);
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
360 |
$theme_id = $db->escape($theme_id);
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
361 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
362 |
// insert it
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
363 |
$q = $db->sql_query('INSERT INTO ' . table_prefix . "themes(theme_id, theme_name, default_style, enabled, group_list, group_policy)\n"
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
364 |
. " VALUES( '$theme_id', '$theme_name', '$default_style', 1, '[]', 'allow_all' );");
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
365 |
if ( !$q )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
366 |
$db->die_json();
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
367 |
|
976
|
368 |
$cache->purge('themes');
|
|
369 |
|
465
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
370 |
// The response isn't processed unless it's in JSON.
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
371 |
echo 'Roger that, over and out.';
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
372 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
373 |
break;
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
374 |
case 'uninstall':
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
375 |
$theme_id =& $request['theme_id'];
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
376 |
$theme_default = getConfig('theme_default');
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
377 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
378 |
// Validation
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
379 |
if ( !isset($themes[$theme_id]) )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
380 |
{
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
381 |
die(enano_json_encode(array(
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
382 |
'mode' => 'error',
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
383 |
'error' => 'Theme was deleted from themes/ directory or couldn\'t read theme metadata from filesystem'
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
384 |
)));
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
385 |
}
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
386 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
387 |
if ( $theme_id == $theme_default )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
388 |
{
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
389 |
die(enano_json_encode(array(
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
390 |
'mode' => 'error',
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
391 |
'error' => $lang->get('acptm_err_uninstalling_default')
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
392 |
)));
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
393 |
}
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
394 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
395 |
if ( $theme_id == 'oxygen' )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
396 |
{
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
397 |
die(enano_json_encode(array(
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
398 |
'mode' => 'error',
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
399 |
'error' => $lang->get('acptm_err_uninstalling_oxygen')
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
400 |
)));
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
401 |
}
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
402 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
403 |
$theme_id = $db->escape($theme_id);
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
404 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
405 |
$q = $db->sql_query('DELETE FROM ' . table_prefix . "themes WHERE theme_id = '$theme_id';");
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
406 |
if ( !$q )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
407 |
$db->die_json();
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
408 |
|
976
|
409 |
$cache->purge('themes');
|
|
410 |
|
465
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
411 |
// Change all the users that were on that theme to the default
|
477
|
412 |
$default_style = $template->named_theme_list[$theme_default]['default_style'];
|
465
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
413 |
$default_style = preg_replace('/\.css$/', '', $default_style);
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
414 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
415 |
$theme_default = $db->escape($theme_default);
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
416 |
$default_style = $db->escape($default_style);
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
417 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
418 |
$q = $db->sql_query('UPDATE ' . table_prefix . "users SET theme = '$theme_default', style = '$default_style' WHERE theme = '$theme_id';");
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
419 |
if ( !$q )
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
420 |
$db->die_json();
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
421 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
422 |
echo '<div class="info-box">' . $lang->get('acptm_msg_uninstall_success') . '</div>';
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
423 |
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
424 |
page_Admin_ThemeManager(true);
|
fe8b8c9b54e8
Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
Dan
diff
changeset
|
425 |
break;
|
433
|
426 |
}
|
|
427 |
}
|
|
428 |
|