| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
<span class="code-comment"> * admin_styles.php |
|---|
| 4 |
* ------------------- |
|---|
| 5 |
* begin : Thursday, Jul 12, 2001 |
|---|
| 6 |
* copyright : (C) 2001 The phpBB Group |
|---|
| 7 |
* email : support@phpbb.com |
|---|
| 8 |
* |
|---|
| 9 |
* $Id: admin_styles.php,v 1.27.2.15 2005/10/04 21:45:02 grahamje Exp $ |
|---|
| 10 |
* |
|---|
| 11 |
* |
|---|
| 12 |
***************************************************************************/ |
|---|
| 13 |
|
|---|
| 14 |
/*************************************************************************** |
|---|
| 15 |
* |
|---|
| 16 |
* This program is free software; you can redistribute it and/or modify |
|---|
| 17 |
* it under the terms of the GNU General Public License as published by |
|---|
| 18 |
* the Free Software Foundation; either version 2 of the License, or |
|---|
| 19 |
* (at your option) any later version. |
|---|
| 20 |
* |
|---|
| 21 |
***************************************************************************/ |
|---|
| 22 |
|
|---|
| 23 |
if( !empty($setmodules) )</span> |
|---|
| 24 |
<span class="code-keyword">{ |
|---|
| 25 |
$file = basename(__FILE__); |
|---|
| 26 |
$module['styles']['add_new'] = "$file?mode=addnew"; |
|---|
| 27 |
$module['styles']['manage'] = $file; |
|---|
| 28 |
$module['styles']['export'] = "$file?mode=export"; |
|---|
| 29 |
return; |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
define('IN_PHPBB', 1); |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
<span class="code-comment">// Load default header |
|---|
| 36 |
// |
|---|
| 37 |
// |
|---|
| 38 |
// Check if the user has cancled a confirmation message. |
|---|
| 39 |
// |
|---|
| 40 |
$root_path = './../';</span> |
|---|
| 41 |
<span class="code-lang">require($root_path . 'extension.inc'); |
|---|
| 42 |
require('./pagestart.' . $phpEx); |
|---|
| 43 |
|
|---|
| 44 |
$confirm = ( isset($_POST['confirm']) ) ? TRUE : FALSE; |
|---|
| 45 |
$cancel = ( isset($_POST['cancel']) ) ? TRUE : FALSE; |
|---|
| 46 |
|
|---|
| 47 |
$no_page_header = (!empty($_POST['send_file']) || $cancel) ? TRUE : FALSE;</span> |
|---|
| 48 |
<span class="code-lang"> |
|---|
| 49 |
if ($cancel) |
|---|
| 50 |
{ |
|---|
| 51 |
redirect('admin/' . append_sid("admin_styles.$phpEx")); |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
if( isset($_GET['mode']) || isset($_POST['mode']) ) |
|---|
| 55 |
{ |
|---|
| 56 |
$mode = ( isset($_GET['mode']) ) ? $_GET['mode'] : $_POST['mode']; |
|---|
| 57 |
$mode = htmlspecialchars($mode); |
|---|
| 58 |
} |
|---|
| 59 |
else |
|---|
| 60 |
{ |
|---|
| 61 |
$mode = ""; |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
switch( $mode ) |
|---|
| 65 |
{ |
|---|
| 66 |
case "addnew": |
|---|
| 67 |
$install_to = ( isset($_GET['install_to']) ? urldecode($_GET['install_to']) : ( isset($_POST['install_to']) ? urldecode($_POST['install_to']) : '' ) ); |
|---|
| 68 |
$style_name = ( isset($_GET['style']) ? urldecode($_GET['style']) : ( isset($_POST['style']) ? urldecode($_POST['style']) : '' ) ); |
|---|
| 69 |
|
|---|
| 70 |
if( $install_to ) |
|---|
| 71 |
{ |
|---|
| 72 |
|
|---|
| 73 |
@include($root_path. "templates/" . basename($install_to) . "/theme_info.cfg"); |
|---|
| 74 |
|
|---|
| 75 |
$template_name = $$install_to; |
|---|
| 76 |
|
|---|
| 77 |
if ( is_array($template_name) ) { |
|---|
| 78 |
foreach ( $template_name AS $key => $val ) { |
|---|
| 79 |
$db_data[$key] = $val; |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
$sql = "INSERT INTO " . THEMES_TABLE . " " . $db->sql_build_array('INSERT', $db_data); |
|---|
| 83 |
|
|---|
| 84 |
$result = $db->sql_query($sql); |
|---|
| 85 |
|
|---|
| 86 |
$message = $lang['theme_installed'] . "<br /><br />" . sprintf($lang['click_return_styleadmin'], "<a href=\"" . append_sid("admin_styles.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>"); |
|---|
| 87 |
} |
|---|
| 88 |
else { |
|---|
| 89 |
$message = $lang['invalid_data'] . "<br /><br />" . sprintf($lang['click_return_styleadmin'], "<a href=\"" . append_sid("admin_styles.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>"); |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
trigger_error($message); |
|---|
| 93 |
return; |
|---|
| 94 |
} |
|---|
| 95 |
else |
|---|
| 96 |
{ |
|---|
| 97 |
|
|---|
| 98 |
$installable_themes = array(); |
|---|
| 99 |
|
|---|
| 100 |
if( $dir = @opendir($root_path . "templates/") ) |
|---|
| 101 |
{ |
|---|
| 102 |
while( $sub_dir = @readdir($dir) ) |
|---|
| 103 |
{ |
|---|
| 104 |
if( !is_file($root_path . 'templates/' .$sub_dir) && !is_link($root_path . 'templates/' .$sub_dir) && $sub_dir != "." && $sub_dir != ".." && $sub_dir != "CVS" && $sub_dir != "admin" && $sub_dir != "upload_templates" ) |
|---|
| 105 |
{ |
|---|
| 106 |
if( @file_exists($root_path. "templates/" . $sub_dir . "/theme_info.cfg") ) |
|---|
| 107 |
{ |
|---|
| 108 |
@include($root_path. "templates/" . $sub_dir . "/theme_info.cfg"); |
|---|
| 109 |
|
|---|
| 110 |
$working_data = $$sub_dir; |
|---|
| 111 |
|
|---|
| 112 |
$style_name = $working_data['style_name']; |
|---|
| 113 |
|
|---|
| 114 |
$sql = "SELECT themes_id |
|---|
| 115 |
FROM " . THEMES_TABLE . " |
|---|
| 116 |
WHERE style_name = '" . $db->sql_escape($style_name) . "'"; |
|---|
| 117 |
$result = $db->sql_query($sql); |
|---|
| 118 |
|
|---|
| 119 |
if( !$row = $db->sql_fetchrow($result) ) |
|---|
| 120 |
{ |
|---|
| 121 |
$installable_themes[$style_name] = $working_data['template_name']; |
|---|
| 122 |
} |
|---|
| 123 |
} |
|---|
| 124 |
} |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
$template->set_filenames(array( |
|---|
| 128 |
"body" => "../admin/styles_addnew_body.tpl") |
|---|
| 129 |
); |
|---|
| 130 |
|
|---|
| 131 |
$template->assign_vars(array( |
|---|
| 132 |
"L_STYLES_TITLE" => $lang['styles_admin'], |
|---|
| 133 |
"L_STYLES_ADD_TEXT" => $lang['styles_addnew_explain']) |
|---|
| 134 |
); |
|---|
| 135 |
|
|---|
| 136 |
$i = 0; |
|---|
| 137 |
foreach ( $installable_themes AS $style_name => $template_name ) { |
|---|
| 138 |
++$i; |
|---|
| 139 |
$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2']; |
|---|
| 140 |
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2']; |
|---|
| 141 |
|
|---|
| 142 |
$template->assign_block_vars("styles", array( |
|---|
| 143 |
"ROW_CLASS" => $row_class, |
|---|
| 144 |
"ROW_COLOR" => "#" . $row_color, |
|---|
| 145 |
"STYLE_NAME" => $style_name, |
|---|
| 146 |
"TEMPLATE_NAME" => $template_name, |
|---|
| 147 |
|
|---|
| 148 |
"U_STYLES_INSTALL" => append_sid("admin_styles.$phpEx?mode=addnew&style=" . urlencode($style_name) . "&install_to=" . urlencode($template_name))) |
|---|
| 149 |
); |
|---|
| 150 |
|
|---|
| 151 |
} |
|---|
| 152 |
$template->display("body"); |
|---|
| 153 |
|
|---|
| 154 |
} |
|---|
| 155 |
closedir($dir); |
|---|
| 156 |
} |
|---|
| 157 |
break; |
|---|
| 158 |
|
|---|
| 159 |
case "export"; |
|---|
| 160 |
if( isset($_POST['export_template']) ) |
|---|
| 161 |
{ |
|---|
| 162 |
$template_name = $_POST['export_template']; |
|---|
| 163 |
|
|---|
| 164 |
$sql = "SELECT * |
|---|
| 165 |
FROM " . THEMES_TABLE . " |
|---|
| 166 |
WHERE template_name = '" . $db->sql_escape($template_name) . "'"; |
|---|
| 167 |
$result = $db->sql_query($sql); |
|---|
| 168 |
|
|---|
| 169 |
if( $theme_rowset = $db->sql_fetchrow($result) ) { |
|---|
| 170 |
|
|---|
| 171 |
$theme_data = '<?php'."\n\n"; |
|---|
| 172 |
$theme_data .= "//\n// TB Dev SZ Edition auto-generated theme config file for $template_name\n// Do not change anything in this file!\n"; |
|---|
| 173 |
$theme_data .= "// Creatation date: " . date('Y-m-d H:i:s') . "\n//\n\n"; |
|---|
| 174 |
|
|---|
| 175 |
do |
|---|
| 176 |
{ |
|---|
| 177 |
foreach ( $theme_rowset AS $key => $val ) { |
|---|
| 178 |
if(!intval($key) && $key != "0" && $key != "themes_id") { |
|---|
| 179 |
$theme_data .= '$' . $template_name . "['$key'] = \"" . addslashes($val) . "\";\n"; |
|---|
| 180 |
} |
|---|
| 181 |
} |
|---|
| 182 |
$theme_data .= "\n"; |
|---|
| 183 |
} |
|---|
| 184 |
while ( $theme_rowset = $db->sql_fetchrow($result) ) ; |
|---|
| 185 |
|
|---|
| 186 |
$theme_data .= '?' . '>'; |
|---|
| 187 |
|
|---|
| 188 |
@umask(0111); |
|---|
| 189 |
|
|---|
| 190 |
$fp = @fopen($root_path . 'templates/' . basename($template_name) . '/theme_info.cfg', 'w'); |
|---|
| 191 |
} |
|---|
| 192 |
else { |
|---|
| 193 |
trigger_error($lang['no_themes']); |
|---|
| 194 |
return; |
|---|
| 195 |
} |
|---|
| 196 |
|
|---|
| 197 |
if( !$fp ) |
|---|
| 198 |
{ |
|---|
| 199 |
|
|---|
| 200 |
// Unable to open the file writeable do something here as an attempt |
|---|
| 201 |
// to get around that... |
|---|
| 202 |
// |
|---|
| 203 |
$s_hidden_fields = '<input type="hidden" name="theme_info" value="' . htmlspecialchars($theme_data) . '" />'; |
|---|
| 204 |
$s_hidden_fields .= '<input type="hidden" name="send_file" value="1" /><input type="hidden" name="mode" value="export" />'; |
|---|
| 205 |
|
|---|
| 206 |
$download_form = '<form action="' . append_sid("admin_styles.$phpEx") . '" method="post"><input class="mainoption" type="submit" name="submit" value="' . $lang['download'] . '" />' . $s_hidden_fields; |
|---|
| 207 |
|
|---|
| 208 |
$template->set_filenames(array( |
|---|
| 209 |
"body" => "../admin/message_body.tpl") |
|---|
| 210 |
); |
|---|
| 211 |
|
|---|
| 212 |
$template->assign_vars(array( |
|---|
| 213 |
"MESSAGE_TITLE" => $lang['export_themes'], |
|---|
| 214 |
"MESSAGE_TEXT" => $lang['download_theme_cfg'] . "<br /><br />" . $download_form) |
|---|
| 215 |
); |
|---|
| 216 |
|
|---|
| 217 |
$template->display('body'); |
|---|
| 218 |
gc(); |
|---|
| 219 |
} |
|---|
| 220 |
|
|---|
| 221 |
$result = @fputs($fp, $theme_data, strlen($theme_data)); |
|---|
| 222 |
fclose($fp); |
|---|
| 223 |
|
|---|
| 224 |
$message = $lang['theme_info_saved'] . "<br /><br />" . sprintf($lang['click_return_styleadmin'], "<a href=\"" . append_sid("admin_styles.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>"); |
|---|
| 225 |
|
|---|
| 226 |
trigger_error($message); |
|---|
| 227 |
return; |
|---|
| 228 |
|
|---|
| 229 |
} |
|---|
| 230 |
else if( isset($_POST['send_file']) ) |
|---|
| 231 |
{ |
|---|
| 232 |
$theme_info = ( isset($_POST['theme_info']) ? trim(stripslashes($_POST['theme_info'])) : '' ); |
|---|
| 233 |
|
|---|
| 234 |
header("Content-Type: text/x-delimtext; name=\"theme_info.cfg\""); |
|---|
| 235 |
header("Content-disposition: attachment; filename=theme_info.cfg"); |
|---|
| 236 |
|
|---|
| 237 |
gc($theme_info); |
|---|
| 238 |
} |
|---|
| 239 |
else |
|---|
| 240 |
{ |
|---|
| 241 |
$template->set_filenames(array( |
|---|
| 242 |
"body" => "../admin/styles_exporter.tpl") |
|---|
| 243 |
); |
|---|
| 244 |
|
|---|
| 245 |
if( $dir = @opendir($root_path . 'templates/') ) |
|---|
| 246 |
{ |
|---|
| 247 |
$s_template_select = '<select name="export_template">'; |
|---|
| 248 |
while( $file = @readdir($dir) ) |
|---|
| 249 |
{ |
|---|
| 250 |
if( !is_file($root_path . 'templates/' . $file) && !is_link($root_path . 'templates/' .$file) && $file != "." && $file != ".." && $file != "CVS" && $file != "admin" && $file != "upload_templates" ) |
|---|
| 251 |
{ |
|---|
| 252 |
$s_template_select .= '<option value="' . $file . '">' . $file . "</option>\n"; |
|---|
| 253 |
} |
|---|
| 254 |
} |
|---|
| 255 |
$s_template_select .= '</select>'; |
|---|
| 256 |
} |
|---|
| 257 |
else |
|---|
| 258 |
{ |
|---|
| 259 |
trigger_error($lang['no_template_dir']); |
|---|
| 260 |
return; |
|---|
| 261 |
} |
|---|
| 262 |
|
|---|
| 263 |
$template->assign_vars(array( |
|---|
| 264 |
"S_EXPORTER_ACTION" => append_sid("admin_styles.$phpEx?mode=export"), |
|---|
| 265 |
"S_TEMPLATE_SELECT" => $s_template_select) |
|---|
| 266 |
); |
|---|
| 267 |
|
|---|
| 268 |
$template->display("body"); |
|---|
| 269 |
|
|---|
| 270 |
} |
|---|
| 271 |
break; |
|---|
| 272 |
|
|---|
| 273 |
case "delete": |
|---|
| 274 |
$style_id = ( isset($_GET['style_id']) ) ? intval($_GET['style_id']) : intval($_POST['style_id']); |
|---|
| 275 |
|
|---|
| 276 |
if( !$confirm ) |
|---|
| 277 |
{ |
|---|
| 278 |
if($style_id == $config['default_style']) |
|---|
| 279 |
{ |
|---|
| 280 |
trigger_error($lang['cannot_remove_style']); |
|---|
| 281 |
return; |
|---|
| 282 |
} |
|---|
| 283 |
|
|---|
| 284 |
$hidden_fields = '<input type="hidden" name="mode" value="'.$mode.'" /><input type="hidden" name="style_id" value="'.$style_id.'" />'; |
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
// Set template files |
|---|
| 288 |
// |
|---|
| 289 |
$template->set_filenames(array( |
|---|
| 290 |
"confirm" => "../admin/confirm_body.tpl") |
|---|
| 291 |
); |
|---|
| 292 |
|
|---|
| 293 |
$template->assign_vars(array( |
|---|
| 294 |
"MESSAGE_TITLE" => $lang['confirm'], |
|---|
| 295 |
"MESSAGE_TEXT" => $lang['confirm_delete_style'], |
|---|
| 296 |
|
|---|
| 297 |
"S_CONFIRM_ACTION" => append_sid("admin_styles.$phpEx"), |
|---|
| 298 |
"S_HIDDEN_FIELDS" => $hidden_fields) |
|---|
| 299 |
); |
|---|
| 300 |
|
|---|
| 301 |
$template->display("confirm"); |
|---|
| 302 |
|
|---|
| 303 |
} |
|---|
| 304 |
else |
|---|
| 305 |
{ |
|---|
| 306 |
|
|---|
| 307 |
// The user has confirmed the delete. Remove the style, the style element |
|---|
| 308 |
// names and update any users who might be using this style |
|---|
| 309 |
// |
|---|
| 310 |
$sql = "DELETE FROM " . THEMES_TABLE . " |
|---|
| 311 |
WHERE themes_id = $style_id"; |
|---|
| 312 |
$db->sql_query($sql); |
|---|
| 313 |
|
|---|
| 314 |
$sql = "UPDATE " . USERS_TABLE . " |
|---|
| 315 |
SET user_style = " . $config['default_style'] . " |
|---|
| 316 |
WHERE user_style = $style_id"; |
|---|
| 317 |
$db->sql_query($sql); |
|---|
| 318 |
|
|---|
| 319 |
$message = $lang['style_removed'] . "<br /><br />" . sprintf($lang['click_return_styleadmin'], "<a href=\"" . append_sid("admin_styles.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>"); |
|---|
| 320 |
|
|---|
| 321 |
trigger_error($message); |
|---|
| 322 |
return; |
|---|
| 323 |
} |
|---|
| 324 |
break; |
|---|
| 325 |
|
|---|
| 326 |
default: |
|---|
| 327 |
|
|---|
| 328 |
$sql = "SELECT themes_id, template_name, style_name |
|---|
| 329 |
FROM " . THEMES_TABLE . " |
|---|
| 330 |
ORDER BY template_name"; |
|---|
| 331 |
$result = $db->sql_query($sql); |
|---|
| 332 |
|
|---|
| 333 |
$template->set_filenames(array( |
|---|
| 334 |
"body" => "../admin/styles_list_body.tpl") |
|---|
| 335 |
); |
|---|
| 336 |
|
|---|
| 337 |
$i = 0; |
|---|
| 338 |
while ( $row = $db->sql_fetchrow($result) ) |
|---|
| 339 |
{ |
|---|
| 340 |
++$i; |
|---|
| 341 |
$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2']; |
|---|
| 342 |
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2']; |
|---|
| 343 |
|
|---|
| 344 |
$template->assign_block_vars("styles", array( |
|---|
| 345 |
"ROW_CLASS" => $row_class, |
|---|
| 346 |
"ROW_COLOR" => $row_color, |
|---|
| 347 |
"STYLE_NAME" => $row['style_name'], |
|---|
| 348 |
"TEMPLATE_NAME" => $row['template_name'], |
|---|
| 349 |
|
|---|
| 350 |
"U_STYLES_EDIT" => append_sid("admin_styles.$phpEx?mode=edit&style_id=" . $row['themes_id']), |
|---|
| 351 |
"U_STYLES_DELETE" => append_sid("admin_styles.$phpEx?mode=delete&style_id=" . $row['themes_id'])) |
|---|
| 352 |
); |
|---|
| 353 |
} |
|---|
| 354 |
|
|---|
| 355 |
$template->display("body"); |
|---|
| 356 |
break; |
|---|
| 357 |
} |
|---|
| 358 |
|
|---|
| 359 |
if (empty($_POST['send_file'])) |
|---|
| 360 |
{ |
|---|
| 361 |
include('./page_footer_admin.'.$phpEx); |
|---|
| 362 |
} |
|---|
| 363 |
|
|---|
| 364 |
?> |
|---|