PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/public/library/xinha/contrib/lc_parse_strings.php

https://bitbucket.org/farouqzaib/precurio
PHP | 325 lines | 263 code | 41 blank | 21 comment | 53 complexity | 2c0c91303e51162658feb1a8fd64fc7b MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, MIT, LGPL-2.1
  1. <?php
  2. die("this script is disabled for security");
  3. /**
  4. * LC-Parse-Strings-Script
  5. *
  6. * This script parses all xinhas source-files and creates base lang-files
  7. * in the lang-folders (one for base and one every plugin)
  8. *
  9. * How To use it: - remove the die() in line 2 (security)
  10. * - make sure all lang-folders are writeable for your webserver
  11. * - open the contrib/lc_parse_strings.php in your browser
  12. * - lang/base.js will be written
  13. * - open base.js, translate all strings into your language and save it
  14. * as yourlangauge.js
  15. * - send the translated file to the xinha-team
  16. **/
  17. error_reporting(E_ALL);
  18. $ret = array();
  19. $files = getFiles("../", "js$");
  20. foreach($files as $file) {
  21. $fp = fopen($file, "r");
  22. $data = "";
  23. while(!feof($fp)) {
  24. $data .= fread($fp, 1024);
  25. }
  26. preg_match_all('#_lc\("([^"]+)"\)|_lc\(\'([^\']+)\'\)#', $data, $m);
  27. foreach($m[1] as $i) {
  28. if(trim($i)=="") continue;
  29. $ret[] = $i;
  30. }
  31. foreach($m[2] as $i) {
  32. if(trim($i)=="") continue;
  33. $ret[] = $i;
  34. }
  35. if(eregi('htmlarea\\.js$', $file)) {
  36. //toolbar-buttons
  37. //bold: [ "Bold"
  38. preg_match_all('#[a-z]+: *\[ * "([^"]+)"#', $data, $m);
  39. foreach($m[1] as $i) {
  40. if(trim($i)=="") continue;
  41. $ret[] = $i;
  42. }
  43. //HTMLArea._lc({key: 'button_bold', string
  44. preg_match_all('#HTMLArea\\._lc\\({key: \'([^\']*)\'#', $data, $m);
  45. foreach($m[1] as $i) {
  46. if(trim($i)=="") continue;
  47. $ret[] = $i;
  48. }
  49. //config.fontname, fontsize and formatblock
  50. $data = substr($data, strpos($data, "this.fontname = {"), strpos($data, "this.customSelects = {};")-strpos($data, "this.fontname = {"));
  51. preg_match_all('#"([^"]+)"[ \t]*:[ \t]*["\'][^"\']*["\'],?#', $data, $m);
  52. foreach($m[1] as $i) {
  53. if(trim($i)=="") continue;
  54. $ret[] = $i;
  55. }
  56. }
  57. }
  58. $files = getFiles("../popups/", "html$");
  59. foreach($files as $file)
  60. {
  61. if(preg_match("#custom2.html$#", $file)) continue;
  62. if(preg_match('#old_#', $file)) continue;
  63. $ret = array_merge($ret, parseHtmlFile($file));
  64. }
  65. $ret = array_unique($ret);
  66. $langData['HTMLArea'] = $ret;
  67. $plugins = getFiles("../plugins/");
  68. foreach($plugins as $pluginDir) {
  69. $plugin = substr($pluginDir, 12);
  70. if($plugin=="ibrowser") continue;
  71. $ret = array();
  72. $files = getFiles("$pluginDir/", "js$");
  73. $files = array_merge($files, getFiles("$pluginDir/popups/", "html$"));
  74. $files = array_merge($files, getFiles("$pluginDir/", "php$"));
  75. foreach($files as $file)
  76. {
  77. $fp = fopen($file, "r");
  78. $data = "";
  79. if($fp) {
  80. echo "$file open...<br>";
  81. while(!feof($fp)) {
  82. $data .= fread($fp, 1024);
  83. }
  84. preg_match_all('#_lc\("([^"]+)"|_lc\(\'([^\']+)\'#', $data, $m);
  85. foreach($m[1] as $i) {
  86. if(trim(strip_tags($i))=="") continue;
  87. $ret[] = $i;
  88. }
  89. foreach($m[2] as $i) {
  90. if(trim(strip_tags($i))=="") continue;
  91. $ret[] = $i;
  92. }
  93. }
  94. }
  95. if($plugin=="TableOperations")
  96. {
  97. preg_match_all('#options = \\[([^\\]]+)\\];#', $data, $m);
  98. foreach($m[1] as $i) {
  99. preg_match_all('#"([^"]+)"#', $i, $m1);
  100. foreach($m1[1] as $i) {
  101. $ret[] = $i;
  102. }
  103. }
  104. //["cell-delete", "td", "Delete cell"],
  105. preg_match_all('#\\["[^"]+",[ \t]*"[^"]+",[ \t]*"([^"]+)"\\]#', $data, $m);
  106. foreach($m[1] as $i) {
  107. $ret[] = $i;
  108. }
  109. }
  110. $files = getFiles("$pluginDir/", "html$");
  111. $files = array_merge($files, getFiles("$pluginDir/", "php$"));
  112. foreach($files as $file)
  113. {
  114. $ret = array_merge($ret, parseHtmlFile($file, $plugin));
  115. }
  116. $files = getFiles("$pluginDir/popups/", "html$");
  117. foreach($files as $file)
  118. {
  119. $ret = array_merge($ret, parseHtmlFile($file, $plugin));
  120. }
  121. $ret = array_unique($ret);
  122. $langData[$plugin] = $ret;
  123. }
  124. $plugins = getFiles("../modules/");
  125. foreach($plugins as $pluginDir) {
  126. $plugin = substr($pluginDir, 12);
  127. $ret = array();
  128. $files = getFiles("$pluginDir/", "js$");
  129. foreach($files as $file)
  130. {
  131. $fp = fopen($file, "r");
  132. $data = "";
  133. if($fp) {
  134. echo "$file open...<br>";
  135. while(!feof($fp)) {
  136. $data .= fread($fp, 1024);
  137. }
  138. preg_match_all('#_lc\("([^"]+)"|_lc\(\'([^\']+)\'#', $data, $m);
  139. foreach($m[1] as $i) {
  140. if(trim(strip_tags($i))=="") continue;
  141. $ret[] = $i;
  142. }
  143. foreach($m[2] as $i) {
  144. if(trim(strip_tags($i))=="") continue;
  145. $ret[] = $i;
  146. }
  147. }
  148. }
  149. $ret = array_unique($ret);
  150. $langData[$plugin] = $ret;
  151. }
  152. foreach($langData as $plugin=>$strings) {
  153. if(sizeof($strings)==0) continue;
  154. $data = "// I18N constants\n";
  155. $data .= "//\n";
  156. $data .= "// LANG: \"base\", ENCODING: UTF-8\n";
  157. $data .= "// Author: Translator-Name, <email@example.com>\n";
  158. $data .= "//\n";
  159. $data .= "// Last revision: 06 september 2007\n";
  160. $data .= "// Please donĀ“t remove this information\n";
  161. $data .= "// If you modify any source, please insert a comment with your name and e-mail\n";
  162. $data .= "//\n";
  163. $data .= "// Distributed under the same terms as HTMLArea itself.\n";
  164. $data .= "// This notice MUST stay intact for use (see license.txt).\n";
  165. $data .= "//\n";
  166. $data .= "// (Please, remove information below)\n";
  167. $data .= "// FOR TRANSLATORS:\n";
  168. $data .= "//\n";
  169. $data .= "// 1. PLEASE PUT YOUR CONTACT INFO IN THE ABOVE LINE\n";
  170. $data .= "// (at least a valid email address)\n";
  171. $data .= "//\n";
  172. $data .= "// 2. PLEASE TRY TO USE UTF-8 FOR ENCODING;\n";
  173. $data .= "// (if this is not possible, please include a comment\n";
  174. $data .= "// that states what encoding is necessary.)\n";
  175. $data .= "\n";
  176. $data .= "{\n";
  177. sort($strings);
  178. foreach($strings as $string) {
  179. $string = str_replace(array('\\', '"'), array('\\\\', '\\"'), $string);
  180. $data .= " \"".$string."\": \"\",\n";
  181. }
  182. $data = substr($data, 0, -2);
  183. $data .= "\n";
  184. $data .= "}\n";
  185. if($plugin=="HTMLArea") {
  186. $file = "../lang/base.js";
  187. $fp = fopen($file, "w");
  188. if(!$fp) continue;
  189. fwrite($fp, $data);
  190. fclose($fp);
  191. echo "$file written...<br>";
  192. } elseif (($plugin=="InternetExplorer")||($plugin=="InsertTable")||($plugin=="InsertImage")||($plugin=="GetHtml")||($plugin=="Gecko")||($plugin=="Dialogs")||($plugin=="CreateLink")||($plugin=="ColorPicker")) {
  193. $file = "../modules/$plugin/lang/base.js";
  194. $fp = fopen($file, "w");
  195. if(!$fp) continue;
  196. fwrite($fp, $data);
  197. fclose($fp);
  198. echo "$file written...<br>";
  199. } elseif ($plugin=="FullScreen") {
  200. $file = "../modules/$plugin/lang/base.js";
  201. $fp = fopen($file, "w");
  202. if(!$fp) continue;
  203. fwrite($fp, $data);
  204. fclose($fp);
  205. echo "$file written...<br>";
  206. $file = "../plugins/$plugin/lang/base.js";
  207. $fp = fopen($file, "w");
  208. if(!$fp) continue;
  209. fwrite($fp, $data);
  210. fclose($fp);
  211. echo "$file written...<br>";
  212. } else {
  213. $file = "../plugins/$plugin/lang/base.js";
  214. $fp = fopen($file, "w");
  215. if(!$fp) continue;
  216. fwrite($fp, $data);
  217. fclose($fp);
  218. echo "$file written...<br>";
  219. }
  220. }
  221. function parseHtmlFile($file, $plugin="")
  222. {
  223. $ret = array();
  224. $fp = fopen($file, "r");
  225. if(!$fp) {
  226. die("invalid fp");
  227. }
  228. $data = "";
  229. while(!feof($fp)) {
  230. $data .= fread($fp, 1024);
  231. }
  232. if($plugin=="FormOperations" || $plugin=="SuperClean" || $plugin=="Linker") {
  233. //<l10n>-tags for inline-dialog or panel-dialog based dialogs
  234. $elems = array("l10n");
  235. } else {
  236. $elems = array("title", "input", "select", "legend", "span", "option", "td", "button", "div", "label");
  237. }
  238. foreach($elems as $elem) {
  239. preg_match_all("#<{$elem}[^>]*>([^<^\"]+)</$elem>#i", $data, $m);
  240. foreach($m[1] as $i) {
  241. if(trim(strip_tags($i))=="") continue;
  242. if($i=="/") continue;
  243. if($plugin=="ImageManager" && preg_match('#^--+$#', $i)) continue; //skip those ------
  244. if($plugin=="CharacterMap" && preg_match('#&[a-z0-9]+;#i', trim($i)) || $i=="@") continue;
  245. if($plugin=="SpellChecker" && preg_match('#^\'\\.\\$[a-z]+\\.\'$#', $i)) continue;
  246. $ret[] = trim($i);
  247. }
  248. }
  249. if($plugin=="FormOperations" || $plugin=="SuperClean" || $plugin=="Linker")
  250. {
  251. //_( for inline-dialog or panel-dialog based dialogs
  252. preg_match_all('#"_\(([^"]+)\)"#i', $data, $m);
  253. foreach($m[1] as $i) {
  254. if(trim($i)=="") continue;
  255. $ret[] = $i;
  256. }
  257. }
  258. else
  259. {
  260. preg_match_all('#title="([^"]+)"#i', $data, $m);
  261. foreach($m[1] as $i) {
  262. if(trim(strip_tags($i))=="") continue;
  263. if(strip_tags($i)==" - ") continue; //skip those - (ImageManager)
  264. $ret[] = $i;
  265. }
  266. }
  267. return($ret);
  268. }
  269. function getFiles($rootdirpath, $eregi_match='') {
  270. $array = array();
  271. if ($dir = @opendir($rootdirpath)) {
  272. $array = array();
  273. while (($file = readdir($dir)) !== false) {
  274. if($file=="." || $file==".." || $file==".svn") continue;
  275. if($eregi_match=="")
  276. $array[] = $rootdirpath."/".$file;
  277. else if(eregi($eregi_match,$file))
  278. $array[] = $rootdirpath."/".$file;
  279. }
  280. closedir($dir);
  281. }
  282. return $array;
  283. }
  284. ?>