Diff of /compile.php [18d51c] .. [d513de] Maximize Restore

  Switch to unified view

a/compile.php b/compile.php
...
...
40
    if (basename($match[2]) == '$LANG.inc.php') {
40
    if (basename($match[2]) == '$LANG.inc.php') {
41
        return $match[0]; // processed later
41
        return $match[0]; // processed later
42
    }
42
    }
43
    $return = file_get_contents(dirname(__FILE__) . "/$project/$match[2]");
43
    $return = file_get_contents(dirname(__FILE__) . "/$project/$match[2]");
44
    if (basename($match[2]) != "lang.inc.php" || !$_SESSION["lang"]) {
44
    if (basename($match[2]) != "lang.inc.php" || !$_SESSION["lang"]) {
45
      if (basename($match[2]) == "lang.inc.php") {
46
          $return = str_replace('function lang($idf, $number = null) {', 'function lang($idf, $number = null) {
47
  if (is_string($idf)) { // compiled version uses numbers, string comes from a plugin
48
      // English translation is closest to the original identifiers //! pluralized translations are not found
49
      $pos = array_search($idf, get_translations("en")); //! this should be cached
50
      if ($pos !== false) {
51
          $idf = $pos;
52
      }
53
  }', $return, $count);
54
          if (!$count) {
55
              echo "lang() not found\n";
56
          }
57
      }
45
        $tokens = token_get_all($return); // to find out the last token
58
        $tokens = token_get_all($return); // to find out the last token
46
        return "?>\n$return" . (in_array($tokens[count($tokens) - 1][0], array(T_CLOSE_TAG, T_INLINE_HTML), true) ? "<?php" : "");
59
        return "?>\n$return" . (in_array($tokens[count($tokens) - 1][0], array(T_CLOSE_TAG, T_INLINE_HTML), true) ? "<?php" : "");
47
    } elseif (preg_match('~\\s*(\\$pos = (.+\n).+;)~sU', $return, $match2)) {
60
    } elseif (preg_match('~\\s*(\\$pos = (.+\n).+;)~sU', $return, $match2)) {
48
        // single language lang() is used for plural
61
        // single language lang() is used for plural
49
        return "function get_lang() {
62
        return "function get_lang() {
50
    return '$_SESSION[lang]';
63
    return '$_SESSION[lang]';
51
}
64
}
52
65
53
function lang(\$translation, \$number = 0) {
66
function lang(\$translation, \$number = null) {
54
    if (is_array(\$translation)) {
67
    if (is_array(\$translation)) {
55
        \$pos = $match2[2]\t\t\t: " . (preg_match("~\\\$LANG == '$_SESSION[lang]'.* \\? (.+)\n~U", $match2[1], $match3) ? $match3[1] : "1") . '
68
        \$pos = $match2[2]\t\t\t: " . (preg_match("~\\\$LANG == '$_SESSION[lang]'.* \\? (.+)\n~U", $match2[1], $match3) ? $match3[1] : "1") . '
56
        );
69
        );
57
        $translation = $translation[$pos];
70
        $translation = $translation[$pos];
58
    }
71
    }
...
...
60
    $number = number_format($number, 0, ".", lang(\',\'));
73
    $number = number_format($number, 0, ".", lang(\',\'));
61
    return sprintf($translation, $number);
74
    return sprintf($translation, $number);
62
}
75
}
63
';
76
';
64
    } else {
77
    } else {
65
        echo "lang() not found\n";
78
        echo "lang() \$pos not found\n";
66
    }
79
    }
67
}
80
}
68
81
69
function lzw_compress($string) {
82
function lzw_compress($string) {
70
    // compression
83
    // compression
...
...
124
    return '$translations = &$_SESSION["translations"];
137
    return '$translations = &$_SESSION["translations"];
125
if ($_SESSION["translations_version"] != ' . $translations_version . ') {
138
if ($_SESSION["translations_version"] != ' . $translations_version . ') {
126
    $translations = array();
139
    $translations = array();
127
    $_SESSION["translations_version"] = ' . $translations_version . ';
140
    $_SESSION["translations_version"] = ' . $translations_version . ';
128
}
141
}
129
if (!$translations) {
142
143
function get_translations($lang) {
130
    switch ($LANG) {' . $return . '
144
    switch ($lang) {' . $return . '
131
    }
145
    }
132
    $translations = array();
146
    $translations = array();
133
    foreach (explode("\n", lzw_decompress($compressed)) as $val) {
147
    foreach (explode("\n", lzw_decompress($compressed)) as $val) {
134
        $translations[] = (strpos($val, "\t") ? explode("\t", $val) : $val);
148
        $translations[] = (strpos($val, "\t") ? explode("\t", $val) : $val);
135
    }
149
    }
150
  return $translations;
151
}
152
153
if (!$translations) {
154
  $translations = get_translations($LANG);
136
}
155
}
137
';
156
';
138
}
157
}
139
158
140
function short_identifier($number, $chars) {
159
function short_identifier($number, $chars) {