lang-check.php 6.9 KB

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