- md5
- 481220a90bb226dc5c8ed2f5a60730a5
- sha1
- c3737014d2f772b09120989f8c586ebfd58ad099
- sha256
- 441d5624ea79c9cc421134ac53f5a7950ed129f341ec88b2edfd7f54b542168f
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
<?php
/**
* @package Joomla.Administrator
* @subpackage com_templates
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Templates\Administrator\Helper;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\Filesystem\File;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Template Helper class.
*
* @since 3.2
*/
abstract class TemplateHelper
{
/**
* Checks if the file is an image
*
* @param string $fileName The filename
*
* @return boolean
*
* @since 3.2
*/
public static function getTypeIcon($fileName)
{
// Get file extension
return strtolower(substr($fileName, strrpos($fileName, '.') + 1));
}
/**
* Checks if the file can be uploaded
*
* @param array $file File information
* @param string $err An error message to be returned
*
* @return boolean
*
* @since 3.2
*/
public static function canUpload($file, $err = '')
{
$params = ComponentHelper::getParams('com_templates');
if (empty($file['name'])) {
$app = Factory::getApplication();
$app->enqueueMessage(Text::_('COM_TEMPLATES_ERROR_UPLOAD_INPUT'), 'error');
return false;
}
// Media file names should never have executable extensions buried in them.
$executable = [
'ade', 'adp', 'asp', 'bat', 'chm', 'cmd', 'com', 'cpl', 'dll', 'exe', 'go',
'hta', 'ins', 'isp', 'jar', 'java', 'jse', 'lib', 'mde', 'msc', 'msp', 'mst',
'perl', 'phtml', 'pif', 'py', 'scr', 'sct', 'shb', 'sht', 'shtm', 'shtml',
'stm', 'sys', 'vb', 'vbe', 'vbs', 'vxd', 'wsc', 'wsf', 'wsh',
];
$explodedFileName = explode('.', $file['name']);
if (\count($explodedFileName) > 2) {
foreach ($executable as $extensionName) {
if (\in_array($extensionName, $explodedFileName)) {
$app = Factory::getApplication();
$app->enqueueMessage(Text::_('COM_TEMPLATES_ERROR_EXECUTABLE'), 'error');
return false;
}
}
}
if ($file['name'] !== File::makeSafe($file['name']) || preg_match('/\s/', File::makeSafe($file['name']))) {
$app = Factory::getApplication();
$app->enqueueMessage(Text::_('COM_TEMPLATES_ERROR_WARNFILENAME'), 'error');
return false;
}
$format = strtolower(File::getExt($file['name']));
$imageTypes = explode(',', $params->get('image_formats', 'gif,bmp,jpg,jpeg,png,webp'));
$sourceTypes = explode(',', $params->get('source_formats', 'txt,less,ini,xml,js,php,css,scss,sass,json'));
$fontTypes = explode(',', $params->get('font_formats', 'woff,woff2,ttf,otf'));
$archiveTypes = explode(',', $params->get('compressed_formats', 'zip'));
$allowable = array_merge($imageTypes, $sourceTypes, $fontTypes, $archiveTypes);
if ($format === '' || !\in_array($format, $allowable)) {
$app = Factory::getApplication();
$app->enqueueMessage(Text::_('COM_TEMPLATES_ERROR_WARNFILETYPE'), 'error');
return false;
}
if (\in_array($format, $archiveTypes)) {
$zip = new \ZipArchive();
if ($zip->open($file['tmp_name']) === true) {
for ($i = 0; $i < $zip->numFiles; $i++) {
$entry = $zip->getNameIndex($i);
$endString = substr($entry, -1);
if ($endString != DIRECTORY_SEPARATOR) {
$explodeArray = explode('.', $entry);
$ext = end($explodeArray);
if (!\in_array($ext, $allowable)) {
$app = Factory::getApplication();
$app->enqueueMessage(Text::_('COM_TEMPLATES_FILE_UNSUPPORTED_ARCHIVE'), 'error');
return false;
}
}
}
} else {
$app = Factory::getApplication();
$app->enqueueMessage(Text::_('COM_TEMPLATES_FILE_ARCHIVE_OPEN_FAIL'), 'error');
return false;
}
}
// Max upload size set to 10 MB for Template Manager
$maxSize = (int) ($params->get('upload_limit') * 1024 * 1024);
if ($maxSize > 0 && (int) $file['size'] > $maxSize) {
$app = Factory::getApplication();
$app->enqueueMessage(Text::_('COM_TEMPLATES_ERROR_WARNFILETOOLARGE'), 'error');
return false;
}
return true;
}
}
The same content is in 6 releases, Joomla 6.2.0-beta2 to 6.2.1-rc1. See them all, or every version of this file.