PageRenderTime 58ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/e107_admin/lancheck.php

https://github.com/CasperGemini/e107
PHP | 1832 lines | 684 code | 248 blank | 900 comment | 134 complexity | 8a2b0e5ff02c7e6c514a40eef1914f24 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * e107 website system
  4. *
  5. * Copyright (C) 2008-2013 e107 Inc (e107.org)
  6. * Released under the terms and conditions of the
  7. * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  8. *
  9. * Administration Area - Language check
  10. * With code from Izydor and Lolo.
  11. *
  12. */
  13. require_once("../class2.php");
  14. if (!getperms("L"))
  15. {
  16. header("location:".e_BASE."index.php");
  17. exit;
  18. }
  19. include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
  20. $e_sub_cat = 'language';
  21. // require_once("auth.php");
  22. $frm = e107::getForm();
  23. $mes = e107::getMessage();
  24. $lck = new lancheck;
  25. /*
  26. $qry = explode("|",e_QUERY);
  27. $f = $qry[0];
  28. $lan = $qry[1];
  29. $mode = $qry[2];
  30. // Write the language file.
  31. if(isset($_POST['submit']))
  32. {
  33. unset($input);
  34. $kom_start = chr(47)."*";
  35. $kom_end = "*".chr(47);
  36. if($_POST['root'])
  37. {
  38. $writeit = $_POST['root'];
  39. }
  40. $old_kom = "";
  41. $in_kom=0;
  42. $data = file($writeit);
  43. foreach($data as $line)
  44. {
  45. if (strpos($line,$kom_start) !== False && $old_kom == "")
  46. {
  47. $in_kom=1;
  48. }
  49. if ($in_kom) { $old_kom.=$line; }
  50. if (strpos($line,$kom_end) !== False && $in_kom) {$in_kom = 0;}
  51. }
  52. $message = "<div style='text-align:left'><br />";
  53. $input .= chr(60)."?php\n";
  54. if ($old_kom == "")
  55. {
  56. // create CVS compatible description.
  57. $diz = chr(47)."*\n";
  58. $diz .= " * e107 website system\n";
  59. $diz .= " *\n";
  60. $diz .= " * Copyright (C) 2008-2009 e107 Inc (e107.org)\n";
  61. $diz .= " * Released under the terms and conditions of the\n";
  62. $diz .= " * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)\n";
  63. $diz .= " *\n";
  64. $diz .= " * Language File\n";
  65. $diz .= " *\n";
  66. $diz .= " * ".chr(36)."Source: ".str_replace(array(e_LANGUAGEDIR, e_PLUGIN), array(e_LANGUAGEDIR_ABS, e_PLUGIN_ABS), $writeit)." ".chr(36)."\n";
  67. $diz .= " * ".chr(36)."Revision: 1.0 ".chr(36)."\n";
  68. $diz .= " * ".chr(36)."Date: ".date("Y/m/d H:i:s")." ".chr(36)."\n";
  69. $diz .= " * ".chr(36)."Author: ".USERNAME." ".chr(36)."\n";
  70. $diz .= " *\n";
  71. $diz .= "*".chr(47)."\n\n";
  72. }
  73. else
  74. {
  75. $diz = $old_kom;
  76. }
  77. $input .= $diz;
  78. $message .= str_replace("\n","<br />",$diz);
  79. for ($i=0; $i<count($_POST['newlang']); $i++)
  80. {
  81. $notdef_start = "";
  82. $notdef_end = "\n";
  83. $deflang = (MAGIC_QUOTES_GPC === TRUE) ? stripslashes($_POST['newlang'][$i]) : $_POST['newlang'][$i];
  84. $func = "define";
  85. $quote = chr(34);
  86. if (strpos($_POST['newdef'][$i],"ndef++") !== FALSE )
  87. {
  88. $defvar = str_replace("ndef++","",$_POST['newdef'][$i]);
  89. $notdef_start = "if (!defined(".chr(34).$defvar.chr(34).")) {";
  90. $notdef_end = "}\n";
  91. }
  92. else
  93. {
  94. $defvar = $_POST['newdef'][$i];
  95. }
  96. if($_POST['newdef'][$i] == "LC_ALL" && isset($_POST['root']))
  97. {
  98. $message .= $notdef_start.'setlocale('.htmlentities($defvar).','.$deflang.');<br />'.$notdef_end;
  99. $input .= $notdef_start."setlocale(".$defvar.",".$deflang.");".$notdef_end;
  100. }
  101. else
  102. {
  103. $message .= $notdef_start.$func.'('.$quote.htmlentities($defvar).$quote.',"'.$deflang.'");<br />'.$notdef_end;
  104. $input .= $notdef_start.$func."(".$quote.$defvar.$quote.", ".chr(34).$deflang.chr(34).");".$notdef_end;
  105. }
  106. }
  107. $message .="<br />";
  108. $message .="</div>";
  109. $input .= "\n\n?>";
  110. // Write to file.
  111. $fp = @fopen($writeit,"w");
  112. if(!@fwrite($fp, $input))
  113. {
  114. $caption = LAN_CHECK_PAGE_TITLE.' - '.LAN_ERROR;
  115. $message = '';
  116. $mes->addError(LAN_CHECK_17);
  117. }
  118. else
  119. {
  120. $caption = LAN_CHECK_PAGE_TITLE.' - '.LAN_CHECK_24;
  121. $mes->addSuccess(sprintXXX(str_replace("[x]", "%s", LAN_CHECK_23), basename($writeit)));
  122. }
  123. fclose($writeit);
  124. $message .= "
  125. <form method='post' action='".e_SELF."' id='core-lancheck-save-file-form'>
  126. <div class='center'>
  127. ".$frm->admin_button('language_sel', LAN_BACK)."
  128. ".$frm->hidden('language', $lan)."
  129. </div>
  130. </form>";
  131. $ns->tablerender($caption, $mes->render().$message);
  132. // require_once(e_ADMIN."footer.php");
  133. exit;
  134. }
  135. // ============================================================================
  136. // Edit the Language File.
  137. if($f != ""){
  138. if (!$mode)
  139. {
  140. $dir1 = e_BASE.$LANGUAGES_DIRECTORY."English/";
  141. $f1=$f;
  142. $dir2 = e_BASE.$LANGUAGES_DIRECTORY.$lan."/";
  143. $f2=$f;
  144. }
  145. else
  146. {
  147. $fullpath_orig = $f;
  148. $fullpath_trans = str_replace("English",$lan,$f);
  149. $f1 = basename($fullpath_orig);
  150. $f2 = basename($fullpath_trans);
  151. $dir1 = dirname($fullpath_orig)."/";
  152. $dir2 = dirname($fullpath_trans)."/";
  153. }
  154. $lck->edit_lanfiles($dir1,$dir2,$f1,$f2);
  155. }
  156. // ===========================================================================
  157. $core_plugins = array(
  158. "alt_auth", "banner_menu", "blogcalendar_menu", "calendar_menu", "chatbox_menu",
  159. "clock_menu", "comment_menu", "content", 'download', "featurebox", "forum",
  160. "gsitemap", "links_page", "linkwords", "list_new", "log", "login_menu",
  161. "newforumposts_main", "newsfeed", "newsletter", "online", "other_news_menu",
  162. "pdf", "pm", "poll", "rss_menu", "search_menu", "siteinfo", "trackback",
  163. "tree_menu", "user_menu"
  164. );
  165. $core_themes = array("bootstrap", $pref['sitetheme']);
  166. if(isset($_POST['language_sel']) && isset($_POST['language']))
  167. {
  168. $text = $lck->check_core_lanfiles($_POST['language']).$lck->check_core_lanfiles($_POST['language'],"admin/");
  169. $text .= "
  170. <fieldset id='core-lancheck-plugin'>
  171. <legend>".ADLAN_CL_7."</legend>
  172. <table class='table adminlist'>
  173. <colgroup>
  174. <col style='width: 25%' />
  175. <col style='width: 25%' />
  176. <col style='width: 40%' />
  177. <col style='width: 10%' />
  178. </colgroup>
  179. <thead>
  180. <tr>
  181. <th>".LAN_PLUGIN."</th>
  182. <th>".LAN_CHECK_16."</th>
  183. <th>".$_POST['language']."</th>
  184. <th class='center last'>".LAN_OPTIONS."</th>
  185. </tr>
  186. </thead>
  187. <tbody>
  188. ";
  189. foreach($core_plugins as $plugs)
  190. {
  191. if(is_readable(e_PLUGIN.$plugs))
  192. {
  193. $text .= $lck->check_lanfiles('P',$plugs,"English",$_POST['language']);
  194. }
  195. }
  196. $text .= "
  197. </tbody>
  198. </table>
  199. </fieldset>
  200. ";
  201. $text .= "
  202. <fieldset id='core-lancheck-theme'>
  203. <legend>".LAN_CHECK_22."</legend>
  204. <table class='table adminlist'>
  205. <colgroup>
  206. <col style='width: 25%' />
  207. <col style='width: 25%' />
  208. <col style='width: 40%' />
  209. <col style='width: 10%' />
  210. </colgroup>
  211. <thead>
  212. <tr>
  213. <th>".LAN_CHECK_21."</th>
  214. <th>".LAN_CHECK_16."</th>
  215. <th>".$_POST['language']."</th>
  216. <th class='center last'>".LAN_OPTIONS."</th>
  217. </tr>
  218. </thead>
  219. <tbody>
  220. ";
  221. foreach($core_themes as $them)
  222. {
  223. if(is_readable(e_THEME.$them))
  224. {
  225. $text .= $lck->check_lanfiles('T',$them,"English",$_POST['language']);
  226. }
  227. }
  228. $text .= "
  229. </tbody>
  230. </table>
  231. </fieldset>
  232. ";
  233. $mes = e107::getMessage();
  234. if($lck->error_count == 0)
  235. {
  236. e107::getConfig()->setPref('lancheck/'.$_POST['language'],1);
  237. e107::getConfig()->save(FALSE);
  238. $mes->addSuccess(LAN_CHECK_27.'<b>: '.$lck->error_count.'</b>');
  239. }
  240. else
  241. {
  242. $mes->addWarning(LAN_CHECK_27.'<b>: '.$lck->error_count.'</b>');
  243. }
  244. $ns->tablerender(LAN_CHECK_25, $mes->render(). $text);
  245. require_once(e_ADMIN."footer.php");
  246. exit;
  247. }
  248. */
  249. class lancheck
  250. {
  251. var $core_plugins = array(
  252. "alt_auth","banner","blogcalendar_menu","calendar_menu","chatbox_menu",
  253. "clock_menu","comment_menu","download","faqs", "featurebox", "forum","gallery", "gsitemap","import", "links_page",
  254. "linkwords","list_new","log","login_menu","newforumposts_main","newsfeed",
  255. "news", "newsletter","online", "page",
  256. "pm","poll","rss_menu","search_menu","siteinfo","tagwords", "tinymce",
  257. "trackback","tree_menu","user_menu"
  258. );
  259. /*
  260. * $core_plugins = array(
  261. "alt_auth", "banner_menu", "blogcalendar_menu", "calendar_menu", "chatbox_menu",
  262. "clock_menu", "comment_menu", "content", 'download', "featurebox", "forum",
  263. "gsitemap", "links_page", "linkwords", "list_new", "log", "login_menu",
  264. "newforumposts_main", "newsfeed", "newsletter", "online", "other_news_menu",
  265. "pdf", "pm", "poll", "rss_menu", "search_menu", "siteinfo", "trackback",
  266. "tree_menu", "user_menu"
  267. );
  268. */
  269. var $core_themes = array("bootstrap");
  270. var $errorsOnly = FALSE;
  271. var $coreImage = array();
  272. function init()
  273. {
  274. $ns = e107::getRender();
  275. $tp = e107::getParser();
  276. $pref = e107::getPref();
  277. // Check current theme also (but do NOT add to generated zip)
  278. $this->core_themes[] = $pref['sitetheme'];
  279. $this->core_themes = array_unique($this->core_themes);
  280. $acceptedLans = explode(",",e_LANLIST);
  281. if(!isset($_SESSION['lancheck-core-image']))
  282. {
  283. $core = array();
  284. $coredir = array('admin' => 'e107_admin', 'files' => 'e107_files', 'images' => 'e107_images', 'themes' => 'e107_themes', 'plugins' => 'e107_plugins', 'handlers' => 'e107_handlers', 'languages' => 'e107_languages', 'downloads' => 'e107_downloads', 'docs' => 'e107_docs');
  285. require_once(e_ADMIN."core_image.php");
  286. unset($core_image['e107_images'],$core_image['e107_files'],$core_image['e107_admin']);
  287. $_SESSION['lancheck-core-image'] = $core_image;
  288. }
  289. if(isset($_POST['language_sel'])) // Verify
  290. {
  291. $_SESSION['lancheck-errors-only'] = ($_POST['errorsonly']==1 ) ? 1 : 0;
  292. $this->errorsOnly = ($_POST['errorsonly']==1) ? TRUE : FALSE;
  293. $this->check_all();
  294. return TRUE;
  295. }
  296. // Write the language file.
  297. if(isset($_POST['submit']) && varsettrue($_POST['lan']) && in_array($_POST['lan'],$acceptedLans))
  298. {
  299. $this->write_lanfile($_POST['lan']);
  300. return TRUE;
  301. }
  302. // Edit the Language File.
  303. if(varsettrue($_GET['f']) && varsettrue($_GET['lan']) && in_array($_GET['lan'],$acceptedLans))
  304. {
  305. if (!$_GET['mode'])
  306. {
  307. $dir1 = e_LANGUAGEDIR."English/";
  308. $f1= $tp->toDB($_GET['f']);
  309. $dir2 = e_LANGUAGEDIR.$_GET['lan']."/";
  310. $f2= $tp->toDB($_GET['f']);
  311. }
  312. else
  313. {
  314. $fullpath_orig = $tp->toDB($_GET['f']);
  315. $fullpath_trans = str_replace("English",$_GET['lan'],$tp->toDB($_GET['f']));
  316. $f1 = basename($fullpath_orig);
  317. $f2 = basename($fullpath_trans);
  318. $dir1 = dirname($fullpath_orig)."/";
  319. $dir2 = dirname($fullpath_trans)."/";
  320. }
  321. $this->edit_lanfiles($dir1,$dir2,$f1,$f2,$_GET['lan']);
  322. return TRUE;
  323. }
  324. return FALSE;
  325. }
  326. function countFiles($array)
  327. {
  328. foreach($array as $k=>$val)
  329. {
  330. if(is_array($val))
  331. {
  332. $key = key($val);
  333. $this->coreImage[$key] = $val;
  334. }
  335. elseif($val)
  336. {
  337. // $this->totalFiles++;
  338. }
  339. }
  340. }
  341. function check_all($mode='render')
  342. {
  343. // global $ns,$tp;
  344. $mes = e107::getMessage();
  345. $ns = e107::getRender();
  346. $tp = e107::getParser();
  347. $_POST['language'] = key($_POST['language_sel']);
  348. $_SESSION['lancheck'][$_POST['language']] = array();
  349. $_SESSION['lancheck'][$_POST['language']]['file'] = 0;
  350. $_SESSION['lancheck'][$_POST['language']]['def'] = 0;
  351. $_SESSION['lancheck'][$_POST['language']]['bom'] = 0;
  352. $_SESSION['lancheck'][$_POST['language']]['utf'] = 0;
  353. $_SESSION['lancheck'][$_POST['language']]['total'] = 0;
  354. $core_text = $this->check_core_lanfiles($_POST['language']);
  355. $core_admin = $this->check_core_lanfiles($_POST['language'],"admin/");
  356. $plug_text = "";
  357. $theme_text = "";
  358. // Plugins -------------
  359. $plug_header = "<table class='table table-striped'>
  360. <tr>
  361. <td class='fcaption'>".LAN_PLUGIN."</td>
  362. <td class='fcaption'>".LAN_CHECK_16."</td>
  363. <td class='fcaption'>".$_POST['language']."</td>
  364. <td class='fcaption'>".LAN_OPTIONS."</td></tr>";
  365. foreach($this->core_plugins as $plugs)
  366. {
  367. if(is_readable(e_PLUGIN.$plugs))
  368. {
  369. $plug_text .= $this->check_lanfiles('P',$plugs,"English",$_POST['language']);
  370. }
  371. }
  372. $plug_footer = "</table>";
  373. // Themes -------------
  374. $theme_header = "<table class='table table-striped'>
  375. <tr>
  376. <td class='fcaption'>".LAN_CHECK_22."</td>
  377. <td class='fcaption'>".LAN_CHECK_16."</td>
  378. <td class='fcaption'>".$_POST['language']."</td>
  379. <td class='fcaption'>".LAN_OPTIONS."</td></tr>";
  380. foreach($this->core_themes as $them)
  381. {
  382. if(is_readable(e_THEME.$them))
  383. {
  384. $theme_text .= $this->check_lanfiles('T',$them,"English",$_POST['language']);
  385. }
  386. }
  387. $theme_footer = "</table>";
  388. // -------------------------
  389. if($mode != 'render')
  390. {
  391. return;
  392. }
  393. $message .= "
  394. <form id='lancheck' method='post' action='".e_ADMIN."language.php?tools'>
  395. <div>\n";
  396. $icon = ($_SESSION['lancheck'][$_POST['language']]['total']>0) ? ADMIN_FALSE_ICON : ADMIN_TRUE_ICON;
  397. $errors_diz = (defsettrue('LAN_CHECK_23')) ? LAN_CHECK_23 : "Errors Found";
  398. $message .= $errors_diz.": ".$_SESSION['lancheck'][$_POST['language']]['total'];
  399. $just_go_diz = (defsettrue('LAN_CHECK_20')) ? LAN_CHECK_20 : "Generate Language Pack";
  400. $lang_sel_diz = (defsettrue('LAN_CHECK_21')) ? LAN_CHECK_21 : "Verify Again";
  401. $lan_pleasewait = (defsettrue('LAN_PLEASEWAIT')) ? $tp->toJS(LAN_PLEASEWAIT) : "Please Wait";
  402. $message .= "
  403. <br /><br />
  404. <input type='hidden' name='language' value='".$_POST['language']."' />
  405. <input type='hidden' name='errorsonly' value='".$_SESSION['lancheck-errors-only']."' />
  406. <input class='btn btn-primary' type='submit' name='ziplang[".$_POST['language']."]' value=\"".$just_go_diz."\" class='btn button' onclick=\"this.value = '".$lan_pleasewait."'\" />
  407. <input type='submit' name='language_sel[".$_POST['language']."]' value=\"".$lang_sel_diz."\" class='btn button' />
  408. </div>
  409. </form>
  410. ";
  411. // print_a($_SESSION['lancheck'][$_POST['language']]);
  412. $plug_text = ($plug_text) ? $plug_header.$plug_text.$plug_footer : "<div>".LAN_OK."</div>";
  413. $theme_text = ($theme_text) ? $theme_header.$theme_text.$theme_footer : "<div>".LAN_OK."</div>";
  414. $mesStatus = ($_SESSION['lancheck'][$_POST['language']]['total']>0) ? E_MESSAGE_INFO : E_MESSAGE_SUCCESS;
  415. $mes->add($message, $mesStatus);
  416. // $ns -> tablerender(LAN_CHECK_24.": ".$_POST['language'],$message);
  417. echo $mes->render();
  418. $ns -> tablerender(LANG_LAN_21.SEP.$_POST['language'].SEP.LAN_CHECK_2, $core_text);
  419. $ns -> tablerender(LAN_CHECK_3.": ".$_POST['language']."/admin", $core_admin);
  420. $ns -> tablerender(ADLAN_CL_7, $plug_text);
  421. $ns -> tablerender(LAN_CHECK_25, $theme_text);
  422. }
  423. function write_lanfile($lan='')
  424. {
  425. if(!$lan){ return; }
  426. global $ns;
  427. unset($input);
  428. $kom_start = chr(47)."*";
  429. $kom_end = "*".chr(47);
  430. if(varsettrue($_SESSION['lancheck-edit-file']))
  431. {
  432. $writeit = $_SESSION['lancheck-edit-file'];
  433. }
  434. else
  435. {
  436. return;
  437. }
  438. $old_kom = "";
  439. $in_kom=0;
  440. if(is_readable($writeit)) // File Exists;
  441. {
  442. $data = file($writeit);
  443. foreach($data as $line)
  444. {
  445. if (strpos($line,$kom_start) !== False && $old_kom == "")
  446. {
  447. $in_kom=1;
  448. }
  449. if ($in_kom) { $old_kom .= $line; }
  450. if (strpos($line,$kom_end) !== False && $in_kom) {$in_kom = 0;}
  451. }
  452. }
  453. $message = "<div style='text-align:left'><br />";
  454. $input .= chr(60)."?php\n";
  455. if ($old_kom == "")
  456. {
  457. // create CVS compatible description.
  458. $diz = chr(47)."*\n";
  459. $diz .= "+---------------------------------------------------------------+\n";
  460. $diz .= "| e107 website content management system ".$lan." Language File\n";
  461. $diz .= "| Released under the terms and conditions of the\n";
  462. $diz .= "| GNU General Public License (http://gnu.org).\n";
  463. $diz .= "|\n";
  464. $diz .= "| ".chr(36)."URL: $writeit ".chr(36)."\n";
  465. $diz .= "| ".chr(36)."Revision: 1.0 ".chr(36)."\n";
  466. $diz .= "| ".chr(36)."Id: ".date("Y/m/d H:i:s")." ".chr(36)."\n";
  467. $diz .= "| ".chr(36)."Author: ".USERNAME." ".chr(36)."\n";
  468. $diz .= "+---------------------------------------------------------------+\n";
  469. $diz .= "*".chr(47)."\n\n";
  470. }
  471. else
  472. {
  473. $diz = $old_kom;
  474. }
  475. $input .= $diz;
  476. $message .= str_replace("\n","<br />",$diz);
  477. for ($i=0; $i<count($_POST['newlang']); $i++)
  478. {
  479. $notdef_start = "";
  480. $notdef_end = "\n";
  481. $deflang = (MAGIC_QUOTES_GPC === TRUE) ? stripslashes($_POST['newlang'][$i]) : $_POST['newlang'][$i];
  482. $func = "define";
  483. $quote = chr(34);
  484. if (strpos($_POST['newdef'][$i],"ndef++") !== FALSE )
  485. {
  486. $defvar = str_replace("ndef++","",$_POST['newdef'][$i]);
  487. $notdef_start = "if (!defined(".chr(34).$defvar.chr(34).")) {";
  488. $notdef_end = "}\n";
  489. }
  490. else
  491. {
  492. $defvar = $_POST['newdef'][$i];
  493. }
  494. if($_POST['newdef'][$i] == "LC_ALL" && varsettrue($_SESSION['lancheck-edit-file']))
  495. {
  496. $message .= $notdef_start.'setlocale('.htmlentities($defvar).','.$deflang.');<br />'.$notdef_end;
  497. $input .= $notdef_start."setlocale(".$defvar.",".$deflang.");".$notdef_end;
  498. }
  499. else
  500. {
  501. $message .= $notdef_start.$func.'('.$quote.htmlentities($defvar).$quote.',"'.$deflang.'");<br />'.$notdef_end;
  502. $input .= $notdef_start.$func."(".$quote.$defvar.$quote.", ".chr(34).$deflang.chr(34).");".$notdef_end;
  503. }
  504. }
  505. $message .="<br />";
  506. $message .="</div>";
  507. $input .= "\n\n?>";
  508. //<?
  509. // Write to file.
  510. $writeit = str_replace("//","/",$writeit); // Quick Fix.
  511. $fp = @fopen($writeit,"w");
  512. if(!@fwrite($fp, $input))
  513. {
  514. $caption = LAN_ERROR;
  515. $message = LAN_CHECK_17;
  516. }
  517. else
  518. {
  519. $caption = LAN_SAVED." <b>".$lan."/".$writeit."</b>";
  520. }
  521. fclose($fp);
  522. $message .= "<form method='post' action='".e_SELF."?tools' id='select_lang'>
  523. <div style='text-align:center'><br />";
  524. $message .= "<br /><br /><input class='btn' type='submit' name='language_sel[".$lan."]' value=\"".LAN_BACK."\" />
  525. </div></form>";
  526. unset($_SESSION['lancheck-edit-file']);
  527. $ns -> tablerender($caption, $message);
  528. }
  529. function check_core_lanfiles($checklan,$subdir='')
  530. {
  531. global $lanfiles,$_POST,$sql;
  532. // $sql->db_Mark_Time('Start Get Core Lan Phrases English');
  533. $English = $this->get_comp_lan_phrases(e_LANGUAGEDIR."English/".$subdir,$checklan);
  534. // $sql->db_Mark_Time('End Get Core Lan Phrases English');
  535. $check = $this->get_comp_lan_phrases(e_LANGUAGEDIR.$checklan."/".$subdir,$checklan);
  536. // print_a($check);
  537. // return;
  538. $text = "";
  539. $header = "<table class='table table-striped'>
  540. <tr>
  541. <th>".LAN_CHECK_16."</th>
  542. <th>".$_POST['language']." ".LAN_CHECK_26."</th>
  543. <th>".LAN_OPTIONS."</th></tr>";
  544. $keys = array_keys($English);
  545. sort($keys);
  546. $er = "";
  547. foreach($keys as $k)
  548. {
  549. if($k != "bom")
  550. {
  551. $lnk = $k;
  552. $k_check = str_replace("English",$checklan,$k);
  553. if(array_key_exists($k,$check))
  554. {
  555. // $text .= "<tr><td class='forumheader3' style='width:45%'>{$lnk}</td>";
  556. $subkeys = array_keys($English[$k]);
  557. $er="";
  558. $utf_error = "";
  559. $bomkey = str_replace(".php","",$k_check);
  560. // $bom_error = ($check['bom'][$bomkey]) ? "<i>".LAN_CHECK_15."</i><br />" : ""; // illegal chars
  561. if($check['bom'][$bomkey])
  562. {
  563. $bom_error = "<i>".LAN_CHECK_15."</i><br />";
  564. $this->checkLog('bom',1);;
  565. }
  566. else
  567. {
  568. $bom_error = "";
  569. }
  570. foreach($subkeys as $sk)
  571. {
  572. if($utf_error == "" && !$this->is_utf8($check[$k][$sk]))
  573. {
  574. $utf_error = "<i>".LAN_CHECK_19."</i><br />";
  575. $this->checkLog('utf',1);
  576. }
  577. if($sk == "LC_ALL"){
  578. $check[$k][$sk] = str_replace(chr(34).chr(34),"",$check[$k][$sk]);
  579. }
  580. $er .= $this->check_lan_errors($English[$k],$check[$k],$sk);
  581. }
  582. if($this->errorsOnly == TRUE && !$er && !$utf_error && !$bom_error)
  583. {
  584. continue;
  585. }
  586. $text .= "<tr><td class='forumheader3' style='width:45%'>{$lnk}</td>";
  587. $style = ($er) ? "forumheader2" : "forumheader3";
  588. $text .= "<td class='{$style}' style='width:50%'><div class='smalltext'>";
  589. $text .= $bom_error . $utf_error;
  590. $text .= (!$er && !$bom_error && !$utf_error) ? "<img src='".e_IMAGE."fileinspector/integrity_pass.png' alt='".LAN_OK."' />" : $er."<br />";
  591. $text .= "</div></td>";
  592. }
  593. else
  594. {
  595. $this->checkLog('file',1);
  596. $this->newFile(e_LANGUAGEDIR.$checklan."/".$subdir.$lnk,$checklan);
  597. $text .= "<tr>
  598. <td class='forumheader3' style='width:45%'>{$lnk}</td>
  599. <td class='forumheader' style='width:50%'>".LAN_CHECK_4."</td>"; // file missing.
  600. }
  601. // Leave in EDIT button for all entries - to allow re-translation of bad entries.
  602. $subpath = ($subdir!='') ? $subdir.$k : $k;
  603. $text .="<td class='center' style='width:5%'>
  604. <input class='btn btn-primary' type='button' style='width:60px' name='but_$i' value=\"".LAN_EDIT."\" onclick=\"window.location='".e_SELF."?f=".$subpath."&amp;lan=".$_POST['language']."'\" /> ";
  605. $text .="</td></tr>";
  606. }
  607. }
  608. $footer = "</table>";
  609. if($text)
  610. {
  611. return $header.$text.$footer;
  612. }
  613. else
  614. {
  615. return "<div>".LAN_OK."</div>";
  616. }
  617. }
  618. function check_lan_errors($english,$translation,$def)
  619. {
  620. $eng_line = $english[$def];
  621. $trans_line = $translation[$def];
  622. // return $eng_line."<br />".$trans_line."<br /><br />";
  623. $error = array();
  624. if((!array_key_exists($def,$translation) && $eng_line != "") || (trim($trans_line) == "" && $eng_line != ""))
  625. {
  626. $this->checkLog('def',1);
  627. return $def.": ".LAN_CHECK_5."<br />";
  628. }
  629. if((strpos($eng_line,"[link=")!==FALSE && strpos($trans_line,"[link=")===FALSE) || (strpos($eng_line,"[b]")!==FALSE && strpos($trans_line,"[b]")===FALSE))
  630. {
  631. $error[] = $def. ": Missing bbcodes";
  632. }
  633. elseif((strpos($eng_line,"[")!==FALSE && strpos($trans_line,"[")===FALSE) || (strpos($eng_line,"]")!==FALSE && strpos($trans_line, "]")===FALSE))
  634. {
  635. $error[] = $def. ": Missing [ and/or ] character(s)";
  636. }
  637. if((strpos($eng_line,"--LINK--")!==FALSE && strpos($trans_line,"--LINK--")==FALSE))
  638. {
  639. $error[] = $def. ": Missing --LINK--";
  640. }
  641. if((strpos($eng_line,"e107.org")!==FALSE && strpos($trans_line,"e107.org")==FALSE))
  642. {
  643. $error[] = $def. ": Missing e107.org URL";
  644. }
  645. if((strpos($eng_line,"e107coders.org")!==FALSE && strpos($trans_line,"e107coders.org")==FALSE))
  646. {
  647. $error[] = $def. ": Missing e107coders.org URL";
  648. }
  649. if(strip_tags($eng_line) != $eng_line)
  650. {
  651. $stripped = strip_tags($trans_line);
  652. if(($stripped == $trans_line))
  653. {
  654. // echo "<br /><br />".$def. "<br />".$stripped."<br />".$trans_line;
  655. $error[] = $def. ": Missing HTML tags" ;
  656. }
  657. }
  658. $this->checkLog('def',count($error));
  659. return ($error) ? implode("<br />",$error)."<br />" : "";
  660. }
  661. function checkLog($type='error',$count)
  662. {
  663. $_SESSION['lancheck'][$_POST['language']][$type] += $count;
  664. $_SESSION['lancheck'][$_POST['language']]['total'] += $count;
  665. }
  666. function get_lan_file_phrases($dir1,$dir2,$file1,$file2){
  667. $ret = array();
  668. $fname = $dir1.$file1;
  669. $type='orig';
  670. if(is_file($fname))
  671. {
  672. $data = file_get_contents($fname);
  673. $ret= $ret + $this->fill_phrases_array($data,$type);
  674. if(substr($data,0,5) != "<?php")
  675. {
  676. $key = str_replace(".php","",$fname);
  677. $ret['bom'][$key] = $fname;
  678. }
  679. }
  680. $fname = $dir2.$file2;
  681. $type='tran';
  682. if(is_file($fname))
  683. {
  684. $data = file_get_contents($fname);
  685. $ret=$ret + $this->fill_phrases_array($data,$type);
  686. if(substr($data,0,5) != "<?php")
  687. {
  688. $key = str_replace(".php","",$fname);
  689. $ret['bom'][$key] = $fname;
  690. }
  691. }
  692. elseif(substr($fname,-4) == ".php")
  693. {
  694. file_put_contents($fname,"<?php\n\n?>");
  695. }
  696. return $ret;
  697. }
  698. function get_comp_lan_phrases($comp_dir,$lang,$depth=0)
  699. {
  700. if(!is_dir($comp_dir))
  701. {
  702. return array();
  703. }
  704. require_once(e_HANDLER."file_class.php");
  705. $fl = new e_file;
  706. $ret = array();
  707. if($lang_array = $fl->get_files($comp_dir, ".php$","standard",$depth)){
  708. sort($lang_array);
  709. }
  710. $regexp = (strpos($comp_dir,e_LANGUAGEDIR) !== FALSE) ? "#.php#" : "#".$lang."#";
  711. foreach($lang_array as $f)
  712. {
  713. if(preg_match($regexp,$f['path'].$f['fname']) && is_file($f['path'].$f['fname']))
  714. {
  715. $allData = file_get_contents($f['path'].$f['fname']);
  716. $data = explode("\n",$allData);
  717. // $data = file($f['path'].$f['fname']);
  718. $relpath = str_replace($comp_dir,"",$f['path']);
  719. $key = str_replace(".php","",$relpath.$f['fname']);
  720. if(substr($data[0],0,5) != "<?php")
  721. {
  722. $ret['bom'][$key] = $f['fname'];
  723. }
  724. $end_of_file = 0;
  725. foreach($data as $line)
  726. {
  727. if($end_of_file == 1)
  728. {
  729. $ret['bom'][$key] = $f['fname'];
  730. }
  731. $line = trim($line);
  732. if($line == "?>")
  733. {
  734. $end_of_file = 1;
  735. }
  736. }
  737. if($f['path'].$f['fname'] == e_LANGUAGEDIR.$lang."/".$lang.".php")
  738. {
  739. $f['fname'] = "English.php"; // change the key for the main language file.
  740. }
  741. if($f['path'].$f['fname'] == e_LANGUAGEDIR.$lang."/".$lang."_custom.php")
  742. {
  743. $f['fname'] = "English_custom.php"; // change the key for the main language file.
  744. }
  745. $ret=$ret + $this->fill_phrases_array($allData,$relpath.$f['fname']);
  746. }
  747. }
  748. return $ret;
  749. }
  750. // for plugins and themes - checkes what kind of language files directory structure we have
  751. function check_lanfiles($mode,$comp_name,$base_lan="English",$target_lan){
  752. global $ns,$sql;
  753. $folder['P'] = e_PLUGIN.$comp_name;
  754. $folder['T'] = e_THEME.$comp_name;
  755. $comp_dir = $folder[$mode];
  756. $baselang = $this->get_comp_lan_phrases($comp_dir."/languages/","English",1);
  757. $check = $this->get_comp_lan_phrases($comp_dir."/languages/",$target_lan,1);
  758. $text = "";
  759. $keys = array_keys($baselang);
  760. sort($keys);
  761. foreach($keys as $k)
  762. {
  763. if($k == 'bom')
  764. {
  765. continue;
  766. }
  767. $lnk = $k;
  768. //echo "klucz ".$k."<br />";
  769. $k_check = str_replace("English",$target_lan,$k);
  770. if(array_key_exists($k_check,$check))
  771. {
  772. $subkeys = array_keys($baselang[$k]);
  773. $er="";
  774. $utf_error = "";
  775. $bomkey = str_replace(".php","",$k_check);
  776. if($check['bom'][$bomkey])
  777. {
  778. $bom_error = "<i>".LAN_CHECK_15."</i><br />";
  779. $this->checkLog('bom',1);
  780. }
  781. else
  782. {
  783. $bom_error = "";
  784. }
  785. // $bom_error = ($check['bom'][$bomkey]) ? "<i>".LAN_CHECK_15."</i><br />" : ""; // illegal chars
  786. foreach($subkeys as $sk)
  787. {
  788. if($utf_error == "" && !$this->is_utf8($check[$k_check][$sk]))
  789. {
  790. $utf_error = "<i>".LAN_CHECK_19."</i><br />";
  791. $this->checkLog('utf',1);
  792. }
  793. /*
  794. if(!array_key_exists($sk,$check[$k_check]) || (trim($check[$k_check][$sk]) == "" && $baselang[$k][$sk] != ""))
  795. {
  796. $er .= ($er) ? "<br />" : "";
  797. $er .= $sk." ".LAN_CHECK_5;
  798. }
  799. */
  800. $er .= $this->check_lan_errors($baselang[$k],$check[$k_check],$sk);
  801. }
  802. if($this->errorsOnly == TRUE && !$er && !$utf_error && !$bom_error)
  803. {
  804. continue;
  805. }
  806. $text .= "<tr>
  807. <td class='forumheader3' style='width:20%'>".$comp_name."</td>
  808. <td class='forumheader3' style='width:25%'>".str_replace("English/","",$lnk)."</td>";
  809. $style = ($er) ? "forumheader2" : "forumheader3";
  810. $text .= "<td class='{$style}' style='width:50%'><div class='smalltext'>";
  811. $text .= $bom_error . $utf_error;
  812. $text .= (!$er && !$bom_error && !$utf_error) ? "<img src='".e_IMAGE."fileinspector/integrity_pass.png' alt='".LAN_OK."' />" : $er."<br />";
  813. $text .= "</div></td>";
  814. }
  815. else
  816. {
  817. $this->checkLog('file',1);
  818. $this->newFile($comp_dir."/languages/".$lnk,$target_lan);
  819. $text .= "<tr>
  820. <td class='forumheader3' style='width:20%'>".$comp_name."</td>
  821. <td class='forumheader3' style='width:25%'>".str_replace("English/","",$lnk)."</td>
  822. <td class='forumheader' style='width:50%'><span style='cursor:pointer' title=\"".str_replace("English",$target_lan,$lnk)."\">".LAN_CHECK_4."</span></td>";
  823. }
  824. $text .="<td class='forumheader3' style='width:5%;text-align:center'>
  825. <input class='btn btn-primary' type='button' style='width:60px' name='but_$i' value=\"".LAN_EDIT."\" onclick=\"window.location='".e_SELF."?f=".$comp_dir."/languages/".$lnk."&amp;lan=".$target_lan."&amp;mode={$mode}'\" /> ";
  826. $text .="</td></tr>";
  827. }
  828. // if (!$known) {$text = LAN_CHECK_18." : --> ".$fname." :: ".$dname;}
  829. return $text;
  830. }
  831. function newFile($lnk,$target_lan)
  832. {
  833. if($target_lan == 'English')
  834. {
  835. return;
  836. }
  837. $newfile = str_replace("English",$target_lan,$lnk);
  838. $dir = dirname($newfile);
  839. if($dir != '.' && !is_dir($dir))
  840. {
  841. // echo "<br />dir: ".$dir;
  842. mkdir($dir,0755);
  843. }
  844. if(!file_exists($newfile))
  845. {
  846. // echo "<br />file: ".$newfile;
  847. $data = chr(60)."?php\n\ndefine(\"EXAMPLE\",\"Generated Empty Language File\");";
  848. file_put_contents($newfile,$data);
  849. }
  850. }
  851. function edit_lanfiles($dir1,$dir2,$f1,$f2,$lan)
  852. {
  853. if($lan == '')
  854. {
  855. echo "Language selection was lost. ";
  856. return;
  857. }
  858. $ns = e107::getRender();
  859. $sql = e107::getDb();
  860. /* echo "<br />dir1 = $dir1";
  861. echo "<br />file1 = $f1";
  862. echo "<br />dir2 = $dir2";
  863. echo "<br />file2 = $f2";*/
  864. if($dir2.$f2 == e_LANGUAGEDIR.$lan."/English.php") // it's a language config file.
  865. {
  866. $f2 = $lan.".php";
  867. $root_file = e_LANGUAGEDIR.$lan."/".$lan.".php";
  868. }
  869. else
  870. {
  871. $root_file = $dir2.$f2;
  872. }
  873. if($dir2.$f2 == e_LANGUAGEDIR.$lan."/English_custom.php") // it's a language config file.
  874. {
  875. $f2 = $lan."_custom.php";
  876. $root_file = e_LANGUAGEDIR.$lan."/".$lan."_custom.php";
  877. }
  878. $writable = (is_writable($dir2)) ? TRUE : FALSE;
  879. $trans = $this->get_lan_file_phrases($dir1,$dir2,$f1,$f2);
  880. $keys = array_keys($trans);
  881. sort($keys);
  882. $text = "<div style='text-align:center'>
  883. <form method='post' action='".e_SELF."?".e_QUERY."' id='transform'>
  884. <table class='table table-striped'>
  885. <thead>
  886. <tr>
  887. <th>LAN</th>
  888. <th>English</th>
  889. <th>".$lan."</th>
  890. </tr>";
  891. $subkeys = array_keys($trans['orig']);
  892. foreach($subkeys as $sk)
  893. {
  894. $rowamount = round(strlen($trans['orig'][$sk])/34)+1;
  895. $hglt1=""; $hglt2="";
  896. if ($trans['tran'][$sk] == "" && $trans['orig'][$sk]!="") {
  897. $hglt1="<span style='font-style:italic;font-weight:bold;color:red'>";
  898. $hglt2="</span>";
  899. }
  900. $text .="<tr>
  901. <td style='width:10%;vertical-align:top'>".$hglt1.htmlentities($sk).$hglt2."</td>
  902. <td style='width:40%;vertical-align:top'>".htmlentities(str_replace("ndef++","",$trans['orig'][$sk])) ."</td>";
  903. $text .= "<td class='forumheader3' style='width:50%;vertical-align:top'>";
  904. $text .= ($writable) ? "<textarea class='input-xxlarge' name='newlang[]' rows='$rowamount' cols='45' style='height:100%'>" : "";
  905. $text .= str_replace("ndef++","",$trans['tran'][$sk]);
  906. $text .= ($writable) ? "</textarea>" : "";
  907. //echo "orig --> ".$trans['orig'][$sk]."<br />";
  908. if (strpos($trans['orig'][$sk],"ndef++") !== False)
  909. {
  910. //echo "+orig --> ".$trans['orig'][$sk]." <> ".strpos($trans['orig'][$sk],"ndef++")."<br />";
  911. $text .= "<input type='hidden' name='newdef[]' value='ndef++".$sk."' />";
  912. }
  913. else
  914. {
  915. $text .= "<input type='hidden' name='newdef[]' value='".$sk."' />";
  916. }
  917. $text .="</td></tr>";
  918. }
  919. unset($_SESSION['lancheck-edit-file']);
  920. //Check if directory is writable
  921. $text .= "</table>";
  922. if($writable)
  923. {
  924. $text .="<div class='buttons-bar center'>
  925. <input type='hidden' name='lan' value='{$lan}' />
  926. <input class='btn btn-primary' type='submit' name='submit' value=\"".LAN_SAVE." ".str_replace($dir2,"",$root_file)." \" />
  927. </div>";
  928. if($root_file)
  929. {
  930. $_SESSION['lancheck-edit-file'] = $root_file;
  931. }
  932. }
  933. $text .= "
  934. </form>
  935. </div>";
  936. $text .= "<form method='post' action='".e_SELF."?tools' id='select_lang'>
  937. <div style='text-align:center'><br />";
  938. $text .= (!$writable) ? "<br />".$dir2.$f2.LAN_NOTWRITABLE : "";
  939. $text .= "<br /><br /><input class='btn' type='submit' name='language_sel[{$lan}]' value=\"".LAN_BACK."\" />
  940. </div></form>";
  941. $caption = LANG_LAN_21.SEP.$lan.SEP.LAN_CHECK_2.SEP.LAN_EDIT.SEP.str_replace("../","",$dir2.$f2);
  942. $ns->tablerender($caption, $text);
  943. }
  944. function fill_phrases_array($data,$type)
  945. {
  946. $retloc = array();
  947. if(preg_match_all('/(\/\*[\s\S]*?\*\/)/i',$data, $multiComment))
  948. {
  949. $data = str_replace($multiComment[1],'',$data); // strip multi-line comments.
  950. }
  951. if(preg_match('/^\s*?setlocale\s*?\(\s*?([\w]+)\s*?,\s*?(.+)\s*?\)\s*?;/im',$data,$locale)) // check for setlocale();
  952. {
  953. $retloc[$type][$locale[1]]= $locale[2];
  954. }
  955. if(preg_match_all('/^\s*?define\s*?\(\s*?(\'|\")([\w]+)(\'|\")\s*?,\s*?(\'|\")([\s\S]*?)\s*?(\'|\")\s*?\)\s*?;/im',$data,$matches))
  956. {
  957. $def = $matches[2];
  958. $values = $matches[5];
  959. foreach($def as $k=>$d)
  960. {
  961. $retloc[$type][$d]= $values[$k];
  962. }
  963. }
  964. return $retloc;
  965. /*
  966. echo "<h2>Raw Data ".$type."</h2><pre>";
  967. echo htmlentities($data);
  968. echo "</pre>";
  969. */
  970. }
  971. //--------------------------------------------------------------------
  972. function is_utf8($str) {
  973. /*
  974. * @see http://hsivonen.iki.fi/php-utf8/ validation.php
  975. */
  976. if(strtolower(CHARSET) != "utf-8" || $str == "")
  977. {
  978. return TRUE;
  979. }
  980. return (preg_match('/^.{1}/us',$str,$ar) == 1);
  981. }
  982. }
  983. /*
  984. class lancheck_old
  985. {
  986. var $error_count=0;
  987. function check_core_lanfiles($checklan,$subdir=''){
  988. $frm = e107::getForm();
  989. $English = $this->get_comp_lan_phrases(e_LANGUAGEDIR."English/".$subdir,$checklan);
  990. $check = $this->get_comp_lan_phrases(e_LANGUAGEDIR.$checklan."/".$subdir,$checklan);
  991. $legend_txt = LAN_CHECK_3.": ".$_POST['language']."/".$subdir;
  992. $fieldset_id = $subdir ? str_replace('/', '', $_POST['language'])."-".str_replace('/', '', $subdir) : str_replace('/', '', $_POST['language']);
  993. $text .= "
  994. <fieldset id='core-lancheck-{$fieldset_id}'>
  995. <legend>{$legend_txt}</legend>
  996. <table class='table adminlist'>
  997. <colgroup>
  998. <col style='width: 50%' />
  999. <col style='width: 40%' />
  1000. <col style='width: 10%' />
  1001. </colgroup>
  1002. <thead>
  1003. <tr>
  1004. <th>".LAN_CHECK_16."</th>
  1005. <th>".$_POST['language'].' '.LAN_CHECK_20."</th>
  1006. <th class='center last'>".LAN_OPTIONS."</th>
  1007. </tr>
  1008. </thead>
  1009. <tbody>
  1010. ";
  1011. $keys = array_keys($English);
  1012. sort($keys);
  1013. $i = 0;
  1014. foreach($keys as $k)
  1015. {
  1016. if($k != "bom")
  1017. {
  1018. $lnk = $k;
  1019. $k_check = str_replace("English",$checklan,$k);
  1020. $text .= "
  1021. <tr>
  1022. ";
  1023. if(array_key_exists($k,$check))
  1024. {
  1025. $text .= "
  1026. <td>{$lnk}</td>
  1027. ";
  1028. $subkeys = array_keys($English[$k]);
  1029. $er="";
  1030. $utf_error = "";
  1031. $bomkey = str_replace(".php","",$k_check);
  1032. $bom_error = ($check['bom'][$bomkey]) ? "<span class='error'><em>".str_replace("[php]", "<?php", LAN_CHECK_15)."</em></span><br />" : ""; // illegal chars
  1033. foreach($subkeys as $sk)
  1034. {
  1035. if($utf_error == "" && !$this->is_utf8($check[$k][$sk]))
  1036. {
  1037. $utf_error = "<span class='error'><em>".LAN_CHECK_19."</em></span><br />";
  1038. }
  1039. if($sk == "LC_ALL"){
  1040. $check[$k][$sk] = str_replace(chr(34).chr(34),"",$check[$k][$sk]);
  1041. }
  1042. if((!array_key_exists($sk,$check[$k]) && $English[$k][$sk] != "") || (trim($check[$k][$sk]) == "" && $English[$k][$sk] != ""))
  1043. {
  1044. $er .= ($er) ? "<br />" : "";
  1045. $er .= $sk." ".LAN_CHECK_5;
  1046. $this->error_count++;
  1047. }
  1048. }
  1049. $style = ($er) ? "warning" : "success";
  1050. $text .= "
  1051. <td class='{$style}' style='width:50%'>
  1052. <div class='smalltext'>
  1053. ";
  1054. $text .= $bom_error . $utf_error;
  1055. if(!$er && !$bom_error && !$utf_error)
  1056. {
  1057. $text .= LAN_OK;
  1058. }
  1059. else
  1060. {
  1061. $text .= $er."<br />";
  1062. $this->error_count++;
  1063. }
  1064. $text .= "
  1065. </div>
  1066. </td>
  1067. ";
  1068. }
  1069. else
  1070. {
  1071. // file missing
  1072. $text .= "
  1073. <td>{$lnk}</td>
  1074. <td><span class='error'>".LAN_CHECK_4."</span></td>
  1075. ";
  1076. $this->error_count++;
  1077. }
  1078. // Leave in EDIT button for all entries - to allow re-translation of bad entries.
  1079. $subpath = ($subdir!='') ? $subdir.$k : $k;
  1080. $text .= "
  1081. <td class='center'>
  1082. ".$frm->admin_button('but-corelan-'.str_replace(array('/', '\\'), '-', $subdir).$i, LAN_EDIT, 'edit', '', array('other' => "onclick=\"window.location='".e_SELF."?".$subpath."|".$_POST['language']."'\""))."
  1083. ";
  1084. $text .= "
  1085. </td>
  1086. </tr>
  1087. ";
  1088. }
  1089. $i++;
  1090. }
  1091. $text .= "
  1092. </tbody>
  1093. </table>
  1094. </fieldset>
  1095. ";
  1096. return $text;
  1097. }
  1098. function get_lan_file_phrases($dir1,$dir2,$file1,$file2){
  1099. $ret = array();
  1100. $fname = $dir1.$file1;
  1101. $type='orig';
  1102. if(is_file($fname))
  1103. {
  1104. $data = file($fname);
  1105. $ret=$ret + $this->fill_phrases_array($data,$type);
  1106. if(substr($data[0],0,5) != "<?php")
  1107. {
  1108. $key = str_replace(".php","",$fname);
  1109. $ret['bom'][$key] = $fname;
  1110. }
  1111. }
  1112. $fname = $dir2.$file2;
  1113. $type='tran';
  1114. if(is_file($fname))
  1115. {
  1116. $data = file($fname);
  1117. $ret=$ret + $this->fill_phrases_array($data,$type);
  1118. if(substr($data[0],0,5) != "<?php")
  1119. {
  1120. $key = str_replace(".php","",$fname);
  1121. $ret['bom'][$key] = $fname;
  1122. }
  1123. }
  1124. return $ret;
  1125. }
  1126. function get_comp_lan_phrases($comp_dir,$lang,$depth=0)
  1127. {
  1128. $fl = e107::getFile();
  1129. $ret = array();
  1130. if($lang_array = $fl->get_files($comp_dir, '\.php','standard',$depth)){
  1131. sort($lang_array);
  1132. }
  1133. $regexp = (strpos($comp_dir,e_LANGUAGEDIR) !== FALSE) ? "#.php#" : "#".$lang."#";
  1134. foreach($lang_array as $f)
  1135. {
  1136. if(preg_match($regexp,$f['path'].$f['fname']))
  1137. {
  1138. $data = file($f['path'].$f['fname']);
  1139. $relpath = str_replace($comp_dir,"",$f['path']);
  1140. if(substr($data[0],0,5) != "<?php")
  1141. {
  1142. $key = str_replace(".php","",$relpath.$f['fname']);
  1143. $ret['bom'][$key] = $f['fname'];
  1144. }
  1145. if($f['path'].$f['fname'] == e_LANGUAGEDIR.$lang."/".$lang.".php")
  1146. {
  1147. $f['fname'] = "English.php"; // change the key for the main language file.
  1148. }
  1149. if($f['path'].$f['fname'] == e_LANGUAGEDIR.$lang."/".$lang."_custom.php")
  1150. {
  1151. $f['fname'] = "English_custom.php"; // change the key for the main language file.
  1152. }
  1153. $ret=$ret + $this->fill_phrases_array($data,$relpath.$f['fname']);
  1154. }
  1155. }
  1156. return $ret;
  1157. }
  1158. // for plugins and themes - checks what kind of language files directory structure we have
  1159. function check_lanfiles($mode, $comp_name, $base_lan="English", $target_lan)
  1160. {
  1161. $frm = e107::getForm();
  1162. $folder['P'] = e_PLUGIN.$comp_name;
  1163. $folder['T'] = e_THEME.$comp_name;
  1164. $comp_dir = $folder[$mode];
  1165. $baselang = $this->get_comp_lan_phrases($comp_dir."/languages/","English",1);
  1166. $check = $this->get_comp_lan_phrases($comp_dir."/languages/",$target_lan,1);
  1167. $text = "";
  1168. $keys = array_keys($baselang);
  1169. sort($keys);
  1170. $i = 0;
  1171. foreach($keys as $k)
  1172. {
  1173. $lnk = $k;
  1174. //echo "klucz ".$k."<br />";
  1175. $k_check = str_replace("English",$target_lan,$k);
  1176. $text .= "
  1177. <tr>
  1178. ";
  1179. if(array_key_exists($k_check,$check))
  1180. {
  1181. $text .= "
  1182. <td>".$comp_name."</td>
  1183. <td>".str_replace("English/","",$lnk)."</td>
  1184. ";
  1185. $subkeys = array_keys($baselang[$k]);
  1186. $er = "";
  1187. $utf_error = "";
  1188. $bomkey = str_replace(".php","",$k_check);
  1189. $bom_error = ($check['bom'][$bomkey]) ? "<span class='error'><em>".LAN_CHECK_15."</em></span><br />" : ""; // illegal chars
  1190. foreach($subkeys as $sk)
  1191. {
  1192. if($utf_error == "" && !$this->is_utf8($check[$k_check][$sk]))
  1193. {
  1194. $utf_error = "<span class='error'><em>".LAN_CHECK_19."</em></span><br />";
  1195. }
  1196. if(!array_key_exists($sk,$check[$k_check]) || (trim($check[$k_check][$sk]) == "" && $baselang[$k][$sk] != ""))
  1197. {
  1198. $er .= ($er) ? "<br />" : "";
  1199. $er .= $sk." ".LAN_CHECK_5;
  1200. $this->error_count++;
  1201. }
  1202. }
  1203. $style = ($er) ? "warning" : "success";
  1204. $text .= "
  1205. <td class='{$style}' style='width:50%'>
  1206. <div class='smalltext'>
  1207. ";
  1208. $text .= $bom_error . $utf_error;
  1209. $text .= (!$er && !$bom_error && !$utf_error) ? LAN_OK : $er."<br />";
  1210. $text .= "
  1211. </div>
  1212. </td>
  1213. ";
  1214. }
  1215. else
  1216. {
  1217. $text .= "
  1218. <td>".$comp_name."</td>
  1219. <td>".str_replace("English/","",$lnk)."</td>
  1220. <td><span class='error' style='cursor:pointer' title='".str_replace("English",$target_lan,$lnk)."'>".LAN_CHECK_4."</span></td>
  1221. ";
  1222. $this->error_count++;
  1223. }
  1224. $text .="
  1225. <td class='center'>
  1226. ".$frm->admin_button('but-corelan-'.str_replace(array('/', '\\'), '-', $comp_dir).$i, LAN_EDIT, 'edit', '', array('other'=> "onclick=\"window.location='".e_SELF."?".$comp_dir."/languages/".$lnk."|".$target_lan."|file'\""))."
  1227. ";
  1228. $text .="
  1229. </td>
  1230. </tr>
  1231. ";
  1232. $i++;
  1233. }
  1234. return $text;
  1235. }
  1236. function edit_lanfiles($dir1,$dir2,$f1,$f2){
  1237. global $e107, $lan;
  1238. $mes = e107::getMessage();
  1239. $ns = e107::getRender();
  1240. // echo "<br />dir1 = $dir1";
  1241. //echo "<br />file1 = $f1";
  1242. //echo "<br />dir2 = $dir2";
  1243. //echo "<br />file2 = $f2";
  1244. if($dir2.$f2 == e_LANGUAGEDIR.$lan."/English.php") // it's a language config file.
  1245. {
  1246. $f2 = $lan.".php";
  1247. $root_file = e_LANGUAGEDIR.$lan."/".$lan.".php";
  1248. }
  1249. else
  1250. {
  1251. $root_file = $dir2.$f2;
  1252. }
  1253. if($dir2.$f2 == e_LANGUAGEDIR.$lan."/English_custom.php") // it's a language config file.
  1254. {
  1255. $f2 = $lan."_custom.php";
  1256. $root_file = e_LANGUAGEDIR.$lan."/".$lan."_custom.php";
  1257. }
  1258. $writable = (is_writable($dir2)) ? TRUE : FALSE;
  1259. $trans = $this->get_lan_file_phrases($dir1,$dir2,$f1,$f2);
  1260. $keys = array_keys($trans);
  1261. sort($keys);
  1262. $text = "
  1263. <form method='post' action='".e_SELF."?".e_QUERY."' id='transform'>
  1264. <fieldset id='core-lancheck-edit'>
  1265. <legend>".LAN_CHECK_3." ".str_replace(array(e_PLUGIN, e_LANGUAGEDIR), array(e_PLUGIN_ABS, e_LANGUAGEDIR_ABS), $dir2)."{$f2} -&gt; {$lan}</legend>
  1266. <table class='table table-striped'>
  1267. <colgroup>
  1268. <col style='width: 20%' />
  1269. <col style='width: 40%' />
  1270. <col style='width: 40%' />
  1271. </colgroup>
  1272. <thead>
  1273. <tr>
  1274. <th>&nbsp;</th>
  1275. <th>".LAN_CHECK_16."</th>
  1276. <th class='last'>Translate to ".$lan."</th>
  1277. </tr>
  1278. </thead>
  1279. <tbody>
  1280. ";
  1281. $subkeys = array_keys($trans['orig']);
  1282. foreach($subkeys as $sk)
  1283. {
  1284. $rowamount = round(strlen($trans['orig'][$sk])/34)+1;
  1285. $hglt1=""; $hglt2="";
  1286. if ($trans['tran'][$sk] == "" && $trans['orig'][$sk]!="") {
  1287. $hglt1="<span class='error'>";
  1288. $hglt2="</span>";
  1289. }
  1290. $text .= "
  1291. <tr>
  1292. <td>".$hglt1.htmlentities($sk).$hglt2."</td>
  1293. <td>".htmlentities(str_replace("ndef++", "", $trans['orig'][$sk])) ."</td>
  1294. <td>
  1295. ".(($writable) ? "<textarea class='input-xxlarge' name='newlang[]' rows='{$rowamount}' cols='45'>" : "")
  1296. .str_replace("ndef++","",$trans['tran'][$sk])
  1297. .(($writable) ? "</textarea>" : "")."
  1298. ";
  1299. //echo "orig --> ".$trans['orig'][$sk]."<br />";
  1300. if (strpos($trans['orig'][$sk],"ndef++") !== False)
  1301. {
  1302. //echo "+orig --> ".$trans['orig'][$sk]." <> ".strpos($trans['orig'][$sk],"ndef++")."<br />";
  1303. $text .= "
  1304. <input type='hidden' name='newdef[]' value='ndef++".$sk."' />
  1305. ";
  1306. }
  1307. else
  1308. {
  1309. $text .= "
  1310. <input type='hidden' name='newdef[]' value='".$sk."' />
  1311. ";
  1312. }
  1313. $text .="
  1314. </td>
  1315. </tr>
  1316. ";
  1317. }
  1318. $text .= "
  1319. </tbody>
  1320. </table>
  1321. ";
  1322. //Check if directory is writable
  1323. if($writable)
  1324. {
  1325. //FIXME place of LAN_SAVE
  1326. $text .="
  1327. <div class='buttons-bar center'>
  1328. <button class='update btn btn-success' type='submit' name='submit' value='sprintXXf'><span>".LAN_SAVE." ".str_replace($dir2, "", $root_file)."</span></button>
  1329. ".(($root_file) ? "<input type='hidden' name='root' value='".$root_file."' />" : "")."
  1330. </div>
  1331. ";
  1332. }
  1333. $text .= "
  1334. </fieldset>
  1335. </form>
  1336. ";
  1337. $text .= "
  1338. <form method='post' action='".e_SELF."' id='select_lang'>
  1339. <div style='text-align:center'>
  1340. ".((!$writable) ? $dir2.$f2.LAN_NOTWRITABLE : "")."
  1341. <br />
  1342. <button class='submit btn' type='submit' name='language_sel' value='no-value'><span>".LAN_BACK."</span></button>
  1343. <input type='hidden' name='language' value='$lan' />
  1344. </div>
  1345. </form>
  1346. ";
  1347. $ns->tablerender(LAN_CHECK_PAGE_TITLE.' - '.LAN_CHECK_24, $text);
  1348. require_once(e_ADMIN."footer.php");
  1349. exit;
  1350. }
  1351. function fill_phrases_array($data,$type) {
  1352. $retloc = array();
  1353. foreach($data as $line){
  1354. //echo "line--> ".$line."<br />";
  1355. if (strpos($line,"define(") !== FALSE && strpos($line,");") === FALSE)
  1356. {
  1357. $indef=1;
  1358. $bigline="";
  1359. // echo "big1 -->".$line."<br />";
  1360. }
  1361. if ($indef)
  1362. {
  1363. $bigline.=str_replace("\n","",$line);
  1364. // echo "big2 -->".$line."<br />";
  1365. }
  1366. if (strpos($line,"define(") === FALSE && strpos($line,");") !== FALSE)
  1367. {
  1368. $indef=0;
  1369. $we_have_bigline=1;
  1370. // echo "big3 -->".$line."<br />";
  1371. }
  1372. if(strpos($line,"setlocale(") !== FALSE)
  1373. {
  1374. $indef=1;
  1375. $we_have_bigline=0;
  1376. }
  1377. if ((strpos($line,"define(") !== FALSE && strpos($line,");") !== FALSE && substr(ltrim($line),0,2) != "//") || $we_have_bigline || strpos($line,"setlocale(") !== FALSE)
  1378. {
  1379. if ($we_have_bigline)
  1380. {
  1381. $we_have_bigline=0;
  1382. $line=$bigline;
  1383. // echo "big -->".$line."<br />";
  1384. }
  1385. $ndef = "";
  1386. //echo "_ndefline -->".$line."<br />";
  1387. if (strpos($line,"defined(") !== FALSE )
  1388. {
  1389. $ndef = "ndef++";
  1390. $line = substr($line,strpos($line,"define("));
  1391. }
  1392. if(strpos($line,"setlocale(") !== FALSE)
  1393. {
  1394. $pos = substr(strstr($line,","),1);
  1395. $rep = array(");","\n",'""');
  1396. $val = str_replace($rep,"",$pos);
  1397. $retloc[$type]['LC_ALL']= $val;
  1398. // $retloc['orig']['LC_ALL']= "'en'";
  1399. }
  1400. else
  1401. {
  1402. //echo "ndefline: ".$line."<br />";
  1403. if(preg_match("#\"(.*?)\".*?\"(.*)\"#",$line,$matches) ||
  1404. preg_match("#\'(.*?)\'.*?\"(.*)\"#",$line,$matches) ||
  1405. preg_match("#\"(.*?)\".*?\'(.*)\'#",$line,$matches) ||
  1406. preg_match("#\'(.*?)\'.*?\'(.*)\'#",$line,$matches) ||
  1407. preg_match("#\((.*?)\,.*?\"(.*)\"#",$line,$matches) ||
  1408. preg_match("#\((.*?)\,.*?\'(.*)\'#",$line,$matches))
  1409. {
  1410. //echo "get_lan -->".$matches[1]." :: ".$ndef.$matches[2]."<br />";
  1411. if(!isset($retloc[$type][$matches[1]]))
  1412. {
  1413. $retloc[$type][$matches[1]]= $ndef.$matches[2];
  1414. }
  1415. }
  1416. }
  1417. }
  1418. }
  1419. return $retloc;
  1420. }
  1421. //--------------------------------------------------------------------
  1422. function is_utf8($str) {
  1423. // @see http://hsivonen.iki.fi/php-utf8/ validation.php
  1424. //@TODO: always TRUE
  1425. // if(strtolower(CHARSET) != "utf-8" || $str == "")
  1426. {
  1427. return TRUE;
  1428. }
  1429. return (preg_match('/^.{1}/us',$str,$ar) == 1);
  1430. }
  1431. }
  1432. */
  1433. /*
  1434. function lancheck_adminmenu()
  1435. {
  1436. include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_language.php");
  1437. global $action;
  1438. $pref = e107::getPref();
  1439. if ($action == "") {
  1440. $action = "tools";
  1441. }
  1442. if($action == "modify")
  1443. {
  1444. $action = "db";
  1445. }
  1446. $var['main']['text'] = LAN_PREFS;
  1447. $var['main']['link'] = e_ADMIN_ABS."language.php";
  1448. if(isset($pref['multilanguage']) && $pref['multilanguage']){
  1449. $var['db']['text'] = LANG_LAN_03;
  1450. $var['db']['link'] = e_ADMIN_ABS."language.php?db";
  1451. }
  1452. $var['tools']['text'] = ADLAN_CL_6;
  1453. $var['tools']['link'] = e_ADMIN_ABS."language.php?tools";
  1454. e107::getNav()->admin(ADLAN_132, $action, $var);
  1455. }
  1456. $ns->tablerender(LAN_CHECK_PAGE_TITLE.' - '.LAN_CHECK_1, LAN_CHECK_26);
  1457. require_once(e_ADMIN."footer.php");
  1458. */