<?php require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_before.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/translate/prolog.php"; $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); }
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; }