Skip to content

Commit 2a8511d

Browse files
authored
[5.4] Proper com_templates error when PHP zip extension is missing (#46716)
1 parent a82c73e commit 2a8511d

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

administrator/components/com_templates/src/Model/TemplateModel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,12 @@ public function getArchive()
17811781
$app = Factory::getApplication();
17821782
$path = $this->getBasePath() . base64_decode($app->getInput()->get('file'));
17831783

1784+
// Check if the ZipArchive class exists
1785+
if (!class_exists('ZipArchive')) {
1786+
$app->enqueueMessage(Text::_('COM_TEMPLATES_ERROR_ZIPARCHIVE_NOT_ENABLED'), 'error');
1787+
return false;
1788+
}
1789+
17841790
if (file_exists(Path::clean($path))) {
17851791
$files = [];
17861792
$zip = new \ZipArchive();

administrator/components/com_templates/tmpl/template/default.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,18 @@
173173
<legend><?php echo Text::_('COM_TEMPLATES_FILE_CONTENT_PREVIEW'); ?></legend>
174174
<form action="<?php echo Route::_('index.php?option=com_templates&view=template&id=' . $input->getInt('id') . '&file=' . $this->file . '&isMedia=' . $input->get('isMedia', 0)); ?>" method="post" name="adminForm" id="adminForm">
175175
<ul class="nav flex-column well">
176-
<?php foreach ($this->archive as $file) : ?>
177-
<li>
178-
<?php if (substr($file, -1) === DIRECTORY_SEPARATOR) : ?>
179-
<span class="icon-folder icon-fw" aria-hidden="true"></span>&nbsp;<?php echo $file; ?>
180-
<?php endif; ?>
181-
<?php if (substr($file, -1) != DIRECTORY_SEPARATOR) : ?>
182-
<span class="icon-file icon-fw" aria-hidden="true"></span>&nbsp;<?php echo $file; ?>
183-
<?php endif; ?>
184-
</li>
185-
<?php endforeach; ?>
176+
<?php if (!empty($this->archive) && is_array($this->archive)) : ?>
177+
<?php foreach ($this->archive as $file) : ?>
178+
<li>
179+
<?php if (substr($file, -1) === DIRECTORY_SEPARATOR) : ?>
180+
<span class="icon-folder icon-fw" aria-hidden="true"></span>&nbsp;<?php echo $file; ?>
181+
<?php endif; ?>
182+
<?php if (substr($file, -1) != DIRECTORY_SEPARATOR) : ?>
183+
<span class="icon-file icon-fw" aria-hidden="true"></span>&nbsp;<?php echo $file; ?>
184+
<?php endif; ?>
185+
</li>
186+
<?php endforeach; ?>
187+
<?php endif; ?>
186188
</ul>
187189
<input type="hidden" name="task" value="">
188190
<?php echo HTMLHelper::_('form.token'); ?>

administrator/language/en-GB/com_templates.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ COM_TEMPLATES_ERROR_WARNFILENAME="Invalid file name. Please correct the name of
9191
COM_TEMPLATES_ERROR_WARNFILETOOLARGE="This file is too large to upload."
9292
COM_TEMPLATES_ERROR_WARNFILETYPE="File format not supported."
9393
COM_TEMPLATES_ERROR_WARNIEXSS="Can't be uploaded. Has XSS."
94+
COM_TEMPLATES_ERROR_ZIPARCHIVE_NOT_ENABLED="The PHP ZipArchive extension is not enabled."
9495
COM_TEMPLATES_ERR_XML="Template XML data not available"
9596
COM_TEMPLATES_FIELD_CLIENT_LABEL="Location"
9697
COM_TEMPLATES_FIELD_HOME_LABEL="Default"

0 commit comments

Comments
 (0)