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