Upgrade to 3.6.2

This commit is contained in:
Bastian Allgeier
2022-02-01 11:42:39 +01:00
parent f62d1a39ca
commit 848ea36dcf
108 changed files with 2887 additions and 2622 deletions

View File

@@ -771,10 +771,11 @@ class App
*/
public function kirbytags(string $text = null, array $data = []): string
{
$data['kirby'] = $data['kirby'] ?? $this;
$data['site'] = $data['site'] ?? $data['kirby']->site();
$data['parent'] = $data['parent'] ?? $data['site']->page();
$options = $this->options;
$data['kirby'] ??= $this;
$data['site'] ??= $data['kirby']->site();
$data['parent'] ??= $data['site']->page();
$options = $this->options;
$text = $this->apply('kirbytags:before', compact('text', 'data', 'options'), 'text');
$text = KirbyTags::parse($text, $data, $options);
@@ -789,14 +790,23 @@ class App
* @internal
* @param string|null $text
* @param array $data
* @param bool $inline
* @param bool $inline (deprecated: use $data['markdown']['inline'] instead)
* @return string
* @todo add deprecation warning for $inline parameter in 3.7.0
* @todo rename $data parameter to $options in 3.7.0
* @todo remove $inline parameter in in 3.8.0
*/
public function kirbytext(string $text = null, array $data = [], bool $inline = false): string
{
$options = A::merge([
'markdown' => [
'inline' => $inline
]
], $data);
$text = $this->apply('kirbytext:before', compact('text'), 'text');
$text = $this->kirbytags($text, $data);
$text = $this->markdown($text, $inline);
$text = $this->kirbytags($text, $options);
$text = $this->markdown($text, $options['markdown']);
if ($this->option('smartypants', false) !== false) {
$text = $this->smartypants($text);
@@ -890,12 +900,31 @@ class App
*
* @internal
* @param string|null $text
* @param bool $inline
* @param bool|array $options
* @return string
* @todo rename $inline parameter to $options in 3.7.0
* @todo add deprecation warning for boolean $options in 3.7.0
* @todo remove boolean $options in in 3.8.0
*/
public function markdown(string $text = null, bool $inline = false): string
public function markdown(string $text = null, $inline = null): string
{
return ($this->component('markdown'))($this, $text, $this->options['markdown'] ?? [], $inline);
// TODO: remove after renaming parameter
$options = $inline;
// support for the old syntax to enable inline mode as second argument
if (is_bool($options) === true) {
$options = [
'inline' => $options
];
}
// merge global options with local options
$options = array_merge(
$this->options['markdown'] ?? [],
(array)$options
);
return ($this->component('markdown'))($this, $text, $options);
}
/**

View File

@@ -3,6 +3,7 @@
namespace Kirby\Cms;
use Kirby\Http\Response;
use Kirby\Toolkit\I18n;
use Whoops\Handler\CallbackHandler;
use Whoops\Handler\Handler;
use Whoops\Handler\PlainTextHandler;
@@ -136,7 +137,7 @@ trait AppErrors
'status' => 'error',
'code' => $code,
'details' => $details,
'message' => 'An unexpected error occurred! Enable debug mode for more info: https://getkirby.com/docs/reference/system/options/debug',
'message' => I18n::translate('error.unexpected'),
], $httpCode);
}

View File

@@ -333,8 +333,6 @@ class Collection extends BaseCollection
*/
public function toArray(Closure $map = null): array
{
return parent::toArray($map ?? function ($object) {
return $object->toArray();
});
return parent::toArray($map ?? fn ($object) => $object->toArray());
}
}

View File

@@ -322,98 +322,32 @@ class Core
public function roots(): array
{
return $this->cache['roots'] ??= [
// kirby
'kirby' => function (array $roots) {
return dirname(__DIR__, 2);
},
'kirby' => fn (array $roots) => dirname(__DIR__, 2),
'i18n' => fn (array $roots) => $roots['kirby'] . '/i18n',
'i18n:translations' => fn (array $roots) => $roots['i18n'] . '/translations',
'i18n:rules' => fn (array $roots) => $roots['i18n'] . '/rules',
// i18n
'i18n' => function (array $roots) {
return $roots['kirby'] . '/i18n';
},
'i18n:translations' => function (array $roots) {
return $roots['i18n'] . '/translations';
},
'i18n:rules' => function (array $roots) {
return $roots['i18n'] . '/rules';
},
// index
'index' => function (array $roots) {
return dirname(__DIR__, 3);
},
// assets
'assets' => function (array $roots) {
return $roots['index'] . '/assets';
},
// content
'content' => function (array $roots) {
return $roots['index'] . '/content';
},
// media
'media' => function (array $roots) {
return $roots['index'] . '/media';
},
// panel
'panel' => function (array $roots) {
return $roots['kirby'] . '/panel';
},
// site
'site' => function (array $roots) {
return $roots['index'] . '/site';
},
'accounts' => function (array $roots) {
return $roots['site'] . '/accounts';
},
'blueprints' => function (array $roots) {
return $roots['site'] . '/blueprints';
},
'cache' => function (array $roots) {
return $roots['site'] . '/cache';
},
'collections' => function (array $roots) {
return $roots['site'] . '/collections';
},
'config' => function (array $roots) {
return $roots['site'] . '/config';
},
'controllers' => function (array $roots) {
return $roots['site'] . '/controllers';
},
'languages' => function (array $roots) {
return $roots['site'] . '/languages';
},
'license' => function (array $roots) {
return $roots['config'] . '/.license';
},
'logs' => function (array $roots) {
return $roots['site'] . '/logs';
},
'models' => function (array $roots) {
return $roots['site'] . '/models';
},
'plugins' => function (array $roots) {
return $roots['site'] . '/plugins';
},
'sessions' => function (array $roots) {
return $roots['site'] . '/sessions';
},
'snippets' => function (array $roots) {
return $roots['site'] . '/snippets';
},
'templates' => function (array $roots) {
return $roots['site'] . '/templates';
},
// blueprints
'roles' => function (array $roots) {
return $roots['blueprints'] . '/users';
},
'index' => fn (array $roots) => dirname(__DIR__, 3),
'assets' => fn (array $roots) => $roots['index'] . '/assets',
'content' => fn (array $roots) => $roots['index'] . '/content',
'media' => fn (array $roots) => $roots['index'] . '/media',
'panel' => fn (array $roots) => $roots['kirby'] . '/panel',
'site' => fn (array $roots) => $roots['index'] . '/site',
'accounts' => fn (array $roots) => $roots['site'] . '/accounts',
'blueprints' => fn (array $roots) => $roots['site'] . '/blueprints',
'cache' => fn (array $roots) => $roots['site'] . '/cache',
'collections' => fn (array $roots) => $roots['site'] . '/collections',
'config' => fn (array $roots) => $roots['site'] . '/config',
'controllers' => fn (array $roots) => $roots['site'] . '/controllers',
'languages' => fn (array $roots) => $roots['site'] . '/languages',
'license' => fn (array $roots) => $roots['config'] . '/.license',
'logs' => fn (array $roots) => $roots['site'] . '/logs',
'models' => fn (array $roots) => $roots['site'] . '/models',
'plugins' => fn (array $roots) => $roots['site'] . '/plugins',
'sessions' => fn (array $roots) => $roots['site'] . '/sessions',
'snippets' => fn (array $roots) => $roots['site'] . '/snippets',
'templates' => fn (array $roots) => $roots['site'] . '/templates',
'roles' => fn (array $roots) => $roots['blueprints'] . '/users',
];
}
@@ -518,12 +452,8 @@ class Core
public function urls(): array
{
return $this->cache['urls'] ??= [
'index' => function () {
return Url::index();
},
'base' => function (array $urls) {
return rtrim($urls['index'], '/');
},
'index' => fn () => Url::index(),
'base' => fn (array $urls) => rtrim($urls['index'], '/'),
'current' => function (array $urls) {
$path = trim($this->kirby->path(), '/');
@@ -533,18 +463,10 @@ class Core
return $urls['base'] . '/' . $path;
}
},
'assets' => function (array $urls) {
return $urls['base'] . '/assets';
},
'api' => function (array $urls) {
return $urls['base'] . '/' . $this->kirby->option('api.slug', 'api');
},
'media' => function (array $urls) {
return $urls['base'] . '/media';
},
'panel' => function (array $urls) {
return $urls['base'] . '/' . $this->kirby->option('panel.slug', 'panel');
}
'assets' => fn (array $urls) => $urls['base'] . '/assets',
'api' => fn (array $urls) => $urls['base'] . '/' . $this->kirby->option('api.slug', 'api'),
'media' => fn (array $urls) => $urls['base'] . '/media',
'panel' => fn (array $urls) => $urls['base'] . '/' . $this->kirby->option('panel.slug', 'panel')
];
}
}

