| 1 | <? |
|---|
| 2 | error_reporting(E_ALL); |
|---|
| 3 | |
|---|
| 4 | $ret = array(); |
|---|
| 5 | $files = getFiles("./", "js$"); |
|---|
| 6 | foreach($files as $file) |
|---|
| 7 | { |
|---|
| 8 | $fp = fopen($file, "r"); |
|---|
| 9 | $data = ""; |
|---|
| 10 | while(!feof($fp)) { |
|---|
| 11 | $data .= fread($fp, 1024); |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | preg_match_all('#_lc\("([^"]+)"\)|_lc\(\'([^\']+)\'\)#', $data, $m); |
|---|
| 15 | foreach($m[1] as $i) { |
|---|
| 16 | if(trim($i)=="") continue; |
|---|
| 17 | $ret[] = $i; |
|---|
| 18 | } |
|---|
| 19 | foreach($m[2] as $i) { |
|---|
| 20 | if(trim($i)=="") continue; |
|---|
| 21 | $ret[] = $i; |
|---|
| 22 | } |
|---|
| 23 | if($file=="htmlarea.js") { |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | preg_match_all('#[a-z]+: *\[ * "([^"]+)"#', $data, $m); |
|---|
| 27 | foreach($m[1] as $i) { |
|---|
| 28 | if(trim($i)=="") continue; |
|---|
| 29 | $ret[] = $i; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | $data = substr($data, strpos($data, "this.fontname = {"), strpos($data, "this.customSelects = {};")-strpos($data, "this.fontname = {")); |
|---|
| 34 | preg_match_all('#"([^"]+)"[ \t]*:[ \t]*["\'][^"\']*["\'],?#', $data, $m); |
|---|
| 35 | foreach($m[1] as $i) { |
|---|
| 36 | if(trim($i)=="") continue; |
|---|
| 37 | $ret[] = $i; |
|---|
| 38 | } |
|---|
| 39 | } |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | $files = getFiles("./popups/", "html$"); |
|---|
| 43 | foreach($files as $file) |
|---|
| 44 | { |
|---|
| 45 | if(preg_match("#custom2.html$#", $file)) continue; |
|---|
| 46 | if(preg_match('#old_#', $file)) continue; |
|---|
| 47 | $ret = array_merge($ret, parseHtmlFile($file)); |
|---|
| 48 | } |
|---|
| 49 | $ret = array_unique($ret); |
|---|
| 50 | $langData['HTMLArea'] = $ret; |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | $plugins = getFiles("./plugins/"); |
|---|
| 55 | foreach($plugins as $pluginDir) |
|---|
| 56 | { |
|---|
| 57 | $plugin = substr($pluginDir, 11); |
|---|
| 58 | if($plugin=="ibrowser") continue; |
|---|
| 59 | $ret = array(); |
|---|
| 60 | |
|---|
| 61 | $files = getFiles("$pluginDir/", "js$"); |
|---|
| 62 | $files = array_merge($files, getFiles("$pluginDir/popups/", "html$")); |
|---|
| 63 | $files = array_merge($files, getFiles("$pluginDir/", "php$")); |
|---|
| 64 | foreach($files as $file) |
|---|
| 65 | { |
|---|
| 66 | $fp = fopen($file, "r"); |
|---|
| 67 | $data = ""; |
|---|
| 68 | while(!feof($fp)) { |
|---|
| 69 | $data .= fread($fp, 1024); |
|---|
| 70 | } |
|---|
| 71 | preg_match_all('#_lc\("([^"]+)"|_lc\(\'([^\']+)\'#', $data, $m); |
|---|
| 72 | foreach($m[1] as $i) { |
|---|
| 73 | if(trim(strip_tags($i))=="") continue; |
|---|
| 74 | $ret[] = $i; |
|---|
| 75 | } |
|---|
| 76 | foreach($m[2] as $i) { |
|---|
| 77 | if(trim(strip_tags($i))=="") continue; |
|---|
| 78 | $ret[] = $i; |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | if($plugin=="TableOperations") |
|---|
| 83 | { |
|---|
| 84 | preg_match_all('#options = \\[([^\\]]+)\\];#', $data, $m); |
|---|
| 85 | foreach($m[1] as $i) { |
|---|
| 86 | preg_match_all('#"([^"]+)"#', $i, $m1); |
|---|
| 87 | foreach($m1[1] as $i) { |
|---|
| 88 | $ret[] = $i; |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | preg_match_all('#\\["[^"]+",[ \t]*"[^"]+",[ \t]*"([^"]+)"\\]#', $data, $m); |
|---|
| 94 | foreach($m[1] as $i) { |
|---|
| 95 | $ret[] = $i; |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | $files = getFiles("$pluginDir/", "html$"); |
|---|
| 101 | $files = array_merge($files, getFiles("$pluginDir/", "php$")); |
|---|
| 102 | foreach($files as $file) |
|---|
| 103 | { |
|---|
| 104 | $ret = array_merge($ret, parseHtmlFile($file, $plugin)); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | $files = getFiles("$pluginDir/popups/", "html$"); |
|---|
| 108 | foreach($files as $file) |
|---|
| 109 | { |
|---|
| 110 | $ret = array_merge($ret, parseHtmlFile($file, $plugin)); |
|---|
| 111 | } |
|---|
| 112 | $ret = array_unique($ret); |
|---|
| 113 | |
|---|
| 114 | $langData[$plugin] = $ret; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | foreach($langData as $plugin=>$strings) |
|---|
| 118 | { |
|---|
| 119 | if(sizeof($strings)==0) continue; |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | $data = "// I18N constants\n"; |
|---|
| 123 | $data .= "//\n"; |
|---|
| 124 | $data .= "//LANG: \"base\", ENCODING: UTF-8\n"; |
|---|
| 125 | $data .= "//Author: Translator-Name, <email@example.com>\n"; |
|---|
| 126 | $data .= "// FOR TRANSLATORS:\n"; |
|---|
| 127 | $data .= "//\n"; |
|---|
| 128 | $data .= "// 1. PLEASE PUT YOUR CONTACT INFO IN THE ABOVE LINE\n"; |
|---|
| 129 | $data .= "// (at least a valid email address)\n"; |
|---|
| 130 | $data .= "//\n"; |
|---|
| 131 | $data .= "// 2. PLEASE TRY TO USE UTF-8 FOR ENCODING;\n"; |
|---|
| 132 | $data .= "// (if this is not possible, please include a comment\n"; |
|---|
| 133 | $data .= "// that states what encoding is necessary.)\n"; |
|---|
| 134 | $data .= "\n"; |
|---|
| 135 | $data .= "{\n"; |
|---|
| 136 | sort($strings); |
|---|
| 137 | foreach($strings as $string) { |
|---|
| 138 | $string = str_replace(array('\\', '"'), array('\\\\', '\\"'), $string); |
|---|
| 139 | $data .= " \"".$string."\": \"\",\n"; |
|---|
| 140 | } |
|---|
| 141 | $data = substr($data, 0, -2); |
|---|
| 142 | $data .= "\n"; |
|---|
| 143 | $data .= "}\n"; |
|---|
| 144 | |
|---|
| 145 | if($plugin=="HTMLArea") |
|---|
| 146 | $file = "lang/base.js"; |
|---|
| 147 | else |
|---|
| 148 | $file = "plugins/$plugin/lang/base.js"; |
|---|
| 149 | |
|---|
| 150 | $fp = fopen($file, "w"); |
|---|
| 151 | if(!$fp) continue; |
|---|
| 152 | fwrite($fp, $data); |
|---|
| 153 | fclose($fp); |
|---|
| 154 | echo "$file written...<br>"; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | function parseHtmlFile($file, $plugin="") |
|---|
| 161 | { |
|---|
| 162 | $ret = array(); |
|---|
| 163 | |
|---|
| 164 | $fp = fopen($file, "r"); |
|---|
| 165 | if(!$fp) { |
|---|
| 166 | die("invalid fp"); |
|---|
| 167 | } |
|---|
| 168 | $data = ""; |
|---|
| 169 | while(!feof($fp)) { |
|---|
| 170 | $data .= fread($fp, 1024); |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | if($plugin=="FormOperations" || $plugin=="SuperClean" || $plugin=="Linker") { |
|---|
| 174 | |
|---|
| 175 | $elems = array("l10n"); |
|---|
| 176 | } else { |
|---|
| 177 | $elems = array("title", "input", "select", "legend", "span", "option", "td", "button", "div", "label"); |
|---|
| 178 | } |
|---|
| 179 | foreach($elems as $elem) { |
|---|
| 180 | preg_match_all("#<{$elem}[^>]*>([^<^\"]+)</$elem>#i", $data, $m); |
|---|
| 181 | foreach($m[1] as $i) { |
|---|
| 182 | if(trim(strip_tags($i))=="") continue; |
|---|
| 183 | if($i=="/") continue; |
|---|
| 184 | if($plugin=="ImageManager" && preg_match('#^--+$#', $i)) continue; |
|---|
| 185 | if($plugin=="CharacterMap" && preg_match('#&[a-z0-9]+;#i', trim($i)) || $i=="@") continue; |
|---|
| 186 | if($plugin=="SpellChecker" && preg_match('#^\'\\.\\$[a-z]+\\.\'$#', $i)) continue; |
|---|
| 187 | $ret[] = trim($i); |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | if($plugin=="FormOperations" || $plugin=="SuperClean" || $plugin=="Linker") |
|---|
| 192 | { |
|---|
| 193 | |
|---|
| 194 | preg_match_all('#"_\(([^"]+)\)"#i', $data, $m); |
|---|
| 195 | foreach($m[1] as $i) { |
|---|
| 196 | if(trim($i)=="") continue; |
|---|
| 197 | $ret[] = $i; |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | else |
|---|
| 201 | { |
|---|
| 202 | preg_match_all('#title="([^"]+)"#i', $data, $m); |
|---|
| 203 | foreach($m[1] as $i) { |
|---|
| 204 | if(trim(strip_tags($i))=="") continue; |
|---|
| 205 | if(strip_tags($i)==" - ") continue; |
|---|
| 206 | $ret[] = $i; |
|---|
| 207 | } |
|---|
| 208 | } |
|---|
| 209 | return($ret); |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | function getFiles($rootdirpath, $eregi_match='') { |
|---|
| 214 | $array = array(); |
|---|
| 215 | if ($dir = @opendir($rootdirpath)) { |
|---|
| 216 | $array = array(); |
|---|
| 217 | while (($file = readdir($dir)) !== false) { |
|---|
| 218 | if($file=="." || $file==".." || $file==".svn") continue; |
|---|
| 219 | if($eregi_match=="") |
|---|
| 220 | $array[] = $rootdirpath."/".$file; |
|---|
| 221 | else if(eregi($eregi_match,$file)) |
|---|
| 222 | $array[] = $rootdirpath."/".$file; |
|---|
| 223 | |
|---|
| 224 | } |
|---|
| 225 | closedir($dir); |
|---|
| 226 | } |
|---|
| 227 | return $array; |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | ?> |
|---|