Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
yama committed Jul 28, 2024
1 parent 37a19cc commit c444bc7
Showing 1 changed file with 65 additions and 66 deletions.
131 changes: 65 additions & 66 deletions manager/includes/extenders/ex_export_site.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,6 @@ public function run()
$ph['total'] = $this->total;
$folder_permission = octdec($modx->config['new_folder_permissions']);

$msg_failed_no_write = $this->makeMsg('failed_no_write', 'fail');
$msg_failed_no_open = $this->makeMsg('failed_no_open', 'fail');
$msg_failed_no_retrieve = $this->makeMsg('failed_no_retrieve', 'fail');
$msg_success = $this->makeMsg('success');
$msg_success_skip_doc = $this->makeMsg('success_skip_doc');
$msg_success_skip_dir = $this->makeMsg('success_skip_dir');

if (!is_file($this->lock_file_path)) {
$this->removeDirectoryAll($this->targetDir);
}
Expand Down Expand Up @@ -248,79 +241,85 @@ public function run()
$this->count++;
$row['count'] = $this->count;

if (!$row['wasNull']) { // needs writing a document
$docname = $this->getFileName(
$row['id'],
$row['alias'],
$modx->config('friendly_url_prefix'),
$modx->config('friendly_url_suffix')
);
$filename = $target_base_path . $docname;
if (is_dir($filename)) {
$filename = rtrim($filename, '/') . '/index.html';
}
if (!is_file($filename) || substr($filename, -10) === 'index.html') {
if ($row['published'] == 1) {
$status = $this->makeFile($row['id'], $filename);
switch ($status) {
case 'failed_no_write' :
$row['status'] = $msg_failed_no_write;
break;
case 'failed_no_open' :
$row['status'] = $msg_failed_no_open;
break;
default :
$row['status'] = $msg_success;
}
} else {
$row['status'] = $msg_failed_no_retrieve;
$this->processRow($row, $target_base_path, $_lang, $mask);
}

if (is_file($this->lock_file_path)) {
unlink($this->lock_file_path);
}

return join("\n", $this->output);
}

private function processRow($row, $target_base_path, $_lang, $mask)
{
if (!$row['wasNull']) { // needs writing a document
$docname = $this->getFileName(
$row['id'],
$row['alias'],
evo()->config('friendly_url_prefix'),
evo()->config('friendly_url_suffix')
);
$filename = $target_base_path . $docname;
if (is_dir($filename)) {
$filename = rtrim($filename, '/') . '/index.html';
}
if (!is_file($filename) || substr($filename, -10) === 'index.html') {
if ($row['published'] == 1) {
$status = $this->makeFile($row['id'], $filename);
switch ($status) {
case 'failed_no_write':
$row['status'] = $this->makeMsg('failed_no_write', 'fail');
break;
case 'failed_no_open':
$row['status'] = $this->makeMsg('failed_no_open', 'fail');
break;
default:
$row['status'] = $this->makeMsg('success');
}
} else {
$row['status'] = $msg_success_skip_doc;
$row['status'] = $this->makeMsg('failed_no_retrieve', 'fail');
}
$this->output[] = $modx->parseText($_lang['export_site_exporting_document'], $row);
} else {
$row['status'] = $msg_success_skip_dir;
$this->output[] = $modx->parseText($_lang['export_site_exporting_document'], $row);
}

if ($row['isfolder'] != 1) {
continue;
$row['status'] = $this->makeMsg('success_skip_doc');
}
$this->output[] = evo()->parseText($_lang['export_site_exporting_document'], $row);
} else {
$row['status'] = $this->makeMsg('success_skip_dir');
$this->output[] = evo()->parseText($_lang['export_site_exporting_document'], $row);
}

if ($modx->config('suffix_mode') == 1 && strpos($row['alias'], '.') !== false) {
continue;
}
if ($row['isfolder'] != 1) {
return;
}

$end_dir = ($row['alias'] !== '') ? $row['alias'] : $row['id'];
$folder_path = $target_base_path . $end_dir;
if (strpos($folder_path, MODX_BASE_PATH) !== 0) {
return false;
}
if (evo()->config('suffix_mode') == 1 && strpos($row['alias'], '.') !== false) {
return;
}

if (!is_dir($folder_path)) {
if (is_file($folder_path)) {
@unlink($folder_path);
}
umask(000);
mkdir($folder_path, 0777);
umask($mask);
}
$end_dir = ($row['alias'] !== '') ? $row['alias'] : $row['id'];
$folder_path = $target_base_path . $end_dir;
if (strpos($folder_path, MODX_BASE_PATH) !== 0) {
return false;
}

if ($modx->config['make_folders'] != 1 || $row['published'] != 1) {
continue;
if (!is_dir($folder_path)) {
if (is_file($folder_path)) {
@unlink($folder_path);
}
umask(000);
mkdir($folder_path, 0777);
umask($mask);
}

if (is_file($filename)) {
rename($filename, $folder_path . '/index.html');
}
if (evo()->config('make_folders') != 1 || $row['published'] != 1) {
return;
}
if (is_file($this->lock_file_path)) {
unlink($this->lock_file_path);

if (is_file($filename)) {
rename($filename, $folder_path . '/index.html');
}
return join("\n", $this->output);
}

private function get_contents($url, $timeout = 10)
{
if (!extension_loaded('curl')) {
Expand Down

0 comments on commit c444bc7

Please sign in to comment.