PageRenderTime 59ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/e107_admin/language.php

https://github.com/CasperGemini/e107
PHP | 2004 lines | 1797 code | 132 blank | 75 comment | 82 complexity | 347e1c938a9e647868b01ad4e49f8525 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  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 - Languages
  10. */
  11. require_once ("../class2.php");
  12. if (!getperms('L'))
  13. {
  14. header("location:".e_BASE."index.php");
  15. exit;
  16. }
  17. //include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
  18. e107::coreLan('language', true);
  19. $e_sub_cat = 'language';
  20. require_once ("auth.php");
  21. $frm = e107::getForm();
  22. $mes = e107::getMessage();
  23. include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_lancheck.php");
  24. require_once(e_ADMIN."lancheck.php");
  25. require_once(e_HANDLER."language_class.php");
  26. // $ln = new language;
  27. $ln = $lng;
  28. $lck = new lancheck;
  29. $tabs = table_list(); // array("news","content","links");
  30. $lanlist = e107::getLanguage()->installed();// Bugfix - don't use e_LANLIST as it's cached (SESSION)
  31. $message = '';
  32. if (e_QUERY)
  33. {
  34. $tmp = explode('.', e_QUERY);
  35. $action = varset($tmp[0]);
  36. $sub_action = varset($tmp[1]);
  37. $id = varset($tmp[2]);
  38. unset($tmp);
  39. }
  40. elseif(!getperms('0'))
  41. {
  42. $action = 'tools';
  43. }
  44. if (isset($_POST['submit_prefs']) && isset($_POST['mainsitelanguage']) && getperms('0'))
  45. {
  46. unset($temp);
  47. $changes = array();
  48. $temp['multilanguage'] = $_POST['multilanguage'];
  49. $temp['multilanguage_subdomain'] = $_POST['multilanguage_subdomain'];
  50. $temp['multilanguage_domain'] = $_POST['multilanguage_domain'];
  51. $temp['sitelanguage'] = $_POST['mainsitelanguage'];
  52. $temp['adminlanguage'] = $_POST['mainadminlanguage'];
  53. $temp['noLanguageSubs'] = $_POST['noLanguageSubs'];
  54. e107::getConfig()->setPref($temp)->save(true);
  55. e107::getSession()->clear('e_language');
  56. }
  57. // ----------------- delete tables ---------------------------------------------
  58. if (isset($_POST['del_existing']) && $_POST['lang_choices'] && getperms('0'))
  59. {
  60. $lang = strtolower($_POST['lang_choices']);
  61. foreach ($tabs as $del_table)
  62. {
  63. if ($sql->db_Table_exists($lang."_".$del_table,TRUE))
  64. {
  65. // echo $del_table." exists<br />";
  66. $qry = "DROP TABLE ".$mySQLprefix."lan_".$lang."_".$del_table;
  67. if (mysql_query($qry))
  68. {
  69. $msg = $tp->lanVars(LANG_LAN_100, $_POST['lang_choices'].' '.$del_table);
  70. $message .= $msg.'[!br!]';
  71. $mes->addSuccess($msg);
  72. }
  73. else
  74. {
  75. $msg = $tp->lanVars(LANG_LAN_101, $_POST['lang_choices'].' '.$del_table);
  76. $message .= $msg.'[!br!]';
  77. $mes->addWarning($msg);
  78. }
  79. }
  80. }
  81. $admin_log->log_event('LANG_02', $message.'[!br!]', E_LOG_INFORMATIVE, '');
  82. $sql->db_ResetTableList();
  83. if ($action == 'modify')
  84. $action = 'db';//FIX - force db action when deleting all lan tables
  85. }
  86. // ----------create tables -----------------------------------------------------
  87. if (isset($_POST['create_tables']) && $_POST['language'])
  88. {
  89. $table_to_copy = array();
  90. $lang_to_create = array();
  91. foreach ($tabs as $value)
  92. {
  93. $lang = strtolower($_POST['language']);
  94. if (isset($_POST[$value]))
  95. {
  96. $copdata = ($_POST['copydata_'.$value]) ? 1 : 0;
  97. if ($sql->db_CopyTable($value, "lan_".$lang."_".$value, $_POST['drop'], $copdata))
  98. {
  99. $msg = $tp->lanVars(LANG_LAN_103, $_POST['language'].' '.$value);
  100. $message .= $msg . '[!br!]'; // Used in admin log.
  101. $mes->addSuccess($msg);
  102. }
  103. else
  104. {
  105. if (!$_POST['drop'])
  106. {
  107. $msg = $tp->lanVars(LANG_LAN_00, $_POST['language'].' '.$value);
  108. $message .= $msg . '[!br!]';
  109. $mes->addWarning($msg);
  110. }
  111. else
  112. {
  113. $msg = $tp->lanVars(LANG_LAN_01, $_POST['language'].' '.$value);
  114. $message .= $msg . '[!br!]';
  115. $mes->addWarning($msg);
  116. }
  117. }
  118. }
  119. elseif ($sql->db_Table_exists($value,$_POST['language']))
  120. {
  121. if ($_POST['remove'])
  122. {
  123. // Remove table.
  124. if (mysql_query("DROP TABLE ".$mySQLprefix."lan_".$lang."_".$value))
  125. {
  126. $message .= $_POST['language'].' '.$value.' '.LAN_DELETED.'[!br!]'; // can be removed?
  127. $mes->addSuccess($_POST['language'].' '.$value.' '.LAN_DELETED);
  128. }
  129. else
  130. {
  131. $msg = $tp->lanVars(LANG_LAN_02, $_POST['language'].' '.$value);
  132. $message .= $msg . '[!br!]';
  133. $mes->addWarning($msg);
  134. }
  135. }
  136. else
  137. {
  138. // leave table. LANG_LAN_104
  139. $msg = $tp->lanVars(LANG_LAN_104, $_POST['language'].' '.$value);
  140. $message .= $msg . '[!br!]';
  141. $mes->addInfo($msg);
  142. }
  143. }
  144. }
  145. $admin_log->log_event('LANG_03', $message, E_LOG_INFORMATIVE, '');
  146. $sql->db_ResetTableList();
  147. }
  148. /*
  149. if(isset($message) && $message)
  150. {
  151. $ns->tablerender(LAN_OK, $message);
  152. }
  153. */
  154. unset($text);
  155. if (!e_QUERY || $action == 'main' && !$_POST['language'] && !$_POST['edit_existing'])
  156. {
  157. multilang_prefs();
  158. }
  159. if (varset($action) == 'db')
  160. {
  161. multilang_db();
  162. }
  163. /*
  164. if (varset($_POST['ziplang']) && varset($_POST['language']))
  165. {
  166. if(varset($pref['lancheck'][$_POST['language']]) == 1)
  167. {
  168. $text = zip_up_lang($_POST['language']);
  169. $admin_log->log_event('LANG_04', $_POST['language'], E_LOG_INFORMATIVE, '');
  170. $mes->addInfo(LANG_LAN_25.': '.$text);
  171. }
  172. else
  173. {
  174. $mes->addWarning(LANG_LAN_36);
  175. }
  176. }
  177. */
  178. // imported from e107 v1
  179. if (varset($_POST['ziplang']))
  180. {
  181. $certVal = isset($_POST['contribute_pack']) ? 1 : 0;
  182. if(!varset($_COOKIE['e107_certified']))
  183. {
  184. cookie('e107_certified',$certVal,(time() + 3600 * 24 * 30));
  185. }
  186. else
  187. {
  188. $_COOKIE['e107_certified'] = $certVal;
  189. }
  190. $_POST['language'] = key($_POST['ziplang']);
  191. // If no session data, scan before zipping.
  192. if(!isset($_SESSION['lancheck'][$_POST['language']]['total']) || $_SESSION['lancheck'][$_POST['language']]['total']!='0')
  193. {
  194. $_POST['language_sel'] = $_POST['ziplang'];
  195. $lck->check_all('norender');
  196. unset($_POST['language_sel']);
  197. }
  198. $status = zip_up_lang($_POST['language']);
  199. if($status['error']==FALSE)
  200. {
  201. $text = $status['message']."<br />";
  202. $text .= share($status['file']);
  203. $mes->addSuccess($text);
  204. //$ns->tablerender(LAN_CREATED, $text );
  205. }
  206. else
  207. {
  208. $mes->addError($status['message']);
  209. //$ns->tablerender(LAN_CREATED_FAILED, $status['message']);
  210. }
  211. echo $mes->render();
  212. }
  213. function find_locale($language)
  214. {
  215. if(!is_readable(e_LANGUAGEDIR.$language."/".$language.".php"))
  216. {
  217. return FALSE;
  218. }
  219. $code = file_get_contents(e_LANGUAGEDIR.$language."/".$language.".php");
  220. $tmp = explode("\n",$code);
  221. $srch = array("define","'",'"',"(",")",";","CORE_LC2","CORE_LC",",");
  222. foreach($tmp as $line)
  223. {
  224. if(strpos($line,"CORE_LC") !== FALSE && (strpos($line,"CORE_LC2") === FALSE))
  225. {
  226. $lc = trim(str_replace($srch,"",$line));
  227. }
  228. elseif(strpos($line,"CORE_LC2") !== FALSE)
  229. {
  230. $lc2 = trim(str_replace($srch,"",$line));
  231. }
  232. }
  233. if(!isset($lc) || !isset($lc2) || $lc=="" || $lc2=="")
  234. {
  235. return FALSE;
  236. }
  237. return substr($lc,0,2)."_".strtoupper(substr($lc2,0,2));
  238. //
  239. }
  240. /**
  241. * Share Language File
  242. * @param object $newfile
  243. * Usage of e107 is granted to you provided that this function is not modified or removed in any way.
  244. * @return
  245. */
  246. function share($newfile)
  247. {
  248. global $pref;
  249. if(!$newfile || E107_DEBUG_LEVEL > 0)
  250. {
  251. return;
  252. }
  253. global $tp;
  254. $full_link = $tp->createConstants($newfile);
  255. $email_message = "<br />Site: <a href='".SITEURL."'>".SITENAME."</a>
  256. <br />User: ".USERNAME."\n
  257. <br />Email: ".USEREMAIL."\n
  258. <br />Language: ".$_POST['language']."\n
  259. <br />IP:".USERIP."
  260. <br />...would like to contribute the following language pack for e107. (see attached)<br />:
  261. <br />Missing Files: ".$_SESSION['lancheck'][$_POST['language']]['file']."
  262. <br />Bom Errors : ".$_SESSION['lancheck'][$_POST['language']]['bom']."
  263. <br />UTF Errors : ".$_SESSION['lancheck'][$_POST['language']]['utf']."
  264. <br />Definition Errors : ".$_SESSION['lancheck'][$_POST['language']]['def']."
  265. <br />Total Errors: ".$_SESSION['lancheck'][$_POST['language']]['total']."
  266. <br />
  267. <br />XML file: ".$_SESSION['lancheck'][$_POST['language']]['xml'];
  268. require_once(e_HANDLER."mail.php");
  269. $send_to = (!$_POST['contribute_pack']) ? "languagepacks@e107inc.org" : "certifiedpack@e107inc.org";
  270. $to_name = "e107 Inc.";
  271. $Cc = "";
  272. $Bcc = "";
  273. $returnpath='';
  274. $returnreceipt='';
  275. $inline ="";
  276. $subject = (!$_POST['contribute_pack']) ? "[0.7 LanguagePack] " : "[0.7 Certified LanguagePack] ";
  277. $subject .= basename($newfile);
  278. if(!@sendemail($send_to, $subject, $email_message, $to_name, '', '', $newfile, $Cc, $Bcc, $returnpath, $returnreceipt,$inline))
  279. {
  280. $text = "<div style='padding:40px'>";
  281. $text .= defined('LANG_LAN_EML') ? "<b>".LANG_LAN_EML."</b>" : "<b>There was a problem sending the language-pack. Please email your verified language pack to:</b>";
  282. $text .= " <a href='mailto:".$send_to."?subject=".$subject."'>".$send_to."</a>";
  283. $text .= "</div>";
  284. return $text;
  285. }
  286. elseif($_POST['contribute_pack'])
  287. {
  288. return "<div style='padding:40px'>Pack Sent to e107 Inc. A confirmation email will be sent to ".$pref['siteadminemail']." once it is received.<br />Please also make sure that email coming from ".$send_to." is not blocked by your spam filter.</div>";
  289. }
  290. }
  291. $debug = "<br />f=".$_GET['f'];
  292. $debug .= "<br />mode=".$_GET['mode'];
  293. $debug .= "<br />lan=".$_GET['lan'];
  294. // $ns->tablerender("Debug",$debug);
  295. $rendered = $lck->init(); // Lancheck functions.
  296. if (varset($action) == "tools" && !$rendered)
  297. {
  298. show_tools();
  299. if($languagePacks = available_langpacks() )
  300. {
  301. e107::getRender()->tablerender(LANG_LAN_34,$languagePacks );
  302. }
  303. }
  304. function findIncludedFiles($script,$reverse=false)
  305. {
  306. $mes = e107::getMessage();
  307. $data = file_get_contents($script);
  308. if(strpos($data, 'e_admin_dispatcher')!==false)
  309. {
  310. $reverse = false;
  311. }
  312. $dir = dirname($script);
  313. $dir = str_replace("/includes","",$dir);
  314. $plugin = basename($dir);
  315. if(strpos($script,'admin')!==false || strpos($script,'includes')!==false) // Admin Language files.
  316. {
  317. $newLangs = array(
  318. 0 => $dir."/languages/English/English_admin_".$plugin.".php",
  319. 1 => $dir."/languages/English_admin_".$plugin.".php",
  320. 2 => $dir."/languages/English_admin.php",
  321. 3 => $dir."/languages/English/English_admin.php"
  322. );
  323. }
  324. else
  325. {
  326. $newLangs = array(
  327. 0 => $dir."/languages/English/English_".$plugin.".php",
  328. 1 => $dir."/languages/English_admin_".$plugin.".php",
  329. 2 => $dir."/languages/English_front.php",
  330. 3 => $dir."/languages/English/English_front.php",
  331. 4 => $dir."/languages/English_front.php",
  332. 5 => $dir."/languages/English/English_front.php"
  333. );
  334. }
  335. // if(strpos($data, 'e_admin_dispatcher')!==false)
  336. {
  337. foreach($newLangs as $path)
  338. {
  339. if(file_exists($path) && $reverse == false)
  340. {
  341. return $path;
  342. }
  343. }
  344. }
  345. preg_match_all("/.*(include_lan|require_once|include|include_once) ?\((.*e_LANGUAGE.*?\.php)/i",$data,$match);
  346. $srch = array(" ",'e_PLUGIN.', 'e_LANGUAGEDIR', '.e_LANGUAGE.', "'", '"', "'.");
  347. $repl = array("", e_PLUGIN, e_LANGUAGEDIR, "English", "", "", "");
  348. foreach($match[2] as $lanFile)
  349. {
  350. $arrt = str_replace($srch,$repl,$lanFile);
  351. // if(strpos($arrt,'admin'))
  352. {
  353. //return $arrt;
  354. $arr[] = $arrt;
  355. }
  356. }
  357. return implode(",",$arr);
  358. // return $arr[0];
  359. }
  360. if(vartrue($_POST['disabled-unused']) && vartrue($_POST['disable-unused-lanfile']))
  361. {
  362. $mes = e107::getMessage();
  363. $data = file_get_contents($_POST['disable-unused-lanfile']);
  364. $new = disableUnused($data);
  365. if(file_put_contents($_POST['disable-unused-lanfile'],$new))
  366. {
  367. $mes->addSuccess("Overwriting ".$_POST['disable-unused-lanfile']);
  368. }
  369. else
  370. {
  371. $mes->addError("Couldn't overwrite ".$_POST['disable-unused-lanfile']);
  372. }
  373. $ns->tablerender("Processed".SEP.$_POST['disable-unused-lanfile'],$mes->render()."<pre>".htmlentities($new)."</pre>");
  374. }
  375. function disableUnused($data)
  376. {
  377. $data = str_replace("2008-2010","2008-2013", $data);
  378. $data = str_replace(' * $URL$
  379. * $Revision$
  380. * $Id$
  381. * $Author$',"",$data); // TODO FIXME ?
  382. $tmp = explode("\n",$data);
  383. foreach($tmp as $line)
  384. {
  385. $ret = getDefined($line);
  386. $newline[] = (in_array($ret['define'],$_SESSION['language-tools-unused']) && substr($line,0,2) !='//') ? "// ".$line : $line;
  387. }
  388. return implode("\n",$newline);
  389. }
  390. if(varset($_POST['searchDeprecated']) && varset($_POST['deprecatedLans']))
  391. {
  392. $mes = e107::getMessage();
  393. // $lanfile = $_POST['deprecatedLans'];
  394. $script = $_POST['deprecatedLans'];
  395. if(strpos($script,e_ADMIN)!==false) // CORE
  396. {
  397. $mes->addDebug("Mode: Core Admin Calculated");
  398. //$scriptname = str_replace("lan_","",basename($lanfile));
  399. $lanfile = e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_".basename($script);
  400. }
  401. else // Plugin
  402. {
  403. $mes->addDebug("Mode: Search Plugins");
  404. $lanfile = findIncludedFiles($script,vartrue($_POST['deprecatedLansReverse']));
  405. }
  406. if(!is_readable($script))
  407. {
  408. $mes->addError("Not Readable: ".$script);
  409. // $script = $scriptname; // matching files. lan_xxxx.php and xxxx.php
  410. }
  411. $found = findIncludedFiles($script,vartrue($_POST['deprecatedLansReverse']));
  412. // print_a($found);
  413. // Exceptions - same language loaded by several scripts.
  414. if($lanfile == e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_e107_update.php")
  415. {
  416. $script = e_ADMIN."update_routines.php,".e_ADMIN."e107_update.php";
  417. }
  418. if(vartrue($_POST['deprecatedLanFile'])) //override.
  419. {
  420. $lanfile = $_POST['deprecatedLanFile'];
  421. }
  422. if($res = unused($lanfile, $script, vartrue($_POST['deprecatedLansReverse'])))
  423. {
  424. $ns -> tablerender($res['caption'],$mes->render(). $res['text']);
  425. }
  426. }
  427. //FIX - create or edit check
  428. if (isset($_POST['create_edit_existing']))
  429. $_POST['edit_existing'] = true;
  430. // Grab Language configuration. ---
  431. if (isset($_POST['edit_existing']))
  432. {
  433. //XXX - JS ok with the current functionality?
  434. $text .= "
  435. <form method='post' action='".e_SELF."?db'>
  436. <fieldset id='core-language-edit'>
  437. <legend class='e-hideme'>".$_POST['lang_choices']."</legend>
  438. <table class='table adminlist'>
  439. <colgroup>
  440. <col class='col-label' />
  441. <col class='col-control' />
  442. </colgroup>
  443. <tbody>
  444. ";
  445. foreach ($tabs as $table_name)
  446. {
  447. $installed = 'lan_'.strtolower($_POST['lang_choices'])."_".$table_name;
  448. if (stristr($_POST['lang_choices'], $installed) === FALSE)
  449. {
  450. $text .= "
  451. <tr>
  452. <td>".ucfirst(str_replace("_", " ", $table_name))."</td>
  453. <td>
  454. <div class='auto-toggle-area f-left e-pointer'>
  455. ";
  456. $selected = ($sql->db_Table_exists($table_name,$_POST['lang_choices'])) ? " checked='checked'" : "";
  457. $text .= "
  458. <input type='checkbox' class='checkbox' id='language-action-{$table_name}' name='{$table_name}' value='1'{$selected} onclick=\"if(document.getElementById('language-action-{$table_name}').checked){document.getElementById('language-datacopy-{$table_name}').style.display = '';}\" />
  459. </div>
  460. <div class='f-left'>
  461. <span id='language-datacopy-{$table_name}' class='e-hideme e-pointer'>
  462. <input type='checkbox' class='checkbox' name='copydata_{$table_name}' id='copydata-{$table_name}' value='1' />
  463. &nbsp;&nbsp;<label for='copydata-{$table_name}'>".LANG_LAN_15."</label>
  464. </span>
  465. </div>
  466. </td>
  467. </tr>
  468. ";
  469. }
  470. }
  471. // ===========================================================================
  472. // Drop tables ? isset()
  473. if (varset($_POST['create_edit_existing']))
  474. {
  475. $baction = 'create';
  476. $bcaption = LANG_LAN_06;
  477. }
  478. else
  479. {
  480. $baction = 'update';
  481. $bcaption = LAN_UPDATE;
  482. }
  483. $text .= "
  484. <tr>
  485. <td><strong>".LANG_LAN_07."</strong></td>
  486. <td>
  487. ".$frm->checkbox('drop', 1)."
  488. <div class='smalltext field-help'>".$frm->label(LANG_LAN_08, 'drop', 1)."</div>
  489. </td>
  490. </tr>
  491. <tr>
  492. <td><strong>".LAN_CONFDELETE."</strong></td>
  493. <td>
  494. ".$frm->checkbox('remove', 1)."
  495. <div class='smalltext field-help'>".$frm->label(LANG_LAN_11, 'remove', 1)."</div>
  496. </td>
  497. </tr>
  498. </tbody>
  499. </table>
  500. <div class='buttons-bar center'>
  501. <input type='hidden' name='language' value='{$_POST['lang_choices']}' />
  502. ".$frm->admin_button('create_tables','no-value',$baction,$bcaption)."
  503. </div>
  504. </fieldset>
  505. </form>
  506. ";
  507. $ns->tablerender($_POST['lang_choices'], $mes->render().$text);
  508. }
  509. require_once (e_ADMIN."footer.php");
  510. // ---------------------------------------------------------------------------
  511. function multilang_prefs()
  512. {
  513. if(!getperms('0'))
  514. {
  515. return;
  516. }
  517. global $lanlist;
  518. $pref = e107::getPref();
  519. $mes = e107::getMessage();
  520. $frm = e107::getForm();
  521. //XXX Remove later.
  522. // Enable only for developers - SetEnv E_ENVIRONMENT develop
  523. if(!isset($_SERVER['E_DEV_LANGUAGE']) || $_SERVER['E_DEV_LANGUAGE'] !== 'true')
  524. {
  525. $lanlist = array('English');
  526. $mes->addInfo("Alpha version currently supports only the English language. After most features are stable and English terms are optimized - translation will be possible.");
  527. }
  528. $text = "
  529. <form method='post' action='".e_SELF."' id='linkform'>
  530. <fieldset id='core-language-settings'>
  531. <legend class='e-hideme'>".LANG_LAN_13."</legend>
  532. <table class='table adminform'>
  533. <colgroup>
  534. <col class='col-label' />
  535. <col class='col-control' />
  536. </colgroup>
  537. <tbody>
  538. <tr>
  539. <td>".LANG_LAN_14.": </td>
  540. <td>";
  541. $sellan = preg_replace("/lan_*.php/i", "", $pref['sitelanguage']);
  542. $text .= $frm->select('mainsitelanguage',$lanlist,$sellan,"useValues=1");
  543. $text .= "
  544. </td>
  545. </tr>";
  546. if(isset($_SERVER['E_DEV_LANGUAGE']) && $_SERVER['E_DEV_LANGUAGE'] === 'true')
  547. {
  548. $text .= "
  549. <tr>
  550. <td>".LANG_LAN_50.": </td>
  551. <td>";
  552. $sellan = preg_replace("/lan_*.php/i", "", $pref['adminlanguage']);
  553. $text .= $frm->select('mainadminlanguage',$lanlist,$sellan,array("useValues"=>1,"default" => LANG_LAN_14));
  554. $text .= "
  555. </td>
  556. </tr>";
  557. }
  558. $text .= "
  559. <tr>
  560. <td>".LANG_LAN_12.": </td>
  561. <td>
  562. <div class='auto-toggle-area autocheck'>";
  563. $checked = ($pref['multilanguage'] == 1) ? " checked='checked'" : "";
  564. $text .= "
  565. <input class='checkbox' type='checkbox' name='multilanguage' value='1'{$checked} />
  566. </div>
  567. </td>
  568. </tr>
  569. <tr>
  570. <td>".LANG_LAN_26.":</td>
  571. <td>
  572. <div class='auto-toggle-area autocheck'>\n";
  573. $checked = ($pref['noLanguageSubs'] == 1) ? " checked='checked'" : "";
  574. $text .= "
  575. <input class='checkbox' type='checkbox' name='noLanguageSubs' value='1'{$checked} />
  576. <div class='smalltext field-help'>".LANG_LAN_27."</div>
  577. </div>
  578. </td>
  579. </tr>
  580. <tr>
  581. <td>
  582. ".LANG_LAN_18."
  583. <small>".LANG_LAN_19."</small>
  584. </td>
  585. <td>
  586. <textarea name='multilanguage_subdomain' rows='5' cols='15'>{$pref['multilanguage_subdomain']}</textarea>
  587. <div class='smalltext field-help'>".LANG_LAN_20."</div>
  588. </td>
  589. </tr>";
  590. $opt = "";
  591. $langs = explode(",",e_LANLIST);
  592. foreach($langs as $val)
  593. {
  594. if($val != $pref['sitelanguage'])
  595. {
  596. $opt .= "<tr><td class='middle' style='width:5%'>".$val."</td><td class='left inline-text'><input type='text' name='multilanguage_domain[".$val."]' value=\"".$pref['multilanguage_domain'][$val]."\" /></td></tr>";
  597. }
  598. }
  599. if($opt)
  600. {
  601. //TODO LANs and class2.php check.
  602. $text .= "
  603. <tr>
  604. <td>
  605. Language by Domain Name
  606. <div class='label-note'>Domain determines the site's language. Enter domain without the 'www.'</div>
  607. </td>
  608. <td><table style='margin-left:0px;width:400px'>".$opt."</table></td>
  609. </tr>";
  610. }
  611. $text .= "
  612. </tbody>
  613. </table>
  614. <div class='buttons-bar center'>".
  615. $frm->admin_button('submit_prefs','no-value','update',LAN_SAVE)."
  616. </div>
  617. </fieldset>
  618. </form>\n";
  619. e107::getRender()->tablerender(ADLAN_132.SEP.LAN_PREFS, $mes->render().$text); // "Language Preferences";
  620. }
  621. // ----------------------------------------------------------------------------
  622. function table_list()
  623. {
  624. // grab default language lists.
  625. $exclude = array();
  626. $exclude[] = "banlist";
  627. $exclude[] = "banner";
  628. $exclude[] = "cache";
  629. $exclude[] = "core";
  630. $exclude[] = "online";
  631. $exclude[] = "parser";
  632. $exclude[] = "plugin";
  633. $exclude[] = "user";
  634. $exclude[] = "upload";
  635. $exclude[] = "userclass_classes";
  636. $exclude[] = "rbinary";
  637. $exclude[] = "session";
  638. $exclude[] = "tmp";
  639. $exclude[] = "flood";
  640. $exclude[] = "stat_info";
  641. $exclude[] = "stat_last";
  642. $exclude[] = "submit_news";
  643. $exclude[] = "rate";
  644. $exclude[] = "stat_counter";
  645. $exclude[] = "user_extended";
  646. $exclude[] = "user_extended_struct";
  647. $exclude[] = "pm_messages";
  648. $exclude[] = "pm_blocks";
  649. $tables = e107::getDb()->db_TableList('nolan'); // db table list without language tables.
  650. return array_diff($tables,$exclude);
  651. }
  652. // ------------- render form ---------------------------------------------------
  653. function multilang_db()
  654. {
  655. if(!getperms('0'))
  656. {
  657. return "Access Denied";
  658. }
  659. global $lanlist, $tabs;
  660. $sql = e107::getDb();
  661. $frm = e107::getForm();
  662. $tp = e107::getParser();
  663. $mes = e107::getMessage();
  664. $pref = e107::getPref();
  665. if (isset($pref['multilanguage']) && $pref['multilanguage'])
  666. {
  667. // Choose Language to Edit:
  668. $text = "
  669. <fieldset id='core-language-list'>
  670. <legend class='e-hideme'>".LANG_LAN_16."</legend>
  671. <table class='table adminlist'>
  672. <colgroup>
  673. <col style='width:20%' />
  674. <col style='width:60%' />
  675. <col style='width:20%' />
  676. </colgroup>
  677. <thead>
  678. <tr>
  679. <th>".ADLAN_132."</th>
  680. <th>".LANG_LAN_03."</th>
  681. <th class='last'>".LAN_OPTIONS."</th>
  682. </tr>
  683. </thead>
  684. <tbody>
  685. ";
  686. sort($lanlist);
  687. foreach ($lanlist as $e_language)
  688. {
  689. $installed = array();
  690. if(strtolower($e_language) == $pref['sitelanguage'])
  691. {
  692. $e_language = "";
  693. }
  694. $text .= "<tr><td>{$e_language}</td><td>";
  695. foreach ($tabs as $tab_name)
  696. {
  697. if ($e_language != $pref['sitelanguage'] && $sql->db_Table_exists($tab_name,$e_language))
  698. {
  699. $installed[] = $tab_name;
  700. }
  701. }
  702. $text .= implode(", ",$installed);
  703. if ($e_language == $pref['sitelanguage'])
  704. {
  705. $text .= "<span>".LANG_LAN_17."</span>";
  706. }
  707. else
  708. {
  709. $text .= (!count($installed)) ? "<span>".LANG_LAN_05."</span>" : "";
  710. }
  711. $text .= "</td>\n";
  712. $text .= "<td>
  713. <form id='core-language-form-".str_replace(" ", "-", $e_language)."' action='".e_SELF."?modify' method='post'>\n";
  714. $text .= "
  715. <div>
  716. ";
  717. if (count($installed))
  718. {
  719. $text .= "<button class='btn btn-primary edit' type='submit' name='edit_existing' value='no-value'><span>".LAN_EDIT."</span></button>
  720. <button class='btn btn-danger delete' type='submit' name='del_existing' value='no-value' title='".$tp->lanVars(LANG_LAN_105, $e_language).' '.LAN_JSCONFIRM."'><span>".LAN_DELETE."</span></button>";
  721. }
  722. elseif ($e_language != $pref['sitelanguage'])
  723. {
  724. // $text .= "<button class='create' type='submit' name='create_edit_existing' value='no-value'><span>".LAN_CREATE."</span></button>";
  725. $text .= $frm->admin_button('create_edit_existing','no-value','create',LAN_CREATE);
  726. }
  727. $text .= "<input type='hidden' name='lang_choices' value='".$e_language."' />
  728. </div>
  729. </form>
  730. </td>
  731. </tr>
  732. ";
  733. }
  734. $text .= "
  735. </tbody>
  736. </table>
  737. </fieldset>
  738. ";
  739. e107::getRender()->tablerender(ADLAN_132.SEP.LANG_LAN_16, $mes->render().$text); // Languages -> Tables
  740. }
  741. }
  742. // ----------------------------------------------------------------------------
  743. function getLanList()
  744. {
  745. global $ln;
  746. $lst = explode(",",e_LANLIST);
  747. $list = array();
  748. foreach($lst as $lang)
  749. {
  750. if($ln->isValid($lang))
  751. {
  752. $list[] = $lang;
  753. }
  754. }
  755. sort($list);
  756. return $list;
  757. }
  758. /**
  759. * List the installed language packs.
  760. * @return
  761. */
  762. function show_packs()
  763. {
  764. $frm = e107::getForm();
  765. $ns = e107::getRender();
  766. $tp = e107::getParser();
  767. if(is_readable(e_ADMIN."ver.php"))
  768. {
  769. include(e_ADMIN."ver.php");
  770. list($ver, $tmp) = explode(" ", $e107info['e107_version']);
  771. }
  772. $lans = getLanList();
  773. $release_diz = defined("LANG_LAN_30") ? LANG_LAN_30 : "Release Date";
  774. $compat_diz = defined("LANG_LAN_31") ? LANG_LAN_31 : "Compatibility";
  775. $lan_pleasewait = (defsettrue('LAN_PLEASEWAIT')) ? $tp->toJS(LAN_PLEASEWAIT) : "Please Wait";
  776. $lan_displayerrors = (defsettrue('LANG_LAN_33')) ? LANG_LAN_33 : "Display only errors during verification";
  777. $text = "<form id='lancheck' method='post' action='".e_SELF."?tools'>
  778. <table class='table table-striped'>";
  779. $text .= "<thead>
  780. <tr>
  781. <th>".ADLAN_132."</th>
  782. <th>".$release_diz."</th>
  783. <th>".$compat_diz."</th>
  784. <th>".LAN_STATUS."</td>
  785. <th style='width:25%;white-space:nowrap'>".LAN_OPTIONS."</td>
  786. </tr>
  787. </thead>
  788. ";
  789. require_once(e_HANDLER."xml_class.php");
  790. $xm = new XMLParse();
  791. foreach($lans as $language)
  792. {
  793. if($language == "English")
  794. {
  795. continue;
  796. }
  797. $metaFile = e_LANGUAGEDIR.$language."/".$language.".xml";
  798. if(is_readable($metaFile))
  799. {
  800. $rawData = file_get_contents($metaFile);
  801. if($rawData)
  802. {
  803. $array = $xm->parse($rawData);
  804. $value = $array['e107Language']['attributes'];
  805. }
  806. else
  807. {
  808. $value = array(
  809. 'date' => "&nbsp;",
  810. 'compatibility' => '&nbsp;'
  811. );
  812. }
  813. }
  814. else
  815. {
  816. $value = array(
  817. 'date' => "&nbsp;",
  818. 'compatibility' => '&nbsp;'
  819. );
  820. }
  821. $errFound = (isset($_SESSION['lancheck'][$language]['total']) && $_SESSION['lancheck'][$language]['total'] > 0) ? TRUE : FALSE;
  822. $text .= "<tr>
  823. <td >".$language."</td>
  824. <td>".$value['date']."</td>
  825. <td>".$value['compatibility']."</td>
  826. <td>".($ver != $value['compatibility'] || $errFound ? ADMIN_FALSE_ICON : ADMIN_TRUE_ICON )."</td>
  827. <td><input type='submit' name='language_sel[{$language}]' value=\"".LAN_CHECK_2."\" class='btn btn-primary' />
  828. <input type='submit' name='ziplang[{$language}]' value=\"".LANG_LAN_23."\" class='button' onclick=\"this.value = '".$lan_pleasewait."'\" /></td>
  829. </tr>";
  830. }
  831. $text .= "
  832. </tr></table>";
  833. $text .= "<table class='table table-striped'>";
  834. $text .= "<thead><tr><th>".LAN_OPTIONS."</th></tr></thead><tbody>";
  835. $srch = array("[","]");
  836. $repl = array("<a rel='external' href='http://e107.org/content/About-Us:The-Team#translation-team'>","</a>");
  837. $diz = (defsettrue("LANG_LAN_28")) ? LANG_LAN_28 : "Check this box if you're an [e107 certified translator].";
  838. $checked = varset($_COOKIE['e107_certified']) == 1 ? true : false;
  839. $text .= "<tr><td>";
  840. $text .= $frm->checkbox('contribute_pack',1,$checked,array('label'=>str_replace($srch,$repl,$diz)));
  841. ;
  842. $text .= "</td>
  843. </tr>
  844. <tr>
  845. <td>";
  846. $echecked = varset($_SESSION['lancheck-errors-only']) == 1 ? true : false;
  847. $text .= $frm->checkbox('errorsonly',1,$echecked,array('label'=>$lan_displayerrors));
  848. $text .= " </td>
  849. </tr>";
  850. // $text .= "
  851. // <tr>
  852. // <td>".$frm->checkbox('non-core-plugs-themes',1,$echecked,array('label'=>$lan_displayerrors))."</td>
  853. // </tr>
  854. // ";
  855. $text .= "</tbody></table>";
  856. $text .= "</form>";
  857. $text .= "<div class='smalltext center' style='padding-top:50px'>".LANG_LAN_AGR."</div>";
  858. $ns->tablerender(ADLAN_132.SEP.LANG_LAN_32, $text);
  859. return;
  860. }
  861. function show_tools()
  862. {
  863. $frm = e107::getForm();
  864. $mes = e107::getMessage();
  865. include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_lancheck.php");
  866. show_packs();
  867. if(vartrue($_SERVER['E_DEV']))
  868. {
  869. return;
  870. }
  871. /*
  872. $text = "
  873. <form id='core-language-lancheck-form' method='post' action='".e_SELF."?tools'>
  874. <fieldset id='core-language-lancheck'>
  875. <legend class='e-hideme'>".LAN_CHECK_1."</legend>
  876. <table class='table adminform'>
  877. <colgroup>
  878. <col class='col-label' />
  879. <col class='col-control' />
  880. </colgroup>
  881. <tbody>
  882. <tr>
  883. <td>".LAN_CHECK_1."</td>
  884. <td class='form-inline'>
  885. <select name='language'>
  886. <option value=''>".LAN_SELECT."</option>";
  887. $languages = explode(",", e_LANLIST);
  888. sort($languages);
  889. foreach ($languages as $lang)
  890. {
  891. if ($lang != "English")
  892. {
  893. $text .= "
  894. <option value='{$lang}' >{$lang}</option>
  895. ";
  896. }
  897. }
  898. $text .= "</select>".
  899. $frm->admin_button('language_sel','no-value','other',LAN_CHECK_2)."
  900. </td>
  901. </tr>
  902. </tbody>
  903. </table>
  904. </fieldset>
  905. </form>";
  906. */
  907. $text = "";
  908. $text .= "
  909. <form id='ziplang' method='post' action='".e_SELF."?tools'>
  910. <fieldset id='core-language-package'>
  911. <legend class='e-hideme'>".LANG_LAN_23."</legend>
  912. <table class='table adminform'>
  913. <colgroup>
  914. <col class='col-label' />
  915. <col class='col-control' />
  916. </colgroup>
  917. <tbody>";
  918. /*
  919. $text .= "
  920. <tr>
  921. <td>".LANG_LAN_23."</td>
  922. <td class='form-inline'>
  923. <select name='language'>
  924. <option value=''>".LAN_SELECT."</option>";
  925. $languages = explode(",", e_LANLIST);
  926. sort($languages);
  927. foreach ($languages as $lang)
  928. {
  929. if ($lang != "English")
  930. {
  931. $text .= "
  932. <option value='{$lang}' >{$lang}</option>
  933. ";
  934. }
  935. }
  936. $text .= "
  937. </select>
  938. ".$frm->admin_button('ziplang','no-value','other',LANG_LAN_24)."
  939. <input type='checkbox' name='contribute_pack' value='1' /> Check to share your language-pack with the e107 community.
  940. </td>
  941. </tr>";
  942. */
  943. $fl = e107::getFile();
  944. $fl->mode = 'full';
  945. if(!$_SESSION['languageTools_lanFileList'])
  946. {
  947. $_SESSION['languageTools_lanFileList'] = $fl->get_files(e_BASE,'.*?(English|lan_).*?\.php$','standard',5);
  948. }
  949. $text .= "
  950. <tr>
  951. <td>Search for Deprecated Lans</td>
  952. <td class='form-inline'>
  953. <select name='deprecatedLans'>
  954. <option value=''>Select Script...</option>";
  955. $omit = array('languages','\.png','\.gif','handlers');
  956. $lans = $fl->get_files(e_ADMIN,'.php','standard',0);
  957. $fl->setFileFilter(array("^e_"));
  958. $plugs = $fl->get_files(e_PLUGIN,'.*?/?.*?\.php',$omit,2);
  959. $exclude = array('lan_admin.php');
  960. $srch = array(e_ADMIN,e_PLUGIN);
  961. $text .= "<optgroup label='Admin Area'>";
  962. foreach($lans as $script=>$lan)
  963. {
  964. if(in_array(basename($lan),$exclude))
  965. {
  966. continue;
  967. }
  968. $selected = ($lan == varset($_POST['deprecatedLans'])) ? "selected='selected'" : "";
  969. $text .= "<option value='".$lan."' {$selected}>".str_replace($srch,"",$lan)."</option>\n";
  970. }
  971. $text .= "</optgroup>";
  972. $text .= "<optgroup label='Plugins'>";
  973. foreach($plugs as $script=>$lan)
  974. {
  975. if(in_array(basename($lan),$exclude))
  976. {
  977. continue;
  978. }
  979. $selected = ($lan == varset($_POST['deprecatedLans'])) ? "selected='selected'" : "";
  980. $text .= "<option value='".$lan."' {$selected}>".str_replace($srch,"",$lan)."</option>\n";
  981. }
  982. $text .= "</optgroup>";
  983. $depOptions = array(
  984. 1 => "Script > Lan File",
  985. 0 => "Script < Lan File"
  986. );
  987. $text .= "
  988. </select> ".
  989. $frm->select('deprecatedLansReverse',$depOptions,$_POST['deprecatedLansReverse'],'class=select')." ";
  990. $search = array(e_PLUGIN,e_ADMIN,e_LANGUAGEDIR,e_THEME);
  991. $replace = array("Plugins ","Admin ","Core ","Themes ");
  992. $prev = 'Core';
  993. $text .= "<select name='deprecatedLanFile'>
  994. <option value=''>Auto-Detect</option>
  995. <optgroup label='CORE'>\n";
  996. foreach($_SESSION['languageTools_lanFileList'] as $val)
  997. {
  998. if(strstr($val,e_SYSTEM))
  999. {
  1000. continue;
  1001. }
  1002. $selected = ($val === $_POST['deprecatedLanFile']) ? "selected='selected'" : "";
  1003. $diz = str_replace($search,$replace,$val);
  1004. list($type,$label) = explode(" ",$diz);
  1005. if($type !== $prev)
  1006. {
  1007. $text .= "</optgroup><optgroup label='".$type."'>\n";
  1008. }
  1009. $text .= "<option value='".$val."' ".$selected.">".$label."</option>\n";
  1010. $prev = $type;
  1011. }
  1012. $text .= "</optgroup></select>";
  1013. // $frm->select('deprecatedLanFile',$_SESSION['languageTools_lanFileList'], $_POST['deprecatedLanFile'],'class=select&useValues=1','Select Language File (optional)').
  1014. $text .= $frm->admin_button('searchDeprecated',"Check",'other');
  1015. // $text .= "<span class='field-help'>".(count($lans) + count($plugs))." files found</span>";
  1016. $text .= "
  1017. </td>
  1018. </tr>";
  1019. $text .= "
  1020. </tbody>
  1021. </table>
  1022. </fieldset>
  1023. </form>
  1024. ";
  1025. e107::getRender()->tablerender(ADLAN_132.SEP.LANG_LAN_21, $mes->render().$text);
  1026. }
  1027. // ----------------------------------------------------------------------------
  1028. function available_langpacks()
  1029. {
  1030. $xml = e107::getXml();
  1031. $feed = e107::getPref('xmlfeed_languagepacks');
  1032. if($rawData = $xml -> loadXMLfile($feed, TRUE))
  1033. {
  1034. if(!varset($rawData['language']))
  1035. {
  1036. return FALSE;
  1037. }
  1038. $text .= "<div class='block-text'>".LANG_LAN_35."</div>";
  1039. $text .= "<table class='table adminlist'>";
  1040. foreach($rawData['language'] as $val)
  1041. {
  1042. $att = $val['@attributes'];
  1043. $name = $att['folder'];
  1044. $languages[$name] = array(
  1045. 'name' => $att['name'],
  1046. 'author' => $att['author'],
  1047. 'authorURL' => $att['authorURL'],
  1048. 'folder' => $att['folder'],
  1049. 'version' => $att['version'],
  1050. 'date' => $att['date'],
  1051. 'compatibility' => $att['compatibility'],
  1052. 'url' => $att['url']
  1053. );
  1054. }
  1055. ksort($languages);
  1056. //TODO LANs
  1057. $text .= "<thead>
  1058. <tr>
  1059. <th>Name</th>
  1060. <th>Version</th>
  1061. <th>Author</th>
  1062. <th>Release-date</th>
  1063. <th>Compatible</th>
  1064. <th>Download</th>
  1065. </tr>
  1066. </thead>
  1067. <tbody>";
  1068. foreach($languages as $value)
  1069. {
  1070. $text .= "<tr>
  1071. <td>".$value['name']."</td>
  1072. <td>".$value['version']."</td>
  1073. <td><a href='".$value['authorURL']."'>".$value['author']."</a></td>
  1074. <td>".$value['date']."</td>
  1075. <td>".$value['compatibility']."</td>
  1076. <td><a href='".$value['url']."'>Download Pack</a></td>
  1077. </tr>";
  1078. }
  1079. $text .= "</tbody></table>";
  1080. return $text;
  1081. }
  1082. }
  1083. function language_adminmenu()
  1084. {
  1085. $pref = e107::getPref();
  1086. $action = e_QUERY;
  1087. if ($action == "")
  1088. {
  1089. $action = getperms('0') ? "main" : "tools";
  1090. }
  1091. if ($action == "modify")
  1092. {
  1093. $action = "db";
  1094. }
  1095. if(getperms('0'))
  1096. {
  1097. $var['main']['text'] = LAN_PREFS;
  1098. $var['main']['link'] = e_SELF;
  1099. if (isset($pref['multilanguage']) && $pref['multilanguage'])
  1100. {
  1101. $var['db']['text'] = LANG_LAN_03;
  1102. $var['db']['link'] = e_SELF."?db";
  1103. }
  1104. }
  1105. // $lcnt = explode(",", e_LANLIST);
  1106. // if (count($lcnt) > 1)
  1107. // {
  1108. $var['tools']['text'] = LANG_LAN_21;
  1109. $var['tools']['link'] = e_SELF."?tools";
  1110. // }
  1111. e107::getNav()->admin(ADLAN_132, $action, $var);
  1112. }
  1113. // Zip up the language pack.
  1114. // ===================================================
  1115. function zip_up_lang($language)
  1116. {
  1117. global $tp;
  1118. $ret = array();
  1119. $ret['file'] = "";
  1120. if($_SESSION['lancheck'][$language]['total'] > 0 && !E107_DEBUG_LEVEL)
  1121. {
  1122. $ret = array();
  1123. $ret['error'] = TRUE;
  1124. $message = (defined('LANG_LAN_34')) ? LANG_LAN_34 : "Please verify and correct the remaining [x] error(s) before attempting to create a language-pack.";
  1125. $ret['message'] = str_replace("[x]",$_SESSION['lancheck'][$language]['total'],$message);
  1126. return $ret;
  1127. }
  1128. if(!isset($_SESSION['lancheck'][$language]))
  1129. {
  1130. $ret = array();
  1131. $ret['error'] = TRUE;
  1132. $ret['message'] = (defined('LANG_LAN_27')) ? LANG_LAN_27 : "Please verify your language files ('Verify') then try again.";
  1133. return $ret;
  1134. }
  1135. if(varset($_POST['contribute_pack']) && varset($_SESSION['lancheck'][$language]['total']) !='0')
  1136. {
  1137. $ret['error'] = TRUE;
  1138. $ret['message'] = (defined("LANG_LAN_29")) ? LANG_LAN_29 : "You should correct the remaining errors before contributing your language pack.";
  1139. $ret['message'] .= "<br />";
  1140. $ret['message'] .= (defined('LANG_LAN_27')) ? LANG_LAN_27 : "Please verify your language files ('Verify') then try again.";
  1141. return $ret;
  1142. }
  1143. if(!is_writable(e_FILE."public"))
  1144. {
  1145. $ret['error'] = TRUE;
  1146. $ret['message'] = LAN_UPLOAD_777 . " ".e_FILE."public";
  1147. return $ret;
  1148. }
  1149. if(is_readable(e_ADMIN."ver.php"))
  1150. {
  1151. include(e_ADMIN."ver.php");
  1152. }
  1153. $core_plugins = array(
  1154. "alt_auth","banner","blogcalendar_menu","calendar_menu","chatbox_menu",
  1155. "clock_menu","comment_menu","download","faqs", "featurebox", "forum","gallery", "gsitemap","import", "links_page",
  1156. "linkwords","list_new","log","login_menu","newforumposts_main","newsfeed",
  1157. "news", "newsletter","online", "page",
  1158. "pm","poll","rss_menu","search_menu","siteinfo","tagwords", "tinymce",
  1159. "trackback","tree_menu","user_menu"
  1160. );
  1161. $core_themes = array("bootstrap");
  1162. require_once(e_HANDLER.'pclzip.lib.php');
  1163. list($ver, $tmp) = explode(" ", $e107info['e107_version']);
  1164. if(!$locale = find_locale($language))
  1165. {
  1166. $ret['error'] = TRUE;
  1167. $file = "e107_languages/{$language}/{$language}.php";
  1168. $def = (defined('LANG_LAN_25')) ? LANG_LAN_25 : "Please check that CORE_LC and CORE_LC2 have values in [lcpath] and try again.";
  1169. $ret['message'] = str_replace("[lcpath]",$file,$def); //
  1170. return $ret;
  1171. }
  1172. global $THEMES_DIRECTORY, $PLUGINS_DIRECTORY, $LANGUAGES_DIRECTORY, $HANDLERS_DIRECTORY, $HELP_DIRECTORY;
  1173. if(($HANDLERS_DIRECTORY != "e107_handlers/") || ( $LANGUAGES_DIRECTORY != "e107_languages/") || ($THEMES_DIRECTORY != "e107_themes/") || ($HELP_DIRECTORY != "e107_docs/help/") || ($PLUGINS_DIRECTORY != "e107_plugins/"))
  1174. {
  1175. $ret['error'] = TRUE;
  1176. $ret['message'] = (defined('LANG_LAN_26')) ? LANG_LAN_26 : "Please make sure you are using default folder names in e107_config.php (eg. e107_languages/, e107_plugins/ etc.) and try again.";
  1177. return $ret;
  1178. }
  1179. $newfile = e_MEDIA_FILE."e107_".$ver."_".$language."_".$locale."-utf8.zip";
  1180. $archive = new PclZip($newfile);
  1181. $core = grab_lans(e_LANGUAGEDIR.$language."/", $language,'',0);
  1182. $core_admin = grab_lans(e_BASE.$LANGUAGES_DIRECTORY.$language."/admin/", $language,'',2);
  1183. $plugs = grab_lans(e_BASE.$PLUGINS_DIRECTORY, $language, $core_plugins); // standardized path.
  1184. $theme = grab_lans(e_BASE.$THEMES_DIRECTORY, $language, $core_themes);
  1185. $docs = grab_lans(e_BASE.$HELP_DIRECTORY,$language);
  1186. $handlers = grab_lans(e_BASE.$HANDLERS_DIRECTORY,$language); // standardized path.
  1187. $file = array_merge($core,$core_admin, $plugs, $theme, $docs, $handlers);
  1188. $data = implode(",", $file);
  1189. if ($archive->create($data,PCLZIP_OPT_REMOVE_PATH,e_BASE) == 0)
  1190. {
  1191. $ret['error'] = TRUE;
  1192. $ret['message'] = $archive->errorInfo(true);
  1193. return $ret;
  1194. }
  1195. else
  1196. {
  1197. $fileName = e_FILE."public/".$language.".xml";
  1198. if(is_readable($fileName))
  1199. {
  1200. @unlink($fileName);
  1201. }
  1202. $fileData = '<?xml version="1.0" encoding="utf-8"?>
  1203. <e107Language name="'.$language.'" compatibility="'.$ver.'" date="'.date("Y-m-d").'" >
  1204. <author name ="'.USERNAME.'" email="'.USEREMAIL.'" url="'.SITEURL.'" />
  1205. </e107Language>';
  1206. if(file_put_contents($fileName,$fileData))
  1207. {
  1208. $addTag = $archive->add($fileName, PCLZIP_OPT_ADD_PATH, 'e107_languages/'.$language, PCLZIP_OPT_REMOVE_PATH, e_FILE.'public/');
  1209. $_SESSION['lancheck'][$language]['xml'] = "Yes";
  1210. }
  1211. else
  1212. {
  1213. $_SESSION['lancheck'][$language]['xml'] = "No";
  1214. }
  1215. @unlink($fileName);
  1216. $ret['file'] = $newfile;
  1217. $ret['message'] = str_replace("../", "", e_MEDIA_FILE)."<a href='".$newfile."' >".basename($newfile)."</a>";
  1218. $ret['error'] = FALSE;
  1219. return $ret;
  1220. }
  1221. }
  1222. /*
  1223. function zip_up_lang($language)
  1224. {
  1225. if (is_readable(e_ADMIN."ver.php"))
  1226. {
  1227. include (e_ADMIN."ver.php");
  1228. }
  1229. $tp = e107::getParser();
  1230. require_once (e_HANDLER.'pclzip.lib.php');
  1231. list($ver, $tmp) = explode(" ", $e107info['e107_version']);
  1232. $newfile = e_UPLOAD."e107_".$ver."_".$language."_utf8.zip";
  1233. $archive = new PclZip($newfile);
  1234. $core = grab_lans(e_LANGUAGEDIR.$language."/", $language);
  1235. $plugs = grab_lans(e_PLUGIN, $language);
  1236. $theme = grab_lans(e_THEME, $language);
  1237. $file = array_merge($core, $plugs, $theme);
  1238. $data = implode(",", $file);
  1239. if ($archive->create($data) == 0)
  1240. {
  1241. return $archive->errorInfo(true);
  1242. }
  1243. else
  1244. {
  1245. if($_POST['contribute_pack'])
  1246. {
  1247. $full_link = $tp->createConstants($newfile);
  1248. $email_message = "Site: ".SITENAME."
  1249. User: ".USERNAME."\n
  1250. IP:".USERIP."
  1251. ...would like to contribute the following language pack for e107 v".$e107info['e107_version'].".
  1252. Please see attachment.";
  1253. $subject = basename($newfile);
  1254. //TODO - send email to languagepack@e107.org with attachment.
  1255. }
  1256. return LANG_LAN_22." (".str_replace("../", "", e_UPLOAD)."<a href='".$newfile."' >".basename($newfile)."</a>).";
  1257. }
  1258. }
  1259. */
  1260. function grab_lans($path, $language, $filter = "")
  1261. {
  1262. $fl = e107::getFile();
  1263. if ($lanlist = $fl->get_files($path, "", "standard", 4))
  1264. {
  1265. sort($lanlist);
  1266. }
  1267. else
  1268. {
  1269. return;
  1270. }
  1271. $pzip = array();
  1272. foreach ($lanlist as $p)
  1273. {
  1274. $fullpath = $p['path'].$p['fname'];
  1275. if (strpos($fullpath, $language) !== FALSE)
  1276. {
  1277. $pzip[] = $fullpath;
  1278. }
  1279. }
  1280. return $pzip;
  1281. }
  1282. // -----------------------
  1283. /**
  1284. * Compare Language File against script and find unused LANs
  1285. * @param object $lanfile
  1286. * @param object $script
  1287. * @return string|boolean FALSE on error
  1288. */
  1289. function unused($lanfile,$script,$reverse=false)
  1290. {
  1291. $mes = e107::getMessage();
  1292. $frm = e107::getForm();
  1293. unset($_SESSION['language-tools-unused']);
  1294. // $mes->addInfo("LAN=".$lanfile."<br />Script = ".$script);
  1295. if($reverse == true)
  1296. {
  1297. $exclude = array("e_LANGUAGE","e_LANGUAGEDIR","e_LAN","e_LANLIST","e_LANCODE");
  1298. $data = file_get_contents($script);
  1299. if(preg_match_all("/([\w_]*LAN[\w_]*)/", $data, $match))
  1300. {
  1301. // print_a($match);
  1302. $foundLans = array();
  1303. foreach($match[1] as $val)
  1304. {
  1305. if(!in_array($val, $exclude))
  1306. {
  1307. $foundLans[] = $val;
  1308. }
  1309. }
  1310. sort($foundLans);
  1311. $foundLans = array_unique($foundLans);
  1312. $lanDefines = implode("\n",$foundLans);
  1313. }
  1314. $mes->addDebug("Script: ".$script);
  1315. $tmp = explode(",", $lanfile);
  1316. foreach($tmp as $scr)
  1317. {
  1318. if(!file_exists($scr))
  1319. {
  1320. $mes->addError("Couldn't Load: ".$scr);
  1321. continue;
  1322. }
  1323. $compare[$scr] = file_get_contents($scr);
  1324. $mes->addDebug("LanFile: ".$scr);
  1325. }
  1326. $lanfile = $script;
  1327. }
  1328. else
  1329. {
  1330. $lanDefines = file_get_contents($lanfile);
  1331. $mes->addDebug("LanFile: ".$lanfile);
  1332. $tmp = explode(",",$script);
  1333. foreach($tmp as $scr)
  1334. {
  1335. if(!file_exists($scr))
  1336. {
  1337. $mes->addError("Couldn't Load: ".$scr);
  1338. continue;
  1339. }
  1340. $compare[$scr] = file_get_contents($scr);
  1341. $mes->addDebug("Script: ".$scr);
  1342. }
  1343. }
  1344. if(!$compare)
  1345. {
  1346. $mes->addError("Couldn't read ".$script);
  1347. }
  1348. if(!$lanDefines)
  1349. {
  1350. $mes->addError("Couldn't read ".$lanfile);
  1351. }
  1352. $srch = array("<?php","<?","?>");
  1353. $lanDefines = str_replace($srch,"",$lanDefines);
  1354. $lanDefines = explode("\n", $lanDefines);
  1355. if($lanDefines)
  1356. {
  1357. $text = $frm->open('language-unused');
  1358. $text .= "<table class='table adminlist'>
  1359. <colgroup>
  1360. <col style='width:40%' />
  1361. <col style='auto' />
  1362. </colgroup>
  1363. <thead>
  1364. <tr>
  1365. <th>".$lanfile."</th>";
  1366. foreach($compare as $k=>$val)
  1367. {
  1368. $text .= "<th>".$k."</th>";
  1369. }
  1370. if($reverse == true)
  1371. {
  1372. $text .= "<th>Definition</th>";
  1373. }
  1374. $text .= "
  1375. </tr>
  1376. </thead>
  1377. <tbody>";
  1378. // for ($i=0; $i<count($lanDefines); $i++)
  1379. // {
  1380. foreach($lanDefines as $line)
  1381. {
  1382. if(trim($line) !="")
  1383. {
  1384. $disabled = (preg_match("#^//#i",$line)) ? " (disabled)" : FALSE;
  1385. if($match = getDefined($line,$reverse))
  1386. {
  1387. $text .= compareit($match['define'],$compare,$match['value'],$disabled,$reverse);
  1388. }
  1389. }
  1390. }
  1391. $text .= "</tbody></table>";
  1392. if(count($_SESSION['language-tools-unused'])>0 && $reverse == false)
  1393. {
  1394. $text .= "<div class='buttons-bar center'>".$frm->admin_button('disabled-unused','Disable All Unused','delete').
  1395. $frm->hidden('disable-unused-lanfile',$lanfile).
  1396. $frm->hidden('deprecatedLans',$script).
  1397. "</div>";
  1398. }
  1399. $text .= $frm->close();
  1400. if($reverse != true)
  1401. {
  1402. $mes->addInfo("<b>Pink items are likely to be unused LANs.<br />Comment out and test thoroughly.</b>");
  1403. }
  1404. $ret['text'] = $mes->render().$text;
  1405. $ret['caption'] = "Deprecated LAN Check (experimental!)";
  1406. return $ret;
  1407. }
  1408. else
  1409. {
  1410. return FALSE;
  1411. }
  1412. }
  1413. function getDefined($line,$script=false)
  1414. {
  1415. if($script == true)
  1416. {
  1417. return array('define'=>$line,'value'=>'unknown');
  1418. }
  1419. if(preg_match("#\"(.*?)\".*?\"(.*)\"#",$line,$match) ||
  1420. preg_match("#\'(.*?)\'.*?\"(.*)\"#",$line,$match) ||
  1421. preg_match("#\"(.*?)\".*?\'(.*)\'#",$line,$match) ||
  1422. preg_match("#\'(.*?)\'.*?\'(.*)\'#",$line,$match) ||
  1423. preg_match("#\((.*?)\,.*?\"(.*)\"#",$line,$match) ||
  1424. preg_match("#\((.*?)\,.*?\'(.*)\'#",$line,$match))
  1425. {
  1426. return array('define'=>$match[1],'value'=>$match[2]);
  1427. }
  1428. }
  1429. function compareit($needle,$haystack,$value='',$disabled=FALSE, $reverse=false){
  1430. // return "Need=".$needle."<br />hack=".$haystack."<br />val=".$val;
  1431. //TODO Move this into a separate function (use a class for this whole script)
  1432. $commonPhrases = file_get_contents(e_LANGUAGEDIR."English/admin/lan_admin.php");
  1433. $commonLines = explode("\n",$commonPhrases);
  1434. $foundSimilar = FALSE;
  1435. $foundCommon = FALSE;
  1436. foreach($commonLines as $line)
  1437. {
  1438. if($match = getDefined($line))
  1439. {
  1440. $id = $match['define'];
  1441. $ar[$id] = $match['value'];
  1442. }
  1443. }
  1444. $commonArray = array_keys($ar);
  1445. // Check if a common phrases was used.
  1446. foreach($ar as $def=>$common)
  1447. {
  1448. similar_text($value, $common, $p);
  1449. if(strtoupper(trim($value)) == strtoupper($common))
  1450. {
  1451. //$text .= "<div style='color:yellow'><b>$common</b></div>";
  1452. $foundCommon = TRUE;
  1453. break;
  1454. }
  1455. elseif($p > 55)
  1456. {
  1457. $foundSimilar = TRUE;
  1458. break;
  1459. }
  1460. $p = 0 ;
  1461. }
  1462. foreach($haystack as $script)
  1463. {
  1464. $lines = explode("\n",$script);
  1465. $text .= "<td>";
  1466. $text2 .= ($reverse == true) ? "<td>" : "";
  1467. $count = 1;
  1468. foreach($lines as $ln)
  1469. {
  1470. if(preg_match("/\b".$needle."\b/i",$ln, $mtch))
  1471. {
  1472. if($disabled)
  1473. {
  1474. $text .= ADMIN_WARNING_ICON;
  1475. }
  1476. elseif($reverse == true)
  1477. {
  1478. $text .= ADMIN_TRUE_ICON;
  1479. }
  1480. $text .= " Line:<b>".$count."</b> "; // "' Found";
  1481. if($reverse == true)
  1482. {
  1483. $text2 .= print_a($ln,true);
  1484. }
  1485. $found = TRUE;
  1486. }
  1487. $count++;
  1488. }
  1489. if(!$found)
  1490. {
  1491. // echo "<br />Unused: ".$needle;
  1492. if($reverse == true)
  1493. {
  1494. if(in_array($needle,$commonArray))
  1495. {
  1496. $color = "background-color:#E9EAF2";
  1497. $text .= ADMIN_TRUE_ICON;
  1498. $value = "Common Term";
  1499. }
  1500. else
  1501. {
  1502. $color = "background-color:yellow";
  1503. $text .= "<a href='#' title=\"Missing\">".ADMIN_WARNING_ICON."</a>";
  1504. $value = "Missing from language file";
  1505. }
  1506. }
  1507. else
  1508. {
  1509. $color = "background-color:pink";
  1510. $text .= "-";
  1511. }
  1512. if(!$disabled)
  1513. {
  1514. $_SESSION['language-tools-unused'][] = $needle;
  1515. }
  1516. }
  1517. $text .= "</td>";
  1518. $text2 .= ($reverse == true) ? "</td>" : "";
  1519. }
  1520. // $color = $found ? "" : "background-color:pink";
  1521. if($foundCommon && $found)
  1522. {
  1523. $color = "background-color:yellow";
  1524. $disabled .= "<br /><i>".$common."</i> is a common phrase.<br />(Use <b>".$def."</b> instead.)";
  1525. // return "<tr><td style='width:25%;'>".$needle .$disabled. "</td><td></td></tr>";
  1526. }
  1527. elseif($foundSimilar && $found && substr($def,0,4) == "LAN_")
  1528. {
  1529. $color = "background-color:#E9EAF2";
  1530. $disabled .= " <a class='e-tip' href='#' title=\"".$value." :: ".$common."\">".round($p)."% like ".$def."</a> ";
  1531. // $disabled .= " <a class='e-tip' href='#' title=\"".$common."\">" . $def."</a>"; // $common;
  1532. }
  1533. if($disabled == " (disabled)")
  1534. {
  1535. $color = "background-color:#DFFFDF";
  1536. }
  1537. if(!$found)
  1538. {
  1539. $needle = "<a class='e-tip' href='#' title=\"".$value."\">".$needle."</a>";
  1540. }
  1541. return "<tr><td style='width:25%;$color'>".$needle .$disabled. "</td>".$text.$text2."</tr>";
  1542. }
  1543. /**
  1544. * Handle page DOM within the page header
  1545. *
  1546. * @return string JS source
  1547. */
  1548. function headerjs()
  1549. {
  1550. //FIXME breaking functionality.
  1551. return;
  1552. require_once (e_HANDLER.'js_helper.php');
  1553. $ret = "
  1554. <script type='text/javascript' src='".e_JS."core/admin.js'></script>
  1555. <script type='text/javascript'>
  1556. //add required core lan - delete confirm message
  1557. (".e_jshelper::toString(LAN_JSCONFIRM).").addModLan('core', 'delete_confirm');
  1558. //core object
  1559. e107Admin.CoreLanguage = {};
  1560. //show Table Copy option
  1561. e107Admin.CoreLanguage.dataCopy = function(table) {
  1562. if($('language-datacopy-' + table)) {
  1563. $('language-datacopy-' + table).show();
  1564. }
  1565. }
  1566. //registry - selected by default
  1567. e107Admin.CoreLanguage._def_checked = {}
  1568. //document observer
  1569. document.observe('dom:loaded', function() {
  1570. //find lan action checkboxes
  1571. \$\$('input[type=checkbox][id^=language-action-]').each( function(element) {
  1572. if(element.checked) e107Admin.CoreLanguage._def_checked[element.id] = true;// already checked, don't allow data copy
  1573. var carea = element.up('div.auto-toggle-area');
  1574. //clickable container - autocheck + allow data copy
  1575. if(carea) {
  1576. carea.observe('click', function(e) {
  1577. element.checked = !(element.checked);
  1578. if(element.checked && !e107Admin.CoreLanguage._def_checked[element.id]) {
  1579. e10

Large files files are truncated, but you can click here to view the full file