Add blueprints and fake content

This commit is contained in:
Paul Nicoué 2021-11-18 17:44:47 +01:00
parent 1ff19bf38f
commit 8235816462
592 changed files with 22385 additions and 31535 deletions

View file

@ -1,13 +1,14 @@
<?php
use Kirby\Cms\App;
use Kirby\Cms\Asset;
use Kirby\Cms\Html;
use Kirby\Cms\Response;
use Kirby\Cms\Url;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Filesystem\Asset;
use Kirby\Filesystem\F;
use Kirby\Http\Router;
use Kirby\Toolkit\Escape;
use Kirby\Toolkit\F;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Str;
use Kirby\Toolkit\V;
@ -16,7 +17,7 @@ use Kirby\Toolkit\V;
* Helper to create an asset object
*
* @param string $path
* @return \Kirby\Cms\Asset
* @return \Kirby\Filesystem\Asset
*/
function asset(string $path)
{
@ -26,12 +27,12 @@ function asset(string $path)
/**
* Generates a list of HTML attributes
*
* @param array $attr A list of attributes as key/value array
* @param string $before An optional string that will be prepended if the result is not empty
* @param string $after An optional string that will be appended if the result is not empty
* @return string
* @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 $attr = null, $before = null, $after = null)
function attr(?array $attr = null, ?string $before = null, ?string $after = null): ?string
{
if ($attrs = Html::attr($attr)) {
return $before . $attrs . $after;
@ -54,28 +55,33 @@ function collection(string $name)
/**
* Checks / returns a CSRF token
*
* @param string $check Pass a token here to compare it to the one in the session
* @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 $check = null)
function csrf(?string $check = null)
{
$session = App::instance()->session();
// check explicitly if there have been no arguments at all;
// no arguments, generate/return a token
// (check explicitly if there have been no arguments at all;
// checking for null introduces a security issue because null could come
// from user input or bugs in the calling code!
// from user input or bugs in the calling code!)
if (func_num_args() === 0) {
// no arguments, generate/return a token
$token = $session->get('kirby.csrf');
if (is_string($token) !== true) {
$token = bin2hex(random_bytes(32));
$session->set('kirby.csrf', $token);
}
return $token;
} elseif (is_string($check) === true && is_string($session->get('kirby.csrf')) === true) {
// argument has been passed, check the token
}
// argument has been passed, check the token
if (
is_string($check) === true &&
is_string($session->get('kirby.csrf')) === true
) {
return hash_equals($session->get('kirby.csrf'), $check) === true;
}
@ -174,7 +180,7 @@ if (function_exists('e') === false) {
* @param string $context Location of output (`html`, `attr`, `js`, `css`, `url` or `xml`)
* @return string Escaped data
*/
function esc($string, $context = 'html')
function esc(string $string, string $context = 'html'): string
{
if (method_exists('Kirby\Toolkit\Escape', $context) === true) {
return Escape::$context($string);
@ -200,10 +206,10 @@ function get($key = null, $default = null)
* Embeds a Github Gist
*
* @param string $url
* @param string $file
* @param string|null $file
* @return string
*/
function gist(string $url, string $file = null): string
function gist(string $url, ?string $file = null): string
{
return kirbytag([
'gist' => $url,
@ -255,10 +261,10 @@ function html(?string $string, bool $keepTags = false)
* Example:
* <?= image('some/page/myimage.jpg') ?>
*
* @param string $path
* @param string|null $path
* @return \Kirby\Cms\File|null
*/
function image(string $path = null)
function image(?string $path = null)
{
if ($path === null) {
return page()->image();
@ -296,9 +302,9 @@ function image(string $path = null)
* @param array $data
* @param array $rules
* @param array $messages
* @return false|array
* @return array
*/
function invalid(array $data = [], array $rules = [], array $messages = [])
function invalid(array $data = [], array $rules = [], array $messages = []): array
{
$errors = [];
@ -407,12 +413,12 @@ function kirby()
* Makes it possible to use any defined Kirbytag as standalone function
*
* @param string|array $type
* @param string $value
* @param string|null $value
* @param array $attr
* @param array $data
* @return string
*/
function kirbytag($type, string $value = null, array $attr = [], array $data = []): string
function kirbytag($type, ?string $value = null, array $attr = [], array $data = []): string
{
if (is_array($type) === true) {
$kirbytag = $type;
@ -434,11 +440,11 @@ function kirbytag($type, string $value = null, array $attr = [], array $data = [
* Parses KirbyTags in the given string. Shortcut
* for `$kirby->kirbytags($text, $data)`
*
* @param string $text
* @param string|null $text
* @param array $data
* @return string
*/
function kirbytags(string $text = null, array $data = []): string
function kirbytags(?string $text = null, array $data = []): string
{
return App::instance()->kirbytags($text, $data);
}
@ -447,11 +453,11 @@ function kirbytags(string $text = null, array $data = []): string
* Parses KirbyTags and Markdown in the
* given string. Shortcut for `$kirby->kirbytext()`
*
* @param string $text
* @param string|null $text
* @param array $data
* @return string
*/
function kirbytext(string $text = null, array $data = []): string
function kirbytext(?string $text = null, array $data = []): string
{
return App::instance()->kirbytext($text, $data);
}
@ -461,11 +467,11 @@ function kirbytext(string $text = null, array $data = []): string
* given string.
* @since 3.1.0
*
* @param string $text
* @param string|null $text
* @param array $data
* @return string
*/
function kirbytextinline(string $text = null, array $data = []): string
function kirbytextinline(?string $text = null, array $data = []): string
{
return App::instance()->kirbytext($text, $data, true);
}
@ -473,11 +479,11 @@ function kirbytextinline(string $text = null, array $data = []): string
/**
* Shortcut for `kirbytext()` helper
*
* @param string $text
* @param string|null $text
* @param array $data
* @return string
*/
function kt(string $text = null, array $data = []): string
function kt(?string $text = null, array $data = []): string
{
return kirbytext($text, $data);
}
@ -486,11 +492,11 @@ function kt(string $text = null, array $data = []): string
* Shortcut for `kirbytextinline()` helper
* @since 3.1.0
*
* @param string $text
* @param string|null $text
* @param array $data
* @return string
*/
function kti(string $text = null, array $data = []): string
function kti(?string $text = null, array $data = []): string
{
return kirbytextinline($text, $data);
}
@ -499,10 +505,10 @@ function kti(string $text = null, array $data = []): string
* A super simple class autoloader
*
* @param array $classmap
* @param string $base
* @param string|null $base
* @return void
*/
function load(array $classmap, string $base = null)
function load(array $classmap, ?string $base = null)
{
// convert all classnames to lowercase
$classmap = array_change_key_case($classmap);
@ -526,10 +532,10 @@ function load(array $classmap, string $base = null)
* Parses markdown in the given string. Shortcut for
* `$kirby->markdown($text)`
*
* @param string $text
* @param string|null $text
* @return string
*/
function markdown(string $text = null): string
function markdown(?string $text = null): string
{
return App::instance()->markdown($text);
}
@ -551,7 +557,8 @@ function option(string $key, $default = null)
* id or the current page when no id is specified
*
* @param string|array ...$id
* @return \Kirby\Cms\Page|null
* @return \Kirby\Cms\Page|\Kirby\Cms\Pages|null
* @todo reduce to one parameter in 3.7.0 (also change return and return type)
*/
function page(...$id)
{
@ -559,6 +566,12 @@ function page(...$id)
return App::instance()->site()->page();
}
if (count($id) > 1) {
// @codeCoverageIgnoreStart
deprecated('Passing multiple parameters to the `page()` helper has been deprecated. Please use the `pages()` helper instead.');
// @codeCoverageIgnoreEnd
}
return App::instance()->site()->find(...$id);
}
@ -566,10 +579,17 @@ function page(...$id)
* Helper to build page collections
*
* @param string|array ...$id
* @return \Kirby\Cms\Pages
* @return \Kirby\Cms\Page|\Kirby\Cms\Pages|null
* @todo return only Pages|null in 3.7.0, wrap in Pages for single passed id
*/
function pages(...$id)
{
if (count($id) === 1) {
// @codeCoverageIgnoreStart
deprecated('Passing a single id to the `pages()` helper will return a Kirby\Cms\Pages collection with a single element instead of the single Kirby\Cms\Page object itself - starting in 3.7.0.');
// @codeCoverageIgnoreEnd
}
return App::instance()->site()->find(...$id);
}
@ -577,10 +597,10 @@ function pages(...$id)
* Returns a single param from the URL
*
* @param string $key
* @param string $fallback
* @param string|null $fallback
* @return string|null
*/
function param(string $key, string $fallback = null): ?string
function param(string $key, ?string $fallback = null): ?string
{
return App::instance()->request()->url()->params()->$key ?? $fallback;
}
@ -608,6 +628,22 @@ function r($condition, $value, $alternative = null)
return $condition ? $value : $alternative;
}
/**
* 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 $path = null, string $method = 'GET', array $routes = [], ?Closure $callback = null)
{
return (new Router($routes))->call($path, $method, $callback);
}
/**
* Returns the current site object
*
@ -623,6 +659,7 @@ function site()
*
* @param mixed $value
* @return int
* @throws \Kirby\Exception\InvalidArgumentException
*/
function size($value): int
{
@ -655,10 +692,10 @@ function size($value): int
* Enhances the given string with
* smartypants. Shortcut for `$kirby->smartypants($text)`
*
* @param string $text
* @param string|null $text
* @return string
*/
function smartypants(string $text = null): string
function smartypants(?string $text = null): string
{
return App::instance()->smartypants($text);
}
@ -725,7 +762,7 @@ function svg($file)
*
* @param string|array $key
* @param string|null $fallback
* @return mixed
* @return array|string|null
*/
function t($key, string $fallback = null)
{
@ -735,11 +772,11 @@ function t($key, string $fallback = null)
/**
* Translates a count
*
* @param string|array $key
* @param string $key
* @param int $count
* @return mixed
*/
function tc($key, int $count)
function tc(string $key, int $count)
{
return I18n::translateCount($key, $count);
}
@ -748,11 +785,11 @@ function tc($key, int $count)
* Rounds the minutes of the given date
* by the defined step
*
* @param string $date
* @param int $step array of `unit` and `size` to round to nearest
* @param string|null $date
* @param int|array|null $step array of `unit` and `size` to round to nearest
* @return int|null
*/
function timestamp(string $date = null, $step = null): ?int
function timestamp(?string $date = null, $step = null): ?int
{
if (V::date($date) === false) {
return null;
@ -807,7 +844,7 @@ function timestamp(string $date = null, $step = null): ?int
);
// on error, convert `false` into `null`
return $timestamp ? $timestamp : null;
return $timestamp ?? null;
}
/**
@ -815,12 +852,12 @@ function timestamp(string $date = null, $step = null): ?int
* placeholders in the text
*
* @param string $key
* @param string $fallback
* @param array $replace
* @param string $locale
* @param string|array|null $fallback
* @param array|null $replace
* @param string|null $locale
* @return string
*/
function tt(string $key, $fallback = null, array $replace = null, string $locale = null)
function tt(string $key, $fallback = null, ?array $replace = null, ?string $locale = null)
{
return I18n::template($key, $fallback, $replace, $locale);
}
@ -829,12 +866,12 @@ function tt(string $key, $fallback = null, array $replace = null, string $locale
* Builds a Twitter link
*
* @param string $username
* @param string $text
* @param string $title
* @param string $class
* @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
function twitter(string $username, ?string $text = null, ?string $title = null, ?string $class = null): string
{
return kirbytag([
'twitter' => $username,
@ -847,11 +884,11 @@ function twitter(string $username, string $text = null, string $title = null, st
/**
* Shortcut for url()
*
* @param string $path
* @param string|null $path
* @param array|string|null $options
* @return string
*/
function u(string $path = null, $options = null): string
function u(?string $path = null, $options = null): string
{
return Url::to($path, $options);
}
@ -859,11 +896,11 @@ function u(string $path = null, $options = null): string
/**
* Builds an absolute URL for a given path
*
* @param string $path
* @param string|null $path
* @param array|string|null $options
* @return string
*/
function url(string $path = null, $options = null): string
function url(?string $path = null, $options = null): string
{
return Url::to($path, $options);
}
@ -906,9 +943,9 @@ function uuid(): string
* @param string $url
* @param array $options
* @param array $attr
* @return string
* @return string|null
*/
function video(string $url, array $options = [], array $attr = []): string
function video(string $url, array $options = [], array $attr = []): ?string
{
return Html::video($url, $options, $attr);
}
@ -919,9 +956,9 @@ function video(string $url, array $options = [], array $attr = []): string
* @param string $url
* @param array $options
* @param array $attr
* @return string
* @return string|null
*/
function vimeo(string $url, array $options = [], array $attr = []): string
function vimeo(string $url, array $options = [], array $attr = []): ?string
{
return Html::vimeo($url, $options, $attr);
}
@ -945,9 +982,9 @@ function widont(string $string = null): string
* @param string $url
* @param array $options
* @param array $attr
* @return string
* @return string|null
*/
function youtube(string $url, array $options = [], array $attr = []): string
function youtube(string $url, array $options = [], array $attr = []): ?string
{
return Html::youtube($url, $options, $attr);
}