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

@@ -1,21 +1,13 @@
<?php
use Kirby\Cms\App;
use Kirby\Cms\File;
use Kirby\Cms\Helpers;
use Kirby\Cms\Html;
use Kirby\Cms\ModelWithContent;
use Kirby\Cms\Page;
use Kirby\Cms\Pages;
use Kirby\Cms\Response;
use Kirby\Cms\Site;
use Kirby\Cms\Url;
use Kirby\Filesystem\Asset;
use Kirby\Filesystem\F;
use Kirby\Http\Response;
use Kirby\Http\Router;
use Kirby\Image\QrCode;
use Kirby\Template\Slot;
use Kirby\Template\Snippet;
use Kirby\Toolkit\Date;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Str;
@@ -24,8 +16,11 @@ use Kirby\Toolkit\V;
if (Helpers::hasOverride('asset') === false) { // @codeCoverageIgnore
/**
* Helper to create an asset object
*
* @param string $path
* @return \Kirby\Filesystem\Asset
*/
function asset(string $path): Asset
function asset(string $path)
{
return new Asset($path);
}
@@ -38,12 +33,10 @@ if (Helpers::hasOverride('attr') === false) { // @codeCoverageIgnore
* @param array|null $attr A list of attributes as key/value array
* @param string|null $before An optional string that will be prepended if the result is not empty
* @param string|null $after An optional string that will be appended if the result is not empty
* @return string|null
*/
function attr(
array|null $attr = null,
string|null $before = null,
string|null $after = null
): string|null {
function attr(?array $attr = null, ?string $before = null, ?string $after = null): ?string
{
return Html::attr($attr, null, $before, $after);
}
}
@@ -52,12 +45,12 @@ if (Helpers::hasOverride('collection') === false) { // @codeCoverageIgnore
/**
* Returns the result of a collection by name
*
* @return \Kirby\Toolkit\Collection|null
* @todo 5.0 Add return type declaration
* @param string $name
* @return \Kirby\Cms\Collection|null
*/
function collection(string $name, array $options = [])
function collection(string $name)
{
return App::instance()->collection($name, $options);
return App::instance()->collection($name);
}
}
@@ -68,7 +61,7 @@ if (Helpers::hasOverride('csrf') === false) { // @codeCoverageIgnore
* @param string|null $check Pass a token here to compare it to the one in the session
* @return string|bool Either the token or a boolean check result
*/
function csrf(string|null $check = null): string|bool
function csrf(?string $check = null)
{
// check explicitly if there have been no arguments at all;
// checking for null introduces a security issue because null could come
@@ -86,12 +79,11 @@ if (Helpers::hasOverride('css') === false) { // @codeCoverageIgnore
* Creates one or multiple CSS link tags
*
* @param string|array $url Relative or absolute URLs, an array of URLs or `@auto` for automatic template css loading
* @param string|array|null $options Pass an array of attributes for the link tag or a media attribute string
* @param string|array $options Pass an array of attributes for the link tag or a media attribute string
* @return string|null
*/
function css(
string|array $url,
string|array|null $options = null
): string|null {
function css($url, $options = null): ?string
{
return Html::css($url, $options);
}
}
@@ -101,6 +93,7 @@ if (Helpers::hasOverride('deprecated') === false) { // @codeCoverageIgnore
* Triggers a deprecation warning if debug mode is active
* @since 3.3.0
*
* @param string $message
* @return bool Whether the warning was triggered
*/
function deprecated(string $message): bool
@@ -109,12 +102,16 @@ if (Helpers::hasOverride('deprecated') === false) { // @codeCoverageIgnore
}
}
if (Helpers::hasOverride('dump') === false && function_exists('dump') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('dump') === false) { // @codeCoverageIgnore
/**
* Simple object and variable dumper
* to help with debugging.
*
* @param mixed $variable
* @param bool $echo
* @return string
*/
function dump(mixed $variable, bool $echo = true): string
function dump($variable, bool $echo = true): string
{
return Helpers::dump($variable, $echo);
}
@@ -124,35 +121,16 @@ if (Helpers::hasOverride('e') === false) { // @codeCoverageIgnore
/**
* Smart version of echo with an if condition as first argument
*
* @param mixed $condition
* @param mixed $value The string to be echoed if the condition is true
* @param mixed $alternative An alternative string which should be echoed when the condition is false
*/
function e(mixed $condition, mixed $value, mixed $alternative = null): void
function e($condition, $value, $alternative = null)
{
echo $condition ? $value : $alternative;
}
}
if (Helpers::hasOverride('endslot') === false) { // @codeCoverageIgnore
/**
* Ends the last started template slot
*/
function endslot(): void
{
Slot::end();
}
}
if (Helpers::hasOverride('endsnippet') === false) { // @codeCoverageIgnore
/**
* Renders the currently active snippet with slots
*/
function endsnippet(): void
{
Snippet::end();
}
}
if (Helpers::hasOverride('esc') === false) { // @codeCoverageIgnore
/**
* Escape context specific output
@@ -173,8 +151,9 @@ if (Helpers::hasOverride('get') === false) { // @codeCoverageIgnore
*
* @param mixed $key The key to look for. Pass false or null to return the entire request array.
* @param mixed $default Optional default value, which should be returned if no element has been found
* @return mixed
*/
function get(mixed $key = null, mixed $default = null): mixed
function get($key = null, $default = null)
{
return App::instance()->request()->get($key, $default);
}
@@ -183,8 +162,12 @@ if (Helpers::hasOverride('get') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('gist') === false) { // @codeCoverageIgnore
/**
* Embeds a Github Gist
*
* @param string $url
* @param string|null $file
* @return string
*/
function gist(string $url, string|null $file = null): string
function gist(string $url, ?string $file = null): string
{
return App::instance()->kirbytag([
'gist' => $url,
@@ -197,8 +180,12 @@ if (Helpers::hasOverride('go') === false) { // @codeCoverageIgnore
/**
* Redirects to the given Urls
* Urls can be relative or absolute.
*
* @param string $url
* @param int $code
* @return void
*/
function go(string $url = '/', int $code = 302): never
function go(string $url = '/', int $code = 302)
{
Response::go($url, $code);
}
@@ -209,8 +196,10 @@ if (Helpers::hasOverride('h') === false) { // @codeCoverageIgnore
* Shortcut for html()
*
* @param string|null $string unencoded text
* @param bool $keepTags
* @return string
*/
function h(string|null $string, bool $keepTags = false): string
function h(?string $string, bool $keepTags = false): string
{
return Html::encode($string, $keepTags);
}
@@ -221,8 +210,10 @@ if (Helpers::hasOverride('html') === false) { // @codeCoverageIgnore
* Creates safe html by encoding special characters
*
* @param string|null $string unencoded text
* @param bool $keepTags
* @return string
*/
function html(string|null $string, bool $keepTags = false): string
function html(?string $string, bool $keepTags = false): string
{
return Html::encode($string, $keepTags);
}
@@ -235,8 +226,11 @@ if (Helpers::hasOverride('image') === false) { // @codeCoverageIgnore
*
* Example:
* <?= image('some/page/myimage.jpg') ?>
*
* @param string|null $path
* @return \Kirby\Cms\File|null
*/
function image(string|null $path = null): File|null
function image(?string $path = null)
{
return App::instance()->image($path);
}
@@ -245,12 +239,14 @@ if (Helpers::hasOverride('image') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('invalid') === false) { // @codeCoverageIgnore
/**
* Runs a number of validators on a set of data and checks if the data is invalid
*
* @param array $data
* @param array $rules
* @param array $messages
* @return array
*/
function invalid(
array $data = [],
array $rules = [],
array $messages = []
): array {
function invalid(array $data = [], array $rules = [], array $messages = []): array
{
return V::invalid($data, $rules, $messages);
}
}
@@ -258,11 +254,13 @@ if (Helpers::hasOverride('invalid') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('js') === false) { // @codeCoverageIgnore
/**
* Creates a script tag to load a javascript file
*
* @param string|array $url
* @param string|array $options
* @return string|null
*/
function js(
string|array $url,
string|array|bool|null $options = null
): string|null {
function js($url, $options = null): ?string
{
return Html::js($url, $options);
}
}
@@ -270,8 +268,10 @@ if (Helpers::hasOverride('js') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('kirby') === false) { // @codeCoverageIgnore
/**
* Returns the Kirby object in any situation
*
* @return \Kirby\Cms\App
*/
function kirby(): App
function kirby()
{
return App::instance();
}
@@ -280,13 +280,15 @@ if (Helpers::hasOverride('kirby') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('kirbytag') === false) { // @codeCoverageIgnore
/**
* Makes it possible to use any defined Kirbytag as standalone function
*
* @param string|array $type
* @param string|null $value
* @param array $attr
* @param array $data
* @return string
*/
function kirbytag(
string|array $type,
string|null $value = null,
array $attr = [],
array $data = []
): string {
function kirbytag($type, ?string $value = null, array $attr = [], array $data = []): string
{
return App::instance()->kirbytag($type, $value, $attr, $data);
}
}
@@ -295,8 +297,12 @@ if (Helpers::hasOverride('kirbytags') === false) { // @codeCoverageIgnore
/**
* Parses KirbyTags in the given string. Shortcut
* for `$kirby->kirbytags($text, $data)`
*
* @param string|null $text
* @param array $data
* @return string
*/
function kirbytags(string|null $text = null, array $data = []): string
function kirbytags(?string $text = null, array $data = []): string
{
return App::instance()->kirbytags($text, $data);
}
@@ -306,8 +312,12 @@ if (Helpers::hasOverride('kirbytext') === false) { // @codeCoverageIgnore
/**
* Parses KirbyTags and Markdown in the
* given string. Shortcut for `$kirby->kirbytext()`
*
* @param string|null $text
* @param array $data
* @return string
*/
function kirbytext(string|null $text = null, array $data = []): string
function kirbytext(?string $text = null, array $data = []): string
{
return App::instance()->kirbytext($text, $data);
}
@@ -318,8 +328,12 @@ if (Helpers::hasOverride('kirbytextinline') === false) { // @codeCoverageIgnore
* Parses KirbyTags and inline Markdown in the
* given string.
* @since 3.1.0
*
* @param string|null $text
* @param array $options
* @return string
*/
function kirbytextinline(string|null $text = null, array $options = []): string
function kirbytextinline(?string $text = null, array $options = []): string
{
$options['markdown']['inline'] = true;
return App::instance()->kirbytext($text, $options);
@@ -329,8 +343,12 @@ if (Helpers::hasOverride('kirbytextinline') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('kt') === false) { // @codeCoverageIgnore
/**
* Shortcut for `kirbytext()` helper
*
* @param string|null $text
* @param array $data
* @return string
*/
function kt(string|null $text = null, array $data = []): string
function kt(?string $text = null, array $data = []): string
{
return App::instance()->kirbytext($text, $data);
}
@@ -340,8 +358,12 @@ if (Helpers::hasOverride('kti') === false) { // @codeCoverageIgnore
/**
* Shortcut for `kirbytextinline()` helper
* @since 3.1.0
*
* @param string|null $text
* @param array $options
* @return string
*/
function kti(string|null $text = null, array $options = []): string
function kti(?string $text = null, array $options = []): string
{
$options['markdown']['inline'] = true;
return App::instance()->kirbytext($text, $options);
@@ -351,8 +373,12 @@ if (Helpers::hasOverride('kti') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('load') === false) { // @codeCoverageIgnore
/**
* A super simple class autoloader
*
* @param array $classmap
* @param string|null $base
* @return void
*/
function load(array $classmap, string|null $base = null): void
function load(array $classmap, ?string $base = null): void
{
F::loadClasses($classmap, $base);
}
@@ -362,8 +388,12 @@ if (Helpers::hasOverride('markdown') === false) { // @codeCoverageIgnore
/**
* Parses markdown in the given string. Shortcut for
* `$kirby->markdown($text)`
*
* @param string|null $text
* @param array $options
* @return string
*/
function markdown(string|null $text = null, array $options = []): string
function markdown(?string $text = null, array $options = []): string
{
return App::instance()->markdown($text, $options);
}
@@ -372,8 +402,12 @@ if (Helpers::hasOverride('markdown') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('option') === false) { // @codeCoverageIgnore
/**
* Shortcut for `$kirby->option($key, $default)`
*
* @param string $key
* @param mixed $default
* @return mixed
*/
function option(string $key, mixed $default = null): mixed
function option(string $key, $default = null)
{
return App::instance()->option($key, $default);
}
@@ -383,8 +417,11 @@ if (Helpers::hasOverride('page') === false) { // @codeCoverageIgnore
/**
* Fetches a single page by id or
* the current page when no id is specified
*
* @param string|null $id
* @return \Kirby\Cms\Page|null
*/
function page(string|null $id = null): Page|null
function page(?string $id = null)
{
if (empty($id) === true) {
return App::instance()->site()->page();
@@ -397,8 +434,11 @@ if (Helpers::hasOverride('page') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('pages') === false) { // @codeCoverageIgnore
/**
* Helper to build pages collection
*
* @param string|array ...$id
* @return \Kirby\Cms\Pages|null
*/
function pages(string|array ...$id): Pages|null
function pages(...$id)
{
// ensure that a list of string arguments and an array
// as the first argument are treated the same
@@ -416,9 +456,11 @@ if (Helpers::hasOverride('param') === false) { // @codeCoverageIgnore
/**
* Returns a single param from the URL
*
* @psalm-return ($fallback is string ? string : string|null)
* @param string $key
* @param string|null $fallback
* @return string|null
*/
function param(string $key, string|null $fallback = null): string|null
function param(string $key, ?string $fallback = null): ?string
{
return App::instance()->request()->url()->params()->$key ?? $fallback;
}
@@ -427,6 +469,8 @@ if (Helpers::hasOverride('param') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('params') === false) { // @codeCoverageIgnore
/**
* Returns all params from the current Url
*
* @return array
*/
function params(): array
{
@@ -434,28 +478,16 @@ if (Helpers::hasOverride('params') === false) { // @codeCoverageIgnore
}
}
if (Helpers::hasOverride('qr') === false) { // @codeCoverageIgnore
/**
* Creates a QR code object
*/
function qr(string|ModelWithContent $data): QrCode
{
if ($data instanceof ModelWithContent) {
$data = $data->url();
}
return new QrCode($data);
}
}
if (Helpers::hasOverride('r') === false) { // @codeCoverageIgnore
/**
* Smart version of return with an if condition as first argument
*
* @param mixed $condition
* @param mixed $value The string to be returned if the condition is true
* @param mixed $alternative An alternative string which should be returned when the condition is false
* @return mixed
*/
function r(mixed $condition, mixed $value, mixed $alternative = null): mixed
function r($condition, $value, $alternative = null)
{
return $condition ? $value : $alternative;
}
@@ -466,13 +498,15 @@ if (Helpers::hasOverride('router') === false) { // @codeCoverageIgnore
* Creates a micro-router and executes
* the routing action immediately
* @since 3.6.0
*
* @param string|null $path
* @param string $method
* @param array $routes
* @param \Closure|null $callback
* @return mixed
*/
function router(
string|null $path = null,
string $method = 'GET',
array $routes = [],
Closure|null $callback = null
): mixed {
function router(?string $path = null, string $method = 'GET', array $routes = [], ?Closure $callback = null)
{
return Router::execute($path, $method, $routes, $callback);
}
}
@@ -480,8 +514,10 @@ if (Helpers::hasOverride('router') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('site') === false) { // @codeCoverageIgnore
/**
* Returns the current site object
*
* @return \Kirby\Cms\Site
*/
function site(): Site
function site()
{
return App::instance()->site();
}
@@ -490,29 +526,26 @@ if (Helpers::hasOverride('site') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('size') === false) { // @codeCoverageIgnore
/**
* Determines the size/length of numbers, strings, arrays and countable objects
*
* @param mixed $value
* @return int
* @throws \Kirby\Exception\InvalidArgumentException
*/
function size(mixed $value): int
function size($value): int
{
return Helpers::size($value);
}
}
if (Helpers::hasOverride('slot') === false) { // @codeCoverageIgnore
/**
* Starts a new template slot
*/
function slot(string $name = 'default'): void
{
Slot::begin($name);
}
}
if (Helpers::hasOverride('smartypants') === false) { // @codeCoverageIgnore
/**
* Enhances the given string with
* smartypants. Shortcut for `$kirby->smartypants($text)`
*
* @param string|null $text
* @return string
*/
function smartypants(string|null $text = null): string
function smartypants(?string $text = null): string
{
return App::instance()->smartypants($text);
}
@@ -521,14 +554,15 @@ if (Helpers::hasOverride('smartypants') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('snippet') === false) { // @codeCoverageIgnore
/**
* Embeds a snippet from the snippet folder
*
* @param string|array $name
* @param array|object $data
* @param bool $return
* @return string|null
*/
function snippet(
$name,
$data = [],
bool $return = false,
bool $slots = false
): Snippet|string|null {
return App::instance()->snippet($name, $data, $return, $slots);
function snippet($name, $data = [], bool $return = false): ?string
{
return App::instance()->snippet($name, $data, $return);
}
}
@@ -536,8 +570,11 @@ if (Helpers::hasOverride('svg') === false) { // @codeCoverageIgnore
/**
* Includes an SVG file by absolute or
* relative file path.
*
* @param string|\Kirby\Cms\File $file
* @return string|false
*/
function svg(string|File $file): string|false
function svg($file)
{
return Html::svg($file);
}
@@ -546,12 +583,14 @@ if (Helpers::hasOverride('svg') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('t') === false) { // @codeCoverageIgnore
/**
* Returns translate string for key from translation file
*
* @param string|array $key
* @param string|null $fallback
* @param string|null $locale
* @return array|string|null
*/
function t(
string|array $key,
string|null $fallback = null,
string|null $locale = null
): string|array|Closure|null {
function t($key, string $fallback = null, string $locale = null)
{
return I18n::translate($key, $fallback, $locale);
}
}
@@ -560,14 +599,18 @@ if (Helpers::hasOverride('tc') === false) { // @codeCoverageIgnore
/**
* Translates a count
*
* @param string $key
* @param int $count
* @param string|null $locale
* @param bool $formatNumber If set to `false`, the count is not formatted
* @return mixed
*/
function tc(
string $key,
int $count,
string|null $locale = null,
string $locale = null,
bool $formatNumber = true
): mixed {
) {
return I18n::translateCount($key, $count, $locale, $formatNumber);
}
}
@@ -577,12 +620,12 @@ if (Helpers::hasOverride('timestamp') === false) { // @codeCoverageIgnore
* Rounds the minutes of the given date
* by the defined step
*
* @param string|null $date
* @param int|array|null $step array of `unit` and `size` to round to nearest
* @return int|null
*/
function timestamp(
string|null $date = null,
int|array|null $step = null
): int|null {
function timestamp(?string $date = null, $step = null): ?int
{
return Date::roundedTimestamp($date, $step);
}
}
@@ -591,25 +634,50 @@ if (Helpers::hasOverride('tt') === false) { // @codeCoverageIgnore
/**
* Translate by key and then replace
* placeholders in the text
*
* @param string $key
* @param string|array|null $fallback
* @param array|null $replace
* @param string|null $locale
* @return string
*/
function tt(
string $key,
string|array|null $fallback = null,
array|null $replace = null,
string|null $locale = null
): string {
function tt(string $key, $fallback = null, ?array $replace = null, ?string $locale = null): string
{
return I18n::template($key, $fallback, $replace, $locale);
}
}
if (Helpers::hasOverride('twitter') === false) { // @codeCoverageIgnore
/**
* Builds a Twitter link
*
* @param string $username
* @param string|null $text
* @param string|null $title
* @param string|null $class
* @return string
*/
function twitter(string $username, ?string $text = null, ?string $title = null, ?string $class = null): string
{
return App::instance()->kirbytag([
'twitter' => $username,
'text' => $text,
'title' => $title,
'class' => $class
]);
}
}
if (Helpers::hasOverride('u') === false) { // @codeCoverageIgnore
/**
* Shortcut for url()
*
* @param string|null $path
* @param array|string|null $options
* @return string
*/
function u(
string|null $path = null,
array|string|null $options = null
): string {
function u(?string $path = null, $options = null): string
{
return Url::to($path, $options);
}
}
@@ -617,11 +685,13 @@ if (Helpers::hasOverride('u') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('url') === false) { // @codeCoverageIgnore
/**
* Builds an absolute URL for a given path
*
* @param string|null $path
* @param array|string|null $options
* @return string
*/
function url(
string|null $path = null,
array|string|null $options = null
): string {
function url(?string $path = null, $options = null): string
{
return Url::to($path, $options);
}
}
@@ -629,6 +699,8 @@ if (Helpers::hasOverride('url') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('uuid') === false) { // @codeCoverageIgnore
/**
* Creates a compliant v4 UUID
*
* @return string
*/
function uuid(): string
{
@@ -641,12 +713,14 @@ if (Helpers::hasOverride('video') === false) { // @codeCoverageIgnore
* Creates a video embed via iframe for Youtube or Vimeo
* videos. The embed Urls are automatically detected from
* the given Url.
*
* @param string $url
* @param array $options
* @param array $attr
* @return string|null
*/
function video(
string $url,
array $options = [],
array $attr = []
): string|null {
function video(string $url, array $options = [], array $attr = []): ?string
{
return Html::video($url, $options, $attr);
}
}
@@ -654,12 +728,14 @@ if (Helpers::hasOverride('video') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('vimeo') === false) { // @codeCoverageIgnore
/**
* Embeds a Vimeo video by URL in an iframe
*
* @param string $url
* @param array $options
* @param array $attr
* @return string|null
*/
function vimeo(
string $url,
array $options = [],
array $attr = []
): string|null {
function vimeo(string $url, array $options = [], array $attr = []): ?string
{
return Html::vimeo($url, $options, $attr);
}
}
@@ -669,8 +745,11 @@ if (Helpers::hasOverride('widont') === false) { // @codeCoverageIgnore
* The widont function makes sure that there are no
* typographical widows at the end of a paragraph
* that's a single word in the last line
*
* @param string|null $string
* @return string
*/
function widont(string|null $string = null): string
function widont(string $string = null): string
{
return Str::widont($string);
}
@@ -679,12 +758,14 @@ if (Helpers::hasOverride('widont') === false) { // @codeCoverageIgnore
if (Helpers::hasOverride('youtube') === false) { // @codeCoverageIgnore
/**
* Embeds a Youtube video by URL in an iframe
*
* @param string $url
* @param array $options
* @param array $attr
* @return string|null
*/
function youtube(
string $url,
array $options = [],
array $attr = []
): string|null {
function youtube(string $url, array $options = [], array $attr = []): ?string
{
return Html::youtube($url, $options, $attr);
}
}