merge master in prod

This commit is contained in:
2020-09-08 12:00:45 +02:00
parent b925edaa9e
commit 3e5e731c2c
226 changed files with 8516 additions and 4149 deletions
+66 -8
View File
@@ -11,6 +11,7 @@ use Grav\Common\Grav;
use Grav\Common\Inflector;
use Grav\Common\Language\Language;
use Grav\Common\Page\Interfaces\PageInterface;
use Grav\Common\Security;
use Grav\Common\Uri;
use Grav\Common\Utils;
use Grav\Framework\Filesystem\Filesystem;
@@ -35,7 +36,7 @@ use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
* @property-read Data $data
* @property-read array $files
* @property-read Data $value
* @property-read array $errors
* @property array $errors
* @property-read array $fields
* @property-read Blueprint $blueprint
* @property-read PageInterface $page
@@ -133,7 +134,7 @@ class Form implements FormInterface, \ArrayAccess
}
// If we're on a modular page, find the real page.
while ($page && $page->modular()) {
while ($page && $page->modularTwig()) {
$header = $page->header();
$header->never_cache_twig = true;
$page = $page->parent();
@@ -546,7 +547,11 @@ class Form implements FormInterface, \ArrayAccess
// json_response
return [
'status' => 'error',
'message' => sprintf($language->translate('PLUGIN_FORM.FILEUPLOAD_UNABLE_TO_UPLOAD', null, true), $filename, $this->upload_errors[$upload['file']['error']])
'message' => sprintf(
$language->translate('PLUGIN_FORM.FILEUPLOAD_UNABLE_TO_UPLOAD', null, true),
$filename,
$this->getFileUploadError($upload['file']['error'], $language)
)
];
}
@@ -652,6 +657,11 @@ class Form implements FormInterface, \ArrayAccess
$upload['file']['name'] = $filename;
$upload['file']['path'] = $path;
// Special Sanitization for SVG
if (method_exists('Grav\Common\Security', 'sanitizeSVG') && Utils::contains($mime, 'svg', false)) {
Security::sanitizeSVG($upload['file']['tmp_name']);
}
// We need to store the file into flash object or it will not be available upon save later on.
$flash = $this->getFlash();
$flash->setUrl($url)->setUser($grav['user'] ?? null);
@@ -693,6 +703,54 @@ class Form implements FormInterface, \ArrayAccess
exit;
}
/**
* Return an error message for a PHP file upload error code
* https://www.php.net/manual/en/features.file-upload.errors.php
*
* @param int $error PHP file upload error code
* @param Language|null $language
* @return string File upload error message
*/
public function getFileUploadError(int $error, Language $language = null): string
{
if (!$language) {
$grav = Grav::instance();
/** @var Language $language */
$language = $grav['language'];
}
switch ($error) {
case UPLOAD_ERR_OK:
$item = 'FILEUPLOAD_ERR_OK';
break;
case UPLOAD_ERR_INI_SIZE:
$item = 'FILEUPLOAD_ERR_INI_SIZE';
break;
case UPLOAD_ERR_FORM_SIZE:
$item = 'FILEUPLOAD_ERR_FORM_SIZE';
break;
case UPLOAD_ERR_PARTIAL:
$item = 'FILEUPLOAD_ERR_PARTIAL';
break;
case UPLOAD_ERR_NO_FILE:
$item = 'FILEUPLOAD_ERR_NO_FILE';
break;
case UPLOAD_ERR_NO_TMP_DIR:
$item = 'FILEUPLOAD_ERR_NO_TMP_DIR';
break;
case UPLOAD_ERR_CANT_WRITE:
$item = 'FILEUPLOAD_ERR_CANT_WRITE';
break;
case UPLOAD_ERR_EXTENSION:
$item = 'FILEUPLOAD_ERR_EXTENSION';
break;
default:
$item = 'FILEUPLOAD_ERR_UNKNOWN';
}
return $language->translate('PLUGIN_FORM.'.$item);
}
/**
* Removes a file from the flash object session, before it gets saved.
*/
@@ -854,7 +912,7 @@ class Form implements FormInterface, \ArrayAccess
/**
* @return string
* @deprecated 3.0 Use $this->getName() instead
* @deprecated 3.0 Use $form->getName() instead
*/
public function name(): string
{
@@ -863,7 +921,7 @@ class Form implements FormInterface, \ArrayAccess
/**
* @return array
* @deprecated 3.0 Use $this->getFields() instead
* @deprecated 3.0 Use $form->getFields() instead
*/
public function fields(): array
{
@@ -872,7 +930,7 @@ class Form implements FormInterface, \ArrayAccess
/**
* @return PageInterface
* @deprecated 3.0 Use $this->getPage() instead
* @deprecated 3.0 Use $form->getPage() instead
*/
public function page(): PageInterface
{
@@ -882,7 +940,7 @@ class Form implements FormInterface, \ArrayAccess
/**
* Backwards compatibility
*
* @deprecated 3.0
* @deprecated 3.0 Calling $form->filter() is not needed anymore (does nothing)
*/
public function filter(): void
{
@@ -995,7 +1053,7 @@ class Form implements FormInterface, \ArrayAccess
public function getPagePathFromToken($path)
{
return Utils::getPagePathFromToken($path, $this->page());
return Utils::getPagePathFromToken($path, $this->getPage());
}
/**