Upgrade to 3.6.0

This commit is contained in:
Bastian Allgeier
2021-11-16 14:53:37 +01:00
parent 7388fa4d24
commit 92b7a330fa
318 changed files with 20017 additions and 6878 deletions

View File

@@ -2,6 +2,7 @@
namespace Kirby\Text;
use Kirby\Cms\App;
use Kirby\Exception\BadMethodCallException;
use Kirby\Exception\InvalidArgumentException;
@@ -45,9 +46,20 @@ class KirbyTag
$type = static::$aliases[$type];
}
$kirby = $data['kirby'] ?? App::instance();
$defaults = $kirby->option('kirbytext.' . $type, []);
$attrs = array_replace($defaults, $attrs);
// all available tag attributes
$availableAttrs = static::$types[$type]['attr'] ?? [];
foreach ($attrs as $attrName => $attrValue) {
$attrName = strtolower($attrName);
$this->$attrName = $attrValue;
// applies only defined attributes to safely update
if (in_array($attrName, $availableAttrs) === true) {
$this->{$attrName} = $attrValue;
}
}
$this->attrs = $attrs;
@@ -75,6 +87,51 @@ class KirbyTag
return (new static(...$arguments))->render();
}
/**
* Finds a file for the given path.
* The method first searches the file
* in the current parent, if it's a page.
* Afterwards it uses Kirby's global file finder.
*
* @param string $path
* @return \Kirby\Cms\File|null
*/
public function file(string $path)
{
$parent = $this->parent();
if (
is_object($parent) === true &&
method_exists($parent, 'file') === true &&
$file = $parent->file($path)
) {
return $file;
}
if (
is_a($parent, 'Kirby\Cms\File') === true &&
$file = $parent->page()->file($path)
) {
return $file;
}
return $this->kirby()->file($path, null, true);
}
/**
* Returns the current Kirby instance
*
* @return \Kirby\Cms\App
*/
public function kirby()
{
return $this->data['kirby'] ?? App::instance();
}
public function option(string $key, $default = null)
{
return $this->options[$key] ?? $default;
}
/**
* @param string $string
* @param array $data
@@ -126,9 +183,14 @@ class KirbyTag
return new static($type, $value, $attributes, $data, $options);
}
public function option(string $key, $default = null)
/**
* Returns the parent model
*
* @return \Kirby\Cms\Model|null
*/
public function parent()
{
return $this->options[$key] ?? $default;
return $this->data['parent'];
}
public function render(): string

View File

@@ -8,7 +8,7 @@ use Kirby\Toolkit\Str;
/**
* Parses and converts custom kirbytags in any
* given string. KiryTags are defined via
* given string. KirbyTags are defined via
* `KirbyTag::$types`. The default tags for the
* Cms are located in `kirby/config/tags.php`
*
@@ -20,8 +20,6 @@ use Kirby\Toolkit\Str;
*/
class KirbyTags
{
protected static $tagClass = 'Kirby\Text\KirbyTag';
public static function parse(string $text = null, array $data = [], array $options = []): string
{
$regex = '!
@@ -29,14 +27,14 @@ class KirbyTags
(?=\([a-z0-9_-]+:) # positive lookahead that requires starts with ( and lowercase ASCII letters, digits, underscores or hyphens followed with : immediately to the right of the current location
(\( # capturing group 1
(?:[^()]+|(?1))*+ # repetitions of any chars other than ( and ) or the whole group 1 pattern (recursed)
\)) # end of capturing group 1
\)) # end of capturing group 1
!isx';
return preg_replace_callback($regex, function ($match) use ($data, $options) {
$debug = $options['debug'] ?? false;
try {
return static::$tagClass::parse($match[0], $data, $options)->render();
return KirbyTag::parse($match[0], $data, $options)->render();
} catch (InvalidArgumentException $e) {
// stay silent in production and ignore non-existing tags
if ($debug !== true || Str::startsWith($e->getMessage(), 'Undefined tag type:') === true) {