Upgrade to 3.4.4

This commit is contained in:
Bastian Allgeier
2020-10-06 10:23:02 +02:00
parent c091f04115
commit 0b80361a79
53 changed files with 976 additions and 83 deletions

View File

@@ -212,6 +212,53 @@ class Api extends BaseApi
]);
}
/**
* Returns the subpages for the given
* parent. The subpages can be filtered
* by status (draft, listed, unlisted, published, all)
*
* @param string|null $parentId
* @param string|null $status
* @return \Kirby\Cms\Pages
*/
public function pages(string $parentId = null, string $status = null)
{
$parent = $parentId === null ? $this->site() : $this->page($parentId);
switch ($status) {
case 'all':
return $parent->childrenAndDrafts();
case 'draft':
case 'drafts':
return $parent->drafts();
case 'listed':
return $parent->children()->listed();
case 'unlisted':
return $parent->children()->unlisted();
case 'published':
default:
return $parent->children();
}
}
/**
* Search for direct subpages of the
* given parent
*
* @param string|null $parent
* @return \Kirby\Cms\Pages
*/
public function searchPages(string $parent = null)
{
$pages = $this->pages($parent, $this->requestQuery('status'));
if ($this->requestMethod() === 'GET') {
return $pages->search($this->requestQuery('q'));
}
return $pages->query($this->requestBody());
}
/**
* Returns the current Session instance
*

View File

@@ -1079,10 +1079,15 @@ class App
// when the page has been found
if ($page) {
try {
return $this
->response()
->body($page->render([], $extension))
->type($extension);
$response = $this->response();
// attach a MIME type based on the representation
// only if no custom MIME type was set
if ($response->type() === null) {
$response->type($extension);
}
return $response->body($page->render([], $extension));
} catch (NotFoundException $e) {
return null;
}

View File

@@ -111,10 +111,14 @@ trait AppErrors
$httpCode = $exception->getHttpCode();
$code = $exception->getCode();
$details = $exception->getDetails();
} else {
} elseif (is_a($exception, '\Throwable') === true) {
$httpCode = 500;
$code = $exception->getCode();
$details = null;
} else {
$httpCode = 500;
$code = 500;
$details = null;
}
if ($this->option('debug') === true) {

View File

@@ -265,6 +265,8 @@ class Auth
// check for blocked ips
if ($this->isBlocked($email) === true) {
$this->kirby->trigger('user.login:failed', compact('email'));
if ($this->kirby->option('debug') === true) {
$message = 'Rate limit exceeded';
} else {
@@ -397,6 +399,8 @@ class Auth
*/
public function track(string $email): bool
{
$this->kirby->trigger('user.login:failed', compact('email'));
$ip = $this->ipHash();
$log = $this->log();
$time = time();

View File

@@ -245,6 +245,9 @@ trait FileActions
F::remove($file->root());
// remove the file from the sibling collection
$file->parent()->files()->remove($file);
return true;
});
}

View File

@@ -86,7 +86,7 @@ class Media
* given filename and then calls the thumb
* component to create a thumbnail accordingly
*
* @param \Kirby\Cms\Model $model
* @param \Kirby\Cms\Model|string $model
* @param string $hash
* @param string $filename
* @return \Kirby\Cms\Response|false
@@ -95,11 +95,14 @@ class Media
{
$kirby = App::instance();
// assets
if (is_string($model) === true) {
// assets
$root = $kirby->root('media') . '/assets/' . $model . '/' . $hash;
// parent files for file model that already included hash
} elseif (is_a($model, '\Kirby\Cms\File')) {
$root = dirname($model->mediaRoot());
// model files
} else {
// model files
$root = $model->mediaRoot() . '/' . $hash;
}

View File

@@ -8,7 +8,6 @@ use Kirby\Exception\NotFoundException;
use Kirby\Http\Uri;
use Kirby\Toolkit\A;
use Kirby\Toolkit\F;
use Kirby\Toolkit\Str;
/**
* The `$page` object is the heart and
@@ -964,11 +963,6 @@ class Page extends ModelWithContent
{
if ($icon = $this->blueprint()->icon()) {
$params['type'] = $icon;
// check for emojis
if (strlen($icon) !== Str::length($icon)) {
$params['emoji'] = true;
}
}
return parent::panelIcon($params);

View File

@@ -27,11 +27,6 @@ class User extends ModelWithContent
use HasSiblings;
use UserActions;
/**
* @var File
*/
protected $avatar;
/**
* @var UserBlueprint
*/
@@ -798,7 +793,7 @@ class User extends ModelWithContent
*/
protected function setName(string $name = null)
{
$this->name = $name !== null ? trim($name) : null;
$this->name = $name !== null ? trim(strip_tags($name)) : null;
return $this;
}

View File

@@ -50,7 +50,7 @@ class UserPermissions extends ModelPermissions
}
// users who are not admins cannot create admins
if ($this->model->isAdmin() === true) {
if ($this->model->isAdmin() === false) {
return false;
}

View File

@@ -6,7 +6,7 @@ use Kirby\Exception\InvalidArgumentException;
use Spyc;
/**
* Simple Wrapper around Symfony's Yaml Component
* Simple Wrapper around the Spyc YAML class
*
* @package Kirby Data
* @author Bastian Allgeier <bastian@getkirby.com>

View File

@@ -19,30 +19,64 @@ class Body
{
use Properties;
/**
* @var string|null
*/
protected $html;
/**
* @var string|null
*/
protected $text;
/**
* Email body constructor
*
* @param array $props
*/
public function __construct(array $props = [])
{
$this->setProperties($props);
}
/**
* Returns the HTML content of the email body
*
* @return string|null
*/
public function html()
{
return $this->html;
}
/**
* Returns the plain text content of the email body
*
* @return string|null
*/
public function text()
{
return $this->text;
}
/**
* Sets the HTML content for the email body
*
* @param string|null $html
* @return self
*/
protected function setHtml(string $html = null)
{
$this->html = $html;
return $this;
}
/**
* Sets the plain text content for the email body
*
* @param string|null $text
* @return self
*/
protected function setText(string $text = null)
{
$this->text = $text;

View File

@@ -21,57 +21,142 @@ class Email
{
use Properties;
/**
* @var array|null
*/
protected $attachments;
/**
* @var \Kirby\Email\Body|null
*/
protected $body;
/**
* @var array|null
*/
protected $bcc;
/**
* @var \Closure|null
*/
protected $beforeSend;
/**
* @var array|null
*/
protected $cc;
/**
* @var string|null
*/
protected $from;
/**
* @var string|null
*/
protected $fromName;
/**
* @var string|null
*/
protected $replyTo;
/**
* @var string|null
*/
protected $replyToName;
/**
* @var bool
*/
protected $isSent = false;
/**
* @var string|null
*/
protected $subject;
/**
* @var array|null
*/
protected $to;
/**
* @var array|null
*/
protected $transport;
/**
* Email constructor
*
* @param array $props
* @param bool $debug
*/
public function __construct(array $props = [], bool $debug = false)
{
$this->setProperties($props);
if ($debug === false) {
$this->send();
$this->send(); // @codeCoverageIgnore
}
}
/**
* Returns the email attachments
*
* @return array
*/
public function attachments(): array
{
return $this->attachments;
}
/**
* @return \Kirby\Email\Body
* Returns the email body
*
* @return \Kirby\Email\Body|null
*/
public function body()
{
return $this->body;
}
/**
* Returns "bcc" recipients
*
* @return array
*/
public function bcc(): array
{
return $this->bcc;
}
/**
* Returns the beforeSend callback closure,
* which has access to the PHPMailer instance
*
* @return \Closure|null
*/
public function beforeSend(): ?Closure
{
return $this->beforeSend;
}
/**
* Returns "cc" recipients
*
* @return array
*/
public function cc(): array
{
return $this->cc;
}
/**
* Returns default transport settings
*
* @return array
*/
protected function defaultTransport(): array
{
return [
@@ -79,36 +164,74 @@ class Email
];
}
/**
* Returns the "from" email address
*
* @return string
*/
public function from(): string
{
return $this->from;
}
/**
* Returns the "from" name
*
* @return string|null
*/
public function fromName(): ?string
{
return $this->fromName;
}
/**
* Checks if the email has an HTML body
*
* @return bool
*/
public function isHtml()
{
return $this->body()->html() !== null;
}
/**
* Checks if the email has been sent successfully
*
* @return bool
*/
public function isSent(): bool
{
return $this->isSent;
}
/**
* Returns the "reply to" email address
*
* @return string
*/
public function replyTo(): string
{
return $this->replyTo;
}
/**
* Returns the "reply to" name
*
* @return string|null
*/
public function replyToName(): ?string
{
return $this->replyToName;
}
/**
* Converts single or multiple email addresses to a sanitized format
*
* @param string|array|null $email
* @param bool $multiple
* @return array|mixed|string
* @throws \Exception
*/
protected function resolveEmail($email = null, bool $multiple = true)
{
if ($email === null) {
@@ -139,17 +262,34 @@ class Email
return $multiple === true ? $result : array_keys($result)[0];
}
/**
* Sends the email
*
* @return bool
*/
public function send(): bool
{
return $this->isSent = true;
}
/**
* Sets the email attachments
*
* @param array|null $attachments
* @return self
*/
protected function setAttachments($attachments = null)
{
$this->attachments = $attachments ?? [];
return $this;
}
/**
* Sets the email body
*
* @param string|array $body
* @return self
*/
protected function setBody($body)
{
if (is_string($body) === true) {
@@ -160,76 +300,151 @@ class Email
return $this;
}
/**
* Sets "bcc" recipients
*
* @param string|array|null $bcc
* @return $this
*/
protected function setBcc($bcc = null)
{
$this->bcc = $this->resolveEmail($bcc);
return $this;
}
/**
* Sets the "beforeSend" callback
*
* @param \Closure|null $beforeSend
* @return self
*/
protected function setBeforeSend(?Closure $beforeSend = null)
{
$this->beforeSend = $beforeSend;
return $this;
}
/**
* Sets "cc" recipients
*
* @param string|array|null $cc
* @return self
*/
protected function setCc($cc = null)
{
$this->cc = $this->resolveEmail($cc);
return $this;
}
/**
* Sets the "from" email address
*
* @param string $from
* @return self
*/
protected function setFrom(string $from)
{
$this->from = $this->resolveEmail($from, false);
return $this;
}
/**
* Sets the "from" name
*
* @param string|null $fromName
* @return self
*/
protected function setFromName(string $fromName = null)
{
$this->fromName = $fromName;
return $this;
}
/**
* Sets the "reply to" email address
*
* @param string|null $replyTo
* @return self
*/
protected function setReplyTo(string $replyTo = null)
{
$this->replyTo = $this->resolveEmail($replyTo, false);
return $this;
}
/**
* Sets the "reply to" name
*
* @param string|null $replyToName
* @return self
*/
protected function setReplyToName(string $replyToName = null)
{
$this->replyToName = $replyToName;
return $this;
}
/**
* Sets the email subject
*
* @param string $subject
* @return self
*/
protected function setSubject(string $subject)
{
$this->subject = $subject;
return $this;
}
/**
* Sets the recipients of the email
*
* @param string|array $to
* @return self
*/
protected function setTo($to)
{
$this->to = $this->resolveEmail($to);
return $this;
}
/**
* Sets the email transport settings
*
* @param array|null $transport
* @return self
*/
protected function setTransport($transport = null)
{
$this->transport = $transport;
return $this;
}
/**
* Returns the email subject
*
* @return string
*/
public function subject(): string
{
return $this->subject;
}
/**
* Returns the email recipients
*
* @return array
*/
public function to(): array
{
return $this->to;
}
/**
* Returns the email transports settings
*
* @return array
*/
public function transport(): array
{
return $this->transport ?? $this->defaultTransport();

View File

@@ -17,6 +17,13 @@ use PHPMailer\PHPMailer\PHPMailer as Mailer;
*/
class PHPMailer extends Email
{
/**
* Sends email via PHPMailer library
*
* @param bool $debug
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public function send(bool $debug = false): bool
{
$mailer = new Mailer(true);
@@ -83,6 +90,6 @@ class PHPMailer extends Email
return $this->isSent = true;
}
return $this->isSent = $mailer->send();
return $this->isSent = $mailer->send(); // @codeCoverageIgnore
}
}

View File

@@ -3,7 +3,6 @@
namespace Kirby\Form;
use Exception;
use Kirby\Cms\Model;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Toolkit\A;
use Kirby\Toolkit\Component;
@@ -51,6 +50,14 @@ class Field extends Component
*/
public static $types = [];
/**
* Field constructor
*
* @param string $type
* @param array $attrs
* @param \Kirby\Form\Fields|null $formFields
* @throws \Kirby\Exception\InvalidArgumentException
*/
public function __construct(string $type, array $attrs = [], ?Fields $formFields = null)
{
if (isset(static::$types[$type]) === false) {
@@ -71,6 +78,8 @@ class Field extends Component
}
/**
* Returns field api call
*
* @return mixed
*/
public function api()
@@ -81,10 +90,12 @@ class Field extends Component
}
/**
* @param mixed $default
* Returns field data
*
* @param bool $default
* @return mixed
*/
public function data($default = false)
public function data(bool $default = false)
{
$save = $this->options['save'] ?? true;
@@ -103,6 +114,11 @@ class Field extends Component
}
}
/**
* Default props and computed of the field
*
* @return array
*/
public static function defaults(): array
{
return [
@@ -232,11 +248,21 @@ class Field extends Component
];
}
/**
* Parent collection with all fields of the current form
*
* @return \Kirby\Form\Fields|null
*/
public function formFields(): ?Fields
{
return $this->formFields;
}
/**
* Validates when run for the first time and returns any errors
*
* @return array
*/
public function errors(): array
{
if ($this->errors === null) {
@@ -246,6 +272,12 @@ class Field extends Component
return $this->errors;
}
/**
* Checks if the field is empty
*
* @param mixed ...$args
* @return bool
*/
public function isEmpty(...$args): bool
{
if (count($args) === 0) {
@@ -261,22 +293,39 @@ class Field extends Component
return in_array($value, [null, '', []], true);
}
/**
* Checks if the field is invalid
*
* @return bool
*/
public function isInvalid(): bool
{
return empty($this->errors()) === false;
}
/**
* Checks if the field is required
*
* @return bool
*/
public function isRequired(): bool
{
return $this->required ?? false;
}
/**
* Checks if the field is valid
*
* @return bool
*/
public function isValid(): bool
{
return empty($this->errors()) === true;
}
/**
* Returns the Kirby instance
*
* @return \Kirby\Cms\App
*/
public function kirby()
@@ -284,6 +333,11 @@ class Field extends Component
return $this->model->kirby();
}
/**
* Returns the parent model
*
* @return mixed|null
*/
public function model()
{
return $this->model;
@@ -329,11 +383,21 @@ class Field extends Component
return true;
}
/**
* Checks if the field is saveable
*
* @return bool
*/
public function save(): bool
{
return ($this->options['save'] ?? true) !== false;
}
/**
* Converts the field to a plain array
*
* @return array
*/
public function toArray(): array
{
$array = parent::toArray();
@@ -352,6 +416,11 @@ class Field extends Component
});
}
/**
* Runs the validations defined for the field
*
* @return void
*/
protected function validate(): void
{
$validations = $this->options['validations'] ?? [];
@@ -395,6 +464,12 @@ class Field extends Component
}
}
/**
* Returns the value of the field if saveable
* otherwise it returns null
*
* @return mixed
*/
public function value()
{
return $this->save() ? $this->value : null;

View File

@@ -22,11 +22,12 @@ class Fields extends Collection
* the collection prop on each object correctly.
*
* @param string $name
* @param object $field
* @param object|array $field
* @return self
*/
public function __set(string $name, $field)
{
if (is_array($field)) {
if (is_array($field) === true) {
// use the array key as name if the name is not set
$field['name'] = $field['name'] ?? $name;
$field = new Field($field['type'], $field);
@@ -40,7 +41,7 @@ class Fields extends Collection
* array and also does that for every
* included field.
*
* @param Closure $map
* @param \Closure|null $map
* @return array
*/
public function toArray(Closure $map = null): array

View File

@@ -19,10 +19,32 @@ use Throwable;
*/
class Form
{
/**
* An array of all found errors
*
* @var array|null
*/
protected $errors;
/**
* Fields in the form
*
* @var \Kirby\Form\Fields|null
*/
protected $fields;
/**
* All values of form
*
* @var array
*/
protected $values = [];
/**
* Form constructor
*
* @param array $props
*/
public function __construct(array $props)
{
$fields = $props['fields'] ?? [];
@@ -85,11 +107,24 @@ class Form
}
}
/**
* Returns the data required to write to the content file
* Doesn't include default and null values
*
* @return array
*/
public function content(): array
{
return $this->data(false, false);
}
/**
* Returns data for all fields in the form
*
* @param false $defaults
* @param bool $includeNulls
* @return array
*/
public function data($defaults = false, bool $includeNulls = true): array
{
$data = $this->values;
@@ -109,6 +144,11 @@ class Form
return $data;
}
/**
* An array of all found errors
*
* @return array
*/
public function errors(): array
{
if ($this->errors !== null) {
@@ -129,6 +169,13 @@ class Form
return $this->errors;
}
/**
* Shows the error with the field
*
* @param \Throwable $exception
* @param array $props
* @return \Kirby\Form\Field
*/
public static function exceptionField(Throwable $exception, array $props = [])
{
$props = array_merge($props, [
@@ -140,21 +187,42 @@ class Form
return new Field('info', $props);
}
/**
* Returns form fields
*
* @return \Kirby\Form\Fields|null
*/
public function fields()
{
return $this->fields;
}
/**
* Checks if the form is invalid
*
* @return bool
*/
public function isInvalid(): bool
{
return empty($this->errors()) === false;
}
/**
* Checks if the form is valid
*
* @return bool
*/
public function isValid(): bool
{
return empty($this->errors()) === true;
}
/**
* Converts the data of fields to strings
*
* @param false $defaults
* @return array
*/
public function strings($defaults = false): array
{
$strings = [];
@@ -172,6 +240,11 @@ class Form
return $strings;
}
/**
* Converts the form to a plain array
*
* @return array
*/
public function toArray(): array
{
$array = [
@@ -185,6 +258,11 @@ class Form
return $array;
}
/**
* Returns form values
*
* @return array
*/
public function values(): array
{
return $this->values;

View File

@@ -19,6 +19,11 @@ use Kirby\Toolkit\I18n;
*/
class Options
{
/**
* Returns the classes of predefined Kirby objects
*
* @return array
*/
protected static function aliases(): array
{
return [
@@ -30,6 +35,13 @@ class Options
];
}
/**
* Brings options through api
*
* @param $api
* @param $model
* @return array
*/
public static function api($api, $model = null): array
{
$model = $model ?? App::instance()->site();
@@ -57,6 +69,10 @@ class Options
return $optionsApi->options();
}
/**
* @param $model
* @return array
*/
protected static function data($model): array
{
$kirby = $model->kirby();
@@ -78,6 +94,14 @@ class Options
return $data;
}
/**
* Brings options by supporting both api and query
*
* @param $options
* @param array $props
* @param null $model
* @return array
*/
public static function factory($options, array $props = [], $model = null): array
{
switch ($options) {
@@ -131,6 +155,13 @@ class Options
return $result;
}
/**
* Brings options with query
*
* @param $query
* @param null $model
* @return array
*/
public static function query($query, $model = null): array
{
$model = $model ?? App::instance()->site();

View File

@@ -25,34 +25,78 @@ class OptionsApi
{
use Properties;
/**
* @var
*/
protected $data;
/**
* @var
*/
protected $fetch;
/**
* @var
*/
protected $options;
/**
* @var string
*/
protected $text = '{{ item.value }}';
/**
* @var
*/
protected $url;
/**
* @var string
*/
protected $value = '{{ item.key }}';
/**
* OptionsApi constructor
*
* @param array $props
*/
public function __construct(array $props)
{
$this->setProperties($props);
}
/**
* @return array
*/
public function data(): array
{
return $this->data;
}
/**
* @return mixed
*/
public function fetch()
{
return $this->fetch;
}
/**
* @param string $field
* @param array $data
* @return string
*/
protected function field(string $field, array $data)
{
$value = $this->$field();
return Str::template($value, $data);
}
/**
* @return array
* @throws \Exception
* @throws \Kirby\Exception\InvalidArgumentException
*/
public function options(): array
{
if (is_array($this->options) === true) {
@@ -103,51 +147,94 @@ class OptionsApi
return $options;
}
/**
* @param array $data
* @return self
*/
protected function setData(array $data)
{
$this->data = $data;
return $this;
}
/**
* @param string|null $fetch
* @return self
*/
protected function setFetch(string $fetch = null)
{
$this->fetch = $fetch;
return $this;
}
/**
* @param $options
* @return self
*/
protected function setOptions($options = null)
{
$this->options = $options;
return $this;
}
/**
* @param $text
* @return self
*/
protected function setText($text = null)
{
$this->text = $text;
return $this;
}
/**
* @param $url
* @return self
*/
protected function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* @param null $value
* @return self
*/
protected function setValue($value = null)
{
$this->value = $value;
return $this;
}
/**
* @return string
*/
public function text()
{
return $this->text;
}
/**
* @return array
* @throws \Kirby\Exception\InvalidArgumentException
*/
public function toArray(): array
{
return $this->options();
}
/**
* @return string
*/
public function url(): string
{
return Str::template($this->url, $this->data());
}
/**
* @return string
*/
public function value()
{
return $this->value;

View File

@@ -27,28 +27,69 @@ class OptionsQuery
{
use Properties;
/**
* @var array
*/
protected $aliases = [];
/**
* @var
*/
protected $data;
/**
* @var
*/
protected $options;
/**
* @var
*/
protected $query;
/**
* @var
*/
protected $text;
/**
* @var
*/
protected $value;
/**
* OptionsQuery constructor
*
* @param array $props
*/
public function __construct(array $props)
{
$this->setProperties($props);
}
/**
* @return array
*/
public function aliases(): array
{
return $this->aliases;
}
/**
* @return array
*/
public function data(): array
{
return $this->data;
}
/**
* @param string $object
* @param string $field
* @param array $data
* @return string
* @throws \Kirby\Exception\NotFoundException
*/
protected function template(string $object, string $field, array $data)
{
$value = $this->$field();
@@ -64,6 +105,9 @@ class OptionsQuery
return Str::template($value, $data);
}
/**
* @return array
*/
public function options(): array
{
if (is_array($this->options) === true) {
@@ -89,11 +133,18 @@ class OptionsQuery
return $this->options = $options;
}
/**
* @return string
*/
public function query(): string
{
return $this->query;
}
/**
* @param $object
* @return mixed|string|null
*/
public function resolve($object)
{
// fast access
@@ -111,6 +162,10 @@ class OptionsQuery
return 'item';
}
/**
* @param $result
* @throws \Kirby\Exception\InvalidArgumentException
*/
protected function resultToCollection($result)
{
if (is_array($result)) {
@@ -133,36 +188,69 @@ class OptionsQuery
return $result;
}
/**
* @param array|null $aliases
* @return self
*/
protected function setAliases(array $aliases = null)
{
$this->aliases = $aliases;
return $this;
}
/**
* @param array $data
* @return self
*/
protected function setData(array $data)
{
$this->data = $data;
return $this;
}
/**
* @param $options
* @return self
*/
protected function setOptions($options = null)
{
$this->options = $options;
return $this;
}
/**
* @param string $query
* @return self
*/
protected function setQuery(string $query)
{
$this->query = $query;
return $this;
}
/**
* @param $text
* @return self
*/
protected function setText($text)
{
$this->text = $text;
return $this;
}
/**
* @param $value
* @return self
*/
protected function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* @return mixed
*/
public function text()
{
return $this->text;
@@ -173,6 +261,9 @@ class OptionsQuery
return $this->options();
}
/**
* @return mixed
*/
public function value()
{
return $this->value;

View File

@@ -16,6 +16,14 @@ use Kirby\Toolkit\V;
*/
class Validations
{
/**
* Validates if the field value is boolean
*
* @param \Kirby\Form\Field $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function boolean(Field $field, $value): bool
{
if ($field->isEmpty($value) === false) {
@@ -29,6 +37,14 @@ class Validations
return true;
}
/**
* Validates if the field value is valid date
*
* @param \Kirby\Form\Field $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function date(Field $field, $value): bool
{
if ($field->isEmpty($value) === false) {
@@ -42,6 +58,14 @@ class Validations
return true;
}
/**
* Validates if the field value is valid email
*
* @param \Kirby\Form\Field $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function email(Field $field, $value): bool
{
if ($field->isEmpty($value) === false) {
@@ -55,6 +79,14 @@ class Validations
return true;
}
/**
* Validates if the field value is maximum
*
* @param \Kirby\Form\Field $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function max(Field $field, $value): bool
{
if ($field->isEmpty($value) === false && $field->max() !== null) {
@@ -68,6 +100,14 @@ class Validations
return true;
}
/**
* Validates if the field value is max length
*
* @param \Kirby\Form\Field $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function maxlength(Field $field, $value): bool
{
if ($field->isEmpty($value) === false && $field->maxlength() !== null) {
@@ -81,6 +121,14 @@ class Validations
return true;
}
/**
* Validates if the field value is minimum
*
* @param \Kirby\Form\Field $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function min(Field $field, $value): bool
{
if ($field->isEmpty($value) === false && $field->min() !== null) {
@@ -94,6 +142,14 @@ class Validations
return true;
}
/**
* Validates if the field value is min length
*
* @param \Kirby\Form\Field $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function minlength(Field $field, $value): bool
{
if ($field->isEmpty($value) === false && $field->minlength() !== null) {
@@ -107,6 +163,14 @@ class Validations
return true;
}
/**
* Validates if the field value matches defined pattern
*
* @param \Kirby\Form\Field $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function pattern(Field $field, $value): bool
{
if ($field->isEmpty($value) === false && $field->pattern() !== null) {
@@ -120,6 +184,14 @@ class Validations
return true;
}
/**
* Validates if the field value is required
*
* @param \Kirby\Form\Field $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function required(Field $field, $value): bool
{
if ($field->isRequired() === true && $field->save() === true && $field->isEmpty($value) === true) {
@@ -131,6 +203,14 @@ class Validations
return true;
}
/**
* Validates if the field value is in defined options
*
* @param \Kirby\Form\Field $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function option(Field $field, $value): bool
{
if ($field->isEmpty($value) === false) {
@@ -146,6 +226,14 @@ class Validations
return true;
}
/**
* Validates if the field values is in defined options
*
* @param \Kirby\Form\Field $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function options(Field $field, $value): bool
{
if ($field->isEmpty($value) === false) {
@@ -162,6 +250,14 @@ class Validations
return true;
}
/**
* Validates if the field value is valid time
*
* @param \Kirby\Form\Field $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function time(Field $field, $value): bool
{
if ($field->isEmpty($value) === false) {
@@ -175,6 +271,14 @@ class Validations
return true;
}
/**
* Validates if the field value is valid url
*
* @param \Kirby\Form\Field $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function url(Field $field, $value): bool
{
if ($field->isEmpty($value) === false) {

View File

@@ -71,10 +71,13 @@ class F
],
'image' => [
'ai',
'avif',
'bmp',
'gif',
'eps',
'ico',
'j2k',
'jp2',
'jpeg',
'jpg',
'jpe',

View File

@@ -29,6 +29,7 @@ class Mime
'aifc' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'avi' => 'video/x-msvideo',
'avif' => 'image/avif',
'bmp' => 'image/bmp',
'css' => 'text/css',
'csv' => ['text/csv', 'text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream'],
@@ -48,6 +49,8 @@ class Mime
'ics' => 'text/calendar',
'js' => 'application/x-javascript',
'json' => ['application/json', 'text/json'],
'j2k' => ['image/jp2'],
'jp2' => ['image/jp2'],
'jpg' => ['image/jpeg', 'image/pjpeg'],
'jpeg' => ['image/jpeg', 'image/pjpeg'],
'jpe' => ['image/jpeg', 'image/pjpeg'],

View File

@@ -353,17 +353,18 @@ class Pagination
return range($start, $end);
}
$start = $page - (int)floor($range/2);
$end = $page + (int)floor($range/2);
$middle = (int)floor($range/2);
$start = $page - $middle + ($range % 2 === 0);
$end = $start + $range - 1;
if ($start <= 0) {
$end += abs($start);
$start = 1;
$end = $range;
$start = 1;
}
if ($end > $pages) {
$start -= $end - $pages;
$end = $pages;
$start = $pages - $range + 1;
$end = $pages;
}
return range($start, $end);