View File

@@ -90,9 +90,11 @@ trait FileActions
*/
public function changeSort(int $sort)
{
return $this->commit('changeSort', ['file' => $this, 'position' => $sort], function ($file, $sort) {
return $file->save(['sort' => $sort]);
});
return $this->commit(
'changeSort',
['file' => $this, 'position' => $sort],
fn ($file, $sort) => $file->save(['sort' => $sort])
);
}
/**

View File

@@ -135,11 +135,14 @@ class Files extends Collection
* human-readable format
* @since 3.6.0
*
* @param string|null|false $locale Locale for number formatting,
* `null` for the current locale,
* `false` to disable number formatting
* @return string
*/
public function niceSize(): string
public function niceSize($locale = null): string
{
return F::niceSize($this->size());
return F::niceSize($this->size(), $locale);
}
/**
@@ -151,9 +154,7 @@ class Files extends Collection
*/
public function size(): int
{
return F::size($this->values(function ($file) {
return $file->root();
}));
return F::size($this->values(fn ($file) => $file->root()));
}
/**

View File

@@ -26,8 +26,6 @@ class NestCollection extends BaseCollection
*/
public function toArray(Closure $map = null): array
{
return parent::toArray($map ?? function ($object) {
return $object->toArray();
});
return parent::toArray($map ?? fn ($object) => $object->toArray());
}
}

