[ Index ] |
PHP Cross Reference of MyBB |
[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$ 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'] || $theme['tid'] == 1) 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(!is_array($tree) || !isset($tree['results'])) 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'], htmlspecialchars_uni($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(htmlspecialchars_uni($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'], htmlspecialchars_uni($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'] || $theme['tid'] == 1) 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'], htmlspecialchars_uni($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(!isset($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(isset($applied_to_count) && $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']) && (!isset($style['applied_to']['global']) || $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'] || $theme['tid'] == 1) 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'], htmlspecialchars_uni($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" && (!isset($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'] || $theme['tid'] == 1) 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(htmlspecialchars_uni($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 foreach(array('background', 'color', 'width', 'font-family', 'font-size', 'font-style', 'font-weight', 'text-decoration') as $_p) 1815 { 1816 if(!isset($properties[$_p])) 1817 { 1818 $properties[$_p] = ''; 1819 } 1820 } 1821 1822 $form = new Form("index.php?module=style-themes&action=edit_stylesheet", "post"); 1823 echo $form->generate_hidden_field("tid", $mybb->input['tid'], array('id' => "tid"))."\n"; 1824 echo $form->generate_hidden_field("file", htmlspecialchars_uni($mybb->input['file']), array('id' => "file"))."\n"; 1825 echo $form->generate_hidden_field("selector", htmlspecialchars_uni($selector), array('id' => 'hidden_selector'))."\n"; 1826 1827 echo "<div id=\"stylesheet\">"; 1828 $table = new Table; 1829 $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%;')); 1830 $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)); 1831 $table->construct_row(); 1832 $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%;')); 1833 $table->construct_row(); 1834 $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%;')); 1835 $table->construct_row(); 1836 $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%;')); 1837 $table->construct_row(); 1838 $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%;')); 1839 $table->construct_row(); 1840 $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%;')); 1841 $table->construct_row(); 1842 $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%;')); 1843 $table->construct_row(); 1844 $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%;')); 1845 $table->construct_row(); 1846 1847 $table->output(htmlspecialchars_uni($editable_selector['class_name'])."<span id=\"saved\" style=\"color: #FEE0C6;\"></span>"); 1848 1849 echo "</div>"; 1850 1851 $buttons[] = $form->generate_reset_button($lang->reset); 1852 $buttons[] = $form->generate_submit_button($lang->save_changes, array('id' => 'save', 'name' => 'save')); 1853 $buttons[] = $form->generate_submit_button($lang->save_changes_and_close, array('id' => 'save_close', 'name' => 'save_close')); 1854 1855 $form->output_submit_wrapper($buttons); 1856 1857 echo '<script type="text/javascript" src="./jscripts/themes.js"></script>'; 1858 echo '<script type="text/javascript"> 1859 1860 Event.observe(window, "load", function() { 1861 //<![CDATA[ 1862 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'].'"); 1863 }); 1864 //]]> 1865 </script>'; 1866 1867 $form->end(); 1868 1869 $page->output_footer(); 1870 } 1871 1872 if($mybb->input['action'] == "edit_stylesheet" && $mybb->input['mode'] == "advanced") 1873 { 1874 $plugins->run_hooks("admin_style_themes_edit_stylesheet_advanced"); 1875 1876 // Fetch the theme we want to edit this stylesheet in 1877 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 1878 $theme = $db->fetch_array($query); 1879 1880 if(!$theme['tid'] || $theme['tid'] == 1) 1881 { 1882 flash_message($lang->error_invalid_theme, 'error'); 1883 admin_redirect("index.php?module=style-themes"); 1884 } 1885 1886 $parent_list = make_parent_theme_list($theme['tid']); 1887 $parent_list = implode(',', $parent_list); 1888 if(!$parent_list) 1889 { 1890 $parent_list = 1; 1891 } 1892 1893 $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)); 1894 $stylesheet = $db->fetch_array($query); 1895 1896 // Does the theme not exist? 1897 if(!$stylesheet['sid']) 1898 { 1899 flash_message($lang->error_invalid_stylesheet, 'error'); 1900 admin_redirect("index.php?module=style-themes"); 1901 } 1902 1903 if($mybb->request_method == "post") 1904 { 1905 $sid = $stylesheet['sid']; 1906 1907 // Theme & stylesheet theme ID do not match, editing inherited - we copy to local theme 1908 if($theme['tid'] != $stylesheet['tid']) 1909 { 1910 $sid = copy_stylesheet_to_theme($stylesheet, $theme['tid']); 1911 } 1912 1913 // Now we have the new stylesheet, save it 1914 $updated_stylesheet = array( 1915 "cachefile" => $db->escape_string($stylesheet['name']), 1916 "stylesheet" => $db->escape_string(unfix_css_urls($mybb->input['stylesheet'])), 1917 "lastmodified" => TIME_NOW 1918 ); 1919 $db->update_query("themestylesheets", $updated_stylesheet, "sid='{$sid}'"); 1920 1921 // Cache the stylesheet to the file 1922 if(!cache_stylesheet($theme['tid'], $stylesheet['name'], $mybb->input['stylesheet'])) 1923 { 1924 $db->update_query("themestylesheets", array('cachefile' => "css.php?stylesheet={$sid}"), "sid='{$sid}'", 1); 1925 } 1926 1927 // Update the CSS file list for this theme 1928 update_theme_stylesheet_list($theme['tid']); 1929 1930 $plugins->run_hooks("admin_style_themes_edit_stylesheet_advanced_commit"); 1931 1932 // Log admin action 1933 log_admin_action(htmlspecialchars_uni($theme['name']), $stylesheet['name']); 1934 1935 flash_message($lang->success_stylesheet_updated, 'success'); 1936 1937 if(!$mybb->input['save_close']) 1938 { 1939 admin_redirect("index.php?module=style-themes&action=edit_stylesheet&file=".htmlspecialchars_uni($stylesheet['name'])."&tid={$theme['tid']}&mode=advanced"); 1940 } 1941 else 1942 { 1943 admin_redirect("index.php?module=style-themes&action=edit&tid={$theme['tid']}"); 1944 } 1945 } 1946 1947 // Fetch list of all of the stylesheets for this theme 1948 $file_stylesheets = unserialize($theme['stylesheets']); 1949 1950 $stylesheets = array(); 1951 $inherited_load = array(); 1952 1953 // Now we loop through the list of stylesheets for each file 1954 foreach($file_stylesheets as $file => $action_stylesheet) 1955 { 1956 if($file == 'inherited') 1957 { 1958 continue; 1959 } 1960 1961 foreach($action_stylesheet as $action => $style) 1962 { 1963 foreach($style as $stylesheet2) 1964 { 1965 $stylesheets[$stylesheet2]['applied_to'][$file][] = $action; 1966 if(is_array($file_stylesheets['inherited'][$file."_".$action]) && in_array($stylesheet2, array_keys($file_stylesheets['inherited'][$file."_".$action]))) 1967 { 1968 $stylesheets[$stylesheet2]['inherited'] = $file_stylesheets['inherited'][$file."_".$action]; 1969 foreach($file_stylesheets['inherited'][$file."_".$action] as $value) 1970 { 1971 $inherited_load[] = $value; 1972 } 1973 } 1974 } 1975 } 1976 } 1977 1978 foreach($stylesheets as $file => $stylesheet2) 1979 { 1980 if(is_array($stylesheet2['inherited'])) 1981 { 1982 foreach($stylesheet2['inherited'] as $inherited_file => $tid) 1983 { 1984 $stylesheet2['inherited'][basename($inherited_file)] = $tid; 1985 unset($stylesheet2['inherited'][$inherited_file]); 1986 } 1987 } 1988 1989 $stylesheets[basename($file)] = $stylesheet2; 1990 unset($stylesheets[$file]); 1991 } 1992 1993 $this_stylesheet = $stylesheets[$stylesheet['name']]; 1994 unset($stylesheets); 1995 1996 if($admin_options['codepress'] != 0) 1997 { 1998 $page->extra_header .= ' 1999 <link type="text/css" href="./jscripts/codepress/languages/css.css" rel="stylesheet" id="cp-lang-style" /> 2000 <script type="text/javascript" src="./jscripts/codepress/codepress.js"></script> 2001 <script type="text/javascript"> 2002 CodePress.language = \'css\'; 2003 </script>'; 2004 } 2005 2006 $page->add_breadcrumb_item(htmlspecialchars_uni($theme['name']), "index.php?module=style-themes&action=edit&tid={$mybb->input['tid']}"); 2007 $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"); 2008 2009 $page->output_header("{$lang->themes} - {$lang->edit_stylesheet_advanced_mode}"); 2010 2011 // If the stylesheet and theme do not match, we must be editing something that is inherited 2012 if($this_stylesheet['inherited'][$stylesheet['name']]) 2013 { 2014 $query = $db->simple_select("themes", "name", "tid='{$stylesheet['tid']}'"); 2015 $stylesheet_parent = htmlspecialchars_uni($db->fetch_field($query, 'name')); 2016 2017 // Show inherited warning 2018 if($stylesheet['tid'] == 1) 2019 { 2020 $page->output_alert($lang->sprintf($lang->stylesheet_inherited_default, $stylesheet_parent)); 2021 } 2022 else 2023 { 2024 $page->output_alert($lang->sprintf($lang->stylesheet_inherited, $stylesheet_parent)); 2025 } 2026 } 2027 2028 $sub_tabs['edit_stylesheet'] = array( 2029 'title' => $lang->edit_stylesheet_simple_mode, 2030 'link' => "index.php?module=style-themes&action=edit_stylesheet&tid={$mybb->input['tid']}&file=".htmlspecialchars_uni($mybb->input['file'])."&mode=simple" 2031 ); 2032 2033 $sub_tabs['edit_stylesheet_advanced'] = array( 2034 'title' => $lang->edit_stylesheet_advanced_mode, 2035 'link' => "index.php?module=style-themes&action=edit_stylesheet&tid={$mybb->input['tid']}&file=".htmlspecialchars_uni($mybb->input['file'])."&mode=advanced", 2036 'description' => $lang->edit_stylesheet_advanced_mode_desc 2037 ); 2038 2039 $page->output_nav_tabs($sub_tabs, 'edit_stylesheet_advanced'); 2040 2041 // Has the file on the file system been modified? 2042 if(resync_stylesheet($stylesheet)) 2043 { 2044 // Need to refetch new stylesheet as it was modified 2045 $query = $db->simple_select("themestylesheets", "stylesheet", "sid='{$stylesheet['sid']}'"); 2046 $stylesheet['stylesheet'] = $db->fetch_field($query, 'stylesheet'); 2047 } 2048 2049 $form = new Form("index.php?module=style-themes&action=edit_stylesheet&mode=advanced", "post", "edit_stylesheet"); 2050 echo $form->generate_hidden_field("tid", $mybb->input['tid'])."\n"; 2051 echo $form->generate_hidden_field("file", htmlspecialchars_uni($mybb->input['file']))."\n"; 2052 2053 $table = new Table; 2054 $table->construct_cell($form->generate_text_area('stylesheet', $stylesheet['stylesheet'], array('id' => 'stylesheet', 'style' => 'width: 99%;', 'class' => 'codepress css', 'rows' => '30'))); 2055 $table->construct_row(); 2056 $table->output("{$lang->full_stylesheet_for} ".htmlspecialchars_uni($stylesheet['name'])); 2057 2058 $buttons[] = $form->generate_reset_button($lang->reset); 2059 $buttons[] = $form->generate_submit_button($lang->save_changes, array('id' => 'save', 'name' => 'save')); 2060 $buttons[] = $form->generate_submit_button($lang->save_changes_and_close, array('id' => 'save_close', 'name' => 'save_close')); 2061 2062 $form->output_submit_wrapper($buttons); 2063 2064 $form->end(); 2065 2066 if($admin_options['codepress'] != 0) 2067 { 2068 echo "<script type=\"text/javascript\"> 2069 Event.observe('edit_stylesheet', 'submit', function() 2070 { 2071 if($('stylesheet_cp')) { 2072 var area = $('stylesheet_cp'); 2073 area.id = 'stylesheet'; 2074 area.value = stylesheet.getCode(); 2075 area.disabled = false; 2076 } 2077 }); 2078 </script>"; 2079 } 2080 2081 $page->output_footer(); 2082 } 2083 2084 if($mybb->input['action'] == "delete_stylesheet") 2085 { 2086 $plugins->run_hooks("admin_style_themes_delete_stylesheet"); 2087 2088 // Fetch the theme we want to edit this stylesheet in 2089 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 2090 $theme = $db->fetch_array($query); 2091 2092 if(!$theme['tid'] || $theme['tid'] == 1) 2093 { 2094 flash_message($lang->error_invalid_theme, 'error'); 2095 admin_redirect("index.php?module=style-themes"); 2096 } 2097 2098 $parent_list = make_parent_theme_list($theme['tid']); 2099 $parent_list = implode(',', $parent_list); 2100 if(!$parent_list) 2101 { 2102 $parent_list = 1; 2103 } 2104 2105 $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)); 2106 $stylesheet = $db->fetch_array($query); 2107 2108 // Does the theme not exist? or are we trying to delete the master? 2109 if(!$stylesheet['sid'] || $stylesheet['tid'] == 1) 2110 { 2111 flash_message($lang->error_invalid_stylesheet, 'error'); 2112 admin_redirect("index.php?module=style-themes"); 2113 } 2114 2115 // User clicked no 2116 if($mybb->input['no']) 2117 { 2118 admin_redirect("index.php?module=style-themes"); 2119 } 2120 2121 if($mybb->request_method == "post") 2122 { 2123 $db->delete_query("themestylesheets", "sid='{$stylesheet['sid']}'", 1); 2124 @unlink(MYBB_ROOT."cache/themes/theme{$theme['tid']}/{$stylesheet['cachefile']}"); 2125 2126 // Update the CSS file list for this theme 2127 update_theme_stylesheet_list($theme['tid']); 2128 2129 $plugins->run_hooks("admin_style_themes_delete_stylesheet_commit"); 2130 2131 // Log admin action 2132 log_admin_action($stylesheet['sid'], $stylesheet['name'], $theme['tid'], htmlspecialchars_uni($theme['name'])); 2133 2134 flash_message($lang->success_stylesheet_deleted, 'success'); 2135 admin_redirect("index.php?module=style-themes&action=edit&tid={$theme['tid']}"); 2136 } 2137 else 2138 { 2139 $page->output_confirm_action("index.php?module=style-themes&action=force&tid={$theme['tid']}", $lang->confirm_stylesheet_deletion); 2140 } 2141 } 2142 2143 if($mybb->input['action'] == "add_stylesheet") 2144 { 2145 $plugins->run_hooks("admin_style_themes_add_stylesheet"); 2146 2147 // Fetch the theme we want to edit this stylesheet in 2148 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 2149 $theme = $db->fetch_array($query); 2150 2151 if(!$theme['tid'] || $theme['tid'] == 1) 2152 { 2153 flash_message($lang->error_invalid_theme, 'error'); 2154 admin_redirect("index.php?module=style-themes"); 2155 } 2156 2157 // Fetch list of all of the stylesheets for this theme 2158 $file_stylesheets = unserialize($theme['stylesheets']); 2159 2160 $stylesheets = array(); 2161 $inherited_load = array(); 2162 2163 // Now we loop through the list of stylesheets for each file 2164 foreach($file_stylesheets as $file => $action_stylesheet) 2165 { 2166 if($file == 'inherited') 2167 { 2168 continue; 2169 } 2170 2171 foreach($action_stylesheet as $action => $style) 2172 { 2173 foreach($style as $stylesheet2) 2174 { 2175 $stylesheets[$stylesheet2]['applied_to'][$file][] = $action; 2176 if(is_array($file_stylesheets['inherited'][$file."_".$action]) && in_array($stylesheet2, array_keys($file_stylesheets['inherited'][$file."_".$action]))) 2177 { 2178 $stylesheets[$stylesheet2]['inherited'] = $file_stylesheets['inherited'][$file."_".$action]; 2179 foreach($file_stylesheets['inherited'][$file."_".$action] as $value) 2180 { 2181 $inherited_load[] = $value; 2182 } 2183 } 2184 } 2185 } 2186 } 2187 2188 foreach($stylesheets as $file => $stylesheet2) 2189 { 2190 if(is_array($stylesheet2['inherited'])) 2191 { 2192 foreach($stylesheet2['inherited'] as $inherited_file => $tid) 2193 { 2194 $stylesheet2['inherited'][basename($inherited_file)] = $tid; 2195 unset($stylesheet2['inherited'][$inherited_file]); 2196 } 2197 } 2198 2199 $stylesheets[basename($file)] = $stylesheet2; 2200 unset($stylesheets[$file]); 2201 } 2202 2203 if($mybb->request_method == "post") 2204 { 2205 // Remove special characters 2206 $mybb->input['name'] = preg_replace('#([^a-z0-9-_\.]+)#i', '', $mybb->input['name']); 2207 if(!$mybb->input['name'] || $mybb->input['name'] == ".css") 2208 { 2209 $errors[] = $lang->error_missing_stylesheet_name; 2210 } 2211 2212 if(substr($mybb->input['name'], -4) != ".css") 2213 { 2214 // Does not end with '.css' 2215 $errors[] = $lang->sprintf($lang->error_missing_stylesheet_extension, $mybb->input['name']); 2216 } 2217 2218 if(!$errors) 2219 { 2220 if($mybb->input['add_type'] == 1) 2221 { 2222 // Import from a current stylesheet 2223 $parent_list = make_parent_theme_list($theme['tid']); 2224 $parent_list = implode(',', $parent_list); 2225 2226 $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')); 2227 $stylesheet = $db->fetch_field($query, "stylesheet"); 2228 } 2229 else 2230 { 2231 // Custom stylesheet 2232 $stylesheet = $mybb->input['stylesheet']; 2233 } 2234 2235 $attached = array(); 2236 2237 if($mybb->input['attach'] == 1) 2238 { 2239 // Our stylesheet is attached to custom pages in MyBB 2240 foreach($mybb->input as $id => $value) 2241 { 2242 $actions_list = ""; 2243 $attached_to = ""; 2244 2245 if(strpos($id, 'attached_') !== false) 2246 { 2247 // We have a custom attached file 2248 $attached_id = intval(str_replace('attached_', '', $id)); 2249 $attached_to = $value; 2250 2251 if($mybb->input['action_'.$attached_id] == 1) 2252 { 2253 // We have custom actions for attached files 2254 $actions_list = $mybb->input['action_list_'.$attached_id]; 2255 } 2256 2257 if($actions_list) 2258 { 2259 $attached_to = $attached_to."?".$actions_list; 2260 } 2261 2262 $attached[] = $attached_to; 2263 } 2264 } 2265 } 2266 2267 // Add Stylesheet 2268 $insert_array = array( 2269 'name' => $db->escape_string($mybb->input['name']), 2270 'tid' => intval($mybb->input['tid']), 2271 'attachedto' => implode('|', array_map(array($db, "escape_string"), $attached)), 2272 'stylesheet' => $db->escape_string($stylesheet), 2273 'cachefile' => $db->escape_string(str_replace('/', '', $mybb->input['name'])), 2274 'lastmodified' => TIME_NOW 2275 ); 2276 2277 $sid = $db->insert_query("themestylesheets", $insert_array); 2278 2279 if(!cache_stylesheet($theme['tid'], str_replace('/', '', $mybb->input['name']), $stylesheet)) 2280 { 2281 $db->update_query("themestylesheets", array('cachefile' => "css.php?stylesheet={$sid}"), "sid='{$sid}'", 1); 2282 } 2283 2284 // Update the CSS file list for this theme 2285 update_theme_stylesheet_list($theme['tid']); 2286 2287 $plugins->run_hooks("admin_style_themes_add_stylesheet_commit"); 2288 2289 // Log admin action 2290 log_admin_action($sid, $mybb->input['name'], $theme['tid'], htmlspecialchars_uni($theme['name'])); 2291 2292 flash_message($lang->success_stylesheet_added, 'success'); 2293 admin_redirect("index.php?module=style-themes&action=edit_stylesheet&tid={$mybb->input['tid']}&sid={$sid}&file=".urlencode($mybb->input['name'])); 2294 } 2295 } 2296 2297 if($admin_options['codepress'] != 0) 2298 { 2299 $page->extra_header .= ' 2300 <link type="text/css" href="./jscripts/codepress/languages/css.css" rel="stylesheet" id="cp-lang-style" /> 2301 <script type="text/javascript" src="./jscripts/codepress/codepress.js"></script> 2302 <script type="text/javascript"> 2303 CodePress.language = \'css\'; 2304 </script>'; 2305 } 2306 2307 $page->add_breadcrumb_item(htmlspecialchars_uni($theme['name']), "index.php?module=style-themes&action=edit&tid={$mybb->input['tid']}"); 2308 $page->add_breadcrumb_item($lang->add_stylesheet); 2309 2310 $page->output_header("{$lang->themes} - {$lang->add_stylesheet}"); 2311 2312 $sub_tabs['edit_stylesheets'] = array( 2313 'title' => $lang->edit_stylesheets, 2314 'link' => "index.php?module=style-themes&action=edit&tid={$mybb->input['tid']}" 2315 ); 2316 2317 $sub_tabs['add_stylesheet'] = array( 2318 'title' => $lang->add_stylesheet, 2319 'link' => "index.php?module=style-themes&action=add_stylesheet&tid={$mybb->input['tid']}", 2320 'description' => $lang->add_stylesheet_desc 2321 ); 2322 2323 $sub_tabs['export_theme'] = array( 2324 'title' => $lang->export_theme, 2325 'link' => "index.php?module=style-themes&action=export&tid={$mybb->input['tid']}" 2326 ); 2327 2328 $page->output_nav_tabs($sub_tabs, 'add_stylesheet'); 2329 2330 if($errors) 2331 { 2332 $page->output_inline_error($errors); 2333 2334 foreach($mybb->input as $name => $value) 2335 { 2336 if(strpos($name, "attached") !== false) 2337 { 2338 list(, $id) = explode('_', $name); 2339 $id = intval($id); 2340 2341 $mybb->input['applied_to'][$value] = array(0 => 'global'); 2342 2343 if($mybb->input['action_'.$id] == 1) 2344 { 2345 $mybb->input['applied_to'][$value] = explode(',', $mybb->input['action_list_'.$id]); 2346 } 2347 } 2348 } 2349 2350 if($mybb->input['add_type'] == 1) 2351 { 2352 $add_checked[1] = "checked=\"checked\""; 2353 $add_checked[2] = ""; 2354 } 2355 else 2356 { 2357 $add_checked[2] = "checked=\"checked\""; 2358 $add_checked[1] = ""; 2359 } 2360 } 2361 else 2362 { 2363 $mybb->input['name'] = $stylesheet['name']; 2364 } 2365 2366 $form = new Form("index.php?module=style-themes&action=add_stylesheet", "post", "add_stylesheet"); 2367 2368 echo $form->generate_hidden_field("tid", $mybb->input['tid'])."\n"; 2369 2370 $specific_files = "<div id=\"attach_1\" class=\"attachs\">"; 2371 $count = 0; 2372 2373 if(is_array($mybb->input['applied_to']) && (!isset($mybb->input['applied_to']['global']) || $mybb->input['applied_to']['global'][0] != "global")) 2374 { 2375 $check_actions = ""; 2376 2377 $global_checked[2] = "checked=\"checked\""; 2378 $global_checked[1] = ""; 2379 2380 foreach($mybb->input['applied_to'] as $name => $actions) 2381 { 2382 $short_name = substr($name, 0, -4); 2383 2384 $action_list = ""; 2385 if($actions[0] != "global") 2386 { 2387 $action_list = implode(',', $actions); 2388 } 2389 2390 if($actions[0] == "global") 2391 { 2392 $global_action_checked[1] = "checked=\"checked\""; 2393 $global_action_checked[2] = ""; 2394 } 2395 else 2396 { 2397 $global_action_checked[2] = "checked=\"checked\""; 2398 $global_action_checked[1] = ""; 2399 } 2400 2401 $specific_file = "<dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\"> 2402 <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> 2403 <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> 2404 <dd style=\"margin-top: 4px;\" id=\"action_{$count}_1\" class=\"action_{$count}s\"> 2405 <small class=\"description\">{$lang->specific_actions_desc}</small> 2406 <table cellpadding=\"4\"> 2407 <tr> 2408 <td>".$form->generate_text_box('action_list_'.$count, $action_list, array('id' => 'action_list_'.$count, 'style' => 'width: 190px;'))."</td> 2409 </tr> 2410 </table> 2411 </dd> 2412 </dl>"; 2413 2414 $form_container = new FormContainer(); 2415 $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}"); 2416 2417 $form_container->output_row("", "", $specific_file); 2418 2419 $specific_files .= "<div id=\"attached_form_{$count}\">".$form_container->end(true)."</div><div id=\"attach_box_{$count}\"></div>"; 2420 2421 $check_actions .= "\n\tcheckAction('action_{$count}');"; 2422 2423 ++$count; 2424 } 2425 } 2426 else 2427 { 2428 $global_checked[1] = "checked=\"checked\""; 2429 $global_checked[2] = ""; 2430 } 2431 2432 $actions = '<script type="text/javascript"> 2433 function checkAction(id) 2434 { 2435 var checked = \'\'; 2436 2437 $$(\'.\'+id+\'s_check\').each(function(e) 2438 { 2439 if(e.checked == true) 2440 { 2441 checked = e.value; 2442 } 2443 }); 2444 $$(\'.\'+id+\'s\').each(function(e) 2445 { 2446 Element.hide(e); 2447 }); 2448 if($(id+\'_\'+checked)) 2449 { 2450 Element.show(id+\'_\'+checked); 2451 } 2452 } 2453 </script> 2454 <dl style="margin-top: 0; margin-bottom: 0; width: 40%;"> 2455 <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> 2456 <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 /> 2457 '.$specific_files.' 2458 </dl> 2459 <script type="text/javascript"> 2460 checkAction(\'attach\');'.$check_actions.' 2461 </script>'; 2462 2463 echo $form->generate_hidden_field("sid", $stylesheet['sid'])."<br />\n"; 2464 2465 $form_container = new FormContainer("{$lang->add_stylesheet_to} ".htmlspecialchars_uni($theme['name'])); 2466 $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'); 2467 2468 $form_container->output_row($lang->attached_to, $lang->attached_to_desc, $actions); 2469 2470 $sheetnames = array(); 2471 foreach($stylesheets as $filename => $style) 2472 { 2473 $sheetnames[basename($filename)] = basename($filename); 2474 } 2475 2476 $actions = "<dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\"> 2477 <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> 2478 <dd style=\"margin-top: 4px;\" id=\"add_1\" class=\"adds\"> 2479 <table cellpadding=\"4\"> 2480 <tr> 2481 <td>".$form->generate_select_box('import', $sheetnames, $mybb->input['import'], array('id' => 'import'))."</td> 2482 </tr> 2483 </table> 2484 </dd> 2485 <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> 2486 <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> 2487 </dl>"; 2488 2489 $form_container->output_row("", "", $actions); 2490 2491 $form_container->end(); 2492 2493 $buttons[] = $form->generate_submit_button($lang->save_stylesheet); 2494 2495 $form->output_submit_wrapper($buttons); 2496 2497 if($admin_options['codepress'] != 0) 2498 { 2499 echo "<script type=\"text/javascript\"> 2500 Event.observe('add_stylesheet', 'submit', function() 2501 { 2502 if($('stylesheet_cp')) { 2503 var area = $('stylesheet_cp'); 2504 area.id = 'stylesheet'; 2505 area.value = stylesheet.getCode(); 2506 area.disabled = false; 2507 } 2508 }); 2509 </script>\n"; 2510 } 2511 2512 echo '<script type="text/javascript" src="./jscripts/themes.js"></script>'; 2513 echo '<script type="text/javascript"> 2514 Event.observe(window, "load", function() { 2515 //<![CDATA[ 2516 new ThemeSelector(\''.$count.'\'); 2517 checkAction(\'add\'); 2518 }); 2519 //]]> 2520 </script>'; 2521 2522 $form->end(); 2523 2524 $page->output_footer(); 2525 } 2526 2527 if($mybb->input['action'] == "set_default") 2528 { 2529 $plugins->run_hooks("admin_style_themes_set_default"); 2530 2531 if(!verify_post_check($mybb->input['my_post_key'])) 2532 { 2533 flash_message($lang->invalid_post_verify_key2, 'error'); 2534 admin_redirect("index.php?module=style-themes"); 2535 } 2536 2537 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 2538 $theme = $db->fetch_array($query); 2539 2540 // Does the theme not exist? 2541 if(!$theme['tid'] || $theme['tid'] == 1) 2542 { 2543 flash_message($lang->error_invalid_theme, 'error'); 2544 admin_redirect("index.php?module=style-themes"); 2545 } 2546 2547 $db->update_query("themes", array('def' => 0)); 2548 $db->update_query("themes", array('def' => 1), "tid='".intval($mybb->input['tid'])."'"); 2549 2550 $plugins->run_hooks("admin_style_themes_set_default_commit"); 2551 2552 // Log admin action 2553 log_admin_action($theme['tid'], htmlspecialchars_uni($theme['name'])); 2554 2555 flash_message($lang->success_theme_set_default, 'success'); 2556 admin_redirect("index.php?module=style-themes"); 2557 } 2558 2559 if($mybb->input['action'] == "force") 2560 { 2561 $plugins->run_hooks("admin_style_themes_force"); 2562 2563 $query = $db->simple_select("themes", "*", "tid='".intval($mybb->input['tid'])."'"); 2564 $theme = $db->fetch_array($query); 2565 2566 // Does the theme not exist? 2567 if(!$theme['tid'] || $theme['tid'] == 1) 2568 { 2569 flash_message($lang->error_invalid_theme, 'error'); 2570 admin_redirect("index.php?module=style-themes"); 2571 } 2572 2573 // User clicked no 2574 if($mybb->input['no']) 2575 { 2576 admin_redirect("index.php?module=style-themes"); 2577 } 2578 2579 if($mybb->request_method == "post") 2580 { 2581 $updated_users = array( 2582 "style" => $theme['tid'] 2583 ); 2584 2585 $db->update_query("users", $updated_users); 2586 2587 $plugins->run_hooks("admin_style_themes_force_commit"); 2588 2589 // Log admin action 2590 log_admin_action($theme['tid'], htmlspecialchars_uni($theme['name'])); 2591 2592 flash_message($lang->success_theme_forced, 'success'); 2593 admin_redirect("index.php?module=style-themes"); 2594 } 2595 else 2596 { 2597 $page->output_confirm_action("index.php?module=style-themes&action=force&tid={$theme['tid']}", $lang->confirm_theme_forced); 2598 } 2599 } 2600 2601 if(!$mybb->input['action']) 2602 { 2603 $plugins->run_hooks("admin_style_themes_start"); 2604 2605 $page->output_header($lang->themes); 2606 2607 $page->output_nav_tabs($sub_tabs, 'themes'); 2608 2609 $table = new Table; 2610 $table->construct_header($lang->theme); 2611 $table->construct_header($lang->num_users, array("class" => "align_center", "width" => 100)); 2612 $table->construct_header($lang->controls, array("class" => "align_center", "width" => 150)); 2613 2614 build_theme_list(); 2615 2616 $table->output($lang->themes); 2617 2618 $page->output_footer(); 2619 } 2620 2621 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |