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);
}
if (isset($_POST['submit_prefs']) && isset($_POST['mainsitelanguage']))
{
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['noLanguageSubs'] = $_POST['noLanguageSubs'];
if ($admin_log->logArrayDiffs($temp, $pref, 'LANG_01'))
{
save_prefs(); // Only save if changes
$emessage->add(LAN_SETSAVED, E_MESSAGE_SUCCESS);
}
else
{
$emessage->add(LAN_NO_CHANGE);
}
}
// ----------------- delete tables ---------------------------------------------
if (isset($_POST['del_existing']) && $_POST['lang_choices'])
{
$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))
{
$message .= sprintf(LANG_LAN_28, $_POST['lang_choices'].' '.$del_table).'[!br!]';
$emessage->add(sprintf(LANG_LAN_28, $_POST['lang_choices'].' '.$del_table), E_MESSAGE_SUCCESS);
}
else
{
$message .= sprintf(LANG_LAN_29, $_POST['lang_choices'].' '.$del_table).'[!br!]';
$emessage->add(sprintf(LANG_LAN_29, $_POST['lang_choices'].' '.$del_table), E_MESSAGE_WARNING);
}
}
}
$admin_log->log_event('LANG_02', $message, 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))
{
$message .= sprintf(LANG_LAN_30, $_POST['language'].' '.$value).'[!br!]';
$emessage->add(sprintf(LANG_LAN_30, $_POST['language'].' '.$value), E_MESSAGE_SUCCESS);
}
else
{
if (!$_POST['drop'])
{
$message .= sprintf(LANG_LAN_00, $_POST['language'].' '.$value).'[!br!]';
$emessage->add(sprintf(LANG_LAN_00, $_POST['language'].' '.$value), E_MESSAGE_WARNING);
}
else
{
$message .= sprintf(LANG_LAN_01, $_POST['language'].' '.$value).'[!br!]';
$emessage->add(sprintf(LANG_LAN_01, $_POST['language'].' '.$value), E_MESSAGE_WARNING);
}
}
}
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!]';
$emessage->add($_POST['language'].' '.$value.' '.LAN_DELETED, E_MESSAGE_SUCCESS);
}
else
{
$message .= sprintf(LANG_LAN_02, $_POST['language'].' '.$value).'[!br!]';
$emessage->add(sprintf(LANG_LAN_02, $_POST['language'].' '.$value), E_MESSAGE_WARNING);
}
}
else
{
// leave table. LANG_LAN_32
$message .= sprintf(LANG_LAN_32, $_POST['language'].' '.$value).'[!br!]';
$emessage->add(sprintf(LANG_LAN_32, $_POST['language'].' '.$value));
}
}
}
$admin_log->log_event('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']);
$admin_log->log_event('LANG_04', $_POST['language'], E_LOG_INFORMATIVE, '');
$emessage->add(LANG_LAN_25.': '.$text);
}
else
{
$emessage->add(LANG_LAN_36,E_MESSAGE_WARNING);
}
}
if (varset($action) == "tools")
{
show_tools();
if($languagePacks = available_langpacks() )
{
e107::getRender()->tablerender(LANG_LAN_34,$languagePacks );
}
}
if(varset($_POST['searchDeprecated']) && varset($_POST['deprecatedLans']))
{
$mes = e107::getMessage();
$lanfile = $_POST['deprecatedLans'];
$scriptname = str_replace("lan_","",basename($lanfile));
if(is_readable(e_ADMIN.$script))
{
$script = e_ADMIN.$scriptname; // matching files. lan_xxxx.php and xxxx.php
}
// 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(is_readable($lanfile))
{
if($res = unused($lanfile,$script))
{
$ns -> tablerender($res['caption'],$mes->render(). $res['text']);
}
}
else
{
// echo 'PROBLEM';
}
}
//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'], $emessage->render().$text);
}
require_once (e_ADMIN."footer.php");
// ---------------------------------------------------------------------------
function multilang_prefs()
{
global $pref,$lanlist,$emessage;
$text = "
\n";
e107::getRender()->tablerender(LANG_LAN_PAGE_TITLE.' - '.LANG_LAN_13, $emessage->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()
{
global $pref,$tp,$frm,$emessage,$lanlist,$tabs;
$sql = e107::getDb();
if (isset($pref['multilanguage']) && $pref['multilanguage'])
{
// Choose Language to Edit:
$text = "
";
e107::getRender()->tablerender(LANG_LAN_PAGE_TITLE.' - '.LANG_LAN_16, $emessage->render().$text);
}
}
// ----------------------------------------------------------------------------
function show_tools()
{
$frm = e107::getForm();
$mes = e107::getMessage();
include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_lancheck.php");
$text = "
";
$text .= "
";
e107::getRender()->tablerender(LANG_LAN_PAGE_TITLE.' - '.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()
{
global $action,$pref;
if ($action == "")
{
$action = "main";
}
if ($action == "modify")
{
$action = "db";
}
$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";
// }
e_admin_menu(ADLAN_132, $action, $var);
}
// Zip up the language pack.
// ===================================================
function zip_up_lang($language)
{
if (is_readable(e_ADMIN."ver.php"))
{
include (e_ADMIN."ver.php");
}
$tp = e107::getParser();
/*
$core_plugins = array(
"alt_auth","banner_menu","blogcalendar_menu","calendar_menu","chatbox_menu",
"clock_menu","comment_menu","content","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","userlanguage_menu",
"usertheme_menu"
);
$core_themes = array("crahan","e107v4a","human_condition","interfectus","jayya",
"khatru","kubrick","lamb","leaf","newsroom","reline","sebes","vekna_blue");
*/
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)
{
$lanDefines = file_get_contents($lanfile);
$tmp = explode(",",$script);
foreach($tmp as $scr)
{
$compare[$scr] = file_get_contents($scr);
}
$mes = e107::getMessage();
if(!$compare)
{
$mes = e107::getMessage();
$mes->add("Couldn't read ".$script, E_MESSAGE_ERROR);
}
if(!$lanDefines)
{
$mes = e107::getMessage();
$mes->add("Couldn't read ".$lanfile, E_MESSAGE_ERROR);
}
$srch = array("");
$lanDefines = str_replace($srch,"",$lanDefines);
$lanDefines = explode("\n", $lanDefines);
if($lanDefines && $compare)
{
$text = "
".$lanfile." | ";
foreach($compare as $k=>$val)
{
$text .= "".$k." | ";
}
$text .= "
";
// for ($i=0; $iaddInfo("Pink is unused LAN");
$ret['text'] = $mes->render().$text;
$ret['caption'] = "Deprecated LAN Check (experimental!)";
return $ret;
}
else
{
return FALSE;
}
}
function getDefined($line)
{
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){
// 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'];
}
}
// 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 .= "";
$count = 1;
foreach($lines as $ln)
{
if(preg_match("/\b".$needle."\b/i",$ln))
{
if($disabled)
{
$text .= ADMIN_WARNING_ICON;
}
$text .= " Line:".$count." "; // "' Found";
$found = TRUE;
}
$count++;
}
if(!$found)
{
$text .= "-";
}
$text .= " | ";
}
$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";
}
return "".$needle .$disabled. " | ".$text."
";
}
/**
* 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;
}
?>