| [ Index ] |
PHP Cross Reference of MyBB 1.6.7 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id: themes.php 5390 2011-03-17 15:23:41Z Tomm $ 10 */ 11 12 // Disallow direct access to this file for security reasons 13 if(!defined("IN_MYBB")) 14 { 15 die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined."); 16 } 17 18 require_once MYBB_ADMIN_DIR."inc/functions_themes.php"; 19 20 $page->extra_header .= " 21 <script type=\"text/javascript\"> 22 //<![CDATA[ 23 var save_changes_lang_string = '{$lang->save_changes_js}'; 24 var delete_lang_string = '{$lang->delete}'; 25 var file_lang_string = '{$lang->file}'; 26 var globally_lang_string = '{$lang->globally}'; 27 var specific_actions_lang_string = '{$lang->specific_actions}'; 28 var specific_actions_desc_lang_string = '{$lang->specific_actions_desc}'; 29 var delete_confirm_lang_string = '{$lang->delete_confirm_js}'; 30 //]]> 31 </script>"; 32 33 if($mybb->input['action'] == "xmlhttp_stylesheet" && $mybb->request_method == "post") 34 { 35 // Fetch the theme we want to edit this stylesheet in 36 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 37 $theme = $db->fetch_array($query); 38 39 if(!$theme['tid']) 40 { 41 flash_message($lang->error_invalid_theme, 'error'); 42 admin_redirect("index.php?module=style-themes"); 43 } 44 45 $parent_list = make_parent_theme_list($theme['tid']); 46 $parent_list = implode(',', $parent_list); 47 if(!$parent_list) 48 { 49 $parent_list = 1; 50 } 51 52 $query = $db->simple_select("themestylesheets", "*", "name='".$db->escape_string($mybb->input['file'])."' AND tid IN ({$parent_list})", array('order_by' => 'tid', 'order_dir' => 'desc', 'limit' => 1)); 53 $stylesheet = $db->fetch_array($query); 54 55 // Does the theme not exist? 56 if(!$stylesheet['sid']) 57 { 58 flash_message($lang->error_invalid_stylesheet, 'error'); 59 admin_redirect("index.php?module=style-themes"); 60 } 61 62 $css_array = css_to_array($stylesheet['stylesheet']); 63 $selector_list = get_selectors_as_options($css_array, $mybb->input['selector']); 64 $editable_selector = $css_array[$mybb->input['selector']]; 65 $properties = parse_css_properties($editable_selector['values']); 66 67 $form = new Form("index.php?module=style-themes&action=stylesheet_properties", "post", "selector_form", 0, "", true); 68 echo $form->generate_hidden_field("tid", $mybb->input['tid'], array('id' => "tid"))."\n"; 69 echo $form->generate_hidden_field("file", htmlspecialchars_uni($mybb->input['file']), array('id' => "file"))."\n"; 70 echo $form->generate_hidden_field("selector", htmlspecialchars_uni($mybb->input['selector']), array('id' => 'hidden_selector'))."\n"; 71 72 $table = new Table; 73 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[background]', $properties['background'], array('id' => 'css_bits[background]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->background}</strong></div>", array('style' => 'width: 20%;')); 74 $table->construct_cell("<strong>{$lang->extra_css_atribs}</strong><br /><div style=\"align: center;\">".$form->generate_text_area('css_bits[extra]', $properties['extra'], array('id' => 'css_bits[extra]', 'style' => 'width: 98%;', 'rows' => '19'))."</div>", array('rowspan' => 8)); 75 $table->construct_row(); 76 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[color]', $properties['color'], array('id' => 'css_bits[color]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->color}</strong></div>", array('style' => 'width: 40%;')); 77 $table->construct_row(); 78 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[width]', $properties['width'], array('id' => 'css_bits[width]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->width}</strong></div>", array('style' => 'width: 40%;')); 79 $table->construct_row(); 80 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[font_family]', $properties['font-family'], array('id' => 'css_bits[font_family]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->font_family}</strong></div>", array('style' => 'width: 40%;')); 81 $table->construct_row(); 82 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[font_size]', $properties['font-size'], array('id' => 'css_bits[font_size]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->font_size}</strong></div>", array('style' => 'width: 40%;')); 83 $table->construct_row(); 84 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[font_style]', $properties['font-style'], array('id' => 'css_bits[font_style]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->font_style}</strong></div>", array('style' => 'width: 40%;')); 85 $table->construct_row(); 86 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[font_weight]', $properties['font-weight'], array('id' => 'css_bits[font_weight]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->font_weight}</strong></div>", array('style' => 'width: 40%;')); 87 $table->construct_row(); 88 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[text_decoration]', $properties['text-decoration'], array('id' => 'css_bits[text_decoration]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->text_decoration}</strong></div>", array('style' => 'width: 40%;')); 89 $table->construct_row(); 90 91 $table->output(htmlspecialchars_uni($editable_selector['class_name'])."<span id=\"saved\" style=\"color: #FEE0C6;\"></span>"); 92 exit; 93 } 94 95 $page->add_breadcrumb_item($lang->themes, "index.php?module=style-themes"); 96 97 if($mybb->input['action'] == "add" || $mybb->input['action'] == "import" || $mybb->input['action'] == "browse" || !$mybb->input['action']) 98 { 99 $sub_tabs['themes'] = array( 100 'title' => $lang->themes, 101 'link' => "index.php?module=style-themes", 102 'description' => $lang->themes_desc 103 ); 104 105 $sub_tabs['create_theme'] = array( 106 'title' => $lang->create_new_theme, 107 'link' => "index.php?module=style-themes&action=add", 108 'description' => $lang->create_new_theme_desc 109 ); 110 111 $sub_tabs['import_theme'] = array( 112 'title' => $lang->import_a_theme, 113 'link' => "index.php?module=style-themes&action=import", 114 'description' => $lang->import_a_theme_desc 115 ); 116 117 $sub_tabs['browse_themes'] = array( 118 'title' => $lang->browse_themes, 119 'link' => "index.php?module=style-themes&action=browse", 120 'description' => $lang->browse_themes_desc 121 ); 122 } 123 124 $plugins->run_hooks("admin_style_themes_begin"); 125 126 if($mybb->input['action'] == "browse") 127 { 128 $plugins->run_hooks("admin_style_themes_browse"); 129 130 $page->add_breadcrumb_item($lang->browse_themes); 131 132 $page->output_header($lang->browse_themes); 133 134 $page->output_nav_tabs($sub_tabs, 'browse_themes'); 135 136 // Process search requests 137 require_once MYBB_ROOT."inc/class_xml.php"; 138 139 $keywords = ""; 140 if($mybb->input['keywords']) 141 { 142 $keywords = "&keywords=".urlencode($mybb->input['keywords']); 143 } 144 145 if($mybb->input['page']) 146 { 147 $url_page = "&page=".intval($mybb->input['page']); 148 } 149 else 150 { 151 $mybb->input['page'] = 1; 152 $url_page = ""; 153 } 154 155 // Gets the major version code. i.e. 1410 -> 1400 or 121 -> 1200 156 if($mybb->version_code >= 1000) 157 { 158 $major_version_code = round($mybb->version_code/100, 0)*100; 159 } 160 else 161 { 162 $major_version_code = round($mybb->version_code/10, 0)*100; 163 } 164 165 $contents = fetch_remote_file("http://mods.mybb.com/xmlbrowse.php?type=theme&version={$major_version_code}{$keywords}{$url_page}", $post_data); 166 167 if(!$contents) 168 { 169 $page->output_inline_error($lang->error_communication_problem); 170 $page->output_footer(); 171 exit; 172 } 173 174 $table = new Table; 175 $table->construct_header($lang->themes, array('colspan' => 2)); 176 $table->construct_header($lang->controls, array("class" => "align_center", 'width' => 125)); 177 178 $parser = new XMLParser($contents); 179 $tree = $parser->get_tree(); 180 181 if(!array_key_exists("results", $tree)) 182 { 183 $page->output_inline_error($lang->error_communication_problem); 184 $page->output_footer(); 185 exit; 186 } 187 188 if(!empty($tree['results']['result'])) 189 { 190 if(array_key_exists("tag", $tree['results']['result'])) 191 { 192 $only_theme = $tree['results']['result']; 193 unset($tree['results']['result']); 194 $tree['results']['result'][0] = $only_theme; 195 } 196 197 foreach($tree['results']['result'] as $result) 198 { 199 $table->construct_cell("<img src=\"http://mods.mybb.com/{$result['thumbnail']['value']}\" alt=\"{$lang->theme_thumbnail}\" title=\"{$lang->theme_thumbnail}\"/>", array("class" => "align_center", "width" => 100)); 200 $table->construct_cell("<strong>{$result['name']['value']}</strong><br /><small>{$result['description']['value']}</small><br /><i><small>{$lang->created_by} {$result['author']['value']}</small></i>"); 201 $table->construct_cell("<strong><a href=\"http://mods.mybb.com/view/{$result['download_url']['value']}\" target=\"_blank\">{$lang->download}</a></strong>", array("class" => "align_center")); 202 $table->construct_row(); 203 } 204 } 205 206 if($table->num_rows() == 0) 207 { 208 $table->construct_cell($lang->error_no_results_found, array("colspan" => 3)); 209 $table->construct_row(); 210 } 211 212 $search = new Form("index.php?module=style-themes&action=browse", 'post', 'search_form'); 213 echo "<div style=\"padding-bottom: 3px; margin-top: -9px; text-align: right;\">"; 214 if($mybb->input['keywords']) 215 { 216 $default_class = ''; 217 $value = htmlspecialchars_uni($mybb->input['keywords']); 218 } 219 else 220 { 221 $default_class = "search_default"; 222 $value = $lang->search_for_themes; 223 } 224 echo $search->generate_text_box('keywords', $value, array('id' => 'search_keywords', 'class' => "{$default_class} field150 field_small"))."\n"; 225 echo "<input type=\"submit\" class=\"search_button\" value=\"{$lang->search}\" />\n"; 226 echo "<script type='text/javascript'> 227 var form = document.getElementById('search_form'); 228 form.onsubmit = function() { 229 var search = document.getElementById('search_keywords'); 230 if(search.value == '' || search.value == '{$lang->search_for_themes}') 231 { 232 search.focus(); 233 return false; 234 } 235 } 236 237 var search = document.getElementById('search_keywords'); 238 search.onfocus = function() 239 { 240 if(this.value == '{$lang->search_for_themes}') 241 { 242 $(this).removeClassName('search_default'); 243 this.value = ''; 244 } 245 } 246 search.onblur = function() 247 { 248 if(this.value == '') 249 { 250 $(this).addClassName('search_default'); 251 this.value = '{$lang->search_for_themes}'; 252 } 253 } 254 // fix the styling used if we have a different default value 255 if(search.value != '{$lang->search_for_themes}') 256 { 257 $(search).removeClassName('search_default'); 258 } 259 </script>\n"; 260 echo "</div>\n"; 261 echo $search->end(); 262 263 // Recommended themes = Default; Otherwise search results & pagination 264 if($mybb->request_method == "post") 265 { 266 $table->output("<span style=\"float: right;\"><small><a href=\"http://mods.mybb.com/themes\" target=\"_blank\">{$lang->browse_all_themes}</a></small></span>".$lang->sprintf($lang->browse_results_for_mybb, $mybb->version)); 267 } 268 else 269 { 270 $table->output("<span style=\"float: right;\"><small><a href=\"http://mods.mybb.com/themes\" target=\"_blank\">{$lang->browse_all_themes}</a></small></span>".$lang->sprintf($lang->recommended_themes_for_mybb, $mybb->version)); 271 } 272 273 echo "<br />".draw_admin_pagination($mybb->input['page'], 15, $tree['results']['attributes']['total'], "index.php?module=style-themes&action=browse{$keywords}&page={page}"); 274 275 $page->output_footer(); 276 } 277 278 if($mybb->input['action'] == "import") 279 { 280 $plugins->run_hooks("admin_style_themes_import"); 281 282 if($mybb->request_method == "post") 283 { 284 if(!$_FILES['local_file'] && !$mybb->input['url']) 285 { 286 $errors[] = $lang->error_missing_url; 287 } 288 289 if(!$errors) 290 { 291 // Find out if there was an uploaded file 292 if($_FILES['local_file']['error'] != 4) 293 { 294 // Find out if there was an error with the uploaded file 295 if($_FILES['local_file']['error'] != 0) 296 { 297 $errors[] = $lang->error_uploadfailed.$lang->error_uploadfailed_detail; 298 switch($_FILES['local_file']['error']) 299 { 300 case 1: // UPLOAD_ERR_INI_SIZE 301 $errors[] = $lang->error_uploadfailed_php1; 302 break; 303 case 2: // UPLOAD_ERR_FORM_SIZE 304 $errors[] = $lang->error_uploadfailed_php2; 305 break; 306 case 3: // UPLOAD_ERR_PARTIAL 307 $errors[] = $lang->error_uploadfailed_php3; 308 break; 309 case 6: // UPLOAD_ERR_NO_TMP_DIR 310 $errors[] = $lang->error_uploadfailed_php6; 311 break; 312 case 7: // UPLOAD_ERR_CANT_WRITE 313 $errors[] = $lang->error_uploadfailed_php7; 314 break; 315 default: 316 $errors[] = $lang->sprintf($lang->error_uploadfailed_phpx, $_FILES['local_file']['error']); 317 break; 318 } 319 } 320 321 if(!$errors) 322 { 323 // Was the temporary file found? 324 if(!is_uploaded_file($_FILES['local_file']['tmp_name'])) 325 { 326 $errors[] = $lang->error_uploadfailed_lost; 327 } 328 // Get the contents 329 $contents = @file_get_contents($_FILES['local_file']['tmp_name']); 330 // Delete the temporary file if possible 331 @unlink($_FILES['local_file']['tmp_name']); 332 // Are there contents? 333 if(!trim($contents)) 334 { 335 $errors[] = $lang->error_uploadfailed_nocontents; 336 } 337 } 338 } 339 else if(!empty($mybb->input['url'])) 340 { 341 // Get the contents 342 $contents = @fetch_remote_file($mybb->input['url']); 343 if(!$contents) 344 { 345 $errors[] = $lang->error_local_file; 346 } 347 } 348 else 349 { 350 // UPLOAD_ERR_NO_FILE 351 $errors[] = $lang->error_uploadfailed_php4; 352 } 353 354 if(!$errors) 355 { 356 $options = array( 357 'no_stylesheets' => ($mybb->input['import_stylesheets'] ? 0 : 1), 358 'no_templates' => ($mybb->input['import_templates'] ? 0 : 1), 359 'version_compat' => intval($mybb->input['version_compat']), 360 'parent' => intval($mybb->input['tid']), 361 'force_name_check' => true, 362 ); 363 $theme_id = import_theme_xml($contents, $options); 364 365 if($theme_id > -1) 366 { 367 $plugins->run_hooks("admin_style_themes_import_commit"); 368 369 // Log admin action 370 log_admin_action($theme_id); 371 372 flash_message($lang->success_imported_theme, 'success'); 373 admin_redirect("index.php?module=style-themes&action=edit&tid=".$theme_id); 374 } 375 else 376 { 377 switch($theme_id) 378 { 379 case -1: 380 $errors[] = $lang->error_uploadfailed_nocontents; 381 break; 382 case -2: 383 $errors[] = $lang->error_invalid_version; 384 break; 385 case -3: 386 $errors[] = $lang->error_theme_already_exists; 387 break; 388 case -4: 389 $errors[] = $lang->error_theme_security_problem; 390 } 391 } 392 } 393 } 394 } 395 396 $query = $db->simple_select("themes", "tid, name"); 397 while($theme = $db->fetch_array($query)) 398 { 399 $themes[$theme['tid']] = $theme['name']; 400 } 401 402 $page->add_breadcrumb_item($lang->import_a_theme, "index.php?module=style-themes&action=import"); 403 404 $page->output_header("{$lang->themes} - {$lang->import_a_theme}"); 405 406 $page->output_nav_tabs($sub_tabs, 'import_theme'); 407 408 if($errors) 409 { 410 $page->output_inline_error($errors); 411 412 if($mybb->input['import'] == 1) 413 { 414 $import_checked[1] = ""; 415 $import_checked[2] = "checked=\"checked\""; 416 } 417 else 418 { 419 $import_checked[1] = "checked=\"checked\""; 420 $import_checked[2] = ""; 421 } 422 } 423 else 424 { 425 $import_checked[1] = "checked=\"checked\""; 426 $import_checked[2] = ""; 427 428 $mybb->input['import_stylesheets'] = true; 429 $mybb->input['import_templates'] = true; 430 } 431 432 $form = new Form("index.php?module=style-themes&action=import", "post", "", 1); 433 434 $actions = '<script type="text/javascript"> 435 function checkAction(id) 436 { 437 var checked = \'\'; 438 439 $$(\'.\'+id+\'s_check\').each(function(e) 440 { 441 if(e.checked == true) 442 { 443 checked = e.value; 444 } 445 }); 446 $$(\'.\'+id+\'s\').each(function(e) 447 { 448 Element.hide(e); 449 }); 450 if($(id+\'_\'+checked)) 451 { 452 Element.show(id+\'_\'+checked); 453 } 454 } 455 </script> 456 <dl style="margin-top: 0; margin-bottom: 0; width: 35%;"> 457 <dt><label style="display: block;"><input type="radio" name="import" value="0" '.$import_checked[1].' class="imports_check" onclick="checkAction(\'import\');" style="vertical-align: middle;" /> '.$lang->local_file.'</label></dt> 458 <dd style="margin-top: 0; margin-bottom: 0; width: 100%;" id="import_0" class="imports"> 459 <table cellpadding="4"> 460 <tr> 461 <td>'.$form->generate_file_upload_box("local_file", array('style' => 'width: 230px;')).'</td> 462 </tr> 463 </table> 464 </dd> 465 <dt><label style="display: block;"><input type="radio" name="import" value="1" '.$import_checked[2].' class="imports_check" onclick="checkAction(\'import\');" style="vertical-align: middle;" /> '.$lang->url.'</label></dt> 466 <dd style="margin-top: 0; margin-bottom: 0; width: 100%;" id="import_1" class="imports"> 467 <table cellpadding="4"> 468 <tr> 469 <td>'.$form->generate_text_box("url", $mybb->input['file']).'</td> 470 </tr> 471 </table></dd> 472 </dl> 473 <script type="text/javascript"> 474 checkAction(\'import\'); 475 </script>'; 476 477 $form_container = new FormContainer($lang->import_a_theme); 478 $form_container->output_row($lang->import_from, $lang->import_from_desc, $actions, 'file'); 479 $form_container->output_row($lang->parent_theme, $lang->parent_theme_desc, $form->generate_select_box('tid', $themes, $mybb->input['tid'], array('id' => 'tid')), 'tid'); 480 $form_container->output_row($lang->new_name, $lang->new_name_desc, $form->generate_text_box('name', $mybb->input['name'], array('id' => 'name')), 'name'); 481 $form_container->output_row($lang->advanced_options, "", $form->generate_check_box('version_compat', '1', $lang->ignore_version_compatibility, array('checked' => $mybb->input['version_compat'], 'id' => 'version_compat'))."<br /><small>{$lang->ignore_version_compat_desc}</small><br />".$form->generate_check_box('import_stylesheets', '1', $lang->import_stylesheets, array('checked' => $mybb->input['import_stylesheets'], 'id' => 'import_stylesheets'))."<br /><small>{$lang->import_stylesheets_desc}</small><br />".$form->generate_check_box('import_templates', '1', $lang->import_templates, array('checked' => $mybb->input['import_templates'], 'id' => 'import_templates'))."<br /><small>{$lang->import_templates_desc}</small>"); 482 483 $form_container->end(); 484 485 $buttons[] = $form->generate_submit_button($lang->import_theme); 486 487 $form->output_submit_wrapper($buttons); 488 489 $form->end(); 490 491 $page->output_footer(); 492 } 493 494 if($mybb->input['action'] == "export") 495 { 496 $plugins->run_hooks("admin_style_themes_export"); 497 498 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 499 $theme = $db->fetch_array($query); 500 501 // Does the theme not exist? 502 if(!$theme['tid']) 503 { 504 flash_message($lang->error_invalid_theme, 'error'); 505 admin_redirect("index.php?module=style-themes"); 506 } 507 508 if($mybb->request_method == "post") 509 { 510 $properties = unserialize($theme['properties']); 511 512 $xml = "<?xml version=\"1.0\" encoding=\"{$lang->settings['charset']}\"?".">\r\n"; 513 $xml .= "<theme name=\"".htmlspecialchars_uni($theme['name'])."\" version=\"".$mybb->version_code."\">\r\n"; 514 $xml .= "\t<properties>\r\n"; 515 foreach($properties as $property => $value) 516 { 517 if($property == "inherited") continue; 518 519 $xml .= "\t\t<{$property}><![CDATA[{$value}]]></{$property}>\r\n"; 520 } 521 $xml .= "\t</properties>\r\n"; 522 523 // Fetch list of all of the stylesheets for this theme 524 $file_stylesheets = unserialize($theme['stylesheets']); 525 526 $stylesheets = array(); 527 $inherited_load = array(); 528 529 // Now we loop through the list of stylesheets for each file 530 foreach($file_stylesheets as $file => $action_stylesheet) 531 { 532 if($file == 'inherited') 533 { 534 continue; 535 } 536 537 foreach($action_stylesheet as $action => $style) 538 { 539 foreach($style as $stylesheet) 540 { 541 $stylesheets[$stylesheet]['applied_to'][$file][] = $action; 542 if(is_array($file_stylesheets['inherited'][$file."_".$action]) && in_array($stylesheet, array_keys($file_stylesheets['inherited'][$file."_".$action]))) 543 { 544 $stylesheets[$stylesheet]['inherited'] = $file_stylesheets['inherited'][$file."_".$action]; 545 foreach($file_stylesheets['inherited'][$file."_".$action] as $value) 546 { 547 $inherited_load[] = $value; 548 } 549 } 550 } 551 } 552 } 553 554 $inherited_load[] = $mybb->input['tid']; 555 $inherited_load = array_unique($inherited_load); 556 557 $inherited_themes = array(); 558 if(count($inherited_load) > 0) 559 { 560 $query = $db->simple_select("themes", "tid, name", "tid IN (".implode(",", $inherited_load).")"); 561 while($inherited_theme = $db->fetch_array($query)) 562 { 563 $inherited_themes[$inherited_theme['tid']] = $inherited_theme['name']; 564 } 565 } 566 567 $theme_stylesheets = array(); 568 569 if(count($inherited_load) > 0) 570 { 571 $query = $db->simple_select("themestylesheets", "*", "tid IN (".implode(",", $inherited_load).")", array('order_by' => 'tid', 'order_dir' => 'desc')); 572 while($theme_stylesheet = $db->fetch_array($query)) 573 { 574 if(!$theme_stylesheets[$theme_stylesheet['cachefile']]) 575 { 576 $theme_stylesheets[$theme_stylesheet['cachefile']] = $theme_stylesheet; 577 $theme_stylesheets[$theme_stylesheet['sid']] = $theme_stylesheet['cachefile']; 578 } 579 } 580 } 581 582 $xml .= "\t<stylesheets>\r\n"; 583 foreach($stylesheets as $filename => $style) 584 { 585 if(strpos($filename, 'css.php?stylesheet=') !== false) 586 { 587 $style['sid'] = (integer)str_replace('css.php?stylesheet=', '', $filename); 588 $filename = $theme_stylesheets[$style['sid']]; 589 } 590 else 591 { 592 $filename = basename($filename); 593 $style['sid'] = $theme_stylesheets[$filename]['sid']; 594 } 595 596 $style['tid'] = $theme_stylesheets[$filename]['tid']; 597 598 if($mybb->input['custom_theme'] == 1 && $style['tid'] != $mybb->input['tid']) 599 { 600 continue; 601 } 602 603 // Has the file on the file system been modified? 604 resync_stylesheet($theme_stylesheets[$filename]); 605 606 $style['sid'] = $theme_stylesheets[$filename]['sid']; 607 608 $attachedto = $theme_stylesheets[$filename]['attachedto']; 609 $stylesheet = $theme_stylesheets[$filename]['stylesheet']; 610 611 if($attachedto) 612 { 613 $attachedto = "attachedto=\"{$attachedto}\" "; 614 } 615 616 $filename = $theme_stylesheets[$filename]['name']; 617 618 $xml .= "\t\t<stylesheet name=\"{$filename}\" {$attachedto}version=\"{$mybb->version_code}\"><![CDATA[{$stylesheet}]]>\r\n\t\t</stylesheet>\r\n"; 619 620 } 621 $xml .= "\t</stylesheets>\r\n"; 622 623 if($mybb->input['include_templates'] != 0) 624 { 625 $xml .= "\t<templates>\r\n"; 626 $query = $db->simple_select("templates", "*", "sid='".$properties['templateset']."'"); 627 while($template = $db->fetch_array($query)) 628 { 629 $xml .= "\t\t<template name=\"{$template['title']}\" version=\"{$template['version']}\"><![CDATA[{$template['template']}]]></template>\r\n"; 630 } 631 $xml .= "\t</templates>\r\n"; 632 } 633 $xml .= "</theme>"; 634 635 $plugins->run_hooks("admin_style_themes_export_commit"); 636 637 // Log admin action 638 log_admin_action($theme['tid'], $theme['name']); 639 640 $theme['name'] = rawurlencode($theme['name']); 641 header("Content-disposition: attachment; filename=".$theme['name']."-theme.xml"); 642 header("Content-type: application/octet-stream"); 643 header("Content-Length: ".strlen($xml)); 644 header("Pragma: no-cache"); 645 header("Expires: 0"); 646 echo $xml; 647 exit; 648 } 649 650 $page->add_breadcrumb_item(htmlspecialchars_uni($theme['name']), "index.php?module=style-themes&action=edit&tid={$mybb->input['tid']}"); 651 652 $page->add_breadcrumb_item($lang->export_theme, "index.php?module=style-themes&action=export"); 653 654 $page->output_header("{$lang->themes} - {$lang->export_theme}"); 655 656 $sub_tabs['edit_stylesheets'] = array( 657 'title' => $lang->edit_stylesheets, 658 'link' => "index.php?module=style-themes&action=edit&tid={$mybb->input['tid']}", 659 ); 660 661 $sub_tabs['add_stylesheet'] = array( 662 'title' => $lang->add_stylesheet, 663 'link' => "index.php?module=style-themes&action=add_stylesheet&tid={$mybb->input['tid']}", 664 ); 665 666 $sub_tabs['export_theme'] = array( 667 'title' => $lang->export_theme, 668 'link' => "index.php?module=style-themes&action=export&tid={$mybb->input['tid']}", 669 'description' => $lang->export_theme_desc 670 ); 671 672 $page->output_nav_tabs($sub_tabs, 'export_theme'); 673 674 if($errors) 675 { 676 $page->output_inline_error($errors); 677 } 678 679 $form = new Form("index.php?module=style-themes&action=export", "post"); 680 echo $form->generate_hidden_field("tid", $theme['tid']); 681 682 $form_container = new FormContainer($lang->export_theme.": ".htmlspecialchars_uni($theme['name'])); 683 $form_container->output_row($lang->include_custom_only, $lang->include_custom_only_desc, $form->generate_yes_no_radio('custom_theme', $mybb->input['custom_theme']), 'custom_theme'); 684 $form_container->output_row($lang->include_templates, $lang->include_templates_desc, $form->generate_yes_no_radio('include_templates', $mybb->input['include_templates']), 'include_templates'); 685 686 $form_container->end(); 687 688 $buttons[] = $form->generate_submit_button($lang->export_theme); 689 690 $form->output_submit_wrapper($buttons); 691 692 $form->end(); 693 694 $page->output_footer(); 695 } 696 697 if($mybb->input['action'] == "add") 698 { 699 $plugins->run_hooks("admin_style_themes_add"); 700 701 if($mybb->request_method == "post") 702 { 703 if(!$mybb->input['name']) 704 { 705 $errors[] = $lang->error_missing_name; 706 } 707 708 if(!$errors) 709 { 710 $tid = build_new_theme($mybb->input['name'], null, $mybb->input['tid']); 711 712 $plugins->run_hooks("admin_style_themes_add_commit"); 713 714 // Log admin action 715 log_admin_action($mybb->input['name'], $tid); 716 717 flash_message($lang->success_theme_created, 'success'); 718 admin_redirect("index.php?module=style-themes&action=edit&tid=".$tid); 719 } 720 } 721 722 $query = $db->simple_select("themes", "tid, name"); 723 while($theme = $db->fetch_array($query)) 724 { 725 $themes[$theme['tid']] = $theme['name']; 726 } 727 728 $page->add_breadcrumb_item($lang->create_new_theme, "index.php?module=style-themes&action=add"); 729 730 $page->output_header("{$lang->themes} - {$lang->create_new_theme}"); 731 732 $page->output_nav_tabs($sub_tabs, 'create_theme'); 733 734 if($errors) 735 { 736 $page->output_inline_error($errors); 737 } 738 739 $form = new Form("index.php?module=style-themes&action=add", "post"); 740 741 $form_container = new FormContainer($lang->create_a_theme); 742 $form_container->output_row($lang->name, $lang->name_desc, $form->generate_text_box('name', $mybb->input['name'], array('id' => 'name')), 'name'); 743 $form_container->output_row($lang->parent_theme, $lang->parent_theme_desc, $form->generate_select_box('tid', $themes, $mybb->input['tid'], array('id' => 'tid')), 'tid'); 744 745 $form_container->end(); 746 747 $buttons[] = $form->generate_submit_button($lang->create_new_theme); 748 749 $form->output_submit_wrapper($buttons); 750 751 $form->end(); 752 753 $page->output_footer(); 754 } 755 756 if($mybb->input['action'] == "delete") 757 { 758 $plugins->run_hooks("admin_style_themes_delete"); 759 760 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 761 $theme = $db->fetch_array($query); 762 763 // Does the theme not exist? or are we trying to delete the master? 764 if(!$theme['tid'] || $theme['tid'] == 1) 765 { 766 flash_message($lang->error_invalid_theme, 'error'); 767 admin_redirect("index.php?module=style-themes"); 768 } 769 770 // User clicked no 771 if($mybb->input['no']) 772 { 773 admin_redirect("index.php?module=style-themes"); 774 } 775 776 if($mybb->request_method == "post") 777 { 778 $inherited_theme_cache = array(); 779 780 $query = $db->simple_select("themes", "tid,stylesheets", "tid != '{$theme['tid']}'", array('order_by' => "pid, name")); 781 while($theme2 = $db->fetch_array($query)) 782 { 783 $theme2['stylesheets'] = unserialize($theme2['stylesheets']); 784 785 if(!$theme2['stylesheets']['inherited']) 786 { 787 continue; 788 } 789 790 $inherited_theme_cache[$theme2['tid']] = $theme2['stylesheets']['inherited']; 791 } 792 793 $inherited_stylesheets = false; 794 795 // Are any other themes relying on stylesheets from this theme? Get a list and show an error 796 foreach($inherited_theme_cache as $tid => $inherited) 797 { 798 foreach($inherited as $file => $value) 799 { 800 foreach($value as $filepath => $val) 801 { 802 if(strpos($filepath, "cache/themes/theme{$theme['tid']}") !== false) 803 { 804 $inherited_stylesheets = true; 805 } 806 } 807 } 808 } 809 810 if($inherited_stylesheets == true) 811 { 812 flash_message($lang->error_inheriting_stylesheets, 'error'); 813 admin_redirect("index.php?module=style-themes"); 814 } 815 816 $query = $db->simple_select("themestylesheets", "cachefile", "tid='{$theme['tid']}'"); 817 while($cachefile = $db->fetch_array($query)) 818 { 819 @unlink(MYBB_ROOT."cache/themes/theme{$theme['tid']}/{$cachefile['cachefile']}"); 820 } 821 @unlink(MYBB_ROOT."cache/themes/theme{$theme['tid']}/index.html"); 822 823 $db->delete_query("themestylesheets", "tid='{$theme['tid']}'"); 824 825 // Update the CSS file list for this theme 826 update_theme_stylesheet_list($theme['tid']); 827 828 $db->update_query("users", array('style' => 0), "style='{$theme['tid']}'"); 829 830 @rmdir(MYBB_ROOT."cache/themes/theme{$theme['tid']}/"); 831 832 $children = make_child_theme_list($theme['tid']); 833 $child_tid = $children[0]; 834 835 $db->update_query("themes", array('pid' => $theme['pid']), "tid='{$child_tid}'"); 836 837 $db->delete_query("themes", "tid='{$theme['tid']}'", 1); 838 839 $plugins->run_hooks("admin_style_themes_delete_commit"); 840 841 // Log admin action 842 log_admin_action($theme['tid'], $theme['name']); 843 844 flash_message($lang->success_theme_deleted, 'success'); 845 admin_redirect("index.php?module=style-themes"); 846 } 847 else 848 { 849 $page->output_confirm_action("index.php?module=style-themes&action=delete&tid={$theme['tid']}", $lang->confirm_theme_deletion); 850 } 851 } 852 853 if($mybb->input['action'] == "edit") 854 { 855 $plugins->run_hooks("admin_style_themes_edit"); 856 857 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 858 $theme = $db->fetch_array($query); 859 860 // Does the theme not exist? 861 if(!$theme['tid']) 862 { 863 flash_message($lang->error_invalid_theme, 'error'); 864 admin_redirect("index.php?module=style-themes"); 865 } 866 867 if($mybb->request_method == "post") 868 { 869 $properties = array( 870 'templateset' => intval($mybb->input['templateset']), 871 'editortheme' => $mybb->input['editortheme'], 872 'imgdir' => $mybb->input['imgdir'], 873 'logo' => $mybb->input['logo'], 874 'tablespace' => intval($mybb->input['tablespace']), 875 'borderwidth' => intval($mybb->input['borderwidth']) 876 ); 877 878 if($properties['templateset'] <= 0) 879 { 880 $errors[] = $lang->error_invalid_templateset; 881 } 882 883 $allowedgroups = array(); 884 if(is_array($mybb->input['allowedgroups'])) 885 { 886 foreach($mybb->input['allowedgroups'] as $gid) 887 { 888 if($gid == "all") 889 { 890 $allowedgroups = "all"; 891 break; 892 } 893 $gid = intval($gid); 894 $allowedgroups[$gid] = $gid; 895 } 896 } 897 if(is_array($allowedgroups)) 898 { 899 $allowedgroups = implode(",", $allowedgroups); 900 } 901 902 $update_array = array( 903 'name' => $db->escape_string($mybb->input['name']), 904 'pid' => intval($mybb->input['pid']), 905 'allowedgroups' => $allowedgroups, 906 'properties' => $db->escape_string(serialize($properties)) 907 ); 908 909 // perform validation 910 if(!$update_array['name']) 911 { 912 $errors[] = $lang->error_missing_name; 913 } 914 915 if($update_array['pid']) 916 { 917 $query = $db->simple_select("themes", "tid", "tid='".$update_array['pid']."'"); 918 $parent_check = $db->fetch_field($query, "tid"); 919 if(!$parent_check) 920 { 921 $errors[] = $lang->error_invalid_parent_theme; 922 } 923 } 924 if($properties['templateset']) 925 { 926 $query = $db->simple_select("templatesets", "sid", "sid='".$properties['templateset']."'"); 927 $ts_check = $db->fetch_field($query, "sid"); 928 if(!$ts_check) 929 { 930 unset($properties['templateset']); 931 } 932 } 933 if(!$properties['templateset']) 934 { 935 $errors[] = $lang->error_invalid_templateset; 936 } 937 if(!$properties['editortheme'] || !@is_dir(MYBB_ROOT."jscripts/editor_themes/".$properties['editortheme'])) 938 { 939 $errors[] = $lang->error_invalid_editortheme; 940 } 941 942 if(empty($errors)) 943 { 944 $db->update_query("themes", $update_array, "tid='{$theme['tid']}'"); 945 946 $plugins->run_hooks("admin_style_themes_edit_commit"); 947 948 // Log admin action 949 log_admin_action($theme['tid'], $theme['name']); 950 951 flash_message($lang->success_theme_properties_updated, 'success'); 952 admin_redirect("index.php?module=style-themes&action=edit&tid={$theme['tid']}"); 953 } 954 } 955 956 // Fetch list of all of the stylesheets for this theme 957 $file_stylesheets = unserialize($theme['stylesheets']); 958 959 $stylesheets = array(); 960 $inherited_load = array(); 961 962 // Now we loop through the list of stylesheets for each file 963 foreach($file_stylesheets as $file => $action_stylesheet) 964 { 965 if($file == 'inherited') 966 { 967 continue; 968 } 969 970 foreach($action_stylesheet as $action => $style) 971 { 972 foreach($style as $stylesheet) 973 { 974 $stylesheets[$stylesheet]['applied_to'][$file][] = $action; 975 if(is_array($file_stylesheets['inherited'][$file."_".$action]) && in_array($stylesheet, array_keys($file_stylesheets['inherited'][$file."_".$action]))) 976 { 977 $stylesheets[$stylesheet]['inherited'] = $file_stylesheets['inherited'][$file."_".$action]; 978 foreach($file_stylesheets['inherited'][$file."_".$action] as $value) 979 { 980 $inherited_load[] = $value; 981 } 982 } 983 } 984 } 985 } 986 987 $inherited_load[] = $mybb->input['tid']; 988 $inherited_load = array_unique($inherited_load); 989 990 $inherited_themes = array(); 991 if(count($inherited_load) > 0) 992 { 993 $query = $db->simple_select("themes", "tid, name", "tid IN (".implode(",", $inherited_load).")"); 994 while($inherited_theme = $db->fetch_array($query)) 995 { 996 $inherited_themes[$inherited_theme['tid']] = $inherited_theme['name']; 997 } 998 } 999 1000 $theme_stylesheets = array(); 1001 1002 if(count($inherited_load) > 0) 1003 { 1004 $query = $db->simple_select("themestylesheets", "*", "", array('order_by' => 'sid DESC, tid', 'order_dir' => 'desc')); 1005 while($theme_stylesheet = $db->fetch_array($query)) 1006 { 1007 if(!$theme_stylesheets[$theme_stylesheet['cachefile']] && in_array($theme_stylesheet['tid'], $inherited_load)) 1008 { 1009 $theme_stylesheets[$theme_stylesheet['cachefile']] = $theme_stylesheet; 1010 } 1011 1012 $theme_stylesheets[$theme_stylesheet['sid']] = $theme_stylesheet['cachefile']; 1013 } 1014 } 1015 1016 $page->add_breadcrumb_item(htmlspecialchars_uni($theme['name']), "index.php?module=style-themes&action=edit&tid={$mybb->input['tid']}"); 1017 1018 $page->output_header("{$lang->themes} - {$lang->stylesheets}"); 1019 1020 $sub_tabs['edit_stylesheets'] = array( 1021 'title' => $lang->edit_stylesheets, 1022 'link' => "index.php?module=style-themes&action=edit&tid={$mybb->input['tid']}", 1023 'description' => $lang->edit_stylesheets_desc 1024 ); 1025 1026 $sub_tabs['add_stylesheet'] = array( 1027 'title' => $lang->add_stylesheet, 1028 'link' => "index.php?module=style-themes&action=add_stylesheet&tid={$mybb->input['tid']}", 1029 ); 1030 1031 $sub_tabs['export_theme'] = array( 1032 'title' => $lang->export_theme, 1033 'link' => "index.php?module=style-themes&action=export&tid={$mybb->input['tid']}" 1034 ); 1035 1036 $page->output_nav_tabs($sub_tabs, 'edit_stylesheets'); 1037 1038 $table = new Table; 1039 $table->construct_header($lang->stylesheets); 1040 $table->construct_header($lang->controls, array("class" => "align_center", "width" => 150)); 1041 1042 foreach($stylesheets as $filename => $style) 1043 { 1044 if(strpos($filename, 'css.php?stylesheet=') !== false) 1045 { 1046 $style['sid'] = (integer)str_replace('css.php?stylesheet=', '', $filename); 1047 $filename = $theme_stylesheets[$style['sid']]; 1048 } 1049 else 1050 { 1051 $filename = basename($filename); 1052 $style['sid'] = $theme_stylesheets[$filename]['sid']; 1053 } 1054 1055 // Has the file on the file system been modified? 1056 resync_stylesheet($theme_stylesheets[$filename]); 1057 1058 $filename = $theme_stylesheets[$filename]['name']; 1059 1060 $inherited = ""; 1061 $inherited_ary = array(); 1062 if(is_array($style['inherited'])) 1063 { 1064 foreach($style['inherited'] as $tid) 1065 { 1066 if($inherited_themes[$tid]) 1067 { 1068 $inherited_ary[$tid] = $inherited_themes[$tid]; 1069 } 1070 } 1071 } 1072 1073 if(!empty($inherited_ary)) 1074 { 1075 $inherited = " <small>({$lang->inherited_from}"; 1076 $sep = " "; 1077 $inherited_count = count($inherited_ary); 1078 $count = 0; 1079 1080 foreach($inherited_ary as $tid => $file) 1081 { 1082 if($count == $applied_to_count && $count != 0) 1083 { 1084 $sep = ", {$lang->and} "; 1085 } 1086 1087 $inherited .= $sep.$file; 1088 $sep = $lang->comma; 1089 1090 ++$count; 1091 } 1092 $inherited .= ")</small>"; 1093 } 1094 1095 if(is_array($style['applied_to']) && $style['applied_to']['global'][0] != "global") 1096 { 1097 $attached_to = "<small>{$lang->attached_to}"; 1098 1099 $applied_to_count = count($style['applied_to']); 1100 $count = 0; 1101 $sep = " "; 1102 $name = ""; 1103 foreach($style['applied_to'] as $name => $actions) 1104 { 1105 if(!$name) 1106 { 1107 continue; 1108 } 1109 1110 ++$count; 1111 1112 if($actions[0] != "global") 1113 { 1114 $name = "{$name} ({$lang->actions}: ".implode(',', $actions).")"; 1115 } 1116 1117 if($count == $applied_to_count && $count > 1) 1118 { 1119 $sep = ", {$lang->and} "; 1120 } 1121 $attached_to .= $sep.$name; 1122 1123 $sep = $lang->comma; 1124 } 1125 1126 $attached_to .= "</small>"; 1127 } 1128 else 1129 { 1130 $attached_to = "<small>{$lang->attached_to_all_pages}</small>"; 1131 } 1132 1133 $popup = new PopupMenu("style_{$style['sid']}", $lang->options); 1134 1135 $popup->add_item($lang->edit_style, "index.php?module=style-themes&action=edit_stylesheet&file=".htmlspecialchars_uni($filename)."&tid={$theme['tid']}"); 1136 $popup->add_item($lang->properties, "index.php?module=style-themes&action=stylesheet_properties&file=".htmlspecialchars_uni($filename)."&tid={$theme['tid']}"); 1137 1138 if($inherited == "") 1139 { 1140 $popup->add_item($lang->delete_revert, "index.php?module=style-themes&action=delete_stylesheet&file=".htmlspecialchars_uni($filename)."&tid={$theme['tid']}&my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_stylesheet_deletion}')"); 1141 } 1142 1143 $table->construct_cell("<strong><a href=\"index.php?module=style-themes&action=edit_stylesheet&file=".htmlspecialchars_uni($filename)."&tid={$theme['tid']}\">{$filename}</a></strong>{$inherited}<br />{$attached_to}"); 1144 $table->construct_cell($popup->fetch(), array("class" => "align_center")); 1145 $table->construct_row(); 1146 } 1147 1148 $table->output("{$lang->stylesheets_in} ".htmlspecialchars_uni($theme['name'])); 1149 1150 // Theme Properties table 1151 if($errors) 1152 { 1153 $page->output_inline_error($errors); 1154 } 1155 1156 $properties = unserialize($theme['properties']); 1157 $form = new Form("index.php?module=style-themes&action=edit", "post", "edit"); 1158 echo $form->generate_hidden_field("tid", $theme['tid']); 1159 $form_container = new FormContainer($lang->edit_theme_properties); 1160 $form_container->output_row($lang->name." <em>*</em>", $lang->name_desc_edit, $form->generate_text_box('name', $theme['name'], array('id' => 'name')), 'name'); 1161 1162 $options = build_theme_array($theme['tid']); 1163 $form_container->output_row($lang->parent_theme." <em>*</em>", $lang->parent_theme_desc, $form->generate_select_box('pid', $options, $theme['pid'], array('id' => 'pid')), 'pid'); 1164 1165 $options = array(); 1166 $query = $db->simple_select("usergroups", "gid, title", "gid != '1'", array('order_by' => 'title')); 1167 $options['all'] = $lang->all_user_groups; 1168 while($usergroup = $db->fetch_array($query)) 1169 { 1170 $options[(int)$usergroup['gid']] = $usergroup['title']; 1171 } 1172 $form_container->output_row($lang->allowed_user_groups, $lang->allowed_user_groups_desc, $form->generate_select_box('allowedgroups[]', $options, explode(",", $theme['allowedgroups']), array('id' => 'allowedgroups', 'multiple' => true, 'size' => 5)), 'allowedgroups'); 1173 1174 $options = array(); 1175 $query = $db->simple_select("templatesets", "*", "", array('order_by' => 'title')); 1176 while($templateset = $db->fetch_array($query)) 1177 { 1178 $options[intval($templateset['sid'])] = $templateset['title']; 1179 } 1180 $form_container->output_row($lang->template_set." <em>*</em>", $lang->template_set_desc, $form->generate_select_box('templateset', $options, $properties['templateset'], array('id' => 'templateset')), 'templateset'); 1181 1182 $options = array(); 1183 $editor_theme_root = MYBB_ROOT."jscripts/editor_themes/"; 1184 if($dh = @opendir($editor_theme_root)) 1185 { 1186 while($dir = readdir($dh)) 1187 { 1188 if($dir == ".svn" || $dir == "." || $dir == ".." || !is_dir($editor_theme_root.$dir)) 1189 { 1190 continue; 1191 } 1192 $options[$dir] = ucfirst(str_replace('_', ' ', $dir)); 1193 } 1194 } 1195 1196 $form_container->output_row($lang->editor_theme." <em>*</em>", $lang->editor_theme_desc, $form->generate_select_box('editortheme', $options, $properties['editortheme'], array('id' => 'editortheme')), 'editortheme'); 1197 1198 $form_container->output_row($lang->img_directory, $lang->img_directory_desc, $form->generate_text_box('imgdir', $properties['imgdir'], array('id' => 'imgdir')), 'imgdir'); 1199 $form_container->output_row($lang->logo, $lang->logo_desc, $form->generate_text_box('logo', $properties['logo'], array('id' => 'boardlogo')), 'logo'); 1200 $form_container->output_row($lang->table_spacing, $lang->table_spacing_desc, $form->generate_text_box('tablespace', $properties['tablespace'], array('id' => 'tablespace')), 'tablespace'); 1201 $form_container->output_row($lang->inner_border, $lang->inner_border_desc, $form->generate_text_box('borderwidth', $properties['borderwidth'], array('id' => 'borderwidth')), 'borderwidth'); 1202 1203 $form_container->end(); 1204 $buttons = array(); 1205 $buttons[] = $form->generate_submit_button($lang->save_theme_properties); 1206 $form->output_submit_wrapper($buttons); 1207 $form->end(); 1208 1209 $page->output_footer(); 1210 } 1211 1212 if($mybb->input['action'] == "stylesheet_properties") 1213 { 1214 $plugins->run_hooks("admin_style_themes_stylesheet_properties"); 1215 1216 // Fetch the theme we want to edit this stylesheet in 1217 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 1218 $theme = $db->fetch_array($query); 1219 1220 if(!$theme['tid']) 1221 { 1222 flash_message($lang->error_invalid_theme, 'error'); 1223 admin_redirect("index.php?module=style-themes"); 1224 } 1225 1226 $parent_list = make_parent_theme_list($theme['tid']); 1227 $parent_list = implode(',', $parent_list); 1228 if(!$parent_list) 1229 { 1230 $parent_list = 1; 1231 } 1232 1233 $query = $db->simple_select("themestylesheets", "*", "name='".$db->escape_string($mybb->input['file'])."' AND tid IN ({$parent_list})", array('order_by' => 'tid', 'order_dir' => 'desc', 'limit' => 1)); 1234 $stylesheet = $db->fetch_array($query); 1235 1236 // Does the theme not exist? 1237 if(!$stylesheet['sid']) 1238 { 1239 flash_message($lang->error_invalid_stylesheet, 'error'); 1240 admin_redirect("index.php?module=style-themes"); 1241 } 1242 1243 // Fetch list of all of the stylesheets for this theme 1244 $file_stylesheets = unserialize($theme['stylesheets']); 1245 1246 $stylesheets = array(); 1247 $inherited_load = array(); 1248 1249 // Now we loop through the list of stylesheets for each file 1250 foreach($file_stylesheets as $file => $action_stylesheet) 1251 { 1252 if($file == 'inherited') 1253 { 1254 continue; 1255 } 1256 1257 foreach($action_stylesheet as $action => $style) 1258 { 1259 foreach($style as $stylesheet2) 1260 { 1261 $stylesheets[$stylesheet2]['applied_to'][$file][] = $action; 1262 if(is_array($file_stylesheets['inherited'][$file."_".$action]) && in_array($stylesheet2, array_keys($file_stylesheets['inherited'][$file."_".$action]))) 1263 { 1264 $stylesheets[$stylesheet2]['inherited'] = $file_stylesheets['inherited'][$file."_".$action]; 1265 foreach($file_stylesheets['inherited'][$file."_".$action] as $value) 1266 { 1267 $inherited_load[] = $value; 1268 } 1269 } 1270 } 1271 } 1272 } 1273 1274 foreach($stylesheets as $file => $stylesheet2) 1275 { 1276 if(is_array($stylesheet2['inherited'])) 1277 { 1278 foreach($stylesheet2['inherited'] as $inherited_file => $tid) 1279 { 1280 $stylesheet2['inherited'][basename($inherited_file)] = $tid; 1281 unset($stylesheet2['inherited'][$inherited_file]); 1282 } 1283 } 1284 1285 unset($stylesheets[$file]); 1286 $stylesheets[basename($file)] = $stylesheet2; 1287 } 1288 1289 if(!array_key_exists($stylesheet['cachefile'], $stylesheets) && array_key_exists("css.php?stylesheet=".$stylesheet['tid'], $stylesheets)) 1290 { 1291 $stylesheet['cachefile'] = "css.php?stylesheet=".$stylesheet['tid']; 1292 } 1293 1294 $this_stylesheet = $stylesheets[$stylesheet['cachefile']]; 1295 unset($stylesheets); 1296 1297 if($mybb->request_method == "post") 1298 { 1299 // Do we not have a name, or is it just an extension? 1300 if(!$mybb->input['name'] || $mybb->input['name'] == ".css") 1301 { 1302 $errors[] = $lang->error_missing_stylesheet_name; 1303 } 1304 1305 if(substr($mybb->input['name'], -4) != ".css") 1306 { 1307 // Does not end with '.css' 1308 $errors[] = $lang->sprintf($lang->error_missing_stylesheet_extension, $mybb->input['name']); 1309 } 1310 1311 if(!$errors) 1312 { 1313 // Theme & stylesheet theme ID do not match, editing inherited - we copy to local theme 1314 if($theme['tid'] != $stylesheet['tid']) 1315 { 1316 $stylesheet['sid'] = copy_stylesheet_to_theme($stylesheet, $theme['tid']); 1317 } 1318 1319 $attached = array(); 1320 1321 if($mybb->input['attach'] == 1) 1322 { 1323 // Our stylesheet is attached to custom pages in MyBB 1324 foreach($mybb->input as $id => $value) 1325 { 1326 $actions_list = ""; 1327 $attached_to = $value; 1328 1329 if(strpos($id, 'attached_') !== false) 1330 { 1331 // We have a custom attached file 1332 $attached_id = intval(str_replace('attached_', '', $id)); 1333 1334 if($mybb->input['action_'.$attached_id] == 1) 1335 { 1336 // We have custom actions for attached files 1337 $actions_list = $mybb->input['action_list_'.$attached_id]; 1338 } 1339 1340 if($actions_list) 1341 { 1342 $attached_to .= "?".$actions_list; 1343 } 1344 1345 $attached[] = $attached_to; 1346 } 1347 } 1348 } 1349 1350 // Update Stylesheet 1351 $update_array = array( 1352 'name' => $db->escape_string($mybb->input['name']), 1353 'attachedto' => $db->escape_string(implode('|', $attached)) 1354 ); 1355 1356 if($stylesheet['name'] != $mybb->input['name']) 1357 { 1358 $update_array['cachefile'] = $db->escape_string(str_replace('/', '', $mybb->input['name'])); 1359 } 1360 1361 $db->update_query("themestylesheets", $update_array, "sid='{$stylesheet['sid']}'", 1); 1362 1363 // If the name changed, re-cache our stylesheet 1364 if($stylesheet['name'] != $mybb->input['name']) 1365 { 1366 $db->update_query("themestylesheets", array('lastmodified' => TIME_NOW), "sid='{$stylesheet['sid']}'", 1); 1367 if(!cache_stylesheet($theme['tid'], str_replace('/', '', $mybb->input['name']), $theme['stylesheet'])) 1368 { 1369 $db->update_query("themestylesheets", array('cachefile' => "css.php?stylesheet={$stylesheet['sid']}"), "sid='{$stylesheet['sid']}'", 1); 1370 } 1371 @unlink(MYBB_ROOT."cache/themes/theme{$theme['tid']}/{$stylesheet['cachefile']}"); 1372 } 1373 1374 // Update the CSS file list for this theme 1375 update_theme_stylesheet_list($theme['tid']); 1376 1377 $plugins->run_hooks("admin_style_themes_stylesheet_properties_commit"); 1378 1379 // Log admin action 1380 log_admin_action($stylesheet['sid'], $mybb->input['name'], $theme['tid'], $theme['name']); 1381 1382 flash_message($lang->success_stylesheet_properties_updated, 'success'); 1383 admin_redirect("index.php?module=style-themes&action=edit&tid={$theme['tid']}"); 1384 } 1385 } 1386 1387 1388 $page->add_breadcrumb_item(htmlspecialchars_uni($theme['name']), "index.php?module=style-themes&action=edit&tid={$mybb->input['tid']}"); 1389 $page->add_breadcrumb_item(htmlspecialchars_uni($stylesheet['name'])." {$lang->properties}", "index.php?module=style-themes&action=edit_properties&tid={$mybb->input['tid']}"); 1390 1391 $page->output_header("{$lang->themes} - {$lang->stylesheet_properties}"); 1392 1393 // If the stylesheet and theme do not match, we must be editing something that is inherited 1394 if($this_stylesheet['inherited'][$stylesheet['name']]) 1395 { 1396 $query = $db->simple_select("themes", "name", "tid='{$stylesheet['tid']}'"); 1397 $stylesheet_parent = htmlspecialchars_uni($db->fetch_field($query, 'name')); 1398 1399 // Show inherited warning 1400 if($stylesheet['tid'] == 1) 1401 { 1402 $page->output_alert($lang->sprintf($lang->stylesheet_inherited_default, $stylesheet_parent)); 1403 } 1404 else 1405 { 1406 $page->output_alert($lang->sprintf($lang->stylesheet_inherited, $stylesheet_parent)); 1407 } 1408 } 1409 1410 $applied_to = $this_stylesheet['applied_to']; 1411 unset($this_stylesheet); 1412 1413 if($errors) 1414 { 1415 $page->output_inline_error($errors); 1416 1417 foreach($mybb->input as $name => $value) 1418 { 1419 if(strpos($name, "attached") !== false) 1420 { 1421 list(, $id) = explode('_', $name); 1422 $id = intval($id); 1423 1424 $applied_to[$value] = array(0 => 'global'); 1425 1426 if($mybb->input['action_'.$id] == 1) 1427 { 1428 $applied_to[$value] = explode(',', $mybb->input['action_list_'.$id]); 1429 } 1430 } 1431 } 1432 } 1433 else 1434 { 1435 $mybb->input['name'] = $stylesheet['name']; 1436 } 1437 1438 $form = new Form("index.php?module=style-themes&action=stylesheet_properties", "post"); 1439 1440 $specific_files = "<div id=\"attach_1\" class=\"attachs\">"; 1441 $count = 0; 1442 1443 if(is_array($applied_to) && $applied_to['global'][0] != "global") 1444 { 1445 $check_actions = ""; 1446 1447 $global_checked[2] = "checked=\"checked\""; 1448 $global_checked[1] = ""; 1449 1450 foreach($applied_to as $name => $actions) 1451 { 1452 $short_name = substr($name, 0, -4); 1453 1454 $action_list = ""; 1455 if($actions[0] != "global") 1456 { 1457 $action_list = implode(',', $actions); 1458 } 1459 1460 if($actions[0] == "global") 1461 { 1462 $global_action_checked[1] = "checked=\"checked\""; 1463 $global_action_checked[2] = ""; 1464 } 1465 else 1466 { 1467 $global_action_checked[2] = "checked=\"checked\""; 1468 $global_action_checked[1] = ""; 1469 } 1470 1471 $specific_file = "<dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\"> 1472 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"action_{$count}\" value=\"0\" {$global_action_checked[1]} class=\"action_{$count}s_check\" onclick=\"checkAction('action_{$count}');\" style=\"vertical-align: middle;\" /> {$lang->globally}</label></dt> 1473 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"action_{$count}\" value=\"1\" {$global_action_checked[2]} class=\"action_{$count}s_check\" onclick=\"checkAction('action_{$count}');\" style=\"vertical-align: middle;\" /> {$lang->specific_actions}</label></dt> 1474 <dd style=\"margin-top: 4px;\" id=\"action_{$count}_1\" class=\"action_{$count}s\"> 1475 <small class=\"description\">{$lang->specific_actions_desc}</small> 1476 <table cellpadding=\"4\"> 1477 <tr> 1478 <td>".$form->generate_text_box('action_list_'.$count, $action_list, array('id' => 'action_list_'.$count, 'style' => 'width: 190px;'))."</td> 1479 </tr> 1480 </table> 1481 </dd> 1482 </dl>"; 1483 1484 $form_container = new FormContainer(); 1485 $form_container->output_row("", "", "<span style=\"float: right;\"><a href=\"\" id=\"delete_img_{$count}\"><img src=\"styles/{$page->style}/images/icons/cross.gif\" alt=\"{$lang->delete}\" title=\"{$lang->delete}\" /></a></span>{$lang->file} ".$form->generate_text_box("attached_{$count}", $name, array('id' => "attached_{$count}", 'style' => 'width: 200px;')), "attached_{$count}"); 1486 1487 $form_container->output_row("", "", $specific_file); 1488 1489 $specific_files .= "<div id=\"attached_form_{$count}\">".$form_container->end(true)."</div><div id=\"attach_box_".($count+1)."\"></div>"; 1490 1491 $check_actions .= "\n\tcheckAction('action_{$count}');"; 1492 1493 ++$count; 1494 } 1495 } 1496 else 1497 { 1498 $global_checked[1] = "checked=\"checked\""; 1499 $global_checked[2] = ""; 1500 } 1501 1502 $specific_files .= "</div>"; 1503 1504 $actions = '<script type="text/javascript"> 1505 function checkAction(id) 1506 { 1507 var checked = \'\'; 1508 1509 $$(\'.\'+id+\'s_check\').each(function(e) 1510 { 1511 if(e.checked == true) 1512 { 1513 checked = e.value; 1514 } 1515 }); 1516 $$(\'.\'+id+\'s\').each(function(e) 1517 { 1518 Element.hide(e); 1519 }); 1520 if($(id+\'_\'+checked)) 1521 { 1522 Element.show(id+\'_\'+checked); 1523 } 1524 } 1525 </script> 1526 <dl style="margin-top: 0; margin-bottom: 0; width: 40%;"> 1527 <dt><label style="display: block;"><input type="radio" name="attach" value="0" '.$global_checked[1].' class="attachs_check" onclick="checkAction(\'attach\');" style="vertical-align: middle;" /> '.$lang->globally.'</label></dt> 1528 <dt><label style="display: block;"><input type="radio" name="attach" value="1" '.$global_checked[2].' class="attachs_check" onclick="checkAction(\'attach\');" style="vertical-align: middle;" /> '.$lang->specific_files.' (<a id="new_specific_file">'.$lang->add_another.'</a>)</label></dt><br /> 1529 '.$specific_files.' 1530 </dl> 1531 <script type="text/javascript"> 1532 checkAction(\'attach\');'.$check_actions.' 1533 </script>'; 1534 1535 echo $form->generate_hidden_field("file", htmlspecialchars_uni($stylesheet['name']))."<br />\n"; 1536 echo $form->generate_hidden_field("tid", $theme['tid'])."<br />\n"; 1537 1538 $form_container = new FormContainer("{$lang->edit_stylesheet_properties_for} ".htmlspecialchars_uni($stylesheet['name'])); 1539 $form_container->output_row($lang->file_name, $lang->file_name_desc, $form->generate_text_box('name', $mybb->input['name'], array('id' => 'name', 'style' => 'width: 200px;')), 'name'); 1540 1541 $form_container->output_row($lang->attached_to, $lang->attached_to_desc, $actions); 1542 1543 $form_container->end(); 1544 1545 $buttons[] = $form->generate_submit_button($lang->save_stylesheet_properties); 1546 1547 $form->output_submit_wrapper($buttons); 1548 1549 echo '<script type="text/javascript" src="./jscripts/themes.js"></script>'; 1550 echo '<script type="text/javascript"> 1551 1552 Event.observe(window, "load", function() { 1553 //<![CDATA[ 1554 new ThemeSelector(\''.$count.'\'); 1555 }); 1556 //]]> 1557 </script>'; 1558 1559 $form->end(); 1560 1561 $page->output_footer(); 1562 } 1563 1564 // Shows the page where you can actually edit a particular selector or the whole stylesheet 1565 if($mybb->input['action'] == "edit_stylesheet" && (!$mybb->input['mode'] || $mybb->input['mode'] == "simple")) 1566 { 1567 $plugins->run_hooks("admin_style_themes_edit_stylesheet_simple"); 1568 1569 // Fetch the theme we want to edit this stylesheet in 1570 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 1571 $theme = $db->fetch_array($query); 1572 1573 if(!$theme['tid']) 1574 { 1575 flash_message($lang->error_invalid_theme, 'error'); 1576 admin_redirect("index.php?module=style-themes"); 1577 } 1578 1579 $parent_list = make_parent_theme_list($theme['tid']); 1580 $parent_list = implode(',', $parent_list); 1581 if(!$parent_list) 1582 { 1583 $parent_list = 1; 1584 } 1585 1586 $query = $db->simple_select("themestylesheets", "*", "name='".$db->escape_string($mybb->input['file'])."' AND tid IN ({$parent_list})", array('order_by' => 'tid', 'order_dir' => 'desc', 'limit' => 1)); 1587 $stylesheet = $db->fetch_array($query); 1588 1589 // Does the theme not exist? 1590 if(!$stylesheet['sid']) 1591 { 1592 flash_message($lang->error_invalid_stylesheet, 'error'); 1593 admin_redirect("index.php?module=style-themes"); 1594 } 1595 1596 if($mybb->request_method == "post") 1597 { 1598 $sid = $stylesheet['sid']; 1599 1600 // Theme & stylesheet theme ID do not match, editing inherited - we copy to local theme 1601 if($theme['tid'] != $stylesheet['tid']) 1602 { 1603 $sid = copy_stylesheet_to_theme($stylesheet, $theme['tid']); 1604 } 1605 1606 // Insert the modified CSS 1607 $new_stylesheet = $stylesheet['stylesheet']; 1608 1609 if($mybb->input['serialized'] == 1) 1610 { 1611 $mybb->input['css_bits'] = unserialize($mybb->input['css_bits']); 1612 } 1613 1614 $css_to_insert = ''; 1615 foreach($mybb->input['css_bits'] as $field => $value) 1616 { 1617 if(!trim($value) || !trim($field)) 1618 { 1619 continue; 1620 } 1621 1622 if($field == "extra") 1623 { 1624 $css_to_insert .= $value."\n"; 1625 } 1626 else 1627 { 1628 $field = str_replace("_", "-", $field); 1629 $css_to_insert .= "{$field}: {$value};\n"; 1630 } 1631 } 1632 1633 $new_stylesheet = insert_into_css($css_to_insert, $mybb->input['selector'], $new_stylesheet); 1634 1635 // Now we have the new stylesheet, save it 1636 $updated_stylesheet = array( 1637 "cachefile" => $db->escape_string($stylesheet['name']), 1638 "stylesheet" => $db->escape_string(unfix_css_urls($new_stylesheet)), 1639 "lastmodified" => TIME_NOW 1640 ); 1641 $db->update_query("themestylesheets", $updated_stylesheet, "sid='{$sid}'"); 1642 1643 // Cache the stylesheet to the file 1644 if(!cache_stylesheet($theme['tid'], $stylesheet['name'], $new_stylesheet)) 1645 { 1646 $db->update_query("themestylesheets", array('cachefile' => "css.php?stylesheet={$sid}"), "sid='{$sid}'", 1); 1647 } 1648 1649 // Update the CSS file list for this theme 1650 update_theme_stylesheet_list($theme['tid']); 1651 1652 $plugins->run_hooks("admin_style_themes_edit_stylesheet_simple_commit"); 1653 1654 // Log admin action 1655 log_admin_action($theme['name'], $stylesheet['name']); 1656 1657 if(!$mybb->input['ajax']) 1658 { 1659 flash_message($lang->success_stylesheet_updated, 'success'); 1660 1661 if($mybb->input['save_close']) 1662 { 1663 admin_redirect("index.php?module=style-themes&action=edit&tid={$theme['tid']}"); 1664 } 1665 else 1666 { 1667 admin_redirect("index.php?module=style-themes&action=edit_stylesheet&tid={$theme['tid']}&file={$stylesheet['name']}"); 1668 } 1669 } 1670 else 1671 { 1672 echo "1"; 1673 exit; 1674 } 1675 } 1676 1677 // Has the file on the file system been modified? 1678 if(resync_stylesheet($stylesheet)) 1679 { 1680 // Need to refetch new stylesheet as it was modified 1681 $query = $db->simple_select("themestylesheets", "stylesheet", "sid='{$stylesheet['sid']}'"); 1682 $stylesheet['stylesheet'] = $db->fetch_field($query, 'stylesheet'); 1683 } 1684 1685 $css_array = css_to_array($stylesheet['stylesheet']); 1686 $selector_list = get_selectors_as_options($css_array, $mybb->input['selector']); 1687 1688 // Do we not have any selectors? Send em to the full edit page 1689 if(!$selector_list) 1690 { 1691 flash_message($lang->error_cannot_parse, 'error'); 1692 admin_redirect("index.php?module=style-themes&action=edit_stylesheet&tid={$theme['tid']}&file=".htmlspecialchars_uni($stylesheet['name'])."&mode=advanced"); 1693 exit; 1694 } 1695 1696 // Fetch list of all of the stylesheets for this theme 1697 $file_stylesheets = unserialize($theme['stylesheets']); 1698 1699 $stylesheets = array(); 1700 $inherited_load = array(); 1701 1702 // Now we loop through the list of stylesheets for each file 1703 foreach($file_stylesheets as $file => $action_stylesheet) 1704 { 1705 if($file == 'inherited') 1706 { 1707 continue; 1708 } 1709 1710 foreach($action_stylesheet as $action => $style) 1711 { 1712 foreach($style as $stylesheet2) 1713 { 1714 $stylesheets[$stylesheet2]['applied_to'][$file][] = $action; 1715 if(is_array($file_stylesheets['inherited'][$file."_".$action]) && in_array($stylesheet2, array_keys($file_stylesheets['inherited'][$file."_".$action]))) 1716 { 1717 $stylesheets[$stylesheet2]['inherited'] = $file_stylesheets['inherited'][$file."_".$action]; 1718 foreach($file_stylesheets['inherited'][$file."_".$action] as $value) 1719 { 1720 $inherited_load[] = $value; 1721 } 1722 } 1723 } 1724 } 1725 } 1726 1727 foreach($stylesheets as $file => $stylesheet2) 1728 { 1729 if(is_array($stylesheet2['inherited'])) 1730 { 1731 foreach($stylesheet2['inherited'] as $inherited_file => $tid) 1732 { 1733 $stylesheet2['inherited'][basename($inherited_file)] = $tid; 1734 unset($stylesheet2['inherited'][$inherited_file]); 1735 } 1736 } 1737 1738 $stylesheets[basename($file)] = $stylesheet2; 1739 unset($stylesheets[$file]); 1740 } 1741 1742 $this_stylesheet = $stylesheets[$stylesheet['name']]; 1743 unset($stylesheets); 1744 1745 $page->extra_header .= " 1746 <script type=\"text/javascript\"> 1747 var my_post_key = '".$mybb->post_code."'; 1748 </script>"; 1749 1750 $page->add_breadcrumb_item(htmlspecialchars_uni($theme['name']), "index.php?module=style-themes&action=edit&tid={$mybb->input['tid']}"); 1751 $page->add_breadcrumb_item("{$lang->editing} ".htmlspecialchars_uni($stylesheet['name']), "index.php?module=style-themes&action=edit_stylesheet&tid={$mybb->input['tid']}&file=".htmlspecialchars_uni($mybb->input['file'])."&mode=simple"); 1752 1753 $page->output_header("{$lang->themes} - {$lang->edit_stylesheets}"); 1754 1755 // If the stylesheet and theme do not match, we must be editing something that is inherited 1756 if($this_stylesheet['inherited'][$stylesheet['name']]) 1757 { 1758 $query = $db->simple_select("themes", "name", "tid='{$stylesheet['tid']}'"); 1759 $stylesheet_parent = htmlspecialchars_uni($db->fetch_field($query, 'name')); 1760 1761 // Show inherited warning 1762 if($stylesheet['tid'] == 1) 1763 { 1764 $page->output_alert($lang->sprintf($lang->stylesheet_inherited_default, $stylesheet_parent), "ajax_alert"); 1765 } 1766 else 1767 { 1768 $page->output_alert($lang->sprintf($lang->stylesheet_inherited, $stylesheet_parent), "ajax_alert"); 1769 } 1770 } 1771 1772 $sub_tabs['edit_stylesheet'] = array( 1773 'title' => $lang->edit_stylesheet_simple_mode, 1774 'link' => "index.php?module=style-themes&action=edit_stylesheet&tid={$mybb->input['tid']}&file=".htmlspecialchars_uni($mybb->input['file'])."&mode=simple", 1775 'description' => $lang->edit_stylesheet_simple_mode_desc 1776 ); 1777 1778 $sub_tabs['edit_stylesheet_advanced'] = array( 1779 'title' => $lang->edit_stylesheet_advanced_mode, 1780 'link' => "index.php?module=style-themes&action=edit_stylesheet&tid={$mybb->input['tid']}&file=".htmlspecialchars_uni($mybb->input['file'])."&mode=advanced", 1781 ); 1782 1783 $page->output_nav_tabs($sub_tabs, 'edit_stylesheet'); 1784 1785 // Output the selection box 1786 $form = new Form("index.php", "get", "selector_form"); 1787 echo $form->generate_hidden_field("module", "style/themes")."\n"; 1788 echo $form->generate_hidden_field("action", "edit_stylesheet")."\n"; 1789 echo $form->generate_hidden_field("tid", $mybb->input['tid'])."\n"; 1790 echo $form->generate_hidden_field("file", htmlspecialchars_uni($mybb->input['file']))."\n"; 1791 1792 echo "{$lang->selector}: <select id=\"selector\" name=\"selector\">\n{$selector_list}</select> <span id=\"mini_spinner\">".$form->generate_submit_button($lang->go)."</span><br /><br />\n"; 1793 1794 $form->end(); 1795 1796 // Haven't chosen a selector to edit, show the first one from the stylesheet 1797 if(!$mybb->input['selector']) 1798 { 1799 reset($css_array); 1800 uasort($css_array, "css_selectors_sort_cmp"); 1801 $selector = key($css_array); 1802 $editable_selector = $css_array[$selector]; 1803 } 1804 // Show a specific selector 1805 else 1806 { 1807 $editable_selector = $css_array[$mybb->input['selector']]; 1808 $selector = $mybb->input['selector']; 1809 } 1810 1811 // Get the properties from this item 1812 $properties = parse_css_properties($editable_selector['values']); 1813 1814 $form = new Form("index.php?module=style-themes&action=edit_stylesheet", "post"); 1815 echo $form->generate_hidden_field("tid", $mybb->input['tid'], array('id' => "tid"))."\n"; 1816 echo $form->generate_hidden_field("file", htmlspecialchars_uni($mybb->input['file']), array('id' => "file"))."\n"; 1817 echo $form->generate_hidden_field("selector", htmlspecialchars_uni($selector), array('id' => 'hidden_selector'))."\n"; 1818 1819 echo "<div id=\"stylesheet\">"; 1820 $table = new Table; 1821 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[background]', $properties['background'], array('id' => 'css_bits[background]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->background}</strong></div>", array('style' => 'width: 20%;')); 1822 $table->construct_cell("<strong>{$lang->extra_css_atribs}</strong><br /><div style=\"align: center;\">".$form->generate_text_area('css_bits[extra]', $properties['extra'], array('id' => 'css_bits[extra]', 'style' => 'width: 98%;', 'rows' => '19'))."</div>", array('rowspan' => 8)); 1823 $table->construct_row(); 1824 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[color]', $properties['color'], array('id' => 'css_bits[color]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->color}</strong></div>", array('style' => 'width: 40%;')); 1825 $table->construct_row(); 1826 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[width]', $properties['width'], array('id' => 'css_bits[width]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->width}</strong></div>", array('style' => 'width: 40%;')); 1827 $table->construct_row(); 1828 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[font_family]', $properties['font-family'], array('id' => 'css_bits[font_family]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->font_family}</strong></div>", array('style' => 'width: 40%;')); 1829 $table->construct_row(); 1830 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[font_size]', $properties['font-size'], array('id' => 'css_bits[font_size]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->font_size}</strong></div>", array('style' => 'width: 40%;')); 1831 $table->construct_row(); 1832 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[font_style]', $properties['font-style'], array('id' => 'css_bits[font_style]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->font_style}</strong></div>", array('style' => 'width: 40%;')); 1833 $table->construct_row(); 1834 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[font_weight]', $properties['font-weight'], array('id' => 'css_bits[font_weight]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->font_weight}</strong></div>", array('style' => 'width: 40%;')); 1835 $table->construct_row(); 1836 $table->construct_cell("<div style=\"float: right;\">".$form->generate_text_box('css_bits[text_decoration]', $properties['text-decoration'], array('id' => 'css_bits[text_decoration]', 'style' => 'width: 260px;'))."</div><div><strong>{$lang->text_decoration}</strong></div>", array('style' => 'width: 40%;')); 1837 $table->construct_row(); 1838 1839 $table->output(htmlspecialchars_uni($editable_selector['class_name'])."<span id=\"saved\" style=\"color: #FEE0C6;\"></span>"); 1840 1841 echo "</div>"; 1842 1843 $buttons[] = $form->generate_reset_button($lang->reset); 1844 $buttons[] = $form->generate_submit_button($lang->save_changes, array('id' => 'save', 'name' => 'save')); 1845 $buttons[] = $form->generate_submit_button($lang->save_changes_and_close, array('id' => 'save_close', 'name' => 'save_close')); 1846 1847 $form->output_submit_wrapper($buttons); 1848 1849 echo '<script type="text/javascript" src="./jscripts/themes.js"></script>'; 1850 echo '<script type="text/javascript"> 1851 1852 Event.observe(window, "load", function() { 1853 //<![CDATA[ 1854 new ThemeSelector("./index.php?module=style-themes&action=xmlhttp_stylesheet", "./index.php?module=style-themes&action=edit_stylesheet", $("selector"), $("stylesheet"), "'.htmlspecialchars_uni($mybb->input['file']).'", $("selector_form"), "'.$mybb->input['tid'].'"); 1855 }); 1856 //]]> 1857 </script>'; 1858 1859 $form->end(); 1860 1861 $page->output_footer(); 1862 } 1863 1864 if($mybb->input['action'] == "edit_stylesheet" && $mybb->input['mode'] == "advanced") 1865 { 1866 $plugins->run_hooks("admin_style_themes_edit_stylesheet_advanced"); 1867 1868 // Fetch the theme we want to edit this stylesheet in 1869 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 1870 $theme = $db->fetch_array($query); 1871 1872 if(!$theme['tid']) 1873 { 1874 flash_message($lang->error_invalid_theme, 'error'); 1875 admin_redirect("index.php?module=style-themes"); 1876 } 1877 1878 $parent_list = make_parent_theme_list($theme['tid']); 1879 $parent_list = implode(',', $parent_list); 1880 if(!$parent_list) 1881 { 1882 $parent_list = 1; 1883 } 1884 1885 $query = $db->simple_select("themestylesheets", "*", "name='".$db->escape_string($mybb->input['file'])."' AND tid IN ({$parent_list})", array('order_by' => 'tid', 'order_dir' => 'desc', 'limit' => 1)); 1886 $stylesheet = $db->fetch_array($query); 1887 1888 // Does the theme not exist? 1889 if(!$stylesheet['sid']) 1890 { 1891 flash_message($lang->error_invalid_stylesheet, 'error'); 1892 admin_redirect("index.php?module=style-themes"); 1893 } 1894 1895 if($mybb->request_method == "post") 1896 { 1897 $sid = $stylesheet['sid']; 1898 1899 // Theme & stylesheet theme ID do not match, editing inherited - we copy to local theme 1900 if($theme['tid'] != $stylesheet['tid']) 1901 { 1902 $sid = copy_stylesheet_to_theme($stylesheet, $theme['tid']); 1903 } 1904 1905 // Now we have the new stylesheet, save it 1906 $updated_stylesheet = array( 1907 "cachefile" => $db->escape_string($stylesheet['name']), 1908 "stylesheet" => $db->escape_string(unfix_css_urls($mybb->input['stylesheet'])), 1909 "lastmodified" => TIME_NOW 1910 ); 1911 $db->update_query("themestylesheets", $updated_stylesheet, "sid='{$sid}'"); 1912 1913 // Cache the stylesheet to the file 1914 if(!cache_stylesheet($theme['tid'], $stylesheet['name'], $mybb->input['stylesheet'])) 1915 { 1916 $db->update_query("themestylesheets", array('cachefile' => "css.php?stylesheet={$sid}"), "sid='{$sid}'", 1); 1917 } 1918 1919 // Update the CSS file list for this theme 1920 update_theme_stylesheet_list($theme['tid']); 1921 1922 $plugins->run_hooks("admin_style_themes_edit_stylesheet_advanced_commit"); 1923 1924 // Log admin action 1925 log_admin_action($theme['name'], $stylesheet['name']); 1926 1927 flash_message($lang->success_stylesheet_updated, 'success'); 1928 1929 if(!$mybb->input['save_close']) 1930 { 1931 admin_redirect("index.php?module=style-themes&action=edit_stylesheet&file=".htmlspecialchars_uni($stylesheet['name'])."&tid={$theme['tid']}&mode=advanced"); 1932 } 1933 else 1934 { 1935 admin_redirect("index.php?module=style-themes&action=edit&tid={$theme['tid']}"); 1936 } 1937 } 1938 1939 // Fetch list of all of the stylesheets for this theme 1940 $file_stylesheets = unserialize($theme['stylesheets']); 1941 1942 $stylesheets = array(); 1943 $inherited_load = array(); 1944 1945 // Now we loop through the list of stylesheets for each file 1946 foreach($file_stylesheets as $file => $action_stylesheet) 1947 { 1948 if($file == 'inherited') 1949 { 1950 continue; 1951 } 1952 1953 foreach($action_stylesheet as $action => $style) 1954 { 1955 foreach($style as $stylesheet2) 1956 { 1957 $stylesheets[$stylesheet2]['applied_to'][$file][] = $action; 1958 if(is_array($file_stylesheets['inherited'][$file."_".$action]) && in_array($stylesheet2, array_keys($file_stylesheets['inherited'][$file."_".$action]))) 1959 { 1960 $stylesheets[$stylesheet2]['inherited'] = $file_stylesheets['inherited'][$file."_".$action]; 1961 foreach($file_stylesheets['inherited'][$file."_".$action] as $value) 1962 { 1963 $inherited_load[] = $value; 1964 } 1965 } 1966 } 1967 } 1968 } 1969 1970 foreach($stylesheets as $file => $stylesheet2) 1971 { 1972 if(is_array($stylesheet2['inherited'])) 1973 { 1974 foreach($stylesheet2['inherited'] as $inherited_file => $tid) 1975 { 1976 $stylesheet2['inherited'][basename($inherited_file)] = $tid; 1977 unset($stylesheet2['inherited'][$inherited_file]); 1978 } 1979 } 1980 1981 $stylesheets[basename($file)] = $stylesheet2; 1982 unset($stylesheets[$file]); 1983 } 1984 1985 $this_stylesheet = $stylesheets[$stylesheet['name']]; 1986 unset($stylesheets); 1987 1988 if($admin_options['codepress'] != 0) 1989 { 1990 $page->extra_header .= ' 1991 <link type="text/css" href="./jscripts/codepress/languages/css.css" rel="stylesheet" id="cp-lang-style" /> 1992 <script type="text/javascript" src="./jscripts/codepress/codepress.js"></script> 1993 <script type="text/javascript"> 1994 CodePress.language = \'css\'; 1995 </script>'; 1996 } 1997 1998 $page->add_breadcrumb_item(htmlspecialchars_uni($theme['name']), "index.php?module=style-themes&action=edit&tid={$mybb->input['tid']}"); 1999 $page->add_breadcrumb_item("{$lang->editing} ".htmlspecialchars_uni($stylesheet['name']), "index.php?module=style-themes&action=edit_stylesheet&tid={$mybb->input['tid']}&file=".htmlspecialchars_uni($mybb->input['file'])."&mode=advanced"); 2000 2001 $page->output_header("{$lang->themes} - {$lang->edit_stylesheet_advanced_mode}"); 2002 2003 // If the stylesheet and theme do not match, we must be editing something that is inherited 2004 if($this_stylesheet['inherited'][$stylesheet['name']]) 2005 { 2006 $query = $db->simple_select("themes", "name", "tid='{$stylesheet['tid']}'"); 2007 $stylesheet_parent = htmlspecialchars_uni($db->fetch_field($query, 'name')); 2008 2009 // Show inherited warning 2010 if($stylesheet['tid'] == 1) 2011 { 2012 $page->output_alert($lang->sprintf($lang->stylesheet_inherited_default, $stylesheet_parent)); 2013 } 2014 else 2015 { 2016 $page->output_alert($lang->sprintf($lang->stylesheet_inherited, $stylesheet_parent)); 2017 } 2018 } 2019 2020 $sub_tabs['edit_stylesheet'] = array( 2021 'title' => $lang->edit_stylesheet_simple_mode, 2022 'link' => "index.php?module=style-themes&action=edit_stylesheet&tid={$mybb->input['tid']}&file=".htmlspecialchars_uni($mybb->input['file'])."&mode=simple" 2023 ); 2024 2025 $sub_tabs['edit_stylesheet_advanced'] = array( 2026 'title' => $lang->edit_stylesheet_advanced_mode, 2027 'link' => "index.php?module=style-themes&action=edit_stylesheet&tid={$mybb->input['tid']}&file=".htmlspecialchars_uni($mybb->input['file'])."&mode=advanced", 2028 'description' => $lang->edit_stylesheet_advanced_mode_desc 2029 ); 2030 2031 $page->output_nav_tabs($sub_tabs, 'edit_stylesheet_advanced'); 2032 2033 // Has the file on the file system been modified? 2034 if(resync_stylesheet($stylesheet)) 2035 { 2036 // Need to refetch new stylesheet as it was modified 2037 $query = $db->simple_select("themestylesheets", "stylesheet", "sid='{$stylesheet['sid']}'"); 2038 $stylesheet['stylesheet'] = $db->fetch_field($query, 'stylesheet'); 2039 } 2040 2041 $form = new Form("index.php?module=style-themes&action=edit_stylesheet&mode=advanced", "post", "edit_stylesheet"); 2042 echo $form->generate_hidden_field("tid", $mybb->input['tid'])."\n"; 2043 echo $form->generate_hidden_field("file", htmlspecialchars_uni($mybb->input['file']))."\n"; 2044 2045 $table = new Table; 2046 $table->construct_cell($form->generate_text_area('stylesheet', $stylesheet['stylesheet'], array('id' => 'stylesheet', 'style' => 'width: 99%;', 'class' => 'codepress css', 'rows' => '30'))); 2047 $table->construct_row(); 2048 $table->output("{$lang->full_stylesheet_for} ".htmlspecialchars_uni($stylesheet['name'])); 2049 2050 $buttons[] = $form->generate_reset_button($lang->reset); 2051 $buttons[] = $form->generate_submit_button($lang->save_changes, array('id' => 'save', 'name' => 'save')); 2052 $buttons[] = $form->generate_submit_button($lang->save_changes_and_close, array('id' => 'save_close', 'name' => 'save_close')); 2053 2054 $form->output_submit_wrapper($buttons); 2055 2056 $form->end(); 2057 2058 if($admin_options['codepress'] != 0) 2059 { 2060 echo "<script type=\"text/javascript\"> 2061 Event.observe('edit_stylesheet', 'submit', function() 2062 { 2063 if($('stylesheet_cp')) { 2064 var area = $('stylesheet_cp'); 2065 area.id = 'stylesheet'; 2066 area.value = stylesheet.getCode(); 2067 area.disabled = false; 2068 } 2069 }); 2070 </script>"; 2071 } 2072 2073 $page->output_footer(); 2074 } 2075 2076 if($mybb->input['action'] == "delete_stylesheet") 2077 { 2078 $plugins->run_hooks("admin_style_themes_delete_stylesheet"); 2079 2080 // Fetch the theme we want to edit this stylesheet in 2081 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 2082 $theme = $db->fetch_array($query); 2083 2084 if(!$theme['tid']) 2085 { 2086 flash_message($lang->error_invalid_theme, 'error'); 2087 admin_redirect("index.php?module=style-themes"); 2088 } 2089 2090 $parent_list = make_parent_theme_list($theme['tid']); 2091 $parent_list = implode(',', $parent_list); 2092 if(!$parent_list) 2093 { 2094 $parent_list = 1; 2095 } 2096 2097 $query = $db->simple_select("themestylesheets", "*", "name='".$db->escape_string($mybb->input['file'])."' AND tid IN ({$parent_list})", array('order_by' => 'tid', 'order_dir' => 'desc', 'limit' => 1)); 2098 $stylesheet = $db->fetch_array($query); 2099 2100 // Does the theme not exist? or are we trying to delete the master? 2101 if(!$stylesheet['sid'] || $stylesheet['tid'] == 1) 2102 { 2103 flash_message($lang->error_invalid_stylesheet, 'error'); 2104 admin_redirect("index.php?module=style-themes"); 2105 } 2106 2107 // User clicked no 2108 if($mybb->input['no']) 2109 { 2110 admin_redirect("index.php?module=style-themes"); 2111 } 2112 2113 if($mybb->request_method == "post") 2114 { 2115 $db->delete_query("themestylesheets", "sid='{$stylesheet['sid']}'", 1); 2116 @unlink(MYBB_ROOT."cache/themes/theme{$theme['tid']}/{$stylesheet['cachefile']}"); 2117 2118 // Update the CSS file list for this theme 2119 update_theme_stylesheet_list($theme['tid']); 2120 2121 $plugins->run_hooks("admin_style_themes_delete_stylesheet_commit"); 2122 2123 // Log admin action 2124 log_admin_action($stylesheet['sid'], $stylesheet['name'], $theme['tid'], $theme['name']); 2125 2126 flash_message($lang->success_stylesheet_deleted, 'success'); 2127 admin_redirect("index.php?module=style-themes&action=edit&tid={$theme['tid']}"); 2128 } 2129 else 2130 { 2131 $page->output_confirm_action("index.php?module=style-themes&action=force&tid={$theme['tid']}", $lang->confirm_stylesheet_deletion); 2132 } 2133 } 2134 2135 if($mybb->input['action'] == "add_stylesheet") 2136 { 2137 $plugins->run_hooks("admin_style_themes_add_stylesheet"); 2138 2139 // Fetch the theme we want to edit this stylesheet in 2140 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 2141 $theme = $db->fetch_array($query); 2142 2143 if(!$theme['tid']) 2144 { 2145 flash_message($lang->error_invalid_theme, 'error'); 2146 admin_redirect("index.php?module=style-themes"); 2147 } 2148 2149 // Fetch list of all of the stylesheets for this theme 2150 $file_stylesheets = unserialize($theme['stylesheets']); 2151 2152 $stylesheets = array(); 2153 $inherited_load = array(); 2154 2155 // Now we loop through the list of stylesheets for each file 2156 foreach($file_stylesheets as $file => $action_stylesheet) 2157 { 2158 if($file == 'inherited') 2159 { 2160 continue; 2161 } 2162 2163 foreach($action_stylesheet as $action => $style) 2164 { 2165 foreach($style as $stylesheet2) 2166 { 2167 $stylesheets[$stylesheet2]['applied_to'][$file][] = $action; 2168 if(is_array($file_stylesheets['inherited'][$file."_".$action]) && in_array($stylesheet2, array_keys($file_stylesheets['inherited'][$file."_".$action]))) 2169 { 2170 $stylesheets[$stylesheet2]['inherited'] = $file_stylesheets['inherited'][$file."_".$action]; 2171 foreach($file_stylesheets['inherited'][$file."_".$action] as $value) 2172 { 2173 $inherited_load[] = $value; 2174 } 2175 } 2176 } 2177 } 2178 } 2179 2180 foreach($stylesheets as $file => $stylesheet2) 2181 { 2182 if(is_array($stylesheet2['inherited'])) 2183 { 2184 foreach($stylesheet2['inherited'] as $inherited_file => $tid) 2185 { 2186 $stylesheet2['inherited'][basename($inherited_file)] = $tid; 2187 unset($stylesheet2['inherited'][$inherited_file]); 2188 } 2189 } 2190 2191 $stylesheets[basename($file)] = $stylesheet2; 2192 unset($stylesheets[$file]); 2193 } 2194 2195 if($mybb->request_method == "post") 2196 { 2197 if(!$mybb->input['name'] || $mybb->input['name'] == ".css") 2198 { 2199 $errors[] = $lang->error_missing_stylesheet_name; 2200 } 2201 2202 if(substr($mybb->input['name'], -4) != ".css") 2203 { 2204 // Does not end with '.css' 2205 $errors[] = $lang->sprintf($lang->error_missing_stylesheet_extension, $mybb->input['name']); 2206 } 2207 2208 if(!$errors) 2209 { 2210 if($mybb->input['add_type'] == 1) 2211 { 2212 // Import from a current stylesheet 2213 $parent_list = make_parent_theme_list($theme['tid']); 2214 $parent_list = implode(',', $parent_list); 2215 2216 $query = $db->simple_select("themestylesheets", "stylesheet", "name='".$db->escape_string($mybb->input['import'])."' AND tid IN ({$parent_list})", array('limit' => 1, 'order_by' => 'tid', 'order_dir' => 'desc')); 2217 $stylesheet = $db->fetch_field($query, "stylesheet"); 2218 } 2219 else 2220 { 2221 // Custom stylesheet 2222 $stylesheet = $mybb->input['stylesheet']; 2223 } 2224 2225 $attached = array(); 2226 2227 if($mybb->input['attach'] == 1) 2228 { 2229 // Our stylesheet is attached to custom pages in MyBB 2230 foreach($mybb->input as $id => $value) 2231 { 2232 $actions_list = ""; 2233 $attached_to = ""; 2234 2235 if(strpos($id, 'attached_') !== false) 2236 { 2237 // We have a custom attached file 2238 $attached_id = intval(str_replace('attached_', '', $id)); 2239 $attached_to = $value; 2240 2241 if($mybb->input['action_'.$attached_id] == 1) 2242 { 2243 // We have custom actions for attached files 2244 $actions_list = $mybb->input['action_list_'.$attached_id]; 2245 } 2246 2247 if($actions_list) 2248 { 2249 $attached_to = $attached_to."?".$actions_list; 2250 } 2251 2252 $attached[] = $attached_to; 2253 } 2254 } 2255 } 2256 2257 // Add Stylesheet 2258 $insert_array = array( 2259 'name' => $db->escape_string($mybb->input['name']), 2260 'tid' => intval($mybb->input['tid']), 2261 'attachedto' => implode('|', array_map(array($db, "escape_string"), $attached)), 2262 'stylesheet' => $db->escape_string($stylesheet), 2263 'cachefile' => $db->escape_string(str_replace('/', '', $mybb->input['name'])), 2264 'lastmodified' => TIME_NOW 2265 ); 2266 2267 $sid = $db->insert_query("themestylesheets", $insert_array); 2268 2269 if(!cache_stylesheet($theme['tid'], str_replace('/', '', $mybb->input['name']), $stylesheet)) 2270 { 2271 $db->update_query("themestylesheets", array('cachefile' => "css.php?stylesheet={$sid}"), "sid='{$sid}'", 1); 2272 } 2273 2274 // Update the CSS file list for this theme 2275 update_theme_stylesheet_list($theme['tid']); 2276 2277 $plugins->run_hooks("admin_style_themes_add_stylesheet_commit"); 2278 2279 // Log admin action 2280 log_admin_action($sid, $mybb->input['name'], $theme['tid'], $theme['name']); 2281 2282 flash_message($lang->success_stylesheet_added, 'success'); 2283 admin_redirect("index.php?module=style-themes&action=edit_stylesheet&tid={$mybb->input['tid']}&sid={$sid}&file=".urlencode($mybb->input['name'])); 2284 } 2285 } 2286 2287 if($admin_options['codepress'] != 0) 2288 { 2289 $page->extra_header .= ' 2290 <link type="text/css" href="./jscripts/codepress/languages/css.css" rel="stylesheet" id="cp-lang-style" /> 2291 <script type="text/javascript" src="./jscripts/codepress/codepress.js"></script> 2292 <script type="text/javascript"> 2293 CodePress.language = \'css\'; 2294 </script>'; 2295 } 2296 2297 $page->add_breadcrumb_item(htmlspecialchars_uni($theme['name']), "index.php?module=style-themes&action=edit&tid={$mybb->input['tid']}"); 2298 $page->add_breadcrumb_item($lang->add_stylesheet); 2299 2300 $page->output_header("{$lang->themes} - {$lang->add_stylesheet}"); 2301 2302 $sub_tabs['edit_stylesheets'] = array( 2303 'title' => $lang->edit_stylesheets, 2304 'link' => "index.php?module=style-themes&action=edit&tid={$mybb->input['tid']}" 2305 ); 2306 2307 $sub_tabs['add_stylesheet'] = array( 2308 'title' => $lang->add_stylesheet, 2309 'link' => "index.php?module=style-themes&action=add_stylesheet&tid={$mybb->input['tid']}", 2310 'description' => $lang->add_stylesheet_desc 2311 ); 2312 2313 $sub_tabs['export_theme'] = array( 2314 'title' => $lang->export_theme, 2315 'link' => "index.php?module=style-themes&action=export&tid={$mybb->input['tid']}" 2316 ); 2317 2318 $page->output_nav_tabs($sub_tabs, 'add_stylesheet'); 2319 2320 if($errors) 2321 { 2322 $page->output_inline_error($errors); 2323 2324 foreach($mybb->input as $name => $value) 2325 { 2326 if(strpos($name, "attached") !== false) 2327 { 2328 list(, $id) = explode('_', $name); 2329 $id = intval($id); 2330 2331 $mybb->input['applied_to'][$value] = array(0 => 'global'); 2332 2333 if($mybb->input['action_'.$id] == 1) 2334 { 2335 $mybb->input['applied_to'][$value] = explode(',', $mybb->input['action_list_'.$id]); 2336 } 2337 } 2338 } 2339 2340 if($mybb->input['add_type'] == 1) 2341 { 2342 $add_checked[1] = "checked=\"checked\""; 2343 $add_checked[2] = ""; 2344 } 2345 else 2346 { 2347 $add_checked[2] = "checked=\"checked\""; 2348 $add_checked[1] = ""; 2349 } 2350 } 2351 else 2352 { 2353 $mybb->input['name'] = $stylesheet['name']; 2354 } 2355 2356 $form = new Form("index.php?module=style-themes&action=add_stylesheet", "post", "add_stylesheet"); 2357 2358 echo $form->generate_hidden_field("tid", $mybb->input['tid'])."\n"; 2359 2360 $specific_files = "<div id=\"attach_1\" class=\"attachs\">"; 2361 $count = 0; 2362 2363 if(is_array($mybb->input['applied_to']) && $mybb->input['applied_to']['global'][0] != "global") 2364 { 2365 $check_actions = ""; 2366 2367 $global_checked[2] = "checked=\"checked\""; 2368 $global_checked[1] = ""; 2369 2370 foreach($mybb->input['applied_to'] as $name => $actions) 2371 { 2372 $short_name = substr($name, 0, -4); 2373 2374 $action_list = ""; 2375 if($actions[0] != "global") 2376 { 2377 $action_list = implode(',', $actions); 2378 } 2379 2380 if($actions[0] == "global") 2381 { 2382 $global_action_checked[1] = "checked=\"checked\""; 2383 $global_action_checked[2] = ""; 2384 } 2385 else 2386 { 2387 $global_action_checked[2] = "checked=\"checked\""; 2388 $global_action_checked[1] = ""; 2389 } 2390 2391 $specific_file = "<dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\"> 2392 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"action_{$count}\" value=\"0\" {$global_action_checked[1]} class=\"action_{$count}s_check\" onclick=\"checkAction('action_{$count}');\" style=\"vertical-align: middle;\" /> {$lang->globally}</label></dt> 2393 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"action_{$count}\" value=\"1\" {$global_action_checked[2]} class=\"action_{$count}s_check\" onclick=\"checkAction('action_{$count}');\" style=\"vertical-align: middle;\" /> {$lang->specific_actions}</label></dt> 2394 <dd style=\"margin-top: 4px;\" id=\"action_{$count}_1\" class=\"action_{$count}s\"> 2395 <small class=\"description\">{$lang->specific_actions_desc}</small> 2396 <table cellpadding=\"4\"> 2397 <tr> 2398 <td>".$form->generate_text_box('action_list_'.$count, $action_list, array('id' => 'action_list_'.$count, 'style' => 'width: 190px;'))."</td> 2399 </tr> 2400 </table> 2401 </dd> 2402 </dl>"; 2403 2404 $form_container = new FormContainer(); 2405 $form_container->output_row("", "", "<span style=\"float: right;\"><a href=\"\" id=\"delete_img_{$count}\"><img src=\"styles/{$page->style}/images/icons/cross.gif\" alt=\"{$lang->delete}\" title=\"{$lang->delete}\" /></a></span>{$lang->file} ".$form->generate_text_box("attached_{$count}", $name, array('id' => "attached_{$count}", 'style' => 'width: 200px;')), "attached_{$count}"); 2406 2407 $form_container->output_row("", "", $specific_file); 2408 2409 $specific_files .= "<div id=\"attached_form_{$count}\">".$form_container->end(true)."</div><div id=\"attach_box_{$count}\"></div>"; 2410 2411 $check_actions .= "\n\tcheckAction('action_{$count}');"; 2412 2413 ++$count; 2414 } 2415 } 2416 else 2417 { 2418 $global_checked[1] = "checked=\"checked\""; 2419 $global_checked[2] = ""; 2420 } 2421 2422 $actions = '<script type="text/javascript"> 2423 function checkAction(id) 2424 { 2425 var checked = \'\'; 2426 2427 $$(\'.\'+id+\'s_check\').each(function(e) 2428 { 2429 if(e.checked == true) 2430 { 2431 checked = e.value; 2432 } 2433 }); 2434 $$(\'.\'+id+\'s\').each(function(e) 2435 { 2436 Element.hide(e); 2437 }); 2438 if($(id+\'_\'+checked)) 2439 { 2440 Element.show(id+\'_\'+checked); 2441 } 2442 } 2443 </script> 2444 <dl style="margin-top: 0; margin-bottom: 0; width: 40%;"> 2445 <dt><label style="display: block;"><input type="radio" name="attach" value="0" '.$global_checked[1].' class="attachs_check" onclick="checkAction(\'attach\');" style="vertical-align: middle;" /> '.$lang->globally.'</label></dt> 2446 <dt><label style="display: block;"><input type="radio" name="attach" value="1" '.$global_checked[2].' class="attachs_check" onclick="checkAction(\'attach\');" style="vertical-align: middle;" /> '.$lang->specific_files.' (<a id="new_specific_file">'.$lang->add_another.'</a>)</label></dt><br /> 2447 '.$specific_files.' 2448 </dl> 2449 <script type="text/javascript"> 2450 checkAction(\'attach\');'.$check_actions.' 2451 </script>'; 2452 2453 echo $form->generate_hidden_field("sid", $stylesheet['sid'])."<br />\n"; 2454 2455 $form_container = new FormContainer("{$lang->add_stylesheet_to} ".htmlspecialchars_uni($theme['name'])); 2456 $form_container->output_row($lang->file_name, $lang->file_name_desc, $form->generate_text_box('name', $mybb->input['name'], array('id' => 'name', 'style' => 'width: 200px;')), 'name'); 2457 2458 $form_container->output_row($lang->attached_to, $lang->attached_to_desc, $actions); 2459 2460 $sheetnames = array(); 2461 foreach($stylesheets as $filename => $style) 2462 { 2463 $sheetnames[basename($filename)] = basename($filename); 2464 } 2465 2466 $actions = "<dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\"> 2467 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"add_type\" value=\"1\" {$add_checked[1]} class=\"adds_check\" onclick=\"checkAction('add');\" style=\"vertical-align: middle;\" /> <strong>{$lang->import_stylesheet_from}</strong></label></dt> 2468 <dd style=\"margin-top: 4px;\" id=\"add_1\" class=\"adds\"> 2469 <table cellpadding=\"4\"> 2470 <tr> 2471 <td>".$form->generate_select_box('import', $sheetnames, $mybb->input['import'], array('id' => 'import'))."</td> 2472 </tr> 2473 </table> 2474 </dd> 2475 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"add_type\" value=\"2\" {$add_checked[2]} class=\"adds_check\" onclick=\"checkAction('add');\" style=\"vertical-align: middle;\" /> <strong>{$lang->write_own}</strong></label></dt> 2476 <span id=\"add_2\" class=\"adds\"><br />".$form->generate_text_area('stylesheet', $mybb->input['stylesheet'], array('id' => 'stylesheet', 'style' => 'width: 99%;', 'class' => 'codepress css', 'rows' => '30'))."</span> 2477 </dl>"; 2478 2479 $form_container->output_row("", "", $actions); 2480 2481 $form_container->end(); 2482 2483 $buttons[] = $form->generate_submit_button($lang->save_stylesheet); 2484 2485 $form->output_submit_wrapper($buttons); 2486 2487 if($admin_options['codepress'] != 0) 2488 { 2489 echo "<script type=\"text/javascript\"> 2490 Event.observe('add_stylesheet', 'submit', function() 2491 { 2492 if($('stylesheet_cp')) { 2493 var area = $('stylesheet_cp'); 2494 area.id = 'stylesheet'; 2495 area.value = stylesheet.getCode(); 2496 area.disabled = false; 2497 } 2498 }); 2499 </script>\n"; 2500 } 2501 2502 echo '<script type="text/javascript" src="./jscripts/themes.js"></script>'; 2503 echo '<script type="text/javascript"> 2504 Event.observe(window, "load", function() { 2505 //<![CDATA[ 2506 new ThemeSelector(\''.$count.'\'); 2507 checkAction(\'add\'); 2508 }); 2509 //]]> 2510 </script>'; 2511 2512 $form->end(); 2513 2514 $page->output_footer(); 2515 } 2516 2517 if($mybb->input['action'] == "set_default") 2518 { 2519 $plugins->run_hooks("admin_style_themes_set_default"); 2520 2521 if(!verify_post_check($mybb->input['my_post_key'])) 2522 { 2523 flash_message($lang->invalid_post_verify_key2, 'error'); 2524 admin_redirect("index.php?module=style-themes"); 2525 } 2526 2527 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 2528 $theme = $db->fetch_array($query); 2529 2530 // Does the theme not exist? 2531 if(!$theme['tid']) 2532 { 2533 flash_message($lang->error_invalid_theme, 'error'); 2534 admin_redirect("index.php?module=style-themes"); 2535 } 2536 2537 $db->update_query("themes", array('def' => 0)); 2538 $db->update_query("themes", array('def' => 1), "tid='".intval($mybb->input['tid'])."'"); 2539 2540 $plugins->run_hooks("admin_style_themes_set_default_commit"); 2541 2542 // Log admin action 2543 log_admin_action($theme['tid'], $theme['name']); 2544 2545 flash_message($lang->success_theme_set_default, 'success'); 2546 admin_redirect("index.php?module=style-themes"); 2547 } 2548 2549 if($mybb->input['action'] == "force") 2550 { 2551 $plugins->run_hooks("admin_style_themes_force"); 2552 2553 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 2554 $theme = $db->fetch_array($query); 2555 2556 // Does the theme not exist? 2557 if(!$theme['tid']) 2558 { 2559 flash_message($lang->error_invalid_theme, 'error'); 2560 admin_redirect("index.php?module=style-themes"); 2561 } 2562 2563 // User clicked no 2564 if($mybb->input['no']) 2565 { 2566 admin_redirect("index.php?module=style-themes"); 2567 } 2568 2569 if($mybb->request_method == "post") 2570 { 2571 $updated_users = array( 2572 "style" => $theme['tid'] 2573 ); 2574 2575 $db->update_query("users", $updated_users); 2576 2577 $plugins->run_hooks("admin_style_themes_force_commit"); 2578 2579 // Log admin action 2580 log_admin_action($theme['tid'], $theme['name']); 2581 2582 flash_message($lang->success_theme_forced, 'success'); 2583 admin_redirect("index.php?module=style-themes"); 2584 } 2585 else 2586 { 2587 $page->output_confirm_action("index.php?module=style-themes&action=force&tid={$theme['tid']}", $lang->confirm_theme_forced); 2588 } 2589 } 2590 2591 if(!$mybb->input['action']) 2592 { 2593 $plugins->run_hooks("admin_style_themes_start"); 2594 2595 $page->output_header($lang->themes); 2596 2597 $page->output_nav_tabs($sub_tabs, 'themes'); 2598 2599 $table = new Table; 2600 $table->construct_header($lang->theme); 2601 $table->construct_header($lang->num_users, array("class" => "align_center", "width" => 100)); 2602 $table->construct_header($lang->controls, array("class" => "align_center", "width" => 150)); 2603 2604 build_theme_list(); 2605 2606 $table->output($lang->themes); 2607 2608 $page->output_footer(); 2609 } 2610 2611 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Mar 31 17:55:03 2012 | Cross-referenced by PHPXref 0.7.1 |