Update to Kirby 5

This commit is contained in:
Paul Nicoué 2025-07-11 14:41:34 +02:00
parent 5d9979fca8
commit 0fefc5e2e1
472 changed files with 30853 additions and 10301 deletions

View file

@ -4,11 +4,15 @@ use Kirby\Cms\App;
use Kirby\Cms\Collection;
use Kirby\Cms\File;
use Kirby\Cms\FileVersion;
use Kirby\Cms\ModelWithContent;
use Kirby\Cms\Page;
use Kirby\Cms\User;
use Kirby\Content\PlainTextStorage;
use Kirby\Content\Storage;
use Kirby\Data\Data;
use Kirby\Email\PHPMailer as Emailer;
use Kirby\Exception\NotFoundException;
use Kirby\Filesystem\Asset;
use Kirby\Filesystem\F;
use Kirby\Filesystem\Filename;
use Kirby\Http\Uri;
@ -59,22 +63,20 @@ return [
/**
* Adapt file characteristics
*
* @param \Kirby\Cms\File|\Kirby\Filesystem\Asset $file The file object
* @param array $options All thumb options (width, height, crop, blur, grayscale)
* @return \Kirby\Cms\File|\Kirby\Cms\FileVersion|\Kirby\Filesystem\Asset
*/
'file::version' => function (
App $kirby,
$file,
File|Asset $file,
array $options = []
) {
): File|Asset|FileVersion {
// if file is not resizable, return
if ($file->isResizable() === false) {
return $file;
}
// create url and root
$mediaRoot = dirname($file->mediaRoot());
$mediaRoot = $file->mediaDir();
$template = $mediaRoot . '/{{ name }}{{ attributes }}.{{ extension }}';
$thumbRoot = (new Filename($file->root(), $template, $options))->toString();
$thumbName = basename($thumbRoot);
@ -85,9 +87,10 @@ return [
$job = $mediaRoot . '/.jobs/' . $thumbName . '.json';
try {
Data::write($job, array_merge($options, [
'filename' => $file->filename()
]));
Data::write(
$job,
[...$options, 'filename' => $file->filename()]
);
} catch (Throwable) {
// if thumb doesn't exist yet and job file cannot
// be created, return
@ -99,7 +102,7 @@ return [
'modifications' => $options,
'original' => $file,
'root' => $thumbRoot,
'url' => dirname($file->mediaUrl()) . '/' . $thumbName,
'url' => $file->mediaUrl($thumbName),
]);
},
@ -150,17 +153,16 @@ return [
$params = ['fields' => Str::split($params, '|')];
}
$defaults = [
$collection = clone $collection;
$query = trim($query ?? '');
$options = [
'fields' => [],
'minlength' => 2,
'score' => [],
'words' => false,
...$params
];
$collection = clone $collection;
$options = array_merge($defaults, $params);
$query = trim($query ?? '');
// empty or too short search query
if (Str::length($query) < $options['minlength']) {
return $collection->limit(0);
@ -204,10 +206,11 @@ return [
$keys[] = 'role';
} elseif ($item instanceof Page) {
// apply the default score for pages
$options['score'] = array_merge(
['id' => 64, 'title' => 64],
$options['score']
);
$options['score'] = [
'id' => 64,
'title' => 64,
...$options['score']
];
}
if (empty($options['fields']) === false) {
@ -231,7 +234,7 @@ return [
$scoring['score'] += 16 * $score;
$scoring['hits'] += 1;
// check for exact beginning matches
// check for exact beginning matches
} elseif (
$options['words'] === false &&
Str::startsWith($lowerValue, $query) === true
@ -239,7 +242,7 @@ return [
$scoring['score'] += 8 * $score;
$scoring['hits'] += 1;
// check for exact query matches
// check for exact query matches
} elseif ($matches = preg_match_all('!' . $exact . '!ui', $value, $r)) {
$scoring['score'] += 2 * $score;
$scoring['hits'] += $matches;
@ -309,6 +312,16 @@ return [
return Snippet::factory($name, $data, $slots);
},
/**
* Create a new storage object for the given model
*/
'storage' => function (
App $kirby,
ModelWithContent $model
): Storage {
return new PlainTextStorage(model: $model);
},
/**
* Add your own template engine
*
@ -332,7 +345,6 @@ return [
* @param string $src Root of the original file
* @param string $dst Template string for the root to the desired destination
* @param array $options All thumb options that should be applied: `width`, `height`, `crop`, `blur`, `grayscale`
* @return string
*/
'thumb' => function (
App $kirby,
@ -401,7 +413,7 @@ return [
// keep relative urls
if (
$path !== null &&
(substr($path, 0, 2) === './' || substr($path, 0, 3) === '../')
(str_starts_with($path, './') || str_starts_with($path, '../'))
) {
return $path;
}
@ -417,7 +429,9 @@ return [
$model = Uuid::for($path)->model();
if ($model === null) {
throw new NotFoundException('The model could not be found for "' . $path . '" uuid');
throw new NotFoundException(
message: 'The model could not be found for "' . $path . '" uuid'
);
}
$path = $model->url();