diff --git a/administrator/components/com_templates/src/Controller/TemplateController.php b/administrator/components/com_templates/src/Controller/TemplateController.php index 619aaa6b65f2f..2171fe090d8a4 100644 --- a/administrator/components/com_templates/src/Controller/TemplateController.php +++ b/administrator/components/com_templates/src/Controller/TemplateController.php @@ -848,11 +848,13 @@ public function extractArchive() if ($model->extractArchive($file)) { $this->setMessage(Text::_('COM_TEMPLATES_FILE_ARCHIVE_EXTRACT_SUCCESS')); - $url = 'index.php?option=com_templates&view=template&id=' . $id . '&file=' . $file; + $url = 'index.php?option=com_templates&view=template&id=' . $id . '&file=' . $file + . '&isMedia=' . $this->input->getInt('isMedia', 0); $this->setRedirect(Route::_($url, false)); } else { $this->setMessage(Text::_('COM_TEMPLATES_FILE_ARCHIVE_EXTRACT_FAIL'), 'error'); - $url = 'index.php?option=com_templates&view=template&id=' . $id . '&file=' . $file; + $url = 'index.php?option=com_templates&view=template&id=' . $id . '&file=' . $file + . '&isMedia=' . $this->input->getInt('isMedia', 0); $this->setRedirect(Route::_($url, false)); } } diff --git a/administrator/components/com_templates/src/Model/TemplateModel.php b/administrator/components/com_templates/src/Model/TemplateModel.php index 953d7ab224f05..3c5c7d5b58744 100644 --- a/administrator/components/com_templates/src/Model/TemplateModel.php +++ b/administrator/components/com_templates/src/Model/TemplateModel.php @@ -1838,27 +1838,26 @@ public function getArchive() public function extractArchive($file) { if ($this->getTemplate()) { - $app = Factory::getApplication(); - $relPath = base64_decode($file); - $explodeArray = explode('/', $relPath); - $fileName = end($explodeArray); - $path = $this->getBasePath() . base64_decode($file); + $app = Factory::getApplication(); + $basePath = $this->getBasePath(); + $archiveFilePath = Path::check($basePath . base64_decode($file), $basePath); + $extractPath = \dirname($archiveFilePath); - if (file_exists(Path::check($path . '/' . $fileName))) { + if (file_exists($archiveFilePath)) { $zip = new \ZipArchive(); - if ($zip->open(Path::clean($path . '/' . $fileName)) === true) { + if ($zip->open($archiveFilePath) === true) { for ($i = 0; $i < $zip->numFiles; $i++) { $entry = $zip->getNameIndex($i); - if (file_exists(Path::clean($path . '/' . $entry))) { + if (file_exists(Path::check($extractPath . '/' . $entry, $extractPath))) { $app->enqueueMessage(Text::_('COM_TEMPLATES_FILE_ARCHIVE_EXISTS'), 'error'); return false; } } - $zip->extractTo($path); + $zip->extractTo($extractPath); return true; }