[ Index ] |
PHP Cross Reference of MyBB 1.8.38 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.8 4 * Copyright 2014 MyBB Group, All Rights Reserved 5 * 6 * Website: http://www.mybb.com 7 * License: http://www.mybb.com/about/license 8 * 9 */ 10 11 // Disallow direct access to this file for security reasons 12 if(!defined("IN_MYBB")) 13 { 14 die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined."); 15 } 16 17 $languages = $lang->get_languages(); 18 19 $page->add_breadcrumb_item($lang->languages, "index.php?module=config-languages"); 20 21 $plugins->run_hooks("admin_config_languages_begin"); 22 23 $no_write = null; 24 if($mybb->input['action'] == "edit_properties") 25 { 26 $editlang = basename($mybb->input['lang']); 27 $file = MYBB_ROOT."inc/languages/".$editlang.".php"; 28 if(!file_exists($file)) 29 { 30 flash_message($lang->error_invalid_file, 'error'); 31 admin_redirect("index.php?module=config-languages"); 32 } 33 34 $plugins->run_hooks("admin_config_languages_edit_properties"); 35 36 if($mybb->request_method == "post") 37 { 38 if(!is_writable($file)) 39 { 40 flash_message($lang->error_cannot_write_to_file, 'error'); 41 admin_redirect("index.php?module=config-languages"); 42 } 43 44 foreach($mybb->input['info'] as $key => $info) 45 { 46 $info = str_replace("\\", "\\\\", $info); 47 $info = str_replace('$', '\$', $info); 48 49 if($key == 'admin' || $key == 'rtl') 50 { 51 $info = (int)$info; 52 } 53 54 $newlanginfo[$key] = str_replace("\"", '\"', $info); 55 } 56 57 // Get contents of existing file 58 require $file; 59 60 // Make the contents of the new file 61 $newfile = "<?php 62 // The friendly name of the language 63 \$langinfo['name'] = \"{$newlanginfo['name']}\"; 64 65 // The author of the language 66 \$langinfo['author'] = \"{$langinfo['author']}\"; 67 68 // The language authors website 69 \$langinfo['website'] = \"{$langinfo['website']}\"; 70 71 // Compatible version of MyBB 72 \$langinfo['version'] = \"{$langinfo['version']}\"; 73 74 // Sets if the translation includes the Admin CP (1 = yes, 0 = no) 75 \$langinfo['admin'] = {$newlanginfo['admin']}; 76 77 // Sets if the language is RTL (Right to Left) (1 = yes, 0 = no) 78 \$langinfo['rtl'] = {$newlanginfo['rtl']}; 79 80 // Sets the lang in the <html> on all pages 81 \$langinfo['htmllang'] = \"{$newlanginfo['htmllang']}\"; 82 83 // Sets the character set, blank uses the default. 84 \$langinfo['charset'] = \"{$newlanginfo['charset']}\";\n"; 85 86 // Put it in! 87 if($file = fopen($file, "w")) 88 { 89 fwrite($file, $newfile); 90 fclose($file); 91 92 $plugins->run_hooks("admin_config_languages_edit_properties_commit"); 93 94 // Log admin action 95 log_admin_action($editlang); 96 97 flash_message($lang->success_langprops_updated, 'success'); 98 admin_redirect("index.php?module=config-languages&action=edit&lang=".htmlspecialchars_uni($editlang)."&editwith=".htmlspecialchars_uni($editlang)); 99 } 100 else 101 { 102 $errors[] = $lang->error_cannot_write_to_file; 103 } 104 } 105 106 $page->add_breadcrumb_item(preg_replace("<\?|\?>", "<span>?</span>", htmlspecialchars_uni($languages[$editlang])), "index.php?module=config-languages&action=edit&lang=".htmlspecialchars_uni($editlang)); 107 $page->add_breadcrumb_item($lang->nav_editing_set); 108 109 $page->output_header($lang->languages); 110 111 $sub_tabs['edit_properties'] = array( 112 "title" => $lang->edit_properties, 113 "link" => "index.php?module=config-languages", 114 "description" => $lang->edit_properties_desc 115 ); 116 $page->output_nav_tabs($sub_tabs, "edit_properties"); 117 118 // Get language info 119 require $file; 120 121 $form = new Form("index.php?module=config-languages&action=edit_properties", "post", "editset"); 122 echo $form->generate_hidden_field("lang", $editlang); 123 echo $form->generate_hidden_field("info[author]", $langinfo['author']); 124 echo $form->generate_hidden_field("info[website]", $langinfo['website']); 125 echo $form->generate_hidden_field("info[version]", $langinfo['version']); 126 127 if($errors) 128 { 129 $page->output_inline_error($errors); 130 } 131 else 132 { 133 if($langinfo['admin']) 134 { 135 $mybb->input['info']['admin'] = 1; 136 } 137 else 138 { 139 $mybb->input['info']['admin'] = 0; 140 } 141 142 if($langinfo['rtl']) 143 { 144 $mybb->input['info']['rtl'] = 1; 145 } 146 else 147 { 148 $mybb->input['info']['rtl'] = 0; 149 } 150 151 $mybb->input['info']['name'] = $langinfo['name']; 152 $mybb->input['info']['htmllang'] = $langinfo['htmllang']; 153 $mybb->input['info']['charset'] = $langinfo['charset']; 154 } 155 156 $form_container = new FormContainer($lang->edit_properties); 157 158 $form_container->output_row($lang->friendly_name." <em>*</em>", "", $form->generate_text_box('info[name]', $mybb->input['info']['name'], array('id' => 'name')), 'name'); 159 $form_container->output_row($lang->language_in_html." <em>*</em>", "", $form->generate_text_box('info[htmllang]', $mybb->input['info']['htmllang'], array('id' => 'htmllang')), 'htmllang'); 160 $form_container->output_row($lang->charset." <em>*</em>", "", $form->generate_text_box('info[charset]', $mybb->input['info']['charset'], array('id' => 'charset')), 'charset'); 161 $form_container->output_row($lang->rtl." <em>*</em>", "", $form->generate_yes_no_radio('info[rtl]', $mybb->input['info']['rtl'], array('id' => 'rtl')), 'rtl'); 162 $form_container->output_row($lang->admin." <em>*</em>", "", $form->generate_yes_no_radio('info[admin]', $mybb->input['info']['admin'], array('id' => 'admin')), 'admin'); 163 164 // Check if file is writable, before allowing submission 165 if(!is_writable($file)) 166 { 167 $no_write = 1; 168 $page->output_alert($lang->alert_note_cannot_write); 169 } 170 171 $form_container->end(); 172 173 $buttons[] = $form->generate_submit_button($lang->save_language_file, array('disabled' => $no_write)); 174 175 $form->output_submit_wrapper($buttons); 176 $form->end(); 177 178 $page->output_footer(); 179 } 180 181 if($mybb->input['action'] == "quick_phrases") 182 { 183 // Validate input 184 $editlang = basename($mybb->input['lang']); 185 186 if(in_array($editlang, array('.', '..'))) 187 { 188 flash_message($lang->error_folders_fail, 'error'); 189 admin_redirect("index.php?module=config-languages"); 190 } 191 192 $folder = MYBB_ROOT."inc/languages/".$editlang."/"; 193 194 $page->add_breadcrumb_item(preg_replace("<\?|\?>", "<span>?</span>", htmlspecialchars_uni($languages[$editlang])), "index.php?module=config-languages&action=quick_edit&lang=".htmlspecialchars_uni($editlang)); 195 196 // Validate that this language pack really exists 197 if(file_exists(MYBB_ROOT."inc/languages/".$editlang.".php")) 198 { 199 // Then validate language pack folders (and try to fix them if missing) 200 if(!is_dir($folder)) 201 { 202 @mkdir($folder); 203 } 204 if(!is_dir($folder."admin")) 205 { 206 @mkdir($folder."admin"); 207 } 208 } 209 210 if(!file_exists($folder) || !file_exists($folder."admin")) 211 { 212 flash_message($lang->error_folders_fail, 'error'); 213 admin_redirect("index.php?module=config-languages"); 214 } 215 216 $plugins->run_hooks("admin_config_languages_quick_phrases"); 217 218 $quick_phrases = array( 219 'member.lang.php' => array( 220 'agreement' => $lang->quickphrases_agreement, 221 'agreement_1' => $lang->quickphrases_agreement_1, 222 'agreement_2' => $lang->quickphrases_agreement_2, 223 'agreement_3' => $lang->quickphrases_agreement_3, 224 'agreement_4' => $lang->quickphrases_agreement_4, 225 'agreement_5' => $lang->quickphrases_agreement_5 226 ), 227 'messages.lang.php' => array( 228 'error_nopermission_guest_1' => $lang->quickphrases_error_nopermission_guest_1, 229 'error_nopermission_guest_2' => $lang->quickphrases_error_nopermission_guest_2, 230 'error_nopermission_guest_3' => $lang->quickphrases_error_nopermission_guest_3, 231 'error_nopermission_guest_4' => $lang->quickphrases_error_nopermission_guest_4 232 ) 233 ); 234 235 if($mybb->request_method == 'post') 236 { 237 if($mybb->request_method == 'post') 238 { 239 // We have more than one file to edit, lets set flag for all of them. 240 $editsuccess = true; 241 foreach($quick_phrases as $file => $phrases) 242 { 243 @include $folder.$file; 244 $contents_file = (array)$l; 245 unset($l); 246 247 foreach($phrases as $key => $value) 248 { 249 // validation - we fetch from input only variables that are defined in $quick_phrases array 250 $contents_file[$key] = $mybb->input['edit'][$key]; 251 } 252 // Save edited language file 253 if($fp = @fopen($folder.$file, "w")) 254 { 255 // We need info about edited language files to generate credits for our file 256 require MYBB_ROOT."inc/languages/".$editlang.".php"; 257 258 // Lets make nice credits header in language file 259 $lang_file_credits = "<?php\n/**\n"; 260 $lang_file_credits .= " * MyBB Copyright 2014 MyBB Group, All Rights Reserved\n *\n"; 261 $lang_file_credits .= " * Website: https://mybb.com\n"; 262 $lang_file_credits .= " * License: https://mybb.com/about/license\n *\n */\n\n"; 263 $lang_file_credits .= "// ".str_repeat('-',80)."\n"; 264 $lang_file_credits .= "// MyBB Language Pack File.\n"; 265 $lang_file_credits .= "// This file has been generated by MyBB - buildin language pack editor.\n"; 266 $lang_file_credits .= "// ".str_repeat('=',80)."\n"; 267 $lang_file_credits .= "// Friendly name of the language : ".preg_replace("#<\?|\?>|\r|\n#i", " ", $langinfo['name'])."\n"; 268 $lang_file_credits .= "// Author of the language pack : ".preg_replace("#<\?|\?>|\r|\n#i", " ", $langinfo['author'])."\n"; 269 $lang_file_credits .= "// Language pack translators website : ".preg_replace("#<\?|\?>|\r|\n#i", " ", $langinfo['website'])."\n"; 270 $lang_file_credits .= "// Compatible version of MyBB : ".preg_replace("#<\?|\?>|\r|\n#i", " ", $langinfo['version'])."\n"; 271 $lang_file_credits .= "// Last edited in MyBB Editor by : ".preg_replace("#<\?|\?>|\r|\n#i", " ", $mybb->user['username'])."\n"; 272 $lang_file_credits .= "// Last edited date : ".gmdate("r")."\n"; 273 $lang_file_credits .= "// ".str_repeat('-',80)."\n\n"; 274 275 $contents_wfile = $lang_file_credits; 276 foreach($contents_file as $key => $value) 277 { 278 $contents_wfile .= "\$l['".$key."'] = ".var_export($value, true).";\n"; 279 } 280 281 flock($fp, LOCK_EX); 282 fwrite($fp, $contents_wfile); 283 flock($fp, LOCK_UN); 284 fclose($fp); 285 } 286 else 287 { 288 // One of files failed 289 $editsuccess = false; 290 } 291 } 292 293 if($editsuccess == true) 294 { 295 // Log admin action 296 log_admin_action($editlang); 297 298 flash_message($lang->success_quickphrases_updated, 'success'); 299 admin_redirect('index.php?module=config-languages&action=edit&lang='.$editlang); 300 } 301 } 302 } 303 304 $page->output_header($lang->languages); 305 306 $sub_tabs['language_files'] = array( 307 'title' => $lang->language_files, 308 'link' => "index.php?module=config-languages&action=edit&lang=".$editlang, 309 'description' => $lang->language_files_desc 310 ); 311 312 $sub_tabs['quick_phrases'] = array( 313 'title' => $lang->quick_phrases, 314 'link' => "index.php?module=config-languages&action=quick_phrases&lang=".$editlang, 315 'description' => $lang->quick_phrases_desc 316 ); 317 318 $page->output_nav_tabs($sub_tabs, 'quick_phrases'); 319 320 $form = new Form('index.php?module=config-languages&action=quick_phrases&lang='.$editlang, 'post', 'quick_phrases'); 321 322 if($errors) 323 { 324 $page->output_inline_error($errors); 325 } 326 327 $table = new Table; 328 329 // Check if files are writable, before allowing submission 330 $no_write = null; 331 foreach($quick_phrases as $file => $phrases) 332 { 333 if(file_exists($folder.$file) && !is_writable($folder.$file) || !is_writable($folder)) 334 { 335 $no_write = 1; 336 } 337 } 338 339 if($no_write) 340 { 341 $page->output_alert($lang->alert_note_cannot_write); 342 } 343 344 $form_container = new FormContainer($lang->quick_phrases); 345 346 foreach($quick_phrases as $file => $phrases) 347 { 348 unset($langinfo); 349 @include MYBB_ROOT."inc/languages/".$editlang.".php"; 350 $quickphrases_dir_class = " langeditor_ltr"; 351 if((int)$langinfo['rtl'] > 0) 352 { 353 $quickphrases_dir_class = " langeditor_rtl"; 354 } 355 356 @include $folder.$file; 357 foreach($phrases as $phrase => $description) 358 { 359 $value = $l[$phrase]; 360 if(my_strtolower($langinfo['charset']) == "utf-8") 361 { 362 $value = preg_replace_callback("#%u([0-9A-F]{1,4})#i", 'encode_language_string_utf8', $value); 363 } 364 else 365 { 366 $value = preg_replace_callback("#%u([0-9A-F]{1,4})#i", 'encode_language_string', $value); 367 } 368 369 $form_container->output_row($description, $phrase, $form->generate_text_area("edit[$phrase]", $value, array('id' => 'lang_'.$phrase, 'rows' => 2, 'class' => "langeditor_textarea_edit {$quickphrases_dir_class}")), 'lang_'.$phrase, array('width' => '50%')); 370 } 371 } 372 373 $form_container->end(); 374 375 $buttons[] = $form->generate_submit_button($lang->save_language_file, array('disabled' => $no_write)); 376 377 $form->output_submit_wrapper($buttons); 378 $form->end(); 379 380 $page->output_footer(); 381 } 382 383 if($mybb->input['action'] == "edit") 384 { 385 // Validate input 386 $editlang = basename($mybb->input['lang']); 387 388 if(in_array($editlang, array('.', '..'))) 389 { 390 flash_message($lang->error_folders_fail, 'error'); 391 admin_redirect("index.php?module=config-languages"); 392 } 393 394 $folder = MYBB_ROOT."inc/languages/".$editlang."/"; 395 396 $page->add_breadcrumb_item(preg_replace("<\?|\?>", "<span>?</span>", htmlspecialchars_uni($languages[$editlang])), "index.php?module=config-languages&action=edit&lang=".htmlspecialchars_uni($editlang)); 397 398 $editwith = basename($mybb->get_input('editwith')); 399 400 if(in_array($editwith, array('.', '..'))) 401 { 402 flash_message($lang->error_folders_fail, 'error'); 403 admin_redirect("index.php?module=config-languages"); 404 } 405 406 407 $editwithfolder = ''; 408 409 if($editwith) 410 { 411 $editwithfolder = MYBB_ROOT."inc/languages/".$editwith."/"; 412 } 413 414 // Validate that edited language pack really exists 415 if(file_exists(MYBB_ROOT."inc/languages/".$editlang.".php")) 416 { 417 // Then validate edited language pack folders (and try to fix them if missing) 418 if(!is_dir($folder)) 419 { 420 @mkdir($folder); 421 } 422 if(!is_dir($folder."admin")) 423 { 424 @mkdir($folder."admin"); 425 } 426 } 427 428 if(!file_exists($folder) || !file_exists($folder."admin")) 429 { 430 flash_message($lang->error_folders_fail, 'error'); 431 admin_redirect("index.php?module=config-languages"); 432 } 433 434 // If we edit in compare mode, verify that at least folders of compared language exists 435 if($editwithfolder && (!file_exists($editwithfolder) || !file_exists($editwithfolder))) 436 { 437 flash_message($lang->error_invalid_set, 'error'); 438 admin_redirect("index.php?module=config-languages"); 439 } 440 441 $plugins->run_hooks("admin_config_languages_edit"); 442 443 if(isset($mybb->input['file'])) 444 { 445 // Validate input 446 $file = basename($mybb->input['file']); 447 448 if(in_array($file, array('.', '..'))) 449 { 450 flash_message($lang->error_folders_fail, 'error'); 451 admin_redirect("index.php?module=config-languages"); 452 } 453 454 if($mybb->get_input('inadmin') == 1) 455 { 456 $file = 'admin/'.$file; 457 } 458 $page->add_breadcrumb_item(htmlspecialchars_uni($file)); 459 460 $editfile = $folder.$file; 461 $withfile = ''; 462 463 $editwithfile = ''; 464 if($editwithfolder) 465 { 466 $editwithfile = $editwithfolder.$file; 467 } 468 469 if($mybb->request_method == "post") 470 { 471 // Save edited phrases to language file 472 473 // To validate input - build array of keys that allready exist in files 474 @include $editfile; 475 $valid_keys = (array)$l; 476 unset($l); 477 478 if(!empty($editwithfile)) 479 { 480 @include $editwithfile; 481 } 482 if(!empty($l)) 483 { 484 $valid_keys = array_merge($valid_keys, (array)$l); 485 } 486 unset($l); 487 488 $contents_wfile = null; 489 490 // Then fetch from input only valid keys 491 foreach($valid_keys as $key => $value) 492 { 493 $contents_wfile .= "\$l['".$key."'] = ".var_export($mybb->input['edit'][$key], true).";\n"; 494 } 495 496 // Save edited language file 497 if($fp = @fopen($editfile, "w")) 498 { 499 // We need info about edited language files to generate credits for our file 500 require MYBB_ROOT."inc/languages/".$editlang.".php"; 501 502 // Lets make nice credits header in language file 503 $lang_file_credits = "<?php\n/**\n"; 504 $lang_file_credits .= " * MyBB Copyright 2014 MyBB Group, All Rights Reserved\n *\n"; 505 $lang_file_credits .= " * Website: https://mybb.com\n"; 506 $lang_file_credits .= " * License: https://mybb.com/about/license\n *\n */\n\n"; 507 $lang_file_credits .= "// ".str_repeat('-',80)."\n"; 508 $lang_file_credits .= "// MyBB Language Pack File.\n"; 509 $lang_file_credits .= "// This file has been generated by MyBB - buildin language pack editor.\n"; 510 $lang_file_credits .= "// ".str_repeat('=',80)."\n"; 511 $lang_file_credits .= "// Friendly name of the language : ".preg_replace("#<\?|\?>|\r|\n#i", " ", $langinfo['name'])."\n"; 512 $lang_file_credits .= "// Author of the language pack : ".preg_replace("#<\?|\?>|\r|\n#i", " ", $langinfo['author'])."\n"; 513 $lang_file_credits .= "// Language pack translators website : ".preg_replace("#<\?|\?>|\r|\n#i", " ", $langinfo['website'])."\n"; 514 $lang_file_credits .= "// Compatible version of MyBB : ".preg_replace("#<\?|\?>|\r|\n#i", " ", $langinfo['version'])."\n"; 515 $lang_file_credits .= "// Last edited in MyBB Editor by : ".preg_replace("#<\?|\?>|\r|\n#i", " ", $mybb->user['username'])."\n"; 516 $lang_file_credits .= "// Last edited date : ".gmdate("r")."\n"; 517 $lang_file_credits .= "// ".str_repeat('-',80)."\n\n"; 518 519 $contents_wfile = $lang_file_credits.$contents_wfile; 520 521 flock($fp, LOCK_EX); 522 fwrite($fp, $contents_wfile); 523 flock($fp, LOCK_UN); 524 fclose($fp); 525 526 $plugins->run_hooks("admin_config_languages_edit_commit"); 527 528 // Log admin action 529 log_admin_action($editlang, $editfile, $mybb->get_input('inadmin', MyBB::INPUT_INT)); 530 531 flash_message($lang->success_langfile_updated, 'success'); 532 admin_redirect("index.php?module=config-languages&action=edit&lang=".htmlspecialchars_uni($editlang)."&editwith=".htmlspecialchars_uni($editwith)); 533 } 534 else 535 { 536 $errors[] = $lang->error_cannot_write_to_file; 537 } 538 } 539 540 if(!empty($editwith)) 541 { 542 unset($langinfo); 543 @include MYBB_ROOT."inc/languages/".$editwith.".php"; 544 $editwith_dir_class = " langeditor_ltr"; 545 if((int)$langinfo['rtl'] > 0) 546 { 547 $editwith_dir_class = " langeditor_rtl"; 548 } 549 } 550 unset($langinfo); 551 @include MYBB_ROOT."inc/languages/".$editlang.".php"; 552 $editlang_dir_class = " langeditor_ltr"; 553 if((int)$langinfo['rtl'] > 0) 554 { 555 $editlang_dir_class = " langeditor_rtl"; 556 } 557 558 // Build and output form with edited phrases 559 560 // Get file being edited in an array 561 $editvars = array(); 562 unset($l); 563 @include $editfile; 564 if(isset($l)) 565 { 566 $editvars = (array)$l; 567 unset($l); 568 } 569 570 $withvars = array(); 571 // Get edit with file in an array if exists 572 if($editwithfile) 573 { 574 // File we will compare to, may not exists, but dont worry we will auto switch to solo mode later if so 575 @include $editwithfile; 576 $withvars = (array)$l; 577 unset($l); 578 } 579 580 // Start output 581 $page->output_header($lang->languages); 582 583 $sub_tabs['edit_language_variables'] = array( 584 "title" => $lang->edit_language_variables, 585 "link" => "index.php?module=config-languages", 586 "description" => $lang->edit_language_variables_desc 587 ); 588 $page->output_nav_tabs($sub_tabs, "edit_language_variables"); 589 590 $form = new Form("index.php?module=config-languages&action=edit", "post", "edit"); 591 echo $form->generate_hidden_field("file", $file); 592 echo $form->generate_hidden_field("lang", $editlang); 593 echo $form->generate_hidden_field("editwith", $editwith); 594 echo $form->generate_hidden_field("inadmin", $mybb->get_input('inadmin', MyBB::INPUT_INT)); 595 if($errors) 596 { 597 $page->output_inline_error($errors); 598 } 599 600 // Check if file is writable, before allowing submission 601 $no_write = null; 602 if(file_exists($editfile) && !is_writable($editfile) || !is_writable($folder)) 603 { 604 $no_write = 1; 605 $page->output_alert($lang->alert_note_cannot_write); 606 } 607 608 $form_container = new FormContainer(htmlspecialchars_uni($file)); 609 if($editwithfile && $withvars) 610 { 611 // Editing with another file 612 613 $form_container->output_row_header(preg_replace("<\?|\?>", "<span>?</span>", htmlspecialchars_uni($languages[$editwith]))); 614 $form_container->output_row_header(preg_replace("<\?|\?>", "<span>?</span>", htmlspecialchars_uni($languages[$editlang]))); 615 616 foreach($withvars as $key => $value) 617 { 618 if(my_strtolower($langinfo['charset']) == "utf-8") 619 { 620 $withvars[$key] = preg_replace_callback("#%u([0-9A-F]{1,4})#i", 'encode_language_string_utf8', $withvars[$key]); 621 $editvars[$key] = preg_replace_callback("#%u([0-9A-F]{1,4})#i", 'encode_language_string_utf8', $editvars[$key]); 622 } 623 else 624 { 625 $withvars[$key] = preg_replace_callback("#%u([0-9A-F]{1,4})#i", 'encode_language_string_utf8', $withvars[$key]); 626 $editvars[$key] = preg_replace_callback("#%u([0-9A-F]{1,4})#i", 'encode_language_string', $editvars[$key]); 627 } 628 629 // Find problems and differences in editfile in comparision to editwithfile 630 631 // Count {x} in left and right variable 632 $withvars_value_cbvCount = preg_match_all("/{[ \t]*\d+[ \t]*}/", $withvars[$key], $matches); 633 $editvars_value_cbvCount = preg_match_all("/{[ \t]*\d+[ \t]*}/", $editvars[$key], $matches); 634 635 // If left contain something but right is empty or only spaces || count of {x} are different betwin left and right 636 if($withvars[$key] && !$editvars[$key] || $withvars_value_cbvCount != $editvars_value_cbvCount) 637 { 638 $textarea_issue_class = " langeditor_textarea_issue"; 639 } 640 else 641 { 642 $textarea_issue_class = ""; 643 } 644 645 $form_container->output_row($key, "", $form->generate_text_area("", $withvars[$key], array('readonly' => true, 'rows' => 2, 'class' => "langeditor_textarea_editwith {$editwith_dir_class}")), "", array('width' => '50%', 'skip_construct' => true)); 646 $form_container->output_row($key, "", $form->generate_text_area("edit[$key]", $editvars[$key], array('id' => 'lang_'.$key, 'rows' => 2, 'class' => "langeditor_textarea_edit {$textarea_issue_class} {$editlang_dir_class}")), 'lang_'.$key, array('width' => '50%')); 647 } 648 649 // Create form fields for extra variables that are present only in edited file 650 $present_in_edit_vars_only = (array)array_diff_key($editvars, $withvars); 651 if($present_in_edit_vars_only) 652 { 653 foreach($present_in_edit_vars_only as $key => $value) 654 { 655 if(my_strtolower($langinfo['charset']) == "utf-8") 656 { 657 $editvars[$key] = preg_replace_callback("#%u([0-9A-F]{1,4})#i", 'encode_language_string_utf8', $editvars[$key]); 658 } 659 else 660 { 661 $editvars[$key] = preg_replace_callback("#%u([0-9A-F]{1,4})#i", 'encode_language_string', $editvars[$key]); 662 } 663 664 $form_container->output_row("", "", "", "", array('width' => '50%', 'skip_construct' => true)); 665 $form_container->output_row($key, "", $form->generate_text_area("edit[$key]", $editvars[$key], array('id' => 'lang_'.$key, 'rows' => 2, 'class' => "langeditor_textarea_edit {$editlang_dir_class}")), 'lang_'.$key, array('width' => '50%')); 666 } 667 } 668 669 } 670 else 671 { 672 // Editing individually 673 $form_container->output_row_header(preg_replace("<\?|\?>", "<span>?</span>", htmlspecialchars_uni($languages[$editlang]))); 674 675 // Make each editing row from current file that we edit 676 foreach($editvars as $key => $value) 677 { 678 if(my_strtolower($langinfo['charset']) == "utf-8") 679 { 680 $value = preg_replace_callback("#%u([0-9A-F]{1,4})#i", 'encode_language_string_utf8', $value); 681 } 682 else 683 { 684 $value = preg_replace_callback("#%u([0-9A-F]{1,4})#i", 'encode_language_string', $value); 685 } 686 $form_container->output_row($key, "", $form->generate_text_area("edit[$key]", $value, array('id' => 'lang_'.$key, 'rows' => 2, 'class' => "langeditor_textarea_edit {$editlang_dir_class}")), 'lang_'.$key, array('width' => '50%')); 687 } 688 } 689 $form_container->end(); 690 691 if(!count($editvars)) 692 { 693 $no_write = 1; 694 } 695 696 $buttons[] = $form->generate_submit_button($lang->save_language_file, array('disabled' => $no_write)); 697 698 $form->output_submit_wrapper($buttons); 699 $form->end(); 700 } 701 else 702 { 703 // Build and output list of available language files 704 705 $page->output_header($lang->languages); 706 707 $sub_tabs['language_files'] = array( 708 'title' => $lang->language_files, 709 'link' => "index.php?module=config-languages&action=edit&lang=".$editlang, 710 'description' => $lang->language_files_desc 711 ); 712 713 $sub_tabs['quick_phrases'] = array( 714 'title' => $lang->quick_phrases, 715 'link' => "index.php?module=config-languages&action=quick_phrases&lang=".$editlang, 716 'description' => $lang->quick_phrases_desc 717 ); 718 719 $page->output_nav_tabs($sub_tabs, 'language_files'); 720 721 if(!file_exists(MYBB_ROOT."inc/languages/".$editlang.".php")) 722 { 723 flash_message($lang->error_invalid_set, 'error'); 724 admin_redirect("index.php?module=config-languages"); 725 } 726 require MYBB_ROOT."inc/languages/".$editlang.".php"; 727 728 $table = new Table; 729 if($editwithfolder) 730 { 731 $table->construct_header(preg_replace("<\?|\?>", "<span>?</span>", htmlspecialchars_uni($languages[$editwith]))); 732 $table->construct_header($lang->phrases, array("class" => "align_center", "width" => 100)); 733 $table->construct_header(preg_replace("<\?|\?>", "<span>?</span>", htmlspecialchars_uni($languages[$editlang]))); 734 $table->construct_header($lang->issues, array("class" => "align_center", "width" => 100)); 735 $table->construct_header($lang->controls, array("class" => "align_center", "width" => 100)); 736 } 737 else 738 { 739 $table->construct_header(preg_replace("<\?|\?>", "<span>?</span>", htmlspecialchars_uni($languages[$editlang]))); 740 $table->construct_header($lang->phrases, array("class" => "align_center", "width" => 100)); 741 $table->construct_header($lang->controls, array("class" => "align_center", "width" => 100)); 742 } 743 744 // Get files in main folder 745 $filenames = array(); 746 if($handle = opendir($folder)) 747 { 748 while(false !== ($file = readdir($handle))) 749 { 750 if(preg_match("#\.lang\.php$#", $file)) 751 { 752 $filenames[] = $file; 753 } 754 } 755 closedir($handle); 756 sort($filenames); 757 } 758 759 $edit_colspan = 3; 760 // Get files from folder we want to peek at (if possible) 761 if($editwithfolder) 762 { 763 $edit_colspan = 5; 764 $filenameswith = array(); 765 if($handle = opendir($editwithfolder)) 766 { 767 while(false !== ($file = readdir($handle))) 768 { 769 if(preg_match("#\.lang\.php$#", $file)) 770 { 771 $filenameswith[] = $file; 772 } 773 } 774 closedir($handle); 775 sort($filenameswith); 776 } 777 } 778 779 if($editwithfolder) 780 { 781 $files_left = array_diff($filenameswith, $filenames); 782 $files_right = array_diff($filenames, $filenameswith); 783 $files_both = array_intersect($filenameswith, $filenames); 784 785 foreach($files_left as $key => $file) 786 { 787 $editvars_left = array(); 788 789 unset($l); 790 @include $editwithfolder.$file; 791 if(isset($l)) 792 { 793 $editvars_left = (array)$l; 794 unset($l); 795 } 796 797 $icon_issues = "<span class='langeditor_ok' title='".$lang->issues_ok."'></span>"; 798 if(count($editvars_left) > 0) 799 { 800 $icon_issues = "<span class='langeditor_warning' title='".$lang->issues_warning."'></span>"; 801 } 802 803 $table->construct_cell(htmlspecialchars_uni($file), array("class" => "langeditor_editwithfile")); 804 $table->construct_cell(count($editvars_left), array("class" => "langeditor_phrases")); 805 $table->construct_cell("", array("class" => "langeditor_editfile")); 806 $table->construct_cell($icon_issues, array("class" => "langeditor_issues")); 807 $table->construct_cell("<a href=\"index.php?module=config-languages&action=edit&lang=".htmlspecialchars_uni($editlang)."&editwith=".htmlspecialchars_uni($editwith)."&file=".htmlspecialchars_uni($file)."\">{$lang->edit}</a>", array("class" => "langeditor_edit")); 808 $table->construct_row(); 809 } 810 foreach($files_right as $key => $file) 811 { 812 $editvars_right = array(); 813 814 unset($l); 815 @include $folder.$file; 816 if(isset($l)) 817 { 818 $editvars_right = (array)$l; 819 unset($l); 820 } 821 822 $icon_issues = "<span class='langeditor_ok' title='".$lang->issues_ok."'></span>"; 823 if(count($editvars_right) > 0) 824 { 825 $icon_issues = "<span class='langeditor_nothingtocompare' title='".$lang->issues_nothingtocompare."'></span>"; 826 } 827 828 $table->construct_cell("", array("class" => "langeditor_editwithfile")); 829 $table->construct_cell("", array("class" => "langeditor_phrases")); 830 $table->construct_cell(htmlspecialchars_uni($file), array("class" => "langeditor_editfile")); 831 $table->construct_cell($icon_issues, array("class" => "langeditor_issues")); 832 $table->construct_cell("<a href=\"index.php?module=config-languages&action=edit&lang=".htmlspecialchars_uni($editlang)."&editwith=".htmlspecialchars_uni($editwith)."&file=".htmlspecialchars_uni($file)."\">{$lang->edit}</a>", array("class" => "langeditor_edit")); 833 $table->construct_row(); 834 } 835 foreach($files_both as $key => $file) 836 { 837 $editvars_right = $editvars_left = array(); 838 839 unset($l); 840 @include $editwithfolder.$file; 841 if(isset($l)) 842 { 843 $editvars_left = (array)$l; 844 unset($l); 845 } 846 @include $folder.$file; 847 if(isset($l)) 848 { 849 $editvars_right = (array)$l; 850 unset($l); 851 } 852 853 $table->construct_cell(htmlspecialchars_uni($file), array("class" => "langeditor_editwithfile")); 854 $table->construct_cell(count($editvars_left), array("class" => "langeditor_phrases")); 855 $table->construct_cell(htmlspecialchars_uni($file), array("class" => "langeditor_editfile")); 856 857 $icon_issues = "<span class='langeditor_ok' title='".$lang->issues_ok."'></span>"; 858 859 // Find problems and differences in editfile in comparision to editwithfile 860 foreach($editvars_left as $editvars_left_key => $editvars_left_value) 861 { 862 // Count {x} in left and right variable 863 $editvars_left_value_cbvCount = preg_match_all("/{[ \t]*\d+[ \t]*}/", $editvars_left_value, $matches); 864 $editvars_right_value_cbvCount = preg_match_all("/{[ \t]*\d+[ \t]*}/", $editvars_right[$editvars_left_key], $matches); 865 // If left contain something but right is empty || count of {x} are different betwin left and right 866 if($editvars_left_value && !$editvars_right[$editvars_left_key] || $editvars_left_value_cbvCount != $editvars_right_value_cbvCount) 867 { 868 $icon_issues = "<span class='langeditor_warning' title='".$lang->issues_warning."'></span>"; 869 // One difference is enought, so lets abort checking for more. 870 break; 871 } 872 } 873 874 $table->construct_cell($icon_issues, array("class" => "langeditor_issues")); 875 $table->construct_cell("<a href=\"index.php?module=config-languages&action=edit&lang=".htmlspecialchars_uni($editlang)."&editwith=".htmlspecialchars_uni($editwith)."&file=".htmlspecialchars_uni($file)."\">{$lang->edit}</a>", array("class" => "langeditor_edit")); 876 $table->construct_row(); 877 } 878 } 879 else 880 { 881 foreach($filenames as $key => $file) 882 { 883 unset($l); 884 @include $folder.$file; 885 $editvars_count = array(); 886 if(isset($l)) 887 { 888 $editvars_count = (array)$l; 889 } 890 unset($l); 891 892 $table->construct_cell(htmlspecialchars_uni($file), array("class" => "langeditor_editfile")); 893 $table->construct_cell(count($editvars_count), array("class" => "langeditor_phrases")); 894 $table->construct_cell("<a href=\"index.php?module=config-languages&action=edit&lang=".htmlspecialchars_uni($editlang)."&editwith=".htmlspecialchars_uni($editwith)."&file=".htmlspecialchars_uni($file)."\">{$lang->edit}</a>", array("class" => "langeditor_edit")); 895 $table->construct_row(); 896 } 897 } 898 899 if($table->num_rows() == 0) 900 { 901 $table->construct_cell($lang->no_language_files_front_end, array('colspan' => $edit_colspan)); 902 $table->construct_row(); 903 } 904 905 $table->output($lang->front_end); 906 907 if($langinfo['admin'] != 0) 908 { 909 $table = new Table; 910 if($editwithfolder) 911 { 912 $table->construct_header(preg_replace("<\?|\?>", "<span>?</span>", htmlspecialchars_uni($languages[$editwith]))); 913 $table->construct_header($lang->phrases, array("class" => "align_center", "width" => 100)); 914 $table->construct_header(preg_replace("<\?|\?>", "<span>?</span>", htmlspecialchars_uni($languages[$editlang]))); 915 $table->construct_header($lang->issues, array("class" => "align_center", "width" => 100)); 916 $table->construct_header($lang->controls, array("class" => "align_center", "width" => 100)); 917 } 918 else 919 { 920 $table->construct_header(preg_replace("<\?|\?>", "<span>?</span>", htmlspecialchars_uni($languages[$editlang]))); 921 $table->construct_header($lang->phrases, array("class" => "align_center", "width" => 100)); 922 $table->construct_header($lang->controls, array("class" => "align_center", "width" => 100)); 923 } 924 925 // Get files in admin folder 926 $adminfilenames = array(); 927 if($handle = opendir($folder."admin")) 928 { 929 while(false !== ($file = readdir($handle))) 930 { 931 if(preg_match("#\.lang\.php$#", $file)) 932 { 933 $adminfilenames[] = $file; 934 } 935 } 936 closedir($handle); 937 sort($adminfilenames); 938 } 939 940 $edit_colspan = 3; 941 // Get files from admin folder we want to peek at (if possible) 942 if($editwithfolder) 943 { 944 $edit_colspan = 5; 945 $adminfilenameswith = array(); 946 if($handle = opendir($editwithfolder."admin")) 947 { 948 while(false !== ($file = readdir($handle))) 949 { 950 if(preg_match("#\.lang\.php$#", $file)) 951 { 952 $adminfilenameswith[] = $file; 953 } 954 } 955 closedir($handle); 956 sort($adminfilenameswith); 957 } 958 } 959 960 if($editwithfolder) 961 { 962 $files_left = array_diff($adminfilenameswith, $adminfilenames); 963 $files_right = array_diff($adminfilenames, $adminfilenameswith); 964 $files_both = array_intersect($adminfilenameswith, $adminfilenames); 965 966 foreach($files_left as $key => $file) 967 { 968 @include $editwithfolder."admin/".$file; 969 $editvars_left = (array)$l; 970 unset($l); 971 972 $icon_issues = "<span class='langeditor_ok' title='".$lang->issues_ok."'></span>"; 973 if(count($editvars_left) >0) 974 { 975 $icon_issues = "<span class='langeditor_warning' title='".$lang->issues_warning."'></span>"; 976 } 977 978 $table->construct_cell(htmlspecialchars_uni($file), array("class" => "langeditor_editwithfile")); 979 $table->construct_cell(count($editvars_left), array("class" => "langeditor_phrases")); 980 $table->construct_cell("", array("class" => "langeditor_editfile")); 981 $table->construct_cell($icon_issues, array("class" => "langeditor_issues")); 982 $table->construct_cell("<a href=\"index.php?module=config-languages&action=edit&lang=".htmlspecialchars_uni($editlang)."&editwith=".htmlspecialchars_uni($editwith)."&file=".htmlspecialchars_uni($file)."&inadmin=1\">{$lang->edit}</a>", array("class" => "langeditor_edit")); 983 $table->construct_row(); 984 } 985 foreach($files_right as $key => $file) 986 { 987 @include $folder."admin/".$file; 988 $editvars_right = (array)$l; 989 unset($l); 990 991 $icon_issues = "<span class='langeditor_ok' title='".$lang->issues_ok."'></span>"; 992 if(count($editvars_right) >0) 993 { 994 $icon_issues = "<span class='langeditor_nothingtocompare' title='".$lang->issues_nothingtocompare."'></span>"; 995 } 996 997 $table->construct_cell("", array("class" => "langeditor_editwithfile")); 998 $table->construct_cell("", array("class" => "langeditor_phrases")); 999 $table->construct_cell(htmlspecialchars_uni($file), array("class" => "langeditor_editfile")); 1000 $table->construct_cell($icon_issues, array("class" => "langeditor_issues")); 1001 $table->construct_cell("<a href=\"index.php?module=config-languages&action=edit&lang=".htmlspecialchars_uni($editlang)."&editwith=".htmlspecialchars_uni($editwith)."&file=".htmlspecialchars_uni($file)."&inadmin=1\">{$lang->edit}</a>", array("class" => "langeditor_edit")); 1002 $table->construct_row(); 1003 } 1004 foreach($files_both as $key => $file) 1005 { 1006 @include $editwithfolder."admin/".$file; 1007 $editvars_left = (array)$l; 1008 unset($l); 1009 @include $folder."admin/".$file; 1010 $editvars_right = (array)$l; 1011 unset($l); 1012 1013 $table->construct_cell(htmlspecialchars_uni($file), array("class" => "langeditor_editwithfile")); 1014 $table->construct_cell(count($editvars_left), array("class" => "langeditor_phrases")); 1015 $table->construct_cell(htmlspecialchars_uni($file), array("class" => "langeditor_editfile")); 1016 1017 $icon_issues = "<span class='langeditor_ok' title='".$lang->issues_ok."'></span>"; 1018 1019 // Find problems and differences in editfile in comparision to editwithfile 1020 foreach($editvars_left as $editvars_left_key => $editvars_left_value) 1021 { 1022 // Count {x} in left and right variable 1023 $editvars_left_value_cbvCount = preg_match_all("/{[ \t]*\d+[ \t]*}/", $editvars_left_value, $matches); 1024 $editvars_right_value_cbvCount = preg_match_all("/{[ \t]*\d+[ \t]*}/", $editvars_right[$editvars_left_key], $matches); 1025 // If left contain something but right is empty || count of {x} are different betwin left and right 1026 if($editvars_left_value && !$editvars_right[$editvars_left_key] || $editvars_left_value_cbvCount != $editvars_right_value_cbvCount) 1027 { 1028 $icon_issues = "<span class='langeditor_warning' title='".$lang->issues_warning."'></span>"; 1029 // One difference is enought. 1030 break; 1031 } 1032 } 1033 1034 $table->construct_cell($icon_issues, array("class" => "langeditor_issues")); 1035 $table->construct_cell("<a href=\"index.php?module=config-languages&action=edit&lang=".htmlspecialchars_uni($editlang)."&editwith=".htmlspecialchars_uni($editwith)."&file=".htmlspecialchars_uni($file)."&inadmin=1\">{$lang->edit}</a>", array("class" => "langeditor_edit")); 1036 $table->construct_row(); 1037 } 1038 } 1039 else 1040 { 1041 foreach($adminfilenames as $key => $file) 1042 { 1043 @include $folder."admin/".$file; 1044 $editvars_count = (array)$l; 1045 unset($l); 1046 1047 $table->construct_cell(htmlspecialchars_uni($file), array("class" => "langeditor_editfile")); 1048 $table->construct_cell(count($editvars_count), array("class" => "langeditor_phrases")); 1049 $table->construct_cell("<a href=\"index.php?module=config-languages&action=edit&lang=".htmlspecialchars_uni($editlang)."&editwith=".htmlspecialchars_uni($editwith)."&file=/".htmlspecialchars_uni($file)."&inadmin=1\">{$lang->edit}</a>", array("class" => "langeditor_edit")); 1050 $table->construct_row(); 1051 } 1052 } 1053 1054 if($table->num_rows() == 0) 1055 { 1056 $table->construct_cell($lang->no_language_files_admin_cp, array('colspan' => $edit_colspan)); 1057 $table->construct_row(); 1058 } 1059 1060 $table->output($lang->admin_cp); 1061 } 1062 } 1063 1064 $page->output_footer(); 1065 } 1066 1067 if(!$mybb->input['action']) 1068 { 1069 $page->output_header($lang->languages); 1070 1071 $sub_tabs['languages'] = array( 1072 'title' => $lang->languages, 1073 'link' => "index.php?module=config-languages", 1074 'description' => $lang->languages_desc 1075 ); 1076 $sub_tabs['find_language'] = array( 1077 'title' => $lang->find_language_packs, 1078 'link' => "https://community.mybb.com/mods.php?action=browse&category=19", 1079 'link_target' => "_blank", 1080 'link_rel' => "noopener" 1081 ); 1082 1083 $plugins->run_hooks("admin_config_languages_start"); 1084 1085 $page->output_nav_tabs($sub_tabs, 'languages'); 1086 1087 $table = new Table; 1088 $table->construct_header($lang->languagevar); 1089 $table->construct_header($lang->version, array("class" => "align_center", "width" => 100)); 1090 $table->construct_header($lang->controls, array("class" => "align_center", "width" => 155)); 1091 1092 asort($languages); 1093 1094 foreach($languages as $key1 => $langname1) 1095 { 1096 $langselectlangs[$key1] = $lang->sprintf($lang->edit_with, preg_replace("<\?|\?>", "<span>?</span>", htmlspecialchars_uni($langname1))); 1097 } 1098 1099 foreach($languages as $key => $langname) 1100 { 1101 include MYBB_ROOT."inc/languages/".$key.".php"; 1102 1103 if(!empty($langinfo['website'])) 1104 { 1105 $author = "<a href=\"".htmlspecialchars_uni($langinfo['website'])."\" target=\"_blank\" rel=\"noopener\">".htmlspecialchars_uni($langinfo['author'])."</a>"; 1106 } 1107 else 1108 { 1109 $author = htmlspecialchars_uni($langinfo['author']); 1110 } 1111 1112 $table->construct_cell("<span class='langeditor_info_name'>".preg_replace("<\?|\?>", "<span>?</span>", htmlspecialchars_uni($langinfo['name']))."</span><br /><span class='langeditor_info_author'>".$author."</span>"); 1113 $table->construct_cell(htmlspecialchars_uni($langinfo['version']), array("class" => "align_center")); 1114 1115 $popup = new PopupMenu("language_".htmlspecialchars_uni($key), $lang->options); 1116 $popup->add_item($lang->edit_language_variables, "index.php?module=config-languages&action=edit&lang=".htmlspecialchars_uni($key)); 1117 foreach($langselectlangs as $key1 => $langname1) 1118 { 1119 if($key != $key1) 1120 { 1121 $popup->add_item($langname1, "index.php?module=config-languages&action=edit&lang=".htmlspecialchars_uni($key)."&editwith=".htmlspecialchars_uni($key1)); 1122 } 1123 } 1124 $popup->add_item($lang->edit_properties, "index.php?module=config-languages&action=edit_properties&lang=".htmlspecialchars_uni($key)); 1125 $table->construct_cell($popup->fetch(), array("class" => "align_center")); 1126 $table->construct_row(); 1127 } 1128 1129 if($table->num_rows() == 0) 1130 { 1131 $table->construct_cell($lang->no_language, array('colspan' => 3)); 1132 $table->construct_row(); 1133 } 1134 1135 $table->output($lang->installed_language_packs); 1136 1137 $page->output_footer(); 1138 } 1139 1140 /** 1141 * Fixes url encoded unicode characters 1142 * 1143 * @param string $string The string to encode. 1144 * @return string The encoded string. 1145 */ 1146 function encode_language_string_utf8($matches) 1147 { 1148 return dec_to_utf8(hexdec($matches[1])); 1149 } 1150 1151 /** 1152 * Fixes url encoded unicode characters 1153 * 1154 * @param string $string The string to encode. 1155 * @return string The encoded string. 1156 */ 1157 function encode_language_string($matches) 1158 { 1159 return "&#".hexdec($matches[1]).";"; 1160 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |