EOF;
}
}
return $sRet;
}
function getLangsArr( $bAddFlag = false, $bRetIDs = false ) {
$rLangs = db_res('SELECT * FROM `LocalizationLanguages` ORDER BY `Title` ASC');
$aLangs = array();
while( $aLang = mysql_fetch_assoc($rLangs) ) {
$sFlag = '';
$sFlag = $bAddFlag ? ( $aLang['Flag'] ? $aLang['Flag'] : 'xx' ) : '';
$sKey = ($bRetIDs) ? $aLang['ID'] : $aLang['Name'];
$aLangs[ $sKey ] = $aLang['Title'] . $sFlag;
}
return $aLangs;
}
function deleteLanguage($langID = 0) {
$langID = (int)$langID;
if($langID <= 0) return false;
$resLangs = mysql_query('
SELECT `ID`, `Name`
FROM `LocalizationLanguages`
WHERE `ID` = '.$langID);
if(mysql_num_rows($resLangs) <= 0) return false;
$arrLang = mysql_fetch_assoc($resLangs);
$numStrings = mysql_query('
SELECT COUNT(`IDKey`)
FROM `LocalizationStrings`
WHERE `IDLanguage` = '.$langID);
$numStrings = mysql_fetch_row($numStrings);
$numStrings = $numStrings[0];
mysql_query('DELETE FROM `LocalizationStrings` WHERE `IDLanguage` = '.$langID);
if(mysql_affected_rows() < $numStrings) return false;
mysql_query('DELETE FROM `LocalizationLanguages` WHERE `ID` = '.$langID);
if(mysql_affected_rows() <= 0) return false;
@unlink( BX_DIRECTORY_PATH_ROOT . 'langs/lang-'.$arrLang['Name'].'.php');
return true;
}
function getLocalizationKeys() {
$resKeys = db_res('SELECT `ID`, `IDCategory`, `Key` FROM `LocalizationKeys`');
$arrKeys = array();
while($arr = mysql_fetch_assoc($resKeys))
{
$ID = $arr['ID'];
unset($arr['ID']);
$arrKeys[$ID] = $arr;
}
return $arrKeys;
}
function getLocalizationStringParams($keyID) {
$keyID = (int)$keyID;
$resParams = mysql_query("
SELECT `IDParam`,
`Description`
FROM `LocalizationStringParams`
WHERE `IDKey` = $keyID
ORDER BY `IDParam`
");
$arrParams = array();
while ($arr = mysql_fetch_assoc($resParams))
{
$arrParams[(int)$arr['IDParam']] = $arr['Description'];
}
return $arrParams;
}
function getLocalizationCategories() {
$resCategories = db_res('SELECT `ID`, `Name` FROM `LocalizationCategories` ORDER BY `Name`');
$arrCategories = array();
while ($arr = mysql_fetch_assoc($resCategories))
{
$arrCategories[$arr['ID']] = $arr['Name'];
}
return $arrCategories;
}
function compileLanguage($langID = 0) {
$langID = (int)$langID;
$newLine = "\r\n";
if($langID <= 0) {
$resLangs = db_res('SELECT `ID`, `Name` FROM `LocalizationLanguages`');
} else {
$resLangs = db_res('
SELECT `ID`, `Name`
FROM `LocalizationLanguages`
WHERE `ID` = '.$langID
);
}
if ( mysql_num_rows($resLangs) <= 0 )
return false;
while($arrLanguage = mysql_fetch_assoc($resLangs)) {
$resKeysStrings = db_res("
SELECT `LocalizationKeys`.`Key` AS `Key`,
`LocalizationStrings`.`String` AS `String`
FROM `LocalizationStrings` INNER JOIN
`LocalizationKeys` ON
`LocalizationKeys`.`ID` = `LocalizationStrings`.`IDKey`
WHERE `LocalizationStrings`.`IDLanguage` = {$arrLanguage['ID']}");
$handle = fopen( BX_DIRECTORY_PATH_ROOT . "langs/lang-{$arrLanguage['Name']}.php", 'w');
if($handle === false) return false;
$fileContent = "{$newLine}\$LANG = array(";
while($arrKeyString = mysql_fetch_assoc($resKeysStrings))
{
$langKey = str_replace("\\", "\\\\", $arrKeyString['Key']);
$langKey = str_replace("'", "\\'", $langKey);
$langStr = str_replace("\\", "\\\\", $arrKeyString['String']);
$langStr = str_replace("'", "\\'", $langStr);
$fileContent .= "{$newLine}\t'$langKey' => '$langStr',";
}
$fileContent = trim($fileContent, ',');
$writeResult = fwrite($handle, $fileContent."{$newLine});?>");
if($writeResult === false) return false;
if(fclose($handle) === false) return false;
@chmod( BX_DIRECTORY_PATH_ROOT . "langs/lang-{$arrLanguage['Name']}.php", 0666);
}
return true;
}
function addStringToLanguage($langKey, $langString, $langID = -1, $categoryID = LANGUAGE_CATEGORY_ID_PROFILE_FIELDS) {
// input validation
$langID = (int)$langID;
$categoryID = (int)$categoryID;
if ( $langID == -1 )
{
$resLangs = db_res('SELECT `ID`, `Name` FROM `LocalizationLanguages`');
}
else
{
$resLangs = db_res('
SELECT `ID`, `Name`
FROM `LocalizationLanguages`
WHERE `ID` = '.$langID);
}
$langKey = addslashes($langKey);
$langString = process_db_input($langString);
$resInsertKey = db_res( "
INSERT INTO `LocalizationKeys`
SET `IDCategory` = $categoryID,
`Key` = '$langKey'", false );
if ( !$resInsertKey || mysql_affected_rows() <= 0 )
return false;
$keyID = mysql_insert_id();
while($arrLanguage = mysql_fetch_assoc($resLangs))
{
$resInsertString = db_res( "
INSERT INTO `LocalizationStrings`
SET `IDKey` = $keyID,
`IDLanguage` = {$arrLanguage['ID']},
`String` = '$langString'", false );
if ( !$resInsertString || mysql_affected_rows() <= 0 )
return false;
}
return true;
}
function updateStringInLanguage($langKey, $langString, $langID = -1) {
// input validation
$langID = (int)$langID;
if ( $langID == -1 )
{
$resLangs = db_res('SELECT `ID`, `Name` FROM `LocalizationLanguages`');
}
else
{
$resLangs = db_res('
SELECT `ID`, `Name`
FROM `LocalizationLanguages`
WHERE `ID` = '.$langID);
}
$langKey = addslashes($langKey);
$langString = process_db_input($langString);
$arrKey = db_arr( "
SELECT `ID`
FROM `LocalizationKeys`
WHERE `Key` = '$langKey'", false );
if ( !$arrKey )
return false;
$keyID = $arrKey['ID'];
while($arrLanguage = mysql_fetch_assoc($resLangs))
{
$resUpdateString = db_res( "
UPDATE `LocalizationStrings`
SET `String` = '$langString'
WHERE `IDKey` = $keyID
AND `IDLanguage` = {$arrLanguage['ID']}", false );
if ( !$resUpdateString || mysql_affected_rows() <= 0 )
return false;
}
return true;
}
function _t_action( $str, $arg0 = "", $arg1 = "", $arg2 = "" ) {
return ""._t($str,$arg0,$arg1,$arg2)."
";
}
function _t_echo_action( $str, $arg0 = "", $arg1 = "", $arg2 = "" ) {
echo ""._t($str,$arg0,$arg1,$arg2)."
";
}
function echo_t_err( $str, $arg0 = "", $arg1 = "", $arg2 = "" ) {
echo ""._t($str,$arg0,$arg1,$arg2)."
";
}
function _t_err( $str, $arg0 = "", $arg1 = "", $arg2 = "" ) {
return '' . _t( $str, $arg0, $arg1, $arg2 ) . '
';
}
function _t($key, $arg0 = "", $arg1 = "", $arg2 = "") {
global $LANG;
if(isset($LANG[$key]))
{
$str = $LANG[$key];
$str = str_replace('{0}', $arg0, $str);
$str = str_replace('{1}', $arg1, $str);
$str = str_replace('{2}', $arg2, $str);
return $str;
}
else
{
return $key;
}
}
function _t_ext($key, $args) {
global $LANG;
if(isset($LANG[$key]))
{
$str = $LANG[$key];
if(!is_array($args))
{
return str_replace('{0}', $args, $str);
}
foreach ($args as $key => $val)
{
$str = str_replace('{'.$key.'}', $val, $str);
}
return $str;
}
else
{
return $key;
}
}