32 private int $tabId = 0;
36 private bool $convertEncoding;
38 private string $encodingOut;
40 private bool $collectUntranslated;
42 private bool $appendSamples;
43 private int $samplesCount = 10;
44 private array $samplesRestriction = [];
47 private array $languages;
50 private array $export;
51 private array $samples;
60 $configureActions = parent::configureActions();
63 $configureActions[self::ACTION_EXPORT] = [
68 $configureActions[self::ACTION_EXPORT_PATH] = [
69 'class' => Translate\Controller\Export\ExportPath::class,
74 $configureActions[self::ACTION_EXPORT_FILE] = [
75 'class' => Translate\Controller\Export\ExportFile::class,
80 $configureActions[self::ACTION_EXPORT_FILE_LIST] = [
81 'class' => Translate\Controller\Export\ExportFileList::class,
86 $configureActions[self::ACTION_EXPORT_FILE_SEARCH] = [
91 $configureActions[self::ACTION_EXPORT_PHRASE_SEARCH] = [
97 $configureActions[self::ACTION_PURGE] = [
102 $configureActions[self::ACTION_CANCEL] = [
107 $configureActions[self::ACTION_CLEAR] = [
113 $configureActions[self::ACTION_DOWNLOAD] = [
115 Main\Engine\ActionFilter\Csrf::class,
122 return $configureActions;
135 if ($this->request->get(
'tabId') !==
null)
137 $this->tabId = (int)$this->request->get(
'tabId');
142 $this->collectUntranslated = ($this->request->get(
'collectUntranslated') ===
'Y');
145 $this->appendSamples = ($this->request->get(
'appendSamples') ===
'Y');
146 $this->samplesCount = (int)$this->request->get(
'samplesCount') ?: 10;
148 $this->samplesRestriction = [];
149 if (!empty($this->request->get(
'samplesRestriction')))
151 $this->samplesRestriction = array_filter($this->request->get(
'samplesRestriction'),
'intVal');
155 $this->convertEncoding = ($this->request->get(
'convertEncoding') ===
'Y');
157 $this->encodingOut =
'';
158 if ($this->convertEncoding)
160 $this->encodingOut =
'utf-8';
165 $languages = $this->request->get(
'languages');
166 if (\is_array($languages) && !\in_array(
'all', $languages))
168 $languages = \array_intersect($languages, $enabledLanguages);
169 $sortLang = \array_flip($enabledLanguages);
172 function (
$a, $b) use ($sortLang)
176 return ((
$a == $b) ? 1 : (
$a < $b ? -1 : 1));
182 $languages = $enabledLanguages;
184 $this->languages = $languages;
197 public function exportAction($tabId,
$path =
''):
array
199 if (empty($tabId) || (
int)$tabId <= 0)
218 if (
$action->hasProcessCompleted() &&
$result[
'TOTAL_ITEMS'] == 0)
220 $result[
'SUMMARY'] = Loc::getMessage(
'TR_EXPORT_VOID');
224 $fileProperties =
$action->getDownloadingParameters();
225 $result[
'FILE_NAME'] = $fileProperties[
'fileName'];
226 $result[
'DOWNLOAD_LINK'] = $this->generateDownloadLink($fileProperties,
'export');
228 $messagePlaceholders = [
229 '#TOTAL_PHRASES#' =>
$result[
'TOTAL_PHRASES'],
230 '#FILE_SIZE_FORMAT#' => \CFile::formatSize($fileProperties[
'fileSize']),
231 '#FILE_NAME#' =>
$result[
'FILE_NAME'],
232 '#FILE_LINK#' =>
$result[
'DOWNLOAD_LINK'],
235 Loc::getMessage(
'TR_EXPORT_COMPLETED')
236 .
"\n". Loc::getMessage(
'TR_EXPORT_ACTION_EXPORT', $messagePlaceholders)
237 .
" ". Loc::getMessage(
'TR_EXPORT_DOWNLOAD', $messagePlaceholders)
240 if ($this->appendSamples)
242 if (
$result[
'TOTAL_SAMPLES'] > 0)
244 $fileSamplesProperties =
$action->getDownloadingSamplesParameters();
245 $result[
'SAMPLES_LINK'] = $this->generateDownloadLink($fileSamplesProperties,
'samples');
246 $result[
'SAMPLES_FILE'] = $fileSamplesProperties[
'fileName'];
248 $messagePlaceholders = [
249 '#TOTAL_SAMPLES#' =>
$result[
'TOTAL_SAMPLES'],
250 '#FILE_SIZE_FORMAT#' => \CFile::formatSize($fileSamplesProperties[
'fileSize']),
251 '#FILE_NAME#' =>
$result[
'SAMPLES_FILE'],
252 '#FILE_LINK#' =>
$result[
'SAMPLES_LINK'],
254 $result[
'SUMMARY'] .=
"\n" . Loc::getMessage(
'TR_EXPORT_SAMPLES', $messagePlaceholders);
255 $result[
'SUMMARY'] .=
" " . Loc::getMessage(
'TR_EXPORT_DOWNLOAD', $messagePlaceholders);
259 $result[
'SUMMARY'] .=
"\n" . Loc::getMessage(
'TR_EXPORT_SAMPLES_NOT_FOUND');
275 private function detectAction(
$path): ExportAction
278 $nextAction = self::ACTION_EXPORT_FILE_LIST;
279 $exporterClass = ExportFileList::class;
283 !empty($this->filter[
'FILE_NAME'])
284 || !empty($this->filter[
'FOLDER_NAME'])
285 || !empty($this->filter[
'INCLUDE_PATHS'])
286 || !empty($this->filter[
'EXCLUDE_PATHS'])
289 $nextAction = self::ACTION_EXPORT_FILE_SEARCH;
290 $exporterClass = ExportFileSearch::class;
294 $pathList = $this->request->get(
'pathList');
295 if (!empty($pathList))
297 $nextAction = self::ACTION_EXPORT_PATH;
298 $exporterClass = ExportPath::class;
303 !empty($this->filter[
'PHRASE_CODE'])
304 || !empty($this->filter[
'INCLUDE_PHRASE_CODES'])
305 || !empty($this->filter[
'EXCLUDE_PHRASE_CODES'])
306 || !empty($this->filter[
'PHRASE_TEXT'])
309 $nextAction = self::ACTION_EXPORT_PHRASE_SEARCH;
310 $exporterClass = ExportPhraseSearch::class;
313 $codeList = $this->request->get(
'codeList');
314 if (!empty($pathList) && !empty($codeList))
316 $nextAction = self::ACTION_EXPORT_PATH;
317 $exporterClass = ExportPath::class;
322 if (\preg_match(
"/\.php$/",
$path))
324 $nextAction = self::ACTION_EXPORT_FILE;
325 $exporterClass = ExportFile::class;
334 'tabId' => $this->tabId,
335 'collectUntranslated' => $this->collectUntranslated,
336 'appendSamples' => $this->appendSamples,
337 'samplesCount' => $this->samplesCount,
338 'samplesRestriction' => $this->samplesRestriction,
339 'convertEncoding' => $this->convertEncoding,
340 'encodingOut' => $this->encodingOut,
341 'languages' => $this->languages,
342 'filter' => $this->filter,
376 $result[
'SUMMARY'] = Loc::getMessage(
'TR_EXPORT_FILE_DROPPED');
398 ->keepField(
'export')
399 ->keepField(
'samples')
400 ->restoreProgressParameters();
402 foreach ([
'export',
'samples'] as
$type)
404 if (!empty($this->{$type}[
'filePath']))
407 if (
$path->isExists())
417 'SUMMARY' => Loc::getMessage(
'TR_EXPORT_ACTION_CANCEL'),
433 $this->
keepField($type)->saveProgressParameters();
435 return $this->
getActionUri(self::ACTION_DOWNLOAD, [
'tabId' => $this->tabId,
'type' =>
$type])->getUri();
452 if (empty(
$type) || !in_array(
$type, [
'export',
'samples'],
true))
457 $this->
keepField($type)->restoreProgressParameters();
459 if (!empty($this->{$type}[
'filePath']) && !empty($this->{$type}[
'fileName']))
462 if (
$path->isExists())
466 $this->{
$type}[
'fileName'],
467 $this->{$type}[
'fileType']
getActionUri(string $actionName, array $params=[], bool $absolute=false)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)