lang-check.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) Copyright (C) 2008 - 2013 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. error_reporting(E_ERROR);
  25. chdir("..");
  26. require_once("includes/helpers.php");
  27. require_once("includes/config.inc.php");
  28. require_once("includes/lang.php");
  29. require_once("includes/functions.php");
  30. function curPageURL() {
  31. $pageURL = ( isset($_SERVER['HTTPS']) and get_true_boolean($_SERVER['HTTPS']) ) ? "https://" : "http://";
  32. if ($_SERVER["SERVER_PORT"] != "80")
  33. $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  34. else
  35. $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  36. return $pageURL;
  37. }
  38. if(isset($_GET['file']))
  39. {
  40. $file = urldecode($_GET['file']);
  41. include($file);
  42. $constants = get_defined_constants(true);
  43. echo base64_encode(serialize($constants['user']));
  44. exit();
  45. }
  46. ?>
  47. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  48. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  49. <html>
  50. <head>
  51. <title>OGP Lang Check</title>
  52. <style type='text/css'>
  53. .missing_lang {
  54. float: left;
  55. width: 100%;
  56. }
  57. .extra_lang {
  58. float: left;
  59. margin-left: 2em;
  60. }
  61. div h4 {
  62. padding: 0;
  63. margin: 0;
  64. }
  65. .clear {
  66. clear: both;
  67. }
  68. .file_vars {
  69. padding: 0;
  70. margin: 0;
  71. }
  72. .file_var h3 {
  73. margin: 0;
  74. padding: 0;
  75. }
  76. .lang {
  77. border: 1px dashed black;
  78. margin: 1em;
  79. padding: 1em;
  80. }
  81. .success {
  82. color: green;
  83. }
  84. .failure {
  85. color: red;
  86. }
  87. textarea {
  88. width: 80%;
  89. }
  90. </style>
  91. </head>
  92. <body>
  93. <h1>Open Game Panel - Language check</h1>
  94. <p>This page can be used to check what variables there are missing or there is extra compared to the
  95. default language (English).</p>
  96. <?php
  97. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  98. $error_text = "";
  99. if (get_db_error_text($db,$error_text))
  100. {
  101. print_failure($error_text);
  102. return;
  103. }
  104. chdir("lang");
  105. $COMPARISON_LANG = "English";
  106. $global_comparison_lang_files = array();
  107. $gclf_tmp = glob($COMPARISON_LANG."/*.php");
  108. // Remove the directory from filename.
  109. foreach ( $gclf_tmp as $tmp )
  110. {
  111. $array_tmp = explode("/",$tmp);
  112. array_push($global_comparison_lang_files,$array_tmp[1]);
  113. }
  114. $gclf_tmp = glob($COMPARISON_LANG."/modules/*.php");
  115. foreach ( $gclf_tmp as $tmp )
  116. {
  117. $array_tmp = explode("/",$tmp);
  118. array_push($global_comparison_lang_files,"modules/".$array_tmp[2]);
  119. }
  120. $locale_files = makefilelist("./", ".|..|.svn", true, "folders");
  121. echo "<ul id='lang_list'>";
  122. foreach ($locale_files as $lang_name)
  123. {
  124. echo "<li><a href='#$lang_name'>$lang_name</a></li>\n";
  125. }
  126. echo "</ul>";
  127. startSession();
  128. if ( isset($_SESSION['users_login']) )
  129. {
  130. $userInfo = $db->getUser($_SESSION['users_login']);
  131. if( $db->isAdmin($_SESSION['user_id']) AND isset($_SESSION['users_passwd']) AND !empty($_SESSION['users_passwd']) AND $_SESSION['users_passwd'] == $userInfo['users_passwd'])
  132. {
  133. if( !empty( $_POST ) )
  134. {
  135. foreach ($locale_files as $lang_name)
  136. {
  137. if ( $lang_name == $COMPARISON_LANG ) continue;
  138. $lang_ok = true;
  139. foreach ( $global_comparison_lang_files as $glf )
  140. {
  141. $file = $lang_name."/".$glf;
  142. if( isset( $_POST[str_replace(".", "_", $file)] ) )
  143. {
  144. echo "<h2>".$lang_name."</h2>\n";
  145. echo $file."\n Values Added.";
  146. $add_values = '<?php '."\n";
  147. foreach ( $_POST as $var => $value )
  148. {
  149. if( $var != str_replace(".", "_", $file) )
  150. $add_values .= 'define(\''.$var.'\', "'.$value.'");'."\n";
  151. }
  152. $add_values .= '?>';
  153. $fh = fopen($file, 'a') or die("can't open file");
  154. fwrite($fh, $add_values);
  155. fclose($fh);
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
  162. $current_url = curPageURL();
  163. foreach ($global_comparison_lang_files as $glf)
  164. {
  165. $file = $COMPARISON_LANG."/".$glf;
  166. $contents = file_get_contents($current_url.'?file='.$file);
  167. $lang[$glf] = unserialize(base64_decode($contents));
  168. }
  169. // Check every lang.
  170. foreach ($locale_files as $lang_name)
  171. {
  172. if ( $lang_name == $COMPARISON_LANG ) continue;
  173. echo "<div id='$lang_name' class='lang'><h2>".$lang_name."</h2>\n";
  174. $lang_ok = true;
  175. foreach ( $global_comparison_lang_files as $glf )
  176. {
  177. $file = $lang_name."/".$glf;
  178. if ( !is_file($file) )
  179. {
  180. echo "<h3>File $file is missing</h3>\n";
  181. $lang_ok = false;
  182. continue;
  183. }
  184. $compare_lang = array();
  185. $contents = file_get_contents("$current_url?file=$file");
  186. $compare_lang = unserialize(base64_decode($contents));
  187. if(!is_array($compare_lang))
  188. echo "Errors where found at $file";
  189. $extra_lang_vars = @array_diff_key($compare_lang,$lang[$glf]);
  190. $missing_lang_vars = @array_diff_key($lang[$glf],$compare_lang);
  191. if(isset($extra_lang_vars['']))
  192. unset($extra_lang_vars['']);
  193. // If there is nothign wrong with the file lest skip it.
  194. if ( empty($missing_lang_vars) && empty($extra_lang_vars) )
  195. continue;
  196. echo "<div class='file_vars'>\n";
  197. echo "<h3>File: $file</h3>
  198. <form action='' method='POST' name='".str_replace(".", "_", $file)."' >\n";
  199. if ( !empty($missing_lang_vars) )
  200. {
  201. echo "<div class='missing_lang'><h4>Missing lang vars:</h4>\n";
  202. echo "<br>";
  203. foreach ( $missing_lang_vars as $var => $value )
  204. {
  205. echo "<label for='$var' >$var</label><br><textarea id='$var' name='$var'>".$lang[$glf][$var]."</textarea><br>\n";
  206. }
  207. echo "<input name='".str_replace(".", "_", $file)."' type='submit' />
  208. </form>
  209. </div>\n";
  210. $lang_ok = false;
  211. }
  212. if ( !empty($extra_lang_vars) )
  213. {
  214. echo "<div class='extra_lang'><h4>Extra lang vars:</h4>\n";
  215. echo "<ul>";
  216. foreach ( $extra_lang_vars as $var => $value )
  217. {
  218. echo "<li>$var</li>";
  219. }
  220. echo "</ul></div>";
  221. $lang_ok = false;
  222. }
  223. echo "</div><div class='clear'></div>\n";
  224. }
  225. if ( $lang_ok )
  226. {
  227. echo "<p class='success'>Lang is $lang_name is OK.</p>\n";
  228. }
  229. else
  230. {
  231. echo "<p class='failure'>Errors found from lang $lang_name.</p>\n";
  232. }
  233. echo "<div class='clear'></div> </div>\n";
  234. }
  235. ?>
  236. </html>