View File

@@ -201,9 +201,11 @@ trait PageActions
protected function changeStatusToDraft()
{
$arguments = ['page' => $this, 'status' => 'draft', 'position' => null];
$page = $this->commit('changeStatus', $arguments, function ($page) {
return $page->unpublish();
});
$page = $this->commit(
'changeStatus',
$arguments,
fn ($page) => $page->unpublish()
);
return $page;
}
@@ -755,9 +757,7 @@ trait PageActions
->children()
->listed()
->append($this)
->filter(function ($page) {
return $page->blueprint()->num() === 'default';
});
->filter(fn ($page) => $page->blueprint()->num() === 'default');
// get a non-associative array of ids
$keys = $siblings->keys();
@@ -804,9 +804,7 @@ trait PageActions
->children()
->listed()
->not($this)
->filter(function ($page) {
return $page->blueprint()->num() === 'default';
});
->filter(fn ($page) => $page->blueprint()->num() === 'default');
if ($siblings->count() > 0) {
foreach ($siblings as $sibling) {

View File

@@ -110,7 +110,7 @@ trait PageSiblings
*/
public function prevUnlisted($collection = null)
{
return $this->prevAll($collection)->unlisted()->first();
return $this->prevAll($collection)->unlisted()->last();
}
/**

View File

@@ -205,6 +205,10 @@ class Pages extends Collection
*/
public function findById(string $id = null)
{
if ($id === null) {
return null;
}
// remove trailing or leading slashes
$id = trim($id, '/');