php files explode trim shell_exec find -iname php messages array forea

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
$files = explode("\n", trim(shell_exec("find . -iname '*.php'")));
$messages = array();
foreach ($files as $file) {
$data = file_get_contents($file);
$n = preg_match_all("/L\s*\(\"(.*?)\"|L\s*\(\'(.*?)\'/", $data, $langs);
for ($i = 0; $i < $n; ++$i) {
if ($langs[1][$i] !== "") {
$lang = $langs[1][$i];
} elseif ($langs[2][$i] !== "") {
$lang = $langs[2][$i];
} else {
echo "[warn] empty L() at $file\n";
continue;
}
$lang = stripslashes($lang);
$msg_id = sprintf("%08X", crc32($lang));
if (isset($messages[$msg_id]) && $messages[$msg_id] !== $lang) {
echo "Коллизия! Пора меня хэш. (".$lang." != ".$messages[$msg_id].")\n";
exit;
}
$messages[$msg_id] = $lang;
}
}
$languages = array("en", "ua");
foreach ($languages as $lang) {
echo "[$lang]\n";
if (file_exists("lang/$lang.ini")) {
// Удалим старые
$lang_data = parse_ini_file("lang/$lang.ini");
foreach ($lang_data as $id => $msg) {
if (!isset($messages[$id])) {
echo " -$id\n";
unset($lang_data[$id]);
}
}
} else
$lang_data = array();
foreach ($messages as $id => $msg) {
if (!isset($lang_data[$id])) {
$lang_data[$id] = $msg;
echo " +$id\n";
}
}
$ini_data = "";
foreach ($lang_data as $id => $msg) {
$lang_escaped = addcslashes($msg, "\"\\\n\r\t\v\0");
$ini_data .= "; $lang_escaped\n";
$ini_data .= "$id = \"$lang_escaped\"\n";
}
file_put_contents("lang/$lang.ini", $ini_data);
}