merge_langs.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. */
  6. require_once( './../inc/header.inc.php' );
  7. require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
  8. // --------------- page variables and login
  9. $_page['name_index'] = 1;
  10. check_logged();
  11. $_page['header'] = "Merge Langs";
  12. $_page['header_text'] = $_page['header'];
  13. // --------------- page components
  14. $_ni = $_page['name_index'];
  15. $_page_cont[$_ni]['page_main_code'] = PageCompPageMainCode();
  16. // --------------- [END] page components
  17. PageCode();
  18. // --------------- page components functions
  19. /**
  20. * page code function
  21. */
  22. function PageCompPageMainCode()
  23. {
  24. $aForm = array(
  25. 'form_attrs' => array(
  26. 'id' => 'test_email_templates',
  27. 'action' => BX_DOL_URL_ROOT . '_ml.php',
  28. 'method' => 'post',
  29. ),
  30. 'params' => array (
  31. 'db' => array(
  32. 'submit_name' => 'do_submit',
  33. ),
  34. ),
  35. 'inputs' => array(
  36. 'l_new' => array(
  37. 'type' => 'textarea',
  38. 'name' => 'l_new',
  39. 'caption' => 'New Language',
  40. ),
  41. 'l_old' => array(
  42. 'type' => 'textarea',
  43. 'name' => 'l_old',
  44. 'caption' => 'Old Language',
  45. ),
  46. 'module_lang_file' => array(
  47. 'type' => 'checkbox',
  48. 'name' => 'module_lang_file',
  49. 'caption' => 'Module language file',
  50. 'value' => 1,
  51. 'checked' => true,
  52. ),
  53. 'submit' => array(
  54. 'type' => 'submit',
  55. 'name' => 'do_submit',
  56. 'value' => _t('_Submit'),
  57. ),
  58. ),
  59. );
  60. $oForm = new BxTemplFormView($aForm);
  61. $oForm->initChecker();
  62. if ($oForm->isSubmittedAndValid()) {
  63. $isModuleLangFile = $_POST['module_lang_file'] ? true : false;
  64. $aLang71 = getLangArray(process_pass_data($_POST['l_new']), $isModuleLangFile);
  65. $aLang70 = getLangArray(process_pass_data($_POST['l_old']), $isModuleLangFile);
  66. if (is_array($aLang71) && is_array($aLang70)) {
  67. $s .= prepareTextarea ('Added Keys', findAddedKeys($aLang71, $aLang70));
  68. $s .= prepareTextarea ('Changed Keys', findChangedKeys($aLang71, $aLang70));
  69. $aDeletedKeys = findDeletedKeys($aLang71, $aLang70);
  70. $s .= prepareTextarea ('Deleted Keys', $aDeletedKeys);
  71. $s .= prepareTextareaWithDeltedKeys ($aDeletedKeys);
  72. } else {
  73. $s = MsgBox("Invalid arrays") . $oForm->getCode();
  74. }
  75. } else {
  76. $s = $oForm->getCode();
  77. }
  78. return DesignBoxContent($GLOBALS['_page']['header'], $s, 11);
  79. }
  80. function getLangArray ($s, $isModuleLangFile)
  81. {
  82. eval($s);
  83. return $isModuleLangFile ? $aLangContent : $LANG;
  84. }
  85. function findDeletedKeys ($aLang71, $aLang70)
  86. {
  87. $a = array ();
  88. foreach ($aLang70 as $k => $v)
  89. if (!isset($aLang71[$k]))
  90. $a[$k] = $v;
  91. return $a;
  92. }
  93. function findAddedKeys ($aLang71, $aLang70)
  94. {
  95. $a = array ();
  96. foreach ($aLang71 as $k => $v)
  97. if (!isset($aLang70[$k]))
  98. $a[$k] = $v;
  99. return $a;
  100. }
  101. function findChangedKeys ($aLang71, $aLang70)
  102. {
  103. $a = array ();
  104. foreach ($aLang71 as $k => $v)
  105. if (isset($aLang70[$k]) && $aLang70[$k] != $aLang71[$k])
  106. $a[$k] = $v;
  107. return $a;
  108. }
  109. function prepareTextarea ($sTitle, $a)
  110. {
  111. ksort($a);
  112. return '<h2>' . $sTitle . '</h2>
  113. <textarea style="width:800px; height:400px;">' . var_export($a, 1) . '</textarea>
  114. <hr class="bx-def-hr bx-def-margin-top bx-def-margin-bottom" />';
  115. }
  116. function prepareTextareaWithDeltedKeys ($a)
  117. {
  118. $iGroupBy = 75;
  119. ksort($a);
  120. $aKeys = array_keys($a);
  121. for ($i = 0; $i < count($aKeys) ; $i+=$iGroupBy) {
  122. $sKeys = '';
  123. $aKeysSlice = array ();
  124. $aKeysSlice = array_slice($aKeys, $i, $iGroupBy, true);
  125. foreach ($aKeysSlice as $k)
  126. $sKeys .= "'" . str_replace("'", "\\'", $k) . "',";
  127. $sKeys = trim($sKeys, ',');
  128. $s .= "
  129. DELETE `sys_localization_strings` FROM `sys_localization_strings`, `sys_localization_keys` WHERE `sys_localization_keys`.`ID` = `sys_localization_strings`.`IDKey` AND `sys_localization_keys`.`Key` IN($sKeys);
  130. DELETE FROM `sys_localization_keys` WHERE `Key` IN($sKeys);";
  131. }
  132. return "<h2>Deleted Keys SQL</h2>
  133. <textarea style=\"width:800px; height:300px;\">
  134. -- delete unused language keys
  135. $s
  136. </textarea>
  137. <hr class=\"bx-def-hr bx-def-margin-top bx-def-margin-bottom\" />";
  138. }