Update Composer packages

This commit is contained in:
Paul Nicoué 2023-04-14 16:30:28 +02:00
parent d482354bdf
commit e7e7361480
219 changed files with 6487 additions and 4444 deletions

View file

@ -53,6 +53,10 @@ return [
// panel classes
'panel' => 'Kirby\Panel\Panel',
// template classes
'snippet' => 'Kirby\Template\Snippet',
'slot' => 'Kirby\Template\Slot',
// toolkit classes
'a' => 'Kirby\Toolkit\A',
'c' => 'Kirby\Toolkit\Config',
@ -73,6 +77,7 @@ return [
'kirby\cms\form' => 'Kirby\Form\Form',
'kirby\cms\kirbytag' => 'Kirby\Text\KirbyTag',
'kirby\cms\kirbytags' => 'Kirby\Text\KirbyTags',
'kirby\cms\template' => 'Kirby\Template\Template',
'kirby\toolkit\dir' => 'Kirby\Filesystem\Dir',
'kirby\toolkit\f' => 'Kirby\Filesystem\F',
'kirby\toolkit\file' => 'Kirby\Filesystem\File',

View file

@ -35,8 +35,9 @@ return [
$code = $this->user()?->language() ??
$this->kirby()->panelLanguage();
return $this->kirby()->translation($code) ??
$this->kirby()->translation('en');
return
$this->kirby()->translation($code) ??
$this->kirby()->translation('en');
},
'kirbytext' => fn () => $this->kirby()->option('panel.kirbytext') ?? true,
'user' => fn () => $this->user(),

View file

@ -38,14 +38,17 @@ return [
// move_uploaded_file() not working with unit test
// @codeCoverageIgnoreStart
return $this->upload(function ($source, $filename) use ($path) {
return $this->parent($path)->createFile([
$props = [
'content' => [
'sort' => $this->requestBody('sort')
],
'source' => $source,
'template' => $this->requestBody('template'),
'filename' => $filename
]);
];
// move the source file from the temp dir
return $this->parent($path)->createFile($props, true);
});
// @codeCoverageIgnoreEnd
}
@ -95,8 +98,9 @@ return [
'pattern' => $pattern . '/files/(:any)',
'method' => 'POST',
'action' => function (string $path, string $filename) {
// move the source file from the temp dir
return $this->upload(
fn ($source) => $this->file($path, $filename)->replace($source)
fn ($source) => $this->file($path, $filename)->replace($source, true)
);
}
],

View file

@ -4,6 +4,9 @@
/**
* Content Lock Routes
*/
use Kirby\Exception\NotFoundException;
return [
[
'pattern' => '(:all)/lock',
@ -25,7 +28,11 @@ return [
'pattern' => '(:all)/lock',
'method' => 'DELETE',
'action' => function (string $path) {
return $this->parent($path)->lock()?->remove();
try {
return $this->parent($path)->lock()?->remove();
} catch (NotFoundException) {
return true;
}
}
],
[
@ -39,7 +46,11 @@ return [
'pattern' => '(:all)/unlock',
'method' => 'DELETE',
'action' => function (string $path) {
return $this->parent($path)->lock()?->resolve();
try {
return $this->parent($path)->lock()?->resolve();
} catch (NotFoundException) {
return true;
}
}
],
];

View file

@ -82,11 +82,16 @@ return [
$this->user($id)->avatar()?->delete();
return $this->upload(
fn ($source, $filename) => $this->user($id)->createFile([
'filename' => 'profile.' . F::extension($filename),
'template' => 'avatar',
'source' => $source
]),
function ($source, $filename) use ($id) {
$props = [
'filename' => 'profile.' . F::extension($filename),
'template' => 'avatar',
'source' => $source
];
// move the source file from the temp dir
return $this->user($id)->createFile($props, true);
},
single: true
);
}

View file

@ -44,10 +44,17 @@ return [
// license registration
'registration' => [
'load' => function () {
$system = App::instance()->system();
return [
'component' => 'k-form-dialog',
'props' => [
'fields' => [
'domain' => [
'type' => 'info',
'theme' => $system->isLocal() ? 'notice' : 'info',
'text' => I18n::template('license.register.' . ($system->isLocal() ? 'local' : 'domain'), ['host' => $system->indexUrl()])
],
'license' => [
'label' => I18n::translate('license.register.label'),
'type' => 'text',
@ -56,9 +63,7 @@ return [
'placeholder' => 'K3-',
'help' => I18n::translate('license.register.help')
],
'email' => Field::email([
'required' => true
])
'email' => Field::email(['required' => true])
],
'submitButton' => I18n::translate('license.register'),
'value' => [

View file

@ -5,7 +5,6 @@ use Kirby\Cms\Collection;
use Kirby\Cms\File;
use Kirby\Cms\FileVersion;
use Kirby\Cms\Page;
use Kirby\Cms\Template;
use Kirby\Cms\User;
use Kirby\Data\Data;
use Kirby\Email\PHPMailer as Emailer;
@ -14,11 +13,12 @@ use Kirby\Filesystem\Filename;
use Kirby\Http\Uri;
use Kirby\Http\Url;
use Kirby\Image\Darkroom;
use Kirby\Template\Snippet;
use Kirby\Template\Template;
use Kirby\Text\Markdown;
use Kirby\Text\SmartyPants;
use Kirby\Toolkit\A;
use Kirby\Toolkit\Str;
use Kirby\Toolkit\Tpl as Snippet;
return [
@ -142,6 +142,7 @@ return [
* @return \Kirby\Cms\Collection|bool
*/
'search' => function (App $kirby, Collection $collection, string $query = null, $params = []) {
// empty search query
if (empty(trim($query ?? '')) === true) {
return $collection->limit(0);
}
@ -159,28 +160,31 @@ return [
$options = array_merge($defaults, $params);
$collection = clone $collection;
$searchWords = preg_replace('/(\s)/u', ',', $query);
$searchWords = Str::split($searchWords, ',', $options['minlength']);
$lowerQuery = Str::lower($query);
$exactQuery = $options['words'] ? '(\b' . preg_quote($query) . '\b)' : preg_quote($query);
$words = preg_replace('/(\s)/u', ',', $query);
$words = Str::split($words, ',', $options['minlength']);
$exact = $options['words'] ? '(\b' . preg_quote($query) . '\b)' : preg_quote($query);
$query = Str::lower($query);
if (empty($options['stopwords']) === false) {
$searchWords = array_diff($searchWords, $options['stopwords']);
$words = array_diff($words, $options['stopwords']);
}
$searchWords = array_map(function ($value) use ($options) {
return $options['words'] ? '\b' . preg_quote($value) . '\b' : preg_quote($value);
}, $searchWords);
$words = A::map(
$words,
fn ($value) => $options['words'] ? '\b' . preg_quote($value) . '\b' : preg_quote($value)
);
// returns an empty collection if there is no search word
if (empty($searchWords) === true) {
if (empty($words) === true) {
return $collection->limit(0);
}
$preg = '!(' . implode('|', $searchWords) . ')!i';
$results = $collection->filter(function ($item) use ($query, $preg, $options, $lowerQuery, $exactQuery) {
$data = $item->content()->toArray();
$keys = array_keys($data);
$preg = '!(' . implode('|', $words) . ')!i';
$scores = [];
$results = $collection->filter(function ($item) use ($query, $exact, $preg, $options, &$scores) {
$data = $item->content()->toArray();
$keys = array_keys($data);
$keys[] = 'id';
if ($item instanceof User) {
@ -200,8 +204,10 @@ return [
$keys = array_intersect($keys, $fields);
}
$item->searchHits = 0;
$item->searchScore = 0;
$scoring = [
'hits' => 0,
'score' => 0
];
foreach ($keys as $key) {
$score = $options['score'][$key] ?? 1;
@ -210,32 +216,39 @@ return [
$lowerValue = Str::lower($value);
// check for exact matches
if ($lowerQuery == $lowerValue) {
$item->searchScore += 16 * $score;
$item->searchHits += 1;
if ($query == $lowerValue) {
$scoring['score'] += 16 * $score;
$scoring['hits'] += 1;
// check for exact beginning matches
} elseif ($options['words'] === false && Str::startsWith($lowerValue, $lowerQuery) === true) {
$item->searchScore += 8 * $score;
$item->searchHits += 1;
} elseif (
$options['words'] === false &&
Str::startsWith($lowerValue, $query) === true
) {
$scoring['score'] += 8 * $score;
$scoring['hits'] += 1;
// check for exact query matches
} elseif ($matches = preg_match_all('!' . $exactQuery . '!i', $value, $r)) {
$item->searchScore += 2 * $score;
$item->searchHits += $matches;
} elseif ($matches = preg_match_all('!' . $exact . '!i', $value, $r)) {
$scoring['score'] += 2 * $score;
$scoring['hits'] += $matches;
}
// check for any match
if ($matches = preg_match_all($preg, $value, $r)) {
$item->searchHits += $matches;
$item->searchScore += $matches * $score;
$scoring['score'] += $matches * $score;
$scoring['hits'] += $matches;
}
}
return $item->searchHits > 0;
$scores[$item->id()] = $scoring;
return $scoring['hits'] > 0;
});
return $results->sort('searchScore', 'desc');
return $results->sort(
fn ($item) => $scores[$item->id()]['score'],
'desc'
);
},
/**
@ -267,23 +280,8 @@ return [
* @param string|array $name Snippet name
* @param array $data Data array for the snippet
*/
'snippet' => function (App $kirby, $name, array $data = []): string {
$snippets = A::wrap($name);
foreach ($snippets as $name) {
$name = (string)$name;
$file = $kirby->root('snippets') . '/' . $name . '.php';
if (file_exists($file) === false) {
$file = $kirby->extensions('snippets')[$name] ?? null;
}
if ($file) {
break;
}
}
return Snippet::load($file, $data);
'snippet' => function (App $kirby, string|array|null $name, array $data = [], bool $slots = false): Snippet|string {
return Snippet::factory($name, $data, $slots);
},
/**
@ -293,7 +291,7 @@ return [
* @param string $name Template name
* @param string $type Extension type
* @param string $defaultType Default extension type
* @return \Kirby\Cms\Template
* @return \Kirby\Template\Template
*/
'template' => function (App $kirby, string $name, string $type = 'html', string $defaultType = 'html') {
return new Template($name, $type, $defaultType);

View file

@ -56,11 +56,14 @@ return [
}
return $api->upload(function ($source, $filename) use ($parent, $params, $map) {
$file = $parent->createFile([
$props = [
'source' => $source,
'template' => $params['template'] ?? null,
'filename' => $filename,
]);
];
// move the source file from the temp dir
$file = $parent->createFile($props, true);
if ($file instanceof File === false) {
throw new Exception('The file could not be uploaded');

View file

@ -1,5 +1,7 @@
<?php
use Kirby\Field\FieldOptions;
return [
'extends' => 'radio',
'props' => [
@ -20,5 +22,16 @@ return [
'placeholder' => function (string $placeholder = '—') {
return $placeholder;
},
],
'methods' => [
'getOptions' => function () {
$props = FieldOptions::polyfill($this->props);
// disable safe mode as the select field does not
// render HTML for the option text
$options = FieldOptions::factory($props['options'], false);
return $options->render($this->model());
}
]
];

View file

@ -10,7 +10,7 @@ return [
* The field value will be converted with the selected converter before the value gets saved. Available converters: `lower`, `upper`, `ucfirst`, `slug`
*/
'converter' => function ($value = null) {
if ($value !== null && in_array($value, array_keys($this->converters())) === false) {
if ($value !== null && array_key_exists($value, $this->converters()) === false) {
throw new InvalidArgumentException([
'key' => 'field.converter.invalid',
'data' => ['converter' => $value]

View file

@ -1,13 +1,20 @@
<?php
use Kirby\Cms\App;
use Kirby\Cms\Collection;
use Kirby\Cms\File;
use Kirby\Cms\Helpers;
use Kirby\Cms\Html;
use Kirby\Cms\Page;
use Kirby\Cms\Pages;
use Kirby\Cms\Response;
use Kirby\Cms\Site;
use Kirby\Cms\Url;
use Kirby\Filesystem\Asset;
use Kirby\Filesystem\F;
use Kirby\Http\Router;
use Kirby\Template\Slot;
use Kirby\Template\Snippet;
use Kirby\Toolkit\Date;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Str;
@ -16,11 +23,8 @@ use Kirby\Toolkit\V;
if (Helpers::hasOverride('asset') === false) { // @codeCoverageIgnore
/**
* Helper to create an asset object
*
* @param string $path
* @return \Kirby\Filesystem\Asset
*/
function asset(string $path)
function asset(string $path): Asset
{
return new Asset($path);
}
@ -33,10 +37,12 @@ if (Helpers::hasOverride('attr') === false) { // @codeCoverageIgnore
* @param array|null $attr A list of attributes as key/value array
* @param string|null $before An optional string that will be prepended if the result is not empty
* @param string|null $after An optional string that will be appended if the result is not empty
* @return string|null
*/
function attr(array|null $attr = null, string|null $before = null, string|null $after = null): string|null
{
function attr(
array|null $attr = null,
string|null $before = null,
string|null $after = null
): string|null {
return Html::attr($attr, null, $before, $after);
}
}
@ -44,11 +50,8 @@ if (Helpers::hasOverride('attr') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('collection') === false) { // @codeCoverageIgnore
/**
* Returns the result of a collection by name
*
* @param string $name
* @return \Kirby\Cms\Collection|null
*/
function collection(string $name)
function collection(string $name): Collection|null
{
return App::instance()->collection($name);
}
@ -61,7 +64,7 @@ if (Helpers::hasOverride('csrf') === false) { // @codeCoverageIgnore
* @param string|null $check Pass a token here to compare it to the one in the session
* @return string|bool Either the token or a boolean check result
*/
function csrf(string|null $check = null)
function csrf(string|null $check = null): string|bool
{
// check explicitly if there have been no arguments at all;
// checking for null introduces a security issue because null could come
@ -79,11 +82,12 @@ if (Helpers::hasOverride('css') === false) { // @codeCoverageIgnore
* Creates one or multiple CSS link tags
*
* @param string|array $url Relative or absolute URLs, an array of URLs or `@auto` for automatic template css loading
* @param string|array $options Pass an array of attributes for the link tag or a media attribute string
* @return string|null
* @param string|array|null $options Pass an array of attributes for the link tag or a media attribute string
*/
function css($url, $options = null): string|null
{
function css(
string|array $url,
string|array|null $options = null
): string|null {
return Html::css($url, $options);
}
}
@ -93,7 +97,6 @@ if (Helpers::hasOverride('deprecated') === false) { // @codeCoverageIgnore
* Triggers a deprecation warning if debug mode is active
* @since 3.3.0
*
* @param string $message
* @return bool Whether the warning was triggered
*/
function deprecated(string $message): bool
@ -106,12 +109,8 @@ if (Helpers::hasOverride('dump') === false) { // @codeCoverageIgnore
/**
* Simple object and variable dumper
* to help with debugging.
*
* @param mixed $variable
* @param bool $echo
* @return string
*/
function dump($variable, bool $echo = true): string
function dump(mixed $variable, bool $echo = true): string
{
return Helpers::dump($variable, $echo);
}
@ -121,16 +120,35 @@ if (Helpers::hasOverride('e') === false) { // @codeCoverageIgnore
/**
* Smart version of echo with an if condition as first argument
*
* @param mixed $condition
* @param mixed $value The string to be echoed if the condition is true
* @param mixed $alternative An alternative string which should be echoed when the condition is false
*/
function e($condition, $value, $alternative = null)
function e(mixed $condition, mixed $value, mixed $alternative = null): void
{
echo $condition ? $value : $alternative;
}
}
if (Helpers::hasOverride('endslot') === false) { // @codeCoverageIgnore
/**
* Ends the last started template slot
*/
function endslot(): void
{
Slot::end();
}
}
if (Helpers::hasOverride('endsnippet') === false) { // @codeCoverageIgnore
/**
* Renders the currently active snippet with slots
*/
function endsnippet(): void
{
Snippet::end();
}
}
if (Helpers::hasOverride('esc') === false) { // @codeCoverageIgnore
/**
* Escape context specific output
@ -151,9 +169,8 @@ if (Helpers::hasOverride('get') === false) { // @codeCoverageIgnore
*
* @param mixed $key The key to look for. Pass false or null to return the entire request array.
* @param mixed $default Optional default value, which should be returned if no element has been found
* @return mixed
*/
function get($key = null, $default = null)
function get(mixed $key = null, mixed $default = null): mixed
{
return App::instance()->request()->get($key, $default);
}
@ -162,10 +179,6 @@ if (Helpers::hasOverride('get') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('gist') === false) { // @codeCoverageIgnore
/**
* Embeds a Github Gist
*
* @param string $url
* @param string|null $file
* @return string
*/
function gist(string $url, string|null $file = null): string
{
@ -181,11 +194,9 @@ if (Helpers::hasOverride('go') === false) { // @codeCoverageIgnore
* Redirects to the given Urls
* Urls can be relative or absolute.
*
* @param string $url
* @param int $code
* @return void
* @todo Change return type to `never` once support for PHP 8.0 is dropped
*/
function go(string $url = '/', int $code = 302)
function go(string $url = '/', int $code = 302): void
{
Response::go($url, $code);
}
@ -196,8 +207,6 @@ if (Helpers::hasOverride('h') === false) { // @codeCoverageIgnore
* Shortcut for html()
*
* @param string|null $string unencoded text
* @param bool $keepTags
* @return string
*/
function h(string|null $string, bool $keepTags = false): string
{
@ -210,8 +219,6 @@ if (Helpers::hasOverride('html') === false) { // @codeCoverageIgnore
* Creates safe html by encoding special characters
*
* @param string|null $string unencoded text
* @param bool $keepTags
* @return string
*/
function html(string|null $string, bool $keepTags = false): string
{
@ -226,11 +233,8 @@ if (Helpers::hasOverride('image') === false) { // @codeCoverageIgnore
*
* Example:
* <?= image('some/page/myimage.jpg') ?>
*
* @param string|null $path
* @return \Kirby\Cms\File|null
*/
function image(string|null $path = null)
function image(string|null $path = null): File|null
{
return App::instance()->image($path);
}
@ -239,14 +243,12 @@ if (Helpers::hasOverride('image') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('invalid') === false) { // @codeCoverageIgnore
/**
* Runs a number of validators on a set of data and checks if the data is invalid
*
* @param array $data
* @param array $rules
* @param array $messages
* @return array
*/
function invalid(array $data = [], array $rules = [], array $messages = []): array
{
function invalid(
array $data = [],
array $rules = [],
array $messages = []
): array {
return V::invalid($data, $rules, $messages);
}
}
@ -254,13 +256,11 @@ if (Helpers::hasOverride('invalid') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('js') === false) { // @codeCoverageIgnore
/**
* Creates a script tag to load a javascript file
*
* @param string|array $url
* @param string|array $options
* @return string|null
*/
function js($url, $options = null): string|null
{
function js(
string|array $url,
string|array|bool|null $options = null
): string|null {
return Html::js($url, $options);
}
}
@ -268,10 +268,8 @@ if (Helpers::hasOverride('js') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('kirby') === false) { // @codeCoverageIgnore
/**
* Returns the Kirby object in any situation
*
* @return \Kirby\Cms\App
*/
function kirby()
function kirby(): App
{
return App::instance();
}
@ -280,15 +278,13 @@ if (Helpers::hasOverride('kirby') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('kirbytag') === false) { // @codeCoverageIgnore
/**
* Makes it possible to use any defined Kirbytag as standalone function
*
* @param string|array $type
* @param string|null $value
* @param array $attr
* @param array $data
* @return string
*/
function kirbytag($type, string|null $value = null, array $attr = [], array $data = []): string
{
function kirbytag(
string|array $type,
string|null $value = null,
array $attr = [],
array $data = []
): string {
return App::instance()->kirbytag($type, $value, $attr, $data);
}
}
@ -297,10 +293,6 @@ if (Helpers::hasOverride('kirbytags') === false) { // @codeCoverageIgnore
/**
* Parses KirbyTags in the given string. Shortcut
* for `$kirby->kirbytags($text, $data)`
*
* @param string|null $text
* @param array $data
* @return string
*/
function kirbytags(string|null $text = null, array $data = []): string
{
@ -312,10 +304,6 @@ if (Helpers::hasOverride('kirbytext') === false) { // @codeCoverageIgnore
/**
* Parses KirbyTags and Markdown in the
* given string. Shortcut for `$kirby->kirbytext()`
*
* @param string|null $text
* @param array $data
* @return string
*/
function kirbytext(string|null $text = null, array $data = []): string
{
@ -328,10 +316,6 @@ if (Helpers::hasOverride('kirbytextinline') === false) { // @codeCoverageIgnore
* Parses KirbyTags and inline Markdown in the
* given string.
* @since 3.1.0
*
* @param string|null $text
* @param array $options
* @return string
*/
function kirbytextinline(string|null $text = null, array $options = []): string
{
@ -343,10 +327,6 @@ if (Helpers::hasOverride('kirbytextinline') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('kt') === false) { // @codeCoverageIgnore
/**
* Shortcut for `kirbytext()` helper
*
* @param string|null $text
* @param array $data
* @return string
*/
function kt(string|null $text = null, array $data = []): string
{
@ -358,10 +338,6 @@ if (Helpers::hasOverride('kti') === false) { // @codeCoverageIgnore
/**
* Shortcut for `kirbytextinline()` helper
* @since 3.1.0
*
* @param string|null $text
* @param array $options
* @return string
*/
function kti(string|null $text = null, array $options = []): string
{
@ -373,10 +349,6 @@ if (Helpers::hasOverride('kti') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('load') === false) { // @codeCoverageIgnore
/**
* A super simple class autoloader
*
* @param array $classmap
* @param string|null $base
* @return void
*/
function load(array $classmap, string|null $base = null): void
{
@ -388,10 +360,6 @@ if (Helpers::hasOverride('markdown') === false) { // @codeCoverageIgnore
/**
* Parses markdown in the given string. Shortcut for
* `$kirby->markdown($text)`
*
* @param string|null $text
* @param array $options
* @return string
*/
function markdown(string|null $text = null, array $options = []): string
{
@ -402,12 +370,8 @@ if (Helpers::hasOverride('markdown') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('option') === false) { // @codeCoverageIgnore
/**
* Shortcut for `$kirby->option($key, $default)`
*
* @param string $key
* @param mixed $default
* @return mixed
*/
function option(string $key, $default = null)
function option(string $key, mixed $default = null): mixed
{
return App::instance()->option($key, $default);
}
@ -417,11 +381,8 @@ if (Helpers::hasOverride('page') === false) { // @codeCoverageIgnore
/**
* Fetches a single page by id or
* the current page when no id is specified
*
* @param string|null $id
* @return \Kirby\Cms\Page|null
*/
function page(string|null $id = null)
function page(string|null $id = null): Page|null
{
if (empty($id) === true) {
return App::instance()->site()->page();
@ -434,11 +395,8 @@ if (Helpers::hasOverride('page') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('pages') === false) { // @codeCoverageIgnore
/**
* Helper to build pages collection
*
* @param string|array ...$id
* @return \Kirby\Cms\Pages|null
*/
function pages(...$id)
function pages(string|array ...$id): Pages|null
{
// ensure that a list of string arguments and an array
// as the first argument are treated the same
@ -456,9 +414,6 @@ if (Helpers::hasOverride('param') === false) { // @codeCoverageIgnore
/**
* Returns a single param from the URL
*
* @param string $key
* @param string|null $fallback
* @return string|null
* @psalm-return ($fallback is string ? string : string|null)
*/
function param(string $key, string|null $fallback = null): string|null
@ -470,8 +425,6 @@ if (Helpers::hasOverride('param') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('params') === false) { // @codeCoverageIgnore
/**
* Returns all params from the current Url
*
* @return array
*/
function params(): array
{
@ -483,12 +436,10 @@ if (Helpers::hasOverride('r') === false) { // @codeCoverageIgnore
/**
* Smart version of return with an if condition as first argument
*
* @param mixed $condition
* @param mixed $value The string to be returned if the condition is true
* @param mixed $alternative An alternative string which should be returned when the condition is false
* @return mixed
*/
function r($condition, $value, $alternative = null)
function r(mixed $condition, mixed $value, mixed $alternative = null): mixed
{
return $condition ? $value : $alternative;
}
@ -499,15 +450,13 @@ if (Helpers::hasOverride('router') === false) { // @codeCoverageIgnore
* Creates a micro-router and executes
* the routing action immediately
* @since 3.6.0
*
* @param string|null $path
* @param string $method
* @param array $routes
* @param \Closure|null $callback
* @return mixed
*/
function router(string|null $path = null, string $method = 'GET', array $routes = [], Closure|null $callback = null)
{
function router(
string|null $path = null,
string $method = 'GET',
array $routes = [],
Closure|null $callback = null
): mixed {
return Router::execute($path, $method, $routes, $callback);
}
}
@ -515,10 +464,8 @@ if (Helpers::hasOverride('router') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('site') === false) { // @codeCoverageIgnore
/**
* Returns the current site object
*
* @return \Kirby\Cms\Site
*/
function site()
function site(): Site
{
return App::instance()->site();
}
@ -527,24 +474,27 @@ if (Helpers::hasOverride('site') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('size') === false) { // @codeCoverageIgnore
/**
* Determines the size/length of numbers, strings, arrays and countable objects
*
* @param mixed $value
* @return int
* @throws \Kirby\Exception\InvalidArgumentException
*/
function size($value): int
function size(mixed $value): int
{
return Helpers::size($value);
}
}
if (Helpers::hasOverride('slot') === false) { // @codeCoverageIgnore
/**
* Starts a new template slot
*/
function slot(string $name = 'default'): void
{
Slot::begin($name);
}
}
if (Helpers::hasOverride('smartypants') === false) { // @codeCoverageIgnore
/**
* Enhances the given string with
* smartypants. Shortcut for `$kirby->smartypants($text)`
*
* @param string|null $text
* @return string
*/
function smartypants(string|null $text = null): string
{
@ -555,15 +505,14 @@ if (Helpers::hasOverride('smartypants') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('snippet') === false) { // @codeCoverageIgnore
/**
* Embeds a snippet from the snippet folder
*
* @param string|array $name
* @param array|object $data
* @param bool $return
* @return string|null
*/
function snippet($name, $data = [], bool $return = false): string|null
{
return App::instance()->snippet($name, $data, $return);
function snippet(
$name,
$data = [],
bool $return = false,
bool $slots = false
): Snippet|string|null {
return App::instance()->snippet($name, $data, $return, $slots);
}
}
@ -571,11 +520,8 @@ if (Helpers::hasOverride('svg') === false) { // @codeCoverageIgnore
/**
* Includes an SVG file by absolute or
* relative file path.
*
* @param string|\Kirby\Cms\File $file
* @return string|false
*/
function svg($file)
function svg(string|File $file): string|false
{
return Html::svg($file);
}
@ -584,14 +530,12 @@ if (Helpers::hasOverride('svg') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('t') === false) { // @codeCoverageIgnore
/**
* Returns translate string for key from translation file
*
* @param string|array $key
* @param string|null $fallback
* @param string|null $locale
* @return array|string|null
*/
function t($key, string $fallback = null, string $locale = null)
{
function t(
string|array $key,
string|null $fallback = null,
string|null $locale = null
): string|array|Closure|null {
return I18n::translate($key, $fallback, $locale);
}
}
@ -600,18 +544,14 @@ if (Helpers::hasOverride('tc') === false) { // @codeCoverageIgnore
/**
* Translates a count
*
* @param string $key
* @param int $count
* @param string|null $locale
* @param bool $formatNumber If set to `false`, the count is not formatted
* @return mixed
*/
function tc(
string $key,
int $count,
string $locale = null,
string|null $locale = null,
bool $formatNumber = true
) {
): mixed {
return I18n::translateCount($key, $count, $locale, $formatNumber);
}
}
@ -621,12 +561,12 @@ if (Helpers::hasOverride('timestamp') === false) { // @codeCoverageIgnore
* Rounds the minutes of the given date
* by the defined step
*
* @param string|null $date
* @param int|array|null $step array of `unit` and `size` to round to nearest
* @return int|null
*/
function timestamp(string|null $date = null, $step = null): int|null
{
function timestamp(
string|null $date = null,
int|array|null $step = null
): int|null {
return Date::roundedTimestamp($date, $step);
}
}
@ -635,15 +575,13 @@ if (Helpers::hasOverride('tt') === false) { // @codeCoverageIgnore
/**
* Translate by key and then replace
* placeholders in the text
*
* @param string $key
* @param string|array|null $fallback
* @param array|null $replace
* @param string|null $locale
* @return string
*/
function tt(string $key, $fallback = null, array|null $replace = null, string|null $locale = null): string
{
function tt(
string $key,
string|array|null $fallback = null,
array|null $replace = null,
string|null $locale = null
): string {
return I18n::template($key, $fallback, $replace, $locale);
}
}
@ -651,15 +589,13 @@ if (Helpers::hasOverride('tt') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('twitter') === false) { // @codeCoverageIgnore
/**
* Builds a Twitter link
*
* @param string $username
* @param string|null $text
* @param string|null $title
* @param string|null $class
* @return string
*/
function twitter(string $username, string|null $text = null, string|null $title = null, string|null $class = null): string
{
function twitter(
string $username,
string|null $text = null,
string|null $title = null,
string|null $class = null
): string {
return App::instance()->kirbytag([
'twitter' => $username,
'text' => $text,
@ -672,13 +608,11 @@ if (Helpers::hasOverride('twitter') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('u') === false) { // @codeCoverageIgnore
/**
* Shortcut for url()
*
* @param string|null $path
* @param array|string|null $options
* @return string
*/
function u(string|null $path = null, $options = null): string
{
function u(
string|null $path = null,
array|string|null $options = null
): string {
return Url::to($path, $options);
}
}
@ -686,13 +620,11 @@ if (Helpers::hasOverride('u') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('url') === false) { // @codeCoverageIgnore
/**
* Builds an absolute URL for a given path
*
* @param string|null $path
* @param array|string|null $options
* @return string
*/
function url(string|null $path = null, $options = null): string
{
function url(
string|null $path = null,
array|string|null $options = null
): string {
return Url::to($path, $options);
}
}
@ -700,8 +632,6 @@ if (Helpers::hasOverride('url') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('uuid') === false) { // @codeCoverageIgnore
/**
* Creates a compliant v4 UUID
*
* @return string
*/
function uuid(): string
{
@ -714,11 +644,6 @@ if (Helpers::hasOverride('video') === false) { // @codeCoverageIgnore
* Creates a video embed via iframe for Youtube or Vimeo
* videos. The embed Urls are automatically detected from
* the given Url.
*
* @param string $url
* @param array $options
* @param array $attr
* @return string|null
*/
function video(string $url, array $options = [], array $attr = []): string|null
{
@ -729,11 +654,6 @@ if (Helpers::hasOverride('video') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('vimeo') === false) { // @codeCoverageIgnore
/**
* Embeds a Vimeo video by URL in an iframe
*
* @param string $url
* @param array $options
* @param array $attr
* @return string|null
*/
function vimeo(string $url, array $options = [], array $attr = []): string|null
{
@ -746,11 +666,8 @@ if (Helpers::hasOverride('widont') === false) { // @codeCoverageIgnore
* The widont function makes sure that there are no
* typographical widows at the end of a paragraph
* that's a single word in the last line
*
* @param string|null $string
* @return string
*/
function widont(string $string = null): string
function widont(string|null $string = null): string
{
return Str::widont($string);
}
@ -759,11 +676,6 @@ if (Helpers::hasOverride('widont') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('youtube') === false) { // @codeCoverageIgnore
/**
* Embeds a Youtube video by URL in an iframe
*
* @param string $url
* @param array $options
* @param array $attr
* @return string|null
*/
function youtube(string $url, array $options = [], array $attr = []): string|null
{

View file

@ -66,7 +66,8 @@ return function (App $app) {
try {
$blocks = Blocks::parse($field->value());
$blocks = Blocks::factory($blocks, [
'parent' => $field->parent()
'parent' => $field->parent(),
'field' => $field,
]);
return $blocks->filter('isHidden', false);
} catch (Throwable) {
@ -192,7 +193,8 @@ return function (App $app) {
*/
'toLayouts' => function (Field $field) {
return Layouts::factory(Layouts::parse($field->value()), [
'parent' => $field->parent()
'parent' => $field->parent(),
'field' => $field,
]);
},
@ -276,10 +278,10 @@ return function (App $app) {
* Converts the field value to a Unix timestamp
*
* @param \Kirby\Cms\Field $field
* @return int
* @return int|false
*/
'toTimestamp' => function (Field $field): int {
return strtotime($field->value);
'toTimestamp' => function (Field $field): int|false {
return strtotime($field->value ?? '');
},
/**
@ -326,7 +328,7 @@ return function (App $app) {
* Returns the number of words in the text
*/
'words' => function (Field $field) {
return str_word_count(strip_tags($field->value));
return str_word_count(strip_tags($field->value ?? ''));
},
// manipulators
@ -394,7 +396,7 @@ return function (App $app) {
// Obsolete elements, script tags, image maps and form elements have
// been excluded for safety reasons and as they are most likely not
// needed in most cases.
$field->value = strip_tags($field->value, Html::$inlineList);
$field->value = strip_tags($field->value ?? '', Html::$inlineList);
return $field;
},
@ -481,7 +483,7 @@ return function (App $app) {
* @return \Kirby\Cms\Field
*/
'nl2br' => function (Field $field) {
$field->value = nl2br($field->value, false);
$field->value = nl2br($field->value ?? '', false);
return $field;
},

View file

@ -57,6 +57,11 @@ return [
// search
if ($this->search === true && empty($this->searchterm()) === false) {
$files = $files->search($this->searchterm());
// disable flip and sortBy while searching
// to show most relevant results
$this->flip = false;
$this->sortBy = null;
}
// sort
@ -157,10 +162,9 @@ return [
}
// count all uploaded files
$total = count($this->data);
$max = $this->max ? $this->max - $total : null;
$max = $this->max ? $this->max - $this->total : null;
if ($this->max && $total === $this->max - 1) {
if ($this->max && $this->total === $this->max - 1) {
$multiple = false;
} else {
$multiple = true;
@ -174,7 +178,10 @@ return [
'max' => $max,
'api' => $this->parent->apiUrl(true) . '/files',
'attributes' => array_filter([
'sort' => $this->sortable === true ? $total + 1 : null,
// TODO: an edge issue that needs to be solved:
// if multiple users load the same section at the same time
// and upload a file, uploaded files have the same sort number
'sort' => $this->sortable === true ? $this->total + 1 : null,
'template' => $template
])
];

View file

@ -94,6 +94,11 @@ return [
// search
if ($this->search === true && empty($this->searchterm()) === false) {
$pages = $pages->search($this->searchterm());
// disable flip and sortBy while searching
// to show most relevant results
$this->flip = false;
$this->sortBy = null;
}
// sort