Upgrade to 3.1.0

This commit is contained in:
Bastian Allgeier
2019-03-19 11:07:14 +01:00
parent 418db4b09b
commit 6e074142f1
98 changed files with 1266 additions and 299 deletions

View File

@@ -17,6 +17,9 @@ return [
'dimensions' => function (File $file) {
return $file->dimensions()->toArray();
},
'dragText' => function (File $file) {
return $file->dragText();
},
'exists' => function (File $file) {
return $file->exists();
},
@@ -53,6 +56,15 @@ return [
'options' => function (File $file) {
return $file->permissions()->toArray();
},
'panelIcon' => function (File $file) {
return $file->panelIcon();
},
'panelImage' => function (File $file) {
return $file->panelImage();
},
'panelUrl' => function (File $file) {
return $file->panelUrl(true);
},
'prev' => function (File $file) {
return $file->prev();
},

View File

@@ -7,6 +7,24 @@ use Kirby\Exception\InvalidArgumentException;
*/
return [
[
'pattern' => '(:all)/files/(:any)/sections/(:any)',
'method' => 'GET',
'action' => function (string $path, string $filename, string $sectionName) {
if ($section = $this->file($path, $filename)->blueprint()->section($sectionName)) {
return $section->toResponse();
}
}
],
[
'pattern' => '(:all)/files/(:any)/fields/(:any)/(:all?)',
'method' => 'ALL',
'action' => function (string $parent, string $filename, string $fieldName, string $path = null) {
if ($file = $this->file($parent, $filename)) {
return $this->fieldApi($file, $fieldName, $path);
}
}
],
[
'pattern' => '(:all)/files',
'method' => 'GET',
@@ -29,9 +47,15 @@ return [
],
[
'pattern' => '(:all)/files/search',
'method' => 'POST',
'method' => 'GET|POST',
'action' => function (string $path) {
return $this->parent($path)->files()->query($this->requestBody());
$files = $this->parent($path)->files();
if ($this->requestMethod() === 'GET') {
return $files->search($this->requestQuery('q'));
} else {
return $files->query($this->requestBody());
}
}
],
[
@@ -78,23 +102,5 @@ return [
return $this->file($path, $filename)->changeName($this->requestBody('name'));
}
],
[
'pattern' => '(:all)/files/(:any)/sections/(:any)',
'method' => 'GET',
'action' => function (string $path, string $filename, string $sectionName) {
if ($section = $this->file($path, $filename)->blueprint()->section($sectionName)) {
return $section->toResponse();
}
}
],
[
'pattern' => '(:all)/files/(:any)/fields/(:any)/(:all?)',
'method' => 'ALL',
'action' => function (string $parent, string $filename, string $fieldName, string $path = null) {
if ($file = $this->file($parent, $filename)) {
return $this->fieldApi($file, $fieldName, $path);
}
}
]
];

View File

@@ -51,9 +51,15 @@ return [
],
[
'pattern' => 'pages/(:any)/children/search',
'method' => 'POST',
'method' => 'GET|POST',
'action' => function (string $id) {
return $this->page($id)->children()->query($this->requestBody());
$pages = $this->page($id)->children();
if ($this->requestMethod() === 'GET') {
return $pages->search($this->requestQuery('q'));
} else {
return $pages->query($this->requestBody());
}
}
],
[

View File

@@ -62,17 +62,18 @@ return [
],
[
'pattern' => 'site/search',
'method' => 'GET',
'method' => 'GET|POST',
'action' => function () {
return $this->site()
->index(true)
->filterBy('isReadable', true)
->search($this->requestQuery('q'), [
'score' => [
'id' => 64,
'title' => 64,
]
]);
$pages = $this
->site()
->index(true)
->filterBy('isReadable', true);
if ($this->requestMethod() === 'GET') {
return $pages->search($this->requestQuery('q'));
} else {
return $pages->query($this->requestBody());
}
}
],
[

View File

@@ -23,9 +23,13 @@ return [
],
[
'pattern' => 'users/search',
'method' => 'POST',
'method' => 'GET|POST',
'action' => function () {
return $this->users()->query($this->requestBody());
if ($this->requestMethod() === 'GET') {
return $this->users()->search($this->requestQuery('q'));
} else {
return $this->users()->query($this->requestBody());
}
}
],
[

View File

@@ -9,6 +9,7 @@ use Kirby\Cms\Template;
use Kirby\Data\Data;
use Kirby\Exception\NotFoundException;
use Kirby\Image\Darkroom;
use Kirby\Text\Markdown;
use Kirby\Text\SmartyPants;
use Kirby\Toolkit\F;
use Kirby\Toolkit\Tpl as Snippet;
@@ -50,17 +51,12 @@ return [
'file::url' => function (App $kirby, $file) {
return $file->mediaUrl();
},
'markdown' => function (App $kirby, string $text = null, array $options = []): string {
'markdown' => function (App $kirby, string $text = null, array $options = [], bool $inline = false): string {
static $markdown;
if (isset($markdown) === false) {
$parser = ($options['extra'] ?? false) === true ? 'ParsedownExtra' : 'Parsedown';
$markdown = new $parser;
$markdown->setBreaksEnabled($options['breaks'] ?? true);
}
$markdown = $markdown ?? new Markdown($options);
// we need the @ here, because parsedown has some notice issues :(
return @$markdown->text($text);
return $markdown->parse($text, $inline);
},
'smartypants' => function (App $kirby, string $text = null, array $options = []): string {
static $smartypants;

View File

@@ -22,7 +22,8 @@ return [
return $search;
},
/**
* If true, entries will be sorted alphabetically on selection
* If true, selected entries will be sorted
* according to their position in the dropdown
*/
'sort' => function (bool $sort = false) {
return $sort;

View File

@@ -1,6 +1,6 @@
<?php
use Kirby\Form\Form;
use Kirby\Cms\Form;
use Kirby\Cms\Blueprint;
return [

View File

@@ -29,6 +29,21 @@ return [
return trim($default);
},
/**
* Sets the options for the files picker
*/
'files' => function ($files = []) {
if (is_string($files) === true) {
return ['query' => $files];
}
if (is_array($files) === false) {
$files = [];
}
return $files;
},
/**
* Maximum number of allowed characters
*/
@@ -50,10 +65,103 @@ return [
return $size;
},
/**
* Sets the upload options for linked files
*/
'uploads' => function ($uploads = []) {
if ($uploads === false) {
return false;
}
if (is_string($uploads) === true) {
return ['template' => $uploads];
}
if (is_array($uploads) === false) {
$uploads = [];
}
return $uploads;
},
'value' => function (string $value = null) {
return trim($value);
}
],
'api' => function () {
return [
[
'pattern' => 'files',
'action' => function () {
$field = $this->field();
$model = $field->model();
if (empty($filed->files['query']) === false) {
$query = $filed->files['query'];
} elseif (is_a($model, 'Kirby\Cms\File') === true) {
$query = 'file.siblings';
} else {
$query = $model::CLASS_ALIAS . '.files';
}
$files = $model->query($query, 'Kirby\Cms\Files');
$data = [];
foreach ($files as $index => $file) {
$image = $file->panelImage($field->files['image'] ?? []);
$model = $field->model();
$data[] = [
'filename' => $file->filename(),
'dragText' => $file->dragText(),
'image' => $image,
'icon' => $file->panelIcon($image)
];
}
return $data;
}
],
[
'pattern' => 'upload',
'action' => function () {
$field = $this->field();
$uploads = $field->uploads();
if ($uploads === false) {
throw new Exception('Uploads are disabled for this field');
}
if ($parentQuery = ($uploads['parent'] ?? null)) {
$parent = $field->model()->query($parentQuery);
} else {
$parent = $field->model();
}
if (is_a($parent, 'Kirby\Cms\File') === true) {
$parent = $parent->parent();
}
return $this->upload(function ($source, $filename) use ($field, $parent, $uploads) {
$file = $parent->createFile([
'source' => $source,
'template' => $uploads['template'] ?? null,
'filename' => $filename,
]);
if (is_a($file, 'Kirby\Cms\File') === false) {
throw new Exception('The file could not be uploaded');
}
return [
'filename' => $file->filename(),
'dragText' => $file->dragText(),
];
});
}
]
];
},
'validations' => [
'minlength',
'maxlength'

View File

@@ -428,6 +428,45 @@ function kirbytext(string $text = null, array $data = []): string
return App::instance()->kirbytext($text, $data);
}
/**
* Parses KirbyTags and inline Markdown in the
* given string.
* @since 3.1.0
*
* @param string $text
* @param array $data
* @return string
*/
function kirbytextinline(string $text = null, array $data = []): string
{
return App::instance()->kirbytext($text, $data, true);
}
/**
* Shortcut for `kirbytext()` helper
*
* @param string $text
* @param array $data
* @return string
*/
function kt(string $text = null, array $data = []): string
{
return kirbytext($text, $data);
}
/**
* Shortcut for `kirbytextinline()` helper
* @since 3.1.0
*
* @param string $text
* @param array $data
* @return string
*/
function kti(string $text = null, array $data = []): string
{
return kirbytextinline($text, $data);
}
/**
* A super simple class autoloader
*

View File

@@ -298,6 +298,19 @@ return function (App $app) {
return $field;
},
/**
* Converts the field content from inline Markdown/Kirbytext to valid HTML
* @since 3.1.0
*/
'kirbytextinline' => function (Field $field) use ($app) {
$field->value = $app->kirbytext($field->value, [
'parent' => $field->parent(),
'field' => $field
], true);
return $field;
},
/**
* Parses all KirbyTags without also parsing Markdown
*/

View File

@@ -56,11 +56,7 @@ return function ($kirby) {
'pattern' => 'media/plugins/(:any)/(:any)/(:all).(css|gif|js|jpg|png|svg|webp|woff2|woff)',
'env' => 'media',
'action' => function (string $provider, string $pluginName, string $filename, string $extension) use ($kirby) {
if ($url = PluginAssets::resolve($provider . '/' . $pluginName, $filename . '.' . $extension)) {
return $kirby
->response()
->redirect($url, 307);
}
return PluginAssets::resolve($provider . '/' . $pluginName, $filename . '.' . $extension);
}
],
[
@@ -115,7 +111,7 @@ return function ($kirby) {
'action' => function () use ($kirby) {
$home = $kirby->site()->homePage();
if ($kirby->url() !== $home->url()) {
if ($home && $kirby->url() !== $home->url()) {
if ($kirby->option('languages.detect') === true) {
return $kirby
->response()
@@ -126,7 +122,7 @@ return function ($kirby) {
->redirect($kirby->site()->url());
}
} else {
return $home;
return $kirby->resolve(null, $kirby->detectedLanguage()->code());
}
}
];
@@ -178,7 +174,7 @@ return function ($kirby) {
'method' => 'ALL',
'env' => 'site',
'action' => function () use ($kirby) {
return $kirby->site()->homePage();
return $kirby->resolve();
}
];

View File

@@ -8,6 +8,7 @@ return [
'mixins' => [
'empty',
'headline',
'help',
'layout',
'min',
'max',

View File

@@ -4,7 +4,8 @@ use Kirby\Toolkit\I18n;
return [
'mixins' => [
'headline'
'headline',
'help'
],
'props' => [
'text' => function ($text = null) {

View File

@@ -0,0 +1,12 @@
<?php
return [
'props' => [
/**
* Sets the help text
*/
'help' => function ($help = null) {
return I18n::translate($help, $help);
}
]
];

View File

@@ -10,6 +10,7 @@ return [
'mixins' => [
'empty',
'headline',
'help',
'layout',
'min',
'max',