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