list_undefined_langvars.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php /* For licensing terms, see /license.txt */
  2. /**
  3. * Cron script to list used, but undefined, language variables.
  4. *
  5. * @package chamilo.cron
  6. */
  7. /**
  8. * Includes and declarations.
  9. */
  10. die();
  11. require_once __DIR__.'/../../inc/global.inc.php';
  12. $path = api_get_path(SYS_LANG_PATH).'english';
  13. ini_set('memory_limit', '128M');
  14. /**
  15. * Main code.
  16. */
  17. $terms = [];
  18. $list = SubLanguageManager::get_lang_folder_files_list($path);
  19. foreach ($list as $entry) {
  20. $file = $path.'/'.$entry;
  21. if (is_file($file)) {
  22. $terms = array_merge($terms, SubLanguageManager::get_all_language_variable_in_file($file, true));
  23. }
  24. }
  25. // get only the array keys (the language variables defined in language files)
  26. $defined_terms = array_flip(array_keys($terms));
  27. $terms = null;
  28. $hidePlugins = !empty($_GET['hidePlugins']);
  29. // now get all terms found in all PHP files of Chamilo (this takes some time and memory)
  30. $undefined_terms = [];
  31. $l = strlen(api_get_path(SYS_PATH));
  32. $files = getAllPhpFiles(api_get_path(SYS_PATH));
  33. foreach ($files as $file) {
  34. $isPlugin = preg_match('#/plugin/#', $file);
  35. if ($isPlugin && $hidePlugins) {
  36. continue;
  37. }
  38. //echo 'Analyzing '.$file."<br />";
  39. $shortfile = substr($file, $l);
  40. $lines = file($file);
  41. foreach ($lines as $line) {
  42. $myterms = [];
  43. $res = preg_match_all('/get_lang\(\'(\\w*)\'\)/', $line, $myterms);
  44. if ($res > 0) {
  45. foreach ($myterms[1] as $term) {
  46. if (!isset($defined_terms[$term]) && !isset($defined_terms['lang'.$term])) {
  47. $undefined_terms[$term] = $shortfile;
  48. //echo "Undefined: $term<br />";
  49. }
  50. }
  51. }
  52. $res = 0;
  53. $res = preg_match_all('/\{[\'"](\\w*)[\'"]\|get_lang\}/', $line, $myterms);
  54. if ($res > 0) {
  55. foreach ($myterms[1] as $term) {
  56. if (!isset($defined_terms[$term]) && !isset($defined_terms['lang'.$term])) {
  57. $undefined_terms[$term] = $shortfile;
  58. //echo "Undefined: $term<br />";
  59. }
  60. }
  61. }
  62. }
  63. flush();
  64. }
  65. //$undefined_terms = array_flip($undefined_terms);
  66. if (count($undefined_terms) < 1) {
  67. die("No missing terms<br />\n");
  68. } else {
  69. echo "The following terms were nowhere to be found: <br />\n<table>";
  70. }
  71. $i = 1;
  72. foreach ($undefined_terms as $term => $file) {
  73. $isPlugin = substr($file, 0, 7) == 'plugin/';
  74. echo "<tr><td>$i</td><td>$term</td><td>in $file";
  75. if ($isPlugin) {
  76. echo " <span style=\"color: #00ff00;\">(this one should be taken care of by the plugin's language files)</span>";
  77. }
  78. echo "</td></tr>\n";
  79. $i++;
  80. }
  81. echo "</table>\n";