コード例 #1
0
ファイル: translate_tools.php プロジェクト: rasuldev/torino
function SaveTCSVFile()
{
    $errors = array();
    if ($GLOBALS['APPLICATION']->GetGroupRight("translate") == 'W' && check_bitrix_sessid()) {
        if (array_key_exists('csvfile', $_FILES) && array_key_exists('tmp_name', $_FILES['csvfile']) && file_exists($_FILES['csvfile']['tmp_name'])) {
            $rewrite = array_key_exists('rewrite_lang_files', $_POST) && $_POST['rewrite_lang_files'] == 'Y';
            $arTLangs = GetTLangList();
            if ($fp = fopen($_FILES['csvfile']['tmp_name'], 'r')) {
                $i = 0;
                $arr = array();
                $arErrLineFile = array();
                while ($arData = fgetcsv($fp, 10000, ';')) {
                    if ($i == 0) {
                        //$arData = array_filter($arData);
                        $arColNames = array_flip($arData);
                    } else {
                        $file = $arData[$arColNames['file']];
                        $key = $arData[$arColNames['key']];
                        foreach ($arTLangs as $lang_id) {
                            if (array_key_exists($arColNames[$lang_id], $arData) && strlen($arData[$arColNames[$lang_id]]) > 0) {
                                $arr[$file][$lang_id][$key] = str_replace("\\\\", "\\", $arData[$arColNames[$lang_id]]);
                            } else {
                                $arErrLineFile[$i + 1] = $i + 1;
                            }
                        }
                    }
                    $i++;
                }
                fclose($fp);
                if (count($arErrLineFile) > 0) {
                    foreach ($arErrLineFile as $val) {
                        $errors[] = str_replace("#LINE#", $val, GetMessage("TR_TOOLS_ERROR_LINE_FILE"));
                    }
                }
                foreach ($arr as $file_patt => $arTranslations) {
                    if (is_lang_dir($file_patt, true)) {
                        foreach ($arTranslations as $lang_id => $arMessages) {
                            if (count($arMessages) < 1) {
                                continue;
                            }
                            $file = replace_lang_id($file_patt, $lang_id);
                            $MESS = array();
                            if (!$rewrite && file_exists($_SERVER['DOCUMENT_ROOT'] . $file)) {
                                include $_SERVER['DOCUMENT_ROOT'] . $file;
                                if (!is_array($MESS)) {
                                    $MESS = array();
                                }
                            }
                            $MESS = array_merge($MESS, $arMessages);
                            if (count($MESS) > 0) {
                                $strMess = "";
                                foreach ($MESS as $key => $value) {
                                    $value = str_replace("\n\r", "\n", $value);
                                    $strMess .= '$MESS["' . EscapePHPString($key) . '"] = "' . EscapePHPString($value) . '";' . "\n";
                                }
                                if (!TR_BACKUP($file)) {
                                    $errors[] = GetMessage("TR_TOOLS_ERROR_CREATE_BACKUP", array('%FILE%' => $file));
                                } else {
                                    if (!RewriteFile($_SERVER["DOCUMENT_ROOT"] . $file, "<?\n" . $strMess . "?" . ">")) {
                                        $errors[] = GetMessage('TR_TOOLS_ERROR_WRITE_FILE', array('%FILE%' => $file));
                                    }
                                }
                            }
                        }
                    } else {
                        $errors[] = GetMessage('TR_TOOLS_ERROR_FILE_NOT_LANG', array('%FILE%' => $file_patt));
                    }
                }
            }
        } else {
            $errors[] = GetMessage('TR_TOOLS_ERROR_EMPTY_FILE');
        }
    } else {
        $errors[] = GetMessage('TR_TOOLS_ERROR_RIGHTS');
    }
    if (count($errors) > 0) {
        $GLOBALS['APPLICATION']->ThrowException(implode('<br>', $errors));
        return false;
    }
    return true;
}
コード例 #2
0
$TRANS_RIGHT = $APPLICATION->GetGroupRight("translate");
if ($TRANS_RIGHT == "D") {
    $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
}
if (!check_bitrix_sessid()) {
    die;
}
require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/translate/include.php";
$arTLangs = GetTLangList();
$NO_TRANSLATE = array_key_exists('download_translate_lang', $_REQUEST) && $_REQUEST['download_translate_lang'] == 'N';
$path = $_REQUEST["path"];
if (preg_match("#\\.\\.[\\/]#" . BX_UTF_PCRE_MODIFIER, $path)) {
    $path = "";
}
$path = Rel2Abs("/", "/" . $path . "/");
$IS_LANG_DIR = is_lang_dir($path);
if ($IS_LANG_DIR) {
    foreach ($arTLangs as $hlang) {
        $ph = add_lang_id($path, $hlang, $arTLangs);
        if (strlen($ph) > 0) {
            GetTDirList($ph, true);
        }
        $ph = "";
    }
} else {
    GetTDirList($path, true);
}
$strFile = '';
$arFileFilter = array();
if (isset($_REQUEST['file'])) {
    $strFile = strval($_REQUEST['file']);
コード例 #3
0
ファイル: translate_list.php プロジェクト: Satariall/izurit
function GetPhraseCounters($arCommon, $path, $key)
{
    global $arCommonCounter, $Counter, $arTLangs;
    $Counter++;
    $arDirFiles = array();
    // is directori
    if (is_dir(prepare_path($_SERVER["DOCUMENT_ROOT"] . "/" . $path . "/"))) {
        if (is_lang_dir($path)) {
            if (is_array($arTLangs)) {
                // files array for directory language
                foreach ($arTLangs as $lng) {
                    $path = replace_lang_id($path, $lng);
                    $path_l = strlen($path);
                    foreach ($arCommon as $arr) {
                        if ($arr["IS_DIR"] == "N" && strncmp($arr["PATH"], $path, $path_l) == 0) {
                            $arDirFiles[] = $arr["PATH"];
                        }
                    }
                }
            }
        } else {
            if (is_array($arCommon)) {
                $path_l = strlen($path);
                // array files for directory
                foreach ($arCommon as $arr) {
                    if ($arr["IS_DIR"] == "N" && strncmp($arr["PATH"], $path, $path_l) == 0) {
                        $arDirFiles[] = $arr["PATH"];
                    }
                }
            }
        }
    } else {
        foreach ($arTLangs as $lng) {
            $arDirFiles[] = replace_lang_id($path, $lng);
        }
    }
    $arFilesLng = array();
    // array for every files
    foreach ($arDirFiles as $file) {
        if (file_exists($_SERVER["DOCUMENT_ROOT"] . $file) && preg_match("#/lang/(.*?)/#", $file, $arMatch)) {
            $file_lang = $arMatch[1];
            if (isset($arTLangs[$file_lang])) {
                if (substr($file, -3) != "php") {
                    continue;
                }
                $MESS_tmp = $MESS;
                $MESS = array();
                include $_SERVER["DOCUMENT_ROOT"] . $file;
                $file_name = remove_lang_id($file, $arTLangs);
                $arFilesLng[$file_name][$file_lang] = array_keys($MESS);
                $MESS = $MESS_tmp;
            }
        }
    }
    $arFilesLngCounter = array();
    //rashogdenia for files
    foreach ($arFilesLng as $file => $arLns) {
        $total_arr = array();
        //summa
        foreach ($arLns as $ln => $arLn) {
            $total_arr = array_merge($total_arr, $arLn);
        }
        $total_arr = array_unique($total_arr);
        $total = sizeof($total_arr);
        foreach ($arTLangs as $lang) {
            $arr = array();
            $arLn = is_array($arLns[$lang]) ? $arLns[$lang] : array();
            $diff_arr = array_diff($total_arr, $arLn);
            $arr["TOTAL"] = $total;
            $diff = sizeof($diff_arr);
            $arr["DIFF"] = $diff;
            $arFilesLngCounter[$file][$lang] = $arr;
        }
    }
    foreach ($arFilesLngCounter as $file => $arCount) {
        foreach ($arCount as $ln => $arLn) {
            $file_path = str_replace("/lang/", "/lang/" . $ln . "/", $file);
            $arCommonCounter[$key][$ln][$file_path]["TOTAL"] += $arLn["TOTAL"];
            $arCommonCounter[$key][$ln][$file_path]["DIFF"] += $arLn["DIFF"];
        }
    }
}