1
0

downgrade to kirby v3

This commit is contained in:
Philip Wagner
2024-09-01 10:47:15 +02:00
parent a4b2aece7b
commit af86acb7a1
1085 changed files with 54743 additions and 65042 deletions

View File

@@ -2,9 +2,6 @@
namespace Kirby\Panel;
use Kirby\Cms\File as CmsFile;
use Kirby\Cms\ModelWithContent;
use Kirby\Filesystem\Asset;
use Kirby\Toolkit\I18n;
use Throwable;
@@ -23,10 +20,12 @@ class File extends Model
/**
* @var \Kirby\Cms\File
*/
protected ModelWithContent $model;
protected $model;
/**
* Breadcrumb array
*
* @return array
*/
public function breadcrumb(): array
{
@@ -35,7 +34,6 @@ class File extends Model
switch ($parent::CLASS_ALIAS) {
case 'user':
/** @var \Kirby\Cms\User $parent */
// The breadcrumb is not necessary
// on the account view
if ($parent->isLoggedIn() === false) {
@@ -46,13 +44,10 @@ class File extends Model
}
break;
case 'page':
/** @var \Kirby\Cms\Page $parent */
$breadcrumb = $this->model->parents()->flip()->values(
fn ($parent) => [
'label' => $parent->title()->toString(),
'link' => $parent->panel()->url(true),
]
);
$breadcrumb = $this->model->parents()->flip()->values(fn ($parent) => [
'label' => $parent->title()->toString(),
'link' => $parent->panel()->url(true),
]);
}
// add the file
@@ -72,54 +67,47 @@ class File extends Model
*
* @internal
* @param string|null $type (`auto`|`kirbytext`|`markdown`)
* @param bool $absolute
* @return string
*/
public function dragText(
string|null $type = null,
bool $absolute = false
): string {
public function dragText(string $type = null, bool $absolute = false): string
{
$type = $this->dragTextType($type);
$url = $this->model->filename();
$file = $this->model->type();
$url = $absolute ? $this->model->id() : $this->model->filename();
// By default only the filename is added as relative URL.
// If an absolute URL is required, either use the permalink
// for markdown notation or the UUID for Kirbytext (since
// Kirbytags support can resolve UUIDs directly)
if ($absolute === true) {
$url = match ($type) {
'markdown' => $this->model->permalink(),
default => $this->model->uuid()
};
// if UUIDs are disabled, fall back to URL
$url ??= $this->model->url();
}
if ($callback = $this->dragTextFromCallback($type, $url)) {
return $callback;
if ($dragTextFromCallback = $this->dragTextFromCallback($type, $url)) {
return $dragTextFromCallback;
}
if ($type === 'markdown') {
return match ($file) {
'image' => '![' . $this->model->alt() . '](' . $url . ')',
default => '[' . $this->model->filename() . '](' . $url . ')'
};
if ($this->model->type() === 'image') {
return '![' . $this->model->alt() . '](' . $url . ')';
}
return '[' . $this->model->filename() . '](' . $url . ')';
}
return match ($file) {
'image', 'video' => '(' . $file . ': ' . $url . ')',
default => '(file: ' . $url . ')'
};
if ($this->model->type() === 'image') {
return '(image: ' . $url . ')';
}
if ($this->model->type() === 'video') {
return '(video: ' . $url . ')';
}
return '(file: ' . $url . ')';
}
/**
* Provides options for the file dropdown
*
* @param array $options
* @return array
*/
public function dropdown(array $options = []): array
{
$file = $this->model;
$request = $file->kirby()->request();
$defaults = $request->get(['view', 'update', 'delete']);
$file = $this->model;
$defaults = $file->kirby()->request()->get(['view', 'update', 'delete']);
$options = array_merge($defaults, $options);
$permissions = $this->options(['preview']);
@@ -144,7 +132,15 @@ class File extends Model
'disabled' => $this->isDisabledDropdownOption('changeName', $options, $permissions)
];
$result[] = [
'click' => 'replace',
'icon' => 'upload',
'text' => I18n::translate('replace'),
'disabled' => $this->isDisabledDropdownOption('replace', $options, $permissions)
];
if ($view === 'list') {
$result[] = '-';
$result[] = [
'dialog' => $url . '/changeSort',
'icon' => 'sort',
@@ -153,22 +149,6 @@ class File extends Model
];
}
$result[] = [
'dialog' => $url . '/changeTemplate',
'icon' => 'template',
'text' => I18n::translate('file.changeTemplate'),
'disabled' => $this->isDisabledDropdownOption('changeTemplate', $options, $permissions)
];
$result[] = '-';
$result[] = [
'click' => 'replace',
'icon' => 'upload',
'text' => I18n::translate('replace'),
'disabled' => $this->isDisabledDropdownOption('replace', $options, $permissions)
];
$result[] = '-';
$result[] = [
'dialog' => $url . '/delete',
@@ -183,7 +163,9 @@ class File extends Model
/**
* Returns the setup for a dropdown option
* which is used in the changes dropdown
* for example
* for example.
*
* @return array
*/
public function dropdownOption(): array
{
@@ -195,36 +177,39 @@ class File extends Model
/**
* Returns the Panel icon color
*
* @return string
*/
protected function imageColor(): string
{
$types = [
'archive' => 'gray-500',
'audio' => 'aqua-500',
'code' => 'pink-500',
'document' => 'red-500',
'image' => 'orange-500',
'video' => 'yellow-500',
'image' => 'orange-400',
'video' => 'yellow-400',
'document' => 'red-400',
'audio' => 'aqua-400',
'code' => 'blue-400',
'archive' => 'gray-500'
];
$extensions = [
'csv' => 'green-500',
'doc' => 'blue-500',
'docx' => 'blue-500',
'indd' => 'purple-500',
'rtf' => 'blue-500',
'xls' => 'green-500',
'xlsx' => 'green-500',
'indd' => 'purple-400',
'xls' => 'green-400',
'xlsx' => 'green-400',
'csv' => 'green-400',
'docx' => 'blue-400',
'doc' => 'blue-400',
'rtf' => 'blue-400'
];
return
$extensions[$this->model->extension()] ??
$types[$this->model->type()] ??
parent::imageDefaults()['color'];
return $extensions[$this->model->extension()] ??
$types[$this->model->type()] ??
parent::imageDefaults()['color'];
}
/**
* Default settings for the file's Panel image
*
* @return array
*/
protected function imageDefaults(): array
{
@@ -236,42 +221,45 @@ class File extends Model
/**
* Returns the Panel icon type
*
* @return string
*/
protected function imageIcon(): string
{
$types = [
'archive' => 'archive',
'audio' => 'audio',
'code' => 'code',
'document' => 'document',
'image' => 'image',
'video' => 'video',
'document' => 'document',
'audio' => 'audio',
'code' => 'code',
'archive' => 'archive'
];
$extensions = [
'csv' => 'table',
'doc' => 'pen',
'docx' => 'pen',
'md' => 'markdown',
'mdown' => 'markdown',
'rtf' => 'pen',
'xls' => 'table',
'xlsx' => 'table',
'csv' => 'table',
'docx' => 'pen',
'doc' => 'pen',
'rtf' => 'pen',
'mdown' => 'markdown',
'md' => 'markdown'
];
return
$extensions[$this->model->extension()] ??
$types[$this->model->type()] ??
'file';
return $extensions[$this->model->extension()] ??
$types[$this->model->type()] ??
'file';
}
/**
* Returns the image file object based on provided query
*
* @internal
* @param string|null $query
* @return \Kirby\Cms\File|\Kirby\Filesystem\Asset|null
*/
protected function imageSource(
string|null $query = null
): CmsFile|Asset|null {
protected function imageSource(string $query = null)
{
if ($query === null && $this->model->isViewable()) {
return $this->model;
}
@@ -279,45 +267,12 @@ class File extends Model
return parent::imageSource($query);
}
/**
* Whether focus can be added in Panel view
*/
public function isFocusable(): bool
{
// blueprint option
$option = $this->model->blueprint()->focus();
// fallback to whether the file is viewable
// (images should be focusable by default, others not)
$option ??= $this->model->isViewable();
if ($option === false) {
return false;
}
// ensure that user can update content file
if ($this->options()['update'] === false) {
return false;
}
$kirby = $this->model->kirby();
// ensure focus is only added when editing primary/only language
if (
$kirby->multilang() === false ||
$kirby->languages()->count() === 0 ||
$kirby->language()->isDefault() === true
) {
return true;
}
return false;
}
/**
* Returns an array of all actions
* that can be performed in the Panel
*
* @param array $unlock An array of options that will be force-unlocked
* @return array
*/
public function options(array $unlock = []): array
{
@@ -327,7 +282,7 @@ class File extends Model
// check if the file type is allowed at all,
// otherwise it cannot be replaced
$this->model->match($this->model->blueprint()->accept());
} catch (Throwable) {
} catch (Throwable $e) {
$options['replace'] = false;
}
@@ -336,6 +291,8 @@ class File extends Model
/**
* Returns the full path without leading slash
*
* @return string
*/
public function path(): string
{
@@ -345,41 +302,51 @@ class File extends Model
/**
* Prepares the response data for file pickers
* and file fields
*
* @param array|null $params
* @return array
*/
public function pickerData(array $params = []): array
{
$name = $this->model->filename();
$id = $this->model->id();
$name = $this->model->filename();
if (empty($params['model']) === false) {
$parent = $this->model->parent();
// if the file belongs to the current parent model,
// store only name as ID to keep its path relative to the model
$id = $parent === $params['model'] ? $name : $id;
$parent = $this->model->parent();
$uuid = $parent === $params['model'] ? $name : $id;
$absolute = $parent !== $params['model'];
}
$params['text'] ??= '{{ file.filename }}';
return array_merge(parent::pickerData($params), [
'dragText' => $this->dragText('auto', $absolute ?? false),
'filename' => $name,
'id' => $id,
'dragText' => $this->dragText('auto', $absolute ?? false),
'type' => $this->model->type(),
'url' => $this->model->url()
'url' => $this->model->url(),
'uuid' => $uuid ?? $id,
]);
}
/**
* Returns the data array for the
* view's component props
*
* @internal
*
* @return array
*/
public function props(): array
{
$file = $this->model;
$dimensions = $file->dimensions();
$siblings = $file->templateSiblings()->sortBy(
'sort',
'asc',
'filename',
'asc'
);
return array_merge(
parent::props(),
@@ -401,13 +368,12 @@ class File extends Model
'url' => $file->url(),
],
'preview' => [
'focusable' => $this->isFocusable(),
'image' => $this->image([
'image' => $this->image([
'back' => 'transparent',
'ratio' => '1/1'
], 'cards'),
'url' => $url = $file->previewUrl(),
'details' => [
'url' => $url = $file->previewUrl(),
'details' => [
[
'title' => I18n::translate('template'),
'text' => $file->template() ?? '—'
@@ -442,7 +408,10 @@ class File extends Model
/**
* Returns navigation array with
* previous and next file
*
* @internal
*
* @return array
*/
public function prevNext(): array
{
@@ -455,11 +424,11 @@ class File extends Model
);
return [
'next' => function () use ($file, $siblings): array|null {
'next' => function () use ($file, $siblings): ?array {
$next = $siblings->nth($siblings->indexOf($file) + 1);
return $this->toPrevNextLink($next, 'filename');
},
'prev' => function () use ($file, $siblings): array|null {
'prev' => function () use ($file, $siblings): ?array {
$prev = $siblings->nth($siblings->indexOf($file) - 1);
return $this->toPrevNextLink($prev, 'filename');
}
@@ -468,6 +437,9 @@ class File extends Model
/**
* Returns the url to the editing view
* in the panel
*
* @param bool $relative
* @return string
*/
public function url(bool $relative = false): string
{
@@ -478,16 +450,21 @@ class File extends Model
/**
* Returns the data array for
* this model's Panel view
*
* @internal
*
* @return array
*/
public function view(): array
{
$file = $this->model;
return [
'breadcrumb' => fn (): array => $this->model->panel()->breadcrumb(),
'breadcrumb' => fn (): array => $file->panel()->breadcrumb(),
'component' => 'k-file-view',
'props' => $this->props(),
'search' => 'files',
'title' => $this->model->filename(),
'title' => $file->filename(),
];
}
}