merge_langs.php 4.6 KB

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