Passed
Push — 1.11.x ( bce6cd...c146d9 )
by Angel Fernando Quiroz
12:25
created

main/cron/lang/list_undefined_langvars.php (1 issue)

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