installed();// Bugfix - don't use e_LANLIST as it's cached (SESSION)
$message = '';
if (e_QUERY)
{
$tmp = explode('.', e_QUERY);
$action = varset($tmp[0]);
$sub_action = varset($tmp[1]);
$id = varset($tmp[2]);
unset($tmp);
}
elseif(!getperms('0'))
{
$action = 'tools';
}
if (isset($_POST['submit_prefs']) && isset($_POST['mainsitelanguage']) && getperms('0'))
{
unset($temp);
$changes = array();
$temp['multilanguage'] = $_POST['multilanguage'];
$temp['multilanguage_subdomain'] = $_POST['multilanguage_subdomain'];
$temp['multilanguage_domain'] = $_POST['multilanguage_domain'];
$temp['sitelanguage'] = $_POST['mainsitelanguage'];
$temp['adminlanguage'] = $_POST['mainadminlanguage'];
$temp['noLanguageSubs'] = $_POST['noLanguageSubs'];
e107::getConfig()->setPref($temp)->save(true);
e107::getSession()->clear('e_language');
}
// ----------------- delete tables ---------------------------------------------
if (isset($_POST['del_existing']) && $_POST['lang_choices'] && getperms('0'))
{
$lang = strtolower($_POST['lang_choices']);
foreach ($tabs as $del_table)
{
if ($sql->db_Table_exists($lang."_".$del_table,TRUE))
{
// echo $del_table." exists ";
$qry = "DROP TABLE ".$mySQLprefix."lan_".$lang."_".$del_table;
if (mysql_query($qry))
{
$msg = $tp->lanVars(LANG_LAN_100, $_POST['lang_choices'].' '.$del_table);
$message .= $msg.'[!br!]';
$mes->addSuccess($msg);
}
else
{
$msg = $tp->lanVars(LANG_LAN_101, $_POST['lang_choices'].' '.$del_table);
$message .= $msg.'[!br!]';
$mes->addWarning($msg);
}
}
}
e107::getLog()->add('LANG_02', $message.'[!br!]', E_LOG_INFORMATIVE, '');
$sql->db_ResetTableList();
if ($action == 'modify')
$action = 'db';//FIX - force db action when deleting all lan tables
}
// ----------create tables -----------------------------------------------------
if (isset($_POST['create_tables']) && $_POST['language'])
{
$table_to_copy = array();
$lang_to_create = array();
foreach ($tabs as $value)
{
$lang = strtolower($_POST['language']);
if (isset($_POST[$value]))
{
$copdata = ($_POST['copydata_'.$value]) ? 1 : 0;
if ($sql->db_CopyTable($value, "lan_".$lang."_".$value, $_POST['drop'], $copdata))
{
$msg = $tp->lanVars(LANG_LAN_103, $_POST['language'].' '.$value);
$message .= $msg . '[!br!]'; // Used in admin log.
$mes->addSuccess($msg);
}
else
{
if (!$_POST['drop'])
{
$msg = $tp->lanVars(LANG_LAN_00, $_POST['language'].' '.$value);
$message .= $msg . '[!br!]';
$mes->addWarning($msg);
}
else
{
$msg = $tp->lanVars(LANG_LAN_01, $_POST['language'].' '.$value);
$message .= $msg . '[!br!]';
$mes->addWarning($msg);
}
}
}
elseif ($sql->db_Table_exists($value,$_POST['language']))
{
if ($_POST['remove'])
{
// Remove table.
if (mysql_query("DROP TABLE ".$mySQLprefix."lan_".$lang."_".$value))
{
$message .= $_POST['language'].' '.$value.' '.LAN_DELETED.'[!br!]'; // can be removed?
$mes->addSuccess($_POST['language'].' '.$value.' '.LAN_DELETED);
}
else
{
$msg = $tp->lanVars(LANG_LAN_02, $_POST['language'].' '.$value);
$message .= $msg . '[!br!]';
$mes->addWarning($msg);
}
}
else
{
// leave table. LANG_LAN_104
$msg = $tp->lanVars(LANG_LAN_104, $_POST['language'].' '.$value);
$message .= $msg . '[!br!]';
$mes->addInfo($msg);
}
}
}
e107::getLog()->add('LANG_03', $message, E_LOG_INFORMATIVE, '');
$sql->db_ResetTableList();
}
/*
if(isset($message) && $message)
{
$ns->tablerender(LAN_OK, $message);
}
*/
unset($text);
if (!e_QUERY || $action == 'main' && !$_POST['language'] && !$_POST['edit_existing'])
{
multilang_prefs();
}
if (varset($action) == 'db')
{
multilang_db();
}
/*
if (varset($_POST['ziplang']) && varset($_POST['language']))
{
if(varset($pref['lancheck'][$_POST['language']]) == 1)
{
$text = zip_up_lang($_POST['language']);
e107::getLog()->add('LANG_04', $_POST['language'], E_LOG_INFORMATIVE, '');
$mes->addInfo(LANG_LAN_25.': '.$text);
}
else
{
$mes->addWarning(LANG_LAN_36);
}
}
*/
// imported from e107 v1
if (varset($_POST['ziplang']))
{
$certVal = isset($_POST['contribute_pack']) ? 1 : 0;
if(!varset($_COOKIE['e107_certified']))
{
cookie('e107_certified',$certVal,(time() + 3600 * 24 * 30));
}
else
{
$_COOKIE['e107_certified'] = $certVal;
}
$_POST['language'] = key($_POST['ziplang']);
// If no session data, scan before zipping.
if(!isset($_SESSION['lancheck'][$_POST['language']]['total']) || $_SESSION['lancheck'][$_POST['language']]['total']!='0')
{
$_POST['language_sel'] = $_POST['ziplang'];
$lck->check_all('norender');
unset($_POST['language_sel']);
}
$status = zip_up_lang($_POST['language']);
if($status['error']==FALSE)
{
$text = $status['message']." ";
$text .= share($status['file']);
$mes->addSuccess($text);
//$ns->tablerender(LAN_CREATED, $text );
}
else
{
$mes->addError($status['message']);
//$ns->tablerender(LAN_CREATED_FAILED, $status['message']);
}
echo $mes->render();
}
function find_locale($language)
{
if(!is_readable(e_LANGUAGEDIR.$language."/".$language.".php"))
{
return FALSE;
}
$code = file_get_contents(e_LANGUAGEDIR.$language."/".$language.".php");
$tmp = explode("\n",$code);
$srch = array("define","'",'"',"(",")",";","CORE_LC2","CORE_LC",",");
foreach($tmp as $line)
{
if(strpos($line,"CORE_LC") !== FALSE && (strpos($line,"CORE_LC2") === FALSE))
{
$lc = trim(str_replace($srch,"",$line));
}
elseif(strpos($line,"CORE_LC2") !== FALSE)
{
$lc2 = trim(str_replace($srch,"",$line));
}
}
if(!isset($lc) || !isset($lc2) || $lc=="" || $lc2=="")
{
return FALSE;
}
return substr($lc,0,2)."_".strtoupper(substr($lc2,0,2));
//
}
/**
* Share Language File
* @param object $newfile
* Usage of e107 is granted to you provided that this function is not modified or removed in any way.
* @return
*/
function share($newfile)
{
global $pref;
if(!$newfile || E107_DEBUG_LEVEL > 0)
{
return;
}
global $tp;
$full_link = $tp->createConstants($newfile);
$email_message = " Site: ".SITENAME."
User: ".USERNAME."\n
Email: ".USEREMAIL."\n
Language: ".$_POST['language']."\n
IP:".USERIP."
...would like to contribute the following language pack for e107. (see attached) :
Missing Files: ".$_SESSION['lancheck'][$_POST['language']]['file']."
Bom Errors : ".$_SESSION['lancheck'][$_POST['language']]['bom']."
UTF Errors : ".$_SESSION['lancheck'][$_POST['language']]['utf']."
Definition Errors : ".$_SESSION['lancheck'][$_POST['language']]['def']."
Total Errors: ".$_SESSION['lancheck'][$_POST['language']]['total']."
XML file: ".$_SESSION['lancheck'][$_POST['language']]['xml'];
require_once(e_HANDLER."mail.php");
$send_to = (!$_POST['contribute_pack']) ? "languagepacks@e107inc.org" : "certifiedpack@e107inc.org";
$to_name = "e107 Inc.";
$Cc = "";
$Bcc = "";
$returnpath='';
$returnreceipt='';
$inline ="";
$subject = (!$_POST['contribute_pack']) ? "[0.7 LanguagePack] " : "[0.7 Certified LanguagePack] ";
$subject .= basename($newfile);
if(!@sendemail($send_to, $subject, $email_message, $to_name, '', '', $newfile, $Cc, $Bcc, $returnpath, $returnreceipt,$inline))
{
$text = "
";
$text .= defined('LANG_LAN_EML') ? "
".LANG_LAN_EML." " : "
There was a problem sending the language-pack. Please email your verified language pack to: ";
$text .= "
".$send_to." ";
$text .= "
";
return $text;
}
elseif($_POST['contribute_pack'])
{
return "Pack Sent to e107 Inc. A confirmation email will be sent to ".$pref['siteadminemail']." once it is received. Please also make sure that email coming from ".$send_to." is not blocked by your spam filter.
";
}
}
$debug = " f=".$_GET['f'];
$debug .= " mode=".$_GET['mode'];
$debug .= " lan=".$_GET['lan'];
// $ns->tablerender("Debug",$debug);
$rendered = $lck->init(); // Lancheck functions.
if (varset($action) == "tools" && !$rendered)
{
show_tools();
if($languagePacks = available_langpacks() )
{
e107::getRender()->tablerender(LANG_LAN_34,$languagePacks );
}
}
function findIncludedFiles($script,$reverse=false)
{
$mes = e107::getMessage();
$data = file_get_contents($script);
if(strpos($data, 'e_admin_dispatcher')!==false)
{
$reverse = false;
}
$dir = dirname($script);
$dir = str_replace("/includes","",$dir);
$plugin = basename($dir);
if(strpos($script,'admin')!==false || strpos($script,'includes')!==false) // Admin Language files.
{
$newLangs = array(
0 => $dir."/languages/English/English_admin_".$plugin.".php",
1 => $dir."/languages/English_admin_".$plugin.".php",
2 => $dir."/languages/English_admin.php",
3 => $dir."/languages/English/English_admin.php"
);
}
else
{
$newLangs = array(
0 => $dir."/languages/English/English_".$plugin.".php",
1 => $dir."/languages/English_admin_".$plugin.".php",
2 => $dir."/languages/English_front.php",
3 => $dir."/languages/English/English_front.php",
4 => $dir."/languages/English_front.php",
5 => $dir."/languages/English/English_front.php"
);
}
// if(strpos($data, 'e_admin_dispatcher')!==false)
{
foreach($newLangs as $path)
{
if(file_exists($path) && $reverse == false)
{
return $path;
}
}
}
preg_match_all("/.*(include_lan|require_once|include|include_once) ?\((.*e_LANGUAGE.*?\.php)/i",$data,$match);
$srch = array(" ",'e_PLUGIN.', 'e_LANGUAGEDIR', '.e_LANGUAGE.', "'", '"', "'.");
$repl = array("", e_PLUGIN, e_LANGUAGEDIR, "English", "", "", "");
foreach($match[2] as $lanFile)
{
$arrt = str_replace($srch,$repl,$lanFile);
// if(strpos($arrt,'admin'))
{
//return $arrt;
$arr[] = $arrt;
}
}
return implode(",",$arr);
// return $arr[0];
}
if(vartrue($_POST['disabled-unused']) && vartrue($_POST['disable-unused-lanfile']))
{
$mes = e107::getMessage();
$data = file_get_contents($_POST['disable-unused-lanfile']);
$new = disableUnused($data);
if(file_put_contents($_POST['disable-unused-lanfile'],$new))
{
$mes->addSuccess("Overwriting ".$_POST['disable-unused-lanfile']);
}
else
{
$mes->addError("Couldn't overwrite ".$_POST['disable-unused-lanfile']);
}
$ns->tablerender("Processed".SEP.$_POST['disable-unused-lanfile'],$mes->render()."".htmlentities($new)." ");
}
function disableUnused($data)
{
$data = str_replace("2008-2010","2008-2013", $data);
$data = str_replace(' * $URL$
* $Revision$
* $Id$
* $Author$',"",$data); // TODO FIXME ?
$tmp = explode("\n",$data);
foreach($tmp as $line)
{
$ret = getDefined($line);
$newline[] = (in_array($ret['define'],$_SESSION['language-tools-unused']) && substr($line,0,2) !='//') ? "// ".$line : $line;
}
return implode("\n",$newline);
}
if(varset($_POST['searchDeprecated']) && varset($_POST['deprecatedLans']))
{
$mes = e107::getMessage();
// $lanfile = $_POST['deprecatedLans'];
$script = $_POST['deprecatedLans'];
if(strpos($script,e_ADMIN)!==false) // CORE
{
$mes->addDebug("Mode: Core Admin Calculated");
//$scriptname = str_replace("lan_","",basename($lanfile));
$lanfile = e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_".basename($script);
}
else // Plugin
{
$mes->addDebug("Mode: Search Plugins");
$lanfile = findIncludedFiles($script,vartrue($_POST['deprecatedLansReverse']));
}
if(!is_readable($script))
{
$mes->addError("Not Readable: ".$script);
// $script = $scriptname; // matching files. lan_xxxx.php and xxxx.php
}
$found = findIncludedFiles($script,vartrue($_POST['deprecatedLansReverse']));
// print_a($found);
// Exceptions - same language loaded by several scripts.
if($lanfile == e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_e107_update.php")
{
$script = e_ADMIN."update_routines.php,".e_ADMIN."e107_update.php";
}
if(vartrue($_POST['deprecatedLanFile'])) //override.
{
$lanfile = $_POST['deprecatedLanFile'];
}
if($res = unused($lanfile, $script, vartrue($_POST['deprecatedLansReverse'])))
{
$ns -> tablerender($res['caption'],$mes->render(). $res['text']);
}
}
//FIX - create or edit check
if (isset($_POST['create_edit_existing']))
$_POST['edit_existing'] = true;
// Grab Language configuration. ---
if (isset($_POST['edit_existing']))
{
//XXX - JS ok with the current functionality?
$text .= "
";
$ns->tablerender($_POST['lang_choices'], $mes->render().$text);
}
require_once (e_ADMIN."footer.php");
// ---------------------------------------------------------------------------
function multilang_prefs()
{
if(!getperms('0'))
{
return;
}
global $lanlist;
$pref = e107::getPref();
$mes = e107::getMessage();
$frm = e107::getForm();
//XXX Remove later.
// Enable only for developers - SetEnv E_ENVIRONMENT develop
// if(!isset($_SERVER['E_DEV_LANGUAGE']) || $_SERVER['E_DEV_LANGUAGE'] !== 'true')
// {
// $lanlist = array('English');
// $mes->addInfo("Alpha version currently supports only the English language. After most features are stable and English terms are optimized - translation will be possible.");
// }
$text = "
\n";
e107::getRender()->tablerender(ADLAN_132.SEP.LAN_PREFS, $mes->render().$text); // "Language Preferences";
}
// ----------------------------------------------------------------------------
function table_list()
{
// grab default language lists.
$exclude = array();
$exclude[] = "banlist";
$exclude[] = "banner";
$exclude[] = "cache";
$exclude[] = "core";
$exclude[] = "online";
$exclude[] = "parser";
$exclude[] = "plugin";
$exclude[] = "user";
$exclude[] = "upload";
$exclude[] = "userclass_classes";
$exclude[] = "rbinary";
$exclude[] = "session";
$exclude[] = "tmp";
$exclude[] = "flood";
$exclude[] = "stat_info";
$exclude[] = "stat_last";
$exclude[] = "submit_news";
$exclude[] = "rate";
$exclude[] = "stat_counter";
$exclude[] = "user_extended";
$exclude[] = "user_extended_struct";
$exclude[] = "pm_messages";
$exclude[] = "pm_blocks";
$tables = e107::getDb()->db_TableList('nolan'); // db table list without language tables.
return array_diff($tables,$exclude);
}
// ------------- render form ---------------------------------------------------
function multilang_db()
{
if(!getperms('0'))
{
return "Access Denied";
}
global $lanlist, $tabs;
$sql = e107::getDb();
$frm = e107::getForm();
$tp = e107::getParser();
$mes = e107::getMessage();
$pref = e107::getPref();
if (isset($pref['multilanguage']) && $pref['multilanguage'])
{
// Choose Language to Edit:
$text = "
".LANG_LAN_16."
".ADLAN_132."
".LANG_LAN_03."
".LAN_OPTIONS."
";
sort($lanlist);
foreach ($lanlist as $e_language)
{
$installed = array();
if(strtolower($e_language) == $pref['sitelanguage'])
{
$e_language = "";
}
$text .= "{$e_language} ";
foreach ($tabs as $tab_name)
{
if ($e_language != $pref['sitelanguage'] && $sql->db_Table_exists($tab_name,$e_language))
{
$installed[] = $tab_name;
}
}
$text .= implode(", ",$installed);
if ($e_language == $pref['sitelanguage'])
{
$text .= "".LANG_LAN_17." ";
}
else
{
$text .= (!count($installed)) ? "".LANG_LAN_05." " : "";
}
$text .= " \n";
$text .= "
\n";
$text .= "
";
if (count($installed))
{
$text .= "".LAN_EDIT."
".LAN_DELETE." ";
}
elseif ($e_language != $pref['sitelanguage'])
{
// $text .= "".LAN_CREATE." ";
$text .= $frm->admin_button('create_edit_existing','no-value','create',LAN_CREATE);
}
$text .= "
";
}
$text .= "
";
e107::getRender()->tablerender(ADLAN_132.SEP.LANG_LAN_16, $mes->render().$text); // Languages -> Tables
}
}
// ----------------------------------------------------------------------------
function getLanList()
{
global $ln;
$lst = explode(",",e_LANLIST);
$list = array();
foreach($lst as $lang)
{
if($ln->isValid($lang))
{
$list[] = $lang;
}
}
sort($list);
return $list;
}
/**
* List the installed language packs.
* @return
*/
function show_packs()
{
$frm = e107::getForm();
$ns = e107::getRender();
$tp = e107::getParser();
if(is_readable(e_ADMIN."ver.php"))
{
include(e_ADMIN."ver.php");
list($ver, $tmp) = explode(" ", $e107info['e107_version']);
}
$lans = getLanList();
$release_diz = defined("LANG_LAN_30") ? LANG_LAN_30 : "Release Date";
$compat_diz = defined("LANG_LAN_31") ? LANG_LAN_31 : "Compatibility";
$lan_pleasewait = (defsettrue('LAN_PLEASEWAIT')) ? $tp->toJS(LAN_PLEASEWAIT) : "Please Wait";
$lan_displayerrors = (defsettrue('LANG_LAN_33')) ? LANG_LAN_33 : "Display only errors during verification";
$text = "
";
$text .= "";
$text .= "".LAN_OPTIONS." ";
$srch = array("[","]");
$repl = array(""," ");
$diz = (defsettrue("LANG_LAN_28")) ? LANG_LAN_28 : "Check this box if you're an [e107 certified translator].";
$checked = varset($_COOKIE['e107_certified']) == 1 ? true : false;
$text .= "";
$text .= $frm->checkbox('contribute_pack',1,$checked,array('label'=>str_replace($srch,$repl,$diz)));
;
$text .= "
";
$echecked = varset($_SESSION['lancheck-errors-only']) == 1 ? true : false;
$text .= $frm->checkbox('errorsonly',1,$echecked,array('label'=>$lan_displayerrors));
$text .= "
";
// $text .= "
//
// ".$frm->checkbox('non-core-plugs-themes',1,$echecked,array('label'=>$lan_displayerrors))."
//
// ";
$text .= "
";
$text .= " ";
$text .= "".LANG_LAN_AGR."
";
$ns->tablerender(ADLAN_132.SEP.LANG_LAN_32, $text);
return;
}
function show_tools()
{
$frm = e107::getForm();
$mes = e107::getMessage();
include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_lancheck.php");
show_packs();
return;
if(!vartrue($_SERVER['E_DEV']))
{
return;
}
/*
$text = "
".LAN_CHECK_1."
";
*/
$text = "";
$text .= "
".LANG_LAN_23."
";
e107::getRender()->tablerender(ADLAN_132.SEP.LANG_LAN_21, $mes->render().$text);
}
// ----------------------------------------------------------------------------
function available_langpacks()
{
$xml = e107::getXml();
$feed = e107::getPref('xmlfeed_languagepacks');
if($rawData = $xml -> loadXMLfile($feed, TRUE))
{
if(!varset($rawData['language']))
{
return FALSE;
}
$text .= "".LANG_LAN_35."
";
$text .= "";
foreach($rawData['language'] as $val)
{
$att = $val['@attributes'];
$name = $att['folder'];
$languages[$name] = array(
'name' => $att['name'],
'author' => $att['author'],
'authorURL' => $att['authorURL'],
'folder' => $att['folder'],
'version' => $att['version'],
'date' => $att['date'],
'compatibility' => $att['compatibility'],
'url' => $att['url']
);
}
ksort($languages);
//TODO LANs
$text .= "
Name
Version
Author
Release-date
Compatible
Download
";
foreach($languages as $value)
{
$text .= "
".$value['name']."
".$value['version']."
".$value['author']."
".$value['date']."
".$value['compatibility']."
Download Pack
";
}
$text .= "
";
return $text;
}
}
function language_adminmenu()
{
$pref = e107::getPref();
$action = e_QUERY;
if ($action == "")
{
$action = getperms('0') ? "main" : "tools";
}
if ($action == "modify")
{
$action = "db";
}
if(getperms('0'))
{
$var['main']['text'] = LAN_PREFS;
$var['main']['link'] = e_SELF;
if (isset($pref['multilanguage']) && $pref['multilanguage'])
{
$var['db']['text'] = LANG_LAN_03;
$var['db']['link'] = e_SELF."?db";
}
}
// $lcnt = explode(",", e_LANLIST);
// if (count($lcnt) > 1)
// {
$var['tools']['text'] = LANG_LAN_21;
$var['tools']['link'] = e_SELF."?tools";
// }
e107::getNav()->admin(ADLAN_132, $action, $var);
}
// Zip up the language pack.
// ===================================================
function zip_up_lang($language)
{
global $tp;
$ret = array();
$ret['file'] = "";
if($_SESSION['lancheck'][$language]['total'] > 0 && !E107_DEBUG_LEVEL)
{
$ret = array();
$ret['error'] = TRUE;
$message = (defined('LANG_LAN_34')) ? LANG_LAN_34 : "Please verify and correct the remaining [x] error(s) before attempting to create a language-pack.";
$ret['message'] = str_replace("[x]",$_SESSION['lancheck'][$language]['total'],$message);
return $ret;
}
if(!isset($_SESSION['lancheck'][$language]))
{
$ret = array();
$ret['error'] = TRUE;
$ret['message'] = (defined('LANG_LAN_27')) ? LANG_LAN_27 : "Please verify your language files ('Verify') then try again.";
return $ret;
}
if(varset($_POST['contribute_pack']) && varset($_SESSION['lancheck'][$language]['total']) !='0')
{
$ret['error'] = TRUE;
$ret['message'] = (defined("LANG_LAN_29")) ? LANG_LAN_29 : "You should correct the remaining errors before contributing your language pack.";
$ret['message'] .= " ";
$ret['message'] .= (defined('LANG_LAN_27')) ? LANG_LAN_27 : "Please verify your language files ('Verify') then try again.";
return $ret;
}
if(!is_writable(e_FILE."public"))
{
$ret['error'] = TRUE;
$ret['message'] = LAN_UPLOAD_777 . " ".e_FILE."public";
return $ret;
}
if(is_readable(e_ADMIN."ver.php"))
{
include(e_ADMIN."ver.php");
}
$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_themes = array("bootstrap");
require_once(e_HANDLER.'pclzip.lib.php');
list($ver, $tmp) = explode(" ", $e107info['e107_version']);
if(!$locale = find_locale($language))
{
$ret['error'] = TRUE;
$file = "e107_languages/{$language}/{$language}.php";
$def = (defined('LANG_LAN_25')) ? LANG_LAN_25 : "Please check that CORE_LC and CORE_LC2 have values in [lcpath] and try again.";
$ret['message'] = str_replace("[lcpath]",$file,$def); //
return $ret;
}
global $THEMES_DIRECTORY, $PLUGINS_DIRECTORY, $LANGUAGES_DIRECTORY, $HANDLERS_DIRECTORY, $HELP_DIRECTORY;
if(($HANDLERS_DIRECTORY != "e107_handlers/") || ( $LANGUAGES_DIRECTORY != "e107_languages/") || ($THEMES_DIRECTORY != "e107_themes/") || ($HELP_DIRECTORY != "e107_docs/help/") || ($PLUGINS_DIRECTORY != "e107_plugins/"))
{
$ret['error'] = TRUE;
$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.";
return $ret;
}
$newfile = e_MEDIA_FILE."e107_".$ver."_".$language."_".$locale."-utf8.zip";
$archive = new PclZip($newfile);
$core = grab_lans(e_LANGUAGEDIR.$language."/", $language,'',0);
$core_admin = grab_lans(e_BASE.$LANGUAGES_DIRECTORY.$language."/admin/", $language,'',2);
$plugs = grab_lans(e_BASE.$PLUGINS_DIRECTORY, $language, $core_plugins); // standardized path.
$theme = grab_lans(e_BASE.$THEMES_DIRECTORY, $language, $core_themes);
$docs = grab_lans(e_BASE.$HELP_DIRECTORY,$language);
$handlers = grab_lans(e_BASE.$HANDLERS_DIRECTORY,$language); // standardized path.
$file = array_merge($core,$core_admin, $plugs, $theme, $docs, $handlers);
$data = implode(",", $file);
if ($archive->create($data,PCLZIP_OPT_REMOVE_PATH,e_BASE) == 0)
{
$ret['error'] = TRUE;
$ret['message'] = $archive->errorInfo(true);
return $ret;
}
else
{
$fileName = e_FILE."public/".$language.".xml";
if(is_readable($fileName))
{
@unlink($fileName);
}
$fileData = '
';
if(file_put_contents($fileName,$fileData))
{
$addTag = $archive->add($fileName, PCLZIP_OPT_ADD_PATH, 'e107_languages/'.$language, PCLZIP_OPT_REMOVE_PATH, e_FILE.'public/');
$_SESSION['lancheck'][$language]['xml'] = "Yes";
}
else
{
$_SESSION['lancheck'][$language]['xml'] = "No";
}
@unlink($fileName);
$ret['file'] = $newfile;
$ret['message'] = str_replace("../", "", e_MEDIA_FILE)."".basename($newfile)." ";
$ret['error'] = FALSE;
return $ret;
}
}
/*
function zip_up_lang($language)
{
if (is_readable(e_ADMIN."ver.php"))
{
include (e_ADMIN."ver.php");
}
$tp = e107::getParser();
require_once (e_HANDLER.'pclzip.lib.php');
list($ver, $tmp) = explode(" ", $e107info['e107_version']);
$newfile = e_UPLOAD."e107_".$ver."_".$language."_utf8.zip";
$archive = new PclZip($newfile);
$core = grab_lans(e_LANGUAGEDIR.$language."/", $language);
$plugs = grab_lans(e_PLUGIN, $language);
$theme = grab_lans(e_THEME, $language);
$file = array_merge($core, $plugs, $theme);
$data = implode(",", $file);
if ($archive->create($data) == 0)
{
return $archive->errorInfo(true);
}
else
{
if($_POST['contribute_pack'])
{
$full_link = $tp->createConstants($newfile);
$email_message = "Site: ".SITENAME."
User: ".USERNAME."\n
IP:".USERIP."
...would like to contribute the following language pack for e107 v".$e107info['e107_version'].".
Please see attachment.";
$subject = basename($newfile);
//TODO - send email to languagepack@e107.org with attachment.
}
return LANG_LAN_22." (".str_replace("../", "", e_UPLOAD)."".basename($newfile)." ).";
}
}
*/
function grab_lans($path, $language, $filter = "")
{
$fl = e107::getFile();
if ($lanlist = $fl->get_files($path, "", "standard", 4))
{
sort($lanlist);
}
else
{
return;
}
$pzip = array();
foreach ($lanlist as $p)
{
$fullpath = $p['path'].$p['fname'];
if (strpos($fullpath, $language) !== FALSE)
{
$pzip[] = $fullpath;
}
}
return $pzip;
}
// -----------------------
/**
* Compare Language File against script and find unused LANs
* @param object $lanfile
* @param object $script
* @return string|boolean FALSE on error
*/
function unused($lanfile,$script,$reverse=false)
{
$mes = e107::getMessage();
$frm = e107::getForm();
unset($_SESSION['language-tools-unused']);
// $mes->addInfo("LAN=".$lanfile." Script = ".$script);
if($reverse == true)
{
$exclude = array("e_LANGUAGE","e_LANGUAGEDIR","e_LAN","e_LANLIST","e_LANCODE");
$data = file_get_contents($script);
if(preg_match_all("/([\w_]*LAN[\w_]*)/", $data, $match))
{
// print_a($match);
$foundLans = array();
foreach($match[1] as $val)
{
if(!in_array($val, $exclude))
{
$foundLans[] = $val;
}
}
sort($foundLans);
$foundLans = array_unique($foundLans);
$lanDefines = implode("\n",$foundLans);
}
$mes->addDebug("Script: ".$script);
$tmp = explode(",", $lanfile);
foreach($tmp as $scr)
{
if(!file_exists($scr))
{
$mes->addError("Couldn't Load: ".$scr);
continue;
}
$compare[$scr] = file_get_contents($scr);
$mes->addDebug("LanFile: ".$scr);
}
$lanfile = $script;
}
else
{
$lanDefines = file_get_contents($lanfile);
$mes->addDebug("LanFile: ".$lanfile);
$tmp = explode(",",$script);
foreach($tmp as $scr)
{
if(!file_exists($scr))
{
$mes->addError("Couldn't Load: ".$scr);
continue;
}
$compare[$scr] = file_get_contents($scr);
$mes->addDebug("Script: ".$scr);
}
}
// print_a($compare);
// print_a($lanDefines);
if(!$compare)
{
$mes->addError("Couldn't read ".$script);
}
if(!$lanDefines)
{
$mes->addError("Couldn't read ".$lanfile);
}
$srch = array("");
$lanDefines = str_replace($srch,"",$lanDefines);
$lanDefines = explode("\n", $lanDefines);
if($lanDefines)
{
$text = $frm->open('language-unused');
$text .= "
".$lanfile." ";
foreach($compare as $k=>$val)
{
$text .= "".$k." ";
}
if($reverse == true)
{
$text .= "Definition ";
}
$text .= "
";
// for ($i=0; $i0 && $reverse == false)
{
$text .= "".$frm->admin_button('disabled-unused','Disable All Unused','delete').
$frm->hidden('disable-unused-lanfile',$lanfile).
$frm->hidden('deprecatedLans',$script).
"
";
}
$text .= $frm->close();
if($reverse != true)
{
$mes->addInfo("Pink items are likely to be unused LANs. Comment out and test thoroughly. ");
}
$ret['text'] = $mes->render().$text;
$ret['caption'] = "Deprecated LAN Check (experimental!)";
return $ret;
}
else
{
return FALSE;
}
}
function getDefined($line,$script=false)
{
if($script == true)
{
return array('define'=>$line,'value'=>'unknown');
}
if(preg_match("#\"(.*?)\".*?\"(.*)\"#",$line,$match) ||
preg_match("#\'(.*?)\'.*?\"(.*)\"#",$line,$match) ||
preg_match("#\"(.*?)\".*?\'(.*)\'#",$line,$match) ||
preg_match("#\'(.*?)\'.*?\'(.*)\'#",$line,$match) ||
preg_match("#\((.*?)\,.*?\"(.*)\"#",$line,$match) ||
preg_match("#\((.*?)\,.*?\'(.*)\'#",$line,$match))
{
return array('define'=>$match[1],'value'=>$match[2]);
}
}
function compareit($needle,$haystack,$value='',$disabled=FALSE, $reverse=false){
// return "Need=".$needle." hack=".$haystack." val=".$val;
//TODO Move this into a separate function (use a class for this whole script)
$commonPhrases = file_get_contents(e_LANGUAGEDIR."English/admin/lan_admin.php");
$commonLines = explode("\n",$commonPhrases);
$foundSimilar = FALSE;
$foundCommon = FALSE;
foreach($commonLines as $line)
{
if($match = getDefined($line))
{
$id = $match['define'];
$ar[$id] = $match['value'];
}
}
$commonArray = array_keys($ar);
// Check if a common phrases was used.
foreach($ar as $def=>$common)
{
similar_text($value, $common, $p);
if(strtoupper(trim($value)) == strtoupper($common))
{
//$text .= "$common
";
$foundCommon = TRUE;
break;
}
elseif($p > 55)
{
$foundSimilar = TRUE;
break;
}
$p = 0 ;
}
foreach($haystack as $script)
{
$lines = explode("\n",$script);
$text .= "";
$text2 .= ($reverse == true) ? " " : "";
$count = 1;
foreach($lines as $ln)
{
if(preg_match("/\b".$needle."\b/i",$ln, $mtch))
{
if($disabled)
{
$text .= ADMIN_WARNING_ICON;
}
elseif($reverse == true)
{
$text .= ADMIN_TRUE_ICON;
}
$text .= " Line:".$count." "; // "' Found";
if($reverse == true)
{
$text2 .= print_a($ln,true);
}
$found = TRUE;
}
$count++;
}
if(!$found)
{
// echo " Unused: ".$needle;
if($reverse == true)
{
if(in_array($needle,$commonArray))
{
$color = "background-color:#E9EAF2";
$text .= ADMIN_TRUE_ICON;
$value = "Common Term";
}
else
{
$color = "background-color:yellow";
$text .= "".ADMIN_WARNING_ICON." ";
$value = "Missing from language file";
}
}
else
{
$color = "background-color:pink";
$text .= "-";
}
if(!$disabled)
{
$_SESSION['language-tools-unused'][] = $needle;
}
}
$text .= " ";
$text2 .= ($reverse == true) ? "" : "";
}
// $color = $found ? "" : "background-color:pink";
if($foundCommon && $found)
{
$color = "background-color:yellow";
$disabled .= "".$common." is a common phrase. (Use ".$def." instead.)";
// return "".$needle .$disabled. " ";
}
elseif($foundSimilar && $found && substr($def,0,4) == "LAN_")
{
$color = "background-color:#E9EAF2";
$disabled .= " ".round($p)."% like ".$def." ";
// $disabled .= " " . $def." "; // $common;
}
if($disabled == " (disabled)")
{
$color = "background-color:#DFFFDF";
}
if(!$found)
{
$needle = "".$needle." ";
}
return "".$needle .$disabled. " ".$text.$text2." ";
}
/**
* Handle page DOM within the page header
*
* @return string JS source
*/
function headerjs()
{
//FIXME breaking functionality.
return;
require_once (e_HANDLER.'js_helper.php');
$ret = "
";
return $ret;
}
?>