lang-check.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 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'])) // Don't allow remote URLs
  39. {
  40. if(!filter_var($_GET['file'], FILTER_VALIDATE_URL)){
  41. $file = urldecode($_GET['file']);
  42. include($file);
  43. $constants = get_defined_constants(true);
  44. echo base64_encode(serialize($constants['user']));
  45. exit();
  46. }else{
  47. exit();
  48. }
  49. }
  50. ?>
  51. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  52. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  53. <html>
  54. <head>
  55. <title>OGP Lang Check</title>
  56. <style type='text/css'>
  57. .missing_lang {
  58. float: left;
  59. width: 100%;
  60. }
  61. .extra_lang {
  62. float: left;
  63. margin-left: 2em;
  64. }
  65. div h4 {
  66. padding: 0;
  67. margin: 0;
  68. }
  69. .clear {
  70. clear: both;
  71. }
  72. .file_vars {
  73. padding: 0;
  74. margin: 0;
  75. }
  76. .file_var h3 {
  77. margin: 0;
  78. padding: 0;
  79. }
  80. .lang {
  81. border: 1px dashed black;
  82. margin: 1em;
  83. padding: 1em;
  84. }
  85. .success {
  86. color: green;
  87. }
  88. .failure {
  89. color: red;
  90. }
  91. textarea {
  92. width: 80%;
  93. }
  94. </style>
  95. </head>
  96. <body>
  97. <h1>Open Game Panel - Language check</h1>
  98. <p>This page can be used to check what variables there are missing or there is extra compared to the
  99. default language (English).</p>
  100. <?php
  101. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  102. $error_text = "";
  103. if (get_db_error_text($db,$error_text))
  104. {
  105. print_failure($error_text);
  106. return;
  107. }
  108. chdir("lang");
  109. $COMPARISON_LANG = "English";
  110. $global_comparison_lang_files = array();
  111. $gclf_tmp = glob($COMPARISON_LANG."/*.php");
  112. // Remove the directory from filename.
  113. foreach ( $gclf_tmp as $tmp )
  114. {
  115. $array_tmp = explode("/",$tmp);
  116. array_push($global_comparison_lang_files,$array_tmp[1]);
  117. }
  118. $gclf_tmp = glob($COMPARISON_LANG."/modules/*.php");
  119. foreach ( $gclf_tmp as $tmp )
  120. {
  121. $array_tmp = explode("/",$tmp);
  122. array_push($global_comparison_lang_files,"modules/".$array_tmp[2]);
  123. }
  124. $locale_files = makefilelist("./", ".|..|.svn", true, "folders");
  125. echo "<ul id='lang_list'>";
  126. foreach ($locale_files as $lang_name)
  127. {
  128. echo "<li><a href='#$lang_name'>$lang_name</a></li>\n";
  129. }
  130. echo "</ul>";
  131. startSession();
  132. if ( isset($_SESSION['users_login']) )
  133. {
  134. $userInfo = $db->getUser($_SESSION['users_login']);
  135. if( $db->isAdmin($_SESSION['user_id']) AND isset($_SESSION['users_passwd']) AND !empty($_SESSION['users_passwd']) AND $_SESSION['users_passwd'] == $userInfo['users_passwd'])
  136. {
  137. if( !empty( $_POST ) )
  138. {
  139. foreach ($locale_files as $lang_name)
  140. {
  141. if ( $lang_name == $COMPARISON_LANG ) continue;
  142. $lang_ok = true;
  143. foreach ( $global_comparison_lang_files as $glf )
  144. {
  145. $file = $lang_name."/".$glf;
  146. if( isset( $_POST[str_replace(".", "_", $file)] ) )
  147. {
  148. echo "<h2>".$lang_name."</h2>\n";
  149. echo $file."\n Values Added.";
  150. $add_values = '<?php '."\n";
  151. foreach ( $_POST as $var => $value )
  152. {
  153. if( $var != str_replace(".", "_", $file) )
  154. $add_values .= 'define(\''.$var.'\', "'.$value.'");'."\n";
  155. }
  156. $add_values .= '?>';
  157. $fh = fopen($file, 'a') or die("can't open file");
  158. fwrite($fh, $add_values);
  159. fclose($fh);
  160. }
  161. }
  162. }
  163. }
  164. }
  165. }
  166. $current_url = curPageURL();
  167. foreach ($global_comparison_lang_files as $glf)
  168. {
  169. $file = $COMPARISON_LANG."/".$glf;
  170. $contents = file_get_contents($current_url.'?file='.$file);
  171. $lang[$glf] = unserialize(base64_decode($contents));
  172. }
  173. // Check every lang.
  174. foreach ($locale_files as $lang_name)
  175. {
  176. if ( $lang_name == $COMPARISON_LANG ) continue;
  177. echo "<div id='$lang_name' class='lang'><h2>".$lang_name."</h2>\n";
  178. $lang_ok = true;
  179. foreach ( $global_comparison_lang_files as $glf )
  180. {
  181. $file = $lang_name."/".$glf;
  182. if ( !is_file($file) )
  183. {
  184. echo "<h3>File $file is missing</h3>\n";
  185. $lang_ok = false;
  186. continue;
  187. }
  188. $compare_lang = array();
  189. $contents = file_get_contents("$current_url?file=$file");
  190. $compare_lang = unserialize(base64_decode($contents));
  191. if(!is_array($compare_lang))
  192. die("Errors where found at $file");
  193. $extra_lang_vars = @array_diff_key($compare_lang,$lang[$glf]);
  194. $missing_lang_vars = @array_diff_key($lang[$glf],$compare_lang);
  195. if(isset($extra_lang_vars['']))
  196. unset($extra_lang_vars['']);
  197. // If there is nothign wrong with the file lest skip it.
  198. if ( empty($missing_lang_vars) && empty($extra_lang_vars) )
  199. continue;
  200. echo "<div class='file_vars'>\n";
  201. echo "<h3>File: $file</h3>
  202. <form action='' method='POST' name='".str_replace(".", "_", $file)."' >\n";
  203. if ( !empty($missing_lang_vars) )
  204. {
  205. echo "<div class='missing_lang'><h4>Missing lang vars:</h4>\n";
  206. echo "<br>";
  207. foreach ( $missing_lang_vars as $var => $value )
  208. {
  209. echo "<label for='$var' >$var</label><br><textarea id='$var' name='$var'>".$lang[$glf][$var]."</textarea><br>\n";
  210. }
  211. echo "<input name='".str_replace(".", "_", $file)."' type='submit' />
  212. </form>
  213. </div>\n";
  214. $lang_ok = false;
  215. }
  216. if ( !empty($extra_lang_vars) )
  217. {
  218. echo "<div class='extra_lang'><h4>Extra lang vars:</h4>\n";
  219. echo "<ul>";
  220. foreach ( $extra_lang_vars as $var => $value )
  221. {
  222. echo "<li>$var</li>";
  223. }
  224. echo "</ul></div>";
  225. $lang_ok = false;
  226. }
  227. echo "</div><div class='clear'></div>\n";
  228. }
  229. if ( $lang_ok )
  230. {
  231. echo "<p class='success'>Lang is $lang_name is OK.</p>\n";
  232. }
  233. else
  234. {
  235. echo "<p class='failure'>Errors found from lang $lang_name.</p>\n";
  236. }
  237. echo "<div class='clear'></div> </div>\n";
  238. }
  239. ?>
  240. </html>