Upgrade to 3.5.7
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Kirby\Cms;
|
||||
|
||||
use Kirby\Image\Image;
|
||||
use Kirby\Toolkit\A;
|
||||
use Kirby\Toolkit\Escape;
|
||||
use Kirby\Toolkit\F;
|
||||
use Throwable;
|
||||
|
||||
@@ -561,6 +562,14 @@ class File extends ModelWithContent
|
||||
$absolute = $this->parent() !== $params['model'];
|
||||
}
|
||||
|
||||
// escape the default text
|
||||
// TODO: no longer needed in 3.6
|
||||
$textQuery = $params['text'] ?? '{{ file.filename }}';
|
||||
$text = $this->toString($textQuery);
|
||||
if ($textQuery === '{{ file.filename }}') {
|
||||
$text = Escape::html($text);
|
||||
}
|
||||
|
||||
return [
|
||||
'filename' => $this->filename(),
|
||||
'dragText' => $this->dragText('auto', $absolute ?? false),
|
||||
@@ -569,7 +578,7 @@ class File extends ModelWithContent
|
||||
'image' => $image,
|
||||
'info' => $this->toString($params['info'] ?? false),
|
||||
'link' => $this->panelUrl(true),
|
||||
'text' => $this->toString($params['text'] ?? '{{ file.filename }}'),
|
||||
'text' => $text,
|
||||
'type' => $this->type(),
|
||||
'url' => $this->url(),
|
||||
'uuid' => $uuid,
|
||||
|
@@ -7,6 +7,7 @@ use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Exception\NotFoundException;
|
||||
use Kirby\Http\Uri;
|
||||
use Kirby\Toolkit\A;
|
||||
use Kirby\Toolkit\Escape;
|
||||
use Kirby\Toolkit\F;
|
||||
|
||||
/**
|
||||
@@ -995,6 +996,14 @@ class Page extends ModelWithContent
|
||||
$image = $this->panelImage($params['image'] ?? []);
|
||||
$icon = $this->panelIcon($image);
|
||||
|
||||
// escape the default text
|
||||
// TODO: no longer needed in 3.6
|
||||
$textQuery = $params['text'] ?? '{{ page.title }}';
|
||||
$text = $this->toString($textQuery);
|
||||
if ($textQuery === '{{ page.title }}') {
|
||||
$text = Escape::html($text);
|
||||
}
|
||||
|
||||
return [
|
||||
'dragText' => $this->dragText(),
|
||||
'hasChildren' => $this->hasChildren(),
|
||||
@@ -1003,7 +1012,7 @@ class Page extends ModelWithContent
|
||||
'image' => $image,
|
||||
'info' => $this->toString($params['info'] ?? false),
|
||||
'link' => $this->panelUrl(true),
|
||||
'text' => $this->toString($params['text'] ?? '{{ page.title }}'),
|
||||
'text' => $text,
|
||||
'url' => $this->url(),
|
||||
];
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ namespace Kirby\Cms;
|
||||
use Exception;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Exception\NotFoundException;
|
||||
use Kirby\Toolkit\Escape;
|
||||
use Kirby\Toolkit\F;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
@@ -628,6 +629,14 @@ class User extends ModelWithContent
|
||||
$image = $this->panelImage($params['image'] ?? []);
|
||||
$icon = $this->panelIcon($image);
|
||||
|
||||
// escape the default text
|
||||
// TODO: no longer needed in 3.6
|
||||
$textQuery = $params['text'] ?? '{{ user.username }}';
|
||||
$text = $this->toString($textQuery);
|
||||
if ($textQuery === '{{ user.username }}') {
|
||||
$text = Escape::html($text);
|
||||
}
|
||||
|
||||
return [
|
||||
'icon' => $icon,
|
||||
'id' => $this->id(),
|
||||
@@ -635,7 +644,7 @@ class User extends ModelWithContent
|
||||
'email' => $this->email(),
|
||||
'info' => $this->toString($params['info'] ?? false),
|
||||
'link' => $this->panelUrl(true),
|
||||
'text' => $this->toString($params['text'] ?? '{{ user.username }}'),
|
||||
'text' => $text,
|
||||
'username' => $this->username(),
|
||||
];
|
||||
}
|
||||
|
@@ -181,6 +181,13 @@ class BlocksField extends FieldClass
|
||||
public function store($value)
|
||||
{
|
||||
$blocks = $this->blocksToValues((array)$value, 'content');
|
||||
|
||||
// returns empty string to avoid storing empty array as string `[]`
|
||||
// and to consistency work with `$field->isEmpty()`
|
||||
if (empty($blocks) === true) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->valueToJson($blocks, $this->pretty());
|
||||
}
|
||||
|
||||
|
@@ -146,6 +146,12 @@ class LayoutField extends BlocksField
|
||||
{
|
||||
$value = Layouts::factory($value, ['parent' => $this->model])->toArray();
|
||||
|
||||
// returns empty string to avoid storing empty array as string `[]`
|
||||
// and to consistency work with `$field->isEmpty()`
|
||||
if (empty($value) === true) {
|
||||
return '';
|
||||
}
|
||||
|
||||
foreach ($value as $layoutIndex => $layout) {
|
||||
if ($this->settings !== null) {
|
||||
$value[$layoutIndex]['attrs'] = $this->attrsForm($layout['attrs'])->content();
|
||||
|
@@ -7,6 +7,7 @@ use Kirby\Exception\Exception;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Http\Remote;
|
||||
use Kirby\Http\Url;
|
||||
use Kirby\Toolkit\Escape;
|
||||
use Kirby\Toolkit\Properties;
|
||||
use Kirby\Toolkit\Query;
|
||||
use Kirby\Toolkit\Str;
|
||||
@@ -86,10 +87,14 @@ class OptionsApi
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
protected function field(string $field, array $data)
|
||||
protected function field(string $field, array $data): string
|
||||
{
|
||||
$value = $this->$field();
|
||||
return Str::template($value, $data);
|
||||
return Str::template($value, $data, [
|
||||
'callback' => function ($result) {
|
||||
return Escape::html($result);
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -6,6 +6,7 @@ use Kirby\Cms\Field;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Exception\NotFoundException;
|
||||
use Kirby\Toolkit\Collection;
|
||||
use Kirby\Toolkit\Escape;
|
||||
use Kirby\Toolkit\Obj;
|
||||
use Kirby\Toolkit\Properties;
|
||||
use Kirby\Toolkit\Query;
|
||||
@@ -102,7 +103,26 @@ class OptionsQuery
|
||||
$value = $value[$object];
|
||||
}
|
||||
|
||||
return Str::template($value, $data);
|
||||
$result = Str::template($value, $data);
|
||||
|
||||
// escape the default queries for the `text` field
|
||||
// TODO: remove after default escape implemented for query templates in 3.6
|
||||
if ($field === 'text') {
|
||||
$defaults = [
|
||||
'arrayItem' => '{{ arrayItem.value }}',
|
||||
'block' => '{{ block.type }}: {{ block.id }}',
|
||||
'file' => '{{ file.filename }}',
|
||||
'page' => '{{ page.title }}',
|
||||
'structureItem' => '{{ structureItem.title }}',
|
||||
'user' => '{{ user.username }}',
|
||||
];
|
||||
|
||||
if (isset($defaults[$object]) && $value === $defaults[$object]) {
|
||||
$result = Escape::html($result);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -286,7 +286,7 @@ class Svg extends Xml
|
||||
'feTurbulence',
|
||||
];
|
||||
|
||||
protected static $allowedNamespaces = [
|
||||
public static $allowedNamespaces = [
|
||||
'xmlns' => 'http://www.w3.org/2000/svg',
|
||||
'xmlns:svg' => 'http://www.w3.org/2000/svg',
|
||||
'xmlns:xlink' => 'http://www.w3.org/1999/xlink'
|
||||
|
@@ -221,6 +221,7 @@ class Dir
|
||||
* @param string $dir The path for the new directory
|
||||
* @param bool $recursive Create all parent directories, which don't exist
|
||||
* @return bool True: the dir has been created, false: creating failed
|
||||
* @throws \Exception If a file with the provided path already exists or the parent directory is not writable
|
||||
*/
|
||||
public static function make(string $dir, bool $recursive = true): bool
|
||||
{
|
||||
@@ -232,6 +233,10 @@ class Dir
|
||||
return true;
|
||||
}
|
||||
|
||||
if (is_file($dir) === true) {
|
||||
throw new Exception(sprintf('A file with the name "%s" already exists', $dir));
|
||||
}
|
||||
|
||||
$parent = dirname($dir);
|
||||
|
||||
if ($recursive === true) {
|
||||
|
@@ -250,7 +250,7 @@ class Str
|
||||
*/
|
||||
public static function contains(string $string = null, string $needle, bool $caseInsensitive = false): bool
|
||||
{
|
||||
return call_user_func($caseInsensitive === true ? 'stristr' : 'strstr', $string, $needle) !== false;
|
||||
return call_user_func($caseInsensitive === true ? 'stripos' : 'strpos', $string, $needle) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -962,17 +962,32 @@ class Str
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @param string $string The string with placeholders
|
||||
* @param string|null $string The string with placeholders
|
||||
* @param array $data Associative array with placeholders as
|
||||
* keys and replacements as values
|
||||
* @param string $fallback A fallback if a token does not have any matches
|
||||
* @param string|array|null $fallback An options array that contains:
|
||||
* - fallback: if a token does not have any matches
|
||||
* - callback: to be able to handle each matching result
|
||||
* - start: start placeholder
|
||||
* - end: end placeholder
|
||||
* A simple fallback string is supported for compatibility (but deprecated).
|
||||
* @param string $start Placeholder start characters
|
||||
* @param string $end Placeholder end characters
|
||||
*
|
||||
* @todo Deprecate `string $fallback` and `$start`/`$end` arguments with warning in 3.6.0
|
||||
* @todo Remove `$start` and `$end` parameters, rename `$fallback` to `$options` and only support `array` type for `$options` in 3.7.0
|
||||
*
|
||||
* @return string The filled-in string
|
||||
*/
|
||||
public static function template(string $string = null, array $data = [], string $fallback = null, string $start = '{{', string $end = '}}'): string
|
||||
public static function template(string $string = null, array $data = [], $fallback = null, string $start = '{{', string $end = '}}'): string
|
||||
{
|
||||
return preg_replace_callback('!' . $start . '(.*?)' . $end . '!', function ($match) use ($data, $fallback) {
|
||||
$options = $fallback;
|
||||
$fallback = is_string($options) === true ? $options : ($options['fallback'] ?? null);
|
||||
$callback = is_a(($options['callback'] ?? null), 'Closure') === true ? $options['callback'] : null;
|
||||
$start = (string)($options['start'] ?? $start);
|
||||
$end = (string)($options['end'] ?? $end);
|
||||
|
||||
return preg_replace_callback('!' . $start . '(.*?)' . $end . '!', function ($match) use ($data, $fallback, $callback) {
|
||||
$query = trim($match[1]);
|
||||
|
||||
// if the placeholder contains a dot, it is a query
|
||||
@@ -991,6 +1006,11 @@ class Str
|
||||
$result = $fallback;
|
||||
}
|
||||
|
||||
// callback on result if given
|
||||
if ($callback !== null) {
|
||||
$result = $callback((string)$result, $query, $data);
|
||||
}
|
||||
|
||||
// if we still don't have a result, keep the original placeholder
|
||||
return $result ?? $match[0];
|
||||
}, $string);
|
||||
|
@@ -463,6 +463,12 @@ V::$validators = [
|
||||
* Checks that the value has the given size
|
||||
*/
|
||||
'size' => function ($value, $size, $operator = '=='): bool {
|
||||
// if value is field object, first convert it to a readable value
|
||||
// it is important to check at the beginning as the value can be string or numeric
|
||||
if (is_a($value, '\Kirby\Cms\Field') === true) {
|
||||
$value = $value->value();
|
||||
}
|
||||
|
||||
if (is_numeric($value) === true) {
|
||||
$count = $value;
|
||||
} elseif (is_string($value) === true) {
|
||||
|
Reference in New Issue
Block a user