PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/source/unused/html/lang.php

http://sharebooks.googlecode.com/
PHP | 425 lines | 388 code | 23 blank | 14 comment | 45 complexity | e6c142e060dca974a4d42861eb2b58c0 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. include_once('define.php');
  3. include_once('filter.class.php');
  4. //edit value of constant
  5. if (isset($_POST['btn_edit']) && ($_POST['btn_edit']))
  6. {
  7. $key = $_POST['hidden_value_edit'];
  8. $file = $_POST['hidden_file_edit'];
  9. $en = $_POST['en'];
  10. $fr = $_POST['fr'];
  11. $de = $_POST['de'];
  12. $es = $_POST['es'];
  13. $it = $_POST['it'];
  14. $current_lang_group = '';
  15. $input = "";
  16. $lines = file("{$root}{$file}");
  17. foreach($lines as $key1 => $line) {
  18. if(preg_match("@^\[([en]+)\]$@U", $line, $out)) {
  19. $current_lang_group = 'en';
  20. }
  21. if(preg_match("@^\[([fr]+)\]$@U", $line, $out)) {
  22. $current_lang_group = 'fr';
  23. }
  24. if(preg_match("@^\[([de]+)\]$@U", $line, $out)) {
  25. $current_lang_group = 'de';
  26. }
  27. if(preg_match("@^\[([es]+)\]$@U", $line, $out)) {
  28. $current_lang_group = 'es';
  29. }
  30. if(preg_match("@^\[([it]+)\]$@U", $line, $out)) {
  31. $current_lang_group = 'it';
  32. }
  33. $line = trim($line);
  34. if(!preg_match("@(^{$key})( =|=)@U", $line) && $line != "") {
  35. $input .= "{$line}\n";
  36. }
  37. else {
  38. if($line != "")
  39. $input .= "{$key} = {$$current_lang_group}\n";
  40. }
  41. }
  42. $file = "{$root}{$file}";
  43. $fp = fopen($file, "w");
  44. fwrite($fp, $input);
  45. fclose($fp);
  46. echo json_encode(array("rep"=> "ok"));
  47. exit;
  48. }
  49. $filter = new filter();
  50. /*
  51. * cache file action.
  52. */
  53. if(isset($_POST['d'])) {
  54. $key = $_POST['d'];
  55. $files = $_POST['f'];
  56. foreach($files as $i => $file) {
  57. $input = ""; $cacheInput = "";
  58. $lines = file("{$root}{$file}");
  59. foreach($lines as $key1 => $line) {
  60. $line = trim($line);
  61. if(!preg_match("@(^{$key})( =|=)@U", $line) && $line != "") {
  62. $input .= "{$line}\n";
  63. } else {
  64. if($line != "")
  65. $cacheInput .= "{$line}\n";
  66. }
  67. if(preg_match("@^\[([en|de|fr|es|it]+)\]$@U", $line, $out)) {
  68. $cacheInput .= "{$line}\n";
  69. }
  70. }
  71. $file = "{$root}{$file}";
  72. $fp = fopen($file, "w");
  73. fwrite($fp, $input);
  74. fclose($fp);
  75. // cache
  76. $cacheFile = str_replace('/', '-', $file);
  77. $cacheFileHandle = fopen("{$cache_lang_dir}{$cacheFile}", 'w');
  78. fwrite($cacheFileHandle, $cacheInput);
  79. fclose($cacheFileHandle);
  80. }
  81. echo json_encode(array("rep"=> "ok"));
  82. exit;
  83. }
  84. /*
  85. * restore cache action.
  86. */
  87. if(isset($_POST['r'])) {
  88. $key = $_POST['r'];
  89. $files = $_POST['f']; // <array>
  90. $contains = array();
  91. foreach($files as $i => $file) {
  92. $filename = str_replace($cache_lang_dir, '', $file);
  93. $lines = file($file); $lang = '';
  94. foreach($lines as $key => $line) {
  95. $line = trim($line);
  96. if(preg_match("@^\[([en|de|fr|es|it]+)\]$@U", $line, $out)) {
  97. $lang = $out[1];
  98. continue;
  99. }
  100. if(empty($lang) || empty($line))
  101. continue;
  102. preg_match_all('/(.*)=(.*)/', $line, $data);
  103. if(!isset($data[1][0]) || !isset($data[2][0])) {
  104. continue;
  105. }
  106. $code = trim($data[1][0]);
  107. $detail = trim($data[2][0]);
  108. $contains[$filename][$lang] = array(
  109. 'key' => $code, 'value' => $detail
  110. );
  111. }
  112. // restore
  113. $fileuse = str_replace('-', '/', $filename);
  114. $ulines = file($fileuse);
  115. $input = '';
  116. foreach($ulines as $j => $uline) {
  117. $uline = trim($uline);
  118. if(preg_match("@^\[([en|de|fr|es|it]+)\]$@U", $uline, $out)) {
  119. $input .= "$out[0]\n";
  120. $input .= "{$contains[$filename][$out[1]]['key']} = {$contains[$filename][$out[1]]['value']}\n";
  121. continue;
  122. }
  123. $input .= "{$uline}\n";
  124. }
  125. $fp = fopen($fileuse, "w");
  126. fwrite($fp, $input);
  127. fclose($fp);
  128. unlink($file);
  129. }
  130. echo json_encode(array('rep' => 'ok'));
  131. exit;
  132. }
  133. // lang key on disk
  134. $langfiles = $filter->dirfiles($view_dir, array('.svn'), array('ini'));
  135. $langkeys = $filter->getkeys($langfiles, $root);
  136. // key to use
  137. $useinifiles = $filter->dirfiles(
  138. "{$root}",
  139. array('.svn', 'config', 'files', 'language', 'logs', 'templates_pub'),
  140. array('html', 'php')
  141. );
  142. $contains = Array();
  143. foreach($useinifiles as $key => $file) {
  144. $info = pathinfo($file);
  145. $content = file_get_contents($file);
  146. $output = Array();
  147. if($info['extension'] == 'php') {
  148. preg_match_all("@({$prefix_lang})(.*)('|\")@U", $content, $out);
  149. if(count($out[0]) > 0) {
  150. $output = $out[0];
  151. }
  152. }
  153. if($info['extension'] == 'html') {
  154. preg_match_all("@#([A-Z0-9_]+)#@U", $content, $out);
  155. if(count($out[1]) > 0) {
  156. $output = $out[1];
  157. }
  158. }
  159. if(count($output) > 0) {
  160. foreach($output as $key => $value) {
  161. $value = str_replace("'", '', $value);
  162. $value = str_replace('"', '', $value);
  163. if (isset($contains[$value][$file][0]))
  164. {
  165. $appearance_time = $contains[$value][$file][0] + 1;
  166. }
  167. else
  168. {
  169. $appearance_time = 1;
  170. }
  171. $contains[$value][$file][0] = $appearance_time;
  172. $line_array = file($file);
  173. foreach($line_array as $i => $line)
  174. {
  175. if (strpos($line, $value))
  176. {
  177. $contains[$value][$file][1] = trim($line_array[$i]);
  178. break;
  179. }
  180. }
  181. }
  182. }
  183. }
  184. // cache file
  185. $cachekeys = Array();
  186. $cachefiles = $filter->files($cache_lang_dir, array('ini'));
  187. foreach($cachefiles as $key => $file) {
  188. $cachefiles[$key] = "{$cache_lang_dir}{$file}";
  189. }
  190. $cachekeys = $filter->getkeys($cachefiles, $root);
  191. ?>
  192. <html>
  193. <head>
  194. <title>Language unused</title>
  195. <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
  196. <script type="text/javascript">
  197. $(document).ready(function(){
  198. $('.true').click(function(){
  199. var panel = $(this).next();
  200. if(panel.is(':hidden')) {
  201. panel.show();
  202. } else {
  203. panel.hide();
  204. }
  205. return false;
  206. });
  207. $('.delete').click(function(){
  208. var self = $(this);
  209. $.post(window.location.href, self.attr('href'), function(data){
  210. if(data.rep == 'ok') {
  211. window.location.reload();
  212. } else {
  213. alert("Error!");
  214. }
  215. }, 'json');
  216. return false;
  217. });
  218. $('.restore').click(function(){
  219. var self = $(this);
  220. $.post(window.location.href, self.attr('href'), function(data){
  221. if(data.rep == 'ok') {
  222. window.location.reload();
  223. } else {
  224. alert("Error!");
  225. }
  226. }, 'json');
  227. return false;
  228. });
  229. });
  230. function popup_exit()
  231. {
  232. var element = document.getElementById('popup');
  233. element.style.display = 'none';
  234. }
  235. function popup_show(key, file_name, en, fr, de, es, it)
  236. {
  237. var element = document.getElementById('popup');
  238. var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth;
  239. var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
  240. element.style.position = "absolute";
  241. element.style.display = "block";
  242. element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth )/2)+'px';
  243. element.style.top = (document.documentElement.scrollTop +(height-element.clientHeight)/2)+'px';
  244. document.getElementById('value_edit').innerHTML = 'EDIT: ' + key;
  245. document.getElementById('file_edit').innerHTML = 'FILE: ' + file_name;
  246. document.getElementById('en').value = en;
  247. document.getElementById('fr').value = fr;
  248. document.getElementById('de').value = de;
  249. document.getElementById('es').value = es;
  250. document.getElementById('it').value = it;
  251. document.getElementById('hidden_value_edit').value = key;
  252. document.getElementById('hidden_file_edit').value = file_name;
  253. }
  254. </script>
  255. <style type="text/css">
  256. .result {
  257. background-color:#f1f1f1;
  258. border:1px solid #ccc;
  259. padding:5px;
  260. margin:0px;
  261. margin-bottom:10px;
  262. color:#333
  263. }
  264. table {
  265. background-color:#eee;
  266. }
  267. .tr {
  268. text-transform: uppercase;
  269. font-weight:bold;
  270. background-color:#ccc;
  271. }
  272. .keys {
  273. }
  274. .keysuse {
  275. color:#060
  276. }
  277. .true {
  278. color:#060;cursor:pointer;font-weight:bold
  279. }
  280. .restore,
  281. .delete {
  282. color:#f00;font-weight:bold
  283. }
  284. .example {
  285. color:#090;
  286. }
  287. div.popup {
  288. z-index: 1;
  289. width: 1000px;
  290. border: 1px solid black;
  291. background-color: #216072;
  292. text-align: center;
  293. }
  294. </style>
  295. </head>
  296. <body>
  297. <?php
  298. if(count($cachekeys) > 0) {
  299. ?>
  300. <h1>Files delete</h1>
  301. <pre class="result">
  302. <?php
  303. foreach($cachekeys['en'] as $key => $files) {
  304. $paramfiles = ''; $cachefiles = '<div class="keysuse">';
  305. if(count($files) > 0) {
  306. foreach($files as $file => $value) {
  307. $paramfiles .= "&f[]={$file}";
  308. $cachefiles .= "\t{$file}\n";
  309. }
  310. }
  311. $cachefiles .= '</div>';
  312. echo "<div class=\"keys\">{$key} <a href=\"r={$key}{$paramfiles}\" class=\"restore\">restore</a>{$cachefiles}</div>";
  313. }
  314. ?>
  315. </pre>
  316. <?php
  317. }
  318. ?>
  319. <h1>Language unused</h1>
  320. <pre class="result">
  321. <?php
  322. //print_r($langkeys);
  323. foreach($langkeys['en'] as $key => $files) {
  324. $act = '';
  325. $key = str_replace($view_dir, "", $key);
  326. if(isset($contains[$key])) {
  327. $act .= '<a href="#" class="true">is use</a>';
  328. $act .= "<div>";
  329. $act .= "\t<strong>Files use</strong><div class=\"keysuse\">";
  330. foreach($contains[$key] as $keyuse => $value){
  331. $act .= "\t\t{$keyuse} ({$value[0]} times) <div class=\"example\">\t\t\t \"...".htmlentities($value[1])."...\" </div> \n";
  332. }
  333. $act .= '</div>';
  334. } else {
  335. $fileparams = '';
  336. if(count($files) > 0) {
  337. foreach($files as $file => $value) {
  338. $fileparams .= "&f[]={$file}";
  339. }
  340. }
  341. $act .= "<a href=\"d={$key}{$fileparams}\" class=\"delete\">delete</a>";
  342. $act .= '</div>';
  343. }
  344. $act .= "\t<strong>Language values</strong><table width=\"100%\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">";
  345. $act .= "<tr class=\"tr\">";
  346. $act .= "<td width=\"30%\">file</td>";
  347. $act .= "<td>en</td>";
  348. $act .= "<td>fr</td>";
  349. $act .= "<td>de</td>";
  350. $act .= "<td>es</td>";
  351. $act .= "<td>it</td>";
  352. $act .= "<td width=\"5%\">Edit</td>";
  353. $act .= "</tr>";
  354. foreach($langkeys['en'][$key] as $key1 => $val1) {
  355. $edit_string = "'" . $key . "', '" . $key1;
  356. $act .= "<tr>";
  357. $act .= "<td>{$key1}</td>";
  358. foreach($defines['language_code'] as $key2 => $val2) {
  359. if (!isset($langkeys[$val2][$key][$key1])) $langkeys[$val2][$key][$key1] = '';
  360. {
  361. $val3 = $langkeys[$val2][$key][$key1];
  362. }
  363. $act .= "<td>" . $val3 . "&nbsp;</td>";
  364. $edit_string .= "', '" . $val3;
  365. }
  366. $edit_string .= "'";
  367. $act .= "<td><a href='#' onclick=\"popup_show(" . $edit_string . ");\" >edit</a></td>";
  368. $act .= "</tr>";
  369. }
  370. $act .= '</table></div>';
  371. echo "<div class=\"keys\">{$key} {$act}</div>";
  372. //popup to edit value of a constant
  373. echo "
  374. <div class='popup' id='popup' style='display: none;'>
  375. <div align='center'>
  376. <form id = 'form_edit' name = 'form_edit' method='post' action=''>
  377. <table width='950px'>
  378. <input type='hidden' name='hidden_value_edit' id='hidden_value_edit' />
  379. <input type='hidden' name='hidden_file_edit' id='hidden_file_edit' />
  380. <tr><th></th><td width='900px' align='center' id='value_edit'>EDIT VALUE</td></tr>
  381. <tr><th></th><td width='900px' align='center' id='file_edit'>file_name</td></tr>
  382. <tr><th>EN:</th><td width='900px'><input size='110' type='text' name='en' id='en' /></td></tr>
  383. <tr><th>FR:</th><td width='900px'><input size='110' type='text' name='fr' id='fr' /></td></tr>
  384. <tr><th>DE:</th><td width='900px'><input size='110' type='text' name='de' id='de' /></td></tr>
  385. <tr><th>ES:</th><td width='900px'><input size='110' type='text' name='es' id='es' /></td></tr>
  386. <tr><th>IT:</th><td width='900px'><input size='110' type='text' name='it' id='it' /></td></tr>
  387. <tr><th></th>
  388. <td>
  389. <input class='btn' type='submit' value='Edit' name='btn_edit' id='btn_edit' />
  390. <input class='btn' onclick=\"popup_exit();\" type='button' value='Cancel' />
  391. </td>
  392. </tr>
  393. </table>
  394. </form>
  395. </div>
  396. </div>
  397. ";
  398. }
  399. ?>
  400. </pre>
  401. </body>
  402. </html>