1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
savesource.php
См. документацию.
1
<?php
2
namespace
Bitrix\Translate\Controller\Editor;
3
4
use Bitrix\Main;
5
use Bitrix\Translate;
6
use Bitrix\Main\Localization\Loc;
7
11
class
SaveSource
12
extends
Operation
13
{
21
public
function
run
($file =
''
)
22
{
23
Loc::loadLanguageFile(__DIR__.
'/operation.php'
);
24
Loc::loadLanguageFile(__FILE__);
25
26
$result
= [];
27
if
(empty($file))
28
{
29
$this->
addError
(
new
Main
\
Error
(Loc::getMessage(
'TR_EDIT_FILE_PATH_ERROR'
)));
30
return
$result
;
31
}
32
$normalized =
Main\IO\Path::normalize
($file);
33
if
($normalized != $file)
34
{
35
$this->
addError
(
new
Main
\
Error
(Loc::getMessage(
'TR_EDIT_FILE_WRONG_NAME'
)));
36
return
$result
;
37
}
38
$file = $normalized;
39
if
(!
Translate
\
IO
\Path::isLangDir($file,
true
) || !
Translate
\
IO
\Path::isPhpFile($file))
40
{
41
$this->
addError
(
new
Main
\
Error
(Loc::getMessage(
'TR_EDIT_ERROR_FILE_NOT_LANG'
, [
'#FILE#'
=> $file])));
42
return
$result
;
43
}
44
if
(!
Translate
\
Permission::isAllowPath
($file))
45
{
46
$this->
addError
(
new
Main
\
Error
(Loc::getMessage(
'TR_EDIT_FILE_WRONG_NAME'
)));
47
return
$result
;
48
}
49
50
$request
= $this->controller->getRequest();
51
52
$languagesToUpdate = [];
53
54
$enabledLanguagesList
=
Translate\Config::getEnabledLanguages
();
55
56
// languages to update
57
$languagesToUpdateTmp =
$request
->getPost(
'LANGS'
);
58
if
($languagesToUpdateTmp !==
null
&& \is_array($languagesToUpdateTmp) && \
count
($languagesToUpdateTmp) > 0)
59
{
60
$languagesToUpdate = \array_intersect($languagesToUpdateTmp,
$enabledLanguagesList
);
61
}
62
unset($languagesToUpdateTmp);
63
64
$currentEncoding =
Main\Localization\Translation::getCurrentEncoding
();
65
$documentRoot
= \rtrim(
Translate
\
IO
\Path::tidy(
Main
\Application::getDocumentRoot()),
'/'
);
66
67
foreach
(
$enabledLanguagesList
as $langId)
68
{
69
if
(!\in_array($langId, $languagesToUpdate))
70
{
71
continue
;
72
}
73
74
$langRelPath =
Translate\IO\Path::replaceLangId
($file, $langId);
75
$fullPath =
Translate\IO\Path::tidy
(
$documentRoot
.
'/'
.$langRelPath);
76
$fullPath =
Main\Localization\Translation::convertLangPath
($fullPath, $langId);
77
78
$langFile
=
new
Translate\File
($fullPath);
79
$langFile
80
->setLangId($langId)
81
->setOperatingEncoding($currentEncoding);
82
83
// backup
84
if
(
$langFile
->isExists() &&
Translate
\Config::needToBackUpFiles())
85
{
86
if
(!
$langFile
->backup())
87
{
88
$this->
addError
(
new
Main
\
Error
(
89
Loc::getMessage(
'TR_CREATE_BACKUP_ERROR'
, [
'#FILE#'
=>
$langFile
->getPath()])
90
));
91
}
92
}
93
94
$fileSrcForSave =
$request
->getPost(
'SRC_'
. $langId);
95
96
if
(empty($fileSrcForSave) || !\is_string($fileSrcForSave))
97
{
98
$this->
addError
(
new
Main
\
Error
(Loc::getMessage(
'TR_EDIT_PARAM_ERROR'
)));
99
continue
;
100
}
101
102
if
(!
$langFile
->lint($fileSrcForSave))
103
{
104
$this->
addErrors
(
$langFile
->getErrors());
105
continue
;
106
}
107
108
try
109
{
110
if
(!
$langFile
->putContents($fileSrcForSave))
111
{
112
if
(
$langFile
->hasErrors())
113
{
114
$this->
addErrors
(
$langFile
->getErrors());
115
}
116
}
117
else
118
{
119
// check
120
if
(!
$langFile
->load() &&
$langFile
->hasErrors())
121
{
122
$this->
addErrors
(
$langFile
->getErrors());
123
}
124
elseif
(
$langFile
->count() > 0)
125
{
126
$langFile
->updatePhraseIndex();
127
}
128
}
129
}
130
catch
(
Main
\
IO
\IoException $exception)
131
{
132
if
(!
$langFile
->isExists())
133
{
134
$this->
addError
(
new
Main
\
Error
(
135
Loc::getMessage(
'TR_ERROR_WRITE_CREATE'
, [
'#FILE#'
=>
$langFile
->getPath()])
136
));
137
}
138
else
139
{
140
$this->
addError
(
new
Main
\
Error
(
141
Loc::getMessage(
'TR_ERROR_WRITE_UPDATE'
, [
'#FILE#'
=>
$langFile
->getPath()])
142
));
143
}
144
}
145
}
146
147
if
(!$this->
hasErrors
())
148
{
149
$result
[
'SUMMARY'
] = Loc::getMessage(
'TR_EDIT_SAVING_COMPLETED'
);
150
}
151
152
return
$result
;
153
}
154
}
$request
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения
catalog_reindex.php:36
Bitrix\Main\IO\Path\normalize
static normalize($path)
Определения
path.php:22
Bitrix\Main\Localization\Translation\getCurrentEncoding
static getCurrentEncoding()
Определения
translation.php:104
Bitrix\Main\Localization\Translation\convertLangPath
static convertLangPath($langFile, $language)
Определения
translation.php:267
Bitrix\Translate\Config\getEnabledLanguages
static getEnabledLanguages()
Определения
config.php:211
Bitrix\Translate\Controller\Editor\Operation
Определения
operation.php:14
Bitrix\Translate\Controller\Editor\Operation\$enabledLanguagesList
static $enabledLanguagesList
Определения
operation.php:16
Bitrix\Translate\Controller\Editor\Operation\$documentRoot
static $documentRoot
Определения
operation.php:18
Bitrix\Translate\Controller\Editor\SaveSource
Определения
savesource.php:13
Bitrix\Translate\Controller\Editor\SaveSource\run
run($file='')
Определения
savesource.php:21
Bitrix\Translate\IO\Path\replaceLangId
static replaceLangId(string $path, string $langId)
Определения
path.php:98
Bitrix\Translate\IO\Path\tidy
static tidy(string $path)
Определения
path.php:16
Bitrix\Translate\Permission\isAllowPath
static isAllowPath(string $path)
Определения
permission.php:23
$langFile
$langFile
Определения
.description.php:2
$result
$result
Определения
get_property_values.php:14
Bitrix\Main\File
Определения
Image.php:9
Bitrix\Main\IO
Определения
directory.php:3
Bitrix\Main
Bitrix\Main\hasErrors
hasErrors()
Определения
errorableimplementation.php:17
Bitrix\Translate
Определения
autoload.php:3
Bitrix\Translate\addErrors
addErrors(array $errors)
Определения
error.php:41
Bitrix\Translate\addError
addError(Main\Error $error)
Определения
error.php:22
Bitrix\Translate\Error
trait Error
Определения
error.php:11
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
count
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения
waybill.php:936
bitrix
modules
translate
lib
controller
editor
savesource.php
Создано системой
1.14.0