";
$input .= chr(60)."?php\n";
if ($old_kom == "")
{
// create CVS compatible description.
$diz = chr(47)."*\n";
$diz .= " * e107 website system\n";
$diz .= " *\n";
$diz .= " * Copyright (C) 2008-2009 e107 Inc (e107.org)\n";
$diz .= " * Released under the terms and conditions of the\n";
$diz .= " * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)\n";
$diz .= " *\n";
$diz .= " * Language File\n";
$diz .= " *\n";
$diz .= " * ".chr(36)."Source: ".str_replace(array(e_LANGUAGEDIR, e_PLUGIN), array(e_LANGUAGEDIR_ABS, e_PLUGIN_ABS), $writeit)." ".chr(36)."\n";
$diz .= " * ".chr(36)."Revision: 1.0 ".chr(36)."\n";
$diz .= " * ".chr(36)."Date: ".date("Y/m/d H:i:s")." ".chr(36)."\n";
$diz .= " * ".chr(36)."Author: ".USERNAME." ".chr(36)."\n";
$diz .= " *\n";
$diz .= "*".chr(47)."\n\n";
}
else
{
$diz = $old_kom;
}
$input .= $diz;
$message .= str_replace("\n"," ",$diz);
for ($i=0; $i '.$notdef_end;
$input .= $notdef_start."setlocale(".$defvar.",".$deflang.");".$notdef_end;
}
else
{
$message .= $notdef_start.$func.'('.$quote.htmlentities($defvar).$quote.',"'.$deflang.'"); '.$notdef_end;
$input .= $notdef_start.$func."(".$quote.$defvar.$quote.", ".chr(34).$deflang.chr(34).");".$notdef_end;
}
}
$message .=" ";
$message .="";
$input .= "\n\n?>";
// Write to file.
$fp = @fopen($writeit,"w");
if(!@fwrite($fp, $input))
{
$caption = LAN_CHECK_PAGE_TITLE.' - '.LAN_ERROR;
$message = '';
$mes->addError(LAN_CHECK_17);
}
else
{
$caption = LAN_CHECK_PAGE_TITLE.' - '.LAN_CHECK_24;
$mes->addSuccess(sprintXXX(str_replace("[x]", "%s", LAN_CHECK_23), basename($writeit)));
}
fclose($writeit);
$message .= "
";
$ns->tablerender($caption, $mes->render().$message);
// require_once(e_ADMIN."footer.php");
exit;
}
// ============================================================================
// Edit the Language File.
if($f != ""){
if (!$mode)
{
$dir1 = e_BASE.$LANGUAGES_DIRECTORY."English/";
$f1=$f;
$dir2 = e_BASE.$LANGUAGES_DIRECTORY.$lan."/";
$f2=$f;
}
else
{
$fullpath_orig = $f;
$fullpath_trans = str_replace("English",$lan,$f);
$f1 = basename($fullpath_orig);
$f2 = basename($fullpath_trans);
$dir1 = dirname($fullpath_orig)."/";
$dir2 = dirname($fullpath_trans)."/";
}
$lck->edit_lanfiles($dir1,$dir2,$f1,$f2);
}
// ===========================================================================
$core_plugins = array(
"alt_auth", "banner_menu", "blogcalendar_menu", "calendar_menu", "chatbox_menu",
"clock_menu", "comment_menu", "content", 'download', "featurebox", "forum",
"gsitemap", "links_page", "linkwords", "list_new", "log", "login_menu",
"newforumposts_main", "newsfeed", "newsletter", "online", "other_news_menu",
"pdf", "pm", "poll", "rss_menu", "search_menu", "siteinfo", "trackback",
"tree_menu", "user_menu"
);
$core_themes = array("bootstrap", $pref['sitetheme']);
if(isset($_POST['language_sel']) && isset($_POST['language']))
{
$text = $lck->check_core_lanfiles($_POST['language']).$lck->check_core_lanfiles($_POST['language'],"admin/");
$text .= "
".ADLAN_CL_7."
".LAN_PLUGIN."
".LAN_CHECK_16."
".$_POST['language']."
".LAN_OPTIONS."
";
foreach($core_plugins as $plugs)
{
if(is_readable(e_PLUGIN.$plugs))
{
$text .= $lck->check_lanfiles('P',$plugs,"English",$_POST['language']);
}
}
$text .= "
";
$text .= "
".LAN_CHECK_22."
".LAN_CHECK_21."
".LAN_CHECK_16."
".$_POST['language']."
".LAN_OPTIONS."
";
foreach($core_themes as $them)
{
if(is_readable(e_THEME.$them))
{
$text .= $lck->check_lanfiles('T',$them,"English",$_POST['language']);
}
}
$text .= "
";
$mes = e107::getMessage();
if($lck->error_count == 0)
{
e107::getConfig()->setPref('lancheck/'.$_POST['language'],1);
e107::getConfig()->save(FALSE);
$mes->addSuccess(LAN_CHECK_27.': '.$lck->error_count.' ');
}
else
{
$mes->addWarning(LAN_CHECK_27.': '.$lck->error_count.' ');
}
$ns->tablerender(LAN_CHECK_25, $mes->render(). $text);
require_once(e_ADMIN."footer.php");
exit;
}
*/
class lancheck
{
var $core_plugins = array(
"alt_auth","banner","blogcalendar_menu","calendar_menu","chatbox_menu",
"clock_menu","comment_menu","download","faqs", "featurebox", "forum","gallery", "gsitemap","import", "links_page",
"linkwords","list_new","log","login_menu","newforumposts_main","newsfeed",
"news", "newsletter","online", "page",
"pm","poll","rss_menu","search_menu","siteinfo","tagwords", "tinymce",
"trackback","tree_menu","user_menu"
);
/*
* $core_plugins = array(
"alt_auth", "banner_menu", "blogcalendar_menu", "calendar_menu", "chatbox_menu",
"clock_menu", "comment_menu", "content", 'download', "featurebox", "forum",
"gsitemap", "links_page", "linkwords", "list_new", "log", "login_menu",
"newforumposts_main", "newsfeed", "newsletter", "online", "other_news_menu",
"pdf", "pm", "poll", "rss_menu", "search_menu", "siteinfo", "trackback",
"tree_menu", "user_menu"
);
*/
var $core_themes = array("bootstrap");
var $errorsOnly = FALSE;
var $coreImage = array();
function init()
{
$ns = e107::getRender();
$tp = e107::getParser();
$pref = e107::getPref();
// Check current theme also (but do NOT add to generated zip)
$this->core_themes[] = $pref['sitetheme'];
$this->core_themes = array_unique($this->core_themes);
$acceptedLans = explode(",",e_LANLIST);
if(!isset($_SESSION['lancheck-core-image']))
{
$core = array();
$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');
require_once(e_ADMIN."core_image.php");
unset($core_image['e107_images'],$core_image['e107_files'],$core_image['e107_admin']);
$_SESSION['lancheck-core-image'] = $core_image;
}
if(isset($_POST['language_sel'])) // Verify
{
$_SESSION['lancheck-errors-only'] = ($_POST['errorsonly']==1 ) ? 1 : 0;
$this->errorsOnly = ($_POST['errorsonly']==1) ? TRUE : FALSE;
$this->check_all();
return TRUE;
}
// Write the language file.
if(isset($_POST['submit']) && varsettrue($_POST['lan']) && in_array($_POST['lan'],$acceptedLans))
{
$this->write_lanfile($_POST['lan']);
return TRUE;
}
// Edit the Language File.
if(varsettrue($_GET['f']) && varsettrue($_GET['lan']) && in_array($_GET['lan'],$acceptedLans))
{
if (!$_GET['mode'])
{
$dir1 = e_LANGUAGEDIR."English/";
$f1= $tp->toDB($_GET['f']);
$dir2 = e_LANGUAGEDIR.$_GET['lan']."/";
$f2= $tp->toDB($_GET['f']);
}
else
{
$fullpath_orig = $tp->toDB($_GET['f']);
$fullpath_trans = str_replace("English",$_GET['lan'],$tp->toDB($_GET['f']));
$f1 = basename($fullpath_orig);
$f2 = basename($fullpath_trans);
$dir1 = dirname($fullpath_orig)."/";
$dir2 = dirname($fullpath_trans)."/";
}
$this->edit_lanfiles($dir1,$dir2,$f1,$f2,$_GET['lan']);
return TRUE;
}
return FALSE;
}
function countFiles($array)
{
foreach($array as $k=>$val)
{
if(is_array($val))
{
$key = key($val);
$this->coreImage[$key] = $val;
}
elseif($val)
{
// $this->totalFiles++;
}
}
}
function check_all($mode='render')
{
// global $ns,$tp;
$mes = e107::getMessage();
$ns = e107::getRender();
$tp = e107::getParser();
$_POST['language'] = key($_POST['language_sel']);
$_SESSION['lancheck'][$_POST['language']] = array();
$_SESSION['lancheck'][$_POST['language']]['file'] = 0;
$_SESSION['lancheck'][$_POST['language']]['def'] = 0;
$_SESSION['lancheck'][$_POST['language']]['bom'] = 0;
$_SESSION['lancheck'][$_POST['language']]['utf'] = 0;
$_SESSION['lancheck'][$_POST['language']]['total'] = 0;
$core_text = $this->check_core_lanfiles($_POST['language']);
$core_admin = $this->check_core_lanfiles($_POST['language'],"admin/");
$plug_text = "";
$theme_text = "";
// Plugins -------------
$plug_header = "
".LAN_PLUGIN."
".LAN_CHECK_16."
".$_POST['language']."
".LAN_OPTIONS." ";
foreach($this->core_plugins as $plugs)
{
if(is_readable(e_PLUGIN.$plugs))
{
$plug_text .= $this->check_lanfiles('P',$plugs,"English",$_POST['language']);
}
}
$plug_footer = "
";
// Themes -------------
$theme_header = "
".LAN_CHECK_22."
".LAN_CHECK_16."
".$_POST['language']."
".LAN_OPTIONS." ";
foreach($this->core_themes as $them)
{
if(is_readable(e_THEME.$them))
{
$theme_text .= $this->check_lanfiles('T',$them,"English",$_POST['language']);
}
}
$theme_footer = "
";
// -------------------------
if($mode != 'render')
{
return;
}
$message .= "
";
// print_a($_SESSION['lancheck'][$_POST['language']]);
$plug_text = ($plug_text) ? $plug_header.$plug_text.$plug_footer : "".LAN_OK."
";
$theme_text = ($theme_text) ? $theme_header.$theme_text.$theme_footer : "".LAN_OK."
";
$mesStatus = ($_SESSION['lancheck'][$_POST['language']]['total']>0) ? E_MESSAGE_INFO : E_MESSAGE_SUCCESS;
$mes->add($message, $mesStatus);
// $ns -> tablerender(LAN_CHECK_24.": ".$_POST['language'],$message);
echo $mes->render();
$ns -> tablerender(LANG_LAN_21.SEP.$_POST['language'].SEP.LAN_CHECK_2, $core_text);
$ns -> tablerender(LAN_CHECK_3.": ".$_POST['language']."/admin", $core_admin);
$ns -> tablerender(ADLAN_CL_7, $plug_text);
$ns -> tablerender(LAN_CHECK_25, $theme_text);
}
function write_lanfile($lan='')
{
if(!$lan){ return; }
global $ns;
unset($input);
$kom_start = chr(47)."*";
$kom_end = "*".chr(47);
if(varsettrue($_SESSION['lancheck-edit-file']))
{
$writeit = $_SESSION['lancheck-edit-file'];
}
else
{
return;
}
$old_kom = "";
$in_kom=0;
if(is_readable($writeit)) // File Exists;
{
$data = file($writeit);
foreach($data as $line)
{
if (strpos($line,$kom_start) !== False && $old_kom == "")
{
$in_kom=1;
}
if ($in_kom) { $old_kom .= $line; }
if (strpos($line,$kom_end) !== False && $in_kom) {$in_kom = 0;}
}
}
$message = " ";
$input .= chr(60)."?php\n";
if ($old_kom == "")
{
// create CVS compatible description.
$diz = chr(47)."*\n";
$diz .= "+---------------------------------------------------------------+\n";
$diz .= "| e107 website content management system ".$lan." Language File\n";
$diz .= "| Released under the terms and conditions of the\n";
$diz .= "| GNU General Public License (http://gnu.org).\n";
$diz .= "|\n";
$diz .= "| ".chr(36)."URL: $writeit ".chr(36)."\n";
$diz .= "| ".chr(36)."Revision: 1.0 ".chr(36)."\n";
$diz .= "| ".chr(36)."Id: ".date("Y/m/d H:i:s")." ".chr(36)."\n";
$diz .= "| ".chr(36)."Author: ".USERNAME." ".chr(36)."\n";
$diz .= "+---------------------------------------------------------------+\n";
$diz .= "*".chr(47)."\n\n";
}
else
{
$diz = $old_kom;
}
$input .= $diz;
$message .= str_replace("\n"," ",$diz);
for ($i=0; $i '.$notdef_end;
$input .= $notdef_start."setlocale(".$defvar.",".$deflang.");".$notdef_end;
}
else
{
$message .= $notdef_start.$func.'('.$quote.htmlentities($defvar).$quote.',"'.$deflang.'"); '.$notdef_end;
$input .= $notdef_start.$func."(".$quote.$defvar.$quote.", ".chr(34).$deflang.chr(34).");".$notdef_end;
}
}
$message .=" ";
$message .="
";
$input .= "\n\n?>";
//
// Write to file.
$writeit = str_replace("//","/",$writeit); // Quick Fix.
$fp = @fopen($writeit,"w");
if(!@fwrite($fp, $input))
{
$caption = LAN_ERROR;
$message = LAN_CHECK_17;
}
else
{
$caption = LAN_SAVED." ".$lan."/".$writeit." ";
}
fclose($fp);
$message .= "";
unset($_SESSION['lancheck-edit-file']);
$ns -> tablerender($caption, $message);
}
function check_core_lanfiles($checklan,$subdir='')
{
global $lanfiles,$_POST,$sql;
// $sql->db_Mark_Time('Start Get Core Lan Phrases English');
$English = $this->get_comp_lan_phrases(e_LANGUAGEDIR."English/".$subdir,$checklan);
// $sql->db_Mark_Time('End Get Core Lan Phrases English');
$check = $this->get_comp_lan_phrases(e_LANGUAGEDIR.$checklan."/".$subdir,$checklan);
// print_a($check);
// return;
$text = "";
$header = "
".LAN_CHECK_16."
".$_POST['language']." ".LAN_CHECK_26."
".LAN_OPTIONS." ";
$keys = array_keys($English);
sort($keys);
$er = "";
foreach($keys as $k)
{
if($k != "bom")
{
$lnk = $k;
$k_check = str_replace("English",$checklan,$k);
if(array_key_exists($k,$check))
{
// $text .= "";
$subkeys = array_keys($English[$k]);
$er="";
$utf_error = "";
$bomkey = str_replace(".php","",$k_check);
// $bom_error = ($check['bom'][$bomkey]) ? "".LAN_CHECK_15." " : ""; // illegal chars
if($check['bom'][$bomkey])
{
$bom_error = "".LAN_CHECK_15." ";
$this->checkLog('bom',1);;
}
else
{
$bom_error = "";
}
foreach($subkeys as $sk)
{
if($utf_error == "" && !$this->is_utf8($check[$k][$sk]))
{
$utf_error = "".LAN_CHECK_19." ";
$this->checkLog('utf',1);
}
if($sk == "LC_ALL"){
$check[$k][$sk] = str_replace(chr(34).chr(34),"",$check[$k][$sk]);
}
$er .= $this->check_lan_errors($English[$k],$check[$k],$sk);
}
if($this->errorsOnly == TRUE && !$er && !$utf_error && !$bom_error)
{
continue;
}
$text .= " ";
$style = ($er) ? "forumheader2" : "forumheader3";
$text .= "";
$text .= $bom_error . $utf_error;
$text .= (!$er && !$bom_error && !$utf_error) ? "
" : $er."
";
$text .= "
";
}
else
{
$this->checkLog('file',1);
$this->newFile(e_LANGUAGEDIR.$checklan."/".$subdir.$lnk,$checklan);
$text .= "
"; // file missing.
}
// Leave in EDIT button for all entries - to allow re-translation of bad entries.
$subpath = ($subdir!='') ? $subdir.$k : $k;
$text .="
";
$text .=" ";
}
}
$footer = "
";
if($text)
{
return $header.$text.$footer;
}
else
{
return "".LAN_OK."
";
}
}
function check_lan_errors($english,$translation,$def)
{
$eng_line = $english[$def];
$trans_line = $translation[$def];
// return $eng_line." ".$trans_line." ";
$error = array();
if((!array_key_exists($def,$translation) && $eng_line != "") || (trim($trans_line) == "" && $eng_line != ""))
{
$this->checkLog('def',1);
return $def.": ".LAN_CHECK_5." ";
}
if((strpos($eng_line,"[link=")!==FALSE && strpos($trans_line,"[link=")===FALSE) || (strpos($eng_line,"[b]")!==FALSE && strpos($trans_line,"[b]")===FALSE))
{
$error[] = $def. ": Missing bbcodes";
}
elseif((strpos($eng_line,"[")!==FALSE && strpos($trans_line,"[")===FALSE) || (strpos($eng_line,"]")!==FALSE && strpos($trans_line, "]")===FALSE))
{
$error[] = $def. ": Missing [ and/or ] character(s)";
}
if((strpos($eng_line,"--LINK--")!==FALSE && strpos($trans_line,"--LINK--")==FALSE))
{
$error[] = $def. ": Missing --LINK--";
}
if((strpos($eng_line,"e107.org")!==FALSE && strpos($trans_line,"e107.org")==FALSE))
{
$error[] = $def. ": Missing e107.org URL";
}
if((strpos($eng_line,"e107coders.org")!==FALSE && strpos($trans_line,"e107coders.org")==FALSE))
{
$error[] = $def. ": Missing e107coders.org URL";
}
if(strip_tags($eng_line) != $eng_line)
{
$stripped = strip_tags($trans_line);
if(($stripped == $trans_line))
{
// echo " ".$def. " ".$stripped." ".$trans_line;
$error[] = $def. ": Missing HTML tags" ;
}
}
$this->checkLog('def',count($error));
return ($error) ? implode(" ",$error)." " : "";
}
function checkLog($type='error',$count)
{
$_SESSION['lancheck'][$_POST['language']][$type] += $count;
$_SESSION['lancheck'][$_POST['language']]['total'] += $count;
}
function get_lan_file_phrases($dir1,$dir2,$file1,$file2){
$ret = array();
$fname = $dir1.$file1;
$type='orig';
if(is_file($fname))
{
$data = file_get_contents($fname);
$ret= $ret + $this->fill_phrases_array($data,$type);
if(substr($data,0,5) != "fill_phrases_array($data,$type);
if(substr($data,0,5) != "");
}
return $ret;
}
function get_comp_lan_phrases($comp_dir,$lang,$depth=0)
{
if(!is_dir($comp_dir))
{
return array();
}
require_once(e_HANDLER."file_class.php");
$fl = new e_file;
$ret = array();
if($lang_array = $fl->get_files($comp_dir, ".php$","standard",$depth)){
sort($lang_array);
}
$regexp = (strpos($comp_dir,e_LANGUAGEDIR) !== FALSE) ? "#.php#" : "#".$lang."#";
foreach($lang_array as $f)
{
if(preg_match($regexp,$f['path'].$f['fname']) && is_file($f['path'].$f['fname']))
{
$allData = file_get_contents($f['path'].$f['fname']);
$data = explode("\n",$allData);
// $data = file($f['path'].$f['fname']);
$relpath = str_replace($comp_dir,"",$f['path']);
$key = str_replace(".php","",$relpath.$f['fname']);
if(substr($data[0],0,5) != "")
{
$end_of_file = 1;
}
}
if($f['path'].$f['fname'] == e_LANGUAGEDIR.$lang."/".$lang.".php")
{
$f['fname'] = "English.php"; // change the key for the main language file.
}
if($f['path'].$f['fname'] == e_LANGUAGEDIR.$lang."/".$lang."_custom.php")
{
$f['fname'] = "English_custom.php"; // change the key for the main language file.
}
$ret=$ret + $this->fill_phrases_array($allData,$relpath.$f['fname']);
}
}
return $ret;
}
// for plugins and themes - checkes what kind of language files directory structure we have
function check_lanfiles($mode,$comp_name,$base_lan="English",$target_lan){
global $ns,$sql;
$folder['P'] = e_PLUGIN.$comp_name;
$folder['T'] = e_THEME.$comp_name;
$comp_dir = $folder[$mode];
$baselang = $this->get_comp_lan_phrases($comp_dir."/languages/","English",1);
$check = $this->get_comp_lan_phrases($comp_dir."/languages/",$target_lan,1);
$text = "";
$keys = array_keys($baselang);
sort($keys);
foreach($keys as $k)
{
if($k == 'bom')
{
continue;
}
$lnk = $k;
//echo "klucz ".$k." ";
$k_check = str_replace("English",$target_lan,$k);
if(array_key_exists($k_check,$check))
{
$subkeys = array_keys($baselang[$k]);
$er="";
$utf_error = "";
$bomkey = str_replace(".php","",$k_check);
if($check['bom'][$bomkey])
{
$bom_error = "".LAN_CHECK_15." ";
$this->checkLog('bom',1);
}
else
{
$bom_error = "";
}
// $bom_error = ($check['bom'][$bomkey]) ? "".LAN_CHECK_15." " : ""; // illegal chars
foreach($subkeys as $sk)
{
if($utf_error == "" && !$this->is_utf8($check[$k_check][$sk]))
{
$utf_error = "".LAN_CHECK_19." ";
$this->checkLog('utf',1);
}
/*
if(!array_key_exists($sk,$check[$k_check]) || (trim($check[$k_check][$sk]) == "" && $baselang[$k][$sk] != ""))
{
$er .= ($er) ? " " : "";
$er .= $sk." ".LAN_CHECK_5;
}
*/
$er .= $this->check_lan_errors($baselang[$k],$check[$k_check],$sk);
}
if($this->errorsOnly == TRUE && !$er && !$utf_error && !$bom_error)
{
continue;
}
$text .= "
";
$style = ($er) ? "forumheader2" : "forumheader3";
$text .= "";
$text .= $bom_error . $utf_error;
$text .= (!$er && !$bom_error && !$utf_error) ? "
" : $er."
";
$text .= "
";
}
else
{
$this->checkLog('file',1);
$this->newFile($comp_dir."/languages/".$lnk,$target_lan);
$text .= "
";
}
$text .=" ";
}
// if (!$known) {$text = LAN_CHECK_18." : --> ".$fname." :: ".$dname;}
return $text;
}
function newFile($lnk,$target_lan)
{
if($target_lan == 'English')
{
return;
}
$newfile = str_replace("English",$target_lan,$lnk);
$dir = dirname($newfile);
if($dir != '.' && !is_dir($dir))
{
// echo " dir: ".$dir;
mkdir($dir,0755);
}
if(!file_exists($newfile))
{
// echo " file: ".$newfile;
$data = chr(60)."?php\n\ndefine(\"EXAMPLE\",\"Generated Empty Language File\");";
file_put_contents($newfile,$data);
}
}
function edit_lanfiles($dir1,$dir2,$f1,$f2,$lan)
{
if($lan == '')
{
echo "Language selection was lost. ";
return;
}
$ns = e107::getRender();
$sql = e107::getDb();
/* echo " dir1 = $dir1";
echo " file1 = $f1";
echo " dir2 = $dir2";
echo " file2 = $f2";*/
if($dir2.$f2 == e_LANGUAGEDIR.$lan."/English.php") // it's a language config file.
{
$f2 = $lan.".php";
$root_file = e_LANGUAGEDIR.$lan."/".$lan.".php";
}
else
{
$root_file = $dir2.$f2;
}
if($dir2.$f2 == e_LANGUAGEDIR.$lan."/English_custom.php") // it's a language config file.
{
$f2 = $lan."_custom.php";
$root_file = e_LANGUAGEDIR.$lan."/".$lan."_custom.php";
}
$writable = (is_writable($dir2)) ? TRUE : FALSE;
$trans = $this->get_lan_file_phrases($dir1,$dir2,$f1,$f2);
$keys = array_keys($trans);
sort($keys);
$text = "";
$text .= "";
$caption = LANG_LAN_21.SEP.$lan.SEP.LAN_CHECK_2.SEP.LAN_EDIT.SEP.str_replace("../","",$dir2.$f2);
$ns->tablerender($caption, $text);
}
function fill_phrases_array($data,$type)
{
$retloc = array();
if(preg_match_all('/(\/\*[\s\S]*?\*\/)/i',$data, $multiComment))
{
$data = str_replace($multiComment[1],'',$data); // strip multi-line comments.
}
if(preg_match('/^\s*?setlocale\s*?\(\s*?([\w]+)\s*?,\s*?(.+)\s*?\)\s*?;/im',$data,$locale)) // check for setlocale();
{
$retloc[$type][$locale[1]]= $locale[2];
}
if(preg_match_all('/^\s*?define\s*?\(\s*?(\'|\")([\w]+)(\'|\")\s*?,\s*?(\'|\")([\s\S]*?)\s*?(\'|\")\s*?\)\s*?;/im',$data,$matches))
{
$def = $matches[2];
$values = $matches[5];
foreach($def as $k=>$d)
{
$retloc[$type][$d]= $values[$k];
}
}
return $retloc;
/*
echo "Raw Data ".$type." ";
echo htmlentities($data);
echo " ";
*/
}
//--------------------------------------------------------------------
function is_utf8($str) {
/*
* @see http://hsivonen.iki.fi/php-utf8/ validation.php
*/
if(strtolower(CHARSET) != "utf-8" || $str == "")
{
return TRUE;
}
return (preg_match('/^.{1}/us',$str,$ar) == 1);
}
}
/*
class lancheck_old
{
var $error_count=0;
function check_core_lanfiles($checklan,$subdir=''){
$frm = e107::getForm();
$English = $this->get_comp_lan_phrases(e_LANGUAGEDIR."English/".$subdir,$checklan);
$check = $this->get_comp_lan_phrases(e_LANGUAGEDIR.$checklan."/".$subdir,$checklan);
$legend_txt = LAN_CHECK_3.": ".$_POST['language']."/".$subdir;
$fieldset_id = $subdir ? str_replace('/', '', $_POST['language'])."-".str_replace('/', '', $subdir) : str_replace('/', '', $_POST['language']);
$text .= "
{$legend_txt}
".LAN_CHECK_16."
".$_POST['language'].' '.LAN_CHECK_20."
".LAN_OPTIONS."
";
$keys = array_keys($English);
sort($keys);
$i = 0;
foreach($keys as $k)
{
if($k != "bom")
{
$lnk = $k;
$k_check = str_replace("English",$checklan,$k);
$text .= "
";
if(array_key_exists($k,$check))
{
$text .= "
{$lnk}
";
$subkeys = array_keys($English[$k]);
$er="";
$utf_error = "";
$bomkey = str_replace(".php","",$k_check);
$bom_error = ($check['bom'][$bomkey]) ? "".str_replace("[php]", " " : ""; // illegal chars
foreach($subkeys as $sk)
{
if($utf_error == "" && !$this->is_utf8($check[$k][$sk]))
{
$utf_error = "".LAN_CHECK_19." ";
}
if($sk == "LC_ALL"){
$check[$k][$sk] = str_replace(chr(34).chr(34),"",$check[$k][$sk]);
}
if((!array_key_exists($sk,$check[$k]) && $English[$k][$sk] != "") || (trim($check[$k][$sk]) == "" && $English[$k][$sk] != ""))
{
$er .= ($er) ? " " : "";
$er .= $sk." ".LAN_CHECK_5;
$this->error_count++;
}
}
$style = ($er) ? "warning" : "success";
$text .= "
";
$text .= $bom_error . $utf_error;
if(!$er && !$bom_error && !$utf_error)
{
$text .= LAN_OK;
}
else
{
$text .= $er." ";
$this->error_count++;
}
$text .= "
";
}
else
{
// file missing
$text .= "
{$lnk}
".LAN_CHECK_4."
";
$this->error_count++;
}
// Leave in EDIT button for all entries - to allow re-translation of bad entries.
$subpath = ($subdir!='') ? $subdir.$k : $k;
$text .= "
".$frm->admin_button('but-corelan-'.str_replace(array('/', '\\'), '-', $subdir).$i, LAN_EDIT, 'edit', '', array('other' => "onclick=\"window.location='".e_SELF."?".$subpath."|".$_POST['language']."'\""))."
";
$text .= "
";
}
$i++;
}
$text .= "
";
return $text;
}
function get_lan_file_phrases($dir1,$dir2,$file1,$file2){
$ret = array();
$fname = $dir1.$file1;
$type='orig';
if(is_file($fname))
{
$data = file($fname);
$ret=$ret + $this->fill_phrases_array($data,$type);
if(substr($data[0],0,5) != "fill_phrases_array($data,$type);
if(substr($data[0],0,5) != "get_files($comp_dir, '\.php','standard',$depth)){
sort($lang_array);
}
$regexp = (strpos($comp_dir,e_LANGUAGEDIR) !== FALSE) ? "#.php#" : "#".$lang."#";
foreach($lang_array as $f)
{
if(preg_match($regexp,$f['path'].$f['fname']))
{
$data = file($f['path'].$f['fname']);
$relpath = str_replace($comp_dir,"",$f['path']);
if(substr($data[0],0,5) != "fill_phrases_array($data,$relpath.$f['fname']);
}
}
return $ret;
}
// for plugins and themes - checks what kind of language files directory structure we have
function check_lanfiles($mode, $comp_name, $base_lan="English", $target_lan)
{
$frm = e107::getForm();
$folder['P'] = e_PLUGIN.$comp_name;
$folder['T'] = e_THEME.$comp_name;
$comp_dir = $folder[$mode];
$baselang = $this->get_comp_lan_phrases($comp_dir."/languages/","English",1);
$check = $this->get_comp_lan_phrases($comp_dir."/languages/",$target_lan,1);
$text = "";
$keys = array_keys($baselang);
sort($keys);
$i = 0;
foreach($keys as $k)
{
$lnk = $k;
//echo "klucz ".$k." ";
$k_check = str_replace("English",$target_lan,$k);
$text .= "
";
if(array_key_exists($k_check,$check))
{
$text .= "
".$comp_name."
".str_replace("English/","",$lnk)."
";
$subkeys = array_keys($baselang[$k]);
$er = "";
$utf_error = "";
$bomkey = str_replace(".php","",$k_check);
$bom_error = ($check['bom'][$bomkey]) ? "".LAN_CHECK_15." " : ""; // illegal chars
foreach($subkeys as $sk)
{
if($utf_error == "" && !$this->is_utf8($check[$k_check][$sk]))
{
$utf_error = "".LAN_CHECK_19." ";
}
if(!array_key_exists($sk,$check[$k_check]) || (trim($check[$k_check][$sk]) == "" && $baselang[$k][$sk] != ""))
{
$er .= ($er) ? " " : "";
$er .= $sk." ".LAN_CHECK_5;
$this->error_count++;
}
}
$style = ($er) ? "warning" : "success";
$text .= "
";
$text .= $bom_error . $utf_error;
$text .= (!$er && !$bom_error && !$utf_error) ? LAN_OK : $er." ";
$text .= "
";
}
else
{
$text .= "
".$comp_name."
".str_replace("English/","",$lnk)."
".LAN_CHECK_4."
";
$this->error_count++;
}
$text .="
".$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'\""))."
";
$text .="
";
$i++;
}
return $text;
}
function edit_lanfiles($dir1,$dir2,$f1,$f2){
global $e107, $lan;
$mes = e107::getMessage();
$ns = e107::getRender();
// echo " dir1 = $dir1";
//echo " file1 = $f1";
//echo " dir2 = $dir2";
//echo " file2 = $f2";
if($dir2.$f2 == e_LANGUAGEDIR.$lan."/English.php") // it's a language config file.
{
$f2 = $lan.".php";
$root_file = e_LANGUAGEDIR.$lan."/".$lan.".php";
}
else
{
$root_file = $dir2.$f2;
}
if($dir2.$f2 == e_LANGUAGEDIR.$lan."/English_custom.php") // it's a language config file.
{
$f2 = $lan."_custom.php";
$root_file = e_LANGUAGEDIR.$lan."/".$lan."_custom.php";
}
$writable = (is_writable($dir2)) ? TRUE : FALSE;
$trans = $this->get_lan_file_phrases($dir1,$dir2,$f1,$f2);
$keys = array_keys($trans);
sort($keys);
$text = "
";
$text .= "
".((!$writable) ? $dir2.$f2.LAN_NOTWRITABLE : "")."
".LAN_BACK."
";
$ns->tablerender(LAN_CHECK_PAGE_TITLE.' - '.LAN_CHECK_24, $text);
require_once(e_ADMIN."footer.php");
exit;
}
function fill_phrases_array($data,$type) {
$retloc = array();
foreach($data as $line){
//echo "line--> ".$line." ";
if (strpos($line,"define(") !== FALSE && strpos($line,");") === FALSE)
{
$indef=1;
$bigline="";
// echo "big1 -->".$line." ";
}
if ($indef)
{
$bigline.=str_replace("\n","",$line);
// echo "big2 -->".$line." ";
}
if (strpos($line,"define(") === FALSE && strpos($line,");") !== FALSE)
{
$indef=0;
$we_have_bigline=1;
// echo "big3 -->".$line." ";
}
if(strpos($line,"setlocale(") !== FALSE)
{
$indef=1;
$we_have_bigline=0;
}
if ((strpos($line,"define(") !== FALSE && strpos($line,");") !== FALSE && substr(ltrim($line),0,2) != "//") || $we_have_bigline || strpos($line,"setlocale(") !== FALSE)
{
if ($we_have_bigline)
{
$we_have_bigline=0;
$line=$bigline;
// echo "big -->".$line." ";
}
$ndef = "";
//echo "_ndefline -->".$line." ";
if (strpos($line,"defined(") !== FALSE )
{
$ndef = "ndef++";
$line = substr($line,strpos($line,"define("));
}
if(strpos($line,"setlocale(") !== FALSE)
{
$pos = substr(strstr($line,","),1);
$rep = array(");","\n",'""');
$val = str_replace($rep,"",$pos);
$retloc[$type]['LC_ALL']= $val;
// $retloc['orig']['LC_ALL']= "'en'";
}
else
{
//echo "ndefline: ".$line." ";
if(preg_match("#\"(.*?)\".*?\"(.*)\"#",$line,$matches) ||
preg_match("#\'(.*?)\'.*?\"(.*)\"#",$line,$matches) ||
preg_match("#\"(.*?)\".*?\'(.*)\'#",$line,$matches) ||
preg_match("#\'(.*?)\'.*?\'(.*)\'#",$line,$matches) ||
preg_match("#\((.*?)\,.*?\"(.*)\"#",$line,$matches) ||
preg_match("#\((.*?)\,.*?\'(.*)\'#",$line,$matches))
{
//echo "get_lan -->".$matches[1]." :: ".$ndef.$matches[2]." ";
if(!isset($retloc[$type][$matches[1]]))
{
$retloc[$type][$matches[1]]= $ndef.$matches[2];
}
}
}
}
}
return $retloc;
}
//--------------------------------------------------------------------
function is_utf8($str) {
// @see http://hsivonen.iki.fi/php-utf8/ validation.php
//@TODO: always TRUE
// if(strtolower(CHARSET) != "utf-8" || $str == "")
{
return TRUE;
}
return (preg_match('/^.{1}/us',$str,$ar) == 1);
}
}
*/
/*
function lancheck_adminmenu()
{
include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_language.php");
global $action;
$pref = e107::getPref();
if ($action == "") {
$action = "tools";
}
if($action == "modify")
{
$action = "db";
}
$var['main']['text'] = LAN_PREFS;
$var['main']['link'] = e_ADMIN_ABS."language.php";
if(isset($pref['multilanguage']) && $pref['multilanguage']){
$var['db']['text'] = LANG_LAN_03;
$var['db']['link'] = e_ADMIN_ABS."language.php?db";
}
$var['tools']['text'] = ADLAN_CL_6;
$var['tools']['link'] = e_ADMIN_ABS."language.php?tools";
e107::getNav()->admin(ADLAN_132, $action, $var);
}
$ns->tablerender(LAN_CHECK_PAGE_TITLE.' - '.LAN_CHECK_1, LAN_CHECK_26);
require_once(e_ADMIN."footer.php");
*/