From 1ad1eaf387950c989728334ffc63e96aeaa01d73 Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 12 Jul 2022 13:33:21 +0200 Subject: [PATCH] Upgrade to 3.7.1 --- kirby/.editorconfig | 15 +- kirby/bootstrap.php | 36 +- kirby/composer.json | 216 +- kirby/composer.lock | 2 +- kirby/config/aliases.php | 136 +- kirby/config/api/authentication.php | 34 +- kirby/config/api/collections.php | 110 +- kirby/config/api/models.php | 26 +- kirby/config/api/models/File.php | 204 +- kirby/config/api/models/FileBlueprint.php | 18 +- kirby/config/api/models/FileVersion.php | 100 +- kirby/config/api/models/Language.php | 42 +- kirby/config/api/models/Page.php | 220 +- kirby/config/api/models/PageBlueprint.php | 24 +- kirby/config/api/models/Role.php | 28 +- kirby/config/api/models/Site.php | 84 +- kirby/config/api/models/SiteBlueprint.php | 16 +- kirby/config/api/models/System.php | 172 +- kirby/config/api/models/Translation.php | 30 +- kirby/config/api/models/User.php | 134 +- kirby/config/api/models/UserBlueprint.php | 18 +- kirby/config/api/routes.php | 34 +- kirby/config/api/routes/auth.php | 176 +- kirby/config/api/routes/files.php | 238 +- kirby/config/api/routes/languages.php | 78 +- kirby/config/api/routes/lock.php | 72 +- kirby/config/api/routes/pages.php | 224 +- kirby/config/api/routes/roles.php | 44 +- kirby/config/api/routes/site.php | 186 +- kirby/config/api/routes/system.php | 118 +- kirby/config/api/routes/translations.php | 32 +- kirby/config/api/routes/users.php | 394 +- kirby/config/areas/account.php | 16 +- kirby/config/areas/account/dialogs.php | 108 +- kirby/config/areas/account/dropdowns.php | 16 +- kirby/config/areas/account/views.php | 54 +- kirby/config/areas/files/dialogs.php | 210 +- kirby/config/areas/files/dropdowns.php | 6 +- kirby/config/areas/installation.php | 66 +- kirby/config/areas/languages.php | 14 +- kirby/config/areas/languages/dialogs.php | 260 +- kirby/config/areas/languages/views.php | 34 +- kirby/config/areas/login.php | 74 +- kirby/config/areas/site.php | 24 +- kirby/config/areas/site/dialogs.php | 1132 +++--- kirby/config/areas/site/dropdowns.php | 36 +- kirby/config/areas/site/searches.php | 86 +- kirby/config/areas/site/views.php | 40 +- kirby/config/areas/system.php | 14 +- kirby/config/areas/system/dialogs.php | 150 +- kirby/config/areas/system/views.php | 92 +- kirby/config/areas/users.php | 20 +- kirby/config/areas/users/dialogs.php | 520 +-- kirby/config/areas/users/dropdowns.php | 20 +- kirby/config/areas/users/searches.php | 34 +- kirby/config/areas/users/views.php | 108 +- kirby/config/blocks/image/image.php | 6 +- kirby/config/components.php | 662 ++-- kirby/config/fields/checkboxes.php | 106 +- kirby/config/fields/date.php | 262 +- kirby/config/fields/email.php | 62 +- kirby/config/fields/files.php | 232 +- kirby/config/fields/gap.php | 2 +- kirby/config/fields/headline.php | 42 +- kirby/config/fields/info.php | 72 +- kirby/config/fields/line.php | 2 +- kirby/config/fields/list.php | 26 +- kirby/config/fields/mixins/datetime.php | 52 +- kirby/config/fields/mixins/filepicker.php | 14 +- kirby/config/fields/mixins/layout.php | 32 +- kirby/config/fields/mixins/min.php | 32 +- kirby/config/fields/mixins/options.php | 84 +- kirby/config/fields/mixins/pagepicker.php | 14 +- kirby/config/fields/mixins/picker.php | 124 +- kirby/config/fields/mixins/upload.php | 108 +- kirby/config/fields/mixins/userpicker.php | 12 +- kirby/config/fields/multiselect.php | 56 +- kirby/config/fields/number.php | 82 +- kirby/config/fields/pages.php | 190 +- kirby/config/fields/radio.php | 48 +- kirby/config/fields/range.php | 38 +- kirby/config/fields/select.php | 38 +- kirby/config/fields/slug.php | 90 +- kirby/config/fields/structure.php | 352 +- kirby/config/fields/tags.php | 174 +- kirby/config/fields/tel.php | 42 +- kirby/config/fields/text.php | 170 +- kirby/config/fields/textarea.php | 208 +- kirby/config/fields/time.php | 218 +- kirby/config/fields/toggle.php | 118 +- kirby/config/fields/toggles.php | 72 +- kirby/config/fields/url.php | 64 +- kirby/config/fields/users.php | 178 +- kirby/config/fields/writer.php | 60 +- kirby/config/helpers.php | 1208 +++--- kirby/config/methods.php | 1060 ++--- kirby/config/presets/files.php | 36 +- kirby/config/presets/page.php | 116 +- kirby/config/presets/pages.php | 78 +- kirby/config/routes.php | 254 +- kirby/config/sections/fields.php | 92 +- kirby/config/sections/files.php | 354 +- kirby/config/sections/info.php | 54 +- kirby/config/sections/mixins/details.php | 58 +- kirby/config/sections/mixins/empty.php | 30 +- kirby/config/sections/mixins/headline.php | 64 +- kirby/config/sections/mixins/help.php | 34 +- kirby/config/sections/mixins/layout.php | 204 +- kirby/config/sections/mixins/max.php | 44 +- kirby/config/sections/mixins/min.php | 32 +- kirby/config/sections/mixins/pagination.php | 58 +- kirby/config/sections/mixins/parent.php | 64 +- kirby/config/sections/mixins/search.php | 26 +- kirby/config/sections/mixins/sort.php | 88 +- kirby/config/sections/pages.php | 452 +-- kirby/config/sections/stats.php | 98 +- kirby/config/setup.php | 24 +- kirby/config/tags.php | 568 +-- kirby/config/templates/emails/auth/login.php | 8 +- .../templates/emails/auth/password-reset.php | 8 +- kirby/i18n/translations/ru.json | 40 +- kirby/panel/cypress.config.js | 11 + kirby/panel/dist/js/index.js | 2 +- kirby/panel/dist/js/vendor.js | 10 +- kirby/router.php | 4 +- kirby/src/Api/Api.php | 1622 ++++---- kirby/src/Api/Collection.php | 262 +- kirby/src/Api/Model.php | 366 +- kirby/src/Cache/ApcuCache.php | 128 +- kirby/src/Cache/Cache.php | 398 +- kirby/src/Cache/FileCache.php | 376 +- kirby/src/Cache/MemCached.php | 148 +- kirby/src/Cache/MemoryCache.php | 124 +- kirby/src/Cache/NullCache.php | 100 +- kirby/src/Cache/Value.php | 238 +- kirby/src/Cms/Api.php | 404 +- kirby/src/Cms/App.php | 3518 +++++++++-------- kirby/src/Cms/AppCaches.php | 196 +- kirby/src/Cms/AppErrors.php | 322 +- kirby/src/Cms/AppPlugins.php | 1759 +++++---- kirby/src/Cms/AppTranslations.php | 338 +- kirby/src/Cms/AppUsers.php | 224 +- kirby/src/Cms/Auth.php | 1720 ++++---- kirby/src/Cms/Auth/Challenge.php | 80 +- kirby/src/Cms/Auth/EmailChallenge.php | 102 +- kirby/src/Cms/Auth/Status.php | 354 +- kirby/src/Cms/Block.php | 422 +- kirby/src/Cms/Blocks.php | 212 +- kirby/src/Cms/Blueprint.php | 1586 ++++---- kirby/src/Cms/Collection.php | 545 +-- kirby/src/Cms/Collections.php | 202 +- kirby/src/Cms/Content.php | 438 +- kirby/src/Cms/ContentLock.php | 364 +- kirby/src/Cms/ContentLocks.php | 352 +- kirby/src/Cms/ContentTranslation.php | 398 +- kirby/src/Cms/Core.php | 848 ++-- kirby/src/Cms/Email.php | 408 +- kirby/src/Cms/Event.php | 476 +-- kirby/src/Cms/Field.php | 402 +- kirby/src/Cms/Fieldset.php | 474 +-- kirby/src/Cms/Fieldsets.php | 134 +- kirby/src/Cms/File.php | 1440 +++---- kirby/src/Cms/FileActions.php | 492 +-- kirby/src/Cms/FileBlueprint.php | 292 +- kirby/src/Cms/FileModifications.php | 350 +- kirby/src/Cms/FilePermissions.php | 2 +- kirby/src/Cms/FilePicker.php | 94 +- kirby/src/Cms/FileRules.php | 544 +-- kirby/src/Cms/FileVersion.php | 222 +- kirby/src/Cms/Files.php | 304 +- kirby/src/Cms/Find.php | 298 +- kirby/src/Cms/HasChildren.php | 390 +- kirby/src/Cms/HasFiles.php | 372 +- kirby/src/Cms/HasMethods.php | 110 +- kirby/src/Cms/HasSiblings.php | 292 +- kirby/src/Cms/Helpers.php | 120 +- kirby/src/Cms/Html.php | 218 +- kirby/src/Cms/Ingredients.php | 138 +- kirby/src/Cms/Item.php | 200 +- kirby/src/Cms/Items.php | 130 +- kirby/src/Cms/Language.php | 1326 +++---- kirby/src/Cms/LanguageRouter.php | 194 +- kirby/src/Cms/LanguageRoutes.php | 248 +- kirby/src/Cms/LanguageRules.php | 142 +- kirby/src/Cms/Languages.php | 144 +- kirby/src/Cms/Layout.php | 192 +- kirby/src/Cms/LayoutColumn.php | 218 +- kirby/src/Cms/LayoutColumns.php | 2 +- kirby/src/Cms/Layouts.php | 144 +- kirby/src/Cms/Loader.php | 386 +- kirby/src/Cms/Media.php | 258 +- kirby/src/Cms/Model.php | 178 +- kirby/src/Cms/ModelPermissions.php | 166 +- kirby/src/Cms/ModelWithContent.php | 1360 +++---- kirby/src/Cms/Nest.php | 48 +- kirby/src/Cms/NestCollection.php | 24 +- kirby/src/Cms/NestObject.php | 42 +- kirby/src/Cms/Page.php | 3068 +++++++------- kirby/src/Cms/PageActions.php | 1702 ++++---- kirby/src/Cms/PageBlueprint.php | 336 +- kirby/src/Cms/PagePermissions.php | 108 +- kirby/src/Cms/PagePicker.php | 424 +- kirby/src/Cms/PageRules.php | 740 ++-- kirby/src/Cms/PageSiblings.php | 230 +- kirby/src/Cms/Pages.php | 1058 ++--- kirby/src/Cms/Pagination.php | 268 +- kirby/src/Cms/Permissions.php | 388 +- kirby/src/Cms/Picker.php | 294 +- kirby/src/Cms/Plugin.php | 348 +- kirby/src/Cms/PluginAssets.php | 98 +- kirby/src/Cms/R.php | 14 +- kirby/src/Cms/Responder.php | 748 ++-- kirby/src/Cms/Response.php | 26 +- kirby/src/Cms/Role.php | 378 +- kirby/src/Cms/Roles.php | 210 +- kirby/src/Cms/S.php | 14 +- kirby/src/Cms/Search.php | 80 +- kirby/src/Cms/Section.php | 148 +- kirby/src/Cms/Site.php | 1348 +++---- kirby/src/Cms/SiteActions.php | 146 +- kirby/src/Cms/SiteBlueprint.php | 78 +- kirby/src/Cms/SitePermissions.php | 2 +- kirby/src/Cms/SiteRules.php | 68 +- kirby/src/Cms/Structure.php | 78 +- kirby/src/Cms/StructureObject.php | 328 +- kirby/src/Cms/System.php | 1220 +++--- kirby/src/Cms/Template.php | 326 +- kirby/src/Cms/Translation.php | 312 +- kirby/src/Cms/Translations.php | 94 +- kirby/src/Cms/Url.php | 76 +- kirby/src/Cms/User.php | 1818 ++++----- kirby/src/Cms/UserActions.php | 608 +-- kirby/src/Cms/UserBlueprint.php | 56 +- kirby/src/Cms/UserPermissions.php | 88 +- kirby/src/Cms/UserPicker.php | 82 +- kirby/src/Cms/UserRules.php | 610 +-- kirby/src/Cms/Users.php | 212 +- kirby/src/Cms/Visitor.php | 14 +- kirby/src/Data/Data.php | 182 +- kirby/src/Data/Handler.php | 82 +- kirby/src/Data/Json.php | 68 +- kirby/src/Data/PHP.php | 132 +- kirby/src/Data/Txt.php | 188 +- kirby/src/Data/Xml.php | 78 +- kirby/src/Data/Yaml.php | 96 +- kirby/src/Database/Database.php | 1252 +++--- kirby/src/Database/Db.php | 230 +- kirby/src/Database/Query.php | 2088 +++++----- kirby/src/Database/Sql.php | 1893 ++++----- kirby/src/Database/Sql/Mysql.php | 74 +- kirby/src/Database/Sql/Sqlite.php | 229 +- kirby/src/Email/Body.php | 116 +- kirby/src/Email/Email.php | 798 ++-- kirby/src/Email/PHPMailer.php | 160 +- .../src/Exception/BadMethodCallException.php | 8 +- kirby/src/Exception/DuplicateException.php | 6 +- kirby/src/Exception/ErrorPageException.php | 6 +- kirby/src/Exception/Exception.php | 360 +- .../Exception/InvalidArgumentException.php | 8 +- kirby/src/Exception/LogicException.php | 6 +- kirby/src/Exception/NotFoundException.php | 6 +- kirby/src/Exception/PermissionException.php | 6 +- kirby/src/Filesystem/Asset.php | 174 +- kirby/src/Filesystem/Dir.php | 1174 +++--- kirby/src/Filesystem/F.php | 1784 ++++----- kirby/src/Filesystem/File.php | 1084 ++--- kirby/src/Filesystem/Filename.php | 486 +-- kirby/src/Filesystem/IsFile.php | 304 +- kirby/src/Filesystem/Mime.php | 582 +-- kirby/src/Form/Field.php | 866 ++-- kirby/src/Form/Field/BlocksField.php | 440 +-- kirby/src/Form/Field/LayoutField.php | 356 +- kirby/src/Form/FieldClass.php | 1698 ++++---- kirby/src/Form/Fields.php | 68 +- kirby/src/Form/Form.php | 626 +-- kirby/src/Form/Mixin/EmptyState.php | 18 +- kirby/src/Form/Mixin/Max.php | 18 +- kirby/src/Form/Mixin/Min.php | 18 +- kirby/src/Form/Options.php | 332 +- kirby/src/Form/OptionsApi.php | 368 +- kirby/src/Form/OptionsQuery.php | 416 +- kirby/src/Form/Validations.php | 498 +-- kirby/src/Http/Cookie.php | 392 +- kirby/src/Http/Environment.php | 2065 +++++----- kirby/src/Http/Header.php | 518 +-- kirby/src/Http/Idn.php | 104 +- kirby/src/Http/Params.php | 234 +- kirby/src/Http/Path.php | 42 +- kirby/src/Http/Query.php | 60 +- kirby/src/Http/Remote.php | 676 ++-- kirby/src/Http/Request.php | 730 ++-- kirby/src/Http/Request/Auth.php | 82 +- kirby/src/Http/Request/Auth/BasicAuth.php | 116 +- kirby/src/Http/Request/Auth/BearerAuth.php | 36 +- kirby/src/Http/Request/Auth/SessionAuth.php | 54 +- kirby/src/Http/Request/Body.php | 190 +- kirby/src/Http/Request/Data.php | 116 +- kirby/src/Http/Request/Files.php | 96 +- kirby/src/Http/Request/Query.php | 146 +- kirby/src/Http/Response.php | 562 +-- kirby/src/Http/Route.php | 384 +- kirby/src/Http/Router.php | 336 +- kirby/src/Http/Server.php | 30 +- kirby/src/Http/Uri.php | 1117 +++--- kirby/src/Http/Url.php | 478 +-- kirby/src/Http/Visitor.php | 408 +- kirby/src/Image/Camera.php | 140 +- kirby/src/Image/Darkroom.php | 244 +- kirby/src/Image/Darkroom/GdLib.php | 180 +- kirby/src/Image/Darkroom/ImageMagick.php | 418 +- kirby/src/Image/Dimensions.php | 736 ++-- kirby/src/Image/Exif.php | 498 +-- kirby/src/Image/Image.php | 404 +- kirby/src/Image/Location.php | 212 +- kirby/src/Panel/Dialog.php | 36 +- kirby/src/Panel/Document.php | 484 +-- kirby/src/Panel/Dropdown.php | 112 +- kirby/src/Panel/Field.php | 442 +-- kirby/src/Panel/File.php | 812 ++-- kirby/src/Panel/Home.php | 398 +- kirby/src/Panel/Json.php | 98 +- kirby/src/Panel/Model.php | 762 ++-- kirby/src/Panel/Page.php | 624 +-- kirby/src/Panel/Panel.php | 1174 +++--- kirby/src/Panel/Plugins.php | 148 +- kirby/src/Panel/Redirect.php | 44 +- kirby/src/Panel/Search.php | 30 +- kirby/src/Panel/Site.php | 152 +- kirby/src/Panel/User.php | 454 +-- kirby/src/Panel/View.php | 750 ++-- kirby/src/Parsley/Element.php | 312 +- kirby/src/Parsley/Inline.php | 262 +- kirby/src/Parsley/Parsley.php | 556 +-- kirby/src/Parsley/Schema.php | 82 +- kirby/src/Parsley/Schema/Blocks.php | 758 ++-- kirby/src/Parsley/Schema/Plain.php | 86 +- kirby/src/Sane/DomHandler.php | 266 +- kirby/src/Sane/Handler.php | 126 +- kirby/src/Sane/Html.php | 238 +- kirby/src/Sane/Sane.php | 336 +- kirby/src/Sane/Svg.php | 912 ++--- kirby/src/Sane/Svgz.php | 94 +- kirby/src/Sane/Xml.php | 96 +- kirby/src/Session/AutoSession.php | 280 +- kirby/src/Session/FileSessionStore.php | 820 ++-- kirby/src/Session/Session.php | 1510 +++---- kirby/src/Session/SessionData.php | 422 +- kirby/src/Session/SessionStore.php | 176 +- kirby/src/Session/Sessions.php | 470 +-- kirby/src/Text/KirbyTag.php | 316 +- kirby/src/Text/KirbyTags.php | 42 +- kirby/src/Text/Markdown.php | 106 +- kirby/src/Text/SmartyPants.php | 204 +- kirby/src/Toolkit/A.php | 1526 +++---- kirby/src/Toolkit/Collection.php | 2540 ++++++------ kirby/src/Toolkit/Component.php | 478 +-- kirby/src/Toolkit/Config.php | 8 +- kirby/src/Toolkit/Controller.php | 68 +- kirby/src/Toolkit/Date.php | 948 ++--- kirby/src/Toolkit/Dom.php | 1786 ++++----- kirby/src/Toolkit/Escape.php | 258 +- kirby/src/Toolkit/Facade.php | 36 +- kirby/src/Toolkit/Html.php | 1234 +++--- kirby/src/Toolkit/I18n.php | 489 +-- kirby/src/Toolkit/Iterator.php | 290 +- kirby/src/Toolkit/Locale.php | 286 +- kirby/src/Toolkit/Obj.php | 186 +- kirby/src/Toolkit/Pagination.php | 828 ++-- kirby/src/Toolkit/Properties.php | 214 +- kirby/src/Toolkit/Query.php | 392 +- kirby/src/Toolkit/Silo.php | 98 +- kirby/src/Toolkit/Str.php | 2836 ++++++------- kirby/src/Toolkit/Tpl.php | 54 +- kirby/src/Toolkit/V.php | 1052 ++--- kirby/src/Toolkit/View.php | 206 +- kirby/src/Toolkit/Xml.php | 726 ++-- kirby/vendor/composer/installed.php | 8 +- 377 files changed, 63981 insertions(+), 63824 deletions(-) create mode 100755 kirby/panel/cypress.config.js diff --git a/kirby/.editorconfig b/kirby/.editorconfig index a0ebce7..76df047 100755 --- a/kirby/.editorconfig +++ b/kirby/.editorconfig @@ -6,10 +6,19 @@ root = true -[*.php] +[*] charset = utf-8 end_of_line = lf -insert_final_newline = true +indent_style = tab +indent_size = 2 trim_trailing_whitespace = true + +[*.php] +indent_size = 4 +insert_final_newline = true + +[*.yml] indent_style = space -indent_size = 4 \ No newline at end of file + +[*.md] +trim_trailing_whitespace = false \ No newline at end of file diff --git a/kirby/bootstrap.php b/kirby/bootstrap.php index 15121d2..a5e9766 100755 --- a/kirby/bootstrap.php +++ b/kirby/bootstrap.php @@ -5,31 +5,31 @@ * stop at older or too recent versions */ if ( - version_compare(PHP_VERSION, '7.4.0', '>=') === false || - version_compare(PHP_VERSION, '8.2.0', '<') === false + version_compare(PHP_VERSION, '7.4.0', '>=') === false || + version_compare(PHP_VERSION, '8.2.0', '<') === false ) { - die(include __DIR__ . '/views/php.php'); + die(include __DIR__ . '/views/php.php'); } if (is_file($autoloader = dirname(__DIR__) . '/vendor/autoload.php')) { - /** - * Always prefer a site-wide Composer autoloader - * if it exists, it means that the user has probably - * installed additional packages - */ - include $autoloader; + /** + * Always prefer a site-wide Composer autoloader + * if it exists, it means that the user has probably + * installed additional packages + */ + include $autoloader; } elseif (is_file($autoloader = __DIR__ . '/vendor/autoload.php')) { - /** - * Fall back to the local autoloader if that exists - */ - include $autoloader; + /** + * Fall back to the local autoloader if that exists + */ + include $autoloader; } else { - /** - * If neither one exists, don't bother searching; - * it's a custom directory setup and the users need to - * load the autoloader themselves - */ + /** + * If neither one exists, don't bother searching; + * it's a custom directory setup and the users need to + * load the autoloader themselves + */ } diff --git a/kirby/composer.json b/kirby/composer.json index 494d130..f8d080b 100755 --- a/kirby/composer.json +++ b/kirby/composer.json @@ -1,110 +1,110 @@ { - "name": "getkirby/cms", - "description": "The Kirby 3 core", - "license": "proprietary", - "type": "kirby-cms", - "version": "3.7.0.2", - "keywords": [ - "kirby", - "cms", - "core" - ], - "authors": [ - { - "name": "Kirby Team", - "email": "support@getkirby.com", - "homepage": "https://getkirby.com" - } - ], - "homepage": "https://getkirby.com", - "support": { - "email": "support@getkirby.com", - "issues": "https://github.com/getkirby/kirby/issues", - "forum": "https://forum.getkirby.com", - "source": "https://github.com/getkirby/kirby" - }, - "require": { - "php": ">=7.4.0 <8.2.0", - "ext-SimpleXML": "*", - "ext-ctype": "*", - "ext-curl": "*", - "ext-dom": "*", - "ext-filter": "*", - "ext-hash": "*", - "ext-iconv": "*", - "ext-json": "*", - "ext-libxml": "*", - "ext-mbstring": "*", - "ext-openssl": "*", - "claviska/simpleimage": "3.6.5", - "filp/whoops": "2.14.5", - "getkirby/composer-installer": "^1.2.1", - "laminas/laminas-escaper": "2.10.0", - "michelf/php-smartypants": "1.8.1", - "phpmailer/phpmailer": "6.6.3", - "symfony/polyfill-intl-idn": "1.26.0", - "symfony/polyfill-mbstring": "1.26.0" - }, - "replace": { - "symfony/polyfill-php72": "*" - }, - "suggest": { - "ext-PDO": "Support for using databases", - "ext-apcu": "Support for the Apcu cache driver", - "ext-exif": "Support for exif information from images", - "ext-fileinfo": "Improved mime type detection for files", - "ext-intl": "Improved i18n number formatting", - "ext-memcached": "Support for the Memcached cache driver", - "ext-zip": "Support for ZIP archive file functions", - "ext-zlib": "Sanitization and validation for svgz files" - }, - "autoload": { - "psr-4": { - "Kirby\\": "src/" - }, - "classmap": [ - "dependencies/" - ], - "files": [ - "config/setup.php", - "config/helpers.php" - ] - }, - "config": { - "allow-plugins": { - "getkirby/composer-installer": true - }, - "optimize-autoloader": true, - "platform": { - "php": "7.4.0" - }, - "platform-check": false - }, - "extra": { - "unused": [ - "symfony/polyfill-intl-idn" - ] - }, - "scripts": { - "post-update-cmd": "curl -o cacert.pem https://curl.se/ca/cacert.pem", - "analyze": [ - "@analyze:composer", - "@analyze:psalm", - "@analyze:phpcpd", - "@analyze:phpmd" - ], - "analyze:composer": "composer validate --strict --no-check-version --no-check-all", - "analyze:phpcpd": "phpcpd --fuzzy --exclude tests --exclude vendor .", - "analyze:phpmd": "phpmd . ansi phpmd.xml.dist --exclude 'dependencies/*,tests/*,vendor/*'", - "analyze:psalm": "psalm", - "build": "./scripts/build", - "ci": [ - "@fix", - "@analyze", - "@test" - ], - "fix": "php-cs-fixer fix", - "test": "phpunit --stderr --coverage-html=tests/coverage", - "zip": "composer archive --format=zip --file=dist" - } + "name": "getkirby/cms", + "description": "The Kirby 3 core", + "license": "proprietary", + "type": "kirby-cms", + "version": "3.7.1", + "keywords": [ + "kirby", + "cms", + "core" + ], + "authors": [ + { + "name": "Kirby Team", + "email": "support@getkirby.com", + "homepage": "https://getkirby.com" + } + ], + "homepage": "https://getkirby.com", + "support": { + "email": "support@getkirby.com", + "issues": "https://github.com/getkirby/kirby/issues", + "forum": "https://forum.getkirby.com", + "source": "https://github.com/getkirby/kirby" + }, + "require": { + "php": ">=7.4.0 <8.2.0", + "ext-SimpleXML": "*", + "ext-ctype": "*", + "ext-curl": "*", + "ext-dom": "*", + "ext-filter": "*", + "ext-hash": "*", + "ext-iconv": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-openssl": "*", + "claviska/simpleimage": "3.6.5", + "filp/whoops": "2.14.5", + "getkirby/composer-installer": "^1.2.1", + "laminas/laminas-escaper": "2.10.0", + "michelf/php-smartypants": "1.8.1", + "phpmailer/phpmailer": "6.6.3", + "symfony/polyfill-intl-idn": "1.26.0", + "symfony/polyfill-mbstring": "1.26.0" + }, + "replace": { + "symfony/polyfill-php72": "*" + }, + "suggest": { + "ext-PDO": "Support for using databases", + "ext-apcu": "Support for the Apcu cache driver", + "ext-exif": "Support for exif information from images", + "ext-fileinfo": "Improved mime type detection for files", + "ext-intl": "Improved i18n number formatting", + "ext-memcached": "Support for the Memcached cache driver", + "ext-zip": "Support for ZIP archive file functions", + "ext-zlib": "Sanitization and validation for svgz files" + }, + "autoload": { + "psr-4": { + "Kirby\\": "src/" + }, + "classmap": [ + "dependencies/" + ], + "files": [ + "config/setup.php", + "config/helpers.php" + ] + }, + "config": { + "allow-plugins": { + "getkirby/composer-installer": true + }, + "optimize-autoloader": true, + "platform": { + "php": "7.4.0" + }, + "platform-check": false + }, + "extra": { + "unused": [ + "symfony/polyfill-intl-idn" + ] + }, + "scripts": { + "post-update-cmd": "curl -o cacert.pem https://curl.se/ca/cacert.pem", + "analyze": [ + "@analyze:composer", + "@analyze:psalm", + "@analyze:phpcpd", + "@analyze:phpmd" + ], + "analyze:composer": "composer validate --strict --no-check-version --no-check-all", + "analyze:phpcpd": "phpcpd --fuzzy --exclude tests --exclude vendor .", + "analyze:phpmd": "phpmd . ansi phpmd.xml.dist --exclude 'dependencies/*,tests/*,vendor/*'", + "analyze:psalm": "psalm", + "build": "./scripts/build", + "ci": [ + "@fix", + "@analyze", + "@test" + ], + "fix": "php-cs-fixer fix", + "test": "phpunit --stderr --coverage-html=tests/coverage", + "zip": "composer archive --format=zip --file=dist" + } } diff --git a/kirby/composer.lock b/kirby/composer.lock index 4e5b667..b327305 100755 --- a/kirby/composer.lock +++ b/kirby/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "538cd92719a152cbecaaaec5cde21f03", + "content-hash": "1d71d8053b544a0d3380bc67234ff81d", "packages": [ { "name": "claviska/simpleimage", diff --git a/kirby/config/aliases.php b/kirby/config/aliases.php index a9a4a4f..ee795a3 100755 --- a/kirby/config/aliases.php +++ b/kirby/config/aliases.php @@ -1,81 +1,81 @@ 'Kirby\Cms\Collection', - 'field' => 'Kirby\Cms\Field', - 'file' => 'Kirby\Cms\File', - 'files' => 'Kirby\Cms\Files', - 'find' => 'Kirby\Cms\Find', - 'helpers' => 'Kirby\Cms\Helpers', - 'html' => 'Kirby\Cms\Html', - 'kirby' => 'Kirby\Cms\App', - 'page' => 'Kirby\Cms\Page', - 'pages' => 'Kirby\Cms\Pages', - 'pagination' => 'Kirby\Cms\Pagination', - 'r' => 'Kirby\Cms\R', - 'response' => 'Kirby\Cms\Response', - 's' => 'Kirby\Cms\S', - 'sane' => 'Kirby\Sane\Sane', - 'site' => 'Kirby\Cms\Site', - 'structure' => 'Kirby\Cms\Structure', - 'url' => 'Kirby\Cms\Url', - 'user' => 'Kirby\Cms\User', - 'users' => 'Kirby\Cms\Users', - 'visitor' => 'Kirby\Cms\Visitor', + // cms classes + 'collection' => 'Kirby\Cms\Collection', + 'field' => 'Kirby\Cms\Field', + 'file' => 'Kirby\Cms\File', + 'files' => 'Kirby\Cms\Files', + 'find' => 'Kirby\Cms\Find', + 'helpers' => 'Kirby\Cms\Helpers', + 'html' => 'Kirby\Cms\Html', + 'kirby' => 'Kirby\Cms\App', + 'page' => 'Kirby\Cms\Page', + 'pages' => 'Kirby\Cms\Pages', + 'pagination' => 'Kirby\Cms\Pagination', + 'r' => 'Kirby\Cms\R', + 'response' => 'Kirby\Cms\Response', + 's' => 'Kirby\Cms\S', + 'sane' => 'Kirby\Sane\Sane', + 'site' => 'Kirby\Cms\Site', + 'structure' => 'Kirby\Cms\Structure', + 'url' => 'Kirby\Cms\Url', + 'user' => 'Kirby\Cms\User', + 'users' => 'Kirby\Cms\Users', + 'visitor' => 'Kirby\Cms\Visitor', - // data handler - 'data' => 'Kirby\Data\Data', - 'json' => 'Kirby\Data\Json', - 'yaml' => 'Kirby\Data\Yaml', + // data handler + 'data' => 'Kirby\Data\Data', + 'json' => 'Kirby\Data\Json', + 'yaml' => 'Kirby\Data\Yaml', - // file classes - 'asset' => 'Kirby\Filesystem\Asset', - 'dir' => 'Kirby\Filesystem\Dir', - 'f' => 'Kirby\Filesystem\F', - 'mime' => 'Kirby\Filesystem\Mime', + // file classes + 'asset' => 'Kirby\Filesystem\Asset', + 'dir' => 'Kirby\Filesystem\Dir', + 'f' => 'Kirby\Filesystem\F', + 'mime' => 'Kirby\Filesystem\Mime', - // data classes - 'database' => 'Kirby\Database\Database', - 'db' => 'Kirby\Database\Db', + // data classes + 'database' => 'Kirby\Database\Database', + 'db' => 'Kirby\Database\Db', - // exceptions - 'errorpageexception' => 'Kirby\Exception\ErrorPageException', + // exceptions + 'errorpageexception' => 'Kirby\Exception\ErrorPageException', - // http classes - 'cookie' => 'Kirby\Http\Cookie', - 'header' => 'Kirby\Http\Header', - 'remote' => 'Kirby\Http\Remote', - 'server' => 'Kirby\Http\Server', + // http classes + 'cookie' => 'Kirby\Http\Cookie', + 'header' => 'Kirby\Http\Header', + 'remote' => 'Kirby\Http\Remote', + 'server' => 'Kirby\Http\Server', - // image classes - 'dimensions' => 'Kirby\Image\Dimensions', + // image classes + 'dimensions' => 'Kirby\Image\Dimensions', - // panel classes - 'panel' => 'Kirby\Panel\Panel', + // panel classes + 'panel' => 'Kirby\Panel\Panel', - // toolkit classes - 'a' => 'Kirby\Toolkit\A', - 'c' => 'Kirby\Toolkit\Config', - 'config' => 'Kirby\Toolkit\Config', - 'escape' => 'Kirby\Toolkit\Escape', - 'i18n' => 'Kirby\Toolkit\I18n', - 'obj' => 'Kirby\Toolkit\Obj', - 'str' => 'Kirby\Toolkit\Str', - 'tpl' => 'Kirby\Toolkit\Tpl', - 'v' => 'Kirby\Toolkit\V', - 'xml' => 'Kirby\Toolkit\Xml', + // toolkit classes + 'a' => 'Kirby\Toolkit\A', + 'c' => 'Kirby\Toolkit\Config', + 'config' => 'Kirby\Toolkit\Config', + 'escape' => 'Kirby\Toolkit\Escape', + 'i18n' => 'Kirby\Toolkit\I18n', + 'obj' => 'Kirby\Toolkit\Obj', + 'str' => 'Kirby\Toolkit\Str', + 'tpl' => 'Kirby\Toolkit\Tpl', + 'v' => 'Kirby\Toolkit\V', + 'xml' => 'Kirby\Toolkit\Xml', - // TODO: remove in 4.0.0 - 'kirby\cms\asset' => 'Kirby\Filesystem\Asset', - 'kirby\cms\dir' => 'Kirby\Filesystem\Dir', - 'kirby\cms\filename' => 'Kirby\Filesystem\Filename', - 'kirby\cms\filefoundation' => 'Kirby\Filesystem\IsFile', - 'kirby\cms\form' => 'Kirby\Form\Form', - 'kirby\cms\kirbytag' => 'Kirby\Text\KirbyTag', - 'kirby\cms\kirbytags' => 'Kirby\Text\KirbyTags', - 'kirby\toolkit\dir' => 'Kirby\Filesystem\Dir', - 'kirby\toolkit\f' => 'Kirby\Filesystem\F', - 'kirby\toolkit\file' => 'Kirby\Filesystem\File', - 'kirby\toolkit\mime' => 'Kirby\Filesystem\Mime', + // TODO: remove in 4.0.0 + 'kirby\cms\asset' => 'Kirby\Filesystem\Asset', + 'kirby\cms\dir' => 'Kirby\Filesystem\Dir', + 'kirby\cms\filename' => 'Kirby\Filesystem\Filename', + 'kirby\cms\filefoundation' => 'Kirby\Filesystem\IsFile', + 'kirby\cms\form' => 'Kirby\Form\Form', + 'kirby\cms\kirbytag' => 'Kirby\Text\KirbyTag', + 'kirby\cms\kirbytags' => 'Kirby\Text\KirbyTags', + 'kirby\toolkit\dir' => 'Kirby\Filesystem\Dir', + 'kirby\toolkit\f' => 'Kirby\Filesystem\F', + 'kirby\toolkit\file' => 'Kirby\Filesystem\File', + 'kirby\toolkit\mime' => 'Kirby\Filesystem\Mime', ]; diff --git a/kirby/config/api/authentication.php b/kirby/config/api/authentication.php index b089940..4758599 100755 --- a/kirby/config/api/authentication.php +++ b/kirby/config/api/authentication.php @@ -3,25 +3,25 @@ use Kirby\Exception\PermissionException; return function () { - $auth = $this->kirby()->auth(); - $allowImpersonation = $this->kirby()->option('api.allowImpersonation') ?? false; + $auth = $this->kirby()->auth(); + $allowImpersonation = $this->kirby()->option('api.allowImpersonation') ?? false; - // csrf token check - if ( - $auth->type($allowImpersonation) === 'session' && - $auth->csrf() === false - ) { - throw new PermissionException('Unauthenticated'); - } + // csrf token check + if ( + $auth->type($allowImpersonation) === 'session' && + $auth->csrf() === false + ) { + throw new PermissionException('Unauthenticated'); + } - // get user from session or basic auth - if ($user = $auth->user(null, $allowImpersonation)) { - if ($user->role()->permissions()->for('access', 'panel') === false) { - throw new PermissionException(['key' => 'access.panel']); - } + // get user from session or basic auth + if ($user = $auth->user(null, $allowImpersonation)) { + if ($user->role()->permissions()->for('access', 'panel') === false) { + throw new PermissionException(['key' => 'access.panel']); + } - return $user; - } + return $user; + } - throw new PermissionException('Unauthenticated'); + throw new PermissionException('Unauthenticated'); }; diff --git a/kirby/config/api/collections.php b/kirby/config/api/collections.php index fb3e218..3a34927 100755 --- a/kirby/config/api/collections.php +++ b/kirby/config/api/collections.php @@ -5,66 +5,66 @@ */ return [ - /** - * Children - */ - 'children' => [ - 'model' => 'page', - 'type' => 'Kirby\Cms\Pages', - 'view' => 'compact' - ], + /** + * Children + */ + 'children' => [ + 'model' => 'page', + 'type' => 'Kirby\Cms\Pages', + 'view' => 'compact' + ], - /** - * Files - */ - 'files' => [ - 'model' => 'file', - 'type' => 'Kirby\Cms\Files' - ], + /** + * Files + */ + 'files' => [ + 'model' => 'file', + 'type' => 'Kirby\Cms\Files' + ], - /** - * Languages - */ - 'languages' => [ - 'model' => 'language', - 'type' => 'Kirby\Cms\Languages' - ], + /** + * Languages + */ + 'languages' => [ + 'model' => 'language', + 'type' => 'Kirby\Cms\Languages' + ], - /** - * Pages - */ - 'pages' => [ - 'model' => 'page', - 'type' => 'Kirby\Cms\Pages', - 'view' => 'compact' - ], + /** + * Pages + */ + 'pages' => [ + 'model' => 'page', + 'type' => 'Kirby\Cms\Pages', + 'view' => 'compact' + ], - /** - * Roles - */ - 'roles' => [ - 'model' => 'role', - 'type' => 'Kirby\Cms\Roles', - 'view' => 'compact' - ], + /** + * Roles + */ + 'roles' => [ + 'model' => 'role', + 'type' => 'Kirby\Cms\Roles', + 'view' => 'compact' + ], - /** - * Translations - */ - 'translations' => [ - 'model' => 'translation', - 'type' => 'Kirby\Cms\Translations', - 'view' => 'compact' - ], + /** + * Translations + */ + 'translations' => [ + 'model' => 'translation', + 'type' => 'Kirby\Cms\Translations', + 'view' => 'compact' + ], - /** - * Users - */ - 'users' => [ - 'default' => fn () => $this->users(), - 'model' => 'user', - 'type' => 'Kirby\Cms\Users', - 'view' => 'compact' - ] + /** + * Users + */ + 'users' => [ + 'default' => fn () => $this->users(), + 'model' => 'user', + 'type' => 'Kirby\Cms\Users', + 'view' => 'compact' + ] ]; diff --git a/kirby/config/api/models.php b/kirby/config/api/models.php index 51d19fb..075442f 100755 --- a/kirby/config/api/models.php +++ b/kirby/config/api/models.php @@ -4,17 +4,17 @@ * Api Model Definitions */ return [ - 'File' => include __DIR__ . '/models/File.php', - 'FileBlueprint' => include __DIR__ . '/models/FileBlueprint.php', - 'FileVersion' => include __DIR__ . '/models/FileVersion.php', - 'Language' => include __DIR__ . '/models/Language.php', - 'Page' => include __DIR__ . '/models/Page.php', - 'PageBlueprint' => include __DIR__ . '/models/PageBlueprint.php', - 'Role' => include __DIR__ . '/models/Role.php', - 'Site' => include __DIR__ . '/models/Site.php', - 'SiteBlueprint' => include __DIR__ . '/models/SiteBlueprint.php', - 'System' => include __DIR__ . '/models/System.php', - 'Translation' => include __DIR__ . '/models/Translation.php', - 'User' => include __DIR__ . '/models/User.php', - 'UserBlueprint' => include __DIR__ . '/models/UserBlueprint.php', + 'File' => include __DIR__ . '/models/File.php', + 'FileBlueprint' => include __DIR__ . '/models/FileBlueprint.php', + 'FileVersion' => include __DIR__ . '/models/FileVersion.php', + 'Language' => include __DIR__ . '/models/Language.php', + 'Page' => include __DIR__ . '/models/Page.php', + 'PageBlueprint' => include __DIR__ . '/models/PageBlueprint.php', + 'Role' => include __DIR__ . '/models/Role.php', + 'Site' => include __DIR__ . '/models/Site.php', + 'SiteBlueprint' => include __DIR__ . '/models/SiteBlueprint.php', + 'System' => include __DIR__ . '/models/System.php', + 'Translation' => include __DIR__ . '/models/Translation.php', + 'User' => include __DIR__ . '/models/User.php', + 'UserBlueprint' => include __DIR__ . '/models/UserBlueprint.php', ]; diff --git a/kirby/config/api/models/File.php b/kirby/config/api/models/File.php index d8d2fac..dac185d 100755 --- a/kirby/config/api/models/File.php +++ b/kirby/config/api/models/File.php @@ -7,109 +7,109 @@ use Kirby\Form\Form; * File */ return [ - 'fields' => [ - 'blueprint' => fn (File $file) => $file->blueprint(), - 'content' => fn (File $file) => Form::for($file)->values(), - 'dimensions' => fn (File $file) => $file->dimensions()->toArray(), - 'dragText' => fn (File $file) => $file->panel()->dragText(), - 'exists' => fn (File $file) => $file->exists(), - 'extension' => fn (File $file) => $file->extension(), - 'filename' => fn (File $file) => $file->filename(), - 'id' => fn (File $file) => $file->id(), - 'link' => fn (File $file) => $file->panel()->url(true), - 'mime' => fn (File $file) => $file->mime(), - 'modified' => fn (File $file) => $file->modified('c'), - 'name' => fn (File $file) => $file->name(), - 'next' => fn (File $file) => $file->next(), - 'nextWithTemplate' => function (File $file) { - $files = $file->templateSiblings()->sorted(); - $index = $files->indexOf($file); + 'fields' => [ + 'blueprint' => fn (File $file) => $file->blueprint(), + 'content' => fn (File $file) => Form::for($file)->values(), + 'dimensions' => fn (File $file) => $file->dimensions()->toArray(), + 'dragText' => fn (File $file) => $file->panel()->dragText(), + 'exists' => fn (File $file) => $file->exists(), + 'extension' => fn (File $file) => $file->extension(), + 'filename' => fn (File $file) => $file->filename(), + 'id' => fn (File $file) => $file->id(), + 'link' => fn (File $file) => $file->panel()->url(true), + 'mime' => fn (File $file) => $file->mime(), + 'modified' => fn (File $file) => $file->modified('c'), + 'name' => fn (File $file) => $file->name(), + 'next' => fn (File $file) => $file->next(), + 'nextWithTemplate' => function (File $file) { + $files = $file->templateSiblings()->sorted(); + $index = $files->indexOf($file); - return $files->nth($index + 1); - }, - 'niceSize' => fn (File $file) => $file->niceSize(), - 'options' => fn (File $file) => $file->panel()->options(), - 'panelImage' => fn (File $file) => $file->panel()->image(), - 'panelUrl' => fn (File $file) => $file->panel()->url(true), - 'prev' => fn (File $file) => $file->prev(), - 'prevWithTemplate' => function (File $file) { - $files = $file->templateSiblings()->sorted(); - $index = $files->indexOf($file); + return $files->nth($index + 1); + }, + 'niceSize' => fn (File $file) => $file->niceSize(), + 'options' => fn (File $file) => $file->panel()->options(), + 'panelImage' => fn (File $file) => $file->panel()->image(), + 'panelUrl' => fn (File $file) => $file->panel()->url(true), + 'prev' => fn (File $file) => $file->prev(), + 'prevWithTemplate' => function (File $file) { + $files = $file->templateSiblings()->sorted(); + $index = $files->indexOf($file); - return $files->nth($index - 1); - }, - 'parent' => fn (File $file) => $file->parent(), - 'parents' => fn (File $file) => $file->parents()->flip(), - 'size' => fn (File $file) => $file->size(), - 'template' => fn (File $file) => $file->template(), - 'thumbs' => function ($file) { - if ($file->isResizable() === false) { - return null; - } + return $files->nth($index - 1); + }, + 'parent' => fn (File $file) => $file->parent(), + 'parents' => fn (File $file) => $file->parents()->flip(), + 'size' => fn (File $file) => $file->size(), + 'template' => fn (File $file) => $file->template(), + 'thumbs' => function ($file) { + if ($file->isResizable() === false) { + return null; + } - return [ - 'tiny' => $file->resize(128)->url(), - 'small' => $file->resize(256)->url(), - 'medium' => $file->resize(512)->url(), - 'large' => $file->resize(768)->url(), - 'huge' => $file->resize(1024)->url(), - ]; - }, - 'type' => fn (File $file) => $file->type(), - 'url' => fn (File $file) => $file->url(), - ], - 'type' => 'Kirby\Cms\File', - 'views' => [ - 'default' => [ - 'content', - 'dimensions', - 'exists', - 'extension', - 'filename', - 'id', - 'link', - 'mime', - 'modified', - 'name', - 'next' => 'compact', - 'niceSize', - 'parent' => 'compact', - 'options', - 'prev' => 'compact', - 'size', - 'template', - 'type', - 'url' - ], - 'compact' => [ - 'filename', - 'id', - 'link', - 'type', - 'url', - ], - 'panel' => [ - 'blueprint', - 'content', - 'dimensions', - 'extension', - 'filename', - 'id', - 'link', - 'mime', - 'modified', - 'name', - 'nextWithTemplate' => 'compact', - 'niceSize', - 'options', - 'panelIcon', - 'panelImage', - 'parent' => 'compact', - 'parents' => ['id', 'slug', 'title'], - 'prevWithTemplate' => 'compact', - 'template', - 'type', - 'url' - ] - ], + return [ + 'tiny' => $file->resize(128)->url(), + 'small' => $file->resize(256)->url(), + 'medium' => $file->resize(512)->url(), + 'large' => $file->resize(768)->url(), + 'huge' => $file->resize(1024)->url(), + ]; + }, + 'type' => fn (File $file) => $file->type(), + 'url' => fn (File $file) => $file->url(), + ], + 'type' => 'Kirby\Cms\File', + 'views' => [ + 'default' => [ + 'content', + 'dimensions', + 'exists', + 'extension', + 'filename', + 'id', + 'link', + 'mime', + 'modified', + 'name', + 'next' => 'compact', + 'niceSize', + 'parent' => 'compact', + 'options', + 'prev' => 'compact', + 'size', + 'template', + 'type', + 'url' + ], + 'compact' => [ + 'filename', + 'id', + 'link', + 'type', + 'url', + ], + 'panel' => [ + 'blueprint', + 'content', + 'dimensions', + 'extension', + 'filename', + 'id', + 'link', + 'mime', + 'modified', + 'name', + 'nextWithTemplate' => 'compact', + 'niceSize', + 'options', + 'panelIcon', + 'panelImage', + 'parent' => 'compact', + 'parents' => ['id', 'slug', 'title'], + 'prevWithTemplate' => 'compact', + 'template', + 'type', + 'url' + ] + ], ]; diff --git a/kirby/config/api/models/FileBlueprint.php b/kirby/config/api/models/FileBlueprint.php index 5279f8a..e781e45 100755 --- a/kirby/config/api/models/FileBlueprint.php +++ b/kirby/config/api/models/FileBlueprint.php @@ -6,13 +6,13 @@ use Kirby\Cms\FileBlueprint; * FileBlueprint */ return [ - 'fields' => [ - 'name' => fn (FileBlueprint $blueprint) => $blueprint->name(), - 'options' => fn (FileBlueprint $blueprint) => $blueprint->options(), - 'tabs' => fn (FileBlueprint $blueprint) => $blueprint->tabs(), - 'title' => fn (FileBlueprint $blueprint) => $blueprint->title(), - ], - 'type' => 'Kirby\Cms\FileBlueprint', - 'views' => [ - ], + 'fields' => [ + 'name' => fn (FileBlueprint $blueprint) => $blueprint->name(), + 'options' => fn (FileBlueprint $blueprint) => $blueprint->options(), + 'tabs' => fn (FileBlueprint $blueprint) => $blueprint->tabs(), + 'title' => fn (FileBlueprint $blueprint) => $blueprint->title(), + ], + 'type' => 'Kirby\Cms\FileBlueprint', + 'views' => [ + ], ]; diff --git a/kirby/config/api/models/FileVersion.php b/kirby/config/api/models/FileVersion.php index d5cea11..df2aac0 100755 --- a/kirby/config/api/models/FileVersion.php +++ b/kirby/config/api/models/FileVersion.php @@ -6,54 +6,54 @@ use Kirby\Cms\FileVersion; * FileVersion */ return [ - 'fields' => [ - 'dimensions' => fn (FileVersion $file) => $file->dimensions()->toArray(), - 'exists' => fn (FileVersion $file) => $file->exists(), - 'extension' => fn (FileVersion $file) => $file->extension(), - 'filename' => fn (FileVersion $file) => $file->filename(), - 'id' => fn (FileVersion $file) => $file->id(), - 'mime' => fn (FileVersion $file) => $file->mime(), - 'modified' => fn (FileVersion $file) => $file->modified('c'), - 'name' => fn (FileVersion $file) => $file->name(), - 'niceSize' => fn (FileVersion $file) => $file->niceSize(), - 'size' => fn (FileVersion $file) => $file->size(), - 'type' => fn (FileVersion $file) => $file->type(), - 'url' => fn (FileVersion $file) => $file->url(), - ], - 'type' => 'Kirby\Cms\FileVersion', - 'views' => [ - 'default' => [ - 'dimensions', - 'exists', - 'extension', - 'filename', - 'id', - 'mime', - 'modified', - 'name', - 'niceSize', - 'size', - 'type', - 'url' - ], - 'compact' => [ - 'filename', - 'id', - 'type', - 'url', - ], - 'panel' => [ - 'dimensions', - 'extension', - 'filename', - 'id', - 'mime', - 'modified', - 'name', - 'niceSize', - 'template', - 'type', - 'url' - ] - ], + 'fields' => [ + 'dimensions' => fn (FileVersion $file) => $file->dimensions()->toArray(), + 'exists' => fn (FileVersion $file) => $file->exists(), + 'extension' => fn (FileVersion $file) => $file->extension(), + 'filename' => fn (FileVersion $file) => $file->filename(), + 'id' => fn (FileVersion $file) => $file->id(), + 'mime' => fn (FileVersion $file) => $file->mime(), + 'modified' => fn (FileVersion $file) => $file->modified('c'), + 'name' => fn (FileVersion $file) => $file->name(), + 'niceSize' => fn (FileVersion $file) => $file->niceSize(), + 'size' => fn (FileVersion $file) => $file->size(), + 'type' => fn (FileVersion $file) => $file->type(), + 'url' => fn (FileVersion $file) => $file->url(), + ], + 'type' => 'Kirby\Cms\FileVersion', + 'views' => [ + 'default' => [ + 'dimensions', + 'exists', + 'extension', + 'filename', + 'id', + 'mime', + 'modified', + 'name', + 'niceSize', + 'size', + 'type', + 'url' + ], + 'compact' => [ + 'filename', + 'id', + 'type', + 'url', + ], + 'panel' => [ + 'dimensions', + 'extension', + 'filename', + 'id', + 'mime', + 'modified', + 'name', + 'niceSize', + 'template', + 'type', + 'url' + ] + ], ]; diff --git a/kirby/config/api/models/Language.php b/kirby/config/api/models/Language.php index 1e76e14..362d6f5 100755 --- a/kirby/config/api/models/Language.php +++ b/kirby/config/api/models/Language.php @@ -6,25 +6,25 @@ use Kirby\Cms\Language; * Language */ return [ - 'fields' => [ - 'code' => fn (Language $language) => $language->code(), - 'default' => fn (Language $language) => $language->isDefault(), - 'direction' => fn (Language $language) => $language->direction(), - 'locale' => fn (Language $language) => $language->locale(), - 'name' => fn (Language $language) => $language->name(), - 'rules' => fn (Language $language) => $language->rules(), - 'url' => fn (Language $language) => $language->url(), - ], - 'type' => 'Kirby\Cms\Language', - 'views' => [ - 'default' => [ - 'code', - 'default', - 'direction', - 'locale', - 'name', - 'rules', - 'url' - ] - ] + 'fields' => [ + 'code' => fn (Language $language) => $language->code(), + 'default' => fn (Language $language) => $language->isDefault(), + 'direction' => fn (Language $language) => $language->direction(), + 'locale' => fn (Language $language) => $language->locale(), + 'name' => fn (Language $language) => $language->name(), + 'rules' => fn (Language $language) => $language->rules(), + 'url' => fn (Language $language) => $language->url(), + ], + 'type' => 'Kirby\Cms\Language', + 'views' => [ + 'default' => [ + 'code', + 'default', + 'direction', + 'locale', + 'name', + 'rules', + 'url' + ] + ] ]; diff --git a/kirby/config/api/models/Page.php b/kirby/config/api/models/Page.php index 50a1de2..03b6c7d 100755 --- a/kirby/config/api/models/Page.php +++ b/kirby/config/api/models/Page.php @@ -8,116 +8,116 @@ use Kirby\Form\Form; * Page */ return [ - 'fields' => [ - 'blueprint' => fn (Page $page) => $page->blueprint(), - 'blueprints' => fn (Page $page) => $page->blueprints(), - 'children' => fn (Page $page) => $page->children(), - 'content' => fn (Page $page) => Form::for($page)->values(), - 'drafts' => fn (Page $page) => $page->drafts(), - 'errors' => fn (Page $page) => $page->errors(), - 'files' => fn (Page $page) => $page->files()->sorted(), - 'hasChildren' => fn (Page $page) => $page->hasChildren(), - 'hasDrafts' => fn (Page $page) => $page->hasDrafts(), - 'hasFiles' => fn (Page $page) => $page->hasFiles(), - 'id' => fn (Page $page) => $page->id(), - 'isSortable' => fn (Page $page) => $page->isSortable(), - /** - * @deprecated 3.6.0 - * @todo Remove in 3.8.0 - * @codeCoverageIgnore - */ - 'next' => function (Page $page) { - Helpers::deprecated('The API field page.next has been deprecated and will be removed in 3.8.0.'); + 'fields' => [ + 'blueprint' => fn (Page $page) => $page->blueprint(), + 'blueprints' => fn (Page $page) => $page->blueprints(), + 'children' => fn (Page $page) => $page->children(), + 'content' => fn (Page $page) => Form::for($page)->values(), + 'drafts' => fn (Page $page) => $page->drafts(), + 'errors' => fn (Page $page) => $page->errors(), + 'files' => fn (Page $page) => $page->files()->sorted(), + 'hasChildren' => fn (Page $page) => $page->hasChildren(), + 'hasDrafts' => fn (Page $page) => $page->hasDrafts(), + 'hasFiles' => fn (Page $page) => $page->hasFiles(), + 'id' => fn (Page $page) => $page->id(), + 'isSortable' => fn (Page $page) => $page->isSortable(), + /** + * @deprecated 3.6.0 + * @todo Remove in 3.8.0 + * @codeCoverageIgnore + */ + 'next' => function (Page $page) { + Helpers::deprecated('The API field page.next has been deprecated and will be removed in 3.8.0.'); - return $page - ->nextAll() - ->filter('intendedTemplate', $page->intendedTemplate()) - ->filter('status', $page->status()) - ->filter('isReadable', true) - ->first(); - }, - 'num' => fn (Page $page) => $page->num(), - 'options' => fn (Page $page) => $page->panel()->options(['preview']), - 'panelImage' => fn (Page $page) => $page->panel()->image(), - 'parent' => fn (Page $page) => $page->parent(), - 'parents' => fn (Page $page) => $page->parents()->flip(), - /** - * @deprecated 3.6.0 - * @todo Remove in 3.8.0 - * @codeCoverageIgnore - */ - 'prev' => function (Page $page) { - Helpers::deprecated('The API field page.prev has been deprecated and will be removed in 3.8.0.'); + return $page + ->nextAll() + ->filter('intendedTemplate', $page->intendedTemplate()) + ->filter('status', $page->status()) + ->filter('isReadable', true) + ->first(); + }, + 'num' => fn (Page $page) => $page->num(), + 'options' => fn (Page $page) => $page->panel()->options(['preview']), + 'panelImage' => fn (Page $page) => $page->panel()->image(), + 'parent' => fn (Page $page) => $page->parent(), + 'parents' => fn (Page $page) => $page->parents()->flip(), + /** + * @deprecated 3.6.0 + * @todo Remove in 3.8.0 + * @codeCoverageIgnore + */ + 'prev' => function (Page $page) { + Helpers::deprecated('The API field page.prev has been deprecated and will be removed in 3.8.0.'); - return $page - ->prevAll() - ->filter('intendedTemplate', $page->intendedTemplate()) - ->filter('status', $page->status()) - ->filter('isReadable', true) - ->last(); - }, - 'previewUrl' => fn (Page $page) => $page->previewUrl(), - 'siblings' => function (Page $page) { - if ($page->isDraft() === true) { - return $page->parentModel()->children()->not($page); - } else { - return $page->siblings(); - } - }, - 'slug' => fn (Page $page) => $page->slug(), - 'status' => fn (Page $page) => $page->status(), - 'template' => fn (Page $page) => $page->intendedTemplate()->name(), - 'title' => fn (Page $page) => $page->title()->value(), - 'url' => fn (Page $page) => $page->url(), - ], - 'type' => 'Kirby\Cms\Page', - 'views' => [ - 'compact' => [ - 'id', - 'title', - 'url', - 'num' - ], - 'default' => [ - 'content', - 'id', - 'status', - 'num', - 'options', - 'parent' => 'compact', - 'slug', - 'template', - 'title', - 'url' - ], - 'panel' => [ - 'id', - 'blueprint', - 'content', - 'status', - 'options', - 'next' => ['id', 'slug', 'title'], - 'parents' => ['id', 'slug', 'title'], - 'prev' => ['id', 'slug', 'title'], - 'previewUrl', - 'slug', - 'title', - 'url' - ], - 'selector' => [ - 'id', - 'title', - 'parent' => [ - 'id', - 'title' - ], - 'children' => [ - 'hasChildren', - 'id', - 'panelIcon', - 'panelImage', - 'title', - ], - ] - ], + return $page + ->prevAll() + ->filter('intendedTemplate', $page->intendedTemplate()) + ->filter('status', $page->status()) + ->filter('isReadable', true) + ->last(); + }, + 'previewUrl' => fn (Page $page) => $page->previewUrl(), + 'siblings' => function (Page $page) { + if ($page->isDraft() === true) { + return $page->parentModel()->children()->not($page); + } else { + return $page->siblings(); + } + }, + 'slug' => fn (Page $page) => $page->slug(), + 'status' => fn (Page $page) => $page->status(), + 'template' => fn (Page $page) => $page->intendedTemplate()->name(), + 'title' => fn (Page $page) => $page->title()->value(), + 'url' => fn (Page $page) => $page->url(), + ], + 'type' => 'Kirby\Cms\Page', + 'views' => [ + 'compact' => [ + 'id', + 'title', + 'url', + 'num' + ], + 'default' => [ + 'content', + 'id', + 'status', + 'num', + 'options', + 'parent' => 'compact', + 'slug', + 'template', + 'title', + 'url' + ], + 'panel' => [ + 'id', + 'blueprint', + 'content', + 'status', + 'options', + 'next' => ['id', 'slug', 'title'], + 'parents' => ['id', 'slug', 'title'], + 'prev' => ['id', 'slug', 'title'], + 'previewUrl', + 'slug', + 'title', + 'url' + ], + 'selector' => [ + 'id', + 'title', + 'parent' => [ + 'id', + 'title' + ], + 'children' => [ + 'hasChildren', + 'id', + 'panelIcon', + 'panelImage', + 'title', + ], + ] + ], ]; diff --git a/kirby/config/api/models/PageBlueprint.php b/kirby/config/api/models/PageBlueprint.php index c5de408..dc240ed 100755 --- a/kirby/config/api/models/PageBlueprint.php +++ b/kirby/config/api/models/PageBlueprint.php @@ -6,16 +6,16 @@ use Kirby\Cms\PageBlueprint; * PageBlueprint */ return [ - 'fields' => [ - 'name' => fn (PageBlueprint $blueprint) => $blueprint->name(), - 'num' => fn (PageBlueprint $blueprint) => $blueprint->num(), - 'options' => fn (PageBlueprint $blueprint) => $blueprint->options(), - 'preview' => fn (PageBlueprint $blueprint) => $blueprint->preview(), - 'status' => fn (PageBlueprint $blueprint) => $blueprint->status(), - 'tabs' => fn (PageBlueprint $blueprint) => $blueprint->tabs(), - 'title' => fn (PageBlueprint $blueprint) => $blueprint->title(), - ], - 'type' => 'Kirby\Cms\PageBlueprint', - 'views' => [ - ], + 'fields' => [ + 'name' => fn (PageBlueprint $blueprint) => $blueprint->name(), + 'num' => fn (PageBlueprint $blueprint) => $blueprint->num(), + 'options' => fn (PageBlueprint $blueprint) => $blueprint->options(), + 'preview' => fn (PageBlueprint $blueprint) => $blueprint->preview(), + 'status' => fn (PageBlueprint $blueprint) => $blueprint->status(), + 'tabs' => fn (PageBlueprint $blueprint) => $blueprint->tabs(), + 'title' => fn (PageBlueprint $blueprint) => $blueprint->title(), + ], + 'type' => 'Kirby\Cms\PageBlueprint', + 'views' => [ + ], ]; diff --git a/kirby/config/api/models/Role.php b/kirby/config/api/models/Role.php index 93a9e01..e1d27c3 100755 --- a/kirby/config/api/models/Role.php +++ b/kirby/config/api/models/Role.php @@ -6,18 +6,18 @@ use Kirby\Cms\Role; * Role */ return [ - 'fields' => [ - 'description' => fn (Role $role) => $role->description(), - 'name' => fn (Role $role) => $role->name(), - 'permissions' => fn (Role $role) => $role->permissions()->toArray(), - 'title' => fn (Role $role) => $role->title(), - ], - 'type' => 'Kirby\Cms\Role', - 'views' => [ - 'compact' => [ - 'description', - 'name', - 'title' - ] - ] + 'fields' => [ + 'description' => fn (Role $role) => $role->description(), + 'name' => fn (Role $role) => $role->name(), + 'permissions' => fn (Role $role) => $role->permissions()->toArray(), + 'title' => fn (Role $role) => $role->title(), + ], + 'type' => 'Kirby\Cms\Role', + 'views' => [ + 'compact' => [ + 'description', + 'name', + 'title' + ] + ] ]; diff --git a/kirby/config/api/models/Site.php b/kirby/config/api/models/Site.php index 4f5463c..c312ef4 100755 --- a/kirby/config/api/models/Site.php +++ b/kirby/config/api/models/Site.php @@ -7,46 +7,46 @@ use Kirby\Form\Form; * Site */ return [ - 'default' => fn () => $this->site(), - 'fields' => [ - 'blueprint' => fn (Site $site) => $site->blueprint(), - 'children' => fn (Site $site) => $site->children(), - 'content' => fn (Site $site) => Form::for($site)->values(), - 'drafts' => fn (Site $site) => $site->drafts(), - 'files' => fn (Site $site) => $site->files()->sorted(), - 'options' => fn (Site $site) => $site->permissions()->toArray(), - 'previewUrl' => fn (Site $site) => $site->previewUrl(), - 'title' => fn (Site $site) => $site->title()->value(), - 'url' => fn (Site $site) => $site->url(), - ], - 'type' => 'Kirby\Cms\Site', - 'views' => [ - 'compact' => [ - 'title', - 'url' - ], - 'default' => [ - 'content', - 'options', - 'title', - 'url' - ], - 'panel' => [ - 'title', - 'blueprint', - 'content', - 'options', - 'previewUrl', - 'url' - ], - 'selector' => [ - 'title', - 'children' => [ - 'id', - 'title', - 'panelIcon', - 'hasChildren' - ], - ] - ] + 'default' => fn () => $this->site(), + 'fields' => [ + 'blueprint' => fn (Site $site) => $site->blueprint(), + 'children' => fn (Site $site) => $site->children(), + 'content' => fn (Site $site) => Form::for($site)->values(), + 'drafts' => fn (Site $site) => $site->drafts(), + 'files' => fn (Site $site) => $site->files()->sorted(), + 'options' => fn (Site $site) => $site->permissions()->toArray(), + 'previewUrl' => fn (Site $site) => $site->previewUrl(), + 'title' => fn (Site $site) => $site->title()->value(), + 'url' => fn (Site $site) => $site->url(), + ], + 'type' => 'Kirby\Cms\Site', + 'views' => [ + 'compact' => [ + 'title', + 'url' + ], + 'default' => [ + 'content', + 'options', + 'title', + 'url' + ], + 'panel' => [ + 'title', + 'blueprint', + 'content', + 'options', + 'previewUrl', + 'url' + ], + 'selector' => [ + 'title', + 'children' => [ + 'id', + 'title', + 'panelIcon', + 'hasChildren' + ], + ] + ] ]; diff --git a/kirby/config/api/models/SiteBlueprint.php b/kirby/config/api/models/SiteBlueprint.php index c940212..7841841 100755 --- a/kirby/config/api/models/SiteBlueprint.php +++ b/kirby/config/api/models/SiteBlueprint.php @@ -6,12 +6,12 @@ use Kirby\Cms\SiteBlueprint; * SiteBlueprint */ return [ - 'fields' => [ - 'name' => fn (SiteBlueprint $blueprint) => $blueprint->name(), - 'options' => fn (SiteBlueprint $blueprint) => $blueprint->options(), - 'tabs' => fn (SiteBlueprint $blueprint) => $blueprint->tabs(), - 'title' => fn (SiteBlueprint $blueprint) => $blueprint->title(), - ], - 'type' => 'Kirby\Cms\SiteBlueprint', - 'views' => [], + 'fields' => [ + 'name' => fn (SiteBlueprint $blueprint) => $blueprint->name(), + 'options' => fn (SiteBlueprint $blueprint) => $blueprint->options(), + 'tabs' => fn (SiteBlueprint $blueprint) => $blueprint->tabs(), + 'title' => fn (SiteBlueprint $blueprint) => $blueprint->title(), + ], + 'type' => 'Kirby\Cms\SiteBlueprint', + 'views' => [], ]; diff --git a/kirby/config/api/models/System.php b/kirby/config/api/models/System.php index 0ad10eb..260aa45 100755 --- a/kirby/config/api/models/System.php +++ b/kirby/config/api/models/System.php @@ -7,92 +7,92 @@ use Kirby\Toolkit\Str; * System */ return [ - 'fields' => [ - 'ascii' => fn () => Str::$ascii, - 'authStatus' => fn () => $this->kirby()->auth()->status()->toArray(), - 'defaultLanguage' => fn () => $this->kirby()->panelLanguage(), - 'isOk' => fn (System $system) => $system->isOk(), - 'isInstallable' => fn (System $system) => $system->isInstallable(), - 'isInstalled' => fn (System $system) => $system->isInstalled(), - 'isLocal' => fn (System $system) => $system->isLocal(), - 'multilang' => fn () => $this->kirby()->option('languages', false) !== false, - 'languages' => fn () => $this->kirby()->languages(), - 'license' => fn (System $system) => $system->license(), - 'locales' => function () { - $locales = []; - $translations = $this->kirby()->translations(); - foreach ($translations as $translation) { - $locales[$translation->code()] = $translation->locale(); - } - return $locales; - }, - 'loginMethods' => fn (System $system) => array_keys($system->loginMethods()), - 'requirements' => fn (System $system) => $system->toArray(), - 'site' => fn (System $system) => $system->title(), - 'slugs' => fn () => Str::$language, - 'title' => fn () => $this->site()->title()->value(), - 'translation' => function () { - if ($user = $this->user()) { - $translationCode = $user->language(); - } else { - $translationCode = $this->kirby()->panelLanguage(); - } + 'fields' => [ + 'ascii' => fn () => Str::$ascii, + 'authStatus' => fn () => $this->kirby()->auth()->status()->toArray(), + 'defaultLanguage' => fn () => $this->kirby()->panelLanguage(), + 'isOk' => fn (System $system) => $system->isOk(), + 'isInstallable' => fn (System $system) => $system->isInstallable(), + 'isInstalled' => fn (System $system) => $system->isInstalled(), + 'isLocal' => fn (System $system) => $system->isLocal(), + 'multilang' => fn () => $this->kirby()->option('languages', false) !== false, + 'languages' => fn () => $this->kirby()->languages(), + 'license' => fn (System $system) => $system->license(), + 'locales' => function () { + $locales = []; + $translations = $this->kirby()->translations(); + foreach ($translations as $translation) { + $locales[$translation->code()] = $translation->locale(); + } + return $locales; + }, + 'loginMethods' => fn (System $system) => array_keys($system->loginMethods()), + 'requirements' => fn (System $system) => $system->toArray(), + 'site' => fn (System $system) => $system->title(), + 'slugs' => fn () => Str::$language, + 'title' => fn () => $this->site()->title()->value(), + 'translation' => function () { + if ($user = $this->user()) { + $translationCode = $user->language(); + } else { + $translationCode = $this->kirby()->panelLanguage(); + } - if ($translation = $this->kirby()->translation($translationCode)) { - return $translation; - } else { - return $this->kirby()->translation('en'); - } - }, - 'kirbytext' => fn () => $this->kirby()->option('panel.kirbytext') ?? true, - 'user' => fn () => $this->user(), - 'version' => function () { - $user = $this->user(); + if ($translation = $this->kirby()->translation($translationCode)) { + return $translation; + } else { + return $this->kirby()->translation('en'); + } + }, + 'kirbytext' => fn () => $this->kirby()->option('panel.kirbytext') ?? true, + 'user' => fn () => $this->user(), + 'version' => function () { + $user = $this->user(); - if ($user && $user->role()->permissions()->for('access', 'system') === true) { - return $this->kirby()->version(); - } else { - return null; - } - } - ], - 'type' => 'Kirby\Cms\System', - 'views' => [ - 'login' => [ - 'authStatus', - 'isOk', - 'isInstallable', - 'isInstalled', - 'loginMethods', - 'title', - 'translation' - ], - 'troubleshooting' => [ - 'isOk', - 'isInstallable', - 'isInstalled', - 'title', - 'translation', - 'requirements' - ], - 'panel' => [ - 'ascii', - 'defaultLanguage', - 'isOk', - 'isInstalled', - 'isLocal', - 'kirbytext', - 'languages', - 'license', - 'locales', - 'multilang', - 'requirements', - 'site', - 'slugs', - 'title', - 'translation', - 'user' => 'auth', - 'version' - ] - ], + if ($user && $user->role()->permissions()->for('access', 'system') === true) { + return $this->kirby()->version(); + } else { + return null; + } + } + ], + 'type' => 'Kirby\Cms\System', + 'views' => [ + 'login' => [ + 'authStatus', + 'isOk', + 'isInstallable', + 'isInstalled', + 'loginMethods', + 'title', + 'translation' + ], + 'troubleshooting' => [ + 'isOk', + 'isInstallable', + 'isInstalled', + 'title', + 'translation', + 'requirements' + ], + 'panel' => [ + 'ascii', + 'defaultLanguage', + 'isOk', + 'isInstalled', + 'isLocal', + 'kirbytext', + 'languages', + 'license', + 'locales', + 'multilang', + 'requirements', + 'site', + 'slugs', + 'title', + 'translation', + 'user' => 'auth', + 'version' + ] + ], ]; diff --git a/kirby/config/api/models/Translation.php b/kirby/config/api/models/Translation.php index fe31b56..faf51e7 100755 --- a/kirby/config/api/models/Translation.php +++ b/kirby/config/api/models/Translation.php @@ -6,19 +6,19 @@ use Kirby\Cms\Translation; * Translation */ return [ - 'fields' => [ - 'author' => fn (Translation $translation) => $translation->author(), - 'data' => fn (Translation $translation) => $translation->dataWithFallback(), - 'direction' => fn (Translation $translation) => $translation->direction(), - 'id' => fn (Translation $translation) => $translation->id(), - 'name' => fn (Translation $translation) => $translation->name(), - ], - 'type' => 'Kirby\Cms\Translation', - 'views' => [ - 'compact' => [ - 'direction', - 'id', - 'name' - ] - ] + 'fields' => [ + 'author' => fn (Translation $translation) => $translation->author(), + 'data' => fn (Translation $translation) => $translation->dataWithFallback(), + 'direction' => fn (Translation $translation) => $translation->direction(), + 'id' => fn (Translation $translation) => $translation->id(), + 'name' => fn (Translation $translation) => $translation->name(), + ], + 'type' => 'Kirby\Cms\Translation', + 'views' => [ + 'compact' => [ + 'direction', + 'id', + 'name' + ] + ] ]; diff --git a/kirby/config/api/models/User.php b/kirby/config/api/models/User.php index c8a7a5f..5354e3a 100755 --- a/kirby/config/api/models/User.php +++ b/kirby/config/api/models/User.php @@ -7,71 +7,71 @@ use Kirby\Form\Form; * User */ return [ - 'default' => fn () => $this->user(), - 'fields' => [ - 'avatar' => fn (User $user) => $user->avatar() ? $user->avatar()->crop(512) : null, - 'blueprint' => fn (User $user) => $user->blueprint(), - 'content' => fn (User $user) => Form::for($user)->values(), - 'email' => fn (User $user) => $user->email(), - 'files' => fn (User $user) => $user->files()->sorted(), - 'id' => fn (User $user) => $user->id(), - 'language' => fn (User $user) => $user->language(), - 'name' => fn (User $user) => $user->name()->value(), - 'next' => fn (User $user) => $user->next(), - 'options' => fn (User $user) => $user->panel()->options(), - 'panelImage' => fn (User $user) => $user->panel()->image(), - 'permissions' => fn (User $user) => $user->role()->permissions()->toArray(), - 'prev' => fn (User $user) => $user->prev(), - 'role' => fn (User $user) => $user->role(), - 'roles' => fn (User $user) => $user->roles(), - 'username' => fn (User $user) => $user->username() - ], - 'type' => 'Kirby\Cms\User', - 'views' => [ - 'default' => [ - 'avatar', - 'content', - 'email', - 'id', - 'language', - 'name', - 'next' => 'compact', - 'options', - 'prev' => 'compact', - 'role', - 'username' - ], - 'compact' => [ - 'avatar' => 'compact', - 'id', - 'email', - 'language', - 'name', - 'role' => 'compact', - 'username' - ], - 'auth' => [ - 'avatar' => 'compact', - 'permissions', - 'email', - 'id', - 'name', - 'role', - 'language' - ], - 'panel' => [ - 'avatar' => 'compact', - 'blueprint', - 'content', - 'email', - 'id', - 'language', - 'name', - 'next' => ['id', 'name'], - 'options', - 'prev' => ['id', 'name'], - 'role', - 'username', - ], - ] + 'default' => fn () => $this->user(), + 'fields' => [ + 'avatar' => fn (User $user) => $user->avatar() ? $user->avatar()->crop(512) : null, + 'blueprint' => fn (User $user) => $user->blueprint(), + 'content' => fn (User $user) => Form::for($user)->values(), + 'email' => fn (User $user) => $user->email(), + 'files' => fn (User $user) => $user->files()->sorted(), + 'id' => fn (User $user) => $user->id(), + 'language' => fn (User $user) => $user->language(), + 'name' => fn (User $user) => $user->name()->value(), + 'next' => fn (User $user) => $user->next(), + 'options' => fn (User $user) => $user->panel()->options(), + 'panelImage' => fn (User $user) => $user->panel()->image(), + 'permissions' => fn (User $user) => $user->role()->permissions()->toArray(), + 'prev' => fn (User $user) => $user->prev(), + 'role' => fn (User $user) => $user->role(), + 'roles' => fn (User $user) => $user->roles(), + 'username' => fn (User $user) => $user->username() + ], + 'type' => 'Kirby\Cms\User', + 'views' => [ + 'default' => [ + 'avatar', + 'content', + 'email', + 'id', + 'language', + 'name', + 'next' => 'compact', + 'options', + 'prev' => 'compact', + 'role', + 'username' + ], + 'compact' => [ + 'avatar' => 'compact', + 'id', + 'email', + 'language', + 'name', + 'role' => 'compact', + 'username' + ], + 'auth' => [ + 'avatar' => 'compact', + 'permissions', + 'email', + 'id', + 'name', + 'role', + 'language' + ], + 'panel' => [ + 'avatar' => 'compact', + 'blueprint', + 'content', + 'email', + 'id', + 'language', + 'name', + 'next' => ['id', 'name'], + 'options', + 'prev' => ['id', 'name'], + 'role', + 'username', + ], + ] ]; diff --git a/kirby/config/api/models/UserBlueprint.php b/kirby/config/api/models/UserBlueprint.php index f20c88a..099a177 100755 --- a/kirby/config/api/models/UserBlueprint.php +++ b/kirby/config/api/models/UserBlueprint.php @@ -6,13 +6,13 @@ use Kirby\Cms\UserBlueprint; * UserBlueprint */ return [ - 'fields' => [ - 'name' => fn (UserBlueprint $blueprint) => $blueprint->name(), - 'options' => fn (UserBlueprint $blueprint) => $blueprint->options(), - 'tabs' => fn (UserBlueprint $blueprint) => $blueprint->tabs(), - 'title' => fn (UserBlueprint $blueprint) => $blueprint->title(), - ], - 'type' => 'Kirby\Cms\UserBlueprint', - 'views' => [ - ], + 'fields' => [ + 'name' => fn (UserBlueprint $blueprint) => $blueprint->name(), + 'options' => fn (UserBlueprint $blueprint) => $blueprint->options(), + 'tabs' => fn (UserBlueprint $blueprint) => $blueprint->tabs(), + 'title' => fn (UserBlueprint $blueprint) => $blueprint->title(), + ], + 'type' => 'Kirby\Cms\UserBlueprint', + 'views' => [ + ], ]; diff --git a/kirby/config/api/routes.php b/kirby/config/api/routes.php index fd3449d..749fbad 100755 --- a/kirby/config/api/routes.php +++ b/kirby/config/api/routes.php @@ -4,23 +4,23 @@ * Api Routes Definitions */ return function ($kirby) { - $routes = array_merge( - include __DIR__ . '/routes/auth.php', - include __DIR__ . '/routes/pages.php', - include __DIR__ . '/routes/roles.php', - include __DIR__ . '/routes/site.php', - include __DIR__ . '/routes/users.php', - include __DIR__ . '/routes/files.php', - include __DIR__ . '/routes/lock.php', - include __DIR__ . '/routes/system.php', - include __DIR__ . '/routes/translations.php' - ); + $routes = array_merge( + include __DIR__ . '/routes/auth.php', + include __DIR__ . '/routes/pages.php', + include __DIR__ . '/routes/roles.php', + include __DIR__ . '/routes/site.php', + include __DIR__ . '/routes/users.php', + include __DIR__ . '/routes/files.php', + include __DIR__ . '/routes/lock.php', + include __DIR__ . '/routes/system.php', + include __DIR__ . '/routes/translations.php' + ); - // only add the language routes if the - // multi language setup is activated - if ($kirby->option('languages', false) !== false) { - $routes = array_merge($routes, include __DIR__ . '/routes/languages.php'); - } + // only add the language routes if the + // multi language setup is activated + if ($kirby->option('languages', false) !== false) { + $routes = array_merge($routes, include __DIR__ . '/routes/languages.php'); + } - return $routes; + return $routes; }; diff --git a/kirby/config/api/routes/auth.php b/kirby/config/api/routes/auth.php index 19f45a5..a4fcbb4 100755 --- a/kirby/config/api/routes/auth.php +++ b/kirby/config/api/routes/auth.php @@ -7,102 +7,102 @@ use Kirby\Exception\NotFoundException; * Authentication */ return [ - [ - 'pattern' => 'auth', - 'method' => 'GET', - 'action' => function () { - if ($user = $this->kirby()->auth()->user()) { - return $this->resolve($user)->view('auth'); - } + [ + 'pattern' => 'auth', + 'method' => 'GET', + 'action' => function () { + if ($user = $this->kirby()->auth()->user()) { + return $this->resolve($user)->view('auth'); + } - throw new NotFoundException('The user cannot be found'); - } - ], - [ - 'pattern' => 'auth/code', - 'method' => 'POST', - 'auth' => false, - 'action' => function () { - $auth = $this->kirby()->auth(); + throw new NotFoundException('The user cannot be found'); + } + ], + [ + 'pattern' => 'auth/code', + 'method' => 'POST', + 'auth' => false, + 'action' => function () { + $auth = $this->kirby()->auth(); - // csrf token check - if ($auth->type() === 'session' && $auth->csrf() === false) { - throw new InvalidArgumentException('Invalid CSRF token'); - } + // csrf token check + if ($auth->type() === 'session' && $auth->csrf() === false) { + throw new InvalidArgumentException('Invalid CSRF token'); + } - $user = $auth->verifyChallenge($this->requestBody('code')); + $user = $auth->verifyChallenge($this->requestBody('code')); - return [ - 'code' => 200, - 'status' => 'ok', - 'user' => $this->resolve($user)->view('auth')->toArray() - ]; - } - ], - [ - 'pattern' => 'auth/login', - 'method' => 'POST', - 'auth' => false, - 'action' => function () { - $auth = $this->kirby()->auth(); - $methods = $this->kirby()->system()->loginMethods(); + return [ + 'code' => 200, + 'status' => 'ok', + 'user' => $this->resolve($user)->view('auth')->toArray() + ]; + } + ], + [ + 'pattern' => 'auth/login', + 'method' => 'POST', + 'auth' => false, + 'action' => function () { + $auth = $this->kirby()->auth(); + $methods = $this->kirby()->system()->loginMethods(); - // csrf token check - if ($auth->type() === 'session' && $auth->csrf() === false) { - throw new InvalidArgumentException('Invalid CSRF token'); - } + // csrf token check + if ($auth->type() === 'session' && $auth->csrf() === false) { + throw new InvalidArgumentException('Invalid CSRF token'); + } - $email = $this->requestBody('email'); - $long = $this->requestBody('long'); - $password = $this->requestBody('password'); + $email = $this->requestBody('email'); + $long = $this->requestBody('long'); + $password = $this->requestBody('password'); - if ($password) { - if (isset($methods['password']) !== true) { - throw new InvalidArgumentException('Login with password is not enabled'); - } + if ($password) { + if (isset($methods['password']) !== true) { + throw new InvalidArgumentException('Login with password is not enabled'); + } - if ( - isset($methods['password']['2fa']) === true && - $methods['password']['2fa'] === true - ) { - $status = $auth->login2fa($email, $password, $long); - } else { - $user = $auth->login($email, $password, $long); - } - } else { - if (isset($methods['code']) === true) { - $mode = 'login'; - } elseif (isset($methods['password-reset']) === true) { - $mode = 'password-reset'; - } else { - throw new InvalidArgumentException('Login without password is not enabled'); - } + if ( + isset($methods['password']['2fa']) === true && + $methods['password']['2fa'] === true + ) { + $status = $auth->login2fa($email, $password, $long); + } else { + $user = $auth->login($email, $password, $long); + } + } else { + if (isset($methods['code']) === true) { + $mode = 'login'; + } elseif (isset($methods['password-reset']) === true) { + $mode = 'password-reset'; + } else { + throw new InvalidArgumentException('Login without password is not enabled'); + } - $status = $auth->createChallenge($email, $long, $mode); - } + $status = $auth->createChallenge($email, $long, $mode); + } - if (isset($user)) { - return [ - 'code' => 200, - 'status' => 'ok', - 'user' => $this->resolve($user)->view('auth')->toArray() - ]; - } else { - return [ - 'code' => 200, - 'status' => 'ok', - 'challenge' => $status->challenge() - ]; - } - } - ], - [ - 'pattern' => 'auth/logout', - 'method' => 'POST', - 'auth' => false, - 'action' => function () { - $this->kirby()->auth()->logout(); - return true; - } - ], + if (isset($user)) { + return [ + 'code' => 200, + 'status' => 'ok', + 'user' => $this->resolve($user)->view('auth')->toArray() + ]; + } else { + return [ + 'code' => 200, + 'status' => 'ok', + 'challenge' => $status->challenge() + ]; + } + } + ], + [ + 'pattern' => 'auth/logout', + 'method' => 'POST', + 'auth' => false, + 'action' => function () { + $this->kirby()->auth()->logout(); + return true; + } + ], ]; diff --git a/kirby/config/api/routes/files.php b/kirby/config/api/routes/files.php index 77aea9c..c1b755b 100755 --- a/kirby/config/api/routes/files.php +++ b/kirby/config/api/routes/files.php @@ -8,125 +8,125 @@ $pattern = '(account|pages/[^/]+|site|users/[^/]+)'; */ return [ - [ - 'pattern' => $pattern . '/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' => $pattern . '/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' => $pattern . '/files', - 'method' => 'GET', - 'action' => function (string $path) { - return $this->parent($path)->files()->sorted(); - } - ], - [ - 'pattern' => $pattern . '/files', - 'method' => 'POST', - 'action' => function (string $path) { - // move_uploaded_file() not working with unit test - // @codeCoverageIgnoreStart - return $this->upload(function ($source, $filename) use ($path) { - return $this->parent($path)->createFile([ - 'content' => [ - 'sort' => $this->requestBody('sort') - ], - 'source' => $source, - 'template' => $this->requestBody('template'), - 'filename' => $filename - ]); - }); - // @codeCoverageIgnoreEnd - } - ], - [ - 'pattern' => $pattern . '/files/search', - 'method' => 'GET|POST', - 'action' => function (string $path) { - $files = $this->parent($path)->files(); + [ + 'pattern' => $pattern . '/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' => $pattern . '/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' => $pattern . '/files', + 'method' => 'GET', + 'action' => function (string $path) { + return $this->parent($path)->files()->sorted(); + } + ], + [ + 'pattern' => $pattern . '/files', + 'method' => 'POST', + 'action' => function (string $path) { + // move_uploaded_file() not working with unit test + // @codeCoverageIgnoreStart + return $this->upload(function ($source, $filename) use ($path) { + return $this->parent($path)->createFile([ + 'content' => [ + 'sort' => $this->requestBody('sort') + ], + 'source' => $source, + 'template' => $this->requestBody('template'), + 'filename' => $filename + ]); + }); + // @codeCoverageIgnoreEnd + } + ], + [ + 'pattern' => $pattern . '/files/search', + 'method' => 'GET|POST', + 'action' => function (string $path) { + $files = $this->parent($path)->files(); - if ($this->requestMethod() === 'GET') { - return $files->search($this->requestQuery('q')); - } else { - return $files->query($this->requestBody()); - } - } - ], - [ - 'pattern' => $pattern . '/files/sort', - 'method' => 'PATCH', - 'action' => function (string $path) { - return $this->parent($path)->files()->changeSort( - $this->requestBody('files'), - $this->requestBody('index') - ); - } - ], - [ - 'pattern' => $pattern . '/files/(:any)', - 'method' => 'GET', - 'action' => function (string $path, string $filename) { - return $this->file($path, $filename); - } - ], - [ - 'pattern' => $pattern . '/files/(:any)', - 'method' => 'PATCH', - 'action' => function (string $path, string $filename) { - return $this->file($path, $filename)->update($this->requestBody(), $this->language(), true); - } - ], - [ - 'pattern' => $pattern . '/files/(:any)', - 'method' => 'POST', - 'action' => function (string $path, string $filename) { - return $this->upload(function ($source) use ($path, $filename) { - return $this->file($path, $filename)->replace($source); - }); - } - ], - [ - 'pattern' => $pattern . '/files/(:any)', - 'method' => 'DELETE', - 'action' => function (string $path, string $filename) { - return $this->file($path, $filename)->delete(); - } - ], - [ - 'pattern' => $pattern . '/files/(:any)/name', - 'method' => 'PATCH', - 'action' => function (string $path, string $filename) { - return $this->file($path, $filename)->changeName($this->requestBody('name')); - } - ], - [ - 'pattern' => 'files/search', - 'method' => 'GET|POST', - 'action' => function () { - $files = $this - ->site() - ->index(true) - ->filter('isReadable', true) - ->files(); + if ($this->requestMethod() === 'GET') { + return $files->search($this->requestQuery('q')); + } else { + return $files->query($this->requestBody()); + } + } + ], + [ + 'pattern' => $pattern . '/files/sort', + 'method' => 'PATCH', + 'action' => function (string $path) { + return $this->parent($path)->files()->changeSort( + $this->requestBody('files'), + $this->requestBody('index') + ); + } + ], + [ + 'pattern' => $pattern . '/files/(:any)', + 'method' => 'GET', + 'action' => function (string $path, string $filename) { + return $this->file($path, $filename); + } + ], + [ + 'pattern' => $pattern . '/files/(:any)', + 'method' => 'PATCH', + 'action' => function (string $path, string $filename) { + return $this->file($path, $filename)->update($this->requestBody(), $this->language(), true); + } + ], + [ + 'pattern' => $pattern . '/files/(:any)', + 'method' => 'POST', + 'action' => function (string $path, string $filename) { + return $this->upload(function ($source) use ($path, $filename) { + return $this->file($path, $filename)->replace($source); + }); + } + ], + [ + 'pattern' => $pattern . '/files/(:any)', + 'method' => 'DELETE', + 'action' => function (string $path, string $filename) { + return $this->file($path, $filename)->delete(); + } + ], + [ + 'pattern' => $pattern . '/files/(:any)/name', + 'method' => 'PATCH', + 'action' => function (string $path, string $filename) { + return $this->file($path, $filename)->changeName($this->requestBody('name')); + } + ], + [ + 'pattern' => 'files/search', + 'method' => 'GET|POST', + 'action' => function () { + $files = $this + ->site() + ->index(true) + ->filter('isReadable', true) + ->files(); - if ($this->requestMethod() === 'GET') { - return $files->search($this->requestQuery('q')); - } else { - return $files->query($this->requestBody()); - } - } - ], + if ($this->requestMethod() === 'GET') { + return $files->search($this->requestQuery('q')); + } else { + return $files->query($this->requestBody()); + } + } + ], ]; diff --git a/kirby/config/api/routes/languages.php b/kirby/config/api/routes/languages.php index 8d8829b..4105ef2 100755 --- a/kirby/config/api/routes/languages.php +++ b/kirby/config/api/routes/languages.php @@ -4,43 +4,43 @@ * Roles Routes */ return [ - [ - 'pattern' => 'languages', - 'method' => 'GET', - 'action' => function () { - return $this->kirby()->languages(); - } - ], - [ - 'pattern' => 'languages', - 'method' => 'POST', - 'action' => function () { - return $this->kirby()->languages()->create($this->requestBody()); - } - ], - [ - 'pattern' => 'languages/(:any)', - 'method' => 'GET', - 'action' => function (string $code) { - return $this->kirby()->languages()->find($code); - } - ], - [ - 'pattern' => 'languages/(:any)', - 'method' => 'PATCH', - 'action' => function (string $code) { - if ($language = $this->kirby()->languages()->find($code)) { - return $language->update($this->requestBody()); - } - } - ], - [ - 'pattern' => 'languages/(:any)', - 'method' => 'DELETE', - 'action' => function (string $code) { - if ($language = $this->kirby()->languages()->find($code)) { - return $language->delete(); - } - } - ] + [ + 'pattern' => 'languages', + 'method' => 'GET', + 'action' => function () { + return $this->kirby()->languages(); + } + ], + [ + 'pattern' => 'languages', + 'method' => 'POST', + 'action' => function () { + return $this->kirby()->languages()->create($this->requestBody()); + } + ], + [ + 'pattern' => 'languages/(:any)', + 'method' => 'GET', + 'action' => function (string $code) { + return $this->kirby()->languages()->find($code); + } + ], + [ + 'pattern' => 'languages/(:any)', + 'method' => 'PATCH', + 'action' => function (string $code) { + if ($language = $this->kirby()->languages()->find($code)) { + return $language->update($this->requestBody()); + } + } + ], + [ + 'pattern' => 'languages/(:any)', + 'method' => 'DELETE', + 'action' => function (string $code) { + if ($language = $this->kirby()->languages()->find($code)) { + return $language->delete(); + } + } + ] ]; diff --git a/kirby/config/api/routes/lock.php b/kirby/config/api/routes/lock.php index 935d5fe..c5b2da4 100755 --- a/kirby/config/api/routes/lock.php +++ b/kirby/config/api/routes/lock.php @@ -5,40 +5,40 @@ * Content Lock Routes */ return [ - [ - 'pattern' => '(:all)/lock', - 'method' => 'PATCH', - 'action' => function (string $path) { - if ($lock = $this->parent($path)->lock()) { - return $lock->create(); - } - } - ], - [ - 'pattern' => '(:all)/lock', - 'method' => 'DELETE', - 'action' => function (string $path) { - if ($lock = $this->parent($path)->lock()) { - return $lock->remove(); - } - } - ], - [ - 'pattern' => '(:all)/unlock', - 'method' => 'PATCH', - 'action' => function (string $path) { - if ($lock = $this->parent($path)->lock()) { - return $lock->unlock(); - } - } - ], - [ - 'pattern' => '(:all)/unlock', - 'method' => 'DELETE', - 'action' => function (string $path) { - if ($lock = $this->parent($path)->lock()) { - return $lock->resolve(); - } - } - ], + [ + 'pattern' => '(:all)/lock', + 'method' => 'PATCH', + 'action' => function (string $path) { + if ($lock = $this->parent($path)->lock()) { + return $lock->create(); + } + } + ], + [ + 'pattern' => '(:all)/lock', + 'method' => 'DELETE', + 'action' => function (string $path) { + if ($lock = $this->parent($path)->lock()) { + return $lock->remove(); + } + } + ], + [ + 'pattern' => '(:all)/unlock', + 'method' => 'PATCH', + 'action' => function (string $path) { + if ($lock = $this->parent($path)->lock()) { + return $lock->unlock(); + } + } + ], + [ + 'pattern' => '(:all)/unlock', + 'method' => 'DELETE', + 'action' => function (string $path) { + if ($lock = $this->parent($path)->lock()) { + return $lock->resolve(); + } + } + ], ]; diff --git a/kirby/config/api/routes/pages.php b/kirby/config/api/routes/pages.php index 525fdc4..3ff255c 100755 --- a/kirby/config/api/routes/pages.php +++ b/kirby/config/api/routes/pages.php @@ -6,116 +6,116 @@ */ return [ - [ - 'pattern' => 'pages/(:any)', - 'method' => 'GET', - 'action' => function (string $id) { - return $this->page($id); - } - ], - [ - 'pattern' => 'pages/(:any)', - 'method' => 'PATCH', - 'action' => function (string $id) { - return $this->page($id)->update($this->requestBody(), $this->language(), true); - } - ], - [ - 'pattern' => 'pages/(:any)', - 'method' => 'DELETE', - 'action' => function (string $id) { - return $this->page($id)->delete($this->requestBody('force', false)); - } - ], - [ - 'pattern' => 'pages/(:any)/blueprint', - 'method' => 'GET', - 'action' => function (string $id) { - return $this->page($id)->blueprint(); - } - ], - [ - 'pattern' => 'pages/(:any)/blueprints', - 'method' => 'GET', - 'action' => function (string $id) { - return $this->page($id)->blueprints($this->requestQuery('section')); - } - ], - [ - 'pattern' => 'pages/(:any)/children', - 'method' => 'GET', - 'action' => function (string $id) { - return $this->pages($id, $this->requestQuery('status')); - } - ], - [ - 'pattern' => 'pages/(:any)/children', - 'method' => 'POST', - 'action' => function (string $id) { - return $this->page($id)->createChild($this->requestBody()); - } - ], - [ - 'pattern' => 'pages/(:any)/children/search', - 'method' => 'GET|POST', - 'action' => function (string $id) { - return $this->searchPages($id); - } - ], - [ - 'pattern' => 'pages/(:any)/duplicate', - 'method' => 'POST', - 'action' => function (string $id) { - return $this->page($id)->duplicate($this->requestBody('slug'), [ - 'children' => $this->requestBody('children'), - 'files' => $this->requestBody('files'), - ]); - } - ], - [ - 'pattern' => 'pages/(:any)/slug', - 'method' => 'PATCH', - 'action' => function (string $id) { - return $this->page($id)->changeSlug($this->requestBody('slug')); - } - ], - [ - 'pattern' => 'pages/(:any)/status', - 'method' => 'PATCH', - 'action' => function (string $id) { - return $this->page($id)->changeStatus($this->requestBody('status'), $this->requestBody('position')); - } - ], - [ - 'pattern' => 'pages/(:any)/template', - 'method' => 'PATCH', - 'action' => function (string $id) { - return $this->page($id)->changeTemplate($this->requestBody('template')); - } - ], - [ - 'pattern' => 'pages/(:any)/title', - 'method' => 'PATCH', - 'action' => function (string $id) { - return $this->page($id)->changeTitle($this->requestBody('title')); - } - ], - [ - 'pattern' => 'pages/(:any)/sections/(:any)', - 'method' => 'GET', - 'action' => function (string $id, string $sectionName) { - if ($section = $this->page($id)->blueprint()->section($sectionName)) { - return $section->toResponse(); - } - } - ], - [ - 'pattern' => 'pages/(:any)/fields/(:any)/(:all?)', - 'method' => 'ALL', - 'action' => function (string $id, string $fieldName, string $path = null) { - if ($page = $this->page($id)) { - return $this->fieldApi($page, $fieldName, $path); - } - } - ], + [ + 'pattern' => 'pages/(:any)', + 'method' => 'GET', + 'action' => function (string $id) { + return $this->page($id); + } + ], + [ + 'pattern' => 'pages/(:any)', + 'method' => 'PATCH', + 'action' => function (string $id) { + return $this->page($id)->update($this->requestBody(), $this->language(), true); + } + ], + [ + 'pattern' => 'pages/(:any)', + 'method' => 'DELETE', + 'action' => function (string $id) { + return $this->page($id)->delete($this->requestBody('force', false)); + } + ], + [ + 'pattern' => 'pages/(:any)/blueprint', + 'method' => 'GET', + 'action' => function (string $id) { + return $this->page($id)->blueprint(); + } + ], + [ + 'pattern' => 'pages/(:any)/blueprints', + 'method' => 'GET', + 'action' => function (string $id) { + return $this->page($id)->blueprints($this->requestQuery('section')); + } + ], + [ + 'pattern' => 'pages/(:any)/children', + 'method' => 'GET', + 'action' => function (string $id) { + return $this->pages($id, $this->requestQuery('status')); + } + ], + [ + 'pattern' => 'pages/(:any)/children', + 'method' => 'POST', + 'action' => function (string $id) { + return $this->page($id)->createChild($this->requestBody()); + } + ], + [ + 'pattern' => 'pages/(:any)/children/search', + 'method' => 'GET|POST', + 'action' => function (string $id) { + return $this->searchPages($id); + } + ], + [ + 'pattern' => 'pages/(:any)/duplicate', + 'method' => 'POST', + 'action' => function (string $id) { + return $this->page($id)->duplicate($this->requestBody('slug'), [ + 'children' => $this->requestBody('children'), + 'files' => $this->requestBody('files'), + ]); + } + ], + [ + 'pattern' => 'pages/(:any)/slug', + 'method' => 'PATCH', + 'action' => function (string $id) { + return $this->page($id)->changeSlug($this->requestBody('slug')); + } + ], + [ + 'pattern' => 'pages/(:any)/status', + 'method' => 'PATCH', + 'action' => function (string $id) { + return $this->page($id)->changeStatus($this->requestBody('status'), $this->requestBody('position')); + } + ], + [ + 'pattern' => 'pages/(:any)/template', + 'method' => 'PATCH', + 'action' => function (string $id) { + return $this->page($id)->changeTemplate($this->requestBody('template')); + } + ], + [ + 'pattern' => 'pages/(:any)/title', + 'method' => 'PATCH', + 'action' => function (string $id) { + return $this->page($id)->changeTitle($this->requestBody('title')); + } + ], + [ + 'pattern' => 'pages/(:any)/sections/(:any)', + 'method' => 'GET', + 'action' => function (string $id, string $sectionName) { + if ($section = $this->page($id)->blueprint()->section($sectionName)) { + return $section->toResponse(); + } + } + ], + [ + 'pattern' => 'pages/(:any)/fields/(:any)/(:all?)', + 'method' => 'ALL', + 'action' => function (string $id, string $fieldName, string $path = null) { + if ($page = $this->page($id)) { + return $this->fieldApi($page, $fieldName, $path); + } + } + ], ]; diff --git a/kirby/config/api/routes/roles.php b/kirby/config/api/routes/roles.php index bd91952..7dbe45f 100755 --- a/kirby/config/api/routes/roles.php +++ b/kirby/config/api/routes/roles.php @@ -4,27 +4,27 @@ * Roles Routes */ return [ - [ - 'pattern' => 'roles', - 'method' => 'GET', - 'action' => function () { - $kirby = $this->kirby(); + [ + 'pattern' => 'roles', + 'method' => 'GET', + 'action' => function () { + $kirby = $this->kirby(); - switch ($kirby->request()->get('canBe')) { - case 'changed': - return $kirby->roles()->canBeChanged(); - case 'created': - return $kirby->roles()->canBeCreated(); - default: - return $kirby->roles(); - } - } - ], - [ - 'pattern' => 'roles/(:any)', - 'method' => 'GET', - 'action' => function (string $name) { - return $this->kirby()->roles()->find($name); - } - ] + switch ($kirby->request()->get('canBe')) { + case 'changed': + return $kirby->roles()->canBeChanged(); + case 'created': + return $kirby->roles()->canBeCreated(); + default: + return $kirby->roles(); + } + } + ], + [ + 'pattern' => 'roles/(:any)', + 'method' => 'GET', + 'action' => function (string $name) { + return $this->kirby()->roles()->find($name); + } + ] ]; diff --git a/kirby/config/api/routes/site.php b/kirby/config/api/routes/site.php index 890707e..3f2601c 100755 --- a/kirby/config/api/routes/site.php +++ b/kirby/config/api/routes/site.php @@ -6,99 +6,99 @@ */ return [ - [ - 'pattern' => 'site', - 'action' => function () { - return $this->site(); - } - ], - [ - 'pattern' => 'site', - 'method' => 'PATCH', - 'action' => function () { - return $this->site()->update($this->requestBody(), $this->language(), true); - } - ], - [ - 'pattern' => 'site/children', - 'method' => 'GET', - 'action' => function () { - return $this->pages(null, $this->requestQuery('status')); - } - ], - [ - 'pattern' => 'site/children', - 'method' => 'POST', - 'action' => function () { - return $this->site()->createChild($this->requestBody()); - } - ], - [ - 'pattern' => 'site/children/search', - 'method' => 'GET|POST', - 'action' => function () { - return $this->searchPages(); - } - ], - [ - 'pattern' => 'site/blueprint', - 'method' => 'GET', - 'action' => function () { - return $this->site()->blueprint(); - } - ], - [ - 'pattern' => 'site/blueprints', - 'method' => 'GET', - 'action' => function () { - return $this->site()->blueprints($this->requestQuery('section')); - } - ], - [ - 'pattern' => 'site/find', - 'method' => 'POST', - 'action' => function () { - return $this->site()->find(false, ...$this->requestBody()); - } - ], - [ - 'pattern' => 'site/title', - 'method' => 'PATCH', - 'action' => function () { - return $this->site()->changeTitle($this->requestBody('title')); - } - ], - [ - 'pattern' => 'site/search', - 'method' => 'GET|POST', - 'action' => function () { - $pages = $this - ->site() - ->index(true) - ->filter('isReadable', true); + [ + 'pattern' => 'site', + 'action' => function () { + return $this->site(); + } + ], + [ + 'pattern' => 'site', + 'method' => 'PATCH', + 'action' => function () { + return $this->site()->update($this->requestBody(), $this->language(), true); + } + ], + [ + 'pattern' => 'site/children', + 'method' => 'GET', + 'action' => function () { + return $this->pages(null, $this->requestQuery('status')); + } + ], + [ + 'pattern' => 'site/children', + 'method' => 'POST', + 'action' => function () { + return $this->site()->createChild($this->requestBody()); + } + ], + [ + 'pattern' => 'site/children/search', + 'method' => 'GET|POST', + 'action' => function () { + return $this->searchPages(); + } + ], + [ + 'pattern' => 'site/blueprint', + 'method' => 'GET', + 'action' => function () { + return $this->site()->blueprint(); + } + ], + [ + 'pattern' => 'site/blueprints', + 'method' => 'GET', + 'action' => function () { + return $this->site()->blueprints($this->requestQuery('section')); + } + ], + [ + 'pattern' => 'site/find', + 'method' => 'POST', + 'action' => function () { + return $this->site()->find(false, ...$this->requestBody()); + } + ], + [ + 'pattern' => 'site/title', + 'method' => 'PATCH', + 'action' => function () { + return $this->site()->changeTitle($this->requestBody('title')); + } + ], + [ + 'pattern' => 'site/search', + 'method' => 'GET|POST', + 'action' => function () { + $pages = $this + ->site() + ->index(true) + ->filter('isReadable', true); - if ($this->requestMethod() === 'GET') { - return $pages->search($this->requestQuery('q')); - } else { - return $pages->query($this->requestBody()); - } - } - ], - [ - 'pattern' => 'site/sections/(:any)', - 'method' => 'GET', - 'action' => function (string $sectionName) { - if ($section = $this->site()->blueprint()->section($sectionName)) { - return $section->toResponse(); - } - } - ], - [ - 'pattern' => 'site/fields/(:any)/(:all?)', - 'method' => 'ALL', - 'action' => function (string $fieldName, string $path = null) { - return $this->fieldApi($this->site(), $fieldName, $path); - } - ] + if ($this->requestMethod() === 'GET') { + return $pages->search($this->requestQuery('q')); + } else { + return $pages->query($this->requestBody()); + } + } + ], + [ + 'pattern' => 'site/sections/(:any)', + 'method' => 'GET', + 'action' => function (string $sectionName) { + if ($section = $this->site()->blueprint()->section($sectionName)) { + return $section->toResponse(); + } + } + ], + [ + 'pattern' => 'site/fields/(:any)/(:all?)', + 'method' => 'ALL', + 'action' => function (string $fieldName, string $path = null) { + return $this->fieldApi($this->site(), $fieldName, $path); + } + ] ]; diff --git a/kirby/config/api/routes/system.php b/kirby/config/api/routes/system.php index 44c8807..0f6ba46 100755 --- a/kirby/config/api/routes/system.php +++ b/kirby/config/api/routes/system.php @@ -8,72 +8,72 @@ use Kirby\Exception\InvalidArgumentException; */ return [ - [ - 'pattern' => 'system', - 'method' => 'GET', - 'auth' => false, - 'action' => function () { - $system = $this->kirby()->system(); + [ + 'pattern' => 'system', + 'method' => 'GET', + 'auth' => false, + 'action' => function () { + $system = $this->kirby()->system(); - if ($this->kirby()->user()) { - return $system; - } else { - if ($system->isOk() === true) { - $info = $this->resolve($system)->view('login')->toArray(); - } else { - $info = $this->resolve($system)->view('troubleshooting')->toArray(); - } + if ($this->kirby()->user()) { + return $system; + } else { + if ($system->isOk() === true) { + $info = $this->resolve($system)->view('login')->toArray(); + } else { + $info = $this->resolve($system)->view('troubleshooting')->toArray(); + } - return [ - 'status' => 'ok', - 'data' => $info, - 'type' => 'model' - ]; - } - } - ], - [ - 'pattern' => 'system/register', - 'method' => 'POST', - 'action' => function () { - return $this->kirby()->system()->register($this->requestBody('license'), $this->requestBody('email')); - } - ], - [ - 'pattern' => 'system/install', - 'method' => 'POST', - 'auth' => false, - 'action' => function () { - $system = $this->kirby()->system(); - $auth = $this->kirby()->auth(); + return [ + 'status' => 'ok', + 'data' => $info, + 'type' => 'model' + ]; + } + } + ], + [ + 'pattern' => 'system/register', + 'method' => 'POST', + 'action' => function () { + return $this->kirby()->system()->register($this->requestBody('license'), $this->requestBody('email')); + } + ], + [ + 'pattern' => 'system/install', + 'method' => 'POST', + 'auth' => false, + 'action' => function () { + $system = $this->kirby()->system(); + $auth = $this->kirby()->auth(); - // csrf token check - if ($auth->type() === 'session' && $auth->csrf() === false) { - throw new InvalidArgumentException('Invalid CSRF token'); - } + // csrf token check + if ($auth->type() === 'session' && $auth->csrf() === false) { + throw new InvalidArgumentException('Invalid CSRF token'); + } - if ($system->isOk() === false) { - throw new Exception('The server is not setup correctly'); - } + if ($system->isOk() === false) { + throw new Exception('The server is not setup correctly'); + } - if ($system->isInstallable() === false) { - throw new Exception('The Panel cannot be installed'); - } + if ($system->isInstallable() === false) { + throw new Exception('The Panel cannot be installed'); + } - if ($system->isInstalled() === true) { - throw new Exception('The Panel is already installed'); - } + if ($system->isInstalled() === true) { + throw new Exception('The Panel is already installed'); + } - // create the first user - $user = $this->users()->create($this->requestBody()); - $token = $user->login($this->requestBody('password')); + // create the first user + $user = $this->users()->create($this->requestBody()); + $token = $user->login($this->requestBody('password')); - return [ - 'status' => 'ok', - 'token' => $token, - 'user' => $this->resolve($user)->view('auth')->toArray() - ]; - } - ] + return [ + 'status' => 'ok', + 'token' => $token, + 'user' => $this->resolve($user)->view('auth')->toArray() + ]; + } + ] ]; diff --git a/kirby/config/api/routes/translations.php b/kirby/config/api/routes/translations.php index db7faca..2d949c5 100755 --- a/kirby/config/api/routes/translations.php +++ b/kirby/config/api/routes/translations.php @@ -4,21 +4,21 @@ * Translations Routes */ return [ - [ - 'pattern' => 'translations', - 'method' => 'GET', - 'auth' => false, - 'action' => function () { - return $this->kirby()->translations(); - } - ], - [ - 'pattern' => 'translations/(:any)', - 'method' => 'GET', - 'auth' => false, - 'action' => function (string $code) { - return $this->kirby()->translations()->find($code); - } - ] + [ + 'pattern' => 'translations', + 'method' => 'GET', + 'auth' => false, + 'action' => function () { + return $this->kirby()->translations(); + } + ], + [ + 'pattern' => 'translations/(:any)', + 'method' => 'GET', + 'auth' => false, + 'action' => function (string $code) { + return $this->kirby()->translations()->find($code); + } + ] ]; diff --git a/kirby/config/api/routes/users.php b/kirby/config/api/routes/users.php index abd09c5..daa245d 100755 --- a/kirby/config/api/routes/users.php +++ b/kirby/config/api/routes/users.php @@ -6,202 +6,202 @@ use Kirby\Filesystem\F; * User Routes */ return [ - [ - 'pattern' => 'users', - 'method' => 'GET', - 'action' => function () { - return $this->users()->sort('username', 'asc', 'email', 'asc'); - } - ], - [ - 'pattern' => 'users', - 'method' => 'POST', - 'action' => function () { - return $this->users()->create($this->requestBody()); - } - ], - [ - 'pattern' => 'users/search', - 'method' => 'GET|POST', - 'action' => function () { - if ($this->requestMethod() === 'GET') { - return $this->users()->search($this->requestQuery('q')); - } else { - return $this->users()->query($this->requestBody()); - } - } - ], - [ - 'pattern' => [ - '(account)', - 'users/(:any)', - ], - 'method' => 'GET', - 'action' => function (string $id) { - return $this->user($id); - } - ], - [ - 'pattern' => [ - '(account)', - 'users/(:any)', - ], - 'method' => 'PATCH', - 'action' => function (string $id) { - return $this->user($id)->update($this->requestBody(), $this->language(), true); - } - ], - [ - 'pattern' => [ - '(account)', - 'users/(:any)', - ], - 'method' => 'DELETE', - 'action' => function (string $id) { - return $this->user($id)->delete(); - } - ], - [ - 'pattern' => [ - '(account)/avatar', - 'users/(:any)/avatar', - ], - 'method' => 'GET', - 'action' => function (string $id) { - return $this->user($id)->avatar(); - } - ], - // @codeCoverageIgnoreStart - [ - 'pattern' => [ - '(account)/avatar', - 'users/(:any)/avatar', - ], - 'method' => 'POST', - 'action' => function (string $id) { - if ($avatar = $this->user($id)->avatar()) { - $avatar->delete(); - } + [ + 'pattern' => 'users', + 'method' => 'GET', + 'action' => function () { + return $this->users()->sort('username', 'asc', 'email', 'asc'); + } + ], + [ + 'pattern' => 'users', + 'method' => 'POST', + 'action' => function () { + return $this->users()->create($this->requestBody()); + } + ], + [ + 'pattern' => 'users/search', + 'method' => 'GET|POST', + 'action' => function () { + if ($this->requestMethod() === 'GET') { + return $this->users()->search($this->requestQuery('q')); + } else { + return $this->users()->query($this->requestBody()); + } + } + ], + [ + 'pattern' => [ + '(account)', + 'users/(:any)', + ], + 'method' => 'GET', + 'action' => function (string $id) { + return $this->user($id); + } + ], + [ + 'pattern' => [ + '(account)', + 'users/(:any)', + ], + 'method' => 'PATCH', + 'action' => function (string $id) { + return $this->user($id)->update($this->requestBody(), $this->language(), true); + } + ], + [ + 'pattern' => [ + '(account)', + 'users/(:any)', + ], + 'method' => 'DELETE', + 'action' => function (string $id) { + return $this->user($id)->delete(); + } + ], + [ + 'pattern' => [ + '(account)/avatar', + 'users/(:any)/avatar', + ], + 'method' => 'GET', + 'action' => function (string $id) { + return $this->user($id)->avatar(); + } + ], + // @codeCoverageIgnoreStart + [ + 'pattern' => [ + '(account)/avatar', + 'users/(:any)/avatar', + ], + 'method' => 'POST', + 'action' => function (string $id) { + if ($avatar = $this->user($id)->avatar()) { + $avatar->delete(); + } - return $this->upload(function ($source, $filename) use ($id) { - return $this->user($id)->createFile([ - 'filename' => 'profile.' . F::extension($filename), - 'template' => 'avatar', - 'source' => $source - ]); - }, $single = true); - } - ], - // @codeCoverageIgnoreEnd - [ - 'pattern' => [ - '(account)/avatar', - 'users/(:any)/avatar', - ], - 'method' => 'DELETE', - 'action' => function (string $id) { - return $this->user($id)->avatar()->delete(); - } - ], - [ - 'pattern' => [ - '(account)/blueprint', - 'users/(:any)/blueprint', - ], - 'method' => 'GET', - 'action' => function (string $id) { - return $this->user($id)->blueprint(); - } - ], - [ - 'pattern' => [ - '(account)/blueprints', - 'users/(:any)/blueprints', - ], - 'method' => 'GET', - 'action' => function (string $id) { - return $this->user($id)->blueprints($this->requestQuery('section')); - } - ], - [ - 'pattern' => [ - '(account)/email', - 'users/(:any)/email', - ], - 'method' => 'PATCH', - 'action' => function (string $id) { - return $this->user($id)->changeEmail($this->requestBody('email')); - } - ], - [ - 'pattern' => [ - '(account)/language', - 'users/(:any)/language', - ], - 'method' => 'PATCH', - 'action' => function (string $id) { - return $this->user($id)->changeLanguage($this->requestBody('language')); - } - ], - [ - 'pattern' => [ - '(account)/name', - 'users/(:any)/name', - ], - 'method' => 'PATCH', - 'action' => function (string $id) { - return $this->user($id)->changeName($this->requestBody('name')); - } - ], - [ - 'pattern' => [ - '(account)/password', - 'users/(:any)/password', - ], - 'method' => 'PATCH', - 'action' => function (string $id) { - return $this->user($id)->changePassword($this->requestBody('password')); - } - ], - [ - 'pattern' => [ - '(account)/role', - 'users/(:any)/role', - ], - 'method' => 'PATCH', - 'action' => function (string $id) { - return $this->user($id)->changeRole($this->requestBody('role')); - } - ], - [ - 'pattern' => [ - '(account)/roles', - 'users/(:any)/roles', - ], - 'action' => function (string $id) { - return $this->user($id)->roles(); - } - ], - [ - 'pattern' => [ - '(account)/sections/(:any)', - 'users/(:any)/sections/(:any)', - ], - 'method' => 'GET', - 'action' => function (string $id, string $sectionName) { - if ($section = $this->user($id)->blueprint()->section($sectionName)) { - return $section->toResponse(); - } - } - ], - [ - 'pattern' => [ - '(account)/fields/(:any)/(:all?)', - 'users/(:any)/fields/(:any)/(:all?)', - ], - 'method' => 'ALL', - 'action' => function (string $id, string $fieldName, string $path = null) { - return $this->fieldApi($this->user($id), $fieldName, $path); - } - ], + return $this->upload(function ($source, $filename) use ($id) { + return $this->user($id)->createFile([ + 'filename' => 'profile.' . F::extension($filename), + 'template' => 'avatar', + 'source' => $source + ]); + }, $single = true); + } + ], + // @codeCoverageIgnoreEnd + [ + 'pattern' => [ + '(account)/avatar', + 'users/(:any)/avatar', + ], + 'method' => 'DELETE', + 'action' => function (string $id) { + return $this->user($id)->avatar()->delete(); + } + ], + [ + 'pattern' => [ + '(account)/blueprint', + 'users/(:any)/blueprint', + ], + 'method' => 'GET', + 'action' => function (string $id) { + return $this->user($id)->blueprint(); + } + ], + [ + 'pattern' => [ + '(account)/blueprints', + 'users/(:any)/blueprints', + ], + 'method' => 'GET', + 'action' => function (string $id) { + return $this->user($id)->blueprints($this->requestQuery('section')); + } + ], + [ + 'pattern' => [ + '(account)/email', + 'users/(:any)/email', + ], + 'method' => 'PATCH', + 'action' => function (string $id) { + return $this->user($id)->changeEmail($this->requestBody('email')); + } + ], + [ + 'pattern' => [ + '(account)/language', + 'users/(:any)/language', + ], + 'method' => 'PATCH', + 'action' => function (string $id) { + return $this->user($id)->changeLanguage($this->requestBody('language')); + } + ], + [ + 'pattern' => [ + '(account)/name', + 'users/(:any)/name', + ], + 'method' => 'PATCH', + 'action' => function (string $id) { + return $this->user($id)->changeName($this->requestBody('name')); + } + ], + [ + 'pattern' => [ + '(account)/password', + 'users/(:any)/password', + ], + 'method' => 'PATCH', + 'action' => function (string $id) { + return $this->user($id)->changePassword($this->requestBody('password')); + } + ], + [ + 'pattern' => [ + '(account)/role', + 'users/(:any)/role', + ], + 'method' => 'PATCH', + 'action' => function (string $id) { + return $this->user($id)->changeRole($this->requestBody('role')); + } + ], + [ + 'pattern' => [ + '(account)/roles', + 'users/(:any)/roles', + ], + 'action' => function (string $id) { + return $this->user($id)->roles(); + } + ], + [ + 'pattern' => [ + '(account)/sections/(:any)', + 'users/(:any)/sections/(:any)', + ], + 'method' => 'GET', + 'action' => function (string $id, string $sectionName) { + if ($section = $this->user($id)->blueprint()->section($sectionName)) { + return $section->toResponse(); + } + } + ], + [ + 'pattern' => [ + '(account)/fields/(:any)/(:all?)', + 'users/(:any)/fields/(:any)/(:all?)', + ], + 'method' => 'ALL', + 'action' => function (string $id, string $fieldName, string $path = null) { + return $this->fieldApi($this->user($id), $fieldName, $path); + } + ], ]; diff --git a/kirby/config/areas/account.php b/kirby/config/areas/account.php index 304aca2..738a839 100755 --- a/kirby/config/areas/account.php +++ b/kirby/config/areas/account.php @@ -3,12 +3,12 @@ use Kirby\Toolkit\I18n; return function () { - return [ - 'icon' => 'account', - 'label' => I18n::translate('view.account'), - 'search' => 'users', - 'dialogs' => require __DIR__ . '/account/dialogs.php', - 'dropdowns' => require __DIR__ . '/account/dropdowns.php', - 'views' => require __DIR__ . '/account/views.php' - ]; + return [ + 'icon' => 'account', + 'label' => I18n::translate('view.account'), + 'search' => 'users', + 'dialogs' => require __DIR__ . '/account/dialogs.php', + 'dropdowns' => require __DIR__ . '/account/dropdowns.php', + 'views' => require __DIR__ . '/account/views.php' + ]; }; diff --git a/kirby/config/areas/account/dialogs.php b/kirby/config/areas/account/dialogs.php index 15bf7b7..7c13062 100755 --- a/kirby/config/areas/account/dialogs.php +++ b/kirby/config/areas/account/dialogs.php @@ -4,67 +4,67 @@ $dialogs = require __DIR__ . '/../users/dialogs.php'; return [ - // change email - 'account.changeEmail' => [ - 'pattern' => '(account)/changeEmail', - 'load' => $dialogs['user.changeEmail']['load'], - 'submit' => $dialogs['user.changeEmail']['submit'], - ], + // change email + 'account.changeEmail' => [ + 'pattern' => '(account)/changeEmail', + 'load' => $dialogs['user.changeEmail']['load'], + 'submit' => $dialogs['user.changeEmail']['submit'], + ], - // change language - 'account.changeLanguage' => [ - 'pattern' => '(account)/changeLanguage', - 'load' => $dialogs['user.changeLanguage']['load'], - 'submit' => $dialogs['user.changeLanguage']['submit'], - ], + // change language + 'account.changeLanguage' => [ + 'pattern' => '(account)/changeLanguage', + 'load' => $dialogs['user.changeLanguage']['load'], + 'submit' => $dialogs['user.changeLanguage']['submit'], + ], - // change name - 'account.changeName' => [ - 'pattern' => '(account)/changeName', - 'load' => $dialogs['user.changeName']['load'], - 'submit' => $dialogs['user.changeName']['submit'], - ], + // change name + 'account.changeName' => [ + 'pattern' => '(account)/changeName', + 'load' => $dialogs['user.changeName']['load'], + 'submit' => $dialogs['user.changeName']['submit'], + ], - // change password - 'account.changePassword' => [ - 'pattern' => '(account)/changePassword', - 'load' => $dialogs['user.changePassword']['load'], - 'submit' => $dialogs['user.changePassword']['submit'], - ], + // change password + 'account.changePassword' => [ + 'pattern' => '(account)/changePassword', + 'load' => $dialogs['user.changePassword']['load'], + 'submit' => $dialogs['user.changePassword']['submit'], + ], - // change role - 'account.changeRole' => [ - 'pattern' => '(account)/changeRole', - 'load' => $dialogs['user.changeRole']['load'], - 'submit' => $dialogs['user.changeRole']['submit'], - ], + // change role + 'account.changeRole' => [ + 'pattern' => '(account)/changeRole', + 'load' => $dialogs['user.changeRole']['load'], + 'submit' => $dialogs['user.changeRole']['submit'], + ], - // delete - 'account.delete' => [ - 'pattern' => '(account)/delete', - 'load' => $dialogs['user.delete']['load'], - 'submit' => $dialogs['user.delete']['submit'], - ], + // delete + 'account.delete' => [ + 'pattern' => '(account)/delete', + 'load' => $dialogs['user.delete']['load'], + 'submit' => $dialogs['user.delete']['submit'], + ], - // change file name - 'account.file.changeName' => [ - 'pattern' => '(account)/files/(:any)/changeName', - 'load' => $dialogs['user.file.changeName']['load'], - 'submit' => $dialogs['user.file.changeName']['submit'], - ], + // change file name + 'account.file.changeName' => [ + 'pattern' => '(account)/files/(:any)/changeName', + 'load' => $dialogs['user.file.changeName']['load'], + 'submit' => $dialogs['user.file.changeName']['submit'], + ], - // change file sort - 'account.file.changeSort' => [ - 'pattern' => '(account)/files/(:any)/changeSort', - 'load' => $dialogs['user.file.changeSort']['load'], - 'submit' => $dialogs['user.file.changeSort']['submit'], - ], + // change file sort + 'account.file.changeSort' => [ + 'pattern' => '(account)/files/(:any)/changeSort', + 'load' => $dialogs['user.file.changeSort']['load'], + 'submit' => $dialogs['user.file.changeSort']['submit'], + ], - // delete - 'account.file.delete' => [ - 'pattern' => '(account)/files/(:any)/delete', - 'load' => $dialogs['user.file.delete']['load'], - 'submit' => $dialogs['user.file.delete']['submit'], - ], + // delete + 'account.file.delete' => [ + 'pattern' => '(account)/files/(:any)/delete', + 'load' => $dialogs['user.file.delete']['load'], + 'submit' => $dialogs['user.file.delete']['submit'], + ], ]; diff --git a/kirby/config/areas/account/dropdowns.php b/kirby/config/areas/account/dropdowns.php index 9cf2bd2..d739971 100755 --- a/kirby/config/areas/account/dropdowns.php +++ b/kirby/config/areas/account/dropdowns.php @@ -3,12 +3,12 @@ $dropdowns = require __DIR__ . '/../users/dropdowns.php'; return [ - 'account' => [ - 'pattern' => '(account)', - 'options' => $dropdowns['user']['options'] - ], - 'account.file' => [ - 'pattern' => '(account)/files/(:any)', - 'options' => $dropdowns['user.file']['options'] - ], + 'account' => [ + 'pattern' => '(account)', + 'options' => $dropdowns['user']['options'] + ], + 'account.file' => [ + 'pattern' => '(account)/files/(:any)', + 'options' => $dropdowns['user.file']['options'] + ], ]; diff --git a/kirby/config/areas/account/views.php b/kirby/config/areas/account/views.php index e85ef77..1ecd469 100755 --- a/kirby/config/areas/account/views.php +++ b/kirby/config/areas/account/views.php @@ -5,31 +5,31 @@ use Kirby\Cms\Find; use Kirby\Panel\Panel; return [ - 'account' => [ - 'pattern' => 'account', - 'action' => fn () => [ - 'component' => 'k-account-view', - 'props' => App::instance()->user()->panel()->props(), - ], - ], - 'account.file' => [ - 'pattern' => 'account/files/(:any)', - 'action' => function (string $filename) { - return Find::file('account', $filename)->panel()->view(); - } - ], - 'account.logout' => [ - 'pattern' => 'logout', - 'auth' => false, - 'action' => function () { - if ($user = App::instance()->user()) { - $user->logout(); - } - Panel::go('login'); - }, - ], - 'account.password' => [ - 'pattern' => 'reset-password', - 'action' => fn () => ['component' => 'k-reset-password-view'] - ] + 'account' => [ + 'pattern' => 'account', + 'action' => fn () => [ + 'component' => 'k-account-view', + 'props' => App::instance()->user()->panel()->props(), + ], + ], + 'account.file' => [ + 'pattern' => 'account/files/(:any)', + 'action' => function (string $filename) { + return Find::file('account', $filename)->panel()->view(); + } + ], + 'account.logout' => [ + 'pattern' => 'logout', + 'auth' => false, + 'action' => function () { + if ($user = App::instance()->user()) { + $user->logout(); + } + Panel::go('login'); + }, + ], + 'account.password' => [ + 'pattern' => 'reset-password', + 'action' => fn () => ['component' => 'k-reset-password-view'] + ] ]; diff --git a/kirby/config/areas/files/dialogs.php b/kirby/config/areas/files/dialogs.php index 9a37449..44625eb 100755 --- a/kirby/config/areas/files/dialogs.php +++ b/kirby/config/areas/files/dialogs.php @@ -14,119 +14,119 @@ use Kirby\Toolkit\I18n; * the appropriate routes in the areas. */ return [ - 'changeName' => [ - 'load' => function (string $path, string $filename) { - $file = Find::file($path, $filename); - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => [ - 'name' => [ - 'label' => I18n::translate('name'), - 'type' => 'slug', - 'required' => true, - 'icon' => 'title', - 'allow' => '@._-', - 'after' => '.' . $file->extension(), - 'preselect' => true - ] - ], - 'submitButton' => I18n::translate('rename'), - 'value' => [ - 'name' => $file->name(), - ] - ] - ]; - }, - 'submit' => function (string $path, string $filename) { - $file = Find::file($path, $filename); - $renamed = $file->changeName($file->kirby()->request()->get('name')); - $oldUrl = $file->panel()->url(true); - $newUrl = $renamed->panel()->url(true); - $response = [ - 'event' => 'file.changeName', - 'dispatch' => [ - 'content/move' => [ - $oldUrl, - $newUrl - ] - ], - ]; + 'changeName' => [ + 'load' => function (string $path, string $filename) { + $file = Find::file($path, $filename); + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => [ + 'name' => [ + 'label' => I18n::translate('name'), + 'type' => 'slug', + 'required' => true, + 'icon' => 'title', + 'allow' => '@._-', + 'after' => '.' . $file->extension(), + 'preselect' => true + ] + ], + 'submitButton' => I18n::translate('rename'), + 'value' => [ + 'name' => $file->name(), + ] + ] + ]; + }, + 'submit' => function (string $path, string $filename) { + $file = Find::file($path, $filename); + $renamed = $file->changeName($file->kirby()->request()->get('name')); + $oldUrl = $file->panel()->url(true); + $newUrl = $renamed->panel()->url(true); + $response = [ + 'event' => 'file.changeName', + 'dispatch' => [ + 'content/move' => [ + $oldUrl, + $newUrl + ] + ], + ]; - // check for a necessary redirect after the filename has changed - if (Panel::referrer() === $oldUrl && $oldUrl !== $newUrl) { - $response['redirect'] = $newUrl; - } + // check for a necessary redirect after the filename has changed + if (Panel::referrer() === $oldUrl && $oldUrl !== $newUrl) { + $response['redirect'] = $newUrl; + } - return $response; - } - ], + return $response; + } + ], - 'changeSort' => [ - 'load' => function (string $path, string $filename) { - $file = Find::file($path, $filename); - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => [ - 'position' => Field::filePosition($file) - ], - 'submitButton' => I18n::translate('change'), - 'value' => [ - 'position' => $file->sort()->isEmpty() ? $file->siblings(false)->count() + 1 : $file->sort()->toInt(), - ] - ] - ]; - }, - 'submit' => function (string $path, string $filename) { - $file = Find::file($path, $filename); - $files = $file->siblings()->sorted(); - $ids = $files->keys(); - $newIndex = (int)($file->kirby()->request()->get('position')) - 1; - $oldIndex = $files->indexOf($file); + 'changeSort' => [ + 'load' => function (string $path, string $filename) { + $file = Find::file($path, $filename); + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => [ + 'position' => Field::filePosition($file) + ], + 'submitButton' => I18n::translate('change'), + 'value' => [ + 'position' => $file->sort()->isEmpty() ? $file->siblings(false)->count() + 1 : $file->sort()->toInt(), + ] + ] + ]; + }, + 'submit' => function (string $path, string $filename) { + $file = Find::file($path, $filename); + $files = $file->siblings()->sorted(); + $ids = $files->keys(); + $newIndex = (int)($file->kirby()->request()->get('position')) - 1; + $oldIndex = $files->indexOf($file); - array_splice($ids, $oldIndex, 1); - array_splice($ids, $newIndex, 0, $file->id()); + array_splice($ids, $oldIndex, 1); + array_splice($ids, $newIndex, 0, $file->id()); - $files->changeSort($ids); + $files->changeSort($ids); - return [ - 'event' => 'file.sort', - ]; - } - ], + return [ + 'event' => 'file.sort', + ]; + } + ], - 'delete' => [ - 'load' => function (string $path, string $filename) { - $file = Find::file($path, $filename); - return [ - 'component' => 'k-remove-dialog', - 'props' => [ - 'text' => I18n::template('file.delete.confirm', [ - 'filename' => Escape::html($file->filename()) - ]), - ] - ]; - }, - 'submit' => function (string $path, string $filename) { - $file = Find::file($path, $filename); - $redirect = false; - $referrer = Panel::referrer(); - $url = $file->panel()->url(true); + 'delete' => [ + 'load' => function (string $path, string $filename) { + $file = Find::file($path, $filename); + return [ + 'component' => 'k-remove-dialog', + 'props' => [ + 'text' => I18n::template('file.delete.confirm', [ + 'filename' => Escape::html($file->filename()) + ]), + ] + ]; + }, + 'submit' => function (string $path, string $filename) { + $file = Find::file($path, $filename); + $redirect = false; + $referrer = Panel::referrer(); + $url = $file->panel()->url(true); - $file->delete(); + $file->delete(); - // redirect to the parent model URL - // if the dialog has been opened in the file view - if ($referrer === $url) { - $redirect = $file->parent()->panel()->url(true); - } + // redirect to the parent model URL + // if the dialog has been opened in the file view + if ($referrer === $url) { + $redirect = $file->parent()->panel()->url(true); + } - return [ - 'event' => 'file.delete', - 'dispatch' => ['content/remove' => [$url]], - 'redirect' => $redirect - ]; - } - ], + return [ + 'event' => 'file.delete', + 'dispatch' => ['content/remove' => [$url]], + 'redirect' => $redirect + ]; + } + ], ]; diff --git a/kirby/config/areas/files/dropdowns.php b/kirby/config/areas/files/dropdowns.php index d038294..8687a54 100755 --- a/kirby/config/areas/files/dropdowns.php +++ b/kirby/config/areas/files/dropdowns.php @@ -3,7 +3,7 @@ use Kirby\Cms\Find; return [ - 'file' => function (string $parent, string $filename) { - return Find::file($parent, $filename)->panel()->dropdown(); - } + 'file' => function (string $parent, string $filename) { + return Find::file($parent, $filename)->panel()->dropdown(); + } ]; diff --git a/kirby/config/areas/installation.php b/kirby/config/areas/installation.php index 1440b19..7f707cb 100755 --- a/kirby/config/areas/installation.php +++ b/kirby/config/areas/installation.php @@ -4,37 +4,37 @@ use Kirby\Panel\Panel; use Kirby\Toolkit\I18n; return function ($kirby) { - return [ - 'icon' => 'settings', - 'label' => I18n::translate('view.installation'), - 'views' => [ - 'installation' => [ - 'pattern' => 'installation', - 'auth' => false, - 'action' => function () use ($kirby) { - $system = $kirby->system(); - return [ - 'component' => 'k-installation-view', - 'props' => [ - 'isInstallable' => $system->isInstallable(), - 'isInstalled' => $system->isInstalled(), - 'isOk' => $system->isOk(), - 'requirements' => $system->status(), - 'translations' => $kirby->translations()->values(function ($translation) { - return [ - 'text' => $translation->name(), - 'value' => $translation->code(), - ]; - }), - ] - ]; - } - ], - 'installation.fallback' => [ - 'pattern' => '(:all)', - 'auth' => false, - 'action' => fn () => Panel::go('installation') - ] - ] - ]; + return [ + 'icon' => 'settings', + 'label' => I18n::translate('view.installation'), + 'views' => [ + 'installation' => [ + 'pattern' => 'installation', + 'auth' => false, + 'action' => function () use ($kirby) { + $system = $kirby->system(); + return [ + 'component' => 'k-installation-view', + 'props' => [ + 'isInstallable' => $system->isInstallable(), + 'isInstalled' => $system->isInstalled(), + 'isOk' => $system->isOk(), + 'requirements' => $system->status(), + 'translations' => $kirby->translations()->values(function ($translation) { + return [ + 'text' => $translation->name(), + 'value' => $translation->code(), + ]; + }), + ] + ]; + } + ], + 'installation.fallback' => [ + 'pattern' => '(:all)', + 'auth' => false, + 'action' => fn () => Panel::go('installation') + ] + ] + ]; }; diff --git a/kirby/config/areas/languages.php b/kirby/config/areas/languages.php index a454043..d464c58 100755 --- a/kirby/config/areas/languages.php +++ b/kirby/config/areas/languages.php @@ -3,11 +3,11 @@ use Kirby\Toolkit\I18n; return function ($kirby) { - return [ - 'icon' => 'globe', - 'label' => I18n::translate('view.languages'), - 'menu' => true, - 'dialogs' => require __DIR__ . '/languages/dialogs.php', - 'views' => require __DIR__ . '/languages/views.php' - ]; + return [ + 'icon' => 'globe', + 'label' => I18n::translate('view.languages'), + 'menu' => true, + 'dialogs' => require __DIR__ . '/languages/dialogs.php', + 'views' => require __DIR__ . '/languages/views.php' + ]; }; diff --git a/kirby/config/areas/languages/dialogs.php b/kirby/config/areas/languages/dialogs.php index ad927f7..a38b148 100755 --- a/kirby/config/areas/languages/dialogs.php +++ b/kirby/config/areas/languages/dialogs.php @@ -8,148 +8,148 @@ use Kirby\Toolkit\Escape; use Kirby\Toolkit\I18n; $languageDialogFields = [ - 'name' => [ - 'label' => I18n::translate('language.name'), - 'type' => 'text', - 'required' => true, - 'icon' => 'title' - ], - 'code' => [ - 'label' => I18n::translate('language.code'), - 'type' => 'text', - 'required' => true, - 'counter' => false, - 'icon' => 'globe', - 'width' => '1/2' - ], - 'direction' => [ - 'label' => I18n::translate('language.direction'), - 'type' => 'select', - 'required' => true, - 'empty' => false, - 'options' => [ - ['value' => 'ltr', 'text' => I18n::translate('language.direction.ltr')], - ['value' => 'rtl', 'text' => I18n::translate('language.direction.rtl')] - ], - 'width' => '1/2' - ], - 'locale' => [ - 'label' => I18n::translate('language.locale'), - 'type' => 'text', - ], + 'name' => [ + 'label' => I18n::translate('language.name'), + 'type' => 'text', + 'required' => true, + 'icon' => 'title' + ], + 'code' => [ + 'label' => I18n::translate('language.code'), + 'type' => 'text', + 'required' => true, + 'counter' => false, + 'icon' => 'globe', + 'width' => '1/2' + ], + 'direction' => [ + 'label' => I18n::translate('language.direction'), + 'type' => 'select', + 'required' => true, + 'empty' => false, + 'options' => [ + ['value' => 'ltr', 'text' => I18n::translate('language.direction.ltr')], + ['value' => 'rtl', 'text' => I18n::translate('language.direction.rtl')] + ], + 'width' => '1/2' + ], + 'locale' => [ + 'label' => I18n::translate('language.locale'), + 'type' => 'text', + ], ]; return [ - // create language - 'language.create' => [ - 'pattern' => 'languages/create', - 'load' => function () use ($languageDialogFields) { - return [ - 'component' => 'k-language-dialog', - 'props' => [ - 'fields' => $languageDialogFields, - 'submitButton' => I18n::translate('language.create'), - 'value' => [ - 'code' => '', - 'direction' => 'ltr', - 'locale' => '', - 'name' => '', - ] - ] - ]; - }, - 'submit' => function () { - $kirby = App::instance(); + // create language + 'language.create' => [ + 'pattern' => 'languages/create', + 'load' => function () use ($languageDialogFields) { + return [ + 'component' => 'k-language-dialog', + 'props' => [ + 'fields' => $languageDialogFields, + 'submitButton' => I18n::translate('language.create'), + 'value' => [ + 'code' => '', + 'direction' => 'ltr', + 'locale' => '', + 'name' => '', + ] + ] + ]; + }, + 'submit' => function () { + $kirby = App::instance(); - $data = $kirby->request()->get([ - 'code', - 'direction', - 'locale', - 'name' - ]); - $kirby->languages()->create($data); + $data = $kirby->request()->get([ + 'code', + 'direction', + 'locale', + 'name' + ]); + $kirby->languages()->create($data); - return [ - 'event' => 'language.create' - ]; - } - ], + return [ + 'event' => 'language.create' + ]; + } + ], - // delete language - 'language.delete' => [ - 'pattern' => 'languages/(:any)/delete', - 'load' => function (string $id) { - $language = Find::language($id); - return [ - 'component' => 'k-remove-dialog', - 'props' => [ - 'text' => I18n::template('language.delete.confirm', [ - 'name' => Escape::html($language->name()) - ]) - ] - ]; - }, - 'submit' => function (string $id) { - Find::language($id)->delete(); - return [ - 'event' => 'language.delete', - ]; - } - ], + // delete language + 'language.delete' => [ + 'pattern' => 'languages/(:any)/delete', + 'load' => function (string $id) { + $language = Find::language($id); + return [ + 'component' => 'k-remove-dialog', + 'props' => [ + 'text' => I18n::template('language.delete.confirm', [ + 'name' => Escape::html($language->name()) + ]) + ] + ]; + }, + 'submit' => function (string $id) { + Find::language($id)->delete(); + return [ + 'event' => 'language.delete', + ]; + } + ], - // update language - 'language.update' => [ - 'pattern' => 'languages/(:any)/update', - 'load' => function (string $id) use ($languageDialogFields) { - $language = Find::language($id); - $fields = $languageDialogFields; - $locale = $language->locale(); + // update language + 'language.update' => [ + 'pattern' => 'languages/(:any)/update', + 'load' => function (string $id) use ($languageDialogFields) { + $language = Find::language($id); + $fields = $languageDialogFields; + $locale = $language->locale(); - // use the first locale key if there's only one - if (count($locale) === 1) { - $locale = A::first($locale); - } + // use the first locale key if there's only one + if (count($locale) === 1) { + $locale = A::first($locale); + } - // the code of an existing language cannot be changed - $fields['code']['disabled'] = true; + // the code of an existing language cannot be changed + $fields['code']['disabled'] = true; - // if the locale settings is more complex than just a - // single string, the text field won't do it anymore. - // Changes can only be made in the language file and - // we display a warning box instead. - if (is_array($locale) === true) { - $fields['locale'] = [ - 'label' => $fields['locale']['label'], - 'type' => 'info', - 'text' => I18n::translate('language.locale.warning') - ]; - } + // if the locale settings is more complex than just a + // single string, the text field won't do it anymore. + // Changes can only be made in the language file and + // we display a warning box instead. + if (is_array($locale) === true) { + $fields['locale'] = [ + 'label' => $fields['locale']['label'], + 'type' => 'info', + 'text' => I18n::translate('language.locale.warning') + ]; + } - return [ - 'component' => 'k-language-dialog', - 'props' => [ - 'fields' => $fields, - 'submitButton' => I18n::translate('save'), - 'value' => [ - 'code' => $language->code(), - 'direction' => $language->direction(), - 'locale' => $locale, - 'name' => $language->name(), - 'rules' => $language->rules(), - ] - ] - ]; - }, - 'submit' => function (string $id) { - $kirby = App::instance(); + return [ + 'component' => 'k-language-dialog', + 'props' => [ + 'fields' => $fields, + 'submitButton' => I18n::translate('save'), + 'value' => [ + 'code' => $language->code(), + 'direction' => $language->direction(), + 'locale' => $locale, + 'name' => $language->name(), + 'rules' => $language->rules(), + ] + ] + ]; + }, + 'submit' => function (string $id) { + $kirby = App::instance(); - $data = $kirby->request()->get(['direction', 'locale', 'name']); - $language = Find::language($id)->update($data); + $data = $kirby->request()->get(['direction', 'locale', 'name']); + $language = Find::language($id)->update($data); - return [ - 'event' => 'language.update' - ]; - } - ], + return [ + 'event' => 'language.update' + ]; + } + ], ]; diff --git a/kirby/config/areas/languages/views.php b/kirby/config/areas/languages/views.php index d824ebf..0eee9da 100755 --- a/kirby/config/areas/languages/views.php +++ b/kirby/config/areas/languages/views.php @@ -4,22 +4,22 @@ use Kirby\Cms\App; use Kirby\Toolkit\Escape; return [ - 'languages' => [ - 'pattern' => 'languages', - 'action' => function () { - $kirby = App::instance(); + 'languages' => [ + 'pattern' => 'languages', + 'action' => function () { + $kirby = App::instance(); - return [ - 'component' => 'k-languages-view', - 'props' => [ - 'languages' => $kirby->languages()->values(fn ($language) => [ - 'default' => $language->isDefault(), - 'id' => $language->code(), - 'info' => Escape::html($language->code()), - 'text' => Escape::html($language->name()), - ]) - ] - ]; - } - ], + return [ + 'component' => 'k-languages-view', + 'props' => [ + 'languages' => $kirby->languages()->values(fn ($language) => [ + 'default' => $language->isDefault(), + 'id' => $language->code(), + 'info' => Escape::html($language->code()), + 'text' => Escape::html($language->name()), + ]) + ] + ]; + } + ], ]; diff --git a/kirby/config/areas/login.php b/kirby/config/areas/login.php index 590a7c4..56f30cb 100755 --- a/kirby/config/areas/login.php +++ b/kirby/config/areas/login.php @@ -4,41 +4,41 @@ use Kirby\Panel\Panel; use Kirby\Toolkit\I18n; return function ($kirby) { - return [ - 'icon' => 'user', - 'label' => I18n::translate('login'), - 'views' => [ - 'login' => [ - 'pattern' => 'login', - 'auth' => false, - 'action' => function () use ($kirby) { - $system = $kirby->system(); - $status = $kirby->auth()->status(); - return [ - 'component' => 'k-login-view', - 'props' => [ - 'methods' => array_keys($system->loginMethods()), - 'pending' => [ - 'email' => $status->email(), - 'challenge' => $status->challenge() - ] - ], - ]; - } - ], - 'login.fallback' => [ - 'pattern' => '(:all)', - 'auth' => false, - 'action' => function ($path) use ($kirby) { - /** - * Store the current path in the session - * Once the user is logged in, the path will - * be used to redirect to that view again - */ - $kirby->session()->set('panel.path', $path); - Panel::go('login'); - } - ] - ] - ]; + return [ + 'icon' => 'user', + 'label' => I18n::translate('login'), + 'views' => [ + 'login' => [ + 'pattern' => 'login', + 'auth' => false, + 'action' => function () use ($kirby) { + $system = $kirby->system(); + $status = $kirby->auth()->status(); + return [ + 'component' => 'k-login-view', + 'props' => [ + 'methods' => array_keys($system->loginMethods()), + 'pending' => [ + 'email' => $status->email(), + 'challenge' => $status->challenge() + ] + ], + ]; + } + ], + 'login.fallback' => [ + 'pattern' => '(:all)', + 'auth' => false, + 'action' => function ($path) use ($kirby) { + /** + * Store the current path in the session + * Once the user is logged in, the path will + * be used to redirect to that view again + */ + $kirby->session()->set('panel.path', $path); + Panel::go('login'); + } + ] + ] + ]; }; diff --git a/kirby/config/areas/site.php b/kirby/config/areas/site.php index a246f7e..3f082be 100755 --- a/kirby/config/areas/site.php +++ b/kirby/config/areas/site.php @@ -3,16 +3,16 @@ use Kirby\Toolkit\I18n; return function ($kirby) { - return [ - 'breadcrumbLabel' => function () use ($kirby) { - return $kirby->site()->title()->or(I18n::translate('view.site'))->toString(); - }, - 'icon' => 'home', - 'label' => $kirby->site()->blueprint()->title() ?? I18n::translate('view.site'), - 'menu' => true, - 'dialogs' => require __DIR__ . '/site/dialogs.php', - 'dropdowns' => require __DIR__ . '/site/dropdowns.php', - 'searches' => require __DIR__ . '/site/searches.php', - 'views' => require __DIR__ . '/site/views.php', - ]; + return [ + 'breadcrumbLabel' => function () use ($kirby) { + return $kirby->site()->title()->or(I18n::translate('view.site'))->toString(); + }, + 'icon' => 'home', + 'label' => $kirby->site()->blueprint()->title() ?? I18n::translate('view.site'), + 'menu' => true, + 'dialogs' => require __DIR__ . '/site/dialogs.php', + 'dropdowns' => require __DIR__ . '/site/dropdowns.php', + 'searches' => require __DIR__ . '/site/searches.php', + 'views' => require __DIR__ . '/site/views.php', + ]; }; diff --git a/kirby/config/areas/site/dialogs.php b/kirby/config/areas/site/dialogs.php index a8632b9..3101464 100755 --- a/kirby/config/areas/site/dialogs.php +++ b/kirby/config/areas/site/dialogs.php @@ -14,571 +14,571 @@ $files = require __DIR__ . '/../files/dialogs.php'; return [ - // change page position - 'page.changeSort' => [ - 'pattern' => 'pages/(:any)/changeSort', - 'load' => function (string $id) { - $page = Find::page($id); - - if ($page->blueprint()->num() !== 'default') { - throw new PermissionException([ - 'key' => 'page.sort.permission', - 'data' => [ - 'slug' => $page->slug() - ] - ]); - } - - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => [ - 'position' => Field::pagePosition($page), - ], - 'submitButton' => I18n::translate('change'), - 'value' => [ - 'position' => $page->panel()->position() - ] - ] - ]; - }, - 'submit' => function (string $id) { - $request = App::instance()->request(); - - Find::page($id)->changeStatus( - 'listed', - $request->get('position') - ); - - return [ - 'event' => 'page.sort', - ]; - } - ], - - // change page status - 'page.changeStatus' => [ - 'pattern' => 'pages/(:any)/changeStatus', - 'load' => function (string $id) { - $page = Find::page($id); - $blueprint = $page->blueprint(); - $status = $page->status(); - $states = []; - $position = null; - - foreach ($blueprint->status() as $key => $state) { - $states[] = [ - 'value' => $key, - 'text' => $state['label'], - 'info' => $state['text'], - ]; - } - - if ($status === 'draft') { - $errors = $page->errors(); - - // switch to the error dialog if there are - // errors and the draft cannot be published - if (count($errors) > 0) { - return [ - 'component' => 'k-error-dialog', - 'props' => [ - 'message' => I18n::translate('error.page.changeStatus.incomplete'), - 'details' => $errors, - ] - ]; - } - } - - $fields = [ - 'status' => [ - 'label' => I18n::translate('page.changeStatus.select'), - 'type' => 'radio', - 'required' => true, - 'options' => $states - ] - ]; - - if ($blueprint->num() === 'default') { - $fields['position'] = Field::pagePosition($page, [ - 'when' => [ - 'status' => 'listed' - ] - ]); - - $position = $page->panel()->position(); - } - - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => $fields, - 'submitButton' => I18n::translate('change'), - 'value' => [ - 'status' => $status, - 'position' => $position - ] - ] - ]; - }, - 'submit' => function (string $id) { - $request = App::instance()->request(); - - Find::page($id)->changeStatus( - $request->get('status'), - $request->get('position') - ); - - return [ - 'event' => 'page.changeStatus', - ]; - } - ], - - // change template - 'page.changeTemplate' => [ - 'pattern' => 'pages/(:any)/changeTemplate', - 'load' => function (string $id) { - $page = Find::page($id); - $blueprints = $page->blueprints(); - - if (count($blueprints) <= 1) { - throw new Exception([ - 'key' => 'page.changeTemplate.invalid', - 'data' => [ - 'slug' => $id - ] - ]); - } - - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => [ - 'template' => Field::template($blueprints, [ - 'required' => true - ]) - ], - 'submitButton' => I18n::translate('change'), - 'value' => [ - 'template' => $page->intendedTemplate()->name() - ] - ] - ]; - }, - 'submit' => function (string $id) { - $request = App::instance()->request(); - - Find::page($id)->changeTemplate($request->get('template')); - - return [ - 'event' => 'page.changeTemplate', - ]; - } - ], - - // change title - 'page.changeTitle' => [ - 'pattern' => 'pages/(:any)/changeTitle', - 'load' => function (string $id) { - $request = App::instance()->request(); - - $page = Find::page($id); - $permissions = $page->permissions(); - $select = $request->get('select', 'title'); - - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => [ - 'title' => Field::title([ - 'required' => true, - 'preselect' => $select === 'title', - 'disabled' => $permissions->can('changeTitle') === false - ]), - 'slug' => Field::slug([ - 'required' => true, - 'preselect' => $select === 'slug', - 'path' => $page->parent() ? '/' . $page->parent()->id() . '/' : '/', - 'disabled' => $permissions->can('changeSlug') === false, - 'wizard' => [ - 'text' => I18n::translate('page.changeSlug.fromTitle'), - 'field' => 'title' - ] - ]) - ], - 'autofocus' => false, - 'submitButton' => I18n::translate('change'), - 'value' => [ - 'title' => $page->title()->value(), - 'slug' => $page->slug(), - ] - ] - ]; - }, - 'submit' => function (string $id) { - $request = App::instance()->request(); - - $page = Find::page($id); - $title = trim($request->get('title', '')); - $slug = trim($request->get('slug', '')); - - // basic input validation before we move on - if (Str::length($title) === 0) { - throw new InvalidArgumentException([ - 'key' => 'page.changeTitle.empty' - ]); - } - - if (Str::length($slug) === 0) { - throw new InvalidArgumentException([ - 'key' => 'page.slug.invalid' - ]); - } - - // nothing changed - if ($page->title()->value() === $title && $page->slug() === $slug) { - return true; - } - - // prepare the response - $response = [ - 'event' => [] - ]; - - // the page title changed - if ($page->title()->value() !== $title) { - $page->changeTitle($title); - $response['event'][] = 'page.changeTitle'; - } - - // the slug changed - if ($page->slug() !== $slug) { - $newPage = $page->changeSlug($slug); - $response['event'][] = 'page.changeSlug'; - $response['dispatch'] = [ - 'content/move' => [ - $oldUrl = $page->panel()->url(true), - $newUrl = $newPage->panel()->url(true) - ] - ]; - - // check for a necessary redirect after the slug has changed - if (Panel::referrer() === $oldUrl && $oldUrl !== $newUrl) { - $response['redirect'] = $newUrl; - } - } - - return $response; - } - ], - - // create a new page - 'page.create' => [ - 'pattern' => 'pages/create', - 'load' => function () { - $kirby = App::instance(); - $request = $kirby->request(); - - // the parent model for the new page - $parent = $request->get('parent', 'site'); - - // the view on which the add button is located - // this is important to find the right section - // and provide the correct templates for the new page - $view = $request->get('view', $parent); - - // templates will be fetched depending on the - // section settings in the blueprint - $section = $request->get('section'); - - // this is the parent model - $model = Find::parent($parent); - - // this is the view model - // i.e. site if the add button is on - // the dashboard - $view = Find::parent($view); - - // available blueprints/templates for the new page - // are always loaded depending on the matching section - // in the view model blueprint - $blueprints = $view->blueprints($section); - - // the pre-selected template - $template = $blueprints[0]['name'] ?? $blueprints[0]['value'] ?? null; - - $fields = [ - 'parent' => Field::hidden(), - 'title' => Field::title([ - 'required' => true, - 'preselect' => true - ]), - 'slug' => Field::slug([ - 'required' => true, - 'sync' => 'title', - 'path' => empty($model->id()) === false ? '/' . $model->id() . '/' : '/' - ]), - 'template' => Field::hidden() - ]; - - // only show template field if > 1 templates available - // or when in debug mode - if (count($blueprints) > 1 || $kirby->option('debug') === true) { - $fields['template'] = Field::template($blueprints, [ - 'required' => true - ]); - } - - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => $fields, - 'submitButton' => I18n::translate('page.draft.create'), - 'value' => [ - 'parent' => $parent, - 'slug' => '', - 'template' => $template, - 'title' => '', - ] - ] - ]; - }, - 'submit' => function () { - $request = App::instance()->request(); - $title = trim($request->get('title', '')); - - if (Str::length($title) === 0) { - throw new InvalidArgumentException([ - 'key' => 'page.changeTitle.empty' - ]); - } - - $page = Find::parent($request->get('parent', 'site'))->createChild([ - 'content' => ['title' => $title], - 'slug' => $request->get('slug'), - 'template' => $request->get('template'), - ]); - - return [ - 'event' => 'page.create', - 'redirect' => $page->panel()->url(true) - ]; - } - ], - - // delete page - 'page.delete' => [ - 'pattern' => 'pages/(:any)/delete', - 'load' => function (string $id) { - $page = Find::page($id); - $text = I18n::template('page.delete.confirm', [ - 'title' => Escape::html($page->title()->value()) - ]); - - if ($page->childrenAndDrafts()->count() > 0) { - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => [ - 'info' => [ - 'type' => 'info', - 'theme' => 'negative', - 'text' => I18n::translate('page.delete.confirm.subpages') - ], - 'check' => [ - 'label' => I18n::translate('page.delete.confirm.title'), - 'type' => 'text', - 'counter' => false - ] - ], - 'size' => 'medium', - 'submitButton' => I18n::translate('delete'), - 'text' => $text, - 'theme' => 'negative', - ] - ]; - } - - return [ - 'component' => 'k-remove-dialog', - 'props' => [ - 'text' => $text - ] - ]; - }, - 'submit' => function (string $id) { - $request = App::instance()->request(); - - $page = Find::page($id); - $redirect = false; - $referrer = Panel::referrer(); - $url = $page->panel()->url(true); - - if ( - $page->childrenAndDrafts()->count() > 0 && - $request->get('check') !== $page->title()->value() - ) { - throw new InvalidArgumentException(['key' => 'page.delete.confirm']); - } - - $page->delete(true); - - // redirect to the parent model URL - // if the dialog has been opened in the page view - if ($referrer === $url) { - $redirect = $page->parentModel()->panel()->url(true); - } - - return [ - 'event' => 'page.delete', - 'dispatch' => ['content/remove' => [$url]], - 'redirect' => $redirect - ]; - } - ], - - // duplicate page - 'page.duplicate' => [ - 'pattern' => 'pages/(:any)/duplicate', - 'load' => function (string $id) { - $page = Find::page($id); - $hasChildren = $page->hasChildren(); - $hasFiles = $page->hasFiles(); - $toggleWidth = '1/' . count(array_filter([$hasChildren, $hasFiles])); - - $fields = [ - 'title' => Field::title([ - 'required' => true - ]), - 'slug' => Field::slug([ - 'required' => true, - 'path' => $page->parent() ? '/' . $page->parent()->id() . '/' : '/', - 'wizard' => [ - 'text' => I18n::translate('page.changeSlug.fromTitle'), - 'field' => 'title' - ] - ]) - ]; - - if ($hasFiles === true) { - $fields['files'] = [ - 'label' => I18n::translate('page.duplicate.files'), - 'type' => 'toggle', - 'required' => true, - 'width' => $toggleWidth - ]; - } - - if ($hasChildren === true) { - $fields['children'] = [ - 'label' => I18n::translate('page.duplicate.pages'), - 'type' => 'toggle', - 'required' => true, - 'width' => $toggleWidth - ]; - } - - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => $fields, - 'submitButton' => I18n::translate('duplicate'), - 'value' => [ - 'children' => false, - 'files' => false, - 'slug' => $page->slug() . '-' . Str::slug(I18n::translate('page.duplicate.appendix')), - 'title' => $page->title() . ' ' . I18n::translate('page.duplicate.appendix') - ] - ] - ]; - }, - 'submit' => function (string $id) { - $request = App::instance()->request(); - - $newPage = Find::page($id)->duplicate($request->get('slug'), [ - 'children' => (bool)$request->get('children'), - 'files' => (bool)$request->get('files'), - 'title' => (string)$request->get('title'), - ]); - - return [ - 'event' => 'page.duplicate', - 'redirect' => $newPage->panel()->url(true) - ]; - } - ], - - // change filename - 'page.file.changeName' => [ - 'pattern' => '(pages/.*?)/files/(:any)/changeName', - 'load' => $files['changeName']['load'], - 'submit' => $files['changeName']['submit'], - ], - - // change sort - 'page.file.changeSort' => [ - 'pattern' => '(pages/.*?)/files/(:any)/changeSort', - 'load' => $files['changeSort']['load'], - 'submit' => $files['changeSort']['submit'], - ], - - // delete - 'page.file.delete' => [ - 'pattern' => '(pages/.*?)/files/(:any)/delete', - 'load' => $files['delete']['load'], - 'submit' => $files['delete']['submit'], - ], - - // change site title - 'site.changeTitle' => [ - 'pattern' => 'site/changeTitle', - 'load' => function () { - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => [ - 'title' => Field::title([ - 'required' => true, - 'preselect' => true - ]) - ], - 'submitButton' => I18n::translate('rename'), - 'value' => [ - 'title' => App::instance()->site()->title()->value() - ] - ] - ]; - }, - 'submit' => function () { - $kirby = App::instance(); - - $kirby->site()->changeTitle($kirby->request()->get('title')); - return [ - 'event' => 'site.changeTitle', - ]; - } - ], - - // change filename - 'site.file.changeName' => [ - 'pattern' => '(site)/files/(:any)/changeName', - 'load' => $files['changeName']['load'], - 'submit' => $files['changeName']['submit'], - ], - - // change sort - 'site.file.changeSort' => [ - 'pattern' => '(site)/files/(:any)/changeSort', - 'load' => $files['changeSort']['load'], - 'submit' => $files['changeSort']['submit'], - ], - - // delete - 'site.file.delete' => [ - 'pattern' => '(site)/files/(:any)/delete', - 'load' => $files['delete']['load'], - 'submit' => $files['delete']['submit'], - ], + // change page position + 'page.changeSort' => [ + 'pattern' => 'pages/(:any)/changeSort', + 'load' => function (string $id) { + $page = Find::page($id); + + if ($page->blueprint()->num() !== 'default') { + throw new PermissionException([ + 'key' => 'page.sort.permission', + 'data' => [ + 'slug' => $page->slug() + ] + ]); + } + + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => [ + 'position' => Field::pagePosition($page), + ], + 'submitButton' => I18n::translate('change'), + 'value' => [ + 'position' => $page->panel()->position() + ] + ] + ]; + }, + 'submit' => function (string $id) { + $request = App::instance()->request(); + + Find::page($id)->changeStatus( + 'listed', + $request->get('position') + ); + + return [ + 'event' => 'page.sort', + ]; + } + ], + + // change page status + 'page.changeStatus' => [ + 'pattern' => 'pages/(:any)/changeStatus', + 'load' => function (string $id) { + $page = Find::page($id); + $blueprint = $page->blueprint(); + $status = $page->status(); + $states = []; + $position = null; + + foreach ($blueprint->status() as $key => $state) { + $states[] = [ + 'value' => $key, + 'text' => $state['label'], + 'info' => $state['text'], + ]; + } + + if ($status === 'draft') { + $errors = $page->errors(); + + // switch to the error dialog if there are + // errors and the draft cannot be published + if (count($errors) > 0) { + return [ + 'component' => 'k-error-dialog', + 'props' => [ + 'message' => I18n::translate('error.page.changeStatus.incomplete'), + 'details' => $errors, + ] + ]; + } + } + + $fields = [ + 'status' => [ + 'label' => I18n::translate('page.changeStatus.select'), + 'type' => 'radio', + 'required' => true, + 'options' => $states + ] + ]; + + if ($blueprint->num() === 'default') { + $fields['position'] = Field::pagePosition($page, [ + 'when' => [ + 'status' => 'listed' + ] + ]); + + $position = $page->panel()->position(); + } + + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => $fields, + 'submitButton' => I18n::translate('change'), + 'value' => [ + 'status' => $status, + 'position' => $position + ] + ] + ]; + }, + 'submit' => function (string $id) { + $request = App::instance()->request(); + + Find::page($id)->changeStatus( + $request->get('status'), + $request->get('position') + ); + + return [ + 'event' => 'page.changeStatus', + ]; + } + ], + + // change template + 'page.changeTemplate' => [ + 'pattern' => 'pages/(:any)/changeTemplate', + 'load' => function (string $id) { + $page = Find::page($id); + $blueprints = $page->blueprints(); + + if (count($blueprints) <= 1) { + throw new Exception([ + 'key' => 'page.changeTemplate.invalid', + 'data' => [ + 'slug' => $id + ] + ]); + } + + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => [ + 'template' => Field::template($blueprints, [ + 'required' => true + ]) + ], + 'submitButton' => I18n::translate('change'), + 'value' => [ + 'template' => $page->intendedTemplate()->name() + ] + ] + ]; + }, + 'submit' => function (string $id) { + $request = App::instance()->request(); + + Find::page($id)->changeTemplate($request->get('template')); + + return [ + 'event' => 'page.changeTemplate', + ]; + } + ], + + // change title + 'page.changeTitle' => [ + 'pattern' => 'pages/(:any)/changeTitle', + 'load' => function (string $id) { + $request = App::instance()->request(); + + $page = Find::page($id); + $permissions = $page->permissions(); + $select = $request->get('select', 'title'); + + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => [ + 'title' => Field::title([ + 'required' => true, + 'preselect' => $select === 'title', + 'disabled' => $permissions->can('changeTitle') === false + ]), + 'slug' => Field::slug([ + 'required' => true, + 'preselect' => $select === 'slug', + 'path' => $page->parent() ? '/' . $page->parent()->id() . '/' : '/', + 'disabled' => $permissions->can('changeSlug') === false, + 'wizard' => [ + 'text' => I18n::translate('page.changeSlug.fromTitle'), + 'field' => 'title' + ] + ]) + ], + 'autofocus' => false, + 'submitButton' => I18n::translate('change'), + 'value' => [ + 'title' => $page->title()->value(), + 'slug' => $page->slug(), + ] + ] + ]; + }, + 'submit' => function (string $id) { + $request = App::instance()->request(); + + $page = Find::page($id); + $title = trim($request->get('title', '')); + $slug = trim($request->get('slug', '')); + + // basic input validation before we move on + if (Str::length($title) === 0) { + throw new InvalidArgumentException([ + 'key' => 'page.changeTitle.empty' + ]); + } + + if (Str::length($slug) === 0) { + throw new InvalidArgumentException([ + 'key' => 'page.slug.invalid' + ]); + } + + // nothing changed + if ($page->title()->value() === $title && $page->slug() === $slug) { + return true; + } + + // prepare the response + $response = [ + 'event' => [] + ]; + + // the page title changed + if ($page->title()->value() !== $title) { + $page->changeTitle($title); + $response['event'][] = 'page.changeTitle'; + } + + // the slug changed + if ($page->slug() !== $slug) { + $newPage = $page->changeSlug($slug); + $response['event'][] = 'page.changeSlug'; + $response['dispatch'] = [ + 'content/move' => [ + $oldUrl = $page->panel()->url(true), + $newUrl = $newPage->panel()->url(true) + ] + ]; + + // check for a necessary redirect after the slug has changed + if (Panel::referrer() === $oldUrl && $oldUrl !== $newUrl) { + $response['redirect'] = $newUrl; + } + } + + return $response; + } + ], + + // create a new page + 'page.create' => [ + 'pattern' => 'pages/create', + 'load' => function () { + $kirby = App::instance(); + $request = $kirby->request(); + + // the parent model for the new page + $parent = $request->get('parent', 'site'); + + // the view on which the add button is located + // this is important to find the right section + // and provide the correct templates for the new page + $view = $request->get('view', $parent); + + // templates will be fetched depending on the + // section settings in the blueprint + $section = $request->get('section'); + + // this is the parent model + $model = Find::parent($parent); + + // this is the view model + // i.e. site if the add button is on + // the dashboard + $view = Find::parent($view); + + // available blueprints/templates for the new page + // are always loaded depending on the matching section + // in the view model blueprint + $blueprints = $view->blueprints($section); + + // the pre-selected template + $template = $blueprints[0]['name'] ?? $blueprints[0]['value'] ?? null; + + $fields = [ + 'parent' => Field::hidden(), + 'title' => Field::title([ + 'required' => true, + 'preselect' => true + ]), + 'slug' => Field::slug([ + 'required' => true, + 'sync' => 'title', + 'path' => empty($model->id()) === false ? '/' . $model->id() . '/' : '/' + ]), + 'template' => Field::hidden() + ]; + + // only show template field if > 1 templates available + // or when in debug mode + if (count($blueprints) > 1 || $kirby->option('debug') === true) { + $fields['template'] = Field::template($blueprints, [ + 'required' => true + ]); + } + + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => $fields, + 'submitButton' => I18n::translate('page.draft.create'), + 'value' => [ + 'parent' => $parent, + 'slug' => '', + 'template' => $template, + 'title' => '', + ] + ] + ]; + }, + 'submit' => function () { + $request = App::instance()->request(); + $title = trim($request->get('title', '')); + + if (Str::length($title) === 0) { + throw new InvalidArgumentException([ + 'key' => 'page.changeTitle.empty' + ]); + } + + $page = Find::parent($request->get('parent', 'site'))->createChild([ + 'content' => ['title' => $title], + 'slug' => $request->get('slug'), + 'template' => $request->get('template'), + ]); + + return [ + 'event' => 'page.create', + 'redirect' => $page->panel()->url(true) + ]; + } + ], + + // delete page + 'page.delete' => [ + 'pattern' => 'pages/(:any)/delete', + 'load' => function (string $id) { + $page = Find::page($id); + $text = I18n::template('page.delete.confirm', [ + 'title' => Escape::html($page->title()->value()) + ]); + + if ($page->childrenAndDrafts()->count() > 0) { + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => [ + 'info' => [ + 'type' => 'info', + 'theme' => 'negative', + 'text' => I18n::translate('page.delete.confirm.subpages') + ], + 'check' => [ + 'label' => I18n::translate('page.delete.confirm.title'), + 'type' => 'text', + 'counter' => false + ] + ], + 'size' => 'medium', + 'submitButton' => I18n::translate('delete'), + 'text' => $text, + 'theme' => 'negative', + ] + ]; + } + + return [ + 'component' => 'k-remove-dialog', + 'props' => [ + 'text' => $text + ] + ]; + }, + 'submit' => function (string $id) { + $request = App::instance()->request(); + + $page = Find::page($id); + $redirect = false; + $referrer = Panel::referrer(); + $url = $page->panel()->url(true); + + if ( + $page->childrenAndDrafts()->count() > 0 && + $request->get('check') !== $page->title()->value() + ) { + throw new InvalidArgumentException(['key' => 'page.delete.confirm']); + } + + $page->delete(true); + + // redirect to the parent model URL + // if the dialog has been opened in the page view + if ($referrer === $url) { + $redirect = $page->parentModel()->panel()->url(true); + } + + return [ + 'event' => 'page.delete', + 'dispatch' => ['content/remove' => [$url]], + 'redirect' => $redirect + ]; + } + ], + + // duplicate page + 'page.duplicate' => [ + 'pattern' => 'pages/(:any)/duplicate', + 'load' => function (string $id) { + $page = Find::page($id); + $hasChildren = $page->hasChildren(); + $hasFiles = $page->hasFiles(); + $toggleWidth = '1/' . count(array_filter([$hasChildren, $hasFiles])); + + $fields = [ + 'title' => Field::title([ + 'required' => true + ]), + 'slug' => Field::slug([ + 'required' => true, + 'path' => $page->parent() ? '/' . $page->parent()->id() . '/' : '/', + 'wizard' => [ + 'text' => I18n::translate('page.changeSlug.fromTitle'), + 'field' => 'title' + ] + ]) + ]; + + if ($hasFiles === true) { + $fields['files'] = [ + 'label' => I18n::translate('page.duplicate.files'), + 'type' => 'toggle', + 'required' => true, + 'width' => $toggleWidth + ]; + } + + if ($hasChildren === true) { + $fields['children'] = [ + 'label' => I18n::translate('page.duplicate.pages'), + 'type' => 'toggle', + 'required' => true, + 'width' => $toggleWidth + ]; + } + + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => $fields, + 'submitButton' => I18n::translate('duplicate'), + 'value' => [ + 'children' => false, + 'files' => false, + 'slug' => $page->slug() . '-' . Str::slug(I18n::translate('page.duplicate.appendix')), + 'title' => $page->title() . ' ' . I18n::translate('page.duplicate.appendix') + ] + ] + ]; + }, + 'submit' => function (string $id) { + $request = App::instance()->request(); + + $newPage = Find::page($id)->duplicate($request->get('slug'), [ + 'children' => (bool)$request->get('children'), + 'files' => (bool)$request->get('files'), + 'title' => (string)$request->get('title'), + ]); + + return [ + 'event' => 'page.duplicate', + 'redirect' => $newPage->panel()->url(true) + ]; + } + ], + + // change filename + 'page.file.changeName' => [ + 'pattern' => '(pages/.*?)/files/(:any)/changeName', + 'load' => $files['changeName']['load'], + 'submit' => $files['changeName']['submit'], + ], + + // change sort + 'page.file.changeSort' => [ + 'pattern' => '(pages/.*?)/files/(:any)/changeSort', + 'load' => $files['changeSort']['load'], + 'submit' => $files['changeSort']['submit'], + ], + + // delete + 'page.file.delete' => [ + 'pattern' => '(pages/.*?)/files/(:any)/delete', + 'load' => $files['delete']['load'], + 'submit' => $files['delete']['submit'], + ], + + // change site title + 'site.changeTitle' => [ + 'pattern' => 'site/changeTitle', + 'load' => function () { + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => [ + 'title' => Field::title([ + 'required' => true, + 'preselect' => true + ]) + ], + 'submitButton' => I18n::translate('rename'), + 'value' => [ + 'title' => App::instance()->site()->title()->value() + ] + ] + ]; + }, + 'submit' => function () { + $kirby = App::instance(); + + $kirby->site()->changeTitle($kirby->request()->get('title')); + return [ + 'event' => 'site.changeTitle', + ]; + } + ], + + // change filename + 'site.file.changeName' => [ + 'pattern' => '(site)/files/(:any)/changeName', + 'load' => $files['changeName']['load'], + 'submit' => $files['changeName']['submit'], + ], + + // change sort + 'site.file.changeSort' => [ + 'pattern' => '(site)/files/(:any)/changeSort', + 'load' => $files['changeSort']['load'], + 'submit' => $files['changeSort']['submit'], + ], + + // delete + 'site.file.delete' => [ + 'pattern' => '(site)/files/(:any)/delete', + 'load' => $files['delete']['load'], + 'submit' => $files['delete']['submit'], + ], ]; diff --git a/kirby/config/areas/site/dropdowns.php b/kirby/config/areas/site/dropdowns.php index c498c00..c08853b 100755 --- a/kirby/config/areas/site/dropdowns.php +++ b/kirby/config/areas/site/dropdowns.php @@ -5,22 +5,22 @@ use Kirby\Panel\Dropdown; $files = require __DIR__ . '/../files/dropdowns.php'; return [ - 'changes' => [ - 'pattern' => 'changes', - 'options' => fn () => Dropdown::changes() - ], - 'page' => [ - 'pattern' => 'pages/(:any)', - 'options' => function (string $path) { - return Find::page($path)->panel()->dropdown(); - } - ], - 'page.file' => [ - 'pattern' => '(pages/.*?)/files/(:any)', - 'options' => $files['file'] - ], - 'site.file' => [ - 'pattern' => '(site)/files/(:any)', - 'options' => $files['file'] - ] + 'changes' => [ + 'pattern' => 'changes', + 'options' => fn () => Dropdown::changes() + ], + 'page' => [ + 'pattern' => 'pages/(:any)', + 'options' => function (string $path) { + return Find::page($path)->panel()->dropdown(); + } + ], + 'page.file' => [ + 'pattern' => '(pages/.*?)/files/(:any)', + 'options' => $files['file'] + ], + 'site.file' => [ + 'pattern' => '(site)/files/(:any)', + 'options' => $files['file'] + ] ]; diff --git a/kirby/config/areas/site/searches.php b/kirby/config/areas/site/searches.php index 0bdfd26..6719bb2 100755 --- a/kirby/config/areas/site/searches.php +++ b/kirby/config/areas/site/searches.php @@ -5,53 +5,53 @@ use Kirby\Toolkit\Escape; use Kirby\Toolkit\I18n; return [ - 'pages' => [ - 'label' => I18n::translate('pages'), - 'icon' => 'page', - 'query' => function (string $query = null) { - $pages = App::instance()->site() - ->index(true) - ->search($query) - ->filter('isReadable', true) - ->limit(10); + 'pages' => [ + 'label' => I18n::translate('pages'), + 'icon' => 'page', + 'query' => function (string $query = null) { + $pages = App::instance()->site() + ->index(true) + ->search($query) + ->filter('isReadable', true) + ->limit(10); - $results = []; + $results = []; - foreach ($pages as $page) { - $results[] = [ - 'image' => $page->panel()->image(), - 'text' => Escape::html($page->title()->value()), - 'link' => $page->panel()->url(true), - 'info' => Escape::html($page->id()) - ]; - } + foreach ($pages as $page) { + $results[] = [ + 'image' => $page->panel()->image(), + 'text' => Escape::html($page->title()->value()), + 'link' => $page->panel()->url(true), + 'info' => Escape::html($page->id()) + ]; + } - return $results; - } - ], - 'files' => [ - 'label' => I18n::translate('files'), - 'icon' => 'image', - 'query' => function (string $query = null) { - $files = App::instance()->site() - ->index(true) - ->filter('isReadable', true) - ->files() - ->search($query) - ->limit(10); + return $results; + } + ], + 'files' => [ + 'label' => I18n::translate('files'), + 'icon' => 'image', + 'query' => function (string $query = null) { + $files = App::instance()->site() + ->index(true) + ->filter('isReadable', true) + ->files() + ->search($query) + ->limit(10); - $results = []; + $results = []; - foreach ($files as $file) { - $results[] = [ - 'image' => $file->panel()->image(), - 'text' => Escape::html($file->filename()), - 'link' => $file->panel()->url(true), - 'info' => Escape::html($file->id()) - ]; - } + foreach ($files as $file) { + $results[] = [ + 'image' => $file->panel()->image(), + 'text' => Escape::html($file->filename()), + 'link' => $file->panel()->url(true), + 'info' => Escape::html($file->id()) + ]; + } - return $results; - } - ] + return $results; + } + ] ]; diff --git a/kirby/config/areas/site/views.php b/kirby/config/areas/site/views.php index d0fcf85..7465d2e 100755 --- a/kirby/config/areas/site/views.php +++ b/kirby/config/areas/site/views.php @@ -4,24 +4,24 @@ use Kirby\Cms\App; use Kirby\Cms\Find; return [ - 'page' => [ - 'pattern' => 'pages/(:any)', - 'action' => fn (string $path) => Find::page($path)->panel()->view() - ], - 'page.file' => [ - 'pattern' => 'pages/(:any)/files/(:any)', - 'action' => function (string $id, string $filename) { - return Find::file('pages/' . $id, $filename)->panel()->view(); - } - ], - 'site' => [ - 'pattern' => 'site', - 'action' => fn () => App::instance()->site()->panel()->view() - ], - 'site.file' => [ - 'pattern' => 'site/files/(:any)', - 'action' => function (string $filename) { - return Find::file('site', $filename)->panel()->view(); - } - ], + 'page' => [ + 'pattern' => 'pages/(:any)', + 'action' => fn (string $path) => Find::page($path)->panel()->view() + ], + 'page.file' => [ + 'pattern' => 'pages/(:any)/files/(:any)', + 'action' => function (string $id, string $filename) { + return Find::file('pages/' . $id, $filename)->panel()->view(); + } + ], + 'site' => [ + 'pattern' => 'site', + 'action' => fn () => App::instance()->site()->panel()->view() + ], + 'site.file' => [ + 'pattern' => 'site/files/(:any)', + 'action' => function (string $filename) { + return Find::file('site', $filename)->panel()->view(); + } + ], ]; diff --git a/kirby/config/areas/system.php b/kirby/config/areas/system.php index 8fed5b2..9f3075a 100755 --- a/kirby/config/areas/system.php +++ b/kirby/config/areas/system.php @@ -3,11 +3,11 @@ use Kirby\Toolkit\I18n; return function ($kirby) { - return [ - 'icon' => 'settings', - 'label' => I18n::translate('view.system'), - 'menu' => true, - 'dialogs' => require __DIR__ . '/system/dialogs.php', - 'views' => require __DIR__ . '/system/views.php' - ]; + return [ + 'icon' => 'settings', + 'label' => I18n::translate('view.system'), + 'menu' => true, + 'dialogs' => require __DIR__ . '/system/dialogs.php', + 'views' => require __DIR__ . '/system/views.php' + ]; }; diff --git a/kirby/config/areas/system/dialogs.php b/kirby/config/areas/system/dialogs.php index 7cefd18..35a3f9a 100755 --- a/kirby/config/areas/system/dialogs.php +++ b/kirby/config/areas/system/dialogs.php @@ -5,82 +5,82 @@ use Kirby\Panel\Field; use Kirby\Toolkit\I18n; return [ - // license key - 'license' => [ - 'load' => function () { - $license = App::instance()->system()->license(); + // license key + 'license' => [ + 'load' => function () { + $license = App::instance()->system()->license(); - // @codeCoverageIgnoreStart - // the system is registered but the license - // key is only visible for admins - if ($license === true) { - $license = 'Kirby 3'; - } - // @codeCoverageIgnoreEnd + // @codeCoverageIgnoreStart + // the system is registered but the license + // key is only visible for admins + if ($license === true) { + $license = 'Kirby 3'; + } + // @codeCoverageIgnoreEnd - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'size' => 'medium', - 'fields' => [ - 'license' => [ - 'type' => 'info', - 'label' => I18n::translate('license'), - 'text' => $license ? $license : I18n::translate('license.unregistered.label'), - 'theme' => $license ? 'code' : 'negative', - 'help' => $license ? - // @codeCoverageIgnoreStart - '' . I18n::translate('license.manage') . ' →' : - // @codeCoverageIgnoreEnd - '' . I18n::translate('license.buy') . ' →' - ] - ], - 'submitButton' => false, - 'cancelButton' => false, - ] - ]; - } - ], - // license registration - 'registration' => [ - 'load' => function () { - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => [ - 'license' => [ - 'label' => I18n::translate('license.register.label'), - 'type' => 'text', - 'required' => true, - 'counter' => false, - 'placeholder' => 'K3-', - 'help' => I18n::translate('license.register.help') - ], - 'email' => Field::email([ - 'required' => true - ]) - ], - 'submitButton' => I18n::translate('license.register'), - 'value' => [ - 'license' => null, - 'email' => null - ] - ] - ]; - }, - 'submit' => function () { - // @codeCoverageIgnoreStart - $kirby = App::instance(); - $kirby->system()->register( - $kirby->request()->get('license'), - $kirby->request()->get('email') - ); + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'size' => 'medium', + 'fields' => [ + 'license' => [ + 'type' => 'info', + 'label' => I18n::translate('license'), + 'text' => $license ? $license : I18n::translate('license.unregistered.label'), + 'theme' => $license ? 'code' : 'negative', + 'help' => $license ? + // @codeCoverageIgnoreStart + '' . I18n::translate('license.manage') . ' →' : + // @codeCoverageIgnoreEnd + '' . I18n::translate('license.buy') . ' →' + ] + ], + 'submitButton' => false, + 'cancelButton' => false, + ] + ]; + } + ], + // license registration + 'registration' => [ + 'load' => function () { + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => [ + 'license' => [ + 'label' => I18n::translate('license.register.label'), + 'type' => 'text', + 'required' => true, + 'counter' => false, + 'placeholder' => 'K3-', + 'help' => I18n::translate('license.register.help') + ], + 'email' => Field::email([ + 'required' => true + ]) + ], + 'submitButton' => I18n::translate('license.register'), + 'value' => [ + 'license' => null, + 'email' => null + ] + ] + ]; + }, + 'submit' => function () { + // @codeCoverageIgnoreStart + $kirby = App::instance(); + $kirby->system()->register( + $kirby->request()->get('license'), + $kirby->request()->get('email') + ); - return [ - 'event' => 'system.register', - 'message' => I18n::translate('license.register.success') - ]; - // @codeCoverageIgnoreEnd - } - ], + return [ + 'event' => 'system.register', + 'message' => I18n::translate('license.register.success') + ]; + // @codeCoverageIgnoreEnd + } + ], ]; diff --git a/kirby/config/areas/system/views.php b/kirby/config/areas/system/views.php index 7b2c265..8bab2a2 100755 --- a/kirby/config/areas/system/views.php +++ b/kirby/config/areas/system/views.php @@ -3,53 +3,53 @@ use Kirby\Cms\App; return [ - 'system' => [ - 'pattern' => 'system', - 'action' => function () { - $kirby = App::instance(); - $system = $kirby->system(); - $license = $system->license(); + 'system' => [ + 'pattern' => 'system', + 'action' => function () { + $kirby = App::instance(); + $system = $kirby->system(); + $license = $system->license(); - // @codeCoverageIgnoreStart - if ($license === true) { - // valid license, but user is not admin - $license = 'Kirby 3'; - } elseif ($license === false) { - // no valid license - $license = null; - } - // @codeCoverageIgnoreEnd + // @codeCoverageIgnoreStart + if ($license === true) { + // valid license, but user is not admin + $license = 'Kirby 3'; + } elseif ($license === false) { + // no valid license + $license = null; + } + // @codeCoverageIgnoreEnd - $plugins = $system->plugins()->values(function ($plugin) { - return [ - 'author' => $plugin->authorsNames(), - 'license' => $plugin->license(), - 'name' => [ - 'text' => $plugin->name(), - 'href' => $plugin->link(), - ], - 'version' => $plugin->version(), - ]; - }); + $plugins = $system->plugins()->values(function ($plugin) { + return [ + 'author' => $plugin->authorsNames(), + 'license' => $plugin->license(), + 'name' => [ + 'text' => $plugin->name(), + 'href' => $plugin->link(), + ], + 'version' => $plugin->version(), + ]; + }); - return [ - 'component' => 'k-system-view', - 'props' => [ - 'debug' => $kirby->option('debug', false), - 'license' => $license, - 'plugins' => $plugins, - 'php' => phpversion(), - 'server' => $system->serverSoftware(), - 'https' => $kirby->environment()->https(), - 'version' => $kirby->version(), - 'urls' => [ - 'content' => $system->exposedFileUrl('content'), - 'git' => $system->exposedFileUrl('git'), - 'kirby' => $system->exposedFileUrl('kirby'), - 'site' => $system->exposedFileUrl('site') - ] - ] - ]; - } - ], + return [ + 'component' => 'k-system-view', + 'props' => [ + 'debug' => $kirby->option('debug', false), + 'license' => $license, + 'plugins' => $plugins, + 'php' => phpversion(), + 'server' => $system->serverSoftware(), + 'https' => $kirby->environment()->https(), + 'version' => $kirby->version(), + 'urls' => [ + 'content' => $system->exposedFileUrl('content'), + 'git' => $system->exposedFileUrl('git'), + 'kirby' => $system->exposedFileUrl('kirby'), + 'site' => $system->exposedFileUrl('site') + ] + ] + ]; + } + ], ]; diff --git a/kirby/config/areas/users.php b/kirby/config/areas/users.php index 830d1fe..ff7e130 100755 --- a/kirby/config/areas/users.php +++ b/kirby/config/areas/users.php @@ -3,14 +3,14 @@ use Kirby\Toolkit\I18n; return function ($kirby) { - return [ - 'icon' => 'users', - 'label' => I18n::translate('view.users'), - 'search' => 'users', - 'menu' => true, - 'dialogs' => require __DIR__ . '/users/dialogs.php', - 'dropdowns' => require __DIR__ . '/users/dropdowns.php', - 'searches' => require __DIR__ . '/users/searches.php', - 'views' => require __DIR__ . '/users/views.php' - ]; + return [ + 'icon' => 'users', + 'label' => I18n::translate('view.users'), + 'search' => 'users', + 'menu' => true, + 'dialogs' => require __DIR__ . '/users/dialogs.php', + 'dropdowns' => require __DIR__ . '/users/dropdowns.php', + 'searches' => require __DIR__ . '/users/searches.php', + 'views' => require __DIR__ . '/users/views.php' + ]; }; diff --git a/kirby/config/areas/users/dialogs.php b/kirby/config/areas/users/dialogs.php index d3b8e2c..291abb3 100755 --- a/kirby/config/areas/users/dialogs.php +++ b/kirby/config/areas/users/dialogs.php @@ -13,299 +13,299 @@ $files = require __DIR__ . '/../files/dialogs.php'; return [ - // create - 'user.create' => [ - 'pattern' => 'users/create', - 'load' => function () { - $kirby = App::instance(); - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => [ - 'name' => Field::username(), - 'email' => Field::email([ - 'link' => false, - 'required' => true - ]), - 'password' => Field::password(), - 'translation' => Field::translation([ - 'required' => true - ]), - 'role' => Field::role([ - 'required' => true - ]) - ], - 'submitButton' => I18n::translate('create'), - 'value' => [ - 'name' => '', - 'email' => '', - 'password' => '', - 'translation' => $kirby->panelLanguage(), - 'role' => $kirby->user()->role()->name() - ] - ] - ]; - }, - 'submit' => function () { - $kirby = App::instance(); + // create + 'user.create' => [ + 'pattern' => 'users/create', + 'load' => function () { + $kirby = App::instance(); + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => [ + 'name' => Field::username(), + 'email' => Field::email([ + 'link' => false, + 'required' => true + ]), + 'password' => Field::password(), + 'translation' => Field::translation([ + 'required' => true + ]), + 'role' => Field::role([ + 'required' => true + ]) + ], + 'submitButton' => I18n::translate('create'), + 'value' => [ + 'name' => '', + 'email' => '', + 'password' => '', + 'translation' => $kirby->panelLanguage(), + 'role' => $kirby->user()->role()->name() + ] + ] + ]; + }, + 'submit' => function () { + $kirby = App::instance(); - $kirby->users()->create([ - 'name' => $kirby->request()->get('name'), - 'email' => $kirby->request()->get('email'), - 'password' => $kirby->request()->get('password'), - 'language' => $kirby->request()->get('translation'), - 'role' => $kirby->request()->get('role') - ]); + $kirby->users()->create([ + 'name' => $kirby->request()->get('name'), + 'email' => $kirby->request()->get('email'), + 'password' => $kirby->request()->get('password'), + 'language' => $kirby->request()->get('translation'), + 'role' => $kirby->request()->get('role') + ]); - return [ - 'event' => 'user.create' - ]; - } - ], + return [ + 'event' => 'user.create' + ]; + } + ], - // change email - 'user.changeEmail' => [ - 'pattern' => 'users/(:any)/changeEmail', - 'load' => function (string $id) { - $user = Find::user($id); + // change email + 'user.changeEmail' => [ + 'pattern' => 'users/(:any)/changeEmail', + 'load' => function (string $id) { + $user = Find::user($id); - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => [ - 'email' => [ - 'label' => I18n::translate('email'), - 'required' => true, - 'type' => 'email', - 'preselect' => true - ] - ], - 'submitButton' => I18n::translate('change'), - 'value' => [ - 'email' => $user->email() - ] - ] - ]; - }, - 'submit' => function (string $id) { - $request = App::instance()->request(); + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => [ + 'email' => [ + 'label' => I18n::translate('email'), + 'required' => true, + 'type' => 'email', + 'preselect' => true + ] + ], + 'submitButton' => I18n::translate('change'), + 'value' => [ + 'email' => $user->email() + ] + ] + ]; + }, + 'submit' => function (string $id) { + $request = App::instance()->request(); - Find::user($id)->changeEmail($request->get('email')); + Find::user($id)->changeEmail($request->get('email')); - return [ - 'event' => 'user.changeEmail' - ]; - } - ], + return [ + 'event' => 'user.changeEmail' + ]; + } + ], - // change language - 'user.changeLanguage' => [ - 'pattern' => 'users/(:any)/changeLanguage', - 'load' => function (string $id) { - $user = Find::user($id); + // change language + 'user.changeLanguage' => [ + 'pattern' => 'users/(:any)/changeLanguage', + 'load' => function (string $id) { + $user = Find::user($id); - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => [ - 'translation' => Field::translation(['required' => true]) - ], - 'submitButton' => I18n::translate('change'), - 'value' => [ - 'translation' => $user->language() - ] - ] - ]; - }, - 'submit' => function (string $id) { - $request = App::instance()->request(); + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => [ + 'translation' => Field::translation(['required' => true]) + ], + 'submitButton' => I18n::translate('change'), + 'value' => [ + 'translation' => $user->language() + ] + ] + ]; + }, + 'submit' => function (string $id) { + $request = App::instance()->request(); - Find::user($id)->changeLanguage($request->get('translation')); + Find::user($id)->changeLanguage($request->get('translation')); - return [ - 'event' => 'user.changeLanguage', - 'reload' => [ - 'globals' => '$translation' - ] - ]; - } - ], + return [ + 'event' => 'user.changeLanguage', + 'reload' => [ + 'globals' => '$translation' + ] + ]; + } + ], - // change name - 'user.changeName' => [ - 'pattern' => 'users/(:any)/changeName', - 'load' => function (string $id) { - $user = Find::user($id); + // change name + 'user.changeName' => [ + 'pattern' => 'users/(:any)/changeName', + 'load' => function (string $id) { + $user = Find::user($id); - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => [ - 'name' => Field::username([ - 'preselect' => true - ]) - ], - 'submitButton' => I18n::translate('rename'), - 'value' => [ - 'name' => $user->name()->value() - ] - ] - ]; - }, - 'submit' => function (string $id) { - $request = App::instance()->request(); + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => [ + 'name' => Field::username([ + 'preselect' => true + ]) + ], + 'submitButton' => I18n::translate('rename'), + 'value' => [ + 'name' => $user->name()->value() + ] + ] + ]; + }, + 'submit' => function (string $id) { + $request = App::instance()->request(); - Find::user($id)->changeName($request->get('name')); + Find::user($id)->changeName($request->get('name')); - return [ - 'event' => 'user.changeName' - ]; - } - ], + return [ + 'event' => 'user.changeName' + ]; + } + ], - // change password - 'user.changePassword' => [ - 'pattern' => 'users/(:any)/changePassword', - 'load' => function (string $id) { - $user = Find::user($id); + // change password + 'user.changePassword' => [ + 'pattern' => 'users/(:any)/changePassword', + 'load' => function (string $id) { + $user = Find::user($id); - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => [ - 'password' => Field::password([ - 'label' => I18n::translate('user.changePassword.new'), - ]), - 'passwordConfirmation' => Field::password([ - 'label' => I18n::translate('user.changePassword.new.confirm'), - ]) - ], - 'submitButton' => I18n::translate('change'), - ] - ]; - }, - 'submit' => function (string $id) { - $request = App::instance()->request(); + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => [ + 'password' => Field::password([ + 'label' => I18n::translate('user.changePassword.new'), + ]), + 'passwordConfirmation' => Field::password([ + 'label' => I18n::translate('user.changePassword.new.confirm'), + ]) + ], + 'submitButton' => I18n::translate('change'), + ] + ]; + }, + 'submit' => function (string $id) { + $request = App::instance()->request(); - $user = Find::user($id); - $password = $request->get('password'); - $passwordConfirmation = $request->get('passwordConfirmation'); + $user = Find::user($id); + $password = $request->get('password'); + $passwordConfirmation = $request->get('passwordConfirmation'); - // validate the password - UserRules::validPassword($user, $password ?? ''); + // validate the password + UserRules::validPassword($user, $password ?? ''); - // compare passwords - if ($password !== $passwordConfirmation) { - throw new InvalidArgumentException([ - 'key' => 'user.password.notSame' - ]); - } + // compare passwords + if ($password !== $passwordConfirmation) { + throw new InvalidArgumentException([ + 'key' => 'user.password.notSame' + ]); + } - // change password if everything's fine - $user->changePassword($password); + // change password if everything's fine + $user->changePassword($password); - return [ - 'event' => 'user.changePassword' - ]; - } - ], + return [ + 'event' => 'user.changePassword' + ]; + } + ], - // change role - 'user.changeRole' => [ - 'pattern' => 'users/(:any)/changeRole', - 'load' => function (string $id) { - $user = Find::user($id); + // change role + 'user.changeRole' => [ + 'pattern' => 'users/(:any)/changeRole', + 'load' => function (string $id) { + $user = Find::user($id); - return [ - 'component' => 'k-form-dialog', - 'props' => [ - 'fields' => [ - 'role' => Field::role([ - 'label' => I18n::translate('user.changeRole.select'), - 'required' => true, - ]) - ], - 'submitButton' => I18n::translate('user.changeRole'), - 'value' => [ - 'role' => $user->role()->name() - ] - ] - ]; - }, - 'submit' => function (string $id) { - $request = App::instance()->request(); + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => [ + 'role' => Field::role([ + 'label' => I18n::translate('user.changeRole.select'), + 'required' => true, + ]) + ], + 'submitButton' => I18n::translate('user.changeRole'), + 'value' => [ + 'role' => $user->role()->name() + ] + ] + ]; + }, + 'submit' => function (string $id) { + $request = App::instance()->request(); - $user = Find::user($id)->changeRole($request->get('role')); + $user = Find::user($id)->changeRole($request->get('role')); - return [ - 'event' => 'user.changeRole', - 'user' => $user->toArray() - ]; - } - ], + return [ + 'event' => 'user.changeRole', + 'user' => $user->toArray() + ]; + } + ], - // delete - 'user.delete' => [ - 'pattern' => 'users/(:any)/delete', - 'load' => function (string $id) { - $user = Find::user($id); - $i18nPrefix = $user->isLoggedIn() ? 'account' : 'user'; + // delete + 'user.delete' => [ + 'pattern' => 'users/(:any)/delete', + 'load' => function (string $id) { + $user = Find::user($id); + $i18nPrefix = $user->isLoggedIn() ? 'account' : 'user'; - return [ - 'component' => 'k-remove-dialog', - 'props' => [ - 'text' => I18n::template($i18nPrefix . '.delete.confirm', [ - 'email' => Escape::html($user->email()) - ]) - ] - ]; - }, - 'submit' => function (string $id) { - $user = Find::user($id); - $redirect = false; - $referrer = Panel::referrer(); - $url = $user->panel()->url(true); + return [ + 'component' => 'k-remove-dialog', + 'props' => [ + 'text' => I18n::template($i18nPrefix . '.delete.confirm', [ + 'email' => Escape::html($user->email()) + ]) + ] + ]; + }, + 'submit' => function (string $id) { + $user = Find::user($id); + $redirect = false; + $referrer = Panel::referrer(); + $url = $user->panel()->url(true); - $user->delete(); + $user->delete(); - // redirect to the users view - // if the dialog has been opened in the user view - if ($referrer === $url) { - $redirect = '/users'; - } + // redirect to the users view + // if the dialog has been opened in the user view + if ($referrer === $url) { + $redirect = '/users'; + } - // logout the user if they deleted themselves - if ($user->isLoggedIn()) { - $redirect = '/logout'; - } + // logout the user if they deleted themselves + if ($user->isLoggedIn()) { + $redirect = '/logout'; + } - return [ - 'event' => 'user.delete', - 'dispatch' => ['content/remove' => [$url]], - 'redirect' => $redirect - ]; - } - ], + return [ + 'event' => 'user.delete', + 'dispatch' => ['content/remove' => [$url]], + 'redirect' => $redirect + ]; + } + ], - // change file name - 'user.file.changeName' => [ - 'pattern' => '(users/.*?)/files/(:any)/changeName', - 'load' => $files['changeName']['load'], - 'submit' => $files['changeName']['submit'], - ], + // change file name + 'user.file.changeName' => [ + 'pattern' => '(users/.*?)/files/(:any)/changeName', + 'load' => $files['changeName']['load'], + 'submit' => $files['changeName']['submit'], + ], - // change file sort - 'user.file.changeSort' => [ - 'pattern' => '(users/.*?)/files/(:any)/changeSort', - 'load' => $files['changeSort']['load'], - 'submit' => $files['changeSort']['submit'], - ], + // change file sort + 'user.file.changeSort' => [ + 'pattern' => '(users/.*?)/files/(:any)/changeSort', + 'load' => $files['changeSort']['load'], + 'submit' => $files['changeSort']['submit'], + ], - // delete file - 'user.file.delete' => [ - 'pattern' => '(users/.*?)/files/(:any)/delete', - 'load' => $files['delete']['load'], - 'submit' => $files['delete']['submit'], - ] + // delete file + 'user.file.delete' => [ + 'pattern' => '(users/.*?)/files/(:any)/delete', + 'load' => $files['delete']['load'], + 'submit' => $files['delete']['submit'], + ] ]; diff --git a/kirby/config/areas/users/dropdowns.php b/kirby/config/areas/users/dropdowns.php index 2b3f15f..ec30a5f 100755 --- a/kirby/config/areas/users/dropdowns.php +++ b/kirby/config/areas/users/dropdowns.php @@ -5,14 +5,14 @@ use Kirby\Cms\Find; $files = require __DIR__ . '/../files/dropdowns.php'; return [ - 'user' => [ - 'pattern' => 'users/(:any)', - 'options' => function (string $id) { - return Find::user($id)->panel()->dropdown(); - } - ], - 'user.file' => [ - 'pattern' => '(users/.*?)/files/(:any)', - 'options' => $files['file'] - ] + 'user' => [ + 'pattern' => 'users/(:any)', + 'options' => function (string $id) { + return Find::user($id)->panel()->dropdown(); + } + ], + 'user.file' => [ + 'pattern' => '(users/.*?)/files/(:any)', + 'options' => $files['file'] + ] ]; diff --git a/kirby/config/areas/users/searches.php b/kirby/config/areas/users/searches.php index e2bf106..25a5702 100755 --- a/kirby/config/areas/users/searches.php +++ b/kirby/config/areas/users/searches.php @@ -5,23 +5,23 @@ use Kirby\Toolkit\Escape; use Kirby\Toolkit\I18n; return [ - 'users' => [ - 'label' => I18n::translate('users'), - 'icon' => 'users', - 'query' => function (string $query = null) { - $users = App::instance()->users()->search($query)->limit(10); - $results = []; + 'users' => [ + 'label' => I18n::translate('users'), + 'icon' => 'users', + 'query' => function (string $query = null) { + $users = App::instance()->users()->search($query)->limit(10); + $results = []; - foreach ($users as $user) { - $results[] = [ - 'image' => $user->panel()->image(), - 'text' => Escape::html($user->username()), - 'link' => $user->panel()->url(true), - 'info' => Escape::html($user->role()->title()) - ]; - } + foreach ($users as $user) { + $results[] = [ + 'image' => $user->panel()->image(), + 'text' => Escape::html($user->username()), + 'link' => $user->panel()->url(true), + 'info' => Escape::html($user->role()->title()) + ]; + } - return $results; - } - ] + return $results; + } + ] ]; diff --git a/kirby/config/areas/users/views.php b/kirby/config/areas/users/views.php index 9ce73d0..a03a5d6 100755 --- a/kirby/config/areas/users/views.php +++ b/kirby/config/areas/users/views.php @@ -5,62 +5,62 @@ use Kirby\Cms\Find; use Kirby\Toolkit\Escape; return [ - 'users' => [ - 'pattern' => 'users', - 'action' => function () { - $kirby = App::instance(); - $role = $kirby->request()->get('role'); - $roles = $kirby->roles()->toArray(fn ($role) => [ - 'id' => $role->id(), - 'title' => $role->title(), - ]); + 'users' => [ + 'pattern' => 'users', + 'action' => function () { + $kirby = App::instance(); + $role = $kirby->request()->get('role'); + $roles = $kirby->roles()->toArray(fn ($role) => [ + 'id' => $role->id(), + 'title' => $role->title(), + ]); - return [ - 'component' => 'k-users-view', - 'props' => [ - 'role' => function () use ($kirby, $roles, $role) { - if ($role) { - return $roles[$role] ?? null; - } - }, - 'roles' => array_values($roles), - 'users' => function () use ($kirby, $role) { - $users = $kirby->users(); + return [ + 'component' => 'k-users-view', + 'props' => [ + 'role' => function () use ($kirby, $roles, $role) { + if ($role) { + return $roles[$role] ?? null; + } + }, + 'roles' => array_values($roles), + 'users' => function () use ($kirby, $role) { + $users = $kirby->users(); - if (empty($role) === false) { - $users = $users->role($role); - } + if (empty($role) === false) { + $users = $users->role($role); + } - $users = $users->paginate([ - 'limit' => 20, - 'page' => $kirby->request()->get('page') - ]); + $users = $users->paginate([ + 'limit' => 20, + 'page' => $kirby->request()->get('page') + ]); - return [ - 'data' => $users->values(fn ($user) => [ - 'id' => $user->id(), - 'image' => $user->panel()->image(), - 'info' => Escape::html($user->role()->title()), - 'link' => $user->panel()->url(true), - 'text' => Escape::html($user->username()) - ]), - 'pagination' => $users->pagination()->toArray() - ]; - }, - ] - ]; - } - ], - 'user' => [ - 'pattern' => 'users/(:any)', - 'action' => function (string $id) { - return Find::user($id)->panel()->view(); - } - ], - 'user.file' => [ - 'pattern' => 'users/(:any)/files/(:any)', - 'action' => function (string $id, string $filename) { - return Find::file('users/' . $id, $filename)->panel()->view(); - } - ], + return [ + 'data' => $users->values(fn ($user) => [ + 'id' => $user->id(), + 'image' => $user->panel()->image(), + 'info' => Escape::html($user->role()->title()), + 'link' => $user->panel()->url(true), + 'text' => Escape::html($user->username()) + ]), + 'pagination' => $users->pagination()->toArray() + ]; + }, + ] + ]; + } + ], + 'user' => [ + 'pattern' => 'users/(:any)', + 'action' => function (string $id) { + return Find::user($id)->panel()->view(); + } + ], + 'user.file' => [ + 'pattern' => 'users/(:any)/files/(:any)', + 'action' => function (string $id, string $filename) { + return Find::file('users/' . $id, $filename)->panel()->view(); + } + ], ]; diff --git a/kirby/config/blocks/image/image.php b/kirby/config/blocks/image/image.php index e1902ec..3e3e3df 100755 --- a/kirby/config/blocks/image/image.php +++ b/kirby/config/blocks/image/image.php @@ -9,10 +9,10 @@ $ratio = $block->ratio()->or('auto'); $src = null; if ($block->location() == 'web') { - $src = $block->src()->esc(); + $src = $block->src()->esc(); } elseif ($image = $block->image()->toFile()) { - $alt = $alt ?? $image->alt(); - $src = $image->url(); + $alt = $alt ?? $image->alt(); + $src = $image->url(); } ?> diff --git a/kirby/config/components.php b/kirby/config/components.php index b60d34c..c05d886 100755 --- a/kirby/config/components.php +++ b/kirby/config/components.php @@ -21,395 +21,395 @@ use Kirby\Toolkit\Tpl as Snippet; return [ - /** - * Used by the `css()` helper - * - * @param \Kirby\Cms\App $kirby Kirby instance - * @param string $url Relative or absolute URL - * @param string|array $options An array of attributes for the link tag or a media attribute string - */ - 'css' => fn (App $kirby, string $url, $options = null): string => $url, + /** + * Used by the `css()` helper + * + * @param \Kirby\Cms\App $kirby Kirby instance + * @param string $url Relative or absolute URL + * @param string|array $options An array of attributes for the link tag or a media attribute string + */ + 'css' => fn (App $kirby, string $url, $options = null): string => $url, - /** - * Object and variable dumper - * to help with debugging. - * - * @param \Kirby\Cms\App $kirby Kirby instance - * @param mixed $variable - * @param bool $echo - * @return string - * - * @deprecated 3.7.0 Disable `dump()` via `KIRBY_HELPER_DUMP` instead and create your own function - * @todo move to `Helpers::dump()`, remove component in 3.8.0 - */ - 'dump' => function (App $kirby, $variable, bool $echo = true) { - if ($kirby->environment()->cli() === true) { - $output = print_r($variable, true) . PHP_EOL; - } else { - $output = '
' . print_r($variable, true) . '
'; - } + /** + * Object and variable dumper + * to help with debugging. + * + * @param \Kirby\Cms\App $kirby Kirby instance + * @param mixed $variable + * @param bool $echo + * @return string + * + * @deprecated 3.7.0 Disable `dump()` via `KIRBY_HELPER_DUMP` instead and create your own function + * @todo move to `Helpers::dump()`, remove component in 3.8.0 + */ + 'dump' => function (App $kirby, $variable, bool $echo = true) { + if ($kirby->environment()->cli() === true) { + $output = print_r($variable, true) . PHP_EOL; + } else { + $output = '
' . print_r($variable, true) . '
'; + } - if ($echo === true) { - echo $output; - } + if ($echo === true) { + echo $output; + } - return $output; - }, + return $output; + }, - /** - * Add your own email provider - * - * @param \Kirby\Cms\App $kirby Kirby instance - * @param array $props - * @param bool $debug - */ - 'email' => function (App $kirby, array $props = [], bool $debug = false) { - return new Emailer($props, $debug); - }, + /** + * Add your own email provider + * + * @param \Kirby\Cms\App $kirby Kirby instance + * @param array $props + * @param bool $debug + */ + 'email' => function (App $kirby, array $props = [], bool $debug = false) { + return new Emailer($props, $debug); + }, - /** - * Modify URLs for file objects - * - * @param \Kirby\Cms\App $kirby Kirby instance - * @param \Kirby\Cms\File $file The original file object - * @return string - */ - 'file::url' => function (App $kirby, File $file): string { - return $file->mediaUrl(); - }, + /** + * Modify URLs for file objects + * + * @param \Kirby\Cms\App $kirby Kirby instance + * @param \Kirby\Cms\File $file The original file object + * @return string + */ + 'file::url' => function (App $kirby, File $file): string { + return $file->mediaUrl(); + }, - /** - * Adapt file characteristics - * - * @param \Kirby\Cms\App $kirby Kirby instance - * @param \Kirby\Cms\File|\Kirby\Filesystem\Asset $file The file object - * @param array $options All thumb options (width, height, crop, blur, grayscale) - * @return \Kirby\Cms\File|\Kirby\Cms\FileVersion|\Kirby\Filesystem\Asset - */ - 'file::version' => function (App $kirby, $file, array $options = []) { - // if file is not resizable, return - if ($file->isResizable() === false) { - return $file; - } + /** + * Adapt file characteristics + * + * @param \Kirby\Cms\App $kirby Kirby instance + * @param \Kirby\Cms\File|\Kirby\Filesystem\Asset $file The file object + * @param array $options All thumb options (width, height, crop, blur, grayscale) + * @return \Kirby\Cms\File|\Kirby\Cms\FileVersion|\Kirby\Filesystem\Asset + */ + 'file::version' => function (App $kirby, $file, array $options = []) { + // if file is not resizable, return + if ($file->isResizable() === false) { + return $file; + } - // create url and root - $mediaRoot = dirname($file->mediaRoot()); - $template = $mediaRoot . '/{{ name }}{{ attributes }}.{{ extension }}'; - $thumbRoot = (new Filename($file->root(), $template, $options))->toString(); - $thumbName = basename($thumbRoot); + // create url and root + $mediaRoot = dirname($file->mediaRoot()); + $template = $mediaRoot . '/{{ name }}{{ attributes }}.{{ extension }}'; + $thumbRoot = (new Filename($file->root(), $template, $options))->toString(); + $thumbName = basename($thumbRoot); - // check if the thumb already exists - if (file_exists($thumbRoot) === false) { + // check if the thumb already exists + if (file_exists($thumbRoot) === false) { - // if not, create job file - $job = $mediaRoot . '/.jobs/' . $thumbName . '.json'; + // if not, create job file + $job = $mediaRoot . '/.jobs/' . $thumbName . '.json'; - try { - Data::write($job, array_merge($options, [ - 'filename' => $file->filename() - ])); - } catch (Throwable $e) { - // if thumb doesn't exist yet and job file cannot - // be created, return - return $file; - } - } + try { + Data::write($job, array_merge($options, [ + 'filename' => $file->filename() + ])); + } catch (Throwable $e) { + // if thumb doesn't exist yet and job file cannot + // be created, return + return $file; + } + } - return new FileVersion([ - 'modifications' => $options, - 'original' => $file, - 'root' => $thumbRoot, - 'url' => dirname($file->mediaUrl()) . '/' . $thumbName, - ]); - }, + return new FileVersion([ + 'modifications' => $options, + 'original' => $file, + 'root' => $thumbRoot, + 'url' => dirname($file->mediaUrl()) . '/' . $thumbName, + ]); + }, - /** - * Used by the `js()` helper - * - * @param \Kirby\Cms\App $kirby Kirby instance - * @param string $url Relative or absolute URL - * @param string|array $options An array of attributes for the link tag or a media attribute string - */ - 'js' => fn (App $kirby, string $url, $options = null): string => $url, + /** + * Used by the `js()` helper + * + * @param \Kirby\Cms\App $kirby Kirby instance + * @param string $url Relative or absolute URL + * @param string|array $options An array of attributes for the link tag or a media attribute string + */ + 'js' => fn (App $kirby, string $url, $options = null): string => $url, - /** - * Add your own Markdown parser - * - * @param \Kirby\Cms\App $kirby Kirby instance - * @param string $text Text to parse - * @param array $options Markdown options - * @param bool $inline Whether to wrap the text in `

` tags (deprecated: set via $options['inline'] instead) - * @return string - * @todo remove $inline parameter in in 3.8.0 - */ - 'markdown' => function (App $kirby, string $text = null, array $options = [], bool $inline = false): string { - static $markdown; - static $config; + /** + * Add your own Markdown parser + * + * @param \Kirby\Cms\App $kirby Kirby instance + * @param string $text Text to parse + * @param array $options Markdown options + * @param bool $inline Whether to wrap the text in `

` tags (deprecated: set via $options['inline'] instead) + * @return string + * @todo remove $inline parameter in in 3.8.0 + */ + 'markdown' => function (App $kirby, string $text = null, array $options = [], bool $inline = false): string { + static $markdown; + static $config; - // warning for deprecated fourth parameter - if (func_num_args() === 4 && isset($options['inline']) === false) { - // @codeCoverageIgnoreStart - Helpers::deprecated('markdown component: the $inline parameter is deprecated and will be removed in Kirby 3.8.0. Use $options[\'inline\'] instead.'); - // @codeCoverageIgnoreEnd - } + // warning for deprecated fourth parameter + if (func_num_args() === 4 && isset($options['inline']) === false) { + // @codeCoverageIgnoreStart + Helpers::deprecated('markdown component: the $inline parameter is deprecated and will be removed in Kirby 3.8.0. Use $options[\'inline\'] instead.'); + // @codeCoverageIgnoreEnd + } - // support for the deprecated fourth argument - $options['inline'] ??= $inline; + // support for the deprecated fourth argument + $options['inline'] ??= $inline; - // if the config options have changed or the component is called for the first time, - // (re-)initialize the parser object - if ($config !== $options) { - $markdown = new Markdown($options); - $config = $options; - } + // if the config options have changed or the component is called for the first time, + // (re-)initialize the parser object + if ($config !== $options) { + $markdown = new Markdown($options); + $config = $options; + } - return $markdown->parse($text, $options['inline'] ?? false); - }, + return $markdown->parse($text, $options['inline'] ?? false); + }, - /** - * Add your own search engine - * - * @param \Kirby\Cms\App $kirby Kirby instance - * @param \Kirby\Cms\Collection $collection Collection of searchable models - * @param string $query - * @param mixed $params - * @return \Kirby\Cms\Collection|bool - */ - 'search' => function (App $kirby, Collection $collection, string $query = null, $params = []) { - if (empty(trim($query ?? '')) === true) { - return $collection->limit(0); - } + /** + * Add your own search engine + * + * @param \Kirby\Cms\App $kirby Kirby instance + * @param \Kirby\Cms\Collection $collection Collection of searchable models + * @param string $query + * @param mixed $params + * @return \Kirby\Cms\Collection|bool + */ + 'search' => function (App $kirby, Collection $collection, string $query = null, $params = []) { + if (empty(trim($query ?? '')) === true) { + return $collection->limit(0); + } - if (is_string($params) === true) { - $params = ['fields' => Str::split($params, '|')]; - } + if (is_string($params) === true) { + $params = ['fields' => Str::split($params, '|')]; + } - $defaults = [ - 'fields' => [], - 'minlength' => 2, - 'score' => [], - 'words' => false, - ]; + $defaults = [ + 'fields' => [], + 'minlength' => 2, + 'score' => [], + 'words' => false, + ]; - $options = array_merge($defaults, $params); - $collection = clone $collection; - $searchWords = preg_replace('/(\s)/u', ',', $query); - $searchWords = Str::split($searchWords, ',', $options['minlength']); - $lowerQuery = Str::lower($query); - $exactQuery = $options['words'] ? '(\b' . preg_quote($query) . '\b)' : preg_quote($query); + $options = array_merge($defaults, $params); + $collection = clone $collection; + $searchWords = preg_replace('/(\s)/u', ',', $query); + $searchWords = Str::split($searchWords, ',', $options['minlength']); + $lowerQuery = Str::lower($query); + $exactQuery = $options['words'] ? '(\b' . preg_quote($query) . '\b)' : preg_quote($query); - if (empty($options['stopwords']) === false) { - $searchWords = array_diff($searchWords, $options['stopwords']); - } + if (empty($options['stopwords']) === false) { + $searchWords = array_diff($searchWords, $options['stopwords']); + } - $searchWords = array_map(function ($value) use ($options) { - return $options['words'] ? '\b' . preg_quote($value) . '\b' : preg_quote($value); - }, $searchWords); + $searchWords = array_map(function ($value) use ($options) { + return $options['words'] ? '\b' . preg_quote($value) . '\b' : preg_quote($value); + }, $searchWords); - $preg = '!(' . implode('|', $searchWords) . ')!i'; - $results = $collection->filter(function ($item) use ($query, $preg, $options, $lowerQuery, $exactQuery) { - $data = $item->content()->toArray(); - $keys = array_keys($data); - $keys[] = 'id'; + $preg = '!(' . implode('|', $searchWords) . ')!i'; + $results = $collection->filter(function ($item) use ($query, $preg, $options, $lowerQuery, $exactQuery) { + $data = $item->content()->toArray(); + $keys = array_keys($data); + $keys[] = 'id'; - if (is_a($item, 'Kirby\Cms\User') === true) { - $keys[] = 'name'; - $keys[] = 'email'; - $keys[] = 'role'; - } elseif (is_a($item, 'Kirby\Cms\Page') === true) { - // apply the default score for pages - $options['score'] = array_merge([ - 'id' => 64, - 'title' => 64, - ], $options['score']); - } + if (is_a($item, 'Kirby\Cms\User') === true) { + $keys[] = 'name'; + $keys[] = 'email'; + $keys[] = 'role'; + } elseif (is_a($item, 'Kirby\Cms\Page') === true) { + // apply the default score for pages + $options['score'] = array_merge([ + 'id' => 64, + 'title' => 64, + ], $options['score']); + } - if (empty($options['fields']) === false) { - $fields = array_map('strtolower', $options['fields']); - $keys = array_intersect($keys, $fields); - } + if (empty($options['fields']) === false) { + $fields = array_map('strtolower', $options['fields']); + $keys = array_intersect($keys, $fields); + } - $item->searchHits = 0; - $item->searchScore = 0; + $item->searchHits = 0; + $item->searchScore = 0; - foreach ($keys as $key) { - $score = $options['score'][$key] ?? 1; - $value = $data[$key] ?? (string)$item->$key(); + foreach ($keys as $key) { + $score = $options['score'][$key] ?? 1; + $value = $data[$key] ?? (string)$item->$key(); - $lowerValue = Str::lower($value); + $lowerValue = Str::lower($value); - // check for exact matches - if ($lowerQuery == $lowerValue) { - $item->searchScore += 16 * $score; - $item->searchHits += 1; + // check for exact matches + if ($lowerQuery == $lowerValue) { + $item->searchScore += 16 * $score; + $item->searchHits += 1; - // check for exact beginning matches - } elseif ($options['words'] === false && Str::startsWith($lowerValue, $lowerQuery) === true) { - $item->searchScore += 8 * $score; - $item->searchHits += 1; + // check for exact beginning matches + } elseif ($options['words'] === false && Str::startsWith($lowerValue, $lowerQuery) === true) { + $item->searchScore += 8 * $score; + $item->searchHits += 1; - // check for exact query matches - } elseif ($matches = preg_match_all('!' . $exactQuery . '!i', $value, $r)) { - $item->searchScore += 2 * $score; - $item->searchHits += $matches; - } + // check for exact query matches + } elseif ($matches = preg_match_all('!' . $exactQuery . '!i', $value, $r)) { + $item->searchScore += 2 * $score; + $item->searchHits += $matches; + } - // check for any match - if ($matches = preg_match_all($preg, $value, $r)) { - $item->searchHits += $matches; - $item->searchScore += $matches * $score; - } - } + // check for any match + if ($matches = preg_match_all($preg, $value, $r)) { + $item->searchHits += $matches; + $item->searchScore += $matches * $score; + } + } - return $item->searchHits > 0; - }); + return $item->searchHits > 0; + }); - return $results->sort('searchScore', 'desc'); - }, + return $results->sort('searchScore', 'desc'); + }, - /** - * Add your own SmartyPants parser - * - * @param \Kirby\Cms\App $kirby Kirby instance - * @param string $text Text to parse - * @param array $options SmartyPants options - * @return string - */ - 'smartypants' => function (App $kirby, string $text = null, array $options = []): string { - static $smartypants; - static $config; + /** + * Add your own SmartyPants parser + * + * @param \Kirby\Cms\App $kirby Kirby instance + * @param string $text Text to parse + * @param array $options SmartyPants options + * @return string + */ + 'smartypants' => function (App $kirby, string $text = null, array $options = []): string { + static $smartypants; + static $config; - // if the config options have changed or the component is called for the first time, - // (re-)initialize the parser object - if ($config !== $options) { - $smartypants = new Smartypants($options); - $config = $options; - } + // if the config options have changed or the component is called for the first time, + // (re-)initialize the parser object + if ($config !== $options) { + $smartypants = new Smartypants($options); + $config = $options; + } - return $smartypants->parse($text); - }, + return $smartypants->parse($text); + }, - /** - * Add your own snippet loader - * - * @param \Kirby\Cms\App $kirby Kirby instance - * @param string|array $name Snippet name - * @param array $data Data array for the snippet - * @return string|null - */ - 'snippet' => function (App $kirby, $name, array $data = []): ?string { - $snippets = A::wrap($name); + /** + * Add your own snippet loader + * + * @param \Kirby\Cms\App $kirby Kirby instance + * @param string|array $name Snippet name + * @param array $data Data array for the snippet + * @return string|null + */ + 'snippet' => function (App $kirby, $name, array $data = []): ?string { + $snippets = A::wrap($name); - foreach ($snippets as $name) { - $name = (string)$name; - $file = $kirby->root('snippets') . '/' . $name . '.php'; + foreach ($snippets as $name) { + $name = (string)$name; + $file = $kirby->root('snippets') . '/' . $name . '.php'; - if (file_exists($file) === false) { - $file = $kirby->extensions('snippets')[$name] ?? null; - } + if (file_exists($file) === false) { + $file = $kirby->extensions('snippets')[$name] ?? null; + } - if ($file) { - break; - } - } + if ($file) { + break; + } + } - return Snippet::load($file, $data); - }, + return Snippet::load($file, $data); + }, - /** - * Add your own template engine - * - * @param \Kirby\Cms\App $kirby Kirby instance - * @param string $name Template name - * @param string $type Extension type - * @param string $defaultType Default extension type - * @return \Kirby\Cms\Template - */ - 'template' => function (App $kirby, string $name, string $type = 'html', string $defaultType = 'html') { - return new Template($name, $type, $defaultType); - }, + /** + * Add your own template engine + * + * @param \Kirby\Cms\App $kirby Kirby instance + * @param string $name Template name + * @param string $type Extension type + * @param string $defaultType Default extension type + * @return \Kirby\Cms\Template + */ + 'template' => function (App $kirby, string $name, string $type = 'html', string $defaultType = 'html') { + return new Template($name, $type, $defaultType); + }, - /** - * Add your own thumb generator - * - * @param \Kirby\Cms\App $kirby Kirby instance - * @param string $src Root of the original file - * @param string $dst Template string for the root to the desired destination - * @param array $options All thumb options that should be applied: `width`, `height`, `crop`, `blur`, `grayscale` - * @return string - */ - 'thumb' => function (App $kirby, string $src, string $dst, array $options): string { - $darkroom = Darkroom::factory( - $kirby->option('thumbs.driver', 'gd'), - $kirby->option('thumbs', []) - ); - $options = $darkroom->preprocess($src, $options); - $root = (new Filename($src, $dst, $options))->toString(); + /** + * Add your own thumb generator + * + * @param \Kirby\Cms\App $kirby Kirby instance + * @param string $src Root of the original file + * @param string $dst Template string for the root to the desired destination + * @param array $options All thumb options that should be applied: `width`, `height`, `crop`, `blur`, `grayscale` + * @return string + */ + 'thumb' => function (App $kirby, string $src, string $dst, array $options): string { + $darkroom = Darkroom::factory( + $kirby->option('thumbs.driver', 'gd'), + $kirby->option('thumbs', []) + ); + $options = $darkroom->preprocess($src, $options); + $root = (new Filename($src, $dst, $options))->toString(); - F::copy($src, $root, true); - $darkroom->process($root, $options); + F::copy($src, $root, true); + $darkroom->process($root, $options); - return $root; - }, + return $root; + }, - /** - * Modify all URLs - * - * @param \Kirby\Cms\App $kirby Kirby instance - * @param string|null $path URL path - * @param array|string|null $options Array of options for the Uri class - * @return string - */ - 'url' => function (App $kirby, string $path = null, $options = null): string { - $language = null; + /** + * Modify all URLs + * + * @param \Kirby\Cms\App $kirby Kirby instance + * @param string|null $path URL path + * @param array|string|null $options Array of options for the Uri class + * @return string + */ + 'url' => function (App $kirby, string $path = null, $options = null): string { + $language = null; - // get language from simple string option - if (is_string($options) === true) { - $language = $options; - $options = null; - } + // get language from simple string option + if (is_string($options) === true) { + $language = $options; + $options = null; + } - // get language from array - if (is_array($options) === true && isset($options['language']) === true) { - $language = $options['language']; - unset($options['language']); - } + // get language from array + if (is_array($options) === true && isset($options['language']) === true) { + $language = $options['language']; + unset($options['language']); + } - // get a language url for the linked page, if the page can be found - if ($kirby->multilang() === true) { - $parts = Str::split($path, '#'); + // get a language url for the linked page, if the page can be found + if ($kirby->multilang() === true) { + $parts = Str::split($path, '#'); - if ($parts[0] ?? null) { - $page = $kirby->site()->find($parts[0]); - } else { - $page = $kirby->site()->page(); - } + if ($parts[0] ?? null) { + $page = $kirby->site()->find($parts[0]); + } else { + $page = $kirby->site()->page(); + } - if ($page) { - $path = $page->url($language); + if ($page) { + $path = $page->url($language); - if (isset($parts[1]) === true) { - $path .= '#' . $parts[1]; - } - } - } + if (isset($parts[1]) === true) { + $path .= '#' . $parts[1]; + } + } + } - // keep relative urls - if ( - $path !== null && - (substr($path, 0, 2) === './' || substr($path, 0, 3) === '../') - ) { - return $path; - } + // keep relative urls + if ( + $path !== null && + (substr($path, 0, 2) === './' || substr($path, 0, 3) === '../') + ) { + return $path; + } - $url = Url::makeAbsolute($path, $kirby->url()); + $url = Url::makeAbsolute($path, $kirby->url()); - if ($options === null) { - return $url; - } + if ($options === null) { + return $url; + } - return (new Uri($url, $options))->toString(); - }, + return (new Uri($url, $options))->toString(); + }, ]; diff --git a/kirby/config/fields/checkboxes.php b/kirby/config/fields/checkboxes.php index 6837b45..c8d962d 100755 --- a/kirby/config/fields/checkboxes.php +++ b/kirby/config/fields/checkboxes.php @@ -4,58 +4,58 @@ use Kirby\Toolkit\A; use Kirby\Toolkit\Str; return [ - 'mixins' => ['min', 'options'], - 'props' => [ - /** - * Unset inherited props - */ - 'after' => null, - 'before' => null, - 'icon' => null, - 'placeholder' => null, + 'mixins' => ['min', 'options'], + 'props' => [ + /** + * Unset inherited props + */ + 'after' => null, + 'before' => null, + 'icon' => null, + 'placeholder' => null, - /** - * Arranges the checkboxes in the given number of columns - */ - 'columns' => function (int $columns = 1) { - return $columns; - }, - /** - * Default value for the field, which will be used when a page/file/user is created - */ - 'default' => function ($default = null) { - return Str::split($default, ','); - }, - /** - * Maximum number of checked boxes - */ - 'max' => function (int $max = null) { - return $max; - }, - /** - * Minimum number of checked boxes - */ - 'min' => function (int $min = null) { - return $min; - }, - 'value' => function ($value = null) { - return Str::split($value, ','); - }, - ], - 'computed' => [ - 'default' => function () { - return $this->sanitizeOptions($this->default); - }, - 'value' => function () { - return $this->sanitizeOptions($this->value); - }, - ], - 'save' => function ($value): string { - return A::join($value, ', '); - }, - 'validations' => [ - 'options', - 'max', - 'min' - ] + /** + * Arranges the checkboxes in the given number of columns + */ + 'columns' => function (int $columns = 1) { + return $columns; + }, + /** + * Default value for the field, which will be used when a page/file/user is created + */ + 'default' => function ($default = null) { + return Str::split($default, ','); + }, + /** + * Maximum number of checked boxes + */ + 'max' => function (int $max = null) { + return $max; + }, + /** + * Minimum number of checked boxes + */ + 'min' => function (int $min = null) { + return $min; + }, + 'value' => function ($value = null) { + return Str::split($value, ','); + }, + ], + 'computed' => [ + 'default' => function () { + return $this->sanitizeOptions($this->default); + }, + 'value' => function () { + return $this->sanitizeOptions($this->value); + }, + ], + 'save' => function ($value): string { + return A::join($value, ', '); + }, + 'validations' => [ + 'options', + 'max', + 'min' + ] ]; diff --git a/kirby/config/fields/date.php b/kirby/config/fields/date.php index e2124c4..ffb6dc4 100755 --- a/kirby/config/fields/date.php +++ b/kirby/config/fields/date.php @@ -7,148 +7,148 @@ use Kirby\Toolkit\I18n; use Kirby\Toolkit\Str; return [ - 'mixins' => ['datetime'], - 'props' => [ - /** - * Unset inherited props - */ - 'placeholder' => null, + 'mixins' => ['datetime'], + 'props' => [ + /** + * Unset inherited props + */ + 'placeholder' => null, - /** - * Activate/deactivate the dropdown calendar - */ - 'calendar' => function (bool $calendar = true) { - return $calendar; - }, + /** + * Activate/deactivate the dropdown calendar + */ + 'calendar' => function (bool $calendar = true) { + return $calendar; + }, - /** - * Default date when a new page/file/user gets created - */ - 'default' => function (string $default = null): string { - return $this->toDatetime($default) ?? ''; - }, + /** + * Default date when a new page/file/user gets created + */ + 'default' => function (string $default = null): string { + return $this->toDatetime($default) ?? ''; + }, - /** - * Custom format (dayjs tokens: `DD`, `MM`, `YYYY`) that is - * used to display the field in the Panel - */ - 'display' => function ($display = 'YYYY-MM-DD') { - return I18n::translate($display, $display); - }, + /** + * Custom format (dayjs tokens: `DD`, `MM`, `YYYY`) that is + * used to display the field in the Panel + */ + 'display' => function ($display = 'YYYY-MM-DD') { + return I18n::translate($display, $display); + }, - /** - * Changes the calendar icon to something custom - */ - 'icon' => function (string $icon = 'calendar') { - return $icon; - }, + /** + * Changes the calendar icon to something custom + */ + 'icon' => function (string $icon = 'calendar') { + return $icon; + }, - /** - * Latest date, which can be selected/saved (Y-m-d) - */ - 'max' => function (string $max = null): ?string { - return Date::optional($max); - }, - /** - * Earliest date, which can be selected/saved (Y-m-d) - */ - 'min' => function (string $min = null): ?string { - return Date::optional($min); - }, + /** + * Latest date, which can be selected/saved (Y-m-d) + */ + 'max' => function (string $max = null): ?string { + return Date::optional($max); + }, + /** + * Earliest date, which can be selected/saved (Y-m-d) + */ + 'min' => function (string $min = null): ?string { + return Date::optional($min); + }, - /** - * Round to the nearest: sub-options for `unit` (day) and `size` (1) - */ - 'step' => function ($step = null) { - return $step; - }, + /** + * Round to the nearest: sub-options for `unit` (day) and `size` (1) + */ + 'step' => function ($step = null) { + return $step; + }, - /** - * Pass `true` or an array of time field options to show the time selector. - */ - 'time' => function ($time = false) { - return $time; - }, - /** - * Must be a parseable date string - */ - 'value' => function ($value = null) { - return $value; - } - ], - 'computed' => [ - 'display' => function () { - if ($this->display) { - return Str::upper($this->display); - } - }, - 'format' => function () { - return $this->props['format'] ?? ($this->time === false ? 'Y-m-d' : 'Y-m-d H:i:s'); - }, - 'time' => function () { - if ($this->time === false) { - return false; - } + /** + * Pass `true` or an array of time field options to show the time selector. + */ + 'time' => function ($time = false) { + return $time; + }, + /** + * Must be a parseable date string + */ + 'value' => function ($value = null) { + return $value; + } + ], + 'computed' => [ + 'display' => function () { + if ($this->display) { + return Str::upper($this->display); + } + }, + 'format' => function () { + return $this->props['format'] ?? ($this->time === false ? 'Y-m-d' : 'Y-m-d H:i:s'); + }, + 'time' => function () { + if ($this->time === false) { + return false; + } - $props = is_array($this->time) ? $this->time : []; - $props['model'] = $this->model(); - $field = new Field('time', $props); - return $field->toArray(); - }, - 'step' => function () { - if ($this->time === false || empty($this->time['step']) === true) { - return Date::stepConfig($this->step, [ - 'size' => 1, - 'unit' => 'day' - ]); - } + $props = is_array($this->time) ? $this->time : []; + $props['model'] = $this->model(); + $field = new Field('time', $props); + return $field->toArray(); + }, + 'step' => function () { + if ($this->time === false || empty($this->time['step']) === true) { + return Date::stepConfig($this->step, [ + 'size' => 1, + 'unit' => 'day' + ]); + } - return Date::stepConfig($this->time['step'], [ - 'size' => 5, - 'unit' => 'minute' - ]); - }, - 'value' => function (): string { - return $this->toDatetime($this->value) ?? ''; - }, - ], - 'validations' => [ - 'date', - 'minMax' => function ($value) { - if (!$value = Date::optional($value)) { - return true; - } + return Date::stepConfig($this->time['step'], [ + 'size' => 5, + 'unit' => 'minute' + ]); + }, + 'value' => function (): string { + return $this->toDatetime($this->value) ?? ''; + }, + ], + 'validations' => [ + 'date', + 'minMax' => function ($value) { + if (!$value = Date::optional($value)) { + return true; + } - $min = Date::optional($this->min); - $max = Date::optional($this->max); + $min = Date::optional($this->min); + $max = Date::optional($this->max); - $format = $this->time === false ? 'd.m.Y' : 'd.m.Y H:i'; + $format = $this->time === false ? 'd.m.Y' : 'd.m.Y H:i'; - if ($min && $max && $value->isBetween($min, $max) === false) { - throw new Exception([ - 'key' => 'validation.date.between', - 'data' => [ - 'min' => $min->format($format), - 'max' => $min->format($format) - ] - ]); - } elseif ($min && $value->isMin($min) === false) { - throw new Exception([ - 'key' => 'validation.date.after', - 'data' => [ - 'date' => $min->format($format), - ] - ]); - } elseif ($max && $value->isMax($max) === false) { - throw new Exception([ - 'key' => 'validation.date.before', - 'data' => [ - 'date' => $max->format($format), - ] - ]); - } + if ($min && $max && $value->isBetween($min, $max) === false) { + throw new Exception([ + 'key' => 'validation.date.between', + 'data' => [ + 'min' => $min->format($format), + 'max' => $min->format($format) + ] + ]); + } elseif ($min && $value->isMin($min) === false) { + throw new Exception([ + 'key' => 'validation.date.after', + 'data' => [ + 'date' => $min->format($format), + ] + ]); + } elseif ($max && $value->isMax($max) === false) { + throw new Exception([ + 'key' => 'validation.date.before', + 'data' => [ + 'date' => $max->format($format), + ] + ]); + } - return true; - }, - ] + return true; + }, + ] ]; diff --git a/kirby/config/fields/email.php b/kirby/config/fields/email.php index e7892b8..5c4630f 100755 --- a/kirby/config/fields/email.php +++ b/kirby/config/fields/email.php @@ -3,38 +3,38 @@ use Kirby\Toolkit\I18n; return [ - 'extends' => 'text', - 'props' => [ - /** - * Unset inherited props - */ - 'converter' => null, - 'counter' => null, + 'extends' => 'text', + 'props' => [ + /** + * Unset inherited props + */ + 'converter' => null, + 'counter' => null, - /** - * Sets the HTML5 autocomplete mode for the input - */ - 'autocomplete' => function (string $autocomplete = 'email') { - return $autocomplete; - }, + /** + * Sets the HTML5 autocomplete mode for the input + */ + 'autocomplete' => function (string $autocomplete = 'email') { + return $autocomplete; + }, - /** - * Changes the email icon to something custom - */ - 'icon' => function (string $icon = 'email') { - return $icon; - }, + /** + * Changes the email icon to something custom + */ + 'icon' => function (string $icon = 'email') { + return $icon; + }, - /** - * Custom placeholder text, when the field is empty. - */ - 'placeholder' => function ($value = null) { - return I18n::translate($value, $value) ?? I18n::translate('email.placeholder'); - } - ], - 'validations' => [ - 'minlength', - 'maxlength', - 'email' - ] + /** + * Custom placeholder text, when the field is empty. + */ + 'placeholder' => function ($value = null) { + return I18n::translate($value, $value) ?? I18n::translate('email.placeholder'); + } + ], + 'validations' => [ + 'minlength', + 'maxlength', + 'email' + ] ]; diff --git a/kirby/config/fields/files.php b/kirby/config/fields/files.php index 10fa851..5fef3e2 100755 --- a/kirby/config/fields/files.php +++ b/kirby/config/fields/files.php @@ -4,128 +4,128 @@ use Kirby\Data\Data; use Kirby\Toolkit\A; return [ - 'mixins' => [ - 'filepicker', - 'layout', - 'min', - 'picker', - 'upload' - ], - 'props' => [ - /** - * Unset inherited props - */ - 'after' => null, - 'before' => null, - 'autofocus' => null, - 'icon' => null, - 'placeholder' => null, + 'mixins' => [ + 'filepicker', + 'layout', + 'min', + 'picker', + 'upload' + ], + 'props' => [ + /** + * Unset inherited props + */ + 'after' => null, + 'before' => null, + 'autofocus' => null, + 'icon' => null, + 'placeholder' => null, - /** - * Sets the file(s), which are selected by default when a new page is created - */ - 'default' => function ($default = null) { - return $default; - }, + /** + * Sets the file(s), which are selected by default when a new page is created + */ + 'default' => function ($default = null) { + return $default; + }, - 'value' => function ($value = null) { - return $value; - } - ], - 'computed' => [ - 'parentModel' => function () { - if (is_string($this->parent) === true && $model = $this->model()->query($this->parent, 'Kirby\Cms\Model')) { - return $model; - } + 'value' => function ($value = null) { + return $value; + } + ], + 'computed' => [ + 'parentModel' => function () { + if (is_string($this->parent) === true && $model = $this->model()->query($this->parent, 'Kirby\Cms\Model')) { + return $model; + } - return $this->model(); - }, - 'parent' => function () { - return $this->parentModel->apiUrl(true); - }, - 'query' => function () { - return $this->query ?? $this->parentModel::CLASS_ALIAS . '.files'; - }, - 'default' => function () { - return $this->toFiles($this->default); - }, - 'value' => function () { - return $this->toFiles($this->value); - }, - ], - 'methods' => [ - 'fileResponse' => function ($file) { - return $file->panel()->pickerData([ - 'image' => $this->image, - 'info' => $this->info ?? false, - 'layout' => $this->layout, - 'model' => $this->model(), - 'text' => $this->text, - ]); - }, - 'toFiles' => function ($value = null) { - $files = []; + return $this->model(); + }, + 'parent' => function () { + return $this->parentModel->apiUrl(true); + }, + 'query' => function () { + return $this->query ?? $this->parentModel::CLASS_ALIAS . '.files'; + }, + 'default' => function () { + return $this->toFiles($this->default); + }, + 'value' => function () { + return $this->toFiles($this->value); + }, + ], + 'methods' => [ + 'fileResponse' => function ($file) { + return $file->panel()->pickerData([ + 'image' => $this->image, + 'info' => $this->info ?? false, + 'layout' => $this->layout, + 'model' => $this->model(), + 'text' => $this->text, + ]); + }, + 'toFiles' => function ($value = null) { + $files = []; - foreach (Data::decode($value, 'yaml') as $id) { - if (is_array($id) === true) { - $id = $id['id'] ?? null; - } + foreach (Data::decode($value, 'yaml') as $id) { + if (is_array($id) === true) { + $id = $id['id'] ?? null; + } - if ($id !== null && ($file = $this->kirby()->file($id, $this->model()))) { - $files[] = $this->fileResponse($file); - } - } + if ($id !== null && ($file = $this->kirby()->file($id, $this->model()))) { + $files[] = $this->fileResponse($file); + } + } - return $files; - } - ], - 'api' => function () { - return [ - [ - 'pattern' => '/', - 'action' => function () { - $field = $this->field(); + return $files; + } + ], + 'api' => function () { + return [ + [ + 'pattern' => '/', + 'action' => function () { + $field = $this->field(); - return $field->filepicker([ - 'image' => $field->image(), - 'info' => $field->info(), - 'layout' => $field->layout(), - 'limit' => $field->limit(), - 'page' => $this->requestQuery('page'), - 'query' => $field->query(), - 'search' => $this->requestQuery('search'), - 'text' => $field->text() - ]); - } - ], - [ - 'pattern' => 'upload', - 'method' => 'POST', - 'action' => function () { - $field = $this->field(); - $uploads = $field->uploads(); + return $field->filepicker([ + 'image' => $field->image(), + 'info' => $field->info(), + 'layout' => $field->layout(), + 'limit' => $field->limit(), + 'page' => $this->requestQuery('page'), + 'query' => $field->query(), + 'search' => $this->requestQuery('search'), + 'text' => $field->text() + ]); + } + ], + [ + 'pattern' => 'upload', + 'method' => 'POST', + 'action' => function () { + $field = $this->field(); + $uploads = $field->uploads(); - // move_uploaded_file() not working with unit test - // @codeCoverageIgnoreStart - return $field->upload($this, $uploads, function ($file, $parent) use ($field) { - return $file->panel()->pickerData([ - 'image' => $field->image(), - 'info' => $field->info(), - 'layout' => $field->layout(), - 'model' => $field->model(), - 'text' => $field->text(), - ]); - }); - // @codeCoverageIgnoreEnd - } - ] - ]; - }, - 'save' => function ($value = null) { - return A::pluck($value, 'uuid'); - }, - 'validations' => [ - 'max', - 'min' - ] + // move_uploaded_file() not working with unit test + // @codeCoverageIgnoreStart + return $field->upload($this, $uploads, function ($file, $parent) use ($field) { + return $file->panel()->pickerData([ + 'image' => $field->image(), + 'info' => $field->info(), + 'layout' => $field->layout(), + 'model' => $field->model(), + 'text' => $field->text(), + ]); + }); + // @codeCoverageIgnoreEnd + } + ] + ]; + }, + 'save' => function ($value = null) { + return A::pluck($value, 'uuid'); + }, + 'validations' => [ + 'max', + 'min' + ] ]; diff --git a/kirby/config/fields/gap.php b/kirby/config/fields/gap.php index 6844d6c..b2dbd70 100755 --- a/kirby/config/fields/gap.php +++ b/kirby/config/fields/gap.php @@ -1,5 +1,5 @@ false + 'save' => false ]; diff --git a/kirby/config/fields/headline.php b/kirby/config/fields/headline.php index c87dd53..01994ad 100755 --- a/kirby/config/fields/headline.php +++ b/kirby/config/fields/headline.php @@ -1,26 +1,26 @@ false, - 'props' => [ - /** - * Unset inherited props - */ - 'after' => null, - 'autofocus' => null, - 'before' => null, - 'default' => null, - 'disabled' => null, - 'icon' => null, - 'placeholder' => null, - 'required' => null, - 'translate' => null, + 'save' => false, + 'props' => [ + /** + * Unset inherited props + */ + 'after' => null, + 'autofocus' => null, + 'before' => null, + 'default' => null, + 'disabled' => null, + 'icon' => null, + 'placeholder' => null, + 'required' => null, + 'translate' => null, - /** - * If `false`, the prepended number will be hidden - */ - 'numbered' => function (bool $numbered = true) { - return $numbered; - } - ] + /** + * If `false`, the prepended number will be hidden + */ + 'numbered' => function (bool $numbered = true) { + return $numbered; + } + ] ]; diff --git a/kirby/config/fields/info.php b/kirby/config/fields/info.php index dcf174b..4df8ed3 100755 --- a/kirby/config/fields/info.php +++ b/kirby/config/fields/info.php @@ -3,42 +3,42 @@ use Kirby\Toolkit\I18n; return [ - 'props' => [ - /** - * Unset inherited props - */ - 'after' => null, - 'autofocus' => null, - 'before' => null, - 'default' => null, - 'disabled' => null, - 'icon' => null, - 'placeholder' => null, - 'required' => null, - 'translate' => null, + 'props' => [ + /** + * Unset inherited props + */ + 'after' => null, + 'autofocus' => null, + 'before' => null, + 'default' => null, + 'disabled' => null, + 'icon' => null, + 'placeholder' => null, + 'required' => null, + 'translate' => null, - /** - * Text to be displayed - */ - 'text' => function ($value = null) { - return I18n::translate($value, $value); - }, + /** + * Text to be displayed + */ + 'text' => function ($value = null) { + return I18n::translate($value, $value); + }, - /** - * Change the design of the info box - */ - 'theme' => function (string $theme = null) { - return $theme; - } - ], - 'computed' => [ - 'text' => function () { - if ($text = $this->text) { - $text = $this->model()->toSafeString($text); - $text = $this->kirby()->kirbytext($text); - return $text; - } - } - ], - 'save' => false, + /** + * Change the design of the info box + */ + 'theme' => function (string $theme = null) { + return $theme; + } + ], + 'computed' => [ + 'text' => function () { + if ($text = $this->text) { + $text = $this->model()->toSafeString($text); + $text = $this->kirby()->kirbytext($text); + return $text; + } + } + ], + 'save' => false, ]; diff --git a/kirby/config/fields/line.php b/kirby/config/fields/line.php index 6844d6c..b2dbd70 100755 --- a/kirby/config/fields/line.php +++ b/kirby/config/fields/line.php @@ -1,5 +1,5 @@ false + 'save' => false ]; diff --git a/kirby/config/fields/list.php b/kirby/config/fields/list.php index c4d886f..74493a7 100755 --- a/kirby/config/fields/list.php +++ b/kirby/config/fields/list.php @@ -1,17 +1,17 @@ [ - /** - * Sets the allowed HTML formats. Available formats: `bold`, `italic`, `underline`, `strike`, `code`, `link`. Activate them all by passing `true`. Deactivate them all by passing `false` - */ - 'marks' => function ($marks = true) { - return $marks; - } - ], - 'computed' => [ - 'value' => function () { - return trim($this->value ?? ''); - } - ] + 'props' => [ + /** + * Sets the allowed HTML formats. Available formats: `bold`, `italic`, `underline`, `strike`, `code`, `link`. Activate them all by passing `true`. Deactivate them all by passing `false` + */ + 'marks' => function ($marks = true) { + return $marks; + } + ], + 'computed' => [ + 'value' => function () { + return trim($this->value ?? ''); + } + ] ]; diff --git a/kirby/config/fields/mixins/datetime.php b/kirby/config/fields/mixins/datetime.php index 8a2125f..b47a865 100755 --- a/kirby/config/fields/mixins/datetime.php +++ b/kirby/config/fields/mixins/datetime.php @@ -3,33 +3,33 @@ use Kirby\Toolkit\Date; return [ - 'props' => [ - /** - * Defines a custom format that is used when the field is saved - */ - 'format' => function (string $format = null) { - return $format; - } - ], - 'methods' => [ - 'toDatetime' => function ($value, string $format = 'Y-m-d H:i:s') { - if ($date = Date::optional($value)) { - if ($this->step) { - $step = Date::stepConfig($this->step); - $date->round($step['unit'], $step['size']); - } + 'props' => [ + /** + * Defines a custom format that is used when the field is saved + */ + 'format' => function (string $format = null) { + return $format; + } + ], + 'methods' => [ + 'toDatetime' => function ($value, string $format = 'Y-m-d H:i:s') { + if ($date = Date::optional($value)) { + if ($this->step) { + $step = Date::stepConfig($this->step); + $date->round($step['unit'], $step['size']); + } - return $date->format($format); - } + return $date->format($format); + } - return null; - } - ], - 'save' => function ($value) { - if ($date = Date::optional($value)) { - return $date->format($this->format); - } + return null; + } + ], + 'save' => function ($value) { + if ($date = Date::optional($value)) { + return $date->format($this->format); + } - return ''; - }, + return ''; + }, ]; diff --git a/kirby/config/fields/mixins/filepicker.php b/kirby/config/fields/mixins/filepicker.php index ba81230..092adc9 100755 --- a/kirby/config/fields/mixins/filepicker.php +++ b/kirby/config/fields/mixins/filepicker.php @@ -3,12 +3,12 @@ use Kirby\Cms\FilePicker; return [ - 'methods' => [ - 'filepicker' => function (array $params = []) { - // fetch the parent model - $params['model'] = $this->model(); + 'methods' => [ + 'filepicker' => function (array $params = []) { + // fetch the parent model + $params['model'] = $this->model(); - return (new FilePicker($params))->toArray(); - } - ] + return (new FilePicker($params))->toArray(); + } + ] ]; diff --git a/kirby/config/fields/mixins/layout.php b/kirby/config/fields/mixins/layout.php index 3fdb1eb..4ac0138 100755 --- a/kirby/config/fields/mixins/layout.php +++ b/kirby/config/fields/mixins/layout.php @@ -1,21 +1,21 @@ [ - /** - * Changes the layout of the selected entries. - * Available layouts: `list`, `cardlets`, `cards` - */ - 'layout' => function (string $layout = 'list') { - $layouts = ['list', 'cardlets', 'cards']; - return in_array($layout, $layouts) ? $layout : 'list'; - }, + 'props' => [ + /** + * Changes the layout of the selected entries. + * Available layouts: `list`, `cardlets`, `cards` + */ + 'layout' => function (string $layout = 'list') { + $layouts = ['list', 'cardlets', 'cards']; + return in_array($layout, $layouts) ? $layout : 'list'; + }, - /** - * Layout size for cards: `tiny`, `small`, `medium`, `large` or `huge` - */ - 'size' => function (string $size = 'auto') { - return $size; - }, - ] + /** + * Layout size for cards: `tiny`, `small`, `medium`, `large` or `huge` + */ + 'size' => function (string $size = 'auto') { + return $size; + }, + ] ]; diff --git a/kirby/config/fields/mixins/min.php b/kirby/config/fields/mixins/min.php index 33e24d4..f5262ea 100755 --- a/kirby/config/fields/mixins/min.php +++ b/kirby/config/fields/mixins/min.php @@ -1,22 +1,22 @@ [ - 'min' => function () { - // set min to at least 1, if required - if ($this->required === true) { - return $this->min ?? 1; - } + 'computed' => [ + 'min' => function () { + // set min to at least 1, if required + if ($this->required === true) { + return $this->min ?? 1; + } - return $this->min; - }, - 'required' => function () { - // set required to true if min is set - if ($this->min) { - return true; - } + return $this->min; + }, + 'required' => function () { + // set required to true if min is set + if ($this->min) { + return true; + } - return $this->required; - } - ] + return $this->required; + } + ] ]; diff --git a/kirby/config/fields/mixins/options.php b/kirby/config/fields/mixins/options.php index 170761a..465ac50 100755 --- a/kirby/config/fields/mixins/options.php +++ b/kirby/config/fields/mixins/options.php @@ -3,46 +3,46 @@ use Kirby\Form\Options; return [ - 'props' => [ - /** - * API settings for options requests. This will only take affect when `options` is set to `api`. - */ - 'api' => function ($api = null) { - return $api; - }, - /** - * An array with options - */ - 'options' => function ($options = []) { - return $options; - }, - /** - * Query settings for options queries. This will only take affect when `options` is set to `query`. - */ - 'query' => function ($query = null) { - return $query; - }, - ], - 'computed' => [ - 'options' => function (): array { - return $this->getOptions(); - } - ], - 'methods' => [ - 'getOptions' => function () { - return Options::factory( - $this->options(), - $this->props, - $this->model() - ); - }, - 'sanitizeOption' => function ($option) { - $allowed = array_column($this->options(), 'value'); - return in_array($option, $allowed, true) === true ? $option : null; - }, - 'sanitizeOptions' => function ($options) { - $allowed = array_column($this->options(), 'value'); - return array_intersect($options, $allowed); - }, - ] + 'props' => [ + /** + * API settings for options requests. This will only take affect when `options` is set to `api`. + */ + 'api' => function ($api = null) { + return $api; + }, + /** + * An array with options + */ + 'options' => function ($options = []) { + return $options; + }, + /** + * Query settings for options queries. This will only take affect when `options` is set to `query`. + */ + 'query' => function ($query = null) { + return $query; + }, + ], + 'computed' => [ + 'options' => function (): array { + return $this->getOptions(); + } + ], + 'methods' => [ + 'getOptions' => function () { + return Options::factory( + $this->options(), + $this->props, + $this->model() + ); + }, + 'sanitizeOption' => function ($option) { + $allowed = array_column($this->options(), 'value'); + return in_array($option, $allowed, true) === true ? $option : null; + }, + 'sanitizeOptions' => function ($options) { + $allowed = array_column($this->options(), 'value'); + return array_intersect($options, $allowed); + }, + ] ]; diff --git a/kirby/config/fields/mixins/pagepicker.php b/kirby/config/fields/mixins/pagepicker.php index bbdc86e..276d8c7 100755 --- a/kirby/config/fields/mixins/pagepicker.php +++ b/kirby/config/fields/mixins/pagepicker.php @@ -3,12 +3,12 @@ use Kirby\Cms\PagePicker; return [ - 'methods' => [ - 'pagepicker' => function (array $params = []) { - // inject the current model - $params['model'] = $this->model(); + 'methods' => [ + 'pagepicker' => function (array $params = []) { + // inject the current model + $params['model'] = $this->model(); - return (new PagePicker($params))->toArray(); - } - ] + return (new PagePicker($params))->toArray(); + } + ] ]; diff --git a/kirby/config/fields/mixins/picker.php b/kirby/config/fields/mixins/picker.php index c2660ad..97b4f8a 100755 --- a/kirby/config/fields/mixins/picker.php +++ b/kirby/config/fields/mixins/picker.php @@ -3,76 +3,76 @@ use Kirby\Toolkit\I18n; return [ - 'props' => [ - /** - * The placeholder text if none have been selected yet - */ - 'empty' => function ($empty = null) { - return I18n::translate($empty, $empty); - }, + 'props' => [ + /** + * The placeholder text if none have been selected yet + */ + 'empty' => function ($empty = null) { + return I18n::translate($empty, $empty); + }, - /** - * Image settings for each item - */ - 'image' => function ($image = null) { - return $image; - }, + /** + * Image settings for each item + */ + 'image' => function ($image = null) { + return $image; + }, - /** - * Info text for each item - */ - 'info' => function (string $info = null) { - return $info; - }, + /** + * Info text for each item + */ + 'info' => function (string $info = null) { + return $info; + }, - /** - * Whether each item should be clickable - */ - 'link' => function (bool $link = true) { - return $link; - }, + /** + * Whether each item should be clickable + */ + 'link' => function (bool $link = true) { + return $link; + }, - /** - * The minimum number of required selected - */ - 'min' => function (int $min = null) { - return $min; - }, + /** + * The minimum number of required selected + */ + 'min' => function (int $min = null) { + return $min; + }, - /** - * The maximum number of allowed selected - */ - 'max' => function (int $max = null) { - return $max; - }, + /** + * The maximum number of allowed selected + */ + 'max' => function (int $max = null) { + return $max; + }, - /** - * If `false`, only a single one can be selected - */ - 'multiple' => function (bool $multiple = true) { - return $multiple; - }, + /** + * If `false`, only a single one can be selected + */ + 'multiple' => function (bool $multiple = true) { + return $multiple; + }, - /** - * Query for the items to be included in the picker - */ - 'query' => function (string $query = null) { - return $query; - }, + /** + * Query for the items to be included in the picker + */ + 'query' => function (string $query = null) { + return $query; + }, - /** - * Enable/disable the search field in the picker - */ - 'search' => function (bool $search = true) { - return $search; - }, + /** + * Enable/disable the search field in the picker + */ + 'search' => function (bool $search = true) { + return $search; + }, - /** - * Main text for each item - */ - 'text' => function (string $text = null) { - return $text; - }, + /** + * Main text for each item + */ + 'text' => function (string $text = null) { + return $text; + }, - ], + ], ]; diff --git a/kirby/config/fields/mixins/upload.php b/kirby/config/fields/mixins/upload.php index 1572ae4..166aeb1 100755 --- a/kirby/config/fields/mixins/upload.php +++ b/kirby/config/fields/mixins/upload.php @@ -5,69 +5,69 @@ use Kirby\Cms\File; use Kirby\Exception\Exception; return [ - 'props' => [ - /** - * Sets the upload options for linked files (since 3.2.0) - */ - 'uploads' => function ($uploads = []) { - if ($uploads === false) { - return false; - } + 'props' => [ + /** + * Sets the upload options for linked files (since 3.2.0) + */ + 'uploads' => function ($uploads = []) { + if ($uploads === false) { + return false; + } - if (is_string($uploads) === true) { - $uploads = ['template' => $uploads]; - } + if (is_string($uploads) === true) { + $uploads = ['template' => $uploads]; + } - if (is_array($uploads) === false) { - $uploads = []; - } + if (is_array($uploads) === false) { + $uploads = []; + } - $template = $uploads['template'] ?? null; + $template = $uploads['template'] ?? null; - if ($template) { - $file = new File([ - 'filename' => 'tmp', - 'parent' => $this->model(), - 'template' => $template - ]); + if ($template) { + $file = new File([ + 'filename' => 'tmp', + 'parent' => $this->model(), + 'template' => $template + ]); - $uploads['accept'] = $file->blueprint()->acceptMime(); - } else { - $uploads['accept'] = '*'; - } + $uploads['accept'] = $file->blueprint()->acceptMime(); + } else { + $uploads['accept'] = '*'; + } - return $uploads; - }, - ], - 'methods' => [ - 'upload' => function (Api $api, $params, Closure $map) { - if ($params === false) { - throw new Exception('Uploads are disabled for this field'); - } + return $uploads; + }, + ], + 'methods' => [ + 'upload' => function (Api $api, $params, Closure $map) { + if ($params === false) { + throw new Exception('Uploads are disabled for this field'); + } - if ($parentQuery = ($params['parent'] ?? null)) { - $parent = $this->model()->query($parentQuery); - } else { - $parent = $this->model(); - } + if ($parentQuery = ($params['parent'] ?? null)) { + $parent = $this->model()->query($parentQuery); + } else { + $parent = $this->model(); + } - if (is_a($parent, 'Kirby\Cms\File') === true) { - $parent = $parent->parent(); - } + if (is_a($parent, 'Kirby\Cms\File') === true) { + $parent = $parent->parent(); + } - return $api->upload(function ($source, $filename) use ($parent, $params, $map) { - $file = $parent->createFile([ - 'source' => $source, - 'template' => $params['template'] ?? null, - 'filename' => $filename, - ]); + return $api->upload(function ($source, $filename) use ($parent, $params, $map) { + $file = $parent->createFile([ + 'source' => $source, + 'template' => $params['template'] ?? null, + 'filename' => $filename, + ]); - if (is_a($file, 'Kirby\Cms\File') === false) { - throw new Exception('The file could not be uploaded'); - } + if (is_a($file, 'Kirby\Cms\File') === false) { + throw new Exception('The file could not be uploaded'); + } - return $map($file, $parent); - }); - } - ] + return $map($file, $parent); + }); + } + ] ]; diff --git a/kirby/config/fields/mixins/userpicker.php b/kirby/config/fields/mixins/userpicker.php index 41c2b62..4f8556c 100755 --- a/kirby/config/fields/mixins/userpicker.php +++ b/kirby/config/fields/mixins/userpicker.php @@ -3,11 +3,11 @@ use Kirby\Cms\UserPicker; return [ - 'methods' => [ - 'userpicker' => function (array $params = []) { - $params['model'] = $this->model(); + 'methods' => [ + 'userpicker' => function (array $params = []) { + $params['model'] = $this->model(); - return (new UserPicker($params))->toArray(); - } - ] + return (new UserPicker($params))->toArray(); + } + ] ]; diff --git a/kirby/config/fields/multiselect.php b/kirby/config/fields/multiselect.php index 4ed2422..37ab356 100755 --- a/kirby/config/fields/multiselect.php +++ b/kirby/config/fields/multiselect.php @@ -1,32 +1,32 @@ 'tags', - 'props' => [ - /** - * Unset inherited props - */ - 'accept' => null, - /** - * Custom icon to replace the arrow down. - */ - 'icon' => function (string $icon = null) { - return $icon; - }, - /** - * Enable/disable the search in the dropdown - * Also limit displayed items (display: 20) - * and set minimum number of characters to search (min: 3) - */ - 'search' => function ($search = true) { - return $search; - }, - /** - * If `true`, selected entries will be sorted - * according to their position in the dropdown - */ - 'sort' => function (bool $sort = false) { - return $sort; - }, - ] + 'extends' => 'tags', + 'props' => [ + /** + * Unset inherited props + */ + 'accept' => null, + /** + * Custom icon to replace the arrow down. + */ + 'icon' => function (string $icon = null) { + return $icon; + }, + /** + * Enable/disable the search in the dropdown + * Also limit displayed items (display: 20) + * and set minimum number of characters to search (min: 3) + */ + 'search' => function ($search = true) { + return $search; + }, + /** + * If `true`, selected entries will be sorted + * according to their position in the dropdown + */ + 'sort' => function (bool $sort = false) { + return $sort; + }, + ] ]; diff --git a/kirby/config/fields/number.php b/kirby/config/fields/number.php index 92a23ee..62470ed 100755 --- a/kirby/config/fields/number.php +++ b/kirby/config/fields/number.php @@ -3,46 +3,46 @@ use Kirby\Toolkit\Str; return [ - 'props' => [ - /** - * Default number that will be saved when a new page/user/file is created - */ - 'default' => function ($default = null) { - return $this->toNumber($default); - }, - /** - * The lowest allowed number - */ - 'min' => function (float $min = null) { - return $min; - }, - /** - * The highest allowed number - */ - 'max' => function (float $max = null) { - return $max; - }, - /** - * Allowed incremental steps between numbers (i.e `0.5`) - */ - 'step' => function ($step = null) { - return $this->toNumber($step); - }, - 'value' => function ($value = null) { - return $this->toNumber($value); - } - ], - 'methods' => [ - 'toNumber' => function ($value) { - if ($this->isEmpty($value) === true) { - return null; - } + 'props' => [ + /** + * Default number that will be saved when a new page/user/file is created + */ + 'default' => function ($default = null) { + return $this->toNumber($default); + }, + /** + * The lowest allowed number + */ + 'min' => function (float $min = null) { + return $min; + }, + /** + * The highest allowed number + */ + 'max' => function (float $max = null) { + return $max; + }, + /** + * Allowed incremental steps between numbers (i.e `0.5`) + */ + 'step' => function ($step = null) { + return $this->toNumber($step); + }, + 'value' => function ($value = null) { + return $this->toNumber($value); + } + ], + 'methods' => [ + 'toNumber' => function ($value) { + if ($this->isEmpty($value) === true) { + return null; + } - return is_float($value) === true ? $value : (float)Str::float($value); - } - ], - 'validations' => [ - 'min', - 'max' - ] + return is_float($value) === true ? $value : (float)Str::float($value); + } + ], + 'validations' => [ + 'min', + 'max' + ] ]; diff --git a/kirby/config/fields/pages.php b/kirby/config/fields/pages.php index 3f42c4b..8eaa70d 100755 --- a/kirby/config/fields/pages.php +++ b/kirby/config/fields/pages.php @@ -5,107 +5,107 @@ use Kirby\Data\Data; use Kirby\Toolkit\A; return [ - 'mixins' => [ - 'layout', - 'min', - 'pagepicker', - 'picker', - ], - 'props' => [ - /** - * Unset inherited props - */ - 'after' => null, - 'autofocus' => null, - 'before' => null, - 'icon' => null, - 'placeholder' => null, + 'mixins' => [ + 'layout', + 'min', + 'pagepicker', + 'picker', + ], + 'props' => [ + /** + * Unset inherited props + */ + 'after' => null, + 'autofocus' => null, + 'before' => null, + 'icon' => null, + 'placeholder' => null, - /** - * Default selected page(s) when a new page/file/user is created - */ - 'default' => function ($default = null) { - return $this->toPages($default); - }, + /** + * Default selected page(s) when a new page/file/user is created + */ + 'default' => function ($default = null) { + return $this->toPages($default); + }, - /** - * Optional query to select a specific set of pages - */ - 'query' => function (string $query = null) { - return $query; - }, + /** + * Optional query to select a specific set of pages + */ + 'query' => function (string $query = null) { + return $query; + }, - /** - * Optionally include subpages of pages - */ - 'subpages' => function (bool $subpages = true) { - return $subpages; - }, + /** + * Optionally include subpages of pages + */ + 'subpages' => function (bool $subpages = true) { + return $subpages; + }, - 'value' => function ($value = null) { - return $this->toPages($value); - }, - ], - 'computed' => [ - /** - * Unset inherited computed - */ - 'default' => null - ], - 'methods' => [ - 'pageResponse' => function ($page) { - return $page->panel()->pickerData([ - 'image' => $this->image, - 'info' => $this->info, - 'layout' => $this->layout, - 'text' => $this->text, - ]); - }, - 'toPages' => function ($value = null) { - $pages = []; - $kirby = App::instance(); + 'value' => function ($value = null) { + return $this->toPages($value); + }, + ], + 'computed' => [ + /** + * Unset inherited computed + */ + 'default' => null + ], + 'methods' => [ + 'pageResponse' => function ($page) { + return $page->panel()->pickerData([ + 'image' => $this->image, + 'info' => $this->info, + 'layout' => $this->layout, + 'text' => $this->text, + ]); + }, + 'toPages' => function ($value = null) { + $pages = []; + $kirby = App::instance(); - foreach (Data::decode($value, 'yaml') as $id) { - if (is_array($id) === true) { - $id = $id['id'] ?? null; - } + foreach (Data::decode($value, 'yaml') as $id) { + if (is_array($id) === true) { + $id = $id['id'] ?? null; + } - if ($id !== null && ($page = $kirby->page($id))) { - $pages[] = $this->pageResponse($page); - } - } + if ($id !== null && ($page = $kirby->page($id))) { + $pages[] = $this->pageResponse($page); + } + } - return $pages; - } - ], - 'api' => function () { - return [ - [ - 'pattern' => '/', - 'action' => function () { - $field = $this->field(); + return $pages; + } + ], + 'api' => function () { + return [ + [ + 'pattern' => '/', + 'action' => function () { + $field = $this->field(); - return $field->pagepicker([ - 'image' => $field->image(), - 'info' => $field->info(), - 'layout' => $field->layout(), - 'limit' => $field->limit(), - 'page' => $this->requestQuery('page'), - 'parent' => $this->requestQuery('parent'), - 'query' => $field->query(), - 'search' => $this->requestQuery('search'), - 'subpages' => $field->subpages(), - 'text' => $field->text() - ]); - } - ] - ]; - }, - 'save' => function ($value = null) { - return A::pluck($value, 'id'); - }, - 'validations' => [ - 'max', - 'min' - ] + return $field->pagepicker([ + 'image' => $field->image(), + 'info' => $field->info(), + 'layout' => $field->layout(), + 'limit' => $field->limit(), + 'page' => $this->requestQuery('page'), + 'parent' => $this->requestQuery('parent'), + 'query' => $field->query(), + 'search' => $this->requestQuery('search'), + 'subpages' => $field->subpages(), + 'text' => $field->text() + ]); + } + ] + ]; + }, + 'save' => function ($value = null) { + return A::pluck($value, 'id'); + }, + 'validations' => [ + 'max', + 'min' + ] ]; diff --git a/kirby/config/fields/radio.php b/kirby/config/fields/radio.php index dd9ffc3..4846053 100755 --- a/kirby/config/fields/radio.php +++ b/kirby/config/fields/radio.php @@ -1,29 +1,29 @@ ['options'], - 'props' => [ - /** - * Unset inherited props - */ - 'after' => null, - 'before' => null, - 'icon' => null, - 'placeholder' => null, + 'mixins' => ['options'], + 'props' => [ + /** + * Unset inherited props + */ + 'after' => null, + 'before' => null, + 'icon' => null, + 'placeholder' => null, - /** - * Arranges the radio buttons in the given number of columns - */ - 'columns' => function (int $columns = 1) { - return $columns; - }, - ], - 'computed' => [ - 'default' => function () { - return $this->sanitizeOption($this->default); - }, - 'value' => function () { - return $this->sanitizeOption($this->value) ?? ''; - } - ] + /** + * Arranges the radio buttons in the given number of columns + */ + 'columns' => function (int $columns = 1) { + return $columns; + }, + ], + 'computed' => [ + 'default' => function () { + return $this->sanitizeOption($this->default); + }, + 'value' => function () { + return $this->sanitizeOption($this->value) ?? ''; + } + ] ]; diff --git a/kirby/config/fields/range.php b/kirby/config/fields/range.php index 5f14388..04221f1 100755 --- a/kirby/config/fields/range.php +++ b/kirby/config/fields/range.php @@ -1,24 +1,24 @@ 'number', - 'props' => [ - /** - * Unset inherited props - */ - 'placeholder' => null, + 'extends' => 'number', + 'props' => [ + /** + * Unset inherited props + */ + 'placeholder' => null, - /** - * The maximum value on the slider - */ - 'max' => function (float $max = 100) { - return $max; - }, - /** - * Enables/disables the tooltip and set the before and after values - */ - 'tooltip' => function ($tooltip = true) { - return $tooltip; - }, - ] + /** + * The maximum value on the slider + */ + 'max' => function (float $max = 100) { + return $max; + }, + /** + * Enables/disables the tooltip and set the before and after values + */ + 'tooltip' => function ($tooltip = true) { + return $tooltip; + }, + ] ]; diff --git a/kirby/config/fields/select.php b/kirby/config/fields/select.php index 24b14b6..04b468d 100755 --- a/kirby/config/fields/select.php +++ b/kirby/config/fields/select.php @@ -1,24 +1,24 @@ 'radio', - 'props' => [ - /** - * Unset inherited props - */ - 'columns' => null, + 'extends' => 'radio', + 'props' => [ + /** + * Unset inherited props + */ + 'columns' => null, - /** - * Custom icon to replace the arrow down. - */ - 'icon' => function (string $icon = null) { - return $icon; - }, - /** - * Custom placeholder string for empty option. - */ - 'placeholder' => function (string $placeholder = '—') { - return $placeholder; - }, - ] + /** + * Custom icon to replace the arrow down. + */ + 'icon' => function (string $icon = null) { + return $icon; + }, + /** + * Custom placeholder string for empty option. + */ + 'placeholder' => function (string $placeholder = '—') { + return $placeholder; + }, + ] ]; diff --git a/kirby/config/fields/slug.php b/kirby/config/fields/slug.php index d927415..9d8efb5 100755 --- a/kirby/config/fields/slug.php +++ b/kirby/config/fields/slug.php @@ -2,54 +2,54 @@ return [ - 'extends' => 'text', - 'props' => [ - /** - * Unset inherited props - */ - 'converter' => null, - 'counter' => null, - 'spellcheck' => null, + 'extends' => 'text', + 'props' => [ + /** + * Unset inherited props + */ + 'converter' => null, + 'counter' => null, + 'spellcheck' => null, - /** - * Set of characters allowed in the slug - */ - 'allow' => function (string $allow = '') { - return $allow; - }, + /** + * Set of characters allowed in the slug + */ + 'allow' => function (string $allow = '') { + return $allow; + }, - /** - * Changes the link icon - */ - 'icon' => function (string $icon = 'url') { - return $icon; - }, + /** + * Changes the link icon + */ + 'icon' => function (string $icon = 'url') { + return $icon; + }, - /** - * Set prefix for the help text - */ - 'path' => function (string $path = null) { - return $path; - }, + /** + * Set prefix for the help text + */ + 'path' => function (string $path = null) { + return $path; + }, - /** - * Name of another field that should be used to - * automatically update this field's value - */ - 'sync' => function (string $sync = null) { - return $sync; - }, + /** + * Name of another field that should be used to + * automatically update this field's value + */ + 'sync' => function (string $sync = null) { + return $sync; + }, - /** - * Set to object with keys `field` and `text` to add - * button to generate from another field - */ - 'wizard' => function ($wizard = false) { - return $wizard; - } - ], - 'validations' => [ - 'minlength', - 'maxlength' - ], + /** + * Set to object with keys `field` and `text` to add + * button to generate from another field + */ + 'wizard' => function ($wizard = false) { + return $wizard; + } + ], + 'validations' => [ + 'minlength', + 'maxlength' + ], ]; diff --git a/kirby/config/fields/structure.php b/kirby/config/fields/structure.php index f26b9ac..48b2841 100755 --- a/kirby/config/fields/structure.php +++ b/kirby/config/fields/structure.php @@ -5,200 +5,200 @@ use Kirby\Form\Form; use Kirby\Toolkit\I18n; return [ - 'mixins' => ['min'], - 'props' => [ - /** - * Unset inherited props - */ - 'after' => null, - 'before' => null, - 'autofocus' => null, - 'icon' => null, - 'placeholder' => null, + 'mixins' => ['min'], + 'props' => [ + /** + * Unset inherited props + */ + 'after' => null, + 'before' => null, + 'autofocus' => null, + 'icon' => null, + 'placeholder' => null, - /** - * Optional columns definition to only show selected fields in the structure table. - */ - 'columns' => function (array $columns = []) { - // lower case all keys, because field names will - // be lowercase as well. - return array_change_key_case($columns); - }, + /** + * Optional columns definition to only show selected fields in the structure table. + */ + 'columns' => function (array $columns = []) { + // lower case all keys, because field names will + // be lowercase as well. + return array_change_key_case($columns); + }, - /** - * Toggles duplicating rows for the structure - */ - 'duplicate' => function (bool $duplicate = true) { - return $duplicate; - }, + /** + * Toggles duplicating rows for the structure + */ + 'duplicate' => function (bool $duplicate = true) { + return $duplicate; + }, - /** - * The placeholder text if no items have been added yet - */ - 'empty' => function ($empty = null) { - return I18n::translate($empty, $empty); - }, + /** + * The placeholder text if no items have been added yet + */ + 'empty' => function ($empty = null) { + return I18n::translate($empty, $empty); + }, - /** - * Set the default rows for the structure - */ - 'default' => function (array $default = null) { - return $default; - }, + /** + * Set the default rows for the structure + */ + 'default' => function (array $default = null) { + return $default; + }, - /** - * Fields setup for the structure form. Works just like fields in regular forms. - */ - 'fields' => function (array $fields) { - return $fields; - }, - /** - * The number of entries that will be displayed on a single page. Afterwards pagination kicks in. - */ - 'limit' => function (int $limit = null) { - return $limit; - }, - /** - * Maximum allowed entries in the structure. Afterwards the "Add" button will be switched off. - */ - 'max' => function (int $max = null) { - return $max; - }, - /** - * Minimum required entries in the structure - */ - 'min' => function (int $min = null) { - return $min; - }, - /** - * Toggles adding to the top or bottom of the list - */ - 'prepend' => function (bool $prepend = null) { - return $prepend; - }, - /** - * Toggles drag & drop sorting - */ - 'sortable' => function (bool $sortable = null) { - return $sortable; - }, - /** - * Sorts the entries by the given field and order (i.e. `title desc`) - * Drag & drop is disabled in this case - */ - 'sortBy' => function (string $sort = null) { - return $sort; - } - ], - 'computed' => [ - 'default' => function () { - return $this->rows($this->default); - }, - 'value' => function () { - return $this->rows($this->value); - }, - 'fields' => function () { - if (empty($this->fields) === true) { - throw new Exception('Please provide some fields for the structure'); - } + /** + * Fields setup for the structure form. Works just like fields in regular forms. + */ + 'fields' => function (array $fields) { + return $fields; + }, + /** + * The number of entries that will be displayed on a single page. Afterwards pagination kicks in. + */ + 'limit' => function (int $limit = null) { + return $limit; + }, + /** + * Maximum allowed entries in the structure. Afterwards the "Add" button will be switched off. + */ + 'max' => function (int $max = null) { + return $max; + }, + /** + * Minimum required entries in the structure + */ + 'min' => function (int $min = null) { + return $min; + }, + /** + * Toggles adding to the top or bottom of the list + */ + 'prepend' => function (bool $prepend = null) { + return $prepend; + }, + /** + * Toggles drag & drop sorting + */ + 'sortable' => function (bool $sortable = null) { + return $sortable; + }, + /** + * Sorts the entries by the given field and order (i.e. `title desc`) + * Drag & drop is disabled in this case + */ + 'sortBy' => function (string $sort = null) { + return $sort; + } + ], + 'computed' => [ + 'default' => function () { + return $this->rows($this->default); + }, + 'value' => function () { + return $this->rows($this->value); + }, + 'fields' => function () { + if (empty($this->fields) === true) { + throw new Exception('Please provide some fields for the structure'); + } - return $this->form()->fields()->toArray(); - }, - 'columns' => function () { - $columns = []; - $mobile = 0; + return $this->form()->fields()->toArray(); + }, + 'columns' => function () { + $columns = []; + $mobile = 0; - if (empty($this->columns)) { - foreach ($this->fields as $field) { + if (empty($this->columns)) { + foreach ($this->fields as $field) { - // Skip hidden and unsaveable fields - // They should never be included as column - if ($field['type'] === 'hidden' || $field['saveable'] === false) { - continue; - } + // Skip hidden and unsaveable fields + // They should never be included as column + if ($field['type'] === 'hidden' || $field['saveable'] === false) { + continue; + } - $columns[$field['name']] = [ - 'type' => $field['type'], - 'label' => $field['label'] ?? $field['name'] - ]; - } - } else { - foreach ($this->columns as $columnName => $columnProps) { - if (is_array($columnProps) === false) { - $columnProps = []; - } + $columns[$field['name']] = [ + 'type' => $field['type'], + 'label' => $field['label'] ?? $field['name'] + ]; + } + } else { + foreach ($this->columns as $columnName => $columnProps) { + if (is_array($columnProps) === false) { + $columnProps = []; + } - $field = $this->fields[$columnName] ?? null; + $field = $this->fields[$columnName] ?? null; - if (empty($field) === true || $field['saveable'] === false) { - continue; - } + if (empty($field) === true || $field['saveable'] === false) { + continue; + } - if (($columnProps['mobile'] ?? false) === true) { - $mobile++; - } + if (($columnProps['mobile'] ?? false) === true) { + $mobile++; + } - $columns[$columnName] = array_merge($columnProps, [ - 'type' => $field['type'], - 'label' => $field['label'] ?? $field['name'] - ]); - } - } + $columns[$columnName] = array_merge($columnProps, [ + 'type' => $field['type'], + 'label' => $field['label'] ?? $field['name'] + ]); + } + } - // make the first column visible on mobile - // if no other mobile columns are defined - if ($mobile === 0) { - $columns[array_key_first($columns)]['mobile'] = true; - } + // make the first column visible on mobile + // if no other mobile columns are defined + if ($mobile === 0) { + $columns[array_key_first($columns)]['mobile'] = true; + } - return $columns; - } - ], - 'methods' => [ - 'rows' => function ($value) { - $rows = Data::decode($value, 'yaml'); - $value = []; + return $columns; + } + ], + 'methods' => [ + 'rows' => function ($value) { + $rows = Data::decode($value, 'yaml'); + $value = []; - foreach ($rows as $index => $row) { - if (is_array($row) === false) { - continue; - } + foreach ($rows as $index => $row) { + if (is_array($row) === false) { + continue; + } - $value[] = $this->form($row)->values(); - } + $value[] = $this->form($row)->values(); + } - return $value; - }, - 'form' => function (array $values = []) { - return new Form([ - 'fields' => $this->attrs['fields'], - 'values' => $values, - 'model' => $this->model - ]); - }, - ], - 'api' => function () { - return [ - [ - 'pattern' => 'validate', - 'method' => 'ALL', - 'action' => function () { - return array_values($this->field()->form($this->requestBody())->errors()); - } - ] - ]; - }, - 'save' => function ($value) { - $data = []; + return $value; + }, + 'form' => function (array $values = []) { + return new Form([ + 'fields' => $this->attrs['fields'], + 'values' => $values, + 'model' => $this->model + ]); + }, + ], + 'api' => function () { + return [ + [ + 'pattern' => 'validate', + 'method' => 'ALL', + 'action' => function () { + return array_values($this->field()->form($this->requestBody())->errors()); + } + ] + ]; + }, + 'save' => function ($value) { + $data = []; - foreach ($value as $row) { - $data[] = $this->form($row)->content(); - } + foreach ($value as $row) { + $data[] = $this->form($row)->content(); + } - return $data; - }, - 'validations' => [ - 'min', - 'max' - ] + return $data; + }, + 'validations' => [ + 'min', + 'max' + ] ]; diff --git a/kirby/config/fields/tags.php b/kirby/config/fields/tags.php index 5cfd4f4..98cfbb4 100755 --- a/kirby/config/fields/tags.php +++ b/kirby/config/fields/tags.php @@ -5,99 +5,99 @@ use Kirby\Toolkit\Str; use Kirby\Toolkit\V; return [ - 'mixins' => ['min', 'options'], - 'props' => [ + 'mixins' => ['min', 'options'], + 'props' => [ - /** - * Unset inherited props - */ - 'after' => null, - 'before' => null, - 'placeholder' => null, + /** + * Unset inherited props + */ + 'after' => null, + 'before' => null, + 'placeholder' => null, - /** - * If set to `all`, any type of input is accepted. If set to `options` only the predefined options are accepted as input. - */ - 'accept' => function ($value = 'all') { - return V::in($value, ['all', 'options']) ? $value : 'all'; - }, - /** - * Changes the tag icon - */ - 'icon' => function ($icon = 'tag') { - return $icon; - }, - /** - * Set to `list` to display each tag with 100% width, - * otherwise the tags are displayed inline - */ - 'layout' => function (?string $layout = null) { - return $layout; - }, - /** - * Minimum number of required entries/tags - */ - 'min' => function (int $min = null) { - return $min; - }, - /** - * Maximum number of allowed entries/tags - */ - 'max' => function (int $max = null) { - return $max; - }, - /** - * Custom tags separator, which will be used to store tags in the content file - */ - 'separator' => function (string $separator = ',') { - return $separator; - }, - ], - 'computed' => [ - 'default' => function (): array { - return $this->toTags($this->default); - }, - 'value' => function (): array { - return $this->toTags($this->value); - } - ], - 'methods' => [ - 'toTags' => function ($value) { - if (is_null($value) === true) { - return []; - } + /** + * If set to `all`, any type of input is accepted. If set to `options` only the predefined options are accepted as input. + */ + 'accept' => function ($value = 'all') { + return V::in($value, ['all', 'options']) ? $value : 'all'; + }, + /** + * Changes the tag icon + */ + 'icon' => function ($icon = 'tag') { + return $icon; + }, + /** + * Set to `list` to display each tag with 100% width, + * otherwise the tags are displayed inline + */ + 'layout' => function (?string $layout = null) { + return $layout; + }, + /** + * Minimum number of required entries/tags + */ + 'min' => function (int $min = null) { + return $min; + }, + /** + * Maximum number of allowed entries/tags + */ + 'max' => function (int $max = null) { + return $max; + }, + /** + * Custom tags separator, which will be used to store tags in the content file + */ + 'separator' => function (string $separator = ',') { + return $separator; + }, + ], + 'computed' => [ + 'default' => function (): array { + return $this->toTags($this->default); + }, + 'value' => function (): array { + return $this->toTags($this->value); + } + ], + 'methods' => [ + 'toTags' => function ($value) { + if (is_null($value) === true) { + return []; + } - $options = $this->options(); + $options = $this->options(); - // transform into value-text objects - return array_map(function ($option) use ($options) { + // transform into value-text objects + return array_map(function ($option) use ($options) { - // already a valid object - if (is_array($option) === true && isset($option['value'], $option['text']) === true) { - return $option; - } + // already a valid object + if (is_array($option) === true && isset($option['value'], $option['text']) === true) { + return $option; + } - $index = array_search($option, array_column($options, 'value')); + $index = array_search($option, array_column($options, 'value')); - if ($index !== false) { - return $options[$index]; - } + if ($index !== false) { + return $options[$index]; + } - return [ - 'value' => $option, - 'text' => $option, - ]; - }, Str::split($value, $this->separator())); - } - ], - 'save' => function (array $value = null): string { - return A::join( - A::pluck($value, 'value'), - $this->separator() . ' ' - ); - }, - 'validations' => [ - 'min', - 'max' - ] + return [ + 'value' => $option, + 'text' => $option, + ]; + }, Str::split($value, $this->separator())); + } + ], + 'save' => function (array $value = null): string { + return A::join( + A::pluck($value, 'value'), + $this->separator() . ' ' + ); + }, + 'validations' => [ + 'min', + 'max' + ] ]; diff --git a/kirby/config/fields/tel.php b/kirby/config/fields/tel.php index 3d73430..715d587 100755 --- a/kirby/config/fields/tel.php +++ b/kirby/config/fields/tel.php @@ -1,27 +1,27 @@ 'text', - 'props' => [ - /** - * Unset inherited props - */ - 'converter' => null, - 'counter' => null, - 'spellcheck' => null, + 'extends' => 'text', + 'props' => [ + /** + * Unset inherited props + */ + 'converter' => null, + 'counter' => null, + 'spellcheck' => null, - /** - * Sets the HTML5 autocomplete attribute - */ - 'autocomplete' => function (string $autocomplete = 'tel') { - return $autocomplete; - }, + /** + * Sets the HTML5 autocomplete attribute + */ + 'autocomplete' => function (string $autocomplete = 'tel') { + return $autocomplete; + }, - /** - * Changes the phone icon - */ - 'icon' => function (string $icon = 'phone') { - return $icon; - } - ] + /** + * Changes the phone icon + */ + 'icon' => function (string $icon = 'phone') { + return $icon; + } + ] ]; diff --git a/kirby/config/fields/text.php b/kirby/config/fields/text.php index bc13bd1..7abd86f 100755 --- a/kirby/config/fields/text.php +++ b/kirby/config/fields/text.php @@ -4,99 +4,99 @@ use Kirby\Exception\InvalidArgumentException; use Kirby\Toolkit\Str; return [ - 'props' => [ + 'props' => [ - /** - * The field value will be converted with the selected converter before the value gets saved. Available converters: `lower`, `upper`, `ucfirst`, `slug` - */ - 'converter' => function ($value = null) { - if ($value !== null && in_array($value, array_keys($this->converters())) === false) { - throw new InvalidArgumentException([ - 'key' => 'field.converter.invalid', - 'data' => ['converter' => $value] - ]); - } + /** + * The field value will be converted with the selected converter before the value gets saved. Available converters: `lower`, `upper`, `ucfirst`, `slug` + */ + 'converter' => function ($value = null) { + if ($value !== null && in_array($value, array_keys($this->converters())) === false) { + throw new InvalidArgumentException([ + 'key' => 'field.converter.invalid', + 'data' => ['converter' => $value] + ]); + } - return $value; - }, + return $value; + }, - /** - * Shows or hides the character counter in the top right corner - */ - 'counter' => function (bool $counter = true) { - return $counter; - }, + /** + * Shows or hides the character counter in the top right corner + */ + 'counter' => function (bool $counter = true) { + return $counter; + }, - /** - * Maximum number of allowed characters - */ - 'maxlength' => function (int $maxlength = null) { - return $maxlength; - }, + /** + * Maximum number of allowed characters + */ + 'maxlength' => function (int $maxlength = null) { + return $maxlength; + }, - /** - * Minimum number of required characters - */ - 'minlength' => function (int $minlength = null) { - return $minlength; - }, + /** + * Minimum number of required characters + */ + 'minlength' => function (int $minlength = null) { + return $minlength; + }, - /** - * A regular expression, which will be used to validate the input - */ - 'pattern' => function (string $pattern = null) { - return $pattern; - }, + /** + * A regular expression, which will be used to validate the input + */ + 'pattern' => function (string $pattern = null) { + return $pattern; + }, - /** - * If `false`, spellcheck will be switched off - */ - 'spellcheck' => function (bool $spellcheck = false) { - return $spellcheck; - }, - ], - 'computed' => [ - 'default' => function () { - return $this->convert($this->default); - }, - 'value' => function () { - return (string)$this->convert($this->value); - } - ], - 'methods' => [ - 'convert' => function ($value) { - if ($this->converter() === null) { - return $value; - } + /** + * If `false`, spellcheck will be switched off + */ + 'spellcheck' => function (bool $spellcheck = false) { + return $spellcheck; + }, + ], + 'computed' => [ + 'default' => function () { + return $this->convert($this->default); + }, + 'value' => function () { + return (string)$this->convert($this->value); + } + ], + 'methods' => [ + 'convert' => function ($value) { + if ($this->converter() === null) { + return $value; + } - $converter = $this->converters()[$this->converter()]; + $converter = $this->converters()[$this->converter()]; - if (is_array($value) === true) { - return array_map($converter, $value); - } + if (is_array($value) === true) { + return array_map($converter, $value); + } - return call_user_func($converter, trim($value ?? '')); - }, - 'converters' => function (): array { - return [ - 'lower' => function ($value) { - return Str::lower($value); - }, - 'slug' => function ($value) { - return Str::slug($value); - }, - 'ucfirst' => function ($value) { - return Str::ucfirst($value); - }, - 'upper' => function ($value) { - return Str::upper($value); - }, - ]; - }, - ], - 'validations' => [ - 'minlength', - 'maxlength', - 'pattern' - ] + return call_user_func($converter, trim($value ?? '')); + }, + 'converters' => function (): array { + return [ + 'lower' => function ($value) { + return Str::lower($value); + }, + 'slug' => function ($value) { + return Str::slug($value); + }, + 'ucfirst' => function ($value) { + return Str::ucfirst($value); + }, + 'upper' => function ($value) { + return Str::upper($value); + }, + ]; + }, + ], + 'validations' => [ + 'minlength', + 'maxlength', + 'pattern' + ] ]; diff --git a/kirby/config/fields/textarea.php b/kirby/config/fields/textarea.php index aaf2962..7b51c1f 100755 --- a/kirby/config/fields/textarea.php +++ b/kirby/config/fields/textarea.php @@ -1,123 +1,123 @@ ['filepicker', 'upload'], - 'props' => [ - /** - * Unset inherited props - */ - 'after' => null, - 'before' => null, + 'mixins' => ['filepicker', 'upload'], + 'props' => [ + /** + * Unset inherited props + */ + 'after' => null, + 'before' => null, - /** - * Enables/disables the format buttons. Can either be `true`/`false` or a list of allowed buttons. Available buttons: `headlines`, `italic`, `bold`, `link`, `email`, `file`, `code`, `ul`, `ol` (as well as `|` for a divider) - */ - 'buttons' => function ($buttons = true) { - return $buttons; - }, + /** + * Enables/disables the format buttons. Can either be `true`/`false` or a list of allowed buttons. Available buttons: `headlines`, `italic`, `bold`, `link`, `email`, `file`, `code`, `ul`, `ol` (as well as `|` for a divider) + */ + 'buttons' => function ($buttons = true) { + return $buttons; + }, - /** - * Enables/disables the character counter in the top right corner - */ - 'counter' => function (bool $counter = true) { - return $counter; - }, + /** + * Enables/disables the character counter in the top right corner + */ + 'counter' => function (bool $counter = true) { + return $counter; + }, - /** - * Sets the default text when a new page/file/user is created - */ - 'default' => function (string $default = null) { - return trim($default ?? ''); - }, + /** + * Sets the default text when a new page/file/user is created + */ + 'default' => function (string $default = null) { + return trim($default ?? ''); + }, - /** - * Sets the options for the files picker - */ - 'files' => function ($files = []) { - if (is_string($files) === true) { - return ['query' => $files]; - } + /** + * Sets the options for the files picker + */ + 'files' => function ($files = []) { + if (is_string($files) === true) { + return ['query' => $files]; + } - if (is_array($files) === false) { - $files = []; - } + if (is_array($files) === false) { + $files = []; + } - return $files; - }, + return $files; + }, - /** - * Sets the font family (sans or monospace) - */ - 'font' => function (string $font = null) { - return $font === 'monospace' ? 'monospace' : 'sans-serif'; - }, + /** + * Sets the font family (sans or monospace) + */ + 'font' => function (string $font = null) { + return $font === 'monospace' ? 'monospace' : 'sans-serif'; + }, - /** - * Maximum number of allowed characters - */ - 'maxlength' => function (int $maxlength = null) { - return $maxlength; - }, + /** + * Maximum number of allowed characters + */ + 'maxlength' => function (int $maxlength = null) { + return $maxlength; + }, - /** - * Minimum number of required characters - */ - 'minlength' => function (int $minlength = null) { - return $minlength; - }, + /** + * Minimum number of required characters + */ + 'minlength' => function (int $minlength = null) { + return $minlength; + }, - /** - * Changes the size of the textarea. Available sizes: `small`, `medium`, `large`, `huge` - */ - 'size' => function (string $size = null) { - return $size; - }, + /** + * Changes the size of the textarea. Available sizes: `small`, `medium`, `large`, `huge` + */ + 'size' => function (string $size = null) { + return $size; + }, - /** - * If `false`, spellcheck will be switched off - */ - 'spellcheck' => function (bool $spellcheck = true) { - return $spellcheck; - }, + /** + * If `false`, spellcheck will be switched off + */ + 'spellcheck' => function (bool $spellcheck = true) { + return $spellcheck; + }, - 'value' => function (string $value = null) { - return trim($value ?? ''); - } - ], - 'api' => function () { - return [ - [ - 'pattern' => 'files', - 'action' => function () { - $params = array_merge($this->field()->files(), [ - 'page' => $this->requestQuery('page'), - 'search' => $this->requestQuery('search') - ]); + 'value' => function (string $value = null) { + return trim($value ?? ''); + } + ], + 'api' => function () { + return [ + [ + 'pattern' => 'files', + 'action' => function () { + $params = array_merge($this->field()->files(), [ + 'page' => $this->requestQuery('page'), + 'search' => $this->requestQuery('search') + ]); - return $this->field()->filepicker($params); - } - ], - [ - 'pattern' => 'upload', - 'method' => 'POST', - 'action' => function () { - $field = $this->field(); - $uploads = $field->uploads(); + return $this->field()->filepicker($params); + } + ], + [ + 'pattern' => 'upload', + 'method' => 'POST', + 'action' => function () { + $field = $this->field(); + $uploads = $field->uploads(); - return $this->field()->upload($this, $uploads, function ($file, $parent) use ($field) { - $absolute = $field->model()->is($parent) === false; + return $this->field()->upload($this, $uploads, function ($file, $parent) use ($field) { + $absolute = $field->model()->is($parent) === false; - return [ - 'filename' => $file->filename(), - 'dragText' => $file->panel()->dragText('auto', $absolute), - ]; - }); - } - ] - ]; - }, - 'validations' => [ - 'minlength', - 'maxlength' - ] + return [ + 'filename' => $file->filename(), + 'dragText' => $file->panel()->dragText('auto', $absolute), + ]; + }); + } + ] + ]; + }, + 'validations' => [ + 'minlength', + 'maxlength' + ] ]; diff --git a/kirby/config/fields/time.php b/kirby/config/fields/time.php index 5dbb536..69a2da9 100755 --- a/kirby/config/fields/time.php +++ b/kirby/config/fields/time.php @@ -5,122 +5,122 @@ use Kirby\Toolkit\Date; use Kirby\Toolkit\I18n; return [ - 'mixins' => ['datetime'], - 'props' => [ - /** - * Unset inherited props - */ - 'placeholder' => null, + 'mixins' => ['datetime'], + 'props' => [ + /** + * Unset inherited props + */ + 'placeholder' => null, - /** - * Sets the default time when a new page/file/user is created - */ - 'default' => function ($default = null): ?string { - return $default; - }, + /** + * Sets the default time when a new page/file/user is created + */ + 'default' => function ($default = null): ?string { + return $default; + }, - /** - * Custom format (dayjs tokens: `HH`, `hh`, `mm`, `ss`, `a`) that is - * used to display the field in the Panel - */ - 'display' => function ($display = null) { - return I18n::translate($display, $display); - }, + /** + * Custom format (dayjs tokens: `HH`, `hh`, `mm`, `ss`, `a`) that is + * used to display the field in the Panel + */ + 'display' => function ($display = null) { + return I18n::translate($display, $display); + }, - /** - * Changes the clock icon - */ - 'icon' => function (string $icon = 'clock') { - return $icon; - }, - /** - * Latest time, which can be selected/saved (H:i or H:i:s) - */ - 'max' => function (string $max = null): ?string { - return Date::optional($max); - }, - /** - * Earliest time, which can be selected/saved (H:i or H:i:s) - */ - 'min' => function (string $min = null): ?string { - return Date::optional($min); - }, + /** + * Changes the clock icon + */ + 'icon' => function (string $icon = 'clock') { + return $icon; + }, + /** + * Latest time, which can be selected/saved (H:i or H:i:s) + */ + 'max' => function (string $max = null): ?string { + return Date::optional($max); + }, + /** + * Earliest time, which can be selected/saved (H:i or H:i:s) + */ + 'min' => function (string $min = null): ?string { + return Date::optional($min); + }, - /** - * `12` or `24` hour notation. If `12`, an AM/PM selector will be shown. - * If `display` is defined, that option will take priority. - */ - 'notation' => function (int $value = 24) { - return $value === 24 ? 24 : 12; - }, - /** - * Round to the nearest: sub-options for `unit` (minute) and `size` (5) - */ - 'step' => function ($step = null) { - return Date::stepConfig($step, [ - 'size' => 5, - 'unit' => 'minute', - ]); - }, - 'value' => function ($value = null): ?string { - return $value; - } - ], - 'computed' => [ - 'display' => function () { - if ($this->display) { - return $this->display; - } + /** + * `12` or `24` hour notation. If `12`, an AM/PM selector will be shown. + * If `display` is defined, that option will take priority. + */ + 'notation' => function (int $value = 24) { + return $value === 24 ? 24 : 12; + }, + /** + * Round to the nearest: sub-options for `unit` (minute) and `size` (5) + */ + 'step' => function ($step = null) { + return Date::stepConfig($step, [ + 'size' => 5, + 'unit' => 'minute', + ]); + }, + 'value' => function ($value = null): ?string { + return $value; + } + ], + 'computed' => [ + 'display' => function () { + if ($this->display) { + return $this->display; + } - return $this->notation === 24 ? 'HH:mm' : 'hh:mm a'; - }, - 'default' => function (): string { - return $this->toDatetime($this->default, 'H:i:s') ?? ''; - }, - 'format' => function () { - return $this->props['format'] ?? 'H:i:s'; - }, - 'value' => function (): ?string { - return $this->toDatetime($this->value, 'H:i:s') ?? ''; - } - ], - 'validations' => [ - 'time', - 'minMax' => function ($value) { - if (!$value = Date::optional($value)) { - return true; - } + return $this->notation === 24 ? 'HH:mm' : 'hh:mm a'; + }, + 'default' => function (): string { + return $this->toDatetime($this->default, 'H:i:s') ?? ''; + }, + 'format' => function () { + return $this->props['format'] ?? 'H:i:s'; + }, + 'value' => function (): ?string { + return $this->toDatetime($this->value, 'H:i:s') ?? ''; + } + ], + 'validations' => [ + 'time', + 'minMax' => function ($value) { + if (!$value = Date::optional($value)) { + return true; + } - $min = Date::optional($this->min); - $max = Date::optional($this->max); + $min = Date::optional($this->min); + $max = Date::optional($this->max); - $format = 'H:i:s'; + $format = 'H:i:s'; - if ($min && $max && $value->isBetween($min, $max) === false) { - throw new Exception([ - 'key' => 'validation.time.between', - 'data' => [ - 'min' => $min->format($format), - 'max' => $min->format($format) - ] - ]); - } elseif ($min && $value->isMin($min) === false) { - throw new Exception([ - 'key' => 'validation.time.after', - 'data' => [ - 'time' => $min->format($format), - ] - ]); - } elseif ($max && $value->isMax($max) === false) { - throw new Exception([ - 'key' => 'validation.time.before', - 'data' => [ - 'time' => $max->format($format), - ] - ]); - } + if ($min && $max && $value->isBetween($min, $max) === false) { + throw new Exception([ + 'key' => 'validation.time.between', + 'data' => [ + 'min' => $min->format($format), + 'max' => $min->format($format) + ] + ]); + } elseif ($min && $value->isMin($min) === false) { + throw new Exception([ + 'key' => 'validation.time.after', + 'data' => [ + 'time' => $min->format($format), + ] + ]); + } elseif ($max && $value->isMax($max) === false) { + throw new Exception([ + 'key' => 'validation.time.before', + 'data' => [ + 'time' => $max->format($format), + ] + ]); + } - return true; - }, - ] + return true; + }, + ] ]; diff --git a/kirby/config/fields/toggle.php b/kirby/config/fields/toggle.php index 6ea330f..4cb8a6e 100755 --- a/kirby/config/fields/toggle.php +++ b/kirby/config/fields/toggle.php @@ -5,69 +5,69 @@ use Kirby\Toolkit\A; use Kirby\Toolkit\I18n; return [ - 'props' => [ - /** - * Unset inherited props - */ - 'placeholder' => null, + 'props' => [ + /** + * Unset inherited props + */ + 'placeholder' => null, - /** - * Default value which will be saved when a new page/user/file is created - */ - 'default' => function ($default = null) { - return $this->default = $default; - }, - /** - * Sets the text next to the toggle. The text can be a string or an array of two options. The first one is the negative text and the second one the positive. The text will automatically switch when the toggle is triggered. - */ - 'text' => function ($value = null) { - $model = $this->model(); + /** + * Default value which will be saved when a new page/user/file is created + */ + 'default' => function ($default = null) { + return $this->default = $default; + }, + /** + * Sets the text next to the toggle. The text can be a string or an array of two options. The first one is the negative text and the second one the positive. The text will automatically switch when the toggle is triggered. + */ + 'text' => function ($value = null) { + $model = $this->model(); - if (is_array($value) === true) { - if (A::isAssociative($value) === true) { - return $model->toSafeString(I18n::translate($value, $value)); - } + if (is_array($value) === true) { + if (A::isAssociative($value) === true) { + return $model->toSafeString(I18n::translate($value, $value)); + } - foreach ($value as $key => $val) { - $value[$key] = $model->toSafeString(I18n::translate($val, $val)); - } + foreach ($value as $key => $val) { + $value[$key] = $model->toSafeString(I18n::translate($val, $val)); + } - return $value; - } + return $value; + } - if (empty($value) === false) { - return $model->toSafeString(I18n::translate($value, $value)); - } + if (empty($value) === false) { + return $model->toSafeString(I18n::translate($value, $value)); + } - return $value; - }, - ], - 'computed' => [ - 'default' => function () { - return $this->toBool($this->default); - }, - 'value' => function () { - if ($this->props['value'] === null) { - return $this->default(); - } else { - return $this->toBool($this->props['value']); - } - } - ], - 'methods' => [ - 'toBool' => function ($value) { - return in_array($value, [true, 'true', 1, '1', 'on'], true) === true; - } - ], - 'save' => function (): string { - return $this->value() === true ? 'true' : 'false'; - }, - 'validations' => [ - 'boolean', - 'required' => function ($value) { - if ($this->isRequired() && ($value === false || $this->isEmpty($value))) { - throw new InvalidArgumentException(I18n::translate('field.required')); - } - }, - ] + return $value; + }, + ], + 'computed' => [ + 'default' => function () { + return $this->toBool($this->default); + }, + 'value' => function () { + if ($this->props['value'] === null) { + return $this->default(); + } else { + return $this->toBool($this->props['value']); + } + } + ], + 'methods' => [ + 'toBool' => function ($value) { + return in_array($value, [true, 'true', 1, '1', 'on'], true) === true; + } + ], + 'save' => function (): string { + return $this->value() === true ? 'true' : 'false'; + }, + 'validations' => [ + 'boolean', + 'required' => function ($value) { + if ($this->isRequired() && ($value === false || $this->isEmpty($value))) { + throw new InvalidArgumentException(I18n::translate('field.required')); + } + }, + ] ]; diff --git a/kirby/config/fields/toggles.php b/kirby/config/fields/toggles.php index 694dd21..c922c2b 100755 --- a/kirby/config/fields/toggles.php +++ b/kirby/config/fields/toggles.php @@ -1,41 +1,41 @@ ['options'], - 'props' => [ - /** - * Unset inherited props - */ - 'after' => null, - 'before' => null, - 'icon' => null, - 'placeholder' => null, + 'mixins' => ['options'], + 'props' => [ + /** + * Unset inherited props + */ + 'after' => null, + 'before' => null, + 'icon' => null, + 'placeholder' => null, - /** - * Toggles will automatically span the full width of the field. With the grow option, you can disable this behaviour for a more compact layout. - */ - 'grow' => function (bool $grow = true) { - return $grow; - }, - /** - * If `false` all labels will be hidden for icon-only toggles. - */ - 'labels' => function (bool $labels = true) { - return $labels; - }, - /** - * A toggle can be deactivated on click. If reset is `false` deactivating a toggle is no longer possible. - */ - 'reset' => function (bool $reset = true) { - return $reset; - } - ], - 'computed' => [ - 'default' => function () { - return $this->sanitizeOption($this->default); - }, - 'value' => function () { - return $this->sanitizeOption($this->value) ?? ''; - }, - ] + /** + * Toggles will automatically span the full width of the field. With the grow option, you can disable this behaviour for a more compact layout. + */ + 'grow' => function (bool $grow = true) { + return $grow; + }, + /** + * If `false` all labels will be hidden for icon-only toggles. + */ + 'labels' => function (bool $labels = true) { + return $labels; + }, + /** + * A toggle can be deactivated on click. If reset is `false` deactivating a toggle is no longer possible. + */ + 'reset' => function (bool $reset = true) { + return $reset; + } + ], + 'computed' => [ + 'default' => function () { + return $this->sanitizeOption($this->default); + }, + 'value' => function () { + return $this->sanitizeOption($this->value) ?? ''; + }, + ] ]; diff --git a/kirby/config/fields/url.php b/kirby/config/fields/url.php index f92dd2c..e9e191f 100755 --- a/kirby/config/fields/url.php +++ b/kirby/config/fields/url.php @@ -3,39 +3,39 @@ use Kirby\Toolkit\I18n; return [ - 'extends' => 'text', - 'props' => [ - /** - * Unset inherited props - */ - 'converter' => null, - 'counter' => null, - 'spellcheck' => null, + 'extends' => 'text', + 'props' => [ + /** + * Unset inherited props + */ + 'converter' => null, + 'counter' => null, + 'spellcheck' => null, - /** - * Sets the HTML5 autocomplete attribute - */ - 'autocomplete' => function (string $autocomplete = 'url') { - return $autocomplete; - }, + /** + * Sets the HTML5 autocomplete attribute + */ + 'autocomplete' => function (string $autocomplete = 'url') { + return $autocomplete; + }, - /** - * Changes the link icon - */ - 'icon' => function (string $icon = 'url') { - return $icon; - }, + /** + * Changes the link icon + */ + 'icon' => function (string $icon = 'url') { + return $icon; + }, - /** - * Sets custom placeholder text, when the field is empty - */ - 'placeholder' => function ($value = null) { - return I18n::translate($value, $value) ?? 'https://example.com'; - } - ], - 'validations' => [ - 'minlength', - 'maxlength', - 'url' - ], + /** + * Sets custom placeholder text, when the field is empty + */ + 'placeholder' => function ($value = null) { + return I18n::translate($value, $value) ?? 'https://example.com'; + } + ], + 'validations' => [ + 'minlength', + 'maxlength', + 'url' + ], ]; diff --git a/kirby/config/fields/users.php b/kirby/config/fields/users.php index 91964df..8641eee 100755 --- a/kirby/config/fields/users.php +++ b/kirby/config/fields/users.php @@ -5,101 +5,101 @@ use Kirby\Data\Data; use Kirby\Toolkit\A; return [ - 'mixins' => [ - 'layout', - 'min', - 'picker', - 'userpicker' - ], - 'props' => [ - /** - * Unset inherited props - */ - 'after' => null, - 'autofocus' => null, - 'before' => null, - 'icon' => null, - 'placeholder' => null, + 'mixins' => [ + 'layout', + 'min', + 'picker', + 'userpicker' + ], + 'props' => [ + /** + * Unset inherited props + */ + 'after' => null, + 'autofocus' => null, + 'before' => null, + 'icon' => null, + 'placeholder' => null, - /** - * Default selected user(s) when a new page/file/user is created - */ - 'default' => function ($default = null) { - if ($default === false) { - return []; - } + /** + * Default selected user(s) when a new page/file/user is created + */ + 'default' => function ($default = null) { + if ($default === false) { + return []; + } - if ($default === null && $user = $this->kirby()->user()) { - return [ - $this->userResponse($user) - ]; - } + if ($default === null && $user = $this->kirby()->user()) { + return [ + $this->userResponse($user) + ]; + } - return $this->toUsers($default); - }, + return $this->toUsers($default); + }, - 'value' => function ($value = null) { - return $this->toUsers($value); - }, - ], - 'computed' => [ - /** - * Unset inherited computed - */ - 'default' => null - ], - 'methods' => [ - 'userResponse' => function ($user) { - return $user->panel()->pickerData([ - 'info' => $this->info, - 'image' => $this->image, - 'layout' => $this->layout, - 'text' => $this->text, - ]); - }, - 'toUsers' => function ($value = null) { - $users = []; - $kirby = App::instance(); + 'value' => function ($value = null) { + return $this->toUsers($value); + }, + ], + 'computed' => [ + /** + * Unset inherited computed + */ + 'default' => null + ], + 'methods' => [ + 'userResponse' => function ($user) { + return $user->panel()->pickerData([ + 'info' => $this->info, + 'image' => $this->image, + 'layout' => $this->layout, + 'text' => $this->text, + ]); + }, + 'toUsers' => function ($value = null) { + $users = []; + $kirby = App::instance(); - foreach (Data::decode($value, 'yaml') as $email) { - if (is_array($email) === true) { - $email = $email['email'] ?? null; - } + foreach (Data::decode($value, 'yaml') as $email) { + if (is_array($email) === true) { + $email = $email['email'] ?? null; + } - if ($email !== null && ($user = $kirby->user($email))) { - $users[] = $this->userResponse($user); - } - } + if ($email !== null && ($user = $kirby->user($email))) { + $users[] = $this->userResponse($user); + } + } - return $users; - } - ], - 'api' => function () { - return [ - [ - 'pattern' => '/', - 'action' => function () { - $field = $this->field(); + return $users; + } + ], + 'api' => function () { + return [ + [ + 'pattern' => '/', + 'action' => function () { + $field = $this->field(); - return $field->userpicker([ - 'image' => $field->image(), - 'info' => $field->info(), - 'layout' => $field->layout(), - 'limit' => $field->limit(), - 'page' => $this->requestQuery('page'), - 'query' => $field->query(), - 'search' => $this->requestQuery('search'), - 'text' => $field->text() - ]); - } - ] - ]; - }, - 'save' => function ($value = null) { - return A::pluck($value, 'id'); - }, - 'validations' => [ - 'max', - 'min' - ] + return $field->userpicker([ + 'image' => $field->image(), + 'info' => $field->info(), + 'layout' => $field->layout(), + 'limit' => $field->limit(), + 'page' => $this->requestQuery('page'), + 'query' => $field->query(), + 'search' => $this->requestQuery('search'), + 'text' => $field->text() + ]); + } + ] + ]; + }, + 'save' => function ($value = null) { + return A::pluck($value, 'id'); + }, + 'validations' => [ + 'max', + 'min' + ] ]; diff --git a/kirby/config/fields/writer.php b/kirby/config/fields/writer.php index a19e9b0..73c4976 100755 --- a/kirby/config/fields/writer.php +++ b/kirby/config/fields/writer.php @@ -3,34 +3,34 @@ use Kirby\Sane\Sane; return [ - 'props' => [ - /** - * Enables inline mode, which will not wrap new lines in paragraphs and creates hard breaks instead. - * - * @param bool $inline - */ - 'inline' => function (bool $inline = false) { - return $inline; - }, - /** - * Sets the allowed HTML formats. Available formats: `bold`, `italic`, `underline`, `strike`, `code`, `link`, `email`. Activate them all by passing `true`. Deactivate them all by passing `false` - * @param array|bool $marks - */ - 'marks' => function ($marks = true) { - return $marks; - }, - /** - * Sets the allowed nodes. Available nodes: `paragraph`, `heading`, `bulletList`, `orderedList`. Activate/deactivate them all by passing `true`/`false`. Default nodes are `paragraph`, `heading`, `bulletList`, `orderedList`. - * @param array|bool|null $nodes - */ - 'nodes' => function ($nodes = null) { - return $nodes; - } - ], - 'computed' => [ - 'value' => function () { - $value = trim($this->value ?? ''); - return Sane::sanitize($value, 'html'); - } - ], + 'props' => [ + /** + * Enables inline mode, which will not wrap new lines in paragraphs and creates hard breaks instead. + * + * @param bool $inline + */ + 'inline' => function (bool $inline = false) { + return $inline; + }, + /** + * Sets the allowed HTML formats. Available formats: `bold`, `italic`, `underline`, `strike`, `code`, `link`, `email`. Activate them all by passing `true`. Deactivate them all by passing `false` + * @param array|bool $marks + */ + 'marks' => function ($marks = true) { + return $marks; + }, + /** + * Sets the allowed nodes. Available nodes: `paragraph`, `heading`, `bulletList`, `orderedList`. Activate/deactivate them all by passing `true`/`false`. Default nodes are `paragraph`, `heading`, `bulletList`, `orderedList`. + * @param array|bool|null $nodes + */ + 'nodes' => function ($nodes = null) { + return $nodes; + } + ], + 'computed' => [ + 'value' => function () { + $value = trim($this->value ?? ''); + return Sane::sanitize($value, 'html'); + } + ], ]; diff --git a/kirby/config/helpers.php b/kirby/config/helpers.php index 9e6adab..f8d0476 100755 --- a/kirby/config/helpers.php +++ b/kirby/config/helpers.php @@ -14,758 +14,758 @@ use Kirby\Toolkit\Str; 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) - { - return new Asset($path); - } + /** + * Helper to create an asset object + * + * @param string $path + * @return \Kirby\Filesystem\Asset + */ + function asset(string $path) + { + return new Asset($path); + } } if (Helpers::hasOverride('attr') === false) { // @codeCoverageIgnore - /** - * Generates a list of HTML attributes - * - * @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, ?string $before = null, ?string $after = null): ?string - { - return Html::attr($attr, null, $before, $after); - } + /** + * Generates a list of HTML attributes + * + * @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, ?string $before = null, ?string $after = null): ?string + { + return Html::attr($attr, null, $before, $after); + } } if (Helpers::hasOverride('collection') === false) { // @codeCoverageIgnore - /** - * Returns the result of a collection by name - * - * @param string $name - * @return \Kirby\Cms\Collection|null - */ - function collection(string $name) - { - return App::instance()->collection($name); - } + /** + * Returns the result of a collection by name + * + * @param string $name + * @return \Kirby\Cms\Collection|null + */ + function collection(string $name) + { + return App::instance()->collection($name); + } } if (Helpers::hasOverride('csrf') === false) { // @codeCoverageIgnore - /** - * Checks / returns a CSRF token - * - * @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) - { - // 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! - if (func_num_args() === 0) { - return App::instance()->csrf(); - } + /** + * Checks / returns a CSRF token + * + * @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) + { + // 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! + if (func_num_args() === 0) { + return App::instance()->csrf(); + } - return App::instance()->csrf($check); - } + return App::instance()->csrf($check); + } } 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 $options Pass an array of attributes for the link tag or a media attribute string - * @return string|null - */ - function css($url, $options = null): ?string - { - return Html::css($url, $options); - } + /** + * 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 $options Pass an array of attributes for the link tag or a media attribute string + * @return string|null + */ + function css($url, $options = null): ?string + { + return Html::css($url, $options); + } } 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 - { - return Helpers::deprecated($message); - } + /** + * 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 + { + return Helpers::deprecated($message); + } } 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($variable, bool $echo = true): string - { - return Helpers::dump($variable, $echo); - } + /** + * Simple object and variable dumper + * to help with debugging. + * + * @param mixed $variable + * @param bool $echo + * @return string + */ + function dump($variable, bool $echo = true): string + { + return Helpers::dump($variable, $echo); + } } 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($condition, $value, $alternative = null) - { - echo $condition ? $value : $alternative; - } + /** + * 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($condition, $value, $alternative = null) + { + echo $condition ? $value : $alternative; + } } if (Helpers::hasOverride('esc') === false) { // @codeCoverageIgnore - /** - * Escape context specific output - * - * @param string $string Untrusted data - * @param string $context Location of output (`html`, `attr`, `js`, `css`, `url` or `xml`) - * @return string Escaped data - */ - function esc(string $string, string $context = 'html'): string - { - return Str::esc($string, $context); - } + /** + * Escape context specific output + * + * @param string $string Untrusted data + * @param string $context Location of output (`html`, `attr`, `js`, `css`, `url` or `xml`) + * @return string Escaped data + */ + function esc(string $string, string $context = 'html'): string + { + return Str::esc($string, $context); + } } if (Helpers::hasOverride('get') === false) { // @codeCoverageIgnore - /** - * Shortcut for $kirby->request()->get() - * - * @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($key = null, $default = null) - { - return App::instance()->request()->get($key, $default); - } + /** + * Shortcut for $kirby->request()->get() + * + * @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($key = null, $default = null) + { + return App::instance()->request()->get($key, $default); + } } if (Helpers::hasOverride('gist') === false) { // @codeCoverageIgnore - /** - * Embeds a Github Gist - * - * @param string $url - * @param string|null $file - * @return string - */ - function gist(string $url, ?string $file = null): string - { - return App::instance()->kirbytag([ - 'gist' => $url, - 'file' => $file, - ]); - } + /** + * Embeds a Github Gist + * + * @param string $url + * @param string|null $file + * @return string + */ + function gist(string $url, ?string $file = null): string + { + return App::instance()->kirbytag([ + 'gist' => $url, + 'file' => $file, + ]); + } } 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) - { - Response::go($url, $code); - } + /** + * 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) + { + Response::go($url, $code); + } } if (Helpers::hasOverride('h') === false) { // @codeCoverageIgnore - /** - * Shortcut for html() - * - * @param string|null $string unencoded text - * @param bool $keepTags - * @return string - */ - function h(?string $string, bool $keepTags = false): string - { - return Html::encode($string, $keepTags); - } + /** + * Shortcut for html() + * + * @param string|null $string unencoded text + * @param bool $keepTags + * @return string + */ + function h(?string $string, bool $keepTags = false): string + { + return Html::encode($string, $keepTags); + } } 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 $string, bool $keepTags = false): string - { - return Html::encode($string, $keepTags); - } + /** + * Creates safe html by encoding special characters + * + * @param string|null $string unencoded text + * @param bool $keepTags + * @return string + */ + function html(?string $string, bool $keepTags = false): string + { + return Html::encode($string, $keepTags); + } } if (Helpers::hasOverride('image') === false) { // @codeCoverageIgnore - /** - * Return an image from any page - * specified by the path - * - * Example: - * - * - * @param string|null $path - * @return \Kirby\Cms\File|null - */ - function image(?string $path = null) - { - return App::instance()->image($path); - } + /** + * Return an image from any page + * specified by the path + * + * Example: + * + * + * @param string|null $path + * @return \Kirby\Cms\File|null + */ + function image(?string $path = null) + { + return App::instance()->image($path); + } } 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 - { - return V::invalid($data, $rules, $messages); - } + /** + * 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 + { + return V::invalid($data, $rules, $messages); + } } 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($url, $options = null): ?string - { - return Html::js($url, $options); - } + /** + * Creates a script tag to load a javascript file + * + * @param string|array $url + * @param string|array $options + * @return string|null + */ + function js($url, $options = null): ?string + { + return Html::js($url, $options); + } } if (Helpers::hasOverride('kirby') === false) { // @codeCoverageIgnore - /** - * Returns the Kirby object in any situation - * - * @return \Kirby\Cms\App - */ - function kirby() - { - return App::instance(); - } + /** + * Returns the Kirby object in any situation + * + * @return \Kirby\Cms\App + */ + function kirby() + { + return App::instance(); + } } 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($type, ?string $value = null, array $attr = [], array $data = []): string - { - return App::instance()->kirbytag($type, $value, $attr, $data); - } + /** + * 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($type, ?string $value = null, array $attr = [], array $data = []): string + { + return App::instance()->kirbytag($type, $value, $attr, $data); + } } 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 $text = null, array $data = []): string - { - return App::instance()->kirbytags($text, $data); - } + /** + * Parses KirbyTags in the given string. Shortcut + * for `$kirby->kirbytags($text, $data)` + * + * @param string|null $text + * @param array $data + * @return string + */ + function kirbytags(?string $text = null, array $data = []): string + { + return App::instance()->kirbytags($text, $data); + } } 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 $text = null, array $data = []): string - { - return App::instance()->kirbytext($text, $data); - } + /** + * Parses KirbyTags and Markdown in the + * given string. Shortcut for `$kirby->kirbytext()` + * + * @param string|null $text + * @param array $data + * @return string + */ + function kirbytext(?string $text = null, array $data = []): string + { + return App::instance()->kirbytext($text, $data); + } } 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 $text = null, array $options = []): string - { - $options['markdown']['inline'] = true; - return App::instance()->kirbytext($text, $options); - } + /** + * 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 $text = null, array $options = []): string + { + $options['markdown']['inline'] = true; + return App::instance()->kirbytext($text, $options); + } } if (Helpers::hasOverride('kt') === false) { // @codeCoverageIgnore - /** - * Shortcut for `kirbytext()` helper - * - * @param string|null $text - * @param array $data - * @return string - */ - function kt(?string $text = null, array $data = []): string - { - return App::instance()->kirbytext($text, $data); - } + /** + * Shortcut for `kirbytext()` helper + * + * @param string|null $text + * @param array $data + * @return string + */ + function kt(?string $text = null, array $data = []): string + { + return App::instance()->kirbytext($text, $data); + } } 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 $text = null, array $options = []): string - { - $options['markdown']['inline'] = true; - return App::instance()->kirbytext($text, $options); - } + /** + * Shortcut for `kirbytextinline()` helper + * @since 3.1.0 + * + * @param string|null $text + * @param array $options + * @return string + */ + function kti(?string $text = null, array $options = []): string + { + $options['markdown']['inline'] = true; + return App::instance()->kirbytext($text, $options); + } } 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 $base = null): void - { - F::loadClasses($classmap, $base); - } + /** + * A super simple class autoloader + * + * @param array $classmap + * @param string|null $base + * @return void + */ + function load(array $classmap, ?string $base = null): void + { + F::loadClasses($classmap, $base); + } } 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 $text = null, array $options = []): string - { - return App::instance()->markdown($text, $options); - } + /** + * Parses markdown in the given string. Shortcut for + * `$kirby->markdown($text)` + * + * @param string|null $text + * @param array $options + * @return string + */ + function markdown(?string $text = null, array $options = []): string + { + return App::instance()->markdown($text, $options); + } } if (Helpers::hasOverride('option') === false) { // @codeCoverageIgnore - /** - * Shortcut for `$kirby->option($key, $default)` - * - * @param string $key - * @param mixed $default - * @return mixed - */ - function option(string $key, $default = null) - { - return App::instance()->option($key, $default); - } + /** + * Shortcut for `$kirby->option($key, $default)` + * + * @param string $key + * @param mixed $default + * @return mixed + */ + function option(string $key, $default = null) + { + return App::instance()->option($key, $default); + } } 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 $id = null) - { - if (empty($id) === true) { - return App::instance()->site()->page(); - } + /** + * 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 $id = null) + { + if (empty($id) === true) { + return App::instance()->site()->page(); + } - return App::instance()->site()->find($id); - } + return App::instance()->site()->find($id); + } } if (Helpers::hasOverride('pages') === false) { // @codeCoverageIgnore - /** - * Helper to build pages collection - * - * @param string|array ...$id - * @return \Kirby\Cms\Pages|null - */ - function pages(...$id) - { - // ensure that a list of string arguments and an array - // as the first argument are treated the same - if (count($id) === 1 && is_array($id[0]) === true) { - $id = $id[0]; - } + /** + * Helper to build pages collection + * + * @param string|array ...$id + * @return \Kirby\Cms\Pages|null + */ + function pages(...$id) + { + // ensure that a list of string arguments and an array + // as the first argument are treated the same + if (count($id) === 1 && is_array($id[0]) === true) { + $id = $id[0]; + } - // always passes $id an array; ensures we get a - // collection even if only one ID is passed - return App::instance()->site()->find($id); - } + // always passes $id an array; ensures we get a + // collection even if only one ID is passed + return App::instance()->site()->find($id); + } } if (Helpers::hasOverride('param') === false) { // @codeCoverageIgnore - /** - * Returns a single param from the URL - * - * @param string $key - * @param string|null $fallback - * @return string|null - */ - function param(string $key, ?string $fallback = null): ?string - { - return App::instance()->request()->url()->params()->$key ?? $fallback; - } + /** + * Returns a single param from the URL + * + * @param string $key + * @param string|null $fallback + * @return string|null + */ + function param(string $key, ?string $fallback = null): ?string + { + return App::instance()->request()->url()->params()->$key ?? $fallback; + } } if (Helpers::hasOverride('params') === false) { // @codeCoverageIgnore - /** - * Returns all params from the current Url - * - * @return array - */ - function params(): array - { - return App::instance()->request()->url()->params()->toArray(); - } + /** + * Returns all params from the current Url + * + * @return array + */ + function params(): array + { + return App::instance()->request()->url()->params()->toArray(); + } } 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($condition, $value, $alternative = null) - { - return $condition ? $value : $alternative; - } + /** + * 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($condition, $value, $alternative = null) + { + return $condition ? $value : $alternative; + } } 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 $path = null, string $method = 'GET', array $routes = [], ?Closure $callback = null) - { - return Router::execute($path, $method, $routes, $callback); - } + /** + * 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 Router::execute($path, $method, $routes, $callback); + } } if (Helpers::hasOverride('site') === false) { // @codeCoverageIgnore - /** - * Returns the current site object - * - * @return \Kirby\Cms\Site - */ - function site() - { - return App::instance()->site(); - } + /** + * Returns the current site object + * + * @return \Kirby\Cms\Site + */ + function site() + { + return App::instance()->site(); + } } 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($value): int - { - return Helpers::size($value); - } + /** + * Determines the size/length of numbers, strings, arrays and countable objects + * + * @param mixed $value + * @return int + * @throws \Kirby\Exception\InvalidArgumentException + */ + function size($value): int + { + return Helpers::size($value); + } } 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 $text = null): string - { - return App::instance()->smartypants($text); - } + /** + * Enhances the given string with + * smartypants. Shortcut for `$kirby->smartypants($text)` + * + * @param string|null $text + * @return string + */ + function smartypants(?string $text = null): string + { + return App::instance()->smartypants($text); + } } 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): ?string - { - return App::instance()->snippet($name, $data, $return); - } + /** + * 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): ?string + { + return App::instance()->snippet($name, $data, $return); + } } 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($file) - { - return Html::svg($file); - } + /** + * Includes an SVG file by absolute or + * relative file path. + * + * @param string|\Kirby\Cms\File $file + * @return string|false + */ + function svg($file) + { + return Html::svg($file); + } } 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($key, string $fallback = null, string $locale = null) - { - return I18n::translate($key, $fallback, $locale); - } + /** + * 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($key, string $fallback = null, string $locale = null) + { + return I18n::translate($key, $fallback, $locale); + } } 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 $locale = null, - bool $formatNumber = true - ) { - return I18n::translateCount($key, $count, $locale, $formatNumber); - } + /** + * 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 $locale = null, + bool $formatNumber = true + ) { + return I18n::translateCount($key, $count, $locale, $formatNumber); + } } 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 $date = null, $step = null): ?int - { - return Date::roundedTimestamp($date, $step); - } + /** + * 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 $date = null, $step = null): ?int + { + return Date::roundedTimestamp($date, $step); + } } 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, $fallback = null, ?array $replace = null, ?string $locale = null): string - { - return I18n::template($key, $fallback, $replace, $locale); - } + /** + * 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, $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 - ]); - } + /** + * 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 $path = null, $options = null): string - { - return Url::to($path, $options); - } + /** + * Shortcut for url() + * + * @param string|null $path + * @param array|string|null $options + * @return string + */ + function u(?string $path = null, $options = null): string + { + return Url::to($path, $options); + } } 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 $path = null, $options = null): string - { - return Url::to($path, $options); - } + /** + * Builds an absolute URL for a given path + * + * @param string|null $path + * @param array|string|null $options + * @return string + */ + function url(?string $path = null, $options = null): string + { + return Url::to($path, $options); + } } if (Helpers::hasOverride('uuid') === false) { // @codeCoverageIgnore - /** - * Creates a compliant v4 UUID - * - * @return string - */ - function uuid(): string - { - return Str::uuid(); - } + /** + * Creates a compliant v4 UUID + * + * @return string + */ + function uuid(): string + { + return Str::uuid(); + } } 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 - { - return Html::video($url, $options, $attr); - } + /** + * 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 + { + return Html::video($url, $options, $attr); + } } 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 - { - return Html::vimeo($url, $options, $attr); - } + /** + * 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 + { + return Html::vimeo($url, $options, $attr); + } } 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 $string = null): string - { - return Str::widont($string); - } + /** + * 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 $string = null): string + { + return Str::widont($string); + } } 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 - { - return Html::youtube($url, $options, $attr); - } + /** + * 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 + { + return Html::youtube($url, $options, $attr); + } } diff --git a/kirby/config/methods.php b/kirby/config/methods.php index d49f799..00209c0 100755 --- a/kirby/config/methods.php +++ b/kirby/config/methods.php @@ -19,596 +19,596 @@ use Kirby\Toolkit\Xml; * Field method setup */ return function (App $app) { - return [ + return [ - // states + // states - /** - * Converts the field value into a proper boolean and inverts it - * - * @param \Kirby\Cms\Field $field - * @return bool - */ - 'isFalse' => function (Field $field): bool { - return $field->toBool() === false; - }, + /** + * Converts the field value into a proper boolean and inverts it + * + * @param \Kirby\Cms\Field $field + * @return bool + */ + 'isFalse' => function (Field $field): bool { + return $field->toBool() === false; + }, - /** - * Converts the field value into a proper boolean - * - * @param \Kirby\Cms\Field $field - * @return bool - */ - 'isTrue' => function (Field $field): bool { - return $field->toBool() === true; - }, + /** + * Converts the field value into a proper boolean + * + * @param \Kirby\Cms\Field $field + * @return bool + */ + 'isTrue' => function (Field $field): bool { + return $field->toBool() === true; + }, - /** - * Validates the field content with the given validator and parameters - * - * @param string $validator - * @param mixed ...$arguments A list of optional validator arguments - * @return bool - */ - 'isValid' => function (Field $field, string $validator, ...$arguments): bool { - return V::$validator($field->value, ...$arguments); - }, + /** + * Validates the field content with the given validator and parameters + * + * @param string $validator + * @param mixed ...$arguments A list of optional validator arguments + * @return bool + */ + 'isValid' => function (Field $field, string $validator, ...$arguments): bool { + return V::$validator($field->value, ...$arguments); + }, - // converters - /** - * Converts a yaml or json field to a Blocks object - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\Blocks - */ - 'toBlocks' => function (Field $field) { - try { - $blocks = Blocks::factory(Blocks::parse($field->value()), [ - 'parent' => $field->parent(), - ]); + // converters + /** + * Converts a yaml or json field to a Blocks object + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\Blocks + */ + 'toBlocks' => function (Field $field) { + try { + $blocks = Blocks::factory(Blocks::parse($field->value()), [ + 'parent' => $field->parent(), + ]); - return $blocks->filter('isHidden', false); - } catch (Throwable $e) { - if ($field->parent() === null) { - $message = 'Invalid blocks data for "' . $field->key() . '" field'; - } else { - $message = 'Invalid blocks data for "' . $field->key() . '" field on parent "' . $field->parent()->title() . '"'; - } + return $blocks->filter('isHidden', false); + } catch (Throwable $e) { + if ($field->parent() === null) { + $message = 'Invalid blocks data for "' . $field->key() . '" field'; + } else { + $message = 'Invalid blocks data for "' . $field->key() . '" field on parent "' . $field->parent()->title() . '"'; + } - throw new InvalidArgumentException($message); - } - }, + throw new InvalidArgumentException($message); + } + }, - /** - * Converts the field value into a proper boolean - * - * @param \Kirby\Cms\Field $field - * @param bool $default Default value if the field is empty - * @return bool - */ - 'toBool' => function (Field $field, $default = false): bool { - $value = $field->isEmpty() ? $default : $field->value; - return filter_var($value, FILTER_VALIDATE_BOOLEAN); - }, + /** + * Converts the field value into a proper boolean + * + * @param \Kirby\Cms\Field $field + * @param bool $default Default value if the field is empty + * @return bool + */ + 'toBool' => function (Field $field, $default = false): bool { + $value = $field->isEmpty() ? $default : $field->value; + return filter_var($value, FILTER_VALIDATE_BOOLEAN); + }, - /** - * Parses the field value with the given method - * - * @param \Kirby\Cms\Field $field - * @param string $method [',', 'yaml', 'json'] - * @return array - */ - 'toData' => function (Field $field, string $method = ',') { - switch ($method) { - case 'yaml': - case 'json': - return Data::decode($field->value, $method); - default: - return $field->split($method); - } - }, + /** + * Parses the field value with the given method + * + * @param \Kirby\Cms\Field $field + * @param string $method [',', 'yaml', 'json'] + * @return array + */ + 'toData' => function (Field $field, string $method = ',') { + switch ($method) { + case 'yaml': + case 'json': + return Data::decode($field->value, $method); + default: + return $field->split($method); + } + }, - /** - * Converts the field value to a timestamp or a formatted date - * - * @param \Kirby\Cms\Field $field - * @param string|\IntlDateFormatter|null $format PHP date formatting string - * @param string|null $fallback Fallback string for `strtotime` (since 3.2) - * @return string|int - */ - 'toDate' => function (Field $field, $format = null, string $fallback = null) use ($app) { - if (empty($field->value) === true && $fallback === null) { - return null; - } + /** + * Converts the field value to a timestamp or a formatted date + * + * @param \Kirby\Cms\Field $field + * @param string|\IntlDateFormatter|null $format PHP date formatting string + * @param string|null $fallback Fallback string for `strtotime` (since 3.2) + * @return string|int + */ + 'toDate' => function (Field $field, $format = null, string $fallback = null) use ($app) { + if (empty($field->value) === true && $fallback === null) { + return null; + } - if (empty($field->value) === false) { - $time = $field->toTimestamp(); - } else { - $time = strtotime($fallback); - } + if (empty($field->value) === false) { + $time = $field->toTimestamp(); + } else { + $time = strtotime($fallback); + } - $handler = $app->option('date.handler', 'date'); - return Str::date($time, $format, $handler); - }, + $handler = $app->option('date.handler', 'date'); + return Str::date($time, $format, $handler); + }, - /** - * Returns a file object from a filename in the field - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\File|null - */ - 'toFile' => function (Field $field) { - return $field->toFiles()->first(); - }, + /** + * Returns a file object from a filename in the field + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\File|null + */ + 'toFile' => function (Field $field) { + return $field->toFiles()->first(); + }, - /** - * Returns a file collection from a yaml list of filenames in the field - * - * @param \Kirby\Cms\Field $field - * @param string $separator - * @return \Kirby\Cms\Files - */ - 'toFiles' => function (Field $field, string $separator = 'yaml') { - $parent = $field->parent(); - $files = new Files([]); + /** + * Returns a file collection from a yaml list of filenames in the field + * + * @param \Kirby\Cms\Field $field + * @param string $separator + * @return \Kirby\Cms\Files + */ + 'toFiles' => function (Field $field, string $separator = 'yaml') { + $parent = $field->parent(); + $files = new Files([]); - foreach ($field->toData($separator) as $id) { - if ($file = $parent->kirby()->file($id, $parent)) { - $files->add($file); - } - } + foreach ($field->toData($separator) as $id) { + if ($file = $parent->kirby()->file($id, $parent)) { + $files->add($file); + } + } - return $files; - }, + return $files; + }, - /** - * Converts the field value into a proper float - * - * @param \Kirby\Cms\Field $field - * @param float $default Default value if the field is empty - * @return float - */ - 'toFloat' => function (Field $field, float $default = 0) { - $value = $field->isEmpty() ? $default : $field->value; - return (float)$value; - }, + /** + * Converts the field value into a proper float + * + * @param \Kirby\Cms\Field $field + * @param float $default Default value if the field is empty + * @return float + */ + 'toFloat' => function (Field $field, float $default = 0) { + $value = $field->isEmpty() ? $default : $field->value; + return (float)$value; + }, - /** - * Converts the field value into a proper integer - * - * @param \Kirby\Cms\Field $field - * @param int $default Default value if the field is empty - * @return int - */ - 'toInt' => function (Field $field, int $default = 0) { - $value = $field->isEmpty() ? $default : $field->value; - return (int)$value; - }, + /** + * Converts the field value into a proper integer + * + * @param \Kirby\Cms\Field $field + * @param int $default Default value if the field is empty + * @return int + */ + 'toInt' => function (Field $field, int $default = 0) { + $value = $field->isEmpty() ? $default : $field->value; + return (int)$value; + }, - /** - * Parse layouts and turn them into - * Layout objects - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\Layouts - */ - 'toLayouts' => function (Field $field) { - return Layouts::factory(Layouts::parse($field->value()), [ - 'parent' => $field->parent() - ]); - }, + /** + * Parse layouts and turn them into + * Layout objects + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\Layouts + */ + 'toLayouts' => function (Field $field) { + return Layouts::factory(Layouts::parse($field->value()), [ + 'parent' => $field->parent() + ]); + }, - /** - * Wraps a link tag around the field value. The field value is used as the link text - * - * @param \Kirby\Cms\Field $field - * @param mixed $attr1 Can be an optional Url. If no Url is set, the Url of the Page, File or Site will be used. Can also be an array of link attributes - * @param mixed $attr2 If `$attr1` is used to set the Url, you can use `$attr2` to pass an array of additional attributes. - * @return string - */ - 'toLink' => function (Field $field, $attr1 = null, $attr2 = null) { - if (is_string($attr1) === true) { - $href = $attr1; - $attr = $attr2; - } else { - $href = $field->parent()->url(); - $attr = $attr1; - } + /** + * Wraps a link tag around the field value. The field value is used as the link text + * + * @param \Kirby\Cms\Field $field + * @param mixed $attr1 Can be an optional Url. If no Url is set, the Url of the Page, File or Site will be used. Can also be an array of link attributes + * @param mixed $attr2 If `$attr1` is used to set the Url, you can use `$attr2` to pass an array of additional attributes. + * @return string + */ + 'toLink' => function (Field $field, $attr1 = null, $attr2 = null) { + if (is_string($attr1) === true) { + $href = $attr1; + $attr = $attr2; + } else { + $href = $field->parent()->url(); + $attr = $attr1; + } - if ($field->parent()->isActive()) { - $attr['aria-current'] = 'page'; - } + if ($field->parent()->isActive()) { + $attr['aria-current'] = 'page'; + } - return Html::a($href, $field->value, $attr ?? []); - }, + return Html::a($href, $field->value, $attr ?? []); + }, - /** - * Returns a page object from a page id in the field - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\Page|null - */ - 'toPage' => function (Field $field) { - return $field->toPages()->first(); - }, + /** + * Returns a page object from a page id in the field + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\Page|null + */ + 'toPage' => function (Field $field) { + return $field->toPages()->first(); + }, - /** - * Returns a pages collection from a yaml list of page ids in the field - * - * @param \Kirby\Cms\Field $field - * @param string $separator Can be any other separator to split the field value by - * @return \Kirby\Cms\Pages - */ - 'toPages' => function (Field $field, string $separator = 'yaml') use ($app) { - return $app->site()->find(false, false, ...$field->toData($separator)); - }, + /** + * Returns a pages collection from a yaml list of page ids in the field + * + * @param \Kirby\Cms\Field $field + * @param string $separator Can be any other separator to split the field value by + * @return \Kirby\Cms\Pages + */ + 'toPages' => function (Field $field, string $separator = 'yaml') use ($app) { + return $app->site()->find(false, false, ...$field->toData($separator)); + }, - /** - * Converts a yaml field to a Structure object - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\Structure - */ - 'toStructure' => function (Field $field) { - try { - return new Structure(Data::decode($field->value, 'yaml'), $field->parent()); - } catch (Exception $e) { - if ($field->parent() === null) { - $message = 'Invalid structure data for "' . $field->key() . '" field'; - } else { - $message = 'Invalid structure data for "' . $field->key() . '" field on parent "' . $field->parent()->title() . '"'; - } + /** + * Converts a yaml field to a Structure object + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\Structure + */ + 'toStructure' => function (Field $field) { + try { + return new Structure(Data::decode($field->value, 'yaml'), $field->parent()); + } catch (Exception $e) { + if ($field->parent() === null) { + $message = 'Invalid structure data for "' . $field->key() . '" field'; + } else { + $message = 'Invalid structure data for "' . $field->key() . '" field on parent "' . $field->parent()->title() . '"'; + } - throw new InvalidArgumentException($message); - } - }, + throw new InvalidArgumentException($message); + } + }, - /** - * Converts the field value to a Unix timestamp - * - * @param \Kirby\Cms\Field $field - * @return int - */ - 'toTimestamp' => function (Field $field): int { - return strtotime($field->value); - }, + /** + * Converts the field value to a Unix timestamp + * + * @param \Kirby\Cms\Field $field + * @return int + */ + 'toTimestamp' => function (Field $field): int { + return strtotime($field->value); + }, - /** - * Turns the field value into an absolute Url - * - * @param \Kirby\Cms\Field $field - * @return string - */ - 'toUrl' => function (Field $field): string { - return Url::to($field->value); - }, + /** + * Turns the field value into an absolute Url + * + * @param \Kirby\Cms\Field $field + * @return string + */ + 'toUrl' => function (Field $field): string { + return Url::to($field->value); + }, - /** - * Converts a user email address to a user object - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\User|null - */ - 'toUser' => function (Field $field) { - return $field->toUsers()->first(); - }, + /** + * Converts a user email address to a user object + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\User|null + */ + 'toUser' => function (Field $field) { + return $field->toUsers()->first(); + }, - /** - * Returns a users collection from a yaml list of user email addresses in the field - * - * @param \Kirby\Cms\Field $field - * @param string $separator - * @return \Kirby\Cms\Users - */ - 'toUsers' => function (Field $field, string $separator = 'yaml') use ($app) { - return $app->users()->find(false, false, ...$field->toData($separator)); - }, + /** + * Returns a users collection from a yaml list of user email addresses in the field + * + * @param \Kirby\Cms\Field $field + * @param string $separator + * @return \Kirby\Cms\Users + */ + 'toUsers' => function (Field $field, string $separator = 'yaml') use ($app) { + return $app->users()->find(false, false, ...$field->toData($separator)); + }, - // inspectors + // inspectors - /** - * Returns the length of the field content - */ - 'length' => function (Field $field) { - return Str::length($field->value); - }, + /** + * Returns the length of the field content + */ + 'length' => function (Field $field) { + return Str::length($field->value); + }, - /** - * Returns the number of words in the text - */ - 'words' => function (Field $field) { - return str_word_count(strip_tags($field->value)); - }, + /** + * Returns the number of words in the text + */ + 'words' => function (Field $field) { + return str_word_count(strip_tags($field->value)); + }, - // manipulators + // manipulators - /** - * Applies the callback function to the field - * @since 3.4.0 - * - * @param \Kirby\Cms\Field $field - * @param Closure $callback - */ - 'callback' => function (Field $field, Closure $callback) { - return $callback($field); - }, + /** + * Applies the callback function to the field + * @since 3.4.0 + * + * @param \Kirby\Cms\Field $field + * @param Closure $callback + */ + 'callback' => function (Field $field, Closure $callback) { + return $callback($field); + }, - /** - * Escapes the field value to be safely used in HTML - * templates without the risk of XSS attacks - * - * @param \Kirby\Cms\Field $field - * @param string $context Location of output (`html`, `attr`, `js`, `css`, `url` or `xml`) - */ - 'escape' => function (Field $field, string $context = 'html') { - $field->value = Str::esc($field->value, $context); - return $field; - }, + /** + * Escapes the field value to be safely used in HTML + * templates without the risk of XSS attacks + * + * @param \Kirby\Cms\Field $field + * @param string $context Location of output (`html`, `attr`, `js`, `css`, `url` or `xml`) + */ + 'escape' => function (Field $field, string $context = 'html') { + $field->value = Str::esc($field->value, $context); + return $field; + }, - /** - * Creates an excerpt of the field value without html - * or any other formatting. - * - * @param \Kirby\Cms\Field $field - * @param int $cahrs - * @param bool $strip - * @param string $rep - * @return \Kirby\Cms\Field - */ - 'excerpt' => function (Field $field, int $chars = 0, bool $strip = true, string $rep = ' …') { - $field->value = Str::excerpt($field->kirbytext()->value(), $chars, $strip, $rep); - return $field; - }, + /** + * Creates an excerpt of the field value without html + * or any other formatting. + * + * @param \Kirby\Cms\Field $field + * @param int $cahrs + * @param bool $strip + * @param string $rep + * @return \Kirby\Cms\Field + */ + 'excerpt' => function (Field $field, int $chars = 0, bool $strip = true, string $rep = ' …') { + $field->value = Str::excerpt($field->kirbytext()->value(), $chars, $strip, $rep); + return $field; + }, - /** - * Converts the field content to valid HTML - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\Field - */ - 'html' => function (Field $field) { - $field->value = Html::encode($field->value); - return $field; - }, + /** + * Converts the field content to valid HTML + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\Field + */ + 'html' => function (Field $field) { + $field->value = Html::encode($field->value); + return $field; + }, - /** - * Strips all block-level HTML elements from the field value, - * it can be safely placed inside of other inline elements - * without the risk of breaking the HTML structure. - * @since 3.3.0 - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\Field - */ - 'inline' => function (Field $field) { - // List of valid inline elements taken from: https://developer.mozilla.org/de/docs/Web/HTML/Inline_elemente - // Obsolete elements, script tags, image maps and form elements have - // been excluded for safety reasons and as they are most likely not - // needed in most cases. - $field->value = strip_tags($field->value, Html::$inlineList); - return $field; - }, + /** + * Strips all block-level HTML elements from the field value, + * it can be safely placed inside of other inline elements + * without the risk of breaking the HTML structure. + * @since 3.3.0 + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\Field + */ + 'inline' => function (Field $field) { + // List of valid inline elements taken from: https://developer.mozilla.org/de/docs/Web/HTML/Inline_elemente + // Obsolete elements, script tags, image maps and form elements have + // been excluded for safety reasons and as they are most likely not + // needed in most cases. + $field->value = strip_tags($field->value, Html::$inlineList); + return $field; + }, - /** - * Converts the field content from Markdown/Kirbytext to valid HTML - * - * @param \Kirby\Cms\Field $field - * @param array $options - * @return \Kirby\Cms\Field - */ - 'kirbytext' => function (Field $field, array $options = []) use ($app) { - $field->value = $app->kirbytext($field->value, A::merge($options, [ - 'parent' => $field->parent(), - 'field' => $field - ])); + /** + * Converts the field content from Markdown/Kirbytext to valid HTML + * + * @param \Kirby\Cms\Field $field + * @param array $options + * @return \Kirby\Cms\Field + */ + 'kirbytext' => function (Field $field, array $options = []) use ($app) { + $field->value = $app->kirbytext($field->value, A::merge($options, [ + 'parent' => $field->parent(), + 'field' => $field + ])); - return $field; - }, + return $field; + }, - /** - * Converts the field content from inline Markdown/Kirbytext - * to valid HTML - * @since 3.1.0 - * - * @param \Kirby\Cms\Field $field - * @param array $options - * @return \Kirby\Cms\Field - */ - 'kirbytextinline' => function (Field $field, array $options = []) use ($app) { - $field->value = $app->kirbytext($field->value, A::merge($options, [ - 'parent' => $field->parent(), - 'field' => $field, - 'markdown' => [ - 'inline' => true - ] - ])); + /** + * Converts the field content from inline Markdown/Kirbytext + * to valid HTML + * @since 3.1.0 + * + * @param \Kirby\Cms\Field $field + * @param array $options + * @return \Kirby\Cms\Field + */ + 'kirbytextinline' => function (Field $field, array $options = []) use ($app) { + $field->value = $app->kirbytext($field->value, A::merge($options, [ + 'parent' => $field->parent(), + 'field' => $field, + 'markdown' => [ + 'inline' => true + ] + ])); - return $field; - }, + return $field; + }, - /** - * Parses all KirbyTags without also parsing Markdown - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\Field - */ - 'kirbytags' => function (Field $field) use ($app) { - $field->value = $app->kirbytags($field->value, [ - 'parent' => $field->parent(), - 'field' => $field - ]); + /** + * Parses all KirbyTags without also parsing Markdown + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\Field + */ + 'kirbytags' => function (Field $field) use ($app) { + $field->value = $app->kirbytags($field->value, [ + 'parent' => $field->parent(), + 'field' => $field + ]); - return $field; - }, + return $field; + }, - /** - * Converts the field content to lowercase - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\Field - */ - 'lower' => function (Field $field) { - $field->value = Str::lower($field->value); - return $field; - }, + /** + * Converts the field content to lowercase + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\Field + */ + 'lower' => function (Field $field) { + $field->value = Str::lower($field->value); + return $field; + }, - /** - * Converts markdown to valid HTML - * - * @param \Kirby\Cms\Field $field - * @param array $options - * @return \Kirby\Cms\Field - */ - 'markdown' => function (Field $field, array $options = []) use ($app) { - $field->value = $app->markdown($field->value, $options); - return $field; - }, + /** + * Converts markdown to valid HTML + * + * @param \Kirby\Cms\Field $field + * @param array $options + * @return \Kirby\Cms\Field + */ + 'markdown' => function (Field $field, array $options = []) use ($app) { + $field->value = $app->markdown($field->value, $options); + return $field; + }, - /** - * Converts all line breaks in the field content to `
` tags. - * @since 3.3.0 - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\Field - */ - 'nl2br' => function (Field $field) { - $field->value = nl2br($field->value, false); - return $field; - }, + /** + * Converts all line breaks in the field content to `
` tags. + * @since 3.3.0 + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\Field + */ + 'nl2br' => function (Field $field) { + $field->value = nl2br($field->value, false); + return $field; + }, - /** - * Uses the field value as Kirby query - * - * @param \Kirby\Cms\Field $field - * @param string|null $expect - * @return mixed - */ - 'query' => function (Field $field, string $expect = null) use ($app) { - if ($parent = $field->parent()) { - return $parent->query($field->value, $expect); - } + /** + * Uses the field value as Kirby query + * + * @param \Kirby\Cms\Field $field + * @param string|null $expect + * @return mixed + */ + 'query' => function (Field $field, string $expect = null) use ($app) { + if ($parent = $field->parent()) { + return $parent->query($field->value, $expect); + } - return Str::query($field->value, [ - 'kirby' => $app, - 'site' => $app->site(), - 'page' => $app->page() - ]); - }, + return Str::query($field->value, [ + 'kirby' => $app, + 'site' => $app->site(), + 'page' => $app->page() + ]); + }, - /** - * It parses any queries found in the field value. - * - * @param \Kirby\Cms\Field $field - * @param array $data - * @param string $fallback Fallback for tokens in the template that cannot be replaced - * @return \Kirby\Cms\Field - */ - 'replace' => function (Field $field, array $data = [], string $fallback = '') use ($app) { - if ($parent = $field->parent()) { - // never pass `null` as the $template to avoid the fallback to the model ID - $field->value = $parent->toString($field->value ?? '', $data, $fallback); - } else { - $field->value = Str::template($field->value, array_replace([ - 'kirby' => $app, - 'site' => $app->site(), - 'page' => $app->page() - ], $data), ['fallback' => $fallback]); - } + /** + * It parses any queries found in the field value. + * + * @param \Kirby\Cms\Field $field + * @param array $data + * @param string $fallback Fallback for tokens in the template that cannot be replaced + * @return \Kirby\Cms\Field + */ + 'replace' => function (Field $field, array $data = [], string $fallback = '') use ($app) { + if ($parent = $field->parent()) { + // never pass `null` as the $template to avoid the fallback to the model ID + $field->value = $parent->toString($field->value ?? '', $data, $fallback); + } else { + $field->value = Str::template($field->value, array_replace([ + 'kirby' => $app, + 'site' => $app->site(), + 'page' => $app->page() + ], $data), ['fallback' => $fallback]); + } - return $field; - }, + return $field; + }, - /** - * Cuts the string after the given length and - * adds "…" if it is longer - * - * @param \Kirby\Cms\Field $field - * @param int $length The number of characters in the string - * @param string $appendix An optional replacement for the missing rest - * @return \Kirby\Cms\Field - */ - 'short' => function (Field $field, int $length, string $appendix = '…') { - $field->value = Str::short($field->value, $length, $appendix); - return $field; - }, + /** + * Cuts the string after the given length and + * adds "…" if it is longer + * + * @param \Kirby\Cms\Field $field + * @param int $length The number of characters in the string + * @param string $appendix An optional replacement for the missing rest + * @return \Kirby\Cms\Field + */ + 'short' => function (Field $field, int $length, string $appendix = '…') { + $field->value = Str::short($field->value, $length, $appendix); + return $field; + }, - /** - * Converts the field content to a slug - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\Field - */ - 'slug' => function (Field $field) { - $field->value = Str::slug($field->value); - return $field; - }, + /** + * Converts the field content to a slug + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\Field + */ + 'slug' => function (Field $field) { + $field->value = Str::slug($field->value); + return $field; + }, - /** - * Applies SmartyPants to the field - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\Field - */ - 'smartypants' => function (Field $field) use ($app) { - $field->value = $app->smartypants($field->value); - return $field; - }, + /** + * Applies SmartyPants to the field + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\Field + */ + 'smartypants' => function (Field $field) use ($app) { + $field->value = $app->smartypants($field->value); + return $field; + }, - /** - * Splits the field content into an array - * - * @param \Kirby\Cms\Field $field - * @return array - */ - 'split' => function (Field $field, $separator = ',') { - return Str::split((string)$field->value, $separator); - }, + /** + * Splits the field content into an array + * + * @param \Kirby\Cms\Field $field + * @return array + */ + 'split' => function (Field $field, $separator = ',') { + return Str::split((string)$field->value, $separator); + }, - /** - * Converts the field content to uppercase - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\Field - */ - 'upper' => function (Field $field) { - $field->value = Str::upper($field->value); - return $field; - }, + /** + * Converts the field content to uppercase + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\Field + */ + 'upper' => function (Field $field) { + $field->value = Str::upper($field->value); + return $field; + }, - /** - * Avoids typographical widows in strings by replacing - * the last space with ` ` - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\Field - */ - 'widont' => function (Field $field) { - $field->value = Str::widont($field->value); - return $field; - }, + /** + * Avoids typographical widows in strings by replacing + * the last space with ` ` + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\Field + */ + 'widont' => function (Field $field) { + $field->value = Str::widont($field->value); + return $field; + }, - /** - * Converts the field content to valid XML - * - * @param \Kirby\Cms\Field $field - * @return \Kirby\Cms\Field - */ - 'xml' => function (Field $field) { - $field->value = Xml::encode($field->value); - return $field; - }, + /** + * Converts the field content to valid XML + * + * @param \Kirby\Cms\Field $field + * @return \Kirby\Cms\Field + */ + 'xml' => function (Field $field) { + $field->value = Xml::encode($field->value); + return $field; + }, - // aliases + // aliases - /** - * Parses yaml in the field content and returns an array - * - * @param \Kirby\Cms\Field $field - * @return array - */ - 'yaml' => function (Field $field): array { - return $field->toData('yaml'); - }, + /** + * Parses yaml in the field content and returns an array + * + * @param \Kirby\Cms\Field $field + * @return array + */ + 'yaml' => function (Field $field): array { + return $field->toData('yaml'); + }, - ]; + ]; }; diff --git a/kirby/config/presets/files.php b/kirby/config/presets/files.php index 9299701..c5cea1d 100755 --- a/kirby/config/presets/files.php +++ b/kirby/config/presets/files.php @@ -3,24 +3,24 @@ use Kirby\Toolkit\I18n; return function (array $props) { - $props['sections'] = [ - 'files' => [ - 'headline' => $props['headline'] ?? I18n::translate('files'), - 'type' => 'files', - 'layout' => $props['layout'] ?? 'cards', - 'template' => $props['template'] ?? null, - 'image' => $props['image'] ?? null, - 'info' => '{{ file.dimensions }}' - ] - ]; + $props['sections'] = [ + 'files' => [ + 'headline' => $props['headline'] ?? I18n::translate('files'), + 'type' => 'files', + 'layout' => $props['layout'] ?? 'cards', + 'template' => $props['template'] ?? null, + 'image' => $props['image'] ?? null, + 'info' => '{{ file.dimensions }}' + ] + ]; - // remove global options - unset( - $props['headline'], - $props['layout'], - $props['template'], - $props['image'] - ); + // remove global options + unset( + $props['headline'], + $props['layout'], + $props['template'], + $props['image'] + ); - return $props; + return $props; }; diff --git a/kirby/config/presets/page.php b/kirby/config/presets/page.php index 49d2daf..fa0e6e6 100755 --- a/kirby/config/presets/page.php +++ b/kirby/config/presets/page.php @@ -3,72 +3,72 @@ use Kirby\Toolkit\I18n; return function ($props) { - $section = function ($defaults, $props) { - if ($props === true) { - $props = []; - } + $section = function ($defaults, $props) { + if ($props === true) { + $props = []; + } - if (is_string($props) === true) { - $props = [ - 'headline' => $props - ]; - } + if (is_string($props) === true) { + $props = [ + 'headline' => $props + ]; + } - return array_replace_recursive($defaults, $props); - }; + return array_replace_recursive($defaults, $props); + }; - if (empty($props['sidebar']) === false) { - $sidebar = $props['sidebar']; - } else { - $sidebar = []; + if (empty($props['sidebar']) === false) { + $sidebar = $props['sidebar']; + } else { + $sidebar = []; - $pages = $props['pages'] ?? []; - $files = $props['files'] ?? []; + $pages = $props['pages'] ?? []; + $files = $props['files'] ?? []; - if ($pages !== false) { - $sidebar['pages'] = $section([ - 'headline' => I18n::translate('pages'), - 'type' => 'pages', - 'status' => 'all', - 'layout' => 'list', - ], $pages); - } + if ($pages !== false) { + $sidebar['pages'] = $section([ + 'headline' => I18n::translate('pages'), + 'type' => 'pages', + 'status' => 'all', + 'layout' => 'list', + ], $pages); + } - if ($files !== false) { - $sidebar['files'] = $section([ - 'headline' => I18n::translate('files'), - 'type' => 'files', - 'layout' => 'list' - ], $files); - } - } + if ($files !== false) { + $sidebar['files'] = $section([ + 'headline' => I18n::translate('files'), + 'type' => 'files', + 'layout' => 'list' + ], $files); + } + } - if (empty($sidebar) === true) { - $props['fields'] = $props['fields'] ?? []; + if (empty($sidebar) === true) { + $props['fields'] = $props['fields'] ?? []; - unset( - $props['files'], - $props['pages'] - ); - } else { - $props['columns'] = [ - [ - 'width' => '2/3', - 'fields' => $props['fields'] ?? [] - ], - [ - 'width' => '1/3', - 'sections' => $sidebar - ], - ]; + unset( + $props['files'], + $props['pages'] + ); + } else { + $props['columns'] = [ + [ + 'width' => '2/3', + 'fields' => $props['fields'] ?? [] + ], + [ + 'width' => '1/3', + 'sections' => $sidebar + ], + ]; - unset( - $props['fields'], - $props['files'], - $props['pages'], - $props['sidebar'] - ); - } + unset( + $props['fields'], + $props['files'], + $props['pages'], + $props['sidebar'] + ); + } - return $props; + return $props; }; diff --git a/kirby/config/presets/pages.php b/kirby/config/presets/pages.php index ff590bc..21e76aa 100755 --- a/kirby/config/presets/pages.php +++ b/kirby/config/presets/pages.php @@ -4,56 +4,56 @@ use Kirby\Toolkit\I18n; return function (array $props) { - // load the general templates setting for all sections - $templates = $props['templates'] ?? null; + // load the general templates setting for all sections + $templates = $props['templates'] ?? null; - $section = function ($headline, $status, $props) use ($templates) { - $defaults = [ - 'headline' => $headline, - 'type' => 'pages', - 'layout' => 'list', - 'status' => $status - ]; + $section = function ($headline, $status, $props) use ($templates) { + $defaults = [ + 'headline' => $headline, + 'type' => 'pages', + 'layout' => 'list', + 'status' => $status + ]; - if ($props === true) { - $props = []; - } + if ($props === true) { + $props = []; + } - if (is_string($props) === true) { - $props = [ - 'headline' => $props - ]; - } + if (is_string($props) === true) { + $props = [ + 'headline' => $props + ]; + } - // inject the global templates definition - if (empty($templates) === false) { - $props['templates'] = $props['templates'] ?? $templates; - } + // inject the global templates definition + if (empty($templates) === false) { + $props['templates'] = $props['templates'] ?? $templates; + } - return array_replace_recursive($defaults, $props); - }; + return array_replace_recursive($defaults, $props); + }; - $sections = []; + $sections = []; - $drafts = $props['drafts'] ?? []; - $unlisted = $props['unlisted'] ?? false; - $listed = $props['listed'] ?? []; + $drafts = $props['drafts'] ?? []; + $unlisted = $props['unlisted'] ?? false; + $listed = $props['listed'] ?? []; - if ($drafts !== false) { - $sections['drafts'] = $section(I18n::translate('pages.status.draft'), 'drafts', $drafts); - } + if ($drafts !== false) { + $sections['drafts'] = $section(I18n::translate('pages.status.draft'), 'drafts', $drafts); + } - if ($unlisted !== false) { - $sections['unlisted'] = $section(I18n::translate('pages.status.unlisted'), 'unlisted', $unlisted); - } + if ($unlisted !== false) { + $sections['unlisted'] = $section(I18n::translate('pages.status.unlisted'), 'unlisted', $unlisted); + } - if ($listed !== false) { - $sections['listed'] = $section(I18n::translate('pages.status.listed'), 'listed', $listed); - } + if ($listed !== false) { + $sections['listed'] = $section(I18n::translate('pages.status.listed'), 'listed', $listed); + } - // cleaning up - unset($props['drafts'], $props['unlisted'], $props['listed'], $props['templates']); + // cleaning up + unset($props['drafts'], $props['unlisted'], $props['listed'], $props['templates']); - return array_merge($props, ['sections' => $sections]); + return array_merge($props, ['sections' => $sections]); }; diff --git a/kirby/config/routes.php b/kirby/config/routes.php index 2c55031..134ad60 100755 --- a/kirby/config/routes.php +++ b/kirby/config/routes.php @@ -8,141 +8,141 @@ use Kirby\Panel\Plugins; use Kirby\Toolkit\Str; return function ($kirby) { - $api = $kirby->option('api.slug', 'api'); - $panel = $kirby->option('panel.slug', 'panel'); - $index = $kirby->url('index'); - $media = $kirby->url('media'); + $api = $kirby->option('api.slug', 'api'); + $panel = $kirby->option('panel.slug', 'panel'); + $index = $kirby->url('index'); + $media = $kirby->url('media'); - if (Str::startsWith($media, $index) === true) { - $media = Str::after($media, $index); - } else { - // media URL is outside of the site, we can't make routing work; - // fall back to the standard media route - $media = 'media'; - } + if (Str::startsWith($media, $index) === true) { + $media = Str::after($media, $index); + } else { + // media URL is outside of the site, we can't make routing work; + // fall back to the standard media route + $media = 'media'; + } - /** - * Before routes are running before the - * plugin routes and cannot be overwritten by - * plugins. - */ - $before = [ - [ - 'pattern' => $api . '/(:all)', - 'method' => 'ALL', - 'env' => 'api', - 'action' => function ($path = null) use ($kirby) { - if ($kirby->option('api') === false) { - return null; - } + /** + * Before routes are running before the + * plugin routes and cannot be overwritten by + * plugins. + */ + $before = [ + [ + 'pattern' => $api . '/(:all)', + 'method' => 'ALL', + 'env' => 'api', + 'action' => function ($path = null) use ($kirby) { + if ($kirby->option('api') === false) { + return null; + } - $request = $kirby->request(); + $request = $kirby->request(); - return $kirby->api()->render($path, $this->method(), [ - 'body' => $request->body()->toArray(), - 'files' => $request->files()->toArray(), - 'headers' => $request->headers(), - 'query' => $request->query()->toArray(), - ]); - } - ], - [ - 'pattern' => $media . '/plugins/index.(css|js)', - 'env' => 'media', - 'action' => function (string $type) use ($kirby) { - $plugins = new Plugins(); + return $kirby->api()->render($path, $this->method(), [ + 'body' => $request->body()->toArray(), + 'files' => $request->files()->toArray(), + 'headers' => $request->headers(), + 'query' => $request->query()->toArray(), + ]); + } + ], + [ + 'pattern' => $media . '/plugins/index.(css|js)', + 'env' => 'media', + 'action' => function (string $type) use ($kirby) { + $plugins = new Plugins(); - return $kirby - ->response() - ->type($type) - ->body($plugins->read($type)); - } - ], - [ - 'pattern' => $media . '/plugins/(:any)/(:any)/(:all).(css|map|gif|js|mjs|jpg|png|svg|webp|avif|woff2|woff|json)', - 'env' => 'media', - 'action' => function (string $provider, string $pluginName, string $filename, string $extension) { - return PluginAssets::resolve($provider . '/' . $pluginName, $filename . '.' . $extension); - } - ], - [ - 'pattern' => $media . '/pages/(:all)/(:any)/(:any)', - 'env' => 'media', - 'action' => function ($path, $hash, $filename) use ($kirby) { - return Media::link($kirby->page($path), $hash, $filename); - } - ], - [ - 'pattern' => $media . '/site/(:any)/(:any)', - 'env' => 'media', - 'action' => function ($hash, $filename) use ($kirby) { - return Media::link($kirby->site(), $hash, $filename); - } - ], - [ - 'pattern' => $media . '/users/(:any)/(:any)/(:any)', - 'env' => 'media', - 'action' => function ($id, $hash, $filename) use ($kirby) { - return Media::link($kirby->user($id), $hash, $filename); - } - ], - [ - 'pattern' => $media . '/assets/(:all)/(:any)/(:any)', - 'env' => 'media', - 'action' => function ($path, $hash, $filename) { - return Media::thumb($path, $hash, $filename); - } - ], - [ - 'pattern' => $panel . '/(:all?)', - 'method' => 'ALL', - 'env' => 'panel', - 'action' => function ($path = null) { - return Panel::router($path); - } - ], - ]; + return $kirby + ->response() + ->type($type) + ->body($plugins->read($type)); + } + ], + [ + 'pattern' => $media . '/plugins/(:any)/(:any)/(:all).(css|map|gif|js|mjs|jpg|png|svg|webp|avif|woff2|woff|json)', + 'env' => 'media', + 'action' => function (string $provider, string $pluginName, string $filename, string $extension) { + return PluginAssets::resolve($provider . '/' . $pluginName, $filename . '.' . $extension); + } + ], + [ + 'pattern' => $media . '/pages/(:all)/(:any)/(:any)', + 'env' => 'media', + 'action' => function ($path, $hash, $filename) use ($kirby) { + return Media::link($kirby->page($path), $hash, $filename); + } + ], + [ + 'pattern' => $media . '/site/(:any)/(:any)', + 'env' => 'media', + 'action' => function ($hash, $filename) use ($kirby) { + return Media::link($kirby->site(), $hash, $filename); + } + ], + [ + 'pattern' => $media . '/users/(:any)/(:any)/(:any)', + 'env' => 'media', + 'action' => function ($id, $hash, $filename) use ($kirby) { + return Media::link($kirby->user($id), $hash, $filename); + } + ], + [ + 'pattern' => $media . '/assets/(:all)/(:any)/(:any)', + 'env' => 'media', + 'action' => function ($path, $hash, $filename) { + return Media::thumb($path, $hash, $filename); + } + ], + [ + 'pattern' => $panel . '/(:all?)', + 'method' => 'ALL', + 'env' => 'panel', + 'action' => function ($path = null) { + return Panel::router($path); + } + ], + ]; - // Multi-language setup - if ($kirby->multilang() === true) { - $after = LanguageRoutes::create($kirby); - } else { + // Multi-language setup + if ($kirby->multilang() === true) { + $after = LanguageRoutes::create($kirby); + } else { - // Single-language home - $after[] = [ - 'pattern' => '', - 'method' => 'ALL', - 'env' => 'site', - 'action' => function () use ($kirby) { - return $kirby->resolve(); - } - ]; + // Single-language home + $after[] = [ + 'pattern' => '', + 'method' => 'ALL', + 'env' => 'site', + 'action' => function () use ($kirby) { + return $kirby->resolve(); + } + ]; - // redirect the home page folder to the real homepage - $after[] = [ - 'pattern' => $kirby->option('home', 'home'), - 'method' => 'ALL', - 'env' => 'site', - 'action' => function () use ($kirby) { - return $kirby - ->response() - ->redirect($kirby->site()->url()); - } - ]; + // redirect the home page folder to the real homepage + $after[] = [ + 'pattern' => $kirby->option('home', 'home'), + 'method' => 'ALL', + 'env' => 'site', + 'action' => function () use ($kirby) { + return $kirby + ->response() + ->redirect($kirby->site()->url()); + } + ]; - // Single-language subpages - $after[] = [ - 'pattern' => '(:all)', - 'method' => 'ALL', - 'env' => 'site', - 'action' => function (string $path) use ($kirby) { - return $kirby->resolve($path); - } - ]; - } + // Single-language subpages + $after[] = [ + 'pattern' => '(:all)', + 'method' => 'ALL', + 'env' => 'site', + 'action' => function (string $path) use ($kirby) { + return $kirby->resolve($path); + } + ]; + } - return [ - 'before' => $before, - 'after' => $after - ]; + return [ + 'before' => $before, + 'after' => $after + ]; }; diff --git a/kirby/config/sections/fields.php b/kirby/config/sections/fields.php index 065f478..38565e5 100755 --- a/kirby/config/sections/fields.php +++ b/kirby/config/sections/fields.php @@ -3,55 +3,55 @@ use Kirby\Form\Form; return [ - 'props' => [ - 'fields' => function (array $fields = []) { - return $fields; - } - ], - 'computed' => [ - 'form' => function () { - $fields = $this->fields; - $disabled = $this->model->permissions()->update() === false; - $lang = $this->model->kirby()->languageCode(); - $content = $this->model->content($lang)->toArray(); + 'props' => [ + 'fields' => function (array $fields = []) { + return $fields; + } + ], + 'computed' => [ + 'form' => function () { + $fields = $this->fields; + $disabled = $this->model->permissions()->update() === false; + $lang = $this->model->kirby()->languageCode(); + $content = $this->model->content($lang)->toArray(); - if ($disabled === true) { - foreach ($fields as $key => $props) { - $fields[$key]['disabled'] = true; - } - } + if ($disabled === true) { + foreach ($fields as $key => $props) { + $fields[$key]['disabled'] = true; + } + } - return new Form([ - 'fields' => $fields, - 'values' => $content, - 'model' => $this->model, - 'strict' => true - ]); - }, - 'fields' => function () { - $fields = $this->form->fields()->toArray(); + return new Form([ + 'fields' => $fields, + 'values' => $content, + 'model' => $this->model, + 'strict' => true + ]); + }, + 'fields' => function () { + $fields = $this->form->fields()->toArray(); - if (is_a($this->model, 'Kirby\Cms\Page') === true || is_a($this->model, 'Kirby\Cms\Site') === true) { - // the title should never be updated directly via - // fields section to avoid conflicts with the rename dialog - unset($fields['title']); - } + if (is_a($this->model, 'Kirby\Cms\Page') === true || is_a($this->model, 'Kirby\Cms\Site') === true) { + // the title should never be updated directly via + // fields section to avoid conflicts with the rename dialog + unset($fields['title']); + } - foreach ($fields as $index => $props) { - unset($fields[$index]['value']); - } + foreach ($fields as $index => $props) { + unset($fields[$index]['value']); + } - return $fields; - } - ], - 'methods' => [ - 'errors' => function () { - return $this->form->errors(); - } - ], - 'toArray' => function () { - return [ - 'fields' => $this->fields, - ]; - } + return $fields; + } + ], + 'methods' => [ + 'errors' => function () { + return $this->form->errors(); + } + ], + 'toArray' => function () { + return [ + 'fields' => $this->fields, + ]; + } ]; diff --git a/kirby/config/sections/files.php b/kirby/config/sections/files.php index 91eae0e..d25e167 100755 --- a/kirby/config/sections/files.php +++ b/kirby/config/sections/files.php @@ -4,203 +4,203 @@ use Kirby\Cms\File; use Kirby\Toolkit\I18n; return [ - 'mixins' => [ - 'details', - 'empty', - 'headline', - 'help', - 'layout', - 'min', - 'max', - 'pagination', - 'parent', - 'search', - 'sort' - ], - 'props' => [ - /** - * Filters all files by template and also sets the template, which will be used for all uploads - */ - 'template' => function (string $template = null) { - return $template; - }, - /** - * Setup for the main text in the list or cards. By default this will display the filename. - */ - 'text' => function ($text = '{{ file.filename }}') { - return I18n::translate($text, $text); - } - ], - 'computed' => [ - 'accept' => function () { - if ($this->template) { - $file = new File([ - 'filename' => 'tmp', - 'parent' => $this->model(), - 'template' => $this->template - ]); + 'mixins' => [ + 'details', + 'empty', + 'headline', + 'help', + 'layout', + 'min', + 'max', + 'pagination', + 'parent', + 'search', + 'sort' + ], + 'props' => [ + /** + * Filters all files by template and also sets the template, which will be used for all uploads + */ + 'template' => function (string $template = null) { + return $template; + }, + /** + * Setup for the main text in the list or cards. By default this will display the filename. + */ + 'text' => function ($text = '{{ file.filename }}') { + return I18n::translate($text, $text); + } + ], + 'computed' => [ + 'accept' => function () { + if ($this->template) { + $file = new File([ + 'filename' => 'tmp', + 'parent' => $this->model(), + 'template' => $this->template + ]); - return $file->blueprint()->acceptMime(); - } + return $file->blueprint()->acceptMime(); + } - return null; - }, - 'parent' => function () { - return $this->parentModel(); - }, - 'files' => function () { - $files = $this->parent->files()->template($this->template); + return null; + }, + 'parent' => function () { + return $this->parentModel(); + }, + 'files' => function () { + $files = $this->parent->files()->template($this->template); - // filter out all protected files - $files = $files->filter('isReadable', true); + // filter out all protected files + $files = $files->filter('isReadable', true); - // search - if ($this->search === true && empty($this->searchterm) === false) { - $files = $files->search($this->searchterm); - } + // search + if ($this->search === true && empty($this->searchterm) === false) { + $files = $files->search($this->searchterm); + } - // sort - if ($this->sortBy) { - $files = $files->sort(...$files::sortArgs($this->sortBy)); - } else { - $files = $files->sorted(); - } + // sort + if ($this->sortBy) { + $files = $files->sort(...$files::sortArgs($this->sortBy)); + } else { + $files = $files->sorted(); + } - // flip - if ($this->flip === true) { - $files = $files->flip(); - } + // flip + if ($this->flip === true) { + $files = $files->flip(); + } - // apply the default pagination - $files = $files->paginate([ - 'page' => $this->page, - 'limit' => $this->limit, - 'method' => 'none' // the page is manually provided - ]); + // apply the default pagination + $files = $files->paginate([ + 'page' => $this->page, + 'limit' => $this->limit, + 'method' => 'none' // the page is manually provided + ]); - return $files; - }, - 'data' => function () { - $data = []; + return $files; + }, + 'data' => function () { + $data = []; - // the drag text needs to be absolute when the files come from - // a different parent model - $dragTextAbsolute = $this->model->is($this->parent) === false; + // the drag text needs to be absolute when the files come from + // a different parent model + $dragTextAbsolute = $this->model->is($this->parent) === false; - foreach ($this->files as $file) { - $panel = $file->panel(); + foreach ($this->files as $file) { + $panel = $file->panel(); - $item = [ - 'dragText' => $panel->dragText('auto', $dragTextAbsolute), - 'extension' => $file->extension(), - 'filename' => $file->filename(), - 'id' => $file->id(), - 'image' => $panel->image( - $this->image, - $this->layout === 'table' ? 'list' : $this->layout - ), - 'info' => $file->toSafeString($this->info ?? false), - 'link' => $panel->url(true), - 'mime' => $file->mime(), - 'parent' => $file->parent()->panel()->path(), - 'template' => $file->template(), - 'text' => $file->toSafeString($this->text), - 'url' => $file->url(), - ]; + $item = [ + 'dragText' => $panel->dragText('auto', $dragTextAbsolute), + 'extension' => $file->extension(), + 'filename' => $file->filename(), + 'id' => $file->id(), + 'image' => $panel->image( + $this->image, + $this->layout === 'table' ? 'list' : $this->layout + ), + 'info' => $file->toSafeString($this->info ?? false), + 'link' => $panel->url(true), + 'mime' => $file->mime(), + 'parent' => $file->parent()->panel()->path(), + 'template' => $file->template(), + 'text' => $file->toSafeString($this->text), + 'url' => $file->url(), + ]; - if ($this->layout === 'table') { - $item = $this->columnsValues($item, $file); - } + if ($this->layout === 'table') { + $item = $this->columnsValues($item, $file); + } - $data[] = $item; - } + $data[] = $item; + } - return $data; - }, - 'total' => function () { - return $this->files->pagination()->total(); - }, - 'errors' => function () { - $errors = []; + return $data; + }, + 'total' => function () { + return $this->files->pagination()->total(); + }, + 'errors' => function () { + $errors = []; - if ($this->validateMax() === false) { - $errors['max'] = I18n::template('error.section.files.max.' . I18n::form($this->max), [ - 'max' => $this->max, - 'section' => $this->headline - ]); - } + if ($this->validateMax() === false) { + $errors['max'] = I18n::template('error.section.files.max.' . I18n::form($this->max), [ + 'max' => $this->max, + 'section' => $this->headline + ]); + } - if ($this->validateMin() === false) { - $errors['min'] = I18n::template('error.section.files.min.' . I18n::form($this->min), [ - 'min' => $this->min, - 'section' => $this->headline - ]); - } + if ($this->validateMin() === false) { + $errors['min'] = I18n::template('error.section.files.min.' . I18n::form($this->min), [ + 'min' => $this->min, + 'section' => $this->headline + ]); + } - if (empty($errors) === true) { - return []; - } + if (empty($errors) === true) { + return []; + } - return [ - $this->name => [ - 'label' => $this->headline, - 'message' => $errors, - ] - ]; - }, - 'pagination' => function () { - return $this->pagination(); - }, - 'upload' => function () { - if ($this->isFull() === true) { - return false; - } + return [ + $this->name => [ + 'label' => $this->headline, + 'message' => $errors, + ] + ]; + }, + 'pagination' => function () { + return $this->pagination(); + }, + 'upload' => function () { + if ($this->isFull() === true) { + return false; + } - // count all uploaded files - $total = count($this->data); - $max = $this->max ? $this->max - $total : null; + // count all uploaded files + $total = count($this->data); + $max = $this->max ? $this->max - $total : null; - if ($this->max && $total === $this->max - 1) { - $multiple = false; - } else { - $multiple = true; - } + if ($this->max && $total === $this->max - 1) { + $multiple = false; + } else { + $multiple = true; + } - $template = $this->template === 'default' ? null : $this->template; + $template = $this->template === 'default' ? null : $this->template; - return [ - 'accept' => $this->accept, - 'multiple' => $multiple, - 'max' => $max, - 'api' => $this->parent->apiUrl(true) . '/files', - 'attributes' => array_filter([ - 'sort' => $this->sortable === true ? $total + 1 : null, - 'template' => $template - ]) - ]; - } - ], - 'toArray' => function () { - return [ - 'data' => $this->data, - 'errors' => $this->errors, - 'options' => [ - 'accept' => $this->accept, - 'apiUrl' => $this->parent->apiUrl(true), - 'columns' => $this->columns, - 'empty' => $this->empty, - 'headline' => $this->headline, - 'help' => $this->help, - 'layout' => $this->layout, - 'link' => $this->link(), - 'max' => $this->max, - 'min' => $this->min, - 'search' => $this->search, - 'size' => $this->size, - 'sortable' => $this->sortable, - 'upload' => $this->upload - ], - 'pagination' => $this->pagination - ]; - } + return [ + 'accept' => $this->accept, + 'multiple' => $multiple, + 'max' => $max, + 'api' => $this->parent->apiUrl(true) . '/files', + 'attributes' => array_filter([ + 'sort' => $this->sortable === true ? $total + 1 : null, + 'template' => $template + ]) + ]; + } + ], + 'toArray' => function () { + return [ + 'data' => $this->data, + 'errors' => $this->errors, + 'options' => [ + 'accept' => $this->accept, + 'apiUrl' => $this->parent->apiUrl(true), + 'columns' => $this->columns, + 'empty' => $this->empty, + 'headline' => $this->headline, + 'help' => $this->help, + 'layout' => $this->layout, + 'link' => $this->link(), + 'max' => $this->max, + 'min' => $this->min, + 'search' => $this->search, + 'size' => $this->size, + 'sortable' => $this->sortable, + 'upload' => $this->upload + ], + 'pagination' => $this->pagination + ]; + } ]; diff --git a/kirby/config/sections/info.php b/kirby/config/sections/info.php index 555af89..e348bd4 100755 --- a/kirby/config/sections/info.php +++ b/kirby/config/sections/info.php @@ -3,31 +3,31 @@ use Kirby\Toolkit\I18n; return [ - 'mixins' => [ - 'headline', - ], - 'props' => [ - 'text' => function ($text = null) { - return I18n::translate($text, $text); - }, - 'theme' => function (string $theme = null) { - return $theme; - } - ], - 'computed' => [ - 'text' => function () { - if ($this->text) { - $text = $this->model()->toSafeString($this->text); - $text = $this->kirby()->kirbytext($text); - return $text; - } - }, - ], - 'toArray' => function () { - return [ - 'headline' => $this->headline, - 'text' => $this->text, - 'theme' => $this->theme - ]; - } + 'mixins' => [ + 'headline', + ], + 'props' => [ + 'text' => function ($text = null) { + return I18n::translate($text, $text); + }, + 'theme' => function (string $theme = null) { + return $theme; + } + ], + 'computed' => [ + 'text' => function () { + if ($this->text) { + $text = $this->model()->toSafeString($this->text); + $text = $this->kirby()->kirbytext($text); + return $text; + } + }, + ], + 'toArray' => function () { + return [ + 'headline' => $this->headline, + 'text' => $this->text, + 'theme' => $this->theme + ]; + } ]; diff --git a/kirby/config/sections/mixins/details.php b/kirby/config/sections/mixins/details.php index 1f2f58b..3d2c928 100755 --- a/kirby/config/sections/mixins/details.php +++ b/kirby/config/sections/mixins/details.php @@ -3,34 +3,34 @@ use Kirby\Toolkit\I18n; return [ - 'props' => [ - /** - * Image options to control the source and look of preview - */ - 'image' => function ($image = null) { - return $image ?? []; - }, - /** - * Optional info text setup. Info text is shown on the right (lists, cardlets) or below (cards) the title. - */ - 'info' => function ($info = null) { - return I18n::translate($info, $info); - }, - /** - * Setup for the main text in the list or cards. By default this will display the title. - */ - 'text' => function ($text = '{{ model.title }}') { - return I18n::translate($text, $text); - } - ], - 'methods' => [ - 'link' => function () { - $modelLink = $this->model->panel()->url(true); - $parentLink = $this->parent->panel()->url(true); + 'props' => [ + /** + * Image options to control the source and look of preview + */ + 'image' => function ($image = null) { + return $image ?? []; + }, + /** + * Optional info text setup. Info text is shown on the right (lists, cardlets) or below (cards) the title. + */ + 'info' => function ($info = null) { + return I18n::translate($info, $info); + }, + /** + * Setup for the main text in the list or cards. By default this will display the title. + */ + 'text' => function ($text = '{{ model.title }}') { + return I18n::translate($text, $text); + } + ], + 'methods' => [ + 'link' => function () { + $modelLink = $this->model->panel()->url(true); + $parentLink = $this->parent->panel()->url(true); - if ($modelLink !== $parentLink) { - return $parentLink; - } - } - ] + if ($modelLink !== $parentLink) { + return $parentLink; + } + } + ] ]; diff --git a/kirby/config/sections/mixins/empty.php b/kirby/config/sections/mixins/empty.php index 967b252..97c2404 100755 --- a/kirby/config/sections/mixins/empty.php +++ b/kirby/config/sections/mixins/empty.php @@ -3,19 +3,19 @@ use Kirby\Toolkit\I18n; return [ - 'props' => [ - /** - * Sets the text for the empty state box - */ - 'empty' => function ($empty = null) { - return I18n::translate($empty, $empty); - } - ], - 'computed' => [ - 'empty' => function () { - if ($this->empty) { - return $this->model()->toSafeString($this->empty); - } - } - ] + 'props' => [ + /** + * Sets the text for the empty state box + */ + 'empty' => function ($empty = null) { + return I18n::translate($empty, $empty); + } + ], + 'computed' => [ + 'empty' => function () { + if ($this->empty) { + return $this->model()->toSafeString($this->empty); + } + } + ] ]; diff --git a/kirby/config/sections/mixins/headline.php b/kirby/config/sections/mixins/headline.php index 5e426f9..df323c6 100755 --- a/kirby/config/sections/mixins/headline.php +++ b/kirby/config/sections/mixins/headline.php @@ -4,39 +4,39 @@ use Kirby\Cms\Helpers; use Kirby\Toolkit\I18n; return [ - 'props' => [ - /** - * The headline for the section. This can be a simple string or a template with additional info from the parent page. - * @todo remove in 3.9.0 - */ - 'headline' => function ($headline = null) { - // TODO: add deprecation notive in 3.8.0 - // if ($headline !== null) { - // Helpers::deprecated('`headline` prop for sections has been deprecated and will be removed in Kirby 3.9.0. Use `label` instead.'); - // } + 'props' => [ + /** + * The headline for the section. This can be a simple string or a template with additional info from the parent page. + * @todo remove in 3.9.0 + */ + 'headline' => function ($headline = null) { + // TODO: add deprecation notive in 3.8.0 + // if ($headline !== null) { + // Helpers::deprecated('`headline` prop for sections has been deprecated and will be removed in Kirby 3.9.0. Use `label` instead.'); + // } - return I18n::translate($headline, $headline); - }, - /** - * The label for the section. This can be a simple string or - * a template with additional info from the parent page. - * Replaces the `headline` prop. - */ - 'label' => function ($label = null) { - return I18n::translate($label, $label); - } - ], - 'computed' => [ - 'headline' => function () { - if ($this->headline) { - return $this->model()->toString($this->headline); - } + return I18n::translate($headline, $headline); + }, + /** + * The label for the section. This can be a simple string or + * a template with additional info from the parent page. + * Replaces the `headline` prop. + */ + 'label' => function ($label = null) { + return I18n::translate($label, $label); + } + ], + 'computed' => [ + 'headline' => function () { + if ($this->headline) { + return $this->model()->toString($this->headline); + } - if ($this->label) { - return $this->model()->toString($this->label); - } + if ($this->label) { + return $this->model()->toString($this->label); + } - return ucfirst($this->name); - } - ] + return ucfirst($this->name); + } + ] ]; diff --git a/kirby/config/sections/mixins/help.php b/kirby/config/sections/mixins/help.php index 1619e32..c95db08 100755 --- a/kirby/config/sections/mixins/help.php +++ b/kirby/config/sections/mixins/help.php @@ -3,21 +3,21 @@ use Kirby\Toolkit\I18n; return [ - 'props' => [ - /** - * Sets the help text - */ - 'help' => function ($help = null) { - return I18n::translate($help, $help); - } - ], - 'computed' => [ - 'help' => function () { - if ($this->help) { - $help = $this->model()->toSafeString($this->help); - $help = $this->kirby()->kirbytext($help); - return $help; - } - } - ] + 'props' => [ + /** + * Sets the help text + */ + 'help' => function ($help = null) { + return I18n::translate($help, $help); + } + ], + 'computed' => [ + 'help' => function () { + if ($this->help) { + $help = $this->model()->toSafeString($this->help); + $help = $this->kirby()->kirbytext($help); + return $help; + } + } + ] ]; diff --git a/kirby/config/sections/mixins/layout.php b/kirby/config/sections/mixins/layout.php index 83f7b9a..1b5ee6e 100755 --- a/kirby/config/sections/mixins/layout.php +++ b/kirby/config/sections/mixins/layout.php @@ -4,122 +4,122 @@ use Kirby\Toolkit\I18n; use Kirby\Toolkit\Str; return [ - 'props' => [ - /** - * Columns config for `layout: table` - */ - 'columns' => function (array $columns = null) { - return $columns ?? []; - }, - /** - * Section layout. - * Available layout methods: `list`, `cardlets`, `cards`, `table`. - */ - 'layout' => function (string $layout = 'list') { - $layouts = ['list', 'cardlets', 'cards', 'table']; - return in_array($layout, $layouts) ? $layout : 'list'; - }, - /** - * The size option controls the size of cards. By default cards are auto-sized and the cards grid will always fill the full width. With a size you can disable auto-sizing. Available sizes: `tiny`, `small`, `medium`, `large`, `huge` - */ - 'size' => function (string $size = 'auto') { - return $size; - }, - ], - 'computed' => [ - 'columns' => function () { - $columns = []; + 'props' => [ + /** + * Columns config for `layout: table` + */ + 'columns' => function (array $columns = null) { + return $columns ?? []; + }, + /** + * Section layout. + * Available layout methods: `list`, `cardlets`, `cards`, `table`. + */ + 'layout' => function (string $layout = 'list') { + $layouts = ['list', 'cardlets', 'cards', 'table']; + return in_array($layout, $layouts) ? $layout : 'list'; + }, + /** + * The size option controls the size of cards. By default cards are auto-sized and the cards grid will always fill the full width. With a size you can disable auto-sizing. Available sizes: `tiny`, `small`, `medium`, `large`, `huge` + */ + 'size' => function (string $size = 'auto') { + return $size; + }, + ], + 'computed' => [ + 'columns' => function () { + $columns = []; - if ($this->layout !== 'table') { - return []; - } + if ($this->layout !== 'table') { + return []; + } - if ($this->image !== false) { - $columns['image'] = [ - 'label' => ' ', - 'mobile' => true, - 'type' => 'image', - 'width' => 'var(--table-row-height)' - ]; - } + if ($this->image !== false) { + $columns['image'] = [ + 'label' => ' ', + 'mobile' => true, + 'type' => 'image', + 'width' => 'var(--table-row-height)' + ]; + } - if ($this->text) { - $columns['title'] = [ - 'label' => I18n::translate('title'), - 'mobile' => true, - 'type' => 'url', - ]; - } + if ($this->text) { + $columns['title'] = [ + 'label' => I18n::translate('title'), + 'mobile' => true, + 'type' => 'url', + ]; + } - if ($this->info) { - $columns['info'] = [ - 'label' => I18n::translate('info'), - 'type' => 'text', - ]; - } + if ($this->info) { + $columns['info'] = [ + 'label' => I18n::translate('info'), + 'type' => 'text', + ]; + } - foreach ($this->columns as $columnName => $column) { - if ($column === true) { - $column = []; - } + foreach ($this->columns as $columnName => $column) { + if ($column === true) { + $column = []; + } - if ($column === false) { - continue; - } + if ($column === false) { + continue; + } - // fallback for labels - $column['label'] ??= Str::ucfirst($columnName); + // fallback for labels + $column['label'] ??= Str::ucfirst($columnName); - // make sure to translate labels - $column['label'] = I18n::translate($column['label'], $column['label']); + // make sure to translate labels + $column['label'] = I18n::translate($column['label'], $column['label']); - // keep the original column name as id - $column['id'] = $columnName; + // keep the original column name as id + $column['id'] = $columnName; - // add the custom column to the array with a key that won't - // override the system columns - $columns[$columnName . 'Cell'] = $column; - } + // add the custom column to the array with a key that won't + // override the system columns + $columns[$columnName . 'Cell'] = $column; + } - if ($this->type === 'pages') { - $columns['flag'] = [ - 'label' => ' ', - 'mobile' => true, - 'type' => 'flag', - 'width' => 'var(--table-row-height)', - ]; - } + if ($this->type === 'pages') { + $columns['flag'] = [ + 'label' => ' ', + 'mobile' => true, + 'type' => 'flag', + 'width' => 'var(--table-row-height)', + ]; + } - return $columns; - }, - ], - 'methods' => [ - 'columnsValues' => function (array $item, $model) { - $item['title'] = [ - 'text' => $item['text'], - 'href' => $model->panel()->url(true) - ]; + return $columns; + }, + ], + 'methods' => [ + 'columnsValues' => function (array $item, $model) { + $item['title'] = [ + 'text' => $item['text'], + 'href' => $model->panel()->url(true) + ]; - foreach ($this->columns as $columnName => $column) { - // don't overwrite essential columns - if (isset($item[$columnName]) === true) { - continue; - } + foreach ($this->columns as $columnName => $column) { + // don't overwrite essential columns + if (isset($item[$columnName]) === true) { + continue; + } - if (empty($column['value']) === false) { - if ($column['type'] ?? false === 'html') { - $value = $model->toString($column['value']); - } else { - $value = $model->toSafeString($column['value']); - } - } else { - $value = $model->content()->get($column['id'] ?? $columnName)->value(); - } + if (empty($column['value']) === false) { + if ($column['type'] ?? false === 'html') { + $value = $model->toString($column['value']); + } else { + $value = $model->toSafeString($column['value']); + } + } else { + $value = $model->content()->get($column['id'] ?? $columnName)->value(); + } - $item[$columnName] = $value; - } + $item[$columnName] = $value; + } - return $item; - } - ], + return $item; + } + ], ]; diff --git a/kirby/config/sections/mixins/max.php b/kirby/config/sections/mixins/max.php index 5ce303c..a87c1cc 100755 --- a/kirby/config/sections/mixins/max.php +++ b/kirby/config/sections/mixins/max.php @@ -1,28 +1,28 @@ [ - /** - * Sets the maximum number of allowed entries in the section - */ - 'max' => function (int $max = null) { - return $max; - } - ], - 'methods' => [ - 'isFull' => function () { - if ($this->max) { - return $this->total >= $this->max; - } + 'props' => [ + /** + * Sets the maximum number of allowed entries in the section + */ + 'max' => function (int $max = null) { + return $max; + } + ], + 'methods' => [ + 'isFull' => function () { + if ($this->max) { + return $this->total >= $this->max; + } - return false; - }, - 'validateMax' => function () { - if ($this->max && $this->total > $this->max) { - return false; - } + return false; + }, + 'validateMax' => function () { + if ($this->max && $this->total > $this->max) { + return false; + } - return true; - } - ] + return true; + } + ] ]; diff --git a/kirby/config/sections/mixins/min.php b/kirby/config/sections/mixins/min.php index bfc495d..6295f2d 100755 --- a/kirby/config/sections/mixins/min.php +++ b/kirby/config/sections/mixins/min.php @@ -1,21 +1,21 @@ [ - /** - * Sets the minimum number of required entries in the section - */ - 'min' => function (int $min = null) { - return $min; - } - ], - 'methods' => [ - 'validateMin' => function () { - if ($this->min && $this->min > $this->total) { - return false; - } + 'props' => [ + /** + * Sets the minimum number of required entries in the section + */ + 'min' => function (int $min = null) { + return $min; + } + ], + 'methods' => [ + 'validateMin' => function () { + if ($this->min && $this->min > $this->total) { + return false; + } - return true; - } - ] + return true; + } + ] ]; diff --git a/kirby/config/sections/mixins/pagination.php b/kirby/config/sections/mixins/pagination.php index 491245a..3b2a2b0 100755 --- a/kirby/config/sections/mixins/pagination.php +++ b/kirby/config/sections/mixins/pagination.php @@ -4,34 +4,34 @@ use Kirby\Cms\App; use Kirby\Toolkit\Pagination; return [ - 'props' => [ - /** - * Sets the number of items per page. If there are more items the pagination navigation will be shown at the bottom of the section. - */ - 'limit' => function (int $limit = 20) { - return $limit; - }, - /** - * Sets the default page for the pagination. This will overwrite default pagination. - */ - 'page' => function (int $page = null) { - return App::instance()->request()->get('page', $page); - }, - ], - 'methods' => [ - 'pagination' => function () { - $pagination = new Pagination([ - 'limit' => $this->limit, - 'page' => $this->page, - 'total' => $this->total - ]); + 'props' => [ + /** + * Sets the number of items per page. If there are more items the pagination navigation will be shown at the bottom of the section. + */ + 'limit' => function (int $limit = 20) { + return $limit; + }, + /** + * Sets the default page for the pagination. This will overwrite default pagination. + */ + 'page' => function (int $page = null) { + return App::instance()->request()->get('page', $page); + }, + ], + 'methods' => [ + 'pagination' => function () { + $pagination = new Pagination([ + 'limit' => $this->limit, + 'page' => $this->page, + 'total' => $this->total + ]); - return [ - 'limit' => $pagination->limit(), - 'offset' => $pagination->offset(), - 'page' => $pagination->page(), - 'total' => $pagination->total(), - ]; - } - ] + return [ + 'limit' => $pagination->limit(), + 'offset' => $pagination->offset(), + 'page' => $pagination->page(), + 'total' => $pagination->total(), + ]; + } + ] ]; diff --git a/kirby/config/sections/mixins/parent.php b/kirby/config/sections/mixins/parent.php index 3534acf..2df8425 100755 --- a/kirby/config/sections/mixins/parent.php +++ b/kirby/config/sections/mixins/parent.php @@ -3,41 +3,41 @@ use Kirby\Exception\Exception; return [ - 'props' => [ - /** - * Sets the query to a parent to find items for the list - */ - 'parent' => function (string $parent = null) { - return $parent; - } - ], - 'methods' => [ - 'parentModel' => function () { - $parent = $this->parent; + 'props' => [ + /** + * Sets the query to a parent to find items for the list + */ + 'parent' => function (string $parent = null) { + return $parent; + } + ], + 'methods' => [ + 'parentModel' => function () { + $parent = $this->parent; - if (is_string($parent) === true) { - $query = $parent; - $parent = $this->model->query($query); + if (is_string($parent) === true) { + $query = $parent; + $parent = $this->model->query($query); - if (!$parent) { - throw new Exception('The parent for the query "' . $query . '" cannot be found in the section "' . $this->name() . '"'); - } + if (!$parent) { + throw new Exception('The parent for the query "' . $query . '" cannot be found in the section "' . $this->name() . '"'); + } - if ( - is_a($parent, 'Kirby\Cms\Page') === false && - is_a($parent, 'Kirby\Cms\Site') === false && - is_a($parent, 'Kirby\Cms\File') === false && - is_a($parent, 'Kirby\Cms\User') === false - ) { - throw new Exception('The parent for the section "' . $this->name() . '" has to be a page, site or user object'); - } - } + if ( + is_a($parent, 'Kirby\Cms\Page') === false && + is_a($parent, 'Kirby\Cms\Site') === false && + is_a($parent, 'Kirby\Cms\File') === false && + is_a($parent, 'Kirby\Cms\User') === false + ) { + throw new Exception('The parent for the section "' . $this->name() . '" has to be a page, site or user object'); + } + } - if ($parent === null) { - return $this->model; - } + if ($parent === null) { + return $this->model; + } - return $parent; - } - ] + return $parent; + } + ] ]; diff --git a/kirby/config/sections/mixins/search.php b/kirby/config/sections/mixins/search.php index 566a8e6..c0aa4bb 100755 --- a/kirby/config/sections/mixins/search.php +++ b/kirby/config/sections/mixins/search.php @@ -3,17 +3,17 @@ use Kirby\Cms\App; return [ - 'props' => [ - /** - * Enable/disable the search in the sections - */ - 'search' => function (bool $search = false): bool { - return $search; - } - ], - 'computed' => [ - 'searchterm' => function (): ?string { - return App::instance()->request()->get('searchterm'); - } - ] + 'props' => [ + /** + * Enable/disable the search in the sections + */ + 'search' => function (bool $search = false): bool { + return $search; + } + ], + 'computed' => [ + 'searchterm' => function (): ?string { + return App::instance()->request()->get('searchterm'); + } + ] ]; diff --git a/kirby/config/sections/mixins/sort.php b/kirby/config/sections/mixins/sort.php index e9bbb28..54c7531 100755 --- a/kirby/config/sections/mixins/sort.php +++ b/kirby/config/sections/mixins/sort.php @@ -1,53 +1,53 @@ [ - /** - * Enables/disables reverse sorting - */ - 'flip' => function (bool $flip = false) { - return $flip; - }, - /** - * Enables/disables manual sorting - */ - 'sortable' => function (bool $sortable = true) { - return $sortable; - }, - /** - * Overwrites manual sorting and sorts by the given field and sorting direction (i.e. `date desc`) - */ - 'sortBy' => function (string $sortBy = null) { - return $sortBy; - }, - ], - 'computed' => [ - 'sortable' => function () { - if ($this->sortable === false) { - return false; - } + 'props' => [ + /** + * Enables/disables reverse sorting + */ + 'flip' => function (bool $flip = false) { + return $flip; + }, + /** + * Enables/disables manual sorting + */ + 'sortable' => function (bool $sortable = true) { + return $sortable; + }, + /** + * Overwrites manual sorting and sorts by the given field and sorting direction (i.e. `date desc`) + */ + 'sortBy' => function (string $sortBy = null) { + return $sortBy; + }, + ], + 'computed' => [ + 'sortable' => function () { + if ($this->sortable === false) { + return false; + } - if ( - $this->type === 'pages' && - in_array($this->status, ['listed', 'published', 'all']) === false - ) { - return false; - } + if ( + $this->type === 'pages' && + in_array($this->status, ['listed', 'published', 'all']) === false + ) { + return false; + } - // don't allow sorting while search filter is active - if (empty($this->query) === false) { - return false; - } + // don't allow sorting while search filter is active + if (empty($this->query) === false) { + return false; + } - if ($this->sortBy !== null) { - return false; - } + if ($this->sortBy !== null) { + return false; + } - if ($this->flip === true) { - return false; - } + if ($this->flip === true) { + return false; + } - return true; - } - ] + return true; + } + ] ]; diff --git a/kirby/config/sections/pages.php b/kirby/config/sections/pages.php index f4c98da..1317d71 100755 --- a/kirby/config/sections/pages.php +++ b/kirby/config/sections/pages.php @@ -6,258 +6,258 @@ use Kirby\Toolkit\A; use Kirby\Toolkit\I18n; return [ - 'mixins' => [ - 'details', - 'empty', - 'headline', - 'help', - 'layout', - 'min', - 'max', - 'pagination', - 'parent', - 'search', - 'sort' - ], - 'props' => [ - /** - * Optional array of templates that should only be allowed to add - * or `false` to completely disable page creation - */ - 'create' => function ($create = null) { - return $create; - }, - /** - * Filters pages by their status. Available status settings: `draft`, `unlisted`, `listed`, `published`, `all`. - */ - 'status' => function (string $status = '') { - if ($status === 'drafts') { - $status = 'draft'; - } + 'mixins' => [ + 'details', + 'empty', + 'headline', + 'help', + 'layout', + 'min', + 'max', + 'pagination', + 'parent', + 'search', + 'sort' + ], + 'props' => [ + /** + * Optional array of templates that should only be allowed to add + * or `false` to completely disable page creation + */ + 'create' => function ($create = null) { + return $create; + }, + /** + * Filters pages by their status. Available status settings: `draft`, `unlisted`, `listed`, `published`, `all`. + */ + 'status' => function (string $status = '') { + if ($status === 'drafts') { + $status = 'draft'; + } - if (in_array($status, ['all', 'draft', 'published', 'listed', 'unlisted']) === false) { - $status = 'all'; - } + if (in_array($status, ['all', 'draft', 'published', 'listed', 'unlisted']) === false) { + $status = 'all'; + } - return $status; - }, - /** - * Filters the list by templates and sets template options when adding new pages to the section. - */ - 'templates' => function ($templates = null) { - return A::wrap($templates ?? $this->template); - } - ], - 'computed' => [ - 'parent' => function () { - $parent = $this->parentModel(); + return $status; + }, + /** + * Filters the list by templates and sets template options when adding new pages to the section. + */ + 'templates' => function ($templates = null) { + return A::wrap($templates ?? $this->template); + } + ], + 'computed' => [ + 'parent' => function () { + $parent = $this->parentModel(); - if ( - is_a($parent, 'Kirby\Cms\Site') === false && - is_a($parent, 'Kirby\Cms\Page') === false - ) { - throw new InvalidArgumentException('The parent is invalid. You must choose the site or a page as parent.'); - } + if ( + is_a($parent, 'Kirby\Cms\Site') === false && + is_a($parent, 'Kirby\Cms\Page') === false + ) { + throw new InvalidArgumentException('The parent is invalid. You must choose the site or a page as parent.'); + } - return $parent; - }, - 'pages' => function () { - switch ($this->status) { - case 'draft': - $pages = $this->parent->drafts(); - break; - case 'listed': - $pages = $this->parent->children()->listed(); - break; - case 'published': - $pages = $this->parent->children(); - break; - case 'unlisted': - $pages = $this->parent->children()->unlisted(); - break; - default: - $pages = $this->parent->childrenAndDrafts(); - } + return $parent; + }, + 'pages' => function () { + switch ($this->status) { + case 'draft': + $pages = $this->parent->drafts(); + break; + case 'listed': + $pages = $this->parent->children()->listed(); + break; + case 'published': + $pages = $this->parent->children(); + break; + case 'unlisted': + $pages = $this->parent->children()->unlisted(); + break; + default: + $pages = $this->parent->childrenAndDrafts(); + } - // filters pages that are protected and not in the templates list - // internal `filter()` method used instead of foreach loop that previously included `unset()` - // because `unset()` is updating the original data, `filter()` is just filtering - // also it has been tested that there is no performance difference - // even in 0.1 seconds on 100k virtual pages - $pages = $pages->filter(function ($page) { - // remove all protected pages - if ($page->isReadable() === false) { - return false; - } + // filters pages that are protected and not in the templates list + // internal `filter()` method used instead of foreach loop that previously included `unset()` + // because `unset()` is updating the original data, `filter()` is just filtering + // also it has been tested that there is no performance difference + // even in 0.1 seconds on 100k virtual pages + $pages = $pages->filter(function ($page) { + // remove all protected pages + if ($page->isReadable() === false) { + return false; + } - // filter by all set templates - if ($this->templates && in_array($page->intendedTemplate()->name(), $this->templates) === false) { - return false; - } + // filter by all set templates + if ($this->templates && in_array($page->intendedTemplate()->name(), $this->templates) === false) { + return false; + } - return true; - }); + return true; + }); - // search - if ($this->search === true && empty($this->searchterm) === false) { - $pages = $pages->search($this->searchterm); - } + // search + if ($this->search === true && empty($this->searchterm) === false) { + $pages = $pages->search($this->searchterm); + } - // sort - if ($this->sortBy) { - $pages = $pages->sort(...$pages::sortArgs($this->sortBy)); - } + // sort + if ($this->sortBy) { + $pages = $pages->sort(...$pages::sortArgs($this->sortBy)); + } - // flip - if ($this->flip === true) { - $pages = $pages->flip(); - } + // flip + if ($this->flip === true) { + $pages = $pages->flip(); + } - // pagination - $pages = $pages->paginate([ - 'page' => $this->page, - 'limit' => $this->limit, - 'method' => 'none' // the page is manually provided - ]); + // pagination + $pages = $pages->paginate([ + 'page' => $this->page, + 'limit' => $this->limit, + 'method' => 'none' // the page is manually provided + ]); - return $pages; - }, - 'total' => function () { - return $this->pages->pagination()->total(); - }, - 'data' => function () { - $data = []; + return $pages; + }, + 'total' => function () { + return $this->pages->pagination()->total(); + }, + 'data' => function () { + $data = []; - foreach ($this->pages as $page) { - $panel = $page->panel(); - $permissions = $page->permissions(); + foreach ($this->pages as $page) { + $panel = $page->panel(); + $permissions = $page->permissions(); - $item = [ - 'dragText' => $panel->dragText(), - 'id' => $page->id(), - 'image' => $panel->image( - $this->image, - $this->layout === 'table' ? 'list' : $this->layout - ), - 'info' => $page->toSafeString($this->info ?? false), - 'link' => $panel->url(true), - 'parent' => $page->parentId(), - 'permissions' => [ - 'sort' => $permissions->can('sort'), - 'changeSlug' => $permissions->can('changeSlug'), - 'changeStatus' => $permissions->can('changeStatus'), - 'changeTitle' => $permissions->can('changeTitle'), - ], - 'status' => $page->status(), - 'template' => $page->intendedTemplate()->name(), - 'text' => $page->toSafeString($this->text), - ]; + $item = [ + 'dragText' => $panel->dragText(), + 'id' => $page->id(), + 'image' => $panel->image( + $this->image, + $this->layout === 'table' ? 'list' : $this->layout + ), + 'info' => $page->toSafeString($this->info ?? false), + 'link' => $panel->url(true), + 'parent' => $page->parentId(), + 'permissions' => [ + 'sort' => $permissions->can('sort'), + 'changeSlug' => $permissions->can('changeSlug'), + 'changeStatus' => $permissions->can('changeStatus'), + 'changeTitle' => $permissions->can('changeTitle'), + ], + 'status' => $page->status(), + 'template' => $page->intendedTemplate()->name(), + 'text' => $page->toSafeString($this->text), + ]; - if ($this->layout === 'table') { - $item = $this->columnsValues($item, $page); - } + if ($this->layout === 'table') { + $item = $this->columnsValues($item, $page); + } - $data[] = $item; - } + $data[] = $item; + } - return $data; - }, - 'errors' => function () { - $errors = []; + return $data; + }, + 'errors' => function () { + $errors = []; - if ($this->validateMax() === false) { - $errors['max'] = I18n::template('error.section.pages.max.' . I18n::form($this->max), [ - 'max' => $this->max, - 'section' => $this->headline - ]); - } + if ($this->validateMax() === false) { + $errors['max'] = I18n::template('error.section.pages.max.' . I18n::form($this->max), [ + 'max' => $this->max, + 'section' => $this->headline + ]); + } - if ($this->validateMin() === false) { - $errors['min'] = I18n::template('error.section.pages.min.' . I18n::form($this->min), [ - 'min' => $this->min, - 'section' => $this->headline - ]); - } + if ($this->validateMin() === false) { + $errors['min'] = I18n::template('error.section.pages.min.' . I18n::form($this->min), [ + 'min' => $this->min, + 'section' => $this->headline + ]); + } - if (empty($errors) === true) { - return []; - } + if (empty($errors) === true) { + return []; + } - return [ - $this->name => [ - 'label' => $this->headline, - 'message' => $errors, - ] - ]; - }, - 'add' => function () { - if ($this->create === false) { - return false; - } + return [ + $this->name => [ + 'label' => $this->headline, + 'message' => $errors, + ] + ]; + }, + 'add' => function () { + if ($this->create === false) { + return false; + } - if (in_array($this->status, ['draft', 'all']) === false) { - return false; - } + if (in_array($this->status, ['draft', 'all']) === false) { + return false; + } - if ($this->isFull() === true) { - return false; - } + if ($this->isFull() === true) { + return false; + } - return true; - }, - 'pagination' => function () { - return $this->pagination(); - } - ], - 'methods' => [ - 'blueprints' => function () { - $blueprints = []; - $templates = empty($this->create) === false ? A::wrap($this->create) : $this->templates; + return true; + }, + 'pagination' => function () { + return $this->pagination(); + } + ], + 'methods' => [ + 'blueprints' => function () { + $blueprints = []; + $templates = empty($this->create) === false ? A::wrap($this->create) : $this->templates; - if (empty($templates) === true) { - $templates = $this->kirby()->blueprints(); - } + if (empty($templates) === true) { + $templates = $this->kirby()->blueprints(); + } - // convert every template to a usable option array - // for the template select box - foreach ($templates as $template) { - try { - $props = Blueprint::load('pages/' . $template); + // convert every template to a usable option array + // for the template select box + foreach ($templates as $template) { + try { + $props = Blueprint::load('pages/' . $template); - $blueprints[] = [ - 'name' => basename($props['name']), - 'title' => $props['title'], - ]; - } catch (Throwable $e) { - $blueprints[] = [ - 'name' => basename($template), - 'title' => ucfirst($template), - ]; - } - } + $blueprints[] = [ + 'name' => basename($props['name']), + 'title' => $props['title'], + ]; + } catch (Throwable $e) { + $blueprints[] = [ + 'name' => basename($template), + 'title' => ucfirst($template), + ]; + } + } - return $blueprints; - } - ], - 'toArray' => function () { - return [ - 'data' => $this->data, - 'errors' => $this->errors, - 'options' => [ - 'add' => $this->add, - 'columns' => $this->columns, - 'empty' => $this->empty, - 'headline' => $this->headline, - 'help' => $this->help, - 'layout' => $this->layout, - 'link' => $this->link(), - 'max' => $this->max, - 'min' => $this->min, - 'search' => $this->search, - 'size' => $this->size, - 'sortable' => $this->sortable - ], - 'pagination' => $this->pagination, - ]; - } + return $blueprints; + } + ], + 'toArray' => function () { + return [ + 'data' => $this->data, + 'errors' => $this->errors, + 'options' => [ + 'add' => $this->add, + 'columns' => $this->columns, + 'empty' => $this->empty, + 'headline' => $this->headline, + 'help' => $this->help, + 'layout' => $this->layout, + 'link' => $this->link(), + 'max' => $this->max, + 'min' => $this->min, + 'search' => $this->search, + 'size' => $this->size, + 'sortable' => $this->sortable + ], + 'pagination' => $this->pagination, + ]; + } ]; diff --git a/kirby/config/sections/stats.php b/kirby/config/sections/stats.php index 662d3f6..e04755b 100755 --- a/kirby/config/sections/stats.php +++ b/kirby/config/sections/stats.php @@ -3,60 +3,60 @@ use Kirby\Toolkit\I18n; return [ - 'mixins' => [ - 'headline', - ], - 'props' => [ - /** - * Array or query string for reports. Each report needs a `label` and `value` and can have additional `info`, `link` and `theme` settings. - */ - 'reports' => function ($reports = null) { - if ($reports === null) { - return []; - } + 'mixins' => [ + 'headline', + ], + 'props' => [ + /** + * Array or query string for reports. Each report needs a `label` and `value` and can have additional `info`, `link` and `theme` settings. + */ + 'reports' => function ($reports = null) { + if ($reports === null) { + return []; + } - if (is_string($reports) === true) { - $reports = $this->model()->query($reports); - } + if (is_string($reports) === true) { + $reports = $this->model()->query($reports); + } - if (is_array($reports) === false) { - return []; - } + if (is_array($reports) === false) { + return []; + } - return $reports; - }, - /** - * The size of the report cards. Available sizes: `tiny`, `small`, `medium`, `large` - */ - 'size' => function (string $size = 'large') { - return $size; - } - ], - 'computed' => [ - 'reports' => function () { - $reports = []; - $model = $this->model(); - $value = fn ($value) => $value === null ? null : $model->toString($value); + return $reports; + }, + /** + * The size of the report cards. Available sizes: `tiny`, `small`, `medium`, `large` + */ + 'size' => function (string $size = 'large') { + return $size; + } + ], + 'computed' => [ + 'reports' => function () { + $reports = []; + $model = $this->model(); + $value = fn ($value) => $value === null ? null : $model->toString($value); - foreach ($this->reports as $report) { - if (is_string($report) === true) { - $report = $model->query($report); - } + foreach ($this->reports as $report) { + if (is_string($report) === true) { + $report = $model->query($report); + } - if (is_array($report) === false) { - continue; - } + if (is_array($report) === false) { + continue; + } - $reports[] = [ - 'label' => I18n::translate($report['label'], $report['label']), - 'value' => $value($report['value'] ?? null), - 'info' => $value($report['info'] ?? null), - 'link' => $value($report['link'] ?? null), - 'theme' => $value($report['theme'] ?? null) - ]; - } + $reports[] = [ + 'label' => I18n::translate($report['label'], $report['label']), + 'value' => $value($report['value'] ?? null), + 'info' => $value($report['info'] ?? null), + 'link' => $value($report['link'] ?? null), + 'theme' => $value($report['theme'] ?? null) + ]; + } - return $reports; - } - ] + return $reports; + } + ] ]; diff --git a/kirby/config/setup.php b/kirby/config/setup.php index eadb131..853b54b 100755 --- a/kirby/config/setup.php +++ b/kirby/config/setup.php @@ -11,11 +11,11 @@ define('DS', '/'); $aliases = require_once __DIR__ . '/aliases.php'; spl_autoload_register(function ($class) use ($aliases) { - $class = strtolower($class); + $class = strtolower($class); - if (isset($aliases[$class]) === true) { - class_alias($aliases[$class], $class); - } + if (isset($aliases[$class]) === true) { + class_alias($aliases[$class], $class); + } }); /** @@ -24,13 +24,13 @@ spl_autoload_register(function ($class) use ($aliases) { $testDir = dirname(__DIR__) . '/tests'; if (is_dir($testDir) === true) { - spl_autoload_register(function ($className) use ($testDir) { - $path = str_replace('Kirby\\', '', $className); - $path = str_replace('\\', '/', $path); - $file = $testDir . '/' . $path . '.php'; + spl_autoload_register(function ($className) use ($testDir) { + $path = str_replace('Kirby\\', '', $className); + $path = str_replace('\\', '/', $path); + $file = $testDir . '/' . $path . '.php'; - if (file_exists($file)) { - include $file; - } - }); + if (file_exists($file)) { + include $file; + } + }); } diff --git a/kirby/config/tags.php b/kirby/config/tags.php index 702b55a..54e7115 100755 --- a/kirby/config/tags.php +++ b/kirby/config/tags.php @@ -9,316 +9,316 @@ use Kirby\Toolkit\Str; */ return [ - /** - * Date - */ - 'date' => [ - 'attr' => [], - 'html' => function ($tag) { - return strtolower($tag->date) === 'year' ? date('Y') : date($tag->date); - } - ], + /** + * Date + */ + 'date' => [ + 'attr' => [], + 'html' => function ($tag) { + return strtolower($tag->date) === 'year' ? date('Y') : date($tag->date); + } + ], - /** - * Email - */ - 'email' => [ - 'attr' => [ - 'class', - 'rel', - 'target', - 'text', - 'title' - ], - 'html' => function ($tag) { - return Html::email($tag->value, $tag->text, [ - 'class' => $tag->class, - 'rel' => $tag->rel, - 'target' => $tag->target, - 'title' => $tag->title, - ]); - } - ], + /** + * Email + */ + 'email' => [ + 'attr' => [ + 'class', + 'rel', + 'target', + 'text', + 'title' + ], + 'html' => function ($tag) { + return Html::email($tag->value, $tag->text, [ + 'class' => $tag->class, + 'rel' => $tag->rel, + 'target' => $tag->target, + 'title' => $tag->title, + ]); + } + ], - /** - * File - */ - 'file' => [ - 'attr' => [ - 'class', - 'download', - 'rel', - 'target', - 'text', - 'title' - ], - 'html' => function ($tag) { - if (!$file = $tag->file($tag->value)) { - return $tag->text; - } + /** + * File + */ + 'file' => [ + 'attr' => [ + 'class', + 'download', + 'rel', + 'target', + 'text', + 'title' + ], + 'html' => function ($tag) { + if (!$file = $tag->file($tag->value)) { + return $tag->text; + } - // use filename if the text is empty and make sure to - // ignore markdown italic underscores in filenames - if (empty($tag->text) === true) { - $tag->text = str_replace('_', '\_', $file->filename()); - } + // use filename if the text is empty and make sure to + // ignore markdown italic underscores in filenames + if (empty($tag->text) === true) { + $tag->text = str_replace('_', '\_', $file->filename()); + } - return Html::a($file->url(), $tag->text, [ - 'class' => $tag->class, - 'download' => $tag->download !== 'false', - 'rel' => $tag->rel, - 'target' => $tag->target, - 'title' => $tag->title, - ]); - } - ], + return Html::a($file->url(), $tag->text, [ + 'class' => $tag->class, + 'download' => $tag->download !== 'false', + 'rel' => $tag->rel, + 'target' => $tag->target, + 'title' => $tag->title, + ]); + } + ], - /** - * Gist - */ - 'gist' => [ - 'attr' => [ - 'file' - ], - 'html' => function ($tag) { - return Html::gist($tag->value, $tag->file); - } - ], + /** + * Gist + */ + 'gist' => [ + 'attr' => [ + 'file' + ], + 'html' => function ($tag) { + return Html::gist($tag->value, $tag->file); + } + ], - /** - * Image - */ - 'image' => [ - 'attr' => [ - 'alt', - 'caption', - 'class', - 'height', - 'imgclass', - 'link', - 'linkclass', - 'rel', - 'target', - 'title', - 'width' - ], - 'html' => function ($tag) { - if ($tag->file = $tag->file($tag->value)) { - $tag->src = $tag->file->url(); - $tag->alt = $tag->alt ?? $tag->file->alt()->or(' ')->value(); - $tag->title = $tag->title ?? $tag->file->title()->value(); - $tag->caption = $tag->caption ?? $tag->file->caption()->value(); - } else { - $tag->src = Url::to($tag->value); - } + /** + * Image + */ + 'image' => [ + 'attr' => [ + 'alt', + 'caption', + 'class', + 'height', + 'imgclass', + 'link', + 'linkclass', + 'rel', + 'target', + 'title', + 'width' + ], + 'html' => function ($tag) { + if ($tag->file = $tag->file($tag->value)) { + $tag->src = $tag->file->url(); + $tag->alt = $tag->alt ?? $tag->file->alt()->or(' ')->value(); + $tag->title = $tag->title ?? $tag->file->title()->value(); + $tag->caption = $tag->caption ?? $tag->file->caption()->value(); + } else { + $tag->src = Url::to($tag->value); + } - $link = function ($img) use ($tag) { - if (empty($tag->link) === true) { - return $img; - } + $link = function ($img) use ($tag) { + if (empty($tag->link) === true) { + return $img; + } - if ($link = $tag->file($tag->link)) { - $link = $link->url(); - } else { - $link = $tag->link === 'self' ? $tag->src : $tag->link; - } + if ($link = $tag->file($tag->link)) { + $link = $link->url(); + } else { + $link = $tag->link === 'self' ? $tag->src : $tag->link; + } - return Html::a($link, [$img], [ - 'rel' => $tag->rel, - 'class' => $tag->linkclass, - 'target' => $tag->target - ]); - }; + return Html::a($link, [$img], [ + 'rel' => $tag->rel, + 'class' => $tag->linkclass, + 'target' => $tag->target + ]); + }; - $image = Html::img($tag->src, [ - 'width' => $tag->width, - 'height' => $tag->height, - 'class' => $tag->imgclass, - 'title' => $tag->title, - 'alt' => $tag->alt ?? ' ' - ]); + $image = Html::img($tag->src, [ + 'width' => $tag->width, + 'height' => $tag->height, + 'class' => $tag->imgclass, + 'title' => $tag->title, + 'alt' => $tag->alt ?? ' ' + ]); - if ($tag->kirby()->option('kirbytext.image.figure', true) === false) { - return $link($image); - } + if ($tag->kirby()->option('kirbytext.image.figure', true) === false) { + return $link($image); + } - // render KirbyText in caption - if ($tag->caption) { - $options = ['markdown' => ['inline' => true]]; - $caption = $tag->kirby()->kirbytext($tag->caption, $options); - $tag->caption = [$caption]; - } + // render KirbyText in caption + if ($tag->caption) { + $options = ['markdown' => ['inline' => true]]; + $caption = $tag->kirby()->kirbytext($tag->caption, $options); + $tag->caption = [$caption]; + } - return Html::figure([ $link($image) ], $tag->caption, [ - 'class' => $tag->class - ]); - } - ], + return Html::figure([ $link($image) ], $tag->caption, [ + 'class' => $tag->class + ]); + } + ], - /** - * Link - */ - 'link' => [ - 'attr' => [ - 'class', - 'lang', - 'rel', - 'role', - 'target', - 'title', - 'text', - ], - 'html' => function ($tag) { - if (empty($tag->lang) === false) { - $tag->value = Url::to($tag->value, $tag->lang); - } + /** + * Link + */ + 'link' => [ + 'attr' => [ + 'class', + 'lang', + 'rel', + 'role', + 'target', + 'title', + 'text', + ], + 'html' => function ($tag) { + if (empty($tag->lang) === false) { + $tag->value = Url::to($tag->value, $tag->lang); + } - return Html::a($tag->value, $tag->text, [ - 'rel' => $tag->rel, - 'class' => $tag->class, - 'role' => $tag->role, - 'title' => $tag->title, - 'target' => $tag->target, - ]); - } - ], + return Html::a($tag->value, $tag->text, [ + 'rel' => $tag->rel, + 'class' => $tag->class, + 'role' => $tag->role, + 'title' => $tag->title, + 'target' => $tag->target, + ]); + } + ], - /** - * Tel - */ - 'tel' => [ - 'attr' => [ - 'class', - 'rel', - 'text', - 'title' - ], - 'html' => function ($tag) { - return Html::tel($tag->value, $tag->text, [ - 'class' => $tag->class, - 'rel' => $tag->rel, - 'title' => $tag->title - ]); - } - ], + /** + * Tel + */ + 'tel' => [ + 'attr' => [ + 'class', + 'rel', + 'text', + 'title' + ], + 'html' => function ($tag) { + return Html::tel($tag->value, $tag->text, [ + 'class' => $tag->class, + 'rel' => $tag->rel, + 'title' => $tag->title + ]); + } + ], - /** - * Twitter - */ - 'twitter' => [ - 'attr' => [ - 'class', - 'rel', - 'target', - 'text', - 'title' - ], - 'html' => function ($tag) { + /** + * Twitter + */ + 'twitter' => [ + 'attr' => [ + 'class', + 'rel', + 'target', + 'text', + 'title' + ], + 'html' => function ($tag) { - // get and sanitize the username - $username = str_replace('@', '', $tag->value); + // get and sanitize the username + $username = str_replace('@', '', $tag->value); - // build the profile url - $url = 'https://twitter.com/' . $username; + // build the profile url + $url = 'https://twitter.com/' . $username; - // sanitize the link text - $text = $tag->text ?? '@' . $username; + // sanitize the link text + $text = $tag->text ?? '@' . $username; - // build the final link - return Html::a($url, $text, [ - 'class' => $tag->class, - 'rel' => $tag->rel, - 'target' => $tag->target, - 'title' => $tag->title, - ]); - } - ], + // build the final link + return Html::a($url, $text, [ + 'class' => $tag->class, + 'rel' => $tag->rel, + 'target' => $tag->target, + 'title' => $tag->title, + ]); + } + ], - /** - * Video - */ - 'video' => [ - 'attr' => [ - 'autoplay', - 'caption', - 'controls', - 'class', - 'height', - 'loop', - 'muted', - 'poster', - 'preload', - 'style', - 'width', - ], - 'html' => function ($tag) { - // checks and gets if poster is local file - if ( - empty($tag->poster) === false && - Str::startsWith($tag->poster, 'http://') !== true && - Str::startsWith($tag->poster, 'https://') !== true - ) { - if ($poster = $tag->file($tag->poster)) { - $tag->poster = $poster->url(); - } - } + /** + * Video + */ + 'video' => [ + 'attr' => [ + 'autoplay', + 'caption', + 'controls', + 'class', + 'height', + 'loop', + 'muted', + 'poster', + 'preload', + 'style', + 'width', + ], + 'html' => function ($tag) { + // checks and gets if poster is local file + if ( + empty($tag->poster) === false && + Str::startsWith($tag->poster, 'http://') !== true && + Str::startsWith($tag->poster, 'https://') !== true + ) { + if ($poster = $tag->file($tag->poster)) { + $tag->poster = $poster->url(); + } + } - // checks video is local or provider(remote) - $isLocalVideo = ( - Str::startsWith($tag->value, 'http://') !== true && - Str::startsWith($tag->value, 'https://') !== true - ); - $isProviderVideo = ( - $isLocalVideo === false && - ( - Str::contains($tag->value, 'youtu', true) === true || - Str::contains($tag->value, 'vimeo', true) === true - ) - ); + // checks video is local or provider(remote) + $isLocalVideo = ( + Str::startsWith($tag->value, 'http://') !== true && + Str::startsWith($tag->value, 'https://') !== true + ); + $isProviderVideo = ( + $isLocalVideo === false && + ( + Str::contains($tag->value, 'youtu', true) === true || + Str::contains($tag->value, 'vimeo', true) === true + ) + ); - // default attributes for local and remote videos - $attrs = [ - 'height' => $tag->height, - 'width' => $tag->width - ]; + // default attributes for local and remote videos + $attrs = [ + 'height' => $tag->height, + 'width' => $tag->width + ]; - // don't use attributes that iframe doesn't support - if ($isProviderVideo === false) { - // converts tag attributes to supported formats (listed below) to output correct html - // booleans: autoplay, controls, loop, muted - // strings : poster, preload - // for ex : `autoplay` will not work if `false` is a `string` instead of a `boolean` - $attrs['autoplay'] = $autoplay = Str::toType($tag->autoplay, 'bool'); - $attrs['controls'] = Str::toType($tag->controls ?? true, 'bool'); - $attrs['loop'] = Str::toType($tag->loop, 'bool'); - $attrs['muted'] = Str::toType($tag->muted ?? $autoplay, 'bool'); - $attrs['poster'] = $tag->poster; - $attrs['preload'] = $tag->preload; - } + // don't use attributes that iframe doesn't support + if ($isProviderVideo === false) { + // converts tag attributes to supported formats (listed below) to output correct html + // booleans: autoplay, controls, loop, muted + // strings : poster, preload + // for ex : `autoplay` will not work if `false` is a `string` instead of a `boolean` + $attrs['autoplay'] = $autoplay = Str::toType($tag->autoplay, 'bool'); + $attrs['controls'] = Str::toType($tag->controls ?? true, 'bool'); + $attrs['loop'] = Str::toType($tag->loop, 'bool'); + $attrs['muted'] = Str::toType($tag->muted ?? $autoplay, 'bool'); + $attrs['poster'] = $tag->poster; + $attrs['preload'] = $tag->preload; + } - // handles local and remote video file - if ($isLocalVideo === true) { - // handles local video file - if ($tag->file = $tag->file($tag->value)) { - $source = Html::tag('source', '', [ - 'src' => $tag->file->url(), - 'type' => $tag->file->mime() - ]); - $video = Html::tag('video', [$source], $attrs); - } - } else { - $video = Html::video( - $tag->value, - $tag->kirby()->option('kirbytext.video.options', []), - $attrs - ); - } + // handles local and remote video file + if ($isLocalVideo === true) { + // handles local video file + if ($tag->file = $tag->file($tag->value)) { + $source = Html::tag('source', '', [ + 'src' => $tag->file->url(), + 'type' => $tag->file->mime() + ]); + $video = Html::tag('video', [$source], $attrs); + } + } else { + $video = Html::video( + $tag->value, + $tag->kirby()->option('kirbytext.video.options', []), + $attrs + ); + } - return Html::figure([$video ?? ''], $tag->caption, [ - 'class' => $tag->class ?? 'video', - 'style' => $tag->style - ]); - } - ], + return Html::figure([$video ?? ''], $tag->caption, [ + 'class' => $tag->class ?? 'video', + 'style' => $tag->style + ]); + } + ], ]; diff --git a/kirby/config/templates/emails/auth/login.php b/kirby/config/templates/emails/auth/login.php index e552481..cacea18 100755 --- a/kirby/config/templates/emails/auth/login.php +++ b/kirby/config/templates/emails/auth/login.php @@ -9,8 +9,8 @@ use Kirby\Toolkit\I18n; * @var int $timeout */ echo I18n::template( - 'login.email.login.body', - null, - compact('user', 'site', 'code', 'timeout'), - $user->language() + 'login.email.login.body', + null, + compact('user', 'site', 'code', 'timeout'), + $user->language() ); diff --git a/kirby/config/templates/emails/auth/password-reset.php b/kirby/config/templates/emails/auth/password-reset.php index 3cd55de..4480f31 100755 --- a/kirby/config/templates/emails/auth/password-reset.php +++ b/kirby/config/templates/emails/auth/password-reset.php @@ -9,8 +9,8 @@ use Kirby\Toolkit\I18n; * @var int $timeout */ echo I18n::template( - 'login.email.password-reset.body', - null, - compact('user', 'site', 'code', 'timeout'), - $user->language() + 'login.email.password-reset.body', + null, + compact('user', 'site', 'code', 'timeout'), + $user->language() ); diff --git a/kirby/i18n/translations/ru.json b/kirby/i18n/translations/ru.json index f4acd25..c38fb9d 100755 --- a/kirby/i18n/translations/ru.json +++ b/kirby/i18n/translations/ru.json @@ -177,7 +177,7 @@ "error.user.duplicate": "Пользователь с Email \"{email}\" уже есть", "error.user.email.invalid": "Пожалуйста, введите правильный адрес эл. почты", "error.user.language.invalid": "Введите правильный язык", - "error.user.notFound": "\u0410\u043a\u043a\u0430\u0443\u043d\u0442 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d", + "error.user.notFound": "Пользователь \"{name}\" не найден", "error.user.password.invalid": "Пожалуйста, введите правильный пароль. Он должен состоять минимум из 8 символов.", "error.user.password.notSame": "\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u0435 \u043f\u0430\u0440\u043e\u043b\u044c", "error.user.password.undefined": "У пользователя нет пароля", @@ -238,11 +238,11 @@ "field.blocks.delete.confirm": "Вы действительно хотите удалить этот блок?", "field.blocks.delete.confirm.all": "Вы действительно хотите удалить все блоки?", "field.blocks.delete.confirm.selected": "Вы действительно хотите удалить эти блоки?", - "field.blocks.empty": "Еще нет блоков", + "field.blocks.empty": "Блоков нет", "field.blocks.fieldsets.label": "Пожалуйста, выберите тип блока…", "field.blocks.fieldsets.paste": "Нажмите {{ shortcut }} чтобы вставить/импортировать блоки из буфера памяти", "field.blocks.gallery.name": "Галерея", - "field.blocks.gallery.images.empty": "Еще нет изображений", + "field.blocks.gallery.images.empty": "Изображений нет", "field.blocks.gallery.images.label": "Изображения", "field.blocks.heading.level": "Уровень", "field.blocks.heading.name": "Заголовок", @@ -275,17 +275,17 @@ "field.blocks.video.url.label": "Ссылка на видео", "field.blocks.video.url.placeholder": "https://youtube.com/?v=", - "field.files.empty": "Еще не выбраны файлы", + "field.files.empty": "Файлы не выбраны", "field.layout.delete": "Удалить разметку", "field.layout.delete.confirm": "Вы действительно хотите удалить эту разметку?", - "field.layout.empty": "Еще нет строк", + "field.layout.empty": "Строк нет", "field.layout.select": "Выберите разметку", - "field.pages.empty": "Еще не выбраны страницы", + "field.pages.empty": "Страницы не выбраны", "field.structure.delete.confirm": "Вы точно хотите удалить эту запись?", - "field.structure.empty": "Еще нет записей", - "field.users.empty": "Еще нет пользователей", + "field.structure.empty": "Записей нет", + "field.users.empty": "Пользователей нет", "file.blueprint": "У файла пока нет разметки. Вы можете определить новые секции и поля разметки в /site/blueprints/files/{blueprint}.yml", "file.delete.confirm": "Вы точно хотите удалить файл
{filename}?", @@ -297,7 +297,7 @@ "hide": "Скрыть", "hour": "Час", "import": "Импортировать", - "info": "Info", + "info": "Информация", "insert": "\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u044c", "insert.after": "Вставить ниже", "insert.before": "Вставить выше", @@ -333,14 +333,14 @@ "languages": "Языки", "languages.default": "Главный язык", - "languages.empty": "Еще нет языков", + "languages.empty": "Языков нет", "languages.secondary": "Дополнительные языки", - "languages.secondary.empty": "Еще нет дополнительных языков", + "languages.secondary.empty": "Дополнительных языков нет", "license": "Лицензия", "license.buy": "Купить лицензию", "license.register": "Зарегистрировать", - "license.manage": "Manage your licenses", + "license.manage": "Управление лицензиями", "license.register.help": "После покупки вы получили по эл. почте код лицензии. Пожалуйста скопируйте и вставьте сюда чтобы зарегистрировать.", "license.register.label": "Пожалуйста вставьте код лицензии", "license.register.success": "Спасибо за поддержку Kirby", @@ -353,7 +353,7 @@ "loading": "Загрузка", "lock.unsaved": "Несохраненные изменения", - "lock.unsaved.empty": "Больше нет несохраненных изменений", + "lock.unsaved.empty": "Несохраненных изменений больше нет", "lock.isLocked": "Несохраненные изменения пользователя {email}", "lock.file.isLocked": "В данный момент этот файл редактирует {email}, поэтому его нельзя изменить.", "lock.page.isLocked": "В данный момент эту страницу редактирует {email}, поэтому его нельзя изменить.", @@ -406,7 +406,7 @@ "open": "Открыть", "open.newWindow": "Открывать в новом окне", "options": "Опции", - "options.none": "Нет параметров", + "options.none": "Параметров нет", "orientation": "Ориентация", "orientation.landscape": "Горизонтальная", @@ -424,7 +424,7 @@ "page.delete.confirm.subpages": "У этой страницы есть внутренние страницы.
Все внутренние страницы так же будут удалены.", "page.delete.confirm.title": "Напишите название страницы, чтобы подтвердить", "page.draft.create": "Создать черновик", - "page.duplicate.appendix": "Скопировать", + "page.duplicate.appendix": "(копия)", "page.duplicate.files": "Копировать файлы", "page.duplicate.pages": "Копировать страницы", "page.sort": "Изменить позицию", @@ -437,7 +437,7 @@ "page.status.unlisted.description": "Страница доступна только по URL", "pages": "Страницы", - "pages.empty": "Еще нет страниц", + "pages.empty": "Страниц нет", "pages.status.draft": "Черновики", "pages.status.listed": "Опубликовано", "pages.status.unlisted": "Скрытая", @@ -462,7 +462,7 @@ "role.admin.description": "Администратор имеет все права", "role.admin.title": "Администратор", "role.all": "Все", - "role.empty": "Нет пользователей с такой ролью", + "role.empty": "Пользователей с такой ролью нет", "role.description.placeholder": "Без описания", "role.nobody.description": "Эта роль применяется если у пользователя нет никаких прав", "role.nobody.title": "Никто", @@ -485,7 +485,7 @@ "slug": "Понятная ссылка", "sort": "Сортировать", - "stats.empty": "Нет уведомлений", + "stats.empty": "Статистики нет", "system.issues.content": "Похоже, к папке content есть несанкционированный доступ", "system.issues.debug": "Включен режим отладки (debugging). Используйте его только при разработке.", "system.issues.git": "Похоже, к папке .git есть несанкционированный доступ", @@ -524,9 +524,9 @@ "translation.locale": "ru_RU", "upload": "Закачать", - "upload.error.cantMove": "Загруженный файл не может быть перемещен", + "upload.error.cantMove": "Не удается переместить загруженный файл", "upload.error.cantWrite": "Не получилось записать файл на диск", - "upload.error.default": "Не получилось загрузить файл", + "upload.error.default": "Не удалось загрузить файл", "upload.error.extension": "Загрузка файла не удалась из за расширения", "upload.error.formSize": "Загруженный файл больше чем MAX_FILE_SIZE настройка в форме", "upload.error.iniPostSize": "Загружаемый файл больше чем post_max_size настройка в php.ini", diff --git a/kirby/panel/cypress.config.js b/kirby/panel/cypress.config.js new file mode 100755 index 0000000..bbb1589 --- /dev/null +++ b/kirby/panel/cypress.config.js @@ -0,0 +1,11 @@ +const { defineConfig } = require("cypress"); + +module.exports = defineConfig({ + video: false, + + e2e: { + baseUrl: "http://sandbox.test", + specPattern: "src/**/*.e2e.js", + supportFile: false + } +}); diff --git a/kirby/panel/dist/js/index.js b/kirby/panel/dist/js/index.js index 13a5c8e..da66f28 100755 --- a/kirby/panel/dist/js/index.js +++ b/kirby/panel/dist/js/index.js @@ -1 +1 @@ -var t=Object.defineProperty,e=Object.defineProperties,n=Object.getOwnPropertyDescriptors,i=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable,r=(e,n,i)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[n]=i,a=(t,e)=>{for(var n in e||(e={}))s.call(e,n)&&r(t,n,e[n]);if(i)for(var n of i(e))o.call(e,n)&&r(t,n,e[n]);return t},l=(t,i)=>e(t,n(i));import{V as u,a as c,m as d,d as p,c as h,b as f,I as m,P as g,S as k,F as v,N as b,s as y,l as $,w as _,e as x,f as w,t as S,g as C,h as O,i as E,j as A,k as T,n as I,D as M,o as L,E as j,p as D,q as B,r as P,T as N,u as q,v as F,x as R,y as z,z as Y,A as H,B as U,C as K,G as J,H as G,J as V}from"./vendor.js";var W=t=>({changeName:async(e,n,i)=>t.patch(e+"/files/"+n+"/name",{name:i}),delete:async(e,n)=>t.delete(e+"/files/"+n),async get(e,n,i){let s=await t.get(e+"/files/"+n,i);return!0===Array.isArray(s.content)&&(s.content={}),s},link(t,e,n){return"/"+this.url(t,e,n)},update:async(e,n,i)=>t.patch(e+"/files/"+n,i),url(t,e,n){let i=t+"/files/"+e;return n&&(i+="/"+n),i}}),X=t=>({async blueprint(e){return t.get("pages/"+this.id(e)+"/blueprint")},async blueprints(e,n){return t.get("pages/"+this.id(e)+"/blueprints",{section:n})},async changeSlug(e,n){return t.patch("pages/"+this.id(e)+"/slug",{slug:n})},async changeStatus(e,n,i){return t.patch("pages/"+this.id(e)+"/status",{status:n,position:i})},async changeTemplate(e,n){return t.patch("pages/"+this.id(e)+"/template",{template:n})},async changeTitle(e,n){return t.patch("pages/"+this.id(e)+"/title",{title:n})},async children(e,n){return t.post("pages/"+this.id(e)+"/children/search",n)},async create(e,n){return null===e||"/"===e?t.post("site/children",n):t.post("pages/"+this.id(e)+"/children",n)},async delete(e,n){return t.delete("pages/"+this.id(e),n)},async duplicate(e,n,i){return t.post("pages/"+this.id(e)+"/duplicate",{slug:n,children:i.children||!1,files:i.files||!1})},async get(e,n){let i=await t.get("pages/"+this.id(e),n);return!0===Array.isArray(i.content)&&(i.content={}),i},id:t=>t.replace(/\//g,"+"),async files(e,n){return t.post("pages/"+this.id(e)+"/files/search",n)},link(t){return"/"+this.url(t)},async preview(t){return(await this.get(this.id(t),{select:"previewUrl"})).previewUrl},async search(e,n){return e?t.post("pages/"+this.id(e)+"/children/search?select=id,title,hasChildren",n):t.post("site/children/search?select=id,title,hasChildren",n)},async update(e,n){return t.patch("pages/"+this.id(e),n)},url(t,e){let n=null===t?"pages":"pages/"+String(t).replace(/\//g,"+");return e&&(n+="/"+e),n}});var Z=t=>({running:0,async request(e,n,i=!1){n=Object.assign(n||{},{credentials:"same-origin",cache:"no-store",headers:a({"x-requested-with":"xmlhttprequest","content-type":"application/json"},n.headers)}),t.methodOverwrite&&"GET"!==n.method&&"POST"!==n.method&&(n.headers["x-http-method-override"]=n.method,n.method="POST"),n=t.onPrepare(n);const s=e+"/"+JSON.stringify(n);t.onStart(s,i),this.running++;const o=await fetch([t.endpoint,e].join(t.endpoint.endsWith("/")||e.startsWith("/")?"":"/"),n);try{const e=await async function(t){const e=await t.text();let n;try{n=JSON.parse(e)}catch(i){return window.panel.$vue.$api.onParserError({html:e}),!1}return n}(o);if(o.status<200||o.status>299)throw e;if("error"===e.status)throw e;let n=e;return e.data&&"model"===e.type&&(n=e.data),this.running--,t.onComplete(s),t.onSuccess(e),n}catch(r){throw this.running--,t.onComplete(s),t.onError(r),r}},async get(t,e,n,i=!1){return e&&(t+="?"+Object.keys(e).filter((t=>void 0!==e[t]&&null!==e[t])).map((t=>t+"="+e[t])).join("&")),this.request(t,Object.assign(n||{},{method:"GET"}),i)},async post(t,e,n,i="POST",s=!1){return this.request(t,Object.assign(n||{},{method:i,body:JSON.stringify(e)}),s)},async patch(t,e,n,i=!1){return this.post(t,e,n,"PATCH",i)},async delete(t,e,n,i=!1){return this.post(t,e,n,"DELETE",i)}}),Q=t=>({blueprint:async e=>t.get("users/"+e+"/blueprint"),blueprints:async(e,n)=>t.get("users/"+e+"/blueprints",{section:n}),changeEmail:async(e,n)=>t.patch("users/"+e+"/email",{email:n}),changeLanguage:async(e,n)=>t.patch("users/"+e+"/language",{language:n}),changeName:async(e,n)=>t.patch("users/"+e+"/name",{name:n}),changePassword:async(e,n)=>t.patch("users/"+e+"/password",{password:n}),changeRole:async(e,n)=>t.patch("users/"+e+"/role",{role:n}),create:async e=>t.post("users",e),delete:async e=>t.delete("users/"+e),deleteAvatar:async e=>t.delete("users/"+e+"/avatar"),link(t,e){return"/"+this.url(t,e)},async list(e){return t.post(this.url(null,"search"),e)},get:async(e,n)=>t.get("users/"+e,n),async roles(e){return(await t.get(this.url(e,"roles"))).data.map((t=>({info:t.description||`(${window.panel.$t("role.description.placeholder")})`,text:t.title,value:t.name})))},search:async e=>t.post("users/search",e),update:async(e,n)=>t.patch("users/"+e,n),url(t,e){let n=t?"users/"+t:"users";return e&&(n+="/"+e),n}}),tt={install(t,e){t.prototype.$api=t.$api=((t={})=>{const e=a(a({},{endpoint:"/api",methodOverwrite:!0,onPrepare:t=>t,onStart(){},onComplete(){},onSuccess(){},onParserError(){},onError(t){throw window.console.log(t.message),t}}),t.config||{});let n=a(a(a({},e),Z(e)),t);return n.auth=(t=>({async login(e){const n={long:e.remember||!1,email:e.email,password:e.password};return t.post("auth/login",n)},logout:async()=>t.post("auth/logout"),user:async e=>t.get("auth",e),verifyCode:async e=>t.post("auth/code",{code:e})}))(n),n.files=W(n),n.languages=(t=>({create:async e=>t.post("languages",e),delete:async e=>t.delete("languages/"+e),get:async e=>t.get("languages/"+e),list:async()=>t.get("languages"),update:async(e,n)=>t.patch("languages/"+e,n)}))(n),n.pages=X(n),n.roles=(t=>({list:async e=>t.get("roles",e),get:async e=>t.get("roles/"+e)}))(n),n.system=(t=>({get:async(e={view:"panel"})=>t.get("system",e),install:async e=>(await t.post("system/install",e)).user,register:async e=>t.post("system/register",e)}))(n),n.site=(t=>({blueprint:async()=>t.get("site/blueprint"),blueprints:async()=>t.get("site/blueprints"),changeTitle:async e=>t.patch("site/title",{title:e}),children:async e=>t.post("site/children/search",e),get:async(e={view:"panel"})=>t.get("site",e),update:async e=>t.post("site",e)}))(n),n.translations=(t=>({list:async()=>t.get("translations"),get:async e=>t.get("translations/"+e)}))(n),n.users=Q(n),n})({config:{endpoint:window.panel.$urls.api,onComplete:n=>{t.$api.requests=t.$api.requests.filter((t=>t!==n)),0===t.$api.requests.length&&e.dispatch("isLoading",!1)},onError:e=>{window.panel.$config.debug&&window.console.error(e),403!==e.code||"Unauthenticated"!==e.message&&"access.panel"!==e.key||t.prototype.$go("/logout")},onParserError:({html:t,silent:n})=>{e.dispatch("fatal",{html:t,silent:n})},onPrepare:t=>(window.panel.$language&&(t.headers["x-language"]=window.panel.$language.code),t.headers["x-csrf"]=window.panel.$system.csrf,t),onStart:(n,i=!1)=>{!1===i&&e.dispatch("isLoading",!0),t.$api.requests.push(n)},onSuccess:()=>{clearInterval(t.$api.ping),t.$api.ping=setInterval(t.$api.auth.user,3e5)}},ping:null,requests:[]}),t.$api.ping=setInterval(t.$api.auth.user,3e5)}},et={name:"Fiber",data:()=>({component:null,state:window.fiber,key:null}),created(){this.$fiber.init(this.state,{base:document.querySelector("base").href,headers:()=>({"X-CSRF":this.state.$system.csrf}),onFatal({text:t,options:e}){this.$store.dispatch("fatal",{html:t,silent:e.silent})},onFinish:()=>{0===this.$api.requests.length&&this.$store.dispatch("isLoading",!1)},onPushState:t=>{window.history.pushState(t,"",t.$url)},onReplaceState:t=>{window.history.replaceState(t,"",t.$url)},onStart:({silent:t})=>{!0!==t&&this.$store.dispatch("isLoading",!0)},onSwap:async(t,e)=>{e=a({navigate:!0,replace:!1},e),this.setGlobals(t),this.setTitle(t),this.setTranslation(t),this.component=t.$view.component,this.state=t,this.key=!0===e.replace?this.key:t.$view.timestamp,!0===e.navigate&&this.navigate()},query:()=>{var t;return{language:null==(t=this.state.$language)?void 0:t.code}}}),window.addEventListener("popstate",this.$reload)},methods:{navigate(){this.$store.dispatch("navigate")},setGlobals(t){["$config","$direction","$language","$languages","$license","$menu","$multilang","$permissions","$searches","$system","$translation","$urls","$user","$view"].forEach((e=>{void 0!==t[e]?u.prototype[e]=window.panel[e]=t[e]:u.prototype[e]=t[e]=window.panel[e]}))},setTitle(t){t.$view.title?document.title=t.$view.title+" | "+t.$system.title:document.title=t.$system.title},setTranslation(t){t.$translation&&(document.documentElement.lang=t.$translation.code)}},render(t){if(this.component)return t(this.component,{key:this.key,props:this.state.$view.props})}};function nt(t){if(void 0!==t)return JSON.parse(JSON.stringify(t))}function it(t,e){for(const n of Object.keys(e))e[n]instanceof Object&&Object.assign(e[n],it(t[n]||{},e[n]));return Object.assign(t||{},e),t}var st={clone:nt,isEmpty:function(t){return null==t||""===t||("object"==typeof t&&0===Object.keys(t).length&&t.constructor===Object||void 0!==t.length&&0===t.length)},merge:it};const ot=(t,e)=>{localStorage.setItem("kirby$content$"+t,JSON.stringify(e))};var rt={namespaced:!0,state:{current:null,models:{},status:{enabled:!0}},getters:{exists:t=>e=>Object.prototype.hasOwnProperty.call(t.models,e),hasChanges:(t,e)=>t=>{const n=e.model(t).changes;return Object.keys(n).length>0},isCurrent:t=>e=>t.current===e,id:t=>e=>(e=e||t.current,window.panel.$language?e+"?language="+window.panel.$language.code:e),model:(t,e)=>n=>(n=n||t.current,!0===e.exists(n)?t.models[n]:{api:null,originals:{},values:{},changes:{}}),originals:(t,e)=>t=>nt(e.model(t).originals),values:(t,e)=>t=>a(a({},e.originals(t)),e.changes(t)),changes:(t,e)=>t=>nt(e.model(t).changes)},mutations:{CLEAR(t){Object.keys(t.models).forEach((e=>{t.models[e].changes={}})),Object.keys(localStorage).forEach((t=>{t.startsWith("kirby$content$")&&localStorage.removeItem(t)}))},CREATE(t,[e,n]){if(!n)return!1;let i=t.models[e]?t.models[e].changes:n.changes;u.set(t.models,e,{api:n.api,originals:n.originals,changes:i||{}})},CURRENT(t,e){t.current=e},MOVE(t,[e,n]){const i=nt(t.models[e]);u.delete(t.models,e),u.set(t.models,n,i);const s=localStorage.getItem("kirby$content$"+e);localStorage.removeItem("kirby$content$"+e),localStorage.setItem("kirby$content$"+n,s)},REMOVE(t,e){u.delete(t.models,e),localStorage.removeItem("kirby$content$"+e)},REVERT(t,e){t.models[e]&&(u.set(t.models[e],"changes",{}),localStorage.removeItem("kirby$content$"+e))},STATUS(t,e){u.set(t.status,"enabled",e)},UPDATE(t,[e,n,i]){if(!t.models[e])return!1;void 0===i&&(i=null),i=nt(i);const s=JSON.stringify(i);JSON.stringify(t.models[e].originals[n])==s?u.delete(t.models[e].changes,n):u.set(t.models[e].changes,n,i),ot(e,{api:t.models[e].api,originals:t.models[e].originals,changes:t.models[e].changes})}},actions:{init(t){Object.keys(localStorage).filter((t=>t.startsWith("kirby$content$"))).map((t=>t.split("kirby$content$")[1])).forEach((e=>{const n=localStorage.getItem("kirby$content$"+e);t.commit("CREATE",[e,JSON.parse(n)])})),Object.keys(localStorage).filter((t=>t.startsWith("kirby$form$"))).map((t=>t.split("kirby$form$")[1])).forEach((e=>{const n=localStorage.getItem("kirby$form$"+e);let i=null;try{i=JSON.parse(n)}catch(o){}if(!i||!i.api)return localStorage.removeItem("kirby$form$"+e),!1;const s={api:i.api,originals:i.originals,changes:i.values};t.commit("CREATE",[e,s]),ot(e,s),localStorage.removeItem("kirby$form$"+e)}))},clear(t){t.commit("CLEAR")},create(t,e){const n=nt(e.content);Array.isArray(e.ignore)&&e.ignore.forEach((t=>delete n[t])),e.id=t.getters.id(e.id);const i={api:e.api,originals:n,changes:{}};t.commit("CREATE",[e.id,i]),t.dispatch("current",e.id)},current(t,e){t.commit("CURRENT",e)},disable(t){t.commit("STATUS",!1)},enable(t){t.commit("STATUS",!0)},move(t,[e,n]){e=t.getters.id(e),n=t.getters.id(n),t.commit("MOVE",[e,n])},remove(t,e){t.commit("REMOVE",e),t.getters.isCurrent(e)&&t.commit("CURRENT",null)},revert(t,e){e=e||t.state.current,t.commit("REVERT",e)},async save(t,e){if(e=e||t.state.current,t.getters.isCurrent(e)&&!1===t.state.status.enabled)return!1;t.dispatch("disable");const n=t.getters.model(e),i=a(a({},n.originals),n.changes);try{await u.$api.patch(n.api,i),t.commit("CREATE",[e,l(a({},n),{originals:i})]),t.dispatch("revert",e)}finally{t.dispatch("enable")}},update(t,[e,n,i]){i=i||t.state.current,t.commit("UPDATE",[i,e,n])}}},at={namespaced:!0,state:{open:[]},mutations:{CLOSE(t,e){t.open=e?t.open.filter((t=>t.id!==e)):[]},GOTO(t,e){t.open=t.open.slice(0,t.open.findIndex((t=>t.id===e))+1)},OPEN(t,e){t.open.push(e)}},actions:{close(t,e){t.commit("CLOSE",e)},goto(t,e){t.commit("GOTO",e)},open(t,e){t.commit("OPEN",e)}}},lt={timer:null,namespaced:!0,state:{type:null,message:null,details:null,timeout:null},mutations:{SET(t,e){t.type=e.type,t.message=e.message,t.details=e.details,t.timeout=e.timeout},UNSET(t){t.type=null,t.message=null,t.details=null,t.timeout=null}},actions:{close(t){clearTimeout(this.timer),t.commit("UNSET")},deprecated(t,e){console.warn("Deprecated: "+e)},error(t,e){let n=e;"string"==typeof e&&(n={message:e}),e instanceof Error&&(n={message:e.message},window.panel.$config.debug&&window.console.error(e)),t.dispatch("dialog",{component:"k-error-dialog",props:n},{root:!0}),t.dispatch("close")},open(t,e){t.dispatch("close"),t.commit("SET",e),e.timeout&&(this.timer=setTimeout((()=>{t.dispatch("close")}),e.timeout))},success(t,e){"string"==typeof e&&(e={message:e}),t.dispatch("open",a({type:"success",timeout:4e3},e))}}};u.use(c);var ut=new c.Store({strict:!1,state:{dialog:null,drag:null,fatal:!1,isLoading:!1},mutations:{SET_DIALOG(t,e){t.dialog=e},SET_DRAG(t,e){t.drag=e},SET_FATAL(t,e){t.fatal=e},SET_LOADING(t,e){t.isLoading=e}},actions:{dialog(t,e){t.commit("SET_DIALOG",e)},drag(t,e){t.commit("SET_DRAG",e)},fatal(t,e){!1!==e?(console.error("The JSON response could not be parsed"),window.panel.$config.debug&&console.info(e.html),e.silent||t.commit("SET_FATAL",e.html)):t.commit("SET_FATAL",!1)},isLoading(t,e){t.commit("SET_LOADING",!0===e)},navigate(t){t.dispatch("dialog",null),t.dispatch("drawers/close")}},modules:{content:rt,drawers:at,notification:lt}}),ct={install(t){window.panel=window.panel||{},window.onunhandledrejection=t=>{t.preventDefault(),ut.dispatch("notification/error",t.reason)},window.panel.deprecated=t=>{ut.dispatch("notification/deprecated",t)},window.panel.error=t.config.errorHandler=t=>{ut.dispatch("notification/error",t)}}},dt={install(t){const e=d(),n={$on:e.on,$off:e.off,$emit:e.emit,click(t){n.$emit("click",t)},copy(t){n.$emit("copy",t)},dragenter(t){n.entered=t.target,n.prevent(t),n.$emit("dragenter",t)},dragleave(t){n.prevent(t),n.entered===t.target&&n.$emit("dragleave",t)},drop(t){n.prevent(t),n.$emit("drop",t)},entered:null,focus(t){n.$emit("focus",t)},keydown(e){let i=["keydown"];(e.metaKey||e.ctrlKey)&&i.push("cmd"),!0===e.altKey&&i.push("alt"),!0===e.shiftKey&&i.push("shift");let s=t.prototype.$helper.string.lcfirst(e.key);const o={escape:"esc",arrowUp:"up",arrowDown:"down",arrowLeft:"left",arrowRight:"right"};o[s]&&(s=o[s]),!1===["alt","control","shift","meta"].includes(s)&&i.push(s),n.$emit(i.join("."),e),n.$emit("keydown",e)},keyup(t){n.$emit("keyup",t)},online(t){n.$emit("online",t)},offline(t){n.$emit("offline",t)},paste(t){n.$emit("paste",t)},prevent(t){t.stopPropagation(),t.preventDefault()}};window.addEventListener("online",n.online),window.addEventListener("offline",n.offline),window.addEventListener("dragenter",n.dragenter,!1),window.addEventListener("dragover",n.prevent,!1),window.addEventListener("dragexit",n.prevent,!1),window.addEventListener("dragleave",n.dragleave,!1),window.addEventListener("drop",n.drop,!1),window.addEventListener("keydown",n.keydown,!1),window.addEventListener("keyup",n.keyup,!1),document.addEventListener("click",n.click,!1),document.addEventListener("copy",n.copy,!0),document.addEventListener("focus",n.focus,!0),document.addEventListener("paste",n.paste,!0),t.prototype.$events=n}};class pt{constructor(t={}){this.options=a({base:"/",headers:()=>({}),onFatal:()=>{},onFinish:()=>{},onPushState:()=>{},onReplaceState:()=>{},onStart:()=>{},onSwap:()=>{},query:()=>({})},t),this.state={}}init(t={},e={}){this.options=a(a({},this.options),e),this.setState(t)}arrayToString(t){return!1===Array.isArray(t)?String(t):t.join(",")}body(t){return"object"==typeof t?JSON.stringify(t):t}async fetch(t,e){return fetch(t,e)}async go(t,e){try{const n=await this.request(t,e);return!1!==n&&this.setState(n,e)}catch(n){if(!0!==(null==e?void 0:e.silent))throw n}}query(t={},e={}){let n=new URLSearchParams(e);return"object"!=typeof t&&(t={}),Object.entries(t).forEach((([t,e])=>{null!==e&&n.set(t,e)})),Object.entries(this.options.query()).forEach((([t,e])=>{var i,s;null!==(e=null!=(s=null!=(i=n.get(t))?i:e)?s:null)&&n.set(t,e)})),n}redirect(t){window.location.href=t}reload(t={}){return this.go(window.location.href,l(a({},t),{replace:!0}))}async request(t="",e={}){var n;const i=!!(e=a({globals:!1,method:"GET",only:[],query:{},silent:!1,type:"$view"},e)).globals&&this.arrayToString(e.globals),s=this.arrayToString(e.only);this.options.onStart(e);try{const r=this.url(t,e.query);if(new URL(r).origin!==location.origin)return this.redirect(r),!1;const u=await this.fetch(r,{method:e.method,body:this.body(e.body),credentials:"same-origin",cache:"no-store",headers:a(l(a({},this.options.headers()),{"X-Fiber":!0,"X-Fiber-Globals":i,"X-Fiber-Only":s,"X-Fiber-Referrer":(null==(n=this.state.$view)?void 0:n.path)||null}),e.headers)});if(!1===u.headers.has("X-Fiber"))return this.redirect(u.url),!1;const c=await u.text();let d;try{d=JSON.parse(c)}catch(o){return this.options.onFatal({url:r,path:t,options:e,response:u,text:c}),!1}if(!d[e.type])throw Error(`The ${e.type} could not be loaded`);const p=d[e.type];if(p.error)throw Error(p.error);return"$view"===e.type?s.length?it(this.state,d):d:p}finally{this.options.onFinish(e)}}async setState(t,e={}){return"object"==typeof t&&(this.state=nt(t),!0===e.replace||this.url(this.state.$url).href===window.location.href?this.options.onReplaceState(this.state,e):this.options.onPushState(this.state,e),this.options.onSwap(this.state,e),this.state)}url(t="",e={}){return(t="string"==typeof t&&null===t.match(/^https?:\/\//)?new URL(this.options.base+t.replace(/^\//,"")):new URL(t)).search=this.query(e,t.search),t}}const ht=async function(t){return a({cancel:null,submit:null,props:{}},t)},ft=async function(t,e={}){let n=null,i=null;"function"==typeof e?(n=e,e={}):(n=e.submit,i=e.cancel);let s=await this.$fiber.request("dialogs/"+t,l(a({},e),{type:"$dialog"}));return"object"==typeof s&&(s.submit=n||null,s.cancel=i||null,s)};async function mt(t,e={}){let n=null;if(n="object"==typeof t?await ht.call(this,t):await ft.call(this,t,e),!n)return!1;if(!n.component||!1===this.$helper.isComponent(n.component))throw Error("The dialog component does not exist");return n.props=n.props||{},this.$store.dispatch("dialog",n),n}function gt(t,e={}){return async n=>{const i=await this.$fiber.request("dropdowns/"+t,l(a({},e),{type:"$dropdown"}));if(!i)return!1;if(!1===Array.isArray(i.options)||0===i.options.length)throw Error("The dropdown is empty");i.options.map((t=>(t.dialog&&(t.click=()=>{const e="string"==typeof t.dialog?t.dialog:t.dialog.url,n="object"==typeof t.dialog?t.dialog:{};return this.$dialog(e,n)}),t))),n(i.options)}}async function kt(t,e,n={}){return await this.$fiber.request("search/"+t,a({query:{query:e},type:"$search"},n))}var vt={install(t){const e=new pt;t.prototype.$fiber=window.panel.$fiber=e,t.prototype.$dialog=window.panel.$dialog=mt,t.prototype.$dropdown=window.panel.$dropdown=gt,t.prototype.$go=window.panel.$go=e.go.bind(e),t.prototype.$reload=window.panel.$reload=e.reload.bind(e),t.prototype.$request=window.panel.$request=e.request.bind(e),t.prototype.$search=window.panel.$search=kt,t.prototype.$url=window.panel.$url=e.url.bind(e)}};var bt={read:function(t){if(!t)return null;if("string"==typeof t)return t;if(t instanceof ClipboardEvent){t.preventDefault();const e=t.clipboardData.getData("text/html")||t.clipboardData.getData("text/plain")||null;if(e)return e.replace(/\u00a0/g," ")}return null},write:function(t,e){if("string"!=typeof t&&(t=JSON.stringify(t,null,2)),e&&e instanceof ClipboardEvent)return e.preventDefault(),e.clipboardData.setData("text/plain",t),!0;const n=document.createElement("textarea");if(n.value=t,document.body.append(n),navigator.userAgent.match(/ipad|ipod|iphone/i)){n.contentEditable=!0,n.readOnly=!0;const t=document.createRange();t.selectNodeContents(n);const e=window.getSelection();e.removeAllRanges(),e.addRange(t),n.setSelectionRange(0,999999)}else n.select();return document.execCommand("copy"),n.remove(),!0}};function yt(t){if("string"==typeof t){if("pattern"===(t=t.toLowerCase()))return"var(--color-gray-800) var(--bg-pattern)";if(!1===t.startsWith("#")&&!1===t.startsWith("var(")){const e="--color-"+t;if(window.getComputedStyle(document.documentElement).getPropertyValue(e))return`var(${e})`}return t}}var $t=(t,e)=>{let n=null;return function(){clearTimeout(n),n=setTimeout((()=>t.apply(this,arguments)),e)}};function _t(t,e=!1){if(!t.match("youtu"))return!1;let n=null;try{n=new URL(t)}catch(d){return!1}const i=n.pathname.split("/").filter((t=>""!==t)),s=i[0],o=i[1],r="https://"+(!0===e?"www.youtube-nocookie.com":n.host)+"/embed",a=t=>!!t&&null!==t.match(/^[a-zA-Z0-9_-]+$/);let l=n.searchParams,u=null;switch(i.join("/")){case"embed/videoseries":case"playlist":a(l.get("list"))&&(u=r+"/videoseries");break;case"watch":a(l.get("v"))&&(u=r+"/"+l.get("v"),l.has("t")&&l.set("start",l.get("t")),l.delete("v"),l.delete("t"));break;default:n.host.includes("youtu.be")&&a(s)?(u="https://www.youtube.com/embed/"+s,l.has("t")&&l.set("start",l.get("t")),l.delete("t")):"embed"===s&&a(o)&&(u=r+"/"+o)}if(!u)return!1;const c=l.toString();return c.length&&(u+="?"+c),u}function xt(t,e=!1){let n=null;try{n=new URL(t)}catch(l){return!1}const i=n.pathname.split("/").filter((t=>""!==t));let s=n.searchParams,o=null;switch(!0===e&&s.append("dnt",1),n.host){case"vimeo.com":case"www.vimeo.com":o=i[0];break;case"player.vimeo.com":o=i[1]}if(!o||!o.match(/^[0-9]*$/))return!1;let r="https://player.vimeo.com/video/"+o;const a=s.toString();return a.length&&(r+="?"+a),r}var wt={youtube:_t,vimeo:xt,video:function(t,e=!1){return t.includes("youtu")?_t(t,e):!!t.includes("vimeo")&&xt(t,e)}},St=t=>void 0!==u.options.components[t],Ct=t=>!!t.dataTransfer&&(!!t.dataTransfer.types&&(!0===t.dataTransfer.types.includes("Files")&&!1===t.dataTransfer.types.includes("text/plain")));var Ot={metaKey:function(){return window.navigator.userAgent.indexOf("Mac")>-1?"cmd":"ctrl"}},Et=(t="3/2",e="100%",n=!0)=>{const i=String(t).split("/");if(2!==i.length)return e;const s=Number(i[0]),o=Number(i[1]);let r=100;return 0!==s&&0!==o&&(r=n?r/s*o:r/o*s,r=parseFloat(String(r)).toFixed(2)),r+"%"},At=t=>{var e=(t=t||{}).desc?-1:1,n=-e,i=/^0/,s=/\s+/g,o=/^\s+|\s+$/g,r=/[^\x00-\x80]/,a=/^0x[0-9a-f]+$/i,l=/(0x[\da-fA-F]+|(^[\+\-]?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?(?=\D|\s|$))|\d+)/g,u=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,c=t.insensitive?function(t){return function(t){if(t.toLocaleLowerCase)return t.toLocaleLowerCase();return t.toLowerCase()}(""+t).replace(o,"")}:function(t){return(""+t).replace(o,"")};function d(t){return t.replace(l,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0")}function p(t,e){return(!t.match(i)||1===e)&&parseFloat(t)||t.replace(s," ").replace(o,"")||0}return function(t,i){var s=c(t),o=c(i);if(!s&&!o)return 0;if(!s&&o)return n;if(s&&!o)return e;var l=d(s),h=d(o),f=parseInt(s.match(a),16)||1!==l.length&&Date.parse(s),m=parseInt(o.match(a),16)||f&&o.match(u)&&Date.parse(o)||null;if(m){if(fm)return e}for(var g=l.length,k=h.length,v=0,b=Math.max(g,k);v0)return e;if(_<0)return n;if(v===b-1)return 0}else{if(y<$)return n;if(y>$)return e}}return 0}};function Tt(t){const e={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};return String(t).replace(/[&<>"'`=/]/g,(t=>e[t]))}function It(t,e={}){const n=(t,e={})=>{var i;const s=Tt(t.shift()),o=null!=(i=e[s])?i:null;return null===o?Object.prototype.hasOwnProperty.call(e,s)||"…":0===t.length?o:n(t,o)},i="[{]{1,2}[\\s]?",s="[\\s]?[}]{1,2}";return(t=t.replace(new RegExp(`${i}(.*?)${s}`,"gi"),((t,i)=>n(i.split("."),e)))).replace(new RegExp(`${i}.*${s}`,"gi"),"…")}function Mt(t){const e=String(t);return e.charAt(0).toUpperCase()+e.slice(1)}RegExp.escape=function(t){return t.replace(new RegExp("[-/\\\\^$*+?.()[\\]{}]","gu"),"\\$&")};var Lt={camelToKebab:function(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()},escapeHTML:Tt,hasEmoji:function(t){if("string"!=typeof t)return!1;const e=t.match(/(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|[\ud83c\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|[\ud83c\ude32-\ude3a]|[\ud83c\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])/i);return null!==e&&null!==e.length},lcfirst:function(t){const e=String(t);return e.charAt(0).toLowerCase()+e.slice(1)},pad:function(t,e=2){t=String(t);let n="";for(;n.length]+)>)/gi,"")},template:It,ucfirst:Mt,ucwords:function(t){return String(t).split(/ /g).map((t=>Mt(t))).join(" ")},uuid:function(){let t,e,n="";for(t=0;t<32;t++)e=16*Math.random()|0,8!=t&&12!=t&&16!=t&&20!=t||(n+="-"),n+=(12==t?4:16==t?3&e|8:e).toString(16);return n}},jt=(t,e)=>{const n=Object.assign({url:"/",field:"file",method:"POST",attributes:{},complete:function(){},error:function(){},success:function(){},progress:function(){}},e),i=new FormData;i.append(n.field,t,t.name),n.attributes&&Object.keys(n.attributes).forEach((t=>{i.append(t,n.attributes[t])}));const s=new XMLHttpRequest,o=e=>{if(!e.lengthComputable||!n.progress)return;let i=Math.max(0,Math.min(100,e.loaded/e.total*100));n.progress(s,t,Math.ceil(i))};s.upload.addEventListener("loadstart",o),s.upload.addEventListener("progress",o),s.addEventListener("load",(e=>{let i=null;try{i=JSON.parse(e.target.response)}catch(o){i={status:"error",message:"The file could not be uploaded"}}"error"===i.status?n.error(s,t,i):(n.success(s,t,i),n.progress(s,t,100))})),s.addEventListener("error",(e=>{const i=JSON.parse(e.target.response);n.error(s,t,i),n.progress(s,t,100)})),s.open(n.method,n.url,!0),n.headers&&Object.keys(n.headers).forEach((t=>{const e=n.headers[t];s.setRequestHeader(t,e)})),s.send(i)},Dt={install(t){Array.prototype.sortBy=function(e){const n=t.prototype.$helper.sort(),i=e.split(" "),s=i[0],o=i[1]||"asc";return this.sort(((t,e)=>{const i=String(t[s]).toLowerCase(),r=String(e[s]).toLowerCase();return"desc"===o?n(r,i):n(i,r)}))},t.prototype.$helper={clipboard:bt,clone:st.clone,color:yt,embed:wt,isComponent:St,isUploadEvent:Ct,debounce:$t,keyboard:Ot,object:st,pad:Lt.pad,ratio:Et,slug:Lt.slug,sort:At,string:Lt,upload:jt,uuid:Lt.uuid},t.prototype.$esc=Lt.escapeHTML}},Bt={install(t){t.$t=t.prototype.$t=window.panel.$t=(t,e,n=null)=>{if("string"!=typeof t)return;const i=window.panel.$translation.data[t]||n;return"string"!=typeof i?i:It(i,e)},t.directive("direction",{inserted(t,e,n){!0!==n.context.disabled?t.dir=n.context.$direction:t.dir=null}})}};p.extend(h),p.extend(((t,e,n)=>{n.interpret=(t,e="date")=>{const i={date:{"YYYY-MM-DD":!0,"YYYY-MM-D":!0,"YYYY-MM-":!0,"YYYY-MM":!0,"YYYY-M-DD":!0,"YYYY-M-D":!0,"YYYY-M-":!0,"YYYY-M":!0,"YYYY-":!0,YYYYMMDD:!0,"MMM DD YYYY":!1,"MMM D YYYY":!1,"MMM DD YY":!1,"MMM D YY":!1,"MMM DD":!1,"MMM D":!1,"DD MMMM YYYY":!1,"DD MMMM YY":!1,"DD MMMM":!1,"D MMMM YYYY":!1,"D MMMM YY":!1,"D MMMM":!1,"DD MMM YYYY":!1,"D MMM YYYY":!1,"DD MMM YY":!1,"D MMM YY":!1,"DD MMM":!1,"D MMM":!1,"DD MM YYYY":!1,"DD M YYYY":!1,"D MM YYYY":!1,"D M YYYY":!1,"DD MM YY":!1,"D MM YY":!1,"DD M YY":!1,"D M YY":!1,YYYY:!0,MMMM:!0,MMM:!0,"DD MM":!1,"DD M":!1,"D MM":!1,"D M":!1,DD:!1,D:!1},time:{"HH:mm:ss a":!1,"HH:mm:ss":!1,"HH:mm a":!1,"HH:mm":!1,"HH a":!1,HH:!1}};if("string"==typeof t&&""!==t)for(const s in i[e]){const o=n(t,s,i[e][s]);if(!0===o.isValid())return o}return null}})),p.extend(((t,e,n)=>{const i=t=>"date"===t?"YYYY-MM-DD":"time"===t?"HH:mm:ss":"YYYY-MM-DD HH:mm:ss";e.prototype.toISO=function(t="datetime"){return this.format(i(t))},n.iso=function(t,e="datetime"){const s=n(t,i(e));return s&&s.isValid()?s:null}})),p.extend(((t,e)=>{e.prototype.merge=function(t,e="date"){let n=this.clone();if(!t||!t.isValid())return this;if("string"==typeof e){const t={date:["year","month","date"],time:["hour","minute","second"]};if(!1===Object.prototype.hasOwnProperty.call(t,e))throw new Error("Invalid merge unit alias");e=t[e]}for(const i of e)n=n.set(i,t.get(i));return n}})),p.extend(((t,e,n)=>{n.pattern=t=>new class{constructor(t,e){this.dayjs=t,this.pattern=e;const n={year:["YY","YYYY"],month:["M","MM","MMM","MMMM"],day:["D","DD"],hour:["h","hh","H","HH"],minute:["m","mm"],second:["s","ss"],meridiem:["a"]};this.parts=this.pattern.split(/\W/).map(((t,e)=>{const i=this.pattern.indexOf(t);return{index:e,unit:Object.keys(n)[Object.values(n).findIndex((e=>e.includes(t)))],start:i,end:i+(t.length-1)}}))}at(t,e=t){const n=this.parts.filter((n=>n.start<=t&&n.end>=e-1));return n[0]?n[0]:this.parts.filter((e=>e.start<=t)).pop()}format(t){return t&&t.isValid()?t.format(this.pattern):null}}(n,t)})),p.extend(((t,e)=>{e.prototype.round=function(t="date",e=1){const n=["second","minute","hour","date","month","year"];if("day"===t&&(t="date"),!1===n.includes(t))throw new Error("Invalid rounding unit");if(["date","month","year"].includes(t)&&1!==e||"hour"===t&&24%e!=0||["second","minute"].includes(t)&&60%e!=0)throw"Invalid rounding size for "+t;let i=this.clone();const s=n.indexOf(t),o=n.slice(0,s),r=o.pop();if(o.forEach((t=>i=i.startOf(t))),r){const e={month:12,date:i.daysInMonth(),hour:24,minute:60,second:60}[r];Math.round(i.get(r)/e)*e===e&&(i=i.add(1,"date"===t?"day":t)),i=i.startOf(t)}return i=i.set(t,Math.round(i.get(t)/e)*e),i}})),p.extend(((t,e,n)=>{e.prototype.validate=function(t,e,i="day"){if(!this.isValid())return!1;if(!t)return!0;t=n.iso(t);const s={min:"isAfter",max:"isBefore"}[e];return this.isSame(t,i)||this[s](t,i)}}));var Pt={install(t){t.prototype.$library={autosize:f,dayjs:p}}},Nt={props:{blueprint:String,lock:[Boolean,Object],help:String,name:String,parent:String,timestamp:Number},methods:{load(){return this.$api.get(this.parent+"/sections/"+this.name)}}},qt={install(t){const e=a({},t.options.components),n={section:Nt};for(const[i,s]of Object.entries(window.panel.plugins.components))s.template||s.render||s.extends?("string"==typeof(null==s?void 0:s.extends)&&(e[s.extends]?s.extends=e[s.extends].extend({options:s,components:a(a({},e),s.components||{})}):s.extends=null),s.template&&(s.render=null),s.mixins&&(s.mixins=s.mixins.map((t=>"string"==typeof t?n[t]:t))),e[i]&&window.console.warn(`Plugin is replacing "${i}"`),t.component(i,s),e[i]=t.options.components[i]):ut.dispatch("notification/error",`Neither template or render method provided nor extending a component when loading plugin component "${i}". The component has not been registered.`);for(const i of window.panel.plugins.use)t.use(i)}};function Ft(t,e,n,i,s,o,r,a){var l,u="function"==typeof t?t.options:t;if(e&&(u.render=e,u.staticRenderFns=n,u._compiled=!0),i&&(u.functional=!0),o&&(u._scopeId="data-v-"+o),r?(l=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),s&&s.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(r)},u._ssrRegister=l):s&&(l=a?function(){s.call(this,(u.functional?this.parent:this).$root.$options.shadowRoot)}:s),l)if(u.functional){u._injectStyles=l;var c=u.render;u.render=function(t,e){return l.call(e),c(t,e)}}else{var d=u.beforeCreate;u.beforeCreate=d?[].concat(d,l):[l]}return{exports:t,options:u}}const Rt={props:{autofocus:{type:Boolean,default:!0},cancelButton:{type:[String,Boolean],default:!0},icon:{type:String,default:"check"},size:{type:String,default:"default"},submitButton:{type:[String,Boolean],default:!0},theme:String,visible:Boolean},data:()=>({notification:null}),computed:{buttons(){let t=[];return this.cancelButton&&t.push({icon:"cancel",text:this.cancelButtonLabel,class:"k-dialog-button-cancel",click:this.cancel}),this.submitButtonConfig&&t.push({icon:this.icon,text:this.submitButtonLabel,theme:this.theme,class:"k-dialog-button-submit",click:this.submit}),t},cancelButtonLabel(){return!1!==this.cancelButton&&(!0===this.cancelButton||0===this.cancelButton.length?this.$t("cancel"):this.cancelButton)},submitButtonConfig(){return void 0!==this.$attrs.button?this.$attrs.button:void 0===this.submitButton||this.submitButton},submitButtonLabel(){return!0===this.submitButton||0===this.submitButton.length?this.$t("confirm"):this.submitButton}},created(){this.$events.$on("keydown.esc",this.close,!1)},destroyed(){this.$events.$off("keydown.esc",this.close,!1)},mounted(){this.visible&&this.$nextTick(this.open)},methods:{onOverlayClose(){this.notification=null,this.$emit("close"),this.$events.$off("keydown.esc",this.close),this.$store.dispatch("dialog",!1)},open(){this.$store.state.dialog||this.$store.dispatch("dialog",!0),this.notification=null,this.$refs.overlay.open(),this.$emit("open"),this.$events.$on("keydown.esc",this.close)},close(){this.$refs.overlay&&this.$refs.overlay.close()},cancel(){this.$emit("cancel"),this.close()},focus(){var t;if(null==(t=this.$refs.dialog)?void 0:t.querySelector){const t=this.$refs.dialog.querySelector(".k-dialog-button-cancel");"function"==typeof(null==t?void 0:t.focus)&&t.focus()}},error(t){this.notification={message:t,type:"error"}},submit(){this.$emit("submit")},success(t){this.notification={message:t,type:"success"}}}},zt={};var Yt=Ft(Rt,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-overlay",{ref:"overlay",attrs:{autofocus:t.autofocus,centered:!0},on:{close:t.onOverlayClose,ready:function(e){return t.$emit("ready")}}},[n("div",{ref:"dialog",staticClass:"k-dialog",class:t.$vnode.data.staticClass,attrs:{"data-size":t.size},on:{mousedown:function(t){t.stopPropagation()}}},[t.notification?n("div",{staticClass:"k-dialog-notification",attrs:{"data-theme":t.notification.type}},[n("p",[t._v(t._s(t.notification.message))]),n("k-button",{attrs:{icon:"cancel"},on:{click:function(e){t.notification=null}}})],1):t._e(),n("div",{staticClass:"k-dialog-body scroll-y-auto"},[t._t("default")],2),t.$slots.footer||t.buttons.length?n("footer",{staticClass:"k-dialog-footer"},[t._t("footer",(function(){return[n("k-button-group",{attrs:{buttons:t.buttons}})]}))],2):t._e()])])}),[],!1,Ht,null,null,null);function Ht(t){for(let e in zt)this[e]=zt[e]}var Ut=function(){return Yt.exports}(),Kt={props:{autofocus:{type:Boolean,default:!0},cancelButton:{type:[String,Boolean],default:!0},icon:String,submitButton:{type:[String,Boolean],default:!0},size:String,theme:String,visible:Boolean},methods:{close(){this.$refs.dialog.close(),this.$emit("close")},error(t){this.$refs.dialog.error(t)},open(){this.$refs.dialog.open(),this.$emit("open")},success(t){this.$refs.dialog.close(),t.route&&this.$go(t.route),t.message&&this.$store.dispatch("notification/success",t.message),t.event&&("string"==typeof t.event&&(t.event=[t.event]),t.event.forEach((e=>{this.$events.$emit(e,t)}))),!1!==Object.prototype.hasOwnProperty.call(t,"emit")&&!1===t.emit||this.$emit("success")}}};const Jt={};var Gt=Ft({mixins:[Kt],props:{details:[Object,Array],message:String,size:{type:String,default:"medium"}},computed:{detailsList(){return Array.isArray(this.details)?this.details:Object.values(this.details||{})}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-dialog",{ref:"dialog",staticClass:"k-error-dialog",attrs:{"cancel-button":!1,size:t.size,visible:!0},on:{cancel:function(e){return t.$emit("cancel")},close:function(e){return t.$emit("close")},submit:function(e){return t.$refs.dialog.close()}}},[n("k-text",[t._v(t._s(t.message))]),t.detailsList.length?n("dl",{staticClass:"k-error-details"},[t._l(t.detailsList,(function(e,i){return[n("dt",{key:"detail-label-"+i},[t._v(" "+t._s(e.label)+" ")]),n("dd",{key:"detail-message-"+i},["object"==typeof e.message?[n("ul",t._l(e.message,(function(e,i){return n("li",{key:i},[t._v(" "+t._s(e)+" ")])})),0)]:[t._v(" "+t._s(e.message)+" ")]],2)]}))],2):t._e()],1)}),[],!1,Vt,null,null,null);function Vt(t){for(let e in Jt)this[e]=Jt[e]}var Wt=function(){return Gt.exports}();const Xt={};var Zt=Ft({props:{code:Number,component:String,path:String,props:Object,referrer:String},methods:{close(){this.$refs.dialog.close()},onCancel(){"function"==typeof this.$store.state.dialog.cancel&&this.$store.state.dialog.cancel({dialog:this})},async onSubmit(t){let e=null;try{if("function"==typeof this.$store.state.dialog.submit)e=await this.$store.state.dialog.submit({dialog:this,value:t});else{if(!this.path)throw"The dialog needs a submit action or a dialog route path to be submitted";e=await this.$request(this.path,{body:t,method:"POST",type:"$dialog",headers:{"X-Fiber-Referrer":this.referrer}})}if(!1===e)return!1;this.close(),this.$store.dispatch("notification/success",":)"),e.event&&("string"==typeof e.event&&(e.event=[e.event]),e.event.forEach((t=>{this.$events.$emit(t,e)}))),e.dispatch&&Object.keys(e.dispatch).forEach((t=>{const n=e.dispatch[t];this.$store.dispatch(t,!0===Array.isArray(n)?[...n]:n)})),e.redirect?this.$go(e.redirect):this.$reload(e.reload||{})}catch(n){this.$refs.dialog.error(n)}}}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)(t.component,t._b({ref:"dialog",tag:"component",attrs:{visible:!0},on:{cancel:t.onCancel,submit:t.onSubmit}},"component",t.props,!1))}),[],!1,Qt,null,null,null);function Qt(t){for(let e in Xt)this[e]=Xt[e]}var te=function(){return Zt.exports}(),ee={data:()=>({models:[],issue:null,selected:{},options:{endpoint:null,max:null,multiple:!0,parent:null,selected:[],search:!0},search:null,pagination:{limit:20,page:1,total:0}}),computed:{checkedIcon(){return!0===this.multiple?"check":"circle-filled"},collection(){return{empty:this.emptyProps,items:this.items,link:!1,layout:"list",pagination:a({details:!0,dropdown:!1,align:"center"},this.pagination),sortable:!1}},items(){return this.models.map(this.item)},multiple(){return!0===this.options.multiple&&1!==this.options.max}},watch:{search(){this.updateSearch()}},created(){this.updateSearch=$t(this.updateSearch,200)},methods:{async fetch(){const t=a({page:this.pagination.page,search:this.search},this.fetchData||{});try{const e=await this.$api.get(this.options.endpoint,t);this.models=e.data,this.pagination=e.pagination,this.onFetched&&this.onFetched(e)}catch(e){this.models=[],this.issue=e.message}},async open(t,e){this.pagination.page=0,this.search=null;let n=!0;Array.isArray(t)?(this.models=t,n=!1):(this.models=[],e=t),this.options=a(a({},this.options),e),this.selected={},this.options.selected.forEach((t=>{this.$set(this.selected,t,{id:t})})),n&&await this.fetch(),this.$refs.dialog.open()},paginate(t){this.pagination.page=t.page,this.pagination.limit=t.limit,this.fetch()},submit(){this.$emit("submit",Object.values(this.selected)),this.$refs.dialog.close()},isSelected(t){return void 0!==this.selected[t.id]},item:t=>t,toggle(t){!1!==this.options.multiple&&1!==this.options.max||(this.selected={}),!0!==this.isSelected(t)?this.options.max&&this.options.max<=Object.keys(this.selected).length||this.$set(this.selected,t.id,t):this.$delete(this.selected,t.id)},toggleBtn(t){const e=this.isSelected(t);return{icon:e?this.checkedIcon:"circle-outline",tooltip:e?this.$t("remove"):this.$t("select"),theme:e?"positive":null}},updateSearch(){this.pagination.page=0,this.fetch()}}};const ne={};var ie=Ft({mixins:[ee],computed:{emptyProps(){return{icon:"image",text:this.$t("dialog.files.empty")}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-dialog",{ref:"dialog",staticClass:"k-files-dialog",attrs:{size:"medium"},on:{cancel:function(e){return t.$emit("cancel")},submit:t.submit}},[t.issue?[n("k-box",{attrs:{text:t.issue,theme:"negative"}})]:[t.options.search?n("k-input",{staticClass:"k-dialog-search",attrs:{autofocus:!0,placeholder:t.$t("search")+" …",type:"text",icon:"search"},model:{value:t.search,callback:function(e){t.search=e},expression:"search"}}):t._e(),n("k-collection",t._b({on:{item:t.toggle,paginate:t.paginate},scopedSlots:t._u([{key:"options",fn:function(e){var i=e.item;return[n("k-button",t._b({on:{click:function(e){return t.toggle(i)}}},"k-button",t.toggleBtn(i),!1))]}}])},"k-collection",t.collection,!1))]],2)}),[],!1,se,null,null,null);function se(t){for(let e in ne)this[e]=ne[e]}var oe=function(){return ie.exports}();const re={mixins:[Kt],props:{fields:{type:[Array,Object],default:()=>[]},novalidate:{type:Boolean,default:!0},size:{type:String,default:"medium"},submitButton:{type:[String,Boolean],default:()=>window.panel.$t("save")},text:{type:String},theme:{type:String,default:"positive"},value:{type:Object,default:()=>({})}},data(){return{model:this.value}},computed:{hasFields(){return Object.keys(this.fields).length>0}},watch:{value(t,e){t!==e&&(this.model=t)}}},ae={};var le=Ft(re,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-dialog",t._b({ref:"dialog",on:{cancel:function(e){return t.$emit("cancel")},close:function(e){return t.$emit("close")},ready:function(e){return t.$emit("ready")},submit:function(e){return t.$refs.form.submit()}}},"k-dialog",t.$props,!1),[t.text?[n("k-text",{domProps:{innerHTML:t._s(t.text)}})]:t._e(),t.hasFields?n("k-form",{ref:"form",attrs:{value:t.model,fields:t.fields,novalidate:t.novalidate},on:{input:function(e){return t.$emit("input",e)},submit:function(e){return t.$emit("submit",e)}}}):n("k-box",{attrs:{theme:"negative"}},[t._v(" This form dialog has no fields ")])],2)}),[],!1,ue,null,null,null);function ue(t){for(let e in ae)this[e]=ae[e]}var ce=function(){return le.exports}();const de={};var pe=Ft({extends:ce,watch:{"model.name"(t){this.fields.code.disabled||this.onNameChanges(t)},"model.code"(t){this.fields.code.disabled||(this.model.code=this.$helper.slug(t,[this.$system.ascii]),this.onCodeChanges(this.model.code))}},methods:{onCodeChanges(t){if(!t)return this.model.locale=null;if(t.length>=2)if(-1!==t.indexOf("-")){let e=t.split("-"),n=[e[0],e[1].toUpperCase()];this.model.locale=n.join("_")}else{let e=this.$system.locales||[];(null==e?void 0:e[t])?this.model.locale=e[t]:this.model.locale=null}},onNameChanges(t){this.model.code=this.$helper.slug(t,[this.model.rules,this.$system.ascii]).substr(0,2)}}},undefined,undefined,!1,he,null,null,null);function he(t){for(let e in de)this[e]=de[e]}var fe=function(){return pe.exports}();const me={};var ge=Ft({mixins:[ee],data(){const t=ee.data();return l(a({},t),{model:{title:null,parent:null},options:l(a({},t.options),{parent:null})})},computed:{emptyProps(){return{icon:"page",text:this.$t("dialog.pages.empty")}},fetchData(){return{parent:this.options.parent}}},methods:{back(){this.options.parent=this.model.parent,this.pagination.page=1,this.fetch()},go(t){this.options.parent=t.id,this.pagination.page=1,this.fetch()},onFetched(t){this.model=t.model}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-dialog",{ref:"dialog",staticClass:"k-pages-dialog",attrs:{size:"medium"},on:{cancel:function(e){return t.$emit("cancel")},submit:t.submit}},[t.issue?[n("k-box",{attrs:{text:t.issue,theme:"negative"}})]:[t.model?n("header",{staticClass:"k-pages-dialog-navbar"},[n("k-button",{attrs:{disabled:!t.model.id,tooltip:t.$t("back"),icon:"angle-left"},on:{click:t.back}}),n("k-headline",[t._v(t._s(t.model.title))])],1):t._e(),t.options.search?n("k-input",{staticClass:"k-dialog-search",attrs:{autofocus:!0,placeholder:t.$t("search")+" …",type:"text",icon:"search"},model:{value:t.search,callback:function(e){t.search=e},expression:"search"}}):t._e(),n("k-collection",t._b({on:{item:t.toggle,paginate:t.paginate},scopedSlots:t._u([{key:"options",fn:function(e){var i=e.item;return[n("k-button",t._b({on:{click:function(e){return t.toggle(i)}}},"k-button",t.toggleBtn(i),!1)),i?n("k-button",{attrs:{disabled:!i.hasChildren,tooltip:t.$t("open"),icon:"angle-right"},on:{click:function(e){return e.stopPropagation(),t.go(i)}}}):t._e()]}}])},"k-collection",t.collection,!1))]],2)}),[],!1,ke,null,null,null);function ke(t){for(let e in me)this[e]=me[e]}var ve=function(){return ge.exports}();const be={mixins:[Kt],props:{icon:{type:String,default:"trash"},submitButton:{type:[String,Boolean],default:()=>window.panel.$t("delete")},text:String,theme:{type:String,default:"negative"}}},ye={};var $e=Ft(be,(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-text-dialog",t._g(t._b({ref:"dialog"},"k-text-dialog",t.$props,!1),t.$listeners),[t._t("default")],2)}),[],!1,_e,null,null,null);function _e(t){for(let e in ye)this[e]=ye[e]}var xe=function(){return $e.exports}();const we={};var Se=Ft({mixins:[Kt],props:{text:String}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-dialog",t._g(t._b({ref:"dialog"},"k-dialog",t.$props,!1),t.$listeners),[t._t("default",(function(){return[t.text?n("k-text",{domProps:{innerHTML:t._s(t.text)}}):n("k-box",{attrs:{theme:"negative"}},[t._v(" This dialog does not define any text ")])]}))],2)}),[],!1,Ce,null,null,null);function Ce(t){for(let e in we)this[e]=we[e]}var Oe=function(){return Se.exports}();const Ee={};var Ae=Ft({mixins:[ee],computed:{emptyProps(){return{icon:"users",text:this.$t("dialog.users.empty")}}},methods:{item:t=>l(a({},t),{key:t.email,info:t.info!==t.text?t.info:null})}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-dialog",{ref:"dialog",staticClass:"k-users-dialog",attrs:{size:"medium"},on:{cancel:function(e){return t.$emit("cancel")},submit:t.submit}},[t.issue?[n("k-box",{attrs:{text:t.issue,theme:"negative"}})]:[t.options.search?n("k-input",{staticClass:"k-dialog-search",attrs:{autofocus:!0,placeholder:t.$t("search")+" …",type:"text",icon:"search"},model:{value:t.search,callback:function(e){t.search=e},expression:"search"}}):t._e(),n("k-collection",t._b({on:{item:t.toggle,paginate:t.paginate},scopedSlots:t._u([{key:"options",fn:function(e){var i=e.item;return[n("k-button",t._b({on:{click:function(e){return t.toggle(i)}}},"k-button",t.toggleBtn(i),!1))]}}])},"k-collection",t.collection,!1))]],2)}),[],!1,Te,null,null,null);function Te(t){for(let e in Ee)this[e]=Ee[e]}var Ie=function(){return Ae.exports}();const Me={};var Le=Ft({inheritAttrs:!1,props:{id:String,icon:String,tab:String,tabs:Object,title:String},data:()=>({click:!1}),computed:{breadcrumb(){return this.$store.state.drawers.open},hasTabs(){return this.tabs&&Object.keys(this.tabs).length>1},index(){return this.breadcrumb.findIndex((t=>t.id===this._uid))},nested(){return this.index>0}},watch:{index(){-1===this.index&&this.close()}},destroyed(){this.$store.dispatch("drawers/close",this._uid)},methods:{close(){this.$refs.overlay.close()},goTo(t){if(t===this._uid)return!0;this.$store.dispatch("drawers/goto",t)},mouseup(){!0===this.click&&this.close(),this.click=!1},mousedown(t=!1){this.click=t,!0===this.click&&this.$store.dispatch("drawers/close")},onClose(){this.$store.dispatch("drawers/close",this._uid),this.$emit("close")},onOpen(){this.$store.dispatch("drawers/open",{id:this._uid,icon:this.icon,title:this.title}),this.$emit("open")},open(){this.$refs.overlay.open()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-overlay",{ref:"overlay",attrs:{dimmed:!1},on:{close:t.onClose,open:t.onOpen}},[n("div",{staticClass:"k-drawer",attrs:{"data-id":t.id,"data-nested":t.nested},on:{mousedown:function(e){return e.stopPropagation(),t.mousedown(!0)},mouseup:t.mouseup}},[n("div",{staticClass:"k-drawer-box",on:{mousedown:function(e){return e.stopPropagation(),t.mousedown(!1)}}},[n("header",{staticClass:"k-drawer-header"},[1===t.breadcrumb.length?n("h2",{staticClass:"k-drawer-title"},[n("k-icon",{attrs:{type:t.icon}}),t._v(" "+t._s(t.title)+" ")],1):n("ul",{staticClass:"k-drawer-breadcrumb"},t._l(t.breadcrumb,(function(e){return n("li",{key:e.id},[n("k-button",{attrs:{icon:e.icon,text:e.title},on:{click:function(n){return t.goTo(e.id)}}})],1)})),0),t.hasTabs?n("nav",{staticClass:"k-drawer-tabs"},t._l(t.tabs,(function(e){return n("k-button",{key:e.name,staticClass:"k-drawer-tab",attrs:{current:t.tab==e.name,text:e.label},on:{click:function(n){return n.stopPropagation(),t.$emit("tab",e.name)}}})})),1):t._e(),n("nav",{staticClass:"k-drawer-options"},[t._t("options"),n("k-button",{staticClass:"k-drawer-option",attrs:{icon:"check"},on:{click:t.close}})],2)]),n("div",{staticClass:"k-drawer-body scroll-y-auto"},[t._t("default")],2)])])])}),[],!1,je,null,null,null);function je(t){for(let e in Me)this[e]=Me[e]}var De=function(){return Le.exports}(),Be=function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-drawer",{ref:"drawer",staticClass:"k-form-drawer",attrs:{id:t.id,icon:t.icon,tabs:t.tabs,tab:t.tab,title:t.title},on:{close:function(e){return t.$emit("close")},open:function(e){return t.$emit("open")},tab:function(e){t.tab=e}},scopedSlots:t._u([{key:"options",fn:function(){return[t._t("options")]},proxy:!0},{key:"default",fn:function(){return[0===Object.keys(t.fields).length?n("k-box",{attrs:{theme:"info"}},[t._v(" "+t._s(t.empty)+" ")]):n("k-form",{ref:"form",attrs:{autofocus:!0,fields:t.fields,value:t.$helper.clone(t.value)},on:{input:function(e){return t.$emit("input",e)}}})]},proxy:!0}],null,!0)})};const Pe={};var Ne=Ft({inheritAttrs:!1,props:{empty:{type:String,default:()=>"Missing field setup"},icon:String,id:String,tabs:Object,title:String,type:String,value:Object},data:()=>({tab:null}),computed:{fields(){const t=this.tab||null;return(this.tabs[t]||this.firstTab).fields||{}},firstTab(){return Object.values(this.tabs)[0]}},methods:{close(){this.$refs.drawer.close()},focus(t){var e;"function"==typeof(null==(e=this.$refs.form)?void 0:e.focus)&&this.$refs.form.focus(t)},open(t,e=!0){this.$refs.drawer.open(),this.tab=t||this.firstTab.name,!1!==e&&setTimeout((()=>{let t=Object.values(this.fields).filter((t=>!0===t.autofocus))[0]||null;this.focus(t)}),1)}}},Be,[],!1,qe,null,null,null);function qe(t){for(let e in Pe)this[e]=Pe[e]}var Fe=function(){return Ne.exports}();const Re={props:{html:{type:Boolean,default:!1},limit:{type:Number,default:10},skip:{type:Array,default:()=>[]},options:Array,query:String},data:()=>({matches:[],selected:{text:null}}),methods:{close(){this.$refs.dropdown.close()},onSelect(t){this.$emit("select",t),this.$refs.dropdown.close()},search(t){if(t.length<1)return;const e=new RegExp(RegExp.escape(t),"ig");this.matches=this.options.filter((t=>!!t.text&&(-1===this.skip.indexOf(t.value)&&null!==t.text.match(e)))).slice(0,this.limit),this.$emit("search",t,this.matches),this.$refs.dropdown.open()}}},ze={};var Ye=Ft(Re,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-dropdown",{staticClass:"k-autocomplete"},[t._t("default"),n("k-dropdown-content",t._g({ref:"dropdown",attrs:{autofocus:!0}},t.$listeners),t._l(t.matches,(function(e,i){return n("k-dropdown-item",t._b({key:i,on:{mousedown:function(n){return t.onSelect(e)},keydown:[function(n){return!n.type.indexOf("key")&&t._k(n.keyCode,"tab",9,n.key,"Tab")?null:(n.preventDefault(),t.onSelect(e))},function(n){return!n.type.indexOf("key")&&t._k(n.keyCode,"enter",13,n.key,"Enter")?null:(n.preventDefault(),t.onSelect(e))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"left",37,e.key,["Left","ArrowLeft"])||"button"in e&&0!==e.button?null:(e.preventDefault(),t.close.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"backspace",void 0,e.key,void 0)?null:(e.preventDefault(),t.close.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"delete",[8,46],e.key,["Backspace","Delete","Del"])?null:(e.preventDefault(),t.close.apply(null,arguments))}]}},"k-dropdown-item",e,!1),[n("span",{domProps:{innerHTML:t._s(t.html?e.text:t.$esc(e.text))}})])})),1),t._v(" "+t._s(t.query)+" ")],2)}),[],!1,He,null,null,null);function He(t){for(let e in ze)this[e]=ze[e]}var Ue=function(){return Ye.exports}();const Ke={props:{disabled:Boolean,max:String,min:String,value:String},data(){return this.data(this.value)},computed:{numberOfDays(){return this.toDate().daysInMonth()},firstWeekday(){const t=this.toDate().day();return t>0?t:7},weekdays(){return["mon","tue","wed","thu","fri","sat","sun"].map((t=>this.$t("days."+t)))},weeks(){const t=this.firstWeekday-1;return Math.ceil((this.numberOfDays+t)/7)},monthnames(){return["january","february","march","april","may","june","july","august","september","october","november","december"].map((t=>this.$t("months."+t)))},months(){var t=[];return this.monthnames.forEach(((e,n)=>{const i=this.toDate(1,n);t.push({value:n,text:e,disabled:i.isBefore(this.current.min,"month")||i.isAfter(this.current.max,"month")})})),t},years(){var t,e,n,i;const s=null!=(e=null==(t=this.current.min)?void 0:t.get("year"))?e:this.current.year-20,o=null!=(i=null==(n=this.current.max)?void 0:n.get("year"))?i:this.current.year+20;return this.toOptions(s,o)}},watch:{value(t){const e=this.data(t);this.dt=e.dt,this.current=e.current}},methods:{data(t){const e=this.$library.dayjs.iso(t),n=this.$library.dayjs();return{dt:e,current:{month:(null!=e?e:n).month(),year:(null!=e?e:n).year(),min:this.$library.dayjs.iso(this.min),max:this.$library.dayjs.iso(this.max)}}},days(t){let e=[];const n=7*(t-1)+1,i=n+7;for(let s=n;sthis.numberOfDays;e.push(n?"":t)}return e},isDisabled(t){const e=this.toDate(t);return this.disabled||e.isBefore(this.current.min,"day")||e.isAfter(this.current.max,"day")},isSelected(t){return this.toDate(t).isSame(this.dt,"day")},isToday(t){const e=this.$library.dayjs();return this.toDate(t).isSame(e,"day")},onInput(){var t;this.$emit("input",(null==(t=this.dt)?void 0:t.toISO("date"))||null)},onNext(){const t=this.toDate().add(1,"month");this.show(t)},onPrev(){const t=this.toDate().subtract(1,"month");this.show(t)},select(t){const e="today"===t?this.$library.dayjs().merge(this.toDate(),"time"):this.toDate(t);this.dt=e,this.show(e),this.onInput()},show(t){this.current.year=t.year(),this.current.month=t.month()},toDate(t=1,e=this.current.month){return this.$library.dayjs(`${this.current.year}-${e+1}-${t}`)},toOptions(t,e){for(var n=[],i=t;i<=e;i++)n.push({value:i,text:this.$helper.pad(i)});return n}}},Je={};var Ge=Ft(Ke,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-calendar-input"},[n("nav",[n("k-button",{attrs:{icon:"angle-left"},on:{click:t.onPrev}}),n("span",{staticClass:"k-calendar-selects"},[n("k-select-input",{attrs:{options:t.months,disabled:t.disabled,required:!0},model:{value:t.current.month,callback:function(e){t.$set(t.current,"month",t._n(e))},expression:"current.month"}}),n("k-select-input",{attrs:{options:t.years,disabled:t.disabled,required:!0},model:{value:t.current.year,callback:function(e){t.$set(t.current,"year",t._n(e))},expression:"current.year"}})],1),n("k-button",{attrs:{icon:"angle-right"},on:{click:t.onNext}})],1),n("table",{staticClass:"k-calendar-table"},[n("thead",[n("tr",t._l(t.weekdays,(function(e){return n("th",{key:"weekday_"+e},[t._v(" "+t._s(e)+" ")])})),0)]),n("tbody",t._l(t.weeks,(function(e){return n("tr",{key:"week_"+e},t._l(t.days(e),(function(e,i){return n("td",{key:"day_"+i,staticClass:"k-calendar-day",attrs:{"aria-current":!!t.isToday(e)&&"date","aria-selected":!!t.isSelected(e)&&"date"}},[e?n("k-button",{attrs:{disabled:t.isDisabled(e),text:e},on:{click:function(n){return t.select(e)}}}):t._e()],1)})),0)})),0),n("tfoot",[n("tr",[n("td",{staticClass:"k-calendar-today",attrs:{colspan:"7"}},[n("k-button",{attrs:{text:t.$t("today")},on:{click:function(e){return t.select("today")}}})],1)])])])])}),[],!1,Ve,null,null,null);function Ve(t){for(let e in Je)this[e]=Je[e]}var We=function(){return Ge.exports}();const Xe={props:{count:Number,min:Number,max:Number,required:{type:Boolean,default:!1}},computed:{valid(){return!1===this.required&&0===this.count||(!0!==this.required||0!==this.count)&&(!(this.min&&this.countthis.max))}}},Ze={};var Qe=Ft(Xe,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("span",{staticClass:"k-counter",attrs:{"data-invalid":!t.valid}},[n("span",[t._v(t._s(t.count))]),t.min&&t.max?n("span",{staticClass:"k-counter-rules"},[t._v("("+t._s(t.min)+"–"+t._s(t.max)+")")]):t.min?n("span",{staticClass:"k-counter-rules"},[t._v("≥ "+t._s(t.min))]):t.max?n("span",{staticClass:"k-counter-rules"},[t._v("≤ "+t._s(t.max))]):t._e()])}),[],!1,tn,null,null,null);function tn(t){for(let e in Ze)this[e]=Ze[e]}var en=function(){return Qe.exports}();const nn={props:{disabled:Boolean,config:Object,fields:{type:[Array,Object],default:()=>({})},novalidate:{type:Boolean,default:!1},value:{type:Object,default:()=>({})}},data(){return{errors:{},listeners:l(a({},this.$listeners),{submit:this.onSubmit})}},methods:{focus(t){var e,n;null==(n=null==(e=this.$refs.fields)?void 0:e.focus)||n.call(e,t)},onSubmit(){this.$emit("submit",this.value)},submit(){this.$refs.submitter.click()}}},sn={};var on=Ft(nn,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("form",{ref:"form",staticClass:"k-form",attrs:{method:"POST",autocomplete:"off",novalidate:""},on:{submit:function(e){return e.preventDefault(),t.onSubmit.apply(null,arguments)}}},[t._t("header"),t._t("default",(function(){return[n("k-fieldset",t._g({ref:"fields",attrs:{disabled:t.disabled,fields:t.fields,novalidate:t.novalidate},model:{value:t.value,callback:function(e){t.value=e},expression:"value"}},t.listeners))]})),t._t("footer"),n("input",{ref:"submitter",staticClass:"k-form-submitter",attrs:{type:"submit"}})],2)}),[],!1,rn,null,null,null);function rn(t){for(let e in sn)this[e]=sn[e]}var an=function(){return on.exports}();const ln={props:{lock:[Boolean,Object]},data:()=>({isRefreshing:null,isLocking:null}),computed:{hasChanges(){return this.$store.getters["content/hasChanges"]()},isDisabled(){return!1===this.$store.state.content.status.enabled},isLocked(){return"lock"===this.lockState},isUnlocked(){return"unlock"===this.lockState},mode(){return null!==this.lockState?this.lockState:!0===this.hasChanges?"changes":null},lockState(){return this.supportsLocking&&this.lock?this.lock.state:null},supportsLocking(){return!1!==this.lock},theme(){return"lock"===this.mode?"negative":"unlock"===this.mode?"info":"notice"}},watch:{hasChanges:{handler(t,e){!0===this.supportsLocking&&!1===this.isLocked&&!1===this.isUnlocked&&(!0===t?(this.onLock(),this.isLocking=setInterval(this.onLock,3e4)):e&&(clearInterval(this.isLocking),this.onLock(!1)))},immediate:!0},isLocked(t){!1===t&&this.$events.$emit("model.reload")}},created(){this.supportsLocking&&(this.isRefreshing=setInterval(this.check,1e4)),this.$events.$on("keydown.cmd.s",this.onSave)},destroyed(){clearInterval(this.isRefreshing),clearInterval(this.isLocking),this.$events.$off("keydown.cmd.s",this.onSave)},methods:{check(){this.$reload({navigate:!1,only:"$view.props.lock",silent:!0})},async onLock(t=!0){const e=[this.$view.path+"/lock",null,null,!0];if(!0===t)try{await this.$api.patch(...e)}catch(n){clearInterval(this.isLocking),this.$store.dispatch("content/revert")}else clearInterval(this.isLocking),await this.$api.delete(...e)},onDownload(){let t="";const e=this.$store.getters["content/changes"]();Object.keys(e).forEach((n=>{t+=n+": \n\n"+e[n],t+="\n\n----\n\n"}));let n=document.createElement("a");n.setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(t)),n.setAttribute("download",this.$view.path+".txt"),n.style.display="none",document.body.appendChild(n),n.click(),document.body.removeChild(n)},async onResolve(){await this.onUnlock(!1),this.$store.dispatch("content/revert")},onRevert(){this.$refs.revert.open()},async onSave(t){if(!t)return!1;t.preventDefault&&t.preventDefault();try{await this.$store.dispatch("content/save"),this.$events.$emit("model.update"),this.$store.dispatch("notification/success",":)")}catch(e){if(403===e.code)return;e.details&&Object.keys(e.details).length>0?this.$store.dispatch("notification/error",{message:this.$t("error.form.incomplete"),details:e.details}):this.$store.dispatch("notification/error",{message:this.$t("error.form.notSaved"),details:[{label:"Exception: "+e.exception,message:e.message}]})}},async onUnlock(t=!0){const e=[this.$view.path+"/unlock",null,null,!0];!0===t?await this.$api.patch(...e):await this.$api.delete(...e),this.$reload({silent:!0})},revert(){this.$store.dispatch("content/revert"),this.$refs.revert.close()}}},un={};var cn=Ft(ln,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("nav",{staticClass:"k-form-buttons",attrs:{"data-theme":t.theme}},["unlock"===t.mode?n("k-view",[n("p",{staticClass:"k-form-lock-info"},[t._v(" "+t._s(t.$t("lock.isUnlocked"))+" ")]),n("span",{staticClass:"k-form-lock-buttons"},[n("k-button",{staticClass:"k-form-button",attrs:{text:t.$t("download"),icon:"download"},on:{click:t.onDownload}}),n("k-button",{staticClass:"k-form-button",attrs:{text:t.$t("confirm"),icon:"check"},on:{click:t.onResolve}})],1)]):"lock"===t.mode?n("k-view",[n("p",{staticClass:"k-form-lock-info"},[n("k-icon",{attrs:{type:"lock"}}),n("span",{domProps:{innerHTML:t._s(t.$t("lock.isLocked",{email:t.$esc(t.lock.data.email)}))}})],1),t.lock.data.unlockable?n("k-button",{staticClass:"k-form-button",attrs:{text:t.$t("lock.unlock"),icon:"unlock"},on:{click:function(e){return t.onUnlock()}}}):n("k-icon",{staticClass:"k-form-lock-loader",attrs:{type:"loader"}})],1):"changes"===t.mode?n("k-view",[n("k-button",{staticClass:"k-form-button",attrs:{disabled:t.isDisabled,text:t.$t("revert"),icon:"undo"},on:{click:t.onRevert}}),n("k-button",{staticClass:"k-form-button",attrs:{disabled:t.isDisabled,text:t.$t("save"),icon:"check"},on:{click:t.onSave}})],1):t._e(),n("k-dialog",{ref:"revert",attrs:{"submit-button":t.$t("revert"),icon:"undo",theme:"negative"},on:{submit:t.revert}},[n("k-text",{domProps:{innerHTML:t._s(t.$t("revert.confirm"))}})],1)],1)}),[],!1,dn,null,null,null);function dn(t){for(let e in un)this[e]=un[e]}var pn=function(){return cn.exports}();const hn={};var fn=Ft({data:()=>({isOpen:!1,options:[]}),computed:{hasChanges(){return this.ids.length>0},ids(){return Object.keys(this.store).filter((t=>{var e;return Object.keys((null==(e=this.store[t])?void 0:e.changes)||{}).length>0}))},store(){return this.$store.state.content.models}},methods:{async toggle(){if(!1===this.$refs.list.isOpen)try{await this.$dropdown("changes",{method:"POST",body:{ids:this.ids}})((t=>{this.options=t}))}catch(t){return this.$store.dispatch("notification/success",this.$t("lock.unsaved.empty")),this.$store.dispatch("content/clear"),!1}this.$refs.list&&this.$refs.list.toggle()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return t.hasChanges?n("k-dropdown",{staticClass:"k-form-indicator"},[n("k-button",{staticClass:"k-form-indicator-toggle k-topbar-button",attrs:{icon:"edit"},on:{click:t.toggle}}),n("k-dropdown-content",{ref:"list",attrs:{align:"right",theme:"light"}},[n("p",{staticClass:"k-form-indicator-info"},[t._v(t._s(t.$t("lock.unsaved"))+":")]),n("hr"),t._l(t.options,(function(e){return n("k-dropdown-item",t._b({key:e.id},"k-dropdown-item",e,!1),[t._v(" "+t._s(e.text)+" ")])}))],2)],1):t._e()}),[],!1,mn,null,null,null);function mn(t){for(let e in hn)this[e]=hn[e]}var gn=function(){return fn.exports}(),kn={props:{after:String}},vn={props:{autofocus:Boolean}},bn={props:{before:String}},yn={props:{disabled:Boolean}},$n={props:{help:String}},_n={props:{id:{type:[Number,String],default(){return this._uid}}}},xn={props:{invalid:Boolean}},wn={props:{label:String}},Sn={props:{name:[Number,String]}},Cn={props:{required:Boolean}};const On={mixins:[yn,$n,wn,Sn,Cn],props:{counter:[Boolean,Object],endpoints:Object,input:[String,Number],translate:Boolean,type:String}},En={};var An=Ft({mixins:[On],inheritAttrs:!1,computed:{labelText(){return this.label||" "}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{class:"k-field k-field-name-"+t.name,attrs:{"data-disabled":t.disabled,"data-translate":t.translate},on:{focusin:function(e){return t.$emit("focus",e)},focusout:function(e){return t.$emit("blur",e)}}},[t._t("header",(function(){return[n("header",{staticClass:"k-field-header"},[t._t("label",(function(){return[n("label",{staticClass:"k-field-label",attrs:{for:t.input}},[t._v(" "+t._s(t.labelText)+" "),t.required?n("abbr",{attrs:{title:t.$t("field.required")}},[t._v("*")]):t._e()])]})),t._t("options"),t._t("counter",(function(){return[t.counter?n("k-counter",t._b({staticClass:"k-field-counter",attrs:{required:t.required}},"k-counter",t.counter,!1)):t._e()]}))],2)]})),t._t("default"),t._t("footer",(function(){return[t.help||t.$slots.help?n("footer",{staticClass:"k-field-footer"},[t._t("help",(function(){return[t.help?n("k-text",{staticClass:"k-field-help",attrs:{theme:"help"},domProps:{innerHTML:t._s(t.help)}}):t._e()]}))],2):t._e()]}))],2)}),[],!1,Tn,null,null,null);function Tn(t){for(let e in En)this[e]=En[e]}var In=function(){return An.exports}();const Mn={props:{config:Object,disabled:Boolean,fields:{type:[Array,Object],default:()=>[]},novalidate:{type:Boolean,default:!1},value:{type:Object,default:()=>({})}},data:()=>({errors:{}}),methods:{focus(t){if(t)return void(this.hasField(t)&&"function"==typeof this.$refs[t][0].focus&&this.$refs[t][0].focus());const e=Object.keys(this.$refs)[0];this.focus(e)},hasFieldType(t){return this.$helper.isComponent(`k-${t}-field`)},hasField(t){var e;return null==(e=this.$refs[t])?void 0:e[0]},meetsCondition(t){if(!t.when)return!0;let e=!0;return Object.keys(t.when).forEach((n=>{this.value[n.toLowerCase()]!==t.when[n]&&(e=!1)})),e},onInvalid(t,e,n,i){this.errors[i]=e,this.$emit("invalid",this.errors)},hasErrors(){return Object.keys(this.errors).length}}},Ln={};var jn=Ft(Mn,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("fieldset",{staticClass:"k-fieldset"},[n("k-grid",[t._l(t.fields,(function(e,i){return["hidden"!==e.type&&t.meetsCondition(e)?n("k-column",{key:e.signature,attrs:{width:e.width}},[n("k-error-boundary",[t.hasFieldType(e.type)?n("k-"+e.type+"-field",t._b({ref:i,refInFor:!0,tag:"component",attrs:{"form-data":t.value,name:i,novalidate:t.novalidate,disabled:t.disabled||e.disabled},on:{input:function(n){return t.$emit("input",t.value,e,i)},focus:function(n){return t.$emit("focus",n,e,i)},invalid:function(n,s){return t.onInvalid(n,s,e,i)},submit:function(n){return t.$emit("submit",n,e,i)}},model:{value:t.value[i],callback:function(e){t.$set(t.value,i,e)},expression:"value[fieldName]"}},"component",e,!1)):n("k-box",{attrs:{theme:"negative"}},[n("k-text",{attrs:{size:"small"}},[t._v(" The field type "),n("strong",[t._v('"'+t._s(i)+'"')]),t._v(" does not exist ")])],1)],1)],1):t._e()]}))],2)],1)}),[],!1,Dn,null,null,null);function Dn(t){for(let e in Ln)this[e]=Ln[e]}var Bn=function(){return jn.exports}();const Pn={mixins:[kn,bn,yn,xn],props:{autofocus:Boolean,type:String,icon:[String,Boolean],theme:String,novalidate:{type:Boolean,default:!1},value:{type:[String,Boolean,Number,Object,Array],default:null}}},Nn={};var qn=Ft({mixins:[Pn],inheritAttrs:!1,data(){return{isInvalid:this.invalid,listeners:l(a({},this.$listeners),{invalid:(t,e)=>{this.isInvalid=t,this.$emit("invalid",t,e)}})}},computed:{inputProps(){return a(a({},this.$props),this.$attrs)}},methods:{blur(t){(null==t?void 0:t.relatedTarget)&&!1===this.$el.contains(t.relatedTarget)&&this.trigger(null,"blur")},focus(t){this.trigger(t,"focus")},select(t){this.trigger(t,"select")},trigger(t,e){var n,i,s;if("INPUT"===(null==(n=null==t?void 0:t.target)?void 0:n.tagName)&&"function"==typeof(null==(i=null==t?void 0:t.target)?void 0:i[e]))return void t.target[e]();if("function"==typeof(null==(s=this.$refs.input)?void 0:s[e]))return void this.$refs.input[e]();const o=this.$el.querySelector("input, select, textarea");"function"==typeof(null==o?void 0:o[e])&&o[e]()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-input",attrs:{"data-disabled":t.disabled,"data-invalid":!t.novalidate&&t.isInvalid,"data-theme":t.theme,"data-type":t.type}},[t.$slots.before||t.before?n("span",{staticClass:"k-input-before",on:{click:t.focus}},[t._t("before",(function(){return[t._v(t._s(t.before))]}))],2):t._e(),n("span",{staticClass:"k-input-element",on:{click:function(e){return e.stopPropagation(),t.focus.apply(null,arguments)}}},[t._t("default",(function(){return[n("k-"+t.type+"-input",t._g(t._b({ref:"input",tag:"component",attrs:{value:t.value}},"component",t.inputProps,!1),t.listeners))]}))],2),t.$slots.after||t.after?n("span",{staticClass:"k-input-after",on:{click:t.focus}},[t._t("after",(function(){return[t._v(t._s(t.after))]}))],2):t._e(),t.$slots.icon||t.icon?n("span",{staticClass:"k-input-icon",on:{click:t.focus}},[t._t("icon",(function(){return[n("k-icon",{attrs:{type:t.icon}})]}))],2):t._e()])}),[],!1,Fn,null,null,null);function Fn(t){for(let e in Nn)this[e]=Nn[e]}var Rn=function(){return qn.exports}();const zn={};var Yn=Ft({props:{methods:Array},data:()=>({currentForm:null,isLoading:!1,issue:"",user:{email:"",password:"",remember:!1}}),computed:{canToggle(){return null!==this.codeMode&&!0===this.methods.includes("password")&&(!0===this.methods.includes("password-reset")||!0===this.methods.includes("code"))},codeMode(){return!0===this.methods.includes("password-reset")?"password-reset":!0===this.methods.includes("code")?"code":null},fields(){let t={email:{autofocus:!0,label:this.$t("email"),type:"email",required:!0,link:!1}};return"email-password"===this.form&&(t.password={label:this.$t("password"),type:"password",minLength:8,required:!0,autocomplete:"current-password",counter:!1}),t},form(){return this.currentForm?this.currentForm:"password"===this.methods[0]?"email-password":"email"},isResetForm(){return"password-reset"===this.codeMode&&"email"===this.form},toggleText(){return this.$t("login.toggleText."+this.codeMode+"."+this.formOpposite(this.form))}},methods:{formOpposite:t=>"email-password"===t?"email":"email-password",async login(){this.issue=null,this.isLoading=!0;let t=Object.assign({},this.user);"email"===this.currentForm&&(t.password=null),!0===this.isResetForm&&(t.remember=!1);try{await this.$api.auth.login(t),this.$reload({globals:["$system","$translation"]})}catch(e){this.issue=e.message}finally{this.isLoading=!1}},toggleForm(){this.currentForm=this.formOpposite(this.form),this.$refs.fieldset.focus("email")}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("form",{staticClass:"k-login-form",on:{submit:function(e){return e.preventDefault(),t.login.apply(null,arguments)}}},[n("h1",{staticClass:"sr-only"},[t._v(" "+t._s(t.$t("login"))+" ")]),t.issue?n("k-login-alert",{on:{click:function(e){t.issue=null}}},[t._v(" "+t._s(t.issue)+" ")]):t._e(),n("div",{staticClass:"k-login-fields"},[!0===t.canToggle?n("button",{staticClass:"k-login-toggler",attrs:{type:"button"},on:{click:t.toggleForm}},[t._v(" "+t._s(t.toggleText)+" ")]):t._e(),n("k-fieldset",{ref:"fieldset",attrs:{novalidate:!0,fields:t.fields},model:{value:t.user,callback:function(e){t.user=e},expression:"user"}})],1),n("div",{staticClass:"k-login-buttons"},[!1===t.isResetForm?n("span",{staticClass:"k-login-checkbox"},[n("k-checkbox-input",{attrs:{value:t.user.remember,label:t.$t("login.remember")},on:{input:function(e){t.user.remember=e}}})],1):t._e(),n("k-button",{staticClass:"k-login-button",attrs:{icon:"check",type:"submit"}},[t._v(" "+t._s(t.$t("login"+(t.isResetForm?".reset":"")))+" "),t.isLoading?[t._v(" … ")]:t._e()],2)],1)],1)}),[],!1,Hn,null,null,null);function Hn(t){for(let e in zn)this[e]=zn[e]}var Un=function(){return Yn.exports}();const Kn={};var Jn=Ft({props:{methods:Array,pending:Object},data:()=>({code:"",isLoadingBack:!1,isLoadingLogin:!1,issue:""}),computed:{mode(){return!0===this.methods.includes("password-reset")?"password-reset":"login"}},methods:{async back(){this.isLoadingBack=!0,this.$go("/logout")},async login(){this.issue=null,this.isLoadingLogin=!0;try{await this.$api.auth.verifyCode(this.code),this.$store.dispatch("notification/success",this.$t("welcome")),"password-reset"===this.mode?this.$go("reset-password"):this.$reload()}catch(t){this.issue=t.message}finally{this.isLoadingLogin=!1}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("form",{staticClass:"k-login-form k-login-code-form",on:{submit:function(e){return e.preventDefault(),t.login.apply(null,arguments)}}},[n("h1",{staticClass:"sr-only"},[t._v(" "+t._s(t.$t("login"))+" ")]),t.issue?n("k-login-alert",{on:{click:function(e){t.issue=null}}},[t._v(" "+t._s(t.issue)+" ")]):t._e(),n("k-user-info",{attrs:{user:t.pending.email}}),n("k-text-field",{attrs:{autofocus:!0,counter:!1,help:t.$t("login.code.text."+t.pending.challenge),label:t.$t("login.code.label."+t.mode),novalidate:!0,placeholder:t.$t("login.code.placeholder."+t.pending.challenge),required:!0,autocomplete:"one-time-code",icon:"unlock",name:"code"},model:{value:t.code,callback:function(e){t.code=e},expression:"code"}}),n("div",{staticClass:"k-login-buttons"},[n("k-button",{staticClass:"k-login-button k-login-back-button",attrs:{icon:"angle-left"},on:{click:t.back}},[t._v(" "+t._s(t.$t("back"))+" "),t.isLoadingBack?[t._v(" … ")]:t._e()],2),n("k-button",{staticClass:"k-login-button",attrs:{icon:"check",type:"submit"}},[t._v(" "+t._s(t.$t("login"+("password-reset"===t.mode?".reset":"")))+" "),t.isLoadingLogin?[t._v(" … ")]:t._e()],2)],1)],1)}),[],!1,Gn,null,null,null);function Gn(t){for(let e in Kn)this[e]=Kn[e]}var Vn=function(){return Jn.exports}();const Wn={};var Xn=Ft({props:{display:{type:String,default:"HH:mm"},value:String},computed:{day(){return this.formatTimes([6,7,8,9,10,11,"-",12,13,14,15,16,17])},night(){return this.formatTimes([18,19,20,21,22,23,"-",0,1,2,3,4,5])}},methods:{formatTimes(t){return t.map((t=>{if("-"===t)return t;const e=this.$library.dayjs(t+":00","H:mm");return{display:e.format(this.display),select:e.toISO("time")}}))},select(t){this.$emit("input",t)}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-times"},[n("div",{staticClass:"k-times-slot"},[n("k-icon",{attrs:{type:"sun"}}),n("ul",t._l(t.day,(function(e){return n("li",{key:e.select},["-"===e?n("hr"):n("k-button",{on:{click:function(n){return t.select(e.select)}}},[t._v(t._s(e.display))])],1)})),0)],1),n("div",{staticClass:"k-times-slot"},[n("k-icon",{attrs:{type:"moon"}}),n("ul",t._l(t.night,(function(e){return n("li",{key:e.select},["-"===e?n("hr"):n("k-button",{on:{click:function(n){return t.select(e.select)}}},[t._v(t._s(e.display))])],1)})),0)],1)])}),[],!1,Zn,null,null,null);function Zn(t){for(let e in Wn)this[e]=Wn[e]}var Qn=function(){return Xn.exports}();const ti={props:{accept:{type:String,default:"*"},attributes:{type:Object},max:{type:Number},method:{type:String,default:"POST"},multiple:{type:Boolean,default:!0},url:{type:String}},data(){return{options:this.$props,completed:{},errors:[],files:[],total:0}},computed:{limit(){return!1===this.options.multiple?1:this.options.max}},methods:{open(t){this.params(t),setTimeout((()=>{this.$refs.input.click()}),1)},params(t){this.options=Object.assign({},this.$props,t)},select(t){this.upload(t.target.files)},drop(t,e){this.params(e),this.upload(t)},upload(t){this.$refs.dialog.open(),this.files=[...t],this.completed={},this.errors=[],this.hasErrors=!1,this.limit&&(this.files=this.files.slice(0,this.limit)),this.total=this.files.length,this.files.forEach((t=>{var e,n;this.$helper.upload(t,{url:this.options.url,attributes:this.options.attributes,method:this.options.method,headers:{"X-CSRF":window.panel.$system.csrf},progress:(t,e,n)=>{var i,s;null==(s=null==(i=this.$refs[e.name])?void 0:i[0])||s.set(n)},success:(t,e,n)=>{this.complete(e,n.data)},error:(t,e,n)=>{this.errors.push({file:e,message:n.message}),this.complete(e,n.data)}}),void 0!==(null==(n=null==(e=this.options)?void 0:e.attributes)?void 0:n.sort)&&this.options.attributes.sort++}))},complete(t,e){if(this.completed[t.name]=e,Object.keys(this.completed).length==this.total){if(this.$refs.input.value="",this.errors.length>0)return this.$forceUpdate(),void this.$emit("error",this.files);setTimeout((()=>{this.$refs.dialog.close(),this.$emit("success",this.files,Object.values(this.completed))}),250)}}}},ei={};var ni=Ft(ti,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-upload"},[n("input",{ref:"input",attrs:{accept:t.options.accept,multiple:t.options.multiple,"aria-hidden":"true",type:"file",tabindex:"-1"},on:{change:t.select,click:function(t){t.stopPropagation()}}}),n("k-dialog",{ref:"dialog",staticClass:"k-upload-dialog",attrs:{"cancel-button":!1,"submit-button":!1,size:"medium"},scopedSlots:t._u([{key:"footer",fn:function(){return[t.errors.length>0?[n("k-button-group",{attrs:{buttons:[{icon:"check",text:t.$t("confirm"),click:function(){return t.$refs.dialog.close()}}]}})]:t._e()]},proxy:!0}])},[t.errors.length>0?[n("k-headline",[t._v(t._s(t.$t("upload.errors")))]),n("ul",{staticClass:"k-upload-error-list"},t._l(t.errors,(function(e,i){return n("li",{key:"error-"+i},[n("p",{staticClass:"k-upload-error-filename"},[t._v(" "+t._s(e.file.name)+" ")]),n("p",{staticClass:"k-upload-error-message"},[t._v(" "+t._s(e.message)+" ")])])})),0)]:[n("k-headline",[t._v(t._s(t.$t("upload.progress")))]),n("ul",{staticClass:"k-upload-list"},t._l(t.files,(function(e,i){return n("li",{key:"file-"+i},[n("k-progress",{ref:e.name,refInFor:!0}),n("p",{staticClass:"k-upload-list-filename"},[t._v(" "+t._s(e.name)+" ")]),n("p",[t._v(t._s(t.errors[e.name]))])],1)})),0)]],2)],1)}),[],!1,ii,null,null,null);function ii(t){for(let e in ei)this[e]=ei[e]}var si=function(){return ni.exports}();var oi=t=>({$from:e})=>((t,e)=>{for(let n=t.depth;n>0;n--){const i=t.node(n);if(e(i))return{pos:n>0?t.before(n):0,start:t.start(n),depth:n,node:i}}})(e,t),ri=t=>e=>{if((t=>t instanceof b)(e)){const{node:n,$from:i}=e;if(((t,e)=>Array.isArray(t)&&t.indexOf(e.type)>-1||e.type===t)(t,n))return{node:n,pos:i.pos,depth:i.depth}}},ai=(t,e,n={})=>{const i=ri(e)(t.selection)||oi((t=>t.type===e))(t.selection);return Object.keys(n).length&&i?i.node.hasMarkup(e,a(a({},i.node.attrs),n)):!!i};function li(t=null,e=null){if(!t||!e)return!1;const n=t.parent.childAfter(t.parentOffset);if(!n.node)return!1;const i=n.node.marks.find((t=>t.type===e));if(!i)return!1;let s=t.index(),o=t.start()+n.offset,r=s+1,a=o+n.node.nodeSize;for(;s>0&&i.isInSet(t.parent.child(s-1).marks);)s-=1,o-=t.parent.child(s).nodeSize;for(;r{s=[...s,...t.marks]}));const o=s.find((t=>t.type.name===e.name));return o?o.attrs:{}},getNodeAttrs:function(t,e){const{from:n,to:i}=t.selection;let s=[];t.doc.nodesBetween(n,i,(t=>{s=[...s,t]}));const o=s.reverse().find((t=>t.type.name===e.name));return o?o.attrs:{}},markInputRule:function(t,e,n){return new m(t,((t,i,s,o)=>{const r=n instanceof Function?n(i):n,{tr:a}=t,l=i.length-1;let u=o,c=s;if(i[l]){const n=s+i[0].indexOf(i[l-1]),r=n+i[l-1].length-1,d=n+i[l-1].lastIndexOf(i[l]),p=d+i[l].length,h=function(t,e,n){let i=[];return n.doc.nodesBetween(t,e,((t,e)=>{i=[...i,...t.marks.map((n=>({start:e,end:e+t.nodeSize,mark:n})))]})),i}(s,o,t).filter((t=>{const{excluded:n}=t.mark.type;return n.find((t=>t.name===e.name))})).filter((t=>t.end>n));if(h.length)return!1;pn&&a.delete(n,d),c=n,u=c+i[l].length}return a.addMark(c,u,e.create(r)),a.removeStoredMark(e),a}))},markIsActive:function(t,e){const{from:n,$from:i,to:s,empty:o}=t.selection;return o?!!e.isInSet(t.storedMarks||i.marks()):!!t.doc.rangeHasMark(n,s,e)},markPasteRule:function(t,e,n){const i=(s,o)=>{const r=[];return s.forEach((s=>{var a;if(s.isText){const{text:i,marks:l}=s;let u,c=0;const d=!!l.filter((t=>"link"===t.type.name))[0];for(;!d&&null!==(u=t.exec(i));)if((null==(a=null==o?void 0:o.type)?void 0:a.allowsMarkType(e))&&u[1]){const t=u.index,i=t+u[0].length,o=t+u[0].indexOf(u[1]),a=o+u[1].length,l=n instanceof Function?n(u):n;t>0&&r.push(s.cut(c,t)),r.push(s.cut(o,a).mark(e.create(l).addToSet(s.marks))),c=i}cnew k(i(t.content),t.openStart,t.openEnd)}})},minMax:function(t=0,e=0,n=0){return Math.min(Math.max(parseInt(t,10),e),n)},nodeIsActive:ai,nodeInputRule:function(t,e,n){return new m(t,((t,i,s,o)=>{const r=n instanceof Function?n(i):n,{tr:a}=t;return i[0]&&a.replaceWith(s-1,o,e.create(r)),a}))},pasteRule:function(t,e,n){const i=s=>{const o=[];return s.forEach((s=>{if(s.isText){const{text:i}=s;let r,a=0;do{if(r=t.exec(i),r){const t=r.index,i=t+r[0].length,l=n instanceof Function?n(r[0]):n;t>0&&o.push(s.cut(a,t)),o.push(s.cut(t,i).mark(e.create(l).addToSet(s.marks))),a=i}}while(r);anew k(i(t.content),t.openStart,t.openEnd)}})},removeMark:function(t){return(e,n)=>{const{tr:i,selection:s}=e;let{from:o,to:r}=s;const{$from:a,empty:l}=s;if(l){const e=li(a,t);o=e.from,r=e.to}return i.removeMark(o,r,t),n(i)}},toggleBlockType:function(t,e,n={}){return(i,s,o)=>ai(i,t,n)?y(e)(i,s,o):y(t,n)(i,s,o)},toggleList:function(t,e){return(n,i,s)=>{const{schema:o,selection:r}=n,{$from:a,$to:l}=r,u=a.blockRange(l);if(!u)return!1;const c=oi((t=>ui(t,o)))(r);if(u.depth>=1&&c&&u.depth-c.depth<=1){if(c.node.type===t)return $(e)(n,i,s);if(ui(c.node,o)&&t.validContent(c.node.content)){const{tr:e}=n;return e.setNodeMarkup(c.pos,t),i&&i(e),!1}}return _(t)(n,i,s)}},updateMark:function(t,e){return(n,i)=>{const{tr:s,selection:o,doc:r}=n,{ranges:a,empty:l}=o;if(l){const{from:n,to:i}=li(o.$from,t);r.rangeHasMark(n,i,t)&&s.removeMark(n,i,t),s.addMark(n,i,t.create(e))}else a.forEach((n=>{const{$to:i,$from:o}=n;r.rangeHasMark(o.pos,i.pos,t)&&s.removeMark(o.pos,i.pos,t),s.addMark(o.pos,i.pos,t.create(e))}));return i(s)}}};class di{constructor(t=[],e){t.forEach((t=>{t.bindEditor(e),t.init()})),this.extensions=t}commands({schema:t,view:e}){return this.extensions.filter((t=>t.commands)).reduce(((n,i)=>{const{name:s,type:o}=i,r={},l=i.commands(a({schema:t,utils:ci},["node","mark"].includes(o)?{type:t[`${o}s`][s]}:{})),u=(t,n)=>{r[t]=t=>{if("function"!=typeof n||!e.editable)return!1;e.focus();const i=n(t);return"function"==typeof i?i(e.state,e.dispatch,e):i}};return"object"==typeof l?Object.entries(l).forEach((([t,e])=>{u(t,e)})):u(s,l),a(a({},n),r)}),{})}buttons(t="mark"){const e={};return this.extensions.filter((e=>e.type===t)).filter((t=>t.button)).forEach((t=>{Array.isArray(t.button)?t.button.forEach((t=>{e[t.id||t.name]=t})):e[t.name]=t.button})),e}getAllowedExtensions(t){return t instanceof Array||!t?t instanceof Array?this.extensions.filter((e=>!t.includes(e.name))):this.extensions:[]}getFromExtensions(t,e,n=this.extensions){return n.filter((t=>["extension"].includes(t.type))).filter((e=>e[t])).map((n=>n[t](l(a({},e),{utils:ci}))))}getFromNodesAndMarks(t,e,n=this.extensions){return n.filter((t=>["node","mark"].includes(t.type))).filter((e=>e[t])).map((n=>n[t](l(a({},e),{type:e.schema[`${n.type}s`][n.name],utils:ci}))))}inputRules({schema:t,excludedExtensions:e}){const n=this.getAllowedExtensions(e);return[...this.getFromExtensions("inputRules",{schema:t},n),...this.getFromNodesAndMarks("inputRules",{schema:t},n)].reduce(((t,e)=>[...t,...e]),[])}keymaps({schema:t}){return[...this.getFromExtensions("keys",{schema:t}),...this.getFromNodesAndMarks("keys",{schema:t})].map((t=>I(t)))}get marks(){return this.extensions.filter((t=>"mark"===t.type)).reduce(((t,{name:e,schema:n})=>l(a({},t),{[e]:n})),{})}get nodes(){return this.extensions.filter((t=>"node"===t.type)).reduce(((t,{name:e,schema:n})=>l(a({},t),{[e]:n})),{})}get options(){const{view:t}=this;return this.extensions.reduce(((e,n)=>l(a({},e),{[n.name]:new Proxy(n.options,{set(e,n,i){const s=e[n]!==i;return Object.assign(e,{[n]:i}),s&&t.updateState(t.state),!0}})})),{})}pasteRules({schema:t,excludedExtensions:e}){const n=this.getAllowedExtensions(e);return[...this.getFromExtensions("pasteRules",{schema:t},n),...this.getFromNodesAndMarks("pasteRules",{schema:t},n)].reduce(((t,e)=>[...t,...e]),[])}plugins({schema:t}){return[...this.getFromExtensions("plugins",{schema:t}),...this.getFromNodesAndMarks("plugins",{schema:t})].reduce(((t,e)=>[...t,...e]),[]).map((t=>t instanceof g?t:new g(t)))}}class pi{constructor(t={}){this.options=a(a({},this.defaults),t)}init(){return null}bindEditor(t=null){this.editor=t}get name(){return null}get type(){return"extension"}get defaults(){return{}}plugins(){return[]}inputRules(){return[]}pasteRules(){return[]}keys(){return{}}}class hi extends pi{constructor(t={}){super(t)}get type(){return"node"}get schema(){return null}commands(){return{}}}class fi extends hi{get defaults(){return{inline:!1}}get name(){return"doc"}get schema(){return{content:this.options.inline?"paragraph+":"block+"}}}class mi extends hi{get button(){return{id:this.name,icon:"paragraph",label:window.panel.$t("toolbar.button.paragraph"),name:this.name}}commands({utils:t,type:e}){return{paragraph:()=>t.setBlockType(e)}}get schema(){return{content:"inline*",group:"block",draggable:!1,parseDOM:[{tag:"p"}],toDOM:()=>["p",0]}}get name(){return"paragraph"}}class gi extends hi{get name(){return"text"}get schema(){return{group:"inline"}}}class ki extends class{emit(t,...e){this._callbacks=this._callbacks||{};const n=this._callbacks[t];return n&&n.forEach((t=>t.apply(this,e))),this}off(t,e){if(arguments.length){const n=this._callbacks?this._callbacks[t]:null;n&&(e?this._callbacks[t]=n.filter((t=>t!==e)):delete this._callbacks[t])}else this._callbacks={};return this}on(t,e){return this._callbacks=this._callbacks||{},this._callbacks[t]=this._callbacks[t]||[],this._callbacks[t].push(e),this}}{constructor(t={}){super(),this.defaults={autofocus:!1,content:"",disableInputRules:!1,disablePasteRules:!1,editable:!0,element:null,extensions:[],emptyDocument:{type:"doc",content:[]},events:{},inline:!1,parseOptions:{},topNode:"doc",useBuiltInExtensions:!0},this.init(t)}blur(){this.view.dom.blur()}get builtInExtensions(){return this.options.useBuiltInExtensions?[new fi({inline:this.options.inline}),new gi,new mi]:[]}buttons(t){return this.extensions.buttons(t)}clearContent(t=!1){this.setContent(this.options.emptyDocument,t)}command(t,...e){this.commands[t]&&this.commands[t](...e)}createCommands(){return this.extensions.commands({schema:this.schema,view:this.view})}createDocument(t,e=this.options.parseOptions){if(null===t)return this.schema.nodeFromJSON(this.options.emptyDocument);if("object"==typeof t)try{return this.schema.nodeFromJSON(t)}catch(n){return window.console.warn("Invalid content.","Passed value:",t,"Error:",n),this.schema.nodeFromJSON(this.options.emptyDocument)}if("string"==typeof t){const n=`

${t}
`,i=(new window.DOMParser).parseFromString(n,"text/html").body.firstElementChild;return M.fromSchema(this.schema).parse(i,e)}return!1}createEvents(){const t=this.options.events||{};return Object.entries(t).forEach((([t,e])=>{this.on(t,e)})),t}createExtensions(){return new di([...this.builtInExtensions,...this.options.extensions],this)}createFocusEvents(){const t=(t,e,n)=>{this.focused=n,this.emit(n?"focus":"blur",{event:e,state:t.state,view:t});const i=this.state.tr.setMeta("focused",n);this.view.dispatch(i)};return new g({props:{attributes:{tabindex:0},handleDOMEvents:{focus:(e,n)=>{t(e,n,!0)},blur:(e,n)=>{t(e,n,!1)}}}})}createInputRules(){return this.extensions.inputRules({schema:this.schema,excludedExtensions:this.options.disableInputRules})}createKeymaps(){return this.extensions.keymaps({schema:this.schema})}createMarks(){return this.extensions.marks}createNodes(){return this.extensions.nodes}createPasteRules(){return this.extensions.pasteRules({schema:this.schema,excludedExtensions:this.options.disablePasteRules})}createPlugins(){return this.extensions.plugins({schema:this.schema})}createSchema(){return new L({topNode:this.options.topNode,nodes:this.nodes,marks:this.marks})}createState(){return j.create({schema:this.schema,doc:this.createDocument(this.options.content),plugins:[...this.plugins,D({rules:this.inputRules}),...this.pasteRules,...this.keymaps,I({Backspace:q}),I(F),this.createFocusEvents()]})}createView(){return new B(this.element,{dispatchTransaction:this.dispatchTransaction.bind(this),editable:()=>this.options.editable,handlePaste:(t,e)=>{if("function"==typeof this.events.paste){const t=e.clipboardData.getData("text/html"),n=e.clipboardData.getData("text/plain");if(!0===this.events.paste(e,t,n))return!0}},handleDrop:(...t)=>{this.emit("drop",...t)},state:this.createState()})}destroy(){this.view&&this.view.destroy()}dispatchTransaction(t){const e=this.state,n=this.state.apply(t);this.view.updateState(n),this.selection={from:this.state.selection.from,to:this.state.selection.to},this.setActiveNodesAndMarks();const i={editor:this,getHTML:this.getHTML.bind(this),getJSON:this.getJSON.bind(this),state:this.state,transaction:t};this.emit("transaction",i),!t.docChanged&&t.getMeta("preventUpdate")||this.emit("update",i);const{from:s,to:o}=this.state.selection,r=!e||!e.selection.eq(n.selection);this.emit(n.selection.empty?"deselect":"select",l(a({},i),{from:s,hasChanged:r,to:o}))}focus(t=null){if(this.view.focused&&null===t||!1===t)return;const{from:e,to:n}=this.selectionAtPosition(t);this.setSelection(e,n),setTimeout((()=>this.view.focus()),10)}getHTML(){const t=document.createElement("div"),e=P.fromSchema(this.schema).serializeFragment(this.state.doc.content);return t.appendChild(e),this.options.inline&&t.querySelector("p")?t.querySelector("p").innerHTML:t.innerHTML}getJSON(){return this.state.doc.toJSON()}getMarkAttrs(t=null){return this.activeMarkAttrs[t]}getSchemaJSON(){return JSON.parse(JSON.stringify({nodes:this.nodes,marks:this.marks}))}init(t={}){this.options=a(a({},this.defaults),t),this.element=this.options.element,this.focused=!1,this.selection={from:0,to:0},this.events=this.createEvents(),this.extensions=this.createExtensions(),this.nodes=this.createNodes(),this.marks=this.createMarks(),this.schema=this.createSchema(),this.keymaps=this.createKeymaps(),this.inputRules=this.createInputRules(),this.pasteRules=this.createPasteRules(),this.plugins=this.createPlugins(),this.view=this.createView(),this.commands=this.createCommands(),this.setActiveNodesAndMarks(),!1!==this.options.autofocus&&this.focus(this.options.autofocus),this.emit("init",{view:this.view,state:this.state}),this.extensions.view=this.view,this.setContent(this.options.content,!0)}isEditable(){return this.options.editable}isEmpty(){if(this.state)return 0===this.state.doc.textContent.length}get isActive(){return Object.entries(a(a({},this.activeMarks),this.activeNodes)).reduce(((t,[e,n])=>l(a({},t),{[e]:(t={})=>n(t)})),{})}removeMark(t){if(this.schema.marks[t])return ci.removeMark(this.schema.marks[t])(this.state,this.view.dispatch)}selectionAtPosition(t=null){if(this.selection&&null===t)return this.selection;if("start"===t||!0===t)return{from:0,to:0};if("end"===t){const{doc:t}=this.state;return{from:t.content.size,to:t.content.size}}return{from:t,to:t}}setActiveNodesAndMarks(){this.activeMarks=Object.values(this.schema.marks).filter((t=>ci.markIsActive(this.state,t))).map((t=>t.name)),this.activeMarkAttrs=Object.entries(this.schema.marks).reduce(((t,[e,n])=>l(a({},t),{[e]:ci.getMarkAttrs(this.state,n)})),{}),this.activeNodes=Object.values(this.schema.nodes).filter((t=>ci.nodeIsActive(this.state,t))).map((t=>t.name)),this.activeNodeAttrs=Object.entries(this.schema.nodes).reduce(((t,[e,n])=>l(a({},t),{[e]:ci.getNodeAttrs(this.state,n)})),{})}setContent(t={},e=!1,n){const{doc:i,tr:s}=this.state,o=this.createDocument(t,n),r=N.create(i,0,i.content.size),a=s.setSelection(r).replaceSelectionWith(o,!1).setMeta("preventUpdate",!e);this.view.dispatch(a)}setSelection(t=0,e=0){const{doc:n,tr:i}=this.state,s=ci.minMax(t,0,n.content.size),o=ci.minMax(e,0,n.content.size),r=N.create(n,s,o),a=i.setSelection(r);this.view.dispatch(a)}get state(){return this.view?this.view.state:null}toggleMark(t){if(this.schema.marks[t])return ci.toggleMark(this.schema.marks[t])(this.state,this.view.dispatch)}updateMark(t,e){if(this.schema.marks[t])return ci.updateMark(this.schema.marks[t],e)(this.state,this.view.dispatch)}}const vi={};var bi=Ft({data:()=>({link:{href:null,title:null,target:!1}}),computed:{fields(){return{href:{label:this.$t("url"),type:"text",icon:"url"},title:{label:this.$t("title"),type:"text",icon:"title"},target:{label:this.$t("open.newWindow"),type:"toggle",text:[this.$t("no"),this.$t("yes")]}}}},methods:{open(t){this.link=a({title:null,target:!1},t),this.link.target=Boolean(this.link.target),this.$refs.dialog.open()},submit(){this.$emit("submit",l(a({},this.link),{target:this.link.target?"_blank":null})),this.$refs.dialog.close()}}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-form-dialog",{ref:"dialog",attrs:{fields:t.fields,"submit-button":t.$t("confirm"),size:"medium"},on:{close:function(e){return t.$emit("close")},submit:t.submit},model:{value:t.link,callback:function(e){t.link=e},expression:"link"}})}),[],!1,yi,null,null,null);function yi(t){for(let e in vi)this[e]=vi[e]}var $i=function(){return bi.exports}();const _i={};var xi=Ft({data:()=>({email:{email:null,title:null}}),computed:{fields(){return{href:{label:this.$t("email"),type:"email",icon:"email"},title:{label:this.$t("title"),type:"text",icon:"title"}}}},methods:{open(t){this.email=a({title:null},t),this.$refs.dialog.open()},submit(){this.$emit("submit",this.email),this.$refs.dialog.close()}}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-form-dialog",{ref:"dialog",attrs:{fields:t.fields,"submit-button":t.$t("confirm"),size:"medium"},on:{close:function(e){return t.$emit("close")},submit:t.submit},model:{value:t.email,callback:function(e){t.email=e},expression:"email"}})}),[],!1,wi,null,null,null);function wi(t){for(let e in _i)this[e]=_i[e]}var Si=function(){return xi.exports}();class Ci extends pi{constructor(t={}){super(t)}command(){return()=>{}}remove(){this.editor.removeMark(this.name)}get schema(){return null}get type(){return"mark"}toggle(){return this.editor.toggleMark(this.name)}update(t){this.editor.updateMark(this.name,t)}}class Oi extends Ci{get button(){return{icon:"code",label:window.panel.$t("toolbar.button.code")}}commands(){return()=>this.toggle()}inputRules({type:t,utils:e}){return[e.markInputRule(/(?:`)([^`]+)(?:`)$/,t)]}keys(){return{"Mod-`":()=>this.toggle()}}get name(){return"code"}pasteRules({type:t,utils:e}){return[e.markPasteRule(/(?:`)([^`]+)(?:`)/g,t)]}get schema(){return{excludes:"_",parseDOM:[{tag:"code"}],toDOM:()=>["code",0]}}}class Ei extends Ci{get button(){return{icon:"bold",label:window.panel.$t("toolbar.button.bold")}}commands(){return()=>this.toggle()}inputRules({type:t,utils:e}){return[e.markInputRule(/(?:\*\*|__)([^*_]+)(?:\*\*|__)$/,t)]}keys(){return{"Mod-b":()=>this.toggle()}}get name(){return"bold"}pasteRules({type:t,utils:e}){return[e.markPasteRule(/(?:\*\*|__)([^*_]+)(?:\*\*|__)/g,t)]}get schema(){return{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:t=>"normal"!==t.style.fontWeight&&null},{style:"font-weight",getAttrs:t=>/^(bold(er)?|[5-9]\d{2,})$/.test(t)&&null}],toDOM:()=>["strong",0]}}}class Ai extends Ci{get button(){return{icon:"italic",label:window.panel.$t("toolbar.button.italic")}}commands(){return()=>this.toggle()}inputRules({type:t,utils:e}){return[e.markInputRule(/(?:^|\s)((?:\*)((?:[^*]+))(?:\*))$/,t),e.markInputRule(/(?:^|\s)((?:_)((?:[^_]+))(?:_))$/,t)]}keys(){return{"Mod-i":()=>this.toggle()}}get name(){return"italic"}pasteRules({type:t,utils:e}){return[e.markPasteRule(/_([^_]+)_/g,t),e.markPasteRule(/\*([^*]+)\*/g,t)]}get schema(){return{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"}],toDOM:()=>["em",0]}}}class Ti extends Ci{get button(){return{icon:"url",label:window.panel.$t("toolbar.button.link")}}commands(){return{link:()=>{this.editor.emit("link",this.editor)},insertLink:(t={})=>{if(t.href)return this.update(t)},removeLink:()=>this.remove(),toggleLink:(t={})=>{var e;(null==(e=t.href)?void 0:e.length)>0?this.editor.command("insertLink",t):this.editor.command("removeLink")}}}get defaults(){return{target:null}}get name(){return"link"}pasteRules({type:t,utils:e}){return[e.pasteRule(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b([-a-zA-Z0-9@:%_+.~#?&//=,]*)/gi,t,(t=>({href:t})))]}plugins(){return[{props:{handleClick:(t,e,n)=>{const i=this.editor.getMarkAttrs("link");i.href&&!0===n.altKey&&n.target instanceof HTMLAnchorElement&&(n.stopPropagation(),window.open(i.href,i.target))}}}]}get schema(){return{attrs:{href:{default:null},target:{default:null},title:{default:null}},inclusive:!1,parseDOM:[{tag:"a[href]:not([href^='mailto:'])",getAttrs:t=>({href:t.getAttribute("href"),target:t.getAttribute("target"),title:t.getAttribute("title")})}],toDOM:t=>["a",l(a({},t.attrs),{rel:"noopener noreferrer"}),0]}}}class Ii extends Ci{get button(){return{icon:"email",label:"Email"}}commands(){return{email:()=>{this.editor.emit("email")},insertEmail:(t={})=>{if(t.href)return this.update(t)},removeEmail:()=>this.remove(),toggleEmail:(t={})=>{var e;(null==(e=t.href)?void 0:e.length)>0?this.editor.command("insertEmail",t):this.editor.command("removeEmail")}}}get defaults(){return{target:null}}get name(){return"email"}pasteRules({type:t,utils:e}){return[e.pasteRule(/^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/gi,t,(t=>({href:t})))]}plugins(){return[{props:{handleClick:(t,e,n)=>{const i=this.editor.getMarkAttrs("email");i.href&&!0===n.altKey&&n.target instanceof HTMLAnchorElement&&(n.stopPropagation(),window.open(i.href))}}}]}get schema(){return{attrs:{href:{default:null},title:{default:null}},inclusive:!1,parseDOM:[{tag:"a[href^='mailto:']",getAttrs:t=>({href:t.getAttribute("href").replace("mailto:",""),title:t.getAttribute("title")})}],toDOM:t=>["a",l(a({},t.attrs),{href:"mailto:"+t.attrs.href}),0]}}}class Mi extends Ci{get button(){return{icon:"strikethrough",label:window.panel.$t("toolbar.button.strike")}}commands(){return()=>this.toggle()}inputRules({type:t,utils:e}){return[e.markInputRule(/~([^~]+)~$/,t)]}keys(){return{"Mod-d":()=>this.toggle()}}get name(){return"strike"}pasteRules({type:t,utils:e}){return[e.markPasteRule(/~([^~]+)~/g,t)]}get schema(){return{parseDOM:[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",getAttrs:t=>"line-through"===t}],toDOM:()=>["s",0]}}}class Li extends Ci{get button(){return{icon:"underline",label:window.panel.$t("toolbar.button.underline")}}commands(){return()=>this.toggle()}keys(){return{"Mod-u":()=>this.toggle()}}get name(){return"underline"}get schema(){return{parseDOM:[{tag:"u"},{style:"text-decoration",getAttrs:t=>"underline"===t}],toDOM:()=>["u",0]}}}class ji extends hi{get button(){return{id:this.name,icon:"list-bullet",label:window.panel.$t("toolbar.button.ul"),name:this.name,when:["listItem","bulletList","orderedList"]}}commands({type:t,schema:e,utils:n}){return()=>n.toggleList(t,e.nodes.listItem)}inputRules({type:t,utils:e}){return[e.wrappingInputRule(/^\s*([-+*])\s$/,t)]}keys({type:t,schema:e,utils:n}){return{"Shift-Ctrl-8":n.toggleList(t,e.nodes.listItem)}}get name(){return"bulletList"}get schema(){return{content:"listItem+",group:"block",parseDOM:[{tag:"ul"}],toDOM:()=>["ul",0]}}}class Di extends hi{commands({utils:t,type:e}){return()=>this.createHardBreak(t,e)}createHardBreak(t,e){return t.chainCommands(t.exitCode,((t,n)=>(n(t.tr.replaceSelectionWith(e.create()).scrollIntoView()),!0)))}get defaults(){return{enter:!1,text:!1}}keys({utils:t,type:e}){const n=this.createHardBreak(t,e);let i={"Mod-Enter":n,"Shift-Enter":n};return this.options.enter&&(i.Enter=n),i}get name(){return"hardBreak"}get schema(){return{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM:()=>["br"]}}}class Bi extends hi{get button(){return this.options.levels.map((t=>({id:`h${t}`,command:`h${t}`,icon:`h${t}`,label:window.panel.$t("toolbar.button.heading."+t),attrs:{level:t},name:this.name,when:["heading","paragraph"]})))}commands({type:t,schema:e,utils:n}){let i={toggleHeading:i=>n.toggleBlockType(t,e.nodes.paragraph,i)};return this.options.levels.forEach((s=>{i[`h${s}`]=()=>n.toggleBlockType(t,e.nodes.paragraph,{level:s})})),i}get defaults(){return{levels:[1,2,3,4,5,6]}}inputRules({type:t,utils:e}){return this.options.levels.map((n=>e.textblockTypeInputRule(new RegExp(`^(#{1,${n}})\\s$`),t,(()=>({level:n})))))}keys({type:t,utils:e}){return this.options.levels.reduce(((n,i)=>a(a({},n),{[`Shift-Ctrl-${i}`]:e.setBlockType(t,{level:i})})),{})}get name(){return"heading"}get schema(){return{attrs:{level:{default:1}},content:"inline*",group:"block",defining:!0,draggable:!1,parseDOM:this.options.levels.map((t=>({tag:`h${t}`,attrs:{level:t}}))),toDOM:t=>[`h${t.attrs.level}`,0]}}}class Pi extends hi{commands({type:t}){return()=>(e,n)=>n(e.tr.replaceSelectionWith(t.create()))}inputRules({type:t,utils:e}){return[e.nodeInputRule(/^(?:---|___\s|\*\*\*\s)$/,t)]}get name(){return"horizontalRule"}get schema(){return{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>["hr"]}}}class Ni extends hi{keys({type:t,utils:e}){return{Enter:e.splitListItem(t),"Shift-Tab":e.liftListItem(t),Tab:e.sinkListItem(t)}}get name(){return"listItem"}get schema(){return{content:"paragraph block*",defining:!0,draggable:!1,parseDOM:[{tag:"li"}],toDOM:()=>["li",0]}}}class qi extends hi{get button(){return{id:this.name,icon:"list-numbers",label:window.panel.$t("toolbar.button.ol"),name:this.name,when:["listItem","bulletList","orderedList"]}}commands({type:t,schema:e,utils:n}){return()=>n.toggleList(t,e.nodes.listItem)}inputRules({type:t,utils:e}){return[e.wrappingInputRule(/^(\d+)\.\s$/,t,(t=>({order:+t[1]})),((t,e)=>e.childCount+e.attrs.order===+t[1]))]}keys({type:t,schema:e,utils:n}){return{"Shift-Ctrl-9":n.toggleList(t,e.nodes.listItem)}}get name(){return"orderedList"}get schema(){return{attrs:{order:{default:1}},content:"listItem+",group:"block",parseDOM:[{tag:"ol",getAttrs:t=>({order:t.hasAttribute("start")?+t.getAttribute("start"):1})}],toDOM:t=>1===t.attrs.order?["ol",0]:["ol",{start:t.attrs.order},0]}}}class Fi extends pi{commands(){return{undo:()=>R,redo:()=>z,undoDepth:()=>Y,redoDepth:()=>H}}get defaults(){return{depth:"",newGroupDelay:""}}keys(){return{"Mod-z":R,"Mod-y":z,"Shift-Mod-z":z,"Mod-я":R,"Shift-Mod-я":z}}get name(){return"history"}plugins(){return[U({depth:this.options.depth,newGroupDelay:this.options.newGroupDelay})]}}class Ri extends pi{commands(){return{insertHtml:t=>(e,n)=>{let i=document.createElement("div");i.innerHTML=t.trim();const s=M.fromSchema(e.schema).parse(i);n(e.tr.replaceSelectionWith(s).scrollIntoView())}}}}class zi extends pi{constructor(t={}){super(t)}close(){this.visible=!1,this.emit()}emit(){this.editor.emit("toolbar",{marks:this.marks,nodes:this.nodes,nodeAttrs:this.nodeAttrs,position:this.position,visible:this.visible})}init(){this.position={left:0,bottom:0},this.visible=!1,this.editor.on("blur",(()=>{this.close()})),this.editor.on("deselect",(()=>{this.close()})),this.editor.on("select",(({hasChanged:t})=>{!1!==t?this.open():this.emit()}))}get marks(){return this.editor.activeMarks}get nodes(){return this.editor.activeNodes}get nodeAttrs(){return this.editor.activeNodeAttrs}open(){this.visible=!0,this.reposition(),this.emit()}reposition(){const{from:t,to:e}=this.editor.selection,n=this.editor.view.coordsAtPos(t),i=this.editor.view.coordsAtPos(e,!0),s=this.editor.element.getBoundingClientRect();let o=(n.left+i.left)/2-s.left,r=Math.round(s.bottom-n.top);return this.position={bottom:r,left:o}}get type(){return"toolbar"}}const Yi={props:{activeMarks:{type:Array,default:()=>[]},activeNodes:{type:Array,default:()=>[]},activeNodeAttrs:{type:[Array,Object],default:()=>[]},editor:{type:Object,required:!0},marks:{type:Array},isParagraphNodeHidden:{type:Boolean,default:!1}},computed:{activeButton(){return Object.values(this.nodeButtons).find((t=>this.isButtonActive(t)))||!1},hasVisibleButtons(){const t=Object.keys(this.nodeButtons);return t.length>1||1===t.length&&!1===t.includes("paragraph")},markButtons(){return this.buttons("mark")},nodeButtons(){let t=this.buttons("node");return!0===this.isParagraphNodeHidden&&t.paragraph&&delete t.paragraph,t}},methods:{buttons(t){const e=this.editor.buttons(t);let n=this.sorting;!1!==n&&!1!==Array.isArray(n)||(n=Object.keys(e));let i={};return n.forEach((t=>{e[t]&&(i[t]=e[t])})),i},command(t,...e){this.$emit("command",t,...e)},isButtonActive(t){if("paragraph"===t.name)return 1===this.activeNodes.length&&this.activeNodes.includes(t.name);let e=!0;if(t.attrs){const n=Object.values(this.activeNodeAttrs).find((e=>JSON.stringify(e)===JSON.stringify(t.attrs)));e=Boolean(n||!1)}return!0===e&&this.activeNodes.includes(t.name)},isButtonCurrent(t){return!!this.activeButton&&this.activeButton.id===t.id},isButtonDisabled(t){var e;if(null==(e=this.activeButton)?void 0:e.when){return!1===this.activeButton.when.includes(t.name)}return!1},needDividerAfterNode(t){let e=["paragraph"],n=Object.keys(this.nodeButtons);return(n.includes("bulletList")||n.includes("orderedList"))&&e.push("h6"),e.includes(t.id)}}},Hi={};var Ui=Ft(Yi,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-writer-toolbar"},[t.hasVisibleButtons?n("k-dropdown",{nativeOn:{mousedown:function(t){t.preventDefault()}}},[n("k-button",{class:{"k-writer-toolbar-button k-writer-toolbar-nodes":!0,"k-writer-toolbar-button-active":!!t.activeButton},attrs:{icon:t.activeButton.icon||"title"},on:{click:function(e){return t.$refs.nodes.toggle()}}}),n("k-dropdown-content",{ref:"nodes"},[t._l(t.nodeButtons,(function(e,i){return[n("k-dropdown-item",{key:i,attrs:{current:t.isButtonCurrent(e),disabled:t.isButtonDisabled(e),icon:e.icon},on:{click:function(n){return t.command(e.command||i)}}},[t._v(" "+t._s(e.label)+" ")]),t.needDividerAfterNode(e)?n("hr",{key:i+"-divider"}):t._e()]}))],2)],1):t._e(),t._l(t.markButtons,(function(e,i){return n("k-button",{key:i,class:{"k-writer-toolbar-button":!0,"k-writer-toolbar-button-active":t.activeMarks.includes(i)},attrs:{icon:e.icon,tooltip:e.label},on:{mousedown:function(n){return n.preventDefault(),t.command(e.command||i)}}})}))],2)}),[],!1,Ki,null,null,null);function Ki(t){for(let e in Hi)this[e]=Hi[e]}const Ji={props:{autofocus:Boolean,breaks:Boolean,code:Boolean,disabled:Boolean,emptyDocument:{type:Object,default:()=>({type:"doc",content:[]})},headings:[Array,Boolean],inline:{type:Boolean,default:!1},marks:{type:[Array,Boolean],default:!0},nodes:{type:[Array,Boolean],default:()=>["heading","bulletList","orderedList"]},paste:{type:Function,default:()=>()=>!1},placeholder:String,spellcheck:Boolean,extensions:Array,value:{type:String,default:""}}},Gi={};var Vi=Ft({components:{"k-writer-email-dialog":Si,"k-writer-link-dialog":$i,"k-writer-toolbar":function(){return Ui.exports}()},mixins:[Ji],data(){return{editor:null,json:{},html:this.value,isEmpty:!0,toolbar:!1}},computed:{isParagraphNodeHidden(){return!0===Array.isArray(this.nodes)&&3!==this.nodes.length&&!1===this.nodes.includes("paragraph")}},watch:{value(t,e){t!==e&&t!==this.html&&(this.html=t,this.editor.setContent(this.html))}},mounted(){this.editor=new ki({autofocus:this.autofocus,content:this.value,editable:!this.disabled,element:this.$el,emptyDocument:this.emptyDocument,events:{link:t=>{this.$refs.linkDialog.open(t.getMarkAttrs("link"))},email:()=>{this.$refs.emailDialog.open(this.editor.getMarkAttrs("email"))},paste:this.paste,toolbar:t=>{this.toolbar=t,this.toolbar.visible&&this.$nextTick((()=>{this.onToolbarOpen()}))},update:t=>{if(!this.editor)return;const e=JSON.stringify(this.editor.getJSON());e!==JSON.stringify(this.json)&&(this.json=e,this.isEmpty=t.editor.isEmpty(),this.html=t.editor.getHTML(),this.isEmpty&&(0===t.editor.activeNodes.length||t.editor.activeNodes.includes("paragraph"))&&(this.html=""),this.$emit("input",this.html))}},extensions:[...this.createMarks(),...this.createNodes(),new Fi,new Ri,new zi,...this.extensions||[]],inline:this.inline}),this.isEmpty=this.editor.isEmpty(),this.json=this.editor.getJSON()},beforeDestroy(){this.editor.destroy()},methods:{filterExtensions(t,e,n){!1===e?e=[]:!0!==e&&!1!==Array.isArray(e)||(e=Object.keys(t));let i=[];return e.forEach((e=>{t[e]&&i.push(t[e])})),"function"==typeof n&&(i=n(e,i)),i},command(t,...e){this.editor.command(t,...e)},createMarks(){return this.filterExtensions({bold:new Ei,italic:new Ai,strike:new Mi,underline:new Li,code:new Oi,link:new Ti,email:new Ii},this.marks)},createNodes(){const t=new Di({text:!0,enter:this.inline});return!0===this.inline?[t]:this.filterExtensions({bulletList:new ji,orderedList:new qi,heading:new Bi,horizontalRule:new Pi,listItem:new Ni},this.nodes,((e,n)=>((e.includes("bulletList")||e.includes("orderedList"))&&n.push(new Ni),n.push(t),n)))},getHTML(){return this.editor.getHTML()},focus(){this.editor.focus()},onToolbarOpen(){if(this.$refs.toolbar){const t=this.$el.clientWidth,e=this.$refs.toolbar.$el.clientWidth;let n=this.toolbar.position.left;n-e/2<0&&(n=n+(e/2-n)-20),n+e/2>t&&(n=n-(n+e/2-t)+20),n!==this.toolbar.position.left&&(this.$refs.toolbar.$el.style.left=n+"px")}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{directives:[{name:"direction",rawName:"v-direction"}],ref:"editor",staticClass:"k-writer",attrs:{"data-empty":t.isEmpty,"data-placeholder":t.placeholder,spellcheck:t.spellcheck}},[t.editor?[t.toolbar.visible?n("k-writer-toolbar",{ref:"toolbar",style:{bottom:t.toolbar.position.bottom+"px","inset-inline-start":t.toolbar.position.left+"px"},attrs:{editor:t.editor,"active-marks":t.toolbar.marks,"active-nodes":t.toolbar.nodes,"active-node-attrs":t.toolbar.nodeAttrs,"is-paragraph-node-hidden":t.isParagraphNodeHidden},on:{command:function(e){return t.editor.command(e)}}}):t._e(),n("k-writer-link-dialog",{ref:"linkDialog",on:{close:function(e){return t.editor.focus()},submit:function(e){return t.editor.command("toggleLink",e)}}}),n("k-writer-email-dialog",{ref:"emailDialog",on:{close:function(e){return t.editor.focus()},submit:function(e){return t.editor.command("toggleEmail",e)}}})]:t._e()],2)}),[],!1,Wi,null,null,null);function Wi(t){for(let e in Gi)this[e]=Gi[e]}var Xi=function(){return Vi.exports}();const Zi={};var Qi=Ft({},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-login-alert",on:{click:function(e){return t.$emit("click")}}},[n("span",[t._t("default")],2),n("k-icon",{attrs:{type:"alert"}})],1)}),[],!1,ts,null,null,null);function ts(t){for(let e in Zi)this[e]=Zi[e]}var es=function(){return Qi.exports}();const ns={};var is=Ft({props:{fields:Object,index:[Number,String],total:Number,value:Object},mounted(){this.$store.dispatch("content/disable"),this.$events.$on("keydown.cmd.s",this.onSubmit),this.$events.$on("keydown.esc",this.onDiscard)},destroyed(){this.$events.$off("keydown.cmd.s",this.onSubmit),this.$events.$off("keydown.esc",this.onDiscard),this.$store.dispatch("content/enable")},methods:{focus(t){this.$refs.form.focus(t)},onDiscard(){this.$emit("discard")},onInput(t){this.$emit("input",t)},onSubmit(){this.$emit("submit")}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-structure-form"},[n("div",{staticClass:"k-structure-backdrop",on:{click:t.onDiscard}}),n("section",[n("k-form",{ref:"form",staticClass:"k-structure-form-fields",attrs:{value:t.value,fields:t.fields},on:{input:t.onInput,submit:t.onSubmit}}),n("footer",{staticClass:"k-structure-form-buttons"},[n("k-button",{staticClass:"k-structure-form-cancel-button",attrs:{text:t.$t("cancel"),icon:"cancel"},on:{click:function(e){return t.$emit("close")}}}),"new"!==t.index?n("k-pagination",{attrs:{dropdown:!1,total:t.total,limit:1,page:t.index+1,details:!0},on:{paginate:function(e){return t.$emit("paginate",e)}}}):t._e(),n("k-button",{staticClass:"k-structure-form-submit-button",attrs:{text:t.$t("new"!==t.index?"confirm":"add"),icon:"check"},on:{click:t.onSubmit}})],1)],1)])}),[],!1,ss,null,null,null);function ss(t){for(let e in ns)this[e]=ns[e]}var os=function(){return is.exports}();const rs=function(t){this.command("insert",((e,n)=>{let i=[];return n.split("\n").forEach(((e,n)=>{let s="ol"===t?n+1+".":"-";i.push(s+" "+e)})),i.join("\n")}))},as={layout:["headlines","bold","italic","|","link","email","file","|","code","ul","ol"],props:{buttons:{type:[Boolean,Array],default:!0},uploads:[Boolean,Object,Array]},data(){let t={},e={},n=[],i=this.commands();return!1===this.buttons?t:(Array.isArray(this.buttons)&&(n=this.buttons),!0!==Array.isArray(this.buttons)&&(n=this.$options.layout),n.forEach(((n,s)=>{if("|"===n)t["divider-"+s]={divider:!0};else if(i[n]){let s=i[n];t[n]=s,s.shortcut&&(e[s.shortcut]=n)}})),{layout:t,shortcuts:e})},methods:{command(t,e){"function"==typeof t?t.apply(this):this.$emit("command",t,e)},close(){Object.keys(this.$refs).forEach((t=>{const e=this.$refs[t][0];"function"==typeof(null==e?void 0:e.close)&&e.close()}))},fileCommandSetup(){let t={label:this.$t("toolbar.button.file"),icon:"attachment"};return!1===this.uploads?t.command="selectFile":t.dropdown={select:{label:this.$t("toolbar.button.file.select"),icon:"check",command:"selectFile"},upload:{label:this.$t("toolbar.button.file.upload"),icon:"upload",command:"uploadFile"}},t},commands(){return{headlines:{label:this.$t("toolbar.button.headings"),icon:"title",dropdown:{h1:{label:this.$t("toolbar.button.heading.1"),icon:"title",command:"prepend",args:"#"},h2:{label:this.$t("toolbar.button.heading.2"),icon:"title",command:"prepend",args:"##"},h3:{label:this.$t("toolbar.button.heading.3"),icon:"title",command:"prepend",args:"###"}}},bold:{label:this.$t("toolbar.button.bold"),icon:"bold",command:"wrap",args:"**",shortcut:"b"},italic:{label:this.$t("toolbar.button.italic"),icon:"italic",command:"wrap",args:"*",shortcut:"i"},link:{label:this.$t("toolbar.button.link"),icon:"url",shortcut:"k",command:"dialog",args:"link"},email:{label:this.$t("toolbar.button.email"),icon:"email",shortcut:"e",command:"dialog",args:"email"},file:this.fileCommandSetup(),code:{label:this.$t("toolbar.button.code"),icon:"code",command:"wrap",args:"`"},ul:{label:this.$t("toolbar.button.ul"),icon:"list-bullet",command(){return rs.apply(this,["ul"])}},ol:{label:this.$t("toolbar.button.ol"),icon:"list-numbers",command(){return rs.apply(this,["ol"])}}}},shortcut(t,e){if(this.shortcuts[t]){const n=this.layout[this.shortcuts[t]];if(!n)return!1;e.preventDefault(),this.command(n.command,n.args)}}}},ls={};var us=Ft(as,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("nav",{staticClass:"k-toolbar"},[n("div",{staticClass:"k-toolbar-wrapper"},[n("div",{staticClass:"k-toolbar-buttons"},[t._l(t.layout,(function(e,i){return[e.divider?[n("span",{key:i,staticClass:"k-toolbar-divider"})]:e.dropdown?[n("k-dropdown",{key:i},[n("k-button",{key:i,staticClass:"k-toolbar-button",attrs:{icon:e.icon,tooltip:e.label,tabindex:"-1"},on:{click:function(e){t.$refs[i+"-dropdown"][0].toggle()}}}),n("k-dropdown-content",{ref:i+"-dropdown",refInFor:!0},t._l(e.dropdown,(function(e,i){return n("k-dropdown-item",{key:i,attrs:{icon:e.icon},on:{click:function(n){return t.command(e.command,e.args)}}},[t._v(" "+t._s(e.label)+" ")])})),1)],1)]:[n("k-button",{key:i,staticClass:"k-toolbar-button",attrs:{icon:e.icon,tooltip:e.label,tabindex:"-1"},on:{click:function(n){return t.command(e.command,e.args)}}})]]}))],2)])])}),[],!1,cs,null,null,null);function cs(t){for(let e in ls)this[e]=ls[e]}var ds=function(){return us.exports}();const ps={};var hs=Ft({data(){return{value:{email:null,text:null},fields:{email:{label:this.$t("email"),type:"email"},text:{label:this.$t("link.text"),type:"text"}}}},computed:{kirbytext(){return this.$config.kirbytext}},methods:{open(t,e){this.value.text=e,this.$refs.dialog.open()},cancel(){this.$emit("cancel")},createKirbytext(){var t;const e=this.value.email||"";return(null==(t=this.value.text)?void 0:t.length)>0?`(email: ${e} text: ${this.value.text})`:`(email: ${e})`},createMarkdown(){var t;const e=this.value.email||"";return(null==(t=this.value.text)?void 0:t.length)>0?`[${this.value.text}](mailto:${e})`:`<${e}>`},submit(){this.$emit("submit",this.kirbytext?this.createKirbytext():this.createMarkdown()),this.value={email:null,text:null},this.$refs.dialog.close()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-dialog",{ref:"dialog",attrs:{"submit-button":t.$t("insert")},on:{close:t.cancel,submit:function(e){return t.$refs.form.submit()}}},[n("k-form",{ref:"form",attrs:{fields:t.fields},on:{submit:t.submit},model:{value:t.value,callback:function(e){t.value=e},expression:"value"}})],1)}),[],!1,fs,null,null,null);function fs(t){for(let e in ps)this[e]=ps[e]}var ms=function(){return hs.exports}();const gs={};var ks=Ft({data(){return{value:{url:null,text:null},fields:{url:{label:this.$t("link"),type:"text",placeholder:this.$t("url.placeholder"),icon:"url"},text:{label:this.$t("link.text"),type:"text"}}}},computed:{kirbytext(){return this.$config.kirbytext}},methods:{open(t,e){this.value.text=e,this.$refs.dialog.open()},cancel(){this.$emit("cancel")},createKirbytext(){return this.value.text.length>0?`(link: ${this.value.url} text: ${this.value.text})`:`(link: ${this.value.url})`},createMarkdown(){return this.value.text.length>0?`[${this.value.text}](${this.value.url})`:`<${this.value.url}>`},submit(){this.$emit("submit",this.kirbytext?this.createKirbytext():this.createMarkdown()),this.value={url:null,text:null},this.$refs.dialog.close()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-dialog",{ref:"dialog",attrs:{"submit-button":t.$t("insert")},on:{close:t.cancel,submit:function(e){return t.$refs.form.submit()}}},[n("k-form",{ref:"form",attrs:{fields:t.fields},on:{submit:t.submit},model:{value:t.value,callback:function(e){t.value=e},expression:"value"}})],1)}),[],!1,vs,null,null,null);function vs(t){for(let e in gs)this[e]=gs[e]}var bs=function(){return ks.exports}();const ys={mixins:[vn,yn,_n,wn,Cn],inheritAttrs:!1,props:{value:Boolean},watch:{value(){this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{focus(){this.$refs.input.focus()},onChange(t){this.$emit("input",t)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},select(){this.focus()}},validations(){return{value:{required:!this.required||K.required}}}},$s={};var _s=Ft(ys,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("label",{staticClass:"k-checkbox-input",on:{click:function(t){t.stopPropagation()}}},[n("input",{ref:"input",staticClass:"k-checkbox-input-native input-hidden",attrs:{id:t.id,disabled:t.disabled,type:"checkbox"},domProps:{checked:t.value},on:{change:function(e){return t.onChange(e.target.checked)}}}),n("span",{staticClass:"k-checkbox-input-icon",attrs:{"aria-hidden":"true"}},[n("svg",{attrs:{width:"12",height:"10",viewBox:"0 0 12 10",xmlns:"http://www.w3.org/2000/svg"}},[n("path",{attrs:{d:"M1 5l3.3 3L11 1","stroke-width":"2",fill:"none","fill-rule":"evenodd"}})])]),n("span",{staticClass:"k-checkbox-input-label",domProps:{innerHTML:t._s(t.label)}})])}),[],!1,xs,null,null,null);function xs(t){for(let e in $s)this[e]=$s[e]}var ws=function(){return _s.exports}();const Ss={mixins:[vn,yn,_n,Cn],props:{columns:Number,max:Number,min:Number,options:Array,value:{type:[Array,Object],default:()=>[]}}},Cs={};var Os=Ft({mixins:[Ss],inheritAttrs:!1,data(){return{selected:this.valueToArray(this.value)}},watch:{value(t){this.selected=this.valueToArray(t)},selected(){this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{focus(){this.$el.querySelector("input").focus()},onInput(t,e){if(!0===e)this.selected.push(t);else{const e=this.selected.indexOf(t);-1!==e&&this.selected.splice(e,1)}this.$emit("input",this.selected)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},select(){this.focus()},valueToArray:t=>!0===Array.isArray(t)?t:"string"==typeof t?String(t).split(","):"object"==typeof t?Object.values(t):void 0},validations(){return{selected:{required:!this.required||K.required,min:!this.min||K.minLength(this.min),max:!this.max||K.maxLength(this.max)}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("ul",{staticClass:"k-checkboxes-input",style:"--columns:"+t.columns},t._l(t.options,(function(e,i){return n("li",{key:i},[n("k-checkbox-input",{attrs:{id:t.id+"-"+i,label:e.text,value:-1!==t.selected.indexOf(e.value)},on:{input:function(n){return t.onInput(e.value,n)}}})],1)})),0)}),[],!1,Es,null,null,null);function Es(t){for(let e in Cs)this[e]=Cs[e]}var As=function(){return Os.exports}();const Ts={mixins:[vn,yn,_n,Cn],props:{display:{type:String,default:"DD.MM.YYYY"},max:String,min:String,step:{type:Object,default:()=>({size:1,unit:"day"})},type:{type:String,default:"date"},value:String}},Is={};var Ms=Ft({mixins:[Ts],inheritAttrs:!1,data:()=>({dt:null,formatted:null}),computed:{inputType:()=>"date",pattern(){return this.$library.dayjs.pattern(this.display)},rounding(){return a(a({},this.$options.props.step.default()),this.step)}},watch:{value:{handler(t,e){if(t!==e){const e=this.toDatetime(t);this.commit(e)}},immediate:!0}},created(){this.$events.$on("keydown.cmd.s",this.onBlur)},destroyed(){this.$events.$off("keydown.cmd.s",this.onBlur)},methods:{alter(t){let e=this.parse()||this.round(this.$library.dayjs()),n=this.rounding.unit,i=this.rounding.size;const s=this.selection();null!==s&&("meridiem"===s.unit?(t="pm"===e.format("a")?"subtract":"add",n="hour",i=12):(n=s.unit,n!==this.rounding.unit&&(i=1))),e=e[t](i,n).round(this.rounding.unit,this.rounding.size),this.commit(e),this.emit(e),this.$nextTick((()=>this.select(s)))},commit(t){this.dt=t,this.formatted=this.pattern.format(t),this.$emit("invalid",this.$v.$invalid,this.$v)},emit(t){this.$emit("input",this.toISO(t))},focus(){this.$refs.input.focus()},onArrowDown(){this.alter("subtract")},onArrowUp(){this.alter("add")},onBlur(){const t=this.parse();this.commit(t),this.emit(t)},onEnter(){this.onBlur(),this.$nextTick((()=>this.$emit("submit")))},onInput(t){const e=this.parse(),n=this.pattern.format(e);if(!t||n==t)return this.commit(e),this.emit(e)},onTab(t){""!=this.$refs.input.value&&(this.onBlur(),this.$nextTick((()=>{const e=this.selection();if(this.$refs.input&&e.start===this.$refs.input.selectionStart&&e.end===this.$refs.input.selectionEnd-1)if(t.shiftKey){if(0===e.index)return;this.selectPrev(e.index)}else{if(e.index===this.pattern.parts.length-1)return;this.selectNext(e.index)}else t.shiftKey?this.selectLast():this.selectFirst();t.preventDefault()})))},parse(){let t=this.$refs.input.value;return t=this.$library.dayjs.interpret(t,this.inputType),this.round(t)},round(t){return(null==t?void 0:t.round(this.rounding.unit,this.rounding.size))||null},select(t){var e;t||(t=this.selection()),null==(e=this.$refs.input)||e.setSelectionRange(t.start,t.end+1)},selectFirst(){this.select(this.pattern.parts[0])},selectLast(){this.select(this.pattern.parts[this.pattern.parts.length-1])},selectNext(t){this.select(this.pattern.parts[t+1])},selectPrev(t){this.select(this.pattern.parts[t-1])},selection(){return this.pattern.at(this.$refs.input.selectionStart,this.$refs.input.selectionEnd)},toDatetime(t){return this.round(this.$library.dayjs.iso(t,this.inputType))},toISO(t){return(null==t?void 0:t.toISO(this.inputType))||null}},validations(){return{value:{min:!this.dt||!this.min||(()=>this.dt.validate(this.min,"min",this.rounding.unit)),max:!this.dt||!this.max||(()=>this.dt.validate(this.max,"max",this.rounding.unit)),required:!this.required||(()=>!!this.dt)}}}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("input",{directives:[{name:"model",rawName:"v-model",value:t.formatted,expression:"formatted"},{name:"direction",rawName:"v-direction"}],ref:"input",class:`k-text-input k-${t.type}-input`,attrs:{id:t.id,autofocus:t.autofocus,disabled:t.disabled,placeholder:t.display,required:t.required,autocomplete:"off",spellcheck:"false",type:"text"},domProps:{value:t.formatted},on:{blur:t.onBlur,focus:function(e){return t.$emit("focus")},input:[function(e){e.target.composing||(t.formatted=e.target.value)},function(e){return t.onInput(e.target.value)}],keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"down",40,e.key,["Down","ArrowDown"])?null:(e.stopPropagation(),e.preventDefault(),t.onArrowDown.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"up",38,e.key,["Up","ArrowUp"])?null:(e.stopPropagation(),e.preventDefault(),t.onArrowUp.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"enter",13,e.key,"Enter")?null:(e.stopPropagation(),e.preventDefault(),t.onEnter.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"tab",9,e.key,"Tab")?null:t.onTab.apply(null,arguments)}]}})}),[],!1,Ls,null,null,null);function Ls(t){for(let e in Is)this[e]=Is[e]}var js=function(){return Ms.exports}();const Ds={mixins:[vn,yn,_n,Sn,Cn],props:{autocomplete:{type:[Boolean,String],default:"off"},maxlength:Number,minlength:Number,pattern:String,placeholder:String,preselect:Boolean,spellcheck:{type:[Boolean,String],default:"off"},type:{type:String,default:"text"},value:String}},Bs={};var Ps=Ft({mixins:[Ds],inheritAttrs:!1,data(){return{listeners:l(a({},this.$listeners),{input:t=>this.onInput(t.target.value)})}},watch:{value(){this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus(),this.$props.preselect&&this.select()},methods:{focus(){this.$refs.input.focus()},onInput(t){this.$emit("input",t)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},select(){this.$refs.input.select()}},validations(){return{value:{required:!this.required||K.required,minLength:!this.minlength||K.minLength(this.minlength),maxLength:!this.maxlength||K.maxLength(this.maxlength),email:"email"!==this.type||K.email,url:"url"!==this.type||K.url,pattern:!this.pattern||(t=>!this.required&&!t||!this.$refs.input.validity.patternMismatch)}}}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("input",t._g(t._b({directives:[{name:"direction",rawName:"v-direction"}],ref:"input",staticClass:"k-text-input"},"input",{autocomplete:t.autocomplete,autofocus:t.autofocus,disabled:t.disabled,id:t.id,minlength:t.minlength,name:t.name,pattern:t.pattern,placeholder:t.placeholder,required:t.required,spellcheck:t.spellcheck,type:t.type,value:t.value},!1),t.listeners))}),[],!1,Ns,null,null,null);function Ns(t){for(let e in Bs)this[e]=Bs[e]}var qs=function(){return Ps.exports}();const Fs={mixins:[Ds],props:{autocomplete:{type:String,default:"email"},placeholder:{type:String,default:()=>window.panel.$t("email.placeholder")},type:{type:String,default:"email"}}};const Rs={};var zs=Ft({extends:qs,mixins:[Fs]},undefined,undefined,!1,Ys,null,null,null);function Ys(t){for(let e in Rs)this[e]=Rs[e]}var Hs=function(){return zs.exports}();class Us extends fi{get schema(){return{content:"bulletList|orderedList"}}}const Ks={inheritAttrs:!1,props:{autofocus:Boolean,marks:{type:[Array,Boolean],default:!0},value:String},data(){return{list:this.value,html:this.value}},computed:{extensions:()=>[new Us({inline:!0})]},watch:{value(t){t!==this.html&&(this.list=t,this.html=t)}},methods:{focus(){this.$refs.input.focus()},onInput(t){let e=(new DOMParser).parseFromString(t,"text/html").querySelector("ul, ol");e&&0!==e.textContent.trim().length?(this.list=t,this.html=t.replace(/(

|<\/p>)/gi,""),this.$emit("input",this.html)):this.$emit("input",this.list="")}}},Js={};var Gs=Ft(Ks,(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-writer",t._b({ref:"input",staticClass:"k-list-input",attrs:{extensions:t.extensions,nodes:["bulletList","orderedList"],value:t.list},on:{input:t.onInput}},"k-writer",t.$props,!1))}),[],!1,Vs,null,null,null);function Vs(t){for(let e in Js)this[e]=Js[e]}var Ws=function(){return Gs.exports}();const Xs={mixins:[yn,_n,Cn],props:{max:Number,min:Number,layout:String,options:{type:Array,default:()=>[]},search:[Object,Boolean],separator:{type:String,default:","},sort:Boolean,value:{type:Array,required:!0,default:()=>[]}}},Zs={};var Qs=Ft({mixins:[Xs],inheritAttrs:!1,data(){return{state:this.value,q:null,limit:!0,scrollTop:0}},computed:{draggable(){return this.state.length>1&&!this.sort},dragOptions(){return{disabled:!this.draggable,draggable:".k-tag",delay:1}},emptyLabel(){return this.q?this.$t("search.results.none"):this.$t("options.none")},filtered(){var t;return(null==(t=this.q)?void 0:t.length)>=(this.search.min||0)?this.options.filter((t=>this.isFiltered(t))).map((t=>l(a({},t),{display:this.toHighlightedString(t.text),info:this.toHighlightedString(t.value)}))):this.options.map((t=>l(a({},t),{display:t.text,info:t.value})))},more(){return!this.max||this.state.lengththis.options.findIndex((e=>e.value===t.value));return t.sort(((t,n)=>e(t)-e(n)))},visible(){return this.limit?this.filtered.slice(0,this.search.display||this.filtered.length):this.filtered}},watch:{value(t){this.state=t,this.onInvalid()}},mounted(){this.onInvalid(),this.$events.$on("click",this.close),this.$events.$on("keydown.cmd.s",this.close)},destroyed(){this.$events.$off("click",this.close),this.$events.$off("keydown.cmd.s",this.close)},methods:{add(t){!0===this.more&&(this.state.push(t),this.onInput())},blur(){this.close()},close(){!0===this.$refs.dropdown.isOpen&&(this.$refs.dropdown.close(),this.limit=!0)},escape(){this.q?this.q=null:this.close()},focus(){this.$refs.dropdown.open()},index(t){return this.state.findIndex((e=>e.value===t.value))},isFiltered(t){return String(t.text).match(this.regex)||String(t.value).match(this.regex)},isSelected(t){return-1!==this.index(t)},navigate(t){var e,n,i;"prev"===t&&(t="previous"),null==(i=null==(n=null==(e=document.activeElement)?void 0:e[t+"Sibling"])?void 0:n.focus)||i.call(n)},onClose(){!1===this.$refs.dropdown.isOpen&&(document.activeElement===this.$parent.$el&&(this.q=null),this.$parent.$el.focus())},onInput(){this.$emit("input",this.sorted)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},onOpen(){this.$nextTick((()=>{var t,e;null==(e=null==(t=this.$refs.search)?void 0:t.focus)||e.call(t),this.$refs.dropdown.$el.querySelector(".k-multiselect-options").scrollTop=this.scrollTop}))},remove(t){this.state.splice(this.index(t),1),this.onInput()},select(t){this.scrollTop=this.$refs.dropdown.$el.querySelector(".k-multiselect-options").scrollTop,t={text:t.text,value:t.value},this.isSelected(t)?this.remove(t):this.add(t)},toHighlightedString(t){return(t=this.$helper.string.stripHTML(t)).replace(this.regex,"$1")}},validations(){return{state:{required:!this.required||K.required,minLength:!this.min||K.minLength(this.min),maxLength:!this.max||K.maxLength(this.max)}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-draggable",{staticClass:"k-multiselect-input",attrs:{list:t.state,options:t.dragOptions,"data-layout":t.layout,element:"k-dropdown"},on:{end:t.onInput},nativeOn:{click:function(e){return t.$refs.dropdown.toggle.apply(null,arguments)}},scopedSlots:t._u([{key:"footer",fn:function(){return[n("k-dropdown-content",{ref:"dropdown",on:{open:t.onOpen,close:t.onClose},nativeOn:{keydown:function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"esc",27,e.key,["Esc","Escape"])?null:(e.stopPropagation(),t.close.apply(null,arguments))}}},[t.search?n("k-dropdown-item",{staticClass:"k-multiselect-search",attrs:{icon:"search"}},[n("input",{directives:[{name:"model",rawName:"v-model",value:t.q,expression:"q"}],ref:"search",attrs:{placeholder:t.search.min?t.$t("search.min",{min:t.search.min}):t.$t("search")+" …"},domProps:{value:t.q},on:{keydown:function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"esc",27,e.key,["Esc","Escape"])?null:(e.stopPropagation(),t.escape.apply(null,arguments))},input:function(e){e.target.composing||(t.q=e.target.value)}}})]):t._e(),n("div",{staticClass:"k-multiselect-options scroll-y-auto"},[t._l(t.visible,(function(e){return n("k-dropdown-item",{key:e.value,class:{"k-multiselect-option":!0,selected:t.isSelected(e),disabled:!t.more},attrs:{icon:t.isSelected(e)?"check":"circle-outline"},on:{click:function(n){return n.preventDefault(),t.select(e)}},nativeOn:{keydown:[function(n){return!n.type.indexOf("key")&&t._k(n.keyCode,"enter",13,n.key,"Enter")?null:(n.preventDefault(),n.stopPropagation(),t.select(e))},function(n){return!n.type.indexOf("key")&&t._k(n.keyCode,"space",32,n.key,[" ","Spacebar"])?null:(n.preventDefault(),n.stopPropagation(),t.select(e))}]}},[n("span",{domProps:{innerHTML:t._s(e.display)}}),n("span",{staticClass:"k-multiselect-value",domProps:{innerHTML:t._s(e.info)}})])})),0===t.filtered.length?n("k-dropdown-item",{staticClass:"k-multiselect-option",attrs:{disabled:!0}},[t._v(" "+t._s(t.emptyLabel)+" ")]):t._e()],2),t.visible.lengththis.onInput(t.target.value),blur:this.onBlur})}},watch:{value(t){this.number=t},number:{immediate:!0,handler(){this.onInvalid()}}},mounted(){this.$props.autofocus&&this.focus(),this.$props.preselect&&this.select()},methods:{decimals(){const t=Number(this.step||0);return Math.floor(t)===t?0:-1!==t.toString().indexOf("e")?parseInt(t.toFixed(16).split(".")[1].split("").reverse().join("")).toString().length:t.toString().split(".")[1].length||0},format(t){if(isNaN(t)||""===t)return"";const e=this.decimals();return t=e?parseFloat(t).toFixed(e):Number.isInteger(this.step)?parseInt(t):parseFloat(t)},clean(){this.number=this.format(this.number)},emit(t){t=parseFloat(t),isNaN(t)&&(t=""),t!==this.value&&this.$emit("input",t)},focus(){this.$refs.input.focus()},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},onInput(t){this.number=t,this.emit(t)},onBlur(){this.clean(),this.emit(this.number)},select(){this.$refs.input.select()}},validations(){return{value:{required:!this.required||K.required,min:!this.min||K.minValue(this.min),max:!this.max||K.maxValue(this.max)}}}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("input",t._g(t._b({ref:"input",staticClass:"k-number-input",attrs:{step:t.stepNumber,type:"number"},domProps:{value:t.number},on:{keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"s",void 0,e.key,void 0)?null:e.ctrlKey?t.clean.apply(null,arguments):null},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"s",void 0,e.key,void 0)?null:e.metaKey?t.clean.apply(null,arguments):null}]}},"input",{autofocus:t.autofocus,disabled:t.disabled,id:t.id,max:t.max,min:t.min,name:t.name,placeholder:t.placeholder,required:t.required},!1),t.listeners))}),[],!1,oo,null,null,null);function oo(t){for(let e in io)this[e]=io[e]}var ro=function(){return so.exports}();const ao={mixins:[Ds],props:{autocomplete:{type:String,default:"new-password"},type:{type:String,default:"password"}}};const lo={};var uo=Ft({extends:qs,mixins:[ao]},undefined,undefined,!1,co,null,null,null);function co(t){for(let e in lo)this[e]=lo[e]}var po=function(){return uo.exports}();const ho={mixins:[vn,yn,_n,Cn],props:{columns:Number,options:Array,value:[String,Number,Boolean]}},fo={};var mo=Ft({mixins:[ho],inheritAttrs:!1,watch:{value(){this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{focus(){this.$el.querySelector("input").focus()},onInput(t){this.$emit("input",t)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},select(){this.focus()}},validations(){return{value:{required:!this.required||K.required}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("ul",{staticClass:"k-radio-input",style:"--columns:"+t.columns},t._l(t.options,(function(e,i){return n("li",{key:i},[n("input",{staticClass:"k-radio-input-native",attrs:{id:t.id+"-"+i,name:t.id,type:"radio"},domProps:{value:e.value,checked:t.value===e.value},on:{change:function(n){return t.onInput(e.value)}}}),e.info?n("label",{attrs:{for:t.id+"-"+i}},[n("span",{staticClass:"k-radio-input-text",domProps:{innerHTML:t._s(e.text)}}),n("span",{staticClass:"k-radio-input-info",domProps:{innerHTML:t._s(e.info)}})]):n("label",{attrs:{for:t.id+"-"+i},domProps:{innerHTML:t._s(e.text)}}),e.icon?n("k-icon",{attrs:{type:e.icon}}):t._e()],1)})),0)}),[],!1,go,null,null,null);function go(t){for(let e in fo)this[e]=fo[e]}var ko=function(){return mo.exports}();const vo={mixins:[vn,yn,_n,Sn,Cn],props:{default:[Number,String],max:{type:Number,default:100},min:{type:Number,default:0},step:{type:Number,default:1},tooltip:{type:[Boolean,Object],default:()=>({before:null,after:null})},value:[Number,String]}},bo={};var yo=Ft({mixins:[vo],inheritAttrs:!1,data(){return{listeners:l(a({},this.$listeners),{input:t=>this.onInput(t.target.value)})}},computed:{baseline(){return this.min<0?0:this.min},label(){return this.required||this.value||0===this.value?this.format(this.position):"–"},position(){return this.value||0===this.value?this.value:this.default||this.baseline}},watch:{position(){this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{focus(){this.$refs.input.focus()},format(t){const e=document.lang?document.lang.replace("_","-"):"en",n=this.step.toString().split("."),i=n.length>1?n[1].length:0;return new Intl.NumberFormat(e,{minimumFractionDigits:i}).format(t)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},onInput(t){this.$emit("input",t)}},validations(){return{position:{required:!this.required||K.required,min:!this.min||K.minValue(this.min),max:!this.max||K.maxValue(this.max)}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("label",{staticClass:"k-range-input"},[n("input",t._g(t._b({ref:"input",staticClass:"k-range-input-native",style:`--min: ${t.min}; --max: ${t.max}; --value: ${t.position}`,attrs:{type:"range"},domProps:{value:t.position}},"input",{autofocus:t.autofocus,disabled:t.disabled,id:t.id,max:t.max,min:t.min,name:t.name,required:t.required,step:t.step},!1),t.listeners)),t.tooltip?n("span",{staticClass:"k-range-input-tooltip"},[t.tooltip.before?n("span",{staticClass:"k-range-input-tooltip-before"},[t._v(t._s(t.tooltip.before))]):t._e(),n("span",{staticClass:"k-range-input-tooltip-text"},[t._v(t._s(t.label))]),t.tooltip.after?n("span",{staticClass:"k-range-input-tooltip-after"},[t._v(t._s(t.tooltip.after))]):t._e()]):t._e()])}),[],!1,$o,null,null,null);function $o(t){for(let e in bo)this[e]=bo[e]}var _o=function(){return yo.exports}();const xo={mixins:[vn,yn,_n,Sn,Cn],props:{ariaLabel:String,default:String,empty:{type:[Boolean,String],default:!0},placeholder:String,options:{type:Array,default:()=>[]},value:{type:[String,Number,Boolean],default:""}}},wo={};var So=Ft({mixins:[xo],inheritAttrs:!1,data(){return{selected:this.value,listeners:l(a({},this.$listeners),{click:t=>this.onClick(t),change:t=>this.onInput(t.target.value),input:()=>{}})}},computed:{emptyOption(){return this.placeholder||"—"},hasEmptyOption(){return!1!==this.empty&&!(this.required&&this.default)},label(){const t=this.text(this.selected);return""===this.selected||null===this.selected||null===t?this.emptyOption:t}},watch:{value(t){this.selected=t,this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{focus(){this.$refs.input.focus()},onClick(t){t.stopPropagation(),this.$emit("click",t)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},onInput(t){this.selected=t,this.$emit("input",this.selected)},select(){this.focus()},text(t){let e=null;return this.options.forEach((n=>{n.value==t&&(e=n.text)})),e}},validations(){return{selected:{required:!this.required||K.required}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("span",{staticClass:"k-select-input",attrs:{"data-disabled":t.disabled,"data-empty":""===t.selected}},[n("select",t._g({ref:"input",staticClass:"k-select-input-native",attrs:{id:t.id,autofocus:t.autofocus,"aria-label":t.ariaLabel,disabled:t.disabled,name:t.name,required:t.required},domProps:{value:t.selected}},t.listeners),[t.hasEmptyOption?n("option",{attrs:{disabled:t.required,value:""}},[t._v(" "+t._s(t.emptyOption)+" ")]):t._e(),t._l(t.options,(function(e){return n("option",{key:e.value,attrs:{disabled:e.disabled},domProps:{value:e.value}},[t._v(" "+t._s(e.text)+" ")])}))],2),t._v(" "+t._s(t.label)+" ")])}),[],!1,Co,null,null,null);function Co(t){for(let e in wo)this[e]=wo[e]}var Oo=function(){return So.exports}();const Eo={mixins:[Ds],props:{allow:{type:String,default:""},formData:{type:Object,default:()=>({})},sync:{type:String}}},Ao={};var To=Ft({extends:qs,mixins:[Eo],data(){return{slug:this.sluggify(this.value),slugs:this.$language?this.$language.rules:this.$system.slugs,syncValue:null}},watch:{formData:{handler(t){return!this.disabled&&(!(!this.sync||void 0===t[this.sync])&&(t[this.sync]!=this.syncValue&&(this.syncValue=t[this.sync],void this.onInput(this.sluggify(this.syncValue)))))},deep:!0,immediate:!0},value(t){(t=this.sluggify(t))!==this.slug&&(this.slug=t,this.$emit("input",this.slug))}},methods:{sluggify(t){return this.$helper.slug(t,[this.slugs,this.$system.ascii],this.allow)},onInput(t){this.slug=this.sluggify(t),this.$emit("input",this.slug)}}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("input",t._g(t._b({directives:[{name:"direction",rawName:"v-direction"}],ref:"input",staticClass:"k-text-input",attrs:{autocomplete:"off",spellcheck:"false",type:"text"},domProps:{value:t.slug}},"input",{autofocus:t.autofocus,disabled:t.disabled,id:t.id,minlength:t.minlength,name:t.name,pattern:t.pattern,placeholder:t.placeholder,required:t.required},!1),t.listeners))}),[],!1,Io,null,null,null);function Io(t){for(let e in Ao)this[e]=Ao[e]}var Mo=function(){return To.exports}();const Lo={mixins:[vn,yn,_n,Sn,Cn],props:{accept:{type:String,default:"all"},icon:{type:[String,Boolean],default:"tag"},layout:String,max:Number,min:Number,options:{type:Array,default:()=>[]},separator:{type:String,default:","},value:{type:Array,default:()=>[]}}},jo={};var Do=Ft({mixins:[Lo],inheritAttrs:!1,data(){return{tags:this.prepareTags(this.value),selected:null,newTag:null,tagOptions:this.options.map((t=>{var e;return(null==(e=this.icon)?void 0:e.length)>0&&(t.icon=this.icon),t}),this)}},computed:{dragOptions(){return{delay:1,disabled:!this.draggable,draggable:".k-tag"}},draggable(){return this.tags.length>1},skip(){return this.tags.map((t=>t.value))}},watch:{value(t){this.tags=this.prepareTags(t),this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{addString(t){if(t)if((t=t.trim()).includes(this.separator))t.split(this.separator).forEach((t=>{this.addString(t)}));else if(0!==t.length)if("options"===this.accept){const e=this.options.filter((e=>e.text===t))[0];if(!e)return;this.addTag(e)}else this.addTag({text:t,value:t})},addTag(t){this.addTagToIndex(t),this.$refs.autocomplete.close(),this.$refs.input.focus()},addTagToIndex(t){if("options"===this.accept){if(!this.options.filter((e=>e.value===t.value))[0])return}-1===this.index(t)&&(!this.max||this.tags.length=this.tags.length)return;break;case"first":e=0;break;case"last":e=this.tags.length-1;break;default:e=t}let i=this.tags[e];if(i){let t=this.$refs[i.value];if(null==t?void 0:t[0])return{ref:t[0],tag:i,index:e}}return!1},index(t){return this.tags.findIndex((e=>e.value===t.value))},onInput(){this.$emit("input",this.tags)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},leaveInput(t){0===t.target.selectionStart&&t.target.selectionStart===t.target.selectionEnd&&0!==this.tags.length&&(this.$refs.autocomplete.close(),this.navigate("last"),t.preventDefault())},navigate(t){var e=this.get(t);e?(e.ref.focus(),this.selectTag(e.tag)):"next"===t&&(this.$refs.input.focus(),this.selectTag(null))},prepareTags:t=>!1===Array.isArray(t)?[]:t.map((t=>"string"==typeof t?{text:t,value:t}:t)),remove(t){const e=this.get("prev"),n=this.get("next");this.tags.splice(this.index(t),1),this.onInput(),e?(this.selectTag(e.tag),e.ref.focus()):n?this.selectTag(n.tag):(this.selectTag(null),this.$refs.input.focus())},select(){this.focus()},selectTag(t){this.selected=t},tab(t){var e;(null==(e=this.newTag)?void 0:e.length)>0&&(t.preventDefault(),this.addString(this.newTag))},type(t){this.newTag=t,this.$refs.autocomplete.search(t)}},validations(){return{tags:{required:!this.required||K.required,minLength:!this.min||K.minLength(this.min),maxLength:!this.max||K.maxLength(this.max)}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-draggable",{directives:[{name:"direction",rawName:"v-direction"}],ref:"box",staticClass:"k-tags-input",attrs:{list:t.tags,"data-layout":t.layout,options:t.dragOptions},on:{end:t.onInput},scopedSlots:t._u([{key:"footer",fn:function(){return[n("span",{staticClass:"k-tags-input-element"},[n("k-autocomplete",{ref:"autocomplete",attrs:{html:!0,options:t.options,skip:t.skip},on:{select:t.addTag,leave:function(e){return t.$refs.input.focus()}}},[n("input",{directives:[{name:"model",rawName:"v-model.trim",value:t.newTag,expression:"newTag",modifiers:{trim:!0}}],ref:"input",attrs:{id:t.id,autofocus:t.autofocus,disabled:t.disabled||t.max&&t.tags.length>=t.max,name:t.name,autocomplete:"off",type:"text"},domProps:{value:t.newTag},on:{input:[function(e){e.target.composing||(t.newTag=e.target.value.trim())},function(e){return t.type(e.target.value)}],blur:[t.blurInput,function(e){return t.$forceUpdate()}],keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"s",void 0,e.key,void 0)?null:e.metaKey?t.blurInput.apply(null,arguments):null},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"left",37,e.key,["Left","ArrowLeft"])||"button"in e&&0!==e.button||e.ctrlKey||e.shiftKey||e.altKey||e.metaKey?null:t.leaveInput.apply(null,arguments)},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"enter",13,e.key,"Enter")||e.ctrlKey||e.shiftKey||e.altKey||e.metaKey?null:t.enter.apply(null,arguments)},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"tab",9,e.key,"Tab")||e.ctrlKey||e.shiftKey||e.altKey||e.metaKey?null:t.tab.apply(null,arguments)},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"backspace",void 0,e.key,void 0)||e.ctrlKey||e.shiftKey||e.altKey||e.metaKey?null:t.leaveInput.apply(null,arguments)}]}})])],1)]},proxy:!0}])},t._l(t.tags,(function(e,i){return n("k-tag",{key:i,ref:e.value,refInFor:!0,attrs:{removable:!t.disabled,name:"tag"},on:{remove:function(n){return t.remove(e)}},nativeOn:{click:function(t){t.stopPropagation()},blur:function(e){return t.selectTag(null)},focus:function(n){return t.selectTag(e)},keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"left",37,e.key,["Left","ArrowLeft"])||"button"in e&&0!==e.button?null:t.navigate("prev")},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"right",39,e.key,["Right","ArrowRight"])||"button"in e&&2!==e.button?null:t.navigate("next")}],dblclick:function(n){return t.edit(e)}}},[n("span",{domProps:{innerHTML:t._s(e.text)}})])})),1)}),[],!1,Bo,null,null,null);function Bo(t){for(let e in jo)this[e]=jo[e]}var Po=function(){return Do.exports}();const No={mixins:[Ds],props:{autocomplete:{type:String,default:"tel"},type:{type:String,default:"tel"}}};const qo={};var Fo=Ft({extends:qs,mixins:[No]},undefined,undefined,!1,Ro,null,null,null);function Ro(t){for(let e in qo)this[e]=qo[e]}var zo=function(){return Fo.exports}();const Yo={mixins:[vn,yn,_n,Sn,Cn],props:{buttons:{type:[Boolean,Array],default:!0},endpoints:Object,font:String,maxlength:Number,minlength:Number,placeholder:String,preselect:Boolean,size:String,spellcheck:{type:[Boolean,String],default:"off"},theme:String,uploads:[Boolean,Object,Array],value:String}},Ho={};var Uo=Ft({mixins:[Yo],inheritAttrs:!1,data:()=>({over:!1}),watch:{value(){this.onInvalid(),this.$nextTick((()=>{this.resize()}))}},mounted(){this.$nextTick((()=>{this.$library.autosize(this.$refs.input)})),this.onInvalid(),this.$props.autofocus&&this.focus(),this.$props.preselect&&this.select()},methods:{cancel(){this.$refs.input.focus()},dialog(t){if(!this.$refs[t+"Dialog"])throw"Invalid toolbar dialog";this.$refs[t+"Dialog"].open(this.$refs.input,this.selection())},focus(){this.$refs.input.focus()},insert(t){const e=this.$refs.input,n=e.value;setTimeout((()=>{if(e.focus(),document.execCommand("insertText",!1,t),e.value===n){const n=e.value.slice(0,e.selectionStart)+t+e.value.slice(e.selectionEnd);e.value=n,this.$emit("input",n)}})),this.resize()},insertFile(t){(null==t?void 0:t.length)>0&&this.insert(t.map((t=>t.dragText)).join("\n\n"))},insertUpload(t,e){this.insert(e.map((t=>t.dragText)).join("\n\n")),this.$events.$emit("model.update")},onClick(){this.$refs.toolbar&&this.$refs.toolbar.close()},onCommand(t,e){"function"==typeof this[t]?"function"==typeof e?this[t](e(this.$refs.input,this.selection())):this[t](e):window.console.warn(t+" is not a valid command")},onDrop(t){if(this.uploads&&this.$helper.isUploadEvent(t))return this.$refs.fileUpload.drop(t.dataTransfer.files,{url:this.$urls.api+"/"+this.endpoints.field+"/upload",multiple:!1});const e=this.$store.state.drag;"text"===(null==e?void 0:e.type)&&(this.focus(),this.insert(e.data))},onFocus(t){this.$emit("focus",t)},onInput(t){this.$emit("input",t.target.value)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},onOut(){this.$refs.input.blur(),this.over=!1},onOver(t){if(this.uploads&&this.$helper.isUploadEvent(t))return t.dataTransfer.dropEffect="copy",this.focus(),void(this.over=!0);const e=this.$store.state.drag;"text"===(null==e?void 0:e.type)&&(t.dataTransfer.dropEffect="copy",this.focus(),this.over=!0)},onShortcut(t){!1!==this.buttons&&"Meta"!==t.key&&"Control"!==t.key&&this.$refs.toolbar&&this.$refs.toolbar.shortcut(t.key,t)},onSubmit(t){return this.$emit("submit",t)},prepend(t){this.insert(t+" "+this.selection())},resize(){this.$library.autosize.update(this.$refs.input)},select(){this.$refs.select()},selectFile(){this.$refs.fileDialog.open({endpoint:this.endpoints.field+"/files",multiple:!1})},selection(){const t=this.$refs.input,e=t.selectionStart,n=t.selectionEnd;return t.value.substring(e,n)},uploadFile(){this.$refs.fileUpload.open({url:this.$urls.api+"/"+this.endpoints.field+"/upload",multiple:!1})},wrap(t){this.insert(t+this.selection()+t)}},validations(){return{value:{required:!this.required||K.required,minLength:!this.minlength||K.minLength(this.minlength),maxLength:!this.maxlength||K.maxLength(this.maxlength)}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-textarea-input",attrs:{"data-over":t.over,"data-size":t.size,"data-theme":t.theme}},[n("div",{staticClass:"k-textarea-input-wrapper"},[t.buttons&&!t.disabled?n("k-toolbar",{ref:"toolbar",attrs:{buttons:t.buttons,disabled:t.disabled,uploads:t.uploads},on:{command:t.onCommand},nativeOn:{mousedown:function(t){t.preventDefault()}}}):t._e(),n("textarea",t._b({directives:[{name:"direction",rawName:"v-direction"}],ref:"input",staticClass:"k-textarea-input-native",attrs:{"data-font":t.font},on:{click:t.onClick,focus:t.onFocus,input:t.onInput,keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"enter",13,e.key,"Enter")?null:e.metaKey?t.onSubmit.apply(null,arguments):null},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"enter",13,e.key,"Enter")?null:e.ctrlKey?t.onSubmit.apply(null,arguments):null},function(e){return e.metaKey?t.onShortcut.apply(null,arguments):null},function(e){return e.ctrlKey?t.onShortcut.apply(null,arguments):null}],dragover:t.onOver,dragleave:t.onOut,drop:t.onDrop}},"textarea",{autofocus:t.autofocus,disabled:t.disabled,id:t.id,minlength:t.minlength,name:t.name,placeholder:t.placeholder,required:t.required,spellcheck:t.spellcheck,value:t.value},!1))],1),n("k-toolbar-email-dialog",{ref:"emailDialog",on:{cancel:t.cancel,submit:function(e){return t.insert(e)}}}),n("k-toolbar-link-dialog",{ref:"linkDialog",on:{cancel:t.cancel,submit:function(e){return t.insert(e)}}}),n("k-files-dialog",{ref:"fileDialog",on:{cancel:t.cancel,submit:function(e){return t.insertFile(e)}}}),t.uploads?n("k-upload",{ref:"fileUpload",on:{success:t.insertUpload}}):t._e()],1)}),[],!1,Ko,null,null,null);function Ko(t){for(let e in Ho)this[e]=Ho[e]}var Jo=function(){return Uo.exports}();const Go={props:{display:{type:String,default:"HH:mm"},max:String,min:String,step:{type:Object,default:()=>({size:5,unit:"minute"})},type:{type:String,default:"time"},value:String}};const Vo={};var Wo=Ft({mixins:[js,Go],computed:{inputType:()=>"time"}},undefined,undefined,!1,Xo,null,null,null);function Xo(t){for(let e in Vo)this[e]=Vo[e]}var Zo=function(){return Wo.exports}();const Qo={props:{autofocus:Boolean,disabled:Boolean,id:[Number,String],text:{type:[Array,String]},required:Boolean,value:Boolean}},tr={};var er=Ft({mixins:[Qo],inheritAttrs:!1,computed:{label(){const t=this.text||[this.$t("off"),this.$t("on")];return Array.isArray(t)?this.value?t[1]:t[0]:t}},watch:{value(){this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{focus(){this.$refs.input.focus()},onEnter(t){"Enter"===t.key&&this.$refs.input.click()},onInput(t){this.$emit("input",t)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},select(){this.$refs.input.focus()}},validations(){return{value:{required:!this.required||K.required}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("label",{staticClass:"k-toggle-input",attrs:{"data-disabled":t.disabled}},[n("input",{ref:"input",staticClass:"k-toggle-input-native",attrs:{id:t.id,disabled:t.disabled,type:"checkbox"},domProps:{checked:t.value},on:{change:function(e){return t.onInput(e.target.checked)}}}),n("span",{staticClass:"k-toggle-input-label",domProps:{innerHTML:t._s(t.label)}})])}),[],!1,nr,null,null,null);function nr(t){for(let e in tr)this[e]=tr[e]}var ir=function(){return er.exports}();const sr={mixins:[vn,yn,_n,Cn],props:{columns:Number,grow:Boolean,labels:Boolean,options:Array,reset:Boolean,value:[String,Number,Boolean]}},or={};var rr=Ft({inheritAttrs:!1,mixins:[sr],watch:{value(){this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{focus(){(this.$el.querySelector("input[checked]")||this.$el.querySelector("input")).focus()},onClick(t){t===this.value&&this.reset&&!this.required&&this.$emit("input","")},onInput(t){this.$emit("input",t)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},select(){this.focus()}},validations(){return{value:{required:!this.required||K.required}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("ul",{staticClass:"k-toggles-input",style:"--options:"+(t.columns||t.options.length),attrs:{"data-invalid":t.$v.$invalid,"data-labels":t.labels}},t._l(t.options,(function(e,i){return n("li",{key:i},[n("input",{staticClass:"input-hidden",attrs:{id:t.id+"-"+i,name:t.id,type:"radio"},domProps:{value:e.value,checked:t.value===e.value},on:{click:function(n){return t.onClick(e.value)},change:function(n){return t.onInput(e.value)}}}),n("label",{attrs:{for:t.id+"-"+i,title:e.text}},[e.icon?n("k-icon",{attrs:{type:e.icon}}):t._e(),t.labels?n("span",{staticClass:"k-toggles-text"},[t._v(" "+t._s(e.text)+" ")]):t._e()],1)])})),0)}),[],!1,ar,null,null,null);function ar(t){for(let e in or)this[e]=or[e]}var lr=function(){return rr.exports}();const ur={mixins:[Ds],props:{autocomplete:{type:String,default:"url"},type:{type:String,default:"url"}}};const cr={};var dr=Ft({extends:qs,mixins:[ur]},undefined,undefined,!1,pr,null,null,null);function pr(t){for(let e in cr)this[e]=cr[e]}var hr=function(){return dr.exports}();u.component("k-checkbox-input",ws),u.component("k-checkboxes-input",As),u.component("k-date-input",js),u.component("k-email-input",Hs),u.component("k-list-input",Ws),u.component("k-multiselect-input",eo),u.component("k-number-input",ro),u.component("k-password-input",po),u.component("k-radio-input",ko),u.component("k-range-input",_o),u.component("k-select-input",Oo),u.component("k-slug-input",Mo),u.component("k-tags-input",Po),u.component("k-tel-input",zo),u.component("k-text-input",qs),u.component("k-textarea-input",Jo),u.component("k-time-input",Zo),u.component("k-toggle-input",ir),u.component("k-toggles-input",lr),u.component("k-url-input",hr);const fr={mixins:[On],inheritAttrs:!1,props:{autofocus:Boolean,empty:String,fieldsets:Object,fieldsetGroups:Object,group:String,max:{type:Number,default:null},value:{type:Array,default:()=>[]}},data:()=>({opened:[]}),computed:{hasFieldsets(){return Object.keys(this.fieldsets).length},isEmpty(){return 0===this.value.length},isFull(){return null!==this.max&&this.value.length>=this.max}},methods:{focus(){this.$refs.blocks.focus()}}},mr={};var gr=Ft(fr,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-blocks-field",scopedSlots:t._u([{key:"options",fn:function(){return[t.hasFieldsets?n("k-dropdown",[n("k-button",{attrs:{icon:"dots"},on:{click:function(e){return t.$refs.options.toggle()}}}),n("k-dropdown-content",{ref:"options",attrs:{align:"right"}},[n("k-dropdown-item",{attrs:{disabled:t.isFull,icon:"add"},on:{click:function(e){return t.$refs.blocks.choose(t.value.length)}}},[t._v(" "+t._s(t.$t("add"))+" ")]),n("hr"),n("k-dropdown-item",{attrs:{disabled:t.isEmpty,icon:"template"},on:{click:function(e){return t.$refs.blocks.copyAll()}}},[t._v(" "+t._s(t.$t("copy.all"))+" ")]),n("k-dropdown-item",{attrs:{disabled:t.isFull,icon:"download"},on:{click:function(e){return t.$refs.blocks.pasteboard()}}},[t._v(" "+t._s(t.$t("paste"))+" ")]),n("hr"),n("k-dropdown-item",{attrs:{disabled:t.isEmpty,icon:"trash"},on:{click:function(e){return t.$refs.blocks.confirmToRemoveAll()}}},[t._v(" "+t._s(t.$t("delete.all"))+" ")])],1)],1):t._e()]},proxy:!0}])},"k-field",t.$props,!1),[n("k-blocks",t._g({ref:"blocks",attrs:{autofocus:t.autofocus,compact:!1,empty:t.empty,endpoints:t.endpoints,fieldsets:t.fieldsets,"fieldset-groups":t.fieldsetGroups,group:t.group,max:t.max,value:t.value},on:{close:function(e){t.opened=e},open:function(e){t.opened=e}}},t.$listeners))],1)}),[],!1,kr,null,null,null);function kr(t){for(let e in mr)this[e]=mr[e]}var vr=function(){return gr.exports}(),br={props:{counter:{type:Boolean,default:!0}},computed:{counterOptions(){var t,e;if(null===this.value||this.disabled||!1===this.counter)return!1;let n=0;return this.value&&(n=Array.isArray(this.value)?this.value.length:String(this.value).length),{count:n,min:null!=(t=this.min)?t:this.minlength,max:null!=(e=this.max)?e:this.maxlength}}}};const yr={};var $r=Ft({mixins:[On,Pn,Ss,br],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-checkboxes-field",attrs:{counter:t.counterOptions}},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"checkboxes"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,_r,null,null,null);function _r(t){for(let e in yr)this[e]=yr[e]}var xr=function(){return $r.exports}();const wr={mixins:[On,Pn,Ts],inheritAttrs:!1,props:{calendar:{type:Boolean,default:!0},icon:{type:String,default:"calendar"},time:{type:[Boolean,Object],default:()=>({})},times:{type:Boolean,default:!0}},data(){return{isInvalid:!1,iso:this.toIso(this.value)}},computed:{isEmpty(){return this.time?null===this.iso.date&&this.iso.time:null===this.iso.date}},watch:{value(t,e){t!==e&&(this.iso=this.toIso(t))}},methods:{focus(){this.$refs.dateInput.focus()},now(){const t=this.$library.dayjs();return{date:t.toISO("date"),time:this.time?t.toISO("time"):"00:00:00"}},onInput(){if(this.isEmpty)return this.$emit("input","");const t=this.$library.dayjs.iso(this.iso.date+" "+this.iso.time);(t||null!==this.iso.date&&null!==this.iso.time)&&this.$emit("input",(null==t?void 0:t.toISO())||"")},onCalendarInput(t){var e;null==(e=this.$refs.calendar)||e.close(),this.onDateInput(t)},onDateInput(t){t&&!this.iso.time&&(this.iso.time=this.now().time),this.iso.date=t,this.onInput()},onDateInvalid(t){this.isInvalid=t},onTimeInput(t){t&&!this.iso.date&&(this.iso.date=this.now().date),this.iso.time=t,this.onInput()},onTimesInput(t){var e;null==(e=this.$refs.times)||e.close(),this.onTimeInput(t+":00")},toIso(t){const e=this.$library.dayjs.iso(t);return{date:(null==e?void 0:e.toISO("date"))||null,time:(null==e?void 0:e.toISO("time"))||null}}}},Sr={};var Cr=Ft(wr,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-date-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[n("div",{ref:"body",staticClass:"k-date-field-body",attrs:{"data-invalid":!t.novalidate&&t.isInvalid,"data-theme":"field"}},[n("k-input",t._b({ref:"dateInput",attrs:{id:t._uid,autofocus:t.autofocus,disabled:t.disabled,display:t.display,max:t.max,min:t.min,required:t.required,value:t.value,theme:"field",type:"date"},on:{invalid:t.onDateInvalid,input:t.onDateInput,submit:function(e){return t.$emit("submit")}},scopedSlots:t._u([t.calendar?{key:"icon",fn:function(){return[n("k-dropdown",[n("k-button",{staticClass:"k-input-icon-button",attrs:{icon:t.icon,tooltip:t.$t("date.select")},on:{click:function(e){return t.$refs.calendar.toggle()}}}),n("k-dropdown-content",{ref:"calendar",attrs:{align:"right"}},[n("k-calendar",{attrs:{value:t.value,min:t.min,max:t.max},on:{input:t.onCalendarInput}})],1)],1)]},proxy:!0}:null],null,!0)},"k-input",t.$props,!1)),t.time?n("k-input",{ref:"timeInput",attrs:{disabled:t.disabled,display:t.time.display,required:t.required,step:t.time.step,value:t.iso.time,icon:t.time.icon,theme:"field",type:"time"},on:{input:t.onTimeInput,submit:function(e){return t.$emit("submit")}},scopedSlots:t._u([t.times?{key:"icon",fn:function(){return[n("k-dropdown",[n("k-button",{staticClass:"k-input-icon-button",attrs:{icon:t.time.icon||"clock",tooltip:t.$t("time.select")},on:{click:function(e){return t.$refs.times.toggle()}}}),n("k-dropdown-content",{ref:"times",attrs:{align:"right"}},[n("k-times",{attrs:{display:t.time.display,value:t.value},on:{input:t.onTimesInput}})],1)],1)]},proxy:!0}:null],null,!0)}):t._e()],1)])}),[],!1,Or,null,null,null);function Or(t){for(let e in Sr)this[e]=Sr[e]}var Er=function(){return Cr.exports}();const Ar={mixins:[On,Pn,Fs],inheritAttrs:!1,props:{link:{type:Boolean,default:!0},icon:{type:String,default:"email"}},computed:{mailto(){var t;return(null==(t=this.value)?void 0:t.length)>0?"mailto:"+this.value:null}},methods:{focus(){this.$refs.input.focus()}}},Tr={};var Ir=Ft(Ar,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-email-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"email"},scopedSlots:t._u([{key:"icon",fn:function(){return[t.link?n("k-button",{staticClass:"k-input-icon-button",attrs:{icon:t.icon,link:t.mailto,tooltip:t.$t("open"),tabindex:"-1",target:"_blank"}}):t._e()]},proxy:!0}])},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,Mr,null,null,null);function Mr(t){for(let e in Tr)this[e]=Tr[e]}var Lr=function(){return Ir.exports}(),jr={mixins:[On],inheritAttrs:!1,props:{empty:String,info:String,link:Boolean,layout:{type:String,default:"list"},max:Number,multiple:Boolean,parent:String,search:Boolean,size:String,text:String,value:{type:Array,default:()=>[]}},data(){return{selected:this.value}},computed:{btnIcon(){return!this.multiple&&this.selected.length>0?"refresh":"add"},btnLabel(){return!this.multiple&&this.selected.length>0?this.$t("change"):this.$t("add")},collection(){return{empty:this.emptyProps,items:this.selected,layout:this.layout,link:this.link,size:this.size,sortable:!this.disabled&&this.selected.length>1}},isInvalid(){return!(!this.required||0!==this.selected.length)||(!!(this.min&&this.selected.lengththis.max))},items(){return this.models.map(this.item)},more(){return!this.max||this.max>this.selected.length}},watch:{value(t){this.selected=t}},methods:{focus(){},item:t=>t,onInput(){this.$emit("input",this.selected)},open(){if(this.disabled)return!1;this.$refs.selector.open({endpoint:this.endpoints.field,max:this.max,multiple:this.multiple,search:this.search,selected:this.selected.map((t=>t.id))})},remove(t){this.selected.splice(t,1),this.onInput()},removeById(t){this.selected=this.selected.filter((e=>e.id!==t)),this.onInput()},select(t){0!==t.length?(this.selected=this.selected.filter((e=>t.filter((t=>t.id===e.id)).length>0)),t.forEach((t=>{0===this.selected.filter((e=>t.id===e.id)).length&&this.selected.push(t)})),this.onInput()):this.selected=[]}}};const Dr={mixins:[jr],props:{uploads:[Boolean,Object,Array]},computed:{emptyProps(){return{icon:"image",text:this.empty||this.$t("field.files.empty")}},moreUpload(){return!this.disabled&&this.more&&this.uploads},options(){return this.uploads?{icon:this.btnIcon,text:this.btnLabel,options:[{icon:"check",text:this.$t("select"),click:"open"},{icon:"upload",text:this.$t("upload"),click:"upload"}]}:{options:[{icon:"check",text:this.$t("select"),click:()=>this.open()}]}},uploadParams(){return{accept:this.uploads.accept,max:this.max,multiple:this.multiple,url:this.$urls.api+"/"+this.endpoints.field+"/upload"}}},created(){this.$events.$on("file.delete",this.removeById)},destroyed(){this.$events.$off("file.delete",this.removeById)},methods:{drop(t){return!1!==this.uploads&&this.$refs.fileUpload.drop(t,this.uploadParams)},prompt(){if(this.disabled)return!1;this.moreUpload?this.$refs.options.toggle():this.open()},onAction(t){if(this.moreUpload)switch(t){case"open":return this.open();case"upload":return this.$refs.fileUpload.open(this.uploadParams)}},isSelected(t){return this.selected.find((e=>e.id===t.id))},upload(t,e){!1===this.multiple&&(this.selected=[]),e.forEach((t=>{this.isSelected(t)||this.selected.push(t)})),this.onInput(),this.$events.$emit("model.update")}}},Br={};var Pr=Ft(Dr,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-files-field",scopedSlots:t._u([t.more&&!t.disabled?{key:"options",fn:function(){return[n("k-button-group",{staticClass:"k-field-options"},[n("k-options-dropdown",t._b({ref:"options",on:{action:t.onAction}},"k-options-dropdown",t.options,!1))],1)]},proxy:!0}:null],null,!0)},"k-field",t.$props,!1),[n("k-dropzone",{attrs:{disabled:!t.moreUpload},on:{drop:t.drop}},[n("k-collection",t._b({on:{empty:t.prompt,sort:t.onInput,sortChange:function(e){return t.$emit("change",e)}},scopedSlots:t._u([{key:"options",fn:function(e){var i=e.index;return[t.disabled?t._e():n("k-button",{attrs:{tooltip:t.$t("remove"),icon:"remove"},on:{click:function(e){return t.remove(i)}}})]}}])},"k-collection",t.collection,!1))],1),n("k-files-dialog",{ref:"selector",on:{submit:t.select}}),n("k-upload",{ref:"fileUpload",on:{success:t.upload}})],1)}),[],!1,Nr,null,null,null);function Nr(t){for(let e in Br)this[e]=Br[e]}var qr=function(){return Pr.exports}();const Fr={};var Rr=Ft({},(function(){var t=this.$createElement;return(this._self._c||t)("div",{staticClass:"k-field k-gap-field"})}),[],!1,zr,null,null,null);function zr(t){for(let e in Fr)this[e]=Fr[e]}var Yr=function(){return Rr.exports}();const Hr={mixins:[$n,wn],props:{numbered:Boolean}},Ur={};var Kr=Ft(Hr,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-headline-field"},[n("k-headline",{attrs:{"data-numbered":t.numbered,size:"large"}},[t._v(" "+t._s(t.label)+" ")]),t.help?n("footer",{staticClass:"k-field-footer"},[t.help?n("k-text",{staticClass:"k-field-help",attrs:{theme:"help"},domProps:{innerHTML:t._s(t.help)}}):t._e()],1):t._e()],1)}),[],!1,Jr,null,null,null);function Jr(t){for(let e in Ur)this[e]=Ur[e]}var Gr=function(){return Kr.exports}();const Vr={};var Wr=Ft({mixins:[$n,wn],props:{text:String,theme:{type:String,default:"info"}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-field k-info-field"},[n("k-headline",[t._v(t._s(t.label))]),n("k-box",{attrs:{theme:t.theme}},[n("k-text",{domProps:{innerHTML:t._s(t.text)}})],1),t.help?n("footer",{staticClass:"k-field-footer"},[t.help?n("k-text",{staticClass:"k-field-help",attrs:{theme:"help"},domProps:{innerHTML:t._s(t.help)}}):t._e()],1):t._e()],1)}),[],!1,Xr,null,null,null);function Xr(t){for(let e in Vr)this[e]=Vr[e]}var Zr=function(){return Wr.exports}();const Qr={props:{blocks:Array,endpoints:Object,fieldsetGroups:Object,fieldsets:Object,id:String,isSelected:Boolean,width:String}},ta={};var ea=Ft(Qr,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-column k-layout-column",attrs:{id:t.id,"data-width":t.width,tabindex:"0"},on:{dblclick:function(e){return t.$refs.blocks.choose(t.blocks.length)}}},[n("k-blocks",{ref:"blocks",attrs:{endpoints:t.endpoints,"fieldset-groups":t.fieldsetGroups,fieldsets:t.fieldsets,value:t.blocks,group:"layout"},on:{input:function(e){return t.$emit("input",e)}},nativeOn:{dblclick:function(t){t.stopPropagation()}}})],1)}),[],!1,na,null,null,null);function na(t){for(let e in ta)this[e]=ta[e]}const ia={components:{"k-layout-column":function(){return ea.exports}()},props:{attrs:[Array,Object],columns:Array,disabled:Boolean,endpoints:Object,fieldsetGroups:Object,fieldsets:Object,id:String,isSelected:Boolean,settings:Object},computed:{tabs(){let t=this.settings.tabs;return Object.entries(t).forEach((([e,n])=>{Object.entries(n.fields).forEach((([n])=>{t[e].fields[n].endpoints={field:this.endpoints.field+"/fields/"+n,section:this.endpoints.section,model:this.endpoints.model}}))})),t}}},sa={};var oa=Ft(ia,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("section",{staticClass:"k-layout",attrs:{"data-selected":t.isSelected,tabindex:"0"},on:{click:function(e){return t.$emit("select")}}},[n("k-grid",{staticClass:"k-layout-columns"},t._l(t.columns,(function(e,i){return n("k-layout-column",t._b({key:e.id,attrs:{endpoints:t.endpoints,"fieldset-groups":t.fieldsetGroups,fieldsets:t.fieldsets},on:{input:function(n){return t.$emit("updateColumn",{column:e,columnIndex:i,blocks:n})}}},"k-layout-column",e,!1))})),1),t.disabled?t._e():n("nav",{staticClass:"k-layout-toolbar"},[t.settings?n("k-button",{staticClass:"k-layout-toolbar-button",attrs:{tooltip:t.$t("settings"),icon:"settings"},on:{click:function(e){return t.$refs.drawer.open()}}}):t._e(),n("k-dropdown",[n("k-button",{staticClass:"k-layout-toolbar-button",attrs:{icon:"angle-down"},on:{click:function(e){return t.$refs.options.toggle()}}}),n("k-dropdown-content",{ref:"options",attrs:{align:"right"}},[n("k-dropdown-item",{attrs:{icon:"angle-up"},on:{click:function(e){return t.$emit("prepend")}}},[t._v(" "+t._s(t.$t("insert.before"))+" ")]),n("k-dropdown-item",{attrs:{icon:"angle-down"},on:{click:function(e){return t.$emit("append")}}},[t._v(" "+t._s(t.$t("insert.after"))+" ")]),n("hr"),t.settings?n("k-dropdown-item",{attrs:{icon:"settings"},on:{click:function(e){return t.$refs.drawer.open()}}},[t._v(" "+t._s(t.$t("settings"))+" ")]):t._e(),n("k-dropdown-item",{attrs:{icon:"copy"},on:{click:function(e){return t.$emit("duplicate")}}},[t._v(" "+t._s(t.$t("duplicate"))+" ")]),n("hr"),n("k-dropdown-item",{attrs:{icon:"trash"},on:{click:function(e){return t.$refs.confirmRemoveDialog.open()}}},[t._v(" "+t._s(t.$t("field.layout.delete"))+" ")])],1)],1),n("k-sort-handle")],1),t.settings?n("k-form-drawer",{ref:"drawer",staticClass:"k-layout-drawer",attrs:{tabs:t.tabs,title:t.$t("settings"),value:t.attrs,icon:"settings"},on:{input:function(e){return t.$emit("updateAttrs",e)}}}):t._e(),n("k-remove-dialog",{ref:"confirmRemoveDialog",attrs:{text:t.$t("field.layout.delete.confirm")},on:{submit:function(e){return t.$emit("remove")}}})],1)}),[],!1,ra,null,null,null);function ra(t){for(let e in sa)this[e]=sa[e]}var aa=function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",[t.rows.length?[n("k-draggable",t._b({staticClass:"k-layouts",on:{sort:t.save}},"k-draggable",t.draggableOptions,!1),t._l(t.rows,(function(e,i){return n("k-layout",t._b({key:e.id,attrs:{disabled:t.disabled,endpoints:t.endpoints,"fieldset-groups":t.fieldsetGroups,fieldsets:t.fieldsets,"is-selected":t.selected===e.id,settings:t.settings},on:{append:function(e){return t.selectLayout(i+1)},duplicate:function(n){return t.duplicateLayout(i,e)},prepend:function(e){return t.selectLayout(i)},remove:function(n){return t.removeLayout(e)},select:function(n){t.selected=e.id},updateAttrs:function(e){return t.updateAttrs(i,e)},updateColumn:function(n){return t.updateColumn(Object.assign({layout:e,layoutIndex:i},n))}}},"k-layout",e,!1))})),1),t.disabled?t._e():n("k-button",{staticClass:"k-layout-add-button",attrs:{icon:"add"},on:{click:function(e){return t.selectLayout(t.rows.length)}}})]:[n("k-empty",{staticClass:"k-layout-empty",attrs:{icon:"dashboard"},on:{click:function(e){return t.selectLayout(0)}}},[t._v(" "+t._s(t.empty||t.$t("field.layout.empty"))+" ")])],n("k-dialog",{ref:"selector",staticClass:"k-layout-selector",attrs:{"cancel-button":!1,"submit-button":!1,size:"medium"}},[n("k-headline",[t._v(t._s(t.$t("field.layout.select")))]),n("ul",t._l(t.layouts,(function(e,i){return n("li",{key:i,staticClass:"k-layout-selector-option"},[n("k-grid",{nativeOn:{click:function(n){return t.addLayout(e)}}},t._l(e,(function(t,e){return n("k-column",{key:e,attrs:{width:t}})})),1)],1)})),0)],1)],2)};const la={components:{"k-layout":function(){return oa.exports}()},props:{disabled:Boolean,empty:String,endpoints:Object,fieldsetGroups:Object,fieldsets:Object,layouts:Array,max:Number,settings:Object,value:Array},data(){return{currentLayout:null,nextIndex:null,rows:this.value,selected:null}},computed:{draggableOptions(){return{id:this._uid,handle:!0,list:this.rows}}},watch:{value(){this.rows=this.value}},methods:{async addLayout(t){let e=await this.$api.post(this.endpoints.field+"/layout",{columns:t});this.rows.splice(this.nextIndex,0,e),this.layouts.length>1&&this.$refs.selector.close(),this.save()},duplicateLayout(t,e){let n=l(a({},this.$helper.clone(e)),{id:this.$helper.uuid()});n.columns=n.columns.map((t=>(t.id=this.$helper.uuid(),t.blocks=t.blocks.map((t=>(t.id=this.$helper.uuid(),t))),t))),this.rows.splice(t+1,0,n),this.save()},removeLayout(t){const e=this.rows.findIndex((e=>e.id===t.id));-1!==e&&this.$delete(this.rows,e),this.save()},save(){this.$emit("input",this.rows)},selectLayout(t){this.nextIndex=t,1!==this.layouts.length?this.$refs.selector.open():this.addLayout(this.layouts[0])},updateColumn(t){this.rows[t.layoutIndex].columns[t.columnIndex].blocks=t.blocks,this.save()},updateAttrs(t,e){this.rows[t].attrs=e,this.save()}}},ua={};var ca=Ft(la,aa,[],!1,da,null,null,null);function da(t){for(let e in ua)this[e]=ua[e]}const pa={};var ha=Ft({components:{"k-block-layouts":function(){return ca.exports}()},mixins:[On],inheritAttrs:!1,props:{empty:String,fieldsetGroups:Object,fieldsets:Object,layouts:{type:Array,default:()=>[["1/1"]]},settings:Object,value:{type:Array,default:()=>[]}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-layout-field"},"k-field",t.$props,!1),[n("k-block-layouts",t._b({on:{input:function(e){return t.$emit("input",e)}}},"k-block-layouts",t.$props,!1))],1)}),[],!1,fa,null,null,null);function fa(t){for(let e in pa)this[e]=pa[e]}var ma=function(){return ha.exports}();const ga={};var ka=Ft({},(function(){var t=this.$createElement;return(this._self._c||t)("hr",{staticClass:"k-line-field"})}),[],!1,va,null,null,null);function va(t){for(let e in ga)this[e]=ga[e]}var ba=function(){return ka.exports}();const ya={mixins:[On,Pn],inheritAttrs:!1,props:{marks:[Array,Boolean],value:String},methods:{focus(){this.$refs.input.focus()}}},$a={};var _a=Ft(ya,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-list-field",attrs:{input:t._uid,counter:!1}},"k-field",t.$props,!1),[n("k-input",t._b({ref:"input",attrs:{id:t._uid,marks:t.marks,value:t.value,type:"list",theme:"field"},on:{input:function(e){return t.$emit("input",e)}}},"k-input",t.$props,!1))],1)}),[],!1,xa,null,null,null);function xa(t){for(let e in $a)this[e]=$a[e]}var wa=function(){return _a.exports}();const Sa={};var Ca=Ft({mixins:[On,Pn,Xs,br],inheritAttrs:!1,props:{icon:{type:String,default:"angle-down"}},mounted(){this.$refs.input.$el.setAttribute("tabindex",0)},methods:{blur(t){this.$refs.input.blur(t)},focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-multiselect-field",attrs:{input:t._uid,counter:t.counterOptions},on:{blur:t.blur},nativeOn:{keydown:function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"enter",13,e.key,"Enter")?null:(e.preventDefault(),t.focus.apply(null,arguments))}}},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"multiselect"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,Oa,null,null,null);function Oa(t){for(let e in Sa)this[e]=Sa[e]}var Ea=function(){return Ca.exports}();const Aa={};var Ta=Ft({mixins:[On,Pn,no],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-number-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"number"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,Ia,null,null,null);function Ia(t){for(let e in Aa)this[e]=Aa[e]}var Ma=function(){return Ta.exports}();const La={};var ja=Ft({mixins:[jr],computed:{emptyProps(){return{icon:"page",text:this.empty||this.$t("field.pages.empty")}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-pages-field",scopedSlots:t._u([{key:"options",fn:function(){return[n("k-button-group",{staticClass:"k-field-options"},[t.more&&!t.disabled?n("k-button",{staticClass:"k-field-options-button",attrs:{icon:t.btnIcon,text:t.btnLabel},on:{click:t.open}}):t._e()],1)]},proxy:!0}])},"k-field",t.$props,!1),[n("k-collection",t._b({on:{empty:t.open,sort:t.onInput,sortChange:function(e){return t.$emit("change",e)}},scopedSlots:t._u([{key:"options",fn:function(e){var i=e.index;return[t.disabled?t._e():n("k-button",{attrs:{tooltip:t.$t("remove"),icon:"remove"},on:{click:function(e){return t.remove(i)}}})]}}])},"k-collection",t.collection,!1)),n("k-pages-dialog",{ref:"selector",on:{submit:t.select}})],1)}),[],!1,Da,null,null,null);function Da(t){for(let e in La)this[e]=La[e]}var Ba=function(){return ja.exports}();const Pa={};var Na=Ft({mixins:[On,Pn,ao,br],inheritAttrs:!1,props:{minlength:{type:Number,default:8},icon:{type:String,default:"key"}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-password-field",attrs:{input:t._uid,counter:t.counterOptions},scopedSlots:t._u([{key:"options",fn:function(){return[t._t("options")]},proxy:!0}],null,!0)},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"password"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,qa,null,null,null);function qa(t){for(let e in Pa)this[e]=Pa[e]}var Fa=function(){return Na.exports}();const Ra={};var za=Ft({mixins:[On,Pn,ho],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-radio-field"},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"radio"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,Ya,null,null,null);function Ya(t){for(let e in Ra)this[e]=Ra[e]}var Ha=function(){return za.exports}();const Ua={};var Ka=Ft({mixins:[Pn,On,vo],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-range-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"range"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,Ja,null,null,null);function Ja(t){for(let e in Ua)this[e]=Ua[e]}var Ga=function(){return Ka.exports}();const Va={};var Wa=Ft({mixins:[On,Pn,xo],inheritAttrs:!1,props:{icon:{type:String,default:"angle-down"}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-select-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"select"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,Xa,null,null,null);function Xa(t){for(let e in Va)this[e]=Va[e]}var Za=function(){return Wa.exports}();const Qa={mixins:[On,Pn,Eo],inheritAttrs:!1,props:{icon:{type:String,default:"url"},path:{type:String},wizard:{type:[Boolean,Object],default:!1}},data(){return{slug:this.value}},computed:{preview(){return void 0!==this.help?this.help:void 0!==this.path?this.path+this.value:null}},watch:{value(){this.slug=this.value}},methods:{focus(){this.$refs.input.focus()},onWizard(){var t;this.formData[null==(t=this.wizard)?void 0:t.field]&&(this.slug=this.formData[this.wizard.field])}}},tl={};var el=Ft(Qa,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-slug-field",attrs:{input:t._uid,help:t.preview},scopedSlots:t._u([t.wizard&&t.wizard.text?{key:"options",fn:function(){return[n("k-button",{attrs:{text:t.wizard.text,icon:"wand"},on:{click:t.onWizard}})]},proxy:!0}:null],null,!0)},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,value:t.slug,theme:"field",type:"slug"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,nl,null,null,null);function nl(t){for(let e in tl)this[e]=tl[e]}var il=function(){return el.exports}();const sl={mixins:[On],inheritAttrs:!1,props:{columns:Object,duplicate:{type:Boolean,default:!0},empty:String,fields:Object,limit:Number,max:Number,min:Number,prepend:{type:Boolean,default:!1},sortable:{type:Boolean,default:!0},sortBy:String,value:{type:Array,default:()=>[]}},data(){return{autofocus:null,items:this.toItems(this.value),currentIndex:null,currentModel:null,trash:null,page:1}},computed:{dragOptions(){return{disabled:!this.isSortable,fallbackClass:"k-sortable-row-fallback"}},form(){let t={};return Object.keys(this.fields).forEach((e=>{let n=this.fields[e];n.section=this.name,n.endpoints={field:this.endpoints.field+"+"+e,section:this.endpoints.section,model:this.endpoints.model},null===this.autofocus&&!0===n.autofocus&&(this.autofocus=e),t[e]=n})),t},index(){return this.limit?(this.page-1)*this.limit:1},more(){return!0!==this.disabled&&!(this.max&&this.items.length>=this.max)},isInvalid(){return!0!==this.disabled&&(!!(this.min&&this.items.lengththis.max))},isSortable(){return!this.sortBy&&(!this.limit&&(!0!==this.disabled&&(!(this.items.length<=1)&&!1!==this.sortable)))},pagination(){let t=0;return this.limit&&(t=(this.page-1)*this.limit),{page:this.page,offset:t,limit:this.limit,total:this.items.length,align:"center",details:!0}},options(){let t=[],e=this.duplicate&&this.more&&null===this.currentIndex;return e&&t.push({icon:"copy",text:this.$t("duplicate"),click:"duplicate"}),t.push({icon:"remove",text:e?this.$t("remove"):null,click:"remove"}),t},paginatedItems(){return this.limit?this.items.slice(this.pagination.offset,this.pagination.offset+this.limit):this.items}},watch:{value(t){t!=this.items&&(this.items=this.toItems(t))}},methods:{add(t){!0===this.prepend?this.items.unshift(t):this.items.push(t)},focus(){var t,e;null==(e=null==(t=this.$refs.add)?void 0:t.focus)||e.call(t)},jump(t,e){this.open(t+this.pagination.offset,e)},onAdd(){if(!0===this.disabled)return!1;if(null!==this.currentIndex)return this.onFormDiscard(),!1;let t={};for(const e in this.fields)t[e]=this.$helper.clone(this.fields[e].default);this.currentIndex="new",this.currentModel=t,this.onFormOpen()},onFormClose(){this.currentIndex=null,this.currentModel=null},onFormDiscard(){if("new"===this.currentIndex){if(0===Object.values(this.currentModel).filter((t=>!1===this.$helper.object.isEmpty(t))).length)return void this.onFormClose()}this.onFormSubmit()},onFormOpen(t=this.autofocus){this.$nextTick((()=>{var e;null==(e=this.$refs.form)||e.focus(t)}))},async onFormPaginate(t){await this.save(),this.open(t)},async onFormSubmit(){try{await this.save(),this.onFormClose()}catch(t){}},onInput(t=this.items){this.$emit("input",t)},onOption(t,e,n){switch(t){case"remove":this.onFormClose(),this.trash=n+this.pagination.offset,this.$refs.remove.open();break;case"duplicate":this.add(this.items[n+this.pagination.offset]),this.onInput()}},onRemove(){if(null===this.trash)return!1;this.items.splice(this.trash,1),this.trash=null,this.$refs.remove.close(),this.onInput(),0===this.paginatedItems.length&&this.page>1&&this.page--,this.items=this.sort(this.items)},open(t,e){this.currentIndex=t,this.currentModel=this.$helper.clone(this.items[t]),this.onFormOpen(e)},paginate({page:t}){this.page=t},sort(t){return this.sortBy?t.sortBy(this.sortBy):t},async save(){if(null!==this.currentIndex&&void 0!==this.currentIndex)try{return await this.validate(this.currentModel),"new"===this.currentIndex?this.add(this.currentModel):this.items[this.currentIndex]=this.currentModel,this.items=this.sort(this.items),this.onInput(),!0}catch(t){throw this.$store.dispatch("notification/error",{message:this.$t("error.form.incomplete"),details:t}),t}},toItems(t){return!1===Array.isArray(t)?[]:this.sort(t)},async validate(t){const e=await this.$api.post(this.endpoints.field+"/validate",t);if(e.length>0)throw e;return!0}}},ol={};var rl=Ft(sl,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-structure-field",nativeOn:{click:function(t){t.stopPropagation()}},scopedSlots:t._u([{key:"options",fn:function(){return[t.more&&null===t.currentIndex?n("k-button",{ref:"add",attrs:{id:t._uid,text:t.$t("add"),icon:"add"},on:{click:t.onAdd}}):t._e()]},proxy:!0}])},"k-field",t.$props,!1),[null!==t.currentIndex?n("k-structure-form",{ref:"form",attrs:{fields:t.form,index:t.currentIndex,total:t.items.length},on:{close:t.onFormClose,discard:t.onFormDiscard,paginate:function(e){return t.onFormPaginate(e.offset)},submit:t.onFormSubmit},model:{value:t.currentModel,callback:function(e){t.currentModel=e},expression:"currentModel"}}):0===t.items.length?n("k-empty",{attrs:{"data-invalid":t.isInvalid,icon:"list-bullet"},on:{click:t.onAdd}},[t._v(" "+t._s(t.empty||t.$t("field.structure.empty"))+" ")]):[n("k-table",{attrs:{columns:t.columns,disabled:t.disabled,fields:t.fields,empty:t.$t("field.structure.empty"),index:t.index,options:t.options,rows:t.paginatedItems,sortable:t.isSortable,"data-invalid":t.isInvalid},on:{cell:function(e){return t.jump(e.rowIndex,e.columnIndex)},input:t.onInput,option:t.onOption}}),t.limit?n("k-pagination",t._b({on:{paginate:t.paginate}},"k-pagination",t.pagination,!1)):t._e(),t.disabled?t._e():n("k-dialog",{ref:"remove",attrs:{"submit-button":t.$t("delete"),theme:"negative"},on:{submit:t.onRemove}},[n("k-text",[t._v(t._s(t.$t("field.structure.delete.confirm")))])],1)]],2)}),[],!1,al,null,null,null);function al(t){for(let e in ol)this[e]=ol[e]}var ll=function(){return rl.exports}();const ul={};var cl=Ft({mixins:[On,Pn,Lo,br],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-tags-field",attrs:{input:t._uid,counter:t.counterOptions}},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"tags"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,dl,null,null,null);function dl(t){for(let e in ul)this[e]=ul[e]}var pl=function(){return cl.exports}();const hl={};var fl=Ft({mixins:[On,Pn,No],inheritAttrs:!1,props:{icon:{type:String,default:"phone"}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-tel-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"tel"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,ml,null,null,null);function ml(t){for(let e in hl)this[e]=hl[e]}var gl=function(){return fl.exports}();const kl={};var vl=Ft({mixins:[On,Pn,Ds,br],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()},select(){this.$refs.input.select()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-text-field",attrs:{input:t._uid,counter:t.counterOptions},scopedSlots:t._u([{key:"options",fn:function(){return[t._t("options")]},proxy:!0}],null,!0)},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,bl,null,null,null);function bl(t){for(let e in kl)this[e]=kl[e]}var yl=function(){return vl.exports}();const $l={};var _l=Ft({mixins:[On,Pn,Yo,br],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-textarea-field",attrs:{input:t._uid,counter:t.counterOptions}},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,type:"textarea",theme:"field"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,xl,null,null,null);function xl(t){for(let e in $l)this[e]=$l[e]}var wl=function(){return _l.exports}();const Sl={mixins:[On,Pn,Go],inheritAttrs:!1,props:{icon:{type:String,default:"clock"},times:{type:Boolean,default:!0}},methods:{focus(){this.$refs.input.focus()},select(t){var e;this.$emit("input",t),null==(e=this.$refs.times)||e.close()}}},Cl={};var Ol=Ft(Sl,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-time-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[n("k-input",t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"time"},on:{input:function(e){return t.$emit("input",e||"")}},scopedSlots:t._u([t.times?{key:"icon",fn:function(){return[n("k-dropdown",[n("k-button",{staticClass:"k-input-icon-button",attrs:{icon:t.icon||"clock",tooltip:t.$t("time.select")},on:{click:function(e){return t.$refs.times.toggle()}}}),n("k-dropdown-content",{ref:"times",attrs:{align:"right"}},[n("k-times",{attrs:{display:t.display,value:t.value},on:{input:t.select}})],1)],1)]},proxy:!0}:null],null,!0)},"k-input",t.$props,!1))],1)}),[],!1,El,null,null,null);function El(t){for(let e in Cl)this[e]=Cl[e]}var Al=function(){return Ol.exports}();const Tl={};var Il=Ft({mixins:[On,Pn,Qo],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-toggle-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"toggle"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,Ml,null,null,null);function Ml(t){for(let e in Tl)this[e]=Tl[e]}var Ll=function(){return Il.exports}();const jl={};var Dl=Ft({inheritAttrs:!1,mixins:[On,Pn,sr],methods:{focus(){this.$refs.input.focus()},onInput(t){this.$emit("input",t)}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-toggles-field"},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",class:{grow:t.grow},attrs:{id:t._uid,theme:"field",type:"toggles"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,Bl,null,null,null);function Bl(t){for(let e in jl)this[e]=jl[e]}var Pl=function(){return Dl.exports}();const Nl={mixins:[On,Pn,ur],inheritAttrs:!1,props:{link:{type:Boolean,default:!0},icon:{type:String,default:"url"}},methods:{focus(){this.$refs.input.focus()}}},ql={};var Fl=Ft(Nl,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-url-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[n("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"url"},scopedSlots:t._u([{key:"icon",fn:function(){return[t.link?n("k-button",{staticClass:"k-input-icon-button",attrs:{icon:t.icon,link:t.value,tooltip:t.$t("open"),tabindex:"-1",target:"_blank"}}):t._e()]},proxy:!0}])},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,Rl,null,null,null);function Rl(t){for(let e in ql)this[e]=ql[e]}var zl=function(){return Fl.exports}();const Yl={};var Hl=Ft({mixins:[jr],computed:{emptyProps(){return{icon:"users",text:this.empty||this.$t("field.users.empty")}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-users-field",scopedSlots:t._u([{key:"options",fn:function(){return[n("k-button-group",{staticClass:"k-field-options"},[t.more&&!t.disabled?n("k-button",{staticClass:"k-field-options-button",attrs:{icon:t.btnIcon,text:t.btnLabel},on:{click:t.open}}):t._e()],1)]},proxy:!0}])},"k-field",t.$props,!1),[n("k-collection",t._b({on:{empty:t.open,sort:t.onInput,sortChange:function(e){return t.$emit("change",e)}},scopedSlots:t._u([{key:"options",fn:function(e){var i=e.index;return[t.disabled?t._e():n("k-button",{attrs:{tooltip:t.$t("remove"),icon:"remove"},on:{click:function(e){return t.remove(i)}}})]}}])},"k-collection",t.collection,!1)),n("k-users-dialog",{ref:"selector",on:{submit:t.select}})],1)}),[],!1,Ul,null,null,null);function Ul(t){for(let e in Yl)this[e]=Yl[e]}var Kl=function(){return Hl.exports}();const Jl={};var Gl=Ft({mixins:[On,Pn,Ji],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-field",t._b({staticClass:"k-writer-field",attrs:{input:t._uid,counter:!1}},"k-field",t.$props,!1),[n("k-input",t._b({attrs:{after:t.after,before:t.before,icon:t.icon,theme:"field"}},"k-input",t.$props,!1),[n("k-writer",t._b({ref:"input",staticClass:"k-writer-field-input",attrs:{value:t.value},on:{input:function(e){return t.$emit("input",e)}}},"k-writer",t.$props,!1))],1)],1)}),[],!1,Vl,null,null,null);function Vl(t){for(let e in Jl)this[e]=Jl[e]}var Wl=function(){return Gl.exports}();u.component("k-blocks-field",vr),u.component("k-checkboxes-field",xr),u.component("k-date-field",Er),u.component("k-email-field",Lr),u.component("k-files-field",qr),u.component("k-gap-field",Yr),u.component("k-headline-field",Gr),u.component("k-info-field",Zr),u.component("k-layout-field",ma),u.component("k-line-field",ba),u.component("k-list-field",wa),u.component("k-multiselect-field",Ea),u.component("k-number-field",Ma),u.component("k-pages-field",Ba),u.component("k-password-field",Fa),u.component("k-radio-field",Ha),u.component("k-range-field",Ga),u.component("k-select-field",Za),u.component("k-slug-field",il),u.component("k-structure-field",ll),u.component("k-tags-field",pl),u.component("k-text-field",yl),u.component("k-textarea-field",wl),u.component("k-tel-field",gl),u.component("k-time-field",Al),u.component("k-toggle-field",Ll),u.component("k-toggles-field",Pl),u.component("k-url-field",zl),u.component("k-users-field",Kl),u.component("k-writer-field",Wl);const Xl={props:{cover:Boolean,ratio:String},computed:{ratioPadding(){return this.$helper.ratio(this.ratio)}}},Zl={};var Ql=Ft(Xl,(function(){var t=this,e=t.$createElement;return(t._self._c||e)("span",{staticClass:"k-aspect-ratio",style:{"padding-bottom":t.ratioPadding},attrs:{"data-cover":t.cover}},[t._t("default")],2)}),[],!1,tu,null,null,null);function tu(t){for(let e in Zl)this[e]=Zl[e]}var eu=function(){return Ql.exports}();const nu={};var iu=Ft({},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-bar"},[t.$slots.left?n("div",{staticClass:"k-bar-slot",attrs:{"data-position":"left"}},[t._t("left")],2):t._e(),t.$slots.center?n("div",{staticClass:"k-bar-slot",attrs:{"data-position":"center"}},[t._t("center")],2):t._e(),t.$slots.right?n("div",{staticClass:"k-bar-slot",attrs:{"data-position":"right"}},[t._t("right")],2):t._e()])}),[],!1,su,null,null,null);function su(t){for(let e in nu)this[e]=nu[e]}var ou=function(){return iu.exports}();const ru={props:{theme:{type:String,default:"none"},text:String,html:{type:Boolean,default:!1}}},au={};var lu=Ft(ru,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",t._g({staticClass:"k-box",attrs:{"data-theme":t.theme}},t.$listeners),[t._t("default",(function(){return[t.html?n("k-text",{domProps:{innerHTML:t._s(t.text)}}):n("k-text",[t._v(" "+t._s(t.text)+" ")])]}))],2)}),[],!1,uu,null,null,null);function uu(t){for(let e in au)this[e]=au[e]}var cu=function(){return lu.exports}();const du={};var pu=Ft({inheritAttrs:!1,props:{back:String,color:String,element:{type:String,default:"li"},image:Object,link:String,text:String}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n(t.link?"k-link":"p",{tag:"component",staticClass:"k-bubble",style:{color:t.$helper.color(t.color),background:t.$helper.color(t.back)},attrs:{to:t.link},nativeOn:{click:function(t){t.stopPropagation()}}},[t.image?n("k-item-image",{attrs:{image:t.image,layout:"list"}}):t._e(),t._v(" "+t._s(t.text)+" ")],1)}),[],!1,hu,null,null,null);function hu(t){for(let e in du)this[e]=du[e]}var fu=function(){return pu.exports}();const mu={};var gu=Ft({inheritAttrs:!1,props:{bubbles:Array},computed:{items(){let t=this.bubbles;return"string"==typeof t&&(t=t.split(",")),t.map((t=>"string"==typeof t?{text:t}:t))}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("ul",{staticClass:"k-bubbles"},t._l(t.items,(function(e,i){return n("li",{key:i},[n("k-bubble",t._b({},"k-bubble",e,!1))],1)})),0)}),[],!1,ku,null,null,null);function ku(t){for(let e in mu)this[e]=mu[e]}var vu=function(){return gu.exports}();const bu={props:{columns:{type:[Object,Array],default:()=>({})},empty:Object,help:String,items:{type:[Array,Object],default:()=>[]},layout:{type:String,default:"list"},link:{type:Boolean,default:!0},size:String,sortable:Boolean,pagination:{type:[Boolean,Object],default:()=>!1}},computed:{hasPagination(){return!1!==this.pagination&&(!0!==this.paginationOptions.hide&&!(this.pagination.total<=this.pagination.limit))},hasFooter(){return!(!this.hasPagination&&!this.help)},paginationOptions(){const t="object"!=typeof this.pagination?{}:this.pagination;return a({limit:10,details:!0,keys:!1,total:0,hide:!1},t)}},watch:{$props(){this.$forceUpdate()}},methods:{onEmpty(t){t.stopPropagation(),this.$emit("empty")},onOption(...t){this.$emit("action",...t),this.$emit("option",...t)}}},yu={};var $u=Ft(bu,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-collection"},[t.items.length?n("k-items",{attrs:{columns:t.columns,items:t.items,layout:t.layout,link:t.link,size:t.size,sortable:t.sortable},on:{change:function(e){return t.$emit("change",e)},item:function(e){return t.$emit("item",e)},option:t.onOption,sort:function(e){return t.$emit("sort",e)}},scopedSlots:t._u([{key:"options",fn:function(e){var n=e.item,i=e.itemIndex;return[t._t("options",null,null,{item:n,index:i})]}}],null,!0)}):n("k-empty",t._g(t._b({attrs:{layout:t.layout}},"k-empty",t.empty,!1),t.$listeners.empty?{click:t.onEmpty}:{})),t.hasFooter?n("footer",{staticClass:"k-collection-footer"},[t.help?n("k-text",{staticClass:"k-collection-help",attrs:{theme:"help"},domProps:{innerHTML:t._s(t.help)}}):t._e(),n("div",{staticClass:"k-collection-pagination"},[t.hasPagination?n("k-pagination",t._b({on:{paginate:function(e){return t.$emit("paginate",e)}}},"k-pagination",t.paginationOptions,!1)):t._e()],1)],1):t._e()],1)}),[],!1,_u,null,null,null);function _u(t){for(let e in yu)this[e]=yu[e]}var xu=function(){return $u.exports}();const wu={props:{width:String,sticky:Boolean}},Su={};var Cu=Ft(wu,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-column",attrs:{"data-width":t.width,"data-sticky":t.sticky}},[n("div",[t._t("default")],2)])}),[],!1,Ou,null,null,null);function Ou(t){for(let e in Su)this[e]=Su[e]}var Eu=function(){return Cu.exports}();const Au={props:{disabled:{type:Boolean,default:!1}},data:()=>({files:[],dragging:!1,over:!1}),methods:{cancel(){this.reset()},reset(){this.dragging=!1,this.over=!1},onDrop(t){return!0===this.disabled||!1===this.$helper.isUploadEvent(t)?this.reset():(this.$events.$emit("dropzone.drop"),this.files=t.dataTransfer.files,this.$emit("drop",this.files),void this.reset())},onEnter(t){!1===this.disabled&&this.$helper.isUploadEvent(t)&&(this.dragging=!0)},onLeave(){this.reset()},onOver(t){!1===this.disabled&&this.$helper.isUploadEvent(t)&&(t.dataTransfer.dropEffect="copy",this.over=!0)}}},Tu={};var Iu=Ft(Au,(function(){var t=this,e=t.$createElement;return(t._self._c||e)("div",{staticClass:"k-dropzone",attrs:{"data-dragging":t.dragging,"data-over":t.over},on:{dragenter:t.onEnter,dragleave:t.onLeave,dragover:t.onOver,drop:t.onDrop}},[t._t("default")],2)}),[],!1,Mu,null,null,null);function Mu(t){for(let e in Tu)this[e]=Tu[e]}var Lu=function(){return Iu.exports}();const ju={};var Du=Ft({props:{text:String,icon:String,layout:{type:String,default:"list"}},computed:{element(){return void 0!==this.$listeners.click?"button":"div"}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n(t.element,t._g({tag:"component",staticClass:"k-empty",attrs:{"data-layout":t.layout,type:"button"===t.element&&"button"}},t.$listeners),[t.icon?n("k-icon",{attrs:{type:t.icon}}):t._e(),n("p",[t._t("default",(function(){return[t._v(t._s(t.text))]}))],2)],1)}),[],!1,Bu,null,null,null);function Bu(t){for(let e in ju)this[e]=ju[e]}var Pu=function(){return Du.exports}();const Nu={};var qu=Ft({props:{details:Array,image:Object,url:String}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-file-preview"},[n("k-view",{staticClass:"k-file-preview-layout"},[n("div",{staticClass:"k-file-preview-image"},[n("k-link",{staticClass:"k-file-preview-image-link",attrs:{to:t.url,title:t.$t("open"),target:"_blank"}},[n("k-item-image",{attrs:{image:t.image,layout:"cards"}})],1)],1),n("div",{staticClass:"k-file-preview-details"},[n("ul",t._l(t.details,(function(e){return n("li",{key:e.title},[n("h3",[t._v(t._s(e.title))]),n("p",[e.link?n("k-link",{attrs:{to:e.link,tabindex:"-1",target:"_blank"}},[t._v(" /"+t._s(e.text)+" ")]):[t._v(" "+t._s(e.text)+" ")]],2)])})),0)])])],1)}),[],!1,Fu,null,null,null);function Fu(t){for(let e in Nu)this[e]=Nu[e]}var Ru=function(){return qu.exports}();const zu={};var Yu=Ft({props:{gutter:String}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("div",{staticClass:"k-grid",attrs:{"data-gutter":t.gutter}},[t._t("default")],2)}),[],!1,Hu,null,null,null);function Hu(t){for(let e in zu)this[e]=zu[e]}var Uu=function(){return Yu.exports}();const Ku={props:{editable:Boolean,tab:String,tabs:{type:Array,default:()=>[]}},computed:{tabsWithBadges(){const t=Object.keys(this.$store.getters["content/changes"]());return this.tabs.map((e=>{let n=[];return Object.values(e.columns).forEach((t=>{Object.values(t.sections).forEach((t=>{"fields"===t.type&&Object.keys(t.fields).forEach((t=>{n.push(t)}))}))})),e.badge=n.filter((e=>t.includes(e.toLowerCase()))).length,e}))}}},Ju={};var Gu=Ft(Ku,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("header",{staticClass:"k-header",attrs:{"data-editable":t.editable,"data-tabs":t.tabsWithBadges.length>1}},[n("k-headline",{attrs:{tag:"h1",size:"huge"}},[t.editable&&t.$listeners.edit?n("span",{staticClass:"k-headline-editable",on:{click:function(e){return t.$emit("edit")}}},[t._t("default"),n("k-icon",{attrs:{type:"edit"}})],2):t._t("default")],2),t.$slots.left||t.$slots.right?n("k-bar",{staticClass:"k-header-buttons",scopedSlots:t._u([{key:"left",fn:function(){return[t._t("left")]},proxy:!0},{key:"right",fn:function(){return[t._t("right")]},proxy:!0}],null,!0)}):t._e(),n("k-tabs",{attrs:{tab:t.tab,tabs:t.tabsWithBadges,theme:"notice"}})],1)}),[],!1,Vu,null,null,null);function Vu(t){for(let e in Ju)this[e]=Ju[e]}var Wu=function(){return Gu.exports}();const Xu={};var Zu=Ft({inheritAttrs:!1},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-panel",{staticClass:"k-panel-inside",attrs:{tabindex:"0"}},[n("header",{staticClass:"k-panel-header"},[n("k-topbar",{attrs:{breadcrumb:t.$view.breadcrumb,license:t.$license,menu:t.$menu,view:t.$view}})],1),n("main",{staticClass:"k-panel-view scroll-y"},[t._t("default")],2),t._t("footer")],2)}),[],!1,Qu,null,null,null);function Qu(t){for(let e in Xu)this[e]=Xu[e]}var tc=function(){return Zu.exports}(),ec=function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("article",t._b({staticClass:"k-item",class:!!t.layout&&"k-"+t.layout+"-item",attrs:{"data-has-figure":t.hasFigure,"data-has-flag":Boolean(t.flag),"data-has-info":Boolean(t.info),"data-has-options":Boolean(t.options),tabindex:"-1"},on:{click:function(e){return t.$emit("click",e)},dragstart:function(e){return t.$emit("drag",e)}}},"article",t.data,!1),[t._t("image",(function(){return[t.hasFigure?n("k-item-image",{attrs:{image:t.image,layout:t.layout,width:t.width}}):t._e()]})),t.sortable?n("k-sort-handle",{staticClass:"k-item-sort-handle"}):t._e(),n("header",{staticClass:"k-item-content"},[t._t("default",(function(){return[n("h3",{staticClass:"k-item-title"},[!1!==t.link?n("k-link",{staticClass:"k-item-title-link",attrs:{target:t.target,to:t.link}},[n("span",{domProps:{innerHTML:t._s(t.title)}})]):n("span",{domProps:{innerHTML:t._s(t.title)}})],1),t.info?n("p",{staticClass:"k-item-info",domProps:{innerHTML:t._s(t.info)}}):t._e()]}))],2),t.flag||t.options||t.$slots.options?n("footer",{staticClass:"k-item-footer"},[n("nav",{staticClass:"k-item-buttons",on:{click:function(t){t.stopPropagation()}}},[t.flag?n("k-status-icon",t._b({},"k-status-icon",t.flag,!1)):t._e(),t._t("options",(function(){return[t.options?n("k-options-dropdown",{staticClass:"k-item-options-dropdown",attrs:{options:t.options},on:{option:t.onOption}}):t._e()]}))],2)]):t._e()],2)};const nc={inheritAttrs:!1,props:{data:Object,flag:Object,image:[Object,Boolean],info:String,layout:{type:String,default:"list"},link:{type:[Boolean,String,Function]},options:{type:[Array,Function,String]},sortable:Boolean,target:String,text:String,width:String},computed:{hasFigure(){return!1!==this.image&&Object.keys(this.image).length>0},title(){return this.text||"-"}},methods:{onOption(t){this.$emit("action",t),this.$emit("option",t)}}},ic={};var sc=Ft(nc,ec,[],!1,oc,null,null,null);function oc(t){for(let e in ic)this[e]=ic[e]}var rc=function(){return sc.exports}();const ac={inheritAttrs:!1,props:{image:[Object,Boolean],layout:{type:String,default:"list"},width:String},computed:{back(){return this.image.back||"black"},ratio(){return"cards"===this.layout&&this.image.ratio||"1/1"},size(){switch(this.layout){case"cards":return"large";case"cardlets":return"medium";default:return"regular"}},sizes(){switch(this.width){case"1/2":case"2/4":return"(min-width: 30em) and (max-width: 65em) 59em, (min-width: 65em) 44em, 27em";case"1/3":return"(min-width: 30em) and (max-width: 65em) 59em, (min-width: 65em) 29.333em, 27em";case"1/4":return"(min-width: 30em) and (max-width: 65em) 59em, (min-width: 65em) 22em, 27em";case"2/3":return"(min-width: 30em) and (max-width: 65em) 59em, (min-width: 65em) 27em, 27em";case"3/4":return"(min-width: 30em) and (max-width: 65em) 59em, (min-width: 65em) 66em, 27em";default:return"(min-width: 30em) and (max-width: 65em) 59em, (min-width: 65em) 88em, 27em"}}}},lc={};var uc=Ft(ac,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return t.image?n("div",{staticClass:"k-item-figure",style:{background:t.$helper.color(t.back)}},[t.image.src?n("k-image",{staticClass:"k-item-image",attrs:{cover:t.image.cover,ratio:t.ratio,sizes:t.sizes,src:t.image.src,srcset:t.image.srcset}}):n("k-aspect-ratio",{attrs:{ratio:t.ratio}},[n("k-icon",{staticClass:"k-item-icon",attrs:{color:t.$helper.color(t.image.color),type:t.image.icon}})],1)],1):t._e()}),[],!1,cc,null,null,null);function cc(t){for(let e in lc)this[e]=lc[e]}var dc=function(){return uc.exports}();const pc={inheritAttrs:!1,props:{columns:{type:[Object,Array],default:()=>({})},items:{type:Array,default:()=>[]},layout:{type:String,default:"list"},link:{type:Boolean,default:!0},image:{type:[Object,Boolean],default:()=>({})},sortable:Boolean,empty:{type:[String,Object]},size:{type:String,default:"default"}},computed:{dragOptions(){return{sort:this.sortable,disabled:!1===this.sortable,draggable:".k-draggable-item"}},table(){return{columns:this.columns,rows:this.items,sortable:this.sortable}}},methods:{onDragStart(t,e){this.$store.dispatch("drag",{type:"text",data:e})},onOption(t,e,n){this.$emit("option",t,e,n)},imageOptions(t){let e=this.image,n=t.image;return!1!==e&&!1!==n&&("object"!=typeof e&&(e={}),"object"!=typeof n&&(n={}),a(a({},n),e))}}},hc={};var fc=Ft(pc,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return"table"===t.layout?n("k-table",t._b({on:{change:function(e){return t.$emit("change",e)},sort:function(e){return t.$emit("sort",e)},option:t.onOption}},"k-table",t.table,!1)):n("k-draggable",{staticClass:"k-items",class:"k-"+t.layout+"-items",attrs:{handle:!0,options:t.dragOptions,"data-layout":t.layout,"data-size":t.size,list:t.items},on:{change:function(e){return t.$emit("change",e)},end:function(e){return t.$emit("sort",t.items,e)}}},t._l(t.items,(function(e,i){return n("k-item",t._b({key:e.id||i,class:{"k-draggable-item":t.sortable&&e.sortable},attrs:{image:t.imageOptions(e),layout:t.layout,link:!!t.link&&e.link,sortable:t.sortable&&e.sortable,width:e.column},on:{click:function(n){return t.$emit("item",e,i)},drag:function(n){return t.onDragStart(n,e.dragText)},option:function(n){return t.onOption(n,e,i)}},nativeOn:{mouseover:function(n){return t.$emit("hover",n,e,i)}},scopedSlots:t._u([{key:"options",fn:function(){return[t._t("options",null,null,{item:e,itemIndex:i})]},proxy:!0}],null,!0)},"k-item",e,!1))})),1)}),[],!1,mc,null,null,null);function mc(t){for(let e in hc)this[e]=hc[e]}var gc=function(){return fc.exports}();const kc={inheritAttrs:!0,props:{autofocus:{type:Boolean,default:!0},centered:{type:Boolean,default:!1},dimmed:{type:Boolean,default:!0},loading:{type:Boolean,default:!1}},data:()=>({isOpen:!1,scrollTop:0}),methods:{close(){!1!==this.isOpen&&(this.isOpen=!1,this.$emit("close"),this.restoreScrollPosition(),this.$events.$off("keydown.esc",this.close))},focus(){var t,e;let n=this.$refs.overlay.querySelector("\n [autofocus],\n [data-autofocus]\n ");return null===n&&(n=this.$refs.overlay.querySelector("\n input,\n textarea,\n select,\n button\n ")),"function"==typeof(null==n?void 0:n.focus)?n.focus():"function"==typeof(null==(e=null==(t=this.$slots.default[0])?void 0:t.context)?void 0:e.focus)?this.$slots.default[0].context.focus():void 0},open(){!0!==this.isOpen&&(this.storeScrollPosition(),this.isOpen=!0,this.$emit("open"),this.$events.$on("keydown.esc",this.close),setTimeout((()=>{!0===this.autofocus&&this.focus(),document.querySelector(".k-overlay > *").addEventListener("mousedown",(t=>t.stopPropagation())),this.$emit("ready")}),1))},restoreScrollPosition(){const t=document.querySelector(".k-panel-view");(null==t?void 0:t.scrollTop)&&(t.scrollTop=this.scrollTop)},storeScrollPosition(){const t=document.querySelector(".k-panel-view");(null==t?void 0:t.scrollTop)?this.scrollTop=t.scrollTop:this.scrollTop=0}}},vc={};var bc=Ft(kc,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return t.isOpen?n("portal",[n("div",t._g({ref:"overlay",staticClass:"k-overlay",class:t.$vnode.data.staticClass,attrs:{"data-centered":t.loading||t.centered,"data-dimmed":t.dimmed,"data-loading":t.loading,dir:t.$translation.direction},on:{mousedown:t.close}},t.$listeners),[t.loading?n("k-loader",{staticClass:"k-overlay-loader"}):t._t("default",null,{close:t.close,isOpen:t.isOpen})],2)]):t._e()}),[],!1,yc,null,null,null);function yc(t){for(let e in vc)this[e]=vc[e]}var $c=function(){return bc.exports}();const _c={};var xc=Ft({computed:{defaultLanguage(){return!!this.$language&&this.$language.default},dialog(){return this.$helper.clone(this.$store.state.dialog)},language(){return this.$language?this.$language.code:null},role(){return this.$user?this.$user.role:null},user(){return this.$user?this.$user.id:null}},created(){this.$events.$on("drop",this.drop)},destroyed(){this.$events.$off("drop",this.drop)},methods:{drop(){this.$store.dispatch("drag",null)}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-panel",attrs:{"data-dragging":t.$store.state.drag,"data-loading":t.$store.state.isLoading,"data-language":t.language,"data-language-default":t.defaultLanguage,"data-role":t.role,"data-translation":t.$translation.code,"data-user":t.user,dir:t.$translation.direction}},[t._t("default"),t.$store.state.dialog&&t.$store.state.dialog.props?[n("k-fiber-dialog",t._b({},"k-fiber-dialog",t.dialog,!1))]:t._e(),!1!==t.$store.state.fatal?n("k-fatal",{attrs:{html:t.$store.state.fatal}}):t._e(),!1===t.$system.isLocal?n("k-offline-warning"):t._e(),n("k-icons")],2)}),[],!1,wc,null,null,null);function wc(t){for(let e in _c)this[e]=_c[e]}var Sc=function(){return xc.exports}();const Cc={};var Oc=Ft({props:{reports:Array,size:{type:String,default:"large"}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("dl",{staticClass:"k-stats",attrs:{"data-size":t.size}},t._l(t.reports,(function(e,i){return n(e.link?"k-link":"div",{key:i,tag:"component",staticClass:"k-stat",attrs:{"data-theme":e.theme,"data-click":!!e.click,to:e.link},on:{click:function(t){e.click&&e.click()}}},[n("dt",{staticClass:"k-stat-label"},[t._v(t._s(e.label))]),n("dd",{staticClass:"k-stat-value"},[t._v(t._s(e.value))]),n("dd",{staticClass:"k-stat-info"},[t._v(t._s(e.info))])])})),1)}),[],!1,Ec,null,null,null);function Ec(t){for(let e in Cc)this[e]=Cc[e]}var Ac=function(){return Oc.exports}();const Tc={inheritAttrs:!1,props:{columns:Object,disabled:Boolean,fields:{type:Object,default:()=>({})},empty:String,index:{type:[Number,Boolean],default:1},rows:Array,options:[Array,Function],sortable:Boolean},data(){return{values:this.rows}},computed:{columnsCount(){return Object.keys(this.columns).length},dragOptions(){return{disabled:!this.sortable,fallbackClass:"k-table-row-fallback",ghostClass:"k-table-row-ghost"}},hasIndexColumn(){return this.sortable||!1!==this.index},hasOptions(){return this.options||Object.values(this.values).filter((t=>t.options)).length>0}},watch:{rows(){this.values=this.rows}},methods:{isColumnEmpty(t){return 0===this.rows.filter((e=>!1===this.$helper.object.isEmpty(e[t]))).length},label(t,e){return t.label||this.$helper.string.ucfirst(e)},onChange(t){this.$emit("change",t)},onCell(t){this.$emit("cell",t)},onCellUpdate({columnIndex:t,rowIndex:e,value:n}){this.values[e][t]=n,this.$emit("input",this.values)},onHeader(t){this.$emit("header",t)},onOption(t,e,n){this.$emit("option",t,e,n)},onSort(){this.$emit("input",this.values),this.$emit("sort",this.values)},width(t){return"string"!=typeof t?"auto":!1===t.includes("/")?t:this.$helper.ratio(t,"auto",!1)}}},Ic={};var Mc=Ft(Tc,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("table",{staticClass:"k-table",attrs:{"data-disabled":t.disabled,"data-indexed":t.hasIndexColumn}},[n("thead",[n("tr",[t.hasIndexColumn?n("th",{staticClass:"k-table-index-column",attrs:{"data-mobile":""}},[t._v(" # ")]):t._e(),t._l(t.columns,(function(e,i){return n("th",{key:i+"-header",staticClass:"k-table-column",style:"width:"+t.width(e.width),attrs:{"data-mobile":e.mobile},on:{click:function(n){return t.onHeader({column:e,columnIndex:i})}}},[t._t("header",(function(){return[t._v(" "+t._s(t.label(e,i))+" ")]}),null,{column:e,columnIndex:i,label:t.label(e,i)})],2)})),t.hasOptions?n("th",{staticClass:"k-table-options-column",attrs:{"data-mobile":""}}):t._e()],2)]),n("k-draggable",{attrs:{list:t.values,options:t.dragOptions,handle:!0,element:"tbody"},on:{change:t.onChange,end:t.onSort}},[0===t.rows.length?n("tr",[n("td",{staticClass:"k-table-empty",attrs:{colspan:t.columnsCount}},[t._v(" "+t._s(t.empty)+" ")])]):t._l(t.values,(function(e,i){return n("tr",{key:i},[t.hasIndexColumn?n("td",{staticClass:"k-table-index-column",attrs:{"data-sortable":t.sortable&&!1!==e.sortable,"data-mobile":""}},[t._t("index",(function(){return[n("div",{staticClass:"k-table-index",domProps:{textContent:t._s(t.index+i)}})]}),null,{row:e,rowIndex:i}),t.sortable&&!1!==e.sortable?n("k-sort-handle",{staticClass:"k-table-sort-handle"}):t._e()],2):t._e(),t._l(t.columns,(function(s,o){return n("k-table-cell",{key:i+"-"+o,staticClass:"k-table-column",style:"width:"+t.width(s.width),attrs:{column:s,field:t.fields[o],row:e,mobile:s.mobile,value:e[o]},on:{input:function(e){return t.onCellUpdate({columnIndex:o,rowIndex:i,value:e})}},nativeOn:{click:function(n){return t.onCell({row:e,rowIndex:i,column:s,columnIndex:o})}}})})),t.hasOptions?n("td",{staticClass:"k-table-options-column",attrs:{"data-mobile":""}},[t._t("options",(function(){return[n("k-options-dropdown",{attrs:{options:e.options||t.options,text:(e.options||t.options).length>1},on:{option:function(n){return t.onOption(n,e,i)}}})]}),null,{row:e,rowIndex:i,options:t.options})],2):t._e()],2)}))],2)],1)}),[],!1,Lc,null,null,null);function Lc(t){for(let e in Ic)this[e]=Ic[e]}var jc=function(){return Mc.exports}();const Dc={inheritAttrs:!1,props:{column:Object,field:Object,mobile:{type:Boolean,default:!1},row:Object,value:{default:""}},computed:{component(){return this.$helper.isComponent(`k-${this.type}-field-preview`)?`k-${this.type}-field-preview`:this.$helper.isComponent(`k-table-${this.type}-cell`)?`k-table-${this.type}-cell`:Array.isArray(this.value)?"k-array-field-preview":"k-text-field-preview"},type(){var t;return this.column.type||(null==(t=this.field)?void 0:t.type)}}},Bc={};var Pc=Ft(Dc,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("td",{attrs:{"data-align":t.column.align,"data-mobile":t.mobile}},[!1===t.$helper.object.isEmpty(t.value)?[n(t.component,{tag:"component",attrs:{column:t.column,field:t.field,row:t.row,value:t.value},on:{input:function(e){return t.$emit("input",e)}}})]:t._e()],2)}),[],!1,Nc,null,null,null);function Nc(t){for(let e in Bc)this[e]=Bc[e]}var qc=function(){return Pc.exports}();const Fc={};var Rc=Ft({props:{tab:String,tabs:Array,theme:String},data(){return{size:null,visibleTabs:this.tabs,invisibleTabs:[]}},computed:{current(){return(this.tabs.find((t=>t.name===this.tab))||this.tabs[0]||{}).name}},watch:{tabs:{handler(t){this.visibleTabs=t,this.invisibleTabs=[],this.resize(!0)},immediate:!0}},created(){window.addEventListener("resize",this.resize)},destroyed(){window.removeEventListener("resize",this.resize)},methods:{resize(t){if(this.tabs&&!(this.tabs.length<=1)){if(this.tabs.length<=3)return this.visibleTabs=this.tabs,void(this.invisibleTabs=[]);if(window.innerWidth>=700){if("large"===this.size&&!t)return;this.visibleTabs=this.tabs,this.invisibleTabs=[],this.size="large"}else{if("small"===this.size&&!t)return;this.visibleTabs=this.tabs.slice(0,2),this.invisibleTabs=this.tabs.slice(2),this.size="small"}}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return t.tabs&&t.tabs.length>1?n("div",{staticClass:"k-tabs",attrs:{"data-theme":t.theme}},[n("nav",[t._l(t.visibleTabs,(function(e){return n("k-button",{key:e.name,staticClass:"k-tab-button",attrs:{link:e.link,current:t.current===e.name,icon:e.icon,tooltip:e.label}},[t._v(" "+t._s(e.label||e.text||e.name)+" "),e.badge?n("span",{staticClass:"k-tabs-badge"},[t._v(" "+t._s(e.badge)+" ")]):t._e()])})),t.invisibleTabs.length?n("k-button",{staticClass:"k-tab-button k-tabs-dropdown-button",attrs:{text:t.$t("more"),icon:"dots"},on:{click:function(e){return e.stopPropagation(),t.$refs.more.toggle()}}}):t._e()],2),t.invisibleTabs.length?n("k-dropdown-content",{ref:"more",staticClass:"k-tabs-dropdown",attrs:{align:"right"}},t._l(t.invisibleTabs,(function(e){return n("k-dropdown-item",{key:"more-"+e.name,attrs:{link:e.link,current:t.tab===e.name,icon:e.icon,tooltip:e.label}},[t._v(" "+t._s(e.label||e.text||e.name)+" ")])})),1):t._e()],1):t._e()}),[],!1,zc,null,null,null);function zc(t){for(let e in Fc)this[e]=Fc[e]}var Yc=function(){return Rc.exports}();const Hc={};var Uc=Ft({props:{align:String}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("div",{staticClass:"k-view",attrs:{"data-align":t.align}},[t._t("default")],2)}),[],!1,Kc,null,null,null);function Kc(t){for(let e in Hc)this[e]=Hc[e]}var Jc=function(){return Uc.exports}();const Gc={components:{draggable:J},props:{data:Object,element:String,handle:[String,Boolean],list:[Array,Object],move:Function,options:Object},data(){return{listeners:l(a({},this.$listeners),{start:t=>{this.$store.dispatch("drag",{}),this.$listeners.start&&this.$listeners.start(t)},end:t=>{this.$store.dispatch("drag",null),this.$listeners.end&&this.$listeners.end(t)}})}},computed:{dragOptions(){let t=!1;return t=!0===this.handle?".k-sort-handle":this.handle,a({fallbackClass:"k-sortable-fallback",fallbackOnBody:!0,forceFallback:!0,ghostClass:"k-sortable-ghost",handle:t,scroll:document.querySelector(".k-panel-view")},this.options)}}},Vc={};var Wc=Ft(Gc,(function(){var t=this,e=t.$createElement;return(t._self._c||e)("draggable",t._g(t._b({staticClass:"k-draggable",attrs:{"component-data":t.data,tag:t.element,list:t.list,move:t.move},scopedSlots:t._u([{key:"footer",fn:function(){return[t._t("footer")]},proxy:!0}],null,!0)},"draggable",t.dragOptions,!1),t.listeners),[t._t("default")],2)}),[],!1,Xc,null,null,null);function Xc(t){for(let e in Vc)this[e]=Vc[e]}var Zc=function(){return Wc.exports}();const Qc={};var td=Ft({data:()=>({error:null}),errorCaptured(t){return this.$config.debug&&window.console.warn(t),this.error=t,!1},render(t){return this.error?this.$slots.error?this.$slots.error[0]:this.$scopedSlots.error?this.$scopedSlots.error({error:this.error}):t("k-box",{attrs:{theme:"negative"}},this.error.message||this.error):this.$slots.default[0]}},undefined,undefined,!1,ed,null,null,null);function ed(t){for(let e in Qc)this[e]=Qc[e]}var nd=function(){return td.exports}();const id={};var sd=Ft({props:{html:String},mounted(){try{let t=this.$refs.iframe.contentWindow.document;t.open(),t.write(this.html),t.close()}catch(t){console.error(t)}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-fatal"},[n("div",{staticClass:"k-fatal-box"},[n("k-bar",{scopedSlots:t._u([{key:"left",fn:function(){return[n("k-headline",[t._v(" The JSON response could not be parsed ")])]},proxy:!0},{key:"right",fn:function(){return[n("k-button",{attrs:{icon:"cancel",text:"Close"},on:{click:function(e){return t.$store.dispatch("fatal",!1)}}})]},proxy:!0}])}),n("iframe",{ref:"iframe",staticClass:"k-fatal-iframe"})],1)])}),[],!1,od,null,null,null);function od(t){for(let e in id)this[e]=id[e]}var rd=function(){return sd.exports}();const ad={};var ld=Ft({props:{link:String,size:{type:String},tag:{type:String,default:"h2"},theme:{type:String}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n(t.tag,t._g({tag:"component",staticClass:"k-headline",attrs:{"data-theme":t.theme,"data-size":t.size}},t.$listeners),[t.link?n("k-link",{attrs:{to:t.link}},[t._t("default")],2):t._t("default")],2)}),[],!1,ud,null,null,null);function ud(t){for(let e in ad)this[e]=ad[e]}var cd=function(){return ld.exports}();const dd={};var pd=Ft({props:{alt:String,color:String,back:String,size:String,type:String},computed:{isEmoji(){return this.$helper.string.hasEmoji(this.type)}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("span",{class:"k-icon k-icon-"+t.type,style:{background:t.$helper.color(t.back)},attrs:{"aria-label":t.alt,role:t.alt?"img":null,"aria-hidden":!t.alt,"data-back":t.back,"data-size":t.size}},[t.isEmoji?n("span",{staticClass:"k-icon-emoji"},[t._v(t._s(t.type))]):n("svg",{style:{color:t.$helper.color(t.color)},attrs:{viewBox:"0 0 16 16"}},[n("use",{attrs:{"xlink:href":"#icon-"+t.type}})])])}),[],!1,hd,null,null,null);function hd(t){for(let e in dd)this[e]=dd[e]}var fd=function(){return pd.exports}(),md=function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("svg",{staticClass:"k-icons",attrs:{"aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",overflow:"hidden"}},[n("defs",t._l(t.$options.icons,(function(e,i){return n("symbol",{key:i,attrs:{id:"icon-"+i,viewBox:"0 0 16 16"},domProps:{innerHTML:t._s(e)}})})),0)])},gd=[];const kd={icons:window.panel.plugins.icons},vd={};var bd=Ft(kd,md,gd,!1,yd,null,null,null);function yd(t){for(let e in vd)this[e]=vd[e]}var $d=function(){return bd.exports}();const _d={props:{alt:String,back:String,cover:Boolean,ratio:String,sizes:String,src:String,srcset:String},data:()=>({loaded:{type:Boolean,default:!1},error:{type:Boolean,default:!1}}),computed:{ratioPadding(){return this.$helper.ratio(this.ratio||"1/1")}},created(){let t=new Image;t.onload=()=>{this.loaded=!0,this.$emit("load")},t.onerror=()=>{this.error=!0,this.$emit("error")},t.src=this.src}},xd={};var wd=Ft(_d,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("span",t._g({staticClass:"k-image",attrs:{"data-ratio":t.ratio,"data-back":t.back,"data-cover":t.cover}},t.$listeners),[n("span",{style:"padding-bottom:"+t.ratioPadding},[t.loaded?n("img",{key:t.src,attrs:{alt:t.alt||"",src:t.src,srcset:t.srcset,sizes:t.sizes},on:{dragstart:function(t){t.preventDefault()}}}):t._e(),t.loaded||t.error?t._e():n("k-loader",{attrs:{position:"center",theme:"light"}}),!t.loaded&&t.error?n("k-icon",{staticClass:"k-image-error",attrs:{type:"cancel"}}):t._e()],1)])}),[],!1,Sd,null,null,null);function Sd(t){for(let e in xd)this[e]=xd[e]}var Cd=function(){return wd.exports}();const Od={};var Ed=Ft({},(function(){var t=this.$createElement,e=this._self._c||t;return e("span",{staticClass:"k-loader"},[e("k-icon",{staticClass:"k-loader-icon",attrs:{type:"loader"}})],1)}),[],!1,Ad,null,null,null);function Ad(t){for(let e in Od)this[e]=Od[e]}var Td=function(){return Ed.exports}();const Id={};var Md=Ft({data:()=>({offline:!1}),created(){this.$events.$on("offline",this.isOffline),this.$events.$on("online",this.isOnline)},destroyed(){this.$events.$off("offline",this.isOffline),this.$events.$off("online",this.isOnline)},methods:{isOnline(){this.offline=!1},isOffline(){this.offline=!0}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return t.offline?n("div",{staticClass:"k-offline-warning"},[n("p",[n("k-icon",{attrs:{type:"bolt"}}),t._v(" "+t._s(t.$t("error.offline")))],1)]):t._e()}),[],!1,Ld,null,null,null);function Ld(t){for(let e in Id)this[e]=Id[e]}var jd=function(){return Md.exports}();const Dd=(t,e=!1)=>{if(t>=0&&t<=100)return!0;if(e)throw new Error("value has to be between 0 and 100");return!1},Bd={};var Pd=Ft({props:{value:{type:Number,default:0,validator:Dd}},data(){return{state:this.value}},watch:{value(t){this.state=t}},methods:{set(t){Dd(t,!0),this.state=t}}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("progress",{staticClass:"k-progress",attrs:{max:"100"},domProps:{value:t.state}},[t._v(t._s(t.state)+"%")])}),[],!1,Nd,null,null,null);function Nd(t){for(let e in Bd)this[e]=Bd[e]}var qd=function(){return Pd.exports}();const Fd={};var Rd=Ft({},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-registration"},[n("p",[t._v(t._s(t.$t("license.unregistered")))]),n("k-button",{staticClass:"k-topbar-button",attrs:{responsive:!0,tooltip:t.$t("license.unregistered"),icon:"key"},on:{click:function(e){return t.$dialog("registration")}}},[t._v(" "+t._s(t.$t("license.register"))+" ")]),n("k-button",{staticClass:"k-topbar-button",attrs:{responsive:!0,link:"https://getkirby.com/buy",target:"_blank",icon:"cart"}},[t._v(" "+t._s(t.$t("license.buy"))+" ")])],1)}),[],!1,zd,null,null,null);function zd(t){for(let e in Fd)this[e]=Fd[e]}var Yd=function(){return Rd.exports}();const Hd={};var Ud=Ft({props:{icon:{type:String,default:"sort"}}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-icon",{staticClass:"k-sort-handle",attrs:{type:t.icon,"aria-hidden":"true"}})}),[],!1,Kd,null,null,null);function Kd(t){for(let e in Hd)this[e]=Hd[e]}var Jd=function(){return Ud.exports}();const Gd={props:{click:{type:Function,default:()=>{}},disabled:Boolean,responsive:Boolean,status:String,text:String,tooltip:String},computed:{icon(){return"draft"===this.status?"circle-outline":"unlisted"===this.status?"circle-half":"circle"},theme(){return"draft"===this.status?"negative":"unlisted"===this.status?"info":"positive"},title(){let t=this.tooltip||this.text;return this.disabled&&(t+=` (${this.$t("disabled")})`),t}},methods:{onClick(){this.click(),this.$emit("click")}}},Vd={};var Wd=Ft(Gd,(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-button",{class:"k-status-icon k-status-icon-"+t.status,attrs:{disabled:t.disabled,icon:t.icon,responsive:t.responsive,text:t.text,theme:t.theme,tooltip:t.title},on:{click:t.onClick}})}),[],!1,Xd,null,null,null);function Xd(t){for(let e in Vd)this[e]=Vd[e]}var Zd=function(){return Wd.exports}();const Qd={};var tp=Ft({props:{align:String,size:String,theme:String}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("div",{staticClass:"k-text",attrs:{"data-align":t.align,"data-size":t.size,"data-theme":t.theme}},[t._t("default")],2)}),[],!1,ep,null,null,null);function ep(t){for(let e in Qd)this[e]=Qd[e]}var np=function(){return tp.exports}();const ip={};var sp=Ft({props:{user:[Object,String]}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-user-info"},[t.user.avatar?n("k-image",{attrs:{cover:!0,src:t.user.avatar.url,ratio:"1/1"}}):n("k-icon",{attrs:{type:"user"}}),t._v(" "+t._s(t.user.name||t.user.email||t.user)+" ")],1)}),[],!1,op,null,null,null);function op(t){for(let e in ip)this[e]=ip[e]}var rp=function(){return sp.exports}();const ap={};var lp=Ft({props:{crumbs:{type:Array,default:()=>[]},label:{type:String,default:"Breadcrumb"},view:Object},computed:{dropdown(){return this.segments.map((t=>l(a({},t),{text:t.label,icon:"angle-right"})))},segments(){return[{link:this.view.link,label:this.view.breadcrumbLabel,icon:this.view.icon,loading:this.$store.state.isLoading},...this.crumbs]}},methods:{isLast(t){return this.crumbs.length-1===t}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("nav",{staticClass:"k-breadcrumb",attrs:{"aria-label":t.label}},[n("k-dropdown",{staticClass:"k-breadcrumb-dropdown"},[n("k-button",{attrs:{icon:"road-sign"},on:{click:function(e){return t.$refs.dropdown.toggle()}}}),n("k-dropdown-content",{ref:"dropdown",attrs:{options:t.dropdown,theme:"light"}})],1),n("ol",t._l(t.segments,(function(e,i){return n("li",{key:i},[n("k-link",{staticClass:"k-breadcrumb-link",attrs:{title:e.text||e.label,to:e.link,"aria-current":!!t.isLast(i)&&"page"}},[e.loading?n("k-loader",{staticClass:"k-breadcrumb-icon"}):e.icon?n("k-icon",{staticClass:"k-breadcrumb-icon",attrs:{type:e.icon}}):t._e(),n("span",{staticClass:"k-breadcrumb-link-text"},[t._v(" "+t._s(e.text||e.label)+" ")])],1)],1)})),0)],1)}),[],!1,up,null,null,null);function up(t){for(let e in ap)this[e]=ap[e]}var cp=function(){return lp.exports}();const dp={inheritAttrs:!1,props:{autofocus:Boolean,click:Function,current:[String,Boolean],disabled:Boolean,icon:String,id:[String,Number],link:String,responsive:Boolean,rel:String,role:String,target:String,tabindex:String,text:[String,Number],theme:String,tooltip:String,type:{type:String,default:"button"}},computed:{component(){return!0===this.disabled?"k-button-disabled":this.link?"k-button-link":"k-button-native"}},methods:{focus(){this.$refs.button.focus&&this.$refs.button.focus()},tab(){this.$refs.button.tab&&this.$refs.button.tab()},untab(){this.$refs.button.untab&&this.$refs.button.untab()}}},pp={};var hp=Ft(dp,(function(){var t=this,e=t.$createElement;return(t._self._c||e)(t.component,t._g(t._b({ref:"button",tag:"component"},"component",t.$props,!1),t.$listeners),[t.text?[t._v(" "+t._s(t.text)+" ")]:t._t("default")],2)}),[],!1,fp,null,null,null);function fp(t){for(let e in pp)this[e]=pp[e]}var mp=function(){return hp.exports}();const gp={inheritAttrs:!1,props:{icon:String,id:[String,Number],responsive:Boolean,theme:String,tooltip:String}},kp={};var vp=Ft(gp,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("span",{staticClass:"k-button",attrs:{id:t.id,"data-disabled":!0,"data-responsive":t.responsive,"data-theme":t.theme,title:t.tooltip}},[t.icon?n("k-icon",{staticClass:"k-button-icon",attrs:{type:t.icon,alt:t.tooltip}}):t._e(),t.$slots.default?n("span",{staticClass:"k-button-text"},[t._t("default")],2):t._e()],1)}),[],!1,bp,null,null,null);function bp(t){for(let e in kp)this[e]=kp[e]}var yp=function(){return vp.exports}();const $p={};var _p=Ft({props:{buttons:Array}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-button-group"},[t.$slots.default?t._t("default"):t._l(t.buttons,(function(e,i){return n("k-button",t._b({key:i},"k-button",e,!1))}))],2)}),[],!1,xp,null,null,null);function xp(t){for(let e in $p)this[e]=$p[e]}var wp=function(){return _p.exports}();const Sp={inheritAttrs:!1,props:{autofocus:Boolean,current:[String,Boolean],icon:String,id:[String,Number],link:String,rel:String,responsive:Boolean,role:String,target:String,tabindex:String,theme:String,tooltip:String},methods:{focus(){this.$el.focus()}}},Cp={};var Op=Ft(Sp,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-link",t._g({staticClass:"k-button",attrs:{id:t.id,"aria-current":t.current,autofocus:t.autofocus,"data-theme":t.theme,"data-responsive":t.responsive,rel:t.rel,role:t.role,tabindex:t.tabindex,target:t.target,title:t.tooltip,to:t.link}},t.$listeners),[t.icon?n("k-icon",{staticClass:"k-button-icon",attrs:{type:t.icon,alt:t.tooltip}}):t._e(),t.$slots.default?n("span",{staticClass:"k-button-text"},[t._t("default")],2):t._e()],1)}),[],!1,Ep,null,null,null);function Ep(t){for(let e in Cp)this[e]=Cp[e]}var Ap=function(){return Op.exports}(),Tp={mounted(){this.$el.addEventListener("keyup",this.onTab,!0),this.$el.addEventListener("blur",this.onUntab,!0)},destroyed(){this.$el.removeEventListener("keyup",this.onTab,!0),this.$el.removeEventListener("blur",this.onUntab,!0)},methods:{focus(){this.$el.focus&&this.$el.focus()},onTab(t){9===t.keyCode&&this.$el.setAttribute("data-tabbed",!0)},onUntab(){this.$el.removeAttribute("data-tabbed")},tab(){this.$el.focus(),this.$el.setAttribute("data-tabbed",!0)},untab(){this.$el.removeAttribute("data-tabbed")}}};const Ip={mixins:[Tp],inheritAttrs:!1,props:{autofocus:Boolean,click:{type:Function,default:()=>{}},current:[String,Boolean],icon:String,id:[String,Number],responsive:Boolean,role:String,tabindex:String,theme:String,tooltip:String,type:{type:String,default:"button"}}},Mp={};var Lp=Ft(Ip,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("button",t._g({staticClass:"k-button",attrs:{id:t.id,"aria-current":t.current,autofocus:t.autofocus,"data-theme":t.theme,"data-responsive":t.responsive,role:t.role,tabindex:t.tabindex,title:t.tooltip,type:t.type},on:{click:t.click}},t.$listeners),[t.icon?n("k-icon",{staticClass:"k-button-icon",attrs:{type:t.icon,alt:t.tooltip}}):t._e(),t.$slots.default?n("span",{staticClass:"k-button-text"},[t._t("default")],2):t._e()],1)}),[],!1,jp,null,null,null);function jp(t){for(let e in Mp)this[e]=Mp[e]}var Dp=function(){return Lp.exports}();const Bp={};var Pp=Ft({},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("span",{staticClass:"k-dropdown",on:{click:function(t){t.stopPropagation()}}},[t._t("default")],2)}),[],!1,Np,null,null,null);function Np(t){for(let e in Bp)this[e]=Bp[e]}var qp=function(){return Pp.exports}();let Fp=null;const Rp={};var zp=Ft({props:{align:{type:String,default:"left"},options:[Array,Function,String],theme:{type:String,default:"dark"}},data:()=>({current:-1,dropup:!1,isOpen:!1,items:[]}),methods:{async fetchOptions(t){if(!this.options)return t(this.items);"string"==typeof this.options?this.$dropdown(this.options)(t):"function"==typeof this.options?this.options(t):Array.isArray(this.options)&&t(this.options)},onOptionClick(t){"function"==typeof t.click?t.click.call(this):t.click&&this.$emit("action",t.click)},open(){this.reset(),Fp&&Fp!==this&&Fp.close(),this.fetchOptions((t=>{this.$events.$on("keydown",this.navigate),this.$events.$on("click",this.close),this.items=t,this.isOpen=!0,Fp=this,this.onOpen(),this.$emit("open")}))},reset(){this.current=-1,this.$events.$off("keydown",this.navigate),this.$events.$off("click",this.close)},close(){this.reset(),this.isOpen=Fp=!1,this.$emit("close")},toggle(){this.isOpen?this.close():this.open()},focus(t=0){var e;(null==(e=this.$children[t])?void 0:e.focus)&&(this.current=t,this.$children[t].focus())},onOpen(){this.dropup=!1,this.$nextTick((()=>{if(this.$el){let t=window.innerHeight||document.body.clientHeight||document.documentElement.clientHeight,e=50,n=this.$el.getBoundingClientRect().top||0,i=this.$el.clientHeight;n+i>t-e&&i+2*ethis.$children.length-1){const t=this.$children.filter((t=>!1===t.disabled));this.current=this.$children.indexOf(t[t.length-1]);break}if(this.$children[this.current]&&!1===this.$children[this.current].disabled){this.focus(this.current);break}}break;case"Tab":for(;;){if(this.current++,this.current>this.$children.length-1){this.close(),this.$emit("leave",t.code);break}if(this.$children[this.current]&&!1===this.$children[this.current].disabled)break}}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return t.isOpen?n("div",{staticClass:"k-dropdown-content",attrs:{"data-align":t.align,"data-dropup":t.dropup,"data-theme":t.theme}},[t._t("default",(function(){return[t._l(t.items,(function(e,i){return["-"===e?n("hr",{key:t._uid+"-item-"+i}):n("k-dropdown-item",t._b({key:t._uid+"-item-"+i,ref:t._uid+"-item-"+i,refInFor:!0,on:{click:function(n){return t.onOptionClick(e)}}},"k-dropdown-item",e,!1),[t._v(" "+t._s(e.text)+" ")])]}))]}))],2):t._e()}),[],!1,Yp,null,null,null);function Yp(t){for(let e in Rp)this[e]=Rp[e]}var Hp=function(){return zp.exports}();const Up={inheritAttrs:!1,props:{disabled:Boolean,icon:String,image:[String,Object],link:String,target:String,theme:String,upload:String,current:[String,Boolean]},data(){return{listeners:l(a({},this.$listeners),{click:t=>{this.$parent.close(),this.$emit("click",t)}})}},methods:{focus(){this.$refs.button.focus()},tab(){this.$refs.button.tab()}}},Kp={};var Jp=Ft(Up,(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-button",t._g(t._b({ref:"button",staticClass:"k-dropdown-item"},"k-button",t.$props,!1),t.listeners),[t._t("default")],2)}),[],!1,Gp,null,null,null);function Gp(t){for(let e in Kp)this[e]=Kp[e]}var Vp=function(){return Jp.exports}();const Wp={mixins:[Tp],props:{disabled:Boolean,rel:String,tabindex:[String,Number],target:String,title:String,to:[String,Function]},data(){return{relAttr:"_blank"===this.target?"noreferrer noopener":this.rel,listeners:l(a({},this.$listeners),{click:this.onClick})}},computed:{href(){return"function"==typeof this.to?"":"/"!==this.to[0]||this.target?!0===this.to.includes("@")&&!1===this.to.includes("/")?"mailto:"+this.to:this.to:this.$url(this.to)}},methods:{isRoutable(t){if(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)return!1;if(t.defaultPrevented)return!1;if(void 0!==t.button&&0!==t.button)return!1;if(this.target)return!1;if("string"==typeof this.href){if(this.href.includes("://")||this.href.startsWith("//"))return!1;if(this.href.includes("mailto:"))return!1}return!0},onClick(t){if(!0===this.disabled)return t.preventDefault(),!1;"function"==typeof this.to&&(t.preventDefault(),this.to()),this.isRoutable(t)&&(t.preventDefault(),this.$go(this.to)),this.$emit("click",t)}}},Xp={};var Zp=Ft(Wp,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return t.to&&!t.disabled?n("a",t._g({ref:"link",staticClass:"k-link",attrs:{href:t.href,rel:t.relAttr,tabindex:t.tabindex,target:t.target,title:t.title}},t.listeners),[t._t("default")],2):n("span",{staticClass:"k-link",attrs:{title:t.title,"data-disabled":""}},[t._t("default")],2)}),[],!1,Qp,null,null,null);function Qp(t){for(let e in Xp)this[e]=Xp[e]}var th=function(){return Zp.exports}();const eh={};var nh=Ft({computed:{defaultLanguage(){return this.$languages.find((t=>!0===t.default))},language(){return this.$language},languages(){return this.$languages.filter((t=>!1===t.default))}},methods:{change(t){this.$emit("change",t),this.$go(window.location,{query:{language:t.code}})}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return t.languages.length?n("k-dropdown",{staticClass:"k-languages-dropdown"},[n("k-button",{attrs:{text:t.language.name,responsive:!0,icon:"globe"},on:{click:function(e){return t.$refs.languages.toggle()}}}),t.languages?n("k-dropdown-content",{ref:"languages"},[n("k-dropdown-item",{on:{click:function(e){return t.change(t.defaultLanguage)}}},[t._v(" "+t._s(t.defaultLanguage.name)+" ")]),n("hr"),t._l(t.languages,(function(e){return n("k-dropdown-item",{key:e.code,on:{click:function(n){return t.change(e)}}},[t._v(" "+t._s(e.name)+" ")])}))],2):t._e()],1):t._e()}),[],!1,ih,null,null,null);function ih(t){for(let e in eh)this[e]=eh[e]}var sh=function(){return nh.exports}();const oh={props:{align:{type:String,default:"right"},icon:{type:String,default:"dots"},options:{type:[Array,Function,String],default:()=>[]},text:{type:[Boolean,String],default:!0},theme:{type:String,default:"dark"}},computed:{hasSingleOption(){return Array.isArray(this.options)&&1===this.options.length}},methods:{onAction(t,e,n){"function"==typeof t?t.call(this):(this.$emit("action",t,e,n),this.$emit("option",t,e,n))},toggle(){this.$refs.options.toggle()}}},rh={};var ah=Ft(oh,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return t.hasSingleOption?n("k-button",{staticClass:"k-options-dropdown-toggle",attrs:{icon:t.options[0].icon||t.icon,tooltip:t.options[0].tooltip||t.options[0].text},on:{click:function(e){return t.onAction(t.options[0].option||t.options[0].click,t.options[0],0)}}},[!0===t.text?[t._v(" "+t._s(t.options[0].text)+" ")]:!1!==t.text?[t._v(" "+t._s(t.text)+" ")]:t._e()],2):t.options.length?n("k-dropdown",{staticClass:"k-options-dropdown"},[n("k-button",{staticClass:"k-options-dropdown-toggle",attrs:{icon:t.icon,tooltip:t.$t("options")},on:{click:function(e){return t.$refs.options.toggle()}}},[t.text&&!0!==t.text?[t._v(" "+t._s(t.text)+" ")]:t._e()],2),n("k-dropdown-content",{ref:"options",staticClass:"k-options-dropdown-content",attrs:{align:t.align,options:t.options},on:{action:t.onAction}})],1):t._e()}),[],!1,lh,null,null,null);function lh(t){for(let e in rh)this[e]=rh[e]}var uh=function(){return ah.exports}();const ch={props:{align:{type:String,default:"left"},details:{type:Boolean,default:!1},dropdown:{type:Boolean,default:!0},keys:{type:Boolean,default:!1},limit:{type:Number,default:10},page:{type:Number,default:1},pageLabel:{type:String,default:()=>window.panel.$t("pagination.page")},total:{type:Number,default:0},prevLabel:{type:String,default:()=>window.panel.$t("prev")},nextLabel:{type:String,default:()=>window.panel.$t("next")},validate:{type:Function,default:()=>Promise.resolve()}},data(){return{currentPage:this.page}},computed:{show(){return this.pages>1},start(){return(this.currentPage-1)*this.limit+1},end(){let t=this.start-1+this.limit;return t>this.total?this.total:t},detailsText(){return 1===this.limit?this.start+" / ":this.start+"-"+this.end+" / "},pages(){return Math.ceil(this.total/this.limit)},hasPrev(){return this.start>1},hasNext(){return this.endthis.limit},offset(){return this.start-1}},watch:{page(t){this.currentPage=parseInt(t)}},created(){!0===this.keys&&window.addEventListener("keydown",this.navigate,!1)},destroyed(){window.removeEventListener("keydown",this.navigate,!1)},methods:{async goTo(t){try{await this.validate(t),t<1&&(t=1),t>this.pages&&(t=this.pages),this.currentPage=t,this.$refs.dropdown&&this.$refs.dropdown.close(),this.$emit("paginate",{page:this.currentPage,start:this.start,end:this.end,limit:this.limit,offset:this.offset})}catch(e){}},prev(){this.goTo(this.currentPage-1)},next(){this.goTo(this.currentPage+1)},navigate(t){switch(t.code){case"ArrowLeft":this.prev();break;case"ArrowRight":this.next()}}}},dh={};var ph=Ft(ch,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return t.show?n("nav",{staticClass:"k-pagination",attrs:{"data-align":t.align}},[t.show?n("k-button",{attrs:{disabled:!t.hasPrev,tooltip:t.prevLabel,icon:"angle-left"},on:{click:t.prev}}):t._e(),t.details?[t.dropdown?[n("k-dropdown",[n("k-button",{staticClass:"k-pagination-details",attrs:{disabled:!t.hasPages},on:{click:function(e){return t.$refs.dropdown.toggle()}}},[t.total>1?[t._v(" "+t._s(t.detailsText)+" ")]:t._e(),t._v(" "+t._s(t.total)+" ")],2),n("k-dropdown-content",{ref:"dropdown",staticClass:"k-pagination-selector",on:{open:function(e){t.$nextTick((function(){return t.$refs.page.focus()}))}}},[n("div",{staticClass:"k-pagination-settings"},[n("label",{attrs:{for:"k-pagination-page"}},[n("span",[t._v(t._s(t.pageLabel)+":")]),n("select",{ref:"page",attrs:{id:"k-pagination-page"}},t._l(t.pages,(function(e){return n("option",{key:e,domProps:{selected:t.page===e,value:e}},[t._v(" "+t._s(e)+" ")])})),0)]),n("k-button",{attrs:{icon:"check"},on:{click:function(e){return t.goTo(t.$refs.page.value)}}})],1)])],1)]:[n("span",{staticClass:"k-pagination-details"},[t.total>1?[t._v(" "+t._s(t.detailsText)+" ")]:t._e(),t._v(" "+t._s(t.total)+" ")],2)]]:t._e(),t.show?n("k-button",{attrs:{disabled:!t.hasNext,tooltip:t.nextLabel,icon:"angle-right"},on:{click:t.next}}):t._e()],2):t._e()}),[],!1,hh,null,null,null);function hh(t){for(let e in dh)this[e]=dh[e]}var fh=function(){return ph.exports}();const mh={props:{prev:{type:[Boolean,Object],default:!1},next:{type:[Boolean,Object],default:!1}},computed:{buttons(){return[l(a({},this.button(this.prev)),{icon:"angle-left"}),l(a({},this.button(this.next)),{icon:"angle-right"})]}},methods:{button:t=>t||{disabled:!0,link:"#"}}},gh={};var kh=Ft(mh,(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-button-group",{staticClass:"k-prev-next",attrs:{buttons:t.buttons}})}),[],!1,vh,null,null,null);function vh(t){for(let e in gh)this[e]=gh[e]}var bh=function(){return kh.exports}();const yh={};var $h=Ft({props:{types:{type:Object,default:()=>({})},type:String},data(){return{isLoading:!1,hasResults:!0,items:[],currentType:this.getType(this.type),q:null,selected:-1}},watch:{q(t,e){t!==e&&this.search(this.q)},currentType(t,e){t!==e&&this.search(this.q)},type(){this.currentType=this.getType(this.type)}},created(){this.search=$t(this.search,250),this.$events.$on("keydown.cmd.shift.f",this.open)},destroyed(){this.$events.$off("keydown.cmd.shift.f",this.open)},methods:{changeType(t){this.currentType=this.getType(t),this.$nextTick((()=>{this.$refs.input.focus()}))},close(){this.$refs.overlay.close(),this.hasResults=!0,this.items=[],this.q=null},getType(t){return this.types[t]||this.types[Object.keys(this.types)[0]]},navigate(t){this.$go(t.link),this.close()},onDown(){this.selected=0&&this.select(this.selected-1)},open(){this.$refs.overlay.open()},async search(t){this.isLoading=!0,this.$refs.types&&this.$refs.types.close();try{if(null===t||""===t)throw Error("Empty query");const e=await this.$search(this.currentType.id,t);if(!1===e)throw Error("JSON parsing failed");this.items=e.results}catch(e){this.items=[]}finally{this.select(-1),this.isLoading=!1,this.hasResults=this.items.length>0}},select(t){if(this.selected=t,this.$refs.items){const e=this.$refs.items.$el.querySelectorAll(".k-item");[...e].forEach((t=>delete t.dataset.selected)),t>=0&&(e[t].dataset.selected=!0)}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-overlay",{ref:"overlay"},[n("div",{staticClass:"k-search",attrs:{role:"search"}},[n("div",{staticClass:"k-search-input"},[n("k-dropdown",{staticClass:"k-search-types"},[n("k-button",{attrs:{icon:t.currentType.icon,text:t.currentType.label},on:{click:function(e){return t.$refs.types.toggle()}}}),n("k-dropdown-content",{ref:"types"},t._l(t.types,(function(e,i){return n("k-dropdown-item",{key:i,attrs:{icon:e.icon},on:{click:function(e){return t.changeType(i)}}},[t._v(" "+t._s(e.label)+" ")])})),1)],1),n("input",{directives:[{name:"model",rawName:"v-model",value:t.q,expression:"q"}],ref:"input",attrs:{placeholder:t.$t("search")+" …","aria-label":t.$t("search"),autofocus:!0,type:"text"},domProps:{value:t.q},on:{input:[function(e){e.target.composing||(t.q=e.target.value)},function(e){t.hasResults=!0}],keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"down",40,e.key,["Down","ArrowDown"])?null:(e.preventDefault(),t.onDown.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"up",38,e.key,["Up","ArrowUp"])?null:(e.preventDefault(),t.onUp.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"tab",9,e.key,"Tab")?null:(e.preventDefault(),t.onTab.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"enter",13,e.key,"Enter")?null:t.onEnter.apply(null,arguments)},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"esc",27,e.key,["Esc","Escape"])?null:t.close.apply(null,arguments)}]}}),n("k-button",{staticClass:"k-search-close",attrs:{icon:t.isLoading?"loader":"cancel",tooltip:t.$t("close")},on:{click:t.close}})],1),!t.q||t.hasResults&&!t.items.length?t._e():n("div",{staticClass:"k-search-results"},[t.items.length?n("k-collection",{ref:"items",attrs:{items:t.items},on:{hover:t.onHover},nativeOn:{mouseout:function(e){return t.select(-1)}}}):t.hasResults?t._e():n("p",{staticClass:"k-search-empty"},[t._v(" "+t._s(t.$t("search.results.none"))+" ")])],1)])])}),[],!1,_h,null,null,null);function _h(t){for(let e in yh)this[e]=yh[e]}var xh=function(){return $h.exports}();const wh={props:{removable:Boolean},methods:{remove(){this.removable&&this.$emit("remove")},focus(){this.$refs.button.focus()}}},Sh={};var Ch=Ft(wh,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("span",{ref:"button",staticClass:"k-tag",attrs:{tabindex:"0"},on:{keydown:function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"delete",[8,46],e.key,["Backspace","Delete","Del"])?null:(e.preventDefault(),t.remove.apply(null,arguments))}}},[n("span",{staticClass:"k-tag-text"},[t._t("default")],2),t.removable?n("k-icon",{staticClass:"k-tag-toggle",attrs:{type:"cancel-small"},nativeOn:{click:function(e){return t.remove.apply(null,arguments)}}}):t._e()],1)}),[],!1,Oh,null,null,null);function Oh(t){for(let e in Sh)this[e]=Sh[e]}var Eh=function(){return Ch.exports}();const Ah={props:{breadcrumb:Array,license:Boolean,menu:Array,title:String,view:Object},computed:{notification(){return this.$store.state.notification.type&&"error"!==this.$store.state.notification.type?this.$store.state.notification:null}}},Th={};var Ih=Ft(Ah,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-topbar"},[n("k-view",[n("div",{staticClass:"k-topbar-wrapper"},[n("k-dropdown",{staticClass:"k-topbar-menu"},[n("k-button",{staticClass:"k-topbar-button k-topbar-menu-button",attrs:{tooltip:t.$t("menu"),icon:"bars"},on:{click:function(e){return t.$refs.menu.toggle()}}},[n("k-icon",{attrs:{type:"angle-down"}})],1),n("k-dropdown-content",{ref:"menu",staticClass:"k-topbar-menu",attrs:{options:t.menu,theme:"light"}})],1),n("k-breadcrumb",{staticClass:"k-topbar-breadcrumb",attrs:{crumbs:t.breadcrumb,view:t.view}}),n("div",{staticClass:"k-topbar-signals"},[t.notification?n("k-button",{staticClass:"k-topbar-notification k-topbar-button",attrs:{text:t.notification.message,theme:"positive"},on:{click:function(e){return t.$store.dispatch("notification/close")}}}):t.license?t._e():n("k-registration"),n("k-form-indicator"),n("k-button",{staticClass:"k-topbar-button",attrs:{tooltip:t.$t("search"),icon:"search"},on:{click:function(e){return t.$refs.search.open()}}})],1)],1)]),n("k-search",{ref:"search",attrs:{type:t.$view.search||"pages",types:t.$searches}})],1)}),[],!1,Mh,null,null,null);function Mh(t){for(let e in Th)this[e]=Th[e]}var Lh=function(){return Ih.exports}();const jh={props:{empty:String,blueprint:String,lock:[Boolean,Object],parent:String,tab:Object},computed:{content(){return this.$store.getters["content/values"]()}},methods:{exists(t){return this.$helper.isComponent(`k-${t}-section`)},meetsCondition(t){if(!t.when)return!0;let e=!0;return Object.keys(t.when).forEach((n=>{this.content[n.toLowerCase()]!==t.when[n]&&(e=!1)})),e}}},Dh={};var Bh=Ft(jh,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return 0===t.tab.columns.length?n("k-box",{attrs:{html:!0,text:t.empty,theme:"info"}}):n("k-grid",{staticClass:"k-sections",attrs:{gutter:"large"}},t._l(t.tab.columns,(function(e,i){return n("k-column",{key:t.parent+"-column-"+i,attrs:{width:e.width,sticky:e.sticky}},[t._l(e.sections,(function(s,o){return[t.meetsCondition(s)?[t.exists(s.type)?n("k-"+s.type+"-section",t._b({key:t.parent+"-column-"+i+"-section-"+o+"-"+t.blueprint,tag:"component",class:"k-section k-section-name-"+s.name,attrs:{column:e.width,lock:t.lock,name:s.name,parent:t.parent,timestamp:t.$view.timestamp},on:{submit:function(e){return t.$emit("submit",e)}}},"component",s,!1)):[n("k-box",{key:t.parent+"-column-"+i+"-section-"+o,attrs:{text:t.$t("error.section.type.invalid",{type:s.type}),theme:"negative"}})]]:t._e()]}))],2)})),1)}),[],!1,Ph,null,null,null);function Ph(t){for(let e in Dh)this[e]=Dh[e]}var Nh=function(){return Bh.exports}();const qh={};var Fh=Ft({mixins:[Nt],inheritAttrs:!1,data:()=>({fields:{},isLoading:!0,issue:null}),computed:{values(){return this.$store.getters["content/values"]()}},watch:{timestamp(){this.fetch()}},created(){this.input=$t(this.input,50),this.fetch()},methods:{input(t,e,n){this.$store.dispatch("content/update",[n,t[n]])},async fetch(){try{const t=await this.load();this.fields=t.fields,Object.keys(this.fields).forEach((t=>{this.fields[t].section=this.name,this.fields[t].endpoints={field:this.parent+"/fields/"+t,section:this.parent+"/sections/"+this.name,model:this.parent}}))}catch(t){this.issue=t}finally{this.isLoading=!1}},onSubmit(t){this.$events.$emit("keydown.cmd.s",t)}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return t.isLoading?t._e():n("section",{staticClass:"k-fields-section"},[t.issue?[n("k-headline",{staticClass:"k-fields-issue-headline"},[t._v(" Error ")]),n("k-box",{attrs:{text:t.issue.message,html:!1,theme:"negative"}})]:t._e(),n("k-form",{attrs:{fields:t.fields,validate:!0,value:t.values,disabled:t.lock&&"lock"===t.lock.state},on:{input:t.input,submit:t.onSubmit}})],2)}),[],!1,Rh,null,null,null);function Rh(t){for(let e in qh)this[e]=qh[e]}var zh=function(){return Fh.exports}(),Yh=function(){var t=this,e=t.$createElement,n=t._self._c||e;return!1===t.isLoading?n("section",{class:`k-models-section k-${t.type}-section`,attrs:{"data-processing":t.isProcessing}},[n("header",{staticClass:"k-section-header"},[n("k-headline",{attrs:{link:t.options.link}},[t._v(" "+t._s(t.options.headline||" ")+" "),t.options.min?n("abbr",{attrs:{title:t.$t("section.required")}},[t._v("*")]):t._e()]),n("k-button-group",{attrs:{buttons:t.buttons}})],1),t.error?n("k-box",{attrs:{theme:"negative"}},[n("k-text",{attrs:{size:"small"}},[n("strong",[t._v(" "+t._s(t.$t("error.section.notLoaded",{name:t.name}))+": ")]),t._v(" "+t._s(t.error)+" ")])],1):[n("k-dropzone",{attrs:{disabled:!t.canDrop},on:{drop:t.onDrop}},[t.searching&&t.options.search?n("k-input",{staticClass:"k-models-section-search",attrs:{autofocus:!0,placeholder:t.$t("search")+" …",type:"text"},on:{keydown:function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"esc",27,e.key,["Esc","Escape"])?null:t.onSearchToggle.apply(null,arguments)}},model:{value:t.searchterm,callback:function(e){t.searchterm=e},expression:"searchterm"}}):t._e(),n("k-collection",t._g(t._b({attrs:{"data-invalid":t.isInvalid},on:{action:t.onAction,change:t.onChange,sort:t.onSort,paginate:t.onPaginate}},"k-collection",t.collection,!1),t.canAdd?{empty:t.onAdd}:{}))],1),n("k-upload",{ref:"upload",on:{success:t.onUpload,error:t.reload}})]],2):t._e()},Hh=[];const Uh={inheritAttrs:!1,props:{blueprint:String,column:String,parent:String,name:String,timestamp:Number},data:()=>({data:[],error:null,isLoading:!1,isProcessing:!1,options:{columns:{},empty:null,headline:null,help:null,layout:"list",link:null,max:null,min:null,size:null,sortable:null},pagination:{page:null},searchterm:null,searching:!1}),computed:{addIcon:()=>"add",buttons(){let t=[];return this.canSearch&&t.push({icon:"filter",text:this.$t("search"),click:this.onSearchToggle,responsive:!0}),this.canAdd&&t.push({icon:this.addIcon,text:this.$t("add"),click:this.onAdd}),t},canAdd:()=>!0,canDrop:()=>!1,canSearch(){return this.options.search},collection(){return{columns:this.options.columns,empty:this.emptyPropsWithSearch,layout:this.options.layout,help:this.options.help,items:this.items,pagination:this.pagination,sortable:!this.isProcessing&&this.options.sortable,size:this.options.size}},emptyProps(){return{icon:"page",text:this.$t("pages.empty")}},emptyPropsWithSearch(){return l(a({},this.emptyProps),{text:this.searching?this.$t("search.results.none"):this.options.empty||this.emptyProps.text})},items(){return this.data},isInvalid(){var t;return!((null==(t=this.searchterm)?void 0:t.length)>0)&&(!!(this.options.min&&this.data.lengththis.options.max))},paginationId(){return"kirby$pagination$"+this.parent+"/"+this.name},type:()=>"models"},watch:{searchterm:$t((function(){this.pagination.page=0,this.reload()}),200),timestamp(){this.reload()}},created(){this.load()},methods:{async load(t){t||(this.isLoading=!0),this.isProcessing=!0,null===this.pagination.page&&(this.pagination.page=localStorage.getItem(this.paginationId)||1);try{const t=await this.$api.get(this.parent+"/sections/"+this.name,{page:this.pagination.page,searchterm:this.searchterm});this.options=t.options,this.pagination=t.pagination,this.data=t.data}catch(e){this.error=e.message}finally{this.isProcessing=!1,this.isLoading=!1}},onAction(){},onAdd(){},onChange(){},onDrop(){},onSort(){},onPaginate(t){localStorage.setItem(this.paginationId,t.page),this.pagination=t,this.reload()},onSearchToggle(){this.searching=!this.searching,this.searchterm=null},onUpload(){},async reload(){await this.load(!0)},update(){this.reload(),this.$events.$emit("model.update")}}},Kh={};var Jh=Ft(Uh,Yh,Hh,!1,Gh,null,null,null);function Gh(t){for(let e in Kh)this[e]=Kh[e]}var Vh=function(){return Jh.exports}();const Wh={};var Xh=Ft({extends:Vh,computed:{addIcon:()=>"upload",canAdd(){return this.$permissions.files.create&&!1!==this.options.upload},canDrop(){return!1!==this.canAdd},emptyProps(){return{icon:"image",text:this.$t("files.empty")}},items(){return this.data.map((t=>(t.sortable=this.options.sortable,t.column=this.column,t.options=this.$dropdown(t.link,{query:{view:"list",update:this.options.sortable,delete:this.data.length>this.options.min}}),t.data={"data-id":t.id,"data-template":t.template},t)))},type:()=>"files",uploadProps(){return l(a({},this.options.upload),{url:this.$urls.api+"/"+this.options.upload.api})}},created(){this.load(),this.$events.$on("model.update",this.reload),this.$events.$on("file.sort",this.reload)},destroyed(){this.$events.$off("model.update",this.reload),this.$events.$off("file.sort",this.reload)},methods:{onAction(t,e){"replace"===t&&this.replace(e)},onAdd(){this.canAdd&&this.$refs.upload.open(this.uploadProps)},onDrop(t){this.canAdd&&this.$refs.upload.drop(t,this.uploadProps)},async onSort(t){if(!1===this.options.sortable)return!1;this.isProcessing=!0;try{await this.$api.patch(this.options.apiUrl+"/files/sort",{files:t.map((t=>t.id)),index:this.pagination.offset}),this.$store.dispatch("notification/success",":)"),this.$events.$emit("file.sort")}catch(e){this.reload(),this.$store.dispatch("notification/error",e.message)}finally{this.isProcessing=!1}},onUpload(){this.$events.$emit("file.create"),this.$events.$emit("model.update"),this.$store.dispatch("notification/success",":)")},replace(t){this.$refs.upload.open({url:this.$urls.api+"/"+t.link,accept:"."+t.extension+","+t.mime,multiple:!1})}}},undefined,undefined,!1,Zh,null,null,null);function Zh(t){for(let e in Wh)this[e]=Wh[e]}var Qh=function(){return Xh.exports}();const tf={};var ef=Ft({mixins:[Nt],data:()=>({headline:null,text:null,theme:null}),async created(){const t=await this.load();this.headline=t.headline,this.text=t.text,this.theme=t.theme||"info"}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("section",{staticClass:"k-info-section"},[n("k-headline",{staticClass:"k-info-section-headline"},[t._v(" "+t._s(t.headline)+" ")]),n("k-box",{attrs:{theme:t.theme}},[n("k-text",{domProps:{innerHTML:t._s(t.text)}})],1)],1)}),[],!1,nf,null,null,null);function nf(t){for(let e in tf)this[e]=tf[e]}var sf=function(){return ef.exports}();const of={};var rf=Ft({extends:Vh,computed:{canAdd(){return this.options.add&&this.$permissions.pages.create},items(){return this.data.map((t=>{const e=!1!==t.permissions.changeStatus;return t.flag={status:t.status,tooltip:this.$t("page.status"),disabled:!e,click:()=>this.$dialog(t.link+"/changeStatus")},t.sortable=t.permissions.sort&&this.options.sortable,t.deletable=this.data.length>this.options.min,t.column=this.column,t.options=this.$dropdown(t.link,{query:{view:"list",delete:t.deletable,sort:t.sortable}}),t.data={"data-id":t.id,"data-status":t.status,"data-template":t.template},t}))}},created(){this.load(),this.$events.$on("page.changeStatus",this.reload),this.$events.$on("page.sort",this.reload)},destroyed(){this.$events.$off("page.changeStatus",this.reload),this.$events.$off("page.sort",this.reload)},methods:{onAdd(){this.canAdd&&this.$dialog("pages/create",{query:{parent:this.options.link||this.parent,view:this.parent,section:this.name}})},async onChange(t){let e=null;if(t.added&&(e="added"),t.moved&&(e="moved"),e){this.isProcessing=!0;const i=t[e].element,s=t[e].newIndex+1+this.pagination.offset;try{await this.$api.pages.changeStatus(i.id,"listed",s),this.$store.dispatch("notification/success",":)"),this.$events.$emit("page.sort",i)}catch(n){this.$store.dispatch("notification/error",{message:n.message,details:n.details}),await this.reload()}finally{this.isProcessing=!1}}}}},undefined,undefined,!1,af,null,null,null);function af(t){for(let e in of)this[e]=of[e]}var lf=function(){return rf.exports}();const uf={};var cf=Ft({mixins:[Nt],data:()=>({isLoading:!0,headline:null,reports:null,size:null}),async created(){const t=await this.load();this.isLoading=!1,this.headline=t.headline,this.reports=t.reports,this.size=t.size},methods:{}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return!1===t.isLoading?n("section",{staticClass:"k-stats-section"},[n("header",{staticClass:"k-section-header"},[n("k-headline",[t._v(" "+t._s(t.headline)+" ")])],1),t.reports.length>0?n("k-stats",{attrs:{reports:t.reports,size:t.size}}):n("k-empty",{attrs:{icon:"chart"}},[t._v(" "+t._s(t.empty||t.$t("stats.empty")))])],1):t._e()}),[],!1,df,null,null,null);function df(t){for(let e in uf)this[e]=uf[e]}var pf=function(){return cf.exports}();u.component("k-sections",Nh),u.component("k-fields-section",zh),u.component("k-files-section",Qh),u.component("k-info-section",sf),u.component("k-pages-section",lf),u.component("k-stats-section",pf);const hf={props:{blueprint:String,next:Object,prev:Object,permissions:{type:Object,default:()=>({})},lock:{type:[Boolean,Object]},model:{type:Object,default:()=>({})},tab:{type:Object,default:()=>({columns:[]})},tabs:{type:Array,default:()=>[]}},computed:{id(){return this.model.link},isLocked(){var t;return"lock"===(null==(t=this.lock)?void 0:t.state)},protectedFields:()=>[]},watch:{"model.id":{handler(){this.content()},immediate:!0}},created(){this.$events.$on("model.reload",this.reload),this.$events.$on("keydown.left",this.toPrev),this.$events.$on("keydown.right",this.toNext)},destroyed(){this.$events.$off("model.reload",this.reload),this.$events.$off("keydown.left",this.toPrev),this.$events.$off("keydown.right",this.toNext)},methods:{content(){this.$store.dispatch("content/create",{id:this.id,api:this.id,content:this.model.content,ignore:this.protectedFields})},async reload(){await this.$reload(),this.content()},toPrev(t){this.prev&&"body"===t.target.localName&&this.$go(this.prev.link)},toNext(t){this.next&&"body"===t.target.localName&&this.$go(this.next.link)}}};const ff={};var mf=Ft(hf,undefined,undefined,!1,gf,null,null,null);function gf(t){for(let e in ff)this[e]=ff[e]}var kf=function(){return mf.exports}();const vf={};var bf=Ft({extends:kf,computed:{avatarOptions(){return[{icon:"upload",text:this.$t("change"),click:()=>this.$refs.upload.open()},{icon:"trash",text:this.$t("delete"),click:this.deleteAvatar}]},buttons(){return[{icon:"email",text:`${this.$t("email")}: ${this.model.email}`,disabled:!this.permissions.changeEmail||this.isLocked,click:()=>this.$dialog(this.id+"/changeEmail")},{icon:"bolt",text:`${this.$t("role")}: ${this.model.role}`,disabled:!this.permissions.changeRole||this.isLocked,click:()=>this.$dialog(this.id+"/changeRole")},{icon:"globe",text:`${this.$t("language")}: ${this.model.language}`,disabled:!this.permissions.changeLanguage||this.isLocked,click:()=>this.$dialog(this.id+"/changeLanguage")}]},uploadApi(){return this.$urls.api+"/"+this.id+"/avatar"}},methods:{async deleteAvatar(){await this.$api.users.deleteAvatar(this.model.id),this.avatar=null,this.$store.dispatch("notification/success",":)"),this.$reload()},onAvatar(){this.model.avatar?this.$refs.picture.toggle():this.$refs.upload.open()},uploadedAvatar(){this.$store.dispatch("notification/success",":)"),this.$reload()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-inside",{scopedSlots:t._u([{key:"footer",fn:function(){return[n("k-form-buttons",{attrs:{lock:t.lock}})]},proxy:!0}])},[n("div",{staticClass:"k-user-view",attrs:{"data-locked":t.isLocked,"data-id":t.model.id,"data-template":t.blueprint}},[n("div",{staticClass:"k-user-profile"},[n("k-view",[n("k-dropdown",[n("k-button",{staticClass:"k-user-view-image",attrs:{tooltip:t.$t("avatar"),disabled:t.isLocked},on:{click:t.onAvatar}},[t.model.avatar?n("k-image",{attrs:{cover:!0,src:t.model.avatar,ratio:"1/1"}}):n("k-icon",{attrs:{back:"gray-900",color:"gray-200",type:"user"}})],1),t.model.avatar?n("k-dropdown-content",{ref:"picture",attrs:{options:t.avatarOptions}}):t._e()],1),n("k-button-group",{attrs:{buttons:t.buttons}})],1)],1),n("k-view",[n("k-header",{attrs:{editable:t.permissions.changeName&&!t.isLocked,tab:t.tab.name,tabs:t.tabs},on:{edit:function(e){return t.$dialog(t.id+"/changeName")}},scopedSlots:t._u([{key:"left",fn:function(){return[n("k-button-group",[n("k-dropdown",{staticClass:"k-user-view-options"},[n("k-button",{attrs:{disabled:t.isLocked,text:t.$t("settings"),icon:"cog"},on:{click:function(e){return t.$refs.settings.toggle()}}}),n("k-dropdown-content",{ref:"settings",attrs:{options:t.$dropdown(t.id)}})],1),n("k-languages-dropdown")],1)]},proxy:!0},{key:"right",fn:function(){return[t.model.account?t._e():n("k-prev-next",{attrs:{prev:t.prev,next:t.next}})]},proxy:!0}])},[t.model.name&&0!==t.model.name.length?[t._v(" "+t._s(t.model.name)+" ")]:n("span",{staticClass:"k-user-name-placeholder"},[t._v(" "+t._s(t.$t("name"))+" … ")])],2),n("k-sections",{attrs:{blueprint:t.blueprint,empty:t.$t("user.blueprint",{blueprint:t.$esc(t.blueprint)}),lock:t.lock,parent:t.id,tab:t.tab}}),n("k-upload",{ref:"upload",attrs:{url:t.uploadApi,multiple:!1,accept:"image/*"},on:{success:t.uploadedAvatar}})],1)],1)])}),[],!1,yf,null,null,null);function yf(t){for(let e in vf)this[e]=vf[e]}var $f=function(){return bf.exports}();const _f={};var xf=Ft({extends:$f,prevnext:!1},undefined,undefined,!1,wf,null,null,null);function wf(t){for(let e in _f)this[e]=_f[e]}var Sf=function(){return xf.exports}();const Cf={};var Of=Ft({props:{error:String,layout:String}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n(`k-${t.layout}`,{tag:"component"},[n("k-view",{staticClass:"k-error-view"},[n("div",{staticClass:"k-error-view-content"},[n("k-text",[n("p",[n("k-icon",{staticClass:"k-error-view-icon",attrs:{type:"alert"}})],1),t._t("default",(function(){return[n("p",[t._v(" "+t._s(t.error)+" ")])]}))],2)],1)])],1)}),[],!1,Ef,null,null,null);function Ef(t){for(let e in Cf)this[e]=Cf[e]}var Af=function(){return Of.exports}();const Tf={};var If=Ft({extends:kf,props:{preview:Object},methods:{action(t){if("replace"===t)this.$refs.upload.open({url:this.$urls.api+"/"+this.id,accept:"."+this.model.extension+","+this.model.mime,multiple:!1})},onUpload(){this.$store.dispatch("notification/success",":)"),this.$reload()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-inside",{scopedSlots:t._u([{key:"footer",fn:function(){return[n("k-form-buttons",{attrs:{lock:t.lock}})]},proxy:!0}])},[n("div",{staticClass:"k-file-view",attrs:{"data-locked":t.isLocked,"data-id":t.model.id,"data-template":t.blueprint}},[n("k-file-preview",t._b({},"k-file-preview",t.preview,!1)),n("k-view",{staticClass:"k-file-content"},[n("k-header",{attrs:{editable:t.permissions.changeName&&!t.isLocked,tab:t.tab.name,tabs:t.tabs},on:{edit:function(e){return t.$dialog(t.id+"/changeName")}},scopedSlots:t._u([{key:"left",fn:function(){return[n("k-button-group",[n("k-button",{staticClass:"k-file-view-options",attrs:{link:t.preview.url,responsive:!0,text:t.$t("open"),icon:"open",target:"_blank"}}),n("k-dropdown",{staticClass:"k-file-view-options"},[n("k-button",{attrs:{disabled:t.isLocked,responsive:!0,text:t.$t("settings"),icon:"cog"},on:{click:function(e){return t.$refs.settings.toggle()}}}),n("k-dropdown-content",{ref:"settings",attrs:{options:t.$dropdown(t.id)},on:{action:t.action}})],1),n("k-languages-dropdown")],1)]},proxy:!0},{key:"right",fn:function(){return[n("k-prev-next",{attrs:{prev:t.prev,next:t.next}})]},proxy:!0}])},[t._v(" "+t._s(t.model.filename)+" ")]),n("k-sections",{attrs:{blueprint:t.blueprint,empty:t.$t("file.blueprint",{blueprint:t.$esc(t.blueprint)}),lock:t.lock,parent:t.id,tab:t.tab}}),n("k-upload",{ref:"upload",on:{success:t.onUpload}})],1)],1)])}),[],!1,Mf,null,null,null);function Mf(t){for(let e in Tf)this[e]=Tf[e]}var Lf=function(){return If.exports}();const jf={props:{isInstallable:Boolean,isInstalled:Boolean,isOk:Boolean,requirements:Object,translations:Array},data(){return{user:{name:"",email:"",language:this.$translation.code,password:"",role:"admin"}}},computed:{fields(){return{email:{label:this.$t("email"),type:"email",link:!1,autofocus:!0,required:!0},password:{label:this.$t("password"),type:"password",placeholder:this.$t("password")+" …",required:!0},language:{label:this.$t("language"),type:"select",options:this.translations,icon:"globe",empty:!1,required:!0}}},isReady(){return this.isOk&&this.isInstallable},isComplete(){return this.isOk&&this.isInstalled}},methods:{async install(){try{await this.$api.system.install(this.user),await this.$reload({globals:["$system","$translation"]}),this.$store.dispatch("notification/success",this.$t("welcome")+"!")}catch(t){this.$store.dispatch("notification/error",t)}}}},Df={};var Bf=Ft(jf,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-panel",[n("k-view",{staticClass:"k-installation-view",attrs:{align:"center"}},[t.isComplete?n("k-text",[n("k-headline",[t._v(t._s(t.$t("installation.completed")))]),n("k-link",{attrs:{to:"/login"}},[t._v(" "+t._s(t.$t("login"))+" ")])],1):t.isReady?n("form",{on:{submit:function(e){return e.preventDefault(),t.install.apply(null,arguments)}}},[n("h1",{staticClass:"sr-only"},[t._v(" "+t._s(t.$t("installation"))+" ")]),n("k-fieldset",{attrs:{fields:t.fields,novalidate:!0},model:{value:t.user,callback:function(e){t.user=e},expression:"user"}}),n("k-button",{attrs:{text:t.$t("install"),type:"submit",icon:"check"}})],1):n("div",[n("k-headline",[t._v(" "+t._s(t.$t("installation.issues.headline"))+" ")]),n("ul",{staticClass:"k-installation-issues"},[!1===t.isInstallable?n("li",[n("k-icon",{attrs:{type:"alert"}}),n("span",{domProps:{innerHTML:t._s(t.$t("installation.disabled"))}})],1):t._e(),!1===t.requirements.php?n("li",[n("k-icon",{attrs:{type:"alert"}}),n("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.php"))}})],1):t._e(),!1===t.requirements.server?n("li",[n("k-icon",{attrs:{type:"alert"}}),n("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.server"))}})],1):t._e(),!1===t.requirements.mbstring?n("li",[n("k-icon",{attrs:{type:"alert"}}),n("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.mbstring"))}})],1):t._e(),!1===t.requirements.curl?n("li",[n("k-icon",{attrs:{type:"alert"}}),n("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.curl"))}})],1):t._e(),!1===t.requirements.accounts?n("li",[n("k-icon",{attrs:{type:"alert"}}),n("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.accounts"))}})],1):t._e(),!1===t.requirements.content?n("li",[n("k-icon",{attrs:{type:"alert"}}),n("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.content"))}})],1):t._e(),!1===t.requirements.media?n("li",[n("k-icon",{attrs:{type:"alert"}}),n("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.media"))}})],1):t._e(),!1===t.requirements.sessions?n("li",[n("k-icon",{attrs:{type:"alert"}}),n("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.sessions"))}})],1):t._e()]),n("k-button",{attrs:{text:t.$t("retry"),icon:"refresh"},on:{click:t.$reload}})],1)],1)],1)}),[],!1,Pf,null,null,null);function Pf(t){for(let e in Df)this[e]=Df[e]}var Nf=function(){return Bf.exports}();const qf={};var Ff=Ft({props:{languages:{type:Array,default:()=>[]}},computed:{languagesCollection(){return this.languages.map((t=>l(a({},t),{image:{back:"black",color:"gray",icon:"globe"},link:()=>{this.$dialog(`languages/${t.id}/update`)},options:[{icon:"edit",text:this.$t("edit"),click(){this.$dialog(`languages/${t.id}/update`)}},{icon:"trash",text:this.$t("delete"),disabled:t.default&&1!==this.languages.length,click(){this.$dialog(`languages/${t.id}/delete`)}}]})))},primaryLanguage(){return this.languagesCollection.filter((t=>t.default))},secondaryLanguages(){return this.languagesCollection.filter((t=>!1===t.default))}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-inside",[n("k-view",{staticClass:"k-languages-view"},[n("k-header",[t._v(" "+t._s(t.$t("view.languages"))+" "),n("k-button-group",{attrs:{slot:"left"},slot:"left"},[n("k-button",{attrs:{text:t.$t("language.create"),icon:"add"},on:{click:function(e){return t.$dialog("languages/create")}}})],1)],1),n("section",{staticClass:"k-languages"},[t.languages.length>0?[n("section",{staticClass:"k-languages-view-section"},[n("header",{staticClass:"k-languages-view-section-header"},[n("k-headline",[t._v(t._s(t.$t("languages.default")))])],1),n("k-collection",{attrs:{items:t.primaryLanguage}})],1),n("section",{staticClass:"k-languages-view-section"},[n("header",{staticClass:"k-languages-view-section-header"},[n("k-headline",[t._v(t._s(t.$t("languages.secondary")))])],1),t.secondaryLanguages.length?n("k-collection",{attrs:{items:t.secondaryLanguages}}):n("k-empty",{attrs:{icon:"globe"},on:{click:function(e){return t.$dialog("languages/create")}}},[t._v(" "+t._s(t.$t("languages.secondary.empty"))+" ")])],1)]:0===t.languages.length?[n("k-empty",{attrs:{icon:"globe"},on:{click:function(e){return t.$dialog("languages/create")}}},[t._v(" "+t._s(t.$t("languages.empty"))+" ")])]:t._e()],2)],1)],1)}),[],!1,Rf,null,null,null);function Rf(t){for(let e in qf)this[e]=qf[e]}var zf=function(){return Ff.exports}(),Yf=function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-panel",["login"===t.form?n("k-view",{staticClass:"k-login-view",attrs:{align:"center"}},[n("k-login-plugin",{attrs:{methods:t.methods}})],1):"code"===t.form?n("k-view",{staticClass:"k-login-code-view",attrs:{align:"center"}},[n("k-login-code",t._b({},"k-login-code",t.$props,!1))],1):t._e()],1)},Hf=[];const Uf={components:{"k-login-plugin":window.panel.plugins.login||Un},props:{methods:Array,pending:Object},computed:{form(){return this.pending.email?"code":this.$user?null:"login"}},created(){this.$store.dispatch("content/clear")}},Kf={};var Jf=Ft(Uf,Yf,Hf,!1,Gf,null,null,null);function Gf(t){for(let e in Kf)this[e]=Kf[e]}var Vf=function(){return Jf.exports}();const Wf={};var Xf=Ft({extends:kf,props:{status:Object},computed:{protectedFields:()=>["title"]}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-inside",{scopedSlots:t._u([{key:"footer",fn:function(){return[n("k-form-buttons",{attrs:{lock:t.lock}})]},proxy:!0}])},[n("k-view",{staticClass:"k-page-view",attrs:{"data-locked":t.isLocked,"data-id":t.model.id,"data-template":t.blueprint}},[n("k-header",{attrs:{editable:t.permissions.changeTitle&&!t.isLocked,tab:t.tab.name,tabs:t.tabs},on:{edit:function(e){return t.$dialog(t.id+"/changeTitle")}},scopedSlots:t._u([{key:"left",fn:function(){return[n("k-button-group",[t.permissions.preview&&t.model.previewUrl?n("k-button",{staticClass:"k-page-view-preview",attrs:{link:t.model.previewUrl,responsive:!0,text:t.$t("open"),icon:"open",target:"_blank"}}):t._e(),t.status?n("k-status-icon",{attrs:{status:t.model.status,disabled:!t.permissions.changeStatus||t.isLocked,responsive:!0,text:t.status.label},on:{click:function(e){return t.$dialog(t.id+"/changeStatus")}}}):t._e(),n("k-dropdown",{staticClass:"k-page-view-options"},[n("k-button",{attrs:{disabled:!0===t.isLocked,responsive:!0,text:t.$t("settings"),icon:"cog"},on:{click:function(e){return t.$refs.settings.toggle()}}}),n("k-dropdown-content",{ref:"settings",attrs:{options:t.$dropdown(t.id)}})],1),n("k-languages-dropdown")],1)]},proxy:!0},{key:"right",fn:function(){return[t.model.id?n("k-prev-next",{attrs:{prev:t.prev,next:t.next}}):t._e()]},proxy:!0}])},[t._v(" "+t._s(t.model.title)+" ")]),n("k-sections",{attrs:{blueprint:t.blueprint,empty:t.$t("page.blueprint",{blueprint:t.$esc(t.blueprint)}),lock:t.lock,parent:t.id,tab:t.tab}})],1)],1)}),[],!1,Zf,null,null,null);function Zf(t){for(let e in Wf)this[e]=Wf[e]}var Qf=function(){return Xf.exports}();const tm={};var em=Ft({props:{id:String},computed:{view(){return"k-"+this.id+"-plugin-view"}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-inside",[n(t.view,{tag:"component"})],1)}),[],!1,nm,null,null,null);function nm(t){for(let e in tm)this[e]=tm[e]}var im=function(){return em.exports}();const sm={};var om=Ft({data:()=>({isLoading:!1,issue:"",values:{password:null,passwordConfirmation:null}}),computed:{fields(){return{password:{autofocus:!0,label:this.$t("user.changePassword.new"),icon:"key",type:"password"},passwordConfirmation:{label:this.$t("user.changePassword.new.confirm"),icon:"key",type:"password"}}}},mounted(){this.$store.dispatch("title",this.$t("view.resetPassword"))},methods:{async submit(){if(!this.values.password||this.values.password.length<8)return this.issue=this.$t("error.user.password.invalid"),!1;if(this.values.password!==this.values.passwordConfirmation)return this.issue=this.$t("error.user.password.notSame"),!1;this.isLoading=!0;try{await this.$api.users.changePassword(this.$user.id,this.values.password),this.$store.dispatch("notification/success",":)"),this.$go("/")}catch(t){this.issue=t.message}finally{this.isLoading=!1}}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-inside",[n("k-view",{staticClass:"k-password-reset-view",attrs:{align:"center"}},[n("k-form",{attrs:{fields:t.fields,"submit-button":t.$t("change")},on:{submit:t.submit},scopedSlots:t._u([{key:"header",fn:function(){return[n("h1",{staticClass:"sr-only"},[t._v(" "+t._s(t.$t("view.resetPassword"))+" ")]),t.issue?n("k-login-alert",{on:{click:function(e){t.issue=null}}},[t._v(" "+t._s(t.issue)+" ")]):t._e(),n("k-user-info",{attrs:{user:t.$user}})]},proxy:!0},{key:"footer",fn:function(){return[n("div",{staticClass:"k-login-buttons"},[n("k-button",{staticClass:"k-login-button",attrs:{icon:"check",type:"submit"}},[t._v(" "+t._s(t.$t("change"))+" "),t.isLoading?[t._v(" … ")]:t._e()],2)],1)]},proxy:!0}]),model:{value:t.values,callback:function(e){t.values=e},expression:"values"}})],1)],1)}),[],!1,rm,null,null,null);function rm(t){for(let e in sm)this[e]=sm[e]}var am=function(){return om.exports}();const lm={};var um=Ft({extends:kf,computed:{protectedFields:()=>["title"]}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-inside",{scopedSlots:t._u([{key:"footer",fn:function(){return[n("k-form-buttons",{attrs:{lock:t.lock}})]},proxy:!0}])},[n("k-view",{staticClass:"k-site-view",attrs:{"data-locked":t.isLocked,"data-id":"/","data-template":"site"}},[n("k-header",{attrs:{editable:t.permissions.changeTitle&&!t.isLocked,tabs:t.tabs,tab:t.tab.name},on:{edit:function(e){return t.$dialog("site/changeTitle")}},scopedSlots:t._u([{key:"left",fn:function(){return[n("k-button-group",[n("k-button",{staticClass:"k-site-view-preview",attrs:{link:t.model.previewUrl,responsive:!0,text:t.$t("open"),icon:"open",target:"_blank"}}),n("k-languages-dropdown")],1)]},proxy:!0}])},[t._v(" "+t._s(t.model.title)+" ")]),n("k-sections",{attrs:{blueprint:t.blueprint,empty:t.$t("site.blueprint"),lock:t.lock,tab:t.tab,parent:"site"},on:{submit:function(e){return t.$emit("submit",e)}}})],1)],1)}),[],!1,cm,null,null,null);function cm(t){for(let e in lm)this[e]=lm[e]}var dm=function(){return um.exports}();const pm={props:{debug:Boolean,license:String,php:String,plugins:Array,server:String,https:Boolean,urls:Object,version:String},data:()=>({security:[]}),computed:{environment(){return[{label:this.$t("license"),value:this.license?"Kirby 3":this.$t("license.unregistered.label"),theme:this.license?null:"negative",click:this.license?()=>this.$dialog("license"):()=>this.$dialog("registration")},{label:this.$t("version"),value:this.version,link:"https://github.com/getkirby/kirby/releases/tag/"+this.version},{label:"PHP",value:this.php},{label:this.$t("server"),value:this.server||"?"}]}},async created(){console.info("Running system health checks for the Panel system view; failed requests in the following console output are expected behavior.");let t=(Promise.allSettled||Promise.all).bind(Promise);await t([this.check("content"),this.check("debug"),this.check("git"),this.check("https"),this.check("kirby"),this.check("site")]),console.info("System health checks ended.")},methods:{async check(t){switch(t){case"debug":!0===this.debug&&this.securityIssue(t);break;case"https":!0!==this.https&&this.securityIssue(t);break;default:const e=this.urls[t];if(!e)return!1;!0===await this.isAccessible(e)&&this.securityIssue(t)}},securityIssue(t){this.security.push({image:{back:"var(--color-red-200)",icon:"alert",color:"var(--color-red)"},id:t,text:this.$t("system.issues."+t),link:"https://getkirby.com/security/"+t})},isAccessible:async t=>(await fetch(t,{cache:"no-store"})).status<400,retry(){this.$go(window.location.href)}}},hm={};var fm=Ft(pm,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-inside",[n("k-view",{staticClass:"k-system-view"},[n("k-header",[t._v(" "+t._s(t.$t("view.system"))+" ")]),n("section",{staticClass:"k-system-view-section"},[n("header",{staticClass:"k-system-view-section-header"},[n("k-headline",[t._v(t._s(t.$t("environment")))])],1),n("k-stats",{staticClass:"k-system-info",attrs:{reports:t.environment,size:"medium"}})],1),t.security.length?n("section",{staticClass:"k-system-view-section"},[n("header",{staticClass:"k-system-view-section-header"},[n("k-headline",[t._v(t._s(t.$t("security")))]),n("k-button",{attrs:{tooltip:t.$t("retry"),icon:"refresh"},on:{click:t.retry}})],1),n("k-items",{attrs:{items:t.security}})],1):t._e(),t.plugins.length?n("section",{staticClass:"k-system-view-section"},[n("header",{staticClass:"k-system-view-section-header"},[n("k-headline",{attrs:{link:"https://getkirby.com/plugins"}},[t._v(" "+t._s(t.$t("plugins"))+" ")])],1),n("k-table",{attrs:{index:!1,columns:{name:{label:t.$t("name"),type:"url",mobile:!0},author:{label:t.$t("author")},license:{label:t.$t("license")},version:{label:t.$t("version"),width:"8rem",mobile:!0}},rows:t.plugins}})],1):t._e()],1)],1)}),[],!1,mm,null,null,null);function mm(t){for(let e in hm)this[e]=hm[e]}var gm=function(){return fm.exports}();const km={};var vm=Ft({props:{role:Object,roles:Array,search:String,title:String,users:Object},computed:{items(){return this.users.data.map((t=>(t.options=this.$dropdown(t.link),t)))}},methods:{paginate(t){this.$reload({query:{page:t.page}})}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-inside",[n("k-view",{staticClass:"k-users-view"},[n("k-header",{scopedSlots:t._u([{key:"left",fn:function(){return[n("k-button-group",{attrs:{buttons:[{disabled:!1===t.$permissions.users.create,text:t.$t("user.create"),icon:"add",click:function(){return t.$dialog("users/create")}}]}})]},proxy:!0},{key:"right",fn:function(){return[n("k-button-group",[n("k-dropdown",[n("k-button",{attrs:{responsive:!0,text:`${t.$t("role")}: ${t.role?t.role.title:t.$t("role.all")}`,icon:"funnel"},on:{click:function(e){return t.$refs.roles.toggle()}}}),n("k-dropdown-content",{ref:"roles",attrs:{align:"right"}},[n("k-dropdown-item",{attrs:{icon:"bolt",link:"/users"}},[t._v(" "+t._s(t.$t("role.all"))+" ")]),n("hr"),t._l(t.roles,(function(e){return n("k-dropdown-item",{key:e.id,attrs:{link:"/users/?role="+e.id,icon:"bolt"}},[t._v(" "+t._s(e.title)+" ")])}))],2)],1)],1)]},proxy:!0}])},[t._v(" "+t._s(t.$t("view.users"))+" ")]),t.users.data.length>0?[n("k-collection",{attrs:{items:t.items,pagination:t.users.pagination},on:{paginate:t.paginate}})]:0===t.users.pagination.total?[n("k-empty",{attrs:{icon:"users"}},[t._v(" "+t._s(t.$t("role.empty"))+" ")])]:t._e()],2)],1)}),[],!1,bm,null,null,null);function bm(t){for(let e in km)this[e]=km[e]}var ym=function(){return vm.exports}();const $m={};var _m=Ft({computed:{placeholder(){return this.field("code",{}).placeholder},languages(){return this.field("language",{options:[]}).options}},methods:{focus(){this.$refs.code.focus()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-block-type-code-editor"},[n("k-input",{ref:"code",attrs:{buttons:!1,placeholder:t.placeholder,spellcheck:!1,value:t.content.code,type:"textarea"},on:{input:function(e){return t.update({code:e})}}}),t.languages.length?n("div",{staticClass:"k-block-type-code-editor-language"},[n("k-icon",{attrs:{type:"code"}}),n("k-input",{ref:"language",attrs:{empty:!1,options:t.languages,value:t.content.language,type:"select"},on:{input:function(e){return t.update({language:e})}}})],1):t._e()],1)}),[],!1,xm,null,null,null);function xm(t){for(let e in $m)this[e]=$m[e]}var wm=function(){return _m.exports}(),Sm=Object.freeze(Object.defineProperty({__proto__:null,default:wm},Symbol.toStringTag,{value:"Module"}));const Cm={};var Om=Ft({},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-block-title",{attrs:{content:t.content,fieldset:t.fieldset},on:{dblclick:function(e){return t.$emit("open")}}})}),[],!1,Em,null,null,null);function Em(t){for(let e in Cm)this[e]=Cm[e]}var Am=function(){return Om.exports}(),Tm=Object.freeze(Object.defineProperty({__proto__:null,default:Am},Symbol.toStringTag,{value:"Module"}));const Im={};var Mm=Ft({},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("ul",{on:{dblclick:t.open}},[0===t.content.images.length?[n("li"),n("li"),n("li"),n("li"),n("li")]:t._l(t.content.images,(function(t){return n("li",{key:t.id},[n("img",{attrs:{src:t.url,srcset:t.image.srcset,alt:t.alt}})])}))],2)}),[],!1,Lm,null,null,null);function Lm(t){for(let e in Im)this[e]=Im[e]}var jm=function(){return Mm.exports}(),Dm=Object.freeze(Object.defineProperty({__proto__:null,default:jm},Symbol.toStringTag,{value:"Module"}));const Bm={};var Pm=Ft({computed:{textField(){return this.field("text",{marks:!0})}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-block-type-heading-input",attrs:{"data-level":t.content.level}},[n("k-writer",{ref:"input",attrs:{inline:!0,marks:t.textField.marks,placeholder:t.textField.placeholder,value:t.content.text},on:{input:function(e){return t.update({text:e})}}})],1)}),[],!1,Nm,null,null,null);function Nm(t){for(let e in Bm)this[e]=Bm[e]}var qm=function(){return Pm.exports}(),Fm=Object.freeze(Object.defineProperty({__proto__:null,default:qm},Symbol.toStringTag,{value:"Module"}));const Rm={};var zm=Ft({computed:{captionMarks(){return this.field("caption",{marks:!0}).marks},crop(){return this.content.crop||!1},src(){var t;return"web"===this.content.location?this.content.src:!!(null==(t=this.content.image[0])?void 0:t.url)&&this.content.image[0].url},ratio(){return this.content.ratio||!1}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-block-figure",{attrs:{caption:t.content.caption,"caption-marks":t.captionMarks,"empty-text":t.$t("field.blocks.image.placeholder")+" …","is-empty":!t.src,"empty-icon":"image"},on:{open:t.open,update:t.update}},[t.src?[t.ratio?n("k-aspect-ratio",{attrs:{ratio:t.ratio,cover:t.crop}},[n("img",{attrs:{alt:t.content.alt,src:t.src}})]):n("img",{staticClass:"k-block-type-image-auto",attrs:{alt:t.content.alt,src:t.src}})]:t._e()],2)}),[],!1,Ym,null,null,null);function Ym(t){for(let e in Rm)this[e]=Rm[e]}var Hm=function(){return zm.exports}(),Um=Object.freeze(Object.defineProperty({__proto__:null,default:Hm},Symbol.toStringTag,{value:"Module"}));const Km={};var Jm=Ft({},(function(){var t=this;t.$createElement;return t._self._c,t._m(0)}),[function(){var t=this.$createElement,e=this._self._c||t;return e("div",[e("hr")])}],!1,Gm,null,null,null);function Gm(t){for(let e in Km)this[e]=Km[e]}var Vm=function(){return Jm.exports}(),Wm=Object.freeze(Object.defineProperty({__proto__:null,default:Vm},Symbol.toStringTag,{value:"Module"}));const Xm={};var Zm=Ft({computed:{marks(){return this.field("text",{}).marks}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-input",{ref:"input",staticClass:"k-block-type-list-input",attrs:{marks:t.marks,value:t.content.text,type:"list"},on:{input:function(e){return t.update({text:e})}}})}),[],!1,Qm,null,null,null);function Qm(t){for(let e in Xm)this[e]=Xm[e]}var tg=function(){return Zm.exports}(),eg=Object.freeze(Object.defineProperty({__proto__:null,default:tg},Symbol.toStringTag,{value:"Module"}));const ng={};var ig=Ft({computed:{placeholder(){return this.field("text",{}).placeholder}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-input",{ref:"input",staticClass:"k-block-type-markdown-input",attrs:{buttons:!1,placeholder:t.placeholder,spellcheck:!1,value:t.content.text,type:"textarea"},on:{input:function(e){return t.update({text:e})}}})}),[],!1,sg,null,null,null);function sg(t){for(let e in ng)this[e]=ng[e]}var og=function(){return ig.exports}(),rg=Object.freeze(Object.defineProperty({__proto__:null,default:og},Symbol.toStringTag,{value:"Module"}));const ag={};var lg=Ft({computed:{citationField(){return this.field("citation",{})},textField(){return this.field("text",{})}},methods:{focus(){this.$refs.text.focus()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-block-type-quote-editor"},[n("k-writer",{ref:"text",staticClass:"k-block-type-quote-text",attrs:{inline:!0,marks:t.textField.marks,placeholder:t.textField.placeholder,value:t.content.text},on:{input:function(e){return t.update({text:e})}}}),n("k-writer",{ref:"citation",staticClass:"k-block-type-quote-citation",attrs:{inline:!0,marks:t.citationField.marks,placeholder:t.citationField.placeholder,value:t.content.citation},on:{input:function(e){return t.update({citation:e})}}})],1)}),[],!1,ug,null,null,null);function ug(t){for(let e in ag)this[e]=ag[e]}var cg=function(){return lg.exports}(),dg=Object.freeze(Object.defineProperty({__proto__:null,default:cg},Symbol.toStringTag,{value:"Module"}));const pg={};var hg=Ft({inheritAttrs:!1,computed:{columns(){return this.table.columns||this.fields},fields(){return this.table.fields||{}},rows(){return this.content.rows||[]},table(){let t=null;for(const e of Object.values(this.fieldset.tabs))e.fields.rows&&(t=e.fields.rows);return t||{}}}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-table",{staticClass:"k-block-type-table-preview",attrs:{columns:t.columns,empty:t.$t("field.structure.empty"),rows:t.rows},nativeOn:{dblclick:function(e){return t.open.apply(null,arguments)}}})}),[],!1,fg,null,null,null);function fg(t){for(let e in pg)this[e]=pg[e]}var mg=function(){return hg.exports}(),gg=Object.freeze(Object.defineProperty({__proto__:null,default:mg},Symbol.toStringTag,{value:"Module"}));const kg={};var vg=Ft({props:{endpoints:Object},computed:{textField(){return this.field("text",{})}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-writer",{ref:"input",staticClass:"k-block-type-text-input",attrs:{inline:t.textField.inline,marks:t.textField.marks,nodes:t.textField.nodes,placeholder:t.textField.placeholder,value:t.content.text},on:{input:function(e){return t.update({text:e})}}})}),[],!1,bg,null,null,null);function bg(t){for(let e in kg)this[e]=kg[e]}var yg=function(){return vg.exports}(),$g=Object.freeze(Object.defineProperty({__proto__:null,default:yg},Symbol.toStringTag,{value:"Module"}));const _g={};var xg=Ft({computed:{captionMarks(){return this.field("caption",{marks:!0}).marks},video(){return this.$helper.embed.video(this.content.url,!0)}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-block-figure",{attrs:{caption:t.content.caption,"caption-marks":t.captionMarks,"empty-text":t.$t("field.blocks.video.placeholder")+" …","is-empty":!t.video,"empty-icon":"video"},on:{open:t.open,update:t.update}},[n("k-aspect-ratio",{attrs:{ratio:"16/9"}},[t.video?n("iframe",{attrs:{src:t.video,referrerpolicy:"strict-origin-when-cross-origin"}}):t._e()])],1)}),[],!1,wg,null,null,null);function wg(t){for(let e in _g)this[e]=_g[e]}var Sg=function(){return xg.exports}(),Cg=Object.freeze(Object.defineProperty({__proto__:null,default:Sg},Symbol.toStringTag,{value:"Module"}));const Og={inheritAttrs:!1,props:{attrs:[Array,Object],content:[Array,Object],endpoints:Object,fieldset:Object,id:String,isBatched:Boolean,isFull:Boolean,isHidden:Boolean,isLastInBatch:Boolean,isSelected:Boolean,name:String,next:Object,prev:Object,type:String},data:()=>({skipFocus:!1}),computed:{className(){let t=["k-block-type-"+this.type];return this.fieldset.preview!==this.type&&t.push("k-block-type-"+this.fieldset.preview),!1===this.wysiwyg&&t.push("k-block-type-default"),t},customComponent(){return this.wysiwyg?this.wysiwygComponent:"k-block-type-default"},isEditable(){return!1!==this.fieldset.editable},listeners(){return l(a({},this.$listeners),{confirmToRemove:this.confirmToRemove,open:this.open})},tabs(){let t=this.fieldset.tabs;return Object.entries(t).forEach((([e,n])=>{Object.entries(n.fields).forEach((([n])=>{t[e].fields[n].section=this.name,t[e].fields[n].endpoints={field:this.endpoints.field+"/fieldsets/"+this.type+"/fields/"+n,section:this.endpoints.section,model:this.endpoints.model}}))})),t},wysiwyg(){return!1!==this.wysiwygComponent},wysiwygComponent(){if(!1===this.fieldset.preview)return!1;let t;return this.fieldset.preview&&(t="k-block-type-"+this.fieldset.preview,this.$helper.isComponent(t))?t:(t="k-block-type-"+this.type,!!this.$helper.isComponent(t)&&t)}},methods:{close(){this.$refs.drawer.close()},confirmToRemove(){this.$refs.removeDialog.open()},focus(){!0!==this.skipFocus&&("function"==typeof this.$refs.editor.focus?this.$refs.editor.focus():this.$refs.container.focus())},onFocusIn(t){var e,n;(null==(n=null==(e=this.$refs.options)?void 0:e.$el)?void 0:n.contains(t.target))||this.$emit("focus",t)},goTo(t){t&&(this.skipFocus=!0,this.close(),this.$nextTick((()=>{t.$refs.container.focus(),t.open(),this.skipFocus=!1})))},open(){var t;null==(t=this.$refs.drawer)||t.open()},remove(){this.$refs.removeDialog.close(),this.$emit("remove",this.id)}}},Eg={};var Ag=Ft(Og,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{ref:"container",staticClass:"k-block-container",class:"k-block-container-type-"+t.type,attrs:{"data-batched":t.isBatched,"data-disabled":t.fieldset.disabled,"data-hidden":t.isHidden,"data-id":t.id,"data-last-in-batch":t.isLastInBatch,"data-selected":t.isSelected,"data-translate":t.fieldset.translate,tabindex:"0"},on:{keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"down",40,e.key,["Down","ArrowDown"])?null:e.ctrlKey&&e.shiftKey?(e.preventDefault(),t.$emit("sortDown")):null},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"up",38,e.key,["Up","ArrowUp"])?null:e.ctrlKey&&e.shiftKey?(e.preventDefault(),t.$emit("sortUp")):null}],focus:function(e){return t.$emit("focus")},focusin:t.onFocusIn}},[n("div",{staticClass:"k-block",class:t.className},[n(t.customComponent,t._g(t._b({ref:"editor",tag:"component"},"component",t.$props,!1),t.listeners))],1),n("k-block-options",t._g({ref:"options",attrs:{"is-batched":t.isBatched,"is-editable":t.isEditable,"is-full":t.isFull,"is-hidden":t.isHidden}},t.listeners)),t.isEditable&&!t.isBatched?n("k-form-drawer",{ref:"drawer",staticClass:"k-block-drawer",attrs:{id:t.id,icon:t.fieldset.icon||"box",tabs:t.tabs,title:t.fieldset.name,value:t.content},on:{close:function(e){return t.focus()},input:function(e){return t.$emit("update",e)}},scopedSlots:t._u([{key:"options",fn:function(){return[t.isHidden?n("k-button",{staticClass:"k-drawer-option",attrs:{icon:"hidden"},on:{click:function(e){return t.$emit("show")}}}):t._e(),n("k-button",{staticClass:"k-drawer-option",attrs:{disabled:!t.prev,icon:"angle-left"},on:{click:function(e){return e.preventDefault(),e.stopPropagation(),t.goTo(t.prev)}}}),n("k-button",{staticClass:"k-drawer-option",attrs:{disabled:!t.next,icon:"angle-right"},on:{click:function(e){return e.preventDefault(),e.stopPropagation(),t.goTo(t.next)}}}),n("k-button",{staticClass:"k-drawer-option",attrs:{icon:"trash"},on:{click:function(e){return e.preventDefault(),e.stopPropagation(),t.confirmToRemove.apply(null,arguments)}}})]},proxy:!0}],null,!1,2211169536)}):t._e(),n("k-remove-dialog",{ref:"removeDialog",attrs:{text:t.$t("field.blocks.delete.confirm")},on:{submit:t.remove}})],1)}),[],!1,Tg,null,null,null);function Tg(t){for(let e in Eg)this[e]=Eg[e]}var Ig=function(){return Ag.exports}();const Mg={};var Lg=Ft({inheritAttrs:!1,computed:{shortcut(){return this.$helper.keyboard.metaKey()+"+v"}},methods:{close(){this.$refs.dialog.close()},open(){this.$refs.dialog.open()},onPaste(t){this.$emit("paste",t),this.close()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-dialog",{ref:"dialog",staticClass:"k-block-importer",attrs:{"cancel-button":!1,"submit-button":!1,size:"large"}},[n("label",{attrs:{for:"pasteboard"},domProps:{innerHTML:t._s(t.$t("field.blocks.fieldsets.paste",{shortcut:t.shortcut}))}}),n("textarea",{attrs:{id:"pasteboard"},on:{paste:function(e){return e.preventDefault(),t.onPaste.apply(null,arguments)}}})])}),[],!1,jg,null,null,null);function jg(t){for(let e in Mg)this[e]=Mg[e]}const Dg={components:{"k-block-pasteboard":function(){return Lg.exports}()},inheritAttrs:!1,props:{autofocus:Boolean,empty:String,endpoints:Object,fieldsets:Object,fieldsetGroups:Object,group:String,max:{type:Number,default:null},value:{type:Array,default:()=>[]}},data(){return{isMultiSelectKey:!1,batch:[],blocks:this.value,current:null,isFocussed:!1}},computed:{draggableOptions(){return{id:this._uid,handle:".k-sort-handle",list:this.blocks,move:this.move,delay:10,data:{fieldsets:this.fieldsets,isFull:this.isFull},options:{group:this.group}}},hasFieldsets(){return Object.keys(this.fieldsets).length},isEditing(){return this.$store.state.dialog||this.$store.state.drawers.open.length>0},isEmpty(){return 0===this.blocks.length},isFull(){return null!==this.max&&this.blocks.length>=this.max},selected(){return this.current},selectedOrBatched(){return this.batch.length>0?this.batch:this.selected?[this.selected]:[]}},watch:{value(){this.blocks=this.value}},created(){this.$events.$on("copy",this.copy),this.$events.$on("focus",this.onOutsideFocus),this.$events.$on("keydown",this.onKey),this.$events.$on("keyup",this.onKey),this.$events.$on("paste",this.onPaste)},destroyed(){this.$events.$off("copy",this.copy),this.$events.$off("focus",this.onOutsideFocus),this.$events.$off("keydown",this.onKey),this.$events.$off("keyup",this.onKey),this.$events.$off("paste",this.onPaste)},mounted(){!0===this.$props.autofocus&&this.focus()},methods:{append(t,e){if("string"!=typeof t){if(Array.isArray(t)){let n=this.$helper.clone(t).map((t=>(t.id=this.$helper.uuid(),t)));const i=Object.keys(this.fieldsets);if(n=n.filter((t=>i.includes(t.type))),this.max){const t=this.max-this.blocks.length;n=n.slice(0,t)}this.blocks.splice(e,0,...n),this.save()}}else this.add(t,e)},async add(t="text",e){const n=await this.$api.get(this.endpoints.field+"/fieldsets/"+t);this.blocks.splice(e,0,n),this.save(),this.$nextTick((()=>{this.focusOrOpen(n)}))},addToBatch(t){null!==this.selected&&!1===this.batch.includes(this.selected)&&(this.batch.push(this.selected),this.current=null),!1===this.batch.includes(t.id)&&this.batch.push(t.id)},choose(t){if(1===Object.keys(this.fieldsets).length){const e=Object.values(this.fieldsets)[0].type;this.add(e,t)}else this.$refs.selector.open(t)},chooseToConvert(t){this.$refs.selector.open(t,{disabled:[t.type],headline:this.$t("field.blocks.changeType"),event:"convert"})},click(t){this.$emit("click",t)},confirmToRemoveAll(){this.$refs.removeAll.open()},confirmToRemoveSelected(){this.$refs.removeSelected.open()},copy(t){if(!0===this.isEditing)return!1;if(0===this.blocks.length)return!1;if(0===this.selectedOrBatched.length)return!1;if(!0===this.isInputEvent(t))return!1;let e=[];if(this.blocks.forEach((t=>{this.selectedOrBatched.includes(t.id)&&e.push(t)})),0===e.length)return!1;this.$helper.clipboard.write(e,t),t instanceof ClipboardEvent==!1&&(this.batch=this.selectedOrBatched),this.$store.dispatch("notification/success",`${e.length} copied!`)},copyAll(){this.selectAll(),this.copy(),this.deselectAll()},async convert(t,e){var n;const i=this.findIndex(e.id);if(-1===i)return!1;const s=t=>{var e;let n={};for(const i of Object.values(null!=(e=null==t?void 0:t.tabs)?e:{}))n=a(a({},n),i.fields);return n},o=this.blocks[i],r=await this.$api.get(this.endpoints.field+"/fieldsets/"+t),u=this.fieldsets[o.type],c=this.fieldsets[t];if(!c)return!1;let d=r.content;const p=s(c),h=s(u);for(const[a,l]of Object.entries(p)){const t=h[a];(null==t?void 0:t.type)===l.type&&(null==(n=null==o?void 0:o.content)?void 0:n[a])&&(d[a]=o.content[a])}this.blocks[i]=l(a({},r),{id:o.id,content:d}),this.save()},deselectAll(){this.batch=[],this.current=null},async duplicate(t,e){const n=l(a({},this.$helper.clone(t)),{id:this.$helper.uuid()});this.blocks.splice(e+1,0,n),this.save()},fieldset(t){return this.fieldsets[t.type]||{icon:"box",name:t.type,tabs:{content:{fields:{}}},type:t.type}},find(t){return this.blocks.find((e=>e.id===t))},findIndex(t){return this.blocks.findIndex((e=>e.id===t))},focus(t){(null==t?void 0:t.id)&&this.$refs["block-"+t.id]?this.$refs["block-"+t.id][0].focus():this.blocks[0]&&this.focus(this.blocks[0])},focusOrOpen(t){this.fieldsets[t.type].wysiwyg?this.focus(t):this.open(t)},hide(t){this.$set(t,"isHidden",!0),this.save()},isBatched(t){return this.batch.includes(t.id)},isInputEvent(){const t=document.querySelector(":focus");return t&&t.matches("input, textarea, [contenteditable], .k-writer")},isLastInBatch(t){const[e]=this.batch.slice(-1);return e&&t.id===e},isOnlyInstance:()=>1===document.querySelectorAll(".k-blocks").length,isSelected(t){return this.selected&&this.selected===t.id},move(t){if(t.from!==t.to){const e=t.draggedContext.element,n=t.relatedContext.component.componentData||t.relatedContext.component.$parent.componentData;if(!1===Object.keys(n.fieldsets).includes(e.type))return!1;if(!0===n.isFull)return!1}return!0},onKey(t){this.isMultiSelectKey=t.metaKey||t.ctrlKey||t.altKey},onOutsideFocus(t){if("function"==typeof t.target.closest&&t.target.closest(".k-dialog"))return;const e=document.querySelector(".k-overlay:last-of-type");if(!1===this.$el.contains(t.target)&&(!e||!1===e.contains(t.target)))return this.select(null);if(e){const e=this.$el.closest(".k-layout-column");if(!1===(null==e?void 0:e.contains(t.target)))return this.select(null)}},onPaste(t){var e;return!0!==this.isInputEvent(t)&&(!0===this.isEditing?!0===(null==(e=this.$refs.selector)?void 0:e.isOpen())&&this.paste(t):(0!==this.selectedOrBatched.length||!0===this.isOnlyInstance())&&this.paste(t))},open(t){this.$refs["block-"+t.id]&&this.$refs["block-"+t.id][0].open()},async paste(t){const e=this.$helper.clipboard.read(t),n=await this.$api.post(this.endpoints.field+"/paste",{html:e});let i=this.selectedOrBatched[this.selectedOrBatched.length-1],s=this.findIndex(i);-1===s&&(s=this.blocks.length),this.append(n,s+1)},pasteboard(){this.$refs.pasteboard.open()},prevNext(t){if(this.blocks[t]){let e=this.blocks[t];if(this.$refs["block-"+e.id])return this.$refs["block-"+e.id][0]}},remove(t){var e;const n=this.findIndex(t.id);-1!==n&&((null==(e=this.selected)?void 0:e.id)===t.id&&this.select(null),this.$delete(this.blocks,n),this.save())},removeAll(){this.batch=[],this.blocks=[],this.save(),this.$refs.removeAll.close()},removeSelected(){this.batch.forEach((t=>{const e=this.findIndex(t);-1!==e&&this.$delete(this.blocks,e)})),this.deselectAll(),this.save(),this.$refs.removeSelected.close()},save(){this.$emit("input",this.blocks)},select(t,e=null){if(e&&this.isMultiSelectKey&&this.onKey(e),t&&this.isMultiSelectKey)return this.addToBatch(t),void(this.current=null);this.batch=[],this.current=t?t.id:null},selectAll(){this.batch=Object.values(this.blocks).map((t=>t.id))},show(t){this.$set(t,"isHidden",!1),this.save()},sort(t,e,n){if(n<0)return;let i=this.$helper.clone(this.blocks);i.splice(e,1),i.splice(n,0,t),this.blocks=i,this.save(),this.$nextTick((()=>{this.focus(t)}))},update(t,e){const n=this.findIndex(t.id);-1!==n&&Object.entries(e).forEach((([t,e])=>{this.$set(this.blocks[n].content,t,e)})),this.save()}}},Bg={};var Pg=Ft(Dg,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{ref:"wrapper",staticClass:"k-blocks",attrs:{"data-empty":0===t.blocks.length,"data-multi-select-key":t.isMultiSelectKey},on:{focusin:function(e){t.focussed=!0},focusout:function(e){t.focussed=!1}}},[t.hasFieldsets?[n("k-draggable",t._b({staticClass:"k-blocks-list",on:{sort:t.save},scopedSlots:t._u([{key:"footer",fn:function(){return[n("k-empty",{staticClass:"k-blocks-empty",attrs:{icon:"box"},on:{click:function(e){return t.choose(t.blocks.length)}}},[t._v(" "+t._s(t.empty||t.$t("field.blocks.empty"))+" ")])]},proxy:!0}],null,!1,2413899928)},"k-draggable",t.draggableOptions,!1),t._l(t.blocks,(function(e,i){return n("k-block",t._b({key:e.id,ref:"block-"+e.id,refInFor:!0,attrs:{endpoints:t.endpoints,fieldset:t.fieldset(e),"is-batched":t.isBatched(e),"is-last-in-batch":t.isLastInBatch(e),"is-full":t.isFull,"is-hidden":!0===e.isHidden,"is-selected":t.isSelected(e),next:t.prevNext(i+1),prev:t.prevNext(i-1)},on:{append:function(e){return t.append(e,i+1)},blur:function(e){return t.select(null)},choose:function(e){return t.choose(e)},chooseToAppend:function(e){return t.choose(i+1)},chooseToConvert:function(n){return t.chooseToConvert(e)},chooseToPrepend:function(e){return t.choose(i)},copy:function(e){return t.copy()},confirmToRemoveSelected:t.confirmToRemoveSelected,duplicate:function(n){return t.duplicate(e,i)},focus:function(n){return t.select(e)},hide:function(n){return t.hide(e)},paste:function(e){return t.pasteboard()},prepend:function(e){return t.add(e,i)},remove:function(n){return t.remove(e)},sortDown:function(n){return t.sort(e,i,i+1)},sortUp:function(n){return t.sort(e,i,i-1)},show:function(n){return t.show(e)},update:function(n){return t.update(e,n)}},nativeOn:{click:function(n){return n.stopPropagation(),t.select(e,n)}}},"k-block",e,!1))})),1),n("k-block-selector",{ref:"selector",attrs:{fieldsets:t.fieldsets,"fieldset-groups":t.fieldsetGroups},on:{add:t.add,convert:t.convert,paste:function(e){return t.paste(e)}}}),n("k-remove-dialog",{ref:"removeAll",attrs:{text:t.$t("field.blocks.delete.confirm.all")},on:{submit:t.removeAll}}),n("k-remove-dialog",{ref:"removeSelected",attrs:{text:t.$t("field.blocks.delete.confirm.selected")},on:{submit:t.removeSelected}}),n("k-block-pasteboard",{ref:"pasteboard",on:{paste:function(e){return t.paste(e)}}})]:[n("k-box",{attrs:{theme:"info"}},[t._v(" No fieldsets yet ")])]],2)}),[],!1,Ng,null,null,null);function Ng(t){for(let e in Bg)this[e]=Bg[e]}var qg=function(){return Pg.exports}();const Fg={inheritAttrs:!1,props:{caption:String,captionMarks:[Boolean,Array],cover:{type:Boolean,default:!0},isEmpty:Boolean,emptyIcon:String,emptyText:String,ratio:String},computed:{ratioPadding(){return this.$helper.ratio(this.ratio||"16/9")}}},Rg={};var zg=Ft(Fg,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("figure",{staticClass:"k-block-figure"},[t.isEmpty?n("k-button",{staticClass:"k-block-figure-empty",attrs:{icon:t.emptyIcon,text:t.emptyText},on:{click:function(e){return t.$emit("open")}}}):n("span",{staticClass:"k-block-figure-container",on:{dblclick:function(e){return t.$emit("open")}}},[t._t("default")],2),t.caption?n("figcaption",[n("k-writer",{attrs:{inline:!0,marks:t.captionMarks,value:t.caption},on:{input:function(e){return t.$emit("update",{caption:e})}}})],1):t._e()],1)}),[],!1,Yg,null,null,null);function Yg(t){for(let e in Rg)this[e]=Rg[e]}var Hg=function(){return zg.exports}();const Ug={props:{isBatched:Boolean,isEditable:Boolean,isFull:Boolean,isHidden:Boolean},methods:{open(){this.$refs.options.open()}}},Kg={};var Jg=Ft(Ug,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-dropdown",{staticClass:"k-block-options"},[t.isBatched?[n("k-button",{staticClass:"k-block-options-button",attrs:{tooltip:t.$t("copy"),icon:"template"},on:{click:function(e){return e.preventDefault(),t.$emit("copy")}}}),n("k-button",{staticClass:"k-block-options-button",attrs:{tooltip:t.$t("remove"),icon:"trash"},on:{click:function(e){return e.preventDefault(),t.$emit("confirmToRemoveSelected")}}})]:[t.isEditable?n("k-button",{staticClass:"k-block-options-button",attrs:{tooltip:t.$t("edit"),icon:"edit"},on:{click:function(e){return t.$emit("open")}}}):t._e(),n("k-button",{staticClass:"k-block-options-button",attrs:{disabled:t.isFull,tooltip:t.$t("insert.after"),icon:"add"},on:{click:function(e){return t.$emit("chooseToAppend")}}}),n("k-button",{staticClass:"k-block-options-button",attrs:{tooltip:t.$t("delete"),icon:"trash"},on:{click:function(e){return t.$emit("confirmToRemove")}}}),n("k-button",{staticClass:"k-block-options-button",attrs:{tooltip:t.$t("more"),icon:"dots"},on:{click:function(e){return t.$refs.options.toggle()}}}),n("k-button",{staticClass:"k-block-options-button k-sort-handle",attrs:{tooltip:t.$t("sort"),icon:"sort"},on:{keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"up",38,e.key,["Up","ArrowUp"])?null:(e.preventDefault(),t.$emit("sortUp"))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"down",40,e.key,["Down","ArrowDown"])?null:(e.preventDefault(),t.$emit("sortDown"))}]}}),n("k-dropdown-content",{ref:"options",attrs:{align:"right"}},[n("k-dropdown-item",{attrs:{disabled:t.isFull,icon:"angle-up"},on:{click:function(e){return t.$emit("chooseToPrepend")}}},[t._v(" "+t._s(t.$t("insert.before"))+" ")]),n("k-dropdown-item",{attrs:{disabled:t.isFull,icon:"angle-down"},on:{click:function(e){return t.$emit("chooseToAppend")}}},[t._v(" "+t._s(t.$t("insert.after"))+" ")]),n("hr"),t.isEditable?n("k-dropdown-item",{attrs:{icon:"edit"},on:{click:function(e){return t.$emit("open")}}},[t._v(" "+t._s(t.$t("edit"))+" ")]):t._e(),n("k-dropdown-item",{attrs:{icon:"refresh"},on:{click:function(e){return t.$emit("chooseToConvert")}}},[t._v(" "+t._s(t.$t("field.blocks.changeType"))+" ")]),n("hr"),n("k-dropdown-item",{attrs:{icon:"template"},on:{click:function(e){return t.$emit("copy")}}},[t._v(" "+t._s(t.$t("copy"))+" ")]),n("k-dropdown-item",{attrs:{icon:"download"},on:{click:function(e){return t.$emit("paste")}}},[t._v(" "+t._s(t.$t("paste.after"))+" ")]),n("hr"),n("k-dropdown-item",{attrs:{icon:t.isHidden?"preview":"hidden"},on:{click:function(e){return t.$emit(t.isHidden?"show":"hide")}}},[t._v(" "+t._s(!0===t.isHidden?t.$t("show"):t.$t("hide"))+" ")]),n("k-dropdown-item",{attrs:{disabled:t.isFull,icon:"copy"},on:{click:function(e){return t.$emit("duplicate")}}},[t._v(" "+t._s(t.$t("duplicate"))+" ")]),n("hr"),n("k-dropdown-item",{attrs:{icon:"trash"},on:{click:function(e){return t.$emit("confirmToRemove")}}},[t._v(" "+t._s(t.$t("delete"))+" ")])],1)]],2)}),[],!1,Gg,null,null,null);function Gg(t){for(let e in Kg)this[e]=Kg[e]}var Vg=function(){return Jg.exports}();const Wg={};var Xg=Ft({inheritAttrs:!1,props:{endpoint:String,fieldsets:Object,fieldsetGroups:Object},data(){return{dialogIsOpen:!1,disabled:[],headline:null,payload:null,event:"add",groups:this.createGroups()}},computed:{shortcut(){return this.$helper.keyboard.metaKey()+"+v"}},methods:{add(t){this.$emit(this.event,t,this.payload),this.$refs.dialog.close()},close(){this.$refs.dialog.close()},createGroups(){let t={},e=0;const n=this.fieldsetGroups||{blocks:{label:this.$t("field.blocks.fieldsets.label"),sets:Object.keys(this.fieldsets)}};return Object.keys(n).forEach((i=>{let s=n[i];s.open=!1!==s.open,s.fieldsets=s.sets.filter((t=>this.fieldsets[t])).map((t=>(e++,l(a({},this.fieldsets[t]),{index:e})))),0!==s.fieldsets.length&&(t[i]=s)})),t},isOpen(){return this.dialogIsOpen},navigate(t){var e,n;null==(n=null==(e=this.$refs["fieldset-"+t])?void 0:e[0])||n.focus()},onClose(){this.dialogIsOpen=!1,this.$events.$off("paste",this.close)},onOpen(){this.dialogIsOpen=!0,this.$events.$on("paste",this.close)},open(t,e={}){const n=a({event:"add",disabled:[],headline:null},e);this.event=n.event,this.disabled=n.disabled,this.headline=n.headline,this.payload=t,this.$refs.dialog.open()}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("k-dialog",{ref:"dialog",staticClass:"k-block-selector",attrs:{"cancel-button":!1,"submit-button":!1,size:"medium"},on:{open:t.onOpen,close:t.onClose}},[t.headline?n("k-headline",[t._v(" "+t._s(t.headline)+" ")]):t._e(),t._l(t.groups,(function(e,i){return n("details",{key:i,attrs:{open:e.open}},[n("summary",[t._v(t._s(e.label))]),n("div",{staticClass:"k-block-types"},t._l(e.fieldsets,(function(e){return n("k-button",{key:e.name,ref:"fieldset-"+e.index,refInFor:!0,attrs:{disabled:t.disabled.includes(e.type),icon:e.icon||"box",text:e.name},on:{keydown:[function(n){return!n.type.indexOf("key")&&t._k(n.keyCode,"up",38,n.key,["Up","ArrowUp"])?null:t.navigate(e.index-1)},function(n){return!n.type.indexOf("key")&&t._k(n.keyCode,"down",40,n.key,["Down","ArrowDown"])?null:t.navigate(e.index+1)}],click:function(n){return t.add(e.type)}}})})),1)])})),n("p",{staticClass:"k-clipboard-hint",domProps:{innerHTML:t._s(t.$t("field.blocks.fieldsets.paste",{shortcut:t.shortcut}))}})],2)}),[],!1,Zg,null,null,null);function Zg(t){for(let e in Wg)this[e]=Wg[e]}var Qg=function(){return Xg.exports}();const tk={};var ek=Ft({inheritAttrs:!1,props:{fieldset:Object,content:Object},computed:{icon(){return this.fieldset.icon||"box"},label(){if(!this.fieldset.label||0===this.fieldset.label.length)return!1;if(this.fieldset.label===this.fieldset.name)return!1;const t=this.$helper.string.template(this.fieldset.label,this.content);return"…"!==t&&t},name(){return this.fieldset.name}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",t._g({staticClass:"k-block-title"},t.$listeners),[n("k-icon",{staticClass:"k-block-icon",attrs:{type:t.icon}}),n("span",{staticClass:"k-block-name"},[t._v(" "+t._s(t.name)+" ")]),t.label?n("span",{staticClass:"k-block-label"},[t._v(" "+t._s(t.label)+" ")]):t._e()],1)}),[],!1,nk,null,null,null);function nk(t){for(let e in tk)this[e]=tk[e]}var ik=function(){return ek.exports}();const sk={};var ok=Ft({inheritAttrs:!1,props:{content:[Object,Array],fieldset:Object},methods:{field(t,e=null){let n=null;return Object.values(this.fieldset.tabs).forEach((e=>{e.fields[t]&&(n=e.fields[t])})),n||e},open(){this.$emit("open")},update(t){this.$emit("update",a(a({},this.content),t))}}},undefined,undefined,!1,rk,null,null,null);function rk(t){for(let e in sk)this[e]=sk[e]}var ak=function(){return ok.exports}();u.component("k-block",Ig),u.component("k-blocks",qg),u.component("k-block-figure",Hg),u.component("k-block-options",Vg),u.component("k-block-selector",Qg),u.component("k-block-title",ik),u.component("k-block-type",ak);const lk={"./Types/Code.vue":Sm,"./Types/Default.vue":Tm,"./Types/Gallery.vue":Dm,"./Types/Heading.vue":Fm,"./Types/Image.vue":Um,"./Types/Line.vue":Wm,"./Types/List.vue":eg,"./Types/Markdown.vue":rg,"./Types/Quote.vue":dg,"./Types/Table.vue":gg,"./Types/Text.vue":$g,"./Types/Video.vue":Cg};Object.keys(lk).map((t=>{const e=t.match(/\/([a-zA-Z]*)\.vue/)[1].toLowerCase();let n=lk[t].default;n.extends=ak,u.component("k-block-type-"+e,n)}));var uk={inheritAttrs:!1,props:{column:{type:Object,default:()=>({})},field:Object,value:{}}};const ck={};var dk=Ft({inheritAttrs:!1,mixins:[uk],props:{value:[Array,String]},computed:{bubbles(){var t,e;let n=this.value;const i=(null==(t=this.column)?void 0:t.options)||(null==(e=this.field)?void 0:e.options)||[];return"string"==typeof n&&(n=n.split(",")),n.map((t=>{"string"==typeof t&&(t={value:t,text:t});for(const e of i)e.value===t.value&&(t.text=e.text);return a({back:"light",color:"black"},t)}))}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-bubbles-field-preview",class:t.$options.class},[n("k-bubbles",{attrs:{bubbles:t.bubbles}})],1)}),[],!1,pk,null,null,null);function pk(t){for(let e in ck)this[e]=ck[e]}var hk=function(){return dk.exports}();const fk={};var mk=Ft({inheritAttrs:!1,extends:hk,class:"k-array-field-preview",computed:{bubbles(){return[{text:1===this.value.length?`1 ${this.$t("entry")}`:`${this.value.length} ${this.$t("entries")}`}]}}},undefined,undefined,!1,gk,null,null,null);function gk(t){for(let e in fk)this[e]=fk[e]}var kk=function(){return mk.exports}();const vk={};var bk=Ft({mixins:[uk],inheritAttrs:!1,computed:{text(){return this.value}}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("p",{staticClass:"k-text-field-preview",class:t.$options.class},[t._v(" "+t._s(t.column.before)+" "),t._t("default",(function(){return[t._v(t._s(t.text))]})),t._v(" "+t._s(t.column.after)+" ")],2)}),[],!1,yk,null,null,null);function yk(t){for(let e in vk)this[e]=vk[e]}var $k=function(){return bk.exports}();const _k={};var xk=Ft({inheritAttrs:!1,extends:$k,props:{value:String},class:"k-date-field-preview",computed:{text(){var t,e,n,i,s,o;if("string"!=typeof this.value)return"";const r=this.$library.dayjs(this.value);if(!r)return"";let a=(null==(t=this.column)?void 0:t.display)||(null==(e=this.field)?void 0:e.display)||"YYYY-MM-DD",l=(null==(i=null==(n=this.column)?void 0:n.time)?void 0:i.display)||(null==(o=null==(s=this.field)?void 0:s.time)?void 0:o.display);return l&&(a+=" "+l),r.format(a)}}},undefined,undefined,!1,wk,null,null,null);function wk(t){for(let e in _k)this[e]=_k[e]}var Sk=function(){return xk.exports}();const Ck={};var Ok=Ft({mixins:[uk],props:{value:[String,Object]},computed:{link(){return"object"==typeof this.value?this.value.href:this.value},text(){return"object"==typeof this.value?this.value.text:this.link}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("p",{staticClass:"k-url-field-preview",class:t.$options.class},[t._v(" "+t._s(t.column.before)+" "),n("k-link",{attrs:{to:t.link},nativeOn:{click:function(t){t.stopPropagation()}}},[t._v(" "+t._s(t.text)+" ")]),t._v(" "+t._s(t.column.after)+" ")],1)}),[],!1,Ek,null,null,null);function Ek(t){for(let e in Ck)this[e]=Ck[e]}var Ak=function(){return Ok.exports}();const Tk={};var Ik=Ft({extends:Ak,class:"k-email-field-preview"},undefined,undefined,!1,Mk,null,null,null);function Mk(t){for(let e in Tk)this[e]=Tk[e]}var Lk=function(){return Ik.exports}();const jk={};var Dk=Ft({inheritAttrs:!1,extends:hk,class:"k-files-field-preview",computed:{bubbles(){return this.value.map((t=>({text:t.filename,link:t.link,image:t.image})))}}},undefined,undefined,!1,Bk,null,null,null);function Bk(t){for(let e in jk)this[e]=jk[e]}var Pk=function(){return Dk.exports}();const Nk={};var qk=Ft({mixins:[uk],inheritAttrs:!1,props:{value:Object}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-status-icon",t._b({staticClass:"k-flag-field-preview"},"k-status-icon",t.value,!1))}),[],!1,Fk,null,null,null);function Fk(t){for(let e in Nk)this[e]=Nk[e]}var Rk=function(){return qk.exports}();const zk={};var Yk=Ft({inheritAttrs:!1,mixins:[uk],props:{value:String},computed:{html(){return this.value}}},(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"k-html-field-preview",class:t.$options.class},[t._v(" "+t._s(t.column.before)+" "),n("div",{domProps:{innerHTML:t._s(t.html)}}),t._v(" "+t._s(t.column.after)+" ")])}),[],!1,Hk,null,null,null);function Hk(t){for(let e in zk)this[e]=zk[e]}var Uk=function(){return Yk.exports}();const Kk={};var Jk=Ft({inheritAttrs:!1,mixins:[uk],props:{value:[Object]}},(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-item-image",{staticClass:"k-image-field-preview",attrs:{image:t.value,layout:"list"}})}),[],!1,Gk,null,null,null);function Gk(t){for(let e in Kk)this[e]=Kk[e]}var Vk=function(){return Jk.exports}();const Wk={};var Xk=Ft({inheritAttrs:!1,extends:hk,class:"k-pages-field-preview"},undefined,undefined,!1,Zk,null,null,null);function Zk(t){for(let e in Wk)this[e]=Wk[e]}var Qk=function(){return Xk.exports}();const tv={};var ev=Ft({inheritAttrs:!1,extends:$k,props:{value:String},class:"k-time-field-preview",computed:{text(){const t=this.$library.dayjs.iso(this.value,"time");return(null==t?void 0:t.format(this.field.display))||""}}},undefined,undefined,!1,nv,null,null,null);function nv(t){for(let e in tv)this[e]=tv[e]}var iv=function(){return ev.exports}();const sv={props:{field:Object,value:Boolean,column:Object},computed:{text(){return!1!==this.column.text?this.field.text:null}}},ov={};var rv=Ft(sv,(function(){var t=this,e=t.$createElement;return(t._self._c||e)("k-input",{staticClass:"k-toggle-field-preview",attrs:{text:t.text,value:t.value,type:"toggle"},on:{input:function(e){return t.$emit("input",e)}}})}),[],!1,av,null,null,null);function av(t){for(let e in ov)this[e]=ov[e]}var lv=function(){return rv.exports}();const uv={};var cv=Ft({inheritAttrs:!1,extends:hk,class:"k-users-field-preview",computed:{bubble(){return this.value.map((t=>({text:t.username,link:t.link,image:t.image})))}}},undefined,undefined,!1,dv,null,null,null);function dv(t){for(let e in uv)this[e]=uv[e]}var pv=function(){return cv.exports}();u.component("k-array-field-preview",kk),u.component("k-bubbles-field-preview",hk),u.component("k-date-field-preview",Sk),u.component("k-email-field-preview",Lk),u.component("k-files-field-preview",Pk),u.component("k-flag-field-preview",Rk),u.component("k-html-field-preview",Uk),u.component("k-image-field-preview",Vk),u.component("k-pages-field-preview",Qk),u.component("k-text-field-preview",$k),u.component("k-toggle-field-preview",lv),u.component("k-time-field-preview",iv),u.component("k-url-field-preview",Ak),u.component("k-users-field-preview",pv),u.component("k-list-field-preview",Uk),u.component("k-writer-field-preview",Uk),u.component("k-checkboxes-field-preview",hk),u.component("k-multiselect-field-preview",hk),u.component("k-radio-field-preview",hk),u.component("k-select-field-preview",hk),u.component("k-tags-field-preview",hk),u.component("k-dialog",Ut),u.component("k-error-dialog",Wt),u.component("k-fiber-dialog",te),u.component("k-files-dialog",oe),u.component("k-form-dialog",ce),u.component("k-language-dialog",fe),u.component("k-pages-dialog",ve),u.component("k-remove-dialog",xe),u.component("k-text-dialog",Oe),u.component("k-users-dialog",Ie),u.component("k-drawer",De),u.component("k-form-drawer",Fe),u.component("k-calendar",We),u.component("k-counter",en),u.component("k-autocomplete",Ue),u.component("k-form",an),u.component("k-form-buttons",pn),u.component("k-form-indicator",gn),u.component("k-field",In),u.component("k-fieldset",Bn),u.component("k-input",Rn),u.component("k-login",Un),u.component("k-login-code",Vn),u.component("k-times",Qn),u.component("k-upload",si),u.component("k-writer",Xi),u.component("k-login-alert",es),u.component("k-structure-form",os),u.component("k-toolbar",ds),u.component("k-toolbar-email-dialog",ms),u.component("k-toolbar-link-dialog",bs),u.component("k-aspect-ratio",eu),u.component("k-bar",ou),u.component("k-box",cu),u.component("k-bubble",fu),u.component("k-bubbles",vu),u.component("k-collection",xu),u.component("k-column",Eu),u.component("k-dropzone",Lu),u.component("k-empty",Pu),u.component("k-file-preview",Ru),u.component("k-grid",Uu),u.component("k-header",Wu),u.component("k-inside",tc),u.component("k-item",rc),u.component("k-item-image",dc),u.component("k-items",gc),u.component("k-overlay",$c),u.component("k-panel",Sc),u.component("k-stats",Ac),u.component("k-table",jc),u.component("k-table-cell",qc),u.component("k-tabs",Yc),u.component("k-view",Jc),u.component("k-draggable",Zc),u.component("k-error-boundary",nd),u.component("k-fatal",rd),u.component("k-headline",cd),u.component("k-icon",fd),u.component("k-icons",$d),u.component("k-image",Cd),u.component("k-loader",Td),u.component("k-offline-warning",jd),u.component("k-progress",qd),u.component("k-registration",Yd),u.component("k-status-icon",Zd),u.component("k-sort-handle",Jd),u.component("k-text",np),u.component("k-user-info",rp),u.component("k-breadcrumb",cp),u.component("k-button",mp),u.component("k-button-disabled",yp),u.component("k-button-group",wp),u.component("k-button-link",Ap),u.component("k-button-native",Dp),u.component("k-dropdown",qp),u.component("k-dropdown-content",Hp),u.component("k-dropdown-item",Vp),u.component("k-languages-dropdown",sh),u.component("k-link",th),u.component("k-options-dropdown",uh),u.component("k-pagination",fh),u.component("k-prev-next",bh),u.component("k-search",xh),u.component("k-tag",Eh),u.component("k-topbar",Lh),u.component("k-account-view",Sf),u.component("k-error-view",Af),u.component("k-file-view",Lf),u.component("k-installation-view",Nf),u.component("k-languages-view",zf),u.component("k-login-view",Vf),u.component("k-page-view",Qf),u.component("k-plugin-view",im),u.component("k-reset-password-view",am),u.component("k-site-view",dm),u.component("k-system-view",gm),u.component("k-users-view",ym),u.component("k-user-view",$f);u.config.productionTip=!1,u.config.devtools=!0,u.use(ct),u.use(Dt),u.use(Pt),u.use(qt),u.use(dt),u.use(Bt),u.use(vt),u.use(tt,ut),u.use(G),u.use(V),new u({store:ut,created(){window.panel.$vue=window.panel.app=this,window.panel.plugins.created.forEach((t=>t(this))),this.$store.dispatch("content/init")},render:t=>t(et)}).$mount("#app"); +import{V as t,a as e,m as s,d as i,c as n,b as o,I as r,P as l,S as a,F as u,N as c,s as d,l as p,w as h,e as m,f,t as g,g as k,h as b,i as v,j as y,k as $,n as _,D as x,o as w,E as S,p as C,q as O,r as A,T,u as I,v as M,x as L,y as E,z as j,A as B,B as D,C as P,G as N,H as q,J as F}from"./vendor.js";var R=t=>({changeName:async(e,s,i)=>t.patch(e+"/files/"+s+"/name",{name:i}),delete:async(e,s)=>t.delete(e+"/files/"+s),async get(e,s,i){let n=await t.get(e+"/files/"+s,i);return!0===Array.isArray(n.content)&&(n.content={}),n},link(t,e,s){return"/"+this.url(t,e,s)},update:async(e,s,i)=>t.patch(e+"/files/"+s,i),url(t,e,s){let i=t+"/files/"+e;return s&&(i+="/"+s),i}}),z=t=>({async blueprint(e){return t.get("pages/"+this.id(e)+"/blueprint")},async blueprints(e,s){return t.get("pages/"+this.id(e)+"/blueprints",{section:s})},async changeSlug(e,s){return t.patch("pages/"+this.id(e)+"/slug",{slug:s})},async changeStatus(e,s,i){return t.patch("pages/"+this.id(e)+"/status",{status:s,position:i})},async changeTemplate(e,s){return t.patch("pages/"+this.id(e)+"/template",{template:s})},async changeTitle(e,s){return t.patch("pages/"+this.id(e)+"/title",{title:s})},async children(e,s){return t.post("pages/"+this.id(e)+"/children/search",s)},async create(e,s){return null===e||"/"===e?t.post("site/children",s):t.post("pages/"+this.id(e)+"/children",s)},async delete(e,s){return t.delete("pages/"+this.id(e),s)},async duplicate(e,s,i){return t.post("pages/"+this.id(e)+"/duplicate",{slug:s,children:i.children||!1,files:i.files||!1})},async get(e,s){let i=await t.get("pages/"+this.id(e),s);return!0===Array.isArray(i.content)&&(i.content={}),i},id:t=>t.replace(/\//g,"+"),async files(e,s){return t.post("pages/"+this.id(e)+"/files/search",s)},link(t){return"/"+this.url(t)},async preview(t){return(await this.get(this.id(t),{select:"previewUrl"})).previewUrl},async search(e,s){return e?t.post("pages/"+this.id(e)+"/children/search?select=id,title,hasChildren",s):t.post("site/children/search?select=id,title,hasChildren",s)},async update(e,s){return t.patch("pages/"+this.id(e),s)},url(t,e){let s=null===t?"pages":"pages/"+String(t).replace(/\//g,"+");return e&&(s+="/"+e),s}});var Y=t=>({running:0,async request(e,s,i=!1){s=Object.assign(s||{},{credentials:"same-origin",cache:"no-store",headers:{"x-requested-with":"xmlhttprequest","content-type":"application/json",...s.headers}}),t.methodOverwrite&&"GET"!==s.method&&"POST"!==s.method&&(s.headers["x-http-method-override"]=s.method,s.method="POST"),s=t.onPrepare(s);const n=e+"/"+JSON.stringify(s);t.onStart(n,i),this.running++;const o=await fetch([t.endpoint,e].join(t.endpoint.endsWith("/")||e.startsWith("/")?"":"/"),s);try{const e=await async function(t){const e=await t.text();let s;try{s=JSON.parse(e)}catch(i){return window.panel.$vue.$api.onParserError({html:e}),!1}return s}(o);if(o.status<200||o.status>299)throw e;if("error"===e.status)throw e;let s=e;return e.data&&"model"===e.type&&(s=e.data),this.running--,t.onComplete(n),t.onSuccess(e),s}catch(r){throw this.running--,t.onComplete(n),t.onError(r),r}},async get(t,e,s,i=!1){return e&&(t+="?"+Object.keys(e).filter((t=>void 0!==e[t]&&null!==e[t])).map((t=>t+"="+e[t])).join("&")),this.request(t,Object.assign(s||{},{method:"GET"}),i)},async post(t,e,s,i="POST",n=!1){return this.request(t,Object.assign(s||{},{method:i,body:JSON.stringify(e)}),n)},async patch(t,e,s,i=!1){return this.post(t,e,s,"PATCH",i)},async delete(t,e,s,i=!1){return this.post(t,e,s,"DELETE",i)}}),H=t=>({blueprint:async e=>t.get("users/"+e+"/blueprint"),blueprints:async(e,s)=>t.get("users/"+e+"/blueprints",{section:s}),changeEmail:async(e,s)=>t.patch("users/"+e+"/email",{email:s}),changeLanguage:async(e,s)=>t.patch("users/"+e+"/language",{language:s}),changeName:async(e,s)=>t.patch("users/"+e+"/name",{name:s}),changePassword:async(e,s)=>t.patch("users/"+e+"/password",{password:s}),changeRole:async(e,s)=>t.patch("users/"+e+"/role",{role:s}),create:async e=>t.post("users",e),delete:async e=>t.delete("users/"+e),deleteAvatar:async e=>t.delete("users/"+e+"/avatar"),link(t,e){return"/"+this.url(t,e)},async list(e){return t.post(this.url(null,"search"),e)},get:async(e,s)=>t.get("users/"+e,s),async roles(e){return(await t.get(this.url(e,"roles"))).data.map((t=>({info:t.description||`(${window.panel.$t("role.description.placeholder")})`,text:t.title,value:t.name})))},search:async e=>t.post("users/search",e),update:async(e,s)=>t.patch("users/"+e,s),url(t,e){let s=t?"users/"+t:"users";return e&&(s+="/"+e),s}}),U={install(t,e){t.prototype.$api=t.$api=((t={})=>{const e={...{endpoint:"/api",methodOverwrite:!0,onPrepare:t=>t,onStart(){},onComplete(){},onSuccess(){},onParserError(){},onError(t){throw window.console.log(t.message),t}},...t.config||{}};let s={...e,...Y(e),...t};return s.auth=(t=>({async login(e){const s={long:e.remember||!1,email:e.email,password:e.password};return t.post("auth/login",s)},logout:async()=>t.post("auth/logout"),user:async e=>t.get("auth",e),verifyCode:async e=>t.post("auth/code",{code:e})}))(s),s.files=R(s),s.languages=(t=>({create:async e=>t.post("languages",e),delete:async e=>t.delete("languages/"+e),get:async e=>t.get("languages/"+e),list:async()=>t.get("languages"),update:async(e,s)=>t.patch("languages/"+e,s)}))(s),s.pages=z(s),s.roles=(t=>({list:async e=>t.get("roles",e),get:async e=>t.get("roles/"+e)}))(s),s.system=(t=>({get:async(e={view:"panel"})=>t.get("system",e),install:async e=>(await t.post("system/install",e)).user,register:async e=>t.post("system/register",e)}))(s),s.site=(t=>({blueprint:async()=>t.get("site/blueprint"),blueprints:async()=>t.get("site/blueprints"),changeTitle:async e=>t.patch("site/title",{title:e}),children:async e=>t.post("site/children/search",e),get:async(e={view:"panel"})=>t.get("site",e),update:async e=>t.post("site",e)}))(s),s.translations=(t=>({list:async()=>t.get("translations"),get:async e=>t.get("translations/"+e)}))(s),s.users=H(s),s})({config:{endpoint:window.panel.$urls.api,onComplete:s=>{t.$api.requests=t.$api.requests.filter((t=>t!==s)),0===t.$api.requests.length&&e.dispatch("isLoading",!1)},onError:e=>{window.panel.$config.debug&&window.console.error(e),403!==e.code||"Unauthenticated"!==e.message&&"access.panel"!==e.key||t.prototype.$go("/logout")},onParserError:({html:t,silent:s})=>{e.dispatch("fatal",{html:t,silent:s})},onPrepare:t=>(window.panel.$language&&(t.headers["x-language"]=window.panel.$language.code),t.headers["x-csrf"]=window.panel.$system.csrf,t),onStart:(s,i=!1)=>{!1===i&&e.dispatch("isLoading",!0),t.$api.requests.push(s)},onSuccess:()=>{clearInterval(t.$api.ping),t.$api.ping=setInterval(t.$api.auth.user,3e5)}},ping:null,requests:[]}),t.$api.ping=setInterval(t.$api.auth.user,3e5)}},K={name:"Fiber",data:()=>({component:null,state:window.fiber,key:null}),created(){this.$fiber.init(this.state,{base:document.querySelector("base").href,headers:()=>({"X-CSRF":this.state.$system.csrf}),onFatal({text:t,options:e}){this.$store.dispatch("fatal",{html:t,silent:e.silent})},onFinish:()=>{0===this.$api.requests.length&&this.$store.dispatch("isLoading",!1)},onPushState:t=>{window.history.pushState(t,"",t.$url)},onReplaceState:t=>{window.history.replaceState(t,"",t.$url)},onStart:({silent:t})=>{!0!==t&&this.$store.dispatch("isLoading",!0)},onSwap:async(t,e)=>{e={navigate:!0,replace:!1,...e},this.setGlobals(t),this.setTitle(t),this.setTranslation(t),this.component=t.$view.component,this.state=t,this.key=!0===e.replace?this.key:t.$view.timestamp,!0===e.navigate&&this.navigate()},query:()=>{var t;return{language:null==(t=this.state.$language)?void 0:t.code}}}),window.addEventListener("popstate",this.$reload)},methods:{navigate(){this.$store.dispatch("navigate")},setGlobals(e){["$config","$direction","$language","$languages","$license","$menu","$multilang","$permissions","$searches","$system","$translation","$urls","$user","$view"].forEach((s=>{void 0!==e[s]?t.prototype[s]=window.panel[s]=e[s]:t.prototype[s]=e[s]=window.panel[s]}))},setTitle(t){t.$view.title?document.title=t.$view.title+" | "+t.$system.title:document.title=t.$system.title},setTranslation(t){t.$translation&&(document.documentElement.lang=t.$translation.code)}},render(t){if(this.component)return t(this.component,{key:this.key,props:this.state.$view.props})}};function J(t){if(void 0!==t)return JSON.parse(JSON.stringify(t))}function G(t,e){for(const s of Object.keys(e))e[s]instanceof Object&&Object.assign(e[s],G(t[s]||{},e[s]));return Object.assign(t||{},e),t}var V={clone:J,isEmpty:function(t){return null==t||""===t||("object"==typeof t&&0===Object.keys(t).length&&t.constructor===Object||void 0!==t.length&&0===t.length)},merge:G};const W=(t,e)=>{localStorage.setItem("kirby$content$"+t,JSON.stringify(e))};var X={namespaced:!0,state:{current:null,models:{},status:{enabled:!0}},getters:{exists:t=>e=>Object.prototype.hasOwnProperty.call(t.models,e),hasChanges:(t,e)=>t=>{const s=e.model(t).changes;return Object.keys(s).length>0},isCurrent:t=>e=>t.current===e,id:t=>e=>(e=e||t.current,window.panel.$language?e+"?language="+window.panel.$language.code:e),model:(t,e)=>s=>(s=s||t.current,!0===e.exists(s)?t.models[s]:{api:null,originals:{},values:{},changes:{}}),originals:(t,e)=>t=>J(e.model(t).originals),values:(t,e)=>t=>({...e.originals(t),...e.changes(t)}),changes:(t,e)=>t=>J(e.model(t).changes)},mutations:{CLEAR(t){Object.keys(t.models).forEach((e=>{t.models[e].changes={}})),Object.keys(localStorage).forEach((t=>{t.startsWith("kirby$content$")&&localStorage.removeItem(t)}))},CREATE(e,[s,i]){if(!i)return!1;let n=e.models[s]?e.models[s].changes:i.changes;t.set(e.models,s,{api:i.api,originals:i.originals,changes:n||{}})},CURRENT(t,e){t.current=e},MOVE(e,[s,i]){const n=J(e.models[s]);t.delete(e.models,s),t.set(e.models,i,n);const o=localStorage.getItem("kirby$content$"+s);localStorage.removeItem("kirby$content$"+s),localStorage.setItem("kirby$content$"+i,o)},REMOVE(e,s){t.delete(e.models,s),localStorage.removeItem("kirby$content$"+s)},REVERT(e,s){e.models[s]&&(t.set(e.models[s],"changes",{}),localStorage.removeItem("kirby$content$"+s))},STATUS(e,s){t.set(e.status,"enabled",s)},UPDATE(e,[s,i,n]){if(!e.models[s])return!1;void 0===n&&(n=null),n=J(n);const o=JSON.stringify(n);JSON.stringify(e.models[s].originals[i])==o?t.delete(e.models[s].changes,i):t.set(e.models[s].changes,i,n),W(s,{api:e.models[s].api,originals:e.models[s].originals,changes:e.models[s].changes})}},actions:{init(t){Object.keys(localStorage).filter((t=>t.startsWith("kirby$content$"))).map((t=>t.split("kirby$content$")[1])).forEach((e=>{const s=localStorage.getItem("kirby$content$"+e);t.commit("CREATE",[e,JSON.parse(s)])})),Object.keys(localStorage).filter((t=>t.startsWith("kirby$form$"))).map((t=>t.split("kirby$form$")[1])).forEach((e=>{const s=localStorage.getItem("kirby$form$"+e);let i=null;try{i=JSON.parse(s)}catch(o){}if(!i||!i.api)return localStorage.removeItem("kirby$form$"+e),!1;const n={api:i.api,originals:i.originals,changes:i.values};t.commit("CREATE",[e,n]),W(e,n),localStorage.removeItem("kirby$form$"+e)}))},clear(t){t.commit("CLEAR")},create(t,e){const s=J(e.content);Array.isArray(e.ignore)&&e.ignore.forEach((t=>delete s[t])),e.id=t.getters.id(e.id);const i={api:e.api,originals:s,changes:{}};t.commit("CREATE",[e.id,i]),t.dispatch("current",e.id)},current(t,e){t.commit("CURRENT",e)},disable(t){t.commit("STATUS",!1)},enable(t){t.commit("STATUS",!0)},move(t,[e,s]){e=t.getters.id(e),s=t.getters.id(s),t.commit("MOVE",[e,s])},remove(t,e){t.commit("REMOVE",e),t.getters.isCurrent(e)&&t.commit("CURRENT",null)},revert(t,e){e=e||t.state.current,t.commit("REVERT",e)},async save(e,s){if(s=s||e.state.current,e.getters.isCurrent(s)&&!1===e.state.status.enabled)return!1;e.dispatch("disable");const i=e.getters.model(s),n={...i.originals,...i.changes};try{await t.$api.patch(i.api,n),e.commit("CREATE",[s,{...i,originals:n}]),e.dispatch("revert",s)}finally{e.dispatch("enable")}},update(t,[e,s,i]){i=i||t.state.current,t.commit("UPDATE",[i,e,s])}}},Z={namespaced:!0,state:{open:[]},mutations:{CLOSE(t,e){t.open=e?t.open.filter((t=>t.id!==e)):[]},GOTO(t,e){t.open=t.open.slice(0,t.open.findIndex((t=>t.id===e))+1)},OPEN(t,e){t.open.push(e)}},actions:{close(t,e){t.commit("CLOSE",e)},goto(t,e){t.commit("GOTO",e)},open(t,e){t.commit("OPEN",e)}}},Q={timer:null,namespaced:!0,state:{type:null,message:null,details:null,timeout:null},mutations:{SET(t,e){t.type=e.type,t.message=e.message,t.details=e.details,t.timeout=e.timeout},UNSET(t){t.type=null,t.message=null,t.details=null,t.timeout=null}},actions:{close(t){clearTimeout(this.timer),t.commit("UNSET")},deprecated(t,e){console.warn("Deprecated: "+e)},error(t,e){let s=e;"string"==typeof e&&(s={message:e}),e instanceof Error&&(s={message:e.message},window.panel.$config.debug&&window.console.error(e)),t.dispatch("dialog",{component:"k-error-dialog",props:s},{root:!0}),t.dispatch("close")},open(t,e){t.dispatch("close"),t.commit("SET",e),e.timeout&&(this.timer=setTimeout((()=>{t.dispatch("close")}),e.timeout))},success(t,e){"string"==typeof e&&(e={message:e}),t.dispatch("open",{type:"success",timeout:4e3,...e})}}};t.use(e);var tt=new e.Store({strict:!1,state:{dialog:null,drag:null,fatal:!1,isLoading:!1},mutations:{SET_DIALOG(t,e){t.dialog=e},SET_DRAG(t,e){t.drag=e},SET_FATAL(t,e){t.fatal=e},SET_LOADING(t,e){t.isLoading=e}},actions:{dialog(t,e){t.commit("SET_DIALOG",e)},drag(t,e){t.commit("SET_DRAG",e)},fatal(t,e){!1!==e?(console.error("The JSON response could not be parsed"),window.panel.$config.debug&&console.info(e.html),e.silent||t.commit("SET_FATAL",e.html)):t.commit("SET_FATAL",!1)},isLoading(t,e){t.commit("SET_LOADING",!0===e)},navigate(t){t.dispatch("dialog",null),t.dispatch("drawers/close")}},modules:{content:X,drawers:Z,notification:Q}}),et={install(t){window.panel=window.panel||{},window.onunhandledrejection=t=>{t.preventDefault(),tt.dispatch("notification/error",t.reason)},window.panel.deprecated=t=>{tt.dispatch("notification/deprecated",t)},window.panel.error=t.config.errorHandler=t=>{tt.dispatch("notification/error",t)}}},st={install(t){const e=s(),i={$on:e.on,$off:e.off,$emit:e.emit,blur(t){i.$emit("blur",t)},click(t){i.$emit("click",t)},copy(t){i.$emit("copy",t)},dragenter(t){i.entered=t.target,i.prevent(t),i.$emit("dragenter",t)},dragleave(t){i.prevent(t),i.entered===t.target&&i.$emit("dragleave",t)},drop(t){i.prevent(t),i.$emit("drop",t)},entered:null,focus(t){i.$emit("focus",t)},keydown(e){let s=["keydown"];(e.metaKey||e.ctrlKey)&&s.push("cmd"),!0===e.altKey&&s.push("alt"),!0===e.shiftKey&&s.push("shift");let n=t.prototype.$helper.string.lcfirst(e.key);const o={escape:"esc",arrowUp:"up",arrowDown:"down",arrowLeft:"left",arrowRight:"right"};o[n]&&(n=o[n]),!1===["alt","control","shift","meta"].includes(n)&&s.push(n),i.$emit(s.join("."),e),i.$emit("keydown",e)},keyup(t){i.$emit("keyup",t)},online(t){i.$emit("online",t)},offline(t){i.$emit("offline",t)},paste(t){i.$emit("paste",t)},prevent(t){t.stopPropagation(),t.preventDefault()}};document.addEventListener("click",i.click,!1),document.addEventListener("copy",i.copy,!0),document.addEventListener("focus",i.focus,!0),document.addEventListener("paste",i.paste,!0),window.addEventListener("blur",i.blur,!1),window.addEventListener("dragenter",i.dragenter,!1),window.addEventListener("dragexit",i.prevent,!1),window.addEventListener("dragleave",i.dragleave,!1),window.addEventListener("drop",i.drop,!1),window.addEventListener("dragover",i.prevent,!1),window.addEventListener("keydown",i.keydown,!1),window.addEventListener("keyup",i.keyup,!1),window.addEventListener("offline",i.offline),window.addEventListener("online",i.online),t.prototype.$events=i}};class it{constructor(t={}){this.options={base:"/",headers:()=>({}),onFatal:()=>{},onFinish:()=>{},onPushState:()=>{},onReplaceState:()=>{},onStart:()=>{},onSwap:()=>{},query:()=>({}),...t},this.state={}}init(t={},e={}){this.options={...this.options,...e},this.setState(t)}arrayToString(t){return!1===Array.isArray(t)?String(t):t.join(",")}body(t){return"object"==typeof t?JSON.stringify(t):t}async fetch(t,e){return fetch(t,e)}async go(t,e){try{const s=await this.request(t,e);return!1!==s&&this.setState(s,e)}catch(s){if(!0!==(null==e?void 0:e.silent))throw s}}query(t={},e={}){let s=new URLSearchParams(e);return"object"!=typeof t&&(t={}),Object.entries(t).forEach((([t,e])=>{null!==e&&s.set(t,e)})),Object.entries(this.options.query()).forEach((([t,e])=>{var i,n;null!==(e=null!=(n=null!=(i=s.get(t))?i:e)?n:null)&&s.set(t,e)})),s}redirect(t){window.location.href=t}reload(t={}){return this.go(window.location.href,{...t,replace:!0})}async request(t="",e={}){var s;const i=!!(e={globals:!1,method:"GET",only:[],query:{},silent:!1,type:"$view",...e}).globals&&this.arrayToString(e.globals),n=this.arrayToString(e.only);this.options.onStart(e);try{const r=this.url(t,e.query);if(new URL(r).origin!==location.origin)return this.redirect(r),!1;const l=await this.fetch(r,{method:e.method,body:this.body(e.body),credentials:"same-origin",cache:"no-store",headers:{...this.options.headers(),"X-Fiber":!0,"X-Fiber-Globals":i,"X-Fiber-Only":n,"X-Fiber-Referrer":(null==(s=this.state.$view)?void 0:s.path)||null,...e.headers}});if(!1===l.headers.has("X-Fiber"))return this.redirect(l.url),!1;const a=await l.text();let u;try{u=JSON.parse(a)}catch(o){return this.options.onFatal({url:r,path:t,options:e,response:l,text:a}),!1}if(!u[e.type])throw Error(`The ${e.type} could not be loaded`);const c=u[e.type];if(c.error)throw Error(c.error);return"$view"===e.type?n.length?G(this.state,u):u:c}finally{this.options.onFinish(e)}}async setState(t,e={}){return"object"==typeof t&&(this.state=J(t),!0===e.replace||this.url(this.state.$url).href===window.location.href?this.options.onReplaceState(this.state,e):this.options.onPushState(this.state,e),this.options.onSwap(this.state,e),this.state)}url(t="",e={}){return(t="string"==typeof t&&null===t.match(/^https?:\/\//)?new URL(this.options.base+t.replace(/^\//,"")):new URL(t)).search=this.query(e,t.search),t}}const nt=async function(t){return{cancel:null,submit:null,props:{},...t}},ot=async function(t,e={}){let s=null,i=null;"function"==typeof e?(s=e,e={}):(s=e.submit,i=e.cancel);let n=await this.$fiber.request("dialogs/"+t,{...e,type:"$dialog"});return"object"==typeof n&&(n.submit=s||null,n.cancel=i||null,n)};async function rt(t,e={}){let s=null;if(s="object"==typeof t?await nt.call(this,t):await ot.call(this,t,e),!s)return!1;if(!s.component||!1===this.$helper.isComponent(s.component))throw Error("The dialog component does not exist");return s.props=s.props||{},this.$store.dispatch("dialog",s),s}function lt(t,e={}){return async s=>{const i=await this.$fiber.request("dropdowns/"+t,{...e,type:"$dropdown"});if(!i)return!1;if(!1===Array.isArray(i.options)||0===i.options.length)throw Error("The dropdown is empty");i.options.map((t=>(t.dialog&&(t.click=()=>{const e="string"==typeof t.dialog?t.dialog:t.dialog.url,s="object"==typeof t.dialog?t.dialog:{};return this.$dialog(e,s)}),t))),s(i.options)}}async function at(t,e,s={}){return await this.$fiber.request("search/"+t,{query:{query:e},type:"$search",...s})}var ut={install(t){const e=new it;t.prototype.$fiber=window.panel.$fiber=e,t.prototype.$dialog=window.panel.$dialog=rt,t.prototype.$dropdown=window.panel.$dropdown=lt,t.prototype.$go=window.panel.$go=e.go.bind(e),t.prototype.$reload=window.panel.$reload=e.reload.bind(e),t.prototype.$request=window.panel.$request=e.request.bind(e),t.prototype.$search=window.panel.$search=at,t.prototype.$url=window.panel.$url=e.url.bind(e)}};var ct={read:function(t){if(!t)return null;if("string"==typeof t)return t;if(t instanceof ClipboardEvent){t.preventDefault();const e=t.clipboardData.getData("text/html")||t.clipboardData.getData("text/plain")||null;if(e)return e.replace(/\u00a0/g," ")}return null},write:function(t,e){if("string"!=typeof t&&(t=JSON.stringify(t,null,2)),e&&e instanceof ClipboardEvent)return e.preventDefault(),e.clipboardData.setData("text/plain",t),!0;const s=document.createElement("textarea");if(s.value=t,document.body.append(s),navigator.userAgent.match(/ipad|ipod|iphone/i)){s.contentEditable=!0,s.readOnly=!0;const t=document.createRange();t.selectNodeContents(s);const e=window.getSelection();e.removeAllRanges(),e.addRange(t),s.setSelectionRange(0,999999)}else s.select();return document.execCommand("copy"),s.remove(),!0}};function dt(t){if("string"==typeof t){if("pattern"===(t=t.toLowerCase()))return"var(--color-gray-800) var(--bg-pattern)";if(!1===t.startsWith("#")&&!1===t.startsWith("var(")){const e="--color-"+t;if(window.getComputedStyle(document.documentElement).getPropertyValue(e))return`var(${e})`}return t}}var pt=(t,e)=>{let s=null;return function(){clearTimeout(s),s=setTimeout((()=>t.apply(this,arguments)),e)}};function ht(t,e=!1){if(!t.match("youtu"))return!1;let s=null;try{s=new URL(t)}catch(d){return!1}const i=s.pathname.split("/").filter((t=>""!==t)),n=i[0],o=i[1],r="https://"+(!0===e?"www.youtube-nocookie.com":s.host)+"/embed",l=t=>!!t&&null!==t.match(/^[a-zA-Z0-9_-]+$/);let a=s.searchParams,u=null;switch(i.join("/")){case"embed/videoseries":case"playlist":l(a.get("list"))&&(u=r+"/videoseries");break;case"watch":l(a.get("v"))&&(u=r+"/"+a.get("v"),a.has("t")&&a.set("start",a.get("t")),a.delete("v"),a.delete("t"));break;default:s.host.includes("youtu.be")&&l(n)?(u="https://www.youtube.com/embed/"+n,a.has("t")&&a.set("start",a.get("t")),a.delete("t")):"embed"===n&&l(o)&&(u=r+"/"+o)}if(!u)return!1;const c=a.toString();return c.length&&(u+="?"+c),u}function mt(t,e=!1){let s=null;try{s=new URL(t)}catch(a){return!1}const i=s.pathname.split("/").filter((t=>""!==t));let n=s.searchParams,o=null;switch(!0===e&&n.append("dnt",1),s.host){case"vimeo.com":case"www.vimeo.com":o=i[0];break;case"player.vimeo.com":o=i[1]}if(!o||!o.match(/^[0-9]*$/))return!1;let r="https://player.vimeo.com/video/"+o;const l=n.toString();return l.length&&(r+="?"+l),r}var ft={youtube:ht,vimeo:mt,video:function(t,e=!1){return t.includes("youtu")?ht(t,e):!!t.includes("vimeo")&&mt(t,e)}},gt=e=>void 0!==t.options.components[e],kt=t=>!!t.dataTransfer&&(!!t.dataTransfer.types&&(!0===t.dataTransfer.types.includes("Files")&&!1===t.dataTransfer.types.includes("text/plain")));var bt={metaKey:function(){return window.navigator.userAgent.indexOf("Mac")>-1?"cmd":"ctrl"}},vt=(t="3/2",e="100%",s=!0)=>{const i=String(t).split("/");if(2!==i.length)return e;const n=Number(i[0]),o=Number(i[1]);let r=100;return 0!==n&&0!==o&&(r=s?r/n*o:r/o*n,r=parseFloat(String(r)).toFixed(2)),r+"%"},yt=t=>{var e=(t=t||{}).desc?-1:1,s=-e,i=/^0/,n=/\s+/g,o=/^\s+|\s+$/g,r=/[^\x00-\x80]/,l=/^0x[0-9a-f]+$/i,a=/(0x[\da-fA-F]+|(^[\+\-]?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?(?=\D|\s|$))|\d+)/g,u=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,c=t.insensitive?function(t){return function(t){if(t.toLocaleLowerCase)return t.toLocaleLowerCase();return t.toLowerCase()}(""+t).replace(o,"")}:function(t){return(""+t).replace(o,"")};function d(t){return t.replace(a,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0")}function p(t,e){return(!t.match(i)||1===e)&&parseFloat(t)||t.replace(n," ").replace(o,"")||0}return function(t,i){var n=c(t),o=c(i);if(!n&&!o)return 0;if(!n&&o)return s;if(n&&!o)return e;var a=d(n),h=d(o),m=parseInt(n.match(l),16)||1!==a.length&&Date.parse(n),f=parseInt(o.match(l),16)||m&&o.match(u)&&Date.parse(o)||null;if(f){if(mf)return e}for(var g=a.length,k=h.length,b=0,v=Math.max(g,k);b0)return e;if(_<0)return s;if(b===v-1)return 0}else{if(y<$)return s;if(y>$)return e}}return 0}};function $t(t){const e={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};return String(t).replace(/[&<>"'`=/]/g,(t=>e[t]))}function _t(t,e={}){const s=(t,e={})=>{var i;const n=$t(t.shift()),o=null!=(i=e[n])?i:null;return null===o?Object.prototype.hasOwnProperty.call(e,n)||"…":0===t.length?o:s(t,o)},i="[{]{1,2}[\\s]?",n="[\\s]?[}]{1,2}";return(t=t.replace(new RegExp(`${i}(.*?)${n}`,"gi"),((t,i)=>s(i.split("."),e)))).replace(new RegExp(`${i}.*${n}`,"gi"),"…")}function xt(t){const e=String(t);return e.charAt(0).toUpperCase()+e.slice(1)}RegExp.escape=function(t){return t.replace(new RegExp("[-/\\\\^$*+?.()[\\]{}]","gu"),"\\$&")};var wt={camelToKebab:function(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()},escapeHTML:$t,hasEmoji:function(t){if("string"!=typeof t)return!1;const e=t.match(/(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|[\ud83c\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|[\ud83c\ude32-\ude3a]|[\ud83c\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])/i);return null!==e&&null!==e.length},lcfirst:function(t){const e=String(t);return e.charAt(0).toLowerCase()+e.slice(1)},pad:function(t,e=2){t=String(t);let s="";for(;s.length]+)>)/gi,"")},template:_t,ucfirst:xt,ucwords:function(t){return String(t).split(/ /g).map((t=>xt(t))).join(" ")},uuid:function(){let t,e,s="";for(t=0;t<32;t++)e=16*Math.random()|0,8!=t&&12!=t&&16!=t&&20!=t||(s+="-"),s+=(12==t?4:16==t?3&e|8:e).toString(16);return s}},St=(t,e)=>{const s=Object.assign({url:"/",field:"file",method:"POST",attributes:{},complete:function(){},error:function(){},success:function(){},progress:function(){}},e),i=new FormData;i.append(s.field,t,t.name),s.attributes&&Object.keys(s.attributes).forEach((t=>{i.append(t,s.attributes[t])}));const n=new XMLHttpRequest,o=e=>{if(!e.lengthComputable||!s.progress)return;let i=Math.max(0,Math.min(100,e.loaded/e.total*100));s.progress(n,t,Math.ceil(i))};n.upload.addEventListener("loadstart",o),n.upload.addEventListener("progress",o),n.addEventListener("load",(e=>{let i=null;try{i=JSON.parse(e.target.response)}catch(o){i={status:"error",message:"The file could not be uploaded"}}"error"===i.status?s.error(n,t,i):(s.success(n,t,i),s.progress(n,t,100))})),n.addEventListener("error",(e=>{const i=JSON.parse(e.target.response);s.error(n,t,i),s.progress(n,t,100)})),n.open(s.method,s.url,!0),s.headers&&Object.keys(s.headers).forEach((t=>{const e=s.headers[t];n.setRequestHeader(t,e)})),n.send(i)},Ct={install(t){Array.prototype.sortBy=function(e){const s=t.prototype.$helper.sort(),i=e.split(" "),n=i[0],o=i[1]||"asc";return this.sort(((t,e)=>{const i=String(t[n]).toLowerCase(),r=String(e[n]).toLowerCase();return"desc"===o?s(r,i):s(i,r)}))},t.prototype.$helper={clipboard:ct,clone:V.clone,color:dt,embed:ft,isComponent:gt,isUploadEvent:kt,debounce:pt,keyboard:bt,object:V,pad:wt.pad,ratio:vt,slug:wt.slug,sort:yt,string:wt,upload:St,uuid:wt.uuid},t.prototype.$esc=wt.escapeHTML}},Ot={install(t){t.$t=t.prototype.$t=window.panel.$t=(t,e,s=null)=>{if("string"!=typeof t)return;const i=window.panel.$translation.data[t]||s;return"string"!=typeof i?i:_t(i,e)},t.directive("direction",{inserted(t,e,s){!0!==s.context.disabled?t.dir=s.context.$direction:t.dir=null}})}};i.extend(n),i.extend(((t,e,s)=>{s.interpret=(t,e="date")=>{const i={date:{"YYYY-MM-DD":!0,"YYYY-MM-D":!0,"YYYY-MM-":!0,"YYYY-MM":!0,"YYYY-M-DD":!0,"YYYY-M-D":!0,"YYYY-M-":!0,"YYYY-M":!0,"YYYY-":!0,YYYYMMDD:!0,"MMM DD YYYY":!1,"MMM D YYYY":!1,"MMM DD YY":!1,"MMM D YY":!1,"MMM DD":!1,"MMM D":!1,"DD MMMM YYYY":!1,"DD MMMM YY":!1,"DD MMMM":!1,"D MMMM YYYY":!1,"D MMMM YY":!1,"D MMMM":!1,"DD MMM YYYY":!1,"D MMM YYYY":!1,"DD MMM YY":!1,"D MMM YY":!1,"DD MMM":!1,"D MMM":!1,"DD MM YYYY":!1,"DD M YYYY":!1,"D MM YYYY":!1,"D M YYYY":!1,"DD MM YY":!1,"D MM YY":!1,"DD M YY":!1,"D M YY":!1,YYYY:!0,MMMM:!0,MMM:!0,"DD MM":!1,"DD M":!1,"D MM":!1,"D M":!1,DD:!1,D:!1},time:{"HH:mm:ss a":!1,"HH:mm:ss":!1,"HH:mm a":!1,"HH:mm":!1,"HH a":!1,HH:!1}};if("string"==typeof t&&""!==t)for(const n in i[e]){const o=s(t,n,i[e][n]);if(!0===o.isValid())return o}return null}})),i.extend(((t,e,s)=>{const i=t=>"date"===t?"YYYY-MM-DD":"time"===t?"HH:mm:ss":"YYYY-MM-DD HH:mm:ss";e.prototype.toISO=function(t="datetime"){return this.format(i(t))},s.iso=function(t,e="datetime"){const n=s(t,i(e));return n&&n.isValid()?n:null}})),i.extend(((t,e)=>{e.prototype.merge=function(t,e="date"){let s=this.clone();if(!t||!t.isValid())return this;if("string"==typeof e){const t={date:["year","month","date"],time:["hour","minute","second"]};if(!1===Object.prototype.hasOwnProperty.call(t,e))throw new Error("Invalid merge unit alias");e=t[e]}for(const i of e)s=s.set(i,t.get(i));return s}})),i.extend(((t,e,s)=>{s.pattern=t=>new class{constructor(t,e){this.dayjs=t,this.pattern=e;const s={year:["YY","YYYY"],month:["M","MM","MMM","MMMM"],day:["D","DD"],hour:["h","hh","H","HH"],minute:["m","mm"],second:["s","ss"],meridiem:["a"]};this.parts=this.pattern.split(/\W/).map(((t,e)=>{const i=this.pattern.indexOf(t);return{index:e,unit:Object.keys(s)[Object.values(s).findIndex((e=>e.includes(t)))],start:i,end:i+(t.length-1)}}))}at(t,e=t){const s=this.parts.filter((s=>s.start<=t&&s.end>=e-1));return s[0]?s[0]:this.parts.filter((e=>e.start<=t)).pop()}format(t){return t&&t.isValid()?t.format(this.pattern):null}}(s,t)})),i.extend(((t,e)=>{e.prototype.round=function(t="date",e=1){const s=["second","minute","hour","date","month","year"];if("day"===t&&(t="date"),!1===s.includes(t))throw new Error("Invalid rounding unit");if(["date","month","year"].includes(t)&&1!==e||"hour"===t&&24%e!=0||["second","minute"].includes(t)&&60%e!=0)throw"Invalid rounding size for "+t;let i=this.clone();const n=s.indexOf(t),o=s.slice(0,n),r=o.pop();if(o.forEach((t=>i=i.startOf(t))),r){const e={month:12,date:i.daysInMonth(),hour:24,minute:60,second:60}[r];Math.round(i.get(r)/e)*e===e&&(i=i.add(1,"date"===t?"day":t)),i=i.startOf(t)}return i=i.set(t,Math.round(i.get(t)/e)*e),i}})),i.extend(((t,e,s)=>{e.prototype.validate=function(t,e,i="day"){if(!this.isValid())return!1;if(!t)return!0;t=s.iso(t);const n={min:"isAfter",max:"isBefore"}[e];return this.isSame(t,i)||this[n](t,i)}}));var At={install(t){t.prototype.$library={autosize:o,dayjs:i}}},Tt={props:{blueprint:String,lock:[Boolean,Object],help:String,name:String,parent:String,timestamp:Number},methods:{load(){return this.$api.get(this.parent+"/sections/"+this.name)}}},It={install(t){const e={...t.options.components},s={section:Tt};for(const[i,n]of Object.entries(window.panel.plugins.components))n.template||n.render||n.extends?("string"==typeof(null==n?void 0:n.extends)&&(e[n.extends]?n.extends=e[n.extends].extend({options:n,components:{...e,...n.components||{}}}):n.extends=null),n.template&&(n.render=null),n.mixins&&(n.mixins=n.mixins.map((t=>"string"==typeof t?s[t]:t))),e[i]&&window.console.warn(`Plugin is replacing "${i}"`),t.component(i,n),e[i]=t.options.components[i]):tt.dispatch("notification/error",`Neither template or render method provided nor extending a component when loading plugin component "${i}". The component has not been registered.`);for(const i of window.panel.plugins.use)t.use(i)}};function Mt(t,e,s,i,n,o,r,l){var a,u="function"==typeof t?t.options:t;if(e&&(u.render=e,u.staticRenderFns=s,u._compiled=!0),i&&(u.functional=!0),o&&(u._scopeId="data-v-"+o),r?(a=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),n&&n.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(r)},u._ssrRegister=a):n&&(a=l?function(){n.call(this,(u.functional?this.parent:this).$root.$options.shadowRoot)}:n),a)if(u.functional){u._injectStyles=a;var c=u.render;u.render=function(t,e){return a.call(e),c(t,e)}}else{var d=u.beforeCreate;u.beforeCreate=d?[].concat(d,a):[a]}return{exports:t,options:u}}var Lt=Mt({props:{autofocus:{type:Boolean,default:!0},cancelButton:{type:[String,Boolean],default:!0},icon:{type:String,default:"check"},size:{type:String,default:"default"},submitButton:{type:[String,Boolean],default:!0},theme:String,visible:Boolean},data:()=>({notification:null}),computed:{buttons(){let t=[];return this.cancelButton&&t.push({icon:"cancel",text:this.cancelButtonLabel,class:"k-dialog-button-cancel",click:this.cancel}),this.submitButtonConfig&&t.push({icon:this.icon,text:this.submitButtonLabel,theme:this.theme,class:"k-dialog-button-submit",click:this.submit}),t},cancelButtonLabel(){return!1!==this.cancelButton&&(!0===this.cancelButton||0===this.cancelButton.length?this.$t("cancel"):this.cancelButton)},submitButtonConfig(){return void 0!==this.$attrs.button?this.$attrs.button:void 0===this.submitButton||this.submitButton},submitButtonLabel(){return!0===this.submitButton||0===this.submitButton.length?this.$t("confirm"):this.submitButton}},created(){this.$events.$on("keydown.esc",this.close,!1)},destroyed(){this.$events.$off("keydown.esc",this.close,!1)},mounted(){this.visible&&this.$nextTick(this.open)},methods:{onOverlayClose(){this.notification=null,this.$emit("close"),this.$events.$off("keydown.esc",this.close),this.$store.dispatch("dialog",!1)},open(){this.$store.state.dialog||this.$store.dispatch("dialog",!0),this.notification=null,this.$refs.overlay.open(),this.$emit("open"),this.$events.$on("keydown.esc",this.close)},close(){this.$refs.overlay&&this.$refs.overlay.close()},cancel(){this.$emit("cancel"),this.close()},focus(){var t;if(null==(t=this.$refs.dialog)?void 0:t.querySelector){const t=this.$refs.dialog.querySelector(".k-dialog-button-cancel");"function"==typeof(null==t?void 0:t.focus)&&t.focus()}},error(t){this.notification={message:t,type:"error"}},submit(){this.$emit("submit")},success(t){this.notification={message:t,type:"success"}}}},(function(){var t=this,e=t._self._c;return e("k-overlay",{ref:"overlay",attrs:{autofocus:t.autofocus,centered:!0},on:{close:t.onOverlayClose,ready:function(e){return t.$emit("ready")}}},[e("div",{ref:"dialog",staticClass:"k-dialog",class:t.$vnode.data.staticClass,attrs:{"data-size":t.size},on:{mousedown:function(t){t.stopPropagation()}}},[t.notification?e("div",{staticClass:"k-dialog-notification",attrs:{"data-theme":t.notification.type}},[e("p",[t._v(t._s(t.notification.message))]),e("k-button",{attrs:{icon:"cancel"},on:{click:function(e){t.notification=null}}})],1):t._e(),e("div",{staticClass:"k-dialog-body scroll-y-auto"},[t._t("default")],2),t.$slots.footer||t.buttons.length?e("footer",{staticClass:"k-dialog-footer"},[t._t("footer",(function(){return[e("k-button-group",{attrs:{buttons:t.buttons}})]}))],2):t._e()])])}),[],!1,null,null,null,null).exports,Et={props:{autofocus:{type:Boolean,default:!0},cancelButton:{type:[String,Boolean],default:!0},icon:String,submitButton:{type:[String,Boolean],default:!0},size:String,theme:String,visible:Boolean},methods:{close(){this.$refs.dialog.close(),this.$emit("close")},error(t){this.$refs.dialog.error(t)},open(){this.$refs.dialog.open(),this.$emit("open")},success(t){this.$refs.dialog.close(),t.route&&this.$go(t.route),t.message&&this.$store.dispatch("notification/success",t.message),t.event&&("string"==typeof t.event&&(t.event=[t.event]),t.event.forEach((e=>{this.$events.$emit(e,t)}))),!1!==Object.prototype.hasOwnProperty.call(t,"emit")&&!1===t.emit||this.$emit("success")}}};var jt=Mt({mixins:[Et],props:{details:[Object,Array],message:String,size:{type:String,default:"medium"}},computed:{detailsList(){return Array.isArray(this.details)?this.details:Object.values(this.details||{})}}},(function(){var t=this,e=t._self._c;return e("k-dialog",{ref:"dialog",staticClass:"k-error-dialog",attrs:{"cancel-button":!1,size:t.size,visible:!0},on:{cancel:function(e){return t.$emit("cancel")},close:function(e){return t.$emit("close")},submit:function(e){return t.$refs.dialog.close()}}},[e("k-text",[t._v(t._s(t.message))]),t.detailsList.length?e("dl",{staticClass:"k-error-details"},[t._l(t.detailsList,(function(s,i){return[e("dt",{key:"detail-label-"+i},[t._v(" "+t._s(s.label)+" ")]),e("dd",{key:"detail-message-"+i},["object"==typeof s.message?[e("ul",t._l(s.message,(function(s,i){return e("li",{key:i},[t._v(" "+t._s(s)+" ")])})),0)]:[t._v(" "+t._s(s.message)+" ")]],2)]}))],2):t._e()],1)}),[],!1,null,null,null,null).exports;var Bt=Mt({props:{code:Number,component:String,path:String,props:Object,referrer:String},methods:{close(){this.$refs.dialog.close()},onCancel(){"function"==typeof this.$store.state.dialog.cancel&&this.$store.state.dialog.cancel({dialog:this})},async onSubmit(t){let e=null;try{if("function"==typeof this.$store.state.dialog.submit)e=await this.$store.state.dialog.submit({dialog:this,value:t});else{if(!this.path)throw"The dialog needs a submit action or a dialog route path to be submitted";e=await this.$request(this.path,{body:t,method:"POST",type:"$dialog",headers:{"X-Fiber-Referrer":this.referrer}})}if(!1===e)return!1;this.close(),this.$store.dispatch("notification/success",":)"),e.event&&("string"==typeof e.event&&(e.event=[e.event]),e.event.forEach((t=>{this.$events.$emit(t,e)}))),e.dispatch&&Object.keys(e.dispatch).forEach((t=>{const s=e.dispatch[t];this.$store.dispatch(t,!0===Array.isArray(s)?[...s]:s)})),e.redirect?this.$go(e.redirect):this.$reload(e.reload||{})}catch(s){this.$refs.dialog.error(s)}}}},(function(){var t=this;return(0,t._self._c)(t.component,t._b({ref:"dialog",tag:"component",attrs:{visible:!0},on:{cancel:t.onCancel,submit:t.onSubmit}},"component",t.props,!1))}),[],!1,null,null,null,null).exports,Dt={data:()=>({models:[],issue:null,selected:{},options:{endpoint:null,max:null,multiple:!0,parent:null,selected:[],search:!0},search:null,pagination:{limit:20,page:1,total:0}}),computed:{checkedIcon(){return!0===this.multiple?"check":"circle-filled"},collection(){return{empty:this.emptyProps,items:this.items,link:!1,layout:"list",pagination:{details:!0,dropdown:!1,align:"center",...this.pagination},sortable:!1}},items(){return this.models.map(this.item)},multiple(){return!0===this.options.multiple&&1!==this.options.max}},watch:{search(){this.updateSearch()}},created(){this.updateSearch=pt(this.updateSearch,200)},methods:{async fetch(){const t={page:this.pagination.page,search:this.search,...this.fetchData||{}};try{const e=await this.$api.get(this.options.endpoint,t);this.models=e.data,this.pagination=e.pagination,this.onFetched&&this.onFetched(e)}catch(e){this.models=[],this.issue=e.message}},async open(t,e){this.pagination.page=0,this.search=null;let s=!0;Array.isArray(t)?(this.models=t,s=!1):(this.models=[],e=t),this.options={...this.options,...e},this.selected={},this.options.selected.forEach((t=>{this.$set(this.selected,t,{id:t})})),s&&await this.fetch(),this.$refs.dialog.open()},paginate(t){this.pagination.page=t.page,this.pagination.limit=t.limit,this.fetch()},submit(){this.$emit("submit",Object.values(this.selected)),this.$refs.dialog.close()},isSelected(t){return void 0!==this.selected[t.id]},item:t=>t,toggle(t){!1!==this.options.multiple&&1!==this.options.max||(this.selected={}),!0!==this.isSelected(t)?this.options.max&&this.options.max<=Object.keys(this.selected).length||this.$set(this.selected,t.id,t):this.$delete(this.selected,t.id)},toggleBtn(t){const e=this.isSelected(t);return{icon:e?this.checkedIcon:"circle-outline",tooltip:e?this.$t("remove"):this.$t("select"),theme:e?"positive":null}},updateSearch(){this.pagination.page=0,this.fetch()}}};var Pt=Mt({mixins:[Dt],computed:{emptyProps(){return{icon:"image",text:this.$t("dialog.files.empty")}}}},(function(){var t=this,e=t._self._c;return e("k-dialog",{ref:"dialog",staticClass:"k-files-dialog",attrs:{size:"medium"},on:{cancel:function(e){return t.$emit("cancel")},submit:t.submit}},[t.issue?[e("k-box",{attrs:{text:t.issue,theme:"negative"}})]:[t.options.search?e("k-input",{staticClass:"k-dialog-search",attrs:{autofocus:!0,placeholder:t.$t("search")+" …",type:"text",icon:"search"},model:{value:t.search,callback:function(e){t.search=e},expression:"search"}}):t._e(),e("k-collection",t._b({on:{item:t.toggle,paginate:t.paginate},scopedSlots:t._u([{key:"options",fn:function({item:s}){return[e("k-button",t._b({on:{click:function(e){return t.toggle(s)}}},"k-button",t.toggleBtn(s),!1))]}}])},"k-collection",t.collection,!1))]],2)}),[],!1,null,null,null,null).exports;var Nt=Mt({mixins:[Et],props:{fields:{type:[Array,Object],default:()=>[]},novalidate:{type:Boolean,default:!0},size:{type:String,default:"medium"},submitButton:{type:[String,Boolean],default:()=>window.panel.$t("save")},text:{type:String},theme:{type:String,default:"positive"},value:{type:Object,default:()=>({})}},data(){return{model:this.value}},computed:{hasFields(){return Object.keys(this.fields).length>0}},watch:{value(t,e){t!==e&&(this.model=t)}}},(function(){var t=this,e=t._self._c;return e("k-dialog",t._b({ref:"dialog",on:{cancel:function(e){return t.$emit("cancel")},close:function(e){return t.$emit("close")},ready:function(e){return t.$emit("ready")},submit:function(e){return t.$refs.form.submit()}}},"k-dialog",t.$props,!1),[t.text?[e("k-text",{domProps:{innerHTML:t._s(t.text)}})]:t._e(),t.hasFields?e("k-form",{ref:"form",attrs:{value:t.model,fields:t.fields,novalidate:t.novalidate},on:{input:function(e){return t.$emit("input",e)},submit:function(e){return t.$emit("submit",e)}}}):e("k-box",{attrs:{theme:"negative"}},[t._v(" This form dialog has no fields ")])],2)}),[],!1,null,null,null,null).exports;var qt=Mt({extends:Nt,watch:{"model.name"(t){this.fields.code.disabled||this.onNameChanges(t)},"model.code"(t){this.fields.code.disabled||(this.model.code=this.$helper.slug(t,[this.$system.ascii]),this.onCodeChanges(this.model.code))}},methods:{onCodeChanges(t){if(!t)return this.model.locale=null;if(t.length>=2)if(-1!==t.indexOf("-")){let e=t.split("-"),s=[e[0],e[1].toUpperCase()];this.model.locale=s.join("_")}else{let e=this.$system.locales||[];(null==e?void 0:e[t])?this.model.locale=e[t]:this.model.locale=null}},onNameChanges(t){this.model.code=this.$helper.slug(t,[this.model.rules,this.$system.ascii]).substr(0,2)}}},null,null,!1,null,null,null,null).exports;var Ft=Mt({mixins:[Dt],data(){const t=Dt.data();return{...t,model:{title:null,parent:null},options:{...t.options,parent:null}}},computed:{emptyProps(){return{icon:"page",text:this.$t("dialog.pages.empty")}},fetchData(){return{parent:this.options.parent}}},methods:{back(){this.options.parent=this.model.parent,this.pagination.page=1,this.fetch()},go(t){this.options.parent=t.id,this.pagination.page=1,this.fetch()},onFetched(t){this.model=t.model}}},(function(){var t=this,e=t._self._c;return e("k-dialog",{ref:"dialog",staticClass:"k-pages-dialog",attrs:{size:"medium"},on:{cancel:function(e){return t.$emit("cancel")},submit:t.submit}},[t.issue?[e("k-box",{attrs:{text:t.issue,theme:"negative"}})]:[t.model?e("header",{staticClass:"k-pages-dialog-navbar"},[e("k-button",{attrs:{disabled:!t.model.id,tooltip:t.$t("back"),icon:"angle-left"},on:{click:t.back}}),e("k-headline",[t._v(t._s(t.model.title))])],1):t._e(),t.options.search?e("k-input",{staticClass:"k-dialog-search",attrs:{autofocus:!0,placeholder:t.$t("search")+" …",type:"text",icon:"search"},model:{value:t.search,callback:function(e){t.search=e},expression:"search"}}):t._e(),e("k-collection",t._b({on:{item:t.toggle,paginate:t.paginate},scopedSlots:t._u([{key:"options",fn:function({item:s}){return[e("k-button",t._b({on:{click:function(e){return t.toggle(s)}}},"k-button",t.toggleBtn(s),!1)),s?e("k-button",{attrs:{disabled:!s.hasChildren,tooltip:t.$t("open"),icon:"angle-right"},on:{click:function(e){return e.stopPropagation(),t.go(s)}}}):t._e()]}}])},"k-collection",t.collection,!1))]],2)}),[],!1,null,null,null,null).exports;var Rt=Mt({mixins:[Et],props:{icon:{type:String,default:"trash"},submitButton:{type:[String,Boolean],default:()=>window.panel.$t("delete")},text:String,theme:{type:String,default:"negative"}}},(function(){var t=this;return(0,t._self._c)("k-text-dialog",t._g(t._b({ref:"dialog"},"k-text-dialog",t.$props,!1),t.$listeners),[t._t("default")],2)}),[],!1,null,null,null,null).exports;var zt=Mt({mixins:[Et],props:{text:String}},(function(){var t=this,e=t._self._c;return e("k-dialog",t._g(t._b({ref:"dialog"},"k-dialog",t.$props,!1),t.$listeners),[t._t("default",(function(){return[t.text?e("k-text",{domProps:{innerHTML:t._s(t.text)}}):e("k-box",{attrs:{theme:"negative"}},[t._v(" This dialog does not define any text ")])]}))],2)}),[],!1,null,null,null,null).exports;var Yt=Mt({mixins:[Dt],computed:{emptyProps(){return{icon:"users",text:this.$t("dialog.users.empty")}}},methods:{item:t=>({...t,key:t.email,info:t.info!==t.text?t.info:null})}},(function(){var t=this,e=t._self._c;return e("k-dialog",{ref:"dialog",staticClass:"k-users-dialog",attrs:{size:"medium"},on:{cancel:function(e){return t.$emit("cancel")},submit:t.submit}},[t.issue?[e("k-box",{attrs:{text:t.issue,theme:"negative"}})]:[t.options.search?e("k-input",{staticClass:"k-dialog-search",attrs:{autofocus:!0,placeholder:t.$t("search")+" …",type:"text",icon:"search"},model:{value:t.search,callback:function(e){t.search=e},expression:"search"}}):t._e(),e("k-collection",t._b({on:{item:t.toggle,paginate:t.paginate},scopedSlots:t._u([{key:"options",fn:function({item:s}){return[e("k-button",t._b({on:{click:function(e){return t.toggle(s)}}},"k-button",t.toggleBtn(s),!1))]}}])},"k-collection",t.collection,!1))]],2)}),[],!1,null,null,null,null).exports;var Ht=Mt({inheritAttrs:!1,props:{id:String,icon:String,tab:String,tabs:Object,title:String},data:()=>({click:!1}),computed:{breadcrumb(){return this.$store.state.drawers.open},hasTabs(){return this.tabs&&Object.keys(this.tabs).length>1},index(){return this.breadcrumb.findIndex((t=>t.id===this._uid))},nested(){return this.index>0}},watch:{index(){-1===this.index&&this.close()}},destroyed(){this.$store.dispatch("drawers/close",this._uid)},methods:{close(){this.$refs.overlay.close()},goTo(t){if(t===this._uid)return!0;this.$store.dispatch("drawers/goto",t)},mouseup(){!0===this.click&&this.close(),this.click=!1},mousedown(t=!1){this.click=t,!0===this.click&&this.$store.dispatch("drawers/close")},onClose(){this.$store.dispatch("drawers/close",this._uid),this.$emit("close")},onOpen(){this.$store.dispatch("drawers/open",{id:this._uid,icon:this.icon,title:this.title}),this.$emit("open")},open(){this.$refs.overlay.open()}}},(function(){var t=this,e=t._self._c;return e("k-overlay",{ref:"overlay",attrs:{dimmed:!1},on:{close:t.onClose,open:t.onOpen}},[e("div",{staticClass:"k-drawer",attrs:{"data-id":t.id,"data-nested":t.nested},on:{mousedown:function(e){return e.stopPropagation(),t.mousedown(!0)},mouseup:t.mouseup}},[e("div",{staticClass:"k-drawer-box",on:{mousedown:function(e){return e.stopPropagation(),t.mousedown(!1)}}},[e("header",{staticClass:"k-drawer-header"},[1===t.breadcrumb.length?e("h2",{staticClass:"k-drawer-title"},[e("k-icon",{attrs:{type:t.icon}}),t._v(" "+t._s(t.title)+" ")],1):e("ul",{staticClass:"k-drawer-breadcrumb"},t._l(t.breadcrumb,(function(s){return e("li",{key:s.id},[e("k-button",{attrs:{icon:s.icon,text:s.title},on:{click:function(e){return t.goTo(s.id)}}})],1)})),0),t.hasTabs?e("nav",{staticClass:"k-drawer-tabs"},t._l(t.tabs,(function(s){return e("k-button",{key:s.name,staticClass:"k-drawer-tab",attrs:{current:t.tab==s.name,text:s.label},on:{click:function(e){return e.stopPropagation(),t.$emit("tab",s.name)}}})})),1):t._e(),e("nav",{staticClass:"k-drawer-options"},[t._t("options"),e("k-button",{staticClass:"k-drawer-option",attrs:{icon:"check"},on:{click:t.close}})],2)]),e("div",{staticClass:"k-drawer-body scroll-y-auto"},[t._t("default")],2)])])])}),[],!1,null,null,null,null).exports;var Ut=Mt({inheritAttrs:!1,props:{empty:{type:String,default:()=>"Missing field setup"},icon:String,id:String,tabs:Object,title:String,type:String,value:Object},data:()=>({tab:null}),computed:{fields(){const t=this.tab||null;return(this.tabs[t]||this.firstTab).fields||{}},firstTab(){return Object.values(this.tabs)[0]}},methods:{close(){this.$refs.drawer.close()},focus(t){var e;"function"==typeof(null==(e=this.$refs.form)?void 0:e.focus)&&this.$refs.form.focus(t)},open(t,e=!0){this.$refs.drawer.open(),this.tab=t||this.firstTab.name,!1!==e&&setTimeout((()=>{let t=Object.values(this.fields).filter((t=>!0===t.autofocus))[0]||null;this.focus(t)}),1)}}},(function(){var t=this,e=t._self._c;return e("k-drawer",{ref:"drawer",staticClass:"k-form-drawer",attrs:{id:t.id,icon:t.icon,tabs:t.tabs,tab:t.tab,title:t.title},on:{close:function(e){return t.$emit("close")},open:function(e){return t.$emit("open")},tab:function(e){t.tab=e}},scopedSlots:t._u([{key:"options",fn:function(){return[t._t("options")]},proxy:!0},{key:"default",fn:function(){return[0===Object.keys(t.fields).length?e("k-box",{attrs:{theme:"info"}},[t._v(" "+t._s(t.empty)+" ")]):e("k-form",{ref:"form",attrs:{autofocus:!0,fields:t.fields,value:t.$helper.clone(t.value)},on:{input:function(e){return t.$emit("input",e)}}})]},proxy:!0}],null,!0)})}),[],!1,null,null,null,null).exports;var Kt=Mt({props:{html:{type:Boolean,default:!1},limit:{type:Number,default:10},skip:{type:Array,default:()=>[]},options:Array,query:String},data:()=>({matches:[],selected:{text:null}}),methods:{close(){this.$refs.dropdown.close()},onSelect(t){this.$emit("select",t),this.$refs.dropdown.close()},search(t){if(t.length<1)return;const e=new RegExp(RegExp.escape(t),"ig");this.matches=this.options.filter((t=>!!t.text&&(-1===this.skip.indexOf(t.value)&&null!==t.text.match(e)))).slice(0,this.limit),this.$emit("search",t,this.matches),this.$refs.dropdown.open()}}},(function(){var t=this,e=t._self._c;return e("k-dropdown",{staticClass:"k-autocomplete"},[t._t("default"),e("k-dropdown-content",t._g({ref:"dropdown",attrs:{autofocus:!0}},t.$listeners),t._l(t.matches,(function(s,i){return e("k-dropdown-item",t._b({key:i,on:{mousedown:function(e){return t.onSelect(s)},keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"tab",9,e.key,"Tab")?null:(e.preventDefault(),t.onSelect(s))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"enter",13,e.key,"Enter")?null:(e.preventDefault(),t.onSelect(s))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"left",37,e.key,["Left","ArrowLeft"])||"button"in e&&0!==e.button?null:(e.preventDefault(),t.close.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"backspace",void 0,e.key,void 0)?null:(e.preventDefault(),t.close.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"delete",[8,46],e.key,["Backspace","Delete","Del"])?null:(e.preventDefault(),t.close.apply(null,arguments))}]}},"k-dropdown-item",s,!1),[e("span",{domProps:{innerHTML:t._s(t.html?s.text:t.$esc(s.text))}})])})),1),t._v(" "+t._s(t.query)+" ")],2)}),[],!1,null,null,null,null).exports;var Jt=Mt({props:{disabled:Boolean,max:String,min:String,value:String},data(){return this.data(this.value)},computed:{numberOfDays(){return this.toDate().daysInMonth()},firstWeekday(){const t=this.toDate().day();return t>0?t:7},weekdays(){return["mon","tue","wed","thu","fri","sat","sun"].map((t=>this.$t("days."+t)))},weeks(){const t=this.firstWeekday-1;return Math.ceil((this.numberOfDays+t)/7)},monthnames(){return["january","february","march","april","may","june","july","august","september","october","november","december"].map((t=>this.$t("months."+t)))},months(){var t=[];return this.monthnames.forEach(((e,s)=>{const i=this.toDate(1,s);t.push({value:s,text:e,disabled:i.isBefore(this.current.min,"month")||i.isAfter(this.current.max,"month")})})),t},years(){var t,e,s,i;const n=null!=(e=null==(t=this.current.min)?void 0:t.get("year"))?e:this.current.year-20,o=null!=(i=null==(s=this.current.max)?void 0:s.get("year"))?i:this.current.year+20;return this.toOptions(n,o)}},watch:{value(t){const e=this.data(t);this.dt=e.dt,this.current=e.current}},methods:{data(t){const e=this.$library.dayjs.iso(t),s=this.$library.dayjs();return{dt:e,current:{month:(null!=e?e:s).month(),year:(null!=e?e:s).year(),min:this.$library.dayjs.iso(this.min),max:this.$library.dayjs.iso(this.max)}}},days(t){let e=[];const s=7*(t-1)+1,i=s+7;for(let n=s;nthis.numberOfDays;e.push(s?"":t)}return e},isDisabled(t){const e=this.toDate(t);return this.disabled||e.isBefore(this.current.min,"day")||e.isAfter(this.current.max,"day")},isSelected(t){return this.toDate(t).isSame(this.dt,"day")},isToday(t){const e=this.$library.dayjs();return this.toDate(t).isSame(e,"day")},onInput(){var t;this.$emit("input",(null==(t=this.dt)?void 0:t.toISO("date"))||null)},onNext(){const t=this.toDate().add(1,"month");this.show(t)},onPrev(){const t=this.toDate().subtract(1,"month");this.show(t)},select(t){const e="today"===t?this.$library.dayjs().merge(this.toDate(),"time"):this.toDate(t);this.dt=e,this.show(e),this.onInput()},show(t){this.current.year=t.year(),this.current.month=t.month()},toDate(t=1,e=this.current.month){return this.$library.dayjs(`${this.current.year}-${e+1}-${t}`)},toOptions(t,e){for(var s=[],i=t;i<=e;i++)s.push({value:i,text:this.$helper.pad(i)});return s}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-calendar-input"},[e("nav",[e("k-button",{attrs:{icon:"angle-left"},on:{click:t.onPrev}}),e("span",{staticClass:"k-calendar-selects"},[e("k-select-input",{attrs:{options:t.months,disabled:t.disabled,required:!0},model:{value:t.current.month,callback:function(e){t.$set(t.current,"month",t._n(e))},expression:"current.month"}}),e("k-select-input",{attrs:{options:t.years,disabled:t.disabled,required:!0},model:{value:t.current.year,callback:function(e){t.$set(t.current,"year",t._n(e))},expression:"current.year"}})],1),e("k-button",{attrs:{icon:"angle-right"},on:{click:t.onNext}})],1),e("table",{staticClass:"k-calendar-table"},[e("thead",[e("tr",t._l(t.weekdays,(function(s){return e("th",{key:"weekday_"+s},[t._v(" "+t._s(s)+" ")])})),0)]),e("tbody",t._l(t.weeks,(function(s){return e("tr",{key:"week_"+s},t._l(t.days(s),(function(s,i){return e("td",{key:"day_"+i,staticClass:"k-calendar-day",attrs:{"aria-current":!!t.isToday(s)&&"date","aria-selected":!!t.isSelected(s)&&"date"}},[s?e("k-button",{attrs:{disabled:t.isDisabled(s),text:s},on:{click:function(e){return t.select(s)}}}):t._e()],1)})),0)})),0),e("tfoot",[e("tr",[e("td",{staticClass:"k-calendar-today",attrs:{colspan:"7"}},[e("k-button",{attrs:{text:t.$t("today")},on:{click:function(e){return t.select("today")}}})],1)])])])])}),[],!1,null,null,null,null).exports;var Gt=Mt({props:{count:Number,min:Number,max:Number,required:{type:Boolean,default:!1}},computed:{valid(){return!1===this.required&&0===this.count||(!0!==this.required||0!==this.count)&&(!(this.min&&this.countthis.max))}}},(function(){var t=this,e=t._self._c;return e("span",{staticClass:"k-counter",attrs:{"data-invalid":!t.valid}},[e("span",[t._v(t._s(t.count))]),t.min&&t.max?e("span",{staticClass:"k-counter-rules"},[t._v("("+t._s(t.min)+"–"+t._s(t.max)+")")]):t.min?e("span",{staticClass:"k-counter-rules"},[t._v("≥ "+t._s(t.min))]):t.max?e("span",{staticClass:"k-counter-rules"},[t._v("≤ "+t._s(t.max))]):t._e()])}),[],!1,null,null,null,null).exports;var Vt=Mt({props:{disabled:Boolean,config:Object,fields:{type:[Array,Object],default:()=>({})},novalidate:{type:Boolean,default:!1},value:{type:Object,default:()=>({})}},data(){return{errors:{},listeners:{...this.$listeners,submit:this.onSubmit}}},methods:{focus(t){var e,s;null==(s=null==(e=this.$refs.fields)?void 0:e.focus)||s.call(e,t)},onSubmit(){this.$emit("submit",this.value)},submit(){this.$refs.submitter.click()}}},(function(){var t=this,e=t._self._c;return e("form",{ref:"form",staticClass:"k-form",attrs:{method:"POST",autocomplete:"off",novalidate:""},on:{submit:function(e){return e.preventDefault(),t.onSubmit.apply(null,arguments)}}},[t._t("header"),t._t("default",(function(){return[e("k-fieldset",t._g({ref:"fields",attrs:{disabled:t.disabled,fields:t.fields,novalidate:t.novalidate},model:{value:t.value,callback:function(e){t.value=e},expression:"value"}},t.listeners))]})),t._t("footer"),e("input",{ref:"submitter",staticClass:"k-form-submitter",attrs:{type:"submit"}})],2)}),[],!1,null,null,null,null).exports;var Wt=Mt({props:{lock:[Boolean,Object]},data:()=>({isRefreshing:null,isLocking:null}),computed:{hasChanges(){return this.$store.getters["content/hasChanges"]()},isDisabled(){return!1===this.$store.state.content.status.enabled},isLocked(){return"lock"===this.lockState},isUnlocked(){return"unlock"===this.lockState},mode(){return null!==this.lockState?this.lockState:!0===this.hasChanges?"changes":null},lockState(){return this.supportsLocking&&this.lock?this.lock.state:null},supportsLocking(){return!1!==this.lock},theme(){return"lock"===this.mode?"negative":"unlock"===this.mode?"info":"notice"}},watch:{hasChanges:{handler(t,e){!0===this.supportsLocking&&!1===this.isLocked&&!1===this.isUnlocked&&(!0===t?(this.onLock(),this.isLocking=setInterval(this.onLock,3e4)):e&&(clearInterval(this.isLocking),this.onLock(!1)))},immediate:!0},isLocked(t){!1===t&&this.$events.$emit("model.reload")}},created(){this.supportsLocking&&(this.isRefreshing=setInterval(this.check,1e4)),this.$events.$on("keydown.cmd.s",this.onSave)},destroyed(){clearInterval(this.isRefreshing),clearInterval(this.isLocking),this.$events.$off("keydown.cmd.s",this.onSave)},methods:{check(){this.$reload({navigate:!1,only:"$view.props.lock",silent:!0})},async onLock(t=!0){const e=[this.$view.path+"/lock",null,null,!0];if(!0===t)try{await this.$api.patch(...e)}catch(s){clearInterval(this.isLocking),this.$store.dispatch("content/revert")}else clearInterval(this.isLocking),await this.$api.delete(...e)},onDownload(){let t="";const e=this.$store.getters["content/changes"]();Object.keys(e).forEach((s=>{t+=s+": \n\n"+e[s],t+="\n\n----\n\n"}));let s=document.createElement("a");s.setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(t)),s.setAttribute("download",this.$view.path+".txt"),s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s)},async onResolve(){await this.onUnlock(!1),this.$store.dispatch("content/revert")},onRevert(){this.$refs.revert.open()},async onSave(t){if(!t)return!1;t.preventDefault&&t.preventDefault();try{await this.$store.dispatch("content/save"),this.$events.$emit("model.update"),this.$store.dispatch("notification/success",":)")}catch(e){if(403===e.code)return;e.details&&Object.keys(e.details).length>0?this.$store.dispatch("notification/error",{message:this.$t("error.form.incomplete"),details:e.details}):this.$store.dispatch("notification/error",{message:this.$t("error.form.notSaved"),details:[{label:"Exception: "+e.exception,message:e.message}]})}},async onUnlock(t=!0){const e=[this.$view.path+"/unlock",null,null,!0];!0===t?await this.$api.patch(...e):await this.$api.delete(...e),this.$reload({silent:!0})},revert(){this.$store.dispatch("content/revert"),this.$refs.revert.close()}}},(function(){var t=this,e=t._self._c;return e("nav",{staticClass:"k-form-buttons",attrs:{"data-theme":t.theme}},["unlock"===t.mode?e("k-view",[e("p",{staticClass:"k-form-lock-info"},[t._v(" "+t._s(t.$t("lock.isUnlocked"))+" ")]),e("span",{staticClass:"k-form-lock-buttons"},[e("k-button",{staticClass:"k-form-button",attrs:{text:t.$t("download"),icon:"download"},on:{click:t.onDownload}}),e("k-button",{staticClass:"k-form-button",attrs:{text:t.$t("confirm"),icon:"check"},on:{click:t.onResolve}})],1)]):"lock"===t.mode?e("k-view",[e("p",{staticClass:"k-form-lock-info"},[e("k-icon",{attrs:{type:"lock"}}),e("span",{domProps:{innerHTML:t._s(t.$t("lock.isLocked",{email:t.$esc(t.lock.data.email)}))}})],1),t.lock.data.unlockable?e("k-button",{staticClass:"k-form-button",attrs:{text:t.$t("lock.unlock"),icon:"unlock"},on:{click:function(e){return t.onUnlock()}}}):e("k-icon",{staticClass:"k-form-lock-loader",attrs:{type:"loader"}})],1):"changes"===t.mode?e("k-view",[e("k-button",{staticClass:"k-form-button",attrs:{disabled:t.isDisabled,text:t.$t("revert"),icon:"undo"},on:{click:t.onRevert}}),e("k-button",{staticClass:"k-form-button",attrs:{disabled:t.isDisabled,text:t.$t("save"),icon:"check"},on:{click:t.onSave}})],1):t._e(),e("k-dialog",{ref:"revert",attrs:{"submit-button":t.$t("revert"),icon:"undo",theme:"negative"},on:{submit:t.revert}},[e("k-text",{domProps:{innerHTML:t._s(t.$t("revert.confirm"))}})],1)],1)}),[],!1,null,null,null,null).exports;var Xt=Mt({data:()=>({isOpen:!1,options:[]}),computed:{hasChanges(){return this.ids.length>0},ids(){return Object.keys(this.store).filter((t=>{var e;return Object.keys((null==(e=this.store[t])?void 0:e.changes)||{}).length>0}))},store(){return this.$store.state.content.models}},methods:{async toggle(){if(!1===this.$refs.list.isOpen)try{await this.$dropdown("changes",{method:"POST",body:{ids:this.ids}})((t=>{this.options=t}))}catch(t){return this.$store.dispatch("notification/success",this.$t("lock.unsaved.empty")),this.$store.dispatch("content/clear"),!1}this.$refs.list&&this.$refs.list.toggle()}}},(function(){var t=this,e=t._self._c;return t.hasChanges?e("k-dropdown",{staticClass:"k-form-indicator"},[e("k-button",{staticClass:"k-form-indicator-toggle k-topbar-button",attrs:{icon:"edit"},on:{click:t.toggle}}),e("k-dropdown-content",{ref:"list",attrs:{align:"right",theme:"light"}},[e("p",{staticClass:"k-form-indicator-info"},[t._v(t._s(t.$t("lock.unsaved"))+":")]),e("hr"),t._l(t.options,(function(s){return e("k-dropdown-item",t._b({key:s.id},"k-dropdown-item",s,!1),[t._v(" "+t._s(s.text)+" ")])}))],2)],1):t._e()}),[],!1,null,null,null,null).exports,Zt={props:{after:String}},Qt={props:{autofocus:Boolean}},te={props:{before:String}},ee={props:{disabled:Boolean}},se={props:{help:String}},ie={props:{id:{type:[Number,String],default(){return this._uid}}}},ne={props:{invalid:Boolean}},oe={props:{label:String}},re={props:{name:[Number,String]}},le={props:{required:Boolean}};const ae={mixins:[ee,se,oe,re,le],props:{counter:[Boolean,Object],endpoints:Object,input:[String,Number],translate:Boolean,type:String}};var ue=Mt({mixins:[ae],inheritAttrs:!1,computed:{labelText(){return this.label||" "}}},(function(){var t=this,e=t._self._c;return e("div",{class:"k-field k-field-name-"+t.name,attrs:{"data-disabled":t.disabled,"data-translate":t.translate},on:{focusin:function(e){return t.$emit("focus",e)},focusout:function(e){return t.$emit("blur",e)}}},[t._t("header",(function(){return[e("header",{staticClass:"k-field-header"},[t._t("label",(function(){return[e("label",{staticClass:"k-field-label",attrs:{for:t.input}},[t._v(" "+t._s(t.labelText)+" "),t.required?e("abbr",{attrs:{title:t.$t("field.required")}},[t._v("*")]):t._e()])]})),t._t("options"),t._t("counter",(function(){return[t.counter?e("k-counter",t._b({staticClass:"k-field-counter",attrs:{required:t.required}},"k-counter",t.counter,!1)):t._e()]}))],2)]})),t._t("default"),t._t("footer",(function(){return[t.help||t.$slots.help?e("footer",{staticClass:"k-field-footer"},[t._t("help",(function(){return[t.help?e("k-text",{staticClass:"k-field-help",attrs:{theme:"help"},domProps:{innerHTML:t._s(t.help)}}):t._e()]}))],2):t._e()]}))],2)}),[],!1,null,null,null,null).exports;var ce=Mt({props:{config:Object,disabled:Boolean,fields:{type:[Array,Object],default:()=>[]},novalidate:{type:Boolean,default:!1},value:{type:Object,default:()=>({})}},data:()=>({errors:{}}),methods:{focus(t){if(t)return void(this.hasField(t)&&"function"==typeof this.$refs[t][0].focus&&this.$refs[t][0].focus());const e=Object.keys(this.$refs)[0];this.focus(e)},hasFieldType(t){return this.$helper.isComponent(`k-${t}-field`)},hasField(t){var e;return null==(e=this.$refs[t])?void 0:e[0]},meetsCondition(t){if(!t.when)return!0;let e=!0;return Object.keys(t.when).forEach((s=>{this.value[s.toLowerCase()]!==t.when[s]&&(e=!1)})),e},onInvalid(t,e,s,i){this.errors[i]=e,this.$emit("invalid",this.errors)},hasErrors(){return Object.keys(this.errors).length}}},(function(){var t=this,e=t._self._c;return e("fieldset",{staticClass:"k-fieldset"},[e("k-grid",[t._l(t.fields,(function(s,i){return["hidden"!==s.type&&t.meetsCondition(s)?e("k-column",{key:s.signature,attrs:{width:s.width}},[e("k-error-boundary",[t.hasFieldType(s.type)?e("k-"+s.type+"-field",t._b({ref:i,refInFor:!0,tag:"component",attrs:{"form-data":t.value,name:i,novalidate:t.novalidate,disabled:t.disabled||s.disabled},on:{input:function(e){return t.$emit("input",t.value,s,i)},focus:function(e){return t.$emit("focus",e,s,i)},invalid:(e,n)=>t.onInvalid(e,n,s,i),submit:function(e){return t.$emit("submit",e,s,i)}},model:{value:t.value[i],callback:function(e){t.$set(t.value,i,e)},expression:"value[fieldName]"}},"component",s,!1)):e("k-box",{attrs:{theme:"negative"}},[e("k-text",{attrs:{size:"small"}},[t._v(" The field type "),e("strong",[t._v('"'+t._s(i)+'"')]),t._v(" does not exist ")])],1)],1)],1):t._e()]}))],2)],1)}),[],!1,null,null,null,null).exports;const de={mixins:[Zt,te,ee,ne],props:{autofocus:Boolean,type:String,icon:[String,Boolean],theme:String,novalidate:{type:Boolean,default:!1},value:{type:[String,Boolean,Number,Object,Array],default:null}}};var pe=Mt({mixins:[de],inheritAttrs:!1,data(){return{isInvalid:this.invalid,listeners:{...this.$listeners,invalid:(t,e)=>{this.isInvalid=t,this.$emit("invalid",t,e)}}}},computed:{inputProps(){return{...this.$props,...this.$attrs}}},methods:{blur(t){(null==t?void 0:t.relatedTarget)&&!1===this.$el.contains(t.relatedTarget)&&this.trigger(null,"blur")},focus(t){this.trigger(t,"focus")},select(t){this.trigger(t,"select")},trigger(t,e){var s,i,n;if("INPUT"===(null==(s=null==t?void 0:t.target)?void 0:s.tagName)&&"function"==typeof(null==(i=null==t?void 0:t.target)?void 0:i[e]))return void t.target[e]();if("function"==typeof(null==(n=this.$refs.input)?void 0:n[e]))return void this.$refs.input[e]();const o=this.$el.querySelector("input, select, textarea");"function"==typeof(null==o?void 0:o[e])&&o[e]()}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-input",attrs:{"data-disabled":t.disabled,"data-invalid":!t.novalidate&&t.isInvalid,"data-theme":t.theme,"data-type":t.type}},[t.$slots.before||t.before?e("span",{staticClass:"k-input-before",on:{click:t.focus}},[t._t("before",(function(){return[t._v(t._s(t.before))]}))],2):t._e(),e("span",{staticClass:"k-input-element",on:{click:function(e){return e.stopPropagation(),t.focus.apply(null,arguments)}}},[t._t("default",(function(){return[e("k-"+t.type+"-input",t._g(t._b({ref:"input",tag:"component",attrs:{value:t.value}},"component",t.inputProps,!1),t.listeners))]}))],2),t.$slots.after||t.after?e("span",{staticClass:"k-input-after",on:{click:t.focus}},[t._t("after",(function(){return[t._v(t._s(t.after))]}))],2):t._e(),t.$slots.icon||t.icon?e("span",{staticClass:"k-input-icon",on:{click:t.focus}},[t._t("icon",(function(){return[e("k-icon",{attrs:{type:t.icon}})]}))],2):t._e()])}),[],!1,null,null,null,null).exports;var he=Mt({props:{methods:Array},data:()=>({currentForm:null,isLoading:!1,issue:"",user:{email:"",password:"",remember:!1}}),computed:{canToggle(){return null!==this.codeMode&&!0===this.methods.includes("password")&&(!0===this.methods.includes("password-reset")||!0===this.methods.includes("code"))},codeMode(){return!0===this.methods.includes("password-reset")?"password-reset":!0===this.methods.includes("code")?"code":null},fields(){let t={email:{autofocus:!0,label:this.$t("email"),type:"email",required:!0,link:!1}};return"email-password"===this.form&&(t.password={label:this.$t("password"),type:"password",minLength:8,required:!0,autocomplete:"current-password",counter:!1}),t},form(){return this.currentForm?this.currentForm:"password"===this.methods[0]?"email-password":"email"},isResetForm(){return"password-reset"===this.codeMode&&"email"===this.form},toggleText(){return this.$t("login.toggleText."+this.codeMode+"."+this.formOpposite(this.form))}},methods:{formOpposite:t=>"email-password"===t?"email":"email-password",async login(){this.issue=null,this.isLoading=!0;let t=Object.assign({},this.user);"email"===this.currentForm&&(t.password=null),!0===this.isResetForm&&(t.remember=!1);try{await this.$api.auth.login(t),this.$reload({globals:["$system","$translation"]})}catch(e){this.issue=e.message}finally{this.isLoading=!1}},toggleForm(){this.currentForm=this.formOpposite(this.form),this.$refs.fieldset.focus("email")}}},(function(){var t=this,e=t._self._c;return e("form",{staticClass:"k-login-form",on:{submit:function(e){return e.preventDefault(),t.login.apply(null,arguments)}}},[e("h1",{staticClass:"sr-only"},[t._v(" "+t._s(t.$t("login"))+" ")]),t.issue?e("k-login-alert",{on:{click:function(e){t.issue=null}}},[t._v(" "+t._s(t.issue)+" ")]):t._e(),e("div",{staticClass:"k-login-fields"},[!0===t.canToggle?e("button",{staticClass:"k-login-toggler",attrs:{type:"button"},on:{click:t.toggleForm}},[t._v(" "+t._s(t.toggleText)+" ")]):t._e(),e("k-fieldset",{ref:"fieldset",attrs:{novalidate:!0,fields:t.fields},model:{value:t.user,callback:function(e){t.user=e},expression:"user"}})],1),e("div",{staticClass:"k-login-buttons"},[!1===t.isResetForm?e("span",{staticClass:"k-login-checkbox"},[e("k-checkbox-input",{attrs:{value:t.user.remember,label:t.$t("login.remember")},on:{input:function(e){t.user.remember=e}}})],1):t._e(),e("k-button",{staticClass:"k-login-button",attrs:{icon:"check",type:"submit"}},[t._v(" "+t._s(t.$t("login"+(t.isResetForm?".reset":"")))+" "),t.isLoading?[t._v(" … ")]:t._e()],2)],1)],1)}),[],!1,null,null,null,null).exports;var me=Mt({props:{methods:Array,pending:Object},data:()=>({code:"",isLoadingBack:!1,isLoadingLogin:!1,issue:""}),computed:{mode(){return!0===this.methods.includes("password-reset")?"password-reset":"login"}},methods:{async back(){this.isLoadingBack=!0,this.$go("/logout")},async login(){this.issue=null,this.isLoadingLogin=!0;try{await this.$api.auth.verifyCode(this.code),this.$store.dispatch("notification/success",this.$t("welcome")),"password-reset"===this.mode?this.$go("reset-password"):this.$reload()}catch(t){this.issue=t.message}finally{this.isLoadingLogin=!1}}}},(function(){var t=this,e=t._self._c;return e("form",{staticClass:"k-login-form k-login-code-form",on:{submit:function(e){return e.preventDefault(),t.login.apply(null,arguments)}}},[e("h1",{staticClass:"sr-only"},[t._v(" "+t._s(t.$t("login"))+" ")]),t.issue?e("k-login-alert",{on:{click:function(e){t.issue=null}}},[t._v(" "+t._s(t.issue)+" ")]):t._e(),e("k-user-info",{attrs:{user:t.pending.email}}),e("k-text-field",{attrs:{autofocus:!0,counter:!1,help:t.$t("login.code.text."+t.pending.challenge),label:t.$t("login.code.label."+t.mode),novalidate:!0,placeholder:t.$t("login.code.placeholder."+t.pending.challenge),required:!0,autocomplete:"one-time-code",icon:"unlock",name:"code"},model:{value:t.code,callback:function(e){t.code=e},expression:"code"}}),e("div",{staticClass:"k-login-buttons"},[e("k-button",{staticClass:"k-login-button k-login-back-button",attrs:{icon:"angle-left"},on:{click:t.back}},[t._v(" "+t._s(t.$t("back"))+" "),t.isLoadingBack?[t._v(" … ")]:t._e()],2),e("k-button",{staticClass:"k-login-button",attrs:{icon:"check",type:"submit"}},[t._v(" "+t._s(t.$t("login"+("password-reset"===t.mode?".reset":"")))+" "),t.isLoadingLogin?[t._v(" … ")]:t._e()],2)],1)],1)}),[],!1,null,null,null,null).exports;var fe=Mt({props:{display:{type:String,default:"HH:mm"},value:String},computed:{day(){return this.formatTimes([6,7,8,9,10,11,"-",12,13,14,15,16,17])},night(){return this.formatTimes([18,19,20,21,22,23,"-",0,1,2,3,4,5])}},methods:{formatTimes(t){return t.map((t=>{if("-"===t)return t;const e=this.$library.dayjs(t+":00","H:mm");return{display:e.format(this.display),select:e.toISO("time")}}))},select(t){this.$emit("input",t)}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-times"},[e("div",{staticClass:"k-times-slot"},[e("k-icon",{attrs:{type:"sun"}}),e("ul",t._l(t.day,(function(s){return e("li",{key:s.select},["-"===s?e("hr"):e("k-button",{on:{click:function(e){return t.select(s.select)}}},[t._v(t._s(s.display))])],1)})),0)],1),e("div",{staticClass:"k-times-slot"},[e("k-icon",{attrs:{type:"moon"}}),e("ul",t._l(t.night,(function(s){return e("li",{key:s.select},["-"===s?e("hr"):e("k-button",{on:{click:function(e){return t.select(s.select)}}},[t._v(t._s(s.display))])],1)})),0)],1)])}),[],!1,null,null,null,null).exports;var ge=Mt({props:{accept:{type:String,default:"*"},attributes:{type:Object},max:{type:Number},method:{type:String,default:"POST"},multiple:{type:Boolean,default:!0},url:{type:String}},data(){return{options:this.$props,completed:{},errors:[],files:[],total:0}},computed:{limit(){return!1===this.options.multiple?1:this.options.max}},methods:{open(t){this.params(t),setTimeout((()=>{this.$refs.input.click()}),1)},params(t){this.options=Object.assign({},this.$props,t)},select(t){this.upload(t.target.files)},drop(t,e){this.params(e),this.upload(t)},upload(t){this.$refs.dialog.open(),this.files=[...t],this.completed={},this.errors=[],this.hasErrors=!1,this.limit&&(this.files=this.files.slice(0,this.limit)),this.total=this.files.length,this.files.forEach((t=>{var e,s;this.$helper.upload(t,{url:this.options.url,attributes:this.options.attributes,method:this.options.method,headers:{"X-CSRF":window.panel.$system.csrf},progress:(t,e,s)=>{var i,n;null==(n=null==(i=this.$refs[e.name])?void 0:i[0])||n.set(s)},success:(t,e,s)=>{this.complete(e,s.data)},error:(t,e,s)=>{this.errors.push({file:e,message:s.message}),this.complete(e,s.data)}}),void 0!==(null==(s=null==(e=this.options)?void 0:e.attributes)?void 0:s.sort)&&this.options.attributes.sort++}))},complete(t,e){if(this.completed[t.name]=e,Object.keys(this.completed).length==this.total){if(this.$refs.input.value="",this.errors.length>0)return this.$forceUpdate(),void this.$emit("error",this.files);setTimeout((()=>{this.$refs.dialog.close(),this.$emit("success",this.files,Object.values(this.completed))}),250)}}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-upload"},[e("input",{ref:"input",attrs:{accept:t.options.accept,multiple:t.options.multiple,"aria-hidden":"true",type:"file",tabindex:"-1"},on:{change:t.select,click:function(t){t.stopPropagation()}}}),e("k-dialog",{ref:"dialog",staticClass:"k-upload-dialog",attrs:{"cancel-button":!1,"submit-button":!1,size:"medium"},scopedSlots:t._u([{key:"footer",fn:function(){return[t.errors.length>0?[e("k-button-group",{attrs:{buttons:[{icon:"check",text:t.$t("confirm"),click:()=>t.$refs.dialog.close()}]}})]:t._e()]},proxy:!0}])},[t.errors.length>0?[e("k-headline",[t._v(t._s(t.$t("upload.errors")))]),e("ul",{staticClass:"k-upload-error-list"},t._l(t.errors,(function(s,i){return e("li",{key:"error-"+i},[e("p",{staticClass:"k-upload-error-filename"},[t._v(" "+t._s(s.file.name)+" ")]),e("p",{staticClass:"k-upload-error-message"},[t._v(" "+t._s(s.message)+" ")])])})),0)]:[e("k-headline",[t._v(t._s(t.$t("upload.progress")))]),e("ul",{staticClass:"k-upload-list"},t._l(t.files,(function(s,i){return e("li",{key:"file-"+i},[e("k-progress",{ref:s.name,refInFor:!0}),e("p",{staticClass:"k-upload-list-filename"},[t._v(" "+t._s(s.name)+" ")]),e("p",[t._v(t._s(t.errors[s.name]))])],1)})),0)]],2)],1)}),[],!1,null,null,null,null).exports;var ke=t=>({$from:e})=>((t,e)=>{for(let s=t.depth;s>0;s--){const i=t.node(s);if(e(i))return{pos:s>0?t.before(s):0,start:t.start(s),depth:s,node:i}}})(e,t),be=t=>e=>{if((t=>t instanceof c)(e)){const{node:s,$from:i}=e;if(((t,e)=>Array.isArray(t)&&t.indexOf(e.type)>-1||e.type===t)(t,s))return{node:s,pos:i.pos,depth:i.depth}}},ve=(t,e,s={})=>{const i=be(e)(t.selection)||ke((t=>t.type===e))(t.selection);return Object.keys(s).length&&i?i.node.hasMarkup(e,{...i.node.attrs,...s}):!!i};function ye(t=null,e=null){if(!t||!e)return!1;const s=t.parent.childAfter(t.parentOffset);if(!s.node)return!1;const i=s.node.marks.find((t=>t.type===e));if(!i)return!1;let n=t.index(),o=t.start()+s.offset,r=n+1,l=o+s.node.nodeSize;for(;n>0&&i.isInSet(t.parent.child(n-1).marks);)n-=1,o-=t.parent.child(n).nodeSize;for(;r{n=[...n,...t.marks]}));const o=n.find((t=>t.type.name===e.name));return o?o.attrs:{}},getNodeAttrs:function(t,e){const{from:s,to:i}=t.selection;let n=[];t.doc.nodesBetween(s,i,(t=>{n=[...n,t]}));const o=n.reverse().find((t=>t.type.name===e.name));return o?o.attrs:{}},markInputRule:function(t,e,s){return new r(t,((t,i,n,o)=>{const r=s instanceof Function?s(i):s,{tr:l}=t,a=i.length-1;let u=o,c=n;if(i[a]){const s=n+i[0].indexOf(i[a-1]),r=s+i[a-1].length-1,d=s+i[a-1].lastIndexOf(i[a]),p=d+i[a].length,h=function(t,e,s){let i=[];return s.doc.nodesBetween(t,e,((t,e)=>{i=[...i,...t.marks.map((s=>({start:e,end:e+t.nodeSize,mark:s})))]})),i}(n,o,t).filter((t=>{const{excluded:s}=t.mark.type;return s.find((t=>t.name===e.name))})).filter((t=>t.end>s));if(h.length)return!1;ps&&l.delete(s,d),c=s,u=c+i[a].length}return l.addMark(c,u,e.create(r)),l.removeStoredMark(e),l}))},markIsActive:function(t,e){const{from:s,$from:i,to:n,empty:o}=t.selection;return o?!!e.isInSet(t.storedMarks||i.marks()):!!t.doc.rangeHasMark(s,n,e)},markPasteRule:function(t,e,s){const i=(n,o)=>{const r=[];return n.forEach((n=>{var l;if(n.isText){const{text:i,marks:a}=n;let u,c=0;const d=!!a.filter((t=>"link"===t.type.name))[0];for(;!d&&null!==(u=t.exec(i));)if((null==(l=null==o?void 0:o.type)?void 0:l.allowsMarkType(e))&&u[1]){const t=u.index,i=t+u[0].length,o=t+u[0].indexOf(u[1]),l=o+u[1].length,a=s instanceof Function?s(u):s;t>0&&r.push(n.cut(c,t)),r.push(n.cut(o,l).mark(e.create(a).addToSet(n.marks))),c=i}cnew a(i(t.content),t.openStart,t.openEnd)}})},minMax:function(t=0,e=0,s=0){return Math.min(Math.max(parseInt(t,10),e),s)},nodeIsActive:ve,nodeInputRule:function(t,e,s){return new r(t,((t,i,n,o)=>{const r=s instanceof Function?s(i):s,{tr:l}=t;return i[0]&&l.replaceWith(n-1,o,e.create(r)),l}))},pasteRule:function(t,e,s){const i=n=>{const o=[];return n.forEach((n=>{if(n.isText){const{text:i}=n;let r,l=0;do{if(r=t.exec(i),r){const t=r.index,i=t+r[0].length,a=s instanceof Function?s(r[0]):s;t>0&&o.push(n.cut(l,t)),o.push(n.cut(t,i).mark(e.create(a).addToSet(n.marks))),l=i}}while(r);lnew a(i(t.content),t.openStart,t.openEnd)}})},removeMark:function(t){return(e,s)=>{const{tr:i,selection:n}=e;let{from:o,to:r}=n;const{$from:l,empty:a}=n;if(a){const e=ye(l,t);o=e.from,r=e.to}return i.removeMark(o,r,t),s(i)}},toggleBlockType:function(t,e,s={}){return(i,n,o)=>ve(i,t,s)?d(e)(i,n,o):d(t,s)(i,n,o)},toggleList:function(t,e){return(s,i,n)=>{const{schema:o,selection:r}=s,{$from:l,$to:a}=r,u=l.blockRange(a);if(!u)return!1;const c=ke((t=>$e(t,o)))(r);if(u.depth>=1&&c&&u.depth-c.depth<=1){if(c.node.type===t)return p(e)(s,i,n);if($e(c.node,o)&&t.validContent(c.node.content)){const{tr:e}=s;return e.setNodeMarkup(c.pos,t),i&&i(e),!1}}return h(t)(s,i,n)}},updateMark:function(t,e){return(s,i)=>{const{tr:n,selection:o,doc:r}=s,{ranges:l,empty:a}=o;if(a){const{from:s,to:i}=ye(o.$from,t);r.rangeHasMark(s,i,t)&&n.removeMark(s,i,t),n.addMark(s,i,t.create(e))}else l.forEach((s=>{const{$to:i,$from:o}=s;r.rangeHasMark(o.pos,i.pos,t)&&n.removeMark(o.pos,i.pos,t),n.addMark(o.pos,i.pos,t.create(e))}));return i(n)}}};class xe{constructor(t=[],e){t.forEach((t=>{t.bindEditor(e),t.init()})),this.extensions=t}commands({schema:t,view:e}){return this.extensions.filter((t=>t.commands)).reduce(((s,i)=>{const{name:n,type:o}=i,r={},l=i.commands({schema:t,utils:_e,...["node","mark"].includes(o)?{type:t[`${o}s`][n]}:{}}),a=(t,s)=>{r[t]=t=>{if("function"!=typeof s||!e.editable)return!1;e.focus();const i=s(t);return"function"==typeof i?i(e.state,e.dispatch,e):i}};return"object"==typeof l?Object.entries(l).forEach((([t,e])=>{a(t,e)})):a(n,l),{...s,...r}}),{})}buttons(t="mark"){const e={};return this.extensions.filter((e=>e.type===t)).filter((t=>t.button)).forEach((t=>{Array.isArray(t.button)?t.button.forEach((t=>{e[t.id||t.name]=t})):e[t.name]=t.button})),e}getAllowedExtensions(t){return t instanceof Array||!t?t instanceof Array?this.extensions.filter((e=>!t.includes(e.name))):this.extensions:[]}getFromExtensions(t,e,s=this.extensions){return s.filter((t=>["extension"].includes(t.type))).filter((e=>e[t])).map((s=>s[t]({...e,utils:_e})))}getFromNodesAndMarks(t,e,s=this.extensions){return s.filter((t=>["node","mark"].includes(t.type))).filter((e=>e[t])).map((s=>s[t]({...e,type:e.schema[`${s.type}s`][s.name],utils:_e})))}inputRules({schema:t,excludedExtensions:e}){const s=this.getAllowedExtensions(e);return[...this.getFromExtensions("inputRules",{schema:t},s),...this.getFromNodesAndMarks("inputRules",{schema:t},s)].reduce(((t,e)=>[...t,...e]),[])}keymaps({schema:t}){return[...this.getFromExtensions("keys",{schema:t}),...this.getFromNodesAndMarks("keys",{schema:t})].map((t=>_(t)))}get marks(){return this.extensions.filter((t=>"mark"===t.type)).reduce(((t,{name:e,schema:s})=>({...t,[e]:s})),{})}get nodes(){return this.extensions.filter((t=>"node"===t.type)).reduce(((t,{name:e,schema:s})=>({...t,[e]:s})),{})}get options(){const{view:t}=this;return this.extensions.reduce(((e,s)=>({...e,[s.name]:new Proxy(s.options,{set(e,s,i){const n=e[s]!==i;return Object.assign(e,{[s]:i}),n&&t.updateState(t.state),!0}})})),{})}pasteRules({schema:t,excludedExtensions:e}){const s=this.getAllowedExtensions(e);return[...this.getFromExtensions("pasteRules",{schema:t},s),...this.getFromNodesAndMarks("pasteRules",{schema:t},s)].reduce(((t,e)=>[...t,...e]),[])}plugins({schema:t}){return[...this.getFromExtensions("plugins",{schema:t}),...this.getFromNodesAndMarks("plugins",{schema:t})].reduce(((t,e)=>[...t,...e]),[]).map((t=>t instanceof l?t:new l(t)))}}class we{constructor(t={}){this.options={...this.defaults,...t}}init(){return null}bindEditor(t=null){this.editor=t}get name(){return null}get type(){return"extension"}get defaults(){return{}}plugins(){return[]}inputRules(){return[]}pasteRules(){return[]}keys(){return{}}}class Se extends we{constructor(t={}){super(t)}get type(){return"node"}get schema(){return null}commands(){return{}}}class Ce extends Se{get defaults(){return{inline:!1}}get name(){return"doc"}get schema(){return{content:this.options.inline?"inline*":"block+"}}}class Oe extends Se{get button(){return{id:this.name,icon:"paragraph",label:window.panel.$t("toolbar.button.paragraph"),name:this.name}}commands({utils:t,type:e}){return{paragraph:()=>t.setBlockType(e)}}get schema(){return{content:"inline*",group:"block",draggable:!1,parseDOM:[{tag:"p"}],toDOM:()=>["p",0]}}get name(){return"paragraph"}}class Ae extends Se{get name(){return"text"}get schema(){return{group:"inline"}}}class Te extends class{emit(t,...e){this._callbacks=this._callbacks||{};const s=this._callbacks[t];return s&&s.forEach((t=>t.apply(this,e))),this}off(t,e){if(arguments.length){const s=this._callbacks?this._callbacks[t]:null;s&&(e?this._callbacks[t]=s.filter((t=>t!==e)):delete this._callbacks[t])}else this._callbacks={};return this}on(t,e){return this._callbacks=this._callbacks||{},this._callbacks[t]=this._callbacks[t]||[],this._callbacks[t].push(e),this}}{constructor(t={}){super(),this.defaults={autofocus:!1,content:"",disableInputRules:!1,disablePasteRules:!1,editable:!0,element:null,extensions:[],emptyDocument:{type:"doc",content:[]},events:{},inline:!1,parseOptions:{},topNode:"doc",useBuiltInExtensions:!0},this.init(t)}blur(){this.view.dom.blur()}get builtInExtensions(){return this.options.useBuiltInExtensions?[new Ce({inline:this.options.inline}),new Ae,new Oe]:[]}buttons(t){return this.extensions.buttons(t)}clearContent(t=!1){this.setContent(this.options.emptyDocument,t)}command(t,...e){this.commands[t]&&this.commands[t](...e)}createCommands(){return this.extensions.commands({schema:this.schema,view:this.view})}createDocument(t,e=this.options.parseOptions){if(null===t)return this.schema.nodeFromJSON(this.options.emptyDocument);if("object"==typeof t)try{return this.schema.nodeFromJSON(t)}catch(s){return window.console.warn("Invalid content.","Passed value:",t,"Error:",s),this.schema.nodeFromJSON(this.options.emptyDocument)}if("string"==typeof t){const s=`

${t}
`,i=(new window.DOMParser).parseFromString(s,"text/html").body.firstElementChild;return x.fromSchema(this.schema).parse(i,e)}return!1}createEvents(){const t=this.options.events||{};return Object.entries(t).forEach((([t,e])=>{this.on(t,e)})),t}createExtensions(){return new xe([...this.builtInExtensions,...this.options.extensions],this)}createFocusEvents(){const t=(t,e,s=!0)=>{this.focused=s,this.emit(s?"focus":"blur",{event:e,state:t.state,view:t});const i=this.state.tr.setMeta("focused",s);this.view.dispatch(i)};return new l({props:{attributes:{tabindex:0},handleDOMEvents:{focus:(e,s)=>{t(e,s,!0)},blur:(e,s)=>{t(e,s,!1)}}}})}createInputRules(){return this.extensions.inputRules({schema:this.schema,excludedExtensions:this.options.disableInputRules})}createKeymaps(){return this.extensions.keymaps({schema:this.schema})}createMarks(){return this.extensions.marks}createNodes(){return this.extensions.nodes}createPasteRules(){return this.extensions.pasteRules({schema:this.schema,excludedExtensions:this.options.disablePasteRules})}createPlugins(){return this.extensions.plugins({schema:this.schema})}createSchema(){return new w({topNode:this.options.topNode,nodes:this.nodes,marks:this.marks})}createState(){return S.create({schema:this.schema,doc:this.createDocument(this.options.content),plugins:[...this.plugins,C({rules:this.inputRules}),...this.pasteRules,...this.keymaps,_({Backspace:I}),_(M),this.createFocusEvents()]})}createView(){return new O(this.element,{dispatchTransaction:this.dispatchTransaction.bind(this),editable:()=>this.options.editable,handlePaste:(t,e)=>{if("function"==typeof this.events.paste){const t=e.clipboardData.getData("text/html"),s=e.clipboardData.getData("text/plain");if(!0===this.events.paste(e,t,s))return!0}},handleDrop:(...t)=>{this.emit("drop",...t)},state:this.createState()})}destroy(){this.view&&this.view.destroy()}dispatchTransaction(t){const e=this.state,s=this.state.apply(t);this.view.updateState(s),this.selection={from:this.state.selection.from,to:this.state.selection.to},this.setActiveNodesAndMarks();const i={editor:this,getHTML:this.getHTML.bind(this),getJSON:this.getJSON.bind(this),state:this.state,transaction:t};this.emit("transaction",i),!t.docChanged&&t.getMeta("preventUpdate")||this.emit("update",i);const{from:n,to:o}=this.state.selection,r=!e||!e.selection.eq(s.selection);this.emit(s.selection.empty?"deselect":"select",{...i,from:n,hasChanged:r,to:o})}focus(t=null){if(this.view.focused&&null===t||!1===t)return;const{from:e,to:s}=this.selectionAtPosition(t);this.setSelection(e,s),setTimeout((()=>this.view.focus()),10)}getHTML(){const t=document.createElement("div"),e=A.fromSchema(this.schema).serializeFragment(this.state.doc.content);return t.appendChild(e),this.options.inline&&t.querySelector("p")?t.querySelector("p").innerHTML:t.innerHTML}getJSON(){return this.state.doc.toJSON()}getMarkAttrs(t=null){return this.activeMarkAttrs[t]}getSchemaJSON(){return JSON.parse(JSON.stringify({nodes:this.nodes,marks:this.marks}))}init(t={}){this.options={...this.defaults,...t},this.element=this.options.element,this.focused=!1,this.selection={from:0,to:0},this.events=this.createEvents(),this.extensions=this.createExtensions(),this.nodes=this.createNodes(),this.marks=this.createMarks(),this.schema=this.createSchema(),this.keymaps=this.createKeymaps(),this.inputRules=this.createInputRules(),this.pasteRules=this.createPasteRules(),this.plugins=this.createPlugins(),this.view=this.createView(),this.commands=this.createCommands(),this.setActiveNodesAndMarks(),!1!==this.options.autofocus&&this.focus(this.options.autofocus),this.emit("init",{view:this.view,state:this.state}),this.extensions.view=this.view,this.setContent(this.options.content,!0)}isEditable(){return this.options.editable}isEmpty(){if(this.state)return 0===this.state.doc.textContent.length}get isActive(){return Object.entries({...this.activeMarks,...this.activeNodes}).reduce(((t,[e,s])=>({...t,[e]:(t={})=>s(t)})),{})}removeMark(t){if(this.schema.marks[t])return _e.removeMark(this.schema.marks[t])(this.state,this.view.dispatch)}selectionAtPosition(t=null){if(this.selection&&null===t)return this.selection;if("start"===t||!0===t)return{from:0,to:0};if("end"===t){const{doc:t}=this.state;return{from:t.content.size,to:t.content.size}}return{from:t,to:t}}setActiveNodesAndMarks(){this.activeMarks=Object.values(this.schema.marks).filter((t=>_e.markIsActive(this.state,t))).map((t=>t.name)),this.activeMarkAttrs=Object.entries(this.schema.marks).reduce(((t,[e,s])=>({...t,[e]:_e.getMarkAttrs(this.state,s)})),{}),this.activeNodes=Object.values(this.schema.nodes).filter((t=>_e.nodeIsActive(this.state,t))).map((t=>t.name)),this.activeNodeAttrs=Object.entries(this.schema.nodes).reduce(((t,[e,s])=>({...t,[e]:_e.getNodeAttrs(this.state,s)})),{})}setContent(t={},e=!1,s){const{doc:i,tr:n}=this.state,o=this.createDocument(t,s),r=n.replaceWith(0,i.content.size,o).setMeta("preventUpdate",!e);this.view.dispatch(r)}setSelection(t=0,e=0){const{doc:s,tr:i}=this.state,n=_e.minMax(t,0,s.content.size),o=_e.minMax(e,0,s.content.size),r=T.create(s,n,o),l=i.setSelection(r);this.view.dispatch(l)}get state(){return this.view?this.view.state:null}toggleMark(t){if(this.schema.marks[t])return _e.toggleMark(this.schema.marks[t])(this.state,this.view.dispatch)}updateMark(t,e){if(this.schema.marks[t])return _e.updateMark(this.schema.marks[t],e)(this.state,this.view.dispatch)}}var Ie=Mt({data:()=>({link:{href:null,title:null,target:!1}}),computed:{fields(){return{href:{label:this.$t("url"),type:"text",icon:"url"},title:{label:this.$t("title"),type:"text",icon:"title"},target:{label:this.$t("open.newWindow"),type:"toggle",text:[this.$t("no"),this.$t("yes")]}}}},methods:{open(t){this.link={title:null,target:!1,...t},this.link.target=Boolean(this.link.target),this.$refs.dialog.open()},submit(){this.$emit("submit",{...this.link,target:this.link.target?"_blank":null}),this.$refs.dialog.close()}}},(function(){var t=this;return(0,t._self._c)("k-form-dialog",{ref:"dialog",attrs:{fields:t.fields,"submit-button":t.$t("confirm"),size:"medium"},on:{close:function(e){return t.$emit("close")},submit:t.submit},model:{value:t.link,callback:function(e){t.link=e},expression:"link"}})}),[],!1,null,null,null,null).exports;var Me=Mt({data:()=>({email:{email:null,title:null}}),computed:{fields(){return{href:{label:this.$t("email"),type:"email",icon:"email"},title:{label:this.$t("title"),type:"text",icon:"title"}}}},methods:{open(t){this.email={title:null,...t},this.$refs.dialog.open()},submit(){this.$emit("submit",this.email),this.$refs.dialog.close()}}},(function(){var t=this;return(0,t._self._c)("k-form-dialog",{ref:"dialog",attrs:{fields:t.fields,"submit-button":t.$t("confirm"),size:"medium"},on:{close:function(e){return t.$emit("close")},submit:t.submit},model:{value:t.email,callback:function(e){t.email=e},expression:"email"}})}),[],!1,null,null,null,null).exports;class Le extends we{constructor(t={}){super(t)}command(){return()=>{}}remove(){this.editor.removeMark(this.name)}get schema(){return null}get type(){return"mark"}toggle(){return this.editor.toggleMark(this.name)}update(t){this.editor.updateMark(this.name,t)}}class Ee extends Le{get button(){return{icon:"code",label:window.panel.$t("toolbar.button.code")}}commands(){return()=>this.toggle()}inputRules({type:t,utils:e}){return[e.markInputRule(/(?:`)([^`]+)(?:`)$/,t)]}keys(){return{"Mod-`":()=>this.toggle()}}get name(){return"code"}pasteRules({type:t,utils:e}){return[e.markPasteRule(/(?:`)([^`]+)(?:`)/g,t)]}get schema(){return{excludes:"_",parseDOM:[{tag:"code"}],toDOM:()=>["code",0]}}}class je extends Le{get button(){return{icon:"bold",label:window.panel.$t("toolbar.button.bold")}}commands(){return()=>this.toggle()}inputRules({type:t,utils:e}){return[e.markInputRule(/(?:\*\*|__)([^*_]+)(?:\*\*|__)$/,t)]}keys(){return{"Mod-b":()=>this.toggle()}}get name(){return"bold"}pasteRules({type:t,utils:e}){return[e.markPasteRule(/(?:\*\*|__)([^*_]+)(?:\*\*|__)/g,t)]}get schema(){return{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:t=>"normal"!==t.style.fontWeight&&null},{style:"font-weight",getAttrs:t=>/^(bold(er)?|[5-9]\d{2,})$/.test(t)&&null}],toDOM:()=>["strong",0]}}}class Be extends Le{get button(){return{icon:"italic",label:window.panel.$t("toolbar.button.italic")}}commands(){return()=>this.toggle()}inputRules({type:t,utils:e}){return[e.markInputRule(/(?:^|\s)((?:\*)((?:[^*]+))(?:\*))$/,t),e.markInputRule(/(?:^|\s)((?:_)((?:[^_]+))(?:_))$/,t)]}keys(){return{"Mod-i":()=>this.toggle()}}get name(){return"italic"}pasteRules({type:t,utils:e}){return[e.markPasteRule(/_([^_]+)_/g,t),e.markPasteRule(/\*([^*]+)\*/g,t)]}get schema(){return{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"}],toDOM:()=>["em",0]}}}class De extends Le{get button(){return{icon:"url",label:window.panel.$t("toolbar.button.link")}}commands(){return{link:()=>{this.editor.emit("link",this.editor)},insertLink:(t={})=>{if(t.href)return this.update(t)},removeLink:()=>this.remove(),toggleLink:(t={})=>{var e;(null==(e=t.href)?void 0:e.length)>0?this.editor.command("insertLink",t):this.editor.command("removeLink")}}}get defaults(){return{target:null}}get name(){return"link"}pasteRules({type:t,utils:e}){return[e.pasteRule(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b([-a-zA-Z0-9@:%_+.~#?&//=,]*)/gi,t,(t=>({href:t})))]}plugins(){return[{props:{handleClick:(t,e,s)=>{const i=this.editor.getMarkAttrs("link");i.href&&!0===s.altKey&&s.target instanceof HTMLAnchorElement&&(s.stopPropagation(),window.open(i.href,i.target))}}}]}get schema(){return{attrs:{href:{default:null},target:{default:null},title:{default:null}},inclusive:!1,parseDOM:[{tag:"a[href]:not([href^='mailto:'])",getAttrs:t=>({href:t.getAttribute("href"),target:t.getAttribute("target"),title:t.getAttribute("title")})}],toDOM:t=>["a",{...t.attrs,rel:"noopener noreferrer"},0]}}}class Pe extends Le{get button(){return{icon:"email",label:"Email"}}commands(){return{email:()=>{this.editor.emit("email")},insertEmail:(t={})=>{if(t.href)return this.update(t)},removeEmail:()=>this.remove(),toggleEmail:(t={})=>{var e;(null==(e=t.href)?void 0:e.length)>0?this.editor.command("insertEmail",t):this.editor.command("removeEmail")}}}get defaults(){return{target:null}}get name(){return"email"}pasteRules({type:t,utils:e}){return[e.pasteRule(/^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/gi,t,(t=>({href:t})))]}plugins(){return[{props:{handleClick:(t,e,s)=>{const i=this.editor.getMarkAttrs("email");i.href&&!0===s.altKey&&s.target instanceof HTMLAnchorElement&&(s.stopPropagation(),window.open(i.href))}}}]}get schema(){return{attrs:{href:{default:null},title:{default:null}},inclusive:!1,parseDOM:[{tag:"a[href^='mailto:']",getAttrs:t=>({href:t.getAttribute("href").replace("mailto:",""),title:t.getAttribute("title")})}],toDOM:t=>["a",{...t.attrs,href:"mailto:"+t.attrs.href},0]}}}class Ne extends Le{get button(){return{icon:"strikethrough",label:window.panel.$t("toolbar.button.strike")}}commands(){return()=>this.toggle()}inputRules({type:t,utils:e}){return[e.markInputRule(/~([^~]+)~$/,t)]}keys(){return{"Mod-d":()=>this.toggle()}}get name(){return"strike"}pasteRules({type:t,utils:e}){return[e.markPasteRule(/~([^~]+)~/g,t)]}get schema(){return{parseDOM:[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",getAttrs:t=>"line-through"===t}],toDOM:()=>["s",0]}}}class qe extends Le{get button(){return{icon:"underline",label:window.panel.$t("toolbar.button.underline")}}commands(){return()=>this.toggle()}keys(){return{"Mod-u":()=>this.toggle()}}get name(){return"underline"}get schema(){return{parseDOM:[{tag:"u"},{style:"text-decoration",getAttrs:t=>"underline"===t}],toDOM:()=>["u",0]}}}class Fe extends Se{get button(){return{id:this.name,icon:"list-bullet",label:window.panel.$t("toolbar.button.ul"),name:this.name,when:["listItem","bulletList","orderedList"]}}commands({type:t,schema:e,utils:s}){return()=>s.toggleList(t,e.nodes.listItem)}inputRules({type:t,utils:e}){return[e.wrappingInputRule(/^\s*([-+*])\s$/,t)]}keys({type:t,schema:e,utils:s}){return{"Shift-Ctrl-8":s.toggleList(t,e.nodes.listItem)}}get name(){return"bulletList"}get schema(){return{content:"listItem+",group:"block",parseDOM:[{tag:"ul"}],toDOM:()=>["ul",0]}}}class Re extends Se{commands({utils:t,type:e}){return()=>this.createHardBreak(t,e)}createHardBreak(t,e){return t.chainCommands(t.exitCode,((t,s)=>(s(t.tr.replaceSelectionWith(e.create()).scrollIntoView()),!0)))}get defaults(){return{enter:!1,text:!1}}keys({utils:t,type:e}){const s=this.createHardBreak(t,e);let i={"Mod-Enter":s,"Shift-Enter":s};return this.options.enter&&(i.Enter=s),i}get name(){return"hardBreak"}get schema(){return{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM:()=>["br"]}}}class ze extends Se{get button(){return this.options.levels.map((t=>({id:`h${t}`,command:`h${t}`,icon:`h${t}`,label:window.panel.$t("toolbar.button.heading."+t),attrs:{level:t},name:this.name,when:["heading","paragraph"]})))}commands({type:t,schema:e,utils:s}){let i={toggleHeading:i=>s.toggleBlockType(t,e.nodes.paragraph,i)};return this.options.levels.forEach((n=>{i[`h${n}`]=()=>s.toggleBlockType(t,e.nodes.paragraph,{level:n})})),i}get defaults(){return{levels:[1,2,3,4,5,6]}}inputRules({type:t,utils:e}){return this.options.levels.map((s=>e.textblockTypeInputRule(new RegExp(`^(#{1,${s}})\\s$`),t,(()=>({level:s})))))}keys({type:t,utils:e}){return this.options.levels.reduce(((s,i)=>({...s,[`Shift-Ctrl-${i}`]:e.setBlockType(t,{level:i})})),{})}get name(){return"heading"}get schema(){return{attrs:{level:{default:1}},content:"inline*",group:"block",defining:!0,draggable:!1,parseDOM:this.options.levels.map((t=>({tag:`h${t}`,attrs:{level:t}}))),toDOM:t=>[`h${t.attrs.level}`,0]}}}class Ye extends Se{commands({type:t}){return()=>(e,s)=>s(e.tr.replaceSelectionWith(t.create()))}inputRules({type:t,utils:e}){return[e.nodeInputRule(/^(?:---|___\s|\*\*\*\s)$/,t)]}get name(){return"horizontalRule"}get schema(){return{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>["hr"]}}}class He extends Se{keys({type:t,utils:e}){return{Enter:e.splitListItem(t),"Shift-Tab":e.liftListItem(t),Tab:e.sinkListItem(t)}}get name(){return"listItem"}get schema(){return{content:"paragraph block*",defining:!0,draggable:!1,parseDOM:[{tag:"li"}],toDOM:()=>["li",0]}}}class Ue extends Se{get button(){return{id:this.name,icon:"list-numbers",label:window.panel.$t("toolbar.button.ol"),name:this.name,when:["listItem","bulletList","orderedList"]}}commands({type:t,schema:e,utils:s}){return()=>s.toggleList(t,e.nodes.listItem)}inputRules({type:t,utils:e}){return[e.wrappingInputRule(/^(\d+)\.\s$/,t,(t=>({order:+t[1]})),((t,e)=>e.childCount+e.attrs.order===+t[1]))]}keys({type:t,schema:e,utils:s}){return{"Shift-Ctrl-9":s.toggleList(t,e.nodes.listItem)}}get name(){return"orderedList"}get schema(){return{attrs:{order:{default:1}},content:"listItem+",group:"block",parseDOM:[{tag:"ol",getAttrs:t=>({order:t.hasAttribute("start")?+t.getAttribute("start"):1})}],toDOM:t=>1===t.attrs.order?["ol",0]:["ol",{start:t.attrs.order},0]}}}class Ke extends we{commands(){return{undo:()=>L,redo:()=>E,undoDepth:()=>j,redoDepth:()=>B}}get defaults(){return{depth:"",newGroupDelay:""}}keys(){return{"Mod-z":L,"Mod-y":E,"Shift-Mod-z":E,"Mod-я":L,"Shift-Mod-я":E}}get name(){return"history"}plugins(){return[D({depth:this.options.depth,newGroupDelay:this.options.newGroupDelay})]}}class Je extends we{commands(){return{insertHtml:t=>(e,s)=>{let i=document.createElement("div");i.innerHTML=t.trim();const n=x.fromSchema(e.schema).parse(i);s(e.tr.replaceSelectionWith(n).scrollIntoView())}}}}class Ge extends we{constructor(t={}){super(t)}close(){this.visible=!1,this.emit()}emit(){this.editor.emit("toolbar",{marks:this.marks,nodes:this.nodes,nodeAttrs:this.nodeAttrs,position:this.position,visible:this.visible})}init(){this.position={left:0,bottom:0},this.visible=!1,this.editor.on("blur",(()=>{this.close()})),this.editor.on("deselect",(()=>{this.close()})),this.editor.on("select",(({hasChanged:t})=>{!1!==t?this.open():this.emit()}))}get marks(){return this.editor.activeMarks}get nodes(){return this.editor.activeNodes}get nodeAttrs(){return this.editor.activeNodeAttrs}open(){this.visible=!0,this.reposition(),this.emit()}reposition(){const{from:t,to:e}=this.editor.selection,s=this.editor.view.coordsAtPos(t),i=this.editor.view.coordsAtPos(e,!0),n=this.editor.element.getBoundingClientRect();let o=(s.left+i.left)/2-n.left,r=Math.round(n.bottom-s.top);return this.position={bottom:r,left:o}}get type(){return"toolbar"}}var Ve=Mt({props:{activeMarks:{type:Array,default:()=>[]},activeNodes:{type:Array,default:()=>[]},activeNodeAttrs:{type:[Array,Object],default:()=>[]},editor:{type:Object,required:!0},marks:{type:Array},isParagraphNodeHidden:{type:Boolean,default:!1}},computed:{activeButton(){return Object.values(this.nodeButtons).find((t=>this.isButtonActive(t)))||!1},hasVisibleButtons(){const t=Object.keys(this.nodeButtons);return t.length>1||1===t.length&&!1===t.includes("paragraph")},markButtons(){return this.buttons("mark")},nodeButtons(){let t=this.buttons("node");return!0===this.isParagraphNodeHidden&&t.paragraph&&delete t.paragraph,t}},methods:{buttons(t){const e=this.editor.buttons(t);let s=this.sorting;!1!==s&&!1!==Array.isArray(s)||(s=Object.keys(e));let i={};return s.forEach((t=>{e[t]&&(i[t]=e[t])})),i},command(t,...e){this.$emit("command",t,...e)},isButtonActive(t){if("paragraph"===t.name)return 1===this.activeNodes.length&&this.activeNodes.includes(t.name);let e=!0;if(t.attrs){const s=Object.values(this.activeNodeAttrs).find((e=>JSON.stringify(e)===JSON.stringify(t.attrs)));e=Boolean(s||!1)}return!0===e&&this.activeNodes.includes(t.name)},isButtonCurrent(t){return!!this.activeButton&&this.activeButton.id===t.id},isButtonDisabled(t){var e;if(null==(e=this.activeButton)?void 0:e.when){return!1===this.activeButton.when.includes(t.name)}return!1},needDividerAfterNode(t){let e=["paragraph"],s=Object.keys(this.nodeButtons);return(s.includes("bulletList")||s.includes("orderedList"))&&e.push("h6"),e.includes(t.id)}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-writer-toolbar"},[t.hasVisibleButtons?e("k-dropdown",{nativeOn:{mousedown:function(t){t.preventDefault()}}},[e("k-button",{class:{"k-writer-toolbar-button k-writer-toolbar-nodes":!0,"k-writer-toolbar-button-active":!!t.activeButton},attrs:{icon:t.activeButton.icon||"title"},on:{click:function(e){return t.$refs.nodes.toggle()}}}),e("k-dropdown-content",{ref:"nodes"},[t._l(t.nodeButtons,(function(s,i){return[e("k-dropdown-item",{key:i,attrs:{current:t.isButtonCurrent(s),disabled:t.isButtonDisabled(s),icon:s.icon},on:{click:function(e){return t.command(s.command||i)}}},[t._v(" "+t._s(s.label)+" ")]),t.needDividerAfterNode(s)?e("hr",{key:i+"-divider"}):t._e()]}))],2)],1):t._e(),t._l(t.markButtons,(function(s,i){return e("k-button",{key:i,class:{"k-writer-toolbar-button":!0,"k-writer-toolbar-button-active":t.activeMarks.includes(i)},attrs:{icon:s.icon,tooltip:s.label},on:{mousedown:function(e){return e.preventDefault(),t.command(s.command||i)}}})}))],2)}),[],!1,null,null,null,null).exports;const We={props:{autofocus:Boolean,breaks:Boolean,code:Boolean,disabled:Boolean,emptyDocument:{type:Object,default:()=>({type:"doc",content:[]})},headings:[Array,Boolean],inline:{type:Boolean,default:!1},marks:{type:[Array,Boolean],default:!0},nodes:{type:[Array,Boolean],default:()=>["heading","bulletList","orderedList"]},paste:{type:Function,default:()=>()=>!1},placeholder:String,spellcheck:Boolean,extensions:Array,value:{type:String,default:""}}};var Xe=Mt({components:{"k-writer-email-dialog":Me,"k-writer-link-dialog":Ie,"k-writer-toolbar":Ve},mixins:[We],data(){return{editor:null,json:{},html:this.value,isEmpty:!0,toolbar:!1}},computed:{isParagraphNodeHidden(){return!0===Array.isArray(this.nodes)&&3!==this.nodes.length&&!1===this.nodes.includes("paragraph")}},watch:{value(t,e){t!==e&&t!==this.html&&(this.html=t,this.editor.setContent(this.html))}},mounted(){this.editor=new Te({autofocus:this.autofocus,content:this.value,editable:!this.disabled,element:this.$el,emptyDocument:this.emptyDocument,events:{link:t=>{this.$refs.linkDialog.open(t.getMarkAttrs("link"))},email:()=>{this.$refs.emailDialog.open(this.editor.getMarkAttrs("email"))},paste:this.paste,toolbar:t=>{this.toolbar=t,this.toolbar.visible&&this.$nextTick((()=>{this.onToolbarOpen()}))},update:t=>{if(!this.editor)return;const e=JSON.stringify(this.editor.getJSON());e!==JSON.stringify(this.json)&&(this.json=e,this.isEmpty=t.editor.isEmpty(),this.html=t.editor.getHTML(),this.isEmpty&&(0===t.editor.activeNodes.length||t.editor.activeNodes.includes("paragraph"))&&(this.html=""),this.$emit("input",this.html))}},extensions:[...this.createMarks(),...this.createNodes(),new Ke,new Je,new Ge,...this.extensions||[]],inline:this.inline}),this.isEmpty=this.editor.isEmpty(),this.json=this.editor.getJSON()},beforeDestroy(){this.editor.destroy()},methods:{filterExtensions(t,e,s){!1===e?e=[]:!0!==e&&!1!==Array.isArray(e)||(e=Object.keys(t));let i=[];return e.forEach((e=>{t[e]&&i.push(t[e])})),"function"==typeof s&&(i=s(e,i)),i},command(t,...e){this.editor.command(t,...e)},createMarks(){return this.filterExtensions({bold:new je,italic:new Be,strike:new Ne,underline:new qe,code:new Ee,link:new De,email:new Pe},this.marks)},createNodes(){const t=new Re({text:!0,enter:this.inline});return!0===this.inline?[t]:this.filterExtensions({bulletList:new Fe,orderedList:new Ue,heading:new ze,horizontalRule:new Ye,listItem:new He},this.nodes,((e,s)=>((e.includes("bulletList")||e.includes("orderedList"))&&s.push(new He),s.push(t),s)))},getHTML(){return this.editor.getHTML()},focus(){this.editor.focus()},onToolbarOpen(){if(this.$refs.toolbar){const t=this.$el.clientWidth,e=this.$refs.toolbar.$el.clientWidth;let s=this.toolbar.position.left;s-e/2<0&&(s=s+(e/2-s)-20),s+e/2>t&&(s=s-(s+e/2-t)+20),s!==this.toolbar.position.left&&(this.$refs.toolbar.$el.style.left=s+"px")}}}},(function(){var t=this,e=t._self._c;return e("div",{directives:[{name:"direction",rawName:"v-direction"}],ref:"editor",staticClass:"k-writer",attrs:{"data-empty":t.isEmpty,"data-placeholder":t.placeholder,spellcheck:t.spellcheck}},[t.editor?[t.toolbar.visible?e("k-writer-toolbar",{ref:"toolbar",style:{bottom:t.toolbar.position.bottom+"px","inset-inline-start":t.toolbar.position.left+"px"},attrs:{editor:t.editor,"active-marks":t.toolbar.marks,"active-nodes":t.toolbar.nodes,"active-node-attrs":t.toolbar.nodeAttrs,"is-paragraph-node-hidden":t.isParagraphNodeHidden},on:{command:function(e){return t.editor.command(e)}}}):t._e(),e("k-writer-link-dialog",{ref:"linkDialog",on:{close:function(e){return t.editor.focus()},submit:function(e){return t.editor.command("toggleLink",e)}}}),e("k-writer-email-dialog",{ref:"emailDialog",on:{close:function(e){return t.editor.focus()},submit:function(e){return t.editor.command("toggleEmail",e)}}})]:t._e()],2)}),[],!1,null,null,null,null).exports;var Ze=Mt({},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-login-alert",on:{click:function(e){return t.$emit("click")}}},[e("span",[t._t("default")],2),e("k-icon",{attrs:{type:"alert"}})],1)}),[],!1,null,null,null,null).exports;var Qe=Mt({props:{fields:Object,index:[Number,String],total:Number,value:Object},mounted(){this.$store.dispatch("content/disable"),this.$events.$on("keydown.cmd.s",this.onSubmit),this.$events.$on("keydown.esc",this.onDiscard)},destroyed(){this.$events.$off("keydown.cmd.s",this.onSubmit),this.$events.$off("keydown.esc",this.onDiscard),this.$store.dispatch("content/enable")},methods:{focus(t){this.$refs.form.focus(t)},onDiscard(){this.$emit("discard")},onInput(t){this.$emit("input",t)},onSubmit(){this.$emit("submit")}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-structure-form"},[e("div",{staticClass:"k-structure-backdrop",on:{click:t.onDiscard}}),e("section",[e("k-form",{ref:"form",staticClass:"k-structure-form-fields",attrs:{value:t.value,fields:t.fields},on:{input:t.onInput,submit:t.onSubmit}}),e("footer",{staticClass:"k-structure-form-buttons"},[e("k-button",{staticClass:"k-structure-form-cancel-button",attrs:{text:t.$t("cancel"),icon:"cancel"},on:{click:function(e){return t.$emit("close")}}}),"new"!==t.index?e("k-pagination",{attrs:{dropdown:!1,total:t.total,limit:1,page:t.index+1,details:!0},on:{paginate:function(e){return t.$emit("paginate",e)}}}):t._e(),e("k-button",{staticClass:"k-structure-form-submit-button",attrs:{text:t.$t("new"!==t.index?"confirm":"add"),icon:"check"},on:{click:t.onSubmit}})],1)],1)])}),[],!1,null,null,null,null).exports;const ts=function(t){this.command("insert",((e,s)=>{let i=[];return s.split("\n").forEach(((e,s)=>{let n="ol"===t?s+1+".":"-";i.push(n+" "+e)})),i.join("\n")}))};var es=Mt({layout:["headlines","bold","italic","|","link","email","file","|","code","ul","ol"],props:{buttons:{type:[Boolean,Array],default:!0},uploads:[Boolean,Object,Array]},data(){let t={},e={},s=[],i=this.commands();return!1===this.buttons?t:(Array.isArray(this.buttons)&&(s=this.buttons),!0!==Array.isArray(this.buttons)&&(s=this.$options.layout),s.forEach(((s,n)=>{if("|"===s)t["divider-"+n]={divider:!0};else if(i[s]){let n=i[s];t[s]=n,n.shortcut&&(e[n.shortcut]=s)}})),{layout:t,shortcuts:e})},methods:{command(t,e){"function"==typeof t?t.apply(this):this.$emit("command",t,e)},close(){Object.keys(this.$refs).forEach((t=>{const e=this.$refs[t][0];"function"==typeof(null==e?void 0:e.close)&&e.close()}))},fileCommandSetup(){let t={label:this.$t("toolbar.button.file"),icon:"attachment"};return!1===this.uploads?t.command="selectFile":t.dropdown={select:{label:this.$t("toolbar.button.file.select"),icon:"check",command:"selectFile"},upload:{label:this.$t("toolbar.button.file.upload"),icon:"upload",command:"uploadFile"}},t},commands(){return{headlines:{label:this.$t("toolbar.button.headings"),icon:"title",dropdown:{h1:{label:this.$t("toolbar.button.heading.1"),icon:"title",command:"prepend",args:"#"},h2:{label:this.$t("toolbar.button.heading.2"),icon:"title",command:"prepend",args:"##"},h3:{label:this.$t("toolbar.button.heading.3"),icon:"title",command:"prepend",args:"###"}}},bold:{label:this.$t("toolbar.button.bold"),icon:"bold",command:"wrap",args:"**",shortcut:"b"},italic:{label:this.$t("toolbar.button.italic"),icon:"italic",command:"wrap",args:"*",shortcut:"i"},link:{label:this.$t("toolbar.button.link"),icon:"url",shortcut:"k",command:"dialog",args:"link"},email:{label:this.$t("toolbar.button.email"),icon:"email",shortcut:"e",command:"dialog",args:"email"},file:this.fileCommandSetup(),code:{label:this.$t("toolbar.button.code"),icon:"code",command:"wrap",args:"`"},ul:{label:this.$t("toolbar.button.ul"),icon:"list-bullet",command(){return ts.apply(this,["ul"])}},ol:{label:this.$t("toolbar.button.ol"),icon:"list-numbers",command(){return ts.apply(this,["ol"])}}}},shortcut(t,e){if(this.shortcuts[t]){const s=this.layout[this.shortcuts[t]];if(!s)return!1;e.preventDefault(),this.command(s.command,s.args)}}}},(function(){var t=this,e=t._self._c;return e("nav",{staticClass:"k-toolbar"},[e("div",{staticClass:"k-toolbar-wrapper"},[e("div",{staticClass:"k-toolbar-buttons"},[t._l(t.layout,(function(s,i){return[s.divider?[e("span",{key:i,staticClass:"k-toolbar-divider"})]:s.dropdown?[e("k-dropdown",{key:i},[e("k-button",{key:i,staticClass:"k-toolbar-button",attrs:{icon:s.icon,tooltip:s.label,tabindex:"-1"},on:{click:function(e){t.$refs[i+"-dropdown"][0].toggle()}}}),e("k-dropdown-content",{ref:i+"-dropdown",refInFor:!0},t._l(s.dropdown,(function(s,i){return e("k-dropdown-item",{key:i,attrs:{icon:s.icon},on:{click:function(e){return t.command(s.command,s.args)}}},[t._v(" "+t._s(s.label)+" ")])})),1)],1)]:[e("k-button",{key:i,staticClass:"k-toolbar-button",attrs:{icon:s.icon,tooltip:s.label,tabindex:"-1"},on:{click:function(e){return t.command(s.command,s.args)}}})]]}))],2)])])}),[],!1,null,null,null,null).exports;var ss=Mt({data(){return{value:{email:null,text:null},fields:{email:{label:this.$t("email"),type:"email"},text:{label:this.$t("link.text"),type:"text"}}}},computed:{kirbytext(){return this.$config.kirbytext}},methods:{open(t,e){this.value.text=e,this.$refs.dialog.open()},cancel(){this.$emit("cancel")},createKirbytext(){var t;const e=this.value.email||"";return(null==(t=this.value.text)?void 0:t.length)>0?`(email: ${e} text: ${this.value.text})`:`(email: ${e})`},createMarkdown(){var t;const e=this.value.email||"";return(null==(t=this.value.text)?void 0:t.length)>0?`[${this.value.text}](mailto:${e})`:`<${e}>`},submit(){this.$emit("submit",this.kirbytext?this.createKirbytext():this.createMarkdown()),this.value={email:null,text:null},this.$refs.dialog.close()}}},(function(){var t=this,e=t._self._c;return e("k-dialog",{ref:"dialog",attrs:{"submit-button":t.$t("insert")},on:{close:t.cancel,submit:function(e){return t.$refs.form.submit()}}},[e("k-form",{ref:"form",attrs:{fields:t.fields},on:{submit:t.submit},model:{value:t.value,callback:function(e){t.value=e},expression:"value"}})],1)}),[],!1,null,null,null,null).exports;var is=Mt({data(){return{value:{url:null,text:null},fields:{url:{label:this.$t("link"),type:"text",placeholder:this.$t("url.placeholder"),icon:"url"},text:{label:this.$t("link.text"),type:"text"}}}},computed:{kirbytext(){return this.$config.kirbytext}},methods:{open(t,e){this.value.text=e,this.$refs.dialog.open()},cancel(){this.$emit("cancel")},createKirbytext(){return this.value.text.length>0?`(link: ${this.value.url} text: ${this.value.text})`:`(link: ${this.value.url})`},createMarkdown(){return this.value.text.length>0?`[${this.value.text}](${this.value.url})`:`<${this.value.url}>`},submit(){this.$emit("submit",this.kirbytext?this.createKirbytext():this.createMarkdown()),this.value={url:null,text:null},this.$refs.dialog.close()}}},(function(){var t=this,e=t._self._c;return e("k-dialog",{ref:"dialog",attrs:{"submit-button":t.$t("insert")},on:{close:t.cancel,submit:function(e){return t.$refs.form.submit()}}},[e("k-form",{ref:"form",attrs:{fields:t.fields},on:{submit:t.submit},model:{value:t.value,callback:function(e){t.value=e},expression:"value"}})],1)}),[],!1,null,null,null,null).exports;var ns=Mt({mixins:[Qt,ee,ie,oe,le],inheritAttrs:!1,props:{value:Boolean},watch:{value(){this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{focus(){this.$refs.input.focus()},onChange(t){this.$emit("input",t)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},select(){this.focus()}},validations(){return{value:{required:!this.required||P.required}}}},(function(){var t=this,e=t._self._c;return e("label",{staticClass:"k-checkbox-input",on:{click:function(t){t.stopPropagation()}}},[e("input",{ref:"input",staticClass:"k-checkbox-input-native input-hidden",attrs:{id:t.id,disabled:t.disabled,type:"checkbox"},domProps:{checked:t.value},on:{change:function(e){return t.onChange(e.target.checked)}}}),e("span",{staticClass:"k-checkbox-input-icon",attrs:{"aria-hidden":"true"}},[e("svg",{attrs:{width:"12",height:"10",viewBox:"0 0 12 10",xmlns:"http://www.w3.org/2000/svg"}},[e("path",{attrs:{d:"M1 5l3.3 3L11 1","stroke-width":"2",fill:"none","fill-rule":"evenodd"}})])]),e("span",{staticClass:"k-checkbox-input-label",domProps:{innerHTML:t._s(t.label)}})])}),[],!1,null,null,null,null).exports;const os={mixins:[Qt,ee,ie,le],props:{columns:Number,max:Number,min:Number,options:Array,value:{type:[Array,Object],default:()=>[]}}};var rs=Mt({mixins:[os],inheritAttrs:!1,data(){return{selected:this.valueToArray(this.value)}},watch:{value(t){this.selected=this.valueToArray(t)},selected(){this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{focus(){this.$el.querySelector("input").focus()},onInput(t,e){if(!0===e)this.selected.push(t);else{const e=this.selected.indexOf(t);-1!==e&&this.selected.splice(e,1)}this.$emit("input",this.selected)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},select(){this.focus()},valueToArray:t=>!0===Array.isArray(t)?t:"string"==typeof t?String(t).split(","):"object"==typeof t?Object.values(t):void 0},validations(){return{selected:{required:!this.required||P.required,min:!this.min||P.minLength(this.min),max:!this.max||P.maxLength(this.max)}}}},(function(){var t=this,e=t._self._c;return e("ul",{staticClass:"k-checkboxes-input",style:"--columns:"+t.columns},t._l(t.options,(function(s,i){return e("li",{key:i},[e("k-checkbox-input",{attrs:{id:t.id+"-"+i,label:s.text,value:-1!==t.selected.indexOf(s.value)},on:{input:function(e){return t.onInput(s.value,e)}}})],1)})),0)}),[],!1,null,null,null,null).exports;const ls={mixins:[Qt,ee,ie,le],props:{display:{type:String,default:"DD.MM.YYYY"},max:String,min:String,step:{type:Object,default:()=>({size:1,unit:"day"})},type:{type:String,default:"date"},value:String}};var as=Mt({mixins:[ls],inheritAttrs:!1,data:()=>({dt:null,formatted:null}),computed:{inputType:()=>"date",pattern(){return this.$library.dayjs.pattern(this.display)},rounding(){return{...this.$options.props.step.default(),...this.step}}},watch:{value:{handler(t,e){if(t!==e){const e=this.toDatetime(t);this.commit(e)}},immediate:!0}},created(){this.$events.$on("keydown.cmd.s",this.onBlur)},destroyed(){this.$events.$off("keydown.cmd.s",this.onBlur)},methods:{alter(t){let e=this.parse()||this.round(this.$library.dayjs()),s=this.rounding.unit,i=this.rounding.size;const n=this.selection();null!==n&&("meridiem"===n.unit?(t="pm"===e.format("a")?"subtract":"add",s="hour",i=12):(s=n.unit,s!==this.rounding.unit&&(i=1))),e=e[t](i,s).round(this.rounding.unit,this.rounding.size),this.commit(e),this.emit(e),this.$nextTick((()=>this.select(n)))},commit(t){this.dt=t,this.formatted=this.pattern.format(t),this.$emit("invalid",this.$v.$invalid,this.$v)},emit(t){this.$emit("input",this.toISO(t))},focus(){this.$refs.input.focus()},onArrowDown(){this.alter("subtract")},onArrowUp(){this.alter("add")},onBlur(){const t=this.parse();this.commit(t),this.emit(t)},onEnter(){this.onBlur(),this.$nextTick((()=>this.$emit("submit")))},onInput(t){const e=this.parse(),s=this.pattern.format(e);if(!t||s==t)return this.commit(e),this.emit(e)},onTab(t){""!=this.$refs.input.value&&(this.onBlur(),this.$nextTick((()=>{const e=this.selection();if(this.$refs.input&&e.start===this.$refs.input.selectionStart&&e.end===this.$refs.input.selectionEnd-1)if(t.shiftKey){if(0===e.index)return;this.selectPrev(e.index)}else{if(e.index===this.pattern.parts.length-1)return;this.selectNext(e.index)}else t.shiftKey?this.selectLast():this.selectFirst();t.preventDefault()})))},parse(){let t=this.$refs.input.value;return t=this.$library.dayjs.interpret(t,this.inputType),this.round(t)},round(t){return(null==t?void 0:t.round(this.rounding.unit,this.rounding.size))||null},select(t){var e;t||(t=this.selection()),null==(e=this.$refs.input)||e.setSelectionRange(t.start,t.end+1)},selectFirst(){this.select(this.pattern.parts[0])},selectLast(){this.select(this.pattern.parts[this.pattern.parts.length-1])},selectNext(t){this.select(this.pattern.parts[t+1])},selectPrev(t){this.select(this.pattern.parts[t-1])},selection(){return this.pattern.at(this.$refs.input.selectionStart,this.$refs.input.selectionEnd)},toDatetime(t){return this.round(this.$library.dayjs.iso(t,this.inputType))},toISO(t){return(null==t?void 0:t.toISO(this.inputType))||null}},validations(){return{value:{min:!this.dt||!this.min||(()=>this.dt.validate(this.min,"min",this.rounding.unit)),max:!this.dt||!this.max||(()=>this.dt.validate(this.max,"max",this.rounding.unit)),required:!this.required||(()=>!!this.dt)}}}},(function(){var t=this;return(0,t._self._c)("input",{directives:[{name:"model",rawName:"v-model",value:t.formatted,expression:"formatted"},{name:"direction",rawName:"v-direction"}],ref:"input",class:`k-text-input k-${t.type}-input`,attrs:{id:t.id,autofocus:t.autofocus,disabled:t.disabled,placeholder:t.display,required:t.required,autocomplete:"off",spellcheck:"false",type:"text"},domProps:{value:t.formatted},on:{blur:t.onBlur,focus:function(e){return t.$emit("focus")},input:[function(e){e.target.composing||(t.formatted=e.target.value)},function(e){return t.onInput(e.target.value)}],keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"down",40,e.key,["Down","ArrowDown"])?null:(e.stopPropagation(),e.preventDefault(),t.onArrowDown.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"up",38,e.key,["Up","ArrowUp"])?null:(e.stopPropagation(),e.preventDefault(),t.onArrowUp.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"enter",13,e.key,"Enter")?null:(e.stopPropagation(),e.preventDefault(),t.onEnter.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"tab",9,e.key,"Tab")?null:t.onTab.apply(null,arguments)}]}})}),[],!1,null,null,null,null).exports;const us={mixins:[Qt,ee,ie,re,le],props:{autocomplete:{type:[Boolean,String],default:"off"},maxlength:Number,minlength:Number,pattern:String,placeholder:String,preselect:Boolean,spellcheck:{type:[Boolean,String],default:"off"},type:{type:String,default:"text"},value:String}};var cs=Mt({mixins:[us],inheritAttrs:!1,data(){return{listeners:{...this.$listeners,input:t=>this.onInput(t.target.value)}}},watch:{value(){this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus(),this.$props.preselect&&this.select()},methods:{focus(){this.$refs.input.focus()},onInput(t){this.$emit("input",t)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},select(){this.$refs.input.select()}},validations(){return{value:{required:!this.required||P.required,minLength:!this.minlength||P.minLength(this.minlength),maxLength:!this.maxlength||P.maxLength(this.maxlength),email:"email"!==this.type||P.email,url:"url"!==this.type||P.url,pattern:!this.pattern||(t=>!this.required&&!t||!this.$refs.input.validity.patternMismatch)}}}},(function(){var t=this;return(0,t._self._c)("input",t._g(t._b({directives:[{name:"direction",rawName:"v-direction"}],ref:"input",staticClass:"k-text-input"},"input",{autocomplete:t.autocomplete,autofocus:t.autofocus,disabled:t.disabled,id:t.id,minlength:t.minlength,name:t.name,pattern:t.pattern,placeholder:t.placeholder,required:t.required,spellcheck:t.spellcheck,type:t.type,value:t.value},!1),t.listeners))}),[],!1,null,null,null,null).exports;const ds={mixins:[us],props:{autocomplete:{type:String,default:"email"},placeholder:{type:String,default:()=>window.panel.$t("email.placeholder")},type:{type:String,default:"email"}}};var ps=Mt({extends:cs,mixins:[ds]},null,null,!1,null,null,null,null).exports;class hs extends Ce{get schema(){return{content:"bulletList|orderedList"}}}var ms=Mt({inheritAttrs:!1,props:{autofocus:Boolean,marks:{type:[Array,Boolean],default:!0},value:String},data(){return{list:this.value,html:this.value}},computed:{extensions:()=>[new hs({inline:!0})]},watch:{value(t){t!==this.html&&(this.list=t,this.html=t)}},methods:{focus(){this.$refs.input.focus()},onInput(t){let e=(new DOMParser).parseFromString(t,"text/html").querySelector("ul, ol");e&&0!==e.textContent.trim().length?(this.list=t,this.html=t.replace(/(

|<\/p>)/gi,""),this.$emit("input",this.html)):this.$emit("input",this.list="")}}},(function(){var t=this;return(0,t._self._c)("k-writer",t._b({ref:"input",staticClass:"k-list-input",attrs:{extensions:t.extensions,nodes:["bulletList","orderedList"],value:t.list},on:{input:t.onInput}},"k-writer",t.$props,!1))}),[],!1,null,null,null,null).exports;const fs={mixins:[ee,ie,le],props:{max:Number,min:Number,layout:String,options:{type:Array,default:()=>[]},search:[Object,Boolean],separator:{type:String,default:","},sort:Boolean,value:{type:Array,required:!0,default:()=>[]}}};var gs=Mt({mixins:[fs],inheritAttrs:!1,data(){return{state:this.value,q:null,limit:!0,scrollTop:0}},computed:{draggable(){return this.state.length>1&&!this.sort},dragOptions(){return{disabled:!this.draggable,draggable:".k-tag",delay:1}},emptyLabel(){return this.q?this.$t("search.results.none"):this.$t("options.none")},filtered(){var t;return(null==(t=this.q)?void 0:t.length)>=(this.search.min||0)?this.options.filter((t=>this.isFiltered(t))).map((t=>({...t,display:this.toHighlightedString(t.text),info:this.toHighlightedString(t.value)}))):this.options.map((t=>({...t,display:t.text,info:t.value})))},more(){return!this.max||this.state.lengththis.options.findIndex((e=>e.value===t.value));return t.sort(((t,s)=>e(t)-e(s)))},visible(){return this.limit?this.filtered.slice(0,this.search.display||this.filtered.length):this.filtered}},watch:{value(t){this.state=t,this.onInvalid()}},mounted(){this.onInvalid(),this.$events.$on("click",this.close),this.$events.$on("keydown.cmd.s",this.close)},destroyed(){this.$events.$off("click",this.close),this.$events.$off("keydown.cmd.s",this.close)},methods:{add(t){!0===this.more&&(this.state.push(t),this.onInput())},blur(){this.close()},close(){!0===this.$refs.dropdown.isOpen&&(this.$refs.dropdown.close(),this.limit=!0)},escape(){this.q?this.q=null:this.close()},focus(){this.$refs.dropdown.open()},index(t){return this.state.findIndex((e=>e.value===t.value))},isFiltered(t){return String(t.text).match(this.regex)||String(t.value).match(this.regex)},isSelected(t){return-1!==this.index(t)},navigate(t){var e,s,i;"prev"===t&&(t="previous"),null==(i=null==(s=null==(e=document.activeElement)?void 0:e[t+"Sibling"])?void 0:s.focus)||i.call(s)},onClose(){!1===this.$refs.dropdown.isOpen&&(document.activeElement===this.$parent.$el&&(this.q=null),this.$parent.$el.focus())},onInput(){this.$emit("input",this.sorted)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},onOpen(){this.$nextTick((()=>{var t,e;null==(e=null==(t=this.$refs.search)?void 0:t.focus)||e.call(t),this.$refs.dropdown.$el.querySelector(".k-multiselect-options").scrollTop=this.scrollTop}))},remove(t){this.state.splice(this.index(t),1),this.onInput()},select(t){this.scrollTop=this.$refs.dropdown.$el.querySelector(".k-multiselect-options").scrollTop,t={text:t.text,value:t.value},this.isSelected(t)?this.remove(t):this.add(t)},toHighlightedString(t){return(t=this.$helper.string.stripHTML(t)).replace(this.regex,"$1")}},validations(){return{state:{required:!this.required||P.required,minLength:!this.min||P.minLength(this.min),maxLength:!this.max||P.maxLength(this.max)}}}},(function(){var t=this,e=t._self._c;return e("k-draggable",{staticClass:"k-multiselect-input",attrs:{list:t.state,options:t.dragOptions,"data-layout":t.layout,element:"k-dropdown"},on:{end:t.onInput},nativeOn:{click:function(e){return t.$refs.dropdown.toggle.apply(null,arguments)}},scopedSlots:t._u([{key:"footer",fn:function(){return[e("k-dropdown-content",{ref:"dropdown",on:{open:t.onOpen,close:t.onClose},nativeOn:{keydown:function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"esc",27,e.key,["Esc","Escape"])?null:(e.stopPropagation(),t.close.apply(null,arguments))}}},[t.search?e("k-dropdown-item",{staticClass:"k-multiselect-search",attrs:{icon:"search"}},[e("input",{directives:[{name:"model",rawName:"v-model",value:t.q,expression:"q"}],ref:"search",attrs:{placeholder:t.search.min?t.$t("search.min",{min:t.search.min}):t.$t("search")+" …"},domProps:{value:t.q},on:{keydown:function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"esc",27,e.key,["Esc","Escape"])?null:(e.stopPropagation(),t.escape.apply(null,arguments))},input:function(e){e.target.composing||(t.q=e.target.value)}}})]):t._e(),e("div",{staticClass:"k-multiselect-options scroll-y-auto"},[t._l(t.visible,(function(s){return e("k-dropdown-item",{key:s.value,class:{"k-multiselect-option":!0,selected:t.isSelected(s),disabled:!t.more},attrs:{icon:t.isSelected(s)?"check":"circle-outline"},on:{click:function(e){return e.preventDefault(),t.select(s)}},nativeOn:{keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"enter",13,e.key,"Enter")?null:(e.preventDefault(),e.stopPropagation(),t.select(s))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"space",32,e.key,[" ","Spacebar"])?null:(e.preventDefault(),e.stopPropagation(),t.select(s))}]}},[e("span",{domProps:{innerHTML:t._s(s.display)}}),e("span",{staticClass:"k-multiselect-value",domProps:{innerHTML:t._s(s.info)}})])})),0===t.filtered.length?e("k-dropdown-item",{staticClass:"k-multiselect-option",attrs:{disabled:!0}},[t._v(" "+t._s(t.emptyLabel)+" ")]):t._e()],2),t.visible.lengththis.onInput(t.target.value),blur:this.onBlur}}},watch:{value(t){this.number=t},number:{immediate:!0,handler(){this.onInvalid()}}},mounted(){this.$props.autofocus&&this.focus(),this.$props.preselect&&this.select()},methods:{decimals(){const t=Number(this.step||0);return Math.floor(t)===t?0:-1!==t.toString().indexOf("e")?parseInt(t.toFixed(16).split(".")[1].split("").reverse().join("")).toString().length:t.toString().split(".")[1].length||0},format(t){if(isNaN(t)||""===t)return"";const e=this.decimals();return t=e?parseFloat(t).toFixed(e):Number.isInteger(this.step)?parseInt(t):parseFloat(t)},clean(){this.number=this.format(this.number)},emit(t){t=parseFloat(t),isNaN(t)&&(t=""),t!==this.value&&this.$emit("input",t)},focus(){this.$refs.input.focus()},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},onInput(t){this.number=t,this.emit(t)},onBlur(){this.clean(),this.emit(this.number)},select(){this.$refs.input.select()}},validations(){return{value:{required:!this.required||P.required,min:!this.min||P.minValue(this.min),max:!this.max||P.maxValue(this.max)}}}},(function(){var t=this;return(0,t._self._c)("input",t._g(t._b({ref:"input",staticClass:"k-number-input",attrs:{step:t.stepNumber,type:"number"},domProps:{value:t.number},on:{keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"s",void 0,e.key,void 0)?null:e.ctrlKey?t.clean.apply(null,arguments):null},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"s",void 0,e.key,void 0)?null:e.metaKey?t.clean.apply(null,arguments):null}]}},"input",{autofocus:t.autofocus,disabled:t.disabled,id:t.id,max:t.max,min:t.min,name:t.name,placeholder:t.placeholder,required:t.required},!1),t.listeners))}),[],!1,null,null,null,null).exports;const vs={mixins:[us],props:{autocomplete:{type:String,default:"new-password"},type:{type:String,default:"password"}}};var ys=Mt({extends:cs,mixins:[vs]},null,null,!1,null,null,null,null).exports;const $s={mixins:[Qt,ee,ie,le],props:{columns:Number,options:Array,value:[String,Number,Boolean]}};var _s=Mt({mixins:[$s],inheritAttrs:!1,watch:{value(){this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{focus(){this.$el.querySelector("input").focus()},onInput(t){this.$emit("input",t)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},select(){this.focus()}},validations(){return{value:{required:!this.required||P.required}}}},(function(){var t=this,e=t._self._c;return e("ul",{staticClass:"k-radio-input",style:"--columns:"+t.columns},t._l(t.options,(function(s,i){return e("li",{key:i},[e("input",{staticClass:"k-radio-input-native",attrs:{id:t.id+"-"+i,name:t.id,type:"radio"},domProps:{value:s.value,checked:t.value===s.value},on:{change:function(e){return t.onInput(s.value)}}}),s.info?e("label",{attrs:{for:t.id+"-"+i}},[e("span",{staticClass:"k-radio-input-text",domProps:{innerHTML:t._s(s.text)}}),e("span",{staticClass:"k-radio-input-info",domProps:{innerHTML:t._s(s.info)}})]):e("label",{attrs:{for:t.id+"-"+i},domProps:{innerHTML:t._s(s.text)}}),s.icon?e("k-icon",{attrs:{type:s.icon}}):t._e()],1)})),0)}),[],!1,null,null,null,null).exports;const xs={mixins:[Qt,ee,ie,re,le],props:{default:[Number,String],max:{type:Number,default:100},min:{type:Number,default:0},step:{type:Number,default:1},tooltip:{type:[Boolean,Object],default:()=>({before:null,after:null})},value:[Number,String]}};var ws=Mt({mixins:[xs],inheritAttrs:!1,data(){return{listeners:{...this.$listeners,input:t=>this.onInput(t.target.value)}}},computed:{baseline(){return this.min<0?0:this.min},label(){return this.required||this.value||0===this.value?this.format(this.position):"–"},position(){return this.value||0===this.value?this.value:this.default||this.baseline}},watch:{position(){this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{focus(){this.$refs.input.focus()},format(t){const e=document.lang?document.lang.replace("_","-"):"en",s=this.step.toString().split("."),i=s.length>1?s[1].length:0;return new Intl.NumberFormat(e,{minimumFractionDigits:i}).format(t)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},onInput(t){this.$emit("input",t)}},validations(){return{position:{required:!this.required||P.required,min:!this.min||P.minValue(this.min),max:!this.max||P.maxValue(this.max)}}}},(function(){var t=this,e=t._self._c;return e("label",{staticClass:"k-range-input"},[e("input",t._g(t._b({ref:"input",staticClass:"k-range-input-native",style:`--min: ${t.min}; --max: ${t.max}; --value: ${t.position}`,attrs:{type:"range"},domProps:{value:t.position}},"input",{autofocus:t.autofocus,disabled:t.disabled,id:t.id,max:t.max,min:t.min,name:t.name,required:t.required,step:t.step},!1),t.listeners)),t.tooltip?e("span",{staticClass:"k-range-input-tooltip"},[t.tooltip.before?e("span",{staticClass:"k-range-input-tooltip-before"},[t._v(t._s(t.tooltip.before))]):t._e(),e("span",{staticClass:"k-range-input-tooltip-text"},[t._v(t._s(t.label))]),t.tooltip.after?e("span",{staticClass:"k-range-input-tooltip-after"},[t._v(t._s(t.tooltip.after))]):t._e()]):t._e()])}),[],!1,null,null,null,null).exports;const Ss={mixins:[Qt,ee,ie,re,le],props:{ariaLabel:String,default:String,empty:{type:[Boolean,String],default:!0},placeholder:String,options:{type:Array,default:()=>[]},value:{type:[String,Number,Boolean],default:""}}};var Cs=Mt({mixins:[Ss],inheritAttrs:!1,data(){return{selected:this.value,listeners:{...this.$listeners,click:t=>this.onClick(t),change:t=>this.onInput(t.target.value),input:()=>{}}}},computed:{emptyOption(){return this.placeholder||"—"},hasEmptyOption(){return!1!==this.empty&&!(this.required&&this.default)},label(){const t=this.text(this.selected);return""===this.selected||null===this.selected||null===t?this.emptyOption:t}},watch:{value(t){this.selected=t,this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{focus(){this.$refs.input.focus()},onClick(t){t.stopPropagation(),this.$emit("click",t)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},onInput(t){this.selected=t,this.$emit("input",this.selected)},select(){this.focus()},text(t){let e=null;return this.options.forEach((s=>{s.value==t&&(e=s.text)})),e}},validations(){return{selected:{required:!this.required||P.required}}}},(function(){var t=this,e=t._self._c;return e("span",{staticClass:"k-select-input",attrs:{"data-disabled":t.disabled,"data-empty":""===t.selected}},[e("select",t._g({ref:"input",staticClass:"k-select-input-native",attrs:{id:t.id,autofocus:t.autofocus,"aria-label":t.ariaLabel,disabled:t.disabled,name:t.name,required:t.required},domProps:{value:t.selected}},t.listeners),[t.hasEmptyOption?e("option",{attrs:{disabled:t.required,value:""}},[t._v(" "+t._s(t.emptyOption)+" ")]):t._e(),t._l(t.options,(function(s){return e("option",{key:s.value,attrs:{disabled:s.disabled},domProps:{value:s.value}},[t._v(" "+t._s(s.text)+" ")])}))],2),t._v(" "+t._s(t.label)+" ")])}),[],!1,null,null,null,null).exports;const Os={mixins:[us],props:{allow:{type:String,default:""},formData:{type:Object,default:()=>({})},sync:{type:String}}};var As=Mt({extends:cs,mixins:[Os],data(){return{slug:this.sluggify(this.value),slugs:this.$language?this.$language.rules:this.$system.slugs,syncValue:null}},watch:{formData:{handler(t){return!this.disabled&&(!(!this.sync||void 0===t[this.sync])&&(t[this.sync]!=this.syncValue&&(this.syncValue=t[this.sync],void this.onInput(this.sluggify(this.syncValue)))))},deep:!0,immediate:!0},value(t){(t=this.sluggify(t))!==this.slug&&(this.slug=t,this.$emit("input",this.slug))}},methods:{sluggify(t){return this.$helper.slug(t,[this.slugs,this.$system.ascii],this.allow)},onInput(t){this.slug=this.sluggify(t),this.$emit("input",this.slug)}}},(function(){var t=this;return(0,t._self._c)("input",t._g(t._b({directives:[{name:"direction",rawName:"v-direction"}],ref:"input",staticClass:"k-text-input",attrs:{autocomplete:"off",spellcheck:"false",type:"text"},domProps:{value:t.slug}},"input",{autofocus:t.autofocus,disabled:t.disabled,id:t.id,minlength:t.minlength,name:t.name,pattern:t.pattern,placeholder:t.placeholder,required:t.required},!1),t.listeners))}),[],!1,null,null,null,null).exports;const Ts={mixins:[Qt,ee,ie,re,le],props:{accept:{type:String,default:"all"},icon:{type:[String,Boolean],default:"tag"},layout:String,max:Number,min:Number,options:{type:Array,default:()=>[]},separator:{type:String,default:","},value:{type:Array,default:()=>[]}}};var Is=Mt({mixins:[Ts],inheritAttrs:!1,data(){return{tags:this.prepareTags(this.value),selected:null,newTag:null,tagOptions:this.options.map((t=>{var e;return(null==(e=this.icon)?void 0:e.length)>0&&(t.icon=this.icon),t}),this)}},computed:{dragOptions(){return{delay:1,disabled:!this.draggable,draggable:".k-tag"}},draggable(){return this.tags.length>1},skip(){return this.tags.map((t=>t.value))}},watch:{value(t){this.tags=this.prepareTags(t),this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{addString(t){if(t)if((t=t.trim()).includes(this.separator))t.split(this.separator).forEach((t=>{this.addString(t)}));else if(0!==t.length)if("options"===this.accept){const e=this.options.filter((e=>e.text===t))[0];if(!e)return;this.addTag(e)}else this.addTag({text:t,value:t})},addTag(t){this.addTagToIndex(t),this.$refs.autocomplete.close(),this.$refs.input.focus()},addTagToIndex(t){if("options"===this.accept){if(!this.options.filter((e=>e.value===t.value))[0])return}-1===this.index(t)&&(!this.max||this.tags.length=this.tags.length)return;break;case"first":e=0;break;case"last":e=this.tags.length-1;break;default:e=t}let i=this.tags[e];if(i){let t=this.$refs[i.value];if(null==t?void 0:t[0])return{ref:t[0],tag:i,index:e}}return!1},index(t){return this.tags.findIndex((e=>e.value===t.value))},onInput(){this.$emit("input",this.tags)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},leaveInput(t){0===t.target.selectionStart&&t.target.selectionStart===t.target.selectionEnd&&0!==this.tags.length&&(this.$refs.autocomplete.close(),this.navigate("last"),t.preventDefault())},navigate(t){var e=this.get(t);e?(e.ref.focus(),this.selectTag(e.tag)):"next"===t&&(this.$refs.input.focus(),this.selectTag(null))},prepareTags:t=>!1===Array.isArray(t)?[]:t.map((t=>"string"==typeof t?{text:t,value:t}:t)),remove(t){const e=this.get("prev"),s=this.get("next");this.tags.splice(this.index(t),1),this.onInput(),e?(this.selectTag(e.tag),e.ref.focus()):s?this.selectTag(s.tag):(this.selectTag(null),this.$refs.input.focus())},select(){this.focus()},selectTag(t){this.selected=t},tab(t){var e;(null==(e=this.newTag)?void 0:e.length)>0&&(t.preventDefault(),this.addString(this.newTag))},type(t){this.newTag=t,this.$refs.autocomplete.search(t)}},validations(){return{tags:{required:!this.required||P.required,minLength:!this.min||P.minLength(this.min),maxLength:!this.max||P.maxLength(this.max)}}}},(function(){var t=this,e=t._self._c;return e("k-draggable",{directives:[{name:"direction",rawName:"v-direction"}],ref:"box",staticClass:"k-tags-input",attrs:{list:t.tags,"data-layout":t.layout,options:t.dragOptions},on:{end:t.onInput},scopedSlots:t._u([{key:"footer",fn:function(){return[e("span",{staticClass:"k-tags-input-element"},[e("k-autocomplete",{ref:"autocomplete",attrs:{html:!0,options:t.options,skip:t.skip},on:{select:t.addTag,leave:function(e){return t.$refs.input.focus()}}},[e("input",{directives:[{name:"model",rawName:"v-model.trim",value:t.newTag,expression:"newTag",modifiers:{trim:!0}}],ref:"input",attrs:{id:t.id,autofocus:t.autofocus,disabled:t.disabled||t.max&&t.tags.length>=t.max,name:t.name,autocomplete:"off",type:"text"},domProps:{value:t.newTag},on:{input:[function(e){e.target.composing||(t.newTag=e.target.value.trim())},function(e){return t.type(e.target.value)}],blur:[t.blurInput,function(e){return t.$forceUpdate()}],keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"s",void 0,e.key,void 0)?null:e.metaKey?t.blurInput.apply(null,arguments):null},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"left",37,e.key,["Left","ArrowLeft"])||"button"in e&&0!==e.button||e.ctrlKey||e.shiftKey||e.altKey||e.metaKey?null:t.leaveInput.apply(null,arguments)},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"enter",13,e.key,"Enter")||e.ctrlKey||e.shiftKey||e.altKey||e.metaKey?null:t.enter.apply(null,arguments)},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"tab",9,e.key,"Tab")||e.ctrlKey||e.shiftKey||e.altKey||e.metaKey?null:t.tab.apply(null,arguments)},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"backspace",void 0,e.key,void 0)||e.ctrlKey||e.shiftKey||e.altKey||e.metaKey?null:t.leaveInput.apply(null,arguments)}]}})])],1)]},proxy:!0}])},t._l(t.tags,(function(s,i){return e("k-tag",{key:i,ref:s.value,refInFor:!0,attrs:{removable:!t.disabled,name:"tag"},on:{remove:function(e){return t.remove(s)}},nativeOn:{click:function(t){t.stopPropagation()},blur:function(e){return t.selectTag(null)},focus:function(e){return t.selectTag(s)},keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"left",37,e.key,["Left","ArrowLeft"])||"button"in e&&0!==e.button?null:t.navigate("prev")},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"right",39,e.key,["Right","ArrowRight"])||"button"in e&&2!==e.button?null:t.navigate("next")}],dblclick:function(e){return t.edit(s)}}},[e("span",{domProps:{innerHTML:t._s(s.text)}})])})),1)}),[],!1,null,null,null,null).exports;const Ms={mixins:[us],props:{autocomplete:{type:String,default:"tel"},type:{type:String,default:"tel"}}};var Ls=Mt({extends:cs,mixins:[Ms]},null,null,!1,null,null,null,null).exports;const Es={mixins:[Qt,ee,ie,re,le],props:{buttons:{type:[Boolean,Array],default:!0},endpoints:Object,font:String,maxlength:Number,minlength:Number,placeholder:String,preselect:Boolean,size:String,spellcheck:{type:[Boolean,String],default:"off"},theme:String,uploads:[Boolean,Object,Array],value:String}};var js=Mt({mixins:[Es],inheritAttrs:!1,data:()=>({over:!1}),watch:{value(){this.onInvalid(),this.$nextTick((()=>{this.resize()}))}},mounted(){this.$nextTick((()=>{this.$library.autosize(this.$refs.input)})),this.onInvalid(),this.$props.autofocus&&this.focus(),this.$props.preselect&&this.select()},methods:{cancel(){this.$refs.input.focus()},dialog(t){if(!this.$refs[t+"Dialog"])throw"Invalid toolbar dialog";this.$refs[t+"Dialog"].open(this.$refs.input,this.selection())},focus(){this.$refs.input.focus()},insert(t){const e=this.$refs.input,s=e.value;setTimeout((()=>{if(e.focus(),document.execCommand("insertText",!1,t),e.value===s){const s=e.value.slice(0,e.selectionStart)+t+e.value.slice(e.selectionEnd);e.value=s,this.$emit("input",s)}})),this.resize()},insertFile(t){(null==t?void 0:t.length)>0&&this.insert(t.map((t=>t.dragText)).join("\n\n"))},insertUpload(t,e){this.insert(e.map((t=>t.dragText)).join("\n\n")),this.$events.$emit("model.update")},onClick(){this.$refs.toolbar&&this.$refs.toolbar.close()},onCommand(t,e){"function"==typeof this[t]?"function"==typeof e?this[t](e(this.$refs.input,this.selection())):this[t](e):window.console.warn(t+" is not a valid command")},onDrop(t){if(this.uploads&&this.$helper.isUploadEvent(t))return this.$refs.fileUpload.drop(t.dataTransfer.files,{url:this.$urls.api+"/"+this.endpoints.field+"/upload",multiple:!1});const e=this.$store.state.drag;"text"===(null==e?void 0:e.type)&&(this.focus(),this.insert(e.data))},onFocus(t){this.$emit("focus",t)},onInput(t){this.$emit("input",t.target.value)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},onOut(){this.$refs.input.blur(),this.over=!1},onOver(t){if(this.uploads&&this.$helper.isUploadEvent(t))return t.dataTransfer.dropEffect="copy",this.focus(),void(this.over=!0);const e=this.$store.state.drag;"text"===(null==e?void 0:e.type)&&(t.dataTransfer.dropEffect="copy",this.focus(),this.over=!0)},onShortcut(t){!1!==this.buttons&&"Meta"!==t.key&&"Control"!==t.key&&this.$refs.toolbar&&this.$refs.toolbar.shortcut(t.key,t)},onSubmit(t){return this.$emit("submit",t)},prepend(t){this.insert(t+" "+this.selection())},resize(){this.$library.autosize.update(this.$refs.input)},select(){this.$refs.select()},selectFile(){this.$refs.fileDialog.open({endpoint:this.endpoints.field+"/files",multiple:!1})},selection(){const t=this.$refs.input,e=t.selectionStart,s=t.selectionEnd;return t.value.substring(e,s)},uploadFile(){this.$refs.fileUpload.open({url:this.$urls.api+"/"+this.endpoints.field+"/upload",multiple:!1})},wrap(t){this.insert(t+this.selection()+t)}},validations(){return{value:{required:!this.required||P.required,minLength:!this.minlength||P.minLength(this.minlength),maxLength:!this.maxlength||P.maxLength(this.maxlength)}}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-textarea-input",attrs:{"data-over":t.over,"data-size":t.size,"data-theme":t.theme}},[e("div",{staticClass:"k-textarea-input-wrapper"},[t.buttons&&!t.disabled?e("k-toolbar",{ref:"toolbar",attrs:{buttons:t.buttons,disabled:t.disabled,uploads:t.uploads},on:{command:t.onCommand},nativeOn:{mousedown:function(t){t.preventDefault()}}}):t._e(),e("textarea",t._b({directives:[{name:"direction",rawName:"v-direction"}],ref:"input",staticClass:"k-textarea-input-native",attrs:{"data-font":t.font},on:{click:t.onClick,focus:t.onFocus,input:t.onInput,keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"enter",13,e.key,"Enter")?null:e.metaKey?t.onSubmit.apply(null,arguments):null},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"enter",13,e.key,"Enter")?null:e.ctrlKey?t.onSubmit.apply(null,arguments):null},function(e){return e.metaKey?t.onShortcut.apply(null,arguments):null},function(e){return e.ctrlKey?t.onShortcut.apply(null,arguments):null}],dragover:t.onOver,dragleave:t.onOut,drop:t.onDrop}},"textarea",{autofocus:t.autofocus,disabled:t.disabled,id:t.id,minlength:t.minlength,name:t.name,placeholder:t.placeholder,required:t.required,spellcheck:t.spellcheck,value:t.value},!1))],1),e("k-toolbar-email-dialog",{ref:"emailDialog",on:{cancel:t.cancel,submit:function(e){return t.insert(e)}}}),e("k-toolbar-link-dialog",{ref:"linkDialog",on:{cancel:t.cancel,submit:function(e){return t.insert(e)}}}),e("k-files-dialog",{ref:"fileDialog",on:{cancel:t.cancel,submit:function(e){return t.insertFile(e)}}}),t.uploads?e("k-upload",{ref:"fileUpload",on:{success:t.insertUpload}}):t._e()],1)}),[],!1,null,null,null,null).exports;const Bs={props:{display:{type:String,default:"HH:mm"},max:String,min:String,step:{type:Object,default:()=>({size:5,unit:"minute"})},type:{type:String,default:"time"},value:String}};var Ds=Mt({mixins:[as,Bs],computed:{inputType:()=>"time"}},null,null,!1,null,null,null,null).exports;const Ps={props:{autofocus:Boolean,disabled:Boolean,id:[Number,String],text:{type:[Array,String]},required:Boolean,value:Boolean}};var Ns=Mt({mixins:[Ps],inheritAttrs:!1,computed:{label(){const t=this.text||[this.$t("off"),this.$t("on")];return Array.isArray(t)?this.value?t[1]:t[0]:t}},watch:{value(){this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{focus(){this.$refs.input.focus()},onEnter(t){"Enter"===t.key&&this.$refs.input.click()},onInput(t){this.$emit("input",t)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},select(){this.$refs.input.focus()}},validations(){return{value:{required:!this.required||P.required}}}},(function(){var t=this,e=t._self._c;return e("label",{staticClass:"k-toggle-input",attrs:{"data-disabled":t.disabled}},[e("input",{ref:"input",staticClass:"k-toggle-input-native",attrs:{id:t.id,disabled:t.disabled,type:"checkbox"},domProps:{checked:t.value},on:{change:function(e){return t.onInput(e.target.checked)}}}),e("span",{staticClass:"k-toggle-input-label",domProps:{innerHTML:t._s(t.label)}})])}),[],!1,null,null,null,null).exports;const qs={mixins:[Qt,ee,ie,le],props:{columns:Number,grow:Boolean,labels:Boolean,options:Array,reset:Boolean,value:[String,Number,Boolean]}};var Fs=Mt({inheritAttrs:!1,mixins:[qs],watch:{value(){this.onInvalid()}},mounted(){this.onInvalid(),this.$props.autofocus&&this.focus()},methods:{focus(){(this.$el.querySelector("input[checked]")||this.$el.querySelector("input")).focus()},onClick(t){t===this.value&&this.reset&&!this.required&&this.$emit("input","")},onInput(t){this.$emit("input",t)},onInvalid(){this.$emit("invalid",this.$v.$invalid,this.$v)},select(){this.focus()}},validations(){return{value:{required:!this.required||P.required}}}},(function(){var t=this,e=t._self._c;return e("ul",{staticClass:"k-toggles-input",style:"--options:"+(t.columns||t.options.length),attrs:{"data-invalid":t.$v.$invalid,"data-labels":t.labels}},t._l(t.options,(function(s,i){return e("li",{key:i},[e("input",{staticClass:"input-hidden",attrs:{id:t.id+"-"+i,name:t.id,type:"radio"},domProps:{value:s.value,checked:t.value===s.value},on:{click:function(e){return t.onClick(s.value)},change:function(e){return t.onInput(s.value)}}}),e("label",{attrs:{for:t.id+"-"+i,title:s.text}},[s.icon?e("k-icon",{attrs:{type:s.icon}}):t._e(),t.labels?e("span",{staticClass:"k-toggles-text"},[t._v(" "+t._s(s.text)+" ")]):t._e()],1)])})),0)}),[],!1,null,null,null,null).exports;const Rs={mixins:[us],props:{autocomplete:{type:String,default:"url"},type:{type:String,default:"url"}}};var zs=Mt({extends:cs,mixins:[Rs]},null,null,!1,null,null,null,null).exports;t.component("k-checkbox-input",ns),t.component("k-checkboxes-input",rs),t.component("k-date-input",as),t.component("k-email-input",ps),t.component("k-list-input",ms),t.component("k-multiselect-input",gs),t.component("k-number-input",bs),t.component("k-password-input",ys),t.component("k-radio-input",_s),t.component("k-range-input",ws),t.component("k-select-input",Cs),t.component("k-slug-input",As),t.component("k-tags-input",Is),t.component("k-tel-input",Ls),t.component("k-text-input",cs),t.component("k-textarea-input",js),t.component("k-time-input",Ds),t.component("k-toggle-input",Ns),t.component("k-toggles-input",Fs),t.component("k-url-input",zs);var Ys=Mt({mixins:[ae],inheritAttrs:!1,props:{autofocus:Boolean,empty:String,fieldsets:Object,fieldsetGroups:Object,group:String,max:{type:Number,default:null},value:{type:Array,default:()=>[]}},data:()=>({opened:[]}),computed:{hasFieldsets(){return Object.keys(this.fieldsets).length},isEmpty(){return 0===this.value.length},isFull(){return null!==this.max&&this.value.length>=this.max}},methods:{focus(){this.$refs.blocks.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-blocks-field",scopedSlots:t._u([{key:"options",fn:function(){return[t.hasFieldsets?e("k-dropdown",[e("k-button",{attrs:{icon:"dots"},on:{click:function(e){return t.$refs.options.toggle()}}}),e("k-dropdown-content",{ref:"options",attrs:{align:"right"}},[e("k-dropdown-item",{attrs:{disabled:t.isFull,icon:"add"},on:{click:function(e){return t.$refs.blocks.choose(t.value.length)}}},[t._v(" "+t._s(t.$t("add"))+" ")]),e("hr"),e("k-dropdown-item",{attrs:{disabled:t.isEmpty,icon:"template"},on:{click:function(e){return t.$refs.blocks.copyAll()}}},[t._v(" "+t._s(t.$t("copy.all"))+" ")]),e("k-dropdown-item",{attrs:{disabled:t.isFull,icon:"download"},on:{click:function(e){return t.$refs.blocks.pasteboard()}}},[t._v(" "+t._s(t.$t("paste"))+" ")]),e("hr"),e("k-dropdown-item",{attrs:{disabled:t.isEmpty,icon:"trash"},on:{click:function(e){return t.$refs.blocks.confirmToRemoveAll()}}},[t._v(" "+t._s(t.$t("delete.all"))+" ")])],1)],1):t._e()]},proxy:!0}])},"k-field",t.$props,!1),[e("k-blocks",t._g({ref:"blocks",attrs:{autofocus:t.autofocus,compact:!1,empty:t.empty,endpoints:t.endpoints,fieldsets:t.fieldsets,"fieldset-groups":t.fieldsetGroups,group:t.group,max:t.max,value:t.value},on:{close:function(e){t.opened=e},open:function(e){t.opened=e}}},t.$listeners))],1)}),[],!1,null,null,null,null).exports,Hs={props:{counter:{type:Boolean,default:!0}},computed:{counterOptions(){var t,e;if(null===this.value||this.disabled||!1===this.counter)return!1;let s=0;return this.value&&(s=Array.isArray(this.value)?this.value.length:String(this.value).length),{count:s,min:null!=(t=this.min)?t:this.minlength,max:null!=(e=this.max)?e:this.maxlength}}}};var Us=Mt({mixins:[ae,de,os,Hs],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-checkboxes-field",attrs:{counter:t.counterOptions}},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"checkboxes"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports;var Ks=Mt({mixins:[ae,de,ls],inheritAttrs:!1,props:{calendar:{type:Boolean,default:!0},icon:{type:String,default:"calendar"},time:{type:[Boolean,Object],default:()=>({})},times:{type:Boolean,default:!0}},data(){return{isInvalid:!1,iso:this.toIso(this.value)}},computed:{isEmpty(){return this.time?null===this.iso.date&&this.iso.time:null===this.iso.date}},watch:{value(t,e){t!==e&&(this.iso=this.toIso(t))}},methods:{focus(){this.$refs.dateInput.focus()},now(){const t=this.$library.dayjs();return{date:t.toISO("date"),time:this.time?t.toISO("time"):"00:00:00"}},onInput(){if(this.isEmpty)return this.$emit("input","");const t=this.$library.dayjs.iso(this.iso.date+" "+this.iso.time);(t||null!==this.iso.date&&null!==this.iso.time)&&this.$emit("input",(null==t?void 0:t.toISO())||"")},onCalendarInput(t){var e;null==(e=this.$refs.calendar)||e.close(),this.onDateInput(t)},onDateInput(t){t&&!this.iso.time&&(this.iso.time=this.now().time),this.iso.date=t,this.onInput()},onDateInvalid(t){this.isInvalid=t},onTimeInput(t){t&&!this.iso.date&&(this.iso.date=this.now().date),this.iso.time=t,this.onInput()},onTimesInput(t){var e;null==(e=this.$refs.times)||e.close(),this.onTimeInput(t+":00")},toIso(t){const e=this.$library.dayjs.iso(t);return{date:(null==e?void 0:e.toISO("date"))||null,time:(null==e?void 0:e.toISO("time"))||null}}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-date-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[e("div",{ref:"body",staticClass:"k-date-field-body",attrs:{"data-invalid":!t.novalidate&&t.isInvalid,"data-theme":"field"}},[e("k-input",t._b({ref:"dateInput",attrs:{id:t._uid,autofocus:t.autofocus,disabled:t.disabled,display:t.display,max:t.max,min:t.min,required:t.required,value:t.value,theme:"field",type:"date"},on:{invalid:t.onDateInvalid,input:t.onDateInput,submit:function(e){return t.$emit("submit")}},scopedSlots:t._u([t.calendar?{key:"icon",fn:function(){return[e("k-dropdown",[e("k-button",{staticClass:"k-input-icon-button",attrs:{icon:t.icon,tooltip:t.$t("date.select")},on:{click:function(e){return t.$refs.calendar.toggle()}}}),e("k-dropdown-content",{ref:"calendar",attrs:{align:"right"}},[e("k-calendar",{attrs:{value:t.value,min:t.min,max:t.max},on:{input:t.onCalendarInput}})],1)],1)]},proxy:!0}:null],null,!0)},"k-input",t.$props,!1)),t.time?e("k-input",{ref:"timeInput",attrs:{disabled:t.disabled,display:t.time.display,required:t.required,step:t.time.step,value:t.iso.time,icon:t.time.icon,theme:"field",type:"time"},on:{input:t.onTimeInput,submit:function(e){return t.$emit("submit")}},scopedSlots:t._u([t.times?{key:"icon",fn:function(){return[e("k-dropdown",[e("k-button",{staticClass:"k-input-icon-button",attrs:{icon:t.time.icon||"clock",tooltip:t.$t("time.select")},on:{click:function(e){return t.$refs.times.toggle()}}}),e("k-dropdown-content",{ref:"times",attrs:{align:"right"}},[e("k-times",{attrs:{display:t.time.display,value:t.value},on:{input:t.onTimesInput}})],1)],1)]},proxy:!0}:null],null,!0)}):t._e()],1)])}),[],!1,null,null,null,null).exports;var Js=Mt({mixins:[ae,de,ds],inheritAttrs:!1,props:{link:{type:Boolean,default:!0},icon:{type:String,default:"email"}},computed:{mailto(){var t;return(null==(t=this.value)?void 0:t.length)>0?"mailto:"+this.value:null}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-email-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"email"},scopedSlots:t._u([{key:"icon",fn:function(){return[t.link?e("k-button",{staticClass:"k-input-icon-button",attrs:{icon:t.icon,link:t.mailto,tooltip:t.$t("open"),tabindex:"-1",target:"_blank"}}):t._e()]},proxy:!0}])},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports,Gs={mixins:[ae],inheritAttrs:!1,props:{empty:String,info:String,link:Boolean,layout:{type:String,default:"list"},max:Number,multiple:Boolean,parent:String,search:Boolean,size:String,text:String,value:{type:Array,default:()=>[]}},data(){return{selected:this.value}},computed:{btnIcon(){return!this.multiple&&this.selected.length>0?"refresh":"add"},btnLabel(){return!this.multiple&&this.selected.length>0?this.$t("change"):this.$t("add")},collection(){return{empty:this.emptyProps,items:this.selected,layout:this.layout,link:this.link,size:this.size,sortable:!this.disabled&&this.selected.length>1}},isInvalid(){return!(!this.required||0!==this.selected.length)||(!!(this.min&&this.selected.lengththis.max))},items(){return this.models.map(this.item)},more(){return!this.max||this.max>this.selected.length}},watch:{value(t){this.selected=t}},methods:{focus(){},item:t=>t,onInput(){this.$emit("input",this.selected)},open(){if(this.disabled)return!1;this.$refs.selector.open({endpoint:this.endpoints.field,max:this.max,multiple:this.multiple,search:this.search,selected:this.selected.map((t=>t.id))})},remove(t){this.selected.splice(t,1),this.onInput()},removeById(t){this.selected=this.selected.filter((e=>e.id!==t)),this.onInput()},select(t){0!==t.length?(this.selected=this.selected.filter((e=>t.filter((t=>t.id===e.id)).length>0)),t.forEach((t=>{0===this.selected.filter((e=>t.id===e.id)).length&&this.selected.push(t)})),this.onInput()):this.selected=[]}}};var Vs=Mt({mixins:[Gs],props:{uploads:[Boolean,Object,Array]},computed:{emptyProps(){return{icon:"image",text:this.empty||this.$t("field.files.empty")}},moreUpload(){return!this.disabled&&this.more&&this.uploads},options(){return this.uploads?{icon:this.btnIcon,text:this.btnLabel,options:[{icon:"check",text:this.$t("select"),click:"open"},{icon:"upload",text:this.$t("upload"),click:"upload"}]}:{options:[{icon:"check",text:this.$t("select"),click:()=>this.open()}]}},uploadParams(){return{accept:this.uploads.accept,max:this.max,multiple:this.multiple,url:this.$urls.api+"/"+this.endpoints.field+"/upload"}}},created(){this.$events.$on("file.delete",this.removeById)},destroyed(){this.$events.$off("file.delete",this.removeById)},methods:{drop(t){return!1!==this.uploads&&this.$refs.fileUpload.drop(t,this.uploadParams)},prompt(){if(this.disabled)return!1;this.moreUpload?this.$refs.options.toggle():this.open()},onAction(t){if(this.moreUpload)switch(t){case"open":return this.open();case"upload":return this.$refs.fileUpload.open(this.uploadParams)}},isSelected(t){return this.selected.find((e=>e.id===t.id))},upload(t,e){!1===this.multiple&&(this.selected=[]),e.forEach((t=>{this.isSelected(t)||this.selected.push(t)})),this.onInput(),this.$events.$emit("model.update")}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-files-field",scopedSlots:t._u([t.more&&!t.disabled?{key:"options",fn:function(){return[e("k-button-group",{staticClass:"k-field-options"},[e("k-options-dropdown",t._b({ref:"options",on:{action:t.onAction}},"k-options-dropdown",t.options,!1))],1)]},proxy:!0}:null],null,!0)},"k-field",t.$props,!1),[e("k-dropzone",{attrs:{disabled:!t.moreUpload},on:{drop:t.drop}},[e("k-collection",t._b({on:{empty:t.prompt,sort:t.onInput,sortChange:function(e){return t.$emit("change",e)}},scopedSlots:t._u([{key:"options",fn:function({index:s}){return[t.disabled?t._e():e("k-button",{attrs:{tooltip:t.$t("remove"),icon:"remove"},on:{click:function(e){return t.remove(s)}}})]}}])},"k-collection",t.collection,!1))],1),e("k-files-dialog",{ref:"selector",on:{submit:t.select}}),e("k-upload",{ref:"fileUpload",on:{success:t.upload}})],1)}),[],!1,null,null,null,null).exports;var Ws=Mt({},(function(){return(0,this._self._c)("div",{staticClass:"k-field k-gap-field"})}),[],!1,null,null,null,null).exports;var Xs=Mt({mixins:[se,oe],props:{numbered:Boolean}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-headline-field"},[e("k-headline",{attrs:{"data-numbered":t.numbered,size:"large"}},[t._v(" "+t._s(t.label)+" ")]),t.help?e("footer",{staticClass:"k-field-footer"},[t.help?e("k-text",{staticClass:"k-field-help",attrs:{theme:"help"},domProps:{innerHTML:t._s(t.help)}}):t._e()],1):t._e()],1)}),[],!1,null,null,null,null).exports;var Zs=Mt({mixins:[se,oe],props:{text:String,theme:{type:String,default:"info"}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-field k-info-field"},[e("k-headline",[t._v(t._s(t.label))]),e("k-box",{attrs:{theme:t.theme}},[e("k-text",{domProps:{innerHTML:t._s(t.text)}})],1),t.help?e("footer",{staticClass:"k-field-footer"},[t.help?e("k-text",{staticClass:"k-field-help",attrs:{theme:"help"},domProps:{innerHTML:t._s(t.help)}}):t._e()],1):t._e()],1)}),[],!1,null,null,null,null).exports;var Qs=Mt({components:{"k-block-layouts":Mt({components:{"k-layout":Mt({components:{"k-layout-column":Mt({props:{blocks:Array,endpoints:Object,fieldsetGroups:Object,fieldsets:Object,id:String,isSelected:Boolean,width:String}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-column k-layout-column",attrs:{id:t.id,"data-width":t.width,tabindex:"0"},on:{dblclick:function(e){return t.$refs.blocks.choose(t.blocks.length)}}},[e("k-blocks",{ref:"blocks",attrs:{endpoints:t.endpoints,"fieldset-groups":t.fieldsetGroups,fieldsets:t.fieldsets,value:t.blocks,group:"layout"},on:{input:function(e){return t.$emit("input",e)}},nativeOn:{dblclick:function(t){t.stopPropagation()}}})],1)}),[],!1,null,null,null,null).exports},props:{attrs:[Array,Object],columns:Array,disabled:Boolean,endpoints:Object,fieldsetGroups:Object,fieldsets:Object,id:String,isSelected:Boolean,settings:Object},computed:{tabs(){let t=this.settings.tabs;return Object.entries(t).forEach((([e,s])=>{Object.entries(s.fields).forEach((([s])=>{t[e].fields[s].endpoints={field:this.endpoints.field+"/fields/"+s,section:this.endpoints.section,model:this.endpoints.model}}))})),t}}},(function(){var t=this,e=t._self._c;return e("section",{staticClass:"k-layout",attrs:{"data-selected":t.isSelected,tabindex:"0"},on:{click:function(e){return t.$emit("select")}}},[e("k-grid",{staticClass:"k-layout-columns"},t._l(t.columns,(function(s,i){return e("k-layout-column",t._b({key:s.id,attrs:{endpoints:t.endpoints,"fieldset-groups":t.fieldsetGroups,fieldsets:t.fieldsets},on:{input:function(e){return t.$emit("updateColumn",{column:s,columnIndex:i,blocks:e})}}},"k-layout-column",s,!1))})),1),t.disabled?t._e():e("nav",{staticClass:"k-layout-toolbar"},[t.settings?e("k-button",{staticClass:"k-layout-toolbar-button",attrs:{tooltip:t.$t("settings"),icon:"settings"},on:{click:function(e){return t.$refs.drawer.open()}}}):t._e(),e("k-dropdown",[e("k-button",{staticClass:"k-layout-toolbar-button",attrs:{icon:"angle-down"},on:{click:function(e){return t.$refs.options.toggle()}}}),e("k-dropdown-content",{ref:"options",attrs:{align:"right"}},[e("k-dropdown-item",{attrs:{icon:"angle-up"},on:{click:function(e){return t.$emit("prepend")}}},[t._v(" "+t._s(t.$t("insert.before"))+" ")]),e("k-dropdown-item",{attrs:{icon:"angle-down"},on:{click:function(e){return t.$emit("append")}}},[t._v(" "+t._s(t.$t("insert.after"))+" ")]),e("hr"),t.settings?e("k-dropdown-item",{attrs:{icon:"settings"},on:{click:function(e){return t.$refs.drawer.open()}}},[t._v(" "+t._s(t.$t("settings"))+" ")]):t._e(),e("k-dropdown-item",{attrs:{icon:"copy"},on:{click:function(e){return t.$emit("duplicate")}}},[t._v(" "+t._s(t.$t("duplicate"))+" ")]),e("hr"),e("k-dropdown-item",{attrs:{icon:"trash"},on:{click:function(e){return t.$refs.confirmRemoveDialog.open()}}},[t._v(" "+t._s(t.$t("field.layout.delete"))+" ")])],1)],1),e("k-sort-handle")],1),t.settings?e("k-form-drawer",{ref:"drawer",staticClass:"k-layout-drawer",attrs:{tabs:t.tabs,title:t.$t("settings"),value:t.attrs,icon:"settings"},on:{input:function(e){return t.$emit("updateAttrs",e)}}}):t._e(),e("k-remove-dialog",{ref:"confirmRemoveDialog",attrs:{text:t.$t("field.layout.delete.confirm")},on:{submit:function(e){return t.$emit("remove")}}})],1)}),[],!1,null,null,null,null).exports},props:{disabled:Boolean,empty:String,endpoints:Object,fieldsetGroups:Object,fieldsets:Object,layouts:Array,max:Number,settings:Object,value:Array},data(){return{currentLayout:null,nextIndex:null,rows:this.value,selected:null}},computed:{draggableOptions(){return{id:this._uid,handle:!0,list:this.rows}}},watch:{value(){this.rows=this.value}},methods:{async addLayout(t){let e=await this.$api.post(this.endpoints.field+"/layout",{columns:t});this.rows.splice(this.nextIndex,0,e),this.layouts.length>1&&this.$refs.selector.close(),this.save()},duplicateLayout(t,e){let s={...this.$helper.clone(e),id:this.$helper.uuid()};s.columns=s.columns.map((t=>(t.id=this.$helper.uuid(),t.blocks=t.blocks.map((t=>(t.id=this.$helper.uuid(),t))),t))),this.rows.splice(t+1,0,s),this.save()},removeLayout(t){const e=this.rows.findIndex((e=>e.id===t.id));-1!==e&&this.$delete(this.rows,e),this.save()},save(){this.$emit("input",this.rows)},selectLayout(t){this.nextIndex=t,1!==this.layouts.length?this.$refs.selector.open():this.addLayout(this.layouts[0])},updateColumn(t){this.rows[t.layoutIndex].columns[t.columnIndex].blocks=t.blocks,this.save()},updateAttrs(t,e){this.rows[t].attrs=e,this.save()}}},(function(){var t=this,e=t._self._c;return e("div",[t.rows.length?[e("k-draggable",t._b({staticClass:"k-layouts",on:{sort:t.save}},"k-draggable",t.draggableOptions,!1),t._l(t.rows,(function(s,i){return e("k-layout",t._b({key:s.id,attrs:{disabled:t.disabled,endpoints:t.endpoints,"fieldset-groups":t.fieldsetGroups,fieldsets:t.fieldsets,"is-selected":t.selected===s.id,settings:t.settings},on:{append:function(e){return t.selectLayout(i+1)},duplicate:function(e){return t.duplicateLayout(i,s)},prepend:function(e){return t.selectLayout(i)},remove:function(e){return t.removeLayout(s)},select:function(e){t.selected=s.id},updateAttrs:function(e){return t.updateAttrs(i,e)},updateColumn:function(e){return t.updateColumn({layout:s,layoutIndex:i,...e})}}},"k-layout",s,!1))})),1),t.disabled?t._e():e("k-button",{staticClass:"k-layout-add-button",attrs:{icon:"add"},on:{click:function(e){return t.selectLayout(t.rows.length)}}})]:[e("k-empty",{staticClass:"k-layout-empty",attrs:{icon:"dashboard"},on:{click:function(e){return t.selectLayout(0)}}},[t._v(" "+t._s(t.empty||t.$t("field.layout.empty"))+" ")])],e("k-dialog",{ref:"selector",staticClass:"k-layout-selector",attrs:{"cancel-button":!1,"submit-button":!1,size:"medium"}},[e("k-headline",[t._v(t._s(t.$t("field.layout.select")))]),e("ul",t._l(t.layouts,(function(s,i){return e("li",{key:i,staticClass:"k-layout-selector-option"},[e("k-grid",{nativeOn:{click:function(e){return t.addLayout(s)}}},t._l(s,(function(t,s){return e("k-column",{key:s,attrs:{width:t}})})),1)],1)})),0)],1)],2)}),[],!1,null,null,null,null).exports},mixins:[ae],inheritAttrs:!1,props:{empty:String,fieldsetGroups:Object,fieldsets:Object,layouts:{type:Array,default:()=>[["1/1"]]},settings:Object,value:{type:Array,default:()=>[]}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-layout-field"},"k-field",t.$props,!1),[e("k-block-layouts",t._b({on:{input:function(e){return t.$emit("input",e)}}},"k-block-layouts",t.$props,!1))],1)}),[],!1,null,null,null,null).exports;var ti=Mt({},(function(){return(0,this._self._c)("hr",{staticClass:"k-line-field"})}),[],!1,null,null,null,null).exports;var ei=Mt({mixins:[ae,de],inheritAttrs:!1,props:{marks:[Array,Boolean],value:String},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-list-field",attrs:{input:t._uid,counter:!1}},"k-field",t.$props,!1),[e("k-input",t._b({ref:"input",attrs:{id:t._uid,marks:t.marks,value:t.value,type:"list",theme:"field"},on:{input:function(e){return t.$emit("input",e)}}},"k-input",t.$props,!1))],1)}),[],!1,null,null,null,null).exports;var si=Mt({mixins:[ae,de,fs,Hs],inheritAttrs:!1,props:{icon:{type:String,default:"angle-down"}},mounted(){this.$refs.input.$el.setAttribute("tabindex",0)},methods:{blur(t){this.$refs.input.blur(t)},focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-multiselect-field",attrs:{input:t._uid,counter:t.counterOptions},on:{blur:t.blur},nativeOn:{keydown:function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"enter",13,e.key,"Enter")?null:(e.preventDefault(),t.focus.apply(null,arguments))}}},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"multiselect"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports;var ii=Mt({mixins:[ae,de,ks],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-number-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"number"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports;var ni=Mt({mixins:[Gs],computed:{emptyProps(){return{icon:"page",text:this.empty||this.$t("field.pages.empty")}}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-pages-field",scopedSlots:t._u([{key:"options",fn:function(){return[e("k-button-group",{staticClass:"k-field-options"},[t.more&&!t.disabled?e("k-button",{staticClass:"k-field-options-button",attrs:{icon:t.btnIcon,text:t.btnLabel},on:{click:t.open}}):t._e()],1)]},proxy:!0}])},"k-field",t.$props,!1),[e("k-collection",t._b({on:{empty:t.open,sort:t.onInput,sortChange:function(e){return t.$emit("change",e)}},scopedSlots:t._u([{key:"options",fn:function({index:s}){return[t.disabled?t._e():e("k-button",{attrs:{tooltip:t.$t("remove"),icon:"remove"},on:{click:function(e){return t.remove(s)}}})]}}])},"k-collection",t.collection,!1)),e("k-pages-dialog",{ref:"selector",on:{submit:t.select}})],1)}),[],!1,null,null,null,null).exports;var oi=Mt({mixins:[ae,de,vs,Hs],inheritAttrs:!1,props:{minlength:{type:Number,default:8},icon:{type:String,default:"key"}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-password-field",attrs:{input:t._uid,counter:t.counterOptions},scopedSlots:t._u([{key:"options",fn:function(){return[t._t("options")]},proxy:!0}],null,!0)},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"password"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports;var ri=Mt({mixins:[ae,de,$s],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-radio-field"},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"radio"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports;var li=Mt({mixins:[de,ae,xs],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-range-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"range"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports;var ai=Mt({mixins:[ae,de,Ss],inheritAttrs:!1,props:{icon:{type:String,default:"angle-down"}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-select-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"select"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports;var ui=Mt({mixins:[ae,de,Os],inheritAttrs:!1,props:{icon:{type:String,default:"url"},path:{type:String},wizard:{type:[Boolean,Object],default:!1}},data(){return{slug:this.value}},computed:{preview(){return void 0!==this.help?this.help:void 0!==this.path?this.path+this.value:null}},watch:{value(){this.slug=this.value}},methods:{focus(){this.$refs.input.focus()},onWizard(){var t;this.formData[null==(t=this.wizard)?void 0:t.field]&&(this.slug=this.formData[this.wizard.field])}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-slug-field",attrs:{input:t._uid,help:t.preview},scopedSlots:t._u([t.wizard&&t.wizard.text?{key:"options",fn:function(){return[e("k-button",{attrs:{text:t.wizard.text,icon:"wand"},on:{click:t.onWizard}})]},proxy:!0}:null],null,!0)},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,value:t.slug,theme:"field",type:"slug"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports;var ci=Mt({mixins:[ae],inheritAttrs:!1,props:{columns:Object,duplicate:{type:Boolean,default:!0},empty:String,fields:Object,limit:Number,max:Number,min:Number,prepend:{type:Boolean,default:!1},sortable:{type:Boolean,default:!0},sortBy:String,value:{type:Array,default:()=>[]}},data(){return{autofocus:null,items:this.toItems(this.value),currentIndex:null,currentModel:null,trash:null,page:1}},computed:{dragOptions(){return{disabled:!this.isSortable,fallbackClass:"k-sortable-row-fallback"}},form(){let t={};return Object.keys(this.fields).forEach((e=>{let s=this.fields[e];s.section=this.name,s.endpoints={field:this.endpoints.field+"+"+e,section:this.endpoints.section,model:this.endpoints.model},null===this.autofocus&&!0===s.autofocus&&(this.autofocus=e),t[e]=s})),t},index(){return this.limit?(this.page-1)*this.limit:1},more(){return!0!==this.disabled&&!(this.max&&this.items.length>=this.max)},isInvalid(){return!0!==this.disabled&&(!!(this.min&&this.items.lengththis.max))},isSortable(){return!this.sortBy&&(!this.limit&&(!0!==this.disabled&&(!(this.items.length<=1)&&!1!==this.sortable)))},pagination(){let t=0;return this.limit&&(t=(this.page-1)*this.limit),{page:this.page,offset:t,limit:this.limit,total:this.items.length,align:"center",details:!0}},options(){let t=[],e=this.duplicate&&this.more&&null===this.currentIndex;return e&&t.push({icon:"copy",text:this.$t("duplicate"),click:"duplicate"}),t.push({icon:"remove",text:e?this.$t("remove"):null,click:"remove"}),t},paginatedItems(){return this.limit?this.items.slice(this.pagination.offset,this.pagination.offset+this.limit):this.items}},watch:{value(t){t!=this.items&&(this.items=this.toItems(t))}},methods:{add(t){!0===this.prepend?this.items.unshift(t):this.items.push(t)},focus(){var t,e;null==(e=null==(t=this.$refs.add)?void 0:t.focus)||e.call(t)},jump(t,e){this.open(t+this.pagination.offset,e)},onAdd(){if(!0===this.disabled)return!1;if(null!==this.currentIndex)return this.onFormDiscard(),!1;let t={};for(const e in this.fields)t[e]=this.$helper.clone(this.fields[e].default);this.currentIndex="new",this.currentModel=t,this.onFormOpen()},onFormClose(){this.currentIndex=null,this.currentModel=null},onFormDiscard(){if("new"===this.currentIndex){if(0===Object.values(this.currentModel).filter((t=>!1===this.$helper.object.isEmpty(t))).length)return void this.onFormClose()}this.onFormSubmit()},onFormOpen(t=this.autofocus){this.$nextTick((()=>{var e;null==(e=this.$refs.form)||e.focus(t)}))},async onFormPaginate(t){await this.save(),this.open(t)},async onFormSubmit(){try{await this.save(),this.onFormClose()}catch(t){}},onInput(t=this.items){this.$emit("input",t)},onOption(t,e,s){switch(t){case"remove":this.onFormClose(),this.trash=s+this.pagination.offset,this.$refs.remove.open();break;case"duplicate":this.add(this.items[s+this.pagination.offset]),this.onInput()}},onRemove(){if(null===this.trash)return!1;this.items.splice(this.trash,1),this.trash=null,this.$refs.remove.close(),this.onInput(),0===this.paginatedItems.length&&this.page>1&&this.page--,this.items=this.sort(this.items)},open(t,e){this.currentIndex=t,this.currentModel=this.$helper.clone(this.items[t]),this.onFormOpen(e)},paginate({page:t}){this.page=t},sort(t){return this.sortBy?t.sortBy(this.sortBy):t},async save(){if(null!==this.currentIndex&&void 0!==this.currentIndex)try{return await this.validate(this.currentModel),"new"===this.currentIndex?this.add(this.currentModel):this.items[this.currentIndex]=this.currentModel,this.items=this.sort(this.items),this.onInput(),!0}catch(t){throw this.$store.dispatch("notification/error",{message:this.$t("error.form.incomplete"),details:t}),t}},toItems(t){return!1===Array.isArray(t)?[]:this.sort(t)},async validate(t){const e=await this.$api.post(this.endpoints.field+"/validate",t);if(e.length>0)throw e;return!0}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-structure-field",nativeOn:{click:function(t){t.stopPropagation()}},scopedSlots:t._u([{key:"options",fn:function(){return[t.more&&null===t.currentIndex?e("k-button",{ref:"add",attrs:{id:t._uid,text:t.$t("add"),icon:"add"},on:{click:t.onAdd}}):t._e()]},proxy:!0}])},"k-field",t.$props,!1),[null!==t.currentIndex?e("k-structure-form",{ref:"form",attrs:{fields:t.form,index:t.currentIndex,total:t.items.length},on:{close:t.onFormClose,discard:t.onFormDiscard,paginate:function(e){return t.onFormPaginate(e.offset)},submit:t.onFormSubmit},model:{value:t.currentModel,callback:function(e){t.currentModel=e},expression:"currentModel"}}):0===t.items.length?e("k-empty",{attrs:{"data-invalid":t.isInvalid,icon:"list-bullet"},on:{click:t.onAdd}},[t._v(" "+t._s(t.empty||t.$t("field.structure.empty"))+" ")]):[e("k-table",{attrs:{columns:t.columns,disabled:t.disabled,fields:t.fields,empty:t.$t("field.structure.empty"),index:t.index,options:t.options,rows:t.paginatedItems,sortable:t.isSortable,"data-invalid":t.isInvalid},on:{cell:function(e){return t.jump(e.rowIndex,e.columnIndex)},input:t.onInput,option:t.onOption}}),t.limit?e("k-pagination",t._b({on:{paginate:t.paginate}},"k-pagination",t.pagination,!1)):t._e(),t.disabled?t._e():e("k-dialog",{ref:"remove",attrs:{"submit-button":t.$t("delete"),theme:"negative"},on:{submit:t.onRemove}},[e("k-text",[t._v(t._s(t.$t("field.structure.delete.confirm")))])],1)]],2)}),[],!1,null,null,null,null).exports;var di=Mt({mixins:[ae,de,Ts,Hs],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-tags-field",attrs:{input:t._uid,counter:t.counterOptions}},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"tags"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports;var pi=Mt({mixins:[ae,de,Ms],inheritAttrs:!1,props:{icon:{type:String,default:"phone"}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-tel-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"tel"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports;var hi=Mt({mixins:[ae,de,us,Hs],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()},select(){this.$refs.input.select()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-text-field",attrs:{input:t._uid,counter:t.counterOptions},scopedSlots:t._u([{key:"options",fn:function(){return[t._t("options")]},proxy:!0}],null,!0)},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports;var mi=Mt({mixins:[ae,de,Es,Hs],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-textarea-field",attrs:{input:t._uid,counter:t.counterOptions}},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,type:"textarea",theme:"field"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports;var fi=Mt({mixins:[ae,de,Bs],inheritAttrs:!1,props:{icon:{type:String,default:"clock"},times:{type:Boolean,default:!0}},methods:{focus(){this.$refs.input.focus()},select(t){var e;this.$emit("input",t),null==(e=this.$refs.times)||e.close()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-time-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[e("k-input",t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"time"},on:{input:function(e){return t.$emit("input",e||"")}},scopedSlots:t._u([t.times?{key:"icon",fn:function(){return[e("k-dropdown",[e("k-button",{staticClass:"k-input-icon-button",attrs:{icon:t.icon||"clock",tooltip:t.$t("time.select")},on:{click:function(e){return t.$refs.times.toggle()}}}),e("k-dropdown-content",{ref:"times",attrs:{align:"right"}},[e("k-times",{attrs:{display:t.display,value:t.value},on:{input:t.select}})],1)],1)]},proxy:!0}:null],null,!0)},"k-input",t.$props,!1))],1)}),[],!1,null,null,null,null).exports;var gi=Mt({mixins:[ae,de,Ps],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-toggle-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"toggle"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports;var ki=Mt({inheritAttrs:!1,mixins:[ae,de,qs],methods:{focus(){this.$refs.input.focus()},onInput(t){this.$emit("input",t)}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-toggles-field"},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",class:{grow:t.grow},attrs:{id:t._uid,theme:"field",type:"toggles"}},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports;var bi=Mt({mixins:[ae,de,Rs],inheritAttrs:!1,props:{link:{type:Boolean,default:!0},icon:{type:String,default:"url"}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-url-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[e("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,theme:"field",type:"url"},scopedSlots:t._u([{key:"icon",fn:function(){return[t.link?e("k-button",{staticClass:"k-input-icon-button",attrs:{icon:t.icon,link:t.value,tooltip:t.$t("open"),tabindex:"-1",target:"_blank"}}):t._e()]},proxy:!0}])},"k-input",t.$props,!1),t.$listeners))],1)}),[],!1,null,null,null,null).exports;var vi=Mt({mixins:[Gs],computed:{emptyProps(){return{icon:"users",text:this.empty||this.$t("field.users.empty")}}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-users-field",scopedSlots:t._u([{key:"options",fn:function(){return[e("k-button-group",{staticClass:"k-field-options"},[t.more&&!t.disabled?e("k-button",{staticClass:"k-field-options-button",attrs:{icon:t.btnIcon,text:t.btnLabel},on:{click:t.open}}):t._e()],1)]},proxy:!0}])},"k-field",t.$props,!1),[e("k-collection",t._b({on:{empty:t.open,sort:t.onInput,sortChange:function(e){return t.$emit("change",e)}},scopedSlots:t._u([{key:"options",fn:function({index:s}){return[t.disabled?t._e():e("k-button",{attrs:{tooltip:t.$t("remove"),icon:"remove"},on:{click:function(e){return t.remove(s)}}})]}}])},"k-collection",t.collection,!1)),e("k-users-dialog",{ref:"selector",on:{submit:t.select}})],1)}),[],!1,null,null,null,null).exports;var yi=Mt({mixins:[ae,de,We],inheritAttrs:!1,methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("k-field",t._b({staticClass:"k-writer-field",attrs:{input:t._uid,counter:!1}},"k-field",t.$props,!1),[e("k-input",t._b({attrs:{after:t.after,before:t.before,icon:t.icon,theme:"field"}},"k-input",t.$props,!1),[e("k-writer",t._b({ref:"input",staticClass:"k-writer-field-input",attrs:{value:t.value},on:{input:function(e){return t.$emit("input",e)}}},"k-writer",t.$props,!1))],1)],1)}),[],!1,null,null,null,null).exports;t.component("k-blocks-field",Ys),t.component("k-checkboxes-field",Us),t.component("k-date-field",Ks),t.component("k-email-field",Js),t.component("k-files-field",Vs),t.component("k-gap-field",Ws),t.component("k-headline-field",Xs),t.component("k-info-field",Zs),t.component("k-layout-field",Qs),t.component("k-line-field",ti),t.component("k-list-field",ei),t.component("k-multiselect-field",si),t.component("k-number-field",ii),t.component("k-pages-field",ni),t.component("k-password-field",oi),t.component("k-radio-field",ri),t.component("k-range-field",li),t.component("k-select-field",ai),t.component("k-slug-field",ui),t.component("k-structure-field",ci),t.component("k-tags-field",di),t.component("k-text-field",hi),t.component("k-textarea-field",mi),t.component("k-tel-field",pi),t.component("k-time-field",fi),t.component("k-toggle-field",gi),t.component("k-toggles-field",ki),t.component("k-url-field",bi),t.component("k-users-field",vi),t.component("k-writer-field",yi);var $i=Mt({props:{cover:Boolean,ratio:String},computed:{ratioPadding(){return this.$helper.ratio(this.ratio)}}},(function(){var t=this;return(0,t._self._c)("span",{staticClass:"k-aspect-ratio",style:{"padding-bottom":t.ratioPadding},attrs:{"data-cover":t.cover}},[t._t("default")],2)}),[],!1,null,null,null,null).exports;var _i=Mt({},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-bar"},[t.$slots.left?e("div",{staticClass:"k-bar-slot",attrs:{"data-position":"left"}},[t._t("left")],2):t._e(),t.$slots.center?e("div",{staticClass:"k-bar-slot",attrs:{"data-position":"center"}},[t._t("center")],2):t._e(),t.$slots.right?e("div",{staticClass:"k-bar-slot",attrs:{"data-position":"right"}},[t._t("right")],2):t._e()])}),[],!1,null,null,null,null).exports;var xi=Mt({props:{theme:{type:String,default:"none"},text:String,html:{type:Boolean,default:!1}}},(function(){var t=this,e=t._self._c;return e("div",t._g({staticClass:"k-box",attrs:{"data-theme":t.theme}},t.$listeners),[t._t("default",(function(){return[t.html?e("k-text",{domProps:{innerHTML:t._s(t.text)}}):e("k-text",[t._v(" "+t._s(t.text)+" ")])]}))],2)}),[],!1,null,null,null,null).exports;var wi=Mt({inheritAttrs:!1,props:{back:String,color:String,element:{type:String,default:"li"},image:Object,link:String,text:String}},(function(){var t=this,e=t._self._c;return e(t.link?"k-link":"p",{tag:"component",staticClass:"k-bubble",style:{color:t.$helper.color(t.color),background:t.$helper.color(t.back)},attrs:{to:t.link},nativeOn:{click:function(t){t.stopPropagation()}}},[t.image?e("k-item-image",{attrs:{image:t.image,layout:"list"}}):t._e(),t._v(" "+t._s(t.text)+" ")],1)}),[],!1,null,null,null,null).exports;var Si=Mt({inheritAttrs:!1,props:{bubbles:Array},computed:{items(){let t=this.bubbles;return"string"==typeof t&&(t=t.split(",")),t.map((t=>"string"==typeof t?{text:t}:t))}}},(function(){var t=this,e=t._self._c;return e("ul",{staticClass:"k-bubbles"},t._l(t.items,(function(s,i){return e("li",{key:i},[e("k-bubble",t._b({},"k-bubble",s,!1))],1)})),0)}),[],!1,null,null,null,null).exports;var Ci=Mt({props:{columns:{type:[Object,Array],default:()=>({})},empty:Object,help:String,items:{type:[Array,Object],default:()=>[]},layout:{type:String,default:"list"},link:{type:Boolean,default:!0},size:String,sortable:Boolean,pagination:{type:[Boolean,Object],default:()=>!1}},computed:{hasPagination(){return!1!==this.pagination&&(!0!==this.paginationOptions.hide&&!(this.pagination.total<=this.pagination.limit))},hasFooter(){return!(!this.hasPagination&&!this.help)},paginationOptions(){return{limit:10,details:!0,keys:!1,total:0,hide:!1,..."object"!=typeof this.pagination?{}:this.pagination}}},watch:{$props(){this.$forceUpdate()}},methods:{onEmpty(t){t.stopPropagation(),this.$emit("empty")},onOption(...t){this.$emit("action",...t),this.$emit("option",...t)}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-collection"},[t.items.length?e("k-items",{attrs:{columns:t.columns,items:t.items,layout:t.layout,link:t.link,size:t.size,sortable:t.sortable},on:{change:function(e){return t.$emit("change",e)},item:function(e){return t.$emit("item",e)},option:t.onOption,sort:function(e){return t.$emit("sort",e)}},scopedSlots:t._u([{key:"options",fn:function({item:e,itemIndex:s}){return[t._t("options",null,null,{item:e,index:s})]}}],null,!0)}):e("k-empty",t._g(t._b({attrs:{layout:t.layout}},"k-empty",t.empty,!1),t.$listeners.empty?{click:t.onEmpty}:{})),t.hasFooter?e("footer",{staticClass:"k-collection-footer"},[t.help?e("k-text",{staticClass:"k-collection-help",attrs:{theme:"help"},domProps:{innerHTML:t._s(t.help)}}):t._e(),e("div",{staticClass:"k-collection-pagination"},[t.hasPagination?e("k-pagination",t._b({on:{paginate:function(e){return t.$emit("paginate",e)}}},"k-pagination",t.paginationOptions,!1)):t._e()],1)],1):t._e()],1)}),[],!1,null,null,null,null).exports;var Oi=Mt({props:{width:String,sticky:Boolean}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-column",attrs:{"data-width":t.width,"data-sticky":t.sticky}},[e("div",[t._t("default")],2)])}),[],!1,null,null,null,null).exports;var Ai=Mt({props:{disabled:{type:Boolean,default:!1}},data:()=>({files:[],dragging:!1,over:!1}),methods:{cancel(){this.reset()},reset(){this.dragging=!1,this.over=!1},onDrop(t){return!0===this.disabled||!1===this.$helper.isUploadEvent(t)?this.reset():(this.$events.$emit("dropzone.drop"),this.files=t.dataTransfer.files,this.$emit("drop",this.files),void this.reset())},onEnter(t){!1===this.disabled&&this.$helper.isUploadEvent(t)&&(this.dragging=!0)},onLeave(){this.reset()},onOver(t){!1===this.disabled&&this.$helper.isUploadEvent(t)&&(t.dataTransfer.dropEffect="copy",this.over=!0)}}},(function(){var t=this;return(0,t._self._c)("div",{staticClass:"k-dropzone",attrs:{"data-dragging":t.dragging,"data-over":t.over},on:{dragenter:t.onEnter,dragleave:t.onLeave,dragover:t.onOver,drop:t.onDrop}},[t._t("default")],2)}),[],!1,null,null,null,null).exports;var Ti=Mt({props:{text:String,icon:String,layout:{type:String,default:"list"}},computed:{element(){return void 0!==this.$listeners.click?"button":"div"}}},(function(){var t=this,e=t._self._c;return e(t.element,t._g({tag:"component",staticClass:"k-empty",attrs:{"data-layout":t.layout,type:"button"===t.element&&"button"}},t.$listeners),[t.icon?e("k-icon",{attrs:{type:t.icon}}):t._e(),e("p",[t._t("default",(function(){return[t._v(t._s(t.text))]}))],2)],1)}),[],!1,null,null,null,null).exports;var Ii=Mt({props:{details:Array,image:Object,url:String}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-file-preview"},[e("k-view",{staticClass:"k-file-preview-layout"},[e("div",{staticClass:"k-file-preview-image"},[e("k-link",{staticClass:"k-file-preview-image-link",attrs:{to:t.url,title:t.$t("open"),target:"_blank"}},[e("k-item-image",{attrs:{image:t.image,layout:"cards"}})],1)],1),e("div",{staticClass:"k-file-preview-details"},[e("ul",t._l(t.details,(function(s){return e("li",{key:s.title},[e("h3",[t._v(t._s(s.title))]),e("p",[s.link?e("k-link",{attrs:{to:s.link,tabindex:"-1",target:"_blank"}},[t._v(" /"+t._s(s.text)+" ")]):[t._v(" "+t._s(s.text)+" ")]],2)])})),0)])])],1)}),[],!1,null,null,null,null).exports;var Mi=Mt({props:{gutter:String}},(function(){var t=this;return(0,t._self._c)("div",{staticClass:"k-grid",attrs:{"data-gutter":t.gutter}},[t._t("default")],2)}),[],!1,null,null,null,null).exports;var Li=Mt({props:{editable:Boolean,tab:String,tabs:{type:Array,default:()=>[]}},computed:{tabsWithBadges(){const t=Object.keys(this.$store.getters["content/changes"]());return this.tabs.map((e=>{let s=[];return Object.values(e.columns).forEach((t=>{Object.values(t.sections).forEach((t=>{"fields"===t.type&&Object.keys(t.fields).forEach((t=>{s.push(t)}))}))})),e.badge=s.filter((e=>t.includes(e.toLowerCase()))).length,e}))}}},(function(){var t=this,e=t._self._c;return e("header",{staticClass:"k-header",attrs:{"data-editable":t.editable,"data-tabs":t.tabsWithBadges.length>1}},[e("k-headline",{attrs:{tag:"h1",size:"huge"}},[t.editable&&t.$listeners.edit?e("span",{staticClass:"k-headline-editable",on:{click:function(e){return t.$emit("edit")}}},[t._t("default"),e("k-icon",{attrs:{type:"edit"}})],2):t._t("default")],2),t.$slots.left||t.$slots.right?e("k-bar",{staticClass:"k-header-buttons",scopedSlots:t._u([{key:"left",fn:function(){return[t._t("left")]},proxy:!0},{key:"right",fn:function(){return[t._t("right")]},proxy:!0}],null,!0)}):t._e(),e("k-tabs",{attrs:{tab:t.tab,tabs:t.tabsWithBadges,theme:"notice"}})],1)}),[],!1,null,null,null,null).exports;var Ei=Mt({inheritAttrs:!1},(function(){var t=this,e=t._self._c;return e("k-panel",{staticClass:"k-panel-inside",attrs:{tabindex:"0"}},[e("header",{staticClass:"k-panel-header"},[e("k-topbar",{attrs:{breadcrumb:t.$view.breadcrumb,license:t.$license,menu:t.$menu,view:t.$view}})],1),e("main",{staticClass:"k-panel-view scroll-y"},[t._t("default")],2),t._t("footer")],2)}),[],!1,null,null,null,null).exports;var ji=Mt({inheritAttrs:!1,props:{data:Object,flag:Object,image:[Object,Boolean],info:String,layout:{type:String,default:"list"},link:{type:[Boolean,String,Function]},options:{type:[Array,Function,String]},sortable:Boolean,target:String,text:String,width:String},computed:{hasFigure(){return!1!==this.image&&Object.keys(this.image).length>0},title(){return this.text||"-"}},methods:{onOption(t){this.$emit("action",t),this.$emit("option",t)}}},(function(){var t=this,e=t._self._c;return e("article",t._b({staticClass:"k-item",class:!!t.layout&&"k-"+t.layout+"-item",attrs:{"data-has-figure":t.hasFigure,"data-has-flag":Boolean(t.flag),"data-has-info":Boolean(t.info),"data-has-options":Boolean(t.options),tabindex:"-1"},on:{click:function(e){return t.$emit("click",e)},dragstart:function(e){return t.$emit("drag",e)}}},"article",t.data,!1),[t._t("image",(function(){return[t.hasFigure?e("k-item-image",{attrs:{image:t.image,layout:t.layout,width:t.width}}):t._e()]})),t.sortable?e("k-sort-handle",{staticClass:"k-item-sort-handle"}):t._e(),e("header",{staticClass:"k-item-content"},[t._t("default",(function(){return[e("h3",{staticClass:"k-item-title"},[!1!==t.link?e("k-link",{staticClass:"k-item-title-link",attrs:{target:t.target,to:t.link}},[e("span",{domProps:{innerHTML:t._s(t.title)}})]):e("span",{domProps:{innerHTML:t._s(t.title)}})],1),t.info?e("p",{staticClass:"k-item-info",domProps:{innerHTML:t._s(t.info)}}):t._e()]}))],2),t.flag||t.options||t.$slots.options?e("footer",{staticClass:"k-item-footer"},[e("nav",{staticClass:"k-item-buttons",on:{click:function(t){t.stopPropagation()}}},[t.flag?e("k-status-icon",t._b({},"k-status-icon",t.flag,!1)):t._e(),t._t("options",(function(){return[t.options?e("k-options-dropdown",{staticClass:"k-item-options-dropdown",attrs:{options:t.options},on:{option:t.onOption}}):t._e()]}))],2)]):t._e()],2)}),[],!1,null,null,null,null).exports;var Bi=Mt({inheritAttrs:!1,props:{image:[Object,Boolean],layout:{type:String,default:"list"},width:String},computed:{back(){return this.image.back||"black"},ratio(){return"cards"===this.layout&&this.image.ratio||"1/1"},size(){switch(this.layout){case"cards":return"large";case"cardlets":return"medium";default:return"regular"}},sizes(){switch(this.width){case"1/2":case"2/4":return"(min-width: 30em) and (max-width: 65em) 59em, (min-width: 65em) 44em, 27em";case"1/3":return"(min-width: 30em) and (max-width: 65em) 59em, (min-width: 65em) 29.333em, 27em";case"1/4":return"(min-width: 30em) and (max-width: 65em) 59em, (min-width: 65em) 22em, 27em";case"2/3":return"(min-width: 30em) and (max-width: 65em) 59em, (min-width: 65em) 27em, 27em";case"3/4":return"(min-width: 30em) and (max-width: 65em) 59em, (min-width: 65em) 66em, 27em";default:return"(min-width: 30em) and (max-width: 65em) 59em, (min-width: 65em) 88em, 27em"}}}},(function(){var t=this,e=t._self._c;return t.image?e("div",{staticClass:"k-item-figure",style:{background:t.$helper.color(t.back)}},[t.image.src?e("k-image",{staticClass:"k-item-image",attrs:{cover:t.image.cover,ratio:t.ratio,sizes:t.sizes,src:t.image.src,srcset:t.image.srcset}}):e("k-aspect-ratio",{attrs:{ratio:t.ratio}},[e("k-icon",{staticClass:"k-item-icon",attrs:{color:t.$helper.color(t.image.color),type:t.image.icon}})],1)],1):t._e()}),[],!1,null,null,null,null).exports;var Di=Mt({inheritAttrs:!1,props:{columns:{type:[Object,Array],default:()=>({})},items:{type:Array,default:()=>[]},layout:{type:String,default:"list"},link:{type:Boolean,default:!0},image:{type:[Object,Boolean],default:()=>({})},sortable:Boolean,empty:{type:[String,Object]},size:{type:String,default:"default"}},computed:{dragOptions(){return{sort:this.sortable,disabled:!1===this.sortable,draggable:".k-draggable-item"}},table(){return{columns:this.columns,rows:this.items,sortable:this.sortable}}},methods:{onDragStart(t,e){this.$store.dispatch("drag",{type:"text",data:e})},onOption(t,e,s){this.$emit("option",t,e,s)},imageOptions(t){let e=this.image,s=t.image;return!1!==e&&!1!==s&&("object"!=typeof e&&(e={}),"object"!=typeof s&&(s={}),{...s,...e})}}},(function(){var t=this,e=t._self._c;return"table"===t.layout?e("k-table",t._b({on:{change:function(e){return t.$emit("change",e)},sort:function(e){return t.$emit("sort",e)},option:t.onOption}},"k-table",t.table,!1)):e("k-draggable",{staticClass:"k-items",class:"k-"+t.layout+"-items",attrs:{handle:!0,options:t.dragOptions,"data-layout":t.layout,"data-size":t.size,list:t.items},on:{change:function(e){return t.$emit("change",e)},end:function(e){return t.$emit("sort",t.items,e)}}},t._l(t.items,(function(s,i){return e("k-item",t._b({key:s.id||i,class:{"k-draggable-item":t.sortable&&s.sortable},attrs:{image:t.imageOptions(s),layout:t.layout,link:!!t.link&&s.link,sortable:t.sortable&&s.sortable,width:s.column},on:{click:function(e){return t.$emit("item",s,i)},drag:function(e){return t.onDragStart(e,s.dragText)},option:function(e){return t.onOption(e,s,i)}},nativeOn:{mouseover:function(e){return t.$emit("hover",e,s,i)}},scopedSlots:t._u([{key:"options",fn:function(){return[t._t("options",null,null,{item:s,itemIndex:i})]},proxy:!0}],null,!0)},"k-item",s,!1))})),1)}),[],!1,null,null,null,null).exports;var Pi=Mt({inheritAttrs:!0,props:{autofocus:{type:Boolean,default:!0},centered:{type:Boolean,default:!1},dimmed:{type:Boolean,default:!0},loading:{type:Boolean,default:!1}},data:()=>({isOpen:!1,scrollTop:0}),methods:{close(){!1!==this.isOpen&&(this.isOpen=!1,this.$emit("close"),this.restoreScrollPosition(),this.$events.$off("keydown.esc",this.close))},focus(){var t,e;let s=this.$refs.overlay.querySelector("\n [autofocus],\n [data-autofocus]\n ");return null===s&&(s=this.$refs.overlay.querySelector("\n input,\n textarea,\n select,\n button\n ")),"function"==typeof(null==s?void 0:s.focus)?s.focus():"function"==typeof(null==(e=null==(t=this.$slots.default[0])?void 0:t.context)?void 0:e.focus)?this.$slots.default[0].context.focus():void 0},open(){!0!==this.isOpen&&(this.storeScrollPosition(),this.isOpen=!0,this.$emit("open"),this.$events.$on("keydown.esc",this.close),setTimeout((()=>{!0===this.autofocus&&this.focus(),document.querySelector(".k-overlay > *").addEventListener("mousedown",(t=>t.stopPropagation())),this.$emit("ready")}),1))},restoreScrollPosition(){const t=document.querySelector(".k-panel-view");(null==t?void 0:t.scrollTop)&&(t.scrollTop=this.scrollTop)},storeScrollPosition(){const t=document.querySelector(".k-panel-view");(null==t?void 0:t.scrollTop)?this.scrollTop=t.scrollTop:this.scrollTop=0}}},(function(){var t=this,e=t._self._c;return t.isOpen?e("portal",[e("div",t._g({ref:"overlay",staticClass:"k-overlay",class:t.$vnode.data.staticClass,attrs:{"data-centered":t.loading||t.centered,"data-dimmed":t.dimmed,"data-loading":t.loading,dir:t.$translation.direction},on:{mousedown:t.close}},t.$listeners),[t.loading?e("k-loader",{staticClass:"k-overlay-loader"}):t._t("default",null,{close:t.close,isOpen:t.isOpen})],2)]):t._e()}),[],!1,null,null,null,null).exports;var Ni=Mt({computed:{defaultLanguage(){return!!this.$language&&this.$language.default},dialog(){return this.$helper.clone(this.$store.state.dialog)},language(){return this.$language?this.$language.code:null},role(){return this.$user?this.$user.role:null},user(){return this.$user?this.$user.id:null}},created(){this.$events.$on("drop",this.drop)},destroyed(){this.$events.$off("drop",this.drop)},methods:{drop(){this.$store.dispatch("drag",null)}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-panel",attrs:{"data-dragging":t.$store.state.drag,"data-loading":t.$store.state.isLoading,"data-language":t.language,"data-language-default":t.defaultLanguage,"data-role":t.role,"data-translation":t.$translation.code,"data-user":t.user,dir:t.$translation.direction}},[t._t("default"),t.$store.state.dialog&&t.$store.state.dialog.props?[e("k-fiber-dialog",t._b({},"k-fiber-dialog",t.dialog,!1))]:t._e(),!1!==t.$store.state.fatal?e("k-fatal",{attrs:{html:t.$store.state.fatal}}):t._e(),!1===t.$system.isLocal?e("k-offline-warning"):t._e(),e("k-icons")],2)}),[],!1,null,null,null,null).exports;var qi=Mt({props:{reports:Array,size:{type:String,default:"large"}}},(function(){var t=this,e=t._self._c;return e("dl",{staticClass:"k-stats",attrs:{"data-size":t.size}},t._l(t.reports,(function(s,i){return e(s.link?"k-link":"div",{key:i,tag:"component",staticClass:"k-stat",attrs:{"data-theme":s.theme,"data-click":!!s.click,to:s.link},on:{click:function(t){s.click&&s.click()}}},[e("dt",{staticClass:"k-stat-label"},[t._v(t._s(s.label))]),e("dd",{staticClass:"k-stat-value"},[t._v(t._s(s.value))]),e("dd",{staticClass:"k-stat-info"},[t._v(t._s(s.info))])])})),1)}),[],!1,null,null,null,null).exports;var Fi=Mt({inheritAttrs:!1,props:{columns:Object,disabled:Boolean,fields:{type:Object,default:()=>({})},empty:String,index:{type:[Number,Boolean],default:1},rows:Array,options:[Array,Function],sortable:Boolean},data(){return{values:this.rows}},computed:{columnsCount(){return Object.keys(this.columns).length},dragOptions(){return{disabled:!this.sortable,fallbackClass:"k-table-row-fallback",ghostClass:"k-table-row-ghost"}},hasIndexColumn(){return this.sortable||!1!==this.index},hasOptions(){return this.options||Object.values(this.values).filter((t=>t.options)).length>0}},watch:{rows(){this.values=this.rows}},methods:{isColumnEmpty(t){return 0===this.rows.filter((e=>!1===this.$helper.object.isEmpty(e[t]))).length},label(t,e){return t.label||this.$helper.string.ucfirst(e)},onChange(t){this.$emit("change",t)},onCell(t){this.$emit("cell",t)},onCellUpdate({columnIndex:t,rowIndex:e,value:s}){this.values[e][t]=s,this.$emit("input",this.values)},onHeader(t){this.$emit("header",t)},onOption(t,e,s){this.$emit("option",t,e,s)},onSort(){this.$emit("input",this.values),this.$emit("sort",this.values)},width(t){return"string"!=typeof t?"auto":!1===t.includes("/")?t:this.$helper.ratio(t,"auto",!1)}}},(function(){var t=this,e=t._self._c;return e("table",{staticClass:"k-table",attrs:{"data-disabled":t.disabled,"data-indexed":t.hasIndexColumn}},[e("thead",[e("tr",[t.hasIndexColumn?e("th",{staticClass:"k-table-index-column",attrs:{"data-mobile":""}},[t._v(" # ")]):t._e(),t._l(t.columns,(function(s,i){return e("th",{key:i+"-header",staticClass:"k-table-column",style:"width:"+t.width(s.width),attrs:{"data-mobile":s.mobile},on:{click:function(e){return t.onHeader({column:s,columnIndex:i})}}},[t._t("header",(function(){return[t._v(" "+t._s(t.label(s,i))+" ")]}),null,{column:s,columnIndex:i,label:t.label(s,i)})],2)})),t.hasOptions?e("th",{staticClass:"k-table-options-column",attrs:{"data-mobile":""}}):t._e()],2)]),e("k-draggable",{attrs:{list:t.values,options:t.dragOptions,handle:!0,element:"tbody"},on:{change:t.onChange,end:t.onSort}},[0===t.rows.length?e("tr",[e("td",{staticClass:"k-table-empty",attrs:{colspan:t.columnsCount}},[t._v(" "+t._s(t.empty)+" ")])]):t._l(t.values,(function(s,i){return e("tr",{key:i},[t.hasIndexColumn?e("td",{staticClass:"k-table-index-column",attrs:{"data-sortable":t.sortable&&!1!==s.sortable,"data-mobile":""}},[t._t("index",(function(){return[e("div",{staticClass:"k-table-index",domProps:{textContent:t._s(t.index+i)}})]}),null,{row:s,rowIndex:i}),t.sortable&&!1!==s.sortable?e("k-sort-handle",{staticClass:"k-table-sort-handle"}):t._e()],2):t._e(),t._l(t.columns,(function(n,o){return e("k-table-cell",{key:i+"-"+o,staticClass:"k-table-column",style:"width:"+t.width(n.width),attrs:{column:n,field:t.fields[o],row:s,mobile:n.mobile,value:s[o]},on:{input:function(e){return t.onCellUpdate({columnIndex:o,rowIndex:i,value:e})}},nativeOn:{click:function(e){return t.onCell({row:s,rowIndex:i,column:n,columnIndex:o})}}})})),t.hasOptions?e("td",{staticClass:"k-table-options-column",attrs:{"data-mobile":""}},[t._t("options",(function(){return[e("k-options-dropdown",{attrs:{options:s.options||t.options,text:(s.options||t.options).length>1},on:{option:function(e){return t.onOption(e,s,i)}}})]}),null,{row:s,rowIndex:i,options:t.options})],2):t._e()],2)}))],2)],1)}),[],!1,null,null,null,null).exports;var Ri=Mt({inheritAttrs:!1,props:{column:Object,field:Object,mobile:{type:Boolean,default:!1},row:Object,value:{default:""}},computed:{component(){return this.$helper.isComponent(`k-${this.type}-field-preview`)?`k-${this.type}-field-preview`:this.$helper.isComponent(`k-table-${this.type}-cell`)?`k-table-${this.type}-cell`:Array.isArray(this.value)?"k-array-field-preview":"k-text-field-preview"},type(){var t;return this.column.type||(null==(t=this.field)?void 0:t.type)}}},(function(){var t=this,e=t._self._c;return e("td",{attrs:{"data-align":t.column.align,"data-mobile":t.mobile}},[!1===t.$helper.object.isEmpty(t.value)?[e(t.component,{tag:"component",attrs:{column:t.column,field:t.field,row:t.row,value:t.value},on:{input:function(e){return t.$emit("input",e)}}})]:t._e()],2)}),[],!1,null,null,null,null).exports;var zi=Mt({props:{tab:String,tabs:Array,theme:String},data(){return{size:null,visibleTabs:this.tabs,invisibleTabs:[]}},computed:{current(){return(this.tabs.find((t=>t.name===this.tab))||this.tabs[0]||{}).name}},watch:{tabs:{handler(t){this.visibleTabs=t,this.invisibleTabs=[],this.resize(!0)},immediate:!0}},created(){window.addEventListener("resize",this.resize)},destroyed(){window.removeEventListener("resize",this.resize)},methods:{resize(t){if(this.tabs&&!(this.tabs.length<=1)){if(this.tabs.length<=3)return this.visibleTabs=this.tabs,void(this.invisibleTabs=[]);if(window.innerWidth>=700){if("large"===this.size&&!t)return;this.visibleTabs=this.tabs,this.invisibleTabs=[],this.size="large"}else{if("small"===this.size&&!t)return;this.visibleTabs=this.tabs.slice(0,2),this.invisibleTabs=this.tabs.slice(2),this.size="small"}}}}},(function(){var t=this,e=t._self._c;return t.tabs&&t.tabs.length>1?e("div",{staticClass:"k-tabs",attrs:{"data-theme":t.theme}},[e("nav",[t._l(t.visibleTabs,(function(s){return e("k-button",{key:s.name,staticClass:"k-tab-button",attrs:{link:s.link,current:t.current===s.name,icon:s.icon,tooltip:s.label}},[t._v(" "+t._s(s.label||s.text||s.name)+" "),s.badge?e("span",{staticClass:"k-tabs-badge"},[t._v(" "+t._s(s.badge)+" ")]):t._e()])})),t.invisibleTabs.length?e("k-button",{staticClass:"k-tab-button k-tabs-dropdown-button",attrs:{text:t.$t("more"),icon:"dots"},on:{click:function(e){return e.stopPropagation(),t.$refs.more.toggle()}}}):t._e()],2),t.invisibleTabs.length?e("k-dropdown-content",{ref:"more",staticClass:"k-tabs-dropdown",attrs:{align:"right"}},t._l(t.invisibleTabs,(function(s){return e("k-dropdown-item",{key:"more-"+s.name,attrs:{link:s.link,current:t.tab===s.name,icon:s.icon,tooltip:s.label}},[t._v(" "+t._s(s.label||s.text||s.name)+" ")])})),1):t._e()],1):t._e()}),[],!1,null,null,null,null).exports;var Yi=Mt({props:{align:String}},(function(){var t=this;return(0,t._self._c)("div",{staticClass:"k-view",attrs:{"data-align":t.align}},[t._t("default")],2)}),[],!1,null,null,null,null).exports;var Hi=Mt({components:{draggable:N},props:{data:Object,element:String,handle:[String,Boolean],list:[Array,Object],move:Function,options:Object},data(){return{listeners:{...this.$listeners,start:t=>{this.$store.dispatch("drag",{}),this.$listeners.start&&this.$listeners.start(t)},end:t=>{this.$store.dispatch("drag",null),this.$listeners.end&&this.$listeners.end(t)}}}},computed:{dragOptions(){let t=!1;return t=!0===this.handle?".k-sort-handle":this.handle,{fallbackClass:"k-sortable-fallback",fallbackOnBody:!0,forceFallback:!0,ghostClass:"k-sortable-ghost",handle:t,scroll:document.querySelector(".k-panel-view"),...this.options}}}},(function(){var t=this;return(0,t._self._c)("draggable",t._g(t._b({staticClass:"k-draggable",attrs:{"component-data":t.data,tag:t.element,list:t.list,move:t.move},scopedSlots:t._u([{key:"footer",fn:function(){return[t._t("footer")]},proxy:!0}],null,!0)},"draggable",t.dragOptions,!1),t.listeners),[t._t("default")],2)}),[],!1,null,null,null,null).exports;var Ui=Mt({data:()=>({error:null}),errorCaptured(t){return this.$config.debug&&window.console.warn(t),this.error=t,!1},render(t){return this.error?this.$slots.error?this.$slots.error[0]:this.$scopedSlots.error?this.$scopedSlots.error({error:this.error}):t("k-box",{attrs:{theme:"negative"}},this.error.message||this.error):this.$slots.default[0]}},null,null,!1,null,null,null,null).exports;var Ki=Mt({props:{html:String},mounted(){try{let t=this.$refs.iframe.contentWindow.document;t.open(),t.write(this.html),t.close()}catch(t){console.error(t)}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-fatal"},[e("div",{staticClass:"k-fatal-box"},[e("k-bar",{scopedSlots:t._u([{key:"left",fn:function(){return[e("k-headline",[t._v(" The JSON response could not be parsed ")])]},proxy:!0},{key:"right",fn:function(){return[e("k-button",{attrs:{icon:"cancel",text:"Close"},on:{click:function(e){return t.$store.dispatch("fatal",!1)}}})]},proxy:!0}])}),e("iframe",{ref:"iframe",staticClass:"k-fatal-iframe"})],1)])}),[],!1,null,null,null,null).exports;var Ji=Mt({props:{link:String,size:{type:String},tag:{type:String,default:"h2"},theme:{type:String}}},(function(){var t=this,e=t._self._c;return e(t.tag,t._g({tag:"component",staticClass:"k-headline",attrs:{"data-theme":t.theme,"data-size":t.size}},t.$listeners),[t.link?e("k-link",{attrs:{to:t.link}},[t._t("default")],2):t._t("default")],2)}),[],!1,null,null,null,null).exports;var Gi=Mt({props:{alt:String,color:String,back:String,size:String,type:String},computed:{isEmoji(){return this.$helper.string.hasEmoji(this.type)}}},(function(){var t=this,e=t._self._c;return e("span",{class:"k-icon k-icon-"+t.type,style:{background:t.$helper.color(t.back)},attrs:{"aria-label":t.alt,role:t.alt?"img":null,"aria-hidden":!t.alt,"data-back":t.back,"data-size":t.size}},[t.isEmoji?e("span",{staticClass:"k-icon-emoji"},[t._v(t._s(t.type))]):e("svg",{style:{color:t.$helper.color(t.color)},attrs:{viewBox:"0 0 16 16"}},[e("use",{attrs:{"xlink:href":"#icon-"+t.type}})])])}),[],!1,null,null,null,null).exports;var Vi=Mt({icons:window.panel.plugins.icons},(function(){var t=this,e=t._self._c;return e("svg",{staticClass:"k-icons",attrs:{"aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",overflow:"hidden"}},[e("defs",t._l(t.$options.icons,(function(s,i){return e("symbol",{key:i,attrs:{id:"icon-"+i,viewBox:"0 0 16 16"},domProps:{innerHTML:t._s(s)}})})),0)])}),[],!1,null,null,null,null).exports;var Wi=Mt({props:{alt:String,back:String,cover:Boolean,ratio:String,sizes:String,src:String,srcset:String},data:()=>({loaded:{type:Boolean,default:!1},error:{type:Boolean,default:!1}}),computed:{ratioPadding(){return this.$helper.ratio(this.ratio||"1/1")}},created(){let t=new Image;t.onload=()=>{this.loaded=!0,this.$emit("load")},t.onerror=()=>{this.error=!0,this.$emit("error")},t.src=this.src}},(function(){var t=this,e=t._self._c;return e("span",t._g({staticClass:"k-image",attrs:{"data-ratio":t.ratio,"data-back":t.back,"data-cover":t.cover}},t.$listeners),[e("span",{style:"padding-bottom:"+t.ratioPadding},[t.loaded?e("img",{key:t.src,attrs:{alt:t.alt||"",src:t.src,srcset:t.srcset,sizes:t.sizes},on:{dragstart:function(t){t.preventDefault()}}}):t._e(),t.loaded||t.error?t._e():e("k-loader",{attrs:{position:"center",theme:"light"}}),!t.loaded&&t.error?e("k-icon",{staticClass:"k-image-error",attrs:{type:"cancel"}}):t._e()],1)])}),[],!1,null,null,null,null).exports;var Xi=Mt({},(function(){var t=this._self._c;return t("span",{staticClass:"k-loader"},[t("k-icon",{staticClass:"k-loader-icon",attrs:{type:"loader"}})],1)}),[],!1,null,null,null,null).exports;var Zi=Mt({data:()=>({offline:!1}),created(){this.$events.$on("offline",this.isOffline),this.$events.$on("online",this.isOnline)},destroyed(){this.$events.$off("offline",this.isOffline),this.$events.$off("online",this.isOnline)},methods:{isOnline(){this.offline=!1},isOffline(){this.offline=!0}}},(function(){var t=this,e=t._self._c;return t.offline?e("div",{staticClass:"k-offline-warning"},[e("p",[e("k-icon",{attrs:{type:"bolt"}}),t._v(" "+t._s(t.$t("error.offline")))],1)]):t._e()}),[],!1,null,null,null,null).exports;const Qi=(t,e=!1)=>{if(t>=0&&t<=100)return!0;if(e)throw new Error("value has to be between 0 and 100");return!1};var tn=Mt({props:{value:{type:Number,default:0,validator:Qi}},data(){return{state:this.value}},watch:{value(t){this.state=t}},methods:{set(t){Qi(t,!0),this.state=t}}},(function(){var t=this;return(0,t._self._c)("progress",{staticClass:"k-progress",attrs:{max:"100"},domProps:{value:t.state}},[t._v(t._s(t.state)+"%")])}),[],!1,null,null,null,null).exports;var en=Mt({},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-registration"},[e("p",[t._v(t._s(t.$t("license.unregistered")))]),e("k-button",{staticClass:"k-topbar-button",attrs:{responsive:!0,tooltip:t.$t("license.unregistered"),icon:"key"},on:{click:function(e){return t.$dialog("registration")}}},[t._v(" "+t._s(t.$t("license.register"))+" ")]),e("k-button",{staticClass:"k-topbar-button",attrs:{responsive:!0,link:"https://getkirby.com/buy",target:"_blank",icon:"cart"}},[t._v(" "+t._s(t.$t("license.buy"))+" ")])],1)}),[],!1,null,null,null,null).exports;var sn=Mt({props:{icon:{type:String,default:"sort"}}},(function(){return(0,this._self._c)("k-icon",{staticClass:"k-sort-handle",attrs:{type:this.icon,"aria-hidden":"true"}})}),[],!1,null,null,null,null).exports;var nn=Mt({props:{click:{type:Function,default:()=>{}},disabled:Boolean,responsive:Boolean,status:String,text:String,tooltip:String},computed:{icon(){return"draft"===this.status?"circle-outline":"unlisted"===this.status?"circle-half":"circle"},theme(){return"draft"===this.status?"negative":"unlisted"===this.status?"info":"positive"},title(){let t=this.tooltip||this.text;return this.disabled&&(t+=` (${this.$t("disabled")})`),t}},methods:{onClick(){this.click(),this.$emit("click")}}},(function(){var t=this;return(0,t._self._c)("k-button",{class:"k-status-icon k-status-icon-"+t.status,attrs:{disabled:t.disabled,icon:t.icon,responsive:t.responsive,text:t.text,theme:t.theme,tooltip:t.title},on:{click:t.onClick}})}),[],!1,null,null,null,null).exports;var on=Mt({props:{align:String,size:String,theme:String}},(function(){var t=this;return(0,t._self._c)("div",{staticClass:"k-text",attrs:{"data-align":t.align,"data-size":t.size,"data-theme":t.theme}},[t._t("default")],2)}),[],!1,null,null,null,null).exports;var rn=Mt({props:{user:[Object,String]}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-user-info"},[t.user.avatar?e("k-image",{attrs:{cover:!0,src:t.user.avatar.url,ratio:"1/1"}}):e("k-icon",{attrs:{type:"user"}}),t._v(" "+t._s(t.user.name||t.user.email||t.user)+" ")],1)}),[],!1,null,null,null,null).exports;var ln=Mt({props:{crumbs:{type:Array,default:()=>[]},label:{type:String,default:"Breadcrumb"},view:Object},computed:{dropdown(){return this.segments.map((t=>({...t,text:t.label,icon:"angle-right"})))},segments(){return[{link:this.view.link,label:this.view.breadcrumbLabel,icon:this.view.icon,loading:this.$store.state.isLoading},...this.crumbs]}},methods:{isLast(t){return this.crumbs.length-1===t}}},(function(){var t=this,e=t._self._c;return e("nav",{staticClass:"k-breadcrumb",attrs:{"aria-label":t.label}},[e("k-dropdown",{staticClass:"k-breadcrumb-dropdown"},[e("k-button",{attrs:{icon:"road-sign"},on:{click:function(e){return t.$refs.dropdown.toggle()}}}),e("k-dropdown-content",{ref:"dropdown",attrs:{options:t.dropdown,theme:"light"}})],1),e("ol",t._l(t.segments,(function(s,i){return e("li",{key:i},[e("k-link",{staticClass:"k-breadcrumb-link",attrs:{title:s.text||s.label,to:s.link,"aria-current":!!t.isLast(i)&&"page"}},[s.loading?e("k-loader",{staticClass:"k-breadcrumb-icon"}):s.icon?e("k-icon",{staticClass:"k-breadcrumb-icon",attrs:{type:s.icon}}):t._e(),e("span",{staticClass:"k-breadcrumb-link-text"},[t._v(" "+t._s(s.text||s.label)+" ")])],1)],1)})),0)],1)}),[],!1,null,null,null,null).exports;var an=Mt({inheritAttrs:!1,props:{autofocus:Boolean,click:Function,current:[String,Boolean],disabled:Boolean,icon:String,id:[String,Number],link:String,responsive:Boolean,rel:String,role:String,target:String,tabindex:String,text:[String,Number],theme:String,tooltip:String,type:{type:String,default:"button"}},computed:{component(){return!0===this.disabled?"k-button-disabled":this.link?"k-button-link":"k-button-native"}},methods:{focus(){this.$refs.button.focus&&this.$refs.button.focus()},tab(){this.$refs.button.tab&&this.$refs.button.tab()},untab(){this.$refs.button.untab&&this.$refs.button.untab()}}},(function(){var t=this;return(0,t._self._c)(t.component,t._g(t._b({ref:"button",tag:"component"},"component",t.$props,!1),t.$listeners),[t.text?[t._v(" "+t._s(t.text)+" ")]:t._t("default")],2)}),[],!1,null,null,null,null).exports;var un=Mt({inheritAttrs:!1,props:{icon:String,id:[String,Number],responsive:Boolean,theme:String,tooltip:String}},(function(){var t=this,e=t._self._c;return e("span",{staticClass:"k-button",attrs:{id:t.id,"data-disabled":!0,"data-responsive":t.responsive,"data-theme":t.theme,title:t.tooltip}},[t.icon?e("k-icon",{staticClass:"k-button-icon",attrs:{type:t.icon,alt:t.tooltip}}):t._e(),t.$slots.default?e("span",{staticClass:"k-button-text"},[t._t("default")],2):t._e()],1)}),[],!1,null,null,null,null).exports;var cn=Mt({props:{buttons:Array}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-button-group"},[t.$slots.default?t._t("default"):t._l(t.buttons,(function(s,i){return e("k-button",t._b({key:i},"k-button",s,!1))}))],2)}),[],!1,null,null,null,null).exports;var dn=Mt({inheritAttrs:!1,props:{autofocus:Boolean,current:[String,Boolean],icon:String,id:[String,Number],link:String,rel:String,responsive:Boolean,role:String,target:String,tabindex:String,theme:String,tooltip:String},methods:{focus(){this.$el.focus()}}},(function(){var t=this,e=t._self._c;return e("k-link",t._g({staticClass:"k-button",attrs:{id:t.id,"aria-current":t.current,autofocus:t.autofocus,"data-theme":t.theme,"data-responsive":t.responsive,rel:t.rel,role:t.role,tabindex:t.tabindex,target:t.target,title:t.tooltip,to:t.link}},t.$listeners),[t.icon?e("k-icon",{staticClass:"k-button-icon",attrs:{type:t.icon,alt:t.tooltip}}):t._e(),t.$slots.default?e("span",{staticClass:"k-button-text"},[t._t("default")],2):t._e()],1)}),[],!1,null,null,null,null).exports,pn={mounted(){this.$el.addEventListener("keyup",this.onTab,!0),this.$el.addEventListener("blur",this.onUntab,!0)},destroyed(){this.$el.removeEventListener("keyup",this.onTab,!0),this.$el.removeEventListener("blur",this.onUntab,!0)},methods:{focus(){this.$el.focus&&this.$el.focus()},onTab(t){9===t.keyCode&&this.$el.setAttribute("data-tabbed",!0)},onUntab(){this.$el.removeAttribute("data-tabbed")},tab(){this.$el.focus(),this.$el.setAttribute("data-tabbed",!0)},untab(){this.$el.removeAttribute("data-tabbed")}}};var hn=Mt({mixins:[pn],inheritAttrs:!1,props:{autofocus:Boolean,click:{type:Function,default:()=>{}},current:[String,Boolean],icon:String,id:[String,Number],responsive:Boolean,role:String,tabindex:String,theme:String,tooltip:String,type:{type:String,default:"button"}}},(function(){var t=this,e=t._self._c;return e("button",t._g({staticClass:"k-button",attrs:{id:t.id,"aria-current":t.current,autofocus:t.autofocus,"data-theme":t.theme,"data-responsive":t.responsive,role:t.role,tabindex:t.tabindex,title:t.tooltip,type:t.type},on:{click:t.click}},t.$listeners),[t.icon?e("k-icon",{staticClass:"k-button-icon",attrs:{type:t.icon,alt:t.tooltip}}):t._e(),t.$slots.default?e("span",{staticClass:"k-button-text"},[t._t("default")],2):t._e()],1)}),[],!1,null,null,null,null).exports;var mn=Mt({},(function(){return(0,this._self._c)("span",{staticClass:"k-dropdown",on:{click:function(t){t.stopPropagation()}}},[this._t("default")],2)}),[],!1,null,null,null,null).exports;let fn=null;var gn=Mt({props:{align:{type:String,default:"left"},options:[Array,Function,String],theme:{type:String,default:"dark"}},data:()=>({current:-1,dropup:!1,isOpen:!1,items:[]}),methods:{async fetchOptions(t){if(!this.options)return t(this.items);"string"==typeof this.options?this.$dropdown(this.options)(t):"function"==typeof this.options?this.options(t):Array.isArray(this.options)&&t(this.options)},onOptionClick(t){"function"==typeof t.click?t.click.call(this):t.click&&this.$emit("action",t.click)},open(){this.reset(),fn&&fn!==this&&fn.close(),this.fetchOptions((t=>{this.$events.$on("keydown",this.navigate),this.$events.$on("click",this.close),this.items=t,this.isOpen=!0,fn=this,this.onOpen(),this.$emit("open")}))},reset(){this.current=-1,this.$events.$off("keydown",this.navigate),this.$events.$off("click",this.close)},close(){this.reset(),this.isOpen=fn=!1,this.$emit("close")},toggle(){this.isOpen?this.close():this.open()},focus(t=0){var e;(null==(e=this.$children[t])?void 0:e.focus)&&(this.current=t,this.$children[t].focus())},onOpen(){this.dropup=!1,this.$nextTick((()=>{if(this.$el){let t=window.innerHeight||document.body.clientHeight||document.documentElement.clientHeight,e=50,s=this.$el.getBoundingClientRect().top||0,i=this.$el.clientHeight;s+i>t-e&&i+2*ethis.$children.length-1){const t=this.$children.filter((t=>!1===t.disabled));this.current=this.$children.indexOf(t[t.length-1]);break}if(this.$children[this.current]&&!1===this.$children[this.current].disabled){this.focus(this.current);break}}break;case"Tab":for(;;){if(this.current++,this.current>this.$children.length-1){this.close(),this.$emit("leave",t.code);break}if(this.$children[this.current]&&!1===this.$children[this.current].disabled)break}}}}},(function(){var t=this,e=t._self._c;return t.isOpen?e("div",{staticClass:"k-dropdown-content",attrs:{"data-align":t.align,"data-dropup":t.dropup,"data-theme":t.theme}},[t._t("default",(function(){return[t._l(t.items,(function(s,i){return["-"===s?e("hr",{key:t._uid+"-item-"+i}):e("k-dropdown-item",t._b({key:t._uid+"-item-"+i,ref:t._uid+"-item-"+i,refInFor:!0,on:{click:function(e){return t.onOptionClick(s)}}},"k-dropdown-item",s,!1),[t._v(" "+t._s(s.text)+" ")])]}))]}))],2):t._e()}),[],!1,null,null,null,null).exports;var kn=Mt({inheritAttrs:!1,props:{disabled:Boolean,icon:String,image:[String,Object],link:String,target:String,theme:String,upload:String,current:[String,Boolean]},data(){return{listeners:{...this.$listeners,click:t=>{this.$parent.close(),this.$emit("click",t)}}}},methods:{focus(){this.$refs.button.focus()},tab(){this.$refs.button.tab()}}},(function(){var t=this;return(0,t._self._c)("k-button",t._g(t._b({ref:"button",staticClass:"k-dropdown-item"},"k-button",t.$props,!1),t.listeners),[t._t("default")],2)}),[],!1,null,null,null,null).exports;var bn=Mt({mixins:[pn],props:{disabled:Boolean,rel:String,tabindex:[String,Number],target:String,title:String,to:[String,Function]},data(){return{relAttr:"_blank"===this.target?"noreferrer noopener":this.rel,listeners:{...this.$listeners,click:this.onClick}}},computed:{href(){return"function"==typeof this.to?"":"/"!==this.to[0]||this.target?!0===this.to.includes("@")&&!1===this.to.includes("/")?"mailto:"+this.to:this.to:this.$url(this.to)}},methods:{isRoutable(t){if(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)return!1;if(t.defaultPrevented)return!1;if(void 0!==t.button&&0!==t.button)return!1;if(this.target)return!1;if("string"==typeof this.href){if(this.href.includes("://")||this.href.startsWith("//"))return!1;if(this.href.includes("mailto:"))return!1}return!0},onClick(t){if(!0===this.disabled)return t.preventDefault(),!1;"function"==typeof this.to&&(t.preventDefault(),this.to()),this.isRoutable(t)&&(t.preventDefault(),this.$go(this.to)),this.$emit("click",t)}}},(function(){var t=this,e=t._self._c;return t.to&&!t.disabled?e("a",t._g({ref:"link",staticClass:"k-link",attrs:{href:t.href,rel:t.relAttr,tabindex:t.tabindex,target:t.target,title:t.title}},t.listeners),[t._t("default")],2):e("span",{staticClass:"k-link",attrs:{title:t.title,"data-disabled":""}},[t._t("default")],2)}),[],!1,null,null,null,null).exports;var vn=Mt({computed:{defaultLanguage(){return this.$languages.find((t=>!0===t.default))},language(){return this.$language},languages(){return this.$languages.filter((t=>!1===t.default))}},methods:{change(t){this.$emit("change",t),this.$go(window.location,{query:{language:t.code}})}}},(function(){var t=this,e=t._self._c;return t.languages.length?e("k-dropdown",{staticClass:"k-languages-dropdown"},[e("k-button",{attrs:{text:t.language.name,responsive:!0,icon:"globe"},on:{click:function(e){return t.$refs.languages.toggle()}}}),t.languages?e("k-dropdown-content",{ref:"languages"},[e("k-dropdown-item",{on:{click:function(e){return t.change(t.defaultLanguage)}}},[t._v(" "+t._s(t.defaultLanguage.name)+" ")]),e("hr"),t._l(t.languages,(function(s){return e("k-dropdown-item",{key:s.code,on:{click:function(e){return t.change(s)}}},[t._v(" "+t._s(s.name)+" ")])}))],2):t._e()],1):t._e()}),[],!1,null,null,null,null).exports;var yn=Mt({props:{align:{type:String,default:"right"},icon:{type:String,default:"dots"},options:{type:[Array,Function,String],default:()=>[]},text:{type:[Boolean,String],default:!0},theme:{type:String,default:"dark"}},computed:{hasSingleOption(){return Array.isArray(this.options)&&1===this.options.length}},methods:{onAction(t,e,s){"function"==typeof t?t.call(this):(this.$emit("action",t,e,s),this.$emit("option",t,e,s))},toggle(){this.$refs.options.toggle()}}},(function(){var t=this,e=t._self._c;return t.hasSingleOption?e("k-button",{staticClass:"k-options-dropdown-toggle",attrs:{icon:t.options[0].icon||t.icon,tooltip:t.options[0].tooltip||t.options[0].text},on:{click:function(e){return t.onAction(t.options[0].option||t.options[0].click,t.options[0],0)}}},[!0===t.text?[t._v(" "+t._s(t.options[0].text)+" ")]:!1!==t.text?[t._v(" "+t._s(t.text)+" ")]:t._e()],2):t.options.length?e("k-dropdown",{staticClass:"k-options-dropdown"},[e("k-button",{staticClass:"k-options-dropdown-toggle",attrs:{icon:t.icon,tooltip:t.$t("options")},on:{click:function(e){return t.$refs.options.toggle()}}},[t.text&&!0!==t.text?[t._v(" "+t._s(t.text)+" ")]:t._e()],2),e("k-dropdown-content",{ref:"options",staticClass:"k-options-dropdown-content",attrs:{align:t.align,options:t.options},on:{action:t.onAction}})],1):t._e()}),[],!1,null,null,null,null).exports;var $n=Mt({props:{align:{type:String,default:"left"},details:{type:Boolean,default:!1},dropdown:{type:Boolean,default:!0},keys:{type:Boolean,default:!1},limit:{type:Number,default:10},page:{type:Number,default:1},pageLabel:{type:String,default:()=>window.panel.$t("pagination.page")},total:{type:Number,default:0},prevLabel:{type:String,default:()=>window.panel.$t("prev")},nextLabel:{type:String,default:()=>window.panel.$t("next")},validate:{type:Function,default:()=>Promise.resolve()}},data(){return{currentPage:this.page}},computed:{show(){return this.pages>1},start(){return(this.currentPage-1)*this.limit+1},end(){let t=this.start-1+this.limit;return t>this.total?this.total:t},detailsText(){return 1===this.limit?this.start+" / ":this.start+"-"+this.end+" / "},pages(){return Math.ceil(this.total/this.limit)},hasPrev(){return this.start>1},hasNext(){return this.endthis.limit},offset(){return this.start-1}},watch:{page(t){this.currentPage=parseInt(t)}},created(){!0===this.keys&&window.addEventListener("keydown",this.navigate,!1)},destroyed(){window.removeEventListener("keydown",this.navigate,!1)},methods:{async goTo(t){try{await this.validate(t),t<1&&(t=1),t>this.pages&&(t=this.pages),this.currentPage=t,this.$refs.dropdown&&this.$refs.dropdown.close(),this.$emit("paginate",{page:this.currentPage,start:this.start,end:this.end,limit:this.limit,offset:this.offset})}catch(e){}},prev(){this.goTo(this.currentPage-1)},next(){this.goTo(this.currentPage+1)},navigate(t){switch(t.code){case"ArrowLeft":this.prev();break;case"ArrowRight":this.next()}}}},(function(){var t=this,e=t._self._c;return t.show?e("nav",{staticClass:"k-pagination",attrs:{"data-align":t.align}},[t.show?e("k-button",{attrs:{disabled:!t.hasPrev,tooltip:t.prevLabel,icon:"angle-left"},on:{click:t.prev}}):t._e(),t.details?[t.dropdown?[e("k-dropdown",[e("k-button",{staticClass:"k-pagination-details",attrs:{disabled:!t.hasPages},on:{click:function(e){return t.$refs.dropdown.toggle()}}},[t.total>1?[t._v(" "+t._s(t.detailsText)+" ")]:t._e(),t._v(" "+t._s(t.total)+" ")],2),e("k-dropdown-content",{ref:"dropdown",staticClass:"k-pagination-selector",on:{open:function(e){t.$nextTick((()=>t.$refs.page.focus()))}}},[e("div",{staticClass:"k-pagination-settings"},[e("label",{attrs:{for:"k-pagination-page"}},[e("span",[t._v(t._s(t.pageLabel)+":")]),e("select",{ref:"page",attrs:{id:"k-pagination-page"}},t._l(t.pages,(function(s){return e("option",{key:s,domProps:{selected:t.page===s,value:s}},[t._v(" "+t._s(s)+" ")])})),0)]),e("k-button",{attrs:{icon:"check"},on:{click:function(e){return t.goTo(t.$refs.page.value)}}})],1)])],1)]:[e("span",{staticClass:"k-pagination-details"},[t.total>1?[t._v(" "+t._s(t.detailsText)+" ")]:t._e(),t._v(" "+t._s(t.total)+" ")],2)]]:t._e(),t.show?e("k-button",{attrs:{disabled:!t.hasNext,tooltip:t.nextLabel,icon:"angle-right"},on:{click:t.next}}):t._e()],2):t._e()}),[],!1,null,null,null,null).exports;var _n=Mt({props:{prev:{type:[Boolean,Object],default:!1},next:{type:[Boolean,Object],default:!1}},computed:{buttons(){return[{...this.button(this.prev),icon:"angle-left"},{...this.button(this.next),icon:"angle-right"}]}},methods:{button:t=>t||{disabled:!0,link:"#"}}},(function(){return(0,this._self._c)("k-button-group",{staticClass:"k-prev-next",attrs:{buttons:this.buttons}})}),[],!1,null,null,null,null).exports;var xn=Mt({props:{types:{type:Object,default:()=>({})},type:String},data(){return{isLoading:!1,hasResults:!0,items:[],currentType:this.getType(this.type),q:null,selected:-1}},watch:{q(t,e){t!==e&&this.search(this.q)},currentType(t,e){t!==e&&this.search(this.q)},type(){this.currentType=this.getType(this.type)}},created(){this.search=pt(this.search,250),this.$events.$on("keydown.cmd.shift.f",this.open)},destroyed(){this.$events.$off("keydown.cmd.shift.f",this.open)},methods:{changeType(t){this.currentType=this.getType(t),this.$nextTick((()=>{this.$refs.input.focus()}))},close(){this.$refs.overlay.close(),this.hasResults=!0,this.items=[],this.q=null},getType(t){return this.types[t]||this.types[Object.keys(this.types)[0]]},navigate(t){this.$go(t.link),this.close()},onDown(){this.selected=0&&this.select(this.selected-1)},open(){this.$refs.overlay.open()},async search(t){this.isLoading=!0,this.$refs.types&&this.$refs.types.close();try{if(null===t||""===t)throw Error("Empty query");const e=await this.$search(this.currentType.id,t);if(!1===e)throw Error("JSON parsing failed");this.items=e.results}catch(e){this.items=[]}finally{this.select(-1),this.isLoading=!1,this.hasResults=this.items.length>0}},select(t){if(this.selected=t,this.$refs.items){const e=this.$refs.items.$el.querySelectorAll(".k-item");[...e].forEach((t=>delete t.dataset.selected)),t>=0&&(e[t].dataset.selected=!0)}}}},(function(){var t=this,e=t._self._c;return e("k-overlay",{ref:"overlay"},[e("div",{staticClass:"k-search",attrs:{role:"search"}},[e("div",{staticClass:"k-search-input"},[e("k-dropdown",{staticClass:"k-search-types"},[e("k-button",{attrs:{icon:t.currentType.icon,text:t.currentType.label},on:{click:function(e){return t.$refs.types.toggle()}}}),e("k-dropdown-content",{ref:"types"},t._l(t.types,(function(s,i){return e("k-dropdown-item",{key:i,attrs:{icon:s.icon},on:{click:function(e){return t.changeType(i)}}},[t._v(" "+t._s(s.label)+" ")])})),1)],1),e("input",{directives:[{name:"model",rawName:"v-model",value:t.q,expression:"q"}],ref:"input",attrs:{placeholder:t.$t("search")+" …","aria-label":t.$t("search"),autofocus:!0,type:"text"},domProps:{value:t.q},on:{input:[function(e){e.target.composing||(t.q=e.target.value)},function(e){t.hasResults=!0}],keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"down",40,e.key,["Down","ArrowDown"])?null:(e.preventDefault(),t.onDown.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"up",38,e.key,["Up","ArrowUp"])?null:(e.preventDefault(),t.onUp.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"tab",9,e.key,"Tab")?null:(e.preventDefault(),t.onTab.apply(null,arguments))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"enter",13,e.key,"Enter")?null:t.onEnter.apply(null,arguments)},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"esc",27,e.key,["Esc","Escape"])?null:t.close.apply(null,arguments)}]}}),e("k-button",{staticClass:"k-search-close",attrs:{icon:t.isLoading?"loader":"cancel",tooltip:t.$t("close")},on:{click:t.close}})],1),!t.q||t.hasResults&&!t.items.length?t._e():e("div",{staticClass:"k-search-results"},[t.items.length?e("k-collection",{ref:"items",attrs:{items:t.items},on:{hover:t.onHover},nativeOn:{mouseout:function(e){return t.select(-1)}}}):t.hasResults?t._e():e("p",{staticClass:"k-search-empty"},[t._v(" "+t._s(t.$t("search.results.none"))+" ")])],1)])])}),[],!1,null,null,null,null).exports;var wn=Mt({props:{removable:Boolean},methods:{remove(){this.removable&&this.$emit("remove")},focus(){this.$refs.button.focus()}}},(function(){var t=this,e=t._self._c;return e("span",{ref:"button",staticClass:"k-tag",attrs:{tabindex:"0"},on:{keydown:function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"delete",[8,46],e.key,["Backspace","Delete","Del"])?null:(e.preventDefault(),t.remove.apply(null,arguments))}}},[e("span",{staticClass:"k-tag-text"},[t._t("default")],2),t.removable?e("k-icon",{staticClass:"k-tag-toggle",attrs:{type:"cancel-small"},nativeOn:{click:function(e){return t.remove.apply(null,arguments)}}}):t._e()],1)}),[],!1,null,null,null,null).exports;var Sn=Mt({props:{breadcrumb:Array,license:Boolean,menu:Array,title:String,view:Object},computed:{notification(){return this.$store.state.notification.type&&"error"!==this.$store.state.notification.type?this.$store.state.notification:null}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-topbar"},[e("k-view",[e("div",{staticClass:"k-topbar-wrapper"},[e("k-dropdown",{staticClass:"k-topbar-menu"},[e("k-button",{staticClass:"k-topbar-button k-topbar-menu-button",attrs:{tooltip:t.$t("menu"),icon:"bars"},on:{click:function(e){return t.$refs.menu.toggle()}}},[e("k-icon",{attrs:{type:"angle-down"}})],1),e("k-dropdown-content",{ref:"menu",staticClass:"k-topbar-menu",attrs:{options:t.menu,theme:"light"}})],1),e("k-breadcrumb",{staticClass:"k-topbar-breadcrumb",attrs:{crumbs:t.breadcrumb,view:t.view}}),e("div",{staticClass:"k-topbar-signals"},[t.notification?e("k-button",{staticClass:"k-topbar-notification k-topbar-button",attrs:{text:t.notification.message,theme:"positive"},on:{click:function(e){return t.$store.dispatch("notification/close")}}}):t.license?t._e():e("k-registration"),e("k-form-indicator"),e("k-button",{staticClass:"k-topbar-button",attrs:{tooltip:t.$t("search"),icon:"search"},on:{click:function(e){return t.$refs.search.open()}}})],1)],1)]),e("k-search",{ref:"search",attrs:{type:t.$view.search||"pages",types:t.$searches}})],1)}),[],!1,null,null,null,null).exports;var Cn=Mt({props:{empty:String,blueprint:String,lock:[Boolean,Object],parent:String,tab:Object},computed:{content(){return this.$store.getters["content/values"]()}},methods:{exists(t){return this.$helper.isComponent(`k-${t}-section`)},meetsCondition(t){if(!t.when)return!0;let e=!0;return Object.keys(t.when).forEach((s=>{this.content[s.toLowerCase()]!==t.when[s]&&(e=!1)})),e}}},(function(){var t=this,e=t._self._c;return 0===t.tab.columns.length?e("k-box",{attrs:{html:!0,text:t.empty,theme:"info"}}):e("k-grid",{staticClass:"k-sections",attrs:{gutter:"large"}},t._l(t.tab.columns,(function(s,i){return e("k-column",{key:t.parent+"-column-"+i,attrs:{width:s.width,sticky:s.sticky}},[t._l(s.sections,(function(n,o){return[t.meetsCondition(n)?[t.exists(n.type)?e("k-"+n.type+"-section",t._b({key:t.parent+"-column-"+i+"-section-"+o+"-"+t.blueprint,tag:"component",class:"k-section k-section-name-"+n.name,attrs:{column:s.width,lock:t.lock,name:n.name,parent:t.parent,timestamp:t.$view.timestamp},on:{submit:function(e){return t.$emit("submit",e)}}},"component",n,!1)):[e("k-box",{key:t.parent+"-column-"+i+"-section-"+o,attrs:{text:t.$t("error.section.type.invalid",{type:n.type}),theme:"negative"}})]]:t._e()]}))],2)})),1)}),[],!1,null,null,null,null).exports;var On=Mt({mixins:[Tt],inheritAttrs:!1,data:()=>({fields:{},isLoading:!0,issue:null}),computed:{values(){return this.$store.getters["content/values"]()}},watch:{timestamp(){this.fetch()}},created(){this.input=pt(this.input,50),this.fetch()},methods:{input(t,e,s){this.$store.dispatch("content/update",[s,t[s]])},async fetch(){try{const t=await this.load();this.fields=t.fields,Object.keys(this.fields).forEach((t=>{this.fields[t].section=this.name,this.fields[t].endpoints={field:this.parent+"/fields/"+t,section:this.parent+"/sections/"+this.name,model:this.parent}}))}catch(t){this.issue=t}finally{this.isLoading=!1}},onSubmit(t){this.$events.$emit("keydown.cmd.s",t)}}},(function(){var t=this,e=t._self._c;return t.isLoading?t._e():e("section",{staticClass:"k-fields-section"},[t.issue?[e("k-headline",{staticClass:"k-fields-issue-headline"},[t._v(" Error ")]),e("k-box",{attrs:{text:t.issue.message,html:!1,theme:"negative"}})]:t._e(),e("k-form",{attrs:{fields:t.fields,validate:!0,value:t.values,disabled:t.lock&&"lock"===t.lock.state},on:{input:t.input,submit:t.onSubmit}})],2)}),[],!1,null,null,null,null).exports;var An=Mt({inheritAttrs:!1,props:{blueprint:String,column:String,parent:String,name:String,timestamp:Number},data:()=>({data:[],error:null,isLoading:!1,isProcessing:!1,options:{columns:{},empty:null,headline:null,help:null,layout:"list",link:null,max:null,min:null,size:null,sortable:null},pagination:{page:null},searchterm:null,searching:!1}),computed:{addIcon:()=>"add",buttons(){let t=[];return this.canSearch&&t.push({icon:"filter",text:this.$t("search"),click:this.onSearchToggle,responsive:!0}),this.canAdd&&t.push({icon:this.addIcon,text:this.$t("add"),click:this.onAdd}),t},canAdd:()=>!0,canDrop:()=>!1,canSearch(){return this.options.search},collection(){return{columns:this.options.columns,empty:this.emptyPropsWithSearch,layout:this.options.layout,help:this.options.help,items:this.items,pagination:this.pagination,sortable:!this.isProcessing&&this.options.sortable,size:this.options.size}},emptyProps(){return{icon:"page",text:this.$t("pages.empty")}},emptyPropsWithSearch(){return{...this.emptyProps,text:this.searching?this.$t("search.results.none"):this.options.empty||this.emptyProps.text}},items(){return this.data},isInvalid(){var t;return!((null==(t=this.searchterm)?void 0:t.length)>0)&&(!!(this.options.min&&this.data.lengththis.options.max))},paginationId(){return"kirby$pagination$"+this.parent+"/"+this.name},type:()=>"models"},watch:{searchterm:pt((function(){this.pagination.page=0,this.reload()}),200),timestamp(){this.reload()}},created(){this.load()},methods:{async load(t){t||(this.isLoading=!0),this.isProcessing=!0,null===this.pagination.page&&(this.pagination.page=localStorage.getItem(this.paginationId)||1);try{const t=await this.$api.get(this.parent+"/sections/"+this.name,{page:this.pagination.page,searchterm:this.searchterm});this.options=t.options,this.pagination=t.pagination,this.data=t.data}catch(e){this.error=e.message}finally{this.isProcessing=!1,this.isLoading=!1}},onAction(){},onAdd(){},onChange(){},onDrop(){},onSort(){},onPaginate(t){localStorage.setItem(this.paginationId,t.page),this.pagination=t,this.reload()},onSearchToggle(){this.searching=!this.searching,this.searchterm=null},onUpload(){},async reload(){await this.load(!0)},update(){this.reload(),this.$events.$emit("model.update")}}},(function(){var t=this,e=t._self._c;return!1===t.isLoading?e("section",{class:`k-models-section k-${t.type}-section`,attrs:{"data-processing":t.isProcessing}},[e("header",{staticClass:"k-section-header"},[e("k-headline",{attrs:{link:t.options.link}},[t._v(" "+t._s(t.options.headline||" ")+" "),t.options.min?e("abbr",{attrs:{title:t.$t("section.required")}},[t._v("*")]):t._e()]),e("k-button-group",{attrs:{buttons:t.buttons}})],1),t.error?e("k-box",{attrs:{theme:"negative"}},[e("k-text",{attrs:{size:"small"}},[e("strong",[t._v(" "+t._s(t.$t("error.section.notLoaded",{name:t.name}))+": ")]),t._v(" "+t._s(t.error)+" ")])],1):[e("k-dropzone",{attrs:{disabled:!t.canDrop},on:{drop:t.onDrop}},[t.searching&&t.options.search?e("k-input",{staticClass:"k-models-section-search",attrs:{autofocus:!0,placeholder:t.$t("search")+" …",type:"text"},on:{keydown:function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"esc",27,e.key,["Esc","Escape"])?null:t.onSearchToggle.apply(null,arguments)}},model:{value:t.searchterm,callback:function(e){t.searchterm=e},expression:"searchterm"}}):t._e(),e("k-collection",t._g(t._b({attrs:{"data-invalid":t.isInvalid},on:{action:t.onAction,change:t.onChange,sort:t.onSort,paginate:t.onPaginate}},"k-collection",t.collection,!1),t.canAdd?{empty:t.onAdd}:{}))],1),e("k-upload",{ref:"upload",on:{success:t.onUpload,error:t.reload}})]],2):t._e()}),[],!1,null,null,null,null).exports;var Tn=Mt({extends:An,computed:{addIcon:()=>"upload",canAdd(){return this.$permissions.files.create&&!1!==this.options.upload},canDrop(){return!1!==this.canAdd},emptyProps(){return{icon:"image",text:this.$t("files.empty")}},items(){return this.data.map((t=>(t.sortable=this.options.sortable,t.column=this.column,t.options=this.$dropdown(t.link,{query:{view:"list",update:this.options.sortable,delete:this.data.length>this.options.min}}),t.data={"data-id":t.id,"data-template":t.template},t)))},type:()=>"files",uploadProps(){return{...this.options.upload,url:this.$urls.api+"/"+this.options.upload.api}}},created(){this.load(),this.$events.$on("model.update",this.reload),this.$events.$on("file.sort",this.reload)},destroyed(){this.$events.$off("model.update",this.reload),this.$events.$off("file.sort",this.reload)},methods:{onAction(t,e){"replace"===t&&this.replace(e)},onAdd(){this.canAdd&&this.$refs.upload.open(this.uploadProps)},onDrop(t){this.canAdd&&this.$refs.upload.drop(t,this.uploadProps)},async onSort(t){if(!1===this.options.sortable)return!1;this.isProcessing=!0;try{await this.$api.patch(this.options.apiUrl+"/files/sort",{files:t.map((t=>t.id)),index:this.pagination.offset}),this.$store.dispatch("notification/success",":)"),this.$events.$emit("file.sort")}catch(e){this.reload(),this.$store.dispatch("notification/error",e.message)}finally{this.isProcessing=!1}},onUpload(){this.$events.$emit("file.create"),this.$events.$emit("model.update"),this.$store.dispatch("notification/success",":)")},replace(t){this.$refs.upload.open({url:this.$urls.api+"/"+t.link,accept:"."+t.extension+","+t.mime,multiple:!1})}}},null,null,!1,null,null,null,null).exports;var In=Mt({mixins:[Tt],data:()=>({headline:null,text:null,theme:null}),async created(){const t=await this.load();this.headline=t.headline,this.text=t.text,this.theme=t.theme||"info"}},(function(){var t=this,e=t._self._c;return e("section",{staticClass:"k-info-section"},[e("k-headline",{staticClass:"k-info-section-headline"},[t._v(" "+t._s(t.headline)+" ")]),e("k-box",{attrs:{theme:t.theme}},[e("k-text",{domProps:{innerHTML:t._s(t.text)}})],1)],1)}),[],!1,null,null,null,null).exports;var Mn=Mt({extends:An,computed:{canAdd(){return this.options.add&&this.$permissions.pages.create},items(){return this.data.map((t=>{const e=!1!==t.permissions.changeStatus;return t.flag={status:t.status,tooltip:this.$t("page.status"),disabled:!e,click:()=>this.$dialog(t.link+"/changeStatus")},t.sortable=t.permissions.sort&&this.options.sortable,t.deletable=this.data.length>this.options.min,t.column=this.column,t.options=this.$dropdown(t.link,{query:{view:"list",delete:t.deletable,sort:t.sortable}}),t.data={"data-id":t.id,"data-status":t.status,"data-template":t.template},t}))}},created(){this.load(),this.$events.$on("page.changeStatus",this.reload),this.$events.$on("page.sort",this.reload)},destroyed(){this.$events.$off("page.changeStatus",this.reload),this.$events.$off("page.sort",this.reload)},methods:{onAdd(){this.canAdd&&this.$dialog("pages/create",{query:{parent:this.options.link||this.parent,view:this.parent,section:this.name}})},async onChange(t){let e=null;if(t.added&&(e="added"),t.moved&&(e="moved"),e){this.isProcessing=!0;const i=t[e].element,n=t[e].newIndex+1+this.pagination.offset;try{await this.$api.pages.changeStatus(i.id,"listed",n),this.$store.dispatch("notification/success",":)"),this.$events.$emit("page.sort",i)}catch(s){this.$store.dispatch("notification/error",{message:s.message,details:s.details}),await this.reload()}finally{this.isProcessing=!1}}}}},null,null,!1,null,null,null,null).exports;var Ln=Mt({mixins:[Tt],data:()=>({isLoading:!0,headline:null,reports:null,size:null}),async created(){const t=await this.load();this.isLoading=!1,this.headline=t.headline,this.reports=t.reports,this.size=t.size},methods:{}},(function(){var t=this,e=t._self._c;return!1===t.isLoading?e("section",{staticClass:"k-stats-section"},[e("header",{staticClass:"k-section-header"},[e("k-headline",[t._v(" "+t._s(t.headline)+" ")])],1),t.reports.length>0?e("k-stats",{attrs:{reports:t.reports,size:t.size}}):e("k-empty",{attrs:{icon:"chart"}},[t._v(" "+t._s(t.empty||t.$t("stats.empty")))])],1):t._e()}),[],!1,null,null,null,null).exports;t.component("k-sections",Cn),t.component("k-fields-section",On),t.component("k-files-section",Tn),t.component("k-info-section",In),t.component("k-pages-section",Mn),t.component("k-stats-section",Ln);var En=Mt({props:{blueprint:String,next:Object,prev:Object,permissions:{type:Object,default:()=>({})},lock:{type:[Boolean,Object]},model:{type:Object,default:()=>({})},tab:{type:Object,default:()=>({columns:[]})},tabs:{type:Array,default:()=>[]}},computed:{id(){return this.model.link},isLocked(){var t;return"lock"===(null==(t=this.lock)?void 0:t.state)},protectedFields:()=>[]},watch:{"model.id":{handler(){this.content()},immediate:!0}},created(){this.$events.$on("model.reload",this.reload),this.$events.$on("keydown.left",this.toPrev),this.$events.$on("keydown.right",this.toNext)},destroyed(){this.$events.$off("model.reload",this.reload),this.$events.$off("keydown.left",this.toPrev),this.$events.$off("keydown.right",this.toNext)},methods:{content(){this.$store.dispatch("content/create",{id:this.id,api:this.id,content:this.model.content,ignore:this.protectedFields})},async reload(){await this.$reload(),this.content()},toPrev(t){this.prev&&"body"===t.target.localName&&this.$go(this.prev.link)},toNext(t){this.next&&"body"===t.target.localName&&this.$go(this.next.link)}}},null,null,!1,null,null,null,null).exports;var jn=Mt({extends:En,computed:{avatarOptions(){return[{icon:"upload",text:this.$t("change"),click:()=>this.$refs.upload.open()},{icon:"trash",text:this.$t("delete"),click:this.deleteAvatar}]},buttons(){return[{icon:"email",text:`${this.$t("email")}: ${this.model.email}`,disabled:!this.permissions.changeEmail||this.isLocked,click:()=>this.$dialog(this.id+"/changeEmail")},{icon:"bolt",text:`${this.$t("role")}: ${this.model.role}`,disabled:!this.permissions.changeRole||this.isLocked,click:()=>this.$dialog(this.id+"/changeRole")},{icon:"globe",text:`${this.$t("language")}: ${this.model.language}`,disabled:!this.permissions.changeLanguage||this.isLocked,click:()=>this.$dialog(this.id+"/changeLanguage")}]},uploadApi(){return this.$urls.api+"/"+this.id+"/avatar"}},methods:{async deleteAvatar(){await this.$api.users.deleteAvatar(this.model.id),this.avatar=null,this.$store.dispatch("notification/success",":)"),this.$reload()},onAvatar(){this.model.avatar?this.$refs.picture.toggle():this.$refs.upload.open()},uploadedAvatar(){this.$store.dispatch("notification/success",":)"),this.$reload()}}},(function(){var t=this,e=t._self._c;return e("k-inside",{scopedSlots:t._u([{key:"footer",fn:function(){return[e("k-form-buttons",{attrs:{lock:t.lock}})]},proxy:!0}])},[e("div",{staticClass:"k-user-view",attrs:{"data-locked":t.isLocked,"data-id":t.model.id,"data-template":t.blueprint}},[e("div",{staticClass:"k-user-profile"},[e("k-view",[e("k-dropdown",[e("k-button",{staticClass:"k-user-view-image",attrs:{tooltip:t.$t("avatar"),disabled:t.isLocked},on:{click:t.onAvatar}},[t.model.avatar?e("k-image",{attrs:{cover:!0,src:t.model.avatar,ratio:"1/1"}}):e("k-icon",{attrs:{back:"gray-900",color:"gray-200",type:"user"}})],1),t.model.avatar?e("k-dropdown-content",{ref:"picture",attrs:{options:t.avatarOptions}}):t._e()],1),e("k-button-group",{attrs:{buttons:t.buttons}})],1)],1),e("k-view",[e("k-header",{attrs:{editable:t.permissions.changeName&&!t.isLocked,tab:t.tab.name,tabs:t.tabs},on:{edit:function(e){return t.$dialog(t.id+"/changeName")}},scopedSlots:t._u([{key:"left",fn:function(){return[e("k-button-group",[e("k-dropdown",{staticClass:"k-user-view-options"},[e("k-button",{attrs:{disabled:t.isLocked,text:t.$t("settings"),icon:"cog"},on:{click:function(e){return t.$refs.settings.toggle()}}}),e("k-dropdown-content",{ref:"settings",attrs:{options:t.$dropdown(t.id)}})],1),e("k-languages-dropdown")],1)]},proxy:!0},{key:"right",fn:function(){return[t.model.account?t._e():e("k-prev-next",{attrs:{prev:t.prev,next:t.next}})]},proxy:!0}])},[t.model.name&&0!==t.model.name.length?[t._v(" "+t._s(t.model.name)+" ")]:e("span",{staticClass:"k-user-name-placeholder"},[t._v(" "+t._s(t.$t("name"))+" … ")])],2),e("k-sections",{attrs:{blueprint:t.blueprint,empty:t.$t("user.blueprint",{blueprint:t.$esc(t.blueprint)}),lock:t.lock,parent:t.id,tab:t.tab}}),e("k-upload",{ref:"upload",attrs:{url:t.uploadApi,multiple:!1,accept:"image/*"},on:{success:t.uploadedAvatar}})],1)],1)])}),[],!1,null,null,null,null).exports;var Bn=Mt({extends:jn,prevnext:!1},null,null,!1,null,null,null,null).exports;var Dn=Mt({props:{error:String,layout:String}},(function(){var t=this,e=t._self._c;return e(`k-${t.layout}`,{tag:"component"},[e("k-view",{staticClass:"k-error-view"},[e("div",{staticClass:"k-error-view-content"},[e("k-text",[e("p",[e("k-icon",{staticClass:"k-error-view-icon",attrs:{type:"alert"}})],1),t._t("default",(function(){return[e("p",[t._v(" "+t._s(t.error)+" ")])]}))],2)],1)])],1)}),[],!1,null,null,null,null).exports;var Pn=Mt({extends:En,props:{preview:Object},methods:{action(t){if("replace"===t)this.$refs.upload.open({url:this.$urls.api+"/"+this.id,accept:"."+this.model.extension+","+this.model.mime,multiple:!1})},onUpload(){this.$store.dispatch("notification/success",":)"),this.$reload()}}},(function(){var t=this,e=t._self._c;return e("k-inside",{scopedSlots:t._u([{key:"footer",fn:function(){return[e("k-form-buttons",{attrs:{lock:t.lock}})]},proxy:!0}])},[e("div",{staticClass:"k-file-view",attrs:{"data-locked":t.isLocked,"data-id":t.model.id,"data-template":t.blueprint}},[e("k-file-preview",t._b({},"k-file-preview",t.preview,!1)),e("k-view",{staticClass:"k-file-content"},[e("k-header",{attrs:{editable:t.permissions.changeName&&!t.isLocked,tab:t.tab.name,tabs:t.tabs},on:{edit:function(e){return t.$dialog(t.id+"/changeName")}},scopedSlots:t._u([{key:"left",fn:function(){return[e("k-button-group",[e("k-button",{staticClass:"k-file-view-options",attrs:{link:t.preview.url,responsive:!0,text:t.$t("open"),icon:"open",target:"_blank"}}),e("k-dropdown",{staticClass:"k-file-view-options"},[e("k-button",{attrs:{disabled:t.isLocked,responsive:!0,text:t.$t("settings"),icon:"cog"},on:{click:function(e){return t.$refs.settings.toggle()}}}),e("k-dropdown-content",{ref:"settings",attrs:{options:t.$dropdown(t.id)},on:{action:t.action}})],1),e("k-languages-dropdown")],1)]},proxy:!0},{key:"right",fn:function(){return[e("k-prev-next",{attrs:{prev:t.prev,next:t.next}})]},proxy:!0}])},[t._v(" "+t._s(t.model.filename)+" ")]),e("k-sections",{attrs:{blueprint:t.blueprint,empty:t.$t("file.blueprint",{blueprint:t.$esc(t.blueprint)}),lock:t.lock,parent:t.id,tab:t.tab}}),e("k-upload",{ref:"upload",on:{success:t.onUpload}})],1)],1)])}),[],!1,null,null,null,null).exports;var Nn=Mt({props:{isInstallable:Boolean,isInstalled:Boolean,isOk:Boolean,requirements:Object,translations:Array},data(){return{user:{name:"",email:"",language:this.$translation.code,password:"",role:"admin"}}},computed:{fields(){return{email:{label:this.$t("email"),type:"email",link:!1,autofocus:!0,required:!0},password:{label:this.$t("password"),type:"password",placeholder:this.$t("password")+" …",required:!0},language:{label:this.$t("language"),type:"select",options:this.translations,icon:"globe",empty:!1,required:!0}}},isReady(){return this.isOk&&this.isInstallable},isComplete(){return this.isOk&&this.isInstalled}},methods:{async install(){try{await this.$api.system.install(this.user),await this.$reload({globals:["$system","$translation"]}),this.$store.dispatch("notification/success",this.$t("welcome")+"!")}catch(t){this.$store.dispatch("notification/error",t)}}}},(function(){var t=this,e=t._self._c;return e("k-panel",[e("k-view",{staticClass:"k-installation-view",attrs:{align:"center"}},[t.isComplete?e("k-text",[e("k-headline",[t._v(t._s(t.$t("installation.completed")))]),e("k-link",{attrs:{to:"/login"}},[t._v(" "+t._s(t.$t("login"))+" ")])],1):t.isReady?e("form",{on:{submit:function(e){return e.preventDefault(),t.install.apply(null,arguments)}}},[e("h1",{staticClass:"sr-only"},[t._v(" "+t._s(t.$t("installation"))+" ")]),e("k-fieldset",{attrs:{fields:t.fields,novalidate:!0},model:{value:t.user,callback:function(e){t.user=e},expression:"user"}}),e("k-button",{attrs:{text:t.$t("install"),type:"submit",icon:"check"}})],1):e("div",[e("k-headline",[t._v(" "+t._s(t.$t("installation.issues.headline"))+" ")]),e("ul",{staticClass:"k-installation-issues"},[!1===t.isInstallable?e("li",[e("k-icon",{attrs:{type:"alert"}}),e("span",{domProps:{innerHTML:t._s(t.$t("installation.disabled"))}})],1):t._e(),!1===t.requirements.php?e("li",[e("k-icon",{attrs:{type:"alert"}}),e("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.php"))}})],1):t._e(),!1===t.requirements.server?e("li",[e("k-icon",{attrs:{type:"alert"}}),e("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.server"))}})],1):t._e(),!1===t.requirements.mbstring?e("li",[e("k-icon",{attrs:{type:"alert"}}),e("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.mbstring"))}})],1):t._e(),!1===t.requirements.curl?e("li",[e("k-icon",{attrs:{type:"alert"}}),e("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.curl"))}})],1):t._e(),!1===t.requirements.accounts?e("li",[e("k-icon",{attrs:{type:"alert"}}),e("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.accounts"))}})],1):t._e(),!1===t.requirements.content?e("li",[e("k-icon",{attrs:{type:"alert"}}),e("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.content"))}})],1):t._e(),!1===t.requirements.media?e("li",[e("k-icon",{attrs:{type:"alert"}}),e("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.media"))}})],1):t._e(),!1===t.requirements.sessions?e("li",[e("k-icon",{attrs:{type:"alert"}}),e("span",{domProps:{innerHTML:t._s(t.$t("installation.issues.sessions"))}})],1):t._e()]),e("k-button",{attrs:{text:t.$t("retry"),icon:"refresh"},on:{click:t.$reload}})],1)],1)],1)}),[],!1,null,null,null,null).exports;var qn=Mt({props:{languages:{type:Array,default:()=>[]}},computed:{languagesCollection(){return this.languages.map((t=>({...t,image:{back:"black",color:"gray",icon:"globe"},link:()=>{this.$dialog(`languages/${t.id}/update`)},options:[{icon:"edit",text:this.$t("edit"),click(){this.$dialog(`languages/${t.id}/update`)}},{icon:"trash",text:this.$t("delete"),disabled:t.default&&1!==this.languages.length,click(){this.$dialog(`languages/${t.id}/delete`)}}]})))},primaryLanguage(){return this.languagesCollection.filter((t=>t.default))},secondaryLanguages(){return this.languagesCollection.filter((t=>!1===t.default))}}},(function(){var t=this,e=t._self._c;return e("k-inside",[e("k-view",{staticClass:"k-languages-view"},[e("k-header",[t._v(" "+t._s(t.$t("view.languages"))+" "),e("k-button-group",{attrs:{slot:"left"},slot:"left"},[e("k-button",{attrs:{text:t.$t("language.create"),icon:"add"},on:{click:function(e){return t.$dialog("languages/create")}}})],1)],1),e("section",{staticClass:"k-languages"},[t.languages.length>0?[e("section",{staticClass:"k-languages-view-section"},[e("header",{staticClass:"k-languages-view-section-header"},[e("k-headline",[t._v(t._s(t.$t("languages.default")))])],1),e("k-collection",{attrs:{items:t.primaryLanguage}})],1),e("section",{staticClass:"k-languages-view-section"},[e("header",{staticClass:"k-languages-view-section-header"},[e("k-headline",[t._v(t._s(t.$t("languages.secondary")))])],1),t.secondaryLanguages.length?e("k-collection",{attrs:{items:t.secondaryLanguages}}):e("k-empty",{attrs:{icon:"globe"},on:{click:function(e){return t.$dialog("languages/create")}}},[t._v(" "+t._s(t.$t("languages.secondary.empty"))+" ")])],1)]:0===t.languages.length?[e("k-empty",{attrs:{icon:"globe"},on:{click:function(e){return t.$dialog("languages/create")}}},[t._v(" "+t._s(t.$t("languages.empty"))+" ")])]:t._e()],2)],1)],1)}),[],!1,null,null,null,null).exports;var Fn=Mt({components:{"k-login-plugin":window.panel.plugins.login||he},props:{methods:Array,pending:Object},computed:{form(){return this.pending.email?"code":this.$user?null:"login"}},created(){this.$store.dispatch("content/clear")}},(function(){var t=this,e=t._self._c;return e("k-panel",["login"===t.form?e("k-view",{staticClass:"k-login-view",attrs:{align:"center"}},[e("k-login-plugin",{attrs:{methods:t.methods}})],1):"code"===t.form?e("k-view",{staticClass:"k-login-code-view",attrs:{align:"center"}},[e("k-login-code",t._b({},"k-login-code",t.$props,!1))],1):t._e()],1)}),[],!1,null,null,null,null).exports;var Rn=Mt({extends:En,props:{status:Object},computed:{protectedFields:()=>["title"]}},(function(){var t=this,e=t._self._c;return e("k-inside",{scopedSlots:t._u([{key:"footer",fn:function(){return[e("k-form-buttons",{attrs:{lock:t.lock}})]},proxy:!0}])},[e("k-view",{staticClass:"k-page-view",attrs:{"data-locked":t.isLocked,"data-id":t.model.id,"data-template":t.blueprint}},[e("k-header",{attrs:{editable:t.permissions.changeTitle&&!t.isLocked,tab:t.tab.name,tabs:t.tabs},on:{edit:function(e){return t.$dialog(t.id+"/changeTitle")}},scopedSlots:t._u([{key:"left",fn:function(){return[e("k-button-group",[t.permissions.preview&&t.model.previewUrl?e("k-button",{staticClass:"k-page-view-preview",attrs:{link:t.model.previewUrl,responsive:!0,text:t.$t("open"),icon:"open",target:"_blank"}}):t._e(),t.status?e("k-status-icon",{attrs:{status:t.model.status,disabled:!t.permissions.changeStatus||t.isLocked,responsive:!0,text:t.status.label},on:{click:function(e){return t.$dialog(t.id+"/changeStatus")}}}):t._e(),e("k-dropdown",{staticClass:"k-page-view-options"},[e("k-button",{attrs:{disabled:!0===t.isLocked,responsive:!0,text:t.$t("settings"),icon:"cog"},on:{click:function(e){return t.$refs.settings.toggle()}}}),e("k-dropdown-content",{ref:"settings",attrs:{options:t.$dropdown(t.id)}})],1),e("k-languages-dropdown")],1)]},proxy:!0},{key:"right",fn:function(){return[t.model.id?e("k-prev-next",{attrs:{prev:t.prev,next:t.next}}):t._e()]},proxy:!0}])},[t._v(" "+t._s(t.model.title)+" ")]),e("k-sections",{attrs:{blueprint:t.blueprint,empty:t.$t("page.blueprint",{blueprint:t.$esc(t.blueprint)}),lock:t.lock,parent:t.id,tab:t.tab}})],1)],1)}),[],!1,null,null,null,null).exports;var zn=Mt({props:{id:String},computed:{view(){return"k-"+this.id+"-plugin-view"}}},(function(){var t=this._self._c;return t("k-inside",[t(this.view,{tag:"component"})],1)}),[],!1,null,null,null,null).exports;var Yn=Mt({data:()=>({isLoading:!1,issue:"",values:{password:null,passwordConfirmation:null}}),computed:{fields(){return{password:{autofocus:!0,label:this.$t("user.changePassword.new"),icon:"key",type:"password"},passwordConfirmation:{label:this.$t("user.changePassword.new.confirm"),icon:"key",type:"password"}}}},mounted(){this.$store.dispatch("title",this.$t("view.resetPassword"))},methods:{async submit(){if(!this.values.password||this.values.password.length<8)return this.issue=this.$t("error.user.password.invalid"),!1;if(this.values.password!==this.values.passwordConfirmation)return this.issue=this.$t("error.user.password.notSame"),!1;this.isLoading=!0;try{await this.$api.users.changePassword(this.$user.id,this.values.password),this.$store.dispatch("notification/success",":)"),this.$go("/")}catch(t){this.issue=t.message}finally{this.isLoading=!1}}}},(function(){var t=this,e=t._self._c;return e("k-inside",[e("k-view",{staticClass:"k-password-reset-view",attrs:{align:"center"}},[e("k-form",{attrs:{fields:t.fields,"submit-button":t.$t("change")},on:{submit:t.submit},scopedSlots:t._u([{key:"header",fn:function(){return[e("h1",{staticClass:"sr-only"},[t._v(" "+t._s(t.$t("view.resetPassword"))+" ")]),t.issue?e("k-login-alert",{on:{click:function(e){t.issue=null}}},[t._v(" "+t._s(t.issue)+" ")]):t._e(),e("k-user-info",{attrs:{user:t.$user}})]},proxy:!0},{key:"footer",fn:function(){return[e("div",{staticClass:"k-login-buttons"},[e("k-button",{staticClass:"k-login-button",attrs:{icon:"check",type:"submit"}},[t._v(" "+t._s(t.$t("change"))+" "),t.isLoading?[t._v(" … ")]:t._e()],2)],1)]},proxy:!0}]),model:{value:t.values,callback:function(e){t.values=e},expression:"values"}})],1)],1)}),[],!1,null,null,null,null).exports;var Hn=Mt({extends:En,computed:{protectedFields:()=>["title"]}},(function(){var t=this,e=t._self._c;return e("k-inside",{scopedSlots:t._u([{key:"footer",fn:function(){return[e("k-form-buttons",{attrs:{lock:t.lock}})]},proxy:!0}])},[e("k-view",{staticClass:"k-site-view",attrs:{"data-locked":t.isLocked,"data-id":"/","data-template":"site"}},[e("k-header",{attrs:{editable:t.permissions.changeTitle&&!t.isLocked,tabs:t.tabs,tab:t.tab.name},on:{edit:function(e){return t.$dialog("site/changeTitle")}},scopedSlots:t._u([{key:"left",fn:function(){return[e("k-button-group",[e("k-button",{staticClass:"k-site-view-preview",attrs:{link:t.model.previewUrl,responsive:!0,text:t.$t("open"),icon:"open",target:"_blank"}}),e("k-languages-dropdown")],1)]},proxy:!0}])},[t._v(" "+t._s(t.model.title)+" ")]),e("k-sections",{attrs:{blueprint:t.blueprint,empty:t.$t("site.blueprint"),lock:t.lock,tab:t.tab,parent:"site"},on:{submit:function(e){return t.$emit("submit",e)}}})],1)],1)}),[],!1,null,null,null,null).exports;var Un=Mt({props:{debug:Boolean,license:String,php:String,plugins:Array,server:String,https:Boolean,urls:Object,version:String},data:()=>({security:[]}),computed:{environment(){return[{label:this.$t("license"),value:this.license?"Kirby 3":this.$t("license.unregistered.label"),theme:this.license?null:"negative",click:this.license?()=>this.$dialog("license"):()=>this.$dialog("registration")},{label:this.$t("version"),value:this.version,link:"https://github.com/getkirby/kirby/releases/tag/"+this.version},{label:"PHP",value:this.php},{label:this.$t("server"),value:this.server||"?"}]}},async created(){console.info("Running system health checks for the Panel system view; failed requests in the following console output are expected behavior.");let t=(Promise.allSettled||Promise.all).bind(Promise);await t([this.check("content"),this.check("debug"),this.check("git"),this.check("https"),this.check("kirby"),this.check("site")]),console.info("System health checks ended.")},methods:{async check(t){switch(t){case"debug":!0===this.debug&&this.securityIssue(t);break;case"https":!0!==this.https&&this.securityIssue(t);break;default:const e=this.urls[t];if(!e)return!1;!0===await this.isAccessible(e)&&this.securityIssue(t)}},securityIssue(t){this.security.push({image:{back:"var(--color-red-200)",icon:"alert",color:"var(--color-red)"},id:t,text:this.$t("system.issues."+t),link:"https://getkirby.com/security/"+t})},isAccessible:async t=>(await fetch(t,{cache:"no-store"})).status<400,retry(){this.$go(window.location.href)}}},(function(){var t=this,e=t._self._c;return e("k-inside",[e("k-view",{staticClass:"k-system-view"},[e("k-header",[t._v(" "+t._s(t.$t("view.system"))+" ")]),e("section",{staticClass:"k-system-view-section"},[e("header",{staticClass:"k-system-view-section-header"},[e("k-headline",[t._v(t._s(t.$t("environment")))])],1),e("k-stats",{staticClass:"k-system-info",attrs:{reports:t.environment,size:"medium"}})],1),t.security.length?e("section",{staticClass:"k-system-view-section"},[e("header",{staticClass:"k-system-view-section-header"},[e("k-headline",[t._v(t._s(t.$t("security")))]),e("k-button",{attrs:{tooltip:t.$t("retry"),icon:"refresh"},on:{click:t.retry}})],1),e("k-items",{attrs:{items:t.security}})],1):t._e(),t.plugins.length?e("section",{staticClass:"k-system-view-section"},[e("header",{staticClass:"k-system-view-section-header"},[e("k-headline",{attrs:{link:"https://getkirby.com/plugins"}},[t._v(" "+t._s(t.$t("plugins"))+" ")])],1),e("k-table",{attrs:{index:!1,columns:{name:{label:t.$t("name"),type:"url",mobile:!0},author:{label:t.$t("author")},license:{label:t.$t("license")},version:{label:t.$t("version"),width:"8rem",mobile:!0}},rows:t.plugins}})],1):t._e()],1)],1)}),[],!1,null,null,null,null).exports;var Kn=Mt({props:{role:Object,roles:Array,search:String,title:String,users:Object},computed:{items(){return this.users.data.map((t=>(t.options=this.$dropdown(t.link),t)))}},methods:{paginate(t){this.$reload({query:{page:t.page}})}}},(function(){var t=this,e=t._self._c;return e("k-inside",[e("k-view",{staticClass:"k-users-view"},[e("k-header",{scopedSlots:t._u([{key:"left",fn:function(){return[e("k-button-group",{attrs:{buttons:[{disabled:!1===t.$permissions.users.create,text:t.$t("user.create"),icon:"add",click:()=>t.$dialog("users/create")}]}})]},proxy:!0},{key:"right",fn:function(){return[e("k-button-group",[e("k-dropdown",[e("k-button",{attrs:{responsive:!0,text:`${t.$t("role")}: ${t.role?t.role.title:t.$t("role.all")}`,icon:"funnel"},on:{click:function(e){return t.$refs.roles.toggle()}}}),e("k-dropdown-content",{ref:"roles",attrs:{align:"right"}},[e("k-dropdown-item",{attrs:{icon:"bolt",link:"/users"}},[t._v(" "+t._s(t.$t("role.all"))+" ")]),e("hr"),t._l(t.roles,(function(s){return e("k-dropdown-item",{key:s.id,attrs:{link:"/users/?role="+s.id,icon:"bolt"}},[t._v(" "+t._s(s.title)+" ")])}))],2)],1)],1)]},proxy:!0}])},[t._v(" "+t._s(t.$t("view.users"))+" ")]),t.users.data.length>0?[e("k-collection",{attrs:{items:t.items,pagination:t.users.pagination},on:{paginate:t.paginate}})]:0===t.users.pagination.total?[e("k-empty",{attrs:{icon:"users"}},[t._v(" "+t._s(t.$t("role.empty"))+" ")])]:t._e()],2)],1)}),[],!1,null,null,null,null).exports;var Jn=Mt({computed:{placeholder(){return this.field("code",{}).placeholder},languages(){return this.field("language",{options:[]}).options}},methods:{focus(){this.$refs.code.focus()}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-block-type-code-editor"},[e("k-input",{ref:"code",attrs:{buttons:!1,placeholder:t.placeholder,spellcheck:!1,value:t.content.code,type:"textarea"},on:{input:function(e){return t.update({code:e})}}}),t.languages.length?e("div",{staticClass:"k-block-type-code-editor-language"},[e("k-icon",{attrs:{type:"code"}}),e("k-input",{ref:"language",attrs:{empty:!1,options:t.languages,value:t.content.language,type:"select"},on:{input:function(e){return t.update({language:e})}}})],1):t._e()],1)}),[],!1,null,null,null,null).exports,Gn=Object.freeze(Object.defineProperty({__proto__:null,default:Jn},Symbol.toStringTag,{value:"Module"}));var Vn=Mt({},(function(){var t=this;return(0,t._self._c)("k-block-title",{attrs:{content:t.content,fieldset:t.fieldset},on:{dblclick:function(e){return t.$emit("open")}}})}),[],!1,null,null,null,null).exports,Wn=Object.freeze(Object.defineProperty({__proto__:null,default:Vn},Symbol.toStringTag,{value:"Module"}));var Xn=Mt({},(function(){var t=this,e=t._self._c;return e("ul",{on:{dblclick:t.open}},[0===t.content.images.length?[e("li"),e("li"),e("li"),e("li"),e("li")]:t._l(t.content.images,(function(t){return e("li",{key:t.id},[e("img",{attrs:{src:t.url,srcset:t.image.srcset,alt:t.alt}})])}))],2)}),[],!1,null,null,null,null).exports,Zn=Object.freeze(Object.defineProperty({__proto__:null,default:Xn},Symbol.toStringTag,{value:"Module"}));var Qn=Mt({computed:{textField(){return this.field("text",{marks:!0})}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-block-type-heading-input",attrs:{"data-level":t.content.level}},[e("k-writer",{ref:"input",attrs:{inline:!0,marks:t.textField.marks,placeholder:t.textField.placeholder,value:t.content.text},on:{input:function(e){return t.update({text:e})}}})],1)}),[],!1,null,null,null,null).exports,to=Object.freeze(Object.defineProperty({__proto__:null,default:Qn},Symbol.toStringTag,{value:"Module"}));var eo=Mt({computed:{captionMarks(){return this.field("caption",{marks:!0}).marks},crop(){return this.content.crop||!1},src(){var t;return"web"===this.content.location?this.content.src:!!(null==(t=this.content.image[0])?void 0:t.url)&&this.content.image[0].url},ratio(){return this.content.ratio||!1}}},(function(){var t=this,e=t._self._c;return e("k-block-figure",{attrs:{caption:t.content.caption,"caption-marks":t.captionMarks,"empty-text":t.$t("field.blocks.image.placeholder")+" …","is-empty":!t.src,"empty-icon":"image"},on:{open:t.open,update:t.update}},[t.src?[t.ratio?e("k-aspect-ratio",{attrs:{ratio:t.ratio,cover:t.crop}},[e("img",{attrs:{alt:t.content.alt,src:t.src}})]):e("img",{staticClass:"k-block-type-image-auto",attrs:{alt:t.content.alt,src:t.src}})]:t._e()],2)}),[],!1,null,null,null,null).exports,so=Object.freeze(Object.defineProperty({__proto__:null,default:eo},Symbol.toStringTag,{value:"Module"}));var io=Mt({},(function(){return this._self._c,this._m(0)}),[function(){var t=this._self._c;return t("div",[t("hr")])}],!1,null,null,null,null).exports,no=Object.freeze(Object.defineProperty({__proto__:null,default:io},Symbol.toStringTag,{value:"Module"}));var oo=Mt({computed:{marks(){return this.field("text",{}).marks}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this;return(0,t._self._c)("k-input",{ref:"input",staticClass:"k-block-type-list-input",attrs:{marks:t.marks,value:t.content.text,type:"list"},on:{input:function(e){return t.update({text:e})}}})}),[],!1,null,null,null,null).exports,ro=Object.freeze(Object.defineProperty({__proto__:null,default:oo},Symbol.toStringTag,{value:"Module"}));var lo=Mt({computed:{placeholder(){return this.field("text",{}).placeholder}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this;return(0,t._self._c)("k-input",{ref:"input",staticClass:"k-block-type-markdown-input",attrs:{buttons:!1,placeholder:t.placeholder,spellcheck:!1,value:t.content.text,type:"textarea"},on:{input:function(e){return t.update({text:e})}}})}),[],!1,null,null,null,null).exports,ao=Object.freeze(Object.defineProperty({__proto__:null,default:lo},Symbol.toStringTag,{value:"Module"}));var uo=Mt({computed:{citationField(){return this.field("citation",{})},textField(){return this.field("text",{})}},methods:{focus(){this.$refs.text.focus()}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-block-type-quote-editor"},[e("k-writer",{ref:"text",staticClass:"k-block-type-quote-text",attrs:{inline:!0,marks:t.textField.marks,placeholder:t.textField.placeholder,value:t.content.text},on:{input:function(e){return t.update({text:e})}}}),e("k-writer",{ref:"citation",staticClass:"k-block-type-quote-citation",attrs:{inline:!0,marks:t.citationField.marks,placeholder:t.citationField.placeholder,value:t.content.citation},on:{input:function(e){return t.update({citation:e})}}})],1)}),[],!1,null,null,null,null).exports,co=Object.freeze(Object.defineProperty({__proto__:null,default:uo},Symbol.toStringTag,{value:"Module"}));var po=Mt({inheritAttrs:!1,computed:{columns(){return this.table.columns||this.fields},fields(){return this.table.fields||{}},rows(){return this.content.rows||[]},table(){let t=null;for(const e of Object.values(this.fieldset.tabs))e.fields.rows&&(t=e.fields.rows);return t||{}}}},(function(){var t=this;return(0,t._self._c)("k-table",{staticClass:"k-block-type-table-preview",attrs:{columns:t.columns,empty:t.$t("field.structure.empty"),rows:t.rows},nativeOn:{dblclick:function(e){return t.open.apply(null,arguments)}}})}),[],!1,null,null,null,null).exports,ho=Object.freeze(Object.defineProperty({__proto__:null,default:po},Symbol.toStringTag,{value:"Module"}));var mo=Mt({props:{endpoints:Object},computed:{textField(){return this.field("text",{})}},methods:{focus(){this.$refs.input.focus()}}},(function(){var t=this;return(0,t._self._c)("k-writer",{ref:"input",staticClass:"k-block-type-text-input",attrs:{inline:t.textField.inline,marks:t.textField.marks,nodes:t.textField.nodes,placeholder:t.textField.placeholder,value:t.content.text},on:{input:function(e){return t.update({text:e})}}})}),[],!1,null,null,null,null).exports,fo=Object.freeze(Object.defineProperty({__proto__:null,default:mo},Symbol.toStringTag,{value:"Module"}));var go=Mt({computed:{captionMarks(){return this.field("caption",{marks:!0}).marks},video(){return this.$helper.embed.video(this.content.url,!0)}}},(function(){var t=this,e=t._self._c;return e("k-block-figure",{attrs:{caption:t.content.caption,"caption-marks":t.captionMarks,"empty-text":t.$t("field.blocks.video.placeholder")+" …","is-empty":!t.video,"empty-icon":"video"},on:{open:t.open,update:t.update}},[e("k-aspect-ratio",{attrs:{ratio:"16/9"}},[t.video?e("iframe",{attrs:{src:t.video,referrerpolicy:"strict-origin-when-cross-origin"}}):t._e()])],1)}),[],!1,null,null,null,null).exports,ko=Object.freeze(Object.defineProperty({__proto__:null,default:go},Symbol.toStringTag,{value:"Module"}));var bo=Mt({inheritAttrs:!1,props:{attrs:[Array,Object],content:[Array,Object],endpoints:Object,fieldset:Object,id:String,isBatched:Boolean,isFull:Boolean,isHidden:Boolean,isLastInBatch:Boolean,isSelected:Boolean,name:String,next:Object,prev:Object,type:String},data:()=>({skipFocus:!1}),computed:{className(){let t=["k-block-type-"+this.type];return this.fieldset.preview!==this.type&&t.push("k-block-type-"+this.fieldset.preview),!1===this.wysiwyg&&t.push("k-block-type-default"),t},customComponent(){return this.wysiwyg?this.wysiwygComponent:"k-block-type-default"},isEditable(){return!1!==this.fieldset.editable},listeners(){return{...this.$listeners,confirmToRemove:this.confirmToRemove,open:this.open}},tabs(){let t=this.fieldset.tabs;return Object.entries(t).forEach((([e,s])=>{Object.entries(s.fields).forEach((([s])=>{t[e].fields[s].section=this.name,t[e].fields[s].endpoints={field:this.endpoints.field+"/fieldsets/"+this.type+"/fields/"+s,section:this.endpoints.section,model:this.endpoints.model}}))})),t},wysiwyg(){return!1!==this.wysiwygComponent},wysiwygComponent(){if(!1===this.fieldset.preview)return!1;let t;return this.fieldset.preview&&(t="k-block-type-"+this.fieldset.preview,this.$helper.isComponent(t))?t:(t="k-block-type-"+this.type,!!this.$helper.isComponent(t)&&t)}},methods:{close(){this.$refs.drawer.close()},confirmToRemove(){this.$refs.removeDialog.open()},focus(){!0!==this.skipFocus&&("function"==typeof this.$refs.editor.focus?this.$refs.editor.focus():this.$refs.container.focus())},onFocusIn(t){var e,s;(null==(s=null==(e=this.$refs.options)?void 0:e.$el)?void 0:s.contains(t.target))||this.$emit("focus",t)},goTo(t){t&&(this.skipFocus=!0,this.close(),this.$nextTick((()=>{t.$refs.container.focus(),t.open(),this.skipFocus=!1})))},open(){var t;null==(t=this.$refs.drawer)||t.open()},remove(){this.$refs.removeDialog.close(),this.$emit("remove",this.id)}}},(function(){var t=this,e=t._self._c;return e("div",{ref:"container",staticClass:"k-block-container",class:"k-block-container-type-"+t.type,attrs:{"data-batched":t.isBatched,"data-disabled":t.fieldset.disabled,"data-hidden":t.isHidden,"data-id":t.id,"data-last-in-batch":t.isLastInBatch,"data-selected":t.isSelected,"data-translate":t.fieldset.translate,tabindex:"0"},on:{keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"down",40,e.key,["Down","ArrowDown"])?null:e.ctrlKey&&e.shiftKey?(e.preventDefault(),t.$emit("sortDown")):null},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"up",38,e.key,["Up","ArrowUp"])?null:e.ctrlKey&&e.shiftKey?(e.preventDefault(),t.$emit("sortUp")):null}],focus:function(e){return t.$emit("focus")},focusin:t.onFocusIn}},[e("div",{staticClass:"k-block",class:t.className},[e(t.customComponent,t._g(t._b({ref:"editor",tag:"component"},"component",t.$props,!1),t.listeners))],1),e("k-block-options",t._g({ref:"options",attrs:{"is-batched":t.isBatched,"is-editable":t.isEditable,"is-full":t.isFull,"is-hidden":t.isHidden}},t.listeners)),t.isEditable&&!t.isBatched?e("k-form-drawer",{ref:"drawer",staticClass:"k-block-drawer",attrs:{id:t.id,icon:t.fieldset.icon||"box",tabs:t.tabs,title:t.fieldset.name,value:t.content},on:{close:function(e){return t.focus()},input:function(e){return t.$emit("update",e)}},scopedSlots:t._u([{key:"options",fn:function(){return[t.isHidden?e("k-button",{staticClass:"k-drawer-option",attrs:{icon:"hidden"},on:{click:function(e){return t.$emit("show")}}}):t._e(),e("k-button",{staticClass:"k-drawer-option",attrs:{disabled:!t.prev,icon:"angle-left"},on:{click:function(e){return e.preventDefault(),e.stopPropagation(),t.goTo(t.prev)}}}),e("k-button",{staticClass:"k-drawer-option",attrs:{disabled:!t.next,icon:"angle-right"},on:{click:function(e){return e.preventDefault(),e.stopPropagation(),t.goTo(t.next)}}}),e("k-button",{staticClass:"k-drawer-option",attrs:{icon:"trash"},on:{click:function(e){return e.preventDefault(),e.stopPropagation(),t.confirmToRemove.apply(null,arguments)}}})]},proxy:!0}],null,!1,2211169536)}):t._e(),e("k-remove-dialog",{ref:"removeDialog",attrs:{text:t.$t("field.blocks.delete.confirm")},on:{submit:t.remove}})],1)}),[],!1,null,null,null,null).exports;var vo=Mt({components:{"k-block-pasteboard":Mt({inheritAttrs:!1,computed:{shortcut(){return this.$helper.keyboard.metaKey()+"+v"}},methods:{close(){this.$refs.dialog.close()},open(){this.$refs.dialog.open()},onPaste(t){this.$emit("paste",t),this.close()}}},(function(){var t=this,e=t._self._c;return e("k-dialog",{ref:"dialog",staticClass:"k-block-importer",attrs:{"cancel-button":!1,"submit-button":!1,size:"large"}},[e("label",{attrs:{for:"pasteboard"},domProps:{innerHTML:t._s(t.$t("field.blocks.fieldsets.paste",{shortcut:t.shortcut}))}}),e("textarea",{attrs:{id:"pasteboard"},on:{paste:function(e){return e.preventDefault(),t.onPaste.apply(null,arguments)}}})])}),[],!1,null,null,null,null).exports},inheritAttrs:!1,props:{autofocus:Boolean,empty:String,endpoints:Object,fieldsets:Object,fieldsetGroups:Object,group:String,max:{type:Number,default:null},value:{type:Array,default:()=>[]}},data(){return{isMultiSelectKey:!1,batch:[],blocks:this.value,current:null,isFocussed:!1}},computed:{draggableOptions(){return{id:this._uid,handle:".k-sort-handle",list:this.blocks,move:this.move,delay:10,data:{fieldsets:this.fieldsets,isFull:this.isFull},options:{group:this.group}}},hasFieldsets(){return Object.keys(this.fieldsets).length},isEditing(){return this.$store.state.dialog||this.$store.state.drawers.open.length>0},isEmpty(){return 0===this.blocks.length},isFull(){return null!==this.max&&this.blocks.length>=this.max},selected(){return this.current},selectedOrBatched(){return this.batch.length>0?this.batch:this.selected?[this.selected]:[]}},watch:{value(){this.blocks=this.value}},created(){this.$events.$on("blur",this.onBlur),this.$events.$on("copy",this.copy),this.$events.$on("focus",this.onOutsideFocus),this.$events.$on("keydown",this.onKey),this.$events.$on("keyup",this.onKey),this.$events.$on("paste",this.onPaste)},destroyed(){this.$events.$off("blur",this.onBlur),this.$events.$off("copy",this.copy),this.$events.$off("focus",this.onOutsideFocus),this.$events.$off("keydown",this.onKey),this.$events.$off("keyup",this.onKey),this.$events.$off("paste",this.onPaste)},mounted(){!0===this.$props.autofocus&&this.focus()},methods:{append(t,e){if("string"!=typeof t){if(Array.isArray(t)){let s=this.$helper.clone(t).map((t=>(t.id=this.$helper.uuid(),t)));const i=Object.keys(this.fieldsets);if(s=s.filter((t=>i.includes(t.type))),this.max){const t=this.max-this.blocks.length;s=s.slice(0,t)}this.blocks.splice(e,0,...s),this.save()}}else this.add(t,e)},async add(t="text",e){const s=await this.$api.get(this.endpoints.field+"/fieldsets/"+t);this.blocks.splice(e,0,s),this.save(),this.$nextTick((()=>{this.focusOrOpen(s)}))},addToBatch(t){null!==this.selected&&!1===this.batch.includes(this.selected)&&(this.batch.push(this.selected),this.current=null),!1===this.batch.includes(t.id)&&this.batch.push(t.id)},choose(t){if(1===Object.keys(this.fieldsets).length){const e=Object.values(this.fieldsets)[0].type;this.add(e,t)}else this.$refs.selector.open(t)},chooseToConvert(t){this.$refs.selector.open(t,{disabled:[t.type],headline:this.$t("field.blocks.changeType"),event:"convert"})},click(t){this.$emit("click",t)},confirmToRemoveAll(){this.$refs.removeAll.open()},confirmToRemoveSelected(){this.$refs.removeSelected.open()},copy(t){if(!0===this.isEditing)return!1;if(0===this.blocks.length)return!1;if(0===this.selectedOrBatched.length)return!1;if(!0===this.isInputEvent(t))return!1;let e=[];if(this.blocks.forEach((t=>{this.selectedOrBatched.includes(t.id)&&e.push(t)})),0===e.length)return!1;this.$helper.clipboard.write(e,t),t instanceof ClipboardEvent==!1&&(this.batch=this.selectedOrBatched),this.$store.dispatch("notification/success",`${e.length} copied!`)},copyAll(){this.selectAll(),this.copy(),this.deselectAll()},async convert(t,e){var s;const i=this.findIndex(e.id);if(-1===i)return!1;const n=t=>{var e;let s={};for(const i of Object.values(null!=(e=null==t?void 0:t.tabs)?e:{}))s={...s,...i.fields};return s},o=this.blocks[i],r=await this.$api.get(this.endpoints.field+"/fieldsets/"+t),l=this.fieldsets[o.type],a=this.fieldsets[t];if(!a)return!1;let u=r.content;const c=n(a),d=n(l);for(const[p,h]of Object.entries(c)){const t=d[p];(null==t?void 0:t.type)===h.type&&(null==(s=null==o?void 0:o.content)?void 0:s[p])&&(u[p]=o.content[p])}this.blocks[i]={...r,id:o.id,content:u},this.save()},deselectAll(){this.batch=[],this.current=null},async duplicate(t,e){const s={...this.$helper.clone(t),id:this.$helper.uuid()};this.blocks.splice(e+1,0,s),this.save()},fieldset(t){return this.fieldsets[t.type]||{icon:"box",name:t.type,tabs:{content:{fields:{}}},type:t.type}},find(t){return this.blocks.find((e=>e.id===t))},findIndex(t){return this.blocks.findIndex((e=>e.id===t))},focus(t){(null==t?void 0:t.id)&&this.$refs["block-"+t.id]?this.$refs["block-"+t.id][0].focus():this.blocks[0]&&this.focus(this.blocks[0])},focusOrOpen(t){this.fieldsets[t.type].wysiwyg?this.focus(t):this.open(t)},hide(t){this.$set(t,"isHidden",!0),this.save()},isBatched(t){return this.batch.includes(t.id)},isInputEvent(){const t=document.querySelector(":focus");return t&&t.matches("input, textarea, [contenteditable], .k-writer")},isLastInBatch(t){const[e]=this.batch.slice(-1);return e&&t.id===e},isOnlyInstance:()=>1===document.querySelectorAll(".k-blocks").length,isSelected(t){return this.selected&&this.selected===t.id},move(t){if(t.from!==t.to){const e=t.draggedContext.element,s=t.relatedContext.component.componentData||t.relatedContext.component.$parent.componentData;if(!1===Object.keys(s.fieldsets).includes(e.type))return!1;if(!0===s.isFull)return!1}return!0},onBlur(){0===this.batch.length&&(this.isMultiSelectKey=!1)},onKey(t){this.isMultiSelectKey=t.metaKey||t.ctrlKey||t.altKey},onOutsideFocus(t){if("function"==typeof t.target.closest&&t.target.closest(".k-dialog"))return;const e=document.querySelector(".k-overlay:last-of-type");if(!1===this.$el.contains(t.target)&&(!e||!1===e.contains(t.target)))return this.select(null);if(e){const e=this.$el.closest(".k-layout-column");if(!1===(null==e?void 0:e.contains(t.target)))return this.select(null)}},onPaste(t){var e;return!0!==this.isInputEvent(t)&&(!0===this.isEditing?!0===(null==(e=this.$refs.selector)?void 0:e.isOpen())&&this.paste(t):(0!==this.selectedOrBatched.length||!0===this.isOnlyInstance())&&this.paste(t))},open(t){this.$refs["block-"+t.id]&&this.$refs["block-"+t.id][0].open()},async paste(t){const e=this.$helper.clipboard.read(t),s=await this.$api.post(this.endpoints.field+"/paste",{html:e});let i=this.selectedOrBatched[this.selectedOrBatched.length-1],n=this.findIndex(i);-1===n&&(n=this.blocks.length),this.append(s,n+1)},pasteboard(){this.$refs.pasteboard.open()},prevNext(t){if(this.blocks[t]){let e=this.blocks[t];if(this.$refs["block-"+e.id])return this.$refs["block-"+e.id][0]}},remove(t){var e;const s=this.findIndex(t.id);-1!==s&&((null==(e=this.selected)?void 0:e.id)===t.id&&this.select(null),this.$delete(this.blocks,s),this.save())},removeAll(){this.batch=[],this.blocks=[],this.save(),this.$refs.removeAll.close()},removeSelected(){this.batch.forEach((t=>{const e=this.findIndex(t);-1!==e&&this.$delete(this.blocks,e)})),this.deselectAll(),this.save(),this.$refs.removeSelected.close()},save(){this.$emit("input",this.blocks)},select(t,e=null){if(e&&this.isMultiSelectKey&&this.onKey(e),t&&this.isMultiSelectKey)return this.addToBatch(t),void(this.current=null);this.batch=[],this.current=t?t.id:null},selectAll(){this.batch=Object.values(this.blocks).map((t=>t.id))},show(t){this.$set(t,"isHidden",!1),this.save()},sort(t,e,s){if(s<0)return;let i=this.$helper.clone(this.blocks);i.splice(e,1),i.splice(s,0,t),this.blocks=i,this.save(),this.$nextTick((()=>{this.focus(t)}))},update(t,e){const s=this.findIndex(t.id);-1!==s&&Object.entries(e).forEach((([t,e])=>{this.$set(this.blocks[s].content,t,e)})),this.save()}}},(function(){var t=this,e=t._self._c;return e("div",{ref:"wrapper",staticClass:"k-blocks",attrs:{"data-empty":0===t.blocks.length,"data-multi-select-key":t.isMultiSelectKey},on:{focusin:function(e){t.focussed=!0},focusout:function(e){t.focussed=!1}}},[t.hasFieldsets?[e("k-draggable",t._b({staticClass:"k-blocks-list",on:{sort:t.save},scopedSlots:t._u([{key:"footer",fn:function(){return[e("k-empty",{staticClass:"k-blocks-empty",attrs:{icon:"box"},on:{click:function(e){return t.choose(t.blocks.length)}}},[t._v(" "+t._s(t.empty||t.$t("field.blocks.empty"))+" ")])]},proxy:!0}],null,!1,2413899928)},"k-draggable",t.draggableOptions,!1),t._l(t.blocks,(function(s,i){return e("k-block",t._b({key:s.id,ref:"block-"+s.id,refInFor:!0,attrs:{endpoints:t.endpoints,fieldset:t.fieldset(s),"is-batched":t.isBatched(s),"is-last-in-batch":t.isLastInBatch(s),"is-full":t.isFull,"is-hidden":!0===s.isHidden,"is-selected":t.isSelected(s),next:t.prevNext(i+1),prev:t.prevNext(i-1)},on:{append:function(e){return t.append(e,i+1)},blur:function(e){return t.select(null)},choose:function(e){return t.choose(e)},chooseToAppend:function(e){return t.choose(i+1)},chooseToConvert:function(e){return t.chooseToConvert(s)},chooseToPrepend:function(e){return t.choose(i)},copy:function(e){return t.copy()},confirmToRemoveSelected:t.confirmToRemoveSelected,duplicate:function(e){return t.duplicate(s,i)},focus:function(e){return t.select(s)},hide:function(e){return t.hide(s)},paste:function(e){return t.pasteboard()},prepend:function(e){return t.add(e,i)},remove:function(e){return t.remove(s)},sortDown:function(e){return t.sort(s,i,i+1)},sortUp:function(e){return t.sort(s,i,i-1)},show:function(e){return t.show(s)},update:function(e){return t.update(s,e)}},nativeOn:{click:function(e){return e.stopPropagation(),t.select(s,e)}}},"k-block",s,!1))})),1),e("k-block-selector",{ref:"selector",attrs:{fieldsets:t.fieldsets,"fieldset-groups":t.fieldsetGroups},on:{add:t.add,convert:t.convert,paste:function(e){return t.paste(e)}}}),e("k-remove-dialog",{ref:"removeAll",attrs:{text:t.$t("field.blocks.delete.confirm.all")},on:{submit:t.removeAll}}),e("k-remove-dialog",{ref:"removeSelected",attrs:{text:t.$t("field.blocks.delete.confirm.selected")},on:{submit:t.removeSelected}}),e("k-block-pasteboard",{ref:"pasteboard",on:{paste:function(e){return t.paste(e)}}})]:[e("k-box",{attrs:{theme:"info"}},[t._v(" No fieldsets yet ")])]],2)}),[],!1,null,null,null,null).exports;var yo=Mt({inheritAttrs:!1,props:{caption:String,captionMarks:[Boolean,Array],cover:{type:Boolean,default:!0},isEmpty:Boolean,emptyIcon:String,emptyText:String,ratio:String},computed:{ratioPadding(){return this.$helper.ratio(this.ratio||"16/9")}}},(function(){var t=this,e=t._self._c;return e("figure",{staticClass:"k-block-figure"},[t.isEmpty?e("k-button",{staticClass:"k-block-figure-empty",attrs:{icon:t.emptyIcon,text:t.emptyText},on:{click:function(e){return t.$emit("open")}}}):e("span",{staticClass:"k-block-figure-container",on:{dblclick:function(e){return t.$emit("open")}}},[t._t("default")],2),t.caption?e("figcaption",[e("k-writer",{attrs:{inline:!0,marks:t.captionMarks,value:t.caption},on:{input:function(e){return t.$emit("update",{caption:e})}}})],1):t._e()],1)}),[],!1,null,null,null,null).exports;var $o=Mt({props:{isBatched:Boolean,isEditable:Boolean,isFull:Boolean,isHidden:Boolean},methods:{open(){this.$refs.options.open()}}},(function(){var t=this,e=t._self._c;return e("k-dropdown",{staticClass:"k-block-options"},[t.isBatched?[e("k-button",{staticClass:"k-block-options-button",attrs:{tooltip:t.$t("copy"),icon:"template"},on:{click:function(e){return e.preventDefault(),t.$emit("copy")}}}),e("k-button",{staticClass:"k-block-options-button",attrs:{tooltip:t.$t("remove"),icon:"trash"},on:{click:function(e){return e.preventDefault(),t.$emit("confirmToRemoveSelected")}}})]:[t.isEditable?e("k-button",{staticClass:"k-block-options-button",attrs:{tooltip:t.$t("edit"),icon:"edit"},on:{click:function(e){return t.$emit("open")}}}):t._e(),e("k-button",{staticClass:"k-block-options-button",attrs:{disabled:t.isFull,tooltip:t.$t("insert.after"),icon:"add"},on:{click:function(e){return t.$emit("chooseToAppend")}}}),e("k-button",{staticClass:"k-block-options-button",attrs:{tooltip:t.$t("delete"),icon:"trash"},on:{click:function(e){return t.$emit("confirmToRemove")}}}),e("k-button",{staticClass:"k-block-options-button",attrs:{tooltip:t.$t("more"),icon:"dots"},on:{click:function(e){return t.$refs.options.toggle()}}}),e("k-button",{staticClass:"k-block-options-button k-sort-handle",attrs:{tooltip:t.$t("sort"),icon:"sort"},on:{keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"up",38,e.key,["Up","ArrowUp"])?null:(e.preventDefault(),t.$emit("sortUp"))},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"down",40,e.key,["Down","ArrowDown"])?null:(e.preventDefault(),t.$emit("sortDown"))}]}}),e("k-dropdown-content",{ref:"options",attrs:{align:"right"}},[e("k-dropdown-item",{attrs:{disabled:t.isFull,icon:"angle-up"},on:{click:function(e){return t.$emit("chooseToPrepend")}}},[t._v(" "+t._s(t.$t("insert.before"))+" ")]),e("k-dropdown-item",{attrs:{disabled:t.isFull,icon:"angle-down"},on:{click:function(e){return t.$emit("chooseToAppend")}}},[t._v(" "+t._s(t.$t("insert.after"))+" ")]),e("hr"),t.isEditable?e("k-dropdown-item",{attrs:{icon:"edit"},on:{click:function(e){return t.$emit("open")}}},[t._v(" "+t._s(t.$t("edit"))+" ")]):t._e(),e("k-dropdown-item",{attrs:{icon:"refresh"},on:{click:function(e){return t.$emit("chooseToConvert")}}},[t._v(" "+t._s(t.$t("field.blocks.changeType"))+" ")]),e("hr"),e("k-dropdown-item",{attrs:{icon:"template"},on:{click:function(e){return t.$emit("copy")}}},[t._v(" "+t._s(t.$t("copy"))+" ")]),e("k-dropdown-item",{attrs:{icon:"download"},on:{click:function(e){return t.$emit("paste")}}},[t._v(" "+t._s(t.$t("paste.after"))+" ")]),e("hr"),e("k-dropdown-item",{attrs:{icon:t.isHidden?"preview":"hidden"},on:{click:function(e){return t.$emit(t.isHidden?"show":"hide")}}},[t._v(" "+t._s(!0===t.isHidden?t.$t("show"):t.$t("hide"))+" ")]),e("k-dropdown-item",{attrs:{disabled:t.isFull,icon:"copy"},on:{click:function(e){return t.$emit("duplicate")}}},[t._v(" "+t._s(t.$t("duplicate"))+" ")]),e("hr"),e("k-dropdown-item",{attrs:{icon:"trash"},on:{click:function(e){return t.$emit("confirmToRemove")}}},[t._v(" "+t._s(t.$t("delete"))+" ")])],1)]],2)}),[],!1,null,null,null,null).exports;var _o=Mt({inheritAttrs:!1,props:{endpoint:String,fieldsets:Object,fieldsetGroups:Object},data(){return{dialogIsOpen:!1,disabled:[],headline:null,payload:null,event:"add",groups:this.createGroups()}},computed:{shortcut(){return this.$helper.keyboard.metaKey()+"+v"}},methods:{add(t){this.$emit(this.event,t,this.payload),this.$refs.dialog.close()},close(){this.$refs.dialog.close()},createGroups(){let t={},e=0;const s=this.fieldsetGroups||{blocks:{label:this.$t("field.blocks.fieldsets.label"),sets:Object.keys(this.fieldsets)}};return Object.keys(s).forEach((i=>{let n=s[i];n.open=!1!==n.open,n.fieldsets=n.sets.filter((t=>this.fieldsets[t])).map((t=>(e++,{...this.fieldsets[t],index:e}))),0!==n.fieldsets.length&&(t[i]=n)})),t},isOpen(){return this.dialogIsOpen},navigate(t){var e,s;null==(s=null==(e=this.$refs["fieldset-"+t])?void 0:e[0])||s.focus()},onClose(){this.dialogIsOpen=!1,this.$events.$off("paste",this.close)},onOpen(){this.dialogIsOpen=!0,this.$events.$on("paste",this.close)},open(t,e={}){const s={event:"add",disabled:[],headline:null,...e};this.event=s.event,this.disabled=s.disabled,this.headline=s.headline,this.payload=t,this.$refs.dialog.open()}}},(function(){var t=this,e=t._self._c;return e("k-dialog",{ref:"dialog",staticClass:"k-block-selector",attrs:{"cancel-button":!1,"submit-button":!1,size:"medium"},on:{open:t.onOpen,close:t.onClose}},[t.headline?e("k-headline",[t._v(" "+t._s(t.headline)+" ")]):t._e(),t._l(t.groups,(function(s,i){return e("details",{key:i,attrs:{open:s.open}},[e("summary",[t._v(t._s(s.label))]),e("div",{staticClass:"k-block-types"},t._l(s.fieldsets,(function(s){return e("k-button",{key:s.name,ref:"fieldset-"+s.index,refInFor:!0,attrs:{disabled:t.disabled.includes(s.type),icon:s.icon||"box",text:s.name},on:{keydown:[function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"up",38,e.key,["Up","ArrowUp"])?null:t.navigate(s.index-1)},function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"down",40,e.key,["Down","ArrowDown"])?null:t.navigate(s.index+1)}],click:function(e){return t.add(s.type)}}})})),1)])})),e("p",{staticClass:"k-clipboard-hint",domProps:{innerHTML:t._s(t.$t("field.blocks.fieldsets.paste",{shortcut:t.shortcut}))}})],2)}),[],!1,null,null,null,null).exports;var xo=Mt({inheritAttrs:!1,props:{fieldset:Object,content:Object},computed:{icon(){return this.fieldset.icon||"box"},label(){if(!this.fieldset.label||0===this.fieldset.label.length)return!1;if(this.fieldset.label===this.fieldset.name)return!1;const t=this.$helper.string.template(this.fieldset.label,this.content);return"…"!==t&&t},name(){return this.fieldset.name}}},(function(){var t=this,e=t._self._c;return e("div",t._g({staticClass:"k-block-title"},t.$listeners),[e("k-icon",{staticClass:"k-block-icon",attrs:{type:t.icon}}),e("span",{staticClass:"k-block-name"},[t._v(" "+t._s(t.name)+" ")]),t.label?e("span",{staticClass:"k-block-label"},[t._v(" "+t._s(t.label)+" ")]):t._e()],1)}),[],!1,null,null,null,null).exports;var wo=Mt({inheritAttrs:!1,props:{content:[Object,Array],fieldset:Object},methods:{field(t,e=null){let s=null;return Object.values(this.fieldset.tabs).forEach((e=>{e.fields[t]&&(s=e.fields[t])})),s||e},open(){this.$emit("open")},update(t){this.$emit("update",{...this.content,...t})}}},null,null,!1,null,null,null,null).exports;t.component("k-block",bo),t.component("k-blocks",vo),t.component("k-block-figure",yo),t.component("k-block-options",$o),t.component("k-block-selector",_o),t.component("k-block-title",xo),t.component("k-block-type",wo);const So={"./Types/Code.vue":Gn,"./Types/Default.vue":Wn,"./Types/Gallery.vue":Zn,"./Types/Heading.vue":to,"./Types/Image.vue":so,"./Types/Line.vue":no,"./Types/List.vue":ro,"./Types/Markdown.vue":ao,"./Types/Quote.vue":co,"./Types/Table.vue":ho,"./Types/Text.vue":fo,"./Types/Video.vue":ko};Object.keys(So).map((e=>{const s=e.match(/\/([a-zA-Z]*)\.vue/)[1].toLowerCase();let i=So[e].default;i.extends=wo,t.component("k-block-type-"+s,i)}));var Co={inheritAttrs:!1,props:{column:{type:Object,default:()=>({})},field:Object,value:{}}};var Oo=Mt({inheritAttrs:!1,mixins:[Co],props:{value:[Array,String]},computed:{bubbles(){var t,e;let s=this.value;const i=(null==(t=this.column)?void 0:t.options)||(null==(e=this.field)?void 0:e.options)||[];return"string"==typeof s&&(s=s.split(",")),s.map((t=>{"string"==typeof t&&(t={value:t,text:t});for(const e of i)e.value===t.value&&(t.text=e.text);return{back:"light",color:"black",...t}}))}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-bubbles-field-preview",class:t.$options.class},[e("k-bubbles",{attrs:{bubbles:t.bubbles}})],1)}),[],!1,null,null,null,null).exports;var Ao=Mt({inheritAttrs:!1,extends:Oo,class:"k-array-field-preview",computed:{bubbles(){return[{text:1===this.value.length?`1 ${this.$t("entry")}`:`${this.value.length} ${this.$t("entries")}`}]}}},null,null,!1,null,null,null,null).exports;var To=Mt({mixins:[Co],inheritAttrs:!1,computed:{text(){return this.value}}},(function(){var t=this;return(0,t._self._c)("p",{staticClass:"k-text-field-preview",class:t.$options.class},[t._v(" "+t._s(t.column.before)+" "),t._t("default",(function(){return[t._v(t._s(t.text))]})),t._v(" "+t._s(t.column.after)+" ")],2)}),[],!1,null,null,null,null).exports;var Io=Mt({inheritAttrs:!1,extends:To,props:{value:String},class:"k-date-field-preview",computed:{text(){var t,e,s,i,n,o;if("string"!=typeof this.value)return"";const r=this.$library.dayjs(this.value);if(!r)return"";let l=(null==(t=this.column)?void 0:t.display)||(null==(e=this.field)?void 0:e.display)||"YYYY-MM-DD",a=(null==(i=null==(s=this.column)?void 0:s.time)?void 0:i.display)||(null==(o=null==(n=this.field)?void 0:n.time)?void 0:o.display);return a&&(l+=" "+a),r.format(l)}}},null,null,!1,null,null,null,null).exports;var Mo=Mt({mixins:[Co],props:{value:[String,Object]},computed:{link(){return"object"==typeof this.value?this.value.href:this.value},text(){return"object"==typeof this.value?this.value.text:this.link}}},(function(){var t=this,e=t._self._c;return e("p",{staticClass:"k-url-field-preview",class:t.$options.class},[t._v(" "+t._s(t.column.before)+" "),e("k-link",{attrs:{to:t.link},nativeOn:{click:function(t){t.stopPropagation()}}},[t._v(" "+t._s(t.text)+" ")]),t._v(" "+t._s(t.column.after)+" ")],1)}),[],!1,null,null,null,null).exports;var Lo=Mt({extends:Mo,class:"k-email-field-preview"},null,null,!1,null,null,null,null).exports;var Eo=Mt({inheritAttrs:!1,extends:Oo,class:"k-files-field-preview",computed:{bubbles(){return this.value.map((t=>({text:t.filename,link:t.link,image:t.image})))}}},null,null,!1,null,null,null,null).exports;var jo=Mt({mixins:[Co],inheritAttrs:!1,props:{value:Object}},(function(){var t=this;return(0,t._self._c)("k-status-icon",t._b({staticClass:"k-flag-field-preview"},"k-status-icon",t.value,!1))}),[],!1,null,null,null,null).exports;var Bo=Mt({inheritAttrs:!1,mixins:[Co],props:{value:String},computed:{html(){return this.value}}},(function(){var t=this,e=t._self._c;return e("div",{staticClass:"k-html-field-preview",class:t.$options.class},[t._v(" "+t._s(t.column.before)+" "),e("div",{domProps:{innerHTML:t._s(t.html)}}),t._v(" "+t._s(t.column.after)+" ")])}),[],!1,null,null,null,null).exports;var Do=Mt({inheritAttrs:!1,mixins:[Co],props:{value:[Object]}},(function(){return(0,this._self._c)("k-item-image",{staticClass:"k-image-field-preview",attrs:{image:this.value,layout:"list"}})}),[],!1,null,null,null,null).exports;var Po=Mt({inheritAttrs:!1,extends:Oo,class:"k-pages-field-preview"},null,null,!1,null,null,null,null).exports;var No=Mt({inheritAttrs:!1,extends:To,props:{value:String},class:"k-time-field-preview",computed:{text(){const t=this.$library.dayjs.iso(this.value,"time");return(null==t?void 0:t.format(this.field.display))||""}}},null,null,!1,null,null,null,null).exports;var qo=Mt({props:{field:Object,value:Boolean,column:Object},computed:{text(){return!1!==this.column.text?this.field.text:null}}},(function(){var t=this;return(0,t._self._c)("k-input",{staticClass:"k-toggle-field-preview",attrs:{text:t.text,value:t.value,type:"toggle"},on:{input:function(e){return t.$emit("input",e)}}})}),[],!1,null,null,null,null).exports;var Fo=Mt({inheritAttrs:!1,extends:Oo,class:"k-users-field-preview",computed:{bubble(){return this.value.map((t=>({text:t.username,link:t.link,image:t.image})))}}},null,null,!1,null,null,null,null).exports;t.component("k-array-field-preview",Ao),t.component("k-bubbles-field-preview",Oo),t.component("k-date-field-preview",Io),t.component("k-email-field-preview",Lo),t.component("k-files-field-preview",Eo),t.component("k-flag-field-preview",jo),t.component("k-html-field-preview",Bo),t.component("k-image-field-preview",Do),t.component("k-pages-field-preview",Po),t.component("k-text-field-preview",To),t.component("k-toggle-field-preview",qo),t.component("k-time-field-preview",No),t.component("k-url-field-preview",Mo),t.component("k-users-field-preview",Fo),t.component("k-list-field-preview",Bo),t.component("k-writer-field-preview",Bo),t.component("k-checkboxes-field-preview",Oo),t.component("k-multiselect-field-preview",Oo),t.component("k-radio-field-preview",Oo),t.component("k-select-field-preview",Oo),t.component("k-tags-field-preview",Oo),t.component("k-dialog",Lt),t.component("k-error-dialog",jt),t.component("k-fiber-dialog",Bt),t.component("k-files-dialog",Pt),t.component("k-form-dialog",Nt),t.component("k-language-dialog",qt),t.component("k-pages-dialog",Ft),t.component("k-remove-dialog",Rt),t.component("k-text-dialog",zt),t.component("k-users-dialog",Yt),t.component("k-drawer",Ht),t.component("k-form-drawer",Ut),t.component("k-calendar",Jt),t.component("k-counter",Gt),t.component("k-autocomplete",Kt),t.component("k-form",Vt),t.component("k-form-buttons",Wt),t.component("k-form-indicator",Xt),t.component("k-field",ue),t.component("k-fieldset",ce),t.component("k-input",pe),t.component("k-login",he),t.component("k-login-code",me),t.component("k-times",fe),t.component("k-upload",ge),t.component("k-writer",Xe),t.component("k-login-alert",Ze),t.component("k-structure-form",Qe),t.component("k-toolbar",es),t.component("k-toolbar-email-dialog",ss),t.component("k-toolbar-link-dialog",is),t.component("k-aspect-ratio",$i),t.component("k-bar",_i),t.component("k-box",xi),t.component("k-bubble",wi),t.component("k-bubbles",Si),t.component("k-collection",Ci),t.component("k-column",Oi),t.component("k-dropzone",Ai),t.component("k-empty",Ti),t.component("k-file-preview",Ii),t.component("k-grid",Mi),t.component("k-header",Li),t.component("k-inside",Ei),t.component("k-item",ji),t.component("k-item-image",Bi),t.component("k-items",Di),t.component("k-overlay",Pi),t.component("k-panel",Ni),t.component("k-stats",qi),t.component("k-table",Fi),t.component("k-table-cell",Ri),t.component("k-tabs",zi),t.component("k-view",Yi),t.component("k-draggable",Hi),t.component("k-error-boundary",Ui),t.component("k-fatal",Ki),t.component("k-headline",Ji),t.component("k-icon",Gi),t.component("k-icons",Vi),t.component("k-image",Wi),t.component("k-loader",Xi),t.component("k-offline-warning",Zi),t.component("k-progress",tn),t.component("k-registration",en),t.component("k-status-icon",nn),t.component("k-sort-handle",sn),t.component("k-text",on),t.component("k-user-info",rn),t.component("k-breadcrumb",ln),t.component("k-button",an),t.component("k-button-disabled",un),t.component("k-button-group",cn),t.component("k-button-link",dn),t.component("k-button-native",hn),t.component("k-dropdown",mn),t.component("k-dropdown-content",gn),t.component("k-dropdown-item",kn),t.component("k-languages-dropdown",vn),t.component("k-link",bn),t.component("k-options-dropdown",yn),t.component("k-pagination",$n),t.component("k-prev-next",_n),t.component("k-search",xn),t.component("k-tag",wn),t.component("k-topbar",Sn),t.component("k-account-view",Bn),t.component("k-error-view",Dn),t.component("k-file-view",Pn),t.component("k-installation-view",Nn),t.component("k-languages-view",qn),t.component("k-login-view",Fn),t.component("k-page-view",Rn),t.component("k-plugin-view",zn),t.component("k-reset-password-view",Yn),t.component("k-site-view",Hn),t.component("k-system-view",Un),t.component("k-users-view",Kn),t.component("k-user-view",jn);t.config.productionTip=!1,t.config.devtools=!0,t.use(et),t.use(Ct),t.use(At),t.use(It),t.use(st),t.use(Ot),t.use(ut),t.use(U,tt),t.use(q),t.use(F),new t({store:tt,created(){window.panel.$vue=window.panel.app=this,window.panel.plugins.created.forEach((t=>t(this))),this.$store.dispatch("content/init")},render:t=>t(K)}).$mount("#app"); diff --git a/kirby/panel/dist/js/vendor.js b/kirby/panel/dist/js/vendor.js index 6df18c1..352c160 100755 --- a/kirby/panel/dist/js/vendor.js +++ b/kirby/panel/dist/js/vendor.js @@ -1,19 +1,19 @@ /*! - * Vue.js v2.6.14 - * (c) 2014-2021 Evan You + * Vue.js v2.7.4 + * (c) 2014-2022 Evan You * Released under the MIT License. */ -var e=Object.freeze({});function t(e){return null==e}function n(e){return null!=e}function r(e){return!0===e}function i(e){return"string"==typeof e||"number"==typeof e||"symbol"==typeof e||"boolean"==typeof e}function o(e){return null!==e&&"object"==typeof e}var s=Object.prototype.toString;function a(e){return"[object Object]"===s.call(e)}function l(e){var t=parseFloat(String(e));return t>=0&&Math.floor(t)===t&&isFinite(e)}function c(e){return n(e)&&"function"==typeof e.then&&"function"==typeof e.catch}function u(e){return null==e?"":Array.isArray(e)||a(e)&&e.toString===s?JSON.stringify(e,null,2):String(e)}function d(e){var t=parseFloat(e);return isNaN(t)?e:t}function h(e,t){for(var n=Object.create(null),r=e.split(","),i=0;i-1)return e.splice(n,1)}}var g=Object.prototype.hasOwnProperty;function v(e,t){return g.call(e,t)}function y(e){var t=Object.create(null);return function(n){return t[n]||(t[n]=e(n))}}var b=/-(\w)/g,w=y((function(e){return e.replace(b,(function(e,t){return t?t.toUpperCase():""}))})),x=y((function(e){return e.charAt(0).toUpperCase()+e.slice(1)})),S=/\B([A-Z])/g,k=y((function(e){return e.replace(S,"-$1").toLowerCase()}));var C=Function.prototype.bind?function(e,t){return e.bind(t)}:function(e,t){function n(n){var r=arguments.length;return r?r>1?e.apply(t,arguments):e.call(t,n):e.call(t)}return n._length=e.length,n};function O(e,t){t=t||0;for(var n=e.length-t,r=new Array(n);n--;)r[n]=e[n+t];return r}function M(e,t){for(var n in t)e[n]=t[n];return e}function _(e){for(var t={},n=0;n0,Y=H&&H.indexOf("edge/")>0;H&&H.indexOf("android");var U=H&&/iphone|ipad|ipod|ios/.test(H)||"ios"===q;H&&/chrome\/\d+/.test(H),H&&/phantomjs/.test(H);var X,G=H&&H.match(/firefox\/(\d+)/),Z={}.watch,Q=!1;if(V)try{var ee={};Object.defineProperty(ee,"passive",{get:function(){Q=!0}}),window.addEventListener("test-passive",null,ee)}catch(wy){}var te=function(){return void 0===X&&(X=!V&&!W&&"undefined"!=typeof global&&(global.process&&"server"===global.process.env.VUE_ENV)),X},ne=V&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__;function re(e){return"function"==typeof e&&/native code/.test(e.toString())}var ie,oe="undefined"!=typeof Symbol&&re(Symbol)&&"undefined"!=typeof Reflect&&re(Reflect.ownKeys);ie="undefined"!=typeof Set&&re(Set)?Set:function(){function e(){this.set=Object.create(null)}return e.prototype.has=function(e){return!0===this.set[e]},e.prototype.add=function(e){this.set[e]=!0},e.prototype.clear=function(){this.set=Object.create(null)},e}();var se=D,ae=0,le=function(){this.id=ae++,this.subs=[]};le.prototype.addSub=function(e){this.subs.push(e)},le.prototype.removeSub=function(e){m(this.subs,e)},le.prototype.depend=function(){le.target&&le.target.addDep(this)},le.prototype.notify=function(){for(var e=this.subs.slice(),t=0,n=e.length;t-1)if(o&&!v(i,"default"))s=!1;else if(""===s||s===k(e)){var l=Le(String,i.type);(l<0||a0&&(ut((a=dt(a,(o||"")+"_"+s))[0])&&ut(c)&&(u[l]=me(c.text+a[0].text),a.shift()),u.push.apply(u,a)):i(a)?ut(c)?u[l]=me(c.text+a):""!==a&&u.push(me(a)):ut(a)&&ut(c)?u[l]=me(c.text+a.text):(r(e._isVList)&&n(a.tag)&&t(a.key)&&n(o)&&(a.key="__vlist"+o+"_"+s+"__"),u.push(a)));return u}function ht(e,t){if(e){for(var n=Object.create(null),r=oe?Reflect.ownKeys(e):Object.keys(e),i=0;i0,s=t?!!t.$stable:!o,a=t&&t.$key;if(t){if(t._normalized)return t._normalized;if(s&&r&&r!==e&&a===r.$key&&!o&&!r.$hasNormal)return r;for(var l in i={},t)t[l]&&"$"!==l[0]&&(i[l]=vt(n,l,t[l]))}else i={};for(var c in n)c in i||(i[c]=yt(n,c));return t&&Object.isExtensible(t)&&(t._normalized=i),F(i,"$stable",s),F(i,"$key",a),F(i,"$hasNormal",o),i}function vt(e,t,n){var r=function(){var e=arguments.length?n.apply(null,arguments):n({}),t=(e=e&&"object"==typeof e&&!Array.isArray(e)?[e]:ct(e))&&e[0];return e&&(!t||1===e.length&&t.isComment&&!mt(t))?void 0:e};return n.proxy&&Object.defineProperty(e,t,{get:r,enumerable:!0,configurable:!0}),r}function yt(e,t){return function(){return e[t]}}function bt(e,t){var r,i,s,a,l;if(Array.isArray(e)||"string"==typeof e)for(r=new Array(e.length),i=0,s=e.length;idocument.createEvent("Event").timeStamp&&(dn=function(){return hn.now()})}function fn(){var e,t;for(un=dn(),ln=!0,rn.sort((function(e,t){return e.id-t.id})),cn=0;cncn&&rn[n].id>e.id;)n--;rn.splice(n+1,0,e)}else rn.push(e);an||(an=!0,et(fn))}}(this)},mn.prototype.run=function(){if(this.active){var e=this.get();if(e!==this.value||o(e)||this.deep){var t=this.value;if(this.value=e,this.user){var n='callback for watcher "'+this.expression+'"';Ve(this.cb,this.vm,[e,t],this.vm,n)}else this.cb.call(this.vm,e,t)}}},mn.prototype.evaluate=function(){this.value=this.get(),this.dirty=!1},mn.prototype.depend=function(){for(var e=this.deps.length;e--;)this.deps[e].depend()},mn.prototype.teardown=function(){if(this.active){this.vm._isBeingDestroyed||m(this.vm._watchers,this);for(var e=this.deps.length;e--;)this.deps[e].removeSub(this);this.active=!1}};var gn={enumerable:!0,configurable:!0,get:D,set:D};function vn(e,t,n){gn.get=function(){return this[t][n]},gn.set=function(e){this[t][n]=e},Object.defineProperty(e,n,gn)}function yn(e){e._watchers=[];var t=e.$options;t.props&&function(e,t){var n=e.$options.propsData||{},r=e._props={},i=e.$options._propKeys=[];e.$parent&&xe(!1);var o=function(o){i.push(o);var s=Re(o,t,n,e);Ce(r,o,s),o in e||vn(e,"_props",o)};for(var s in t)o(s);xe(!0)}(e,t.props),t.methods&&function(e,t){for(var n in e.$options.props,t)e[n]="function"!=typeof t[n]?D:C(t[n],e)}(e,t.methods),t.data?function(e){var t=e.$options.data;a(t=e._data="function"==typeof t?function(e,t){ue();try{return e.call(t,t)}catch(wy){return Be(wy,t,"data()"),{}}finally{de()}}(t,e):t||{})||(t={});var n=Object.keys(t),r=e.$options.props;e.$options.methods;var i=n.length;for(;i--;){var o=n[i];r&&v(r,o)||j(o)||vn(e,"_data",o)}ke(t,!0)}(e):ke(e._data={},!0),t.computed&&function(e,t){var n=e._computedWatchers=Object.create(null),r=te();for(var i in t){var o=t[i],s="function"==typeof o?o:o.get;r||(n[i]=new mn(e,s||D,D,bn)),i in e||wn(e,i,o)}}(e,t.computed),t.watch&&t.watch!==Z&&function(e,t){for(var n in t){var r=t[n];if(Array.isArray(r))for(var i=0;i-1:"string"==typeof e?e.split(",").indexOf(t)>-1:(n=e,"[object RegExp]"===s.call(n)&&e.test(t));var n}function $n(e,t){var n=e.cache,r=e.keys,i=e._vnode;for(var o in n){var s=n[o];if(s){var a=s.name;a&&!t(a)&&An(n,o,r,i)}}}function An(e,t,n,r){var i=e[t];!i||r&&i.tag===r.tag||i.componentInstance.$destroy(),e[t]=null,m(n,t)}Mn.prototype._init=function(t){var n=this;n._uid=Cn++,n._isVue=!0,t&&t._isComponent?function(e,t){var n=e.$options=Object.create(e.constructor.options),r=t._parentVnode;n.parent=t.parent,n._parentVnode=r;var i=r.componentOptions;n.propsData=i.propsData,n._parentListeners=i.listeners,n._renderChildren=i.children,n._componentTag=i.tag,t.render&&(n.render=t.render,n.staticRenderFns=t.staticRenderFns)}(n,t):n.$options=Pe(On(n.constructor),t||{},n),n._renderProxy=n,n._self=n,function(e){var t=e.$options,n=t.parent;if(n&&!t.abstract){for(;n.$options.abstract&&n.$parent;)n=n.$parent;n.$children.push(e)}e.$parent=n,e.$root=n?n.$root:e,e.$children=[],e.$refs={},e._watcher=null,e._inactive=null,e._directInactive=!1,e._isMounted=!1,e._isDestroyed=!1,e._isBeingDestroyed=!1}(n),function(e){e._events=Object.create(null),e._hasHookEvent=!1;var t=e.$options._parentListeners;t&&Xt(e,t)}(n),function(t){t._vnode=null,t._staticTrees=null;var n=t.$options,r=t.$vnode=n._parentVnode,i=r&&r.context;t.$slots=ft(n._renderChildren,i),t.$scopedSlots=e,t._c=function(e,n,r,i){return Bt(t,e,n,r,i,!1)},t.$createElement=function(e,n,r,i){return Bt(t,e,n,r,i,!0)};var o=r&&r.data;Ce(t,"$attrs",o&&o.attrs||e,null,!0),Ce(t,"$listeners",n._parentListeners||e,null,!0)}(n),nn(n,"beforeCreate"),function(e){var t=ht(e.$options.inject,e);t&&(xe(!1),Object.keys(t).forEach((function(n){Ce(e,n,t[n])})),xe(!0))}(n),yn(n),function(e){var t=e.$options.provide;t&&(e._provided="function"==typeof t?t.call(e):t)}(n),nn(n,"created"),n.$options.el&&n.$mount(n.$options.el)},function(e){var t={get:function(){return this._data}},n={get:function(){return this._props}};Object.defineProperty(e.prototype,"$data",t),Object.defineProperty(e.prototype,"$props",n),e.prototype.$set=Oe,e.prototype.$delete=Me,e.prototype.$watch=function(e,t,n){var r=this;if(a(t))return kn(r,e,t,n);(n=n||{}).user=!0;var i=new mn(r,e,t,n);if(n.immediate){var o='callback for immediate watcher "'+i.expression+'"';ue(),Ve(t,r,[i.value],r,o),de()}return function(){i.teardown()}}}(Mn),function(e){var t=/^hook:/;e.prototype.$on=function(e,n){var r=this;if(Array.isArray(e))for(var i=0,o=e.length;i1?O(n):n;for(var r=O(arguments,1),i='event handler for "'+e+'"',o=0,s=n.length;oparseInt(this.max)&&An(t,n[0],n,this._vnode),this.vnodeToCache=null}}},created:function(){this.cache=Object.create(null),this.keys=[]},destroyed:function(){for(var e in this.cache)An(this.cache,e,this.keys)},mounted:function(){var e=this;this.cacheVNode(),this.$watch("include",(function(t){$n(e,(function(e){return Tn(t,e)}))})),this.$watch("exclude",(function(t){$n(e,(function(e){return!Tn(t,e)}))}))},updated:function(){this.cacheVNode()},render:function(){var e=this.$slots.default,t=Jt(e),n=t&&t.componentOptions;if(n){var r=Dn(n),i=this.include,o=this.exclude;if(i&&(!r||!Tn(i,r))||o&&r&&Tn(o,r))return t;var s=this.cache,a=this.keys,l=null==t.key?n.Ctor.cid+(n.tag?"::"+n.tag:""):t.key;s[l]?(t.componentInstance=s[l].componentInstance,m(a,l),a.push(l)):(this.vnodeToCache=t,this.keyToCache=l),t.data.keepAlive=!0}return t||e&&e[0]}}};!function(e){var t={get:function(){return R}};Object.defineProperty(e,"config",t),e.util={warn:se,extend:M,mergeOptions:Pe,defineReactive:Ce},e.set=Oe,e.delete=Me,e.nextTick=et,e.observable=function(e){return ke(e),e},e.options=Object.create(null),P.forEach((function(t){e.options[t+"s"]=Object.create(null)})),e.options._base=e,M(e.options.components,Nn),function(e){e.use=function(e){var t=this._installedPlugins||(this._installedPlugins=[]);if(t.indexOf(e)>-1)return this;var n=O(arguments,1);return n.unshift(this),"function"==typeof e.install?e.install.apply(e,n):"function"==typeof e&&e.apply(null,n),t.push(e),this}}(e),function(e){e.mixin=function(e){return this.options=Pe(this.options,e),this}}(e),_n(e),function(e){P.forEach((function(t){e[t]=function(e,n){return n?("component"===t&&a(n)&&(n.name=n.name||e,n=this.options._base.extend(n)),"directive"===t&&"function"==typeof n&&(n={bind:n,update:n}),this.options[t+"s"][e]=n,n):this.options[t+"s"][e]}}))}(e)}(Mn),Object.defineProperty(Mn.prototype,"$isServer",{get:te}),Object.defineProperty(Mn.prototype,"$ssrContext",{get:function(){return this.$vnode&&this.$vnode.ssrContext}}),Object.defineProperty(Mn,"FunctionalRenderContext",{value:Pt}),Mn.version="2.6.14";var Pn=h("style,class"),In=h("input,textarea,option,select,progress"),Rn=function(e,t,n){return"value"===n&&In(e)&&"button"!==t||"selected"===n&&"option"===e||"checked"===n&&"input"===e||"muted"===n&&"video"===e},zn=h("contenteditable,draggable,spellcheck"),jn=h("events,caret,typing,plaintext-only"),Fn=h("allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,default,defaultchecked,defaultmuted,defaultselected,defer,disabled,enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,required,reversed,scoped,seamless,selected,sortable,truespeed,typemustmatch,visible"),Ln="http://www.w3.org/1999/xlink",Bn=function(e){return":"===e.charAt(5)&&"xlink"===e.slice(0,5)},Vn=function(e){return Bn(e)?e.slice(6,e.length):""},Wn=function(e){return null==e||!1===e};function qn(e){for(var t=e.data,r=e,i=e;n(i.componentInstance);)(i=i.componentInstance._vnode)&&i.data&&(t=Hn(i.data,t));for(;n(r=r.parent);)r&&r.data&&(t=Hn(t,r.data));return function(e,t){if(n(e)||n(t))return Jn(e,Kn(t));return""}(t.staticClass,t.class)}function Hn(e,t){return{staticClass:Jn(e.staticClass,t.staticClass),class:n(e.class)?[e.class,t.class]:t.class}}function Jn(e,t){return e?t?e+" "+t:e:t||""}function Kn(e){return Array.isArray(e)?function(e){for(var t,r="",i=0,o=e.length;i-1?yr(e,t,n):Fn(t)?Wn(n)?e.removeAttribute(t):(n="allowfullscreen"===t&&"EMBED"===e.tagName?"true":t,e.setAttribute(t,n)):zn(t)?e.setAttribute(t,function(e,t){return Wn(t)||"false"===t?"false":"contenteditable"===e&&jn(t)?t:"true"}(t,n)):Bn(t)?Wn(n)?e.removeAttributeNS(Ln,Vn(t)):e.setAttributeNS(Ln,t,n):yr(e,t,n)}function yr(e,t,n){if(Wn(n))e.removeAttribute(t);else{if(J&&!K&&"TEXTAREA"===e.tagName&&"placeholder"===t&&""!==n&&!e.__ieph){var r=function(t){t.stopImmediatePropagation(),e.removeEventListener("input",r)};e.addEventListener("input",r),e.__ieph=!0}e.setAttribute(t,n)}}var br={create:gr,update:gr};function wr(e,r){var i=r.elm,o=r.data,s=e.data;if(!(t(o.staticClass)&&t(o.class)&&(t(s)||t(s.staticClass)&&t(s.class)))){var a=qn(r),l=i._transitionClasses;n(l)&&(a=Jn(a,Kn(l))),a!==i._prevClass&&(i.setAttribute("class",a),i._prevClass=a)}}var xr,Sr,kr,Cr,Or,Mr,_r={create:wr,update:wr},Dr=/[\w).+\-_$\]]/;function Tr(e){var t,n,r,i,o,s=!1,a=!1,l=!1,c=!1,u=0,d=0,h=0,f=0;for(r=0;r=0&&" "===(m=e.charAt(p));p--);m&&Dr.test(m)||(c=!0)}}else void 0===i?(f=r+1,i=e.slice(0,r).trim()):g();function g(){(o||(o=[])).push(e.slice(f,r).trim()),f=r+1}if(void 0===i?i=e.slice(0,r).trim():0!==f&&g(),o)for(r=0;r-1?{exp:e.slice(0,Cr),key:'"'+e.slice(Cr+1)+'"'}:{exp:e,key:null};Sr=e,Cr=Or=Mr=0;for(;!Jr();)Kr(kr=Hr())?Ur(kr):91===kr&&Yr(kr);return{exp:e.slice(0,Or),key:e.slice(Or+1,Mr)}}(e);return null===n.key?e+"="+t:"$set("+n.exp+", "+n.key+", "+t+")"}function Hr(){return Sr.charCodeAt(++Cr)}function Jr(){return Cr>=xr}function Kr(e){return 34===e||39===e}function Yr(e){var t=1;for(Or=Cr;!Jr();)if(Kr(e=Hr()))Ur(e);else if(91===e&&t++,93===e&&t--,0===t){Mr=Cr;break}}function Ur(e){for(var t=e;!Jr()&&(e=Hr())!==t;);}var Xr;function Gr(e,t,n){var r=Xr;return function i(){var o=t.apply(null,arguments);null!==o&&ei(e,i,n,r)}}var Zr=Je&&!(G&&Number(G[1])<=53);function Qr(e,t,n,r){if(Zr){var i=un,o=t;t=o._wrapper=function(e){if(e.target===e.currentTarget||e.timeStamp>=i||e.timeStamp<=0||e.target.ownerDocument!==document)return o.apply(this,arguments)}}Xr.addEventListener(e,t,Q?{capture:n,passive:r}:n)}function ei(e,t,n,r){(r||Xr).removeEventListener(e,t._wrapper||t,n)}function ti(e,r){if(!t(e.data.on)||!t(r.data.on)){var i=r.data.on||{},o=e.data.on||{};Xr=r.elm,function(e){if(n(e.__r)){var t=J?"change":"input";e[t]=[].concat(e.__r,e[t]||[]),delete e.__r}n(e.__c)&&(e.change=[].concat(e.__c,e.change||[]),delete e.__c)}(i),st(i,o,Qr,ei,Gr,r.context),Xr=void 0}}var ni,ri={create:ti,update:ti};function ii(e,r){if(!t(e.data.domProps)||!t(r.data.domProps)){var i,o,s=r.elm,a=e.data.domProps||{},l=r.data.domProps||{};for(i in n(l.__ob__)&&(l=r.data.domProps=M({},l)),a)i in l||(s[i]="");for(i in l){if(o=l[i],"textContent"===i||"innerHTML"===i){if(r.children&&(r.children.length=0),o===a[i])continue;1===s.childNodes.length&&s.removeChild(s.childNodes[0])}if("value"===i&&"PROGRESS"!==s.tagName){s._value=o;var c=t(o)?"":String(o);oi(s,c)&&(s.value=c)}else if("innerHTML"===i&&Xn(s.tagName)&&t(s.innerHTML)){(ni=ni||document.createElement("div")).innerHTML=""+o+"";for(var u=ni.firstChild;s.firstChild;)s.removeChild(s.firstChild);for(;u.firstChild;)s.appendChild(u.firstChild)}else if(o!==a[i])try{s[i]=o}catch(wy){}}}}function oi(e,t){return!e.composing&&("OPTION"===e.tagName||function(e,t){var n=!0;try{n=document.activeElement!==e}catch(wy){}return n&&e.value!==t}(e,t)||function(e,t){var r=e.value,i=e._vModifiers;if(n(i)){if(i.number)return d(r)!==d(t);if(i.trim)return r.trim()!==t.trim()}return r!==t}(e,t))}var si={create:ii,update:ii},ai=y((function(e){var t={},n=/:(.+)/;return e.split(/;(?![^(]*\))/g).forEach((function(e){if(e){var r=e.split(n);r.length>1&&(t[r[0].trim()]=r[1].trim())}})),t}));function li(e){var t=ci(e.style);return e.staticStyle?M(e.staticStyle,t):t}function ci(e){return Array.isArray(e)?_(e):"string"==typeof e?ai(e):e}var ui,di=/^--/,hi=/\s*!important$/,fi=function(e,t,n){if(di.test(t))e.style.setProperty(t,n);else if(hi.test(n))e.style.setProperty(k(t),n.replace(hi,""),"important");else{var r=mi(t);if(Array.isArray(n))for(var i=0,o=n.length;i-1?t.split(yi).forEach((function(t){return e.classList.add(t)})):e.classList.add(t);else{var n=" "+(e.getAttribute("class")||"")+" ";n.indexOf(" "+t+" ")<0&&e.setAttribute("class",(n+t).trim())}}function wi(e,t){if(t&&(t=t.trim()))if(e.classList)t.indexOf(" ")>-1?t.split(yi).forEach((function(t){return e.classList.remove(t)})):e.classList.remove(t),e.classList.length||e.removeAttribute("class");else{for(var n=" "+(e.getAttribute("class")||"")+" ",r=" "+t+" ";n.indexOf(r)>=0;)n=n.replace(r," ");(n=n.trim())?e.setAttribute("class",n):e.removeAttribute("class")}}function xi(e){if(e){if("object"==typeof e){var t={};return!1!==e.css&&M(t,Si(e.name||"v")),M(t,e),t}return"string"==typeof e?Si(e):void 0}}var Si=y((function(e){return{enterClass:e+"-enter",enterToClass:e+"-enter-to",enterActiveClass:e+"-enter-active",leaveClass:e+"-leave",leaveToClass:e+"-leave-to",leaveActiveClass:e+"-leave-active"}})),ki=V&&!K,Ci="transition",Oi="transitionend",Mi="animation",_i="animationend";ki&&(void 0===window.ontransitionend&&void 0!==window.onwebkittransitionend&&(Ci="WebkitTransition",Oi="webkitTransitionEnd"),void 0===window.onanimationend&&void 0!==window.onwebkitanimationend&&(Mi="WebkitAnimation",_i="webkitAnimationEnd"));var Di=V?window.requestAnimationFrame?window.requestAnimationFrame.bind(window):setTimeout:function(e){return e()};function Ti(e){Di((function(){Di(e)}))}function $i(e,t){var n=e._transitionClasses||(e._transitionClasses=[]);n.indexOf(t)<0&&(n.push(t),bi(e,t))}function Ai(e,t){e._transitionClasses&&m(e._transitionClasses,t),wi(e,t)}function Ei(e,t,n){var r=Pi(e,t),i=r.type,o=r.timeout,s=r.propCount;if(!i)return n();var a="transition"===i?Oi:_i,l=0,c=function(){e.removeEventListener(a,u),n()},u=function(t){t.target===e&&++l>=s&&c()};setTimeout((function(){l0&&(n="transition",u=s,d=o.length):"animation"===t?c>0&&(n="animation",u=c,d=l.length):d=(n=(u=Math.max(s,c))>0?s>c?"transition":"animation":null)?"transition"===n?o.length:l.length:0,{type:n,timeout:u,propCount:d,hasTransform:"transition"===n&&Ni.test(r[Ci+"Property"])}}function Ii(e,t){for(;e.length1}function Bi(e,t){!0!==t.data.show&&zi(t)}var Vi=function(e){var o,s,a={},l=e.modules,c=e.nodeOps;for(o=0;op?b(e,t(i[v+1])?null:i[v+1].elm,i,f,v,o):f>v&&x(r,h,p)}(h,m,v,o,u):n(v)?(n(e.text)&&c.setTextContent(h,""),b(h,null,v,0,v.length-1,o)):n(m)?x(m,0,m.length-1):n(e.text)&&c.setTextContent(h,""):e.text!==i.text&&c.setTextContent(h,i.text),n(p)&&n(f=p.hook)&&n(f=f.postpatch)&&f(e,i)}}}function O(e,t,i){if(r(i)&&n(e.parent))e.parent.data.pendingInsert=t;else for(var o=0;o-1,s.selected!==o&&(s.selected=o);else if(A(Ki(s),r))return void(e.selectedIndex!==a&&(e.selectedIndex=a));i||(e.selectedIndex=-1)}}function Ji(e,t){return t.every((function(t){return!A(t,e)}))}function Ki(e){return"_value"in e?e._value:e.value}function Yi(e){e.target.composing=!0}function Ui(e){e.target.composing&&(e.target.composing=!1,Xi(e.target,"input"))}function Xi(e,t){var n=document.createEvent("HTMLEvents");n.initEvent(t,!0,!0),e.dispatchEvent(n)}function Gi(e){return!e.componentInstance||e.data&&e.data.transition?e:Gi(e.componentInstance._vnode)}var Zi={model:Wi,show:{bind:function(e,t,n){var r=t.value,i=(n=Gi(n)).data&&n.data.transition,o=e.__vOriginalDisplay="none"===e.style.display?"":e.style.display;r&&i?(n.data.show=!0,zi(n,(function(){e.style.display=o}))):e.style.display=r?o:"none"},update:function(e,t,n){var r=t.value;!r!=!t.oldValue&&((n=Gi(n)).data&&n.data.transition?(n.data.show=!0,r?zi(n,(function(){e.style.display=e.__vOriginalDisplay})):ji(n,(function(){e.style.display="none"}))):e.style.display=r?e.__vOriginalDisplay:"none")},unbind:function(e,t,n,r,i){i||(e.style.display=e.__vOriginalDisplay)}}},Qi={name:String,appear:Boolean,css:Boolean,mode:String,type:String,enterClass:String,leaveClass:String,enterToClass:String,leaveToClass:String,enterActiveClass:String,leaveActiveClass:String,appearClass:String,appearActiveClass:String,appearToClass:String,duration:[Number,String,Object]};function eo(e){var t=e&&e.componentOptions;return t&&t.Ctor.options.abstract?eo(Jt(t.children)):e}function to(e){var t={},n=e.$options;for(var r in n.propsData)t[r]=e[r];var i=n._parentListeners;for(var o in i)t[w(o)]=i[o];return t}function no(e,t){if(/\d-keep-alive$/.test(t.tag))return e("keep-alive",{props:t.componentOptions.propsData})}var ro=function(e){return e.tag||mt(e)},io=function(e){return"show"===e.name},oo={name:"transition",props:Qi,abstract:!0,render:function(e){var t=this,n=this.$slots.default;if(n&&(n=n.filter(ro)).length){var r=this.mode,o=n[0];if(function(e){for(;e=e.parent;)if(e.data.transition)return!0}(this.$vnode))return o;var s=eo(o);if(!s)return o;if(this._leaving)return no(e,o);var a="__transition-"+this._uid+"-";s.key=null==s.key?s.isComment?a+"comment":a+s.tag:i(s.key)?0===String(s.key).indexOf(a)?s.key:a+s.key:s.key;var l=(s.data||(s.data={})).transition=to(this),c=this._vnode,u=eo(c);if(s.data.directives&&s.data.directives.some(io)&&(s.data.show=!0),u&&u.data&&!function(e,t){return t.key===e.key&&t.tag===e.tag}(s,u)&&!mt(u)&&(!u.componentInstance||!u.componentInstance._vnode.isComment)){var d=u.data.transition=M({},l);if("out-in"===r)return this._leaving=!0,at(d,"afterLeave",(function(){t._leaving=!1,t.$forceUpdate()})),no(e,o);if("in-out"===r){if(mt(s))return c;var h,f=function(){h()};at(l,"afterEnter",f),at(l,"enterCancelled",f),at(d,"delayLeave",(function(e){h=e}))}}return o}}},so=M({tag:String,moveClass:String},Qi);delete so.mode;var ao={props:so,beforeMount:function(){var e=this,t=this._update;this._update=function(n,r){var i=Zt(e);e.__patch__(e._vnode,e.kept,!1,!0),e._vnode=e.kept,i(),t.call(e,n,r)}},render:function(e){for(var t=this.tag||this.$vnode.data.tag||"span",n=Object.create(null),r=this.prevChildren=this.children,i=this.$slots.default||[],o=this.children=[],s=to(this),a=0;a-1?Qn[e]=t.constructor===window.HTMLUnknownElement||t.constructor===window.HTMLElement:Qn[e]=/HTMLUnknownElement/.test(t.toString())},M(Mn.options.directives,Zi),M(Mn.options.components,ho),Mn.prototype.__patch__=V?Vi:D,Mn.prototype.$mount=function(e,t){return function(e,t,n){var r;return e.$el=t,e.$options.render||(e.$options.render=pe),nn(e,"beforeMount"),r=function(){e._update(e._render(),n)},new mn(e,r,D,{before:function(){e._isMounted&&!e._isDestroyed&&nn(e,"beforeUpdate")}},!0),n=!1,null==e.$vnode&&(e._isMounted=!0,nn(e,"mounted")),e}(this,e=e&&V?tr(e):void 0,t)},V&&setTimeout((function(){R.devtools&&ne&&ne.emit("init",Mn)}),0);var fo=/\{\{((?:.|\r?\n)+?)\}\}/g,po=/[-.*+?^${}()|[\]\/\\]/g,mo=y((function(e){var t=e[0].replace(po,"\\$&"),n=e[1].replace(po,"\\$&");return new RegExp(t+"((?:.|\\n)+?)"+n,"g")}));var go={staticKeys:["staticClass"],transformNode:function(e,t){t.warn;var n=Lr(e,"class");n&&(e.staticClass=JSON.stringify(n));var r=Fr(e,"class",!1);r&&(e.classBinding=r)},genData:function(e){var t="";return e.staticClass&&(t+="staticClass:"+e.staticClass+","),e.classBinding&&(t+="class:"+e.classBinding+","),t}};var vo,yo={staticKeys:["staticStyle"],transformNode:function(e,t){t.warn;var n=Lr(e,"style");n&&(e.staticStyle=JSON.stringify(ai(n)));var r=Fr(e,"style",!1);r&&(e.styleBinding=r)},genData:function(e){var t="";return e.staticStyle&&(t+="staticStyle:"+e.staticStyle+","),e.styleBinding&&(t+="style:("+e.styleBinding+"),"),t}},bo=function(e){return(vo=vo||document.createElement("div")).innerHTML=e,vo.textContent},wo=h("area,base,br,col,embed,frame,hr,img,input,isindex,keygen,link,meta,param,source,track,wbr"),xo=h("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source"),So=h("address,article,aside,base,blockquote,body,caption,col,colgroup,dd,details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,title,tr,track"),ko=/^\s*([^\s"'<>\/=]+)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/,Co=/^\s*((?:v-[\w-]+:|@|:|#)\[[^=]+?\][^\s"'<>\/=]*)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/,Oo="[a-zA-Z_][\\-\\.0-9_a-zA-Z"+z.source+"]*",Mo="((?:"+Oo+"\\:)?"+Oo+")",_o=new RegExp("^<"+Mo),Do=/^\s*(\/?)>/,To=new RegExp("^<\\/"+Mo+"[^>]*>"),$o=/^]+>/i,Ao=/^",""":'"',"&":"&"," ":"\n"," ":"\t","'":"'"},Ro=/&(?:lt|gt|quot|amp|#39);/g,zo=/&(?:lt|gt|quot|amp|#39|#10|#9);/g,jo=h("pre,textarea",!0),Fo=function(e,t){return e&&jo(e)&&"\n"===t[0]};function Lo(e,t){var n=t?zo:Ro;return e.replace(n,(function(e){return Io[e]}))}var Bo,Vo,Wo,qo,Ho,Jo,Ko,Yo,Uo=/^@|^v-on:/,Xo=/^v-|^@|^:|^#/,Go=/([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/,Zo=/,([^,\}\]]*)(?:,([^,\}\]]*))?$/,Qo=/^\(|\)$/g,es=/^\[.*\]$/,ts=/:(.*)$/,ns=/^:|^\.|^v-bind:/,rs=/\.[^.\]]+(?=[^\]]*$)/g,is=/^v-slot(:|$)|^#/,ss=/[\r\n]/,as=/[ \f\t\r\n]+/g,ls=y(bo);function cs(e,t,n){return{type:1,tag:e,attrsList:t,attrsMap:gs(t),rawAttrsMap:{},parent:n,children:[]}}function us(e,t){Bo=t.warn||Ar,Jo=t.isPreTag||T,Ko=t.mustUseProp||T,Yo=t.getTagNamespace||T,t.isReservedTag,Wo=Er(t.modules,"transformNode"),qo=Er(t.modules,"preTransformNode"),Ho=Er(t.modules,"postTransformNode"),Vo=t.delimiters;var n,r,i=[],o=!1!==t.preserveWhitespace,s=t.whitespace,a=!1,l=!1;function c(e){if(u(e),a||e.processed||(e=ds(e,t)),i.length||e===n||n.if&&(e.elseif||e.else)&&fs(n,{exp:e.elseif,block:e}),r&&!e.forbidden)if(e.elseif||e.else)s=e,c=function(e){for(var t=e.length;t--;){if(1===e[t].type)return e[t];e.pop()}}(r.children),c&&c.if&&fs(c,{exp:s.elseif,block:s});else{if(e.slotScope){var o=e.slotTarget||'"default"';(r.scopedSlots||(r.scopedSlots={}))[o]=e}r.children.push(e),e.parent=r}var s,c;e.children=e.children.filter((function(e){return!e.slotScope})),u(e),e.pre&&(a=!1),Jo(e.tag)&&(l=!1);for(var d=0;d]*>)","i")),h=e.replace(d,(function(e,n,r){return c=r.length,No(u)||"noscript"===u||(n=n.replace(//g,"$1").replace(//g,"$1")),Fo(u,n)&&(n=n.slice(1)),t.chars&&t.chars(n),""}));l+=e.length-h.length,e=h,M(u,l-c,l)}else{var f=e.indexOf("<");if(0===f){if(Ao.test(e)){var p=e.indexOf("--\x3e");if(p>=0){t.shouldKeepComment&&t.comment(e.substring(4,p),l,l+p+3),k(p+3);continue}}if(Eo.test(e)){var m=e.indexOf("]>");if(m>=0){k(m+2);continue}}var g=e.match($o);if(g){k(g[0].length);continue}var v=e.match(To);if(v){var y=l;k(v[0].length),M(v[1],y,l);continue}var b=C();if(b){O(b),Fo(b.tagName,e)&&k(1);continue}}var w=void 0,x=void 0,S=void 0;if(f>=0){for(x=e.slice(f);!(To.test(x)||_o.test(x)||Ao.test(x)||Eo.test(x)||(S=x.indexOf("<",1))<0);)f+=S,x=e.slice(f);w=e.substring(0,f)}f<0&&(w=e),w&&k(w.length),t.chars&&w&&t.chars(w,l-w.length,l)}if(e===n){t.chars&&t.chars(e);break}}function k(t){l+=t,e=e.substring(t)}function C(){var t=e.match(_o);if(t){var n,r,i={tagName:t[1],attrs:[],start:l};for(k(t[0].length);!(n=e.match(Do))&&(r=e.match(Co)||e.match(ko));)r.start=l,k(r[0].length),r.end=l,i.attrs.push(r);if(n)return i.unarySlash=n[1],k(n[0].length),i.end=l,i}}function O(e){var n=e.tagName,l=e.unarySlash;o&&("p"===r&&So(n)&&M(r),a(n)&&r===n&&M(n));for(var c=s(n)||!!l,u=e.attrs.length,d=new Array(u),h=0;h=0&&i[s].lowerCasedTag!==a;s--);else s=0;if(s>=0){for(var c=i.length-1;c>=s;c--)t.end&&t.end(i[c].tag,n,o);i.length=s,r=s&&i[s-1].tag}else"br"===a?t.start&&t.start(e,[],!0,n,o):"p"===a&&(t.start&&t.start(e,[],!1,n,o),t.end&&t.end(e,n,o))}M()}(e,{warn:Bo,expectHTML:t.expectHTML,isUnaryTag:t.isUnaryTag,canBeLeftOpenTag:t.canBeLeftOpenTag,shouldDecodeNewlines:t.shouldDecodeNewlines,shouldDecodeNewlinesForHref:t.shouldDecodeNewlinesForHref,shouldKeepComment:t.comments,outputSourceRange:t.outputSourceRange,start:function(e,o,s,u,d){var h=r&&r.ns||Yo(e);J&&"svg"===h&&(o=function(e){for(var t=[],n=0;nl&&(a.push(o=e.slice(l,i)),s.push(JSON.stringify(o)));var c=Tr(r[1].trim());s.push("_s("+c+")"),a.push({"@binding":c}),l=i+r[0].length}return l-1"+("true"===o?":("+t+")":":_q("+t+","+o+")")),jr(e,"change","var $$a="+t+",$$el=$event.target,$$c=$$el.checked?("+o+"):("+s+");if(Array.isArray($$a)){var $$v="+(r?"_n("+i+")":i)+",$$i=_i($$a,$$v);if($$el.checked){$$i<0&&("+qr(t,"$$a.concat([$$v])")+")}else{$$i>-1&&("+qr(t,"$$a.slice(0,$$i).concat($$a.slice($$i+1))")+")}}else{"+qr(t,"$$c")+"}",null,!0)}(e,r,i);else if("input"===o&&"radio"===s)!function(e,t,n){var r=n&&n.number,i=Fr(e,"value")||"null";Nr(e,"checked","_q("+t+","+(i=r?"_n("+i+")":i)+")"),jr(e,"change",qr(t,i),null,!0)}(e,r,i);else if("input"===o||"textarea"===o)!function(e,t,n){var r=e.attrsMap.type,i=n||{},o=i.lazy,s=i.number,a=i.trim,l=!o&&"range"!==r,c=o?"change":"range"===r?"__r":"input",u="$event.target.value";a&&(u="$event.target.value.trim()");s&&(u="_n("+u+")");var d=qr(t,u);l&&(d="if($event.target.composing)return;"+d);Nr(e,"value","("+t+")"),jr(e,c,d,null,!0),(a||s)&&jr(e,"blur","$forceUpdate()")}(e,r,i);else if(!R.isReservedTag(o))return Wr(e,r,i),!1;return!0},text:function(e,t){t.value&&Nr(e,"textContent","_s("+t.value+")",t)},html:function(e,t){t.value&&Nr(e,"innerHTML","_s("+t.value+")",t)}},Os={expectHTML:!0,modules:ws,directives:Cs,isPreTag:function(e){return"pre"===e},isUnaryTag:wo,mustUseProp:Rn,canBeLeftOpenTag:xo,isReservedTag:Gn,getTagNamespace:Zn,staticKeys:(xs=ws,xs.reduce((function(e,t){return e.concat(t.staticKeys||[])}),[]).join(","))},Ms=y((function(e){return h("type,tag,attrsList,attrsMap,plain,parent,children,attrs,start,end,rawAttrsMap"+(e?","+e:""))}));function _s(e,t){e&&(Ss=Ms(t.staticKeys||""),ks=t.isReservedTag||T,Ds(e),Ts(e,!1))}function Ds(e){if(e.static=function(e){if(2===e.type)return!1;if(3===e.type)return!0;return!(!e.pre&&(e.hasBindings||e.if||e.for||f(e.tag)||!ks(e.tag)||function(e){for(;e.parent;){if("template"!==(e=e.parent).tag)return!1;if(e.for)return!0}return!1}(e)||!Object.keys(e).every(Ss)))}(e),1===e.type){if(!ks(e.tag)&&"slot"!==e.tag&&null==e.attrsMap["inline-template"])return;for(var t=0,n=e.children.length;t|^function(?:\s+[\w$]+)?\s*\(/,As=/\([^)]*?\);*$/,Es=/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/,Ns={esc:27,tab:9,enter:13,space:32,up:38,left:37,right:39,down:40,delete:[8,46]},Ps={esc:["Esc","Escape"],tab:"Tab",enter:"Enter",space:[" ","Spacebar"],up:["Up","ArrowUp"],left:["Left","ArrowLeft"],right:["Right","ArrowRight"],down:["Down","ArrowDown"],delete:["Backspace","Delete","Del"]},Is=function(e){return"if("+e+")return null;"},Rs={stop:"$event.stopPropagation();",prevent:"$event.preventDefault();",self:Is("$event.target !== $event.currentTarget"),ctrl:Is("!$event.ctrlKey"),shift:Is("!$event.shiftKey"),alt:Is("!$event.altKey"),meta:Is("!$event.metaKey"),left:Is("'button' in $event && $event.button !== 0"),middle:Is("'button' in $event && $event.button !== 1"),right:Is("'button' in $event && $event.button !== 2")};function zs(e,t){var n=t?"nativeOn:":"on:",r="",i="";for(var o in e){var s=js(e[o]);e[o]&&e[o].dynamic?i+=o+","+s+",":r+='"'+o+'":'+s+","}return r="{"+r.slice(0,-1)+"}",i?n+"_d("+r+",["+i.slice(0,-1)+"])":n+r}function js(e){if(!e)return"function(){}";if(Array.isArray(e))return"["+e.map((function(e){return js(e)})).join(",")+"]";var t=Es.test(e.value),n=$s.test(e.value),r=Es.test(e.value.replace(As,""));if(e.modifiers){var i="",o="",s=[];for(var a in e.modifiers)if(Rs[a])o+=Rs[a],Ns[a]&&s.push(a);else if("exact"===a){var l=e.modifiers;o+=Is(["ctrl","shift","alt","meta"].filter((function(e){return!l[e]})).map((function(e){return"$event."+e+"Key"})).join("||"))}else s.push(a);return s.length&&(i+=function(e){return"if(!$event.type.indexOf('key')&&"+e.map(Fs).join("&&")+")return null;"}(s)),o&&(i+=o),"function($event){"+i+(t?"return "+e.value+".apply(null, arguments)":n?"return ("+e.value+").apply(null, arguments)":r?"return "+e.value:e.value)+"}"}return t||n?e.value:"function($event){"+(r?"return "+e.value:e.value)+"}"}function Fs(e){var t=parseInt(e,10);if(t)return"$event.keyCode!=="+t;var n=Ns[e],r=Ps[e];return"_k($event.keyCode,"+JSON.stringify(e)+","+JSON.stringify(n)+",$event.key,"+JSON.stringify(r)+")"}var Ls={on:function(e,t){e.wrapListeners=function(e){return"_g("+e+","+t.value+")"}},bind:function(e,t){e.wrapData=function(n){return"_b("+n+",'"+e.tag+"',"+t.value+","+(t.modifiers&&t.modifiers.prop?"true":"false")+(t.modifiers&&t.modifiers.sync?",true":"")+")"}},cloak:D},Bs=function(e){this.options=e,this.warn=e.warn||Ar,this.transforms=Er(e.modules,"transformCode"),this.dataGenFns=Er(e.modules,"genData"),this.directives=M(M({},Ls),e.directives);var t=e.isReservedTag||T;this.maybeComponent=function(e){return!!e.component||!t(e.tag)},this.onceId=0,this.staticRenderFns=[],this.pre=!1};function Vs(e,t){var n=new Bs(t);return{render:"with(this){return "+(e?"script"===e.tag?"null":Ws(e,n):'_c("div")')+"}",staticRenderFns:n.staticRenderFns}}function Ws(e,t){if(e.parent&&(e.pre=e.pre||e.parent.pre),e.staticRoot&&!e.staticProcessed)return qs(e,t);if(e.once&&!e.onceProcessed)return Hs(e,t);if(e.for&&!e.forProcessed)return Ys(e,t);if(e.if&&!e.ifProcessed)return Js(e,t);if("template"!==e.tag||e.slotTarget||t.pre){if("slot"===e.tag)return function(e,t){var n=e.slotName||'"default"',r=Zs(e,t),i="_t("+n+(r?",function(){return "+r+"}":""),o=e.attrs||e.dynamicAttrs?ta((e.attrs||[]).concat(e.dynamicAttrs||[]).map((function(e){return{name:w(e.name),value:e.value,dynamic:e.dynamic}}))):null,s=e.attrsMap["v-bind"];!o&&!s||r||(i+=",null");o&&(i+=","+o);s&&(i+=(o?"":",null")+","+s);return i+")"}(e,t);var n;if(e.component)n=function(e,t,n){var r=t.inlineTemplate?null:Zs(t,n,!0);return"_c("+e+","+Us(t,n)+(r?","+r:"")+")"}(e.component,e,t);else{var r;(!e.plain||e.pre&&t.maybeComponent(e))&&(r=Us(e,t));var i=e.inlineTemplate?null:Zs(e,t,!0);n="_c('"+e.tag+"'"+(r?","+r:"")+(i?","+i:"")+")"}for(var o=0;o>>0}(s):"")+")"}(e,e.scopedSlots,t)+","),e.model&&(n+="model:{value:"+e.model.value+",callback:"+e.model.callback+",expression:"+e.model.expression+"},"),e.inlineTemplate){var o=function(e,t){var n=e.children[0];if(n&&1===n.type){var r=Vs(n,t.options);return"inlineTemplate:{render:function(){"+r.render+"},staticRenderFns:["+r.staticRenderFns.map((function(e){return"function(){"+e+"}"})).join(",")+"]}"}}(e,t);o&&(n+=o+",")}return n=n.replace(/,$/,"")+"}",e.dynamicAttrs&&(n="_b("+n+',"'+e.tag+'",'+ta(e.dynamicAttrs)+")"),e.wrapData&&(n=e.wrapData(n)),e.wrapListeners&&(n=e.wrapListeners(n)),n}function Xs(e){return 1===e.type&&("slot"===e.tag||e.children.some(Xs))}function Gs(e,t){var n=e.attrsMap["slot-scope"];if(e.if&&!e.ifProcessed&&!n)return Js(e,t,Gs,"null");if(e.for&&!e.forProcessed)return Ys(e,t,Gs);var r="_empty_"===e.slotScope?"":String(e.slotScope),i="function("+r+"){return "+("template"===e.tag?e.if&&n?"("+e.if+")?"+(Zs(e,t)||"undefined")+":undefined":Zs(e,t)||"undefined":Ws(e,t))+"}",o=r?"":",proxy:true";return"{key:"+(e.slotTarget||'"default"')+",fn:"+i+o+"}"}function Zs(e,t,n,r,i){var o=e.children;if(o.length){var s=o[0];if(1===o.length&&s.for&&"template"!==s.tag&&"slot"!==s.tag){var a=n?t.maybeComponent(s)?",1":",0":"";return""+(r||Ws)(s,t)+a}var l=n?function(e,t){for(var n=0,r=0;r':'

',sa.innerHTML.indexOf(" ")>0}var ua=!!V&&ca(!1),da=!!V&&ca(!0),ha=y((function(e){var t=tr(e);return t&&t.innerHTML})),fa=Mn.prototype.$mount;Mn.prototype.$mount=function(e,t){if((e=e&&tr(e))===document.body||e===document.documentElement)return this;var n=this.$options;if(!n.render){var r=n.template;if(r)if("string"==typeof r)"#"===r.charAt(0)&&(r=ha(r));else{if(!r.nodeType)return this;r=r.innerHTML}else e&&(r=function(e){if(e.outerHTML)return e.outerHTML;var t=document.createElement("div");return t.appendChild(e.cloneNode(!0)),t.innerHTML}(e));if(r){var i=la(r,{outputSourceRange:!1,shouldDecodeNewlines:ua,shouldDecodeNewlinesForHref:da,delimiters:n.delimiters,comments:n.comments},this),o=i.render,s=i.staticRenderFns;n.render=o,n.staticRenderFns=s}}return fa.call(this,e,t)},Mn.compile=la;var pa=("undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).__VUE_DEVTOOLS_GLOBAL_HOOK__;function ma(e,t){if(void 0===t&&(t=[]),null===e||"object"!=typeof e)return e;var n,r=(n=function(t){return t.original===e},t.filter(n)[0]);if(r)return r.copy;var i=Array.isArray(e)?[]:{};return t.push({original:e,copy:i}),Object.keys(e).forEach((function(n){i[n]=ma(e[n],t)})),i}function ga(e,t){Object.keys(e).forEach((function(n){return t(e[n],n)}))}function va(e){return null!==e&&"object"==typeof e}var ya=function(e,t){this.runtime=t,this._children=Object.create(null),this._rawModule=e;var n=e.state;this.state=("function"==typeof n?n():n)||{}},ba={namespaced:{configurable:!0}};ba.namespaced.get=function(){return!!this._rawModule.namespaced},ya.prototype.addChild=function(e,t){this._children[e]=t},ya.prototype.removeChild=function(e){delete this._children[e]},ya.prototype.getChild=function(e){return this._children[e]},ya.prototype.hasChild=function(e){return e in this._children},ya.prototype.update=function(e){this._rawModule.namespaced=e.namespaced,e.actions&&(this._rawModule.actions=e.actions),e.mutations&&(this._rawModule.mutations=e.mutations),e.getters&&(this._rawModule.getters=e.getters)},ya.prototype.forEachChild=function(e){ga(this._children,e)},ya.prototype.forEachGetter=function(e){this._rawModule.getters&&ga(this._rawModule.getters,e)},ya.prototype.forEachAction=function(e){this._rawModule.actions&&ga(this._rawModule.actions,e)},ya.prototype.forEachMutation=function(e){this._rawModule.mutations&&ga(this._rawModule.mutations,e)},Object.defineProperties(ya.prototype,ba);var wa,xa=function(e){this.register([],e,!1)};function Sa(e,t,n){if(t.update(n),n.modules)for(var r in n.modules){if(!t.getChild(r))return;Sa(e.concat(r),t.getChild(r),n.modules[r])}}xa.prototype.get=function(e){return e.reduce((function(e,t){return e.getChild(t)}),this.root)},xa.prototype.getNamespace=function(e){var t=this.root;return e.reduce((function(e,n){return e+((t=t.getChild(n)).namespaced?n+"/":"")}),"")},xa.prototype.update=function(e){Sa([],this.root,e)},xa.prototype.register=function(e,t,n){var r=this;void 0===n&&(n=!0);var i=new ya(t,n);0===e.length?this.root=i:this.get(e.slice(0,-1)).addChild(e[e.length-1],i);t.modules&&ga(t.modules,(function(t,i){r.register(e.concat(i),t,n)}))},xa.prototype.unregister=function(e){var t=this.get(e.slice(0,-1)),n=e[e.length-1],r=t.getChild(n);r&&r.runtime&&t.removeChild(n)},xa.prototype.isRegistered=function(e){var t=this.get(e.slice(0,-1)),n=e[e.length-1];return!!t&&t.hasChild(n)};var ka=function(e){var t=this;void 0===e&&(e={}),!wa&&"undefined"!=typeof window&&window.Vue&&Aa(window.Vue);var n=e.plugins;void 0===n&&(n=[]);var r=e.strict;void 0===r&&(r=!1),this._committing=!1,this._actions=Object.create(null),this._actionSubscribers=[],this._mutations=Object.create(null),this._wrappedGetters=Object.create(null),this._modules=new xa(e),this._modulesNamespaceMap=Object.create(null),this._subscribers=[],this._watcherVM=new wa,this._makeLocalGettersCache=Object.create(null);var i=this,o=this.dispatch,s=this.commit;this.dispatch=function(e,t){return o.call(i,e,t)},this.commit=function(e,t,n){return s.call(i,e,t,n)},this.strict=r;var a=this._modules.root.state;Da(this,a,[],this._modules.root),_a(this,a),n.forEach((function(e){return e(t)})),(void 0!==e.devtools?e.devtools:wa.config.devtools)&&function(e){pa&&(e._devtoolHook=pa,pa.emit("vuex:init",e),pa.on("vuex:travel-to-state",(function(t){e.replaceState(t)})),e.subscribe((function(e,t){pa.emit("vuex:mutation",e,t)}),{prepend:!0}),e.subscribeAction((function(e,t){pa.emit("vuex:action",e,t)}),{prepend:!0}))}(this)},Ca={state:{configurable:!0}};function Oa(e,t,n){return t.indexOf(e)<0&&(n&&n.prepend?t.unshift(e):t.push(e)),function(){var n=t.indexOf(e);n>-1&&t.splice(n,1)}}function Ma(e,t){e._actions=Object.create(null),e._mutations=Object.create(null),e._wrappedGetters=Object.create(null),e._modulesNamespaceMap=Object.create(null);var n=e.state;Da(e,n,[],e._modules.root,!0),_a(e,n,t)}function _a(e,t,n){var r=e._vm;e.getters={},e._makeLocalGettersCache=Object.create(null);var i=e._wrappedGetters,o={};ga(i,(function(t,n){o[n]=function(e,t){return function(){return e(t)}}(t,e),Object.defineProperty(e.getters,n,{get:function(){return e._vm[n]},enumerable:!0})}));var s=wa.config.silent;wa.config.silent=!0,e._vm=new wa({data:{$$state:t},computed:o}),wa.config.silent=s,e.strict&&function(e){e._vm.$watch((function(){return this._data.$$state}),(function(){}),{deep:!0,sync:!0})}(e),r&&(n&&e._withCommit((function(){r._data.$$state=null})),wa.nextTick((function(){return r.$destroy()})))}function Da(e,t,n,r,i){var o=!n.length,s=e._modules.getNamespace(n);if(r.namespaced&&(e._modulesNamespaceMap[s],e._modulesNamespaceMap[s]=r),!o&&!i){var a=Ta(t,n.slice(0,-1)),l=n[n.length-1];e._withCommit((function(){wa.set(a,l,r.state)}))}var c=r.context=function(e,t,n){var r=""===t,i={dispatch:r?e.dispatch:function(n,r,i){var o=$a(n,r,i),s=o.payload,a=o.options,l=o.type;return a&&a.root||(l=t+l),e.dispatch(l,s)},commit:r?e.commit:function(n,r,i){var o=$a(n,r,i),s=o.payload,a=o.options,l=o.type;a&&a.root||(l=t+l),e.commit(l,s,a)}};return Object.defineProperties(i,{getters:{get:r?function(){return e.getters}:function(){return function(e,t){if(!e._makeLocalGettersCache[t]){var n={},r=t.length;Object.keys(e.getters).forEach((function(i){if(i.slice(0,r)===t){var o=i.slice(r);Object.defineProperty(n,o,{get:function(){return e.getters[i]},enumerable:!0})}})),e._makeLocalGettersCache[t]=n}return e._makeLocalGettersCache[t]}(e,t)}},state:{get:function(){return Ta(e.state,n)}}}),i}(e,s,n);r.forEachMutation((function(t,n){!function(e,t,n,r){(e._mutations[t]||(e._mutations[t]=[])).push((function(t){n.call(e,r.state,t)}))}(e,s+n,t,c)})),r.forEachAction((function(t,n){var r=t.root?n:s+n,i=t.handler||t;!function(e,t,n,r){(e._actions[t]||(e._actions[t]=[])).push((function(t){var i,o=n.call(e,{dispatch:r.dispatch,commit:r.commit,getters:r.getters,state:r.state,rootGetters:e.getters,rootState:e.state},t);return(i=o)&&"function"==typeof i.then||(o=Promise.resolve(o)),e._devtoolHook?o.catch((function(t){throw e._devtoolHook.emit("vuex:error",t),t})):o}))}(e,r,i,c)})),r.forEachGetter((function(t,n){!function(e,t,n,r){if(e._wrappedGetters[t])return;e._wrappedGetters[t]=function(e){return n(r.state,r.getters,e.state,e.getters)}}(e,s+n,t,c)})),r.forEachChild((function(r,o){Da(e,t,n.concat(o),r,i)}))}function Ta(e,t){return t.reduce((function(e,t){return e[t]}),e)}function $a(e,t,n){return va(e)&&e.type&&(n=t,t=e,e=e.type),{type:e,payload:t,options:n}}function Aa(e){wa&&e===wa|| +var t=Object.freeze({}),e=Array.isArray;function n(t){return null==t}function r(t){return null!=t}function o(t){return!0===t}function i(t){return"string"==typeof t||"number"==typeof t||"symbol"==typeof t||"boolean"==typeof t}function s(t){return"function"==typeof t}function a(t){return null!==t&&"object"==typeof t}var l=Object.prototype.toString;function c(t){return"[object Object]"===l.call(t)}function u(t){var e=parseFloat(String(t));return e>=0&&Math.floor(e)===e&&isFinite(t)}function d(t){return r(t)&&"function"==typeof t.then&&"function"==typeof t.catch}function h(t){return null==t?"":Array.isArray(t)||c(t)&&t.toString===l?JSON.stringify(t,null,2):String(t)}function f(t){var e=parseFloat(t);return isNaN(e)?t:e}function p(t,e){for(var n=Object.create(null),r=t.split(","),o=0;o-1)return t.splice(n,1)}}var y=Object.prototype.hasOwnProperty;function b(t,e){return y.call(t,e)}function w(t){var e=Object.create(null);return function(n){return e[n]||(e[n]=t(n))}}var x=/-(\w)/g,S=w((function(t){return t.replace(x,(function(t,e){return e?e.toUpperCase():""}))})),k=w((function(t){return t.charAt(0).toUpperCase()+t.slice(1)})),_=/\B([A-Z])/g,O=w((function(t){return t.replace(_,"-$1").toLowerCase()}));var C=Function.prototype.bind?function(t,e){return t.bind(e)}:function(t,e){function n(n){var r=arguments.length;return r?r>1?t.apply(e,arguments):t.call(e,n):t.call(e)}return n._length=t.length,n};function M(t,e){e=e||0;for(var n=t.length-e,r=new Array(n);n--;)r[n]=t[n+e];return r}function D(t,e){for(var n in e)t[n]=e[n];return t}function T(t){for(var e={},n=0;n0,U=J&&J.indexOf("edge/")>0;J&&J.indexOf("android");var G=J&&/iphone|ipad|ipod|ios/.test(J);J&&/chrome\/\d+/.test(J),J&&/phantomjs/.test(J);var X,Z=J&&J.match(/firefox\/(\d+)/),Q={}.watch,tt=!1;if(H)try{var et={};Object.defineProperty(et,"passive",{get:function(){tt=!0}}),window.addEventListener("test-passive",null,et)}catch(jy){}var nt=function(){return void 0===X&&(X=!H&&"undefined"!=typeof global&&(global.process&&"server"===global.process.env.VUE_ENV)),X},rt=H&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__;function ot(t){return"function"==typeof t&&/native code/.test(t.toString())}var it,st="undefined"!=typeof Symbol&&ot(Symbol)&&"undefined"!=typeof Reflect&&ot(Reflect.ownKeys);it="undefined"!=typeof Set&&ot(Set)?Set:function(){function t(){this.set=Object.create(null)}return t.prototype.has=function(t){return!0===this.set[t]},t.prototype.add=function(t){this.set[t]=!0},t.prototype.clear=function(){this.set=Object.create(null)},t}();var at=null;function lt(t){void 0===t&&(t=null),t||at&&at._scope.off(),at=t,t&&t._scope.on()}var ct=$,ut=0,dt=function(){function t(){this.id=ut++,this.subs=[]}return t.prototype.addSub=function(t){this.subs.push(t)},t.prototype.removeSub=function(t){v(this.subs,t)},t.prototype.depend=function(e){t.target&&t.target.addDep(this)},t.prototype.notify=function(t){for(var e=this.subs.slice(),n=0,r=e.length;n0&&(Pt((l=It(l,"".concat(s||"","_").concat(a)))[0])&&Pt(u)&&(d[c]=vt(u.text+l[0].text),l.shift()),d.push.apply(d,l)):i(l)?Pt(u)?d[c]=vt(u.text+l):""!==l&&d.push(vt(l)):Pt(l)&&Pt(u)?d[c]=vt(u.text+l.text):(o(t._isVList)&&r(l.tag)&&n(l.key)&&r(s)&&(l.key="__vlist".concat(s,"_").concat(a,"__")),d.push(l)));return d}function Rt(e){var n=e.$options,r=n.setup;if(r){var o=e._setupContext=function(e){return{get attrs(){return function(e){if(!e._attrsProxy){var n=e._attrsProxy={};V(n,"_v_attr_proxy",!0),zt(n,e.$attrs,t,e)}return e._attrsProxy}(e)},get slots(){return function(t){t._slotsProxy||Ft(t._slotsProxy={},t.$scopedSlots);return t._slotsProxy}(e)},emit:C(e.$emit,e),expose:function(t){t&&Object.keys(t).forEach((function(n){return _t(e,t,n)}))}}}(e);lt(e),ft();var i=rn(r,null,[e._props||xt({}),o],e,"setup");if(pt(),lt(),s(i))n.render=i;else if(a(i))if(e._setupState=i,i.__sfc){var l=e._setupProxy={};for(var c in i)"__sfc"!==c&&_t(l,i,c)}else for(var c in i)B(c)||_t(e,i,c)}}function zt(t,e,n,r){var o=!1;for(var i in e)i in t?e[i]!==n[i]&&(o=!0):(o=!0,jt(t,i,r));for(var i in t)i in e||(o=!0,delete t[i]);return o}function jt(t,e,n){Object.defineProperty(t,e,{enumerable:!0,configurable:!0,get:function(){return n.$attrs[e]}})}function Ft(t,e){for(var n in e)t[n]=e[n];for(var n in t)n in e||delete t[n]}var Lt={enumerable:!0,configurable:!0,get:$,set:$};function Bt(t,e,n){Lt.get=function(){return this[e][n]},Lt.set=function(t){this[e][n]=t},Object.defineProperty(t,n,Lt)}function Vt(t){var n=t.$options;if(n.props&&function(t,e){var n=t.$options.propsData||{},r=t._props=xt({}),o=t.$options._propKeys=[];t.$parent&&wn(!1);var i=function(i){o.push(i);var s=Rn(i,e,n,t);_n(r,i,s),i in t||Bt(t,"_props",i)};for(var s in e)i(s);wn(!0)}(t,n.props),Rt(t),n.methods&&function(t,e){for(var n in t.$options.props,e)t[n]="function"!=typeof e[n]?$:C(e[n],t)}(t,n.methods),n.data)!function(t){var e=t.$options.data;c(e=t._data=s(e)?function(t,e){ft();try{return t.call(e,e)}catch(jy){return nn(jy,e,"data()"),{}}finally{pt()}}(e,t):e||{})||(e={});var n=Object.keys(e),r=t.$options.props;t.$options.methods;var o=n.length;for(;o--;){var i=n[o];r&&b(r,i)||B(i)||Bt(t,"_data",i)}var a=kn(e);a&&a.vmCount++}(t);else{var r=kn(t._data={});r&&r.vmCount++}n.computed&&function(t,e){var n=t._computedWatchers=Object.create(null),r=nt();for(var o in e){var i=e[o],a=s(i)?i:i.get;r||(n[o]=new en(t,a||$,$,qt)),o in t||Ht(t,o,i)}}(t,n.computed),n.watch&&n.watch!==Q&&function(t,n){for(var r in n){var o=n[r];if(e(o))for(var i=0;i0,a=n?!!n.$stable:!s,l=n&&n.$key;if(n){if(n._normalized)return n._normalized;if(a&&o&&o!==t&&l===o.$key&&!s&&!o.$hasNormal)return o;for(var c in i={},n)n[c]&&"$"!==c[0]&&(i[c]=oe(e,r,c,n[c]))}else i={};for(var u in r)u in i||(i[u]=ie(r,u));return n&&Object.isExtensible(n)&&(n._normalized=i),V(i,"$stable",a),V(i,"$key",l),V(i,"$hasNormal",s),i}function oe(t,n,r,o){var i=function(){var n=at;lt(t);var r=arguments.length?o.apply(null,arguments):o({}),i=(r=r&&"object"==typeof r&&!e(r)?[r]:At(r))&&r[0];return lt(n),r&&(!i||1===r.length&&i.isComment&&!ne(i))?void 0:r};return o.proxy&&Object.defineProperty(n,r,{get:i,enumerable:!0,configurable:!0}),i}function ie(t,e){return function(){return t[e]}}function se(t,n){var o,i,s,l,c=null;if(e(t)||"string"==typeof t)for(c=new Array(t.length),o=0,i=t.length;odocument.createEvent("Event").timeStamp&&(Xe=function(){return Ze.now()})}function Qe(){var t,e;for(Ge=Xe(),Ye=!0,qe.sort((function(t,e){return t.id-e.id})),Ue=0;UeUe&&qe[n].id>t.id;)n--;qe.splice(n+1,0,t)}else qe.push(t);Ke||(Ke=!0,gn(Qe))}}(this)},t.prototype.run=function(){if(this.active){var t=this.get();if(t!==this.value||a(t)||this.deep){var e=this.value;if(this.value=t,this.user){var n='callback for watcher "'.concat(this.expression,'"');rn(this.cb,this.vm,[t,e],this.vm,n)}else this.cb.call(this.vm,t,e)}}},t.prototype.evaluate=function(){this.value=this.get(),this.dirty=!1},t.prototype.depend=function(){for(var t=this.deps.length;t--;)this.deps[t].depend()},t.prototype.teardown=function(){if(this.vm&&!this.vm._isBeingDestroyed&&v(this.vm._scope.effects,this),this.active){for(var t=this.deps.length;t--;)this.deps[t].removeSub(this);this.active=!1,this.onStop&&this.onStop()}},t}();function nn(t,e,n){ft();try{if(e)for(var r=e;r=r.$parent;){var o=r.$options.errorCaptured;if(o)for(var i=0;i-1)if(i&&!b(o,"default"))a=!1;else if(""===a||a===O(t)){var c=Ln(String,o.type);(c<0||l-1:"string"==typeof t?t.split(",").indexOf(n)>-1:(r=t,"[object RegExp]"===l.call(r)&&t.test(n));var r}function Hn(t,e){var n=t.cache,r=t.keys,o=t._vnode;for(var i in n){var s=n[i];if(s){var a=s.name;a&&!e(a)&&Jn(n,i,r,o)}}}function Jn(t,e,n,r){var o=t[e];!o||r&&o.tag===r.tag||o.componentInstance.$destroy(),t[e]=null,v(n,e)}Bn.prototype._init=function(e){var n=this;n._uid=Zt++,n._isVue=!0,n.__v_skip=!0,n._scope=new Xt(!0),e&&e._isComponent?function(t,e){var n=t.$options=Object.create(t.constructor.options),r=e._parentVnode;n.parent=e.parent,n._parentVnode=r;var o=r.componentOptions;n.propsData=o.propsData,n._parentListeners=o.listeners,n._renderChildren=o.children,n._componentTag=o.tag,e.render&&(n.render=e.render,n.staticRenderFns=e.staticRenderFns)}(n,e):n.$options=Pn(Qt(n.constructor),e||{},n),n._renderProxy=n,n._self=n,function(t){var e=t.$options,n=e.parent;if(n&&!e.abstract){for(;n.$options.abstract&&n.$parent;)n=n.$parent;n.$children.push(t)}t.$parent=n,t.$root=n?n.$root:t,t.$children=[],t.$refs={},t._provided=n?n._provided:Object.create(null),t._watcher=null,t._inactive=null,t._directInactive=!1,t._isMounted=!1,t._isDestroyed=!1,t._isBeingDestroyed=!1}(n),function(t){t._events=Object.create(null),t._hasHookEvent=!1;var e=t.$options._parentListeners;e&&ze(t,e)}(n),function(e){e._vnode=null,e._staticTrees=null;var n=e.$options,r=e.$vnode=n._parentVnode,o=r&&r.context;e.$slots=te(n._renderChildren,o),e.$scopedSlots=t,e._c=function(t,n,r,o){return De(e,t,n,r,o,!1)},e.$createElement=function(t,n,r,o){return De(e,t,n,r,o,!0)};var i=r&&r.data;_n(e,"$attrs",i&&i.attrs||t,null,!0),_n(e,"$listeners",n._parentListeners||t,null,!0)}(n),We(n,"beforeCreate"),function(t){var e=Gt(t.$options.inject,t);e&&(wn(!1),Object.keys(e).forEach((function(n){_n(t,n,e[n])})),wn(!0))}(n),Vt(n),function(t){var e=t.$options.provide;if(e){var n=s(e)?e.call(t):e;if(!a(n))return;var r=st?Reflect.ownKeys(n):Object.keys(n);lt(t);for(var o=0;o1?M(n):n;for(var r=M(arguments,1),o='event handler for "'.concat(t,'"'),i=0,s=n.length;iparseInt(this.max)&&Jn(e,n[0],n,this._vnode),this.vnodeToCache=null}}},created:function(){this.cache=Object.create(null),this.keys=[]},destroyed:function(){for(var t in this.cache)Jn(this.cache,t,this.keys)},mounted:function(){var t=this;this.cacheVNode(),this.$watch("include",(function(e){Hn(t,(function(t){return qn(e,t)}))})),this.$watch("exclude",(function(e){Hn(t,(function(t){return!qn(e,t)}))}))},updated:function(){this.cacheVNode()},render:function(){var t=this.$slots.default,e=Ae(t),n=e&&e.componentOptions;if(n){var r=Wn(n),o=this.include,i=this.exclude;if(o&&(!r||!qn(o,r))||i&&r&&qn(i,r))return e;var s=this.cache,a=this.keys,l=null==e.key?n.Ctor.cid+(n.tag?"::".concat(n.tag):""):e.key;s[l]?(e.componentInstance=s[l].componentInstance,v(a,l),a.push(l)):(this.vnodeToCache=e,this.keyToCache=l),e.data.keepAlive=!0}return e||t&&t[0]}}};!function(t){var e={get:function(){return F}};Object.defineProperty(t,"config",e),t.util={warn:ct,extend:D,mergeOptions:Pn,defineReactive:_n},t.set=On,t.delete=Cn,t.nextTick=gn,t.observable=function(t){return kn(t),t},t.options=Object.create(null),z.forEach((function(e){t.options[e+"s"]=Object.create(null)})),t.options._base=t,D(t.options.components,Yn),function(t){t.use=function(t){var e=this._installedPlugins||(this._installedPlugins=[]);if(e.indexOf(t)>-1)return this;var n=M(arguments,1);return n.unshift(this),s(t.install)?t.install.apply(t,n):s(t)&&t.apply(null,n),e.push(t),this}}(t),function(t){t.mixin=function(t){return this.options=Pn(this.options,t),this}}(t),Vn(t),function(t){z.forEach((function(e){t[e]=function(t,n){return n?("component"===e&&c(n)&&(n.name=n.name||t,n=this.options._base.extend(n)),"directive"===e&&s(n)&&(n={bind:n,update:n}),this.options[e+"s"][t]=n,n):this.options[e+"s"][t]}}))}(t)}(Bn),Object.defineProperty(Bn.prototype,"$isServer",{get:nt}),Object.defineProperty(Bn.prototype,"$ssrContext",{get:function(){return this.$vnode&&this.$vnode.ssrContext}}),Object.defineProperty(Bn,"FunctionalRenderContext",{value:xe}),Bn.version="2.7.4";var Un=p("style,class"),Gn=p("input,textarea,option,select,progress"),Xn=function(t,e,n){return"value"===n&&Gn(t)&&"button"!==e||"selected"===n&&"option"===t||"checked"===n&&"input"===t||"muted"===n&&"video"===t},Zn=p("contenteditable,draggable,spellcheck"),Qn=p("events,caret,typing,plaintext-only"),tr=p("allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,default,defaultchecked,defaultmuted,defaultselected,defer,disabled,enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,required,reversed,scoped,seamless,selected,sortable,truespeed,typemustmatch,visible"),er="http://www.w3.org/1999/xlink",nr=function(t){return":"===t.charAt(5)&&"xlink"===t.slice(0,5)},rr=function(t){return nr(t)?t.slice(6,t.length):""},or=function(t){return null==t||!1===t};function ir(t){for(var e=t.data,n=t,o=t;r(o.componentInstance);)(o=o.componentInstance._vnode)&&o.data&&(e=sr(o.data,e));for(;r(n=n.parent);)n&&n.data&&(e=sr(e,n.data));return function(t,e){if(r(t)||r(e))return ar(t,lr(e));return""}(e.staticClass,e.class)}function sr(t,e){return{staticClass:ar(t.staticClass,e.staticClass),class:r(t.class)?[t.class,e.class]:e.class}}function ar(t,e){return t?e?t+" "+e:t:e||""}function lr(t){return Array.isArray(t)?function(t){for(var e,n="",o=0,i=t.length;o-1?Pr(t,e,n):tr(e)?or(n)?t.removeAttribute(e):(n="allowfullscreen"===e&&"EMBED"===t.tagName?"true":e,t.setAttribute(e,n)):Zn(e)?t.setAttribute(e,function(t,e){return or(e)||"false"===e?"false":"contenteditable"===t&&Qn(e)?e:"true"}(e,n)):nr(e)?or(n)?t.removeAttributeNS(er,rr(e)):t.setAttributeNS(er,e,n):Pr(t,e,n)}function Pr(t,e,n){if(or(n))t.removeAttribute(e);else{if(K&&!Y&&"TEXTAREA"===t.tagName&&"placeholder"===e&&""!==n&&!t.__ieph){var r=function(e){e.stopImmediatePropagation(),t.removeEventListener("input",r)};t.addEventListener("input",r),t.__ieph=!0}t.setAttribute(e,n)}}var Ir={create:Nr,update:Nr};function Rr(t,e){var o=e.elm,i=e.data,s=t.data;if(!(n(i.staticClass)&&n(i.class)&&(n(s)||n(s.staticClass)&&n(s.class)))){var a=ir(e),l=o._transitionClasses;r(l)&&(a=ar(a,lr(l))),a!==o._prevClass&&(o.setAttribute("class",a),o._prevClass=a)}}var zr,jr,Fr,Lr,Br,Vr,Wr={create:Rr,update:Rr},qr=/[\w).+\-_$\]]/;function Hr(t){var e,n,r,o,i,s=!1,a=!1,l=!1,c=!1,u=0,d=0,h=0,f=0;for(r=0;r=0&&" "===(m=t.charAt(p));p--);m&&qr.test(m)||(c=!0)}}else void 0===o?(f=r+1,o=t.slice(0,r).trim()):g();function g(){(i||(i=[])).push(t.slice(f,r).trim()),f=r+1}if(void 0===o?o=t.slice(0,r).trim():0!==f&&g(),i)for(r=0;r-1?{exp:t.slice(0,Lr),key:'"'+t.slice(Lr+1)+'"'}:{exp:t,key:null};jr=t,Lr=Br=Vr=0;for(;!lo();)co(Fr=ao())?ho(Fr):91===Fr&&uo(Fr);return{exp:t.slice(0,Br),key:t.slice(Br+1,Vr)}}(t);return null===n.key?"".concat(t,"=").concat(e):"$set(".concat(n.exp,", ").concat(n.key,", ").concat(e,")")}function ao(){return jr.charCodeAt(++Lr)}function lo(){return Lr>=zr}function co(t){return 34===t||39===t}function uo(t){var e=1;for(Br=Lr;!lo();)if(co(t=ao()))ho(t);else if(91===t&&e++,93===t&&e--,0===e){Vr=Lr;break}}function ho(t){for(var e=t;!lo()&&(t=ao())!==e;);}var fo;function po(t,e,n){var r=fo;return function o(){var i=e.apply(null,arguments);null!==i&&vo(t,o,n,r)}}var mo=ln&&!(Z&&Number(Z[1])<=53);function go(t,e,n,r){if(mo){var o=Ge,i=e;e=i._wrapper=function(t){if(t.target===t.currentTarget||t.timeStamp>=o||t.timeStamp<=0||t.target.ownerDocument!==document)return i.apply(this,arguments)}}fo.addEventListener(t,e,tt?{capture:n,passive:r}:n)}function vo(t,e,n,r){(r||fo).removeEventListener(t,e._wrapper||e,n)}function yo(t,e){if(!n(t.data.on)||!n(e.data.on)){var o=e.data.on||{},i=t.data.on||{};fo=e.elm||t.elm,function(t){if(r(t.__r)){var e=K?"change":"input";t[e]=[].concat(t.__r,t[e]||[]),delete t.__r}r(t.__c)&&(t.change=[].concat(t.__c,t.change||[]),delete t.__c)}(o),$t(o,i,go,vo,po,e.context),fo=void 0}}var bo,wo={create:yo,update:yo,destroy:function(t){return yo(t,xr)}};function xo(t,e){if(!n(t.data.domProps)||!n(e.data.domProps)){var i,s,a=e.elm,l=t.data.domProps||{},c=e.data.domProps||{};for(i in(r(c.__ob__)||o(c._v_attr_proxy))&&(c=e.data.domProps=D({},c)),l)i in c||(a[i]="");for(i in c){if(s=c[i],"textContent"===i||"innerHTML"===i){if(e.children&&(e.children.length=0),s===l[i])continue;1===a.childNodes.length&&a.removeChild(a.childNodes[0])}if("value"===i&&"PROGRESS"!==a.tagName){a._value=s;var u=n(s)?"":String(s);So(a,u)&&(a.value=u)}else if("innerHTML"===i&&dr(a.tagName)&&n(a.innerHTML)){(bo=bo||document.createElement("div")).innerHTML="".concat(s,"");for(var d=bo.firstChild;a.firstChild;)a.removeChild(a.firstChild);for(;d.firstChild;)a.appendChild(d.firstChild)}else if(s!==l[i])try{a[i]=s}catch(jy){}}}}function So(t,e){return!t.composing&&("OPTION"===t.tagName||function(t,e){var n=!0;try{n=document.activeElement!==t}catch(jy){}return n&&t.value!==e}(t,e)||function(t,e){var n=t.value,o=t._vModifiers;if(r(o)){if(o.number)return f(n)!==f(e);if(o.trim)return n.trim()!==e.trim()}return n!==e}(t,e))}var ko={create:xo,update:xo},_o=w((function(t){var e={},n=/:(.+)/;return t.split(/;(?![^(]*\))/g).forEach((function(t){if(t){var r=t.split(n);r.length>1&&(e[r[0].trim()]=r[1].trim())}})),e}));function Oo(t){var e=Co(t.style);return t.staticStyle?D(t.staticStyle,e):e}function Co(t){return Array.isArray(t)?T(t):"string"==typeof t?_o(t):t}var Mo,Do=/^--/,To=/\s*!important$/,$o=function(t,e,n){if(Do.test(e))t.style.setProperty(e,n);else if(To.test(n))t.style.setProperty(O(e),n.replace(To,""),"important");else{var r=No(e);if(Array.isArray(n))for(var o=0,i=n.length;o-1?e.split(Io).forEach((function(e){return t.classList.add(e)})):t.classList.add(e);else{var n=" ".concat(t.getAttribute("class")||""," ");n.indexOf(" "+e+" ")<0&&t.setAttribute("class",(n+e).trim())}}function zo(t,e){if(e&&(e=e.trim()))if(t.classList)e.indexOf(" ")>-1?e.split(Io).forEach((function(e){return t.classList.remove(e)})):t.classList.remove(e),t.classList.length||t.removeAttribute("class");else{for(var n=" ".concat(t.getAttribute("class")||""," "),r=" "+e+" ";n.indexOf(r)>=0;)n=n.replace(r," ");(n=n.trim())?t.setAttribute("class",n):t.removeAttribute("class")}}function jo(t){if(t){if("object"==typeof t){var e={};return!1!==t.css&&D(e,Fo(t.name||"v")),D(e,t),e}return"string"==typeof t?Fo(t):void 0}}var Fo=w((function(t){return{enterClass:"".concat(t,"-enter"),enterToClass:"".concat(t,"-enter-to"),enterActiveClass:"".concat(t,"-enter-active"),leaveClass:"".concat(t,"-leave"),leaveToClass:"".concat(t,"-leave-to"),leaveActiveClass:"".concat(t,"-leave-active")}})),Lo=H&&!Y,Bo="transition",Vo="transitionend",Wo="animation",qo="animationend";Lo&&(void 0===window.ontransitionend&&void 0!==window.onwebkittransitionend&&(Bo="WebkitTransition",Vo="webkitTransitionEnd"),void 0===window.onanimationend&&void 0!==window.onwebkitanimationend&&(Wo="WebkitAnimation",qo="webkitAnimationEnd"));var Ho=H?window.requestAnimationFrame?window.requestAnimationFrame.bind(window):setTimeout:function(t){return t()};function Jo(t){Ho((function(){Ho(t)}))}function Ko(t,e){var n=t._transitionClasses||(t._transitionClasses=[]);n.indexOf(e)<0&&(n.push(e),Ro(t,e))}function Yo(t,e){t._transitionClasses&&v(t._transitionClasses,e),zo(t,e)}function Uo(t,e,n){var r=Xo(t,e),o=r.type,i=r.timeout,s=r.propCount;if(!o)return n();var a="transition"===o?Vo:qo,l=0,c=function(){t.removeEventListener(a,u),n()},u=function(e){e.target===t&&++l>=s&&c()};setTimeout((function(){l0&&(n="transition",u=s,d=i.length):"animation"===e?c>0&&(n="animation",u=c,d=l.length):d=(n=(u=Math.max(s,c))>0?s>c?"transition":"animation":null)?"transition"===n?i.length:l.length:0,{type:n,timeout:u,propCount:d,hasTransform:"transition"===n&&Go.test(r[Bo+"Property"])}}function Zo(t,e){for(;t.length1}function oi(t,e){!0!==e.data.show&&ti(e)}var ii=function(t){var s,a,l={},c=t.modules,u=t.nodeOps;for(s=0;sp?w(t,n(o[v+1])?null:o[v+1].elm,o,f,v,i):f>v&&S(e,d,p)}(d,m,g,i,c):r(g)?(r(t.text)&&u.setTextContent(d,""),w(d,null,g,0,g.length-1,i)):r(m)?S(m,0,m.length-1):r(t.text)&&u.setTextContent(d,""):t.text!==e.text&&u.setTextContent(d,e.text),r(p)&&r(f=p.hook)&&r(f=f.postpatch)&&f(t,e)}}}function C(t,e,n){if(o(n)&&r(t.parent))t.parent.data.pendingInsert=e;else for(var i=0;i-1,s.selected!==i&&(s.selected=i);else if(A(ui(s),r))return void(t.selectedIndex!==a&&(t.selectedIndex=a));o||(t.selectedIndex=-1)}}function ci(t,e){return e.every((function(e){return!A(e,t)}))}function ui(t){return"_value"in t?t._value:t.value}function di(t){t.target.composing=!0}function hi(t){t.target.composing&&(t.target.composing=!1,fi(t.target,"input"))}function fi(t,e){var n=document.createEvent("HTMLEvents");n.initEvent(e,!0,!0),t.dispatchEvent(n)}function pi(t){return!t.componentInstance||t.data&&t.data.transition?t:pi(t.componentInstance._vnode)}var mi={model:si,show:{bind:function(t,e,n){var r=e.value,o=(n=pi(n)).data&&n.data.transition,i=t.__vOriginalDisplay="none"===t.style.display?"":t.style.display;r&&o?(n.data.show=!0,ti(n,(function(){t.style.display=i}))):t.style.display=r?i:"none"},update:function(t,e,n){var r=e.value;!r!=!e.oldValue&&((n=pi(n)).data&&n.data.transition?(n.data.show=!0,r?ti(n,(function(){t.style.display=t.__vOriginalDisplay})):ei(n,(function(){t.style.display="none"}))):t.style.display=r?t.__vOriginalDisplay:"none")},unbind:function(t,e,n,r,o){o||(t.style.display=t.__vOriginalDisplay)}}},gi={name:String,appear:Boolean,css:Boolean,mode:String,type:String,enterClass:String,leaveClass:String,enterToClass:String,leaveToClass:String,enterActiveClass:String,leaveActiveClass:String,appearClass:String,appearActiveClass:String,appearToClass:String,duration:[Number,String,Object]};function vi(t){var e=t&&t.componentOptions;return e&&e.Ctor.options.abstract?vi(Ae(e.children)):t}function yi(t){var e={},n=t.$options;for(var r in n.propsData)e[r]=t[r];var o=n._parentListeners;for(var r in o)e[S(r)]=o[r];return e}function bi(t,e){if(/\d-keep-alive$/.test(e.tag))return t("keep-alive",{props:e.componentOptions.propsData})}var wi=function(t){return t.tag||ne(t)},xi=function(t){return"show"===t.name},Si={name:"transition",props:gi,abstract:!0,render:function(t){var e=this,n=this.$slots.default;if(n&&(n=n.filter(wi)).length){var r=this.mode,o=n[0];if(function(t){for(;t=t.parent;)if(t.data.transition)return!0}(this.$vnode))return o;var s=vi(o);if(!s)return o;if(this._leaving)return bi(t,o);var a="__transition-".concat(this._uid,"-");s.key=null==s.key?s.isComment?a+"comment":a+s.tag:i(s.key)?0===String(s.key).indexOf(a)?s.key:a+s.key:s.key;var l=(s.data||(s.data={})).transition=yi(this),c=this._vnode,u=vi(c);if(s.data.directives&&s.data.directives.some(xi)&&(s.data.show=!0),u&&u.data&&!function(t,e){return e.key===t.key&&e.tag===t.tag}(s,u)&&!ne(u)&&(!u.componentInstance||!u.componentInstance._vnode.isComment)){var d=u.data.transition=D({},l);if("out-in"===r)return this._leaving=!0,Et(d,"afterLeave",(function(){e._leaving=!1,e.$forceUpdate()})),bi(t,o);if("in-out"===r){if(ne(s))return c;var h,f=function(){h()};Et(l,"afterEnter",f),Et(l,"enterCancelled",f),Et(d,"delayLeave",(function(t){h=t}))}}return o}}},ki=D({tag:String,moveClass:String},gi);delete ki.mode;var _i={props:ki,beforeMount:function(){var t=this,e=this._update;this._update=function(n,r){var o=Fe(t);t.__patch__(t._vnode,t.kept,!1,!0),t._vnode=t.kept,o(),e.call(t,n,r)}},render:function(t){for(var e=this.tag||this.$vnode.data.tag||"span",n=Object.create(null),r=this.prevChildren=this.children,o=this.$slots.default||[],i=this.children=[],s=yi(this),a=0;a-1?pr[t]=e.constructor===window.HTMLUnknownElement||e.constructor===window.HTMLElement:pr[t]=/HTMLUnknownElement/.test(e.toString())},D(Bn.options.directives,mi),D(Bn.options.components,Di),Bn.prototype.__patch__=H?ii:$,Bn.prototype.$mount=function(t,e){return function(t,e,n){var r;t.$el=e,t.$options.render||(t.$options.render=gt),We(t,"beforeMount"),r=function(){t._update(t._render(),n)},new en(t,r,$,{before:function(){t._isMounted&&!t._isDestroyed&&We(t,"beforeUpdate")}},!0),n=!1;var o=t._preWatchers;if(o)for(var i=0;i\/=]+)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/,Li=/^\s*((?:v-[\w-]+:|@|:|#)\[[^=]+?\][^\s"'<>\/=]*)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/,Bi="[a-zA-Z_][\\-\\.0-9_a-zA-Z".concat(L.source,"]*"),Vi="((?:".concat(Bi,"\\:)?").concat(Bi,")"),Wi=new RegExp("^<".concat(Vi)),qi=/^\s*(\/?)>/,Hi=new RegExp("^<\\/".concat(Vi,"[^>]*>")),Ji=/^]+>/i,Ki=/^",""":'"',"&":"&"," ":"\n"," ":"\t","'":"'"},Zi=/&(?:lt|gt|quot|amp|#39);/g,Qi=/&(?:lt|gt|quot|amp|#39|#10|#9);/g,ts=p("pre,textarea",!0),es=function(t,e){return t&&ts(t)&&"\n"===e[0]};function ns(t,e){var n=e?Qi:Zi;return t.replace(n,(function(t){return Xi[t]}))}function rs(t,e){for(var n,r,o=[],i=e.expectHTML,s=e.isUnaryTag||E,a=e.canBeLeftOpenTag||E,l=0,c=function(){if(n=t,r&&Ui(r)){var c=0,h=r.toLowerCase(),f=Gi[h]||(Gi[h]=new RegExp("([\\s\\S]*?)(]*>)","i"));S=t.replace(f,(function(t,n,r){return c=r.length,Ui(h)||"noscript"===h||(n=n.replace(//g,"$1").replace(//g,"$1")),es(h,n)&&(n=n.slice(1)),e.chars&&e.chars(n),""}));l+=t.length-S.length,t=S,d(h,l-c,l)}else{var p=t.indexOf("<");if(0===p){if(Ki.test(t)){var m=t.indexOf("--\x3e");if(m>=0)return e.shouldKeepComment&&e.comment&&e.comment(t.substring(4,m),l,l+m+3),u(m+3),"continue"}if(Yi.test(t)){var g=t.indexOf("]>");if(g>=0)return u(g+2),"continue"}var v=t.match(Ji);if(v)return u(v[0].length),"continue";var y=t.match(Hi);if(y){var b=l;return u(y[0].length),d(y[1],b,l),"continue"}var w=function(){var e=t.match(Wi);if(e){var n={tagName:e[1],attrs:[],start:l};u(e[0].length);for(var r=void 0,o=void 0;!(r=t.match(qi))&&(o=t.match(Li)||t.match(Fi));)o.start=l,u(o[0].length),o.end=l,n.attrs.push(o);if(r)return n.unarySlash=r[1],u(r[0].length),n.end=l,n}}();if(w)return function(t){var n=t.tagName,l=t.unarySlash;i&&("p"===r&&ji(n)&&d(r),a(n)&&r===n&&d(n));for(var c=s(n)||!!l,u=t.attrs.length,h=new Array(u),f=0;f=0){for(S=t.slice(p);!(Hi.test(S)||Wi.test(S)||Ki.test(S)||Yi.test(S)||(k=S.indexOf("<",1))<0);)p+=k,S=t.slice(p);x=t.substring(0,p)}p<0&&(x=t),x&&u(x.length),e.chars&&x&&e.chars(x,l-x.length,l)}if(t===n)return e.chars&&e.chars(t),"break"};t;){if("break"===c())break}function u(e){l+=e,t=t.substring(e)}function d(t,n,i){var s,a;if(null==n&&(n=l),null==i&&(i=l),t)for(a=t.toLowerCase(),s=o.length-1;s>=0&&o[s].lowerCasedTag!==a;s--);else s=0;if(s>=0){for(var c=o.length-1;c>=s;c--)e.end&&e.end(o[c].tag,n,i);o.length=s,r=s&&o[s-1].tag}else"br"===a?e.start&&e.start(t,[],!0,n,i):"p"===a&&(e.start&&e.start(t,[],!1,n,i),e.end&&e.end(t,n,i))}d()}var is,ss,as,ls,cs,us,ds,hs,fs=/^@|^v-on:/,ps=/^v-|^@|^:|^#/,ms=/([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/,gs=/,([^,\}\]]*)(?:,([^,\}\]]*))?$/,vs=/^\(|\)$/g,ys=/^\[.*\]$/,bs=/:(.*)$/,ws=/^:|^\.|^v-bind:/,xs=/\.[^.\]]+(?=[^\]]*$)/g,Ss=/^v-slot(:|$)|^#/,ks=/[\r\n]/,_s=/[ \f\t\r\n]+/g,Os=w(Ii);function Cs(t,e,n){return{type:1,tag:t,attrsList:e,attrsMap:As(e),rawAttrsMap:{},parent:n,children:[]}}function Ms(t,e){is=e.warn||Kr,us=e.isPreTag||E,ds=e.mustUseProp||E,hs=e.getTagNamespace||E,e.isReservedTag,as=Yr(e.modules,"transformNode"),ls=Yr(e.modules,"preTransformNode"),cs=Yr(e.modules,"postTransformNode"),ss=e.delimiters;var n,r,o=[],i=!1!==e.preserveWhitespace,s=e.whitespace,a=!1,l=!1;function c(t){if(u(t),a||t.processed||(t=Ds(t,e)),o.length||t===n||n.if&&(t.elseif||t.else)&&$s(n,{exp:t.elseif,block:t}),r&&!t.forbidden)if(t.elseif||t.else)s=t,c=function(t){for(var e=t.length;e--;){if(1===t[e].type)return t[e];t.pop()}}(r.children),c&&c.if&&$s(c,{exp:s.elseif,block:s});else{if(t.slotScope){var i=t.slotTarget||'"default"';(r.scopedSlots||(r.scopedSlots={}))[i]=t}r.children.push(t),t.parent=r}var s,c;t.children=t.children.filter((function(t){return!t.slotScope})),u(t),t.pre&&(a=!1),us(t.tag)&&(l=!1);for(var d=0;dl&&(a.push(i=t.slice(l,o)),s.push(JSON.stringify(i)));var c=Hr(r[1].trim());s.push("_s(".concat(c,")")),a.push({"@binding":c}),l=o+r[0].length}return l-1")+("true"===i?":(".concat(e,")"):":_q(".concat(e,",").concat(i,")"))),to(t,"change","var $$a=".concat(e,",")+"$$el=$event.target,"+"$$c=$$el.checked?(".concat(i,"):(").concat(s,");")+"if(Array.isArray($$a)){"+"var $$v=".concat(r?"_n("+o+")":o,",")+"$$i=_i($$a,$$v);"+"if($$el.checked){$$i<0&&(".concat(so(e,"$$a.concat([$$v])"),")}")+"else{$$i>-1&&(".concat(so(e,"$$a.slice(0,$$i).concat($$a.slice($$i+1))"),")}")+"}else{".concat(so(e,"$$c"),"}"),null,!0)}(t,r,o);else if("input"===i&&"radio"===s)!function(t,e,n){var r=n&&n.number,o=eo(t,"value")||"null";o=r?"_n(".concat(o,")"):o,Ur(t,"checked","_q(".concat(e,",").concat(o,")")),to(t,"change",so(e,o),null,!0)}(t,r,o);else if("input"===i||"textarea"===i)!function(t,e,n){var r=t.attrsMap.type,o=n||{},i=o.lazy,s=o.number,a=o.trim,l=!i&&"range"!==r,c=i?"change":"range"===r?"__r":"input",u="$event.target.value";a&&(u="$event.target.value.trim()");s&&(u="_n(".concat(u,")"));var d=so(e,u);l&&(d="if($event.target.composing)return;".concat(d));Ur(t,"value","(".concat(e,")")),to(t,c,d,null,!0),(a||s)&&to(t,"blur","$forceUpdate()")}(t,r,o);else if(!F.isReservedTag(i))return io(t,r,o),!1;return!0},text:function(t,e){e.value&&Ur(t,"textContent","_s(".concat(e.value,")"),e)},html:function(t,e){e.value&&Ur(t,"innerHTML","_s(".concat(e.value,")"),e)}},Vs={expectHTML:!0,modules:zs,directives:Bs,isPreTag:function(t){return"pre"===t},isUnaryTag:Ri,mustUseProp:Xn,canBeLeftOpenTag:zi,isReservedTag:hr,getTagNamespace:fr,staticKeys:(js=zs,js.reduce((function(t,e){return t.concat(e.staticKeys||[])}),[]).join(","))},Ws=w((function(t){return p("type,tag,attrsList,attrsMap,plain,parent,children,attrs,start,end,rawAttrsMap"+(t?","+t:""))}));function qs(t,e){t&&(Fs=Ws(e.staticKeys||""),Ls=e.isReservedTag||E,Hs(t),Js(t,!1))}function Hs(t){if(t.static=function(t){if(2===t.type)return!1;if(3===t.type)return!0;return!(!t.pre&&(t.hasBindings||t.if||t.for||m(t.tag)||!Ls(t.tag)||function(t){for(;t.parent;){if("template"!==(t=t.parent).tag)return!1;if(t.for)return!0}return!1}(t)||!Object.keys(t).every(Fs)))}(t),1===t.type){if(!Ls(t.tag)&&"slot"!==t.tag&&null==t.attrsMap["inline-template"])return;for(var e=0,n=t.children.length;e|^function(?:\s+[\w$]+)?\s*\(/,Ys=/\([^)]*?\);*$/,Us=/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/,Gs={esc:27,tab:9,enter:13,space:32,up:38,left:37,right:39,down:40,delete:[8,46]},Xs={esc:["Esc","Escape"],tab:"Tab",enter:"Enter",space:[" ","Spacebar"],up:["Up","ArrowUp"],left:["Left","ArrowLeft"],right:["Right","ArrowRight"],down:["Down","ArrowDown"],delete:["Backspace","Delete","Del"]},Zs=function(t){return"if(".concat(t,")return null;")},Qs={stop:"$event.stopPropagation();",prevent:"$event.preventDefault();",self:Zs("$event.target !== $event.currentTarget"),ctrl:Zs("!$event.ctrlKey"),shift:Zs("!$event.shiftKey"),alt:Zs("!$event.altKey"),meta:Zs("!$event.metaKey"),left:Zs("'button' in $event && $event.button !== 0"),middle:Zs("'button' in $event && $event.button !== 1"),right:Zs("'button' in $event && $event.button !== 2")};function ta(t,e){var n=e?"nativeOn:":"on:",r="",o="";for(var i in t){var s=ea(t[i]);t[i]&&t[i].dynamic?o+="".concat(i,",").concat(s,","):r+='"'.concat(i,'":').concat(s,",")}return r="{".concat(r.slice(0,-1),"}"),o?n+"_d(".concat(r,",[").concat(o.slice(0,-1),"])"):n+r}function ea(t){if(!t)return"function(){}";if(Array.isArray(t))return"[".concat(t.map((function(t){return ea(t)})).join(","),"]");var e=Us.test(t.value),n=Ks.test(t.value),r=Us.test(t.value.replace(Ys,""));if(t.modifiers){var o="",i="",s=[],a=function(e){if(Qs[e])i+=Qs[e],Gs[e]&&s.push(e);else if("exact"===e){var n=t.modifiers;i+=Zs(["ctrl","shift","alt","meta"].filter((function(t){return!n[t]})).map((function(t){return"$event.".concat(t,"Key")})).join("||"))}else s.push(e)};for(var l in t.modifiers)a(l);s.length&&(o+=function(t){return"if(!$event.type.indexOf('key')&&"+"".concat(t.map(na).join("&&"),")return null;")}(s)),i&&(o+=i);var c=e?"return ".concat(t.value,".apply(null, arguments)"):n?"return (".concat(t.value,").apply(null, arguments)"):r?"return ".concat(t.value):t.value;return"function($event){".concat(o).concat(c,"}")}return e||n?t.value:"function($event){".concat(r?"return ".concat(t.value):t.value,"}")}function na(t){var e=parseInt(t,10);if(e)return"$event.keyCode!==".concat(e);var n=Gs[t],r=Xs[t];return"_k($event.keyCode,"+"".concat(JSON.stringify(t),",")+"".concat(JSON.stringify(n),",")+"$event.key,"+"".concat(JSON.stringify(r))+")"}var ra={on:function(t,e){t.wrapListeners=function(t){return"_g(".concat(t,",").concat(e.value,")")}},bind:function(t,e){t.wrapData=function(n){return"_b(".concat(n,",'").concat(t.tag,"',").concat(e.value,",").concat(e.modifiers&&e.modifiers.prop?"true":"false").concat(e.modifiers&&e.modifiers.sync?",true":"",")")}},cloak:$},oa=function(t){this.options=t,this.warn=t.warn||Kr,this.transforms=Yr(t.modules,"transformCode"),this.dataGenFns=Yr(t.modules,"genData"),this.directives=D(D({},ra),t.directives);var e=t.isReservedTag||E;this.maybeComponent=function(t){return!!t.component||!e(t.tag)},this.onceId=0,this.staticRenderFns=[],this.pre=!1};function ia(t,e){var n=new oa(e),r=t?"script"===t.tag?"null":sa(t,n):'_c("div")';return{render:"with(this){return ".concat(r,"}"),staticRenderFns:n.staticRenderFns}}function sa(t,e){if(t.parent&&(t.pre=t.pre||t.parent.pre),t.staticRoot&&!t.staticProcessed)return la(t,e);if(t.once&&!t.onceProcessed)return ca(t,e);if(t.for&&!t.forProcessed)return ha(t,e);if(t.if&&!t.ifProcessed)return ua(t,e);if("template"!==t.tag||t.slotTarget||e.pre){if("slot"===t.tag)return function(t,e){var n=t.slotName||'"default"',r=ga(t,e),o="_t(".concat(n).concat(r?",function(){return ".concat(r,"}"):""),i=t.attrs||t.dynamicAttrs?ba((t.attrs||[]).concat(t.dynamicAttrs||[]).map((function(t){return{name:S(t.name),value:t.value,dynamic:t.dynamic}}))):null,s=t.attrsMap["v-bind"];!i&&!s||r||(o+=",null");i&&(o+=",".concat(i));s&&(o+="".concat(i?"":",null",",").concat(s));return o+")"}(t,e);var n=void 0;if(t.component)n=function(t,e,n){var r=e.inlineTemplate?null:ga(e,n,!0);return"_c(".concat(t,",").concat(fa(e,n)).concat(r?",".concat(r):"",")")}(t.component,t,e);else{var r=void 0;(!t.plain||t.pre&&e.maybeComponent(t))&&(r=fa(t,e));var o=void 0,i=e.options.bindings;i&&!1!==i.__isScriptSetup&&(o=aa(i,t.tag)||aa(i,S(t.tag))||aa(i,k(S(t.tag)))),o||(o="'".concat(t.tag,"'"));var s=t.inlineTemplate?null:ga(t,e,!0);n="_c(".concat(o).concat(r?",".concat(r):"").concat(s?",".concat(s):"",")")}for(var a=0;a>>0}(s)):"",")")}(t,t.scopedSlots,e),",")),t.model&&(n+="model:{value:".concat(t.model.value,",callback:").concat(t.model.callback,",expression:").concat(t.model.expression,"},")),t.inlineTemplate){var i=function(t,e){var n=t.children[0];if(n&&1===n.type){var r=ia(n,e.options);return"inlineTemplate:{render:function(){".concat(r.render,"},staticRenderFns:[").concat(r.staticRenderFns.map((function(t){return"function(){".concat(t,"}")})).join(","),"]}")}}(t,e);i&&(n+="".concat(i,","))}return n=n.replace(/,$/,"")+"}",t.dynamicAttrs&&(n="_b(".concat(n,',"').concat(t.tag,'",').concat(ba(t.dynamicAttrs),")")),t.wrapData&&(n=t.wrapData(n)),t.wrapListeners&&(n=t.wrapListeners(n)),n}function pa(t){return 1===t.type&&("slot"===t.tag||t.children.some(pa))}function ma(t,e){var n=t.attrsMap["slot-scope"];if(t.if&&!t.ifProcessed&&!n)return ua(t,e,ma,"null");if(t.for&&!t.forProcessed)return ha(t,e,ma);var r="_empty_"===t.slotScope?"":String(t.slotScope),o="function(".concat(r,"){")+"return ".concat("template"===t.tag?t.if&&n?"(".concat(t.if,")?").concat(ga(t,e)||"undefined",":undefined"):ga(t,e)||"undefined":sa(t,e),"}"),i=r?"":",proxy:true";return"{key:".concat(t.slotTarget||'"default"',",fn:").concat(o).concat(i,"}")}function ga(t,e,n,r,o){var i=t.children;if(i.length){var s=i[0];if(1===i.length&&s.for&&"template"!==s.tag&&"slot"!==s.tag){var a=n?e.maybeComponent(s)?",1":",0":"";return"".concat((r||sa)(s,e)).concat(a)}var l=n?function(t,e){for(var n=0,r=0;r':'
',_a.innerHTML.indexOf(" ")>0}var Da=!!H&&Ma(!1),Ta=!!H&&Ma(!0),$a=w((function(t){var e=gr(t);return e&&e.innerHTML})),Ea=Bn.prototype.$mount;Bn.prototype.$mount=function(t,e){if((t=t&&gr(t))===document.body||t===document.documentElement)return this;var n=this.$options;if(!n.render){var r=n.template;if(r)if("string"==typeof r)"#"===r.charAt(0)&&(r=$a(r));else{if(!r.nodeType)return this;r=r.innerHTML}else t&&(r=function(t){if(t.outerHTML)return t.outerHTML;var e=document.createElement("div");return e.appendChild(t.cloneNode(!0)),e.innerHTML}(t));if(r){var o=Ca(r,{outputSourceRange:!1,shouldDecodeNewlines:Da,shouldDecodeNewlinesForHref:Ta,delimiters:n.delimiters,comments:n.comments},this),i=o.render,s=o.staticRenderFns;n.render=i,n.staticRenderFns=s}}return Ea.call(this,t,e)},Bn.compile=Ca;var Na=("undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).__VUE_DEVTOOLS_GLOBAL_HOOK__;function Aa(t,e){if(void 0===e&&(e=[]),null===t||"object"!=typeof t)return t;var n,r=(n=function(e){return e.original===t},e.filter(n)[0]);if(r)return r.copy;var o=Array.isArray(t)?[]:{};return e.push({original:t,copy:o}),Object.keys(t).forEach((function(n){o[n]=Aa(t[n],e)})),o}function Pa(t,e){Object.keys(t).forEach((function(n){return e(t[n],n)}))}function Ia(t){return null!==t&&"object"==typeof t}var Ra=function(t,e){this.runtime=e,this._children=Object.create(null),this._rawModule=t;var n=t.state;this.state=("function"==typeof n?n():n)||{}},za={namespaced:{configurable:!0}};za.namespaced.get=function(){return!!this._rawModule.namespaced},Ra.prototype.addChild=function(t,e){this._children[t]=e},Ra.prototype.removeChild=function(t){delete this._children[t]},Ra.prototype.getChild=function(t){return this._children[t]},Ra.prototype.hasChild=function(t){return t in this._children},Ra.prototype.update=function(t){this._rawModule.namespaced=t.namespaced,t.actions&&(this._rawModule.actions=t.actions),t.mutations&&(this._rawModule.mutations=t.mutations),t.getters&&(this._rawModule.getters=t.getters)},Ra.prototype.forEachChild=function(t){Pa(this._children,t)},Ra.prototype.forEachGetter=function(t){this._rawModule.getters&&Pa(this._rawModule.getters,t)},Ra.prototype.forEachAction=function(t){this._rawModule.actions&&Pa(this._rawModule.actions,t)},Ra.prototype.forEachMutation=function(t){this._rawModule.mutations&&Pa(this._rawModule.mutations,t)},Object.defineProperties(Ra.prototype,za);var ja,Fa=function(t){this.register([],t,!1)};function La(t,e,n){if(e.update(n),n.modules)for(var r in n.modules){if(!e.getChild(r))return;La(t.concat(r),e.getChild(r),n.modules[r])}}Fa.prototype.get=function(t){return t.reduce((function(t,e){return t.getChild(e)}),this.root)},Fa.prototype.getNamespace=function(t){var e=this.root;return t.reduce((function(t,n){return t+((e=e.getChild(n)).namespaced?n+"/":"")}),"")},Fa.prototype.update=function(t){La([],this.root,t)},Fa.prototype.register=function(t,e,n){var r=this;void 0===n&&(n=!0);var o=new Ra(e,n);0===t.length?this.root=o:this.get(t.slice(0,-1)).addChild(t[t.length-1],o);e.modules&&Pa(e.modules,(function(e,o){r.register(t.concat(o),e,n)}))},Fa.prototype.unregister=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1],r=e.getChild(n);r&&r.runtime&&e.removeChild(n)},Fa.prototype.isRegistered=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1];return!!e&&e.hasChild(n)};var Ba=function(t){var e=this;void 0===t&&(t={}),!ja&&"undefined"!=typeof window&&window.Vue&&Ua(window.Vue);var n=t.plugins;void 0===n&&(n=[]);var r=t.strict;void 0===r&&(r=!1),this._committing=!1,this._actions=Object.create(null),this._actionSubscribers=[],this._mutations=Object.create(null),this._wrappedGetters=Object.create(null),this._modules=new Fa(t),this._modulesNamespaceMap=Object.create(null),this._subscribers=[],this._watcherVM=new ja,this._makeLocalGettersCache=Object.create(null);var o=this,i=this.dispatch,s=this.commit;this.dispatch=function(t,e){return i.call(o,t,e)},this.commit=function(t,e,n){return s.call(o,t,e,n)},this.strict=r;var a=this._modules.root.state;Ja(this,a,[],this._modules.root),Ha(this,a),n.forEach((function(t){return t(e)})),(void 0!==t.devtools?t.devtools:ja.config.devtools)&&function(t){Na&&(t._devtoolHook=Na,Na.emit("vuex:init",t),Na.on("vuex:travel-to-state",(function(e){t.replaceState(e)})),t.subscribe((function(t,e){Na.emit("vuex:mutation",t,e)}),{prepend:!0}),t.subscribeAction((function(t,e){Na.emit("vuex:action",t,e)}),{prepend:!0}))}(this)},Va={state:{configurable:!0}};function Wa(t,e,n){return e.indexOf(t)<0&&(n&&n.prepend?e.unshift(t):e.push(t)),function(){var n=e.indexOf(t);n>-1&&e.splice(n,1)}}function qa(t,e){t._actions=Object.create(null),t._mutations=Object.create(null),t._wrappedGetters=Object.create(null),t._modulesNamespaceMap=Object.create(null);var n=t.state;Ja(t,n,[],t._modules.root,!0),Ha(t,n,e)}function Ha(t,e,n){var r=t._vm;t.getters={},t._makeLocalGettersCache=Object.create(null);var o=t._wrappedGetters,i={};Pa(o,(function(e,n){i[n]=function(t,e){return function(){return t(e)}}(e,t),Object.defineProperty(t.getters,n,{get:function(){return t._vm[n]},enumerable:!0})}));var s=ja.config.silent;ja.config.silent=!0,t._vm=new ja({data:{$$state:e},computed:i}),ja.config.silent=s,t.strict&&function(t){t._vm.$watch((function(){return this._data.$$state}),(function(){}),{deep:!0,sync:!0})}(t),r&&(n&&t._withCommit((function(){r._data.$$state=null})),ja.nextTick((function(){return r.$destroy()})))}function Ja(t,e,n,r,o){var i=!n.length,s=t._modules.getNamespace(n);if(r.namespaced&&(t._modulesNamespaceMap[s],t._modulesNamespaceMap[s]=r),!i&&!o){var a=Ka(e,n.slice(0,-1)),l=n[n.length-1];t._withCommit((function(){ja.set(a,l,r.state)}))}var c=r.context=function(t,e,n){var r=""===e,o={dispatch:r?t.dispatch:function(n,r,o){var i=Ya(n,r,o),s=i.payload,a=i.options,l=i.type;return a&&a.root||(l=e+l),t.dispatch(l,s)},commit:r?t.commit:function(n,r,o){var i=Ya(n,r,o),s=i.payload,a=i.options,l=i.type;a&&a.root||(l=e+l),t.commit(l,s,a)}};return Object.defineProperties(o,{getters:{get:r?function(){return t.getters}:function(){return function(t,e){if(!t._makeLocalGettersCache[e]){var n={},r=e.length;Object.keys(t.getters).forEach((function(o){if(o.slice(0,r)===e){var i=o.slice(r);Object.defineProperty(n,i,{get:function(){return t.getters[o]},enumerable:!0})}})),t._makeLocalGettersCache[e]=n}return t._makeLocalGettersCache[e]}(t,e)}},state:{get:function(){return Ka(t.state,n)}}}),o}(t,s,n);r.forEachMutation((function(e,n){!function(t,e,n,r){(t._mutations[e]||(t._mutations[e]=[])).push((function(e){n.call(t,r.state,e)}))}(t,s+n,e,c)})),r.forEachAction((function(e,n){var r=e.root?n:s+n,o=e.handler||e;!function(t,e,n,r){(t._actions[e]||(t._actions[e]=[])).push((function(e){var o,i=n.call(t,{dispatch:r.dispatch,commit:r.commit,getters:r.getters,state:r.state,rootGetters:t.getters,rootState:t.state},e);return(o=i)&&"function"==typeof o.then||(i=Promise.resolve(i)),t._devtoolHook?i.catch((function(e){throw t._devtoolHook.emit("vuex:error",e),e})):i}))}(t,r,o,c)})),r.forEachGetter((function(e,n){!function(t,e,n,r){if(t._wrappedGetters[e])return;t._wrappedGetters[e]=function(t){return n(r.state,r.getters,t.state,t.getters)}}(t,s+n,e,c)})),r.forEachChild((function(r,i){Ja(t,e,n.concat(i),r,o)}))}function Ka(t,e){return e.reduce((function(t,e){return t[e]}),t)}function Ya(t,e,n){return Ia(t)&&t.type&&(n=e,e=t,t=t.type),{type:t,payload:e,options:n}}function Ua(t){ja&&t===ja|| /*! * vuex v3.6.2 * (c) 2021 Evan You * @license MIT */ -function(e){if(Number(e.version.split(".")[0])>=2)e.mixin({beforeCreate:n});else{var t=e.prototype._init;e.prototype._init=function(e){void 0===e&&(e={}),e.init=e.init?[n].concat(e.init):n,t.call(this,e)}}function n(){var e=this.$options;e.store?this.$store="function"==typeof e.store?e.store():e.store:e.parent&&e.parent.$store&&(this.$store=e.parent.$store)}}(wa=e)}Ca.state.get=function(){return this._vm._data.$$state},Ca.state.set=function(e){},ka.prototype.commit=function(e,t,n){var r=this,i=$a(e,t,n),o=i.type,s=i.payload,a={type:o,payload:s},l=this._mutations[o];l&&(this._withCommit((function(){l.forEach((function(e){e(s)}))})),this._subscribers.slice().forEach((function(e){return e(a,r.state)})))},ka.prototype.dispatch=function(e,t){var n=this,r=$a(e,t),i=r.type,o=r.payload,s={type:i,payload:o},a=this._actions[i];if(a){try{this._actionSubscribers.slice().filter((function(e){return e.before})).forEach((function(e){return e.before(s,n.state)}))}catch(wy){}var l=a.length>1?Promise.all(a.map((function(e){return e(o)}))):a[0](o);return new Promise((function(e,t){l.then((function(t){try{n._actionSubscribers.filter((function(e){return e.after})).forEach((function(e){return e.after(s,n.state)}))}catch(wy){}e(t)}),(function(e){try{n._actionSubscribers.filter((function(e){return e.error})).forEach((function(t){return t.error(s,n.state,e)}))}catch(wy){}t(e)}))}))}},ka.prototype.subscribe=function(e,t){return Oa(e,this._subscribers,t)},ka.prototype.subscribeAction=function(e,t){return Oa("function"==typeof e?{before:e}:e,this._actionSubscribers,t)},ka.prototype.watch=function(e,t,n){var r=this;return this._watcherVM.$watch((function(){return e(r.state,r.getters)}),t,n)},ka.prototype.replaceState=function(e){var t=this;this._withCommit((function(){t._vm._data.$$state=e}))},ka.prototype.registerModule=function(e,t,n){void 0===n&&(n={}),"string"==typeof e&&(e=[e]),this._modules.register(e,t),Da(this,this.state,e,this._modules.get(e),n.preserveState),_a(this,this.state)},ka.prototype.unregisterModule=function(e){var t=this;"string"==typeof e&&(e=[e]),this._modules.unregister(e),this._withCommit((function(){var n=Ta(t.state,e.slice(0,-1));wa.delete(n,e[e.length-1])})),Ma(this)},ka.prototype.hasModule=function(e){return"string"==typeof e&&(e=[e]),this._modules.isRegistered(e)},ka.prototype.hotUpdate=function(e){this._modules.update(e),Ma(this,!0)},ka.prototype._withCommit=function(e){var t=this._committing;this._committing=!0,e(),this._committing=t},Object.defineProperties(ka.prototype,Ca);var Ea=za((function(e,t){var n={};return Ra(t).forEach((function(t){var r=t.key,i=t.val;n[r]=function(){var t=this.$store.state,n=this.$store.getters;if(e){var r=ja(this.$store,"mapState",e);if(!r)return;t=r.context.state,n=r.context.getters}return"function"==typeof i?i.call(this,t,n):t[i]},n[r].vuex=!0})),n})),Na=za((function(e,t){var n={};return Ra(t).forEach((function(t){var r=t.key,i=t.val;n[r]=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];var r=this.$store.commit;if(e){var o=ja(this.$store,"mapMutations",e);if(!o)return;r=o.context.commit}return"function"==typeof i?i.apply(this,[r].concat(t)):r.apply(this.$store,[i].concat(t))}})),n})),Pa=za((function(e,t){var n={};return Ra(t).forEach((function(t){var r=t.key,i=t.val;i=e+i,n[r]=function(){if(!e||ja(this.$store,"mapGetters",e))return this.$store.getters[i]},n[r].vuex=!0})),n})),Ia=za((function(e,t){var n={};return Ra(t).forEach((function(t){var r=t.key,i=t.val;n[r]=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];var r=this.$store.dispatch;if(e){var o=ja(this.$store,"mapActions",e);if(!o)return;r=o.context.dispatch}return"function"==typeof i?i.apply(this,[r].concat(t)):r.apply(this.$store,[i].concat(t))}})),n}));function Ra(e){return function(e){return Array.isArray(e)||va(e)}(e)?Array.isArray(e)?e.map((function(e){return{key:e,val:e}})):Object.keys(e).map((function(t){return{key:t,val:e[t]}})):[]}function za(e){return function(t,n){return"string"!=typeof t?(n=t,t=""):"/"!==t.charAt(t.length-1)&&(t+="/"),e(t,n)}}function ja(e,t,n){return e._modulesNamespaceMap[n]}function Fa(e,t,n){var r=n?e.groupCollapsed:e.group;try{r.call(e,t)}catch(wy){e.log(t)}}function La(e){try{e.groupEnd()}catch(wy){e.log("—— log end ——")}}function Ba(){var e=new Date;return" @ "+Va(e.getHours(),2)+":"+Va(e.getMinutes(),2)+":"+Va(e.getSeconds(),2)+"."+Va(e.getMilliseconds(),3)}function Va(e,t){return n="0",r=t-e.toString().length,new Array(r+1).join(n)+e;var n,r}var Wa={Store:ka,install:Aa,version:"3.6.2",mapState:Ea,mapMutations:Na,mapGetters:Pa,mapActions:Ia,createNamespacedHelpers:function(e){return{mapState:Ea.bind(null,e),mapGetters:Pa.bind(null,e),mapMutations:Na.bind(null,e),mapActions:Ia.bind(null,e)}},createLogger:function(e){void 0===e&&(e={});var t=e.collapsed;void 0===t&&(t=!0);var n=e.filter;void 0===n&&(n=function(e,t,n){return!0});var r=e.transformer;void 0===r&&(r=function(e){return e});var i=e.mutationTransformer;void 0===i&&(i=function(e){return e});var o=e.actionFilter;void 0===o&&(o=function(e,t){return!0});var s=e.actionTransformer;void 0===s&&(s=function(e){return e});var a=e.logMutations;void 0===a&&(a=!0);var l=e.logActions;void 0===l&&(l=!0);var c=e.logger;return void 0===c&&(c=console),function(e){var u=ma(e.state);void 0!==c&&(a&&e.subscribe((function(e,o){var s=ma(o);if(n(e,u,s)){var a=Ba(),l=i(e),d="mutation "+e.type+a;Fa(c,d,t),c.log("%c prev state","color: #9E9E9E; font-weight: bold",r(u)),c.log("%c mutation","color: #03A9F4; font-weight: bold",l),c.log("%c next state","color: #4CAF50; font-weight: bold",r(s)),La(c)}u=s})),l&&e.subscribeAction((function(e,n){if(o(e,n)){var r=Ba(),i=s(e),a="action "+e.type+r;Fa(c,a,t),c.log("%c action","color: #03A9F4; font-weight: bold",i),La(c)}})))}}};function qa(e){return{all:e=e||new Map,on:function(t,n){var r=e.get(t);r?r.push(n):e.set(t,[n])},off:function(t,n){var r=e.get(t);r&&(n?r.splice(r.indexOf(n)>>>0,1):e.set(t,[]))},emit:function(t,n){var r=e.get(t);r&&r.slice().map((function(e){e(n)})),(r=e.get("*"))&&r.slice().map((function(e){e(t,n)}))}}}var Ha,Ja,Ka="function"==typeof Map?new Map:(Ha=[],Ja=[],{has:function(e){return Ha.indexOf(e)>-1},get:function(e){return Ja[Ha.indexOf(e)]},set:function(e,t){-1===Ha.indexOf(e)&&(Ha.push(e),Ja.push(t))},delete:function(e){var t=Ha.indexOf(e);t>-1&&(Ha.splice(t,1),Ja.splice(t,1))}}),Ya=function(e){return new Event(e,{bubbles:!0})};try{new Event("test")}catch(wy){Ya=function(e){var t=document.createEvent("Event");return t.initEvent(e,!0,!1),t}}function Ua(e){var t=Ka.get(e);t&&t.destroy()}function Xa(e){var t=Ka.get(e);t&&t.update()}var Ga=null;"undefined"==typeof window||"function"!=typeof window.getComputedStyle?((Ga=function(e){return e}).destroy=function(e){return e},Ga.update=function(e){return e}):((Ga=function(e,t){return e&&Array.prototype.forEach.call(e.length?e:[e],(function(e){return function(e){if(e&&e.nodeName&&"TEXTAREA"===e.nodeName&&!Ka.has(e)){var t,n=null,r=null,i=null,o=function(){e.clientWidth!==r&&c()},s=function(t){window.removeEventListener("resize",o,!1),e.removeEventListener("input",c,!1),e.removeEventListener("keyup",c,!1),e.removeEventListener("autosize:destroy",s,!1),e.removeEventListener("autosize:update",c,!1),Object.keys(t).forEach((function(n){e.style[n]=t[n]})),Ka.delete(e)}.bind(e,{height:e.style.height,resize:e.style.resize,overflowY:e.style.overflowY,overflowX:e.style.overflowX,wordWrap:e.style.wordWrap});e.addEventListener("autosize:destroy",s,!1),"onpropertychange"in e&&"oninput"in e&&e.addEventListener("keyup",c,!1),window.addEventListener("resize",o,!1),e.addEventListener("input",c,!1),e.addEventListener("autosize:update",c,!1),e.style.overflowX="hidden",e.style.wordWrap="break-word",Ka.set(e,{destroy:s,update:c}),"vertical"===(t=window.getComputedStyle(e,null)).resize?e.style.resize="none":"both"===t.resize&&(e.style.resize="horizontal"),n="content-box"===t.boxSizing?-(parseFloat(t.paddingTop)+parseFloat(t.paddingBottom)):parseFloat(t.borderTopWidth)+parseFloat(t.borderBottomWidth),isNaN(n)&&(n=0),c()}function a(t){var n=e.style.width;e.style.width="0px",e.style.width=n,e.style.overflowY=t}function l(){if(0!==e.scrollHeight){var t=function(e){for(var t=[];e&&e.parentNode&&e.parentNode instanceof Element;)e.parentNode.scrollTop&&t.push({node:e.parentNode,scrollTop:e.parentNode.scrollTop}),e=e.parentNode;return t}(e),i=document.documentElement&&document.documentElement.scrollTop;e.style.height="",e.style.height=e.scrollHeight+n+"px",r=e.clientWidth,t.forEach((function(e){e.node.scrollTop=e.scrollTop})),i&&(document.documentElement.scrollTop=i)}}function c(){l();var t=Math.round(parseFloat(e.style.height)),n=window.getComputedStyle(e,null),r="content-box"===n.boxSizing?Math.round(parseFloat(n.height)):e.offsetHeight;if(r=t?e:""+Array(t+1-r.length).join(n)+e},y={s:v,z:function(e){var t=-e.utcOffset(),n=Math.abs(t),r=Math.floor(n/60),i=n%60;return(t<=0?"+":"-")+v(r,2,"0")+":"+v(i,2,"0")},m:function e(t,n){if(t.date()1)return e(s[0])}else{var a=t.name;w[a]=t,i=a}return!r&&i&&(b=i),i||!r&&b},k=function(e,t){if(x(e))return e.clone();var n="object"==typeof t?t:{};return n.date=e,n.args=arguments,new O(n)},C=y;C.l=S,C.i=x,C.w=function(e,t){return k(e,{locale:t.$L,utc:t.$u,x:t.$x,$offset:t.$offset})};var O=function(){function g(e){this.$L=S(e.locale,null,!0),this.parse(e)}var v=g.prototype;return v.parse=function(e){this.$d=function(e){var t=e.date,n=e.utc;if(null===t)return new Date(NaN);if(C.u(t))return new Date;if(t instanceof Date)return new Date(t);if("string"==typeof t&&!/Z$/i.test(t)){var r=t.match(p);if(r){var i=r[2]-1||0,o=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,o)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,o)}}return new Date(t)}(e),this.$x=e.x||{},this.init()},v.init=function(){var e=this.$d;this.$y=e.getFullYear(),this.$M=e.getMonth(),this.$D=e.getDate(),this.$W=e.getDay(),this.$H=e.getHours(),this.$m=e.getMinutes(),this.$s=e.getSeconds(),this.$ms=e.getMilliseconds()},v.$utils=function(){return C},v.isValid=function(){return!(this.$d.toString()===f)},v.isSame=function(e,t){var n=k(e);return this.startOf(t)<=n&&n<=this.endOf(t)},v.isAfter=function(e,t){return k(e)68?1900:2e3)},a=function(e){return function(t){this[e]=+t}},l=[/[+-]\d\d:?(\d\d)?|Z/,function(e){(this.zone||(this.zone={})).offset=function(e){if(!e)return 0;if("Z"===e)return 0;var t=e.match(/([+-]|\d\d)/g),n=60*t[1]+(+t[2]||0);return 0===n?0:"+"===t[0]?-n:n}(e)}],c=function(e){var t=o[e];return t&&(t.indexOf?t:t.s.concat(t.f))},u=function(e,t){var n,r=o.meridiem;if(r){for(var i=1;i<=24;i+=1)if(e.indexOf(r(i,0,t))>-1){n=i>12;break}}else n=e===(t?"pm":"PM");return n},d={A:[i,function(e){this.afternoon=u(e,!1)}],a:[i,function(e){this.afternoon=u(e,!0)}],S:[/\d/,function(e){this.milliseconds=100*+e}],SS:[n,function(e){this.milliseconds=10*+e}],SSS:[/\d{3}/,function(e){this.milliseconds=+e}],s:[r,a("seconds")],ss:[r,a("seconds")],m:[r,a("minutes")],mm:[r,a("minutes")],H:[r,a("hours")],h:[r,a("hours")],HH:[r,a("hours")],hh:[r,a("hours")],D:[r,a("day")],DD:[n,a("day")],Do:[i,function(e){var t=o.ordinal,n=e.match(/\d+/);if(this.day=n[0],t)for(var r=1;r<=31;r+=1)t(r).replace(/\[|\]/g,"")===e&&(this.day=r)}],M:[r,a("month")],MM:[n,a("month")],MMM:[i,function(e){var t=c("months"),n=(c("monthsShort")||t.map((function(e){return e.slice(0,3)}))).indexOf(e)+1;if(n<1)throw new Error;this.month=n%12||n}],MMMM:[i,function(e){var t=c("months").indexOf(e)+1;if(t<1)throw new Error;this.month=t%12||t}],Y:[/[+-]?\d+/,a("year")],YY:[n,function(e){this.year=s(e)}],YYYY:[/\d{4}/,a("year")],Z:l,ZZ:l};function h(n){var r,i;r=n,i=o&&o.formats;for(var s=(n=r.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,(function(t,n,r){var o=r&&r.toUpperCase();return n||i[r]||e[r]||i[o].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,(function(e,t,n){return t||n.slice(1)}))}))).match(t),a=s.length,l=0;l-1)return new Date(("X"===t?1e3:1)*e);var r=h(t)(e),i=r.year,o=r.month,s=r.day,a=r.hours,l=r.minutes,c=r.seconds,u=r.milliseconds,d=r.zone,f=new Date,p=s||(i||o?1:f.getDate()),m=i||f.getFullYear(),g=0;i&&!o||(g=o>0?o-1:f.getMonth());var v=a||0,y=l||0,b=c||0,w=u||0;return d?new Date(Date.UTC(m,g,p,v,y,b,w+60*d.offset*1e3)):n?new Date(Date.UTC(m,g,p,v,y,b,w)):new Date(m,g,p,v,y,b,w)}catch(x){return new Date("")}}(t,a,r),this.init(),d&&!0!==d&&(this.$L=this.locale(d).$L),u&&t!=this.format(a)&&(this.$d=new Date("")),o={}}else if(a instanceof Array)for(var f=a.length,p=1;p<=f;p+=1){s[1]=a[p-1];var m=n.apply(this,s);if(m.isValid()){this.$d=m.$d,this.$L=m.$L,this.init();break}p===f&&(this.$d=new Date(""))}else i.call(this,e)}}}();function il(e){return(il="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var ol={selector:"vue-portal-target-".concat(((e=21)=>{let t="",n=e;for(;n--;)t+="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"[64*Math.random()|0];return t})())},sl=function(e){return ol.selector=e},al="undefined"!=typeof window&&void 0!==("undefined"==typeof document?"undefined":il(document)),ll=Mn.extend({abstract:!0,name:"PortalOutlet",props:["nodes","tag"],data:function(e){return{updatedNodes:e.nodes}},render:function(e){var t=this.updatedNodes&&this.updatedNodes();return t?1!==t.length||t[0].text?e(this.tag||"DIV",t):t:e()},destroyed:function(){var e=this.$el;e&&e.parentNode.removeChild(e)}}),cl=Mn.extend({name:"VueSimplePortal",props:{disabled:{type:Boolean},prepend:{type:Boolean},selector:{type:String,default:function(){return"#".concat(ol.selector)}},tag:{type:String,default:"DIV"}},render:function(e){if(this.disabled){var t=this.$scopedSlots&&this.$scopedSlots.default();return t?t.length<2&&!t[0].text?t:e(this.tag,t):e()}return e()},created:function(){this.getTargetEl()||this.insertTargetEl()},updated:function(){var e=this;this.$nextTick((function(){e.disabled||e.slotFn===e.$scopedSlots.default||(e.container.updatedNodes=e.$scopedSlots.default),e.slotFn=e.$scopedSlots.default}))},beforeDestroy:function(){this.unmount()},watch:{disabled:{immediate:!0,handler:function(e){e?this.unmount():this.$nextTick(this.mount)}}},methods:{getTargetEl:function(){if(al)return document.querySelector(this.selector)},insertTargetEl:function(){if(al){var e=document.querySelector("body"),t=document.createElement(this.tag);t.id=this.selector.substring(1),e.appendChild(t)}},mount:function(){if(al){var e=this.getTargetEl(),t=document.createElement("DIV");this.prepend&&e.firstChild?e.insertBefore(t,e.firstChild):e.appendChild(t),this.container=new ll({el:t,parent:this,propsData:{tag:this.tag,nodes:this.$scopedSlots.default}})}},unmount:function(){this.container&&(this.container.$destroy(),delete this.container)}}});function ul(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e.component(t.name||"portal",cl),t.defaultSelector&&sl(t.defaultSelector)}"undefined"!=typeof window&&window.Vue&&window.Vue===Mn&&Mn.use(ul);var dl={},hl={};function fl(e){return null==e}function pl(e){return null!=e}function ml(e,t){return t.tag===e.tag&&t.key===e.key}function gl(e){var t=e.tag;e.vm=new t({data:e.args})}function vl(e,t,n){var r,i,o={};for(r=t;r<=n;++r)pl(i=e[r].key)&&(o[i]=r);return o}function yl(e,t,n){for(;t<=n;++t)gl(e[t])}function bl(e,t,n){for(;t<=n;++t){var r=e[t];pl(r)&&(r.vm.$destroy(),r.vm=null)}}function wl(e,t){e!==t&&(t.vm=e.vm,function(e){for(var t=Object.keys(e.args),n=0;na?yl(t,s,u):s>u&&bl(e,o,a)}(e,t):pl(t)?yl(t,0,t.length-1):pl(e)&&bl(e,0,e.length-1)};var xl={};function Sl(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function kl(e){for(var t=1;te.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?a:a.$sub[0]:null}}},computed:{run:function(){var e=this,t=this.lazyParentModel();if(Array.isArray(t)&&t.__ob__){var n=t.__ob__.dep;n.depend();var r=n.constructor.target;if(!this._indirectWatcher){var i=r.constructor;this._indirectWatcher=new i(this,(function(){return e.runRule(t)}),null,{lazy:!0})}var o=this.getModel();if(!this._indirectWatcher.dirty&&this._lastModel===o)return this._indirectWatcher.depend(),r.value;this._lastModel=o,this._indirectWatcher.evaluate(),this._indirectWatcher.depend()}else this._indirectWatcher&&(this._indirectWatcher.teardown(),this._indirectWatcher=null);return this._indirectWatcher?this._indirectWatcher.value:this.runRule(t)},$params:function(){return this.run.params},proxy:function(){var e=this.run.output;return e.__isVuelidateAsyncVm?!!e.v:!!e},$pending:function(){var e=this.run.output;return!!e.__isVuelidateAsyncVm&&e.p}},destroyed:function(){this._indirectWatcher&&(this._indirectWatcher.teardown(),this._indirectWatcher=null)}}),a=i.extend({data:function(){return{dirty:!1,validations:null,lazyModel:null,model:null,prop:null,lazyParentModel:null,rootModel:null}},methods:s(s({},g),{},{refProxy:function(e){return this.getRef(e).proxy},getRef:function(e){return this.refs[e]},isNested:function(e){return"function"!=typeof this.validations[e]}}),computed:s(s({},p),{},{nestedKeys:function(){return this.keys.filter(this.isNested)},ruleKeys:function(){var e=this;return this.keys.filter((function(t){return!e.isNested(t)}))},keys:function(){return Object.keys(this.validations).filter((function(e){return"$params"!==e}))},proxy:function(){var e=this,t=u(this.keys,(function(t){return{enumerable:!0,configurable:!0,get:function(){return e.refProxy(t)}}})),n=u(v,(function(t){return{enumerable:!0,configurable:!0,get:function(){return e[t]}}})),r=u(y,(function(t){return{enumerable:!1,configurable:!0,get:function(){return e[t]}}})),i=this.hasIter()?{$iter:{enumerable:!0,value:Object.defineProperties({},s({},t))}}:{};return Object.defineProperties({},s(s(s(s({},t),i),{},{$model:{enumerable:!0,get:function(){var t=e.lazyParentModel();return null!=t?t[e.prop]:null},set:function(t){var n=e.lazyParentModel();null!=n&&(n[e.prop]=t,e.$touch())}}},n),r))},children:function(){var e=this;return[].concat(r(this.nestedKeys.map((function(t){return w(e,t)}))),r(this.ruleKeys.map((function(t){return x(e,t)})))).filter(Boolean)}})}),l=a.extend({methods:{isNested:function(e){return void 0!==this.validations[e]()},getRef:function(e){var t=this;return{get proxy(){return t.validations[e]()||!1}}}}}),m=a.extend({computed:{keys:function(){var e=this.getModel();return h(e)?Object.keys(e):[]},tracker:function(){var e=this,t=this.validations.$trackBy;return t?function(n){return"".concat(f(e.rootModel,e.getModelKey(n),t))}:function(e){return"".concat(e)}},getModelLazy:function(){var e=this;return function(){return e.getModel()}},children:function(){var e=this,n=this.validations,r=this.getModel(),i=s({},n);delete i.$trackBy;var o={};return this.keys.map((function(n){var s=e.tracker(n);return o.hasOwnProperty(s)?null:(o[s]=!0,(0,t.h)(a,s,{validations:i,prop:n,lazyParentModel:e.getModelLazy,model:r[n],rootModel:e.rootModel}))})).filter(Boolean)}},methods:{isNested:function(){return!0},getRef:function(e){return this.refs[this.tracker(e)]},hasIter:function(){return!0}}}),w=function(e,n){if("$each"===n)return(0,t.h)(m,n,{validations:e.validations[n],lazyParentModel:e.lazyParentModel,prop:n,lazyModel:e.getModel,rootModel:e.rootModel});var r=e.validations[n];if(Array.isArray(r)){var i=e.rootModel,o=u(r,(function(e){return function(){return f(i,i.$v,e)}}),(function(e){return Array.isArray(e)?e.join("."):e}));return(0,t.h)(l,n,{validations:o,lazyParentModel:c,prop:n,lazyModel:c,rootModel:i})}return(0,t.h)(a,n,{validations:r,lazyParentModel:e.getModel,prop:n,lazyModel:e.getModelKey,rootModel:e.rootModel})},x=function(e,n){return(0,t.h)(o,n,{rule:e.validations[n],lazyParentModel:e.lazyParentModel,lazyModel:e.getModel,rootModel:e.rootModel})};return b={VBase:i,Validation:a}},x=null;var S=function(e,n){var r=function(e){if(x)return x;for(var t=e.constructor;t.super;)t=t.super;return x=t,t}(e),i=w(r),o=i.Validation;return new(0,i.VBase)({computed:{children:function(){var r="function"==typeof n?n.call(e):n;return[(0,t.h)(o,"$v",{validations:r,lazyParentModel:c,prop:"$v",model:e,rootModel:e})]}}})},k={data:function(){var e=this.$options.validations;return e&&(this._vuelidate=S(this,e)),{}},beforeCreate:function(){var e=this.$options;e.validations&&(e.computed||(e.computed={}),e.computed.$v||(e.computed.$v=function(){return this._vuelidate?this._vuelidate.refs.$v.proxy:null}))},beforeDestroy:function(){this._vuelidate&&(this._vuelidate.$destroy(),this._vuelidate=null)}};function C(e){e.mixin(k)}e.validationMixin=k;var O=C;e.default=O}(dl);var El=Qa(dl);function Nl(e){this.content=e}function Pl(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),o=t.child(r);if(i!=o){if(!i.sameMarkup(o))return n;if(i.isText&&i.text!=o.text){for(let e=0;i.text[e]==o.text[e];e++)n++;return n}if(i.content.size||o.content.size){let e=Pl(i.content,o.content,n+1);if(null!=e)return e}n+=i.nodeSize}else n+=i.nodeSize}}function Il(e,t,n,r){for(let i=e.childCount,o=t.childCount;;){if(0==i||0==o)return i==o?null:{a:n,b:r};let s=e.child(--i),a=t.child(--o),l=s.nodeSize;if(s!=a){if(!s.sameMarkup(a))return{a:n,b:r};if(s.isText&&s.text!=a.text){let e=0,t=Math.min(s.text.length,a.text.length);for(;e>1}},Nl.from=function(e){if(e instanceof Nl)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new Nl(t)};class Rl{constructor(e,t){if(this.content=e,this.size=t||0,null==t)for(let n=0;ne&&!1!==n(a,r+s,i||null,o)&&a.content.size){let i=s+1;a.nodesBetween(Math.max(0,e-i),Math.min(a.content.size,t-i),n,r+i)}s=l}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i="",o=!0;return this.nodesBetween(e,t,((s,a)=>{s.isText?(i+=s.text.slice(Math.max(e,a)-a,t-a),o=!n):s.isLeaf&&r?(i+="function"==typeof r?r(s):r,o=!n):!o&&s.isBlock&&(i+=n,o=!0)}),0),i}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,r=this.content.slice(),i=0;for(t.isText&&t.sameMarkup(n)&&(r[r.length-1]=t.withText(t.text+n.text),i=1);ie)for(let i=0,o=0;oe&&((ot)&&(s=s.isText?s.cut(Math.max(0,e-o),Math.min(s.text.length,t-o)):s.cut(Math.max(0,e-o-1),Math.min(s.content.size,t-o-1))),n.push(s),r+=s.nodeSize),o=a}return new Rl(n,r)}cutByIndex(e,t){return e==t?Rl.empty:0==e&&t==this.content.length?this:new Rl(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let r=this.content.slice(),i=this.size+t.nodeSize-n.nodeSize;return r[e]=t,new Rl(r,i)}addToStart(e){return new Rl([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new Rl(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,r=0;;n++){let i=r+this.child(n).nodeSize;if(i>=e)return i==e||t>0?jl(n+1,i):jl(n,r);r=i}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map((e=>e.toJSON())):null}static fromJSON(e,t){if(!t)return Rl.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new Rl(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return Rl.empty;let t,n=0;for(let r=0;rthis.type.rank&&(t||(t=e.slice(0,r)),t.push(this),n=!0),t&&t.push(i)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;te.type.rank-t.type.rank)),t}}Ll.none=[];class Bl extends Error{}class Vl{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=ql(this.content,e+this.openStart,t);return n&&new Vl(n,this.openStart,this.openEnd)}removeBetween(e,t){return new Vl(Wl(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return Vl.empty;let n=t.openStart||0,r=t.openEnd||0;if("number"!=typeof n||"number"!=typeof r)throw new RangeError("Invalid input for Slice.fromJSON");return new Vl(Rl.fromJSON(e,t.content),n,r)}static maxOpen(e,t=!0){let n=0,r=0;for(let i=e.firstChild;i&&!i.isLeaf&&(t||!i.type.spec.isolating);i=i.firstChild)n++;for(let i=e.lastChild;i&&!i.isLeaf&&(t||!i.type.spec.isolating);i=i.lastChild)r++;return new Vl(e,n,r)}}function Wl(e,t,n){let{index:r,offset:i}=e.findIndex(t),o=e.maybeChild(r),{index:s,offset:a}=e.findIndex(n);if(i==t||o.isText){if(a!=n&&!e.child(s).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(r!=s)throw new RangeError("Removing non-flat range");return e.replaceChild(r,o.copy(Wl(o.content,t-i-1,n-i-1)))}function ql(e,t,n,r){let{index:i,offset:o}=e.findIndex(t),s=e.maybeChild(i);if(o==t||s.isText)return r&&!r.canReplace(i,i,n)?null:e.cut(0,t).append(n).append(e.cut(t));let a=ql(s.content,t-o-1,n);return a&&e.replaceChild(i,s.copy(a))}function Hl(e,t,n){if(n.openStart>e.depth)throw new Bl("Inserted content deeper than insertion position");if(e.depth-n.openStart!=t.depth-n.openEnd)throw new Bl("Inconsistent open depths");return Jl(e,t,n,0)}function Jl(e,t,n,r){let i=e.index(r),o=e.node(r);if(i==t.index(r)&&r=0;i--)r=t.node(i).copy(Rl.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}(n,e);return Gl(o,Zl(e,i,s,t,r))}{let r=e.parent,i=r.content;return Gl(r,i.cut(0,e.parentOffset).append(n.content).append(i.cut(t.parentOffset)))}}return Gl(o,Ql(e,t,r))}function Kl(e,t){if(!t.type.compatibleContent(e.type))throw new Bl("Cannot join "+t.type.name+" onto "+e.type.name)}function Yl(e,t,n){let r=e.node(n);return Kl(r,t.node(n)),r}function Ul(e,t){let n=t.length-1;n>=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function Xl(e,t,n,r){let i=(t||e).node(n),o=0,s=t?t.index(n):i.childCount;e&&(o=e.index(n),e.depth>n?o++:e.textOffset&&(Ul(e.nodeAfter,r),o++));for(let a=o;ai&&Yl(e,t,i+1),s=r.depth>i&&Yl(n,r,i+1),a=[];return Xl(null,e,i,a),o&&s&&t.index(i)==n.index(i)?(Kl(o,s),Ul(Gl(o,Zl(e,t,n,r,i+1)),a)):(o&&Ul(Gl(o,Ql(e,t,i+1)),a),Xl(t,n,i,a),s&&Ul(Gl(s,Ql(n,r,i+1)),a)),Xl(r,null,i,a),new Rl(a)}function Ql(e,t,n){let r=[];if(Xl(null,e,n,r),e.depth>n){Ul(Gl(Yl(e,t,n+1),Ql(e,t,n+1)),r)}return Xl(t,null,n,r),new Rl(r)}Vl.empty=new Vl(Rl.empty,0,0);class ec{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return null==e?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[3*this.resolveDepth(e)]}index(e){return this.path[3*this.resolveDepth(e)+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e!=this.depth||this.textOffset?1:0)}start(e){return 0==(e=this.resolveDepth(e))?0:this.path[3*e-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(!(e=this.resolveDepth(e)))throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]}after(e){if(!(e=this.resolveDepth(e)))throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]+this.path[3*e].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):0==e?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[3*t],r=0==t?0:this.path[3*t-1]+1;for(let i=0;i0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new ic(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let n=[],r=0,i=t;for(let o=e;;){let{index:e,offset:t}=o.content.findIndex(i),s=i-t;if(n.push(o,e,r+t),!s)break;if(o=o.child(e),o.isText)break;i=s-1,r+=t+1}return new ec(t,n,i)}static resolveCached(e,t){for(let r=0;re&&this.nodesBetween(e,t,(e=>(n.isInSet(e.marks)&&(r=!0),!r))),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),lc(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=Rl.empty,r=0,i=n.childCount){let o=this.contentMatchAt(e).matchFragment(n,r,i),s=o&&o.matchFragment(this.content,t);if(!s||!s.validEnd)return!1;for(let a=r;ae.type.name))}`);this.content.forEach((e=>e.check()))}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map((e=>e.toJSON()))),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let n=null;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if("text"==t.type){if("string"!=typeof t.text)throw new RangeError("Invalid text node in JSON");return e.text(t.text,n)}let r=Rl.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,r,n)}}sc.prototype.text=void 0;class ac extends sc{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):lc(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new ac(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new ac(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return 0==e&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function lc(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class cc{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new uc(e,t);if(null==n.next)return cc.empty;let r=dc(n);n.next&&n.err("Unexpected trailing text");let i=function(e){let t=Object.create(null);return n(vc(e,0));function n(r){let i=[];r.forEach((t=>{e[t].forEach((({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e{r||i.push([t,r=[]]),-1==r.indexOf(e)&&r.push(e)}))}))}));let o=t[r.join(",")]=new cc(r.indexOf(e.length-1)>-1);for(let e=0;ee.to=t))}function o(e,t){if("choice"==e.type)return e.exprs.reduce(((e,n)=>e.concat(o(n,t))),[]);if("seq"!=e.type){if("star"==e.type){let s=n();return r(t,s),i(o(e.expr,s),s),[r(s)]}if("plus"==e.type){let s=n();return i(o(e.expr,t),s),i(o(e.expr,s),s),[r(s)]}if("opt"==e.type)return[r(t)].concat(o(e.expr,t));if("range"==e.type){let s=t;for(let t=0;te.createAndFill())));for(let e=0;e=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];return function t(n){e.push(n);for(let r=0;r{let r=n+(t.validEnd?"*":" ")+" ";for(let i=0;i"+e.indexOf(t.next[i].next);return r})).join("\n")}}cc.empty=new cc(!0);class uc{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),""==this.tokens[this.tokens.length-1]&&this.tokens.pop(),""==this.tokens[0]&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function dc(e){let t=[];do{t.push(hc(e))}while(e.eat("|"));return 1==t.length?t[0]:{type:"choice",exprs:t}}function hc(e){let t=[];do{t.push(fc(e))}while(e.next&&")"!=e.next&&"|"!=e.next);return 1==t.length?t[0]:{type:"seq",exprs:t}}function fc(e){let t=function(e){if(e.eat("(")){let t=dc(e);return e.eat(")")||e.err("Missing closing paren"),t}if(!/\W/.test(e.next)){let t=function(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let o in n){let e=n[o];e.groups.indexOf(t)>-1&&i.push(e)}0==i.length&&e.err("No node type or group '"+t+"' found");return i}(e,e.next).map((t=>(null==e.inline?e.inline=t.isInline:e.inline!=t.isInline&&e.err("Mixing inline and block content"),{type:"name",value:t})));return e.pos++,1==t.length?t[0]:{type:"choice",exprs:t}}e.err("Unexpected token '"+e.next+"'")}(e);for(;;)if(e.eat("+"))t={type:"plus",expr:t};else if(e.eat("*"))t={type:"star",expr:t};else if(e.eat("?"))t={type:"opt",expr:t};else{if(!e.eat("{"))break;t=mc(e,t)}return t}function pc(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function mc(e,t){let n=pc(e),r=n;return e.eat(",")&&(r="}"!=e.next?pc(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:t}}function gc(e,t){return t-e}function vc(e,t){let n=[];return function t(r){let i=e[r];if(1==i.length&&!i[0].term)return t(i[0].to);n.push(r);for(let e=0;e-1}allowsMarks(e){if(null==this.markSet)return!0;for(let t=0;tn[e]=new xc(e,t,r)));let r=t.spec.topNode||"doc";if(!n[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!n.text)throw new RangeError("Every schema needs a 'text' type");for(let i in n.text.attrs)throw new RangeError("The text node type should not have attributes");return n}}class Sc{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}}class kc{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=wc(r.attrs),this.excluded=null;let i=yc(this.attrs);this.instance=i?new Ll(this,i):null}create(e=null){return!e&&this.instance?this.instance:new Ll(this,bc(this.attrs,e))}static compile(e,t){let n=Object.create(null),r=0;return e.forEach(((e,i)=>n[e]=new kc(e,r++,t,i))),n}removeFromSet(e){for(var t=0;t-1}}class Cc{constructor(e){this.cached=Object.create(null),this.spec={nodes:Nl.from(e.nodes),marks:Nl.from(e.marks||{}),topNode:e.topNode},this.nodes=xc.compile(this.spec.nodes,this),this.marks=kc.compile(this.spec.marks,this);let t=Object.create(null);for(let n in this.nodes){if(n in this.marks)throw new RangeError(n+" can not be both a node and a mark");let e=this.nodes[n],r=e.spec.content||"",i=e.spec.marks;e.contentMatch=t[r]||(t[r]=cc.parse(r,this.nodes)),e.inlineContent=e.contentMatch.inlineContent,e.markSet="_"==i?null:i?Oc(this,i.split(" ")):""!=i&&e.inlineContent?null:[]}for(let n in this.marks){let e=this.marks[n],t=e.spec.excludes;e.excluded=null==t?[e]:""==t?[]:Oc(this,t.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if("string"==typeof e)e=this.nodeType(e);else{if(!(e instanceof xc))throw new RangeError("Invalid node type: "+e);if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new ac(n,n.defaultAttrs,e,Ll.setFrom(t))}mark(e,t){return"string"==typeof e&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return sc.fromJSON(this,e)}markFromJSON(e){return Ll.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function Oc(e,t){let n=[];for(let r=0;r-1)&&n.push(s=r)}if(!s)throw new SyntaxError("Unknown mark type: '"+t[r]+"'")}return n}class Mc{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[],t.forEach((e=>{e.tag?this.tags.push(e):e.style&&this.styles.push(e)})),this.normalizeLists=!this.tags.some((t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)}))}parse(e,t={}){let n=new Ec(this,t,!1);return n.addAll(e,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new Ec(this,t,!0);return n.addAll(e,t.from,t.to),Vl.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;re.length&&(61!=o.charCodeAt(e.length)||o.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(!1===e)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=null==e.priority?50:e.priority,r=0;for(;r{n(e=Pc(e)),e.mark=r}))}for(let r in e.nodes){let t=e.nodes[r].spec.parseDOM;t&&t.forEach((e=>{n(e=Pc(e)),e.node=r}))}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Mc(e,Mc.schemaRules(e)))}}const _c={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Dc={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Tc={ol:!0,ul:!0};function $c(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}class Ac{constructor(e,t,n,r,i,o,s){this.type=e,this.attrs=t,this.marks=n,this.pendingMarks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=Ll.none,this.stashMarks=[],this.match=o||(4&s?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(Rl.from(e));if(!t){let t,n=this.type.contentMatch;return(t=n.findWrapping(e.type))?(this.match=n,t):null}this.match=this.type.contentMatch.matchFragment(t)}return this.match.findWrapping(e.type)}finish(e){if(!(1&this.options)){let e,t=this.content[this.content.length-1];if(t&&t.isText&&(e=/[ \t\r\n\u000c]+$/.exec(t.text))){let n=t;t.text.length==e[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-e[0].length))}}let t=Rl.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(Rl.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}popFromStashMark(e){for(let t=this.stashMarks.length-1;t>=0;t--)if(e.eq(this.stashMarks[t]))return this.stashMarks.splice(t,1)[0]}applyPending(e){for(let t=0,n=this.pendingMarks;tthis.insertNode(e)));else{let n=e;"string"==typeof t.contentElement?n=e.querySelector(t.contentElement):"function"==typeof t.contentElement?n=t.contentElement(e):t.contentElement&&(n=t.contentElement),this.findAround(e,n,!0),this.addAll(n)}r&&this.sync(s)&&this.open--,o&&this.removePendingMark(o,s)}addAll(e,t,n){let r=t||0;for(let i=t?e.childNodes[t]:e.firstChild,o=null==n?null:e.childNodes[n];i!=o;i=i.nextSibling,++r)this.findAtPoint(e,r),this.addDOM(i);this.findAtPoint(e,r)}findPlace(e){let t,n;for(let r=this.open;r>=0;r--){let i=this.nodes[r],o=i.findWrapping(e);if(o&&(!t||t.length>o.length)&&(t=o,n=i,!o.length))break;if(i.solid)break}if(!t)return!1;this.sync(n);for(let r=0;rthis.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,r=!(this.isOpen||n&&n.parent.type!=this.nodes[0].type),i=-(n?n.depth+1:0)+(r?0:1),o=(e,s)=>{for(;e>=0;e--){let a=t[e];if(""==a){if(e==t.length-1||0==e)continue;for(;s>=i;s--)if(o(e-1,s))return!0;return!1}{let e=s>0||0==s&&r?this.nodes[s].type:n&&s>=i?n.node(s-i).type:null;if(!e||e.name!=a&&-1==e.groups.indexOf(a))return!1;s--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let t in this.parser.schema.nodes){let e=this.parser.schema.nodes[t];if(e.isTextblock&&e.defaultAttrs)return e}}addPendingMark(e){let t=function(e,t){for(let n=0;n=0;n--){let r=this.nodes[n];if(r.pendingMarks.lastIndexOf(e)>-1)r.pendingMarks=e.removeFromSet(r.pendingMarks);else{r.activeMarks=e.removeFromSet(r.activeMarks);let t=r.popFromStashMark(e);t&&r.type&&r.type.allowsMarkType(t.type)&&(r.activeMarks=t.addToSet(r.activeMarks))}if(r==t)break}}}function Nc(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function Pc(e){let t={};for(let n in e)t[n]=e[n];return t}function Ic(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let o=[],s=e=>{o.push(e);for(let n=0;n{if(i.length||e.marks.length){let n=0,o=0;for(;n=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&Rc.renderSpec(jc(n),r(e,t))}static renderSpec(e,t,n=null){if("string"==typeof t)return{dom:e.createTextNode(t)};if(null!=t.nodeType)return{dom:t};if(t.dom&&null!=t.dom.nodeType)return t;let r,i=t[0],o=i.indexOf(" ");o>0&&(n=i.slice(0,o),i=i.slice(o+1));let s=n?e.createElementNS(n,i):e.createElement(i),a=t[1],l=1;if(a&&"object"==typeof a&&null==a.nodeType&&!Array.isArray(a)){l=2;for(let e in a)if(null!=a[e]){let t=e.indexOf(" ");t>0?s.setAttributeNS(e.slice(0,t),e.slice(t+1),a[e]):s.setAttribute(e,a[e])}}for(let c=l;cl)throw new RangeError("Content hole must be the only child of its parent node");return{dom:s,contentDOM:s}}{let{dom:t,contentDOM:o}=Rc.renderSpec(e,i,n);if(s.appendChild(t),o){if(r)throw new RangeError("Multiple content holes");r=o}}}return{dom:s,contentDOM:r}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new Rc(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=zc(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return zc(e.marks)}}function zc(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function jc(e){return e.document||window.document}const Fc=Math.pow(2,16);function Lc(e){return 65535&e}class Bc{constructor(e,t=!1,n=null){this.pos=e,this.deleted=t,this.recover=n}}class Vc{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Vc.empty)return Vc.empty}recover(e){let t=0,n=Lc(e);if(!this.inverted)for(let r=0;re)break;let l=this.ranges[s+i],c=this.ranges[s+o],u=a+l;if(e<=u){let i=a+r+((l?e==a?-1:e==u?1:t:t)<0?0:c);if(n)return i;let o=e==(t<0?a:u)?null:s/3+(e-a)*Fc;return new Bc(i,t<0?e!=a:e!=u,o)}r+=c-l}return n?e+r:new Bc(e+r)}touches(e,t){let n=0,r=Lc(t),i=this.inverted?2:1,o=this.inverted?1:2;for(let s=0;se)break;let a=this.ranges[s+i];if(e<=t+a&&s==3*r)return!0;n+=this.ranges[s+o]-a}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r=0;t--){let r=e.getMirror(t);this.appendMap(e.maps[t].invert(),null!=r&&r>t?n-r-1:void 0)}}invert(){let e=new Wc;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;ni&&te.isAtom&&t.type.allowsMarkType(this.mark.type)?e.mark(this.mark.addToSet(e.marks)):e),r),t.openStart,t.openEnd);return Jc.fromReplace(e,this.from,this.to,i)}invert(){return new Uc(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new Yc(t.pos,n.pos,this.mark)}merge(e){return e instanceof Yc&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Yc(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Yc(t.from,t.to,e.markFromJSON(t.mark))}}Hc.jsonID("addMark",Yc);class Uc extends Hc{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new Vl(Kc(t.content,(e=>e.mark(this.mark.removeFromSet(e.marks))),e),t.openStart,t.openEnd);return Jc.fromReplace(e,this.from,this.to,n)}invert(){return new Yc(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new Uc(t.pos,n.pos,this.mark)}merge(e){return e instanceof Uc&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Uc(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Uc(t.from,t.to,e.markFromJSON(t.mark))}}Hc.jsonID("removeMark",Uc);class Xc extends Hc{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&Zc(e,this.from,this.to)?Jc.fail("Structure replace would overwrite content"):Jc.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Vc([this.from,this.to-this.from,this.slice.size])}invert(e){return new Xc(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted?null:new Xc(t.pos,Math.max(t.pos,n.pos),this.slice)}merge(e){if(!(e instanceof Xc)||e.structure||this.structure)return null;if(this.from+this.slice.size!=e.from||this.slice.openEnd||e.slice.openStart){if(e.to!=this.from||this.slice.openStart||e.slice.openEnd)return null;{let t=this.slice.size+e.slice.size==0?Vl.empty:new Vl(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Xc(e.from,this.to,t,this.structure)}}{let t=this.slice.size+e.slice.size==0?Vl.empty:new Vl(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Xc(this.from,this.to+(e.to-e.from),t,this.structure)}}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Xc(t.from,t.to,Vl.fromJSON(e,t.slice),!!t.structure)}}Hc.jsonID("replace",Xc);class Gc extends Hc{constructor(e,t,n,r,i,o,s=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=i,this.insert=o,this.structure=s}apply(e){if(this.structure&&(Zc(e,this.from,this.gapFrom)||Zc(e,this.gapTo,this.to)))return Jc.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return Jc.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?Jc.fromReplace(e,this.from,this.to,n):Jc.fail("Content does not fit in gap")}getMap(){return new Vc([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new Gc(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1),r=e.map(this.gapFrom,-1),i=e.map(this.gapTo,1);return t.deleted&&n.deleted||rn.pos?null:new Gc(t.pos,n.pos,r,i,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to||"number"!=typeof t.gapFrom||"number"!=typeof t.gapTo||"number"!=typeof t.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Gc(t.from,t.to,t.gapFrom,t.gapTo,Vl.fromJSON(e,t.slice),t.insert,!!t.structure)}}function Zc(e,t,n){let r=e.resolve(t),i=n-t,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let e=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function Qc(e,t,n){return(0==t||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function eu(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth;;--n){let r=e.$from.node(n),i=e.$from.index(n),o=e.$to.indexAfter(n);if(no;c--,u--){let e=i.node(c),t=i.index(c);if(e.type.spec.isolating)return!1;let n=e.content.cutByIndex(t,e.childCount),o=r&&r[u]||e;if(o!=e&&(n=n.replaceChild(0,o.type.create(o.attrs))),!e.canReplace(t+1,e.childCount)||!o.type.validContent(n))return!1}let a=i.indexAfter(o),l=r&&r[0];return i.node(o).canReplaceWith(a,a,l?l.type:i.node(o+1).type)}function iu(e,t){let n=e.resolve(t),r=n.index();return i=n.nodeBefore,o=n.nodeAfter,!(!i||!o||i.isLeaf||!i.canAppend(o))&&n.parent.canReplace(r,r+1);var i,o}function ou(e,t,n=t,r=Vl.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),o=e.resolve(n);return su(i,o,r)?new Xc(t,n,r):new au(i,o,r).fit()}function su(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}Hc.jsonID("replaceAround",Gc);class au{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=Rl.empty;for(let r=0;r<=e.depth;r++){let t=e.node(r);this.frontier.push({type:t.type,match:t.contentMatchAt(e.indexAfter(r))})}for(let r=e.depth;r>0;r--)this.placed=Rl.from(e.node(r).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let i=this.placed,o=n.depth,s=r.depth;for(;o&&s&&1==i.childCount;)i=i.firstChild.content,o--,s--;let a=new Vl(i,o,s);return e>-1?new Gc(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new Xc(n.pos,r.pos,a):null}findFittable(){for(let e=1;e<=2;e++)for(let t=this.unplaced.openStart;t>=0;t--){let n,r=null;t?(r=uu(this.unplaced.content,t-1).firstChild,n=r.content):n=this.unplaced.content;let i=n.firstChild;for(let o=this.depth;o>=0;o--){let n,{type:s,match:a}=this.frontier[o],l=null;if(1==e&&(i?a.matchType(i.type)||(l=a.fillBefore(Rl.from(i),!1)):r&&s.compatibleContent(r.type)))return{sliceDepth:t,frontierDepth:o,parent:r,inject:l};if(2==e&&i&&(n=a.findWrapping(i.type)))return{sliceDepth:t,frontierDepth:o,parent:r,wrap:n};if(r&&a.matchType(r.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=uu(e,t);return!(!r.childCount||r.firstChild.isLeaf)&&(this.unplaced=new Vl(e,t+1,Math.max(n,r.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=uu(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new Vl(lu(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new Vl(lu(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let p=0;p1||0==a||e.content.size)&&(u=t,c.push(du(e.mark(d.allowedMarks(e.marks)),1==l?a:0,l==s.childCount?h:-1)))}let f=l==s.childCount;f||(h=-1),this.placed=cu(this.placed,t,Rl.from(c)),this.frontier[t].match=u,f&&h<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let p=0,m=s;p1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],i=t=0;n--){let{match:t,type:r}=this.frontier[n],i=hu(e,n,r,t,!0);if(!i||i.childCount)continue e}return{depth:t,fit:o,move:i?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=cu(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=cu(this.placed,this.depth,Rl.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(Rl.empty,!0);e.childCount&&(this.placed=cu(this.placed,this.frontier.length,e))}}function lu(e,t,n){return 0==t?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(lu(e.firstChild.content,t-1,n)))}function cu(e,t,n){return 0==t?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(cu(e.lastChild.content,t-1,n)))}function uu(e,t){for(let n=0;n1&&(r=r.replaceChild(0,du(r.firstChild,t-1,1==r.childCount?n-1:0))),t>0&&(r=e.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(e.type.contentMatch.matchFragment(r).fillBefore(Rl.empty,!0)))),e.copy(r)}function hu(e,t,n,r,i){let o=e.node(t),s=i?e.indexAfter(t):e.index(t);if(s==o.childCount&&!n.compatibleContent(o.type))return null;let a=r.fillBefore(o.content,!0,s);return a&&!function(e,t,n){for(let r=n;rr){let t=i.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(Rl.empty,!0))}return e}function mu(e,t){let n=[];for(let r=Math.min(e.depth,t.depth);r>=0;r--){let i=e.start(r);if(it.pos+(t.depth-r)||e.node(r).type.spec.isolating||t.node(r).type.spec.isolating)break;(i==t.start(r)||r==e.depth&&r==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&r&&t.start(r-1)==i-1)&&n.push(r)}return n}let gu=class extends Error{};gu=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},(gu.prototype=Object.create(Error.prototype)).constructor=gu,gu.prototype.name="TransformError";const vu=Object.create(null);class yu{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new bu(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;i--){let r=t<0?Du(e.node(0),e.node(i),e.before(i+1),e.index(i),t,n):Du(e.node(0),e.node(i),e.after(i+1),e.index(i)+1,t,n);if(r)return r}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Mu(e.node(0))}static atStart(e){return Du(e,e,0,0,1)||new Mu(e)}static atEnd(e){return Du(e,e,e.content.size,e.childCount,-1)||new Mu(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=vu[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in vu)throw new RangeError("Duplicate use of selection JSON ID "+e);return vu[e]=t,t.prototype.jsonID=e,t}getBookmark(){return Su.between(this.$anchor,this.$head).getBookmark()}}yu.prototype.visible=!0;class bu{constructor(e,t){this.$from=e,this.$to=t}}let wu=!1;function xu(e){wu||e.parent.inlineContent||(wu=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class Su extends yu{constructor(e,t=e){xu(e),xu(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return yu.near(n);let r=e.resolve(t.map(this.anchor));return new Su(r.parent.inlineContent?r:n,n)}replace(e,t=Vl.empty){if(super.replace(e,t),t==Vl.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(e){return e instanceof Su&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new ku(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if("number"!=typeof t.anchor||"number"!=typeof t.head)throw new RangeError("Invalid input for TextSelection.fromJSON");return new Su(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(e,t,n){let r=e.pos-t.pos;if(n&&!r||(n=r>=0?1:-1),!t.parent.inlineContent){let e=yu.findFrom(t,n,!0)||yu.findFrom(t,-n,!0);if(!e)return yu.near(t,n);t=e.$head}return e.parent.inlineContent||(0==r||(e=(yu.findFrom(e,-n,!0)||yu.findFrom(e,n,!0)).$anchor).posnew Mu(e)};function Du(e,t,n,r,i,o=!1){if(t.inlineContent)return Su.create(e,n);for(let s=r-(i>0?0:1);i>0?s=0;s+=i){let r=t.child(s);if(r.isAtom){if(!o&&Cu.isSelectable(r))return Cu.create(e,n-(i<0?r.nodeSize:0))}else{let t=Du(e,r,n+i,i<0?r.childCount:0,i,o);if(t)return t}n+=r.nodeSize*i}return null}function Tu(e,t,n){let r=e.steps.length-1;if(r{null==i&&(i=r)})),e.setSelection(yu.near(e.doc.resolve(i),n)))}class $u extends class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Wc}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new gu(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=Vl.empty){let r=ou(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new Vl(Rl.from(n),0,0))}delete(e,t){return this.replace(e,t,Vl.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return function(e,t,n,r){if(!r.size)return e.deleteRange(t,n);let i=e.doc.resolve(t),o=e.doc.resolve(n);if(su(i,o,r))return e.step(new Xc(t,n,r));let s=mu(i,e.doc.resolve(n));0==s[s.length-1]&&s.pop();let a=-(i.depth+1);s.unshift(a);for(let h=i.depth,f=i.pos-1;h>0;h--,f--){let e=i.node(h).type.spec;if(e.defining||e.definingAsContext||e.isolating)break;s.indexOf(h)>-1?a=h:i.before(h)==f&&s.splice(1,0,-h)}let l=s.indexOf(a),c=[],u=r.openStart;for(let h=r.content,f=0;;f++){let e=h.firstChild;if(c.push(e),f==r.openStart)break;h=e.content}for(let h=u-1;h>=0;h--){let e=c[h].type,t=fu(e);if(t&&i.node(l).type!=e)u=h;else if(t||!e.isTextblock)break}for(let h=r.openStart;h>=0;h--){let t=(h+u+1)%(r.openStart+1),a=c[t];if(a)for(let c=0;c=0&&(e.replace(t,n,r),!(e.steps.length>d));h--){let e=s[h];e<0||(t=i.before(e),n=o.after(e))}}(this,e,t,n),this}replaceRangeWith(e,t,n){return function(e,t,n,r){if(!r.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let i=function(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(0==r.parentOffset)for(let i=r.depth-1;i>=0;i--){let e=r.index(i);if(r.node(i).canReplaceWith(e,e,n))return r.before(i+1);if(e>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let e=r.indexAfter(i);if(r.node(i).canReplaceWith(e,e,n))return r.after(i+1);if(e0&&(n||r.node(t-1).canReplace(r.index(t-1),i.indexAfter(t-1))))return e.delete(r.before(t),i.after(t))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(t-r.start(s)==r.depth-s&&n>r.end(s)&&i.end(s)-n!=i.depth-s)return e.delete(r.before(s),n);e.delete(t,n)}(this,e,t),this}lift(e,t){return function(e,t,n){let{$from:r,$to:i,depth:o}=t,s=r.before(o+1),a=i.after(o+1),l=s,c=a,u=Rl.empty,d=0;for(let p=o,m=!1;p>n;p--)m||r.index(p)>0?(m=!0,u=Rl.from(r.node(p).copy(u)),d++):l--;let h=Rl.empty,f=0;for(let p=o,m=!1;p>n;p--)m||i.after(p+1)=0;s--){if(r.size){let e=n[s].type.contentMatch.matchFragment(r);if(!e||!e.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=Rl.from(n[s].type.create(n[s].attrs,r))}let i=t.start,o=t.end;e.step(new Gc(i,o,i,o,new Vl(r,0,0),n.length,!0))}(this,e,t),this}setBlockType(e,t=e,n,r=null){return function(e,t,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=e.steps.length;e.doc.nodesBetween(t,n,((t,n)=>{if(t.isTextblock&&!t.hasMarkup(r,i)&&function(e,t,n){let r=e.resolve(t),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}(e.doc,e.mapping.slice(o).map(n),r)){e.clearIncompatible(e.mapping.slice(o).map(n,1),r);let s=e.mapping.slice(o),a=s.map(n,1),l=s.map(n+t.nodeSize,1);return e.step(new Gc(a,l,a+1,l-1,new Vl(Rl.from(r.create(i,null,t.marks)),0,0),1,!0)),!1}}))}(this,e,t,n,r),this}setNodeMarkup(e,t,n=null,r=[]){return function(e,t,n,r,i){let o=e.doc.nodeAt(t);if(!o)throw new RangeError("No node at given position");n||(n=o.type);let s=n.create(r,null,i||o.marks);if(o.isLeaf)return e.replaceWith(t,t+o.nodeSize,s);if(!n.validContent(o.content))throw new RangeError("Invalid content for node type "+n.name);e.step(new Gc(t,t+o.nodeSize,t+1,t+o.nodeSize-1,new Vl(Rl.from(s),0,0),1,!0))}(this,e,t,n,r),this}split(e,t=1,n){return function(e,t,n=1,r){let i=e.doc.resolve(t),o=Rl.empty,s=Rl.empty;for(let a=i.depth,l=i.depth-n,c=n-1;a>l;a--,c--){o=Rl.from(i.node(a).copy(o));let e=r&&r[c];s=Rl.from(e?e.type.create(e.attrs,s):i.node(a).copy(s))}e.step(new Xc(t,t,new Vl(o.append(s),n,n),!0))}(this,e,t,n),this}addMark(e,t,n){return function(e,t,n,r){let i,o,s=[],a=[];e.doc.nodesBetween(t,n,((e,l,c)=>{if(!e.isInline)return;let u=e.marks;if(!r.isInSet(u)&&c.type.allowsMarkType(r.type)){let c=Math.max(l,t),d=Math.min(l+e.nodeSize,n),h=r.addToSet(u);for(let e=0;ee.step(t))),a.forEach((t=>e.step(t)))}(this,e,t,n),this}removeMark(e,t,n){return function(e,t,n,r){let i=[],o=0;e.doc.nodesBetween(t,n,((e,s)=>{if(!e.isInline)return;o++;let a=null;if(r instanceof kc){let t,n=e.marks;for(;t=r.isInSet(n);)(a||(a=[])).push(t),n=t.removeFromSet(n)}else r?r.isInSet(e.marks)&&(a=[r]):a=e.marks;if(a&&a.length){let r=Math.min(s+e.nodeSize,n);for(let e=0;ee.step(new Uc(t.from,t.to,t.style))))}(this,e,t,n),this}clearIncompatible(e,t,n){return function(e,t,n,r=n.contentMatch){let i=e.doc.nodeAt(t),o=[],s=t+1;for(let a=0;a=0;a--)e.step(o[a])}(this,e,t,n),this}}{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=2,this}ensureMarks(e){return Ll.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(2&this.updated)>0}addStep(e,t){super.addStep(e,t),this.updated=-3&this.updated,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||Ll.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(null==t)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(null==n&&(n=t),n=null==n?t:n,!e)return this.deleteRange(t,n);let i=this.storedMarks;if(!i){let e=this.doc.resolve(t);i=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,i)),this.selection.empty||this.setSelection(yu.near(this.selection.$to)),this}}setMeta(e,t){return this.meta["string"==typeof e?e:e.key]=t,this}getMeta(e){return this.meta["string"==typeof e?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=4,this}get scrolledIntoView(){return(4&this.updated)>0}}function Au(e,t){return t&&e?e.bind(t):e}class Eu{constructor(e,t,n){this.name=e,this.init=Au(t.init,n),this.apply=Au(t.apply,n)}}const Nu=[new Eu("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new Eu("selection",{init:(e,t)=>e.selection||yu.atStart(t.doc),apply:e=>e.selection}),new Eu("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,r)=>r.selection.$cursor?e.storedMarks:null}),new Eu("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t})];class Pu{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Nu.slice(),t&&t.forEach((e=>{if(this.pluginsByKey[e.key])throw new RangeError("Adding different instances of a keyed plugin ("+e.key+")");this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new Eu(e.key,e.spec.state,e))}))}}class Iu{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;ne.toJSON()))),e&&"object"==typeof e)for(let n in e){if("doc"==n||"selection"==n)throw new RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],i=r.spec.state;i&&i.toJSON&&(t[n]=i.toJSON.call(r,this[r.key]))}return t}static fromJSON(e,t,n){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let r=new Pu(e.schema,e.plugins),i=new Iu(r);return r.fields.forEach((r=>{if("doc"==r.name)i.doc=sc.fromJSON(e.schema,t.doc);else if("selection"==r.name)i.selection=yu.fromJSON(i.doc,t.selection);else if("storedMarks"==r.name)t.storedMarks&&(i.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let o in n){let s=n[o],a=s.spec.state;if(s.key==r.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,o))return void(i[r.name]=a.fromJSON.call(s,e,t[o],i))}i[r.name]=r.init(e,i)}})),i}}function Ru(e,t,n){for(let r in e){let i=e[r];i instanceof Function?i=i.bind(t):"handleDOMEvents"==r&&(i=Ru(i,t,{})),n[r]=i}return n}class zu{constructor(e){this.spec=e,this.props={},e.props&&Ru(e.props,this,this.props),this.key=e.key?e.key.key:Fu("plugin")}getState(e){return e[this.key]}}const ju=Object.create(null);function Fu(e){return e in ju?e+"$"+ ++ju[e]:(ju[e]=0,e+"$")}class Lu{constructor(e="key"){this.key=Fu(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Bu="undefined"!=typeof navigator?navigator:null,Vu="undefined"!=typeof document?document:null,Wu=Bu&&Bu.userAgent||"",qu=/Edge\/(\d+)/.exec(Wu),Hu=/MSIE \d/.exec(Wu),Ju=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Wu),Ku=!!(Hu||Ju||qu),Yu=Hu?document.documentMode:Ju?+Ju[1]:qu?+qu[1]:0,Uu=!Ku&&/gecko\/(\d+)/i.test(Wu);Uu&&(/Firefox\/(\d+)/.exec(Wu)||[0,0])[1];const Xu=!Ku&&/Chrome\/(\d+)/.exec(Wu),Gu=!!Xu,Zu=Xu?+Xu[1]:0,Qu=!Ku&&!!Bu&&/Apple Computer/.test(Bu.vendor),ed=Qu&&(/Mobile\/\w+/.test(Wu)||!!Bu&&Bu.maxTouchPoints>2),td=ed||!!Bu&&/Mac/.test(Bu.platform),nd=/Android \d/.test(Wu),rd=!!Vu&&"webkitFontSmoothing"in Vu.documentElement.style,id=rd?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,od=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},sd=function(e){let t=e.assignedSlot||e.parentNode;return t&&11==t.nodeType?t.host:t};let ad=null;const ld=function(e,t,n){let r=ad||(ad=document.createRange());return r.setEnd(e,null==n?e.nodeValue.length:n),r.setStart(e,t||0),r},cd=function(e,t,n,r){return n&&(dd(e,t,n,r,-1)||dd(e,t,n,r,1))},ud=/^(img|br|input|textarea|hr)$/i;function dd(e,t,n,r,i){for(;;){if(e==n&&t==r)return!0;if(t==(i<0?0:hd(e))){let n=e.parentNode;if(!n||1!=n.nodeType||fd(e)||ud.test(e.nodeName)||"false"==e.contentEditable)return!1;t=od(e)+(i<0?0:1),e=n}else{if(1!=e.nodeType)return!1;if("false"==(e=e.childNodes[t+(i<0?-1:0)]).contentEditable)return!1;t=i<0?hd(e):0}}}function hd(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function fd(e){let t;for(let n=e;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&t.node.isBlock&&(t.dom==e||t.contentDOM==e)}const pd=function(e){let t=e.isCollapsed;return t&&Gu&&e.rangeCount&&!e.getRangeAt(0).collapsed&&(t=!1),t};function md(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}function gd(e){return{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function vd(e,t){return"number"==typeof e?e:e[t]}function yd(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}function bd(e,t,n){let r=e.someProp("scrollThreshold")||0,i=e.someProp("scrollMargin")||5,o=e.dom.ownerDocument;for(let s=n||e.dom;s;s=sd(s)){if(1!=s.nodeType)continue;let e=s,n=e==o.body,a=n?gd(o):yd(e),l=0,c=0;if(t.topa.bottom-vd(r,"bottom")&&(c=t.bottom-a.bottom+vd(i,"bottom")),t.lefta.right-vd(r,"right")&&(l=t.right-a.right+vd(i,"right")),l||c)if(n)o.defaultView.scrollBy(l,c);else{let n=e.scrollLeft,r=e.scrollTop;c&&(e.scrollTop+=c),l&&(e.scrollLeft+=l);let i=e.scrollLeft-n,o=e.scrollTop-r;t={left:t.left-i,top:t.top-o,right:t.right-i,bottom:t.bottom-o}}if(n)break}}function wd(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=sd(r));return t}function xd(e,t){for(let n=0;n=a){s=Math.max(d.bottom,s),a=Math.min(d.top,a);let e=d.left>t.left?d.left-t.left:d.right=(d.left+d.right)/2?1:0));continue}}!n&&(t.left>=d.right&&t.top>=d.top||t.left>=d.left&&t.top>=d.bottom)&&(o=c+1)}}return n&&3==n.nodeType?function(e,t){let n=e.nodeValue.length,r=document.createRange();for(let i=0;i=(n.left+n.right)/2?1:0)}}return{node:e,offset:0}}(n,r):!n||i&&1==n.nodeType?{node:e,offset:o}:kd(n,r)}function Cd(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function Od(e,t,n){let r=e.childNodes.length;if(r&&n.topt.top&&i++}n==e.dom&&i==n.childNodes.length-1&&1==n.lastChild.nodeType&&t.top>n.lastChild.getBoundingClientRect().bottom?o=e.state.doc.content.size:0!=i&&1==n.nodeType&&"BR"==n.childNodes[i-1].nodeName||(o=function(e,t,n,r){let i=-1;for(let o=t;o!=e.dom;){let t=e.docView.nearestDesc(o,!0);if(!t)return null;if(t.node.isBlock&&t.parent){let e=t.dom.getBoundingClientRect();if(e.left>r.left||e.top>r.top)i=t.posBefore;else{if(!(e.right-1?i:e.docView.posFromDOM(t,n,1)}(e,n,i,t))}null==o&&(o=function(e,t,n){let{node:r,offset:i}=kd(t,n),o=-1;if(1==r.nodeType&&!r.firstChild){let e=r.getBoundingClientRect();o=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(r,i,o)}(e,s,t));let a=e.docView.nearestDesc(s,!0);return{pos:o,inside:a?a.posAtStart-a.border:-1}}function _d(e,t){let n=e.getClientRects();return n.length?n[t<0?0:n.length-1]:e.getBoundingClientRect()}const Dd=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Td(e,t,n){let{node:r,offset:i}=e.docView.domFromPos(t,n<0?-1:1),o=rd||Uu;if(3==r.nodeType){if(!o||!Dd.test(r.nodeValue)&&(n<0?i:i!=r.nodeValue.length)){let e=i,t=i,o=n<0?1:-1;return n<0&&!i?(t++,o=-1):n>=0&&i==r.nodeValue.length?(e--,o=1):n<0?e--:t++,$d(_d(ld(r,e,t),o),o<0)}{let e=_d(ld(r,i,i),n);if(Uu&&i&&/\s/.test(r.nodeValue[i-1])&&i=0)}if(i&&(n<0||i==hd(r))){let e=r.childNodes[i-1],t=3==e.nodeType?ld(e,hd(e)-(o?0:1)):1!=e.nodeType||"BR"==e.nodeName&&e.nextSibling?null:e;if(t)return $d(_d(t,1),!1)}if(i=0)}function $d(e,t){if(0==e.width)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function Ad(e,t){if(0==e.height)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function Ed(e,t,n){let r=e.state,i=e.root.activeElement;r!=t&&e.updateState(t),i!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),i!=e.dom&&i&&i.focus()}}const Nd=/[\u0590-\u08ac]/;let Pd=null,Id=null,Rd=!1;function zd(e,t,n){return Pd==t&&Id==n?Rd:(Pd=t,Id=n,Rd="up"==n||"down"==n?function(e,t,n){let r=t.selection,i="up"==n?r.$from:r.$to;return Ed(e,t,(()=>{let{node:t}=e.docView.domFromPos(i.pos,"up"==n?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.dom;break}t=n.dom.parentNode}let r=Td(e,i.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(1==e.nodeType)t=e.getClientRects();else{if(3!=e.nodeType)continue;t=ld(e,0,e.nodeValue.length).getClientRects()}for(let e=0;ei.top+1&&("up"==n?r.top-i.top>2*(i.bottom-r.top):i.bottom-r.bottom>2*(r.bottom-i.top)))return!1}}return!0}))}(e,t,n):function(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,a=e.domSelection();return Nd.test(r.parent.textContent)&&a.modify?Ed(e,t,(()=>{let t=a.getRangeAt(0),i=a.focusNode,o=a.focusOffset,s=a.caretBidiLevel;a.modify("move",n,"character");let l=!(r.depth?e.docView.domAfterPos(r.before()):e.dom).contains(1==a.focusNode.nodeType?a.focusNode:a.focusNode.parentNode)||i==a.focusNode&&o==a.focusOffset;return a.removeAllRanges(),a.addRange(t),null!=s&&(a.caretBidiLevel=s),l})):"left"==n||"backward"==n?o:s}(e,t,n))}class jd{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=0,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tod(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=2&e.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==t)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(null==r&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return(null==r?n>0:r)?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let i,o=this.getDesc(r);if(o&&(!t||o.node)){if(!n||!(i=o.nodeDOM)||(1==i.nodeType?i.contains(1==e.nodeType?e:e.parentNode):i==e))return o;n=!1}}}getDesc(e){let t=e.pmViewDesc;for(let n=t;n;n=n.parent)if(n==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let i=this.getDesc(r);if(i)return i.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;te||t instanceof Hd){i=e-o;break}o=n}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(;r&&!(n=this.children[r-1]).size&&n instanceof Fd&&n.side>=0;r--);if(t<=0){let e,n=!0;for(;e=r?this.children[r-1]:null,e&&e.dom.parentNode!=this.contentDOM;r--,n=!1);return e&&t&&n&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?od(e.dom)+1:0}}{let e,n=!0;for(;e=r=i&&t<=a-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,i);e=o;for(let t=s;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=od(n.dom)+1;break}e-=n.size}-1==r&&(r=0)}if(r>-1&&(a>t||s==this.children.length-1)){t=a;for(let e=s+1;ef&&ot){let e=s;s=a,a=e}let n=document.createRange();n.setEnd(a.node,a.offset),n.setStart(s.node,s.offset),l.removeAllRanges(),l.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&"selection"!=e.type}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,r=0;r=n:en){let r=n+i.border,s=o-i.border;if(e>=r&&t<=s)return this.dirty=e==n||t==o?2:1,void(e!=r||t!=s||!i.contentLost&&i.dom.parentNode==this.contentDOM?i.markDirty(e-r,t-r):i.dirty=3);i.dirty=i.dom!=i.contentDOM||i.dom.parentNode!=this.contentDOM||i.children.length?3:2}n=o}this.dirty=2}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=1==e?2:1;t.dirtyi?i.parent?i.parent.posBeforeChild(i):void 0:r))),!t.type.spec.raw){if(1!=o.nodeType){let e=document.createElement("span");e.appendChild(o),o=e}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return 0==this.dirty&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return!!t&&t(e)}ignoreMutation(e){return"selection"!=e.type||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}}class Ld extends jd{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return"characterData"===e.type&&e.target.nodeValue==e.oldValue}}class Bd extends jd{constructor(e,t,n,r){super(e,[],n,r),this.mark=t}static create(e,t,n,r){let i=r.nodeViews[t.type.name],o=i&&i(t,r,n);return o&&o.dom||(o=Rc.renderSpec(document,t.type.spec.toDOM(t,n))),new Bd(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return 3&this.dirty||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM||void 0}}matchesMark(e){return 3!=this.dirty&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),0!=this.dirty){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty0&&(i=ih(i,0,e,n));for(let s=0;ss?s.parent?s.parent.posBeforeChild(s):void 0:o),n,r),c=l&&l.dom,u=l&&l.contentDOM;if(t.isText)if(c){if(3!=c.nodeType)throw new RangeError("Text must be rendered as a DOM text node")}else c=document.createTextNode(t.text);else c||({dom:c,contentDOM:u}=Rc.renderSpec(document,t.type.spec.toDOM(t)));u||t.isText||"BR"==c.nodeName||(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let d=c;return c=Qd(c,n,t),l?s=new Jd(e,t,n,r,c,u||null,d,l,i,o+1):t.isText?new qd(e,t,n,r,c,d,i):new Vd(e,t,n,r,c,u||null,d,i,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if("pre"==this.node.type.whitespace&&(e.preserveWhitespace="full"),this.contentDOM)if(this.contentLost){for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>Rl.empty)}else e.contentElement=this.contentDOM;else e.getContent=()=>this.node.content;return e}matchesNode(e,t,n){return 0==this.dirty&&e.eq(this.node)&&eh(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=this.node.inlineContent,r=t,i=e.composing?this.localCompositionInfo(e,t):null,o=i&&i.pos>-1?i:null,s=i&&i.pos<0,a=new nh(this,o&&o.node);!function(e,t,n,r){let i=t.locals(e),o=0;if(0==i.length){for(let n=0;no;)a.push(i[s++]);let h=o+u.nodeSize;if(u.isText){let e=h;s!e.inline)):a.slice(),t.forChild(o,u),d),o=h}}(this.node,this.innerDeco,((t,i,o)=>{t.spec.marks?a.syncToMarks(t.spec.marks,n,e):t.type.side>=0&&!o&&a.syncToMarks(i==this.node.childCount?Ll.none:this.node.child(i).marks,n,e),a.placeWidget(t,e,r)}),((t,o,l,c)=>{let u;a.syncToMarks(t.marks,n,e),a.findNodeMatch(t,o,l,c)||s&&e.state.selection.from>r&&e.state.selection.to-1&&a.updateNodeAt(t,o,l,u,e)||a.updateNextNode(t,o,l,e,c)||a.addNode(t,o,l,e,r),r+=t.nodeSize})),a.syncToMarks([],n,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||2==this.dirty)&&(o&&this.protectLocalComposition(e,o),Kd(this.contentDOM,this.children,e),ed&&function(e){if("UL"==e.nodeName||"OL"==e.nodeName){let t=e.style.cssText;e.style.cssText=t+"; list-style: square !important",window.getComputedStyle(e).listStyle,e.style.cssText=t}}(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof Su)||nt+this.node.content.size)return null;let i=e.domSelection(),o=function(e,t){for(;;){if(3==e.nodeType)return e;if(1==e.nodeType&&t>0){if(e.childNodes.length>t&&3==e.childNodes[t].nodeType)return e.childNodes[t];t=hd(e=e.childNodes[t-1])}else{if(!(1==e.nodeType&&t=n){let e=a=0&&e+t.length+a>=n)return a+e;if(n==r&&l.length>=r+t.length-a&&l.slice(r-a,r-a+t.length)==t)return r}}return-1}(this.node.content,e,n-t,r-t);return i<0?null:{node:o,pos:i,text:e}}return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&(i.pmViewDesc=void 0)}let o=new Ld(this,i,t,r);e.input.compositionNodes.push(o),this.children=ih(this.children,n,n+r.length,e,o)}update(e,t,n,r){return!(3==this.dirty||!e.sameMarkup(this.node))&&(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=0}updateOuterDeco(e){if(eh(e,this.outerDeco))return;let t=1!=this.nodeDOM.nodeType,n=this.dom;this.dom=Gd(this.dom,this.nodeDOM,Xd(this.outerDeco,this.node,t),Xd(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){1==this.nodeDOM.nodeType&&this.nodeDOM.classList.add("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||(this.dom.draggable=!0)}deselectNode(){1==this.nodeDOM.nodeType&&this.nodeDOM.classList.remove("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||this.dom.removeAttribute("draggable")}get domAtom(){return this.node.isAtom}}function Wd(e,t,n,r,i){return Qd(r,t,e),new Vd(void 0,e,t,n,r,r,r,i,0)}class qd extends Vd{constructor(e,t,n,r,i,o,s){super(e,t,n,r,i,null,o,s,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return!(3==this.dirty||0!=this.dirty&&!this.inParent()||!e.sameMarkup(this.node))&&(this.updateOuterDeco(t),0==this.dirty&&e.text==this.node.text||e.text==this.nodeDOM.nodeValue||(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=0,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return"characterData"!=e.type&&"selection"!=e.type}slice(e,t,n){let r=this.node.cut(e,t),i=document.createTextNode(r.text);return new qd(this.parent,r,this.outerDeco,this.innerDeco,i,i,n)}markDirty(e,t){super.markDirty(e,t),this.dom==this.nodeDOM||0!=e&&t!=this.nodeDOM.nodeValue.length||(this.dirty=3)}get domAtom(){return!1}}class Hd extends jd{parseRule(){return{ignore:!0}}matchesHack(e){return 0==this.dirty&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return"IMG"==this.dom.nodeName}}class Jd extends Vd{constructor(e,t,n,r,i,o,s,a,l,c){super(e,t,n,r,i,o,s,l,c),this.spec=a}update(e,t,n,r){if(3==this.dirty)return!1;if(this.spec.update){let i=this.spec.update(e,t,n);return i&&this.updateInner(e,t,n,r),i}return!(!this.contentDOM&&!e.isLeaf)&&super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n):super.setSelection(e,t,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return!!this.spec.stopEvent&&this.spec.stopEvent(e)}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function Kd(e,t,n){let r=e.firstChild,i=!1;for(let o=0;o0;){let a;for(;;)if(r){let e=n.children[r-1];if(!(e instanceof Bd)){a=e,r--;break}n=e,r=e.children.length}else{if(n==t)break e;r=n.parent.children.indexOf(n),n=n.parent}let l=a.node;if(l){if(l!=e.child(i-1))break;--i,o.set(a,i),s.push(a)}}return{index:i,matched:o,matches:s.reverse()}}(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n>1,o=Math.min(i,e.length);for(;r-1)r>this.index&&(this.changed=!0,this.destroyBetween(this.index,r)),this.top=this.top.children[this.index];else{let r=Bd.create(this.top,e[i],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,i++}}findNodeMatch(e,t,n,r){let i,o=-1;if(r>=this.preMatch.index&&(i=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&i.matchesNode(e,t,n))o=this.top.children.indexOf(i,this.index);else for(let s=this.index,a=Math.min(this.top.children.length,s+5);s=n||u<=t?o.push(l):(cn&&o.push(l.slice(n-c,l.size,r)))}return o}function oh(e,t=null){let n=e.domSelection(),r=e.state.doc;if(!n.focusNode)return null;let i=e.docView.nearestDesc(n.focusNode),o=i&&0==i.size,s=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let a,l,c=r.resolve(s);if(pd(n)){for(a=c;i&&!i.node;)i=i.parent;let e=i.node;if(i&&e.isAtom&&Cu.isSelectable(e)&&i.parent&&(!e.isInline||!function(e,t,n){for(let r=0==t,i=t==hd(e);r||i;){if(e==n)return!0;let t=od(e);if(!(e=e.parentNode))return!1;r=r&&0==t,i=i&&t==hd(e)}}(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;l=new Cu(s==e?c:r.resolve(e))}}else{let t=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(t<0)return null;a=r.resolve(t)}if(!l){l=ph(e,a,c,"pointer"==t||e.state.selection.head{n.anchorNode==r&&n.anchorOffset==i||(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout((()=>{sh(e)&&!e.state.selection.visible||e.dom.classList.remove("ProseMirror-hideselection")}),20))})}(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}const lh=Qu||Gu&&Zu<63;function ch(e,t){let{node:n,offset:r}=e.docView.domFromPos(t,0),i=rr(e,t,n)))||Su.between(t,n,r)}function mh(e){return(!e.editable||e.root.activeElement==e.dom)&&gh(e)}function gh(e){let t=e.domSelection();if(!t.anchorNode)return!1;try{return e.dom.contains(3==t.anchorNode.nodeType?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(3==t.focusNode.nodeType?t.focusNode.parentNode:t.focusNode))}catch(n){return!1}}function vh(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),o=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return o&&yu.findFrom(o,t)}function yh(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function bh(e,t,n){let r=e.state.selection;if(!(r instanceof Su)){if(r instanceof Cu&&r.node.isInline)return yh(e,new Su(t>0?r.$to:r.$from));{let n=vh(e.state,t);return!!n&&yh(e,n)}}if(!r.empty||n.indexOf("s")>-1)return!1;if(e.endOfTextblock(t>0?"right":"left")){let n=vh(e.state,t);return!!(n&&n instanceof Cu)&&yh(e,n)}if(!(td&&n.indexOf("m")>-1)){let n,i=r.$head,o=i.textOffset?null:t<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText)return!1;let s=t<0?i.pos-o.nodeSize:i.pos;return!!(o.isAtom||(n=e.docView.descAt(s))&&!n.contentDOM)&&(Cu.isSelectable(o)?yh(e,new Cu(t<0?e.state.doc.resolve(i.pos-o.nodeSize):i)):!!rd&&yh(e,new Su(e.state.doc.resolve(t<0?s:s+o.nodeSize))))}}function wh(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function xh(e){let t=e.pmViewDesc;return t&&0==t.size&&(e.nextSibling||"BR"!=e.nodeName)}function Sh(e){let t=e.domSelection(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,o,s=!1;for(Uu&&1==n.nodeType&&r0){if(1!=n.nodeType)break;{let e=n.childNodes[r-1];if(xh(e))i=n,o=--r;else{if(3!=e.nodeType)break;n=e,r=n.nodeValue.length}}}else{if(Ch(n))break;{let t=n.previousSibling;for(;t&&xh(t);)i=n.parentNode,o=od(t),t=t.previousSibling;if(t)n=t,r=wh(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}}s?Oh(e,t,n,r):i&&Oh(e,t,i,o)}function kh(e){let t=e.domSelection(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,o,s=wh(n);for(;;)if(r{e.state==i&&ah(e)}),50)}function Mh(e,t,n){let r=e.state.selection;if(r instanceof Su&&!r.empty||n.indexOf("s")>-1)return!1;if(td&&n.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=vh(e.state,t);if(n&&n instanceof Cu)return yh(e,n)}if(!i.parent.inlineContent){let n=t<0?i:o,s=r instanceof Mu?yu.near(n,t):yu.findFrom(n,t);return!!s&&yh(e,s)}return!1}function _h(e,t){if(!(e.state.selection instanceof Su))return!0;let{$head:n,$anchor:r,empty:i}=e.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?"forward":"backward"))return!0;let o=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(o&&!o.isText){let r=e.state.tr;return t<0?r.delete(n.pos-o.nodeSize,n.pos):r.delete(n.pos,n.pos+o.nodeSize),e.dispatch(r),!0}return!1}function Dh(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function Th(e,t){let n=t.keyCode,r=function(e){let t="";return e.ctrlKey&&(t+="c"),e.metaKey&&(t+="m"),e.altKey&&(t+="a"),e.shiftKey&&(t+="s"),t}(t);return 8==n||td&&72==n&&"c"==r?_h(e,-1)||Sh(e):46==n||td&&68==n&&"c"==r?_h(e,1)||kh(e):13==n||27==n||(37==n||td&&66==n&&"c"==r?bh(e,-1,r)||Sh(e):39==n||td&&70==n&&"c"==r?bh(e,1,r)||kh(e):38==n||td&&80==n&&"c"==r?Mh(e,-1,r)||Sh(e):40==n||td&&78==n&&"c"==r?function(e){if(!Qu||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelection();if(t&&1==t.nodeType&&0==n&&t.firstChild&&"false"==t.firstChild.contentEditable){let n=t.firstChild;Dh(e,n,"true"),setTimeout((()=>Dh(e,n,"false")),20)}return!1}(e)||Mh(e,1,r)||kh(e):r==(td?"m":"c")&&(66==n||73==n||89==n||90==n))}function $h(e,t){let n=[],{content:r,openStart:i,openEnd:o}=t;for(;i>1&&o>1&&1==r.childCount&&1==r.firstChild.childCount;){i--,o--;let e=r.firstChild;n.push(e.type.name,e.attrs!=e.type.defaultAttrs?e.attrs:null),r=e.content}let s=e.someProp("clipboardSerializer")||Rc.fromSchema(e.state.schema),a=Lh(),l=a.createElement("div");l.appendChild(s.serializeFragment(r,{document:a}));let c,u=l.firstChild,d=0;for(;u&&1==u.nodeType&&(c=jh[u.nodeName.toLowerCase()]);){for(let e=c.length-1;e>=0;e--){let t=a.createElement(c[e]);for(;l.firstChild;)t.appendChild(l.firstChild);l.appendChild(t),d++}u=l.firstChild}return u&&1==u.nodeType&&u.setAttribute("data-pm-slice",`${i} ${o}${d?` -${d}`:""} ${JSON.stringify(n)}`),{dom:l,text:e.someProp("clipboardTextSerializer",(e=>e(t)))||t.content.textBetween(0,t.content.size,"\n\n")}}function Ah(e,t,n,r,i){let o,s,a=i.parent.type.spec.code;if(!n&&!t)return null;let l=t&&(r||a||!n);if(l){if(e.someProp("transformPastedText",(e=>{t=e(t,a||r)})),a)return t?new Vl(Rl.from(e.state.schema.text(t.replace(/\r\n?/g,"\n"))),0,0):Vl.empty;let n=e.someProp("clipboardTextParser",(e=>e(t,i,r)));if(n)s=n;else{let n=i.marks(),{schema:r}=e.state,s=Rc.fromSchema(r);o=document.createElement("div"),t.split(/(?:\r\n?|\n)+/).forEach((e=>{let t=o.appendChild(document.createElement("p"));e&&t.appendChild(s.serializeNode(r.text(e,n)))}))}}else e.someProp("transformPastedHTML",(e=>{n=e(n)})),o=function(e){let t=/^(\s*]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n,r=Lh().createElement("div"),i=/<([a-z][^>\s]+)/i.exec(e);(n=i&&jh[i[1].toLowerCase()])&&(e=n.map((e=>"<"+e+">")).join("")+e+n.map((e=>"")).reverse().join(""));if(r.innerHTML=e,n)for(let o=0;o0&&o.firstChild;d--)o=o.firstChild;if(!s){let t=e.someProp("clipboardParser")||e.someProp("domParser")||Mc.fromSchema(e.state.schema);s=t.parseSlice(o,{preserveWhitespace:!(!l&&!u),context:i,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||Eh.test(e.parentNode.nodeName)?null:{ignore:!0}})}if(u)s=function(e,t){if(!e.size)return e;let n,r=e.content.firstChild.type.schema;try{n=JSON.parse(t)}catch(wy){return e}let{content:i,openStart:o,openEnd:s}=e;for(let a=n.length-2;a>=0;a-=2){let e=r.nodes[n[a]];if(!e||e.hasRequiredAttrs())break;i=Rl.from(e.create(n[a+1],i)),o++,s++}return new Vl(i,o,s)}(zh(s,+u[1],+u[2]),u[4]);else if(s=Vl.maxOpen(function(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r,i=t.node(n).contentMatchAt(t.index(n)),o=[];if(e.forEach((e=>{if(!o)return;let t,n=i.findWrapping(e.type);if(!n)return o=null;if(t=o.length&&r.length&&Ph(n,r,e,o[o.length-1],0))o[o.length-1]=t;else{o.length&&(o[o.length-1]=Ih(o[o.length-1],r.length));let t=Nh(e,n);o.push(t),i=i.matchType(t.type),r=n}})),o)return Rl.from(o)}return e}(s.content,i),!0),s.openStart||s.openEnd){let e=0,t=0;for(let n=s.content.firstChild;e{s=e(s)})),s}const Eh=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function Nh(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,Rl.from(e));return e}function Ph(e,t,n,r,i){if(i=n&&(a=t<0?s.contentMatchAt(0).fillBefore(a,e.childCount>1||o<=i).append(a):a.append(s.contentMatchAt(s.childCount).fillBefore(Rl.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,s.copy(a))}function zh(e,t,n){return t{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>Jh(e,t))}))}function Jh(e,t){return e.someProp("handleDOMEvents",(n=>{let r=n[t.type];return!!r&&(r(e,t)||t.defaultPrevented)}))}function Kh(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||11==n.nodeType||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function Yh(e){return{left:e.clientX,top:e.clientY}}function Uh(e,t,n,r,i){if(-1==r)return!1;let o=e.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(e.someProp(t,(t=>s>o.depth?t(e,n,o.nodeAfter,o.before(s),i,!0):t(e,n,o.node(s),o.before(s),i,!1))))return!0;return!1}function Xh(e,t,n){e.focused||e.focus();let r=e.state.tr.setSelection(t);"pointer"==n&&r.setMeta("pointer",!0),e.dispatch(r)}function Gh(e,t,n,r,i){return Uh(e,"handleClickOn",t,n,r)||e.someProp("handleClick",(n=>n(e,t,r)))||(i?function(e,t){if(-1==t)return!1;let n,r,i=e.state.selection;i instanceof Cu&&(n=i.node);let o=e.state.doc.resolve(t);for(let s=o.depth+1;s>0;s--){let e=s>o.depth?o.nodeAfter:o.node(s);if(Cu.isSelectable(e)){r=n&&i.$from.depth>0&&s>=i.$from.depth&&o.before(i.$from.depth+1)==i.$from.pos?o.before(i.$from.depth):o.before(s);break}}return null!=r&&(Xh(e,Cu.create(e.state.doc,r),"pointer"),!0)}(e,n):function(e,t){if(-1==t)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return!!(r&&r.isAtom&&Cu.isSelectable(r))&&(Xh(e,new Cu(n),"pointer"),!0)}(e,n))}function Zh(e,t,n,r){return Uh(e,"handleDoubleClickOn",t,n,r)||e.someProp("handleDoubleClick",(n=>n(e,t,r)))}function Qh(e,t,n,r){return Uh(e,"handleTripleClickOn",t,n,r)||e.someProp("handleTripleClick",(n=>n(e,t,r)))||function(e,t,n){if(0!=n.button)return!1;let r=e.state.doc;if(-1==t)return!!r.inlineContent&&(Xh(e,Su.create(r,0,r.content.size),"pointer"),!0);let i=r.resolve(t);for(let o=i.depth+1;o>0;o--){let t=o>i.depth?i.nodeAfter:i.node(o),n=i.before(o);if(t.inlineContent)Xh(e,Su.create(r,n+1,n+1+t.content.size),"pointer");else{if(!Cu.isSelectable(t))continue;Xh(e,Cu.create(r,n),"pointer")}return!0}}(e,n,r)}function ef(e){return lf(e)}Vh.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=16==n.keyCode||n.shiftKey,!rf(e,n)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!nd||!Gu||13!=n.keyCode))if(229!=n.keyCode&&e.domObserver.forceFlush(),!ed||13!=n.keyCode||n.ctrlKey||n.altKey||n.metaKey)e.someProp("handleKeyDown",(t=>t(e,n)))||Th(e,n)?n.preventDefault():qh(e,"key");else{let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout((()=>{e.input.lastIOSEnter==t&&(e.someProp("handleKeyDown",(t=>t(e,md(13,"Enter")))),e.input.lastIOSEnter=0)}),200)}},Vh.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},Vh.keypress=(e,t)=>{let n=t;if(rf(e,n)||!n.charCode||n.ctrlKey&&!n.altKey||td&&n.metaKey)return;if(e.someProp("handleKeyPress",(t=>t(e,n))))return void n.preventDefault();let r=e.state.selection;if(!(r instanceof Su&&r.$from.sameParent(r.$to))){let t=String.fromCharCode(n.charCode);e.someProp("handleTextInput",(n=>n(e,r.$from.pos,r.$to.pos,t)))||e.dispatch(e.state.tr.insertText(t).scrollIntoView()),n.preventDefault()}};const tf=td?"metaKey":"ctrlKey";Bh.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=ef(e),i=Date.now(),o="singleClick";i-e.input.lastClick.time<500&&function(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}(n,e.input.lastClick)&&!n[tf]&&("singleClick"==e.input.lastClick.type?o="doubleClick":"doubleClick"==e.input.lastClick.type&&(o="tripleClick")),e.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:o};let s=e.posAtCoords(Yh(n));s&&("singleClick"==o?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new nf(e,s,n,!!r)):("doubleClick"==o?Zh:Qh)(e,s.pos,s.inside,n)?n.preventDefault():qh(e,"pointer"))};class nf{constructor(e,t,n,r){let i,o;if(this.view=e,this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[tf],this.allowDefault=n.shiftKey,t.inside>-1)i=e.state.doc.nodeAt(t.inside),o=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,o=n.depth?n.before():0}const s=r?null:n.target,a=s?e.docView.nearestDesc(s,!0):null;this.target=a?a.dom:null;let{selection:l}=e.state;(0==n.button&&i.type.spec.draggable&&!1!==i.type.spec.selectable||l instanceof Cu&&l.from<=o&&l.to>o)&&(this.mightDrag={node:i,pos:o,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!Uu||this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout((()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")}),20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),qh(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout((()=>ah(this.view))),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(Yh(e))),this.allowDefault||!t?qh(this.view,"pointer"):Gh(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():0==e.button&&(this.flushed||Qu&&this.mightDrag&&!this.mightDrag.node.isAtom||Gu&&!(this.view.state.selection instanceof Su)&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(Xh(this.view,yu.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):qh(this.view,"pointer")}move(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0),qh(this.view,"pointer"),0==e.buttons&&this.done()}}function rf(e,t){return!!e.composing||!!(Qu&&Math.abs(t.timeStamp-e.input.compositionEndedAt)<500)&&(e.input.compositionEndedAt=-2e8,!0)}Bh.touchdown=e=>{ef(e),qh(e,"pointer")},Bh.contextmenu=e=>ef(e);const of=nd?5e3:-1;function sf(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout((()=>lf(e)),t))}function af(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=function(){let e=document.createEvent("Event");return e.initEvent("event",!0,!0),e.timeStamp}());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function lf(e,t=!1){if(!(nd&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),af(e),t||e.docView&&e.docView.dirty){let t=oh(e);return t&&!t.eq(e.state.selection)?e.dispatch(e.state.tr.setSelection(t)):e.updateState(e.state),!0}return!1}}Vh.compositionstart=Vh.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$from;if(t.selection.empty&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some((e=>!1===e.type.spec.inclusive))))e.markCursor=e.state.storedMarks||n.marks(),lf(e,!0),e.markCursor=null;else if(lf(e),Uu&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelection();for(let e=t.focusNode,n=t.focusOffset;e&&1==e.nodeType&&0!=n;){let r=n<0?e.lastChild:e.childNodes[n-1];if(!r)break;if(3==r.nodeType){t.collapse(r,r.nodeValue.length);break}e=r,n=-1}}e.input.composing=!0}sf(e,of)},Vh.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,sf(e,20))};const cf=Ku&&Yu<15||ed&&id<604;function uf(e,t,n,r){let i=Ah(e,t,n,e.input.shiftKey,e.state.selection.$from);if(e.someProp("handlePaste",(t=>t(e,r,i||Vl.empty))))return!0;if(!i)return!1;let o=function(e){return 0==e.openStart&&0==e.openEnd&&1==e.content.childCount?e.content.firstChild:null}(i),s=o?e.state.tr.replaceSelectionWith(o,e.input.shiftKey):e.state.tr.replaceSelection(i);return e.dispatch(s.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}Bh.copy=Vh.cut=(e,t)=>{let n=t,r=e.state.selection,i="cut"==n.type;if(r.empty)return;let o=cf?null:n.clipboardData,s=r.content(),{dom:a,text:l}=$h(e,s);o?(n.preventDefault(),o.clearData(),o.setData("text/html",a.innerHTML),o.setData("text/plain",l)):function(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(t),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout((()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()}),50)}(e,a),i&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},Vh.paste=(e,t)=>{let n=t;if(e.composing&&!nd)return;let r=cf?null:n.clipboardData;r&&uf(e,r.getData("text/plain"),r.getData("text/html"),n)?n.preventDefault():function(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus(),setTimeout((()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?uf(e,r.value,null,t):uf(e,r.textContent,r.innerHTML,t)}),50)}(e,n)};class df{constructor(e,t){this.slice=e,this.move=t}}const hf=td?"altKey":"ctrlKey";Bh.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=e.state.selection,o=i.empty?null:e.posAtCoords(Yh(n));if(o&&o.pos>=i.from&&o.pos<=(i instanceof Cu?i.to-1:i.to));else if(r&&r.mightDrag)e.dispatch(e.state.tr.setSelection(Cu.create(e.state.doc,r.mightDrag.pos)));else if(n.target&&1==n.target.nodeType){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&e.dispatch(e.state.tr.setSelection(Cu.create(e.state.doc,t.posBefore)))}let s=e.state.selection.content(),{dom:a,text:l}=$h(e,s);n.dataTransfer.clearData(),n.dataTransfer.setData(cf?"Text":"text/html",a.innerHTML),n.dataTransfer.effectAllowed="copyMove",cf||n.dataTransfer.setData("text/plain",l),e.dragging=new df(s,!n[hf])},Bh.dragend=e=>{let t=e.dragging;window.setTimeout((()=>{e.dragging==t&&(e.dragging=null)}),50)},Vh.dragover=Vh.dragenter=(e,t)=>t.preventDefault(),Vh.drop=(e,t)=>{let n=t,r=e.dragging;if(e.dragging=null,!n.dataTransfer)return;let i=e.posAtCoords(Yh(n));if(!i)return;let o=e.state.doc.resolve(i.pos);if(!o)return;let s=r&&r.slice;s?e.someProp("transformPasted",(e=>{s=e(s)})):s=Ah(e,n.dataTransfer.getData(cf?"Text":"text/plain"),cf?null:n.dataTransfer.getData("text/html"),!1,o);let a=!(!r||n[hf]);if(e.someProp("handleDrop",(t=>t(e,n,s||Vl.empty,a))))return void n.preventDefault();if(!s)return;n.preventDefault();let l=s?function(e,t,n){let r=e.resolve(t);if(!n.content.size)return t;let i=n.content;for(let o=0;o=0;e--){let t=e==r.depth?0:r.pos<=(r.start(e+1)+r.end(e+1))/2?-1:1,n=r.index(e)+(t>0?1:0),s=r.node(e),a=!1;if(1==o)a=s.canReplace(n,n,i);else{let e=s.contentMatchAt(n).findWrapping(i.firstChild.type);a=e&&s.canReplaceWith(n,n,e[0])}if(a)return 0==t?r.pos:t<0?r.before(e+1):r.after(e+1)}return null}(e.state.doc,o.pos,s):o.pos;null==l&&(l=o.pos);let c=e.state.tr;a&&c.deleteSelection();let u=c.mapping.map(l),d=0==s.openStart&&0==s.openEnd&&1==s.content.childCount,h=c.doc;if(d?c.replaceRangeWith(u,u,s.content.firstChild):c.replaceRange(u,u,s),c.doc.eq(h))return;let f=c.doc.resolve(u);if(d&&Cu.isSelectable(s.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(s.content.firstChild))c.setSelection(new Cu(f));else{let t=c.mapping.map(l);c.mapping.maps[c.mapping.maps.length-1].forEach(((e,n,r,i)=>t=i)),c.setSelection(ph(e,f,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta("uiEvent","drop"))},Bh.focus=e=>{e.focused||(e.domObserver.stop(),e.dom.classList.add("ProseMirror-focused"),e.domObserver.start(),e.focused=!0,setTimeout((()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelection())&&ah(e)}),20))},Bh.blur=(e,t)=>{let n=t;e.focused&&(e.domObserver.stop(),e.dom.classList.remove("ProseMirror-focused"),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),e.focused=!1)},Bh.beforeinput=(e,t)=>{if(Gu&&nd&&"deleteContentBackward"==t.inputType){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout((()=>{if(e.input.domChangeCount!=t)return;if(e.dom.blur(),e.focus(),e.someProp("handleKeyDown",(t=>t(e,md(8,"Backspace")))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())}),50)}};for(let os in Vh)Bh[os]=Vh[os];function ff(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}class pf{constructor(e,t){this.toDOM=e,this.spec=t||bf,this.side=this.spec.side||0}map(e,t,n,r){let{pos:i,deleted:o}=e.mapResult(t.from+r,this.side<0?-1:1);return o?null:new vf(i-n,i-n,this)}valid(){return!0}eq(e){return this==e||e instanceof pf&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&ff(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class mf{constructor(e,t){this.attrs=e,this.spec=t||bf}map(e,t,n,r){let i=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,o=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return i>=o?null:new vf(i,o,this)}valid(e,t){return t.from=e&&(!i||i(s.spec))&&n.push(s.copy(s.from+r,s.to+r))}for(let o=0;oe){let s=this.children[o]+1;this.children[o+2].findInner(e-s,t-s,n,r+s,i)}}map(e,t,n){return this==xf||0==e.maps.length?this:this.mapInner(e,t,0,0,n||bf)}mapInner(e,t,n,r,i){let o;for(let s=0;s{for(let s=0;sc+o)continue;let u=a[s]+o;t>=u?a[s+1]=e<=u?-2:-1:n>=i&&(l=r-n-(t-e))&&(a[s]+=l,a[s+1]+=l)}};for(let u=0;u=r.content.size){c=!0;continue}let d=n.map(e[u+1]+o,-1)-i,{index:h,offset:f}=r.content.findIndex(l),p=r.maybeChild(h);if(p&&f==l&&f+p.nodeSize==d){let r=a[u+2].mapInner(n,p,t+1,e[u]+o+1,s);r!=xf?(a[u]=l,a[u+1]=d,a[u+2]=r):(a[u+1]=-2,c=!0)}else c=!0}if(c){let l=function(e,t,n,r,i,o,s){function a(e,t){for(let o=0;o{let s,a=o+n;if(s=Cf(t,e,a)){for(r||(r=this.children.slice());io&&t.to=e){this.children[s]==e&&(n=this.children[s+2]);break}let i=e+1,o=i+t.content.size;for(let s=0;si&&e.type instanceof mf){let t=Math.max(i,e.from)-i,n=Math.min(o,e.to)-i;tn.map(e,t,bf)));return Sf.from(n)}forChild(e,t){if(t.isLeaf)return wf.empty;let n=[];for(let r=0;rn&&o.to{let a=Cf(e,t,s+n);if(a){o=!0;let e=Mf(a,t,n+s+1,r);e!=xf&&i.push(s,s+t.nodeSize,e)}}));let s=kf(o?Of(e):e,-n).sort(_f);for(let a=0;a0;)t++;e.splice(t,0,n)}function $f(e){let t=[];return e.someProp("decorations",(n=>{let r=n(e.state);r&&r!=xf&&t.push(r)})),e.cursorWrapper&&t.push(wf.create(e.state.doc,[e.cursorWrapper.deco])),Sf.from(t)}const Af={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Ef=Ku&&Yu<=11;class Nf{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class Pf{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Nf,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.observer=window.MutationObserver&&new window.MutationObserver((e=>{for(let t=0;t"childList"==e.type&&e.removedNodes.length||"characterData"==e.type&&e.oldValue.length>e.target.nodeValue.length))?this.flushSoon():this.flush()})),Ef&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout((()=>{this.flushingSoon=-1,this.flush()}),20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&this.observer.observe(this.view.dom,Af),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;tthis.flush()),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout((()=>this.suppressingSelectionUpdates=!1),50)}onSelectionChange(){if(mh(this.view)){if(this.suppressingSelectionUpdates)return ah(this.view);if(Ku&&Yu<=11&&!this.view.state.selection.empty){let e=this.view.domSelection();if(e.focusNode&&cd(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelection())}ignoreSelectionChange(e){if(0==e.rangeCount)return!0;let t=e.getRangeAt(0).commonAncestorContainer,n=this.view.docView.nearestDesc(t);return n&&n.ignoreMutation({type:"selection",target:3==t.nodeType?t.parentNode:t})?(this.setCurSelection(),!0):void 0}flush(){if(!this.view.docView||this.flushingSoon>-1)return;let e=this.observer?this.observer.takeRecords():[];this.queue.length&&(e=this.queue.concat(e),this.queue.length=0);let t=this.view.domSelection(),n=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(t)&&mh(this.view)&&!this.ignoreSelectionChange(t),r=-1,i=-1,o=!1,s=[];if(this.view.editable)for(let a=0;a1){let e=s.filter((e=>"BR"==e.nodeName));if(2==e.length){let t=e[0],n=e[1];t.parentNode&&t.parentNode.parentNode==n.parentNode?n.remove():t.remove()}}(r>-1||n)&&(r>-1&&(this.view.docView.markDirty(r,i),function(e){if(If)return;If=!0,"normal"==getComputedStyle(e.dom).whiteSpace&&console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package.")}(this.view)),this.handleDOMChange(r,i,o,s),this.view.docView&&this.view.docView.dirty?this.view.updateState(this.view.state):this.currentSelection.eq(t)||ah(this.view),this.currentSelection.set(t))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if("attributes"==e.type&&(n==this.view.docView||"contenteditable"==e.attributeName||"style"==e.attributeName&&!e.oldValue&&!e.target.getAttribute("style")))return null;if(!n||n.ignoreMutation(e))return null;if("childList"==e.type){for(let n=0;nDate.now()-50?e.input.lastSelectionOrigin:null,n=oh(e,t);if(n&&!e.state.selection.eq(n)){let r=e.state.tr.setSelection(n);"pointer"==t?r.setMeta("pointer",!0):"key"==t&&r.scrollIntoView(),e.dispatch(r)}return}let o=e.state.doc.resolve(t),s=o.sharedDepth(n);t=o.before(s+1),n=e.state.doc.resolve(n).after(s+1);let a=e.state.selection,l=function(e,t,n){let r,{node:i,fromOffset:o,toOffset:s,from:a,to:l}=e.docView.parseRange(t,n),c=e.domSelection(),u=c.anchorNode;if(u&&e.dom.contains(1==u.nodeType?u:u.parentNode)&&(r=[{node:u,offset:c.anchorOffset}],pd(c)||r.push({node:c.focusNode,offset:c.focusOffset})),Gu&&8===e.input.lastKeyCode)for(let g=s;g>o;g--){let e=i.childNodes[g-1],t=e.pmViewDesc;if("BR"==e.nodeName&&!t){s=g;break}if(!t||t.size)break}let d=e.state.doc,h=e.someProp("domParser")||Mc.fromSchema(e.state.schema),f=d.resolve(a),p=null,m=h.parse(i,{topNode:f.parent,topMatch:f.parent.contentMatchAt(f.index()),topOpen:!0,from:o,to:s,preserveWhitespace:"pre"!=f.parent.type.whitespace||"full",findPositions:r,ruleFromNode:Rf,context:f});if(r&&null!=r[0].pos){let e=r[0].pos,t=r[1]&&r[1].pos;null==t&&(t=e),p={anchor:e+a,head:t+a}}return{doc:m,sel:p,from:a,to:l}}(e,t,n);if(Gu&&e.cursorWrapper&&l.sel&&l.sel.anchor==e.cursorWrapper.deco.from){let t=e.cursorWrapper.deco.type.toDOM.nextSibling,n=t&&t.nodeValue?t.nodeValue.length:1;l.sel={anchor:l.sel.anchor+n,head:l.sel.anchor+n}}let c,u,d=e.state.doc,h=d.slice(l.from,l.to);8===e.input.lastKeyCode&&Date.now()-100=s?o-r:0,a=o+(a-s),s=o}else if(a=a?o-r:0,s=o+(s-a),a=o}return{start:o,endA:s,endB:a}}(h.content,l.doc.content,l.from,c,u);if((ed&&e.input.lastIOSEnter>Date.now()-225||nd)&&i.some((e=>"DIV"==e.nodeName||"P"==e.nodeName))&&(!f||f.endA>=f.endB)&&e.someProp("handleKeyDown",(t=>t(e,md(13,"Enter")))))return void(e.input.lastIOSEnter=0);if(!f){if(!(r&&a instanceof Su&&!a.empty&&a.$head.sameParent(a.$anchor))||e.composing||l.sel&&l.sel.anchor!=l.sel.head){if(l.sel){let t=jf(e,e.state.doc,l.sel);t&&!t.eq(e.state.selection)&&e.dispatch(e.state.tr.setSelection(t))}return}f={start:a.from,endA:a.to,endB:a.to}}e.input.domChangeCount++,e.state.selection.frome.state.selection.from&&f.start<=e.state.selection.from+2&&e.state.selection.from>=l.from?f.start=e.state.selection.from:f.endA=e.state.selection.to-2&&e.state.selection.to<=l.to&&(f.endB+=e.state.selection.to-f.endA,f.endA=e.state.selection.to)),Ku&&Yu<=11&&f.endB==f.start+1&&f.endA==f.start&&f.start>l.from&&"  "==l.doc.textBetween(f.start-l.from-1,f.start-l.from+1)&&(f.start--,f.endA--,f.endB--);let p,m=l.doc.resolveNoCache(f.start-l.from),g=l.doc.resolveNoCache(f.endB-l.from),v=d.resolve(f.start),y=m.sameParent(g)&&m.parent.inlineContent&&v.end()>=f.endA;if((ed&&e.input.lastIOSEnter>Date.now()-225&&(!y||i.some((e=>"DIV"==e.nodeName||"P"==e.nodeName)))||!y&&m.post(e,md(13,"Enter")))))return void(e.input.lastIOSEnter=0);if(e.state.selection.anchor>f.start&&function(e,t,n,r,i){if(!r.parent.isTextblock||n-t<=i.pos-r.pos||Ff(r,!0,!1)n||Ff(s,!0,!1)t(e,md(8,"Backspace")))))return void(nd&&Gu&&e.domObserver.suppressSelectionUpdates());Gu&&nd&&f.endB==f.start&&(e.input.lastAndroidDelete=Date.now()),nd&&!y&&m.start()!=g.start()&&0==g.parentOffset&&m.depth==g.depth&&l.sel&&l.sel.anchor==l.sel.head&&l.sel.head==f.endA&&(f.endB-=2,g=l.doc.resolveNoCache(f.endB-l.from),setTimeout((()=>{e.someProp("handleKeyDown",(function(t){return t(e,md(13,"Enter"))}))}),20));let b,w,x,S=f.start,k=f.endA;if(y)if(m.pos==g.pos)Ku&&Yu<=11&&0==m.parentOffset&&(e.domObserver.suppressSelectionUpdates(),setTimeout((()=>ah(e)),20)),b=e.state.tr.delete(S,k),w=d.resolve(f.start).marksAcross(d.resolve(f.endA));else if(f.endA==f.endB&&(x=function(e,t){let n,r,i,o=e.firstChild.marks,s=t.firstChild.marks,a=o,l=s;for(let u=0;ue.mark(r.addToSet(e.marks));else{if(0!=a.length||1!=l.length)return null;r=l[0],n="remove",i=e=>e.mark(r.removeFromSet(e.marks))}let c=[];for(let u=0;un(e,S,k,t))))return;b=e.state.tr.insertText(t,S,k)}if(b||(b=e.state.tr.replace(S,k,l.doc.slice(f.start-l.from,f.endB-l.from))),l.sel){let t=jf(e,b.doc,l.sel);t&&!(Gu&&nd&&e.composing&&t.empty&&(f.start!=f.endB||e.input.lastAndroidDeletet.content.size?null:ph(e,t.resolve(n.anchor),t.resolve(n.head))}function Ff(e,t,n){let r=e.depth,i=t?e.end():e.pos;for(;r>0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}class Lf{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new Wh,this.prevDirectPlugins=[],this.pluginViews=[],this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Hf),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):"function"==typeof e?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=Wf(this),Vf(this),this.nodeViews=qf(this),this.docView=Wd(this.state.doc,Bf(this),$f(this),this.dom,this),this.domObserver=new Pf(this,((e,t,n,r)=>zf(this,e,t,n,r))),this.domObserver.start(),function(e){for(let t in Bh){let n=Bh[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{!Kh(e,t)||Jh(e,t)||!e.editable&&t.type in Vh||n(e,t)})}Qu&&e.dom.addEventListener("input",(()=>null)),Hh(e)}(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&Hh(this),this._props=e,e.plugins&&(e.plugins.forEach(Hf),this.directPlugins=e.plugins),this.updateStateInner(e.state,!0)}setProps(e){let t={};for(let n in this._props)t[n]=this._props[n];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this.state.plugins!=e.plugins)}updateStateInner(e,t){let n=this.state,r=!1,i=!1;if(e.storedMarks&&this.composing&&(af(this),i=!0),this.state=e,t){let e=qf(this);(function(e,t){let n=0,r=0;for(let i in e){if(e[i]!=t[i])return!0;n++}for(let i in t)r++;return n!=r})(e,this.nodeViews)&&(this.nodeViews=e,r=!0),Hh(this)}this.editable=Wf(this),Vf(this);let o=$f(this),s=Bf(this),a=t?"reset":e.scrollToSelection>n.scrollToSelection?"to selection":"preserve",l=r||!this.docView.matchesNode(e.doc,s,o);!l&&e.selection.eq(n.selection)||(i=!0);let c="preserve"==a&&i&&null==this.dom.style.overflowAnchor&&function(e){let t,n,r=e.dom.getBoundingClientRect(),i=Math.max(0,r.top);for(let o=(r.left+r.right)/2,s=i+1;s=i-20){t=r,n=a.top;break}}return{refDOM:t,refTop:n,stack:wd(e.dom)}}(this);if(i){this.domObserver.stop();let t=l&&(Ku||Gu)&&!this.composing&&!n.selection.empty&&!e.selection.empty&&function(e,t){let n=Math.min(e.$anchor.sharedDepth(e.head),t.$anchor.sharedDepth(t.head));return e.$anchor.start(n)!=t.$anchor.start(n)}(n.selection,e.selection);if(l){let n=Gu?this.trackWrites=this.domSelection().focusNode:null;!r&&this.docView.update(e.doc,s,o,this)||(this.docView.updateOuterDeco([]),this.docView.destroy(),this.docView=Wd(e.doc,s,o,this.dom,this)),n&&!this.trackWrites&&(t=!0)}t||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelection())&&function(e){let t=e.docView.domFromPos(e.state.selection.anchor,0),n=e.domSelection();return cd(t.node,t.offset,n.anchorNode,n.anchorOffset)}(this))?ah(this,t):(hh(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}if(this.updatePluginViews(n),"reset"==a)this.dom.scrollTop=0;else if("to selection"==a){let t=this.domSelection().focusNode;if(this.someProp("handleScrollToSelection",(e=>e(this))));else if(e.selection instanceof Cu){let n=this.docView.domAfterPos(e.selection.from);1==n.nodeType&&bd(this,n.getBoundingClientRect(),t)}else bd(this,this.coordsAtPos(e.selection.head,1),t)}else c&&function({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;xd(n,0==r?0:r-t)}(c)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(e&&e.plugins==this.state.plugins&&this.directPlugins==this.prevDirectPlugins)for(let t=0;tt.ownerDocument.getSelection()),this._root=t;return e||document}posAtCoords(e){return Md(this,e)}coordsAtPos(e,t=1){return Td(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(null==r)throw new RangeError("DOM position not inside the editor");return r}endOfTextblock(e,t){return zd(this,t||this.state,e)}destroy(){this.docView&&(!function(e){e.domObserver.stop();for(let t in e.input.eventHandlers)e.dom.removeEventListener(t,e.input.eventHandlers[t]);clearTimeout(e.input.composingTimeout),clearTimeout(e.input.lastIOSEnterFallbackTimeout)}(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],$f(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null)}get isDestroyed(){return null==this.docView}dispatchEvent(e){return function(e,t){Jh(e,t)||!Bh[t.type]||!e.editable&&t.type in Vh||Bh[t.type](e,t)}(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelection(){return this.root.getSelection()}}function Bf(e){let t=Object.create(null);return t.class="ProseMirror",t.contenteditable=String(e.editable),t.translate="no",e.someProp("attributes",(n=>{if("function"==typeof n&&(n=n(e.state)),n)for(let e in n)"class"==e&&(t.class+=" "+n[e]),"style"==e?t.style=(t.style?t.style+";":"")+n[e]:t[e]||"contenteditable"==e||"nodeName"==e||(t[e]=String(n[e]))})),[vf.node(0,e.state.doc.content.size,t)]}function Vf(e){if(e.markCursor){let t=document.createElement("img");t.className="ProseMirror-separator",t.setAttribute("mark-placeholder","true"),t.setAttribute("alt",""),e.cursorWrapper={dom:t,deco:vf.widget(e.state.selection.head,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function Wf(e){return!e.someProp("editable",(t=>!1===t(e.state)))}function qf(e){let t=Object.create(null);return e.someProp("nodeViews",(e=>{for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])})),t}function Hf(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}for(var Jf={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",229:"q"},Kf={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"',229:"Q"},Yf="undefined"!=typeof navigator&&/Chrome\/(\d+)/.exec(navigator.userAgent),Uf="undefined"!=typeof navigator&&/Apple Computer/.test(navigator.vendor),Xf="undefined"!=typeof navigator&&/Gecko\/\d+/.test(navigator.userAgent),Gf="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),Zf="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Qf=Yf&&(Gf||+Yf[1]<57)||Xf&&Gf,ep=0;ep<10;ep++)Jf[48+ep]=Jf[96+ep]=String(ep);for(ep=1;ep<=24;ep++)Jf[ep+111]="F"+ep;for(ep=65;ep<=90;ep++)Jf[ep]=String.fromCharCode(ep+32),Kf[ep]=String.fromCharCode(ep);for(var tp in Jf)Kf.hasOwnProperty(tp)||(Kf[tp]=Jf[tp]);const np="undefined"!=typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform);function rp(e){let t,n,r,i,o=e.split(/-(?!$)/),s=o[o.length-1];"Space"==s&&(s=" ");for(let a=0;a127)&&(r=Jf[n.keyCode])&&r!=i){let i=t[ip(r,n,!0)];if(i&&i(e.state,e.dispatch,e))return!0}else if(o&&n.shiftKey){let r=t[ip(i,n,!0)];if(r&&r(e.state,e.dispatch,e))return!0}return!1}}const ap=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function lp(e,t,n=!1){for(let r=e;r;r="start"==t?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&1!=r.childCount)return!1}return!1}function cp(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function up(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){let n=e.node(t);if(e.index(t)+1{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),o=n.indexAfter(-1),s=dp(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(t){let r=n.after(),i=e.tr.replaceWith(r,r,s.createAndFill());i.setSelection(yu.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0};function fp(e,t,n){let r,i,o=t.nodeBefore,s=t.nodeAfter;if(o.type.spec.isolating||s.type.spec.isolating)return!1;if(function(e,t,n){let r=t.nodeBefore,i=t.nodeAfter,o=t.index();return!(!(r&&i&&r.type.compatibleContent(i.type))||(!r.content.size&&t.parent.canReplace(o-1,o)?(n&&n(e.tr.delete(t.pos-r.nodeSize,t.pos).scrollIntoView()),0):!t.parent.canReplace(o,o+1)||!i.isTextblock&&!iu(e.doc,t.pos)||(n&&n(e.tr.clearIncompatible(t.pos,r.type,r.contentMatchAt(r.childCount)).join(t.pos).scrollIntoView()),0)))}(e,t,n))return!0;let a=t.parent.canReplace(t.index(),t.index()+1);if(a&&(r=(i=o.contentMatchAt(o.childCount)).findWrapping(s.type))&&i.matchType(r[0]||s.type).validEnd){if(n){let i=t.pos+s.nodeSize,a=Rl.empty;for(let e=r.length-1;e>=0;e--)a=Rl.from(r[e].create(null,a));a=Rl.from(o.copy(a));let l=e.tr.step(new Gc(t.pos-1,i,t.pos,i,new Vl(a,1,0),r.length,!0)),c=i+2*r.length;iu(l.doc,c)&&l.join(c),n(l.scrollIntoView())}return!0}let l=yu.findFrom(t,1),c=l&&l.$from.blockRange(l.$to),u=c&&eu(c);if(null!=u&&u>=t.depth)return n&&n(e.tr.lift(c,u).scrollIntoView()),!0;if(a&&lp(s,"start",!0)&&lp(o,"end")){let r=o,i=[];for(;i.push(r),!r.isTextblock;)r=r.lastChild;let a=s,l=1;for(;!a.isTextblock;a=a.firstChild)l++;if(r.canReplace(r.childCount,r.childCount,a.content)){if(n){let r=Rl.empty;for(let e=i.length-1;e>=0;e--)r=Rl.from(i[e].copy(r));n(e.tr.step(new Gc(t.pos-i.length,t.pos+s.nodeSize,t.pos+l,t.pos+s.nodeSize-l,new Vl(r,i.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function pp(e){return function(t,n){let r=t.selection,i=e<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return!!i.node(o).isTextblock&&(n&&n(t.tr.setSelection(Su.create(t.doc,e<0?i.start(o):i.end(o)))),!0)}}const mp=pp(-1),gp=pp(1);function vp(e,t=null){return function(n,r){let{from:i,to:o}=n.selection,s=!1;return n.doc.nodesBetween(i,o,((r,i)=>{if(s)return!1;if(r.isTextblock&&!r.hasMarkup(e,t))if(r.type==e)s=!0;else{let t=n.doc.resolve(i),r=t.index();s=t.parent.canReplaceWith(r,r+1,e)}})),!!s&&(r&&r(n.tr.setBlockType(i,o,e,t).scrollIntoView()),!0)}}function yp(e,t=null){return function(n,r){let{empty:i,$cursor:o,ranges:s}=n.selection;if(i&&!o||!function(e,t,n){for(let r=0;r{if(s)return!1;s=e.inlineContent&&e.type.allowsMarkType(n)})),s)return!0}return!1}(n.doc,s,e))return!1;if(r)if(o)e.isInSet(n.storedMarks||o.marks())?r(n.tr.removeStoredMark(e)):r(n.tr.addStoredMark(e.create(t)));else{let i=!1,o=n.tr;for(let t=0;!i&&t{let{$cursor:r}=e.selection;if(!r||(n?!n.endOfTextblock("backward",e):r.parentOffset>0))return!1;let i=cp(r);if(!i){let n=r.blockRange(),i=n&&eu(n);return null!=i&&(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let o=i.nodeBefore;if(!o.type.spec.isolating&&fp(e,i,t))return!0;if(0==r.parent.content.size&&(lp(o,"end")||Cu.isSelectable(o))){let n=ou(e.doc,r.before(),r.after(),Vl.empty);if(n&&n.slice.size{let{$head:r,empty:i}=e.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",e):r.parentOffset>0)return!1;o=cp(r)}let s=o&&o.nodeBefore;return!(!s||!Cu.isSelectable(s))&&(t&&t(e.tr.setSelection(Cu.create(e.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)})),xp=bp(ap,((e,t,n)=>{let{$cursor:r}=e.selection;if(!r||(n?!n.endOfTextblock("forward",e):r.parentOffset{let{$head:r,empty:i}=e.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",e):r.parentOffset{let{$head:n,$anchor:r}=e.selection;return!(!n.parent.type.spec.code||!n.sameParent(r))&&(t&&t(e.tr.insertText("\n").scrollIntoView()),!0)}),((e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof Mu||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=dp(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(t){let n=(!r.parentOffset&&i.index(){let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(ru(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),i=r&&eu(r);return null!=i&&(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)}),((e,t)=>{let{$from:n,$to:r}=e.selection;if(e.selection instanceof Cu&&e.selection.node.isBlock)return!(!n.parentOffset||!ru(e.doc,n.pos))&&(t&&t(e.tr.split(n.pos).scrollIntoView()),!0);if(!n.parent.isBlock)return!1;if(t){let i=r.parentOffset==r.parent.content.size,o=e.tr;(e.selection instanceof Su||e.selection instanceof Mu)&&o.deleteSelection();let s=0==n.depth?null:dp(n.node(-1).contentMatchAt(n.indexAfter(-1))),a=i&&s?[{type:s}]:void 0,l=ru(o.doc,o.mapping.map(n.pos),1,a);if(a||l||!ru(o.doc,o.mapping.map(n.pos),1,s?[{type:s}]:void 0)||(s&&(a=[{type:s}]),l=!0),l&&(o.split(o.mapping.map(n.pos),1,a),!i&&!n.parentOffset&&n.parent.type!=s)){let e=o.mapping.map(n.before()),t=o.doc.resolve(e);s&&n.node(-1).canReplaceWith(t.index(),t.index()+1,s)&&o.setNodeMarkup(o.mapping.map(n.before()),s)}t(o.scrollIntoView())}return!0})),"Mod-Enter":hp,Backspace:wp,"Mod-Backspace":wp,"Shift-Backspace":wp,Delete:xp,"Mod-Delete":xp,"Mod-a":(e,t)=>(t&&t(e.tr.setSelection(new Mu(e.doc))),!0)},kp={"Ctrl-h":Sp.Backspace,"Alt-Backspace":Sp["Mod-Backspace"],"Ctrl-d":Sp.Delete,"Ctrl-Alt-Backspace":Sp["Mod-Delete"],"Alt-Delete":Sp["Mod-Delete"],"Alt-d":Sp["Mod-Delete"],"Ctrl-a":mp,"Ctrl-e":gp};for(let os in Sp)kp[os]=Sp[os];const Cp=("undefined"!=typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!("undefined"==typeof os||!os.platform)&&"darwin"==os.platform())?kp:Sp;class Op{constructor(e,t){var n;this.match=e,this.match=e,this.handler="string"==typeof t?(n=t,function(e,t,r,i){let o=n;if(t[1]){let e=t[0].lastIndexOf(t[1]);o+=t[0].slice(e+t[1].length);let n=(r+=e)-i;n>0&&(o=t[0].slice(e-n,e)+o,r=i)}return e.tr.insertText(o,r,i)}):t}}function Mp({rules:e}){let t=new zu({state:{init:()=>null,apply(e,t){let n=e.getMeta(this);return n||(e.selectionSet||e.docChanged?null:t)}},props:{handleTextInput:(n,r,i,o)=>_p(n,r,i,o,e,t),handleDOMEvents:{compositionend:n=>{setTimeout((()=>{let{$cursor:r}=n.state.selection;r&&_p(n,r.pos,r.pos,"",e,t)}))}}},isInputRules:!0});return t}function _p(e,t,n,r,i,o){if(e.composing)return!1;let s=e.state,a=s.doc.resolve(t);if(a.parent.type.spec.code)return!1;let l=a.parent.textBetween(Math.max(0,a.parentOffset-500),a.parentOffset,null,"")+r;for(let c=0;c{let n=e.plugins;for(let r=0;r=0;e--)n.step(r.steps[e].invert(r.docs[e]));if(i.text){let t=n.doc.resolve(i.from).marks();n.replaceWith(i.from,i.to,e.schema.text(i.text,t))}else n.delete(i.from,i.to);t(n)}return!0}}return!1};function Tp(e,t,n=null,r){return new Op(e,((e,i,o,s)=>{let a=n instanceof Function?n(i):n,l=e.tr.delete(o,s),c=l.doc.resolve(o).blockRange(),u=c&&tu(c,t,a);if(!u)return null;l.wrap(c,u);let d=l.doc.resolve(o-1).nodeBefore;return d&&d.type==t&&iu(l.doc,o-1)&&(!r||r(i,d))&&l.join(o-1),l}))}function $p(e,t,n=null){return new Op(e,((e,r,i,o)=>{let s=e.doc.resolve(i),a=n instanceof Function?n(r):n;return s.node(-1).canReplaceWith(s.index(-1),s.indexAfter(-1),t)?e.tr.delete(i,o).setBlockType(i,i,t,a):null}))}new Op(/--$/,"—"),new Op(/\.\.\.$/,"…"),new Op(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"“"),new Op(/"$/,"”"),new Op(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"‘"),new Op(/'$/,"’");const Ap=["ol",0],Ep=["ul",0],Np=["li",0],Pp={attrs:{order:{default:1}},parseDOM:[{tag:"ol",getAttrs:e=>({order:e.hasAttribute("start")?+e.getAttribute("start"):1})}],toDOM:e=>1==e.attrs.order?Ap:["ol",{start:e.attrs.order},0]},Ip={parseDOM:[{tag:"ul"}],toDOM:()=>Ep},Rp={parseDOM:[{tag:"li"}],toDOM:()=>Np,defining:!0};function zp(e,t){let n={};for(let r in e)n[r]=e[r];for(let r in t)n[r]=t[r];return n}function jp(e,t,n){return e.append({ordered_list:zp(Pp,{content:"list_item+",group:n}),bullet_list:zp(Ip,{content:"list_item+",group:n}),list_item:zp(Rp,{content:t})})}function Fp(e,t=null){return function(n,r){let{$from:i,$to:o}=n.selection,s=i.blockRange(o),a=!1,l=s;if(!s)return!1;if(s.depth>=2&&i.node(s.depth-1).type.compatibleContent(e)&&0==s.startIndex){if(0==i.index(s.depth-1))return!1;let e=n.doc.resolve(s.start-2);l=new ic(e,e,s.depth),s.endIndex=0;u--)o=Rl.from(n[u].type.create(n[u].attrs,o));e.step(new Gc(t.start-(r?2:0),t.end,t.start,t.end,new Vl(o,0,0),n.length,!0));let s=0;for(let u=0;u=r.depth-3;e--)i=Rl.from(r.node(e).copy(i));let s=r.indexAfter(-1){if(c>-1)return!1;e.isTextblock&&0==e.content.size&&(c=t+1)})),c>-1&&l.setSelection(yu.near(l.doc.resolve(c))),n(l.scrollIntoView())}return!0}let a=i.pos==r.end()?s.contentMatchAt(0).defaultType:null,l=t.tr.delete(r.pos,i.pos),c=a?[null,{type:a}]:void 0;return!!ru(l.doc,r.pos,2,c)&&(n&&n(l.split(r.pos,2,c).scrollIntoView()),!0)}}function Bp(e){return function(t,n){let{$from:r,$to:i}=t.selection,o=r.blockRange(i,(t=>t.childCount>0&&t.firstChild.type==e));return!!o&&(!n||(r.node(o.depth-1).type==e?function(e,t,n,r){let i=e.tr,o=r.end,s=r.$to.end(r.depth);om;p--)f-=i.child(p).nodeSize,r.delete(f-1,f+1);let o=r.doc.resolve(n.start),s=o.nodeAfter;if(r.mapping.map(n.end)!=n.start+o.nodeAfter.nodeSize)return!1;let a=0==n.startIndex,l=n.endIndex==i.childCount,c=o.node(-1),u=o.index(-1);if(!c.canReplace(u+(a?0:1),u+1,s.content.append(l?Rl.empty:Rl.from(i))))return!1;let d=o.pos,h=d+s.nodeSize;return r.step(new Gc(d-(a?1:0),h+(l?1:0),d+1,h-1,new Vl((a?Rl.empty:Rl.from(i.copy(Rl.empty))).append(l?Rl.empty:Rl.from(i.copy(Rl.empty))),a?0:1,l?0:1),a?0:1)),t(r.scrollIntoView()),!0}(t,n,o)))}}function Vp(e){return function(t,n){let{$from:r,$to:i}=t.selection,o=r.blockRange(i,(t=>t.childCount>0&&t.firstChild.type==e));if(!o)return!1;let s=o.startIndex;if(0==s)return!1;let a=o.parent,l=a.child(s-1);if(l.type!=e)return!1;if(n){let r=l.lastChild&&l.lastChild.type==a.type,i=Rl.from(r?e.create():null),s=new Vl(Rl.from(e.create(null,Rl.from(a.type.create(null,i)))),r?3:1,0),c=o.start,u=o.end;n(t.tr.step(new Gc(c-(r?3:1),u,c,u,s,1,!0)).scrollIntoView())}return!0}}var Wp=function(){};Wp.prototype.append=function(e){return e.length?(e=Wp.from(e),!this.length&&e||e.length<200&&this.leafAppend(e)||this.length<200&&e.leafPrepend(this)||this.appendInner(e)):this},Wp.prototype.prepend=function(e){return e.length?Wp.from(e).append(this):this},Wp.prototype.appendInner=function(e){return new Hp(this,e)},Wp.prototype.slice=function(e,t){return void 0===e&&(e=0),void 0===t&&(t=this.length),e>=t?Wp.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},Wp.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},Wp.prototype.forEach=function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},Wp.prototype.map=function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=this.length);var r=[];return this.forEach((function(t,n){return r.push(e(t,n))}),t,n),r},Wp.from=function(e){return e instanceof Wp?e:e&&e.length?new qp(e):Wp.empty};var qp=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return 0==e&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var i=t;i=n;i--)if(!1===e(this.values[i],r+i))return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=200)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=200)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(Wp);Wp.empty=new qp([]);var Hp=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return ei&&!1===this.right.forEachInner(e,Math.max(t-i,0),Math.min(this.length,n)-i,r+i))&&void 0)},t.prototype.forEachInvertedInner=function(e,t,n,r){var i=this.left.length;return!(t>i&&!1===this.right.forEachInvertedInner(e,t-i,Math.max(n,i)-i,r+i))&&(!(n=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(Wp),Jp=Wp;class Kp{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(0==this.eventCount)return null;let n,r,i=this.items.length;for(;;i--){if(this.items.get(i-1).selection){--i;break}}t&&(n=this.remapping(i,this.items.length),r=n.maps.length);let o,s,a=e.tr,l=[],c=[];return this.items.forEach(((e,t)=>{if(!e.step)return n||(n=this.remapping(i,t+1),r=n.maps.length),r--,void c.push(e);if(n){c.push(new Yp(e.map));let t,i=e.step.map(n.slice(r));i&&a.maybeStep(i).doc&&(t=a.mapping.maps[a.mapping.maps.length-1],l.push(new Yp(t,void 0,void 0,l.length+c.length))),r--,t&&n.appendMap(t,r)}else a.maybeStep(e.step);return e.selection?(o=n?e.selection.map(n.slice(r)):e.selection,s=new Kp(this.items.slice(0,i).append(c.reverse().concat(l)),this.eventCount-1),!1):void 0}),this.items.length,0),{remaining:s,transform:a,selection:o}}addTransform(e,t,n,r){let i=[],o=this.eventCount,s=this.items,a=!r&&s.length?s.get(s.length-1):null;for(let c=0;cXp&&(s=function(e,t){let n;return e.forEach(((e,r)=>{if(e.selection&&0==t--)return n=r,!1})),e.slice(n)}(s,l),o-=l),new Kp(s.append(i),o)}remapping(e,t){let n=new Wc;return this.items.forEach(((t,r)=>{let i=null!=t.mirrorOffset&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,i)}),e,t),n}addMaps(e){return 0==this.eventCount?this:new Kp(this.items.append(e.map((e=>new Yp(e)))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],r=Math.max(0,this.items.length-t),i=e.mapping,o=e.steps.length,s=this.eventCount;this.items.forEach((e=>{e.selection&&s--}),r);let a=t;this.items.forEach((t=>{let r=i.getMirror(--a);if(null==r)return;o=Math.min(o,r);let l=i.maps[r];if(t.step){let o=e.steps[r].invert(e.docs[r]),c=t.selection&&t.selection.map(i.slice(a+1,r));c&&s++,n.push(new Yp(l,o,c))}else n.push(new Yp(l))}),r);let l=[];for(let d=t;d500&&(u=u.compress(this.items.length-n.length)),u}emptyItemCount(){let e=0;return this.items.forEach((t=>{t.step||e++})),e}compress(e=this.items.length){let t=this.remapping(0,e),n=t.maps.length,r=[],i=0;return this.items.forEach(((o,s)=>{if(s>=e)r.push(o),o.selection&&i++;else if(o.step){let e=o.step.map(t.slice(n)),s=e&&e.getMap();if(n--,s&&t.appendMap(s,n),e){let a=o.selection&&o.selection.map(t.slice(n));a&&i++;let l,c=new Yp(s.invert(),e,a),u=r.length-1;(l=r.length&&r[u].merge(c))?r[u]=l:r.push(c)}}else o.map&&n--}),this.items.length,0),new Kp(Jp.from(r.reverse()),i)}}Kp.empty=new Kp(Jp.empty,0);class Yp{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new Yp(t.getMap().invert(),t,this.selection)}}}class Up{constructor(e,t,n,r){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r}}const Xp=20;function Gp(e){let t=[];return e.forEach(((e,n,r,i)=>t.push(r,i))),t}function Zp(e,t){if(!e)return null;let n=[];for(let r=0;rnew Up(Kp.empty,Kp.empty,null,0),apply:(t,n,r)=>function(e,t,n,r){let i,o=n.getMeta(rm);if(o)return o.historyState;n.getMeta(im)&&(e=new Up(e.done,e.undone,null,0));let s=n.getMeta("appendedTransaction");if(0==n.steps.length)return e;if(s&&s.getMeta(rm))return s.getMeta(rm).redo?new Up(e.done.addTransform(n,void 0,r,nm(t)),e.undone,Gp(n.mapping.maps[n.steps.length-1]),e.prevTime):new Up(e.done,e.undone.addTransform(n,void 0,r,nm(t)),null,e.prevTime);if(!1===n.getMeta("addToHistory")||s&&!1===s.getMeta("addToHistory"))return(i=n.getMeta("rebased"))?new Up(e.done.rebased(n,i),e.undone.rebased(n,i),Zp(e.prevRanges,n.mapping),e.prevTime):new Up(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),Zp(e.prevRanges,n.mapping),e.prevTime);{let i=0==e.prevTime||!s&&(e.prevTime<(n.time||0)-r.newGroupDelay||!function(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach(((e,r)=>{for(let i=0;i=t[i]&&(n=!0)})),n}(n,e.prevRanges)),o=s?Zp(e.prevRanges,n.mapping):Gp(n.mapping.maps[n.steps.length-1]);return new Up(e.done.addTransform(n,i?t.selection.getBookmark():void 0,r,nm(t)),Kp.empty,o,n.time)}}(n,r,t,e)},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,r="historyUndo"==n?sm:"historyRedo"==n?am:null;return!!r&&(t.preventDefault(),r(e.state,e.dispatch))}}}})}const sm=(e,t)=>{let n=rm.getState(e);return!(!n||0==n.done.eventCount)&&(t&&Qp(n,e,t,!1),!0)},am=(e,t)=>{let n=rm.getState(e);return!(!n||0==n.undone.eventCount)&&(t&&Qp(n,e,t,!0),!0)};function lm(e){let t=rm.getState(e);return t?t.done.eventCount:0}function cm(e){let t=rm.getState(e);return t?t.undone.eventCount:0}var um={},dm={},hm={},fm={};Object.defineProperty(fm,"__esModule",{value:!0}),fm.default=void 0;var pm=xl.withParams;fm.default=pm,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.req=e.regex=e.ref=e.len=void 0,Object.defineProperty(e,"withParams",{enumerable:!0,get:function(){return n.default}});var t,n=(t=fm)&&t.__esModule?t:{default:t};function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var i=function(e){if(Array.isArray(e))return!!e.length;if(null==e)return!1;if(!1===e)return!0;if(e instanceof Date)return!isNaN(e.getTime());if("object"===r(e)){for(var t in e)return!0;return!1}return!!String(e).length};e.req=i;e.len=function(e){return Array.isArray(e)?e.length:"object"===r(e)?Object.keys(e).length:String(e).length};e.ref=function(e,t,n){return"function"==typeof e?e.call(t,n):n[e]};e.regex=function(e,t){return(0,n.default)({type:e},(function(e){return!i(e)||t.test(e)}))}}(hm),Object.defineProperty(dm,"__esModule",{value:!0}),dm.default=void 0;var mm=(0,hm.regex)("alpha",/^[a-zA-Z]*$/);dm.default=mm;var gm={};Object.defineProperty(gm,"__esModule",{value:!0}),gm.default=void 0;var vm=(0,hm.regex)("alphaNum",/^[a-zA-Z0-9]*$/);gm.default=vm;var ym={};Object.defineProperty(ym,"__esModule",{value:!0}),ym.default=void 0;var bm=(0,hm.regex)("numeric",/^[0-9]*$/);ym.default=bm;var wm={};Object.defineProperty(wm,"__esModule",{value:!0}),wm.default=void 0;var xm=hm;wm.default=function(e,t){return(0,xm.withParams)({type:"between",min:e,max:t},(function(n){return!(0,xm.req)(n)||(!/\s/.test(n)||n instanceof Date)&&+e<=+n&&+t>=+n}))};var Sm={};Object.defineProperty(Sm,"__esModule",{value:!0}),Sm.default=void 0;var km=(0,hm.regex)("email",/^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i);Sm.default=km;var Cm={};Object.defineProperty(Cm,"__esModule",{value:!0}),Cm.default=void 0;var Om=hm,Mm=(0,Om.withParams)({type:"ipAddress"},(function(e){if(!(0,Om.req)(e))return!0;if("string"!=typeof e)return!1;var t=e.split(".");return 4===t.length&&t.every(_m)}));Cm.default=Mm;var _m=function(e){if(e.length>3||0===e.length)return!1;if("0"===e[0]&&"0"!==e)return!1;if(!e.match(/^\d+$/))return!1;var t=0|+e;return t>=0&&t<=255},Dm={};Object.defineProperty(Dm,"__esModule",{value:!0}),Dm.default=void 0;var Tm=hm;Dm.default=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:":";return(0,Tm.withParams)({type:"macAddress"},(function(t){if(!(0,Tm.req)(t))return!0;if("string"!=typeof t)return!1;var n="string"==typeof e&&""!==e?t.split(e):12===t.length||16===t.length?t.match(/.{2}/g):null;return null!==n&&(6===n.length||8===n.length)&&n.every($m)}))};var $m=function(e){return e.toLowerCase().match(/^[0-9a-f]{2}$/)},Am={};Object.defineProperty(Am,"__esModule",{value:!0}),Am.default=void 0;var Em=hm;Am.default=function(e){return(0,Em.withParams)({type:"maxLength",max:e},(function(t){return!(0,Em.req)(t)||(0,Em.len)(t)<=e}))};var Nm={};Object.defineProperty(Nm,"__esModule",{value:!0}),Nm.default=void 0;var Pm=hm;Nm.default=function(e){return(0,Pm.withParams)({type:"minLength",min:e},(function(t){return!(0,Pm.req)(t)||(0,Pm.len)(t)>=e}))};var Im={};Object.defineProperty(Im,"__esModule",{value:!0}),Im.default=void 0;var Rm=hm,zm=(0,Rm.withParams)({type:"required"},(function(e){return(0,Rm.req)("string"==typeof e?e.trim():e)}));Im.default=zm;var jm={};Object.defineProperty(jm,"__esModule",{value:!0}),jm.default=void 0;var Fm=hm;jm.default=function(e){return(0,Fm.withParams)({type:"requiredIf",prop:e},(function(t,n){return!(0,Fm.ref)(e,this,n)||(0,Fm.req)(t)}))};var Lm={};Object.defineProperty(Lm,"__esModule",{value:!0}),Lm.default=void 0;var Bm=hm;Lm.default=function(e){return(0,Bm.withParams)({type:"requiredUnless",prop:e},(function(t,n){return!!(0,Bm.ref)(e,this,n)||(0,Bm.req)(t)}))};var Vm={};Object.defineProperty(Vm,"__esModule",{value:!0}),Vm.default=void 0;var Wm=hm;Vm.default=function(e){return(0,Wm.withParams)({type:"sameAs",eq:e},(function(t,n){return t===(0,Wm.ref)(e,this,n)}))};var qm={};Object.defineProperty(qm,"__esModule",{value:!0}),qm.default=void 0;var Hm=(0,hm.regex)("url",/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i);qm.default=Hm;var Jm={};Object.defineProperty(Jm,"__esModule",{value:!0}),Jm.default=void 0;var Km=hm;Jm.default=function(){for(var e=arguments.length,t=new Array(e),n=0;n0&&t.reduce((function(t,n){return t||n.apply(e,r)}),!1)}))};var Ym={};Object.defineProperty(Ym,"__esModule",{value:!0}),Ym.default=void 0;var Um=hm;Ym.default=function(){for(var e=arguments.length,t=new Array(e),n=0;n0&&t.reduce((function(t,n){return t&&n.apply(e,r)}),!0)}))};var Xm={};Object.defineProperty(Xm,"__esModule",{value:!0}),Xm.default=void 0;var Gm=hm;Xm.default=function(e){return(0,Gm.withParams)({type:"not"},(function(t,n){return!(0,Gm.req)(t)||!e.call(this,t,n)}))};var Zm={};Object.defineProperty(Zm,"__esModule",{value:!0}),Zm.default=void 0;var Qm=hm;Zm.default=function(e){return(0,Qm.withParams)({type:"minValue",min:e},(function(t){return!(0,Qm.req)(t)||(!/\s/.test(t)||t instanceof Date)&&+t>=+e}))};var eg={};Object.defineProperty(eg,"__esModule",{value:!0}),eg.default=void 0;var tg=hm;eg.default=function(e){return(0,tg.withParams)({type:"maxValue",max:e},(function(t){return!(0,tg.req)(t)||(!/\s/.test(t)||t instanceof Date)&&+t<=+e}))};var ng={};Object.defineProperty(ng,"__esModule",{value:!0}),ng.default=void 0;var rg=(0,hm.regex)("integer",/(^[0-9]*$)|(^-[0-9]+$)/);ng.default=rg;var ig={};Object.defineProperty(ig,"__esModule",{value:!0}),ig.default=void 0;var og=(0,hm.regex)("decimal",/^[-]?\d*(\.\d+)?$/); +function(t){if(Number(t.version.split(".")[0])>=2)t.mixin({beforeCreate:n});else{var e=t.prototype._init;t.prototype._init=function(t){void 0===t&&(t={}),t.init=t.init?[n].concat(t.init):n,e.call(this,t)}}function n(){var t=this.$options;t.store?this.$store="function"==typeof t.store?t.store():t.store:t.parent&&t.parent.$store&&(this.$store=t.parent.$store)}}(ja=t)}Va.state.get=function(){return this._vm._data.$$state},Va.state.set=function(t){},Ba.prototype.commit=function(t,e,n){var r=this,o=Ya(t,e,n),i=o.type,s=o.payload,a={type:i,payload:s},l=this._mutations[i];l&&(this._withCommit((function(){l.forEach((function(t){t(s)}))})),this._subscribers.slice().forEach((function(t){return t(a,r.state)})))},Ba.prototype.dispatch=function(t,e){var n=this,r=Ya(t,e),o=r.type,i=r.payload,s={type:o,payload:i},a=this._actions[o];if(a){try{this._actionSubscribers.slice().filter((function(t){return t.before})).forEach((function(t){return t.before(s,n.state)}))}catch(jy){}var l=a.length>1?Promise.all(a.map((function(t){return t(i)}))):a[0](i);return new Promise((function(t,e){l.then((function(e){try{n._actionSubscribers.filter((function(t){return t.after})).forEach((function(t){return t.after(s,n.state)}))}catch(jy){}t(e)}),(function(t){try{n._actionSubscribers.filter((function(t){return t.error})).forEach((function(e){return e.error(s,n.state,t)}))}catch(jy){}e(t)}))}))}},Ba.prototype.subscribe=function(t,e){return Wa(t,this._subscribers,e)},Ba.prototype.subscribeAction=function(t,e){return Wa("function"==typeof t?{before:t}:t,this._actionSubscribers,e)},Ba.prototype.watch=function(t,e,n){var r=this;return this._watcherVM.$watch((function(){return t(r.state,r.getters)}),e,n)},Ba.prototype.replaceState=function(t){var e=this;this._withCommit((function(){e._vm._data.$$state=t}))},Ba.prototype.registerModule=function(t,e,n){void 0===n&&(n={}),"string"==typeof t&&(t=[t]),this._modules.register(t,e),Ja(this,this.state,t,this._modules.get(t),n.preserveState),Ha(this,this.state)},Ba.prototype.unregisterModule=function(t){var e=this;"string"==typeof t&&(t=[t]),this._modules.unregister(t),this._withCommit((function(){var n=Ka(e.state,t.slice(0,-1));ja.delete(n,t[t.length-1])})),qa(this)},Ba.prototype.hasModule=function(t){return"string"==typeof t&&(t=[t]),this._modules.isRegistered(t)},Ba.prototype.hotUpdate=function(t){this._modules.update(t),qa(this,!0)},Ba.prototype._withCommit=function(t){var e=this._committing;this._committing=!0,t(),this._committing=e},Object.defineProperties(Ba.prototype,Va);var Ga=el((function(t,e){var n={};return tl(e).forEach((function(e){var r=e.key,o=e.val;n[r]=function(){var e=this.$store.state,n=this.$store.getters;if(t){var r=nl(this.$store,"mapState",t);if(!r)return;e=r.context.state,n=r.context.getters}return"function"==typeof o?o.call(this,e,n):e[o]},n[r].vuex=!0})),n})),Xa=el((function(t,e){var n={};return tl(e).forEach((function(e){var r=e.key,o=e.val;n[r]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var r=this.$store.commit;if(t){var i=nl(this.$store,"mapMutations",t);if(!i)return;r=i.context.commit}return"function"==typeof o?o.apply(this,[r].concat(e)):r.apply(this.$store,[o].concat(e))}})),n})),Za=el((function(t,e){var n={};return tl(e).forEach((function(e){var r=e.key,o=e.val;o=t+o,n[r]=function(){if(!t||nl(this.$store,"mapGetters",t))return this.$store.getters[o]},n[r].vuex=!0})),n})),Qa=el((function(t,e){var n={};return tl(e).forEach((function(e){var r=e.key,o=e.val;n[r]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var r=this.$store.dispatch;if(t){var i=nl(this.$store,"mapActions",t);if(!i)return;r=i.context.dispatch}return"function"==typeof o?o.apply(this,[r].concat(e)):r.apply(this.$store,[o].concat(e))}})),n}));function tl(t){return function(t){return Array.isArray(t)||Ia(t)}(t)?Array.isArray(t)?t.map((function(t){return{key:t,val:t}})):Object.keys(t).map((function(e){return{key:e,val:t[e]}})):[]}function el(t){return function(e,n){return"string"!=typeof e?(n=e,e=""):"/"!==e.charAt(e.length-1)&&(e+="/"),t(e,n)}}function nl(t,e,n){return t._modulesNamespaceMap[n]}function rl(t,e,n){var r=n?t.groupCollapsed:t.group;try{r.call(t,e)}catch(jy){t.log(e)}}function ol(t){try{t.groupEnd()}catch(jy){t.log("—— log end ——")}}function il(){var t=new Date;return" @ "+sl(t.getHours(),2)+":"+sl(t.getMinutes(),2)+":"+sl(t.getSeconds(),2)+"."+sl(t.getMilliseconds(),3)}function sl(t,e){return n="0",r=e-t.toString().length,new Array(r+1).join(n)+t;var n,r}var al={Store:Ba,install:Ua,version:"3.6.2",mapState:Ga,mapMutations:Xa,mapGetters:Za,mapActions:Qa,createNamespacedHelpers:function(t){return{mapState:Ga.bind(null,t),mapGetters:Za.bind(null,t),mapMutations:Xa.bind(null,t),mapActions:Qa.bind(null,t)}},createLogger:function(t){void 0===t&&(t={});var e=t.collapsed;void 0===e&&(e=!0);var n=t.filter;void 0===n&&(n=function(t,e,n){return!0});var r=t.transformer;void 0===r&&(r=function(t){return t});var o=t.mutationTransformer;void 0===o&&(o=function(t){return t});var i=t.actionFilter;void 0===i&&(i=function(t,e){return!0});var s=t.actionTransformer;void 0===s&&(s=function(t){return t});var a=t.logMutations;void 0===a&&(a=!0);var l=t.logActions;void 0===l&&(l=!0);var c=t.logger;return void 0===c&&(c=console),function(t){var u=Aa(t.state);void 0!==c&&(a&&t.subscribe((function(t,i){var s=Aa(i);if(n(t,u,s)){var a=il(),l=o(t),d="mutation "+t.type+a;rl(c,d,e),c.log("%c prev state","color: #9E9E9E; font-weight: bold",r(u)),c.log("%c mutation","color: #03A9F4; font-weight: bold",l),c.log("%c next state","color: #4CAF50; font-weight: bold",r(s)),ol(c)}u=s})),l&&t.subscribeAction((function(t,n){if(i(t,n)){var r=il(),o=s(t),a="action "+t.type+r;rl(c,a,e),c.log("%c action","color: #03A9F4; font-weight: bold",o),ol(c)}})))}}};function ll(t){return{all:t=t||new Map,on:function(e,n){var r=t.get(e);r?r.push(n):t.set(e,[n])},off:function(e,n){var r=t.get(e);r&&(n?r.splice(r.indexOf(n)>>>0,1):t.set(e,[]))},emit:function(e,n){var r=t.get(e);r&&r.slice().map((function(t){t(n)})),(r=t.get("*"))&&r.slice().map((function(t){t(e,n)}))}}}var cl,ul,dl="function"==typeof Map?new Map:(cl=[],ul=[],{has:function(t){return cl.indexOf(t)>-1},get:function(t){return ul[cl.indexOf(t)]},set:function(t,e){-1===cl.indexOf(t)&&(cl.push(t),ul.push(e))},delete:function(t){var e=cl.indexOf(t);e>-1&&(cl.splice(e,1),ul.splice(e,1))}}),hl=function(t){return new Event(t,{bubbles:!0})};try{new Event("test")}catch(jy){hl=function(t){var e=document.createEvent("Event");return e.initEvent(t,!0,!1),e}}function fl(t){var e=dl.get(t);e&&e.destroy()}function pl(t){var e=dl.get(t);e&&e.update()}var ml=null;"undefined"==typeof window||"function"!=typeof window.getComputedStyle?((ml=function(t){return t}).destroy=function(t){return t},ml.update=function(t){return t}):((ml=function(t,e){return t&&Array.prototype.forEach.call(t.length?t:[t],(function(t){return function(t){if(t&&t.nodeName&&"TEXTAREA"===t.nodeName&&!dl.has(t)){var e,n=null,r=null,o=null,i=function(){t.clientWidth!==r&&c()},s=function(e){window.removeEventListener("resize",i,!1),t.removeEventListener("input",c,!1),t.removeEventListener("keyup",c,!1),t.removeEventListener("autosize:destroy",s,!1),t.removeEventListener("autosize:update",c,!1),Object.keys(e).forEach((function(n){t.style[n]=e[n]})),dl.delete(t)}.bind(t,{height:t.style.height,resize:t.style.resize,overflowY:t.style.overflowY,overflowX:t.style.overflowX,wordWrap:t.style.wordWrap});t.addEventListener("autosize:destroy",s,!1),"onpropertychange"in t&&"oninput"in t&&t.addEventListener("keyup",c,!1),window.addEventListener("resize",i,!1),t.addEventListener("input",c,!1),t.addEventListener("autosize:update",c,!1),t.style.overflowX="hidden",t.style.wordWrap="break-word",dl.set(t,{destroy:s,update:c}),"vertical"===(e=window.getComputedStyle(t,null)).resize?t.style.resize="none":"both"===e.resize&&(t.style.resize="horizontal"),n="content-box"===e.boxSizing?-(parseFloat(e.paddingTop)+parseFloat(e.paddingBottom)):parseFloat(e.borderTopWidth)+parseFloat(e.borderBottomWidth),isNaN(n)&&(n=0),c()}function a(e){var n=t.style.width;t.style.width="0px",t.style.width=n,t.style.overflowY=e}function l(){if(0!==t.scrollHeight){var e=function(t){for(var e=[];t&&t.parentNode&&t.parentNode instanceof Element;)t.parentNode.scrollTop&&e.push({node:t.parentNode,scrollTop:t.parentNode.scrollTop}),t=t.parentNode;return e}(t),o=document.documentElement&&document.documentElement.scrollTop;t.style.height="",t.style.height=t.scrollHeight+n+"px",r=t.clientWidth,e.forEach((function(t){t.node.scrollTop=t.scrollTop})),o&&(document.documentElement.scrollTop=o)}}function c(){l();var e=Math.round(parseFloat(t.style.height)),n=window.getComputedStyle(t,null),r="content-box"===n.boxSizing?Math.round(parseFloat(n.height)):t.offsetHeight;if(r=e?t:""+Array(e+1-r.length).join(n)+t},y={s:v,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),o=n%60;return(e<=0?"+":"-")+v(r,2,"0")+":"+v(o,2,"0")},m:function t(e,n){if(e.date()1)return t(s[0])}else{var a=e.name;w[a]=e,o=a}return!r&&o&&(b=o),o||!r&&b},k=function(t,e){if(x(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new O(n)},_=y;_.l=S,_.i=x,_.w=function(t,e){return k(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var O=function(){function g(t){this.$L=S(t.locale,null,!0),this.parse(t)}var v=g.prototype;return v.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(_.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match(p);if(r){var o=r[2]-1||0,i=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],o,r[3]||1,r[4]||0,r[5]||0,r[6]||0,i)):new Date(r[1],o,r[3]||1,r[4]||0,r[5]||0,r[6]||0,i)}}return new Date(e)}(t),this.$x=t.x||{},this.init()},v.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},v.$utils=function(){return _},v.isValid=function(){return!(this.$d.toString()===f)},v.isSame=function(t,e){var n=k(t);return this.startOf(e)<=n&&n<=this.endOf(e)},v.isAfter=function(t,e){return k(t)68?1900:2e3)},a=function(t){return function(e){this[t]=+e}},l=[/[+-]\d\d:?(\d\d)?|Z/,function(t){(this.zone||(this.zone={})).offset=function(t){if(!t)return 0;if("Z"===t)return 0;var e=t.match(/([+-]|\d\d)/g),n=60*e[1]+(+e[2]||0);return 0===n?0:"+"===e[0]?-n:n}(t)}],c=function(t){var e=i[t];return e&&(e.indexOf?e:e.s.concat(e.f))},u=function(t,e){var n,r=i.meridiem;if(r){for(var o=1;o<=24;o+=1)if(t.indexOf(r(o,0,e))>-1){n=o>12;break}}else n=t===(e?"pm":"PM");return n},d={A:[o,function(t){this.afternoon=u(t,!1)}],a:[o,function(t){this.afternoon=u(t,!0)}],S:[/\d/,function(t){this.milliseconds=100*+t}],SS:[n,function(t){this.milliseconds=10*+t}],SSS:[/\d{3}/,function(t){this.milliseconds=+t}],s:[r,a("seconds")],ss:[r,a("seconds")],m:[r,a("minutes")],mm:[r,a("minutes")],H:[r,a("hours")],h:[r,a("hours")],HH:[r,a("hours")],hh:[r,a("hours")],D:[r,a("day")],DD:[n,a("day")],Do:[o,function(t){var e=i.ordinal,n=t.match(/\d+/);if(this.day=n[0],e)for(var r=1;r<=31;r+=1)e(r).replace(/\[|\]/g,"")===t&&(this.day=r)}],M:[r,a("month")],MM:[n,a("month")],MMM:[o,function(t){var e=c("months"),n=(c("monthsShort")||e.map((function(t){return t.slice(0,3)}))).indexOf(t)+1;if(n<1)throw new Error;this.month=n%12||n}],MMMM:[o,function(t){var e=c("months").indexOf(t)+1;if(e<1)throw new Error;this.month=e%12||e}],Y:[/[+-]?\d+/,a("year")],YY:[n,function(t){this.year=s(t)}],YYYY:[/\d{4}/,a("year")],Z:l,ZZ:l};function h(n){var r,o;r=n,o=i&&i.formats;for(var s=(n=r.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,(function(e,n,r){var i=r&&r.toUpperCase();return n||o[r]||t[r]||o[i].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,(function(t,e,n){return e||n.slice(1)}))}))).match(e),a=s.length,l=0;l-1)return new Date(("X"===e?1e3:1)*t);var r=h(e)(t),o=r.year,i=r.month,s=r.day,a=r.hours,l=r.minutes,c=r.seconds,u=r.milliseconds,d=r.zone,f=new Date,p=s||(o||i?1:f.getDate()),m=o||f.getFullYear(),g=0;o&&!i||(g=i>0?i-1:f.getMonth());var v=a||0,y=l||0,b=c||0,w=u||0;return d?new Date(Date.UTC(m,g,p,v,y,b,w+60*d.offset*1e3)):n?new Date(Date.UTC(m,g,p,v,y,b,w)):new Date(m,g,p,v,y,b,w)}catch(x){return new Date("")}}(e,a,r),this.init(),d&&!0!==d&&(this.$L=this.locale(d).$L),u&&e!=this.format(a)&&(this.$d=new Date("")),i={}}else if(a instanceof Array)for(var f=a.length,p=1;p<=f;p+=1){s[1]=a[p-1];var m=n.apply(this,s);if(m.isValid()){this.$d=m.$d,this.$L=m.$L,this.init();break}p===f&&(this.$d=new Date(""))}else o.call(this,t)}}}();function Sl(t){return(Sl="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var kl={selector:"vue-portal-target-".concat(((t=21)=>{let e="",n=t;for(;n--;)e+="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"[64*Math.random()|0];return e})())},_l=function(t){return kl.selector=t},Ol="undefined"!=typeof window&&void 0!==("undefined"==typeof document?"undefined":Sl(document)),Cl=Bn.extend({abstract:!0,name:"PortalOutlet",props:["nodes","tag"],data:function(t){return{updatedNodes:t.nodes}},render:function(t){var e=this.updatedNodes&&this.updatedNodes();return e?1!==e.length||e[0].text?t(this.tag||"DIV",e):e:t()},destroyed:function(){var t=this.$el;t&&t.parentNode.removeChild(t)}}),Ml=Bn.extend({name:"VueSimplePortal",props:{disabled:{type:Boolean},prepend:{type:Boolean},selector:{type:String,default:function(){return"#".concat(kl.selector)}},tag:{type:String,default:"DIV"}},render:function(t){if(this.disabled){var e=this.$scopedSlots&&this.$scopedSlots.default();return e?e.length<2&&!e[0].text?e:t(this.tag,e):t()}return t()},created:function(){this.getTargetEl()||this.insertTargetEl()},updated:function(){var t=this;this.$nextTick((function(){t.disabled||t.slotFn===t.$scopedSlots.default||(t.container.updatedNodes=t.$scopedSlots.default),t.slotFn=t.$scopedSlots.default}))},beforeDestroy:function(){this.unmount()},watch:{disabled:{immediate:!0,handler:function(t){t?this.unmount():this.$nextTick(this.mount)}}},methods:{getTargetEl:function(){if(Ol)return document.querySelector(this.selector)},insertTargetEl:function(){if(Ol){var t=document.querySelector("body"),e=document.createElement(this.tag);e.id=this.selector.substring(1),t.appendChild(e)}},mount:function(){if(Ol){var t=this.getTargetEl(),e=document.createElement("DIV");this.prepend&&t.firstChild?t.insertBefore(e,t.firstChild):t.appendChild(e),this.container=new Cl({el:e,parent:this,propsData:{tag:this.tag,nodes:this.$scopedSlots.default}})}},unmount:function(){this.container&&(this.container.$destroy(),delete this.container)}}});function Dl(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t.component(e.name||"portal",Ml),e.defaultSelector&&_l(e.defaultSelector)}"undefined"!=typeof window&&window.Vue&&window.Vue===Bn&&Bn.use(Dl);var Tl={},$l={};function El(t){return null==t}function Nl(t){return null!=t}function Al(t,e){return e.tag===t.tag&&e.key===t.key}function Pl(t){var e=t.tag;t.vm=new e({data:t.args})}function Il(t,e,n){var r,o,i={};for(r=e;r<=n;++r)Nl(o=t[r].key)&&(i[o]=r);return i}function Rl(t,e,n){for(;e<=n;++e)Pl(t[e])}function zl(t,e,n){for(;e<=n;++e){var r=t[e];Nl(r)&&(r.vm.$destroy(),r.vm=null)}}function jl(t,e){t!==e&&(e.vm=t.vm,function(t){for(var e=Object.keys(t.args),n=0;na?Rl(e,s,u):s>u&&zl(t,i,a)}(t,e):Nl(e)?Rl(e,0,e.length-1):Nl(t)&&zl(t,0,t.length-1)};var Fl={};function Ll(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Bl(t){for(var e=1;et.length)&&(e=t.length);for(var n=0,r=new Array(e);n1?a:a.$sub[0]:null}}},computed:{run:function(){var t=this,e=this.lazyParentModel();if(Array.isArray(e)&&e.__ob__){var n=e.__ob__.dep;n.depend();var r=n.constructor.target;if(!this._indirectWatcher){var o=r.constructor;this._indirectWatcher=new o(this,(function(){return t.runRule(e)}),null,{lazy:!0})}var i=this.getModel();if(!this._indirectWatcher.dirty&&this._lastModel===i)return this._indirectWatcher.depend(),r.value;this._lastModel=i,this._indirectWatcher.evaluate(),this._indirectWatcher.depend()}else this._indirectWatcher&&(this._indirectWatcher.teardown(),this._indirectWatcher=null);return this._indirectWatcher?this._indirectWatcher.value:this.runRule(e)},$params:function(){return this.run.params},proxy:function(){var t=this.run.output;return t.__isVuelidateAsyncVm?!!t.v:!!t},$pending:function(){var t=this.run.output;return!!t.__isVuelidateAsyncVm&&t.p}},destroyed:function(){this._indirectWatcher&&(this._indirectWatcher.teardown(),this._indirectWatcher=null)}}),a=o.extend({data:function(){return{dirty:!1,validations:null,lazyModel:null,model:null,prop:null,lazyParentModel:null,rootModel:null}},methods:s(s({},g),{},{refProxy:function(t){return this.getRef(t).proxy},getRef:function(t){return this.refs[t]},isNested:function(t){return"function"!=typeof this.validations[t]}}),computed:s(s({},p),{},{nestedKeys:function(){return this.keys.filter(this.isNested)},ruleKeys:function(){var t=this;return this.keys.filter((function(e){return!t.isNested(e)}))},keys:function(){return Object.keys(this.validations).filter((function(t){return"$params"!==t}))},proxy:function(){var t=this,e=u(this.keys,(function(e){return{enumerable:!0,configurable:!0,get:function(){return t.refProxy(e)}}})),n=u(v,(function(e){return{enumerable:!0,configurable:!0,get:function(){return t[e]}}})),r=u(y,(function(e){return{enumerable:!1,configurable:!0,get:function(){return t[e]}}})),o=this.hasIter()?{$iter:{enumerable:!0,value:Object.defineProperties({},s({},e))}}:{};return Object.defineProperties({},s(s(s(s({},e),o),{},{$model:{enumerable:!0,get:function(){var e=t.lazyParentModel();return null!=e?e[t.prop]:null},set:function(e){var n=t.lazyParentModel();null!=n&&(n[t.prop]=e,t.$touch())}}},n),r))},children:function(){var t=this;return[].concat(r(this.nestedKeys.map((function(e){return w(t,e)}))),r(this.ruleKeys.map((function(e){return x(t,e)})))).filter(Boolean)}})}),l=a.extend({methods:{isNested:function(t){return void 0!==this.validations[t]()},getRef:function(t){var e=this;return{get proxy(){return e.validations[t]()||!1}}}}}),m=a.extend({computed:{keys:function(){var t=this.getModel();return h(t)?Object.keys(t):[]},tracker:function(){var t=this,e=this.validations.$trackBy;return e?function(n){return"".concat(f(t.rootModel,t.getModelKey(n),e))}:function(t){return"".concat(t)}},getModelLazy:function(){var t=this;return function(){return t.getModel()}},children:function(){var t=this,n=this.validations,r=this.getModel(),o=s({},n);delete o.$trackBy;var i={};return this.keys.map((function(n){var s=t.tracker(n);return i.hasOwnProperty(s)?null:(i[s]=!0,(0,e.h)(a,s,{validations:o,prop:n,lazyParentModel:t.getModelLazy,model:r[n],rootModel:t.rootModel}))})).filter(Boolean)}},methods:{isNested:function(){return!0},getRef:function(t){return this.refs[this.tracker(t)]},hasIter:function(){return!0}}}),w=function(t,n){if("$each"===n)return(0,e.h)(m,n,{validations:t.validations[n],lazyParentModel:t.lazyParentModel,prop:n,lazyModel:t.getModel,rootModel:t.rootModel});var r=t.validations[n];if(Array.isArray(r)){var o=t.rootModel,i=u(r,(function(t){return function(){return f(o,o.$v,t)}}),(function(t){return Array.isArray(t)?t.join("."):t}));return(0,e.h)(l,n,{validations:i,lazyParentModel:c,prop:n,lazyModel:c,rootModel:o})}return(0,e.h)(a,n,{validations:r,lazyParentModel:t.getModel,prop:n,lazyModel:t.getModelKey,rootModel:t.rootModel})},x=function(t,n){return(0,e.h)(i,n,{rule:t.validations[n],lazyParentModel:t.lazyParentModel,lazyModel:t.getModel,rootModel:t.rootModel})};return b={VBase:o,Validation:a}},x=null;var S=function(t,n){var r=function(t){if(x)return x;for(var e=t.constructor;e.super;)e=e.super;return x=e,e}(t),o=w(r),i=o.Validation;return new(0,o.VBase)({computed:{children:function(){var r="function"==typeof n?n.call(t):n;return[(0,e.h)(i,"$v",{validations:r,lazyParentModel:c,prop:"$v",model:t,rootModel:t})]}}})},k={data:function(){var t=this.$options.validations;return t&&(this._vuelidate=S(this,t)),{}},beforeCreate:function(){var t=this.$options;t.validations&&(t.computed||(t.computed={}),t.computed.$v||(t.computed.$v=function(){return this._vuelidate?this._vuelidate.refs.$v.proxy:null}))},beforeDestroy:function(){this._vuelidate&&(this._vuelidate.$destroy(),this._vuelidate=null)}};function _(t){t.mixin(k)}t.validationMixin=k;var O=_;t.default=O}(Tl);var Gl=vl(Tl);function Xl(t){this.content=t}function Zl(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let o=t.child(r),i=e.child(r);if(o!=i){if(!o.sameMarkup(i))return n;if(o.isText&&o.text!=i.text){for(let t=0;o.text[t]==i.text[t];t++)n++;return n}if(o.content.size||i.content.size){let t=Zl(o.content,i.content,n+1);if(null!=t)return t}n+=o.nodeSize}else n+=o.nodeSize}}function Ql(t,e,n,r){for(let o=t.childCount,i=e.childCount;;){if(0==o||0==i)return o==i?null:{a:n,b:r};let s=t.child(--o),a=e.child(--i),l=s.nodeSize;if(s!=a){if(!s.sameMarkup(a))return{a:n,b:r};if(s.isText&&s.text!=a.text){let t=0,e=Math.min(s.text.length,a.text.length);for(;t>1}},Xl.from=function(t){if(t instanceof Xl)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new Xl(e)};class tc{constructor(t,e){if(this.content=t,this.size=e||0,null==e)for(let n=0;nt&&!1!==n(a,r+s,o||null,i)&&a.content.size){let o=s+1;a.nodesBetween(Math.max(0,t-o),Math.min(a.content.size,e-o),n,r+o)}s=l}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,e,n,r){let o="",i=!0;return this.nodesBetween(t,e,((s,a)=>{s.isText?(o+=s.text.slice(Math.max(t,a)-a,e-a),i=!n):s.isLeaf?(r?o+="function"==typeof r?r(s):r:s.type.spec.leafText&&(o+=s.type.spec.leafText(s)),i=!n):!i&&s.isBlock&&(o+=n,i=!0)}),0),o}append(t){if(!t.size)return this;if(!this.size)return t;let e=this.lastChild,n=t.firstChild,r=this.content.slice(),o=0;for(e.isText&&e.sameMarkup(n)&&(r[r.length-1]=e.withText(e.text+n.text),o=1);ot)for(let o=0,i=0;it&&((ie)&&(s=s.isText?s.cut(Math.max(0,t-i),Math.min(s.text.length,e-i)):s.cut(Math.max(0,t-i-1),Math.min(s.content.size,e-i-1))),n.push(s),r+=s.nodeSize),i=a}return new tc(n,r)}cutByIndex(t,e){return t==e?tc.empty:0==t&&e==this.content.length?this:new tc(this.content.slice(t,e))}replaceChild(t,e){let n=this.content[t];if(n==e)return this;let r=this.content.slice(),o=this.size+e.nodeSize-n.nodeSize;return r[t]=e,new tc(r,o)}addToStart(t){return new tc([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new tc(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return!1;for(let e=0;ethis.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let n=0,r=0;;n++){let o=r+this.child(n).nodeSize;if(o>=t)return o==t||e>0?nc(n+1,o):nc(n,r);r=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map((t=>t.toJSON())):null}static fromJSON(t,e){if(!e)return tc.empty;if(!Array.isArray(e))throw new RangeError("Invalid input for Fragment.fromJSON");return new tc(e.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return tc.empty;let e,n=0;for(let r=0;rthis.type.rank&&(e||(e=t.slice(0,r)),e.push(this),n=!0),e&&e.push(o)}}return e||(e=t.slice()),n||e.push(this),e}removeFromSet(t){for(let e=0;et.type.rank-e.type.rank)),e}}oc.none=[];class ic extends Error{}class sc{constructor(t,e,n){this.content=t,this.openStart=e,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,e){let n=lc(this.content,t+this.openStart,e);return n&&new sc(n,this.openStart,this.openEnd)}removeBetween(t,e){return new sc(ac(this.content,t+this.openStart,e+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t}static fromJSON(t,e){if(!e)return sc.empty;let n=e.openStart||0,r=e.openEnd||0;if("number"!=typeof n||"number"!=typeof r)throw new RangeError("Invalid input for Slice.fromJSON");return new sc(tc.fromJSON(t,e.content),n,r)}static maxOpen(t,e=!0){let n=0,r=0;for(let o=t.firstChild;o&&!o.isLeaf&&(e||!o.type.spec.isolating);o=o.firstChild)n++;for(let o=t.lastChild;o&&!o.isLeaf&&(e||!o.type.spec.isolating);o=o.lastChild)r++;return new sc(t,n,r)}}function ac(t,e,n){let{index:r,offset:o}=t.findIndex(e),i=t.maybeChild(r),{index:s,offset:a}=t.findIndex(n);if(o==e||i.isText){if(a!=n&&!t.child(s).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=s)throw new RangeError("Removing non-flat range");return t.replaceChild(r,i.copy(ac(i.content,e-o-1,n-o-1)))}function lc(t,e,n,r){let{index:o,offset:i}=t.findIndex(e),s=t.maybeChild(o);if(i==e||s.isText)return r&&!r.canReplace(o,o,n)?null:t.cut(0,e).append(n).append(t.cut(e));let a=lc(s.content,e-i-1,n);return a&&t.replaceChild(o,s.copy(a))}function cc(t,e,n){if(n.openStart>t.depth)throw new ic("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new ic("Inconsistent open depths");return uc(t,e,n,0)}function uc(t,e,n,r){let o=t.index(r),i=t.node(r);if(o==e.index(r)&&r=0;o--)r=e.node(o).copy(tc.from(r));return{start:r.resolveNoCache(t.openStart+n),end:r.resolveNoCache(r.content.size-t.openEnd-n)}}(n,t);return mc(i,gc(t,o,s,e,r))}{let r=t.parent,o=r.content;return mc(r,o.cut(0,t.parentOffset).append(n.content).append(o.cut(e.parentOffset)))}}return mc(i,vc(t,e,r))}function dc(t,e){if(!e.type.compatibleContent(t.type))throw new ic("Cannot join "+e.type.name+" onto "+t.type.name)}function hc(t,e,n){let r=t.node(n);return dc(r,e.node(n)),r}function fc(t,e){let n=e.length-1;n>=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function pc(t,e,n,r){let o=(e||t).node(n),i=0,s=e?e.index(n):o.childCount;t&&(i=t.index(n),t.depth>n?i++:t.textOffset&&(fc(t.nodeAfter,r),i++));for(let a=i;ao&&hc(t,e,o+1),s=r.depth>o&&hc(n,r,o+1),a=[];return pc(null,t,o,a),i&&s&&e.index(o)==n.index(o)?(dc(i,s),fc(mc(i,gc(t,e,n,r,o+1)),a)):(i&&fc(mc(i,vc(t,e,o+1)),a),pc(e,n,o,a),s&&fc(mc(s,vc(n,r,o+1)),a)),pc(r,null,o,a),new tc(a)}function vc(t,e,n){let r=[];if(pc(null,t,n,r),t.depth>n){fc(mc(hc(t,e,n+1),vc(t,e,n+1)),r)}return pc(e,null,n,r),new tc(r)}sc.empty=new sc(tc.empty,0,0);class yc{constructor(t,e,n){this.pos=t,this.path=e,this.parentOffset=n,this.depth=e.length/3-1}resolveDepth(t){return null==t?this.depth:t<0?this.depth+t:t}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(t){return this.path[3*this.resolveDepth(t)]}index(t){return this.path[3*this.resolveDepth(t)+1]}indexAfter(t){return t=this.resolveDepth(t),this.index(t)+(t!=this.depth||this.textOffset?1:0)}start(t){return 0==(t=this.resolveDepth(t))?0:this.path[3*t-1]+1}end(t){return t=this.resolveDepth(t),this.start(t)+this.node(t).content.size}before(t){if(!(t=this.resolveDepth(t)))throw new RangeError("There is no position before the top-level node");return t==this.depth+1?this.pos:this.path[3*t-1]}after(t){if(!(t=this.resolveDepth(t)))throw new RangeError("There is no position after the top-level node");return t==this.depth+1?this.pos:this.path[3*t-1]+this.path[3*t].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let t=this.parent,e=this.index(this.depth);if(e==t.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=t.child(e);return n?t.child(e).cut(n):r}get nodeBefore(){let t=this.index(this.depth),e=this.pos-this.path[this.path.length-1];return e?this.parent.child(t).cut(0,e):0==t?null:this.parent.child(t-1)}posAtIndex(t,e){e=this.resolveDepth(e);let n=this.path[3*e],r=0==e?0:this.path[3*e-1]+1;for(let o=0;o0;e--)if(this.start(e)<=t&&this.end(e)>=t)return e;return 0}blockRange(t=this,e){if(t.pos=0;n--)if(t.pos<=this.end(n)&&(!e||e(this.node(n))))return new Sc(this,t,n);return null}sameParent(t){return this.pos-this.parentOffset==t.pos-t.parentOffset}max(t){return t.pos>this.pos?t:this}min(t){return t.pos=0&&e<=t.content.size))throw new RangeError("Position "+e+" out of range");let n=[],r=0,o=e;for(let i=t;;){let{index:t,offset:e}=i.content.findIndex(o),s=o-e;if(n.push(i,t,r+e),!s)break;if(i=i.child(t),i.isText)break;o=s-1,r+=e+1}return new yc(e,n,o)}static resolveCached(t,e){for(let r=0;rt&&this.nodesBetween(t,e,(t=>(n.isInSet(t.marks)&&(r=!0),!r))),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let t=this.type.name;return this.content.size&&(t+="("+this.content.toStringInner()+")"),Cc(this.marks,t)}contentMatchAt(t){let e=this.type.contentMatch.matchFragment(this.content,0,t);if(!e)throw new Error("Called contentMatchAt on a node with invalid content");return e}canReplace(t,e,n=tc.empty,r=0,o=n.childCount){let i=this.contentMatchAt(t).matchFragment(n,r,o),s=i&&i.matchFragment(this.content,e);if(!s||!s.validEnd)return!1;for(let a=r;at.type.name))}`);this.content.forEach((t=>t.check()))}toJSON(){let t={type:this.type.name};for(let e in this.attrs){t.attrs=this.attrs;break}return this.content.size&&(t.content=this.content.toJSON()),this.marks.length&&(t.marks=this.marks.map((t=>t.toJSON()))),t}static fromJSON(t,e){if(!e)throw new RangeError("Invalid input for Node.fromJSON");let n=null;if(e.marks){if(!Array.isArray(e.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=e.marks.map(t.markFromJSON)}if("text"==e.type){if("string"!=typeof e.text)throw new RangeError("Invalid text node in JSON");return t.text(e.text,n)}let r=tc.fromJSON(t,e.content);return t.nodeType(e.type).create(e.attrs,r,n)}}_c.prototype.text=void 0;class Oc extends _c{constructor(t,e,n,r){if(super(t,e,null,r),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Cc(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(t,e){return this.text.slice(t,e)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new Oc(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new Oc(this.type,this.attrs,t,this.marks)}cut(t=0,e=this.text.length){return 0==t&&e==this.text.length?this:this.withText(this.text.slice(t,e))}eq(t){return this.sameMarkup(t)&&this.text==t.text}toJSON(){let t=super.toJSON();return t.text=this.text,t}}function Cc(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class Mc{constructor(t){this.validEnd=t,this.next=[],this.wrapCache=[]}static parse(t,e){let n=new Dc(t,e);if(null==n.next)return Mc.empty;let r=Tc(n);n.next&&n.err("Unexpected trailing text");let o=function(t){let e=Object.create(null);return n(Ic(t,0));function n(r){let o=[];r.forEach((e=>{t[e].forEach((({term:e,to:n})=>{if(!e)return;let r;for(let t=0;t{r||o.push([e,r=[]]),-1==r.indexOf(t)&&r.push(t)}))}))}));let i=e[r.join(",")]=new Mc(r.indexOf(t.length-1)>-1);for(let t=0;tt.to=e))}function i(t,e){if("choice"==t.type)return t.exprs.reduce(((t,n)=>t.concat(i(n,e))),[]);if("seq"!=t.type){if("star"==t.type){let s=n();return r(e,s),o(i(t.expr,s),s),[r(s)]}if("plus"==t.type){let s=n();return o(i(t.expr,e),s),o(i(t.expr,s),s),[r(s)]}if("opt"==t.type)return[r(e)].concat(i(t.expr,e));if("range"==t.type){let s=e;for(let e=0;et.createAndFill())));for(let t=0;t=this.next.length)throw new RangeError(`There's no ${t}th edge in this content match`);return this.next[t]}toString(){let t=[];return function e(n){t.push(n);for(let r=0;r{let r=n+(e.validEnd?"*":" ")+" ";for(let o=0;o"+t.indexOf(e.next[o].next);return r})).join("\n")}}Mc.empty=new Mc(!0);class Dc{constructor(t,e){this.string=t,this.nodeTypes=e,this.inline=null,this.pos=0,this.tokens=t.split(/\s*(?=\b|\W|$)/),""==this.tokens[this.tokens.length-1]&&this.tokens.pop(),""==this.tokens[0]&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(t){return this.next==t&&(this.pos++||!0)}err(t){throw new SyntaxError(t+" (in content expression '"+this.string+"')")}}function Tc(t){let e=[];do{e.push($c(t))}while(t.eat("|"));return 1==e.length?e[0]:{type:"choice",exprs:e}}function $c(t){let e=[];do{e.push(Ec(t))}while(t.next&&")"!=t.next&&"|"!=t.next);return 1==e.length?e[0]:{type:"seq",exprs:e}}function Ec(t){let e=function(t){if(t.eat("(")){let e=Tc(t);return t.eat(")")||t.err("Missing closing paren"),e}if(!/\W/.test(t.next)){let e=function(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let o=[];for(let i in n){let t=n[i];t.groups.indexOf(e)>-1&&o.push(t)}0==o.length&&t.err("No node type or group '"+e+"' found");return o}(t,t.next).map((e=>(null==t.inline?t.inline=e.isInline:t.inline!=e.isInline&&t.err("Mixing inline and block content"),{type:"name",value:e})));return t.pos++,1==e.length?e[0]:{type:"choice",exprs:e}}t.err("Unexpected token '"+t.next+"'")}(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else{if(!t.eat("{"))break;e=Ac(t,e)}return e}function Nc(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function Ac(t,e){let n=Nc(t),r=n;return t.eat(",")&&(r="}"!=t.next?Nc(t):-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function Pc(t,e){return e-t}function Ic(t,e){let n=[];return function e(r){let o=t[r];if(1==o.length&&!o[0].term)return e(o[0].to);n.push(r);for(let t=0;t-1}allowsMarks(t){if(null==this.markSet)return!0;for(let e=0;en[t]=new Fc(t,e,r)));let r=e.spec.topNode||"doc";if(!n[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!n.text)throw new RangeError("Every schema needs a 'text' type");for(let o in n.text.attrs)throw new RangeError("The text node type should not have attributes");return n}}class Lc{constructor(t){this.hasDefault=Object.prototype.hasOwnProperty.call(t,"default"),this.default=t.default}get isRequired(){return!this.hasDefault}}class Bc{constructor(t,e,n,r){this.name=t,this.rank=e,this.schema=n,this.spec=r,this.attrs=jc(r.attrs),this.excluded=null;let o=Rc(this.attrs);this.instance=o?new oc(this,o):null}create(t=null){return!t&&this.instance?this.instance:new oc(this,zc(this.attrs,t))}static compile(t,e){let n=Object.create(null),r=0;return t.forEach(((t,o)=>n[t]=new Bc(t,r++,e,o))),n}removeFromSet(t){for(var e=0;e-1}}class Vc{constructor(t){this.cached=Object.create(null),this.spec={nodes:Xl.from(t.nodes),marks:Xl.from(t.marks||{}),topNode:t.topNode},this.nodes=Fc.compile(this.spec.nodes,this),this.marks=Bc.compile(this.spec.marks,this);let e=Object.create(null);for(let n in this.nodes){if(n in this.marks)throw new RangeError(n+" can not be both a node and a mark");let t=this.nodes[n],r=t.spec.content||"",o=t.spec.marks;t.contentMatch=e[r]||(e[r]=Mc.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.markSet="_"==o?null:o?Wc(this,o.split(" ")):""!=o&&t.inlineContent?null:[]}for(let n in this.marks){let t=this.marks[n],e=t.spec.excludes;t.excluded=null==e?[t]:""==e?[]:Wc(this,e.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(t,e=null,n,r){if("string"==typeof t)t=this.nodeType(t);else{if(!(t instanceof Fc))throw new RangeError("Invalid node type: "+t);if(t.schema!=this)throw new RangeError("Node type from different schema used ("+t.name+")")}return t.createChecked(e,n,r)}text(t,e){let n=this.nodes.text;return new Oc(n,n.defaultAttrs,t,oc.setFrom(e))}mark(t,e){return"string"==typeof t&&(t=this.marks[t]),t.create(e)}nodeFromJSON(t){return _c.fromJSON(this,t)}markFromJSON(t){return oc.fromJSON(this,t)}nodeType(t){let e=this.nodes[t];if(!e)throw new RangeError("Unknown node type: "+t);return e}}function Wc(t,e){let n=[];for(let r=0;r-1)&&n.push(s=r)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}class qc{constructor(t,e){this.schema=t,this.rules=e,this.tags=[],this.styles=[],e.forEach((t=>{t.tag?this.tags.push(t):t.style&&this.styles.push(t)})),this.normalizeLists=!this.tags.some((e=>{if(!/^(ul|ol)\b/.test(e.tag)||!e.node)return!1;let n=t.nodes[e.node];return n.contentMatch.matchType(n)}))}parse(t,e={}){let n=new Gc(this,e,!1);return n.addAll(t,e.from,e.to),n.finish()}parseSlice(t,e={}){let n=new Gc(this,e,!0);return n.addAll(t,e.from,e.to),sc.maxOpen(n.finish())}matchTag(t,e,n){for(let r=n?this.tags.indexOf(n)+1:0;rt.length&&(61!=i.charCodeAt(t.length)||i.slice(t.length+1)!=e))){if(r.getAttrs){let t=r.getAttrs(e);if(!1===t)continue;r.attrs=t||void 0}return r}}}static schemaRules(t){let e=[];function n(t){let n=null==t.priority?50:t.priority,r=0;for(;r{n(t=Zc(t)),t.mark=r}))}for(let r in t.nodes){let e=t.nodes[r].spec.parseDOM;e&&e.forEach((t=>{n(t=Zc(t)),t.node=r}))}return e}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new qc(t,qc.schemaRules(t)))}}const Hc={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Jc={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Kc={ol:!0,ul:!0};function Yc(t,e,n){return null!=e?(e?1:0)|("full"===e?2:0):t&&"pre"==t.whitespace?3:-5&n}class Uc{constructor(t,e,n,r,o,i,s){this.type=t,this.attrs=e,this.marks=n,this.pendingMarks=r,this.solid=o,this.options=s,this.content=[],this.activeMarks=oc.none,this.stashMarks=[],this.match=i||(4&s?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let e=this.type.contentMatch.fillBefore(tc.from(t));if(!e){let e,n=this.type.contentMatch;return(e=n.findWrapping(t.type))?(this.match=n,e):null}this.match=this.type.contentMatch.matchFragment(e)}return this.match.findWrapping(t.type)}finish(t){if(!(1&this.options)){let t,e=this.content[this.content.length-1];if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let n=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-t[0].length))}}let e=tc.from(this.content);return!t&&this.match&&(e=e.append(this.match.fillBefore(tc.empty,!0))),this.type?this.type.create(this.attrs,e,this.marks):e}popFromStashMark(t){for(let e=this.stashMarks.length-1;e>=0;e--)if(t.eq(this.stashMarks[e]))return this.stashMarks.splice(e,1)[0]}applyPending(t){for(let e=0,n=this.pendingMarks;ethis.insertNode(t)));else{let n=t;"string"==typeof e.contentElement?n=t.querySelector(e.contentElement):"function"==typeof e.contentElement?n=e.contentElement(t):e.contentElement&&(n=e.contentElement),this.findAround(t,n,!0),this.addAll(n)}r&&this.sync(s)&&this.open--,i&&this.removePendingMark(i,s)}addAll(t,e,n){let r=e||0;for(let o=e?t.childNodes[e]:t.firstChild,i=null==n?null:t.childNodes[n];o!=i;o=o.nextSibling,++r)this.findAtPoint(t,r),this.addDOM(o);this.findAtPoint(t,r)}findPlace(t){let e,n;for(let r=this.open;r>=0;r--){let o=this.nodes[r],i=o.findWrapping(t);if(i&&(!e||e.length>i.length)&&(e=i,n=o,!i.length))break;if(o.solid)break}if(!e)return!1;this.sync(n);for(let r=0;rthis.open){for(;e>this.open;e--)this.nodes[e-1].content.push(this.nodes[e].finish(t));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(t){for(let e=this.open;e>=0;e--)if(this.nodes[e]==t)return this.open=e,!0;return!1}get currentPos(){this.closeExtra();let t=0;for(let e=this.open;e>=0;e--){let n=this.nodes[e].content;for(let e=n.length-1;e>=0;e--)t+=n[e].nodeSize;e&&t++}return t}findAtPoint(t,e){if(this.find)for(let n=0;n-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let e=t.split("/"),n=this.options.context,r=!(this.isOpen||n&&n.parent.type!=this.nodes[0].type),o=-(n?n.depth+1:0)+(r?0:1),i=(t,s)=>{for(;t>=0;t--){let a=e[t];if(""==a){if(t==e.length-1||0==t)continue;for(;s>=o;s--)if(i(t-1,s))return!0;return!1}{let t=s>0||0==s&&r?this.nodes[s].type:n&&s>=o?n.node(s-o).type:null;if(!t||t.name!=a&&-1==t.groups.indexOf(a))return!1;s--}}return!0};return i(e.length-1,this.open)}textblockFromContext(){let t=this.options.context;if(t)for(let e=t.depth;e>=0;e--){let n=t.node(e).contentMatchAt(t.indexAfter(e)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}addPendingMark(t){let e=function(t,e){for(let n=0;n=0;n--){let r=this.nodes[n];if(r.pendingMarks.lastIndexOf(t)>-1)r.pendingMarks=t.removeFromSet(r.pendingMarks);else{r.activeMarks=t.removeFromSet(r.activeMarks);let e=r.popFromStashMark(t);e&&r.type&&r.type.allowsMarkType(e.type)&&(r.activeMarks=e.addToSet(r.activeMarks))}if(r==e)break}}}function Xc(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function Zc(t){let e={};for(let n in t)e[n]=t[n];return e}function Qc(t,e){let n=e.schema.nodes;for(let r in n){let o=n[r];if(!o.allowsMarkType(t))continue;let i=[],s=t=>{i.push(t);for(let n=0;n{if(o.length||t.marks.length){let n=0,i=0;for(;n=0;r--){let o=this.serializeMark(t.marks[r],t.isInline,e);o&&((o.contentDOM||o.dom).appendChild(n),n=o.dom)}return n}serializeMark(t,e,n={}){let r=this.marks[t.type.name];return r&&tu.renderSpec(nu(n),r(t,e))}static renderSpec(t,e,n=null){if("string"==typeof e)return{dom:t.createTextNode(e)};if(null!=e.nodeType)return{dom:e};if(e.dom&&null!=e.dom.nodeType)return e;let r,o=e[0],i=o.indexOf(" ");i>0&&(n=o.slice(0,i),o=o.slice(i+1));let s=n?t.createElementNS(n,o):t.createElement(o),a=e[1],l=1;if(a&&"object"==typeof a&&null==a.nodeType&&!Array.isArray(a)){l=2;for(let t in a)if(null!=a[t]){let e=t.indexOf(" ");e>0?s.setAttributeNS(t.slice(0,e),t.slice(e+1),a[t]):s.setAttribute(t,a[t])}}for(let c=l;cl)throw new RangeError("Content hole must be the only child of its parent node");return{dom:s,contentDOM:s}}{let{dom:e,contentDOM:i}=tu.renderSpec(t,o,n);if(s.appendChild(e),i){if(r)throw new RangeError("Multiple content holes");r=i}}}return{dom:s,contentDOM:r}}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new tu(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(t){let e=eu(t.nodes);return e.text||(e.text=t=>t.text),e}static marksFromSchema(t){return eu(t.marks)}}function eu(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function nu(t){return t.document||window.document}const ru=Math.pow(2,16);function ou(t){return 65535&t}class iu{constructor(t,e,n){this.pos=t,this.delInfo=e,this.recover=n}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}}class su{constructor(t,e=!1){if(this.ranges=t,this.inverted=e,!t.length&&su.empty)return su.empty}recover(t){let e=0,n=ou(t);if(!this.inverted)for(let r=0;rt)break;let l=this.ranges[s+o],c=this.ranges[s+i],u=a+l;if(t<=u){let o=a+r+((l?t==a?-1:t==u?1:e:e)<0?0:c);if(n)return o;let i=t==(e<0?a:u)?null:s/3+(t-a)*ru,d=t==a?2:t==u?1:4;return(e<0?t!=a:t!=u)&&(d|=8),new iu(o,d,i)}r+=c-l}return n?t+r:new iu(t+r,0,null)}touches(t,e){let n=0,r=ou(e),o=this.inverted?2:1,i=this.inverted?1:2;for(let s=0;st)break;let a=this.ranges[s+o];if(t<=e+a&&s==3*r)return!0;n+=this.ranges[s+i]-a}return!1}forEach(t){let e=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,o=0;r=0;e--){let r=t.getMirror(e);this.appendMap(t.maps[e].invert(),null!=r&&r>e?n-r-1:void 0)}}invert(){let t=new au;return t.appendMappingInverted(this),t}map(t,e=1){if(this.mirror)return this._map(t,e,!0);for(let n=this.from;no&&et.isAtom&&e.type.allowsMarkType(this.mark.type)?t.mark(this.mark.addToSet(t.marks)):t),r),e.openStart,e.openEnd);return uu.fromReplace(t,this.from,this.to,o)}invert(){return new fu(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),n=t.mapResult(this.to,-1);return e.deleted&&n.deleted||e.pos>=n.pos?null:new hu(e.pos,n.pos,this.mark)}merge(t){return t instanceof hu&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new hu(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new hu(e.from,e.to,t.markFromJSON(e.mark))}}cu.jsonID("addMark",hu);class fu extends cu{constructor(t,e,n){super(),this.from=t,this.to=e,this.mark=n}apply(t){let e=t.slice(this.from,this.to),n=new sc(du(e.content,(t=>t.mark(this.mark.removeFromSet(t.marks))),t),e.openStart,e.openEnd);return uu.fromReplace(t,this.from,this.to,n)}invert(){return new hu(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),n=t.mapResult(this.to,-1);return e.deleted&&n.deleted||e.pos>=n.pos?null:new fu(e.pos,n.pos,this.mark)}merge(t){return t instanceof fu&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new fu(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new fu(e.from,e.to,t.markFromJSON(e.mark))}}cu.jsonID("removeMark",fu);class pu extends cu{constructor(t,e,n,r=!1){super(),this.from=t,this.to=e,this.slice=n,this.structure=r}apply(t){return this.structure&&gu(t,this.from,this.to)?uu.fail("Structure replace would overwrite content"):uu.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new su([this.from,this.to-this.from,this.slice.size])}invert(t){return new pu(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let e=t.mapResult(this.from,1),n=t.mapResult(this.to,-1);return e.deletedAcross&&n.deletedAcross?null:new pu(e.pos,Math.max(e.pos,n.pos),this.slice)}merge(t){if(!(t instanceof pu)||t.structure||this.structure)return null;if(this.from+this.slice.size!=t.from||this.slice.openEnd||t.slice.openStart){if(t.to!=this.from||this.slice.openStart||t.slice.openEnd)return null;{let e=this.slice.size+t.slice.size==0?sc.empty:new sc(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new pu(t.from,this.to,e,this.structure)}}{let e=this.slice.size+t.slice.size==0?sc.empty:new sc(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new pu(this.from,this.to+(t.to-t.from),e,this.structure)}}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new pu(e.from,e.to,sc.fromJSON(t,e.slice),!!e.structure)}}cu.jsonID("replace",pu);class mu extends cu{constructor(t,e,n,r,o,i,s=!1){super(),this.from=t,this.to=e,this.gapFrom=n,this.gapTo=r,this.slice=o,this.insert=i,this.structure=s}apply(t){if(this.structure&&(gu(t,this.from,this.gapFrom)||gu(t,this.gapTo,this.to)))return uu.fail("Structure gap-replace would overwrite content");let e=t.slice(this.gapFrom,this.gapTo);if(e.openStart||e.openEnd)return uu.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,e.content);return n?uu.fromReplace(t,this.from,this.to,n):uu.fail("Content does not fit in gap")}getMap(){return new su([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let e=this.gapTo-this.gapFrom;return new mu(this.from,this.from+this.slice.size+e,this.from+this.insert,this.from+this.insert+e,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let e=t.mapResult(this.from,1),n=t.mapResult(this.to,-1),r=t.map(this.gapFrom,-1),o=t.map(this.gapTo,1);return e.deletedAcross&&n.deletedAcross||rn.pos?null:new mu(e.pos,n.pos,r,o,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to||"number"!=typeof e.gapFrom||"number"!=typeof e.gapTo||"number"!=typeof e.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new mu(e.from,e.to,e.gapFrom,e.gapTo,sc.fromJSON(t,e.slice),e.insert,!!e.structure)}}function gu(t,e,n){let r=t.resolve(e),o=n-e,i=r.depth;for(;o>0&&i>0&&r.indexAfter(i)==r.node(i).childCount;)i--,o--;if(o>0){let t=r.node(i).maybeChild(r.indexAfter(i));for(;o>0;){if(!t||t.isLeaf)return!0;t=t.firstChild,o--}}return!1}function vu(t,e,n){return(0==e||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function yu(t){let e=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let n=t.depth;;--n){let r=t.$from.node(n),o=t.$from.index(n),i=t.$to.indexAfter(n);if(ni;c--,u--){let t=o.node(c),e=o.index(c);if(t.type.spec.isolating)return!1;let n=t.content.cutByIndex(e,t.childCount),i=r&&r[u]||t;if(i!=t&&(n=n.replaceChild(0,i.type.create(i.attrs))),!t.canReplace(e+1,t.childCount)||!i.type.validContent(n))return!1}let a=o.indexAfter(i),l=r&&r[0];return o.node(i).canReplaceWith(a,a,l?l.type:o.node(i+1).type)}function Su(t,e){let n=t.resolve(e),r=n.index();return o=n.nodeBefore,i=n.nodeAfter,!(!o||!i||o.isLeaf||!o.canAppend(i))&&n.parent.canReplace(r,r+1);var o,i}function ku(t,e,n=e,r=sc.empty){if(e==n&&!r.size)return null;let o=t.resolve(e),i=t.resolve(n);return _u(o,i,r)?new pu(e,n,r):new Ou(o,i,r).fit()}function _u(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}cu.jsonID("replaceAround",mu);class Ou{constructor(t,e,n){this.$from=t,this.$to=e,this.unplaced=n,this.frontier=[],this.placed=tc.empty;for(let r=0;r<=t.depth;r++){let e=t.node(r);this.frontier.push({type:e.type,match:e.contentMatchAt(t.indexAfter(r))})}for(let r=t.depth;r>0;r--)this.placed=tc.from(t.node(r).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let t=this.findFittable();t?this.placeNodes(t):this.openMore()||this.dropNode()}let t=this.mustMoveInline(),e=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(t<0?this.$to:n.doc.resolve(t));if(!r)return null;let o=this.placed,i=n.depth,s=r.depth;for(;i&&s&&1==o.childCount;)o=o.firstChild.content,i--,s--;let a=new sc(o,i,s);return t>-1?new mu(n.pos,t,this.$to.pos,this.$to.end(),a,e):a.size||n.pos!=this.$to.pos?new pu(n.pos,r.pos,a):null}findFittable(){for(let t=1;t<=2;t++)for(let e=this.unplaced.openStart;e>=0;e--){let n,r=null;e?(r=Du(this.unplaced.content,e-1).firstChild,n=r.content):n=this.unplaced.content;let o=n.firstChild;for(let i=this.depth;i>=0;i--){let n,{type:s,match:a}=this.frontier[i],l=null;if(1==t&&(o?a.matchType(o.type)||(l=a.fillBefore(tc.from(o),!1)):r&&s.compatibleContent(r.type)))return{sliceDepth:e,frontierDepth:i,parent:r,inject:l};if(2==t&&o&&(n=a.findWrapping(o.type)))return{sliceDepth:e,frontierDepth:i,parent:r,wrap:n};if(r&&a.matchType(r.type))break}}}openMore(){let{content:t,openStart:e,openEnd:n}=this.unplaced,r=Du(t,e);return!(!r.childCount||r.firstChild.isLeaf)&&(this.unplaced=new sc(t,e+1,Math.max(n,r.size+e>=t.size-n?e+1:0)),!0)}dropNode(){let{content:t,openStart:e,openEnd:n}=this.unplaced,r=Du(t,e);if(r.childCount<=1&&e>0){let o=t.size-e<=e+r.size;this.unplaced=new sc(Cu(t,e-1,1),e-1,o?e-1:n)}else this.unplaced=new sc(Cu(t,e,1),e,n)}placeNodes({sliceDepth:t,frontierDepth:e,parent:n,inject:r,wrap:o}){for(;this.depth>e;)this.closeFrontierNode();if(o)for(let p=0;p1||0==a||t.content.size)&&(u=e,c.push(Tu(t.mark(d.allowedMarks(t.marks)),1==l?a:0,l==s.childCount?h:-1)))}let f=l==s.childCount;f||(h=-1),this.placed=Mu(this.placed,e,tc.from(c)),this.frontier[e].match=u,f&&h<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let p=0,m=s;p1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(t){t:for(let e=Math.min(this.depth,t.depth);e>=0;e--){let{match:n,type:r}=this.frontier[e],o=e=0;n--){let{match:e,type:r}=this.frontier[n],o=$u(t,n,r,e,!0);if(!o||o.childCount)continue t}return{depth:e,fit:i,move:o?t.doc.resolve(t.after(e+1)):t}}}}close(t){let e=this.findCloseLevel(t);if(!e)return null;for(;this.depth>e.depth;)this.closeFrontierNode();e.fit.childCount&&(this.placed=Mu(this.placed,e.depth,e.fit)),t=e.move;for(let n=e.depth+1;n<=t.depth;n++){let e=t.node(n),r=e.type.contentMatch.fillBefore(e.content,!0,t.index(n));this.openFrontierNode(e.type,e.attrs,r)}return t}openFrontierNode(t,e=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(t),this.placed=Mu(this.placed,this.depth,tc.from(t.create(e,n))),this.frontier.push({type:t,match:t.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(tc.empty,!0);t.childCount&&(this.placed=Mu(this.placed,this.frontier.length,t))}}function Cu(t,e,n){return 0==e?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(Cu(t.firstChild.content,e-1,n)))}function Mu(t,e,n){return 0==e?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(Mu(t.lastChild.content,e-1,n)))}function Du(t,e){for(let n=0;n1&&(r=r.replaceChild(0,Tu(r.firstChild,e-1,1==r.childCount?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(tc.empty,!0)))),t.copy(r)}function $u(t,e,n,r,o){let i=t.node(e),s=o?t.indexAfter(e):t.index(e);if(s==i.childCount&&!n.compatibleContent(i.type))return null;let a=r.fillBefore(i.content,!0,s);return a&&!function(t,e,n){for(let r=n;rr){let e=o.contentMatchAt(0),n=e.fillBefore(t).append(t);t=n.append(e.matchFragment(n).fillBefore(tc.empty,!0))}return t}function Au(t,e){let n=[];for(let r=Math.min(t.depth,e.depth);r>=0;r--){let o=t.start(r);if(oe.pos+(e.depth-r)||t.node(r).type.spec.isolating||e.node(r).type.spec.isolating)break;(o==e.start(r)||r==t.depth&&r==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&r&&e.start(r-1)==o-1)&&n.push(r)}return n}let Pu=class extends Error{};Pu=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n},(Pu.prototype=Object.create(Error.prototype)).constructor=Pu,Pu.prototype.name="TransformError";const Iu=Object.create(null);class Ru{constructor(t,e,n){this.$anchor=t,this.$head=e,this.ranges=n||[new zu(t.min(e),t.max(e))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let t=this.ranges;for(let e=0;e=0;o--){let r=e<0?Ju(t.node(0),t.node(o),t.before(o+1),t.index(o),e,n):Ju(t.node(0),t.node(o),t.after(o+1),t.index(o)+1,e,n);if(r)return r}return null}static near(t,e=1){return this.findFrom(t,e)||this.findFrom(t,-e)||new qu(t.node(0))}static atStart(t){return Ju(t,t,0,0,1)||new qu(t)}static atEnd(t){return Ju(t,t,t.content.size,t.childCount,-1)||new qu(t)}static fromJSON(t,e){if(!e||!e.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=Iu[e.type];if(!n)throw new RangeError(`No selection type ${e.type} defined`);return n.fromJSON(t,e)}static jsonID(t,e){if(t in Iu)throw new RangeError("Duplicate use of selection JSON ID "+t);return Iu[t]=e,e.prototype.jsonID=t,e}getBookmark(){return Lu.between(this.$anchor,this.$head).getBookmark()}}Ru.prototype.visible=!0;class zu{constructor(t,e){this.$from=t,this.$to=e}}let ju=!1;function Fu(t){ju||t.parent.inlineContent||(ju=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class Lu extends Ru{constructor(t,e=t){Fu(t),Fu(e),super(t,e)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,e){let n=t.resolve(e.map(this.head));if(!n.parent.inlineContent)return Ru.near(n);let r=t.resolve(e.map(this.anchor));return new Lu(r.parent.inlineContent?r:n,n)}replace(t,e=sc.empty){if(super.replace(t,e),e==sc.empty){let e=this.$from.marksAcross(this.$to);e&&t.ensureMarks(e)}}eq(t){return t instanceof Lu&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new Bu(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,e){if("number"!=typeof e.anchor||"number"!=typeof e.head)throw new RangeError("Invalid input for TextSelection.fromJSON");return new Lu(t.resolve(e.anchor),t.resolve(e.head))}static create(t,e,n=e){let r=t.resolve(e);return new this(r,n==e?r:t.resolve(n))}static between(t,e,n){let r=t.pos-e.pos;if(n&&!r||(n=r>=0?1:-1),!e.parent.inlineContent){let t=Ru.findFrom(e,n,!0)||Ru.findFrom(e,-n,!0);if(!t)return Ru.near(e,n);e=t.$head}return t.parent.inlineContent||(0==r||(t=(Ru.findFrom(t,-n,!0)||Ru.findFrom(t,n,!0)).$anchor).posnew qu(t)};function Ju(t,e,n,r,o,i=!1){if(e.inlineContent)return Lu.create(t,n);for(let s=r-(o>0?0:1);o>0?s=0;s+=o){let r=e.child(s);if(r.isAtom){if(!i&&Vu.isSelectable(r))return Vu.create(t,n-(o<0?r.nodeSize:0))}else{let e=Ju(t,r,n+o,o<0?r.childCount:0,o,i);if(e)return e}n+=r.nodeSize*o}return null}function Ku(t,e,n){let r=t.steps.length-1;if(r{null==o&&(o=r)})),t.setSelection(Ru.near(t.doc.resolve(o),n)))}class Yu extends class{constructor(t){this.doc=t,this.steps=[],this.docs=[],this.mapping=new au}get before(){return this.docs.length?this.docs[0]:this.doc}step(t){let e=this.maybeStep(t);if(e.failed)throw new Pu(e.failed);return this}maybeStep(t){let e=t.apply(this.doc);return e.failed||this.addStep(t,e.doc),e}get docChanged(){return this.steps.length>0}addStep(t,e){this.docs.push(this.doc),this.steps.push(t),this.mapping.appendMap(t.getMap()),this.doc=e}replace(t,e=t,n=sc.empty){let r=ku(this.doc,t,e,n);return r&&this.step(r),this}replaceWith(t,e,n){return this.replace(t,e,new sc(tc.from(n),0,0))}delete(t,e){return this.replace(t,e,sc.empty)}insert(t,e){return this.replaceWith(t,t,e)}replaceRange(t,e,n){return function(t,e,n,r){if(!r.size)return t.deleteRange(e,n);let o=t.doc.resolve(e),i=t.doc.resolve(n);if(_u(o,i,r))return t.step(new pu(e,n,r));let s=Au(o,t.doc.resolve(n));0==s[s.length-1]&&s.pop();let a=-(o.depth+1);s.unshift(a);for(let h=o.depth,f=o.pos-1;h>0;h--,f--){let t=o.node(h).type.spec;if(t.defining||t.definingAsContext||t.isolating)break;s.indexOf(h)>-1?a=h:o.before(h)==f&&s.splice(1,0,-h)}let l=s.indexOf(a),c=[],u=r.openStart;for(let h=r.content,f=0;;f++){let t=h.firstChild;if(c.push(t),f==r.openStart)break;h=t.content}for(let h=u-1;h>=0;h--){let t=c[h].type,e=Eu(t);if(e&&o.node(l).type!=t)u=h;else if(e||!t.isTextblock)break}for(let h=r.openStart;h>=0;h--){let e=(h+u+1)%(r.openStart+1),a=c[e];if(a)for(let c=0;c=0&&(t.replace(e,n,r),!(t.steps.length>d));h--){let t=s[h];t<0||(e=o.before(t),n=i.after(t))}}(this,t,e,n),this}replaceRangeWith(t,e,n){return function(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let o=function(t,e,n){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),n))return e;if(0==r.parentOffset)for(let o=r.depth-1;o>=0;o--){let t=r.index(o);if(r.node(o).canReplaceWith(t,t,n))return r.before(o+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let o=r.depth-1;o>=0;o--){let t=r.indexAfter(o);if(r.node(o).canReplaceWith(t,t,n))return r.after(o+1);if(t0&&(n||r.node(e-1).canReplace(r.index(e-1),o.indexAfter(e-1))))return t.delete(r.before(e),o.after(e))}for(let s=1;s<=r.depth&&s<=o.depth;s++)if(e-r.start(s)==r.depth-s&&n>r.end(s)&&o.end(s)-n!=o.depth-s)return t.delete(r.before(s),n);t.delete(e,n)}(this,t,e),this}lift(t,e){return function(t,e,n){let{$from:r,$to:o,depth:i}=e,s=r.before(i+1),a=o.after(i+1),l=s,c=a,u=tc.empty,d=0;for(let p=i,m=!1;p>n;p--)m||r.index(p)>0?(m=!0,u=tc.from(r.node(p).copy(u)),d++):l--;let h=tc.empty,f=0;for(let p=i,m=!1;p>n;p--)m||o.after(p+1)=0;s--){if(r.size){let t=n[s].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=tc.from(n[s].type.create(n[s].attrs,r))}let o=e.start,i=e.end;t.step(new mu(o,i,o,i,new sc(r,0,0),n.length,!0))}(this,t,e),this}setBlockType(t,e=t,n,r=null){return function(t,e,n,r,o){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let i=t.steps.length;t.doc.nodesBetween(e,n,((e,n)=>{if(e.isTextblock&&!e.hasMarkup(r,o)&&function(t,e,n){let r=t.resolve(e),o=r.index();return r.parent.canReplaceWith(o,o+1,n)}(t.doc,t.mapping.slice(i).map(n),r)){t.clearIncompatible(t.mapping.slice(i).map(n,1),r);let s=t.mapping.slice(i),a=s.map(n,1),l=s.map(n+e.nodeSize,1);return t.step(new mu(a,l,a+1,l-1,new sc(tc.from(r.create(o,null,e.marks)),0,0),1,!0)),!1}}))}(this,t,e,n,r),this}setNodeMarkup(t,e,n=null,r=[]){return function(t,e,n,r,o){let i=t.doc.nodeAt(e);if(!i)throw new RangeError("No node at given position");n||(n=i.type);let s=n.create(r,null,o||i.marks);if(i.isLeaf)return t.replaceWith(e,e+i.nodeSize,s);if(!n.validContent(i.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new mu(e,e+i.nodeSize,e+1,e+i.nodeSize-1,new sc(tc.from(s),0,0),1,!0))}(this,t,e,n,r),this}split(t,e=1,n){return function(t,e,n=1,r){let o=t.doc.resolve(e),i=tc.empty,s=tc.empty;for(let a=o.depth,l=o.depth-n,c=n-1;a>l;a--,c--){i=tc.from(o.node(a).copy(i));let t=r&&r[c];s=tc.from(t?t.type.create(t.attrs,s):o.node(a).copy(s))}t.step(new pu(e,e,new sc(i.append(s),n,n),!0))}(this,t,e,n),this}addMark(t,e,n){return function(t,e,n,r){let o,i,s=[],a=[];t.doc.nodesBetween(e,n,((t,l,c)=>{if(!t.isInline)return;let u=t.marks;if(!r.isInSet(u)&&c.type.allowsMarkType(r.type)){let c=Math.max(l,e),d=Math.min(l+t.nodeSize,n),h=r.addToSet(u);for(let t=0;tt.step(e))),a.forEach((e=>t.step(e)))}(this,t,e,n),this}removeMark(t,e,n){return function(t,e,n,r){let o=[],i=0;t.doc.nodesBetween(e,n,((t,s)=>{if(!t.isInline)return;i++;let a=null;if(r instanceof Bc){let e,n=t.marks;for(;e=r.isInSet(n);)(a||(a=[])).push(e),n=e.removeFromSet(n)}else r?r.isInSet(t.marks)&&(a=[r]):a=t.marks;if(a&&a.length){let r=Math.min(s+t.nodeSize,n);for(let t=0;tt.step(new fu(e.from,e.to,e.style))))}(this,t,e,n),this}clearIncompatible(t,e,n){return function(t,e,n,r=n.contentMatch){let o=t.doc.nodeAt(e),i=[],s=e+1;for(let a=0;a=0;a--)t.step(i[a])}(this,t,e,n),this}}{constructor(t){super(t.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=t.selection,this.storedMarks=t.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(t){return this.storedMarks=t,this.updated|=2,this}ensureMarks(t){return oc.sameSet(this.storedMarks||this.selection.$from.marks(),t)||this.setStoredMarks(t),this}addStoredMark(t){return this.ensureMarks(t.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(t){return this.ensureMarks(t.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(2&this.updated)>0}addStep(t,e){super.addStep(t,e),this.updated=-3&this.updated,this.storedMarks=null}setTime(t){return this.time=t,this}replaceSelection(t){return this.selection.replace(this,t),this}replaceSelectionWith(t,e=!0){let n=this.selection;return e&&(t=t.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||oc.none))),n.replaceWith(this,t),this}deleteSelection(){return this.selection.replace(this),this}insertText(t,e,n){let r=this.doc.type.schema;if(null==e)return t?this.replaceSelectionWith(r.text(t),!0):this.deleteSelection();{if(null==n&&(n=e),n=null==n?e:n,!t)return this.deleteRange(e,n);let o=this.storedMarks;if(!o){let t=this.doc.resolve(e);o=n==e?t.marks():t.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(e,n,r.text(t,o)),this.selection.empty||this.setSelection(Ru.near(this.selection.$to)),this}}setMeta(t,e){return this.meta["string"==typeof t?t:t.key]=e,this}getMeta(t){return this.meta["string"==typeof t?t:t.key]}get isGeneric(){for(let t in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=4,this}get scrolledIntoView(){return(4&this.updated)>0}}function Uu(t,e){return e&&t?t.bind(e):t}class Gu{constructor(t,e,n){this.name=t,this.init=Uu(e.init,n),this.apply=Uu(e.apply,n)}}const Xu=[new Gu("doc",{init:t=>t.doc||t.schema.topNodeType.createAndFill(),apply:t=>t.doc}),new Gu("selection",{init:(t,e)=>t.selection||Ru.atStart(e.doc),apply:t=>t.selection}),new Gu("storedMarks",{init:t=>t.storedMarks||null,apply:(t,e,n,r)=>r.selection.$cursor?t.storedMarks:null}),new Gu("scrollToSelection",{init:()=>0,apply:(t,e)=>t.scrolledIntoView?e+1:e})];class Zu{constructor(t,e){this.schema=t,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Xu.slice(),e&&e.forEach((t=>{if(this.pluginsByKey[t.key])throw new RangeError("Adding different instances of a keyed plugin ("+t.key+")");this.plugins.push(t),this.pluginsByKey[t.key]=t,t.spec.state&&this.fields.push(new Gu(t.key,t.spec.state,t))}))}}class Qu{constructor(t){this.config=t}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(t){return this.applyTransaction(t).state}filterTransaction(t,e=-1){for(let n=0;nt.toJSON()))),t&&"object"==typeof t)for(let n in t){if("doc"==n||"selection"==n)throw new RangeError("The JSON fields `doc` and `selection` are reserved");let r=t[n],o=r.spec.state;o&&o.toJSON&&(e[n]=o.toJSON.call(r,this[r.key]))}return e}static fromJSON(t,e,n){if(!e)throw new RangeError("Invalid input for EditorState.fromJSON");if(!t.schema)throw new RangeError("Required config field 'schema' missing");let r=new Zu(t.schema,t.plugins),o=new Qu(r);return r.fields.forEach((r=>{if("doc"==r.name)o.doc=_c.fromJSON(t.schema,e.doc);else if("selection"==r.name)o.selection=Ru.fromJSON(o.doc,e.selection);else if("storedMarks"==r.name)e.storedMarks&&(o.storedMarks=e.storedMarks.map(t.schema.markFromJSON));else{if(n)for(let i in n){let s=n[i],a=s.spec.state;if(s.key==r.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(e,i))return void(o[r.name]=a.fromJSON.call(s,t,e[i],o))}o[r.name]=r.init(t,o)}})),o}}function td(t,e,n){for(let r in t){let o=t[r];o instanceof Function?o=o.bind(e):"handleDOMEvents"==r&&(o=td(o,e,{})),n[r]=o}return n}class ed{constructor(t){this.spec=t,this.props={},t.props&&td(t.props,this,this.props),this.key=t.key?t.key.key:rd("plugin")}getState(t){return t[this.key]}}const nd=Object.create(null);function rd(t){return t in nd?t+"$"+ ++nd[t]:(nd[t]=0,t+"$")}class od{constructor(t="key"){this.key=rd(t)}get(t){return t.config.pluginsByKey[this.key]}getState(t){return t[this.key]}}const id="undefined"!=typeof navigator?navigator:null,sd="undefined"!=typeof document?document:null,ad=id&&id.userAgent||"",ld=/Edge\/(\d+)/.exec(ad),cd=/MSIE \d/.exec(ad),ud=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ad),dd=!!(cd||ud||ld),hd=cd?document.documentMode:ud?+ud[1]:ld?+ld[1]:0,fd=!dd&&/gecko\/(\d+)/i.test(ad);fd&&(/Firefox\/(\d+)/.exec(ad)||[0,0])[1];const pd=!dd&&/Chrome\/(\d+)/.exec(ad),md=!!pd,gd=pd?+pd[1]:0,vd=!dd&&!!id&&/Apple Computer/.test(id.vendor),yd=vd&&(/Mobile\/\w+/.test(ad)||!!id&&id.maxTouchPoints>2),bd=yd||!!id&&/Mac/.test(id.platform),wd=/Android \d/.test(ad),xd=!!sd&&"webkitFontSmoothing"in sd.documentElement.style,Sd=xd?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,kd=function(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e},_d=function(t){let e=t.assignedSlot||t.parentNode;return e&&11==e.nodeType?e.host:e};let Od=null;const Cd=function(t,e,n){let r=Od||(Od=document.createRange());return r.setEnd(t,null==n?t.nodeValue.length:n),r.setStart(t,e||0),r},Md=function(t,e,n,r){return n&&(Td(t,e,n,r,-1)||Td(t,e,n,r,1))},Dd=/^(img|br|input|textarea|hr)$/i;function Td(t,e,n,r,o){for(;;){if(t==n&&e==r)return!0;if(e==(o<0?0:$d(t))){let n=t.parentNode;if(!n||1!=n.nodeType||Ed(t)||Dd.test(t.nodeName)||"false"==t.contentEditable)return!1;e=kd(t)+(o<0?0:1),t=n}else{if(1!=t.nodeType)return!1;if("false"==(t=t.childNodes[e+(o<0?-1:0)]).contentEditable)return!1;e=o<0?$d(t):0}}}function $d(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function Ed(t){let e;for(let n=t;n&&!(e=n.pmViewDesc);n=n.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}const Nd=function(t){let e=t.isCollapsed;return e&&md&&t.rangeCount&&!t.getRangeAt(0).collapsed&&(e=!1),e};function Ad(t,e){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=t,n.key=n.code=e,n}function Pd(t){return{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function Id(t,e){return"number"==typeof t?t:t[e]}function Rd(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*r}}function zd(t,e,n){let r=t.someProp("scrollThreshold")||0,o=t.someProp("scrollMargin")||5,i=t.dom.ownerDocument;for(let s=n||t.dom;s;s=_d(s)){if(1!=s.nodeType)continue;let t=s,n=t==i.body,a=n?Pd(i):Rd(t),l=0,c=0;if(e.topa.bottom-Id(r,"bottom")&&(c=e.bottom-a.bottom+Id(o,"bottom")),e.lefta.right-Id(r,"right")&&(l=e.right-a.right+Id(o,"right")),l||c)if(n)i.defaultView.scrollBy(l,c);else{let n=t.scrollLeft,r=t.scrollTop;c&&(t.scrollTop+=c),l&&(t.scrollLeft+=l);let o=t.scrollLeft-n,i=t.scrollTop-r;e={left:e.left-o,top:e.top-i,right:e.right-o,bottom:e.bottom-i}}if(n)break}}function jd(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=_d(r));return e}function Fd(t,e){for(let n=0;n=a){s=Math.max(d.bottom,s),a=Math.min(d.top,a);let t=d.left>e.left?d.left-e.left:d.right=(d.left+d.right)/2?1:0));continue}}!n&&(e.left>=d.right&&e.top>=d.top||e.left>=d.left&&e.top>=d.bottom)&&(i=c+1)}}return n&&3==n.nodeType?function(t,e){let n=t.nodeValue.length,r=document.createRange();for(let o=0;o=(n.left+n.right)/2?1:0)}}return{node:t,offset:0}}(n,r):!n||o&&1==n.nodeType?{node:t,offset:i}:Bd(n,r)}function Vd(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function Wd(t,e,n){let r=t.childNodes.length;if(r&&n.tope.top&&o++}n==t.dom&&o==n.childNodes.length-1&&1==n.lastChild.nodeType&&e.top>n.lastChild.getBoundingClientRect().bottom?i=t.state.doc.content.size:0!=o&&1==n.nodeType&&"BR"==n.childNodes[o-1].nodeName||(i=function(t,e,n,r){let o=-1;for(let i=e;i!=t.dom;){let e=t.docView.nearestDesc(i,!0);if(!e)return null;if(e.node.isBlock&&e.parent){let t=e.dom.getBoundingClientRect();if(t.left>r.left||t.top>r.top)o=e.posBefore;else{if(!(t.right-1?o:t.docView.posFromDOM(e,n,1)}(t,n,o,e))}null==i&&(i=function(t,e,n){let{node:r,offset:o}=Bd(e,n),i=-1;if(1==r.nodeType&&!r.firstChild){let t=r.getBoundingClientRect();i=t.left!=t.right&&n.left>(t.left+t.right)/2?1:-1}return t.docView.posFromDOM(r,o,i)}(t,s,e));let a=t.docView.nearestDesc(s,!0);return{pos:i,inside:a?a.posAtStart-a.border:-1}}function Hd(t,e){let n=t.getClientRects();return n.length?n[e<0?0:n.length-1]:t.getBoundingClientRect()}const Jd=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Kd(t,e,n){let{node:r,offset:o,atom:i}=t.docView.domFromPos(e,n<0?-1:1),s=xd||fd;if(3==r.nodeType){if(!s||!Jd.test(r.nodeValue)&&(n<0?o:o!=r.nodeValue.length)){let t=o,e=o,i=n<0?1:-1;return n<0&&!o?(e++,i=-1):n>=0&&o==r.nodeValue.length?(t--,i=1):n<0?t--:e++,Yd(Hd(Cd(r,t,e),i),i<0)}{let t=Hd(Cd(r,o,o),n);if(fd&&o&&/\s/.test(r.nodeValue[o-1])&&o=0)}if(null==i&&o&&(n<0||o==$d(r))){let t=r.childNodes[o-1],e=3==t.nodeType?Cd(t,$d(t)-(s?0:1)):1!=t.nodeType||"BR"==t.nodeName&&t.nextSibling?null:t;if(e)return Yd(Hd(e,1),!1)}if(null==i&&o<$d(r)){let t=r.childNodes[o];for(;t.pmViewDesc&&t.pmViewDesc.ignoreForCoords;)t=t.nextSibling;let e=t?3==t.nodeType?Cd(t,0,s?0:1):1==t.nodeType?t:null:null;if(e)return Yd(Hd(e,-1),!0)}return Yd(Hd(3==r.nodeType?Cd(r):r,-n),n>=0)}function Yd(t,e){if(0==t.width)return t;let n=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:n,right:n}}function Ud(t,e){if(0==t.height)return t;let n=e?t.top:t.bottom;return{top:n,bottom:n,left:t.left,right:t.right}}function Gd(t,e,n){let r=t.state,o=t.root.activeElement;r!=e&&t.updateState(e),o!=t.dom&&t.focus();try{return n()}finally{r!=e&&t.updateState(r),o!=t.dom&&o&&o.focus()}}const Xd=/[\u0590-\u08ac]/;let Zd=null,Qd=null,th=!1;function eh(t,e,n){return Zd==e&&Qd==n?th:(Zd=e,Qd=n,th="up"==n||"down"==n?function(t,e,n){let r=e.selection,o="up"==n?r.$from:r.$to;return Gd(t,e,(()=>{let{node:e}=t.docView.domFromPos(o.pos,"up"==n?-1:1);for(;;){let n=t.docView.nearestDesc(e,!0);if(!n)break;if(n.node.isBlock){e=n.dom;break}e=n.dom.parentNode}let r=Kd(t,o.pos,1);for(let t=e.firstChild;t;t=t.nextSibling){let e;if(1==t.nodeType)e=t.getClientRects();else{if(3!=t.nodeType)continue;e=Cd(t,0,t.nodeValue.length).getClientRects()}for(let t=0;to.top+1&&("up"==n?r.top-o.top>2*(o.bottom-r.top):o.bottom-r.bottom>2*(r.bottom-o.top)))return!1}}return!0}))}(t,e,n):function(t,e,n){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let o=r.parentOffset,i=!o,s=o==r.parent.content.size,a=t.domSelection();return Xd.test(r.parent.textContent)&&a.modify?Gd(t,e,(()=>{let e=a.getRangeAt(0),o=a.focusNode,i=a.focusOffset,s=a.caretBidiLevel;a.modify("move",n,"character");let l=!(r.depth?t.docView.domAfterPos(r.before()):t.dom).contains(1==a.focusNode.nodeType?a.focusNode:a.focusNode.parentNode)||o==a.focusNode&&i==a.focusOffset;return a.removeAllRanges(),a.addRange(e),null!=s&&(a.caretBidiLevel=s),l})):"left"==n||"backward"==n?i:s}(t,e,n))}class nh{constructor(t,e,n,r){this.parent=t,this.children=e,this.dom=n,this.contentDOM=r,this.dirty=0,n.pmViewDesc=this}matchesWidget(t){return!1}matchesMark(t){return!1}matchesNode(t,e,n){return!1}matchesHack(t){return!1}parseRule(){return null}stopEvent(t){return!1}get size(){let t=0;for(let e=0;ekd(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=2&t.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==e)for(let e=t;;e=e.parentNode){if(e==this.dom){r=!1;break}if(e.previousSibling)break}if(null==r&&e==t.childNodes.length)for(let e=t;;e=e.parentNode){if(e==this.dom){r=!0;break}if(e.nextSibling)break}}return(null==r?n>0:r)?this.posAtEnd:this.posAtStart}nearestDesc(t,e=!1){for(let n=!0,r=t;r;r=r.parentNode){let o,i=this.getDesc(r);if(i&&(!e||i.node)){if(!n||!(o=i.nodeDOM)||(1==o.nodeType?o.contains(1==t.nodeType?t:t.parentNode):o==t))return i;n=!1}}}getDesc(t){let e=t.pmViewDesc;for(let n=e;n;n=n.parent)if(n==this)return e}posFromDOM(t,e,n){for(let r=t;r;r=r.parentNode){let o=this.getDesc(r);if(o)return o.localPosFromDOM(t,e,n)}return-1}descAt(t){for(let e=0,n=0;et||e instanceof ch){o=t-i;break}i=n}if(o)return this.children[r].domFromPos(o-this.children[r].border,e);for(;r&&!(n=this.children[r-1]).size&&n instanceof rh&&n.side>=0;r--);if(e<=0){let t,n=!0;for(;t=r?this.children[r-1]:null,t&&t.dom.parentNode!=this.contentDOM;r--,n=!1);return t&&e&&n&&!t.border&&!t.domAtom?t.domFromPos(t.size,e):{node:this.contentDOM,offset:t?kd(t.dom)+1:0}}{let t,n=!0;for(;t=r=o&&e<=a-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(t,e,o);t=i;for(let e=s;e>0;e--){let n=this.children[e-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=kd(n.dom)+1;break}t-=n.size}-1==r&&(r=0)}if(r>-1&&(a>e||s==this.children.length-1)){e=a;for(let t=s+1;tf&&ie){let t=s;s=a,a=t}let n=document.createRange();n.setEnd(a.node,a.offset),n.setStart(s.node,s.offset),l.removeAllRanges(),l.addRange(n)}}ignoreMutation(t){return!this.contentDOM&&"selection"!=t.type}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(t,e){for(let n=0,r=0;r=n:tn){let r=n+o.border,s=i-o.border;if(t>=r&&e<=s)return this.dirty=t==n||e==i?2:1,void(t!=r||e!=s||!o.contentLost&&o.dom.parentNode==this.contentDOM?o.markDirty(t-r,e-r):o.dirty=3);o.dirty=o.dom!=o.contentDOM||o.dom.parentNode!=this.contentDOM||o.children.length?3:2}n=i}this.dirty=2}markParentsDirty(){let t=1;for(let e=this.parent;e;e=e.parent,t++){let n=1==t?2:1;e.dirtyo?o.parent?o.parent.posBeforeChild(o):void 0:r))),!e.type.spec.raw){if(1!=i.nodeType){let t=document.createElement("span");t.appendChild(i),i=t}i.contentEditable="false",i.classList.add("ProseMirror-widget")}super(t,[],i,null),this.widget=e,this.widget=e,o=this}matchesWidget(t){return 0==this.dirty&&t.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(t){let e=this.widget.spec.stopEvent;return!!e&&e(t)}ignoreMutation(t){return"selection"!=t.type||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}}class oh extends nh{constructor(t,e,n,r){super(t,[],e,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(t,e){return t!=this.textDOM?this.posAtStart+(e?this.size:0):this.posAtStart+e}domFromPos(t){return{node:this.textDOM,offset:t}}ignoreMutation(t){return"characterData"===t.type&&t.target.nodeValue==t.oldValue}}class ih extends nh{constructor(t,e,n,r){super(t,[],n,r),this.mark=e}static create(t,e,n,r){let o=r.nodeViews[e.type.name],i=o&&o(e,r,n);return i&&i.dom||(i=tu.renderSpec(document,e.type.spec.toDOM(e,n))),new ih(t,e,i.dom,i.contentDOM||i.dom)}parseRule(){return 3&this.dirty||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM||void 0}}matchesMark(t){return 3!=this.dirty&&this.mark.eq(t)}markDirty(t,e){if(super.markDirty(t,e),0!=this.dirty){let t=this.parent;for(;!t.node;)t=t.parent;t.dirty0&&(o=Sh(o,0,t,n));for(let s=0;ss?s.parent?s.parent.posBeforeChild(s):void 0:i),n,r),c=l&&l.dom,u=l&&l.contentDOM;if(e.isText)if(c){if(3!=c.nodeType)throw new RangeError("Text must be rendered as a DOM text node")}else c=document.createTextNode(e.text);else c||({dom:c,contentDOM:u}=tu.renderSpec(document,e.type.spec.toDOM(e)));u||e.isText||"BR"==c.nodeName||(c.hasAttribute("contenteditable")||(c.contentEditable="false"),e.type.spec.draggable&&(c.draggable=!0));let d=c;return c=vh(c,n,e),l?s=new uh(t,e,n,r,c,u||null,d,l,o,i+1):e.isText?new lh(t,e,n,r,c,d,o):new sh(t,e,n,r,c,u||null,d,o,i+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let t={node:this.node.type.name,attrs:this.node.attrs};if("pre"==this.node.type.whitespace&&(t.preserveWhitespace="full"),this.contentDOM)if(this.contentLost){for(let e=this.children.length-1;e>=0;e--){let n=this.children[e];if(this.dom.contains(n.dom.parentNode)){t.contentElement=n.dom.parentNode;break}}t.contentElement||(t.getContent=()=>tc.empty)}else t.contentElement=this.contentDOM;else t.getContent=()=>this.node.content;return t}matchesNode(t,e,n){return 0==this.dirty&&t.eq(this.node)&&yh(e,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(t,e){let n=this.node.inlineContent,r=e,o=t.composing?this.localCompositionInfo(t,e):null,i=o&&o.pos>-1?o:null,s=o&&o.pos<0,a=new wh(this,i&&i.node);!function(t,e,n,r){let o=e.locals(t),i=0;if(0==o.length){for(let n=0;ni;)a.push(o[s++]);let h=i+u.nodeSize;if(u.isText){let t=h;s!t.inline)):a.slice(),e.forChild(i,u),d),i=h}}(this.node,this.innerDeco,((e,o,i)=>{e.spec.marks?a.syncToMarks(e.spec.marks,n,t):e.type.side>=0&&!i&&a.syncToMarks(o==this.node.childCount?oc.none:this.node.child(o).marks,n,t),a.placeWidget(e,t,r)}),((e,i,l,c)=>{let u;a.syncToMarks(e.marks,n,t),a.findNodeMatch(e,i,l,c)||s&&t.state.selection.from>r&&t.state.selection.to-1&&a.updateNodeAt(e,i,l,u,t)||a.updateNextNode(e,i,l,t,c)||a.addNode(e,i,l,t,r),r+=e.nodeSize})),a.syncToMarks([],n,t),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||2==this.dirty)&&(i&&this.protectLocalComposition(t,i),dh(this.contentDOM,this.children,t),yd&&function(t){if("UL"==t.nodeName||"OL"==t.nodeName){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t).listStyle,t.style.cssText=e}}(this.dom))}localCompositionInfo(t,e){let{from:n,to:r}=t.state.selection;if(!(t.state.selection instanceof Lu)||ne+this.node.content.size)return null;let o=t.domSelection(),i=function(t,e){for(;;){if(3==t.nodeType)return t;if(1==t.nodeType&&e>0){if(t.childNodes.length>e&&3==t.childNodes[e].nodeType)return t.childNodes[e];e=$d(t=t.childNodes[e-1])}else{if(!(1==t.nodeType&&e=n){let t=a=0&&t+e.length+a>=n)return a+t;if(n==r&&l.length>=r+e.length-a&&l.slice(r-a,r-a+e.length)==e)return r}}return-1}(this.node.content,t,n-e,r-e);return o<0?null:{node:i,pos:o,text:t}}return{node:i,pos:-1,text:""}}protectLocalComposition(t,{node:e,pos:n,text:r}){if(this.getDesc(e))return;let o=e;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let i=new oh(this,o,e,r);t.input.compositionNodes.push(i),this.children=Sh(this.children,n,n+r.length,t,i)}update(t,e,n,r){return!(3==this.dirty||!t.sameMarkup(this.node))&&(this.updateInner(t,e,n,r),!0)}updateInner(t,e,n,r){this.updateOuterDeco(e),this.node=t,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=0}updateOuterDeco(t){if(yh(t,this.outerDeco))return;let e=1!=this.nodeDOM.nodeType,n=this.dom;this.dom=mh(this.dom,this.nodeDOM,ph(this.outerDeco,this.node,e),ph(t,this.node,e)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=t}selectNode(){1==this.nodeDOM.nodeType&&this.nodeDOM.classList.add("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||(this.dom.draggable=!0)}deselectNode(){1==this.nodeDOM.nodeType&&this.nodeDOM.classList.remove("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||this.dom.removeAttribute("draggable")}get domAtom(){return this.node.isAtom}}function ah(t,e,n,r,o){return vh(r,e,t),new sh(void 0,t,e,n,r,r,r,o,0)}class lh extends sh{constructor(t,e,n,r,o,i,s){super(t,e,n,r,o,null,i,s,0)}parseRule(){let t=this.nodeDOM.parentNode;for(;t&&t!=this.dom&&!t.pmIsDeco;)t=t.parentNode;return{skip:t||!0}}update(t,e,n,r){return!(3==this.dirty||0!=this.dirty&&!this.inParent()||!t.sameMarkup(this.node))&&(this.updateOuterDeco(e),0==this.dirty&&t.text==this.node.text||t.text==this.nodeDOM.nodeValue||(this.nodeDOM.nodeValue=t.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=t,this.dirty=0,!0)}inParent(){let t=this.parent.contentDOM;for(let e=this.nodeDOM;e;e=e.parentNode)if(e==t)return!0;return!1}domFromPos(t){return{node:this.nodeDOM,offset:t}}localPosFromDOM(t,e,n){return t==this.nodeDOM?this.posAtStart+Math.min(e,this.node.text.length):super.localPosFromDOM(t,e,n)}ignoreMutation(t){return"characterData"!=t.type&&"selection"!=t.type}slice(t,e,n){let r=this.node.cut(t,e),o=document.createTextNode(r.text);return new lh(this.parent,r,this.outerDeco,this.innerDeco,o,o,n)}markDirty(t,e){super.markDirty(t,e),this.dom==this.nodeDOM||0!=t&&e!=this.nodeDOM.nodeValue.length||(this.dirty=3)}get domAtom(){return!1}}class ch extends nh{parseRule(){return{ignore:!0}}matchesHack(t){return 0==this.dirty&&this.dom.nodeName==t}get domAtom(){return!0}get ignoreForCoords(){return"IMG"==this.dom.nodeName}}class uh extends sh{constructor(t,e,n,r,o,i,s,a,l,c){super(t,e,n,r,o,i,s,l,c),this.spec=a}update(t,e,n,r){if(3==this.dirty)return!1;if(this.spec.update){let o=this.spec.update(t,e,n);return o&&this.updateInner(t,e,n,r),o}return!(!this.contentDOM&&!t.isLeaf)&&super.update(t,e,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(t,e,n,r){this.spec.setSelection?this.spec.setSelection(t,e,n):super.setSelection(t,e,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(t){return!!this.spec.stopEvent&&this.spec.stopEvent(t)}ignoreMutation(t){return this.spec.ignoreMutation?this.spec.ignoreMutation(t):super.ignoreMutation(t)}}function dh(t,e,n){let r=t.firstChild,o=!1;for(let i=0;i0;){let a;for(;;)if(r){let t=n.children[r-1];if(!(t instanceof ih)){a=t,r--;break}n=t,r=t.children.length}else{if(n==e)break t;r=n.parent.children.indexOf(n),n=n.parent}let l=a.node;if(l){if(l!=t.child(o-1))break;--o,i.set(a,o),s.push(a)}}return{index:o,matched:i,matches:s.reverse()}}(t.node.content,t)}destroyBetween(t,e){if(t!=e){for(let n=t;n>1,i=Math.min(o,t.length);for(;r-1)r>this.index&&(this.changed=!0,this.destroyBetween(this.index,r)),this.top=this.top.children[this.index];else{let r=ih.create(this.top,t[o],e,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,o++}}findNodeMatch(t,e,n,r){let o,i=-1;if(r>=this.preMatch.index&&(o=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&o.matchesNode(t,e,n))i=this.top.children.indexOf(o,this.index);else for(let s=this.index,a=Math.min(this.top.children.length,s+5);s=n||u<=e?i.push(l):(cn&&i.push(l.slice(n-c,l.size,r)))}return i}function kh(t,e=null){let n=t.domSelection(),r=t.state.doc;if(!n.focusNode)return null;let o=t.docView.nearestDesc(n.focusNode),i=o&&0==o.size,s=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let a,l,c=r.resolve(s);if(Nd(n)){for(a=c;o&&!o.node;)o=o.parent;let t=o.node;if(o&&t.isAtom&&Vu.isSelectable(t)&&o.parent&&(!t.isInline||!function(t,e,n){for(let r=0==e,o=e==$d(t);r||o;){if(t==n)return!0;let e=kd(t);if(!(t=t.parentNode))return!1;r=r&&0==e,o=o&&e==$d(t)}}(n.focusNode,n.focusOffset,o.dom))){let t=o.posBefore;l=new Vu(s==t?c:r.resolve(t))}}else{let e=t.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(e<0)return null;a=r.resolve(e)}if(!l){l=Nh(t,a,c,"pointer"==e||t.state.selection.head{n.anchorNode==r&&n.anchorOffset==o||(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout((()=>{_h(t)&&!t.state.selection.visible||t.dom.classList.remove("ProseMirror-hideselection")}),20))})}(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}}const Ch=vd||md&&gd<63;function Mh(t,e){let{node:n,offset:r}=t.docView.domFromPos(e,0),o=rr(t,e,n)))||Lu.between(e,n,r)}function Ah(t){return(!t.editable||t.root.activeElement==t.dom)&&Ph(t)}function Ph(t){let e=t.domSelection();if(!e.anchorNode)return!1;try{return t.dom.contains(3==e.anchorNode.nodeType?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(3==e.focusNode.nodeType?e.focusNode.parentNode:e.focusNode))}catch(n){return!1}}function Ih(t,e){let{$anchor:n,$head:r}=t.selection,o=e>0?n.max(r):n.min(r),i=o.parent.inlineContent?o.depth?t.doc.resolve(e>0?o.after():o.before()):null:o;return i&&Ru.findFrom(i,e)}function Rh(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function zh(t,e,n){let r=t.state.selection;if(!(r instanceof Lu)){if(r instanceof Vu&&r.node.isInline)return Rh(t,new Lu(e>0?r.$to:r.$from));{let n=Ih(t.state,e);return!!n&&Rh(t,n)}}if(!r.empty||n.indexOf("s")>-1)return!1;if(t.endOfTextblock(e>0?"right":"left")){let n=Ih(t.state,e);return!!(n&&n instanceof Vu)&&Rh(t,n)}if(!(bd&&n.indexOf("m")>-1)){let n,o=r.$head,i=o.textOffset?null:e<0?o.nodeBefore:o.nodeAfter;if(!i||i.isText)return!1;let s=e<0?o.pos-i.nodeSize:o.pos;return!!(i.isAtom||(n=t.docView.descAt(s))&&!n.contentDOM)&&(Vu.isSelectable(i)?Rh(t,new Vu(e<0?t.state.doc.resolve(o.pos-i.nodeSize):o)):!!xd&&Rh(t,new Lu(t.state.doc.resolve(e<0?s:s+i.nodeSize))))}}function jh(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function Fh(t){let e=t.pmViewDesc;return e&&0==e.size&&(t.nextSibling||"BR"!=t.nodeName)}function Lh(t){let e=t.domSelection(),n=e.focusNode,r=e.focusOffset;if(!n)return;let o,i,s=!1;for(fd&&1==n.nodeType&&r0){if(1!=n.nodeType)break;{let t=n.childNodes[r-1];if(Fh(t))o=n,i=--r;else{if(3!=t.nodeType)break;n=t,r=n.nodeValue.length}}}else{if(Vh(n))break;{let e=n.previousSibling;for(;e&&Fh(e);)o=n.parentNode,i=kd(e),e=e.previousSibling;if(e)n=e,r=jh(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}s?Wh(t,e,n,r):o&&Wh(t,e,o,i)}function Bh(t){let e=t.domSelection(),n=e.focusNode,r=e.focusOffset;if(!n)return;let o,i,s=jh(n);for(;;)if(r{t.state==o&&Oh(t)}),50)}function qh(t,e,n){let r=t.state.selection;if(r instanceof Lu&&!r.empty||n.indexOf("s")>-1)return!1;if(bd&&n.indexOf("m")>-1)return!1;let{$from:o,$to:i}=r;if(!o.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let n=Ih(t.state,e);if(n&&n instanceof Vu)return Rh(t,n)}if(!o.parent.inlineContent){let n=e<0?o:i,s=r instanceof qu?Ru.near(n,e):Ru.findFrom(n,e);return!!s&&Rh(t,s)}return!1}function Hh(t,e){if(!(t.state.selection instanceof Lu))return!0;let{$head:n,$anchor:r,empty:o}=t.state.selection;if(!n.sameParent(r))return!0;if(!o)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let i=!n.textOffset&&(e<0?n.nodeBefore:n.nodeAfter);if(i&&!i.isText){let r=t.state.tr;return e<0?r.delete(n.pos-i.nodeSize,n.pos):r.delete(n.pos,n.pos+i.nodeSize),t.dispatch(r),!0}return!1}function Jh(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function Kh(t,e){let n=e.keyCode,r=function(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}(e);return 8==n||bd&&72==n&&"c"==r?Hh(t,-1)||Lh(t):46==n||bd&&68==n&&"c"==r?Hh(t,1)||Bh(t):13==n||27==n||(37==n||bd&&66==n&&"c"==r?zh(t,-1,r)||Lh(t):39==n||bd&&70==n&&"c"==r?zh(t,1,r)||Bh(t):38==n||bd&&80==n&&"c"==r?qh(t,-1,r)||Lh(t):40==n||bd&&78==n&&"c"==r?function(t){if(!vd||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelection();if(e&&1==e.nodeType&&0==n&&e.firstChild&&"false"==e.firstChild.contentEditable){let n=e.firstChild;Jh(t,n,"true"),setTimeout((()=>Jh(t,n,"false")),20)}return!1}(t)||qh(t,1,r)||Bh(t):r==(bd?"m":"c")&&(66==n||73==n||89==n||90==n))}function Yh(t,e){let n=[],{content:r,openStart:o,openEnd:i}=e;for(;o>1&&i>1&&1==r.childCount&&1==r.firstChild.childCount;){o--,i--;let t=r.firstChild;n.push(t.type.name,t.attrs!=t.type.defaultAttrs?t.attrs:null),r=t.content}let s=t.someProp("clipboardSerializer")||tu.fromSchema(t.state.schema),a=of(),l=a.createElement("div");l.appendChild(s.serializeFragment(r,{document:a}));let c,u=l.firstChild,d=0;for(;u&&1==u.nodeType&&(c=nf[u.nodeName.toLowerCase()]);){for(let t=c.length-1;t>=0;t--){let e=a.createElement(c[t]);for(;l.firstChild;)e.appendChild(l.firstChild);l.appendChild(e),d++}u=l.firstChild}return u&&1==u.nodeType&&u.setAttribute("data-pm-slice",`${o} ${i}${d?` -${d}`:""} ${JSON.stringify(n)}`),{dom:l,text:t.someProp("clipboardTextSerializer",(t=>t(e)))||e.content.textBetween(0,e.content.size,"\n\n")}}function Uh(t,e,n,r,o){let i,s,a=o.parent.type.spec.code;if(!n&&!e)return null;let l=e&&(r||a||!n);if(l){if(t.someProp("transformPastedText",(t=>{e=t(e,a||r)})),a)return e?new sc(tc.from(t.state.schema.text(e.replace(/\r\n?/g,"\n"))),0,0):sc.empty;let n=t.someProp("clipboardTextParser",(t=>t(e,o,r)));if(n)s=n;else{let n=o.marks(),{schema:r}=t.state,s=tu.fromSchema(r);i=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach((t=>{let e=i.appendChild(document.createElement("p"));t&&e.appendChild(s.serializeNode(r.text(t,n)))}))}}else t.someProp("transformPastedHTML",(t=>{n=t(n)})),i=function(t){let e=/^(\s*]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n,r=of().createElement("div"),o=/<([a-z][^>\s]+)/i.exec(t);(n=o&&nf[o[1].toLowerCase()])&&(t=n.map((t=>"<"+t+">")).join("")+t+n.map((t=>"")).reverse().join(""));if(r.innerHTML=t,n)for(let i=0;i0&&i.firstChild;d--)i=i.firstChild;if(!s){let e=t.someProp("clipboardParser")||t.someProp("domParser")||qc.fromSchema(t.state.schema);s=e.parseSlice(i,{preserveWhitespace:!(!l&&!u),context:o,ruleFromNode:t=>"BR"!=t.nodeName||t.nextSibling||!t.parentNode||Gh.test(t.parentNode.nodeName)?null:{ignore:!0}})}if(u)s=function(t,e){if(!t.size)return t;let n,r=t.content.firstChild.type.schema;try{n=JSON.parse(e)}catch(jy){return t}let{content:o,openStart:i,openEnd:s}=t;for(let a=n.length-2;a>=0;a-=2){let t=r.nodes[n[a]];if(!t||t.hasRequiredAttrs())break;o=tc.from(t.create(n[a+1],o)),i++,s++}return new sc(o,i,s)}(ef(s,+u[1],+u[2]),u[4]);else if(s=sc.maxOpen(function(t,e){if(t.childCount<2)return t;for(let n=e.depth;n>=0;n--){let r,o=e.node(n).contentMatchAt(e.index(n)),i=[];if(t.forEach((t=>{if(!i)return;let e,n=o.findWrapping(t.type);if(!n)return i=null;if(e=i.length&&r.length&&Zh(n,r,t,i[i.length-1],0))i[i.length-1]=e;else{i.length&&(i[i.length-1]=Qh(i[i.length-1],r.length));let e=Xh(t,n);i.push(e),o=o.matchType(e.type),r=n}})),i)return tc.from(i)}return t}(s.content,o),!0),s.openStart||s.openEnd){let t=0,e=0;for(let n=s.content.firstChild;t{s=t(s)})),s}const Gh=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function Xh(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,tc.from(t));return t}function Zh(t,e,n,r,o){if(o=n&&(a=e<0?s.contentMatchAt(0).fillBefore(a,t.childCount>1||i<=o).append(a):a.append(s.contentMatchAt(s.childCount).fillBefore(tc.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,s.copy(a))}function ef(t,e,n){return e{for(let n in e)t.input.eventHandlers[n]||t.dom.addEventListener(n,t.input.eventHandlers[n]=e=>df(t,e))}))}function df(t,e){return t.someProp("handleDOMEvents",(n=>{let r=n[e.type];return!!r&&(r(t,e)||e.defaultPrevented)}))}function hf(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target;n!=t.dom;n=n.parentNode)if(!n||11==n.nodeType||n.pmViewDesc&&n.pmViewDesc.stopEvent(e))return!1;return!0}function ff(t){return{left:t.clientX,top:t.clientY}}function pf(t,e,n,r,o){if(-1==r)return!1;let i=t.state.doc.resolve(r);for(let s=i.depth+1;s>0;s--)if(t.someProp(e,(e=>s>i.depth?e(t,n,i.nodeAfter,i.before(s),o,!0):e(t,n,i.node(s),i.before(s),o,!1))))return!0;return!1}function mf(t,e,n){t.focused||t.focus();let r=t.state.tr.setSelection(e);"pointer"==n&&r.setMeta("pointer",!0),t.dispatch(r)}function gf(t,e,n,r,o){return pf(t,"handleClickOn",e,n,r)||t.someProp("handleClick",(n=>n(t,e,r)))||(o?function(t,e){if(-1==e)return!1;let n,r,o=t.state.selection;o instanceof Vu&&(n=o.node);let i=t.state.doc.resolve(e);for(let s=i.depth+1;s>0;s--){let t=s>i.depth?i.nodeAfter:i.node(s);if(Vu.isSelectable(t)){r=n&&o.$from.depth>0&&s>=o.$from.depth&&i.before(o.$from.depth+1)==o.$from.pos?i.before(o.$from.depth):i.before(s);break}}return null!=r&&(mf(t,Vu.create(t.state.doc,r),"pointer"),!0)}(t,n):function(t,e){if(-1==e)return!1;let n=t.state.doc.resolve(e),r=n.nodeAfter;return!!(r&&r.isAtom&&Vu.isSelectable(r))&&(mf(t,new Vu(n),"pointer"),!0)}(t,n))}function vf(t,e,n,r){return pf(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",(n=>n(t,e,r)))}function yf(t,e,n,r){return pf(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",(n=>n(t,e,r)))||function(t,e,n){if(0!=n.button)return!1;let r=t.state.doc;if(-1==e)return!!r.inlineContent&&(mf(t,Lu.create(r,0,r.content.size),"pointer"),!0);let o=r.resolve(e);for(let i=o.depth+1;i>0;i--){let e=i>o.depth?o.nodeAfter:o.node(i),n=o.before(i);if(e.inlineContent)mf(t,Lu.create(r,n+1,n+1+e.content.size),"pointer");else{if(!Vu.isSelectable(e))continue;mf(t,Vu.create(r,n),"pointer")}return!0}}(t,n,r)}function bf(t){return Cf(t)}af.keydown=(t,e)=>{let n=e;if(t.input.shiftKey=16==n.keyCode||n.shiftKey,!Sf(t,n)&&(t.input.lastKeyCode=n.keyCode,t.input.lastKeyCodeTime=Date.now(),!wd||!md||13!=n.keyCode))if(229!=n.keyCode&&t.domObserver.forceFlush(),!yd||13!=n.keyCode||n.ctrlKey||n.altKey||n.metaKey)t.someProp("handleKeyDown",(e=>e(t,n)))||Kh(t,n)?n.preventDefault():cf(t,"key");else{let e=Date.now();t.input.lastIOSEnter=e,t.input.lastIOSEnterFallbackTimeout=setTimeout((()=>{t.input.lastIOSEnter==e&&(t.someProp("handleKeyDown",(e=>e(t,Ad(13,"Enter")))),t.input.lastIOSEnter=0)}),200)}},af.keyup=(t,e)=>{16==e.keyCode&&(t.input.shiftKey=!1)},af.keypress=(t,e)=>{let n=e;if(Sf(t,n)||!n.charCode||n.ctrlKey&&!n.altKey||bd&&n.metaKey)return;if(t.someProp("handleKeyPress",(e=>e(t,n))))return void n.preventDefault();let r=t.state.selection;if(!(r instanceof Lu&&r.$from.sameParent(r.$to))){let e=String.fromCharCode(n.charCode);t.someProp("handleTextInput",(n=>n(t,r.$from.pos,r.$to.pos,e)))||t.dispatch(t.state.tr.insertText(e).scrollIntoView()),n.preventDefault()}};const wf=bd?"metaKey":"ctrlKey";sf.mousedown=(t,e)=>{let n=e;t.input.shiftKey=n.shiftKey;let r=bf(t),o=Date.now(),i="singleClick";o-t.input.lastClick.time<500&&function(t,e){let n=e.x-t.clientX,r=e.y-t.clientY;return n*n+r*r<100}(n,t.input.lastClick)&&!n[wf]&&("singleClick"==t.input.lastClick.type?i="doubleClick":"doubleClick"==t.input.lastClick.type&&(i="tripleClick")),t.input.lastClick={time:o,x:n.clientX,y:n.clientY,type:i};let s=t.posAtCoords(ff(n));s&&("singleClick"==i?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new xf(t,s,n,!!r)):("doubleClick"==i?vf:yf)(t,s.pos,s.inside,n)?n.preventDefault():cf(t,"pointer"))};class xf{constructor(t,e,n,r){let o,i;if(this.view=t,this.pos=e,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=t.state.doc,this.selectNode=!!n[wf],this.allowDefault=n.shiftKey,e.inside>-1)o=t.state.doc.nodeAt(e.inside),i=e.inside;else{let n=t.state.doc.resolve(e.pos);o=n.parent,i=n.depth?n.before():0}const s=r?null:n.target,a=s?t.docView.nearestDesc(s,!0):null;this.target=a?a.dom:null;let{selection:l}=t.state;(0==n.button&&o.type.spec.draggable&&!1!==o.type.spec.selectable||l instanceof Vu&&l.from<=i&&l.to>i)&&(this.mightDrag={node:o,pos:i,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!fd||this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout((()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")}),20),this.view.domObserver.start()),t.root.addEventListener("mouseup",this.up=this.up.bind(this)),t.root.addEventListener("mousemove",this.move=this.move.bind(this)),cf(t,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout((()=>Oh(this.view))),this.view.input.mouseDown=null}up(t){if(this.done(),!this.view.dom.contains(t.target))return;let e=this.pos;this.view.state.doc!=this.startDoc&&(e=this.view.posAtCoords(ff(t))),this.allowDefault||!e?cf(this.view,"pointer"):gf(this.view,e.pos,e.inside,t,this.selectNode)?t.preventDefault():0==t.button&&(this.flushed||vd&&this.mightDrag&&!this.mightDrag.node.isAtom||md&&!(this.view.state.selection instanceof Lu)&&Math.min(Math.abs(e.pos-this.view.state.selection.from),Math.abs(e.pos-this.view.state.selection.to))<=2)?(mf(this.view,Ru.near(this.view.state.doc.resolve(e.pos)),"pointer"),t.preventDefault()):cf(this.view,"pointer")}move(t){!this.allowDefault&&(Math.abs(this.event.x-t.clientX)>4||Math.abs(this.event.y-t.clientY)>4)&&(this.allowDefault=!0),cf(this.view,"pointer"),0==t.buttons&&this.done()}}function Sf(t,e){return!!t.composing||!!(vd&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500)&&(t.input.compositionEndedAt=-2e8,!0)}sf.touchdown=t=>{bf(t),cf(t,"pointer")},sf.contextmenu=t=>bf(t);const kf=wd?5e3:-1;function _f(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout((()=>Cf(t)),e))}function Of(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=function(){let t=document.createEvent("Event");return t.initEvent("event",!0,!0),t.timeStamp}());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function Cf(t,e=!1){if(!(wd&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),Of(t),e||t.docView&&t.docView.dirty){let e=kh(t);return e&&!e.eq(t.state.selection)?t.dispatch(t.state.tr.setSelection(e)):t.updateState(t.state),!0}return!1}}af.compositionstart=af.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,n=e.selection.$from;if(e.selection.empty&&(e.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some((t=>!1===t.type.spec.inclusive))))t.markCursor=t.state.storedMarks||n.marks(),Cf(t,!0),t.markCursor=null;else if(Cf(t),fd&&e.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let e=t.domSelection();for(let t=e.focusNode,n=e.focusOffset;t&&1==t.nodeType&&0!=n;){let r=n<0?t.lastChild:t.childNodes[n-1];if(!r)break;if(3==r.nodeType){e.collapse(r,r.nodeValue.length);break}t=r,n=-1}}t.input.composing=!0}_f(t,kf)},af.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=e.timeStamp,_f(t,20))};const Mf=dd&&hd<15||yd&&Sd<604;function Df(t,e,n,r){let o=Uh(t,e,n,t.input.shiftKey,t.state.selection.$from);if(t.someProp("handlePaste",(e=>e(t,r,o||sc.empty))))return!0;if(!o)return!1;let i=function(t){return 0==t.openStart&&0==t.openEnd&&1==t.content.childCount?t.content.firstChild:null}(o),s=i?t.state.tr.replaceSelectionWith(i,t.input.shiftKey):t.state.tr.replaceSelection(o);return t.dispatch(s.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}sf.copy=af.cut=(t,e)=>{let n=e,r=t.state.selection,o="cut"==n.type;if(r.empty)return;let i=Mf?null:n.clipboardData,s=r.content(),{dom:a,text:l}=Yh(t,s);i?(n.preventDefault(),i.clearData(),i.setData("text/html",a.innerHTML),i.setData("text/plain",l)):function(t,e){if(!t.dom.parentNode)return;let n=t.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(e),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),o=document.createRange();o.selectNodeContents(e),t.dom.blur(),r.removeAllRanges(),r.addRange(o),setTimeout((()=>{n.parentNode&&n.parentNode.removeChild(n),t.focus()}),50)}(t,a),o&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},af.paste=(t,e)=>{let n=e;if(t.composing&&!wd)return;let r=Mf?null:n.clipboardData;r&&Df(t,r.getData("text/plain"),r.getData("text/html"),n)?n.preventDefault():function(t,e){if(!t.dom.parentNode)return;let n=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,r=t.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus(),setTimeout((()=>{t.focus(),r.parentNode&&r.parentNode.removeChild(r),n?Df(t,r.value,null,e):Df(t,r.textContent,r.innerHTML,e)}),50)}(t,n)};class Tf{constructor(t,e){this.slice=t,this.move=e}}const $f=bd?"altKey":"ctrlKey";sf.dragstart=(t,e)=>{let n=e,r=t.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let o=t.state.selection,i=o.empty?null:t.posAtCoords(ff(n));if(i&&i.pos>=o.from&&i.pos<=(o instanceof Vu?o.to-1:o.to));else if(r&&r.mightDrag)t.dispatch(t.state.tr.setSelection(Vu.create(t.state.doc,r.mightDrag.pos)));else if(n.target&&1==n.target.nodeType){let e=t.docView.nearestDesc(n.target,!0);e&&e.node.type.spec.draggable&&e!=t.docView&&t.dispatch(t.state.tr.setSelection(Vu.create(t.state.doc,e.posBefore)))}let s=t.state.selection.content(),{dom:a,text:l}=Yh(t,s);n.dataTransfer.clearData(),n.dataTransfer.setData(Mf?"Text":"text/html",a.innerHTML),n.dataTransfer.effectAllowed="copyMove",Mf||n.dataTransfer.setData("text/plain",l),t.dragging=new Tf(s,!n[$f])},sf.dragend=t=>{let e=t.dragging;window.setTimeout((()=>{t.dragging==e&&(t.dragging=null)}),50)},af.dragover=af.dragenter=(t,e)=>e.preventDefault(),af.drop=(t,e)=>{let n=e,r=t.dragging;if(t.dragging=null,!n.dataTransfer)return;let o=t.posAtCoords(ff(n));if(!o)return;let i=t.state.doc.resolve(o.pos);if(!i)return;let s=r&&r.slice;s?t.someProp("transformPasted",(t=>{s=t(s)})):s=Uh(t,n.dataTransfer.getData(Mf?"Text":"text/plain"),Mf?null:n.dataTransfer.getData("text/html"),!1,i);let a=!(!r||n[$f]);if(t.someProp("handleDrop",(e=>e(t,n,s||sc.empty,a))))return void n.preventDefault();if(!s)return;n.preventDefault();let l=s?function(t,e,n){let r=t.resolve(e);if(!n.content.size)return e;let o=n.content;for(let i=0;i=0;t--){let e=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,n=r.index(t)+(e>0?1:0),s=r.node(t),a=!1;if(1==i)a=s.canReplace(n,n,o);else{let t=s.contentMatchAt(n).findWrapping(o.firstChild.type);a=t&&s.canReplaceWith(n,n,t[0])}if(a)return 0==e?r.pos:e<0?r.before(t+1):r.after(t+1)}return null}(t.state.doc,i.pos,s):i.pos;null==l&&(l=i.pos);let c=t.state.tr;a&&c.deleteSelection();let u=c.mapping.map(l),d=0==s.openStart&&0==s.openEnd&&1==s.content.childCount,h=c.doc;if(d?c.replaceRangeWith(u,u,s.content.firstChild):c.replaceRange(u,u,s),c.doc.eq(h))return;let f=c.doc.resolve(u);if(d&&Vu.isSelectable(s.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(s.content.firstChild))c.setSelection(new Vu(f));else{let e=c.mapping.map(l);c.mapping.maps[c.mapping.maps.length-1].forEach(((t,n,r,o)=>e=o)),c.setSelection(Nh(t,f,c.doc.resolve(e)))}t.focus(),t.dispatch(c.setMeta("uiEvent","drop"))},sf.focus=t=>{t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout((()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelection())&&Oh(t)}),20))},sf.blur=(t,e)=>{let n=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),n.relatedTarget&&t.dom.contains(n.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)},sf.beforeinput=(t,e)=>{if(md&&wd&&"deleteContentBackward"==e.inputType){t.domObserver.flushSoon();let{domChangeCount:e}=t.input;setTimeout((()=>{if(t.input.domChangeCount!=e)return;if(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",(e=>e(t,Ad(8,"Backspace")))))return;let{$cursor:n}=t.state.selection;n&&n.pos>0&&t.dispatch(t.state.tr.delete(n.pos-1,n.pos).scrollIntoView())}),50)}};for(let os in af)sf[os]=af[os];function Ef(t,e){if(t==e)return!0;for(let n in t)if(t[n]!==e[n])return!1;for(let n in e)if(!(n in t))return!1;return!0}class Nf{constructor(t,e){this.toDOM=t,this.spec=e||zf,this.side=this.spec.side||0}map(t,e,n,r){let{pos:o,deleted:i}=t.mapResult(e.from+r,this.side<0?-1:1);return i?null:new If(o-n,o-n,this)}valid(){return!0}eq(t){return this==t||t instanceof Nf&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&Ef(this.spec,t.spec))}destroy(t){this.spec.destroy&&this.spec.destroy(t)}}class Af{constructor(t,e){this.attrs=t,this.spec=e||zf}map(t,e,n,r){let o=t.map(e.from+r,this.spec.inclusiveStart?-1:1)-n,i=t.map(e.to+r,this.spec.inclusiveEnd?1:-1)-n;return o>=i?null:new If(o,i,this)}valid(t,e){return e.from=t&&(!o||o(s.spec))&&n.push(s.copy(s.from+r,s.to+r))}for(let i=0;it){let s=this.children[i]+1;this.children[i+2].findInner(t-s,e-s,n,r+s,o)}}map(t,e,n){return this==Ff||0==t.maps.length?this:this.mapInner(t,e,0,0,n||zf)}mapInner(t,e,n,r,o){let i;for(let s=0;s{for(let s=0;sc+i)continue;let u=a[s]+i;e>=u?a[s+1]=t<=u?-2:-1:n>=o&&(l=r-n-(e-t))&&(a[s]+=l,a[s+1]+=l)}};for(let u=0;u=r.content.size){c=!0;continue}let d=n.map(t[u+1]+i,-1)-o,{index:h,offset:f}=r.content.findIndex(l),p=r.maybeChild(h);if(p&&f==l&&f+p.nodeSize==d){let r=a[u+2].mapInner(n,p,e+1,t[u]+i+1,s);r!=Ff?(a[u]=l,a[u+1]=d,a[u+2]=r):(a[u+1]=-2,c=!0)}else c=!0}if(c){let l=function(t,e,n,r,o,i,s){function a(t,e){for(let i=0;i{let s,a=i+n;if(s=Vf(e,t,a)){for(r||(r=this.children.slice());oi&&e.to=t){this.children[s]==t&&(n=this.children[s+2]);break}let o=t+1,i=o+e.content.size;for(let s=0;so&&t.type instanceof Af){let e=Math.max(o,t.from)-o,n=Math.min(i,t.to)-o;en.map(t,e,zf)));return Lf.from(n)}forChild(t,e){if(e.isLeaf)return jf.empty;let n=[];for(let r=0;rn&&i.to{let a=Vf(t,e,s+n);if(a){i=!0;let t=qf(a,e,n+s+1,r);t!=Ff&&o.push(s,s+e.nodeSize,t)}}));let s=Bf(i?Wf(t):t,-n).sort(Hf);for(let a=0;a0;)e++;t.splice(e,0,n)}function Yf(t){let e=[];return t.someProp("decorations",(n=>{let r=n(t.state);r&&r!=Ff&&e.push(r)})),t.cursorWrapper&&e.push(jf.create(t.state.doc,[t.cursorWrapper.deco])),Lf.from(e)}const Uf={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Gf=dd&&hd<=11;class Xf{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(t){this.anchorNode=t.anchorNode,this.anchorOffset=t.anchorOffset,this.focusNode=t.focusNode,this.focusOffset=t.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(t){return t.anchorNode==this.anchorNode&&t.anchorOffset==this.anchorOffset&&t.focusNode==this.focusNode&&t.focusOffset==this.focusOffset}}class Zf{constructor(t,e){this.view=t,this.handleDOMChange=e,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Xf,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.observer=window.MutationObserver&&new window.MutationObserver((t=>{for(let e=0;e"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length))?this.flushSoon():this.flush()})),Gf&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout((()=>{this.flushingSoon=-1,this.flush()}),20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,Uf)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let t=this.observer.takeRecords();if(t.length){for(let e=0;ethis.flush()),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout((()=>this.suppressingSelectionUpdates=!1),50)}onSelectionChange(){if(Ah(this.view)){if(this.suppressingSelectionUpdates)return Oh(this.view);if(dd&&hd<=11&&!this.view.state.selection.empty){let t=this.view.domSelection();if(t.focusNode&&Md(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelection())}ignoreSelectionChange(t){if(0==t.rangeCount)return!0;let e=t.getRangeAt(0).commonAncestorContainer,n=this.view.docView.nearestDesc(e);return n&&n.ignoreMutation({type:"selection",target:3==e.nodeType?e.parentNode:e})?(this.setCurSelection(),!0):void 0}flush(){if(!this.view.docView||this.flushingSoon>-1)return;let t=this.observer?this.observer.takeRecords():[];this.queue.length&&(t=this.queue.concat(t),this.queue.length=0);let e=this.view.domSelection(),n=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(e)&&Ah(this.view)&&!this.ignoreSelectionChange(e),r=-1,o=-1,i=!1,s=[];if(this.view.editable)for(let a=0;a1){let t=s.filter((t=>"BR"==t.nodeName));if(2==t.length){let e=t[0],n=t[1];e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}}(r>-1||n)&&(r>-1&&(this.view.docView.markDirty(r,o),function(t){if(Qf)return;Qf=!0,"normal"==getComputedStyle(t.dom).whiteSpace&&console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package.")}(this.view)),this.handleDOMChange(r,o,i,s),this.view.docView&&this.view.docView.dirty?this.view.updateState(this.view.state):this.currentSelection.eq(e)||Oh(this.view),this.currentSelection.set(e))}registerMutation(t,e){if(e.indexOf(t.target)>-1)return null;let n=this.view.docView.nearestDesc(t.target);if("attributes"==t.type&&(n==this.view.docView||"contenteditable"==t.attributeName||"style"==t.attributeName&&!t.oldValue&&!t.target.getAttribute("style")))return null;if(!n||n.ignoreMutation(t))return null;if("childList"==t.type){for(let n=0;nDate.now()-50?t.input.lastSelectionOrigin:null,n=kh(t,e);if(n&&!t.state.selection.eq(n)){let r=t.state.tr.setSelection(n);"pointer"==e?r.setMeta("pointer",!0):"key"==e&&r.scrollIntoView(),t.dispatch(r)}return}let i=t.state.doc.resolve(e),s=i.sharedDepth(n);e=i.before(s+1),n=t.state.doc.resolve(n).after(s+1);let a=t.state.selection,l=function(t,e,n){let r,{node:o,fromOffset:i,toOffset:s,from:a,to:l}=t.docView.parseRange(e,n),c=t.domSelection(),u=c.anchorNode;if(u&&t.dom.contains(1==u.nodeType?u:u.parentNode)&&(r=[{node:u,offset:c.anchorOffset}],Nd(c)||r.push({node:c.focusNode,offset:c.focusOffset})),md&&8===t.input.lastKeyCode)for(let g=s;g>i;g--){let t=o.childNodes[g-1],e=t.pmViewDesc;if("BR"==t.nodeName&&!e){s=g;break}if(!e||e.size)break}let d=t.state.doc,h=t.someProp("domParser")||qc.fromSchema(t.state.schema),f=d.resolve(a),p=null,m=h.parse(o,{topNode:f.parent,topMatch:f.parent.contentMatchAt(f.index()),topOpen:!0,from:i,to:s,preserveWhitespace:"pre"!=f.parent.type.whitespace||"full",findPositions:r,ruleFromNode:tp,context:f});if(r&&null!=r[0].pos){let t=r[0].pos,e=r[1]&&r[1].pos;null==e&&(e=t),p={anchor:t+a,head:e+a}}return{doc:m,sel:p,from:a,to:l}}(t,e,n);if(md&&t.cursorWrapper&&l.sel&&l.sel.anchor==t.cursorWrapper.deco.from){let e=t.cursorWrapper.deco.type.toDOM.nextSibling,n=e&&e.nodeValue?e.nodeValue.length:1;l.sel={anchor:l.sel.anchor+n,head:l.sel.anchor+n}}let c,u,d=t.state.doc,h=d.slice(l.from,l.to);8===t.input.lastKeyCode&&Date.now()-100=s?i-r:0,a=i+(a-s),s=i}else if(a=a?i-r:0,s=i+(s-a),a=i}return{start:i,endA:s,endB:a}}(h.content,l.doc.content,l.from,c,u);if((yd&&t.input.lastIOSEnter>Date.now()-225||wd)&&o.some((t=>"DIV"==t.nodeName||"P"==t.nodeName))&&(!f||f.endA>=f.endB)&&t.someProp("handleKeyDown",(e=>e(t,Ad(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(!f){if(!(r&&a instanceof Lu&&!a.empty&&a.$head.sameParent(a.$anchor))||t.composing||l.sel&&l.sel.anchor!=l.sel.head){if(l.sel){let e=np(t,t.state.doc,l.sel);e&&!e.eq(t.state.selection)&&t.dispatch(t.state.tr.setSelection(e))}return}f={start:a.from,endA:a.to,endB:a.to}}t.input.domChangeCount++,t.state.selection.fromt.state.selection.from&&f.start<=t.state.selection.from+2&&t.state.selection.from>=l.from?f.start=t.state.selection.from:f.endA=t.state.selection.to-2&&t.state.selection.to<=l.to&&(f.endB+=t.state.selection.to-f.endA,f.endA=t.state.selection.to)),dd&&hd<=11&&f.endB==f.start+1&&f.endA==f.start&&f.start>l.from&&"  "==l.doc.textBetween(f.start-l.from-1,f.start-l.from+1)&&(f.start--,f.endA--,f.endB--);let p,m=l.doc.resolveNoCache(f.start-l.from),g=l.doc.resolveNoCache(f.endB-l.from),v=d.resolve(f.start),y=m.sameParent(g)&&m.parent.inlineContent&&v.end()>=f.endA;if((yd&&t.input.lastIOSEnter>Date.now()-225&&(!y||o.some((t=>"DIV"==t.nodeName||"P"==t.nodeName)))||!y&&m.pose(t,Ad(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(t.state.selection.anchor>f.start&&function(t,e,n,r,o){if(!r.parent.isTextblock||n-e<=o.pos-r.pos||rp(r,!0,!1)n||rp(s,!0,!1)e(t,Ad(8,"Backspace")))))return void(wd&&md&&t.domObserver.suppressSelectionUpdates());md&&wd&&f.endB==f.start&&(t.input.lastAndroidDelete=Date.now()),wd&&!y&&m.start()!=g.start()&&0==g.parentOffset&&m.depth==g.depth&&l.sel&&l.sel.anchor==l.sel.head&&l.sel.head==f.endA&&(f.endB-=2,g=l.doc.resolveNoCache(f.endB-l.from),setTimeout((()=>{t.someProp("handleKeyDown",(function(e){return e(t,Ad(13,"Enter"))}))}),20));let b,w,x,S=f.start,k=f.endA;if(y)if(m.pos==g.pos)dd&&hd<=11&&0==m.parentOffset&&(t.domObserver.suppressSelectionUpdates(),setTimeout((()=>Oh(t)),20)),b=t.state.tr.delete(S,k),w=d.resolve(f.start).marksAcross(d.resolve(f.endA));else if(f.endA==f.endB&&(x=function(t,e){let n,r,o,i=t.firstChild.marks,s=e.firstChild.marks,a=i,l=s;for(let u=0;ut.mark(r.addToSet(t.marks));else{if(0!=a.length||1!=l.length)return null;r=l[0],n="remove",o=t=>t.mark(r.removeFromSet(t.marks))}let c=[];for(let u=0;un(t,S,k,e))))return;b=t.state.tr.insertText(e,S,k)}if(b||(b=t.state.tr.replace(S,k,l.doc.slice(f.start-l.from,f.endB-l.from))),l.sel){let e=np(t,b.doc,l.sel);e&&!(md&&wd&&t.composing&&e.empty&&(f.start!=f.endB||t.input.lastAndroidDeletee.content.size?null:Nh(t,e.resolve(n.anchor),e.resolve(n.head))}function rp(t,e,n){let r=t.depth,o=e?t.end():t.pos;for(;r>0&&(e||t.indexAfter(r)==t.node(r).childCount);)r--,o++,e=!1;if(n){let e=t.node(r).maybeChild(t.indexAfter(r));for(;e&&!e.isLeaf;)e=e.firstChild,o++}return o}class op{constructor(t,e){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new lf,this.prevDirectPlugins=[],this.pluginViews=[],this.dragging=null,this._props=e,this.state=e.state,this.directPlugins=e.plugins||[],this.directPlugins.forEach(cp),this.dispatch=this.dispatch.bind(this),this.dom=t&&t.mount||document.createElement("div"),t&&(t.appendChild?t.appendChild(this.dom):"function"==typeof t?t(this.dom):t.mount&&(this.mounted=!0)),this.editable=ap(this),sp(this),this.nodeViews=lp(this),this.docView=ah(this.state.doc,ip(this),Yf(this),this.dom,this),this.domObserver=new Zf(this,((t,e,n,r)=>ep(this,t,e,n,r))),this.domObserver.start(),function(t){for(let e in sf){let n=sf[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=e=>{!hf(t,e)||df(t,e)||!t.editable&&e.type in af||n(t,e)})}vd&&t.dom.addEventListener("input",(()=>null)),uf(t)}(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let t=this._props;this._props={};for(let e in t)this._props[e]=t[e];this._props.state=this.state}return this._props}update(t){t.handleDOMEvents!=this._props.handleDOMEvents&&uf(this),this._props=t,t.plugins&&(t.plugins.forEach(cp),this.directPlugins=t.plugins),this.updateStateInner(t.state,!0)}setProps(t){let e={};for(let n in this._props)e[n]=this._props[n];e.state=this.state;for(let n in t)e[n]=t[n];this.update(e)}updateState(t){this.updateStateInner(t,this.state.plugins!=t.plugins)}updateStateInner(t,e){let n=this.state,r=!1,o=!1;if(t.storedMarks&&this.composing&&(Of(this),o=!0),this.state=t,e){let t=lp(this);(function(t,e){let n=0,r=0;for(let o in t){if(t[o]!=e[o])return!0;n++}for(let o in e)r++;return n!=r})(t,this.nodeViews)&&(this.nodeViews=t,r=!0),uf(this)}this.editable=ap(this),sp(this);let i=Yf(this),s=ip(this),a=e?"reset":t.scrollToSelection>n.scrollToSelection?"to selection":"preserve",l=r||!this.docView.matchesNode(t.doc,s,i);!l&&t.selection.eq(n.selection)||(o=!0);let c="preserve"==a&&o&&null==this.dom.style.overflowAnchor&&function(t){let e,n,r=t.dom.getBoundingClientRect(),o=Math.max(0,r.top);for(let i=(r.left+r.right)/2,s=o+1;s=o-20){e=r,n=a.top;break}}return{refDOM:e,refTop:n,stack:jd(t.dom)}}(this);if(o){this.domObserver.stop();let e=l&&(dd||md)&&!this.composing&&!n.selection.empty&&!t.selection.empty&&function(t,e){let n=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(n)!=e.$anchor.start(n)}(n.selection,t.selection);if(l){let n=md?this.trackWrites=this.domSelection().focusNode:null;!r&&this.docView.update(t.doc,s,i,this)||(this.docView.updateOuterDeco([]),this.docView.destroy(),this.docView=ah(t.doc,s,i,this.dom,this)),n&&!this.trackWrites&&(e=!0)}e||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelection())&&function(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelection();return Md(e.node,e.offset,n.anchorNode,n.anchorOffset)}(this))?Oh(this,e):($h(this,t.selection),this.domObserver.setCurSelection()),this.domObserver.start()}if(this.updatePluginViews(n),"reset"==a)this.dom.scrollTop=0;else if("to selection"==a){let e=this.domSelection().focusNode;if(this.someProp("handleScrollToSelection",(t=>t(this))));else if(t.selection instanceof Vu){let n=this.docView.domAfterPos(t.selection.from);1==n.nodeType&&zd(this,n.getBoundingClientRect(),e)}else zd(this,this.coordsAtPos(t.selection.head,1),e)}else c&&function({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;Fd(n,0==r?0:r-e)}(c)}destroyPluginViews(){let t;for(;t=this.pluginViews.pop();)t.destroy&&t.destroy()}updatePluginViews(t){if(t&&t.plugins==this.state.plugins&&this.directPlugins==this.prevDirectPlugins)for(let e=0;ee.ownerDocument.getSelection()),this._root=e;return t||document}posAtCoords(t){return qd(this,t)}coordsAtPos(t,e=1){return Kd(this,t,e)}domAtPos(t,e=0){return this.docView.domFromPos(t,e)}nodeDOM(t){let e=this.docView.descAt(t);return e?e.nodeDOM:null}posAtDOM(t,e,n=-1){let r=this.docView.posFromDOM(t,e,n);if(null==r)throw new RangeError("DOM position not inside the editor");return r}endOfTextblock(t,e){return eh(this,e||this.state,t)}destroy(){this.docView&&(!function(t){t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Yf(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null)}get isDestroyed(){return null==this.docView}dispatchEvent(t){return function(t,e){df(t,e)||!sf[e.type]||!t.editable&&e.type in af||sf[e.type](t,e)}(this,t)}dispatch(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))}domSelection(){return this.root.getSelection()}}function ip(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),e.translate="no",t.someProp("attributes",(n=>{if("function"==typeof n&&(n=n(t.state)),n)for(let t in n)"class"==t&&(e.class+=" "+n[t]),"style"==t?e.style=(e.style?e.style+";":"")+n[t]:e[t]||"contenteditable"==t||"nodeName"==t||(e[t]=String(n[t]))})),[If.node(0,t.state.doc.content.size,e)]}function sp(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:If.widget(t.state.selection.head,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function ap(t){return!t.someProp("editable",(e=>!1===e(t.state)))}function lp(t){let e=Object.create(null);function n(t){for(let n in t)Object.prototype.hasOwnProperty.call(e,n)||(e[n]=t[n])}return t.someProp("nodeViews",n),t.someProp("markViews",n),e}function cp(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}for(var up={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",229:"q"},dp={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"',229:"Q"},hp="undefined"!=typeof navigator&&/Chrome\/(\d+)/.exec(navigator.userAgent),fp="undefined"!=typeof navigator&&/Apple Computer/.test(navigator.vendor),pp="undefined"!=typeof navigator&&/Gecko\/\d+/.test(navigator.userAgent),mp="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),gp="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),vp=hp&&(mp||+hp[1]<57)||pp&&mp,yp=0;yp<10;yp++)up[48+yp]=up[96+yp]=String(yp);for(yp=1;yp<=24;yp++)up[yp+111]="F"+yp;for(yp=65;yp<=90;yp++)up[yp]=String.fromCharCode(yp+32),dp[yp]=String.fromCharCode(yp);for(var bp in up)dp.hasOwnProperty(bp)||(dp[bp]=up[bp]);const wp="undefined"!=typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform);function xp(t){let e,n,r,o,i=t.split(/-(?!$)/),s=i[i.length-1];"Space"==s&&(s=" ");for(let a=0;a127)&&(r=up[n.keyCode])&&r!=o){let o=e[Sp(r,n,!0)];if(o&&o(t.state,t.dispatch,t))return!0}else if(i&&n.shiftKey){let r=e[Sp(o,n,!0)];if(r&&r(t.state,t.dispatch,t))return!0}return!1}}const Op=(t,e)=>!t.selection.empty&&(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function Cp(t,e,n=!1){for(let r=t;r;r="start"==e?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&1!=r.childCount)return!1}return!1}function Mp(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function Dp(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){let n=t.node(e);if(t.index(e)+1{let{$head:n,$anchor:r}=t.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let o=n.node(-1),i=n.indexAfter(-1),s=Tp(o.contentMatchAt(i));if(!s||!o.canReplaceWith(i,i,s))return!1;if(e){let r=n.after(),o=t.tr.replaceWith(r,r,s.createAndFill());o.setSelection(Ru.near(o.doc.resolve(r),1)),e(o.scrollIntoView())}return!0};function Ep(t,e,n){let r,o,i=e.nodeBefore,s=e.nodeAfter;if(i.type.spec.isolating||s.type.spec.isolating)return!1;if(function(t,e,n){let r=e.nodeBefore,o=e.nodeAfter,i=e.index();return!(!(r&&o&&r.type.compatibleContent(o.type))||(!r.content.size&&e.parent.canReplace(i-1,i)?(n&&n(t.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),0):!e.parent.canReplace(i,i+1)||!o.isTextblock&&!Su(t.doc,e.pos)||(n&&n(t.tr.clearIncompatible(e.pos,r.type,r.contentMatchAt(r.childCount)).join(e.pos).scrollIntoView()),0)))}(t,e,n))return!0;let a=e.parent.canReplace(e.index(),e.index()+1);if(a&&(r=(o=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&o.matchType(r[0]||s.type).validEnd){if(n){let o=e.pos+s.nodeSize,a=tc.empty;for(let t=r.length-1;t>=0;t--)a=tc.from(r[t].create(null,a));a=tc.from(i.copy(a));let l=t.tr.step(new mu(e.pos-1,o,e.pos,o,new sc(a,1,0),r.length,!0)),c=o+2*r.length;Su(l.doc,c)&&l.join(c),n(l.scrollIntoView())}return!0}let l=Ru.findFrom(e,1),c=l&&l.$from.blockRange(l.$to),u=c&&yu(c);if(null!=u&&u>=e.depth)return n&&n(t.tr.lift(c,u).scrollIntoView()),!0;if(a&&Cp(s,"start",!0)&&Cp(i,"end")){let r=i,o=[];for(;o.push(r),!r.isTextblock;)r=r.lastChild;let a=s,l=1;for(;!a.isTextblock;a=a.firstChild)l++;if(r.canReplace(r.childCount,r.childCount,a.content)){if(n){let r=tc.empty;for(let t=o.length-1;t>=0;t--)r=tc.from(o[t].copy(r));n(t.tr.step(new mu(e.pos-o.length,e.pos+s.nodeSize,e.pos+l,e.pos+s.nodeSize-l,new sc(r,o.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function Np(t){return function(e,n){let r=e.selection,o=t<0?r.$from:r.$to,i=o.depth;for(;o.node(i).isInline;){if(!i)return!1;i--}return!!o.node(i).isTextblock&&(n&&n(e.tr.setSelection(Lu.create(e.doc,t<0?o.start(i):o.end(i)))),!0)}}const Ap=Np(-1),Pp=Np(1);function Ip(t,e=null){return function(n,r){let{from:o,to:i}=n.selection,s=!1;return n.doc.nodesBetween(o,i,((r,o)=>{if(s)return!1;if(r.isTextblock&&!r.hasMarkup(t,e))if(r.type==t)s=!0;else{let e=n.doc.resolve(o),r=e.index();s=e.parent.canReplaceWith(r,r+1,t)}})),!!s&&(r&&r(n.tr.setBlockType(o,i,t,e).scrollIntoView()),!0)}}function Rp(t,e=null){return function(n,r){let{empty:o,$cursor:i,ranges:s}=n.selection;if(o&&!i||!function(t,e,n){for(let r=0;r{if(s)return!1;s=t.inlineContent&&t.type.allowsMarkType(n)})),s)return!0}return!1}(n.doc,s,t))return!1;if(r)if(i)t.isInSet(n.storedMarks||i.marks())?r(n.tr.removeStoredMark(t)):r(n.tr.addStoredMark(t.create(e)));else{let o=!1,i=n.tr;for(let e=0;!o&&e{let{$cursor:r}=t.selection;if(!r||(n?!n.endOfTextblock("backward",t):r.parentOffset>0))return!1;let o=Mp(r);if(!o){let n=r.blockRange(),o=n&&yu(n);return null!=o&&(e&&e(t.tr.lift(n,o).scrollIntoView()),!0)}let i=o.nodeBefore;if(!i.type.spec.isolating&&Ep(t,o,e))return!0;if(0==r.parent.content.size&&(Cp(i,"end")||Vu.isSelectable(i))){let n=ku(t.doc,r.before(),r.after(),sc.empty);if(n&&n.slice.size{let{$head:r,empty:o}=t.selection,i=r;if(!o)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",t):r.parentOffset>0)return!1;i=Mp(r)}let s=i&&i.nodeBefore;return!(!s||!Vu.isSelectable(s))&&(e&&e(t.tr.setSelection(Vu.create(t.doc,i.pos-s.nodeSize)).scrollIntoView()),!0)})),Fp=zp(Op,((t,e,n)=>{let{$cursor:r}=t.selection;if(!r||(n?!n.endOfTextblock("forward",t):r.parentOffset{let{$head:r,empty:o}=t.selection,i=r;if(!o)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",t):r.parentOffset{let{$head:n,$anchor:r}=t.selection;return!(!n.parent.type.spec.code||!n.sameParent(r))&&(e&&e(t.tr.insertText("\n").scrollIntoView()),!0)}),((t,e)=>{let n=t.selection,{$from:r,$to:o}=n;if(n instanceof qu||r.parent.inlineContent||o.parent.inlineContent)return!1;let i=Tp(o.parent.contentMatchAt(o.indexAfter()));if(!i||!i.isTextblock)return!1;if(e){let n=(!r.parentOffset&&o.index(){let{$cursor:n}=t.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(xu(t.doc,r))return e&&e(t.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),o=r&&yu(r);return null!=o&&(e&&e(t.tr.lift(r,o).scrollIntoView()),!0)}),((t,e)=>{let{$from:n,$to:r}=t.selection;if(t.selection instanceof Vu&&t.selection.node.isBlock)return!(!n.parentOffset||!xu(t.doc,n.pos))&&(e&&e(t.tr.split(n.pos).scrollIntoView()),!0);if(!n.parent.isBlock)return!1;if(e){let o=r.parentOffset==r.parent.content.size,i=t.tr;(t.selection instanceof Lu||t.selection instanceof qu)&&i.deleteSelection();let s=0==n.depth?null:Tp(n.node(-1).contentMatchAt(n.indexAfter(-1))),a=o&&s?[{type:s}]:void 0,l=xu(i.doc,i.mapping.map(n.pos),1,a);if(a||l||!xu(i.doc,i.mapping.map(n.pos),1,s?[{type:s}]:void 0)||(s&&(a=[{type:s}]),l=!0),l&&(i.split(i.mapping.map(n.pos),1,a),!o&&!n.parentOffset&&n.parent.type!=s)){let t=i.mapping.map(n.before()),e=i.doc.resolve(t);s&&n.node(-1).canReplaceWith(e.index(),e.index()+1,s)&&i.setNodeMarkup(i.mapping.map(n.before()),s)}e(i.scrollIntoView())}return!0})),"Mod-Enter":$p,Backspace:jp,"Mod-Backspace":jp,"Shift-Backspace":jp,Delete:Fp,"Mod-Delete":Fp,"Mod-a":(t,e)=>(e&&e(t.tr.setSelection(new qu(t.doc))),!0)},Bp={"Ctrl-h":Lp.Backspace,"Alt-Backspace":Lp["Mod-Backspace"],"Ctrl-d":Lp.Delete,"Ctrl-Alt-Backspace":Lp["Mod-Delete"],"Alt-Delete":Lp["Mod-Delete"],"Alt-d":Lp["Mod-Delete"],"Ctrl-a":Ap,"Ctrl-e":Pp};for(let os in Lp)Bp[os]=Lp[os];const Vp=("undefined"!=typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!("undefined"==typeof os||!os.platform)&&"darwin"==os.platform())?Bp:Lp;class Wp{constructor(t,e){var n;this.match=t,this.match=t,this.handler="string"==typeof e?(n=e,function(t,e,r,o){let i=n;if(e[1]){let t=e[0].lastIndexOf(e[1]);i+=e[0].slice(t+e[1].length);let n=(r+=t)-o;n>0&&(i=e[0].slice(t-n,t)+i,r=o)}return t.tr.insertText(i,r,o)}):e}}function qp({rules:t}){let e=new ed({state:{init:()=>null,apply(t,e){let n=t.getMeta(this);return n||(t.selectionSet||t.docChanged?null:e)}},props:{handleTextInput:(n,r,o,i)=>Hp(n,r,o,i,t,e),handleDOMEvents:{compositionend:n=>{setTimeout((()=>{let{$cursor:r}=n.state.selection;r&&Hp(n,r.pos,r.pos,"",t,e)}))}}},isInputRules:!0});return e}function Hp(t,e,n,r,o,i){if(t.composing)return!1;let s=t.state,a=s.doc.resolve(e);if(a.parent.type.spec.code)return!1;let l=a.parent.textBetween(Math.max(0,a.parentOffset-500),a.parentOffset,null,"")+r;for(let c=0;c{let n=t.plugins;for(let r=0;r=0;t--)n.step(r.steps[t].invert(r.docs[t]));if(o.text){let e=n.doc.resolve(o.from).marks();n.replaceWith(o.from,o.to,t.schema.text(o.text,e))}else n.delete(o.from,o.to);e(n)}return!0}}return!1};function Kp(t,e,n=null,r){return new Wp(t,((t,o,i,s)=>{let a=n instanceof Function?n(o):n,l=t.tr.delete(i,s),c=l.doc.resolve(i).blockRange(),u=c&&bu(c,e,a);if(!u)return null;l.wrap(c,u);let d=l.doc.resolve(i-1).nodeBefore;return d&&d.type==e&&Su(l.doc,i-1)&&(!r||r(o,d))&&l.join(i-1),l}))}function Yp(t,e,n=null){return new Wp(t,((t,r,o,i)=>{let s=t.doc.resolve(o),a=n instanceof Function?n(r):n;return s.node(-1).canReplaceWith(s.index(-1),s.indexAfter(-1),e)?t.tr.delete(o,i).setBlockType(o,o,e,a):null}))}new Wp(/--$/,"—"),new Wp(/\.\.\.$/,"…"),new Wp(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"“"),new Wp(/"$/,"”"),new Wp(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"‘"),new Wp(/'$/,"’");const Up=["ol",0],Gp=["ul",0],Xp=["li",0],Zp={attrs:{order:{default:1}},parseDOM:[{tag:"ol",getAttrs:t=>({order:t.hasAttribute("start")?+t.getAttribute("start"):1})}],toDOM:t=>1==t.attrs.order?Up:["ol",{start:t.attrs.order},0]},Qp={parseDOM:[{tag:"ul"}],toDOM:()=>Gp},tm={parseDOM:[{tag:"li"}],toDOM:()=>Xp,defining:!0};function em(t,e){let n={};for(let r in t)n[r]=t[r];for(let r in e)n[r]=e[r];return n}function nm(t,e,n){return t.append({ordered_list:em(Zp,{content:"list_item+",group:n}),bullet_list:em(Qp,{content:"list_item+",group:n}),list_item:em(tm,{content:e})})}function rm(t,e=null){return function(n,r){let{$from:o,$to:i}=n.selection,s=o.blockRange(i),a=!1,l=s;if(!s)return!1;if(s.depth>=2&&o.node(s.depth-1).type.compatibleContent(t)&&0==s.startIndex){if(0==o.index(s.depth-1))return!1;let t=n.doc.resolve(s.start-2);l=new Sc(t,t,s.depth),s.endIndex=0;u--)i=tc.from(n[u].type.create(n[u].attrs,i));t.step(new mu(e.start-(r?2:0),e.end,e.start,e.end,new sc(i,0,0),n.length,!0));let s=0;for(let u=0;u=r.depth-3;t--)o=tc.from(r.node(t).copy(o));let s=r.indexAfter(-1){if(c>-1)return!1;t.isTextblock&&0==t.content.size&&(c=e+1)})),c>-1&&l.setSelection(Ru.near(l.doc.resolve(c))),n(l.scrollIntoView())}return!0}let a=o.pos==r.end()?s.contentMatchAt(0).defaultType:null,l=e.tr.delete(r.pos,o.pos),c=a?[null,{type:a}]:void 0;return!!xu(l.doc,r.pos,2,c)&&(n&&n(l.split(r.pos,2,c).scrollIntoView()),!0)}}function im(t){return function(e,n){let{$from:r,$to:o}=e.selection,i=r.blockRange(o,(e=>e.childCount>0&&e.firstChild.type==t));return!!i&&(!n||(r.node(i.depth-1).type==t?function(t,e,n,r){let o=t.tr,i=r.end,s=r.$to.end(r.depth);im;p--)f-=o.child(p).nodeSize,r.delete(f-1,f+1);let i=r.doc.resolve(n.start),s=i.nodeAfter;if(r.mapping.map(n.end)!=n.start+i.nodeAfter.nodeSize)return!1;let a=0==n.startIndex,l=n.endIndex==o.childCount,c=i.node(-1),u=i.index(-1);if(!c.canReplace(u+(a?0:1),u+1,s.content.append(l?tc.empty:tc.from(o))))return!1;let d=i.pos,h=d+s.nodeSize;return r.step(new mu(d-(a?1:0),h+(l?1:0),d+1,h-1,new sc((a?tc.empty:tc.from(o.copy(tc.empty))).append(l?tc.empty:tc.from(o.copy(tc.empty))),a?0:1,l?0:1),a?0:1)),e(r.scrollIntoView()),!0}(e,n,i)))}}function sm(t){return function(e,n){let{$from:r,$to:o}=e.selection,i=r.blockRange(o,(e=>e.childCount>0&&e.firstChild.type==t));if(!i)return!1;let s=i.startIndex;if(0==s)return!1;let a=i.parent,l=a.child(s-1);if(l.type!=t)return!1;if(n){let r=l.lastChild&&l.lastChild.type==a.type,o=tc.from(r?t.create():null),s=new sc(tc.from(t.create(null,tc.from(a.type.create(null,o)))),r?3:1,0),c=i.start,u=i.end;n(e.tr.step(new mu(c-(r?3:1),u,c,u,s,1,!0)).scrollIntoView())}return!0}}var am=function(){};am.prototype.append=function(t){return t.length?(t=am.from(t),!this.length&&t||t.length<200&&this.leafAppend(t)||this.length<200&&t.leafPrepend(this)||this.appendInner(t)):this},am.prototype.prepend=function(t){return t.length?am.from(t).append(this):this},am.prototype.appendInner=function(t){return new cm(this,t)},am.prototype.slice=function(t,e){return void 0===t&&(t=0),void 0===e&&(e=this.length),t>=e?am.empty:this.sliceInner(Math.max(0,t),Math.min(this.length,e))},am.prototype.get=function(t){if(!(t<0||t>=this.length))return this.getInner(t)},am.prototype.forEach=function(t,e,n){void 0===e&&(e=0),void 0===n&&(n=this.length),e<=n?this.forEachInner(t,e,n,0):this.forEachInvertedInner(t,e,n,0)},am.prototype.map=function(t,e,n){void 0===e&&(e=0),void 0===n&&(n=this.length);var r=[];return this.forEach((function(e,n){return r.push(t(e,n))}),e,n),r},am.from=function(t){return t instanceof am?t:t&&t.length?new lm(t):am.empty};var lm=function(t){function e(e){t.call(this),this.values=e}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var n={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(t,n){return 0==t&&n==this.length?this:new e(this.values.slice(t,n))},e.prototype.getInner=function(t){return this.values[t]},e.prototype.forEachInner=function(t,e,n,r){for(var o=e;o=n;o--)if(!1===t(this.values[o],r+o))return!1},e.prototype.leafAppend=function(t){if(this.length+t.length<=200)return new e(this.values.concat(t.flatten()))},e.prototype.leafPrepend=function(t){if(this.length+t.length<=200)return new e(t.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(e.prototype,n),e}(am);am.empty=new lm([]);var cm=function(t){function e(e,n){t.call(this),this.left=e,this.right=n,this.length=e.length+n.length,this.depth=Math.max(e.depth,n.depth)+1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(t){return to&&!1===this.right.forEachInner(t,Math.max(e-o,0),Math.min(this.length,n)-o,r+o))&&void 0)},e.prototype.forEachInvertedInner=function(t,e,n,r){var o=this.left.length;return!(e>o&&!1===this.right.forEachInvertedInner(t,e-o,Math.max(n,o)-o,r+o))&&(!(n=n?this.right.slice(t-n,e-n):this.left.slice(t,n).append(this.right.slice(0,e-n))},e.prototype.leafAppend=function(t){var n=this.right.leafAppend(t);if(n)return new e(this.left,n)},e.prototype.leafPrepend=function(t){var n=this.left.leafPrepend(t);if(n)return new e(n,this.right)},e.prototype.appendInner=function(t){return this.left.depth>=Math.max(this.right.depth,t.depth)+1?new e(this.left,new e(this.right,t)):new e(this,t)},e}(am),um=am;class dm{constructor(t,e){this.items=t,this.eventCount=e}popEvent(t,e){if(0==this.eventCount)return null;let n,r,o=this.items.length;for(;;o--){if(this.items.get(o-1).selection){--o;break}}e&&(n=this.remapping(o,this.items.length),r=n.maps.length);let i,s,a=t.tr,l=[],c=[];return this.items.forEach(((t,e)=>{if(!t.step)return n||(n=this.remapping(o,e+1),r=n.maps.length),r--,void c.push(t);if(n){c.push(new hm(t.map));let e,o=t.step.map(n.slice(r));o&&a.maybeStep(o).doc&&(e=a.mapping.maps[a.mapping.maps.length-1],l.push(new hm(e,void 0,void 0,l.length+c.length))),r--,e&&n.appendMap(e,r)}else a.maybeStep(t.step);return t.selection?(i=n?t.selection.map(n.slice(r)):t.selection,s=new dm(this.items.slice(0,o).append(c.reverse().concat(l)),this.eventCount-1),!1):void 0}),this.items.length,0),{remaining:s,transform:a,selection:i}}addTransform(t,e,n,r){let o=[],i=this.eventCount,s=this.items,a=!r&&s.length?s.get(s.length-1):null;for(let c=0;cpm&&(s=function(t,e){let n;return t.forEach(((t,r)=>{if(t.selection&&0==e--)return n=r,!1})),t.slice(n)}(s,l),i-=l),new dm(s.append(o),i)}remapping(t,e){let n=new au;return this.items.forEach(((e,r)=>{let o=null!=e.mirrorOffset&&r-e.mirrorOffset>=t?n.maps.length-e.mirrorOffset:void 0;n.appendMap(e.map,o)}),t,e),n}addMaps(t){return 0==this.eventCount?this:new dm(this.items.append(t.map((t=>new hm(t)))),this.eventCount)}rebased(t,e){if(!this.eventCount)return this;let n=[],r=Math.max(0,this.items.length-e),o=t.mapping,i=t.steps.length,s=this.eventCount;this.items.forEach((t=>{t.selection&&s--}),r);let a=e;this.items.forEach((e=>{let r=o.getMirror(--a);if(null==r)return;i=Math.min(i,r);let l=o.maps[r];if(e.step){let i=t.steps[r].invert(t.docs[r]),c=e.selection&&e.selection.map(o.slice(a+1,r));c&&s++,n.push(new hm(l,i,c))}else n.push(new hm(l))}),r);let l=[];for(let d=e;d500&&(u=u.compress(this.items.length-n.length)),u}emptyItemCount(){let t=0;return this.items.forEach((e=>{e.step||t++})),t}compress(t=this.items.length){let e=this.remapping(0,t),n=e.maps.length,r=[],o=0;return this.items.forEach(((i,s)=>{if(s>=t)r.push(i),i.selection&&o++;else if(i.step){let t=i.step.map(e.slice(n)),s=t&&t.getMap();if(n--,s&&e.appendMap(s,n),t){let a=i.selection&&i.selection.map(e.slice(n));a&&o++;let l,c=new hm(s.invert(),t,a),u=r.length-1;(l=r.length&&r[u].merge(c))?r[u]=l:r.push(c)}}else i.map&&n--}),this.items.length,0),new dm(um.from(r.reverse()),o)}}dm.empty=new dm(um.empty,0);class hm{constructor(t,e,n,r){this.map=t,this.step=e,this.selection=n,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let e=t.step.merge(this.step);if(e)return new hm(e.getMap().invert(),e,this.selection)}}}class fm{constructor(t,e,n,r){this.done=t,this.undone=e,this.prevRanges=n,this.prevTime=r}}const pm=20;function mm(t){let e=[];return t.forEach(((t,n,r,o)=>e.push(r,o))),e}function gm(t,e){if(!t)return null;let n=[];for(let r=0;rnew fm(dm.empty,dm.empty,null,0),apply:(e,n,r)=>function(t,e,n,r){let o,i=n.getMeta(xm);if(i)return i.historyState;n.getMeta(Sm)&&(t=new fm(t.done,t.undone,null,0));let s=n.getMeta("appendedTransaction");if(0==n.steps.length)return t;if(s&&s.getMeta(xm))return s.getMeta(xm).redo?new fm(t.done.addTransform(n,void 0,r,wm(e)),t.undone,mm(n.mapping.maps[n.steps.length-1]),t.prevTime):new fm(t.done,t.undone.addTransform(n,void 0,r,wm(e)),null,t.prevTime);if(!1===n.getMeta("addToHistory")||s&&!1===s.getMeta("addToHistory"))return(o=n.getMeta("rebased"))?new fm(t.done.rebased(n,o),t.undone.rebased(n,o),gm(t.prevRanges,n.mapping),t.prevTime):new fm(t.done.addMaps(n.mapping.maps),t.undone.addMaps(n.mapping.maps),gm(t.prevRanges,n.mapping),t.prevTime);{let o=0==t.prevTime||!s&&(t.prevTime<(n.time||0)-r.newGroupDelay||!function(t,e){if(!e)return!1;if(!t.docChanged)return!0;let n=!1;return t.mapping.maps[0].forEach(((t,r)=>{for(let o=0;o=e[o]&&(n=!0)})),n}(n,t.prevRanges)),i=s?gm(t.prevRanges,n.mapping):mm(n.mapping.maps[n.steps.length-1]);return new fm(t.done.addTransform(n,o?e.selection.getBookmark():void 0,r,wm(e)),dm.empty,i,n.time)}}(n,r,e,t)},config:t,props:{handleDOMEvents:{beforeinput(t,e){let n=e.inputType,r="historyUndo"==n?_m:"historyRedo"==n?Om:null;return!!r&&(e.preventDefault(),r(t.state,t.dispatch))}}}})}const _m=(t,e)=>{let n=xm.getState(t);return!(!n||0==n.done.eventCount)&&(e&&vm(n,t,e,!1),!0)},Om=(t,e)=>{let n=xm.getState(t);return!(!n||0==n.undone.eventCount)&&(e&&vm(n,t,e,!0),!0)};function Cm(t){let e=xm.getState(t);return e?e.done.eventCount:0}function Mm(t){let e=xm.getState(t);return e?e.undone.eventCount:0}var Dm={},Tm={},$m={},Em={};Object.defineProperty(Em,"__esModule",{value:!0}),Em.default=void 0;var Nm=Fl.withParams;Em.default=Nm,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.req=t.regex=t.ref=t.len=void 0,Object.defineProperty(t,"withParams",{enumerable:!0,get:function(){return n.default}});var e,n=(e=Em)&&e.__esModule?e:{default:e};function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var o=function(t){if(Array.isArray(t))return!!t.length;if(null==t)return!1;if(!1===t)return!0;if(t instanceof Date)return!isNaN(t.getTime());if("object"===r(t)){for(var e in t)return!0;return!1}return!!String(t).length};t.req=o;t.len=function(t){return Array.isArray(t)?t.length:"object"===r(t)?Object.keys(t).length:String(t).length};t.ref=function(t,e,n){return"function"==typeof t?t.call(e,n):n[t]};t.regex=function(t,e){return(0,n.default)({type:t},(function(t){return!o(t)||e.test(t)}))}}($m),Object.defineProperty(Tm,"__esModule",{value:!0}),Tm.default=void 0;var Am=(0,$m.regex)("alpha",/^[a-zA-Z]*$/);Tm.default=Am;var Pm={};Object.defineProperty(Pm,"__esModule",{value:!0}),Pm.default=void 0;var Im=(0,$m.regex)("alphaNum",/^[a-zA-Z0-9]*$/);Pm.default=Im;var Rm={};Object.defineProperty(Rm,"__esModule",{value:!0}),Rm.default=void 0;var zm=(0,$m.regex)("numeric",/^[0-9]*$/);Rm.default=zm;var jm={};Object.defineProperty(jm,"__esModule",{value:!0}),jm.default=void 0;var Fm=$m;jm.default=function(t,e){return(0,Fm.withParams)({type:"between",min:t,max:e},(function(n){return!(0,Fm.req)(n)||(!/\s/.test(n)||n instanceof Date)&&+t<=+n&&+e>=+n}))};var Lm={};Object.defineProperty(Lm,"__esModule",{value:!0}),Lm.default=void 0;var Bm=(0,$m.regex)("email",/^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i);Lm.default=Bm;var Vm={};Object.defineProperty(Vm,"__esModule",{value:!0}),Vm.default=void 0;var Wm=$m,qm=(0,Wm.withParams)({type:"ipAddress"},(function(t){if(!(0,Wm.req)(t))return!0;if("string"!=typeof t)return!1;var e=t.split(".");return 4===e.length&&e.every(Hm)}));Vm.default=qm;var Hm=function(t){if(t.length>3||0===t.length)return!1;if("0"===t[0]&&"0"!==t)return!1;if(!t.match(/^\d+$/))return!1;var e=0|+t;return e>=0&&e<=255},Jm={};Object.defineProperty(Jm,"__esModule",{value:!0}),Jm.default=void 0;var Km=$m;Jm.default=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:":";return(0,Km.withParams)({type:"macAddress"},(function(e){if(!(0,Km.req)(e))return!0;if("string"!=typeof e)return!1;var n="string"==typeof t&&""!==t?e.split(t):12===e.length||16===e.length?e.match(/.{2}/g):null;return null!==n&&(6===n.length||8===n.length)&&n.every(Ym)}))};var Ym=function(t){return t.toLowerCase().match(/^[0-9a-f]{2}$/)},Um={};Object.defineProperty(Um,"__esModule",{value:!0}),Um.default=void 0;var Gm=$m;Um.default=function(t){return(0,Gm.withParams)({type:"maxLength",max:t},(function(e){return!(0,Gm.req)(e)||(0,Gm.len)(e)<=t}))};var Xm={};Object.defineProperty(Xm,"__esModule",{value:!0}),Xm.default=void 0;var Zm=$m;Xm.default=function(t){return(0,Zm.withParams)({type:"minLength",min:t},(function(e){return!(0,Zm.req)(e)||(0,Zm.len)(e)>=t}))};var Qm={};Object.defineProperty(Qm,"__esModule",{value:!0}),Qm.default=void 0;var tg=$m,eg=(0,tg.withParams)({type:"required"},(function(t){return(0,tg.req)("string"==typeof t?t.trim():t)}));Qm.default=eg;var ng={};Object.defineProperty(ng,"__esModule",{value:!0}),ng.default=void 0;var rg=$m;ng.default=function(t){return(0,rg.withParams)({type:"requiredIf",prop:t},(function(e,n){return!(0,rg.ref)(t,this,n)||(0,rg.req)(e)}))};var og={};Object.defineProperty(og,"__esModule",{value:!0}),og.default=void 0;var ig=$m;og.default=function(t){return(0,ig.withParams)({type:"requiredUnless",prop:t},(function(e,n){return!!(0,ig.ref)(t,this,n)||(0,ig.req)(e)}))};var sg={};Object.defineProperty(sg,"__esModule",{value:!0}),sg.default=void 0;var ag=$m;sg.default=function(t){return(0,ag.withParams)({type:"sameAs",eq:t},(function(e,n){return e===(0,ag.ref)(t,this,n)}))};var lg={};Object.defineProperty(lg,"__esModule",{value:!0}),lg.default=void 0;var cg=(0,$m.regex)("url",/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i);lg.default=cg;var ug={};Object.defineProperty(ug,"__esModule",{value:!0}),ug.default=void 0;var dg=$m;ug.default=function(){for(var t=arguments.length,e=new Array(t),n=0;n0&&e.reduce((function(e,n){return e||n.apply(t,r)}),!1)}))};var hg={};Object.defineProperty(hg,"__esModule",{value:!0}),hg.default=void 0;var fg=$m;hg.default=function(){for(var t=arguments.length,e=new Array(t),n=0;n0&&e.reduce((function(e,n){return e&&n.apply(t,r)}),!0)}))};var pg={};Object.defineProperty(pg,"__esModule",{value:!0}),pg.default=void 0;var mg=$m;pg.default=function(t){return(0,mg.withParams)({type:"not"},(function(e,n){return!(0,mg.req)(e)||!t.call(this,e,n)}))};var gg={};Object.defineProperty(gg,"__esModule",{value:!0}),gg.default=void 0;var vg=$m;gg.default=function(t){return(0,vg.withParams)({type:"minValue",min:t},(function(e){return!(0,vg.req)(e)||(!/\s/.test(e)||e instanceof Date)&&+e>=+t}))};var yg={};Object.defineProperty(yg,"__esModule",{value:!0}),yg.default=void 0;var bg=$m;yg.default=function(t){return(0,bg.withParams)({type:"maxValue",max:t},(function(e){return!(0,bg.req)(e)||(!/\s/.test(e)||e instanceof Date)&&+e<=+t}))};var wg={};Object.defineProperty(wg,"__esModule",{value:!0}),wg.default=void 0;var xg=(0,$m.regex)("integer",/(^[0-9]*$)|(^-[0-9]+$)/);wg.default=xg;var Sg={};Object.defineProperty(Sg,"__esModule",{value:!0}),Sg.default=void 0;var kg=(0,$m.regex)("decimal",/^[-]?\d*(\.\d+)?$/); /**! * Sortable 1.10.2 * @author RubaXa * @author owenm * @license MIT */ -function sg(e){return(sg="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ag(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function lg(){return lg=Object.assign||function(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}ig.default=og,function(e){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"alpha",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(e,"alphaNum",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(e,"and",{enumerable:!0,get:function(){return v.default}}),Object.defineProperty(e,"between",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(e,"decimal",{enumerable:!0,get:function(){return S.default}}),Object.defineProperty(e,"email",{enumerable:!0,get:function(){return s.default}}),e.helpers=void 0,Object.defineProperty(e,"integer",{enumerable:!0,get:function(){return x.default}}),Object.defineProperty(e,"ipAddress",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(e,"macAddress",{enumerable:!0,get:function(){return l.default}}),Object.defineProperty(e,"maxLength",{enumerable:!0,get:function(){return c.default}}),Object.defineProperty(e,"maxValue",{enumerable:!0,get:function(){return w.default}}),Object.defineProperty(e,"minLength",{enumerable:!0,get:function(){return u.default}}),Object.defineProperty(e,"minValue",{enumerable:!0,get:function(){return b.default}}),Object.defineProperty(e,"not",{enumerable:!0,get:function(){return y.default}}),Object.defineProperty(e,"numeric",{enumerable:!0,get:function(){return i.default}}),Object.defineProperty(e,"or",{enumerable:!0,get:function(){return g.default}}),Object.defineProperty(e,"required",{enumerable:!0,get:function(){return d.default}}),Object.defineProperty(e,"requiredIf",{enumerable:!0,get:function(){return h.default}}),Object.defineProperty(e,"requiredUnless",{enumerable:!0,get:function(){return f.default}}),Object.defineProperty(e,"sameAs",{enumerable:!0,get:function(){return p.default}}),Object.defineProperty(e,"url",{enumerable:!0,get:function(){return m.default}});var n=O(dm),r=O(gm),i=O(ym),o=O(wm),s=O(Sm),a=O(Cm),l=O(Dm),c=O(Am),u=O(Nm),d=O(Im),h=O(jm),f=O(Lm),p=O(Vm),m=O(qm),g=O(Jm),v=O(Ym),y=O(Xm),b=O(Zm),w=O(eg),x=O(ng),S=O(ig),k=function(e,n){if(!n&&e&&e.__esModule)return e;if(null===e||"object"!==t(e)&&"function"!=typeof e)return{default:e};var r=C(n);if(r&&r.has(e))return r.get(e);var i={},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var s in e)if("default"!==s&&Object.prototype.hasOwnProperty.call(e,s)){var a=o?Object.getOwnPropertyDescriptor(e,s):null;a&&(a.get||a.set)?Object.defineProperty(i,s,a):i[s]=e[s]}i.default=e,r&&r.set(e,i);return i}(hm);function C(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(C=function(e){return e?n:t})(e)}function O(e){return e&&e.__esModule?e:{default:e}}e.helpers=k}(um);function dg(e){if("undefined"!=typeof window&&window.navigator)return!!navigator.userAgent.match(e)}var hg=dg(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),fg=dg(/Edge/i),pg=dg(/firefox/i),mg=dg(/safari/i)&&!dg(/chrome/i)&&!dg(/android/i),gg=dg(/iP(ad|od|hone)/i),vg=dg(/chrome/i)&&dg(/android/i),yg={capture:!1,passive:!1};function bg(e,t,n){e.addEventListener(t,n,!hg&&yg)}function wg(e,t,n){e.removeEventListener(t,n,!hg&&yg)}function xg(e,t){if(t){if(">"===t[0]&&(t=t.substring(1)),e)try{if(e.matches)return e.matches(t);if(e.msMatchesSelector)return e.msMatchesSelector(t);if(e.webkitMatchesSelector)return e.webkitMatchesSelector(t)}catch(n){return!1}return!1}}function Sg(e){return e.host&&e!==document&&e.host.nodeType?e.host:e.parentNode}function kg(e,t,n,r){if(e){n=n||document;do{if(null!=t&&(">"===t[0]?e.parentNode===n&&xg(e,t):xg(e,t))||r&&e===n)return e;if(e===n)break}while(e=Sg(e))}return null}var Cg,Og=/\s+/g;function Mg(e,t,n){if(e&&t)if(e.classList)e.classList[n?"add":"remove"](t);else{var r=(" "+e.className+" ").replace(Og," ").replace(" "+t+" "," ");e.className=(r+(n?" "+t:"")).replace(Og," ")}}function _g(e,t,n){var r=e&&e.style;if(r){if(void 0===n)return document.defaultView&&document.defaultView.getComputedStyle?n=document.defaultView.getComputedStyle(e,""):e.currentStyle&&(n=e.currentStyle),void 0===t?n:n[t];t in r||-1!==t.indexOf("webkit")||(t="-webkit-"+t),r[t]=n+("string"==typeof n?"":"px")}}function Dg(e,t){var n="";if("string"==typeof e)n=e;else do{var r=_g(e,"transform");r&&"none"!==r&&(n=r+" "+n)}while(!t&&(e=e.parentNode));var i=window.DOMMatrix||window.WebKitCSSMatrix||window.CSSMatrix||window.MSCSSMatrix;return i&&new i(n)}function Tg(e,t,n){if(e){var r=e.getElementsByTagName(t),i=0,o=r.length;if(n)for(;i=o:i<=o))return r;if(r===$g())break;r=zg(r,!1)}return!1}function Ng(e,t,n){for(var r=0,i=0,o=e.children;i2&&void 0!==arguments[2]?arguments[2]:{},r=n.evt,i=ug(n,["evt"]);Jg.pluginEvent.bind(Fv)(e,t,cg({dragEl:Ug,parentEl:Xg,ghostEl:Gg,rootEl:Zg,nextEl:Qg,lastDownEl:ev,cloneEl:tv,cloneHidden:nv,dragStarted:mv,putSortable:lv,activeSortable:Fv.active,originalEvent:r,oldIndex:rv,oldDraggableIndex:ov,newIndex:iv,newDraggableIndex:sv,hideGhostForTarget:Iv,unhideGhostForTarget:Rv,cloneNowHidden:function(){nv=!0},cloneNowShown:function(){nv=!1},dispatchSortableEvent:function(e){Yg({sortable:t,name:e,originalEvent:r})}},i))};function Yg(e){!function(e){var t=e.sortable,n=e.rootEl,r=e.name,i=e.targetEl,o=e.cloneEl,s=e.toEl,a=e.fromEl,l=e.oldIndex,c=e.newIndex,u=e.oldDraggableIndex,d=e.newDraggableIndex,h=e.originalEvent,f=e.putSortable,p=e.extraEventProperties;if(t=t||n&&n[Vg]){var m,g=t.options,v="on"+r.charAt(0).toUpperCase()+r.substr(1);!window.CustomEvent||hg||fg?(m=document.createEvent("Event")).initEvent(r,!0,!0):m=new CustomEvent(r,{bubbles:!0,cancelable:!0}),m.to=s||n,m.from=a||n,m.item=i||n,m.clone=o,m.oldIndex=l,m.newIndex=c,m.oldDraggableIndex=u,m.newDraggableIndex=d,m.originalEvent=h,m.pullMode=f?f.lastPutMode:void 0;var y=cg({},p,Jg.getEventProperties(r,t));for(var b in y)m[b]=y[b];n&&n.dispatchEvent(m),g[v]&&g[v].call(t,m)}}(cg({putSortable:lv,cloneEl:tv,targetEl:Ug,rootEl:Zg,oldIndex:rv,oldDraggableIndex:ov,newIndex:iv,newDraggableIndex:sv},e))}var Ug,Xg,Gg,Zg,Qg,ev,tv,nv,rv,iv,ov,sv,av,lv,cv,uv,dv,hv,fv,pv,mv,gv,vv,yv,bv,wv=!1,xv=!1,Sv=[],kv=!1,Cv=!1,Ov=[],Mv=!1,_v=[],Dv="undefined"!=typeof document,Tv=gg,$v=fg||hg?"cssFloat":"float",Av=Dv&&!vg&&!gg&&"draggable"in document.createElement("div"),Ev=function(){if(Dv){if(hg)return!1;var e=document.createElement("x");return e.style.cssText="pointer-events:auto","auto"===e.style.pointerEvents}}(),Nv=function(e,t){var n=_g(e),r=parseInt(n.width)-parseInt(n.paddingLeft)-parseInt(n.paddingRight)-parseInt(n.borderLeftWidth)-parseInt(n.borderRightWidth),i=Ng(e,0,t),o=Ng(e,1,t),s=i&&_g(i),a=o&&_g(o),l=s&&parseInt(s.marginLeft)+parseInt(s.marginRight)+Ag(i).width,c=a&&parseInt(a.marginLeft)+parseInt(a.marginRight)+Ag(o).width;if("flex"===n.display)return"column"===n.flexDirection||"column-reverse"===n.flexDirection?"vertical":"horizontal";if("grid"===n.display)return n.gridTemplateColumns.split(" ").length<=1?"vertical":"horizontal";if(i&&s.float&&"none"!==s.float){var u="left"===s.float?"left":"right";return!o||"both"!==a.clear&&a.clear!==u?"horizontal":"vertical"}return i&&("block"===s.display||"flex"===s.display||"table"===s.display||"grid"===s.display||l>=r&&"none"===n[$v]||o&&"none"===n[$v]&&l+c>r)?"vertical":"horizontal"},Pv=function(e){function t(e,n){return function(r,i,o,s){var a=r.options.group.name&&i.options.group.name&&r.options.group.name===i.options.group.name;if(null==e&&(n||a))return!0;if(null==e||!1===e)return!1;if(n&&"clone"===e)return e;if("function"==typeof e)return t(e(r,i,o,s),n)(r,i,o,s);var l=(n?r:i).options.group.name;return!0===e||"string"==typeof e&&e===l||e.join&&e.indexOf(l)>-1}}var n={},r=e.group;r&&"object"==sg(r)||(r={name:r}),n.name=r.name,n.checkPull=t(r.pull,!0),n.checkPut=t(r.put),n.revertClone=r.revertClone,e.group=n},Iv=function(){!Ev&&Gg&&_g(Gg,"display","none")},Rv=function(){!Ev&&Gg&&_g(Gg,"display","")};Dv&&document.addEventListener("click",(function(e){if(xv)return e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.stopImmediatePropagation&&e.stopImmediatePropagation(),xv=!1,!1}),!0);var zv=function(e){if(Ug){e=e.touches?e.touches[0]:e;var t=(i=e.clientX,o=e.clientY,Sv.some((function(e){if(!Pg(e)){var t=Ag(e),n=e[Vg].options.emptyInsertThreshold,r=i>=t.left-n&&i<=t.right+n,a=o>=t.top-n&&o<=t.bottom+n;return n&&r&&a?s=e:void 0}})),s);if(t){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=e[r]);n.target=n.rootEl=t,n.preventDefault=void 0,n.stopPropagation=void 0,t[Vg]._onDragOver(n)}}var i,o,s},jv=function(e){Ug&&Ug.parentNode[Vg]._isOutsideThisEl(e.target)};function Fv(e,t){if(!e||!e.nodeType||1!==e.nodeType)throw"Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(e));this.el=e,this.options=t=lg({},t),e[Vg]=this;var n={group:null,sort:!0,disabled:!1,store:null,handle:null,draggable:/^[uo]l$/i.test(e.nodeName)?">li":">*",swapThreshold:1,invertSwap:!1,invertedSwapThreshold:null,removeCloneOnHide:!0,direction:function(){return Nv(e,this.options)},ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",ignore:"a, img",filter:null,preventOnFilter:!0,animation:0,easing:null,setData:function(e,t){e.setData("Text",t.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,fallbackTolerance:0,fallbackOffset:{x:0,y:0},supportPointer:!1!==Fv.supportPointer&&"PointerEvent"in window,emptyInsertThreshold:5};for(var r in Jg.initializePlugins(this,e,n),n)!(r in t)&&(t[r]=n[r]);for(var i in Pv(t),this)"_"===i.charAt(0)&&"function"==typeof this[i]&&(this[i]=this[i].bind(this));this.nativeDraggable=!t.forceFallback&&Av,this.nativeDraggable&&(this.options.touchStartThreshold=1),t.supportPointer?bg(e,"pointerdown",this._onTapStart):(bg(e,"mousedown",this._onTapStart),bg(e,"touchstart",this._onTapStart)),this.nativeDraggable&&(bg(e,"dragover",this),bg(e,"dragenter",this)),Sv.push(this.el),t.store&&t.store.get&&this.sort(t.store.get(this)||[]),lg(this,Wg())}function Lv(e,t,n,r,i,o,s,a){var l,c,u=e[Vg],d=u.options.onMove;return!window.CustomEvent||hg||fg?(l=document.createEvent("Event")).initEvent("move",!0,!0):l=new CustomEvent("move",{bubbles:!0,cancelable:!0}),l.to=t,l.from=e,l.dragged=n,l.draggedRect=r,l.related=i||t,l.relatedRect=o||Ag(t),l.willInsertAfter=a,l.originalEvent=s,e.dispatchEvent(l),d&&(c=d.call(u,l,s)),c}function Bv(e){e.draggable=!1}function Vv(){Mv=!1}function Wv(e){for(var t=e.tagName+e.className+e.src+e.href+e.textContent,n=t.length,r=0;n--;)r+=t.charCodeAt(n);return r.toString(36)}function qv(e){return setTimeout(e,0)}function Hv(e){return clearTimeout(e)}Fv.prototype={constructor:Fv,_isOutsideThisEl:function(e){this.el.contains(e)||e===this.el||(gv=null)},_getDirection:function(e,t){return"function"==typeof this.options.direction?this.options.direction.call(this,e,t,Ug):this.options.direction},_onTapStart:function(e){if(e.cancelable){var t=this,n=this.el,r=this.options,i=r.preventOnFilter,o=e.type,s=e.touches&&e.touches[0]||e.pointerType&&"touch"===e.pointerType&&e,a=(s||e).target,l=e.target.shadowRoot&&(e.path&&e.path[0]||e.composedPath&&e.composedPath()[0])||a,c=r.filter;if(function(e){_v.length=0;var t=e.getElementsByTagName("input"),n=t.length;for(;n--;){var r=t[n];r.checked&&_v.push(r)}}(n),!Ug&&!(/mousedown|pointerdown/.test(o)&&0!==e.button||r.disabled||l.isContentEditable||(a=kg(a,r.draggable,n,!1))&&a.animated||ev===a)){if(rv=Ig(a),ov=Ig(a,r.draggable),"function"==typeof c){if(c.call(this,e,a,this))return Yg({sortable:t,rootEl:l,name:"filter",targetEl:a,toEl:n,fromEl:n}),Kg("filter",t,{evt:e}),void(i&&e.cancelable&&e.preventDefault())}else if(c&&(c=c.split(",").some((function(r){if(r=kg(l,r.trim(),n,!1))return Yg({sortable:t,rootEl:r,name:"filter",targetEl:a,fromEl:n,toEl:n}),Kg("filter",t,{evt:e}),!0}))))return void(i&&e.cancelable&&e.preventDefault());r.handle&&!kg(l,r.handle,n,!1)||this._prepareDragStart(e,s,a)}}},_prepareDragStart:function(e,t,n){var r,i=this,o=i.el,s=i.options,a=o.ownerDocument;if(n&&!Ug&&n.parentNode===o){var l=Ag(n);if(Zg=o,Xg=(Ug=n).parentNode,Qg=Ug.nextSibling,ev=n,av=s.group,Fv.dragged=Ug,cv={target:Ug,clientX:(t||e).clientX,clientY:(t||e).clientY},fv=cv.clientX-l.left,pv=cv.clientY-l.top,this._lastX=(t||e).clientX,this._lastY=(t||e).clientY,Ug.style["will-change"]="all",r=function(){Kg("delayEnded",i,{evt:e}),Fv.eventCanceled?i._onDrop():(i._disableDelayedDragEvents(),!pg&&i.nativeDraggable&&(Ug.draggable=!0),i._triggerDragStart(e,t),Yg({sortable:i,name:"choose",originalEvent:e}),Mg(Ug,s.chosenClass,!0))},s.ignore.split(",").forEach((function(e){Tg(Ug,e.trim(),Bv)})),bg(a,"dragover",zv),bg(a,"mousemove",zv),bg(a,"touchmove",zv),bg(a,"mouseup",i._onDrop),bg(a,"touchend",i._onDrop),bg(a,"touchcancel",i._onDrop),pg&&this.nativeDraggable&&(this.options.touchStartThreshold=4,Ug.draggable=!0),Kg("delayStart",this,{evt:e}),!s.delay||s.delayOnTouchOnly&&!t||this.nativeDraggable&&(fg||hg))r();else{if(Fv.eventCanceled)return void this._onDrop();bg(a,"mouseup",i._disableDelayedDrag),bg(a,"touchend",i._disableDelayedDrag),bg(a,"touchcancel",i._disableDelayedDrag),bg(a,"mousemove",i._delayedDragTouchMoveHandler),bg(a,"touchmove",i._delayedDragTouchMoveHandler),s.supportPointer&&bg(a,"pointermove",i._delayedDragTouchMoveHandler),i._dragStartTimer=setTimeout(r,s.delay)}}},_delayedDragTouchMoveHandler:function(e){var t=e.touches?e.touches[0]:e;Math.max(Math.abs(t.clientX-this._lastX),Math.abs(t.clientY-this._lastY))>=Math.floor(this.options.touchStartThreshold/(this.nativeDraggable&&window.devicePixelRatio||1))&&this._disableDelayedDrag()},_disableDelayedDrag:function(){Ug&&Bv(Ug),clearTimeout(this._dragStartTimer),this._disableDelayedDragEvents()},_disableDelayedDragEvents:function(){var e=this.el.ownerDocument;wg(e,"mouseup",this._disableDelayedDrag),wg(e,"touchend",this._disableDelayedDrag),wg(e,"touchcancel",this._disableDelayedDrag),wg(e,"mousemove",this._delayedDragTouchMoveHandler),wg(e,"touchmove",this._delayedDragTouchMoveHandler),wg(e,"pointermove",this._delayedDragTouchMoveHandler)},_triggerDragStart:function(e,t){t=t||"touch"==e.pointerType&&e,!this.nativeDraggable||t?this.options.supportPointer?bg(document,"pointermove",this._onTouchMove):bg(document,t?"touchmove":"mousemove",this._onTouchMove):(bg(Ug,"dragend",this),bg(Zg,"dragstart",this._onDragStart));try{document.selection?qv((function(){document.selection.empty()})):window.getSelection().removeAllRanges()}catch(n){}},_dragStarted:function(e,t){if(wv=!1,Zg&&Ug){Kg("dragStarted",this,{evt:t}),this.nativeDraggable&&bg(document,"dragover",jv);var n=this.options;!e&&Mg(Ug,n.dragClass,!1),Mg(Ug,n.ghostClass,!0),Fv.active=this,e&&this._appendGhost(),Yg({sortable:this,name:"start",originalEvent:t})}else this._nulling()},_emulateDragOver:function(){if(uv){this._lastX=uv.clientX,this._lastY=uv.clientY,Iv();for(var e=document.elementFromPoint(uv.clientX,uv.clientY),t=e;e&&e.shadowRoot&&(e=e.shadowRoot.elementFromPoint(uv.clientX,uv.clientY))!==t;)t=e;if(Ug.parentNode[Vg]._isOutsideThisEl(e),t)do{if(t[Vg]){if(t[Vg]._onDragOver({clientX:uv.clientX,clientY:uv.clientY,target:e,rootEl:t})&&!this.options.dragoverBubble)break}e=t}while(t=t.parentNode);Rv()}},_onTouchMove:function(e){if(cv){var t=this.options,n=t.fallbackTolerance,r=t.fallbackOffset,i=e.touches?e.touches[0]:e,o=Gg&&Dg(Gg,!0),s=Gg&&o&&o.a,a=Gg&&o&&o.d,l=Tv&&bv&&Rg(bv),c=(i.clientX-cv.clientX+r.x)/(s||1)+(l?l[0]-Ov[0]:0)/(s||1),u=(i.clientY-cv.clientY+r.y)/(a||1)+(l?l[1]-Ov[1]:0)/(a||1);if(!Fv.active&&!wv){if(n&&Math.max(Math.abs(i.clientX-this._lastX),Math.abs(i.clientY-this._lastY))r.right+i||e.clientX<=r.right&&e.clientY>r.bottom&&e.clientX>=r.left:e.clientX>r.right&&e.clientY>r.top||e.clientX<=r.right&&e.clientY>r.bottom+i}(e,i,this)&&!m.animated){if(m===Ug)return $(!1);if(m&&o===e.target&&(s=m),s&&(n=Ag(s)),!1!==Lv(Zg,o,Ug,t,s,n,e,!!s))return T(),o.appendChild(Ug),Xg=o,A(),$(!0)}else if(s.parentNode===o){n=Ag(s);var g,v,y,b=Ug.parentNode!==o,w=!function(e,t,n){var r=n?e.left:e.top,i=n?e.right:e.bottom,o=n?e.width:e.height,s=n?t.left:t.top,a=n?t.right:t.bottom,l=n?t.width:t.height;return r===s||i===a||r+o/2===s+l/2}(Ug.animated&&Ug.toRect||t,s.animated&&s.toRect||n,i),x=i?"top":"left",S=Eg(s,"top","top")||Eg(Ug,"top","top"),k=S?S.scrollTop:void 0;if(gv!==s&&(v=n[x],kv=!1,Cv=!w&&a.invertSwap||b),g=function(e,t,n,r,i,o,s,a){var l=r?e.clientY:e.clientX,c=r?n.height:n.width,u=r?n.top:n.left,d=r?n.bottom:n.right,h=!1;if(!s)if(a&&yvu+c*o/2:ld-yv)return-vv}else if(l>u+c*(1-i)/2&&ld-c*o/2))return l>u+c/2?1:-1;return 0}(e,s,n,i,w?1:a.swapThreshold,null==a.invertedSwapThreshold?a.swapThreshold:a.invertedSwapThreshold,Cv,gv===s),0!==g){var C=Ig(Ug);do{C-=g,y=Xg.children[C]}while(y&&("none"===_g(y,"display")||y===Gg))}if(0===g||y===s)return $(!1);gv=s,vv=g;var O=s.nextElementSibling,M=!1,_=Lv(Zg,o,Ug,t,s,n,e,M=1===g);if(!1!==_)return 1!==_&&-1!==_||(M=1===_),Mv=!0,setTimeout(Vv,30),T(),M&&!O?o.appendChild(Ug):s.parentNode.insertBefore(Ug,M?O:s),S&&Lg(S,0,k-S.scrollTop),Xg=Ug.parentNode,void 0===v||Cv||(yv=Math.abs(v-Ag(s)[x])),A(),$(!0)}if(o.contains(Ug))return $(!1)}return!1}function D(a,l){Kg(a,f,cg({evt:e,isOwner:u,axis:i?"vertical":"horizontal",revert:r,dragRect:t,targetRect:n,canSort:d,fromSortable:h,target:s,completed:$,onMove:function(n,r){return Lv(Zg,o,Ug,t,n,Ag(n),e,r)},changed:A},l))}function T(){D("dragOverAnimationCapture"),f.captureAnimationState(),f!==h&&h.captureAnimationState()}function $(t){return D("dragOverCompleted",{insertion:t}),t&&(u?c._hideClone():c._showClone(f),f!==h&&(Mg(Ug,lv?lv.options.ghostClass:c.options.ghostClass,!1),Mg(Ug,a.ghostClass,!0)),lv!==f&&f!==Fv.active?lv=f:f===Fv.active&&lv&&(lv=null),h===f&&(f._ignoreWhileAnimating=s),f.animateAll((function(){D("dragOverAnimationComplete"),f._ignoreWhileAnimating=null})),f!==h&&(h.animateAll(),h._ignoreWhileAnimating=null)),(s===Ug&&!Ug.animated||s===o&&!s.animated)&&(gv=null),a.dragoverBubble||e.rootEl||s===document||(Ug.parentNode[Vg]._isOutsideThisEl(e.target),!t&&zv(e)),!a.dragoverBubble&&e.stopPropagation&&e.stopPropagation(),p=!0}function A(){iv=Ig(Ug),sv=Ig(Ug,a.draggable),Yg({sortable:f,name:"change",toEl:o,newIndex:iv,newDraggableIndex:sv,originalEvent:e})}},_ignoreWhileAnimating:null,_offMoveEvents:function(){wg(document,"mousemove",this._onTouchMove),wg(document,"touchmove",this._onTouchMove),wg(document,"pointermove",this._onTouchMove),wg(document,"dragover",zv),wg(document,"mousemove",zv),wg(document,"touchmove",zv)},_offUpEvents:function(){var e=this.el.ownerDocument;wg(e,"mouseup",this._onDrop),wg(e,"touchend",this._onDrop),wg(e,"pointerup",this._onDrop),wg(e,"touchcancel",this._onDrop),wg(document,"selectstart",this)},_onDrop:function(e){var t=this.el,n=this.options;iv=Ig(Ug),sv=Ig(Ug,n.draggable),Kg("drop",this,{evt:e}),Xg=Ug&&Ug.parentNode,iv=Ig(Ug),sv=Ig(Ug,n.draggable),Fv.eventCanceled||(wv=!1,Cv=!1,kv=!1,clearInterval(this._loopId),clearTimeout(this._dragStartTimer),Hv(this.cloneId),Hv(this._dragStartId),this.nativeDraggable&&(wg(document,"drop",this),wg(t,"dragstart",this._onDragStart)),this._offMoveEvents(),this._offUpEvents(),mg&&_g(document.body,"user-select",""),_g(Ug,"transform",""),e&&(mv&&(e.cancelable&&e.preventDefault(),!n.dropBubble&&e.stopPropagation()),Gg&&Gg.parentNode&&Gg.parentNode.removeChild(Gg),(Zg===Xg||lv&&"clone"!==lv.lastPutMode)&&tv&&tv.parentNode&&tv.parentNode.removeChild(tv),Ug&&(this.nativeDraggable&&wg(Ug,"dragend",this),Bv(Ug),Ug.style["will-change"]="",mv&&!wv&&Mg(Ug,lv?lv.options.ghostClass:this.options.ghostClass,!1),Mg(Ug,this.options.chosenClass,!1),Yg({sortable:this,name:"unchoose",toEl:Xg,newIndex:null,newDraggableIndex:null,originalEvent:e}),Zg!==Xg?(iv>=0&&(Yg({rootEl:Xg,name:"add",toEl:Xg,fromEl:Zg,originalEvent:e}),Yg({sortable:this,name:"remove",toEl:Xg,originalEvent:e}),Yg({rootEl:Xg,name:"sort",toEl:Xg,fromEl:Zg,originalEvent:e}),Yg({sortable:this,name:"sort",toEl:Xg,originalEvent:e})),lv&&lv.save()):iv!==rv&&iv>=0&&(Yg({sortable:this,name:"update",toEl:Xg,originalEvent:e}),Yg({sortable:this,name:"sort",toEl:Xg,originalEvent:e})),Fv.active&&(null!=iv&&-1!==iv||(iv=rv,sv=ov),Yg({sortable:this,name:"end",toEl:Xg,originalEvent:e}),this.save())))),this._nulling()},_nulling:function(){Kg("nulling",this),Zg=Ug=Xg=Gg=Qg=tv=ev=nv=cv=uv=mv=iv=sv=rv=ov=gv=vv=lv=av=Fv.dragged=Fv.ghost=Fv.clone=Fv.active=null,_v.forEach((function(e){e.checked=!0})),_v.length=dv=hv=0},handleEvent:function(e){switch(e.type){case"drop":case"dragend":this._onDrop(e);break;case"dragenter":case"dragover":Ug&&(this._onDragOver(e),function(e){e.dataTransfer&&(e.dataTransfer.dropEffect="move");e.cancelable&&e.preventDefault()}(e));break;case"selectstart":e.preventDefault()}},toArray:function(){for(var e,t=[],n=this.el.children,r=0,i=n.length,o=this.options;re.replace(ay,((e,t)=>t?t.toUpperCase():""))));function cy(e){null!==e.parentElement&&e.parentElement.removeChild(e)}function uy(e,t,n){const r=0===n?e.children[0]:e.children[n-1].nextSibling;e.insertBefore(t,r)}function dy(e,t){this.$nextTick((()=>this.$emit(e.toLowerCase(),t)))}function hy(e){return t=>{null!==this.realList&&this["onDrag"+e](t),dy.call(this,e,t)}}function fy(e){return["transition-group","TransitionGroup"].includes(e)}function py(e,t,n){return e[n]||(t[n]?t[n]():void 0)}const my=["Start","Add","Remove","Update","End"],gy=["Choose","Unchoose","Sort","Filter","Clone"],vy=["Move",...my,...gy].map((e=>"on"+e));var yy=null;const by={name:"draggable",inheritAttrs:!1,props:{options:Object,list:{type:Array,required:!1,default:null},value:{type:Array,required:!1,default:null},noTransitionOnDrag:{type:Boolean,default:!1},clone:{type:Function,default:e=>e},element:{type:String,default:"div"},tag:{type:String,default:null},move:{type:Function,default:null},componentData:{type:Object,required:!1,default:null}},data:()=>({transitionMode:!1,noneFunctionalComponentMode:!1}),render(e){const t=this.$slots.default;this.transitionMode=function(e){if(!e||1!==e.length)return!1;const[{componentOptions:t}]=e;return!!t&&fy(t.tag)}(t);const{children:n,headerOffset:r,footerOffset:i}=function(e,t,n){let r=0,i=0;const o=py(t,n,"header");o&&(r=o.length,e=e?[...o,...e]:[...o]);const s=py(t,n,"footer");return s&&(i=s.length,e=e?[...e,...s]:[...s]),{children:e,headerOffset:r,footerOffset:i}}(t,this.$slots,this.$scopedSlots);this.headerOffset=r,this.footerOffset=i;const o=function(e,t){let n=null;const r=(e,t)=>{n=function(e,t,n){return void 0===n||((e=e||{})[t]=n),e}(n,e,t)};if(r("attrs",Object.keys(e).filter((e=>"id"===e||e.startsWith("data-"))).reduce(((t,n)=>(t[n]=e[n],t)),{})),!t)return n;const{on:i,props:o,attrs:s}=t;return r("on",i),r("props",o),Object.assign(n.attrs,s),n}(this.$attrs,this.componentData);return e(this.getTag(),o,n)},created(){null!==this.list&&null!==this.value&&sy.error("Value and list props are mutually exclusive! Please set one or another."),"div"!==this.element&&sy.warn("Element props is deprecated please use tag props instead. See https://github.com/SortableJS/Vue.Draggable/blob/master/documentation/migrate.md#element-props"),void 0!==this.options&&sy.warn("Options props is deprecated, add sortable options directly as vue.draggable item, or use v-bind. See https://github.com/SortableJS/Vue.Draggable/blob/master/documentation/migrate.md#options-props")},mounted(){if(this.noneFunctionalComponentMode=this.getTag().toLowerCase()!==this.$el.nodeName.toLowerCase()&&!this.getIsFunctional(),this.noneFunctionalComponentMode&&this.transitionMode)throw new Error(`Transition-group inside component is not supported. Please alter tag value or remove transition-group. Current tag value: ${this.getTag()}`);const e={};my.forEach((t=>{e["on"+t]=hy.call(this,t)})),gy.forEach((t=>{e["on"+t]=dy.bind(this,t)}));const t=Object.keys(this.$attrs).reduce(((e,t)=>(e[ly(t)]=this.$attrs[t],e)),{}),n=Object.assign({},this.options,t,e,{onMove:(e,t)=>this.onDragMove(e,t)});!("draggable"in n)&&(n.draggable=">*"),this._sortable=new Fv(this.rootContainer,n),this.computeIndexes()},beforeDestroy(){void 0!==this._sortable&&this._sortable.destroy()},computed:{rootContainer(){return this.transitionMode?this.$el.children[0]:this.$el},realList(){return this.list?this.list:this.value}},watch:{options:{handler(e){this.updateOptions(e)},deep:!0},$attrs:{handler(e){this.updateOptions(e)},deep:!0},realList(){this.computeIndexes()}},methods:{getIsFunctional(){const{fnOptions:e}=this._vnode;return e&&e.functional},getTag(){return this.tag||this.element},updateOptions(e){for(var t in e){const n=ly(t);-1===vy.indexOf(n)&&this._sortable.option(n,e[t])}},getChildrenNodes(){if(this.noneFunctionalComponentMode)return this.$children[0].$slots.default;const e=this.$slots.default;return this.transitionMode?e[0].child.$slots.default:e},computeIndexes(){this.$nextTick((()=>{this.visibleIndexes=function(e,t,n,r){if(!e)return[];const i=e.map((e=>e.elm)),o=t.length-r,s=[...t].map(((e,t)=>t>=o?i.length:i.indexOf(e)));return n?s.filter((e=>-1!==e)):s}(this.getChildrenNodes(),this.rootContainer.children,this.transitionMode,this.footerOffset)}))},getUnderlyingVm(e){const t=function(e,t){return e.map((e=>e.elm)).indexOf(t)}(this.getChildrenNodes()||[],e);if(-1===t)return null;return{index:t,element:this.realList[t]}},getUnderlyingPotencialDraggableComponent:({__vue__:e})=>e&&e.$options&&fy(e.$options._componentTag)?e.$parent:!("realList"in e)&&1===e.$children.length&&"realList"in e.$children[0]?e.$children[0]:e,emitChanges(e){this.$nextTick((()=>{this.$emit("change",e)}))},alterList(e){if(this.list)return void e(this.list);const t=[...this.value];e(t),this.$emit("input",t)},spliceList(){this.alterList((e=>e.splice(...arguments)))},updatePosition(e,t){this.alterList((n=>n.splice(t,0,n.splice(e,1)[0])))},getRelatedContextFromMoveEvent({to:e,related:t}){const n=this.getUnderlyingPotencialDraggableComponent(e);if(!n)return{component:n};const r=n.realList,i={list:r,component:n};if(e!==t&&r&&n.getUnderlyingVm){const e=n.getUnderlyingVm(t);if(e)return Object.assign(e,i)}return i},getVmIndex(e){const t=this.visibleIndexes,n=t.length;return e>n-1?n:t[e]},getComponent(){return this.$slots.default[0].componentInstance},resetTransitionData(e){if(!this.noTransitionOnDrag||!this.transitionMode)return;this.getChildrenNodes()[e].data=null;const t=this.getComponent();t.children=[],t.kept=void 0},onDragStart(e){this.context=this.getUnderlyingVm(e.item),e.item._underlying_vm_=this.clone(this.context.element),yy=e.item},onDragAdd(e){const t=e.item._underlying_vm_;if(void 0===t)return;cy(e.item);const n=this.getVmIndex(e.newIndex);this.spliceList(n,0,t),this.computeIndexes();const r={element:t,newIndex:n};this.emitChanges({added:r})},onDragRemove(e){if(uy(this.rootContainer,e.item,e.oldIndex),"clone"===e.pullMode)return void cy(e.clone);const t=this.context.index;this.spliceList(t,1);const n={element:this.context.element,oldIndex:t};this.resetTransitionData(t),this.emitChanges({removed:n})},onDragUpdate(e){cy(e.item),uy(e.from,e.item,e.oldIndex);const t=this.context.index,n=this.getVmIndex(e.newIndex);this.updatePosition(t,n);const r={element:this.context.element,oldIndex:t,newIndex:n};this.emitChanges({moved:r})},updateProperty(e,t){e.hasOwnProperty(t)&&(e[t]+=this.headerOffset)},computeFutureIndex(e,t){if(!e.element)return 0;const n=[...t.to.children].filter((e=>"none"!==e.style.display)),r=n.indexOf(t.related),i=e.component.getVmIndex(r);return-1!==n.indexOf(yy)||!t.willInsertAfter?i:i+1},onDragMove(e,t){const n=this.move;if(!n||!this.realList)return!0;const r=this.getRelatedContextFromMoveEvent(e),i=this.context,o=this.computeFutureIndex(r,e);Object.assign(i,{futureIndex:o});return n(Object.assign({},e,{relatedContext:r,draggedContext:i}),t)},onDragEnd(){this.computeIndexes(),yy=null}}};"undefined"!=typeof window&&"Vue"in window&&window.Vue.component("draggable",by);export{cm as A,om as B,um as C,Mc as D,Iu as E,Rl as F,by as G,ul as H,Op as I,El as J,Cu as N,zu as P,Vl as S,Su as T,Mn as V,Wa as a,Za as b,rl as c,tl as d,bp as e,hp as f,Tp as g,$p as h,jp as i,Lp as j,Vp as k,Bp as l,qa as m,op as n,Cc as o,Mp as p,Lf as q,Rc as r,vp as s,yp as t,Dp as u,Cp as v,Fp as w,sm as x,am as y,lm as z}; +function _g(t){return(_g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function Og(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Cg(){return Cg=Object.assign||function(t){for(var e=1;e=0||(o[n]=t[n]);return o}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}Sg.default=kg,function(t){function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"alpha",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(t,"alphaNum",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(t,"and",{enumerable:!0,get:function(){return v.default}}),Object.defineProperty(t,"between",{enumerable:!0,get:function(){return i.default}}),Object.defineProperty(t,"decimal",{enumerable:!0,get:function(){return S.default}}),Object.defineProperty(t,"email",{enumerable:!0,get:function(){return s.default}}),t.helpers=void 0,Object.defineProperty(t,"integer",{enumerable:!0,get:function(){return x.default}}),Object.defineProperty(t,"ipAddress",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(t,"macAddress",{enumerable:!0,get:function(){return l.default}}),Object.defineProperty(t,"maxLength",{enumerable:!0,get:function(){return c.default}}),Object.defineProperty(t,"maxValue",{enumerable:!0,get:function(){return w.default}}),Object.defineProperty(t,"minLength",{enumerable:!0,get:function(){return u.default}}),Object.defineProperty(t,"minValue",{enumerable:!0,get:function(){return b.default}}),Object.defineProperty(t,"not",{enumerable:!0,get:function(){return y.default}}),Object.defineProperty(t,"numeric",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(t,"or",{enumerable:!0,get:function(){return g.default}}),Object.defineProperty(t,"required",{enumerable:!0,get:function(){return d.default}}),Object.defineProperty(t,"requiredIf",{enumerable:!0,get:function(){return h.default}}),Object.defineProperty(t,"requiredUnless",{enumerable:!0,get:function(){return f.default}}),Object.defineProperty(t,"sameAs",{enumerable:!0,get:function(){return p.default}}),Object.defineProperty(t,"url",{enumerable:!0,get:function(){return m.default}});var n=O(Tm),r=O(Pm),o=O(Rm),i=O(jm),s=O(Lm),a=O(Vm),l=O(Jm),c=O(Um),u=O(Xm),d=O(Qm),h=O(ng),f=O(og),p=O(sg),m=O(lg),g=O(ug),v=O(hg),y=O(pg),b=O(gg),w=O(yg),x=O(wg),S=O(Sg),k=function(t,n){if(!n&&t&&t.__esModule)return t;if(null===t||"object"!==e(t)&&"function"!=typeof t)return{default:t};var r=_(n);if(r&&r.has(t))return r.get(t);var o={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var s in t)if("default"!==s&&Object.prototype.hasOwnProperty.call(t,s)){var a=i?Object.getOwnPropertyDescriptor(t,s):null;a&&(a.get||a.set)?Object.defineProperty(o,s,a):o[s]=t[s]}o.default=t,r&&r.set(t,o);return o}($m);function _(t){if("function"!=typeof WeakMap)return null;var e=new WeakMap,n=new WeakMap;return(_=function(t){return t?n:e})(t)}function O(t){return t&&t.__esModule?t:{default:t}}t.helpers=k}(Dm);function Tg(t){if("undefined"!=typeof window&&window.navigator)return!!navigator.userAgent.match(t)}var $g=Tg(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),Eg=Tg(/Edge/i),Ng=Tg(/firefox/i),Ag=Tg(/safari/i)&&!Tg(/chrome/i)&&!Tg(/android/i),Pg=Tg(/iP(ad|od|hone)/i),Ig=Tg(/chrome/i)&&Tg(/android/i),Rg={capture:!1,passive:!1};function zg(t,e,n){t.addEventListener(e,n,!$g&&Rg)}function jg(t,e,n){t.removeEventListener(e,n,!$g&&Rg)}function Fg(t,e){if(e){if(">"===e[0]&&(e=e.substring(1)),t)try{if(t.matches)return t.matches(e);if(t.msMatchesSelector)return t.msMatchesSelector(e);if(t.webkitMatchesSelector)return t.webkitMatchesSelector(e)}catch(n){return!1}return!1}}function Lg(t){return t.host&&t!==document&&t.host.nodeType?t.host:t.parentNode}function Bg(t,e,n,r){if(t){n=n||document;do{if(null!=e&&(">"===e[0]?t.parentNode===n&&Fg(t,e):Fg(t,e))||r&&t===n)return t;if(t===n)break}while(t=Lg(t))}return null}var Vg,Wg=/\s+/g;function qg(t,e,n){if(t&&e)if(t.classList)t.classList[n?"add":"remove"](e);else{var r=(" "+t.className+" ").replace(Wg," ").replace(" "+e+" "," ");t.className=(r+(n?" "+e:"")).replace(Wg," ")}}function Hg(t,e,n){var r=t&&t.style;if(r){if(void 0===n)return document.defaultView&&document.defaultView.getComputedStyle?n=document.defaultView.getComputedStyle(t,""):t.currentStyle&&(n=t.currentStyle),void 0===e?n:n[e];e in r||-1!==e.indexOf("webkit")||(e="-webkit-"+e),r[e]=n+("string"==typeof n?"":"px")}}function Jg(t,e){var n="";if("string"==typeof t)n=t;else do{var r=Hg(t,"transform");r&&"none"!==r&&(n=r+" "+n)}while(!e&&(t=t.parentNode));var o=window.DOMMatrix||window.WebKitCSSMatrix||window.CSSMatrix||window.MSCSSMatrix;return o&&new o(n)}function Kg(t,e,n){if(t){var r=t.getElementsByTagName(e),o=0,i=r.length;if(n)for(;o=i:o<=i))return r;if(r===Yg())break;r=ev(r,!1)}return!1}function Xg(t,e,n){for(var r=0,o=0,i=t.children;o2&&void 0!==arguments[2]?arguments[2]:{},r=n.evt,o=Dg(n,["evt"]);uv.pluginEvent.bind(ry)(t,e,Mg({dragEl:fv,parentEl:pv,ghostEl:mv,rootEl:gv,nextEl:vv,lastDownEl:yv,cloneEl:bv,cloneHidden:wv,dragStarted:Av,putSortable:Cv,activeSortable:ry.active,originalEvent:r,oldIndex:xv,oldDraggableIndex:kv,newIndex:Sv,newDraggableIndex:_v,hideGhostForTarget:Qv,unhideGhostForTarget:ty,cloneNowHidden:function(){wv=!0},cloneNowShown:function(){wv=!1},dispatchSortableEvent:function(t){hv({sortable:e,name:t,originalEvent:r})}},o))};function hv(t){!function(t){var e=t.sortable,n=t.rootEl,r=t.name,o=t.targetEl,i=t.cloneEl,s=t.toEl,a=t.fromEl,l=t.oldIndex,c=t.newIndex,u=t.oldDraggableIndex,d=t.newDraggableIndex,h=t.originalEvent,f=t.putSortable,p=t.extraEventProperties;if(e=e||n&&n[sv]){var m,g=e.options,v="on"+r.charAt(0).toUpperCase()+r.substr(1);!window.CustomEvent||$g||Eg?(m=document.createEvent("Event")).initEvent(r,!0,!0):m=new CustomEvent(r,{bubbles:!0,cancelable:!0}),m.to=s||n,m.from=a||n,m.item=o||n,m.clone=i,m.oldIndex=l,m.newIndex=c,m.oldDraggableIndex=u,m.newDraggableIndex=d,m.originalEvent=h,m.pullMode=f?f.lastPutMode:void 0;var y=Mg({},p,uv.getEventProperties(r,e));for(var b in y)m[b]=y[b];n&&n.dispatchEvent(m),g[v]&&g[v].call(e,m)}}(Mg({putSortable:Cv,cloneEl:bv,targetEl:fv,rootEl:gv,oldIndex:xv,oldDraggableIndex:kv,newIndex:Sv,newDraggableIndex:_v},t))}var fv,pv,mv,gv,vv,yv,bv,wv,xv,Sv,kv,_v,Ov,Cv,Mv,Dv,Tv,$v,Ev,Nv,Av,Pv,Iv,Rv,zv,jv=!1,Fv=!1,Lv=[],Bv=!1,Vv=!1,Wv=[],qv=!1,Hv=[],Jv="undefined"!=typeof document,Kv=Pg,Yv=Eg||$g?"cssFloat":"float",Uv=Jv&&!Ig&&!Pg&&"draggable"in document.createElement("div"),Gv=function(){if(Jv){if($g)return!1;var t=document.createElement("x");return t.style.cssText="pointer-events:auto","auto"===t.style.pointerEvents}}(),Xv=function(t,e){var n=Hg(t),r=parseInt(n.width)-parseInt(n.paddingLeft)-parseInt(n.paddingRight)-parseInt(n.borderLeftWidth)-parseInt(n.borderRightWidth),o=Xg(t,0,e),i=Xg(t,1,e),s=o&&Hg(o),a=i&&Hg(i),l=s&&parseInt(s.marginLeft)+parseInt(s.marginRight)+Ug(o).width,c=a&&parseInt(a.marginLeft)+parseInt(a.marginRight)+Ug(i).width;if("flex"===n.display)return"column"===n.flexDirection||"column-reverse"===n.flexDirection?"vertical":"horizontal";if("grid"===n.display)return n.gridTemplateColumns.split(" ").length<=1?"vertical":"horizontal";if(o&&s.float&&"none"!==s.float){var u="left"===s.float?"left":"right";return!i||"both"!==a.clear&&a.clear!==u?"horizontal":"vertical"}return o&&("block"===s.display||"flex"===s.display||"table"===s.display||"grid"===s.display||l>=r&&"none"===n[Yv]||i&&"none"===n[Yv]&&l+c>r)?"vertical":"horizontal"},Zv=function(t){function e(t,n){return function(r,o,i,s){var a=r.options.group.name&&o.options.group.name&&r.options.group.name===o.options.group.name;if(null==t&&(n||a))return!0;if(null==t||!1===t)return!1;if(n&&"clone"===t)return t;if("function"==typeof t)return e(t(r,o,i,s),n)(r,o,i,s);var l=(n?r:o).options.group.name;return!0===t||"string"==typeof t&&t===l||t.join&&t.indexOf(l)>-1}}var n={},r=t.group;r&&"object"==_g(r)||(r={name:r}),n.name=r.name,n.checkPull=e(r.pull,!0),n.checkPut=e(r.put),n.revertClone=r.revertClone,t.group=n},Qv=function(){!Gv&&mv&&Hg(mv,"display","none")},ty=function(){!Gv&&mv&&Hg(mv,"display","")};Jv&&document.addEventListener("click",(function(t){if(Fv)return t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.stopImmediatePropagation&&t.stopImmediatePropagation(),Fv=!1,!1}),!0);var ey=function(t){if(fv){t=t.touches?t.touches[0]:t;var e=(o=t.clientX,i=t.clientY,Lv.some((function(t){if(!Zg(t)){var e=Ug(t),n=t[sv].options.emptyInsertThreshold,r=o>=e.left-n&&o<=e.right+n,a=i>=e.top-n&&i<=e.bottom+n;return n&&r&&a?s=t:void 0}})),s);if(e){var n={};for(var r in t)t.hasOwnProperty(r)&&(n[r]=t[r]);n.target=n.rootEl=e,n.preventDefault=void 0,n.stopPropagation=void 0,e[sv]._onDragOver(n)}}var o,i,s},ny=function(t){fv&&fv.parentNode[sv]._isOutsideThisEl(t.target)};function ry(t,e){if(!t||!t.nodeType||1!==t.nodeType)throw"Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(t));this.el=t,this.options=e=Cg({},e),t[sv]=this;var n={group:null,sort:!0,disabled:!1,store:null,handle:null,draggable:/^[uo]l$/i.test(t.nodeName)?">li":">*",swapThreshold:1,invertSwap:!1,invertedSwapThreshold:null,removeCloneOnHide:!0,direction:function(){return Xv(t,this.options)},ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",ignore:"a, img",filter:null,preventOnFilter:!0,animation:0,easing:null,setData:function(t,e){t.setData("Text",e.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,fallbackTolerance:0,fallbackOffset:{x:0,y:0},supportPointer:!1!==ry.supportPointer&&"PointerEvent"in window,emptyInsertThreshold:5};for(var r in uv.initializePlugins(this,t,n),n)!(r in e)&&(e[r]=n[r]);for(var o in Zv(e),this)"_"===o.charAt(0)&&"function"==typeof this[o]&&(this[o]=this[o].bind(this));this.nativeDraggable=!e.forceFallback&&Uv,this.nativeDraggable&&(this.options.touchStartThreshold=1),e.supportPointer?zg(t,"pointerdown",this._onTapStart):(zg(t,"mousedown",this._onTapStart),zg(t,"touchstart",this._onTapStart)),this.nativeDraggable&&(zg(t,"dragover",this),zg(t,"dragenter",this)),Lv.push(this.el),e.store&&e.store.get&&this.sort(e.store.get(this)||[]),Cg(this,av())}function oy(t,e,n,r,o,i,s,a){var l,c,u=t[sv],d=u.options.onMove;return!window.CustomEvent||$g||Eg?(l=document.createEvent("Event")).initEvent("move",!0,!0):l=new CustomEvent("move",{bubbles:!0,cancelable:!0}),l.to=e,l.from=t,l.dragged=n,l.draggedRect=r,l.related=o||e,l.relatedRect=i||Ug(e),l.willInsertAfter=a,l.originalEvent=s,t.dispatchEvent(l),d&&(c=d.call(u,l,s)),c}function iy(t){t.draggable=!1}function sy(){qv=!1}function ay(t){for(var e=t.tagName+t.className+t.src+t.href+t.textContent,n=e.length,r=0;n--;)r+=e.charCodeAt(n);return r.toString(36)}function ly(t){return setTimeout(t,0)}function cy(t){return clearTimeout(t)}ry.prototype={constructor:ry,_isOutsideThisEl:function(t){this.el.contains(t)||t===this.el||(Pv=null)},_getDirection:function(t,e){return"function"==typeof this.options.direction?this.options.direction.call(this,t,e,fv):this.options.direction},_onTapStart:function(t){if(t.cancelable){var e=this,n=this.el,r=this.options,o=r.preventOnFilter,i=t.type,s=t.touches&&t.touches[0]||t.pointerType&&"touch"===t.pointerType&&t,a=(s||t).target,l=t.target.shadowRoot&&(t.path&&t.path[0]||t.composedPath&&t.composedPath()[0])||a,c=r.filter;if(function(t){Hv.length=0;var e=t.getElementsByTagName("input"),n=e.length;for(;n--;){var r=e[n];r.checked&&Hv.push(r)}}(n),!fv&&!(/mousedown|pointerdown/.test(i)&&0!==t.button||r.disabled||l.isContentEditable||(a=Bg(a,r.draggable,n,!1))&&a.animated||yv===a)){if(xv=Qg(a),kv=Qg(a,r.draggable),"function"==typeof c){if(c.call(this,t,a,this))return hv({sortable:e,rootEl:l,name:"filter",targetEl:a,toEl:n,fromEl:n}),dv("filter",e,{evt:t}),void(o&&t.cancelable&&t.preventDefault())}else if(c&&(c=c.split(",").some((function(r){if(r=Bg(l,r.trim(),n,!1))return hv({sortable:e,rootEl:r,name:"filter",targetEl:a,fromEl:n,toEl:n}),dv("filter",e,{evt:t}),!0}))))return void(o&&t.cancelable&&t.preventDefault());r.handle&&!Bg(l,r.handle,n,!1)||this._prepareDragStart(t,s,a)}}},_prepareDragStart:function(t,e,n){var r,o=this,i=o.el,s=o.options,a=i.ownerDocument;if(n&&!fv&&n.parentNode===i){var l=Ug(n);if(gv=i,pv=(fv=n).parentNode,vv=fv.nextSibling,yv=n,Ov=s.group,ry.dragged=fv,Mv={target:fv,clientX:(e||t).clientX,clientY:(e||t).clientY},Ev=Mv.clientX-l.left,Nv=Mv.clientY-l.top,this._lastX=(e||t).clientX,this._lastY=(e||t).clientY,fv.style["will-change"]="all",r=function(){dv("delayEnded",o,{evt:t}),ry.eventCanceled?o._onDrop():(o._disableDelayedDragEvents(),!Ng&&o.nativeDraggable&&(fv.draggable=!0),o._triggerDragStart(t,e),hv({sortable:o,name:"choose",originalEvent:t}),qg(fv,s.chosenClass,!0))},s.ignore.split(",").forEach((function(t){Kg(fv,t.trim(),iy)})),zg(a,"dragover",ey),zg(a,"mousemove",ey),zg(a,"touchmove",ey),zg(a,"mouseup",o._onDrop),zg(a,"touchend",o._onDrop),zg(a,"touchcancel",o._onDrop),Ng&&this.nativeDraggable&&(this.options.touchStartThreshold=4,fv.draggable=!0),dv("delayStart",this,{evt:t}),!s.delay||s.delayOnTouchOnly&&!e||this.nativeDraggable&&(Eg||$g))r();else{if(ry.eventCanceled)return void this._onDrop();zg(a,"mouseup",o._disableDelayedDrag),zg(a,"touchend",o._disableDelayedDrag),zg(a,"touchcancel",o._disableDelayedDrag),zg(a,"mousemove",o._delayedDragTouchMoveHandler),zg(a,"touchmove",o._delayedDragTouchMoveHandler),s.supportPointer&&zg(a,"pointermove",o._delayedDragTouchMoveHandler),o._dragStartTimer=setTimeout(r,s.delay)}}},_delayedDragTouchMoveHandler:function(t){var e=t.touches?t.touches[0]:t;Math.max(Math.abs(e.clientX-this._lastX),Math.abs(e.clientY-this._lastY))>=Math.floor(this.options.touchStartThreshold/(this.nativeDraggable&&window.devicePixelRatio||1))&&this._disableDelayedDrag()},_disableDelayedDrag:function(){fv&&iy(fv),clearTimeout(this._dragStartTimer),this._disableDelayedDragEvents()},_disableDelayedDragEvents:function(){var t=this.el.ownerDocument;jg(t,"mouseup",this._disableDelayedDrag),jg(t,"touchend",this._disableDelayedDrag),jg(t,"touchcancel",this._disableDelayedDrag),jg(t,"mousemove",this._delayedDragTouchMoveHandler),jg(t,"touchmove",this._delayedDragTouchMoveHandler),jg(t,"pointermove",this._delayedDragTouchMoveHandler)},_triggerDragStart:function(t,e){e=e||"touch"==t.pointerType&&t,!this.nativeDraggable||e?this.options.supportPointer?zg(document,"pointermove",this._onTouchMove):zg(document,e?"touchmove":"mousemove",this._onTouchMove):(zg(fv,"dragend",this),zg(gv,"dragstart",this._onDragStart));try{document.selection?ly((function(){document.selection.empty()})):window.getSelection().removeAllRanges()}catch(n){}},_dragStarted:function(t,e){if(jv=!1,gv&&fv){dv("dragStarted",this,{evt:e}),this.nativeDraggable&&zg(document,"dragover",ny);var n=this.options;!t&&qg(fv,n.dragClass,!1),qg(fv,n.ghostClass,!0),ry.active=this,t&&this._appendGhost(),hv({sortable:this,name:"start",originalEvent:e})}else this._nulling()},_emulateDragOver:function(){if(Dv){this._lastX=Dv.clientX,this._lastY=Dv.clientY,Qv();for(var t=document.elementFromPoint(Dv.clientX,Dv.clientY),e=t;t&&t.shadowRoot&&(t=t.shadowRoot.elementFromPoint(Dv.clientX,Dv.clientY))!==e;)e=t;if(fv.parentNode[sv]._isOutsideThisEl(t),e)do{if(e[sv]){if(e[sv]._onDragOver({clientX:Dv.clientX,clientY:Dv.clientY,target:t,rootEl:e})&&!this.options.dragoverBubble)break}t=e}while(e=e.parentNode);ty()}},_onTouchMove:function(t){if(Mv){var e=this.options,n=e.fallbackTolerance,r=e.fallbackOffset,o=t.touches?t.touches[0]:t,i=mv&&Jg(mv,!0),s=mv&&i&&i.a,a=mv&&i&&i.d,l=Kv&&zv&&tv(zv),c=(o.clientX-Mv.clientX+r.x)/(s||1)+(l?l[0]-Wv[0]:0)/(s||1),u=(o.clientY-Mv.clientY+r.y)/(a||1)+(l?l[1]-Wv[1]:0)/(a||1);if(!ry.active&&!jv){if(n&&Math.max(Math.abs(o.clientX-this._lastX),Math.abs(o.clientY-this._lastY))r.right+o||t.clientX<=r.right&&t.clientY>r.bottom&&t.clientX>=r.left:t.clientX>r.right&&t.clientY>r.top||t.clientX<=r.right&&t.clientY>r.bottom+o}(t,o,this)&&!m.animated){if(m===fv)return $(!1);if(m&&i===t.target&&(s=m),s&&(n=Ug(s)),!1!==oy(gv,i,fv,e,s,n,t,!!s))return T(),i.appendChild(fv),pv=i,E(),$(!0)}else if(s.parentNode===i){n=Ug(s);var g,v,y,b=fv.parentNode!==i,w=!function(t,e,n){var r=n?t.left:t.top,o=n?t.right:t.bottom,i=n?t.width:t.height,s=n?e.left:e.top,a=n?e.right:e.bottom,l=n?e.width:e.height;return r===s||o===a||r+i/2===s+l/2}(fv.animated&&fv.toRect||e,s.animated&&s.toRect||n,o),x=o?"top":"left",S=Gg(s,"top","top")||Gg(fv,"top","top"),k=S?S.scrollTop:void 0;if(Pv!==s&&(v=n[x],Bv=!1,Vv=!w&&a.invertSwap||b),g=function(t,e,n,r,o,i,s,a){var l=r?t.clientY:t.clientX,c=r?n.height:n.width,u=r?n.top:n.left,d=r?n.bottom:n.right,h=!1;if(!s)if(a&&Rvu+c*i/2:ld-Rv)return-Iv}else if(l>u+c*(1-o)/2&&ld-c*i/2))return l>u+c/2?1:-1;return 0}(t,s,n,o,w?1:a.swapThreshold,null==a.invertedSwapThreshold?a.swapThreshold:a.invertedSwapThreshold,Vv,Pv===s),0!==g){var _=Qg(fv);do{_-=g,y=pv.children[_]}while(y&&("none"===Hg(y,"display")||y===mv))}if(0===g||y===s)return $(!1);Pv=s,Iv=g;var O=s.nextElementSibling,C=!1,M=oy(gv,i,fv,e,s,n,t,C=1===g);if(!1!==M)return 1!==M&&-1!==M||(C=1===M),qv=!0,setTimeout(sy,30),T(),C&&!O?i.appendChild(fv):s.parentNode.insertBefore(fv,C?O:s),S&&ov(S,0,k-S.scrollTop),pv=fv.parentNode,void 0===v||Vv||(Rv=Math.abs(v-Ug(s)[x])),E(),$(!0)}if(i.contains(fv))return $(!1)}return!1}function D(a,l){dv(a,f,Mg({evt:t,isOwner:u,axis:o?"vertical":"horizontal",revert:r,dragRect:e,targetRect:n,canSort:d,fromSortable:h,target:s,completed:$,onMove:function(n,r){return oy(gv,i,fv,e,n,Ug(n),t,r)},changed:E},l))}function T(){D("dragOverAnimationCapture"),f.captureAnimationState(),f!==h&&h.captureAnimationState()}function $(e){return D("dragOverCompleted",{insertion:e}),e&&(u?c._hideClone():c._showClone(f),f!==h&&(qg(fv,Cv?Cv.options.ghostClass:c.options.ghostClass,!1),qg(fv,a.ghostClass,!0)),Cv!==f&&f!==ry.active?Cv=f:f===ry.active&&Cv&&(Cv=null),h===f&&(f._ignoreWhileAnimating=s),f.animateAll((function(){D("dragOverAnimationComplete"),f._ignoreWhileAnimating=null})),f!==h&&(h.animateAll(),h._ignoreWhileAnimating=null)),(s===fv&&!fv.animated||s===i&&!s.animated)&&(Pv=null),a.dragoverBubble||t.rootEl||s===document||(fv.parentNode[sv]._isOutsideThisEl(t.target),!e&&ey(t)),!a.dragoverBubble&&t.stopPropagation&&t.stopPropagation(),p=!0}function E(){Sv=Qg(fv),_v=Qg(fv,a.draggable),hv({sortable:f,name:"change",toEl:i,newIndex:Sv,newDraggableIndex:_v,originalEvent:t})}},_ignoreWhileAnimating:null,_offMoveEvents:function(){jg(document,"mousemove",this._onTouchMove),jg(document,"touchmove",this._onTouchMove),jg(document,"pointermove",this._onTouchMove),jg(document,"dragover",ey),jg(document,"mousemove",ey),jg(document,"touchmove",ey)},_offUpEvents:function(){var t=this.el.ownerDocument;jg(t,"mouseup",this._onDrop),jg(t,"touchend",this._onDrop),jg(t,"pointerup",this._onDrop),jg(t,"touchcancel",this._onDrop),jg(document,"selectstart",this)},_onDrop:function(t){var e=this.el,n=this.options;Sv=Qg(fv),_v=Qg(fv,n.draggable),dv("drop",this,{evt:t}),pv=fv&&fv.parentNode,Sv=Qg(fv),_v=Qg(fv,n.draggable),ry.eventCanceled||(jv=!1,Vv=!1,Bv=!1,clearInterval(this._loopId),clearTimeout(this._dragStartTimer),cy(this.cloneId),cy(this._dragStartId),this.nativeDraggable&&(jg(document,"drop",this),jg(e,"dragstart",this._onDragStart)),this._offMoveEvents(),this._offUpEvents(),Ag&&Hg(document.body,"user-select",""),Hg(fv,"transform",""),t&&(Av&&(t.cancelable&&t.preventDefault(),!n.dropBubble&&t.stopPropagation()),mv&&mv.parentNode&&mv.parentNode.removeChild(mv),(gv===pv||Cv&&"clone"!==Cv.lastPutMode)&&bv&&bv.parentNode&&bv.parentNode.removeChild(bv),fv&&(this.nativeDraggable&&jg(fv,"dragend",this),iy(fv),fv.style["will-change"]="",Av&&!jv&&qg(fv,Cv?Cv.options.ghostClass:this.options.ghostClass,!1),qg(fv,this.options.chosenClass,!1),hv({sortable:this,name:"unchoose",toEl:pv,newIndex:null,newDraggableIndex:null,originalEvent:t}),gv!==pv?(Sv>=0&&(hv({rootEl:pv,name:"add",toEl:pv,fromEl:gv,originalEvent:t}),hv({sortable:this,name:"remove",toEl:pv,originalEvent:t}),hv({rootEl:pv,name:"sort",toEl:pv,fromEl:gv,originalEvent:t}),hv({sortable:this,name:"sort",toEl:pv,originalEvent:t})),Cv&&Cv.save()):Sv!==xv&&Sv>=0&&(hv({sortable:this,name:"update",toEl:pv,originalEvent:t}),hv({sortable:this,name:"sort",toEl:pv,originalEvent:t})),ry.active&&(null!=Sv&&-1!==Sv||(Sv=xv,_v=kv),hv({sortable:this,name:"end",toEl:pv,originalEvent:t}),this.save())))),this._nulling()},_nulling:function(){dv("nulling",this),gv=fv=pv=mv=vv=bv=yv=wv=Mv=Dv=Av=Sv=_v=xv=kv=Pv=Iv=Cv=Ov=ry.dragged=ry.ghost=ry.clone=ry.active=null,Hv.forEach((function(t){t.checked=!0})),Hv.length=Tv=$v=0},handleEvent:function(t){switch(t.type){case"drop":case"dragend":this._onDrop(t);break;case"dragenter":case"dragover":fv&&(this._onDragOver(t),function(t){t.dataTransfer&&(t.dataTransfer.dropEffect="move");t.cancelable&&t.preventDefault()}(t));break;case"selectstart":t.preventDefault()}},toArray:function(){for(var t,e=[],n=this.el.children,r=0,o=n.length,i=this.options;rt.replace(Oy,((t,e)=>e?e.toUpperCase():""))));function My(t){null!==t.parentElement&&t.parentElement.removeChild(t)}function Dy(t,e,n){const r=0===n?t.children[0]:t.children[n-1].nextSibling;t.insertBefore(e,r)}function Ty(t,e){this.$nextTick((()=>this.$emit(t.toLowerCase(),e)))}function $y(t){return e=>{null!==this.realList&&this["onDrag"+t](e),Ty.call(this,t,e)}}function Ey(t){return["transition-group","TransitionGroup"].includes(t)}function Ny(t,e,n){return t[n]||(e[n]?e[n]():void 0)}const Ay=["Start","Add","Remove","Update","End"],Py=["Choose","Unchoose","Sort","Filter","Clone"],Iy=["Move",...Ay,...Py].map((t=>"on"+t));var Ry=null;const zy={name:"draggable",inheritAttrs:!1,props:{options:Object,list:{type:Array,required:!1,default:null},value:{type:Array,required:!1,default:null},noTransitionOnDrag:{type:Boolean,default:!1},clone:{type:Function,default:t=>t},element:{type:String,default:"div"},tag:{type:String,default:null},move:{type:Function,default:null},componentData:{type:Object,required:!1,default:null}},data:()=>({transitionMode:!1,noneFunctionalComponentMode:!1}),render(t){const e=this.$slots.default;this.transitionMode=function(t){if(!t||1!==t.length)return!1;const[{componentOptions:e}]=t;return!!e&&Ey(e.tag)}(e);const{children:n,headerOffset:r,footerOffset:o}=function(t,e,n){let r=0,o=0;const i=Ny(e,n,"header");i&&(r=i.length,t=t?[...i,...t]:[...i]);const s=Ny(e,n,"footer");return s&&(o=s.length,t=t?[...t,...s]:[...s]),{children:t,headerOffset:r,footerOffset:o}}(e,this.$slots,this.$scopedSlots);this.headerOffset=r,this.footerOffset=o;const i=function(t,e){let n=null;const r=(t,e)=>{n=function(t,e,n){return void 0===n||((t=t||{})[e]=n),t}(n,t,e)};if(r("attrs",Object.keys(t).filter((t=>"id"===t||t.startsWith("data-"))).reduce(((e,n)=>(e[n]=t[n],e)),{})),!e)return n;const{on:o,props:i,attrs:s}=e;return r("on",o),r("props",i),Object.assign(n.attrs,s),n}(this.$attrs,this.componentData);return t(this.getTag(),i,n)},created(){null!==this.list&&null!==this.value&&_y.error("Value and list props are mutually exclusive! Please set one or another."),"div"!==this.element&&_y.warn("Element props is deprecated please use tag props instead. See https://github.com/SortableJS/Vue.Draggable/blob/master/documentation/migrate.md#element-props"),void 0!==this.options&&_y.warn("Options props is deprecated, add sortable options directly as vue.draggable item, or use v-bind. See https://github.com/SortableJS/Vue.Draggable/blob/master/documentation/migrate.md#options-props")},mounted(){if(this.noneFunctionalComponentMode=this.getTag().toLowerCase()!==this.$el.nodeName.toLowerCase()&&!this.getIsFunctional(),this.noneFunctionalComponentMode&&this.transitionMode)throw new Error(`Transition-group inside component is not supported. Please alter tag value or remove transition-group. Current tag value: ${this.getTag()}`);const t={};Ay.forEach((e=>{t["on"+e]=$y.call(this,e)})),Py.forEach((e=>{t["on"+e]=Ty.bind(this,e)}));const e=Object.keys(this.$attrs).reduce(((t,e)=>(t[Cy(e)]=this.$attrs[e],t)),{}),n=Object.assign({},this.options,e,t,{onMove:(t,e)=>this.onDragMove(t,e)});!("draggable"in n)&&(n.draggable=">*"),this._sortable=new ry(this.rootContainer,n),this.computeIndexes()},beforeDestroy(){void 0!==this._sortable&&this._sortable.destroy()},computed:{rootContainer(){return this.transitionMode?this.$el.children[0]:this.$el},realList(){return this.list?this.list:this.value}},watch:{options:{handler(t){this.updateOptions(t)},deep:!0},$attrs:{handler(t){this.updateOptions(t)},deep:!0},realList(){this.computeIndexes()}},methods:{getIsFunctional(){const{fnOptions:t}=this._vnode;return t&&t.functional},getTag(){return this.tag||this.element},updateOptions(t){for(var e in t){const n=Cy(e);-1===Iy.indexOf(n)&&this._sortable.option(n,t[e])}},getChildrenNodes(){if(this.noneFunctionalComponentMode)return this.$children[0].$slots.default;const t=this.$slots.default;return this.transitionMode?t[0].child.$slots.default:t},computeIndexes(){this.$nextTick((()=>{this.visibleIndexes=function(t,e,n,r){if(!t)return[];const o=t.map((t=>t.elm)),i=e.length-r,s=[...e].map(((t,e)=>e>=i?o.length:o.indexOf(t)));return n?s.filter((t=>-1!==t)):s}(this.getChildrenNodes(),this.rootContainer.children,this.transitionMode,this.footerOffset)}))},getUnderlyingVm(t){const e=function(t,e){return t.map((t=>t.elm)).indexOf(e)}(this.getChildrenNodes()||[],t);if(-1===e)return null;return{index:e,element:this.realList[e]}},getUnderlyingPotencialDraggableComponent:({__vue__:t})=>t&&t.$options&&Ey(t.$options._componentTag)?t.$parent:!("realList"in t)&&1===t.$children.length&&"realList"in t.$children[0]?t.$children[0]:t,emitChanges(t){this.$nextTick((()=>{this.$emit("change",t)}))},alterList(t){if(this.list)return void t(this.list);const e=[...this.value];t(e),this.$emit("input",e)},spliceList(){this.alterList((t=>t.splice(...arguments)))},updatePosition(t,e){this.alterList((n=>n.splice(e,0,n.splice(t,1)[0])))},getRelatedContextFromMoveEvent({to:t,related:e}){const n=this.getUnderlyingPotencialDraggableComponent(t);if(!n)return{component:n};const r=n.realList,o={list:r,component:n};if(t!==e&&r&&n.getUnderlyingVm){const t=n.getUnderlyingVm(e);if(t)return Object.assign(t,o)}return o},getVmIndex(t){const e=this.visibleIndexes,n=e.length;return t>n-1?n:e[t]},getComponent(){return this.$slots.default[0].componentInstance},resetTransitionData(t){if(!this.noTransitionOnDrag||!this.transitionMode)return;this.getChildrenNodes()[t].data=null;const e=this.getComponent();e.children=[],e.kept=void 0},onDragStart(t){this.context=this.getUnderlyingVm(t.item),t.item._underlying_vm_=this.clone(this.context.element),Ry=t.item},onDragAdd(t){const e=t.item._underlying_vm_;if(void 0===e)return;My(t.item);const n=this.getVmIndex(t.newIndex);this.spliceList(n,0,e),this.computeIndexes();const r={element:e,newIndex:n};this.emitChanges({added:r})},onDragRemove(t){if(Dy(this.rootContainer,t.item,t.oldIndex),"clone"===t.pullMode)return void My(t.clone);const e=this.context.index;this.spliceList(e,1);const n={element:this.context.element,oldIndex:e};this.resetTransitionData(e),this.emitChanges({removed:n})},onDragUpdate(t){My(t.item),Dy(t.from,t.item,t.oldIndex);const e=this.context.index,n=this.getVmIndex(t.newIndex);this.updatePosition(e,n);const r={element:this.context.element,oldIndex:e,newIndex:n};this.emitChanges({moved:r})},updateProperty(t,e){t.hasOwnProperty(e)&&(t[e]+=this.headerOffset)},computeFutureIndex(t,e){if(!t.element)return 0;const n=[...e.to.children].filter((t=>"none"!==t.style.display)),r=n.indexOf(e.related),o=t.component.getVmIndex(r);return-1!==n.indexOf(Ry)||!e.willInsertAfter?o:o+1},onDragMove(t,e){const n=this.move;if(!n||!this.realList)return!0;const r=this.getRelatedContextFromMoveEvent(t),o=this.context,i=this.computeFutureIndex(r,t);Object.assign(o,{futureIndex:i});return n(Object.assign({},t,{relatedContext:r,draggedContext:o}),e)},onDragEnd(){this.computeIndexes(),Ry=null}}};"undefined"!=typeof window&&"Vue"in window&&window.Vue.component("draggable",zy);export{Mm as A,km as B,Dm as C,qc as D,Qu as E,tc as F,zy as G,Dl as H,Wp as I,Gl as J,Vu as N,ed as P,sc as S,Lu as T,Bn as V,al as a,gl as b,xl as c,bl as d,zp as e,$p as f,Kp as g,Yp as h,nm as i,om as j,sm as k,im as l,ll as m,kp as n,Vc as o,qp as p,op as q,tu as r,Ip as s,Rp as t,Jp as u,Vp as v,rm as w,_m as x,Om as y,Cm as z}; diff --git a/kirby/router.php b/kirby/router.php index 456f24a..10386c7 100755 --- a/kirby/router.php +++ b/kirby/router.php @@ -1,12 +1,12 @@ data($method, ...$args); - } - - /** - * Creates a new API instance - * - * @param array $props - */ - public function __construct(array $props) - { - $this->setProperties($props); - } - - /** - * Runs the authentication method - * if set - * - * @return mixed - */ - public function authenticate() - { - if ($auth = $this->authentication()) { - return $auth->call($this); - } - - return true; - } - - /** - * Returns the authentication callback - * - * @return \Closure|null - */ - public function authentication() - { - return $this->authentication; - } - - /** - * Execute an API call for the given path, - * request method and optional request data - * - * @param string|null $path - * @param string $method - * @param array $requestData - * @return mixed - * @throws \Kirby\Exception\NotFoundException - * @throws \Exception - */ - public function call(string $path = null, string $method = 'GET', array $requestData = []) - { - $path = rtrim($path ?? '', '/'); - - $this->setRequestMethod($method); - $this->setRequestData($requestData); - - $this->router = new Router($this->routes()); - $this->route = $this->router->find($path, $method); - $auth = $this->route->attributes()['auth'] ?? true; - - if ($auth !== false) { - $user = $this->authenticate(); - - // set PHP locales based on *user* language - // so that e.g. strftime() gets formatted correctly - if (is_a($user, 'Kirby\Cms\User') === true) { - $language = $user->language(); - - // get the locale from the translation - $translation = $user->kirby()->translation($language); - $locale = ($translation !== null) ? $translation->locale() : $language; - - // provide some variants as fallbacks to be - // compatible with as many systems as possible - $locales = [ - $locale . '.UTF-8', - $locale . '.UTF8', - $locale . '.ISO8859-1', - $locale, - $language, - setlocale(LC_ALL, 0) // fall back to the previously defined locale - ]; - - // set the locales that are relevant for string formatting - // *don't* set LC_CTYPE to avoid breaking other parts of the system - setlocale(LC_MONETARY, $locales); - setlocale(LC_NUMERIC, $locales); - setlocale(LC_TIME, $locales); - } - } - - // don't throw pagination errors if pagination - // page is out of bounds - $validate = Pagination::$validate; - Pagination::$validate = false; - - $output = $this->route->action()->call($this, ...$this->route->arguments()); - - // restore old pagination validation mode - Pagination::$validate = $validate; - - if ( - is_object($output) === true && - is_a($output, 'Kirby\\Http\\Response') !== true - ) { - return $this->resolve($output)->toResponse(); - } - - return $output; - } - - /** - * Setter and getter for an API collection - * - * @param string $name - * @param array|null $collection - * @return \Kirby\Api\Collection - * @throws \Kirby\Exception\NotFoundException If no collection for `$name` exists - * @throws \Exception - */ - public function collection(string $name, $collection = null) - { - if (isset($this->collections[$name]) === false) { - throw new NotFoundException(sprintf('The collection "%s" does not exist', $name)); - } - - return new Collection($this, $collection, $this->collections[$name]); - } - - /** - * Returns the collections definition - * - * @return array - */ - public function collections(): array - { - return $this->collections; - } - - /** - * Returns the injected data array - * or certain parts of it by key - * - * @param string|null $key - * @param mixed ...$args - * @return mixed - * - * @throws \Kirby\Exception\NotFoundException If no data for `$key` exists - */ - public function data($key = null, ...$args) - { - if ($key === null) { - return $this->data; - } - - if ($this->hasData($key) === false) { - throw new NotFoundException(sprintf('Api data for "%s" does not exist', $key)); - } - - // lazy-load data wrapped in Closures - if (is_a($this->data[$key], 'Closure') === true) { - return $this->data[$key]->call($this, ...$args); - } - - return $this->data[$key]; - } - - /** - * Returns the debugging flag - * - * @return bool - */ - public function debug(): bool - { - return $this->debug; - } - - /** - * Checks if injected data exists for the given key - * - * @param string $key - * @return bool - */ - public function hasData(string $key): bool - { - return isset($this->data[$key]) === true; - } - - /** - * Matches an object with an array item - * based on the `type` field - * - * @param array models or collections - * @param mixed $object - * - * @return string key of match - */ - protected function match(array $array, $object = null) - { - foreach ($array as $definition => $model) { - if (is_a($object, $model['type']) === true) { - return $definition; - } - } - } - - /** - * Returns an API model instance by name - * - * @param string|null $name - * @param mixed $object - * @return \Kirby\Api\Model - * - * @throws \Kirby\Exception\NotFoundException If no model for `$name` exists - */ - public function model(string $name = null, $object = null) - { - // Try to auto-match object with API models - if ($name === null) { - if ($model = $this->match($this->models, $object)) { - $name = $model; - } - } - - if (isset($this->models[$name]) === false) { - throw new NotFoundException(sprintf('The model "%s" does not exist', $name)); - } - - return new Model($this, $object, $this->models[$name]); - } - - /** - * Returns all model definitions - * - * @return array - */ - public function models(): array - { - return $this->models; - } - - /** - * Getter for request data - * Can either get all the data - * or certain parts of it. - * - * @param string|null $type - * @param string|null $key - * @param mixed $default - * @return mixed - */ - public function requestData(string $type = null, string $key = null, $default = null) - { - if ($type === null) { - return $this->requestData; - } - - if ($key === null) { - return $this->requestData[$type] ?? []; - } - - $data = array_change_key_case($this->requestData($type)); - $key = strtolower($key); - - return $data[$key] ?? $default; - } - - /** - * Returns the request body if available - * - * @param string|null $key - * @param mixed $default - * @return mixed - */ - public function requestBody(string $key = null, $default = null) - { - return $this->requestData('body', $key, $default); - } - - /** - * Returns the files from the request if available - * - * @param string|null $key - * @param mixed $default - * @return mixed - */ - public function requestFiles(string $key = null, $default = null) - { - return $this->requestData('files', $key, $default); - } - - /** - * Returns all headers from the request if available - * - * @param string|null $key - * @param mixed $default - * @return mixed - */ - public function requestHeaders(string $key = null, $default = null) - { - return $this->requestData('headers', $key, $default); - } - - /** - * Returns the request method - * - * @return string - */ - public function requestMethod(): string - { - return $this->requestMethod; - } - - /** - * Returns the request query if available - * - * @param string|null $key - * @param mixed $default - * @return mixed - */ - public function requestQuery(string $key = null, $default = null) - { - return $this->requestData('query', $key, $default); - } - - /** - * Turns a Kirby object into an - * API model or collection representation - * - * @param mixed $object - * @return \Kirby\Api\Model|\Kirby\Api\Collection - * - * @throws \Kirby\Exception\NotFoundException If `$object` cannot be resolved - */ - public function resolve($object) - { - if (is_a($object, 'Kirby\Api\Model') === true || is_a($object, 'Kirby\Api\Collection') === true) { - return $object; - } - - if ($model = $this->match($this->models, $object)) { - return $this->model($model, $object); - } - - if ($collection = $this->match($this->collections, $object)) { - return $this->collection($collection, $object); - } - - throw new NotFoundException(sprintf('The object "%s" cannot be resolved', get_class($object))); - } - - /** - * Returns all defined routes - * - * @return array - */ - public function routes(): array - { - return $this->routes; - } - - /** - * Setter for the authentication callback - * - * @param \Closure|null $authentication - * @return $this - */ - protected function setAuthentication(Closure $authentication = null) - { - $this->authentication = $authentication; - return $this; - } - - /** - * Setter for the collections definition - * - * @param array|null $collections - * @return $this - */ - protected function setCollections(array $collections = null) - { - if ($collections !== null) { - $this->collections = array_change_key_case($collections); - } - return $this; - } - - /** - * Setter for the injected data - * - * @param array|null $data - * @return $this - */ - protected function setData(array $data = null) - { - $this->data = $data ?? []; - return $this; - } - - /** - * Setter for the debug flag - * - * @param bool $debug - * @return $this - */ - protected function setDebug(bool $debug = false) - { - $this->debug = $debug; - return $this; - } - - /** - * Setter for the model definitions - * - * @param array|null $models - * @return $this - */ - protected function setModels(array $models = null) - { - if ($models !== null) { - $this->models = array_change_key_case($models); - } - - return $this; - } - - /** - * Setter for the request data - * - * @param array|null $requestData - * @return $this - */ - protected function setRequestData(array $requestData = null) - { - $defaults = [ - 'query' => [], - 'body' => [], - 'files' => [] - ]; - - $this->requestData = array_merge($defaults, (array)$requestData); - return $this; - } - - /** - * Setter for the request method - * - * @param string|null $requestMethod - * @return $this - */ - protected function setRequestMethod(string $requestMethod = null) - { - $this->requestMethod = $requestMethod ?? 'GET'; - return $this; - } - - /** - * Setter for the route definitions - * - * @param array|null $routes - * @return $this - */ - protected function setRoutes(array $routes = null) - { - $this->routes = $routes ?? []; - return $this; - } - - /** - * Renders the API call - * - * @param string $path - * @param string $method - * @param array $requestData - * @return mixed - */ - public function render(string $path, $method = 'GET', array $requestData = []) - { - try { - $result = $this->call($path, $method, $requestData); - } catch (Throwable $e) { - $result = $this->responseForException($e); - } - - if ($result === null) { - $result = $this->responseFor404(); - } elseif ($result === false) { - $result = $this->responseFor400(); - } elseif ($result === true) { - $result = $this->responseFor200(); - } - - if (is_array($result) === false) { - return $result; - } - - // pretty print json data - $pretty = (bool)($requestData['query']['pretty'] ?? false) === true; - - if (($result['status'] ?? 'ok') === 'error') { - $code = $result['code'] ?? 400; - - // sanitize the error code - if ($code < 400 || $code > 599) { - $code = 500; - } - - return Response::json($result, $code, $pretty); - } - - return Response::json($result, 200, $pretty); - } - - /** - * Returns a 200 - ok - * response array. - * - * @return array - */ - public function responseFor200(): array - { - return [ - 'status' => 'ok', - 'message' => 'ok', - 'code' => 200 - ]; - } - - /** - * Returns a 400 - bad request - * response array. - * - * @return array - */ - public function responseFor400(): array - { - return [ - 'status' => 'error', - 'message' => 'bad request', - 'code' => 400, - ]; - } - - /** - * Returns a 404 - not found - * response array. - * - * @return array - */ - public function responseFor404(): array - { - return [ - 'status' => 'error', - 'message' => 'not found', - 'code' => 404, - ]; - } - - /** - * Creates the response array for - * an exception. Kirby exceptions will - * have more information - * - * @param \Throwable $e - * @return array - */ - public function responseForException(Throwable $e): array - { - if (isset($this->kirby) === true) { - $docRoot = $this->kirby->environment()->get('DOCUMENT_ROOT'); - } else { - $docRoot = $_SERVER['DOCUMENT_ROOT'] ?? null; - } - - // prepare the result array for all exception types - $result = [ - 'status' => 'error', - 'message' => $e->getMessage(), - 'code' => empty($e->getCode()) === true ? 500 : $e->getCode(), - 'exception' => get_class($e), - 'key' => null, - 'file' => F::relativepath($e->getFile(), $docRoot), - 'line' => $e->getLine(), - 'details' => [], - 'route' => $this->route ? $this->route->pattern() : null - ]; - - // extend the information for Kirby Exceptions - if (is_a($e, 'Kirby\Exception\Exception') === true) { - $result['key'] = $e->getKey(); - $result['details'] = $e->getDetails(); - $result['code'] = $e->getHttpCode(); - } - - // remove critical info from the result set if - // debug mode is switched off - if ($this->debug !== true) { - unset( - $result['file'], - $result['exception'], - $result['line'], - $result['route'] - ); - } - - return $result; - } - - /** - * Upload helper method - * - * move_uploaded_file() not working with unit test - * Added debug parameter for testing purposes as we did in the Email class - * - * @param \Closure $callback - * @param bool $single - * @param bool $debug - * @return array - * - * @throws \Exception If request has no files or there was an error with the upload - */ - public function upload(Closure $callback, $single = false, $debug = false): array - { - $trials = 0; - $uploads = []; - $errors = []; - $files = $this->requestFiles(); - - // get error messages from translation - $errorMessages = [ - UPLOAD_ERR_INI_SIZE => I18n::translate('upload.error.iniSize'), - UPLOAD_ERR_FORM_SIZE => I18n::translate('upload.error.formSize'), - UPLOAD_ERR_PARTIAL => I18n::translate('upload.error.partial'), - UPLOAD_ERR_NO_FILE => I18n::translate('upload.error.noFile'), - UPLOAD_ERR_NO_TMP_DIR => I18n::translate('upload.error.tmpDir'), - UPLOAD_ERR_CANT_WRITE => I18n::translate('upload.error.cantWrite'), - UPLOAD_ERR_EXTENSION => I18n::translate('upload.error.extension') - ]; - - if (empty($files) === true) { - $postMaxSize = Str::toBytes(ini_get('post_max_size')); - $uploadMaxFileSize = Str::toBytes(ini_get('upload_max_filesize')); - - if ($postMaxSize < $uploadMaxFileSize) { - throw new Exception(I18n::translate('upload.error.iniPostSize')); - } else { - throw new Exception(I18n::translate('upload.error.noFiles')); - } - } - - foreach ($files as $upload) { - if (isset($upload['tmp_name']) === false && is_array($upload)) { - continue; - } - - $trials++; - - try { - if ($upload['error'] !== 0) { - $errorMessage = $errorMessages[$upload['error']] ?? I18n::translate('upload.error.default'); - throw new Exception($errorMessage); - } - - // get the extension of the uploaded file - $extension = F::extension($upload['name']); - - // try to detect the correct mime and add the extension - // accordingly. This will avoid .tmp filenames - if (empty($extension) === true || in_array($extension, ['tmp', 'temp'])) { - $mime = F::mime($upload['tmp_name']); - $extension = F::mimeToExtension($mime); - $filename = F::name($upload['name']) . '.' . $extension; - } else { - $filename = basename($upload['name']); - } - - $source = dirname($upload['tmp_name']) . '/' . uniqid() . '.' . $filename; - - // move the file to a location including the extension, - // for better mime detection - if ($debug === false && move_uploaded_file($upload['tmp_name'], $source) === false) { - throw new Exception(I18n::translate('upload.error.cantMove')); - } - - $data = $callback($source, $filename); - - if (is_object($data) === true) { - $data = $this->resolve($data)->toArray(); - } - - $uploads[$upload['name']] = $data; - } catch (Exception $e) { - $errors[$upload['name']] = $e->getMessage(); - } - - if ($single === true) { - break; - } - } - - // return a single upload response - if ($trials === 1) { - if (empty($errors) === false) { - return [ - 'status' => 'error', - 'message' => current($errors) - ]; - } - - return [ - 'status' => 'ok', - 'data' => current($uploads) - ]; - } - - if (empty($errors) === false) { - return [ - 'status' => 'error', - 'errors' => $errors - ]; - } - - return [ - 'status' => 'ok', - 'data' => $uploads - ]; - } + use Properties; + + /** + * Authentication callback + * + * @var \Closure + */ + protected $authentication; + + /** + * Debugging flag + * + * @var bool + */ + protected $debug = false; + + /** + * Collection definition + * + * @var array + */ + protected $collections = []; + + /** + * Injected data/dependencies + * + * @var array + */ + protected $data = []; + + /** + * Model definitions + * + * @var array + */ + protected $models = []; + + /** + * The current route + * + * @var \Kirby\Http\Route + */ + protected $route; + + /** + * The Router instance + * + * @var \Kirby\Http\Router + */ + protected $router; + + /** + * Route definition + * + * @var array + */ + protected $routes = []; + + /** + * Request data + * [query, body, files] + * + * @var array + */ + protected $requestData = []; + + /** + * The applied request method + * (GET, POST, PATCH, etc.) + * + * @var string + */ + protected $requestMethod; + + /** + * Magic accessor for any given data + * + * @param string $method + * @param array $args + * @return mixed + * @throws \Kirby\Exception\NotFoundException + */ + public function __call(string $method, array $args = []) + { + return $this->data($method, ...$args); + } + + /** + * Creates a new API instance + * + * @param array $props + */ + public function __construct(array $props) + { + $this->setProperties($props); + } + + /** + * Runs the authentication method + * if set + * + * @return mixed + */ + public function authenticate() + { + if ($auth = $this->authentication()) { + return $auth->call($this); + } + + return true; + } + + /** + * Returns the authentication callback + * + * @return \Closure|null + */ + public function authentication() + { + return $this->authentication; + } + + /** + * Execute an API call for the given path, + * request method and optional request data + * + * @param string|null $path + * @param string $method + * @param array $requestData + * @return mixed + * @throws \Kirby\Exception\NotFoundException + * @throws \Exception + */ + public function call(string $path = null, string $method = 'GET', array $requestData = []) + { + $path = rtrim($path ?? '', '/'); + + $this->setRequestMethod($method); + $this->setRequestData($requestData); + + $this->router = new Router($this->routes()); + $this->route = $this->router->find($path, $method); + $auth = $this->route->attributes()['auth'] ?? true; + + if ($auth !== false) { + $user = $this->authenticate(); + + // set PHP locales based on *user* language + // so that e.g. strftime() gets formatted correctly + if (is_a($user, 'Kirby\Cms\User') === true) { + $language = $user->language(); + + // get the locale from the translation + $translation = $user->kirby()->translation($language); + $locale = ($translation !== null) ? $translation->locale() : $language; + + // provide some variants as fallbacks to be + // compatible with as many systems as possible + $locales = [ + $locale . '.UTF-8', + $locale . '.UTF8', + $locale . '.ISO8859-1', + $locale, + $language, + setlocale(LC_ALL, 0) // fall back to the previously defined locale + ]; + + // set the locales that are relevant for string formatting + // *don't* set LC_CTYPE to avoid breaking other parts of the system + setlocale(LC_MONETARY, $locales); + setlocale(LC_NUMERIC, $locales); + setlocale(LC_TIME, $locales); + } + } + + // don't throw pagination errors if pagination + // page is out of bounds + $validate = Pagination::$validate; + Pagination::$validate = false; + + $output = $this->route->action()->call($this, ...$this->route->arguments()); + + // restore old pagination validation mode + Pagination::$validate = $validate; + + if ( + is_object($output) === true && + is_a($output, 'Kirby\\Http\\Response') !== true + ) { + return $this->resolve($output)->toResponse(); + } + + return $output; + } + + /** + * Setter and getter for an API collection + * + * @param string $name + * @param array|null $collection + * @return \Kirby\Api\Collection + * @throws \Kirby\Exception\NotFoundException If no collection for `$name` exists + * @throws \Exception + */ + public function collection(string $name, $collection = null) + { + if (isset($this->collections[$name]) === false) { + throw new NotFoundException(sprintf('The collection "%s" does not exist', $name)); + } + + return new Collection($this, $collection, $this->collections[$name]); + } + + /** + * Returns the collections definition + * + * @return array + */ + public function collections(): array + { + return $this->collections; + } + + /** + * Returns the injected data array + * or certain parts of it by key + * + * @param string|null $key + * @param mixed ...$args + * @return mixed + * + * @throws \Kirby\Exception\NotFoundException If no data for `$key` exists + */ + public function data($key = null, ...$args) + { + if ($key === null) { + return $this->data; + } + + if ($this->hasData($key) === false) { + throw new NotFoundException(sprintf('Api data for "%s" does not exist', $key)); + } + + // lazy-load data wrapped in Closures + if (is_a($this->data[$key], 'Closure') === true) { + return $this->data[$key]->call($this, ...$args); + } + + return $this->data[$key]; + } + + /** + * Returns the debugging flag + * + * @return bool + */ + public function debug(): bool + { + return $this->debug; + } + + /** + * Checks if injected data exists for the given key + * + * @param string $key + * @return bool + */ + public function hasData(string $key): bool + { + return isset($this->data[$key]) === true; + } + + /** + * Matches an object with an array item + * based on the `type` field + * + * @param array models or collections + * @param mixed $object + * + * @return string key of match + */ + protected function match(array $array, $object = null) + { + foreach ($array as $definition => $model) { + if (is_a($object, $model['type']) === true) { + return $definition; + } + } + } + + /** + * Returns an API model instance by name + * + * @param string|null $name + * @param mixed $object + * @return \Kirby\Api\Model + * + * @throws \Kirby\Exception\NotFoundException If no model for `$name` exists + */ + public function model(string $name = null, $object = null) + { + // Try to auto-match object with API models + if ($name === null) { + if ($model = $this->match($this->models, $object)) { + $name = $model; + } + } + + if (isset($this->models[$name]) === false) { + throw new NotFoundException(sprintf('The model "%s" does not exist', $name)); + } + + return new Model($this, $object, $this->models[$name]); + } + + /** + * Returns all model definitions + * + * @return array + */ + public function models(): array + { + return $this->models; + } + + /** + * Getter for request data + * Can either get all the data + * or certain parts of it. + * + * @param string|null $type + * @param string|null $key + * @param mixed $default + * @return mixed + */ + public function requestData(string $type = null, string $key = null, $default = null) + { + if ($type === null) { + return $this->requestData; + } + + if ($key === null) { + return $this->requestData[$type] ?? []; + } + + $data = array_change_key_case($this->requestData($type)); + $key = strtolower($key); + + return $data[$key] ?? $default; + } + + /** + * Returns the request body if available + * + * @param string|null $key + * @param mixed $default + * @return mixed + */ + public function requestBody(string $key = null, $default = null) + { + return $this->requestData('body', $key, $default); + } + + /** + * Returns the files from the request if available + * + * @param string|null $key + * @param mixed $default + * @return mixed + */ + public function requestFiles(string $key = null, $default = null) + { + return $this->requestData('files', $key, $default); + } + + /** + * Returns all headers from the request if available + * + * @param string|null $key + * @param mixed $default + * @return mixed + */ + public function requestHeaders(string $key = null, $default = null) + { + return $this->requestData('headers', $key, $default); + } + + /** + * Returns the request method + * + * @return string + */ + public function requestMethod(): string + { + return $this->requestMethod; + } + + /** + * Returns the request query if available + * + * @param string|null $key + * @param mixed $default + * @return mixed + */ + public function requestQuery(string $key = null, $default = null) + { + return $this->requestData('query', $key, $default); + } + + /** + * Turns a Kirby object into an + * API model or collection representation + * + * @param mixed $object + * @return \Kirby\Api\Model|\Kirby\Api\Collection + * + * @throws \Kirby\Exception\NotFoundException If `$object` cannot be resolved + */ + public function resolve($object) + { + if (is_a($object, 'Kirby\Api\Model') === true || is_a($object, 'Kirby\Api\Collection') === true) { + return $object; + } + + if ($model = $this->match($this->models, $object)) { + return $this->model($model, $object); + } + + if ($collection = $this->match($this->collections, $object)) { + return $this->collection($collection, $object); + } + + throw new NotFoundException(sprintf('The object "%s" cannot be resolved', get_class($object))); + } + + /** + * Returns all defined routes + * + * @return array + */ + public function routes(): array + { + return $this->routes; + } + + /** + * Setter for the authentication callback + * + * @param \Closure|null $authentication + * @return $this + */ + protected function setAuthentication(Closure $authentication = null) + { + $this->authentication = $authentication; + return $this; + } + + /** + * Setter for the collections definition + * + * @param array|null $collections + * @return $this + */ + protected function setCollections(array $collections = null) + { + if ($collections !== null) { + $this->collections = array_change_key_case($collections); + } + return $this; + } + + /** + * Setter for the injected data + * + * @param array|null $data + * @return $this + */ + protected function setData(array $data = null) + { + $this->data = $data ?? []; + return $this; + } + + /** + * Setter for the debug flag + * + * @param bool $debug + * @return $this + */ + protected function setDebug(bool $debug = false) + { + $this->debug = $debug; + return $this; + } + + /** + * Setter for the model definitions + * + * @param array|null $models + * @return $this + */ + protected function setModels(array $models = null) + { + if ($models !== null) { + $this->models = array_change_key_case($models); + } + + return $this; + } + + /** + * Setter for the request data + * + * @param array|null $requestData + * @return $this + */ + protected function setRequestData(array $requestData = null) + { + $defaults = [ + 'query' => [], + 'body' => [], + 'files' => [] + ]; + + $this->requestData = array_merge($defaults, (array)$requestData); + return $this; + } + + /** + * Setter for the request method + * + * @param string|null $requestMethod + * @return $this + */ + protected function setRequestMethod(string $requestMethod = null) + { + $this->requestMethod = $requestMethod ?? 'GET'; + return $this; + } + + /** + * Setter for the route definitions + * + * @param array|null $routes + * @return $this + */ + protected function setRoutes(array $routes = null) + { + $this->routes = $routes ?? []; + return $this; + } + + /** + * Renders the API call + * + * @param string $path + * @param string $method + * @param array $requestData + * @return mixed + */ + public function render(string $path, $method = 'GET', array $requestData = []) + { + try { + $result = $this->call($path, $method, $requestData); + } catch (Throwable $e) { + $result = $this->responseForException($e); + } + + if ($result === null) { + $result = $this->responseFor404(); + } elseif ($result === false) { + $result = $this->responseFor400(); + } elseif ($result === true) { + $result = $this->responseFor200(); + } + + if (is_array($result) === false) { + return $result; + } + + // pretty print json data + $pretty = (bool)($requestData['query']['pretty'] ?? false) === true; + + if (($result['status'] ?? 'ok') === 'error') { + $code = $result['code'] ?? 400; + + // sanitize the error code + if ($code < 400 || $code > 599) { + $code = 500; + } + + return Response::json($result, $code, $pretty); + } + + return Response::json($result, 200, $pretty); + } + + /** + * Returns a 200 - ok + * response array. + * + * @return array + */ + public function responseFor200(): array + { + return [ + 'status' => 'ok', + 'message' => 'ok', + 'code' => 200 + ]; + } + + /** + * Returns a 400 - bad request + * response array. + * + * @return array + */ + public function responseFor400(): array + { + return [ + 'status' => 'error', + 'message' => 'bad request', + 'code' => 400, + ]; + } + + /** + * Returns a 404 - not found + * response array. + * + * @return array + */ + public function responseFor404(): array + { + return [ + 'status' => 'error', + 'message' => 'not found', + 'code' => 404, + ]; + } + + /** + * Creates the response array for + * an exception. Kirby exceptions will + * have more information + * + * @param \Throwable $e + * @return array + */ + public function responseForException(Throwable $e): array + { + if (isset($this->kirby) === true) { + $docRoot = $this->kirby->environment()->get('DOCUMENT_ROOT'); + } else { + $docRoot = $_SERVER['DOCUMENT_ROOT'] ?? null; + } + + // prepare the result array for all exception types + $result = [ + 'status' => 'error', + 'message' => $e->getMessage(), + 'code' => empty($e->getCode()) === true ? 500 : $e->getCode(), + 'exception' => get_class($e), + 'key' => null, + 'file' => F::relativepath($e->getFile(), $docRoot), + 'line' => $e->getLine(), + 'details' => [], + 'route' => $this->route ? $this->route->pattern() : null + ]; + + // extend the information for Kirby Exceptions + if (is_a($e, 'Kirby\Exception\Exception') === true) { + $result['key'] = $e->getKey(); + $result['details'] = $e->getDetails(); + $result['code'] = $e->getHttpCode(); + } + + // remove critical info from the result set if + // debug mode is switched off + if ($this->debug !== true) { + unset( + $result['file'], + $result['exception'], + $result['line'], + $result['route'] + ); + } + + return $result; + } + + /** + * Upload helper method + * + * move_uploaded_file() not working with unit test + * Added debug parameter for testing purposes as we did in the Email class + * + * @param \Closure $callback + * @param bool $single + * @param bool $debug + * @return array + * + * @throws \Exception If request has no files or there was an error with the upload + */ + public function upload(Closure $callback, $single = false, $debug = false): array + { + $trials = 0; + $uploads = []; + $errors = []; + $files = $this->requestFiles(); + + // get error messages from translation + $errorMessages = [ + UPLOAD_ERR_INI_SIZE => I18n::translate('upload.error.iniSize'), + UPLOAD_ERR_FORM_SIZE => I18n::translate('upload.error.formSize'), + UPLOAD_ERR_PARTIAL => I18n::translate('upload.error.partial'), + UPLOAD_ERR_NO_FILE => I18n::translate('upload.error.noFile'), + UPLOAD_ERR_NO_TMP_DIR => I18n::translate('upload.error.tmpDir'), + UPLOAD_ERR_CANT_WRITE => I18n::translate('upload.error.cantWrite'), + UPLOAD_ERR_EXTENSION => I18n::translate('upload.error.extension') + ]; + + if (empty($files) === true) { + $postMaxSize = Str::toBytes(ini_get('post_max_size')); + $uploadMaxFileSize = Str::toBytes(ini_get('upload_max_filesize')); + + if ($postMaxSize < $uploadMaxFileSize) { + throw new Exception(I18n::translate('upload.error.iniPostSize')); + } else { + throw new Exception(I18n::translate('upload.error.noFiles')); + } + } + + foreach ($files as $upload) { + if (isset($upload['tmp_name']) === false && is_array($upload)) { + continue; + } + + $trials++; + + try { + if ($upload['error'] !== 0) { + $errorMessage = $errorMessages[$upload['error']] ?? I18n::translate('upload.error.default'); + throw new Exception($errorMessage); + } + + // get the extension of the uploaded file + $extension = F::extension($upload['name']); + + // try to detect the correct mime and add the extension + // accordingly. This will avoid .tmp filenames + if (empty($extension) === true || in_array($extension, ['tmp', 'temp'])) { + $mime = F::mime($upload['tmp_name']); + $extension = F::mimeToExtension($mime); + $filename = F::name($upload['name']) . '.' . $extension; + } else { + $filename = basename($upload['name']); + } + + $source = dirname($upload['tmp_name']) . '/' . uniqid() . '.' . $filename; + + // move the file to a location including the extension, + // for better mime detection + if ($debug === false && move_uploaded_file($upload['tmp_name'], $source) === false) { + throw new Exception(I18n::translate('upload.error.cantMove')); + } + + $data = $callback($source, $filename); + + if (is_object($data) === true) { + $data = $this->resolve($data)->toArray(); + } + + $uploads[$upload['name']] = $data; + } catch (Exception $e) { + $errors[$upload['name']] = $e->getMessage(); + } + + if ($single === true) { + break; + } + } + + // return a single upload response + if ($trials === 1) { + if (empty($errors) === false) { + return [ + 'status' => 'error', + 'message' => current($errors) + ]; + } + + return [ + 'status' => 'ok', + 'data' => current($uploads) + ]; + } + + if (empty($errors) === false) { + return [ + 'status' => 'error', + 'errors' => $errors + ]; + } + + return [ + 'status' => 'ok', + 'data' => $uploads + ]; + } } diff --git a/kirby/src/Api/Collection.php b/kirby/src/Api/Collection.php index 01eb49b..48ddca2 100755 --- a/kirby/src/Api/Collection.php +++ b/kirby/src/Api/Collection.php @@ -19,160 +19,160 @@ use Kirby\Toolkit\Str; */ class Collection { - /** - * @var \Kirby\Api\Api - */ - protected $api; + /** + * @var \Kirby\Api\Api + */ + protected $api; - /** - * @var mixed|null - */ - protected $data; + /** + * @var mixed|null + */ + protected $data; - /** - * @var mixed|null - */ - protected $model; + /** + * @var mixed|null + */ + protected $model; - /** - * @var mixed|null - */ - protected $select; + /** + * @var mixed|null + */ + protected $select; - /** - * @var mixed|null - */ - protected $view; + /** + * @var mixed|null + */ + protected $view; - /** - * Collection constructor - * - * @param \Kirby\Api\Api $api - * @param mixed|null $data - * @param array $schema - * @throws \Exception - */ - public function __construct(Api $api, $data, array $schema) - { - $this->api = $api; - $this->data = $data; - $this->model = $schema['model'] ?? null; - $this->view = $schema['view'] ?? null; + /** + * Collection constructor + * + * @param \Kirby\Api\Api $api + * @param mixed|null $data + * @param array $schema + * @throws \Exception + */ + public function __construct(Api $api, $data, array $schema) + { + $this->api = $api; + $this->data = $data; + $this->model = $schema['model'] ?? null; + $this->view = $schema['view'] ?? null; - if ($data === null) { - if (is_a($schema['default'] ?? null, 'Closure') === false) { - throw new Exception('Missing collection data'); - } + if ($data === null) { + if (is_a($schema['default'] ?? null, 'Closure') === false) { + throw new Exception('Missing collection data'); + } - $this->data = $schema['default']->call($this->api); - } + $this->data = $schema['default']->call($this->api); + } - if ( - isset($schema['type']) === true && - is_a($this->data, $schema['type']) === false - ) { - throw new Exception('Invalid collection type'); - } - } + if ( + isset($schema['type']) === true && + is_a($this->data, $schema['type']) === false + ) { + throw new Exception('Invalid collection type'); + } + } - /** - * @param string|array|null $keys - * @return $this - * @throws \Exception - */ - public function select($keys = null) - { - if ($keys === false) { - return $this; - } + /** + * @param string|array|null $keys + * @return $this + * @throws \Exception + */ + public function select($keys = null) + { + if ($keys === false) { + return $this; + } - if (is_string($keys)) { - $keys = Str::split($keys); - } + if (is_string($keys)) { + $keys = Str::split($keys); + } - if ($keys !== null && is_array($keys) === false) { - throw new Exception('Invalid select keys'); - } + if ($keys !== null && is_array($keys) === false) { + throw new Exception('Invalid select keys'); + } - $this->select = $keys; - return $this; - } + $this->select = $keys; + return $this; + } - /** - * @return array - * @throws \Kirby\Exception\NotFoundException - * @throws \Exception - */ - public function toArray(): array - { - $result = []; + /** + * @return array + * @throws \Kirby\Exception\NotFoundException + * @throws \Exception + */ + public function toArray(): array + { + $result = []; - foreach ($this->data as $item) { - $model = $this->api->model($this->model, $item); + foreach ($this->data as $item) { + $model = $this->api->model($this->model, $item); - if ($this->view !== null) { - $model = $model->view($this->view); - } + if ($this->view !== null) { + $model = $model->view($this->view); + } - if ($this->select !== null) { - $model = $model->select($this->select); - } + if ($this->select !== null) { + $model = $model->select($this->select); + } - $result[] = $model->toArray(); - } + $result[] = $model->toArray(); + } - return $result; - } + return $result; + } - /** - * @return array - * @throws \Kirby\Exception\NotFoundException - * @throws \Exception - */ - public function toResponse(): array - { - if ($query = $this->api->requestQuery('query')) { - $this->data = $this->data->query($query); - } + /** + * @return array + * @throws \Kirby\Exception\NotFoundException + * @throws \Exception + */ + public function toResponse(): array + { + if ($query = $this->api->requestQuery('query')) { + $this->data = $this->data->query($query); + } - if (!$this->data->pagination()) { - $this->data = $this->data->paginate([ - 'page' => $this->api->requestQuery('page', 1), - 'limit' => $this->api->requestQuery('limit', 100) - ]); - } + if (!$this->data->pagination()) { + $this->data = $this->data->paginate([ + 'page' => $this->api->requestQuery('page', 1), + 'limit' => $this->api->requestQuery('limit', 100) + ]); + } - $pagination = $this->data->pagination(); + $pagination = $this->data->pagination(); - if ($select = $this->api->requestQuery('select')) { - $this->select($select); - } + if ($select = $this->api->requestQuery('select')) { + $this->select($select); + } - if ($view = $this->api->requestQuery('view')) { - $this->view($view); - } + if ($view = $this->api->requestQuery('view')) { + $this->view($view); + } - return [ - 'code' => 200, - 'data' => $this->toArray(), - 'pagination' => [ - 'page' => $pagination->page(), - 'total' => $pagination->total(), - 'offset' => $pagination->offset(), - 'limit' => $pagination->limit(), - ], - 'status' => 'ok', - 'type' => 'collection' - ]; - } + return [ + 'code' => 200, + 'data' => $this->toArray(), + 'pagination' => [ + 'page' => $pagination->page(), + 'total' => $pagination->total(), + 'offset' => $pagination->offset(), + 'limit' => $pagination->limit(), + ], + 'status' => 'ok', + 'type' => 'collection' + ]; + } - /** - * @param string $view - * @return $this - */ - public function view(string $view) - { - $this->view = $view; - return $this; - } + /** + * @param string $view + * @return $this + */ + public function view(string $view) + { + $this->view = $view; + return $this; + } } diff --git a/kirby/src/Api/Model.php b/kirby/src/Api/Model.php index 02118af..f0189c0 100755 --- a/kirby/src/Api/Model.php +++ b/kirby/src/Api/Model.php @@ -21,228 +21,228 @@ use Kirby\Toolkit\Str; */ class Model { - /** - * @var \Kirby\Api\Api - */ - protected $api; + /** + * @var \Kirby\Api\Api + */ + protected $api; - /** - * @var mixed|null - */ - protected $data; + /** + * @var mixed|null + */ + protected $data; - /** - * @var array|mixed - */ - protected $fields; + /** + * @var array|mixed + */ + protected $fields; - /** - * @var mixed|null - */ - protected $select; + /** + * @var mixed|null + */ + protected $select; - /** - * @var array|mixed - */ - protected $views; + /** + * @var array|mixed + */ + protected $views; - /** - * Model constructor - * - * @param \Kirby\Api\Api $api - * @param mixed $data - * @param array $schema - * @throws \Exception - */ - public function __construct(Api $api, $data, array $schema) - { - $this->api = $api; - $this->data = $data; - $this->fields = $schema['fields'] ?? []; - $this->select = $schema['select'] ?? null; - $this->views = $schema['views'] ?? []; + /** + * Model constructor + * + * @param \Kirby\Api\Api $api + * @param mixed $data + * @param array $schema + * @throws \Exception + */ + public function __construct(Api $api, $data, array $schema) + { + $this->api = $api; + $this->data = $data; + $this->fields = $schema['fields'] ?? []; + $this->select = $schema['select'] ?? null; + $this->views = $schema['views'] ?? []; - if ($this->select === null && array_key_exists('default', $this->views)) { - $this->view('default'); - } + if ($this->select === null && array_key_exists('default', $this->views)) { + $this->view('default'); + } - if ($data === null) { - if (is_a($schema['default'] ?? null, 'Closure') === false) { - throw new Exception('Missing model data'); - } + if ($data === null) { + if (is_a($schema['default'] ?? null, 'Closure') === false) { + throw new Exception('Missing model data'); + } - $this->data = $schema['default']->call($this->api); - } + $this->data = $schema['default']->call($this->api); + } - if ( - isset($schema['type']) === true && - is_a($this->data, $schema['type']) === false - ) { - throw new Exception(sprintf('Invalid model type "%s" expected: "%s"', get_class($this->data), $schema['type'])); - } - } + if ( + isset($schema['type']) === true && + is_a($this->data, $schema['type']) === false + ) { + throw new Exception(sprintf('Invalid model type "%s" expected: "%s"', get_class($this->data), $schema['type'])); + } + } - /** - * @param null $keys - * @return $this - * @throws \Exception - */ - public function select($keys = null) - { - if ($keys === false) { - return $this; - } + /** + * @param null $keys + * @return $this + * @throws \Exception + */ + public function select($keys = null) + { + if ($keys === false) { + return $this; + } - if (is_string($keys)) { - $keys = Str::split($keys); - } + if (is_string($keys)) { + $keys = Str::split($keys); + } - if ($keys !== null && is_array($keys) === false) { - throw new Exception('Invalid select keys'); - } + if ($keys !== null && is_array($keys) === false) { + throw new Exception('Invalid select keys'); + } - $this->select = $keys; - return $this; - } + $this->select = $keys; + return $this; + } - /** - * @return array - * @throws \Exception - */ - public function selection(): array - { - $select = $this->select; + /** + * @return array + * @throws \Exception + */ + public function selection(): array + { + $select = $this->select; - if ($select === null) { - $select = array_keys($this->fields); - } + if ($select === null) { + $select = array_keys($this->fields); + } - $selection = []; + $selection = []; - foreach ($select as $key => $value) { - if (is_int($key) === true) { - $selection[$value] = [ - 'view' => null, - 'select' => null - ]; - continue; - } + foreach ($select as $key => $value) { + if (is_int($key) === true) { + $selection[$value] = [ + 'view' => null, + 'select' => null + ]; + continue; + } - if (is_string($value) === true) { - if ($value === 'any') { - throw new Exception('Invalid sub view: "any"'); - } + if (is_string($value) === true) { + if ($value === 'any') { + throw new Exception('Invalid sub view: "any"'); + } - $selection[$key] = [ - 'view' => $value, - 'select' => null - ]; + $selection[$key] = [ + 'view' => $value, + 'select' => null + ]; - continue; - } + continue; + } - if (is_array($value) === true) { - $selection[$key] = [ - 'view' => null, - 'select' => $value - ]; - } - } + if (is_array($value) === true) { + $selection[$key] = [ + 'view' => null, + 'select' => $value + ]; + } + } - return $selection; - } + return $selection; + } - /** - * @return array - * @throws \Kirby\Exception\NotFoundException - * @throws \Exception - */ - public function toArray(): array - { - $select = $this->selection(); - $result = []; + /** + * @return array + * @throws \Kirby\Exception\NotFoundException + * @throws \Exception + */ + public function toArray(): array + { + $select = $this->selection(); + $result = []; - foreach ($this->fields as $key => $resolver) { - if (array_key_exists($key, $select) === false || is_a($resolver, 'Closure') === false) { - continue; - } + foreach ($this->fields as $key => $resolver) { + if (array_key_exists($key, $select) === false || is_a($resolver, 'Closure') === false) { + continue; + } - $value = $resolver->call($this->api, $this->data); + $value = $resolver->call($this->api, $this->data); - if (is_object($value)) { - $value = $this->api->resolve($value); - } + if (is_object($value)) { + $value = $this->api->resolve($value); + } - if ( - is_a($value, 'Kirby\Api\Collection') === true || - is_a($value, 'Kirby\Api\Model') === true - ) { - $selection = $select[$key]; + if ( + is_a($value, 'Kirby\Api\Collection') === true || + is_a($value, 'Kirby\Api\Model') === true + ) { + $selection = $select[$key]; - if ($subview = $selection['view']) { - $value->view($subview); - } + if ($subview = $selection['view']) { + $value->view($subview); + } - if ($subselect = $selection['select']) { - $value->select($subselect); - } + if ($subselect = $selection['select']) { + $value->select($subselect); + } - $value = $value->toArray(); - } + $value = $value->toArray(); + } - $result[$key] = $value; - } + $result[$key] = $value; + } - ksort($result); + ksort($result); - return $result; - } + return $result; + } - /** - * @return array - * @throws \Kirby\Exception\NotFoundException - * @throws \Exception - */ - public function toResponse(): array - { - $model = $this; + /** + * @return array + * @throws \Kirby\Exception\NotFoundException + * @throws \Exception + */ + public function toResponse(): array + { + $model = $this; - if ($select = $this->api->requestQuery('select')) { - $model = $model->select($select); - } + if ($select = $this->api->requestQuery('select')) { + $model = $model->select($select); + } - if ($view = $this->api->requestQuery('view')) { - $model = $model->view($view); - } + if ($view = $this->api->requestQuery('view')) { + $model = $model->view($view); + } - return [ - 'code' => 200, - 'data' => $model->toArray(), - 'status' => 'ok', - 'type' => 'model' - ]; - } + return [ + 'code' => 200, + 'data' => $model->toArray(), + 'status' => 'ok', + 'type' => 'model' + ]; + } - /** - * @param string $name - * @return $this - * @throws \Exception - */ - public function view(string $name) - { - if ($name === 'any') { - return $this->select(null); - } + /** + * @param string $name + * @return $this + * @throws \Exception + */ + public function view(string $name) + { + if ($name === 'any') { + return $this->select(null); + } - if (isset($this->views[$name]) === false) { - $name = 'default'; + if (isset($this->views[$name]) === false) { + $name = 'default'; - // try to fall back to the default view at least - if (isset($this->views[$name]) === false) { - throw new Exception(sprintf('The view "%s" does not exist', $name)); - } - } + // try to fall back to the default view at least + if (isset($this->views[$name]) === false) { + throw new Exception(sprintf('The view "%s" does not exist', $name)); + } + } - return $this->select($this->views[$name]); - } + return $this->select($this->views[$name]); + } } diff --git a/kirby/src/Cache/ApcuCache.php b/kirby/src/Cache/ApcuCache.php index ba0b4f9..fb11eda 100755 --- a/kirby/src/Cache/ApcuCache.php +++ b/kirby/src/Cache/ApcuCache.php @@ -15,72 +15,72 @@ use APCUIterator; */ class ApcuCache extends Cache { - /** - * Determines if an item exists in the cache - * - * @param string $key - * @return bool - */ - public function exists(string $key): bool - { - return apcu_exists($this->key($key)); - } + /** + * Determines if an item exists in the cache + * + * @param string $key + * @return bool + */ + public function exists(string $key): bool + { + return apcu_exists($this->key($key)); + } - /** - * Flushes the entire cache and returns - * whether the operation was successful - * - * @return bool - */ - public function flush(): bool - { - if (empty($this->options['prefix']) === false) { - return apcu_delete(new APCUIterator('!^' . preg_quote($this->options['prefix']) . '!')); - } else { - return apcu_clear_cache(); - } - } + /** + * Flushes the entire cache and returns + * whether the operation was successful + * + * @return bool + */ + public function flush(): bool + { + if (empty($this->options['prefix']) === false) { + return apcu_delete(new APCUIterator('!^' . preg_quote($this->options['prefix']) . '!')); + } else { + return apcu_clear_cache(); + } + } - /** - * Removes an item from the cache and returns - * whether the operation was successful - * - * @param string $key - * @return bool - */ - public function remove(string $key): bool - { - return apcu_delete($this->key($key)); - } + /** + * Removes an item from the cache and returns + * whether the operation was successful + * + * @param string $key + * @return bool + */ + public function remove(string $key): bool + { + return apcu_delete($this->key($key)); + } - /** - * Internal method to retrieve the raw cache value; - * needs to return a Value object or null if not found - * - * @param string $key - * @return \Kirby\Cache\Value|null - */ - public function retrieve(string $key) - { - return Value::fromJson(apcu_fetch($this->key($key))); - } + /** + * Internal method to retrieve the raw cache value; + * needs to return a Value object or null if not found + * + * @param string $key + * @return \Kirby\Cache\Value|null + */ + public function retrieve(string $key) + { + return Value::fromJson(apcu_fetch($this->key($key))); + } - /** - * Writes an item to the cache for a given number of minutes and - * returns whether the operation was successful - * - * - * // put an item in the cache for 15 minutes - * $cache->set('value', 'my value', 15); - * - * - * @param string $key - * @param mixed $value - * @param int $minutes - * @return bool - */ - public function set(string $key, $value, int $minutes = 0): bool - { - return apcu_store($this->key($key), (new Value($value, $minutes))->toJson(), $this->expiration($minutes)); - } + /** + * Writes an item to the cache for a given number of minutes and + * returns whether the operation was successful + * + * + * // put an item in the cache for 15 minutes + * $cache->set('value', 'my value', 15); + * + * + * @param string $key + * @param mixed $value + * @param int $minutes + * @return bool + */ + public function set(string $key, $value, int $minutes = 0): bool + { + return apcu_store($this->key($key), (new Value($value, $minutes))->toJson(), $this->expiration($minutes)); + } } diff --git a/kirby/src/Cache/Cache.php b/kirby/src/Cache/Cache.php index 0ffda81..5eeaec8 100755 --- a/kirby/src/Cache/Cache.php +++ b/kirby/src/Cache/Cache.php @@ -16,227 +16,227 @@ namespace Kirby\Cache; */ abstract class Cache { - /** - * Stores all options for the driver - * @var array - */ - protected $options = []; + /** + * Stores all options for the driver + * @var array + */ + protected $options = []; - /** - * Sets all parameters which are needed to connect to the cache storage - * - * @param array $options - */ - public function __construct(array $options = []) - { - $this->options = $options; - } + /** + * Sets all parameters which are needed to connect to the cache storage + * + * @param array $options + */ + public function __construct(array $options = []) + { + $this->options = $options; + } - /** - * Writes an item to the cache for a given number of minutes and - * returns whether the operation was successful; - * this needs to be defined by the driver - * - * - * // put an item in the cache for 15 minutes - * $cache->set('value', 'my value', 15); - * - * - * @param string $key - * @param mixed $value - * @param int $minutes - * @return bool - */ - abstract public function set(string $key, $value, int $minutes = 0): bool; + /** + * Writes an item to the cache for a given number of minutes and + * returns whether the operation was successful; + * this needs to be defined by the driver + * + * + * // put an item in the cache for 15 minutes + * $cache->set('value', 'my value', 15); + * + * + * @param string $key + * @param mixed $value + * @param int $minutes + * @return bool + */ + abstract public function set(string $key, $value, int $minutes = 0): bool; - /** - * Adds the prefix to the key if given - * - * @param string $key - * @return string - */ - protected function key(string $key): string - { - if (empty($this->options['prefix']) === false) { - $key = $this->options['prefix'] . '/' . $key; - } + /** + * Adds the prefix to the key if given + * + * @param string $key + * @return string + */ + protected function key(string $key): string + { + if (empty($this->options['prefix']) === false) { + $key = $this->options['prefix'] . '/' . $key; + } - return $key; - } + return $key; + } - /** - * Internal method to retrieve the raw cache value; - * needs to return a Value object or null if not found; - * this needs to be defined by the driver - * - * @param string $key - * @return \Kirby\Cache\Value|null - */ - abstract public function retrieve(string $key); + /** + * Internal method to retrieve the raw cache value; + * needs to return a Value object or null if not found; + * this needs to be defined by the driver + * + * @param string $key + * @return \Kirby\Cache\Value|null + */ + abstract public function retrieve(string $key); - /** - * Gets an item from the cache - * - * - * // get an item from the cache driver - * $value = $cache->get('value'); - * - * // return a default value if the requested item isn't cached - * $value = $cache->get('value', 'default value'); - * - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function get(string $key, $default = null) - { - // get the Value - $value = $this->retrieve($key); + /** + * Gets an item from the cache + * + * + * // get an item from the cache driver + * $value = $cache->get('value'); + * + * // return a default value if the requested item isn't cached + * $value = $cache->get('value', 'default value'); + * + * + * @param string $key + * @param mixed $default + * @return mixed + */ + public function get(string $key, $default = null) + { + // get the Value + $value = $this->retrieve($key); - // check for a valid cache value - if (!is_a($value, 'Kirby\Cache\Value')) { - return $default; - } + // check for a valid cache value + if (!is_a($value, 'Kirby\Cache\Value')) { + return $default; + } - // remove the item if it is expired - if ($value->expires() > 0 && time() >= $value->expires()) { - $this->remove($key); - return $default; - } + // remove the item if it is expired + if ($value->expires() > 0 && time() >= $value->expires()) { + $this->remove($key); + return $default; + } - // return the pure value - return $value->value(); - } + // return the pure value + return $value->value(); + } - /** - * Calculates the expiration timestamp - * - * @param int $minutes - * @return int - */ - protected function expiration(int $minutes = 0): int - { - // 0 = keep forever - if ($minutes === 0) { - return 0; - } + /** + * Calculates the expiration timestamp + * + * @param int $minutes + * @return int + */ + protected function expiration(int $minutes = 0): int + { + // 0 = keep forever + if ($minutes === 0) { + return 0; + } - // calculate the time - return time() + ($minutes * 60); - } + // calculate the time + return time() + ($minutes * 60); + } - /** - * Checks when an item in the cache expires; - * returns the expiry timestamp on success, null if the - * item never expires and false if the item does not exist - * - * @param string $key - * @return int|null|false - */ - public function expires(string $key) - { - // get the Value object - $value = $this->retrieve($key); + /** + * Checks when an item in the cache expires; + * returns the expiry timestamp on success, null if the + * item never expires and false if the item does not exist + * + * @param string $key + * @return int|null|false + */ + public function expires(string $key) + { + // get the Value object + $value = $this->retrieve($key); - // check for a valid Value object - if (!is_a($value, 'Kirby\Cache\Value')) { - return false; - } + // check for a valid Value object + if (!is_a($value, 'Kirby\Cache\Value')) { + return false; + } - // return the expires timestamp - return $value->expires(); - } + // return the expires timestamp + return $value->expires(); + } - /** - * Checks if an item in the cache is expired - * - * @param string $key - * @return bool - */ - public function expired(string $key): bool - { - $expires = $this->expires($key); + /** + * Checks if an item in the cache is expired + * + * @param string $key + * @return bool + */ + public function expired(string $key): bool + { + $expires = $this->expires($key); - if ($expires === null) { - return false; - } elseif (!is_int($expires)) { - return true; - } else { - return time() >= $expires; - } - } + if ($expires === null) { + return false; + } elseif (!is_int($expires)) { + return true; + } else { + return time() >= $expires; + } + } - /** - * Checks when the cache has been created; - * returns the creation timestamp on success - * and false if the item does not exist - * - * @param string $key - * @return int|false - */ - public function created(string $key) - { - // get the Value object - $value = $this->retrieve($key); + /** + * Checks when the cache has been created; + * returns the creation timestamp on success + * and false if the item does not exist + * + * @param string $key + * @return int|false + */ + public function created(string $key) + { + // get the Value object + $value = $this->retrieve($key); - // check for a valid Value object - if (!is_a($value, 'Kirby\Cache\Value')) { - return false; - } + // check for a valid Value object + if (!is_a($value, 'Kirby\Cache\Value')) { + return false; + } - // return the expires timestamp - return $value->created(); - } + // return the expires timestamp + return $value->created(); + } - /** - * Alternate version for Cache::created($key) - * - * @param string $key - * @return int|false - */ - public function modified(string $key) - { - return static::created($key); - } + /** + * Alternate version for Cache::created($key) + * + * @param string $key + * @return int|false + */ + public function modified(string $key) + { + return static::created($key); + } - /** - * Determines if an item exists in the cache - * - * @param string $key - * @return bool - */ - public function exists(string $key): bool - { - return $this->expired($key) === false; - } + /** + * Determines if an item exists in the cache + * + * @param string $key + * @return bool + */ + public function exists(string $key): bool + { + return $this->expired($key) === false; + } - /** - * Removes an item from the cache and returns - * whether the operation was successful; - * this needs to be defined by the driver - * - * @param string $key - * @return bool - */ - abstract public function remove(string $key): bool; + /** + * Removes an item from the cache and returns + * whether the operation was successful; + * this needs to be defined by the driver + * + * @param string $key + * @return bool + */ + abstract public function remove(string $key): bool; - /** - * Flushes the entire cache and returns - * whether the operation was successful; - * this needs to be defined by the driver - * - * @return bool - */ - abstract public function flush(): bool; + /** + * Flushes the entire cache and returns + * whether the operation was successful; + * this needs to be defined by the driver + * + * @return bool + */ + abstract public function flush(): bool; - /** - * Returns all passed cache options - * - * @return array - */ - public function options(): array - { - return $this->options; - } + /** + * Returns all passed cache options + * + * @return array + */ + public function options(): array + { + return $this->options; + } } diff --git a/kirby/src/Cache/FileCache.php b/kirby/src/Cache/FileCache.php index ed12a69..7393e23 100755 --- a/kirby/src/Cache/FileCache.php +++ b/kirby/src/Cache/FileCache.php @@ -18,217 +18,217 @@ use Kirby\Toolkit\Str; */ class FileCache extends Cache { - /** - * Full root including prefix - * - * @var string - */ - protected $root; + /** + * Full root including prefix + * + * @var string + */ + protected $root; - /** - * Sets all parameters which are needed for the file cache - * - * @param array $options 'root' (required) - * 'prefix' (default: none) - * 'extension' (file extension for cache files, default: none) - */ - public function __construct(array $options) - { - $defaults = [ - 'root' => null, - 'prefix' => null, - 'extension' => null - ]; + /** + * Sets all parameters which are needed for the file cache + * + * @param array $options 'root' (required) + * 'prefix' (default: none) + * 'extension' (file extension for cache files, default: none) + */ + public function __construct(array $options) + { + $defaults = [ + 'root' => null, + 'prefix' => null, + 'extension' => null + ]; - parent::__construct(array_merge($defaults, $options)); + parent::__construct(array_merge($defaults, $options)); - // build the full root including prefix - $this->root = $this->options['root']; - if (empty($this->options['prefix']) === false) { - $this->root .= '/' . $this->options['prefix']; - } + // build the full root including prefix + $this->root = $this->options['root']; + if (empty($this->options['prefix']) === false) { + $this->root .= '/' . $this->options['prefix']; + } - // try to create the directory - Dir::make($this->root, true); - } + // try to create the directory + Dir::make($this->root, true); + } - /** - * Returns the full root including prefix - * - * @return string - */ - public function root(): string - { - return $this->root; - } + /** + * Returns the full root including prefix + * + * @return string + */ + public function root(): string + { + return $this->root; + } - /** - * Returns the full path to a file for a given key - * - * @param string $key - * @return string - */ - protected function file(string $key): string - { - // strip out invalid characters in each path segment - // split by slash or backslash - $keyParts = []; - foreach (preg_split('#([\/\\\\])#', $key, 0, PREG_SPLIT_DELIM_CAPTURE) as $part) { - switch ($part) { - // forward slashes don't need special treatment - case '/': - break; + /** + * Returns the full path to a file for a given key + * + * @param string $key + * @return string + */ + protected function file(string $key): string + { + // strip out invalid characters in each path segment + // split by slash or backslash + $keyParts = []; + foreach (preg_split('#([\/\\\\])#', $key, 0, PREG_SPLIT_DELIM_CAPTURE) as $part) { + switch ($part) { + // forward slashes don't need special treatment + case '/': + break; - // backslashes get their own marker in the path - // to differentiate the cache key from one with forward slashes - case '\\': - $keyParts[] = '_backslash'; - break; + // backslashes get their own marker in the path + // to differentiate the cache key from one with forward slashes + case '\\': + $keyParts[] = '_backslash'; + break; - // empty part means two slashes in a row; - // special marker like for backslashes - case '': - $keyParts[] = '_empty'; - break; + // empty part means two slashes in a row; + // special marker like for backslashes + case '': + $keyParts[] = '_empty'; + break; - // an actual path segment - default: - // check if the segment only contains safe characters; - // underscores are *not* safe to guarantee uniqueness - // as they are used in the special cases - if (preg_match('/^[a-zA-Z0-9-]+$/', $part) === 1) { - $keyParts[] = $part; - } else { - $keyParts[] = Str::slug($part) . '_' . sha1($part); - } - } - } + // an actual path segment + default: + // check if the segment only contains safe characters; + // underscores are *not* safe to guarantee uniqueness + // as they are used in the special cases + if (preg_match('/^[a-zA-Z0-9-]+$/', $part) === 1) { + $keyParts[] = $part; + } else { + $keyParts[] = Str::slug($part) . '_' . sha1($part); + } + } + } - $file = $this->root . '/' . implode('/', $keyParts); + $file = $this->root . '/' . implode('/', $keyParts); - if (isset($this->options['extension'])) { - return $file . '.' . $this->options['extension']; - } else { - return $file; - } - } + if (isset($this->options['extension'])) { + return $file . '.' . $this->options['extension']; + } else { + return $file; + } + } - /** - * Writes an item to the cache for a given number of minutes and - * returns whether the operation was successful - * - * - * // put an item in the cache for 15 minutes - * $cache->set('value', 'my value', 15); - * - * - * @param string $key - * @param mixed $value - * @param int $minutes - * @return bool - */ - public function set(string $key, $value, int $minutes = 0): bool - { - $file = $this->file($key); + /** + * Writes an item to the cache for a given number of minutes and + * returns whether the operation was successful + * + * + * // put an item in the cache for 15 minutes + * $cache->set('value', 'my value', 15); + * + * + * @param string $key + * @param mixed $value + * @param int $minutes + * @return bool + */ + public function set(string $key, $value, int $minutes = 0): bool + { + $file = $this->file($key); - return F::write($file, (new Value($value, $minutes))->toJson()); - } + return F::write($file, (new Value($value, $minutes))->toJson()); + } - /** - * Internal method to retrieve the raw cache value; - * needs to return a Value object or null if not found - * - * @param string $key - * @return \Kirby\Cache\Value|null - */ - public function retrieve(string $key) - { - $file = $this->file($key); - $value = F::read($file); + /** + * Internal method to retrieve the raw cache value; + * needs to return a Value object or null if not found + * + * @param string $key + * @return \Kirby\Cache\Value|null + */ + public function retrieve(string $key) + { + $file = $this->file($key); + $value = F::read($file); - return $value ? Value::fromJson($value) : null; - } + return $value ? Value::fromJson($value) : null; + } - /** - * Checks when the cache has been created; - * returns the creation timestamp on success - * and false if the item does not exist - * - * @param string $key - * @return mixed - */ - public function created(string $key) - { - // use the modification timestamp - // as indicator when the cache has been created/overwritten - clearstatcache(); + /** + * Checks when the cache has been created; + * returns the creation timestamp on success + * and false if the item does not exist + * + * @param string $key + * @return mixed + */ + public function created(string $key) + { + // use the modification timestamp + // as indicator when the cache has been created/overwritten + clearstatcache(); - // get the file for this cache key - $file = $this->file($key); - return file_exists($file) ? filemtime($this->file($key)) : false; - } + // get the file for this cache key + $file = $this->file($key); + return file_exists($file) ? filemtime($this->file($key)) : false; + } - /** - * Removes an item from the cache and returns - * whether the operation was successful - * - * @param string $key - * @return bool - */ - public function remove(string $key): bool - { - $file = $this->file($key); + /** + * Removes an item from the cache and returns + * whether the operation was successful + * + * @param string $key + * @return bool + */ + public function remove(string $key): bool + { + $file = $this->file($key); - if (is_file($file) === true && F::remove($file) === true) { - $this->removeEmptyDirectories(dirname($file)); - return true; - } + if (is_file($file) === true && F::remove($file) === true) { + $this->removeEmptyDirectories(dirname($file)); + return true; + } - return false; - } + return false; + } - /** - * Removes empty directories safely by checking each directory - * up to the root directory - * - * @param string $dir - * @return void - */ - protected function removeEmptyDirectories(string $dir): void - { - try { - // ensure the path doesn't end with a slash for the next comparison - $dir = rtrim($dir, '/\/'); + /** + * Removes empty directories safely by checking each directory + * up to the root directory + * + * @param string $dir + * @return void + */ + protected function removeEmptyDirectories(string $dir): void + { + try { + // ensure the path doesn't end with a slash for the next comparison + $dir = rtrim($dir, '/\/'); - // checks all directory segments until reaching the root directory - while (Str::startsWith($dir, $this->root()) === true && $dir !== $this->root()) { - $files = array_diff(scandir($dir) ?? [], ['.', '..']); + // checks all directory segments until reaching the root directory + while (Str::startsWith($dir, $this->root()) === true && $dir !== $this->root()) { + $files = array_diff(scandir($dir) ?? [], ['.', '..']); - if (empty($files) === true && Dir::remove($dir) === true) { - // continue with the next level up - $dir = dirname($dir); - } else { - // no need to continue with the next level up as `$dir` was not deleted - break; - } - } - } catch (Exception $e) { // @codeCoverageIgnore - // silently stops the process - } - } + if (empty($files) === true && Dir::remove($dir) === true) { + // continue with the next level up + $dir = dirname($dir); + } else { + // no need to continue with the next level up as `$dir` was not deleted + break; + } + } + } catch (Exception $e) { // @codeCoverageIgnore + // silently stops the process + } + } - /** - * Flushes the entire cache and returns - * whether the operation was successful - * - * @return bool - */ - public function flush(): bool - { - if (Dir::remove($this->root) === true && Dir::make($this->root) === true) { - return true; - } + /** + * Flushes the entire cache and returns + * whether the operation was successful + * + * @return bool + */ + public function flush(): bool + { + if (Dir::remove($this->root) === true && Dir::make($this->root) === true) { + return true; + } - return false; // @codeCoverageIgnore - } + return false; // @codeCoverageIgnore + } } diff --git a/kirby/src/Cache/MemCached.php b/kirby/src/Cache/MemCached.php index de83a85..591919f 100755 --- a/kirby/src/Cache/MemCached.php +++ b/kirby/src/Cache/MemCached.php @@ -15,85 +15,85 @@ use Memcached as MemcachedExt; */ class MemCached extends Cache { - /** - * store for the memcache connection - * @var \Memcached - */ - protected $connection; + /** + * store for the memcache connection + * @var \Memcached + */ + protected $connection; - /** - * Sets all parameters which are needed to connect to Memcached - * - * @param array $options 'host' (default: localhost) - * 'port' (default: 11211) - * 'prefix' (default: null) - */ - public function __construct(array $options = []) - { - $defaults = [ - 'host' => 'localhost', - 'port' => 11211, - 'prefix' => null, - ]; + /** + * Sets all parameters which are needed to connect to Memcached + * + * @param array $options 'host' (default: localhost) + * 'port' (default: 11211) + * 'prefix' (default: null) + */ + public function __construct(array $options = []) + { + $defaults = [ + 'host' => 'localhost', + 'port' => 11211, + 'prefix' => null, + ]; - parent::__construct(array_merge($defaults, $options)); + parent::__construct(array_merge($defaults, $options)); - $this->connection = new MemcachedExt(); - $this->connection->addServer($this->options['host'], $this->options['port']); - } + $this->connection = new MemcachedExt(); + $this->connection->addServer($this->options['host'], $this->options['port']); + } - /** - * Writes an item to the cache for a given number of minutes and - * returns whether the operation was successful - * - * - * // put an item in the cache for 15 minutes - * $cache->set('value', 'my value', 15); - * - * - * @param string $key - * @param mixed $value - * @param int $minutes - * @return bool - */ - public function set(string $key, $value, int $minutes = 0): bool - { - return $this->connection->set($this->key($key), (new Value($value, $minutes))->toJson(), $this->expiration($minutes)); - } + /** + * Writes an item to the cache for a given number of minutes and + * returns whether the operation was successful + * + * + * // put an item in the cache for 15 minutes + * $cache->set('value', 'my value', 15); + * + * + * @param string $key + * @param mixed $value + * @param int $minutes + * @return bool + */ + public function set(string $key, $value, int $minutes = 0): bool + { + return $this->connection->set($this->key($key), (new Value($value, $minutes))->toJson(), $this->expiration($minutes)); + } - /** - * Internal method to retrieve the raw cache value; - * needs to return a Value object or null if not found - * - * @param string $key - * @return \Kirby\Cache\Value|null - */ - public function retrieve(string $key) - { - return Value::fromJson($this->connection->get($this->key($key))); - } + /** + * Internal method to retrieve the raw cache value; + * needs to return a Value object or null if not found + * + * @param string $key + * @return \Kirby\Cache\Value|null + */ + public function retrieve(string $key) + { + return Value::fromJson($this->connection->get($this->key($key))); + } - /** - * Removes an item from the cache and returns - * whether the operation was successful - * - * @param string $key - * @return bool - */ - public function remove(string $key): bool - { - return $this->connection->delete($this->key($key)); - } + /** + * Removes an item from the cache and returns + * whether the operation was successful + * + * @param string $key + * @return bool + */ + public function remove(string $key): bool + { + return $this->connection->delete($this->key($key)); + } - /** - * Flushes the entire cache and returns - * whether the operation was successful; - * WARNING: Memcached only supports flushing the whole cache at once! - * - * @return bool - */ - public function flush(): bool - { - return $this->connection->flush(); - } + /** + * Flushes the entire cache and returns + * whether the operation was successful; + * WARNING: Memcached only supports flushing the whole cache at once! + * + * @return bool + */ + public function flush(): bool + { + return $this->connection->flush(); + } } diff --git a/kirby/src/Cache/MemoryCache.php b/kirby/src/Cache/MemoryCache.php index 5b0d40d..3ee6636 100755 --- a/kirby/src/Cache/MemoryCache.php +++ b/kirby/src/Cache/MemoryCache.php @@ -13,70 +13,70 @@ namespace Kirby\Cache; */ class MemoryCache extends Cache { - /** - * Cache data - * @var array - */ - protected $store = []; + /** + * Cache data + * @var array + */ + protected $store = []; - /** - * Writes an item to the cache for a given number of minutes and - * returns whether the operation was successful - * - * - * // put an item in the cache for 15 minutes - * $cache->set('value', 'my value', 15); - * - * - * @param string $key - * @param mixed $value - * @param int $minutes - * @return bool - */ - public function set(string $key, $value, int $minutes = 0): bool - { - $this->store[$key] = new Value($value, $minutes); - return true; - } + /** + * Writes an item to the cache for a given number of minutes and + * returns whether the operation was successful + * + * + * // put an item in the cache for 15 minutes + * $cache->set('value', 'my value', 15); + * + * + * @param string $key + * @param mixed $value + * @param int $minutes + * @return bool + */ + public function set(string $key, $value, int $minutes = 0): bool + { + $this->store[$key] = new Value($value, $minutes); + return true; + } - /** - * Internal method to retrieve the raw cache value; - * needs to return a Value object or null if not found - * - * @param string $key - * @return \Kirby\Cache\Value|null - */ - public function retrieve(string $key) - { - return $this->store[$key] ?? null; - } + /** + * Internal method to retrieve the raw cache value; + * needs to return a Value object or null if not found + * + * @param string $key + * @return \Kirby\Cache\Value|null + */ + public function retrieve(string $key) + { + return $this->store[$key] ?? null; + } - /** - * Removes an item from the cache and returns - * whether the operation was successful - * - * @param string $key - * @return bool - */ - public function remove(string $key): bool - { - if (isset($this->store[$key])) { - unset($this->store[$key]); - return true; - } else { - return false; - } - } + /** + * Removes an item from the cache and returns + * whether the operation was successful + * + * @param string $key + * @return bool + */ + public function remove(string $key): bool + { + if (isset($this->store[$key])) { + unset($this->store[$key]); + return true; + } else { + return false; + } + } - /** - * Flushes the entire cache and returns - * whether the operation was successful - * - * @return bool - */ - public function flush(): bool - { - $this->store = []; - return true; - } + /** + * Flushes the entire cache and returns + * whether the operation was successful + * + * @return bool + */ + public function flush(): bool + { + $this->store = []; + return true; + } } diff --git a/kirby/src/Cache/NullCache.php b/kirby/src/Cache/NullCache.php index 1064504..36b419e 100755 --- a/kirby/src/Cache/NullCache.php +++ b/kirby/src/Cache/NullCache.php @@ -13,57 +13,57 @@ namespace Kirby\Cache; */ class NullCache extends Cache { - /** - * Writes an item to the cache for a given number of minutes and - * returns whether the operation was successful - * - * - * // put an item in the cache for 15 minutes - * $cache->set('value', 'my value', 15); - * - * - * @param string $key - * @param mixed $value - * @param int $minutes - * @return bool - */ - public function set(string $key, $value, int $minutes = 0): bool - { - return true; - } + /** + * Writes an item to the cache for a given number of minutes and + * returns whether the operation was successful + * + * + * // put an item in the cache for 15 minutes + * $cache->set('value', 'my value', 15); + * + * + * @param string $key + * @param mixed $value + * @param int $minutes + * @return bool + */ + public function set(string $key, $value, int $minutes = 0): bool + { + return true; + } - /** - * Internal method to retrieve the raw cache value; - * needs to return a Value object or null if not found - * - * @param string $key - * @return \Kirby\Cache\Value|null - */ - public function retrieve(string $key) - { - return null; - } + /** + * Internal method to retrieve the raw cache value; + * needs to return a Value object or null if not found + * + * @param string $key + * @return \Kirby\Cache\Value|null + */ + public function retrieve(string $key) + { + return null; + } - /** - * Removes an item from the cache and returns - * whether the operation was successful - * - * @param string $key - * @return bool - */ - public function remove(string $key): bool - { - return true; - } + /** + * Removes an item from the cache and returns + * whether the operation was successful + * + * @param string $key + * @return bool + */ + public function remove(string $key): bool + { + return true; + } - /** - * Flushes the entire cache and returns - * whether the operation was successful - * - * @return bool - */ - public function flush(): bool - { - return true; - } + /** + * Flushes the entire cache and returns + * whether the operation was successful + * + * @return bool + */ + public function flush(): bool + { + return true; + } } diff --git a/kirby/src/Cache/Value.php b/kirby/src/Cache/Value.php index 075d76b..3a1105e 100755 --- a/kirby/src/Cache/Value.php +++ b/kirby/src/Cache/Value.php @@ -17,136 +17,136 @@ use Throwable; */ class Value { - /** - * Cached value - * @var mixed - */ - protected $value; + /** + * Cached value + * @var mixed + */ + protected $value; - /** - * the number of minutes until the value expires - * @todo Rename this property to $expiry to reflect - * both minutes and absolute timestamps - * @var int - */ - protected $minutes; + /** + * the number of minutes until the value expires + * @todo Rename this property to $expiry to reflect + * both minutes and absolute timestamps + * @var int + */ + protected $minutes; - /** - * Creation timestamp - * @var int - */ - protected $created; + /** + * Creation timestamp + * @var int + */ + protected $created; - /** - * Constructor - * - * @param mixed $value - * @param int $minutes the number of minutes until the value expires - * or an absolute UNIX timestamp - * @param int $created the UNIX timestamp when the value has been created - */ - public function __construct($value, int $minutes = 0, int $created = null) - { - $this->value = $value; - $this->minutes = $minutes ?? 0; - $this->created = $created ?? time(); - } + /** + * Constructor + * + * @param mixed $value + * @param int $minutes the number of minutes until the value expires + * or an absolute UNIX timestamp + * @param int $created the UNIX timestamp when the value has been created + */ + public function __construct($value, int $minutes = 0, int $created = null) + { + $this->value = $value; + $this->minutes = $minutes ?? 0; + $this->created = $created ?? time(); + } - /** - * Returns the creation date as UNIX timestamp - * - * @return int - */ - public function created(): int - { - return $this->created; - } + /** + * Returns the creation date as UNIX timestamp + * + * @return int + */ + public function created(): int + { + return $this->created; + } - /** - * Returns the expiration date as UNIX timestamp or - * null if the value never expires - * - * @return int|null - */ - public function expires(): ?int - { - // 0 = keep forever - if ($this->minutes === 0) { - return null; - } + /** + * Returns the expiration date as UNIX timestamp or + * null if the value never expires + * + * @return int|null + */ + public function expires(): ?int + { + // 0 = keep forever + if ($this->minutes === 0) { + return null; + } - if ($this->minutes > 1000000000) { - // absolute timestamp - return $this->minutes; - } + if ($this->minutes > 1000000000) { + // absolute timestamp + return $this->minutes; + } - return $this->created + ($this->minutes * 60); - } + return $this->created + ($this->minutes * 60); + } - /** - * Creates a value object from an array - * - * @param array $array - * @return static - */ - public static function fromArray(array $array) - { - return new static($array['value'] ?? null, $array['minutes'] ?? 0, $array['created'] ?? null); - } + /** + * Creates a value object from an array + * + * @param array $array + * @return static + */ + public static function fromArray(array $array) + { + return new static($array['value'] ?? null, $array['minutes'] ?? 0, $array['created'] ?? null); + } - /** - * Creates a value object from a JSON string; - * returns null on error - * - * @param string $json - * @return static|null - */ - public static function fromJson(string $json) - { - try { - $array = json_decode($json, true); + /** + * Creates a value object from a JSON string; + * returns null on error + * + * @param string $json + * @return static|null + */ + public static function fromJson(string $json) + { + try { + $array = json_decode($json, true); - if (is_array($array)) { - return static::fromArray($array); - } else { - return null; - } - } catch (Throwable $e) { - return null; - } - } + if (is_array($array)) { + return static::fromArray($array); + } else { + return null; + } + } catch (Throwable $e) { + return null; + } + } - /** - * Converts the object to a JSON string - * - * @return string - */ - public function toJson(): string - { - return json_encode($this->toArray()); - } + /** + * Converts the object to a JSON string + * + * @return string + */ + public function toJson(): string + { + return json_encode($this->toArray()); + } - /** - * Converts the object to an array - * - * @return array - */ - public function toArray(): array - { - return [ - 'created' => $this->created, - 'minutes' => $this->minutes, - 'value' => $this->value, - ]; - } + /** + * Converts the object to an array + * + * @return array + */ + public function toArray(): array + { + return [ + 'created' => $this->created, + 'minutes' => $this->minutes, + 'value' => $this->value, + ]; + } - /** - * Returns the pure value - * - * @return mixed - */ - public function value() - { - return $this->value; - } + /** + * Returns the pure value + * + * @return mixed + */ + public function value() + { + return $this->value; + } } diff --git a/kirby/src/Cms/Api.php b/kirby/src/Cms/Api.php index 45b3fe9..30aa140 100755 --- a/kirby/src/Cms/Api.php +++ b/kirby/src/Cms/Api.php @@ -17,229 +17,229 @@ use Kirby\Form\Form; */ class Api extends BaseApi { - /** - * @var App - */ - protected $kirby; + /** + * @var App + */ + protected $kirby; - /** - * Execute an API call for the given path, - * request method and optional request data - * - * @param string|null $path - * @param string $method - * @param array $requestData - * @return mixed - */ - public function call(string $path = null, string $method = 'GET', array $requestData = []) - { - $this->setRequestMethod($method); - $this->setRequestData($requestData); + /** + * Execute an API call for the given path, + * request method and optional request data + * + * @param string|null $path + * @param string $method + * @param array $requestData + * @return mixed + */ + public function call(string $path = null, string $method = 'GET', array $requestData = []) + { + $this->setRequestMethod($method); + $this->setRequestData($requestData); - $this->kirby->setCurrentLanguage($this->language()); + $this->kirby->setCurrentLanguage($this->language()); - $allowImpersonation = $this->kirby()->option('api.allowImpersonation', false); - if ($user = $this->kirby->user(null, $allowImpersonation)) { - $translation = $user->language(); - } else { - $translation = $this->kirby->panelLanguage(); - } - $this->kirby->setCurrentTranslation($translation); + $allowImpersonation = $this->kirby()->option('api.allowImpersonation', false); + if ($user = $this->kirby->user(null, $allowImpersonation)) { + $translation = $user->language(); + } else { + $translation = $this->kirby->panelLanguage(); + } + $this->kirby->setCurrentTranslation($translation); - return parent::call($path, $method, $requestData); - } + return parent::call($path, $method, $requestData); + } - /** - * @param mixed $model - * @param string $name - * @param string|null $path - * @return mixed - * @throws \Kirby\Exception\NotFoundException if the field type cannot be found or the field cannot be loaded - */ - public function fieldApi($model, string $name, string $path = null) - { - $field = Form::for($model)->field($name); + /** + * @param mixed $model + * @param string $name + * @param string|null $path + * @return mixed + * @throws \Kirby\Exception\NotFoundException if the field type cannot be found or the field cannot be loaded + */ + public function fieldApi($model, string $name, string $path = null) + { + $field = Form::for($model)->field($name); - $fieldApi = new static( - array_merge($this->propertyData, [ - 'data' => array_merge($this->data(), ['field' => $field]), - 'routes' => $field->api(), - ]), - ); + $fieldApi = new static( + array_merge($this->propertyData, [ + 'data' => array_merge($this->data(), ['field' => $field]), + 'routes' => $field->api(), + ]), + ); - return $fieldApi->call($path, $this->requestMethod(), $this->requestData()); - } + return $fieldApi->call($path, $this->requestMethod(), $this->requestData()); + } - /** - * Returns the file object for the given - * parent path and filename - * - * @param string|null $path Path to file's parent model - * @param string $filename Filename - * @return \Kirby\Cms\File|null - * @throws \Kirby\Exception\NotFoundException if the file cannot be found - */ - public function file(string $path = null, string $filename) - { - return Find::file($path, $filename); - } + /** + * Returns the file object for the given + * parent path and filename + * + * @param string|null $path Path to file's parent model + * @param string $filename Filename + * @return \Kirby\Cms\File|null + * @throws \Kirby\Exception\NotFoundException if the file cannot be found + */ + public function file(string $path = null, string $filename) + { + return Find::file($path, $filename); + } - /** - * Returns the model's object for the given path - * - * @param string $path Path to parent model - * @return \Kirby\Cms\Model|null - * @throws \Kirby\Exception\InvalidArgumentException if the model type is invalid - * @throws \Kirby\Exception\NotFoundException if the model cannot be found - */ - public function parent(string $path) - { - return Find::parent($path); - } + /** + * Returns the model's object for the given path + * + * @param string $path Path to parent model + * @return \Kirby\Cms\Model|null + * @throws \Kirby\Exception\InvalidArgumentException if the model type is invalid + * @throws \Kirby\Exception\NotFoundException if the model cannot be found + */ + public function parent(string $path) + { + return Find::parent($path); + } - /** - * Returns the Kirby instance - * - * @return \Kirby\Cms\App - */ - public function kirby() - { - return $this->kirby; - } + /** + * Returns the Kirby instance + * + * @return \Kirby\Cms\App + */ + public function kirby() + { + return $this->kirby; + } - /** - * Returns the language request header - * - * @return string|null - */ - public function language(): ?string - { - return $this->requestQuery('language') ?? $this->requestHeaders('x-language'); - } + /** + * Returns the language request header + * + * @return string|null + */ + public function language(): ?string + { + return $this->requestQuery('language') ?? $this->requestHeaders('x-language'); + } - /** - * Returns the page object for the given id - * - * @param string $id Page's id - * @return \Kirby\Cms\Page|null - * @throws \Kirby\Exception\NotFoundException if the page cannot be found - */ - public function page(string $id) - { - return Find::page($id); - } + /** + * Returns the page object for the given id + * + * @param string $id Page's id + * @return \Kirby\Cms\Page|null + * @throws \Kirby\Exception\NotFoundException if the page cannot be found + */ + public function page(string $id) + { + return Find::page($id); + } - /** - * 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); + /** + * 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(); - } - } + 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')); + /** + * 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')); - } + if ($this->requestMethod() === 'GET') { + return $pages->search($this->requestQuery('q')); + } - return $pages->query($this->requestBody()); - } + return $pages->query($this->requestBody()); + } - /** - * Returns the current Session instance - * - * @param array $options Additional options, see the session component - * @return \Kirby\Session\Session - */ - public function session(array $options = []) - { - return $this->kirby->session(array_merge([ - 'detect' => true - ], $options)); - } + /** + * Returns the current Session instance + * + * @param array $options Additional options, see the session component + * @return \Kirby\Session\Session + */ + public function session(array $options = []) + { + return $this->kirby->session(array_merge([ + 'detect' => true + ], $options)); + } - /** - * Setter for the parent Kirby instance - * - * @param \Kirby\Cms\App $kirby - * @return $this - */ - protected function setKirby(App $kirby) - { - $this->kirby = $kirby; - return $this; - } + /** + * Setter for the parent Kirby instance + * + * @param \Kirby\Cms\App $kirby + * @return $this + */ + protected function setKirby(App $kirby) + { + $this->kirby = $kirby; + return $this; + } - /** - * Returns the site object - * - * @return \Kirby\Cms\Site - */ - public function site() - { - return $this->kirby->site(); - } + /** + * Returns the site object + * + * @return \Kirby\Cms\Site + */ + public function site() + { + return $this->kirby->site(); + } - /** - * Returns the user object for the given id or - * returns the current authenticated user if no - * id is passed - * - * @param string|null $id User's id - * @return \Kirby\Cms\User|null - * @throws \Kirby\Exception\NotFoundException if the user for the given id cannot be found - */ - public function user(string $id = null) - { - try { - return Find::user($id); - } catch (NotFoundException $e) { - if ($id === null) { - return null; - } + /** + * Returns the user object for the given id or + * returns the current authenticated user if no + * id is passed + * + * @param string|null $id User's id + * @return \Kirby\Cms\User|null + * @throws \Kirby\Exception\NotFoundException if the user for the given id cannot be found + */ + public function user(string $id = null) + { + try { + return Find::user($id); + } catch (NotFoundException $e) { + if ($id === null) { + return null; + } - throw $e; - } - } + throw $e; + } + } - /** - * Returns the users collection - * - * @return \Kirby\Cms\Users - */ - public function users() - { - return $this->kirby->users(); - } + /** + * Returns the users collection + * + * @return \Kirby\Cms\Users + */ + public function users() + { + return $this->kirby->users(); + } } diff --git a/kirby/src/Cms/App.php b/kirby/src/Cms/App.php index df889b9..e49b644 100755 --- a/kirby/src/Cms/App.php +++ b/kirby/src/Cms/App.php @@ -40,1756 +40,1770 @@ use Throwable; */ class App { - use AppCaches; - use AppErrors; - use AppPlugins; - use AppTranslations; - use AppUsers; - use Properties; - - public const CLASS_ALIAS = 'kirby'; - - protected static $instance; - protected static $version; - - public $data = []; - - protected $api; - protected $collections; - protected $core; - protected $defaultLanguage; - protected $environment; - protected $language; - protected $languages; - protected $locks; - protected $multilang; - protected $nonce; - protected $options; - protected $path; - protected $request; - protected $response; - protected $roles; - protected $roots; - protected $routes; - protected $router; - protected $sessionHandler; - protected $site; - protected $system; - protected $urls; - protected $user; - protected $users; - protected $visitor; - - /** - * Creates a new App instance - * - * @param array $props - * @param bool $setInstance If false, the instance won't be set globally - */ - public function __construct(array $props = [], bool $setInstance = true) - { - $this->core = new Core($this); - - // register all roots to be able to load stuff afterwards - $this->bakeRoots($props['roots'] ?? []); - - try { - // stuff from config and additional options - $this->optionsFromConfig(); - $this->optionsFromProps($props['options'] ?? []); - $this->optionsFromEnvironment($props); - } finally { - // register the Whoops error handler inside of a - // try-finally block to ensure it's still registered - // even if there is a problem loading the configurations - $this->handleErrors(); - } - - // a custom request setup must come before defining the path - $this->setRequest($props['request'] ?? null); - - // set the path to make it available for the url bakery - $this->setPath($props['path'] ?? null); - - // create all urls after the config, so possible - // options can be taken into account - $this->bakeUrls($props['urls'] ?? []); - - // configurable properties - $this->setOptionalProperties($props, [ - 'languages', - 'roles', - 'site', - 'user', - 'users' - ]); - - // set the singleton - if (static::$instance === null || $setInstance === true) { - Model::$kirby = static::$instance = $this; - } - - // setup the I18n class with the translation loader - $this->i18n(); - - // load all extensions - $this->extensionsFromSystem(); - $this->extensionsFromProps($props); - $this->extensionsFromPlugins(); - $this->extensionsFromOptions(); - $this->extensionsFromFolders(); - - // trigger hook for use in plugins - $this->trigger('system.loadPlugins:after'); - - // execute a ready callback from the config - $this->optionsFromReadyCallback(); - - // bake config - $this->bakeOptions(); - } - - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return [ - 'languages' => $this->languages(), - 'options' => $this->options(), - 'request' => $this->request(), - 'roots' => $this->roots(), - 'site' => $this->site(), - 'urls' => $this->urls(), - 'version' => $this->version(), - ]; - } - - /** - * Returns the Api instance - * - * @internal - * @return \Kirby\Cms\Api - */ - public function api() - { - if ($this->api !== null) { - return $this->api; - } - - $root = $this->root('kirby') . '/config/api'; - $extensions = $this->extensions['api'] ?? []; - $routes = (include $root . '/routes.php')($this); - - $api = [ - 'debug' => $this->option('debug', false), - 'authentication' => $extensions['authentication'] ?? include $root . '/authentication.php', - 'data' => $extensions['data'] ?? [], - 'collections' => array_merge($extensions['collections'] ?? [], include $root . '/collections.php'), - 'models' => array_merge($extensions['models'] ?? [], include $root . '/models.php'), - 'routes' => array_merge($routes, $extensions['routes'] ?? []), - 'kirby' => $this, - ]; - - return $this->api = new Api($api); - } - - /** - * Applies a hook to the given value - * - * @internal - * @param string $name Full event name - * @param array $args Associative array of named event arguments - * @param string $modify Key in $args that is modified by the hooks - * @param \Kirby\Cms\Event|null $originalEvent Event object (internal use) - * @return mixed Resulting value as modified by the hooks - */ - public function apply(string $name, array $args, string $modify, ?Event $originalEvent = null) - { - $event = $originalEvent ?? new Event($name, $args); - - if ($functions = $this->extension('hooks', $name)) { - foreach ($functions as $function) { - // bind the App object to the hook - $newValue = $event->call($this, $function); - - // update value if one was returned - if ($newValue !== null) { - $event->updateArgument($modify, $newValue); - } - } - } - - // apply wildcard hooks if available - $nameWildcards = $event->nameWildcards(); - if ($originalEvent === null && count($nameWildcards) > 0) { - foreach ($nameWildcards as $nameWildcard) { - // the $event object is passed by reference - // and will be modified down the chain - $this->apply($nameWildcard, $event->arguments(), $modify, $event); - } - } - - return $event->argument($modify); - } - - /** - * Normalizes and globally sets the configured options - * - * @return $this - */ - protected function bakeOptions() - { - // convert the old plugin option syntax to the new one - foreach ($this->options as $key => $value) { - // detect option keys with the `vendor.plugin.option` format - if (preg_match('/^([a-z0-9-]+\.[a-z0-9-]+)\.(.*)$/i', $key, $matches) === 1) { - list(, $plugin, $option) = $matches; - - // verify that it's really a plugin option - if (isset(static::$plugins[str_replace('.', '/', $plugin)]) !== true) { - continue; - } - - // ensure that the target option array exists - // (which it will if the plugin has any options) - if (isset($this->options[$plugin]) !== true) { - $this->options[$plugin] = []; // @codeCoverageIgnore - } - - // move the option to the plugin option array - // don't overwrite nested arrays completely but merge them - $this->options[$plugin] = array_replace_recursive($this->options[$plugin], [$option => $value]); - unset($this->options[$key]); - } - } - - Config::$data = $this->options; - return $this; - } - - /** - * Sets the directory structure - * - * @param array|null $roots - * @return $this - */ - protected function bakeRoots(array $roots = null) - { - $roots = array_merge($this->core->roots(), (array)$roots); - $this->roots = Ingredients::bake($roots); - return $this; - } - - /** - * Sets the Url structure - * - * @param array|null $urls - * @return $this - */ - protected function bakeUrls(array $urls = null) - { - $urls = array_merge($this->core->urls(), (array)$urls); - $this->urls = Ingredients::bake($urls); - return $this; - } - - /** - * Returns all available blueprints for this installation - * - * @param string $type - * @return array - */ - public function blueprints(string $type = 'pages'): array - { - $blueprints = []; - - foreach ($this->extensions('blueprints') as $name => $blueprint) { - if (dirname($name) === $type) { - $name = basename($name); - $blueprints[$name] = $name; - } - } - - foreach (glob($this->root('blueprints') . '/' . $type . '/*.yml') as $blueprint) { - $name = F::name($blueprint); - $blueprints[$name] = $name; - } - - ksort($blueprints); - - return array_values($blueprints); - } - - /** - * Calls any Kirby route - * - * @param string|null $path - * @param string|null $method - * @return mixed - */ - public function call(string $path = null, string $method = null) - { - $path ??= $this->path(); - $method ??= $this->request()->method(); - return $this->router()->call($path, $method); - } - - /** - * Creates an instance with the same - * initial properties - * - * @param array $props - * @param bool $setInstance If false, the instance won't be set globally - * @return static - */ - public function clone(array $props = [], bool $setInstance = true) - { - $props = array_replace_recursive($this->propertyData, $props); - - $clone = new static($props, $setInstance); - $clone->data = $this->data; - - return $clone; - } - - /** - * Returns a specific user-defined collection - * by name. All relevant dependencies are - * automatically injected - * - * @param string $name - * @return \Kirby\Cms\Collection|null - */ - public function collection(string $name) - { - return $this->collections()->get($name, [ - 'kirby' => $this, - 'site' => $this->site(), - 'pages' => $this->site()->children(), - 'users' => $this->users() - ]); - } - - /** - * Returns all user-defined collections - * - * @return \Kirby\Cms\Collections - */ - public function collections() - { - return $this->collections = $this->collections ?? new Collections(); - } - - /** - * Returns a core component - * - * @internal - * @param string $name - * @return mixed - */ - public function component($name) - { - return $this->extensions['components'][$name] ?? null; - } - - /** - * Returns the content extension - * - * @internal - * @return string - */ - public function contentExtension(): string - { - return $this->options['content']['extension'] ?? 'txt'; - } - - /** - * Returns files that should be ignored when scanning folders - * - * @internal - * @return array - */ - public function contentIgnore(): array - { - return $this->options['content']['ignore'] ?? Dir::$ignore; - } - - /** - * Generates a non-guessable token based on model - * data and a configured salt - * - * @param mixed $model Object to pass to the salt callback if configured - * @param string $value Model data to include in the generated token - * @return string - */ - public function contentToken($model, string $value): string - { - if (method_exists($model, 'root') === true) { - $default = $model->root(); - } else { - $default = $this->root('content'); - } - - $salt = $this->option('content.salt', $default); - - if (is_a($salt, 'Closure') === true) { - $salt = $salt($model); - } - - return hash_hmac('sha1', $value, $salt); - } - - /** - * Calls a page controller by name - * and with the given arguments - * - * @internal - * @param string $name - * @param array $arguments - * @param string $contentType - * @return array - */ - public function controller(string $name, array $arguments = [], string $contentType = 'html'): array - { - $name = basename(strtolower($name)); - - if ($controller = $this->controllerLookup($name, $contentType)) { - return (array)$controller->call($this, $arguments); - } - - if ($contentType !== 'html') { - - // no luck for a specific representation controller? - // let's try the html controller instead - if ($controller = $this->controllerLookup($name)) { - return (array)$controller->call($this, $arguments); - } - } - - // still no luck? Let's take the site controller - if ($controller = $this->controllerLookup('site')) { - return (array)$controller->call($this, $arguments); - } - - return []; - } - - /** - * Try to find a controller by name - * - * @param string $name - * @param string $contentType - * @return \Kirby\Toolkit\Controller|null - */ - protected function controllerLookup(string $name, string $contentType = 'html') - { - if ($contentType !== null && $contentType !== 'html') { - $name .= '.' . $contentType; - } - - // controller on disk - if ($controller = Controller::load($this->root('controllers') . '/' . $name . '.php')) { - return $controller; - } - - // registry controller - if ($controller = $this->extension('controllers', $name)) { - return is_a($controller, 'Kirby\Toolkit\Controller') ? $controller : new Controller($controller); - } - - return null; - } - - /** - * Get access to object that lists - * all parts of Kirby core - * - * @return \Kirby\Cms\Core - */ - public function core() - { - return $this->core; - } - - /** - * Checks/returns a CSRF token - * @since 3.7.0 - * - * @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 - */ - public function csrf(?string $check = null) - { - $session = $this->session(); - - // 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!) - if (func_num_args() === 0) { - $token = $session->get('kirby.csrf'); - - if (is_string($token) !== true) { - $token = bin2hex(random_bytes(32)); - $session->set('kirby.csrf', $token); - } - - return $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; - } - - return false; - } - - /** - * Returns the default language object - * - * @return \Kirby\Cms\Language|null - */ - public function defaultLanguage() - { - return $this->defaultLanguage = $this->defaultLanguage ?? $this->languages()->default(); - } - - /** - * Destroy the instance singleton and - * purge other static props - * - * @internal - */ - public static function destroy(): void - { - static::$plugins = []; - static::$instance = null; - } - - /** - * Detect the preferred language from the visitor object - * - * @return \Kirby\Cms\Language - */ - public function detectedLanguage() - { - $languages = $this->languages(); - $visitor = $this->visitor(); - - foreach ($visitor->acceptedLanguages() as $lang) { - if ($language = $languages->findBy('locale', $lang->locale(LC_ALL))) { - return $language; - } - } - - foreach ($visitor->acceptedLanguages() as $lang) { - if ($language = $languages->findBy('code', $lang->code())) { - return $language; - } - } - - return $this->defaultLanguage(); - } - - /** - * Returns the Email singleton - * - * @param mixed $preset - * @param array $props - * @return \Kirby\Email\Email - */ - public function email($preset = [], array $props = []) - { - $debug = $props['debug'] ?? false; - $props = (new Email($preset, $props))->toArray(); - - return ($this->component('email'))($this, $props, $debug); - } - - /** - * Returns the environment object with access - * to the detected host, base url and dedicated options - * - * @return \Kirby\Http\Environment - */ - public function environment() - { - return $this->environment ?? new Environment(); - } - - /** - * Finds any file in the content directory - * - * @param string $path - * @param mixed $parent - * @param bool $drafts - * @return \Kirby\Cms\File|null - */ - public function file(string $path, $parent = null, bool $drafts = true) - { - $parent = $parent ?? $this->site(); - $id = dirname($path); - $filename = basename($path); - - if (is_a($parent, 'Kirby\Cms\User') === true) { - return $parent->file($filename); - } - - if (is_a($parent, 'Kirby\Cms\File') === true) { - $parent = $parent->parent(); - } - - if ($id === '.') { - if ($file = $parent->file($filename)) { - return $file; - } - - if ($file = $this->site()->file($filename)) { - return $file; - } - - return null; - } - - if ($page = $this->page($id, $parent, $drafts)) { - return $page->file($filename); - } - - if ($page = $this->page($id, null, $drafts)) { - return $page->file($filename); - } - - return null; - } - - /** - * Return an image from any page - * specified by the path - * - * Example: - * - * - * @param string|null $path - * @return \Kirby\Cms\File|null - * - * @todo merge with App::file() - */ - public function image(?string $path = null) - { - if ($path === null) { - return $this->site()->page()->image(); - } - - $uri = dirname($path); - $filename = basename($path); - - if ($uri === '.') { - $uri = null; - } - - switch ($uri) { - case '/': - $parent = $this->site(); - break; - case null: - $parent = $this->site()->page(); - break; - default: - $parent = $this->site()->page($uri); - break; - } - - if ($parent) { - return $parent->image($filename); - } - - return null; - } - - /** - * Returns the current App instance - * - * @param \Kirby\Cms\App|null $instance - * @param bool $lazy If `true`, the instance is only returned if already existing - * @return static|null - */ - public static function instance(self $instance = null, bool $lazy = false) - { - if ($instance === null) { - if ($lazy === true) { - return static::$instance; - } else { - return static::$instance ?? new static(); - } - } - - return static::$instance = $instance; - } - - /** - * Takes almost any kind of input and - * tries to convert it into a valid response - * - * @internal - * @param mixed $input - * @return \Kirby\Http\Response - */ - public function io($input) - { - // use the current response configuration - $response = $this->response(); - - // any direct exception will be turned into an error page - if (is_a($input, 'Throwable') === true) { - if (is_a($input, 'Kirby\Exception\Exception') === true) { - $code = $input->getHttpCode(); - } else { - $code = $input->getCode(); - } - $message = $input->getMessage(); - - if ($code < 400 || $code > 599) { - $code = 500; - } - - if ($errorPage = $this->site()->errorPage()) { - return $response->code($code)->send($errorPage->render([ - 'errorCode' => $code, - 'errorMessage' => $message, - 'errorType' => get_class($input) - ])); - } - - return $response - ->code($code) - ->type('text/html') - ->send($message); - } - - // Empty input - if (empty($input) === true) { - return $this->io(new NotFoundException()); - } - - // (Modified) global response configuration, e.g. in routes - if (is_a($input, 'Kirby\Cms\Responder') === true) { - // return the passed object unmodified (without injecting headers - // from the global object) to allow a complete response override - // https://github.com/getkirby/kirby/pull/4144#issuecomment-1034766726 - return $input->send(); - } - - // Responses - if (is_a($input, 'Kirby\Http\Response') === true) { - $data = $input->toArray(); - - // inject headers from the global response configuration - // lazily (only if they are not already set); - // the case-insensitive nature of headers will be - // handled by PHP's `header()` function - $data['headers'] = array_merge($response->headers(), $data['headers']); - - return new Response($data); - } - - // Pages - if (is_a($input, 'Kirby\Cms\Page')) { - try { - $html = $input->render(); - } catch (ErrorPageException $e) { - return $this->io($e); - } - - if ($input->isErrorPage() === true) { - if ($response->code() === null) { - $response->code(404); - } - } - - return $response->send($html); - } - - // Files - if (is_a($input, 'Kirby\Cms\File')) { - return $response->redirect($input->mediaUrl(), 307)->send(); - } - - // Simple HTML response - if (is_string($input) === true) { - return $response->send($input); - } - - // array to json conversion - if (is_array($input) === true) { - return $response->json($input)->send(); - } - - throw new InvalidArgumentException('Unexpected input'); - } - - /** - * Renders a single KirbyTag with the given attributes - * - * @internal - * @param string|array $type Tag type or array with all tag arguments - * (the key of the first element becomes the type) - * @param string|null $value - * @param array $attr - * @param array $data - * @return string - */ - public function kirbytag($type, ?string $value = null, array $attr = [], array $data = []): string - { - if (is_array($type) === true) { - $kirbytag = $type; - $type = key($kirbytag); - $value = current($kirbytag); - $attr = $kirbytag; - - // check data attribute and separate from attr data if exists - if (isset($attr['data']) === true) { - $data = $attr['data']; - unset($attr['data']); - } - } - - $data['kirby'] = $data['kirby'] ?? $this; - $data['site'] = $data['site'] ?? $data['kirby']->site(); - $data['parent'] = $data['parent'] ?? $data['site']->page(); - - return (new KirbyTag($type, $value, $attr, $data, $this->options))->render(); - } - - /** - * KirbyTags Parser - * - * @internal - * @param string|null $text - * @param array $data - * @return string - */ - public function kirbytags(string $text = null, array $data = []): string - { - $data['kirby'] ??= $this; - $data['site'] ??= $data['kirby']->site(); - $data['parent'] ??= $data['site']->page(); - - $options = $this->options; - - $text = $this->apply('kirbytags:before', compact('text', 'data', 'options'), 'text'); - $text = KirbyTags::parse($text, $data, $options); - $text = $this->apply('kirbytags:after', compact('text', 'data', 'options'), 'text'); - - return $text; - } - - /** - * Parses KirbyTags first and Markdown afterwards - * - * @internal - * @param string|null $text - * @param array $options - * @param bool $inline (deprecated: use $options['markdown']['inline'] instead) - * @return string - * @todo remove $inline parameter in in 3.8.0 - */ - public function kirbytext(string $text = null, array $options = [], bool $inline = false): string - { - // warning for deprecated fourth parameter - // @codeCoverageIgnoreStart - if (func_num_args() === 3) { - Helpers::deprecated('Cms\App::kirbytext(): the $inline parameter is deprecated and will be removed in Kirby 3.8.0. Use $options[\'markdown\'][\'inline\'] instead.'); - } - // @codeCoverageIgnoreEnd - - $options['markdown']['inline'] ??= $inline; - - $text = $this->apply('kirbytext:before', compact('text'), 'text'); - $text = $this->kirbytags($text, $options); - $text = $this->markdown($text, $options['markdown']); - - if ($this->option('smartypants', false) !== false) { - $text = $this->smartypants($text); - } - - $text = $this->apply('kirbytext:after', compact('text'), 'text'); - - return $text; - } - - /** - * Returns the current language - * - * @param string|null $code - * @return \Kirby\Cms\Language|null - */ - public function language(string $code = null) - { - if ($this->multilang() === false) { - return null; - } - - if ($code === 'default') { - return $this->languages()->default(); - } - - if ($code !== null) { - return $this->languages()->find($code); - } - - return $this->language = $this->language ?? $this->languages()->default(); - } - - /** - * Returns the current language code - * - * @internal - * @param string|null $languageCode - * @return string|null - */ - public function languageCode(string $languageCode = null): ?string - { - if ($language = $this->language($languageCode)) { - return $language->code(); - } - - return null; - } - - /** - * Returns all available site languages - * - * @param bool - * @return \Kirby\Cms\Languages - */ - public function languages(bool $clone = true) - { - if ($this->languages !== null) { - return $clone === true ? clone $this->languages : $this->languages; - } - - return $this->languages = Languages::load(); - } - - /** - * Access Kirby's part loader - * - * @return \Kirby\Cms\Loader - */ - public function load() - { - return new Loader($this); - } - - /** - * Returns the app's locks object - * - * @return \Kirby\Cms\ContentLocks - */ - public function locks(): ContentLocks - { - if ($this->locks !== null) { - return $this->locks; - } - - return $this->locks = new ContentLocks(); - } - - /** - * Parses Markdown - * - * @internal - * @param string|null $text - * @param bool|array $options Boolean inline value is deprecated, use `['inline' => true]` instead - * @return string - * @todo remove boolean $options in in 3.8.0 - */ - public function markdown(string $text = null, $options = null): string - { - // support for the old syntax to enable inline mode as second argument - // @codeCoverageIgnoreStart - if (is_bool($options) === true) { - Helpers::deprecated('Cms\App::markdown(): Passing a boolean as second parameter has been deprecated and won\'t be supported anymore in Kirby 3.8.0. Instead pass array with the key "inline" set to true or false.'); - - $options = [ - 'inline' => $options - ]; - } - // @codeCoverageIgnoreEnd - - // merge global options with local options - $options = array_merge( - $this->options['markdown'] ?? [], - (array)$options - ); - - // TODO: remove passing the $inline parameter in 3.8.0 - // $options['inline'] is set to `false` to avoid the deprecation - // warning in the component; this can also be removed in 3.8.0 - $inline = $options['inline'] ??= false; - return ($this->component('markdown'))($this, $text, $options, $inline); - } - - /** - * Check for a multilang setup - * - * @return bool - */ - public function multilang(): bool - { - if ($this->multilang !== null) { - return $this->multilang; - } - - return $this->multilang = $this->languages()->count() !== 0; - } - - /** - * Returns the nonce, which is used - * in the panel for inline scripts - * @since 3.3.0 - * - * @return string - */ - public function nonce(): string - { - return $this->nonce = $this->nonce ?? base64_encode(random_bytes(20)); - } - - /** - * Load a specific configuration option - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function option(string $key, $default = null) - { - return A::get($this->options, $key, $default); - } - - /** - * Returns all configuration options - * - * @return array - */ - public function options(): array - { - return $this->options; - } - - /** - * Load all options from files in site/config - * - * @return array - */ - protected function optionsFromConfig(): array - { - // create an empty config container - Config::$data = []; - - // load the main config options - $root = $this->root('config'); - $options = F::load($root . '/config.php', []); - - // merge into one clean options array - return $this->options = array_replace_recursive(Config::$data, $options); - } - - /** - * Load all options for the current - * server environment - * - * @param array $props - * @return array - */ - protected function optionsFromEnvironment(array $props = []): array - { - // create the environment based on the URL setup - $this->environment = new Environment([ - 'allowed' => $this->options['url'] ?? null, - 'cli' => $props['cli'] ?? null, - ], $props['server'] ?? null); - - // merge into one clean options array - $options = $this->environment()->options($this->root('config')); - return $this->options = array_replace_recursive($this->options, $options); - } - - /** - * Inject options from Kirby instance props - * - * @param array $options - * @return array - */ - protected function optionsFromProps(array $options = []): array - { - return $this->options = array_replace_recursive( - $this->options, - $options - ); - } - - /** - * Merge last-minute options from ready callback - * - * @return array - */ - protected function optionsFromReadyCallback(): array - { - if (isset($this->options['ready']) === true && is_callable($this->options['ready']) === true) { - // fetch last-minute options from the callback - $options = (array)$this->options['ready']($this); - - // inject all last-minute options recursively - $this->options = array_replace_recursive($this->options, $options); - - // update the system with changed options - if ( - isset($options['debug']) === true || - isset($options['whoops']) === true || - isset($options['editor']) === true - ) { - $this->handleErrors(); - } - - if (isset($options['debug']) === true) { - $this->api = null; - } - - if (isset($options['home']) === true || isset($options['error']) === true) { - $this->site = null; - } - - // checks custom language definition for slugs - if ($slugsOption = $this->option('slugs')) { - // slugs option must be set to string or "slugs" => ["language" => "de"] as array - if (is_string($slugsOption) === true || isset($slugsOption['language']) === true) { - $this->i18n(); - } - } - } - - return $this->options; - } - - /** - * Returns any page from the content folder - * - * @param string|null $id - * @param \Kirby\Cms\Page|\Kirby\Cms\Site|null $parent - * @param bool $drafts - * @return \Kirby\Cms\Page|null - */ - public function page(?string $id = null, $parent = null, bool $drafts = true) - { - if ($id === null) { - return null; - } - - $parent = $parent ?? $this->site(); - - if ($page = $parent->find($id)) { - /** - * We passed a single $id, we can be sure that the result is - * @var \Kirby\Cms\Page $page - */ - return $page; - } - - if ($drafts === true && $draft = $parent->draft($id)) { - return $draft; - } - - return null; - } - - /** - * Returns the request path - * - * @return string - */ - public function path(): string - { - if (is_string($this->path) === true) { - return $this->path; - } - - $current = $this->request()->path()->toString(); - $index = $this->environment()->baseUri()->path()->toString(); - $path = Str::afterStart($current, $index); - - return $this->setPath($path)->path; - } - - /** - * Returns the Response object for the - * current request - * - * @param string|null $path - * @param string|null $method - * @return \Kirby\Http\Response - */ - public function render(string $path = null, string $method = null) - { - return $this->io($this->call($path, $method)); - } - - /** - * Returns the Request singleton - * - * @return \Kirby\Http\Request - */ - public function request() - { - if ($this->request !== null) { - return $this->request; - } - - $env = $this->environment(); - - return $this->request = new Request([ - 'cli' => $env->cli(), - 'url' => $env->requestUri() - ]); - } - - /** - * Path resolver for the router - * - * @internal - * @param string|null $path - * @param string|null $language - * @return mixed - * @throws \Kirby\Exception\NotFoundException if the home page cannot be found - */ - public function resolve(string $path = null, string $language = null) - { - // set the current translation - $this->setCurrentTranslation($language); - - // set the current locale - $this->setCurrentLanguage($language); - - // the site is needed a couple times here - $site = $this->site(); - - // use the home page - if ($path === null) { - if ($homePage = $site->homePage()) { - return $homePage; - } - - throw new NotFoundException('The home page does not exist'); - } - - // search for the page by path - $page = $site->find($path); - - // search for a draft if the page cannot be found - if (!$page && $draft = $site->draft($path)) { - if ($this->user() || $draft->isVerified($this->request()->get('token'))) { - $page = $draft; - } - } - - // try to resolve content representations if the path has an extension - $extension = F::extension($path); - - // no content representation? then return the page - if (empty($extension) === true) { - return $page; - } - - // only try to return a representation - // when the page has been found - if ($page) { - try { - $response = $this->response(); - $output = $page->render([], $extension); - - // 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($output); - } catch (NotFoundException $e) { - return null; - } - } - - $id = dirname($path); - $filename = basename($path); - - // try to resolve image urls for pages and drafts - if ($page = $site->findPageOrDraft($id)) { - return $page->file($filename); - } - - // try to resolve site files at least - return $site->file($filename); - } - - /** - * Response configuration - * - * @return \Kirby\Cms\Responder - */ - public function response() - { - return $this->response = $this->response ?? new Responder(); - } - - /** - * Returns all user roles - * - * @return \Kirby\Cms\Roles - */ - public function roles() - { - return $this->roles = $this->roles ?? Roles::load($this->root('roles')); - } - - /** - * Returns a system root - * - * @param string $type - * @return string|null - */ - public function root(string $type = 'index'): ?string - { - return $this->roots->__get($type); - } - - /** - * Returns the directory structure - * - * @return \Kirby\Cms\Ingredients - */ - public function roots() - { - return $this->roots; - } - - /** - * Returns the currently active route - * - * @return \Kirby\Http\Route|null - */ - public function route() - { - return $this->router()->route(); - } - - /** - * Returns the Router singleton - * - * @internal - * @return \Kirby\Http\Router - */ - public function router() - { - $routes = $this->routes(); - - if ($this->multilang() === true) { - foreach ($routes as $index => $route) { - if (empty($route['language']) === false) { - unset($routes[$index]); - } - } - } - - $hooks = [ - 'beforeEach' => function ($route, $path, $method) { - $this->trigger('route:before', compact('route', 'path', 'method')); - }, - 'afterEach' => function ($route, $path, $method, $result, $final) { - return $this->apply('route:after', compact('route', 'path', 'method', 'result', 'final'), 'result'); - } - ]; - - return $this->router ??= new Router($routes, $hooks); - } - - /** - * Returns all defined routes - * - * @internal - * @return array - */ - public function routes(): array - { - if (is_array($this->routes) === true) { - return $this->routes; - } - - $registry = $this->extensions('routes'); - $system = $this->core->routes(); - $routes = array_merge($system['before'], $registry, $system['after']); - - return $this->routes = $routes; - } - - /** - * Returns the current session object - * - * @param array $options Additional options, see the session component - * @return \Kirby\Session\Session - */ - public function session(array $options = []) - { - $session = $this->sessionHandler()->get($options); - - // disable caching for sessions that use the `Authorization` header; - // cookie sessions are already covered by the `Cookie` class - if ($session->mode() === 'manual') { - $this->response()->cache(false); - $this->response()->header('Cache-Control', 'no-store, private', true); - } - - return $session; - } - - /** - * Returns the session handler - * - * @return \Kirby\Session\AutoSession - */ - public function sessionHandler() - { - $this->sessionHandler = $this->sessionHandler ?? new AutoSession($this->root('sessions'), $this->option('session', [])); - return $this->sessionHandler; - } - - /** - * Create your own set of languages - * - * @param array|null $languages - * @return $this - */ - protected function setLanguages(array $languages = null) - { - if ($languages !== null) { - $objects = []; - - foreach ($languages as $props) { - $objects[] = new Language($props); - } - - $this->languages = new Languages($objects); - } - - return $this; - } - - /** - * Sets the request path that is - * used for the router - * - * @param string|null $path - * @return $this - */ - protected function setPath(string $path = null) - { - $this->path = $path !== null ? trim($path, '/') : null; - return $this; - } - - /** - * Sets the request - * - * @param array|null $request - * @return $this - */ - protected function setRequest(array $request = null) - { - if ($request !== null) { - $this->request = new Request($request); - } - - return $this; - } - - /** - * Create your own set of roles - * - * @param array|null $roles - * @return $this - */ - protected function setRoles(array $roles = null) - { - if ($roles !== null) { - $this->roles = Roles::factory($roles, [ - 'kirby' => $this - ]); - } - - return $this; - } - - /** - * Sets a custom Site object - * - * @param \Kirby\Cms\Site|array|null $site - * @return $this - */ - protected function setSite($site = null) - { - if (is_array($site) === true) { - $site = new Site($site + [ - 'kirby' => $this - ]); - } - - $this->site = $site; - return $this; - } - - /** - * Returns the Environment object - * @deprecated 3.7.0 Use `$kirby->environment()` instead - * - * @return \Kirby\Http\Environment - * @todo Start throwing deprecation warnings in 3.8.0 - * @todo Remove in 3.9.0 - * @codeCoverageIgnore - */ - public function server() - { - return $this->environment(); - } - - /** - * Initializes and returns the Site object - * - * @return \Kirby\Cms\Site - */ - public function site() - { - return $this->site = $this->site ?? new Site([ - 'errorPageId' => $this->options['error'] ?? 'error', - 'homePageId' => $this->options['home'] ?? 'home', - 'kirby' => $this, - 'url' => $this->url('index'), - ]); - } - - /** - * Applies the smartypants rule on the text - * - * @internal - * @param string|null $text - * @return string - */ - public function smartypants(string $text = null): string - { - $options = $this->option('smartypants', []); - - if ($options === false) { - return $text; - } elseif (is_array($options) === false) { - $options = []; - } - - if ($this->multilang() === true) { - $languageSmartypants = $this->language()->smartypants() ?? []; - - if (empty($languageSmartypants) === false) { - $options = array_merge($options, $languageSmartypants); - } - } - - return ($this->component('smartypants'))($this, $text, $options); - } - - /** - * Uses the snippet component to create - * and return a template snippet - * - * @internal - * @param mixed $name - * @param array|object $data Variables or an object that becomes `$item` - * @param bool $return On `false`, directly echo the snippet - * @return string|null - */ - public function snippet($name, $data = [], bool $return = true): ?string - { - if (is_object($data) === true) { - $data = ['item' => $data]; - } - - $snippet = ($this->component('snippet'))($this, $name, array_merge($this->data, $data)); - - if ($return === true) { - return $snippet; - } - - echo $snippet; - return null; - } - - /** - * System check class - * - * @return \Kirby\Cms\System - */ - public function system() - { - return $this->system = $this->system ?? new System($this); - } - - /** - * Uses the template component to initialize - * and return the Template object - * - * @internal - * @return \Kirby\Cms\Template - * @param string $name - * @param string $type - * @param string $defaultType - */ - public function template(string $name, string $type = 'html', string $defaultType = 'html') - { - return ($this->component('template'))($this, $name, $type, $defaultType); - } - - /** - * Thumbnail creator - * - * @param string $src - * @param string $dst - * @param array $options - * @return string - */ - public function thumb(string $src, string $dst, array $options = []): string - { - return ($this->component('thumb'))($this, $src, $dst, $options); - } - - /** - * Trigger a hook by name - * - * @internal - * @param string $name Full event name - * @param array $args Associative array of named event arguments - * @param \Kirby\Cms\Event|null $originalEvent Event object (internal use) - * @return void - */ - public function trigger(string $name, array $args = [], ?Event $originalEvent = null) - { - $event = $originalEvent ?? new Event($name, $args); - - if ($functions = $this->extension('hooks', $name)) { - static $level = 0; - static $triggered = []; - $level++; - - foreach ($functions as $index => $function) { - if (in_array($function, $triggered[$name] ?? []) === true) { - continue; - } - - // mark the hook as triggered, to avoid endless loops - $triggered[$name][] = $function; - - // bind the App object to the hook - $event->call($this, $function); - } - - $level--; - - if ($level === 0) { - $triggered = []; - } - } - - // trigger wildcard hooks if available - $nameWildcards = $event->nameWildcards(); - if ($originalEvent === null && count($nameWildcards) > 0) { - foreach ($nameWildcards as $nameWildcard) { - $this->trigger($nameWildcard, $args, $event); - } - } - } - - /** - * Returns a system url - * - * @param string $type - * @param bool $object If set to `true`, the URL is converted to an object - * @return string|\Kirby\Http\Uri|null - */ - public function url(string $type = 'index', bool $object = false) - { - $url = $this->urls->__get($type); - - if ($object === true) { - if (Url::isAbsolute($url)) { - return Url::toObject($url); - } - - // index URL was configured without host, use the current host - return Uri::current([ - 'path' => $url, - 'query' => null - ]); - } - - return $url; - } - - /** - * Returns the url structure - * - * @return \Kirby\Cms\Ingredients - */ - public function urls() - { - return $this->urls; - } - - /** - * Returns the current version number from - * the composer.json (Keep that up to date! :)) - * - * @return string|null - * @throws \Kirby\Exception\LogicException if the Kirby version cannot be detected - */ - public static function version(): ?string - { - try { - return static::$version = static::$version ?? Data::read(dirname(__DIR__, 2) . '/composer.json')['version'] ?? null; - } catch (Throwable $e) { - throw new LogicException('The Kirby version cannot be detected. The composer.json is probably missing or not readable.'); - } - } - - /** - * Creates a hash of the version number - * - * @return string - */ - public static function versionHash(): string - { - return md5(static::version()); - } - - /** - * Returns the visitor object - * - * @return \Kirby\Http\Visitor - */ - public function visitor() - { - return $this->visitor = $this->visitor ?? new Visitor(); - } + use AppCaches; + use AppErrors; + use AppPlugins; + use AppTranslations; + use AppUsers; + use Properties; + + public const CLASS_ALIAS = 'kirby'; + + protected static $instance; + protected static $version; + + public $data = []; + + protected $api; + protected $collections; + protected $core; + protected $defaultLanguage; + protected $environment; + protected $language; + protected $languages; + protected $locks; + protected $multilang; + protected $nonce; + protected $options; + protected $path; + protected $request; + protected $response; + protected $roles; + protected $roots; + protected $routes; + protected $router; + protected $sessionHandler; + protected $site; + protected $system; + protected $urls; + protected $user; + protected $users; + protected $visitor; + + /** + * Creates a new App instance + * + * @param array $props + * @param bool $setInstance If false, the instance won't be set globally + */ + public function __construct(array $props = [], bool $setInstance = true) + { + $this->core = new Core($this); + + // register all roots to be able to load stuff afterwards + $this->bakeRoots($props['roots'] ?? []); + + try { + // stuff from config and additional options + $this->optionsFromConfig(); + $this->optionsFromProps($props['options'] ?? []); + $this->optionsFromEnvironment($props); + } finally { + // register the Whoops error handler inside of a + // try-finally block to ensure it's still registered + // even if there is a problem loading the configurations + $this->handleErrors(); + } + + // a custom request setup must come before defining the path + $this->setRequest($props['request'] ?? null); + + // set the path to make it available for the url bakery + $this->setPath($props['path'] ?? null); + + // create all urls after the config, so possible + // options can be taken into account + $this->bakeUrls($props['urls'] ?? []); + + // configurable properties + $this->setOptionalProperties($props, [ + 'languages', + 'roles', + 'site', + 'user', + 'users' + ]); + + // set the singleton + if (static::$instance === null || $setInstance === true) { + Model::$kirby = static::$instance = $this; + } + + // setup the I18n class with the translation loader + $this->i18n(); + + // load all extensions + $this->extensionsFromSystem(); + $this->extensionsFromProps($props); + $this->extensionsFromPlugins(); + $this->extensionsFromOptions(); + $this->extensionsFromFolders(); + + // trigger hook for use in plugins + $this->trigger('system.loadPlugins:after'); + + // execute a ready callback from the config + $this->optionsFromReadyCallback(); + + // bake config + $this->bakeOptions(); + } + + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return [ + 'languages' => $this->languages(), + 'options' => $this->options(), + 'request' => $this->request(), + 'roots' => $this->roots(), + 'site' => $this->site(), + 'urls' => $this->urls(), + 'version' => $this->version(), + ]; + } + + /** + * Returns the Api instance + * + * @internal + * @return \Kirby\Cms\Api + */ + public function api() + { + if ($this->api !== null) { + return $this->api; + } + + $root = $this->root('kirby') . '/config/api'; + $extensions = $this->extensions['api'] ?? []; + $routes = (include $root . '/routes.php')($this); + + $api = [ + 'debug' => $this->option('debug', false), + 'authentication' => $extensions['authentication'] ?? include $root . '/authentication.php', + 'data' => $extensions['data'] ?? [], + 'collections' => array_merge($extensions['collections'] ?? [], include $root . '/collections.php'), + 'models' => array_merge($extensions['models'] ?? [], include $root . '/models.php'), + 'routes' => array_merge($routes, $extensions['routes'] ?? []), + 'kirby' => $this, + ]; + + return $this->api = new Api($api); + } + + /** + * Applies a hook to the given value + * + * @internal + * @param string $name Full event name + * @param array $args Associative array of named event arguments + * @param string $modify Key in $args that is modified by the hooks + * @param \Kirby\Cms\Event|null $originalEvent Event object (internal use) + * @return mixed Resulting value as modified by the hooks + */ + public function apply(string $name, array $args, string $modify, ?Event $originalEvent = null) + { + $event = $originalEvent ?? new Event($name, $args); + + if ($functions = $this->extension('hooks', $name)) { + foreach ($functions as $function) { + // bind the App object to the hook + $newValue = $event->call($this, $function); + + // update value if one was returned + if ($newValue !== null) { + $event->updateArgument($modify, $newValue); + } + } + } + + // apply wildcard hooks if available + $nameWildcards = $event->nameWildcards(); + if ($originalEvent === null && count($nameWildcards) > 0) { + foreach ($nameWildcards as $nameWildcard) { + // the $event object is passed by reference + // and will be modified down the chain + $this->apply($nameWildcard, $event->arguments(), $modify, $event); + } + } + + return $event->argument($modify); + } + + /** + * Normalizes and globally sets the configured options + * + * @return $this + */ + protected function bakeOptions() + { + // convert the old plugin option syntax to the new one + foreach ($this->options as $key => $value) { + // detect option keys with the `vendor.plugin.option` format + if (preg_match('/^([a-z0-9-]+\.[a-z0-9-]+)\.(.*)$/i', $key, $matches) === 1) { + list(, $plugin, $option) = $matches; + + // verify that it's really a plugin option + if (isset(static::$plugins[str_replace('.', '/', $plugin)]) !== true) { + continue; + } + + // ensure that the target option array exists + // (which it will if the plugin has any options) + if (isset($this->options[$plugin]) !== true) { + $this->options[$plugin] = []; // @codeCoverageIgnore + } + + // move the option to the plugin option array + // don't overwrite nested arrays completely but merge them + $this->options[$plugin] = array_replace_recursive($this->options[$plugin], [$option => $value]); + unset($this->options[$key]); + } + } + + Config::$data = $this->options; + return $this; + } + + /** + * Sets the directory structure + * + * @param array|null $roots + * @return $this + */ + protected function bakeRoots(array $roots = null) + { + $roots = array_merge($this->core->roots(), (array)$roots); + $this->roots = Ingredients::bake($roots); + return $this; + } + + /** + * Sets the Url structure + * + * @param array|null $urls + * @return $this + */ + protected function bakeUrls(array $urls = null) + { + $urls = array_merge($this->core->urls(), (array)$urls); + $this->urls = Ingredients::bake($urls); + return $this; + } + + /** + * Returns all available blueprints for this installation + * + * @param string $type + * @return array + */ + public function blueprints(string $type = 'pages'): array + { + $blueprints = []; + + foreach ($this->extensions('blueprints') as $name => $blueprint) { + if (dirname($name) === $type) { + $name = basename($name); + $blueprints[$name] = $name; + } + } + + foreach (glob($this->root('blueprints') . '/' . $type . '/*.yml') as $blueprint) { + $name = F::name($blueprint); + $blueprints[$name] = $name; + } + + ksort($blueprints); + + return array_values($blueprints); + } + + /** + * Calls any Kirby route + * + * @param string|null $path + * @param string|null $method + * @return mixed + */ + public function call(string $path = null, string $method = null) + { + $path ??= $this->path(); + $method ??= $this->request()->method(); + return $this->router()->call($path, $method); + } + + /** + * Creates an instance with the same + * initial properties + * + * @param array $props + * @param bool $setInstance If false, the instance won't be set globally + * @return static + */ + public function clone(array $props = [], bool $setInstance = true) + { + $props = array_replace_recursive($this->propertyData, $props); + + $clone = new static($props, $setInstance); + $clone->data = $this->data; + + return $clone; + } + + /** + * Returns a specific user-defined collection + * by name. All relevant dependencies are + * automatically injected + * + * @param string $name + * @return \Kirby\Cms\Collection|null + */ + public function collection(string $name) + { + return $this->collections()->get($name, [ + 'kirby' => $this, + 'site' => $this->site(), + 'pages' => $this->site()->children(), + 'users' => $this->users() + ]); + } + + /** + * Returns all user-defined collections + * + * @return \Kirby\Cms\Collections + */ + public function collections() + { + return $this->collections = $this->collections ?? new Collections(); + } + + /** + * Returns a core component + * + * @internal + * @param string $name + * @return mixed + */ + public function component($name) + { + return $this->extensions['components'][$name] ?? null; + } + + /** + * Returns the content extension + * + * @internal + * @return string + */ + public function contentExtension(): string + { + return $this->options['content']['extension'] ?? 'txt'; + } + + /** + * Returns files that should be ignored when scanning folders + * + * @internal + * @return array + */ + public function contentIgnore(): array + { + return $this->options['content']['ignore'] ?? Dir::$ignore; + } + + /** + * Generates a non-guessable token based on model + * data and a configured salt + * + * @param mixed $model Object to pass to the salt callback if configured + * @param string $value Model data to include in the generated token + * @return string + */ + public function contentToken($model, string $value): string + { + if (method_exists($model, 'root') === true) { + $default = $model->root(); + } else { + $default = $this->root('content'); + } + + $salt = $this->option('content.salt', $default); + + if (is_a($salt, 'Closure') === true) { + $salt = $salt($model); + } + + return hash_hmac('sha1', $value, $salt); + } + + /** + * Calls a page controller by name + * and with the given arguments + * + * @internal + * @param string $name + * @param array $arguments + * @param string $contentType + * @return array + */ + public function controller(string $name, array $arguments = [], string $contentType = 'html'): array + { + $name = basename(strtolower($name)); + + if ($controller = $this->controllerLookup($name, $contentType)) { + return (array)$controller->call($this, $arguments); + } + + if ($contentType !== 'html') { + + // no luck for a specific representation controller? + // let's try the html controller instead + if ($controller = $this->controllerLookup($name)) { + return (array)$controller->call($this, $arguments); + } + } + + // still no luck? Let's take the site controller + if ($controller = $this->controllerLookup('site')) { + return (array)$controller->call($this, $arguments); + } + + return []; + } + + /** + * Try to find a controller by name + * + * @param string $name + * @param string $contentType + * @return \Kirby\Toolkit\Controller|null + */ + protected function controllerLookup(string $name, string $contentType = 'html') + { + if ($contentType !== null && $contentType !== 'html') { + $name .= '.' . $contentType; + } + + // controller on disk + if ($controller = Controller::load($this->root('controllers') . '/' . $name . '.php')) { + return $controller; + } + + // registry controller + if ($controller = $this->extension('controllers', $name)) { + return is_a($controller, 'Kirby\Toolkit\Controller') ? $controller : new Controller($controller); + } + + return null; + } + + /** + * Get access to object that lists + * all parts of Kirby core + * + * @return \Kirby\Cms\Core + */ + public function core() + { + return $this->core; + } + + /** + * Checks/returns a CSRF token + * @since 3.7.0 + * + * @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 + */ + public function csrf(?string $check = null) + { + $session = $this->session(); + + // 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!) + if (func_num_args() === 0) { + $token = $session->get('kirby.csrf'); + + if (is_string($token) !== true) { + $token = bin2hex(random_bytes(32)); + $session->set('kirby.csrf', $token); + } + + return $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; + } + + return false; + } + + /** + * Returns the default language object + * + * @return \Kirby\Cms\Language|null + */ + public function defaultLanguage() + { + return $this->defaultLanguage = $this->defaultLanguage ?? $this->languages()->default(); + } + + /** + * Destroy the instance singleton and + * purge other static props + * + * @internal + */ + public static function destroy(): void + { + static::$plugins = []; + static::$instance = null; + } + + /** + * Detect the preferred language from the visitor object + * + * @return \Kirby\Cms\Language + */ + public function detectedLanguage() + { + $languages = $this->languages(); + $visitor = $this->visitor(); + + foreach ($visitor->acceptedLanguages() as $lang) { + if ($language = $languages->findBy('locale', $lang->locale(LC_ALL))) { + return $language; + } + } + + foreach ($visitor->acceptedLanguages() as $lang) { + if ($language = $languages->findBy('code', $lang->code())) { + return $language; + } + } + + return $this->defaultLanguage(); + } + + /** + * Returns the Email singleton + * + * @param mixed $preset + * @param array $props + * @return \Kirby\Email\Email + */ + public function email($preset = [], array $props = []) + { + $debug = $props['debug'] ?? false; + $props = (new Email($preset, $props))->toArray(); + + return ($this->component('email'))($this, $props, $debug); + } + + /** + * Returns the environment object with access + * to the detected host, base url and dedicated options + * + * @return \Kirby\Http\Environment + */ + public function environment() + { + return $this->environment ?? new Environment(); + } + + /** + * Finds any file in the content directory + * + * @param string $path + * @param mixed $parent + * @param bool $drafts + * @return \Kirby\Cms\File|null + */ + public function file(string $path, $parent = null, bool $drafts = true) + { + $parent = $parent ?? $this->site(); + $id = dirname($path); + $filename = basename($path); + + if (is_a($parent, 'Kirby\Cms\User') === true) { + return $parent->file($filename); + } + + if (is_a($parent, 'Kirby\Cms\File') === true) { + $parent = $parent->parent(); + } + + if ($id === '.') { + if ($file = $parent->file($filename)) { + return $file; + } + + if ($file = $this->site()->file($filename)) { + return $file; + } + + return null; + } + + if ($page = $this->page($id, $parent, $drafts)) { + return $page->file($filename); + } + + if ($page = $this->page($id, null, $drafts)) { + return $page->file($filename); + } + + return null; + } + + /** + * Return an image from any page + * specified by the path + * + * Example: + * + * + * @param string|null $path + * @return \Kirby\Cms\File|null + * + * @todo merge with App::file() + */ + public function image(?string $path = null) + { + if ($path === null) { + return $this->site()->page()->image(); + } + + $uri = dirname($path); + $filename = basename($path); + + if ($uri === '.') { + $uri = null; + } + + switch ($uri) { + case '/': + $parent = $this->site(); + break; + case null: + $parent = $this->site()->page(); + break; + default: + $parent = $this->site()->page($uri); + break; + } + + if ($parent) { + return $parent->image($filename); + } + + return null; + } + + /** + * Returns the current App instance + * + * @param \Kirby\Cms\App|null $instance + * @param bool $lazy If `true`, the instance is only returned if already existing + * @return static|null + */ + public static function instance(self $instance = null, bool $lazy = false) + { + if ($instance === null) { + if ($lazy === true) { + return static::$instance; + } else { + return static::$instance ?? new static(); + } + } + + return static::$instance = $instance; + } + + /** + * Takes almost any kind of input and + * tries to convert it into a valid response + * + * @internal + * @param mixed $input + * @return \Kirby\Http\Response + */ + public function io($input) + { + // use the current response configuration + $response = $this->response(); + + // any direct exception will be turned into an error page + if (is_a($input, 'Throwable') === true) { + if (is_a($input, 'Kirby\Exception\Exception') === true) { + $code = $input->getHttpCode(); + } else { + $code = $input->getCode(); + } + $message = $input->getMessage(); + + if ($code < 400 || $code > 599) { + $code = 500; + } + + if ($errorPage = $this->site()->errorPage()) { + return $response->code($code)->send($errorPage->render([ + 'errorCode' => $code, + 'errorMessage' => $message, + 'errorType' => get_class($input) + ])); + } + + return $response + ->code($code) + ->type('text/html') + ->send($message); + } + + // Empty input + if (empty($input) === true) { + return $this->io(new NotFoundException()); + } + + // (Modified) global response configuration, e.g. in routes + if (is_a($input, 'Kirby\Cms\Responder') === true) { + // return the passed object unmodified (without injecting headers + // from the global object) to allow a complete response override + // https://github.com/getkirby/kirby/pull/4144#issuecomment-1034766726 + return $input->send(); + } + + // Responses + if (is_a($input, 'Kirby\Http\Response') === true) { + $data = $input->toArray(); + + // inject headers from the global response configuration + // lazily (only if they are not already set); + // the case-insensitive nature of headers will be + // handled by PHP's `header()` function + $data['headers'] = array_merge($response->headers(), $data['headers']); + + return new Response($data); + } + + // Pages + if (is_a($input, 'Kirby\Cms\Page')) { + try { + $html = $input->render(); + } catch (ErrorPageException $e) { + return $this->io($e); + } + + if ($input->isErrorPage() === true) { + if ($response->code() === null) { + $response->code(404); + } + } + + return $response->send($html); + } + + // Files + if (is_a($input, 'Kirby\Cms\File')) { + return $response->redirect($input->mediaUrl(), 307)->send(); + } + + // Simple HTML response + if (is_string($input) === true) { + return $response->send($input); + } + + // array to json conversion + if (is_array($input) === true) { + return $response->json($input)->send(); + } + + throw new InvalidArgumentException('Unexpected input'); + } + + /** + * Renders a single KirbyTag with the given attributes + * + * @internal + * @param string|array $type Tag type or array with all tag arguments + * (the key of the first element becomes the type) + * @param string|null $value + * @param array $attr + * @param array $data + * @return string + */ + public function kirbytag($type, ?string $value = null, array $attr = [], array $data = []): string + { + if (is_array($type) === true) { + $kirbytag = $type; + $type = key($kirbytag); + $value = current($kirbytag); + $attr = $kirbytag; + + // check data attribute and separate from attr data if exists + if (isset($attr['data']) === true) { + $data = $attr['data']; + unset($attr['data']); + } + } + + $data['kirby'] = $data['kirby'] ?? $this; + $data['site'] = $data['site'] ?? $data['kirby']->site(); + $data['parent'] = $data['parent'] ?? $data['site']->page(); + + return (new KirbyTag($type, $value, $attr, $data, $this->options))->render(); + } + + /** + * KirbyTags Parser + * + * @internal + * @param string|null $text + * @param array $data + * @return string + */ + public function kirbytags(string $text = null, array $data = []): string + { + $data['kirby'] ??= $this; + $data['site'] ??= $data['kirby']->site(); + $data['parent'] ??= $data['site']->page(); + + $options = $this->options; + + $text = $this->apply('kirbytags:before', compact('text', 'data', 'options'), 'text'); + $text = KirbyTags::parse($text, $data, $options); + $text = $this->apply('kirbytags:after', compact('text', 'data', 'options'), 'text'); + + return $text; + } + + /** + * Parses KirbyTags first and Markdown afterwards + * + * @internal + * @param string|null $text + * @param array $options + * @param bool $inline (deprecated: use $options['markdown']['inline'] instead) + * @return string + * @todo remove $inline parameter in in 3.8.0 + */ + public function kirbytext(string $text = null, array $options = [], bool $inline = false): string + { + // warning for deprecated fourth parameter + // @codeCoverageIgnoreStart + if (func_num_args() === 3) { + Helpers::deprecated('Cms\App::kirbytext(): the $inline parameter is deprecated and will be removed in Kirby 3.8.0. Use $options[\'markdown\'][\'inline\'] instead.'); + } + // @codeCoverageIgnoreEnd + + $options['markdown']['inline'] ??= $inline; + + $text = $this->apply('kirbytext:before', compact('text'), 'text'); + $text = $this->kirbytags($text, $options); + $text = $this->markdown($text, $options['markdown']); + + if ($this->option('smartypants', false) !== false) { + $text = $this->smartypants($text); + } + + $text = $this->apply('kirbytext:after', compact('text'), 'text'); + + return $text; + } + + /** + * Returns the current language + * + * @param string|null $code + * @return \Kirby\Cms\Language|null + */ + public function language(string $code = null) + { + if ($this->multilang() === false) { + return null; + } + + if ($code === 'default') { + return $this->languages()->default(); + } + + if ($code !== null) { + return $this->languages()->find($code); + } + + return $this->language = $this->language ?? $this->languages()->default(); + } + + /** + * Returns the current language code + * + * @internal + * @param string|null $languageCode + * @return string|null + */ + public function languageCode(string $languageCode = null): ?string + { + if ($language = $this->language($languageCode)) { + return $language->code(); + } + + return null; + } + + /** + * Returns all available site languages + * + * @param bool + * @return \Kirby\Cms\Languages + */ + public function languages(bool $clone = true) + { + if ($this->languages !== null) { + return $clone === true ? clone $this->languages : $this->languages; + } + + return $this->languages = Languages::load(); + } + + /** + * Access Kirby's part loader + * + * @return \Kirby\Cms\Loader + */ + public function load() + { + return new Loader($this); + } + + /** + * Returns the app's locks object + * + * @return \Kirby\Cms\ContentLocks + */ + public function locks(): ContentLocks + { + if ($this->locks !== null) { + return $this->locks; + } + + return $this->locks = new ContentLocks(); + } + + /** + * Parses Markdown + * + * @internal + * @param string|null $text + * @param bool|array $options Boolean inline value is deprecated, use `['inline' => true]` instead + * @return string + * @todo remove boolean $options in in 3.8.0 + */ + public function markdown(string $text = null, $options = null): string + { + // support for the old syntax to enable inline mode as second argument + // @codeCoverageIgnoreStart + if (is_bool($options) === true) { + Helpers::deprecated('Cms\App::markdown(): Passing a boolean as second parameter has been deprecated and won\'t be supported anymore in Kirby 3.8.0. Instead pass array with the key "inline" set to true or false.'); + + $options = [ + 'inline' => $options + ]; + } + // @codeCoverageIgnoreEnd + + // merge global options with local options + $options = array_merge( + $this->options['markdown'] ?? [], + (array)$options + ); + + // TODO: remove passing the $inline parameter in 3.8.0 + // $options['inline'] is set to `false` to avoid the deprecation + // warning in the component; this can also be removed in 3.8.0 + $inline = $options['inline'] ??= false; + return ($this->component('markdown'))($this, $text, $options, $inline); + } + + /** + * Check for a multilang setup + * + * @return bool + */ + public function multilang(): bool + { + if ($this->multilang !== null) { + return $this->multilang; + } + + return $this->multilang = $this->languages()->count() !== 0; + } + + /** + * Returns the nonce, which is used + * in the panel for inline scripts + * @since 3.3.0 + * + * @return string + */ + public function nonce(): string + { + return $this->nonce = $this->nonce ?? base64_encode(random_bytes(20)); + } + + /** + * Load a specific configuration option + * + * @param string $key + * @param mixed $default + * @return mixed + */ + public function option(string $key, $default = null) + { + return A::get($this->options, $key, $default); + } + + /** + * Returns all configuration options + * + * @return array + */ + public function options(): array + { + return $this->options; + } + + /** + * Load all options from files in site/config + * + * @return array + */ + protected function optionsFromConfig(): array + { + // create an empty config container + Config::$data = []; + + // load the main config options + $root = $this->root('config'); + $options = F::load($root . '/config.php', []); + + // merge into one clean options array + return $this->options = array_replace_recursive(Config::$data, $options); + } + + /** + * Load all options for the current + * server environment + * + * @param array $props + * @return array + */ + protected function optionsFromEnvironment(array $props = []): array + { + $globalUrl = $this->options['url'] ?? null; + + // create the environment based on the URL setup + $this->environment = new Environment([ + 'allowed' => $globalUrl, + 'cli' => $props['cli'] ?? null, + ], $props['server'] ?? null); + + // merge into one clean options array + $options = $this->environment()->options($this->root('config')); + $this->options = array_replace_recursive($this->options, $options); + + // reload the environment if the environment config has overridden + // the `url` option; this ensures that the base URL is correct + $envUrl = $this->options['url'] ?? null; + if ($envUrl !== $globalUrl) { + $this->environment->detect([ + 'allowed' => $envUrl, + 'cli' => $props['cli'] ?? null + ], $props['server'] ?? null); + } + + return $this->options; + } + + /** + * Inject options from Kirby instance props + * + * @param array $options + * @return array + */ + protected function optionsFromProps(array $options = []): array + { + return $this->options = array_replace_recursive( + $this->options, + $options + ); + } + + /** + * Merge last-minute options from ready callback + * + * @return array + */ + protected function optionsFromReadyCallback(): array + { + if (isset($this->options['ready']) === true && is_callable($this->options['ready']) === true) { + // fetch last-minute options from the callback + $options = (array)$this->options['ready']($this); + + // inject all last-minute options recursively + $this->options = array_replace_recursive($this->options, $options); + + // update the system with changed options + if ( + isset($options['debug']) === true || + isset($options['whoops']) === true || + isset($options['editor']) === true + ) { + $this->handleErrors(); + } + + if (isset($options['debug']) === true) { + $this->api = null; + } + + if (isset($options['home']) === true || isset($options['error']) === true) { + $this->site = null; + } + + // checks custom language definition for slugs + if ($slugsOption = $this->option('slugs')) { + // slugs option must be set to string or "slugs" => ["language" => "de"] as array + if (is_string($slugsOption) === true || isset($slugsOption['language']) === true) { + $this->i18n(); + } + } + } + + return $this->options; + } + + /** + * Returns any page from the content folder + * + * @param string|null $id + * @param \Kirby\Cms\Page|\Kirby\Cms\Site|null $parent + * @param bool $drafts + * @return \Kirby\Cms\Page|null + */ + public function page(?string $id = null, $parent = null, bool $drafts = true) + { + if ($id === null) { + return null; + } + + $parent = $parent ?? $this->site(); + + if ($page = $parent->find($id)) { + /** + * We passed a single $id, we can be sure that the result is + * @var \Kirby\Cms\Page $page + */ + return $page; + } + + if ($drafts === true && $draft = $parent->draft($id)) { + return $draft; + } + + return null; + } + + /** + * Returns the request path + * + * @return string + */ + public function path(): string + { + if (is_string($this->path) === true) { + return $this->path; + } + + $current = $this->request()->path()->toString(); + $index = $this->environment()->baseUri()->path()->toString(); + $path = Str::afterStart($current, $index); + + return $this->setPath($path)->path; + } + + /** + * Returns the Response object for the + * current request + * + * @param string|null $path + * @param string|null $method + * @return \Kirby\Http\Response + */ + public function render(string $path = null, string $method = null) + { + return $this->io($this->call($path, $method)); + } + + /** + * Returns the Request singleton + * + * @return \Kirby\Http\Request + */ + public function request() + { + if ($this->request !== null) { + return $this->request; + } + + $env = $this->environment(); + + return $this->request = new Request([ + 'cli' => $env->cli(), + 'url' => $env->requestUri() + ]); + } + + /** + * Path resolver for the router + * + * @internal + * @param string|null $path + * @param string|null $language + * @return mixed + * @throws \Kirby\Exception\NotFoundException if the home page cannot be found + */ + public function resolve(string $path = null, string $language = null) + { + // set the current translation + $this->setCurrentTranslation($language); + + // set the current locale + $this->setCurrentLanguage($language); + + // the site is needed a couple times here + $site = $this->site(); + + // use the home page + if ($path === null) { + if ($homePage = $site->homePage()) { + return $homePage; + } + + throw new NotFoundException('The home page does not exist'); + } + + // search for the page by path + $page = $site->find($path); + + // search for a draft if the page cannot be found + if (!$page && $draft = $site->draft($path)) { + if ($this->user() || $draft->isVerified($this->request()->get('token'))) { + $page = $draft; + } + } + + // try to resolve content representations if the path has an extension + $extension = F::extension($path); + + // no content representation? then return the page + if (empty($extension) === true) { + return $page; + } + + // only try to return a representation + // when the page has been found + if ($page) { + try { + $response = $this->response(); + $output = $page->render([], $extension); + + // 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($output); + } catch (NotFoundException $e) { + return null; + } + } + + $id = dirname($path); + $filename = basename($path); + + // try to resolve image urls for pages and drafts + if ($page = $site->findPageOrDraft($id)) { + return $page->file($filename); + } + + // try to resolve site files at least + return $site->file($filename); + } + + /** + * Response configuration + * + * @return \Kirby\Cms\Responder + */ + public function response() + { + return $this->response = $this->response ?? new Responder(); + } + + /** + * Returns all user roles + * + * @return \Kirby\Cms\Roles + */ + public function roles() + { + return $this->roles = $this->roles ?? Roles::load($this->root('roles')); + } + + /** + * Returns a system root + * + * @param string $type + * @return string|null + */ + public function root(string $type = 'index'): ?string + { + return $this->roots->__get($type); + } + + /** + * Returns the directory structure + * + * @return \Kirby\Cms\Ingredients + */ + public function roots() + { + return $this->roots; + } + + /** + * Returns the currently active route + * + * @return \Kirby\Http\Route|null + */ + public function route() + { + return $this->router()->route(); + } + + /** + * Returns the Router singleton + * + * @internal + * @return \Kirby\Http\Router + */ + public function router() + { + $routes = $this->routes(); + + if ($this->multilang() === true) { + foreach ($routes as $index => $route) { + if (empty($route['language']) === false) { + unset($routes[$index]); + } + } + } + + $hooks = [ + 'beforeEach' => function ($route, $path, $method) { + $this->trigger('route:before', compact('route', 'path', 'method')); + }, + 'afterEach' => function ($route, $path, $method, $result, $final) { + return $this->apply('route:after', compact('route', 'path', 'method', 'result', 'final'), 'result'); + } + ]; + + return $this->router ??= new Router($routes, $hooks); + } + + /** + * Returns all defined routes + * + * @internal + * @return array + */ + public function routes(): array + { + if (is_array($this->routes) === true) { + return $this->routes; + } + + $registry = $this->extensions('routes'); + $system = $this->core->routes(); + $routes = array_merge($system['before'], $registry, $system['after']); + + return $this->routes = $routes; + } + + /** + * Returns the current session object + * + * @param array $options Additional options, see the session component + * @return \Kirby\Session\Session + */ + public function session(array $options = []) + { + $session = $this->sessionHandler()->get($options); + + // disable caching for sessions that use the `Authorization` header; + // cookie sessions are already covered by the `Cookie` class + if ($session->mode() === 'manual') { + $this->response()->cache(false); + $this->response()->header('Cache-Control', 'no-store, private', true); + } + + return $session; + } + + /** + * Returns the session handler + * + * @return \Kirby\Session\AutoSession + */ + public function sessionHandler() + { + $this->sessionHandler = $this->sessionHandler ?? new AutoSession($this->root('sessions'), $this->option('session', [])); + return $this->sessionHandler; + } + + /** + * Create your own set of languages + * + * @param array|null $languages + * @return $this + */ + protected function setLanguages(array $languages = null) + { + if ($languages !== null) { + $objects = []; + + foreach ($languages as $props) { + $objects[] = new Language($props); + } + + $this->languages = new Languages($objects); + } + + return $this; + } + + /** + * Sets the request path that is + * used for the router + * + * @param string|null $path + * @return $this + */ + protected function setPath(string $path = null) + { + $this->path = $path !== null ? trim($path, '/') : null; + return $this; + } + + /** + * Sets the request + * + * @param array|null $request + * @return $this + */ + protected function setRequest(array $request = null) + { + if ($request !== null) { + $this->request = new Request($request); + } + + return $this; + } + + /** + * Create your own set of roles + * + * @param array|null $roles + * @return $this + */ + protected function setRoles(array $roles = null) + { + if ($roles !== null) { + $this->roles = Roles::factory($roles, [ + 'kirby' => $this + ]); + } + + return $this; + } + + /** + * Sets a custom Site object + * + * @param \Kirby\Cms\Site|array|null $site + * @return $this + */ + protected function setSite($site = null) + { + if (is_array($site) === true) { + $site = new Site($site + [ + 'kirby' => $this + ]); + } + + $this->site = $site; + return $this; + } + + /** + * Returns the Environment object + * @deprecated 3.7.0 Use `$kirby->environment()` instead + * + * @return \Kirby\Http\Environment + * @todo Start throwing deprecation warnings in 3.8.0 + * @todo Remove in 3.9.0 + * @codeCoverageIgnore + */ + public function server() + { + return $this->environment(); + } + + /** + * Initializes and returns the Site object + * + * @return \Kirby\Cms\Site + */ + public function site() + { + return $this->site = $this->site ?? new Site([ + 'errorPageId' => $this->options['error'] ?? 'error', + 'homePageId' => $this->options['home'] ?? 'home', + 'kirby' => $this, + 'url' => $this->url('index'), + ]); + } + + /** + * Applies the smartypants rule on the text + * + * @internal + * @param string|null $text + * @return string + */ + public function smartypants(string $text = null): string + { + $options = $this->option('smartypants', []); + + if ($options === false) { + return $text; + } elseif (is_array($options) === false) { + $options = []; + } + + if ($this->multilang() === true) { + $languageSmartypants = $this->language()->smartypants() ?? []; + + if (empty($languageSmartypants) === false) { + $options = array_merge($options, $languageSmartypants); + } + } + + return ($this->component('smartypants'))($this, $text, $options); + } + + /** + * Uses the snippet component to create + * and return a template snippet + * + * @internal + * @param mixed $name + * @param array|object $data Variables or an object that becomes `$item` + * @param bool $return On `false`, directly echo the snippet + * @return string|null + */ + public function snippet($name, $data = [], bool $return = true): ?string + { + if (is_object($data) === true) { + $data = ['item' => $data]; + } + + $snippet = ($this->component('snippet'))($this, $name, array_merge($this->data, $data)); + + if ($return === true) { + return $snippet; + } + + echo $snippet; + return null; + } + + /** + * System check class + * + * @return \Kirby\Cms\System + */ + public function system() + { + return $this->system = $this->system ?? new System($this); + } + + /** + * Uses the template component to initialize + * and return the Template object + * + * @internal + * @return \Kirby\Cms\Template + * @param string $name + * @param string $type + * @param string $defaultType + */ + public function template(string $name, string $type = 'html', string $defaultType = 'html') + { + return ($this->component('template'))($this, $name, $type, $defaultType); + } + + /** + * Thumbnail creator + * + * @param string $src + * @param string $dst + * @param array $options + * @return string + */ + public function thumb(string $src, string $dst, array $options = []): string + { + return ($this->component('thumb'))($this, $src, $dst, $options); + } + + /** + * Trigger a hook by name + * + * @internal + * @param string $name Full event name + * @param array $args Associative array of named event arguments + * @param \Kirby\Cms\Event|null $originalEvent Event object (internal use) + * @return void + */ + public function trigger(string $name, array $args = [], ?Event $originalEvent = null) + { + $event = $originalEvent ?? new Event($name, $args); + + if ($functions = $this->extension('hooks', $name)) { + static $level = 0; + static $triggered = []; + $level++; + + foreach ($functions as $index => $function) { + if (in_array($function, $triggered[$name] ?? []) === true) { + continue; + } + + // mark the hook as triggered, to avoid endless loops + $triggered[$name][] = $function; + + // bind the App object to the hook + $event->call($this, $function); + } + + $level--; + + if ($level === 0) { + $triggered = []; + } + } + + // trigger wildcard hooks if available + $nameWildcards = $event->nameWildcards(); + if ($originalEvent === null && count($nameWildcards) > 0) { + foreach ($nameWildcards as $nameWildcard) { + $this->trigger($nameWildcard, $args, $event); + } + } + } + + /** + * Returns a system url + * + * @param string $type + * @param bool $object If set to `true`, the URL is converted to an object + * @return string|\Kirby\Http\Uri|null + */ + public function url(string $type = 'index', bool $object = false) + { + $url = $this->urls->__get($type); + + if ($object === true) { + if (Url::isAbsolute($url)) { + return Url::toObject($url); + } + + // index URL was configured without host, use the current host + return Uri::current([ + 'path' => $url, + 'query' => null + ]); + } + + return $url; + } + + /** + * Returns the url structure + * + * @return \Kirby\Cms\Ingredients + */ + public function urls() + { + return $this->urls; + } + + /** + * Returns the current version number from + * the composer.json (Keep that up to date! :)) + * + * @return string|null + * @throws \Kirby\Exception\LogicException if the Kirby version cannot be detected + */ + public static function version(): ?string + { + try { + return static::$version = static::$version ?? Data::read(dirname(__DIR__, 2) . '/composer.json')['version'] ?? null; + } catch (Throwable $e) { + throw new LogicException('The Kirby version cannot be detected. The composer.json is probably missing or not readable.'); + } + } + + /** + * Creates a hash of the version number + * + * @return string + */ + public static function versionHash(): string + { + return md5(static::version()); + } + + /** + * Returns the visitor object + * + * @return \Kirby\Http\Visitor + */ + public function visitor() + { + return $this->visitor = $this->visitor ?? new Visitor(); + } } diff --git a/kirby/src/Cms/AppCaches.php b/kirby/src/Cms/AppCaches.php index c9dff45..2bea1ed 100755 --- a/kirby/src/Cms/AppCaches.php +++ b/kirby/src/Cms/AppCaches.php @@ -16,122 +16,122 @@ use Kirby\Exception\InvalidArgumentException; */ trait AppCaches { - protected $caches = []; + protected $caches = []; - /** - * Returns a cache instance by key - * - * @param string $key - * @return \Kirby\Cache\Cache - */ - public function cache(string $key) - { - if (isset($this->caches[$key]) === true) { - return $this->caches[$key]; - } + /** + * Returns a cache instance by key + * + * @param string $key + * @return \Kirby\Cache\Cache + */ + public function cache(string $key) + { + if (isset($this->caches[$key]) === true) { + return $this->caches[$key]; + } - // get the options for this cache type - $options = $this->cacheOptions($key); + // get the options for this cache type + $options = $this->cacheOptions($key); - if ($options['active'] === false) { - // use a dummy cache that does nothing - return $this->caches[$key] = new NullCache(); - } + if ($options['active'] === false) { + // use a dummy cache that does nothing + return $this->caches[$key] = new NullCache(); + } - $type = strtolower($options['type']); - $types = $this->extensions['cacheTypes'] ?? []; + $type = strtolower($options['type']); + $types = $this->extensions['cacheTypes'] ?? []; - if (array_key_exists($type, $types) === false) { - throw new InvalidArgumentException([ - 'key' => 'app.invalid.cacheType', - 'data' => ['type' => $type] - ]); - } + if (array_key_exists($type, $types) === false) { + throw new InvalidArgumentException([ + 'key' => 'app.invalid.cacheType', + 'data' => ['type' => $type] + ]); + } - $className = $types[$type]; + $className = $types[$type]; - // initialize the cache class - $cache = new $className($options); + // initialize the cache class + $cache = new $className($options); - // check if it is a usable cache object - if (is_a($cache, 'Kirby\Cache\Cache') !== true) { - throw new InvalidArgumentException([ - 'key' => 'app.invalid.cacheType', - 'data' => ['type' => $type] - ]); - } + // check if it is a usable cache object + if (is_a($cache, 'Kirby\Cache\Cache') !== true) { + throw new InvalidArgumentException([ + 'key' => 'app.invalid.cacheType', + 'data' => ['type' => $type] + ]); + } - return $this->caches[$key] = $cache; - } + return $this->caches[$key] = $cache; + } - /** - * Returns the cache options by key - * - * @param string $key - * @return array - */ - protected function cacheOptions(string $key): array - { - $options = $this->option($this->cacheOptionsKey($key), false); + /** + * Returns the cache options by key + * + * @param string $key + * @return array + */ + protected function cacheOptions(string $key): array + { + $options = $this->option($this->cacheOptionsKey($key), false); - if ($options === false) { - return [ - 'active' => false - ]; - } + if ($options === false) { + return [ + 'active' => false + ]; + } - $prefix = str_replace(['/', ':'], '_', $this->system()->indexUrl()) . - '/' . - str_replace('.', '/', $key); + $prefix = str_replace(['/', ':'], '_', $this->system()->indexUrl()) . + '/' . + str_replace('.', '/', $key); - $defaults = [ - 'active' => true, - 'type' => 'file', - 'extension' => 'cache', - 'root' => $this->root('cache'), - 'prefix' => $prefix - ]; + $defaults = [ + 'active' => true, + 'type' => 'file', + 'extension' => 'cache', + 'root' => $this->root('cache'), + 'prefix' => $prefix + ]; - if ($options === true) { - return $defaults; - } else { - return array_merge($defaults, $options); - } - } + if ($options === true) { + return $defaults; + } else { + return array_merge($defaults, $options); + } + } - /** - * Takes care of converting prefixed plugin cache setups - * to the right cache key, while leaving regular cache - * setups untouched. - * - * @param string $key - * @return string - */ - protected function cacheOptionsKey(string $key): string - { - $prefixedKey = 'cache.' . $key; + /** + * Takes care of converting prefixed plugin cache setups + * to the right cache key, while leaving regular cache + * setups untouched. + * + * @param string $key + * @return string + */ + protected function cacheOptionsKey(string $key): string + { + $prefixedKey = 'cache.' . $key; - if (isset($this->options[$prefixedKey])) { - return $prefixedKey; - } + if (isset($this->options[$prefixedKey])) { + return $prefixedKey; + } - // plain keys without dots don't need further investigation - // since they can never be from a plugin. - if (strpos($key, '.') === false) { - return $prefixedKey; - } + // plain keys without dots don't need further investigation + // since they can never be from a plugin. + if (strpos($key, '.') === false) { + return $prefixedKey; + } - // try to extract the plugin name - $parts = explode('.', $key); - $pluginName = implode('/', array_slice($parts, 0, 2)); - $pluginPrefix = implode('.', array_slice($parts, 0, 2)); - $cacheName = implode('.', array_slice($parts, 2)); + // try to extract the plugin name + $parts = explode('.', $key); + $pluginName = implode('/', array_slice($parts, 0, 2)); + $pluginPrefix = implode('.', array_slice($parts, 0, 2)); + $cacheName = implode('.', array_slice($parts, 2)); - // check if such a plugin exists - if ($this->plugin($pluginName)) { - return empty($cacheName) === true ? $pluginPrefix . '.cache' : $pluginPrefix . '.cache.' . $cacheName; - } + // check if such a plugin exists + if ($this->plugin($pluginName)) { + return empty($cacheName) === true ? $pluginPrefix . '.cache' : $pluginPrefix . '.cache.' . $cacheName; + } - return $prefixedKey; - } + return $prefixedKey; + } } diff --git a/kirby/src/Cms/AppErrors.php b/kirby/src/Cms/AppErrors.php index 279d2d4..a1013a5 100755 --- a/kirby/src/Cms/AppErrors.php +++ b/kirby/src/Cms/AppErrors.php @@ -22,184 +22,184 @@ use Whoops\Run as Whoops; */ trait AppErrors { - /** - * Whoops instance cache - * - * @var \Whoops\Run - */ - protected $whoops; + /** + * Whoops instance cache + * + * @var \Whoops\Run + */ + protected $whoops; - /** - * Registers the PHP error handler for CLI usage - * - * @return void - */ - protected function handleCliErrors(): void - { - $this->setWhoopsHandler(new PlainTextHandler()); - } + /** + * Registers the PHP error handler for CLI usage + * + * @return void + */ + protected function handleCliErrors(): void + { + $this->setWhoopsHandler(new PlainTextHandler()); + } - /** - * Registers the PHP error handler - * based on the environment - * - * @return void - */ - protected function handleErrors(): void - { - if ($this->environment()->cli() === true) { - $this->handleCliErrors(); - return; - } + /** + * Registers the PHP error handler + * based on the environment + * + * @return void + */ + protected function handleErrors(): void + { + if ($this->environment()->cli() === true) { + $this->handleCliErrors(); + return; + } - if ($this->visitor()->prefersJson() === true) { - $this->handleJsonErrors(); - return; - } + if ($this->visitor()->prefersJson() === true) { + $this->handleJsonErrors(); + return; + } - $this->handleHtmlErrors(); - } + $this->handleHtmlErrors(); + } - /** - * Registers the PHP error handler for HTML output - * - * @return void - */ - protected function handleHtmlErrors(): void - { - $handler = null; + /** + * Registers the PHP error handler for HTML output + * + * @return void + */ + protected function handleHtmlErrors(): void + { + $handler = null; - if ($this->option('debug') === true) { - if ($this->option('whoops', true) === true) { - $handler = new PrettyPageHandler(); - $handler->setPageTitle('Kirby CMS Debugger'); - $handler->setResourcesPath(dirname(__DIR__, 2) . '/assets'); - $handler->addCustomCss('whoops.css'); + if ($this->option('debug') === true) { + if ($this->option('whoops', true) === true) { + $handler = new PrettyPageHandler(); + $handler->setPageTitle('Kirby CMS Debugger'); + $handler->setResourcesPath(dirname(__DIR__, 2) . '/assets'); + $handler->addCustomCss('whoops.css'); - if ($editor = $this->option('editor')) { - $handler->setEditor($editor); - } - } - } else { - $handler = new CallbackHandler(function ($exception, $inspector, $run) { - $fatal = $this->option('fatal'); + if ($editor = $this->option('editor')) { + $handler->setEditor($editor); + } + } + } else { + $handler = new CallbackHandler(function ($exception, $inspector, $run) { + $fatal = $this->option('fatal'); - if (is_a($fatal, 'Closure') === true) { - echo $fatal($this, $exception); - } else { - include $this->root('kirby') . '/views/fatal.php'; - } + if (is_a($fatal, 'Closure') === true) { + echo $fatal($this, $exception); + } else { + include $this->root('kirby') . '/views/fatal.php'; + } - return Handler::QUIT; - }); - } + return Handler::QUIT; + }); + } - if ($handler !== null) { - $this->setWhoopsHandler($handler); - } else { - $this->unsetWhoopsHandler(); - } - } + if ($handler !== null) { + $this->setWhoopsHandler($handler); + } else { + $this->unsetWhoopsHandler(); + } + } - /** - * Registers the PHP error handler for JSON output - * - * @return void - */ - protected function handleJsonErrors(): void - { - $handler = new CallbackHandler(function ($exception, $inspector, $run) { - if (is_a($exception, 'Kirby\Exception\Exception') === true) { - $httpCode = $exception->getHttpCode(); - $code = $exception->getCode(); - $details = $exception->getDetails(); - } elseif (is_a($exception, '\Throwable') === true) { - $httpCode = 500; - $code = $exception->getCode(); - $details = null; - } else { - $httpCode = 500; - $code = 500; - $details = null; - } + /** + * Registers the PHP error handler for JSON output + * + * @return void + */ + protected function handleJsonErrors(): void + { + $handler = new CallbackHandler(function ($exception, $inspector, $run) { + if (is_a($exception, 'Kirby\Exception\Exception') === true) { + $httpCode = $exception->getHttpCode(); + $code = $exception->getCode(); + $details = $exception->getDetails(); + } 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) { - echo Response::json([ - 'status' => 'error', - 'exception' => get_class($exception), - 'code' => $code, - 'message' => $exception->getMessage(), - 'details' => $details, - 'file' => F::relativepath($exception->getFile(), $this->environment()->get('DOCUMENT_ROOT', '')), - 'line' => $exception->getLine(), - ], $httpCode); - } else { - echo Response::json([ - 'status' => 'error', - 'code' => $code, - 'details' => $details, - 'message' => I18n::translate('error.unexpected'), - ], $httpCode); - } + if ($this->option('debug') === true) { + echo Response::json([ + 'status' => 'error', + 'exception' => get_class($exception), + 'code' => $code, + 'message' => $exception->getMessage(), + 'details' => $details, + 'file' => F::relativepath($exception->getFile(), $this->environment()->get('DOCUMENT_ROOT', '')), + 'line' => $exception->getLine(), + ], $httpCode); + } else { + echo Response::json([ + 'status' => 'error', + 'code' => $code, + 'details' => $details, + 'message' => I18n::translate('error.unexpected'), + ], $httpCode); + } - return Handler::QUIT; - }); + return Handler::QUIT; + }); - $this->setWhoopsHandler($handler); - $this->whoops()->sendHttpCode(false); - } + $this->setWhoopsHandler($handler); + $this->whoops()->sendHttpCode(false); + } - /** - * Enables Whoops with the specified handler - * - * @param Callable|\Whoops\Handler\HandlerInterface $handler - * @return void - */ - protected function setWhoopsHandler($handler): void - { - $whoops = $this->whoops(); - $whoops->clearHandlers(); - $whoops->pushHandler($handler); - $whoops->pushHandler($this->getExceptionHookWhoopsHandler()); - $whoops->register(); // will only do something if not already registered - } + /** + * Enables Whoops with the specified handler + * + * @param Callable|\Whoops\Handler\HandlerInterface $handler + * @return void + */ + protected function setWhoopsHandler($handler): void + { + $whoops = $this->whoops(); + $whoops->clearHandlers(); + $whoops->pushHandler($handler); + $whoops->pushHandler($this->getExceptionHookWhoopsHandler()); + $whoops->register(); // will only do something if not already registered + } - /** - * Initializes a callback handler for triggering the `system.exception` hook - * - * @return \Whoops\Handler\CallbackHandler - */ - protected function getExceptionHookWhoopsHandler(): CallbackHandler - { - return new CallbackHandler(function ($exception, $inspector, $run) { - $this->trigger('system.exception', compact('exception')); - return Handler::DONE; - }); - } + /** + * Initializes a callback handler for triggering the `system.exception` hook + * + * @return \Whoops\Handler\CallbackHandler + */ + protected function getExceptionHookWhoopsHandler(): CallbackHandler + { + return new CallbackHandler(function ($exception, $inspector, $run) { + $this->trigger('system.exception', compact('exception')); + return Handler::DONE; + }); + } - /** - * Clears the Whoops handlers and disables Whoops - * - * @return void - */ - protected function unsetWhoopsHandler(): void - { - $whoops = $this->whoops(); - $whoops->clearHandlers(); - $whoops->unregister(); // will only do something if currently registered - } + /** + * Clears the Whoops handlers and disables Whoops + * + * @return void + */ + protected function unsetWhoopsHandler(): void + { + $whoops = $this->whoops(); + $whoops->clearHandlers(); + $whoops->unregister(); // will only do something if currently registered + } - /** - * Returns the Whoops error handler instance - * - * @return \Whoops\Run - */ - protected function whoops() - { - if ($this->whoops !== null) { - return $this->whoops; - } + /** + * Returns the Whoops error handler instance + * + * @return \Whoops\Run + */ + protected function whoops() + { + if ($this->whoops !== null) { + return $this->whoops; + } - return $this->whoops = new Whoops(); - } + return $this->whoops = new Whoops(); + } } diff --git a/kirby/src/Cms/AppPlugins.php b/kirby/src/Cms/AppPlugins.php index 26d0f4c..161fb2b 100755 --- a/kirby/src/Cms/AppPlugins.php +++ b/kirby/src/Cms/AppPlugins.php @@ -26,877 +26,890 @@ use Kirby\Toolkit\V; */ trait AppPlugins { - /** - * A list of all registered plugins - * - * @var array - */ - protected static $plugins = []; - - /** - * The extension registry - * - * @var array - */ - protected $extensions = [ - // load options first to make them available for the rest - 'options' => [], - - // other plugin types - 'api' => [], - 'areas' => [], - 'authChallenges' => [], - 'blockMethods' => [], - 'blockModels' => [], - 'blocksMethods' => [], - 'blueprints' => [], - 'cacheTypes' => [], - 'collections' => [], - 'components' => [], - 'controllers' => [], - 'collectionFilters' => [], - 'collectionMethods' => [], - 'fieldMethods' => [], - 'fileMethods' => [], - 'fileTypes' => [], - 'filesMethods' => [], - 'fields' => [], - 'hooks' => [], - 'layoutMethods' => [], - 'layoutColumnMethods' => [], - 'layoutsMethods' => [], - 'pages' => [], - 'pageMethods' => [], - 'pagesMethods' => [], - 'pageModels' => [], - 'permissions' => [], - 'routes' => [], - 'sections' => [], - 'siteMethods' => [], - 'snippets' => [], - 'tags' => [], - 'templates' => [], - 'thirdParty' => [], - 'translations' => [], - 'userMethods' => [], - 'userModels' => [], - 'usersMethods' => [], - 'validators' => [], - ]; - - /** - * Flag when plugins have been loaded - * to not load them again - * - * @var bool - */ - protected $pluginsAreLoaded = false; - - /** - * Register all given extensions - * - * @internal - * @param array $extensions - * @param \Kirby\Cms\Plugin $plugin|null The plugin which defined those extensions - * @return array - */ - public function extend(array $extensions, Plugin $plugin = null): array - { - foreach ($this->extensions as $type => $registered) { - if (isset($extensions[$type]) === true) { - $this->{'extend' . $type}($extensions[$type], $plugin); - } - } - - return $this->extensions; - } - - /** - * Registers API extensions - * - * @param array|bool $api - * @return array - */ - protected function extendApi($api): array - { - if (is_array($api) === true) { - if (is_a($api['routes'] ?? [], 'Closure') === true) { - $api['routes'] = $api['routes']($this); - } - - return $this->extensions['api'] = A::merge($this->extensions['api'], $api, A::MERGE_APPEND); - } else { - return $this->extensions['api']; - } - } - - /** - * Registers additional custom Panel areas - * - * @param array $areas - * @return array - */ - protected function extendAreas(array $areas): array - { - foreach ($areas as $id => $area) { - if (isset($this->extensions['areas'][$id]) === false) { - $this->extensions['areas'][$id] = []; - } - - $this->extensions['areas'][$id][] = $area; - } - - return $this->extensions['areas']; - } - - /** - * Registers additional authentication challenges - * - * @param array $challenges - * @return array - */ - protected function extendAuthChallenges(array $challenges): array - { - return $this->extensions['authChallenges'] = Auth::$challenges = array_merge(Auth::$challenges, $challenges); - } - - /** - * Registers additional block methods - * - * @param array $methods - * @return array - */ - protected function extendBlockMethods(array $methods): array - { - return $this->extensions['blockMethods'] = Block::$methods = array_merge(Block::$methods, $methods); - } - - /** - * Registers additional block models - * - * @param array $models - * @return array - */ - protected function extendBlockModels(array $models): array - { - return $this->extensions['blockModels'] = Block::$models = array_merge(Block::$models, $models); - } - - /** - * Registers additional blocks methods - * - * @param array $methods - * @return array - */ - protected function extendBlocksMethods(array $methods): array - { - return $this->extensions['blockMethods'] = Blocks::$methods = array_merge(Blocks::$methods, $methods); - } - - /** - * Registers additional blueprints - * - * @param array $blueprints - * @return array - */ - protected function extendBlueprints(array $blueprints): array - { - return $this->extensions['blueprints'] = array_merge($this->extensions['blueprints'], $blueprints); - } - - /** - * Registers additional cache types - * - * @param array $cacheTypes - * @return array - */ - protected function extendCacheTypes(array $cacheTypes): array - { - return $this->extensions['cacheTypes'] = array_merge($this->extensions['cacheTypes'], $cacheTypes); - } - - /** - * Registers additional collection filters - * - * @param array $filters - * @return array - */ - protected function extendCollectionFilters(array $filters): array - { - return $this->extensions['collectionFilters'] = ToolkitCollection::$filters = array_merge(ToolkitCollection::$filters, $filters); - } - - /** - * Registers additional collection methods - * - * @param array $methods - * @return array - */ - protected function extendCollectionMethods(array $methods): array - { - return $this->extensions['collectionMethods'] = Collection::$methods = array_merge(Collection::$methods, $methods); - } - - /** - * Registers additional collections - * - * @param array $collections - * @return array - */ - protected function extendCollections(array $collections): array - { - return $this->extensions['collections'] = array_merge($this->extensions['collections'], $collections); - } - - /** - * Registers core components - * - * @param array $components - * @return array - */ - protected function extendComponents(array $components): array - { - return $this->extensions['components'] = array_merge($this->extensions['components'], $components); - } - - /** - * Registers additional controllers - * - * @param array $controllers - * @return array - */ - protected function extendControllers(array $controllers): array - { - return $this->extensions['controllers'] = array_merge($this->extensions['controllers'], $controllers); - } - - /** - * Registers additional file methods - * - * @param array $methods - * @return array - */ - protected function extendFileMethods(array $methods): array - { - return $this->extensions['fileMethods'] = File::$methods = array_merge(File::$methods, $methods); - } - - /** - * Registers additional custom file types and mimes - * - * @param array $fileTypes - * @return array - */ - protected function extendFileTypes(array $fileTypes): array - { - // normalize array - foreach ($fileTypes as $ext => $file) { - $extension = $file['extension'] ?? $ext; - $type = $file['type'] ?? null; - $mime = $file['mime'] ?? null; - $resizable = $file['resizable'] ?? false; - $viewable = $file['viewable'] ?? false; - - if (is_string($type) === true) { - if (isset(F::$types[$type]) === false) { - F::$types[$type] = []; - } - - if (in_array($extension, F::$types[$type]) === false) { - F::$types[$type][] = $extension; - } - } - - if ($mime !== null) { - if (array_key_exists($extension, Mime::$types) === true) { - // if `Mime::$types[$extension]` is not already an array, make it one - // and append the new MIME type unless it's already in the list - Mime::$types[$extension] = array_unique(array_merge((array)Mime::$types[$extension], (array)$mime)); - } else { - Mime::$types[$extension] = $mime; - } - } - - if ($resizable === true && in_array($extension, Image::$resizableTypes) === false) { - Image::$resizableTypes[] = $extension; - } - - if ($viewable === true && in_array($extension, Image::$viewableTypes) === false) { - Image::$viewableTypes[] = $extension; - } - } - - return $this->extensions['fileTypes'] = [ - 'type' => F::$types, - 'mime' => Mime::$types, - 'resizable' => Image::$resizableTypes, - 'viewable' => Image::$viewableTypes - ]; - } - - /** - * Registers additional files methods - * - * @param array $methods - * @return array - */ - protected function extendFilesMethods(array $methods): array - { - return $this->extensions['filesMethods'] = Files::$methods = array_merge(Files::$methods, $methods); - } - - /** - * Registers additional field methods - * - * @param array $methods - * @return array - */ - protected function extendFieldMethods(array $methods): array - { - return $this->extensions['fieldMethods'] = Field::$methods = array_merge(Field::$methods, array_change_key_case($methods)); - } - - /** - * Registers Panel fields - * - * @param array $fields - * @return array - */ - protected function extendFields(array $fields): array - { - return $this->extensions['fields'] = FormField::$types = array_merge(FormField::$types, $fields); - } - - /** - * Registers hooks - * - * @param array $hooks - * @return array - */ - protected function extendHooks(array $hooks): array - { - foreach ($hooks as $name => $callbacks) { - if (isset($this->extensions['hooks'][$name]) === false) { - $this->extensions['hooks'][$name] = []; - } - - if (is_array($callbacks) === false) { - $callbacks = [$callbacks]; - } - - foreach ($callbacks as $callback) { - $this->extensions['hooks'][$name][] = $callback; - } - } - - return $this->extensions['hooks']; - } - - /** - * Registers markdown component - * - * @param Closure $markdown - * @return Closure - */ - protected function extendMarkdown(Closure $markdown) - { - return $this->extensions['markdown'] = $markdown; - } - - /** - * Registers additional layout methods - * - * @param array $methods - * @return array - */ - protected function extendLayoutMethods(array $methods): array - { - return $this->extensions['layoutMethods'] = Layout::$methods = array_merge(Layout::$methods, $methods); - } - - /** - * Registers additional layout column methods - * - * @param array $methods - * @return array - */ - protected function extendLayoutColumnMethods(array $methods): array - { - return $this->extensions['layoutColumnMethods'] = LayoutColumn::$methods = array_merge(LayoutColumn::$methods, $methods); - } - - /** - * Registers additional layouts methods - * - * @param array $methods - * @return array - */ - protected function extendLayoutsMethods(array $methods): array - { - return $this->extensions['layoutsMethods'] = Layouts::$methods = array_merge(Layouts::$methods, $methods); - } - - /** - * Registers additional options - * - * @param array $options - * @param \Kirby\Cms\Plugin|null $plugin - * @return array - */ - protected function extendOptions(array $options, Plugin $plugin = null): array - { - if ($plugin !== null) { - $options = [$plugin->prefix() => $options]; - } - - return $this->extensions['options'] = $this->options = A::merge($options, $this->options, A::MERGE_REPLACE); - } - - /** - * Registers additional page methods - * - * @param array $methods - * @return array - */ - protected function extendPageMethods(array $methods): array - { - return $this->extensions['pageMethods'] = Page::$methods = array_merge(Page::$methods, $methods); - } - - /** - * Registers additional pages methods - * - * @param array $methods - * @return array - */ - protected function extendPagesMethods(array $methods): array - { - return $this->extensions['pagesMethods'] = Pages::$methods = array_merge(Pages::$methods, $methods); - } - - /** - * Registers additional page models - * - * @param array $models - * @return array - */ - protected function extendPageModels(array $models): array - { - return $this->extensions['pageModels'] = Page::$models = array_merge(Page::$models, $models); - } - - /** - * Registers pages - * - * @param array $pages - * @return array - */ - protected function extendPages(array $pages): array - { - return $this->extensions['pages'] = array_merge($this->extensions['pages'], $pages); - } - - /** - * Registers additional permissions - * - * @param array $permissions - * @param \Kirby\Cms\Plugin|null $plugin - * @return array - */ - protected function extendPermissions(array $permissions, Plugin $plugin = null): array - { - if ($plugin !== null) { - $permissions = [$plugin->prefix() => $permissions]; - } - - return $this->extensions['permissions'] = Permissions::$extendedActions = array_merge(Permissions::$extendedActions, $permissions); - } - - /** - * Registers additional routes - * - * @param array|\Closure $routes - * @return array - */ - protected function extendRoutes($routes): array - { - if (is_a($routes, 'Closure') === true) { - $routes = $routes($this); - } - - return $this->extensions['routes'] = array_merge($this->extensions['routes'], $routes); - } - - /** - * Registers Panel sections - * - * @param array $sections - * @return array - */ - protected function extendSections(array $sections): array - { - return $this->extensions['sections'] = Section::$types = array_merge(Section::$types, $sections); - } - - /** - * Registers additional site methods - * - * @param array $methods - * @return array - */ - protected function extendSiteMethods(array $methods): array - { - return $this->extensions['siteMethods'] = Site::$methods = array_merge(Site::$methods, $methods); - } - - /** - * Registers SmartyPants component - * - * @param \Closure $smartypants - * @return \Closure - */ - protected function extendSmartypants(Closure $smartypants) - { - return $this->extensions['smartypants'] = $smartypants; - } - - /** - * Registers additional snippets - * - * @param array $snippets - * @return array - */ - protected function extendSnippets(array $snippets): array - { - return $this->extensions['snippets'] = array_merge($this->extensions['snippets'], $snippets); - } - - /** - * Registers additional KirbyTags - * - * @param array $tags - * @return array - */ - protected function extendTags(array $tags): array - { - return $this->extensions['tags'] = KirbyTag::$types = array_merge(KirbyTag::$types, array_change_key_case($tags)); - } - - /** - * Registers additional templates - * - * @param array $templates - * @return array - */ - protected function extendTemplates(array $templates): array - { - return $this->extensions['templates'] = array_merge($this->extensions['templates'], $templates); - } - - /** - * Registers translations - * - * @param array $translations - * @return array - */ - protected function extendTranslations(array $translations): array - { - return $this->extensions['translations'] = array_replace_recursive($this->extensions['translations'], $translations); - } - - /** - * Add third party extensions to the registry - * so they can be used as plugins for plugins - * for example. - * - * @param array $extensions - * @return array - */ - protected function extendThirdParty(array $extensions): array - { - return $this->extensions['thirdParty'] = array_replace_recursive($this->extensions['thirdParty'], $extensions); - } - - /** - * Registers additional user methods - * - * @param array $methods - * @return array - */ - protected function extendUserMethods(array $methods): array - { - return $this->extensions['userMethods'] = User::$methods = array_merge(User::$methods, $methods); - } - - /** - * Registers additional user models - * - * @param array $models - * @return array - */ - protected function extendUserModels(array $models): array - { - return $this->extensions['userModels'] = User::$models = array_merge(User::$models, $models); - } - - /** - * Registers additional users methods - * - * @param array $methods - * @return array - */ - protected function extendUsersMethods(array $methods): array - { - return $this->extensions['usersMethods'] = Users::$methods = array_merge(Users::$methods, $methods); - } - - /** - * Registers additional custom validators - * - * @param array $validators - * @return array - */ - protected function extendValidators(array $validators): array - { - return $this->extensions['validators'] = V::$validators = array_merge(V::$validators, $validators); - } - - /** - * Returns a given extension by type and name - * - * @internal - * @param string $type i.e. `'hooks'` - * @param string $name i.e. `'page.delete:before'` - * @param mixed $fallback - * @return mixed - */ - public function extension(string $type, string $name, $fallback = null) - { - return $this->extensions($type)[$name] ?? $fallback; - } - - /** - * Returns the extensions registry - * - * @internal - * @param string|null $type - * @return array - */ - public function extensions(string $type = null) - { - if ($type === null) { - return $this->extensions; - } - - return $this->extensions[$type] ?? []; - } - - /** - * Load extensions from site folders. - * This is only used for models for now, but - * could be extended later - */ - protected function extensionsFromFolders() - { - $models = []; - - foreach (glob($this->root('models') . '/*.php') as $model) { - $name = F::name($model); - $class = str_replace(['.', '-', '_'], '', $name) . 'Page'; - - // load the model class - F::loadOnce($model); - - if (class_exists($class) === true) { - $models[$name] = $class; - } - } - - $this->extendPageModels($models); - } - - /** - * Register extensions that could be located in - * the options array. I.e. hooks and routes can be - * setup from the config. - * - * @return void - */ - protected function extensionsFromOptions() - { - // register routes and hooks from options - $this->extend([ - 'api' => $this->options['api'] ?? [], - 'routes' => $this->options['routes'] ?? [], - 'hooks' => $this->options['hooks'] ?? [] - ]); - } - - /** - * Apply all plugin extensions - * - * @return void - */ - protected function extensionsFromPlugins() - { - // register all their extensions - foreach ($this->plugins() as $plugin) { - $extends = $plugin->extends(); - - if (empty($extends) === false) { - $this->extend($extends, $plugin); - } - } - } - - /** - * Apply all passed extensions - * - * @param array $props - * @return void - */ - protected function extensionsFromProps(array $props) - { - $this->extend($props); - } - - /** - * Apply all default extensions - * - * @return void - */ - protected function extensionsFromSystem() - { - // mixins - FormField::$mixins = $this->core->fieldMixins(); - Section::$mixins = $this->core->sectionMixins(); - - // aliases - KirbyTag::$aliases = $this->core->kirbyTagAliases(); - Field::$aliases = $this->core->fieldMethodAliases(); - - // blueprint presets - PageBlueprint::$presets = $this->core->blueprintPresets(); - - $this->extendAuthChallenges($this->core->authChallenges()); - $this->extendCacheTypes($this->core->cacheTypes()); - $this->extendComponents($this->core->components()); - $this->extendBlueprints($this->core->blueprints()); - $this->extendFields($this->core->fields()); - $this->extendFieldMethods($this->core->fieldMethods()); - $this->extendSections($this->core->sections()); - $this->extendSnippets($this->core->snippets()); - $this->extendTags($this->core->kirbyTags()); - $this->extendTemplates($this->core->templates()); - } - - /** - * Checks if a native component was extended - * @since 3.7.0 - * - * @param string $component - * @return bool - */ - public function isNativeComponent(string $component): bool - { - return $this->component($component) === $this->nativeComponent($component); - } - - /** - * Returns the native implementation - * of a core component - * - * @param string $component - * @return \Closure|false - */ - public function nativeComponent(string $component) - { - return $this->core->components()[$component] ?? false; - } - - /** - * Kirby plugin factory and getter - * - * @param string $name - * @param array|null $extends If null is passed it will be used as getter. Otherwise as factory. - * @return \Kirby\Cms\Plugin|null - * @throws \Kirby\Exception\DuplicateException - */ - public static function plugin(string $name, array $extends = null) - { - if ($extends === null) { - return static::$plugins[$name] ?? null; - } - - // get the correct root for the plugin - $extends['root'] = $extends['root'] ?? dirname(debug_backtrace()[0]['file']); - - $plugin = new Plugin($name, $extends); - $name = $plugin->name(); - - if (isset(static::$plugins[$name]) === true) { - throw new DuplicateException('The plugin "' . $name . '" has already been registered'); - } - - return static::$plugins[$name] = $plugin; - } - - /** - * Loads and returns all plugins in the site/plugins directory - * Loading only happens on the first call. - * - * @internal - * @param array|null $plugins Can be used to overwrite the plugins registry - * @return array - */ - public function plugins(array $plugins = null): array - { - // overwrite the existing plugins registry - if ($plugins !== null) { - $this->pluginsAreLoaded = true; - return static::$plugins = $plugins; - } - - // don't load plugins twice - if ($this->pluginsAreLoaded === true) { - return static::$plugins; - } - - // load all plugins from site/plugins - $this->pluginsLoader(); - - // mark plugins as loaded to stop doing it twice - $this->pluginsAreLoaded = true; - return static::$plugins; - } - - /** - * Loads all plugins from site/plugins - * - * @return array Array of loaded directories - */ - protected function pluginsLoader(): array - { - $root = $this->root('plugins'); - $loaded = []; - - foreach (Dir::read($root) as $dirname) { - if (in_array(substr($dirname, 0, 1), ['.', '_']) === true) { - continue; - } - - $dir = $root . '/' . $dirname; - $entry = $dir . '/index.php'; - - if (is_dir($dir) !== true || is_file($entry) !== true) { - continue; - } - - F::loadOnce($entry); - - $loaded[] = $dir; - } - - return $loaded; - } + /** + * A list of all registered plugins + * + * @var array + */ + protected static $plugins = []; + + /** + * The extension registry + * + * @var array + */ + protected $extensions = [ + // load options first to make them available for the rest + 'options' => [], + + // other plugin types + 'api' => [], + 'areas' => [], + 'authChallenges' => [], + 'blockMethods' => [], + 'blockModels' => [], + 'blocksMethods' => [], + 'blueprints' => [], + 'cacheTypes' => [], + 'collections' => [], + 'components' => [], + 'controllers' => [], + 'collectionFilters' => [], + 'collectionMethods' => [], + 'fieldMethods' => [], + 'fileMethods' => [], + 'fileTypes' => [], + 'filesMethods' => [], + 'fields' => [], + 'hooks' => [], + 'layoutMethods' => [], + 'layoutColumnMethods' => [], + 'layoutsMethods' => [], + 'pages' => [], + 'pageMethods' => [], + 'pagesMethods' => [], + 'pageModels' => [], + 'permissions' => [], + 'routes' => [], + 'sections' => [], + 'siteMethods' => [], + 'snippets' => [], + 'tags' => [], + 'templates' => [], + 'thirdParty' => [], + 'translations' => [], + 'userMethods' => [], + 'userModels' => [], + 'usersMethods' => [], + 'validators' => [], + ]; + + /** + * Flag when plugins have been loaded + * to not load them again + * + * @var bool + */ + protected $pluginsAreLoaded = false; + + /** + * Register all given extensions + * + * @internal + * @param array $extensions + * @param \Kirby\Cms\Plugin $plugin|null The plugin which defined those extensions + * @return array + */ + public function extend(array $extensions, Plugin $plugin = null): array + { + foreach ($this->extensions as $type => $registered) { + if (isset($extensions[$type]) === true) { + $this->{'extend' . $type}($extensions[$type], $plugin); + } + } + + return $this->extensions; + } + + /** + * Registers API extensions + * + * @param array|bool $api + * @return array + */ + protected function extendApi($api): array + { + if (is_array($api) === true) { + if (is_a($api['routes'] ?? [], 'Closure') === true) { + $api['routes'] = $api['routes']($this); + } + + return $this->extensions['api'] = A::merge($this->extensions['api'], $api, A::MERGE_APPEND); + } else { + return $this->extensions['api']; + } + } + + /** + * Registers additional custom Panel areas + * + * @param array $areas + * @return array + */ + protected function extendAreas(array $areas): array + { + foreach ($areas as $id => $area) { + if (isset($this->extensions['areas'][$id]) === false) { + $this->extensions['areas'][$id] = []; + } + + $this->extensions['areas'][$id][] = $area; + } + + return $this->extensions['areas']; + } + + /** + * Registers additional authentication challenges + * + * @param array $challenges + * @return array + */ + protected function extendAuthChallenges(array $challenges): array + { + return $this->extensions['authChallenges'] = Auth::$challenges = array_merge(Auth::$challenges, $challenges); + } + + /** + * Registers additional block methods + * + * @param array $methods + * @return array + */ + protected function extendBlockMethods(array $methods): array + { + return $this->extensions['blockMethods'] = Block::$methods = array_merge(Block::$methods, $methods); + } + + /** + * Registers additional block models + * + * @param array $models + * @return array + */ + protected function extendBlockModels(array $models): array + { + return $this->extensions['blockModels'] = Block::$models = array_merge(Block::$models, $models); + } + + /** + * Registers additional blocks methods + * + * @param array $methods + * @return array + */ + protected function extendBlocksMethods(array $methods): array + { + return $this->extensions['blockMethods'] = Blocks::$methods = array_merge(Blocks::$methods, $methods); + } + + /** + * Registers additional blueprints + * + * @param array $blueprints + * @return array + */ + protected function extendBlueprints(array $blueprints): array + { + return $this->extensions['blueprints'] = array_merge($this->extensions['blueprints'], $blueprints); + } + + /** + * Registers additional cache types + * + * @param array $cacheTypes + * @return array + */ + protected function extendCacheTypes(array $cacheTypes): array + { + return $this->extensions['cacheTypes'] = array_merge($this->extensions['cacheTypes'], $cacheTypes); + } + + /** + * Registers additional collection filters + * + * @param array $filters + * @return array + */ + protected function extendCollectionFilters(array $filters): array + { + return $this->extensions['collectionFilters'] = ToolkitCollection::$filters = array_merge(ToolkitCollection::$filters, $filters); + } + + /** + * Registers additional collection methods + * + * @param array $methods + * @return array + */ + protected function extendCollectionMethods(array $methods): array + { + return $this->extensions['collectionMethods'] = Collection::$methods = array_merge(Collection::$methods, $methods); + } + + /** + * Registers additional collections + * + * @param array $collections + * @return array + */ + protected function extendCollections(array $collections): array + { + return $this->extensions['collections'] = array_merge($this->extensions['collections'], $collections); + } + + /** + * Registers core components + * + * @param array $components + * @return array + */ + protected function extendComponents(array $components): array + { + return $this->extensions['components'] = array_merge($this->extensions['components'], $components); + } + + /** + * Registers additional controllers + * + * @param array $controllers + * @return array + */ + protected function extendControllers(array $controllers): array + { + return $this->extensions['controllers'] = array_merge($this->extensions['controllers'], $controllers); + } + + /** + * Registers additional file methods + * + * @param array $methods + * @return array + */ + protected function extendFileMethods(array $methods): array + { + return $this->extensions['fileMethods'] = File::$methods = array_merge(File::$methods, $methods); + } + + /** + * Registers additional custom file types and mimes + * + * @param array $fileTypes + * @return array + */ + protected function extendFileTypes(array $fileTypes): array + { + // normalize array + foreach ($fileTypes as $ext => $file) { + $extension = $file['extension'] ?? $ext; + $type = $file['type'] ?? null; + $mime = $file['mime'] ?? null; + $resizable = $file['resizable'] ?? false; + $viewable = $file['viewable'] ?? false; + + if (is_string($type) === true) { + if (isset(F::$types[$type]) === false) { + F::$types[$type] = []; + } + + if (in_array($extension, F::$types[$type]) === false) { + F::$types[$type][] = $extension; + } + } + + if ($mime !== null) { + if (array_key_exists($extension, Mime::$types) === true) { + // if `Mime::$types[$extension]` is not already an array, make it one + // and append the new MIME type unless it's already in the list + Mime::$types[$extension] = array_unique(array_merge((array)Mime::$types[$extension], (array)$mime)); + } else { + Mime::$types[$extension] = $mime; + } + } + + if ($resizable === true && in_array($extension, Image::$resizableTypes) === false) { + Image::$resizableTypes[] = $extension; + } + + if ($viewable === true && in_array($extension, Image::$viewableTypes) === false) { + Image::$viewableTypes[] = $extension; + } + } + + return $this->extensions['fileTypes'] = [ + 'type' => F::$types, + 'mime' => Mime::$types, + 'resizable' => Image::$resizableTypes, + 'viewable' => Image::$viewableTypes + ]; + } + + /** + * Registers additional files methods + * + * @param array $methods + * @return array + */ + protected function extendFilesMethods(array $methods): array + { + return $this->extensions['filesMethods'] = Files::$methods = array_merge(Files::$methods, $methods); + } + + /** + * Registers additional field methods + * + * @param array $methods + * @return array + */ + protected function extendFieldMethods(array $methods): array + { + return $this->extensions['fieldMethods'] = Field::$methods = array_merge(Field::$methods, array_change_key_case($methods)); + } + + /** + * Registers Panel fields + * + * @param array $fields + * @return array + */ + protected function extendFields(array $fields): array + { + return $this->extensions['fields'] = FormField::$types = array_merge(FormField::$types, $fields); + } + + /** + * Registers hooks + * + * @param array $hooks + * @return array + */ + protected function extendHooks(array $hooks): array + { + foreach ($hooks as $name => $callbacks) { + if (isset($this->extensions['hooks'][$name]) === false) { + $this->extensions['hooks'][$name] = []; + } + + if (is_array($callbacks) === false) { + $callbacks = [$callbacks]; + } + + foreach ($callbacks as $callback) { + $this->extensions['hooks'][$name][] = $callback; + } + } + + return $this->extensions['hooks']; + } + + /** + * Registers markdown component + * + * @param Closure $markdown + * @return Closure + */ + protected function extendMarkdown(Closure $markdown) + { + return $this->extensions['markdown'] = $markdown; + } + + /** + * Registers additional layout methods + * + * @param array $methods + * @return array + */ + protected function extendLayoutMethods(array $methods): array + { + return $this->extensions['layoutMethods'] = Layout::$methods = array_merge(Layout::$methods, $methods); + } + + /** + * Registers additional layout column methods + * + * @param array $methods + * @return array + */ + protected function extendLayoutColumnMethods(array $methods): array + { + return $this->extensions['layoutColumnMethods'] = LayoutColumn::$methods = array_merge(LayoutColumn::$methods, $methods); + } + + /** + * Registers additional layouts methods + * + * @param array $methods + * @return array + */ + protected function extendLayoutsMethods(array $methods): array + { + return $this->extensions['layoutsMethods'] = Layouts::$methods = array_merge(Layouts::$methods, $methods); + } + + /** + * Registers additional options + * + * @param array $options + * @param \Kirby\Cms\Plugin|null $plugin + * @return array + */ + protected function extendOptions(array $options, Plugin $plugin = null): array + { + if ($plugin !== null) { + $options = [$plugin->prefix() => $options]; + } + + return $this->extensions['options'] = $this->options = A::merge($options, $this->options, A::MERGE_REPLACE); + } + + /** + * Registers additional page methods + * + * @param array $methods + * @return array + */ + protected function extendPageMethods(array $methods): array + { + return $this->extensions['pageMethods'] = Page::$methods = array_merge(Page::$methods, $methods); + } + + /** + * Registers additional pages methods + * + * @param array $methods + * @return array + */ + protected function extendPagesMethods(array $methods): array + { + return $this->extensions['pagesMethods'] = Pages::$methods = array_merge(Pages::$methods, $methods); + } + + /** + * Registers additional page models + * + * @param array $models + * @return array + */ + protected function extendPageModels(array $models): array + { + return $this->extensions['pageModels'] = Page::$models = array_merge(Page::$models, $models); + } + + /** + * Registers pages + * + * @param array $pages + * @return array + */ + protected function extendPages(array $pages): array + { + return $this->extensions['pages'] = array_merge($this->extensions['pages'], $pages); + } + + /** + * Registers additional permissions + * + * @param array $permissions + * @param \Kirby\Cms\Plugin|null $plugin + * @return array + */ + protected function extendPermissions(array $permissions, Plugin $plugin = null): array + { + if ($plugin !== null) { + $permissions = [$plugin->prefix() => $permissions]; + } + + return $this->extensions['permissions'] = Permissions::$extendedActions = array_merge(Permissions::$extendedActions, $permissions); + } + + /** + * Registers additional routes + * + * @param array|\Closure $routes + * @return array + */ + protected function extendRoutes($routes): array + { + if (is_a($routes, 'Closure') === true) { + $routes = $routes($this); + } + + return $this->extensions['routes'] = array_merge($this->extensions['routes'], $routes); + } + + /** + * Registers Panel sections + * + * @param array $sections + * @return array + */ + protected function extendSections(array $sections): array + { + return $this->extensions['sections'] = Section::$types = array_merge(Section::$types, $sections); + } + + /** + * Registers additional site methods + * + * @param array $methods + * @return array + */ + protected function extendSiteMethods(array $methods): array + { + return $this->extensions['siteMethods'] = Site::$methods = array_merge(Site::$methods, $methods); + } + + /** + * Registers SmartyPants component + * + * @param \Closure $smartypants + * @return \Closure + */ + protected function extendSmartypants(Closure $smartypants) + { + return $this->extensions['smartypants'] = $smartypants; + } + + /** + * Registers additional snippets + * + * @param array $snippets + * @return array + */ + protected function extendSnippets(array $snippets): array + { + return $this->extensions['snippets'] = array_merge($this->extensions['snippets'], $snippets); + } + + /** + * Registers additional KirbyTags + * + * @param array $tags + * @return array + */ + protected function extendTags(array $tags): array + { + return $this->extensions['tags'] = KirbyTag::$types = array_merge(KirbyTag::$types, array_change_key_case($tags)); + } + + /** + * Registers additional templates + * + * @param array $templates + * @return array + */ + protected function extendTemplates(array $templates): array + { + return $this->extensions['templates'] = array_merge($this->extensions['templates'], $templates); + } + + /** + * Registers translations + * + * @param array $translations + * @return array + */ + protected function extendTranslations(array $translations): array + { + return $this->extensions['translations'] = array_replace_recursive($this->extensions['translations'], $translations); + } + + /** + * Add third party extensions to the registry + * so they can be used as plugins for plugins + * for example. + * + * @param array $extensions + * @return array + */ + protected function extendThirdParty(array $extensions): array + { + return $this->extensions['thirdParty'] = array_replace_recursive($this->extensions['thirdParty'], $extensions); + } + + /** + * Registers additional user methods + * + * @param array $methods + * @return array + */ + protected function extendUserMethods(array $methods): array + { + return $this->extensions['userMethods'] = User::$methods = array_merge(User::$methods, $methods); + } + + /** + * Registers additional user models + * + * @param array $models + * @return array + */ + protected function extendUserModels(array $models): array + { + return $this->extensions['userModels'] = User::$models = array_merge(User::$models, $models); + } + + /** + * Registers additional users methods + * + * @param array $methods + * @return array + */ + protected function extendUsersMethods(array $methods): array + { + return $this->extensions['usersMethods'] = Users::$methods = array_merge(Users::$methods, $methods); + } + + /** + * Registers additional custom validators + * + * @param array $validators + * @return array + */ + protected function extendValidators(array $validators): array + { + return $this->extensions['validators'] = V::$validators = array_merge(V::$validators, $validators); + } + + /** + * Returns a given extension by type and name + * + * @internal + * @param string $type i.e. `'hooks'` + * @param string $name i.e. `'page.delete:before'` + * @param mixed $fallback + * @return mixed + */ + public function extension(string $type, string $name, $fallback = null) + { + return $this->extensions($type)[$name] ?? $fallback; + } + + /** + * Returns the extensions registry + * + * @internal + * @param string|null $type + * @return array + */ + public function extensions(string $type = null) + { + if ($type === null) { + return $this->extensions; + } + + return $this->extensions[$type] ?? []; + } + + /** + * Load extensions from site folders. + * This is only used for models for now, but + * could be extended later + */ + protected function extensionsFromFolders() + { + $models = []; + + foreach (glob($this->root('models') . '/*.php') as $model) { + $name = F::name($model); + $class = str_replace(['.', '-', '_'], '', $name) . 'Page'; + + // load the model class + F::loadOnce($model); + + if (class_exists($class) === true) { + $models[$name] = $class; + } + } + + $this->extendPageModels($models); + } + + /** + * Register extensions that could be located in + * the options array. I.e. hooks and routes can be + * setup from the config. + * + * @return void + */ + protected function extensionsFromOptions() + { + // register routes and hooks from options + $this->extend([ + 'api' => $this->options['api'] ?? [], + 'routes' => $this->options['routes'] ?? [], + 'hooks' => $this->options['hooks'] ?? [] + ]); + } + + /** + * Apply all plugin extensions + * + * @return void + */ + protected function extensionsFromPlugins() + { + // register all their extensions + foreach ($this->plugins() as $plugin) { + $extends = $plugin->extends(); + + if (empty($extends) === false) { + $this->extend($extends, $plugin); + } + } + } + + /** + * Apply all passed extensions + * + * @param array $props + * @return void + */ + protected function extensionsFromProps(array $props) + { + $this->extend($props); + } + + /** + * Apply all default extensions + * + * @return void + */ + protected function extensionsFromSystem() + { + // mixins + FormField::$mixins = $this->core->fieldMixins(); + Section::$mixins = $this->core->sectionMixins(); + + // aliases + KirbyTag::$aliases = $this->core->kirbyTagAliases(); + Field::$aliases = $this->core->fieldMethodAliases(); + + // blueprint presets + PageBlueprint::$presets = $this->core->blueprintPresets(); + + $this->extendAuthChallenges($this->core->authChallenges()); + $this->extendCacheTypes($this->core->cacheTypes()); + $this->extendComponents($this->core->components()); + $this->extendBlueprints($this->core->blueprints()); + $this->extendFields($this->core->fields()); + $this->extendFieldMethods($this->core->fieldMethods()); + $this->extendSections($this->core->sections()); + $this->extendSnippets($this->core->snippets()); + $this->extendTags($this->core->kirbyTags()); + $this->extendTemplates($this->core->templates()); + } + + /** + * Checks if a native component was extended + * @since 3.7.0 + * + * @param string $component + * @return bool + */ + public function isNativeComponent(string $component): bool + { + return $this->component($component) === $this->nativeComponent($component); + } + + /** + * Returns the native implementation + * of a core component + * + * @param string $component + * @return \Closure|false + */ + public function nativeComponent(string $component) + { + return $this->core->components()[$component] ?? false; + } + + /** + * Kirby plugin factory and getter + * + * @param string $name + * @param array|null $extends If null is passed it will be used as getter. Otherwise as factory. + * @return \Kirby\Cms\Plugin|null + * @throws \Kirby\Exception\DuplicateException + */ + public static function plugin(string $name, array $extends = null) + { + if ($extends === null) { + return static::$plugins[$name] ?? null; + } + + // get the correct root for the plugin + $extends['root'] = $extends['root'] ?? dirname(debug_backtrace()[0]['file']); + + $plugin = new Plugin($name, $extends); + $name = $plugin->name(); + + if (isset(static::$plugins[$name]) === true) { + throw new DuplicateException('The plugin "' . $name . '" has already been registered'); + } + + return static::$plugins[$name] = $plugin; + } + + /** + * Loads and returns all plugins in the site/plugins directory + * Loading only happens on the first call. + * + * @internal + * @param array|null $plugins Can be used to overwrite the plugins registry + * @return array + */ + public function plugins(array $plugins = null): array + { + // overwrite the existing plugins registry + if ($plugins !== null) { + $this->pluginsAreLoaded = true; + return static::$plugins = $plugins; + } + + // don't load plugins twice + if ($this->pluginsAreLoaded === true) { + return static::$plugins; + } + + // load all plugins from site/plugins + $this->pluginsLoader(); + + // mark plugins as loaded to stop doing it twice + $this->pluginsAreLoaded = true; + return static::$plugins; + } + + /** + * Loads all plugins from site/plugins + * + * @return array Array of loaded directories + */ + protected function pluginsLoader(): array + { + $root = $this->root('plugins'); + $loaded = []; + + foreach (Dir::read($root) as $dirname) { + if (in_array(substr($dirname, 0, 1), ['.', '_']) === true) { + continue; + } + + $dir = $root . '/' . $dirname; + + if (is_dir($dir) !== true) { + continue; + } + + $entry = $dir . '/index.php'; + $script = $dir . '/index.js'; + $styles = $dir . '/index.css'; + + if (is_file($entry) === true) { + F::loadOnce($entry); + } elseif (is_file($script) === true || is_file($styles) === true) { + // if no PHP file is present but an index.js or index.css, + // register as anonymous plugin (without actual extensions) + // to be picked up by the Panel\Document class when + // rendering the Panel view + static::plugin('plugins/' . $dirname, ['root' => $dir]); + } else { + continue; + } + + $loaded[] = $dir; + } + + return $loaded; + } } diff --git a/kirby/src/Cms/AppTranslations.php b/kirby/src/Cms/AppTranslations.php index dd5ff6b..86d09c2 100755 --- a/kirby/src/Cms/AppTranslations.php +++ b/kirby/src/Cms/AppTranslations.php @@ -17,205 +17,205 @@ use Kirby\Toolkit\Str; */ trait AppTranslations { - protected $translations; + protected $translations; - /** - * Setup internationalization - * - * @return void - */ - protected function i18n(): void - { - I18n::$load = function ($locale): array { - $data = []; + /** + * Setup internationalization + * + * @return void + */ + protected function i18n(): void + { + I18n::$load = function ($locale): array { + $data = []; - if ($translation = $this->translation($locale)) { - $data = $translation->data(); - } + if ($translation = $this->translation($locale)) { + $data = $translation->data(); + } - // inject translations from the current language - if ( - $this->multilang() === true && - $language = $this->languages()->find($locale) - ) { - $data = array_merge($data, $language->translations()); - } + // inject translations from the current language + if ( + $this->multilang() === true && + $language = $this->languages()->find($locale) + ) { + $data = array_merge($data, $language->translations()); + } - return $data; - }; + return $data; + }; - // the actual locale is set using $app->setCurrentTranslation() - I18n::$locale = function (): string { - if ($this->multilang() === true) { - return $this->defaultLanguage()->code(); - } else { - return 'en'; - } - }; + // the actual locale is set using $app->setCurrentTranslation() + I18n::$locale = function (): string { + if ($this->multilang() === true) { + return $this->defaultLanguage()->code(); + } else { + return 'en'; + } + }; - I18n::$fallback = function (): array { - if ($this->multilang() === true) { - // first try to fall back to the configured default language - $defaultCode = $this->defaultLanguage()->code(); - $fallback = [$defaultCode]; + I18n::$fallback = function (): array { + if ($this->multilang() === true) { + // first try to fall back to the configured default language + $defaultCode = $this->defaultLanguage()->code(); + $fallback = [$defaultCode]; - // if the default language is specified with a country code - // (e.g. `en-us`), also try with just the language code - if (preg_match('/^([a-z]{2})-[a-z]+$/i', $defaultCode, $matches) === 1) { - $fallback[] = $matches[1]; - } + // if the default language is specified with a country code + // (e.g. `en-us`), also try with just the language code + if (preg_match('/^([a-z]{2})-[a-z]+$/i', $defaultCode, $matches) === 1) { + $fallback[] = $matches[1]; + } - // fall back to the complete English translation - // as a last resort - $fallback[] = 'en'; + // fall back to the complete English translation + // as a last resort + $fallback[] = 'en'; - return $fallback; - } else { - return ['en']; - } - }; + return $fallback; + } else { + return ['en']; + } + }; - I18n::$translations = []; + I18n::$translations = []; - // add slug rules based on config option - if ($slugs = $this->option('slugs')) { - // two ways that the option can be defined: - // "slugs" => "de" or "slugs" => ["language" => "de"] - if ($slugs = $slugs['language'] ?? $slugs ?? null) { - Str::$language = Language::loadRules($slugs); - } - } - } + // add slug rules based on config option + if ($slugs = $this->option('slugs')) { + // two ways that the option can be defined: + // "slugs" => "de" or "slugs" => ["language" => "de"] + if ($slugs = $slugs['language'] ?? $slugs ?? null) { + Str::$language = Language::loadRules($slugs); + } + } + } - /** - * Returns the language code that will be used - * for the Panel if no user is logged in or if - * no language is configured for the user - * - * @return string - */ - public function panelLanguage(): string - { - if ($this->multilang() === true) { - $defaultCode = $this->defaultLanguage()->code(); + /** + * Returns the language code that will be used + * for the Panel if no user is logged in or if + * no language is configured for the user + * + * @return string + */ + public function panelLanguage(): string + { + if ($this->multilang() === true) { + $defaultCode = $this->defaultLanguage()->code(); - // extract the language code from a language that - // contains the country code (e.g. `en-us`) - if (preg_match('/^([a-z]{2})-[a-z]+$/i', $defaultCode, $matches) === 1) { - $defaultCode = $matches[1]; - } - } else { - $defaultCode = 'en'; - } + // extract the language code from a language that + // contains the country code (e.g. `en-us`) + if (preg_match('/^([a-z]{2})-[a-z]+$/i', $defaultCode, $matches) === 1) { + $defaultCode = $matches[1]; + } + } else { + $defaultCode = 'en'; + } - return $this->option('panel.language', $defaultCode); - } + return $this->option('panel.language', $defaultCode); + } - /** - * Load and set the current language if it exists - * Otherwise fall back to the default language - * - * @internal - * @param string|null $languageCode - * @return \Kirby\Cms\Language|null - */ - public function setCurrentLanguage(string $languageCode = null) - { - if ($this->multilang() === false) { - Locale::set($this->option('locale', 'en_US.utf-8')); - return $this->language = null; - } + /** + * Load and set the current language if it exists + * Otherwise fall back to the default language + * + * @internal + * @param string|null $languageCode + * @return \Kirby\Cms\Language|null + */ + public function setCurrentLanguage(string $languageCode = null) + { + if ($this->multilang() === false) { + Locale::set($this->option('locale', 'en_US.utf-8')); + return $this->language = null; + } - if ($language = $this->language($languageCode)) { - $this->language = $language; - } else { - $this->language = $this->defaultLanguage(); - } + if ($language = $this->language($languageCode)) { + $this->language = $language; + } else { + $this->language = $this->defaultLanguage(); + } - if ($this->language) { - Locale::set($this->language->locale()); - } + if ($this->language) { + Locale::set($this->language->locale()); + } - // add language slug rules to Str class - Str::$language = $this->language->rules(); + // add language slug rules to Str class + Str::$language = $this->language->rules(); - return $this->language; - } + return $this->language; + } - /** - * Set the current translation - * - * @internal - * @param string|null $translationCode - * @return void - */ - public function setCurrentTranslation(string $translationCode = null): void - { - I18n::$locale = $translationCode ?? 'en'; - } + /** + * Set the current translation + * + * @internal + * @param string|null $translationCode + * @return void + */ + public function setCurrentTranslation(string $translationCode = null): void + { + I18n::$locale = $translationCode ?? 'en'; + } - /** - * Load a specific translation by locale - * - * @param string|null $locale Locale name or `null` for the current locale - * @return \Kirby\Cms\Translation - */ - public function translation(?string $locale = null) - { - $locale = $locale ?? I18n::locale(); - $locale = basename($locale); + /** + * Load a specific translation by locale + * + * @param string|null $locale Locale name or `null` for the current locale + * @return \Kirby\Cms\Translation + */ + public function translation(?string $locale = null) + { + $locale = $locale ?? I18n::locale(); + $locale = basename($locale); - // prefer loading them from the translations collection - if (is_a($this->translations, 'Kirby\Cms\Translations') === true) { - if ($translation = $this->translations()->find($locale)) { - return $translation; - } - } + // prefer loading them from the translations collection + if (is_a($this->translations, 'Kirby\Cms\Translations') === true) { + if ($translation = $this->translations()->find($locale)) { + return $translation; + } + } - // get injected translation data from plugins etc. - $inject = $this->extensions['translations'][$locale] ?? []; + // get injected translation data from plugins etc. + $inject = $this->extensions['translations'][$locale] ?? []; - // inject current language translations - if ($language = $this->language($locale)) { - $inject = array_merge($inject, $language->translations()); - } + // inject current language translations + if ($language = $this->language($locale)) { + $inject = array_merge($inject, $language->translations()); + } - // load from disk instead - return Translation::load($locale, $this->root('i18n:translations') . '/' . $locale . '.json', $inject); - } + // load from disk instead + return Translation::load($locale, $this->root('i18n:translations') . '/' . $locale . '.json', $inject); + } - /** - * Returns all available translations - * - * @return \Kirby\Cms\Translations - */ - public function translations() - { - if (is_a($this->translations, 'Kirby\Cms\Translations') === true) { - return $this->translations; - } + /** + * Returns all available translations + * + * @return \Kirby\Cms\Translations + */ + public function translations() + { + if (is_a($this->translations, 'Kirby\Cms\Translations') === true) { + return $this->translations; + } - $translations = $this->extensions['translations'] ?? []; + $translations = $this->extensions['translations'] ?? []; - // injects languages translations - if ($languages = $this->languages()) { - foreach ($languages as $language) { - $languageCode = $language->code(); - $languageTranslations = $language->translations(); + // injects languages translations + if ($languages = $this->languages()) { + foreach ($languages as $language) { + $languageCode = $language->code(); + $languageTranslations = $language->translations(); - // merges language translations with extensions translations - if (empty($languageTranslations) === false) { - $translations[$languageCode] = array_merge( - $translations[$languageCode] ?? [], - $languageTranslations - ); - } - } - } + // merges language translations with extensions translations + if (empty($languageTranslations) === false) { + $translations[$languageCode] = array_merge( + $translations[$languageCode] ?? [], + $languageTranslations + ); + } + } + } - $this->translations = Translations::load($this->root('i18n:translations'), $translations); + $this->translations = Translations::load($this->root('i18n:translations'), $translations); - return $this->translations; - } + return $this->translations; + } } diff --git a/kirby/src/Cms/AppUsers.php b/kirby/src/Cms/AppUsers.php index 777dea9..8eedcce 100755 --- a/kirby/src/Cms/AppUsers.php +++ b/kirby/src/Cms/AppUsers.php @@ -16,128 +16,128 @@ use Throwable; */ trait AppUsers { - /** - * Cache for the auth auth layer - * - * @var Auth - */ - protected $auth; + /** + * Cache for the auth auth layer + * + * @var Auth + */ + protected $auth; - /** - * Returns the Authentication layer class - * - * @internal - * @return \Kirby\Cms\Auth - */ - public function auth() - { - return $this->auth = $this->auth ?? new Auth($this); - } + /** + * Returns the Authentication layer class + * + * @internal + * @return \Kirby\Cms\Auth + */ + public function auth() + { + return $this->auth = $this->auth ?? new Auth($this); + } - /** - * Become any existing user or disable the current user - * - * @param string|null $who User ID or email address, - * `null` to use the actual user again, - * `'kirby'` for a virtual admin user or - * `'nobody'` to disable the actual user - * @param Closure|null $callback Optional action function that will be run with - * the permissions of the impersonated user; the - * impersonation will be reset afterwards - * @return mixed If called without callback: User that was impersonated; - * if called with callback: Return value from the callback - * @throws \Throwable - */ - public function impersonate(?string $who = null, ?Closure $callback = null) - { - $auth = $this->auth(); + /** + * Become any existing user or disable the current user + * + * @param string|null $who User ID or email address, + * `null` to use the actual user again, + * `'kirby'` for a virtual admin user or + * `'nobody'` to disable the actual user + * @param Closure|null $callback Optional action function that will be run with + * the permissions of the impersonated user; the + * impersonation will be reset afterwards + * @return mixed If called without callback: User that was impersonated; + * if called with callback: Return value from the callback + * @throws \Throwable + */ + public function impersonate(?string $who = null, ?Closure $callback = null) + { + $auth = $this->auth(); - $userBefore = $auth->currentUserFromImpersonation(); - $userAfter = $auth->impersonate($who); + $userBefore = $auth->currentUserFromImpersonation(); + $userAfter = $auth->impersonate($who); - if ($callback === null) { - return $userAfter; - } + if ($callback === null) { + return $userAfter; + } - try { - // bind the App object to the callback - return $callback->call($this, $userAfter); - } catch (Throwable $e) { - throw $e; - } finally { - // ensure that the impersonation is *always* reset - // to the original value, even if an error occurred - $auth->impersonate($userBefore !== null ? $userBefore->id() : null); - } - } + try { + // bind the App object to the callback + return $callback->call($this, $userAfter); + } catch (Throwable $e) { + throw $e; + } finally { + // ensure that the impersonation is *always* reset + // to the original value, even if an error occurred + $auth->impersonate($userBefore !== null ? $userBefore->id() : null); + } + } - /** - * Set the currently active user id - * - * @param \Kirby\Cms\User|string $user - * @return \Kirby\Cms\App - */ - protected function setUser($user = null) - { - $this->user = $user; - return $this; - } + /** + * Set the currently active user id + * + * @param \Kirby\Cms\User|string $user + * @return \Kirby\Cms\App + */ + protected function setUser($user = null) + { + $this->user = $user; + return $this; + } - /** - * Create your own set of app users - * - * @param array|null $users - * @return \Kirby\Cms\App - */ - protected function setUsers(array $users = null) - { - if ($users !== null) { - $this->users = Users::factory($users, [ - 'kirby' => $this - ]); - } + /** + * Create your own set of app users + * + * @param array|null $users + * @return \Kirby\Cms\App + */ + protected function setUsers(array $users = null) + { + if ($users !== null) { + $this->users = Users::factory($users, [ + 'kirby' => $this + ]); + } - return $this; - } + return $this; + } - /** - * Returns a specific user by id - * or the current user if no id is given - * - * @param string|null $id - * @param bool $allowImpersonation If set to false, only the actually - * logged in user will be returned - * (when `$id` is passed as `null`) - * @return \Kirby\Cms\User|null - */ - public function user(?string $id = null, bool $allowImpersonation = true) - { - if ($id !== null) { - return $this->users()->find($id); - } + /** + * Returns a specific user by id + * or the current user if no id is given + * + * @param string|null $id + * @param bool $allowImpersonation If set to false, only the actually + * logged in user will be returned + * (when `$id` is passed as `null`) + * @return \Kirby\Cms\User|null + */ + public function user(?string $id = null, bool $allowImpersonation = true) + { + if ($id !== null) { + return $this->users()->find($id); + } - if ($allowImpersonation === true && is_string($this->user) === true) { - return $this->auth()->impersonate($this->user); - } else { - try { - return $this->auth()->user(null, $allowImpersonation); - } catch (Throwable $e) { - return null; - } - } - } + if ($allowImpersonation === true && is_string($this->user) === true) { + return $this->auth()->impersonate($this->user); + } else { + try { + return $this->auth()->user(null, $allowImpersonation); + } catch (Throwable $e) { + return null; + } + } + } - /** - * Returns all users - * - * @return \Kirby\Cms\Users - */ - public function users() - { - if (is_a($this->users, 'Kirby\Cms\Users') === true) { - return $this->users; - } + /** + * Returns all users + * + * @return \Kirby\Cms\Users + */ + public function users() + { + if (is_a($this->users, 'Kirby\Cms\Users') === true) { + return $this->users; + } - return $this->users = Users::load($this->root('accounts'), ['kirby' => $this]); - } + return $this->users = Users::load($this->root('accounts'), ['kirby' => $this]); + } } diff --git a/kirby/src/Cms/Auth.php b/kirby/src/Cms/Auth.php index 6c3604b..6c81392 100755 --- a/kirby/src/Cms/Auth.php +++ b/kirby/src/Cms/Auth.php @@ -25,864 +25,864 @@ use Throwable; */ class Auth { - /** - * Available auth challenge classes - * from the core and plugins - * - * @var array - */ - public static $challenges = []; - - /** - * Currently impersonated user - * - * @var \Kirby\Cms\User|null - */ - protected $impersonate; - - /** - * Kirby instance - * - * @var \Kirby\Cms\App - */ - protected $kirby; - - /** - * Cache of the auth status object - * - * @var \Kirby\Cms\Auth\Status - */ - protected $status; - - /** - * Instance of the currently logged in user or - * `false` if the user was not yet determined - * - * @var \Kirby\Cms\User|null|false - */ - protected $user = false; - - /** - * Exception that was thrown while - * determining the current user - * - * @var \Throwable - */ - protected $userException; - - /** - * @param \Kirby\Cms\App $kirby - * @codeCoverageIgnore - */ - public function __construct(App $kirby) - { - $this->kirby = $kirby; - } - - /** - * Creates an authentication challenge - * (one-time auth code) - * @since 3.5.0 - * - * @param string $email - * @param bool $long If `true`, a long session will be created - * @param string $mode Either 'login' or 'password-reset' - * @return \Kirby\Cms\Auth\Status - * - * @throws \Kirby\Exception\LogicException If there is no suitable authentication challenge (only in debug mode) - * @throws \Kirby\Exception\NotFoundException If the user does not exist (only in debug mode) - * @throws \Kirby\Exception\PermissionException If the rate limit is exceeded - */ - public function createChallenge(string $email, bool $long = false, string $mode = 'login') - { - $email = $this->validateEmail($email); - - // rate-limit the number of challenges for DoS/DDoS protection - $this->track($email, false); - - $session = $this->kirby->session([ - 'createMode' => 'cookie', - 'long' => $long === true - ]); - - $challenge = null; - if ($user = $this->kirby->users()->find($email)) { - $timeout = $this->kirby->option('auth.challenge.timeout', 10 * 60); - - foreach ($this->enabledChallenges() as $name) { - $class = static::$challenges[$name] ?? null; - if ( - $class && - class_exists($class) === true && - is_subclass_of($class, 'Kirby\Cms\Auth\Challenge') === true && - $class::isAvailable($user, $mode) === true - ) { - $challenge = $name; - $code = $class::create($user, compact('mode', 'timeout')); - - $session->set('kirby.challenge.type', $challenge); - - if ($code !== null) { - $session->set('kirby.challenge.code', password_hash($code, PASSWORD_DEFAULT)); - $session->set('kirby.challenge.timeout', time() + $timeout); - } - - break; - } - } - - // if no suitable challenge was found, `$challenge === null` at this point; - // only leak this in debug mode - if ($challenge === null && $this->kirby->option('debug') === true) { - throw new LogicException('Could not find a suitable authentication challenge'); - } - } else { - $this->kirby->trigger('user.login:failed', compact('email')); - - // only leak the non-existing user in debug mode - if ($this->kirby->option('debug') === true) { - throw new NotFoundException([ - 'key' => 'user.notFound', - 'data' => [ - 'name' => $email - ] - ]); - } - } - - // always set the email, even if the challenge won't be - // created to avoid leaking whether the user exists - $session->set('kirby.challenge.email', $email); - - // sleep for a random amount of milliseconds - // to make automated attacks harder and to - // avoid leaking whether the user exists - usleep(random_int(1000, 300000)); - - // clear the status cache - $this->status = null; - - return $this->status($session, false); - } - - /** - * Returns the csrf token if it exists and if it is valid - * - * @return string|false - */ - public function csrf() - { - // get the csrf from the header - $fromHeader = $this->kirby->request()->csrf(); - - // check for a predefined csrf or use the one from session - $fromSession = $this->csrfFromSession(); - - // compare both tokens - if (hash_equals((string)$fromSession, (string)$fromHeader) !== true) { - return false; - } - - return $fromSession; - } - - /** - * Returns either predefined csrf or the one from session - * @since 3.6.0 - * - * @return string - */ - public function csrfFromSession(): string - { - $isDev = $this->kirby->option('panel.dev', false) !== false; - $fallback = $isDev ? 'dev' : $this->kirby->csrf(); - return $this->kirby->option('api.csrf', $fallback); - } - - /** - * Returns the logged in user by checking - * for a basic authentication header with - * valid credentials - * - * @param \Kirby\Http\Request\Auth\BasicAuth|null $auth - * @return \Kirby\Cms\User|null - * @throws \Kirby\Exception\InvalidArgumentException if the authorization header is invalid - * @throws \Kirby\Exception\PermissionException if basic authentication is not allowed - */ - public function currentUserFromBasicAuth(BasicAuth $auth = null) - { - if ($this->kirby->option('api.basicAuth', false) !== true) { - throw new PermissionException('Basic authentication is not activated'); - } - - // if logging in with password is disabled, basic auth cannot be possible either - $loginMethods = $this->kirby->system()->loginMethods(); - if (isset($loginMethods['password']) !== true) { - throw new PermissionException('Login with password is not enabled'); - } - - // if any login method requires 2FA, basic auth without 2FA would be a weakness - foreach ($loginMethods as $method) { - if (isset($method['2fa']) === true && $method['2fa'] === true) { - throw new PermissionException('Basic authentication cannot be used with 2FA'); - } - } - - $request = $this->kirby->request(); - $auth = $auth ?? $request->auth(); - - if (!$auth || $auth->type() !== 'basic') { - throw new InvalidArgumentException('Invalid authorization header'); - } - - // only allow basic auth when https is enabled or insecure requests permitted - if ($request->ssl() === false && $this->kirby->option('api.allowInsecure', false) !== true) { - throw new PermissionException('Basic authentication is only allowed over HTTPS'); - } - - return $this->validatePassword($auth->username(), $auth->password()); - } - - /** - * Returns the currently impersonated user - * - * @return \Kirby\Cms\User|null - */ - public function currentUserFromImpersonation() - { - return $this->impersonate; - } - - /** - * Returns the logged in user by checking - * the current session and finding a valid - * valid user id in there - * - * @param \Kirby\Session\Session|array|null $session - * @return \Kirby\Cms\User|null - */ - public function currentUserFromSession($session = null) - { - $session = $this->session($session); - - $id = $session->data()->get('kirby.userId'); - - if (is_string($id) !== true) { - return null; - } - - if ($user = $this->kirby->users()->find($id)) { - // in case the session needs to be updated, do it now - // for better performance - $session->commit(); - return $user; - } - - return null; - } - - /** - * Returns the list of enabled challenges in the - * configured order - * @since 3.5.1 - * - * @return array - */ - public function enabledChallenges(): array - { - return A::wrap($this->kirby->option('auth.challenges', ['email'])); - } - - /** - * Become any existing user or disable the current user - * - * @param string|null $who User ID or email address, - * `null` to use the actual user again, - * `'kirby'` for a virtual admin user or - * `'nobody'` to disable the actual user - * @return \Kirby\Cms\User|null - * @throws \Kirby\Exception\NotFoundException if the given user cannot be found - */ - public function impersonate(?string $who = null) - { - // clear the status cache - $this->status = null; - - switch ($who) { - case null: - return $this->impersonate = null; - case 'kirby': - return $this->impersonate = new User([ - 'email' => 'kirby@getkirby.com', - 'id' => 'kirby', - 'role' => 'admin', - ]); - case 'nobody': - return $this->impersonate = new User([ - 'email' => 'nobody@getkirby.com', - 'id' => 'nobody', - 'role' => 'nobody', - ]); - default: - if ($user = $this->kirby->users()->find($who)) { - return $this->impersonate = $user; - } - - throw new NotFoundException('The user "' . $who . '" cannot be found'); - } - } - - /** - * Returns the hashed ip of the visitor - * which is used to track invalid logins - * - * @return string - */ - public function ipHash(): string - { - $hash = hash('sha256', $this->kirby->visitor()->ip()); - - // only use the first 50 chars to ensure privacy - return substr($hash, 0, 50); - } - - /** - * Check if logins are blocked for the current ip or email - * - * @param string $email - * @return bool - */ - public function isBlocked(string $email): bool - { - $ip = $this->ipHash(); - $log = $this->log(); - $trials = $this->kirby->option('auth.trials', 10); - - if ($entry = ($log['by-ip'][$ip] ?? null)) { - if ($entry['trials'] >= $trials) { - return true; - } - } - - if ($this->kirby->users()->find($email)) { - if ($entry = ($log['by-email'][$email] ?? null)) { - if ($entry['trials'] >= $trials) { - return true; - } - } - } - - return false; - } - - /** - * Login a user by email and password - * - * @param string $email - * @param string $password - * @param bool $long - * @return \Kirby\Cms\User - * - * @throws \Kirby\Exception\PermissionException If the rate limit was exceeded or if any other error occurred with debug mode off - * @throws \Kirby\Exception\NotFoundException If the email was invalid - * @throws \Kirby\Exception\InvalidArgumentException If the password is not valid (via `$user->login()`) - */ - public function login(string $email, string $password, bool $long = false) - { - // session options - $options = [ - 'createMode' => 'cookie', - 'long' => $long === true - ]; - - // validate the user and log in to the session - $user = $this->validatePassword($email, $password); - $user->loginPasswordless($options); - - // clear the status cache - $this->status = null; - - return $user; - } - - /** - * Login a user by email, password and auth challenge - * @since 3.5.0 - * - * @param string $email - * @param string $password - * @param bool $long - * @return \Kirby\Cms\Auth\Status - * - * @throws \Kirby\Exception\PermissionException If the rate limit was exceeded or if any other error occurred with debug mode off - * @throws \Kirby\Exception\NotFoundException If the email was invalid - * @throws \Kirby\Exception\InvalidArgumentException If the password is not valid (via `$user->login()`) - */ - public function login2fa(string $email, string $password, bool $long = false) - { - $this->validatePassword($email, $password); - return $this->createChallenge($email, $long, '2fa'); - } - - /** - * Sets a user object as the current user in the cache - * @internal - * - * @param \Kirby\Cms\User $user - * @return void - */ - public function setUser(User $user): void - { - // stop impersonating - $this->impersonate = null; - - $this->user = $user; - - // clear the status cache - $this->status = null; - } - - /** - * Returns the authentication status object - * @since 3.5.1 - * - * @param \Kirby\Session\Session|array|null $session - * @param bool $allowImpersonation If set to false, only the actually - * logged in user will be returned - * @return \Kirby\Cms\Auth\Status - */ - public function status($session = null, bool $allowImpersonation = true) - { - // try to return from cache - if ($this->status && $session === null && $allowImpersonation === true) { - return $this->status; - } - - $sessionObj = $this->session($session); - - $props = ['kirby' => $this->kirby]; - if ($user = $this->user($sessionObj, $allowImpersonation)) { - // a user is currently logged in - if ($allowImpersonation === true && $this->impersonate !== null) { - $props['status'] = 'impersonated'; - } else { - $props['status'] = 'active'; - } - - $props['email'] = $user->email(); - } elseif ($email = $sessionObj->get('kirby.challenge.email')) { - // a challenge is currently pending - $props['status'] = 'pending'; - $props['email'] = $email; - $props['challenge'] = $sessionObj->get('kirby.challenge.type'); - $props['challengeFallback'] = A::last($this->enabledChallenges()); - } else { - // no active authentication - $props['status'] = 'inactive'; - } - - $status = new Status($props); - - // only cache the default object - if ($session === null && $allowImpersonation === true) { - $this->status = $status; - } - - return $status; - } - - /** - * Ensures that email addresses with IDN domains are in Unicode format - * and that the rate limit was not exceeded - * - * @param string $email - * @return string The normalized Unicode email address - * - * @throws \Kirby\Exception\PermissionException If the rate limit was exceeded - */ - protected function validateEmail(string $email): string - { - // ensure that email addresses with IDN domains are in Unicode format - $email = Idn::decodeEmail($email); - - // 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 { - // avoid leaking security-relevant information - $message = ['key' => 'access.login']; - } - - throw new PermissionException($message); - } - - return $email; - } - - /** - * Validates the user credentials and returns the user object on success; - * otherwise logs the failed attempt - * - * @param string $email - * @param string $password - * @return \Kirby\Cms\User - * - * @throws \Kirby\Exception\PermissionException If the rate limit was exceeded or if any other error occurred with debug mode off - * @throws \Kirby\Exception\NotFoundException If the email was invalid - * @throws \Kirby\Exception\InvalidArgumentException If the password is not valid (via `$user->login()`) - */ - public function validatePassword(string $email, string $password) - { - $email = $this->validateEmail($email); - - // validate the user - try { - if ($user = $this->kirby->users()->find($email)) { - if ($user->validatePassword($password) === true) { - return $user; - } - } - - throw new NotFoundException([ - 'key' => 'user.notFound', - 'data' => [ - 'name' => $email - ] - ]); - } catch (Throwable $e) { - // log invalid login trial - $this->track($email); - - // sleep for a random amount of milliseconds - // to make automated attacks harder - usleep(random_int(1000, 2000000)); - - // keep throwing the original error in debug mode, - // otherwise hide it to avoid leaking security-relevant information - if ($this->kirby->option('debug') === true) { - throw $e; - } else { - throw new PermissionException(['key' => 'access.login']); - } - } - } - - /** - * Returns the absolute path to the logins log - * - * @return string - */ - public function logfile(): string - { - return $this->kirby->root('accounts') . '/.logins'; - } - - /** - * Read all tracked logins - * - * @return array - */ - public function log(): array - { - try { - $log = Data::read($this->logfile(), 'json'); - $read = true; - } catch (Throwable $e) { - $log = []; - $read = false; - } - - // ensure that the category arrays are defined - $log['by-ip'] = $log['by-ip'] ?? []; - $log['by-email'] = $log['by-email'] ?? []; - - // remove all elements on the top level with different keys (old structure) - $log = array_intersect_key($log, array_flip(['by-ip', 'by-email'])); - - // remove entries that are no longer needed - $originalLog = $log; - $time = time() - $this->kirby->option('auth.timeout', 3600); - foreach ($log as $category => $entries) { - $log[$category] = array_filter( - $entries, - fn ($entry) => $entry['time'] > $time - ); - } - - // write new log to the file system if it changed - if ($read === false || $log !== $originalLog) { - if (count($log['by-ip']) === 0 && count($log['by-email']) === 0) { - F::remove($this->logfile()); - } else { - Data::write($this->logfile(), $log, 'json'); - } - } - - return $log; - } - - /** - * Logout the current user - * - * @return void - */ - public function logout(): void - { - // stop impersonating; - // ensures that we log out the actually logged in user - $this->impersonate = null; - - // logout the current user if it exists - if ($user = $this->user()) { - $user->logout(); - } - - // clear the pending challenge - $session = $this->kirby->session(); - $session->remove('kirby.challenge.code'); - $session->remove('kirby.challenge.email'); - $session->remove('kirby.challenge.timeout'); - $session->remove('kirby.challenge.type'); - - // clear the status cache - $this->status = null; - } - - /** - * Clears the cached user data after logout - * @internal - * - * @return void - */ - public function flush(): void - { - $this->impersonate = null; - $this->status = null; - $this->user = null; - } - - /** - * Tracks a login - * - * @param string|null $email - * @param bool $triggerHook If `false`, no user.login:failed hook is triggered - * @return bool - */ - public function track(?string $email, bool $triggerHook = true): bool - { - if ($triggerHook === true) { - $this->kirby->trigger('user.login:failed', compact('email')); - } - - $ip = $this->ipHash(); - $log = $this->log(); - $time = time(); - - if (isset($log['by-ip'][$ip]) === true) { - $log['by-ip'][$ip] = [ - 'time' => $time, - 'trials' => ($log['by-ip'][$ip]['trials'] ?? 0) + 1 - ]; - } else { - $log['by-ip'][$ip] = [ - 'time' => $time, - 'trials' => 1 - ]; - } - - if ($email !== null && $this->kirby->users()->find($email)) { - if (isset($log['by-email'][$email]) === true) { - $log['by-email'][$email] = [ - 'time' => $time, - 'trials' => ($log['by-email'][$email]['trials'] ?? 0) + 1 - ]; - } else { - $log['by-email'][$email] = [ - 'time' => $time, - 'trials' => 1 - ]; - } - } - - return Data::write($this->logfile(), $log, 'json'); - } - - /** - * Returns the current authentication type - * - * @param bool $allowImpersonation If set to false, 'impersonate' won't - * be returned as authentication type - * even if an impersonation is active - * @return string - */ - public function type(bool $allowImpersonation = true): string - { - $basicAuth = $this->kirby->option('api.basicAuth', false); - $auth = $this->kirby->request()->auth(); - - if ($basicAuth === true && $auth && $auth->type() === 'basic') { - return 'basic'; - } elseif ($allowImpersonation === true && $this->impersonate !== null) { - return 'impersonate'; - } else { - return 'session'; - } - } - - /** - * Validates the currently logged in user - * - * @param \Kirby\Session\Session|array|null $session - * @param bool $allowImpersonation If set to false, only the actually - * logged in user will be returned - * @return \Kirby\Cms\User|null - * - * @throws \Throwable If an authentication error occurred - */ - public function user($session = null, bool $allowImpersonation = true) - { - if ($allowImpersonation === true && $this->impersonate !== null) { - return $this->impersonate; - } - - // return from cache - if ($this->user === null) { - // throw the same Exception again if one was captured before - if ($this->userException !== null) { - throw $this->userException; - } - - return null; - } elseif ($this->user !== false) { - return $this->user; - } - - try { - if ($this->type() === 'basic') { - return $this->user = $this->currentUserFromBasicAuth(); - } else { - return $this->user = $this->currentUserFromSession($session); - } - } catch (Throwable $e) { - $this->user = null; - - // capture the Exception for future calls - $this->userException = $e; - - throw $e; - } - } - - /** - * Verifies an authentication code that was - * requested with the `createChallenge()` method; - * if successful, the user is automatically logged in - * @since 3.5.0 - * - * @param string $code User-provided auth code to verify - * @return \Kirby\Cms\User User object of the logged-in user - * - * @throws \Kirby\Exception\PermissionException If the rate limit was exceeded, the challenge timed out, the code - * is incorrect or if any other error occurred with debug mode off - * @throws \Kirby\Exception\NotFoundException If the user from the challenge doesn't exist - * @throws \Kirby\Exception\InvalidArgumentException If no authentication challenge is active - * @throws \Kirby\Exception\LogicException If the authentication challenge is invalid - */ - public function verifyChallenge(string $code) - { - try { - $session = $this->kirby->session(); - - // first check if we have an active challenge at all - $email = $session->get('kirby.challenge.email'); - $challenge = $session->get('kirby.challenge.type'); - if (is_string($email) !== true || is_string($challenge) !== true) { - throw new InvalidArgumentException('No authentication challenge is active'); - } - - $user = $this->kirby->users()->find($email); - if ($user === null) { - throw new NotFoundException([ - 'key' => 'user.notFound', - 'data' => [ - 'name' => $email - ] - ]); - } - - // rate-limiting - if ($this->isBlocked($email) === true) { - $this->kirby->trigger('user.login:failed', compact('email')); - throw new PermissionException('Rate limit exceeded'); - } - - // time-limiting - $timeout = $session->get('kirby.challenge.timeout'); - if ($timeout !== null && time() > $timeout) { - throw new PermissionException('Authentication challenge timeout'); - } - - if ( - isset(static::$challenges[$challenge]) === true && - class_exists(static::$challenges[$challenge]) === true && - is_subclass_of(static::$challenges[$challenge], 'Kirby\Cms\Auth\Challenge') === true - ) { - $class = static::$challenges[$challenge]; - if ($class::verify($user, $code) === true) { - $this->logout(); - $user->loginPasswordless(); - - // clear the status cache - $this->status = null; - - return $user; - } else { - throw new PermissionException(['key' => 'access.code']); - } - } - - throw new LogicException('Invalid authentication challenge: ' . $challenge); - } catch (Throwable $e) { - if (empty($email) === false && $e->getMessage() !== 'Rate limit exceeded') { - $this->track($email); - } - - // sleep for a random amount of milliseconds - // to make automated attacks harder and to - // avoid leaking whether the user exists - usleep(random_int(1000, 2000000)); - - // keep throwing the original error in debug mode, - // otherwise hide it to avoid leaking security-relevant information - if ($this->kirby->option('debug') === true) { - throw $e; - } else { - throw new PermissionException(['key' => 'access.code']); - } - } - } - - /** - * Creates a session object from the passed options - * - * @param \Kirby\Session\Session|array|null $session - * @return \Kirby\Session\Session - */ - protected function session($session = null) - { - // use passed session options or session object if set - if (is_array($session) === true) { - return $this->kirby->session($session); - } - - // try session in header or cookie - if (is_a($session, 'Kirby\Session\Session') === false) { - return $this->kirby->session(['detect' => true]); - } - - return $session; - } + /** + * Available auth challenge classes + * from the core and plugins + * + * @var array + */ + public static $challenges = []; + + /** + * Currently impersonated user + * + * @var \Kirby\Cms\User|null + */ + protected $impersonate; + + /** + * Kirby instance + * + * @var \Kirby\Cms\App + */ + protected $kirby; + + /** + * Cache of the auth status object + * + * @var \Kirby\Cms\Auth\Status + */ + protected $status; + + /** + * Instance of the currently logged in user or + * `false` if the user was not yet determined + * + * @var \Kirby\Cms\User|null|false + */ + protected $user = false; + + /** + * Exception that was thrown while + * determining the current user + * + * @var \Throwable + */ + protected $userException; + + /** + * @param \Kirby\Cms\App $kirby + * @codeCoverageIgnore + */ + public function __construct(App $kirby) + { + $this->kirby = $kirby; + } + + /** + * Creates an authentication challenge + * (one-time auth code) + * @since 3.5.0 + * + * @param string $email + * @param bool $long If `true`, a long session will be created + * @param string $mode Either 'login' or 'password-reset' + * @return \Kirby\Cms\Auth\Status + * + * @throws \Kirby\Exception\LogicException If there is no suitable authentication challenge (only in debug mode) + * @throws \Kirby\Exception\NotFoundException If the user does not exist (only in debug mode) + * @throws \Kirby\Exception\PermissionException If the rate limit is exceeded + */ + public function createChallenge(string $email, bool $long = false, string $mode = 'login') + { + $email = $this->validateEmail($email); + + // rate-limit the number of challenges for DoS/DDoS protection + $this->track($email, false); + + $session = $this->kirby->session([ + 'createMode' => 'cookie', + 'long' => $long === true + ]); + + $challenge = null; + if ($user = $this->kirby->users()->find($email)) { + $timeout = $this->kirby->option('auth.challenge.timeout', 10 * 60); + + foreach ($this->enabledChallenges() as $name) { + $class = static::$challenges[$name] ?? null; + if ( + $class && + class_exists($class) === true && + is_subclass_of($class, 'Kirby\Cms\Auth\Challenge') === true && + $class::isAvailable($user, $mode) === true + ) { + $challenge = $name; + $code = $class::create($user, compact('mode', 'timeout')); + + $session->set('kirby.challenge.type', $challenge); + + if ($code !== null) { + $session->set('kirby.challenge.code', password_hash($code, PASSWORD_DEFAULT)); + $session->set('kirby.challenge.timeout', time() + $timeout); + } + + break; + } + } + + // if no suitable challenge was found, `$challenge === null` at this point; + // only leak this in debug mode + if ($challenge === null && $this->kirby->option('debug') === true) { + throw new LogicException('Could not find a suitable authentication challenge'); + } + } else { + $this->kirby->trigger('user.login:failed', compact('email')); + + // only leak the non-existing user in debug mode + if ($this->kirby->option('debug') === true) { + throw new NotFoundException([ + 'key' => 'user.notFound', + 'data' => [ + 'name' => $email + ] + ]); + } + } + + // always set the email, even if the challenge won't be + // created to avoid leaking whether the user exists + $session->set('kirby.challenge.email', $email); + + // sleep for a random amount of milliseconds + // to make automated attacks harder and to + // avoid leaking whether the user exists + usleep(random_int(1000, 300000)); + + // clear the status cache + $this->status = null; + + return $this->status($session, false); + } + + /** + * Returns the csrf token if it exists and if it is valid + * + * @return string|false + */ + public function csrf() + { + // get the csrf from the header + $fromHeader = $this->kirby->request()->csrf(); + + // check for a predefined csrf or use the one from session + $fromSession = $this->csrfFromSession(); + + // compare both tokens + if (hash_equals((string)$fromSession, (string)$fromHeader) !== true) { + return false; + } + + return $fromSession; + } + + /** + * Returns either predefined csrf or the one from session + * @since 3.6.0 + * + * @return string + */ + public function csrfFromSession(): string + { + $isDev = $this->kirby->option('panel.dev', false) !== false; + $fallback = $isDev ? 'dev' : $this->kirby->csrf(); + return $this->kirby->option('api.csrf', $fallback); + } + + /** + * Returns the logged in user by checking + * for a basic authentication header with + * valid credentials + * + * @param \Kirby\Http\Request\Auth\BasicAuth|null $auth + * @return \Kirby\Cms\User|null + * @throws \Kirby\Exception\InvalidArgumentException if the authorization header is invalid + * @throws \Kirby\Exception\PermissionException if basic authentication is not allowed + */ + public function currentUserFromBasicAuth(BasicAuth $auth = null) + { + if ($this->kirby->option('api.basicAuth', false) !== true) { + throw new PermissionException('Basic authentication is not activated'); + } + + // if logging in with password is disabled, basic auth cannot be possible either + $loginMethods = $this->kirby->system()->loginMethods(); + if (isset($loginMethods['password']) !== true) { + throw new PermissionException('Login with password is not enabled'); + } + + // if any login method requires 2FA, basic auth without 2FA would be a weakness + foreach ($loginMethods as $method) { + if (isset($method['2fa']) === true && $method['2fa'] === true) { + throw new PermissionException('Basic authentication cannot be used with 2FA'); + } + } + + $request = $this->kirby->request(); + $auth = $auth ?? $request->auth(); + + if (!$auth || $auth->type() !== 'basic') { + throw new InvalidArgumentException('Invalid authorization header'); + } + + // only allow basic auth when https is enabled or insecure requests permitted + if ($request->ssl() === false && $this->kirby->option('api.allowInsecure', false) !== true) { + throw new PermissionException('Basic authentication is only allowed over HTTPS'); + } + + return $this->validatePassword($auth->username(), $auth->password()); + } + + /** + * Returns the currently impersonated user + * + * @return \Kirby\Cms\User|null + */ + public function currentUserFromImpersonation() + { + return $this->impersonate; + } + + /** + * Returns the logged in user by checking + * the current session and finding a valid + * valid user id in there + * + * @param \Kirby\Session\Session|array|null $session + * @return \Kirby\Cms\User|null + */ + public function currentUserFromSession($session = null) + { + $session = $this->session($session); + + $id = $session->data()->get('kirby.userId'); + + if (is_string($id) !== true) { + return null; + } + + if ($user = $this->kirby->users()->find($id)) { + // in case the session needs to be updated, do it now + // for better performance + $session->commit(); + return $user; + } + + return null; + } + + /** + * Returns the list of enabled challenges in the + * configured order + * @since 3.5.1 + * + * @return array + */ + public function enabledChallenges(): array + { + return A::wrap($this->kirby->option('auth.challenges', ['email'])); + } + + /** + * Become any existing user or disable the current user + * + * @param string|null $who User ID or email address, + * `null` to use the actual user again, + * `'kirby'` for a virtual admin user or + * `'nobody'` to disable the actual user + * @return \Kirby\Cms\User|null + * @throws \Kirby\Exception\NotFoundException if the given user cannot be found + */ + public function impersonate(?string $who = null) + { + // clear the status cache + $this->status = null; + + switch ($who) { + case null: + return $this->impersonate = null; + case 'kirby': + return $this->impersonate = new User([ + 'email' => 'kirby@getkirby.com', + 'id' => 'kirby', + 'role' => 'admin', + ]); + case 'nobody': + return $this->impersonate = new User([ + 'email' => 'nobody@getkirby.com', + 'id' => 'nobody', + 'role' => 'nobody', + ]); + default: + if ($user = $this->kirby->users()->find($who)) { + return $this->impersonate = $user; + } + + throw new NotFoundException('The user "' . $who . '" cannot be found'); + } + } + + /** + * Returns the hashed ip of the visitor + * which is used to track invalid logins + * + * @return string + */ + public function ipHash(): string + { + $hash = hash('sha256', $this->kirby->visitor()->ip()); + + // only use the first 50 chars to ensure privacy + return substr($hash, 0, 50); + } + + /** + * Check if logins are blocked for the current ip or email + * + * @param string $email + * @return bool + */ + public function isBlocked(string $email): bool + { + $ip = $this->ipHash(); + $log = $this->log(); + $trials = $this->kirby->option('auth.trials', 10); + + if ($entry = ($log['by-ip'][$ip] ?? null)) { + if ($entry['trials'] >= $trials) { + return true; + } + } + + if ($this->kirby->users()->find($email)) { + if ($entry = ($log['by-email'][$email] ?? null)) { + if ($entry['trials'] >= $trials) { + return true; + } + } + } + + return false; + } + + /** + * Login a user by email and password + * + * @param string $email + * @param string $password + * @param bool $long + * @return \Kirby\Cms\User + * + * @throws \Kirby\Exception\PermissionException If the rate limit was exceeded or if any other error occurred with debug mode off + * @throws \Kirby\Exception\NotFoundException If the email was invalid + * @throws \Kirby\Exception\InvalidArgumentException If the password is not valid (via `$user->login()`) + */ + public function login(string $email, string $password, bool $long = false) + { + // session options + $options = [ + 'createMode' => 'cookie', + 'long' => $long === true + ]; + + // validate the user and log in to the session + $user = $this->validatePassword($email, $password); + $user->loginPasswordless($options); + + // clear the status cache + $this->status = null; + + return $user; + } + + /** + * Login a user by email, password and auth challenge + * @since 3.5.0 + * + * @param string $email + * @param string $password + * @param bool $long + * @return \Kirby\Cms\Auth\Status + * + * @throws \Kirby\Exception\PermissionException If the rate limit was exceeded or if any other error occurred with debug mode off + * @throws \Kirby\Exception\NotFoundException If the email was invalid + * @throws \Kirby\Exception\InvalidArgumentException If the password is not valid (via `$user->login()`) + */ + public function login2fa(string $email, string $password, bool $long = false) + { + $this->validatePassword($email, $password); + return $this->createChallenge($email, $long, '2fa'); + } + + /** + * Sets a user object as the current user in the cache + * @internal + * + * @param \Kirby\Cms\User $user + * @return void + */ + public function setUser(User $user): void + { + // stop impersonating + $this->impersonate = null; + + $this->user = $user; + + // clear the status cache + $this->status = null; + } + + /** + * Returns the authentication status object + * @since 3.5.1 + * + * @param \Kirby\Session\Session|array|null $session + * @param bool $allowImpersonation If set to false, only the actually + * logged in user will be returned + * @return \Kirby\Cms\Auth\Status + */ + public function status($session = null, bool $allowImpersonation = true) + { + // try to return from cache + if ($this->status && $session === null && $allowImpersonation === true) { + return $this->status; + } + + $sessionObj = $this->session($session); + + $props = ['kirby' => $this->kirby]; + if ($user = $this->user($sessionObj, $allowImpersonation)) { + // a user is currently logged in + if ($allowImpersonation === true && $this->impersonate !== null) { + $props['status'] = 'impersonated'; + } else { + $props['status'] = 'active'; + } + + $props['email'] = $user->email(); + } elseif ($email = $sessionObj->get('kirby.challenge.email')) { + // a challenge is currently pending + $props['status'] = 'pending'; + $props['email'] = $email; + $props['challenge'] = $sessionObj->get('kirby.challenge.type'); + $props['challengeFallback'] = A::last($this->enabledChallenges()); + } else { + // no active authentication + $props['status'] = 'inactive'; + } + + $status = new Status($props); + + // only cache the default object + if ($session === null && $allowImpersonation === true) { + $this->status = $status; + } + + return $status; + } + + /** + * Ensures that email addresses with IDN domains are in Unicode format + * and that the rate limit was not exceeded + * + * @param string $email + * @return string The normalized Unicode email address + * + * @throws \Kirby\Exception\PermissionException If the rate limit was exceeded + */ + protected function validateEmail(string $email): string + { + // ensure that email addresses with IDN domains are in Unicode format + $email = Idn::decodeEmail($email); + + // 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 { + // avoid leaking security-relevant information + $message = ['key' => 'access.login']; + } + + throw new PermissionException($message); + } + + return $email; + } + + /** + * Validates the user credentials and returns the user object on success; + * otherwise logs the failed attempt + * + * @param string $email + * @param string $password + * @return \Kirby\Cms\User + * + * @throws \Kirby\Exception\PermissionException If the rate limit was exceeded or if any other error occurred with debug mode off + * @throws \Kirby\Exception\NotFoundException If the email was invalid + * @throws \Kirby\Exception\InvalidArgumentException If the password is not valid (via `$user->login()`) + */ + public function validatePassword(string $email, string $password) + { + $email = $this->validateEmail($email); + + // validate the user + try { + if ($user = $this->kirby->users()->find($email)) { + if ($user->validatePassword($password) === true) { + return $user; + } + } + + throw new NotFoundException([ + 'key' => 'user.notFound', + 'data' => [ + 'name' => $email + ] + ]); + } catch (Throwable $e) { + // log invalid login trial + $this->track($email); + + // sleep for a random amount of milliseconds + // to make automated attacks harder + usleep(random_int(1000, 2000000)); + + // keep throwing the original error in debug mode, + // otherwise hide it to avoid leaking security-relevant information + if ($this->kirby->option('debug') === true) { + throw $e; + } else { + throw new PermissionException(['key' => 'access.login']); + } + } + } + + /** + * Returns the absolute path to the logins log + * + * @return string + */ + public function logfile(): string + { + return $this->kirby->root('accounts') . '/.logins'; + } + + /** + * Read all tracked logins + * + * @return array + */ + public function log(): array + { + try { + $log = Data::read($this->logfile(), 'json'); + $read = true; + } catch (Throwable $e) { + $log = []; + $read = false; + } + + // ensure that the category arrays are defined + $log['by-ip'] = $log['by-ip'] ?? []; + $log['by-email'] = $log['by-email'] ?? []; + + // remove all elements on the top level with different keys (old structure) + $log = array_intersect_key($log, array_flip(['by-ip', 'by-email'])); + + // remove entries that are no longer needed + $originalLog = $log; + $time = time() - $this->kirby->option('auth.timeout', 3600); + foreach ($log as $category => $entries) { + $log[$category] = array_filter( + $entries, + fn ($entry) => $entry['time'] > $time + ); + } + + // write new log to the file system if it changed + if ($read === false || $log !== $originalLog) { + if (count($log['by-ip']) === 0 && count($log['by-email']) === 0) { + F::remove($this->logfile()); + } else { + Data::write($this->logfile(), $log, 'json'); + } + } + + return $log; + } + + /** + * Logout the current user + * + * @return void + */ + public function logout(): void + { + // stop impersonating; + // ensures that we log out the actually logged in user + $this->impersonate = null; + + // logout the current user if it exists + if ($user = $this->user()) { + $user->logout(); + } + + // clear the pending challenge + $session = $this->kirby->session(); + $session->remove('kirby.challenge.code'); + $session->remove('kirby.challenge.email'); + $session->remove('kirby.challenge.timeout'); + $session->remove('kirby.challenge.type'); + + // clear the status cache + $this->status = null; + } + + /** + * Clears the cached user data after logout + * @internal + * + * @return void + */ + public function flush(): void + { + $this->impersonate = null; + $this->status = null; + $this->user = null; + } + + /** + * Tracks a login + * + * @param string|null $email + * @param bool $triggerHook If `false`, no user.login:failed hook is triggered + * @return bool + */ + public function track(?string $email, bool $triggerHook = true): bool + { + if ($triggerHook === true) { + $this->kirby->trigger('user.login:failed', compact('email')); + } + + $ip = $this->ipHash(); + $log = $this->log(); + $time = time(); + + if (isset($log['by-ip'][$ip]) === true) { + $log['by-ip'][$ip] = [ + 'time' => $time, + 'trials' => ($log['by-ip'][$ip]['trials'] ?? 0) + 1 + ]; + } else { + $log['by-ip'][$ip] = [ + 'time' => $time, + 'trials' => 1 + ]; + } + + if ($email !== null && $this->kirby->users()->find($email)) { + if (isset($log['by-email'][$email]) === true) { + $log['by-email'][$email] = [ + 'time' => $time, + 'trials' => ($log['by-email'][$email]['trials'] ?? 0) + 1 + ]; + } else { + $log['by-email'][$email] = [ + 'time' => $time, + 'trials' => 1 + ]; + } + } + + return Data::write($this->logfile(), $log, 'json'); + } + + /** + * Returns the current authentication type + * + * @param bool $allowImpersonation If set to false, 'impersonate' won't + * be returned as authentication type + * even if an impersonation is active + * @return string + */ + public function type(bool $allowImpersonation = true): string + { + $basicAuth = $this->kirby->option('api.basicAuth', false); + $auth = $this->kirby->request()->auth(); + + if ($basicAuth === true && $auth && $auth->type() === 'basic') { + return 'basic'; + } elseif ($allowImpersonation === true && $this->impersonate !== null) { + return 'impersonate'; + } else { + return 'session'; + } + } + + /** + * Validates the currently logged in user + * + * @param \Kirby\Session\Session|array|null $session + * @param bool $allowImpersonation If set to false, only the actually + * logged in user will be returned + * @return \Kirby\Cms\User|null + * + * @throws \Throwable If an authentication error occurred + */ + public function user($session = null, bool $allowImpersonation = true) + { + if ($allowImpersonation === true && $this->impersonate !== null) { + return $this->impersonate; + } + + // return from cache + if ($this->user === null) { + // throw the same Exception again if one was captured before + if ($this->userException !== null) { + throw $this->userException; + } + + return null; + } elseif ($this->user !== false) { + return $this->user; + } + + try { + if ($this->type() === 'basic') { + return $this->user = $this->currentUserFromBasicAuth(); + } else { + return $this->user = $this->currentUserFromSession($session); + } + } catch (Throwable $e) { + $this->user = null; + + // capture the Exception for future calls + $this->userException = $e; + + throw $e; + } + } + + /** + * Verifies an authentication code that was + * requested with the `createChallenge()` method; + * if successful, the user is automatically logged in + * @since 3.5.0 + * + * @param string $code User-provided auth code to verify + * @return \Kirby\Cms\User User object of the logged-in user + * + * @throws \Kirby\Exception\PermissionException If the rate limit was exceeded, the challenge timed out, the code + * is incorrect or if any other error occurred with debug mode off + * @throws \Kirby\Exception\NotFoundException If the user from the challenge doesn't exist + * @throws \Kirby\Exception\InvalidArgumentException If no authentication challenge is active + * @throws \Kirby\Exception\LogicException If the authentication challenge is invalid + */ + public function verifyChallenge(string $code) + { + try { + $session = $this->kirby->session(); + + // first check if we have an active challenge at all + $email = $session->get('kirby.challenge.email'); + $challenge = $session->get('kirby.challenge.type'); + if (is_string($email) !== true || is_string($challenge) !== true) { + throw new InvalidArgumentException('No authentication challenge is active'); + } + + $user = $this->kirby->users()->find($email); + if ($user === null) { + throw new NotFoundException([ + 'key' => 'user.notFound', + 'data' => [ + 'name' => $email + ] + ]); + } + + // rate-limiting + if ($this->isBlocked($email) === true) { + $this->kirby->trigger('user.login:failed', compact('email')); + throw new PermissionException('Rate limit exceeded'); + } + + // time-limiting + $timeout = $session->get('kirby.challenge.timeout'); + if ($timeout !== null && time() > $timeout) { + throw new PermissionException('Authentication challenge timeout'); + } + + if ( + isset(static::$challenges[$challenge]) === true && + class_exists(static::$challenges[$challenge]) === true && + is_subclass_of(static::$challenges[$challenge], 'Kirby\Cms\Auth\Challenge') === true + ) { + $class = static::$challenges[$challenge]; + if ($class::verify($user, $code) === true) { + $this->logout(); + $user->loginPasswordless(); + + // clear the status cache + $this->status = null; + + return $user; + } else { + throw new PermissionException(['key' => 'access.code']); + } + } + + throw new LogicException('Invalid authentication challenge: ' . $challenge); + } catch (Throwable $e) { + if (empty($email) === false && $e->getMessage() !== 'Rate limit exceeded') { + $this->track($email); + } + + // sleep for a random amount of milliseconds + // to make automated attacks harder and to + // avoid leaking whether the user exists + usleep(random_int(1000, 2000000)); + + // keep throwing the original error in debug mode, + // otherwise hide it to avoid leaking security-relevant information + if ($this->kirby->option('debug') === true) { + throw $e; + } else { + throw new PermissionException(['key' => 'access.code']); + } + } + } + + /** + * Creates a session object from the passed options + * + * @param \Kirby\Session\Session|array|null $session + * @return \Kirby\Session\Session + */ + protected function session($session = null) + { + // use passed session options or session object if set + if (is_array($session) === true) { + return $this->kirby->session($session); + } + + // try session in header or cookie + if (is_a($session, 'Kirby\Session\Session') === false) { + return $this->kirby->session(['detect' => true]); + } + + return $session; + } } diff --git a/kirby/src/Cms/Auth/Challenge.php b/kirby/src/Cms/Auth/Challenge.php index 49cb59f..69a7574 100755 --- a/kirby/src/Cms/Auth/Challenge.php +++ b/kirby/src/Cms/Auth/Challenge.php @@ -16,48 +16,48 @@ use Kirby\Cms\User; */ abstract class Challenge { - /** - * Checks whether the challenge is available - * for the passed user and purpose - * - * @param \Kirby\Cms\User $user User the code will be generated for - * @param string $mode Purpose of the code ('login', 'reset' or '2fa') - * @return bool - */ - abstract public static function isAvailable(User $user, string $mode): bool; + /** + * Checks whether the challenge is available + * for the passed user and purpose + * + * @param \Kirby\Cms\User $user User the code will be generated for + * @param string $mode Purpose of the code ('login', 'reset' or '2fa') + * @return bool + */ + abstract public static function isAvailable(User $user, string $mode): bool; - /** - * Generates a random one-time auth code and returns that code - * for later verification - * - * @param \Kirby\Cms\User $user User to generate the code for - * @param array $options Details of the challenge request: - * - 'mode': Purpose of the code ('login', 'reset' or '2fa') - * - 'timeout': Number of seconds the code will be valid for - * @return string|null The generated and sent code or `null` in case - * there was no code to generate by this algorithm - */ - abstract public static function create(User $user, array $options): ?string; + /** + * Generates a random one-time auth code and returns that code + * for later verification + * + * @param \Kirby\Cms\User $user User to generate the code for + * @param array $options Details of the challenge request: + * - 'mode': Purpose of the code ('login', 'reset' or '2fa') + * - 'timeout': Number of seconds the code will be valid for + * @return string|null The generated and sent code or `null` in case + * there was no code to generate by this algorithm + */ + abstract public static function create(User $user, array $options): ?string; - /** - * Verifies the provided code against the created one; - * default implementation that checks the code that was - * returned from the `create()` method - * - * @param \Kirby\Cms\User $user User to check the code for - * @param string $code Code to verify - * @return bool - */ - public static function verify(User $user, string $code): bool - { - $hash = $user->kirby()->session()->get('kirby.challenge.code'); - if (is_string($hash) !== true) { - return false; - } + /** + * Verifies the provided code against the created one; + * default implementation that checks the code that was + * returned from the `create()` method + * + * @param \Kirby\Cms\User $user User to check the code for + * @param string $code Code to verify + * @return bool + */ + public static function verify(User $user, string $code): bool + { + $hash = $user->kirby()->session()->get('kirby.challenge.code'); + if (is_string($hash) !== true) { + return false; + } - // normalize the formatting in the user-provided code - $code = str_replace(' ', '', $code); + // normalize the formatting in the user-provided code + $code = str_replace(' ', '', $code); - return password_verify($code, $hash); - } + return password_verify($code, $hash); + } } diff --git a/kirby/src/Cms/Auth/EmailChallenge.php b/kirby/src/Cms/Auth/EmailChallenge.php index 6c6cbe1..e0bcfbe 100755 --- a/kirby/src/Cms/Auth/EmailChallenge.php +++ b/kirby/src/Cms/Auth/EmailChallenge.php @@ -18,60 +18,60 @@ use Kirby\Toolkit\Str; */ class EmailChallenge extends Challenge { - /** - * Checks whether the challenge is available - * for the passed user and purpose - * - * @param \Kirby\Cms\User $user User the code will be generated for - * @param string $mode Purpose of the code ('login', 'reset' or '2fa') - * @return bool - */ - public static function isAvailable(User $user, string $mode): bool - { - return true; - } + /** + * Checks whether the challenge is available + * for the passed user and purpose + * + * @param \Kirby\Cms\User $user User the code will be generated for + * @param string $mode Purpose of the code ('login', 'reset' or '2fa') + * @return bool + */ + public static function isAvailable(User $user, string $mode): bool + { + return true; + } - /** - * Generates a random one-time auth code and returns that code - * for later verification - * - * @param \Kirby\Cms\User $user User to generate the code for - * @param array $options Details of the challenge request: - * - 'mode': Purpose of the code ('login', 'reset' or '2fa') - * - 'timeout': Number of seconds the code will be valid for - * @return string The generated and sent code - */ - public static function create(User $user, array $options): string - { - $code = Str::random(6, 'num'); + /** + * Generates a random one-time auth code and returns that code + * for later verification + * + * @param \Kirby\Cms\User $user User to generate the code for + * @param array $options Details of the challenge request: + * - 'mode': Purpose of the code ('login', 'reset' or '2fa') + * - 'timeout': Number of seconds the code will be valid for + * @return string The generated and sent code + */ + public static function create(User $user, array $options): string + { + $code = Str::random(6, 'num'); - // insert a space in the middle for easier readability - $formatted = substr($code, 0, 3) . ' ' . substr($code, 3, 3); + // insert a space in the middle for easier readability + $formatted = substr($code, 0, 3) . ' ' . substr($code, 3, 3); - // use the login templates for 2FA - $mode = $options['mode']; - if ($mode === '2fa') { - $mode = 'login'; - } + // use the login templates for 2FA + $mode = $options['mode']; + if ($mode === '2fa') { + $mode = 'login'; + } - $kirby = $user->kirby(); - $kirby->email([ - 'from' => $kirby->option('auth.challenge.email.from', 'noreply@' . $kirby->url('index', true)->host()), - 'fromName' => $kirby->option('auth.challenge.email.fromName', $kirby->site()->title()), - 'to' => $user, - 'subject' => $kirby->option( - 'auth.challenge.email.subject', - I18n::translate('login.email.' . $mode . '.subject', null, $user->language()) - ), - 'template' => 'auth/' . $mode, - 'data' => [ - 'user' => $user, - 'site' => $kirby->system()->title(), - 'code' => $formatted, - 'timeout' => round($options['timeout'] / 60) - ] - ]); + $kirby = $user->kirby(); + $kirby->email([ + 'from' => $kirby->option('auth.challenge.email.from', 'noreply@' . $kirby->url('index', true)->host()), + 'fromName' => $kirby->option('auth.challenge.email.fromName', $kirby->site()->title()), + 'to' => $user, + 'subject' => $kirby->option( + 'auth.challenge.email.subject', + I18n::translate('login.email.' . $mode . '.subject', null, $user->language()) + ), + 'template' => 'auth/' . $mode, + 'data' => [ + 'user' => $user, + 'site' => $kirby->system()->title(), + 'code' => $formatted, + 'timeout' => round($options['timeout'] / 60) + ] + ]); - return $code; - } + return $code; + } } diff --git a/kirby/src/Cms/Auth/Status.php b/kirby/src/Cms/Auth/Status.php index 7716b8a..43031c7 100755 --- a/kirby/src/Cms/Auth/Status.php +++ b/kirby/src/Cms/Auth/Status.php @@ -19,201 +19,201 @@ use Kirby\Toolkit\Properties; */ class Status { - use Properties; + use Properties; - /** - * Type of the active challenge - * - * @var string|null - */ - protected $challenge = null; + /** + * Type of the active challenge + * + * @var string|null + */ + protected $challenge = null; - /** - * Challenge type to use as a fallback - * when $challenge is `null` - * - * @var string|null - */ - protected $challengeFallback = null; + /** + * Challenge type to use as a fallback + * when $challenge is `null` + * + * @var string|null + */ + protected $challengeFallback = null; - /** - * Email address of the current/pending user - * - * @var string|null - */ - protected $email = null; + /** + * Email address of the current/pending user + * + * @var string|null + */ + protected $email = null; - /** - * Kirby instance for user lookup - * - * @var \Kirby\Cms\App - */ - protected $kirby; + /** + * Kirby instance for user lookup + * + * @var \Kirby\Cms\App + */ + protected $kirby; - /** - * Authentication status: - * `active|impersonated|pending|inactive` - * - * @var string - */ - protected $status; + /** + * Authentication status: + * `active|impersonated|pending|inactive` + * + * @var string + */ + protected $status; - /** - * Class constructor - * - * @param array $props - */ - public function __construct(array $props) - { - $this->setProperties($props); - } + /** + * Class constructor + * + * @param array $props + */ + public function __construct(array $props) + { + $this->setProperties($props); + } - /** - * Returns the authentication status - * - * @return string - */ - public function __toString(): string - { - return $this->status(); - } + /** + * Returns the authentication status + * + * @return string + */ + public function __toString(): string + { + return $this->status(); + } - /** - * Returns the type of the active challenge - * - * @param bool $automaticFallback If set to `false`, no faked challenge is returned; - * WARNING: never send the resulting `null` value to the - * user to avoid leaking whether the pending user exists - * @return string|null - */ - public function challenge(bool $automaticFallback = true): ?string - { - // never return a challenge type if the status doesn't match - if ($this->status() !== 'pending') { - return null; - } + /** + * Returns the type of the active challenge + * + * @param bool $automaticFallback If set to `false`, no faked challenge is returned; + * WARNING: never send the resulting `null` value to the + * user to avoid leaking whether the pending user exists + * @return string|null + */ + public function challenge(bool $automaticFallback = true): ?string + { + // never return a challenge type if the status doesn't match + if ($this->status() !== 'pending') { + return null; + } - if ($automaticFallback === false) { - return $this->challenge; - } else { - return $this->challenge ?? $this->challengeFallback; - } - } + if ($automaticFallback === false) { + return $this->challenge; + } else { + return $this->challenge ?? $this->challengeFallback; + } + } - /** - * Returns the email address of the current/pending user - * - * @return string|null - */ - public function email(): ?string - { - return $this->email; - } + /** + * Returns the email address of the current/pending user + * + * @return string|null + */ + public function email(): ?string + { + return $this->email; + } - /** - * Returns the authentication status - * - * @return string `active|impersonated|pending|inactive` - */ - public function status(): string - { - return $this->status; - } + /** + * Returns the authentication status + * + * @return string `active|impersonated|pending|inactive` + */ + public function status(): string + { + return $this->status; + } - /** - * Returns an array with all public status data - * - * @return array - */ - public function toArray(): array - { - return [ - 'challenge' => $this->challenge(), - 'email' => $this->email(), - 'status' => $this->status() - ]; - } + /** + * Returns an array with all public status data + * + * @return array + */ + public function toArray(): array + { + return [ + 'challenge' => $this->challenge(), + 'email' => $this->email(), + 'status' => $this->status() + ]; + } - /** - * Returns the currently logged in user - * - * @return \Kirby\Cms\User - */ - public function user() - { - // for security, only return the user if they are - // already logged in - if (in_array($this->status(), ['active', 'impersonated']) !== true) { - return null; - } + /** + * Returns the currently logged in user + * + * @return \Kirby\Cms\User + */ + public function user() + { + // for security, only return the user if they are + // already logged in + if (in_array($this->status(), ['active', 'impersonated']) !== true) { + return null; + } - return $this->kirby->user($this->email()); - } + return $this->kirby->user($this->email()); + } - /** - * Sets the type of the active challenge - * - * @param string|null $challenge - * @return $this - */ - protected function setChallenge(?string $challenge = null) - { - $this->challenge = $challenge; - return $this; - } + /** + * Sets the type of the active challenge + * + * @param string|null $challenge + * @return $this + */ + protected function setChallenge(?string $challenge = null) + { + $this->challenge = $challenge; + return $this; + } - /** - * Sets the challenge type to use as - * a fallback when $challenge is `null` - * - * @param string|null $challengeFallback - * @return $this - */ - protected function setChallengeFallback(?string $challengeFallback = null) - { - $this->challengeFallback = $challengeFallback; - return $this; - } + /** + * Sets the challenge type to use as + * a fallback when $challenge is `null` + * + * @param string|null $challengeFallback + * @return $this + */ + protected function setChallengeFallback(?string $challengeFallback = null) + { + $this->challengeFallback = $challengeFallback; + return $this; + } - /** - * Sets the email address of the current/pending user - * - * @param string|null $email - * @return $this - */ - protected function setEmail(?string $email = null) - { - $this->email = $email; - return $this; - } + /** + * Sets the email address of the current/pending user + * + * @param string|null $email + * @return $this + */ + protected function setEmail(?string $email = null) + { + $this->email = $email; + return $this; + } - /** - * Sets the Kirby instance for user lookup - * - * @param \Kirby\Cms\App $kirby - * @return $this - */ - protected function setKirby(App $kirby) - { - $this->kirby = $kirby; - return $this; - } + /** + * Sets the Kirby instance for user lookup + * + * @param \Kirby\Cms\App $kirby + * @return $this + */ + protected function setKirby(App $kirby) + { + $this->kirby = $kirby; + return $this; + } - /** - * Sets the authentication status - * - * @param string $status `active|impersonated|pending|inactive` - * @return $this - */ - protected function setStatus(string $status) - { - if (in_array($status, ['active', 'impersonated', 'pending', 'inactive']) !== true) { - throw new InvalidArgumentException([ - 'data' => ['argument' => '$props[\'status\']', 'method' => 'Status::__construct'] - ]); - } + /** + * Sets the authentication status + * + * @param string $status `active|impersonated|pending|inactive` + * @return $this + */ + protected function setStatus(string $status) + { + if (in_array($status, ['active', 'impersonated', 'pending', 'inactive']) !== true) { + throw new InvalidArgumentException([ + 'data' => ['argument' => '$props[\'status\']', 'method' => 'Status::__construct'] + ]); + } - $this->status = $status; - return $this; - } + $this->status = $status; + return $this; + } } diff --git a/kirby/src/Cms/Block.php b/kirby/src/Cms/Block.php index 4310f0b..0096384 100755 --- a/kirby/src/Cms/Block.php +++ b/kirby/src/Cms/Block.php @@ -20,242 +20,246 @@ use Throwable; */ class Block extends Item { - use HasMethods; + use HasMethods; - public const ITEMS_CLASS = '\Kirby\Cms\Blocks'; + public const ITEMS_CLASS = '\Kirby\Cms\Blocks'; - /** - * @var \Kirby\Cms\Content - */ - protected $content; + /** + * @var \Kirby\Cms\Content + */ + protected $content; - /** - * @var bool - */ - protected $isHidden; + /** + * @var bool + */ + protected $isHidden; - /** - * Registry with all block models - * - * @var array - */ - public static $models = []; + /** + * Registry with all block models + * + * @var array + */ + public static $models = []; - /** - * @var string - */ - protected $type; + /** + * @var string + */ + protected $type; - /** - * Proxy for content fields - * - * @param string $method - * @param array $args - * @return \Kirby\Cms\Field - */ - public function __call(string $method, array $args = []) - { - // block methods - if ($this->hasMethod($method)) { - return $this->callMethod($method, $args); - } + /** + * Proxy for content fields + * + * @param string $method + * @param array $args + * @return \Kirby\Cms\Field + */ + public function __call(string $method, array $args = []) + { + // block methods + if ($this->hasMethod($method)) { + return $this->callMethod($method, $args); + } - return $this->content()->get($method); - } + return $this->content()->get($method); + } - /** - * Creates a new block object - * - * @param array $params - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function __construct(array $params) - { - parent::__construct($params); + /** + * Creates a new block object + * + * @param array $params + * @throws \Kirby\Exception\InvalidArgumentException + */ + public function __construct(array $params) + { + parent::__construct($params); - if (isset($params['type']) === false) { - throw new InvalidArgumentException('The block type is missing'); - } + if (isset($params['type']) === false) { + throw new InvalidArgumentException('The block type is missing'); + } - // make sure the content is always defined as array to keep - // at least a bit of backward compatibility with older fields - if (is_array($params['content'] ?? null) === false) { - $params['content'] = []; - } + // make sure the content is always defined as array to keep + // at least a bit of backward compatibility with older fields + if (is_array($params['content'] ?? null) === false) { + $params['content'] = []; + } - $this->content = $params['content']; - $this->isHidden = $params['isHidden'] ?? false; - $this->type = $params['type']; + $this->content = $params['content']; + $this->isHidden = $params['isHidden'] ?? false; + $this->type = $params['type']; - // create the content object - $this->content = new Content($this->content, $this->parent); - } + // create the content object + $this->content = new Content($this->content, $this->parent); + } - /** - * Converts the object to a string - * - * @return string - */ - public function __toString(): string - { - return $this->toHtml(); - } + /** + * Converts the object to a string + * + * @return string + */ + public function __toString(): string + { + return $this->toHtml(); + } - /** - * Returns the content object - * - * @return \Kirby\Cms\Content - */ - public function content() - { - return $this->content; - } + /** + * Returns the content object + * + * @return \Kirby\Cms\Content + */ + public function content() + { + return $this->content; + } - /** - * Controller for the block snippet - * - * @return array - */ - public function controller(): array - { - return [ - 'block' => $this, - 'content' => $this->content(), - // deprecated block data - 'data' => $this, - 'id' => $this->id(), - 'prev' => $this->prev(), - 'next' => $this->next() - ]; - } + /** + * Controller for the block snippet + * + * @return array + */ + public function controller(): array + { + return [ + 'block' => $this, + 'content' => $this->content(), + // deprecated block data + 'data' => $this, + 'id' => $this->id(), + 'prev' => $this->prev(), + 'next' => $this->next() + ]; + } - /** - * Converts the block to HTML and then - * uses the Str::excerpt method to create - * a non-formatted, shortened excerpt from it - * - * @param mixed ...$args - * @return string - */ - public function excerpt(...$args) - { - return Str::excerpt($this->toHtml(), ...$args); - } + /** + * Converts the block to HTML and then + * uses the Str::excerpt method to create + * a non-formatted, shortened excerpt from it + * + * @param mixed ...$args + * @return string + */ + public function excerpt(...$args) + { + return Str::excerpt($this->toHtml(), ...$args); + } - /** - * Constructs a block object with registering blocks models - * - * @param array $params - * @return static - * @throws \Kirby\Exception\InvalidArgumentException - * @internal - */ - public static function factory(array $params) - { - $type = $params['type'] ?? null; + /** + * Constructs a block object with registering blocks models + * + * @param array $params + * @return static + * @throws \Kirby\Exception\InvalidArgumentException + * @internal + */ + public static function factory(array $params) + { + $type = $params['type'] ?? null; - if (empty($type) === false && $class = (static::$models[$type] ?? null)) { - $object = new $class($params); + if (empty($type) === false && $class = (static::$models[$type] ?? null)) { + $object = new $class($params); - if (is_a($object, 'Kirby\Cms\Block') === true) { - return $object; - } - } + if (is_a($object, 'Kirby\Cms\Block') === true) { + return $object; + } + } - // default model for blocks - if ($class = (static::$models['Kirby\Cms\Block'] ?? null)) { - $object = new $class($params); + // default model for blocks + if ($class = (static::$models['Kirby\Cms\Block'] ?? null)) { + $object = new $class($params); - if (is_a($object, 'Kirby\Cms\Block') === true) { - return $object; - } - } + if (is_a($object, 'Kirby\Cms\Block') === true) { + return $object; + } + } - return new static($params); - } + return new static($params); + } - /** - * Checks if the block is empty - * - * @return bool - */ - public function isEmpty(): bool - { - return empty($this->content()->toArray()); - } + /** + * Checks if the block is empty + * + * @return bool + */ + public function isEmpty(): bool + { + return empty($this->content()->toArray()); + } - /** - * Checks if the block is hidden - * from being rendered in the frontend - * - * @return bool - */ - public function isHidden(): bool - { - return $this->isHidden; - } + /** + * Checks if the block is hidden + * from being rendered in the frontend + * + * @return bool + */ + public function isHidden(): bool + { + return $this->isHidden; + } - /** - * Checks if the block is not empty - * - * @return bool - */ - public function isNotEmpty(): bool - { - return $this->isEmpty() === false; - } + /** + * Checks if the block is not empty + * + * @return bool + */ + public function isNotEmpty(): bool + { + return $this->isEmpty() === false; + } - /** - * Returns the block type - * - * @return string - */ - public function type(): string - { - return $this->type; - } + /** + * Returns the block type + * + * @return string + */ + public function type(): string + { + return $this->type; + } - /** - * The result is being sent to the editor - * via the API in the panel - * - * @return array - */ - public function toArray(): array - { - return [ - 'content' => $this->content()->toArray(), - 'id' => $this->id(), - 'isHidden' => $this->isHidden(), - 'type' => $this->type(), - ]; - } + /** + * The result is being sent to the editor + * via the API in the panel + * + * @return array + */ + public function toArray(): array + { + return [ + 'content' => $this->content()->toArray(), + 'id' => $this->id(), + 'isHidden' => $this->isHidden(), + 'type' => $this->type(), + ]; + } - /** - * Converts the block to html first - * and then places that inside a field - * object. This can be used further - * with all available field methods - * - * @return \Kirby\Cms\Field - */ - public function toField() - { - return new Field($this->parent(), $this->id(), $this->toHtml()); - } + /** + * Converts the block to html first + * and then places that inside a field + * object. This can be used further + * with all available field methods + * + * @return \Kirby\Cms\Field + */ + public function toField() + { + return new Field($this->parent(), $this->id(), $this->toHtml()); + } - /** - * Converts the block to HTML - * - * @return string - */ - public function toHtml(): string - { - try { - $kirby = $this->parent()->kirby(); - return (string)$kirby->snippet('blocks/' . $this->type(), $this->controller(), true); - } catch (Throwable $e) { - return '

Block error: "' . $e->getMessage() . '" in block type: "' . $this->type() . '"

'; - } - } + /** + * Converts the block to HTML + * + * @return string + */ + public function toHtml(): string + { + try { + $kirby = $this->parent()->kirby(); + return (string)$kirby->snippet('blocks/' . $this->type(), $this->controller(), true); + } catch (Throwable $e) { + if ($kirby->option('debug') === true) { + return '

Block error: "' . $e->getMessage() . '" in block type: "' . $this->type() . '"

'; + } + + return ''; + } + } } diff --git a/kirby/src/Cms/Blocks.php b/kirby/src/Cms/Blocks.php index 3d2fbfb..49589ec 100755 --- a/kirby/src/Cms/Blocks.php +++ b/kirby/src/Cms/Blocks.php @@ -20,126 +20,126 @@ use Throwable; */ class Blocks extends Items { - public const ITEM_CLASS = '\Kirby\Cms\Block'; + public const ITEM_CLASS = '\Kirby\Cms\Block'; - /** - * Return HTML when the collection is - * converted to a string - * - * @return string - */ - public function __toString(): string - { - return $this->toHtml(); - } + /** + * Return HTML when the collection is + * converted to a string + * + * @return string + */ + public function __toString(): string + { + return $this->toHtml(); + } - /** - * Converts the blocks to HTML and then - * uses the Str::excerpt method to create - * a non-formatted, shortened excerpt from it - * - * @param mixed ...$args - * @return string - */ - public function excerpt(...$args) - { - return Str::excerpt($this->toHtml(), ...$args); - } + /** + * Converts the blocks to HTML and then + * uses the Str::excerpt method to create + * a non-formatted, shortened excerpt from it + * + * @param mixed ...$args + * @return string + */ + public function excerpt(...$args) + { + return Str::excerpt($this->toHtml(), ...$args); + } - /** - * Wrapper around the factory to - * catch blocks from layouts - * - * @param array $items - * @param array $params - * @return \Kirby\Cms\Blocks - */ - public static function factory(array $items = null, array $params = []) - { - $items = static::extractFromLayouts($items); + /** + * Wrapper around the factory to + * catch blocks from layouts + * + * @param array $items + * @param array $params + * @return \Kirby\Cms\Blocks + */ + public static function factory(array $items = null, array $params = []) + { + $items = static::extractFromLayouts($items); - return parent::factory($items, $params); - } + return parent::factory($items, $params); + } - /** - * Pull out blocks from layouts - * - * @param array $input - * @return array - */ - protected static function extractFromLayouts(array $input): array - { - if (empty($input) === true) { - return []; - } + /** + * Pull out blocks from layouts + * + * @param array $input + * @return array + */ + protected static function extractFromLayouts(array $input): array + { + if (empty($input) === true) { + return []; + } - // no columns = no layout - if (array_key_exists('columns', $input[0]) === false) { - return $input; - } + // no columns = no layout + if (array_key_exists('columns', $input[0]) === false) { + return $input; + } - $blocks = []; + $blocks = []; - foreach ($input as $layout) { - foreach (($layout['columns'] ?? []) as $column) { - foreach (($column['blocks'] ?? []) as $block) { - $blocks[] = $block; - } - } - } + foreach ($input as $layout) { + foreach (($layout['columns'] ?? []) as $column) { + foreach (($column['blocks'] ?? []) as $block) { + $blocks[] = $block; + } + } + } - return $blocks; - } + return $blocks; + } - /** - * Checks if a given block type exists in the collection - * @since 3.6.0 - * - * @param string $type - * @return bool - */ - public function hasType(string $type): bool - { - return $this->filterBy('type', $type)->count() > 0; - } + /** + * Checks if a given block type exists in the collection + * @since 3.6.0 + * + * @param string $type + * @return bool + */ + public function hasType(string $type): bool + { + return $this->filterBy('type', $type)->count() > 0; + } - /** - * Parse and sanitize various block formats - * - * @param array|string $input - * @return array - */ - public static function parse($input): array - { - if (empty($input) === false && is_array($input) === false) { - try { - $input = Json::decode((string)$input); - } catch (Throwable $e) { - $parser = new Parsley((string)$input, new BlockSchema()); - $input = $parser->blocks(); - } - } + /** + * Parse and sanitize various block formats + * + * @param array|string $input + * @return array + */ + public static function parse($input): array + { + if (empty($input) === false && is_array($input) === false) { + try { + $input = Json::decode((string)$input); + } catch (Throwable $e) { + $parser = new Parsley((string)$input, new BlockSchema()); + $input = $parser->blocks(); + } + } - if (empty($input) === true) { - return []; - } + if (empty($input) === true) { + return []; + } - return $input; - } + return $input; + } - /** - * Convert all blocks to HTML - * - * @return string - */ - public function toHtml(): string - { - $html = []; + /** + * Convert all blocks to HTML + * + * @return string + */ + public function toHtml(): string + { + $html = []; - foreach ($this->data as $block) { - $html[] = $block->toHtml(); - } + foreach ($this->data as $block) { + $html[] = $block->toHtml(); + } - return implode($html); - } + return implode($html); + } } diff --git a/kirby/src/Cms/Blueprint.php b/kirby/src/Cms/Blueprint.php index 681aa71..bb3f3c1 100755 --- a/kirby/src/Cms/Blueprint.php +++ b/kirby/src/Cms/Blueprint.php @@ -25,797 +25,797 @@ use Throwable; */ class Blueprint { - public static $presets = []; - public static $loaded = []; - - protected $fields = []; - protected $model; - protected $props; - protected $sections = []; - protected $tabs = []; - - /** - * Magic getter/caller for any blueprint prop - * - * @param string $key - * @param array|null $arguments - * @return mixed - */ - public function __call(string $key, array $arguments = null) - { - return $this->props[$key] ?? null; - } - - /** - * Creates a new blueprint object with the given props - * - * @param array $props - * @throws \Kirby\Exception\InvalidArgumentException If the blueprint model is missing - */ - public function __construct(array $props) - { - if (empty($props['model']) === true) { - throw new InvalidArgumentException('A blueprint model is required'); - } - - if (is_a($props['model'], ModelWithContent::class) === false) { - throw new InvalidArgumentException('Invalid blueprint model'); - } - - $this->model = $props['model']; - - // the model should not be included in the props array - unset($props['model']); - - // extend the blueprint in general - $props = $this->extend($props); - - // apply any blueprint preset - $props = $this->preset($props); - - // normalize the name - $props['name'] ??= 'default'; - - // normalize and translate the title - $props['title'] = $this->i18n($props['title'] ?? ucfirst($props['name'])); - - // convert all shortcuts - $props = $this->convertFieldsToSections('main', $props); - $props = $this->convertSectionsToColumns('main', $props); - $props = $this->convertColumnsToTabs('main', $props); - - // normalize all tabs - $props['tabs'] = $this->normalizeTabs($props['tabs'] ?? []); - - $this->props = $props; - } - - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return $this->props ?? []; - } - - /** - * Converts all column definitions, that - * are not wrapped in a tab, into a generic tab - * - * @param string $tabName - * @param array $props - * @return array - */ - protected function convertColumnsToTabs(string $tabName, array $props): array - { - if (isset($props['columns']) === false) { - return $props; - } - - // wrap everything in a main tab - $props['tabs'] = [ - $tabName => [ - 'columns' => $props['columns'] - ] - ]; - - unset($props['columns']); - - return $props; - } - - /** - * Converts all field definitions, that are not - * wrapped in a fields section into a generic - * fields section. - * - * @param string $tabName - * @param array $props - * @return array - */ - protected function convertFieldsToSections(string $tabName, array $props): array - { - if (isset($props['fields']) === false) { - return $props; - } - - // wrap all fields in a section - $props['sections'] = [ - $tabName . '-fields' => [ - 'type' => 'fields', - 'fields' => $props['fields'] - ] - ]; - - unset($props['fields']); - - return $props; - } - - /** - * Converts all sections that are not wrapped in - * columns, into a single generic column. - * - * @param string $tabName - * @param array $props - * @return array - */ - protected function convertSectionsToColumns(string $tabName, array $props): array - { - if (isset($props['sections']) === false) { - return $props; - } - - // wrap everything in one big column - $props['columns'] = [ - [ - 'width' => '1/1', - 'sections' => $props['sections'] - ] - ]; - - unset($props['sections']); - - return $props; - } - - /** - * Extends the props with props from a given - * mixin, when an extends key is set or the - * props is just a string - * - * @param array|string $props - * @return array - */ - public static function extend($props): array - { - if (is_string($props) === true) { - $props = [ - 'extends' => $props - ]; - } - - $extends = $props['extends'] ?? null; - - if ($extends === null) { - return $props; - } - - foreach (A::wrap($extends) as $extend) { - try { - $mixin = static::find($extend); - $mixin = static::extend($mixin); - $props = A::merge($mixin, $props, A::MERGE_REPLACE); - } catch (Exception $e) { - // keep the props unextended if the snippet wasn't found - } - } - - // remove the extends flag - unset($props['extends']); - - return $props; - } - - /** - * Create a new blueprint for a model - * - * @param string $name - * @param string|null $fallback - * @param \Kirby\Cms\Model $model - * @return static|null - */ - public static function factory(string $name, string $fallback = null, Model $model) - { - try { - $props = static::load($name); - } catch (Exception $e) { - $props = $fallback !== null ? static::load($fallback) : null; - } - - if ($props === null) { - return null; - } - - // inject the parent model - $props['model'] = $model; - - return new static($props); - } - - /** - * Returns a single field definition by name - * - * @param string $name - * @return array|null - */ - public function field(string $name): ?array - { - return $this->fields[$name] ?? null; - } - - /** - * Returns all field definitions - * - * @return array - */ - public function fields(): array - { - return $this->fields; - } - - /** - * Find a blueprint by name - * - * @param string $name - * @return array - * @throws \Kirby\Exception\NotFoundException If the blueprint cannot be found - */ - public static function find(string $name): array - { - if (isset(static::$loaded[$name]) === true) { - return static::$loaded[$name]; - } - - $kirby = App::instance(); - $root = $kirby->root('blueprints'); - $file = $root . '/' . $name . '.yml'; - - // first try to find a site blueprint, - // then check in the plugin extensions - if (F::exists($file, $root) !== true) { - $file = $kirby->extension('blueprints', $name); - } - - // callback option can be return array or blueprint file path - if (is_callable($file) === true) { - $file = $file($kirby); - } - - // now ensure that we always return the data array - if (is_string($file) === true && F::exists($file) === true) { - return static::$loaded[$name] = Data::read($file); - } elseif (is_array($file) === true) { - return static::$loaded[$name] = $file; - } - - // neither a valid file nor array data - throw new NotFoundException([ - 'key' => 'blueprint.notFound', - 'data' => ['name' => $name] - ]); - } - - /** - * Used to translate any label, heading, etc. - * - * @param mixed $value - * @param mixed $fallback - * @return mixed - */ - protected function i18n($value, $fallback = null) - { - return I18n::translate($value, $fallback ?? $value); - } - - /** - * Checks if this is the default blueprint - * - * @return bool - */ - public function isDefault(): bool - { - return $this->name() === 'default'; - } - - /** - * Loads a blueprint from file or array - * - * @param string $name - * @return array - */ - public static function load(string $name): array - { - $props = static::find($name); - - $normalize = function ($props) use ($name) { - // inject the filename as name if no name is set - $props['name'] ??= $name; - - // normalize the title - $title = $props['title'] ?? ucfirst($props['name']); - - // translate the title - $props['title'] = I18n::translate($title, $title); - - return $props; - }; - - return $normalize($props); - } - - /** - * Returns the parent model - * - * @return \Kirby\Cms\Model - */ - public function model() - { - return $this->model; - } - - /** - * Returns the blueprint name - * - * @return string - */ - public function name(): string - { - return $this->props['name']; - } - - /** - * Normalizes all required props in a column setup - * - * @param string $tabName - * @param array $columns - * @return array - */ - protected function normalizeColumns(string $tabName, array $columns): array - { - foreach ($columns as $columnKey => $columnProps) { - // unset/remove column if its property is not array - if (is_array($columnProps) === false) { - unset($columns[$columnKey]); - continue; - } - - $columnProps = $this->convertFieldsToSections($tabName . '-col-' . $columnKey, $columnProps); - - // inject getting started info, if the sections are empty - if (empty($columnProps['sections']) === true) { - $columnProps['sections'] = [ - $tabName . '-info-' . $columnKey => [ - 'headline' => 'Column (' . ($columnProps['width'] ?? '1/1') . ')', - 'type' => 'info', - 'text' => 'No sections yet' - ] - ]; - } - - $columns[$columnKey] = array_merge($columnProps, [ - 'width' => $columnProps['width'] ?? '1/1', - 'sections' => $this->normalizeSections($tabName, $columnProps['sections'] ?? []) - ]); - } - - return $columns; - } - - /** - * @param array $items - * @return string - */ - public static function helpList(array $items): string - { - $md = []; - - foreach ($items as $item) { - $md[] = '- *' . $item . '*'; - } - - return PHP_EOL . implode(PHP_EOL, $md); - } - - /** - * Normalize field props for a single field - * - * @param array|string $props - * @return array - * @throws \Kirby\Exception\InvalidArgumentException If the filed name is missing or the field type is invalid - */ - public static function fieldProps($props): array - { - $props = static::extend($props); - - if (isset($props['name']) === false) { - throw new InvalidArgumentException('The field name is missing'); - } - - $name = $props['name']; - $type = $props['type'] ?? $name; - - if ($type !== 'group' && isset(Field::$types[$type]) === false) { - throw new InvalidArgumentException('Invalid field type ("' . $type . '")'); - } - - // support for nested fields - if (isset($props['fields']) === true) { - $props['fields'] = static::fieldsProps($props['fields']); - } - - // groups don't need all the crap - if ($type === 'group') { - return [ - 'fields' => $props['fields'], - 'name' => $name, - 'type' => $type, - ]; - } - - // add some useful defaults - return array_merge($props, [ - 'label' => $props['label'] ?? ucfirst($name), - 'name' => $name, - 'type' => $type, - 'width' => $props['width'] ?? '1/1', - ]); - } - - /** - * Creates an error field with the given error message - * - * @param string $name - * @param string $message - * @return array - */ - public static function fieldError(string $name, string $message): array - { - return [ - 'label' => 'Error', - 'name' => $name, - 'text' => strip_tags($message), - 'theme' => 'negative', - 'type' => 'info', - ]; - } - - /** - * Normalizes all fields and adds automatic labels, - * types and widths. - * - * @param array $fields - * @return array - */ - public static function fieldsProps($fields): array - { - if (is_array($fields) === false) { - $fields = []; - } - - foreach ($fields as $fieldName => $fieldProps) { - - // extend field from string - if (is_string($fieldProps) === true) { - $fieldProps = [ - 'extends' => $fieldProps, - 'name' => $fieldName - ]; - } - - // use the name as type definition - if ($fieldProps === true) { - $fieldProps = []; - } - - // unset / remove field if its property is false - if ($fieldProps === false) { - unset($fields[$fieldName]); - continue; - } - - // inject the name - $fieldProps['name'] = $fieldName; - - // create all props - try { - $fieldProps = static::fieldProps($fieldProps); - } catch (Throwable $e) { - $fieldProps = static::fieldError($fieldName, $e->getMessage()); - } - - // resolve field groups - if ($fieldProps['type'] === 'group') { - if (empty($fieldProps['fields']) === false && is_array($fieldProps['fields']) === true) { - $index = array_search($fieldName, array_keys($fields)); - $before = array_slice($fields, 0, $index); - $after = array_slice($fields, $index + 1); - $fields = array_merge($before, $fieldProps['fields'] ?? [], $after); - } else { - unset($fields[$fieldName]); - } - } else { - $fields[$fieldName] = $fieldProps; - } - } - - return $fields; - } - - /** - * Normalizes blueprint options. This must be used in the - * constructor of an extended class, if you want to make use of it. - * - * @param array|true|false|null|string $options - * @param array $defaults - * @param array $aliases - * @return array - */ - protected function normalizeOptions($options, array $defaults, array $aliases = []): array - { - // return defaults when options are not defined or set to true - if ($options === true) { - return $defaults; - } - - // set all options to false - if ($options === false) { - return array_map(fn () => false, $defaults); - } - - // extend options if possible - $options = $this->extend($options); - - foreach ($options as $key => $value) { - $alias = $aliases[$key] ?? null; - - if ($alias !== null) { - $options[$alias] ??= $value; - unset($options[$key]); - } - } - - return array_merge($defaults, $options); - } - - /** - * Normalizes all required keys in sections - * - * @param string $tabName - * @param array $sections - * @return array - */ - protected function normalizeSections(string $tabName, array $sections): array - { - foreach ($sections as $sectionName => $sectionProps) { - - // unset / remove section if its property is false - if ($sectionProps === false) { - unset($sections[$sectionName]); - continue; - } - - // fallback to default props when true is passed - if ($sectionProps === true) { - $sectionProps = []; - } - - // inject all section extensions - $sectionProps = $this->extend($sectionProps); - - $sections[$sectionName] = $sectionProps = array_merge($sectionProps, [ - 'name' => $sectionName, - 'type' => $type = $sectionProps['type'] ?? $sectionName - ]); - - if (empty($type) === true || is_string($type) === false) { - $sections[$sectionName] = [ - 'name' => $sectionName, - 'headline' => 'Invalid section type for section "' . $sectionName . '"', - 'type' => 'info', - 'text' => 'The following section types are available: ' . $this->helpList(array_keys(Section::$types)) - ]; - } elseif (isset(Section::$types[$type]) === false) { - $sections[$sectionName] = [ - 'name' => $sectionName, - 'headline' => 'Invalid section type ("' . $type . '")', - 'type' => 'info', - 'text' => 'The following section types are available: ' . $this->helpList(array_keys(Section::$types)) - ]; - } - - if ($sectionProps['type'] === 'fields') { - $fields = Blueprint::fieldsProps($sectionProps['fields'] ?? []); - - // inject guide fields guide - if (empty($fields) === true) { - $fields = [ - $tabName . '-info' => [ - 'label' => 'Fields', - 'text' => 'No fields yet', - 'type' => 'info' - ] - ]; - } else { - foreach ($fields as $fieldName => $fieldProps) { - if (isset($this->fields[$fieldName]) === true) { - $this->fields[$fieldName] = $fields[$fieldName] = [ - 'type' => 'info', - 'label' => $fieldProps['label'] ?? 'Error', - 'text' => 'The field name "' . $fieldName . '" already exists in your blueprint.', - 'theme' => 'negative' - ]; - } else { - $this->fields[$fieldName] = $fieldProps; - } - } - } - - $sections[$sectionName]['fields'] = $fields; - } - } - - // store all normalized sections - $this->sections = array_merge($this->sections, $sections); - - return $sections; - } - - /** - * Normalizes all required keys in tabs - * - * @param array $tabs - * @return array - */ - protected function normalizeTabs($tabs): array - { - if (is_array($tabs) === false) { - $tabs = []; - } - - foreach ($tabs as $tabName => $tabProps) { - - // unset / remove tab if its property is false - if ($tabProps === false) { - unset($tabs[$tabName]); - continue; - } - - // inject all tab extensions - $tabProps = $this->extend($tabProps); - - // inject a preset if available - $tabProps = $this->preset($tabProps); - - $tabProps = $this->convertFieldsToSections($tabName, $tabProps); - $tabProps = $this->convertSectionsToColumns($tabName, $tabProps); - - $tabs[$tabName] = array_merge($tabProps, [ - 'columns' => $this->normalizeColumns($tabName, $tabProps['columns'] ?? []), - 'icon' => $tabProps['icon'] ?? null, - 'label' => $this->i18n($tabProps['label'] ?? ucfirst($tabName)), - 'link' => $this->model->panel()->url(true) . '/?tab=' . $tabName, - 'name' => $tabName, - ]); - } - - return $this->tabs = $tabs; - } - - /** - * Injects a blueprint preset - * - * @param array $props - * @return array - */ - protected function preset(array $props): array - { - if (isset($props['preset']) === false) { - return $props; - } - - if (isset(static::$presets[$props['preset']]) === false) { - return $props; - } - - $preset = static::$presets[$props['preset']]; - - if (is_string($preset) === true) { - $preset = require $preset; - } - - return $preset($props); - } - - /** - * Returns a single section by name - * - * @param string $name - * @return \Kirby\Cms\Section|null - */ - public function section(string $name) - { - if (empty($this->sections[$name]) === true) { - return null; - } - - // get all props - $props = $this->sections[$name]; - - // inject the blueprint model - $props['model'] = $this->model(); - - // create a new section object - return new Section($props['type'], $props); - } - - /** - * Returns all sections - * - * @return array - */ - public function sections(): array - { - return A::map( - $this->sections, - fn ($section) => $this->section($section['name']) - ); - } - - /** - * Returns a single tab by name - * - * @param string|null $name - * @return array|null - */ - public function tab(?string $name = null): ?array - { - if ($name === null) { - return A::first($this->tabs); - } - - return $this->tabs[$name] ?? null; - } - - /** - * Returns all tabs - * - * @return array - */ - public function tabs(): array - { - return array_values($this->tabs); - } - - /** - * Returns the blueprint title - * - * @return string - */ - public function title(): string - { - return $this->props['title']; - } - - /** - * Converts the blueprint object to a plain array - * - * @return array - */ - public function toArray(): array - { - return $this->props; - } + public static $presets = []; + public static $loaded = []; + + protected $fields = []; + protected $model; + protected $props; + protected $sections = []; + protected $tabs = []; + + /** + * Magic getter/caller for any blueprint prop + * + * @param string $key + * @param array|null $arguments + * @return mixed + */ + public function __call(string $key, array $arguments = null) + { + return $this->props[$key] ?? null; + } + + /** + * Creates a new blueprint object with the given props + * + * @param array $props + * @throws \Kirby\Exception\InvalidArgumentException If the blueprint model is missing + */ + public function __construct(array $props) + { + if (empty($props['model']) === true) { + throw new InvalidArgumentException('A blueprint model is required'); + } + + if (is_a($props['model'], ModelWithContent::class) === false) { + throw new InvalidArgumentException('Invalid blueprint model'); + } + + $this->model = $props['model']; + + // the model should not be included in the props array + unset($props['model']); + + // extend the blueprint in general + $props = $this->extend($props); + + // apply any blueprint preset + $props = $this->preset($props); + + // normalize the name + $props['name'] ??= 'default'; + + // normalize and translate the title + $props['title'] = $this->i18n($props['title'] ?? ucfirst($props['name'])); + + // convert all shortcuts + $props = $this->convertFieldsToSections('main', $props); + $props = $this->convertSectionsToColumns('main', $props); + $props = $this->convertColumnsToTabs('main', $props); + + // normalize all tabs + $props['tabs'] = $this->normalizeTabs($props['tabs'] ?? []); + + $this->props = $props; + } + + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return $this->props ?? []; + } + + /** + * Converts all column definitions, that + * are not wrapped in a tab, into a generic tab + * + * @param string $tabName + * @param array $props + * @return array + */ + protected function convertColumnsToTabs(string $tabName, array $props): array + { + if (isset($props['columns']) === false) { + return $props; + } + + // wrap everything in a main tab + $props['tabs'] = [ + $tabName => [ + 'columns' => $props['columns'] + ] + ]; + + unset($props['columns']); + + return $props; + } + + /** + * Converts all field definitions, that are not + * wrapped in a fields section into a generic + * fields section. + * + * @param string $tabName + * @param array $props + * @return array + */ + protected function convertFieldsToSections(string $tabName, array $props): array + { + if (isset($props['fields']) === false) { + return $props; + } + + // wrap all fields in a section + $props['sections'] = [ + $tabName . '-fields' => [ + 'type' => 'fields', + 'fields' => $props['fields'] + ] + ]; + + unset($props['fields']); + + return $props; + } + + /** + * Converts all sections that are not wrapped in + * columns, into a single generic column. + * + * @param string $tabName + * @param array $props + * @return array + */ + protected function convertSectionsToColumns(string $tabName, array $props): array + { + if (isset($props['sections']) === false) { + return $props; + } + + // wrap everything in one big column + $props['columns'] = [ + [ + 'width' => '1/1', + 'sections' => $props['sections'] + ] + ]; + + unset($props['sections']); + + return $props; + } + + /** + * Extends the props with props from a given + * mixin, when an extends key is set or the + * props is just a string + * + * @param array|string $props + * @return array + */ + public static function extend($props): array + { + if (is_string($props) === true) { + $props = [ + 'extends' => $props + ]; + } + + $extends = $props['extends'] ?? null; + + if ($extends === null) { + return $props; + } + + foreach (A::wrap($extends) as $extend) { + try { + $mixin = static::find($extend); + $mixin = static::extend($mixin); + $props = A::merge($mixin, $props, A::MERGE_REPLACE); + } catch (Exception $e) { + // keep the props unextended if the snippet wasn't found + } + } + + // remove the extends flag + unset($props['extends']); + + return $props; + } + + /** + * Create a new blueprint for a model + * + * @param string $name + * @param string|null $fallback + * @param \Kirby\Cms\Model $model + * @return static|null + */ + public static function factory(string $name, string $fallback = null, Model $model) + { + try { + $props = static::load($name); + } catch (Exception $e) { + $props = $fallback !== null ? static::load($fallback) : null; + } + + if ($props === null) { + return null; + } + + // inject the parent model + $props['model'] = $model; + + return new static($props); + } + + /** + * Returns a single field definition by name + * + * @param string $name + * @return array|null + */ + public function field(string $name): ?array + { + return $this->fields[$name] ?? null; + } + + /** + * Returns all field definitions + * + * @return array + */ + public function fields(): array + { + return $this->fields; + } + + /** + * Find a blueprint by name + * + * @param string $name + * @return array + * @throws \Kirby\Exception\NotFoundException If the blueprint cannot be found + */ + public static function find(string $name): array + { + if (isset(static::$loaded[$name]) === true) { + return static::$loaded[$name]; + } + + $kirby = App::instance(); + $root = $kirby->root('blueprints'); + $file = $root . '/' . $name . '.yml'; + + // first try to find a site blueprint, + // then check in the plugin extensions + if (F::exists($file, $root) !== true) { + $file = $kirby->extension('blueprints', $name); + } + + // callback option can be return array or blueprint file path + if (is_callable($file) === true) { + $file = $file($kirby); + } + + // now ensure that we always return the data array + if (is_string($file) === true && F::exists($file) === true) { + return static::$loaded[$name] = Data::read($file); + } elseif (is_array($file) === true) { + return static::$loaded[$name] = $file; + } + + // neither a valid file nor array data + throw new NotFoundException([ + 'key' => 'blueprint.notFound', + 'data' => ['name' => $name] + ]); + } + + /** + * Used to translate any label, heading, etc. + * + * @param mixed $value + * @param mixed $fallback + * @return mixed + */ + protected function i18n($value, $fallback = null) + { + return I18n::translate($value, $fallback ?? $value); + } + + /** + * Checks if this is the default blueprint + * + * @return bool + */ + public function isDefault(): bool + { + return $this->name() === 'default'; + } + + /** + * Loads a blueprint from file or array + * + * @param string $name + * @return array + */ + public static function load(string $name): array + { + $props = static::find($name); + + $normalize = function ($props) use ($name) { + // inject the filename as name if no name is set + $props['name'] ??= $name; + + // normalize the title + $title = $props['title'] ?? ucfirst($props['name']); + + // translate the title + $props['title'] = I18n::translate($title, $title); + + return $props; + }; + + return $normalize($props); + } + + /** + * Returns the parent model + * + * @return \Kirby\Cms\Model + */ + public function model() + { + return $this->model; + } + + /** + * Returns the blueprint name + * + * @return string + */ + public function name(): string + { + return $this->props['name']; + } + + /** + * Normalizes all required props in a column setup + * + * @param string $tabName + * @param array $columns + * @return array + */ + protected function normalizeColumns(string $tabName, array $columns): array + { + foreach ($columns as $columnKey => $columnProps) { + // unset/remove column if its property is not array + if (is_array($columnProps) === false) { + unset($columns[$columnKey]); + continue; + } + + $columnProps = $this->convertFieldsToSections($tabName . '-col-' . $columnKey, $columnProps); + + // inject getting started info, if the sections are empty + if (empty($columnProps['sections']) === true) { + $columnProps['sections'] = [ + $tabName . '-info-' . $columnKey => [ + 'headline' => 'Column (' . ($columnProps['width'] ?? '1/1') . ')', + 'type' => 'info', + 'text' => 'No sections yet' + ] + ]; + } + + $columns[$columnKey] = array_merge($columnProps, [ + 'width' => $columnProps['width'] ?? '1/1', + 'sections' => $this->normalizeSections($tabName, $columnProps['sections'] ?? []) + ]); + } + + return $columns; + } + + /** + * @param array $items + * @return string + */ + public static function helpList(array $items): string + { + $md = []; + + foreach ($items as $item) { + $md[] = '- *' . $item . '*'; + } + + return PHP_EOL . implode(PHP_EOL, $md); + } + + /** + * Normalize field props for a single field + * + * @param array|string $props + * @return array + * @throws \Kirby\Exception\InvalidArgumentException If the filed name is missing or the field type is invalid + */ + public static function fieldProps($props): array + { + $props = static::extend($props); + + if (isset($props['name']) === false) { + throw new InvalidArgumentException('The field name is missing'); + } + + $name = $props['name']; + $type = $props['type'] ?? $name; + + if ($type !== 'group' && isset(Field::$types[$type]) === false) { + throw new InvalidArgumentException('Invalid field type ("' . $type . '")'); + } + + // support for nested fields + if (isset($props['fields']) === true) { + $props['fields'] = static::fieldsProps($props['fields']); + } + + // groups don't need all the crap + if ($type === 'group') { + return [ + 'fields' => $props['fields'], + 'name' => $name, + 'type' => $type, + ]; + } + + // add some useful defaults + return array_merge($props, [ + 'label' => $props['label'] ?? ucfirst($name), + 'name' => $name, + 'type' => $type, + 'width' => $props['width'] ?? '1/1', + ]); + } + + /** + * Creates an error field with the given error message + * + * @param string $name + * @param string $message + * @return array + */ + public static function fieldError(string $name, string $message): array + { + return [ + 'label' => 'Error', + 'name' => $name, + 'text' => strip_tags($message), + 'theme' => 'negative', + 'type' => 'info', + ]; + } + + /** + * Normalizes all fields and adds automatic labels, + * types and widths. + * + * @param array $fields + * @return array + */ + public static function fieldsProps($fields): array + { + if (is_array($fields) === false) { + $fields = []; + } + + foreach ($fields as $fieldName => $fieldProps) { + + // extend field from string + if (is_string($fieldProps) === true) { + $fieldProps = [ + 'extends' => $fieldProps, + 'name' => $fieldName + ]; + } + + // use the name as type definition + if ($fieldProps === true) { + $fieldProps = []; + } + + // unset / remove field if its property is false + if ($fieldProps === false) { + unset($fields[$fieldName]); + continue; + } + + // inject the name + $fieldProps['name'] = $fieldName; + + // create all props + try { + $fieldProps = static::fieldProps($fieldProps); + } catch (Throwable $e) { + $fieldProps = static::fieldError($fieldName, $e->getMessage()); + } + + // resolve field groups + if ($fieldProps['type'] === 'group') { + if (empty($fieldProps['fields']) === false && is_array($fieldProps['fields']) === true) { + $index = array_search($fieldName, array_keys($fields)); + $before = array_slice($fields, 0, $index); + $after = array_slice($fields, $index + 1); + $fields = array_merge($before, $fieldProps['fields'] ?? [], $after); + } else { + unset($fields[$fieldName]); + } + } else { + $fields[$fieldName] = $fieldProps; + } + } + + return $fields; + } + + /** + * Normalizes blueprint options. This must be used in the + * constructor of an extended class, if you want to make use of it. + * + * @param array|true|false|null|string $options + * @param array $defaults + * @param array $aliases + * @return array + */ + protected function normalizeOptions($options, array $defaults, array $aliases = []): array + { + // return defaults when options are not defined or set to true + if ($options === true) { + return $defaults; + } + + // set all options to false + if ($options === false) { + return array_map(fn () => false, $defaults); + } + + // extend options if possible + $options = $this->extend($options); + + foreach ($options as $key => $value) { + $alias = $aliases[$key] ?? null; + + if ($alias !== null) { + $options[$alias] ??= $value; + unset($options[$key]); + } + } + + return array_merge($defaults, $options); + } + + /** + * Normalizes all required keys in sections + * + * @param string $tabName + * @param array $sections + * @return array + */ + protected function normalizeSections(string $tabName, array $sections): array + { + foreach ($sections as $sectionName => $sectionProps) { + + // unset / remove section if its property is false + if ($sectionProps === false) { + unset($sections[$sectionName]); + continue; + } + + // fallback to default props when true is passed + if ($sectionProps === true) { + $sectionProps = []; + } + + // inject all section extensions + $sectionProps = $this->extend($sectionProps); + + $sections[$sectionName] = $sectionProps = array_merge($sectionProps, [ + 'name' => $sectionName, + 'type' => $type = $sectionProps['type'] ?? $sectionName + ]); + + if (empty($type) === true || is_string($type) === false) { + $sections[$sectionName] = [ + 'name' => $sectionName, + 'headline' => 'Invalid section type for section "' . $sectionName . '"', + 'type' => 'info', + 'text' => 'The following section types are available: ' . $this->helpList(array_keys(Section::$types)) + ]; + } elseif (isset(Section::$types[$type]) === false) { + $sections[$sectionName] = [ + 'name' => $sectionName, + 'headline' => 'Invalid section type ("' . $type . '")', + 'type' => 'info', + 'text' => 'The following section types are available: ' . $this->helpList(array_keys(Section::$types)) + ]; + } + + if ($sectionProps['type'] === 'fields') { + $fields = Blueprint::fieldsProps($sectionProps['fields'] ?? []); + + // inject guide fields guide + if (empty($fields) === true) { + $fields = [ + $tabName . '-info' => [ + 'label' => 'Fields', + 'text' => 'No fields yet', + 'type' => 'info' + ] + ]; + } else { + foreach ($fields as $fieldName => $fieldProps) { + if (isset($this->fields[$fieldName]) === true) { + $this->fields[$fieldName] = $fields[$fieldName] = [ + 'type' => 'info', + 'label' => $fieldProps['label'] ?? 'Error', + 'text' => 'The field name "' . $fieldName . '" already exists in your blueprint.', + 'theme' => 'negative' + ]; + } else { + $this->fields[$fieldName] = $fieldProps; + } + } + } + + $sections[$sectionName]['fields'] = $fields; + } + } + + // store all normalized sections + $this->sections = array_merge($this->sections, $sections); + + return $sections; + } + + /** + * Normalizes all required keys in tabs + * + * @param array $tabs + * @return array + */ + protected function normalizeTabs($tabs): array + { + if (is_array($tabs) === false) { + $tabs = []; + } + + foreach ($tabs as $tabName => $tabProps) { + + // unset / remove tab if its property is false + if ($tabProps === false) { + unset($tabs[$tabName]); + continue; + } + + // inject all tab extensions + $tabProps = $this->extend($tabProps); + + // inject a preset if available + $tabProps = $this->preset($tabProps); + + $tabProps = $this->convertFieldsToSections($tabName, $tabProps); + $tabProps = $this->convertSectionsToColumns($tabName, $tabProps); + + $tabs[$tabName] = array_merge($tabProps, [ + 'columns' => $this->normalizeColumns($tabName, $tabProps['columns'] ?? []), + 'icon' => $tabProps['icon'] ?? null, + 'label' => $this->i18n($tabProps['label'] ?? ucfirst($tabName)), + 'link' => $this->model->panel()->url(true) . '/?tab=' . $tabName, + 'name' => $tabName, + ]); + } + + return $this->tabs = $tabs; + } + + /** + * Injects a blueprint preset + * + * @param array $props + * @return array + */ + protected function preset(array $props): array + { + if (isset($props['preset']) === false) { + return $props; + } + + if (isset(static::$presets[$props['preset']]) === false) { + return $props; + } + + $preset = static::$presets[$props['preset']]; + + if (is_string($preset) === true) { + $preset = require $preset; + } + + return $preset($props); + } + + /** + * Returns a single section by name + * + * @param string $name + * @return \Kirby\Cms\Section|null + */ + public function section(string $name) + { + if (empty($this->sections[$name]) === true) { + return null; + } + + // get all props + $props = $this->sections[$name]; + + // inject the blueprint model + $props['model'] = $this->model(); + + // create a new section object + return new Section($props['type'], $props); + } + + /** + * Returns all sections + * + * @return array + */ + public function sections(): array + { + return A::map( + $this->sections, + fn ($section) => $this->section($section['name']) + ); + } + + /** + * Returns a single tab by name + * + * @param string|null $name + * @return array|null + */ + public function tab(?string $name = null): ?array + { + if ($name === null) { + return A::first($this->tabs); + } + + return $this->tabs[$name] ?? null; + } + + /** + * Returns all tabs + * + * @return array + */ + public function tabs(): array + { + return array_values($this->tabs); + } + + /** + * Returns the blueprint title + * + * @return string + */ + public function title(): string + { + return $this->props['title']; + } + + /** + * Converts the blueprint object to a plain array + * + * @return array + */ + public function toArray(): array + { + return $this->props; + } } diff --git a/kirby/src/Cms/Collection.php b/kirby/src/Cms/Collection.php index 01f7b45..fb8f5f9 100755 --- a/kirby/src/Cms/Collection.php +++ b/kirby/src/Cms/Collection.php @@ -24,315 +24,316 @@ use Kirby\Toolkit\Str; */ class Collection extends BaseCollection { - use HasMethods; + use HasMethods; - /** - * Stores the parent object, which is needed - * in some collections to get the finder methods right. - * - * @var object - */ - protected $parent; + /** + * Stores the parent object, which is needed + * in some collections to get the finder methods right. + * + * @var object + */ + protected $parent; - /** - * Magic getter function - * - * @param string $key - * @param mixed $arguments - * @return mixed - */ - public function __call(string $key, $arguments) - { - // collection methods - if ($this->hasMethod($key) === true) { - return $this->callMethod($key, $arguments); - } - } + /** + * Magic getter function + * + * @param string $key + * @param mixed $arguments + * @return mixed + */ + public function __call(string $key, $arguments) + { + // collection methods + if ($this->hasMethod($key) === true) { + return $this->callMethod($key, $arguments); + } + } - /** - * Creates a new Collection with the given objects - * - * @param array $objects - * @param object|null $parent - */ - public function __construct($objects = [], $parent = null) - { - $this->parent = $parent; + /** + * Creates a new Collection with the given objects + * + * @param array $objects + * @param object|null $parent + */ + public function __construct($objects = [], $parent = null) + { + $this->parent = $parent; - foreach ($objects as $object) { - $this->add($object); - } - } + foreach ($objects as $object) { + $this->add($object); + } + } - /** - * Internal setter for each object in the Collection. - * This takes care of Component validation and of setting - * the collection prop on each object correctly. - * - * @param string $id - * @param object $object - */ - public function __set(string $id, $object) - { - $this->data[$id] = $object; - } + /** + * Internal setter for each object in the Collection. + * This takes care of Component validation and of setting + * the collection prop on each object correctly. + * + * @param string $id + * @param object $object + * @return void + */ + public function __set(string $id, $object): void + { + $this->data[$id] = $object; + } - /** - * Adds a single object or - * an entire second collection to the - * current collection - * - * @param mixed $object - */ - public function add($object) - { - if (is_a($object, self::class) === true) { - $this->data = array_merge($this->data, $object->data); - } elseif (is_object($object) === true && method_exists($object, 'id') === true) { - $this->__set($object->id(), $object); - } else { - $this->append($object); - } + /** + * Adds a single object or + * an entire second collection to the + * current collection + * + * @param mixed $object + */ + public function add($object) + { + if (is_a($object, self::class) === true) { + $this->data = array_merge($this->data, $object->data); + } elseif (is_object($object) === true && method_exists($object, 'id') === true) { + $this->__set($object->id(), $object); + } else { + $this->append($object); + } - return $this; - } + return $this; + } - /** - * Appends an element to the data array - * - * @param mixed ...$args - * @param mixed $key Optional collection key, will be determined from the item if not given - * @param mixed $item - * @return \Kirby\Cms\Collection - */ - public function append(...$args) - { - if (count($args) === 1) { - // try to determine the key from the provided item - if (is_object($args[0]) === true && is_callable([$args[0], 'id']) === true) { - return parent::append($args[0]->id(), $args[0]); - } else { - return parent::append($args[0]); - } - } + /** + * Appends an element to the data array + * + * @param mixed ...$args + * @param mixed $key Optional collection key, will be determined from the item if not given + * @param mixed $item + * @return \Kirby\Cms\Collection + */ + public function append(...$args) + { + if (count($args) === 1) { + // try to determine the key from the provided item + if (is_object($args[0]) === true && is_callable([$args[0], 'id']) === true) { + return parent::append($args[0]->id(), $args[0]); + } else { + return parent::append($args[0]); + } + } - return parent::append(...$args); - } + return parent::append(...$args); + } - /** - * Groups the items by a given field or callback. Returns a collection - * with an item for each group and a collection for each group. - * - * @param string|Closure $field - * @param bool $i Ignore upper/lowercase for group names - * @return \Kirby\Cms\Collection - * @throws \Kirby\Exception\Exception - */ - public function group($field, bool $i = true) - { - if (is_string($field) === true) { - $groups = new Collection([], $this->parent()); + /** + * Groups the items by a given field or callback. Returns a collection + * with an item for each group and a collection for each group. + * + * @param string|Closure $field + * @param bool $i Ignore upper/lowercase for group names + * @return \Kirby\Cms\Collection + * @throws \Kirby\Exception\Exception + */ + public function group($field, bool $i = true) + { + if (is_string($field) === true) { + $groups = new Collection([], $this->parent()); - foreach ($this->data as $key => $item) { - $value = $this->getAttribute($item, $field); + foreach ($this->data as $key => $item) { + $value = $this->getAttribute($item, $field); - // make sure that there's always a proper value to group by - if (!$value) { - throw new InvalidArgumentException('Invalid grouping value for key: ' . $key); - } + // make sure that there's always a proper value to group by + if (!$value) { + throw new InvalidArgumentException('Invalid grouping value for key: ' . $key); + } - // ignore upper/lowercase for group names - if ($i) { - $value = Str::lower($value); - } + // ignore upper/lowercase for group names + if ($i) { + $value = Str::lower($value); + } - if (isset($groups->data[$value]) === false) { - // create a new entry for the group if it does not exist yet - $groups->data[$value] = new static([$key => $item]); - } else { - // add the item to an existing group - $groups->data[$value]->set($key, $item); - } - } + if (isset($groups->data[$value]) === false) { + // create a new entry for the group if it does not exist yet + $groups->data[$value] = new static([$key => $item]); + } else { + // add the item to an existing group + $groups->data[$value]->set($key, $item); + } + } - return $groups; - } + return $groups; + } - return parent::group($field, $i); - } + return parent::group($field, $i); + } - /** - * Checks if the given object or id - * is in the collection - * - * @param string|object $key - * @return bool - */ - public function has($key): bool - { - if (is_object($key) === true) { - $key = $key->id(); - } + /** + * Checks if the given object or id + * is in the collection + * + * @param string|object $key + * @return bool + */ + public function has($key): bool + { + if (is_object($key) === true) { + $key = $key->id(); + } - return parent::has($key); - } + return parent::has($key); + } - /** - * Correct position detection for objects. - * The method will automatically detect objects - * or ids and then search accordingly. - * - * @param string|object $needle - * @return int - */ - public function indexOf($needle): int - { - if (is_string($needle) === true) { - return array_search($needle, $this->keys()); - } + /** + * Correct position detection for objects. + * The method will automatically detect objects + * or ids and then search accordingly. + * + * @param string|object $needle + * @return int + */ + public function indexOf($needle): int + { + if (is_string($needle) === true) { + return array_search($needle, $this->keys()); + } - return array_search($needle->id(), $this->keys()); - } + return array_search($needle->id(), $this->keys()); + } - /** - * Returns a Collection without the given element(s) - * - * @param mixed ...$keys any number of keys, passed as individual arguments - * @return \Kirby\Cms\Collection - */ - public function not(...$keys) - { - $collection = $this->clone(); + /** + * Returns a Collection without the given element(s) + * + * @param mixed ...$keys any number of keys, passed as individual arguments + * @return \Kirby\Cms\Collection + */ + public function not(...$keys) + { + $collection = $this->clone(); - foreach ($keys as $key) { - if (is_array($key) === true) { - return $this->not(...$key); - } elseif (is_a($key, 'Kirby\Toolkit\Collection') === true) { - $collection = $collection->not(...$key->keys()); - } elseif (is_object($key) === true) { - $key = $key->id(); - } + foreach ($keys as $key) { + if (is_array($key) === true) { + return $this->not(...$key); + } elseif (is_a($key, 'Kirby\Toolkit\Collection') === true) { + $collection = $collection->not(...$key->keys()); + } elseif (is_object($key) === true) { + $key = $key->id(); + } - unset($collection->{$key}); - } + unset($collection->{$key}); + } - return $collection; - } + return $collection; + } - /** - * Add pagination and return a sliced set of data. - * - * @param mixed ...$arguments - * @return \Kirby\Cms\Collection - */ - public function paginate(...$arguments) - { - $this->pagination = Pagination::for($this, ...$arguments); + /** + * Add pagination and return a sliced set of data. + * + * @param mixed ...$arguments + * @return \Kirby\Cms\Collection + */ + public function paginate(...$arguments) + { + $this->pagination = Pagination::for($this, ...$arguments); - // slice and clone the collection according to the pagination - return $this->slice($this->pagination->offset(), $this->pagination->limit()); - } + // slice and clone the collection according to the pagination + return $this->slice($this->pagination->offset(), $this->pagination->limit()); + } - /** - * Returns the parent model - * - * @return \Kirby\Cms\Model - */ - public function parent() - { - return $this->parent; - } + /** + * Returns the parent model + * + * @return \Kirby\Cms\Model + */ + public function parent() + { + return $this->parent; + } - /** - * Prepends an element to the data array - * - * @param mixed ...$args - * @param mixed $key Optional collection key, will be determined from the item if not given - * @param mixed $item - * @return \Kirby\Cms\Collection - */ - public function prepend(...$args) - { - if (count($args) === 1) { - // try to determine the key from the provided item - if (is_object($args[0]) === true && is_callable([$args[0], 'id']) === true) { - return parent::prepend($args[0]->id(), $args[0]); - } else { - return parent::prepend($args[0]); - } - } + /** + * Prepends an element to the data array + * + * @param mixed ...$args + * @param mixed $key Optional collection key, will be determined from the item if not given + * @param mixed $item + * @return \Kirby\Cms\Collection + */ + public function prepend(...$args) + { + if (count($args) === 1) { + // try to determine the key from the provided item + if (is_object($args[0]) === true && is_callable([$args[0], 'id']) === true) { + return parent::prepend($args[0]->id(), $args[0]); + } else { + return parent::prepend($args[0]); + } + } - return parent::prepend(...$args); - } + return parent::prepend(...$args); + } - /** - * Runs a combination of filter, sort, not, - * offset, limit, search and paginate on the collection. - * Any part of the query is optional. - * - * @param array $arguments - * @return static - */ - public function query(array $arguments = []) - { - $paginate = $arguments['paginate'] ?? null; - $search = $arguments['search'] ?? null; + /** + * Runs a combination of filter, sort, not, + * offset, limit, search and paginate on the collection. + * Any part of the query is optional. + * + * @param array $arguments + * @return static + */ + public function query(array $arguments = []) + { + $paginate = $arguments['paginate'] ?? null; + $search = $arguments['search'] ?? null; - unset($arguments['paginate']); + unset($arguments['paginate']); - $result = parent::query($arguments); + $result = parent::query($arguments); - if (empty($search) === false) { - if (is_array($search) === true) { - $result = $result->search($search['query'] ?? null, $search['options'] ?? []); - } else { - $result = $result->search($search); - } - } + if (empty($search) === false) { + if (is_array($search) === true) { + $result = $result->search($search['query'] ?? null, $search['options'] ?? []); + } else { + $result = $result->search($search); + } + } - if (empty($paginate) === false) { - $result = $result->paginate($paginate); - } + if (empty($paginate) === false) { + $result = $result->paginate($paginate); + } - return $result; - } + return $result; + } - /** - * Removes an object - * - * @param mixed $key the name of the key - */ - public function remove($key) - { - if (is_object($key) === true) { - $key = $key->id(); - } + /** + * Removes an object + * + * @param mixed $key the name of the key + */ + public function remove($key) + { + if (is_object($key) === true) { + $key = $key->id(); + } - return parent::remove($key); - } + return parent::remove($key); + } - /** - * Searches the collection - * - * @param string|null $query - * @param array $params - * @return self - */ - public function search(string $query = null, $params = []) - { - return Search::collection($this, $query, $params); - } + /** + * Searches the collection + * + * @param string|null $query + * @param array $params + * @return self + */ + public function search(string $query = null, $params = []) + { + return Search::collection($this, $query, $params); + } - /** - * Converts all objects in the collection - * to an array. This can also take a callback - * function to further modify the array result. - * - * @param \Closure|null $map - * @return array - */ - public function toArray(Closure $map = null): array - { - return parent::toArray($map ?? fn ($object) => $object->toArray()); - } + /** + * Converts all objects in the collection + * to an array. This can also take a callback + * function to further modify the array result. + * + * @param \Closure|null $map + * @return array + */ + public function toArray(Closure $map = null): array + { + return parent::toArray($map ?? fn ($object) => $object->toArray()); + } } diff --git a/kirby/src/Cms/Collections.php b/kirby/src/Cms/Collections.php index b7f7d64..542ed03 100755 --- a/kirby/src/Cms/Collections.php +++ b/kirby/src/Cms/Collections.php @@ -22,120 +22,120 @@ use Kirby\Toolkit\Controller; */ class Collections { - /** - * Each collection is cached once it - * has been called, to avoid further - * processing on sequential calls to - * the same collection. - * - * @var array - */ - protected $cache = []; + /** + * Each collection is cached once it + * has been called, to avoid further + * processing on sequential calls to + * the same collection. + * + * @var array + */ + protected $cache = []; - /** - * Store of all collections - * - * @var array - */ - protected $collections = []; + /** + * Store of all collections + * + * @var array + */ + protected $collections = []; - /** - * Magic caller to enable something like - * `$collections->myCollection()` - * - * @param string $name - * @param array $arguments - * @return \Kirby\Cms\Collection|null - */ - public function __call(string $name, array $arguments = []) - { - return $this->get($name, ...$arguments); - } + /** + * Magic caller to enable something like + * `$collections->myCollection()` + * + * @param string $name + * @param array $arguments + * @return \Kirby\Cms\Collection|null + */ + public function __call(string $name, array $arguments = []) + { + return $this->get($name, ...$arguments); + } - /** - * Loads a collection by name if registered - * - * @param string $name - * @param array $data - * @return \Kirby\Cms\Collection|null - */ - public function get(string $name, array $data = []) - { - // if not yet loaded - if (isset($this->collections[$name]) === false) { - $this->collections[$name] = $this->load($name); - } + /** + * Loads a collection by name if registered + * + * @param string $name + * @param array $data + * @return \Kirby\Cms\Collection|null + */ + public function get(string $name, array $data = []) + { + // if not yet loaded + if (isset($this->collections[$name]) === false) { + $this->collections[$name] = $this->load($name); + } - // if not yet cached - if ( - isset($this->cache[$name]) === false || - $this->cache[$name]['data'] !== $data - ) { - $controller = new Controller($this->collections[$name]); - $this->cache[$name] = [ - 'result' => $controller->call(null, $data), - 'data' => $data - ]; - } + // if not yet cached + if ( + isset($this->cache[$name]) === false || + $this->cache[$name]['data'] !== $data + ) { + $controller = new Controller($this->collections[$name]); + $this->cache[$name] = [ + 'result' => $controller->call(null, $data), + 'data' => $data + ]; + } - // return cloned object - if (is_object($this->cache[$name]['result']) === true) { - return clone $this->cache[$name]['result']; - } + // return cloned object + if (is_object($this->cache[$name]['result']) === true) { + return clone $this->cache[$name]['result']; + } - return $this->cache[$name]['result']; - } + return $this->cache[$name]['result']; + } - /** - * Checks if a collection exists - * - * @param string $name - * @return bool - */ - public function has(string $name): bool - { - if (isset($this->collections[$name]) === true) { - return true; - } + /** + * Checks if a collection exists + * + * @param string $name + * @return bool + */ + public function has(string $name): bool + { + if (isset($this->collections[$name]) === true) { + return true; + } - try { - $this->load($name); - return true; - } catch (NotFoundException $e) { - return false; - } - } + try { + $this->load($name); + return true; + } catch (NotFoundException $e) { + return false; + } + } - /** - * Loads collection from php file in a - * given directory or from plugin extension. - * - * @param string $name - * @return mixed - * @throws \Kirby\Exception\NotFoundException - */ - public function load(string $name) - { - $kirby = App::instance(); + /** + * Loads collection from php file in a + * given directory or from plugin extension. + * + * @param string $name + * @return mixed + * @throws \Kirby\Exception\NotFoundException + */ + public function load(string $name) + { + $kirby = App::instance(); - // first check for collection file - $file = $kirby->root('collections') . '/' . $name . '.php'; + // first check for collection file + $file = $kirby->root('collections') . '/' . $name . '.php'; - if (is_file($file) === true) { - $collection = F::load($file); + if (is_file($file) === true) { + $collection = F::load($file); - if (is_a($collection, 'Closure')) { - return $collection; - } - } + if (is_a($collection, 'Closure')) { + return $collection; + } + } - // fallback to collections from plugins - $collections = $kirby->extensions('collections'); + // fallback to collections from plugins + $collections = $kirby->extensions('collections'); - if (isset($collections[$name]) === true) { - return $collections[$name]; - } + if (isset($collections[$name]) === true) { + return $collections[$name]; + } - throw new NotFoundException('The collection cannot be found'); - } + throw new NotFoundException('The collection cannot be found'); + } } diff --git a/kirby/src/Cms/Content.php b/kirby/src/Cms/Content.php index 8ad474c..d0a6e11 100755 --- a/kirby/src/Cms/Content.php +++ b/kirby/src/Cms/Content.php @@ -16,254 +16,254 @@ use Kirby\Form\Form; */ class Content { - /** - * The raw data array - * - * @var array - */ - protected $data = []; + /** + * The raw data array + * + * @var array + */ + protected $data = []; - /** - * Cached field objects - * Once a field is being fetched - * it is added to this array for - * later reuse - * - * @var array - */ - protected $fields = []; + /** + * Cached field objects + * Once a field is being fetched + * it is added to this array for + * later reuse + * + * @var array + */ + protected $fields = []; - /** - * A potential parent object. - * Not necessarily needed. Especially - * for testing, but field methods might - * need it. - * - * @var Model - */ - protected $parent; + /** + * A potential parent object. + * Not necessarily needed. Especially + * for testing, but field methods might + * need it. + * + * @var Model + */ + protected $parent; - /** - * Magic getter for content fields - * - * @param string $name - * @param array $arguments - * @return \Kirby\Cms\Field - */ - public function __call(string $name, array $arguments = []) - { - return $this->get($name); - } + /** + * Magic getter for content fields + * + * @param string $name + * @param array $arguments + * @return \Kirby\Cms\Field + */ + public function __call(string $name, array $arguments = []) + { + return $this->get($name); + } - /** - * Creates a new Content object - * - * @param array|null $data - * @param object|null $parent - * @param bool $normalize Set to `false` if the input field keys are already lowercase - */ - public function __construct(array $data = [], $parent = null, bool $normalize = true) - { - if ($normalize === true) { - $data = array_change_key_case($data, CASE_LOWER); - } + /** + * Creates a new Content object + * + * @param array|null $data + * @param object|null $parent + * @param bool $normalize Set to `false` if the input field keys are already lowercase + */ + public function __construct(array $data = [], $parent = null, bool $normalize = true) + { + if ($normalize === true) { + $data = array_change_key_case($data, CASE_LOWER); + } - $this->data = $data; - $this->parent = $parent; - } + $this->data = $data; + $this->parent = $parent; + } - /** - * Same as `self::data()` to improve - * `var_dump` output - * - * @see self::data() - * @return array - */ - public function __debugInfo(): array - { - return $this->toArray(); - } + /** + * Same as `self::data()` to improve + * `var_dump` output + * + * @see self::data() + * @return array + */ + public function __debugInfo(): array + { + return $this->toArray(); + } - /** - * Converts the content to a new blueprint - * - * @param string $to - * @return array - */ - public function convertTo(string $to): array - { - // prepare data - $data = []; - $content = $this; + /** + * Converts the content to a new blueprint + * + * @param string $to + * @return array + */ + public function convertTo(string $to): array + { + // prepare data + $data = []; + $content = $this; - // blueprints - $old = $this->parent->blueprint(); - $subfolder = dirname($old->name()); - $new = Blueprint::factory($subfolder . '/' . $to, $subfolder . '/default', $this->parent); + // blueprints + $old = $this->parent->blueprint(); + $subfolder = dirname($old->name()); + $new = Blueprint::factory($subfolder . '/' . $to, $subfolder . '/default', $this->parent); - // forms - $oldForm = new Form(['fields' => $old->fields(), 'model' => $this->parent]); - $newForm = new Form(['fields' => $new->fields(), 'model' => $this->parent]); + // forms + $oldForm = new Form(['fields' => $old->fields(), 'model' => $this->parent]); + $newForm = new Form(['fields' => $new->fields(), 'model' => $this->parent]); - // fields - $oldFields = $oldForm->fields(); - $newFields = $newForm->fields(); + // fields + $oldFields = $oldForm->fields(); + $newFields = $newForm->fields(); - // go through all fields of new template - foreach ($newFields as $newField) { - $name = $newField->name(); - $oldField = $oldFields->get($name); + // go through all fields of new template + foreach ($newFields as $newField) { + $name = $newField->name(); + $oldField = $oldFields->get($name); - // field name and type matches with old template - if ($oldField && $oldField->type() === $newField->type()) { - $data[$name] = $content->get($name)->value(); - } else { - $data[$name] = $newField->default(); - } - } + // field name and type matches with old template + if ($oldField && $oldField->type() === $newField->type()) { + $data[$name] = $content->get($name)->value(); + } else { + $data[$name] = $newField->default(); + } + } - // preserve existing fields - return array_merge($this->data, $data); - } + // preserve existing fields + return array_merge($this->data, $data); + } - /** - * Returns the raw data array - * - * @return array - */ - public function data(): array - { - return $this->data; - } + /** + * Returns the raw data array + * + * @return array + */ + public function data(): array + { + return $this->data; + } - /** - * Returns all registered field objects - * - * @return array - */ - public function fields(): array - { - foreach ($this->data as $key => $value) { - $this->get($key); - } - return $this->fields; - } + /** + * Returns all registered field objects + * + * @return array + */ + public function fields(): array + { + foreach ($this->data as $key => $value) { + $this->get($key); + } + return $this->fields; + } - /** - * Returns either a single field object - * or all registered fields - * - * @param string|null $key - * @return \Kirby\Cms\Field|array - */ - public function get(string $key = null) - { - if ($key === null) { - return $this->fields(); - } + /** + * Returns either a single field object + * or all registered fields + * + * @param string|null $key + * @return \Kirby\Cms\Field|array + */ + public function get(string $key = null) + { + if ($key === null) { + return $this->fields(); + } - $key = strtolower($key); + $key = strtolower($key); - if (isset($this->fields[$key])) { - return $this->fields[$key]; - } + if (isset($this->fields[$key])) { + return $this->fields[$key]; + } - $value = $this->data()[$key] ?? null; + $value = $this->data()[$key] ?? null; - return $this->fields[$key] = new Field($this->parent, $key, $value); - } + return $this->fields[$key] = new Field($this->parent, $key, $value); + } - /** - * Checks if a content field is set - * - * @param string $key - * @return bool - */ - public function has(string $key): bool - { - return isset($this->data[strtolower($key)]) === true; - } + /** + * Checks if a content field is set + * + * @param string $key + * @return bool + */ + public function has(string $key): bool + { + return isset($this->data[strtolower($key)]) === true; + } - /** - * Returns all field keys - * - * @return array - */ - public function keys(): array - { - return array_keys($this->data()); - } + /** + * Returns all field keys + * + * @return array + */ + public function keys(): array + { + return array_keys($this->data()); + } - /** - * Returns a clone of the content object - * without the fields, specified by the - * passed key(s) - * - * @param string ...$keys - * @return static - */ - public function not(...$keys) - { - $copy = clone $this; - $copy->fields = null; + /** + * Returns a clone of the content object + * without the fields, specified by the + * passed key(s) + * + * @param string ...$keys + * @return static + */ + public function not(...$keys) + { + $copy = clone $this; + $copy->fields = null; - foreach ($keys as $key) { - unset($copy->data[strtolower($key)]); - } + foreach ($keys as $key) { + unset($copy->data[strtolower($key)]); + } - return $copy; - } + return $copy; + } - /** - * Returns the parent - * Site, Page, File or User object - * - * @return \Kirby\Cms\Model - */ - public function parent() - { - return $this->parent; - } + /** + * Returns the parent + * Site, Page, File or User object + * + * @return \Kirby\Cms\Model + */ + public function parent() + { + return $this->parent; + } - /** - * Set the parent model - * - * @param \Kirby\Cms\Model $parent - * @return $this - */ - public function setParent(Model $parent) - { - $this->parent = $parent; - return $this; - } + /** + * Set the parent model + * + * @param \Kirby\Cms\Model $parent + * @return $this + */ + public function setParent(Model $parent) + { + $this->parent = $parent; + return $this; + } - /** - * Returns the raw data array - * - * @see self::data() - * @return array - */ - public function toArray(): array - { - return $this->data(); - } + /** + * Returns the raw data array + * + * @see self::data() + * @return array + */ + public function toArray(): array + { + return $this->data(); + } - /** - * Updates the content and returns - * a cloned object - * - * @param array|null $content - * @param bool $overwrite - * @return $this - */ - public function update(array $content = null, bool $overwrite = false) - { - $content = array_change_key_case((array)$content, CASE_LOWER); - $this->data = $overwrite === true ? $content : array_merge($this->data, $content); + /** + * Updates the content and returns + * a cloned object + * + * @param array|null $content + * @param bool $overwrite + * @return $this + */ + public function update(array $content = null, bool $overwrite = false) + { + $content = array_change_key_case((array)$content, CASE_LOWER); + $this->data = $overwrite === true ? $content : array_merge($this->data, $content); - // clear cache of Field objects - $this->fields = []; + // clear cache of Field objects + $this->fields = []; - return $this; - } + return $this; + } } diff --git a/kirby/src/Cms/ContentLock.php b/kirby/src/Cms/ContentLock.php index c3daf2f..f938116 100755 --- a/kirby/src/Cms/ContentLock.php +++ b/kirby/src/Cms/ContentLock.php @@ -17,216 +17,216 @@ use Kirby\Exception\PermissionException; */ class ContentLock { - /** - * Lock data - * - * @var array - */ - protected $data; + /** + * Lock data + * + * @var array + */ + protected $data; - /** - * The model to manage locking/unlocking for - * - * @var ModelWithContent - */ - protected $model; + /** + * The model to manage locking/unlocking for + * + * @var ModelWithContent + */ + protected $model; - /** - * @param \Kirby\Cms\ModelWithContent $model - */ - public function __construct(ModelWithContent $model) - { - $this->model = $model; - $this->data = $this->kirby()->locks()->get($model); - } + /** + * @param \Kirby\Cms\ModelWithContent $model + */ + public function __construct(ModelWithContent $model) + { + $this->model = $model; + $this->data = $this->kirby()->locks()->get($model); + } - /** - * Clears the lock unconditionally - * - * @return bool - */ - protected function clearLock(): bool - { - // if no lock exists, skip - if (isset($this->data['lock']) === false) { - return true; - } + /** + * Clears the lock unconditionally + * + * @return bool + */ + protected function clearLock(): bool + { + // if no lock exists, skip + if (isset($this->data['lock']) === false) { + return true; + } - // remove lock - unset($this->data['lock']); + // remove lock + unset($this->data['lock']); - return $this->kirby()->locks()->set($this->model, $this->data); - } + return $this->kirby()->locks()->set($this->model, $this->data); + } - /** - * Sets lock with the current user - * - * @return bool - * @throws \Kirby\Exception\DuplicateException - */ - public function create(): bool - { - // check if model is already locked by another user - if ( - isset($this->data['lock']) === true && - $this->data['lock']['user'] !== $this->user()->id() - ) { - $id = ContentLocks::id($this->model); - throw new DuplicateException($id . ' is already locked'); - } + /** + * Sets lock with the current user + * + * @return bool + * @throws \Kirby\Exception\DuplicateException + */ + public function create(): bool + { + // check if model is already locked by another user + if ( + isset($this->data['lock']) === true && + $this->data['lock']['user'] !== $this->user()->id() + ) { + $id = ContentLocks::id($this->model); + throw new DuplicateException($id . ' is already locked'); + } - $this->data['lock'] = [ - 'user' => $this->user()->id(), - 'time' => time() - ]; + $this->data['lock'] = [ + 'user' => $this->user()->id(), + 'time' => time() + ]; - return $this->kirby()->locks()->set($this->model, $this->data); - } + return $this->kirby()->locks()->set($this->model, $this->data); + } - /** - * Returns either `false` or array with `user`, `email`, - * `time` and `unlockable` keys - * - * @return array|bool - */ - public function get() - { - $data = $this->data['lock'] ?? []; + /** + * Returns either `false` or array with `user`, `email`, + * `time` and `unlockable` keys + * + * @return array|bool + */ + public function get() + { + $data = $this->data['lock'] ?? []; - if (empty($data) === false && $data['user'] !== $this->user()->id()) { - if ($user = $this->kirby()->user($data['user'])) { - $time = (int)($data['time']); + if (empty($data) === false && $data['user'] !== $this->user()->id()) { + if ($user = $this->kirby()->user($data['user'])) { + $time = (int)($data['time']); - return [ - 'user' => $user->id(), - 'email' => $user->email(), - 'time' => $time, - 'unlockable' => ($time + 60) <= time() - ]; - } + return [ + 'user' => $user->id(), + 'email' => $user->email(), + 'time' => $time, + 'unlockable' => ($time + 60) <= time() + ]; + } - // clear lock if user not found - $this->clearLock(); - } + // clear lock if user not found + $this->clearLock(); + } - return false; - } + return false; + } - /** - * Returns if the model is locked by another user - * - * @return bool - */ - public function isLocked(): bool - { - $lock = $this->get(); + /** + * Returns if the model is locked by another user + * + * @return bool + */ + public function isLocked(): bool + { + $lock = $this->get(); - if ($lock !== false && $lock['user'] !== $this->user()->id()) { - return true; - } + if ($lock !== false && $lock['user'] !== $this->user()->id()) { + return true; + } - return false; - } + return false; + } - /** - * Returns if the current user's lock has been removed by another user - * - * @return bool - */ - public function isUnlocked(): bool - { - $data = $this->data['unlock'] ?? []; + /** + * Returns if the current user's lock has been removed by another user + * + * @return bool + */ + public function isUnlocked(): bool + { + $data = $this->data['unlock'] ?? []; - return in_array($this->user()->id(), $data) === true; - } + return in_array($this->user()->id(), $data) === true; + } - /** - * Returns the app instance - * - * @return \Kirby\Cms\App - */ - protected function kirby(): App - { - return $this->model->kirby(); - } + /** + * Returns the app instance + * + * @return \Kirby\Cms\App + */ + protected function kirby(): App + { + return $this->model->kirby(); + } - /** - * Removes lock of current user - * - * @return bool - * @throws \Kirby\Exception\LogicException - */ - public function remove(): bool - { - // if no lock exists, skip - if (isset($this->data['lock']) === false) { - return true; - } + /** + * Removes lock of current user + * + * @return bool + * @throws \Kirby\Exception\LogicException + */ + public function remove(): bool + { + // if no lock exists, skip + if (isset($this->data['lock']) === false) { + return true; + } - // check if lock was set by another user - if ($this->data['lock']['user'] !== $this->user()->id()) { - throw new LogicException([ - 'fallback' => 'The content lock can only be removed by the user who created it. Use unlock instead.', - 'httpCode' => 409 - ]); - } + // check if lock was set by another user + if ($this->data['lock']['user'] !== $this->user()->id()) { + throw new LogicException([ + 'fallback' => 'The content lock can only be removed by the user who created it. Use unlock instead.', + 'httpCode' => 409 + ]); + } - return $this->clearLock(); - } + return $this->clearLock(); + } - /** - * Removes unlock information for current user - * - * @return bool - */ - public function resolve(): bool - { - // if no unlocks exist, skip - if (isset($this->data['unlock']) === false) { - return true; - } + /** + * Removes unlock information for current user + * + * @return bool + */ + public function resolve(): bool + { + // if no unlocks exist, skip + if (isset($this->data['unlock']) === false) { + return true; + } - // remove user from unlock array - $this->data['unlock'] = array_diff( - $this->data['unlock'], - [$this->user()->id()] - ); + // remove user from unlock array + $this->data['unlock'] = array_diff( + $this->data['unlock'], + [$this->user()->id()] + ); - return $this->kirby()->locks()->set($this->model, $this->data); - } + return $this->kirby()->locks()->set($this->model, $this->data); + } - /** - * Removes current lock and adds lock user to unlock data - * - * @return bool - */ - public function unlock(): bool - { - // if no lock exists, skip - if (isset($this->data['lock']) === false) { - return true; - } + /** + * Removes current lock and adds lock user to unlock data + * + * @return bool + */ + public function unlock(): bool + { + // if no lock exists, skip + if (isset($this->data['lock']) === false) { + return true; + } - // add lock user to unlocked data - $this->data['unlock'] ??= []; - $this->data['unlock'][] = $this->data['lock']['user']; + // add lock user to unlocked data + $this->data['unlock'] ??= []; + $this->data['unlock'][] = $this->data['lock']['user']; - return $this->clearLock(); - } + return $this->clearLock(); + } - /** - * Returns currently authenticated user; - * throws exception if none is authenticated - * - * @return \Kirby\Cms\User - * @throws \Kirby\Exception\PermissionException - */ - protected function user(): User - { - if ($user = $this->kirby()->user()) { - return $user; - } + /** + * Returns currently authenticated user; + * throws exception if none is authenticated + * + * @return \Kirby\Cms\User + * @throws \Kirby\Exception\PermissionException + */ + protected function user(): User + { + if ($user = $this->kirby()->user()) { + return $user; + } - throw new PermissionException('No user authenticated.'); - } + throw new PermissionException('No user authenticated.'); + } } diff --git a/kirby/src/Cms/ContentLocks.php b/kirby/src/Cms/ContentLocks.php index f56d216..2d08d9f 100755 --- a/kirby/src/Cms/ContentLocks.php +++ b/kirby/src/Cms/ContentLocks.php @@ -18,211 +18,211 @@ use Kirby\Filesystem\F; */ class ContentLocks { - /** - * Data from the `.lock` files - * that have been read so far - * cached by `.lock` file path - * - * @var array - */ - protected $data = []; + /** + * Data from the `.lock` files + * that have been read so far + * cached by `.lock` file path + * + * @var array + */ + protected $data = []; - /** - * PHP file handles for all currently - * open `.lock` files - * - * @var array - */ - protected $handles = []; + /** + * PHP file handles for all currently + * open `.lock` files + * + * @var array + */ + protected $handles = []; - /** - * Closes the open file handles - * - * @codeCoverageIgnore - */ - public function __destruct() - { - foreach ($this->handles as $file => $handle) { - $this->closeHandle($file); - } - } + /** + * Closes the open file handles + * + * @codeCoverageIgnore + */ + public function __destruct() + { + foreach ($this->handles as $file => $handle) { + $this->closeHandle($file); + } + } - /** - * Removes the file lock and closes the file handle - * - * @param string $file - * @return void - * @throws \Kirby\Exception\Exception - */ - protected function closeHandle(string $file) - { - if (isset($this->handles[$file]) === false) { - return; - } + /** + * Removes the file lock and closes the file handle + * + * @param string $file + * @return void + * @throws \Kirby\Exception\Exception + */ + protected function closeHandle(string $file) + { + if (isset($this->handles[$file]) === false) { + return; + } - $handle = $this->handles[$file]; - $result = flock($handle, LOCK_UN) && fclose($handle); + $handle = $this->handles[$file]; + $result = flock($handle, LOCK_UN) && fclose($handle); - if ($result !== true) { - throw new Exception('Unexpected file system error.'); // @codeCoverageIgnore - } + if ($result !== true) { + throw new Exception('Unexpected file system error.'); // @codeCoverageIgnore + } - unset($this->handles[$file]); - } + unset($this->handles[$file]); + } - /** - * Returns the path to a model's lock file - * - * @param \Kirby\Cms\ModelWithContent $model - * @return string - */ - public static function file(ModelWithContent $model): string - { - return $model->contentFileDirectory() . '/.lock'; - } + /** + * Returns the path to a model's lock file + * + * @param \Kirby\Cms\ModelWithContent $model + * @return string + */ + public static function file(ModelWithContent $model): string + { + return $model->contentFileDirectory() . '/.lock'; + } - /** - * Returns the lock/unlock data for the specified model - * - * @param \Kirby\Cms\ModelWithContent $model - * @return array - */ - public function get(ModelWithContent $model): array - { - $file = static::file($model); - $id = static::id($model); + /** + * Returns the lock/unlock data for the specified model + * + * @param \Kirby\Cms\ModelWithContent $model + * @return array + */ + public function get(ModelWithContent $model): array + { + $file = static::file($model); + $id = static::id($model); - // return from cache if file was already loaded - if (isset($this->data[$file]) === true) { - return $this->data[$file][$id] ?? []; - } + // return from cache if file was already loaded + if (isset($this->data[$file]) === true) { + return $this->data[$file][$id] ?? []; + } - // first get a handle to ensure a file system lock - $handle = $this->handle($file); + // first get a handle to ensure a file system lock + $handle = $this->handle($file); - if (is_resource($handle) === true) { - // read data from file - clearstatcache(); - $filesize = filesize($file); + if (is_resource($handle) === true) { + // read data from file + clearstatcache(); + $filesize = filesize($file); - if ($filesize > 0) { - // always read the whole file - rewind($handle); - $string = fread($handle, $filesize); - $data = Data::decode($string, 'yaml'); - } - } + if ($filesize > 0) { + // always read the whole file + rewind($handle); + $string = fread($handle, $filesize); + $data = Data::decode($string, 'yaml'); + } + } - $this->data[$file] = $data ?? []; + $this->data[$file] = $data ?? []; - return $this->data[$file][$id] ?? []; - } + return $this->data[$file][$id] ?? []; + } - /** - * Returns the file handle to a `.lock` file - * - * @param string $file - * @param bool $create Whether to create the file if it does not exist - * @return resource|null File handle - * @throws \Kirby\Exception\Exception - */ - protected function handle(string $file, bool $create = false) - { - // check for an already open handle - if (isset($this->handles[$file]) === true) { - return $this->handles[$file]; - } + /** + * Returns the file handle to a `.lock` file + * + * @param string $file + * @param bool $create Whether to create the file if it does not exist + * @return resource|null File handle + * @throws \Kirby\Exception\Exception + */ + protected function handle(string $file, bool $create = false) + { + // check for an already open handle + if (isset($this->handles[$file]) === true) { + return $this->handles[$file]; + } - // don't create a file if not requested - if (is_file($file) !== true && $create !== true) { - return null; - } + // don't create a file if not requested + if (is_file($file) !== true && $create !== true) { + return null; + } - $handle = @fopen($file, 'c+b'); - if (is_resource($handle) === false) { - throw new Exception('Lock file ' . $file . ' could not be opened.'); // @codeCoverageIgnore - } + $handle = @fopen($file, 'c+b'); + if (is_resource($handle) === false) { + throw new Exception('Lock file ' . $file . ' could not be opened.'); // @codeCoverageIgnore + } - // lock the lock file exclusively to prevent changes by other threads - $result = flock($handle, LOCK_EX); - if ($result !== true) { - throw new Exception('Unexpected file system error.'); // @codeCoverageIgnore - } + // lock the lock file exclusively to prevent changes by other threads + $result = flock($handle, LOCK_EX); + if ($result !== true) { + throw new Exception('Unexpected file system error.'); // @codeCoverageIgnore + } - return $this->handles[$file] = $handle; - } + return $this->handles[$file] = $handle; + } - /** - * Returns model ID used as the key for the data array; - * prepended with a slash because the $site otherwise won't have an ID - * - * @param \Kirby\Cms\ModelWithContent $model - * @return string - */ - public static function id(ModelWithContent $model): string - { - return '/' . $model->id(); - } + /** + * Returns model ID used as the key for the data array; + * prepended with a slash because the $site otherwise won't have an ID + * + * @param \Kirby\Cms\ModelWithContent $model + * @return string + */ + public static function id(ModelWithContent $model): string + { + return '/' . $model->id(); + } - /** - * Sets and writes the lock/unlock data for the specified model - * - * @param \Kirby\Cms\ModelWithContent $model - * @param array $data - * @return bool - * @throws \Kirby\Exception\Exception - */ - public function set(ModelWithContent $model, array $data): bool - { - $file = static::file($model); - $id = static::id($model); - $handle = $this->handle($file, true); + /** + * Sets and writes the lock/unlock data for the specified model + * + * @param \Kirby\Cms\ModelWithContent $model + * @param array $data + * @return bool + * @throws \Kirby\Exception\Exception + */ + public function set(ModelWithContent $model, array $data): bool + { + $file = static::file($model); + $id = static::id($model); + $handle = $this->handle($file, true); - $this->data[$file][$id] = $data; + $this->data[$file][$id] = $data; - // make sure to unset model id entries, - // if no lock data for the model exists - foreach ($this->data[$file] as $id => $data) { - // there is no data for that model whatsoever - if ( - isset($data['lock']) === false && - (isset($data['unlock']) === false || - count($data['unlock']) === 0) - ) { - unset($this->data[$file][$id]); + // make sure to unset model id entries, + // if no lock data for the model exists + foreach ($this->data[$file] as $id => $data) { + // there is no data for that model whatsoever + if ( + isset($data['lock']) === false && + (isset($data['unlock']) === false || + count($data['unlock']) === 0) + ) { + unset($this->data[$file][$id]); - // there is empty unlock data, but still lock data - } elseif ( - isset($data['unlock']) === true && - count($data['unlock']) === 0 - ) { - unset($this->data[$file][$id]['unlock']); - } - } + // there is empty unlock data, but still lock data + } elseif ( + isset($data['unlock']) === true && + count($data['unlock']) === 0 + ) { + unset($this->data[$file][$id]['unlock']); + } + } - // there is no data left in the file whatsoever, delete the file - if (count($this->data[$file]) === 0) { - unset($this->data[$file]); + // there is no data left in the file whatsoever, delete the file + if (count($this->data[$file]) === 0) { + unset($this->data[$file]); - // close the file handle, otherwise we can't delete it on Windows - $this->closeHandle($file); + // close the file handle, otherwise we can't delete it on Windows + $this->closeHandle($file); - return F::remove($file); - } + return F::remove($file); + } - $yaml = Data::encode($this->data[$file], 'yaml'); + $yaml = Data::encode($this->data[$file], 'yaml'); - // delete all file contents first - if (rewind($handle) !== true || ftruncate($handle, 0) !== true) { - throw new Exception('Could not write lock file ' . $file . '.'); // @codeCoverageIgnore - } + // delete all file contents first + if (rewind($handle) !== true || ftruncate($handle, 0) !== true) { + throw new Exception('Could not write lock file ' . $file . '.'); // @codeCoverageIgnore + } - // write the new contents - $result = fwrite($handle, $yaml); - if (is_int($result) === false || $result === 0) { - throw new Exception('Could not write lock file ' . $file . '.'); // @codeCoverageIgnore - } + // write the new contents + $result = fwrite($handle, $yaml); + if (is_int($result) === false || $result === 0) { + throw new Exception('Could not write lock file ' . $file . '.'); // @codeCoverageIgnore + } - return true; - } + return true; + } } diff --git a/kirby/src/Cms/ContentTranslation.php b/kirby/src/Cms/ContentTranslation.php index 60b9d0e..5ffa744 100755 --- a/kirby/src/Cms/ContentTranslation.php +++ b/kirby/src/Cms/ContentTranslation.php @@ -17,232 +17,232 @@ use Kirby\Toolkit\Properties; */ class ContentTranslation { - use Properties; + use Properties; - /** - * @var string - */ - protected $code; + /** + * @var string + */ + protected $code; - /** - * @var array - */ - protected $content; + /** + * @var array + */ + protected $content; - /** - * @var string - */ - protected $contentFile; + /** + * @var string + */ + protected $contentFile; - /** - * @var Model - */ - protected $parent; + /** + * @var Model + */ + protected $parent; - /** - * @var string - */ - protected $slug; + /** + * @var string + */ + protected $slug; - /** - * Creates a new translation object - * - * @param array $props - */ - public function __construct(array $props) - { - $this->setRequiredProperties($props, ['parent', 'code']); - $this->setOptionalProperties($props, ['slug', 'content']); - } + /** + * Creates a new translation object + * + * @param array $props + */ + public function __construct(array $props) + { + $this->setRequiredProperties($props, ['parent', 'code']); + $this->setOptionalProperties($props, ['slug', 'content']); + } - /** - * Improve `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return $this->toArray(); - } + /** + * Improve `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return $this->toArray(); + } - /** - * Returns the language code of the - * translation - * - * @return string - */ - public function code(): string - { - return $this->code; - } + /** + * Returns the language code of the + * translation + * + * @return string + */ + public function code(): string + { + return $this->code; + } - /** - * Returns the translation content - * as plain array - * - * @return array - */ - public function content(): array - { - $parent = $this->parent(); + /** + * Returns the translation content + * as plain array + * + * @return array + */ + public function content(): array + { + $parent = $this->parent(); - if ($this->content === null) { - $this->content = $parent->readContent($this->code()); - } + if ($this->content === null) { + $this->content = $parent->readContent($this->code()); + } - $content = $this->content; + $content = $this->content; - // merge with the default content - if ($this->isDefault() === false && $defaultLanguage = $parent->kirby()->defaultLanguage()) { - $default = []; + // merge with the default content + if ($this->isDefault() === false && $defaultLanguage = $parent->kirby()->defaultLanguage()) { + $default = []; - if ($defaultTranslation = $parent->translation($defaultLanguage->code())) { - $default = $defaultTranslation->content(); - } + if ($defaultTranslation = $parent->translation($defaultLanguage->code())) { + $default = $defaultTranslation->content(); + } - $content = array_merge($default, $content); - } + $content = array_merge($default, $content); + } - return $content; - } + return $content; + } - /** - * Absolute path to the translation content file - * - * @return string - */ - public function contentFile(): string - { - return $this->contentFile = $this->parent->contentFile($this->code, true); - } + /** + * Absolute path to the translation content file + * + * @return string + */ + public function contentFile(): string + { + return $this->contentFile = $this->parent->contentFile($this->code, true); + } - /** - * Checks if the translation file exists - * - * @return bool - */ - public function exists(): bool - { - return file_exists($this->contentFile()) === true; - } + /** + * Checks if the translation file exists + * + * @return bool + */ + public function exists(): bool + { + return file_exists($this->contentFile()) === true; + } - /** - * Returns the translation code as id - * - * @return string - */ - public function id(): string - { - return $this->code(); - } + /** + * Returns the translation code as id + * + * @return string + */ + public function id(): string + { + return $this->code(); + } - /** - * Checks if the this is the default translation - * of the model - * - * @return bool - */ - public function isDefault(): bool - { - if ($defaultLanguage = $this->parent->kirby()->defaultLanguage()) { - return $this->code() === $defaultLanguage->code(); - } + /** + * Checks if the this is the default translation + * of the model + * + * @return bool + */ + public function isDefault(): bool + { + if ($defaultLanguage = $this->parent->kirby()->defaultLanguage()) { + return $this->code() === $defaultLanguage->code(); + } - return false; - } + return false; + } - /** - * Returns the parent page, file or site object - * - * @return \Kirby\Cms\Model - */ - public function parent() - { - return $this->parent; - } + /** + * Returns the parent page, file or site object + * + * @return \Kirby\Cms\Model + */ + public function parent() + { + return $this->parent; + } - /** - * @param string $code - * @return $this - */ - protected function setCode(string $code) - { - $this->code = $code; - return $this; - } + /** + * @param string $code + * @return $this + */ + protected function setCode(string $code) + { + $this->code = $code; + return $this; + } - /** - * @param array|null $content - * @return $this - */ - protected function setContent(array $content = null) - { - if ($content !== null) { - $this->content = array_change_key_case($content); - } else { - $this->content = null; - } + /** + * @param array|null $content + * @return $this + */ + protected function setContent(array $content = null) + { + if ($content !== null) { + $this->content = array_change_key_case($content); + } else { + $this->content = null; + } - return $this; - } + return $this; + } - /** - * @param \Kirby\Cms\Model $parent - * @return $this - */ - protected function setParent(Model $parent) - { - $this->parent = $parent; - return $this; - } + /** + * @param \Kirby\Cms\Model $parent + * @return $this + */ + protected function setParent(Model $parent) + { + $this->parent = $parent; + return $this; + } - /** - * @param string|null $slug - * @return $this - */ - protected function setSlug(string $slug = null) - { - $this->slug = $slug; - return $this; - } + /** + * @param string|null $slug + * @return $this + */ + protected function setSlug(string $slug = null) + { + $this->slug = $slug; + return $this; + } - /** - * Returns the custom translation slug - * - * @return string|null - */ - public function slug(): ?string - { - return $this->slug ??= ($this->content()['slug'] ?? null); - } + /** + * Returns the custom translation slug + * + * @return string|null + */ + public function slug(): ?string + { + return $this->slug ??= ($this->content()['slug'] ?? null); + } - /** - * Merge the old and new data - * - * @param array|null $data - * @param bool $overwrite - * @return $this - */ - public function update(array $data = null, bool $overwrite = false) - { - $data = array_change_key_case((array)$data); - $this->content = $overwrite === true ? $data : array_merge($this->content(), $data); - return $this; - } + /** + * Merge the old and new data + * + * @param array|null $data + * @param bool $overwrite + * @return $this + */ + public function update(array $data = null, bool $overwrite = false) + { + $data = array_change_key_case((array)$data); + $this->content = $overwrite === true ? $data : array_merge($this->content(), $data); + return $this; + } - /** - * Converts the most important translation - * props to an array - * - * @return array - */ - public function toArray(): array - { - return [ - 'code' => $this->code(), - 'content' => $this->content(), - 'exists' => $this->exists(), - 'slug' => $this->slug(), - ]; - } + /** + * Converts the most important translation + * props to an array + * + * @return array + */ + public function toArray(): array + { + return [ + 'code' => $this->code(), + 'content' => $this->content(), + 'exists' => $this->exists(), + 'slug' => $this->slug(), + ]; + } } diff --git a/kirby/src/Cms/Core.php b/kirby/src/Cms/Core.php index bffa287..35eb6b3 100755 --- a/kirby/src/Cms/Core.php +++ b/kirby/src/Cms/Core.php @@ -21,457 +21,457 @@ namespace Kirby\Cms; */ class Core { - /** - * @var array - */ - protected $cache = []; + /** + * @var array + */ + protected $cache = []; - /** - * @var \Kirby\Cms\App - */ - protected $kirby; + /** + * @var \Kirby\Cms\App + */ + protected $kirby; - /** - * @var string - */ - protected $root; + /** + * @var string + */ + protected $root; - /** - * @param \Kirby\Cms\App $kirby - */ - public function __construct(App $kirby) - { - $this->kirby = $kirby; - $this->root = dirname(__DIR__, 2) . '/config'; - } + /** + * @param \Kirby\Cms\App $kirby + */ + public function __construct(App $kirby) + { + $this->kirby = $kirby; + $this->root = dirname(__DIR__, 2) . '/config'; + } - /** - * Fetches the definition array of a particular area. - * - * This is a shortcut for `$kirby->core()->load()->area()` - * to give faster access to original area code in plugins. - * - * @param string $name - * @return array|null - */ - public function area(string $name): ?array - { - return $this->load()->area($name); - } + /** + * Fetches the definition array of a particular area. + * + * This is a shortcut for `$kirby->core()->load()->area()` + * to give faster access to original area code in plugins. + * + * @param string $name + * @return array|null + */ + public function area(string $name): ?array + { + return $this->load()->area($name); + } - /** - * Returns a list of all paths to area definition files - * - * They are located in `/kirby/config/areas` - * - * @return array - */ - public function areas(): array - { - return [ - 'account' => $this->root . '/areas/account.php', - 'installation' => $this->root . '/areas/installation.php', - 'languages' => $this->root . '/areas/languages.php', - 'login' => $this->root . '/areas/login.php', - 'site' => $this->root . '/areas/site.php', - 'system' => $this->root . '/areas/system.php', - 'users' => $this->root . '/areas/users.php', - ]; - } + /** + * Returns a list of all paths to area definition files + * + * They are located in `/kirby/config/areas` + * + * @return array + */ + public function areas(): array + { + return [ + 'account' => $this->root . '/areas/account.php', + 'installation' => $this->root . '/areas/installation.php', + 'languages' => $this->root . '/areas/languages.php', + 'login' => $this->root . '/areas/login.php', + 'site' => $this->root . '/areas/site.php', + 'system' => $this->root . '/areas/system.php', + 'users' => $this->root . '/areas/users.php', + ]; + } - /** - * Returns a list of all default auth challenge classes - * - * @return array - */ - public function authChallenges(): array - { - return [ - 'email' => 'Kirby\Cms\Auth\EmailChallenge' - ]; - } + /** + * Returns a list of all default auth challenge classes + * + * @return array + */ + public function authChallenges(): array + { + return [ + 'email' => 'Kirby\Cms\Auth\EmailChallenge' + ]; + } - /** - * Returns a list of all paths to blueprint presets - * - * They are located in `/kirby/config/presets` - * - * @return array - */ - public function blueprintPresets(): array - { - return [ - 'pages' => $this->root . '/presets/pages.php', - 'page' => $this->root . '/presets/page.php', - 'files' => $this->root . '/presets/files.php', - ]; - } + /** + * Returns a list of all paths to blueprint presets + * + * They are located in `/kirby/config/presets` + * + * @return array + */ + public function blueprintPresets(): array + { + return [ + 'pages' => $this->root . '/presets/pages.php', + 'page' => $this->root . '/presets/page.php', + 'files' => $this->root . '/presets/files.php', + ]; + } - /** - * Returns a list of all paths to core blueprints - * - * They are located in `/kirby/config/blueprints`. - * Block blueprints are located in `/kirby/config/blocks` - * - * @return array - */ - public function blueprints(): array - { - return [ - // blocks - 'blocks/code' => $this->root . '/blocks/code/code.yml', - 'blocks/gallery' => $this->root . '/blocks/gallery/gallery.yml', - 'blocks/heading' => $this->root . '/blocks/heading/heading.yml', - 'blocks/image' => $this->root . '/blocks/image/image.yml', - 'blocks/line' => $this->root . '/blocks/line/line.yml', - 'blocks/list' => $this->root . '/blocks/list/list.yml', - 'blocks/markdown' => $this->root . '/blocks/markdown/markdown.yml', - 'blocks/quote' => $this->root . '/blocks/quote/quote.yml', - 'blocks/table' => $this->root . '/blocks/table/table.yml', - 'blocks/text' => $this->root . '/blocks/text/text.yml', - 'blocks/video' => $this->root . '/blocks/video/video.yml', + /** + * Returns a list of all paths to core blueprints + * + * They are located in `/kirby/config/blueprints`. + * Block blueprints are located in `/kirby/config/blocks` + * + * @return array + */ + public function blueprints(): array + { + return [ + // blocks + 'blocks/code' => $this->root . '/blocks/code/code.yml', + 'blocks/gallery' => $this->root . '/blocks/gallery/gallery.yml', + 'blocks/heading' => $this->root . '/blocks/heading/heading.yml', + 'blocks/image' => $this->root . '/blocks/image/image.yml', + 'blocks/line' => $this->root . '/blocks/line/line.yml', + 'blocks/list' => $this->root . '/blocks/list/list.yml', + 'blocks/markdown' => $this->root . '/blocks/markdown/markdown.yml', + 'blocks/quote' => $this->root . '/blocks/quote/quote.yml', + 'blocks/table' => $this->root . '/blocks/table/table.yml', + 'blocks/text' => $this->root . '/blocks/text/text.yml', + 'blocks/video' => $this->root . '/blocks/video/video.yml', - // file blueprints - 'files/default' => $this->root . '/blueprints/files/default.yml', + // file blueprints + 'files/default' => $this->root . '/blueprints/files/default.yml', - // page blueprints - 'pages/default' => $this->root . '/blueprints/pages/default.yml', + // page blueprints + 'pages/default' => $this->root . '/blueprints/pages/default.yml', - // site blueprints - 'site' => $this->root . '/blueprints/site.yml' - ]; - } + // site blueprints + 'site' => $this->root . '/blueprints/site.yml' + ]; + } - /** - * Returns a list of all cache driver classes - * - * @return array - */ - public function cacheTypes(): array - { - return [ - 'apcu' => 'Kirby\Cache\ApcuCache', - 'file' => 'Kirby\Cache\FileCache', - 'memcached' => 'Kirby\Cache\MemCached', - 'memory' => 'Kirby\Cache\MemoryCache', - ]; - } + /** + * Returns a list of all cache driver classes + * + * @return array + */ + public function cacheTypes(): array + { + return [ + 'apcu' => 'Kirby\Cache\ApcuCache', + 'file' => 'Kirby\Cache\FileCache', + 'memcached' => 'Kirby\Cache\MemCached', + 'memory' => 'Kirby\Cache\MemoryCache', + ]; + } - /** - * Returns an array of all core component functions - * - * The component functions can be found in - * `/kirby/config/components.php` - * - * @return array - */ - public function components(): array - { - return $this->cache['components'] ??= include $this->root . '/components.php'; - } + /** + * Returns an array of all core component functions + * + * The component functions can be found in + * `/kirby/config/components.php` + * + * @return array + */ + public function components(): array + { + return $this->cache['components'] ??= include $this->root . '/components.php'; + } - /** - * Returns a map of all field method aliases - * - * @return array - */ - public function fieldMethodAliases(): array - { - return [ - 'bool' => 'toBool', - 'esc' => 'escape', - 'excerpt' => 'toExcerpt', - 'float' => 'toFloat', - 'h' => 'html', - 'int' => 'toInt', - 'kt' => 'kirbytext', - 'kti' => 'kirbytextinline', - 'link' => 'toLink', - 'md' => 'markdown', - 'sp' => 'smartypants', - 'v' => 'isValid', - 'x' => 'xml' - ]; - } + /** + * Returns a map of all field method aliases + * + * @return array + */ + public function fieldMethodAliases(): array + { + return [ + 'bool' => 'toBool', + 'esc' => 'escape', + 'excerpt' => 'toExcerpt', + 'float' => 'toFloat', + 'h' => 'html', + 'int' => 'toInt', + 'kt' => 'kirbytext', + 'kti' => 'kirbytextinline', + 'link' => 'toLink', + 'md' => 'markdown', + 'sp' => 'smartypants', + 'v' => 'isValid', + 'x' => 'xml' + ]; + } - /** - * Returns an array of all field method functions - * - * Field methods are stored in `/kirby/config/methods.php` - * - * @return array - */ - public function fieldMethods(): array - { - return $this->cache['fieldMethods'] ??= (include $this->root . '/methods.php')($this->kirby); - } + /** + * Returns an array of all field method functions + * + * Field methods are stored in `/kirby/config/methods.php` + * + * @return array + */ + public function fieldMethods(): array + { + return $this->cache['fieldMethods'] ??= (include $this->root . '/methods.php')($this->kirby); + } - /** - * Returns an array of paths for field mixins - * - * They are located in `/kirby/config/fields/mixins` - * - * @return array - */ - public function fieldMixins(): array - { - return [ - 'datetime' => $this->root . '/fields/mixins/datetime.php', - 'filepicker' => $this->root . '/fields/mixins/filepicker.php', - 'layout' => $this->root . '/fields/mixins/layout.php', - 'min' => $this->root . '/fields/mixins/min.php', - 'options' => $this->root . '/fields/mixins/options.php', - 'pagepicker' => $this->root . '/fields/mixins/pagepicker.php', - 'picker' => $this->root . '/fields/mixins/picker.php', - 'upload' => $this->root . '/fields/mixins/upload.php', - 'userpicker' => $this->root . '/fields/mixins/userpicker.php', - ]; - } + /** + * Returns an array of paths for field mixins + * + * They are located in `/kirby/config/fields/mixins` + * + * @return array + */ + public function fieldMixins(): array + { + return [ + 'datetime' => $this->root . '/fields/mixins/datetime.php', + 'filepicker' => $this->root . '/fields/mixins/filepicker.php', + 'layout' => $this->root . '/fields/mixins/layout.php', + 'min' => $this->root . '/fields/mixins/min.php', + 'options' => $this->root . '/fields/mixins/options.php', + 'pagepicker' => $this->root . '/fields/mixins/pagepicker.php', + 'picker' => $this->root . '/fields/mixins/picker.php', + 'upload' => $this->root . '/fields/mixins/upload.php', + 'userpicker' => $this->root . '/fields/mixins/userpicker.php', + ]; + } - /** - * Returns an array of all paths and class names of panel fields - * - * Traditional panel fields are located in `/kirby/config/fields` - * - * The more complex field classes can be found in - * `/kirby/src/Form/Fields` - * - * @return array - */ - public function fields(): array - { - return [ - 'blocks' => 'Kirby\Form\Field\BlocksField', - 'checkboxes' => $this->root . '/fields/checkboxes.php', - 'date' => $this->root . '/fields/date.php', - 'email' => $this->root . '/fields/email.php', - 'files' => $this->root . '/fields/files.php', - 'gap' => $this->root . '/fields/gap.php', - 'headline' => $this->root . '/fields/headline.php', - 'hidden' => $this->root . '/fields/hidden.php', - 'info' => $this->root . '/fields/info.php', - 'layout' => 'Kirby\Form\Field\LayoutField', - 'line' => $this->root . '/fields/line.php', - 'list' => $this->root . '/fields/list.php', - 'multiselect' => $this->root . '/fields/multiselect.php', - 'number' => $this->root . '/fields/number.php', - 'pages' => $this->root . '/fields/pages.php', - 'radio' => $this->root . '/fields/radio.php', - 'range' => $this->root . '/fields/range.php', - 'select' => $this->root . '/fields/select.php', - 'slug' => $this->root . '/fields/slug.php', - 'structure' => $this->root . '/fields/structure.php', - 'tags' => $this->root . '/fields/tags.php', - 'tel' => $this->root . '/fields/tel.php', - 'text' => $this->root . '/fields/text.php', - 'textarea' => $this->root . '/fields/textarea.php', - 'time' => $this->root . '/fields/time.php', - 'toggle' => $this->root . '/fields/toggle.php', - 'toggles' => $this->root . '/fields/toggles.php', - 'url' => $this->root . '/fields/url.php', - 'users' => $this->root . '/fields/users.php', - 'writer' => $this->root . '/fields/writer.php' - ]; - } + /** + * Returns an array of all paths and class names of panel fields + * + * Traditional panel fields are located in `/kirby/config/fields` + * + * The more complex field classes can be found in + * `/kirby/src/Form/Fields` + * + * @return array + */ + public function fields(): array + { + return [ + 'blocks' => 'Kirby\Form\Field\BlocksField', + 'checkboxes' => $this->root . '/fields/checkboxes.php', + 'date' => $this->root . '/fields/date.php', + 'email' => $this->root . '/fields/email.php', + 'files' => $this->root . '/fields/files.php', + 'gap' => $this->root . '/fields/gap.php', + 'headline' => $this->root . '/fields/headline.php', + 'hidden' => $this->root . '/fields/hidden.php', + 'info' => $this->root . '/fields/info.php', + 'layout' => 'Kirby\Form\Field\LayoutField', + 'line' => $this->root . '/fields/line.php', + 'list' => $this->root . '/fields/list.php', + 'multiselect' => $this->root . '/fields/multiselect.php', + 'number' => $this->root . '/fields/number.php', + 'pages' => $this->root . '/fields/pages.php', + 'radio' => $this->root . '/fields/radio.php', + 'range' => $this->root . '/fields/range.php', + 'select' => $this->root . '/fields/select.php', + 'slug' => $this->root . '/fields/slug.php', + 'structure' => $this->root . '/fields/structure.php', + 'tags' => $this->root . '/fields/tags.php', + 'tel' => $this->root . '/fields/tel.php', + 'text' => $this->root . '/fields/text.php', + 'textarea' => $this->root . '/fields/textarea.php', + 'time' => $this->root . '/fields/time.php', + 'toggle' => $this->root . '/fields/toggle.php', + 'toggles' => $this->root . '/fields/toggles.php', + 'url' => $this->root . '/fields/url.php', + 'users' => $this->root . '/fields/users.php', + 'writer' => $this->root . '/fields/writer.php' + ]; + } - /** - * Returns a map of all kirbytag aliases - * - * @return array - */ - public function kirbyTagAliases(): array - { - return [ - 'youtube' => 'video', - 'vimeo' => 'video' - ]; - } + /** + * Returns a map of all kirbytag aliases + * + * @return array + */ + public function kirbyTagAliases(): array + { + return [ + 'youtube' => 'video', + 'vimeo' => 'video' + ]; + } - /** - * Returns an array of all kirbytag definitions - * - * They are located in `/kirby/config/tags.php` - * - * @return array - */ - public function kirbyTags(): array - { - return $this->cache['kirbytags'] ??= include $this->root . '/tags.php'; - } + /** + * Returns an array of all kirbytag definitions + * + * They are located in `/kirby/config/tags.php` + * + * @return array + */ + public function kirbyTags(): array + { + return $this->cache['kirbytags'] ??= include $this->root . '/tags.php'; + } - /** - * Loads a core part of Kirby - * - * The loader is set to not include plugins. - * This way, you can access original Kirby core code - * through this load method. - * - * @return \Kirby\Cms\Loader - */ - public function load() - { - return new Loader($this->kirby, false); - } + /** + * Loads a core part of Kirby + * + * The loader is set to not include plugins. + * This way, you can access original Kirby core code + * through this load method. + * + * @return \Kirby\Cms\Loader + */ + public function load() + { + return new Loader($this->kirby, false); + } - /** - * Returns all absolute paths to important directories - * - * Roots are resolved and baked in `\Kirby\Cms\App::bakeRoots()` - * - * @return array - */ - public function roots(): array - { - return $this->cache['roots'] ??= [ - 'kirby' => fn (array $roots) => dirname(__DIR__, 2), - 'i18n' => fn (array $roots) => $roots['kirby'] . '/i18n', - 'i18n:translations' => fn (array $roots) => $roots['i18n'] . '/translations', - 'i18n:rules' => fn (array $roots) => $roots['i18n'] . '/rules', + /** + * Returns all absolute paths to important directories + * + * Roots are resolved and baked in `\Kirby\Cms\App::bakeRoots()` + * + * @return array + */ + public function roots(): array + { + return $this->cache['roots'] ??= [ + 'kirby' => fn (array $roots) => dirname(__DIR__, 2), + 'i18n' => fn (array $roots) => $roots['kirby'] . '/i18n', + 'i18n:translations' => fn (array $roots) => $roots['i18n'] . '/translations', + 'i18n:rules' => fn (array $roots) => $roots['i18n'] . '/rules', - 'index' => fn (array $roots) => dirname(__DIR__, 3), - 'assets' => fn (array $roots) => $roots['index'] . '/assets', - 'content' => fn (array $roots) => $roots['index'] . '/content', - 'media' => fn (array $roots) => $roots['index'] . '/media', - 'panel' => fn (array $roots) => $roots['kirby'] . '/panel', - 'site' => fn (array $roots) => $roots['index'] . '/site', - 'accounts' => fn (array $roots) => $roots['site'] . '/accounts', - 'blueprints' => fn (array $roots) => $roots['site'] . '/blueprints', - 'cache' => fn (array $roots) => $roots['site'] . '/cache', - 'collections' => fn (array $roots) => $roots['site'] . '/collections', - 'config' => fn (array $roots) => $roots['site'] . '/config', - 'controllers' => fn (array $roots) => $roots['site'] . '/controllers', - 'languages' => fn (array $roots) => $roots['site'] . '/languages', - 'license' => fn (array $roots) => $roots['config'] . '/.license', - 'logs' => fn (array $roots) => $roots['site'] . '/logs', - 'models' => fn (array $roots) => $roots['site'] . '/models', - 'plugins' => fn (array $roots) => $roots['site'] . '/plugins', - 'sessions' => fn (array $roots) => $roots['site'] . '/sessions', - 'snippets' => fn (array $roots) => $roots['site'] . '/snippets', - 'templates' => fn (array $roots) => $roots['site'] . '/templates', - 'roles' => fn (array $roots) => $roots['blueprints'] . '/users', - ]; - } + 'index' => fn (array $roots) => dirname(__DIR__, 3), + 'assets' => fn (array $roots) => $roots['index'] . '/assets', + 'content' => fn (array $roots) => $roots['index'] . '/content', + 'media' => fn (array $roots) => $roots['index'] . '/media', + 'panel' => fn (array $roots) => $roots['kirby'] . '/panel', + 'site' => fn (array $roots) => $roots['index'] . '/site', + 'accounts' => fn (array $roots) => $roots['site'] . '/accounts', + 'blueprints' => fn (array $roots) => $roots['site'] . '/blueprints', + 'cache' => fn (array $roots) => $roots['site'] . '/cache', + 'collections' => fn (array $roots) => $roots['site'] . '/collections', + 'config' => fn (array $roots) => $roots['site'] . '/config', + 'controllers' => fn (array $roots) => $roots['site'] . '/controllers', + 'languages' => fn (array $roots) => $roots['site'] . '/languages', + 'license' => fn (array $roots) => $roots['config'] . '/.license', + 'logs' => fn (array $roots) => $roots['site'] . '/logs', + 'models' => fn (array $roots) => $roots['site'] . '/models', + 'plugins' => fn (array $roots) => $roots['site'] . '/plugins', + 'sessions' => fn (array $roots) => $roots['site'] . '/sessions', + 'snippets' => fn (array $roots) => $roots['site'] . '/snippets', + 'templates' => fn (array $roots) => $roots['site'] . '/templates', + 'roles' => fn (array $roots) => $roots['blueprints'] . '/users', + ]; + } - /** - * Returns an array of all routes for Kirby’s router - * - * Routes are split into `before` and `after` routes. - * - * Plugin routes will be injected inbetween. - * - * @return array - */ - public function routes(): array - { - return $this->cache['routes'] ??= (include $this->root . '/routes.php')($this->kirby); - } + /** + * Returns an array of all routes for Kirby’s router + * + * Routes are split into `before` and `after` routes. + * + * Plugin routes will be injected inbetween. + * + * @return array + */ + public function routes(): array + { + return $this->cache['routes'] ??= (include $this->root . '/routes.php')($this->kirby); + } - /** - * Returns a list of all paths to core block snippets - * - * They are located in `/kirby/config/blocks` - * - * @return array - */ - public function snippets(): array - { - return [ - 'blocks/code' => $this->root . '/blocks/code/code.php', - 'blocks/gallery' => $this->root . '/blocks/gallery/gallery.php', - 'blocks/heading' => $this->root . '/blocks/heading/heading.php', - 'blocks/image' => $this->root . '/blocks/image/image.php', - 'blocks/line' => $this->root . '/blocks/line/line.php', - 'blocks/list' => $this->root . '/blocks/list/list.php', - 'blocks/markdown' => $this->root . '/blocks/markdown/markdown.php', - 'blocks/quote' => $this->root . '/blocks/quote/quote.php', - 'blocks/table' => $this->root . '/blocks/table/table.php', - 'blocks/text' => $this->root . '/blocks/text/text.php', - 'blocks/video' => $this->root . '/blocks/video/video.php', - ]; - } + /** + * Returns a list of all paths to core block snippets + * + * They are located in `/kirby/config/blocks` + * + * @return array + */ + public function snippets(): array + { + return [ + 'blocks/code' => $this->root . '/blocks/code/code.php', + 'blocks/gallery' => $this->root . '/blocks/gallery/gallery.php', + 'blocks/heading' => $this->root . '/blocks/heading/heading.php', + 'blocks/image' => $this->root . '/blocks/image/image.php', + 'blocks/line' => $this->root . '/blocks/line/line.php', + 'blocks/list' => $this->root . '/blocks/list/list.php', + 'blocks/markdown' => $this->root . '/blocks/markdown/markdown.php', + 'blocks/quote' => $this->root . '/blocks/quote/quote.php', + 'blocks/table' => $this->root . '/blocks/table/table.php', + 'blocks/text' => $this->root . '/blocks/text/text.php', + 'blocks/video' => $this->root . '/blocks/video/video.php', + ]; + } - /** - * Returns a list of paths to section mixins - * - * They are located in `/kirby/config/sections/mixins` - * - * @return array - */ - public function sectionMixins(): array - { - return [ - 'details' => $this->root . '/sections/mixins/details.php', - 'empty' => $this->root . '/sections/mixins/empty.php', - 'headline' => $this->root . '/sections/mixins/headline.php', - 'help' => $this->root . '/sections/mixins/help.php', - 'layout' => $this->root . '/sections/mixins/layout.php', - 'max' => $this->root . '/sections/mixins/max.php', - 'min' => $this->root . '/sections/mixins/min.php', - 'pagination' => $this->root . '/sections/mixins/pagination.php', - 'parent' => $this->root . '/sections/mixins/parent.php', - 'search' => $this->root . '/sections/mixins/search.php', - 'sort' => $this->root . '/sections/mixins/sort.php', - ]; - } + /** + * Returns a list of paths to section mixins + * + * They are located in `/kirby/config/sections/mixins` + * + * @return array + */ + public function sectionMixins(): array + { + return [ + 'details' => $this->root . '/sections/mixins/details.php', + 'empty' => $this->root . '/sections/mixins/empty.php', + 'headline' => $this->root . '/sections/mixins/headline.php', + 'help' => $this->root . '/sections/mixins/help.php', + 'layout' => $this->root . '/sections/mixins/layout.php', + 'max' => $this->root . '/sections/mixins/max.php', + 'min' => $this->root . '/sections/mixins/min.php', + 'pagination' => $this->root . '/sections/mixins/pagination.php', + 'parent' => $this->root . '/sections/mixins/parent.php', + 'search' => $this->root . '/sections/mixins/search.php', + 'sort' => $this->root . '/sections/mixins/sort.php', + ]; + } - /** - * Returns a list of all section definitions - * - * They are located in `/kirby/config/sections` - * - * @return array - */ - public function sections(): array - { - return [ - 'fields' => $this->root . '/sections/fields.php', - 'files' => $this->root . '/sections/files.php', - 'info' => $this->root . '/sections/info.php', - 'pages' => $this->root . '/sections/pages.php', - 'stats' => $this->root . '/sections/stats.php', - ]; - } + /** + * Returns a list of all section definitions + * + * They are located in `/kirby/config/sections` + * + * @return array + */ + public function sections(): array + { + return [ + 'fields' => $this->root . '/sections/fields.php', + 'files' => $this->root . '/sections/files.php', + 'info' => $this->root . '/sections/info.php', + 'pages' => $this->root . '/sections/pages.php', + 'stats' => $this->root . '/sections/stats.php', + ]; + } - /** - * Returns a list of paths to all system templates - * - * They are located in `/kirby/config/templates` - * - * @return array - */ - public function templates(): array - { - return [ - 'emails/auth/login' => $this->root . '/templates/emails/auth/login.php', - 'emails/auth/password-reset' => $this->root . '/templates/emails/auth/password-reset.php' - ]; - } + /** + * Returns a list of paths to all system templates + * + * They are located in `/kirby/config/templates` + * + * @return array + */ + public function templates(): array + { + return [ + 'emails/auth/login' => $this->root . '/templates/emails/auth/login.php', + 'emails/auth/password-reset' => $this->root . '/templates/emails/auth/password-reset.php' + ]; + } - /** - * Returns an array with all system URLs - * - * URLs are resolved and baked in `\Kirby\Cms\App::bakeUrls()` - * - * @return array - */ - public function urls(): array - { - return $this->cache['urls'] ??= [ - 'index' => fn () => $this->kirby->environment()->baseUrl(), - 'base' => fn (array $urls) => rtrim($urls['index'], '/'), - 'current' => function (array $urls) { - $path = trim($this->kirby->path(), '/'); + /** + * Returns an array with all system URLs + * + * URLs are resolved and baked in `\Kirby\Cms\App::bakeUrls()` + * + * @return array + */ + public function urls(): array + { + return $this->cache['urls'] ??= [ + 'index' => fn () => $this->kirby->environment()->baseUrl(), + 'base' => fn (array $urls) => rtrim($urls['index'], '/'), + 'current' => function (array $urls) { + $path = trim($this->kirby->path(), '/'); - if (empty($path) === true) { - return $urls['index']; - } else { - return $urls['base'] . '/' . $path; - } - }, - 'assets' => fn (array $urls) => $urls['base'] . '/assets', - 'api' => fn (array $urls) => $urls['base'] . '/' . $this->kirby->option('api.slug', 'api'), - 'media' => fn (array $urls) => $urls['base'] . '/media', - 'panel' => fn (array $urls) => $urls['base'] . '/' . $this->kirby->option('panel.slug', 'panel') - ]; - } + if (empty($path) === true) { + return $urls['index']; + } else { + return $urls['base'] . '/' . $path; + } + }, + 'assets' => fn (array $urls) => $urls['base'] . '/assets', + 'api' => fn (array $urls) => $urls['base'] . '/' . $this->kirby->option('api.slug', 'api'), + 'media' => fn (array $urls) => $urls['base'] . '/media', + 'panel' => fn (array $urls) => $urls['base'] . '/' . $this->kirby->option('panel.slug', 'panel') + ]; + } } diff --git a/kirby/src/Cms/Email.php b/kirby/src/Cms/Email.php index 8943a84..e6550d8 100755 --- a/kirby/src/Cms/Email.php +++ b/kirby/src/Cms/Email.php @@ -19,237 +19,237 @@ use Kirby\Exception\NotFoundException; */ class Email { - /** - * Options configured through the `email` CMS option - * - * @var array - */ - protected $options; + /** + * Options configured through the `email` CMS option + * + * @var array + */ + protected $options; - /** - * Props for the email object; will be passed to the - * Kirby\Email\Email class - * - * @var array - */ - protected $props; + /** + * Props for the email object; will be passed to the + * Kirby\Email\Email class + * + * @var array + */ + protected $props; - /** - * Class constructor - * - * @param string|array $preset Preset name from the config or a simple props array - * @param array $props Props array to override the $preset - */ - public function __construct($preset = [], array $props = []) - { - $this->options = App::instance()->option('email'); + /** + * Class constructor + * + * @param string|array $preset Preset name from the config or a simple props array + * @param array $props Props array to override the $preset + */ + public function __construct($preset = [], array $props = []) + { + $this->options = App::instance()->option('email'); - // build a prop array based on preset and props - $preset = $this->preset($preset); - $this->props = array_merge($preset, $props); + // build a prop array based on preset and props + $preset = $this->preset($preset); + $this->props = array_merge($preset, $props); - // add transport settings - if (isset($this->props['transport']) === false) { - $this->props['transport'] = $this->options['transport'] ?? []; - } + // add transport settings + if (isset($this->props['transport']) === false) { + $this->props['transport'] = $this->options['transport'] ?? []; + } - // add predefined beforeSend option - if (isset($this->props['beforeSend']) === false) { - $this->props['beforeSend'] = $this->options['beforeSend'] ?? null; - } + // add predefined beforeSend option + if (isset($this->props['beforeSend']) === false) { + $this->props['beforeSend'] = $this->options['beforeSend'] ?? null; + } - // transform model objects to values - $this->transformUserSingle('from', 'fromName'); - $this->transformUserSingle('replyTo', 'replyToName'); - $this->transformUserMultiple('to'); - $this->transformUserMultiple('cc'); - $this->transformUserMultiple('bcc'); - $this->transformFile('attachments'); + // transform model objects to values + $this->transformUserSingle('from', 'fromName'); + $this->transformUserSingle('replyTo', 'replyToName'); + $this->transformUserMultiple('to'); + $this->transformUserMultiple('cc'); + $this->transformUserMultiple('bcc'); + $this->transformFile('attachments'); - // load template for body text - $this->template(); - } + // load template for body text + $this->template(); + } - /** - * Grabs a preset from the options; supports fixed - * prop arrays in case a preset is not needed - * - * @param string|array $preset Preset name or simple prop array - * @return array - * @throws \Kirby\Exception\NotFoundException - */ - protected function preset($preset): array - { - // only passed props, not preset name - if (is_array($preset) === true) { - return $preset; - } + /** + * Grabs a preset from the options; supports fixed + * prop arrays in case a preset is not needed + * + * @param string|array $preset Preset name or simple prop array + * @return array + * @throws \Kirby\Exception\NotFoundException + */ + protected function preset($preset): array + { + // only passed props, not preset name + if (is_array($preset) === true) { + return $preset; + } - // preset does not exist - if (isset($this->options['presets'][$preset]) !== true) { - throw new NotFoundException([ - 'key' => 'email.preset.notFound', - 'data' => ['name' => $preset] - ]); - } + // preset does not exist + if (isset($this->options['presets'][$preset]) !== true) { + throw new NotFoundException([ + 'key' => 'email.preset.notFound', + 'data' => ['name' => $preset] + ]); + } - return $this->options['presets'][$preset]; - } + return $this->options['presets'][$preset]; + } - /** - * Renders the email template(s) and sets the body props - * to the result - * - * @return void - * @throws \Kirby\Exception\NotFoundException - */ - protected function template(): void - { - if (isset($this->props['template']) === true) { + /** + * Renders the email template(s) and sets the body props + * to the result + * + * @return void + * @throws \Kirby\Exception\NotFoundException + */ + protected function template(): void + { + if (isset($this->props['template']) === true) { - // prepare data to be passed to template - $data = $this->props['data'] ?? []; + // prepare data to be passed to template + $data = $this->props['data'] ?? []; - // check if html/text templates exist - $html = $this->getTemplate($this->props['template'], 'html'); - $text = $this->getTemplate($this->props['template'], 'text'); + // check if html/text templates exist + $html = $this->getTemplate($this->props['template'], 'html'); + $text = $this->getTemplate($this->props['template'], 'text'); - if ($html->exists()) { - $this->props['body'] = [ - 'html' => $html->render($data) - ]; + if ($html->exists()) { + $this->props['body'] = [ + 'html' => $html->render($data) + ]; - if ($text->exists()) { - $this->props['body']['text'] = $text->render($data); - } + if ($text->exists()) { + $this->props['body']['text'] = $text->render($data); + } - // fallback to single email text template - } elseif ($text->exists()) { - $this->props['body'] = $text->render($data); - } else { - throw new NotFoundException('The email template "' . $this->props['template'] . '" cannot be found'); - } - } - } + // fallback to single email text template + } elseif ($text->exists()) { + $this->props['body'] = $text->render($data); + } else { + throw new NotFoundException('The email template "' . $this->props['template'] . '" cannot be found'); + } + } + } - /** - * Returns an email template by name and type - * - * @param string $name Template name - * @param string|null $type `html` or `text` - * @return \Kirby\Cms\Template - */ - protected function getTemplate(string $name, string $type = null) - { - return App::instance()->template('emails/' . $name, $type, 'text'); - } + /** + * Returns an email template by name and type + * + * @param string $name Template name + * @param string|null $type `html` or `text` + * @return \Kirby\Cms\Template + */ + protected function getTemplate(string $name, string $type = null) + { + return App::instance()->template('emails/' . $name, $type, 'text'); + } - /** - * Returns the prop array - * - * @return array - */ - public function toArray(): array - { - return $this->props; - } + /** + * Returns the prop array + * + * @return array + */ + public function toArray(): array + { + return $this->props; + } - /** - * Transforms file object(s) to an array of file roots; - * supports simple strings, file objects or collections/arrays of either - * - * @param string $prop Prop to transform - * @return void - */ - protected function transformFile(string $prop): void - { - $this->props[$prop] = $this->transformModel($prop, 'Kirby\Cms\File', 'root'); - } + /** + * Transforms file object(s) to an array of file roots; + * supports simple strings, file objects or collections/arrays of either + * + * @param string $prop Prop to transform + * @return void + */ + protected function transformFile(string $prop): void + { + $this->props[$prop] = $this->transformModel($prop, 'Kirby\Cms\File', 'root'); + } - /** - * Transforms Kirby models to a simplified collection - * - * @param string $prop Prop to transform - * @param string $class Fully qualified class name of the supported model - * @param string $contentValue Model method that returns the array value - * @param string|null $contentKey Optional model method that returns the array key; - * returns a simple value-only array if not given - * @return array Simple key-value or just value array with the transformed prop data - */ - protected function transformModel(string $prop, string $class, string $contentValue, string $contentKey = null): array - { - $value = $this->props[$prop] ?? []; + /** + * Transforms Kirby models to a simplified collection + * + * @param string $prop Prop to transform + * @param string $class Fully qualified class name of the supported model + * @param string $contentValue Model method that returns the array value + * @param string|null $contentKey Optional model method that returns the array key; + * returns a simple value-only array if not given + * @return array Simple key-value or just value array with the transformed prop data + */ + protected function transformModel(string $prop, string $class, string $contentValue, string $contentKey = null): array + { + $value = $this->props[$prop] ?? []; - // ensure consistent input by making everything an iterable value - if (is_iterable($value) !== true) { - $value = [$value]; - } + // ensure consistent input by making everything an iterable value + if (is_iterable($value) !== true) { + $value = [$value]; + } - $result = []; - foreach ($value as $key => $item) { - if (is_string($item) === true) { - // value is already a string - if ($contentKey !== null && is_string($key) === true) { - $result[$key] = $item; - } else { - $result[] = $item; - } - } elseif (is_a($item, $class) === true) { - // value is a model object, get value through content method(s) - if ($contentKey !== null) { - $result[(string)$item->$contentKey()] = (string)$item->$contentValue(); - } else { - $result[] = (string)$item->$contentValue(); - } - } else { - // invalid input - throw new InvalidArgumentException('Invalid input for prop "' . $prop . '", expected string or "' . $class . '" object or collection'); - } - } + $result = []; + foreach ($value as $key => $item) { + if (is_string($item) === true) { + // value is already a string + if ($contentKey !== null && is_string($key) === true) { + $result[$key] = $item; + } else { + $result[] = $item; + } + } elseif (is_a($item, $class) === true) { + // value is a model object, get value through content method(s) + if ($contentKey !== null) { + $result[(string)$item->$contentKey()] = (string)$item->$contentValue(); + } else { + $result[] = (string)$item->$contentValue(); + } + } else { + // invalid input + throw new InvalidArgumentException('Invalid input for prop "' . $prop . '", expected string or "' . $class . '" object or collection'); + } + } - return $result; - } + return $result; + } - /** - * Transforms an user object to the email address and name; - * supports simple strings, user objects or collections/arrays of either - * (note: only the first item in a collection/array will be used) - * - * @param string $addressProp Prop with the email address - * @param string $nameProp Prop with the name corresponding to the $addressProp - * @return void - */ - protected function transformUserSingle(string $addressProp, string $nameProp): void - { - $result = $this->transformModel($addressProp, 'Kirby\Cms\User', 'name', 'email'); + /** + * Transforms an user object to the email address and name; + * supports simple strings, user objects or collections/arrays of either + * (note: only the first item in a collection/array will be used) + * + * @param string $addressProp Prop with the email address + * @param string $nameProp Prop with the name corresponding to the $addressProp + * @return void + */ + protected function transformUserSingle(string $addressProp, string $nameProp): void + { + $result = $this->transformModel($addressProp, 'Kirby\Cms\User', 'name', 'email'); - $address = array_keys($result)[0] ?? null; - $name = $result[$address] ?? null; + $address = array_keys($result)[0] ?? null; + $name = $result[$address] ?? null; - // if the array is non-associative, the value is the address - if (is_int($address) === true) { - $address = $name; - $name = null; - } + // if the array is non-associative, the value is the address + if (is_int($address) === true) { + $address = $name; + $name = null; + } - // always use the address as we have transformed that prop above - $this->props[$addressProp] = $address; + // always use the address as we have transformed that prop above + $this->props[$addressProp] = $address; - // only use the name from the user if no custom name was set - if (isset($this->props[$nameProp]) === false || $this->props[$nameProp] === null) { - $this->props[$nameProp] = $name; - } - } + // only use the name from the user if no custom name was set + if (isset($this->props[$nameProp]) === false || $this->props[$nameProp] === null) { + $this->props[$nameProp] = $name; + } + } - /** - * Transforms user object(s) to the email address(es) and name(s); - * supports simple strings, user objects or collections/arrays of either - * - * @param string $prop Prop to transform - * @return void - */ - protected function transformUserMultiple(string $prop): void - { - $this->props[$prop] = $this->transformModel($prop, 'Kirby\Cms\User', 'name', 'email'); - } + /** + * Transforms user object(s) to the email address(es) and name(s); + * supports simple strings, user objects or collections/arrays of either + * + * @param string $prop Prop to transform + * @return void + */ + protected function transformUserMultiple(string $prop): void + { + $this->props[$prop] = $this->transformModel($prop, 'Kirby\Cms\User', 'name', 'email'); + } } diff --git a/kirby/src/Cms/Event.php b/kirby/src/Cms/Event.php index 40d5af0..c6ed0c2 100755 --- a/kirby/src/Cms/Event.php +++ b/kirby/src/Cms/Event.php @@ -21,270 +21,270 @@ use Kirby\Toolkit\Controller; */ class Event { - /** - * The full event name - * (e.g. `page.create:after`) - * - * @var string - */ - protected $name; + /** + * The full event name + * (e.g. `page.create:after`) + * + * @var string + */ + protected $name; - /** - * The event type - * (e.g. `page` in `page.create:after`) - * - * @var string - */ - protected $type; + /** + * The event type + * (e.g. `page` in `page.create:after`) + * + * @var string + */ + protected $type; - /** - * The event action - * (e.g. `create` in `page.create:after`) - * - * @var string|null - */ - protected $action; + /** + * The event action + * (e.g. `create` in `page.create:after`) + * + * @var string|null + */ + protected $action; - /** - * The event state - * (e.g. `after` in `page.create:after`) - * - * @var string|null - */ - protected $state; + /** + * The event state + * (e.g. `after` in `page.create:after`) + * + * @var string|null + */ + protected $state; - /** - * The event arguments - * - * @var array - */ - protected $arguments = []; + /** + * The event arguments + * + * @var array + */ + protected $arguments = []; - /** - * Class constructor - * - * @param string $name Full event name - * @param array $arguments Associative array of named event arguments - */ - public function __construct(string $name, array $arguments = []) - { - // split the event name into `$type.$action:$state` - // $action and $state are optional; - // if there is more than one dot, $type will be greedy - $regex = '/^(?.+?)(?:\.(?[^.]*?))?(?:\:(?.*))?$/'; - preg_match($regex, $name, $matches, PREG_UNMATCHED_AS_NULL); + /** + * Class constructor + * + * @param string $name Full event name + * @param array $arguments Associative array of named event arguments + */ + public function __construct(string $name, array $arguments = []) + { + // split the event name into `$type.$action:$state` + // $action and $state are optional; + // if there is more than one dot, $type will be greedy + $regex = '/^(?.+?)(?:\.(?[^.]*?))?(?:\:(?.*))?$/'; + preg_match($regex, $name, $matches, PREG_UNMATCHED_AS_NULL); - $this->name = $name; - $this->type = $matches['type']; - $this->action = $matches['action'] ?? null; - $this->state = $matches['state'] ?? null; - $this->arguments = $arguments; - } + $this->name = $name; + $this->type = $matches['type']; + $this->action = $matches['action'] ?? null; + $this->state = $matches['state'] ?? null; + $this->arguments = $arguments; + } - /** - * Magic caller for event arguments - * - * @param string $method - * @param array $arguments - * @return mixed - */ - public function __call(string $method, array $arguments = []) - { - return $this->argument($method); - } + /** + * Magic caller for event arguments + * + * @param string $method + * @param array $arguments + * @return mixed + */ + public function __call(string $method, array $arguments = []) + { + return $this->argument($method); + } - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return $this->toArray(); - } + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return $this->toArray(); + } - /** - * Makes it possible to simply echo - * or stringify the entire object - * - * @return string - */ - public function __toString(): string - { - return $this->toString(); - } + /** + * Makes it possible to simply echo + * or stringify the entire object + * + * @return string + */ + public function __toString(): string + { + return $this->toString(); + } - /** - * Returns the action of the event (e.g. `create`) - * or `null` if the event name does not include an action - * - * @return string|null - */ - public function action(): ?string - { - return $this->action; - } + /** + * Returns the action of the event (e.g. `create`) + * or `null` if the event name does not include an action + * + * @return string|null + */ + public function action(): ?string + { + return $this->action; + } - /** - * Returns a specific event argument - * - * @param string $name - * @return mixed - */ - public function argument(string $name) - { - if (isset($this->arguments[$name]) === true) { - return $this->arguments[$name]; - } + /** + * Returns a specific event argument + * + * @param string $name + * @return mixed + */ + public function argument(string $name) + { + if (isset($this->arguments[$name]) === true) { + return $this->arguments[$name]; + } - return null; - } + return null; + } - /** - * Returns the arguments of the event - * - * @return array - */ - public function arguments(): array - { - return $this->arguments; - } + /** + * Returns the arguments of the event + * + * @return array + */ + public function arguments(): array + { + return $this->arguments; + } - /** - * Calls a hook with the event data and returns - * the hook's return value - * - * @param object|null $bind Optional object to bind to the hook function - * @param \Closure $hook - * @return mixed - */ - public function call(?object $bind, Closure $hook) - { - // collect the list of possible hook arguments - $data = $this->arguments(); - $data['event'] = $this; + /** + * Calls a hook with the event data and returns + * the hook's return value + * + * @param object|null $bind Optional object to bind to the hook function + * @param \Closure $hook + * @return mixed + */ + public function call(?object $bind, Closure $hook) + { + // collect the list of possible hook arguments + $data = $this->arguments(); + $data['event'] = $this; - // magically call the hook with the arguments it requested - $hook = new Controller($hook); - return $hook->call($bind, $data); - } + // magically call the hook with the arguments it requested + $hook = new Controller($hook); + return $hook->call($bind, $data); + } - /** - * Returns the full name of the event - * - * @return string - */ - public function name(): string - { - return $this->name; - } + /** + * Returns the full name of the event + * + * @return string + */ + public function name(): string + { + return $this->name; + } - /** - * Returns the full list of possible wildcard - * event names based on the current event name - * - * @return array - */ - public function nameWildcards(): array - { - // if the event is already a wildcard event, no further variation is possible - if ($this->type === '*' || $this->action === '*' || $this->state === '*') { - return []; - } + /** + * Returns the full list of possible wildcard + * event names based on the current event name + * + * @return array + */ + public function nameWildcards(): array + { + // if the event is already a wildcard event, no further variation is possible + if ($this->type === '*' || $this->action === '*' || $this->state === '*') { + return []; + } - if ($this->action !== null && $this->state !== null) { - // full $type.$action:$state event + if ($this->action !== null && $this->state !== null) { + // full $type.$action:$state event - return [ - $this->type . '.*:' . $this->state, - $this->type . '.' . $this->action . ':*', - $this->type . '.*:*', - '*.' . $this->action . ':' . $this->state, - '*.' . $this->action . ':*', - '*:' . $this->state, - '*' - ]; - } elseif ($this->state !== null) { - // event without action: $type:$state + return [ + $this->type . '.*:' . $this->state, + $this->type . '.' . $this->action . ':*', + $this->type . '.*:*', + '*.' . $this->action . ':' . $this->state, + '*.' . $this->action . ':*', + '*:' . $this->state, + '*' + ]; + } elseif ($this->state !== null) { + // event without action: $type:$state - return [ - $this->type . ':*', - '*:' . $this->state, - '*' - ]; - } elseif ($this->action !== null) { - // event without state: $type.$action + return [ + $this->type . ':*', + '*:' . $this->state, + '*' + ]; + } elseif ($this->action !== null) { + // event without state: $type.$action - return [ - $this->type . '.*', - '*.' . $this->action, - '*' - ]; - } else { - // event with a simple name + return [ + $this->type . '.*', + '*.' . $this->action, + '*' + ]; + } else { + // event with a simple name - return ['*']; - } - } + return ['*']; + } + } - /** - * Returns the state of the event (e.g. `after`) - * - * @return string|null - */ - public function state(): ?string - { - return $this->state; - } + /** + * Returns the state of the event (e.g. `after`) + * + * @return string|null + */ + public function state(): ?string + { + return $this->state; + } - /** - * Returns the event data as array - * - * @return array - */ - public function toArray(): array - { - return [ - 'name' => $this->name, - 'arguments' => $this->arguments - ]; - } + /** + * Returns the event data as array + * + * @return array + */ + public function toArray(): array + { + return [ + 'name' => $this->name, + 'arguments' => $this->arguments + ]; + } - /** - * Returns the event name as string - * - * @return string - */ - public function toString(): string - { - return $this->name; - } + /** + * Returns the event name as string + * + * @return string + */ + public function toString(): string + { + return $this->name; + } - /** - * Returns the type of the event (e.g. `page`) - * - * @return string - */ - public function type(): string - { - return $this->type; - } + /** + * Returns the type of the event (e.g. `page`) + * + * @return string + */ + public function type(): string + { + return $this->type; + } - /** - * Updates a given argument with a new value - * - * @internal - * @param string $name - * @param mixed $value - * @return void - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function updateArgument(string $name, $value): void - { - if (array_key_exists($name, $this->arguments) !== true) { - throw new InvalidArgumentException('The argument ' . $name . ' does not exist'); - } + /** + * Updates a given argument with a new value + * + * @internal + * @param string $name + * @param mixed $value + * @return void + * @throws \Kirby\Exception\InvalidArgumentException + */ + public function updateArgument(string $name, $value): void + { + if (array_key_exists($name, $this->arguments) !== true) { + throw new InvalidArgumentException('The argument ' . $name . ' does not exist'); + } - $this->arguments[$name] = $value; - } + $this->arguments[$name] = $value; + } } diff --git a/kirby/src/Cms/Field.php b/kirby/src/Cms/Field.php index 2923f93..d3f97a5 100755 --- a/kirby/src/Cms/Field.php +++ b/kirby/src/Cms/Field.php @@ -26,232 +26,232 @@ use Kirby\Exception\InvalidArgumentException; */ class Field { - /** - * Field method aliases - * - * @var array - */ - public static $aliases = []; + /** + * Field method aliases + * + * @var array + */ + public static $aliases = []; - /** - * The field name - * - * @var string - */ - protected $key; + /** + * The field name + * + * @var string + */ + protected $key; - /** - * Registered field methods - * - * @var array - */ - public static $methods = []; + /** + * Registered field methods + * + * @var array + */ + public static $methods = []; - /** - * The parent object if available. - * This will be the page, site, user or file - * to which the content belongs - * - * @var Model - */ - protected $parent; + /** + * The parent object if available. + * This will be the page, site, user or file + * to which the content belongs + * + * @var Model + */ + protected $parent; - /** - * The value of the field - * - * @var mixed - */ - public $value; + /** + * The value of the field + * + * @var mixed + */ + public $value; - /** - * Magic caller for field methods - * - * @param string $method - * @param array $arguments - * @return mixed - */ - public function __call(string $method, array $arguments = []) - { - $method = strtolower($method); + /** + * Magic caller for field methods + * + * @param string $method + * @param array $arguments + * @return mixed + */ + public function __call(string $method, array $arguments = []) + { + $method = strtolower($method); - if (isset(static::$methods[$method]) === true) { - return (static::$methods[$method])(clone $this, ...$arguments); - } + if (isset(static::$methods[$method]) === true) { + return (static::$methods[$method])(clone $this, ...$arguments); + } - if (isset(static::$aliases[$method]) === true) { - $method = strtolower(static::$aliases[$method]); + if (isset(static::$aliases[$method]) === true) { + $method = strtolower(static::$aliases[$method]); - if (isset(static::$methods[$method]) === true) { - return (static::$methods[$method])(clone $this, ...$arguments); - } - } + if (isset(static::$methods[$method]) === true) { + return (static::$methods[$method])(clone $this, ...$arguments); + } + } - return $this; - } + return $this; + } - /** - * Creates a new field object - * - * @param object|null $parent - * @param string $key - * @param mixed $value - */ - public function __construct(?object $parent, string $key, $value) - { - $this->key = $key; - $this->value = $value; - $this->parent = $parent; - } + /** + * Creates a new field object + * + * @param object|null $parent + * @param string $key + * @param mixed $value + */ + public function __construct(?object $parent, string $key, $value) + { + $this->key = $key; + $this->value = $value; + $this->parent = $parent; + } - /** - * Simplifies the var_dump result - * - * @see Field::toArray - * @return array - */ - public function __debugInfo() - { - return $this->toArray(); - } + /** + * Simplifies the var_dump result + * + * @see Field::toArray + * @return array + */ + public function __debugInfo() + { + return $this->toArray(); + } - /** - * Makes it possible to simply echo - * or stringify the entire object - * - * @see Field::toString - * @return string - */ - public function __toString(): string - { - return $this->toString(); - } + /** + * Makes it possible to simply echo + * or stringify the entire object + * + * @see Field::toString + * @return string + */ + public function __toString(): string + { + return $this->toString(); + } - /** - * Checks if the field exists in the content data array - * - * @return bool - */ - public function exists(): bool - { - return $this->parent->content()->has($this->key); - } + /** + * Checks if the field exists in the content data array + * + * @return bool + */ + public function exists(): bool + { + return $this->parent->content()->has($this->key); + } - /** - * Checks if the field content is empty - * - * @return bool - */ - public function isEmpty(): bool - { - return empty($this->value) === true && in_array($this->value, [0, '0', false], true) === false; - } + /** + * Checks if the field content is empty + * + * @return bool + */ + public function isEmpty(): bool + { + return empty($this->value) === true && in_array($this->value, [0, '0', false], true) === false; + } - /** - * Checks if the field content is not empty - * - * @return bool - */ - public function isNotEmpty(): bool - { - return $this->isEmpty() === false; - } + /** + * Checks if the field content is not empty + * + * @return bool + */ + public function isNotEmpty(): bool + { + return $this->isEmpty() === false; + } - /** - * Returns the name of the field - * - * @return string - */ - public function key(): string - { - return $this->key; - } + /** + * Returns the name of the field + * + * @return string + */ + public function key(): string + { + return $this->key; + } - /** - * @see Field::parent() - * @return \Kirby\Cms\Model|null - */ - public function model() - { - return $this->parent; - } + /** + * @see Field::parent() + * @return \Kirby\Cms\Model|null + */ + public function model() + { + return $this->parent; + } - /** - * Provides a fallback if the field value is empty - * - * @param mixed $fallback - * @return $this|static - */ - public function or($fallback = null) - { - if ($this->isNotEmpty()) { - return $this; - } + /** + * Provides a fallback if the field value is empty + * + * @param mixed $fallback + * @return $this|static + */ + public function or($fallback = null) + { + if ($this->isNotEmpty()) { + return $this; + } - if (is_a($fallback, 'Kirby\Cms\Field') === true) { - return $fallback; - } + if (is_a($fallback, 'Kirby\Cms\Field') === true) { + return $fallback; + } - $field = clone $this; - $field->value = $fallback; - return $field; - } + $field = clone $this; + $field->value = $fallback; + return $field; + } - /** - * Returns the parent object of the field - * - * @return \Kirby\Cms\Model|null - */ - public function parent() - { - return $this->parent; - } + /** + * Returns the parent object of the field + * + * @return \Kirby\Cms\Model|null + */ + public function parent() + { + return $this->parent; + } - /** - * Converts the Field object to an array - * - * @return array - */ - public function toArray(): array - { - return [$this->key => $this->value]; - } + /** + * Converts the Field object to an array + * + * @return array + */ + public function toArray(): array + { + return [$this->key => $this->value]; + } - /** - * Returns the field value as string - * - * @return string - */ - public function toString(): string - { - return (string)$this->value; - } + /** + * Returns the field value as string + * + * @return string + */ + public function toString(): string + { + return (string)$this->value; + } - /** - * Returns the field content. If a new value is passed, - * the modified field will be returned. Otherwise it - * will return the field value. - * - * @param string|\Closure $value - * @return mixed - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function value($value = null) - { - if ($value === null) { - return $this->value; - } + /** + * Returns the field content. If a new value is passed, + * the modified field will be returned. Otherwise it + * will return the field value. + * + * @param string|\Closure $value + * @return mixed + * @throws \Kirby\Exception\InvalidArgumentException + */ + public function value($value = null) + { + if ($value === null) { + return $this->value; + } - if (is_scalar($value)) { - $value = (string)$value; - } elseif (is_callable($value)) { - $value = (string)$value->call($this, $this->value); - } else { - throw new InvalidArgumentException('Invalid field value type: ' . gettype($value)); - } + if (is_scalar($value)) { + $value = (string)$value; + } elseif (is_callable($value)) { + $value = (string)$value->call($this, $this->value); + } else { + throw new InvalidArgumentException('Invalid field value type: ' . gettype($value)); + } - $clone = clone $this; - $clone->value = $value; + $clone = clone $this; + $clone->value = $value; - return $clone; - } + return $clone; + } } diff --git a/kirby/src/Cms/Fieldset.php b/kirby/src/Cms/Fieldset.php index 3bd0c7c..0b49fd4 100755 --- a/kirby/src/Cms/Fieldset.php +++ b/kirby/src/Cms/Fieldset.php @@ -19,276 +19,276 @@ use Kirby\Toolkit\Str; */ class Fieldset extends Item { - public const ITEMS_CLASS = '\Kirby\Cms\Fieldsets'; + public const ITEMS_CLASS = '\Kirby\Cms\Fieldsets'; - protected $disabled; - protected $editable; - protected $fields = []; - protected $icon; - protected $label; - protected $model; - protected $name; - protected $preview; - protected $tabs; - protected $translate; - protected $type; - protected $unset; - protected $wysiwyg; + protected $disabled; + protected $editable; + protected $fields = []; + protected $icon; + protected $label; + protected $model; + protected $name; + protected $preview; + protected $tabs; + protected $translate; + protected $type; + protected $unset; + protected $wysiwyg; - /** - * Creates a new Fieldset object - * - * @param array $params - */ - public function __construct(array $params = []) - { - if (empty($params['type']) === true) { - throw new InvalidArgumentException('The fieldset type is missing'); - } + /** + * Creates a new Fieldset object + * + * @param array $params + */ + public function __construct(array $params = []) + { + if (empty($params['type']) === true) { + throw new InvalidArgumentException('The fieldset type is missing'); + } - $this->type = $params['id'] = $params['type']; + $this->type = $params['id'] = $params['type']; - parent::__construct($params); + parent::__construct($params); - $this->disabled = $params['disabled'] ?? false; - $this->editable = $params['editable'] ?? true; - $this->icon = $params['icon'] ?? null; - $this->model = $this->parent; - $this->name = $this->createName($params['title'] ?? $params['name'] ?? Str::ucfirst($this->type)); - $this->label = $this->createLabel($params['label'] ?? null); - $this->preview = $params['preview'] ?? null; - $this->tabs = $this->createTabs($params); - $this->translate = $params['translate'] ?? true; - $this->unset = $params['unset'] ?? false; - $this->wysiwyg = $params['wysiwyg'] ?? false; + $this->disabled = $params['disabled'] ?? false; + $this->editable = $params['editable'] ?? true; + $this->icon = $params['icon'] ?? null; + $this->model = $this->parent; + $this->name = $this->createName($params['title'] ?? $params['name'] ?? Str::ucfirst($this->type)); + $this->label = $this->createLabel($params['label'] ?? null); + $this->preview = $params['preview'] ?? null; + $this->tabs = $this->createTabs($params); + $this->translate = $params['translate'] ?? true; + $this->unset = $params['unset'] ?? false; + $this->wysiwyg = $params['wysiwyg'] ?? false; - if ( - $this->translate === false && - $this->kirby()->multilang() === true && - $this->kirby()->language()->isDefault() === false - ) { - // disable and unset the fieldset if it's not translatable - $this->unset = true; - $this->disabled = true; - } - } + if ( + $this->translate === false && + $this->kirby()->multilang() === true && + $this->kirby()->language()->isDefault() === false + ) { + // disable and unset the fieldset if it's not translatable + $this->unset = true; + $this->disabled = true; + } + } - /** - * @param array $fields - * @return array - */ - protected function createFields(array $fields = []): array - { - $fields = Blueprint::fieldsProps($fields); - $fields = $this->form($fields)->fields()->toArray(); + /** + * @param array $fields + * @return array + */ + protected function createFields(array $fields = []): array + { + $fields = Blueprint::fieldsProps($fields); + $fields = $this->form($fields)->fields()->toArray(); - // collect all fields - $this->fields = array_merge($this->fields, $fields); + // collect all fields + $this->fields = array_merge($this->fields, $fields); - return $fields; - } + return $fields; + } - /** - * @param array|string $name - * @return string|null - */ - protected function createName($name): ?string - { - return I18n::translate($name, $name); - } + /** + * @param array|string $name + * @return string|null + */ + protected function createName($name): ?string + { + return I18n::translate($name, $name); + } - /** - * @param array|string $label - * @return string|null - */ - protected function createLabel($label = null): ?string - { - return I18n::translate($label, $label); - } + /** + * @param array|string $label + * @return string|null + */ + protected function createLabel($label = null): ?string + { + return I18n::translate($label, $label); + } - /** - * @param array $params - * @return array - */ - protected function createTabs(array $params = []): array - { - $tabs = $params['tabs'] ?? []; + /** + * @param array $params + * @return array + */ + protected function createTabs(array $params = []): array + { + $tabs = $params['tabs'] ?? []; - // return a single tab if there are only fields - if (empty($tabs) === true) { - return [ - 'content' => [ - 'fields' => $this->createFields($params['fields'] ?? []), - ] - ]; - } + // return a single tab if there are only fields + if (empty($tabs) === true) { + return [ + 'content' => [ + 'fields' => $this->createFields($params['fields'] ?? []), + ] + ]; + } - // normalize tabs props - foreach ($tabs as $name => $tab) { - // unset/remove tab if its property is false - if ($tab === false) { - unset($tabs[$name]); - continue; - } + // normalize tabs props + foreach ($tabs as $name => $tab) { + // unset/remove tab if its property is false + if ($tab === false) { + unset($tabs[$name]); + continue; + } - $tab = Blueprint::extend($tab); + $tab = Blueprint::extend($tab); - $tab['fields'] = $this->createFields($tab['fields'] ?? []); - $tab['label'] = $this->createLabel($tab['label'] ?? Str::ucfirst($name)); - $tab['name'] = $name; + $tab['fields'] = $this->createFields($tab['fields'] ?? []); + $tab['label'] = $this->createLabel($tab['label'] ?? Str::ucfirst($name)); + $tab['name'] = $name; - $tabs[$name] = $tab; - } + $tabs[$name] = $tab; + } - return $tabs; - } + return $tabs; + } - /** - * @return bool - */ - public function disabled(): bool - { - return $this->disabled; - } + /** + * @return bool + */ + public function disabled(): bool + { + return $this->disabled; + } - /** - * @return bool - */ - public function editable(): bool - { - if ($this->editable === false) { - return false; - } + /** + * @return bool + */ + public function editable(): bool + { + if ($this->editable === false) { + return false; + } - if (count($this->fields) === 0) { - return false; - } + if (count($this->fields) === 0) { + return false; + } - return true; - } + return true; + } - /** - * @return array - */ - public function fields(): array - { - return $this->fields; - } + /** + * @return array + */ + public function fields(): array + { + return $this->fields; + } - /** - * Creates a form for the given fields - * - * @param array $fields - * @param array $input - * @return \Kirby\Form\Form - */ - public function form(array $fields, array $input = []) - { - return new Form([ - 'fields' => $fields, - 'model' => $this->model, - 'strict' => true, - 'values' => $input, - ]); - } + /** + * Creates a form for the given fields + * + * @param array $fields + * @param array $input + * @return \Kirby\Form\Form + */ + public function form(array $fields, array $input = []) + { + return new Form([ + 'fields' => $fields, + 'model' => $this->model, + 'strict' => true, + 'values' => $input, + ]); + } - /** - * @return string|null - */ - public function icon(): ?string - { - return $this->icon; - } + /** + * @return string|null + */ + public function icon(): ?string + { + return $this->icon; + } - /** - * @return string|null - */ - public function label(): ?string - { - return $this->label; - } + /** + * @return string|null + */ + public function label(): ?string + { + return $this->label; + } - /** - * @return \Kirby\Cms\ModelWithContent - */ - public function model() - { - return $this->model; - } + /** + * @return \Kirby\Cms\ModelWithContent + */ + public function model() + { + return $this->model; + } - /** - * @return string - */ - public function name(): string - { - return $this->name; - } + /** + * @return string + */ + public function name(): string + { + return $this->name; + } - /** - * @return string|bool - */ - public function preview() - { - return $this->preview; - } + /** + * @return string|bool + */ + public function preview() + { + return $this->preview; + } - /** - * @return array - */ - public function tabs(): array - { - return $this->tabs; - } + /** + * @return array + */ + public function tabs(): array + { + return $this->tabs; + } - /** - * @return bool - */ - public function translate(): bool - { - return $this->translate; - } + /** + * @return bool + */ + public function translate(): bool + { + return $this->translate; + } - /** - * @return string - */ - public function type(): string - { - return $this->type; - } + /** + * @return string + */ + public function type(): string + { + return $this->type; + } - /** - * @return array - */ - public function toArray(): array - { - return [ - 'disabled' => $this->disabled(), - 'editable' => $this->editable(), - 'icon' => $this->icon(), - 'label' => $this->label(), - 'name' => $this->name(), - 'preview' => $this->preview(), - 'tabs' => $this->tabs(), - 'translate' => $this->translate(), - 'type' => $this->type(), - 'unset' => $this->unset(), - 'wysiwyg' => $this->wysiwyg(), - ]; - } + /** + * @return array + */ + public function toArray(): array + { + return [ + 'disabled' => $this->disabled(), + 'editable' => $this->editable(), + 'icon' => $this->icon(), + 'label' => $this->label(), + 'name' => $this->name(), + 'preview' => $this->preview(), + 'tabs' => $this->tabs(), + 'translate' => $this->translate(), + 'type' => $this->type(), + 'unset' => $this->unset(), + 'wysiwyg' => $this->wysiwyg(), + ]; + } - /** - * @return bool - */ - public function unset(): bool - { - return $this->unset; - } + /** + * @return bool + */ + public function unset(): bool + { + return $this->unset; + } - /** - * @return bool - */ - public function wysiwyg(): bool - { - return $this->wysiwyg; - } + /** + * @return bool + */ + public function wysiwyg(): bool + { + return $this->wysiwyg; + } } diff --git a/kirby/src/Cms/Fieldsets.php b/kirby/src/Cms/Fieldsets.php index aaf0150..6189b22 100755 --- a/kirby/src/Cms/Fieldsets.php +++ b/kirby/src/Cms/Fieldsets.php @@ -19,85 +19,85 @@ use Kirby\Toolkit\Str; */ class Fieldsets extends Items { - public const ITEM_CLASS = '\Kirby\Cms\Fieldset'; + public const ITEM_CLASS = '\Kirby\Cms\Fieldset'; - protected static function createFieldsets($params) - { - $fieldsets = []; - $groups = []; + protected static function createFieldsets($params) + { + $fieldsets = []; + $groups = []; - foreach ($params as $type => $fieldset) { - if (is_int($type) === true && is_string($fieldset)) { - $type = $fieldset; - $fieldset = 'blocks/' . $type; - } + foreach ($params as $type => $fieldset) { + if (is_int($type) === true && is_string($fieldset)) { + $type = $fieldset; + $fieldset = 'blocks/' . $type; + } - if ($fieldset === false) { - continue; - } + if ($fieldset === false) { + continue; + } - if ($fieldset === true) { - $fieldset = 'blocks/' . $type; - } + if ($fieldset === true) { + $fieldset = 'blocks/' . $type; + } - $fieldset = Blueprint::extend($fieldset); + $fieldset = Blueprint::extend($fieldset); - // make sure the type is always set - $fieldset['type'] ??= $type; + // make sure the type is always set + $fieldset['type'] ??= $type; - // extract groups - if ($fieldset['type'] === 'group') { - $result = static::createFieldsets($fieldset['fieldsets'] ?? []); - $fieldsets = array_merge($fieldsets, $result['fieldsets']); - $label = $fieldset['label'] ?? Str::ucfirst($type); + // extract groups + if ($fieldset['type'] === 'group') { + $result = static::createFieldsets($fieldset['fieldsets'] ?? []); + $fieldsets = array_merge($fieldsets, $result['fieldsets']); + $label = $fieldset['label'] ?? Str::ucfirst($type); - $groups[$type] = [ - 'label' => I18n::translate($label, $label), - 'name' => $type, - 'open' => $fieldset['open'] ?? true, - 'sets' => array_column($result['fieldsets'], 'type'), - ]; - } else { - $fieldsets[$fieldset['type']] = $fieldset; - } - } + $groups[$type] = [ + 'label' => I18n::translate($label, $label), + 'name' => $type, + 'open' => $fieldset['open'] ?? true, + 'sets' => array_column($result['fieldsets'], 'type'), + ]; + } else { + $fieldsets[$fieldset['type']] = $fieldset; + } + } - return [ - 'fieldsets' => $fieldsets, - 'groups' => $groups - ]; - } + return [ + 'fieldsets' => $fieldsets, + 'groups' => $groups + ]; + } - public static function factory(array $items = null, array $params = []) - { - $items ??= App::instance()->option('blocks.fieldsets', [ - 'code' => 'blocks/code', - 'gallery' => 'blocks/gallery', - 'heading' => 'blocks/heading', - 'image' => 'blocks/image', - 'line' => 'blocks/line', - 'list' => 'blocks/list', - 'markdown' => 'blocks/markdown', - 'quote' => 'blocks/quote', - 'text' => 'blocks/text', - 'video' => 'blocks/video', - ]); + public static function factory(array $items = null, array $params = []) + { + $items ??= App::instance()->option('blocks.fieldsets', [ + 'code' => 'blocks/code', + 'gallery' => 'blocks/gallery', + 'heading' => 'blocks/heading', + 'image' => 'blocks/image', + 'line' => 'blocks/line', + 'list' => 'blocks/list', + 'markdown' => 'blocks/markdown', + 'quote' => 'blocks/quote', + 'text' => 'blocks/text', + 'video' => 'blocks/video', + ]); - $result = static::createFieldsets($items); + $result = static::createFieldsets($items); - return parent::factory($result['fieldsets'], ['groups' => $result['groups']] + $params); - } + return parent::factory($result['fieldsets'], ['groups' => $result['groups']] + $params); + } - public function groups(): array - { - return $this->options['groups'] ?? []; - } + public function groups(): array + { + return $this->options['groups'] ?? []; + } - public function toArray(?Closure $map = null): array - { - return A::map( - $this->data, - $map ?? fn ($fieldset) => $fieldset->toArray() - ); - } + public function toArray(?Closure $map = null): array + { + return A::map( + $this->data, + $map ?? fn ($fieldset) => $fieldset->toArray() + ); + } } diff --git a/kirby/src/Cms/File.php b/kirby/src/Cms/File.php index 02f66c2..bc81c7d 100755 --- a/kirby/src/Cms/File.php +++ b/kirby/src/Cms/File.php @@ -30,724 +30,724 @@ use Kirby\Toolkit\Str; */ class File extends ModelWithContent { - use FileActions; - use FileModifications; - use HasMethods; - use HasSiblings; - use IsFile; - - public const CLASS_ALIAS = 'file'; - - /** - * Cache for the initialized blueprint object - * - * @var \Kirby\Cms\FileBlueprint - */ - protected $blueprint; - - /** - * @var string - */ - protected $filename; - - /** - * @var string - */ - protected $id; - - /** - * All registered file methods - * - * @var array - */ - public static $methods = []; - - /** - * The parent object - * - * @var \Kirby\Cms\Model - */ - protected $parent; - - /** - * The absolute path to the file - * - * @var string|null - */ - protected $root; - - /** - * @var string - */ - protected $template; - - /** - * The public file Url - * - * @var string - */ - protected $url; - - /** - * Magic caller for file methods - * and content fields. (in this order) - * - * @param string $method - * @param array $arguments - * @return mixed - */ - public function __call(string $method, array $arguments = []) - { - // public property access - if (isset($this->$method) === true) { - return $this->$method; - } - - // asset method proxy - if (method_exists($this->asset(), $method)) { - return $this->asset()->$method(...$arguments); - } - - // file methods - if ($this->hasMethod($method)) { - return $this->callMethod($method, $arguments); - } - - // content fields - return $this->content()->get($method); - } - - /** - * Creates a new File object - * - * @param array $props - */ - public function __construct(array $props) - { - // set filename as the most important prop first - // TODO: refactor later to avoid redundant prop setting - $this->setProperty('filename', $props['filename'] ?? null, true); - - // set other properties - $this->setProperties($props); - } - - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return array_merge($this->toArray(), [ - 'content' => $this->content(), - 'siblings' => $this->siblings(), - ]); - } - - /** - * Returns the url to api endpoint - * - * @internal - * @param bool $relative - * @return string - */ - public function apiUrl(bool $relative = false): string - { - return $this->parent()->apiUrl($relative) . '/files/' . $this->filename(); - } - - /** - * Returns the FileBlueprint object for the file - * - * @return \Kirby\Cms\FileBlueprint - */ - public function blueprint() - { - if (is_a($this->blueprint, 'Kirby\Cms\FileBlueprint') === true) { - return $this->blueprint; - } - - return $this->blueprint = FileBlueprint::factory('files/' . $this->template(), 'files/default', $this); - } - - /** - * Store the template in addition to the - * other content. - * - * @internal - * @param array $data - * @param string|null $languageCode - * @return array - */ - public function contentFileData(array $data, string $languageCode = null): array - { - return A::append($data, [ - 'template' => $this->template(), - ]); - } - - /** - * Returns the directory in which - * the content file is located - * - * @internal - * @return string - */ - public function contentFileDirectory(): string - { - return dirname($this->root()); - } - - /** - * Filename for the content file - * - * @internal - * @return string - */ - public function contentFileName(): string - { - return $this->filename(); - } - - /** - * Constructs a File object - * - * @internal - * @param mixed $props - * @return static - */ - public static function factory($props) - { - return new static($props); - } - - /** - * Returns the filename with extension - * - * @return string - */ - public function filename(): string - { - return $this->filename; - } - - /** - * Returns the parent Files collection - * - * @return \Kirby\Cms\Files - */ - public function files() - { - return $this->siblingsCollection(); - } - - /** - * Converts the file to html - * - * @param array $attr - * @return string - */ - public function html(array $attr = []): string - { - return $this->asset()->html(array_merge( - ['alt' => $this->alt()], - $attr - )); - } - - /** - * Returns the id - * - * @return string - */ - public function id(): string - { - if ($this->id !== null) { - return $this->id; - } - - if (is_a($this->parent(), 'Kirby\Cms\Page') === true) { - return $this->id = $this->parent()->id() . '/' . $this->filename(); - } elseif (is_a($this->parent(), 'Kirby\Cms\User') === true) { - return $this->id = $this->parent()->id() . '/' . $this->filename(); - } - - return $this->id = $this->filename(); - } - - /** - * Compares the current object with the given file object - * - * @param \Kirby\Cms\File $file - * @return bool - */ - public function is(File $file): bool - { - return $this->id() === $file->id(); - } - - /** - * Check if the file can be read by the current user - * - * @return bool - */ - public function isReadable(): bool - { - static $readable = []; - - $template = $this->template(); - - if (isset($readable[$template]) === true) { - return $readable[$template]; - } - - return $readable[$template] = $this->permissions()->can('read'); - } - - /** - * Creates a unique media hash - * - * @internal - * @return string - */ - public function mediaHash(): string - { - return $this->mediaToken() . '-' . $this->modifiedFile(); - } - - /** - * Returns the absolute path to the file in the public media folder - * - * @internal - * @return string - */ - public function mediaRoot(): string - { - return $this->parent()->mediaRoot() . '/' . $this->mediaHash() . '/' . $this->filename(); - } - - /** - * Creates a non-guessable token string for this file - * - * @internal - * @return string - */ - public function mediaToken(): string - { - $token = $this->kirby()->contentToken($this, $this->id()); - return substr($token, 0, 10); - } - - /** - * Returns the absolute Url to the file in the public media folder - * - * @internal - * @return string - */ - public function mediaUrl(): string - { - return $this->parent()->mediaUrl() . '/' . $this->mediaHash() . '/' . $this->filename(); - } - - /** - * Get the file's last modification time. - * - * @param string|\IntlDateFormatter|null $format - * @param string|null $handler date, intl or strftime - * @param string|null $languageCode - * @return mixed - */ - public function modified($format = null, string $handler = null, string $languageCode = null) - { - $file = $this->modifiedFile(); - $content = $this->modifiedContent($languageCode); - $modified = max($file, $content); - $handler ??= $this->kirby()->option('date.handler', 'date'); - - return Str::date($modified, $format, $handler); - } - - /** - * Timestamp of the last modification - * of the content file - * - * @param string|null $languageCode - * @return int - */ - protected function modifiedContent(string $languageCode = null): int - { - return F::modified($this->contentFile($languageCode)); - } - - /** - * Timestamp of the last modification - * of the source file - * - * @return int - */ - protected function modifiedFile(): int - { - return F::modified($this->root()); - } - - /** - * Returns the parent Page object - * - * @return \Kirby\Cms\Page|null - */ - public function page() - { - return is_a($this->parent(), 'Kirby\Cms\Page') === true ? $this->parent() : null; - } - - /** - * Returns the panel info object - * - * @return \Kirby\Panel\File - */ - public function panel() - { - return new Panel($this); - } - - /** - * Returns the parent Model object - * - * @return \Kirby\Cms\Model - */ - public function parent() - { - return $this->parent ??= $this->kirby()->site(); - } - - /** - * Returns the parent id if a parent exists - * - * @internal - * @return string - */ - public function parentId(): string - { - return $this->parent()->id(); - } - - /** - * Returns a collection of all parent pages - * - * @return \Kirby\Cms\Pages - */ - public function parents() - { - if (is_a($this->parent(), 'Kirby\Cms\Page') === true) { - return $this->parent()->parents()->prepend($this->parent()->id(), $this->parent()); - } - - return new Pages(); - } - - /** - * Returns the permissions object for this file - * - * @return \Kirby\Cms\FilePermissions - */ - public function permissions() - { - return new FilePermissions($this); - } - - /** - * Returns the absolute root to the file - * - * @return string|null - */ - public function root(): ?string - { - return $this->root ??= $this->parent()->root() . '/' . $this->filename(); - } - - /** - * Returns the FileRules class to - * validate any important action. - * - * @return \Kirby\Cms\FileRules - */ - protected function rules() - { - return new FileRules(); - } - - /** - * Sets the Blueprint object - * - * @param array|null $blueprint - * @return $this - */ - protected function setBlueprint(array $blueprint = null) - { - if ($blueprint !== null) { - $blueprint['model'] = $this; - $this->blueprint = new FileBlueprint($blueprint); - } - - return $this; - } - - /** - * Sets the filename - * - * @param string $filename - * @return $this - */ - protected function setFilename(string $filename) - { - $this->filename = $filename; - return $this; - } - - /** - * Sets the parent model object - * - * @param \Kirby\Cms\Model $parent - * @return $this - */ - protected function setParent(Model $parent) - { - $this->parent = $parent; - return $this; - } - - /** - * Always set the root to null, to invoke - * auto root detection - * - * @param string|null $root - * @return $this - */ - protected function setRoot(string $root = null) - { - $this->root = null; - return $this; - } - - /** - * @param string|null $template - * @return $this - */ - protected function setTemplate(string $template = null) - { - $this->template = $template; - return $this; - } - - /** - * Sets the url - * - * @param string|null $url - * @return $this - */ - protected function setUrl(string $url = null) - { - $this->url = $url; - return $this; - } - - /** - * Returns the parent Files collection - * @internal - * - * @return \Kirby\Cms\Files - */ - protected function siblingsCollection() - { - return $this->parent()->files(); - } - - /** - * Returns the parent Site object - * - * @return \Kirby\Cms\Site - */ - public function site() - { - return is_a($this->parent(), 'Kirby\Cms\Site') === true ? $this->parent() : $this->kirby()->site(); - } - - /** - * Returns the final template - * - * @return string|null - */ - public function template(): ?string - { - return $this->template ??= $this->content()->get('template')->value(); - } - - /** - * Returns siblings with the same template - * - * @param bool $self - * @return \Kirby\Cms\Files - */ - public function templateSiblings(bool $self = true) - { - return $this->siblings($self)->filter('template', $this->template()); - } - - /** - * Extended info for the array export - * by injecting the information from - * the asset. - * - * @return array - */ - public function toArray(): array - { - return array_merge($this->asset()->toArray(), parent::toArray()); - } - - /** - * Returns the Url - * - * @return string - */ - public function url(): string - { - return $this->url ??= ($this->kirby()->component('file::url'))($this->kirby(), $this); - } - - - /** - * Deprecated! - */ - - /** - * Provides a kirbytag or markdown - * tag for the file, which will be - * used in the panel, when the file - * gets dragged onto a textarea - * - * @todo Remove in 3.8.0 - * - * @internal - * @param string|null $type (null|auto|kirbytext|markdown) - * @param bool $absolute - * @return string - * @codeCoverageIgnore - */ - public function dragText(string $type = null, bool $absolute = false): string - { - Helpers::deprecated('Cms\File::dragText() has been deprecated and will be removed in Kirby 3.8.0. Use $file->panel()->dragText() instead.'); - return $this->panel()->dragText($type, $absolute); - } - - /** - * Returns an array of all actions - * that can be performed in the Panel - * - * @todo Remove in 3.8.0 - * - * @since 3.3.0 This also checks for the lock status - * @since 3.5.1 This also checks for matching accept settings - * - * @param array $unlock An array of options that will be force-unlocked - * @return array - * @codeCoverageIgnore - */ - public function panelOptions(array $unlock = []): array - { - Helpers::deprecated('Cms\File::panelOptions() has been deprecated and will be removed in Kirby 3.8.0. Use $file->panel()->options() instead.'); - return $this->panel()->options($unlock); - } - - /** - * Returns the full path without leading slash - * - * @todo Remove in 3.8.0 - * - * @internal - * @return string - * @codeCoverageIgnore - */ - public function panelPath(): string - { - Helpers::deprecated('Cms\File::panelPath() has been deprecated and will be removed in Kirby 3.8.0. Use $file->panel()->path() instead.'); - return $this->panel()->path(); - } - - /** - * Prepares the response data for file pickers - * and file fields - * - * @todo Remove in 3.8.0 - * - * @param array|null $params - * @return array - * @codeCoverageIgnore - */ - public function panelPickerData(array $params = []): array - { - Helpers::deprecated('Cms\File::panelPickerData() has been deprecated and will be removed in Kirby 3.8.0. Use $file->panel()->pickerData() instead.'); - return $this->panel()->pickerData($params); - } - - /** - * Returns the url to the editing view - * in the panel - * - * @todo Remove in 3.8.0 - * - * @internal - * @param bool $relative - * @return string - * @codeCoverageIgnore - */ - public function panelUrl(bool $relative = false): string - { - Helpers::deprecated('Cms\File::panelUrl() has been deprecated and will be removed in Kirby 3.8.0. Use $file->panel()->url() instead.'); - return $this->panel()->url($relative); - } - - /** - * Simplified File URL that uses the parent - * Page URL and the filename as a more stable - * alternative for the media URLs. - * - * @return string - */ - public function previewUrl(): string - { - $parent = $this->parent(); - $url = Url::to($this->id()); - - switch ($parent::CLASS_ALIAS) { - case 'page': - $preview = $parent->blueprint()->preview(); - - // the page has a custom preview setting, - // thus the file is only accessible through - // the direct media URL - if ($preview !== true) { - return $this->url(); - } - - // it's more stable to access files for drafts - // through their direct URL to avoid conflicts - // with draft token verification - if ($parent->isDraft() === true) { - return $this->url(); - } - - // checks `file::url` component is extended - if ($this->kirby()->isNativeComponent('file::url') === false) { - return $this->url(); - } - - return $url; - case 'user': - return $this->url(); - default: - return $url; - } - } + use FileActions; + use FileModifications; + use HasMethods; + use HasSiblings; + use IsFile; + + public const CLASS_ALIAS = 'file'; + + /** + * Cache for the initialized blueprint object + * + * @var \Kirby\Cms\FileBlueprint + */ + protected $blueprint; + + /** + * @var string + */ + protected $filename; + + /** + * @var string + */ + protected $id; + + /** + * All registered file methods + * + * @var array + */ + public static $methods = []; + + /** + * The parent object + * + * @var \Kirby\Cms\Model + */ + protected $parent; + + /** + * The absolute path to the file + * + * @var string|null + */ + protected $root; + + /** + * @var string + */ + protected $template; + + /** + * The public file Url + * + * @var string + */ + protected $url; + + /** + * Magic caller for file methods + * and content fields. (in this order) + * + * @param string $method + * @param array $arguments + * @return mixed + */ + public function __call(string $method, array $arguments = []) + { + // public property access + if (isset($this->$method) === true) { + return $this->$method; + } + + // asset method proxy + if (method_exists($this->asset(), $method)) { + return $this->asset()->$method(...$arguments); + } + + // file methods + if ($this->hasMethod($method)) { + return $this->callMethod($method, $arguments); + } + + // content fields + return $this->content()->get($method); + } + + /** + * Creates a new File object + * + * @param array $props + */ + public function __construct(array $props) + { + // set filename as the most important prop first + // TODO: refactor later to avoid redundant prop setting + $this->setProperty('filename', $props['filename'] ?? null, true); + + // set other properties + $this->setProperties($props); + } + + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return array_merge($this->toArray(), [ + 'content' => $this->content(), + 'siblings' => $this->siblings(), + ]); + } + + /** + * Returns the url to api endpoint + * + * @internal + * @param bool $relative + * @return string + */ + public function apiUrl(bool $relative = false): string + { + return $this->parent()->apiUrl($relative) . '/files/' . $this->filename(); + } + + /** + * Returns the FileBlueprint object for the file + * + * @return \Kirby\Cms\FileBlueprint + */ + public function blueprint() + { + if (is_a($this->blueprint, 'Kirby\Cms\FileBlueprint') === true) { + return $this->blueprint; + } + + return $this->blueprint = FileBlueprint::factory('files/' . $this->template(), 'files/default', $this); + } + + /** + * Store the template in addition to the + * other content. + * + * @internal + * @param array $data + * @param string|null $languageCode + * @return array + */ + public function contentFileData(array $data, string $languageCode = null): array + { + return A::append($data, [ + 'template' => $this->template(), + ]); + } + + /** + * Returns the directory in which + * the content file is located + * + * @internal + * @return string + */ + public function contentFileDirectory(): string + { + return dirname($this->root()); + } + + /** + * Filename for the content file + * + * @internal + * @return string + */ + public function contentFileName(): string + { + return $this->filename(); + } + + /** + * Constructs a File object + * + * @internal + * @param mixed $props + * @return static + */ + public static function factory($props) + { + return new static($props); + } + + /** + * Returns the filename with extension + * + * @return string + */ + public function filename(): string + { + return $this->filename; + } + + /** + * Returns the parent Files collection + * + * @return \Kirby\Cms\Files + */ + public function files() + { + return $this->siblingsCollection(); + } + + /** + * Converts the file to html + * + * @param array $attr + * @return string + */ + public function html(array $attr = []): string + { + return $this->asset()->html(array_merge( + ['alt' => $this->alt()], + $attr + )); + } + + /** + * Returns the id + * + * @return string + */ + public function id(): string + { + if ($this->id !== null) { + return $this->id; + } + + if (is_a($this->parent(), 'Kirby\Cms\Page') === true) { + return $this->id = $this->parent()->id() . '/' . $this->filename(); + } elseif (is_a($this->parent(), 'Kirby\Cms\User') === true) { + return $this->id = $this->parent()->id() . '/' . $this->filename(); + } + + return $this->id = $this->filename(); + } + + /** + * Compares the current object with the given file object + * + * @param \Kirby\Cms\File $file + * @return bool + */ + public function is(File $file): bool + { + return $this->id() === $file->id(); + } + + /** + * Check if the file can be read by the current user + * + * @return bool + */ + public function isReadable(): bool + { + static $readable = []; + + $template = $this->template(); + + if (isset($readable[$template]) === true) { + return $readable[$template]; + } + + return $readable[$template] = $this->permissions()->can('read'); + } + + /** + * Creates a unique media hash + * + * @internal + * @return string + */ + public function mediaHash(): string + { + return $this->mediaToken() . '-' . $this->modifiedFile(); + } + + /** + * Returns the absolute path to the file in the public media folder + * + * @internal + * @return string + */ + public function mediaRoot(): string + { + return $this->parent()->mediaRoot() . '/' . $this->mediaHash() . '/' . $this->filename(); + } + + /** + * Creates a non-guessable token string for this file + * + * @internal + * @return string + */ + public function mediaToken(): string + { + $token = $this->kirby()->contentToken($this, $this->id()); + return substr($token, 0, 10); + } + + /** + * Returns the absolute Url to the file in the public media folder + * + * @internal + * @return string + */ + public function mediaUrl(): string + { + return $this->parent()->mediaUrl() . '/' . $this->mediaHash() . '/' . $this->filename(); + } + + /** + * Get the file's last modification time. + * + * @param string|\IntlDateFormatter|null $format + * @param string|null $handler date, intl or strftime + * @param string|null $languageCode + * @return mixed + */ + public function modified($format = null, string $handler = null, string $languageCode = null) + { + $file = $this->modifiedFile(); + $content = $this->modifiedContent($languageCode); + $modified = max($file, $content); + $handler ??= $this->kirby()->option('date.handler', 'date'); + + return Str::date($modified, $format, $handler); + } + + /** + * Timestamp of the last modification + * of the content file + * + * @param string|null $languageCode + * @return int + */ + protected function modifiedContent(string $languageCode = null): int + { + return F::modified($this->contentFile($languageCode)); + } + + /** + * Timestamp of the last modification + * of the source file + * + * @return int + */ + protected function modifiedFile(): int + { + return F::modified($this->root()); + } + + /** + * Returns the parent Page object + * + * @return \Kirby\Cms\Page|null + */ + public function page() + { + return is_a($this->parent(), 'Kirby\Cms\Page') === true ? $this->parent() : null; + } + + /** + * Returns the panel info object + * + * @return \Kirby\Panel\File + */ + public function panel() + { + return new Panel($this); + } + + /** + * Returns the parent Model object + * + * @return \Kirby\Cms\Model + */ + public function parent() + { + return $this->parent ??= $this->kirby()->site(); + } + + /** + * Returns the parent id if a parent exists + * + * @internal + * @return string + */ + public function parentId(): string + { + return $this->parent()->id(); + } + + /** + * Returns a collection of all parent pages + * + * @return \Kirby\Cms\Pages + */ + public function parents() + { + if (is_a($this->parent(), 'Kirby\Cms\Page') === true) { + return $this->parent()->parents()->prepend($this->parent()->id(), $this->parent()); + } + + return new Pages(); + } + + /** + * Returns the permissions object for this file + * + * @return \Kirby\Cms\FilePermissions + */ + public function permissions() + { + return new FilePermissions($this); + } + + /** + * Returns the absolute root to the file + * + * @return string|null + */ + public function root(): ?string + { + return $this->root ??= $this->parent()->root() . '/' . $this->filename(); + } + + /** + * Returns the FileRules class to + * validate any important action. + * + * @return \Kirby\Cms\FileRules + */ + protected function rules() + { + return new FileRules(); + } + + /** + * Sets the Blueprint object + * + * @param array|null $blueprint + * @return $this + */ + protected function setBlueprint(array $blueprint = null) + { + if ($blueprint !== null) { + $blueprint['model'] = $this; + $this->blueprint = new FileBlueprint($blueprint); + } + + return $this; + } + + /** + * Sets the filename + * + * @param string $filename + * @return $this + */ + protected function setFilename(string $filename) + { + $this->filename = $filename; + return $this; + } + + /** + * Sets the parent model object + * + * @param \Kirby\Cms\Model $parent + * @return $this + */ + protected function setParent(Model $parent) + { + $this->parent = $parent; + return $this; + } + + /** + * Always set the root to null, to invoke + * auto root detection + * + * @param string|null $root + * @return $this + */ + protected function setRoot(string $root = null) + { + $this->root = null; + return $this; + } + + /** + * @param string|null $template + * @return $this + */ + protected function setTemplate(string $template = null) + { + $this->template = $template; + return $this; + } + + /** + * Sets the url + * + * @param string|null $url + * @return $this + */ + protected function setUrl(string $url = null) + { + $this->url = $url; + return $this; + } + + /** + * Returns the parent Files collection + * @internal + * + * @return \Kirby\Cms\Files + */ + protected function siblingsCollection() + { + return $this->parent()->files(); + } + + /** + * Returns the parent Site object + * + * @return \Kirby\Cms\Site + */ + public function site() + { + return is_a($this->parent(), 'Kirby\Cms\Site') === true ? $this->parent() : $this->kirby()->site(); + } + + /** + * Returns the final template + * + * @return string|null + */ + public function template(): ?string + { + return $this->template ??= $this->content()->get('template')->value(); + } + + /** + * Returns siblings with the same template + * + * @param bool $self + * @return \Kirby\Cms\Files + */ + public function templateSiblings(bool $self = true) + { + return $this->siblings($self)->filter('template', $this->template()); + } + + /** + * Extended info for the array export + * by injecting the information from + * the asset. + * + * @return array + */ + public function toArray(): array + { + return array_merge($this->asset()->toArray(), parent::toArray()); + } + + /** + * Returns the Url + * + * @return string + */ + public function url(): string + { + return $this->url ??= ($this->kirby()->component('file::url'))($this->kirby(), $this); + } + + + /** + * Deprecated! + */ + + /** + * Provides a kirbytag or markdown + * tag for the file, which will be + * used in the panel, when the file + * gets dragged onto a textarea + * + * @todo Remove in 3.8.0 + * + * @internal + * @param string|null $type (null|auto|kirbytext|markdown) + * @param bool $absolute + * @return string + * @codeCoverageIgnore + */ + public function dragText(string $type = null, bool $absolute = false): string + { + Helpers::deprecated('Cms\File::dragText() has been deprecated and will be removed in Kirby 3.8.0. Use $file->panel()->dragText() instead.'); + return $this->panel()->dragText($type, $absolute); + } + + /** + * Returns an array of all actions + * that can be performed in the Panel + * + * @todo Remove in 3.8.0 + * + * @since 3.3.0 This also checks for the lock status + * @since 3.5.1 This also checks for matching accept settings + * + * @param array $unlock An array of options that will be force-unlocked + * @return array + * @codeCoverageIgnore + */ + public function panelOptions(array $unlock = []): array + { + Helpers::deprecated('Cms\File::panelOptions() has been deprecated and will be removed in Kirby 3.8.0. Use $file->panel()->options() instead.'); + return $this->panel()->options($unlock); + } + + /** + * Returns the full path without leading slash + * + * @todo Remove in 3.8.0 + * + * @internal + * @return string + * @codeCoverageIgnore + */ + public function panelPath(): string + { + Helpers::deprecated('Cms\File::panelPath() has been deprecated and will be removed in Kirby 3.8.0. Use $file->panel()->path() instead.'); + return $this->panel()->path(); + } + + /** + * Prepares the response data for file pickers + * and file fields + * + * @todo Remove in 3.8.0 + * + * @param array|null $params + * @return array + * @codeCoverageIgnore + */ + public function panelPickerData(array $params = []): array + { + Helpers::deprecated('Cms\File::panelPickerData() has been deprecated and will be removed in Kirby 3.8.0. Use $file->panel()->pickerData() instead.'); + return $this->panel()->pickerData($params); + } + + /** + * Returns the url to the editing view + * in the panel + * + * @todo Remove in 3.8.0 + * + * @internal + * @param bool $relative + * @return string + * @codeCoverageIgnore + */ + public function panelUrl(bool $relative = false): string + { + Helpers::deprecated('Cms\File::panelUrl() has been deprecated and will be removed in Kirby 3.8.0. Use $file->panel()->url() instead.'); + return $this->panel()->url($relative); + } + + /** + * Simplified File URL that uses the parent + * Page URL and the filename as a more stable + * alternative for the media URLs. + * + * @return string + */ + public function previewUrl(): string + { + $parent = $this->parent(); + $url = Url::to($this->id()); + + switch ($parent::CLASS_ALIAS) { + case 'page': + $preview = $parent->blueprint()->preview(); + + // the page has a custom preview setting, + // thus the file is only accessible through + // the direct media URL + if ($preview !== true) { + return $this->url(); + } + + // it's more stable to access files for drafts + // through their direct URL to avoid conflicts + // with draft token verification + if ($parent->isDraft() === true) { + return $this->url(); + } + + // checks `file::url` component is extended + if ($this->kirby()->isNativeComponent('file::url') === false) { + return $this->url(); + } + + return $url; + case 'user': + return $this->url(); + default: + return $url; + } + } } diff --git a/kirby/src/Cms/FileActions.php b/kirby/src/Cms/FileActions.php index b06c686..9e1b24f 100755 --- a/kirby/src/Cms/FileActions.php +++ b/kirby/src/Cms/FileActions.php @@ -19,298 +19,298 @@ use Kirby\Form\Form; */ trait FileActions { - /** - * Renames the file without touching the extension - * The store is used to actually execute this. - * - * @param string $name - * @param bool $sanitize - * @return $this|static - * @throws \Kirby\Exception\LogicException - */ - public function changeName(string $name, bool $sanitize = true) - { - if ($sanitize === true) { - $name = F::safeName($name); - } + /** + * Renames the file without touching the extension + * The store is used to actually execute this. + * + * @param string $name + * @param bool $sanitize + * @return $this|static + * @throws \Kirby\Exception\LogicException + */ + public function changeName(string $name, bool $sanitize = true) + { + if ($sanitize === true) { + $name = F::safeName($name); + } - // don't rename if not necessary - if ($name === $this->name()) { - return $this; - } + // don't rename if not necessary + if ($name === $this->name()) { + return $this; + } - return $this->commit('changeName', ['file' => $this, 'name' => $name], function ($oldFile, $name) { - $newFile = $oldFile->clone([ - 'filename' => $name . '.' . $oldFile->extension(), - ]); + return $this->commit('changeName', ['file' => $this, 'name' => $name], function ($oldFile, $name) { + $newFile = $oldFile->clone([ + 'filename' => $name . '.' . $oldFile->extension(), + ]); - if ($oldFile->exists() === false) { - return $newFile; - } + if ($oldFile->exists() === false) { + return $newFile; + } - if ($newFile->exists() === true) { - throw new LogicException('The new file exists and cannot be overwritten'); - } + if ($newFile->exists() === true) { + throw new LogicException('The new file exists and cannot be overwritten'); + } - // remove the lock of the old file - if ($lock = $oldFile->lock()) { - $lock->remove(); - } + // remove the lock of the old file + if ($lock = $oldFile->lock()) { + $lock->remove(); + } - // remove all public versions - $oldFile->unpublish(); + // remove all public versions + $oldFile->unpublish(); - // rename the main file - F::move($oldFile->root(), $newFile->root()); + // rename the main file + F::move($oldFile->root(), $newFile->root()); - if ($newFile->kirby()->multilang() === true) { - foreach ($newFile->translations() as $translation) { - $translationCode = $translation->code(); + if ($newFile->kirby()->multilang() === true) { + foreach ($newFile->translations() as $translation) { + $translationCode = $translation->code(); - // rename the content file - F::move($oldFile->contentFile($translationCode), $newFile->contentFile($translationCode)); - } - } else { - // rename the content file - F::move($oldFile->contentFile(), $newFile->contentFile()); - } + // rename the content file + F::move($oldFile->contentFile($translationCode), $newFile->contentFile($translationCode)); + } + } else { + // rename the content file + F::move($oldFile->contentFile(), $newFile->contentFile()); + } - $newFile->parent()->files()->remove($oldFile->id()); - $newFile->parent()->files()->set($newFile->id(), $newFile); + $newFile->parent()->files()->remove($oldFile->id()); + $newFile->parent()->files()->set($newFile->id(), $newFile); - return $newFile; - }); - } + return $newFile; + }); + } - /** - * Changes the file's sorting number in the meta file - * - * @param int $sort - * @return static - */ - public function changeSort(int $sort) - { - return $this->commit( - 'changeSort', - ['file' => $this, 'position' => $sort], - fn ($file, $sort) => $file->save(['sort' => $sort]) - ); - } + /** + * Changes the file's sorting number in the meta file + * + * @param int $sort + * @return static + */ + public function changeSort(int $sort) + { + return $this->commit( + 'changeSort', + ['file' => $this, 'position' => $sort], + fn ($file, $sort) => $file->save(['sort' => $sort]) + ); + } - /** - * Commits a file action, by following these steps - * - * 1. checks the action rules - * 2. sends the before hook - * 3. commits the store action - * 4. sends the after hook - * 5. returns the result - * - * @param string $action - * @param array $arguments - * @param Closure $callback - * @return mixed - */ - protected function commit(string $action, array $arguments, Closure $callback) - { - $old = $this->hardcopy(); - $kirby = $this->kirby(); - $argumentValues = array_values($arguments); + /** + * Commits a file action, by following these steps + * + * 1. checks the action rules + * 2. sends the before hook + * 3. commits the store action + * 4. sends the after hook + * 5. returns the result + * + * @param string $action + * @param array $arguments + * @param Closure $callback + * @return mixed + */ + protected function commit(string $action, array $arguments, Closure $callback) + { + $old = $this->hardcopy(); + $kirby = $this->kirby(); + $argumentValues = array_values($arguments); - $this->rules()->$action(...$argumentValues); - $kirby->trigger('file.' . $action . ':before', $arguments); + $this->rules()->$action(...$argumentValues); + $kirby->trigger('file.' . $action . ':before', $arguments); - $result = $callback(...$argumentValues); + $result = $callback(...$argumentValues); - if ($action === 'create') { - $argumentsAfter = ['file' => $result]; - } elseif ($action === 'delete') { - $argumentsAfter = ['status' => $result, 'file' => $old]; - } else { - $argumentsAfter = ['newFile' => $result, 'oldFile' => $old]; - } - $kirby->trigger('file.' . $action . ':after', $argumentsAfter); + if ($action === 'create') { + $argumentsAfter = ['file' => $result]; + } elseif ($action === 'delete') { + $argumentsAfter = ['status' => $result, 'file' => $old]; + } else { + $argumentsAfter = ['newFile' => $result, 'oldFile' => $old]; + } + $kirby->trigger('file.' . $action . ':after', $argumentsAfter); - $kirby->cache('pages')->flush(); - return $result; - } + $kirby->cache('pages')->flush(); + return $result; + } - /** - * Copy the file to the given page - * - * @param \Kirby\Cms\Page $page - * @return \Kirby\Cms\File - */ - public function copy(Page $page) - { - F::copy($this->root(), $page->root() . '/' . $this->filename()); + /** + * Copy the file to the given page + * + * @param \Kirby\Cms\Page $page + * @return \Kirby\Cms\File + */ + public function copy(Page $page) + { + F::copy($this->root(), $page->root() . '/' . $this->filename()); - if ($this->kirby()->multilang() === true) { - foreach ($this->kirby()->languages() as $language) { - $contentFile = $this->contentFile($language->code()); - F::copy($contentFile, $page->root() . '/' . basename($contentFile)); - } - } else { - $contentFile = $this->contentFile(); - F::copy($contentFile, $page->root() . '/' . basename($contentFile)); - } + if ($this->kirby()->multilang() === true) { + foreach ($this->kirby()->languages() as $language) { + $contentFile = $this->contentFile($language->code()); + F::copy($contentFile, $page->root() . '/' . basename($contentFile)); + } + } else { + $contentFile = $this->contentFile(); + F::copy($contentFile, $page->root() . '/' . basename($contentFile)); + } - return $page->clone()->file($this->filename()); - } + return $page->clone()->file($this->filename()); + } - /** - * Creates a new file on disk and returns the - * File object. The store is used to handle file - * writing, so it can be replaced by any other - * way of generating files. - * - * @param array $props - * @return static - * @throws \Kirby\Exception\InvalidArgumentException - * @throws \Kirby\Exception\LogicException - */ - public static function create(array $props) - { - if (isset($props['source'], $props['parent']) === false) { - throw new InvalidArgumentException('Please provide the "source" and "parent" props for the File'); - } + /** + * Creates a new file on disk and returns the + * File object. The store is used to handle file + * writing, so it can be replaced by any other + * way of generating files. + * + * @param array $props + * @return static + * @throws \Kirby\Exception\InvalidArgumentException + * @throws \Kirby\Exception\LogicException + */ + public static function create(array $props) + { + if (isset($props['source'], $props['parent']) === false) { + throw new InvalidArgumentException('Please provide the "source" and "parent" props for the File'); + } - // prefer the filename from the props - $props['filename'] = F::safeName($props['filename'] ?? basename($props['source'])); + // prefer the filename from the props + $props['filename'] = F::safeName($props['filename'] ?? basename($props['source'])); - $props['model'] = strtolower($props['template'] ?? 'default'); + $props['model'] = strtolower($props['template'] ?? 'default'); - // create the basic file and a test upload object - $file = static::factory($props); - $upload = $file->asset($props['source']); + // create the basic file and a test upload object + $file = static::factory($props); + $upload = $file->asset($props['source']); - // create a form for the file - $form = Form::for($file, [ - 'values' => $props['content'] ?? [] - ]); + // create a form for the file + $form = Form::for($file, [ + 'values' => $props['content'] ?? [] + ]); - // inject the content - $file = $file->clone(['content' => $form->strings(true)]); + // inject the content + $file = $file->clone(['content' => $form->strings(true)]); - // run the hook - return $file->commit('create', compact('file', 'upload'), function ($file, $upload) { + // run the hook + return $file->commit('create', compact('file', 'upload'), function ($file, $upload) { - // delete all public versions - $file->unpublish(); + // delete all public versions + $file->unpublish(); - // overwrite the original - if (F::copy($upload->root(), $file->root(), true) !== true) { - throw new LogicException('The file could not be created'); - } + // overwrite the original + if (F::copy($upload->root(), $file->root(), true) !== true) { + throw new LogicException('The file could not be created'); + } - // always create pages in the default language - if ($file->kirby()->multilang() === true) { - $languageCode = $file->kirby()->defaultLanguage()->code(); - } else { - $languageCode = null; - } + // always create pages in the default language + if ($file->kirby()->multilang() === true) { + $languageCode = $file->kirby()->defaultLanguage()->code(); + } else { + $languageCode = null; + } - // store the content if necessary - $file->save($file->content()->toArray(), $languageCode); + // store the content if necessary + $file->save($file->content()->toArray(), $languageCode); - // add the file to the list of siblings - $file->siblings()->append($file->id(), $file); + // add the file to the list of siblings + $file->siblings()->append($file->id(), $file); - // return a fresh clone - return $file->clone(); - }); - } + // return a fresh clone + return $file->clone(); + }); + } - /** - * Deletes the file. The store is used to - * manipulate the filesystem or whatever you prefer. - * - * @return bool - */ - public function delete(): bool - { - return $this->commit('delete', ['file' => $this], function ($file) { + /** + * Deletes the file. The store is used to + * manipulate the filesystem or whatever you prefer. + * + * @return bool + */ + public function delete(): bool + { + return $this->commit('delete', ['file' => $this], function ($file) { - // remove all versions in the media folder - $file->unpublish(); + // remove all versions in the media folder + $file->unpublish(); - // remove the lock of the old file - if ($lock = $file->lock()) { - $lock->remove(); - } + // remove the lock of the old file + if ($lock = $file->lock()) { + $lock->remove(); + } - if ($file->kirby()->multilang() === true) { - foreach ($file->translations() as $translation) { - F::remove($file->contentFile($translation->code())); - } - } else { - F::remove($file->contentFile()); - } + if ($file->kirby()->multilang() === true) { + foreach ($file->translations() as $translation) { + F::remove($file->contentFile($translation->code())); + } + } else { + F::remove($file->contentFile()); + } - F::remove($file->root()); + F::remove($file->root()); - // remove the file from the sibling collection - $file->parent()->files()->remove($file); + // remove the file from the sibling collection + $file->parent()->files()->remove($file); - return true; - }); - } + return true; + }); + } - /** - * Move the file to the public media folder - * if it's not already there. - * - * @return $this - */ - public function publish() - { - Media::publish($this, $this->mediaRoot()); - return $this; - } + /** + * Move the file to the public media folder + * if it's not already there. + * + * @return $this + */ + public function publish() + { + Media::publish($this, $this->mediaRoot()); + return $this; + } - /** - * Replaces the file. The source must - * be an absolute path to a file or a Url. - * The store handles the replacement so it - * finally decides what it will support as - * source. - * - * @param string $source - * @return static - * @throws \Kirby\Exception\LogicException - */ - public function replace(string $source) - { - $file = $this->clone(); + /** + * Replaces the file. The source must + * be an absolute path to a file or a Url. + * The store handles the replacement so it + * finally decides what it will support as + * source. + * + * @param string $source + * @return static + * @throws \Kirby\Exception\LogicException + */ + public function replace(string $source) + { + $file = $this->clone(); - $arguments = [ - 'file' => $file, - 'upload' => $file->asset($source) - ]; + $arguments = [ + 'file' => $file, + 'upload' => $file->asset($source) + ]; - return $this->commit('replace', $arguments, function ($file, $upload) { + return $this->commit('replace', $arguments, function ($file, $upload) { - // delete all public versions - $file->unpublish(); + // delete all public versions + $file->unpublish(); - // overwrite the original - if (F::copy($upload->root(), $file->root(), true) !== true) { - throw new LogicException('The file could not be created'); - } + // overwrite the original + if (F::copy($upload->root(), $file->root(), true) !== true) { + throw new LogicException('The file could not be created'); + } - // return a fresh clone - return $file->clone(); - }); - } + // return a fresh clone + return $file->clone(); + }); + } - /** - * Remove all public versions of this file - * - * @return $this - */ - public function unpublish() - { - Media::unpublish($this->parent()->mediaRoot(), $this); - return $this; - } + /** + * Remove all public versions of this file + * + * @return $this + */ + public function unpublish() + { + Media::unpublish($this->parent()->mediaRoot(), $this); + return $this; + } } diff --git a/kirby/src/Cms/FileBlueprint.php b/kirby/src/Cms/FileBlueprint.php index 3cb1062..aee9b8b 100755 --- a/kirby/src/Cms/FileBlueprint.php +++ b/kirby/src/Cms/FileBlueprint.php @@ -17,172 +17,172 @@ use Kirby\Toolkit\Str; */ class FileBlueprint extends Blueprint { - /** - * `true` if the default accepted - * types are being used - * - * @var bool - */ - protected $defaultTypes = false; + /** + * `true` if the default accepted + * types are being used + * + * @var bool + */ + protected $defaultTypes = false; - public function __construct(array $props) - { - parent::__construct($props); + public function __construct(array $props) + { + parent::__construct($props); - // normalize all available page options - $this->props['options'] = $this->normalizeOptions( - $this->props['options'] ?? true, - // defaults - [ - 'changeName' => null, - 'create' => null, - 'delete' => null, - 'read' => null, - 'replace' => null, - 'update' => null, - ] - ); + // normalize all available page options + $this->props['options'] = $this->normalizeOptions( + $this->props['options'] ?? true, + // defaults + [ + 'changeName' => null, + 'create' => null, + 'delete' => null, + 'read' => null, + 'replace' => null, + 'update' => null, + ] + ); - // normalize the accept settings - $this->props['accept'] = $this->normalizeAccept($this->props['accept'] ?? []); - } + // normalize the accept settings + $this->props['accept'] = $this->normalizeAccept($this->props['accept'] ?? []); + } - /** - * @return array - */ - public function accept(): array - { - return $this->props['accept']; - } + /** + * @return array + */ + public function accept(): array + { + return $this->props['accept']; + } - /** - * Returns the list of all accepted MIME types for - * file upload or `*` if all MIME types are allowed - * - * @return string - */ - public function acceptMime(): string - { - // don't disclose the specific default types - if ($this->defaultTypes === true) { - return '*'; - } + /** + * Returns the list of all accepted MIME types for + * file upload or `*` if all MIME types are allowed + * + * @return string + */ + public function acceptMime(): string + { + // don't disclose the specific default types + if ($this->defaultTypes === true) { + return '*'; + } - $accept = $this->accept(); - $restrictions = []; + $accept = $this->accept(); + $restrictions = []; - if (is_array($accept['mime']) === true) { - $restrictions[] = $accept['mime']; - } else { - // only fall back to the extension or type if - // no explicit MIME types were defined - // (allows to set custom MIME types for the frontend - // check but still restrict the extension and/or type) + if (is_array($accept['mime']) === true) { + $restrictions[] = $accept['mime']; + } else { + // only fall back to the extension or type if + // no explicit MIME types were defined + // (allows to set custom MIME types for the frontend + // check but still restrict the extension and/or type) - if (is_array($accept['extension']) === true) { - // determine the main MIME type for each extension - $restrictions[] = array_map(['Kirby\Filesystem\Mime', 'fromExtension'], $accept['extension']); - } + if (is_array($accept['extension']) === true) { + // determine the main MIME type for each extension + $restrictions[] = array_map(['Kirby\Filesystem\Mime', 'fromExtension'], $accept['extension']); + } - if (is_array($accept['type']) === true) { - // determine the MIME types of each file type - $mimes = []; - foreach ($accept['type'] as $type) { - if ($extensions = F::typeToExtensions($type)) { - $mimes[] = array_map(['Kirby\Filesystem\Mime', 'fromExtension'], $extensions); - } - } + if (is_array($accept['type']) === true) { + // determine the MIME types of each file type + $mimes = []; + foreach ($accept['type'] as $type) { + if ($extensions = F::typeToExtensions($type)) { + $mimes[] = array_map(['Kirby\Filesystem\Mime', 'fromExtension'], $extensions); + } + } - $restrictions[] = array_merge(...$mimes); - } - } + $restrictions[] = array_merge(...$mimes); + } + } - if ($restrictions !== []) { - if (count($restrictions) > 1) { - // only return the MIME types that are allowed by all restrictions - $mimes = array_intersect(...$restrictions); - } else { - $mimes = $restrictions[0]; - } + if ($restrictions !== []) { + if (count($restrictions) > 1) { + // only return the MIME types that are allowed by all restrictions + $mimes = array_intersect(...$restrictions); + } else { + $mimes = $restrictions[0]; + } - // filter out empty MIME types and duplicates - return implode(', ', array_filter(array_unique($mimes))); - } + // filter out empty MIME types and duplicates + return implode(', ', array_filter(array_unique($mimes))); + } - // no restrictions, accept everything - return '*'; - } + // no restrictions, accept everything + return '*'; + } - /** - * @param mixed $accept - * @return array - */ - protected function normalizeAccept($accept = null): array - { - if (is_string($accept) === true) { - $accept = [ - 'mime' => $accept - ]; - } elseif ($accept === true) { - // explicitly no restrictions at all - $accept = [ - 'mime' => null - ]; - } elseif (empty($accept) === true) { - // no custom restrictions - $accept = []; - } + /** + * @param mixed $accept + * @return array + */ + protected function normalizeAccept($accept = null): array + { + if (is_string($accept) === true) { + $accept = [ + 'mime' => $accept + ]; + } elseif ($accept === true) { + // explicitly no restrictions at all + $accept = [ + 'mime' => null + ]; + } elseif (empty($accept) === true) { + // no custom restrictions + $accept = []; + } - $accept = array_change_key_case($accept); + $accept = array_change_key_case($accept); - $defaults = [ - 'extension' => null, - 'mime' => null, - 'maxheight' => null, - 'maxsize' => null, - 'maxwidth' => null, - 'minheight' => null, - 'minsize' => null, - 'minwidth' => null, - 'orientation' => null, - 'type' => null - ]; + $defaults = [ + 'extension' => null, + 'mime' => null, + 'maxheight' => null, + 'maxsize' => null, + 'maxwidth' => null, + 'minheight' => null, + 'minsize' => null, + 'minwidth' => null, + 'orientation' => null, + 'type' => null + ]; - // default type restriction if none are configured; - // this ensures that no unexpected files are uploaded - if ( - array_key_exists('mime', $accept) === false && - array_key_exists('extension', $accept) === false && - array_key_exists('type', $accept) === false - ) { - $defaults['type'] = ['image', 'document', 'archive', 'audio', 'video']; - $this->defaultTypes = true; - } + // default type restriction if none are configured; + // this ensures that no unexpected files are uploaded + if ( + array_key_exists('mime', $accept) === false && + array_key_exists('extension', $accept) === false && + array_key_exists('type', $accept) === false + ) { + $defaults['type'] = ['image', 'document', 'archive', 'audio', 'video']; + $this->defaultTypes = true; + } - $accept = array_merge($defaults, $accept); + $accept = array_merge($defaults, $accept); - // normalize the MIME, extension and type from strings into arrays - if (is_string($accept['mime']) === true) { - $accept['mime'] = array_map( - fn ($mime) => $mime['value'], - Str::accepted($accept['mime']) - ); - } + // normalize the MIME, extension and type from strings into arrays + if (is_string($accept['mime']) === true) { + $accept['mime'] = array_map( + fn ($mime) => $mime['value'], + Str::accepted($accept['mime']) + ); + } - if (is_string($accept['extension']) === true) { - $accept['extension'] = array_map( - 'trim', - explode(',', $accept['extension']) - ); - } + if (is_string($accept['extension']) === true) { + $accept['extension'] = array_map( + 'trim', + explode(',', $accept['extension']) + ); + } - if (is_string($accept['type']) === true) { - $accept['type'] = array_map( - 'trim', - explode(',', $accept['type']) - ); - } + if (is_string($accept['type']) === true) { + $accept['type'] = array_map( + 'trim', + explode(',', $accept['type']) + ); + } - return $accept; - } + return $accept; + } } diff --git a/kirby/src/Cms/FileModifications.php b/kirby/src/Cms/FileModifications.php index b9b6912..9e2ca70 100755 --- a/kirby/src/Cms/FileModifications.php +++ b/kirby/src/Cms/FileModifications.php @@ -15,200 +15,200 @@ use Kirby\Exception\InvalidArgumentException; */ trait FileModifications { - /** - * Blurs the image by the given amount of pixels - * - * @param bool $pixels - * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File - */ - public function blur($pixels = true) - { - return $this->thumb(['blur' => $pixels]); - } + /** + * Blurs the image by the given amount of pixels + * + * @param bool $pixels + * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File + */ + public function blur($pixels = true) + { + return $this->thumb(['blur' => $pixels]); + } - /** - * Converts the image to black and white - * - * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File - */ - public function bw() - { - return $this->thumb(['grayscale' => true]); - } + /** + * Converts the image to black and white + * + * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File + */ + public function bw() + { + return $this->thumb(['grayscale' => true]); + } - /** - * Crops the image by the given width and height - * - * @param int $width - * @param int|null $height - * @param string|array $options - * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File - */ - public function crop(int $width, int $height = null, $options = null) - { - $quality = null; - $crop = 'center'; + /** + * Crops the image by the given width and height + * + * @param int $width + * @param int|null $height + * @param string|array $options + * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File + */ + public function crop(int $width, int $height = null, $options = null) + { + $quality = null; + $crop = 'center'; - if (is_int($options) === true) { - $quality = $options; - } elseif (is_string($options)) { - $crop = $options; - } elseif (is_a($options, 'Kirby\Cms\Field') === true) { - $crop = $options->value(); - } elseif (is_array($options)) { - $quality = $options['quality'] ?? $quality; - $crop = $options['crop'] ?? $crop; - } + if (is_int($options) === true) { + $quality = $options; + } elseif (is_string($options)) { + $crop = $options; + } elseif (is_a($options, 'Kirby\Cms\Field') === true) { + $crop = $options->value(); + } elseif (is_array($options)) { + $quality = $options['quality'] ?? $quality; + $crop = $options['crop'] ?? $crop; + } - return $this->thumb([ - 'width' => $width, - 'height' => $height, - 'quality' => $quality, - 'crop' => $crop - ]); - } + return $this->thumb([ + 'width' => $width, + 'height' => $height, + 'quality' => $quality, + 'crop' => $crop + ]); + } - /** - * Alias for File::bw() - * - * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File - */ - public function grayscale() - { - return $this->thumb(['grayscale' => true]); - } + /** + * Alias for File::bw() + * + * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File + */ + public function grayscale() + { + return $this->thumb(['grayscale' => true]); + } - /** - * Alias for File::bw() - * - * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File - */ - public function greyscale() - { - return $this->thumb(['grayscale' => true]); - } + /** + * Alias for File::bw() + * + * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File + */ + public function greyscale() + { + return $this->thumb(['grayscale' => true]); + } - /** - * Sets the JPEG compression quality - * - * @param int $quality - * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File - */ - public function quality(int $quality) - { - return $this->thumb(['quality' => $quality]); - } + /** + * Sets the JPEG compression quality + * + * @param int $quality + * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File + */ + public function quality(int $quality) + { + return $this->thumb(['quality' => $quality]); + } - /** - * Resizes the file with the given width and height - * while keeping the aspect ratio. - * - * @param int|null $width - * @param int|null $height - * @param int|null $quality - * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function resize(int $width = null, int $height = null, int $quality = null) - { - return $this->thumb([ - 'width' => $width, - 'height' => $height, - 'quality' => $quality - ]); - } + /** + * Resizes the file with the given width and height + * while keeping the aspect ratio. + * + * @param int|null $width + * @param int|null $height + * @param int|null $quality + * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File + * @throws \Kirby\Exception\InvalidArgumentException + */ + public function resize(int $width = null, int $height = null, int $quality = null) + { + return $this->thumb([ + 'width' => $width, + 'height' => $height, + 'quality' => $quality + ]); + } - /** - * Create a srcset definition for the given sizes - * Sizes can be defined as a simple array. They can - * also be set up in the config with the thumbs.srcsets option. - * @since 3.1.0 - * - * @param array|string|null $sizes - * @return string|null - */ - public function srcset($sizes = null): ?string - { - if (empty($sizes) === true) { - $sizes = $this->kirby()->option('thumbs.srcsets.default', []); - } + /** + * Create a srcset definition for the given sizes + * Sizes can be defined as a simple array. They can + * also be set up in the config with the thumbs.srcsets option. + * @since 3.1.0 + * + * @param array|string|null $sizes + * @return string|null + */ + public function srcset($sizes = null): ?string + { + if (empty($sizes) === true) { + $sizes = $this->kirby()->option('thumbs.srcsets.default', []); + } - if (is_string($sizes) === true) { - $sizes = $this->kirby()->option('thumbs.srcsets.' . $sizes, []); - } + if (is_string($sizes) === true) { + $sizes = $this->kirby()->option('thumbs.srcsets.' . $sizes, []); + } - if (is_array($sizes) === false || empty($sizes) === true) { - return null; - } + if (is_array($sizes) === false || empty($sizes) === true) { + return null; + } - $set = []; + $set = []; - foreach ($sizes as $key => $value) { - if (is_array($value)) { - $options = $value; - $condition = $key; - } elseif (is_string($value) === true) { - $options = [ - 'width' => $key - ]; - $condition = $value; - } else { - $options = [ - 'width' => $value - ]; - $condition = $value . 'w'; - } + foreach ($sizes as $key => $value) { + if (is_array($value)) { + $options = $value; + $condition = $key; + } elseif (is_string($value) === true) { + $options = [ + 'width' => $key + ]; + $condition = $value; + } else { + $options = [ + 'width' => $value + ]; + $condition = $value . 'w'; + } - $set[] = $this->thumb($options)->url() . ' ' . $condition; - } + $set[] = $this->thumb($options)->url() . ' ' . $condition; + } - return implode(', ', $set); - } + return implode(', ', $set); + } - /** - * Creates a modified version of images - * The media manager takes care of generating - * those modified versions and putting them - * in the right place. This is normally the - * `/media` folder of your installation, but - * could potentially also be a CDN or any other - * place. - * - * @param array|null|string $options - * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function thumb($options = null) - { - // thumb presets - if (empty($options) === true) { - $options = $this->kirby()->option('thumbs.presets.default'); - } elseif (is_string($options) === true) { - $options = $this->kirby()->option('thumbs.presets.' . $options); - } + /** + * Creates a modified version of images + * The media manager takes care of generating + * those modified versions and putting them + * in the right place. This is normally the + * `/media` folder of your installation, but + * could potentially also be a CDN or any other + * place. + * + * @param array|null|string $options + * @return \Kirby\Cms\FileVersion|\Kirby\Cms\File + * @throws \Kirby\Exception\InvalidArgumentException + */ + public function thumb($options = null) + { + // thumb presets + if (empty($options) === true) { + $options = $this->kirby()->option('thumbs.presets.default'); + } elseif (is_string($options) === true) { + $options = $this->kirby()->option('thumbs.presets.' . $options); + } - if (empty($options) === true || is_array($options) === false) { - return $this; - } + if (empty($options) === true || is_array($options) === false) { + return $this; + } - // fallback to global config options - if (isset($options['format']) === false) { - if ($format = $this->kirby()->option('thumbs.format')) { - $options['format'] = $format; - } - } + // fallback to global config options + if (isset($options['format']) === false) { + if ($format = $this->kirby()->option('thumbs.format')) { + $options['format'] = $format; + } + } - $component = $this->kirby()->component('file::version'); - $result = $component($this->kirby(), $this, $options); + $component = $this->kirby()->component('file::version'); + $result = $component($this->kirby(), $this, $options); - if ( - is_a($result, 'Kirby\Cms\FileVersion') === false && - is_a($result, 'Kirby\Cms\File') === false && - is_a($result, 'Kirby\Filesystem\Asset') === false - ) { - throw new InvalidArgumentException('The file::version component must return a File, FileVersion or Asset object'); - } + if ( + is_a($result, 'Kirby\Cms\FileVersion') === false && + is_a($result, 'Kirby\Cms\File') === false && + is_a($result, 'Kirby\Filesystem\Asset') === false + ) { + throw new InvalidArgumentException('The file::version component must return a File, FileVersion or Asset object'); + } - return $result; - } + return $result; + } } diff --git a/kirby/src/Cms/FilePermissions.php b/kirby/src/Cms/FilePermissions.php index 674a058..e296de5 100755 --- a/kirby/src/Cms/FilePermissions.php +++ b/kirby/src/Cms/FilePermissions.php @@ -13,5 +13,5 @@ namespace Kirby\Cms; */ class FilePermissions extends ModelPermissions { - protected $category = 'files'; + protected $category = 'files'; } diff --git a/kirby/src/Cms/FilePicker.php b/kirby/src/Cms/FilePicker.php index b81ec9d..ea30ce1 100755 --- a/kirby/src/Cms/FilePicker.php +++ b/kirby/src/Cms/FilePicker.php @@ -17,58 +17,58 @@ use Kirby\Exception\InvalidArgumentException; */ class FilePicker extends Picker { - /** - * Extends the basic defaults - * - * @return array - */ - public function defaults(): array - { - $defaults = parent::defaults(); - $defaults['text'] = '{{ file.filename }}'; + /** + * Extends the basic defaults + * + * @return array + */ + public function defaults(): array + { + $defaults = parent::defaults(); + $defaults['text'] = '{{ file.filename }}'; - return $defaults; - } + return $defaults; + } - /** - * Search all files for the picker - * - * @return \Kirby\Cms\Files|null - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function items() - { - $model = $this->options['model']; + /** + * Search all files for the picker + * + * @return \Kirby\Cms\Files|null + * @throws \Kirby\Exception\InvalidArgumentException + */ + public function items() + { + $model = $this->options['model']; - // find the right default query - if (empty($this->options['query']) === false) { - $query = $this->options['query']; - } elseif (is_a($model, 'Kirby\Cms\File') === true) { - $query = 'file.siblings'; - } else { - $query = $model::CLASS_ALIAS . '.files'; - } + // find the right default query + if (empty($this->options['query']) === false) { + $query = $this->options['query']; + } elseif (is_a($model, 'Kirby\Cms\File') === true) { + $query = 'file.siblings'; + } else { + $query = $model::CLASS_ALIAS . '.files'; + } - // fetch all files for the picker - $files = $model->query($query); + // fetch all files for the picker + $files = $model->query($query); - // help mitigate some typical query usage issues - // by converting site and page objects to proper - // pages by returning their children - if (is_a($files, 'Kirby\Cms\Site') === true) { - $files = $files->files(); - } elseif (is_a($files, 'Kirby\Cms\Page') === true) { - $files = $files->files(); - } elseif (is_a($files, 'Kirby\Cms\User') === true) { - $files = $files->files(); - } elseif (is_a($files, 'Kirby\Cms\Files') === false) { - throw new InvalidArgumentException('Your query must return a set of files'); - } + // help mitigate some typical query usage issues + // by converting site and page objects to proper + // pages by returning their children + if (is_a($files, 'Kirby\Cms\Site') === true) { + $files = $files->files(); + } elseif (is_a($files, 'Kirby\Cms\Page') === true) { + $files = $files->files(); + } elseif (is_a($files, 'Kirby\Cms\User') === true) { + $files = $files->files(); + } elseif (is_a($files, 'Kirby\Cms\Files') === false) { + throw new InvalidArgumentException('Your query must return a set of files'); + } - // search - $files = $this->search($files); + // search + $files = $this->search($files); - // paginate - return $this->paginate($files); - } + // paginate + return $this->paginate($files); + } } diff --git a/kirby/src/Cms/FileRules.php b/kirby/src/Cms/FileRules.php index 4bfb237..09c6b53 100755 --- a/kirby/src/Cms/FileRules.php +++ b/kirby/src/Cms/FileRules.php @@ -20,315 +20,315 @@ use Kirby\Toolkit\V; */ class FileRules { - /** - * Validates if the filename can be changed - * - * @param \Kirby\Cms\File $file - * @param string $name - * @return bool - * @throws \Kirby\Exception\DuplicateException If a file with this name exists - * @throws \Kirby\Exception\PermissionException If the user is not allowed to rename the file - */ - public static function changeName(File $file, string $name): bool - { - if ($file->permissions()->changeName() !== true) { - throw new PermissionException([ - 'key' => 'file.changeName.permission', - 'data' => ['filename' => $file->filename()] - ]); - } + /** + * Validates if the filename can be changed + * + * @param \Kirby\Cms\File $file + * @param string $name + * @return bool + * @throws \Kirby\Exception\DuplicateException If a file with this name exists + * @throws \Kirby\Exception\PermissionException If the user is not allowed to rename the file + */ + public static function changeName(File $file, string $name): bool + { + if ($file->permissions()->changeName() !== true) { + throw new PermissionException([ + 'key' => 'file.changeName.permission', + 'data' => ['filename' => $file->filename()] + ]); + } - if (Str::length($name) === 0) { - throw new InvalidArgumentException([ - 'key' => 'file.changeName.empty' - ]); - } + if (Str::length($name) === 0) { + throw new InvalidArgumentException([ + 'key' => 'file.changeName.empty' + ]); + } - $parent = $file->parent(); - $duplicate = $parent->files()->not($file)->findBy('filename', $name . '.' . $file->extension()); + $parent = $file->parent(); + $duplicate = $parent->files()->not($file)->findBy('filename', $name . '.' . $file->extension()); - if ($duplicate) { - throw new DuplicateException([ - 'key' => 'file.duplicate', - 'data' => ['filename' => $duplicate->filename()] - ]); - } + if ($duplicate) { + throw new DuplicateException([ + 'key' => 'file.duplicate', + 'data' => ['filename' => $duplicate->filename()] + ]); + } - return true; - } + return true; + } - /** - * Validates if the file can be sorted - * - * @param \Kirby\Cms\File $file - * @param int $sort - * @return bool - */ - public static function changeSort(File $file, int $sort): bool - { - return true; - } + /** + * Validates if the file can be sorted + * + * @param \Kirby\Cms\File $file + * @param int $sort + * @return bool + */ + public static function changeSort(File $file, int $sort): bool + { + return true; + } - /** - * Validates if the file can be created - * - * @param \Kirby\Cms\File $file - * @param \Kirby\Filesystem\File $upload - * @return bool - * @throws \Kirby\Exception\DuplicateException If a file with the same name exists - * @throws \Kirby\Exception\PermissionException If the user is not allowed to create the file - */ - public static function create(File $file, BaseFile $upload): bool - { - // We want to ensure that we are not creating duplicate files. - // If a file with the same name already exists - if ($file->exists() === true) { - // $file will be based on the props of the new file, - // to compare templates, we need to get the props of - // the already existing file from meta content file - $existing = $file->parent()->file($file->filename()); + /** + * Validates if the file can be created + * + * @param \Kirby\Cms\File $file + * @param \Kirby\Filesystem\File $upload + * @return bool + * @throws \Kirby\Exception\DuplicateException If a file with the same name exists + * @throws \Kirby\Exception\PermissionException If the user is not allowed to create the file + */ + public static function create(File $file, BaseFile $upload): bool + { + // We want to ensure that we are not creating duplicate files. + // If a file with the same name already exists + if ($file->exists() === true) { + // $file will be based on the props of the new file, + // to compare templates, we need to get the props of + // the already existing file from meta content file + $existing = $file->parent()->file($file->filename()); - // if the new upload is the exact same file - // and uses the same template, we can continue - if ( - $file->sha1() === $upload->sha1() && - $file->template() === $existing->template() - ) { - return true; - } + // if the new upload is the exact same file + // and uses the same template, we can continue + if ( + $file->sha1() === $upload->sha1() && + $file->template() === $existing->template() + ) { + return true; + } - // otherwise throw an error for duplicate file - throw new DuplicateException([ - 'key' => 'file.duplicate', - 'data' => [ - 'filename' => $file->filename() - ] - ]); - } + // otherwise throw an error for duplicate file + throw new DuplicateException([ + 'key' => 'file.duplicate', + 'data' => [ + 'filename' => $file->filename() + ] + ]); + } - if ($file->permissions()->create() !== true) { - throw new PermissionException('The file cannot be created'); - } + if ($file->permissions()->create() !== true) { + throw new PermissionException('The file cannot be created'); + } - static::validFile($file, $upload->mime()); + static::validFile($file, $upload->mime()); - $upload->match($file->blueprint()->accept()); - $upload->validateContents(true); + $upload->match($file->blueprint()->accept()); + $upload->validateContents(true); - return true; - } + return true; + } - /** - * Validates if the file can be deleted - * - * @param \Kirby\Cms\File $file - * @return bool - * @throws \Kirby\Exception\PermissionException If the user is not allowed to delete the file - */ - public static function delete(File $file): bool - { - if ($file->permissions()->delete() !== true) { - throw new PermissionException('The file cannot be deleted'); - } + /** + * Validates if the file can be deleted + * + * @param \Kirby\Cms\File $file + * @return bool + * @throws \Kirby\Exception\PermissionException If the user is not allowed to delete the file + */ + public static function delete(File $file): bool + { + if ($file->permissions()->delete() !== true) { + throw new PermissionException('The file cannot be deleted'); + } - return true; - } + return true; + } - /** - * Validates if the file can be replaced - * - * @param \Kirby\Cms\File $file - * @param \Kirby\Filesystem\File $upload - * @return bool - * @throws \Kirby\Exception\PermissionException If the user is not allowed to replace the file - * @throws \Kirby\Exception\InvalidArgumentException If the file type of the new file is different - */ - public static function replace(File $file, BaseFile $upload): bool - { - if ($file->permissions()->replace() !== true) { - throw new PermissionException('The file cannot be replaced'); - } + /** + * Validates if the file can be replaced + * + * @param \Kirby\Cms\File $file + * @param \Kirby\Filesystem\File $upload + * @return bool + * @throws \Kirby\Exception\PermissionException If the user is not allowed to replace the file + * @throws \Kirby\Exception\InvalidArgumentException If the file type of the new file is different + */ + public static function replace(File $file, BaseFile $upload): bool + { + if ($file->permissions()->replace() !== true) { + throw new PermissionException('The file cannot be replaced'); + } - static::validMime($file, $upload->mime()); + static::validMime($file, $upload->mime()); - if ( - (string)$upload->mime() !== (string)$file->mime() && - (string)$upload->extension() !== (string)$file->extension() - ) { - throw new InvalidArgumentException([ - 'key' => 'file.mime.differs', - 'data' => ['mime' => $file->mime()] - ]); - } + if ( + (string)$upload->mime() !== (string)$file->mime() && + (string)$upload->extension() !== (string)$file->extension() + ) { + throw new InvalidArgumentException([ + 'key' => 'file.mime.differs', + 'data' => ['mime' => $file->mime()] + ]); + } - $upload->match($file->blueprint()->accept()); - $upload->validateContents(true); + $upload->match($file->blueprint()->accept()); + $upload->validateContents(true); - return true; - } + return true; + } - /** - * Validates if the file can be updated - * - * @param \Kirby\Cms\File $file - * @param array $content - * @return bool - * @throws \Kirby\Exception\PermissionException If the user is not allowed to update the file - */ - public static function update(File $file, array $content = []): bool - { - if ($file->permissions()->update() !== true) { - throw new PermissionException('The file cannot be updated'); - } + /** + * Validates if the file can be updated + * + * @param \Kirby\Cms\File $file + * @param array $content + * @return bool + * @throws \Kirby\Exception\PermissionException If the user is not allowed to update the file + */ + public static function update(File $file, array $content = []): bool + { + if ($file->permissions()->update() !== true) { + throw new PermissionException('The file cannot be updated'); + } - return true; - } + return true; + } - /** - * Validates the file extension - * - * @param \Kirby\Cms\File $file - * @param string $extension - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException If the extension is missing or forbidden - */ - public static function validExtension(File $file, string $extension): bool - { - // make it easier to compare the extension - $extension = strtolower($extension); + /** + * Validates the file extension + * + * @param \Kirby\Cms\File $file + * @param string $extension + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException If the extension is missing or forbidden + */ + public static function validExtension(File $file, string $extension): bool + { + // make it easier to compare the extension + $extension = strtolower($extension); - if (empty($extension) === true) { - throw new InvalidArgumentException([ - 'key' => 'file.extension.missing', - 'data' => ['filename' => $file->filename()] - ]); - } + if (empty($extension) === true) { + throw new InvalidArgumentException([ + 'key' => 'file.extension.missing', + 'data' => ['filename' => $file->filename()] + ]); + } - if ( - Str::contains($extension, 'php') !== false || - Str::contains($extension, 'phar') !== false || - Str::contains($extension, 'phtml') !== false - ) { - throw new InvalidArgumentException([ - 'key' => 'file.type.forbidden', - 'data' => ['type' => 'PHP'] - ]); - } + if ( + Str::contains($extension, 'php') !== false || + Str::contains($extension, 'phar') !== false || + Str::contains($extension, 'phtml') !== false + ) { + throw new InvalidArgumentException([ + 'key' => 'file.type.forbidden', + 'data' => ['type' => 'PHP'] + ]); + } - if (Str::contains($extension, 'htm') !== false) { - throw new InvalidArgumentException([ - 'key' => 'file.type.forbidden', - 'data' => ['type' => 'HTML'] - ]); - } + if (Str::contains($extension, 'htm') !== false) { + throw new InvalidArgumentException([ + 'key' => 'file.type.forbidden', + 'data' => ['type' => 'HTML'] + ]); + } - if (V::in($extension, ['exe', App::instance()->contentExtension()]) !== false) { - throw new InvalidArgumentException([ - 'key' => 'file.extension.forbidden', - 'data' => ['extension' => $extension] - ]); - } + if (V::in($extension, ['exe', App::instance()->contentExtension()]) !== false) { + throw new InvalidArgumentException([ + 'key' => 'file.extension.forbidden', + 'data' => ['extension' => $extension] + ]); + } - return true; - } + return true; + } - /** - * Validates the extension, MIME type and filename - * - * @param \Kirby\Cms\File $file - * @param string|null|false $mime If not passed, the MIME type is detected from the file, - * if `false`, the MIME type is not validated for performance reasons - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException If the extension, MIME type or filename is missing or forbidden - */ - public static function validFile(File $file, $mime = null): bool - { - if ($mime === false) { - // request to skip the MIME check for performance reasons - $validMime = true; - } else { - $validMime = static::validMime($file, $mime ?? $file->mime()); - } + /** + * Validates the extension, MIME type and filename + * + * @param \Kirby\Cms\File $file + * @param string|null|false $mime If not passed, the MIME type is detected from the file, + * if `false`, the MIME type is not validated for performance reasons + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException If the extension, MIME type or filename is missing or forbidden + */ + public static function validFile(File $file, $mime = null): bool + { + if ($mime === false) { + // request to skip the MIME check for performance reasons + $validMime = true; + } else { + $validMime = static::validMime($file, $mime ?? $file->mime()); + } - return - $validMime && - static::validExtension($file, $file->extension()) && - static::validFilename($file, $file->filename()); - } + return + $validMime && + static::validExtension($file, $file->extension()) && + static::validFilename($file, $file->filename()); + } - /** - * Validates the filename - * - * @param \Kirby\Cms\File $file - * @param string $filename - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException If the filename is missing or forbidden - */ - public static function validFilename(File $file, string $filename): bool - { - // make it easier to compare the filename - $filename = strtolower($filename); + /** + * Validates the filename + * + * @param \Kirby\Cms\File $file + * @param string $filename + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException If the filename is missing or forbidden + */ + public static function validFilename(File $file, string $filename): bool + { + // make it easier to compare the filename + $filename = strtolower($filename); - // check for missing filenames - if (empty($filename)) { - throw new InvalidArgumentException([ - 'key' => 'file.name.missing' - ]); - } + // check for missing filenames + if (empty($filename)) { + throw new InvalidArgumentException([ + 'key' => 'file.name.missing' + ]); + } - // Block htaccess files - if (Str::startsWith($filename, '.ht')) { - throw new InvalidArgumentException([ - 'key' => 'file.type.forbidden', - 'data' => ['type' => 'Apache config'] - ]); - } + // Block htaccess files + if (Str::startsWith($filename, '.ht')) { + throw new InvalidArgumentException([ + 'key' => 'file.type.forbidden', + 'data' => ['type' => 'Apache config'] + ]); + } - // Block invisible files - if (Str::startsWith($filename, '.')) { - throw new InvalidArgumentException([ - 'key' => 'file.type.forbidden', - 'data' => ['type' => 'invisible'] - ]); - } + // Block invisible files + if (Str::startsWith($filename, '.')) { + throw new InvalidArgumentException([ + 'key' => 'file.type.forbidden', + 'data' => ['type' => 'invisible'] + ]); + } - return true; - } + return true; + } - /** - * Validates the MIME type - * - * @param \Kirby\Cms\File $file - * @param string|null $mime - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException If the MIME type is missing or forbidden - */ - public static function validMime(File $file, string $mime = null): bool - { - // make it easier to compare the mime - $mime = strtolower($mime); + /** + * Validates the MIME type + * + * @param \Kirby\Cms\File $file + * @param string|null $mime + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException If the MIME type is missing or forbidden + */ + public static function validMime(File $file, string $mime = null): bool + { + // make it easier to compare the mime + $mime = strtolower($mime); - if (empty($mime)) { - throw new InvalidArgumentException([ - 'key' => 'file.mime.missing', - 'data' => ['filename' => $file->filename()] - ]); - } + if (empty($mime)) { + throw new InvalidArgumentException([ + 'key' => 'file.mime.missing', + 'data' => ['filename' => $file->filename()] + ]); + } - if (Str::contains($mime, 'php')) { - throw new InvalidArgumentException([ - 'key' => 'file.type.forbidden', - 'data' => ['type' => 'PHP'] - ]); - } + if (Str::contains($mime, 'php')) { + throw new InvalidArgumentException([ + 'key' => 'file.type.forbidden', + 'data' => ['type' => 'PHP'] + ]); + } - if (V::in($mime, ['text/html', 'application/x-msdownload'])) { - throw new InvalidArgumentException([ - 'key' => 'file.mime.forbidden', - 'data' => ['mime' => $mime] - ]); - } + if (V::in($mime, ['text/html', 'application/x-msdownload'])) { + throw new InvalidArgumentException([ + 'key' => 'file.mime.forbidden', + 'data' => ['mime' => $mime] + ]); + } - return true; - } + return true; + } } diff --git a/kirby/src/Cms/FileVersion.php b/kirby/src/Cms/FileVersion.php index 8db0aa5..8eb47b1 100755 --- a/kirby/src/Cms/FileVersion.php +++ b/kirby/src/Cms/FileVersion.php @@ -15,130 +15,130 @@ use Kirby\Filesystem\IsFile; */ class FileVersion { - use IsFile; + use IsFile; - protected $modifications; - protected $original; + protected $modifications; + protected $original; - /** - * Proxy for public properties, asset methods - * and content field getters - * - * @param string $method - * @param array $arguments - * @return mixed - */ - public function __call(string $method, array $arguments = []) - { - // public property access - if (isset($this->$method) === true) { - return $this->$method; - } + /** + * Proxy for public properties, asset methods + * and content field getters + * + * @param string $method + * @param array $arguments + * @return mixed + */ + public function __call(string $method, array $arguments = []) + { + // public property access + if (isset($this->$method) === true) { + return $this->$method; + } - // asset method proxy - if (method_exists($this->asset(), $method)) { - if ($this->exists() === false) { - $this->save(); - } + // asset method proxy + if (method_exists($this->asset(), $method)) { + if ($this->exists() === false) { + $this->save(); + } - return $this->asset()->$method(...$arguments); - } + return $this->asset()->$method(...$arguments); + } - // content fields - if (is_a($this->original(), 'Kirby\Cms\File') === true) { - return $this->original()->content()->get($method, $arguments); - } - } + // content fields + if (is_a($this->original(), 'Kirby\Cms\File') === true) { + return $this->original()->content()->get($method, $arguments); + } + } - /** - * Returns the unique ID - * - * @return string - */ - public function id(): string - { - return dirname($this->original()->id()) . '/' . $this->filename(); - } + /** + * Returns the unique ID + * + * @return string + */ + public function id(): string + { + return dirname($this->original()->id()) . '/' . $this->filename(); + } - /** - * Returns the parent Kirby App instance - * - * @return \Kirby\Cms\App - */ - public function kirby() - { - return $this->original()->kirby(); - } + /** + * Returns the parent Kirby App instance + * + * @return \Kirby\Cms\App + */ + public function kirby() + { + return $this->original()->kirby(); + } - /** - * Returns an array with all applied modifications - * - * @return array - */ - public function modifications(): array - { - return $this->modifications ?? []; - } + /** + * Returns an array with all applied modifications + * + * @return array + */ + public function modifications(): array + { + return $this->modifications ?? []; + } - /** - * Returns the instance of the original File object - * - * @return mixed - */ - public function original() - { - return $this->original; - } + /** + * Returns the instance of the original File object + * + * @return mixed + */ + public function original() + { + return $this->original; + } - /** - * Applies the stored modifications and - * saves the file on disk - * - * @return $this - */ - public function save() - { - $this->kirby()->thumb( - $this->original()->root(), - $this->root(), - $this->modifications() - ); - return $this; - } + /** + * Applies the stored modifications and + * saves the file on disk + * + * @return $this + */ + public function save() + { + $this->kirby()->thumb( + $this->original()->root(), + $this->root(), + $this->modifications() + ); + return $this; + } - /** - * Setter for modifications - * - * @param array|null $modifications - */ - protected function setModifications(array $modifications = null) - { - $this->modifications = $modifications; - } + /** + * Setter for modifications + * + * @param array|null $modifications + */ + protected function setModifications(array $modifications = null) + { + $this->modifications = $modifications; + } - /** - * Setter for the original File object - * - * @param $original - */ - protected function setOriginal($original) - { - $this->original = $original; - } + /** + * Setter for the original File object + * + * @param $original + */ + protected function setOriginal($original) + { + $this->original = $original; + } - /** - * Converts the object to an array - * - * @return array - */ - public function toArray(): array - { - $array = array_merge($this->asset()->toArray(), [ - 'modifications' => $this->modifications(), - ]); + /** + * Converts the object to an array + * + * @return array + */ + public function toArray(): array + { + $array = array_merge($this->asset()->toArray(), [ + 'modifications' => $this->modifications(), + ]); - ksort($array); + ksort($array); - return $array; - } + return $array; + } } diff --git a/kirby/src/Cms/Files.php b/kirby/src/Cms/Files.php index fe00604..ab5b249 100755 --- a/kirby/src/Cms/Files.php +++ b/kirby/src/Cms/Files.php @@ -21,177 +21,177 @@ use Kirby\Filesystem\F; */ class Files extends Collection { - /** - * All registered files methods - * - * @var array - */ - public static $methods = []; + /** + * All registered files methods + * + * @var array + */ + public static $methods = []; - /** - * Adds a single file or - * an entire second collection to the - * current collection - * - * @param \Kirby\Cms\Files|\Kirby\Cms\File|string $object - * @return $this - * @throws \Kirby\Exception\InvalidArgumentException When no `File` or `Files` object or an ID of an existing file is passed - */ - public function add($object) - { - // add a files collection - if (is_a($object, self::class) === true) { - $this->data = array_merge($this->data, $object->data); + /** + * Adds a single file or + * an entire second collection to the + * current collection + * + * @param \Kirby\Cms\Files|\Kirby\Cms\File|string $object + * @return $this + * @throws \Kirby\Exception\InvalidArgumentException When no `File` or `Files` object or an ID of an existing file is passed + */ + public function add($object) + { + // add a files collection + if (is_a($object, self::class) === true) { + $this->data = array_merge($this->data, $object->data); - // add a file by id - } elseif (is_string($object) === true && $file = App::instance()->file($object)) { - $this->__set($file->id(), $file); + // add a file by id + } elseif (is_string($object) === true && $file = App::instance()->file($object)) { + $this->__set($file->id(), $file); - // add a file object - } elseif (is_a($object, 'Kirby\Cms\File') === true) { - $this->__set($object->id(), $object); + // add a file object + } elseif (is_a($object, 'Kirby\Cms\File') === true) { + $this->__set($object->id(), $object); - // give a useful error message on invalid input; - // silently ignore "empty" values for compatibility with existing setups - } elseif (in_array($object, [null, false, true], true) !== true) { - throw new InvalidArgumentException('You must pass a Files or File object or an ID of an existing file to the Files collection'); - } + // give a useful error message on invalid input; + // silently ignore "empty" values for compatibility with existing setups + } elseif (in_array($object, [null, false, true], true) !== true) { + throw new InvalidArgumentException('You must pass a Files or File object or an ID of an existing file to the Files collection'); + } - return $this; - } + return $this; + } - /** - * Sort all given files by the - * order in the array - * - * @param array $files List of file ids - * @param int $offset Sorting offset - * @return $this - */ - public function changeSort(array $files, int $offset = 0) - { - foreach ($files as $filename) { - if ($file = $this->get($filename)) { - $offset++; - $file->changeSort($offset); - } - } + /** + * Sort all given files by the + * order in the array + * + * @param array $files List of file ids + * @param int $offset Sorting offset + * @return $this + */ + public function changeSort(array $files, int $offset = 0) + { + foreach ($files as $filename) { + if ($file = $this->get($filename)) { + $offset++; + $file->changeSort($offset); + } + } - return $this; - } + return $this; + } - /** - * Creates a files collection from an array of props - * - * @param array $files - * @param \Kirby\Cms\Model $parent - * @return static - */ - public static function factory(array $files, Model $parent) - { - $collection = new static([], $parent); - $kirby = $parent->kirby(); + /** + * Creates a files collection from an array of props + * + * @param array $files + * @param \Kirby\Cms\Model $parent + * @return static + */ + public static function factory(array $files, Model $parent) + { + $collection = new static([], $parent); + $kirby = $parent->kirby(); - foreach ($files as $props) { - $props['collection'] = $collection; - $props['kirby'] = $kirby; - $props['parent'] = $parent; + foreach ($files as $props) { + $props['collection'] = $collection; + $props['kirby'] = $kirby; + $props['parent'] = $parent; - $file = File::factory($props); + $file = File::factory($props); - $collection->data[$file->id()] = $file; - } + $collection->data[$file->id()] = $file; + } - return $collection; - } + return $collection; + } - /** - * Tries to find a file by id/filename - * @deprecated 3.7.0 Use `$files->find()` instead - * @todo 3.8.0 Remove method - * @codeCoverageIgnore - * - * @param string $id - * @return \Kirby\Cms\File|null - */ - public function findById(string $id) - { - Helpers::deprecated('Cms\Files::findById() has been deprecated and will be removed in Kirby 3.8.0. Use $files->find() instead.'); + /** + * Tries to find a file by id/filename + * @deprecated 3.7.0 Use `$files->find()` instead + * @todo 3.8.0 Remove method + * @codeCoverageIgnore + * + * @param string $id + * @return \Kirby\Cms\File|null + */ + public function findById(string $id) + { + Helpers::deprecated('Cms\Files::findById() has been deprecated and will be removed in Kirby 3.8.0. Use $files->find() instead.'); - return $this->findByKey($id); - } + return $this->findByKey($id); + } - /** - * Finds a file by its filename - * @internal Use `$files->find()` instead - * - * @param string $key - * @return \Kirby\Cms\File|null - */ - public function findByKey(string $key) - { - return $this->get(ltrim($this->parent->id() . '/' . $key, '/')); - } + /** + * Finds a file by its filename + * @internal Use `$files->find()` instead + * + * @param string $key + * @return \Kirby\Cms\File|null + */ + public function findByKey(string $key) + { + return $this->get(ltrim($this->parent->id() . '/' . $key, '/')); + } - /** - * Returns the file size for all - * files in the collection in a - * human-readable format - * @since 3.6.0 - * - * @param string|null|false $locale Locale for number formatting, - * `null` for the current locale, - * `false` to disable number formatting - * @return string - */ - public function niceSize($locale = null): string - { - return F::niceSize($this->size(), $locale); - } + /** + * Returns the file size for all + * files in the collection in a + * human-readable format + * @since 3.6.0 + * + * @param string|null|false $locale Locale for number formatting, + * `null` for the current locale, + * `false` to disable number formatting + * @return string + */ + public function niceSize($locale = null): string + { + return F::niceSize($this->size(), $locale); + } - /** - * Returns the raw size for all - * files in the collection - * @since 3.6.0 - * - * @return int - */ - public function size(): int - { - return F::size($this->values(fn ($file) => $file->root())); - } + /** + * Returns the raw size for all + * files in the collection + * @since 3.6.0 + * + * @return int + */ + public function size(): int + { + return F::size($this->values(fn ($file) => $file->root())); + } - /** - * Returns the collection sorted by - * the sort number and the filename - * - * @return static - */ - public function sorted() - { - return $this->sort('sort', 'asc', 'filename', 'asc'); - } + /** + * Returns the collection sorted by + * the sort number and the filename + * + * @return static + */ + public function sorted() + { + return $this->sort('sort', 'asc', 'filename', 'asc'); + } - /** - * Filter all files by the given template - * - * @param null|string|array $template - * @return $this|static - */ - public function template($template) - { - if (empty($template) === true) { - return $this; - } + /** + * Filter all files by the given template + * + * @param null|string|array $template + * @return $this|static + */ + public function template($template) + { + if (empty($template) === true) { + return $this; + } - if ($template === 'default') { - $template = ['default', '']; - } + if ($template === 'default') { + $template = ['default', '']; + } - return $this->filter( - 'template', - is_array($template) ? 'in' : '==', - $template - ); - } + return $this->filter( + 'template', + is_array($template) ? 'in' : '==', + $template + ); + } } diff --git a/kirby/src/Cms/Find.php b/kirby/src/Cms/Find.php index 585f9c7..581d3ab 100755 --- a/kirby/src/Cms/Find.php +++ b/kirby/src/Cms/Find.php @@ -19,173 +19,173 @@ use Kirby\Toolkit\Str; */ class Find { - /** - * Returns the file object for the given - * parent path and filename - * - * @param string|null $path Path to file's parent model - * @param string $filename Filename - * @return \Kirby\Cms\File|null - * @throws \Kirby\Exception\NotFoundException if the file cannot be found - */ - public static function file(string $path = null, string $filename) - { - $filename = urldecode($filename); - $file = static::parent($path)->file($filename); + /** + * Returns the file object for the given + * parent path and filename + * + * @param string|null $path Path to file's parent model + * @param string $filename Filename + * @return \Kirby\Cms\File|null + * @throws \Kirby\Exception\NotFoundException if the file cannot be found + */ + public static function file(string $path = null, string $filename) + { + $filename = urldecode($filename); + $file = static::parent($path)->file($filename); - if ($file && $file->isReadable() === true) { - return $file; - } + if ($file && $file->isReadable() === true) { + return $file; + } - throw new NotFoundException([ - 'key' => 'file.notFound', - 'data' => [ - 'filename' => $filename - ] - ]); - } + throw new NotFoundException([ + 'key' => 'file.notFound', + 'data' => [ + 'filename' => $filename + ] + ]); + } - /** - * Returns the language object for the given code - * - * @param string $code Language code - * @return \Kirby\Cms\Language|null - * @throws \Kirby\Exception\NotFoundException if the language cannot be found - */ - public static function language(string $code) - { - if ($language = App::instance()->language($code)) { - return $language; - } + /** + * Returns the language object for the given code + * + * @param string $code Language code + * @return \Kirby\Cms\Language|null + * @throws \Kirby\Exception\NotFoundException if the language cannot be found + */ + public static function language(string $code) + { + if ($language = App::instance()->language($code)) { + return $language; + } - throw new NotFoundException([ - 'key' => 'language.notFound', - 'data' => [ - 'code' => $code - ] - ]); - } + throw new NotFoundException([ + 'key' => 'language.notFound', + 'data' => [ + 'code' => $code + ] + ]); + } - /** - * Returns the page object for the given id - * - * @param string $id Page's id - * @return \Kirby\Cms\Page|null - * @throws \Kirby\Exception\NotFoundException if the page cannot be found - */ - public static function page(string $id) - { - $id = str_replace(['+', ' '], '/', $id); - $page = App::instance()->page($id); + /** + * Returns the page object for the given id + * + * @param string $id Page's id + * @return \Kirby\Cms\Page|null + * @throws \Kirby\Exception\NotFoundException if the page cannot be found + */ + public static function page(string $id) + { + $id = str_replace(['+', ' '], '/', $id); + $page = App::instance()->page($id); - if ($page && $page->isReadable() === true) { - return $page; - } + if ($page && $page->isReadable() === true) { + return $page; + } - throw new NotFoundException([ - 'key' => 'page.notFound', - 'data' => [ - 'slug' => $id - ] - ]); - } + throw new NotFoundException([ + 'key' => 'page.notFound', + 'data' => [ + 'slug' => $id + ] + ]); + } - /** - * Returns the model's object for the given path - * - * @param string $path Path to parent model - * @return \Kirby\Cms\Model|null - * @throws \Kirby\Exception\InvalidArgumentException if the model type is invalid - * @throws \Kirby\Exception\NotFoundException if the model cannot be found - */ - public static function parent(string $path) - { - $path = trim($path, '/'); - $modelType = in_array($path, ['site', 'account']) ? $path : trim(dirname($path), '/'); - $modelTypes = [ - 'site' => 'site', - 'users' => 'user', - 'pages' => 'page', - 'account' => 'account' - ]; + /** + * Returns the model's object for the given path + * + * @param string $path Path to parent model + * @return \Kirby\Cms\Model|null + * @throws \Kirby\Exception\InvalidArgumentException if the model type is invalid + * @throws \Kirby\Exception\NotFoundException if the model cannot be found + */ + public static function parent(string $path) + { + $path = trim($path, '/'); + $modelType = in_array($path, ['site', 'account']) ? $path : trim(dirname($path), '/'); + $modelTypes = [ + 'site' => 'site', + 'users' => 'user', + 'pages' => 'page', + 'account' => 'account' + ]; - $modelName = $modelTypes[$modelType] ?? null; + $modelName = $modelTypes[$modelType] ?? null; - if (Str::endsWith($modelType, '/files') === true) { - $modelName = 'file'; - } + if (Str::endsWith($modelType, '/files') === true) { + $modelName = 'file'; + } - $kirby = App::instance(); + $kirby = App::instance(); - switch ($modelName) { - case 'site': - $model = $kirby->site(); - break; - case 'account': - $model = static::user(); - break; - case 'page': - $model = static::page(basename($path)); - break; - case 'file': - $model = static::file(...explode('/files/', $path)); - break; - case 'user': - $model = $kirby->user(basename($path)); - break; - default: - throw new InvalidArgumentException('Invalid model type: ' . $modelType); - } + switch ($modelName) { + case 'site': + $model = $kirby->site(); + break; + case 'account': + $model = static::user(); + break; + case 'page': + $model = static::page(basename($path)); + break; + case 'file': + $model = static::file(...explode('/files/', $path)); + break; + case 'user': + $model = $kirby->user(basename($path)); + break; + default: + throw new InvalidArgumentException('Invalid model type: ' . $modelType); + } - if ($model) { - return $model; - } + if ($model) { + return $model; + } - throw new NotFoundException([ - 'key' => $modelName . '.undefined' - ]); - } + throw new NotFoundException([ + 'key' => $modelName . '.undefined' + ]); + } - /** - * Returns the user object for the given id or - * returns the current authenticated user if no - * id is passed - * - * @param string|null $id User's id - * @return \Kirby\Cms\User|null - * @throws \Kirby\Exception\NotFoundException if the user for the given id cannot be found - */ - public static function user(string $id = null) - { - // account is a reserved word to find the current - // user. It's used in various API and area routes. - if ($id === 'account') { - $id = null; - } + /** + * Returns the user object for the given id or + * returns the current authenticated user if no + * id is passed + * + * @param string|null $id User's id + * @return \Kirby\Cms\User|null + * @throws \Kirby\Exception\NotFoundException if the user for the given id cannot be found + */ + public static function user(string $id = null) + { + // account is a reserved word to find the current + // user. It's used in various API and area routes. + if ($id === 'account') { + $id = null; + } - $kirby = App::instance(); + $kirby = App::instance(); - // get the authenticated user - if ($id === null) { - if ($user = $kirby->user(null, $kirby->option('api.allowImpersonation', false))) { - return $user; - } + // get the authenticated user + if ($id === null) { + if ($user = $kirby->user(null, $kirby->option('api.allowImpersonation', false))) { + return $user; + } - throw new NotFoundException([ - 'key' => 'user.undefined' - ]); - } + throw new NotFoundException([ + 'key' => 'user.undefined' + ]); + } - // get a specific user by id - if ($user = $kirby->user($id)) { - return $user; - } + // get a specific user by id + if ($user = $kirby->user($id)) { + return $user; + } - throw new NotFoundException([ - 'key' => 'user.notFound', - 'data' => [ - 'name' => $id - ] - ]); - } + throw new NotFoundException([ + 'key' => 'user.notFound', + 'data' => [ + 'name' => $id + ] + ]); + } } diff --git a/kirby/src/Cms/HasChildren.php b/kirby/src/Cms/HasChildren.php index bb5be29..a13a46b 100755 --- a/kirby/src/Cms/HasChildren.php +++ b/kirby/src/Cms/HasChildren.php @@ -16,227 +16,227 @@ use Kirby\Toolkit\Str; */ trait HasChildren { - /** - * The list of available published children - * - * @var \Kirby\Cms\Pages - */ - public $children; + /** + * The list of available published children + * + * @var \Kirby\Cms\Pages + */ + public $children; - /** - * The list of available draft children - * - * @var \Kirby\Cms\Pages - */ - public $drafts; + /** + * The list of available draft children + * + * @var \Kirby\Cms\Pages + */ + public $drafts; - /** - * Returns all published children - * - * @return \Kirby\Cms\Pages - */ - public function children() - { - if (is_a($this->children, 'Kirby\Cms\Pages') === true) { - return $this->children; - } + /** + * Returns all published children + * + * @return \Kirby\Cms\Pages + */ + public function children() + { + if (is_a($this->children, 'Kirby\Cms\Pages') === true) { + return $this->children; + } - return $this->children = Pages::factory($this->inventory()['children'], $this); - } + return $this->children = Pages::factory($this->inventory()['children'], $this); + } - /** - * Returns all published and draft children at the same time - * - * @return \Kirby\Cms\Pages - */ - public function childrenAndDrafts() - { - return $this->children()->merge($this->drafts()); - } + /** + * Returns all published and draft children at the same time + * + * @return \Kirby\Cms\Pages + */ + public function childrenAndDrafts() + { + return $this->children()->merge($this->drafts()); + } - /** - * Returns a list of IDs for the model's - * `toArray` method - * - * @return array - */ - protected function convertChildrenToArray(): array - { - return $this->children()->keys(); - } + /** + * Returns a list of IDs for the model's + * `toArray` method + * + * @return array + */ + protected function convertChildrenToArray(): array + { + return $this->children()->keys(); + } - /** - * Searches for a draft child by ID - * - * @param string $path - * @return \Kirby\Cms\Page|null - */ - public function draft(string $path) - { - $path = str_replace('_drafts/', '', $path); + /** + * Searches for a draft child by ID + * + * @param string $path + * @return \Kirby\Cms\Page|null + */ + public function draft(string $path) + { + $path = str_replace('_drafts/', '', $path); - if (Str::contains($path, '/') === false) { - return $this->drafts()->find($path); - } + if (Str::contains($path, '/') === false) { + return $this->drafts()->find($path); + } - $parts = explode('/', $path); - $parent = $this; + $parts = explode('/', $path); + $parent = $this; - foreach ($parts as $slug) { - if ($page = $parent->find($slug)) { - $parent = $page; - continue; - } + foreach ($parts as $slug) { + if ($page = $parent->find($slug)) { + $parent = $page; + continue; + } - if ($draft = $parent->drafts()->find($slug)) { - $parent = $draft; - continue; - } + if ($draft = $parent->drafts()->find($slug)) { + $parent = $draft; + continue; + } - return null; - } + return null; + } - return $parent; - } + return $parent; + } - /** - * Returns all draft children - * - * @return \Kirby\Cms\Pages - */ - public function drafts() - { - if (is_a($this->drafts, 'Kirby\Cms\Pages') === true) { - return $this->drafts; - } + /** + * Returns all draft children + * + * @return \Kirby\Cms\Pages + */ + public function drafts() + { + if (is_a($this->drafts, 'Kirby\Cms\Pages') === true) { + return $this->drafts; + } - $kirby = $this->kirby(); + $kirby = $this->kirby(); - // create the inventory for all drafts - $inventory = Dir::inventory( - $this->root() . '/_drafts', - $kirby->contentExtension(), - $kirby->contentIgnore(), - $kirby->multilang() - ); + // create the inventory for all drafts + $inventory = Dir::inventory( + $this->root() . '/_drafts', + $kirby->contentExtension(), + $kirby->contentIgnore(), + $kirby->multilang() + ); - return $this->drafts = Pages::factory($inventory['children'], $this, true); - } + return $this->drafts = Pages::factory($inventory['children'], $this, true); + } - /** - * Finds one or multiple published children by ID - * - * @param string ...$arguments - * @return \Kirby\Cms\Page|\Kirby\Cms\Pages|null - */ - public function find(...$arguments) - { - return $this->children()->find(...$arguments); - } + /** + * Finds one or multiple published children by ID + * + * @param string ...$arguments + * @return \Kirby\Cms\Page|\Kirby\Cms\Pages|null + */ + public function find(...$arguments) + { + return $this->children()->find(...$arguments); + } - /** - * Finds a single published or draft child - * - * @param string $path - * @return \Kirby\Cms\Page|null - */ - public function findPageOrDraft(string $path) - { - return $this->children()->find($path) ?? $this->drafts()->find($path); - } + /** + * Finds a single published or draft child + * + * @param string $path + * @return \Kirby\Cms\Page|null + */ + public function findPageOrDraft(string $path) + { + return $this->children()->find($path) ?? $this->drafts()->find($path); + } - /** - * Returns a collection of all published children of published children - * - * @return \Kirby\Cms\Pages - */ - public function grandChildren() - { - return $this->children()->children(); - } + /** + * Returns a collection of all published children of published children + * + * @return \Kirby\Cms\Pages + */ + public function grandChildren() + { + return $this->children()->children(); + } - /** - * Checks if the model has any published children - * - * @return bool - */ - public function hasChildren(): bool - { - return $this->children()->count() > 0; - } + /** + * Checks if the model has any published children + * + * @return bool + */ + public function hasChildren(): bool + { + return $this->children()->count() > 0; + } - /** - * Checks if the model has any draft children - * - * @return bool - */ - public function hasDrafts(): bool - { - return $this->drafts()->count() > 0; - } + /** + * Checks if the model has any draft children + * + * @return bool + */ + public function hasDrafts(): bool + { + return $this->drafts()->count() > 0; + } - /** - * Checks if the page has any listed children - * - * @return bool - */ - public function hasListedChildren(): bool - { - return $this->children()->listed()->count() > 0; - } + /** + * Checks if the page has any listed children + * + * @return bool + */ + public function hasListedChildren(): bool + { + return $this->children()->listed()->count() > 0; + } - /** - * Checks if the page has any unlisted children - * - * @return bool - */ - public function hasUnlistedChildren(): bool - { - return $this->children()->unlisted()->count() > 0; - } + /** + * Checks if the page has any unlisted children + * + * @return bool + */ + public function hasUnlistedChildren(): bool + { + return $this->children()->unlisted()->count() > 0; + } - /** - * Creates a flat child index - * - * @param bool $drafts If set to `true`, draft children are included - * @return \Kirby\Cms\Pages - */ - public function index(bool $drafts = false) - { - if ($drafts === true) { - return $this->childrenAndDrafts()->index($drafts); - } else { - return $this->children()->index(); - } - } + /** + * Creates a flat child index + * + * @param bool $drafts If set to `true`, draft children are included + * @return \Kirby\Cms\Pages + */ + public function index(bool $drafts = false) + { + if ($drafts === true) { + return $this->childrenAndDrafts()->index($drafts); + } else { + return $this->children()->index(); + } + } - /** - * Sets the published children collection - * - * @param array|null $children - * @return $this - */ - protected function setChildren(array $children = null) - { - if ($children !== null) { - $this->children = Pages::factory($children, $this); - } + /** + * Sets the published children collection + * + * @param array|null $children + * @return $this + */ + protected function setChildren(array $children = null) + { + if ($children !== null) { + $this->children = Pages::factory($children, $this); + } - return $this; - } + return $this; + } - /** - * Sets the draft children collection - * - * @param array|null $drafts - * @return $this - */ - protected function setDrafts(array $drafts = null) - { - if ($drafts !== null) { - $this->drafts = Pages::factory($drafts, $this, true); - } + /** + * Sets the draft children collection + * + * @param array|null $drafts + * @return $this + */ + protected function setDrafts(array $drafts = null) + { + if ($drafts !== null) { + $this->drafts = Pages::factory($drafts, $this, true); + } - return $this; - } + return $this; + } } diff --git a/kirby/src/Cms/HasFiles.php b/kirby/src/Cms/HasFiles.php index 54dd797..cb4102d 100755 --- a/kirby/src/Cms/HasFiles.php +++ b/kirby/src/Cms/HasFiles.php @@ -13,214 +13,214 @@ namespace Kirby\Cms; */ trait HasFiles { - /** - * The Files collection - * - * @var \Kirby\Cms\Files - */ - protected $files; + /** + * The Files collection + * + * @var \Kirby\Cms\Files + */ + protected $files; - /** - * Filters the Files collection by type audio - * - * @return \Kirby\Cms\Files - */ - public function audio() - { - return $this->files()->filter('type', '==', 'audio'); - } + /** + * Filters the Files collection by type audio + * + * @return \Kirby\Cms\Files + */ + public function audio() + { + return $this->files()->filter('type', '==', 'audio'); + } - /** - * Filters the Files collection by type code - * - * @return \Kirby\Cms\Files - */ - public function code() - { - return $this->files()->filter('type', '==', 'code'); - } + /** + * Filters the Files collection by type code + * + * @return \Kirby\Cms\Files + */ + public function code() + { + return $this->files()->filter('type', '==', 'code'); + } - /** - * Returns a list of file ids - * for the toArray method of the model - * - * @return array - */ - protected function convertFilesToArray(): array - { - return $this->files()->keys(); - } + /** + * Returns a list of file ids + * for the toArray method of the model + * + * @return array + */ + protected function convertFilesToArray(): array + { + return $this->files()->keys(); + } - /** - * Creates a new file - * - * @param array $props - * @return \Kirby\Cms\File - */ - public function createFile(array $props) - { - $props = array_merge($props, [ - 'parent' => $this, - 'url' => null - ]); + /** + * Creates a new file + * + * @param array $props + * @return \Kirby\Cms\File + */ + public function createFile(array $props) + { + $props = array_merge($props, [ + 'parent' => $this, + 'url' => null + ]); - return File::create($props); - } + return File::create($props); + } - /** - * Filters the Files collection by type documents - * - * @return \Kirby\Cms\Files - */ - public function documents() - { - return $this->files()->filter('type', '==', 'document'); - } + /** + * Filters the Files collection by type documents + * + * @return \Kirby\Cms\Files + */ + public function documents() + { + return $this->files()->filter('type', '==', 'document'); + } - /** - * Returns a specific file by filename or the first one - * - * @param string|null $filename - * @param string $in - * @return \Kirby\Cms\File|null - */ - public function file(string $filename = null, string $in = 'files') - { - if ($filename === null) { - return $this->$in()->first(); - } + /** + * Returns a specific file by filename or the first one + * + * @param string|null $filename + * @param string $in + * @return \Kirby\Cms\File|null + */ + public function file(string $filename = null, string $in = 'files') + { + if ($filename === null) { + return $this->$in()->first(); + } - if (strpos($filename, '/') !== false) { - $path = dirname($filename); - $filename = basename($filename); + if (strpos($filename, '/') !== false) { + $path = dirname($filename); + $filename = basename($filename); - if ($page = $this->find($path)) { - return $page->$in()->find($filename); - } + if ($page = $this->find($path)) { + return $page->$in()->find($filename); + } - return null; - } + return null; + } - return $this->$in()->find($filename); - } + return $this->$in()->find($filename); + } - /** - * Returns the Files collection - * - * @return \Kirby\Cms\Files - */ - public function files() - { - if (is_a($this->files, 'Kirby\Cms\Files') === true) { - return $this->files; - } + /** + * Returns the Files collection + * + * @return \Kirby\Cms\Files + */ + public function files() + { + if (is_a($this->files, 'Kirby\Cms\Files') === true) { + return $this->files; + } - return $this->files = Files::factory($this->inventory()['files'], $this); - } + return $this->files = Files::factory($this->inventory()['files'], $this); + } - /** - * Checks if the Files collection has any audio files - * - * @return bool - */ - public function hasAudio(): bool - { - return $this->audio()->count() > 0; - } + /** + * Checks if the Files collection has any audio files + * + * @return bool + */ + public function hasAudio(): bool + { + return $this->audio()->count() > 0; + } - /** - * Checks if the Files collection has any code files - * - * @return bool - */ - public function hasCode(): bool - { - return $this->code()->count() > 0; - } + /** + * Checks if the Files collection has any code files + * + * @return bool + */ + public function hasCode(): bool + { + return $this->code()->count() > 0; + } - /** - * Checks if the Files collection has any document files - * - * @return bool - */ - public function hasDocuments(): bool - { - return $this->documents()->count() > 0; - } + /** + * Checks if the Files collection has any document files + * + * @return bool + */ + public function hasDocuments(): bool + { + return $this->documents()->count() > 0; + } - /** - * Checks if the Files collection has any files - * - * @return bool - */ - public function hasFiles(): bool - { - return $this->files()->count() > 0; - } + /** + * Checks if the Files collection has any files + * + * @return bool + */ + public function hasFiles(): bool + { + return $this->files()->count() > 0; + } - /** - * Checks if the Files collection has any images - * - * @return bool - */ - public function hasImages(): bool - { - return $this->images()->count() > 0; - } + /** + * Checks if the Files collection has any images + * + * @return bool + */ + public function hasImages(): bool + { + return $this->images()->count() > 0; + } - /** - * Checks if the Files collection has any videos - * - * @return bool - */ - public function hasVideos(): bool - { - return $this->videos()->count() > 0; - } + /** + * Checks if the Files collection has any videos + * + * @return bool + */ + public function hasVideos(): bool + { + return $this->videos()->count() > 0; + } - /** - * Returns a specific image by filename or the first one - * - * @param string|null $filename - * @return \Kirby\Cms\File|null - */ - public function image(string $filename = null) - { - return $this->file($filename, 'images'); - } + /** + * Returns a specific image by filename or the first one + * + * @param string|null $filename + * @return \Kirby\Cms\File|null + */ + public function image(string $filename = null) + { + return $this->file($filename, 'images'); + } - /** - * Filters the Files collection by type image - * - * @return \Kirby\Cms\Files - */ - public function images() - { - return $this->files()->filter('type', '==', 'image'); - } + /** + * Filters the Files collection by type image + * + * @return \Kirby\Cms\Files + */ + public function images() + { + return $this->files()->filter('type', '==', 'image'); + } - /** - * Sets the Files collection - * - * @param \Kirby\Cms\Files|null $files - * @return $this - */ - protected function setFiles(array $files = null) - { - if ($files !== null) { - $this->files = Files::factory($files, $this); - } + /** + * Sets the Files collection + * + * @param \Kirby\Cms\Files|null $files + * @return $this + */ + protected function setFiles(array $files = null) + { + if ($files !== null) { + $this->files = Files::factory($files, $this); + } - return $this; - } + return $this; + } - /** - * Filters the Files collection by type videos - * - * @return \Kirby\Cms\Files - */ - public function videos() - { - return $this->files()->filter('type', '==', 'video'); - } + /** + * Filters the Files collection by type videos + * + * @return \Kirby\Cms\Files + */ + public function videos() + { + return $this->files()->filter('type', '==', 'video'); + } } diff --git a/kirby/src/Cms/HasMethods.php b/kirby/src/Cms/HasMethods.php index 36a19ae..053eb8b 100755 --- a/kirby/src/Cms/HasMethods.php +++ b/kirby/src/Cms/HasMethods.php @@ -15,66 +15,66 @@ use Kirby\Exception\BadMethodCallException; */ trait HasMethods { - /** - * All registered methods - * - * @var array - */ - public static $methods = []; + /** + * All registered methods + * + * @var array + */ + public static $methods = []; - /** - * Calls a registered method class with the - * passed arguments - * - * @internal - * @param string $method - * @param array $args - * @return mixed - * @throws \Kirby\Exception\BadMethodCallException - */ - public function callMethod(string $method, array $args = []) - { - $closure = $this->getMethod($method); + /** + * Calls a registered method class with the + * passed arguments + * + * @internal + * @param string $method + * @param array $args + * @return mixed + * @throws \Kirby\Exception\BadMethodCallException + */ + public function callMethod(string $method, array $args = []) + { + $closure = $this->getMethod($method); - if ($closure === null) { - throw new BadMethodCallException('The method ' . $method . ' does not exist'); - } + if ($closure === null) { + throw new BadMethodCallException('The method ' . $method . ' does not exist'); + } - return $closure->call($this, ...$args); - } + return $closure->call($this, ...$args); + } - /** - * Checks if the object has a registered method - * - * @internal - * @param string $method - * @return bool - */ - public function hasMethod(string $method): bool - { - return $this->getMethod($method) !== null; - } + /** + * Checks if the object has a registered method + * + * @internal + * @param string $method + * @return bool + */ + public function hasMethod(string $method): bool + { + return $this->getMethod($method) !== null; + } - /** - * Returns a registered method by name, either from - * the current class or from a parent class ordered by - * inheritance order (top to bottom) - * - * @param string $method - * @return \Closure|null - */ - protected function getMethod(string $method) - { - if (isset(static::$methods[$method]) === true) { - return static::$methods[$method]; - } + /** + * Returns a registered method by name, either from + * the current class or from a parent class ordered by + * inheritance order (top to bottom) + * + * @param string $method + * @return \Closure|null + */ + protected function getMethod(string $method) + { + if (isset(static::$methods[$method]) === true) { + return static::$methods[$method]; + } - foreach (class_parents($this) as $parent) { - if (isset($parent::$methods[$method]) === true) { - return $parent::$methods[$method]; - } - } + foreach (class_parents($this) as $parent) { + if (isset($parent::$methods[$method]) === true) { + return $parent::$methods[$method]; + } + } - return null; - } + return null; + } } diff --git a/kirby/src/Cms/HasSiblings.php b/kirby/src/Cms/HasSiblings.php index b4f1846..ad6fa7d 100755 --- a/kirby/src/Cms/HasSiblings.php +++ b/kirby/src/Cms/HasSiblings.php @@ -14,169 +14,169 @@ namespace Kirby\Cms; */ trait HasSiblings { - /** - * Returns the position / index in the collection - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return int - */ - public function indexOf($collection = null): int - { - if ($collection === null) { - $collection = $this->siblingsCollection(); - } + /** + * Returns the position / index in the collection + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return int + */ + public function indexOf($collection = null): int + { + if ($collection === null) { + $collection = $this->siblingsCollection(); + } - return $collection->indexOf($this); - } + return $collection->indexOf($this); + } - /** - * Returns the next item in the collection if available - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return \Kirby\Cms\Model|null - */ - public function next($collection = null) - { - if ($collection === null) { - $collection = $this->siblingsCollection(); - } + /** + * Returns the next item in the collection if available + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return \Kirby\Cms\Model|null + */ + public function next($collection = null) + { + if ($collection === null) { + $collection = $this->siblingsCollection(); + } - return $collection->nth($this->indexOf($collection) + 1); - } + return $collection->nth($this->indexOf($collection) + 1); + } - /** - * Returns the end of the collection starting after the current item - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return \Kirby\Cms\Collection - */ - public function nextAll($collection = null) - { - if ($collection === null) { - $collection = $this->siblingsCollection(); - } + /** + * Returns the end of the collection starting after the current item + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return \Kirby\Cms\Collection + */ + public function nextAll($collection = null) + { + if ($collection === null) { + $collection = $this->siblingsCollection(); + } - return $collection->slice($this->indexOf($collection) + 1); - } + return $collection->slice($this->indexOf($collection) + 1); + } - /** - * Returns the previous item in the collection if available - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return \Kirby\Cms\Model|null - */ - public function prev($collection = null) - { - if ($collection === null) { - $collection = $this->siblingsCollection(); - } + /** + * Returns the previous item in the collection if available + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return \Kirby\Cms\Model|null + */ + public function prev($collection = null) + { + if ($collection === null) { + $collection = $this->siblingsCollection(); + } - return $collection->nth($this->indexOf($collection) - 1); - } + return $collection->nth($this->indexOf($collection) - 1); + } - /** - * Returns the beginning of the collection before the current item - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return \Kirby\Cms\Collection - */ - public function prevAll($collection = null) - { - if ($collection === null) { - $collection = $this->siblingsCollection(); - } + /** + * Returns the beginning of the collection before the current item + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return \Kirby\Cms\Collection + */ + public function prevAll($collection = null) + { + if ($collection === null) { + $collection = $this->siblingsCollection(); + } - return $collection->slice(0, $this->indexOf($collection)); - } + return $collection->slice(0, $this->indexOf($collection)); + } - /** - * Returns all sibling elements - * - * @param bool $self - * @return \Kirby\Cms\Collection - */ - public function siblings(bool $self = true) - { - $siblings = $this->siblingsCollection(); + /** + * Returns all sibling elements + * + * @param bool $self + * @return \Kirby\Cms\Collection + */ + public function siblings(bool $self = true) + { + $siblings = $this->siblingsCollection(); - if ($self === false) { - return $siblings->not($this); - } + if ($self === false) { + return $siblings->not($this); + } - return $siblings; - } + return $siblings; + } - /** - * Checks if there's a next item in the collection - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return bool - */ - public function hasNext($collection = null): bool - { - return $this->next($collection) !== null; - } + /** + * Checks if there's a next item in the collection + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return bool + */ + public function hasNext($collection = null): bool + { + return $this->next($collection) !== null; + } - /** - * Checks if there's a previous item in the collection - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return bool - */ - public function hasPrev($collection = null): bool - { - return $this->prev($collection) !== null; - } + /** + * Checks if there's a previous item in the collection + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return bool + */ + public function hasPrev($collection = null): bool + { + return $this->prev($collection) !== null; + } - /** - * Checks if the item is the first in the collection - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return bool - */ - public function isFirst($collection = null): bool - { - if ($collection === null) { - $collection = $this->siblingsCollection(); - } + /** + * Checks if the item is the first in the collection + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return bool + */ + public function isFirst($collection = null): bool + { + if ($collection === null) { + $collection = $this->siblingsCollection(); + } - return $collection->first()->is($this); - } + return $collection->first()->is($this); + } - /** - * Checks if the item is the last in the collection - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return bool - */ - public function isLast($collection = null): bool - { - if ($collection === null) { - $collection = $this->siblingsCollection(); - } + /** + * Checks if the item is the last in the collection + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return bool + */ + public function isLast($collection = null): bool + { + if ($collection === null) { + $collection = $this->siblingsCollection(); + } - return $collection->last()->is($this); - } + return $collection->last()->is($this); + } - /** - * Checks if the item is at a certain position - * - * @param \Kirby\Cms\Collection|null $collection - * @param int $n - * - * @return bool - */ - public function isNth(int $n, $collection = null): bool - { - return $this->indexOf($collection) === $n; - } + /** + * Checks if the item is at a certain position + * + * @param \Kirby\Cms\Collection|null $collection + * @param int $n + * + * @return bool + */ + public function isNth(int $n, $collection = null): bool + { + return $this->indexOf($collection) === $n; + } } diff --git a/kirby/src/Cms/Helpers.php b/kirby/src/Cms/Helpers.php index 38caf16..c893b30 100755 --- a/kirby/src/Cms/Helpers.php +++ b/kirby/src/Cms/Helpers.php @@ -17,71 +17,71 @@ use Kirby\Toolkit\Str; */ class Helpers { - /** - * Triggers a deprecation warning if debug mode is active - * - * @param string $message - * @return bool Whether the warning was triggered - */ - public static function deprecated(string $message): bool - { - if (App::instance()->option('debug') === true) { - return trigger_error($message, E_USER_DEPRECATED) === true; - } + /** + * Triggers a deprecation warning if debug mode is active + * + * @param string $message + * @return bool Whether the warning was triggered + */ + public static function deprecated(string $message): bool + { + if (App::instance()->option('debug') === true) { + return trigger_error($message, E_USER_DEPRECATED) === true; + } - return false; - } + return false; + } - /** - * Simple object and variable dumper - * to help with debugging. - * - * @param mixed $variable - * @param bool $echo - * @return string - */ - public static function dump($variable, bool $echo = true): string - { - $kirby = App::instance(); - return ($kirby->component('dump'))($kirby, $variable, $echo); - } + /** + * Simple object and variable dumper + * to help with debugging. + * + * @param mixed $variable + * @param bool $echo + * @return string + */ + public static function dump($variable, bool $echo = true): string + { + $kirby = App::instance(); + return ($kirby->component('dump'))($kirby, $variable, $echo); + } - /** - * Checks if a helper was overridden by the user - * by setting the `KIRBY_HELPER_*` constant - * @internal - * - * @param string $name Name of the helper - * @return bool - */ - public static function hasOverride(string $name): bool - { - $name = 'KIRBY_HELPER_' . strtoupper($name); - return defined($name) === true && constant($name) === false; - } + /** + * Checks if a helper was overridden by the user + * by setting the `KIRBY_HELPER_*` constant + * @internal + * + * @param string $name Name of the helper + * @return bool + */ + public static function hasOverride(string $name): bool + { + $name = 'KIRBY_HELPER_' . strtoupper($name); + return defined($name) === true && constant($name) === false; + } - /** - * Determines the size/length of numbers, - * strings, arrays and countable objects - * - * @param mixed $value - * @return int - * @throws \Kirby\Exception\InvalidArgumentException - */ - public static function size($value): int - { - if (is_numeric($value)) { - return (int)$value; - } + /** + * Determines the size/length of numbers, + * strings, arrays and countable objects + * + * @param mixed $value + * @return int + * @throws \Kirby\Exception\InvalidArgumentException + */ + public static function size($value): int + { + if (is_numeric($value)) { + return (int)$value; + } - if (is_string($value)) { - return Str::length(trim($value)); - } + if (is_string($value)) { + return Str::length(trim($value)); + } - if (is_countable($value)) { - return count($value); - } + if (is_countable($value)) { + return count($value); + } - throw new InvalidArgumentException('Could not determine the size of the given value'); - } + throw new InvalidArgumentException('Could not determine the size of the given value'); + } } diff --git a/kirby/src/Cms/Html.php b/kirby/src/Cms/Html.php index 5b1f881..1af6087 100755 --- a/kirby/src/Cms/Html.php +++ b/kirby/src/Cms/Html.php @@ -18,132 +18,132 @@ use Kirby\Toolkit\A; */ class Html extends \Kirby\Toolkit\Html { - /** - * Creates one or multiple CSS link tags - * @since 3.7.0 - * - * @param string|array $url Relative or absolute URLs, an array of URLs or `@auto` for automatic template css loading - * @param string|array $options Pass an array of attributes for the link tag or a media attribute string - * @return string|null - */ - public static function css($url, $options = null): ?string - { - if (is_array($url) === true) { - $links = A::map($url, fn ($url) => static::css($url, $options)); - return implode(PHP_EOL, $links); - } + /** + * Creates one or multiple CSS link tags + * @since 3.7.0 + * + * @param string|array $url Relative or absolute URLs, an array of URLs or `@auto` for automatic template css loading + * @param string|array $options Pass an array of attributes for the link tag or a media attribute string + * @return string|null + */ + public static function css($url, $options = null): ?string + { + if (is_array($url) === true) { + $links = A::map($url, fn ($url) => static::css($url, $options)); + return implode(PHP_EOL, $links); + } - if (is_string($options) === true) { - $options = ['media' => $options]; - } + if (is_string($options) === true) { + $options = ['media' => $options]; + } - $kirby = App::instance(); + $kirby = App::instance(); - if ($url === '@auto') { - if (!$url = Url::toTemplateAsset('css/templates', 'css')) { - return null; - } - } + if ($url === '@auto') { + if (!$url = Url::toTemplateAsset('css/templates', 'css')) { + return null; + } + } - // only valid value for 'rel' is 'alternate stylesheet', if 'title' is given as well - if ( - ($options['rel'] ?? '') !== 'alternate stylesheet' || - ($options['title'] ?? '') === '' - ) { - $options['rel'] = 'stylesheet'; - } + // only valid value for 'rel' is 'alternate stylesheet', if 'title' is given as well + if ( + ($options['rel'] ?? '') !== 'alternate stylesheet' || + ($options['title'] ?? '') === '' + ) { + $options['rel'] = 'stylesheet'; + } - $url = ($kirby->component('css'))($kirby, $url, $options); - $url = Url::to($url); - $attr = array_merge((array)$options, [ - 'href' => $url - ]); + $url = ($kirby->component('css'))($kirby, $url, $options); + $url = Url::to($url); + $attr = array_merge((array)$options, [ + 'href' => $url + ]); - return ''; - } + return ''; + } - /** - * Generates an `a` tag with an absolute Url - * - * @param string|null $href Relative or absolute Url - * @param string|array|null $text If `null`, the link will be used as link text. If an array is passed, each element will be added unencoded - * @param array $attr Additional attributes for the a tag. - * @return string - */ - public static function link(string $href = null, $text = null, array $attr = []): string - { - return parent::link(Url::to($href), $text, $attr); - } + /** + * Generates an `a` tag with an absolute Url + * + * @param string|null $href Relative or absolute Url + * @param string|array|null $text If `null`, the link will be used as link text. If an array is passed, each element will be added unencoded + * @param array $attr Additional attributes for the a tag. + * @return string + */ + public static function link(string $href = null, $text = null, array $attr = []): string + { + return parent::link(Url::to($href), $text, $attr); + } - /** - * Creates a script tag to load a javascript file - * @since 3.7.0 - * - * @param string|array $url - * @param string|array $options - * @return string|null - */ - public static function js($url, $options = null): ?string - { - if (is_array($url) === true) { - $scripts = A::map($url, fn ($url) => static::js($url, $options)); - return implode(PHP_EOL, $scripts); - } + /** + * Creates a script tag to load a javascript file + * @since 3.7.0 + * + * @param string|array $url + * @param string|array $options + * @return string|null + */ + public static function js($url, $options = null): ?string + { + if (is_array($url) === true) { + $scripts = A::map($url, fn ($url) => static::js($url, $options)); + return implode(PHP_EOL, $scripts); + } - if (is_bool($options) === true) { - $options = ['async' => $options]; - } + if (is_bool($options) === true) { + $options = ['async' => $options]; + } - $kirby = App::instance(); + $kirby = App::instance(); - if ($url === '@auto') { - if (!$url = Url::toTemplateAsset('js/templates', 'js')) { - return null; - } - } + if ($url === '@auto') { + if (!$url = Url::toTemplateAsset('js/templates', 'js')) { + return null; + } + } - $url = ($kirby->component('js'))($kirby, $url, $options); - $url = Url::to($url); - $attr = array_merge((array)$options, ['src' => $url]); + $url = ($kirby->component('js'))($kirby, $url, $options); + $url = Url::to($url); + $attr = array_merge((array)$options, ['src' => $url]); - return ''; - } + return ''; + } - /** - * Includes an SVG file by absolute or - * relative file path. - * @since 3.7.0 - * - * @param string|\Kirby\Cms\File $file - * @return string|false - */ - public static function svg($file) - { - // support for Kirby's file objects - if ( - is_a($file, 'Kirby\Cms\File') === true && - $file->extension() === 'svg' - ) { - return $file->read(); - } + /** + * Includes an SVG file by absolute or + * relative file path. + * @since 3.7.0 + * + * @param string|\Kirby\Cms\File $file + * @return string|false + */ + public static function svg($file) + { + // support for Kirby's file objects + if ( + is_a($file, 'Kirby\Cms\File') === true && + $file->extension() === 'svg' + ) { + return $file->read(); + } - if (is_string($file) === false) { - return false; - } + if (is_string($file) === false) { + return false; + } - $extension = F::extension($file); + $extension = F::extension($file); - // check for valid svg files - if ($extension !== 'svg') { - return false; - } + // check for valid svg files + if ($extension !== 'svg') { + return false; + } - // try to convert relative paths to absolute - if (file_exists($file) === false) { - $root = App::instance()->root(); - $file = realpath($root . '/' . $file); - } + // try to convert relative paths to absolute + if (file_exists($file) === false) { + $root = App::instance()->root(); + $file = realpath($root . '/' . $file); + } - return F::read($file); - } + return F::read($file); + } } diff --git a/kirby/src/Cms/Ingredients.php b/kirby/src/Cms/Ingredients.php index f0dcc44..42442b3 100755 --- a/kirby/src/Cms/Ingredients.php +++ b/kirby/src/Cms/Ingredients.php @@ -16,80 +16,80 @@ namespace Kirby\Cms; */ class Ingredients { - /** - * @var array - */ - protected $ingredients = []; + /** + * @var array + */ + protected $ingredients = []; - /** - * Creates a new ingredient collection - * - * @param array $ingredients - */ - public function __construct(array $ingredients) - { - $this->ingredients = $ingredients; - } + /** + * Creates a new ingredient collection + * + * @param array $ingredients + */ + public function __construct(array $ingredients) + { + $this->ingredients = $ingredients; + } - /** - * Magic getter for single ingredients - * - * @param string $method - * @param array|null $args - * @return mixed - */ - public function __call(string $method, array $args = null) - { - return $this->ingredients[$method] ?? null; - } + /** + * Magic getter for single ingredients + * + * @param string $method + * @param array|null $args + * @return mixed + */ + public function __call(string $method, array $args = null) + { + return $this->ingredients[$method] ?? null; + } - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return $this->ingredients; - } + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return $this->ingredients; + } - /** - * Get a single ingredient by key - * - * @param string $key - * @return mixed - */ - public function __get(string $key) - { - return $this->ingredients[$key] ?? null; - } + /** + * Get a single ingredient by key + * + * @param string $key + * @return mixed + */ + public function __get(string $key) + { + return $this->ingredients[$key] ?? null; + } - /** - * Resolves all ingredient callbacks - * and creates a plain array - * - * @internal - * @param array $ingredients - * @return static - */ - public static function bake(array $ingredients) - { - foreach ($ingredients as $name => $ingredient) { - if (is_a($ingredient, 'Closure') === true) { - $ingredients[$name] = $ingredient($ingredients); - } - } + /** + * Resolves all ingredient callbacks + * and creates a plain array + * + * @internal + * @param array $ingredients + * @return static + */ + public static function bake(array $ingredients) + { + foreach ($ingredients as $name => $ingredient) { + if (is_a($ingredient, 'Closure') === true) { + $ingredients[$name] = $ingredient($ingredients); + } + } - return new static($ingredients); - } + return new static($ingredients); + } - /** - * Returns all ingredients as plain array - * - * @return array - */ - public function toArray(): array - { - return $this->ingredients; - } + /** + * Returns all ingredients as plain array + * + * @return array + */ + public function toArray(): array + { + return $this->ingredients; + } } diff --git a/kirby/src/Cms/Item.php b/kirby/src/Cms/Item.php index ac0bb4a..2f6922e 100755 --- a/kirby/src/Cms/Item.php +++ b/kirby/src/Cms/Item.php @@ -22,118 +22,118 @@ use Kirby\Toolkit\Str; */ class Item { - use HasSiblings; + use HasSiblings; - public const ITEMS_CLASS = '\Kirby\Cms\Items'; + public const ITEMS_CLASS = '\Kirby\Cms\Items'; - /** - * @var string - */ - protected $id; + /** + * @var string + */ + protected $id; - /** - * @var array - */ - protected $params; + /** + * @var array + */ + protected $params; - /** - * @var \Kirby\Cms\Page|\Kirby\Cms\Site|\Kirby\Cms\File|\Kirby\Cms\User - */ - protected $parent; + /** + * @var \Kirby\Cms\Page|\Kirby\Cms\Site|\Kirby\Cms\File|\Kirby\Cms\User + */ + protected $parent; - /** - * @var \Kirby\Cms\Items - */ - protected $siblings; + /** + * @var \Kirby\Cms\Items + */ + protected $siblings; - /** - * Creates a new item - * - * @param array $params - */ - public function __construct(array $params = []) - { - $siblingsClass = static::ITEMS_CLASS; + /** + * Creates a new item + * + * @param array $params + */ + public function __construct(array $params = []) + { + $siblingsClass = static::ITEMS_CLASS; - $this->id = $params['id'] ?? Str::uuid(); - $this->params = $params; - $this->parent = $params['parent'] ?? App::instance()->site(); - $this->siblings = $params['siblings'] ?? new $siblingsClass(); - } + $this->id = $params['id'] ?? Str::uuid(); + $this->params = $params; + $this->parent = $params['parent'] ?? App::instance()->site(); + $this->siblings = $params['siblings'] ?? new $siblingsClass(); + } - /** - * Static Item factory - * - * @param array $params - * @return \Kirby\Cms\Item - */ - public static function factory(array $params) - { - return new static($params); - } + /** + * Static Item factory + * + * @param array $params + * @return \Kirby\Cms\Item + */ + public static function factory(array $params) + { + return new static($params); + } - /** - * Returns the unique item id (UUID v4) - * - * @return string - */ - public function id(): string - { - return $this->id; - } + /** + * Returns the unique item id (UUID v4) + * + * @return string + */ + public function id(): string + { + return $this->id; + } - /** - * Compares the item to another one - * - * @param \Kirby\Cms\Item $item - * @return bool - */ - public function is(Item $item): bool - { - return $this->id() === $item->id(); - } + /** + * Compares the item to another one + * + * @param \Kirby\Cms\Item $item + * @return bool + */ + public function is(Item $item): bool + { + return $this->id() === $item->id(); + } - /** - * Returns the Kirby instance - * - * @return \Kirby\Cms\App - */ - public function kirby() - { - return $this->parent()->kirby(); - } + /** + * Returns the Kirby instance + * + * @return \Kirby\Cms\App + */ + public function kirby() + { + return $this->parent()->kirby(); + } - /** - * Returns the parent model - * - * @return \Kirby\Cms\Page|\Kirby\Cms\Site|\Kirby\Cms\File|\Kirby\Cms\User - */ - public function parent() - { - return $this->parent; - } + /** + * Returns the parent model + * + * @return \Kirby\Cms\Page|\Kirby\Cms\Site|\Kirby\Cms\File|\Kirby\Cms\User + */ + public function parent() + { + return $this->parent; + } - /** - * Returns the sibling collection - * This is required by the HasSiblings trait - * - * @return \Kirby\Cms\Items - * @psalm-return self::ITEMS_CLASS - */ - protected function siblingsCollection() - { - return $this->siblings; - } + /** + * Returns the sibling collection + * This is required by the HasSiblings trait + * + * @return \Kirby\Cms\Items + * @psalm-return self::ITEMS_CLASS + */ + protected function siblingsCollection() + { + return $this->siblings; + } - /** - * Converts the item to an array - * - * @return array - */ - public function toArray(): array - { - return [ - 'id' => $this->id(), - ]; - } + /** + * Converts the item to an array + * + * @return array + */ + public function toArray(): array + { + return [ + 'id' => $this->id(), + ]; + } } diff --git a/kirby/src/Cms/Items.php b/kirby/src/Cms/Items.php index c5783e4..6bbecb5 100755 --- a/kirby/src/Cms/Items.php +++ b/kirby/src/Cms/Items.php @@ -17,81 +17,81 @@ use Exception; */ class Items extends Collection { - public const ITEM_CLASS = '\Kirby\Cms\Item'; + public const ITEM_CLASS = '\Kirby\Cms\Item'; - /** - * @var array - */ - protected $options; + /** + * @var array + */ + protected $options; - /** - * @var \Kirby\Cms\ModelWithContent - */ - protected $parent; + /** + * @var \Kirby\Cms\ModelWithContent + */ + protected $parent; - /** - * Constructor - * - * @param array $objects - * @param array $options - */ - public function __construct($objects = [], array $options = []) - { - $this->options = $options; - $this->parent = $options['parent'] ?? App::instance()->site(); + /** + * Constructor + * + * @param array $objects + * @param array $options + */ + public function __construct($objects = [], array $options = []) + { + $this->options = $options; + $this->parent = $options['parent'] ?? App::instance()->site(); - parent::__construct($objects, $this->parent); - } + parent::__construct($objects, $this->parent); + } - /** - * Creates a new item collection from a - * an array of item props - * - * @param array $items - * @param array $params - * @return \Kirby\Cms\Items - */ - public static function factory(array $items = null, array $params = []) - { - $options = array_merge([ - 'options' => [], - 'parent' => App::instance()->site(), - ], $params); + /** + * Creates a new item collection from a + * an array of item props + * + * @param array $items + * @param array $params + * @return \Kirby\Cms\Items + */ + public static function factory(array $items = null, array $params = []) + { + $options = array_merge([ + 'options' => [], + 'parent' => App::instance()->site(), + ], $params); - if (empty($items) === true || is_array($items) === false) { - return new static(); - } + if (empty($items) === true || is_array($items) === false) { + return new static(); + } - if (is_array($options) === false) { - throw new Exception('Invalid item options'); - } + if (is_array($options) === false) { + throw new Exception('Invalid item options'); + } - // create a new collection of blocks - $collection = new static([], $options); + // create a new collection of blocks + $collection = new static([], $options); - foreach ($items as $params) { - if (is_array($params) === false) { - continue; - } + foreach ($items as $params) { + if (is_array($params) === false) { + continue; + } - $params['options'] = $options['options']; - $params['parent'] = $options['parent']; - $params['siblings'] = $collection; - $class = static::ITEM_CLASS; - $item = $class::factory($params); - $collection->append($item->id(), $item); - } + $params['options'] = $options['options']; + $params['parent'] = $options['parent']; + $params['siblings'] = $collection; + $class = static::ITEM_CLASS; + $item = $class::factory($params); + $collection->append($item->id(), $item); + } - return $collection; - } + return $collection; + } - /** - * Convert the items to an array - * - * @return array - */ - public function toArray(Closure $map = null): array - { - return array_values(parent::toArray($map)); - } + /** + * Convert the items to an array + * + * @return array + */ + public function toArray(Closure $map = null): array + { + return array_values(parent::toArray($map)); + } } diff --git a/kirby/src/Cms/Language.php b/kirby/src/Cms/Language.php index f63420e..04fec9d 100755 --- a/kirby/src/Cms/Language.php +++ b/kirby/src/Cms/Language.php @@ -28,667 +28,667 @@ use Throwable; */ class Language extends Model { - /** - * @var string - */ - protected $code; - - /** - * @var bool - */ - protected $default; - - /** - * @var string - */ - protected $direction; - - /** - * @var array - */ - protected $locale; - - /** - * @var string - */ - protected $name; - - /** - * @var array|null - */ - protected $slugs; - - /** - * @var array|null - */ - protected $smartypants; - - /** - * @var array|null - */ - protected $translations; - - /** - * @var string - */ - protected $url; - - /** - * Creates a new language object - * - * @param array $props - */ - public function __construct(array $props) - { - $this->setRequiredProperties($props, [ - 'code' - ]); - - $this->setOptionalProperties($props, [ - 'default', - 'direction', - 'locale', - 'name', - 'slugs', - 'smartypants', - 'translations', - 'url', - ]); - } - - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return $this->toArray(); - } - - /** - * Returns the language code - * when the language is converted to a string - * - * @return string - */ - public function __toString(): string - { - return $this->code(); - } - - /** - * Returns the base Url for the language - * without the path or other cruft - * - * @return string - */ - public function baseUrl(): string - { - $kirbyUrl = $this->kirby()->url(); - $languageUrl = $this->url(); - - if (empty($this->url)) { - return $kirbyUrl; - } - - if (Str::startsWith($languageUrl, $kirbyUrl) === true) { - return $kirbyUrl; - } - - return Url::base($languageUrl) ?? $kirbyUrl; - } - - /** - * Returns the language code/id. - * The language code is used in - * text file names as appendix. - * - * @return string - */ - public function code(): string - { - return $this->code; - } - - /** - * Internal converter to create or remove - * translation files. - * - * @param string $from - * @param string $to - * @return bool - */ - protected static function converter(string $from, string $to): bool - { - $kirby = App::instance(); - $site = $kirby->site(); - - // convert site - foreach ($site->files() as $file) { - F::move($file->contentFile($from, true), $file->contentFile($to, true)); - } - - F::move($site->contentFile($from, true), $site->contentFile($to, true)); - - // convert all pages - foreach ($kirby->site()->index(true) as $page) { - foreach ($page->files() as $file) { - F::move($file->contentFile($from, true), $file->contentFile($to, true)); - } - - F::move($page->contentFile($from, true), $page->contentFile($to, true)); - } - - // convert all users - foreach ($kirby->users() as $user) { - foreach ($user->files() as $file) { - F::move($file->contentFile($from, true), $file->contentFile($to, true)); - } - - F::move($user->contentFile($from, true), $user->contentFile($to, true)); - } - - return true; - } - - /** - * Creates a new language object - * - * @internal - * @param array $props - * @return static - */ - public static function create(array $props) - { - $props['code'] = Str::slug($props['code'] ?? null); - $kirby = App::instance(); - $languages = $kirby->languages(); - - // make the first language the default language - if ($languages->count() === 0) { - $props['default'] = true; - } - - $language = new static($props); - - // validate the new language - LanguageRules::create($language); - - $language->save(); - - if ($languages->count() === 0) { - static::converter('', $language->code()); - } - - // update the main languages collection in the app instance - App::instance()->languages(false)->append($language->code(), $language); - - return $language; - } - - /** - * Delete the current language and - * all its translation files - * - * @internal - * @return bool - * @throws \Kirby\Exception\Exception - */ - public function delete(): bool - { - $kirby = App::instance(); - $languages = $kirby->languages(); - $code = $this->code(); - $isLast = $languages->count() === 1; - - if (F::remove($this->root()) !== true) { - throw new Exception('The language could not be deleted'); - } - - if ($isLast === true) { - $this->converter($code, ''); - } else { - $this->deleteContentFiles($code); - } - - // get the original language collection and remove the current language - $kirby->languages(false)->remove($code); - - return true; - } - - /** - * When the language is deleted, all content files with - * the language code must be removed as well. - * - * @param mixed $code - * @return bool - */ - protected function deleteContentFiles($code): bool - { - $kirby = App::instance(); - $site = $kirby->site(); - - F::remove($site->contentFile($code, true)); - - foreach ($kirby->site()->index(true) as $page) { - foreach ($page->files() as $file) { - F::remove($file->contentFile($code, true)); - } - - F::remove($page->contentFile($code, true)); - } - - foreach ($kirby->users() as $user) { - foreach ($user->files() as $file) { - F::remove($file->contentFile($code, true)); - } - - F::remove($user->contentFile($code, true)); - } - - return true; - } - - /** - * Reading direction of this language - * - * @return string - */ - public function direction(): string - { - return $this->direction; - } - - /** - * Check if the language file exists - * - * @return bool - */ - public function exists(): bool - { - return file_exists($this->root()); - } - - /** - * Checks if this is the default language - * for the site. - * - * @return bool - */ - public function isDefault(): bool - { - return $this->default; - } - - /** - * The id is required for collections - * to work properly. The code is used as id - * - * @return string - */ - public function id(): string - { - return $this->code; - } - - /** - * Loads the language rules for provided locale code - * - * @param string $code - */ - public static function loadRules(string $code) - { - $kirby = App::instance(); - $code = Str::contains($code, '.') ? Str::before($code, '.') : $code; - $file = $kirby->root('i18n:rules') . '/' . $code . '.json'; - - if (F::exists($file) === false) { - $file = $kirby->root('i18n:rules') . '/' . Str::before($code, '_') . '.json'; - } - - try { - return Data::read($file); - } catch (\Exception $e) { - return []; - } - } - - /** - * Returns the PHP locale setting array - * - * @param int $category If passed, returns the locale for the specified category (e.g. LC_ALL) as string - * @return array|string - */ - public function locale(int $category = null) - { - if ($category !== null) { - return $this->locale[$category] ?? $this->locale[LC_ALL] ?? null; - } else { - return $this->locale; - } - } - - /** - * Returns the human-readable name - * of the language - * - * @return string - */ - public function name(): string - { - return $this->name; - } - - /** - * Returns the URL path for the language - * - * @return string - */ - public function path(): string - { - if ($this->url === null) { - return $this->code; - } - - return Url::path($this->url); - } - - /** - * Returns the routing pattern for the language - * - * @return string - */ - public function pattern(): string - { - $path = $this->path(); - - if (empty($path) === true) { - return '(:all)'; - } - - return $path . '/(:all?)'; - } - - /** - * Returns the absolute path to the language file - * - * @return string - */ - public function root(): string - { - return App::instance()->root('languages') . '/' . $this->code() . '.php'; - } - - /** - * Returns the LanguageRouter instance - * which is used to handle language specific - * routes. - * - * @return \Kirby\Cms\LanguageRouter - */ - public function router() - { - return new LanguageRouter($this); - } - - /** - * Get slug rules for language - * - * @internal - * @return array - */ - public function rules(): array - { - $code = $this->locale(LC_CTYPE); - $data = static::loadRules($code); - return array_merge($data, $this->slugs()); - } - - /** - * Saves the language settings in the languages folder - * - * @internal - * @return $this - */ - public function save() - { - try { - $existingData = Data::read($this->root()); - } catch (Throwable $e) { - $existingData = []; - } - - $props = [ - 'code' => $this->code(), - 'default' => $this->isDefault(), - 'direction' => $this->direction(), - 'locale' => Locale::export($this->locale()), - 'name' => $this->name(), - 'translations' => $this->translations(), - 'url' => $this->url, - ]; - - $data = array_merge($existingData, $props); - - ksort($data); - - Data::write($this->root(), $data); - - return $this; - } - - /** - * @param string $code - * @return $this - */ - protected function setCode(string $code) - { - $this->code = trim($code); - return $this; - } - - /** - * @param bool $default - * @return $this - */ - protected function setDefault(bool $default = false) - { - $this->default = $default; - return $this; - } - - /** - * @param string $direction - * @return $this - */ - protected function setDirection(string $direction = 'ltr') - { - $this->direction = $direction === 'rtl' ? 'rtl' : 'ltr'; - return $this; - } - - /** - * @param string|array $locale - * @return $this - */ - protected function setLocale($locale = null) - { - if ($locale === null) { - $this->locale = [LC_ALL => $this->code]; - } else { - $this->locale = Locale::normalize($locale); - } - - return $this; - } - - /** - * @param string $name - * @return $this - */ - protected function setName(string $name = null) - { - $this->name = trim($name ?? $this->code); - return $this; - } - - /** - * @param array $slugs - * @return $this - */ - protected function setSlugs(array $slugs = null) - { - $this->slugs = $slugs ?? []; - return $this; - } - - /** - * @param array $smartypants - * @return $this - */ - protected function setSmartypants(array $smartypants = null) - { - $this->smartypants = $smartypants ?? []; - return $this; - } - - /** - * @param array $translations - * @return $this - */ - protected function setTranslations(array $translations = null) - { - $this->translations = $translations ?? []; - return $this; - } - - /** - * @param string $url - * @return $this - */ - protected function setUrl(string $url = null) - { - $this->url = $url; - return $this; - } - - /** - * Returns the custom slug rules for this language - * - * @return array - */ - public function slugs(): array - { - return $this->slugs; - } - - /** - * Returns the custom SmartyPants options for this language - * - * @return array - */ - public function smartypants(): array - { - return $this->smartypants; - } - - /** - * Returns the most important - * properties as array - * - * @return array - */ - public function toArray(): array - { - return [ - 'code' => $this->code(), - 'default' => $this->isDefault(), - 'direction' => $this->direction(), - 'locale' => $this->locale(), - 'name' => $this->name(), - 'rules' => $this->rules(), - 'url' => $this->url() - ]; - } - - /** - * Returns the translation strings for this language - * - * @return array - */ - public function translations(): array - { - return $this->translations; - } - - /** - * Returns the absolute Url for the language - * - * @return string - */ - public function url(): string - { - $url = $this->url; - - if ($url === null) { - $url = '/' . $this->code; - } - - return Url::makeAbsolute($url, $this->kirby()->url()); - } - - /** - * Update language properties and save them - * - * @internal - * @param array $props - * @return static - */ - public function update(array $props = null) - { - // don't change the language code - unset($props['code']); - - // make sure the slug is nice and clean - $props['slug'] = Str::slug($props['slug'] ?? null); - - $kirby = App::instance(); - $updated = $this->clone($props); - - // validate the updated language - LanguageRules::update($updated); - - // convert the current default to a non-default language - if ($updated->isDefault() === true) { - if ($oldDefault = $kirby->defaultLanguage()) { - $oldDefault->clone(['default' => false])->save(); - } - - $code = $this->code(); - $site = $kirby->site(); - - touch($site->contentFile($code)); - - foreach ($kirby->site()->index(true) as $page) { - $files = $page->files(); - - foreach ($files as $file) { - touch($file->contentFile($code)); - } - - touch($page->contentFile($code)); - } - } elseif ($this->isDefault() === true) { - throw new PermissionException('Please select another language to be the primary language'); - } - - $language = $updated->save(); - - // make sure the language is also updated in the Kirby language collection - App::instance()->languages(false)->set($language->code(), $language); - - return $language; - } + /** + * @var string + */ + protected $code; + + /** + * @var bool + */ + protected $default; + + /** + * @var string + */ + protected $direction; + + /** + * @var array + */ + protected $locale; + + /** + * @var string + */ + protected $name; + + /** + * @var array|null + */ + protected $slugs; + + /** + * @var array|null + */ + protected $smartypants; + + /** + * @var array|null + */ + protected $translations; + + /** + * @var string + */ + protected $url; + + /** + * Creates a new language object + * + * @param array $props + */ + public function __construct(array $props) + { + $this->setRequiredProperties($props, [ + 'code' + ]); + + $this->setOptionalProperties($props, [ + 'default', + 'direction', + 'locale', + 'name', + 'slugs', + 'smartypants', + 'translations', + 'url', + ]); + } + + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return $this->toArray(); + } + + /** + * Returns the language code + * when the language is converted to a string + * + * @return string + */ + public function __toString(): string + { + return $this->code(); + } + + /** + * Returns the base Url for the language + * without the path or other cruft + * + * @return string + */ + public function baseUrl(): string + { + $kirbyUrl = $this->kirby()->url(); + $languageUrl = $this->url(); + + if (empty($this->url)) { + return $kirbyUrl; + } + + if (Str::startsWith($languageUrl, $kirbyUrl) === true) { + return $kirbyUrl; + } + + return Url::base($languageUrl) ?? $kirbyUrl; + } + + /** + * Returns the language code/id. + * The language code is used in + * text file names as appendix. + * + * @return string + */ + public function code(): string + { + return $this->code; + } + + /** + * Internal converter to create or remove + * translation files. + * + * @param string $from + * @param string $to + * @return bool + */ + protected static function converter(string $from, string $to): bool + { + $kirby = App::instance(); + $site = $kirby->site(); + + // convert site + foreach ($site->files() as $file) { + F::move($file->contentFile($from, true), $file->contentFile($to, true)); + } + + F::move($site->contentFile($from, true), $site->contentFile($to, true)); + + // convert all pages + foreach ($kirby->site()->index(true) as $page) { + foreach ($page->files() as $file) { + F::move($file->contentFile($from, true), $file->contentFile($to, true)); + } + + F::move($page->contentFile($from, true), $page->contentFile($to, true)); + } + + // convert all users + foreach ($kirby->users() as $user) { + foreach ($user->files() as $file) { + F::move($file->contentFile($from, true), $file->contentFile($to, true)); + } + + F::move($user->contentFile($from, true), $user->contentFile($to, true)); + } + + return true; + } + + /** + * Creates a new language object + * + * @internal + * @param array $props + * @return static + */ + public static function create(array $props) + { + $props['code'] = Str::slug($props['code'] ?? null); + $kirby = App::instance(); + $languages = $kirby->languages(); + + // make the first language the default language + if ($languages->count() === 0) { + $props['default'] = true; + } + + $language = new static($props); + + // validate the new language + LanguageRules::create($language); + + $language->save(); + + if ($languages->count() === 0) { + static::converter('', $language->code()); + } + + // update the main languages collection in the app instance + App::instance()->languages(false)->append($language->code(), $language); + + return $language; + } + + /** + * Delete the current language and + * all its translation files + * + * @internal + * @return bool + * @throws \Kirby\Exception\Exception + */ + public function delete(): bool + { + $kirby = App::instance(); + $languages = $kirby->languages(); + $code = $this->code(); + $isLast = $languages->count() === 1; + + if (F::remove($this->root()) !== true) { + throw new Exception('The language could not be deleted'); + } + + if ($isLast === true) { + $this->converter($code, ''); + } else { + $this->deleteContentFiles($code); + } + + // get the original language collection and remove the current language + $kirby->languages(false)->remove($code); + + return true; + } + + /** + * When the language is deleted, all content files with + * the language code must be removed as well. + * + * @param mixed $code + * @return bool + */ + protected function deleteContentFiles($code): bool + { + $kirby = App::instance(); + $site = $kirby->site(); + + F::remove($site->contentFile($code, true)); + + foreach ($kirby->site()->index(true) as $page) { + foreach ($page->files() as $file) { + F::remove($file->contentFile($code, true)); + } + + F::remove($page->contentFile($code, true)); + } + + foreach ($kirby->users() as $user) { + foreach ($user->files() as $file) { + F::remove($file->contentFile($code, true)); + } + + F::remove($user->contentFile($code, true)); + } + + return true; + } + + /** + * Reading direction of this language + * + * @return string + */ + public function direction(): string + { + return $this->direction; + } + + /** + * Check if the language file exists + * + * @return bool + */ + public function exists(): bool + { + return file_exists($this->root()); + } + + /** + * Checks if this is the default language + * for the site. + * + * @return bool + */ + public function isDefault(): bool + { + return $this->default; + } + + /** + * The id is required for collections + * to work properly. The code is used as id + * + * @return string + */ + public function id(): string + { + return $this->code; + } + + /** + * Loads the language rules for provided locale code + * + * @param string $code + */ + public static function loadRules(string $code) + { + $kirby = App::instance(); + $code = Str::contains($code, '.') ? Str::before($code, '.') : $code; + $file = $kirby->root('i18n:rules') . '/' . $code . '.json'; + + if (F::exists($file) === false) { + $file = $kirby->root('i18n:rules') . '/' . Str::before($code, '_') . '.json'; + } + + try { + return Data::read($file); + } catch (\Exception $e) { + return []; + } + } + + /** + * Returns the PHP locale setting array + * + * @param int $category If passed, returns the locale for the specified category (e.g. LC_ALL) as string + * @return array|string + */ + public function locale(int $category = null) + { + if ($category !== null) { + return $this->locale[$category] ?? $this->locale[LC_ALL] ?? null; + } else { + return $this->locale; + } + } + + /** + * Returns the human-readable name + * of the language + * + * @return string + */ + public function name(): string + { + return $this->name; + } + + /** + * Returns the URL path for the language + * + * @return string + */ + public function path(): string + { + if ($this->url === null) { + return $this->code; + } + + return Url::path($this->url); + } + + /** + * Returns the routing pattern for the language + * + * @return string + */ + public function pattern(): string + { + $path = $this->path(); + + if (empty($path) === true) { + return '(:all)'; + } + + return $path . '/(:all?)'; + } + + /** + * Returns the absolute path to the language file + * + * @return string + */ + public function root(): string + { + return App::instance()->root('languages') . '/' . $this->code() . '.php'; + } + + /** + * Returns the LanguageRouter instance + * which is used to handle language specific + * routes. + * + * @return \Kirby\Cms\LanguageRouter + */ + public function router() + { + return new LanguageRouter($this); + } + + /** + * Get slug rules for language + * + * @internal + * @return array + */ + public function rules(): array + { + $code = $this->locale(LC_CTYPE); + $data = static::loadRules($code); + return array_merge($data, $this->slugs()); + } + + /** + * Saves the language settings in the languages folder + * + * @internal + * @return $this + */ + public function save() + { + try { + $existingData = Data::read($this->root()); + } catch (Throwable $e) { + $existingData = []; + } + + $props = [ + 'code' => $this->code(), + 'default' => $this->isDefault(), + 'direction' => $this->direction(), + 'locale' => Locale::export($this->locale()), + 'name' => $this->name(), + 'translations' => $this->translations(), + 'url' => $this->url, + ]; + + $data = array_merge($existingData, $props); + + ksort($data); + + Data::write($this->root(), $data); + + return $this; + } + + /** + * @param string $code + * @return $this + */ + protected function setCode(string $code) + { + $this->code = trim($code); + return $this; + } + + /** + * @param bool $default + * @return $this + */ + protected function setDefault(bool $default = false) + { + $this->default = $default; + return $this; + } + + /** + * @param string $direction + * @return $this + */ + protected function setDirection(string $direction = 'ltr') + { + $this->direction = $direction === 'rtl' ? 'rtl' : 'ltr'; + return $this; + } + + /** + * @param string|array $locale + * @return $this + */ + protected function setLocale($locale = null) + { + if ($locale === null) { + $this->locale = [LC_ALL => $this->code]; + } else { + $this->locale = Locale::normalize($locale); + } + + return $this; + } + + /** + * @param string $name + * @return $this + */ + protected function setName(string $name = null) + { + $this->name = trim($name ?? $this->code); + return $this; + } + + /** + * @param array $slugs + * @return $this + */ + protected function setSlugs(array $slugs = null) + { + $this->slugs = $slugs ?? []; + return $this; + } + + /** + * @param array $smartypants + * @return $this + */ + protected function setSmartypants(array $smartypants = null) + { + $this->smartypants = $smartypants ?? []; + return $this; + } + + /** + * @param array $translations + * @return $this + */ + protected function setTranslations(array $translations = null) + { + $this->translations = $translations ?? []; + return $this; + } + + /** + * @param string $url + * @return $this + */ + protected function setUrl(string $url = null) + { + $this->url = $url; + return $this; + } + + /** + * Returns the custom slug rules for this language + * + * @return array + */ + public function slugs(): array + { + return $this->slugs; + } + + /** + * Returns the custom SmartyPants options for this language + * + * @return array + */ + public function smartypants(): array + { + return $this->smartypants; + } + + /** + * Returns the most important + * properties as array + * + * @return array + */ + public function toArray(): array + { + return [ + 'code' => $this->code(), + 'default' => $this->isDefault(), + 'direction' => $this->direction(), + 'locale' => $this->locale(), + 'name' => $this->name(), + 'rules' => $this->rules(), + 'url' => $this->url() + ]; + } + + /** + * Returns the translation strings for this language + * + * @return array + */ + public function translations(): array + { + return $this->translations; + } + + /** + * Returns the absolute Url for the language + * + * @return string + */ + public function url(): string + { + $url = $this->url; + + if ($url === null) { + $url = '/' . $this->code; + } + + return Url::makeAbsolute($url, $this->kirby()->url()); + } + + /** + * Update language properties and save them + * + * @internal + * @param array $props + * @return static + */ + public function update(array $props = null) + { + // don't change the language code + unset($props['code']); + + // make sure the slug is nice and clean + $props['slug'] = Str::slug($props['slug'] ?? null); + + $kirby = App::instance(); + $updated = $this->clone($props); + + // validate the updated language + LanguageRules::update($updated); + + // convert the current default to a non-default language + if ($updated->isDefault() === true) { + if ($oldDefault = $kirby->defaultLanguage()) { + $oldDefault->clone(['default' => false])->save(); + } + + $code = $this->code(); + $site = $kirby->site(); + + touch($site->contentFile($code)); + + foreach ($kirby->site()->index(true) as $page) { + $files = $page->files(); + + foreach ($files as $file) { + touch($file->contentFile($code)); + } + + touch($page->contentFile($code)); + } + } elseif ($this->isDefault() === true) { + throw new PermissionException('Please select another language to be the primary language'); + } + + $language = $updated->save(); + + // make sure the language is also updated in the Kirby language collection + App::instance()->languages(false)->set($language->code(), $language); + + return $language; + } } diff --git a/kirby/src/Cms/LanguageRouter.php b/kirby/src/Cms/LanguageRouter.php index af35401..8d38455 100755 --- a/kirby/src/Cms/LanguageRouter.php +++ b/kirby/src/Cms/LanguageRouter.php @@ -20,117 +20,117 @@ use Kirby\Toolkit\Str; */ class LanguageRouter { - /** - * The parent language - * - * @var Language - */ - protected $language; + /** + * The parent language + * + * @var Language + */ + protected $language; - /** - * The router instance - * - * @var Router - */ - protected $router; + /** + * The router instance + * + * @var Router + */ + protected $router; - /** - * Creates a new language router instance - * for the given language - * - * @param \Kirby\Cms\Language $language - */ - public function __construct(Language $language) - { - $this->language = $language; - } + /** + * Creates a new language router instance + * for the given language + * + * @param \Kirby\Cms\Language $language + */ + public function __construct(Language $language) + { + $this->language = $language; + } - /** - * Fetches all scoped routes for the - * current language from the Kirby instance - * - * @return array - * @throws \Kirby\Exception\NotFoundException - */ - public function routes(): array - { - $language = $this->language; - $kirby = $language->kirby(); - $routes = $kirby->routes(); + /** + * Fetches all scoped routes for the + * current language from the Kirby instance + * + * @return array + * @throws \Kirby\Exception\NotFoundException + */ + public function routes(): array + { + $language = $this->language; + $kirby = $language->kirby(); + $routes = $kirby->routes(); - // only keep the scoped language routes - $routes = array_values(array_filter($routes, function ($route) use ($language) { + // only keep the scoped language routes + $routes = array_values(array_filter($routes, function ($route) use ($language) { - // no language scope - if (empty($route['language']) === true) { - return false; - } + // no language scope + if (empty($route['language']) === true) { + return false; + } - // wildcard - if ($route['language'] === '*') { - return true; - } + // wildcard + if ($route['language'] === '*') { + return true; + } - // get all applicable languages - $languages = Str::split(strtolower($route['language']), '|'); + // get all applicable languages + $languages = Str::split(strtolower($route['language']), '|'); - // validate the language - return in_array($language->code(), $languages) === true; - })); + // validate the language + return in_array($language->code(), $languages) === true; + })); - // add the page-scope if necessary - foreach ($routes as $index => $route) { - if ($pageId = ($route['page'] ?? null)) { - if ($page = $kirby->page($pageId)) { + // add the page-scope if necessary + foreach ($routes as $index => $route) { + if ($pageId = ($route['page'] ?? null)) { + if ($page = $kirby->page($pageId)) { - // convert string patterns to arrays - $patterns = A::wrap($route['pattern']); + // convert string patterns to arrays + $patterns = A::wrap($route['pattern']); - // prefix all patterns with the page slug - $patterns = A::map( - $patterns, - fn ($pattern) => $page->uri($language) . '/' . $pattern - ); + // prefix all patterns with the page slug + $patterns = A::map( + $patterns, + fn ($pattern) => $page->uri($language) . '/' . $pattern + ); - // re-inject the pattern and the full page object - $routes[$index]['pattern'] = $patterns; - $routes[$index]['page'] = $page; - } else { - throw new NotFoundException('The page "' . $pageId . '" does not exist'); - } - } - } + // re-inject the pattern and the full page object + $routes[$index]['pattern'] = $patterns; + $routes[$index]['page'] = $page; + } else { + throw new NotFoundException('The page "' . $pageId . '" does not exist'); + } + } + } - return $routes; - } + return $routes; + } - /** - * Wrapper around the Router::call method - * that injects the Language instance and - * if needed also the Page as arguments. - * - * @param string|null $path - * @return mixed - */ - public function call(string $path = null) - { - $language = $this->language; - $kirby = $language->kirby(); - $router = new Router($this->routes()); + /** + * Wrapper around the Router::call method + * that injects the Language instance and + * if needed also the Page as arguments. + * + * @param string|null $path + * @return mixed + */ + public function call(string $path = null) + { + $language = $this->language; + $kirby = $language->kirby(); + $router = new Router($this->routes()); - try { - return $router->call($path, $kirby->request()->method(), function ($route) use ($kirby, $language) { - $kirby->setCurrentTranslation($language); - $kirby->setCurrentLanguage($language); + try { + return $router->call($path, $kirby->request()->method(), function ($route) use ($kirby, $language) { + $kirby->setCurrentTranslation($language); + $kirby->setCurrentLanguage($language); - if ($page = $route->page()) { - return $route->action()->call($route, $language, $page, ...$route->arguments()); - } else { - return $route->action()->call($route, $language, ...$route->arguments()); - } - }); - } catch (Exception $e) { - return $kirby->resolve($path, $language->code()); - } - } + if ($page = $route->page()) { + return $route->action()->call($route, $language, $page, ...$route->arguments()); + } else { + return $route->action()->call($route, $language, ...$route->arguments()); + } + }); + } catch (Exception $e) { + return $kirby->resolve($path, $language->code()); + } + } } diff --git a/kirby/src/Cms/LanguageRoutes.php b/kirby/src/Cms/LanguageRoutes.php index 14801bb..ad0ac89 100755 --- a/kirby/src/Cms/LanguageRoutes.php +++ b/kirby/src/Cms/LanguageRoutes.php @@ -6,150 +6,150 @@ use Kirby\Filesystem\F; class LanguageRoutes { - /** - * Creates all multi-language routes - * - * @param \Kirby\Cms\App $kirby - * @return array - */ - public static function create(App $kirby): array - { - $routes = []; + /** + * Creates all multi-language routes + * + * @param \Kirby\Cms\App $kirby + * @return array + */ + public static function create(App $kirby): array + { + $routes = []; - // add the route for the home page - $routes[] = static::home($kirby); + // add the route for the home page + $routes[] = static::home($kirby); - // Kirby's base url - $baseurl = $kirby->url(); + // Kirby's base url + $baseurl = $kirby->url(); - foreach ($kirby->languages() as $language) { + foreach ($kirby->languages() as $language) { - // ignore languages with a different base url - if ($language->baseurl() !== $baseurl) { - continue; - } + // ignore languages with a different base url + if ($language->baseurl() !== $baseurl) { + continue; + } - $routes[] = [ - 'pattern' => $language->pattern(), - 'method' => 'ALL', - 'env' => 'site', - 'action' => function ($path = null) use ($language) { - if ($result = $language->router()->call($path)) { - return $result; - } + $routes[] = [ + 'pattern' => $language->pattern(), + 'method' => 'ALL', + 'env' => 'site', + 'action' => function ($path = null) use ($language) { + if ($result = $language->router()->call($path)) { + return $result; + } - // jump through to the fallback if nothing - // can be found for this language - /** @var \Kirby\Http\Route $this */ - $this->next(); - } - ]; - } + // jump through to the fallback if nothing + // can be found for this language + /** @var \Kirby\Http\Route $this */ + $this->next(); + } + ]; + } - $routes[] = static::fallback($kirby); + $routes[] = static::fallback($kirby); - return $routes; - } + return $routes; + } - /** - * Create the fallback route - * for unprefixed default language URLs. - * - * @param \Kirby\Cms\App $kirby - * @return array - */ - public static function fallback(App $kirby): array - { - return [ - 'pattern' => '(:all)', - 'method' => 'ALL', - 'env' => 'site', - 'action' => function (string $path) use ($kirby) { + /** + * Create the fallback route + * for unprefixed default language URLs. + * + * @param \Kirby\Cms\App $kirby + * @return array + */ + public static function fallback(App $kirby): array + { + return [ + 'pattern' => '(:all)', + 'method' => 'ALL', + 'env' => 'site', + 'action' => function (string $path) use ($kirby) { - // check for content representations or files - $extension = F::extension($path); + // check for content representations or files + $extension = F::extension($path); - // try to redirect prefixed pages - if (empty($extension) === true && $page = $kirby->page($path)) { - $url = $kirby->request()->url([ - 'query' => null, - 'params' => null, - 'fragment' => null - ]); + // try to redirect prefixed pages + if (empty($extension) === true && $page = $kirby->page($path)) { + $url = $kirby->request()->url([ + 'query' => null, + 'params' => null, + 'fragment' => null + ]); - if ($url->toString() !== $page->url()) { - // redirect to translated page directly - // if translation is exists and languages detect is enabled - if ( - $kirby->option('languages.detect') === true && - $page->translation($kirby->detectedLanguage()->code())->exists() === true - ) { - return $kirby - ->response() - ->redirect($page->url($kirby->detectedLanguage()->code())); - } + if ($url->toString() !== $page->url()) { + // redirect to translated page directly + // if translation is exists and languages detect is enabled + if ( + $kirby->option('languages.detect') === true && + $page->translation($kirby->detectedLanguage()->code())->exists() === true + ) { + return $kirby + ->response() + ->redirect($page->url($kirby->detectedLanguage()->code())); + } - return $kirby - ->response() - ->redirect($page->url()); - } - } + return $kirby + ->response() + ->redirect($page->url()); + } + } - return $kirby->language()->router()->call($path); - } - ]; - } + return $kirby->language()->router()->call($path); + } + ]; + } - /** - * Create the multi-language home page route - * - * @param \Kirby\Cms\App $kirby - * @return array - */ - public static function home(App $kirby): array - { - // Multi-language home - return [ - 'pattern' => '', - 'method' => 'ALL', - 'env' => 'site', - 'action' => function () use ($kirby) { + /** + * Create the multi-language home page route + * + * @param \Kirby\Cms\App $kirby + * @return array + */ + public static function home(App $kirby): array + { + // Multi-language home + return [ + 'pattern' => '', + 'method' => 'ALL', + 'env' => 'site', + 'action' => function () use ($kirby) { - // find all languages with the same base url as the current installation - $languages = $kirby->languages()->filter('baseurl', $kirby->url()); + // find all languages with the same base url as the current installation + $languages = $kirby->languages()->filter('baseurl', $kirby->url()); - // if there's no language with a matching base url, - // redirect to the default language - if ($languages->count() === 0) { - return $kirby - ->response() - ->redirect($kirby->defaultLanguage()->url()); - } + // if there's no language with a matching base url, + // redirect to the default language + if ($languages->count() === 0) { + return $kirby + ->response() + ->redirect($kirby->defaultLanguage()->url()); + } - // if there's just one language, we take that to render the home page - if ($languages->count() === 1) { - $currentLanguage = $languages->first(); - } else { - $currentLanguage = $kirby->defaultLanguage(); - } + // if there's just one language, we take that to render the home page + if ($languages->count() === 1) { + $currentLanguage = $languages->first(); + } else { + $currentLanguage = $kirby->defaultLanguage(); + } - // language detection on the home page with / as URL - if ($kirby->url() !== $currentLanguage->url()) { - if ($kirby->option('languages.detect') === true) { - return $kirby - ->response() - ->redirect($kirby->detectedLanguage()->url()); - } + // language detection on the home page with / as URL + if ($kirby->url() !== $currentLanguage->url()) { + if ($kirby->option('languages.detect') === true) { + return $kirby + ->response() + ->redirect($kirby->detectedLanguage()->url()); + } - return $kirby - ->response() - ->redirect($currentLanguage->url()); - } + return $kirby + ->response() + ->redirect($currentLanguage->url()); + } - // render the home page of the current language - return $currentLanguage->router()->call(); - } - ]; - } + // render the home page of the current language + return $currentLanguage->router()->call(); + } + ]; + } } diff --git a/kirby/src/Cms/LanguageRules.php b/kirby/src/Cms/LanguageRules.php index d8887ae..31c751e 100755 --- a/kirby/src/Cms/LanguageRules.php +++ b/kirby/src/Cms/LanguageRules.php @@ -17,82 +17,82 @@ use Kirby\Toolkit\Str; */ class LanguageRules { - /** - * Validates if the language can be created - * - * @param \Kirby\Cms\Language $language - * @return bool - * @throws \Kirby\Exception\DuplicateException If the language already exists - */ - public static function create(Language $language): bool - { - static::validLanguageCode($language); - static::validLanguageName($language); + /** + * Validates if the language can be created + * + * @param \Kirby\Cms\Language $language + * @return bool + * @throws \Kirby\Exception\DuplicateException If the language already exists + */ + public static function create(Language $language): bool + { + static::validLanguageCode($language); + static::validLanguageName($language); - if ($language->exists() === true) { - throw new DuplicateException([ - 'key' => 'language.duplicate', - 'data' => [ - 'code' => $language->code() - ] - ]); - } + if ($language->exists() === true) { + throw new DuplicateException([ + 'key' => 'language.duplicate', + 'data' => [ + 'code' => $language->code() + ] + ]); + } - return true; - } + return true; + } - /** - * Validates if the language can be updated - * - * @param \Kirby\Cms\Language $language - */ - public static function update(Language $language) - { - static::validLanguageCode($language); - static::validLanguageName($language); - } + /** + * Validates if the language can be updated + * + * @param \Kirby\Cms\Language $language + */ + public static function update(Language $language) + { + static::validLanguageCode($language); + static::validLanguageName($language); + } - /** - * Validates if the language code is formatted correctly - * - * @param \Kirby\Cms\Language $language - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException If the language code is not valid - */ - public static function validLanguageCode(Language $language): bool - { - if (Str::length($language->code()) < 2) { - throw new InvalidArgumentException([ - 'key' => 'language.code', - 'data' => [ - 'code' => $language->code(), - 'name' => $language->name() - ] - ]); - } + /** + * Validates if the language code is formatted correctly + * + * @param \Kirby\Cms\Language $language + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException If the language code is not valid + */ + public static function validLanguageCode(Language $language): bool + { + if (Str::length($language->code()) < 2) { + throw new InvalidArgumentException([ + 'key' => 'language.code', + 'data' => [ + 'code' => $language->code(), + 'name' => $language->name() + ] + ]); + } - return true; - } + return true; + } - /** - * Validates if the language name is formatted correctly - * - * @param \Kirby\Cms\Language $language - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException If the language name is invalid - */ - public static function validLanguageName(Language $language): bool - { - if (Str::length($language->name()) < 1) { - throw new InvalidArgumentException([ - 'key' => 'language.name', - 'data' => [ - 'code' => $language->code(), - 'name' => $language->name() - ] - ]); - } + /** + * Validates if the language name is formatted correctly + * + * @param \Kirby\Cms\Language $language + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException If the language name is invalid + */ + public static function validLanguageName(Language $language): bool + { + if (Str::length($language->name()) < 1) { + throw new InvalidArgumentException([ + 'key' => 'language.name', + 'data' => [ + 'code' => $language->code(), + 'name' => $language->name() + ] + ]); + } - return true; - } + return true; + } } diff --git a/kirby/src/Cms/Languages.php b/kirby/src/Cms/Languages.php index 2b07096..d746977 100755 --- a/kirby/src/Cms/Languages.php +++ b/kirby/src/Cms/Languages.php @@ -16,86 +16,86 @@ use Kirby\Filesystem\F; */ class Languages extends Collection { - /** - * Creates a new collection with the given language objects - * - * @param array $objects `Kirby\Cms\Language` objects - * @param null $parent - * @throws \Kirby\Exception\DuplicateException - */ - public function __construct($objects = [], $parent = null) - { - $defaults = array_filter( - $objects, - fn ($language) => $language->isDefault() === true - ); + /** + * Creates a new collection with the given language objects + * + * @param array $objects `Kirby\Cms\Language` objects + * @param null $parent + * @throws \Kirby\Exception\DuplicateException + */ + public function __construct($objects = [], $parent = null) + { + $defaults = array_filter( + $objects, + fn ($language) => $language->isDefault() === true + ); - if (count($defaults) > 1) { - throw new DuplicateException('You cannot have multiple default languages. Please check your language config files.'); - } + if (count($defaults) > 1) { + throw new DuplicateException('You cannot have multiple default languages. Please check your language config files.'); + } - parent::__construct($objects, $parent); - } + parent::__construct($objects, $parent); + } - /** - * Returns all language codes as array - * - * @return array - */ - public function codes(): array - { - return $this->keys(); - } + /** + * Returns all language codes as array + * + * @return array + */ + public function codes(): array + { + return $this->keys(); + } - /** - * Creates a new language with the given props - * - * @internal - * @param array $props - * @return \Kirby\Cms\Language - */ - public function create(array $props) - { - return Language::create($props); - } + /** + * Creates a new language with the given props + * + * @internal + * @param array $props + * @return \Kirby\Cms\Language + */ + public function create(array $props) + { + return Language::create($props); + } - /** - * Returns the default language - * - * @return \Kirby\Cms\Language|null - */ - public function default() - { - if ($language = $this->findBy('isDefault', true)) { - return $language; - } else { - return $this->first(); - } - } + /** + * Returns the default language + * + * @return \Kirby\Cms\Language|null + */ + public function default() + { + if ($language = $this->findBy('isDefault', true)) { + return $language; + } else { + return $this->first(); + } + } - /** - * Convert all defined languages to a collection - * - * @internal - * @return static - */ - public static function load() - { - $languages = []; - $files = glob(App::instance()->root('languages') . '/*.php'); + /** + * Convert all defined languages to a collection + * + * @internal + * @return static + */ + public static function load() + { + $languages = []; + $files = glob(App::instance()->root('languages') . '/*.php'); - foreach ($files as $file) { - $props = F::load($file); + foreach ($files as $file) { + $props = F::load($file); - if (is_array($props) === true) { - // inject the language code from the filename - // if it does not exist - $props['code'] ??= F::name($file); + if (is_array($props) === true) { + // inject the language code from the filename + // if it does not exist + $props['code'] ??= F::name($file); - $languages[] = new Language($props); - } - } + $languages[] = new Language($props); + } + } - return new static($languages); - } + return new static($languages); + } } diff --git a/kirby/src/Cms/Layout.php b/kirby/src/Cms/Layout.php index 22bbf06..9a27fbf 100755 --- a/kirby/src/Cms/Layout.php +++ b/kirby/src/Cms/Layout.php @@ -15,113 +15,113 @@ namespace Kirby\Cms; */ class Layout extends Item { - use HasMethods; + use HasMethods; - public const ITEMS_CLASS = '\Kirby\Cms\Layouts'; + public const ITEMS_CLASS = '\Kirby\Cms\Layouts'; - /** - * @var \Kirby\Cms\Content - */ - protected $attrs; + /** + * @var \Kirby\Cms\Content + */ + protected $attrs; - /** - * @var \Kirby\Cms\LayoutColumns - */ - protected $columns; + /** + * @var \Kirby\Cms\LayoutColumns + */ + protected $columns; - /** - * Proxy for attrs - * - * @param string $method - * @param array $args - * @return \Kirby\Cms\Field - */ - public function __call(string $method, array $args = []) - { - // layout methods - if ($this->hasMethod($method) === true) { - return $this->callMethod($method, $args); - } + /** + * Proxy for attrs + * + * @param string $method + * @param array $args + * @return \Kirby\Cms\Field + */ + public function __call(string $method, array $args = []) + { + // layout methods + if ($this->hasMethod($method) === true) { + return $this->callMethod($method, $args); + } - return $this->attrs()->get($method); - } + return $this->attrs()->get($method); + } - /** - * Creates a new Layout object - * - * @param array $params - */ - public function __construct(array $params = []) - { - parent::__construct($params); + /** + * Creates a new Layout object + * + * @param array $params + */ + public function __construct(array $params = []) + { + parent::__construct($params); - $this->columns = LayoutColumns::factory($params['columns'] ?? [], [ - 'parent' => $this->parent - ]); + $this->columns = LayoutColumns::factory($params['columns'] ?? [], [ + 'parent' => $this->parent + ]); - // create the attrs object - $this->attrs = new Content($params['attrs'] ?? [], $this->parent); - } + // create the attrs object + $this->attrs = new Content($params['attrs'] ?? [], $this->parent); + } - /** - * Returns the attrs object - * - * @return \Kirby\Cms\Content - */ - public function attrs() - { - return $this->attrs; - } + /** + * Returns the attrs object + * + * @return \Kirby\Cms\Content + */ + public function attrs() + { + return $this->attrs; + } - /** - * Returns the columns in this layout - * - * @return \Kirby\Cms\LayoutColumns - */ - public function columns() - { - return $this->columns; - } + /** + * Returns the columns in this layout + * + * @return \Kirby\Cms\LayoutColumns + */ + public function columns() + { + return $this->columns; + } - /** - * Checks if the layout is empty - * @since 3.5.2 - * - * @return bool - */ - public function isEmpty(): bool - { - return $this - ->columns() - ->filter(function ($column) { - return $column->isNotEmpty(); - }) - ->count() === 0; - } + /** + * Checks if the layout is empty + * @since 3.5.2 + * + * @return bool + */ + public function isEmpty(): bool + { + return $this + ->columns() + ->filter(function ($column) { + return $column->isNotEmpty(); + }) + ->count() === 0; + } - /** - * Checks if the layout is not empty - * @since 3.5.2 - * - * @return bool - */ - public function isNotEmpty(): bool - { - return $this->isEmpty() === false; - } + /** + * Checks if the layout is not empty + * @since 3.5.2 + * + * @return bool + */ + public function isNotEmpty(): bool + { + return $this->isEmpty() === false; + } - /** - * The result is being sent to the editor - * via the API in the panel - * - * @return array - */ - public function toArray(): array - { - return [ - 'attrs' => $this->attrs()->toArray(), - 'columns' => $this->columns()->toArray(), - 'id' => $this->id(), - ]; - } + /** + * The result is being sent to the editor + * via the API in the panel + * + * @return array + */ + public function toArray(): array + { + return [ + 'attrs' => $this->attrs()->toArray(), + 'columns' => $this->columns()->toArray(), + 'id' => $this->id(), + ]; + } } diff --git a/kirby/src/Cms/LayoutColumn.php b/kirby/src/Cms/LayoutColumn.php index 1a33ab9..2f652d1 100755 --- a/kirby/src/Cms/LayoutColumn.php +++ b/kirby/src/Cms/LayoutColumn.php @@ -17,128 +17,128 @@ use Kirby\Toolkit\Str; */ class LayoutColumn extends Item { - use HasMethods; + use HasMethods; - public const ITEMS_CLASS = '\Kirby\Cms\LayoutColumns'; + public const ITEMS_CLASS = '\Kirby\Cms\LayoutColumns'; - /** - * @var \Kirby\Cms\Blocks - */ - protected $blocks; + /** + * @var \Kirby\Cms\Blocks + */ + protected $blocks; - /** - * @var string - */ - protected $width; + /** + * @var string + */ + protected $width; - /** - * Creates a new LayoutColumn object - * - * @param array $params - */ - public function __construct(array $params = []) - { - parent::__construct($params); + /** + * Creates a new LayoutColumn object + * + * @param array $params + */ + public function __construct(array $params = []) + { + parent::__construct($params); - $this->blocks = Blocks::factory($params['blocks'] ?? [], [ - 'parent' => $this->parent - ]); + $this->blocks = Blocks::factory($params['blocks'] ?? [], [ + 'parent' => $this->parent + ]); - $this->width = $params['width'] ?? '1/1'; - } + $this->width = $params['width'] ?? '1/1'; + } - /** - * Magic getter function - * - * @param string $method - * @param mixed $args - * @return mixed - */ - public function __call(string $method, $args) - { - // layout column methods - if ($this->hasMethod($method) === true) { - return $this->callMethod($method, $args); - } - } + /** + * Magic getter function + * + * @param string $method + * @param mixed $args + * @return mixed + */ + public function __call(string $method, $args) + { + // layout column methods + if ($this->hasMethod($method) === true) { + return $this->callMethod($method, $args); + } + } - /** - * Returns the blocks collection - * - * @param bool $includeHidden Sets whether to include hidden blocks - * @return \Kirby\Cms\Blocks - */ - public function blocks(bool $includeHidden = false) - { - if ($includeHidden === false) { - return $this->blocks->filter('isHidden', false); - } + /** + * Returns the blocks collection + * + * @param bool $includeHidden Sets whether to include hidden blocks + * @return \Kirby\Cms\Blocks + */ + public function blocks(bool $includeHidden = false) + { + if ($includeHidden === false) { + return $this->blocks->filter('isHidden', false); + } - return $this->blocks; - } + return $this->blocks; + } - /** - * Checks if the column is empty - * @since 3.5.2 - * - * @return bool - */ - public function isEmpty(): bool - { - return $this - ->blocks() - ->filter('isHidden', false) - ->count() === 0; - } + /** + * Checks if the column is empty + * @since 3.5.2 + * + * @return bool + */ + public function isEmpty(): bool + { + return $this + ->blocks() + ->filter('isHidden', false) + ->count() === 0; + } - /** - * Checks if the column is not empty - * @since 3.5.2 - * - * @return bool - */ - public function isNotEmpty(): bool - { - return $this->isEmpty() === false; - } + /** + * Checks if the column is not empty + * @since 3.5.2 + * + * @return bool + */ + public function isNotEmpty(): bool + { + return $this->isEmpty() === false; + } - /** - * Returns the number of columns this column spans - * - * @param int $columns - * @return int - */ - public function span(int $columns = 12): int - { - $fraction = Str::split($this->width, '/'); - $a = $fraction[0] ?? 1; - $b = $fraction[1] ?? 1; + /** + * Returns the number of columns this column spans + * + * @param int $columns + * @return int + */ + public function span(int $columns = 12): int + { + $fraction = Str::split($this->width, '/'); + $a = $fraction[0] ?? 1; + $b = $fraction[1] ?? 1; - return $columns * $a / $b; - } + return $columns * $a / $b; + } - /** - * The result is being sent to the editor - * via the API in the panel - * - * @return array - */ - public function toArray(): array - { - return [ - 'blocks' => $this->blocks(true)->toArray(), - 'id' => $this->id(), - 'width' => $this->width(), - ]; - } + /** + * The result is being sent to the editor + * via the API in the panel + * + * @return array + */ + public function toArray(): array + { + return [ + 'blocks' => $this->blocks(true)->toArray(), + 'id' => $this->id(), + 'width' => $this->width(), + ]; + } - /** - * Returns the width of the column - * - * @return string - */ - public function width(): string - { - return $this->width; - } + /** + * Returns the width of the column + * + * @return string + */ + public function width(): string + { + return $this->width; + } } diff --git a/kirby/src/Cms/LayoutColumns.php b/kirby/src/Cms/LayoutColumns.php index 1ebab67..449678b 100755 --- a/kirby/src/Cms/LayoutColumns.php +++ b/kirby/src/Cms/LayoutColumns.php @@ -14,5 +14,5 @@ namespace Kirby\Cms; */ class LayoutColumns extends Items { - public const ITEM_CLASS = '\Kirby\Cms\LayoutColumn'; + public const ITEM_CLASS = '\Kirby\Cms\LayoutColumn'; } diff --git a/kirby/src/Cms/Layouts.php b/kirby/src/Cms/Layouts.php index 35dfc73..b9f4c90 100755 --- a/kirby/src/Cms/Layouts.php +++ b/kirby/src/Cms/Layouts.php @@ -18,86 +18,86 @@ use Throwable; */ class Layouts extends Items { - public const ITEM_CLASS = '\Kirby\Cms\Layout'; + public const ITEM_CLASS = '\Kirby\Cms\Layout'; - public static function factory(array $items = null, array $params = []) - { - $first = $items[0] ?? []; + public static function factory(array $items = null, array $params = []) + { + $first = $items[0] ?? []; - // if there are no wrapping layouts for blocks yet … - if (array_key_exists('content', $first) === true || array_key_exists('type', $first) === true) { - $items = [ - [ - 'id' => Str::uuid(), - 'columns' => [ - [ - 'width' => '1/1', - 'blocks' => $items - ] - ] - ] - ]; - } + // if there are no wrapping layouts for blocks yet … + if (array_key_exists('content', $first) === true || array_key_exists('type', $first) === true) { + $items = [ + [ + 'id' => Str::uuid(), + 'columns' => [ + [ + 'width' => '1/1', + 'blocks' => $items + ] + ] + ] + ]; + } - return parent::factory($items, $params); - } + return parent::factory($items, $params); + } - /** - * Checks if a given block type exists in the layouts collection - * @since 3.6.0 - * - * @param string $type - * @return bool - */ - public function hasBlockType(string $type): bool - { - return $this->toBlocks()->hasType($type); - } + /** + * Checks if a given block type exists in the layouts collection + * @since 3.6.0 + * + * @param string $type + * @return bool + */ + public function hasBlockType(string $type): bool + { + return $this->toBlocks()->hasType($type); + } - /** - * Parse layouts data - * - * @param array|string $input - * @return array - */ - public static function parse($input): array - { - if (empty($input) === false && is_array($input) === false) { - try { - $input = Data::decode($input, 'json'); - } catch (Throwable $e) { - return []; - } - } + /** + * Parse layouts data + * + * @param array|string $input + * @return array + */ + public static function parse($input): array + { + if (empty($input) === false && is_array($input) === false) { + try { + $input = Data::decode($input, 'json'); + } catch (Throwable $e) { + return []; + } + } - if (empty($input) === true) { - return []; - } + if (empty($input) === true) { + return []; + } - return $input; - } + return $input; + } - /** - * Converts layouts to blocks - * @since 3.6.0 - * - * @param bool $includeHidden Sets whether to include hidden blocks - * @return \Kirby\Cms\Blocks - */ - public function toBlocks(bool $includeHidden = false) - { - $blocks = []; + /** + * Converts layouts to blocks + * @since 3.6.0 + * + * @param bool $includeHidden Sets whether to include hidden blocks + * @return \Kirby\Cms\Blocks + */ + public function toBlocks(bool $includeHidden = false) + { + $blocks = []; - if ($this->isNotEmpty() === true) { - foreach ($this->data() as $layout) { - foreach ($layout->columns() as $column) { - foreach ($column->blocks($includeHidden) as $block) { - $blocks[] = $block->toArray(); - } - } - } - } + if ($this->isNotEmpty() === true) { + foreach ($this->data() as $layout) { + foreach ($layout->columns() as $column) { + foreach ($column->blocks($includeHidden) as $block) { + $blocks[] = $block->toArray(); + } + } + } + } - return Blocks::factory($blocks); - } + return Blocks::factory($blocks); + } } diff --git a/kirby/src/Cms/Loader.php b/kirby/src/Cms/Loader.php index 611727c..0f0cbc4 100755 --- a/kirby/src/Cms/Loader.php +++ b/kirby/src/Cms/Loader.php @@ -28,223 +28,223 @@ use Kirby\Filesystem\F; */ class Loader { - /** - * @var \Kirby\Cms\App - */ - protected $kirby; + /** + * @var \Kirby\Cms\App + */ + protected $kirby; - /** - * @var bool - */ - protected $withPlugins; + /** + * @var bool + */ + protected $withPlugins; - /** - * @param \Kirby\Cms\App $kirby - * @param bool $withPlugins - */ - public function __construct(App $kirby, bool $withPlugins = true) - { - $this->kirby = $kirby; - $this->withPlugins = $withPlugins; - } + /** + * @param \Kirby\Cms\App $kirby + * @param bool $withPlugins + */ + public function __construct(App $kirby, bool $withPlugins = true) + { + $this->kirby = $kirby; + $this->withPlugins = $withPlugins; + } - /** - * Loads the area definition - * - * @param string $name - * @return array|null - */ - public function area(string $name): ?array - { - return $this->areas()[$name] ?? null; - } + /** + * Loads the area definition + * + * @param string $name + * @return array|null + */ + public function area(string $name): ?array + { + return $this->areas()[$name] ?? null; + } - /** - * Loads all areas and makes sure that plugins - * are injected properly - * - * @return array - */ - public function areas(): array - { - $areas = []; - $extensions = $this->withPlugins === true ? $this->kirby->extensions('areas') : []; + /** + * Loads all areas and makes sure that plugins + * are injected properly + * + * @return array + */ + public function areas(): array + { + $areas = []; + $extensions = $this->withPlugins === true ? $this->kirby->extensions('areas') : []; - // load core areas and extend them with elements from plugins if they exist - foreach ($this->kirby->core()->areas() as $id => $area) { - $area = $this->resolveArea($area); + // load core areas and extend them with elements from plugins if they exist + foreach ($this->kirby->core()->areas() as $id => $area) { + $area = $this->resolveArea($area); - if (isset($extensions[$id]) === true) { - foreach ($extensions[$id] as $areaExtension) { - $extension = $this->resolveArea($areaExtension); - $area = array_replace_recursive($area, $extension); - } + if (isset($extensions[$id]) === true) { + foreach ($extensions[$id] as $areaExtension) { + $extension = $this->resolveArea($areaExtension); + $area = array_replace_recursive($area, $extension); + } - unset($extensions[$id]); - } + unset($extensions[$id]); + } - $areas[$id] = $area; - } + $areas[$id] = $area; + } - // add additional areas from plugins - foreach ($extensions as $id => $areaExtensions) { - foreach ($areaExtensions as $areaExtension) { - $areas[$id] = $this->resolve($areaExtension); - } - } + // add additional areas from plugins + foreach ($extensions as $id => $areaExtensions) { + foreach ($areaExtensions as $areaExtension) { + $areas[$id] = $this->resolve($areaExtension); + } + } - return $areas; - } + return $areas; + } - /** - * Loads a core component closure - * - * @param string $name - * @return \Closure|null - */ - public function component(string $name): ?Closure - { - return $this->extension('components', $name); - } + /** + * Loads a core component closure + * + * @param string $name + * @return \Closure|null + */ + public function component(string $name): ?Closure + { + return $this->extension('components', $name); + } - /** - * Loads all core component closures - * - * @return array - */ - public function components(): array - { - return $this->extensions('components'); - } + /** + * Loads all core component closures + * + * @return array + */ + public function components(): array + { + return $this->extensions('components'); + } - /** - * Loads a particular extension - * - * @param string $type - * @param string $name - * @return mixed - */ - public function extension(string $type, string $name) - { - return $this->extensions($type)[$name] ?? null; - } + /** + * Loads a particular extension + * + * @param string $type + * @param string $name + * @return mixed + */ + public function extension(string $type, string $name) + { + return $this->extensions($type)[$name] ?? null; + } - /** - * Loads all defined extensions - * - * @param string $type - * @return array - */ - public function extensions(string $type): array - { - return $this->withPlugins === false ? $this->kirby->core()->$type() : $this->kirby->extensions($type); - } + /** + * Loads all defined extensions + * + * @param string $type + * @return array + */ + public function extensions(string $type): array + { + return $this->withPlugins === false ? $this->kirby->core()->$type() : $this->kirby->extensions($type); + } - /** - * The resolver takes a string, array or closure. - * - * 1.) a string is supposed to be a path to an existing file. - * The file will either be included when it's a PHP file and - * the array contents will be read. Or it will be parsed with - * the Data class to read yml or json data into an array - * - * 2.) arrays are untouched and returned - * - * 3.) closures will be called and the Kirby instance will be - * passed as first argument - * - * @param mixed $item - * @return mixed - */ - public function resolve($item) - { - if (is_string($item) === true) { - if (F::extension($item) !== 'php') { - $item = Data::read($item); - } else { - $item = require $item; - } - } + /** + * The resolver takes a string, array or closure. + * + * 1.) a string is supposed to be a path to an existing file. + * The file will either be included when it's a PHP file and + * the array contents will be read. Or it will be parsed with + * the Data class to read yml or json data into an array + * + * 2.) arrays are untouched and returned + * + * 3.) closures will be called and the Kirby instance will be + * passed as first argument + * + * @param mixed $item + * @return mixed + */ + public function resolve($item) + { + if (is_string($item) === true) { + if (F::extension($item) !== 'php') { + $item = Data::read($item); + } else { + $item = require $item; + } + } - if (is_callable($item)) { - $item = $item($this->kirby); - } + if (is_callable($item)) { + $item = $item($this->kirby); + } - return $item; - } + return $item; + } - /** - * Calls `static::resolve()` on all items - * in the given array - * - * @param array $items - * @return array - */ - public function resolveAll(array $items): array - { - $result = []; + /** + * Calls `static::resolve()` on all items + * in the given array + * + * @param array $items + * @return array + */ + public function resolveAll(array $items): array + { + $result = []; - foreach ($items as $key => $value) { - $result[$key] = $this->resolve($value); - } + foreach ($items as $key => $value) { + $result[$key] = $this->resolve($value); + } - return $result; - } + return $result; + } - /** - * Areas need a bit of special treatment - * when they are being loaded - * - * @param string|array|Closure $area - * @return array - */ - public function resolveArea($area): array - { - $area = $this->resolve($area); - $dropdowns = $area['dropdowns'] ?? []; + /** + * Areas need a bit of special treatment + * when they are being loaded + * + * @param string|array|Closure $area + * @return array + */ + public function resolveArea($area): array + { + $area = $this->resolve($area); + $dropdowns = $area['dropdowns'] ?? []; - // convert closure dropdowns to an array definition - // otherwise they cannot be merged properly later - foreach ($dropdowns as $key => $dropdown) { - if (is_a($dropdown, 'Closure') === true) { - $area['dropdowns'][$key] = [ - 'options' => $dropdown - ]; - } - } + // convert closure dropdowns to an array definition + // otherwise they cannot be merged properly later + foreach ($dropdowns as $key => $dropdown) { + if (is_a($dropdown, 'Closure') === true) { + $area['dropdowns'][$key] = [ + 'options' => $dropdown + ]; + } + } - return $area; - } + return $area; + } - /** - * Loads a particular section definition - * - * @param string $name - * @return array|null - */ - public function section(string $name): ?array - { - return $this->resolve($this->extension('sections', $name)); - } + /** + * Loads a particular section definition + * + * @param string $name + * @return array|null + */ + public function section(string $name): ?array + { + return $this->resolve($this->extension('sections', $name)); + } - /** - * Loads all section defintions - * - * @return array - */ - public function sections(): array - { - return $this->resolveAll($this->extensions('sections')); - } + /** + * Loads all section defintions + * + * @return array + */ + public function sections(): array + { + return $this->resolveAll($this->extensions('sections')); + } - /** - * Returns the status flag, which shows - * if plugins are loaded as well. - * - * @return bool - */ - public function withPlugins(): bool - { - return $this->withPlugins; - } + /** + * Returns the status flag, which shows + * if plugins are loaded as well. + * + * @return bool + */ + public function withPlugins(): bool + { + return $this->withPlugins; + } } diff --git a/kirby/src/Cms/Media.php b/kirby/src/Cms/Media.php index 1520ab9..022778b 100755 --- a/kirby/src/Cms/Media.php +++ b/kirby/src/Cms/Media.php @@ -20,153 +20,153 @@ use Throwable; */ class Media { - /** - * Tries to find a file by model and filename - * and to copy it to the media folder. - * - * @param \Kirby\Cms\Model|null $model - * @param string $hash - * @param string $filename - * @return \Kirby\Cms\Response|false - */ - public static function link(Model $model = null, string $hash, string $filename) - { - if ($model === null) { - return false; - } + /** + * Tries to find a file by model and filename + * and to copy it to the media folder. + * + * @param \Kirby\Cms\Model|null $model + * @param string $hash + * @param string $filename + * @return \Kirby\Cms\Response|false + */ + public static function link(Model $model = null, string $hash, string $filename) + { + if ($model === null) { + return false; + } - // fix issues with spaces in filenames - $filename = urldecode($filename); + // fix issues with spaces in filenames + $filename = urldecode($filename); - // try to find a file by model and filename - // this should work for all original files - if ($file = $model->file($filename)) { + // try to find a file by model and filename + // this should work for all original files + if ($file = $model->file($filename)) { - // check if the request contained an outdated media hash - if ($file->mediaHash() !== $hash) { - // if at least the token was correct, redirect - if (Str::startsWith($hash, $file->mediaToken() . '-') === true) { - return Response::redirect($file->mediaUrl(), 307); - } else { - // don't leak the correct token, render the error page - return false; - } - } + // check if the request contained an outdated media hash + if ($file->mediaHash() !== $hash) { + // if at least the token was correct, redirect + if (Str::startsWith($hash, $file->mediaToken() . '-') === true) { + return Response::redirect($file->mediaUrl(), 307); + } else { + // don't leak the correct token, render the error page + return false; + } + } - // send the file to the browser - return Response::file($file->publish()->mediaRoot()); - } + // send the file to the browser + return Response::file($file->publish()->mediaRoot()); + } - // try to generate a thumb for the file - return static::thumb($model, $hash, $filename); - } + // try to generate a thumb for the file + return static::thumb($model, $hash, $filename); + } - /** - * Copy the file to the final media folder location - * - * @param \Kirby\Cms\File $file - * @param string $dest - * @return bool - */ - public static function publish(File $file, string $dest): bool - { - // never publish risky files (e.g. HTML, PHP or Apache config files) - FileRules::validFile($file, false); + /** + * Copy the file to the final media folder location + * + * @param \Kirby\Cms\File $file + * @param string $dest + * @return bool + */ + public static function publish(File $file, string $dest): bool + { + // never publish risky files (e.g. HTML, PHP or Apache config files) + FileRules::validFile($file, false); - $src = $file->root(); - $version = dirname($dest); - $directory = dirname($version); + $src = $file->root(); + $version = dirname($dest); + $directory = dirname($version); - // unpublish all files except stuff in the version folder - Media::unpublish($directory, $file, $version); + // unpublish all files except stuff in the version folder + Media::unpublish($directory, $file, $version); - // copy/overwrite the file to the dest folder - return F::copy($src, $dest, true); - } + // copy/overwrite the file to the dest folder + return F::copy($src, $dest, true); + } - /** - * Tries to find a job file for the - * given filename and then calls the thumb - * component to create a thumbnail accordingly - * - * @param \Kirby\Cms\Model|string $model - * @param string $hash - * @param string $filename - * @return \Kirby\Cms\Response|false - */ - public static function thumb($model, string $hash, string $filename) - { - $kirby = App::instance(); + /** + * Tries to find a job file for the + * given filename and then calls the thumb + * component to create a thumbnail accordingly + * + * @param \Kirby\Cms\Model|string $model + * @param string $hash + * @param string $filename + * @return \Kirby\Cms\Response|false + */ + public static function thumb($model, string $hash, string $filename) + { + $kirby = App::instance(); - // assets - if (is_string($model) === true) { - $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 { - $root = $model->mediaRoot() . '/' . $hash; - } + // assets + if (is_string($model) === true) { + $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 { + $root = $model->mediaRoot() . '/' . $hash; + } - try { - $thumb = $root . '/' . $filename; - $job = $root . '/.jobs/' . $filename . '.json'; - $options = Data::read($job); + try { + $thumb = $root . '/' . $filename; + $job = $root . '/.jobs/' . $filename . '.json'; + $options = Data::read($job); - if (empty($options) === true) { - return false; - } + if (empty($options) === true) { + return false; + } - if (is_string($model) === true) { - $source = $kirby->root('index') . '/' . $model . '/' . $options['filename']; - } else { - $source = $model->file($options['filename'])->root(); - } + if (is_string($model) === true) { + $source = $kirby->root('index') . '/' . $model . '/' . $options['filename']; + } else { + $source = $model->file($options['filename'])->root(); + } - try { - $kirby->thumb($source, $thumb, $options); - F::remove($job); - return Response::file($thumb); - } catch (Throwable $e) { - F::remove($thumb); - return Response::file($source); - } - } catch (Throwable $e) { - return false; - } - } + try { + $kirby->thumb($source, $thumb, $options); + F::remove($job); + return Response::file($thumb); + } catch (Throwable $e) { + F::remove($thumb); + return Response::file($source); + } + } catch (Throwable $e) { + return false; + } + } - /** - * Deletes all versions of the given file - * within the parent directory - * - * @param string $directory - * @param \Kirby\Cms\File $file - * @param string|null $ignore - * @return bool - */ - public static function unpublish(string $directory, File $file, string $ignore = null): bool - { - if (is_dir($directory) === false) { - return true; - } + /** + * Deletes all versions of the given file + * within the parent directory + * + * @param string $directory + * @param \Kirby\Cms\File $file + * @param string|null $ignore + * @return bool + */ + public static function unpublish(string $directory, File $file, string $ignore = null): bool + { + if (is_dir($directory) === false) { + return true; + } - // get both old and new versions (pre and post Kirby 3.4.0) - $versions = array_merge( - glob($directory . '/' . crc32($file->filename()) . '-*', GLOB_ONLYDIR), - glob($directory . '/' . $file->mediaToken() . '-*', GLOB_ONLYDIR) - ); + // get both old and new versions (pre and post Kirby 3.4.0) + $versions = array_merge( + glob($directory . '/' . crc32($file->filename()) . '-*', GLOB_ONLYDIR), + glob($directory . '/' . $file->mediaToken() . '-*', GLOB_ONLYDIR) + ); - // delete all versions of the file - foreach ($versions as $version) { - if ($version === $ignore) { - continue; - } + // delete all versions of the file + foreach ($versions as $version) { + if ($version === $ignore) { + continue; + } - Dir::remove($version); - } + Dir::remove($version); + } - return true; - } + return true; + } } diff --git a/kirby/src/Cms/Model.php b/kirby/src/Cms/Model.php index 95b83d8..94c0317 100755 --- a/kirby/src/Cms/Model.php +++ b/kirby/src/Cms/Model.php @@ -15,103 +15,103 @@ use Kirby\Toolkit\Properties; */ abstract class Model { - use Properties; + use Properties; - /** - * Each model must define a CLASS_ALIAS - * which will be used in template queries. - * The CLASS_ALIAS is a short human-readable - * version of the class name. I.e. page. - */ - public const CLASS_ALIAS = null; + /** + * Each model must define a CLASS_ALIAS + * which will be used in template queries. + * The CLASS_ALIAS is a short human-readable + * version of the class name. I.e. page. + */ + public const CLASS_ALIAS = null; - /** - * The parent Kirby instance - * - * @var \Kirby\Cms\App - */ - public static $kirby; + /** + * The parent Kirby instance + * + * @var \Kirby\Cms\App + */ + public static $kirby; - /** - * The parent site instance - * - * @var \Kirby\Cms\Site - */ - protected $site; + /** + * The parent site instance + * + * @var \Kirby\Cms\Site + */ + protected $site; - /** - * Makes it possible to convert the entire model - * to a string. Mostly useful for debugging - * - * @return string - */ - public function __toString(): string - { - return $this->id(); - } + /** + * Makes it possible to convert the entire model + * to a string. Mostly useful for debugging + * + * @return string + */ + public function __toString(): string + { + return $this->id(); + } - /** - * Each model must return a unique id - * - * @return string|int - */ - public function id() - { - return null; - } + /** + * Each model must return a unique id + * + * @return string|int + */ + public function id() + { + return null; + } - /** - * Returns the parent Kirby instance - * - * @return \Kirby\Cms\App - */ - public function kirby() - { - return static::$kirby ??= App::instance(); - } + /** + * Returns the parent Kirby instance + * + * @return \Kirby\Cms\App + */ + public function kirby() + { + return static::$kirby ??= App::instance(); + } - /** - * Returns the parent Site instance - * - * @return \Kirby\Cms\Site - */ - public function site() - { - return $this->site ??= $this->kirby()->site(); - } + /** + * Returns the parent Site instance + * + * @return \Kirby\Cms\Site + */ + public function site() + { + return $this->site ??= $this->kirby()->site(); + } - /** - * Setter for the parent Kirby object - * - * @param \Kirby\Cms\App|null $kirby - * @return $this - */ - protected function setKirby(App $kirby = null) - { - static::$kirby = $kirby; - return $this; - } + /** + * Setter for the parent Kirby object + * + * @param \Kirby\Cms\App|null $kirby + * @return $this + */ + protected function setKirby(App $kirby = null) + { + static::$kirby = $kirby; + return $this; + } - /** - * Setter for the parent site object - * - * @internal - * @param \Kirby\Cms\Site|null $site - * @return $this - */ - public function setSite(Site $site = null) - { - $this->site = $site; - return $this; - } + /** + * Setter for the parent site object + * + * @internal + * @param \Kirby\Cms\Site|null $site + * @return $this + */ + public function setSite(Site $site = null) + { + $this->site = $site; + return $this; + } - /** - * Convert the model to a simple array - * - * @return array - */ - public function toArray(): array - { - return $this->propertiesToArray(); - } + /** + * Convert the model to a simple array + * + * @return array + */ + public function toArray(): array + { + return $this->propertiesToArray(); + } } diff --git a/kirby/src/Cms/ModelPermissions.php b/kirby/src/Cms/ModelPermissions.php index 86fcfbe..5212c4f 100755 --- a/kirby/src/Cms/ModelPermissions.php +++ b/kirby/src/Cms/ModelPermissions.php @@ -15,102 +15,102 @@ use Kirby\Toolkit\A; */ abstract class ModelPermissions { - protected $category; - protected $model; - protected $options; - protected $permissions; - protected $user; + protected $category; + protected $model; + protected $options; + protected $permissions; + protected $user; - /** - * @param string $method - * @param array $arguments - * @return bool - */ - public function __call(string $method, array $arguments = []): bool - { - return $this->can($method); - } + /** + * @param string $method + * @param array $arguments + * @return bool + */ + public function __call(string $method, array $arguments = []): bool + { + return $this->can($method); + } - /** - * ModelPermissions constructor - * - * @param \Kirby\Cms\Model $model - */ - public function __construct(Model $model) - { - $this->model = $model; - $this->options = $model->blueprint()->options(); - $this->user = $model->kirby()->user() ?? User::nobody(); - $this->permissions = $this->user->role()->permissions(); - } + /** + * ModelPermissions constructor + * + * @param \Kirby\Cms\Model $model + */ + public function __construct(Model $model) + { + $this->model = $model; + $this->options = $model->blueprint()->options(); + $this->user = $model->kirby()->user() ?? User::nobody(); + $this->permissions = $this->user->role()->permissions(); + } - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return $this->toArray(); - } + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return $this->toArray(); + } - /** - * @param string $action - * @return bool - */ - public function can(string $action): bool - { - $role = $this->user->role()->id(); + /** + * @param string $action + * @return bool + */ + public function can(string $action): bool + { + $role = $this->user->role()->id(); - if ($role === 'nobody') { - return false; - } + if ($role === 'nobody') { + return false; + } - // check for a custom overall can method - if (method_exists($this, 'can' . $action) === true && $this->{'can' . $action}() === false) { - return false; - } + // check for a custom overall can method + if (method_exists($this, 'can' . $action) === true && $this->{'can' . $action}() === false) { + return false; + } - // evaluate the blueprint options block - if (isset($this->options[$action]) === true) { - $options = $this->options[$action]; + // evaluate the blueprint options block + if (isset($this->options[$action]) === true) { + $options = $this->options[$action]; - if ($options === false) { - return false; - } + if ($options === false) { + return false; + } - if ($options === true) { - return true; - } + if ($options === true) { + return true; + } - if (is_array($options) === true && A::isAssociative($options) === true) { - return $options[$role] ?? $options['*'] ?? false; - } - } + if (is_array($options) === true && A::isAssociative($options) === true) { + return $options[$role] ?? $options['*'] ?? false; + } + } - return $this->permissions->for($this->category, $action); - } + return $this->permissions->for($this->category, $action); + } - /** - * @param string $action - * @return bool - */ - public function cannot(string $action): bool - { - return $this->can($action) === false; - } + /** + * @param string $action + * @return bool + */ + public function cannot(string $action): bool + { + return $this->can($action) === false; + } - /** - * @return array - */ - public function toArray(): array - { - $array = []; + /** + * @return array + */ + public function toArray(): array + { + $array = []; - foreach ($this->options as $key => $value) { - $array[$key] = $this->can($key); - } + foreach ($this->options as $key => $value) { + $array[$key] = $this->can($key); + } - return $array; - } + return $array; + } } diff --git a/kirby/src/Cms/ModelWithContent.php b/kirby/src/Cms/ModelWithContent.php index 8dfe878..796eb17 100755 --- a/kirby/src/Cms/ModelWithContent.php +++ b/kirby/src/Cms/ModelWithContent.php @@ -20,684 +20,684 @@ use Throwable; */ abstract class ModelWithContent extends Model { - /** - * The content - * - * @var \Kirby\Cms\Content - */ - public $content; - - /** - * @var \Kirby\Cms\Translations - */ - public $translations; - - /** - * Returns the blueprint of the model - * - * @return \Kirby\Cms\Blueprint - */ - abstract public function blueprint(); - - /** - * Returns an array with all blueprints that are available - * - * @param string|null $inSection - * @return array - */ - public function blueprints(string $inSection = null): array - { - $blueprints = []; - $blueprint = $this->blueprint(); - $sections = $inSection !== null ? [$blueprint->section($inSection)] : $blueprint->sections(); - - foreach ($sections as $section) { - if ($section === null) { - continue; - } - - foreach ((array)$section->blueprints() as $blueprint) { - $blueprints[$blueprint['name']] = $blueprint; - } - } - - return array_values($blueprints); - } - - /** - * Executes any given model action - * - * @param string $action - * @param array $arguments - * @param \Closure $callback - * @return mixed - */ - abstract protected function commit(string $action, array $arguments, Closure $callback); - - /** - * Returns the content - * - * @param string|null $languageCode - * @return \Kirby\Cms\Content - * @throws \Kirby\Exception\InvalidArgumentException If the language for the given code does not exist - */ - public function content(string $languageCode = null) - { - - // single language support - if ($this->kirby()->multilang() === false) { - if (is_a($this->content, 'Kirby\Cms\Content') === true) { - return $this->content; - } - - // don't normalize field keys (already handled by the `Data` class) - return $this->content = new Content($this->readContent(), $this, false); - - // multi language support - } else { - - // only fetch from cache for the default language - if ($languageCode === null && is_a($this->content, 'Kirby\Cms\Content') === true) { - return $this->content; - } - - // get the translation by code - if ($translation = $this->translation($languageCode)) { - // don't normalize field keys (already handled by the `ContentTranslation` class) - $content = new Content($translation->content(), $this, false); - } else { - throw new InvalidArgumentException('Invalid language: ' . $languageCode); - } - - // only store the content for the current language - if ($languageCode === null) { - $this->content = $content; - } - - return $content; - } - } - - /** - * Returns the absolute path to the content file - * - * @internal - * @param string|null $languageCode - * @param bool $force - * @return string - * @throws \Kirby\Exception\InvalidArgumentException If the language for the given code does not exist - */ - public function contentFile(string $languageCode = null, bool $force = false): string - { - $extension = $this->contentFileExtension(); - $directory = $this->contentFileDirectory(); - $filename = $this->contentFileName(); - - // overwrite the language code - if ($force === true) { - if (empty($languageCode) === false) { - return $directory . '/' . $filename . '.' . $languageCode . '.' . $extension; - } else { - return $directory . '/' . $filename . '.' . $extension; - } - } - - // add and validate the language code in multi language mode - if ($this->kirby()->multilang() === true) { - if ($language = $this->kirby()->languageCode($languageCode)) { - return $directory . '/' . $filename . '.' . $language . '.' . $extension; - } else { - throw new InvalidArgumentException('Invalid language: ' . $languageCode); - } - } else { - return $directory . '/' . $filename . '.' . $extension; - } - } - - /** - * Returns an array with all content files - * - * @return array - */ - public function contentFiles(): array - { - if ($this->kirby()->multilang() === true) { - $files = []; - foreach ($this->kirby()->languages()->codes() as $code) { - $files[] = $this->contentFile($code); - } - return $files; - } else { - return [ - $this->contentFile() - ]; - } - } - - /** - * Prepares the content that should be written - * to the text file - * - * @internal - * @param array $data - * @param string|null $languageCode - * @return array - */ - public function contentFileData(array $data, string $languageCode = null): array - { - return $data; - } - - /** - * Returns the absolute path to the - * folder in which the content file is - * located - * - * @internal - * @return string|null - */ - public function contentFileDirectory(): ?string - { - return $this->root(); - } - - /** - * Returns the extension of the content file - * - * @internal - * @return string - */ - public function contentFileExtension(): string - { - return $this->kirby()->contentExtension(); - } - - /** - * Needs to be declared by the final model - * - * @internal - * @return string - */ - abstract public function contentFileName(): string; - - /** - * Decrement a given field value - * - * @param string $field - * @param int $by - * @param int $min - * @return static - */ - public function decrement(string $field, int $by = 1, int $min = 0) - { - $value = (int)$this->content()->get($field)->value() - $by; - - if ($value < $min) { - $value = $min; - } - - return $this->update([$field => $value]); - } - - /** - * Returns all content validation errors - * - * @return array - */ - public function errors(): array - { - $errors = []; - - foreach ($this->blueprint()->sections() as $section) { - $errors = array_merge($errors, $section->errors()); - } - - return $errors; - } - - /** - * Increment a given field value - * - * @param string $field - * @param int $by - * @param int|null $max - * @return static - */ - public function increment(string $field, int $by = 1, int $max = null) - { - $value = (int)$this->content()->get($field)->value() + $by; - - if ($max && $value > $max) { - $value = $max; - } - - return $this->update([$field => $value]); - } - - /** - * Checks if the model is locked for the current user - * - * @return bool - */ - public function isLocked(): bool - { - $lock = $this->lock(); - return $lock && $lock->isLocked() === true; - } - - /** - * Checks if the data has any errors - * - * @return bool - */ - public function isValid(): bool - { - return Form::for($this)->hasErrors() === false; - } - - /** - * Returns the lock object for this model - * - * Only if a content directory exists, - * virtual pages will need to overwrite this method - * - * @return \Kirby\Cms\ContentLock|null - */ - public function lock() - { - $dir = $this->contentFileDirectory(); - - if ( - $this->kirby()->option('content.locking', true) && - is_string($dir) === true && - file_exists($dir) === true - ) { - return new ContentLock($this); - } - } - - /** - * Returns the panel info of the model - * @since 3.6.0 - * - * @return \Kirby\Panel\Model - */ - abstract public function panel(); - - /** - * Must return the permissions object for the model - * - * @return \Kirby\Cms\ModelPermissions - */ - abstract public function permissions(); - - /** - * Creates a string query, starting from the model - * - * @internal - * @param string|null $query - * @param string|null $expect - * @return mixed - */ - public function query(string $query = null, string $expect = null) - { - if ($query === null) { - return null; - } - - try { - $result = Str::query($query, [ - 'kirby' => $this->kirby(), - 'site' => is_a($this, 'Kirby\Cms\Site') ? $this : $this->site(), - 'model' => $this, - static::CLASS_ALIAS => $this - ]); - } catch (Throwable $e) { - return null; - } - - if ($expect !== null && is_a($result, $expect) !== true) { - return null; - } - - return $result; - } - - /** - * Read the content from the content file - * - * @internal - * @param string|null $languageCode - * @return array - */ - public function readContent(string $languageCode = null): array - { - try { - return Data::read($this->contentFile($languageCode)); - } catch (Throwable $e) { - return []; - } - } - - /** - * Returns the absolute path to the model - * - * @return string|null - */ - abstract public function root(): ?string; - - /** - * Stores the content on disk - * - * @internal - * @param array|null $data - * @param string|null $languageCode - * @param bool $overwrite - * @return static - */ - public function save(array $data = null, string $languageCode = null, bool $overwrite = false) - { - if ($this->kirby()->multilang() === true) { - return $this->saveTranslation($data, $languageCode, $overwrite); - } else { - return $this->saveContent($data, $overwrite); - } - } - - /** - * Save the single language content - * - * @param array|null $data - * @param bool $overwrite - * @return static - */ - protected function saveContent(array $data = null, bool $overwrite = false) - { - // create a clone to avoid modifying the original - $clone = $this->clone(); - - // merge the new data with the existing content - $clone->content()->update($data, $overwrite); - - // send the full content array to the writer - $clone->writeContent($clone->content()->toArray()); - - return $clone; - } - - /** - * Save a translation - * - * @param array|null $data - * @param string|null $languageCode - * @param bool $overwrite - * @return static - * @throws \Kirby\Exception\InvalidArgumentException If the language for the given code does not exist - */ - protected function saveTranslation(array $data = null, string $languageCode = null, bool $overwrite = false) - { - // create a clone to not touch the original - $clone = $this->clone(); - - // fetch the matching translation and update all the strings - $translation = $clone->translation($languageCode); - - if ($translation === null) { - throw new InvalidArgumentException('Invalid language: ' . $languageCode); - } - - // get the content to store - $content = $translation->update($data, $overwrite)->content(); - $kirby = $this->kirby(); - $languageCode = $kirby->languageCode($languageCode); - - // remove all untranslatable fields - if ($languageCode !== $kirby->defaultLanguage()->code()) { - foreach ($this->blueprint()->fields() as $field) { - if (($field['translate'] ?? true) === false) { - $content[strtolower($field['name'])] = null; - } - } - - // merge the translation with the new data - $translation->update($content, true); - } - - // send the full translation array to the writer - $clone->writeContent($translation->content(), $languageCode); - - // reset the content object - $clone->content = null; - - // return the updated model - return $clone; - } - - /** - * Sets the Content object - * - * @param array|null $content - * @return $this - */ - protected function setContent(array $content = null) - { - if ($content !== null) { - $content = new Content($content, $this); - } - - $this->content = $content; - return $this; - } - - /** - * Create the translations collection from an array - * - * @param array|null $translations - * @return $this - */ - protected function setTranslations(array $translations = null) - { - if ($translations !== null) { - $this->translations = new Collection(); - - foreach ($translations as $props) { - $props['parent'] = $this; - $translation = new ContentTranslation($props); - $this->translations->data[$translation->code()] = $translation; - } - } - - return $this; - } - - /** - * String template builder with automatic HTML escaping - * @since 3.6.0 - * - * @param string|null $template Template string or `null` to use the model ID - * @param array $data - * @param string $fallback Fallback for tokens in the template that cannot be replaced - * @return string - */ - public function toSafeString(string $template = null, array $data = [], string $fallback = ''): string - { - return $this->toString($template, $data, $fallback, 'safeTemplate'); - } - - /** - * String template builder - * - * @param string|null $template Template string or `null` to use the model ID - * @param array $data - * @param string $fallback Fallback for tokens in the template that cannot be replaced - * @param string $handler For internal use - * @return string - */ - public function toString(string $template = null, array $data = [], string $fallback = '', string $handler = 'template'): string - { - if ($template === null) { - return $this->id() ?? ''; - } - - if ($handler !== 'template' && $handler !== 'safeTemplate') { - throw new InvalidArgumentException('Invalid toString handler'); // @codeCoverageIgnore - } - - $result = Str::$handler($template, array_replace([ - 'kirby' => $this->kirby(), - 'site' => is_a($this, 'Kirby\Cms\Site') ? $this : $this->site(), - 'model' => $this, - static::CLASS_ALIAS => $this, - ], $data), ['fallback' => $fallback]); - - return $result; - } - - /** - * Returns a single translation by language code - * If no code is specified the current translation is returned - * - * @param string|null $languageCode - * @return \Kirby\Cms\ContentTranslation|null - */ - public function translation(string $languageCode = null) - { - return $this->translations()->find($languageCode ?? $this->kirby()->language()->code()); - } - - /** - * Returns the translations collection - * - * @return \Kirby\Cms\Collection - */ - public function translations() - { - if ($this->translations !== null) { - return $this->translations; - } - - $this->translations = new Collection(); - - foreach ($this->kirby()->languages() as $language) { - $translation = new ContentTranslation([ - 'parent' => $this, - 'code' => $language->code(), - ]); - - $this->translations->data[$translation->code()] = $translation; - } - - return $this->translations; - } - - /** - * Updates the model data - * - * @param array|null $input - * @param string|null $languageCode - * @param bool $validate - * @return static - * @throws \Kirby\Exception\InvalidArgumentException If the input array contains invalid values - */ - public function update(array $input = null, string $languageCode = null, bool $validate = false) - { - $form = Form::for($this, [ - 'ignoreDisabled' => $validate === false, - 'input' => $input, - 'language' => $languageCode, - ]); - - // validate the input - if ($validate === true) { - if ($form->isInvalid() === true) { - throw new InvalidArgumentException([ - 'fallback' => 'Invalid form with errors', - 'details' => $form->errors() - ]); - } - } - - $arguments = [static::CLASS_ALIAS => $this, 'values' => $form->data(), 'strings' => $form->strings(), 'languageCode' => $languageCode]; - return $this->commit('update', $arguments, function ($model, $values, $strings, $languageCode) { - // save updated values - $model = $model->save($strings, $languageCode, true); - - // update model in siblings collection - $model->siblings()->add($model); - - return $model; - }); - } - - /** - * Low level data writer method - * to store the given data on disk or anywhere else - * - * @internal - * @param array $data - * @param string|null $languageCode - * @return bool - */ - public function writeContent(array $data, string $languageCode = null): bool - { - return Data::write( - $this->contentFile($languageCode), - $this->contentFileData($data, $languageCode) - ); - } - - - /** - * Deprecated! - */ - - /** - * Returns the panel icon definition - * - * @deprecated 3.6.0 Use `->panel()->image()` instead - * @todo Remove in 3.8.0 - * - * @internal - * @param array|null $params - * @return array|null - * @codeCoverageIgnore - */ - public function panelIcon(array $params = null): ?array - { - Helpers::deprecated('Cms\ModelWithContent::panelIcon() has been deprecated and will be removed in Kirby 3.8.0. Use $model->panel()->image() instead.'); - return $this->panel()->image($params); - } - - /** - * @deprecated 3.6.0 Use `->panel()->image()` instead - * @todo Remove in 3.8.0 - * - * @internal - * @param string|array|false|null $settings - * @return array|null - * @codeCoverageIgnore - */ - public function panelImage($settings = null): ?array - { - Helpers::deprecated('Cms\ModelWithContent::panelImage() has been deprecated and will be removed in Kirby 3.8.0. Use $model->panel()->image() instead.'); - return $this->panel()->image($settings); - } - - /** - * Returns an array of all actions - * that can be performed in the Panel - * This also checks for the lock status - * - * @deprecated 3.6.0 Use `->panel()->options()` instead - * @todo Remove in 3.8.0 - * - * @param array $unlock An array of options that will be force-unlocked - * @return array - * @codeCoverageIgnore - */ - public function panelOptions(array $unlock = []): array - { - Helpers::deprecated('Cms\ModelWithContent::panelOptions() has been deprecated and will be removed in Kirby 3.8.0. Use $model->panel()->options() instead.'); - return $this->panel()->options($unlock); - } + /** + * The content + * + * @var \Kirby\Cms\Content + */ + public $content; + + /** + * @var \Kirby\Cms\Translations + */ + public $translations; + + /** + * Returns the blueprint of the model + * + * @return \Kirby\Cms\Blueprint + */ + abstract public function blueprint(); + + /** + * Returns an array with all blueprints that are available + * + * @param string|null $inSection + * @return array + */ + public function blueprints(string $inSection = null): array + { + $blueprints = []; + $blueprint = $this->blueprint(); + $sections = $inSection !== null ? [$blueprint->section($inSection)] : $blueprint->sections(); + + foreach ($sections as $section) { + if ($section === null) { + continue; + } + + foreach ((array)$section->blueprints() as $blueprint) { + $blueprints[$blueprint['name']] = $blueprint; + } + } + + return array_values($blueprints); + } + + /** + * Executes any given model action + * + * @param string $action + * @param array $arguments + * @param \Closure $callback + * @return mixed + */ + abstract protected function commit(string $action, array $arguments, Closure $callback); + + /** + * Returns the content + * + * @param string|null $languageCode + * @return \Kirby\Cms\Content + * @throws \Kirby\Exception\InvalidArgumentException If the language for the given code does not exist + */ + public function content(string $languageCode = null) + { + + // single language support + if ($this->kirby()->multilang() === false) { + if (is_a($this->content, 'Kirby\Cms\Content') === true) { + return $this->content; + } + + // don't normalize field keys (already handled by the `Data` class) + return $this->content = new Content($this->readContent(), $this, false); + + // multi language support + } else { + + // only fetch from cache for the default language + if ($languageCode === null && is_a($this->content, 'Kirby\Cms\Content') === true) { + return $this->content; + } + + // get the translation by code + if ($translation = $this->translation($languageCode)) { + // don't normalize field keys (already handled by the `ContentTranslation` class) + $content = new Content($translation->content(), $this, false); + } else { + throw new InvalidArgumentException('Invalid language: ' . $languageCode); + } + + // only store the content for the current language + if ($languageCode === null) { + $this->content = $content; + } + + return $content; + } + } + + /** + * Returns the absolute path to the content file + * + * @internal + * @param string|null $languageCode + * @param bool $force + * @return string + * @throws \Kirby\Exception\InvalidArgumentException If the language for the given code does not exist + */ + public function contentFile(string $languageCode = null, bool $force = false): string + { + $extension = $this->contentFileExtension(); + $directory = $this->contentFileDirectory(); + $filename = $this->contentFileName(); + + // overwrite the language code + if ($force === true) { + if (empty($languageCode) === false) { + return $directory . '/' . $filename . '.' . $languageCode . '.' . $extension; + } else { + return $directory . '/' . $filename . '.' . $extension; + } + } + + // add and validate the language code in multi language mode + if ($this->kirby()->multilang() === true) { + if ($language = $this->kirby()->languageCode($languageCode)) { + return $directory . '/' . $filename . '.' . $language . '.' . $extension; + } else { + throw new InvalidArgumentException('Invalid language: ' . $languageCode); + } + } else { + return $directory . '/' . $filename . '.' . $extension; + } + } + + /** + * Returns an array with all content files + * + * @return array + */ + public function contentFiles(): array + { + if ($this->kirby()->multilang() === true) { + $files = []; + foreach ($this->kirby()->languages()->codes() as $code) { + $files[] = $this->contentFile($code); + } + return $files; + } else { + return [ + $this->contentFile() + ]; + } + } + + /** + * Prepares the content that should be written + * to the text file + * + * @internal + * @param array $data + * @param string|null $languageCode + * @return array + */ + public function contentFileData(array $data, string $languageCode = null): array + { + return $data; + } + + /** + * Returns the absolute path to the + * folder in which the content file is + * located + * + * @internal + * @return string|null + */ + public function contentFileDirectory(): ?string + { + return $this->root(); + } + + /** + * Returns the extension of the content file + * + * @internal + * @return string + */ + public function contentFileExtension(): string + { + return $this->kirby()->contentExtension(); + } + + /** + * Needs to be declared by the final model + * + * @internal + * @return string + */ + abstract public function contentFileName(): string; + + /** + * Decrement a given field value + * + * @param string $field + * @param int $by + * @param int $min + * @return static + */ + public function decrement(string $field, int $by = 1, int $min = 0) + { + $value = (int)$this->content()->get($field)->value() - $by; + + if ($value < $min) { + $value = $min; + } + + return $this->update([$field => $value]); + } + + /** + * Returns all content validation errors + * + * @return array + */ + public function errors(): array + { + $errors = []; + + foreach ($this->blueprint()->sections() as $section) { + $errors = array_merge($errors, $section->errors()); + } + + return $errors; + } + + /** + * Increment a given field value + * + * @param string $field + * @param int $by + * @param int|null $max + * @return static + */ + public function increment(string $field, int $by = 1, int $max = null) + { + $value = (int)$this->content()->get($field)->value() + $by; + + if ($max && $value > $max) { + $value = $max; + } + + return $this->update([$field => $value]); + } + + /** + * Checks if the model is locked for the current user + * + * @return bool + */ + public function isLocked(): bool + { + $lock = $this->lock(); + return $lock && $lock->isLocked() === true; + } + + /** + * Checks if the data has any errors + * + * @return bool + */ + public function isValid(): bool + { + return Form::for($this)->hasErrors() === false; + } + + /** + * Returns the lock object for this model + * + * Only if a content directory exists, + * virtual pages will need to overwrite this method + * + * @return \Kirby\Cms\ContentLock|null + */ + public function lock() + { + $dir = $this->contentFileDirectory(); + + if ( + $this->kirby()->option('content.locking', true) && + is_string($dir) === true && + file_exists($dir) === true + ) { + return new ContentLock($this); + } + } + + /** + * Returns the panel info of the model + * @since 3.6.0 + * + * @return \Kirby\Panel\Model + */ + abstract public function panel(); + + /** + * Must return the permissions object for the model + * + * @return \Kirby\Cms\ModelPermissions + */ + abstract public function permissions(); + + /** + * Creates a string query, starting from the model + * + * @internal + * @param string|null $query + * @param string|null $expect + * @return mixed + */ + public function query(string $query = null, string $expect = null) + { + if ($query === null) { + return null; + } + + try { + $result = Str::query($query, [ + 'kirby' => $this->kirby(), + 'site' => is_a($this, 'Kirby\Cms\Site') ? $this : $this->site(), + 'model' => $this, + static::CLASS_ALIAS => $this + ]); + } catch (Throwable $e) { + return null; + } + + if ($expect !== null && is_a($result, $expect) !== true) { + return null; + } + + return $result; + } + + /** + * Read the content from the content file + * + * @internal + * @param string|null $languageCode + * @return array + */ + public function readContent(string $languageCode = null): array + { + try { + return Data::read($this->contentFile($languageCode)); + } catch (Throwable $e) { + return []; + } + } + + /** + * Returns the absolute path to the model + * + * @return string|null + */ + abstract public function root(): ?string; + + /** + * Stores the content on disk + * + * @internal + * @param array|null $data + * @param string|null $languageCode + * @param bool $overwrite + * @return static + */ + public function save(array $data = null, string $languageCode = null, bool $overwrite = false) + { + if ($this->kirby()->multilang() === true) { + return $this->saveTranslation($data, $languageCode, $overwrite); + } else { + return $this->saveContent($data, $overwrite); + } + } + + /** + * Save the single language content + * + * @param array|null $data + * @param bool $overwrite + * @return static + */ + protected function saveContent(array $data = null, bool $overwrite = false) + { + // create a clone to avoid modifying the original + $clone = $this->clone(); + + // merge the new data with the existing content + $clone->content()->update($data, $overwrite); + + // send the full content array to the writer + $clone->writeContent($clone->content()->toArray()); + + return $clone; + } + + /** + * Save a translation + * + * @param array|null $data + * @param string|null $languageCode + * @param bool $overwrite + * @return static + * @throws \Kirby\Exception\InvalidArgumentException If the language for the given code does not exist + */ + protected function saveTranslation(array $data = null, string $languageCode = null, bool $overwrite = false) + { + // create a clone to not touch the original + $clone = $this->clone(); + + // fetch the matching translation and update all the strings + $translation = $clone->translation($languageCode); + + if ($translation === null) { + throw new InvalidArgumentException('Invalid language: ' . $languageCode); + } + + // get the content to store + $content = $translation->update($data, $overwrite)->content(); + $kirby = $this->kirby(); + $languageCode = $kirby->languageCode($languageCode); + + // remove all untranslatable fields + if ($languageCode !== $kirby->defaultLanguage()->code()) { + foreach ($this->blueprint()->fields() as $field) { + if (($field['translate'] ?? true) === false) { + $content[strtolower($field['name'])] = null; + } + } + + // merge the translation with the new data + $translation->update($content, true); + } + + // send the full translation array to the writer + $clone->writeContent($translation->content(), $languageCode); + + // reset the content object + $clone->content = null; + + // return the updated model + return $clone; + } + + /** + * Sets the Content object + * + * @param array|null $content + * @return $this + */ + protected function setContent(array $content = null) + { + if ($content !== null) { + $content = new Content($content, $this); + } + + $this->content = $content; + return $this; + } + + /** + * Create the translations collection from an array + * + * @param array|null $translations + * @return $this + */ + protected function setTranslations(array $translations = null) + { + if ($translations !== null) { + $this->translations = new Collection(); + + foreach ($translations as $props) { + $props['parent'] = $this; + $translation = new ContentTranslation($props); + $this->translations->data[$translation->code()] = $translation; + } + } + + return $this; + } + + /** + * String template builder with automatic HTML escaping + * @since 3.6.0 + * + * @param string|null $template Template string or `null` to use the model ID + * @param array $data + * @param string $fallback Fallback for tokens in the template that cannot be replaced + * @return string + */ + public function toSafeString(string $template = null, array $data = [], string $fallback = ''): string + { + return $this->toString($template, $data, $fallback, 'safeTemplate'); + } + + /** + * String template builder + * + * @param string|null $template Template string or `null` to use the model ID + * @param array $data + * @param string $fallback Fallback for tokens in the template that cannot be replaced + * @param string $handler For internal use + * @return string + */ + public function toString(string $template = null, array $data = [], string $fallback = '', string $handler = 'template'): string + { + if ($template === null) { + return $this->id() ?? ''; + } + + if ($handler !== 'template' && $handler !== 'safeTemplate') { + throw new InvalidArgumentException('Invalid toString handler'); // @codeCoverageIgnore + } + + $result = Str::$handler($template, array_replace([ + 'kirby' => $this->kirby(), + 'site' => is_a($this, 'Kirby\Cms\Site') ? $this : $this->site(), + 'model' => $this, + static::CLASS_ALIAS => $this, + ], $data), ['fallback' => $fallback]); + + return $result; + } + + /** + * Returns a single translation by language code + * If no code is specified the current translation is returned + * + * @param string|null $languageCode + * @return \Kirby\Cms\ContentTranslation|null + */ + public function translation(string $languageCode = null) + { + return $this->translations()->find($languageCode ?? $this->kirby()->language()->code()); + } + + /** + * Returns the translations collection + * + * @return \Kirby\Cms\Collection + */ + public function translations() + { + if ($this->translations !== null) { + return $this->translations; + } + + $this->translations = new Collection(); + + foreach ($this->kirby()->languages() as $language) { + $translation = new ContentTranslation([ + 'parent' => $this, + 'code' => $language->code(), + ]); + + $this->translations->data[$translation->code()] = $translation; + } + + return $this->translations; + } + + /** + * Updates the model data + * + * @param array|null $input + * @param string|null $languageCode + * @param bool $validate + * @return static + * @throws \Kirby\Exception\InvalidArgumentException If the input array contains invalid values + */ + public function update(array $input = null, string $languageCode = null, bool $validate = false) + { + $form = Form::for($this, [ + 'ignoreDisabled' => $validate === false, + 'input' => $input, + 'language' => $languageCode, + ]); + + // validate the input + if ($validate === true) { + if ($form->isInvalid() === true) { + throw new InvalidArgumentException([ + 'fallback' => 'Invalid form with errors', + 'details' => $form->errors() + ]); + } + } + + $arguments = [static::CLASS_ALIAS => $this, 'values' => $form->data(), 'strings' => $form->strings(), 'languageCode' => $languageCode]; + return $this->commit('update', $arguments, function ($model, $values, $strings, $languageCode) { + // save updated values + $model = $model->save($strings, $languageCode, true); + + // update model in siblings collection + $model->siblings()->add($model); + + return $model; + }); + } + + /** + * Low level data writer method + * to store the given data on disk or anywhere else + * + * @internal + * @param array $data + * @param string|null $languageCode + * @return bool + */ + public function writeContent(array $data, string $languageCode = null): bool + { + return Data::write( + $this->contentFile($languageCode), + $this->contentFileData($data, $languageCode) + ); + } + + + /** + * Deprecated! + */ + + /** + * Returns the panel icon definition + * + * @deprecated 3.6.0 Use `->panel()->image()` instead + * @todo Remove in 3.8.0 + * + * @internal + * @param array|null $params + * @return array|null + * @codeCoverageIgnore + */ + public function panelIcon(array $params = null): ?array + { + Helpers::deprecated('Cms\ModelWithContent::panelIcon() has been deprecated and will be removed in Kirby 3.8.0. Use $model->panel()->image() instead.'); + return $this->panel()->image($params); + } + + /** + * @deprecated 3.6.0 Use `->panel()->image()` instead + * @todo Remove in 3.8.0 + * + * @internal + * @param string|array|false|null $settings + * @return array|null + * @codeCoverageIgnore + */ + public function panelImage($settings = null): ?array + { + Helpers::deprecated('Cms\ModelWithContent::panelImage() has been deprecated and will be removed in Kirby 3.8.0. Use $model->panel()->image() instead.'); + return $this->panel()->image($settings); + } + + /** + * Returns an array of all actions + * that can be performed in the Panel + * This also checks for the lock status + * + * @deprecated 3.6.0 Use `->panel()->options()` instead + * @todo Remove in 3.8.0 + * + * @param array $unlock An array of options that will be force-unlocked + * @return array + * @codeCoverageIgnore + */ + public function panelOptions(array $unlock = []): array + { + Helpers::deprecated('Cms\ModelWithContent::panelOptions() has been deprecated and will be removed in Kirby 3.8.0. Use $model->panel()->options() instead.'); + return $this->panel()->options($unlock); + } } diff --git a/kirby/src/Cms/Nest.php b/kirby/src/Cms/Nest.php index bbaf810..56455b3 100755 --- a/kirby/src/Cms/Nest.php +++ b/kirby/src/Cms/Nest.php @@ -18,31 +18,31 @@ namespace Kirby\Cms; */ class Nest { - /** - * @param $data - * @param null $parent - * @return mixed - */ - public static function create($data, $parent = null) - { - if (is_scalar($data) === true) { - return new Field($parent, $data, $data); - } + /** + * @param $data + * @param null $parent + * @return mixed + */ + public static function create($data, $parent = null) + { + if (is_scalar($data) === true) { + return new Field($parent, $data, $data); + } - $result = []; + $result = []; - foreach ($data as $key => $value) { - if (is_array($value) === true) { - $result[$key] = static::create($value, $parent); - } elseif (is_scalar($value) === true) { - $result[$key] = new Field($parent, $key, $value); - } - } + foreach ($data as $key => $value) { + if (is_array($value) === true) { + $result[$key] = static::create($value, $parent); + } elseif (is_scalar($value) === true) { + $result[$key] = new Field($parent, $key, $value); + } + } - if (is_int(key($data))) { - return new NestCollection($result); - } else { - return new NestObject($result); - } - } + if (is_int(key($data))) { + return new NestCollection($result); + } else { + return new NestObject($result); + } + } } diff --git a/kirby/src/Cms/NestCollection.php b/kirby/src/Cms/NestCollection.php index e3857b0..b5b1a7b 100755 --- a/kirby/src/Cms/NestCollection.php +++ b/kirby/src/Cms/NestCollection.php @@ -16,16 +16,16 @@ use Kirby\Toolkit\Collection as BaseCollection; */ class NestCollection extends BaseCollection { - /** - * Converts all objects in the collection - * to an array. This can also take a callback - * function to further modify the array result. - * - * @param \Closure|null $map - * @return array - */ - public function toArray(Closure $map = null): array - { - return parent::toArray($map ?? fn ($object) => $object->toArray()); - } + /** + * Converts all objects in the collection + * to an array. This can also take a callback + * function to further modify the array result. + * + * @param \Closure|null $map + * @return array + */ + public function toArray(Closure $map = null): array + { + return parent::toArray($map ?? fn ($object) => $object->toArray()); + } } diff --git a/kirby/src/Cms/NestObject.php b/kirby/src/Cms/NestObject.php index 026be2c..4744539 100755 --- a/kirby/src/Cms/NestObject.php +++ b/kirby/src/Cms/NestObject.php @@ -15,29 +15,29 @@ use Kirby\Toolkit\Obj; */ class NestObject extends Obj { - /** - * Converts the object to an array - * - * @return array - */ - public function toArray(): array - { - $result = []; + /** + * Converts the object to an array + * + * @return array + */ + public function toArray(): array + { + $result = []; - foreach ((array)$this as $key => $value) { - if (is_a($value, 'Kirby\Cms\Field') === true) { - $result[$key] = $value->value(); - continue; - } + foreach ((array)$this as $key => $value) { + if (is_a($value, 'Kirby\Cms\Field') === true) { + $result[$key] = $value->value(); + continue; + } - if (is_object($value) === true && method_exists($value, 'toArray')) { - $result[$key] = $value->toArray(); - continue; - } + if (is_object($value) === true && method_exists($value, 'toArray')) { + $result[$key] = $value->toArray(); + continue; + } - $result[$key] = $value; - } + $result[$key] = $value; + } - return $result; - } + return $result; + } } diff --git a/kirby/src/Cms/Page.php b/kirby/src/Cms/Page.php index 7157bb0..88c95cd 100755 --- a/kirby/src/Cms/Page.php +++ b/kirby/src/Cms/Page.php @@ -26,1538 +26,1538 @@ use Kirby\Toolkit\A; */ class Page extends ModelWithContent { - use PageActions; - use PageSiblings; - use HasChildren; - use HasFiles; - use HasMethods; - use HasSiblings; - - public const CLASS_ALIAS = 'page'; - - /** - * All registered page methods - * - * @var array - */ - public static $methods = []; - - /** - * Registry with all Page models - * - * @var array - */ - public static $models = []; - - /** - * The PageBlueprint object - * - * @var \Kirby\Cms\PageBlueprint - */ - protected $blueprint; - - /** - * Nesting level - * - * @var int - */ - protected $depth; - - /** - * Sorting number + slug - * - * @var string - */ - protected $dirname; - - /** - * Path of dirnames - * - * @var string - */ - protected $diruri; - - /** - * Draft status flag - * - * @var bool - */ - protected $isDraft; - - /** - * The Page id - * - * @var string - */ - protected $id; - - /** - * The template, that should be loaded - * if it exists - * - * @var \Kirby\Cms\Template - */ - protected $intendedTemplate; - - /** - * @var array - */ - protected $inventory; - - /** - * The sorting number - * - * @var int|null - */ - protected $num; - - /** - * The parent page - * - * @var \Kirby\Cms\Page|null - */ - protected $parent; - - /** - * Absolute path to the page directory - * - * @var string - */ - protected $root; - - /** - * The parent Site object - * - * @var \Kirby\Cms\Site|null - */ - protected $site; - - /** - * The URL-appendix aka slug - * - * @var string - */ - protected $slug; - - /** - * The intended page template - * - * @var \Kirby\Cms\Template - */ - protected $template; - - /** - * The page url - * - * @var string|null - */ - protected $url; - - /** - * Magic caller - * - * @param string $method - * @param array $arguments - * @return mixed - */ - public function __call(string $method, array $arguments = []) - { - // public property access - if (isset($this->$method) === true) { - return $this->$method; - } - - // page methods - if ($this->hasMethod($method)) { - return $this->callMethod($method, $arguments); - } - - // return page content otherwise - return $this->content()->get($method); - } - - /** - * Creates a new page object - * - * @param array $props - */ - public function __construct(array $props) - { - // set the slug as the first property - $this->slug = $props['slug'] ?? null; - - // add all other properties - $this->setProperties($props); - } - - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return array_merge($this->toArray(), [ - 'content' => $this->content(), - 'children' => $this->children(), - 'siblings' => $this->siblings(), - 'translations' => $this->translations(), - 'files' => $this->files(), - ]); - } - - /** - * Returns the url to the api endpoint - * - * @internal - * @param bool $relative - * @return string - */ - public function apiUrl(bool $relative = false): string - { - if ($relative === true) { - return 'pages/' . $this->panel()->id(); - } else { - return $this->kirby()->url('api') . '/pages/' . $this->panel()->id(); - } - } - - /** - * Returns the blueprint object - * - * @return \Kirby\Cms\PageBlueprint - */ - public function blueprint() - { - if (is_a($this->blueprint, 'Kirby\Cms\PageBlueprint') === true) { - return $this->blueprint; - } - - return $this->blueprint = PageBlueprint::factory('pages/' . $this->intendedTemplate(), 'pages/default', $this); - } - - /** - * Returns an array with all blueprints that are available for the page - * - * @param string|null $inSection - * @return array - */ - public function blueprints(?string $inSection = null): array - { - if ($inSection !== null) { - return $this->blueprint()->section($inSection)->blueprints(); - } - - $blueprints = []; - $templates = $this->blueprint()->changeTemplate() ?? $this->blueprint()->options()['changeTemplate'] ?? []; - $currentTemplate = $this->intendedTemplate()->name(); - - if (is_array($templates) === false) { - $templates = []; - } - - // add the current template to the array if it's not already there - if (in_array($currentTemplate, $templates) === false) { - array_unshift($templates, $currentTemplate); - } - - // make sure every template is only included once - $templates = array_unique($templates); - - foreach ($templates as $template) { - try { - $props = Blueprint::load('pages/' . $template); - - $blueprints[] = [ - 'name' => basename($props['name']), - 'title' => $props['title'], - ]; - } catch (Exception $e) { - // skip invalid blueprints - } - } - - return array_values($blueprints); - } - - /** - * Builds the cache id for the page - * - * @param string $contentType - * @return string - */ - protected function cacheId(string $contentType): string - { - $cacheId = [$this->id()]; - - if ($this->kirby()->multilang() === true) { - $cacheId[] = $this->kirby()->language()->code(); - } - - $cacheId[] = $contentType; - - return implode('.', $cacheId); - } - - /** - * Prepares the content for the write method - * - * @internal - * @param array $data - * @param string|null $languageCode - * @return array - */ - public function contentFileData(array $data, ?string $languageCode = null): array - { - return A::prepend($data, [ - 'title' => $data['title'] ?? null, - 'slug' => $data['slug'] ?? null - ]); - } - - /** - * Returns the content text file - * which is found by the inventory method - * - * @internal - * @param string|null $languageCode - * @return string - */ - public function contentFileName(?string $languageCode = null): string - { - return $this->intendedTemplate()->name(); - } - - /** - * Call the page controller - * - * @internal - * @param array $data - * @param string $contentType - * @return array - * @throws \Kirby\Exception\InvalidArgumentException If the controller returns invalid objects for `kirby`, `site`, `pages` or `page` - */ - public function controller(array $data = [], string $contentType = 'html'): array - { - // create the template data - $data = array_merge($data, [ - 'kirby' => $kirby = $this->kirby(), - 'site' => $site = $this->site(), - 'pages' => $site->children(), - 'page' => $site->visit($this) - ]); - - // call the template controller if there's one. - $controllerData = $kirby->controller($this->template()->name(), $data, $contentType); - - // merge controller data with original data safely - if (empty($controllerData) === false) { - $classes = [ - 'kirby' => 'Kirby\Cms\App', - 'site' => 'Kirby\Cms\Site', - 'pages' => 'Kirby\Cms\Pages', - 'page' => 'Kirby\Cms\Page' - ]; - - foreach ($controllerData as $key => $value) { - if (array_key_exists($key, $classes) === true) { - if (is_a($value, $classes[$key]) === true) { - $data[$key] = $value; - } else { - throw new InvalidArgumentException('The returned variable "' . $key . '" from the controller "' . $this->template()->name() . '" is not of the required type "' . $classes[$key] . '"'); - } - } else { - $data[$key] = $value; - } - } - } - - return $data; - } - - /** - * Returns a number indicating how deep the page - * is nested within the content folder - * - * @return int - */ - public function depth(): int - { - return $this->depth ??= (substr_count($this->id(), '/') + 1); - } - - /** - * Sorting number + Slug - * - * @return string - */ - public function dirname(): string - { - if ($this->dirname !== null) { - return $this->dirname; - } - - if ($this->num() !== null) { - return $this->dirname = $this->num() . Dir::$numSeparator . $this->uid(); - } else { - return $this->dirname = $this->uid(); - } - } - - /** - * Sorting number + Slug - * - * @return string - */ - public function diruri(): string - { - if (is_string($this->diruri) === true) { - return $this->diruri; - } - - if ($this->isDraft() === true) { - $dirname = '_drafts/' . $this->dirname(); - } else { - $dirname = $this->dirname(); - } - - if ($parent = $this->parent()) { - return $this->diruri = $parent->diruri() . '/' . $dirname; - } else { - return $this->diruri = $dirname; - } - } - - /** - * Checks if the page exists on disk - * - * @return bool - */ - public function exists(): bool - { - return is_dir($this->root()) === true; - } - - /** - * Constructs a Page object and also - * takes page models into account. - * - * @internal - * @param mixed $props - * @return static - */ - public static function factory($props) - { - if (empty($props['model']) === false) { - return static::model($props['model'], $props); - } - - return new static($props); - } - - /** - * Redirects to this page, - * wrapper for the `go()` helper - * - * @since 3.4.0 - * - * @param array $options Options for `Kirby\Http\Uri` to create URL parts - * @param int $code HTTP status code - */ - public function go(array $options = [], int $code = 302) - { - Response::go($this->url($options), $code); - } - - /** - * Checks if the intended template - * for the page exists. - * - * @return bool - */ - public function hasTemplate(): bool - { - return $this->intendedTemplate() === $this->template(); - } - - /** - * Returns the Page Id - * - * @return string - */ - public function id(): string - { - if ($this->id !== null) { - return $this->id; - } - - // set the id, depending on the parent - if ($parent = $this->parent()) { - return $this->id = $parent->id() . '/' . $this->uid(); - } - - return $this->id = $this->uid(); - } - - /** - * Returns the template that should be - * loaded if it exists. - * - * @return \Kirby\Cms\Template - */ - public function intendedTemplate() - { - if ($this->intendedTemplate !== null) { - return $this->intendedTemplate; - } - - return $this->setTemplate($this->inventory()['template'])->intendedTemplate(); - } - - /** - * Returns the inventory of files - * children and content files - * - * @internal - * @return array - */ - public function inventory(): array - { - if ($this->inventory !== null) { - return $this->inventory; - } - - $kirby = $this->kirby(); - - return $this->inventory = Dir::inventory( - $this->root(), - $kirby->contentExtension(), - $kirby->contentIgnore(), - $kirby->multilang() - ); - } - - /** - * Compares the current object with the given page object - * - * @param \Kirby\Cms\Page|string $page - * @return bool - */ - public function is($page): bool - { - if (is_a($page, 'Kirby\Cms\Page') === false) { - if (is_string($page) === false) { - return false; - } - - $page = $this->kirby()->page($page); - } - - if (is_a($page, 'Kirby\Cms\Page') === false) { - return false; - } - - return $this->id() === $page->id(); - } - - /** - * Checks if the page is the current page - * - * @return bool - */ - public function isActive(): bool - { - if ($page = $this->site()->page()) { - if ($page->is($this) === true) { - return true; - } - } - - return false; - } - - /** - * Checks if the page is a direct or indirect ancestor of the given $page object - * - * @param Page $child - * @return bool - */ - public function isAncestorOf(Page $child): bool - { - return $child->parents()->has($this->id()) === true; - } - - /** - * Checks if the page can be cached in the - * pages cache. This will also check if one - * of the ignore rules from the config kick in. - * - * @return bool - */ - public function isCacheable(): bool - { - $kirby = $this->kirby(); - $cache = $kirby->cache('pages'); - $options = $cache->options(); - $ignore = $options['ignore'] ?? null; - - // the pages cache is switched off - if (($options['active'] ?? false) === false) { - return false; - } - - // inspect the current request - $request = $kirby->request(); - - // disable the pages cache for any request types but GET or HEAD - if (in_array($request->method(), ['GET', 'HEAD']) === false) { - return false; - } - - // disable the pages cache when there's request data - if (empty($request->data()) === false) { - return false; - } - - // disable the pages cache when there are any params - if ($request->params()->isNotEmpty()) { - return false; - } - - // check for a custom ignore rule - if (is_a($ignore, 'Closure') === true) { - if ($ignore($this) === true) { - return false; - } - } - - // ignore pages by id - if (is_array($ignore) === true) { - if (in_array($this->id(), $ignore) === true) { - return false; - } - } - - return true; - } - - /** - * Checks if the page is a child of the given page - * - * @param \Kirby\Cms\Page|string $parent - * @return bool - */ - public function isChildOf($parent): bool - { - if ($parentObj = $this->parent()) { - return $parentObj->is($parent); - } - - return false; - } - - /** - * Checks if the page is a descendant of the given page - * - * @param \Kirby\Cms\Page|string $parent - * @return bool - */ - public function isDescendantOf($parent): bool - { - if (is_string($parent) === true) { - $parent = $this->site()->find($parent); - } - - if (!$parent) { - return false; - } - - return $this->parents()->has($parent->id()) === true; - } - - /** - * Checks if the page is a descendant of the currently active page - * - * @return bool - */ - public function isDescendantOfActive(): bool - { - if ($active = $this->site()->page()) { - return $this->isDescendantOf($active); - } - - return false; - } - - /** - * Checks if the current page is a draft - * - * @return bool - */ - public function isDraft(): bool - { - return $this->isDraft; - } - - /** - * Checks if the page is the error page - * - * @return bool - */ - public function isErrorPage(): bool - { - return $this->id() === $this->site()->errorPageId(); - } - - /** - * Checks if the page is the home page - * - * @return bool - */ - public function isHomePage(): bool - { - return $this->id() === $this->site()->homePageId(); - } - - /** - * It's often required to check for the - * home and error page to stop certain - * actions. That's why there's a shortcut. - * - * @return bool - */ - public function isHomeOrErrorPage(): bool - { - return $this->isHomePage() === true || $this->isErrorPage() === true; - } - - /** - * Checks if the page has a sorting number - * - * @return bool - */ - public function isListed(): bool - { - return $this->num() !== null; - } - - /** - * Checks if the page is open. - * Open pages are either the current one - * or descendants of the current one. - * - * @return bool - */ - public function isOpen(): bool - { - if ($this->isActive() === true) { - return true; - } - - if ($page = $this->site()->page()) { - if ($page->parents()->has($this->id()) === true) { - return true; - } - } - - return false; - } - - /** - * Checks if the page is not a draft. - * - * @return bool - */ - public function isPublished(): bool - { - return $this->isDraft() === false; - } - - /** - * Check if the page can be read by the current user - * - * @return bool - */ - public function isReadable(): bool - { - static $readable = []; - - $template = $this->intendedTemplate()->name(); - - if (isset($readable[$template]) === true) { - return $readable[$template]; - } - - return $readable[$template] = $this->permissions()->can('read'); - } - - /** - * Checks if the page is sortable - * - * @return bool - */ - public function isSortable(): bool - { - return $this->permissions()->can('sort'); - } - - /** - * Checks if the page has no sorting number - * - * @return bool - */ - public function isUnlisted(): bool - { - return $this->isListed() === false; - } - - /** - * Checks if the page access is verified. - * This is only used for drafts so far. - * - * @internal - * @param string|null $token - * @return bool - */ - public function isVerified(string $token = null) - { - if ( - $this->isDraft() === false && - $this->parents()->findBy('status', 'draft') === null - ) { - return true; - } - - if ($token === null) { - return false; - } - - return $this->token() === $token; - } - - /** - * Returns the root to the media folder for the page - * - * @internal - * @return string - */ - public function mediaRoot(): string - { - return $this->kirby()->root('media') . '/pages/' . $this->id(); - } - - /** - * The page's base URL for any files - * - * @internal - * @return string - */ - public function mediaUrl(): string - { - return $this->kirby()->url('media') . '/pages/' . $this->id(); - } - - /** - * Creates a page model if it has been registered - * - * @internal - * @param string $name - * @param array $props - * @return static - */ - public static function model(string $name, array $props = []) - { - if ($class = (static::$models[$name] ?? null)) { - $object = new $class($props); - - if (is_a($object, 'Kirby\Cms\Page') === true) { - return $object; - } - } - - return new static($props); - } - - /** - * Returns the last modification date of the page - * - * @param string|null $format - * @param string|null $handler - * @param string|null $languageCode - * @return int|string - */ - public function modified(string $format = null, string $handler = null, string $languageCode = null) - { - return F::modified( - $this->contentFile($languageCode), - $format, - $handler ?? $this->kirby()->option('date.handler', 'date') - ); - } - - /** - * Returns the sorting number - * - * @return int|null - */ - public function num(): ?int - { - return $this->num; - } - - /** - * Returns the panel info object - * - * @return \Kirby\Panel\Page - */ - public function panel() - { - return new Panel($this); - } - - /** - * Returns the parent Page object - * - * @return \Kirby\Cms\Page|null - */ - public function parent() - { - return $this->parent; - } - - /** - * Returns the parent id, if a parent exists - * - * @internal - * @return string|null - */ - public function parentId(): ?string - { - if ($parent = $this->parent()) { - return $parent->id(); - } - - return null; - } - - /** - * Returns the parent model, - * which can either be another Page - * or the Site - * - * @internal - * @return \Kirby\Cms\Page|\Kirby\Cms\Site - */ - public function parentModel() - { - return $this->parent() ?? $this->site(); - } - - /** - * Returns a list of all parents and their parents recursively - * - * @return \Kirby\Cms\Pages - */ - public function parents() - { - $parents = new Pages(); - $page = $this->parent(); - - while ($page !== null) { - $parents->append($page->id(), $page); - $page = $page->parent(); - } - - return $parents; - } - - /** - * Returns the permissions object for this page - * - * @return \Kirby\Cms\PagePermissions - */ - public function permissions() - { - return new PagePermissions($this); - } - - /** - * Draft preview Url - * - * @internal - * @return string|null - */ - public function previewUrl(): ?string - { - $preview = $this->blueprint()->preview(); - - if ($preview === false) { - return null; - } - - if ($preview === true) { - $url = $this->url(); - } else { - $url = $preview; - } - - if ($this->isDraft() === true) { - $uri = new Uri($url); - $uri->query->token = $this->token(); - - $url = $uri->toString(); - } - - return $url; - } - - /** - * Renders the page with the given data. - * - * An optional content type can be passed to - * render a content representation instead of - * the default template. - * - * @param array $data - * @param string $contentType - * @return string - * @throws \Kirby\Exception\NotFoundException If the default template cannot be found - */ - public function render(array $data = [], $contentType = 'html'): string - { - $kirby = $this->kirby(); - $cache = $cacheId = $html = null; - - // try to get the page from cache - if (empty($data) === true && $this->isCacheable() === true) { - $cache = $kirby->cache('pages'); - $cacheId = $this->cacheId($contentType); - $result = $cache->get($cacheId); - $html = $result['html'] ?? null; - $response = $result['response'] ?? []; - $usesAuth = $result['usesAuth'] ?? false; - $usesCookies = $result['usesCookies'] ?? []; - - // if the request contains dynamic data that the cached response - // relied on, don't use the cache to allow dynamic code to run - if (Responder::isPrivate($usesAuth, $usesCookies) === true) { - $html = null; - } - - // reconstruct the response configuration - if (empty($html) === false && empty($response) === false) { - $kirby->response()->fromArray($response); - } - } - - // fetch the page regularly - if ($html === null) { - if ($contentType === 'html') { - $template = $this->template(); - } else { - $template = $this->representation($contentType); - } - - if ($template->exists() === false) { - throw new NotFoundException([ - 'key' => 'template.default.notFound' - ]); - } - - $kirby->data = $this->controller($data, $contentType); - - // render the page - $html = $template->render($kirby->data); - - // cache the result - $response = $kirby->response(); - if ($cache !== null && $response->cache() === true) { - $cache->set($cacheId, [ - 'html' => $html, - 'response' => $response->toArray(), - 'usesAuth' => $response->usesAuth(), - 'usesCookies' => $response->usesCookies(), - ], $response->expires() ?? 0); - } - } - - return $html; - } - - /** - * @internal - * @param mixed $type - * @return \Kirby\Cms\Template - * @throws \Kirby\Exception\NotFoundException If the content representation cannot be found - */ - public function representation($type) - { - $kirby = $this->kirby(); - $template = $this->template(); - $representation = $kirby->template($template->name(), $type); - - if ($representation->exists() === true) { - return $representation; - } - - throw new NotFoundException('The content representation cannot be found'); - } - - /** - * Returns the absolute root to the page directory - * No matter if it exists or not. - * - * @return string - */ - public function root(): string - { - return $this->root ??= $this->kirby()->root('content') . '/' . $this->diruri(); - } - - /** - * Returns the PageRules class instance - * which is being used in various methods - * to check for valid actions and input. - * - * @return \Kirby\Cms\PageRules - */ - protected function rules() - { - return new PageRules(); - } - - /** - * Search all pages within the current page - * - * @param string|null $query - * @param array $params - * @return \Kirby\Cms\Pages - */ - public function search(string $query = null, $params = []) - { - return $this->index()->search($query, $params); - } - - /** - * Sets the Blueprint object - * - * @param array|null $blueprint - * @return $this - */ - protected function setBlueprint(array $blueprint = null) - { - if ($blueprint !== null) { - $blueprint['model'] = $this; - $this->blueprint = new PageBlueprint($blueprint); - } - - return $this; - } - - /** - * Sets the dirname manually, which works - * more reliable in connection with the inventory - * than computing the dirname afterwards - * - * @param string|null $dirname - * @return $this - */ - protected function setDirname(string $dirname = null) - { - $this->dirname = $dirname; - return $this; - } - - /** - * Sets the draft flag - * - * @param bool $isDraft - * @return $this - */ - protected function setIsDraft(bool $isDraft = null) - { - $this->isDraft = $isDraft ?? false; - return $this; - } - - /** - * Sets the sorting number - * - * @param int|null $num - * @return $this - */ - protected function setNum(int $num = null) - { - $this->num = $num === null ? $num : (int)$num; - return $this; - } - - /** - * Sets the parent page object - * - * @param \Kirby\Cms\Page|null $parent - * @return $this - */ - protected function setParent(Page $parent = null) - { - $this->parent = $parent; - return $this; - } - - /** - * Sets the absolute path to the page - * - * @param string|null $root - * @return $this - */ - protected function setRoot(string $root = null) - { - $this->root = $root; - return $this; - } - - /** - * Sets the required Page slug - * - * @param string $slug - * @return $this - */ - protected function setSlug(string $slug) - { - $this->slug = $slug; - return $this; - } - - /** - * Sets the intended template - * - * @param string|null $template - * @return $this - */ - protected function setTemplate(string $template = null) - { - if ($template !== null) { - $this->intendedTemplate = $this->kirby()->template($template); - } - - return $this; - } - - /** - * Sets the Url - * - * @param string|null $url - * @return $this - */ - protected function setUrl(string $url = null) - { - if (is_string($url) === true) { - $url = rtrim($url, '/'); - } - - $this->url = $url; - return $this; - } - - /** - * Returns the slug of the page - * - * @param string|null $languageCode - * @return string - */ - public function slug(string $languageCode = null): string - { - if ($this->kirby()->multilang() === true) { - if ($languageCode === null) { - $languageCode = $this->kirby()->languageCode(); - } - - $defaultLanguageCode = $this->kirby()->defaultLanguage()->code(); - - if ($languageCode !== $defaultLanguageCode && $translation = $this->translations()->find($languageCode)) { - return $translation->slug() ?? $this->slug; - } - } - - return $this->slug; - } - - /** - * Returns the page status, which - * can be `draft`, `listed` or `unlisted` - * - * @return string - */ - public function status(): string - { - if ($this->isDraft() === true) { - return 'draft'; - } - - if ($this->isUnlisted() === true) { - return 'unlisted'; - } - - return 'listed'; - } - - /** - * Returns the final template - * - * @return \Kirby\Cms\Template - */ - public function template() - { - if ($this->template !== null) { - return $this->template; - } - - $intended = $this->intendedTemplate(); - - if ($intended->exists() === true) { - return $this->template = $intended; - } - - return $this->template = $this->kirby()->template('default'); - } - - /** - * Returns the title field or the slug as fallback - * - * @return \Kirby\Cms\Field - */ - public function title() - { - return $this->content()->get('title')->or($this->slug()); - } - - /** - * Converts the most important - * properties to array - * - * @return array - */ - public function toArray(): array - { - return [ - 'children' => $this->children()->keys(), - 'content' => $this->content()->toArray(), - 'files' => $this->files()->keys(), - 'id' => $this->id(), - 'mediaUrl' => $this->mediaUrl(), - 'mediaRoot' => $this->mediaRoot(), - 'num' => $this->num(), - 'parent' => $this->parent() ? $this->parent()->id() : null, - 'slug' => $this->slug(), - 'template' => $this->template(), - 'translations' => $this->translations()->toArray(), - 'uid' => $this->uid(), - 'uri' => $this->uri(), - 'url' => $this->url() - ]; - } - - /** - * Returns a verification token, which - * is used for the draft authentication - * - * @return string - */ - protected function token(): string - { - return $this->kirby()->contentToken($this, $this->id() . $this->template()); - } - - /** - * Returns the UID of the page. - * The UID is basically the same as the - * slug, but stays the same on - * multi-language sites. Whereas the slug - * can be translated. - * - * @see self::slug() - * @return string - */ - public function uid(): string - { - return $this->slug; - } - - /** - * The uri is the same as the id, except - * that it will be translated in multi-language setups - * - * @param string|null $languageCode - * @return string - */ - public function uri(string $languageCode = null): string - { - // set the id, depending on the parent - if ($parent = $this->parent()) { - return $parent->uri($languageCode) . '/' . $this->slug($languageCode); - } - - return $this->slug($languageCode); - } - - /** - * Returns the Url - * - * @param array|string|null $options - * @return string - */ - public function url($options = null): string - { - if ($this->kirby()->multilang() === true) { - if (is_string($options) === true) { - return $this->urlForLanguage($options); - } else { - return $this->urlForLanguage(null, $options); - } - } - - if ($options !== null) { - return Url::to($this->url(), $options); - } - - if (is_string($this->url) === true) { - return $this->url; - } - - if ($this->isHomePage() === true) { - return $this->url = $this->site()->url(); - } - - if ($parent = $this->parent()) { - if ($parent->isHomePage() === true) { - return $this->url = $this->kirby()->url('base') . '/' . $parent->uid() . '/' . $this->uid(); - } else { - return $this->url = $this->parent()->url() . '/' . $this->uid(); - } - } - - return $this->url = $this->kirby()->url('base') . '/' . $this->uid(); - } - - /** - * Builds the Url for a specific language - * - * @internal - * @param string|null $language - * @param array|null $options - * @return string - */ - public function urlForLanguage($language = null, array $options = null): string - { - if ($options !== null) { - return Url::to($this->urlForLanguage($language), $options); - } - - if ($this->isHomePage() === true) { - return $this->url = $this->site()->urlForLanguage($language); - } - - if ($parent = $this->parent()) { - if ($parent->isHomePage() === true) { - return $this->url = $this->site()->urlForLanguage($language) . '/' . $parent->slug($language) . '/' . $this->slug($language); - } else { - return $this->url = $this->parent()->urlForLanguage($language) . '/' . $this->slug($language); - } - } - - return $this->url = $this->site()->urlForLanguage($language) . '/' . $this->slug($language); - } - - - /** - * Deprecated! - */ - - /** - * Provides a kirbytag or markdown - * tag for the page, which will be - * used in the panel, when the page - * gets dragged onto a textarea - * - * @deprecated 3.6.0 Use `->panel()->dragText()` instead - * @todo Remove in 3.8.0 - * - * @internal - * @param string|null $type (null|auto|kirbytext|markdown) - * @return string - * @codeCoverageIgnore - */ - public function dragText(string $type = null): string - { - Helpers::deprecated('Cms\Page::dragText() has been deprecated and will be removed in Kirby 3.8.0. Use $page->panel()->dragText() instead.'); - return $this->panel()->dragText($type); - } - - /** - * Returns the escaped Id, which is - * used in the panel to make routing work properly - * - * @deprecated 3.6.0 Use `->panel()->id()` instead - * @todo Remove in 3.8.0 - * - * @internal - * @return string - * @codeCoverageIgnore - */ - public function panelId(): string - { - Helpers::deprecated('Cms\Page::panelId() has been deprecated and will be removed in Kirby 3.8.0. Use $page->panel()->id() instead.'); - return $this->panel()->id(); - } - - /** - * Returns the full path without leading slash - * - * @deprecated 3.6.0 Use `->panel()->path()` instead - * @todo Remove in 3.8.0 - * - * @internal - * @return string - * @codeCoverageIgnore - */ - public function panelPath(): string - { - Helpers::deprecated('Cms\Page::panelPath() has been deprecated and will be removed in Kirby 3.8.0. Use $page->panel()->path() instead.'); - return $this->panel()->path(); - } - - /** - * Prepares the response data for page pickers - * and page fields - * - * @deprecated 3.6.0 Use `->panel()->pickerData()` instead - * @todo Remove in 3.8.0 - * - * @param array|null $params - * @return array - * @codeCoverageIgnore - */ - public function panelPickerData(array $params = []): array - { - Helpers::deprecated('Cms\Page::panelPickerData() has been deprecated and will be removed in Kirby 3.8.0. Use $page->panel()->pickerData() instead.'); - return $this->panel()->pickerData($params); - } - - /** - * Returns the url to the editing view - * in the panel - * - * @deprecated 3.6.0 Use `->panel()->url()` instead - * @todo Remove in 3.8.0 - * - * @internal - * @param bool $relative - * @return string - * @codeCoverageIgnore - */ - public function panelUrl(bool $relative = false): string - { - Helpers::deprecated('Cms\Page::panelUrl() has been deprecated and will be removed in Kirby 3.8.0. Use $page->panel()->url() instead.'); - return $this->panel()->url($relative); - } + use PageActions; + use PageSiblings; + use HasChildren; + use HasFiles; + use HasMethods; + use HasSiblings; + + public const CLASS_ALIAS = 'page'; + + /** + * All registered page methods + * + * @var array + */ + public static $methods = []; + + /** + * Registry with all Page models + * + * @var array + */ + public static $models = []; + + /** + * The PageBlueprint object + * + * @var \Kirby\Cms\PageBlueprint + */ + protected $blueprint; + + /** + * Nesting level + * + * @var int + */ + protected $depth; + + /** + * Sorting number + slug + * + * @var string + */ + protected $dirname; + + /** + * Path of dirnames + * + * @var string + */ + protected $diruri; + + /** + * Draft status flag + * + * @var bool + */ + protected $isDraft; + + /** + * The Page id + * + * @var string + */ + protected $id; + + /** + * The template, that should be loaded + * if it exists + * + * @var \Kirby\Cms\Template + */ + protected $intendedTemplate; + + /** + * @var array + */ + protected $inventory; + + /** + * The sorting number + * + * @var int|null + */ + protected $num; + + /** + * The parent page + * + * @var \Kirby\Cms\Page|null + */ + protected $parent; + + /** + * Absolute path to the page directory + * + * @var string + */ + protected $root; + + /** + * The parent Site object + * + * @var \Kirby\Cms\Site|null + */ + protected $site; + + /** + * The URL-appendix aka slug + * + * @var string + */ + protected $slug; + + /** + * The intended page template + * + * @var \Kirby\Cms\Template + */ + protected $template; + + /** + * The page url + * + * @var string|null + */ + protected $url; + + /** + * Magic caller + * + * @param string $method + * @param array $arguments + * @return mixed + */ + public function __call(string $method, array $arguments = []) + { + // public property access + if (isset($this->$method) === true) { + return $this->$method; + } + + // page methods + if ($this->hasMethod($method)) { + return $this->callMethod($method, $arguments); + } + + // return page content otherwise + return $this->content()->get($method); + } + + /** + * Creates a new page object + * + * @param array $props + */ + public function __construct(array $props) + { + // set the slug as the first property + $this->slug = $props['slug'] ?? null; + + // add all other properties + $this->setProperties($props); + } + + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return array_merge($this->toArray(), [ + 'content' => $this->content(), + 'children' => $this->children(), + 'siblings' => $this->siblings(), + 'translations' => $this->translations(), + 'files' => $this->files(), + ]); + } + + /** + * Returns the url to the api endpoint + * + * @internal + * @param bool $relative + * @return string + */ + public function apiUrl(bool $relative = false): string + { + if ($relative === true) { + return 'pages/' . $this->panel()->id(); + } else { + return $this->kirby()->url('api') . '/pages/' . $this->panel()->id(); + } + } + + /** + * Returns the blueprint object + * + * @return \Kirby\Cms\PageBlueprint + */ + public function blueprint() + { + if (is_a($this->blueprint, 'Kirby\Cms\PageBlueprint') === true) { + return $this->blueprint; + } + + return $this->blueprint = PageBlueprint::factory('pages/' . $this->intendedTemplate(), 'pages/default', $this); + } + + /** + * Returns an array with all blueprints that are available for the page + * + * @param string|null $inSection + * @return array + */ + public function blueprints(?string $inSection = null): array + { + if ($inSection !== null) { + return $this->blueprint()->section($inSection)->blueprints(); + } + + $blueprints = []; + $templates = $this->blueprint()->changeTemplate() ?? $this->blueprint()->options()['changeTemplate'] ?? []; + $currentTemplate = $this->intendedTemplate()->name(); + + if (is_array($templates) === false) { + $templates = []; + } + + // add the current template to the array if it's not already there + if (in_array($currentTemplate, $templates) === false) { + array_unshift($templates, $currentTemplate); + } + + // make sure every template is only included once + $templates = array_unique($templates); + + foreach ($templates as $template) { + try { + $props = Blueprint::load('pages/' . $template); + + $blueprints[] = [ + 'name' => basename($props['name']), + 'title' => $props['title'], + ]; + } catch (Exception $e) { + // skip invalid blueprints + } + } + + return array_values($blueprints); + } + + /** + * Builds the cache id for the page + * + * @param string $contentType + * @return string + */ + protected function cacheId(string $contentType): string + { + $cacheId = [$this->id()]; + + if ($this->kirby()->multilang() === true) { + $cacheId[] = $this->kirby()->language()->code(); + } + + $cacheId[] = $contentType; + + return implode('.', $cacheId); + } + + /** + * Prepares the content for the write method + * + * @internal + * @param array $data + * @param string|null $languageCode + * @return array + */ + public function contentFileData(array $data, ?string $languageCode = null): array + { + return A::prepend($data, [ + 'title' => $data['title'] ?? null, + 'slug' => $data['slug'] ?? null + ]); + } + + /** + * Returns the content text file + * which is found by the inventory method + * + * @internal + * @param string|null $languageCode + * @return string + */ + public function contentFileName(?string $languageCode = null): string + { + return $this->intendedTemplate()->name(); + } + + /** + * Call the page controller + * + * @internal + * @param array $data + * @param string $contentType + * @return array + * @throws \Kirby\Exception\InvalidArgumentException If the controller returns invalid objects for `kirby`, `site`, `pages` or `page` + */ + public function controller(array $data = [], string $contentType = 'html'): array + { + // create the template data + $data = array_merge($data, [ + 'kirby' => $kirby = $this->kirby(), + 'site' => $site = $this->site(), + 'pages' => $site->children(), + 'page' => $site->visit($this) + ]); + + // call the template controller if there's one. + $controllerData = $kirby->controller($this->template()->name(), $data, $contentType); + + // merge controller data with original data safely + if (empty($controllerData) === false) { + $classes = [ + 'kirby' => 'Kirby\Cms\App', + 'site' => 'Kirby\Cms\Site', + 'pages' => 'Kirby\Cms\Pages', + 'page' => 'Kirby\Cms\Page' + ]; + + foreach ($controllerData as $key => $value) { + if (array_key_exists($key, $classes) === true) { + if (is_a($value, $classes[$key]) === true) { + $data[$key] = $value; + } else { + throw new InvalidArgumentException('The returned variable "' . $key . '" from the controller "' . $this->template()->name() . '" is not of the required type "' . $classes[$key] . '"'); + } + } else { + $data[$key] = $value; + } + } + } + + return $data; + } + + /** + * Returns a number indicating how deep the page + * is nested within the content folder + * + * @return int + */ + public function depth(): int + { + return $this->depth ??= (substr_count($this->id(), '/') + 1); + } + + /** + * Sorting number + Slug + * + * @return string + */ + public function dirname(): string + { + if ($this->dirname !== null) { + return $this->dirname; + } + + if ($this->num() !== null) { + return $this->dirname = $this->num() . Dir::$numSeparator . $this->uid(); + } else { + return $this->dirname = $this->uid(); + } + } + + /** + * Sorting number + Slug + * + * @return string + */ + public function diruri(): string + { + if (is_string($this->diruri) === true) { + return $this->diruri; + } + + if ($this->isDraft() === true) { + $dirname = '_drafts/' . $this->dirname(); + } else { + $dirname = $this->dirname(); + } + + if ($parent = $this->parent()) { + return $this->diruri = $parent->diruri() . '/' . $dirname; + } else { + return $this->diruri = $dirname; + } + } + + /** + * Checks if the page exists on disk + * + * @return bool + */ + public function exists(): bool + { + return is_dir($this->root()) === true; + } + + /** + * Constructs a Page object and also + * takes page models into account. + * + * @internal + * @param mixed $props + * @return static + */ + public static function factory($props) + { + if (empty($props['model']) === false) { + return static::model($props['model'], $props); + } + + return new static($props); + } + + /** + * Redirects to this page, + * wrapper for the `go()` helper + * + * @since 3.4.0 + * + * @param array $options Options for `Kirby\Http\Uri` to create URL parts + * @param int $code HTTP status code + */ + public function go(array $options = [], int $code = 302) + { + Response::go($this->url($options), $code); + } + + /** + * Checks if the intended template + * for the page exists. + * + * @return bool + */ + public function hasTemplate(): bool + { + return $this->intendedTemplate() === $this->template(); + } + + /** + * Returns the Page Id + * + * @return string + */ + public function id(): string + { + if ($this->id !== null) { + return $this->id; + } + + // set the id, depending on the parent + if ($parent = $this->parent()) { + return $this->id = $parent->id() . '/' . $this->uid(); + } + + return $this->id = $this->uid(); + } + + /** + * Returns the template that should be + * loaded if it exists. + * + * @return \Kirby\Cms\Template + */ + public function intendedTemplate() + { + if ($this->intendedTemplate !== null) { + return $this->intendedTemplate; + } + + return $this->setTemplate($this->inventory()['template'])->intendedTemplate(); + } + + /** + * Returns the inventory of files + * children and content files + * + * @internal + * @return array + */ + public function inventory(): array + { + if ($this->inventory !== null) { + return $this->inventory; + } + + $kirby = $this->kirby(); + + return $this->inventory = Dir::inventory( + $this->root(), + $kirby->contentExtension(), + $kirby->contentIgnore(), + $kirby->multilang() + ); + } + + /** + * Compares the current object with the given page object + * + * @param \Kirby\Cms\Page|string $page + * @return bool + */ + public function is($page): bool + { + if (is_a($page, 'Kirby\Cms\Page') === false) { + if (is_string($page) === false) { + return false; + } + + $page = $this->kirby()->page($page); + } + + if (is_a($page, 'Kirby\Cms\Page') === false) { + return false; + } + + return $this->id() === $page->id(); + } + + /** + * Checks if the page is the current page + * + * @return bool + */ + public function isActive(): bool + { + if ($page = $this->site()->page()) { + if ($page->is($this) === true) { + return true; + } + } + + return false; + } + + /** + * Checks if the page is a direct or indirect ancestor of the given $page object + * + * @param Page $child + * @return bool + */ + public function isAncestorOf(Page $child): bool + { + return $child->parents()->has($this->id()) === true; + } + + /** + * Checks if the page can be cached in the + * pages cache. This will also check if one + * of the ignore rules from the config kick in. + * + * @return bool + */ + public function isCacheable(): bool + { + $kirby = $this->kirby(); + $cache = $kirby->cache('pages'); + $options = $cache->options(); + $ignore = $options['ignore'] ?? null; + + // the pages cache is switched off + if (($options['active'] ?? false) === false) { + return false; + } + + // inspect the current request + $request = $kirby->request(); + + // disable the pages cache for any request types but GET or HEAD + if (in_array($request->method(), ['GET', 'HEAD']) === false) { + return false; + } + + // disable the pages cache when there's request data + if (empty($request->data()) === false) { + return false; + } + + // disable the pages cache when there are any params + if ($request->params()->isNotEmpty()) { + return false; + } + + // check for a custom ignore rule + if (is_a($ignore, 'Closure') === true) { + if ($ignore($this) === true) { + return false; + } + } + + // ignore pages by id + if (is_array($ignore) === true) { + if (in_array($this->id(), $ignore) === true) { + return false; + } + } + + return true; + } + + /** + * Checks if the page is a child of the given page + * + * @param \Kirby\Cms\Page|string $parent + * @return bool + */ + public function isChildOf($parent): bool + { + if ($parentObj = $this->parent()) { + return $parentObj->is($parent); + } + + return false; + } + + /** + * Checks if the page is a descendant of the given page + * + * @param \Kirby\Cms\Page|string $parent + * @return bool + */ + public function isDescendantOf($parent): bool + { + if (is_string($parent) === true) { + $parent = $this->site()->find($parent); + } + + if (!$parent) { + return false; + } + + return $this->parents()->has($parent->id()) === true; + } + + /** + * Checks if the page is a descendant of the currently active page + * + * @return bool + */ + public function isDescendantOfActive(): bool + { + if ($active = $this->site()->page()) { + return $this->isDescendantOf($active); + } + + return false; + } + + /** + * Checks if the current page is a draft + * + * @return bool + */ + public function isDraft(): bool + { + return $this->isDraft; + } + + /** + * Checks if the page is the error page + * + * @return bool + */ + public function isErrorPage(): bool + { + return $this->id() === $this->site()->errorPageId(); + } + + /** + * Checks if the page is the home page + * + * @return bool + */ + public function isHomePage(): bool + { + return $this->id() === $this->site()->homePageId(); + } + + /** + * It's often required to check for the + * home and error page to stop certain + * actions. That's why there's a shortcut. + * + * @return bool + */ + public function isHomeOrErrorPage(): bool + { + return $this->isHomePage() === true || $this->isErrorPage() === true; + } + + /** + * Checks if the page has a sorting number + * + * @return bool + */ + public function isListed(): bool + { + return $this->num() !== null; + } + + /** + * Checks if the page is open. + * Open pages are either the current one + * or descendants of the current one. + * + * @return bool + */ + public function isOpen(): bool + { + if ($this->isActive() === true) { + return true; + } + + if ($page = $this->site()->page()) { + if ($page->parents()->has($this->id()) === true) { + return true; + } + } + + return false; + } + + /** + * Checks if the page is not a draft. + * + * @return bool + */ + public function isPublished(): bool + { + return $this->isDraft() === false; + } + + /** + * Check if the page can be read by the current user + * + * @return bool + */ + public function isReadable(): bool + { + static $readable = []; + + $template = $this->intendedTemplate()->name(); + + if (isset($readable[$template]) === true) { + return $readable[$template]; + } + + return $readable[$template] = $this->permissions()->can('read'); + } + + /** + * Checks if the page is sortable + * + * @return bool + */ + public function isSortable(): bool + { + return $this->permissions()->can('sort'); + } + + /** + * Checks if the page has no sorting number + * + * @return bool + */ + public function isUnlisted(): bool + { + return $this->isListed() === false; + } + + /** + * Checks if the page access is verified. + * This is only used for drafts so far. + * + * @internal + * @param string|null $token + * @return bool + */ + public function isVerified(string $token = null) + { + if ( + $this->isDraft() === false && + $this->parents()->findBy('status', 'draft') === null + ) { + return true; + } + + if ($token === null) { + return false; + } + + return $this->token() === $token; + } + + /** + * Returns the root to the media folder for the page + * + * @internal + * @return string + */ + public function mediaRoot(): string + { + return $this->kirby()->root('media') . '/pages/' . $this->id(); + } + + /** + * The page's base URL for any files + * + * @internal + * @return string + */ + public function mediaUrl(): string + { + return $this->kirby()->url('media') . '/pages/' . $this->id(); + } + + /** + * Creates a page model if it has been registered + * + * @internal + * @param string $name + * @param array $props + * @return static + */ + public static function model(string $name, array $props = []) + { + if ($class = (static::$models[$name] ?? null)) { + $object = new $class($props); + + if (is_a($object, 'Kirby\Cms\Page') === true) { + return $object; + } + } + + return new static($props); + } + + /** + * Returns the last modification date of the page + * + * @param string|null $format + * @param string|null $handler + * @param string|null $languageCode + * @return int|string + */ + public function modified(string $format = null, string $handler = null, string $languageCode = null) + { + return F::modified( + $this->contentFile($languageCode), + $format, + $handler ?? $this->kirby()->option('date.handler', 'date') + ); + } + + /** + * Returns the sorting number + * + * @return int|null + */ + public function num(): ?int + { + return $this->num; + } + + /** + * Returns the panel info object + * + * @return \Kirby\Panel\Page + */ + public function panel() + { + return new Panel($this); + } + + /** + * Returns the parent Page object + * + * @return \Kirby\Cms\Page|null + */ + public function parent() + { + return $this->parent; + } + + /** + * Returns the parent id, if a parent exists + * + * @internal + * @return string|null + */ + public function parentId(): ?string + { + if ($parent = $this->parent()) { + return $parent->id(); + } + + return null; + } + + /** + * Returns the parent model, + * which can either be another Page + * or the Site + * + * @internal + * @return \Kirby\Cms\Page|\Kirby\Cms\Site + */ + public function parentModel() + { + return $this->parent() ?? $this->site(); + } + + /** + * Returns a list of all parents and their parents recursively + * + * @return \Kirby\Cms\Pages + */ + public function parents() + { + $parents = new Pages(); + $page = $this->parent(); + + while ($page !== null) { + $parents->append($page->id(), $page); + $page = $page->parent(); + } + + return $parents; + } + + /** + * Returns the permissions object for this page + * + * @return \Kirby\Cms\PagePermissions + */ + public function permissions() + { + return new PagePermissions($this); + } + + /** + * Draft preview Url + * + * @internal + * @return string|null + */ + public function previewUrl(): ?string + { + $preview = $this->blueprint()->preview(); + + if ($preview === false) { + return null; + } + + if ($preview === true) { + $url = $this->url(); + } else { + $url = $preview; + } + + if ($this->isDraft() === true) { + $uri = new Uri($url); + $uri->query->token = $this->token(); + + $url = $uri->toString(); + } + + return $url; + } + + /** + * Renders the page with the given data. + * + * An optional content type can be passed to + * render a content representation instead of + * the default template. + * + * @param array $data + * @param string $contentType + * @return string + * @throws \Kirby\Exception\NotFoundException If the default template cannot be found + */ + public function render(array $data = [], $contentType = 'html'): string + { + $kirby = $this->kirby(); + $cache = $cacheId = $html = null; + + // try to get the page from cache + if (empty($data) === true && $this->isCacheable() === true) { + $cache = $kirby->cache('pages'); + $cacheId = $this->cacheId($contentType); + $result = $cache->get($cacheId); + $html = $result['html'] ?? null; + $response = $result['response'] ?? []; + $usesAuth = $result['usesAuth'] ?? false; + $usesCookies = $result['usesCookies'] ?? []; + + // if the request contains dynamic data that the cached response + // relied on, don't use the cache to allow dynamic code to run + if (Responder::isPrivate($usesAuth, $usesCookies) === true) { + $html = null; + } + + // reconstruct the response configuration + if (empty($html) === false && empty($response) === false) { + $kirby->response()->fromArray($response); + } + } + + // fetch the page regularly + if ($html === null) { + if ($contentType === 'html') { + $template = $this->template(); + } else { + $template = $this->representation($contentType); + } + + if ($template->exists() === false) { + throw new NotFoundException([ + 'key' => 'template.default.notFound' + ]); + } + + $kirby->data = $this->controller($data, $contentType); + + // render the page + $html = $template->render($kirby->data); + + // cache the result + $response = $kirby->response(); + if ($cache !== null && $response->cache() === true) { + $cache->set($cacheId, [ + 'html' => $html, + 'response' => $response->toArray(), + 'usesAuth' => $response->usesAuth(), + 'usesCookies' => $response->usesCookies(), + ], $response->expires() ?? 0); + } + } + + return $html; + } + + /** + * @internal + * @param mixed $type + * @return \Kirby\Cms\Template + * @throws \Kirby\Exception\NotFoundException If the content representation cannot be found + */ + public function representation($type) + { + $kirby = $this->kirby(); + $template = $this->template(); + $representation = $kirby->template($template->name(), $type); + + if ($representation->exists() === true) { + return $representation; + } + + throw new NotFoundException('The content representation cannot be found'); + } + + /** + * Returns the absolute root to the page directory + * No matter if it exists or not. + * + * @return string + */ + public function root(): string + { + return $this->root ??= $this->kirby()->root('content') . '/' . $this->diruri(); + } + + /** + * Returns the PageRules class instance + * which is being used in various methods + * to check for valid actions and input. + * + * @return \Kirby\Cms\PageRules + */ + protected function rules() + { + return new PageRules(); + } + + /** + * Search all pages within the current page + * + * @param string|null $query + * @param array $params + * @return \Kirby\Cms\Pages + */ + public function search(string $query = null, $params = []) + { + return $this->index()->search($query, $params); + } + + /** + * Sets the Blueprint object + * + * @param array|null $blueprint + * @return $this + */ + protected function setBlueprint(array $blueprint = null) + { + if ($blueprint !== null) { + $blueprint['model'] = $this; + $this->blueprint = new PageBlueprint($blueprint); + } + + return $this; + } + + /** + * Sets the dirname manually, which works + * more reliable in connection with the inventory + * than computing the dirname afterwards + * + * @param string|null $dirname + * @return $this + */ + protected function setDirname(string $dirname = null) + { + $this->dirname = $dirname; + return $this; + } + + /** + * Sets the draft flag + * + * @param bool $isDraft + * @return $this + */ + protected function setIsDraft(bool $isDraft = null) + { + $this->isDraft = $isDraft ?? false; + return $this; + } + + /** + * Sets the sorting number + * + * @param int|null $num + * @return $this + */ + protected function setNum(int $num = null) + { + $this->num = $num === null ? $num : (int)$num; + return $this; + } + + /** + * Sets the parent page object + * + * @param \Kirby\Cms\Page|null $parent + * @return $this + */ + protected function setParent(Page $parent = null) + { + $this->parent = $parent; + return $this; + } + + /** + * Sets the absolute path to the page + * + * @param string|null $root + * @return $this + */ + protected function setRoot(string $root = null) + { + $this->root = $root; + return $this; + } + + /** + * Sets the required Page slug + * + * @param string $slug + * @return $this + */ + protected function setSlug(string $slug) + { + $this->slug = $slug; + return $this; + } + + /** + * Sets the intended template + * + * @param string|null $template + * @return $this + */ + protected function setTemplate(string $template = null) + { + if ($template !== null) { + $this->intendedTemplate = $this->kirby()->template($template); + } + + return $this; + } + + /** + * Sets the Url + * + * @param string|null $url + * @return $this + */ + protected function setUrl(string $url = null) + { + if (is_string($url) === true) { + $url = rtrim($url, '/'); + } + + $this->url = $url; + return $this; + } + + /** + * Returns the slug of the page + * + * @param string|null $languageCode + * @return string + */ + public function slug(string $languageCode = null): string + { + if ($this->kirby()->multilang() === true) { + if ($languageCode === null) { + $languageCode = $this->kirby()->languageCode(); + } + + $defaultLanguageCode = $this->kirby()->defaultLanguage()->code(); + + if ($languageCode !== $defaultLanguageCode && $translation = $this->translations()->find($languageCode)) { + return $translation->slug() ?? $this->slug; + } + } + + return $this->slug; + } + + /** + * Returns the page status, which + * can be `draft`, `listed` or `unlisted` + * + * @return string + */ + public function status(): string + { + if ($this->isDraft() === true) { + return 'draft'; + } + + if ($this->isUnlisted() === true) { + return 'unlisted'; + } + + return 'listed'; + } + + /** + * Returns the final template + * + * @return \Kirby\Cms\Template + */ + public function template() + { + if ($this->template !== null) { + return $this->template; + } + + $intended = $this->intendedTemplate(); + + if ($intended->exists() === true) { + return $this->template = $intended; + } + + return $this->template = $this->kirby()->template('default'); + } + + /** + * Returns the title field or the slug as fallback + * + * @return \Kirby\Cms\Field + */ + public function title() + { + return $this->content()->get('title')->or($this->slug()); + } + + /** + * Converts the most important + * properties to array + * + * @return array + */ + public function toArray(): array + { + return [ + 'children' => $this->children()->keys(), + 'content' => $this->content()->toArray(), + 'files' => $this->files()->keys(), + 'id' => $this->id(), + 'mediaUrl' => $this->mediaUrl(), + 'mediaRoot' => $this->mediaRoot(), + 'num' => $this->num(), + 'parent' => $this->parent() ? $this->parent()->id() : null, + 'slug' => $this->slug(), + 'template' => $this->template(), + 'translations' => $this->translations()->toArray(), + 'uid' => $this->uid(), + 'uri' => $this->uri(), + 'url' => $this->url() + ]; + } + + /** + * Returns a verification token, which + * is used for the draft authentication + * + * @return string + */ + protected function token(): string + { + return $this->kirby()->contentToken($this, $this->id() . $this->template()); + } + + /** + * Returns the UID of the page. + * The UID is basically the same as the + * slug, but stays the same on + * multi-language sites. Whereas the slug + * can be translated. + * + * @see self::slug() + * @return string + */ + public function uid(): string + { + return $this->slug; + } + + /** + * The uri is the same as the id, except + * that it will be translated in multi-language setups + * + * @param string|null $languageCode + * @return string + */ + public function uri(string $languageCode = null): string + { + // set the id, depending on the parent + if ($parent = $this->parent()) { + return $parent->uri($languageCode) . '/' . $this->slug($languageCode); + } + + return $this->slug($languageCode); + } + + /** + * Returns the Url + * + * @param array|string|null $options + * @return string + */ + public function url($options = null): string + { + if ($this->kirby()->multilang() === true) { + if (is_string($options) === true) { + return $this->urlForLanguage($options); + } else { + return $this->urlForLanguage(null, $options); + } + } + + if ($options !== null) { + return Url::to($this->url(), $options); + } + + if (is_string($this->url) === true) { + return $this->url; + } + + if ($this->isHomePage() === true) { + return $this->url = $this->site()->url(); + } + + if ($parent = $this->parent()) { + if ($parent->isHomePage() === true) { + return $this->url = $this->kirby()->url('base') . '/' . $parent->uid() . '/' . $this->uid(); + } else { + return $this->url = $this->parent()->url() . '/' . $this->uid(); + } + } + + return $this->url = $this->kirby()->url('base') . '/' . $this->uid(); + } + + /** + * Builds the Url for a specific language + * + * @internal + * @param string|null $language + * @param array|null $options + * @return string + */ + public function urlForLanguage($language = null, array $options = null): string + { + if ($options !== null) { + return Url::to($this->urlForLanguage($language), $options); + } + + if ($this->isHomePage() === true) { + return $this->url = $this->site()->urlForLanguage($language); + } + + if ($parent = $this->parent()) { + if ($parent->isHomePage() === true) { + return $this->url = $this->site()->urlForLanguage($language) . '/' . $parent->slug($language) . '/' . $this->slug($language); + } else { + return $this->url = $this->parent()->urlForLanguage($language) . '/' . $this->slug($language); + } + } + + return $this->url = $this->site()->urlForLanguage($language) . '/' . $this->slug($language); + } + + + /** + * Deprecated! + */ + + /** + * Provides a kirbytag or markdown + * tag for the page, which will be + * used in the panel, when the page + * gets dragged onto a textarea + * + * @deprecated 3.6.0 Use `->panel()->dragText()` instead + * @todo Remove in 3.8.0 + * + * @internal + * @param string|null $type (null|auto|kirbytext|markdown) + * @return string + * @codeCoverageIgnore + */ + public function dragText(string $type = null): string + { + Helpers::deprecated('Cms\Page::dragText() has been deprecated and will be removed in Kirby 3.8.0. Use $page->panel()->dragText() instead.'); + return $this->panel()->dragText($type); + } + + /** + * Returns the escaped Id, which is + * used in the panel to make routing work properly + * + * @deprecated 3.6.0 Use `->panel()->id()` instead + * @todo Remove in 3.8.0 + * + * @internal + * @return string + * @codeCoverageIgnore + */ + public function panelId(): string + { + Helpers::deprecated('Cms\Page::panelId() has been deprecated and will be removed in Kirby 3.8.0. Use $page->panel()->id() instead.'); + return $this->panel()->id(); + } + + /** + * Returns the full path without leading slash + * + * @deprecated 3.6.0 Use `->panel()->path()` instead + * @todo Remove in 3.8.0 + * + * @internal + * @return string + * @codeCoverageIgnore + */ + public function panelPath(): string + { + Helpers::deprecated('Cms\Page::panelPath() has been deprecated and will be removed in Kirby 3.8.0. Use $page->panel()->path() instead.'); + return $this->panel()->path(); + } + + /** + * Prepares the response data for page pickers + * and page fields + * + * @deprecated 3.6.0 Use `->panel()->pickerData()` instead + * @todo Remove in 3.8.0 + * + * @param array|null $params + * @return array + * @codeCoverageIgnore + */ + public function panelPickerData(array $params = []): array + { + Helpers::deprecated('Cms\Page::panelPickerData() has been deprecated and will be removed in Kirby 3.8.0. Use $page->panel()->pickerData() instead.'); + return $this->panel()->pickerData($params); + } + + /** + * Returns the url to the editing view + * in the panel + * + * @deprecated 3.6.0 Use `->panel()->url()` instead + * @todo Remove in 3.8.0 + * + * @internal + * @param bool $relative + * @return string + * @codeCoverageIgnore + */ + public function panelUrl(bool $relative = false): string + { + Helpers::deprecated('Cms\Page::panelUrl() has been deprecated and will be removed in Kirby 3.8.0. Use $page->panel()->url() instead.'); + return $this->panel()->url($relative); + } } diff --git a/kirby/src/Cms/PageActions.php b/kirby/src/Cms/PageActions.php index fd804b5..2f465cb 100755 --- a/kirby/src/Cms/PageActions.php +++ b/kirby/src/Cms/PageActions.php @@ -25,855 +25,855 @@ use Kirby\Toolkit\Str; */ trait PageActions { - /** - * Changes the sorting number. - * The sorting number must already be correct - * when the method is called. - * This only affects this page, - * siblings will not be resorted. - * - * @param int|null $num - * @return $this|static - * @throws \Kirby\Exception\LogicException If a draft is being sorted or the directory cannot be moved - */ - public function changeNum(int $num = null) - { - if ($this->isDraft() === true) { - throw new LogicException('Drafts cannot change their sorting number'); - } - - // don't run the action if everything stayed the same - if ($this->num() === $num) { - return $this; - } - - return $this->commit('changeNum', ['page' => $this, 'num' => $num], function ($oldPage, $num) { - $newPage = $oldPage->clone([ - 'num' => $num, - 'dirname' => null, - 'root' => null - ]); - - // actually move the page on disk - if ($oldPage->exists() === true) { - if (Dir::move($oldPage->root(), $newPage->root()) === true) { - // Updates the root path of the old page with the root path - // of the moved new page to use fly actions on old page in loop - $oldPage->setRoot($newPage->root()); - } else { - throw new LogicException('The page directory cannot be moved'); - } - } - - // overwrite the child in the parent page - $newPage - ->parentModel() - ->children() - ->set($newPage->id(), $newPage); - - return $newPage; - }); - } - - /** - * Changes the slug/uid of the page - * - * @param string $slug - * @param string|null $languageCode - * @return $this|static - * @throws \Kirby\Exception\LogicException If the directory cannot be moved - */ - public function changeSlug(string $slug, string $languageCode = null) - { - // always sanitize the slug - $slug = Str::slug($slug); - - // in multi-language installations the slug for the non-default - // languages is stored in the text file. The changeSlugForLanguage - // method takes care of that. - if ($language = $this->kirby()->language($languageCode)) { - if ($language->isDefault() === false) { - return $this->changeSlugForLanguage($slug, $languageCode); - } - } - - // if the slug stays exactly the same, - // nothing needs to be done. - if ($slug === $this->slug()) { - return $this; - } - - $arguments = ['page' => $this, 'slug' => $slug, 'languageCode' => null]; - return $this->commit('changeSlug', $arguments, function ($oldPage, $slug) { - $newPage = $oldPage->clone([ - 'slug' => $slug, - 'dirname' => null, - 'root' => null - ]); - - if ($oldPage->exists() === true) { - // remove the lock of the old page - if ($lock = $oldPage->lock()) { - $lock->remove(); - } - - // actually move stuff on disk - if (Dir::move($oldPage->root(), $newPage->root()) !== true) { - throw new LogicException('The page directory cannot be moved'); - } - - // remove from the siblings - $oldPage->parentModel()->children()->remove($oldPage); - - Dir::remove($oldPage->mediaRoot()); - } - - // overwrite the new page in the parent collection - if ($newPage->isDraft() === true) { - $newPage->parentModel()->drafts()->set($newPage->id(), $newPage); - } else { - $newPage->parentModel()->children()->set($newPage->id(), $newPage); - } - - return $newPage; - }); - } - - /** - * Change the slug for a specific language - * - * @param string $slug - * @param string|null $languageCode - * @return static - * @throws \Kirby\Exception\NotFoundException If the language for the given language code cannot be found - * @throws \Kirby\Exception\InvalidArgumentException If the slug for the default language is being changed - */ - protected function changeSlugForLanguage(string $slug, string $languageCode = null) - { - $language = $this->kirby()->language($languageCode); - - if (!$language) { - throw new NotFoundException('The language: "' . $languageCode . '" does not exist'); - } - - if ($language->isDefault() === true) { - throw new InvalidArgumentException('Use the changeSlug method to change the slug for the default language'); - } - - $arguments = ['page' => $this, 'slug' => $slug, 'languageCode' => $languageCode]; - return $this->commit('changeSlug', $arguments, function ($page, $slug, $languageCode) { - // remove the slug if it's the same as the folder name - if ($slug === $page->uid()) { - $slug = null; - } - - return $page->save(['slug' => $slug], $languageCode); - }); - } - - /** - * Change the status of the current page - * to either draft, listed or unlisted. - * If changing to `listed`, you can pass a position for the - * page in the siblings collection. Siblings will be resorted. - * - * @param string $status "draft", "listed" or "unlisted" - * @param int|null $position Optional sorting number - * @return static - * @throws \Kirby\Exception\InvalidArgumentException If an invalid status is being passed - */ - public function changeStatus(string $status, int $position = null) - { - switch ($status) { - case 'draft': - return $this->changeStatusToDraft(); - case 'listed': - return $this->changeStatusToListed($position); - case 'unlisted': - return $this->changeStatusToUnlisted(); - default: - throw new InvalidArgumentException('Invalid status: ' . $status); - } - } - - /** - * @return static - */ - protected function changeStatusToDraft() - { - $arguments = ['page' => $this, 'status' => 'draft', 'position' => null]; - $page = $this->commit( - 'changeStatus', - $arguments, - fn ($page) => $page->unpublish() - ); - - return $page; - } - - /** - * @param int|null $position - * @return $this|static - */ - protected function changeStatusToListed(int $position = null) - { - // create a sorting number for the page - $num = $this->createNum($position); - - // don't sort if not necessary - if ($this->status() === 'listed' && $num === $this->num()) { - return $this; - } - - $arguments = ['page' => $this, 'status' => 'listed', 'position' => $num]; - $page = $this->commit('changeStatus', $arguments, function ($page, $status, $position) { - return $page->publish()->changeNum($position); - }); - - if ($this->blueprint()->num() === 'default') { - $page->resortSiblingsAfterListing($num); - } - - return $page; - } - - /** - * @return $this|static - */ - protected function changeStatusToUnlisted() - { - if ($this->status() === 'unlisted') { - return $this; - } - - $arguments = ['page' => $this, 'status' => 'unlisted', 'position' => null]; - $page = $this->commit('changeStatus', $arguments, function ($page) { - return $page->publish()->changeNum(null); - }); - - $this->resortSiblingsAfterUnlisting(); - - return $page; - } - - /** - * Change the position of the page in its siblings - * collection. Siblings will be resorted. If the page - * status isn't yet `listed`, it will be changed to it. - * - * @param int|null $position - * @return $this|static - */ - public function changeSort(int $position = null) - { - return $this->changeStatus('listed', $position); - } - - /** - * Changes the page template - * - * @param string $template - * @return $this|static - * @throws \Kirby\Exception\LogicException If the textfile cannot be renamed/moved - */ - public function changeTemplate(string $template) - { - if ($template === $this->intendedTemplate()->name()) { - return $this; - } - - return $this->commit('changeTemplate', ['page' => $this, 'template' => $template], function ($oldPage, $template) { - if ($this->kirby()->multilang() === true) { - $newPage = $this->clone([ - 'template' => $template - ]); - - foreach ($this->kirby()->languages()->codes() as $code) { - if ($oldPage->translation($code)->exists() !== true) { - continue; - } - - $content = $oldPage->content($code)->convertTo($template); - - if (F::remove($oldPage->contentFile($code)) !== true) { - throw new LogicException('The old text file could not be removed'); - } - - // save the language file - $newPage->save($content, $code); - } - - // return a fresh copy of the object - $page = $newPage->clone(); - } else { - $newPage = $this->clone([ - 'content' => $this->content()->convertTo($template), - 'template' => $template - ]); - - if (F::remove($oldPage->contentFile()) !== true) { - throw new LogicException('The old text file could not be removed'); - } - - $page = $newPage->save(); - } - - // update the parent collection - if ($page->isDraft() === true) { - $page->parentModel()->drafts()->set($page->id(), $page); - } else { - $page->parentModel()->children()->set($page->id(), $page); - } - - return $page; - }); - } - - /** - * Change the page title - * - * @param string $title - * @param string|null $languageCode - * @return static - */ - public function changeTitle(string $title, string $languageCode = null) - { - $arguments = ['page' => $this, 'title' => $title, 'languageCode' => $languageCode]; - return $this->commit('changeTitle', $arguments, function ($page, $title, $languageCode) { - $page = $page->save(['title' => $title], $languageCode); - - // flush the parent cache to get children and drafts right - if ($page->isDraft() === true) { - $page->parentModel()->drafts()->set($page->id(), $page); - } else { - $page->parentModel()->children()->set($page->id(), $page); - } - - return $page; - }); - } - - /** - * Commits a page action, by following these steps - * - * 1. checks the action rules - * 2. sends the before hook - * 3. commits the store action - * 4. sends the after hook - * 5. returns the result - * - * @param string $action - * @param array $arguments - * @param \Closure $callback - * @return mixed - */ - protected function commit(string $action, array $arguments, Closure $callback) - { - $old = $this->hardcopy(); - $kirby = $this->kirby(); - $argumentValues = array_values($arguments); - - $this->rules()->$action(...$argumentValues); - $kirby->trigger('page.' . $action . ':before', $arguments); - - $result = $callback(...$argumentValues); - - if ($action === 'create') { - $argumentsAfter = ['page' => $result]; - } elseif ($action === 'duplicate') { - $argumentsAfter = ['duplicatePage' => $result, 'originalPage' => $old]; - } elseif ($action === 'delete') { - $argumentsAfter = ['status' => $result, 'page' => $old]; - } else { - $argumentsAfter = ['newPage' => $result, 'oldPage' => $old]; - } - $kirby->trigger('page.' . $action . ':after', $argumentsAfter); - - $kirby->cache('pages')->flush(); - return $result; - } - - /** - * Copies the page to a new parent - * - * @param array $options - * @return \Kirby\Cms\Page - * @throws \Kirby\Exception\DuplicateException If the page already exists - */ - public function copy(array $options = []) - { - $slug = $options['slug'] ?? $this->slug(); - $isDraft = $options['isDraft'] ?? $this->isDraft(); - $parent = $options['parent'] ?? null; - $parentModel = $options['parent'] ?? $this->site(); - $num = $options['num'] ?? null; - $children = $options['children'] ?? false; - $files = $options['files'] ?? false; - - // clean up the slug - $slug = Str::slug($slug); - - if ($parentModel->findPageOrDraft($slug)) { - throw new DuplicateException([ - 'key' => 'page.duplicate', - 'data' => [ - 'slug' => $slug - ] - ]); - } - - $tmp = new static([ - 'isDraft' => $isDraft, - 'num' => $num, - 'parent' => $parent, - 'slug' => $slug, - ]); - - $ignore = [ - $this->kirby()->locks()->file($this) - ]; - - // don't copy files - if ($files === false) { - foreach ($this->files() as $file) { - $ignore[] = $file->root(); - - // append all content files - array_push($ignore, ...$file->contentFiles()); - } - } - - Dir::copy($this->root(), $tmp->root(), $children, $ignore); - - $copy = $parentModel->clone()->findPageOrDraft($slug); - - // remove all translated slugs - if ($this->kirby()->multilang() === true) { - foreach ($this->kirby()->languages() as $language) { - if ($language->isDefault() === false && $copy->translation($language)->exists() === true) { - $copy = $copy->save(['slug' => null], $language->code()); - } - } - } - - // add copy to siblings - if ($isDraft === true) { - $parentModel->drafts()->append($copy->id(), $copy); - } else { - $parentModel->children()->append($copy->id(), $copy); - } - - return $copy; - } - - /** - * Creates and stores a new page - * - * @param array $props - * @return static - */ - public static function create(array $props) - { - // clean up the slug - $props['slug'] = Str::slug($props['slug'] ?? $props['content']['title'] ?? null); - $props['template'] = $props['model'] = strtolower($props['template'] ?? 'default'); - $props['isDraft'] = ($props['draft'] ?? true); - - // create a temporary page object - $page = Page::factory($props); - - // create a form for the page - $form = Form::for($page, [ - 'values' => $props['content'] ?? [] - ]); - - // inject the content - $page = $page->clone(['content' => $form->strings(true)]); - - // run the hooks and creation action - $page = $page->commit('create', ['page' => $page, 'input' => $props], function ($page, $props) { - - // always create pages in the default language - if ($page->kirby()->multilang() === true) { - $languageCode = $page->kirby()->defaultLanguage()->code(); - } else { - $languageCode = null; - } - - // write the content file - $page = $page->save($page->content()->toArray(), $languageCode); - - // flush the parent cache to get children and drafts right - if ($page->isDraft() === true) { - $page->parentModel()->drafts()->append($page->id(), $page); - } else { - $page->parentModel()->children()->append($page->id(), $page); - } - - return $page; - }); - - // publish the new page if a number is given - if (isset($props['num']) === true) { - $page = $page->changeStatus('listed', $props['num']); - } - - return $page; - } - - /** - * Creates a child of the current page - * - * @param array $props - * @return static - */ - public function createChild(array $props) - { - $props = array_merge($props, [ - 'url' => null, - 'num' => null, - 'parent' => $this, - 'site' => $this->site(), - ]); - - $modelClass = Page::$models[$props['template']] ?? Page::class; - return $modelClass::create($props); - } - - /** - * Create the sorting number for the page - * depending on the blueprint settings - * - * @param int|null $num - * @return int - */ - public function createNum(int $num = null): int - { - $mode = $this->blueprint()->num(); - - switch ($mode) { - case 'zero': - return 0; - case 'date': - case 'datetime': - // the $format needs to produce only digits, - // so it can be converted to integer below - $format = $mode === 'date' ? 'Ymd' : 'YmdHi'; - $lang = $this->kirby()->defaultLanguage() ?? null; - $field = $this->content($lang)->get('date'); - $date = $field->isEmpty() ? 'now' : $field; - return (int)date($format, strtotime($date)); - case 'default': - - $max = $this - ->parentModel() - ->children() - ->listed() - ->merge($this) - ->count(); - - // default positioning at the end - if ($num === null) { - $num = $max; - } - - // avoid zeros or negative numbers - if ($num < 1) { - return 1; - } - - // avoid higher numbers than possible - if ($num > $max) { - return $max; - } - - return $num; - default: - // get instance with default language - $app = $this->kirby()->clone([], false); - $app->setCurrentLanguage(); - - $template = Str::template($mode, [ - 'kirby' => $app, - 'page' => $app->page($this->id()), - 'site' => $app->site(), - ], ['fallback' => '']); - - return (int)$template; - } - } - - /** - * Deletes the page - * - * @param bool $force - * @return bool - */ - public function delete(bool $force = false): bool - { - return $this->commit('delete', ['page' => $this, 'force' => $force], function ($page, $force) { - - // delete all files individually - foreach ($page->files() as $file) { - $file->delete(); - } - - // delete all children individually - foreach ($page->children() as $child) { - $child->delete(true); - } - - // actually remove the page from disc - if ($page->exists() === true) { - - // delete all public media files - Dir::remove($page->mediaRoot()); - - // delete the content folder for this page - Dir::remove($page->root()); - - // if the page is a draft and the _drafts folder - // is now empty. clean it up. - if ($page->isDraft() === true) { - $draftsDir = dirname($page->root()); - - if (Dir::isEmpty($draftsDir) === true) { - Dir::remove($draftsDir); - } - } - } - - if ($page->isDraft() === true) { - $page->parentModel()->drafts()->remove($page); - } else { - $page->parentModel()->children()->remove($page); - $page->resortSiblingsAfterUnlisting(); - } - - return true; - }); - } - - /** - * Duplicates the page with the given - * slug and optionally copies all files - * - * @param string|null $slug - * @param array $options - * @return \Kirby\Cms\Page - */ - public function duplicate(string $slug = null, array $options = []) - { - - // create the slug for the duplicate - $slug = Str::slug($slug ?? $this->slug() . '-' . Str::slug(I18n::translate('page.duplicate.appendix'))); - - $arguments = [ - 'originalPage' => $this, - 'input' => $slug, - 'options' => $options - ]; - - return $this->commit('duplicate', $arguments, function ($page, $slug, $options) { - $page = $this->copy([ - 'parent' => $this->parent(), - 'slug' => $slug, - 'isDraft' => true, - 'files' => $options['files'] ?? false, - 'children' => $options['children'] ?? false, - ]); - - if (isset($options['title']) === true) { - $page = $page->changeTitle($options['title']); - } - - return $page; - }); - } - - /** - * @return $this|static - * @throws \Kirby\Exception\LogicException If the folder cannot be moved - */ - public function publish() - { - if ($this->isDraft() === false) { - return $this; - } - - $page = $this->clone([ - 'isDraft' => false, - 'root' => null - ]); - - // actually do it on disk - if ($this->exists() === true) { - if (Dir::move($this->root(), $page->root()) !== true) { - throw new LogicException('The draft folder cannot be moved'); - } - - // Get the draft folder and check if there are any other drafts - // left. Otherwise delete it. - $draftDir = dirname($this->root()); - - if (Dir::isEmpty($draftDir) === true) { - Dir::remove($draftDir); - } - } - - // remove the page from the parent drafts and add it to children - $page->parentModel()->drafts()->remove($page); - $page->parentModel()->children()->append($page->id(), $page); - - return $page; - } - - /** - * Clean internal caches - * @return $this - */ - public function purge() - { - $this->blueprint = null; - $this->children = null; - $this->content = null; - $this->drafts = null; - $this->files = null; - $this->inventory = null; - $this->translations = null; - - return $this; - } - - /** - * @param int|null $position - * @return bool - * @throws \Kirby\Exception\LogicException If the page is not included in the siblings collection - */ - protected function resortSiblingsAfterListing(int $position = null): bool - { - // get all siblings including the current page - $siblings = $this - ->parentModel() - ->children() - ->listed() - ->append($this) - ->filter(fn ($page) => $page->blueprint()->num() === 'default'); - - // get a non-associative array of ids - $keys = $siblings->keys(); - $index = array_search($this->id(), $keys); - - // if the page is not included in the siblings something went wrong - if ($index === false) { - throw new LogicException('The page is not included in the sorting index'); - } - - if ($position > count($keys)) { - $position = count($keys); - } - - // move the current page number in the array of keys - // subtract 1 from the num and the position, because of the - // zero-based array keys - $sorted = A::move($keys, $index, $position - 1); - - foreach ($sorted as $key => $id) { - if ($id === $this->id()) { - continue; - } elseif ($sibling = $siblings->get($id)) { - $sibling->changeNum($key + 1); - } - } - - $parent = $this->parentModel(); - $parent->children = $parent->children()->sort('num', 'asc'); - - return true; - } - - /** - * @return bool - */ - public function resortSiblingsAfterUnlisting(): bool - { - $index = 0; - $parent = $this->parentModel(); - $siblings = $parent - ->children() - ->listed() - ->not($this) - ->filter(fn ($page) => $page->blueprint()->num() === 'default'); - - if ($siblings->count() > 0) { - foreach ($siblings as $sibling) { - $index++; - $sibling->changeNum($index); - } - - $parent->children = $siblings->sort('num', 'asc'); - } - - return true; - } - - /** - * Convert a page from listed or - * unlisted to draft. - * - * @return $this|static - * @throws \Kirby\Exception\LogicException If the folder cannot be moved - */ - public function unpublish() - { - if ($this->isDraft() === true) { - return $this; - } - - $page = $this->clone([ - 'isDraft' => true, - 'num' => null, - 'dirname' => null, - 'root' => null - ]); - - // actually do it on disk - if ($this->exists() === true) { - if (Dir::move($this->root(), $page->root()) !== true) { - throw new LogicException('The page folder cannot be moved to drafts'); - } - } - - // remove the page from the parent children and add it to drafts - $page->parentModel()->children()->remove($page); - $page->parentModel()->drafts()->append($page->id(), $page); - - $page->resortSiblingsAfterUnlisting(); - - return $page; - } - - /** - * Updates the page data - * - * @param array|null $input - * @param string|null $languageCode - * @param bool $validate - * @return static - */ - public function update(array $input = null, string $languageCode = null, bool $validate = false) - { - if ($this->isDraft() === true) { - $validate = false; - } - - $page = parent::update($input, $languageCode, $validate); - - // if num is created from page content, update num on content update - if ($page->isListed() === true && in_array($page->blueprint()->num(), ['zero', 'default']) === false) { - $page = $page->changeNum($page->createNum()); - } - - return $page; - } + /** + * Changes the sorting number. + * The sorting number must already be correct + * when the method is called. + * This only affects this page, + * siblings will not be resorted. + * + * @param int|null $num + * @return $this|static + * @throws \Kirby\Exception\LogicException If a draft is being sorted or the directory cannot be moved + */ + public function changeNum(int $num = null) + { + if ($this->isDraft() === true) { + throw new LogicException('Drafts cannot change their sorting number'); + } + + // don't run the action if everything stayed the same + if ($this->num() === $num) { + return $this; + } + + return $this->commit('changeNum', ['page' => $this, 'num' => $num], function ($oldPage, $num) { + $newPage = $oldPage->clone([ + 'num' => $num, + 'dirname' => null, + 'root' => null + ]); + + // actually move the page on disk + if ($oldPage->exists() === true) { + if (Dir::move($oldPage->root(), $newPage->root()) === true) { + // Updates the root path of the old page with the root path + // of the moved new page to use fly actions on old page in loop + $oldPage->setRoot($newPage->root()); + } else { + throw new LogicException('The page directory cannot be moved'); + } + } + + // overwrite the child in the parent page + $newPage + ->parentModel() + ->children() + ->set($newPage->id(), $newPage); + + return $newPage; + }); + } + + /** + * Changes the slug/uid of the page + * + * @param string $slug + * @param string|null $languageCode + * @return $this|static + * @throws \Kirby\Exception\LogicException If the directory cannot be moved + */ + public function changeSlug(string $slug, string $languageCode = null) + { + // always sanitize the slug + $slug = Str::slug($slug); + + // in multi-language installations the slug for the non-default + // languages is stored in the text file. The changeSlugForLanguage + // method takes care of that. + if ($language = $this->kirby()->language($languageCode)) { + if ($language->isDefault() === false) { + return $this->changeSlugForLanguage($slug, $languageCode); + } + } + + // if the slug stays exactly the same, + // nothing needs to be done. + if ($slug === $this->slug()) { + return $this; + } + + $arguments = ['page' => $this, 'slug' => $slug, 'languageCode' => null]; + return $this->commit('changeSlug', $arguments, function ($oldPage, $slug) { + $newPage = $oldPage->clone([ + 'slug' => $slug, + 'dirname' => null, + 'root' => null + ]); + + if ($oldPage->exists() === true) { + // remove the lock of the old page + if ($lock = $oldPage->lock()) { + $lock->remove(); + } + + // actually move stuff on disk + if (Dir::move($oldPage->root(), $newPage->root()) !== true) { + throw new LogicException('The page directory cannot be moved'); + } + + // remove from the siblings + $oldPage->parentModel()->children()->remove($oldPage); + + Dir::remove($oldPage->mediaRoot()); + } + + // overwrite the new page in the parent collection + if ($newPage->isDraft() === true) { + $newPage->parentModel()->drafts()->set($newPage->id(), $newPage); + } else { + $newPage->parentModel()->children()->set($newPage->id(), $newPage); + } + + return $newPage; + }); + } + + /** + * Change the slug for a specific language + * + * @param string $slug + * @param string|null $languageCode + * @return static + * @throws \Kirby\Exception\NotFoundException If the language for the given language code cannot be found + * @throws \Kirby\Exception\InvalidArgumentException If the slug for the default language is being changed + */ + protected function changeSlugForLanguage(string $slug, string $languageCode = null) + { + $language = $this->kirby()->language($languageCode); + + if (!$language) { + throw new NotFoundException('The language: "' . $languageCode . '" does not exist'); + } + + if ($language->isDefault() === true) { + throw new InvalidArgumentException('Use the changeSlug method to change the slug for the default language'); + } + + $arguments = ['page' => $this, 'slug' => $slug, 'languageCode' => $languageCode]; + return $this->commit('changeSlug', $arguments, function ($page, $slug, $languageCode) { + // remove the slug if it's the same as the folder name + if ($slug === $page->uid()) { + $slug = null; + } + + return $page->save(['slug' => $slug], $languageCode); + }); + } + + /** + * Change the status of the current page + * to either draft, listed or unlisted. + * If changing to `listed`, you can pass a position for the + * page in the siblings collection. Siblings will be resorted. + * + * @param string $status "draft", "listed" or "unlisted" + * @param int|null $position Optional sorting number + * @return static + * @throws \Kirby\Exception\InvalidArgumentException If an invalid status is being passed + */ + public function changeStatus(string $status, int $position = null) + { + switch ($status) { + case 'draft': + return $this->changeStatusToDraft(); + case 'listed': + return $this->changeStatusToListed($position); + case 'unlisted': + return $this->changeStatusToUnlisted(); + default: + throw new InvalidArgumentException('Invalid status: ' . $status); + } + } + + /** + * @return static + */ + protected function changeStatusToDraft() + { + $arguments = ['page' => $this, 'status' => 'draft', 'position' => null]; + $page = $this->commit( + 'changeStatus', + $arguments, + fn ($page) => $page->unpublish() + ); + + return $page; + } + + /** + * @param int|null $position + * @return $this|static + */ + protected function changeStatusToListed(int $position = null) + { + // create a sorting number for the page + $num = $this->createNum($position); + + // don't sort if not necessary + if ($this->status() === 'listed' && $num === $this->num()) { + return $this; + } + + $arguments = ['page' => $this, 'status' => 'listed', 'position' => $num]; + $page = $this->commit('changeStatus', $arguments, function ($page, $status, $position) { + return $page->publish()->changeNum($position); + }); + + if ($this->blueprint()->num() === 'default') { + $page->resortSiblingsAfterListing($num); + } + + return $page; + } + + /** + * @return $this|static + */ + protected function changeStatusToUnlisted() + { + if ($this->status() === 'unlisted') { + return $this; + } + + $arguments = ['page' => $this, 'status' => 'unlisted', 'position' => null]; + $page = $this->commit('changeStatus', $arguments, function ($page) { + return $page->publish()->changeNum(null); + }); + + $this->resortSiblingsAfterUnlisting(); + + return $page; + } + + /** + * Change the position of the page in its siblings + * collection. Siblings will be resorted. If the page + * status isn't yet `listed`, it will be changed to it. + * + * @param int|null $position + * @return $this|static + */ + public function changeSort(int $position = null) + { + return $this->changeStatus('listed', $position); + } + + /** + * Changes the page template + * + * @param string $template + * @return $this|static + * @throws \Kirby\Exception\LogicException If the textfile cannot be renamed/moved + */ + public function changeTemplate(string $template) + { + if ($template === $this->intendedTemplate()->name()) { + return $this; + } + + return $this->commit('changeTemplate', ['page' => $this, 'template' => $template], function ($oldPage, $template) { + if ($this->kirby()->multilang() === true) { + $newPage = $this->clone([ + 'template' => $template + ]); + + foreach ($this->kirby()->languages()->codes() as $code) { + if ($oldPage->translation($code)->exists() !== true) { + continue; + } + + $content = $oldPage->content($code)->convertTo($template); + + if (F::remove($oldPage->contentFile($code)) !== true) { + throw new LogicException('The old text file could not be removed'); + } + + // save the language file + $newPage->save($content, $code); + } + + // return a fresh copy of the object + $page = $newPage->clone(); + } else { + $newPage = $this->clone([ + 'content' => $this->content()->convertTo($template), + 'template' => $template + ]); + + if (F::remove($oldPage->contentFile()) !== true) { + throw new LogicException('The old text file could not be removed'); + } + + $page = $newPage->save(); + } + + // update the parent collection + if ($page->isDraft() === true) { + $page->parentModel()->drafts()->set($page->id(), $page); + } else { + $page->parentModel()->children()->set($page->id(), $page); + } + + return $page; + }); + } + + /** + * Change the page title + * + * @param string $title + * @param string|null $languageCode + * @return static + */ + public function changeTitle(string $title, string $languageCode = null) + { + $arguments = ['page' => $this, 'title' => $title, 'languageCode' => $languageCode]; + return $this->commit('changeTitle', $arguments, function ($page, $title, $languageCode) { + $page = $page->save(['title' => $title], $languageCode); + + // flush the parent cache to get children and drafts right + if ($page->isDraft() === true) { + $page->parentModel()->drafts()->set($page->id(), $page); + } else { + $page->parentModel()->children()->set($page->id(), $page); + } + + return $page; + }); + } + + /** + * Commits a page action, by following these steps + * + * 1. checks the action rules + * 2. sends the before hook + * 3. commits the store action + * 4. sends the after hook + * 5. returns the result + * + * @param string $action + * @param array $arguments + * @param \Closure $callback + * @return mixed + */ + protected function commit(string $action, array $arguments, Closure $callback) + { + $old = $this->hardcopy(); + $kirby = $this->kirby(); + $argumentValues = array_values($arguments); + + $this->rules()->$action(...$argumentValues); + $kirby->trigger('page.' . $action . ':before', $arguments); + + $result = $callback(...$argumentValues); + + if ($action === 'create') { + $argumentsAfter = ['page' => $result]; + } elseif ($action === 'duplicate') { + $argumentsAfter = ['duplicatePage' => $result, 'originalPage' => $old]; + } elseif ($action === 'delete') { + $argumentsAfter = ['status' => $result, 'page' => $old]; + } else { + $argumentsAfter = ['newPage' => $result, 'oldPage' => $old]; + } + $kirby->trigger('page.' . $action . ':after', $argumentsAfter); + + $kirby->cache('pages')->flush(); + return $result; + } + + /** + * Copies the page to a new parent + * + * @param array $options + * @return \Kirby\Cms\Page + * @throws \Kirby\Exception\DuplicateException If the page already exists + */ + public function copy(array $options = []) + { + $slug = $options['slug'] ?? $this->slug(); + $isDraft = $options['isDraft'] ?? $this->isDraft(); + $parent = $options['parent'] ?? null; + $parentModel = $options['parent'] ?? $this->site(); + $num = $options['num'] ?? null; + $children = $options['children'] ?? false; + $files = $options['files'] ?? false; + + // clean up the slug + $slug = Str::slug($slug); + + if ($parentModel->findPageOrDraft($slug)) { + throw new DuplicateException([ + 'key' => 'page.duplicate', + 'data' => [ + 'slug' => $slug + ] + ]); + } + + $tmp = new static([ + 'isDraft' => $isDraft, + 'num' => $num, + 'parent' => $parent, + 'slug' => $slug, + ]); + + $ignore = [ + $this->kirby()->locks()->file($this) + ]; + + // don't copy files + if ($files === false) { + foreach ($this->files() as $file) { + $ignore[] = $file->root(); + + // append all content files + array_push($ignore, ...$file->contentFiles()); + } + } + + Dir::copy($this->root(), $tmp->root(), $children, $ignore); + + $copy = $parentModel->clone()->findPageOrDraft($slug); + + // remove all translated slugs + if ($this->kirby()->multilang() === true) { + foreach ($this->kirby()->languages() as $language) { + if ($language->isDefault() === false && $copy->translation($language)->exists() === true) { + $copy = $copy->save(['slug' => null], $language->code()); + } + } + } + + // add copy to siblings + if ($isDraft === true) { + $parentModel->drafts()->append($copy->id(), $copy); + } else { + $parentModel->children()->append($copy->id(), $copy); + } + + return $copy; + } + + /** + * Creates and stores a new page + * + * @param array $props + * @return static + */ + public static function create(array $props) + { + // clean up the slug + $props['slug'] = Str::slug($props['slug'] ?? $props['content']['title'] ?? null); + $props['template'] = $props['model'] = strtolower($props['template'] ?? 'default'); + $props['isDraft'] = ($props['draft'] ?? true); + + // create a temporary page object + $page = Page::factory($props); + + // create a form for the page + $form = Form::for($page, [ + 'values' => $props['content'] ?? [] + ]); + + // inject the content + $page = $page->clone(['content' => $form->strings(true)]); + + // run the hooks and creation action + $page = $page->commit('create', ['page' => $page, 'input' => $props], function ($page, $props) { + + // always create pages in the default language + if ($page->kirby()->multilang() === true) { + $languageCode = $page->kirby()->defaultLanguage()->code(); + } else { + $languageCode = null; + } + + // write the content file + $page = $page->save($page->content()->toArray(), $languageCode); + + // flush the parent cache to get children and drafts right + if ($page->isDraft() === true) { + $page->parentModel()->drafts()->append($page->id(), $page); + } else { + $page->parentModel()->children()->append($page->id(), $page); + } + + return $page; + }); + + // publish the new page if a number is given + if (isset($props['num']) === true) { + $page = $page->changeStatus('listed', $props['num']); + } + + return $page; + } + + /** + * Creates a child of the current page + * + * @param array $props + * @return static + */ + public function createChild(array $props) + { + $props = array_merge($props, [ + 'url' => null, + 'num' => null, + 'parent' => $this, + 'site' => $this->site(), + ]); + + $modelClass = Page::$models[$props['template']] ?? Page::class; + return $modelClass::create($props); + } + + /** + * Create the sorting number for the page + * depending on the blueprint settings + * + * @param int|null $num + * @return int + */ + public function createNum(int $num = null): int + { + $mode = $this->blueprint()->num(); + + switch ($mode) { + case 'zero': + return 0; + case 'date': + case 'datetime': + // the $format needs to produce only digits, + // so it can be converted to integer below + $format = $mode === 'date' ? 'Ymd' : 'YmdHi'; + $lang = $this->kirby()->defaultLanguage() ?? null; + $field = $this->content($lang)->get('date'); + $date = $field->isEmpty() ? 'now' : $field; + return (int)date($format, strtotime($date)); + case 'default': + + $max = $this + ->parentModel() + ->children() + ->listed() + ->merge($this) + ->count(); + + // default positioning at the end + if ($num === null) { + $num = $max; + } + + // avoid zeros or negative numbers + if ($num < 1) { + return 1; + } + + // avoid higher numbers than possible + if ($num > $max) { + return $max; + } + + return $num; + default: + // get instance with default language + $app = $this->kirby()->clone([], false); + $app->setCurrentLanguage(); + + $template = Str::template($mode, [ + 'kirby' => $app, + 'page' => $app->page($this->id()), + 'site' => $app->site(), + ], ['fallback' => '']); + + return (int)$template; + } + } + + /** + * Deletes the page + * + * @param bool $force + * @return bool + */ + public function delete(bool $force = false): bool + { + return $this->commit('delete', ['page' => $this, 'force' => $force], function ($page, $force) { + + // delete all files individually + foreach ($page->files() as $file) { + $file->delete(); + } + + // delete all children individually + foreach ($page->children() as $child) { + $child->delete(true); + } + + // actually remove the page from disc + if ($page->exists() === true) { + + // delete all public media files + Dir::remove($page->mediaRoot()); + + // delete the content folder for this page + Dir::remove($page->root()); + + // if the page is a draft and the _drafts folder + // is now empty. clean it up. + if ($page->isDraft() === true) { + $draftsDir = dirname($page->root()); + + if (Dir::isEmpty($draftsDir) === true) { + Dir::remove($draftsDir); + } + } + } + + if ($page->isDraft() === true) { + $page->parentModel()->drafts()->remove($page); + } else { + $page->parentModel()->children()->remove($page); + $page->resortSiblingsAfterUnlisting(); + } + + return true; + }); + } + + /** + * Duplicates the page with the given + * slug and optionally copies all files + * + * @param string|null $slug + * @param array $options + * @return \Kirby\Cms\Page + */ + public function duplicate(string $slug = null, array $options = []) + { + + // create the slug for the duplicate + $slug = Str::slug($slug ?? $this->slug() . '-' . Str::slug(I18n::translate('page.duplicate.appendix'))); + + $arguments = [ + 'originalPage' => $this, + 'input' => $slug, + 'options' => $options + ]; + + return $this->commit('duplicate', $arguments, function ($page, $slug, $options) { + $page = $this->copy([ + 'parent' => $this->parent(), + 'slug' => $slug, + 'isDraft' => true, + 'files' => $options['files'] ?? false, + 'children' => $options['children'] ?? false, + ]); + + if (isset($options['title']) === true) { + $page = $page->changeTitle($options['title']); + } + + return $page; + }); + } + + /** + * @return $this|static + * @throws \Kirby\Exception\LogicException If the folder cannot be moved + */ + public function publish() + { + if ($this->isDraft() === false) { + return $this; + } + + $page = $this->clone([ + 'isDraft' => false, + 'root' => null + ]); + + // actually do it on disk + if ($this->exists() === true) { + if (Dir::move($this->root(), $page->root()) !== true) { + throw new LogicException('The draft folder cannot be moved'); + } + + // Get the draft folder and check if there are any other drafts + // left. Otherwise delete it. + $draftDir = dirname($this->root()); + + if (Dir::isEmpty($draftDir) === true) { + Dir::remove($draftDir); + } + } + + // remove the page from the parent drafts and add it to children + $page->parentModel()->drafts()->remove($page); + $page->parentModel()->children()->append($page->id(), $page); + + return $page; + } + + /** + * Clean internal caches + * @return $this + */ + public function purge() + { + $this->blueprint = null; + $this->children = null; + $this->content = null; + $this->drafts = null; + $this->files = null; + $this->inventory = null; + $this->translations = null; + + return $this; + } + + /** + * @param int|null $position + * @return bool + * @throws \Kirby\Exception\LogicException If the page is not included in the siblings collection + */ + protected function resortSiblingsAfterListing(int $position = null): bool + { + // get all siblings including the current page + $siblings = $this + ->parentModel() + ->children() + ->listed() + ->append($this) + ->filter(fn ($page) => $page->blueprint()->num() === 'default'); + + // get a non-associative array of ids + $keys = $siblings->keys(); + $index = array_search($this->id(), $keys); + + // if the page is not included in the siblings something went wrong + if ($index === false) { + throw new LogicException('The page is not included in the sorting index'); + } + + if ($position > count($keys)) { + $position = count($keys); + } + + // move the current page number in the array of keys + // subtract 1 from the num and the position, because of the + // zero-based array keys + $sorted = A::move($keys, $index, $position - 1); + + foreach ($sorted as $key => $id) { + if ($id === $this->id()) { + continue; + } elseif ($sibling = $siblings->get($id)) { + $sibling->changeNum($key + 1); + } + } + + $parent = $this->parentModel(); + $parent->children = $parent->children()->sort('num', 'asc'); + + return true; + } + + /** + * @return bool + */ + public function resortSiblingsAfterUnlisting(): bool + { + $index = 0; + $parent = $this->parentModel(); + $siblings = $parent + ->children() + ->listed() + ->not($this) + ->filter(fn ($page) => $page->blueprint()->num() === 'default'); + + if ($siblings->count() > 0) { + foreach ($siblings as $sibling) { + $index++; + $sibling->changeNum($index); + } + + $parent->children = $siblings->sort('num', 'asc'); + } + + return true; + } + + /** + * Convert a page from listed or + * unlisted to draft. + * + * @return $this|static + * @throws \Kirby\Exception\LogicException If the folder cannot be moved + */ + public function unpublish() + { + if ($this->isDraft() === true) { + return $this; + } + + $page = $this->clone([ + 'isDraft' => true, + 'num' => null, + 'dirname' => null, + 'root' => null + ]); + + // actually do it on disk + if ($this->exists() === true) { + if (Dir::move($this->root(), $page->root()) !== true) { + throw new LogicException('The page folder cannot be moved to drafts'); + } + } + + // remove the page from the parent children and add it to drafts + $page->parentModel()->children()->remove($page); + $page->parentModel()->drafts()->append($page->id(), $page); + + $page->resortSiblingsAfterUnlisting(); + + return $page; + } + + /** + * Updates the page data + * + * @param array|null $input + * @param string|null $languageCode + * @param bool $validate + * @return static + */ + public function update(array $input = null, string $languageCode = null, bool $validate = false) + { + if ($this->isDraft() === true) { + $validate = false; + } + + $page = parent::update($input, $languageCode, $validate); + + // if num is created from page content, update num on content update + if ($page->isListed() === true && in_array($page->blueprint()->num(), ['zero', 'default']) === false) { + $page = $page->changeNum($page->createNum()); + } + + return $page; + } } diff --git a/kirby/src/Cms/PageBlueprint.php b/kirby/src/Cms/PageBlueprint.php index a8d15e5..0a5e9bf 100755 --- a/kirby/src/Cms/PageBlueprint.php +++ b/kirby/src/Cms/PageBlueprint.php @@ -13,197 +13,197 @@ namespace Kirby\Cms; */ class PageBlueprint extends Blueprint { - /** - * Creates a new page blueprint object - * with the given props - * - * @param array $props - */ - public function __construct(array $props) - { - parent::__construct($props); + /** + * Creates a new page blueprint object + * with the given props + * + * @param array $props + */ + public function __construct(array $props) + { + parent::__construct($props); - // normalize all available page options - $this->props['options'] = $this->normalizeOptions( - $this->props['options'] ?? true, - // defaults - [ - 'changeSlug' => null, - 'changeStatus' => null, - 'changeTemplate' => null, - 'changeTitle' => null, - 'create' => null, - 'delete' => null, - 'duplicate' => null, - 'read' => null, - 'preview' => null, - 'sort' => null, - 'update' => null, - ], - // aliases (from v2) - [ - 'status' => 'changeStatus', - 'template' => 'changeTemplate', - 'title' => 'changeTitle', - 'url' => 'changeSlug', - ] - ); + // normalize all available page options + $this->props['options'] = $this->normalizeOptions( + $this->props['options'] ?? true, + // defaults + [ + 'changeSlug' => null, + 'changeStatus' => null, + 'changeTemplate' => null, + 'changeTitle' => null, + 'create' => null, + 'delete' => null, + 'duplicate' => null, + 'read' => null, + 'preview' => null, + 'sort' => null, + 'update' => null, + ], + // aliases (from v2) + [ + 'status' => 'changeStatus', + 'template' => 'changeTemplate', + 'title' => 'changeTitle', + 'url' => 'changeSlug', + ] + ); - // normalize the ordering number - $this->props['num'] = $this->normalizeNum($this->props['num'] ?? 'default'); + // normalize the ordering number + $this->props['num'] = $this->normalizeNum($this->props['num'] ?? 'default'); - // normalize the available status array - $this->props['status'] = $this->normalizeStatus($this->props['status'] ?? null); - } + // normalize the available status array + $this->props['status'] = $this->normalizeStatus($this->props['status'] ?? null); + } - /** - * Returns the page numbering mode - * - * @return string - */ - public function num(): string - { - return $this->props['num']; - } + /** + * Returns the page numbering mode + * + * @return string + */ + public function num(): string + { + return $this->props['num']; + } - /** - * Normalizes the ordering number - * - * @param mixed $num - * @return string - */ - protected function normalizeNum($num): string - { - $aliases = [ - '0' => 'zero', - 'sort' => 'default', - ]; + /** + * Normalizes the ordering number + * + * @param mixed $num + * @return string + */ + protected function normalizeNum($num): string + { + $aliases = [ + '0' => 'zero', + 'sort' => 'default', + ]; - if (isset($aliases[$num]) === true) { - return $aliases[$num]; - } + if (isset($aliases[$num]) === true) { + return $aliases[$num]; + } - return $num; - } + return $num; + } - /** - * Normalizes the available status options for the page - * - * @param mixed $status - * @return array - */ - protected function normalizeStatus($status): array - { - $defaults = [ - 'draft' => [ - 'label' => $this->i18n('page.status.draft'), - 'text' => $this->i18n('page.status.draft.description'), - ], - 'unlisted' => [ - 'label' => $this->i18n('page.status.unlisted'), - 'text' => $this->i18n('page.status.unlisted.description'), - ], - 'listed' => [ - 'label' => $this->i18n('page.status.listed'), - 'text' => $this->i18n('page.status.listed.description'), - ] - ]; + /** + * Normalizes the available status options for the page + * + * @param mixed $status + * @return array + */ + protected function normalizeStatus($status): array + { + $defaults = [ + 'draft' => [ + 'label' => $this->i18n('page.status.draft'), + 'text' => $this->i18n('page.status.draft.description'), + ], + 'unlisted' => [ + 'label' => $this->i18n('page.status.unlisted'), + 'text' => $this->i18n('page.status.unlisted.description'), + ], + 'listed' => [ + 'label' => $this->i18n('page.status.listed'), + 'text' => $this->i18n('page.status.listed.description'), + ] + ]; - // use the defaults, when the status is not defined - if (empty($status) === true) { - $status = $defaults; - } + // use the defaults, when the status is not defined + if (empty($status) === true) { + $status = $defaults; + } - // extend the status definition - $status = $this->extend($status); + // extend the status definition + $status = $this->extend($status); - // clean up and translate each status - foreach ($status as $key => $options) { + // clean up and translate each status + foreach ($status as $key => $options) { - // skip invalid status definitions - if (in_array($key, ['draft', 'listed', 'unlisted']) === false || $options === false) { - unset($status[$key]); - continue; - } + // skip invalid status definitions + if (in_array($key, ['draft', 'listed', 'unlisted']) === false || $options === false) { + unset($status[$key]); + continue; + } - if ($options === true) { - $status[$key] = $defaults[$key]; - continue; - } + if ($options === true) { + $status[$key] = $defaults[$key]; + continue; + } - // convert everything to a simple array - if (is_array($options) === false) { - $status[$key] = [ - 'label' => $options, - 'text' => null - ]; - } + // convert everything to a simple array + if (is_array($options) === false) { + $status[$key] = [ + 'label' => $options, + 'text' => null + ]; + } - // always make sure to have a proper label - if (empty($status[$key]['label']) === true) { - $status[$key]['label'] = $defaults[$key]['label']; - } + // always make sure to have a proper label + if (empty($status[$key]['label']) === true) { + $status[$key]['label'] = $defaults[$key]['label']; + } - // also make sure to have the text field set - if (isset($status[$key]['text']) === false) { - $status[$key]['text'] = null; - } + // also make sure to have the text field set + if (isset($status[$key]['text']) === false) { + $status[$key]['text'] = null; + } - // translate text and label if necessary - $status[$key]['label'] = $this->i18n($status[$key]['label'], $status[$key]['label']); - $status[$key]['text'] = $this->i18n($status[$key]['text'], $status[$key]['text']); - } + // translate text and label if necessary + $status[$key]['label'] = $this->i18n($status[$key]['label'], $status[$key]['label']); + $status[$key]['text'] = $this->i18n($status[$key]['text'], $status[$key]['text']); + } - // the draft status is required - if (isset($status['draft']) === false) { - $status = ['draft' => $defaults['draft']] + $status; - } + // the draft status is required + if (isset($status['draft']) === false) { + $status = ['draft' => $defaults['draft']] + $status; + } - // remove the draft status for the home and error pages - if ($this->model->isHomeOrErrorPage() === true) { - unset($status['draft']); - } + // remove the draft status for the home and error pages + if ($this->model->isHomeOrErrorPage() === true) { + unset($status['draft']); + } - return $status; - } + return $status; + } - /** - * Returns the options object - * that handles page options and permissions - * - * @return array - */ - public function options(): array - { - return $this->props['options']; - } + /** + * Returns the options object + * that handles page options and permissions + * + * @return array + */ + public function options(): array + { + return $this->props['options']; + } - /** - * Returns the preview settings - * The preview setting controls the "Open" - * button in the panel and redirects it to a - * different URL if necessary. - * - * @return string|bool - */ - public function preview() - { - $preview = $this->props['options']['preview'] ?? true; + /** + * Returns the preview settings + * The preview setting controls the "Open" + * button in the panel and redirects it to a + * different URL if necessary. + * + * @return string|bool + */ + public function preview() + { + $preview = $this->props['options']['preview'] ?? true; - if (is_string($preview) === true) { - return $this->model->toString($preview); - } + if (is_string($preview) === true) { + return $this->model->toString($preview); + } - return $preview; - } + return $preview; + } - /** - * Returns the status array - * - * @return array - */ - public function status(): array - { - return $this->props['status']; - } + /** + * Returns the status array + * + * @return array + */ + public function status(): array + { + return $this->props['status']; + } } diff --git a/kirby/src/Cms/PagePermissions.php b/kirby/src/Cms/PagePermissions.php index 9943235..53fcb84 100755 --- a/kirby/src/Cms/PagePermissions.php +++ b/kirby/src/Cms/PagePermissions.php @@ -13,68 +13,68 @@ namespace Kirby\Cms; */ class PagePermissions extends ModelPermissions { - /** - * @var string - */ - protected $category = 'pages'; + /** + * @var string + */ + protected $category = 'pages'; - /** - * @return bool - */ - protected function canChangeSlug(): bool - { - return $this->model->isHomeOrErrorPage() !== true; - } + /** + * @return bool + */ + protected function canChangeSlug(): bool + { + return $this->model->isHomeOrErrorPage() !== true; + } - /** - * @return bool - */ - protected function canChangeStatus(): bool - { - return $this->model->isErrorPage() !== true; - } + /** + * @return bool + */ + protected function canChangeStatus(): bool + { + return $this->model->isErrorPage() !== true; + } - /** - * @return bool - */ - protected function canChangeTemplate(): bool - { - if ($this->model->isHomeOrErrorPage() === true) { - return false; - } + /** + * @return bool + */ + protected function canChangeTemplate(): bool + { + if ($this->model->isHomeOrErrorPage() === true) { + return false; + } - if (count($this->model->blueprints()) <= 1) { - return false; - } + if (count($this->model->blueprints()) <= 1) { + return false; + } - return true; - } + return true; + } - /** - * @return bool - */ - protected function canDelete(): bool - { - return $this->model->isHomeOrErrorPage() !== true; - } + /** + * @return bool + */ + protected function canDelete(): bool + { + return $this->model->isHomeOrErrorPage() !== true; + } - /** - * @return bool - */ - protected function canSort(): bool - { - if ($this->model->isErrorPage() === true) { - return false; - } + /** + * @return bool + */ + protected function canSort(): bool + { + if ($this->model->isErrorPage() === true) { + return false; + } - if ($this->model->isListed() !== true) { - return false; - } + if ($this->model->isListed() !== true) { + return false; + } - if ($this->model->blueprint()->num() !== 'default') { - return false; - } + if ($this->model->blueprint()->num() !== 'default') { + return false; + } - return true; - } + return true; + } } diff --git a/kirby/src/Cms/PagePicker.php b/kirby/src/Cms/PagePicker.php index 6bc74d7..802e7e8 100755 --- a/kirby/src/Cms/PagePicker.php +++ b/kirby/src/Cms/PagePicker.php @@ -18,248 +18,248 @@ use Kirby\Exception\InvalidArgumentException; */ class PagePicker extends Picker { - /** - * @var \Kirby\Cms\Pages - */ - protected $items; + /** + * @var \Kirby\Cms\Pages + */ + protected $items; - /** - * @var \Kirby\Cms\Pages - */ - protected $itemsForQuery; + /** + * @var \Kirby\Cms\Pages + */ + protected $itemsForQuery; - /** - * @var \Kirby\Cms\Page|\Kirby\Cms\Site|null - */ - protected $parent; + /** + * @var \Kirby\Cms\Page|\Kirby\Cms\Site|null + */ + protected $parent; - /** - * Extends the basic defaults - * - * @return array - */ - public function defaults(): array - { - return array_merge(parent::defaults(), [ - // Page ID of the selected parent. Used to navigate - 'parent' => null, - // enable/disable subpage navigation - 'subpages' => true, - ]); - } + /** + * Extends the basic defaults + * + * @return array + */ + public function defaults(): array + { + return array_merge(parent::defaults(), [ + // Page ID of the selected parent. Used to navigate + 'parent' => null, + // enable/disable subpage navigation + 'subpages' => true, + ]); + } - /** - * Returns the parent model object that - * is currently selected in the page picker. - * It normally starts at the site, but can - * also be any subpage. When a query is given - * and subpage navigation is deactivated, - * there will be no model available at all. - * - * @return \Kirby\Cms\Page|\Kirby\Cms\Site|null - */ - public function model() - { - // no subpages navigation = no model - if ($this->options['subpages'] === false) { - return null; - } + /** + * Returns the parent model object that + * is currently selected in the page picker. + * It normally starts at the site, but can + * also be any subpage. When a query is given + * and subpage navigation is deactivated, + * there will be no model available at all. + * + * @return \Kirby\Cms\Page|\Kirby\Cms\Site|null + */ + public function model() + { + // no subpages navigation = no model + if ($this->options['subpages'] === false) { + return null; + } - // the model for queries is a bit more tricky to find - if (empty($this->options['query']) === false) { - return $this->modelForQuery(); - } + // the model for queries is a bit more tricky to find + if (empty($this->options['query']) === false) { + return $this->modelForQuery(); + } - return $this->parent(); - } + return $this->parent(); + } - /** - * Returns a model object for the given - * query, depending on the parent and subpages - * options. - * - * @return \Kirby\Cms\Page|\Kirby\Cms\Site|null - */ - public function modelForQuery() - { - if ($this->options['subpages'] === true && empty($this->options['parent']) === false) { - return $this->parent(); - } + /** + * Returns a model object for the given + * query, depending on the parent and subpages + * options. + * + * @return \Kirby\Cms\Page|\Kirby\Cms\Site|null + */ + public function modelForQuery() + { + if ($this->options['subpages'] === true && empty($this->options['parent']) === false) { + return $this->parent(); + } - if ($items = $this->items()) { - return $items->parent(); - } + if ($items = $this->items()) { + return $items->parent(); + } - return null; - } + return null; + } - /** - * Returns basic information about the - * parent model that is currently selected - * in the page picker. - * - * @param \Kirby\Cms\Site|\Kirby\Cms\Page|null - * @return array|null - */ - public function modelToArray($model = null): ?array - { - if ($model === null) { - return null; - } + /** + * Returns basic information about the + * parent model that is currently selected + * in the page picker. + * + * @param \Kirby\Cms\Site|\Kirby\Cms\Page|null + * @return array|null + */ + public function modelToArray($model = null): ?array + { + if ($model === null) { + return null; + } - // the selected model is the site. there's nothing above - if (is_a($model, 'Kirby\Cms\Site') === true) { - return [ - 'id' => null, - 'parent' => null, - 'title' => $model->title()->value() - ]; - } + // the selected model is the site. there's nothing above + if (is_a($model, 'Kirby\Cms\Site') === true) { + return [ + 'id' => null, + 'parent' => null, + 'title' => $model->title()->value() + ]; + } - // the top-most page has been reached - // the missing id indicates that there's nothing above - if ($model->id() === $this->start()->id()) { - return [ - 'id' => null, - 'parent' => null, - 'title' => $model->title()->value() - ]; - } + // the top-most page has been reached + // the missing id indicates that there's nothing above + if ($model->id() === $this->start()->id()) { + return [ + 'id' => null, + 'parent' => null, + 'title' => $model->title()->value() + ]; + } - // the model is a regular page - return [ - 'id' => $model->id(), - 'parent' => $model->parentModel()->id(), - 'title' => $model->title()->value() - ]; - } + // the model is a regular page + return [ + 'id' => $model->id(), + 'parent' => $model->parentModel()->id(), + 'title' => $model->title()->value() + ]; + } - /** - * Search all pages for the picker - * - * @return \Kirby\Cms\Pages|null - */ - public function items() - { - // cache - if ($this->items !== null) { - return $this->items; - } + /** + * Search all pages for the picker + * + * @return \Kirby\Cms\Pages|null + */ + public function items() + { + // cache + if ($this->items !== null) { + return $this->items; + } - // no query? simple parent-based search for pages - if (empty($this->options['query']) === true) { - $items = $this->itemsForParent(); + // no query? simple parent-based search for pages + if (empty($this->options['query']) === true) { + $items = $this->itemsForParent(); - // when subpage navigation is enabled, a parent - // might be passed in addition to the query. - // The parent then takes priority. - } elseif ($this->options['subpages'] === true && empty($this->options['parent']) === false) { - $items = $this->itemsForParent(); + // when subpage navigation is enabled, a parent + // might be passed in addition to the query. + // The parent then takes priority. + } elseif ($this->options['subpages'] === true && empty($this->options['parent']) === false) { + $items = $this->itemsForParent(); - // search by query - } else { - $items = $this->itemsForQuery(); - } + // search by query + } else { + $items = $this->itemsForQuery(); + } - // filter protected pages - $items = $items->filter('isReadable', true); + // filter protected pages + $items = $items->filter('isReadable', true); - // search - $items = $this->search($items); + // search + $items = $this->search($items); - // paginate the result - return $this->items = $this->paginate($items); - } + // paginate the result + return $this->items = $this->paginate($items); + } - /** - * Search for pages by parent - * - * @return \Kirby\Cms\Pages - */ - public function itemsForParent() - { - return $this->parent()->children(); - } + /** + * Search for pages by parent + * + * @return \Kirby\Cms\Pages + */ + public function itemsForParent() + { + return $this->parent()->children(); + } - /** - * Search for pages by query string - * - * @return \Kirby\Cms\Pages - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function itemsForQuery() - { - // cache - if ($this->itemsForQuery !== null) { - return $this->itemsForQuery; - } + /** + * Search for pages by query string + * + * @return \Kirby\Cms\Pages + * @throws \Kirby\Exception\InvalidArgumentException + */ + public function itemsForQuery() + { + // cache + if ($this->itemsForQuery !== null) { + return $this->itemsForQuery; + } - $model = $this->options['model']; - $items = $model->query($this->options['query']); + $model = $this->options['model']; + $items = $model->query($this->options['query']); - // help mitigate some typical query usage issues - // by converting site and page objects to proper - // pages by returning their children - if (is_a($items, 'Kirby\Cms\Site') === true) { - $items = $items->children(); - } elseif (is_a($items, 'Kirby\Cms\Page') === true) { - $items = $items->children(); - } elseif (is_a($items, 'Kirby\Cms\Pages') === false) { - throw new InvalidArgumentException('Your query must return a set of pages'); - } + // help mitigate some typical query usage issues + // by converting site and page objects to proper + // pages by returning their children + if (is_a($items, 'Kirby\Cms\Site') === true) { + $items = $items->children(); + } elseif (is_a($items, 'Kirby\Cms\Page') === true) { + $items = $items->children(); + } elseif (is_a($items, 'Kirby\Cms\Pages') === false) { + throw new InvalidArgumentException('Your query must return a set of pages'); + } - return $this->itemsForQuery = $items; - } + return $this->itemsForQuery = $items; + } - /** - * Returns the parent model. - * The model will be used to fetch - * subpages unless there's a specific - * query to find pages instead. - * - * @return \Kirby\Cms\Page|\Kirby\Cms\Site - */ - public function parent() - { - if ($this->parent !== null) { - return $this->parent; - } + /** + * Returns the parent model. + * The model will be used to fetch + * subpages unless there's a specific + * query to find pages instead. + * + * @return \Kirby\Cms\Page|\Kirby\Cms\Site + */ + public function parent() + { + if ($this->parent !== null) { + return $this->parent; + } - return $this->parent = $this->kirby->page($this->options['parent']) ?? $this->site; - } + return $this->parent = $this->kirby->page($this->options['parent']) ?? $this->site; + } - /** - * Calculates the top-most model (page or site) - * that can be accessed when navigating - * through pages. - * - * @return \Kirby\Cms\Page|\Kirby\Cms\Site - */ - public function start() - { - if (empty($this->options['query']) === false) { - if ($items = $this->itemsForQuery()) { - return $items->parent(); - } + /** + * Calculates the top-most model (page or site) + * that can be accessed when navigating + * through pages. + * + * @return \Kirby\Cms\Page|\Kirby\Cms\Site + */ + public function start() + { + if (empty($this->options['query']) === false) { + if ($items = $this->itemsForQuery()) { + return $items->parent(); + } - return $this->site; - } + return $this->site; + } - return $this->site; - } + return $this->site; + } - /** - * Returns an associative array - * with all information for the picker. - * This will be passed directly to the API. - * - * @return array - */ - public function toArray(): array - { - $array = parent::toArray(); - $array['model'] = $this->modelToArray($this->model()); + /** + * Returns an associative array + * with all information for the picker. + * This will be passed directly to the API. + * + * @return array + */ + public function toArray(): array + { + $array = parent::toArray(); + $array['model'] = $this->modelToArray($this->model()); - return $array; - } + return $array; + } } diff --git a/kirby/src/Cms/PageRules.php b/kirby/src/Cms/PageRules.php index 4e980a0..68cc711 100755 --- a/kirby/src/Cms/PageRules.php +++ b/kirby/src/Cms/PageRules.php @@ -19,421 +19,421 @@ use Kirby\Toolkit\Str; */ class PageRules { - /** - * Validates if the sorting number of the page can be changed - * - * @param \Kirby\Cms\Page $page - * @param int|null $num - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException If the given number is invalid - */ - public static function changeNum(Page $page, int $num = null): bool - { - if ($num !== null && $num < 0) { - throw new InvalidArgumentException(['key' => 'page.num.invalid']); - } + /** + * Validates if the sorting number of the page can be changed + * + * @param \Kirby\Cms\Page $page + * @param int|null $num + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException If the given number is invalid + */ + public static function changeNum(Page $page, int $num = null): bool + { + if ($num !== null && $num < 0) { + throw new InvalidArgumentException(['key' => 'page.num.invalid']); + } - return true; - } + return true; + } - /** - * Validates if the slug for the page can be changed - * - * @param \Kirby\Cms\Page $page - * @param string $slug - * @return bool - * @throws \Kirby\Exception\DuplicateException If a page with this slug already exists - * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the slug - */ - public static function changeSlug(Page $page, string $slug): bool - { - if ($page->permissions()->changeSlug() !== true) { - throw new PermissionException([ - 'key' => 'page.changeSlug.permission', - 'data' => [ - 'slug' => $page->slug() - ] - ]); - } + /** + * Validates if the slug for the page can be changed + * + * @param \Kirby\Cms\Page $page + * @param string $slug + * @return bool + * @throws \Kirby\Exception\DuplicateException If a page with this slug already exists + * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the slug + */ + public static function changeSlug(Page $page, string $slug): bool + { + if ($page->permissions()->changeSlug() !== true) { + throw new PermissionException([ + 'key' => 'page.changeSlug.permission', + 'data' => [ + 'slug' => $page->slug() + ] + ]); + } - self::validateSlugLength($slug); + self::validateSlugLength($slug); - $siblings = $page->parentModel()->children(); - $drafts = $page->parentModel()->drafts(); + $siblings = $page->parentModel()->children(); + $drafts = $page->parentModel()->drafts(); - if ($duplicate = $siblings->find($slug)) { - if ($duplicate->is($page) === false) { - throw new DuplicateException([ - 'key' => 'page.duplicate', - 'data' => [ - 'slug' => $slug - ] - ]); - } - } + if ($duplicate = $siblings->find($slug)) { + if ($duplicate->is($page) === false) { + throw new DuplicateException([ + 'key' => 'page.duplicate', + 'data' => [ + 'slug' => $slug + ] + ]); + } + } - if ($duplicate = $drafts->find($slug)) { - if ($duplicate->is($page) === false) { - throw new DuplicateException([ - 'key' => 'page.draft.duplicate', - 'data' => [ - 'slug' => $slug - ] - ]); - } - } + if ($duplicate = $drafts->find($slug)) { + if ($duplicate->is($page) === false) { + throw new DuplicateException([ + 'key' => 'page.draft.duplicate', + 'data' => [ + 'slug' => $slug + ] + ]); + } + } - return true; - } + return true; + } - /** - * Validates if the status for the page can be changed - * - * @param \Kirby\Cms\Page $page - * @param string $status - * @param int|null $position - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException If the given status is invalid - */ - public static function changeStatus(Page $page, string $status, int $position = null): bool - { - if (isset($page->blueprint()->status()[$status]) === false) { - throw new InvalidArgumentException(['key' => 'page.status.invalid']); - } + /** + * Validates if the status for the page can be changed + * + * @param \Kirby\Cms\Page $page + * @param string $status + * @param int|null $position + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException If the given status is invalid + */ + public static function changeStatus(Page $page, string $status, int $position = null): bool + { + if (isset($page->blueprint()->status()[$status]) === false) { + throw new InvalidArgumentException(['key' => 'page.status.invalid']); + } - switch ($status) { - case 'draft': - return static::changeStatusToDraft($page); - case 'listed': - return static::changeStatusToListed($page, $position); - case 'unlisted': - return static::changeStatusToUnlisted($page); - default: - throw new InvalidArgumentException(['key' => 'page.status.invalid']); - } - } + switch ($status) { + case 'draft': + return static::changeStatusToDraft($page); + case 'listed': + return static::changeStatusToListed($page, $position); + case 'unlisted': + return static::changeStatusToUnlisted($page); + default: + throw new InvalidArgumentException(['key' => 'page.status.invalid']); + } + } - /** - * Validates if a page can be converted to a draft - * - * @param \Kirby\Cms\Page $page - * @return bool - * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the status or the page cannot be converted to a draft - */ - public static function changeStatusToDraft(Page $page) - { - if ($page->permissions()->changeStatus() !== true) { - throw new PermissionException([ - 'key' => 'page.changeStatus.permission', - 'data' => [ - 'slug' => $page->slug() - ] - ]); - } + /** + * Validates if a page can be converted to a draft + * + * @param \Kirby\Cms\Page $page + * @return bool + * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the status or the page cannot be converted to a draft + */ + public static function changeStatusToDraft(Page $page) + { + if ($page->permissions()->changeStatus() !== true) { + throw new PermissionException([ + 'key' => 'page.changeStatus.permission', + 'data' => [ + 'slug' => $page->slug() + ] + ]); + } - if ($page->isHomeOrErrorPage() === true) { - throw new PermissionException([ - 'key' => 'page.changeStatus.toDraft.invalid', - 'data' => [ - 'slug' => $page->slug() - ] - ]); - } + if ($page->isHomeOrErrorPage() === true) { + throw new PermissionException([ + 'key' => 'page.changeStatus.toDraft.invalid', + 'data' => [ + 'slug' => $page->slug() + ] + ]); + } - return true; - } + return true; + } - /** - * Validates if the status of a page can be changed to listed - * - * @param \Kirby\Cms\Page $page - * @param int $position - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException If the given position is invalid - * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the status or the status for the page cannot be changed by any user - */ - public static function changeStatusToListed(Page $page, int $position) - { - // no need to check for status changing permissions, - // instead we need to check for sorting permissions - if ($page->isListed() === true) { - if ($page->isSortable() !== true) { - throw new PermissionException([ - 'key' => 'page.sort.permission', - 'data' => [ - 'slug' => $page->slug() - ] - ]); - } + /** + * Validates if the status of a page can be changed to listed + * + * @param \Kirby\Cms\Page $page + * @param int $position + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException If the given position is invalid + * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the status or the status for the page cannot be changed by any user + */ + public static function changeStatusToListed(Page $page, int $position) + { + // no need to check for status changing permissions, + // instead we need to check for sorting permissions + if ($page->isListed() === true) { + if ($page->isSortable() !== true) { + throw new PermissionException([ + 'key' => 'page.sort.permission', + 'data' => [ + 'slug' => $page->slug() + ] + ]); + } - return true; - } + return true; + } - static::publish($page); + static::publish($page); - if ($position !== null && $position < 0) { - throw new InvalidArgumentException(['key' => 'page.num.invalid']); - } + if ($position !== null && $position < 0) { + throw new InvalidArgumentException(['key' => 'page.num.invalid']); + } - return true; - } + return true; + } - /** - * Validates if the status of a page can be changed to unlisted - * - * @param \Kirby\Cms\Page $page - * @return bool - * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the status - */ - public static function changeStatusToUnlisted(Page $page) - { - static::publish($page); + /** + * Validates if the status of a page can be changed to unlisted + * + * @param \Kirby\Cms\Page $page + * @return bool + * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the status + */ + public static function changeStatusToUnlisted(Page $page) + { + static::publish($page); - return true; - } + return true; + } - /** - * Validates if the template of the page can be changed - * - * @param \Kirby\Cms\Page $page - * @param string $template - * @return bool - * @throws \Kirby\Exception\LogicException If the template of the page cannot be changed at all - * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the template - */ - public static function changeTemplate(Page $page, string $template): bool - { - if ($page->permissions()->changeTemplate() !== true) { - throw new PermissionException([ - 'key' => 'page.changeTemplate.permission', - 'data' => [ - 'slug' => $page->slug() - ] - ]); - } + /** + * Validates if the template of the page can be changed + * + * @param \Kirby\Cms\Page $page + * @param string $template + * @return bool + * @throws \Kirby\Exception\LogicException If the template of the page cannot be changed at all + * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the template + */ + public static function changeTemplate(Page $page, string $template): bool + { + if ($page->permissions()->changeTemplate() !== true) { + throw new PermissionException([ + 'key' => 'page.changeTemplate.permission', + 'data' => [ + 'slug' => $page->slug() + ] + ]); + } - if (count($page->blueprints()) <= 1) { - throw new LogicException([ - 'key' => 'page.changeTemplate.invalid', - 'data' => ['slug' => $page->slug()] - ]); - } + if (count($page->blueprints()) <= 1) { + throw new LogicException([ + 'key' => 'page.changeTemplate.invalid', + 'data' => ['slug' => $page->slug()] + ]); + } - return true; - } + return true; + } - /** - * Validates if the title of the page can be changed - * - * @param \Kirby\Cms\Page $page - * @param string $title - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException If the new title is empty - * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the title - */ - public static function changeTitle(Page $page, string $title): bool - { - if ($page->permissions()->changeTitle() !== true) { - throw new PermissionException([ - 'key' => 'page.changeTitle.permission', - 'data' => [ - 'slug' => $page->slug() - ] - ]); - } + /** + * Validates if the title of the page can be changed + * + * @param \Kirby\Cms\Page $page + * @param string $title + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException If the new title is empty + * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the title + */ + public static function changeTitle(Page $page, string $title): bool + { + if ($page->permissions()->changeTitle() !== true) { + throw new PermissionException([ + 'key' => 'page.changeTitle.permission', + 'data' => [ + 'slug' => $page->slug() + ] + ]); + } - if (Str::length($title) === 0) { - throw new InvalidArgumentException([ - 'key' => 'page.changeTitle.empty', - ]); - } + if (Str::length($title) === 0) { + throw new InvalidArgumentException([ + 'key' => 'page.changeTitle.empty', + ]); + } - return true; - } + return true; + } - /** - * Validates if the page can be created - * - * @param \Kirby\Cms\Page $page - * @return bool - * @throws \Kirby\Exception\DuplicateException If the same page or a draft already exists - * @throws \Kirby\Exception\InvalidArgumentException If the slug is invalid - * @throws \Kirby\Exception\PermissionException If the user is not allowed to create this page - */ - public static function create(Page $page): bool - { - if ($page->permissions()->create() !== true) { - throw new PermissionException([ - 'key' => 'page.create.permission', - 'data' => [ - 'slug' => $page->slug() - ] - ]); - } + /** + * Validates if the page can be created + * + * @param \Kirby\Cms\Page $page + * @return bool + * @throws \Kirby\Exception\DuplicateException If the same page or a draft already exists + * @throws \Kirby\Exception\InvalidArgumentException If the slug is invalid + * @throws \Kirby\Exception\PermissionException If the user is not allowed to create this page + */ + public static function create(Page $page): bool + { + if ($page->permissions()->create() !== true) { + throw new PermissionException([ + 'key' => 'page.create.permission', + 'data' => [ + 'slug' => $page->slug() + ] + ]); + } - self::validateSlugLength($page->slug()); + self::validateSlugLength($page->slug()); - if ($page->exists() === true) { - throw new DuplicateException([ - 'key' => 'page.draft.duplicate', - 'data' => [ - 'slug' => $page->slug() - ] - ]); - } + if ($page->exists() === true) { + throw new DuplicateException([ + 'key' => 'page.draft.duplicate', + 'data' => [ + 'slug' => $page->slug() + ] + ]); + } - $siblings = $page->parentModel()->children(); - $drafts = $page->parentModel()->drafts(); - $slug = $page->slug(); + $siblings = $page->parentModel()->children(); + $drafts = $page->parentModel()->drafts(); + $slug = $page->slug(); - if ($siblings->find($slug)) { - throw new DuplicateException([ - 'key' => 'page.duplicate', - 'data' => ['slug' => $slug] - ]); - } + if ($siblings->find($slug)) { + throw new DuplicateException([ + 'key' => 'page.duplicate', + 'data' => ['slug' => $slug] + ]); + } - if ($drafts->find($slug)) { - throw new DuplicateException([ - 'key' => 'page.draft.duplicate', - 'data' => ['slug' => $slug] - ]); - } + if ($drafts->find($slug)) { + throw new DuplicateException([ + 'key' => 'page.draft.duplicate', + 'data' => ['slug' => $slug] + ]); + } - return true; - } + return true; + } - /** - * Validates if the page can be deleted - * - * @param \Kirby\Cms\Page $page - * @param bool $force - * @return bool - * @throws \Kirby\Exception\LogicException If the page has children and should not be force-deleted - * @throws \Kirby\Exception\PermissionException If the user is not allowed to delete the page - */ - public static function delete(Page $page, bool $force = false): bool - { - if ($page->permissions()->delete() !== true) { - throw new PermissionException([ - 'key' => 'page.delete.permission', - 'data' => [ - 'slug' => $page->slug() - ] - ]); - } + /** + * Validates if the page can be deleted + * + * @param \Kirby\Cms\Page $page + * @param bool $force + * @return bool + * @throws \Kirby\Exception\LogicException If the page has children and should not be force-deleted + * @throws \Kirby\Exception\PermissionException If the user is not allowed to delete the page + */ + public static function delete(Page $page, bool $force = false): bool + { + if ($page->permissions()->delete() !== true) { + throw new PermissionException([ + 'key' => 'page.delete.permission', + 'data' => [ + 'slug' => $page->slug() + ] + ]); + } - if (($page->hasChildren() === true || $page->hasDrafts() === true) && $force === false) { - throw new LogicException(['key' => 'page.delete.hasChildren']); - } + if (($page->hasChildren() === true || $page->hasDrafts() === true) && $force === false) { + throw new LogicException(['key' => 'page.delete.hasChildren']); + } - return true; - } + return true; + } - /** - * Validates if the page can be duplicated - * - * @param \Kirby\Cms\Page $page - * @param string $slug - * @param array $options - * @return bool - * @throws \Kirby\Exception\PermissionException If the user is not allowed to duplicate the page - */ - public static function duplicate(Page $page, string $slug, array $options = []): bool - { - if ($page->permissions()->duplicate() !== true) { - throw new PermissionException([ - 'key' => 'page.duplicate.permission', - 'data' => [ - 'slug' => $page->slug() - ] - ]); - } + /** + * Validates if the page can be duplicated + * + * @param \Kirby\Cms\Page $page + * @param string $slug + * @param array $options + * @return bool + * @throws \Kirby\Exception\PermissionException If the user is not allowed to duplicate the page + */ + public static function duplicate(Page $page, string $slug, array $options = []): bool + { + if ($page->permissions()->duplicate() !== true) { + throw new PermissionException([ + 'key' => 'page.duplicate.permission', + 'data' => [ + 'slug' => $page->slug() + ] + ]); + } - self::validateSlugLength($slug); + self::validateSlugLength($slug); - return true; - } + return true; + } - /** - * Check if the page can be published - * (status change from draft to listed or unlisted) - * - * @param Page $page - * @return bool - */ - public static function publish(Page $page): bool - { - if ($page->permissions()->changeStatus() !== true) { - throw new PermissionException([ - 'key' => 'page.changeStatus.permission', - 'data' => [ - 'slug' => $page->slug() - ] - ]); - } + /** + * Check if the page can be published + * (status change from draft to listed or unlisted) + * + * @param Page $page + * @return bool + */ + public static function publish(Page $page): bool + { + if ($page->permissions()->changeStatus() !== true) { + throw new PermissionException([ + 'key' => 'page.changeStatus.permission', + 'data' => [ + 'slug' => $page->slug() + ] + ]); + } - if ($page->isDraft() === true && empty($page->errors()) === false) { - throw new PermissionException([ - 'key' => 'page.changeStatus.incomplete', - 'details' => $page->errors() - ]); - } + if ($page->isDraft() === true && empty($page->errors()) === false) { + throw new PermissionException([ + 'key' => 'page.changeStatus.incomplete', + 'details' => $page->errors() + ]); + } - return true; - } + return true; + } - /** - * Validates if the page can be updated - * - * @param \Kirby\Cms\Page $page - * @param array $content - * @return bool - * @throws \Kirby\Exception\PermissionException If the user is not allowed to update the page - */ - public static function update(Page $page, array $content = []): bool - { - if ($page->permissions()->update() !== true) { - throw new PermissionException([ - 'key' => 'page.update.permission', - 'data' => [ - 'slug' => $page->slug() - ] - ]); - } + /** + * Validates if the page can be updated + * + * @param \Kirby\Cms\Page $page + * @param array $content + * @return bool + * @throws \Kirby\Exception\PermissionException If the user is not allowed to update the page + */ + public static function update(Page $page, array $content = []): bool + { + if ($page->permissions()->update() !== true) { + throw new PermissionException([ + 'key' => 'page.update.permission', + 'data' => [ + 'slug' => $page->slug() + ] + ]); + } - return true; - } + return true; + } - /** - * Ensures that the slug is not empty and doesn't exceed the maximum length - * to make sure that the directory name will be accepted by the filesystem - * - * @param string $slug New slug to check - * @return void - * @throws \Kirby\Exception\InvalidArgumentException If the slug is empty or too long - */ - protected static function validateSlugLength(string $slug): void - { - $slugLength = Str::length($slug); + /** + * Ensures that the slug is not empty and doesn't exceed the maximum length + * to make sure that the directory name will be accepted by the filesystem + * + * @param string $slug New slug to check + * @return void + * @throws \Kirby\Exception\InvalidArgumentException If the slug is empty or too long + */ + protected static function validateSlugLength(string $slug): void + { + $slugLength = Str::length($slug); - if ($slugLength === 0) { - throw new InvalidArgumentException([ - 'key' => 'page.slug.invalid', - ]); - } + if ($slugLength === 0) { + throw new InvalidArgumentException([ + 'key' => 'page.slug.invalid', + ]); + } - if ($slugsMaxlength = App::instance()->option('slugs.maxlength', 255)) { - $maxlength = (int)$slugsMaxlength; + if ($slugsMaxlength = App::instance()->option('slugs.maxlength', 255)) { + $maxlength = (int)$slugsMaxlength; - if ($slugLength > $maxlength) { - throw new InvalidArgumentException([ - 'key' => 'page.slug.maxlength', - 'data' => [ - 'length' => $maxlength - ] - ]); - } - } - } + if ($slugLength > $maxlength) { + throw new InvalidArgumentException([ + 'key' => 'page.slug.maxlength', + 'data' => [ + 'length' => $maxlength + ] + ]); + } + } + } } diff --git a/kirby/src/Cms/PageSiblings.php b/kirby/src/Cms/PageSiblings.php index 3b880c0..2507a1d 100755 --- a/kirby/src/Cms/PageSiblings.php +++ b/kirby/src/Cms/PageSiblings.php @@ -13,128 +13,128 @@ namespace Kirby\Cms; */ trait PageSiblings { - /** - * Checks if there's a next listed - * page in the siblings collection - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return bool - */ - public function hasNextListed($collection = null): bool - { - return $this->nextListed($collection) !== null; - } + /** + * Checks if there's a next listed + * page in the siblings collection + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return bool + */ + public function hasNextListed($collection = null): bool + { + return $this->nextListed($collection) !== null; + } - /** - * Checks if there's a next unlisted - * page in the siblings collection - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return bool - */ - public function hasNextUnlisted($collection = null): bool - { - return $this->nextUnlisted($collection) !== null; - } + /** + * Checks if there's a next unlisted + * page in the siblings collection + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return bool + */ + public function hasNextUnlisted($collection = null): bool + { + return $this->nextUnlisted($collection) !== null; + } - /** - * Checks if there's a previous listed - * page in the siblings collection - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return bool - */ - public function hasPrevListed($collection = null): bool - { - return $this->prevListed($collection) !== null; - } + /** + * Checks if there's a previous listed + * page in the siblings collection + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return bool + */ + public function hasPrevListed($collection = null): bool + { + return $this->prevListed($collection) !== null; + } - /** - * Checks if there's a previous unlisted - * page in the siblings collection - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return bool - */ - public function hasPrevUnlisted($collection = null): bool - { - return $this->prevUnlisted($collection) !== null; - } + /** + * Checks if there's a previous unlisted + * page in the siblings collection + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return bool + */ + public function hasPrevUnlisted($collection = null): bool + { + return $this->prevUnlisted($collection) !== null; + } - /** - * Returns the next listed page if it exists - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return \Kirby\Cms\Page|null - */ - public function nextListed($collection = null) - { - return $this->nextAll($collection)->listed()->first(); - } + /** + * Returns the next listed page if it exists + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return \Kirby\Cms\Page|null + */ + public function nextListed($collection = null) + { + return $this->nextAll($collection)->listed()->first(); + } - /** - * Returns the next unlisted page if it exists - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return \Kirby\Cms\Page|null - */ - public function nextUnlisted($collection = null) - { - return $this->nextAll($collection)->unlisted()->first(); - } + /** + * Returns the next unlisted page if it exists + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return \Kirby\Cms\Page|null + */ + public function nextUnlisted($collection = null) + { + return $this->nextAll($collection)->unlisted()->first(); + } - /** - * Returns the previous listed page - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return \Kirby\Cms\Page|null - */ - public function prevListed($collection = null) - { - return $this->prevAll($collection)->listed()->last(); - } + /** + * Returns the previous listed page + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return \Kirby\Cms\Page|null + */ + public function prevListed($collection = null) + { + return $this->prevAll($collection)->listed()->last(); + } - /** - * Returns the previous unlisted page - * - * @param \Kirby\Cms\Collection|null $collection - * - * @return \Kirby\Cms\Page|null - */ - public function prevUnlisted($collection = null) - { - return $this->prevAll($collection)->unlisted()->last(); - } + /** + * Returns the previous unlisted page + * + * @param \Kirby\Cms\Collection|null $collection + * + * @return \Kirby\Cms\Page|null + */ + public function prevUnlisted($collection = null) + { + return $this->prevAll($collection)->unlisted()->last(); + } - /** - * Private siblings collector - * - * @return \Kirby\Cms\Collection - */ - protected function siblingsCollection() - { - if ($this->isDraft() === true) { - return $this->parentModel()->drafts(); - } else { - return $this->parentModel()->children(); - } - } + /** + * Private siblings collector + * + * @return \Kirby\Cms\Collection + */ + protected function siblingsCollection() + { + if ($this->isDraft() === true) { + return $this->parentModel()->drafts(); + } else { + return $this->parentModel()->children(); + } + } - /** - * Returns siblings with the same template - * - * @param bool $self - * @return \Kirby\Cms\Pages - */ - public function templateSiblings(bool $self = true) - { - return $this->siblings($self)->filter('intendedTemplate', $this->intendedTemplate()->name()); - } + /** + * Returns siblings with the same template + * + * @param bool $self + * @return \Kirby\Cms\Pages + */ + public function templateSiblings(bool $self = true) + { + return $this->siblings($self)->filter('intendedTemplate', $this->intendedTemplate()->name()); + } } diff --git a/kirby/src/Cms/Pages.php b/kirby/src/Cms/Pages.php index 55125c9..5aa3959 100755 --- a/kirby/src/Cms/Pages.php +++ b/kirby/src/Cms/Pages.php @@ -22,533 +22,533 @@ use Kirby\Exception\InvalidArgumentException; */ class Pages extends Collection { - /** - * Cache for the index only listed and unlisted pages - * - * @var \Kirby\Cms\Pages|null - */ - protected $index = null; - - /** - * Cache for the index all statuses also including drafts - * - * @var \Kirby\Cms\Pages|null - */ - protected $indexWithDrafts = null; - - /** - * All registered pages methods - * - * @var array - */ - public static $methods = []; - - /** - * Adds a single page or - * an entire second collection to the - * current collection - * - * @param \Kirby\Cms\Pages|\Kirby\Cms\Page|string $object - * @return $this - * @throws \Kirby\Exception\InvalidArgumentException When no `Page` or `Pages` object or an ID of an existing page is passed - */ - public function add($object) - { - $site = App::instance()->site(); - - // add a pages collection - if (is_a($object, self::class) === true) { - $this->data = array_merge($this->data, $object->data); - - // add a page by id - } elseif (is_string($object) === true && $page = $site->find($object)) { - $this->__set($page->id(), $page); - - // add a page object - } elseif (is_a($object, 'Kirby\Cms\Page') === true) { - $this->__set($object->id(), $object); - - // give a useful error message on invalid input; - // silently ignore "empty" values for compatibility with existing setups - } elseif (in_array($object, [null, false, true], true) !== true) { - throw new InvalidArgumentException('You must pass a Pages or Page object or an ID of an existing page to the Pages collection'); - } - - return $this; - } - - /** - * Returns all audio files of all children - * - * @return \Kirby\Cms\Files - */ - public function audio() - { - return $this->files()->filter('type', 'audio'); - } - - /** - * Returns all children for each page in the array - * - * @return \Kirby\Cms\Pages - */ - public function children() - { - $children = new Pages([]); - - foreach ($this->data as $page) { - foreach ($page->children() as $childKey => $child) { - $children->data[$childKey] = $child; - } - } - - return $children; - } - - /** - * Returns all code files of all children - * - * @return \Kirby\Cms\Files - */ - public function code() - { - return $this->files()->filter('type', 'code'); - } - - /** - * Returns all documents of all children - * - * @return \Kirby\Cms\Files - */ - public function documents() - { - return $this->files()->filter('type', 'document'); - } - - /** - * Fetch all drafts for all pages in the collection - * - * @return \Kirby\Cms\Pages - */ - public function drafts() - { - $drafts = new Pages([]); - - foreach ($this->data as $page) { - foreach ($page->drafts() as $draftKey => $draft) { - $drafts->data[$draftKey] = $draft; - } - } - - return $drafts; - } - - /** - * Creates a pages collection from an array of props - * - * @param array $pages - * @param \Kirby\Cms\Model|null $model - * @param bool $draft - * @return static - */ - public static function factory(array $pages, Model $model = null, bool $draft = false) - { - $model ??= App::instance()->site(); - $children = new static([], $model); - $kirby = $model->kirby(); - - if (is_a($model, 'Kirby\Cms\Page') === true) { - $parent = $model; - $site = $model->site(); - } else { - $parent = null; - $site = $model; - } - - foreach ($pages as $props) { - $props['kirby'] = $kirby; - $props['parent'] = $parent; - $props['site'] = $site; - $props['isDraft'] = $draft; - - $page = Page::factory($props); - - $children->data[$page->id()] = $page; - } - - return $children; - } - - /** - * Returns all files of all children - * - * @return \Kirby\Cms\Files - */ - public function files() - { - $files = new Files([], $this->parent); - - foreach ($this->data as $page) { - foreach ($page->files() as $fileKey => $file) { - $files->data[$fileKey] = $file; - } - } - - return $files; - } - - /** - * Finds a page in the collection by id. - * This works recursively for children and - * children of children, etc. - * @deprecated 3.7.0 Use `$pages->get()` or `$pages->find()` instead - * @todo 3.8.0 Remove method - * @codeCoverageIgnore - * - * @param string|null $id - * @return mixed - */ - public function findById(string $id = null) - { - Helpers::deprecated('Cms\Pages::findById() has been deprecated and will be removed in Kirby 3.8.0. Use $pages->get() or $pages->find() instead.'); - - return $this->findByKey($id); - } - - /** - * Finds a child or child of a child recursively. - * @deprecated 3.7.0 Use `$pages->find()` instead - * @todo 3.8.0 Integrate code into `findByKey()` and remove this method - * - * @param string $id - * @param string|null $startAt - * @param bool $multiLang - * @return mixed - */ - public function findByIdRecursive(string $id, string $startAt = null, bool $multiLang = false, bool $silenceWarning = false) - { - // @codeCoverageIgnoreStart - if ($silenceWarning !== true) { - Helpers::deprecated('Cms\Pages::findByIdRecursive() has been deprecated and will be removed in Kirby 3.8.0. Use $pages->find() instead.'); - } - // @codeCoverageIgnoreEnd - - $path = explode('/', $id); - $item = null; - $query = $startAt; - - foreach ($path as $key) { - $collection = $item ? $item->children() : $this; - $query = ltrim($query . '/' . $key, '/'); - $item = $collection->get($query) ?? null; - - if ($item === null && $multiLang === true && !App::instance()->language()->isDefault()) { - if (count($path) > 1 || $collection->parent()) { - // either the desired path is definitely not a slug, or collection is the children of another collection - $item = $collection->findBy('slug', $key); - } else { - // desired path _could_ be a slug or a "top level" uri - $item = $collection->findBy('uri', $key); - } - } - - if ($item === null) { - return null; - } - } - - return $item; - } - - /** - * Finds a page by its ID or URI - * @internal Use `$pages->find()` instead - * - * @param string|null $key - * @return \Kirby\Cms\Page|null - */ - public function findByKey(?string $key = null) - { - if ($key === null) { - return null; - } - - // remove trailing or leading slashes - $key = trim($key, '/'); - - // strip extensions from the id - if (strpos($key, '.') !== false) { - $info = pathinfo($key); - - if ($info['dirname'] !== '.') { - $key = $info['dirname'] . '/' . $info['filename']; - } else { - $key = $info['filename']; - } - } - - // try the obvious way - if ($page = $this->get($key)) { - return $page; - } - - // try to find the page by its (translated) URI by stepping through the page tree - $start = is_a($this->parent, 'Kirby\Cms\Page') === true ? $this->parent->id() : ''; - if ($page = $this->findByIdRecursive($key, $start, App::instance()->multilang(), true)) { - return $page; - } - - // for secondary languages, try the full translated URI - // (for collections without parent that won't have a result above) - if ( - App::instance()->multilang() === true && - App::instance()->language()->isDefault() === false && - $page = $this->findBy('uri', $key) - ) { - return $page; - } - - return null; - } - - /** - * Alias for `$pages->find()` - * @deprecated 3.7.0 Use `$pages->find()` instead - * @todo 3.8.0 Remove method - * @codeCoverageIgnore - * - * @param string $id - * @return \Kirby\Cms\Page|null - */ - public function findByUri(string $id) - { - Helpers::deprecated('Cms\Pages::findByUri() has been deprecated and will be removed in Kirby 3.8.0. Use $pages->find() instead.'); - - return $this->findByKey($id); - } - - /** - * Finds the currently open page - * - * @return \Kirby\Cms\Page|null - */ - public function findOpen() - { - return $this->findBy('isOpen', true); - } - - /** - * Custom getter that is able to find - * extension pages - * - * @param string $key - * @param mixed $default - * @return \Kirby\Cms\Page|null - */ - public function get($key, $default = null) - { - if ($key === null) { - return null; - } - - if ($item = parent::get($key)) { - return $item; - } - - return App::instance()->extension('pages', $key); - } - - /** - * Returns all images of all children - * - * @return \Kirby\Cms\Files - */ - public function images() - { - return $this->files()->filter('type', 'image'); - } - - /** - * Create a recursive flat index of all - * pages and subpages, etc. - * - * @param bool $drafts - * @return \Kirby\Cms\Pages - */ - public function index(bool $drafts = false) - { - // get object property by cache mode - $index = $drafts === true ? $this->indexWithDrafts : $this->index; - - if (is_a($index, 'Kirby\Cms\Pages') === true) { - return $index; - } - - $index = new Pages([]); - - foreach ($this->data as $pageKey => $page) { - $index->data[$pageKey] = $page; - $pageIndex = $page->index($drafts); - - if ($pageIndex) { - foreach ($pageIndex as $childKey => $child) { - $index->data[$childKey] = $child; - } - } - } - - if ($drafts === true) { - return $this->indexWithDrafts = $index; - } - - return $this->index = $index; - } - - /** - * Returns all listed pages in the collection - * - * @return \Kirby\Cms\Pages - */ - public function listed() - { - return $this->filter('isListed', '==', true); - } - - /** - * Returns all unlisted pages in the collection - * - * @return \Kirby\Cms\Pages - */ - public function unlisted() - { - return $this->filter('isUnlisted', '==', true); - } - - /** - * Include all given items in the collection - * - * @param mixed ...$args - * @return $this|static - */ - public function merge(...$args) - { - // merge multiple arguments at once - if (count($args) > 1) { - $collection = clone $this; - foreach ($args as $arg) { - $collection = $collection->merge($arg); - } - return $collection; - } - - // merge all parent drafts - if ($args[0] === 'drafts') { - if ($parent = $this->parent()) { - return $this->merge($parent->drafts()); - } - - return $this; - } - - // merge an entire collection - if (is_a($args[0], self::class) === true) { - $collection = clone $this; - $collection->data = array_merge($collection->data, $args[0]->data); - return $collection; - } - - // append a single page - if (is_a($args[0], 'Kirby\Cms\Page') === true) { - $collection = clone $this; - return $collection->set($args[0]->id(), $args[0]); - } - - // merge an array - if (is_array($args[0]) === true) { - $collection = clone $this; - foreach ($args[0] as $arg) { - $collection = $collection->merge($arg); - } - return $collection; - } - - if (is_string($args[0]) === true) { - return $this->merge(App::instance()->site()->find($args[0])); - } - - return $this; - } - - /** - * Filter all pages by excluding the given template - * @since 3.3.0 - * - * @param string|array $templates - * @return \Kirby\Cms\Pages - */ - public function notTemplate($templates) - { - if (empty($templates) === true) { - return $this; - } - - if (is_array($templates) === false) { - $templates = [$templates]; - } - - return $this->filter(function ($page) use ($templates) { - return !in_array($page->intendedTemplate()->name(), $templates); - }); - } - - /** - * Returns an array with all page numbers - * - * @return array - */ - public function nums(): array - { - return $this->pluck('num'); - } - - /* - * Returns all listed and unlisted pages in the collection - * - * @return \Kirby\Cms\Pages - */ - public function published() - { - return $this->filter('isDraft', '==', false); - } - - /** - * Filter all pages by the given template - * - * @param string|array $templates - * @return \Kirby\Cms\Pages - */ - public function template($templates) - { - if (empty($templates) === true) { - return $this; - } - - if (is_array($templates) === false) { - $templates = [$templates]; - } - - return $this->filter(function ($page) use ($templates) { - return in_array($page->intendedTemplate()->name(), $templates); - }); - } - - /** - * Returns all video files of all children - * - * @return \Kirby\Cms\Files - */ - public function videos() - { - return $this->files()->filter('type', 'video'); - } + /** + * Cache for the index only listed and unlisted pages + * + * @var \Kirby\Cms\Pages|null + */ + protected $index = null; + + /** + * Cache for the index all statuses also including drafts + * + * @var \Kirby\Cms\Pages|null + */ + protected $indexWithDrafts = null; + + /** + * All registered pages methods + * + * @var array + */ + public static $methods = []; + + /** + * Adds a single page or + * an entire second collection to the + * current collection + * + * @param \Kirby\Cms\Pages|\Kirby\Cms\Page|string $object + * @return $this + * @throws \Kirby\Exception\InvalidArgumentException When no `Page` or `Pages` object or an ID of an existing page is passed + */ + public function add($object) + { + $site = App::instance()->site(); + + // add a pages collection + if (is_a($object, self::class) === true) { + $this->data = array_merge($this->data, $object->data); + + // add a page by id + } elseif (is_string($object) === true && $page = $site->find($object)) { + $this->__set($page->id(), $page); + + // add a page object + } elseif (is_a($object, 'Kirby\Cms\Page') === true) { + $this->__set($object->id(), $object); + + // give a useful error message on invalid input; + // silently ignore "empty" values for compatibility with existing setups + } elseif (in_array($object, [null, false, true], true) !== true) { + throw new InvalidArgumentException('You must pass a Pages or Page object or an ID of an existing page to the Pages collection'); + } + + return $this; + } + + /** + * Returns all audio files of all children + * + * @return \Kirby\Cms\Files + */ + public function audio() + { + return $this->files()->filter('type', 'audio'); + } + + /** + * Returns all children for each page in the array + * + * @return \Kirby\Cms\Pages + */ + public function children() + { + $children = new Pages([]); + + foreach ($this->data as $page) { + foreach ($page->children() as $childKey => $child) { + $children->data[$childKey] = $child; + } + } + + return $children; + } + + /** + * Returns all code files of all children + * + * @return \Kirby\Cms\Files + */ + public function code() + { + return $this->files()->filter('type', 'code'); + } + + /** + * Returns all documents of all children + * + * @return \Kirby\Cms\Files + */ + public function documents() + { + return $this->files()->filter('type', 'document'); + } + + /** + * Fetch all drafts for all pages in the collection + * + * @return \Kirby\Cms\Pages + */ + public function drafts() + { + $drafts = new Pages([]); + + foreach ($this->data as $page) { + foreach ($page->drafts() as $draftKey => $draft) { + $drafts->data[$draftKey] = $draft; + } + } + + return $drafts; + } + + /** + * Creates a pages collection from an array of props + * + * @param array $pages + * @param \Kirby\Cms\Model|null $model + * @param bool $draft + * @return static + */ + public static function factory(array $pages, Model $model = null, bool $draft = false) + { + $model ??= App::instance()->site(); + $children = new static([], $model); + $kirby = $model->kirby(); + + if (is_a($model, 'Kirby\Cms\Page') === true) { + $parent = $model; + $site = $model->site(); + } else { + $parent = null; + $site = $model; + } + + foreach ($pages as $props) { + $props['kirby'] = $kirby; + $props['parent'] = $parent; + $props['site'] = $site; + $props['isDraft'] = $draft; + + $page = Page::factory($props); + + $children->data[$page->id()] = $page; + } + + return $children; + } + + /** + * Returns all files of all children + * + * @return \Kirby\Cms\Files + */ + public function files() + { + $files = new Files([], $this->parent); + + foreach ($this->data as $page) { + foreach ($page->files() as $fileKey => $file) { + $files->data[$fileKey] = $file; + } + } + + return $files; + } + + /** + * Finds a page in the collection by id. + * This works recursively for children and + * children of children, etc. + * @deprecated 3.7.0 Use `$pages->get()` or `$pages->find()` instead + * @todo 3.8.0 Remove method + * @codeCoverageIgnore + * + * @param string|null $id + * @return mixed + */ + public function findById(string $id = null) + { + Helpers::deprecated('Cms\Pages::findById() has been deprecated and will be removed in Kirby 3.8.0. Use $pages->get() or $pages->find() instead.'); + + return $this->findByKey($id); + } + + /** + * Finds a child or child of a child recursively. + * @deprecated 3.7.0 Use `$pages->find()` instead + * @todo 3.8.0 Integrate code into `findByKey()` and remove this method + * + * @param string $id + * @param string|null $startAt + * @param bool $multiLang + * @return mixed + */ + public function findByIdRecursive(string $id, string $startAt = null, bool $multiLang = false, bool $silenceWarning = false) + { + // @codeCoverageIgnoreStart + if ($silenceWarning !== true) { + Helpers::deprecated('Cms\Pages::findByIdRecursive() has been deprecated and will be removed in Kirby 3.8.0. Use $pages->find() instead.'); + } + // @codeCoverageIgnoreEnd + + $path = explode('/', $id); + $item = null; + $query = $startAt; + + foreach ($path as $key) { + $collection = $item ? $item->children() : $this; + $query = ltrim($query . '/' . $key, '/'); + $item = $collection->get($query) ?? null; + + if ($item === null && $multiLang === true && !App::instance()->language()->isDefault()) { + if (count($path) > 1 || $collection->parent()) { + // either the desired path is definitely not a slug, or collection is the children of another collection + $item = $collection->findBy('slug', $key); + } else { + // desired path _could_ be a slug or a "top level" uri + $item = $collection->findBy('uri', $key); + } + } + + if ($item === null) { + return null; + } + } + + return $item; + } + + /** + * Finds a page by its ID or URI + * @internal Use `$pages->find()` instead + * + * @param string|null $key + * @return \Kirby\Cms\Page|null + */ + public function findByKey(?string $key = null) + { + if ($key === null) { + return null; + } + + // remove trailing or leading slashes + $key = trim($key, '/'); + + // strip extensions from the id + if (strpos($key, '.') !== false) { + $info = pathinfo($key); + + if ($info['dirname'] !== '.') { + $key = $info['dirname'] . '/' . $info['filename']; + } else { + $key = $info['filename']; + } + } + + // try the obvious way + if ($page = $this->get($key)) { + return $page; + } + + // try to find the page by its (translated) URI by stepping through the page tree + $start = is_a($this->parent, 'Kirby\Cms\Page') === true ? $this->parent->id() : ''; + if ($page = $this->findByIdRecursive($key, $start, App::instance()->multilang(), true)) { + return $page; + } + + // for secondary languages, try the full translated URI + // (for collections without parent that won't have a result above) + if ( + App::instance()->multilang() === true && + App::instance()->language()->isDefault() === false && + $page = $this->findBy('uri', $key) + ) { + return $page; + } + + return null; + } + + /** + * Alias for `$pages->find()` + * @deprecated 3.7.0 Use `$pages->find()` instead + * @todo 3.8.0 Remove method + * @codeCoverageIgnore + * + * @param string $id + * @return \Kirby\Cms\Page|null + */ + public function findByUri(string $id) + { + Helpers::deprecated('Cms\Pages::findByUri() has been deprecated and will be removed in Kirby 3.8.0. Use $pages->find() instead.'); + + return $this->findByKey($id); + } + + /** + * Finds the currently open page + * + * @return \Kirby\Cms\Page|null + */ + public function findOpen() + { + return $this->findBy('isOpen', true); + } + + /** + * Custom getter that is able to find + * extension pages + * + * @param string $key + * @param mixed $default + * @return \Kirby\Cms\Page|null + */ + public function get($key, $default = null) + { + if ($key === null) { + return null; + } + + if ($item = parent::get($key)) { + return $item; + } + + return App::instance()->extension('pages', $key); + } + + /** + * Returns all images of all children + * + * @return \Kirby\Cms\Files + */ + public function images() + { + return $this->files()->filter('type', 'image'); + } + + /** + * Create a recursive flat index of all + * pages and subpages, etc. + * + * @param bool $drafts + * @return \Kirby\Cms\Pages + */ + public function index(bool $drafts = false) + { + // get object property by cache mode + $index = $drafts === true ? $this->indexWithDrafts : $this->index; + + if (is_a($index, 'Kirby\Cms\Pages') === true) { + return $index; + } + + $index = new Pages([]); + + foreach ($this->data as $pageKey => $page) { + $index->data[$pageKey] = $page; + $pageIndex = $page->index($drafts); + + if ($pageIndex) { + foreach ($pageIndex as $childKey => $child) { + $index->data[$childKey] = $child; + } + } + } + + if ($drafts === true) { + return $this->indexWithDrafts = $index; + } + + return $this->index = $index; + } + + /** + * Returns all listed pages in the collection + * + * @return \Kirby\Cms\Pages + */ + public function listed() + { + return $this->filter('isListed', '==', true); + } + + /** + * Returns all unlisted pages in the collection + * + * @return \Kirby\Cms\Pages + */ + public function unlisted() + { + return $this->filter('isUnlisted', '==', true); + } + + /** + * Include all given items in the collection + * + * @param mixed ...$args + * @return $this|static + */ + public function merge(...$args) + { + // merge multiple arguments at once + if (count($args) > 1) { + $collection = clone $this; + foreach ($args as $arg) { + $collection = $collection->merge($arg); + } + return $collection; + } + + // merge all parent drafts + if ($args[0] === 'drafts') { + if ($parent = $this->parent()) { + return $this->merge($parent->drafts()); + } + + return $this; + } + + // merge an entire collection + if (is_a($args[0], self::class) === true) { + $collection = clone $this; + $collection->data = array_merge($collection->data, $args[0]->data); + return $collection; + } + + // append a single page + if (is_a($args[0], 'Kirby\Cms\Page') === true) { + $collection = clone $this; + return $collection->set($args[0]->id(), $args[0]); + } + + // merge an array + if (is_array($args[0]) === true) { + $collection = clone $this; + foreach ($args[0] as $arg) { + $collection = $collection->merge($arg); + } + return $collection; + } + + if (is_string($args[0]) === true) { + return $this->merge(App::instance()->site()->find($args[0])); + } + + return $this; + } + + /** + * Filter all pages by excluding the given template + * @since 3.3.0 + * + * @param string|array $templates + * @return \Kirby\Cms\Pages + */ + public function notTemplate($templates) + { + if (empty($templates) === true) { + return $this; + } + + if (is_array($templates) === false) { + $templates = [$templates]; + } + + return $this->filter(function ($page) use ($templates) { + return !in_array($page->intendedTemplate()->name(), $templates); + }); + } + + /** + * Returns an array with all page numbers + * + * @return array + */ + public function nums(): array + { + return $this->pluck('num'); + } + + /* + * Returns all listed and unlisted pages in the collection + * + * @return \Kirby\Cms\Pages + */ + public function published() + { + return $this->filter('isDraft', '==', false); + } + + /** + * Filter all pages by the given template + * + * @param string|array $templates + * @return \Kirby\Cms\Pages + */ + public function template($templates) + { + if (empty($templates) === true) { + return $this; + } + + if (is_array($templates) === false) { + $templates = [$templates]; + } + + return $this->filter(function ($page) use ($templates) { + return in_array($page->intendedTemplate()->name(), $templates); + }); + } + + /** + * Returns all video files of all children + * + * @return \Kirby\Cms\Files + */ + public function videos() + { + return $this->files()->filter('type', 'video'); + } } diff --git a/kirby/src/Cms/Pagination.php b/kirby/src/Cms/Pagination.php index 253a523..13f6ef2 100755 --- a/kirby/src/Cms/Pagination.php +++ b/kirby/src/Cms/Pagination.php @@ -22,158 +22,158 @@ use Kirby\Toolkit\Pagination as BasePagination; */ class Pagination extends BasePagination { - /** - * Pagination method (param, query, none) - * - * @var string - */ - protected $method; + /** + * Pagination method (param, query, none) + * + * @var string + */ + protected $method; - /** - * The base URL - * - * @var string - */ - protected $url; + /** + * The base URL + * + * @var string + */ + protected $url; - /** - * Variable name for query strings - * - * @var string - */ - protected $variable; + /** + * Variable name for query strings + * + * @var string + */ + protected $variable; - /** - * Creates the pagination object. As a new - * property you can now pass the base Url. - * That Url must be the Url of the first - * page of the collection without additional - * pagination information/query parameters in it. - * - * ```php - * $pagination = new Pagination([ - * 'page' => 1, - * 'limit' => 10, - * 'total' => 120, - * 'method' => 'query', - * 'variable' => 'p', - * 'url' => new Uri('https://getkirby.com/blog') - * ]); - * ``` - * - * @param array $params - */ - public function __construct(array $params = []) - { - $kirby = App::instance(); - $config = $kirby->option('pagination', []); - $request = $kirby->request(); + /** + * Creates the pagination object. As a new + * property you can now pass the base Url. + * That Url must be the Url of the first + * page of the collection without additional + * pagination information/query parameters in it. + * + * ```php + * $pagination = new Pagination([ + * 'page' => 1, + * 'limit' => 10, + * 'total' => 120, + * 'method' => 'query', + * 'variable' => 'p', + * 'url' => new Uri('https://getkirby.com/blog') + * ]); + * ``` + * + * @param array $params + */ + public function __construct(array $params = []) + { + $kirby = App::instance(); + $config = $kirby->option('pagination', []); + $request = $kirby->request(); - $params['limit'] ??= $config['limit'] ?? 20; - $params['method'] ??= $config['method'] ?? 'param'; - $params['variable'] ??= $config['variable'] ?? 'page'; + $params['limit'] ??= $config['limit'] ?? 20; + $params['method'] ??= $config['method'] ?? 'param'; + $params['variable'] ??= $config['variable'] ?? 'page'; - if (empty($params['url']) === true) { - $params['url'] = new Uri($kirby->url('current'), [ - 'params' => $request->params(), - 'query' => $request->query()->toArray(), - ]); - } + if (empty($params['url']) === true) { + $params['url'] = new Uri($kirby->url('current'), [ + 'params' => $request->params(), + 'query' => $request->query()->toArray(), + ]); + } - if ($params['method'] === 'query') { - $params['page'] ??= $params['url']->query()->get($params['variable']); - } elseif ($params['method'] === 'param') { - $params['page'] ??= $params['url']->params()->get($params['variable']); - } + if ($params['method'] === 'query') { + $params['page'] ??= $params['url']->query()->get($params['variable']); + } elseif ($params['method'] === 'param') { + $params['page'] ??= $params['url']->params()->get($params['variable']); + } - parent::__construct($params); + parent::__construct($params); - $this->method = $params['method']; - $this->url = $params['url']; - $this->variable = $params['variable']; - } + $this->method = $params['method']; + $this->url = $params['url']; + $this->variable = $params['variable']; + } - /** - * Returns the Url for the first page - * - * @return string|null - */ - public function firstPageUrl(): ?string - { - return $this->pageUrl(1); - } + /** + * Returns the Url for the first page + * + * @return string|null + */ + public function firstPageUrl(): ?string + { + return $this->pageUrl(1); + } - /** - * Returns the Url for the last page - * - * @return string|null - */ - public function lastPageUrl(): ?string - { - return $this->pageUrl($this->lastPage()); - } + /** + * Returns the Url for the last page + * + * @return string|null + */ + public function lastPageUrl(): ?string + { + return $this->pageUrl($this->lastPage()); + } - /** - * Returns the Url for the next page. - * Returns null if there's no next page. - * - * @return string|null - */ - public function nextPageUrl(): ?string - { - if ($page = $this->nextPage()) { - return $this->pageUrl($page); - } + /** + * Returns the Url for the next page. + * Returns null if there's no next page. + * + * @return string|null + */ + public function nextPageUrl(): ?string + { + if ($page = $this->nextPage()) { + return $this->pageUrl($page); + } - return null; - } + return null; + } - /** - * Returns the URL of the current page. - * If the `$page` variable is set, the URL - * for that page will be returned. - * - * @param int|null $page - * @return string|null - */ - public function pageUrl(int $page = null): ?string - { - if ($page === null) { - return $this->pageUrl($this->page()); - } + /** + * Returns the URL of the current page. + * If the `$page` variable is set, the URL + * for that page will be returned. + * + * @param int|null $page + * @return string|null + */ + public function pageUrl(int $page = null): ?string + { + if ($page === null) { + return $this->pageUrl($this->page()); + } - $url = clone $this->url; - $variable = $this->variable; + $url = clone $this->url; + $variable = $this->variable; - if ($this->hasPage($page) === false) { - return null; - } + if ($this->hasPage($page) === false) { + return null; + } - $pageValue = $page === 1 ? null : $page; + $pageValue = $page === 1 ? null : $page; - if ($this->method === 'query') { - $url->query->$variable = $pageValue; - } elseif ($this->method === 'param') { - $url->params->$variable = $pageValue; - } else { - return null; - } + if ($this->method === 'query') { + $url->query->$variable = $pageValue; + } elseif ($this->method === 'param') { + $url->params->$variable = $pageValue; + } else { + return null; + } - return $url->toString(); - } + return $url->toString(); + } - /** - * Returns the Url for the previous page. - * Returns null if there's no previous page. - * - * @return string|null - */ - public function prevPageUrl(): ?string - { - if ($page = $this->prevPage()) { - return $this->pageUrl($page); - } + /** + * Returns the Url for the previous page. + * Returns null if there's no previous page. + * + * @return string|null + */ + public function prevPageUrl(): ?string + { + if ($page = $this->prevPage()) { + return $this->pageUrl($page); + } - return null; - } + return null; + } } diff --git a/kirby/src/Cms/Permissions.php b/kirby/src/Cms/Permissions.php index c7cb6c1..caaa284 100755 --- a/kirby/src/Cms/Permissions.php +++ b/kirby/src/Cms/Permissions.php @@ -17,222 +17,222 @@ use Kirby\Exception\InvalidArgumentException; */ class Permissions { - /** - * @var array - */ - public static $extendedActions = []; + /** + * @var array + */ + public static $extendedActions = []; - /** - * @var array - */ - protected $actions = [ - 'access' => [ - 'account' => true, - 'languages' => true, - 'panel' => true, - 'site' => true, - 'system' => true, - 'users' => true, - ], - 'files' => [ - 'changeName' => true, - 'create' => true, - 'delete' => true, - 'read' => true, - 'replace' => true, - 'update' => true - ], - 'languages' => [ - 'create' => true, - 'delete' => true - ], - 'pages' => [ - 'changeSlug' => true, - 'changeStatus' => true, - 'changeTemplate' => true, - 'changeTitle' => true, - 'create' => true, - 'delete' => true, - 'duplicate' => true, - 'preview' => true, - 'read' => true, - 'sort' => true, - 'update' => true - ], - 'site' => [ - 'changeTitle' => true, - 'update' => true - ], - 'users' => [ - 'changeEmail' => true, - 'changeLanguage' => true, - 'changeName' => true, - 'changePassword' => true, - 'changeRole' => true, - 'create' => true, - 'delete' => true, - 'update' => true - ], - 'user' => [ - 'changeEmail' => true, - 'changeLanguage' => true, - 'changeName' => true, - 'changePassword' => true, - 'changeRole' => true, - 'delete' => true, - 'update' => true - ] - ]; + /** + * @var array + */ + protected $actions = [ + 'access' => [ + 'account' => true, + 'languages' => true, + 'panel' => true, + 'site' => true, + 'system' => true, + 'users' => true, + ], + 'files' => [ + 'changeName' => true, + 'create' => true, + 'delete' => true, + 'read' => true, + 'replace' => true, + 'update' => true + ], + 'languages' => [ + 'create' => true, + 'delete' => true + ], + 'pages' => [ + 'changeSlug' => true, + 'changeStatus' => true, + 'changeTemplate' => true, + 'changeTitle' => true, + 'create' => true, + 'delete' => true, + 'duplicate' => true, + 'preview' => true, + 'read' => true, + 'sort' => true, + 'update' => true + ], + 'site' => [ + 'changeTitle' => true, + 'update' => true + ], + 'users' => [ + 'changeEmail' => true, + 'changeLanguage' => true, + 'changeName' => true, + 'changePassword' => true, + 'changeRole' => true, + 'create' => true, + 'delete' => true, + 'update' => true + ], + 'user' => [ + 'changeEmail' => true, + 'changeLanguage' => true, + 'changeName' => true, + 'changePassword' => true, + 'changeRole' => true, + 'delete' => true, + 'update' => true + ] + ]; - /** - * Permissions constructor - * - * @param array $settings - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function __construct($settings = []) - { - // dynamically register the extended actions - foreach (static::$extendedActions as $key => $actions) { - if (isset($this->actions[$key]) === true) { - throw new InvalidArgumentException('The action ' . $key . ' is already a core action'); - } + /** + * Permissions constructor + * + * @param array $settings + * @throws \Kirby\Exception\InvalidArgumentException + */ + public function __construct($settings = []) + { + // dynamically register the extended actions + foreach (static::$extendedActions as $key => $actions) { + if (isset($this->actions[$key]) === true) { + throw new InvalidArgumentException('The action ' . $key . ' is already a core action'); + } - $this->actions[$key] = $actions; - } + $this->actions[$key] = $actions; + } - if (is_array($settings) === true) { - return $this->setCategories($settings); - } + if (is_array($settings) === true) { + return $this->setCategories($settings); + } - if (is_bool($settings) === true) { - return $this->setAll($settings); - } - } + if (is_bool($settings) === true) { + return $this->setAll($settings); + } + } - /** - * @param string|null $category - * @param string|null $action - * @return bool - */ - public function for(string $category = null, string $action = null): bool - { - if ($action === null) { - if ($this->hasCategory($category) === false) { - return false; - } + /** + * @param string|null $category + * @param string|null $action + * @return bool + */ + public function for(string $category = null, string $action = null): bool + { + if ($action === null) { + if ($this->hasCategory($category) === false) { + return false; + } - return $this->actions[$category]; - } + return $this->actions[$category]; + } - if ($this->hasAction($category, $action) === false) { - return false; - } + if ($this->hasAction($category, $action) === false) { + return false; + } - return $this->actions[$category][$action]; - } + return $this->actions[$category][$action]; + } - /** - * @param string $category - * @param string $action - * @return bool - */ - protected function hasAction(string $category, string $action): bool - { - return $this->hasCategory($category) === true && array_key_exists($action, $this->actions[$category]) === true; - } + /** + * @param string $category + * @param string $action + * @return bool + */ + protected function hasAction(string $category, string $action): bool + { + return $this->hasCategory($category) === true && array_key_exists($action, $this->actions[$category]) === true; + } - /** - * @param string $category - * @return bool - */ - protected function hasCategory(string $category): bool - { - return array_key_exists($category, $this->actions) === true; - } + /** + * @param string $category + * @return bool + */ + protected function hasCategory(string $category): bool + { + return array_key_exists($category, $this->actions) === true; + } - /** - * @param string $category - * @param string $action - * @param $setting - * @return $this - */ - protected function setAction(string $category, string $action, $setting) - { - // deprecated fallback for the settings/system view - // TODO: remove in 3.8.0 - if ($category === 'access' && $action === 'settings') { - $action = 'system'; - } + /** + * @param string $category + * @param string $action + * @param $setting + * @return $this + */ + protected function setAction(string $category, string $action, $setting) + { + // deprecated fallback for the settings/system view + // TODO: remove in 3.8.0 + if ($category === 'access' && $action === 'settings') { + $action = 'system'; + } - // wildcard to overwrite the entire category - if ($action === '*') { - return $this->setCategory($category, $setting); - } + // wildcard to overwrite the entire category + if ($action === '*') { + return $this->setCategory($category, $setting); + } - $this->actions[$category][$action] = $setting; + $this->actions[$category][$action] = $setting; - return $this; - } + return $this; + } - /** - * @param bool $setting - * @return $this - */ - protected function setAll(bool $setting) - { - foreach ($this->actions as $categoryName => $actions) { - $this->setCategory($categoryName, $setting); - } + /** + * @param bool $setting + * @return $this + */ + protected function setAll(bool $setting) + { + foreach ($this->actions as $categoryName => $actions) { + $this->setCategory($categoryName, $setting); + } - return $this; - } + return $this; + } - /** - * @param array $settings - * @return $this - */ - protected function setCategories(array $settings) - { - foreach ($settings as $categoryName => $categoryActions) { - if (is_bool($categoryActions) === true) { - $this->setCategory($categoryName, $categoryActions); - } + /** + * @param array $settings + * @return $this + */ + protected function setCategories(array $settings) + { + foreach ($settings as $categoryName => $categoryActions) { + if (is_bool($categoryActions) === true) { + $this->setCategory($categoryName, $categoryActions); + } - if (is_array($categoryActions) === true) { - foreach ($categoryActions as $actionName => $actionSetting) { - $this->setAction($categoryName, $actionName, $actionSetting); - } - } - } + if (is_array($categoryActions) === true) { + foreach ($categoryActions as $actionName => $actionSetting) { + $this->setAction($categoryName, $actionName, $actionSetting); + } + } + } - return $this; - } + return $this; + } - /** - * @param string $category - * @param bool $setting - * @return $this - * @throws \Kirby\Exception\InvalidArgumentException - */ - protected function setCategory(string $category, bool $setting) - { - if ($this->hasCategory($category) === false) { - throw new InvalidArgumentException('Invalid permissions category'); - } + /** + * @param string $category + * @param bool $setting + * @return $this + * @throws \Kirby\Exception\InvalidArgumentException + */ + protected function setCategory(string $category, bool $setting) + { + if ($this->hasCategory($category) === false) { + throw new InvalidArgumentException('Invalid permissions category'); + } - foreach ($this->actions[$category] as $actionName => $actionSetting) { - $this->actions[$category][$actionName] = $setting; - } + foreach ($this->actions[$category] as $actionName => $actionSetting) { + $this->actions[$category][$actionName] = $setting; + } - return $this; - } + return $this; + } - /** - * @return array - */ - public function toArray(): array - { - return $this->actions; - } + /** + * @return array + */ + public function toArray(): array + { + return $this->actions; + } } diff --git a/kirby/src/Cms/Picker.php b/kirby/src/Cms/Picker.php index d141740..7c26ad6 100755 --- a/kirby/src/Cms/Picker.php +++ b/kirby/src/Cms/Picker.php @@ -14,166 +14,166 @@ namespace Kirby\Cms; */ abstract class Picker { - /** - * @var \Kirby\Cms\App - */ - protected $kirby; + /** + * @var \Kirby\Cms\App + */ + protected $kirby; - /** - * @var array - */ - protected $options; + /** + * @var array + */ + protected $options; - /** - * @var \Kirby\Cms\Site - */ - protected $site; + /** + * @var \Kirby\Cms\Site + */ + protected $site; - /** - * Creates a new Picker instance - * - * @param array $params - */ - public function __construct(array $params = []) - { - $this->options = array_merge($this->defaults(), $params); - $this->kirby = $this->options['model']->kirby(); - $this->site = $this->kirby->site(); - } + /** + * Creates a new Picker instance + * + * @param array $params + */ + public function __construct(array $params = []) + { + $this->options = array_merge($this->defaults(), $params); + $this->kirby = $this->options['model']->kirby(); + $this->site = $this->kirby->site(); + } - /** - * Return the array of default values - * - * @return array - */ - protected function defaults(): array - { - // default params - return [ - // image settings (ratio, cover, etc.) - 'image' => [], - // query template for the info field - 'info' => false, - // listing style: list, cards, cardlets - 'layout' =>'list', - // number of users displayed per pagination page - 'limit' => 20, - // optional mapping function for the result array - 'map' => null, - // the reference model - 'model' => App::instance()->site(), - // current page when paginating - 'page' => 1, - // a query string to fetch specific items - 'query' => null, - // search query - 'search' => null, - // query template for the text field - 'text' => null - ]; - } + /** + * Return the array of default values + * + * @return array + */ + protected function defaults(): array + { + // default params + return [ + // image settings (ratio, cover, etc.) + 'image' => [], + // query template for the info field + 'info' => false, + // listing style: list, cards, cardlets + 'layout' =>'list', + // number of users displayed per pagination page + 'limit' => 20, + // optional mapping function for the result array + 'map' => null, + // the reference model + 'model' => App::instance()->site(), + // current page when paginating + 'page' => 1, + // a query string to fetch specific items + 'query' => null, + // search query + 'search' => null, + // query template for the text field + 'text' => null + ]; + } - /** - * Fetches all items for the picker - * - * @return \Kirby\Cms\Collection|null - */ - abstract public function items(); + /** + * Fetches all items for the picker + * + * @return \Kirby\Cms\Collection|null + */ + abstract public function items(); - /** - * Converts all given items to an associative - * array that is already optimized for the - * panel picker component. - * - * @param \Kirby\Cms\Collection|null $items - * @return array - */ - public function itemsToArray($items = null): array - { - if ($items === null) { - return []; - } + /** + * Converts all given items to an associative + * array that is already optimized for the + * panel picker component. + * + * @param \Kirby\Cms\Collection|null $items + * @return array + */ + public function itemsToArray($items = null): array + { + if ($items === null) { + return []; + } - $result = []; + $result = []; - foreach ($items as $index => $item) { - if (empty($this->options['map']) === false) { - $result[] = $this->options['map']($item); - } else { - $result[] = $item->panel()->pickerData([ - 'image' => $this->options['image'], - 'info' => $this->options['info'], - 'layout' => $this->options['layout'], - 'model' => $this->options['model'], - 'text' => $this->options['text'], - ]); - } - } + foreach ($items as $index => $item) { + if (empty($this->options['map']) === false) { + $result[] = $this->options['map']($item); + } else { + $result[] = $item->panel()->pickerData([ + 'image' => $this->options['image'], + 'info' => $this->options['info'], + 'layout' => $this->options['layout'], + 'model' => $this->options['model'], + 'text' => $this->options['text'], + ]); + } + } - return $result; - } + return $result; + } - /** - * Apply pagination to the collection - * of items according to the options. - * - * @param \Kirby\Cms\Collection $items - * @return \Kirby\Cms\Collection - */ - public function paginate(Collection $items) - { - return $items->paginate([ - 'limit' => $this->options['limit'], - 'page' => $this->options['page'] - ]); - } + /** + * Apply pagination to the collection + * of items according to the options. + * + * @param \Kirby\Cms\Collection $items + * @return \Kirby\Cms\Collection + */ + public function paginate(Collection $items) + { + return $items->paginate([ + 'limit' => $this->options['limit'], + 'page' => $this->options['page'] + ]); + } - /** - * Return the most relevant pagination - * info as array - * - * @param \Kirby\Cms\Pagination $pagination - * @return array - */ - public function paginationToArray(Pagination $pagination): array - { - return [ - 'limit' => $pagination->limit(), - 'page' => $pagination->page(), - 'total' => $pagination->total() - ]; - } + /** + * Return the most relevant pagination + * info as array + * + * @param \Kirby\Cms\Pagination $pagination + * @return array + */ + public function paginationToArray(Pagination $pagination): array + { + return [ + 'limit' => $pagination->limit(), + 'page' => $pagination->page(), + 'total' => $pagination->total() + ]; + } - /** - * Search through the collection of items - * if not deactivate in the options - * - * @param \Kirby\Cms\Collection $items - * @return \Kirby\Cms\Collection - */ - public function search(Collection $items) - { - if (empty($this->options['search']) === false) { - return $items->search($this->options['search']); - } + /** + * Search through the collection of items + * if not deactivate in the options + * + * @param \Kirby\Cms\Collection $items + * @return \Kirby\Cms\Collection + */ + public function search(Collection $items) + { + if (empty($this->options['search']) === false) { + return $items->search($this->options['search']); + } - return $items; - } + return $items; + } - /** - * Returns an associative array - * with all information for the picker. - * This will be passed directly to the API. - * - * @return array - */ - public function toArray(): array - { - $items = $this->items(); + /** + * Returns an associative array + * with all information for the picker. + * This will be passed directly to the API. + * + * @return array + */ + public function toArray(): array + { + $items = $this->items(); - return [ - 'data' => $this->itemsToArray($items), - 'pagination' => $this->paginationToArray($items->pagination()), - ]; - } + return [ + 'data' => $this->itemsToArray($items), + 'pagination' => $this->paginationToArray($items->pagination()), + ]; + } } diff --git a/kirby/src/Cms/Plugin.php b/kirby/src/Cms/Plugin.php index 2f17dfd..ae5e07f 100755 --- a/kirby/src/Cms/Plugin.php +++ b/kirby/src/Cms/Plugin.php @@ -20,203 +20,203 @@ use Kirby\Toolkit\V; */ class Plugin extends Model { - protected $extends; - protected $info; - protected $name; - protected $root; + protected $extends; + protected $info; + protected $name; + protected $root; - /** - * @param string $key - * @param array|null $arguments - * @return mixed|null - */ - public function __call(string $key, array $arguments = null) - { - return $this->info()[$key] ?? null; - } + /** + * @param string $key + * @param array|null $arguments + * @return mixed|null + */ + public function __call(string $key, array $arguments = null) + { + return $this->info()[$key] ?? null; + } - /** - * Plugin constructor - * - * @param string $name - * @param array $extends - */ - public function __construct(string $name, array $extends = []) - { - $this->setName($name); - $this->extends = $extends; - $this->root = $extends['root'] ?? dirname(debug_backtrace()[0]['file']); - $this->info = empty($extends['info']) === false && is_array($extends['info']) ? $extends['info'] : null; + /** + * Plugin constructor + * + * @param string $name + * @param array $extends + */ + public function __construct(string $name, array $extends = []) + { + $this->setName($name); + $this->extends = $extends; + $this->root = $extends['root'] ?? dirname(debug_backtrace()[0]['file']); + $this->info = empty($extends['info']) === false && is_array($extends['info']) ? $extends['info'] : null; - unset($this->extends['root'], $this->extends['info']); - } + unset($this->extends['root'], $this->extends['info']); + } - /** - * Returns the array with author information - * from the composer file - * - * @return array - */ - public function authors(): array - { - return $this->info()['authors'] ?? []; - } + /** + * Returns the array with author information + * from the composer file + * + * @return array + */ + public function authors(): array + { + return $this->info()['authors'] ?? []; + } - /** - * Returns a comma-separated list with all author names - * - * @return string - */ - public function authorsNames(): string - { - $names = []; + /** + * Returns a comma-separated list with all author names + * + * @return string + */ + public function authorsNames(): string + { + $names = []; - foreach ($this->authors() as $author) { - $names[] = $author['name'] ?? null; - } + foreach ($this->authors() as $author) { + $names[] = $author['name'] ?? null; + } - return implode(', ', array_filter($names)); - } + return implode(', ', array_filter($names)); + } - /** - * @return array - */ - public function extends(): array - { - return $this->extends; - } + /** + * @return array + */ + public function extends(): array + { + return $this->extends; + } - /** - * Returns the unique id for the plugin - * - * @return string - */ - public function id(): string - { - return $this->name(); - } + /** + * Returns the unique id for the plugin + * + * @return string + */ + public function id(): string + { + return $this->name(); + } - /** - * @return array - */ - public function info(): array - { - if (is_array($this->info) === true) { - return $this->info; - } + /** + * @return array + */ + public function info(): array + { + if (is_array($this->info) === true) { + return $this->info; + } - try { - $info = Data::read($this->manifest()); - } catch (Exception $e) { - // there is no manifest file or it is invalid - $info = []; - } + try { + $info = Data::read($this->manifest()); + } catch (Exception $e) { + // there is no manifest file or it is invalid + $info = []; + } - return $this->info = $info; - } + return $this->info = $info; + } - /** - * Returns the link to the plugin homepage - * - * @return string|null - */ - public function link(): ?string - { - $info = $this->info(); - $homepage = $info['homepage'] ?? null; - $docs = $info['support']['docs'] ?? null; - $source = $info['support']['source'] ?? null; + /** + * Returns the link to the plugin homepage + * + * @return string|null + */ + public function link(): ?string + { + $info = $this->info(); + $homepage = $info['homepage'] ?? null; + $docs = $info['support']['docs'] ?? null; + $source = $info['support']['source'] ?? null; - $link = $homepage ?? $docs ?? $source; + $link = $homepage ?? $docs ?? $source; - return V::url($link) ? $link : null; - } + return V::url($link) ? $link : null; + } - /** - * @return string - */ - public function manifest(): string - { - return $this->root() . '/composer.json'; - } + /** + * @return string + */ + public function manifest(): string + { + return $this->root() . '/composer.json'; + } - /** - * @return string - */ - public function mediaRoot(): string - { - return App::instance()->root('media') . '/plugins/' . $this->name(); - } + /** + * @return string + */ + public function mediaRoot(): string + { + return App::instance()->root('media') . '/plugins/' . $this->name(); + } - /** - * @return string - */ - public function mediaUrl(): string - { - return App::instance()->url('media') . '/plugins/' . $this->name(); - } + /** + * @return string + */ + public function mediaUrl(): string + { + return App::instance()->url('media') . '/plugins/' . $this->name(); + } - /** - * @return string - */ - public function name(): string - { - return $this->name; - } + /** + * @return string + */ + public function name(): string + { + return $this->name; + } - /** - * @param string $key - * @return mixed - */ - public function option(string $key) - { - return $this->kirby()->option($this->prefix() . '.' . $key); - } + /** + * @param string $key + * @return mixed + */ + public function option(string $key) + { + return $this->kirby()->option($this->prefix() . '.' . $key); + } - /** - * @return string - */ - public function prefix(): string - { - return str_replace('/', '.', $this->name()); - } + /** + * @return string + */ + public function prefix(): string + { + return str_replace('/', '.', $this->name()); + } - /** - * @return string - */ - public function root(): string - { - return $this->root; - } + /** + * @return string + */ + public function root(): string + { + return $this->root; + } - /** - * @param string $name - * @return $this - * @throws \Kirby\Exception\InvalidArgumentException - */ - protected function setName(string $name) - { - if (preg_match('!^[a-z0-9-]+\/[a-z0-9-]+$!i', $name) !== 1) { - throw new InvalidArgumentException('The plugin name must follow the format "a-z0-9-/a-z0-9-"'); - } + /** + * @param string $name + * @return $this + * @throws \Kirby\Exception\InvalidArgumentException + */ + protected function setName(string $name) + { + if (preg_match('!^[a-z0-9-]+\/[a-z0-9-]+$!i', $name) !== 1) { + throw new InvalidArgumentException('The plugin name must follow the format "a-z0-9-/a-z0-9-"'); + } - $this->name = $name; - return $this; - } + $this->name = $name; + return $this; + } - /** - * @return array - */ - public function toArray(): array - { - return [ - 'authors' => $this->authors(), - 'description' => $this->description(), - 'name' => $this->name(), - 'license' => $this->license(), - 'link' => $this->link(), - 'root' => $this->root(), - 'version' => $this->version() - ]; - } + /** + * @return array + */ + public function toArray(): array + { + return [ + 'authors' => $this->authors(), + 'description' => $this->description(), + 'name' => $this->name(), + 'license' => $this->license(), + 'link' => $this->link(), + 'root' => $this->root(), + 'version' => $this->version() + ]; + } } diff --git a/kirby/src/Cms/PluginAssets.php b/kirby/src/Cms/PluginAssets.php index 6af559a..a05ffea 100755 --- a/kirby/src/Cms/PluginAssets.php +++ b/kirby/src/Cms/PluginAssets.php @@ -19,62 +19,62 @@ use Kirby\Http\Response; */ class PluginAssets { - /** - * Clean old/deprecated assets on every resolve - * - * @param string $pluginName - * @return void - */ - public static function clean(string $pluginName): void - { - if ($plugin = App::instance()->plugin($pluginName)) { - $root = $plugin->root() . '/assets'; - $media = $plugin->mediaRoot(); - $assets = Dir::index($media, true); + /** + * Clean old/deprecated assets on every resolve + * + * @param string $pluginName + * @return void + */ + public static function clean(string $pluginName): void + { + if ($plugin = App::instance()->plugin($pluginName)) { + $root = $plugin->root() . '/assets'; + $media = $plugin->mediaRoot(); + $assets = Dir::index($media, true); - foreach ($assets as $asset) { - $original = $root . '/' . $asset; + foreach ($assets as $asset) { + $original = $root . '/' . $asset; - if (file_exists($original) === false) { - $assetRoot = $media . '/' . $asset; + if (file_exists($original) === false) { + $assetRoot = $media . '/' . $asset; - if (is_file($assetRoot) === true) { - F::remove($assetRoot); - } else { - Dir::remove($assetRoot); - } - } - } - } - } + if (is_file($assetRoot) === true) { + F::remove($assetRoot); + } else { + Dir::remove($assetRoot); + } + } + } + } + } - /** - * Create a symlink for a plugin asset and - * return the public URL - * - * @param string $pluginName - * @param string $filename - * @return \Kirby\Cms\Response|null - */ - public static function resolve(string $pluginName, string $filename) - { - if ($plugin = App::instance()->plugin($pluginName)) { - $source = $plugin->root() . '/assets/' . $filename; + /** + * Create a symlink for a plugin asset and + * return the public URL + * + * @param string $pluginName + * @param string $filename + * @return \Kirby\Cms\Response|null + */ + public static function resolve(string $pluginName, string $filename) + { + if ($plugin = App::instance()->plugin($pluginName)) { + $source = $plugin->root() . '/assets/' . $filename; - if (F::exists($source, $plugin->root()) === true) { - // do some spring cleaning for older files - static::clean($pluginName); + if (F::exists($source, $plugin->root()) === true) { + // do some spring cleaning for older files + static::clean($pluginName); - $target = $plugin->mediaRoot() . '/' . $filename; + $target = $plugin->mediaRoot() . '/' . $filename; - // create a symlink if possible - F::link($source, $target, 'symlink'); + // create a symlink if possible + F::link($source, $target, 'symlink'); - // return the file response - return Response::file($source); - } - } + // return the file response + return Response::file($source); + } + } - return null; - } + return null; + } } diff --git a/kirby/src/Cms/R.php b/kirby/src/Cms/R.php index ee881cf..5ef5df9 100755 --- a/kirby/src/Cms/R.php +++ b/kirby/src/Cms/R.php @@ -15,11 +15,11 @@ use Kirby\Toolkit\Facade; */ class R extends Facade { - /** - * @return \Kirby\Http\Request - */ - public static function instance() - { - return App::instance()->request(); - } + /** + * @return \Kirby\Http\Request + */ + public static function instance() + { + return App::instance()->request(); + } } diff --git a/kirby/src/Cms/Responder.php b/kirby/src/Cms/Responder.php index 92d1974..7f3d38e 100755 --- a/kirby/src/Cms/Responder.php +++ b/kirby/src/Cms/Responder.php @@ -17,431 +17,431 @@ use Kirby\Toolkit\Str; */ class Responder { - /** - * Timestamp when the response expires - * in Kirby's cache - * - * @var int|null - */ - protected $expires = null; + /** + * Timestamp when the response expires + * in Kirby's cache + * + * @var int|null + */ + protected $expires = null; - /** - * HTTP status code - * - * @var int - */ - protected $code = null; + /** + * HTTP status code + * + * @var int + */ + protected $code = null; - /** - * Response body - * - * @var string - */ - protected $body = null; + /** + * Response body + * + * @var string + */ + protected $body = null; - /** - * Flag that defines whether the current - * response can be cached by Kirby's cache - * - * @var bool - */ - protected $cache = true; + /** + * Flag that defines whether the current + * response can be cached by Kirby's cache + * + * @var bool + */ + protected $cache = true; - /** - * HTTP headers - * - * @var array - */ - protected $headers = []; + /** + * HTTP headers + * + * @var array + */ + protected $headers = []; - /** - * Content type - * - * @var string - */ - protected $type = null; + /** + * Content type + * + * @var string + */ + protected $type = null; - /** - * Flag that defines whether the current - * response uses the HTTP `Authorization` - * request header - * - * @var bool - */ - protected $usesAuth = false; + /** + * Flag that defines whether the current + * response uses the HTTP `Authorization` + * request header + * + * @var bool + */ + protected $usesAuth = false; - /** - * List of cookie names the response - * relies on - * - * @var array - */ - protected $usesCookies = []; + /** + * List of cookie names the response + * relies on + * + * @var array + */ + protected $usesCookies = []; - /** - * Creates and sends the response - * - * @return string - */ - public function __toString(): string - { - return (string)$this->send(); - } + /** + * Creates and sends the response + * + * @return string + */ + public function __toString(): string + { + return (string)$this->send(); + } - /** - * Setter and getter for the response body - * - * @param string|null $body - * @return string|$this - */ - public function body(string $body = null) - { - if ($body === null) { - return $this->body; - } + /** + * Setter and getter for the response body + * + * @param string|null $body + * @return string|$this + */ + public function body(string $body = null) + { + if ($body === null) { + return $this->body; + } - $this->body = $body; - return $this; - } + $this->body = $body; + return $this; + } - /** - * Setter and getter for the flag that defines - * whether the current response can be cached - * by Kirby's cache - * @since 3.5.5 - * - * @param bool|null $cache - * @return bool|$this - */ - public function cache(?bool $cache = null) - { - if ($cache === null) { - // never ever cache private responses - if (static::isPrivate($this->usesAuth(), $this->usesCookies()) === true) { - return false; - } + /** + * Setter and getter for the flag that defines + * whether the current response can be cached + * by Kirby's cache + * @since 3.5.5 + * + * @param bool|null $cache + * @return bool|$this + */ + public function cache(?bool $cache = null) + { + if ($cache === null) { + // never ever cache private responses + if (static::isPrivate($this->usesAuth(), $this->usesCookies()) === true) { + return false; + } - return $this->cache; - } + return $this->cache; + } - $this->cache = $cache; - return $this; - } + $this->cache = $cache; + return $this; + } - /** - * Setter and getter for the flag that defines - * whether the current response uses the HTTP - * `Authorization` request header - * @since 3.7.0 - * - * @param bool|null $usesAuth - * @return bool|$this - */ - public function usesAuth(?bool $usesAuth = null) - { - if ($usesAuth === null) { - return $this->usesAuth; - } + /** + * Setter and getter for the flag that defines + * whether the current response uses the HTTP + * `Authorization` request header + * @since 3.7.0 + * + * @param bool|null $usesAuth + * @return bool|$this + */ + public function usesAuth(?bool $usesAuth = null) + { + if ($usesAuth === null) { + return $this->usesAuth; + } - $this->usesAuth = $usesAuth; - return $this; - } + $this->usesAuth = $usesAuth; + return $this; + } - /** - * Setter for a cookie name that is - * used by the response - * @since 3.7.0 - * - * @param string $name - * @return void - */ - public function usesCookie(string $name): void - { - // only add unique names - if (in_array($name, $this->usesCookies) === false) { - $this->usesCookies[] = $name; - } - } + /** + * Setter for a cookie name that is + * used by the response + * @since 3.7.0 + * + * @param string $name + * @return void + */ + public function usesCookie(string $name): void + { + // only add unique names + if (in_array($name, $this->usesCookies) === false) { + $this->usesCookies[] = $name; + } + } - /** - * Setter and getter for the list of cookie - * names the response relies on - * @since 3.7.0 - * - * @param array|null $usesCookies - * @return array|$this - */ - public function usesCookies(?array $usesCookies = null) - { - if ($usesCookies === null) { - return $this->usesCookies; - } + /** + * Setter and getter for the list of cookie + * names the response relies on + * @since 3.7.0 + * + * @param array|null $usesCookies + * @return array|$this + */ + public function usesCookies(?array $usesCookies = null) + { + if ($usesCookies === null) { + return $this->usesCookies; + } - $this->usesCookies = $usesCookies; - return $this; - } + $this->usesCookies = $usesCookies; + return $this; + } - /** - * Setter and getter for the cache expiry - * timestamp for Kirby's cache - * @since 3.5.5 - * - * @param int|string|null $expires Timestamp, number of minutes or time string to parse - * @param bool $override If `true`, the already defined timestamp will be overridden - * @return int|null|$this - */ - public function expires($expires = null, bool $override = false) - { - // getter - if ($expires === null && $override === false) { - return $this->expires; - } + /** + * Setter and getter for the cache expiry + * timestamp for Kirby's cache + * @since 3.5.5 + * + * @param int|string|null $expires Timestamp, number of minutes or time string to parse + * @param bool $override If `true`, the already defined timestamp will be overridden + * @return int|null|$this + */ + public function expires($expires = null, bool $override = false) + { + // getter + if ($expires === null && $override === false) { + return $this->expires; + } - // explicit un-setter - if ($expires === null) { - $this->expires = null; - return $this; - } + // explicit un-setter + if ($expires === null) { + $this->expires = null; + return $this; + } - // normalize the value to an integer timestamp - if (is_int($expires) === true && $expires < 1000000000) { - // number of minutes - $expires = time() + ($expires * 60); - } elseif (is_int($expires) !== true) { - // time string - $parsedExpires = strtotime($expires); + // normalize the value to an integer timestamp + if (is_int($expires) === true && $expires < 1000000000) { + // number of minutes + $expires = time() + ($expires * 60); + } elseif (is_int($expires) !== true) { + // time string + $parsedExpires = strtotime($expires); - if (is_int($parsedExpires) !== true) { - throw new InvalidArgumentException('Invalid time string "' . $expires . '"'); - } + if (is_int($parsedExpires) !== true) { + throw new InvalidArgumentException('Invalid time string "' . $expires . '"'); + } - $expires = $parsedExpires; - } + $expires = $parsedExpires; + } - // by default only ever *reduce* the cache expiry time - if ( - $override === true || - $this->expires === null || - $expires < $this->expires - ) { - $this->expires = $expires; - } + // by default only ever *reduce* the cache expiry time + if ( + $override === true || + $this->expires === null || + $expires < $this->expires + ) { + $this->expires = $expires; + } - return $this; - } + return $this; + } - /** - * Setter and getter for the status code - * - * @param int|null $code - * @return int|$this - */ - public function code(int $code = null) - { - if ($code === null) { - return $this->code; - } + /** + * Setter and getter for the status code + * + * @param int|null $code + * @return int|$this + */ + public function code(int $code = null) + { + if ($code === null) { + return $this->code; + } - $this->code = $code; - return $this; - } + $this->code = $code; + return $this; + } - /** - * Construct response from an array - * - * @param array $response - */ - public function fromArray(array $response): void - { - $this->body($response['body'] ?? null); - $this->cache($response['cache'] ?? null); - $this->code($response['code'] ?? null); - $this->expires($response['expires'] ?? null); - $this->headers($response['headers'] ?? null); - $this->type($response['type'] ?? null); - $this->usesAuth($response['usesAuth'] ?? null); - $this->usesCookies($response['usesCookies'] ?? null); - } + /** + * Construct response from an array + * + * @param array $response + */ + public function fromArray(array $response): void + { + $this->body($response['body'] ?? null); + $this->cache($response['cache'] ?? null); + $this->code($response['code'] ?? null); + $this->expires($response['expires'] ?? null); + $this->headers($response['headers'] ?? null); + $this->type($response['type'] ?? null); + $this->usesAuth($response['usesAuth'] ?? null); + $this->usesCookies($response['usesCookies'] ?? null); + } - /** - * Setter and getter for a single header - * - * @param string $key - * @param string|false|null $value - * @param bool $lazy If `true`, an existing header value is not overridden - * @return string|$this - */ - public function header(string $key, $value = null, bool $lazy = false) - { - if ($value === null) { - return $this->headers()[$key] ?? null; - } + /** + * Setter and getter for a single header + * + * @param string $key + * @param string|false|null $value + * @param bool $lazy If `true`, an existing header value is not overridden + * @return string|$this + */ + public function header(string $key, $value = null, bool $lazy = false) + { + if ($value === null) { + return $this->headers()[$key] ?? null; + } - if ($value === false) { - unset($this->headers[$key]); - return $this; - } + if ($value === false) { + unset($this->headers[$key]); + return $this; + } - if ($lazy === true && isset($this->headers[$key]) === true) { - return $this; - } + if ($lazy === true && isset($this->headers[$key]) === true) { + return $this; + } - $this->headers[$key] = $value; - return $this; - } + $this->headers[$key] = $value; + return $this; + } - /** - * Setter and getter for all headers - * - * @param array|null $headers - * @return array|$this - */ - public function headers(array $headers = null) - { - if ($headers === null) { - $injectedHeaders = []; + /** + * Setter and getter for all headers + * + * @param array|null $headers + * @return array|$this + */ + public function headers(array $headers = null) + { + if ($headers === null) { + $injectedHeaders = []; - if (static::isPrivate($this->usesAuth(), $this->usesCookies()) === true) { - // never ever cache private responses - $injectedHeaders['Cache-Control'] = 'no-store, private'; - } else { - // the response is public, but it may - // vary based on request headers - $vary = []; + if (static::isPrivate($this->usesAuth(), $this->usesCookies()) === true) { + // never ever cache private responses + $injectedHeaders['Cache-Control'] = 'no-store, private'; + } else { + // the response is public, but it may + // vary based on request headers + $vary = []; - if ($this->usesAuth() === true) { - $vary[] = 'Authorization'; - } + if ($this->usesAuth() === true) { + $vary[] = 'Authorization'; + } - if ($this->usesCookies() !== []) { - $vary[] = 'Cookie'; - } + if ($this->usesCookies() !== []) { + $vary[] = 'Cookie'; + } - if ($vary !== []) { - $injectedHeaders['Vary'] = implode(', ', $vary); - } - } + if ($vary !== []) { + $injectedHeaders['Vary'] = implode(', ', $vary); + } + } - // lazily inject (never override custom headers) - return array_merge($injectedHeaders, $this->headers); - } + // lazily inject (never override custom headers) + return array_merge($injectedHeaders, $this->headers); + } - $this->headers = $headers; - return $this; - } + $this->headers = $headers; + return $this; + } - /** - * Shortcut to configure a json response - * - * @param array|null $json - * @return string|$this - */ - public function json(array $json = null) - { - if ($json !== null) { - $this->body(json_encode($json)); - } + /** + * Shortcut to configure a json response + * + * @param array|null $json + * @return string|$this + */ + public function json(array $json = null) + { + if ($json !== null) { + $this->body(json_encode($json)); + } - return $this->type('application/json'); - } + return $this->type('application/json'); + } - /** - * Shortcut to create a redirect response - * - * @param string|null $location - * @param int|null $code - * @return $this - */ - public function redirect(?string $location = null, ?int $code = null) - { - $location = Url::to($location ?? '/'); - $location = Url::unIdn($location); + /** + * Shortcut to create a redirect response + * + * @param string|null $location + * @param int|null $code + * @return $this + */ + public function redirect(?string $location = null, ?int $code = null) + { + $location = Url::to($location ?? '/'); + $location = Url::unIdn($location); - return $this - ->header('Location', (string)$location) - ->code($code ?? 302); - } + return $this + ->header('Location', (string)$location) + ->code($code ?? 302); + } - /** - * Creates and returns the response object from the config - * - * @param string|null $body - * @return \Kirby\Cms\Response - */ - public function send(string $body = null) - { - if ($body !== null) { - $this->body($body); - } + /** + * Creates and returns the response object from the config + * + * @param string|null $body + * @return \Kirby\Cms\Response + */ + public function send(string $body = null) + { + if ($body !== null) { + $this->body($body); + } - return new Response($this->toArray()); - } + return new Response($this->toArray()); + } - /** - * Converts the response configuration - * to an array - * - * @return array - */ - public function toArray(): array - { - // the `cache`, `expires`, `usesAuth` and `usesCookies` - // values are explicitly *not* serialized as they are - // volatile and not to be exported - return [ - 'body' => $this->body(), - 'code' => $this->code(), - 'headers' => $this->headers(), - 'type' => $this->type(), - ]; - } + /** + * Converts the response configuration + * to an array + * + * @return array + */ + public function toArray(): array + { + // the `cache`, `expires`, `usesAuth` and `usesCookies` + // values are explicitly *not* serialized as they are + // volatile and not to be exported + return [ + 'body' => $this->body(), + 'code' => $this->code(), + 'headers' => $this->headers(), + 'type' => $this->type(), + ]; + } - /** - * Setter and getter for the content type - * - * @param string|null $type - * @return string|$this - */ - public function type(string $type = null) - { - if ($type === null) { - return $this->type; - } + /** + * Setter and getter for the content type + * + * @param string|null $type + * @return string|$this + */ + public function type(string $type = null) + { + if ($type === null) { + return $this->type; + } - if (Str::contains($type, '/') === false) { - $type = Mime::fromExtension($type); - } + if (Str::contains($type, '/') === false) { + $type = Mime::fromExtension($type); + } - $this->type = $type; - return $this; - } + $this->type = $type; + return $this; + } - /** - * Checks whether the response needs to be exempted from - * all caches due to using dynamic data based on auth - * and/or cookies; the request data only matters if it - * is actually used/relied on by the response - * @since 3.7.0 - * @internal - * - * @param bool $usesAuth - * @param array $usesCookies - * @return bool - */ - public static function isPrivate(bool $usesAuth, array $usesCookies): bool - { - $kirby = App::instance(); + /** + * Checks whether the response needs to be exempted from + * all caches due to using dynamic data based on auth + * and/or cookies; the request data only matters if it + * is actually used/relied on by the response + * @since 3.7.0 + * @internal + * + * @param bool $usesAuth + * @param array $usesCookies + * @return bool + */ + public static function isPrivate(bool $usesAuth, array $usesCookies): bool + { + $kirby = App::instance(); - if ($usesAuth === true && $kirby->request()->hasAuth() === true) { - return true; - } + if ($usesAuth === true && $kirby->request()->hasAuth() === true) { + return true; + } - foreach ($usesCookies as $cookie) { - if (isset($_COOKIE[$cookie]) === true) { - return true; - } - } + foreach ($usesCookies as $cookie) { + if (isset($_COOKIE[$cookie]) === true) { + return true; + } + } - return false; - } + return false; + } } diff --git a/kirby/src/Cms/Response.php b/kirby/src/Cms/Response.php index b4f9636..9674440 100755 --- a/kirby/src/Cms/Response.php +++ b/kirby/src/Cms/Response.php @@ -14,17 +14,17 @@ namespace Kirby\Cms; */ class Response extends \Kirby\Http\Response { - /** - * Adjusted redirect creation which - * parses locations with the Url::to method - * first. - * - * @param string $location - * @param int $code - * @return static - */ - public static function redirect(string $location = '/', int $code = 302) - { - return parent::redirect(Url::to($location), $code); - } + /** + * Adjusted redirect creation which + * parses locations with the Url::to method + * first. + * + * @param string $location + * @param int $code + * @return static + */ + public static function redirect(string $location = '/', int $code = 302) + { + return parent::redirect(Url::to($location), $code); + } } diff --git a/kirby/src/Cms/Role.php b/kirby/src/Cms/Role.php index e943864..aa22264 100755 --- a/kirby/src/Cms/Role.php +++ b/kirby/src/Cms/Role.php @@ -19,214 +19,214 @@ use Kirby\Toolkit\I18n; */ class Role extends Model { - protected $description; - protected $name; - protected $permissions; - protected $title; + protected $description; + protected $name; + protected $permissions; + protected $title; - public function __construct(array $props) - { - $this->setProperties($props); - } + public function __construct(array $props) + { + $this->setProperties($props); + } - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return $this->toArray(); - } + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return $this->toArray(); + } - /** - * @return string - */ - public function __toString(): string - { - return $this->name(); - } + /** + * @return string + */ + public function __toString(): string + { + return $this->name(); + } - /** - * @param array $inject - * @return static - */ - public static function admin(array $inject = []) - { - try { - return static::load('admin'); - } catch (Exception $e) { - return static::factory(static::defaults()['admin'], $inject); - } - } + /** + * @param array $inject + * @return static + */ + public static function admin(array $inject = []) + { + try { + return static::load('admin'); + } catch (Exception $e) { + return static::factory(static::defaults()['admin'], $inject); + } + } - /** - * @return array - */ - protected static function defaults(): array - { - return [ - 'admin' => [ - 'name' => 'admin', - 'description' => I18n::translate('role.admin.description'), - 'title' => I18n::translate('role.admin.title'), - 'permissions' => true, - ], - 'nobody' => [ - 'name' => 'nobody', - 'description' => I18n::translate('role.nobody.description'), - 'title' => I18n::translate('role.nobody.title'), - 'permissions' => false, - ] - ]; - } + /** + * @return array + */ + protected static function defaults(): array + { + return [ + 'admin' => [ + 'name' => 'admin', + 'description' => I18n::translate('role.admin.description'), + 'title' => I18n::translate('role.admin.title'), + 'permissions' => true, + ], + 'nobody' => [ + 'name' => 'nobody', + 'description' => I18n::translate('role.nobody.description'), + 'title' => I18n::translate('role.nobody.title'), + 'permissions' => false, + ] + ]; + } - /** - * @return mixed - */ - public function description() - { - return $this->description; - } + /** + * @return mixed + */ + public function description() + { + return $this->description; + } - /** - * @param array $props - * @param array $inject - * @return static - */ - public static function factory(array $props, array $inject = []) - { - return new static($props + $inject); - } + /** + * @param array $props + * @param array $inject + * @return static + */ + public static function factory(array $props, array $inject = []) + { + return new static($props + $inject); + } - /** - * @return string - */ - public function id(): string - { - return $this->name(); - } + /** + * @return string + */ + public function id(): string + { + return $this->name(); + } - /** - * @return bool - */ - public function isAdmin(): bool - { - return $this->name() === 'admin'; - } + /** + * @return bool + */ + public function isAdmin(): bool + { + return $this->name() === 'admin'; + } - /** - * @return bool - */ - public function isNobody(): bool - { - return $this->name() === 'nobody'; - } + /** + * @return bool + */ + public function isNobody(): bool + { + return $this->name() === 'nobody'; + } - /** - * @param string $file - * @param array $inject - * @return static - */ - public static function load(string $file, array $inject = []) - { - $data = Data::read($file); - $data['name'] = F::name($file); + /** + * @param string $file + * @param array $inject + * @return static + */ + public static function load(string $file, array $inject = []) + { + $data = Data::read($file); + $data['name'] = F::name($file); - return static::factory($data, $inject); - } + return static::factory($data, $inject); + } - /** - * @return string - */ - public function name(): string - { - return $this->name; - } + /** + * @return string + */ + public function name(): string + { + return $this->name; + } - /** - * @param array $inject - * @return static - */ - public static function nobody(array $inject = []) - { - try { - return static::load('nobody'); - } catch (Exception $e) { - return static::factory(static::defaults()['nobody'], $inject); - } - } + /** + * @param array $inject + * @return static + */ + public static function nobody(array $inject = []) + { + try { + return static::load('nobody'); + } catch (Exception $e) { + return static::factory(static::defaults()['nobody'], $inject); + } + } - /** - * @return \Kirby\Cms\Permissions - */ - public function permissions() - { - return $this->permissions; - } + /** + * @return \Kirby\Cms\Permissions + */ + public function permissions() + { + return $this->permissions; + } - /** - * @param mixed $description - * @return $this - */ - protected function setDescription($description = null) - { - $this->description = I18n::translate($description, $description); - return $this; - } + /** + * @param mixed $description + * @return $this + */ + protected function setDescription($description = null) + { + $this->description = I18n::translate($description, $description); + return $this; + } - /** - * @param string $name - * @return $this - */ - protected function setName(string $name) - { - $this->name = $name; - return $this; - } + /** + * @param string $name + * @return $this + */ + protected function setName(string $name) + { + $this->name = $name; + return $this; + } - /** - * @param mixed $permissions - * @return $this - */ - protected function setPermissions($permissions = null) - { - $this->permissions = new Permissions($permissions); - return $this; - } + /** + * @param mixed $permissions + * @return $this + */ + protected function setPermissions($permissions = null) + { + $this->permissions = new Permissions($permissions); + return $this; + } - /** - * @param mixed $title - * @return $this - */ - protected function setTitle($title = null) - { - $this->title = I18n::translate($title, $title); - return $this; - } + /** + * @param mixed $title + * @return $this + */ + protected function setTitle($title = null) + { + $this->title = I18n::translate($title, $title); + return $this; + } - /** - * @return string - */ - public function title(): string - { - return $this->title ??= ucfirst($this->name()); - } + /** + * @return string + */ + public function title(): string + { + return $this->title ??= ucfirst($this->name()); + } - /** - * Converts the most important role - * properties to an array - * - * @return array - */ - public function toArray(): array - { - return [ - 'description' => $this->description(), - 'id' => $this->id(), - 'name' => $this->name(), - 'permissions' => $this->permissions()->toArray(), - 'title' => $this->title(), - ]; - } + /** + * Converts the most important role + * properties to an array + * + * @return array + */ + public function toArray(): array + { + return [ + 'description' => $this->description(), + 'id' => $this->id(), + 'name' => $this->name(), + 'permissions' => $this->permissions()->toArray(), + 'title' => $this->title(), + ]; + } } diff --git a/kirby/src/Cms/Roles.php b/kirby/src/Cms/Roles.php index e4bad3f..fb99dd0 100755 --- a/kirby/src/Cms/Roles.php +++ b/kirby/src/Cms/Roles.php @@ -18,128 +18,128 @@ namespace Kirby\Cms; */ class Roles extends Collection { - /** - * Returns a filtered list of all - * roles that can be created by the - * current user - * - * @return $this|static - * @throws \Exception - */ - public function canBeChanged() - { - if (App::instance()->user()) { - return $this->filter(function ($role) { - $newUser = new User([ - 'email' => 'test@getkirby.com', - 'role' => $role->id() - ]); + /** + * Returns a filtered list of all + * roles that can be created by the + * current user + * + * @return $this|static + * @throws \Exception + */ + public function canBeChanged() + { + if (App::instance()->user()) { + return $this->filter(function ($role) { + $newUser = new User([ + 'email' => 'test@getkirby.com', + 'role' => $role->id() + ]); - return $newUser->permissions()->can('changeRole'); - }); - } + return $newUser->permissions()->can('changeRole'); + }); + } - return $this; - } + return $this; + } - /** - * Returns a filtered list of all - * roles that can be created by the - * current user - * - * @return $this|static - * @throws \Exception - */ - public function canBeCreated() - { - if (App::instance()->user()) { - return $this->filter(function ($role) { - $newUser = new User([ - 'email' => 'test@getkirby.com', - 'role' => $role->id() - ]); + /** + * Returns a filtered list of all + * roles that can be created by the + * current user + * + * @return $this|static + * @throws \Exception + */ + public function canBeCreated() + { + if (App::instance()->user()) { + return $this->filter(function ($role) { + $newUser = new User([ + 'email' => 'test@getkirby.com', + 'role' => $role->id() + ]); - return $newUser->permissions()->can('create'); - }); - } + return $newUser->permissions()->can('create'); + }); + } - return $this; - } + return $this; + } - /** - * @param array $roles - * @param array $inject - * @return static - */ - public static function factory(array $roles, array $inject = []) - { - $collection = new static(); + /** + * @param array $roles + * @param array $inject + * @return static + */ + public static function factory(array $roles, array $inject = []) + { + $collection = new static(); - // read all user blueprints - foreach ($roles as $props) { - $role = Role::factory($props, $inject); - $collection->set($role->id(), $role); - } + // read all user blueprints + foreach ($roles as $props) { + $role = Role::factory($props, $inject); + $collection->set($role->id(), $role); + } - // always include the admin role - if ($collection->find('admin') === null) { - $collection->set('admin', Role::admin()); - } + // always include the admin role + if ($collection->find('admin') === null) { + $collection->set('admin', Role::admin()); + } - // return the collection sorted by name - return $collection->sort('name', 'asc'); - } + // return the collection sorted by name + return $collection->sort('name', 'asc'); + } - /** - * @param string|null $root - * @param array $inject - * @return static - */ - public static function load(string $root = null, array $inject = []) - { - $kirby = App::instance(); - $roles = new static(); + /** + * @param string|null $root + * @param array $inject + * @return static + */ + public static function load(string $root = null, array $inject = []) + { + $kirby = App::instance(); + $roles = new static(); - // load roles from plugins - foreach ($kirby->extensions('blueprints') as $blueprintName => $blueprint) { - if (substr($blueprintName, 0, 6) !== 'users/') { - continue; - } + // load roles from plugins + foreach ($kirby->extensions('blueprints') as $blueprintName => $blueprint) { + if (substr($blueprintName, 0, 6) !== 'users/') { + continue; + } - // callback option can be return array or blueprint file path - if (is_callable($blueprint) === true) { - $blueprint = $blueprint($kirby); - } + // callback option can be return array or blueprint file path + if (is_callable($blueprint) === true) { + $blueprint = $blueprint($kirby); + } - if (is_array($blueprint) === true) { - $role = Role::factory($blueprint, $inject); - } else { - $role = Role::load($blueprint, $inject); - } + if (is_array($blueprint) === true) { + $role = Role::factory($blueprint, $inject); + } else { + $role = Role::load($blueprint, $inject); + } - $roles->set($role->id(), $role); - } + $roles->set($role->id(), $role); + } - // load roles from directory - if ($root !== null) { - foreach (glob($root . '/*.yml') as $file) { - $filename = basename($file); + // load roles from directory + if ($root !== null) { + foreach (glob($root . '/*.yml') as $file) { + $filename = basename($file); - if ($filename === 'default.yml') { - continue; - } + if ($filename === 'default.yml') { + continue; + } - $role = Role::load($file, $inject); - $roles->set($role->id(), $role); - } - } + $role = Role::load($file, $inject); + $roles->set($role->id(), $role); + } + } - // always include the admin role - if ($roles->find('admin') === null) { - $roles->set('admin', Role::admin($inject)); - } + // always include the admin role + if ($roles->find('admin') === null) { + $roles->set('admin', Role::admin($inject)); + } - // return the collection sorted by name - return $roles->sort('name', 'asc'); - } + // return the collection sorted by name + return $roles->sort('name', 'asc'); + } } diff --git a/kirby/src/Cms/S.php b/kirby/src/Cms/S.php index 0db9f93..cced071 100755 --- a/kirby/src/Cms/S.php +++ b/kirby/src/Cms/S.php @@ -15,11 +15,11 @@ use Kirby\Toolkit\Facade; */ class S extends Facade { - /** - * @return \Kirby\Session\Session - */ - public static function instance() - { - return App::instance()->session(); - } + /** + * @return \Kirby\Session\Session + */ + public static function instance() + { + return App::instance()->session(); + } } diff --git a/kirby/src/Cms/Search.php b/kirby/src/Cms/Search.php index 1782133..0169b40 100755 --- a/kirby/src/Cms/Search.php +++ b/kirby/src/Cms/Search.php @@ -16,47 +16,47 @@ namespace Kirby\Cms; */ class Search { - /** - * @param string|null $query - * @param array $params - * @return \Kirby\Cms\Files - */ - public static function files(string $query = null, $params = []) - { - return App::instance()->site()->index()->files()->search($query, $params); - } + /** + * @param string|null $query + * @param array $params + * @return \Kirby\Cms\Files + */ + public static function files(string $query = null, $params = []) + { + return App::instance()->site()->index()->files()->search($query, $params); + } - /** - * Native search method to search for anything within the collection - * - * @param \Kirby\Cms\Collection $collection - * @param string|null $query - * @param mixed $params - * @return \Kirby\Cms\Collection|bool - */ - public static function collection(Collection $collection, string $query = null, $params = []) - { - $kirby = App::instance(); - return ($kirby->component('search'))($kirby, $collection, $query, $params); - } + /** + * Native search method to search for anything within the collection + * + * @param \Kirby\Cms\Collection $collection + * @param string|null $query + * @param mixed $params + * @return \Kirby\Cms\Collection|bool + */ + public static function collection(Collection $collection, string $query = null, $params = []) + { + $kirby = App::instance(); + return ($kirby->component('search'))($kirby, $collection, $query, $params); + } - /** - * @param string|null $query - * @param array $params - * @return \Kirby\Cms\Pages - */ - public static function pages(string $query = null, $params = []) - { - return App::instance()->site()->index()->search($query, $params); - } + /** + * @param string|null $query + * @param array $params + * @return \Kirby\Cms\Pages + */ + public static function pages(string $query = null, $params = []) + { + return App::instance()->site()->index()->search($query, $params); + } - /** - * @param string|null $query - * @param array $params - * @return \Kirby\Cms\Users - */ - public static function users(string $query = null, $params = []) - { - return App::instance()->users()->search($query, $params); - } + /** + * @param string|null $query + * @param array $params + * @return \Kirby\Cms\Users + */ + public static function users(string $query = null, $params = []) + { + return App::instance()->users()->search($query, $params); + } } diff --git a/kirby/src/Cms/Section.php b/kirby/src/Cms/Section.php index 9c394c7..d68b3c2 100755 --- a/kirby/src/Cms/Section.php +++ b/kirby/src/Cms/Section.php @@ -16,92 +16,92 @@ use Kirby\Toolkit\Component; */ class Section extends Component { - /** - * Registry for all component mixins - * - * @var array - */ - public static $mixins = []; + /** + * Registry for all component mixins + * + * @var array + */ + public static $mixins = []; - /** - * Registry for all component types - * - * @var array - */ - public static $types = []; + /** + * Registry for all component types + * + * @var array + */ + public static $types = []; - /** - * Section constructor. - * - * @param string $type - * @param array $attrs - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function __construct(string $type, array $attrs = []) - { - if (isset($attrs['model']) === false) { - throw new InvalidArgumentException('Undefined section model'); - } + /** + * Section constructor. + * + * @param string $type + * @param array $attrs + * @throws \Kirby\Exception\InvalidArgumentException + */ + public function __construct(string $type, array $attrs = []) + { + if (isset($attrs['model']) === false) { + throw new InvalidArgumentException('Undefined section model'); + } - if (is_a($attrs['model'], 'Kirby\Cms\Model') === false) { - throw new InvalidArgumentException('Invalid section model'); - } + if (is_a($attrs['model'], 'Kirby\Cms\Model') === false) { + throw new InvalidArgumentException('Invalid section model'); + } - // use the type as fallback for the name - $attrs['name'] ??= $type; - $attrs['type'] = $type; + // use the type as fallback for the name + $attrs['name'] ??= $type; + $attrs['type'] = $type; - parent::__construct($type, $attrs); - } + parent::__construct($type, $attrs); + } - public function errors(): array - { - if (array_key_exists('errors', $this->methods) === true) { - return $this->methods['errors']->call($this); - } + public function errors(): array + { + if (array_key_exists('errors', $this->methods) === true) { + return $this->methods['errors']->call($this); + } - return $this->errors ?? []; - } + return $this->errors ?? []; + } - /** - * @return \Kirby\Cms\App - */ - public function kirby() - { - return $this->model()->kirby(); - } + /** + * @return \Kirby\Cms\App + */ + public function kirby() + { + return $this->model()->kirby(); + } - /** - * @return \Kirby\Cms\Model - */ - public function model() - { - return $this->model; - } + /** + * @return \Kirby\Cms\Model + */ + public function model() + { + return $this->model; + } - /** - * @return array - */ - public function toArray(): array - { - $array = parent::toArray(); + /** + * @return array + */ + public function toArray(): array + { + $array = parent::toArray(); - unset($array['model']); + unset($array['model']); - return $array; - } + return $array; + } - /** - * @return array - */ - public function toResponse(): array - { - return array_merge([ - 'status' => 'ok', - 'code' => 200, - 'name' => $this->name, - 'type' => $this->type - ], $this->toArray()); - } + /** + * @return array + */ + public function toResponse(): array + { + return array_merge([ + 'status' => 'ok', + 'code' => 200, + 'name' => $this->name, + 'type' => $this->type + ], $this->toArray()); + } } diff --git a/kirby/src/Cms/Site.php b/kirby/src/Cms/Site.php index a365173..2343ed7 100755 --- a/kirby/src/Cms/Site.php +++ b/kirby/src/Cms/Site.php @@ -22,678 +22,678 @@ use Kirby\Toolkit\A; */ class Site extends ModelWithContent { - use SiteActions; - use HasChildren; - use HasFiles; - use HasMethods; - - public const CLASS_ALIAS = 'site'; - - /** - * The SiteBlueprint object - * - * @var \Kirby\Cms\SiteBlueprint - */ - protected $blueprint; - - /** - * The error page object - * - * @var \Kirby\Cms\Page - */ - protected $errorPage; - - /** - * The id of the error page, which is - * fetched in the errorPage method - * - * @var string - */ - protected $errorPageId = 'error'; - - /** - * The home page object - * - * @var \Kirby\Cms\Page - */ - protected $homePage; - - /** - * The id of the home page, which is - * fetched in the errorPage method - * - * @var string - */ - protected $homePageId = 'home'; - - /** - * Cache for the inventory array - * - * @var array - */ - protected $inventory; - - /** - * The current page object - * - * @var \Kirby\Cms\Page - */ - protected $page; - - /** - * The absolute path to the site directory - * - * @var string - */ - protected $root; - - /** - * The page url - * - * @var string - */ - protected $url; - - /** - * Modified getter to also return fields - * from the content - * - * @param string $method - * @param array $arguments - * @return mixed - */ - public function __call(string $method, array $arguments = []) - { - // public property access - if (isset($this->$method) === true) { - return $this->$method; - } - - // site methods - if ($this->hasMethod($method)) { - return $this->callMethod($method, $arguments); - } - - // return site content otherwise - return $this->content()->get($method); - } - - /** - * Creates a new Site object - * - * @param array $props - */ - public function __construct(array $props = []) - { - $this->setProperties($props); - } - - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return array_merge($this->toArray(), [ - 'content' => $this->content(), - 'children' => $this->children(), - 'files' => $this->files(), - ]); - } - - /** - * Makes it possible to convert the site model - * to a string. Mostly useful for debugging. - * - * @return string - */ - public function __toString(): string - { - return $this->url(); - } - - /** - * Returns the url to the api endpoint - * - * @internal - * @param bool $relative - * @return string - */ - public function apiUrl(bool $relative = false): string - { - if ($relative === true) { - return 'site'; - } else { - return $this->kirby()->url('api') . '/site'; - } - } - - /** - * Returns the blueprint object - * - * @return \Kirby\Cms\SiteBlueprint - */ - public function blueprint() - { - if (is_a($this->blueprint, 'Kirby\Cms\SiteBlueprint') === true) { - return $this->blueprint; - } - - return $this->blueprint = SiteBlueprint::factory('site', null, $this); - } - - /** - * Builds a breadcrumb collection - * - * @return \Kirby\Cms\Pages - */ - public function breadcrumb() - { - // get all parents and flip the order - $crumb = $this->page()->parents()->flip(); - - // add the home page - $crumb->prepend($this->homePage()->id(), $this->homePage()); - - // add the active page - $crumb->append($this->page()->id(), $this->page()); - - return $crumb; - } - - /** - * Prepares the content for the write method - * - * @internal - * @param array $data - * @param string|null $languageCode - * @return array - */ - public function contentFileData(array $data, ?string $languageCode = null): array - { - return A::prepend($data, [ - 'title' => $data['title'] ?? null, - ]); - } - - /** - * Filename for the content file - * - * @internal - * @return string - */ - public function contentFileName(): string - { - return 'site'; - } - - /** - * Returns the error page object - * - * @return \Kirby\Cms\Page|null - */ - public function errorPage() - { - if (is_a($this->errorPage, 'Kirby\Cms\Page') === true) { - return $this->errorPage; - } - - if ($error = $this->find($this->errorPageId())) { - return $this->errorPage = $error; - } - - return null; - } - - /** - * Returns the global error page id - * - * @internal - * @return string - */ - public function errorPageId(): string - { - return $this->errorPageId ?? 'error'; - } - - /** - * Checks if the site exists on disk - * - * @return bool - */ - public function exists(): bool - { - return is_dir($this->root()) === true; - } - - /** - * Returns the home page object - * - * @return \Kirby\Cms\Page|null - */ - public function homePage() - { - if (is_a($this->homePage, 'Kirby\Cms\Page') === true) { - return $this->homePage; - } - - if ($home = $this->find($this->homePageId())) { - return $this->homePage = $home; - } - - return null; - } - - /** - * Returns the global home page id - * - * @internal - * @return string - */ - public function homePageId(): string - { - return $this->homePageId ?? 'home'; - } - - /** - * Creates an inventory of all files - * and children in the site directory - * - * @internal - * @return array - */ - public function inventory(): array - { - if ($this->inventory !== null) { - return $this->inventory; - } - - $kirby = $this->kirby(); - - return $this->inventory = Dir::inventory( - $this->root(), - $kirby->contentExtension(), - $kirby->contentIgnore(), - $kirby->multilang() - ); - } - - /** - * Compares the current object with the given site object - * - * @param mixed $site - * @return bool - */ - public function is($site): bool - { - if (is_a($site, 'Kirby\Cms\Site') === false) { - return false; - } - - return $this === $site; - } - - /** - * Returns the root to the media folder for the site - * - * @internal - * @return string - */ - public function mediaRoot(): string - { - return $this->kirby()->root('media') . '/site'; - } - - /** - * The site's base url for any files - * - * @internal - * @return string - */ - public function mediaUrl(): string - { - return $this->kirby()->url('media') . '/site'; - } - - /** - * Gets the last modification date of all pages - * in the content folder. - * - * @param string|null $format - * @param string|null $handler - * @return int|string - */ - public function modified(?string $format = null, ?string $handler = null) - { - return Dir::modified( - $this->root(), - $format, - $handler ?? $this->kirby()->option('date.handler', 'date') - ); - } - - /** - * Returns the current page if `$path` - * is not specified. Otherwise it will try - * to find a page by the given path. - * - * If no current page is set with the page - * prop, the home page will be returned if - * it can be found. (see `Site::homePage()`) - * - * @param string|null $path omit for current page, - * otherwise e.g. `notes/across-the-ocean` - * @return \Kirby\Cms\Page|null - */ - public function page(?string $path = null) - { - if ($path !== null) { - return $this->find($path); - } - - if (is_a($this->page, 'Kirby\Cms\Page') === true) { - return $this->page; - } - - try { - return $this->page = $this->homePage(); - } catch (LogicException $e) { - return $this->page = null; - } - } - - /** - * Alias for `Site::children()` - * - * @return \Kirby\Cms\Pages - */ - public function pages() - { - return $this->children(); - } - - /** - * Returns the panel info object - * - * @return \Kirby\Panel\Site - */ - public function panel() - { - return new Panel($this); - } - - /** - * Returns the permissions object for this site - * - * @return \Kirby\Cms\SitePermissions - */ - public function permissions() - { - return new SitePermissions($this); - } - - /** - * Preview Url - * - * @internal - * @return string|null - */ - public function previewUrl(): ?string - { - $preview = $this->blueprint()->preview(); - - if ($preview === false) { - return null; - } - - if ($preview === true) { - $url = $this->url(); - } else { - $url = $preview; - } - - return $url; - } - - /** - * Returns the absolute path to the content directory - * - * @return string - */ - public function root(): string - { - return $this->root ??= $this->kirby()->root('content'); - } - - /** - * Returns the SiteRules class instance - * which is being used in various methods - * to check for valid actions and input. - * - * @return \Kirby\Cms\SiteRules - */ - protected function rules() - { - return new SiteRules(); - } - - /** - * Search all pages in the site - * - * @param string|null $query - * @param array $params - * @return \Kirby\Cms\Pages - */ - public function search(?string $query = null, $params = []) - { - return $this->index()->search($query, $params); - } - - /** - * Sets the Blueprint object - * - * @param array|null $blueprint - * @return $this - */ - protected function setBlueprint(?array $blueprint = null) - { - if ($blueprint !== null) { - $blueprint['model'] = $this; - $this->blueprint = new SiteBlueprint($blueprint); - } - - return $this; - } - - /** - * Sets the id of the error page, which - * is used in the errorPage method - * to get the default error page if nothing - * else is set. - * - * @param string $id - * @return $this - */ - protected function setErrorPageId(string $id = 'error') - { - $this->errorPageId = $id; - return $this; - } - - /** - * Sets the id of the home page, which - * is used in the homePage method - * to get the default home page if nothing - * else is set. - * - * @param string $id - * @return $this - */ - protected function setHomePageId(string $id = 'home') - { - $this->homePageId = $id; - return $this; - } - - /** - * Sets the current page object - * - * @internal - * @param \Kirby\Cms\Page|null $page - * @return $this - */ - public function setPage(?Page $page = null) - { - $this->page = $page; - return $this; - } - - /** - * Sets the Url - * - * @param string|null $url - * @return $this - */ - protected function setUrl(?string $url = null) - { - $this->url = $url; - return $this; - } - - /** - * Converts the most important site - * properties to an array - * - * @return array - */ - public function toArray(): array - { - return [ - 'children' => $this->children()->keys(), - 'content' => $this->content()->toArray(), - 'errorPage' => $this->errorPage() ? $this->errorPage()->id() : false, - 'files' => $this->files()->keys(), - 'homePage' => $this->homePage() ? $this->homePage()->id() : false, - 'page' => $this->page() ? $this->page()->id() : false, - 'title' => $this->title()->value(), - 'url' => $this->url(), - ]; - } - - /** - * Returns the Url - * - * @param string|null $language - * @return string - */ - public function url(?string $language = null): string - { - if ($language !== null || $this->kirby()->multilang() === true) { - return $this->urlForLanguage($language); - } - - return $this->url ?? $this->kirby()->url(); - } - - /** - * Returns the translated url - * - * @internal - * @param string|null $languageCode - * @param array|null $options - * @return string - */ - public function urlForLanguage(?string $languageCode = null, ?array $options = null): string - { - if ($language = $this->kirby()->language($languageCode)) { - return $language->url(); - } - - return $this->kirby()->url(); - } - - /** - * Sets the current page by - * id or page object and - * returns the current page - * - * @internal - * @param string|\Kirby\Cms\Page $page - * @param string|null $languageCode - * @return \Kirby\Cms\Page - */ - public function visit($page, ?string $languageCode = null) - { - if ($languageCode !== null) { - $this->kirby()->setCurrentTranslation($languageCode); - $this->kirby()->setCurrentLanguage($languageCode); - } - - // convert ids to a Page object - if (is_string($page)) { - $page = $this->find($page); - } - - // handle invalid pages - if (is_a($page, 'Kirby\Cms\Page') === false) { - throw new InvalidArgumentException('Invalid page object'); - } - - // set the current active page - $this->setPage($page); - - // return the page - return $page; - } - - /** - * Checks if any content of the site has been - * modified after the given unix timestamp - * This is mainly used to auto-update the cache - * - * @param mixed $time - * @return bool - */ - public function wasModifiedAfter($time): bool - { - return Dir::wasModifiedAfter($this->root(), $time); - } - - - /** - * Deprecated! - */ - - /** - * Returns the full path without leading slash - * - * @todo Remove in 3.8.0 - * - * @internal - * @return string - * @codeCoverageIgnore - */ - public function panelPath(): string - { - Helpers::deprecated('Cms\Site::panelPath() has been deprecated and will be removed in Kirby 3.8.0. Use $site->panel()->path() instead.'); - return $this->panel()->path(); - } - - /** - * Returns the url to the editing view - * in the panel - * - * @todo Remove in 3.8.0 - * - * @internal - * @param bool $relative - * @return string - * @codeCoverageIgnore - */ - public function panelUrl(bool $relative = false): string - { - Helpers::deprecated('Cms\Site::panelUrl() has been deprecated and will be removed in Kirby 3.8.0. Use $site->panel()->url() instead.'); - return $this->panel()->url($relative); - } + use SiteActions; + use HasChildren; + use HasFiles; + use HasMethods; + + public const CLASS_ALIAS = 'site'; + + /** + * The SiteBlueprint object + * + * @var \Kirby\Cms\SiteBlueprint + */ + protected $blueprint; + + /** + * The error page object + * + * @var \Kirby\Cms\Page + */ + protected $errorPage; + + /** + * The id of the error page, which is + * fetched in the errorPage method + * + * @var string + */ + protected $errorPageId = 'error'; + + /** + * The home page object + * + * @var \Kirby\Cms\Page + */ + protected $homePage; + + /** + * The id of the home page, which is + * fetched in the errorPage method + * + * @var string + */ + protected $homePageId = 'home'; + + /** + * Cache for the inventory array + * + * @var array + */ + protected $inventory; + + /** + * The current page object + * + * @var \Kirby\Cms\Page + */ + protected $page; + + /** + * The absolute path to the site directory + * + * @var string + */ + protected $root; + + /** + * The page url + * + * @var string + */ + protected $url; + + /** + * Modified getter to also return fields + * from the content + * + * @param string $method + * @param array $arguments + * @return mixed + */ + public function __call(string $method, array $arguments = []) + { + // public property access + if (isset($this->$method) === true) { + return $this->$method; + } + + // site methods + if ($this->hasMethod($method)) { + return $this->callMethod($method, $arguments); + } + + // return site content otherwise + return $this->content()->get($method); + } + + /** + * Creates a new Site object + * + * @param array $props + */ + public function __construct(array $props = []) + { + $this->setProperties($props); + } + + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return array_merge($this->toArray(), [ + 'content' => $this->content(), + 'children' => $this->children(), + 'files' => $this->files(), + ]); + } + + /** + * Makes it possible to convert the site model + * to a string. Mostly useful for debugging. + * + * @return string + */ + public function __toString(): string + { + return $this->url(); + } + + /** + * Returns the url to the api endpoint + * + * @internal + * @param bool $relative + * @return string + */ + public function apiUrl(bool $relative = false): string + { + if ($relative === true) { + return 'site'; + } else { + return $this->kirby()->url('api') . '/site'; + } + } + + /** + * Returns the blueprint object + * + * @return \Kirby\Cms\SiteBlueprint + */ + public function blueprint() + { + if (is_a($this->blueprint, 'Kirby\Cms\SiteBlueprint') === true) { + return $this->blueprint; + } + + return $this->blueprint = SiteBlueprint::factory('site', null, $this); + } + + /** + * Builds a breadcrumb collection + * + * @return \Kirby\Cms\Pages + */ + public function breadcrumb() + { + // get all parents and flip the order + $crumb = $this->page()->parents()->flip(); + + // add the home page + $crumb->prepend($this->homePage()->id(), $this->homePage()); + + // add the active page + $crumb->append($this->page()->id(), $this->page()); + + return $crumb; + } + + /** + * Prepares the content for the write method + * + * @internal + * @param array $data + * @param string|null $languageCode + * @return array + */ + public function contentFileData(array $data, ?string $languageCode = null): array + { + return A::prepend($data, [ + 'title' => $data['title'] ?? null, + ]); + } + + /** + * Filename for the content file + * + * @internal + * @return string + */ + public function contentFileName(): string + { + return 'site'; + } + + /** + * Returns the error page object + * + * @return \Kirby\Cms\Page|null + */ + public function errorPage() + { + if (is_a($this->errorPage, 'Kirby\Cms\Page') === true) { + return $this->errorPage; + } + + if ($error = $this->find($this->errorPageId())) { + return $this->errorPage = $error; + } + + return null; + } + + /** + * Returns the global error page id + * + * @internal + * @return string + */ + public function errorPageId(): string + { + return $this->errorPageId ?? 'error'; + } + + /** + * Checks if the site exists on disk + * + * @return bool + */ + public function exists(): bool + { + return is_dir($this->root()) === true; + } + + /** + * Returns the home page object + * + * @return \Kirby\Cms\Page|null + */ + public function homePage() + { + if (is_a($this->homePage, 'Kirby\Cms\Page') === true) { + return $this->homePage; + } + + if ($home = $this->find($this->homePageId())) { + return $this->homePage = $home; + } + + return null; + } + + /** + * Returns the global home page id + * + * @internal + * @return string + */ + public function homePageId(): string + { + return $this->homePageId ?? 'home'; + } + + /** + * Creates an inventory of all files + * and children in the site directory + * + * @internal + * @return array + */ + public function inventory(): array + { + if ($this->inventory !== null) { + return $this->inventory; + } + + $kirby = $this->kirby(); + + return $this->inventory = Dir::inventory( + $this->root(), + $kirby->contentExtension(), + $kirby->contentIgnore(), + $kirby->multilang() + ); + } + + /** + * Compares the current object with the given site object + * + * @param mixed $site + * @return bool + */ + public function is($site): bool + { + if (is_a($site, 'Kirby\Cms\Site') === false) { + return false; + } + + return $this === $site; + } + + /** + * Returns the root to the media folder for the site + * + * @internal + * @return string + */ + public function mediaRoot(): string + { + return $this->kirby()->root('media') . '/site'; + } + + /** + * The site's base url for any files + * + * @internal + * @return string + */ + public function mediaUrl(): string + { + return $this->kirby()->url('media') . '/site'; + } + + /** + * Gets the last modification date of all pages + * in the content folder. + * + * @param string|null $format + * @param string|null $handler + * @return int|string + */ + public function modified(?string $format = null, ?string $handler = null) + { + return Dir::modified( + $this->root(), + $format, + $handler ?? $this->kirby()->option('date.handler', 'date') + ); + } + + /** + * Returns the current page if `$path` + * is not specified. Otherwise it will try + * to find a page by the given path. + * + * If no current page is set with the page + * prop, the home page will be returned if + * it can be found. (see `Site::homePage()`) + * + * @param string|null $path omit for current page, + * otherwise e.g. `notes/across-the-ocean` + * @return \Kirby\Cms\Page|null + */ + public function page(?string $path = null) + { + if ($path !== null) { + return $this->find($path); + } + + if (is_a($this->page, 'Kirby\Cms\Page') === true) { + return $this->page; + } + + try { + return $this->page = $this->homePage(); + } catch (LogicException $e) { + return $this->page = null; + } + } + + /** + * Alias for `Site::children()` + * + * @return \Kirby\Cms\Pages + */ + public function pages() + { + return $this->children(); + } + + /** + * Returns the panel info object + * + * @return \Kirby\Panel\Site + */ + public function panel() + { + return new Panel($this); + } + + /** + * Returns the permissions object for this site + * + * @return \Kirby\Cms\SitePermissions + */ + public function permissions() + { + return new SitePermissions($this); + } + + /** + * Preview Url + * + * @internal + * @return string|null + */ + public function previewUrl(): ?string + { + $preview = $this->blueprint()->preview(); + + if ($preview === false) { + return null; + } + + if ($preview === true) { + $url = $this->url(); + } else { + $url = $preview; + } + + return $url; + } + + /** + * Returns the absolute path to the content directory + * + * @return string + */ + public function root(): string + { + return $this->root ??= $this->kirby()->root('content'); + } + + /** + * Returns the SiteRules class instance + * which is being used in various methods + * to check for valid actions and input. + * + * @return \Kirby\Cms\SiteRules + */ + protected function rules() + { + return new SiteRules(); + } + + /** + * Search all pages in the site + * + * @param string|null $query + * @param array $params + * @return \Kirby\Cms\Pages + */ + public function search(?string $query = null, $params = []) + { + return $this->index()->search($query, $params); + } + + /** + * Sets the Blueprint object + * + * @param array|null $blueprint + * @return $this + */ + protected function setBlueprint(?array $blueprint = null) + { + if ($blueprint !== null) { + $blueprint['model'] = $this; + $this->blueprint = new SiteBlueprint($blueprint); + } + + return $this; + } + + /** + * Sets the id of the error page, which + * is used in the errorPage method + * to get the default error page if nothing + * else is set. + * + * @param string $id + * @return $this + */ + protected function setErrorPageId(string $id = 'error') + { + $this->errorPageId = $id; + return $this; + } + + /** + * Sets the id of the home page, which + * is used in the homePage method + * to get the default home page if nothing + * else is set. + * + * @param string $id + * @return $this + */ + protected function setHomePageId(string $id = 'home') + { + $this->homePageId = $id; + return $this; + } + + /** + * Sets the current page object + * + * @internal + * @param \Kirby\Cms\Page|null $page + * @return $this + */ + public function setPage(?Page $page = null) + { + $this->page = $page; + return $this; + } + + /** + * Sets the Url + * + * @param string|null $url + * @return $this + */ + protected function setUrl(?string $url = null) + { + $this->url = $url; + return $this; + } + + /** + * Converts the most important site + * properties to an array + * + * @return array + */ + public function toArray(): array + { + return [ + 'children' => $this->children()->keys(), + 'content' => $this->content()->toArray(), + 'errorPage' => $this->errorPage() ? $this->errorPage()->id() : false, + 'files' => $this->files()->keys(), + 'homePage' => $this->homePage() ? $this->homePage()->id() : false, + 'page' => $this->page() ? $this->page()->id() : false, + 'title' => $this->title()->value(), + 'url' => $this->url(), + ]; + } + + /** + * Returns the Url + * + * @param string|null $language + * @return string + */ + public function url(?string $language = null): string + { + if ($language !== null || $this->kirby()->multilang() === true) { + return $this->urlForLanguage($language); + } + + return $this->url ?? $this->kirby()->url(); + } + + /** + * Returns the translated url + * + * @internal + * @param string|null $languageCode + * @param array|null $options + * @return string + */ + public function urlForLanguage(?string $languageCode = null, ?array $options = null): string + { + if ($language = $this->kirby()->language($languageCode)) { + return $language->url(); + } + + return $this->kirby()->url(); + } + + /** + * Sets the current page by + * id or page object and + * returns the current page + * + * @internal + * @param string|\Kirby\Cms\Page $page + * @param string|null $languageCode + * @return \Kirby\Cms\Page + */ + public function visit($page, ?string $languageCode = null) + { + if ($languageCode !== null) { + $this->kirby()->setCurrentTranslation($languageCode); + $this->kirby()->setCurrentLanguage($languageCode); + } + + // convert ids to a Page object + if (is_string($page)) { + $page = $this->find($page); + } + + // handle invalid pages + if (is_a($page, 'Kirby\Cms\Page') === false) { + throw new InvalidArgumentException('Invalid page object'); + } + + // set the current active page + $this->setPage($page); + + // return the page + return $page; + } + + /** + * Checks if any content of the site has been + * modified after the given unix timestamp + * This is mainly used to auto-update the cache + * + * @param mixed $time + * @return bool + */ + public function wasModifiedAfter($time): bool + { + return Dir::wasModifiedAfter($this->root(), $time); + } + + + /** + * Deprecated! + */ + + /** + * Returns the full path without leading slash + * + * @todo Remove in 3.8.0 + * + * @internal + * @return string + * @codeCoverageIgnore + */ + public function panelPath(): string + { + Helpers::deprecated('Cms\Site::panelPath() has been deprecated and will be removed in Kirby 3.8.0. Use $site->panel()->path() instead.'); + return $this->panel()->path(); + } + + /** + * Returns the url to the editing view + * in the panel + * + * @todo Remove in 3.8.0 + * + * @internal + * @param bool $relative + * @return string + * @codeCoverageIgnore + */ + public function panelUrl(bool $relative = false): string + { + Helpers::deprecated('Cms\Site::panelUrl() has been deprecated and will be removed in Kirby 3.8.0. Use $site->panel()->url() instead.'); + return $this->panel()->url($relative); + } } diff --git a/kirby/src/Cms/SiteActions.php b/kirby/src/Cms/SiteActions.php index 5805d9c..dd1ceb9 100755 --- a/kirby/src/Cms/SiteActions.php +++ b/kirby/src/Cms/SiteActions.php @@ -15,87 +15,87 @@ use Closure; */ trait SiteActions { - /** - * Commits a site action, by following these steps - * - * 1. checks the action rules - * 2. sends the before hook - * 3. commits the store action - * 4. sends the after hook - * 5. returns the result - * - * @param string $action - * @param mixed ...$arguments - * @param Closure $callback - * @return mixed - */ - protected function commit(string $action, array $arguments, Closure $callback) - { - $old = $this->hardcopy(); - $kirby = $this->kirby(); - $argumentValues = array_values($arguments); + /** + * Commits a site action, by following these steps + * + * 1. checks the action rules + * 2. sends the before hook + * 3. commits the store action + * 4. sends the after hook + * 5. returns the result + * + * @param string $action + * @param mixed ...$arguments + * @param Closure $callback + * @return mixed + */ + protected function commit(string $action, array $arguments, Closure $callback) + { + $old = $this->hardcopy(); + $kirby = $this->kirby(); + $argumentValues = array_values($arguments); - $this->rules()->$action(...$argumentValues); - $kirby->trigger('site.' . $action . ':before', $arguments); + $this->rules()->$action(...$argumentValues); + $kirby->trigger('site.' . $action . ':before', $arguments); - $result = $callback(...$argumentValues); + $result = $callback(...$argumentValues); - $kirby->trigger('site.' . $action . ':after', ['newSite' => $result, 'oldSite' => $old]); + $kirby->trigger('site.' . $action . ':after', ['newSite' => $result, 'oldSite' => $old]); - $kirby->cache('pages')->flush(); - return $result; - } + $kirby->cache('pages')->flush(); + return $result; + } - /** - * Change the site title - * - * @param string $title - * @param string|null $languageCode - * @return static - */ - public function changeTitle(string $title, string $languageCode = null) - { - $site = $this; - $title = trim($title); - $arguments = compact('site', 'title', 'languageCode'); + /** + * Change the site title + * + * @param string $title + * @param string|null $languageCode + * @return static + */ + public function changeTitle(string $title, string $languageCode = null) + { + $site = $this; + $title = trim($title); + $arguments = compact('site', 'title', 'languageCode'); - return $this->commit('changeTitle', $arguments, function ($site, $title, $languageCode) { - return $site->save(['title' => $title], $languageCode); - }); - } + return $this->commit('changeTitle', $arguments, function ($site, $title, $languageCode) { + return $site->save(['title' => $title], $languageCode); + }); + } - /** - * Creates a main page - * - * @param array $props - * @return \Kirby\Cms\Page - */ - public function createChild(array $props) - { - $props = array_merge($props, [ - 'url' => null, - 'num' => null, - 'parent' => null, - 'site' => $this, - ]); + /** + * Creates a main page + * + * @param array $props + * @return \Kirby\Cms\Page + */ + public function createChild(array $props) + { + $props = array_merge($props, [ + 'url' => null, + 'num' => null, + 'parent' => null, + 'site' => $this, + ]); - return Page::create($props); - } + return Page::create($props); + } - /** - * Clean internal caches - * - * @return $this - */ - public function purge() - { - $this->blueprint = null; - $this->children = null; - $this->content = null; - $this->files = null; - $this->inventory = null; - $this->translations = null; + /** + * Clean internal caches + * + * @return $this + */ + public function purge() + { + $this->blueprint = null; + $this->children = null; + $this->content = null; + $this->files = null; + $this->inventory = null; + $this->translations = null; - return $this; - } + return $this; + } } diff --git a/kirby/src/Cms/SiteBlueprint.php b/kirby/src/Cms/SiteBlueprint.php index d320bb7..ce38ab9 100755 --- a/kirby/src/Cms/SiteBlueprint.php +++ b/kirby/src/Cms/SiteBlueprint.php @@ -14,47 +14,47 @@ namespace Kirby\Cms; */ class SiteBlueprint extends Blueprint { - /** - * Creates a new page blueprint object - * with the given props - * - * @param array $props - */ - public function __construct(array $props) - { - parent::__construct($props); + /** + * Creates a new page blueprint object + * with the given props + * + * @param array $props + */ + public function __construct(array $props) + { + parent::__construct($props); - // normalize all available page options - $this->props['options'] = $this->normalizeOptions( - $this->props['options'] ?? true, - // defaults - [ - 'changeTitle' => null, - 'update' => null, - ], - // aliases - [ - 'title' => 'changeTitle', - ] - ); - } + // normalize all available page options + $this->props['options'] = $this->normalizeOptions( + $this->props['options'] ?? true, + // defaults + [ + 'changeTitle' => null, + 'update' => null, + ], + // aliases + [ + 'title' => 'changeTitle', + ] + ); + } - /** - * Returns the preview settings - * The preview setting controls the "Open" - * button in the panel and redirects it to a - * different URL if necessary. - * - * @return string|bool - */ - public function preview() - { - $preview = $this->props['options']['preview'] ?? true; + /** + * Returns the preview settings + * The preview setting controls the "Open" + * button in the panel and redirects it to a + * different URL if necessary. + * + * @return string|bool + */ + public function preview() + { + $preview = $this->props['options']['preview'] ?? true; - if (is_string($preview) === true) { - return $this->model->toString($preview); - } + if (is_string($preview) === true) { + return $this->model->toString($preview); + } - return $preview; - } + return $preview; + } } diff --git a/kirby/src/Cms/SitePermissions.php b/kirby/src/Cms/SitePermissions.php index 5ced409..b6ce350 100755 --- a/kirby/src/Cms/SitePermissions.php +++ b/kirby/src/Cms/SitePermissions.php @@ -13,5 +13,5 @@ namespace Kirby\Cms; */ class SitePermissions extends ModelPermissions { - protected $category = 'site'; + protected $category = 'site'; } diff --git a/kirby/src/Cms/SiteRules.php b/kirby/src/Cms/SiteRules.php index 64b64f4..07db1b9 100755 --- a/kirby/src/Cms/SiteRules.php +++ b/kirby/src/Cms/SiteRules.php @@ -17,42 +17,42 @@ use Kirby\Toolkit\Str; */ class SiteRules { - /** - * Validates if the site title can be changed - * - * @param \Kirby\Cms\Site $site - * @param string $title - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException If the title is empty - * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the title - */ - public static function changeTitle(Site $site, string $title): bool - { - if ($site->permissions()->changeTitle() !== true) { - throw new PermissionException(['key' => 'site.changeTitle.permission']); - } + /** + * Validates if the site title can be changed + * + * @param \Kirby\Cms\Site $site + * @param string $title + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException If the title is empty + * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the title + */ + public static function changeTitle(Site $site, string $title): bool + { + if ($site->permissions()->changeTitle() !== true) { + throw new PermissionException(['key' => 'site.changeTitle.permission']); + } - if (Str::length($title) === 0) { - throw new InvalidArgumentException(['key' => 'site.changeTitle.empty']); - } + if (Str::length($title) === 0) { + throw new InvalidArgumentException(['key' => 'site.changeTitle.empty']); + } - return true; - } + return true; + } - /** - * Validates if the site can be updated - * - * @param \Kirby\Cms\Site $site - * @param array $content - * @return bool - * @throws \Kirby\Exception\PermissionException If the user is not allowed to update the site - */ - public static function update(Site $site, array $content = []): bool - { - if ($site->permissions()->update() !== true) { - throw new PermissionException(['key' => 'site.update.permission']); - } + /** + * Validates if the site can be updated + * + * @param \Kirby\Cms\Site $site + * @param array $content + * @return bool + * @throws \Kirby\Exception\PermissionException If the user is not allowed to update the site + */ + public static function update(Site $site, array $content = []): bool + { + if ($site->permissions()->update() !== true) { + throw new PermissionException(['key' => 'site.update.permission']); + } - return true; - } + return true; + } } diff --git a/kirby/src/Cms/Structure.php b/kirby/src/Cms/Structure.php index 886fff0..d86e611 100755 --- a/kirby/src/Cms/Structure.php +++ b/kirby/src/Cms/Structure.php @@ -20,45 +20,47 @@ use Kirby\Exception\InvalidArgumentException; */ class Structure extends Collection { - /** - * Creates a new Collection with the given objects - * - * @param array $objects Kirby\Cms\StructureObject` objects or props arrays - * @param object|null $parent - */ - public function __construct($objects = [], $parent = null) - { - $this->parent = $parent; - $this->set($objects); - } + /** + * Creates a new Collection with the given objects + * + * @param array $objects Kirby\Cms\StructureObject` objects or props arrays + * @param object|null $parent + */ + public function __construct($objects = [], $parent = null) + { + $this->parent = $parent; + $this->set($objects); + } - /** - * The internal setter for collection items. - * This makes sure that nothing unexpected ends - * up in the collection. You can pass arrays or - * StructureObjects - * - * @param string $id - * @param array|StructureObject $props - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function __set(string $id, $props) - { - if (is_a($props, 'Kirby\Cms\StructureObject') === true) { - $object = $props; - } else { - if (is_array($props) === false) { - throw new InvalidArgumentException('Invalid structure data'); - } + /** + * The internal setter for collection items. + * This makes sure that nothing unexpected ends + * up in the collection. You can pass arrays or + * StructureObjects + * + * @param string $id + * @param array|StructureObject $props + * @return void + * + * @throws \Kirby\Exception\InvalidArgumentException + */ + public function __set(string $id, $props): void + { + if (is_a($props, 'Kirby\Cms\StructureObject') === true) { + $object = $props; + } else { + if (is_array($props) === false) { + throw new InvalidArgumentException('Invalid structure data'); + } - $object = new StructureObject([ - 'content' => $props, - 'id' => $props['id'] ?? $id, - 'parent' => $this->parent, - 'structure' => $this - ]); - } + $object = new StructureObject([ + 'content' => $props, + 'id' => $props['id'] ?? $id, + 'parent' => $this->parent, + 'structure' => $this + ]); + } - return parent::__set($object->id(), $object); - } + parent::__set($object->id(), $object); + } } diff --git a/kirby/src/Cms/StructureObject.php b/kirby/src/Cms/StructureObject.php index 877c798..2b0bddd 100755 --- a/kirby/src/Cms/StructureObject.php +++ b/kirby/src/Cms/StructureObject.php @@ -20,190 +20,190 @@ namespace Kirby\Cms; */ class StructureObject extends Model { - use HasSiblings; + use HasSiblings; - /** - * The content - * - * @var Content - */ - protected $content; + /** + * The content + * + * @var Content + */ + protected $content; - /** - * @var string - */ - protected $id; + /** + * @var string + */ + protected $id; - /** - * @var \Kirby\Cms\Site|\Kirby\Cms\Page|\Kirby\Cms\File|\Kirby\Cms\User|null - */ - protected $parent; + /** + * @var \Kirby\Cms\Site|\Kirby\Cms\Page|\Kirby\Cms\File|\Kirby\Cms\User|null + */ + protected $parent; - /** - * The parent Structure collection - * - * @var Structure - */ - protected $structure; + /** + * The parent Structure collection + * + * @var Structure + */ + protected $structure; - /** - * Modified getter to also return fields - * from the object's content - * - * @param string $method - * @param array $arguments - * @return mixed - */ - public function __call(string $method, array $arguments = []) - { - // public property access - if (isset($this->$method) === true) { - return $this->$method; - } + /** + * Modified getter to also return fields + * from the object's content + * + * @param string $method + * @param array $arguments + * @return mixed + */ + public function __call(string $method, array $arguments = []) + { + // public property access + if (isset($this->$method) === true) { + return $this->$method; + } - return $this->content()->get($method); - } + return $this->content()->get($method); + } - /** - * Creates a new StructureObject with the given props - * - * @param array $props - */ - public function __construct(array $props) - { - $this->setProperties($props); - } + /** + * Creates a new StructureObject with the given props + * + * @param array $props + */ + public function __construct(array $props) + { + $this->setProperties($props); + } - /** - * Returns the content - * - * @return \Kirby\Cms\Content - */ - public function content() - { - if (is_a($this->content, 'Kirby\Cms\Content') === true) { - return $this->content; - } + /** + * Returns the content + * + * @return \Kirby\Cms\Content + */ + public function content() + { + if (is_a($this->content, 'Kirby\Cms\Content') === true) { + return $this->content; + } - if (is_array($this->content) !== true) { - $this->content = []; - } + if (is_array($this->content) !== true) { + $this->content = []; + } - return $this->content = new Content($this->content, $this->parent()); - } + return $this->content = new Content($this->content, $this->parent()); + } - /** - * Returns the required id - * - * @return string - */ - public function id(): string - { - return $this->id; - } + /** + * Returns the required id + * + * @return string + */ + public function id(): string + { + return $this->id; + } - /** - * Compares the current object with the given structure object - * - * @param mixed $structure - * @return bool - */ - public function is($structure): bool - { - if (is_a($structure, 'Kirby\Cms\StructureObject') === false) { - return false; - } + /** + * Compares the current object with the given structure object + * + * @param mixed $structure + * @return bool + */ + public function is($structure): bool + { + if (is_a($structure, 'Kirby\Cms\StructureObject') === false) { + return false; + } - return $this === $structure; - } + return $this === $structure; + } - /** - * Returns the parent Model object - * - * @return \Kirby\Cms\Model - */ - public function parent() - { - return $this->parent; - } + /** + * Returns the parent Model object + * + * @return \Kirby\Cms\Model + */ + public function parent() + { + return $this->parent; + } - /** - * Sets the Content object with the given parent - * - * @param array|null $content - * @return $this - */ - protected function setContent(array $content = null) - { - $this->content = $content; - return $this; - } + /** + * Sets the Content object with the given parent + * + * @param array|null $content + * @return $this + */ + protected function setContent(array $content = null) + { + $this->content = $content; + return $this; + } - /** - * Sets the id of the object. - * The id is required. The structure - * class will use the index, if no id is - * specified. - * - * @param string $id - * @return $this - */ - protected function setId(string $id) - { - $this->id = $id; - return $this; - } + /** + * Sets the id of the object. + * The id is required. The structure + * class will use the index, if no id is + * specified. + * + * @param string $id + * @return $this + */ + protected function setId(string $id) + { + $this->id = $id; + return $this; + } - /** - * Sets the parent Model - * - * @return $this - * @param \Kirby\Cms\Site|\Kirby\Cms\Page|\Kirby\Cms\File|\Kirby\Cms\User|null $parent - */ - protected function setParent(Model $parent = null) - { - $this->parent = $parent; - return $this; - } + /** + * Sets the parent Model + * + * @return $this + * @param \Kirby\Cms\Site|\Kirby\Cms\Page|\Kirby\Cms\File|\Kirby\Cms\User|null $parent + */ + protected function setParent(Model $parent = null) + { + $this->parent = $parent; + return $this; + } - /** - * Sets the parent Structure collection - * - * @param \Kirby\Cms\Structure|null $structure - * @return $this - */ - protected function setStructure(Structure $structure = null) - { - $this->structure = $structure; - return $this; - } + /** + * Sets the parent Structure collection + * + * @param \Kirby\Cms\Structure|null $structure + * @return $this + */ + protected function setStructure(Structure $structure = null) + { + $this->structure = $structure; + return $this; + } - /** - * Returns the parent Structure collection as siblings - * - * @return \Kirby\Cms\Structure - */ - protected function siblingsCollection() - { - return $this->structure; - } + /** + * Returns the parent Structure collection as siblings + * + * @return \Kirby\Cms\Structure + */ + protected function siblingsCollection() + { + return $this->structure; + } - /** - * Converts all fields in the object to a - * plain associative array. The id is - * injected into the array afterwards - * to make sure it's always present and - * not overloaded in the content. - * - * @return array - */ - public function toArray(): array - { - $array = $this->content()->toArray(); - $array['id'] = $this->id(); + /** + * Converts all fields in the object to a + * plain associative array. The id is + * injected into the array afterwards + * to make sure it's always present and + * not overloaded in the content. + * + * @return array + */ + public function toArray(): array + { + $array = $this->content()->toArray(); + $array['id'] = $this->id(); - ksort($array); + ksort($array); - return $array; - } + return $array; + } } diff --git a/kirby/src/Cms/System.php b/kirby/src/Cms/System.php index f585aad..bf19418 100755 --- a/kirby/src/Cms/System.php +++ b/kirby/src/Cms/System.php @@ -30,614 +30,614 @@ use Throwable; */ class System { - /** - * @var \Kirby\Cms\App - */ - protected $app; - - /** - * @param \Kirby\Cms\App $app - */ - public function __construct(App $app) - { - $this->app = $app; - - // try to create all folders that could be missing - $this->init(); - } - - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return $this->toArray(); - } - - /** - * Check for a writable accounts folder - * - * @return bool - */ - public function accounts(): bool - { - return is_writable($this->app->root('accounts')); - } - - /** - * Check for a writable content folder - * - * @return bool - */ - public function content(): bool - { - return is_writable($this->app->root('content')); - } - - /** - * Check for an existing curl extension - * - * @return bool - */ - public function curl(): bool - { - return extension_loaded('curl'); - } - - /** - * Returns the URL to the file within a system folder - * if the file is located in the document - * root. Otherwise it will return null. - * - * @param string $folder 'git', 'content', 'site', 'kirby' - * @return string|null - */ - public function exposedFileUrl(string $folder): ?string - { - if (!$url = $this->folderUrl($folder)) { - return null; - } - - switch ($folder) { - case 'content': - return $url . '/' . basename($this->app->site()->contentFile()); - case 'git': - return $url . '/config'; - case 'kirby': - return $url . '/composer.json'; - case 'site': - $root = $this->app->root('site'); - $files = glob($root . '/blueprints/*.yml'); - - if (empty($files) === true) { - $files = glob($root . '/templates/*.*'); - } - - if (empty($files) === true) { - $files = glob($root . '/snippets/*.*'); - } - - if (empty($files) === true || empty($files[0]) === true) { - return $url; - } - - $file = $files[0]; - $file = basename(dirname($file)) . '/' . basename($file); - - return $url . '/' . $file; - default: - return null; - } - } - - /** - * Returns the URL to a system folder - * if the folder is located in the document - * root. Otherwise it will return null. - * - * @param string $folder 'git', 'content', 'site', 'kirby' - * @return string|null - */ - public function folderUrl(string $folder): ?string - { - $index = $this->app->root('index'); - - if ($folder === 'git') { - $root = $index . '/.git'; - } else { - $root = $this->app->root($folder); - } - - if ($root === null || is_dir($root) === false || is_dir($index) === false) { - return null; - } - - $root = realpath($root); - $index = realpath($index); - - // windows - $root = str_replace('\\', '/', $root); - $index = str_replace('\\', '/', $index); - - // the folder is not within the document root? - if (Str::startsWith($root, $index) === false) { - return null; - } - - // get the path after the document root - $path = trim(Str::after($root, $index), '/'); - - // build the absolute URL to the folder - return Url::to($path); - } - - /** - * Returns the app's human-readable - * index URL without scheme - * - * @return string - */ - public function indexUrl(): string - { - return $this->app->url('index', true)->setScheme(null)->setSlash(false)->toString(); - } - - /** - * Create the most important folders - * if they don't exist yet - * - * @return void - * @throws \Kirby\Exception\PermissionException - */ - public function init() - { - // init /site/accounts - try { - Dir::make($this->app->root('accounts')); - } catch (Throwable $e) { - throw new PermissionException('The accounts directory could not be created'); - } - - // init /site/sessions - try { - Dir::make($this->app->root('sessions')); - } catch (Throwable $e) { - throw new PermissionException('The sessions directory could not be created'); - } - - // init /content - try { - Dir::make($this->app->root('content')); - } catch (Throwable $e) { - throw new PermissionException('The content directory could not be created'); - } - - // init /media - try { - Dir::make($this->app->root('media')); - } catch (Throwable $e) { - throw new PermissionException('The media directory could not be created'); - } - } - - /** - * Check if the panel is installable. - * On a public server the panel.install - * option must be explicitly set to true - * to get the installer up and running. - * - * @return bool - */ - public function isInstallable(): bool - { - return $this->isLocal() === true || $this->app->option('panel.install', false) === true; - } - - /** - * Check if Kirby is already installed - * - * @return bool - */ - public function isInstalled(): bool - { - return $this->app->users()->count() > 0; - } - - /** - * Check if this is a local installation - * - * @return bool - */ - public function isLocal(): bool - { - return $this->app->environment()->isLocal(); - } - - /** - * Check if all tests pass - * - * @return bool - */ - public function isOk(): bool - { - return in_array(false, array_values($this->status()), true) === false; - } - - /** - * Loads the license file and returns - * the license information if available - * - * @return string|bool License key or `false` if the current user has - * permissions for access.settings, otherwise just a - * boolean that tells whether a valid license is active - */ - public function license() - { - try { - $license = Json::read($this->app->root('license')); - } catch (Throwable $e) { - return false; - } - - // check for all required fields for the validation - if (isset( - $license['license'], - $license['order'], - $license['date'], - $license['email'], - $license['domain'], - $license['signature'] - ) !== true) { - return false; - } - - // build the license verification data - $data = [ - 'license' => $license['license'], - 'order' => $license['order'], - 'email' => hash('sha256', $license['email'] . 'kwAHMLyLPBnHEskzH9pPbJsBxQhKXZnX'), - 'domain' => $license['domain'], - 'date' => $license['date'] - ]; - - - // get the public key - $pubKey = F::read($this->app->root('kirby') . '/kirby.pub'); - - // verify the license signature - if (openssl_verify(json_encode($data), hex2bin($license['signature']), $pubKey, 'RSA-SHA256') !== 1) { - return false; - } - - // verify the URL - if ($this->licenseUrl() !== $this->licenseUrl($license['domain'])) { - return false; - } - - // only return the actual license key if the - // current user has appropriate permissions - $user = $this->app->user(); - if ($user && $user->isAdmin() === true) { - return $license['license']; - } else { - return true; - } - } - - /** - * Normalizes the app's index URL for - * licensing purposes - * - * @param string|null $url Input URL, by default the app's index URL - * @return string Normalized URL - */ - protected function licenseUrl(string $url = null): string - { - if ($url === null) { - $url = $this->indexUrl(); - } - - // remove common "testing" subdomains as well as www. - // to ensure that installations of the same site have - // the same license URL; only for installations at /, - // subdirectory installations are difficult to normalize - if (Str::contains($url, '/') === false) { - if (Str::startsWith($url, 'www.')) { - return substr($url, 4); - } - - if (Str::startsWith($url, 'dev.')) { - return substr($url, 4); - } - - if (Str::startsWith($url, 'test.')) { - return substr($url, 5); - } - - if (Str::startsWith($url, 'staging.')) { - return substr($url, 8); - } - } - - return $url; - } - - /** - * Returns the configured UI modes for the login form - * with their respective options - * - * @return array - * - * @throws \Kirby\Exception\InvalidArgumentException If the configuration is invalid - * (only in debug mode) - */ - public function loginMethods(): array - { - $default = ['password' => []]; - $methods = A::wrap($this->app->option('auth.methods', $default)); - - // normalize the syntax variants - $normalized = []; - $uses2fa = false; - foreach ($methods as $key => $value) { - if (is_int($key) === true) { - // ['password'] - $normalized[$value] = []; - } elseif ($value === true) { - // ['password' => true] - $normalized[$key] = []; - } else { - // ['password' => [...]] - $normalized[$key] = $value; - - if (isset($value['2fa']) === true && $value['2fa'] === true) { - $uses2fa = true; - } - } - } - - // 2FA must not be circumvented by code-based modes - foreach (['code', 'password-reset'] as $method) { - if ($uses2fa === true && isset($normalized[$method]) === true) { - unset($normalized[$method]); - - if ($this->app->option('debug') === true) { - $message = 'The "' . $method . '" login method cannot be enabled when 2FA is required'; - throw new InvalidArgumentException($message); - } - } - } - - // only one code-based mode can be active at once - if ( - isset($normalized['code']) === true && - isset($normalized['password-reset']) === true - ) { - unset($normalized['code']); - - if ($this->app->option('debug') === true) { - $message = 'The "code" and "password-reset" login methods cannot be enabled together'; - throw new InvalidArgumentException($message); - } - } - - return $normalized; - } - - /** - * Check for an existing mbstring extension - * - * @return bool - */ - public function mbString(): bool - { - return extension_loaded('mbstring'); - } - - /** - * Check for a writable media folder - * - * @return bool - */ - public function media(): bool - { - return is_writable($this->app->root('media')); - } - - /** - * Check for a valid PHP version - * - * @return bool - */ - public function php(): bool - { - return - version_compare(PHP_VERSION, '7.4.0', '>=') === true && - version_compare(PHP_VERSION, '8.2.0', '<') === true; - } - - /** - * Returns a sorted collection of all - * installed plugins - * - * @return \Kirby\Cms\Collection - */ - public function plugins() - { - return (new Collection(App::instance()->plugins()))->sortBy('name', 'asc'); - } - - /** - * Validates the license key - * and adds it to the .license file in the config - * folder if possible. - * - * @param string|null $license - * @param string|null $email - * @return bool - * @throws \Kirby\Exception\Exception - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function register(string $license = null, string $email = null): bool - { - if (Str::startsWith($license, 'K3-PRO-') === false) { - throw new InvalidArgumentException([ - 'key' => 'license.format' - ]); - } - - if (V::email($email) === false) { - throw new InvalidArgumentException([ - 'key' => 'license.email' - ]); - } - - // @codeCoverageIgnoreStart - $response = Remote::get('https://hub.getkirby.com/register', [ - 'data' => [ - 'license' => $license, - 'email' => Str::lower(trim($email)), - 'domain' => $this->indexUrl() - ] - ]); - - if ($response->code() !== 200) { - throw new Exception($response->content()); - } - - // decode the response - $json = Json::decode($response->content()); - - // replace the email with the plaintext version - $json['email'] = $email; - - // where to store the license file - $file = $this->app->root('license'); - - // save the license information - Json::write($file, $json); - - if ($this->license() === false) { - throw new InvalidArgumentException([ - 'key' => 'license.verification' - ]); - } - // @codeCoverageIgnoreEnd - - return true; - } - - /** - * Check for a valid server environment - * - * @return bool - */ - public function server(): bool - { - return $this->serverSoftware() !== null; - } - - /** - * Returns the detected server software - * - * @return string|null - */ - public function serverSoftware(): ?string - { - if ($servers = $this->app->option('servers')) { - $servers = A::wrap($servers); - } else { - $servers = [ - 'apache', - 'caddy', - 'litespeed', - 'nginx', - 'php' - ]; - } - - $software = $this->app->environment()->get('SERVER_SOFTWARE', ''); - - preg_match('!(' . implode('|', $servers) . ')!i', $software, $matches); - - return $matches[0] ?? null; - } - - /** - * Check for a writable sessions folder - * - * @return bool - */ - public function sessions(): bool - { - return is_writable($this->app->root('sessions')); - } - - /** - * Get an status array of all checks - * - * @return array - */ - public function status(): array - { - return [ - 'accounts' => $this->accounts(), - 'content' => $this->content(), - 'curl' => $this->curl(), - 'sessions' => $this->sessions(), - 'mbstring' => $this->mbstring(), - 'media' => $this->media(), - 'php' => $this->php(), - 'server' => $this->server(), - ]; - } - - /** - * Returns the site's title as defined in the - * content file or `site.yml` blueprint - * @since 3.6.0 - * - * @return string - */ - public function title(): string - { - $site = $this->app->site(); - - if ($site->title()->isNotEmpty()) { - return $site->title()->value(); - } - - return $site->blueprint()->title(); - } - - /** - * @return array - */ - public function toArray(): array - { - return $this->status(); - } - - /** - * Upgrade to the new folder separator - * - * @param string $root - * @return void - */ - public static function upgradeContent(string $root) - { - $index = Dir::read($root); - - foreach ($index as $dir) { - $oldRoot = $root . '/' . $dir; - $newRoot = preg_replace('!\/([0-9]+)\-!', '/$1_', $oldRoot); - - if (is_dir($oldRoot) === true) { - Dir::move($oldRoot, $newRoot); - static::upgradeContent($newRoot); - } - } - } + /** + * @var \Kirby\Cms\App + */ + protected $app; + + /** + * @param \Kirby\Cms\App $app + */ + public function __construct(App $app) + { + $this->app = $app; + + // try to create all folders that could be missing + $this->init(); + } + + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return $this->toArray(); + } + + /** + * Check for a writable accounts folder + * + * @return bool + */ + public function accounts(): bool + { + return is_writable($this->app->root('accounts')); + } + + /** + * Check for a writable content folder + * + * @return bool + */ + public function content(): bool + { + return is_writable($this->app->root('content')); + } + + /** + * Check for an existing curl extension + * + * @return bool + */ + public function curl(): bool + { + return extension_loaded('curl'); + } + + /** + * Returns the URL to the file within a system folder + * if the file is located in the document + * root. Otherwise it will return null. + * + * @param string $folder 'git', 'content', 'site', 'kirby' + * @return string|null + */ + public function exposedFileUrl(string $folder): ?string + { + if (!$url = $this->folderUrl($folder)) { + return null; + } + + switch ($folder) { + case 'content': + return $url . '/' . basename($this->app->site()->contentFile()); + case 'git': + return $url . '/config'; + case 'kirby': + return $url . '/composer.json'; + case 'site': + $root = $this->app->root('site'); + $files = glob($root . '/blueprints/*.yml'); + + if (empty($files) === true) { + $files = glob($root . '/templates/*.*'); + } + + if (empty($files) === true) { + $files = glob($root . '/snippets/*.*'); + } + + if (empty($files) === true || empty($files[0]) === true) { + return $url; + } + + $file = $files[0]; + $file = basename(dirname($file)) . '/' . basename($file); + + return $url . '/' . $file; + default: + return null; + } + } + + /** + * Returns the URL to a system folder + * if the folder is located in the document + * root. Otherwise it will return null. + * + * @param string $folder 'git', 'content', 'site', 'kirby' + * @return string|null + */ + public function folderUrl(string $folder): ?string + { + $index = $this->app->root('index'); + + if ($folder === 'git') { + $root = $index . '/.git'; + } else { + $root = $this->app->root($folder); + } + + if ($root === null || is_dir($root) === false || is_dir($index) === false) { + return null; + } + + $root = realpath($root); + $index = realpath($index); + + // windows + $root = str_replace('\\', '/', $root); + $index = str_replace('\\', '/', $index); + + // the folder is not within the document root? + if (Str::startsWith($root, $index) === false) { + return null; + } + + // get the path after the document root + $path = trim(Str::after($root, $index), '/'); + + // build the absolute URL to the folder + return Url::to($path); + } + + /** + * Returns the app's human-readable + * index URL without scheme + * + * @return string + */ + public function indexUrl(): string + { + return $this->app->url('index', true)->setScheme(null)->setSlash(false)->toString(); + } + + /** + * Create the most important folders + * if they don't exist yet + * + * @return void + * @throws \Kirby\Exception\PermissionException + */ + public function init() + { + // init /site/accounts + try { + Dir::make($this->app->root('accounts')); + } catch (Throwable $e) { + throw new PermissionException('The accounts directory could not be created'); + } + + // init /site/sessions + try { + Dir::make($this->app->root('sessions')); + } catch (Throwable $e) { + throw new PermissionException('The sessions directory could not be created'); + } + + // init /content + try { + Dir::make($this->app->root('content')); + } catch (Throwable $e) { + throw new PermissionException('The content directory could not be created'); + } + + // init /media + try { + Dir::make($this->app->root('media')); + } catch (Throwable $e) { + throw new PermissionException('The media directory could not be created'); + } + } + + /** + * Check if the panel is installable. + * On a public server the panel.install + * option must be explicitly set to true + * to get the installer up and running. + * + * @return bool + */ + public function isInstallable(): bool + { + return $this->isLocal() === true || $this->app->option('panel.install', false) === true; + } + + /** + * Check if Kirby is already installed + * + * @return bool + */ + public function isInstalled(): bool + { + return $this->app->users()->count() > 0; + } + + /** + * Check if this is a local installation + * + * @return bool + */ + public function isLocal(): bool + { + return $this->app->environment()->isLocal(); + } + + /** + * Check if all tests pass + * + * @return bool + */ + public function isOk(): bool + { + return in_array(false, array_values($this->status()), true) === false; + } + + /** + * Loads the license file and returns + * the license information if available + * + * @return string|bool License key or `false` if the current user has + * permissions for access.settings, otherwise just a + * boolean that tells whether a valid license is active + */ + public function license() + { + try { + $license = Json::read($this->app->root('license')); + } catch (Throwable $e) { + return false; + } + + // check for all required fields for the validation + if (isset( + $license['license'], + $license['order'], + $license['date'], + $license['email'], + $license['domain'], + $license['signature'] + ) !== true) { + return false; + } + + // build the license verification data + $data = [ + 'license' => $license['license'], + 'order' => $license['order'], + 'email' => hash('sha256', $license['email'] . 'kwAHMLyLPBnHEskzH9pPbJsBxQhKXZnX'), + 'domain' => $license['domain'], + 'date' => $license['date'] + ]; + + + // get the public key + $pubKey = F::read($this->app->root('kirby') . '/kirby.pub'); + + // verify the license signature + if (openssl_verify(json_encode($data), hex2bin($license['signature']), $pubKey, 'RSA-SHA256') !== 1) { + return false; + } + + // verify the URL + if ($this->licenseUrl() !== $this->licenseUrl($license['domain'])) { + return false; + } + + // only return the actual license key if the + // current user has appropriate permissions + $user = $this->app->user(); + if ($user && $user->isAdmin() === true) { + return $license['license']; + } else { + return true; + } + } + + /** + * Normalizes the app's index URL for + * licensing purposes + * + * @param string|null $url Input URL, by default the app's index URL + * @return string Normalized URL + */ + protected function licenseUrl(string $url = null): string + { + if ($url === null) { + $url = $this->indexUrl(); + } + + // remove common "testing" subdomains as well as www. + // to ensure that installations of the same site have + // the same license URL; only for installations at /, + // subdirectory installations are difficult to normalize + if (Str::contains($url, '/') === false) { + if (Str::startsWith($url, 'www.')) { + return substr($url, 4); + } + + if (Str::startsWith($url, 'dev.')) { + return substr($url, 4); + } + + if (Str::startsWith($url, 'test.')) { + return substr($url, 5); + } + + if (Str::startsWith($url, 'staging.')) { + return substr($url, 8); + } + } + + return $url; + } + + /** + * Returns the configured UI modes for the login form + * with their respective options + * + * @return array + * + * @throws \Kirby\Exception\InvalidArgumentException If the configuration is invalid + * (only in debug mode) + */ + public function loginMethods(): array + { + $default = ['password' => []]; + $methods = A::wrap($this->app->option('auth.methods', $default)); + + // normalize the syntax variants + $normalized = []; + $uses2fa = false; + foreach ($methods as $key => $value) { + if (is_int($key) === true) { + // ['password'] + $normalized[$value] = []; + } elseif ($value === true) { + // ['password' => true] + $normalized[$key] = []; + } else { + // ['password' => [...]] + $normalized[$key] = $value; + + if (isset($value['2fa']) === true && $value['2fa'] === true) { + $uses2fa = true; + } + } + } + + // 2FA must not be circumvented by code-based modes + foreach (['code', 'password-reset'] as $method) { + if ($uses2fa === true && isset($normalized[$method]) === true) { + unset($normalized[$method]); + + if ($this->app->option('debug') === true) { + $message = 'The "' . $method . '" login method cannot be enabled when 2FA is required'; + throw new InvalidArgumentException($message); + } + } + } + + // only one code-based mode can be active at once + if ( + isset($normalized['code']) === true && + isset($normalized['password-reset']) === true + ) { + unset($normalized['code']); + + if ($this->app->option('debug') === true) { + $message = 'The "code" and "password-reset" login methods cannot be enabled together'; + throw new InvalidArgumentException($message); + } + } + + return $normalized; + } + + /** + * Check for an existing mbstring extension + * + * @return bool + */ + public function mbString(): bool + { + return extension_loaded('mbstring'); + } + + /** + * Check for a writable media folder + * + * @return bool + */ + public function media(): bool + { + return is_writable($this->app->root('media')); + } + + /** + * Check for a valid PHP version + * + * @return bool + */ + public function php(): bool + { + return + version_compare(PHP_VERSION, '7.4.0', '>=') === true && + version_compare(PHP_VERSION, '8.2.0', '<') === true; + } + + /** + * Returns a sorted collection of all + * installed plugins + * + * @return \Kirby\Cms\Collection + */ + public function plugins() + { + return (new Collection(App::instance()->plugins()))->sortBy('name', 'asc'); + } + + /** + * Validates the license key + * and adds it to the .license file in the config + * folder if possible. + * + * @param string|null $license + * @param string|null $email + * @return bool + * @throws \Kirby\Exception\Exception + * @throws \Kirby\Exception\InvalidArgumentException + */ + public function register(string $license = null, string $email = null): bool + { + if (Str::startsWith($license, 'K3-PRO-') === false) { + throw new InvalidArgumentException([ + 'key' => 'license.format' + ]); + } + + if (V::email($email) === false) { + throw new InvalidArgumentException([ + 'key' => 'license.email' + ]); + } + + // @codeCoverageIgnoreStart + $response = Remote::get('https://hub.getkirby.com/register', [ + 'data' => [ + 'license' => $license, + 'email' => Str::lower(trim($email)), + 'domain' => $this->indexUrl() + ] + ]); + + if ($response->code() !== 200) { + throw new Exception($response->content()); + } + + // decode the response + $json = Json::decode($response->content()); + + // replace the email with the plaintext version + $json['email'] = $email; + + // where to store the license file + $file = $this->app->root('license'); + + // save the license information + Json::write($file, $json); + + if ($this->license() === false) { + throw new InvalidArgumentException([ + 'key' => 'license.verification' + ]); + } + // @codeCoverageIgnoreEnd + + return true; + } + + /** + * Check for a valid server environment + * + * @return bool + */ + public function server(): bool + { + return $this->serverSoftware() !== null; + } + + /** + * Returns the detected server software + * + * @return string|null + */ + public function serverSoftware(): ?string + { + if ($servers = $this->app->option('servers')) { + $servers = A::wrap($servers); + } else { + $servers = [ + 'apache', + 'caddy', + 'litespeed', + 'nginx', + 'php' + ]; + } + + $software = $this->app->environment()->get('SERVER_SOFTWARE', ''); + + preg_match('!(' . implode('|', $servers) . ')!i', $software, $matches); + + return $matches[0] ?? null; + } + + /** + * Check for a writable sessions folder + * + * @return bool + */ + public function sessions(): bool + { + return is_writable($this->app->root('sessions')); + } + + /** + * Get an status array of all checks + * + * @return array + */ + public function status(): array + { + return [ + 'accounts' => $this->accounts(), + 'content' => $this->content(), + 'curl' => $this->curl(), + 'sessions' => $this->sessions(), + 'mbstring' => $this->mbstring(), + 'media' => $this->media(), + 'php' => $this->php(), + 'server' => $this->server(), + ]; + } + + /** + * Returns the site's title as defined in the + * content file or `site.yml` blueprint + * @since 3.6.0 + * + * @return string + */ + public function title(): string + { + $site = $this->app->site(); + + if ($site->title()->isNotEmpty()) { + return $site->title()->value(); + } + + return $site->blueprint()->title(); + } + + /** + * @return array + */ + public function toArray(): array + { + return $this->status(); + } + + /** + * Upgrade to the new folder separator + * + * @param string $root + * @return void + */ + public static function upgradeContent(string $root) + { + $index = Dir::read($root); + + foreach ($index as $dir) { + $oldRoot = $root . '/' . $dir; + $newRoot = preg_replace('!\/([0-9]+)\-!', '/$1_', $oldRoot); + + if (is_dir($oldRoot) === true) { + Dir::move($oldRoot, $newRoot); + static::upgradeContent($newRoot); + } + } + } } diff --git a/kirby/src/Cms/Template.php b/kirby/src/Cms/Template.php index 8241442..e3e7e07 100755 --- a/kirby/src/Cms/Template.php +++ b/kirby/src/Cms/Template.php @@ -18,188 +18,188 @@ use Kirby\Toolkit\Tpl; */ class Template { - /** - * Global template data - * - * @var array - */ - public static $data = []; + /** + * Global template data + * + * @var array + */ + public static $data = []; - /** - * The name of the template - * - * @var string - */ - protected $name; + /** + * The name of the template + * + * @var string + */ + protected $name; - /** - * Template type (html, json, etc.) - * - * @var string - */ - protected $type; + /** + * Template type (html, json, etc.) + * + * @var string + */ + protected $type; - /** - * Default template type if no specific type is set - * - * @var string - */ - protected $defaultType; + /** + * Default template type if no specific type is set + * + * @var string + */ + protected $defaultType; - /** - * Creates a new template object - * - * @param string $name - * @param string $type - * @param string $defaultType - */ - public function __construct(string $name, string $type = 'html', string $defaultType = 'html') - { - $this->name = strtolower($name); - $this->type = $type; - $this->defaultType = $defaultType; - } + /** + * Creates a new template object + * + * @param string $name + * @param string $type + * @param string $defaultType + */ + public function __construct(string $name, string $type = 'html', string $defaultType = 'html') + { + $this->name = strtolower($name); + $this->type = $type; + $this->defaultType = $defaultType; + } - /** - * Converts the object to a simple string - * This is used in template filters for example - * - * @return string - */ - public function __toString(): string - { - return $this->name; - } + /** + * Converts the object to a simple string + * This is used in template filters for example + * + * @return string + */ + public function __toString(): string + { + return $this->name; + } - /** - * Checks if the template exists - * - * @return bool - */ - public function exists(): bool - { - if ($file = $this->file()) { - return file_exists($file); - } + /** + * Checks if the template exists + * + * @return bool + */ + public function exists(): bool + { + if ($file = $this->file()) { + return file_exists($file); + } - return false; - } + return false; + } - /** - * Returns the expected template file extension - * - * @return string - */ - public function extension(): string - { - return 'php'; - } + /** + * Returns the expected template file extension + * + * @return string + */ + public function extension(): string + { + return 'php'; + } - /** - * Returns the default template type - * - * @return string - */ - public function defaultType(): string - { - return $this->defaultType; - } + /** + * Returns the default template type + * + * @return string + */ + public function defaultType(): string + { + return $this->defaultType; + } - /** - * Returns the place where templates are located - * in the site folder and and can be found in extensions - * - * @return string - */ - public function store(): string - { - return 'templates'; - } + /** + * Returns the place where templates are located + * in the site folder and and can be found in extensions + * + * @return string + */ + public function store(): string + { + return 'templates'; + } - /** - * Detects the location of the template file - * if it exists. - * - * @return string|null - */ - public function file(): ?string - { - if ($this->hasDefaultType() === true) { - try { - // Try the default template in the default template directory. - return F::realpath($this->root() . '/' . $this->name() . '.' . $this->extension(), $this->root()); - } catch (Exception $e) { - // ignore errors, continue searching - } + /** + * Detects the location of the template file + * if it exists. + * + * @return string|null + */ + public function file(): ?string + { + if ($this->hasDefaultType() === true) { + try { + // Try the default template in the default template directory. + return F::realpath($this->root() . '/' . $this->name() . '.' . $this->extension(), $this->root()); + } catch (Exception $e) { + // ignore errors, continue searching + } - // Look for the default template provided by an extension. - $path = App::instance()->extension($this->store(), $this->name()); + // Look for the default template provided by an extension. + $path = App::instance()->extension($this->store(), $this->name()); - if ($path !== null) { - return $path; - } - } + if ($path !== null) { + return $path; + } + } - $name = $this->name() . '.' . $this->type(); + $name = $this->name() . '.' . $this->type(); - try { - // Try the template with type extension in the default template directory. - return F::realpath($this->root() . '/' . $name . '.' . $this->extension(), $this->root()); - } catch (Exception $e) { - // Look for the template with type extension provided by an extension. - // This might be null if the template does not exist. - return App::instance()->extension($this->store(), $name); - } - } + try { + // Try the template with type extension in the default template directory. + return F::realpath($this->root() . '/' . $name . '.' . $this->extension(), $this->root()); + } catch (Exception $e) { + // Look for the template with type extension provided by an extension. + // This might be null if the template does not exist. + return App::instance()->extension($this->store(), $name); + } + } - /** - * Returns the template name - * - * @return string - */ - public function name(): string - { - return $this->name; - } + /** + * Returns the template name + * + * @return string + */ + public function name(): string + { + return $this->name; + } - /** - * @param array $data - * @return string - */ - public function render(array $data = []): string - { - return Tpl::load($this->file(), $data); - } + /** + * @param array $data + * @return string + */ + public function render(array $data = []): string + { + return Tpl::load($this->file(), $data); + } - /** - * Returns the root to the templates directory - * - * @return string - */ - public function root(): string - { - return App::instance()->root($this->store()); - } + /** + * Returns the root to the templates directory + * + * @return string + */ + public function root(): string + { + return App::instance()->root($this->store()); + } - /** - * Returns the template type - * - * @return string - */ - public function type(): string - { - return $this->type; - } + /** + * Returns the template type + * + * @return string + */ + public function type(): string + { + return $this->type; + } - /** - * Checks if the template uses the default type - * - * @return bool - */ - public function hasDefaultType(): bool - { - $type = $this->type(); + /** + * Checks if the template uses the default type + * + * @return bool + */ + public function hasDefaultType(): bool + { + $type = $this->type(); - return $type === null || $type === $this->defaultType(); - } + return $type === null || $type === $this->defaultType(); + } } diff --git a/kirby/src/Cms/Translation.php b/kirby/src/Cms/Translation.php index 1a0e15c..b297ba4 100755 --- a/kirby/src/Cms/Translation.php +++ b/kirby/src/Cms/Translation.php @@ -18,178 +18,178 @@ use Kirby\Toolkit\Str; */ class Translation { - /** - * @var string - */ - protected $code; + /** + * @var string + */ + protected $code; - /** - * @var array - */ - protected $data = []; + /** + * @var array + */ + protected $data = []; - /** - * @param string $code - * @param array $data - */ - public function __construct(string $code, array $data) - { - $this->code = $code; - $this->data = $data; - } + /** + * @param string $code + * @param array $data + */ + public function __construct(string $code, array $data) + { + $this->code = $code; + $this->data = $data; + } - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return $this->toArray(); - } + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return $this->toArray(); + } - /** - * Returns the translation author - * - * @return string - */ - public function author(): string - { - return $this->get('translation.author', 'Kirby'); - } + /** + * Returns the translation author + * + * @return string + */ + public function author(): string + { + return $this->get('translation.author', 'Kirby'); + } - /** - * Returns the official translation code - * - * @return string - */ - public function code(): string - { - return $this->code; - } + /** + * Returns the official translation code + * + * @return string + */ + public function code(): string + { + return $this->code; + } - /** - * Returns an array with all - * translation strings - * - * @return array - */ - public function data(): array - { - return $this->data; - } + /** + * Returns an array with all + * translation strings + * + * @return array + */ + public function data(): array + { + return $this->data; + } - /** - * Returns the translation data and merges - * it with the data from the default translation - * - * @return array - */ - public function dataWithFallback(): array - { - if ($this->code === 'en') { - return $this->data; - } + /** + * Returns the translation data and merges + * it with the data from the default translation + * + * @return array + */ + public function dataWithFallback(): array + { + if ($this->code === 'en') { + return $this->data; + } - // get the fallback array - $fallback = App::instance()->translation('en')->data(); + // get the fallback array + $fallback = App::instance()->translation('en')->data(); - return array_merge($fallback, $this->data); - } + return array_merge($fallback, $this->data); + } - /** - * Returns the writing direction - * (ltr or rtl) - * - * @return string - */ - public function direction(): string - { - return $this->get('translation.direction', 'ltr'); - } + /** + * Returns the writing direction + * (ltr or rtl) + * + * @return string + */ + public function direction(): string + { + return $this->get('translation.direction', 'ltr'); + } - /** - * Returns a single translation - * string by key - * - * @param string $key - * @param string|null $default - * @return string|null - */ - public function get(string $key, string $default = null): ?string - { - return $this->data[$key] ?? $default; - } + /** + * Returns a single translation + * string by key + * + * @param string $key + * @param string|null $default + * @return string|null + */ + public function get(string $key, string $default = null): ?string + { + return $this->data[$key] ?? $default; + } - /** - * Returns the translation id, - * which is also the code - * - * @return string - */ - public function id(): string - { - return $this->code; - } + /** + * Returns the translation id, + * which is also the code + * + * @return string + */ + public function id(): string + { + return $this->code; + } - /** - * Loads the translation from the - * json file in Kirby's translations folder - * - * @param string $code - * @param string $root - * @param array $inject - * @return static - */ - public static function load(string $code, string $root, array $inject = []) - { - try { - $data = array_merge(Data::read($root), $inject); - } catch (Exception $e) { - $data = []; - } + /** + * Loads the translation from the + * json file in Kirby's translations folder + * + * @param string $code + * @param string $root + * @param array $inject + * @return static + */ + public static function load(string $code, string $root, array $inject = []) + { + try { + $data = array_merge(Data::read($root), $inject); + } catch (Exception $e) { + $data = []; + } - return new static($code, $data); - } + return new static($code, $data); + } - /** - * Returns the PHP locale of the translation - * - * @return string - */ - public function locale(): string - { - $default = $this->code; - if (Str::contains($default, '_') !== true) { - $default .= '_' . strtoupper($this->code); - } + /** + * Returns the PHP locale of the translation + * + * @return string + */ + public function locale(): string + { + $default = $this->code; + if (Str::contains($default, '_') !== true) { + $default .= '_' . strtoupper($this->code); + } - return $this->get('translation.locale', $default); - } + return $this->get('translation.locale', $default); + } - /** - * Returns the human-readable translation name. - * - * @return string - */ - public function name(): string - { - return $this->get('translation.name', $this->code); - } + /** + * Returns the human-readable translation name. + * + * @return string + */ + public function name(): string + { + return $this->get('translation.name', $this->code); + } - /** - * Converts the most important - * properties to an array - * - * @return array - */ - public function toArray(): array - { - return [ - 'code' => $this->code(), - 'data' => $this->data(), - 'name' => $this->name(), - 'author' => $this->author(), - ]; - } + /** + * Converts the most important + * properties to an array + * + * @return array + */ + public function toArray(): array + { + return [ + 'code' => $this->code(), + 'data' => $this->data(), + 'name' => $this->name(), + 'author' => $this->author(), + ]; + } } diff --git a/kirby/src/Cms/Translations.php b/kirby/src/Cms/Translations.php index 0512997..c45dd40 100755 --- a/kirby/src/Cms/Translations.php +++ b/kirby/src/Cms/Translations.php @@ -19,60 +19,60 @@ use Kirby\Filesystem\F; */ class Translations extends Collection { - /** - * @param string $code - * @return void - */ - public function start(string $code): void - { - F::move($this->parent->contentFile('', true), $this->parent->contentFile($code, true)); - } + /** + * @param string $code + * @return void + */ + public function start(string $code): void + { + F::move($this->parent->contentFile('', true), $this->parent->contentFile($code, true)); + } - /** - * @param string $code - * @return void - */ - public function stop(string $code): void - { - F::move($this->parent->contentFile($code, true), $this->parent->contentFile('', true)); - } + /** + * @param string $code + * @return void + */ + public function stop(string $code): void + { + F::move($this->parent->contentFile($code, true), $this->parent->contentFile('', true)); + } - /** - * @param array $translations - * @return static - */ - public static function factory(array $translations) - { - $collection = new static(); + /** + * @param array $translations + * @return static + */ + public static function factory(array $translations) + { + $collection = new static(); - foreach ($translations as $code => $props) { - $translation = new Translation($code, $props); - $collection->data[$translation->code()] = $translation; - } + foreach ($translations as $code => $props) { + $translation = new Translation($code, $props); + $collection->data[$translation->code()] = $translation; + } - return $collection; - } + return $collection; + } - /** - * @param string $root - * @param array $inject - * @return static - */ - public static function load(string $root, array $inject = []) - { - $collection = new static(); + /** + * @param string $root + * @param array $inject + * @return static + */ + public static function load(string $root, array $inject = []) + { + $collection = new static(); - foreach (Dir::read($root) as $filename) { - if (F::extension($filename) !== 'json') { - continue; - } + foreach (Dir::read($root) as $filename) { + if (F::extension($filename) !== 'json') { + continue; + } - $locale = F::name($filename); - $translation = Translation::load($locale, $root . '/' . $filename, $inject[$locale] ?? []); + $locale = F::name($filename); + $translation = Translation::load($locale, $root . '/' . $filename, $inject[$locale] ?? []); - $collection->data[$locale] = $translation; - } + $collection->data[$locale] = $translation; + } - return $collection; - } + return $collection; + } } diff --git a/kirby/src/Cms/Url.php b/kirby/src/Cms/Url.php index 4351fbf..9111b09 100755 --- a/kirby/src/Cms/Url.php +++ b/kirby/src/Cms/Url.php @@ -21,46 +21,46 @@ use Kirby\Http\Url as BaseUrl; */ class Url extends BaseUrl { - public static $home = null; + public static $home = null; - /** - * Returns the Url to the homepage - * - * @return string - */ - public static function home(): string - { - return App::instance()->url(); - } + /** + * Returns the Url to the homepage + * + * @return string + */ + public static function home(): string + { + return App::instance()->url(); + } - /** - * Creates an absolute Url to a template asset if it exists. This is used in the `css()` and `js()` helpers - * - * @param string $assetPath - * @param string $extension - * @return string|null - */ - public static function toTemplateAsset(string $assetPath, string $extension) - { - $kirby = App::instance(); - $page = $kirby->site()->page(); - $path = $assetPath . '/' . $page->template() . '.' . $extension; - $file = $kirby->root('assets') . '/' . $path; - $url = $kirby->url('assets') . '/' . $path; + /** + * Creates an absolute Url to a template asset if it exists. This is used in the `css()` and `js()` helpers + * + * @param string $assetPath + * @param string $extension + * @return string|null + */ + public static function toTemplateAsset(string $assetPath, string $extension) + { + $kirby = App::instance(); + $page = $kirby->site()->page(); + $path = $assetPath . '/' . $page->template() . '.' . $extension; + $file = $kirby->root('assets') . '/' . $path; + $url = $kirby->url('assets') . '/' . $path; - return file_exists($file) === true ? $url : null; - } + return file_exists($file) === true ? $url : null; + } - /** - * Smart resolver for internal and external urls - * - * @param string|null $path - * @param array|string|null $options Either an array of options for the Uri class or a language string - * @return string - */ - public static function to(string $path = null, $options = null): string - { - $kirby = App::instance(); - return ($kirby->component('url'))($kirby, $path, $options); - } + /** + * Smart resolver for internal and external urls + * + * @param string|null $path + * @param array|string|null $options Either an array of options for the Uri class or a language string + * @return string + */ + public static function to(string $path = null, $options = null): string + { + $kirby = App::instance(); + return ($kirby->component('url'))($kirby, $path, $options); + } } diff --git a/kirby/src/Cms/User.php b/kirby/src/Cms/User.php index 02d5417..6bd2cb0 100755 --- a/kirby/src/Cms/User.php +++ b/kirby/src/Cms/User.php @@ -22,913 +22,913 @@ use Kirby\Toolkit\Str; */ class User extends ModelWithContent { - use HasFiles; - use HasMethods; - use HasSiblings; - use UserActions; - - public const CLASS_ALIAS = 'user'; - - /** - * @var UserBlueprint - */ - protected $blueprint; - - /** - * @var array - */ - protected $credentials; - - /** - * @var string - */ - protected $email; - - /** - * @var string - */ - protected $hash; - - /** - * @var string - */ - protected $id; - - /** - * @var array|null - */ - protected $inventory; - - /** - * @var string - */ - protected $language; - - /** - * All registered user methods - * - * @var array - */ - public static $methods = []; - - /** - * Registry with all User models - * - * @var array - */ - public static $models = []; - - /** - * @var \Kirby\Cms\Field - */ - protected $name; - - /** - * @var string - */ - protected $password; - - /** - * The user role - * - * @var string - */ - protected $role; - - /** - * Modified getter to also return fields - * from the content - * - * @param string $method - * @param array $arguments - * @return mixed - */ - public function __call(string $method, array $arguments = []) - { - // public property access - if (isset($this->$method) === true) { - return $this->$method; - } - - // user methods - if ($this->hasMethod($method)) { - return $this->callMethod($method, $arguments); - } - - // return site content otherwise - return $this->content()->get($method); - } - - /** - * Creates a new User object - * - * @param array $props - */ - public function __construct(array $props) - { - // TODO: refactor later to avoid redundant prop setting - $this->setProperty('id', $props['id'] ?? $this->createId(), true); - $this->setProperties($props); - } - - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return array_merge($this->toArray(), [ - 'avatar' => $this->avatar(), - 'content' => $this->content(), - 'role' => $this->role() - ]); - } - - /** - * Returns the url to the api endpoint - * - * @internal - * @param bool $relative - * @return string - */ - public function apiUrl(bool $relative = false): string - { - if ($relative === true) { - return 'users/' . $this->id(); - } else { - return $this->kirby()->url('api') . '/users/' . $this->id(); - } - } - - /** - * Returns the File object for the avatar or null - * - * @return \Kirby\Cms\File|null - */ - public function avatar() - { - return $this->files()->template('avatar')->first(); - } - - /** - * Returns the UserBlueprint object - * - * @return \Kirby\Cms\Blueprint - */ - public function blueprint() - { - if (is_a($this->blueprint, 'Kirby\Cms\Blueprint') === true) { - return $this->blueprint; - } - - try { - return $this->blueprint = UserBlueprint::factory('users/' . $this->role(), 'users/default', $this); - } catch (Exception $e) { - return $this->blueprint = new UserBlueprint([ - 'model' => $this, - 'name' => 'default', - 'title' => 'Default', - ]); - } - } - - /** - * Prepares the content for the write method - * - * @internal - * @param array $data - * @param string $languageCode|null Not used so far - * @return array - */ - public function contentFileData(array $data, string $languageCode = null): array - { - // remove stuff that has nothing to do in the text files - unset( - $data['email'], - $data['language'], - $data['name'], - $data['password'], - $data['role'] - ); - - return $data; - } - - /** - * Filename for the content file - * - * @internal - * @return string - */ - public function contentFileName(): string - { - return 'user'; - } - - protected function credentials(): array - { - return $this->credentials ??= $this->readCredentials(); - } - - /** - * Returns the user email address - * - * @return string - */ - public function email(): ?string - { - return $this->email ??= $this->credentials()['email'] ?? null; - } - - /** - * Checks if the user exists - * - * @return bool - */ - public function exists(): bool - { - return is_file($this->contentFile('default')) === true; - } - - /** - * Constructs a User object and also - * takes User models into account. - * - * @internal - * @param mixed $props - * @return static - */ - public static function factory($props) - { - if (empty($props['model']) === false) { - return static::model($props['model'], $props); - } - - return new static($props); - } - - /** - * Hashes the user's password unless it is `null`, - * which will leave it as `null` - * - * @internal - * @param string|null $password - * @return string|null - */ - public static function hashPassword($password): ?string - { - if ($password !== null) { - $password = password_hash($password, PASSWORD_DEFAULT); - } - - return $password; - } - - /** - * Returns the user id - * - * @return string - */ - public function id(): string - { - return $this->id; - } - - /** - * Returns the inventory of files - * children and content files - * - * @return array - */ - public function inventory(): array - { - if ($this->inventory !== null) { - return $this->inventory; - } - - $kirby = $this->kirby(); - - return $this->inventory = Dir::inventory( - $this->root(), - $kirby->contentExtension(), - $kirby->contentIgnore(), - $kirby->multilang() - ); - } - - /** - * Compares the current object with the given user object - * - * @param \Kirby\Cms\User|null $user - * @return bool - */ - public function is(User $user = null): bool - { - if ($user === null) { - return false; - } - - return $this->id() === $user->id(); - } - - /** - * Checks if this user has the admin role - * - * @return bool - */ - public function isAdmin(): bool - { - return $this->role()->id() === 'admin'; - } - - /** - * Checks if the current user is the virtual - * Kirby user - * - * @return bool - */ - public function isKirby(): bool - { - return $this->email() === 'kirby@getkirby.com'; - } - - /** - * Checks if the current user is this user - * - * @return bool - */ - public function isLoggedIn(): bool - { - return $this->is($this->kirby()->user()); - } - - /** - * Checks if the user is the last one - * with the admin role - * - * @return bool - */ - public function isLastAdmin(): bool - { - return $this->role()->isAdmin() === true && - $this->kirby()->users()->filter('role', 'admin')->count() <= 1; - } - - /** - * Checks if the user is the last user - * - * @return bool - */ - public function isLastUser(): bool - { - return $this->kirby()->users()->count() === 1; - } - - /** - * Checks if the current user is the virtual - * Nobody user - * - * @return bool - */ - public function isNobody(): bool - { - return $this->email() === 'nobody@getkirby.com'; - } - - /** - * Returns the user language - * - * @return string - */ - public function language(): string - { - return $this->language ??= $this->credentials()['language'] ?? $this->kirby()->panelLanguage(); - } - - /** - * Logs the user in - * - * @param string $password - * @param \Kirby\Session\Session|array|null $session Session options or session object to set the user in - * @return bool - */ - public function login(string $password, $session = null): bool - { - $this->validatePassword($password); - $this->loginPasswordless($session); - - return true; - } - - /** - * Logs the user in without checking the password - * - * @param \Kirby\Session\Session|array|null $session Session options or session object to set the user in - * @return void - */ - public function loginPasswordless($session = null): void - { - $kirby = $this->kirby(); - - $session = $this->sessionFromOptions($session); - - $kirby->trigger('user.login:before', ['user' => $this, 'session' => $session]); - - $session->regenerateToken(); // privilege change - $session->data()->set('kirby.userId', $this->id()); - $this->kirby()->auth()->setUser($this); - - $kirby->trigger('user.login:after', ['user' => $this, 'session' => $session]); - } - - /** - * Logs the user out - * - * @param \Kirby\Session\Session|array|null $session Session options or session object to unset the user in - * @return void - */ - public function logout($session = null): void - { - $kirby = $this->kirby(); - $session = $this->sessionFromOptions($session); - - $kirby->trigger('user.logout:before', ['user' => $this, 'session' => $session]); - - // remove the user from the session for future requests - $session->data()->remove('kirby.userId'); - - // clear the cached user object from the app state of the current request - $this->kirby()->auth()->flush(); - - if ($session->data()->get() === []) { - // session is now empty, we might as well destroy it - $session->destroy(); - - $kirby->trigger('user.logout:after', ['user' => $this, 'session' => null]); - } else { - // privilege change - $session->regenerateToken(); - - $kirby->trigger('user.logout:after', ['user' => $this, 'session' => $session]); - } - } - - /** - * Returns the root to the media folder for the user - * - * @internal - * @return string - */ - public function mediaRoot(): string - { - return $this->kirby()->root('media') . '/users/' . $this->id(); - } - - /** - * Returns the media url for the user object - * - * @internal - * @return string - */ - public function mediaUrl(): string - { - return $this->kirby()->url('media') . '/users/' . $this->id(); - } - - /** - * Creates a user model if it has been registered - * - * @internal - * @param string $name - * @param array $props - * @return \Kirby\Cms\User - */ - public static function model(string $name, array $props = []) - { - if ($class = (static::$models[$name] ?? null)) { - $object = new $class($props); - - if (is_a($object, 'Kirby\Cms\User') === true) { - return $object; - } - } - - return new static($props); - } - - /** - * Returns the last modification date of the user - * - * @param string $format - * @param string|null $handler - * @param string|null $languageCode - * @return int|string - */ - public function modified(string $format = 'U', string $handler = null, string $languageCode = null) - { - $modifiedContent = F::modified($this->contentFile($languageCode)); - $modifiedIndex = F::modified($this->root() . '/index.php'); - $modifiedTotal = max([$modifiedContent, $modifiedIndex]); - $handler ??= $this->kirby()->option('date.handler', 'date'); - - return Str::date($modifiedTotal, $format, $handler); - } - - /** - * Returns the user's name - * - * @return \Kirby\Cms\Field - */ - public function name() - { - if (is_string($this->name) === true) { - return new Field($this, 'name', $this->name); - } - - if ($this->name !== null) { - return $this->name; - } - - return $this->name = new Field($this, 'name', $this->credentials()['name'] ?? null); - } - - /** - * Returns the user's name or, - * if empty, the email address - * - * @return \Kirby\Cms\Field - */ - public function nameOrEmail() - { - $name = $this->name(); - return $name->isNotEmpty() ? $name : new Field($this, 'email', $this->email()); - } - - /** - * Create a dummy nobody - * - * @internal - * @return static - */ - public static function nobody() - { - return new static([ - 'email' => 'nobody@getkirby.com', - 'role' => 'nobody' - ]); - } - - /** - * Returns the panel info object - * - * @return \Kirby\Panel\User - */ - public function panel() - { - return new Panel($this); - } - - /** - * Returns the encrypted user password - * - * @return string|null - */ - public function password(): ?string - { - if ($this->password !== null) { - return $this->password; - } - - return $this->password = $this->readPassword(); - } - - /** - * @return \Kirby\Cms\UserPermissions - */ - public function permissions() - { - return new UserPermissions($this); - } - - /** - * Returns the user role - * - * @return \Kirby\Cms\Role - */ - public function role() - { - if (is_a($this->role, 'Kirby\Cms\Role') === true) { - return $this->role; - } - - $roleName = $this->role ?? $this->credentials()['role'] ?? 'visitor'; - - if ($role = $this->kirby()->roles()->find($roleName)) { - return $this->role = $role; - } - - return $this->role = Role::nobody(); - } - - /** - * Returns all available roles - * for this user, that can be selected - * by the authenticated user - * - * @return \Kirby\Cms\Roles - */ - public function roles() - { - $kirby = $this->kirby(); - $roles = $kirby->roles(); - - // a collection with just the one role of the user - $myRole = $roles->filter('id', $this->role()->id()); - - // if there's an authenticated user … - if ($user = $kirby->user()) { - - // admin users can select pretty much any role - if ($user->isAdmin() === true) { - // except if the user is the last admin - if ($this->isLastAdmin() === true) { - // in which case they have to stay admin - return $myRole; - } - - // return all roles for mighty admins - return $roles; - } - } - - // any other user can only keep their role - return $myRole; - } - - /** - * The absolute path to the user directory - * - * @return string - */ - public function root(): string - { - return $this->kirby()->root('accounts') . '/' . $this->id(); - } - - /** - * Returns the UserRules class to - * validate any important action. - * - * @return \Kirby\Cms\UserRules - */ - protected function rules() - { - return new UserRules(); - } - - /** - * Sets the Blueprint object - * - * @param array|null $blueprint - * @return $this - */ - protected function setBlueprint(array $blueprint = null) - { - if ($blueprint !== null) { - $blueprint['model'] = $this; - $this->blueprint = new UserBlueprint($blueprint); - } - - return $this; - } - - /** - * Sets the user email - * - * @param string $email|null - * @return $this - */ - protected function setEmail(string $email = null) - { - if ($email !== null) { - $this->email = Str::lower(trim($email)); - } - return $this; - } - - /** - * Sets the user id - * - * @param string $id|null - * @return $this - */ - protected function setId(string $id = null) - { - $this->id = $id; - return $this; - } - - /** - * Sets the user language - * - * @param string $language|null - * @return $this - */ - protected function setLanguage(string $language = null) - { - $this->language = $language !== null ? trim($language) : null; - return $this; - } - - /** - * Sets the user name - * - * @param string $name|null - * @return $this - */ - protected function setName(string $name = null) - { - $this->name = $name !== null ? trim(strip_tags($name)) : null; - return $this; - } - - /** - * Sets the user's password hash - * - * @param string $password|null - * @return $this - */ - protected function setPassword(string $password = null) - { - $this->password = $password; - return $this; - } - - /** - * Sets the user role - * - * @param string $role|null - * @return $this - */ - protected function setRole(string $role = null) - { - $this->role = $role !== null ? Str::lower(trim($role)) : null; - return $this; - } - - /** - * Converts session options into a session object - * - * @param \Kirby\Session\Session|array $session Session options or session object to unset the user in - * @return \Kirby\Session\Session - */ - protected function sessionFromOptions($session) - { - // use passed session options or session object if set - if (is_array($session) === true) { - $session = $this->kirby()->session($session); - } elseif (is_a($session, 'Kirby\Session\Session') === false) { - $session = $this->kirby()->session(['detect' => true]); - } - - return $session; - } - - /** - * Returns the parent Users collection - * - * @return \Kirby\Cms\Users - */ - protected function siblingsCollection() - { - return $this->kirby()->users(); - } - - /** - * Converts the most important user properties - * to an array - * - * @return array - */ - public function toArray(): array - { - return [ - 'avatar' => $this->avatar() ? $this->avatar()->toArray() : null, - 'content' => $this->content()->toArray(), - 'email' => $this->email(), - 'id' => $this->id(), - 'language' => $this->language(), - 'role' => $this->role()->name(), - 'username' => $this->username() - ]; - } - - /** - * String template builder - * - * @param string|null $template - * @param array|null $data - * @param string $fallback Fallback for tokens in the template that cannot be replaced - * @return string - */ - public function toString(string $template = null, array $data = [], string $fallback = '', string $handler = 'template'): string - { - if ($template === null) { - $template = $this->email(); - } - - return parent::toString($template, $data, $fallback, $handler); - } - - /** - * Returns the username - * which is the given name or the email - * as a fallback - * - * @return string|null - */ - public function username(): ?string - { - return $this->name()->or($this->email())->value(); - } - - /** - * Compares the given password with the stored one - * - * @param string $password|null - * @return bool - * - * @throws \Kirby\Exception\NotFoundException If the user has no password - * @throws \Kirby\Exception\InvalidArgumentException If the entered password is not valid - * or does not match the user password - */ - public function validatePassword(string $password = null): bool - { - if (empty($this->password()) === true) { - throw new NotFoundException(['key' => 'user.password.undefined']); - } - - if (Str::length($password) < 8) { - throw new InvalidArgumentException(['key' => 'user.password.invalid']); - } - - if (password_verify($password, $this->password()) !== true) { - throw new InvalidArgumentException(['key' => 'user.password.wrong', 'httpCode' => 401]); - } - - return true; - } - - - /** - * Deprecated! - */ - - /** - * Returns the full path without leading slash - * - * @todo Remove in 3.8.0 - * - * @internal - * @return string - * @codeCoverageIgnore - */ - public function panelPath(): string - { - Helpers::deprecated('Cms\User::panelPath() has been deprecated and will be removed in Kirby 3.8.0. Use $user->panel()->path() instead.'); - return $this->panel()->path(); - } - - /** - * Returns prepared data for the panel user picker - * - * @todo Remove in 3.8.0 - * - * @param array|null $params - * @return array - * @codeCoverageIgnore - */ - public function panelPickerData(array $params = null): array - { - Helpers::deprecated('Cms\User::panelPickerData() has been deprecated and will be removed in Kirby 3.8.0. Use $user->panel()->pickerData() instead.'); - return $this->panel()->pickerData($params); - } - - /** - * Returns the url to the editing view - * in the panel - * - * @todo Remove in 3.8.0 - * - * @internal - * @param bool $relative - * @return string - * @codeCoverageIgnore - */ - public function panelUrl(bool $relative = false): string - { - Helpers::deprecated('Cms\User::panelUrl() has been deprecated and will be removed in Kirby 3.8.0. Use $user->panel()->url() instead.'); - return $this->panel()->url($relative); - } + use HasFiles; + use HasMethods; + use HasSiblings; + use UserActions; + + public const CLASS_ALIAS = 'user'; + + /** + * @var UserBlueprint + */ + protected $blueprint; + + /** + * @var array + */ + protected $credentials; + + /** + * @var string + */ + protected $email; + + /** + * @var string + */ + protected $hash; + + /** + * @var string + */ + protected $id; + + /** + * @var array|null + */ + protected $inventory; + + /** + * @var string + */ + protected $language; + + /** + * All registered user methods + * + * @var array + */ + public static $methods = []; + + /** + * Registry with all User models + * + * @var array + */ + public static $models = []; + + /** + * @var \Kirby\Cms\Field + */ + protected $name; + + /** + * @var string + */ + protected $password; + + /** + * The user role + * + * @var string + */ + protected $role; + + /** + * Modified getter to also return fields + * from the content + * + * @param string $method + * @param array $arguments + * @return mixed + */ + public function __call(string $method, array $arguments = []) + { + // public property access + if (isset($this->$method) === true) { + return $this->$method; + } + + // user methods + if ($this->hasMethod($method)) { + return $this->callMethod($method, $arguments); + } + + // return site content otherwise + return $this->content()->get($method); + } + + /** + * Creates a new User object + * + * @param array $props + */ + public function __construct(array $props) + { + // TODO: refactor later to avoid redundant prop setting + $this->setProperty('id', $props['id'] ?? $this->createId(), true); + $this->setProperties($props); + } + + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return array_merge($this->toArray(), [ + 'avatar' => $this->avatar(), + 'content' => $this->content(), + 'role' => $this->role() + ]); + } + + /** + * Returns the url to the api endpoint + * + * @internal + * @param bool $relative + * @return string + */ + public function apiUrl(bool $relative = false): string + { + if ($relative === true) { + return 'users/' . $this->id(); + } else { + return $this->kirby()->url('api') . '/users/' . $this->id(); + } + } + + /** + * Returns the File object for the avatar or null + * + * @return \Kirby\Cms\File|null + */ + public function avatar() + { + return $this->files()->template('avatar')->first(); + } + + /** + * Returns the UserBlueprint object + * + * @return \Kirby\Cms\Blueprint + */ + public function blueprint() + { + if (is_a($this->blueprint, 'Kirby\Cms\Blueprint') === true) { + return $this->blueprint; + } + + try { + return $this->blueprint = UserBlueprint::factory('users/' . $this->role(), 'users/default', $this); + } catch (Exception $e) { + return $this->blueprint = new UserBlueprint([ + 'model' => $this, + 'name' => 'default', + 'title' => 'Default', + ]); + } + } + + /** + * Prepares the content for the write method + * + * @internal + * @param array $data + * @param string $languageCode|null Not used so far + * @return array + */ + public function contentFileData(array $data, string $languageCode = null): array + { + // remove stuff that has nothing to do in the text files + unset( + $data['email'], + $data['language'], + $data['name'], + $data['password'], + $data['role'] + ); + + return $data; + } + + /** + * Filename for the content file + * + * @internal + * @return string + */ + public function contentFileName(): string + { + return 'user'; + } + + protected function credentials(): array + { + return $this->credentials ??= $this->readCredentials(); + } + + /** + * Returns the user email address + * + * @return string + */ + public function email(): ?string + { + return $this->email ??= $this->credentials()['email'] ?? null; + } + + /** + * Checks if the user exists + * + * @return bool + */ + public function exists(): bool + { + return is_file($this->contentFile('default')) === true; + } + + /** + * Constructs a User object and also + * takes User models into account. + * + * @internal + * @param mixed $props + * @return static + */ + public static function factory($props) + { + if (empty($props['model']) === false) { + return static::model($props['model'], $props); + } + + return new static($props); + } + + /** + * Hashes the user's password unless it is `null`, + * which will leave it as `null` + * + * @internal + * @param string|null $password + * @return string|null + */ + public static function hashPassword($password): ?string + { + if ($password !== null) { + $password = password_hash($password, PASSWORD_DEFAULT); + } + + return $password; + } + + /** + * Returns the user id + * + * @return string + */ + public function id(): string + { + return $this->id; + } + + /** + * Returns the inventory of files + * children and content files + * + * @return array + */ + public function inventory(): array + { + if ($this->inventory !== null) { + return $this->inventory; + } + + $kirby = $this->kirby(); + + return $this->inventory = Dir::inventory( + $this->root(), + $kirby->contentExtension(), + $kirby->contentIgnore(), + $kirby->multilang() + ); + } + + /** + * Compares the current object with the given user object + * + * @param \Kirby\Cms\User|null $user + * @return bool + */ + public function is(User $user = null): bool + { + if ($user === null) { + return false; + } + + return $this->id() === $user->id(); + } + + /** + * Checks if this user has the admin role + * + * @return bool + */ + public function isAdmin(): bool + { + return $this->role()->id() === 'admin'; + } + + /** + * Checks if the current user is the virtual + * Kirby user + * + * @return bool + */ + public function isKirby(): bool + { + return $this->email() === 'kirby@getkirby.com'; + } + + /** + * Checks if the current user is this user + * + * @return bool + */ + public function isLoggedIn(): bool + { + return $this->is($this->kirby()->user()); + } + + /** + * Checks if the user is the last one + * with the admin role + * + * @return bool + */ + public function isLastAdmin(): bool + { + return $this->role()->isAdmin() === true && + $this->kirby()->users()->filter('role', 'admin')->count() <= 1; + } + + /** + * Checks if the user is the last user + * + * @return bool + */ + public function isLastUser(): bool + { + return $this->kirby()->users()->count() === 1; + } + + /** + * Checks if the current user is the virtual + * Nobody user + * + * @return bool + */ + public function isNobody(): bool + { + return $this->email() === 'nobody@getkirby.com'; + } + + /** + * Returns the user language + * + * @return string + */ + public function language(): string + { + return $this->language ??= $this->credentials()['language'] ?? $this->kirby()->panelLanguage(); + } + + /** + * Logs the user in + * + * @param string $password + * @param \Kirby\Session\Session|array|null $session Session options or session object to set the user in + * @return bool + */ + public function login(string $password, $session = null): bool + { + $this->validatePassword($password); + $this->loginPasswordless($session); + + return true; + } + + /** + * Logs the user in without checking the password + * + * @param \Kirby\Session\Session|array|null $session Session options or session object to set the user in + * @return void + */ + public function loginPasswordless($session = null): void + { + $kirby = $this->kirby(); + + $session = $this->sessionFromOptions($session); + + $kirby->trigger('user.login:before', ['user' => $this, 'session' => $session]); + + $session->regenerateToken(); // privilege change + $session->data()->set('kirby.userId', $this->id()); + $this->kirby()->auth()->setUser($this); + + $kirby->trigger('user.login:after', ['user' => $this, 'session' => $session]); + } + + /** + * Logs the user out + * + * @param \Kirby\Session\Session|array|null $session Session options or session object to unset the user in + * @return void + */ + public function logout($session = null): void + { + $kirby = $this->kirby(); + $session = $this->sessionFromOptions($session); + + $kirby->trigger('user.logout:before', ['user' => $this, 'session' => $session]); + + // remove the user from the session for future requests + $session->data()->remove('kirby.userId'); + + // clear the cached user object from the app state of the current request + $this->kirby()->auth()->flush(); + + if ($session->data()->get() === []) { + // session is now empty, we might as well destroy it + $session->destroy(); + + $kirby->trigger('user.logout:after', ['user' => $this, 'session' => null]); + } else { + // privilege change + $session->regenerateToken(); + + $kirby->trigger('user.logout:after', ['user' => $this, 'session' => $session]); + } + } + + /** + * Returns the root to the media folder for the user + * + * @internal + * @return string + */ + public function mediaRoot(): string + { + return $this->kirby()->root('media') . '/users/' . $this->id(); + } + + /** + * Returns the media url for the user object + * + * @internal + * @return string + */ + public function mediaUrl(): string + { + return $this->kirby()->url('media') . '/users/' . $this->id(); + } + + /** + * Creates a user model if it has been registered + * + * @internal + * @param string $name + * @param array $props + * @return \Kirby\Cms\User + */ + public static function model(string $name, array $props = []) + { + if ($class = (static::$models[$name] ?? null)) { + $object = new $class($props); + + if (is_a($object, 'Kirby\Cms\User') === true) { + return $object; + } + } + + return new static($props); + } + + /** + * Returns the last modification date of the user + * + * @param string $format + * @param string|null $handler + * @param string|null $languageCode + * @return int|string + */ + public function modified(string $format = 'U', string $handler = null, string $languageCode = null) + { + $modifiedContent = F::modified($this->contentFile($languageCode)); + $modifiedIndex = F::modified($this->root() . '/index.php'); + $modifiedTotal = max([$modifiedContent, $modifiedIndex]); + $handler ??= $this->kirby()->option('date.handler', 'date'); + + return Str::date($modifiedTotal, $format, $handler); + } + + /** + * Returns the user's name + * + * @return \Kirby\Cms\Field + */ + public function name() + { + if (is_string($this->name) === true) { + return new Field($this, 'name', $this->name); + } + + if ($this->name !== null) { + return $this->name; + } + + return $this->name = new Field($this, 'name', $this->credentials()['name'] ?? null); + } + + /** + * Returns the user's name or, + * if empty, the email address + * + * @return \Kirby\Cms\Field + */ + public function nameOrEmail() + { + $name = $this->name(); + return $name->isNotEmpty() ? $name : new Field($this, 'email', $this->email()); + } + + /** + * Create a dummy nobody + * + * @internal + * @return static + */ + public static function nobody() + { + return new static([ + 'email' => 'nobody@getkirby.com', + 'role' => 'nobody' + ]); + } + + /** + * Returns the panel info object + * + * @return \Kirby\Panel\User + */ + public function panel() + { + return new Panel($this); + } + + /** + * Returns the encrypted user password + * + * @return string|null + */ + public function password(): ?string + { + if ($this->password !== null) { + return $this->password; + } + + return $this->password = $this->readPassword(); + } + + /** + * @return \Kirby\Cms\UserPermissions + */ + public function permissions() + { + return new UserPermissions($this); + } + + /** + * Returns the user role + * + * @return \Kirby\Cms\Role + */ + public function role() + { + if (is_a($this->role, 'Kirby\Cms\Role') === true) { + return $this->role; + } + + $roleName = $this->role ?? $this->credentials()['role'] ?? 'visitor'; + + if ($role = $this->kirby()->roles()->find($roleName)) { + return $this->role = $role; + } + + return $this->role = Role::nobody(); + } + + /** + * Returns all available roles + * for this user, that can be selected + * by the authenticated user + * + * @return \Kirby\Cms\Roles + */ + public function roles() + { + $kirby = $this->kirby(); + $roles = $kirby->roles(); + + // a collection with just the one role of the user + $myRole = $roles->filter('id', $this->role()->id()); + + // if there's an authenticated user … + if ($user = $kirby->user()) { + + // admin users can select pretty much any role + if ($user->isAdmin() === true) { + // except if the user is the last admin + if ($this->isLastAdmin() === true) { + // in which case they have to stay admin + return $myRole; + } + + // return all roles for mighty admins + return $roles; + } + } + + // any other user can only keep their role + return $myRole; + } + + /** + * The absolute path to the user directory + * + * @return string + */ + public function root(): string + { + return $this->kirby()->root('accounts') . '/' . $this->id(); + } + + /** + * Returns the UserRules class to + * validate any important action. + * + * @return \Kirby\Cms\UserRules + */ + protected function rules() + { + return new UserRules(); + } + + /** + * Sets the Blueprint object + * + * @param array|null $blueprint + * @return $this + */ + protected function setBlueprint(array $blueprint = null) + { + if ($blueprint !== null) { + $blueprint['model'] = $this; + $this->blueprint = new UserBlueprint($blueprint); + } + + return $this; + } + + /** + * Sets the user email + * + * @param string $email|null + * @return $this + */ + protected function setEmail(string $email = null) + { + if ($email !== null) { + $this->email = Str::lower(trim($email)); + } + return $this; + } + + /** + * Sets the user id + * + * @param string $id|null + * @return $this + */ + protected function setId(string $id = null) + { + $this->id = $id; + return $this; + } + + /** + * Sets the user language + * + * @param string $language|null + * @return $this + */ + protected function setLanguage(string $language = null) + { + $this->language = $language !== null ? trim($language) : null; + return $this; + } + + /** + * Sets the user name + * + * @param string $name|null + * @return $this + */ + protected function setName(string $name = null) + { + $this->name = $name !== null ? trim(strip_tags($name)) : null; + return $this; + } + + /** + * Sets the user's password hash + * + * @param string $password|null + * @return $this + */ + protected function setPassword(string $password = null) + { + $this->password = $password; + return $this; + } + + /** + * Sets the user role + * + * @param string $role|null + * @return $this + */ + protected function setRole(string $role = null) + { + $this->role = $role !== null ? Str::lower(trim($role)) : null; + return $this; + } + + /** + * Converts session options into a session object + * + * @param \Kirby\Session\Session|array $session Session options or session object to unset the user in + * @return \Kirby\Session\Session + */ + protected function sessionFromOptions($session) + { + // use passed session options or session object if set + if (is_array($session) === true) { + $session = $this->kirby()->session($session); + } elseif (is_a($session, 'Kirby\Session\Session') === false) { + $session = $this->kirby()->session(['detect' => true]); + } + + return $session; + } + + /** + * Returns the parent Users collection + * + * @return \Kirby\Cms\Users + */ + protected function siblingsCollection() + { + return $this->kirby()->users(); + } + + /** + * Converts the most important user properties + * to an array + * + * @return array + */ + public function toArray(): array + { + return [ + 'avatar' => $this->avatar() ? $this->avatar()->toArray() : null, + 'content' => $this->content()->toArray(), + 'email' => $this->email(), + 'id' => $this->id(), + 'language' => $this->language(), + 'role' => $this->role()->name(), + 'username' => $this->username() + ]; + } + + /** + * String template builder + * + * @param string|null $template + * @param array|null $data + * @param string $fallback Fallback for tokens in the template that cannot be replaced + * @return string + */ + public function toString(string $template = null, array $data = [], string $fallback = '', string $handler = 'template'): string + { + if ($template === null) { + $template = $this->email(); + } + + return parent::toString($template, $data, $fallback, $handler); + } + + /** + * Returns the username + * which is the given name or the email + * as a fallback + * + * @return string|null + */ + public function username(): ?string + { + return $this->name()->or($this->email())->value(); + } + + /** + * Compares the given password with the stored one + * + * @param string $password|null + * @return bool + * + * @throws \Kirby\Exception\NotFoundException If the user has no password + * @throws \Kirby\Exception\InvalidArgumentException If the entered password is not valid + * or does not match the user password + */ + public function validatePassword(string $password = null): bool + { + if (empty($this->password()) === true) { + throw new NotFoundException(['key' => 'user.password.undefined']); + } + + if (Str::length($password) < 8) { + throw new InvalidArgumentException(['key' => 'user.password.invalid']); + } + + if (password_verify($password, $this->password()) !== true) { + throw new InvalidArgumentException(['key' => 'user.password.wrong', 'httpCode' => 401]); + } + + return true; + } + + + /** + * Deprecated! + */ + + /** + * Returns the full path without leading slash + * + * @todo Remove in 3.8.0 + * + * @internal + * @return string + * @codeCoverageIgnore + */ + public function panelPath(): string + { + Helpers::deprecated('Cms\User::panelPath() has been deprecated and will be removed in Kirby 3.8.0. Use $user->panel()->path() instead.'); + return $this->panel()->path(); + } + + /** + * Returns prepared data for the panel user picker + * + * @todo Remove in 3.8.0 + * + * @param array|null $params + * @return array + * @codeCoverageIgnore + */ + public function panelPickerData(array $params = null): array + { + Helpers::deprecated('Cms\User::panelPickerData() has been deprecated and will be removed in Kirby 3.8.0. Use $user->panel()->pickerData() instead.'); + return $this->panel()->pickerData($params); + } + + /** + * Returns the url to the editing view + * in the panel + * + * @todo Remove in 3.8.0 + * + * @internal + * @param bool $relative + * @return string + * @codeCoverageIgnore + */ + public function panelUrl(bool $relative = false): string + { + Helpers::deprecated('Cms\User::panelUrl() has been deprecated and will be removed in Kirby 3.8.0. Use $user->panel()->url() instead.'); + return $this->panel()->url($relative); + } } diff --git a/kirby/src/Cms/UserActions.php b/kirby/src/Cms/UserActions.php index 8a5df12..4547844 100755 --- a/kirby/src/Cms/UserActions.php +++ b/kirby/src/Cms/UserActions.php @@ -24,367 +24,367 @@ use Throwable; */ trait UserActions { - /** - * Changes the user email address - * - * @param string $email - * @return static - */ - public function changeEmail(string $email) - { - $email = trim($email); + /** + * Changes the user email address + * + * @param string $email + * @return static + */ + public function changeEmail(string $email) + { + $email = trim($email); - return $this->commit('changeEmail', ['user' => $this, 'email' => Idn::decodeEmail($email)], function ($user, $email) { - $user = $user->clone([ - 'email' => $email - ]); + return $this->commit('changeEmail', ['user' => $this, 'email' => Idn::decodeEmail($email)], function ($user, $email) { + $user = $user->clone([ + 'email' => $email + ]); - $user->updateCredentials([ - 'email' => $email - ]); + $user->updateCredentials([ + 'email' => $email + ]); - // update the users collection - $user->kirby()->users()->set($user->id(), $user); + // update the users collection + $user->kirby()->users()->set($user->id(), $user); - return $user; - }); - } + return $user; + }); + } - /** - * Changes the user language - * - * @param string $language - * @return static - */ - public function changeLanguage(string $language) - { - return $this->commit('changeLanguage', ['user' => $this, 'language' => $language], function ($user, $language) { - $user = $user->clone([ - 'language' => $language, - ]); + /** + * Changes the user language + * + * @param string $language + * @return static + */ + public function changeLanguage(string $language) + { + return $this->commit('changeLanguage', ['user' => $this, 'language' => $language], function ($user, $language) { + $user = $user->clone([ + 'language' => $language, + ]); - $user->updateCredentials([ - 'language' => $language - ]); + $user->updateCredentials([ + 'language' => $language + ]); - // update the users collection - $user->kirby()->users()->set($user->id(), $user); + // update the users collection + $user->kirby()->users()->set($user->id(), $user); - return $user; - }); - } + return $user; + }); + } - /** - * Changes the screen name of the user - * - * @param string $name - * @return static - */ - public function changeName(string $name) - { - $name = trim($name); + /** + * Changes the screen name of the user + * + * @param string $name + * @return static + */ + public function changeName(string $name) + { + $name = trim($name); - return $this->commit('changeName', ['user' => $this, 'name' => $name], function ($user, $name) { - $user = $user->clone([ - 'name' => $name - ]); + return $this->commit('changeName', ['user' => $this, 'name' => $name], function ($user, $name) { + $user = $user->clone([ + 'name' => $name + ]); - $user->updateCredentials([ - 'name' => $name - ]); + $user->updateCredentials([ + 'name' => $name + ]); - // update the users collection - $user->kirby()->users()->set($user->id(), $user); + // update the users collection + $user->kirby()->users()->set($user->id(), $user); - return $user; - }); - } + return $user; + }); + } - /** - * Changes the user password - * - * @param string $password - * @return static - */ - public function changePassword(string $password) - { - return $this->commit('changePassword', ['user' => $this, 'password' => $password], function ($user, $password) { - $user = $user->clone([ - 'password' => $password = User::hashPassword($password) - ]); + /** + * Changes the user password + * + * @param string $password + * @return static + */ + public function changePassword(string $password) + { + return $this->commit('changePassword', ['user' => $this, 'password' => $password], function ($user, $password) { + $user = $user->clone([ + 'password' => $password = User::hashPassword($password) + ]); - $user->writePassword($password); + $user->writePassword($password); - // update the users collection - $user->kirby()->users()->set($user->id(), $user); + // update the users collection + $user->kirby()->users()->set($user->id(), $user); - return $user; - }); - } + return $user; + }); + } - /** - * Changes the user role - * - * @param string $role - * @return static - */ - public function changeRole(string $role) - { - return $this->commit('changeRole', ['user' => $this, 'role' => $role], function ($user, $role) { - $user = $user->clone([ - 'role' => $role, - ]); + /** + * Changes the user role + * + * @param string $role + * @return static + */ + public function changeRole(string $role) + { + return $this->commit('changeRole', ['user' => $this, 'role' => $role], function ($user, $role) { + $user = $user->clone([ + 'role' => $role, + ]); - $user->updateCredentials([ - 'role' => $role - ]); + $user->updateCredentials([ + 'role' => $role + ]); - // update the users collection - $user->kirby()->users()->set($user->id(), $user); + // update the users collection + $user->kirby()->users()->set($user->id(), $user); - return $user; - }); - } + return $user; + }); + } - /** - * Commits a user action, by following these steps - * - * 1. checks the action rules - * 2. sends the before hook - * 3. commits the action - * 4. sends the after hook - * 5. returns the result - * - * @param string $action - * @param array $arguments - * @param \Closure $callback - * @return mixed - * @throws \Kirby\Exception\PermissionException - */ - protected function commit(string $action, array $arguments, Closure $callback) - { - if ($this->isKirby() === true) { - throw new PermissionException('The Kirby user cannot be changed'); - } + /** + * Commits a user action, by following these steps + * + * 1. checks the action rules + * 2. sends the before hook + * 3. commits the action + * 4. sends the after hook + * 5. returns the result + * + * @param string $action + * @param array $arguments + * @param \Closure $callback + * @return mixed + * @throws \Kirby\Exception\PermissionException + */ + protected function commit(string $action, array $arguments, Closure $callback) + { + if ($this->isKirby() === true) { + throw new PermissionException('The Kirby user cannot be changed'); + } - $old = $this->hardcopy(); - $kirby = $this->kirby(); - $argumentValues = array_values($arguments); + $old = $this->hardcopy(); + $kirby = $this->kirby(); + $argumentValues = array_values($arguments); - $this->rules()->$action(...$argumentValues); - $kirby->trigger('user.' . $action . ':before', $arguments); + $this->rules()->$action(...$argumentValues); + $kirby->trigger('user.' . $action . ':before', $arguments); - $result = $callback(...$argumentValues); + $result = $callback(...$argumentValues); - if ($action === 'create') { - $argumentsAfter = ['user' => $result]; - } elseif ($action === 'delete') { - $argumentsAfter = ['status' => $result, 'user' => $old]; - } else { - $argumentsAfter = ['newUser' => $result, 'oldUser' => $old]; - } - $kirby->trigger('user.' . $action . ':after', $argumentsAfter); + if ($action === 'create') { + $argumentsAfter = ['user' => $result]; + } elseif ($action === 'delete') { + $argumentsAfter = ['status' => $result, 'user' => $old]; + } else { + $argumentsAfter = ['newUser' => $result, 'oldUser' => $old]; + } + $kirby->trigger('user.' . $action . ':after', $argumentsAfter); - $kirby->cache('pages')->flush(); - return $result; - } + $kirby->cache('pages')->flush(); + return $result; + } - /** - * Creates a new User from the given props and returns a new User object - * - * @param array|null $props - * @return static - */ - public static function create(array $props = null) - { - $data = $props; + /** + * Creates a new User from the given props and returns a new User object + * + * @param array|null $props + * @return static + */ + public static function create(array $props = null) + { + $data = $props; - if (isset($props['email']) === true) { - $data['email'] = Idn::decodeEmail($props['email']); - } + if (isset($props['email']) === true) { + $data['email'] = Idn::decodeEmail($props['email']); + } - if (isset($props['password']) === true) { - $data['password'] = User::hashPassword($props['password']); - } + if (isset($props['password']) === true) { + $data['password'] = User::hashPassword($props['password']); + } - $props['role'] = $props['model'] = strtolower($props['role'] ?? 'default'); + $props['role'] = $props['model'] = strtolower($props['role'] ?? 'default'); - $user = User::factory($data); + $user = User::factory($data); - // create a form for the user - $form = Form::for($user, [ - 'values' => $props['content'] ?? [] - ]); + // create a form for the user + $form = Form::for($user, [ + 'values' => $props['content'] ?? [] + ]); - // inject the content - $user = $user->clone(['content' => $form->strings(true)]); + // inject the content + $user = $user->clone(['content' => $form->strings(true)]); - // run the hook - return $user->commit('create', ['user' => $user, 'input' => $props], function ($user, $props) { - $user->writeCredentials([ - 'email' => $user->email(), - 'language' => $user->language(), - 'name' => $user->name()->value(), - 'role' => $user->role()->id(), - ]); + // run the hook + return $user->commit('create', ['user' => $user, 'input' => $props], function ($user, $props) { + $user->writeCredentials([ + 'email' => $user->email(), + 'language' => $user->language(), + 'name' => $user->name()->value(), + 'role' => $user->role()->id(), + ]); - $user->writePassword($user->password()); + $user->writePassword($user->password()); - // always create users in the default language - if ($user->kirby()->multilang() === true) { - $languageCode = $user->kirby()->defaultLanguage()->code(); - } else { - $languageCode = null; - } + // always create users in the default language + if ($user->kirby()->multilang() === true) { + $languageCode = $user->kirby()->defaultLanguage()->code(); + } else { + $languageCode = null; + } - // add the user to users collection - $user->kirby()->users()->add($user); + // add the user to users collection + $user->kirby()->users()->add($user); - // write the user data - return $user->save($user->content()->toArray(), $languageCode); - }); - } + // write the user data + return $user->save($user->content()->toArray(), $languageCode); + }); + } - /** - * Returns a random user id - * - * @return string - */ - public function createId(): string - { - $length = 8; + /** + * Returns a random user id + * + * @return string + */ + public function createId(): string + { + $length = 8; - do { - try { - $id = Str::random($length); - if (UserRules::validId($this, $id) === true) { - return $id; - } + do { + try { + $id = Str::random($length); + if (UserRules::validId($this, $id) === true) { + return $id; + } - // we can't really test for a random match - // @codeCoverageIgnoreStart - } catch (Throwable $e) { - $length++; - } - } while (true); - // @codeCoverageIgnoreEnd - } + // we can't really test for a random match + // @codeCoverageIgnoreStart + } catch (Throwable $e) { + $length++; + } + } while (true); + // @codeCoverageIgnoreEnd + } - /** - * Deletes the user - * - * @return bool - * @throws \Kirby\Exception\LogicException - */ - public function delete(): bool - { - return $this->commit('delete', ['user' => $this], function ($user) { - if ($user->exists() === false) { - return true; - } + /** + * Deletes the user + * + * @return bool + * @throws \Kirby\Exception\LogicException + */ + public function delete(): bool + { + return $this->commit('delete', ['user' => $this], function ($user) { + if ($user->exists() === false) { + return true; + } - // delete all public assets for this user - Dir::remove($user->mediaRoot()); + // delete all public assets for this user + Dir::remove($user->mediaRoot()); - // delete the user directory - if (Dir::remove($user->root()) !== true) { - throw new LogicException('The user directory for "' . $user->email() . '" could not be deleted'); - } + // delete the user directory + if (Dir::remove($user->root()) !== true) { + throw new LogicException('The user directory for "' . $user->email() . '" could not be deleted'); + } - // remove the user from users collection - $user->kirby()->users()->remove($user); + // remove the user from users collection + $user->kirby()->users()->remove($user); - return true; - }); - } + return true; + }); + } - /** - * Read the account information from disk - * - * @return array - */ - protected function readCredentials(): array - { - $path = $this->root() . '/index.php'; + /** + * Read the account information from disk + * + * @return array + */ + protected function readCredentials(): array + { + $path = $this->root() . '/index.php'; - if (is_file($path) === true) { - $credentials = F::load($path); + if (is_file($path) === true) { + $credentials = F::load($path); - return is_array($credentials) === false ? [] : $credentials; - } else { - return []; - } - } + return is_array($credentials) === false ? [] : $credentials; + } else { + return []; + } + } - /** - * Reads the user password from disk - * - * @return string|false - */ - protected function readPassword() - { - return F::read($this->root() . '/.htpasswd'); - } + /** + * Reads the user password from disk + * + * @return string|false + */ + protected function readPassword() + { + return F::read($this->root() . '/.htpasswd'); + } - /** - * Updates the user data - * - * @param array|null $input - * @param string|null $languageCode - * @param bool $validate - * @return static - */ - public function update(array $input = null, string $languageCode = null, bool $validate = false) - { - $user = parent::update($input, $languageCode, $validate); + /** + * Updates the user data + * + * @param array|null $input + * @param string|null $languageCode + * @param bool $validate + * @return static + */ + public function update(array $input = null, string $languageCode = null, bool $validate = false) + { + $user = parent::update($input, $languageCode, $validate); - // set auth user data only if the current user is this user - if ($user->isLoggedIn() === true) { - $this->kirby()->auth()->setUser($user); - } + // set auth user data only if the current user is this user + if ($user->isLoggedIn() === true) { + $this->kirby()->auth()->setUser($user); + } - // update the users collection - $user->kirby()->users()->set($user->id(), $user); + // update the users collection + $user->kirby()->users()->set($user->id(), $user); - return $user; - } + return $user; + } - /** - * This always merges the existing credentials - * with the given input. - * - * @param array $credentials - * @return bool - */ - protected function updateCredentials(array $credentials): bool - { - // normalize the email address - if (isset($credentials['email']) === true) { - $credentials['email'] = Str::lower(trim($credentials['email'])); - } + /** + * This always merges the existing credentials + * with the given input. + * + * @param array $credentials + * @return bool + */ + protected function updateCredentials(array $credentials): bool + { + // normalize the email address + if (isset($credentials['email']) === true) { + $credentials['email'] = Str::lower(trim($credentials['email'])); + } - return $this->writeCredentials(array_merge($this->credentials(), $credentials)); - } + return $this->writeCredentials(array_merge($this->credentials(), $credentials)); + } - /** - * Writes the account information to disk - * - * @param array $credentials - * @return bool - */ - protected function writeCredentials(array $credentials): bool - { - return Data::write($this->root() . '/index.php', $credentials); - } + /** + * Writes the account information to disk + * + * @param array $credentials + * @return bool + */ + protected function writeCredentials(array $credentials): bool + { + return Data::write($this->root() . '/index.php', $credentials); + } - /** - * Writes the password to disk - * - * @param string|null $password - * @return bool - */ - protected function writePassword(string $password = null): bool - { - return F::write($this->root() . '/.htpasswd', $password); - } + /** + * Writes the password to disk + * + * @param string|null $password + * @return bool + */ + protected function writePassword(string $password = null): bool + { + return F::write($this->root() . '/.htpasswd', $password); + } } diff --git a/kirby/src/Cms/UserBlueprint.php b/kirby/src/Cms/UserBlueprint.php index 73c0bf8..0f86fe1 100755 --- a/kirby/src/Cms/UserBlueprint.php +++ b/kirby/src/Cms/UserBlueprint.php @@ -14,34 +14,34 @@ namespace Kirby\Cms; */ class UserBlueprint extends Blueprint { - /** - * UserBlueprint constructor. - * - * @param array $props - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function __construct(array $props) - { - // normalize and translate the description - $props['description'] = $this->i18n($props['description'] ?? null); + /** + * UserBlueprint constructor. + * + * @param array $props + * @throws \Kirby\Exception\InvalidArgumentException + */ + public function __construct(array $props) + { + // normalize and translate the description + $props['description'] = $this->i18n($props['description'] ?? null); - // register the other props - parent::__construct($props); + // register the other props + parent::__construct($props); - // normalize all available page options - $this->props['options'] = $this->normalizeOptions( - $this->props['options'] ?? true, - // defaults - [ - 'create' => null, - 'changeEmail' => null, - 'changeLanguage' => null, - 'changeName' => null, - 'changePassword' => null, - 'changeRole' => null, - 'delete' => null, - 'update' => null, - ] - ); - } + // normalize all available page options + $this->props['options'] = $this->normalizeOptions( + $this->props['options'] ?? true, + // defaults + [ + 'create' => null, + 'changeEmail' => null, + 'changeLanguage' => null, + 'changeName' => null, + 'changePassword' => null, + 'changeRole' => null, + 'delete' => null, + 'update' => null, + ] + ); + } } diff --git a/kirby/src/Cms/UserPermissions.php b/kirby/src/Cms/UserPermissions.php index 34e0176..bc91161 100755 --- a/kirby/src/Cms/UserPermissions.php +++ b/kirby/src/Cms/UserPermissions.php @@ -13,55 +13,55 @@ namespace Kirby\Cms; */ class UserPermissions extends ModelPermissions { - /** - * @var string - */ - protected $category = 'users'; + /** + * @var string + */ + protected $category = 'users'; - /** - * UserPermissions constructor - * - * @param \Kirby\Cms\Model $model - */ - public function __construct(Model $model) - { - parent::__construct($model); + /** + * UserPermissions constructor + * + * @param \Kirby\Cms\Model $model + */ + public function __construct(Model $model) + { + parent::__construct($model); - // change the scope of the permissions, when the current user is this user - $this->category = $this->user && $this->user->is($model) ? 'user' : 'users'; - } + // change the scope of the permissions, when the current user is this user + $this->category = $this->user && $this->user->is($model) ? 'user' : 'users'; + } - /** - * @return bool - */ - protected function canChangeRole(): bool - { - return $this->model->roles()->count() > 1; - } + /** + * @return bool + */ + protected function canChangeRole(): bool + { + return $this->model->roles()->count() > 1; + } - /** - * @return bool - */ - protected function canCreate(): bool - { - // the admin can always create new users - if ($this->user->isAdmin() === true) { - return true; - } + /** + * @return bool + */ + protected function canCreate(): bool + { + // the admin can always create new users + if ($this->user->isAdmin() === true) { + return true; + } - // users who are not admins cannot create admins - if ($this->model->isAdmin() === true) { - return false; - } + // users who are not admins cannot create admins + if ($this->model->isAdmin() === true) { + return false; + } - return true; - } + return true; + } - /** - * @return bool - */ - protected function canDelete(): bool - { - return $this->model->isLastAdmin() !== true; - } + /** + * @return bool + */ + protected function canDelete(): bool + { + return $this->model->isLastAdmin() !== true; + } } diff --git a/kirby/src/Cms/UserPicker.php b/kirby/src/Cms/UserPicker.php index f4c01ec..46da3dc 100755 --- a/kirby/src/Cms/UserPicker.php +++ b/kirby/src/Cms/UserPicker.php @@ -17,53 +17,53 @@ use Kirby\Exception\InvalidArgumentException; */ class UserPicker extends Picker { - /** - * Extends the basic defaults - * - * @return array - */ - public function defaults(): array - { - $defaults = parent::defaults(); - $defaults['text'] = '{{ user.username }}'; + /** + * Extends the basic defaults + * + * @return array + */ + public function defaults(): array + { + $defaults = parent::defaults(); + $defaults['text'] = '{{ user.username }}'; - return $defaults; - } + return $defaults; + } - /** - * Search all users for the picker - * - * @return \Kirby\Cms\Users|null - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function items() - { - $model = $this->options['model']; + /** + * Search all users for the picker + * + * @return \Kirby\Cms\Users|null + * @throws \Kirby\Exception\InvalidArgumentException + */ + public function items() + { + $model = $this->options['model']; - // find the right default query - if (empty($this->options['query']) === false) { - $query = $this->options['query']; - } elseif (is_a($model, 'Kirby\Cms\User') === true) { - $query = 'user.siblings'; - } else { - $query = 'kirby.users'; - } + // find the right default query + if (empty($this->options['query']) === false) { + $query = $this->options['query']; + } elseif (is_a($model, 'Kirby\Cms\User') === true) { + $query = 'user.siblings'; + } else { + $query = 'kirby.users'; + } - // fetch all users for the picker - $users = $model->query($query); + // fetch all users for the picker + $users = $model->query($query); - // catch invalid data - if (is_a($users, 'Kirby\Cms\Users') === false) { - throw new InvalidArgumentException('Your query must return a set of users'); - } + // catch invalid data + if (is_a($users, 'Kirby\Cms\Users') === false) { + throw new InvalidArgumentException('Your query must return a set of users'); + } - // search - $users = $this->search($users); + // search + $users = $this->search($users); - // sort - $users = $users->sort('username', 'asc'); + // sort + $users = $users->sort('username', 'asc'); - // paginate - return $this->paginate($users); - } + // paginate + return $this->paginate($users); + } } diff --git a/kirby/src/Cms/UserRules.php b/kirby/src/Cms/UserRules.php index 34d554b..fa740fa 100755 --- a/kirby/src/Cms/UserRules.php +++ b/kirby/src/Cms/UserRules.php @@ -20,350 +20,350 @@ use Kirby\Toolkit\V; */ class UserRules { - /** - * Validates if the email address can be changed - * - * @param \Kirby\Cms\User $user - * @param string $email - * @return bool - * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the address - */ - public static function changeEmail(User $user, string $email): bool - { - if ($user->permissions()->changeEmail() !== true) { - throw new PermissionException([ - 'key' => 'user.changeEmail.permission', - 'data' => ['name' => $user->username()] - ]); - } + /** + * Validates if the email address can be changed + * + * @param \Kirby\Cms\User $user + * @param string $email + * @return bool + * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the address + */ + public static function changeEmail(User $user, string $email): bool + { + if ($user->permissions()->changeEmail() !== true) { + throw new PermissionException([ + 'key' => 'user.changeEmail.permission', + 'data' => ['name' => $user->username()] + ]); + } - return static::validEmail($user, $email); - } + return static::validEmail($user, $email); + } - /** - * Validates if the language can be changed - * - * @param \Kirby\Cms\User $user - * @param string $language - * @return bool - * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the language - */ - public static function changeLanguage(User $user, string $language): bool - { - if ($user->permissions()->changeLanguage() !== true) { - throw new PermissionException([ - 'key' => 'user.changeLanguage.permission', - 'data' => ['name' => $user->username()] - ]); - } + /** + * Validates if the language can be changed + * + * @param \Kirby\Cms\User $user + * @param string $language + * @return bool + * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the language + */ + public static function changeLanguage(User $user, string $language): bool + { + if ($user->permissions()->changeLanguage() !== true) { + throw new PermissionException([ + 'key' => 'user.changeLanguage.permission', + 'data' => ['name' => $user->username()] + ]); + } - return static::validLanguage($user, $language); - } + return static::validLanguage($user, $language); + } - /** - * Validates if the name can be changed - * - * @param \Kirby\Cms\User $user - * @param string $name - * @return bool - * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the name - */ - public static function changeName(User $user, string $name): bool - { - if ($user->permissions()->changeName() !== true) { - throw new PermissionException([ - 'key' => 'user.changeName.permission', - 'data' => ['name' => $user->username()] - ]); - } + /** + * Validates if the name can be changed + * + * @param \Kirby\Cms\User $user + * @param string $name + * @return bool + * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the name + */ + public static function changeName(User $user, string $name): bool + { + if ($user->permissions()->changeName() !== true) { + throw new PermissionException([ + 'key' => 'user.changeName.permission', + 'data' => ['name' => $user->username()] + ]); + } - return true; - } + return true; + } - /** - * Validates if the password can be changed - * - * @param \Kirby\Cms\User $user - * @param string $password - * @return bool - * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the password - */ - public static function changePassword(User $user, string $password): bool - { - if ($user->permissions()->changePassword() !== true) { - throw new PermissionException([ - 'key' => 'user.changePassword.permission', - 'data' => ['name' => $user->username()] - ]); - } + /** + * Validates if the password can be changed + * + * @param \Kirby\Cms\User $user + * @param string $password + * @return bool + * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the password + */ + public static function changePassword(User $user, string $password): bool + { + if ($user->permissions()->changePassword() !== true) { + throw new PermissionException([ + 'key' => 'user.changePassword.permission', + 'data' => ['name' => $user->username()] + ]); + } - return static::validPassword($user, $password); - } + return static::validPassword($user, $password); + } - /** - * Validates if the role can be changed - * - * @param \Kirby\Cms\User $user - * @param string $role - * @return bool - * @throws \Kirby\Exception\LogicException If the user is the last admin - * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the role - */ - public static function changeRole(User $user, string $role): bool - { - // protect admin from role changes by non-admin - if ( - $user->kirby()->user()->isAdmin() === false && - $user->isAdmin() === true - ) { - throw new PermissionException([ - 'key' => 'user.changeRole.permission', - 'data' => ['name' => $user->username()] - ]); - } + /** + * Validates if the role can be changed + * + * @param \Kirby\Cms\User $user + * @param string $role + * @return bool + * @throws \Kirby\Exception\LogicException If the user is the last admin + * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the role + */ + public static function changeRole(User $user, string $role): bool + { + // protect admin from role changes by non-admin + if ( + $user->kirby()->user()->isAdmin() === false && + $user->isAdmin() === true + ) { + throw new PermissionException([ + 'key' => 'user.changeRole.permission', + 'data' => ['name' => $user->username()] + ]); + } - // prevent non-admins making a user to admin - if ( - $user->kirby()->user()->isAdmin() === false && - $role === 'admin' - ) { - throw new PermissionException([ - 'key' => 'user.changeRole.toAdmin' - ]); - } + // prevent non-admins making a user to admin + if ( + $user->kirby()->user()->isAdmin() === false && + $role === 'admin' + ) { + throw new PermissionException([ + 'key' => 'user.changeRole.toAdmin' + ]); + } - static::validRole($user, $role); + static::validRole($user, $role); - if ($role !== 'admin' && $user->isLastAdmin() === true) { - throw new LogicException([ - 'key' => 'user.changeRole.lastAdmin', - 'data' => ['name' => $user->username()] - ]); - } + if ($role !== 'admin' && $user->isLastAdmin() === true) { + throw new LogicException([ + 'key' => 'user.changeRole.lastAdmin', + 'data' => ['name' => $user->username()] + ]); + } - if ($user->permissions()->changeRole() !== true) { - throw new PermissionException([ - 'key' => 'user.changeRole.permission', - 'data' => ['name' => $user->username()] - ]); - } + if ($user->permissions()->changeRole() !== true) { + throw new PermissionException([ + 'key' => 'user.changeRole.permission', + 'data' => ['name' => $user->username()] + ]); + } - return true; - } + return true; + } - /** - * Validates if the user can be created - * - * @param \Kirby\Cms\User $user - * @param array $props - * @return bool - * @throws \Kirby\Exception\PermissionException If the user is not allowed to create a new user - */ - public static function create(User $user, array $props = []): bool - { - static::validId($user, $user->id()); - static::validEmail($user, $user->email(), true); - static::validLanguage($user, $user->language()); + /** + * Validates if the user can be created + * + * @param \Kirby\Cms\User $user + * @param array $props + * @return bool + * @throws \Kirby\Exception\PermissionException If the user is not allowed to create a new user + */ + public static function create(User $user, array $props = []): bool + { + static::validId($user, $user->id()); + static::validEmail($user, $user->email(), true); + static::validLanguage($user, $user->language()); - // the first user must have a password - if ($user->kirby()->users()->count() === 0 && empty($props['password'])) { - // trigger invalid password error - static::validPassword($user, ' '); - } + // the first user must have a password + if ($user->kirby()->users()->count() === 0 && empty($props['password'])) { + // trigger invalid password error + static::validPassword($user, ' '); + } - if (empty($props['password']) === false) { - static::validPassword($user, $props['password']); - } + if (empty($props['password']) === false) { + static::validPassword($user, $props['password']); + } - // get the current user if it exists - $currentUser = $user->kirby()->user(); + // get the current user if it exists + $currentUser = $user->kirby()->user(); - // admins are allowed everything - if ($currentUser && $currentUser->isAdmin() === true) { - return true; - } + // admins are allowed everything + if ($currentUser && $currentUser->isAdmin() === true) { + return true; + } - // only admins are allowed to add admins - $role = $props['role'] ?? null; + // only admins are allowed to add admins + $role = $props['role'] ?? null; - if ($role === 'admin' && $currentUser && $currentUser->isAdmin() === false) { - throw new PermissionException([ - 'key' => 'user.create.permission' - ]); - } + if ($role === 'admin' && $currentUser && $currentUser->isAdmin() === false) { + throw new PermissionException([ + 'key' => 'user.create.permission' + ]); + } - // check user permissions (if not on install) - if ($user->kirby()->users()->count() > 0) { - if ($user->permissions()->create() !== true) { - throw new PermissionException([ - 'key' => 'user.create.permission' - ]); - } - } + // check user permissions (if not on install) + if ($user->kirby()->users()->count() > 0) { + if ($user->permissions()->create() !== true) { + throw new PermissionException([ + 'key' => 'user.create.permission' + ]); + } + } - return true; - } + return true; + } - /** - * Validates if the user can be deleted - * - * @param \Kirby\Cms\User $user - * @return bool - * @throws \Kirby\Exception\LogicException If this is the last user or last admin, which cannot be deleted - * @throws \Kirby\Exception\PermissionException If the user is not allowed to delete this user - */ - public static function delete(User $user): bool - { - if ($user->isLastAdmin() === true) { - throw new LogicException(['key' => 'user.delete.lastAdmin']); - } + /** + * Validates if the user can be deleted + * + * @param \Kirby\Cms\User $user + * @return bool + * @throws \Kirby\Exception\LogicException If this is the last user or last admin, which cannot be deleted + * @throws \Kirby\Exception\PermissionException If the user is not allowed to delete this user + */ + public static function delete(User $user): bool + { + if ($user->isLastAdmin() === true) { + throw new LogicException(['key' => 'user.delete.lastAdmin']); + } - if ($user->isLastUser() === true) { - throw new LogicException([ - 'key' => 'user.delete.lastUser' - ]); - } + if ($user->isLastUser() === true) { + throw new LogicException([ + 'key' => 'user.delete.lastUser' + ]); + } - if ($user->permissions()->delete() !== true) { - throw new PermissionException([ - 'key' => 'user.delete.permission', - 'data' => ['name' => $user->username()] - ]); - } + if ($user->permissions()->delete() !== true) { + throw new PermissionException([ + 'key' => 'user.delete.permission', + 'data' => ['name' => $user->username()] + ]); + } - return true; - } + return true; + } - /** - * Validates if the user can be updated - * - * @param \Kirby\Cms\User $user - * @param array $values - * @param array $strings - * @return bool - * @throws \Kirby\Exception\PermissionException If the user it not allowed to update this user - */ - public static function update(User $user, array $values = [], array $strings = []): bool - { - if ($user->permissions()->update() !== true) { - throw new PermissionException([ - 'key' => 'user.update.permission', - 'data' => ['name' => $user->username()] - ]); - } + /** + * Validates if the user can be updated + * + * @param \Kirby\Cms\User $user + * @param array $values + * @param array $strings + * @return bool + * @throws \Kirby\Exception\PermissionException If the user it not allowed to update this user + */ + public static function update(User $user, array $values = [], array $strings = []): bool + { + if ($user->permissions()->update() !== true) { + throw new PermissionException([ + 'key' => 'user.update.permission', + 'data' => ['name' => $user->username()] + ]); + } - return true; - } + return true; + } - /** - * Validates an email address - * - * @param \Kirby\Cms\User $user - * @param string $email - * @param bool $strict - * @return bool - * @throws \Kirby\Exception\DuplicateException If the email address already exists - * @throws \Kirby\Exception\InvalidArgumentException If the email address is invalid - */ - public static function validEmail(User $user, string $email, bool $strict = false): bool - { - if (V::email($email ?? null) === false) { - throw new InvalidArgumentException([ - 'key' => 'user.email.invalid', - ]); - } + /** + * Validates an email address + * + * @param \Kirby\Cms\User $user + * @param string $email + * @param bool $strict + * @return bool + * @throws \Kirby\Exception\DuplicateException If the email address already exists + * @throws \Kirby\Exception\InvalidArgumentException If the email address is invalid + */ + public static function validEmail(User $user, string $email, bool $strict = false): bool + { + if (V::email($email ?? null) === false) { + throw new InvalidArgumentException([ + 'key' => 'user.email.invalid', + ]); + } - if ($strict === true) { - $duplicate = $user->kirby()->users()->find($email); - } else { - $duplicate = $user->kirby()->users()->not($user)->find($email); - } + if ($strict === true) { + $duplicate = $user->kirby()->users()->find($email); + } else { + $duplicate = $user->kirby()->users()->not($user)->find($email); + } - if ($duplicate) { - throw new DuplicateException([ - 'key' => 'user.duplicate', - 'data' => ['email' => $email] - ]); - } + if ($duplicate) { + throw new DuplicateException([ + 'key' => 'user.duplicate', + 'data' => ['email' => $email] + ]); + } - return true; - } + return true; + } - /** - * Validates a user id - * - * @param \Kirby\Cms\User $user - * @param string $id - * @return bool - * @throws \Kirby\Exception\DuplicateException If the user already exists - */ - public static function validId(User $user, string $id): bool - { - if ($id === 'account') { - throw new InvalidArgumentException('"account" is a reserved word and cannot be used as user id'); - } + /** + * Validates a user id + * + * @param \Kirby\Cms\User $user + * @param string $id + * @return bool + * @throws \Kirby\Exception\DuplicateException If the user already exists + */ + public static function validId(User $user, string $id): bool + { + if ($id === 'account') { + throw new InvalidArgumentException('"account" is a reserved word and cannot be used as user id'); + } - if ($user->kirby()->users()->find($id)) { - throw new DuplicateException('A user with this id exists'); - } + if ($user->kirby()->users()->find($id)) { + throw new DuplicateException('A user with this id exists'); + } - return true; - } + return true; + } - /** - * Validates a user language code - * - * @param \Kirby\Cms\User $user - * @param string $language - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException If the language does not exist - */ - public static function validLanguage(User $user, string $language): bool - { - if (in_array($language, $user->kirby()->translations()->keys(), true) === false) { - throw new InvalidArgumentException([ - 'key' => 'user.language.invalid', - ]); - } + /** + * Validates a user language code + * + * @param \Kirby\Cms\User $user + * @param string $language + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException If the language does not exist + */ + public static function validLanguage(User $user, string $language): bool + { + if (in_array($language, $user->kirby()->translations()->keys(), true) === false) { + throw new InvalidArgumentException([ + 'key' => 'user.language.invalid', + ]); + } - return true; - } + return true; + } - /** - * Validates a password - * - * @param \Kirby\Cms\User $user - * @param string $password - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException If the password is too short - */ - public static function validPassword(User $user, string $password): bool - { - if (Str::length($password ?? null) < 8) { - throw new InvalidArgumentException([ - 'key' => 'user.password.invalid', - ]); - } + /** + * Validates a password + * + * @param \Kirby\Cms\User $user + * @param string $password + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException If the password is too short + */ + public static function validPassword(User $user, string $password): bool + { + if (Str::length($password ?? null) < 8) { + throw new InvalidArgumentException([ + 'key' => 'user.password.invalid', + ]); + } - return true; - } + return true; + } - /** - * Validates a user role - * - * @param \Kirby\Cms\User $user - * @param string $role - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException If the user role does not exist - */ - public static function validRole(User $user, string $role): bool - { - if (is_a($user->kirby()->roles()->find($role), 'Kirby\Cms\Role') === true) { - return true; - } + /** + * Validates a user role + * + * @param \Kirby\Cms\User $user + * @param string $role + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException If the user role does not exist + */ + public static function validRole(User $user, string $role): bool + { + if (is_a($user->kirby()->roles()->find($role), 'Kirby\Cms\Role') === true) { + return true; + } - throw new InvalidArgumentException([ - 'key' => 'user.role.invalid', - ]); - } + throw new InvalidArgumentException([ + 'key' => 'user.role.invalid', + ]); + } } diff --git a/kirby/src/Cms/Users.php b/kirby/src/Cms/Users.php index ec0da33..055863c 100755 --- a/kirby/src/Cms/Users.php +++ b/kirby/src/Cms/Users.php @@ -21,128 +21,128 @@ use Kirby\Toolkit\Str; */ class Users extends Collection { - /** - * All registered users methods - * - * @var array - */ - public static $methods = []; + /** + * All registered users methods + * + * @var array + */ + public static $methods = []; - public function create(array $data) - { - return User::create($data); - } + public function create(array $data) + { + return User::create($data); + } - /** - * Adds a single user or - * an entire second collection to the - * current collection - * - * @param \Kirby\Cms\Users|\Kirby\Cms\User|string $object - * @return $this - * @throws \Kirby\Exception\InvalidArgumentException When no `User` or `Users` object or an ID of an existing user is passed - */ - public function add($object) - { - // add a users collection - if (is_a($object, self::class) === true) { - $this->data = array_merge($this->data, $object->data); + /** + * Adds a single user or + * an entire second collection to the + * current collection + * + * @param \Kirby\Cms\Users|\Kirby\Cms\User|string $object + * @return $this + * @throws \Kirby\Exception\InvalidArgumentException When no `User` or `Users` object or an ID of an existing user is passed + */ + public function add($object) + { + // add a users collection + if (is_a($object, self::class) === true) { + $this->data = array_merge($this->data, $object->data); - // add a user by id - } elseif (is_string($object) === true && $user = App::instance()->user($object)) { - $this->__set($user->id(), $user); + // add a user by id + } elseif (is_string($object) === true && $user = App::instance()->user($object)) { + $this->__set($user->id(), $user); - // add a user object - } elseif (is_a($object, 'Kirby\Cms\User') === true) { - $this->__set($object->id(), $object); + // add a user object + } elseif (is_a($object, 'Kirby\Cms\User') === true) { + $this->__set($object->id(), $object); - // give a useful error message on invalid input; - // silently ignore "empty" values for compatibility with existing setups - } elseif (in_array($object, [null, false, true], true) !== true) { - throw new InvalidArgumentException('You must pass a Users or User object or an ID of an existing user to the Users collection'); - } + // give a useful error message on invalid input; + // silently ignore "empty" values for compatibility with existing setups + } elseif (in_array($object, [null, false, true], true) !== true) { + throw new InvalidArgumentException('You must pass a Users or User object or an ID of an existing user to the Users collection'); + } - return $this; - } + return $this; + } - /** - * Takes an array of user props and creates a nice and clean user collection from it - * - * @param array $users - * @param array $inject - * @return static - */ - public static function factory(array $users, array $inject = []) - { - $collection = new static(); + /** + * Takes an array of user props and creates a nice and clean user collection from it + * + * @param array $users + * @param array $inject + * @return static + */ + public static function factory(array $users, array $inject = []) + { + $collection = new static(); - // read all user blueprints - foreach ($users as $props) { - $user = User::factory($props + $inject); - $collection->set($user->id(), $user); - } + // read all user blueprints + foreach ($users as $props) { + $user = User::factory($props + $inject); + $collection->set($user->id(), $user); + } - return $collection; - } + return $collection; + } - /** - * Finds a user in the collection by ID or email address - * @internal Use `$users->find()` instead - * - * @param string $key - * @return \Kirby\Cms\User|null - */ - public function findByKey(string $key) - { - if (Str::contains($key, '@') === true) { - return parent::findBy('email', Str::lower($key)); - } + /** + * Finds a user in the collection by ID or email address + * @internal Use `$users->find()` instead + * + * @param string $key + * @return \Kirby\Cms\User|null + */ + public function findByKey(string $key) + { + if (Str::contains($key, '@') === true) { + return parent::findBy('email', Str::lower($key)); + } - return parent::findByKey($key); - } + return parent::findByKey($key); + } - /** - * Loads a user from disk by passing the absolute path (root) - * - * @param string $root - * @param array $inject - * @return static - */ - public static function load(string $root, array $inject = []) - { - $users = new static(); + /** + * Loads a user from disk by passing the absolute path (root) + * + * @param string $root + * @param array $inject + * @return static + */ + public static function load(string $root, array $inject = []) + { + $users = new static(); - foreach (Dir::read($root) as $userDirectory) { - if (is_dir($root . '/' . $userDirectory) === false) { - continue; - } + foreach (Dir::read($root) as $userDirectory) { + if (is_dir($root . '/' . $userDirectory) === false) { + continue; + } - // get role information - $path = $root . '/' . $userDirectory . '/index.php'; - if (is_file($path) === true) { - $credentials = F::load($path); - } + // get role information + $path = $root . '/' . $userDirectory . '/index.php'; + if (is_file($path) === true) { + $credentials = F::load($path); + } - // create user model based on role - $user = User::factory([ - 'id' => $userDirectory, - 'model' => $credentials['role'] ?? null - ] + $inject); + // create user model based on role + $user = User::factory([ + 'id' => $userDirectory, + 'model' => $credentials['role'] ?? null + ] + $inject); - $users->set($user->id(), $user); - } + $users->set($user->id(), $user); + } - return $users; - } + return $users; + } - /** - * Shortcut for `$users->filter('role', 'admin')` - * - * @param string $role - * @return static - */ - public function role(string $role) - { - return $this->filter('role', $role); - } + /** + * Shortcut for `$users->filter('role', 'admin')` + * + * @param string $role + * @return static + */ + public function role(string $role) + { + return $this->filter('role', $role); + } } diff --git a/kirby/src/Cms/Visitor.php b/kirby/src/Cms/Visitor.php index 44db05c..eae9f3a 100755 --- a/kirby/src/Cms/Visitor.php +++ b/kirby/src/Cms/Visitor.php @@ -15,11 +15,11 @@ use Kirby\Toolkit\Facade; */ class Visitor extends Facade { - /** - * @return \Kirby\Http\Visitor - */ - public static function instance() - { - return App::instance()->visitor(); - } + /** + * @return \Kirby\Http\Visitor + */ + public static function instance() + { + return App::instance()->visitor(); + } } diff --git a/kirby/src/Data/Data.php b/kirby/src/Data/Data.php index 767c972..3c69e32 100755 --- a/kirby/src/Data/Data.php +++ b/kirby/src/Data/Data.php @@ -24,104 +24,104 @@ use Kirby\Filesystem\F; */ class Data { - /** - * Handler Type Aliases - * - * @var array - */ - public static $aliases = [ - 'md' => 'txt', - 'mdown' => 'txt', - 'rss' => 'xml', - 'yml' => 'yaml', - ]; + /** + * Handler Type Aliases + * + * @var array + */ + public static $aliases = [ + 'md' => 'txt', + 'mdown' => 'txt', + 'rss' => 'xml', + 'yml' => 'yaml', + ]; - /** - * All registered handlers - * - * @var array - */ - public static $handlers = [ - 'json' => 'Kirby\Data\Json', - 'php' => 'Kirby\Data\PHP', - 'txt' => 'Kirby\Data\Txt', - 'xml' => 'Kirby\Data\Xml', - 'yaml' => 'Kirby\Data\Yaml', - ]; + /** + * All registered handlers + * + * @var array + */ + public static $handlers = [ + 'json' => 'Kirby\Data\Json', + 'php' => 'Kirby\Data\PHP', + 'txt' => 'Kirby\Data\Txt', + 'xml' => 'Kirby\Data\Xml', + 'yaml' => 'Kirby\Data\Yaml', + ]; - /** - * Handler getter - * - * @param string $type - * @return \Kirby\Data\Handler - */ - public static function handler(string $type) - { - // normalize the type - $type = strtolower($type); + /** + * Handler getter + * + * @param string $type + * @return \Kirby\Data\Handler + */ + public static function handler(string $type) + { + // normalize the type + $type = strtolower($type); - // find a handler or alias - $handler = static::$handlers[$type] ?? - static::$handlers[static::$aliases[$type] ?? null] ?? - null; + // find a handler or alias + $handler = static::$handlers[$type] ?? + static::$handlers[static::$aliases[$type] ?? null] ?? + null; - if ($handler !== null && class_exists($handler)) { - return new $handler(); - } + if ($handler !== null && class_exists($handler)) { + return new $handler(); + } - throw new Exception('Missing handler for type: "' . $type . '"'); - } + throw new Exception('Missing handler for type: "' . $type . '"'); + } - /** - * Decodes data with the specified handler - * - * @param mixed $string - * @param string $type - * @return array - */ - public static function decode($string, string $type): array - { - return static::handler($type)->decode($string); - } + /** + * Decodes data with the specified handler + * + * @param mixed $string + * @param string $type + * @return array + */ + public static function decode($string, string $type): array + { + return static::handler($type)->decode($string); + } - /** - * Encodes data with the specified handler - * - * @param mixed $data - * @param string $type - * @return string - */ - public static function encode($data, string $type): string - { - return static::handler($type)->encode($data); - } + /** + * Encodes data with the specified handler + * + * @param mixed $data + * @param string $type + * @return string + */ + public static function encode($data, string $type): string + { + return static::handler($type)->encode($data); + } - /** - * Reads data from a file; - * the data handler is automatically chosen by - * the extension if not specified - * - * @param string $file - * @param string $type - * @return array - */ - public static function read(string $file, string $type = null): array - { - return static::handler($type ?? F::extension($file))->read($file); - } + /** + * Reads data from a file; + * the data handler is automatically chosen by + * the extension if not specified + * + * @param string $file + * @param string $type + * @return array + */ + public static function read(string $file, string $type = null): array + { + return static::handler($type ?? F::extension($file))->read($file); + } - /** - * Writes data to a file; - * the data handler is automatically chosen by - * the extension if not specified - * - * @param string $file - * @param mixed $data - * @param string $type - * @return bool - */ - public static function write(string $file = null, $data = [], string $type = null): bool - { - return static::handler($type ?? F::extension($file))->write($file, $data); - } + /** + * Writes data to a file; + * the data handler is automatically chosen by + * the extension if not specified + * + * @param string $file + * @param mixed $data + * @param string $type + * @return bool + */ + public static function write(string $file = null, $data = [], string $type = null): bool + { + return static::handler($type ?? F::extension($file))->write($file, $data); + } } diff --git a/kirby/src/Data/Handler.php b/kirby/src/Data/Handler.php index 5b65e24..9c511f8 100755 --- a/kirby/src/Data/Handler.php +++ b/kirby/src/Data/Handler.php @@ -18,49 +18,49 @@ use Kirby\Filesystem\F; */ abstract class Handler { - /** - * Parses an encoded string and returns a multi-dimensional array - * - * Needs to throw an Exception if the file can't be parsed. - * - * @param mixed $string - * @return array - */ - abstract public static function decode($string): array; + /** + * Parses an encoded string and returns a multi-dimensional array + * + * Needs to throw an Exception if the file can't be parsed. + * + * @param mixed $string + * @return array + */ + abstract public static function decode($string): array; - /** - * Converts an array to an encoded string - * - * @param mixed $data - * @return string - */ - abstract public static function encode($data): string; + /** + * Converts an array to an encoded string + * + * @param mixed $data + * @return string + */ + abstract public static function encode($data): string; - /** - * Reads data from a file - * - * @param string $file - * @return array - */ - public static function read(string $file): array - { - $contents = F::read($file); - if ($contents === false) { - throw new Exception('The file "' . $file . '" does not exist'); - } + /** + * Reads data from a file + * + * @param string $file + * @return array + */ + public static function read(string $file): array + { + $contents = F::read($file); + if ($contents === false) { + throw new Exception('The file "' . $file . '" does not exist'); + } - return static::decode($contents); - } + return static::decode($contents); + } - /** - * Writes data to a file - * - * @param string $file - * @param mixed $data - * @return bool - */ - public static function write(string $file = null, $data = []): bool - { - return F::write($file, static::encode($data)); - } + /** + * Writes data to a file + * + * @param string $file + * @param mixed $data + * @return bool + */ + public static function write(string $file = null, $data = []): bool + { + return F::write($file, static::encode($data)); + } } diff --git a/kirby/src/Data/Json.php b/kirby/src/Data/Json.php index 00dba6b..622636b 100755 --- a/kirby/src/Data/Json.php +++ b/kirby/src/Data/Json.php @@ -15,43 +15,43 @@ use Kirby\Exception\InvalidArgumentException; */ class Json extends Handler { - /** - * Converts an array to an encoded JSON string - * - * @param mixed $data - * @return string - */ - public static function encode($data): string - { - return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); - } + /** + * Converts an array to an encoded JSON string + * + * @param mixed $data + * @return string + */ + public static function encode($data): string + { + return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + } - /** - * Parses an encoded JSON string and returns a multi-dimensional array - * - * @param mixed $string - * @return array - */ - public static function decode($string): array - { - if ($string === null || $string === '') { - return []; - } + /** + * Parses an encoded JSON string and returns a multi-dimensional array + * + * @param mixed $string + * @return array + */ + public static function decode($string): array + { + if ($string === null || $string === '') { + return []; + } - if (is_array($string) === true) { - return $string; - } + if (is_array($string) === true) { + return $string; + } - if (is_string($string) === false) { - throw new InvalidArgumentException('Invalid JSON data; please pass a string'); - } + if (is_string($string) === false) { + throw new InvalidArgumentException('Invalid JSON data; please pass a string'); + } - $result = json_decode($string, true); + $result = json_decode($string, true); - if (is_array($result) === true) { - return $result; - } else { - throw new InvalidArgumentException('JSON string is invalid'); - } - } + if (is_array($result) === true) { + return $result; + } else { + throw new InvalidArgumentException('JSON string is invalid'); + } + } } diff --git a/kirby/src/Data/PHP.php b/kirby/src/Data/PHP.php index 0391b29..ff3106c 100755 --- a/kirby/src/Data/PHP.php +++ b/kirby/src/Data/PHP.php @@ -17,78 +17,78 @@ use Kirby\Filesystem\F; */ class PHP extends Handler { - /** - * Converts an array to PHP file content - * - * @param mixed $data - * @param string $indent For internal use only - * @return string - */ - public static function encode($data, string $indent = ''): string - { - switch (gettype($data)) { - case 'array': - $indexed = array_keys($data) === range(0, count($data) - 1); - $array = []; + /** + * Converts an array to PHP file content + * + * @param mixed $data + * @param string $indent For internal use only + * @return string + */ + public static function encode($data, string $indent = ''): string + { + switch (gettype($data)) { + case 'array': + $indexed = array_keys($data) === range(0, count($data) - 1); + $array = []; - foreach ($data as $key => $value) { - $array[] = "$indent " . ($indexed ? '' : static::encode($key) . ' => ') . static::encode($value, "$indent "); - } + foreach ($data as $key => $value) { + $array[] = "$indent " . ($indexed ? '' : static::encode($key) . ' => ') . static::encode($value, "$indent "); + } - return "[\n" . implode(",\n", $array) . "\n" . $indent . ']'; - case 'boolean': - return $data ? 'true' : 'false'; - case 'integer': - case 'double': - return $data; - default: - return var_export($data, true); - } - } + return "[\n" . implode(",\n", $array) . "\n" . $indent . ']'; + case 'boolean': + return $data ? 'true' : 'false'; + case 'integer': + case 'double': + return $data; + default: + return var_export($data, true); + } + } - /** - * PHP strings shouldn't be decoded manually - * - * @param mixed $string - * @return array - */ - public static function decode($string): array - { - throw new BadMethodCallException('The PHP::decode() method is not implemented'); - } + /** + * PHP strings shouldn't be decoded manually + * + * @param mixed $string + * @return array + */ + public static function decode($string): array + { + throw new BadMethodCallException('The PHP::decode() method is not implemented'); + } - /** - * Reads data from a file - * - * @param string $file - * @return array - */ - public static function read(string $file): array - { - if (is_file($file) !== true) { - throw new Exception('The file "' . $file . '" does not exist'); - } + /** + * Reads data from a file + * + * @param string $file + * @return array + */ + public static function read(string $file): array + { + if (is_file($file) !== true) { + throw new Exception('The file "' . $file . '" does not exist'); + } - return (array)F::load($file, []); - } + return (array)F::load($file, []); + } - /** - * Creates a PHP file with the given data - * - * @param string $file - * @param mixed $data - * @return bool - */ - public static function write(string $file = null, $data = []): bool - { - $php = static::encode($data); - $php = " $value) { - if (empty($key) === true || $value === null) { - continue; - } + foreach (A::wrap($data) as $key => $value) { + if (empty($key) === true || $value === null) { + continue; + } - $key = Str::ucfirst(Str::slug($key)); - $value = static::encodeValue($value); - $result[$key] = static::encodeResult($key, $value); - } + $key = Str::ucfirst(Str::slug($key)); + $value = static::encodeValue($value); + $result[$key] = static::encodeResult($key, $value); + } - return implode("\n\n----\n\n", $result); - } + return implode("\n\n----\n\n", $result); + } - /** - * Helper for converting the value - * - * @param array|string $value - * @return string - */ - protected static function encodeValue($value): string - { - // avoid problems with arrays - if (is_array($value) === true) { - $value = Data::encode($value, 'yaml'); - // avoid problems with localized floats - } elseif (is_float($value) === true) { - $value = Str::float($value); - } + /** + * Helper for converting the value + * + * @param array|string $value + * @return string + */ + protected static function encodeValue($value): string + { + // avoid problems with arrays + if (is_array($value) === true) { + $value = Data::encode($value, 'yaml'); + // avoid problems with localized floats + } elseif (is_float($value) === true) { + $value = Str::float($value); + } - // escape accidental dividers within a field - $value = preg_replace('!(?<=\n|^)----!', '\\----', $value); + // escape accidental dividers within a field + $value = preg_replace('!(?<=\n|^)----!', '\\----', $value); - return $value; - } + return $value; + } - /** - * Helper for converting the key and value to the result string - * - * @param string $key - * @param string $value - * @return string - */ - protected static function encodeResult(string $key, string $value): string - { - $result = $key . ':'; + /** + * Helper for converting the key and value to the result string + * + * @param string $key + * @param string $value + * @return string + */ + protected static function encodeResult(string $key, string $value): string + { + $result = $key . ':'; - // multi-line content - if (preg_match('!\R!', $value) === 1) { - $result .= "\n\n"; - } else { - $result .= ' '; - } + // multi-line content + if (preg_match('!\R!', $value) === 1) { + $result .= "\n\n"; + } else { + $result .= ' '; + } - $result .= trim($value); + $result .= trim($value); - return $result; - } + return $result; + } - /** - * Parses a Kirby txt string and returns a multi-dimensional array - * - * @param mixed $string - * @return array - */ - public static function decode($string): array - { - if ($string === null || $string === '') { - return []; - } + /** + * Parses a Kirby txt string and returns a multi-dimensional array + * + * @param mixed $string + * @return array + */ + public static function decode($string): array + { + if ($string === null || $string === '') { + return []; + } - if (is_array($string) === true) { - return $string; - } + if (is_array($string) === true) { + return $string; + } - if (is_string($string) === false) { - throw new InvalidArgumentException('Invalid TXT data; please pass a string'); - } + if (is_string($string) === false) { + throw new InvalidArgumentException('Invalid TXT data; please pass a string'); + } - // remove BOM - $string = str_replace("\xEF\xBB\xBF", '', $string); - // explode all fields by the line separator - $fields = preg_split('!\n----\s*\n*!', $string); - // start the data array - $data = []; + // remove BOM + $string = str_replace("\xEF\xBB\xBF", '', $string); + // explode all fields by the line separator + $fields = preg_split('!\n----\s*\n*!', $string); + // start the data array + $data = []; - // loop through all fields and add them to the content - foreach ($fields as $field) { - $pos = strpos($field, ':'); - $key = str_replace(['-', ' '], '_', strtolower(trim(substr($field, 0, $pos)))); + // loop through all fields and add them to the content + foreach ($fields as $field) { + $pos = strpos($field, ':'); + $key = str_replace(['-', ' '], '_', strtolower(trim(substr($field, 0, $pos)))); - // Don't add fields with empty keys - if (empty($key) === true) { - continue; - } + // Don't add fields with empty keys + if (empty($key) === true) { + continue; + } - $value = trim(substr($field, $pos + 1)); + $value = trim(substr($field, $pos + 1)); - // unescape escaped dividers within a field - $data[$key] = preg_replace('!(?<=\n|^)\\\\----!', '----', $value); - } + // unescape escaped dividers within a field + $data[$key] = preg_replace('!(?<=\n|^)\\\\----!', '----', $value); + } - return $data; - } + return $data; + } } diff --git a/kirby/src/Data/Xml.php b/kirby/src/Data/Xml.php index 3951df3..ccbd171 100755 --- a/kirby/src/Data/Xml.php +++ b/kirby/src/Data/Xml.php @@ -16,49 +16,49 @@ use Kirby\Toolkit\Xml as XmlConverter; */ class Xml extends Handler { - /** - * Converts an array to an encoded XML string - * - * @param mixed $data - * @return string - */ - public static function encode($data): string - { - return XmlConverter::create($data, 'data'); - } + /** + * Converts an array to an encoded XML string + * + * @param mixed $data + * @return string + */ + public static function encode($data): string + { + return XmlConverter::create($data, 'data'); + } - /** - * Parses an encoded XML string and returns a multi-dimensional array - * - * @param mixed $string - * @return array - */ - public static function decode($string): array - { - if ($string === null || $string === '') { - return []; - } + /** + * Parses an encoded XML string and returns a multi-dimensional array + * + * @param mixed $string + * @return array + */ + public static function decode($string): array + { + if ($string === null || $string === '') { + return []; + } - if (is_array($string) === true) { - return $string; - } + if (is_array($string) === true) { + return $string; + } - if (is_string($string) === false) { - throw new InvalidArgumentException('Invalid XML data; please pass a string'); - } + if (is_string($string) === false) { + throw new InvalidArgumentException('Invalid XML data; please pass a string'); + } - $result = XmlConverter::parse($string); + $result = XmlConverter::parse($string); - if (is_array($result) === true) { - // remove the root's name if it is the default to ensure that - // the decoded data is the same as the input to the encode() method - if ($result['@name'] === 'data') { - unset($result['@name']); - } + if (is_array($result) === true) { + // remove the root's name if it is the default to ensure that + // the decoded data is the same as the input to the encode() method + if ($result['@name'] === 'data') { + unset($result['@name']); + } - return $result; - } else { - throw new InvalidArgumentException('XML string is invalid'); - } - } + return $result; + } else { + throw new InvalidArgumentException('XML string is invalid'); + } + } } diff --git a/kirby/src/Data/Yaml.php b/kirby/src/Data/Yaml.php index 205cdde..56c1349 100755 --- a/kirby/src/Data/Yaml.php +++ b/kirby/src/Data/Yaml.php @@ -16,62 +16,62 @@ use Spyc; */ class Yaml extends Handler { - /** - * Converts an array to an encoded YAML string - * - * @param mixed $data - * @return string - */ - public static function encode($data): string - { - // TODO: The locale magic should no longer be - // necessary when support for PHP 7.x is dropped + /** + * Converts an array to an encoded YAML string + * + * @param mixed $data + * @return string + */ + public static function encode($data): string + { + // TODO: The locale magic should no longer be + // necessary when support for PHP 7.x is dropped - // fetch the current locale setting for numbers - $locale = setlocale(LC_NUMERIC, 0); + // fetch the current locale setting for numbers + $locale = setlocale(LC_NUMERIC, 0); - // change to english numerics to avoid issues with floats - setlocale(LC_NUMERIC, 'C'); + // change to english numerics to avoid issues with floats + setlocale(LC_NUMERIC, 'C'); - // $data, $indent, $wordwrap, $no_opening_dashes - $yaml = Spyc::YAMLDump($data, false, false, true); + // $data, $indent, $wordwrap, $no_opening_dashes + $yaml = Spyc::YAMLDump($data, false, false, true); - // restore the previous locale settings - setlocale(LC_NUMERIC, $locale); + // restore the previous locale settings + setlocale(LC_NUMERIC, $locale); - return $yaml; - } + return $yaml; + } - /** - * Parses an encoded YAML string and returns a multi-dimensional array - * - * @param mixed $string - * @return array - */ - public static function decode($string): array - { - if ($string === null || $string === '') { - return []; - } + /** + * Parses an encoded YAML string and returns a multi-dimensional array + * + * @param mixed $string + * @return array + */ + public static function decode($string): array + { + if ($string === null || $string === '') { + return []; + } - if (is_array($string) === true) { - return $string; - } + if (is_array($string) === true) { + return $string; + } - if (is_string($string) === false) { - throw new InvalidArgumentException('Invalid YAML data; please pass a string'); - } + if (is_string($string) === false) { + throw new InvalidArgumentException('Invalid YAML data; please pass a string'); + } - // remove BOM - $string = str_replace("\xEF\xBB\xBF", '', $string); - $result = Spyc::YAMLLoadString($string); + // remove BOM + $string = str_replace("\xEF\xBB\xBF", '', $string); + $result = Spyc::YAMLLoadString($string); - if (is_array($result)) { - return $result; - } else { - // apparently Spyc always returns an array, even for invalid YAML syntax - // so this Exception should currently never be thrown - throw new InvalidArgumentException('The YAML data cannot be parsed'); // @codeCoverageIgnore - } - } + if (is_array($result)) { + return $result; + } else { + // apparently Spyc always returns an array, even for invalid YAML syntax + // so this Exception should currently never be thrown + throw new InvalidArgumentException('The YAML data cannot be parsed'); // @codeCoverageIgnore + } + } } diff --git a/kirby/src/Database/Database.php b/kirby/src/Database/Database.php index d0ddb48..87b77b4 100755 --- a/kirby/src/Database/Database.php +++ b/kirby/src/Database/Database.php @@ -20,651 +20,651 @@ use Throwable; */ class Database { - /** - * The number of affected rows for the last query - * - * @var int|null - */ - protected $affected; - - /** - * Whitelist for column names - * - * @var array - */ - protected $columnWhitelist = []; - - /** - * The established connection - * - * @var \PDO|null - */ - protected $connection; - - /** - * A global array of started connections - * - * @var array - */ - public static $connections = []; - - /** - * Database name - * - * @var string - */ - protected $database; - - /** - * @var string - */ - protected $dsn; - - /** - * Set to true to throw exceptions on failed queries - * - * @var bool - */ - protected $fail = false; - - /** - * The connection id - * - * @var string - */ - protected $id; - - /** - * The last error - * - * @var \Exception|null - */ - protected $lastError; - - /** - * The last insert id - * - * @var int|null - */ - protected $lastId; - - /** - * The last query - * - * @var string - */ - protected $lastQuery; - - /** - * The last result set - * - * @var mixed - */ - protected $lastResult; - - /** - * Optional prefix for table names - * - * @var string - */ - protected $prefix; - - /** - * The PDO query statement - * - * @var \PDOStatement|null - */ - protected $statement; - - /** - * List of existing tables in the database - * - * @var array|null - */ - protected $tables; - - /** - * An array with all queries which are being made - * - * @var array - */ - protected $trace = []; - - /** - * The database type (mysql, sqlite) - * - * @var string - */ - protected $type; - - /** - * @var array - */ - public static $types = []; - - /** - * Creates a new Database instance - * - * @param array $params - * @return void - */ - public function __construct(array $params = []) - { - $this->connect($params); - } - - /** - * Returns one of the started instances - * - * @param string|null $id - * @return static|null - */ - public static function instance(string $id = null) - { - return $id === null ? A::last(static::$connections) : static::$connections[$id] ?? null; - } - - /** - * Returns all started instances - * - * @return array - */ - public static function instances(): array - { - return static::$connections; - } - - /** - * Connects to a database - * - * @param array|null $params This can either be a config key or an array of parameters for the connection - * @return \PDO|null - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function connect(array $params = null) - { - $defaults = [ - 'database' => null, - 'type' => 'mysql', - 'prefix' => null, - 'user' => null, - 'password' => null, - 'id' => uniqid() - ]; - - $options = array_merge($defaults, $params); - - // store the database information - $this->database = $options['database']; - $this->type = $options['type']; - $this->prefix = $options['prefix']; - $this->id = $options['id']; - - if (isset(static::$types[$this->type]) === false) { - throw new InvalidArgumentException('Invalid database type: ' . $this->type); - } - - // fetch the dsn and store it - $this->dsn = (static::$types[$this->type]['dsn'])($options); - - // try to connect - $this->connection = new PDO($this->dsn, $options['user'], $options['password']); - $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); - - // TODO: behavior without this attribute would be preferrable - // (actual types instead of all strings) but would be a breaking change - if ($this->type === 'sqlite') { - $this->connection->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); - } - - // store the connection - static::$connections[$this->id] = $this; - - // return the connection - return $this->connection; - } - - /** - * Returns the currently active connection - * - * @return \PDO|null - */ - public function connection(): ?PDO - { - return $this->connection; - } - - /** - * Sets the exception mode - * - * @param bool $fail - * @return \Kirby\Database\Database - */ - public function fail(bool $fail = true) - { - $this->fail = $fail; - return $this; - } - - /** - * Returns the used database type - * - * @return string - */ - public function type(): string - { - return $this->type; - } - - /** - * Returns the used table name prefix - * - * @return string|null - */ - public function prefix(): ?string - { - return $this->prefix; - } - - /** - * Escapes a value to be used for a safe query - * NOTE: Prepared statements using bound parameters are more secure and solid - * - * @param string $value - * @return string - */ - public function escape(string $value): string - { - return substr($this->connection()->quote($value), 1, -1); - } - - /** - * Adds a value to the db trace and also returns the entire trace if nothing is specified - * - * @param array|null $data - * @return array - */ - public function trace(array $data = null): array - { - // return the full trace - if ($data === null) { - return $this->trace; - } - - // add a new entry to the trace - $this->trace[] = $data; - - return $this->trace; - } - - /** - * Returns the number of affected rows for the last query - * - * @return int|null - */ - public function affected(): ?int - { - return $this->affected; - } - - /** - * Returns the last id if available - * - * @return int|null - */ - public function lastId(): ?int - { - return $this->lastId; - } - - /** - * Returns the last query - * - * @return string|null - */ - public function lastQuery(): ?string - { - return $this->lastQuery; - } - - /** - * Returns the last set of results - * - * @return mixed - */ - public function lastResult() - { - return $this->lastResult; - } - - /** - * Returns the last db error - * - * @return \Throwable - */ - public function lastError() - { - return $this->lastError; - } - - /** - * Returns the name of the database - * - * @return string|null - */ - public function name(): ?string - { - return $this->database; - } - - /** - * Private method to execute database queries. - * This is used by the query() and execute() methods - * - * @param string $query - * @param array $bindings - * @return bool - */ - protected function hit(string $query, array $bindings = []): bool - { - // try to prepare and execute the sql - try { - $this->statement = $this->connection->prepare($query); - $this->statement->execute($bindings); - - $this->affected = $this->statement->rowCount(); - $this->lastId = Str::startsWith($query, 'insert ', true) ? $this->connection->lastInsertId() : null; - $this->lastError = null; - - // store the final sql to add it to the trace later - $this->lastQuery = $this->statement->queryString; - } catch (Throwable $e) { - - // store the error - $this->affected = 0; - $this->lastError = $e; - $this->lastId = null; - $this->lastQuery = $query; - - // only throw the extension if failing is allowed - if ($this->fail === true) { - throw $e; - } - } - - // add a new entry to the singleton trace array - $this->trace([ - 'query' => $this->lastQuery, - 'bindings' => $bindings, - 'error' => $this->lastError - ]); - - // return true or false on success or failure - return $this->lastError === null; - } - - /** - * Executes a sql query, which is expected to return a set of results - * - * @param string $query - * @param array $bindings - * @param array $params - * @return mixed - */ - public function query(string $query, array $bindings = [], array $params = []) - { - $defaults = [ - 'flag' => null, - 'method' => 'fetchAll', - 'fetch' => 'Kirby\Toolkit\Obj', - 'iterator' => 'Kirby\Toolkit\Collection', - ]; - - $options = array_merge($defaults, $params); - - if ($this->hit($query, $bindings) === false) { - return false; - } - - // define the default flag for the fetch method - if ($options['fetch'] instanceof Closure || $options['fetch'] === 'array') { - $flags = PDO::FETCH_ASSOC; - } else { - $flags = PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE; - } - - // add optional flags - if (empty($options['flag']) === false) { - $flags |= $options['flag']; - } - - // set the fetch mode - if ($options['fetch'] instanceof Closure || $options['fetch'] === 'array') { - $this->statement->setFetchMode($flags); - } else { - $this->statement->setFetchMode($flags, $options['fetch']); - } - - // fetch that stuff - $results = $this->statement->{$options['method']}(); - - // apply the fetch closure to all results if given - if ($options['fetch'] instanceof Closure) { - foreach ($results as $key => $result) { - $results[$key] = $options['fetch']($result, $key); - } - } - - if ($options['iterator'] === 'array') { - return $this->lastResult = $results; - } - - return $this->lastResult = new $options['iterator']($results); - } - - /** - * Executes a sql query, which is expected to not return a set of results - * - * @param string $query - * @param array $bindings - * @return bool - */ - public function execute(string $query, array $bindings = []): bool - { - return $this->lastResult = $this->hit($query, $bindings); - } - - /** - * Returns the correct Sql generator instance - * for the type of database - * - * @return \Kirby\Database\Sql - */ - public function sql() - { - $className = static::$types[$this->type]['sql'] ?? 'Sql'; - return new $className($this); - } - - /** - * Sets the current table, which should be queried. Returns a - * Query object, which can be used to build a full query - * for that table - * - * @param string $table - * @return \Kirby\Database\Query - */ - public function table(string $table) - { - return new Query($this, $this->prefix() . $table); - } - - /** - * Checks if a table exists in the current database - * - * @param string $table - * @return bool - */ - public function validateTable(string $table): bool - { - if ($this->tables === null) { - // Get the list of tables from the database - $sql = $this->sql()->tables(); - $results = $this->query($sql['query'], $sql['bindings']); - - if ($results) { - $this->tables = $results->pluck('name'); - } else { - return false; - } - } - - return in_array($table, $this->tables) === true; - } - - /** - * Checks if a column exists in a specified table - * - * @param string $table - * @param string $column - * @return bool - */ - public function validateColumn(string $table, string $column): bool - { - if (isset($this->columnWhitelist[$table]) === false) { - if ($this->validateTable($table) === false) { - $this->columnWhitelist[$table] = []; - return false; - } - - // Get the column whitelist from the database - $sql = $this->sql()->columns($table); - $results = $this->query($sql['query'], $sql['bindings']); - - if ($results) { - $this->columnWhitelist[$table] = $results->pluck('name'); - } else { - return false; - } - } - - return in_array($column, $this->columnWhitelist[$table]) === true; - } - - /** - * Creates a new table - * - * @param string $table - * @param array $columns - * @return bool - */ - public function createTable($table, $columns = []): bool - { - $sql = $this->sql()->createTable($table, $columns); - $queries = Str::split($sql['query'], ';'); - - foreach ($queries as $query) { - $query = trim($query); - - if ($this->execute($query, $sql['bindings']) === false) { - return false; - } - } - - // update cache - if (in_array($table, $this->tables ?? []) !== true) { - $this->tables[] = $table; - } - - return true; - } - - /** - * Drops a table - * - * @param string $table - * @return bool - */ - public function dropTable(string $table): bool - { - $sql = $this->sql()->dropTable($table); - if ($this->execute($sql['query'], $sql['bindings']) !== true) { - return false; - } - - // update cache - $key = array_search($table, $this->tables ?? []); - if ($key !== false) { - unset($this->tables[$key]); - } - - return true; - } - - /** - * Magic way to start queries for tables by - * using a method named like the table. - * I.e. $db->users()->all() - * - * @param mixed $method - * @param mixed $arguments - * @return \Kirby\Database\Query - */ - public function __call($method, $arguments = null) - { - return $this->table($method); - } + /** + * The number of affected rows for the last query + * + * @var int|null + */ + protected $affected; + + /** + * Whitelist for column names + * + * @var array + */ + protected $columnWhitelist = []; + + /** + * The established connection + * + * @var \PDO|null + */ + protected $connection; + + /** + * A global array of started connections + * + * @var array + */ + public static $connections = []; + + /** + * Database name + * + * @var string + */ + protected $database; + + /** + * @var string + */ + protected $dsn; + + /** + * Set to true to throw exceptions on failed queries + * + * @var bool + */ + protected $fail = false; + + /** + * The connection id + * + * @var string + */ + protected $id; + + /** + * The last error + * + * @var \Exception|null + */ + protected $lastError; + + /** + * The last insert id + * + * @var int|null + */ + protected $lastId; + + /** + * The last query + * + * @var string + */ + protected $lastQuery; + + /** + * The last result set + * + * @var mixed + */ + protected $lastResult; + + /** + * Optional prefix for table names + * + * @var string + */ + protected $prefix; + + /** + * The PDO query statement + * + * @var \PDOStatement|null + */ + protected $statement; + + /** + * List of existing tables in the database + * + * @var array|null + */ + protected $tables; + + /** + * An array with all queries which are being made + * + * @var array + */ + protected $trace = []; + + /** + * The database type (mysql, sqlite) + * + * @var string + */ + protected $type; + + /** + * @var array + */ + public static $types = []; + + /** + * Creates a new Database instance + * + * @param array $params + * @return void + */ + public function __construct(array $params = []) + { + $this->connect($params); + } + + /** + * Returns one of the started instances + * + * @param string|null $id + * @return static|null + */ + public static function instance(string $id = null) + { + return $id === null ? A::last(static::$connections) : static::$connections[$id] ?? null; + } + + /** + * Returns all started instances + * + * @return array + */ + public static function instances(): array + { + return static::$connections; + } + + /** + * Connects to a database + * + * @param array|null $params This can either be a config key or an array of parameters for the connection + * @return \PDO|null + * @throws \Kirby\Exception\InvalidArgumentException + */ + public function connect(array $params = null) + { + $defaults = [ + 'database' => null, + 'type' => 'mysql', + 'prefix' => null, + 'user' => null, + 'password' => null, + 'id' => uniqid() + ]; + + $options = array_merge($defaults, $params); + + // store the database information + $this->database = $options['database']; + $this->type = $options['type']; + $this->prefix = $options['prefix']; + $this->id = $options['id']; + + if (isset(static::$types[$this->type]) === false) { + throw new InvalidArgumentException('Invalid database type: ' . $this->type); + } + + // fetch the dsn and store it + $this->dsn = (static::$types[$this->type]['dsn'])($options); + + // try to connect + $this->connection = new PDO($this->dsn, $options['user'], $options['password']); + $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); + + // TODO: behavior without this attribute would be preferrable + // (actual types instead of all strings) but would be a breaking change + if ($this->type === 'sqlite') { + $this->connection->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + } + + // store the connection + static::$connections[$this->id] = $this; + + // return the connection + return $this->connection; + } + + /** + * Returns the currently active connection + * + * @return \PDO|null + */ + public function connection(): ?PDO + { + return $this->connection; + } + + /** + * Sets the exception mode + * + * @param bool $fail + * @return \Kirby\Database\Database + */ + public function fail(bool $fail = true) + { + $this->fail = $fail; + return $this; + } + + /** + * Returns the used database type + * + * @return string + */ + public function type(): string + { + return $this->type; + } + + /** + * Returns the used table name prefix + * + * @return string|null + */ + public function prefix(): ?string + { + return $this->prefix; + } + + /** + * Escapes a value to be used for a safe query + * NOTE: Prepared statements using bound parameters are more secure and solid + * + * @param string $value + * @return string + */ + public function escape(string $value): string + { + return substr($this->connection()->quote($value), 1, -1); + } + + /** + * Adds a value to the db trace and also returns the entire trace if nothing is specified + * + * @param array|null $data + * @return array + */ + public function trace(array $data = null): array + { + // return the full trace + if ($data === null) { + return $this->trace; + } + + // add a new entry to the trace + $this->trace[] = $data; + + return $this->trace; + } + + /** + * Returns the number of affected rows for the last query + * + * @return int|null + */ + public function affected(): ?int + { + return $this->affected; + } + + /** + * Returns the last id if available + * + * @return int|null + */ + public function lastId(): ?int + { + return $this->lastId; + } + + /** + * Returns the last query + * + * @return string|null + */ + public function lastQuery(): ?string + { + return $this->lastQuery; + } + + /** + * Returns the last set of results + * + * @return mixed + */ + public function lastResult() + { + return $this->lastResult; + } + + /** + * Returns the last db error + * + * @return \Throwable + */ + public function lastError() + { + return $this->lastError; + } + + /** + * Returns the name of the database + * + * @return string|null + */ + public function name(): ?string + { + return $this->database; + } + + /** + * Private method to execute database queries. + * This is used by the query() and execute() methods + * + * @param string $query + * @param array $bindings + * @return bool + */ + protected function hit(string $query, array $bindings = []): bool + { + // try to prepare and execute the sql + try { + $this->statement = $this->connection->prepare($query); + $this->statement->execute($bindings); + + $this->affected = $this->statement->rowCount(); + $this->lastId = Str::startsWith($query, 'insert ', true) ? $this->connection->lastInsertId() : null; + $this->lastError = null; + + // store the final sql to add it to the trace later + $this->lastQuery = $this->statement->queryString; + } catch (Throwable $e) { + + // store the error + $this->affected = 0; + $this->lastError = $e; + $this->lastId = null; + $this->lastQuery = $query; + + // only throw the extension if failing is allowed + if ($this->fail === true) { + throw $e; + } + } + + // add a new entry to the singleton trace array + $this->trace([ + 'query' => $this->lastQuery, + 'bindings' => $bindings, + 'error' => $this->lastError + ]); + + // return true or false on success or failure + return $this->lastError === null; + } + + /** + * Executes a sql query, which is expected to return a set of results + * + * @param string $query + * @param array $bindings + * @param array $params + * @return mixed + */ + public function query(string $query, array $bindings = [], array $params = []) + { + $defaults = [ + 'flag' => null, + 'method' => 'fetchAll', + 'fetch' => 'Kirby\Toolkit\Obj', + 'iterator' => 'Kirby\Toolkit\Collection', + ]; + + $options = array_merge($defaults, $params); + + if ($this->hit($query, $bindings) === false) { + return false; + } + + // define the default flag for the fetch method + if ($options['fetch'] instanceof Closure || $options['fetch'] === 'array') { + $flags = PDO::FETCH_ASSOC; + } else { + $flags = PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE; + } + + // add optional flags + if (empty($options['flag']) === false) { + $flags |= $options['flag']; + } + + // set the fetch mode + if ($options['fetch'] instanceof Closure || $options['fetch'] === 'array') { + $this->statement->setFetchMode($flags); + } else { + $this->statement->setFetchMode($flags, $options['fetch']); + } + + // fetch that stuff + $results = $this->statement->{$options['method']}(); + + // apply the fetch closure to all results if given + if ($options['fetch'] instanceof Closure) { + foreach ($results as $key => $result) { + $results[$key] = $options['fetch']($result, $key); + } + } + + if ($options['iterator'] === 'array') { + return $this->lastResult = $results; + } + + return $this->lastResult = new $options['iterator']($results); + } + + /** + * Executes a sql query, which is expected to not return a set of results + * + * @param string $query + * @param array $bindings + * @return bool + */ + public function execute(string $query, array $bindings = []): bool + { + return $this->lastResult = $this->hit($query, $bindings); + } + + /** + * Returns the correct Sql generator instance + * for the type of database + * + * @return \Kirby\Database\Sql + */ + public function sql() + { + $className = static::$types[$this->type]['sql'] ?? 'Sql'; + return new $className($this); + } + + /** + * Sets the current table, which should be queried. Returns a + * Query object, which can be used to build a full query + * for that table + * + * @param string $table + * @return \Kirby\Database\Query + */ + public function table(string $table) + { + return new Query($this, $this->prefix() . $table); + } + + /** + * Checks if a table exists in the current database + * + * @param string $table + * @return bool + */ + public function validateTable(string $table): bool + { + if ($this->tables === null) { + // Get the list of tables from the database + $sql = $this->sql()->tables(); + $results = $this->query($sql['query'], $sql['bindings']); + + if ($results) { + $this->tables = $results->pluck('name'); + } else { + return false; + } + } + + return in_array($table, $this->tables) === true; + } + + /** + * Checks if a column exists in a specified table + * + * @param string $table + * @param string $column + * @return bool + */ + public function validateColumn(string $table, string $column): bool + { + if (isset($this->columnWhitelist[$table]) === false) { + if ($this->validateTable($table) === false) { + $this->columnWhitelist[$table] = []; + return false; + } + + // Get the column whitelist from the database + $sql = $this->sql()->columns($table); + $results = $this->query($sql['query'], $sql['bindings']); + + if ($results) { + $this->columnWhitelist[$table] = $results->pluck('name'); + } else { + return false; + } + } + + return in_array($column, $this->columnWhitelist[$table]) === true; + } + + /** + * Creates a new table + * + * @param string $table + * @param array $columns + * @return bool + */ + public function createTable($table, $columns = []): bool + { + $sql = $this->sql()->createTable($table, $columns); + $queries = Str::split($sql['query'], ';'); + + foreach ($queries as $query) { + $query = trim($query); + + if ($this->execute($query, $sql['bindings']) === false) { + return false; + } + } + + // update cache + if (in_array($table, $this->tables ?? []) !== true) { + $this->tables[] = $table; + } + + return true; + } + + /** + * Drops a table + * + * @param string $table + * @return bool + */ + public function dropTable(string $table): bool + { + $sql = $this->sql()->dropTable($table); + if ($this->execute($sql['query'], $sql['bindings']) !== true) { + return false; + } + + // update cache + $key = array_search($table, $this->tables ?? []); + if ($key !== false) { + unset($this->tables[$key]); + } + + return true; + } + + /** + * Magic way to start queries for tables by + * using a method named like the table. + * I.e. $db->users()->all() + * + * @param mixed $method + * @param mixed $arguments + * @return \Kirby\Database\Query + */ + public function __call($method, $arguments = null) + { + return $this->table($method); + } } /** * MySQL database connector */ Database::$types['mysql'] = [ - 'sql' => 'Kirby\Database\Sql\Mysql', - 'dsn' => function (array $params) { - if (isset($params['host']) === false && isset($params['socket']) === false) { - throw new InvalidArgumentException('The mysql connection requires either a "host" or a "socket" parameter'); - } + 'sql' => 'Kirby\Database\Sql\Mysql', + 'dsn' => function (array $params) { + if (isset($params['host']) === false && isset($params['socket']) === false) { + throw new InvalidArgumentException('The mysql connection requires either a "host" or a "socket" parameter'); + } - if (isset($params['database']) === false) { - throw new InvalidArgumentException('The mysql connection requires a "database" parameter'); - } + if (isset($params['database']) === false) { + throw new InvalidArgumentException('The mysql connection requires a "database" parameter'); + } - $parts = []; + $parts = []; - if (empty($params['host']) === false) { - $parts[] = 'host=' . $params['host']; - } + if (empty($params['host']) === false) { + $parts[] = 'host=' . $params['host']; + } - if (empty($params['port']) === false) { - $parts[] = 'port=' . $params['port']; - } + if (empty($params['port']) === false) { + $parts[] = 'port=' . $params['port']; + } - if (empty($params['socket']) === false) { - $parts[] = 'unix_socket=' . $params['socket']; - } + if (empty($params['socket']) === false) { + $parts[] = 'unix_socket=' . $params['socket']; + } - if (empty($params['database']) === false) { - $parts[] = 'dbname=' . $params['database']; - } + if (empty($params['database']) === false) { + $parts[] = 'dbname=' . $params['database']; + } - $parts[] = 'charset=' . ($params['charset'] ?? 'utf8'); + $parts[] = 'charset=' . ($params['charset'] ?? 'utf8'); - return 'mysql:' . implode(';', $parts); - } + return 'mysql:' . implode(';', $parts); + } ]; /** * SQLite database connector */ Database::$types['sqlite'] = [ - 'sql' => 'Kirby\Database\Sql\Sqlite', - 'dsn' => function (array $params) { - if (isset($params['database']) === false) { - throw new InvalidArgumentException('The sqlite connection requires a "database" parameter'); - } + 'sql' => 'Kirby\Database\Sql\Sqlite', + 'dsn' => function (array $params) { + if (isset($params['database']) === false) { + throw new InvalidArgumentException('The sqlite connection requires a "database" parameter'); + } - return 'sqlite:' . $params['database']; - } + return 'sqlite:' . $params['database']; + } ]; diff --git a/kirby/src/Database/Db.php b/kirby/src/Database/Db.php index 4686b36..e57562f 100755 --- a/kirby/src/Database/Db.php +++ b/kirby/src/Database/Db.php @@ -16,121 +16,121 @@ use Kirby\Toolkit\Config; */ class Db { - /** - * Query shortcuts - * - * @var array - */ - public static $queries = []; + /** + * Query shortcuts + * + * @var array + */ + public static $queries = []; - /** - * The singleton Database object - * - * @var \Kirby\Database\Database - */ - public static $connection = null; + /** + * The singleton Database object + * + * @var \Kirby\Database\Database + */ + public static $connection = null; - /** - * (Re)connect the database - * - * @param array|null $params Pass `[]` to use the default params from the config, - * don't pass any argument to get the current connection - * @return \Kirby\Database\Database - */ - public static function connect(?array $params = null) - { - if ($params === null && static::$connection !== null) { - return static::$connection; - } + /** + * (Re)connect the database + * + * @param array|null $params Pass `[]` to use the default params from the config, + * don't pass any argument to get the current connection + * @return \Kirby\Database\Database + */ + public static function connect(?array $params = null) + { + if ($params === null && static::$connection !== null) { + return static::$connection; + } - // try to connect with the default - // connection settings if no params are set - $params ??= [ - 'type' => Config::get('db.type', 'mysql'), - 'host' => Config::get('db.host', 'localhost'), - 'user' => Config::get('db.user', 'root'), - 'password' => Config::get('db.password', ''), - 'database' => Config::get('db.database', ''), - 'prefix' => Config::get('db.prefix', ''), - 'port' => Config::get('db.port', '') - ]; + // try to connect with the default + // connection settings if no params are set + $params ??= [ + 'type' => Config::get('db.type', 'mysql'), + 'host' => Config::get('db.host', 'localhost'), + 'user' => Config::get('db.user', 'root'), + 'password' => Config::get('db.password', ''), + 'database' => Config::get('db.database', ''), + 'prefix' => Config::get('db.prefix', ''), + 'port' => Config::get('db.port', '') + ]; - return static::$connection = new Database($params); - } + return static::$connection = new Database($params); + } - /** - * Returns the current database connection - * - * @return \Kirby\Database\Database|null - */ - public static function connection() - { - return static::$connection; - } + /** + * Returns the current database connection + * + * @return \Kirby\Database\Database|null + */ + public static function connection() + { + return static::$connection; + } - /** - * Sets the current table which should be queried. Returns a - * Query object, which can be used to build a full query for - * that table. - * - * @param string $table - * @return \Kirby\Database\Query - */ - public static function table(string $table) - { - $db = static::connect(); - return $db->table($table); - } + /** + * Sets the current table which should be queried. Returns a + * Query object, which can be used to build a full query for + * that table. + * + * @param string $table + * @return \Kirby\Database\Query + */ + public static function table(string $table) + { + $db = static::connect(); + return $db->table($table); + } - /** - * Executes a raw SQL query which expects a set of results - * - * @param string $query - * @param array $bindings - * @param array $params - * @return mixed - */ - public static function query(string $query, array $bindings = [], array $params = []) - { - $db = static::connect(); - return $db->query($query, $bindings, $params); - } + /** + * Executes a raw SQL query which expects a set of results + * + * @param string $query + * @param array $bindings + * @param array $params + * @return mixed + */ + public static function query(string $query, array $bindings = [], array $params = []) + { + $db = static::connect(); + return $db->query($query, $bindings, $params); + } - /** - * Executes a raw SQL query which expects no set of results (i.e. update, insert, delete) - * - * @param string $query - * @param array $bindings - * @return bool - */ - public static function execute(string $query, array $bindings = []): bool - { - $db = static::connect(); - return $db->execute($query, $bindings); - } + /** + * Executes a raw SQL query which expects no set of results (i.e. update, insert, delete) + * + * @param string $query + * @param array $bindings + * @return bool + */ + public static function execute(string $query, array $bindings = []): bool + { + $db = static::connect(); + return $db->execute($query, $bindings); + } - /** - * Magic calls for other static Db methods are - * redirected to either a predefined query or - * the respective method of the Database object - * - * @param string $method - * @param mixed $arguments - * @return mixed - * @throws \Kirby\Exception\InvalidArgumentException - */ - public static function __callStatic(string $method, $arguments) - { - if (isset(static::$queries[$method])) { - return (static::$queries[$method])(...$arguments); - } + /** + * Magic calls for other static Db methods are + * redirected to either a predefined query or + * the respective method of the Database object + * + * @param string $method + * @param mixed $arguments + * @return mixed + * @throws \Kirby\Exception\InvalidArgumentException + */ + public static function __callStatic(string $method, $arguments) + { + if (isset(static::$queries[$method])) { + return (static::$queries[$method])(...$arguments); + } - if (static::$connection !== null && method_exists(static::$connection, $method) === true) { - return call_user_func_array([static::$connection, $method], $arguments); - } + if (static::$connection !== null && method_exists(static::$connection, $method) === true) { + return call_user_func_array([static::$connection, $method], $arguments); + } - throw new InvalidArgumentException('Invalid static Db method: ' . $method); - } + throw new InvalidArgumentException('Invalid static Db method: ' . $method); + } } // @codeCoverageIgnoreStart @@ -147,7 +147,7 @@ class Db * @return mixed */ Db::$queries['select'] = function (string $table, $columns = '*', $where = null, string $order = null, int $offset = 0, int $limit = null) { - return Db::table($table)->select($columns)->where($where)->order($order)->offset($offset)->limit($limit)->all(); + return Db::table($table)->select($columns)->where($where)->order($order)->offset($offset)->limit($limit)->all(); }; /** @@ -162,7 +162,7 @@ Db::$queries['select'] = function (string $table, $columns = '*', $where = null, * @return mixed */ Db::$queries['first'] = Db::$queries['row'] = Db::$queries['one'] = function (string $table, $columns = '*', $where = null, string $order = null) { - return Db::table($table)->select($columns)->where($where)->order($order)->first(); + return Db::table($table)->select($columns)->where($where)->order($order)->first(); }; /** @@ -177,7 +177,7 @@ Db::$queries['first'] = Db::$queries['row'] = Db::$queries['one'] = function (st * @return mixed */ Db::$queries['column'] = function (string $table, string $column, $where = null, string $order = null, int $offset = 0, int $limit = null) { - return Db::table($table)->where($where)->order($order)->offset($offset)->limit($limit)->column($column); + return Db::table($table)->where($where)->order($order)->offset($offset)->limit($limit)->column($column); }; /** @@ -188,7 +188,7 @@ Db::$queries['column'] = function (string $table, string $column, $where = null, * @return mixed Returns the last inserted id on success or false */ Db::$queries['insert'] = function (string $table, array $values) { - return Db::table($table)->insert($values); + return Db::table($table)->insert($values); }; /** @@ -200,7 +200,7 @@ Db::$queries['insert'] = function (string $table, array $values) { * @return bool */ Db::$queries['update'] = function (string $table, array $values, $where = null): bool { - return Db::table($table)->where($where)->update($values); + return Db::table($table)->where($where)->update($values); }; /** @@ -211,7 +211,7 @@ Db::$queries['update'] = function (string $table, array $values, $where = null): * @return bool */ Db::$queries['delete'] = function (string $table, $where = null): bool { - return Db::table($table)->where($where)->delete(); + return Db::table($table)->where($where)->delete(); }; /** @@ -222,7 +222,7 @@ Db::$queries['delete'] = function (string $table, $where = null): bool { * @return int */ Db::$queries['count'] = function (string $table, $where = null): int { - return Db::table($table)->where($where)->count(); + return Db::table($table)->where($where)->count(); }; /** @@ -234,7 +234,7 @@ Db::$queries['count'] = function (string $table, $where = null): int { * @return float */ Db::$queries['min'] = function (string $table, string $column, $where = null): float { - return Db::table($table)->where($where)->min($column); + return Db::table($table)->where($where)->min($column); }; /** @@ -246,7 +246,7 @@ Db::$queries['min'] = function (string $table, string $column, $where = null): f * @return float */ Db::$queries['max'] = function (string $table, string $column, $where = null): float { - return Db::table($table)->where($where)->max($column); + return Db::table($table)->where($where)->max($column); }; /** @@ -258,7 +258,7 @@ Db::$queries['max'] = function (string $table, string $column, $where = null): f * @return float */ Db::$queries['avg'] = function (string $table, string $column, $where = null): float { - return Db::table($table)->where($where)->avg($column); + return Db::table($table)->where($where)->avg($column); }; /** @@ -270,7 +270,7 @@ Db::$queries['avg'] = function (string $table, string $column, $where = null): f * @return float */ Db::$queries['sum'] = function (string $table, string $column, $where = null): float { - return Db::table($table)->where($where)->sum($column); + return Db::table($table)->where($where)->sum($column); }; // @codeCoverageIgnoreEnd diff --git a/kirby/src/Database/Query.php b/kirby/src/Database/Query.php index 72b6ec7..ac128f8 100755 --- a/kirby/src/Database/Query.php +++ b/kirby/src/Database/Query.php @@ -19,1056 +19,1056 @@ use Kirby\Toolkit\Str; */ class Query { - public const ERROR_INVALID_QUERY_METHOD = 0; - - /** - * Parent Database object - * - * @var \Kirby\Database\Database - */ - protected $database = null; - - /** - * The object which should be fetched for each row - * or function to call for each row - * - * @var string|\Closure - */ - protected $fetch = 'Kirby\Toolkit\Obj'; - - /** - * The iterator class, which should be used for result sets - * - * @var string - */ - protected $iterator = 'Kirby\Toolkit\Collection'; - - /** - * An array of bindings for the final query - * - * @var array - */ - protected $bindings = []; - - /** - * The table name - * - * @var string - */ - protected $table; - - /** - * The name of the primary key column - * - * @var string - */ - protected $primaryKeyName = 'id'; - - /** - * An array with additional join parameters - * - * @var array - */ - protected $join; - - /** - * A list of columns, which should be selected - * - * @var array|string - */ - protected $select; - - /** - * Boolean for distinct select clauses - * - * @var bool - */ - protected $distinct; - - /** - * Boolean for if exceptions should be thrown on failing queries - * - * @var bool - */ - protected $fail = false; - - /** - * A list of values for update and insert clauses - * - * @var array - */ - protected $values; - - /** - * WHERE clause - * - * @var mixed - */ - protected $where; - - /** - * GROUP BY clause - * - * @var mixed - */ - protected $group; - - /** - * HAVING clause - * - * @var mixed - */ - protected $having; - - /** - * ORDER BY clause - * - * @var mixed - */ - protected $order; - - /** - * The offset, which should be applied to the select query - * - * @var int - */ - protected $offset = 0; - - /** - * The limit, which should be applied to the select query - * - * @var int - */ - protected $limit; - - /** - * Boolean to enable query debugging - * - * @var bool - */ - protected $debug = false; - - /** - * Constructor - * - * @param \Kirby\Database\Database $database Database object - * @param string $table Optional name of the table, which should be queried - */ - public function __construct(Database $database, string $table) - { - $this->database = $database; - $this->table($table); - } - - /** - * Reset the query class after each db hit - */ - protected function reset() - { - $this->bindings = []; - $this->join = null; - $this->select = null; - $this->distinct = null; - $this->fail = false; - $this->values = null; - $this->where = null; - $this->group = null; - $this->having = null; - $this->order = null; - $this->offset = 0; - $this->limit = null; - $this->debug = false; - } - - /** - * Enables query debugging. - * If enabled, the query will return an array with all important info about - * the query instead of actually executing the query and returning results - * - * @param bool $debug - * @return \Kirby\Database\Query - */ - public function debug(bool $debug = true) - { - $this->debug = $debug; - return $this; - } - - /** - * Enables distinct select clauses. - * - * @param bool $distinct - * @return \Kirby\Database\Query - */ - public function distinct(bool $distinct = true) - { - $this->distinct = $distinct; - return $this; - } - - /** - * Enables failing queries. - * If enabled queries will no longer fail silently but throw an exception - * - * @param bool $fail - * @return \Kirby\Database\Query - */ - public function fail(bool $fail = true) - { - $this->fail = $fail; - return $this; - } - - /** - * Sets the object class, which should be fetched; - * set this to `'array'` to get a simple array instead of an object; - * pass a function that receives the `$data` and the `$key` to generate arbitrary data structures - * - * @param string|\Closure $fetch - * @return \Kirby\Database\Query - */ - public function fetch($fetch) - { - $this->fetch = $fetch; - return $this; - } - - /** - * Sets the iterator class, which should be used for multiple results - * Set this to array to get a simple array instead of an iterator object - * - * @param string $iterator - * @return \Kirby\Database\Query - */ - public function iterator(string $iterator) - { - $this->iterator = $iterator; - return $this; - } - - /** - * Sets the name of the table, which should be queried - * - * @param string $table - * @return \Kirby\Database\Query - * @throws \Kirby\Exception\InvalidArgumentException if the table does not exist - */ - public function table(string $table) - { - if ($this->database->validateTable($table) === false) { - throw new InvalidArgumentException('Invalid table: ' . $table); - } - - $this->table = $table; - return $this; - } - - /** - * Sets the name of the primary key column - * - * @param string $primaryKeyName - * @return \Kirby\Database\Query - */ - public function primaryKeyName(string $primaryKeyName) - { - $this->primaryKeyName = $primaryKeyName; - return $this; - } - - /** - * Sets the columns, which should be selected from the table - * By default all columns will be selected - * - * @param mixed $select Pass either a string of columns or an array - * @return \Kirby\Database\Query - */ - public function select($select) - { - $this->select = $select; - return $this; - } - - /** - * Adds a new join clause to the query - * - * @param string $table Name of the table, which should be joined - * @param string $on The on clause for this join - * @param string $type The join type. Uses an inner join by default - * @return $this - */ - public function join(string $table, string $on, string $type = 'JOIN') - { - $join = [ - 'table' => $table, - 'on' => $on, - 'type' => $type - ]; - - $this->join[] = $join; - return $this; - } - - /** - * Shortcut for creating a left join clause - * - * @param string $table Name of the table, which should be joined - * @param string $on The on clause for this join - * @return \Kirby\Database\Query - */ - public function leftJoin(string $table, string $on) - { - return $this->join($table, $on, 'left'); - } - - /** - * Shortcut for creating a right join clause - * - * @param string $table Name of the table, which should be joined - * @param string $on The on clause for this join - * @return \Kirby\Database\Query - */ - public function rightJoin(string $table, string $on) - { - return $this->join($table, $on, 'right'); - } - - /** - * Shortcut for creating an inner join clause - * - * @param string $table Name of the table, which should be joined - * @param string $on The on clause for this join - * @return \Kirby\Database\Query - */ - public function innerJoin($table, $on) - { - return $this->join($table, $on, 'inner join'); - } - - /** - * Sets the values which should be used for the update or insert clause - * - * @param mixed $values Can either be a string or an array of values - * @return \Kirby\Database\Query - */ - public function values($values = []) - { - if ($values !== null) { - $this->values = $values; - } - return $this; - } - - /** - * Attaches additional bindings to the query. - * Also can be used as getter for all attached bindings by not passing an argument. - * - * @param mixed $bindings Array of bindings or null to use this method as getter - * @return array|\Kirby\Database\Query - */ - public function bindings(array $bindings = null) - { - if (is_array($bindings) === true) { - $this->bindings = array_merge($this->bindings, $bindings); - return $this; - } - - return $this->bindings; - } - - /** - * Attaches an additional where clause - * - * All available ways to add where clauses - * - * ->where('username like "myuser"'); (args: 1) - * ->where(['username' => 'myuser']); (args: 1) - * ->where(function($where) { $where->where('id', '=', 1) }) (args: 1) - * ->where('username like ?', 'myuser') (args: 2) - * ->where('username', 'like', 'myuser'); (args: 3) - * - * @param mixed ...$args - * @return \Kirby\Database\Query - */ - public function where(...$args) - { - $this->where = $this->filterQuery($args, $this->where); - return $this; - } - - /** - * Shortcut to attach a where clause with an OR operator. - * Check out the where() method docs for additional info. - * - * @param mixed ...$args - * @return \Kirby\Database\Query - */ - public function orWhere(...$args) - { - $mode = A::last($args); - - // if there's a where clause mode attribute attached… - if (in_array($mode, ['AND', 'OR']) === true) { - // remove that from the list of arguments - array_pop($args); - } - - // make sure to always attach the OR mode indicator - $args[] = 'OR'; - - $this->where(...$args); - return $this; - } - - /** - * Shortcut to attach a where clause with an AND operator. - * Check out the where() method docs for additional info. - * - * @param mixed ...$args - * @return \Kirby\Database\Query - */ - public function andWhere(...$args) - { - $mode = A::last($args); - - // if there's a where clause mode attribute attached… - if (in_array($mode, ['AND', 'OR']) === true) { - // remove that from the list of arguments - array_pop($args); - } - - // make sure to always attach the AND mode indicator - $args[] = 'AND'; - - $this->where(...$args); - return $this; - } - - /** - * Attaches a group by clause - * - * @param string|null $group - * @return \Kirby\Database\Query - */ - public function group(string $group = null) - { - $this->group = $group; - return $this; - } - - /** - * Attaches an additional having clause - * - * All available ways to add having clauses - * - * ->having('username like "myuser"'); (args: 1) - * ->having(['username' => 'myuser']); (args: 1) - * ->having(function($having) { $having->having('id', '=', 1) }) (args: 1) - * ->having('username like ?', 'myuser') (args: 2) - * ->having('username', 'like', 'myuser'); (args: 3) - * - * @param mixed ...$args - * @return \Kirby\Database\Query - */ - public function having(...$args) - { - $this->having = $this->filterQuery($args, $this->having); - return $this; - } - - /** - * Attaches an order clause - * - * @param string|null $order - * @return \Kirby\Database\Query - */ - public function order(string $order = null) - { - $this->order = $order; - return $this; - } - - /** - * Sets the offset for select clauses - * - * @param int|null $offset - * @return \Kirby\Database\Query - */ - public function offset(int $offset = null) - { - $this->offset = $offset; - return $this; - } - - /** - * Sets the limit for select clauses - * - * @param int|null $limit - * @return \Kirby\Database\Query - */ - public function limit(int $limit = null) - { - $this->limit = $limit; - return $this; - } - - /** - * Builds the different types of SQL queries - * This uses the SQL class to build stuff. - * - * @param string $type (select, update, insert) - * @return array The final query - */ - public function build(string $type) - { - $sql = $this->database->sql(); - - switch ($type) { - case 'select': - return $sql->select([ - 'table' => $this->table, - 'columns' => $this->select, - 'join' => $this->join, - 'distinct' => $this->distinct, - 'where' => $this->where, - 'group' => $this->group, - 'having' => $this->having, - 'order' => $this->order, - 'offset' => $this->offset, - 'limit' => $this->limit, - 'bindings' => $this->bindings - ]); - case 'update': - return $sql->update([ - 'table' => $this->table, - 'where' => $this->where, - 'values' => $this->values, - 'bindings' => $this->bindings - ]); - case 'insert': - return $sql->insert([ - 'table' => $this->table, - 'values' => $this->values, - 'bindings' => $this->bindings - ]); - case 'delete': - return $sql->delete([ - 'table' => $this->table, - 'where' => $this->where, - 'bindings' => $this->bindings - ]); - } - } - - /** - * Builds a count query - * - * @return int - */ - public function count(): int - { - return (int)$this->aggregate('COUNT'); - } - - /** - * Builds a max query - * - * @param string $column - * @return float - */ - public function max(string $column): float - { - return (float)$this->aggregate('MAX', $column); - } - - /** - * Builds a min query - * - * @param string $column - * @return float - */ - public function min(string $column): float - { - return (float)$this->aggregate('MIN', $column); - } - - /** - * Builds a sum query - * - * @param string $column - * @return float - */ - public function sum(string $column): float - { - return (float)$this->aggregate('SUM', $column); - } - - /** - * Builds an average query - * - * @param string $column - * @return float - */ - public function avg(string $column): float - { - return (float)$this->aggregate('AVG', $column); - } - - /** - * Builds an aggregation query. - * This is used by all the aggregation methods above - * - * @param string $method - * @param string $column - * @param int $default An optional default value, which should be returned if the query fails - * @return mixed - */ - public function aggregate(string $method, string $column = '*', $default = 0) - { - // reset the sorting to avoid counting issues - $this->order = null; - - // validate column - if ($column !== '*') { - $sql = $this->database->sql(); - $column = $sql->columnName($this->table, $column); - } - - $fetch = $this->fetch; - $row = $this->select($method . '(' . $column . ') as aggregation')->fetch('Obj')->first(); - - if ($this->debug === true) { - return $row; - } - - $result = $row ? $row->get('aggregation') : $default; - - $this->fetch($fetch); - - return $result; - } - - /** - * Used as an internal shortcut for firing a db query - * - * @param string|array $sql - * @param array $params - * @return mixed - */ - protected function query($sql, array $params = []) - { - if (is_string($sql) === true) { - $sql = [ - 'query' => $sql, - 'bindings' => $this->bindings() - ]; - } - - if ($this->debug) { - return [ - 'query' => $sql['query'], - 'bindings' => $this->bindings(), - 'options' => $params - ]; - } - - if ($this->fail) { - $this->database->fail(); - } - - $result = $this->database->query($sql['query'], $sql['bindings'], $params); - - $this->reset(); - - return $result; - } - - /** - * Used as an internal shortcut for executing a db query - * - * @param string|array $sql - * @param array $params - * @return mixed - */ - protected function execute($sql, array $params = []) - { - if (is_string($sql) === true) { - $sql = [ - 'query' => $sql, - 'bindings' => $this->bindings() - ]; - } - - if ($this->debug === true) { - return [ - 'query' => $sql['query'], - 'bindings' => $sql['bindings'], - 'options' => $params - ]; - } - - if ($this->fail) { - $this->database->fail(); - } - - $result = $this->database->execute($sql['query'], $sql['bindings']); - - $this->reset(); - - return $result; - } - - /** - * Selects only one row from a table - * - * @return object - */ - public function first() - { - return $this->query($this->offset(0)->limit(1)->build('select'), [ - 'fetch' => $this->fetch, - 'iterator' => 'array', - 'method' => 'fetch', - ]); - } - - /** - * Selects only one row from a table - * - * @return object - */ - public function row() - { - return $this->first(); - } - - /** - * Selects only one row from a table - * - * @return object - */ - public function one() - { - return $this->first(); - } - - /** - * Automatically adds pagination to a query - * - * @param int $page - * @param int $limit The number of rows, which should be returned for each page - * @return object Collection iterator with attached pagination object - */ - public function page(int $page, int $limit) - { - // clone this to create a counter query - $counter = clone $this; - - // count the total number of rows for this query - $count = $counter->debug(false)->count(); - - // pagination - $pagination = new Pagination([ - 'limit' => $limit, - 'page' => $page, - 'total' => $count, - ]); - - // apply it to the dataset and retrieve all rows. make sure to use Collection as the iterator to be able to attach the pagination object - $iterator = $this->iterator; - $collection = $this - ->offset($pagination->offset()) - ->limit($pagination->limit()) - ->iterator('Kirby\Toolkit\Collection') - ->all(); - - $this->iterator($iterator); - - // return debug information if debug mode is active - if ($this->debug) { - $collection['totalcount'] = $count; - return $collection; - } - - // store all pagination vars in a separate object - if ($collection) { - $collection->paginate($pagination); - } - - // return the limited collection - return $collection; - } - - /** - * Returns all matching rows from a table - * - * @return mixed - */ - public function all() - { - return $this->query($this->build('select'), [ - 'fetch' => $this->fetch, - 'iterator' => $this->iterator, - ]); - } - - /** - * Returns only values from a single column - * - * @param string $column - * @return mixed - */ - public function column(string $column) - { - // if there isn't already an explicit order, order by the primary key - // instead of the column that was requested (which would be implied otherwise) - if ($this->order === null) { - $sql = $this->database->sql(); - $primaryKey = $sql->combineIdentifier($this->table, $this->primaryKeyName); - - $this->order($primaryKey . ' ASC'); - } - - $results = $this->query($this->select([$column])->build('select'), [ - 'iterator' => 'array', - 'fetch' => 'array', - ]); - - if ($this->debug === true) { - return $results; - } - - $results = array_column($results, $column); - - if ($this->iterator === 'array') { - return $results; - } - - $iterator = $this->iterator; - - return new $iterator($results); - } - - /** - * Find a single row by column and value - * - * @param string $column - * @param mixed $value - * @return mixed - */ - public function findBy(string $column, $value) - { - return $this->where([$column => $value])->first(); - } - - /** - * Find a single row by its primary key - * - * @param mixed $id - * @return mixed - */ - public function find($id) - { - return $this->findBy($this->primaryKeyName, $id); - } - - /** - * Fires an insert query - * - * @param mixed $values You can pass values here or set them with ->values() before - * @return mixed Returns the last inserted id on success or false. - */ - public function insert($values = null) - { - $query = $this->execute($this->values($values)->build('insert')); - - if ($this->debug === true) { - return $query; - } - - return $query ? $this->database->lastId() : false; - } - - /** - * Fires an update query - * - * @param mixed $values You can pass values here or set them with ->values() before - * @param mixed $where You can pass a where clause here or set it with ->where() before - * @return bool - */ - public function update($values = null, $where = null) - { - return $this->execute($this->values($values)->where($where)->build('update')); - } - - /** - * Fires a delete query - * - * @param mixed $where You can pass a where clause here or set it with ->where() before - * @return bool - */ - public function delete($where = null) - { - return $this->execute($this->where($where)->build('delete')); - } - - /** - * Enables magic queries like findByUsername or findByEmail - * - * @param string $method - * @param array $arguments - * @return mixed - */ - public function __call(string $method, array $arguments = []) - { - if (preg_match('!^findBy([a-z]+)!i', $method, $match)) { - $column = Str::lower($match[1]); - return $this->findBy($column, $arguments[0]); - } else { - throw new InvalidArgumentException('Invalid query method: ' . $method, static::ERROR_INVALID_QUERY_METHOD); - } - } - - /** - * Builder for where and having clauses - * - * @param array $args Arguments, see where() description - * @param mixed $current Current value (like $this->where) - * @return string - */ - protected function filterQuery(array $args, $current) - { - $mode = A::last($args); - $result = ''; - - // if there's a where clause mode attribute attached… - if (in_array($mode, ['AND', 'OR'])) { - // remove that from the list of arguments - array_pop($args); - } else { - $mode = 'AND'; - } - - switch (count($args)) { - case 1: - - if ($args[0] === null) { - return $current; - - // ->where('username like "myuser"'); - } elseif (is_string($args[0]) === true) { - - // simply add the entire string to the where clause - // escaping or using bindings has to be done before calling this method - $result = $args[0]; - - // ->where(['username' => 'myuser']); - } elseif (is_array($args[0]) === true) { - - // simple array mode (AND operator) - $sql = $this->database->sql()->values($this->table, $args[0], ' AND ', true, true); - - $result = $sql['query']; - - $this->bindings($sql['bindings']); - } elseif (is_callable($args[0]) === true) { - $query = clone $this; - - // since the callback uses its own where condition - // it is necessary to clear/reset the cloned where condition - $query->where = null; - - call_user_func($args[0], $query); - - // copy over the bindings from the nested query - $this->bindings = array_merge($this->bindings, $query->bindings); - - $result = '(' . $query->where . ')'; - } - - break; - case 2: - - // ->where('username like :username', ['username' => 'myuser']) - if (is_string($args[0]) === true && is_array($args[1]) === true) { - - // prepared where clause - $result = $args[0]; - - // store the bindings - $this->bindings($args[1]); - - // ->where('username like ?', 'myuser') - } elseif (is_string($args[0]) === true && is_string($args[1]) === true) { - - // prepared where clause - $result = $args[0]; - - // store the bindings - $this->bindings([$args[1]]); - } - - break; - case 3: - - // ->where('username', 'like', 'myuser'); - if (is_string($args[0]) === true && is_string($args[1]) === true) { - - // validate column - $sql = $this->database->sql(); - $key = $sql->columnName($this->table, $args[0]); - - // ->where('username', 'in', ['myuser', 'myotheruser']); - $predicate = trim(strtoupper($args[1])); - if (is_array($args[2]) === true) { - if (in_array($predicate, ['IN', 'NOT IN']) === false) { - throw new InvalidArgumentException('Invalid predicate ' . $predicate); - } - - // build a list of bound values - $values = []; - $bindings = []; - - foreach ($args[2] as $value) { - $valueBinding = $sql->bindingName('value'); - $bindings[$valueBinding] = $value; - $values[] = $valueBinding; - } + public const ERROR_INVALID_QUERY_METHOD = 0; + + /** + * Parent Database object + * + * @var \Kirby\Database\Database + */ + protected $database = null; + + /** + * The object which should be fetched for each row + * or function to call for each row + * + * @var string|\Closure + */ + protected $fetch = 'Kirby\Toolkit\Obj'; + + /** + * The iterator class, which should be used for result sets + * + * @var string + */ + protected $iterator = 'Kirby\Toolkit\Collection'; + + /** + * An array of bindings for the final query + * + * @var array + */ + protected $bindings = []; + + /** + * The table name + * + * @var string + */ + protected $table; + + /** + * The name of the primary key column + * + * @var string + */ + protected $primaryKeyName = 'id'; + + /** + * An array with additional join parameters + * + * @var array + */ + protected $join; + + /** + * A list of columns, which should be selected + * + * @var array|string + */ + protected $select; + + /** + * Boolean for distinct select clauses + * + * @var bool + */ + protected $distinct; + + /** + * Boolean for if exceptions should be thrown on failing queries + * + * @var bool + */ + protected $fail = false; + + /** + * A list of values for update and insert clauses + * + * @var array + */ + protected $values; + + /** + * WHERE clause + * + * @var mixed + */ + protected $where; + + /** + * GROUP BY clause + * + * @var mixed + */ + protected $group; + + /** + * HAVING clause + * + * @var mixed + */ + protected $having; + + /** + * ORDER BY clause + * + * @var mixed + */ + protected $order; + + /** + * The offset, which should be applied to the select query + * + * @var int + */ + protected $offset = 0; + + /** + * The limit, which should be applied to the select query + * + * @var int + */ + protected $limit; + + /** + * Boolean to enable query debugging + * + * @var bool + */ + protected $debug = false; + + /** + * Constructor + * + * @param \Kirby\Database\Database $database Database object + * @param string $table Optional name of the table, which should be queried + */ + public function __construct(Database $database, string $table) + { + $this->database = $database; + $this->table($table); + } + + /** + * Reset the query class after each db hit + */ + protected function reset() + { + $this->bindings = []; + $this->join = null; + $this->select = null; + $this->distinct = null; + $this->fail = false; + $this->values = null; + $this->where = null; + $this->group = null; + $this->having = null; + $this->order = null; + $this->offset = 0; + $this->limit = null; + $this->debug = false; + } + + /** + * Enables query debugging. + * If enabled, the query will return an array with all important info about + * the query instead of actually executing the query and returning results + * + * @param bool $debug + * @return \Kirby\Database\Query + */ + public function debug(bool $debug = true) + { + $this->debug = $debug; + return $this; + } + + /** + * Enables distinct select clauses. + * + * @param bool $distinct + * @return \Kirby\Database\Query + */ + public function distinct(bool $distinct = true) + { + $this->distinct = $distinct; + return $this; + } + + /** + * Enables failing queries. + * If enabled queries will no longer fail silently but throw an exception + * + * @param bool $fail + * @return \Kirby\Database\Query + */ + public function fail(bool $fail = true) + { + $this->fail = $fail; + return $this; + } + + /** + * Sets the object class, which should be fetched; + * set this to `'array'` to get a simple array instead of an object; + * pass a function that receives the `$data` and the `$key` to generate arbitrary data structures + * + * @param string|\Closure $fetch + * @return \Kirby\Database\Query + */ + public function fetch($fetch) + { + $this->fetch = $fetch; + return $this; + } + + /** + * Sets the iterator class, which should be used for multiple results + * Set this to array to get a simple array instead of an iterator object + * + * @param string $iterator + * @return \Kirby\Database\Query + */ + public function iterator(string $iterator) + { + $this->iterator = $iterator; + return $this; + } + + /** + * Sets the name of the table, which should be queried + * + * @param string $table + * @return \Kirby\Database\Query + * @throws \Kirby\Exception\InvalidArgumentException if the table does not exist + */ + public function table(string $table) + { + if ($this->database->validateTable($table) === false) { + throw new InvalidArgumentException('Invalid table: ' . $table); + } + + $this->table = $table; + return $this; + } + + /** + * Sets the name of the primary key column + * + * @param string $primaryKeyName + * @return \Kirby\Database\Query + */ + public function primaryKeyName(string $primaryKeyName) + { + $this->primaryKeyName = $primaryKeyName; + return $this; + } + + /** + * Sets the columns, which should be selected from the table + * By default all columns will be selected + * + * @param mixed $select Pass either a string of columns or an array + * @return \Kirby\Database\Query + */ + public function select($select) + { + $this->select = $select; + return $this; + } + + /** + * Adds a new join clause to the query + * + * @param string $table Name of the table, which should be joined + * @param string $on The on clause for this join + * @param string $type The join type. Uses an inner join by default + * @return $this + */ + public function join(string $table, string $on, string $type = 'JOIN') + { + $join = [ + 'table' => $table, + 'on' => $on, + 'type' => $type + ]; + + $this->join[] = $join; + return $this; + } + + /** + * Shortcut for creating a left join clause + * + * @param string $table Name of the table, which should be joined + * @param string $on The on clause for this join + * @return \Kirby\Database\Query + */ + public function leftJoin(string $table, string $on) + { + return $this->join($table, $on, 'left'); + } + + /** + * Shortcut for creating a right join clause + * + * @param string $table Name of the table, which should be joined + * @param string $on The on clause for this join + * @return \Kirby\Database\Query + */ + public function rightJoin(string $table, string $on) + { + return $this->join($table, $on, 'right'); + } + + /** + * Shortcut for creating an inner join clause + * + * @param string $table Name of the table, which should be joined + * @param string $on The on clause for this join + * @return \Kirby\Database\Query + */ + public function innerJoin($table, $on) + { + return $this->join($table, $on, 'inner join'); + } + + /** + * Sets the values which should be used for the update or insert clause + * + * @param mixed $values Can either be a string or an array of values + * @return \Kirby\Database\Query + */ + public function values($values = []) + { + if ($values !== null) { + $this->values = $values; + } + return $this; + } + + /** + * Attaches additional bindings to the query. + * Also can be used as getter for all attached bindings by not passing an argument. + * + * @param mixed $bindings Array of bindings or null to use this method as getter + * @return array|\Kirby\Database\Query + */ + public function bindings(array $bindings = null) + { + if (is_array($bindings) === true) { + $this->bindings = array_merge($this->bindings, $bindings); + return $this; + } + + return $this->bindings; + } + + /** + * Attaches an additional where clause + * + * All available ways to add where clauses + * + * ->where('username like "myuser"'); (args: 1) + * ->where(['username' => 'myuser']); (args: 1) + * ->where(function($where) { $where->where('id', '=', 1) }) (args: 1) + * ->where('username like ?', 'myuser') (args: 2) + * ->where('username', 'like', 'myuser'); (args: 3) + * + * @param mixed ...$args + * @return \Kirby\Database\Query + */ + public function where(...$args) + { + $this->where = $this->filterQuery($args, $this->where); + return $this; + } + + /** + * Shortcut to attach a where clause with an OR operator. + * Check out the where() method docs for additional info. + * + * @param mixed ...$args + * @return \Kirby\Database\Query + */ + public function orWhere(...$args) + { + $mode = A::last($args); + + // if there's a where clause mode attribute attached… + if (in_array($mode, ['AND', 'OR']) === true) { + // remove that from the list of arguments + array_pop($args); + } + + // make sure to always attach the OR mode indicator + $args[] = 'OR'; + + $this->where(...$args); + return $this; + } + + /** + * Shortcut to attach a where clause with an AND operator. + * Check out the where() method docs for additional info. + * + * @param mixed ...$args + * @return \Kirby\Database\Query + */ + public function andWhere(...$args) + { + $mode = A::last($args); + + // if there's a where clause mode attribute attached… + if (in_array($mode, ['AND', 'OR']) === true) { + // remove that from the list of arguments + array_pop($args); + } + + // make sure to always attach the AND mode indicator + $args[] = 'AND'; + + $this->where(...$args); + return $this; + } + + /** + * Attaches a group by clause + * + * @param string|null $group + * @return \Kirby\Database\Query + */ + public function group(string $group = null) + { + $this->group = $group; + return $this; + } + + /** + * Attaches an additional having clause + * + * All available ways to add having clauses + * + * ->having('username like "myuser"'); (args: 1) + * ->having(['username' => 'myuser']); (args: 1) + * ->having(function($having) { $having->having('id', '=', 1) }) (args: 1) + * ->having('username like ?', 'myuser') (args: 2) + * ->having('username', 'like', 'myuser'); (args: 3) + * + * @param mixed ...$args + * @return \Kirby\Database\Query + */ + public function having(...$args) + { + $this->having = $this->filterQuery($args, $this->having); + return $this; + } + + /** + * Attaches an order clause + * + * @param string|null $order + * @return \Kirby\Database\Query + */ + public function order(string $order = null) + { + $this->order = $order; + return $this; + } + + /** + * Sets the offset for select clauses + * + * @param int|null $offset + * @return \Kirby\Database\Query + */ + public function offset(int $offset = null) + { + $this->offset = $offset; + return $this; + } + + /** + * Sets the limit for select clauses + * + * @param int|null $limit + * @return \Kirby\Database\Query + */ + public function limit(int $limit = null) + { + $this->limit = $limit; + return $this; + } + + /** + * Builds the different types of SQL queries + * This uses the SQL class to build stuff. + * + * @param string $type (select, update, insert) + * @return array The final query + */ + public function build(string $type) + { + $sql = $this->database->sql(); + + switch ($type) { + case 'select': + return $sql->select([ + 'table' => $this->table, + 'columns' => $this->select, + 'join' => $this->join, + 'distinct' => $this->distinct, + 'where' => $this->where, + 'group' => $this->group, + 'having' => $this->having, + 'order' => $this->order, + 'offset' => $this->offset, + 'limit' => $this->limit, + 'bindings' => $this->bindings + ]); + case 'update': + return $sql->update([ + 'table' => $this->table, + 'where' => $this->where, + 'values' => $this->values, + 'bindings' => $this->bindings + ]); + case 'insert': + return $sql->insert([ + 'table' => $this->table, + 'values' => $this->values, + 'bindings' => $this->bindings + ]); + case 'delete': + return $sql->delete([ + 'table' => $this->table, + 'where' => $this->where, + 'bindings' => $this->bindings + ]); + } + } + + /** + * Builds a count query + * + * @return int + */ + public function count(): int + { + return (int)$this->aggregate('COUNT'); + } + + /** + * Builds a max query + * + * @param string $column + * @return float + */ + public function max(string $column): float + { + return (float)$this->aggregate('MAX', $column); + } + + /** + * Builds a min query + * + * @param string $column + * @return float + */ + public function min(string $column): float + { + return (float)$this->aggregate('MIN', $column); + } + + /** + * Builds a sum query + * + * @param string $column + * @return float + */ + public function sum(string $column): float + { + return (float)$this->aggregate('SUM', $column); + } + + /** + * Builds an average query + * + * @param string $column + * @return float + */ + public function avg(string $column): float + { + return (float)$this->aggregate('AVG', $column); + } + + /** + * Builds an aggregation query. + * This is used by all the aggregation methods above + * + * @param string $method + * @param string $column + * @param int $default An optional default value, which should be returned if the query fails + * @return mixed + */ + public function aggregate(string $method, string $column = '*', $default = 0) + { + // reset the sorting to avoid counting issues + $this->order = null; + + // validate column + if ($column !== '*') { + $sql = $this->database->sql(); + $column = $sql->columnName($this->table, $column); + } + + $fetch = $this->fetch; + $row = $this->select($method . '(' . $column . ') as aggregation')->fetch('Obj')->first(); + + if ($this->debug === true) { + return $row; + } + + $result = $row ? $row->get('aggregation') : $default; + + $this->fetch($fetch); + + return $result; + } + + /** + * Used as an internal shortcut for firing a db query + * + * @param string|array $sql + * @param array $params + * @return mixed + */ + protected function query($sql, array $params = []) + { + if (is_string($sql) === true) { + $sql = [ + 'query' => $sql, + 'bindings' => $this->bindings() + ]; + } + + if ($this->debug) { + return [ + 'query' => $sql['query'], + 'bindings' => $this->bindings(), + 'options' => $params + ]; + } + + if ($this->fail) { + $this->database->fail(); + } + + $result = $this->database->query($sql['query'], $sql['bindings'], $params); + + $this->reset(); + + return $result; + } + + /** + * Used as an internal shortcut for executing a db query + * + * @param string|array $sql + * @param array $params + * @return mixed + */ + protected function execute($sql, array $params = []) + { + if (is_string($sql) === true) { + $sql = [ + 'query' => $sql, + 'bindings' => $this->bindings() + ]; + } + + if ($this->debug === true) { + return [ + 'query' => $sql['query'], + 'bindings' => $sql['bindings'], + 'options' => $params + ]; + } + + if ($this->fail) { + $this->database->fail(); + } + + $result = $this->database->execute($sql['query'], $sql['bindings']); + + $this->reset(); + + return $result; + } + + /** + * Selects only one row from a table + * + * @return object + */ + public function first() + { + return $this->query($this->offset(0)->limit(1)->build('select'), [ + 'fetch' => $this->fetch, + 'iterator' => 'array', + 'method' => 'fetch', + ]); + } + + /** + * Selects only one row from a table + * + * @return object + */ + public function row() + { + return $this->first(); + } + + /** + * Selects only one row from a table + * + * @return object + */ + public function one() + { + return $this->first(); + } + + /** + * Automatically adds pagination to a query + * + * @param int $page + * @param int $limit The number of rows, which should be returned for each page + * @return object Collection iterator with attached pagination object + */ + public function page(int $page, int $limit) + { + // clone this to create a counter query + $counter = clone $this; + + // count the total number of rows for this query + $count = $counter->debug(false)->count(); + + // pagination + $pagination = new Pagination([ + 'limit' => $limit, + 'page' => $page, + 'total' => $count, + ]); + + // apply it to the dataset and retrieve all rows. make sure to use Collection as the iterator to be able to attach the pagination object + $iterator = $this->iterator; + $collection = $this + ->offset($pagination->offset()) + ->limit($pagination->limit()) + ->iterator('Kirby\Toolkit\Collection') + ->all(); + + $this->iterator($iterator); + + // return debug information if debug mode is active + if ($this->debug) { + $collection['totalcount'] = $count; + return $collection; + } + + // store all pagination vars in a separate object + if ($collection) { + $collection->paginate($pagination); + } + + // return the limited collection + return $collection; + } + + /** + * Returns all matching rows from a table + * + * @return mixed + */ + public function all() + { + return $this->query($this->build('select'), [ + 'fetch' => $this->fetch, + 'iterator' => $this->iterator, + ]); + } + + /** + * Returns only values from a single column + * + * @param string $column + * @return mixed + */ + public function column(string $column) + { + // if there isn't already an explicit order, order by the primary key + // instead of the column that was requested (which would be implied otherwise) + if ($this->order === null) { + $sql = $this->database->sql(); + $primaryKey = $sql->combineIdentifier($this->table, $this->primaryKeyName); + + $this->order($primaryKey . ' ASC'); + } + + $results = $this->query($this->select([$column])->build('select'), [ + 'iterator' => 'array', + 'fetch' => 'array', + ]); + + if ($this->debug === true) { + return $results; + } + + $results = array_column($results, $column); + + if ($this->iterator === 'array') { + return $results; + } + + $iterator = $this->iterator; + + return new $iterator($results); + } + + /** + * Find a single row by column and value + * + * @param string $column + * @param mixed $value + * @return mixed + */ + public function findBy(string $column, $value) + { + return $this->where([$column => $value])->first(); + } + + /** + * Find a single row by its primary key + * + * @param mixed $id + * @return mixed + */ + public function find($id) + { + return $this->findBy($this->primaryKeyName, $id); + } + + /** + * Fires an insert query + * + * @param mixed $values You can pass values here or set them with ->values() before + * @return mixed Returns the last inserted id on success or false. + */ + public function insert($values = null) + { + $query = $this->execute($this->values($values)->build('insert')); + + if ($this->debug === true) { + return $query; + } + + return $query ? $this->database->lastId() : false; + } + + /** + * Fires an update query + * + * @param mixed $values You can pass values here or set them with ->values() before + * @param mixed $where You can pass a where clause here or set it with ->where() before + * @return bool + */ + public function update($values = null, $where = null) + { + return $this->execute($this->values($values)->where($where)->build('update')); + } + + /** + * Fires a delete query + * + * @param mixed $where You can pass a where clause here or set it with ->where() before + * @return bool + */ + public function delete($where = null) + { + return $this->execute($this->where($where)->build('delete')); + } + + /** + * Enables magic queries like findByUsername or findByEmail + * + * @param string $method + * @param array $arguments + * @return mixed + */ + public function __call(string $method, array $arguments = []) + { + if (preg_match('!^findBy([a-z]+)!i', $method, $match)) { + $column = Str::lower($match[1]); + return $this->findBy($column, $arguments[0]); + } else { + throw new InvalidArgumentException('Invalid query method: ' . $method, static::ERROR_INVALID_QUERY_METHOD); + } + } + + /** + * Builder for where and having clauses + * + * @param array $args Arguments, see where() description + * @param mixed $current Current value (like $this->where) + * @return string + */ + protected function filterQuery(array $args, $current) + { + $mode = A::last($args); + $result = ''; + + // if there's a where clause mode attribute attached… + if (in_array($mode, ['AND', 'OR'])) { + // remove that from the list of arguments + array_pop($args); + } else { + $mode = 'AND'; + } + + switch (count($args)) { + case 1: + + if ($args[0] === null) { + return $current; + + // ->where('username like "myuser"'); + } elseif (is_string($args[0]) === true) { + + // simply add the entire string to the where clause + // escaping or using bindings has to be done before calling this method + $result = $args[0]; + + // ->where(['username' => 'myuser']); + } elseif (is_array($args[0]) === true) { + + // simple array mode (AND operator) + $sql = $this->database->sql()->values($this->table, $args[0], ' AND ', true, true); + + $result = $sql['query']; + + $this->bindings($sql['bindings']); + } elseif (is_callable($args[0]) === true) { + $query = clone $this; + + // since the callback uses its own where condition + // it is necessary to clear/reset the cloned where condition + $query->where = null; + + call_user_func($args[0], $query); + + // copy over the bindings from the nested query + $this->bindings = array_merge($this->bindings, $query->bindings); + + $result = '(' . $query->where . ')'; + } + + break; + case 2: + + // ->where('username like :username', ['username' => 'myuser']) + if (is_string($args[0]) === true && is_array($args[1]) === true) { + + // prepared where clause + $result = $args[0]; + + // store the bindings + $this->bindings($args[1]); + + // ->where('username like ?', 'myuser') + } elseif (is_string($args[0]) === true && is_string($args[1]) === true) { + + // prepared where clause + $result = $args[0]; + + // store the bindings + $this->bindings([$args[1]]); + } + + break; + case 3: + + // ->where('username', 'like', 'myuser'); + if (is_string($args[0]) === true && is_string($args[1]) === true) { + + // validate column + $sql = $this->database->sql(); + $key = $sql->columnName($this->table, $args[0]); + + // ->where('username', 'in', ['myuser', 'myotheruser']); + $predicate = trim(strtoupper($args[1])); + if (is_array($args[2]) === true) { + if (in_array($predicate, ['IN', 'NOT IN']) === false) { + throw new InvalidArgumentException('Invalid predicate ' . $predicate); + } + + // build a list of bound values + $values = []; + $bindings = []; + + foreach ($args[2] as $value) { + $valueBinding = $sql->bindingName('value'); + $bindings[$valueBinding] = $value; + $values[] = $valueBinding; + } - // add that to the where clause in parenthesis - $result = $key . ' ' . $predicate . ' (' . implode(', ', $values) . ')'; + // add that to the where clause in parenthesis + $result = $key . ' ' . $predicate . ' (' . implode(', ', $values) . ')'; - // ->where('username', 'like', 'myuser'); - } else { - $predicates = [ - '=', '>=', '>', '<=', '<', '<>', '!=', '<=>', - 'IS', 'IS NOT', - 'BETWEEN', 'NOT BETWEEN', - 'LIKE', 'NOT LIKE', - 'SOUNDS LIKE', - 'REGEXP', 'NOT REGEXP' - ]; + // ->where('username', 'like', 'myuser'); + } else { + $predicates = [ + '=', '>=', '>', '<=', '<', '<>', '!=', '<=>', + 'IS', 'IS NOT', + 'BETWEEN', 'NOT BETWEEN', + 'LIKE', 'NOT LIKE', + 'SOUNDS LIKE', + 'REGEXP', 'NOT REGEXP' + ]; - if (in_array($predicate, $predicates) === false) { - throw new InvalidArgumentException('Invalid predicate/operator ' . $predicate); - } + if (in_array($predicate, $predicates) === false) { + throw new InvalidArgumentException('Invalid predicate/operator ' . $predicate); + } - $valueBinding = $sql->bindingName('value'); - $bindings[$valueBinding] = $args[2]; + $valueBinding = $sql->bindingName('value'); + $bindings[$valueBinding] = $args[2]; - $result = $key . ' ' . $predicate . ' ' . $valueBinding; - } - $this->bindings($bindings); - } + $result = $key . ' ' . $predicate . ' ' . $valueBinding; + } + $this->bindings($bindings); + } - break; + break; - } + } - // attach the where clause - if (empty($current) === false) { - return $current . ' ' . $mode . ' ' . $result; - } else { - return $result; - } - } + // attach the where clause + if (empty($current) === false) { + return $current . ' ' . $mode . ' ' . $result; + } else { + return $result; + } + } } diff --git a/kirby/src/Database/Sql.php b/kirby/src/Database/Sql.php index 52ba287..2228c29 100755 --- a/kirby/src/Database/Sql.php +++ b/kirby/src/Database/Sql.php @@ -17,950 +17,951 @@ use Kirby\Toolkit\Str; */ abstract class Sql { - /** - * List of literals which should not be escaped in queries - * - * @var array - */ - public static $literals = ['NOW()', null]; - - /** - * The parent database connection - * - * @var \Kirby\Database\Database - */ - protected $database; - - /** - * List of used bindings; used to avoid - * duplicate binding names - * - * @var array - */ - protected $bindings = []; - - /** - * Constructor - * @codeCoverageIgnore - * - * @param \Kirby\Database\Database $database - */ - public function __construct($database) - { - $this->database = $database; - } - - /** - * Returns a randomly generated binding name - * - * @param string $label String that only contains alphanumeric chars and - * underscores to use as a human-readable identifier - * @return string Binding name that is guaranteed to be unique for this connection - */ - public function bindingName(string $label): string - { - // make sure that the binding name is safe to prevent injections; - // otherwise use a generic label - if (!$label || preg_match('/^[a-zA-Z0-9_]+$/', $label) !== 1) { - $label = 'invalid'; - } - - // generate random bindings until the name is unique - do { - $binding = ':' . $label . '_' . Str::random(8, 'alphaNum'); - } while (in_array($binding, $this->bindings) === true); - - // cache the generated binding name for future invocations - $this->bindings[] = $binding; - return $binding; - } - - /** - * Returns a query to list the columns of a specified table; - * the query needs to return rows with a column `name` - * - * @param string $table Table name - * @return array - */ - abstract public function columns(string $table): array; - - /** - * Returns a query snippet for a column default value - * - * @param string $name Column name - * @param array $column Column definition array with an optional `default` key - * @return array Array with a `query` string and a `bindings` array - */ - public function columnDefault(string $name, array $column): array - { - if (isset($column['default']) === false) { - return [ - 'query' => null, - 'bindings' => [] - ]; - } - - $binding = $this->bindingName($name . '_default'); - - return [ - 'query' => 'DEFAULT ' . $binding, - 'bindings' => [ - $binding => $column['default'] - ] - ]; - } - - /** - * Returns the cleaned identifier based on the table and column name - * - * @param string $table Table name - * @param string $column Column name - * @param bool $enforceQualified If true, a qualified identifier is returned in all cases - * @return string|null Identifier or null if the table or column is invalid - */ - public function columnName(string $table, string $column, bool $enforceQualified = false): ?string - { - // ensure we have clean $table and $column values without qualified identifiers - list($table, $column) = $this->splitIdentifier($table, $column); - - // combine the identifiers again - if ($this->database->validateColumn($table, $column) === true) { - return $this->combineIdentifier($table, $column, $enforceQualified !== true); - } - - // the table or column does not exist - return null; - } - - /** - * Abstracted column types to simplify table - * creation for multiple database drivers - * @codeCoverageIgnore - * - * @return array - */ - public function columnTypes(): array - { - return [ - 'id' => '{{ name }} INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', - 'varchar' => '{{ name }} varchar(255) {{ null }} {{ default }} {{ unique }}', - 'text' => '{{ name }} TEXT {{ unique }}', - 'int' => '{{ name }} INT(11) UNSIGNED {{ null }} {{ default }} {{ unique }}', - 'timestamp' => '{{ name }} TIMESTAMP {{ null }} {{ default }} {{ unique }}' - ]; - } - - /** - * Combines an identifier (table and column) - * - * @param $table string - * @param $column string - * @param $values bool Whether the identifier is going to be used for a VALUES clause; - * only relevant for SQLite - * @return string - */ - public function combineIdentifier(string $table, string $column, bool $values = false): string - { - return $this->quoteIdentifier($table) . '.' . $this->quoteIdentifier($column); - } - - /** - * Creates the CREATE TABLE syntax for a single column - * - * @param string $name Column name - * @param array $column Column definition array; valid keys: - * - `type` (required): Column template to use - * - `null`: Whether the column may be NULL (boolean) - * - `key`: Index this column is part of; special values `'primary'` for PRIMARY KEY and `true` for automatic naming - * - `unique`: Whether the index (or if not set the column itself) has a UNIQUE constraint - * - `default`: Default value of this column - * @return array Array with `query` and `key` strings, a `unique` boolean and a `bindings` array - * @throws \Kirby\Exception\InvalidArgumentException if no column type is given or the column type is not supported. - */ - public function createColumn(string $name, array $column): array - { - // column type - if (isset($column['type']) === false) { - throw new InvalidArgumentException('No column type given for column ' . $name); - } - $template = $this->columnTypes()[$column['type']] ?? null; - if (!$template) { - throw new InvalidArgumentException('Unsupported column type: ' . $column['type']); - } - - // null option - if (A::get($column, 'null') === false) { - $null = 'NOT NULL'; - } else { - $null = 'NULL'; - } - - // indexes/keys - if (isset($column['key']) === true) { - if (is_string($column['key']) === true) { - $column['key'] = strtolower($column['key']); - } elseif ($column['key'] === true) { - $column['key'] = $name . '_index'; - } - } - - // unique - $uniqueKey = false; - $uniqueColumn = null; - if (isset($column['unique']) === true && $column['unique'] === true) { - if (isset($column['key']) === true) { - // this column is part of an index, make that unique - $uniqueKey = true; - } else { - // make the column itself unique - $uniqueColumn = 'UNIQUE'; - } - } - - // default value - $columnDefault = $this->columnDefault($name, $column); - - $query = trim(Str::template($template, [ - 'name' => $this->quoteIdentifier($name), - 'null' => $null, - 'default' => $columnDefault['query'], - 'unique' => $uniqueColumn - ], ['fallback' => ''])); - - return [ - 'query' => $query, - 'bindings' => $columnDefault['bindings'], - 'key' => $column['key'] ?? null, - 'unique' => $uniqueKey - ]; - } - - /** - * Creates the inner query for the columns in a CREATE TABLE query - * - * @param array $columns Array of column definition arrays, see `Kirby\Database\Sql::createColumn()` - * @return array Array with a `query` string and `bindings`, `keys` and `unique` arrays - */ - public function createTableInner(array $columns): array - { - $query = []; - $bindings = []; - $keys = []; - $unique = []; - - foreach ($columns as $name => $column) { - $sql = $this->createColumn($name, $column); - - // collect query and bindings - $query[] = $sql['query']; - $bindings += $sql['bindings']; - - // make a list of keys per key name - if ($sql['key'] !== null) { - if (isset($keys[$sql['key']]) !== true) { - $keys[$sql['key']] = []; - } - - $keys[$sql['key']][] = $name; - if ($sql['unique'] === true) { - $unique[$sql['key']] = true; - } - } - } - - return [ - 'query' => implode(',' . PHP_EOL, $query), - 'bindings' => $bindings, - 'keys' => $keys, - 'unique' => $unique - ]; - } - - /** - * Creates a CREATE TABLE query - * - * @param string $table Table name - * @param array $columns Array of column definition arrays, see `Kirby\Database\Sql::createColumn()` - * @return array Array with a `query` string and a `bindings` array - */ - public function createTable(string $table, array $columns = []): array - { - $inner = $this->createTableInner($columns); - - // add keys - foreach ($inner['keys'] as $key => $columns) { - // quote each column name and make a list string out of the column names - $columns = implode(', ', array_map( - fn ($name) => $this->quoteIdentifier($name), - $columns - )); - - if ($key === 'primary') { - $key = 'PRIMARY KEY'; - } else { - $unique = isset($inner['unique'][$key]) === true ? 'UNIQUE ' : ''; - $key = $unique . 'INDEX ' . $this->quoteIdentifier($key); - } - - $inner['query'] .= ',' . PHP_EOL . $key . ' (' . $columns . ')'; - } - - return [ - 'query' => 'CREATE TABLE ' . $this->quoteIdentifier($table) . ' (' . PHP_EOL . $inner['query'] . PHP_EOL . ')', - 'bindings' => $inner['bindings'] - ]; - } - - /** - * Builds a DELETE clause - * - * @param array $params List of parameters for the DELETE clause. See defaults for more info. - * @return array - */ - public function delete(array $params = []): array - { - $defaults = [ - 'table' => '', - 'where' => null, - 'bindings' => [] - ]; - - $options = array_merge($defaults, $params); - $bindings = $options['bindings']; - $query = ['DELETE']; - - // from - $this->extend($query, $bindings, $this->from($options['table'])); - - // where - $this->extend($query, $bindings, $this->where($options['where'])); - - return [ - 'query' => $this->query($query), - 'bindings' => $bindings - ]; - } - - /** - * Creates the sql for dropping a single table - * - * @param string $table - * @return array - */ - public function dropTable(string $table): array - { - return [ - 'query' => 'DROP TABLE ' . $this->tableName($table), - 'bindings' => [] - ]; - } - - /** - * Extends a given query and bindings - * by reference - * - * @param array $query - * @param array $bindings - * @param array $input - * @return void - */ - public function extend(&$query, array &$bindings, $input) - { - if (empty($input['query']) === false) { - $query[] = $input['query']; - $bindings = array_merge($bindings, $input['bindings']); - } - } - - /** - * Creates the from syntax - * - * @param string $table - * @return array - */ - public function from(string $table): array - { - return [ - 'query' => 'FROM ' . $this->tableName($table), - 'bindings' => [] - ]; - } - - /** - * Creates the group by syntax - * - * @param string $group - * @return array - */ - public function group(string $group = null): array - { - if (empty($group) === true) { - return [ - 'query' => null, - 'bindings' => [] - ]; - } - - return [ - 'query' => 'GROUP BY ' . $group, - 'bindings' => [] - ]; - } - - /** - * Creates the having syntax - * - * @param string|null $having - * @return array - */ - public function having(string $having = null): array - { - if (empty($having) === true) { - return [ - 'query' => null, - 'bindings' => [] - ]; - } - - return [ - 'query' => 'HAVING ' . $having, - 'bindings' => [] - ]; - } - - /** - * Creates an insert query - * - * @param array $params - * @return array - */ - public function insert(array $params = []): array - { - $table = $params['table'] ?? null; - $values = $params['values'] ?? null; - $bindings = $params['bindings']; - $query = ['INSERT INTO ' . $this->tableName($table)]; - - // add the values - $this->extend($query, $bindings, $this->values($table, $values, ', ', false)); - - return [ - 'query' => $this->query($query), - 'bindings' => $bindings - ]; - } - - /** - * Creates a join query - * - * @param string $table - * @param string $type - * @param string $on - * @return array - * @throws \Kirby\Exception\InvalidArgumentException if an invalid join type is given - */ - public function join(string $type, string $table, string $on): array - { - $types = [ - 'JOIN', - 'INNER JOIN', - 'OUTER JOIN', - 'LEFT OUTER JOIN', - 'LEFT JOIN', - 'RIGHT OUTER JOIN', - 'RIGHT JOIN', - 'FULL OUTER JOIN', - 'FULL JOIN', - 'NATURAL JOIN', - 'CROSS JOIN', - 'SELF JOIN' - ]; - - $type = strtoupper(trim($type)); - - // validate join type - if (in_array($type, $types) === false) { - throw new InvalidArgumentException('Invalid join type ' . $type); - } - - return [ - 'query' => $type . ' ' . $this->tableName($table) . ' ON ' . $on, - 'bindings' => [], - ]; - } - - /** - * Create the syntax for multiple joins - * - * @param array|null $joins - * @return array - */ - public function joins(array $joins = null): array - { - $query = []; - $bindings = []; - - foreach ((array)$joins as $join) { - $this->extend($query, $bindings, $this->join($join['type'] ?? 'JOIN', $join['table'] ?? null, $join['on'] ?? null)); - } - - return [ - 'query' => implode(' ', array_filter($query)), - 'bindings' => [], - ]; - } - - /** - * Creates a limit and offset query instruction - * - * @param int $offset - * @param int|null $limit - * @return array - */ - public function limit(int $offset = 0, int $limit = null): array - { - // no need to add it to the query - if ($offset === 0 && $limit === null) { - return [ - 'query' => null, - 'bindings' => [] - ]; - } - - $limit ??= '18446744073709551615'; - - $offsetBinding = $this->bindingName('offset'); - $limitBinding = $this->bindingName('limit'); - - return [ - 'query' => 'LIMIT ' . $offsetBinding . ', ' . $limitBinding, - 'bindings' => [ - $limitBinding => $limit, - $offsetBinding => $offset, - ] - ]; - } - - /** - * Creates the order by syntax - * - * @param string $order - * @return array - */ - public function order(string $order = null): array - { - if (empty($order) === true) { - return [ - 'query' => null, - 'bindings' => [] - ]; - } - - return [ - 'query' => 'ORDER BY ' . $order, - 'bindings' => [] - ]; - } - - /** - * Converts a query array into a final string - * - * @param array $query - * @param string $separator - * @return string - */ - public function query(array $query, string $separator = ' ') - { - return implode($separator, array_filter($query)); - } - - /** - * Quotes an identifier (table *or* column) - * - * @param $identifier string - * @return string - */ - public function quoteIdentifier(string $identifier): string - { - // * is special, don't quote that - if ($identifier === '*') { - return $identifier; - } - - // escape backticks inside the identifier name - $identifier = str_replace('`', '``', $identifier); - - // wrap in backticks - return '`' . $identifier . '`'; - } - - /** - * Builds a select clause - * - * @param array $params List of parameters for the select clause. Check out the defaults for more info. - * @return array An array with the query and the bindings - */ - public function select(array $params = []): array - { - $defaults = [ - 'table' => '', - 'columns' => '*', - 'join' => null, - 'distinct' => false, - 'where' => null, - 'group' => null, - 'having' => null, - 'order' => null, - 'offset' => 0, - 'limit' => null, - 'bindings' => [] - ]; - - $options = array_merge($defaults, $params); - $bindings = $options['bindings']; - $query = ['SELECT']; - - // select distinct values - if ($options['distinct'] === true) { - $query[] = 'DISTINCT'; - } - - // columns - $query[] = $this->selected($options['table'], $options['columns']); - - // from - $this->extend($query, $bindings, $this->from($options['table'])); - - // joins - $this->extend($query, $bindings, $this->joins($options['join'])); - - // where - $this->extend($query, $bindings, $this->where($options['where'])); - - // group - $this->extend($query, $bindings, $this->group($options['group'])); - - // having - $this->extend($query, $bindings, $this->having($options['having'])); - - // order - $this->extend($query, $bindings, $this->order($options['order'])); - - // offset and limit - $this->extend($query, $bindings, $this->limit($options['offset'], $options['limit'])); - - return [ - 'query' => $this->query($query), - 'bindings' => $bindings - ]; - } - - /** - * Creates a columns definition from string or array - * - * @param string $table - * @param array|string|null $columns - * @return string - */ - public function selected($table, $columns = null): string - { - // all columns - if (empty($columns) === true) { - return '*'; - } - - // array of columns - if (is_array($columns) === true) { - - // validate columns - $result = []; - - foreach ($columns as $column) { - list($table, $columnPart) = $this->splitIdentifier($table, $column); - - if ($this->validateColumn($table, $columnPart) === true) { - $result[] = $this->combineIdentifier($table, $columnPart); - } - } - - return implode(', ', $result); - } else { - return $columns; - } - } - - /** - * Splits a (qualified) identifier into table and column - * - * @param $table string Default table if the identifier is not qualified - * @param $identifier string - * @return array - * @throws \Kirby\Exception\InvalidArgumentException if an invalid identifier is given - */ - public function splitIdentifier($table, $identifier): array - { - // split by dot, but only outside of quotes - $parts = preg_split('/(?:`[^`]*`|"[^"]*")(*SKIP)(*F)|\./', $identifier); - - switch (count($parts)) { - // non-qualified identifier - case 1: - return [$table, $this->unquoteIdentifier($parts[0])]; - - // qualified identifier - case 2: - return [$this->unquoteIdentifier($parts[0]), $this->unquoteIdentifier($parts[1])]; - - // every other number is an error - default: - throw new InvalidArgumentException('Invalid identifier ' . $identifier); - } - } - - /** - * Returns a query to list the tables of the current database; - * the query needs to return rows with a column `name` - * - * @return array - */ - abstract public function tables(): array; - - /** - * Validates and quotes a table name - * - * @param string $table - * @return string - * @throws \Kirby\Exception\InvalidArgumentException if an invalid table name is given - */ - public function tableName(string $table): string - { - // validate table - if ($this->database->validateTable($table) === false) { - throw new InvalidArgumentException('Invalid table ' . $table); - } - - return $this->quoteIdentifier($table); - } - - /** - * Unquotes an identifier (table *or* column) - * - * @param $identifier string - * @return string - */ - public function unquoteIdentifier(string $identifier): string - { - // remove quotes around the identifier - if (in_array(Str::substr($identifier, 0, 1), ['"', '`']) === true) { - $identifier = Str::substr($identifier, 1); - } - - if (in_array(Str::substr($identifier, -1), ['"', '`']) === true) { - $identifier = Str::substr($identifier, 0, -1); - } - - // unescape duplicated quotes - return str_replace(['""', '``'], ['"', '`'], $identifier); - } - - /** - * Builds an update clause - * - * @param array $params List of parameters for the update clause. See defaults for more info. - * @return array - */ - public function update(array $params = []): array - { - $defaults = [ - 'table' => null, - 'values' => null, - 'where' => null, - 'bindings' => [] - ]; - - $options = array_merge($defaults, $params); - $bindings = $options['bindings']; - - // start the query - $query = ['UPDATE ' . $this->tableName($options['table']) . ' SET']; - - // add the values - $this->extend($query, $bindings, $this->values($options['table'], $options['values'])); - - // add the where clause - $this->extend($query, $bindings, $this->where($options['where'])); - - return [ - 'query' => $this->query($query), - 'bindings' => $bindings - ]; - } - - /** - * Validates a given column name in a table - * - * @param string $table - * @param string $column - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException If the column is invalid - */ - public function validateColumn(string $table, string $column): bool - { - if ($this->database->validateColumn($table, $column) !== true) { - throw new InvalidArgumentException('Invalid column ' . $column); - } - - return true; - } - - /** - * Builds a safe list of values for insert, select or update queries - * - * @param string $table Table name - * @param mixed $values A value string or array of values - * @param string $separator A separator which should be used to join values - * @param bool $set If true builds a set list of values for update clauses - * @param bool $enforceQualified Always use fully qualified column names - */ - public function values(string $table, $values, string $separator = ', ', bool $set = true, bool $enforceQualified = false): array - { - if (is_array($values) === false) { - return [ - 'query' => $values, - 'bindings' => [] - ]; - } - - if ($set === true) { - return $this->valueSet($table, $values, $separator, $enforceQualified); - } else { - return $this->valueList($table, $values, $separator, $enforceQualified); - } - } - - /** - * Creates a list of fields and values - * - * @param string $table - * @param string|array $values - * @param string $separator - * @param bool $enforceQualified - * @param array - */ - public function valueList(string $table, $values, string $separator = ',', bool $enforceQualified = false): array - { - $fields = []; - $query = []; - $bindings = []; - - foreach ($values as $column => $value) { - $key = $this->columnName($table, $column, $enforceQualified); - - if ($key === null) { - continue; - } - - $fields[] = $key; - - if (in_array($value, static::$literals, true) === true) { - $query[] = $value ?: 'null'; - continue; - } - - if (is_array($value) === true) { - $value = json_encode($value); - } - - // add the binding - $bindings[$bindingName = $this->bindingName('value')] = $value; - - // create the query - $query[] = $bindingName; - } - - return [ - 'query' => '(' . implode($separator, $fields) . ') VALUES (' . implode($separator, $query) . ')', - 'bindings' => $bindings - ]; - } - - /** - * Creates a set of values - * - * @param string $table - * @param string|array $values - * @param string $separator - * @param bool $enforceQualified - * @param array - * @return array - */ - public function valueSet(string $table, $values, string $separator = ',', bool $enforceQualified = false): array - { - $query = []; - $bindings = []; - - foreach ($values as $column => $value) { - $key = $this->columnName($table, $column, $enforceQualified); - - if ($key === null) { - continue; - } - - if (in_array($value, static::$literals, true) === true) { - $query[] = $key . ' = ' . ($value ?: 'null'); - continue; - } - - if (is_array($value) === true) { - $value = json_encode($value); - } - - // add the binding - $bindings[$bindingName = $this->bindingName('value')] = $value; - - // create the query - $query[] = $key . ' = ' . $bindingName; - } - - return [ - 'query' => implode($separator, $query), - 'bindings' => $bindings - ]; - } - - /** - * @param string|array|null $where - * @param array $bindings - * @return array - */ - public function where($where, array $bindings = []): array - { - if (empty($where) === true) { - return [ - 'query' => null, - 'bindings' => [], - ]; - } - - if (is_string($where) === true) { - return [ - 'query' => 'WHERE ' . $where, - 'bindings' => $bindings - ]; - } - - $query = []; - - foreach ($where as $key => $value) { - $binding = $this->bindingName('where_' . $key); - $bindings[$binding] = $value; - - $query[] = $key . ' = ' . $binding; - } - - return [ - 'query' => 'WHERE ' . implode(' AND ', $query), - 'bindings' => $bindings - ]; - } + /** + * List of literals which should not be escaped in queries + * + * @var array + */ + public static $literals = ['NOW()', null]; + + /** + * The parent database connection + * + * @var \Kirby\Database\Database + */ + protected $database; + + /** + * List of used bindings; used to avoid + * duplicate binding names + * + * @var array + */ + protected $bindings = []; + + /** + * Constructor + * @codeCoverageIgnore + * + * @param \Kirby\Database\Database $database + */ + public function __construct($database) + { + $this->database = $database; + } + + /** + * Returns a randomly generated binding name + * + * @param string $label String that only contains alphanumeric chars and + * underscores to use as a human-readable identifier + * @return string Binding name that is guaranteed to be unique for this connection + */ + public function bindingName(string $label): string + { + // make sure that the binding name is safe to prevent injections; + // otherwise use a generic label + if (!$label || preg_match('/^[a-zA-Z0-9_]+$/', $label) !== 1) { + $label = 'invalid'; + } + + // generate random bindings until the name is unique + do { + $binding = ':' . $label . '_' . Str::random(8, 'alphaNum'); + } while (in_array($binding, $this->bindings) === true); + + // cache the generated binding name for future invocations + $this->bindings[] = $binding; + return $binding; + } + + /** + * Returns a query to list the columns of a specified table; + * the query needs to return rows with a column `name` + * + * @param string $table Table name + * @return array + */ + abstract public function columns(string $table): array; + + /** + * Returns a query snippet for a column default value + * + * @param string $name Column name + * @param array $column Column definition array with an optional `default` key + * @return array Array with a `query` string and a `bindings` array + */ + public function columnDefault(string $name, array $column): array + { + if (isset($column['default']) === false) { + return [ + 'query' => null, + 'bindings' => [] + ]; + } + + $binding = $this->bindingName($name . '_default'); + + return [ + 'query' => 'DEFAULT ' . $binding, + 'bindings' => [ + $binding => $column['default'] + ] + ]; + } + + /** + * Returns the cleaned identifier based on the table and column name + * + * @param string $table Table name + * @param string $column Column name + * @param bool $enforceQualified If true, a qualified identifier is returned in all cases + * @return string|null Identifier or null if the table or column is invalid + */ + public function columnName(string $table, string $column, bool $enforceQualified = false): ?string + { + // ensure we have clean $table and $column values without qualified identifiers + list($table, $column) = $this->splitIdentifier($table, $column); + + // combine the identifiers again + if ($this->database->validateColumn($table, $column) === true) { + return $this->combineIdentifier($table, $column, $enforceQualified !== true); + } + + // the table or column does not exist + return null; + } + + /** + * Abstracted column types to simplify table + * creation for multiple database drivers + * @codeCoverageIgnore + * + * @return array + */ + public function columnTypes(): array + { + return [ + 'id' => '{{ name }} INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', + 'varchar' => '{{ name }} varchar(255) {{ null }} {{ default }} {{ unique }}', + 'text' => '{{ name }} TEXT {{ unique }}', + 'int' => '{{ name }} INT(11) UNSIGNED {{ null }} {{ default }} {{ unique }}', + 'timestamp' => '{{ name }} TIMESTAMP {{ null }} {{ default }} {{ unique }}', + 'bool' => '{{ name }} TINYINT(1) {{ null }} {{ default }} {{ unique }}' + ]; + } + + /** + * Combines an identifier (table and column) + * + * @param $table string + * @param $column string + * @param $values bool Whether the identifier is going to be used for a VALUES clause; + * only relevant for SQLite + * @return string + */ + public function combineIdentifier(string $table, string $column, bool $values = false): string + { + return $this->quoteIdentifier($table) . '.' . $this->quoteIdentifier($column); + } + + /** + * Creates the CREATE TABLE syntax for a single column + * + * @param string $name Column name + * @param array $column Column definition array; valid keys: + * - `type` (required): Column template to use + * - `null`: Whether the column may be NULL (boolean) + * - `key`: Index this column is part of; special values `'primary'` for PRIMARY KEY and `true` for automatic naming + * - `unique`: Whether the index (or if not set the column itself) has a UNIQUE constraint + * - `default`: Default value of this column + * @return array Array with `query` and `key` strings, a `unique` boolean and a `bindings` array + * @throws \Kirby\Exception\InvalidArgumentException if no column type is given or the column type is not supported. + */ + public function createColumn(string $name, array $column): array + { + // column type + if (isset($column['type']) === false) { + throw new InvalidArgumentException('No column type given for column ' . $name); + } + $template = $this->columnTypes()[$column['type']] ?? null; + if (!$template) { + throw new InvalidArgumentException('Unsupported column type: ' . $column['type']); + } + + // null option + if (A::get($column, 'null') === false) { + $null = 'NOT NULL'; + } else { + $null = 'NULL'; + } + + // indexes/keys + if (isset($column['key']) === true) { + if (is_string($column['key']) === true) { + $column['key'] = strtolower($column['key']); + } elseif ($column['key'] === true) { + $column['key'] = $name . '_index'; + } + } + + // unique + $uniqueKey = false; + $uniqueColumn = null; + if (isset($column['unique']) === true && $column['unique'] === true) { + if (isset($column['key']) === true) { + // this column is part of an index, make that unique + $uniqueKey = true; + } else { + // make the column itself unique + $uniqueColumn = 'UNIQUE'; + } + } + + // default value + $columnDefault = $this->columnDefault($name, $column); + + $query = trim(Str::template($template, [ + 'name' => $this->quoteIdentifier($name), + 'null' => $null, + 'default' => $columnDefault['query'], + 'unique' => $uniqueColumn + ], ['fallback' => ''])); + + return [ + 'query' => $query, + 'bindings' => $columnDefault['bindings'], + 'key' => $column['key'] ?? null, + 'unique' => $uniqueKey + ]; + } + + /** + * Creates the inner query for the columns in a CREATE TABLE query + * + * @param array $columns Array of column definition arrays, see `Kirby\Database\Sql::createColumn()` + * @return array Array with a `query` string and `bindings`, `keys` and `unique` arrays + */ + public function createTableInner(array $columns): array + { + $query = []; + $bindings = []; + $keys = []; + $unique = []; + + foreach ($columns as $name => $column) { + $sql = $this->createColumn($name, $column); + + // collect query and bindings + $query[] = $sql['query']; + $bindings += $sql['bindings']; + + // make a list of keys per key name + if ($sql['key'] !== null) { + if (isset($keys[$sql['key']]) !== true) { + $keys[$sql['key']] = []; + } + + $keys[$sql['key']][] = $name; + if ($sql['unique'] === true) { + $unique[$sql['key']] = true; + } + } + } + + return [ + 'query' => implode(',' . PHP_EOL, $query), + 'bindings' => $bindings, + 'keys' => $keys, + 'unique' => $unique + ]; + } + + /** + * Creates a CREATE TABLE query + * + * @param string $table Table name + * @param array $columns Array of column definition arrays, see `Kirby\Database\Sql::createColumn()` + * @return array Array with a `query` string and a `bindings` array + */ + public function createTable(string $table, array $columns = []): array + { + $inner = $this->createTableInner($columns); + + // add keys + foreach ($inner['keys'] as $key => $columns) { + // quote each column name and make a list string out of the column names + $columns = implode(', ', array_map( + fn ($name) => $this->quoteIdentifier($name), + $columns + )); + + if ($key === 'primary') { + $key = 'PRIMARY KEY'; + } else { + $unique = isset($inner['unique'][$key]) === true ? 'UNIQUE ' : ''; + $key = $unique . 'INDEX ' . $this->quoteIdentifier($key); + } + + $inner['query'] .= ',' . PHP_EOL . $key . ' (' . $columns . ')'; + } + + return [ + 'query' => 'CREATE TABLE ' . $this->quoteIdentifier($table) . ' (' . PHP_EOL . $inner['query'] . PHP_EOL . ')', + 'bindings' => $inner['bindings'] + ]; + } + + /** + * Builds a DELETE clause + * + * @param array $params List of parameters for the DELETE clause. See defaults for more info. + * @return array + */ + public function delete(array $params = []): array + { + $defaults = [ + 'table' => '', + 'where' => null, + 'bindings' => [] + ]; + + $options = array_merge($defaults, $params); + $bindings = $options['bindings']; + $query = ['DELETE']; + + // from + $this->extend($query, $bindings, $this->from($options['table'])); + + // where + $this->extend($query, $bindings, $this->where($options['where'])); + + return [ + 'query' => $this->query($query), + 'bindings' => $bindings + ]; + } + + /** + * Creates the sql for dropping a single table + * + * @param string $table + * @return array + */ + public function dropTable(string $table): array + { + return [ + 'query' => 'DROP TABLE ' . $this->tableName($table), + 'bindings' => [] + ]; + } + + /** + * Extends a given query and bindings + * by reference + * + * @param array $query + * @param array $bindings + * @param array $input + * @return void + */ + public function extend(&$query, array &$bindings, $input) + { + if (empty($input['query']) === false) { + $query[] = $input['query']; + $bindings = array_merge($bindings, $input['bindings']); + } + } + + /** + * Creates the from syntax + * + * @param string $table + * @return array + */ + public function from(string $table): array + { + return [ + 'query' => 'FROM ' . $this->tableName($table), + 'bindings' => [] + ]; + } + + /** + * Creates the group by syntax + * + * @param string $group + * @return array + */ + public function group(string $group = null): array + { + if (empty($group) === true) { + return [ + 'query' => null, + 'bindings' => [] + ]; + } + + return [ + 'query' => 'GROUP BY ' . $group, + 'bindings' => [] + ]; + } + + /** + * Creates the having syntax + * + * @param string|null $having + * @return array + */ + public function having(string $having = null): array + { + if (empty($having) === true) { + return [ + 'query' => null, + 'bindings' => [] + ]; + } + + return [ + 'query' => 'HAVING ' . $having, + 'bindings' => [] + ]; + } + + /** + * Creates an insert query + * + * @param array $params + * @return array + */ + public function insert(array $params = []): array + { + $table = $params['table'] ?? null; + $values = $params['values'] ?? null; + $bindings = $params['bindings']; + $query = ['INSERT INTO ' . $this->tableName($table)]; + + // add the values + $this->extend($query, $bindings, $this->values($table, $values, ', ', false)); + + return [ + 'query' => $this->query($query), + 'bindings' => $bindings + ]; + } + + /** + * Creates a join query + * + * @param string $table + * @param string $type + * @param string $on + * @return array + * @throws \Kirby\Exception\InvalidArgumentException if an invalid join type is given + */ + public function join(string $type, string $table, string $on): array + { + $types = [ + 'JOIN', + 'INNER JOIN', + 'OUTER JOIN', + 'LEFT OUTER JOIN', + 'LEFT JOIN', + 'RIGHT OUTER JOIN', + 'RIGHT JOIN', + 'FULL OUTER JOIN', + 'FULL JOIN', + 'NATURAL JOIN', + 'CROSS JOIN', + 'SELF JOIN' + ]; + + $type = strtoupper(trim($type)); + + // validate join type + if (in_array($type, $types) === false) { + throw new InvalidArgumentException('Invalid join type ' . $type); + } + + return [ + 'query' => $type . ' ' . $this->tableName($table) . ' ON ' . $on, + 'bindings' => [], + ]; + } + + /** + * Create the syntax for multiple joins + * + * @param array|null $joins + * @return array + */ + public function joins(array $joins = null): array + { + $query = []; + $bindings = []; + + foreach ((array)$joins as $join) { + $this->extend($query, $bindings, $this->join($join['type'] ?? 'JOIN', $join['table'] ?? null, $join['on'] ?? null)); + } + + return [ + 'query' => implode(' ', array_filter($query)), + 'bindings' => [], + ]; + } + + /** + * Creates a limit and offset query instruction + * + * @param int $offset + * @param int|null $limit + * @return array + */ + public function limit(int $offset = 0, int $limit = null): array + { + // no need to add it to the query + if ($offset === 0 && $limit === null) { + return [ + 'query' => null, + 'bindings' => [] + ]; + } + + $limit ??= '18446744073709551615'; + + $offsetBinding = $this->bindingName('offset'); + $limitBinding = $this->bindingName('limit'); + + return [ + 'query' => 'LIMIT ' . $offsetBinding . ', ' . $limitBinding, + 'bindings' => [ + $limitBinding => $limit, + $offsetBinding => $offset, + ] + ]; + } + + /** + * Creates the order by syntax + * + * @param string $order + * @return array + */ + public function order(string $order = null): array + { + if (empty($order) === true) { + return [ + 'query' => null, + 'bindings' => [] + ]; + } + + return [ + 'query' => 'ORDER BY ' . $order, + 'bindings' => [] + ]; + } + + /** + * Converts a query array into a final string + * + * @param array $query + * @param string $separator + * @return string + */ + public function query(array $query, string $separator = ' ') + { + return implode($separator, array_filter($query)); + } + + /** + * Quotes an identifier (table *or* column) + * + * @param $identifier string + * @return string + */ + public function quoteIdentifier(string $identifier): string + { + // * is special, don't quote that + if ($identifier === '*') { + return $identifier; + } + + // escape backticks inside the identifier name + $identifier = str_replace('`', '``', $identifier); + + // wrap in backticks + return '`' . $identifier . '`'; + } + + /** + * Builds a select clause + * + * @param array $params List of parameters for the select clause. Check out the defaults for more info. + * @return array An array with the query and the bindings + */ + public function select(array $params = []): array + { + $defaults = [ + 'table' => '', + 'columns' => '*', + 'join' => null, + 'distinct' => false, + 'where' => null, + 'group' => null, + 'having' => null, + 'order' => null, + 'offset' => 0, + 'limit' => null, + 'bindings' => [] + ]; + + $options = array_merge($defaults, $params); + $bindings = $options['bindings']; + $query = ['SELECT']; + + // select distinct values + if ($options['distinct'] === true) { + $query[] = 'DISTINCT'; + } + + // columns + $query[] = $this->selected($options['table'], $options['columns']); + + // from + $this->extend($query, $bindings, $this->from($options['table'])); + + // joins + $this->extend($query, $bindings, $this->joins($options['join'])); + + // where + $this->extend($query, $bindings, $this->where($options['where'])); + + // group + $this->extend($query, $bindings, $this->group($options['group'])); + + // having + $this->extend($query, $bindings, $this->having($options['having'])); + + // order + $this->extend($query, $bindings, $this->order($options['order'])); + + // offset and limit + $this->extend($query, $bindings, $this->limit($options['offset'], $options['limit'])); + + return [ + 'query' => $this->query($query), + 'bindings' => $bindings + ]; + } + + /** + * Creates a columns definition from string or array + * + * @param string $table + * @param array|string|null $columns + * @return string + */ + public function selected($table, $columns = null): string + { + // all columns + if (empty($columns) === true) { + return '*'; + } + + // array of columns + if (is_array($columns) === true) { + + // validate columns + $result = []; + + foreach ($columns as $column) { + list($table, $columnPart) = $this->splitIdentifier($table, $column); + + if ($this->validateColumn($table, $columnPart) === true) { + $result[] = $this->combineIdentifier($table, $columnPart); + } + } + + return implode(', ', $result); + } else { + return $columns; + } + } + + /** + * Splits a (qualified) identifier into table and column + * + * @param $table string Default table if the identifier is not qualified + * @param $identifier string + * @return array + * @throws \Kirby\Exception\InvalidArgumentException if an invalid identifier is given + */ + public function splitIdentifier($table, $identifier): array + { + // split by dot, but only outside of quotes + $parts = preg_split('/(?:`[^`]*`|"[^"]*")(*SKIP)(*F)|\./', $identifier); + + switch (count($parts)) { + // non-qualified identifier + case 1: + return [$table, $this->unquoteIdentifier($parts[0])]; + + // qualified identifier + case 2: + return [$this->unquoteIdentifier($parts[0]), $this->unquoteIdentifier($parts[1])]; + + // every other number is an error + default: + throw new InvalidArgumentException('Invalid identifier ' . $identifier); + } + } + + /** + * Returns a query to list the tables of the current database; + * the query needs to return rows with a column `name` + * + * @return array + */ + abstract public function tables(): array; + + /** + * Validates and quotes a table name + * + * @param string $table + * @return string + * @throws \Kirby\Exception\InvalidArgumentException if an invalid table name is given + */ + public function tableName(string $table): string + { + // validate table + if ($this->database->validateTable($table) === false) { + throw new InvalidArgumentException('Invalid table ' . $table); + } + + return $this->quoteIdentifier($table); + } + + /** + * Unquotes an identifier (table *or* column) + * + * @param $identifier string + * @return string + */ + public function unquoteIdentifier(string $identifier): string + { + // remove quotes around the identifier + if (in_array(Str::substr($identifier, 0, 1), ['"', '`']) === true) { + $identifier = Str::substr($identifier, 1); + } + + if (in_array(Str::substr($identifier, -1), ['"', '`']) === true) { + $identifier = Str::substr($identifier, 0, -1); + } + + // unescape duplicated quotes + return str_replace(['""', '``'], ['"', '`'], $identifier); + } + + /** + * Builds an update clause + * + * @param array $params List of parameters for the update clause. See defaults for more info. + * @return array + */ + public function update(array $params = []): array + { + $defaults = [ + 'table' => null, + 'values' => null, + 'where' => null, + 'bindings' => [] + ]; + + $options = array_merge($defaults, $params); + $bindings = $options['bindings']; + + // start the query + $query = ['UPDATE ' . $this->tableName($options['table']) . ' SET']; + + // add the values + $this->extend($query, $bindings, $this->values($options['table'], $options['values'])); + + // add the where clause + $this->extend($query, $bindings, $this->where($options['where'])); + + return [ + 'query' => $this->query($query), + 'bindings' => $bindings + ]; + } + + /** + * Validates a given column name in a table + * + * @param string $table + * @param string $column + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException If the column is invalid + */ + public function validateColumn(string $table, string $column): bool + { + if ($this->database->validateColumn($table, $column) !== true) { + throw new InvalidArgumentException('Invalid column ' . $column); + } + + return true; + } + + /** + * Builds a safe list of values for insert, select or update queries + * + * @param string $table Table name + * @param mixed $values A value string or array of values + * @param string $separator A separator which should be used to join values + * @param bool $set If true builds a set list of values for update clauses + * @param bool $enforceQualified Always use fully qualified column names + */ + public function values(string $table, $values, string $separator = ', ', bool $set = true, bool $enforceQualified = false): array + { + if (is_array($values) === false) { + return [ + 'query' => $values, + 'bindings' => [] + ]; + } + + if ($set === true) { + return $this->valueSet($table, $values, $separator, $enforceQualified); + } else { + return $this->valueList($table, $values, $separator, $enforceQualified); + } + } + + /** + * Creates a list of fields and values + * + * @param string $table + * @param string|array $values + * @param string $separator + * @param bool $enforceQualified + * @param array + */ + public function valueList(string $table, $values, string $separator = ',', bool $enforceQualified = false): array + { + $fields = []; + $query = []; + $bindings = []; + + foreach ($values as $column => $value) { + $key = $this->columnName($table, $column, $enforceQualified); + + if ($key === null) { + continue; + } + + $fields[] = $key; + + if (in_array($value, static::$literals, true) === true) { + $query[] = $value ?: 'null'; + continue; + } + + if (is_array($value) === true) { + $value = json_encode($value); + } + + // add the binding + $bindings[$bindingName = $this->bindingName('value')] = $value; + + // create the query + $query[] = $bindingName; + } + + return [ + 'query' => '(' . implode($separator, $fields) . ') VALUES (' . implode($separator, $query) . ')', + 'bindings' => $bindings + ]; + } + + /** + * Creates a set of values + * + * @param string $table + * @param string|array $values + * @param string $separator + * @param bool $enforceQualified + * @param array + * @return array + */ + public function valueSet(string $table, $values, string $separator = ',', bool $enforceQualified = false): array + { + $query = []; + $bindings = []; + + foreach ($values as $column => $value) { + $key = $this->columnName($table, $column, $enforceQualified); + + if ($key === null) { + continue; + } + + if (in_array($value, static::$literals, true) === true) { + $query[] = $key . ' = ' . ($value ?: 'null'); + continue; + } + + if (is_array($value) === true) { + $value = json_encode($value); + } + + // add the binding + $bindings[$bindingName = $this->bindingName('value')] = $value; + + // create the query + $query[] = $key . ' = ' . $bindingName; + } + + return [ + 'query' => implode($separator, $query), + 'bindings' => $bindings + ]; + } + + /** + * @param string|array|null $where + * @param array $bindings + * @return array + */ + public function where($where, array $bindings = []): array + { + if (empty($where) === true) { + return [ + 'query' => null, + 'bindings' => [], + ]; + } + + if (is_string($where) === true) { + return [ + 'query' => 'WHERE ' . $where, + 'bindings' => $bindings + ]; + } + + $query = []; + + foreach ($where as $key => $value) { + $binding = $this->bindingName('where_' . $key); + $bindings[$binding] = $value; + + $query[] = $key . ' = ' . $binding; + } + + return [ + 'query' => 'WHERE ' . implode(' AND ', $query), + 'bindings' => $bindings + ]; + } } diff --git a/kirby/src/Database/Sql/Mysql.php b/kirby/src/Database/Sql/Mysql.php index 1d351b5..f8fc9d3 100755 --- a/kirby/src/Database/Sql/Mysql.php +++ b/kirby/src/Database/Sql/Mysql.php @@ -15,45 +15,45 @@ use Kirby\Database\Sql; */ class Mysql extends Sql { - /** - * Returns a query to list the columns of a specified table; - * the query needs to return rows with a column `name` - * - * @param string $table Table name - * @return array - */ - public function columns(string $table): array - { - $databaseBinding = $this->bindingName('database'); - $tableBinding = $this->bindingName('table'); + /** + * Returns a query to list the columns of a specified table; + * the query needs to return rows with a column `name` + * + * @param string $table Table name + * @return array + */ + public function columns(string $table): array + { + $databaseBinding = $this->bindingName('database'); + $tableBinding = $this->bindingName('table'); - $query = 'SELECT COLUMN_NAME AS name FROM INFORMATION_SCHEMA.COLUMNS '; - $query .= 'WHERE TABLE_SCHEMA = ' . $databaseBinding . ' AND TABLE_NAME = ' . $tableBinding; + $query = 'SELECT COLUMN_NAME AS name FROM INFORMATION_SCHEMA.COLUMNS '; + $query .= 'WHERE TABLE_SCHEMA = ' . $databaseBinding . ' AND TABLE_NAME = ' . $tableBinding; - return [ - 'query' => $query, - 'bindings' => [ - $databaseBinding => $this->database->name(), - $tableBinding => $table, - ] - ]; - } + return [ + 'query' => $query, + 'bindings' => [ + $databaseBinding => $this->database->name(), + $tableBinding => $table, + ] + ]; + } - /** - * Returns a query to list the tables of the current database; - * the query needs to return rows with a column `name` - * - * @return array - */ - public function tables(): array - { - $binding = $this->bindingName('database'); + /** + * Returns a query to list the tables of the current database; + * the query needs to return rows with a column `name` + * + * @return array + */ + public function tables(): array + { + $binding = $this->bindingName('database'); - return [ - 'query' => 'SELECT TABLE_NAME AS name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ' . $binding, - 'bindings' => [ - $binding => $this->database->name() - ] - ]; - } + return [ + 'query' => 'SELECT TABLE_NAME AS name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ' . $binding, + 'bindings' => [ + $binding => $this->database->name() + ] + ]; + } } diff --git a/kirby/src/Database/Sql/Sqlite.php b/kirby/src/Database/Sql/Sqlite.php index 2d04d24..c064522 100755 --- a/kirby/src/Database/Sql/Sqlite.php +++ b/kirby/src/Database/Sql/Sqlite.php @@ -15,130 +15,131 @@ use Kirby\Database\Sql; */ class Sqlite extends Sql { - /** - * Returns a query to list the columns of a specified table; - * the query needs to return rows with a column `name` - * - * @param string $table Table name - * @return array - */ - public function columns(string $table): array - { - return [ - 'query' => 'PRAGMA table_info(' . $this->tableName($table) . ')', - 'bindings' => [], - ]; - } + /** + * Returns a query to list the columns of a specified table; + * the query needs to return rows with a column `name` + * + * @param string $table Table name + * @return array + */ + public function columns(string $table): array + { + return [ + 'query' => 'PRAGMA table_info(' . $this->tableName($table) . ')', + 'bindings' => [], + ]; + } - /** - * Abstracted column types to simplify table - * creation for multiple database drivers - * @codeCoverageIgnore - * - * @return array - */ - public function columnTypes(): array - { - return [ - 'id' => '{{ name }} INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE', - 'varchar' => '{{ name }} TEXT {{ null }} {{ default }} {{ unique }}', - 'text' => '{{ name }} TEXT {{ null }} {{ default }} {{ unique }}', - 'int' => '{{ name }} INTEGER {{ null }} {{ default }} {{ unique }}', - 'timestamp' => '{{ name }} INTEGER {{ null }} {{ default }} {{ unique }}' - ]; - } + /** + * Abstracted column types to simplify table + * creation for multiple database drivers + * @codeCoverageIgnore + * + * @return array + */ + public function columnTypes(): array + { + return [ + 'id' => '{{ name }} INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE', + 'varchar' => '{{ name }} TEXT {{ null }} {{ default }} {{ unique }}', + 'text' => '{{ name }} TEXT {{ null }} {{ default }} {{ unique }}', + 'int' => '{{ name }} INTEGER {{ null }} {{ default }} {{ unique }}', + 'timestamp' => '{{ name }} INTEGER {{ null }} {{ default }} {{ unique }}', + 'bool' => '{{ name }} INTEGER {{ null }} {{ default }} {{ unique }}' + ]; + } - /** - * Combines an identifier (table and column) - * - * @param $table string - * @param $column string - * @param $values bool Whether the identifier is going to be used for a VALUES clause; - * only relevant for SQLite - * @return string - */ - public function combineIdentifier(string $table, string $column, bool $values = false): string - { - // SQLite doesn't support qualified column names for VALUES clauses - if ($values === true) { - return $this->quoteIdentifier($column); - } + /** + * Combines an identifier (table and column) + * + * @param $table string + * @param $column string + * @param $values bool Whether the identifier is going to be used for a VALUES clause; + * only relevant for SQLite + * @return string + */ + public function combineIdentifier(string $table, string $column, bool $values = false): string + { + // SQLite doesn't support qualified column names for VALUES clauses + if ($values === true) { + return $this->quoteIdentifier($column); + } - return $this->quoteIdentifier($table) . '.' . $this->quoteIdentifier($column); - } + return $this->quoteIdentifier($table) . '.' . $this->quoteIdentifier($column); + } - /** - * Creates a CREATE TABLE query - * - * @param string $table Table name - * @param array $columns Array of column definition arrays, see `Kirby\Database\Sql::createColumn()` - * @return array Array with a `query` string and a `bindings` array - */ - public function createTable(string $table, array $columns = []): array - { - $inner = $this->createTableInner($columns); + /** + * Creates a CREATE TABLE query + * + * @param string $table Table name + * @param array $columns Array of column definition arrays, see `Kirby\Database\Sql::createColumn()` + * @return array Array with a `query` string and a `bindings` array + */ + public function createTable(string $table, array $columns = []): array + { + $inner = $this->createTableInner($columns); - // add keys - $keys = []; - foreach ($inner['keys'] as $key => $columns) { - // quote each column name and make a list string out of the column names - $columns = implode(', ', array_map( - fn ($name) => $this->quoteIdentifier($name), - $columns - )); + // add keys + $keys = []; + foreach ($inner['keys'] as $key => $columns) { + // quote each column name and make a list string out of the column names + $columns = implode(', ', array_map( + fn ($name) => $this->quoteIdentifier($name), + $columns + )); - if ($key === 'primary') { - $inner['query'] .= ',' . PHP_EOL . 'PRIMARY KEY (' . $columns . ')'; - } else { - // SQLite only supports index creation using a separate CREATE INDEX query - $unique = isset($inner['unique'][$key]) === true ? 'UNIQUE ' : ''; - $keys[] = 'CREATE ' . $unique . 'INDEX ' . $this->quoteIdentifier($table . '_index_' . $key) . - ' ON ' . $this->quoteIdentifier($table) . ' (' . $columns . ')'; - } - } + if ($key === 'primary') { + $inner['query'] .= ',' . PHP_EOL . 'PRIMARY KEY (' . $columns . ')'; + } else { + // SQLite only supports index creation using a separate CREATE INDEX query + $unique = isset($inner['unique'][$key]) === true ? 'UNIQUE ' : ''; + $keys[] = 'CREATE ' . $unique . 'INDEX ' . $this->quoteIdentifier($table . '_index_' . $key) . + ' ON ' . $this->quoteIdentifier($table) . ' (' . $columns . ')'; + } + } - $query = 'CREATE TABLE ' . $this->quoteIdentifier($table) . ' (' . PHP_EOL . $inner['query'] . PHP_EOL . ')'; - if (empty($keys) === false) { - $query .= ';' . PHP_EOL . implode(';' . PHP_EOL, $keys); - } + $query = 'CREATE TABLE ' . $this->quoteIdentifier($table) . ' (' . PHP_EOL . $inner['query'] . PHP_EOL . ')'; + if (empty($keys) === false) { + $query .= ';' . PHP_EOL . implode(';' . PHP_EOL, $keys); + } - return [ - 'query' => $query, - 'bindings' => $inner['bindings'] - ]; - } + return [ + 'query' => $query, + 'bindings' => $inner['bindings'] + ]; + } - /** - * Quotes an identifier (table *or* column) - * - * @param $identifier string - * @return string - */ - public function quoteIdentifier(string $identifier): string - { - // * is special - if ($identifier === '*') { - return $identifier; - } + /** + * Quotes an identifier (table *or* column) + * + * @param $identifier string + * @return string + */ + public function quoteIdentifier(string $identifier): string + { + // * is special + if ($identifier === '*') { + return $identifier; + } - // escape quotes inside the identifier name - $identifier = str_replace('"', '""', $identifier); + // escape quotes inside the identifier name + $identifier = str_replace('"', '""', $identifier); - // wrap in quotes - return '"' . $identifier . '"'; - } + // wrap in quotes + return '"' . $identifier . '"'; + } - /** - * Returns a query to list the tables of the current database; - * the query needs to return rows with a column `name` - * - * @return string - */ - public function tables(): array - { - return [ - 'query' => 'SELECT name FROM sqlite_master WHERE type = "table" OR type = "view"', - 'bindings' => [] - ]; - } + /** + * Returns a query to list the tables of the current database; + * the query needs to return rows with a column `name` + * + * @return string + */ + public function tables(): array + { + return [ + 'query' => 'SELECT name FROM sqlite_master WHERE type = "table" OR type = "view"', + 'bindings' => [] + ]; + } } diff --git a/kirby/src/Email/Body.php b/kirby/src/Email/Body.php index 403a5fa..716dfd5 100755 --- a/kirby/src/Email/Body.php +++ b/kirby/src/Email/Body.php @@ -17,69 +17,69 @@ use Kirby\Toolkit\Properties; */ class Body { - use Properties; + use Properties; - /** - * @var string - */ - protected $html; + /** + * @var string + */ + protected $html; - /** - * @var string - */ - protected $text; + /** + * @var string + */ + protected $text; - /** - * Email body constructor - * - * @param array $props - */ - public function __construct(array $props = []) - { - $this->setProperties($props); - } + /** + * Email body constructor + * + * @param array $props + */ + public function __construct(array $props = []) + { + $this->setProperties($props); + } - /** - * Returns the HTML content of the email body - * - * @return string - */ - public function html() - { - return $this->html ?? ''; - } + /** + * Returns the HTML content of the email body + * + * @return string + */ + public function html() + { + return $this->html ?? ''; + } - /** - * Returns the plain text content of the email body - * - * @return string - */ - public function text() - { - return $this->text ?? ''; - } + /** + * Returns the plain text content of the email body + * + * @return string + */ + public function text() + { + return $this->text ?? ''; + } - /** - * Sets the HTML content for the email body - * - * @param string|null $html - * @return $this - */ - protected function setHtml(string $html = null) - { - $this->html = $html; - return $this; - } + /** + * Sets the HTML content for the email body + * + * @param string|null $html + * @return $this + */ + 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 $this - */ - protected function setText(string $text = null) - { - $this->text = $text; - return $this; - } + /** + * Sets the plain text content for the email body + * + * @param string|null $text + * @return $this + */ + protected function setText(string $text = null) + { + $this->text = $text; + return $this; + } } diff --git a/kirby/src/Email/Email.php b/kirby/src/Email/Email.php index 3f96793..5cacbb7 100755 --- a/kirby/src/Email/Email.php +++ b/kirby/src/Email/Email.php @@ -19,454 +19,454 @@ use Kirby\Toolkit\V; */ class Email { - use Properties; + use Properties; - /** - * If set to `true`, the debug mode is enabled - * for all emails - * - * @var bool - */ - public static $debug = false; + /** + * If set to `true`, the debug mode is enabled + * for all emails + * + * @var bool + */ + public static $debug = false; - /** - * Store for sent emails when `Email::$debug` - * is set to `true` - * - * @var array - */ - public static $emails = []; + /** + * Store for sent emails when `Email::$debug` + * is set to `true` + * + * @var array + */ + public static $emails = []; - /** - * @var array|null - */ - protected $attachments; + /** + * @var array|null + */ + protected $attachments; - /** - * @var \Kirby\Email\Body|null - */ - protected $body; + /** + * @var \Kirby\Email\Body|null + */ + protected $body; - /** - * @var array|null - */ - protected $bcc; + /** + * @var array|null + */ + protected $bcc; - /** - * @var \Closure|null - */ - protected $beforeSend; + /** + * @var \Closure|null + */ + protected $beforeSend; - /** - * @var array|null - */ - protected $cc; + /** + * @var array|null + */ + protected $cc; - /** - * @var string|null - */ - protected $from; + /** + * @var string|null + */ + protected $from; - /** - * @var string|null - */ - protected $fromName; + /** + * @var string|null + */ + protected $fromName; - /** - * @var string|null - */ - protected $replyTo; + /** + * @var string|null + */ + protected $replyTo; - /** - * @var string|null - */ - protected $replyToName; + /** + * @var string|null + */ + protected $replyToName; - /** - * @var bool - */ - protected $isSent = false; + /** + * @var bool + */ + protected $isSent = false; - /** - * @var string|null - */ - protected $subject; + /** + * @var string|null + */ + protected $subject; - /** - * @var array|null - */ - protected $to; + /** + * @var array|null + */ + protected $to; - /** - * @var array|null - */ - protected $transport; + /** + * @var array|null + */ + protected $transport; - /** - * Email constructor - * - * @param array $props - * @param bool $debug - */ - public function __construct(array $props = [], bool $debug = false) - { - $this->setProperties($props); + /** + * Email constructor + * + * @param array $props + * @param bool $debug + */ + public function __construct(array $props = [], bool $debug = false) + { + $this->setProperties($props); - // @codeCoverageIgnoreStart - if (static::$debug === false && $debug === false) { - $this->send(); - } elseif (static::$debug === true) { - static::$emails[] = $this; - } - // @codeCoverageIgnoreEnd - } + // @codeCoverageIgnoreStart + if (static::$debug === false && $debug === false) { + $this->send(); + } elseif (static::$debug === true) { + static::$emails[] = $this; + } + // @codeCoverageIgnoreEnd + } - /** - * Returns the email attachments - * - * @return array - */ - public function attachments(): array - { - return $this->attachments; - } + /** + * Returns the email attachments + * + * @return array + */ + public function attachments(): array + { + return $this->attachments; + } - /** - * Returns the email body - * - * @return \Kirby\Email\Body|null - */ - public function body() - { - return $this->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 "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 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 "cc" recipients + * + * @return array + */ + public function cc(): array + { + return $this->cc; + } - /** - * Returns default transport settings - * - * @return array - */ - protected function defaultTransport(): array - { - return [ - 'type' => 'mail' - ]; - } + /** + * Returns default transport settings + * + * @return array + */ + protected function defaultTransport(): array + { + return [ + 'type' => 'mail' + ]; + } - /** - * Returns the "from" email address - * - * @return string - */ - public function from(): string - { - return $this->from; - } + /** + * 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; - } + /** + * 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 empty($this->body()->html()) === false; - } + /** + * Checks if the email has an HTML body + * + * @return bool + */ + public function isHtml() + { + return empty($this->body()->html()) === false; + } - /** - * Checks if the email has been sent successfully - * - * @return bool - */ - public function isSent(): bool - { - return $this->isSent; - } + /** + * 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" 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; - } + /** + * 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) { - return $multiple === true ? [] : ''; - } + /** + * 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) { + return $multiple === true ? [] : ''; + } - if (is_array($email) === false) { - $email = [$email => null]; - } + if (is_array($email) === false) { + $email = [$email => null]; + } - $result = []; - foreach ($email as $address => $name) { - // convert simple email arrays to associative arrays - if (is_int($address) === true) { - // the value is the address, there is no name - $address = $name; - $result[$address] = null; - } else { - $result[$address] = $name; - } + $result = []; + foreach ($email as $address => $name) { + // convert simple email arrays to associative arrays + if (is_int($address) === true) { + // the value is the address, there is no name + $address = $name; + $result[$address] = null; + } else { + $result[$address] = $name; + } - // ensure that the address is valid - if (V::email($address) === false) { - throw new Exception(sprintf('"%s" is not a valid email address', $address)); - } - } + // ensure that the address is valid + if (V::email($address) === false) { + throw new Exception(sprintf('"%s" is not a valid email address', $address)); + } + } - return $multiple === true ? $result : array_keys($result)[0]; - } + return $multiple === true ? $result : array_keys($result)[0]; + } - /** - * Sends the email - * - * @return bool - */ - public function send(): bool - { - return $this->isSent = true; - } + /** + * Sends the email + * + * @return bool + */ + public function send(): bool + { + return $this->isSent = true; + } - /** - * Sets the email attachments - * - * @param array|null $attachments - * @return $this - */ - protected function setAttachments($attachments = null) - { - $this->attachments = $attachments ?? []; - return $this; - } + /** + * Sets the email attachments + * + * @param array|null $attachments + * @return $this + */ + protected function setAttachments($attachments = null) + { + $this->attachments = $attachments ?? []; + return $this; + } - /** - * Sets the email body - * - * @param string|array $body - * @return $this - */ - protected function setBody($body) - { - if (is_string($body) === true) { - $body = ['text' => $body]; - } + /** + * Sets the email body + * + * @param string|array $body + * @return $this + */ + protected function setBody($body) + { + if (is_string($body) === true) { + $body = ['text' => $body]; + } - $this->body = new Body($body); - return $this; - } + $this->body = new Body($body); + 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 "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 $this - */ - protected function setBeforeSend(?Closure $beforeSend = null) - { - $this->beforeSend = $beforeSend; - return $this; - } + /** + * Sets the "beforeSend" callback + * + * @param \Closure|null $beforeSend + * @return $this + */ + protected function setBeforeSend(?Closure $beforeSend = null) + { + $this->beforeSend = $beforeSend; + return $this; + } - /** - * Sets "cc" recipients - * - * @param string|array|null $cc - * @return $this - */ - protected function setCc($cc = null) - { - $this->cc = $this->resolveEmail($cc); - return $this; - } + /** + * Sets "cc" recipients + * + * @param string|array|null $cc + * @return $this + */ + protected function setCc($cc = null) + { + $this->cc = $this->resolveEmail($cc); + return $this; + } - /** - * Sets the "from" email address - * - * @param string $from - * @return $this - */ - protected function setFrom(string $from) - { - $this->from = $this->resolveEmail($from, false); - return $this; - } + /** + * Sets the "from" email address + * + * @param string $from + * @return $this + */ + protected function setFrom(string $from) + { + $this->from = $this->resolveEmail($from, false); + return $this; + } - /** - * Sets the "from" name - * - * @param string|null $fromName - * @return $this - */ - protected function setFromName(string $fromName = null) - { - $this->fromName = $fromName; - return $this; - } + /** + * Sets the "from" name + * + * @param string|null $fromName + * @return $this + */ + protected function setFromName(string $fromName = null) + { + $this->fromName = $fromName; + return $this; + } - /** - * Sets the "reply to" email address - * - * @param string|null $replyTo - * @return $this - */ - protected function setReplyTo(string $replyTo = null) - { - $this->replyTo = $this->resolveEmail($replyTo, false); - return $this; - } + /** + * Sets the "reply to" email address + * + * @param string|null $replyTo + * @return $this + */ + protected function setReplyTo(string $replyTo = null) + { + $this->replyTo = $this->resolveEmail($replyTo, false); + return $this; + } - /** - * Sets the "reply to" name - * - * @param string|null $replyToName - * @return $this - */ - protected function setReplyToName(string $replyToName = null) - { - $this->replyToName = $replyToName; - return $this; - } + /** + * Sets the "reply to" name + * + * @param string|null $replyToName + * @return $this + */ + protected function setReplyToName(string $replyToName = null) + { + $this->replyToName = $replyToName; + return $this; + } - /** - * Sets the email subject - * - * @param string $subject - * @return $this - */ - protected function setSubject(string $subject) - { - $this->subject = $subject; - return $this; - } + /** + * Sets the email subject + * + * @param string $subject + * @return $this + */ + protected function setSubject(string $subject) + { + $this->subject = $subject; + return $this; + } - /** - * Sets the recipients of the email - * - * @param string|array $to - * @return $this - */ - protected function setTo($to) - { - $this->to = $this->resolveEmail($to); - return $this; - } + /** + * Sets the recipients of the email + * + * @param string|array $to + * @return $this + */ + protected function setTo($to) + { + $this->to = $this->resolveEmail($to); + return $this; + } - /** - * Sets the email transport settings - * - * @param array|null $transport - * @return $this - */ - protected function setTransport($transport = null) - { - $this->transport = $transport; - return $this; - } + /** + * Sets the email transport settings + * + * @param array|null $transport + * @return $this + */ + 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 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 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(); - } + /** + * Returns the email transports settings + * + * @return array + */ + public function transport(): array + { + return $this->transport ?? $this->defaultTransport(); + } } diff --git a/kirby/src/Email/PHPMailer.php b/kirby/src/Email/PHPMailer.php index cc0ba8c..17f89cf 100755 --- a/kirby/src/Email/PHPMailer.php +++ b/kirby/src/Email/PHPMailer.php @@ -17,97 +17,97 @@ 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); + /** + * 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); - // set sender's address - $mailer->setFrom($this->from(), $this->fromName() ?? ''); + // set sender's address + $mailer->setFrom($this->from(), $this->fromName() ?? ''); - // optional reply-to address - if ($replyTo = $this->replyTo()) { - $mailer->addReplyTo($replyTo, $this->replyToName() ?? ''); - } + // optional reply-to address + if ($replyTo = $this->replyTo()) { + $mailer->addReplyTo($replyTo, $this->replyToName() ?? ''); + } - // add (multiple) recipient, CC & BCC addresses - foreach ($this->to() as $email => $name) { - $mailer->addAddress($email, $name ?? ''); - } - foreach ($this->cc() as $email => $name) { - $mailer->addCC($email, $name ?? ''); - } - foreach ($this->bcc() as $email => $name) { - $mailer->addBCC($email, $name ?? ''); - } + // add (multiple) recipient, CC & BCC addresses + foreach ($this->to() as $email => $name) { + $mailer->addAddress($email, $name ?? ''); + } + foreach ($this->cc() as $email => $name) { + $mailer->addCC($email, $name ?? ''); + } + foreach ($this->bcc() as $email => $name) { + $mailer->addBCC($email, $name ?? ''); + } - $mailer->Subject = $this->subject(); - $mailer->CharSet = 'UTF-8'; + $mailer->Subject = $this->subject(); + $mailer->CharSet = 'UTF-8'; - // set body according to html/text - if ($this->isHtml()) { - $mailer->isHTML(true); - $mailer->Body = $this->body()->html(); - $mailer->AltBody = $this->body()->text(); - } else { - $mailer->Body = $this->body()->text(); - } + // set body according to html/text + if ($this->isHtml()) { + $mailer->isHTML(true); + $mailer->Body = $this->body()->html(); + $mailer->AltBody = $this->body()->text(); + } else { + $mailer->Body = $this->body()->text(); + } - // add attachments - foreach ($this->attachments() as $attachment) { - $mailer->addAttachment($attachment); - } + // add attachments + foreach ($this->attachments() as $attachment) { + $mailer->addAttachment($attachment); + } - // smtp transport settings - if (($this->transport()['type'] ?? 'mail') === 'smtp') { - $mailer->isSMTP(); - $mailer->Host = $this->transport()['host'] ?? null; - $mailer->SMTPAuth = $this->transport()['auth'] ?? false; - $mailer->Username = $this->transport()['username'] ?? null; - $mailer->Password = $this->transport()['password'] ?? null; - $mailer->SMTPSecure = $this->transport()['security'] ?? 'ssl'; - $mailer->Port = $this->transport()['port'] ?? null; + // smtp transport settings + if (($this->transport()['type'] ?? 'mail') === 'smtp') { + $mailer->isSMTP(); + $mailer->Host = $this->transport()['host'] ?? null; + $mailer->SMTPAuth = $this->transport()['auth'] ?? false; + $mailer->Username = $this->transport()['username'] ?? null; + $mailer->Password = $this->transport()['password'] ?? null; + $mailer->SMTPSecure = $this->transport()['security'] ?? 'ssl'; + $mailer->Port = $this->transport()['port'] ?? null; - if ($mailer->SMTPSecure === true) { - switch ($mailer->Port) { - case null: - case 587: - $mailer->SMTPSecure = 'tls'; - $mailer->Port = 587; - break; - case 465: - $mailer->SMTPSecure = 'ssl'; - break; - default: - throw new InvalidArgumentException( - 'Could not automatically detect the "security" protocol from the ' . - '"port" option, please set it explicitly to "tls" or "ssl".' - ); - } - } - } + if ($mailer->SMTPSecure === true) { + switch ($mailer->Port) { + case null: + case 587: + $mailer->SMTPSecure = 'tls'; + $mailer->Port = 587; + break; + case 465: + $mailer->SMTPSecure = 'ssl'; + break; + default: + throw new InvalidArgumentException( + 'Could not automatically detect the "security" protocol from the ' . + '"port" option, please set it explicitly to "tls" or "ssl".' + ); + } + } + } - // accessible phpMailer instance - $beforeSend = $this->beforeSend(); + // accessible phpMailer instance + $beforeSend = $this->beforeSend(); - if (empty($beforeSend) === false && is_a($beforeSend, 'Closure') === true) { - $mailer = $beforeSend->call($this, $mailer) ?? $mailer; + if (empty($beforeSend) === false && is_a($beforeSend, 'Closure') === true) { + $mailer = $beforeSend->call($this, $mailer) ?? $mailer; - if (is_a($mailer, 'PHPMailer\PHPMailer\PHPMailer') === false) { - throw new InvalidArgumentException('"beforeSend" option return should be instance of PHPMailer\PHPMailer\PHPMailer class'); - } - } + if (is_a($mailer, 'PHPMailer\PHPMailer\PHPMailer') === false) { + throw new InvalidArgumentException('"beforeSend" option return should be instance of PHPMailer\PHPMailer\PHPMailer class'); + } + } - if ($debug === true) { - return $this->isSent = true; - } + if ($debug === true) { + return $this->isSent = true; + } - return $this->isSent = $mailer->send(); // @codeCoverageIgnore - } + return $this->isSent = $mailer->send(); // @codeCoverageIgnore + } } diff --git a/kirby/src/Exception/BadMethodCallException.php b/kirby/src/Exception/BadMethodCallException.php index a3b2c62..68c1f05 100755 --- a/kirby/src/Exception/BadMethodCallException.php +++ b/kirby/src/Exception/BadMethodCallException.php @@ -14,8 +14,8 @@ namespace Kirby\Exception; */ class BadMethodCallException extends Exception { - protected static $defaultKey = 'invalidMethod'; - protected static $defaultFallback = 'The method "{ method }" does not exist'; - protected static $defaultHttpCode = 400; - protected static $defaultData = ['method' => null]; + protected static $defaultKey = 'invalidMethod'; + protected static $defaultFallback = 'The method "{ method }" does not exist'; + protected static $defaultHttpCode = 400; + protected static $defaultData = ['method' => null]; } diff --git a/kirby/src/Exception/DuplicateException.php b/kirby/src/Exception/DuplicateException.php index b57f636..74bc859 100755 --- a/kirby/src/Exception/DuplicateException.php +++ b/kirby/src/Exception/DuplicateException.php @@ -15,7 +15,7 @@ namespace Kirby\Exception; */ class DuplicateException extends Exception { - protected static $defaultKey = 'duplicate'; - protected static $defaultFallback = 'The entry exists'; - protected static $defaultHttpCode = 400; + protected static $defaultKey = 'duplicate'; + protected static $defaultFallback = 'The entry exists'; + protected static $defaultHttpCode = 400; } diff --git a/kirby/src/Exception/ErrorPageException.php b/kirby/src/Exception/ErrorPageException.php index a1d83d8..7e9ed69 100755 --- a/kirby/src/Exception/ErrorPageException.php +++ b/kirby/src/Exception/ErrorPageException.php @@ -15,7 +15,7 @@ namespace Kirby\Exception; */ class ErrorPageException extends Exception { - protected static $defaultKey = 'errorPage'; - protected static $defaultFallback = 'Triggered error page'; - protected static $defaultHttpCode = 404; + protected static $defaultKey = 'errorPage'; + protected static $defaultFallback = 'Triggered error page'; + protected static $defaultHttpCode = 404; } diff --git a/kirby/src/Exception/Exception.php b/kirby/src/Exception/Exception.php index 415f880..d3a0ba9 100755 --- a/kirby/src/Exception/Exception.php +++ b/kirby/src/Exception/Exception.php @@ -19,209 +19,209 @@ use Kirby\Toolkit\Str; */ class Exception extends \Exception { - /** - * Data variables that can be used inside the exception message - * - * @var array - */ - protected $data; + /** + * Data variables that can be used inside the exception message + * + * @var array + */ + protected $data; - /** - * HTTP code that corresponds with the exception - * - * @var int - */ - protected $httpCode; + /** + * HTTP code that corresponds with the exception + * + * @var int + */ + protected $httpCode; - /** - * Additional details that are not included in the exception message - * - * @var array - */ - protected $details; + /** + * Additional details that are not included in the exception message + * + * @var array + */ + protected $details; - /** - * Whether the exception message could be translated into the user's language - * - * @var bool - */ - protected $isTranslated = true; + /** + * Whether the exception message could be translated into the user's language + * + * @var bool + */ + protected $isTranslated = true; - /** - * Defaults that can be overridden by specific - * exception classes - */ - protected static $defaultKey = 'general'; - protected static $defaultFallback = 'An error occurred'; - protected static $defaultData = []; - protected static $defaultHttpCode = 500; - protected static $defaultDetails = []; + /** + * Defaults that can be overridden by specific + * exception classes + */ + protected static $defaultKey = 'general'; + protected static $defaultFallback = 'An error occurred'; + protected static $defaultData = []; + protected static $defaultHttpCode = 500; + protected static $defaultDetails = []; - /** - * Prefix for the exception key (e.g. 'error.general') - * - * @var string - */ - private static $prefix = 'error'; + /** + * Prefix for the exception key (e.g. 'error.general') + * + * @var string + */ + private static $prefix = 'error'; - /** - * Class constructor - * - * @param array|string $args Full option array ('key', 'translate', 'fallback', - * 'data', 'httpCode', 'details' and 'previous') or - * just the message string - */ - public function __construct($args = []) - { - // set data and httpCode from provided arguments or defaults - $this->data = $args['data'] ?? static::$defaultData; - $this->httpCode = $args['httpCode'] ?? static::$defaultHttpCode; - $this->details = $args['details'] ?? static::$defaultDetails; + /** + * Class constructor + * + * @param array|string $args Full option array ('key', 'translate', 'fallback', + * 'data', 'httpCode', 'details' and 'previous') or + * just the message string + */ + public function __construct($args = []) + { + // set data and httpCode from provided arguments or defaults + $this->data = $args['data'] ?? static::$defaultData; + $this->httpCode = $args['httpCode'] ?? static::$defaultHttpCode; + $this->details = $args['details'] ?? static::$defaultDetails; - // define the Exception key - $key = self::$prefix . '.' . ($args['key'] ?? static::$defaultKey); + // define the Exception key + $key = self::$prefix . '.' . ($args['key'] ?? static::$defaultKey); - if (is_string($args) === true) { - $this->isTranslated = false; - parent::__construct($args); - } else { - // define whether message can/should be translated - $translate = ($args['translate'] ?? true) === true && class_exists('Kirby\Cms\App') === true; + if (is_string($args) === true) { + $this->isTranslated = false; + parent::__construct($args); + } else { + // define whether message can/should be translated + $translate = ($args['translate'] ?? true) === true && class_exists('Kirby\Cms\App') === true; - // fallback waterfall for message string - $message = null; + // fallback waterfall for message string + $message = null; - if ($translate) { - // 1. translation for provided key in current language - // 2. translation for provided key in default language - if (isset($args['key']) === true) { - $message = I18n::translate(self::$prefix . '.' . $args['key']); - $this->isTranslated = true; - } - } + if ($translate) { + // 1. translation for provided key in current language + // 2. translation for provided key in default language + if (isset($args['key']) === true) { + $message = I18n::translate(self::$prefix . '.' . $args['key']); + $this->isTranslated = true; + } + } - // 3. provided fallback message - if ($message === null) { - $message = $args['fallback'] ?? null; - $this->isTranslated = false; - } + // 3. provided fallback message + if ($message === null) { + $message = $args['fallback'] ?? null; + $this->isTranslated = false; + } - if ($translate) { - // 4. translation for default key in current language - // 5. translation for default key in default language - if ($message === null) { - $message = I18n::translate(self::$prefix . '.' . static::$defaultKey); - $this->isTranslated = true; - } - } + if ($translate) { + // 4. translation for default key in current language + // 5. translation for default key in default language + if ($message === null) { + $message = I18n::translate(self::$prefix . '.' . static::$defaultKey); + $this->isTranslated = true; + } + } - // 6. default fallback message - if ($message === null) { - $message = static::$defaultFallback; - $this->isTranslated = false; - } + // 6. default fallback message + if ($message === null) { + $message = static::$defaultFallback; + $this->isTranslated = false; + } - // format message with passed data - $message = Str::template($message, $this->data, [ - 'fallback' => '-', - 'start' => '{', - 'end' => '}' - ]); + // format message with passed data + $message = Str::template($message, $this->data, [ + 'fallback' => '-', + 'start' => '{', + 'end' => '}' + ]); - // handover to Exception parent class constructor - parent::__construct($message, 0, $args['previous'] ?? null); - } + // handover to Exception parent class constructor + parent::__construct($message, 0, $args['previous'] ?? null); + } - // set the Exception code to the key - $this->code = $key; - } + // set the Exception code to the key + $this->code = $key; + } - /** - * Returns the file in which the Exception was created - * relative to the document root - * - * @return string - */ - final public function getFileRelative(): string - { - $file = $this->getFile(); - $docRoot = Environment::getGlobally('DOCUMENT_ROOT'); + /** + * Returns the file in which the Exception was created + * relative to the document root + * + * @return string + */ + final public function getFileRelative(): string + { + $file = $this->getFile(); + $docRoot = Environment::getGlobally('DOCUMENT_ROOT'); - if (empty($docRoot) === false) { - $file = ltrim(Str::after($file, $docRoot), '/'); - } + if (empty($docRoot) === false) { + $file = ltrim(Str::after($file, $docRoot), '/'); + } - return $file; - } + return $file; + } - /** - * Returns the data variables from the message - * - * @return array - */ - final public function getData(): array - { - return $this->data; - } + /** + * Returns the data variables from the message + * + * @return array + */ + final public function getData(): array + { + return $this->data; + } - /** - * Returns the additional details that are - * not included in the message - * - * @return array - */ - final public function getDetails(): array - { - return $this->details; - } + /** + * Returns the additional details that are + * not included in the message + * + * @return array + */ + final public function getDetails(): array + { + return $this->details; + } - /** - * Returns the exception key (error type) - * - * @return string - */ - final public function getKey(): string - { - return $this->getCode(); - } + /** + * Returns the exception key (error type) + * + * @return string + */ + final public function getKey(): string + { + return $this->getCode(); + } - /** - * Returns the HTTP code that corresponds - * with the exception - * - * @return array - */ - final public function getHttpCode(): int - { - return $this->httpCode; - } + /** + * Returns the HTTP code that corresponds + * with the exception + * + * @return array + */ + final public function getHttpCode(): int + { + return $this->httpCode; + } - /** - * Returns whether the exception message could - * be translated into the user's language - * - * @return bool - */ - final public function isTranslated(): bool - { - return $this->isTranslated; - } + /** + * Returns whether the exception message could + * be translated into the user's language + * + * @return bool + */ + final public function isTranslated(): bool + { + return $this->isTranslated; + } - /** - * Converts the object to an array - * - * @return array - */ - public function toArray(): array - { - return [ - 'exception' => static::class, - 'message' => $this->getMessage(), - 'key' => $this->getKey(), - 'file' => $this->getFileRelative(), - 'line' => $this->getLine(), - 'details' => $this->getDetails(), - 'code' => $this->getHttpCode() - ]; - } + /** + * Converts the object to an array + * + * @return array + */ + public function toArray(): array + { + return [ + 'exception' => static::class, + 'message' => $this->getMessage(), + 'key' => $this->getKey(), + 'file' => $this->getFileRelative(), + 'line' => $this->getLine(), + 'details' => $this->getDetails(), + 'code' => $this->getHttpCode() + ]; + } } diff --git a/kirby/src/Exception/InvalidArgumentException.php b/kirby/src/Exception/InvalidArgumentException.php index 874a522..d6cef17 100755 --- a/kirby/src/Exception/InvalidArgumentException.php +++ b/kirby/src/Exception/InvalidArgumentException.php @@ -14,8 +14,8 @@ namespace Kirby\Exception; */ class InvalidArgumentException extends Exception { - protected static $defaultKey = 'invalidArgument'; - protected static $defaultFallback = 'Invalid argument "{ argument }" in method "{ method }"'; - protected static $defaultHttpCode = 400; - protected static $defaultData = ['argument' => null, 'method' => null]; + protected static $defaultKey = 'invalidArgument'; + protected static $defaultFallback = 'Invalid argument "{ argument }" in method "{ method }"'; + protected static $defaultHttpCode = 400; + protected static $defaultData = ['argument' => null, 'method' => null]; } diff --git a/kirby/src/Exception/LogicException.php b/kirby/src/Exception/LogicException.php index 656c9bb..d1fbc55 100755 --- a/kirby/src/Exception/LogicException.php +++ b/kirby/src/Exception/LogicException.php @@ -14,7 +14,7 @@ namespace Kirby\Exception; */ class LogicException extends Exception { - protected static $defaultKey = 'logic'; - protected static $defaultFallback = 'This task cannot be finished'; - protected static $defaultHttpCode = 400; + protected static $defaultKey = 'logic'; + protected static $defaultFallback = 'This task cannot be finished'; + protected static $defaultHttpCode = 400; } diff --git a/kirby/src/Exception/NotFoundException.php b/kirby/src/Exception/NotFoundException.php index 2f84438..1f48c4b 100755 --- a/kirby/src/Exception/NotFoundException.php +++ b/kirby/src/Exception/NotFoundException.php @@ -14,7 +14,7 @@ namespace Kirby\Exception; */ class NotFoundException extends Exception { - protected static $defaultKey = 'notFound'; - protected static $defaultFallback = 'Not found'; - protected static $defaultHttpCode = 404; + protected static $defaultKey = 'notFound'; + protected static $defaultFallback = 'Not found'; + protected static $defaultHttpCode = 404; } diff --git a/kirby/src/Exception/PermissionException.php b/kirby/src/Exception/PermissionException.php index 8cf2a33..4863f66 100755 --- a/kirby/src/Exception/PermissionException.php +++ b/kirby/src/Exception/PermissionException.php @@ -15,7 +15,7 @@ namespace Kirby\Exception; */ class PermissionException extends Exception { - protected static $defaultKey = 'permission'; - protected static $defaultFallback = 'You are not allowed to do this'; - protected static $defaultHttpCode = 403; + protected static $defaultKey = 'permission'; + protected static $defaultFallback = 'You are not allowed to do this'; + protected static $defaultHttpCode = 403; } diff --git a/kirby/src/Filesystem/Asset.php b/kirby/src/Filesystem/Asset.php index 74a0124..e2ee880 100755 --- a/kirby/src/Filesystem/Asset.php +++ b/kirby/src/Filesystem/Asset.php @@ -18,100 +18,100 @@ use Kirby\Cms\FileModifications; */ class Asset { - use IsFile; - use FileModifications; + use IsFile; + use FileModifications; - /** - * Relative file path - * - * @var string - */ - protected $path; + /** + * Relative file path + * + * @var string + */ + protected $path; - /** - * Creates a new Asset object for the given path. - * - * @param string $path - */ - public function __construct(string $path) - { - $this->setProperties([ - 'path' => dirname($path), - 'root' => $this->kirby()->root('index') . '/' . $path, - 'url' => $this->kirby()->url('index') . '/' . $path - ]); - } + /** + * Creates a new Asset object for the given path. + * + * @param string $path + */ + public function __construct(string $path) + { + $this->setProperties([ + 'path' => dirname($path), + 'root' => $this->kirby()->root('index') . '/' . $path, + 'url' => $this->kirby()->url('index') . '/' . $path + ]); + } - /** - * Returns a unique id for the asset - * - * @return string - */ - public function id(): string - { - return $this->root(); - } + /** + * Returns a unique id for the asset + * + * @return string + */ + public function id(): string + { + return $this->root(); + } - /** - * Create a unique media hash - * - * @return string - */ - public function mediaHash(): string - { - return crc32($this->filename()) . '-' . $this->modified(); - } + /** + * Create a unique media hash + * + * @return string + */ + public function mediaHash(): string + { + return crc32($this->filename()) . '-' . $this->modified(); + } - /** - * Returns the relative path starting at the media folder - * - * @return string - */ - public function mediaPath(): string - { - return 'assets/' . $this->path() . '/' . $this->mediaHash() . '/' . $this->filename(); - } + /** + * Returns the relative path starting at the media folder + * + * @return string + */ + public function mediaPath(): string + { + return 'assets/' . $this->path() . '/' . $this->mediaHash() . '/' . $this->filename(); + } - /** - * Returns the absolute path to the file in the public media folder - * - * @return string - */ - public function mediaRoot(): string - { - return $this->kirby()->root('media') . '/' . $this->mediaPath(); - } + /** + * Returns the absolute path to the file in the public media folder + * + * @return string + */ + public function mediaRoot(): string + { + return $this->kirby()->root('media') . '/' . $this->mediaPath(); + } - /** - * Returns the absolute Url to the file in the public media folder - * - * @return string - */ - public function mediaUrl(): string - { - return $this->kirby()->url('media') . '/' . $this->mediaPath(); - } + /** + * Returns the absolute Url to the file in the public media folder + * + * @return string + */ + public function mediaUrl(): string + { + return $this->kirby()->url('media') . '/' . $this->mediaPath(); + } - /** - * Returns the path of the file from the web root, - * excluding the filename - * - * @return string - */ - public function path(): string - { - return $this->path; - } + /** + * Returns the path of the file from the web root, + * excluding the filename + * + * @return string + */ + public function path(): string + { + return $this->path; + } - /** - * Setter for the path - * - * @param string $path - * @return $this - */ - protected function setPath(string $path) - { - $this->path = $path === '.' ? '' : $path; - return $this; - } + /** + * Setter for the path + * + * @param string $path + * @return $this + */ + protected function setPath(string $path) + { + $this->path = $path === '.' ? '' : $path; + return $this; + } } diff --git a/kirby/src/Filesystem/Dir.php b/kirby/src/Filesystem/Dir.php index 3a3c5ba..133ec6d 100755 --- a/kirby/src/Filesystem/Dir.php +++ b/kirby/src/Filesystem/Dir.php @@ -28,591 +28,591 @@ use Throwable; */ class Dir { - /** - * Ignore when scanning directories - * - * @var array - */ - public static $ignore = [ - '.', - '..', - '.DS_Store', - '.gitignore', - '.git', - '.svn', - '.htaccess', - 'Thumb.db', - '@eaDir' - ]; - - public static $numSeparator = '_'; - - /** - * Copy the directory to a new destination - * - * @param string $dir - * @param string $target - * @param bool $recursive - * @param array $ignore - * @return bool - */ - public static function copy(string $dir, string $target, bool $recursive = true, array $ignore = []): bool - { - if (is_dir($dir) === false) { - throw new Exception('The directory "' . $dir . '" does not exist'); - } - - if (is_dir($target) === true) { - throw new Exception('The target directory "' . $target . '" exists'); - } - - if (static::make($target) !== true) { - throw new Exception('The target directory "' . $target . '" could not be created'); - } - - foreach (static::read($dir) as $name) { - $root = $dir . '/' . $name; - - if (in_array($root, $ignore) === true) { - continue; - } - - if (is_dir($root) === true) { - if ($recursive === true) { - static::copy($root, $target . '/' . $name, true, $ignore); - } - } else { - F::copy($root, $target . '/' . $name); - } - } - - return true; - } - - /** - * Get all subdirectories - * - * @param string $dir - * @param array $ignore - * @param bool $absolute - * @return array - */ - public static function dirs(string $dir, array $ignore = null, bool $absolute = false): array - { - $result = array_values(array_filter(static::read($dir, $ignore, true), 'is_dir')); - - if ($absolute !== true) { - $result = array_map('basename', $result); - } - - return $result; - } - - /** - * Checks if the directory exists on disk - * - * @param string $dir - * @return bool - */ - public static function exists(string $dir): bool - { - return is_dir($dir) === true; - } - - /** - * Get all files - * - * @param string $dir - * @param array $ignore - * @param bool $absolute - * @return array - */ - public static function files(string $dir, array $ignore = null, bool $absolute = false): array - { - $result = array_values(array_filter(static::read($dir, $ignore, true), 'is_file')); - - if ($absolute !== true) { - $result = array_map('basename', $result); - } - - return $result; - } - - /** - * Read the directory and all subdirectories - * - * @param string $dir - * @param bool $recursive - * @param array $ignore - * @param string $path - * @return array - */ - public static function index(string $dir, bool $recursive = false, array $ignore = null, string $path = null) - { - $result = []; - $dir = realpath($dir); - $items = static::read($dir); - - foreach ($items as $item) { - $root = $dir . '/' . $item; - $entry = $path !== null ? $path . '/' . $item : $item; - $result[] = $entry; - - if ($recursive === true && is_dir($root) === true) { - $result = array_merge($result, static::index($root, true, $ignore, $entry)); - } - } - - return $result; - } - - /** - * Checks if the folder has any contents - * - * @param string $dir - * @return bool - */ - public static function isEmpty(string $dir): bool - { - return count(static::read($dir)) === 0; - } - - /** - * Checks if the directory is readable - * - * @param string $dir - * @return bool - */ - public static function isReadable(string $dir): bool - { - return is_readable($dir); - } - - /** - * Checks if the directory is writable - * - * @param string $dir - * @return bool - */ - public static function isWritable(string $dir): bool - { - return is_writable($dir); - } - - /** - * Scans the directory and analyzes files, - * content, meta info and children. This is used - * in `Kirby\Cms\Page`, `Kirby\Cms\Site` and - * `Kirby\Cms\User` objects to fetch all - * relevant information. - * - * Don't use outside the Cms context. - * - * @internal - * - * @param string $dir - * @param string $contentExtension - * @param array|null $contentIgnore - * @param bool $multilang - * @return array - */ - public static function inventory(string $dir, string $contentExtension = 'txt', array $contentIgnore = null, bool $multilang = false): array - { - $dir = realpath($dir); - - $inventory = [ - 'children' => [], - 'files' => [], - 'template' => 'default', - ]; - - if ($dir === false) { - return $inventory; - } - - $items = static::read($dir, $contentIgnore); - - // a temporary store for all content files - $content = []; - - // sort all items naturally to avoid sorting issues later - natsort($items); - - foreach ($items as $item) { - - // ignore all items with a leading dot - if (in_array(substr($item, 0, 1), ['.', '_']) === true) { - continue; - } - - $root = $dir . '/' . $item; - - if (is_dir($root) === true) { - - // extract the slug and num of the directory - if (preg_match('/^([0-9]+)' . static::$numSeparator . '(.*)$/', $item, $match)) { - $num = (int)$match[1]; - $slug = $match[2]; - } else { - $num = null; - $slug = $item; - } - - $inventory['children'][] = [ - 'dirname' => $item, - 'model' => null, - 'num' => $num, - 'root' => $root, - 'slug' => $slug, - ]; - } else { - $extension = pathinfo($item, PATHINFO_EXTENSION); - - switch ($extension) { - case 'htm': - case 'html': - case 'php': - // don't track those files - break; - case $contentExtension: - $content[] = pathinfo($item, PATHINFO_FILENAME); - break; - default: - $inventory['files'][$item] = [ - 'filename' => $item, - 'extension' => $extension, - 'root' => $root, - ]; - } - } - } - - // remove the language codes from all content filenames - if ($multilang === true) { - foreach ($content as $key => $filename) { - $content[$key] = pathinfo($filename, PATHINFO_FILENAME); - } - - $content = array_unique($content); - } - - $inventory = static::inventoryContent($inventory, $content); - $inventory = static::inventoryModels($inventory, $contentExtension, $multilang); - - return $inventory; - } - - /** - * Take all content files, - * remove those who are meta files and - * detect the main content file - * - * @param array $inventory - * @param array $content - * @return array - */ - protected static function inventoryContent(array $inventory, array $content): array - { - - // filter meta files from the content file - if (empty($content) === true) { - $inventory['template'] = 'default'; - return $inventory; - } - - foreach ($content as $contentName) { - - // could be a meta file. i.e. cover.jpg - if (isset($inventory['files'][$contentName]) === true) { - continue; - } - - // it's most likely the template - $inventory['template'] = $contentName; - } - - return $inventory; - } - - /** - * Go through all inventory children - * and inject a model for each - * - * @param array $inventory - * @param string $contentExtension - * @param bool $multilang - * @return array - */ - protected static function inventoryModels(array $inventory, string $contentExtension, bool $multilang = false): array - { - // inject models - if (empty($inventory['children']) === false && empty(Page::$models) === false) { - if ($multilang === true) { - $contentExtension = App::instance()->defaultLanguage()->code() . '.' . $contentExtension; - } - - foreach ($inventory['children'] as $key => $child) { - foreach (Page::$models as $modelName => $modelClass) { - if (file_exists($child['root'] . '/' . $modelName . '.' . $contentExtension) === true) { - $inventory['children'][$key]['model'] = $modelName; - break; - } - } - } - } - - return $inventory; - } - - /** - * Create a (symbolic) link to a directory - * - * @param string $source - * @param string $link - * @return bool - */ - public static function link(string $source, string $link): bool - { - static::make(dirname($link), true); - - if (is_dir($link) === true) { - return true; - } - - if (is_dir($source) === false) { - throw new Exception(sprintf('The directory "%s" does not exist and cannot be linked', $source)); - } - - try { - return symlink($source, $link) === true; - } catch (Throwable $e) { - return false; - } - } - - /** - * Creates a new directory - * - * @param string $dir The path for the new directory - * @param bool $recursive Create all parent directories, which don't exist - * @return bool True: the dir has been created, false: creating failed - * @throws \Exception If a file with the provided path already exists or the parent directory is not writable - */ - public static function make(string $dir, bool $recursive = true): bool - { - if (empty($dir) === true) { - return false; - } - - if (is_dir($dir) === true) { - return true; - } - - if (is_file($dir) === true) { - throw new Exception(sprintf('A file with the name "%s" already exists', $dir)); - } - - $parent = dirname($dir); - - if ($recursive === true) { - if (is_dir($parent) === false) { - static::make($parent, true); - } - } - - if (is_writable($parent) === false) { - throw new Exception(sprintf('The directory "%s" cannot be created', $dir)); - } - - return mkdir($dir); - } - - /** - * Recursively check when the dir and all - * subfolders have been modified for the last time. - * - * @param string $dir The path of the directory - * @param string $format - * @param string $handler - * @return int|string - */ - public static function modified(string $dir, string $format = null, string $handler = 'date') - { - $modified = filemtime($dir); - $items = static::read($dir); - - foreach ($items as $item) { - if (is_file($dir . '/' . $item) === true) { - $newModified = filemtime($dir . '/' . $item); - } else { - $newModified = static::modified($dir . '/' . $item); - } - - $modified = ($newModified > $modified) ? $newModified : $modified; - } - - return Str::date($modified, $format, $handler); - } - - /** - * Moves a directory to a new location - * - * @param string $old The current path of the directory - * @param string $new The desired path where the dir should be moved to - * @return bool true: the directory has been moved, false: moving failed - */ - public static function move(string $old, string $new): bool - { - if ($old === $new) { - return true; - } - - if (is_dir($old) === false || is_dir($new) === true) { - return false; - } - - if (static::make(dirname($new), true) !== true) { - throw new Exception('The parent directory cannot be created'); - } - - return rename($old, $new); - } - - /** - * Returns a nicely formatted size of all the contents of the folder - * - * @param string $dir The path of the directory - * @param string|null|false $locale Locale for number formatting, - * `null` for the current locale, - * `false` to disable number formatting - * @return mixed - */ - public static function niceSize(string $dir, $locale = null) - { - return F::niceSize(static::size($dir), $locale); - } - - /** - * Reads all files from a directory and returns them as an array. - * It skips unwanted invisible stuff. - * - * @param string $dir The path of directory - * @param array $ignore Optional array with filenames, which should be ignored - * @param bool $absolute If true, the full path for each item will be returned - * @return array An array of filenames - */ - public static function read(string $dir, array $ignore = null, bool $absolute = false): array - { - if (is_dir($dir) === false) { - return []; - } - - // create the ignore pattern - $ignore ??= static::$ignore; - $ignore = array_merge($ignore, ['.', '..']); - - // scan for all files and dirs - $result = array_values((array)array_diff(scandir($dir), $ignore)); - - // add absolute paths - if ($absolute === true) { - $result = array_map(fn ($item) => $dir . '/' . $item, $result); - } - - return $result; - } - - /** - * Removes a folder including all containing files and folders - * - * @param string $dir - * @return bool - */ - public static function remove(string $dir): bool - { - $dir = realpath($dir); - - if (is_dir($dir) === false) { - return true; - } - - if (is_link($dir) === true) { - return unlink($dir); - } - - foreach (scandir($dir) as $childName) { - if (in_array($childName, ['.', '..']) === true) { - continue; - } - - $child = $dir . '/' . $childName; - - if (is_link($child) === true) { - unlink($child); - } elseif (is_dir($child) === true) { - static::remove($child); - } else { - F::remove($child); - } - } - - return rmdir($dir); - } - - /** - * Gets the size of the directory - * - * @param string $dir The path of the directory - * @param bool $recursive Include all subfolders and their files - * @return mixed - */ - public static function size(string $dir, bool $recursive = true) - { - if (is_dir($dir) === false) { - return false; - } - - // Get size for all direct files - $size = F::size(static::files($dir, null, true)); - - // if recursive, add sizes of all subdirectories - if ($recursive === true) { - foreach (static::dirs($dir, null, true) as $subdir) { - $size += static::size($subdir); - } - } - - return $size; - } - - /** - * Checks if the directory or any subdirectory has been - * modified after the given timestamp - * - * @param string $dir - * @param int $time - * @return bool - */ - public static function wasModifiedAfter(string $dir, int $time): bool - { - if (filemtime($dir) > $time) { - return true; - } - - $content = static::read($dir); - - foreach ($content as $item) { - $subdir = $dir . '/' . $item; - - if (filemtime($subdir) > $time) { - return true; - } - - if (is_dir($subdir) === true && static::wasModifiedAfter($subdir, $time) === true) { - return true; - } - } - - return false; - } + /** + * Ignore when scanning directories + * + * @var array + */ + public static $ignore = [ + '.', + '..', + '.DS_Store', + '.gitignore', + '.git', + '.svn', + '.htaccess', + 'Thumb.db', + '@eaDir' + ]; + + public static $numSeparator = '_'; + + /** + * Copy the directory to a new destination + * + * @param string $dir + * @param string $target + * @param bool $recursive + * @param array $ignore + * @return bool + */ + public static function copy(string $dir, string $target, bool $recursive = true, array $ignore = []): bool + { + if (is_dir($dir) === false) { + throw new Exception('The directory "' . $dir . '" does not exist'); + } + + if (is_dir($target) === true) { + throw new Exception('The target directory "' . $target . '" exists'); + } + + if (static::make($target) !== true) { + throw new Exception('The target directory "' . $target . '" could not be created'); + } + + foreach (static::read($dir) as $name) { + $root = $dir . '/' . $name; + + if (in_array($root, $ignore) === true) { + continue; + } + + if (is_dir($root) === true) { + if ($recursive === true) { + static::copy($root, $target . '/' . $name, true, $ignore); + } + } else { + F::copy($root, $target . '/' . $name); + } + } + + return true; + } + + /** + * Get all subdirectories + * + * @param string $dir + * @param array $ignore + * @param bool $absolute + * @return array + */ + public static function dirs(string $dir, array $ignore = null, bool $absolute = false): array + { + $result = array_values(array_filter(static::read($dir, $ignore, true), 'is_dir')); + + if ($absolute !== true) { + $result = array_map('basename', $result); + } + + return $result; + } + + /** + * Checks if the directory exists on disk + * + * @param string $dir + * @return bool + */ + public static function exists(string $dir): bool + { + return is_dir($dir) === true; + } + + /** + * Get all files + * + * @param string $dir + * @param array $ignore + * @param bool $absolute + * @return array + */ + public static function files(string $dir, array $ignore = null, bool $absolute = false): array + { + $result = array_values(array_filter(static::read($dir, $ignore, true), 'is_file')); + + if ($absolute !== true) { + $result = array_map('basename', $result); + } + + return $result; + } + + /** + * Read the directory and all subdirectories + * + * @param string $dir + * @param bool $recursive + * @param array $ignore + * @param string $path + * @return array + */ + public static function index(string $dir, bool $recursive = false, array $ignore = null, string $path = null) + { + $result = []; + $dir = realpath($dir); + $items = static::read($dir); + + foreach ($items as $item) { + $root = $dir . '/' . $item; + $entry = $path !== null ? $path . '/' . $item : $item; + $result[] = $entry; + + if ($recursive === true && is_dir($root) === true) { + $result = array_merge($result, static::index($root, true, $ignore, $entry)); + } + } + + return $result; + } + + /** + * Checks if the folder has any contents + * + * @param string $dir + * @return bool + */ + public static function isEmpty(string $dir): bool + { + return count(static::read($dir)) === 0; + } + + /** + * Checks if the directory is readable + * + * @param string $dir + * @return bool + */ + public static function isReadable(string $dir): bool + { + return is_readable($dir); + } + + /** + * Checks if the directory is writable + * + * @param string $dir + * @return bool + */ + public static function isWritable(string $dir): bool + { + return is_writable($dir); + } + + /** + * Scans the directory and analyzes files, + * content, meta info and children. This is used + * in `Kirby\Cms\Page`, `Kirby\Cms\Site` and + * `Kirby\Cms\User` objects to fetch all + * relevant information. + * + * Don't use outside the Cms context. + * + * @internal + * + * @param string $dir + * @param string $contentExtension + * @param array|null $contentIgnore + * @param bool $multilang + * @return array + */ + public static function inventory(string $dir, string $contentExtension = 'txt', array $contentIgnore = null, bool $multilang = false): array + { + $dir = realpath($dir); + + $inventory = [ + 'children' => [], + 'files' => [], + 'template' => 'default', + ]; + + if ($dir === false) { + return $inventory; + } + + $items = static::read($dir, $contentIgnore); + + // a temporary store for all content files + $content = []; + + // sort all items naturally to avoid sorting issues later + natsort($items); + + foreach ($items as $item) { + + // ignore all items with a leading dot + if (in_array(substr($item, 0, 1), ['.', '_']) === true) { + continue; + } + + $root = $dir . '/' . $item; + + if (is_dir($root) === true) { + + // extract the slug and num of the directory + if (preg_match('/^([0-9]+)' . static::$numSeparator . '(.*)$/', $item, $match)) { + $num = (int)$match[1]; + $slug = $match[2]; + } else { + $num = null; + $slug = $item; + } + + $inventory['children'][] = [ + 'dirname' => $item, + 'model' => null, + 'num' => $num, + 'root' => $root, + 'slug' => $slug, + ]; + } else { + $extension = pathinfo($item, PATHINFO_EXTENSION); + + switch ($extension) { + case 'htm': + case 'html': + case 'php': + // don't track those files + break; + case $contentExtension: + $content[] = pathinfo($item, PATHINFO_FILENAME); + break; + default: + $inventory['files'][$item] = [ + 'filename' => $item, + 'extension' => $extension, + 'root' => $root, + ]; + } + } + } + + // remove the language codes from all content filenames + if ($multilang === true) { + foreach ($content as $key => $filename) { + $content[$key] = pathinfo($filename, PATHINFO_FILENAME); + } + + $content = array_unique($content); + } + + $inventory = static::inventoryContent($inventory, $content); + $inventory = static::inventoryModels($inventory, $contentExtension, $multilang); + + return $inventory; + } + + /** + * Take all content files, + * remove those who are meta files and + * detect the main content file + * + * @param array $inventory + * @param array $content + * @return array + */ + protected static function inventoryContent(array $inventory, array $content): array + { + + // filter meta files from the content file + if (empty($content) === true) { + $inventory['template'] = 'default'; + return $inventory; + } + + foreach ($content as $contentName) { + + // could be a meta file. i.e. cover.jpg + if (isset($inventory['files'][$contentName]) === true) { + continue; + } + + // it's most likely the template + $inventory['template'] = $contentName; + } + + return $inventory; + } + + /** + * Go through all inventory children + * and inject a model for each + * + * @param array $inventory + * @param string $contentExtension + * @param bool $multilang + * @return array + */ + protected static function inventoryModels(array $inventory, string $contentExtension, bool $multilang = false): array + { + // inject models + if (empty($inventory['children']) === false && empty(Page::$models) === false) { + if ($multilang === true) { + $contentExtension = App::instance()->defaultLanguage()->code() . '.' . $contentExtension; + } + + foreach ($inventory['children'] as $key => $child) { + foreach (Page::$models as $modelName => $modelClass) { + if (file_exists($child['root'] . '/' . $modelName . '.' . $contentExtension) === true) { + $inventory['children'][$key]['model'] = $modelName; + break; + } + } + } + } + + return $inventory; + } + + /** + * Create a (symbolic) link to a directory + * + * @param string $source + * @param string $link + * @return bool + */ + public static function link(string $source, string $link): bool + { + static::make(dirname($link), true); + + if (is_dir($link) === true) { + return true; + } + + if (is_dir($source) === false) { + throw new Exception(sprintf('The directory "%s" does not exist and cannot be linked', $source)); + } + + try { + return symlink($source, $link) === true; + } catch (Throwable $e) { + return false; + } + } + + /** + * Creates a new directory + * + * @param string $dir The path for the new directory + * @param bool $recursive Create all parent directories, which don't exist + * @return bool True: the dir has been created, false: creating failed + * @throws \Exception If a file with the provided path already exists or the parent directory is not writable + */ + public static function make(string $dir, bool $recursive = true): bool + { + if (empty($dir) === true) { + return false; + } + + if (is_dir($dir) === true) { + return true; + } + + if (is_file($dir) === true) { + throw new Exception(sprintf('A file with the name "%s" already exists', $dir)); + } + + $parent = dirname($dir); + + if ($recursive === true) { + if (is_dir($parent) === false) { + static::make($parent, true); + } + } + + if (is_writable($parent) === false) { + throw new Exception(sprintf('The directory "%s" cannot be created', $dir)); + } + + return mkdir($dir); + } + + /** + * Recursively check when the dir and all + * subfolders have been modified for the last time. + * + * @param string $dir The path of the directory + * @param string $format + * @param string $handler + * @return int|string + */ + public static function modified(string $dir, string $format = null, string $handler = 'date') + { + $modified = filemtime($dir); + $items = static::read($dir); + + foreach ($items as $item) { + if (is_file($dir . '/' . $item) === true) { + $newModified = filemtime($dir . '/' . $item); + } else { + $newModified = static::modified($dir . '/' . $item); + } + + $modified = ($newModified > $modified) ? $newModified : $modified; + } + + return Str::date($modified, $format, $handler); + } + + /** + * Moves a directory to a new location + * + * @param string $old The current path of the directory + * @param string $new The desired path where the dir should be moved to + * @return bool true: the directory has been moved, false: moving failed + */ + public static function move(string $old, string $new): bool + { + if ($old === $new) { + return true; + } + + if (is_dir($old) === false || is_dir($new) === true) { + return false; + } + + if (static::make(dirname($new), true) !== true) { + throw new Exception('The parent directory cannot be created'); + } + + return rename($old, $new); + } + + /** + * Returns a nicely formatted size of all the contents of the folder + * + * @param string $dir The path of the directory + * @param string|null|false $locale Locale for number formatting, + * `null` for the current locale, + * `false` to disable number formatting + * @return mixed + */ + public static function niceSize(string $dir, $locale = null) + { + return F::niceSize(static::size($dir), $locale); + } + + /** + * Reads all files from a directory and returns them as an array. + * It skips unwanted invisible stuff. + * + * @param string $dir The path of directory + * @param array $ignore Optional array with filenames, which should be ignored + * @param bool $absolute If true, the full path for each item will be returned + * @return array An array of filenames + */ + public static function read(string $dir, array $ignore = null, bool $absolute = false): array + { + if (is_dir($dir) === false) { + return []; + } + + // create the ignore pattern + $ignore ??= static::$ignore; + $ignore = array_merge($ignore, ['.', '..']); + + // scan for all files and dirs + $result = array_values((array)array_diff(scandir($dir), $ignore)); + + // add absolute paths + if ($absolute === true) { + $result = array_map(fn ($item) => $dir . '/' . $item, $result); + } + + return $result; + } + + /** + * Removes a folder including all containing files and folders + * + * @param string $dir + * @return bool + */ + public static function remove(string $dir): bool + { + $dir = realpath($dir); + + if (is_dir($dir) === false) { + return true; + } + + if (is_link($dir) === true) { + return unlink($dir); + } + + foreach (scandir($dir) as $childName) { + if (in_array($childName, ['.', '..']) === true) { + continue; + } + + $child = $dir . '/' . $childName; + + if (is_link($child) === true) { + unlink($child); + } elseif (is_dir($child) === true) { + static::remove($child); + } else { + F::remove($child); + } + } + + return rmdir($dir); + } + + /** + * Gets the size of the directory + * + * @param string $dir The path of the directory + * @param bool $recursive Include all subfolders and their files + * @return mixed + */ + public static function size(string $dir, bool $recursive = true) + { + if (is_dir($dir) === false) { + return false; + } + + // Get size for all direct files + $size = F::size(static::files($dir, null, true)); + + // if recursive, add sizes of all subdirectories + if ($recursive === true) { + foreach (static::dirs($dir, null, true) as $subdir) { + $size += static::size($subdir); + } + } + + return $size; + } + + /** + * Checks if the directory or any subdirectory has been + * modified after the given timestamp + * + * @param string $dir + * @param int $time + * @return bool + */ + public static function wasModifiedAfter(string $dir, int $time): bool + { + if (filemtime($dir) > $time) { + return true; + } + + $content = static::read($dir); + + foreach ($content as $item) { + $subdir = $dir . '/' . $item; + + if (filemtime($subdir) > $time) { + return true; + } + + if (is_dir($subdir) === true && static::wasModifiedAfter($subdir, $time) === true) { + return true; + } + } + + return false; + } } diff --git a/kirby/src/Filesystem/F.php b/kirby/src/Filesystem/F.php index 452e723..1b55e5a 100755 --- a/kirby/src/Filesystem/F.php +++ b/kirby/src/Filesystem/F.php @@ -22,896 +22,896 @@ use ZipArchive; */ class F { - /** - * @var array - */ - public static $types = [ - 'archive' => [ - 'gz', - 'gzip', - 'tar', - 'tgz', - 'zip', - ], - 'audio' => [ - 'aif', - 'aiff', - 'm4a', - 'midi', - 'mp3', - 'wav', - ], - 'code' => [ - 'css', - 'js', - 'json', - 'java', - 'htm', - 'html', - 'php', - 'rb', - 'py', - 'scss', - 'xml', - 'yaml', - 'yml', - ], - 'document' => [ - 'csv', - 'doc', - 'docx', - 'dotx', - 'indd', - 'md', - 'mdown', - 'pdf', - 'ppt', - 'pptx', - 'rtf', - 'txt', - 'xl', - 'xls', - 'xlsx', - 'xltx', - ], - 'image' => [ - 'ai', - 'avif', - 'bmp', - 'gif', - 'eps', - 'ico', - 'j2k', - 'jp2', - 'jpeg', - 'jpg', - 'jpe', - 'png', - 'ps', - 'psd', - 'svg', - 'tif', - 'tiff', - 'webp' - ], - 'video' => [ - 'avi', - 'flv', - 'm4v', - 'mov', - 'movie', - 'mpe', - 'mpg', - 'mp4', - 'ogg', - 'ogv', - 'swf', - 'webm', - ], - ]; - - /** - * @var array - */ - public static $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; - - /** - * Appends new content to an existing file - * - * @param string $file The path for the file - * @param mixed $content Either a string or an array. Arrays will be converted to JSON. - * @return bool - */ - public static function append(string $file, $content): bool - { - return static::write($file, $content, true); - } - - /** - * Returns the file content as base64 encoded string - * - * @param string $file The path for the file - * @return string - */ - public static function base64(string $file): string - { - return base64_encode(static::read($file)); - } - - /** - * Copy a file to a new location. - * - * @param string $source - * @param string $target - * @param bool $force - * @return bool - */ - public static function copy(string $source, string $target, bool $force = false): bool - { - if (file_exists($source) === false || (file_exists($target) === true && $force === false)) { - return false; - } - - $directory = dirname($target); - - // create the parent directory if it does not exist - if (is_dir($directory) === false) { - Dir::make($directory, true); - } - - return copy($source, $target); - } - - /** - * Just an alternative for dirname() to stay consistent - * - * - * - * $dirname = F::dirname('/var/www/test.txt'); - * // dirname is /var/www - * - * - * - * @param string $file The path - * @return string - */ - public static function dirname(string $file): string - { - return dirname($file); - } - - /** - * Checks if the file exists on disk - * - * @param string $file - * @param string $in - * @return bool - */ - public static function exists(string $file, string $in = null): bool - { - try { - static::realpath($file, $in); - return true; - } catch (Exception $e) { - return false; - } - } - - /** - * Gets the extension of a file - * - * @param string $file The filename or path - * @param string $extension Set an optional extension to overwrite the current one - * @return string - */ - public static function extension(string $file = null, string $extension = null): string - { - // overwrite the current extension - if ($extension !== null) { - return static::name($file) . '.' . $extension; - } - - // return the current extension - return Str::lower(pathinfo($file, PATHINFO_EXTENSION)); - } - - /** - * Converts a file extension to a mime type - * - * @param string $extension - * @return string|false - */ - public static function extensionToMime(string $extension) - { - return Mime::fromExtension($extension); - } - - /** - * Returns the file type for a passed extension - * - * @param string $extension - * @return string|false - */ - public static function extensionToType(string $extension) - { - foreach (static::$types as $type => $extensions) { - if (in_array($extension, $extensions) === true) { - return $type; - } - } - - return false; - } - - /** - * Returns all extensions for a certain file type - * - * @param string $type - * @return array - */ - public static function extensions(string $type = null) - { - if ($type === null) { - return array_keys(Mime::types()); - } - - return static::$types[$type] ?? []; - } - - /** - * Extracts the filename from a file path - * - * - * - * $filename = F::filename('/var/www/test.txt'); - * // filename is test.txt - * - * - * - * @param string $name The path - * @return string - */ - public static function filename(string $name): string - { - return pathinfo($name, PATHINFO_BASENAME); - } - - /** - * Invalidate opcode cache for file. - * - * @param string $file The path of the file - * @return bool - */ - public static function invalidateOpcodeCache(string $file): bool - { - if (function_exists('opcache_invalidate') && strlen(ini_get('opcache.restrict_api')) === 0) { - return opcache_invalidate($file, true); - } else { - return false; - } - } - - /** - * Checks if a file is of a certain type - * - * @param string $file Full path to the file - * @param string $value An extension or mime type - * @return bool - */ - public static function is(string $file, string $value): bool - { - // check for the extension - if (in_array($value, static::extensions()) === true) { - return static::extension($file) === $value; - } - - // check for the mime type - if (strpos($value, '/') !== false) { - return static::mime($file) === $value; - } - - return false; - } - - /** - * Checks if the file is readable - * - * @param string $file - * @return bool - */ - public static function isReadable(string $file): bool - { - return is_readable($file); - } - - /** - * Checks if the file is writable - * - * @param string $file - * @return bool - */ - public static function isWritable(string $file): bool - { - if (file_exists($file) === false) { - return is_writable(dirname($file)); - } - - return is_writable($file); - } - - /** - * Create a (symbolic) link to a file - * - * @param string $source - * @param string $link - * @param string $method - * @return bool - */ - public static function link(string $source, string $link, string $method = 'link'): bool - { - Dir::make(dirname($link), true); - - if (is_file($link) === true) { - return true; - } - - if (is_file($source) === false) { - throw new Exception(sprintf('The file "%s" does not exist and cannot be linked', $source)); - } - - try { - return $method($source, $link) === true; - } catch (Throwable $e) { - return false; - } - } - - /** - * Loads a file and returns the result or `false` if the - * file to load does not exist - * - * @param string $file - * @param mixed $fallback - * @param array $data Optional array of variables to extract in the variable scope - * @return mixed - */ - public static function load(string $file, $fallback = null, array $data = []) - { - if (is_file($file) === false) { - return $fallback; - } - - // we use the loadIsolated() method here to prevent the included - // file from overwriting our $fallback in this variable scope; see - // https://www.php.net/manual/en/function.include.php#example-124 - $result = static::loadIsolated($file, $data); - - if ($fallback !== null && gettype($result) !== gettype($fallback)) { - return $fallback; - } - - return $result; - } - - /** - * A super simple class autoloader - * @since 3.7.0 - * - * @param array $classmap - * @param string|null $base - * @return void - */ - public static function loadClasses(array $classmap, ?string $base = null): void - { - // convert all classnames to lowercase - $classmap = array_change_key_case($classmap); - - spl_autoload_register(function ($class) use ($classmap, $base) { - $class = strtolower($class); - - if (!isset($classmap[$class])) { - return false; - } - - if ($base) { - include $base . '/' . $classmap[$class]; - } else { - include $classmap[$class]; - } - }); - } - - /** - * Loads a file with as little as possible in the variable scope - * - * @param string $file - * @param array $data Optional array of variables to extract in the variable scope - * @return mixed - */ - protected static function loadIsolated(string $file, array $data = []) - { - // extract the $data variables in this scope to be accessed by the included file; - // protect $file against being overwritten by a $data variable - $___file___ = $file; - extract($data); - - return include $___file___; - } - - /** - * Loads a file using `include_once()` and returns whether loading was successful - * - * @param string $file - * @return bool - */ - public static function loadOnce(string $file): bool - { - if (is_file($file) === false) { - return false; - } - - include_once $file; - return true; - } - - /** - * Returns the mime type of a file - * - * @param string $file - * @return string|false - */ - public static function mime(string $file) - { - return Mime::type($file); - } - - /** - * Converts a mime type to a file extension - * - * @param string $mime - * @return string|false - */ - public static function mimeToExtension(string $mime = null) - { - return Mime::toExtension($mime); - } - - /** - * Returns the type for a given mime - * - * @param string $mime - * @return string|false - */ - public static function mimeToType(string $mime) - { - return static::extensionToType(Mime::toExtension($mime)); - } - - /** - * Get the file's last modification time. - * - * @param string $file - * @param string|\IntlDateFormatter|null $format - * @param string $handler date, intl or strftime - * @return mixed - */ - public static function modified(string $file, $format = null, string $handler = 'date') - { - if (file_exists($file) !== true) { - return false; - } - - $modified = filemtime($file); - - return Str::date($modified, $format, $handler); - } - - /** - * Moves a file to a new location - * - * @param string $oldRoot The current path for the file - * @param string $newRoot The path to the new location - * @param bool $force Force move if the target file exists - * @return bool - */ - public static function move(string $oldRoot, string $newRoot, bool $force = false): bool - { - // check if the file exists - if (file_exists($oldRoot) === false) { - return false; - } - - if (file_exists($newRoot) === true) { - if ($force === false) { - return false; - } - - // delete the existing file - static::remove($newRoot); - } - - // actually move the file if it exists - if (rename($oldRoot, $newRoot) !== true) { - return false; - } - - return true; - } - - /** - * Extracts the name from a file path or filename without extension - * - * @param string $name The path or filename - * @return string - */ - public static function name(string $name): string - { - return pathinfo($name, PATHINFO_FILENAME); - } - - /** - * Converts an integer size into a human readable format - * - * @param mixed $size The file size, a file path or array of paths - * @param string|null|false $locale Locale for number formatting, - * `null` for the current locale, - * `false` to disable number formatting - * @return string - */ - public static function niceSize($size, $locale = null): string - { - // file mode - if (is_string($size) === true || is_array($size) === true) { - $size = static::size($size); - } - - // make sure it's an int - $size = (int)$size; - - // avoid errors for invalid sizes - if ($size <= 0) { - return '0 KB'; - } - - // the math magic - $size = round($size / pow(1024, ($unit = floor(log($size, 1024)))), 2); - - // format the number if requested - if ($locale !== false) { - $size = I18n::formatNumber($size, $locale); - } - - return $size . ' ' . static::$units[$unit]; - } - - /** - * Reads the content of a file or requests the - * contents of a remote HTTP or HTTPS URL - * - * @param string $file The path for the file or an absolute URL - * @return string|false - */ - public static function read(string $file) - { - if ( - is_file($file) !== true && - Str::startsWith($file, 'https://') !== true && - Str::startsWith($file, 'http://') !== true - ) { - return false; - } - - return @file_get_contents($file); - } - - /** - * Changes the name of the file without - * touching the extension - * - * @param string $file - * @param string $newName - * @param bool $overwrite Force overwrite existing files - * @return string|false - */ - public static function rename(string $file, string $newName, bool $overwrite = false) - { - // create the new name - $name = static::safeName(basename($newName)); - - // overwrite the root - $newRoot = rtrim(dirname($file) . '/' . $name . '.' . F::extension($file), '.'); - - // nothing has changed - if ($newRoot === $file) { - return $newRoot; - } - - if (F::move($file, $newRoot, $overwrite) !== true) { - return false; - } - - return $newRoot; - } - - /** - * Returns the absolute path to the file if the file can be found. - * - * @param string $file - * @param string $in - * @return string|null - */ - public static function realpath(string $file, string $in = null) - { - $realpath = realpath($file); - - if ($realpath === false || is_file($realpath) === false) { - throw new Exception(sprintf('The file does not exist at the given path: "%s"', $file)); - } - - if ($in !== null) { - $parent = realpath($in); - - if ($parent === false || is_dir($parent) === false) { - throw new Exception(sprintf('The parent directory does not exist: "%s"', $in)); - } - - if (substr($realpath, 0, strlen($parent)) !== $parent) { - throw new Exception('The file is not within the parent directory'); - } - } - - return $realpath; - } - - /** - * Returns the relative path of the file - * starting after $in - * - * @SuppressWarnings(PHPMD.CountInLoopExpression) - * - * @param string $file - * @param string $in - * @return string - */ - public static function relativepath(string $file, string $in = null): string - { - if (empty($in) === true) { - return basename($file); - } - - // windows - $file = str_replace('\\', '/', $file); - $in = str_replace('\\', '/', $in); - - // trim trailing slashes - $file = rtrim($file, '/'); - $in = rtrim($in, '/'); - - if (Str::contains($file, $in . '/') === false) { - // make the paths relative by stripping what they have - // in common and adding `../` tokens at the start - $fileParts = explode('/', $file); - $inParts = explode('/', $in); - while (count($fileParts) && count($inParts) && ($fileParts[0] === $inParts[0])) { - array_shift($fileParts); - array_shift($inParts); - } - - return str_repeat('../', count($inParts)) . implode('/', $fileParts); - } - - return '/' . Str::after($file, $in . '/'); - } - - /** - * Deletes a file - * - * - * - * $remove = F::remove('test.txt'); - * if($remove) echo 'The file has been removed'; - * - * - * - * @param string $file The path for the file - * @return bool - */ - public static function remove(string $file): bool - { - if (strpos($file, '*') !== false) { - foreach (glob($file) as $f) { - static::remove($f); - } - - return true; - } - - $file = realpath($file); - - if (file_exists($file) === false) { - return true; - } - - return unlink($file); - } - - /** - * Sanitize a filename to strip unwanted special characters - * - * - * - * $safe = f::safeName('über genius.txt'); - * // safe will be ueber-genius.txt - * - * - * - * @param string $string The file name - * @return string - */ - public static function safeName(string $string): string - { - $name = static::name($string); - $extension = static::extension($string); - $safeName = Str::slug($name, '-', 'a-z0-9@._-'); - $safeExtension = empty($extension) === false ? '.' . Str::slug($extension) : ''; - - return $safeName . $safeExtension; - } - - /** - * Tries to find similar or the same file by - * building a glob based on the path - * - * @param string $path - * @param string $pattern - * @return array - */ - public static function similar(string $path, string $pattern = '*'): array - { - $dir = dirname($path); - $name = static::name($path); - $extension = static::extension($path); - $glob = $dir . '/' . $name . $pattern . '.' . $extension; - return glob($glob); - } - - /** - * Returns the size of a file or an array of files. - * - * @param string|array $file file path or array of paths - * @return int - */ - public static function size($file): int - { - if (is_array($file) === true) { - return array_reduce( - $file, - fn ($total, $file) => $total + F::size($file), - 0 - ); - } - - try { - return filesize($file); - } catch (Throwable $e) { - return 0; - } - } - - /** - * Categorize the file - * - * @param string $file Either the file path or extension - * @return string|null - */ - public static function type(string $file) - { - $length = strlen($file); - - if ($length >= 2 && $length <= 4) { - // use the file name as extension - $extension = $file; - } else { - // get the extension from the filename - $extension = pathinfo($file, PATHINFO_EXTENSION); - } - - if (empty($extension) === true) { - // detect the mime type first to get the most reliable extension - $mime = static::mime($file); - $extension = static::mimeToExtension($mime); - } - - // sanitize extension - $extension = strtolower($extension); - - foreach (static::$types as $type => $extensions) { - if (in_array($extension, $extensions) === true) { - return $type; - } - } - - return null; - } - - /** - * Returns all extensions of a given file type - * or `null` if the file type is unknown - * - * @param string $type - * @return array|null - */ - public static function typeToExtensions(string $type): ?array - { - return static::$types[$type] ?? null; - } - - /** - * Unzips a zip file - * - * @param string $file - * @param string $to - * @return bool - */ - public static function unzip(string $file, string $to): bool - { - if (class_exists('ZipArchive') === false) { - throw new Exception('The ZipArchive class is not available'); - } - - $zip = new ZipArchive(); - - if ($zip->open($file) === true) { - $zip->extractTo($to); - $zip->close(); - return true; - } - - return false; - } - - /** - * Returns the file as data uri - * - * @param string $file The path for the file - * @return string|false - */ - public static function uri(string $file) - { - if ($mime = static::mime($file)) { - return 'data:' . $mime . ';base64,' . static::base64($file); - } - - return false; - } - - /** - * Creates a new file - * - * @param string $file The path for the new file - * @param mixed $content Either a string, an object or an array. Arrays and objects will be serialized. - * @param bool $append true: append the content to an existing file if available. false: overwrite. - * @return bool - */ - public static function write(string $file, $content, bool $append = false): bool - { - if (is_array($content) === true || is_object($content) === true) { - $content = serialize($content); - } - - $mode = $append === true ? FILE_APPEND | LOCK_EX : LOCK_EX; - - // if the parent directory does not exist, create it - if (is_dir(dirname($file)) === false) { - if (Dir::make(dirname($file)) === false) { - return false; - } - } - - if (static::isWritable($file) === false) { - throw new Exception('The file "' . $file . '" is not writable'); - } - - return file_put_contents($file, $content, $mode) !== false; - } + /** + * @var array + */ + public static $types = [ + 'archive' => [ + 'gz', + 'gzip', + 'tar', + 'tgz', + 'zip', + ], + 'audio' => [ + 'aif', + 'aiff', + 'm4a', + 'midi', + 'mp3', + 'wav', + ], + 'code' => [ + 'css', + 'js', + 'json', + 'java', + 'htm', + 'html', + 'php', + 'rb', + 'py', + 'scss', + 'xml', + 'yaml', + 'yml', + ], + 'document' => [ + 'csv', + 'doc', + 'docx', + 'dotx', + 'indd', + 'md', + 'mdown', + 'pdf', + 'ppt', + 'pptx', + 'rtf', + 'txt', + 'xl', + 'xls', + 'xlsx', + 'xltx', + ], + 'image' => [ + 'ai', + 'avif', + 'bmp', + 'gif', + 'eps', + 'ico', + 'j2k', + 'jp2', + 'jpeg', + 'jpg', + 'jpe', + 'png', + 'ps', + 'psd', + 'svg', + 'tif', + 'tiff', + 'webp' + ], + 'video' => [ + 'avi', + 'flv', + 'm4v', + 'mov', + 'movie', + 'mpe', + 'mpg', + 'mp4', + 'ogg', + 'ogv', + 'swf', + 'webm', + ], + ]; + + /** + * @var array + */ + public static $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + + /** + * Appends new content to an existing file + * + * @param string $file The path for the file + * @param mixed $content Either a string or an array. Arrays will be converted to JSON. + * @return bool + */ + public static function append(string $file, $content): bool + { + return static::write($file, $content, true); + } + + /** + * Returns the file content as base64 encoded string + * + * @param string $file The path for the file + * @return string + */ + public static function base64(string $file): string + { + return base64_encode(static::read($file)); + } + + /** + * Copy a file to a new location. + * + * @param string $source + * @param string $target + * @param bool $force + * @return bool + */ + public static function copy(string $source, string $target, bool $force = false): bool + { + if (file_exists($source) === false || (file_exists($target) === true && $force === false)) { + return false; + } + + $directory = dirname($target); + + // create the parent directory if it does not exist + if (is_dir($directory) === false) { + Dir::make($directory, true); + } + + return copy($source, $target); + } + + /** + * Just an alternative for dirname() to stay consistent + * + * + * + * $dirname = F::dirname('/var/www/test.txt'); + * // dirname is /var/www + * + * + * + * @param string $file The path + * @return string + */ + public static function dirname(string $file): string + { + return dirname($file); + } + + /** + * Checks if the file exists on disk + * + * @param string $file + * @param string $in + * @return bool + */ + public static function exists(string $file, string $in = null): bool + { + try { + static::realpath($file, $in); + return true; + } catch (Exception $e) { + return false; + } + } + + /** + * Gets the extension of a file + * + * @param string $file The filename or path + * @param string $extension Set an optional extension to overwrite the current one + * @return string + */ + public static function extension(string $file = null, string $extension = null): string + { + // overwrite the current extension + if ($extension !== null) { + return static::name($file) . '.' . $extension; + } + + // return the current extension + return Str::lower(pathinfo($file, PATHINFO_EXTENSION)); + } + + /** + * Converts a file extension to a mime type + * + * @param string $extension + * @return string|false + */ + public static function extensionToMime(string $extension) + { + return Mime::fromExtension($extension); + } + + /** + * Returns the file type for a passed extension + * + * @param string $extension + * @return string|false + */ + public static function extensionToType(string $extension) + { + foreach (static::$types as $type => $extensions) { + if (in_array($extension, $extensions) === true) { + return $type; + } + } + + return false; + } + + /** + * Returns all extensions for a certain file type + * + * @param string $type + * @return array + */ + public static function extensions(string $type = null) + { + if ($type === null) { + return array_keys(Mime::types()); + } + + return static::$types[$type] ?? []; + } + + /** + * Extracts the filename from a file path + * + * + * + * $filename = F::filename('/var/www/test.txt'); + * // filename is test.txt + * + * + * + * @param string $name The path + * @return string + */ + public static function filename(string $name): string + { + return pathinfo($name, PATHINFO_BASENAME); + } + + /** + * Invalidate opcode cache for file. + * + * @param string $file The path of the file + * @return bool + */ + public static function invalidateOpcodeCache(string $file): bool + { + if (function_exists('opcache_invalidate') && strlen(ini_get('opcache.restrict_api')) === 0) { + return opcache_invalidate($file, true); + } else { + return false; + } + } + + /** + * Checks if a file is of a certain type + * + * @param string $file Full path to the file + * @param string $value An extension or mime type + * @return bool + */ + public static function is(string $file, string $value): bool + { + // check for the extension + if (in_array($value, static::extensions()) === true) { + return static::extension($file) === $value; + } + + // check for the mime type + if (strpos($value, '/') !== false) { + return static::mime($file) === $value; + } + + return false; + } + + /** + * Checks if the file is readable + * + * @param string $file + * @return bool + */ + public static function isReadable(string $file): bool + { + return is_readable($file); + } + + /** + * Checks if the file is writable + * + * @param string $file + * @return bool + */ + public static function isWritable(string $file): bool + { + if (file_exists($file) === false) { + return is_writable(dirname($file)); + } + + return is_writable($file); + } + + /** + * Create a (symbolic) link to a file + * + * @param string $source + * @param string $link + * @param string $method + * @return bool + */ + public static function link(string $source, string $link, string $method = 'link'): bool + { + Dir::make(dirname($link), true); + + if (is_file($link) === true) { + return true; + } + + if (is_file($source) === false) { + throw new Exception(sprintf('The file "%s" does not exist and cannot be linked', $source)); + } + + try { + return $method($source, $link) === true; + } catch (Throwable $e) { + return false; + } + } + + /** + * Loads a file and returns the result or `false` if the + * file to load does not exist + * + * @param string $file + * @param mixed $fallback + * @param array $data Optional array of variables to extract in the variable scope + * @return mixed + */ + public static function load(string $file, $fallback = null, array $data = []) + { + if (is_file($file) === false) { + return $fallback; + } + + // we use the loadIsolated() method here to prevent the included + // file from overwriting our $fallback in this variable scope; see + // https://www.php.net/manual/en/function.include.php#example-124 + $result = static::loadIsolated($file, $data); + + if ($fallback !== null && gettype($result) !== gettype($fallback)) { + return $fallback; + } + + return $result; + } + + /** + * A super simple class autoloader + * @since 3.7.0 + * + * @param array $classmap + * @param string|null $base + * @return void + */ + public static function loadClasses(array $classmap, ?string $base = null): void + { + // convert all classnames to lowercase + $classmap = array_change_key_case($classmap); + + spl_autoload_register(function ($class) use ($classmap, $base) { + $class = strtolower($class); + + if (!isset($classmap[$class])) { + return false; + } + + if ($base) { + include $base . '/' . $classmap[$class]; + } else { + include $classmap[$class]; + } + }); + } + + /** + * Loads a file with as little as possible in the variable scope + * + * @param string $file + * @param array $data Optional array of variables to extract in the variable scope + * @return mixed + */ + protected static function loadIsolated(string $file, array $data = []) + { + // extract the $data variables in this scope to be accessed by the included file; + // protect $file against being overwritten by a $data variable + $___file___ = $file; + extract($data); + + return include $___file___; + } + + /** + * Loads a file using `include_once()` and returns whether loading was successful + * + * @param string $file + * @return bool + */ + public static function loadOnce(string $file): bool + { + if (is_file($file) === false) { + return false; + } + + include_once $file; + return true; + } + + /** + * Returns the mime type of a file + * + * @param string $file + * @return string|false + */ + public static function mime(string $file) + { + return Mime::type($file); + } + + /** + * Converts a mime type to a file extension + * + * @param string $mime + * @return string|false + */ + public static function mimeToExtension(string $mime = null) + { + return Mime::toExtension($mime); + } + + /** + * Returns the type for a given mime + * + * @param string $mime + * @return string|false + */ + public static function mimeToType(string $mime) + { + return static::extensionToType(Mime::toExtension($mime)); + } + + /** + * Get the file's last modification time. + * + * @param string $file + * @param string|\IntlDateFormatter|null $format + * @param string $handler date, intl or strftime + * @return mixed + */ + public static function modified(string $file, $format = null, string $handler = 'date') + { + if (file_exists($file) !== true) { + return false; + } + + $modified = filemtime($file); + + return Str::date($modified, $format, $handler); + } + + /** + * Moves a file to a new location + * + * @param string $oldRoot The current path for the file + * @param string $newRoot The path to the new location + * @param bool $force Force move if the target file exists + * @return bool + */ + public static function move(string $oldRoot, string $newRoot, bool $force = false): bool + { + // check if the file exists + if (file_exists($oldRoot) === false) { + return false; + } + + if (file_exists($newRoot) === true) { + if ($force === false) { + return false; + } + + // delete the existing file + static::remove($newRoot); + } + + // actually move the file if it exists + if (rename($oldRoot, $newRoot) !== true) { + return false; + } + + return true; + } + + /** + * Extracts the name from a file path or filename without extension + * + * @param string $name The path or filename + * @return string + */ + public static function name(string $name): string + { + return pathinfo($name, PATHINFO_FILENAME); + } + + /** + * Converts an integer size into a human readable format + * + * @param mixed $size The file size, a file path or array of paths + * @param string|null|false $locale Locale for number formatting, + * `null` for the current locale, + * `false` to disable number formatting + * @return string + */ + public static function niceSize($size, $locale = null): string + { + // file mode + if (is_string($size) === true || is_array($size) === true) { + $size = static::size($size); + } + + // make sure it's an int + $size = (int)$size; + + // avoid errors for invalid sizes + if ($size <= 0) { + return '0 KB'; + } + + // the math magic + $size = round($size / pow(1024, ($unit = floor(log($size, 1024)))), 2); + + // format the number if requested + if ($locale !== false) { + $size = I18n::formatNumber($size, $locale); + } + + return $size . ' ' . static::$units[$unit]; + } + + /** + * Reads the content of a file or requests the + * contents of a remote HTTP or HTTPS URL + * + * @param string $file The path for the file or an absolute URL + * @return string|false + */ + public static function read(string $file) + { + if ( + is_file($file) !== true && + Str::startsWith($file, 'https://') !== true && + Str::startsWith($file, 'http://') !== true + ) { + return false; + } + + return @file_get_contents($file); + } + + /** + * Changes the name of the file without + * touching the extension + * + * @param string $file + * @param string $newName + * @param bool $overwrite Force overwrite existing files + * @return string|false + */ + public static function rename(string $file, string $newName, bool $overwrite = false) + { + // create the new name + $name = static::safeName(basename($newName)); + + // overwrite the root + $newRoot = rtrim(dirname($file) . '/' . $name . '.' . F::extension($file), '.'); + + // nothing has changed + if ($newRoot === $file) { + return $newRoot; + } + + if (F::move($file, $newRoot, $overwrite) !== true) { + return false; + } + + return $newRoot; + } + + /** + * Returns the absolute path to the file if the file can be found. + * + * @param string $file + * @param string $in + * @return string|null + */ + public static function realpath(string $file, string $in = null) + { + $realpath = realpath($file); + + if ($realpath === false || is_file($realpath) === false) { + throw new Exception(sprintf('The file does not exist at the given path: "%s"', $file)); + } + + if ($in !== null) { + $parent = realpath($in); + + if ($parent === false || is_dir($parent) === false) { + throw new Exception(sprintf('The parent directory does not exist: "%s"', $in)); + } + + if (substr($realpath, 0, strlen($parent)) !== $parent) { + throw new Exception('The file is not within the parent directory'); + } + } + + return $realpath; + } + + /** + * Returns the relative path of the file + * starting after $in + * + * @SuppressWarnings(PHPMD.CountInLoopExpression) + * + * @param string $file + * @param string $in + * @return string + */ + public static function relativepath(string $file, string $in = null): string + { + if (empty($in) === true) { + return basename($file); + } + + // windows + $file = str_replace('\\', '/', $file); + $in = str_replace('\\', '/', $in); + + // trim trailing slashes + $file = rtrim($file, '/'); + $in = rtrim($in, '/'); + + if (Str::contains($file, $in . '/') === false) { + // make the paths relative by stripping what they have + // in common and adding `../` tokens at the start + $fileParts = explode('/', $file); + $inParts = explode('/', $in); + while (count($fileParts) && count($inParts) && ($fileParts[0] === $inParts[0])) { + array_shift($fileParts); + array_shift($inParts); + } + + return str_repeat('../', count($inParts)) . implode('/', $fileParts); + } + + return '/' . Str::after($file, $in . '/'); + } + + /** + * Deletes a file + * + * + * + * $remove = F::remove('test.txt'); + * if($remove) echo 'The file has been removed'; + * + * + * + * @param string $file The path for the file + * @return bool + */ + public static function remove(string $file): bool + { + if (strpos($file, '*') !== false) { + foreach (glob($file) as $f) { + static::remove($f); + } + + return true; + } + + $file = realpath($file); + + if (file_exists($file) === false) { + return true; + } + + return unlink($file); + } + + /** + * Sanitize a filename to strip unwanted special characters + * + * + * + * $safe = f::safeName('über genius.txt'); + * // safe will be ueber-genius.txt + * + * + * + * @param string $string The file name + * @return string + */ + public static function safeName(string $string): string + { + $name = static::name($string); + $extension = static::extension($string); + $safeName = Str::slug($name, '-', 'a-z0-9@._-'); + $safeExtension = empty($extension) === false ? '.' . Str::slug($extension) : ''; + + return $safeName . $safeExtension; + } + + /** + * Tries to find similar or the same file by + * building a glob based on the path + * + * @param string $path + * @param string $pattern + * @return array + */ + public static function similar(string $path, string $pattern = '*'): array + { + $dir = dirname($path); + $name = static::name($path); + $extension = static::extension($path); + $glob = $dir . '/' . $name . $pattern . '.' . $extension; + return glob($glob); + } + + /** + * Returns the size of a file or an array of files. + * + * @param string|array $file file path or array of paths + * @return int + */ + public static function size($file): int + { + if (is_array($file) === true) { + return array_reduce( + $file, + fn ($total, $file) => $total + F::size($file), + 0 + ); + } + + try { + return filesize($file); + } catch (Throwable $e) { + return 0; + } + } + + /** + * Categorize the file + * + * @param string $file Either the file path or extension + * @return string|null + */ + public static function type(string $file) + { + $length = strlen($file); + + if ($length >= 2 && $length <= 4) { + // use the file name as extension + $extension = $file; + } else { + // get the extension from the filename + $extension = pathinfo($file, PATHINFO_EXTENSION); + } + + if (empty($extension) === true) { + // detect the mime type first to get the most reliable extension + $mime = static::mime($file); + $extension = static::mimeToExtension($mime); + } + + // sanitize extension + $extension = strtolower($extension); + + foreach (static::$types as $type => $extensions) { + if (in_array($extension, $extensions) === true) { + return $type; + } + } + + return null; + } + + /** + * Returns all extensions of a given file type + * or `null` if the file type is unknown + * + * @param string $type + * @return array|null + */ + public static function typeToExtensions(string $type): ?array + { + return static::$types[$type] ?? null; + } + + /** + * Unzips a zip file + * + * @param string $file + * @param string $to + * @return bool + */ + public static function unzip(string $file, string $to): bool + { + if (class_exists('ZipArchive') === false) { + throw new Exception('The ZipArchive class is not available'); + } + + $zip = new ZipArchive(); + + if ($zip->open($file) === true) { + $zip->extractTo($to); + $zip->close(); + return true; + } + + return false; + } + + /** + * Returns the file as data uri + * + * @param string $file The path for the file + * @return string|false + */ + public static function uri(string $file) + { + if ($mime = static::mime($file)) { + return 'data:' . $mime . ';base64,' . static::base64($file); + } + + return false; + } + + /** + * Creates a new file + * + * @param string $file The path for the new file + * @param mixed $content Either a string, an object or an array. Arrays and objects will be serialized. + * @param bool $append true: append the content to an existing file if available. false: overwrite. + * @return bool + */ + public static function write(string $file, $content, bool $append = false): bool + { + if (is_array($content) === true || is_object($content) === true) { + $content = serialize($content); + } + + $mode = $append === true ? FILE_APPEND | LOCK_EX : LOCK_EX; + + // if the parent directory does not exist, create it + if (is_dir(dirname($file)) === false) { + if (Dir::make(dirname($file)) === false) { + return false; + } + } + + if (static::isWritable($file) === false) { + throw new Exception('The file "' . $file . '" is not writable'); + } + + return file_put_contents($file, $content, $mode) !== false; + } } diff --git a/kirby/src/Filesystem/File.php b/kirby/src/Filesystem/File.php index d89b1b2..89cffbb 100755 --- a/kirby/src/Filesystem/File.php +++ b/kirby/src/Filesystem/File.php @@ -25,610 +25,610 @@ use Kirby\Toolkit\V; */ class File { - use Properties; + use Properties; - /** - * Absolute file path - * - * @var string - */ - protected $root; + /** + * Absolute file path + * + * @var string + */ + protected $root; - /** - * Absolute file URL - * - * @var string|null - */ - protected $url; + /** + * Absolute file URL + * + * @var string|null + */ + protected $url; - /** - * Validation rules to be used for `::match()` - * - * @var array - */ - public static $validations = [ - 'maxsize' => ['size', 'max'], - 'minsize' => ['size', 'min'] - ]; + /** + * Validation rules to be used for `::match()` + * + * @var array + */ + public static $validations = [ + 'maxsize' => ['size', 'max'], + 'minsize' => ['size', 'min'] + ]; - /** - * Constructor sets all file properties - * - * @param array|string|null $props Properties or deprecated `$root` string - * @param string|null $url Deprecated argument, use `$props['url']` instead - */ - public function __construct($props = null, string $url = null) - { - // Legacy support for old constructor of - // the `Kirby\Image\Image` class - // @todo 4.0.0 remove - if (is_array($props) === false) { - $props = [ - 'root' => $props, - 'url' => $url - ]; - } + /** + * Constructor sets all file properties + * + * @param array|string|null $props Properties or deprecated `$root` string + * @param string|null $url Deprecated argument, use `$props['url']` instead + */ + public function __construct($props = null, string $url = null) + { + // Legacy support for old constructor of + // the `Kirby\Image\Image` class + // @todo 4.0.0 remove + if (is_array($props) === false) { + $props = [ + 'root' => $props, + 'url' => $url + ]; + } - $this->setProperties($props); - } + $this->setProperties($props); + } - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return $this->toArray(); - } + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return $this->toArray(); + } - /** - * Returns the URL for the file object - * - * @return string - */ - public function __toString(): string - { - return $this->url() ?? $this->root() ?? ''; - } + /** + * Returns the URL for the file object + * + * @return string + */ + public function __toString(): string + { + return $this->url() ?? $this->root() ?? ''; + } - /** - * Returns the file content as base64 encoded string - * - * @return string - */ - public function base64(): string - { - return base64_encode($this->read()); - } + /** + * Returns the file content as base64 encoded string + * + * @return string + */ + public function base64(): string + { + return base64_encode($this->read()); + } - /** - * Copy a file to a new location. - * - * @param string $target - * @param bool $force - * @return static - */ - public function copy(string $target, bool $force = false) - { - if (F::copy($this->root, $target, $force) !== true) { - throw new Exception('The file "' . $this->root . '" could not be copied'); - } + /** + * Copy a file to a new location. + * + * @param string $target + * @param bool $force + * @return static + */ + public function copy(string $target, bool $force = false) + { + if (F::copy($this->root, $target, $force) !== true) { + throw new Exception('The file "' . $this->root . '" could not be copied'); + } - return new static($target); - } + return new static($target); + } - /** - * Returns the file as data uri - * - * @param bool $base64 Whether the data should be base64 encoded or not - * @return string - */ - public function dataUri(bool $base64 = true): string - { - if ($base64 === true) { - return 'data:' . $this->mime() . ';base64,' . $this->base64(); - } + /** + * Returns the file as data uri + * + * @param bool $base64 Whether the data should be base64 encoded or not + * @return string + */ + public function dataUri(bool $base64 = true): string + { + if ($base64 === true) { + return 'data:' . $this->mime() . ';base64,' . $this->base64(); + } - return 'data:' . $this->mime() . ',' . Escape::url($this->read()); - } + return 'data:' . $this->mime() . ',' . Escape::url($this->read()); + } - /** - * Deletes the file - * - * @return bool - */ - public function delete(): bool - { - if (F::remove($this->root) !== true) { - throw new Exception('The file "' . $this->root . '" could not be deleted'); - } + /** + * Deletes the file + * + * @return bool + */ + public function delete(): bool + { + if (F::remove($this->root) !== true) { + throw new Exception('The file "' . $this->root . '" could not be deleted'); + } - return true; - } + return true; + } - /* - * Automatically sends all needed headers for the file to be downloaded - * and echos the file's content - * - * @param string|null $filename Optional filename for the download - * @return string - */ - public function download($filename = null): string - { - return Response::download($this->root, $filename ?? $this->filename()); - } + /* + * Automatically sends all needed headers for the file to be downloaded + * and echos the file's content + * + * @param string|null $filename Optional filename for the download + * @return string + */ + public function download($filename = null): string + { + return Response::download($this->root, $filename ?? $this->filename()); + } - /** - * Checks if the file actually exists - * - * @return bool - */ - public function exists(): bool - { - return file_exists($this->root) === true; - } + /** + * Checks if the file actually exists + * + * @return bool + */ + public function exists(): bool + { + return file_exists($this->root) === true; + } - /** - * Returns the current lowercase extension (without .) - * - * @return string - */ - public function extension(): string - { - return F::extension($this->root); - } + /** + * Returns the current lowercase extension (without .) + * + * @return string + */ + public function extension(): string + { + return F::extension($this->root); + } - /** - * Returns the filename - * - * @return string - */ - public function filename(): string - { - return basename($this->root); - } + /** + * Returns the filename + * + * @return string + */ + public function filename(): string + { + return basename($this->root); + } - /** - * Returns a md5 hash of the root - * - * @return string - */ - public function hash(): string - { - return md5($this->root); - } + /** + * Returns a md5 hash of the root + * + * @return string + */ + public function hash(): string + { + return md5($this->root); + } - /** - * Sends an appropriate header for the asset - * - * @param bool $send - * @return \Kirby\Http\Response|void - */ - public function header(bool $send = true) - { - $response = new Response('', $this->mime()); + /** + * Sends an appropriate header for the asset + * + * @param bool $send + * @return \Kirby\Http\Response|void + */ + public function header(bool $send = true) + { + $response = new Response('', $this->mime()); - if ($send !== true) { - return $response; - } + if ($send !== true) { + return $response; + } - $response->send(); - } + $response->send(); + } - /** - * Converts the file to html - * - * @param array $attr - * @return string - */ - public function html(array $attr = []): string - { - return Html::a($this->url() ?? '', $attr); - } + /** + * Converts the file to html + * + * @param array $attr + * @return string + */ + public function html(array $attr = []): string + { + return Html::a($this->url() ?? '', $attr); + } - /** - * Checks if a file is of a certain type - * - * @param string $value An extension or mime type - * @return bool - */ - public function is(string $value): bool - { - return F::is($this->root, $value); - } + /** + * Checks if a file is of a certain type + * + * @param string $value An extension or mime type + * @return bool + */ + public function is(string $value): bool + { + return F::is($this->root, $value); + } - /** - * Checks if the file is readable - * - * @return bool - */ - public function isReadable(): bool - { - return is_readable($this->root) === true; - } + /** + * Checks if the file is readable + * + * @return bool + */ + public function isReadable(): bool + { + return is_readable($this->root) === true; + } - /** - * Checks if the file is a resizable image - * - * @return bool - */ - public function isResizable(): bool - { - return false; - } + /** + * Checks if the file is a resizable image + * + * @return bool + */ + public function isResizable(): bool + { + return false; + } - /** - * Checks if a preview can be displayed for the file - * in the panel or in the frontend - * - * @return bool - */ - public function isViewable(): bool - { - return false; - } + /** + * Checks if a preview can be displayed for the file + * in the panel or in the frontend + * + * @return bool + */ + public function isViewable(): bool + { + return false; + } - /** - * Checks if the file is writable - * - * @return bool - */ - public function isWritable(): bool - { - return F::isWritable($this->root); - } + /** + * Checks if the file is writable + * + * @return bool + */ + public function isWritable(): bool + { + return F::isWritable($this->root); + } - /** - * Returns the app instance if it exists - * - * @return \Kirby\Cms\App|null - */ - public function kirby() - { - return App::instance(null, true); - } + /** + * Returns the app instance if it exists + * + * @return \Kirby\Cms\App|null + */ + public function kirby() + { + return App::instance(null, true); + } - /** - * Runs a set of validations on the file object - * (mainly for images). - * - * @param array $rules - * @return bool - * @throws \Kirby\Exception\Exception - */ - public function match(array $rules): bool - { - $rules = array_change_key_case($rules); + /** + * Runs a set of validations on the file object + * (mainly for images). + * + * @param array $rules + * @return bool + * @throws \Kirby\Exception\Exception + */ + public function match(array $rules): bool + { + $rules = array_change_key_case($rules); - if (is_array($rules['mime'] ?? null) === true) { - $mime = $this->mime(); + if (is_array($rules['mime'] ?? null) === true) { + $mime = $this->mime(); - // determine if any pattern matches the MIME type; - // once any pattern matches, `$carry` is `true` and the rest is skipped - $matches = array_reduce( - $rules['mime'], - fn ($carry, $pattern) => $carry || Mime::matches($mime, $pattern), - false - ); + // determine if any pattern matches the MIME type; + // once any pattern matches, `$carry` is `true` and the rest is skipped + $matches = array_reduce( + $rules['mime'], + fn ($carry, $pattern) => $carry || Mime::matches($mime, $pattern), + false + ); - if ($matches !== true) { - throw new Exception([ - 'key' => 'file.mime.invalid', - 'data' => compact('mime') - ]); - } - } + if ($matches !== true) { + throw new Exception([ + 'key' => 'file.mime.invalid', + 'data' => compact('mime') + ]); + } + } - if (is_array($rules['extension'] ?? null) === true) { - $extension = $this->extension(); - if (in_array($extension, $rules['extension']) !== true) { - throw new Exception([ - 'key' => 'file.extension.invalid', - 'data' => compact('extension') - ]); - } - } + if (is_array($rules['extension'] ?? null) === true) { + $extension = $this->extension(); + if (in_array($extension, $rules['extension']) !== true) { + throw new Exception([ + 'key' => 'file.extension.invalid', + 'data' => compact('extension') + ]); + } + } - if (is_array($rules['type'] ?? null) === true) { - $type = $this->type(); - if (in_array($type, $rules['type']) !== true) { - throw new Exception([ - 'key' => 'file.type.invalid', - 'data' => compact('type') - ]); - } - } + if (is_array($rules['type'] ?? null) === true) { + $type = $this->type(); + if (in_array($type, $rules['type']) !== true) { + throw new Exception([ + 'key' => 'file.type.invalid', + 'data' => compact('type') + ]); + } + } - foreach (static::$validations as $key => $arguments) { - $rule = $rules[$key] ?? null; + foreach (static::$validations as $key => $arguments) { + $rule = $rules[$key] ?? null; - if ($rule !== null) { - $property = $arguments[0]; - $validator = $arguments[1]; + if ($rule !== null) { + $property = $arguments[0]; + $validator = $arguments[1]; - if (V::$validator($this->$property(), $rule) === false) { - throw new Exception([ - 'key' => 'file.' . $key, - 'data' => [$property => $rule] - ]); - } - } - } + if (V::$validator($this->$property(), $rule) === false) { + throw new Exception([ + 'key' => 'file.' . $key, + 'data' => [$property => $rule] + ]); + } + } + } - return true; - } + return true; + } - /** - * Detects the mime type of the file - * - * @return string|null - */ - public function mime() - { - return Mime::type($this->root); - } + /** + * Detects the mime type of the file + * + * @return string|null + */ + public function mime() + { + return Mime::type($this->root); + } - /** - * Returns the file's last modification time - * - * @param string|\IntlDateFormatter|null $format - * @param string|null $handler date, intl or strftime - * @return mixed - */ - public function modified($format = null, ?string $handler = null) - { - $kirby = $this->kirby(); + /** + * Returns the file's last modification time + * + * @param string|\IntlDateFormatter|null $format + * @param string|null $handler date, intl or strftime + * @return mixed + */ + public function modified($format = null, ?string $handler = null) + { + $kirby = $this->kirby(); - return F::modified( - $this->root, - $format, - $handler ?? ($kirby ? $kirby->option('date.handler', 'date') : 'date') - ); - } + return F::modified( + $this->root, + $format, + $handler ?? ($kirby ? $kirby->option('date.handler', 'date') : 'date') + ); + } - /** - * Move the file to a new location - * - * @param string $newRoot - * @param bool $overwrite Force overwriting any existing files - * @return static - */ - public function move(string $newRoot, bool $overwrite = false) - { - if (F::move($this->root, $newRoot, $overwrite) !== true) { - throw new Exception('The file: "' . $this->root . '" could not be moved to: "' . $newRoot . '"'); - } + /** + * Move the file to a new location + * + * @param string $newRoot + * @param bool $overwrite Force overwriting any existing files + * @return static + */ + public function move(string $newRoot, bool $overwrite = false) + { + if (F::move($this->root, $newRoot, $overwrite) !== true) { + throw new Exception('The file: "' . $this->root . '" could not be moved to: "' . $newRoot . '"'); + } - return new static($newRoot); - } + return new static($newRoot); + } - /** - * Getter for the name of the file - * without the extension - * - * @return string - */ - public function name(): string - { - return pathinfo($this->root, PATHINFO_FILENAME); - } + /** + * Getter for the name of the file + * without the extension + * + * @return string + */ + public function name(): string + { + return pathinfo($this->root, PATHINFO_FILENAME); + } - /** - * Returns the file size in a - * human-readable format - * - * @param string|null|false $locale Locale for number formatting, - * `null` for the current locale, - * `false` to disable number formatting - * @return string - */ - public function niceSize($locale = null): string - { - return F::niceSize($this->root, $locale); - } + /** + * Returns the file size in a + * human-readable format + * + * @param string|null|false $locale Locale for number formatting, + * `null` for the current locale, + * `false` to disable number formatting + * @return string + */ + public function niceSize($locale = null): string + { + return F::niceSize($this->root, $locale); + } - /** - * Reads the file content and returns it. - * - * @return string|false - */ - public function read() - { - return F::read($this->root); - } + /** + * Reads the file content and returns it. + * + * @return string|false + */ + public function read() + { + return F::read($this->root); + } - /** - * Returns the absolute path to the file - * - * @return string - */ - public function realpath(): string - { - return realpath($this->root); - } + /** + * Returns the absolute path to the file + * + * @return string + */ + public function realpath(): string + { + return realpath($this->root); + } - /** - * Changes the name of the file without - * touching the extension - * - * @param string $newName - * @param bool $overwrite Force overwrite existing files - * @return static - */ - public function rename(string $newName, bool $overwrite = false) - { - $newRoot = F::rename($this->root, $newName, $overwrite); + /** + * Changes the name of the file without + * touching the extension + * + * @param string $newName + * @param bool $overwrite Force overwrite existing files + * @return static + */ + public function rename(string $newName, bool $overwrite = false) + { + $newRoot = F::rename($this->root, $newName, $overwrite); - if ($newRoot === false) { - throw new Exception('The file: "' . $this->root . '" could not be renamed to: "' . $newName . '"'); - } + if ($newRoot === false) { + throw new Exception('The file: "' . $this->root . '" could not be renamed to: "' . $newName . '"'); + } - return new static($newRoot); - } + return new static($newRoot); + } - /** - * Returns the given file path - * - * @return string|null - */ - public function root(): ?string - { - return $this->root; - } + /** + * Returns the given file path + * + * @return string|null + */ + public function root(): ?string + { + return $this->root; + } - /** - * Setter for the root - * - * @param string|null $root - * @return $this - */ - protected function setRoot(?string $root = null) - { - $this->root = $root; - return $this; - } + /** + * Setter for the root + * + * @param string|null $root + * @return $this + */ + protected function setRoot(?string $root = null) + { + $this->root = $root; + return $this; + } - /** - * Setter for the file url - * - * @param string|null $url - * @return $this - */ - protected function setUrl(?string $url = null) - { - $this->url = $url; - return $this; - } + /** + * Setter for the file url + * + * @param string|null $url + * @return $this + */ + protected function setUrl(?string $url = null) + { + $this->url = $url; + return $this; + } - /** - * Returns the absolute url for the file - * - * @return string|null - */ - public function url(): ?string - { - return $this->url; - } + /** + * Returns the absolute url for the file + * + * @return string|null + */ + public function url(): ?string + { + return $this->url; + } - /** - * Sanitizes the file contents depending on the file type - * by overwriting the file with the sanitized version - * @since 3.6.0 - * - * @param string|bool $typeLazy Explicit sane handler type string, - * `true` for lazy autodetection or - * `false` for normal autodetection - * @return void - * - * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation - * @throws \Kirby\Exception\LogicException If more than one handler applies - * @throws \Kirby\Exception\NotFoundException If the handler was not found - * @throws \Kirby\Exception\Exception On other errors - */ - public function sanitizeContents($typeLazy = false): void - { - Sane::sanitizeFile($this->root(), $typeLazy); - } + /** + * Sanitizes the file contents depending on the file type + * by overwriting the file with the sanitized version + * @since 3.6.0 + * + * @param string|bool $typeLazy Explicit sane handler type string, + * `true` for lazy autodetection or + * `false` for normal autodetection + * @return void + * + * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation + * @throws \Kirby\Exception\LogicException If more than one handler applies + * @throws \Kirby\Exception\NotFoundException If the handler was not found + * @throws \Kirby\Exception\Exception On other errors + */ + public function sanitizeContents($typeLazy = false): void + { + Sane::sanitizeFile($this->root(), $typeLazy); + } - /** - * Returns the sha1 hash of the file - * @since 3.6.0 - * - * @return string - */ - public function sha1(): string - { - return sha1_file($this->root); - } + /** + * Returns the sha1 hash of the file + * @since 3.6.0 + * + * @return string + */ + public function sha1(): string + { + return sha1_file($this->root); + } - /** - * Returns the raw size of the file - * - * @return int - */ - public function size(): int - { - return F::size($this->root); - } + /** + * Returns the raw size of the file + * + * @return int + */ + public function size(): int + { + return F::size($this->root); + } - /** - * Converts the media object to a - * plain PHP array - * - * @return array - */ - public function toArray(): array - { - return [ - 'extension' => $this->extension(), - 'filename' => $this->filename(), - 'hash' => $this->hash(), - 'isReadable' => $this->isReadable(), - 'isResizable' => $this->isResizable(), - 'isWritable' => $this->isWritable(), - 'mime' => $this->mime(), - 'modified' => $this->modified('c'), - 'name' => $this->name(), - 'niceSize' => $this->niceSize(), - 'root' => $this->root(), - 'safeName' => F::safeName($this->name()), - 'size' => $this->size(), - 'type' => $this->type(), - 'url' => $this->url() - ]; - } + /** + * Converts the media object to a + * plain PHP array + * + * @return array + */ + public function toArray(): array + { + return [ + 'extension' => $this->extension(), + 'filename' => $this->filename(), + 'hash' => $this->hash(), + 'isReadable' => $this->isReadable(), + 'isResizable' => $this->isResizable(), + 'isWritable' => $this->isWritable(), + 'mime' => $this->mime(), + 'modified' => $this->modified('c'), + 'name' => $this->name(), + 'niceSize' => $this->niceSize(), + 'root' => $this->root(), + 'safeName' => F::safeName($this->name()), + 'size' => $this->size(), + 'type' => $this->type(), + 'url' => $this->url() + ]; + } - /** - * Converts the entire file array into - * a json string - * - * @return string - */ - public function toJson(): string - { - return json_encode($this->toArray()); - } + /** + * Converts the entire file array into + * a json string + * + * @return string + */ + public function toJson(): string + { + return json_encode($this->toArray()); + } - /** - * Returns the file type. - * - * @return string|null - */ - public function type(): ?string - { - return F::type($this->root); - } + /** + * Returns the file type. + * + * @return string|null + */ + public function type(): ?string + { + return F::type($this->root); + } - /** - * Validates the file contents depending on the file type - * - * @param string|bool $typeLazy Explicit sane handler type string, - * `true` for lazy autodetection or - * `false` for normal autodetection - * @return void - * - * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation - * @throws \Kirby\Exception\NotFoundException If the handler was not found - * @throws \Kirby\Exception\Exception On other errors - */ - public function validateContents($typeLazy = false): void - { - Sane::validateFile($this->root(), $typeLazy); - } + /** + * Validates the file contents depending on the file type + * + * @param string|bool $typeLazy Explicit sane handler type string, + * `true` for lazy autodetection or + * `false` for normal autodetection + * @return void + * + * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation + * @throws \Kirby\Exception\NotFoundException If the handler was not found + * @throws \Kirby\Exception\Exception On other errors + */ + public function validateContents($typeLazy = false): void + { + Sane::validateFile($this->root(), $typeLazy); + } - /** - * Writes content to the file - * - * @param string $content - * @return bool - */ - public function write($content): bool - { - if (F::write($this->root, $content) !== true) { - throw new Exception('The file "' . $this->root . '" could not be written'); - } + /** + * Writes content to the file + * + * @param string $content + * @return bool + */ + public function write($content): bool + { + if (F::write($this->root, $content) !== true) { + throw new Exception('The file "' . $this->root . '" could not be written'); + } - return true; - } + return true; + } } diff --git a/kirby/src/Filesystem/Filename.php b/kirby/src/Filesystem/Filename.php index 01c1647..f97de71 100755 --- a/kirby/src/Filesystem/Filename.php +++ b/kirby/src/Filesystem/Filename.php @@ -28,280 +28,280 @@ use Kirby\Toolkit\Str; */ class Filename { - /** - * List of all applicable attributes - * - * @var array - */ - protected $attributes; + /** + * List of all applicable attributes + * + * @var array + */ + protected $attributes; - /** - * The sanitized file extension - * - * @var string - */ - protected $extension; + /** + * The sanitized file extension + * + * @var string + */ + protected $extension; - /** - * The source original filename - * - * @var string - */ - protected $filename; + /** + * The source original filename + * + * @var string + */ + protected $filename; - /** - * The sanitized file name - * - * @var string - */ - protected $name; + /** + * The sanitized file name + * + * @var string + */ + protected $name; - /** - * The template for the final name - * - * @var string - */ - protected $template; + /** + * The template for the final name + * + * @var string + */ + protected $template; - /** - * Creates a new Filename object - * - * @param string $filename - * @param string $template - * @param array $attributes - */ - public function __construct(string $filename, string $template, array $attributes = []) - { - $this->filename = $filename; - $this->template = $template; - $this->attributes = $attributes; - $this->extension = $this->sanitizeExtension( - $attributes['format'] ?? - pathinfo($filename, PATHINFO_EXTENSION) - ); - $this->name = $this->sanitizeName(pathinfo($filename, PATHINFO_FILENAME)); - } + /** + * Creates a new Filename object + * + * @param string $filename + * @param string $template + * @param array $attributes + */ + public function __construct(string $filename, string $template, array $attributes = []) + { + $this->filename = $filename; + $this->template = $template; + $this->attributes = $attributes; + $this->extension = $this->sanitizeExtension( + $attributes['format'] ?? + pathinfo($filename, PATHINFO_EXTENSION) + ); + $this->name = $this->sanitizeName(pathinfo($filename, PATHINFO_FILENAME)); + } - /** - * Converts the entire object to a string - * - * @return string - */ - public function __toString(): string - { - return $this->toString(); - } + /** + * Converts the entire object to a string + * + * @return string + */ + public function __toString(): string + { + return $this->toString(); + } - /** - * Converts all processed attributes - * to an array. The array keys are already - * the shortened versions for the filename - * - * @return array - */ - public function attributesToArray(): array - { - $array = [ - 'dimensions' => implode('x', $this->dimensions()), - 'crop' => $this->crop(), - 'blur' => $this->blur(), - 'bw' => $this->grayscale(), - 'q' => $this->quality(), - ]; + /** + * Converts all processed attributes + * to an array. The array keys are already + * the shortened versions for the filename + * + * @return array + */ + public function attributesToArray(): array + { + $array = [ + 'dimensions' => implode('x', $this->dimensions()), + 'crop' => $this->crop(), + 'blur' => $this->blur(), + 'bw' => $this->grayscale(), + 'q' => $this->quality(), + ]; - $array = array_filter( - $array, - fn ($item) => $item !== null && $item !== false && $item !== '' - ); + $array = array_filter( + $array, + fn ($item) => $item !== null && $item !== false && $item !== '' + ); - return $array; - } + return $array; + } - /** - * Converts all processed attributes - * to a string, that can be used in the - * new filename - * - * @param string|null $prefix The prefix will be used in the filename creation - * @return string - */ - public function attributesToString(string $prefix = null): string - { - $array = $this->attributesToArray(); - $result = []; + /** + * Converts all processed attributes + * to a string, that can be used in the + * new filename + * + * @param string|null $prefix The prefix will be used in the filename creation + * @return string + */ + public function attributesToString(string $prefix = null): string + { + $array = $this->attributesToArray(); + $result = []; - foreach ($array as $key => $value) { - if ($value === true) { - $value = ''; - } + foreach ($array as $key => $value) { + if ($value === true) { + $value = ''; + } - switch ($key) { - case 'dimensions': - $result[] = $value; - break; - case 'crop': - $result[] = ($value === 'center') ? 'crop' : $key . '-' . $value; - break; - default: - $result[] = $key . $value; - } - } + switch ($key) { + case 'dimensions': + $result[] = $value; + break; + case 'crop': + $result[] = ($value === 'center') ? 'crop' : $key . '-' . $value; + break; + default: + $result[] = $key . $value; + } + } - $result = array_filter($result); - $attributes = implode('-', $result); + $result = array_filter($result); + $attributes = implode('-', $result); - if (empty($attributes) === true) { - return ''; - } + if (empty($attributes) === true) { + return ''; + } - return $prefix . $attributes; - } + return $prefix . $attributes; + } - /** - * Normalizes the blur option value - * - * @return false|int - */ - public function blur() - { - $value = $this->attributes['blur'] ?? false; + /** + * Normalizes the blur option value + * + * @return false|int + */ + public function blur() + { + $value = $this->attributes['blur'] ?? false; - if ($value === false) { - return false; - } + if ($value === false) { + return false; + } - return (int)$value; - } + return (int)$value; + } - /** - * Normalizes the crop option value - * - * @return false|string - */ - public function crop() - { - // get the crop value - $crop = $this->attributes['crop'] ?? false; + /** + * Normalizes the crop option value + * + * @return false|string + */ + public function crop() + { + // get the crop value + $crop = $this->attributes['crop'] ?? false; - if ($crop === false) { - return false; - } + if ($crop === false) { + return false; + } - return Str::slug($crop); - } + return Str::slug($crop); + } - /** - * Returns a normalized array - * with width and height values - * if available - * - * @return array - */ - public function dimensions() - { - if (empty($this->attributes['width']) === true && empty($this->attributes['height']) === true) { - return []; - } + /** + * Returns a normalized array + * with width and height values + * if available + * + * @return array + */ + public function dimensions() + { + if (empty($this->attributes['width']) === true && empty($this->attributes['height']) === true) { + return []; + } - return [ - 'width' => $this->attributes['width'] ?? null, - 'height' => $this->attributes['height'] ?? null - ]; - } + return [ + 'width' => $this->attributes['width'] ?? null, + 'height' => $this->attributes['height'] ?? null + ]; + } - /** - * Returns the sanitized extension - * - * @return string - */ - public function extension(): string - { - return $this->extension; - } + /** + * Returns the sanitized extension + * + * @return string + */ + public function extension(): string + { + return $this->extension; + } - /** - * Normalizes the grayscale option value - * and also the available ways to write - * the option. You can use `grayscale`, - * `greyscale` or simply `bw`. The function - * will always return `grayscale` - * - * @return bool - */ - public function grayscale(): bool - { - // normalize options - $value = $this->attributes['grayscale'] ?? $this->attributes['greyscale'] ?? $this->attributes['bw'] ?? false; + /** + * Normalizes the grayscale option value + * and also the available ways to write + * the option. You can use `grayscale`, + * `greyscale` or simply `bw`. The function + * will always return `grayscale` + * + * @return bool + */ + public function grayscale(): bool + { + // normalize options + $value = $this->attributes['grayscale'] ?? $this->attributes['greyscale'] ?? $this->attributes['bw'] ?? false; - // turn anything into boolean - return filter_var($value, FILTER_VALIDATE_BOOLEAN); - } + // turn anything into boolean + return filter_var($value, FILTER_VALIDATE_BOOLEAN); + } - /** - * Returns the filename without extension - * - * @return string - */ - public function name(): string - { - return $this->name; - } + /** + * Returns the filename without extension + * + * @return string + */ + public function name(): string + { + return $this->name; + } - /** - * Normalizes the quality option value - * - * @return false|int - */ - public function quality() - { - $value = $this->attributes['quality'] ?? false; + /** + * Normalizes the quality option value + * + * @return false|int + */ + public function quality() + { + $value = $this->attributes['quality'] ?? false; - if ($value === false || $value === true) { - return false; - } + if ($value === false || $value === true) { + return false; + } - return (int)$value; - } + return (int)$value; + } - /** - * Sanitizes the file extension. - * The extension will be converted - * to lowercase and `jpeg` will be - * replaced with `jpg` - * - * @param string $extension - * @return string - */ - protected function sanitizeExtension(string $extension): string - { - $extension = strtolower($extension); - $extension = str_replace('jpeg', 'jpg', $extension); - return $extension; - } + /** + * Sanitizes the file extension. + * The extension will be converted + * to lowercase and `jpeg` will be + * replaced with `jpg` + * + * @param string $extension + * @return string + */ + protected function sanitizeExtension(string $extension): string + { + $extension = strtolower($extension); + $extension = str_replace('jpeg', 'jpg', $extension); + return $extension; + } - /** - * Sanitizes the name with Kirby's - * Str::slug function - * - * @param string $name - * @return string - */ - protected function sanitizeName(string $name): string - { - return Str::slug($name); - } + /** + * Sanitizes the name with Kirby's + * Str::slug function + * + * @param string $name + * @return string + */ + protected function sanitizeName(string $name): string + { + return Str::slug($name); + } - /** - * Returns the converted filename as string - * - * @return string - */ - public function toString(): string - { - return Str::template($this->template, [ - 'name' => $this->name(), - 'attributes' => $this->attributesToString('-'), - 'extension' => $this->extension() - ], ['fallback' => '']); - } + /** + * Returns the converted filename as string + * + * @return string + */ + public function toString(): string + { + return Str::template($this->template, [ + 'name' => $this->name(), + 'attributes' => $this->attributesToString('-'), + 'extension' => $this->extension() + ], ['fallback' => '']); + } } diff --git a/kirby/src/Filesystem/IsFile.php b/kirby/src/Filesystem/IsFile.php index 8162f3c..7e69799 100755 --- a/kirby/src/Filesystem/IsFile.php +++ b/kirby/src/Filesystem/IsFile.php @@ -22,175 +22,175 @@ use Kirby\Toolkit\Properties; */ trait IsFile { - use Properties; + use Properties; - /** - * File asset object - * - * @var \Kirby\Filesystem\File - */ - protected $asset; + /** + * File asset object + * + * @var \Kirby\Filesystem\File + */ + protected $asset; - /** - * Absolute file path - * - * @var string|null - */ - protected $root; + /** + * Absolute file path + * + * @var string|null + */ + protected $root; - /** - * Absolute file URL - * - * @var string|null - */ - protected $url; + /** + * Absolute file URL + * + * @var string|null + */ + protected $url; - /** - * Constructor sets all file properties - * - * @param array $props - */ - public function __construct(array $props) - { - $this->setProperties($props); - } + /** + * Constructor sets all file properties + * + * @param array $props + */ + public function __construct(array $props) + { + $this->setProperties($props); + } - /** - * Magic caller for asset methods - * - * @param string $method - * @param array $arguments - * @return mixed - * @throws \Kirby\Exception\BadMethodCallException - */ - public function __call(string $method, array $arguments = []) - { - // public property access - if (isset($this->$method) === true) { - return $this->$method; - } + /** + * Magic caller for asset methods + * + * @param string $method + * @param array $arguments + * @return mixed + * @throws \Kirby\Exception\BadMethodCallException + */ + public function __call(string $method, array $arguments = []) + { + // public property access + if (isset($this->$method) === true) { + return $this->$method; + } - // asset method proxy - if (method_exists($this->asset(), $method)) { - return $this->asset()->$method(...$arguments); - } + // asset method proxy + if (method_exists($this->asset(), $method)) { + return $this->asset()->$method(...$arguments); + } - throw new BadMethodCallException('The method: "' . $method . '" does not exist'); - } + throw new BadMethodCallException('The method: "' . $method . '" does not exist'); + } - /** - * Converts the asset to a string - * - * @return string - */ - public function __toString(): string - { - return (string)$this->asset(); - } + /** + * Converts the asset to a string + * + * @return string + */ + public function __toString(): string + { + return (string)$this->asset(); + } - /** - * Returns the file asset object - * - * @param array|string|null $props - * @return \Kirby\Filesystem\File - */ - public function asset($props = null) - { - if ($this->asset !== null) { - return $this->asset; - } + /** + * Returns the file asset object + * + * @param array|string|null $props + * @return \Kirby\Filesystem\File + */ + public function asset($props = null) + { + if ($this->asset !== null) { + return $this->asset; + } - $props = $props ?? [ - 'root' => $this->root(), - 'url' => $this->url() - ]; + $props = $props ?? [ + 'root' => $this->root(), + 'url' => $this->url() + ]; - switch ($this->type()) { - case 'image': - return $this->asset = new Image($props); - default: - return $this->asset = new File($props); - } - } + switch ($this->type()) { + case 'image': + return $this->asset = new Image($props); + default: + return $this->asset = new File($props); + } + } - /** - * Checks if the file exists on disk - * - * @return bool - */ - public function exists(): bool - { - // Important to include this in the trait - // to avoid infinite loops when trying - // to proxy the method from the asset object - return file_exists($this->root()) === true; - } + /** + * Checks if the file exists on disk + * + * @return bool + */ + public function exists(): bool + { + // Important to include this in the trait + // to avoid infinite loops when trying + // to proxy the method from the asset object + return file_exists($this->root()) === true; + } - /** - * Returns the app instance - * - * @return \Kirby\Cms\App - */ - public function kirby() - { - return App::instance(); - } + /** + * Returns the app instance + * + * @return \Kirby\Cms\App + */ + public function kirby() + { + return App::instance(); + } - /** - * Returns the given file path - * - * @return string|null - */ - public function root(): ?string - { - return $this->root; - } + /** + * Returns the given file path + * + * @return string|null + */ + public function root(): ?string + { + return $this->root; + } - /** - * Setter for the root - * - * @param string|null $root - * @return $this - */ - protected function setRoot(?string $root = null) - { - $this->root = $root; - return $this; - } + /** + * Setter for the root + * + * @param string|null $root + * @return $this + */ + protected function setRoot(?string $root = null) + { + $this->root = $root; + return $this; + } - /** - * Setter for the file url - * - * @param string|null $url - * @return $this - */ - protected function setUrl(?string $url = null) - { - $this->url = $url; - return $this; - } + /** + * Setter for the file url + * + * @param string|null $url + * @return $this + */ + protected function setUrl(?string $url = null) + { + $this->url = $url; + return $this; + } - /** - * Returns the file type - * - * @return string|null - */ - public function type(): ?string - { - // Important to include this in the trait - // to avoid infinite loops when trying - // to proxy the method from the asset object - return F::type($this->root() ?? $this->url()); - } + /** + * Returns the file type + * + * @return string|null + */ + public function type(): ?string + { + // Important to include this in the trait + // to avoid infinite loops when trying + // to proxy the method from the asset object + return F::type($this->root() ?? $this->url()); + } - /** - * Returns the absolute url for the file - * - * @return string|null - */ - public function url(): ?string - { - return $this->url; - } + /** + * Returns the absolute url for the file + * + * @return string|null + */ + public function url(): ?string + { + return $this->url; + } } diff --git a/kirby/src/Filesystem/Mime.php b/kirby/src/Filesystem/Mime.php index ed153f9..eb5c4c9 100755 --- a/kirby/src/Filesystem/Mime.php +++ b/kirby/src/Filesystem/Mime.php @@ -19,325 +19,325 @@ use SimpleXMLElement; */ class Mime { - /** - * Extension to MIME type map - * - * @var array - */ - public static $types = [ - 'ai' => 'application/postscript', - 'aif' => 'audio/x-aiff', - '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'], - 'doc' => 'application/msword', - 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', - 'dvi' => 'application/x-dvi', - 'eml' => 'message/rfc822', - 'eps' => 'application/postscript', - 'exe' => ['application/octet-stream', 'application/x-msdownload'], - 'gif' => 'image/gif', - 'gtar' => 'application/x-gtar', - 'gz' => 'application/x-gzip', - 'htm' => 'text/html', - 'html' => 'text/html', - 'ico' => 'image/x-icon', - 'ics' => 'text/calendar', - 'js' => ['application/javascript', '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'], - 'log' => ['text/plain', 'text/x-log'], - 'm4a' => 'audio/mp4', - 'm4v' => 'video/mp4', - 'mid' => 'audio/midi', - 'midi' => 'audio/midi', - 'mif' => 'application/vnd.mif', - 'mov' => 'video/quicktime', - 'movie' => 'video/x-sgi-movie', - 'mp2' => 'audio/mpeg', - 'mp3' => ['audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'], - 'mp4' => 'video/mp4', - 'mpe' => 'video/mpeg', - 'mpeg' => 'video/mpeg', - 'mpg' => 'video/mpeg', - 'mpga' => 'audio/mpeg', - 'odc' => 'application/vnd.oasis.opendocument.chart', - 'odp' => 'application/vnd.oasis.opendocument.presentation', - 'odt' => 'application/vnd.oasis.opendocument.text', - 'pdf' => ['application/pdf', 'application/x-download'], - 'php' => ['text/php', 'text/x-php', 'application/x-httpd-php', 'application/php', 'application/x-php', 'application/x-httpd-php-source'], - 'php3' => ['text/php', 'text/x-php', 'application/x-httpd-php', 'application/php', 'application/x-php', 'application/x-httpd-php-source'], - 'phps' => ['text/php', 'text/x-php', 'application/x-httpd-php', 'application/php', 'application/x-php', 'application/x-httpd-php-source'], - 'phtml' => ['text/php', 'text/x-php', 'application/x-httpd-php', 'application/php', 'application/x-php', 'application/x-httpd-php-source'], - 'png' => 'image/png', - 'ppt' => ['application/powerpoint', 'application/vnd.ms-powerpoint'], - 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', - 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', - 'ps' => 'application/postscript', - 'psd' => 'application/x-photoshop', - 'qt' => 'video/quicktime', - 'rss' => 'application/rss+xml', - 'rtf' => 'text/rtf', - 'rtx' => 'text/richtext', - 'shtml' => 'text/html', - 'svg' => 'image/svg+xml', - 'swf' => 'application/x-shockwave-flash', - 'tar' => 'application/x-tar', - 'text' => 'text/plain', - 'txt' => 'text/plain', - 'tgz' => ['application/x-tar', 'application/x-gzip-compressed'], - 'tif' => 'image/tiff', - 'tiff' => 'image/tiff', - 'wav' => 'audio/x-wav', - 'wbxml' => 'application/wbxml', - 'webm' => 'video/webm', - 'webp' => 'image/webp', - 'word' => ['application/msword', 'application/octet-stream'], - 'xhtml' => 'application/xhtml+xml', - 'xht' => 'application/xhtml+xml', - 'xml' => 'text/xml', - 'xl' => 'application/excel', - 'xls' => ['application/excel', 'application/vnd.ms-excel', 'application/msexcel'], - 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', - 'xsl' => 'text/xml', - 'yaml' => ['application/yaml', 'text/yaml'], - 'yml' => ['application/yaml', 'text/yaml'], - 'zip' => ['application/x-zip', 'application/zip', 'application/x-zip-compressed'], - ]; + /** + * Extension to MIME type map + * + * @var array + */ + public static $types = [ + 'ai' => 'application/postscript', + 'aif' => 'audio/x-aiff', + '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'], + 'doc' => 'application/msword', + 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', + 'dvi' => 'application/x-dvi', + 'eml' => 'message/rfc822', + 'eps' => 'application/postscript', + 'exe' => ['application/octet-stream', 'application/x-msdownload'], + 'gif' => 'image/gif', + 'gtar' => 'application/x-gtar', + 'gz' => 'application/x-gzip', + 'htm' => 'text/html', + 'html' => 'text/html', + 'ico' => 'image/x-icon', + 'ics' => 'text/calendar', + 'js' => ['application/javascript', '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'], + 'log' => ['text/plain', 'text/x-log'], + 'm4a' => 'audio/mp4', + 'm4v' => 'video/mp4', + 'mid' => 'audio/midi', + 'midi' => 'audio/midi', + 'mif' => 'application/vnd.mif', + 'mov' => 'video/quicktime', + 'movie' => 'video/x-sgi-movie', + 'mp2' => 'audio/mpeg', + 'mp3' => ['audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'], + 'mp4' => 'video/mp4', + 'mpe' => 'video/mpeg', + 'mpeg' => 'video/mpeg', + 'mpg' => 'video/mpeg', + 'mpga' => 'audio/mpeg', + 'odc' => 'application/vnd.oasis.opendocument.chart', + 'odp' => 'application/vnd.oasis.opendocument.presentation', + 'odt' => 'application/vnd.oasis.opendocument.text', + 'pdf' => ['application/pdf', 'application/x-download'], + 'php' => ['text/php', 'text/x-php', 'application/x-httpd-php', 'application/php', 'application/x-php', 'application/x-httpd-php-source'], + 'php3' => ['text/php', 'text/x-php', 'application/x-httpd-php', 'application/php', 'application/x-php', 'application/x-httpd-php-source'], + 'phps' => ['text/php', 'text/x-php', 'application/x-httpd-php', 'application/php', 'application/x-php', 'application/x-httpd-php-source'], + 'phtml' => ['text/php', 'text/x-php', 'application/x-httpd-php', 'application/php', 'application/x-php', 'application/x-httpd-php-source'], + 'png' => 'image/png', + 'ppt' => ['application/powerpoint', 'application/vnd.ms-powerpoint'], + 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', + 'ps' => 'application/postscript', + 'psd' => 'application/x-photoshop', + 'qt' => 'video/quicktime', + 'rss' => 'application/rss+xml', + 'rtf' => 'text/rtf', + 'rtx' => 'text/richtext', + 'shtml' => 'text/html', + 'svg' => 'image/svg+xml', + 'swf' => 'application/x-shockwave-flash', + 'tar' => 'application/x-tar', + 'text' => 'text/plain', + 'txt' => 'text/plain', + 'tgz' => ['application/x-tar', 'application/x-gzip-compressed'], + 'tif' => 'image/tiff', + 'tiff' => 'image/tiff', + 'wav' => 'audio/x-wav', + 'wbxml' => 'application/wbxml', + 'webm' => 'video/webm', + 'webp' => 'image/webp', + 'word' => ['application/msword', 'application/octet-stream'], + 'xhtml' => 'application/xhtml+xml', + 'xht' => 'application/xhtml+xml', + 'xml' => 'text/xml', + 'xl' => 'application/excel', + 'xls' => ['application/excel', 'application/vnd.ms-excel', 'application/msexcel'], + 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', + 'xsl' => 'text/xml', + 'yaml' => ['application/yaml', 'text/yaml'], + 'yml' => ['application/yaml', 'text/yaml'], + 'zip' => ['application/x-zip', 'application/zip', 'application/x-zip-compressed'], + ]; - /** - * Fixes an invalid MIME type guess for the given file - * - * @param string $file - * @param string $mime - * @param string $extension - * @return string|null - */ - public static function fix(string $file, string $mime = null, string $extension = null) - { - // fixing map - $map = [ - 'text/html' => [ - 'svg' => ['Kirby\Filesystem\Mime', 'fromSvg'], - ], - 'text/plain' => [ - 'css' => 'text/css', - 'json' => 'application/json', - 'svg' => ['Kirby\Filesystem\Mime', 'fromSvg'], - ], - 'text/x-asm' => [ - 'css' => 'text/css' - ], - 'image/svg' => [ - 'svg' => 'image/svg+xml' - ] - ]; + /** + * Fixes an invalid MIME type guess for the given file + * + * @param string $file + * @param string $mime + * @param string $extension + * @return string|null + */ + public static function fix(string $file, string $mime = null, string $extension = null) + { + // fixing map + $map = [ + 'text/html' => [ + 'svg' => ['Kirby\Filesystem\Mime', 'fromSvg'], + ], + 'text/plain' => [ + 'css' => 'text/css', + 'json' => 'application/json', + 'svg' => ['Kirby\Filesystem\Mime', 'fromSvg'], + ], + 'text/x-asm' => [ + 'css' => 'text/css' + ], + 'image/svg' => [ + 'svg' => 'image/svg+xml' + ] + ]; - if ($mode = ($map[$mime][$extension] ?? null)) { - if (is_callable($mode) === true) { - return $mode($file, $mime, $extension); - } + if ($mode = ($map[$mime][$extension] ?? null)) { + if (is_callable($mode) === true) { + return $mode($file, $mime, $extension); + } - if (is_string($mode) === true) { - return $mode; - } - } + if (is_string($mode) === true) { + return $mode; + } + } - return $mime; - } + return $mime; + } - /** - * Guesses a MIME type by extension - * - * @param string $extension - * @return string|null - */ - public static function fromExtension(string $extension): ?string - { - $mime = static::$types[$extension] ?? null; - return is_array($mime) === true ? array_shift($mime) : $mime; - } + /** + * Guesses a MIME type by extension + * + * @param string $extension + * @return string|null + */ + public static function fromExtension(string $extension): ?string + { + $mime = static::$types[$extension] ?? null; + return is_array($mime) === true ? array_shift($mime) : $mime; + } - /** - * Returns the MIME type of a file - * - * @param string $file - * @return string|false - */ - public static function fromFileInfo(string $file) - { - if (function_exists('finfo_file') === true && file_exists($file) === true) { - $finfo = finfo_open(FILEINFO_MIME_TYPE); - $mime = finfo_file($finfo, $file); - finfo_close($finfo); - return $mime; - } + /** + * Returns the MIME type of a file + * + * @param string $file + * @return string|false + */ + public static function fromFileInfo(string $file) + { + if (function_exists('finfo_file') === true && file_exists($file) === true) { + $finfo = finfo_open(FILEINFO_MIME_TYPE); + $mime = finfo_file($finfo, $file); + finfo_close($finfo); + return $mime; + } - return false; - } + return false; + } - /** - * Returns the MIME type of a file - * - * @param string $file - * @return string|false - */ - public static function fromMimeContentType(string $file) - { - if (function_exists('mime_content_type') === true && file_exists($file) === true) { - return mime_content_type($file); - } + /** + * Returns the MIME type of a file + * + * @param string $file + * @return string|false + */ + public static function fromMimeContentType(string $file) + { + if (function_exists('mime_content_type') === true && file_exists($file) === true) { + return mime_content_type($file); + } - return false; - } + return false; + } - /** - * Tries to detect a valid SVG and returns the MIME type accordingly - * - * @param string $file - * @return string|false - */ - public static function fromSvg(string $file) - { - if (file_exists($file) === true) { - libxml_use_internal_errors(true); + /** + * Tries to detect a valid SVG and returns the MIME type accordingly + * + * @param string $file + * @return string|false + */ + public static function fromSvg(string $file) + { + if (file_exists($file) === true) { + libxml_use_internal_errors(true); - $svg = new SimpleXMLElement(file_get_contents($file)); + $svg = new SimpleXMLElement(file_get_contents($file)); - if ($svg !== false && $svg->getName() === 'svg') { - return 'image/svg+xml'; - } - } + if ($svg !== false && $svg->getName() === 'svg') { + return 'image/svg+xml'; + } + } - return false; - } + return false; + } - /** - * Tests if a given MIME type is matched by an `Accept` header - * pattern; returns true if the MIME type is contained at all - * - * @param string $mime - * @param string $pattern - * @return bool - */ - public static function isAccepted(string $mime, string $pattern): bool - { - $accepted = Str::accepted($pattern); + /** + * Tests if a given MIME type is matched by an `Accept` header + * pattern; returns true if the MIME type is contained at all + * + * @param string $mime + * @param string $pattern + * @return bool + */ + public static function isAccepted(string $mime, string $pattern): bool + { + $accepted = Str::accepted($pattern); - foreach ($accepted as $m) { - if (static::matches($mime, $m['value']) === true) { - return true; - } - } + foreach ($accepted as $m) { + if (static::matches($mime, $m['value']) === true) { + return true; + } + } - return false; - } + return false; + } - /** - * Tests if a MIME wildcard pattern from an `Accept` header - * matches a given type - * @since 3.3.0 - * - * @param string $test - * @param string $wildcard - * @return bool - */ - public static function matches(string $test, string $wildcard): bool - { - return fnmatch($wildcard, $test, FNM_PATHNAME) === true; - } + /** + * Tests if a MIME wildcard pattern from an `Accept` header + * matches a given type + * @since 3.3.0 + * + * @param string $test + * @param string $wildcard + * @return bool + */ + public static function matches(string $test, string $wildcard): bool + { + return fnmatch($wildcard, $test, FNM_PATHNAME) === true; + } - /** - * Returns the extension for a given MIME type - * - * @param string|null $mime - * @return string|false - */ - public static function toExtension(string $mime = null) - { - foreach (static::$types as $key => $value) { - if (is_array($value) === true && in_array($mime, $value) === true) { - return $key; - } + /** + * Returns the extension for a given MIME type + * + * @param string|null $mime + * @return string|false + */ + public static function toExtension(string $mime = null) + { + foreach (static::$types as $key => $value) { + if (is_array($value) === true && in_array($mime, $value) === true) { + return $key; + } - if ($value === $mime) { - return $key; - } - } + if ($value === $mime) { + return $key; + } + } - return false; - } + return false; + } - /** - * Returns all available extensions for a given MIME type - * - * @param string|null $mime - * @return array - */ - public static function toExtensions(string $mime = null): array - { - $extensions = []; + /** + * Returns all available extensions for a given MIME type + * + * @param string|null $mime + * @return array + */ + public static function toExtensions(string $mime = null): array + { + $extensions = []; - foreach (static::$types as $key => $value) { - if (is_array($value) === true && in_array($mime, $value) === true) { - $extensions[] = $key; - continue; - } + foreach (static::$types as $key => $value) { + if (is_array($value) === true && in_array($mime, $value) === true) { + $extensions[] = $key; + continue; + } - if ($value === $mime) { - $extensions[] = $key; - } - } + if ($value === $mime) { + $extensions[] = $key; + } + } - return $extensions; - } + return $extensions; + } - /** - * Returns the MIME type of a file - * - * @param string $file - * @param string $extension - * @return string|false - */ - public static function type(string $file, string $extension = null) - { - // use the standard finfo extension - $mime = static::fromFileInfo($file); + /** + * Returns the MIME type of a file + * + * @param string $file + * @param string $extension + * @return string|false + */ + public static function type(string $file, string $extension = null) + { + // use the standard finfo extension + $mime = static::fromFileInfo($file); - // use the mime_content_type function - if ($mime === false) { - $mime = static::fromMimeContentType($file); - } + // use the mime_content_type function + if ($mime === false) { + $mime = static::fromMimeContentType($file); + } - // get the extension or extract it from the filename - $extension ??= F::extension($file); + // get the extension or extract it from the filename + $extension ??= F::extension($file); - // try to guess the mime type at least - if ($mime === false) { - $mime = static::fromExtension($extension); - } + // try to guess the mime type at least + if ($mime === false) { + $mime = static::fromExtension($extension); + } - // fix broken mime detection - return static::fix($file, $mime, $extension); - } + // fix broken mime detection + return static::fix($file, $mime, $extension); + } - /** - * Returns all detectable MIME types - * - * @return array - */ - public static function types(): array - { - return static::$types; - } + /** + * Returns all detectable MIME types + * + * @return array + */ + public static function types(): array + { + return static::$types; + } } diff --git a/kirby/src/Form/Field.php b/kirby/src/Form/Field.php index 6d9e473..34f4a62 100755 --- a/kirby/src/Form/Field.php +++ b/kirby/src/Form/Field.php @@ -22,486 +22,486 @@ use Kirby\Toolkit\V; */ class Field extends Component { - /** - * An array of all found errors - * - * @var array|null - */ - protected $errors; + /** + * An array of all found errors + * + * @var array|null + */ + protected $errors; - /** - * Parent collection with all fields of the current form - * - * @var \Kirby\Form\Fields|null - */ - protected $formFields; + /** + * Parent collection with all fields of the current form + * + * @var \Kirby\Form\Fields|null + */ + protected $formFields; - /** - * Registry for all component mixins - * - * @var array - */ - public static $mixins = []; + /** + * Registry for all component mixins + * + * @var array + */ + public static $mixins = []; - /** - * Registry for all component types - * - * @var array - */ - public static $types = []; + /** + * Registry for all component types + * + * @var array + */ + 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) { - throw new InvalidArgumentException('The field type "' . $type . '" does not exist'); - } + /** + * 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) { + throw new InvalidArgumentException('The field type "' . $type . '" does not exist'); + } - if (isset($attrs['model']) === false) { - throw new InvalidArgumentException('Field requires a model'); - } + if (isset($attrs['model']) === false) { + throw new InvalidArgumentException('Field requires a model'); + } - $this->formFields = $formFields; + $this->formFields = $formFields; - // use the type as fallback for the name - $attrs['name'] ??= $type; - $attrs['type'] = $type; + // use the type as fallback for the name + $attrs['name'] ??= $type; + $attrs['type'] = $type; - parent::__construct($type, $attrs); - } + parent::__construct($type, $attrs); + } - /** - * Returns field api call - * - * @return mixed - */ - public function api() - { - if ( - isset($this->options['api']) === true && - is_a($this->options['api'], 'Closure') === true - ) { - return $this->options['api']->call($this); - } - } + /** + * Returns field api call + * + * @return mixed + */ + public function api() + { + if ( + isset($this->options['api']) === true && + is_a($this->options['api'], 'Closure') === true + ) { + return $this->options['api']->call($this); + } + } - /** - * Returns field data - * - * @param bool $default - * @return mixed - */ - public function data(bool $default = false) - { - $save = $this->options['save'] ?? true; + /** + * Returns field data + * + * @param bool $default + * @return mixed + */ + public function data(bool $default = false) + { + $save = $this->options['save'] ?? true; - if ($default === true && $this->isEmpty($this->value)) { - $value = $this->default(); - } else { - $value = $this->value; - } + if ($default === true && $this->isEmpty($this->value)) { + $value = $this->default(); + } else { + $value = $this->value; + } - if ($save === false) { - return null; - } + if ($save === false) { + return null; + } - if (is_a($save, 'Closure') === true) { - return $save->call($this, $value); - } + if (is_a($save, 'Closure') === true) { + return $save->call($this, $value); + } - return $value; - } + return $value; + } - /** - * Default props and computed of the field - * - * @return array - */ - public static function defaults(): array - { - return [ - 'props' => [ - /** - * Optional text that will be shown after the input - */ - 'after' => function ($after = null) { - return I18n::translate($after, $after); - }, - /** - * Sets the focus on this field when the form loads. Only the first field with this label gets - */ - 'autofocus' => function (bool $autofocus = null): bool { - return $autofocus ?? false; - }, - /** - * Optional text that will be shown before the input - */ - 'before' => function ($before = null) { - return I18n::translate($before, $before); - }, - /** - * Default value for the field, which will be used when a page/file/user is created - */ - 'default' => function ($default = null) { - return $default; - }, - /** - * If `true`, the field is no longer editable and will not be saved - */ - 'disabled' => function (bool $disabled = null): bool { - return $disabled ?? false; - }, - /** - * Optional help text below the field - */ - 'help' => function ($help = null) { - return I18n::translate($help, $help); - }, - /** - * Optional icon that will be shown at the end of the field - */ - 'icon' => function (string $icon = null) { - return $icon; - }, - /** - * The field label can be set as string or associative array with translations - */ - 'label' => function ($label = null) { - return I18n::translate($label, $label); - }, - /** - * Optional placeholder value that will be shown when the field is empty - */ - 'placeholder' => function ($placeholder = null) { - return I18n::translate($placeholder, $placeholder); - }, - /** - * If `true`, the field has to be filled in correctly to be saved. - */ - 'required' => function (bool $required = null): bool { - return $required ?? false; - }, - /** - * If `false`, the field will be disabled in non-default languages and cannot be translated. This is only relevant in multi-language setups. - */ - 'translate' => function (bool $translate = true): bool { - return $translate; - }, - /** - * Conditions when the field will be shown (since 3.1.0) - */ - 'when' => function ($when = null) { - return $when; - }, - /** - * The width of the field in the field grid. Available widths: `1/1`, `1/2`, `1/3`, `1/4`, `2/3`, `3/4` - */ - 'width' => function (string $width = '1/1') { - return $width; - }, - 'value' => function ($value = null) { - return $value; - } - ], - 'computed' => [ - 'after' => function () { - /** @var \Kirby\Form\Field $this */ - if ($this->after !== null) { - return $this->model()->toString($this->after); - } - }, - 'before' => function () { - /** @var \Kirby\Form\Field $this */ - if ($this->before !== null) { - return $this->model()->toString($this->before); - } - }, - 'default' => function () { - /** @var \Kirby\Form\Field $this */ - if ($this->default === null) { - return; - } + /** + * Default props and computed of the field + * + * @return array + */ + public static function defaults(): array + { + return [ + 'props' => [ + /** + * Optional text that will be shown after the input + */ + 'after' => function ($after = null) { + return I18n::translate($after, $after); + }, + /** + * Sets the focus on this field when the form loads. Only the first field with this label gets + */ + 'autofocus' => function (bool $autofocus = null): bool { + return $autofocus ?? false; + }, + /** + * Optional text that will be shown before the input + */ + 'before' => function ($before = null) { + return I18n::translate($before, $before); + }, + /** + * Default value for the field, which will be used when a page/file/user is created + */ + 'default' => function ($default = null) { + return $default; + }, + /** + * If `true`, the field is no longer editable and will not be saved + */ + 'disabled' => function (bool $disabled = null): bool { + return $disabled ?? false; + }, + /** + * Optional help text below the field + */ + 'help' => function ($help = null) { + return I18n::translate($help, $help); + }, + /** + * Optional icon that will be shown at the end of the field + */ + 'icon' => function (string $icon = null) { + return $icon; + }, + /** + * The field label can be set as string or associative array with translations + */ + 'label' => function ($label = null) { + return I18n::translate($label, $label); + }, + /** + * Optional placeholder value that will be shown when the field is empty + */ + 'placeholder' => function ($placeholder = null) { + return I18n::translate($placeholder, $placeholder); + }, + /** + * If `true`, the field has to be filled in correctly to be saved. + */ + 'required' => function (bool $required = null): bool { + return $required ?? false; + }, + /** + * If `false`, the field will be disabled in non-default languages and cannot be translated. This is only relevant in multi-language setups. + */ + 'translate' => function (bool $translate = true): bool { + return $translate; + }, + /** + * Conditions when the field will be shown (since 3.1.0) + */ + 'when' => function ($when = null) { + return $when; + }, + /** + * The width of the field in the field grid. Available widths: `1/1`, `1/2`, `1/3`, `1/4`, `2/3`, `3/4` + */ + 'width' => function (string $width = '1/1') { + return $width; + }, + 'value' => function ($value = null) { + return $value; + } + ], + 'computed' => [ + 'after' => function () { + /** @var \Kirby\Form\Field $this */ + if ($this->after !== null) { + return $this->model()->toString($this->after); + } + }, + 'before' => function () { + /** @var \Kirby\Form\Field $this */ + if ($this->before !== null) { + return $this->model()->toString($this->before); + } + }, + 'default' => function () { + /** @var \Kirby\Form\Field $this */ + if ($this->default === null) { + return; + } - if (is_string($this->default) === false) { - return $this->default; - } + if (is_string($this->default) === false) { + return $this->default; + } - return $this->model()->toString($this->default); - }, - 'help' => function () { - /** @var \Kirby\Form\Field $this */ - if ($this->help) { - $help = $this->model()->toSafeString($this->help); - $help = $this->kirby()->kirbytext($help); - return $help; - } - }, - 'label' => function () { - /** @var \Kirby\Form\Field $this */ - if ($this->label !== null) { - return $this->model()->toString($this->label); - } - }, - 'placeholder' => function () { - /** @var \Kirby\Form\Field $this */ - if ($this->placeholder !== null) { - return $this->model()->toString($this->placeholder); - } - } - ] - ]; - } + return $this->model()->toString($this->default); + }, + 'help' => function () { + /** @var \Kirby\Form\Field $this */ + if ($this->help) { + $help = $this->model()->toSafeString($this->help); + $help = $this->kirby()->kirbytext($help); + return $help; + } + }, + 'label' => function () { + /** @var \Kirby\Form\Field $this */ + if ($this->label !== null) { + return $this->model()->toString($this->label); + } + }, + 'placeholder' => function () { + /** @var \Kirby\Form\Field $this */ + if ($this->placeholder !== null) { + return $this->model()->toString($this->placeholder); + } + } + ] + ]; + } - /** - * Creates a new field instance - * - * @param string $type - * @param array $attrs - * @param Fields|null $formFields - * @return static - */ - public static function factory(string $type, array $attrs = [], ?Fields $formFields = null) - { - $field = static::$types[$type] ?? null; + /** + * Creates a new field instance + * + * @param string $type + * @param array $attrs + * @param Fields|null $formFields + * @return static + */ + public static function factory(string $type, array $attrs = [], ?Fields $formFields = null) + { + $field = static::$types[$type] ?? null; - if (is_string($field) && class_exists($field) === true) { - $attrs['siblings'] = $formFields; - return new $field($attrs); - } + if (is_string($field) && class_exists($field) === true) { + $attrs['siblings'] = $formFields; + return new $field($attrs); + } - return new static($type, $attrs, $formFields); - } + return new static($type, $attrs, $formFields); + } - /** - * Parent collection with all fields of the current form - * - * @return \Kirby\Form\Fields|null - */ - public function formFields(): ?Fields - { - return $this->formFields; - } + /** + * 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) { - $this->validate(); - } + /** + * Validates when run for the first time and returns any errors + * + * @return array + */ + public function errors(): array + { + if ($this->errors === null) { + $this->validate(); + } - return $this->errors; - } + return $this->errors; + } - /** - * Checks if the field is empty - * - * @param mixed ...$args - * @return bool - */ - public function isEmpty(...$args): bool - { - if (count($args) === 0) { - $value = $this->value(); - } else { - $value = $args[0]; - } + /** + * Checks if the field is empty + * + * @param mixed ...$args + * @return bool + */ + public function isEmpty(...$args): bool + { + if (count($args) === 0) { + $value = $this->value(); + } else { + $value = $args[0]; + } - if (isset($this->options['isEmpty']) === true) { - return $this->options['isEmpty']->call($this, $value); - } + if (isset($this->options['isEmpty']) === true) { + return $this->options['isEmpty']->call($this, $value); + } - return in_array($value, [null, '', []], true); - } + 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 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 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; - } + /** + * 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() - { - return $this->model()->kirby(); - } + /** + * Returns the Kirby instance + * + * @return \Kirby\Cms\App + */ + public function kirby() + { + return $this->model()->kirby(); + } - /** - * Returns the parent model - * - * @return mixed - */ - public function model() - { - return $this->model; - } + /** + * Returns the parent model + * + * @return mixed + */ + public function model() + { + return $this->model; + } - /** - * Checks if the field needs a value before being saved; - * this is the case if all of the following requirements are met: - * - The field is saveable - * - The field is required - * - The field is currently empty - * - The field is not currently inactive because of a `when` rule - * - * @return bool - */ - protected function needsValue(): bool - { - // check simple conditions first - if ($this->save() === false || $this->isRequired() === false || $this->isEmpty() === false) { - return false; - } + /** + * Checks if the field needs a value before being saved; + * this is the case if all of the following requirements are met: + * - The field is saveable + * - The field is required + * - The field is currently empty + * - The field is not currently inactive because of a `when` rule + * + * @return bool + */ + protected function needsValue(): bool + { + // check simple conditions first + if ($this->save() === false || $this->isRequired() === false || $this->isEmpty() === false) { + return false; + } - // check the data of the relevant fields if there is a `when` option - if (empty($this->when) === false && is_array($this->when) === true) { - $formFields = $this->formFields(); + // check the data of the relevant fields if there is a `when` option + if (empty($this->when) === false && is_array($this->when) === true) { + $formFields = $this->formFields(); - if ($formFields !== null) { - foreach ($this->when as $field => $value) { - $field = $formFields->get($field); - $inputValue = $field !== null ? $field->value() : ''; + if ($formFields !== null) { + foreach ($this->when as $field => $value) { + $field = $formFields->get($field); + $inputValue = $field !== null ? $field->value() : ''; - // if the input data doesn't match the requested `when` value, - // that means that this field is not required and can be saved - // (*all* `when` conditions must be met for this field to be required) - if ($inputValue !== $value) { - return false; - } - } - } - } + // if the input data doesn't match the requested `when` value, + // that means that this field is not required and can be saved + // (*all* `when` conditions must be met for this field to be required) + if ($inputValue !== $value) { + return false; + } + } + } + } - // either there was no `when` condition or all conditions matched - return true; - } + // either there was no `when` condition or all conditions matched + return true; + } - /** - * Checks if the field is saveable - * - * @return bool - */ - public function save(): bool - { - return ($this->options['save'] ?? true) !== false; - } + /** + * 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(); + /** + * Converts the field to a plain array + * + * @return array + */ + public function toArray(): array + { + $array = parent::toArray(); - unset($array['model']); + unset($array['model']); - $array['saveable'] = $this->save(); - $array['signature'] = md5(json_encode($array)); + $array['saveable'] = $this->save(); + $array['signature'] = md5(json_encode($array)); - ksort($array); + ksort($array); - return array_filter( - $array, - fn ($item) => $item !== null && is_object($item) === false - ); - } + return array_filter( + $array, + fn ($item) => $item !== null && is_object($item) === false + ); + } - /** - * Runs the validations defined for the field - * - * @return void - */ - protected function validate(): void - { - $validations = $this->options['validations'] ?? []; - $this->errors = []; + /** + * Runs the validations defined for the field + * + * @return void + */ + protected function validate(): void + { + $validations = $this->options['validations'] ?? []; + $this->errors = []; - // validate required values - if ($this->needsValue() === true) { - $this->errors['required'] = I18n::translate('error.validation.required'); - } + // validate required values + if ($this->needsValue() === true) { + $this->errors['required'] = I18n::translate('error.validation.required'); + } - foreach ($validations as $key => $validation) { - if (is_int($key) === true) { - // predefined validation - try { - Validations::$validation($this, $this->value()); - } catch (Exception $e) { - $this->errors[$validation] = $e->getMessage(); - } - continue; - } + foreach ($validations as $key => $validation) { + if (is_int($key) === true) { + // predefined validation + try { + Validations::$validation($this, $this->value()); + } catch (Exception $e) { + $this->errors[$validation] = $e->getMessage(); + } + continue; + } - if (is_a($validation, 'Closure') === true) { - try { - $validation->call($this, $this->value()); - } catch (Exception $e) { - $this->errors[$key] = $e->getMessage(); - } - } - } + if (is_a($validation, 'Closure') === true) { + try { + $validation->call($this, $this->value()); + } catch (Exception $e) { + $this->errors[$key] = $e->getMessage(); + } + } + } - if ( - empty($this->validate) === false && - ($this->isEmpty() === false || $this->isRequired() === true) - ) { - $rules = A::wrap($this->validate); - $errors = V::errors($this->value(), $rules); + if ( + empty($this->validate) === false && + ($this->isEmpty() === false || $this->isRequired() === true) + ) { + $rules = A::wrap($this->validate); + $errors = V::errors($this->value(), $rules); - if (empty($errors) === false) { - $this->errors = array_merge($this->errors, $errors); - } - } - } + if (empty($errors) === false) { + $this->errors = array_merge($this->errors, $errors); + } + } + } - /** - * Returns the value of the field if saveable - * otherwise it returns null - * - * @return mixed - */ - public function value() - { - return $this->save() ? $this->value : null; - } + /** + * Returns the value of the field if saveable + * otherwise it returns null + * + * @return mixed + */ + public function value() + { + return $this->save() ? $this->value : null; + } } diff --git a/kirby/src/Form/Field/BlocksField.php b/kirby/src/Form/Field/BlocksField.php index b49c473..6479b8a 100755 --- a/kirby/src/Form/Field/BlocksField.php +++ b/kirby/src/Form/Field/BlocksField.php @@ -18,268 +18,268 @@ use Throwable; class BlocksField extends FieldClass { - use EmptyState; - use Max; - use Min; + use EmptyState; + use Max; + use Min; - protected $blocks; - protected $fieldsets; - protected $group; - protected $pretty; - protected $value = []; + protected $blocks; + protected $fieldsets; + protected $group; + protected $pretty; + protected $value = []; - public function __construct(array $params = []) - { - $this->setFieldsets($params['fieldsets'] ?? null, $params['model'] ?? App::instance()->site()); + public function __construct(array $params = []) + { + $this->setFieldsets($params['fieldsets'] ?? null, $params['model'] ?? App::instance()->site()); - parent::__construct($params); + parent::__construct($params); - $this->setEmpty($params['empty'] ?? null); - $this->setGroup($params['group'] ?? 'blocks'); - $this->setMax($params['max'] ?? null); - $this->setMin($params['min'] ?? null); - $this->setPretty($params['pretty'] ?? false); - } + $this->setEmpty($params['empty'] ?? null); + $this->setGroup($params['group'] ?? 'blocks'); + $this->setMax($params['max'] ?? null); + $this->setMin($params['min'] ?? null); + $this->setPretty($params['pretty'] ?? false); + } - public function blocksToValues($blocks, $to = 'values'): array - { - $result = []; - $fields = []; + public function blocksToValues($blocks, $to = 'values'): array + { + $result = []; + $fields = []; - foreach ($blocks as $block) { - try { - $type = $block['type']; + foreach ($blocks as $block) { + try { + $type = $block['type']; - // get and cache fields at the same time - $fields[$type] ??= $this->fields($block['type']); + // get and cache fields at the same time + $fields[$type] ??= $this->fields($block['type']); - // overwrite the block content with form values - $block['content'] = $this->form($fields[$type], $block['content'])->$to(); + // overwrite the block content with form values + $block['content'] = $this->form($fields[$type], $block['content'])->$to(); - $result[] = $block; - } catch (Throwable $e) { - $result[] = $block; + $result[] = $block; + } catch (Throwable $e) { + $result[] = $block; - // skip invalid blocks - continue; - } - } + // skip invalid blocks + continue; + } + } - return $result; - } + return $result; + } - public function fields(string $type) - { - return $this->fieldset($type)->fields(); - } + public function fields(string $type) + { + return $this->fieldset($type)->fields(); + } - public function fieldset(string $type) - { - if ($fieldset = $this->fieldsets->find($type)) { - return $fieldset; - } + public function fieldset(string $type) + { + if ($fieldset = $this->fieldsets->find($type)) { + return $fieldset; + } - throw new NotFoundException('The fieldset ' . $type . ' could not be found'); - } + throw new NotFoundException('The fieldset ' . $type . ' could not be found'); + } - public function fieldsets() - { - return $this->fieldsets; - } + public function fieldsets() + { + return $this->fieldsets; + } - public function fieldsetGroups(): ?array - { - $fieldsetGroups = $this->fieldsets()->groups(); - return empty($fieldsetGroups) === true ? null : $fieldsetGroups; - } + public function fieldsetGroups(): ?array + { + $fieldsetGroups = $this->fieldsets()->groups(); + return empty($fieldsetGroups) === true ? null : $fieldsetGroups; + } - public function fill($value = null) - { - $value = BlocksCollection::parse($value); - $blocks = BlocksCollection::factory($value); - $this->value = $this->blocksToValues($blocks->toArray()); - } + public function fill($value = null) + { + $value = BlocksCollection::parse($value); + $blocks = BlocksCollection::factory($value); + $this->value = $this->blocksToValues($blocks->toArray()); + } - public function form(array $fields, array $input = []) - { - return new Form([ - 'fields' => $fields, - 'model' => $this->model, - 'strict' => true, - 'values' => $input, - ]); - } + public function form(array $fields, array $input = []) + { + return new Form([ + 'fields' => $fields, + 'model' => $this->model, + 'strict' => true, + 'values' => $input, + ]); + } - public function isEmpty(): bool - { - return count($this->value()) === 0; - } + public function isEmpty(): bool + { + return count($this->value()) === 0; + } - public function group(): string - { - return $this->group; - } + public function group(): string + { + return $this->group; + } - public function pretty(): bool - { - return $this->pretty; - } + public function pretty(): bool + { + return $this->pretty; + } - public function props(): array - { - return [ - 'empty' => $this->empty(), - 'fieldsets' => $this->fieldsets()->toArray(), - 'fieldsetGroups' => $this->fieldsetGroups(), - 'group' => $this->group(), - 'max' => $this->max(), - 'min' => $this->min(), - ] + parent::props(); - } + public function props(): array + { + return [ + 'empty' => $this->empty(), + 'fieldsets' => $this->fieldsets()->toArray(), + 'fieldsetGroups' => $this->fieldsetGroups(), + 'group' => $this->group(), + 'max' => $this->max(), + 'min' => $this->min(), + ] + parent::props(); + } - public function routes(): array - { - $field = $this; + public function routes(): array + { + $field = $this; - return [ - [ - 'pattern' => 'uuid', - 'action' => fn () => ['uuid' => Str::uuid()] - ], - [ - 'pattern' => 'paste', - 'method' => 'POST', - 'action' => function () use ($field) { - $request = App::instance()->request(); + return [ + [ + 'pattern' => 'uuid', + 'action' => fn () => ['uuid' => Str::uuid()] + ], + [ + 'pattern' => 'paste', + 'method' => 'POST', + 'action' => function () use ($field) { + $request = App::instance()->request(); - $value = BlocksCollection::parse($request->get('html')); - $blocks = BlocksCollection::factory($value); - return $field->blocksToValues($blocks->toArray()); - } - ], - [ - 'pattern' => 'fieldsets/(:any)', - 'method' => 'GET', - 'action' => function ($fieldsetType) use ($field) { - $fields = $field->fields($fieldsetType); - $defaults = $field->form($fields, [])->data(true); - $content = $field->form($fields, $defaults)->values(); + $value = BlocksCollection::parse($request->get('html')); + $blocks = BlocksCollection::factory($value); + return $field->blocksToValues($blocks->toArray()); + } + ], + [ + 'pattern' => 'fieldsets/(:any)', + 'method' => 'GET', + 'action' => function ($fieldsetType) use ($field) { + $fields = $field->fields($fieldsetType); + $defaults = $field->form($fields, [])->data(true); + $content = $field->form($fields, $defaults)->values(); - return Block::factory([ - 'content' => $content, - 'type' => $fieldsetType - ])->toArray(); - } - ], - [ - 'pattern' => 'fieldsets/(:any)/fields/(:any)/(:all?)', - 'method' => 'ALL', - 'action' => function (string $fieldsetType, string $fieldName, string $path = null) use ($field) { - $fields = $field->fields($fieldsetType); - $field = $field->form($fields)->field($fieldName); + return Block::factory([ + 'content' => $content, + 'type' => $fieldsetType + ])->toArray(); + } + ], + [ + 'pattern' => 'fieldsets/(:any)/fields/(:any)/(:all?)', + 'method' => 'ALL', + 'action' => function (string $fieldsetType, string $fieldName, string $path = null) use ($field) { + $fields = $field->fields($fieldsetType); + $field = $field->form($fields)->field($fieldName); - $fieldApi = $this->clone([ - 'routes' => $field->api(), - 'data' => array_merge($this->data(), ['field' => $field]) - ]); + $fieldApi = $this->clone([ + 'routes' => $field->api(), + 'data' => array_merge($this->data(), ['field' => $field]) + ]); - return $fieldApi->call($path, $this->requestMethod(), $this->requestData()); - } - ], - ]; - } + return $fieldApi->call($path, $this->requestMethod(), $this->requestData()); + } + ], + ]; + } - public function store($value) - { - $blocks = $this->blocksToValues((array)$value, 'content'); + public function store($value) + { + $blocks = $this->blocksToValues((array)$value, 'content'); - // returns empty string to avoid storing empty array as string `[]` - // and to consistency work with `$field->isEmpty()` - if (empty($blocks) === true) { - return ''; - } + // returns empty string to avoid storing empty array as string `[]` + // and to consistency work with `$field->isEmpty()` + if (empty($blocks) === true) { + return ''; + } - return $this->valueToJson($blocks, $this->pretty()); - } + return $this->valueToJson($blocks, $this->pretty()); + } - protected function setFieldsets($fieldsets, $model) - { - if (is_string($fieldsets) === true) { - $fieldsets = []; - } + protected function setFieldsets($fieldsets, $model) + { + if (is_string($fieldsets) === true) { + $fieldsets = []; + } - $this->fieldsets = Fieldsets::factory($fieldsets, [ - 'parent' => $model - ]); - } + $this->fieldsets = Fieldsets::factory($fieldsets, [ + 'parent' => $model + ]); + } - protected function setGroup(string $group = null) - { - $this->group = $group; - } + protected function setGroup(string $group = null) + { + $this->group = $group; + } - protected function setPretty(bool $pretty = false) - { - $this->pretty = $pretty; - } + protected function setPretty(bool $pretty = false) + { + $this->pretty = $pretty; + } - public function validations(): array - { - return [ - 'blocks' => function ($value) { - if ($this->min && count($value) < $this->min) { - throw new InvalidArgumentException([ - 'key' => 'blocks.min.' . ($this->min === 1 ? 'singular' : 'plural'), - 'data' => [ - 'min' => $this->min - ] - ]); - } + public function validations(): array + { + return [ + 'blocks' => function ($value) { + if ($this->min && count($value) < $this->min) { + throw new InvalidArgumentException([ + 'key' => 'blocks.min.' . ($this->min === 1 ? 'singular' : 'plural'), + 'data' => [ + 'min' => $this->min + ] + ]); + } - if ($this->max && count($value) > $this->max) { - throw new InvalidArgumentException([ - 'key' => 'blocks.max.' . ($this->max === 1 ? 'singular' : 'plural'), - 'data' => [ - 'max' => $this->max - ] - ]); - } + if ($this->max && count($value) > $this->max) { + throw new InvalidArgumentException([ + 'key' => 'blocks.max.' . ($this->max === 1 ? 'singular' : 'plural'), + 'data' => [ + 'max' => $this->max + ] + ]); + } - $fields = []; - $index = 0; + $fields = []; + $index = 0; - foreach ($value as $block) { - $index++; - $blockType = $block['type']; + foreach ($value as $block) { + $index++; + $blockType = $block['type']; - try { - $blockFields = $fields[$blockType] ?? $this->fields($blockType) ?? []; - } catch (Throwable $e) { - // skip invalid blocks - continue; - } + try { + $blockFields = $fields[$blockType] ?? $this->fields($blockType) ?? []; + } catch (Throwable $e) { + // skip invalid blocks + continue; + } - // store the fields for the next round - $fields[$blockType] = $blockFields; + // store the fields for the next round + $fields[$blockType] = $blockFields; - // overwrite the content with the serialized form - foreach ($this->form($blockFields, $block['content'])->fields() as $field) { - $errors = $field->errors(); + // overwrite the content with the serialized form + foreach ($this->form($blockFields, $block['content'])->fields() as $field) { + $errors = $field->errors(); - // rough first validation - if (empty($errors) === false) { - throw new InvalidArgumentException([ - 'key' => 'blocks.validation', - 'data' => [ - 'index' => $index, - ] - ]); - } - } - } + // rough first validation + if (empty($errors) === false) { + throw new InvalidArgumentException([ + 'key' => 'blocks.validation', + 'data' => [ + 'index' => $index, + ] + ]); + } + } + } - return true; - } - ]; - } + return true; + } + ]; + } } diff --git a/kirby/src/Form/Field/LayoutField.php b/kirby/src/Form/Field/LayoutField.php index 56856b0..640d095 100755 --- a/kirby/src/Form/Field/LayoutField.php +++ b/kirby/src/Form/Field/LayoutField.php @@ -14,222 +14,222 @@ use Throwable; class LayoutField extends BlocksField { - protected $layouts; - protected $settings; + protected $layouts; + protected $settings; - public function __construct(array $params) - { - $this->setModel($params['model'] ?? App::instance()->site()); - $this->setLayouts($params['layouts'] ?? ['1/1']); - $this->setSettings($params['settings'] ?? null); + public function __construct(array $params) + { + $this->setModel($params['model'] ?? App::instance()->site()); + $this->setLayouts($params['layouts'] ?? ['1/1']); + $this->setSettings($params['settings'] ?? null); - parent::__construct($params); - } + parent::__construct($params); + } - public function fill($value = null) - { - $value = $this->valueFromJson($value); - $layouts = Layouts::factory($value, ['parent' => $this->model])->toArray(); + public function fill($value = null) + { + $value = $this->valueFromJson($value); + $layouts = Layouts::factory($value, ['parent' => $this->model])->toArray(); - foreach ($layouts as $layoutIndex => $layout) { - if ($this->settings !== null) { - $layouts[$layoutIndex]['attrs'] = $this->attrsForm($layout['attrs'])->values(); - } + foreach ($layouts as $layoutIndex => $layout) { + if ($this->settings !== null) { + $layouts[$layoutIndex]['attrs'] = $this->attrsForm($layout['attrs'])->values(); + } - foreach ($layout['columns'] as $columnIndex => $column) { - $layouts[$layoutIndex]['columns'][$columnIndex]['blocks'] = $this->blocksToValues($column['blocks']); - } - } + foreach ($layout['columns'] as $columnIndex => $column) { + $layouts[$layoutIndex]['columns'][$columnIndex]['blocks'] = $this->blocksToValues($column['blocks']); + } + } - $this->value = $layouts; - } + $this->value = $layouts; + } - public function attrsForm(array $input = []) - { - $settings = $this->settings(); + public function attrsForm(array $input = []) + { + $settings = $this->settings(); - return new Form([ - 'fields' => $settings ? $settings->fields() : [], - 'model' => $this->model, - 'strict' => true, - 'values' => $input, - ]); - } + return new Form([ + 'fields' => $settings ? $settings->fields() : [], + 'model' => $this->model, + 'strict' => true, + 'values' => $input, + ]); + } - public function layouts(): ?array - { - return $this->layouts; - } + public function layouts(): ?array + { + return $this->layouts; + } - public function props(): array - { - $settings = $this->settings(); + public function props(): array + { + $settings = $this->settings(); - return array_merge(parent::props(), [ - 'settings' => $settings !== null ? $settings->toArray() : null, - 'layouts' => $this->layouts() - ]); - } + return array_merge(parent::props(), [ + 'settings' => $settings !== null ? $settings->toArray() : null, + 'layouts' => $this->layouts() + ]); + } - public function routes(): array - { - $field = $this; - $routes = parent::routes(); - $routes[] = [ - 'pattern' => 'layout', - 'method' => 'POST', - 'action' => function () use ($field) { - $request = App::instance()->request(); + public function routes(): array + { + $field = $this; + $routes = parent::routes(); + $routes[] = [ + 'pattern' => 'layout', + 'method' => 'POST', + 'action' => function () use ($field) { + $request = App::instance()->request(); - $defaults = $field->attrsForm([])->data(true); - $attrs = $field->attrsForm($defaults)->values(); - $columns = $request->get('columns') ?? ['1/1']; + $defaults = $field->attrsForm([])->data(true); + $attrs = $field->attrsForm($defaults)->values(); + $columns = $request->get('columns') ?? ['1/1']; - return Layout::factory([ - 'attrs' => $attrs, - 'columns' => array_map(fn ($width) => [ - 'blocks' => [], - 'id' => Str::uuid(), - 'width' => $width, - ], $columns) - ])->toArray(); - }, - ]; + return Layout::factory([ + 'attrs' => $attrs, + 'columns' => array_map(fn ($width) => [ + 'blocks' => [], + 'id' => Str::uuid(), + 'width' => $width, + ], $columns) + ])->toArray(); + }, + ]; - $routes[] = [ - 'pattern' => 'fields/(:any)/(:all?)', - 'method' => 'ALL', - 'action' => function (string $fieldName, string $path = null) use ($field) { - $form = $field->attrsForm(); - $field = $form->field($fieldName); + $routes[] = [ + 'pattern' => 'fields/(:any)/(:all?)', + 'method' => 'ALL', + 'action' => function (string $fieldName, string $path = null) use ($field) { + $form = $field->attrsForm(); + $field = $form->field($fieldName); - $fieldApi = $this->clone([ - 'routes' => $field->api(), - 'data' => array_merge($this->data(), ['field' => $field]) - ]); + $fieldApi = $this->clone([ + 'routes' => $field->api(), + 'data' => array_merge($this->data(), ['field' => $field]) + ]); - return $fieldApi->call($path, $this->requestMethod(), $this->requestData()); - } - ]; + return $fieldApi->call($path, $this->requestMethod(), $this->requestData()); + } + ]; - return $routes; - } + return $routes; + } - protected function setLayouts(array $layouts = []) - { - $this->layouts = array_map( - fn ($layout) => Str::split($layout), - $layouts - ); - } + protected function setLayouts(array $layouts = []) + { + $this->layouts = array_map( + fn ($layout) => Str::split($layout), + $layouts + ); + } - protected function setSettings($settings = null) - { - if (empty($settings) === true) { - $this->settings = null; - return; - } + protected function setSettings($settings = null) + { + if (empty($settings) === true) { + $this->settings = null; + return; + } - $settings = Blueprint::extend($settings); + $settings = Blueprint::extend($settings); - $settings['icon'] = 'dashboard'; - $settings['type'] = 'layout'; - $settings['parent'] = $this->model(); + $settings['icon'] = 'dashboard'; + $settings['type'] = 'layout'; + $settings['parent'] = $this->model(); - $this->settings = Fieldset::factory($settings); - } + $this->settings = Fieldset::factory($settings); + } - public function settings() - { - return $this->settings; - } + public function settings() + { + return $this->settings; + } - public function store($value) - { - $value = Layouts::factory($value, ['parent' => $this->model])->toArray(); + public function store($value) + { + $value = Layouts::factory($value, ['parent' => $this->model])->toArray(); - // returns empty string to avoid storing empty array as string `[]` - // and to consistency work with `$field->isEmpty()` - if (empty($value) === true) { - return ''; - } + // returns empty string to avoid storing empty array as string `[]` + // and to consistency work with `$field->isEmpty()` + if (empty($value) === true) { + return ''; + } - foreach ($value as $layoutIndex => $layout) { - if ($this->settings !== null) { - $value[$layoutIndex]['attrs'] = $this->attrsForm($layout['attrs'])->content(); - } + foreach ($value as $layoutIndex => $layout) { + if ($this->settings !== null) { + $value[$layoutIndex]['attrs'] = $this->attrsForm($layout['attrs'])->content(); + } - foreach ($layout['columns'] as $columnIndex => $column) { - $value[$layoutIndex]['columns'][$columnIndex]['blocks'] = $this->blocksToValues($column['blocks'] ?? [], 'content'); - } - } + foreach ($layout['columns'] as $columnIndex => $column) { + $value[$layoutIndex]['columns'][$columnIndex]['blocks'] = $this->blocksToValues($column['blocks'] ?? [], 'content'); + } + } - return $this->valueToJson($value, $this->pretty()); - } + return $this->valueToJson($value, $this->pretty()); + } - public function validations(): array - { - return [ - 'layout' => function ($value) { - $fields = []; - $layoutIndex = 0; + public function validations(): array + { + return [ + 'layout' => function ($value) { + $fields = []; + $layoutIndex = 0; - foreach ($value as $layout) { - $layoutIndex++; + foreach ($value as $layout) { + $layoutIndex++; - // validate settings form - foreach ($this->attrsForm($layout['attrs'] ?? [])->fields() as $field) { - $errors = $field->errors(); + // validate settings form + foreach ($this->attrsForm($layout['attrs'] ?? [])->fields() as $field) { + $errors = $field->errors(); - if (empty($errors) === false) { - throw new InvalidArgumentException([ - 'key' => 'layout.validation.settings', - 'data' => [ - 'index' => $layoutIndex - ] - ]); - } - } + if (empty($errors) === false) { + throw new InvalidArgumentException([ + 'key' => 'layout.validation.settings', + 'data' => [ + 'index' => $layoutIndex + ] + ]); + } + } - // validate blocks in the layout - $blockIndex = 0; + // validate blocks in the layout + $blockIndex = 0; - foreach ($layout['columns'] ?? [] as $column) { - foreach ($column['blocks'] ?? [] as $block) { - $blockIndex++; - $blockType = $block['type']; + foreach ($layout['columns'] ?? [] as $column) { + foreach ($column['blocks'] ?? [] as $block) { + $blockIndex++; + $blockType = $block['type']; - try { - $blockFields = $fields[$blockType] ?? $this->fields($blockType) ?? []; - } catch (Throwable $e) { - // skip invalid blocks - continue; - } + try { + $blockFields = $fields[$blockType] ?? $this->fields($blockType) ?? []; + } catch (Throwable $e) { + // skip invalid blocks + continue; + } - // store the fields for the next round - $fields[$blockType] = $blockFields; + // store the fields for the next round + $fields[$blockType] = $blockFields; - // overwrite the content with the serialized form - foreach ($this->form($blockFields, $block['content'])->fields() as $field) { - $errors = $field->errors(); + // overwrite the content with the serialized form + foreach ($this->form($blockFields, $block['content'])->fields() as $field) { + $errors = $field->errors(); - // rough first validation - if (empty($errors) === false) { - throw new InvalidArgumentException([ - 'key' => 'layout.validation.block', - 'data' => [ - 'blockIndex' => $blockIndex, - 'layoutIndex' => $layoutIndex - ] - ]); - } - } - } - } - } + // rough first validation + if (empty($errors) === false) { + throw new InvalidArgumentException([ + 'key' => 'layout.validation.block', + 'data' => [ + 'blockIndex' => $blockIndex, + 'layoutIndex' => $layoutIndex + ] + ]); + } + } + } + } + } - return true; - } - ]; - } + return true; + } + ]; + } } diff --git a/kirby/src/Form/FieldClass.php b/kirby/src/Form/FieldClass.php index f242f74..ed3804b 100755 --- a/kirby/src/Form/FieldClass.php +++ b/kirby/src/Form/FieldClass.php @@ -24,853 +24,853 @@ use Throwable; */ abstract class FieldClass { - use HasSiblings; - - /** - * @var string|null - */ - protected $after; - - /** - * @var bool - */ - protected $autofocus; - - /** - * @var string|null - */ - protected $before; - - /** - * @var mixed - */ - protected $default; - - /** - * @var bool - */ - protected $disabled; - - /** - * @var string|null - */ - protected $help; - - /** - * @var string|null - */ - protected $icon; - - /** - * @var string|null - */ - protected $label; - - /** - * @var \Kirby\Cms\ModelWithContent - */ - protected $model; - - /** - * @var string - */ - protected $name; - - /** - * @var array - */ - protected $params; - - /** - * @var string|null - */ - protected $placeholder; - - /** - * @var bool - */ - protected $required; - - /** - * @var \Kirby\Form\Fields - */ - protected $siblings; - - /** - * @var bool - */ - protected $translate; - - /** - * @var mixed - */ - protected $value; - - /** - * @var array|null - */ - protected $when; - - /** - * @var string|null - */ - protected $width; - - /** - * @param string $param - * @param array $args - * @return mixed - */ - public function __call(string $param, array $args) - { - if (isset($this->$param) === true) { - return $this->$param; - } - - return $this->params[$param] ?? null; - } - - /** - * @param array $params - */ - public function __construct(array $params = []) - { - $this->params = $params; - - $this->setAfter($params['after'] ?? null); - $this->setAutofocus($params['autofocus'] ?? false); - $this->setBefore($params['before'] ?? null); - $this->setDefault($params['default'] ?? null); - $this->setDisabled($params['disabled'] ?? false); - $this->setHelp($params['help'] ?? null); - $this->setIcon($params['icon'] ?? null); - $this->setLabel($params['label'] ?? null); - $this->setModel($params['model'] ?? App::instance()->site()); - $this->setName($params['name'] ?? null); - $this->setPlaceholder($params['placeholder'] ?? null); - $this->setRequired($params['required'] ?? false); - $this->setSiblings($params['siblings'] ?? null); - $this->setTranslate($params['translate'] ?? true); - $this->setWhen($params['when'] ?? null); - $this->setWidth($params['width'] ?? null); - - if (array_key_exists('value', $params) === true) { - $this->fill($params['value']); - } - } - - /** - * @return string|null - */ - public function after(): ?string - { - return $this->stringTemplate($this->after); - } - - /** - * @return array - */ - public function api(): array - { - return $this->routes(); - } - - /** - * @return bool - */ - public function autofocus(): bool - { - return $this->autofocus; - } - - /** - * @return string|null - */ - public function before(): ?string - { - return $this->stringTemplate($this->before); - } - - /** - * @deprecated 3.5.0 - * @todo remove when the general field class setup has been refactored - * - * Returns the field data - * in a format to be stored - * in Kirby's content fields - * - * @param bool $default - * @return mixed - */ - public function data(bool $default = false) - { - return $this->store($this->value($default)); - } - - /** - * Returns the default value for the field, - * which will be used when a page/file/user is created - * - * @return mixed - */ - public function default() - { - if (is_string($this->default) === false) { - return $this->default; - } - - return $this->stringTemplate($this->default); - } - - /** - * If `true`, the field is no longer editable and will not be saved - * - * @return bool - */ - public function disabled(): bool - { - return $this->disabled; - } - - /** - * Runs all validations and returns an array of - * error messages - * - * @return array - */ - public function errors(): array - { - return $this->validate(); - } - - /** - * Setter for the value - * - * @param mixed $value - * @return void - */ - public function fill($value = null) - { - $this->value = $value; - } - - /** - * Optional help text below the field - * - * @return string|null - */ - public function help(): ?string - { - if (empty($this->help) === false) { - $help = $this->stringTemplate($this->help); - $help = $this->kirby()->kirbytext($help); - return $help; - } - - return null; - } - - /** - * @param string|array|null $param - * @return string|null - */ - protected function i18n($param = null): ?string - { - return empty($param) === false ? I18n::translate($param, $param) : null; - } - - /** - * Optional icon that will be shown at the end of the field - * - * @return string|null - */ - public function icon(): ?string - { - return $this->icon; - } - - /** - * @return string - */ - public function id(): string - { - return $this->name(); - } - - /** - * @return bool - */ - public function isDisabled(): bool - { - return $this->disabled; - } - - /** - * @return bool - */ - public function isEmpty(): bool - { - return $this->isEmptyValue($this->value()); - } - - /** - * @param mixed $value - * @return bool - */ - public function isEmptyValue($value = null): bool - { - return in_array($value, [null, '', []], true); - } - - /** - * Checks if the field is invalid - * - * @return bool - */ - public function isInvalid(): bool - { - return $this->isValid() === false; - } - - /** - * @return bool - */ - public function isRequired(): bool - { - return $this->required; - } - - /** - * @return bool - */ - public function isSaveable(): bool - { - return true; - } - - /** - * 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() - { - return $this->model->kirby(); - } - - /** - * The field label can be set as string or associative array with translations - * - * @return string - */ - public function label(): string - { - return $this->stringTemplate($this->label ?? Str::ucfirst($this->name())); - } - - /** - * Returns the parent model - * - * @return mixed - */ - public function model() - { - return $this->model; - } - - /** - * Returns the field name - * - * @return string - */ - public function name(): string - { - return $this->name ?? $this->type(); - } - - /** - * Checks if the field needs a value before being saved; - * this is the case if all of the following requirements are met: - * - The field is saveable - * - The field is required - * - The field is currently empty - * - The field is not currently inactive because of a `when` rule - * - * @return bool - */ - protected function needsValue(): bool - { - // check simple conditions first - if ( - $this->isSaveable() === false || - $this->isRequired() === false || - $this->isEmpty() === false - ) { - return false; - } - - // check the data of the relevant fields if there is a `when` option - if (empty($this->when) === false && is_array($this->when) === true) { - $formFields = $this->siblings(); - - if ($formFields !== null) { - foreach ($this->when as $field => $value) { - $field = $formFields->get($field); - $inputValue = $field !== null ? $field->value() : ''; - - // if the input data doesn't match the requested `when` value, - // that means that this field is not required and can be saved - // (*all* `when` conditions must be met for this field to be required) - if ($inputValue !== $value) { - return false; - } - } - } - } - - // either there was no `when` condition or all conditions matched - return true; - } - - /** - * Returns all original params for the field - * - * @return array - */ - public function params(): array - { - return $this->params; - } - - /** - * Optional placeholder value that will be shown when the field is empty - * - * @return string|null - */ - public function placeholder(): ?string - { - return $this->stringTemplate($this->placeholder); - } - - /** - * Define the props that will be sent to - * the Vue component - * - * @return array - */ - public function props(): array - { - return [ - 'after' => $this->after(), - 'autofocus' => $this->autofocus(), - 'before' => $this->before(), - 'default' => $this->default(), - 'disabled' => $this->isDisabled(), - 'help' => $this->help(), - 'icon' => $this->icon(), - 'label' => $this->label(), - 'name' => $this->name(), - 'placeholder' => $this->placeholder(), - 'required' => $this->isRequired(), - 'saveable' => $this->isSaveable(), - 'translate' => $this->translate(), - 'type' => $this->type(), - 'when' => $this->when(), - 'width' => $this->width(), - ]; - } - - /** - * If `true`, the field has to be filled in correctly to be saved. - * - * @return bool - */ - public function required(): bool - { - return $this->required; - } - - /** - * Routes for the field API - * - * @return array - */ - public function routes(): array - { - return []; - } - - /** - * @deprecated 3.5.0 - * @todo remove when the general field class setup has been refactored - * @return bool - */ - public function save() - { - return $this->isSaveable(); - } - - /** - * @param array|string|null $after - * @return void - */ - protected function setAfter($after = null) - { - $this->after = $this->i18n($after); - } - - /** - * @param bool $autofocus - * @return void - */ - protected function setAutofocus(bool $autofocus = false) - { - $this->autofocus = $autofocus; - } - - /** - * @param array|string|null $before - * @return void - */ - protected function setBefore($before = null) - { - $this->before = $this->i18n($before); - } - - /** - * @param mixed $default - * @return void - */ - protected function setDefault($default = null) - { - $this->default = $default; - } - - /** - * @param bool $disabled - * @return void - */ - protected function setDisabled(bool $disabled = false) - { - $this->disabled = $disabled; - } - - /** - * @param array|string|null $help - * @return void - */ - protected function setHelp($help = null) - { - $this->help = $this->i18n($help); - } - - /** - * @param string|null $icon - * @return void - */ - protected function setIcon(?string $icon = null) - { - $this->icon = $icon; - } - - /** - * @param array|string|null $label - * @return void - */ - protected function setLabel($label = null) - { - $this->label = $this->i18n($label); - } - - /** - * @param \Kirby\Cms\ModelWithContent $model - * @return void - */ - protected function setModel(ModelWithContent $model) - { - $this->model = $model; - } - - /** - * @param string|null $name - * @return void - */ - protected function setName(string $name = null) - { - $this->name = $name; - } - - /** - * @param array|string|null $placeholder - * @return void - */ - protected function setPlaceholder($placeholder = null) - { - $this->placeholder = $this->i18n($placeholder); - } - - /** - * @param bool $required - * @return void - */ - protected function setRequired(bool $required = false) - { - $this->required = $required; - } - - /** - * @param \Kirby\Form\Fields|null $siblings - * @return void - */ - protected function setSiblings(?Fields $siblings = null) - { - $this->siblings = $siblings ?? new Fields([$this]); - } - - /** - * @param bool $translate - * @return void - */ - protected function setTranslate(bool $translate = true) - { - $this->translate = $translate; - } - - /** - * Setter for the when condition - * - * @param mixed $when - * @return void - */ - protected function setWhen($when = null) - { - $this->when = $when; - } - - /** - * Setter for the field width - * - * @param string|null $width - * @return void - */ - protected function setWidth(string $width = null) - { - $this->width = $width; - } - - /** - * Returns all sibling fields - * - * @return \Kirby\Form\Fields - */ - protected function siblingsCollection() - { - return $this->siblings; - } - - /** - * Parses a string template in the given value - * - * @param string|null $string - * @return string|null - */ - protected function stringTemplate(?string $string = null): ?string - { - if ($string !== null) { - return $this->model->toString($string); - } - - return null; - } - - /** - * Converts the given value to a value - * that can be stored in the text file - * - * @param mixed $value - * @return mixed - */ - public function store($value) - { - return $value; - } - - /** - * Should the field be translatable? - * - * @return bool - */ - public function translate(): bool - { - return $this->translate; - } - - /** - * Converts the field to a plain array - * - * @return array - */ - public function toArray(): array - { - $props = $this->props(); - $props['signature'] = md5(json_encode($props)); - - ksort($props); - - return array_filter($props, fn ($item) => $item !== null); - } - - /** - * Returns the field type - * - * @return string - */ - public function type(): string - { - return lcfirst(basename(str_replace(['\\', 'Field'], ['/', ''], static::class))); - } - - /** - * Runs the validations defined for the field - * - * @return array - */ - protected function validate(): array - { - $validations = $this->validations(); - $value = $this->value(); - $errors = []; - - // validate required values - if ($this->needsValue() === true) { - $errors['required'] = I18n::translate('error.validation.required'); - } - - foreach ($validations as $key => $validation) { - if (is_int($key) === true) { - // predefined validation - try { - Validations::$validation($this, $value); - } catch (Exception $e) { - $errors[$validation] = $e->getMessage(); - } - continue; - } - - if (is_a($validation, 'Closure') === true) { - try { - $validation->call($this, $value); - } catch (Exception $e) { - $errors[$key] = $e->getMessage(); - } - } - } - - return $errors; - } - - /** - * Defines all validation rules - * - * @return array - */ - protected function validations(): array - { - return []; - } - - /** - * Returns the value of the field if saveable - * otherwise it returns null - * - * @return mixed - */ - public function value(bool $default = false) - { - if ($this->isSaveable() === false) { - return null; - } - - if ($default === true && $this->isEmpty() === true) { - return $this->default(); - } - - return $this->value; - } - - /** - * @param mixed $value - * @return array - */ - protected function valueFromJson($value): array - { - try { - return Data::decode($value, 'json'); - } catch (Throwable $e) { - return []; - } - } - - /** - * @param mixed $value - * @return array - */ - protected function valueFromYaml($value): array - { - return Data::decode($value, 'yaml'); - } - - /** - * @param array|null $value - * @param bool $pretty - * @return string - */ - protected function valueToJson(array $value = null, bool $pretty = false): string - { - if ($pretty === true) { - return json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); - } - - return json_encode($value); - } - - /** - * @param array|null $value - * @return string - */ - protected function valueToYaml(array $value = null): string - { - return Data::encode($value, 'yaml'); - } - - /** - * Conditions when the field will be shown - * - * @return array|null - */ - public function when(): ?array - { - return $this->when; - } - - /** - * Returns the width of the field in - * the Panel grid - * - * @return string - */ - public function width(): string - { - return $this->width ?? '1/1'; - } + use HasSiblings; + + /** + * @var string|null + */ + protected $after; + + /** + * @var bool + */ + protected $autofocus; + + /** + * @var string|null + */ + protected $before; + + /** + * @var mixed + */ + protected $default; + + /** + * @var bool + */ + protected $disabled; + + /** + * @var string|null + */ + protected $help; + + /** + * @var string|null + */ + protected $icon; + + /** + * @var string|null + */ + protected $label; + + /** + * @var \Kirby\Cms\ModelWithContent + */ + protected $model; + + /** + * @var string + */ + protected $name; + + /** + * @var array + */ + protected $params; + + /** + * @var string|null + */ + protected $placeholder; + + /** + * @var bool + */ + protected $required; + + /** + * @var \Kirby\Form\Fields + */ + protected $siblings; + + /** + * @var bool + */ + protected $translate; + + /** + * @var mixed + */ + protected $value; + + /** + * @var array|null + */ + protected $when; + + /** + * @var string|null + */ + protected $width; + + /** + * @param string $param + * @param array $args + * @return mixed + */ + public function __call(string $param, array $args) + { + if (isset($this->$param) === true) { + return $this->$param; + } + + return $this->params[$param] ?? null; + } + + /** + * @param array $params + */ + public function __construct(array $params = []) + { + $this->params = $params; + + $this->setAfter($params['after'] ?? null); + $this->setAutofocus($params['autofocus'] ?? false); + $this->setBefore($params['before'] ?? null); + $this->setDefault($params['default'] ?? null); + $this->setDisabled($params['disabled'] ?? false); + $this->setHelp($params['help'] ?? null); + $this->setIcon($params['icon'] ?? null); + $this->setLabel($params['label'] ?? null); + $this->setModel($params['model'] ?? App::instance()->site()); + $this->setName($params['name'] ?? null); + $this->setPlaceholder($params['placeholder'] ?? null); + $this->setRequired($params['required'] ?? false); + $this->setSiblings($params['siblings'] ?? null); + $this->setTranslate($params['translate'] ?? true); + $this->setWhen($params['when'] ?? null); + $this->setWidth($params['width'] ?? null); + + if (array_key_exists('value', $params) === true) { + $this->fill($params['value']); + } + } + + /** + * @return string|null + */ + public function after(): ?string + { + return $this->stringTemplate($this->after); + } + + /** + * @return array + */ + public function api(): array + { + return $this->routes(); + } + + /** + * @return bool + */ + public function autofocus(): bool + { + return $this->autofocus; + } + + /** + * @return string|null + */ + public function before(): ?string + { + return $this->stringTemplate($this->before); + } + + /** + * @deprecated 3.5.0 + * @todo remove when the general field class setup has been refactored + * + * Returns the field data + * in a format to be stored + * in Kirby's content fields + * + * @param bool $default + * @return mixed + */ + public function data(bool $default = false) + { + return $this->store($this->value($default)); + } + + /** + * Returns the default value for the field, + * which will be used when a page/file/user is created + * + * @return mixed + */ + public function default() + { + if (is_string($this->default) === false) { + return $this->default; + } + + return $this->stringTemplate($this->default); + } + + /** + * If `true`, the field is no longer editable and will not be saved + * + * @return bool + */ + public function disabled(): bool + { + return $this->disabled; + } + + /** + * Runs all validations and returns an array of + * error messages + * + * @return array + */ + public function errors(): array + { + return $this->validate(); + } + + /** + * Setter for the value + * + * @param mixed $value + * @return void + */ + public function fill($value = null) + { + $this->value = $value; + } + + /** + * Optional help text below the field + * + * @return string|null + */ + public function help(): ?string + { + if (empty($this->help) === false) { + $help = $this->stringTemplate($this->help); + $help = $this->kirby()->kirbytext($help); + return $help; + } + + return null; + } + + /** + * @param string|array|null $param + * @return string|null + */ + protected function i18n($param = null): ?string + { + return empty($param) === false ? I18n::translate($param, $param) : null; + } + + /** + * Optional icon that will be shown at the end of the field + * + * @return string|null + */ + public function icon(): ?string + { + return $this->icon; + } + + /** + * @return string + */ + public function id(): string + { + return $this->name(); + } + + /** + * @return bool + */ + public function isDisabled(): bool + { + return $this->disabled; + } + + /** + * @return bool + */ + public function isEmpty(): bool + { + return $this->isEmptyValue($this->value()); + } + + /** + * @param mixed $value + * @return bool + */ + public function isEmptyValue($value = null): bool + { + return in_array($value, [null, '', []], true); + } + + /** + * Checks if the field is invalid + * + * @return bool + */ + public function isInvalid(): bool + { + return $this->isValid() === false; + } + + /** + * @return bool + */ + public function isRequired(): bool + { + return $this->required; + } + + /** + * @return bool + */ + public function isSaveable(): bool + { + return true; + } + + /** + * 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() + { + return $this->model->kirby(); + } + + /** + * The field label can be set as string or associative array with translations + * + * @return string + */ + public function label(): string + { + return $this->stringTemplate($this->label ?? Str::ucfirst($this->name())); + } + + /** + * Returns the parent model + * + * @return mixed + */ + public function model() + { + return $this->model; + } + + /** + * Returns the field name + * + * @return string + */ + public function name(): string + { + return $this->name ?? $this->type(); + } + + /** + * Checks if the field needs a value before being saved; + * this is the case if all of the following requirements are met: + * - The field is saveable + * - The field is required + * - The field is currently empty + * - The field is not currently inactive because of a `when` rule + * + * @return bool + */ + protected function needsValue(): bool + { + // check simple conditions first + if ( + $this->isSaveable() === false || + $this->isRequired() === false || + $this->isEmpty() === false + ) { + return false; + } + + // check the data of the relevant fields if there is a `when` option + if (empty($this->when) === false && is_array($this->when) === true) { + $formFields = $this->siblings(); + + if ($formFields !== null) { + foreach ($this->when as $field => $value) { + $field = $formFields->get($field); + $inputValue = $field !== null ? $field->value() : ''; + + // if the input data doesn't match the requested `when` value, + // that means that this field is not required and can be saved + // (*all* `when` conditions must be met for this field to be required) + if ($inputValue !== $value) { + return false; + } + } + } + } + + // either there was no `when` condition or all conditions matched + return true; + } + + /** + * Returns all original params for the field + * + * @return array + */ + public function params(): array + { + return $this->params; + } + + /** + * Optional placeholder value that will be shown when the field is empty + * + * @return string|null + */ + public function placeholder(): ?string + { + return $this->stringTemplate($this->placeholder); + } + + /** + * Define the props that will be sent to + * the Vue component + * + * @return array + */ + public function props(): array + { + return [ + 'after' => $this->after(), + 'autofocus' => $this->autofocus(), + 'before' => $this->before(), + 'default' => $this->default(), + 'disabled' => $this->isDisabled(), + 'help' => $this->help(), + 'icon' => $this->icon(), + 'label' => $this->label(), + 'name' => $this->name(), + 'placeholder' => $this->placeholder(), + 'required' => $this->isRequired(), + 'saveable' => $this->isSaveable(), + 'translate' => $this->translate(), + 'type' => $this->type(), + 'when' => $this->when(), + 'width' => $this->width(), + ]; + } + + /** + * If `true`, the field has to be filled in correctly to be saved. + * + * @return bool + */ + public function required(): bool + { + return $this->required; + } + + /** + * Routes for the field API + * + * @return array + */ + public function routes(): array + { + return []; + } + + /** + * @deprecated 3.5.0 + * @todo remove when the general field class setup has been refactored + * @return bool + */ + public function save() + { + return $this->isSaveable(); + } + + /** + * @param array|string|null $after + * @return void + */ + protected function setAfter($after = null) + { + $this->after = $this->i18n($after); + } + + /** + * @param bool $autofocus + * @return void + */ + protected function setAutofocus(bool $autofocus = false) + { + $this->autofocus = $autofocus; + } + + /** + * @param array|string|null $before + * @return void + */ + protected function setBefore($before = null) + { + $this->before = $this->i18n($before); + } + + /** + * @param mixed $default + * @return void + */ + protected function setDefault($default = null) + { + $this->default = $default; + } + + /** + * @param bool $disabled + * @return void + */ + protected function setDisabled(bool $disabled = false) + { + $this->disabled = $disabled; + } + + /** + * @param array|string|null $help + * @return void + */ + protected function setHelp($help = null) + { + $this->help = $this->i18n($help); + } + + /** + * @param string|null $icon + * @return void + */ + protected function setIcon(?string $icon = null) + { + $this->icon = $icon; + } + + /** + * @param array|string|null $label + * @return void + */ + protected function setLabel($label = null) + { + $this->label = $this->i18n($label); + } + + /** + * @param \Kirby\Cms\ModelWithContent $model + * @return void + */ + protected function setModel(ModelWithContent $model) + { + $this->model = $model; + } + + /** + * @param string|null $name + * @return void + */ + protected function setName(string $name = null) + { + $this->name = $name; + } + + /** + * @param array|string|null $placeholder + * @return void + */ + protected function setPlaceholder($placeholder = null) + { + $this->placeholder = $this->i18n($placeholder); + } + + /** + * @param bool $required + * @return void + */ + protected function setRequired(bool $required = false) + { + $this->required = $required; + } + + /** + * @param \Kirby\Form\Fields|null $siblings + * @return void + */ + protected function setSiblings(?Fields $siblings = null) + { + $this->siblings = $siblings ?? new Fields([$this]); + } + + /** + * @param bool $translate + * @return void + */ + protected function setTranslate(bool $translate = true) + { + $this->translate = $translate; + } + + /** + * Setter for the when condition + * + * @param mixed $when + * @return void + */ + protected function setWhen($when = null) + { + $this->when = $when; + } + + /** + * Setter for the field width + * + * @param string|null $width + * @return void + */ + protected function setWidth(string $width = null) + { + $this->width = $width; + } + + /** + * Returns all sibling fields + * + * @return \Kirby\Form\Fields + */ + protected function siblingsCollection() + { + return $this->siblings; + } + + /** + * Parses a string template in the given value + * + * @param string|null $string + * @return string|null + */ + protected function stringTemplate(?string $string = null): ?string + { + if ($string !== null) { + return $this->model->toString($string); + } + + return null; + } + + /** + * Converts the given value to a value + * that can be stored in the text file + * + * @param mixed $value + * @return mixed + */ + public function store($value) + { + return $value; + } + + /** + * Should the field be translatable? + * + * @return bool + */ + public function translate(): bool + { + return $this->translate; + } + + /** + * Converts the field to a plain array + * + * @return array + */ + public function toArray(): array + { + $props = $this->props(); + $props['signature'] = md5(json_encode($props)); + + ksort($props); + + return array_filter($props, fn ($item) => $item !== null); + } + + /** + * Returns the field type + * + * @return string + */ + public function type(): string + { + return lcfirst(basename(str_replace(['\\', 'Field'], ['/', ''], static::class))); + } + + /** + * Runs the validations defined for the field + * + * @return array + */ + protected function validate(): array + { + $validations = $this->validations(); + $value = $this->value(); + $errors = []; + + // validate required values + if ($this->needsValue() === true) { + $errors['required'] = I18n::translate('error.validation.required'); + } + + foreach ($validations as $key => $validation) { + if (is_int($key) === true) { + // predefined validation + try { + Validations::$validation($this, $value); + } catch (Exception $e) { + $errors[$validation] = $e->getMessage(); + } + continue; + } + + if (is_a($validation, 'Closure') === true) { + try { + $validation->call($this, $value); + } catch (Exception $e) { + $errors[$key] = $e->getMessage(); + } + } + } + + return $errors; + } + + /** + * Defines all validation rules + * + * @return array + */ + protected function validations(): array + { + return []; + } + + /** + * Returns the value of the field if saveable + * otherwise it returns null + * + * @return mixed + */ + public function value(bool $default = false) + { + if ($this->isSaveable() === false) { + return null; + } + + if ($default === true && $this->isEmpty() === true) { + return $this->default(); + } + + return $this->value; + } + + /** + * @param mixed $value + * @return array + */ + protected function valueFromJson($value): array + { + try { + return Data::decode($value, 'json'); + } catch (Throwable $e) { + return []; + } + } + + /** + * @param mixed $value + * @return array + */ + protected function valueFromYaml($value): array + { + return Data::decode($value, 'yaml'); + } + + /** + * @param array|null $value + * @param bool $pretty + * @return string + */ + protected function valueToJson(array $value = null, bool $pretty = false): string + { + if ($pretty === true) { + return json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + } + + return json_encode($value); + } + + /** + * @param array|null $value + * @return string + */ + protected function valueToYaml(array $value = null): string + { + return Data::encode($value, 'yaml'); + } + + /** + * Conditions when the field will be shown + * + * @return array|null + */ + public function when(): ?array + { + return $this->when; + } + + /** + * Returns the width of the field in + * the Panel grid + * + * @return string + */ + public function width(): string + { + return $this->width ?? '1/1'; + } } diff --git a/kirby/src/Form/Fields.php b/kirby/src/Form/Fields.php index b6b3e36..9abd199 100755 --- a/kirby/src/Form/Fields.php +++ b/kirby/src/Form/Fields.php @@ -16,42 +16,42 @@ use Kirby\Toolkit\Collection; */ class Fields extends Collection { - /** - * Internal setter for each object in the Collection. - * This takes care of validation and of setting - * the collection prop on each object correctly. - * - * @param string $name - * @param object|array $field - * @return $this - */ - public function __set(string $name, $field) - { - if (is_array($field) === true) { - // use the array key as name if the name is not set - $field['name'] ??= $name; - $field = Field::factory($field['type'], $field, $this); - } + /** + * Internal setter for each object in the Collection. + * This takes care of validation and of setting + * the collection prop on each object correctly. + * + * @param string $name + * @param object|array $field + * @return void + */ + public function __set(string $name, $field): void + { + if (is_array($field) === true) { + // use the array key as name if the name is not set + $field['name'] ??= $name; + $field = Field::factory($field['type'], $field, $this); + } - return parent::__set($field->name(), $field); - } + parent::__set($field->name(), $field); + } - /** - * Converts the fields collection to an - * array and also does that for every - * included field. - * - * @param \Closure|null $map - * @return array - */ - public function toArray(Closure $map = null): array - { - $array = []; + /** + * Converts the fields collection to an + * array and also does that for every + * included field. + * + * @param \Closure|null $map + * @return array + */ + public function toArray(Closure $map = null): array + { + $array = []; - foreach ($this as $field) { - $array[$field->name()] = $field->toArray(); - } + foreach ($this as $field) { + $array[$field->name()] = $field->toArray(); + } - return $array; - } + return $array; + } } diff --git a/kirby/src/Form/Form.php b/kirby/src/Form/Form.php index e77006b..e6445e7 100755 --- a/kirby/src/Form/Form.php +++ b/kirby/src/Form/Form.php @@ -23,373 +23,373 @@ use Throwable; */ class Form { - /** - * An array of all found errors - * - * @var array|null - */ - protected $errors; + /** + * An array of all found errors + * + * @var array|null + */ + protected $errors; - /** - * Fields in the form - * - * @var \Kirby\Form\Fields|null - */ - protected $fields; + /** + * Fields in the form + * + * @var \Kirby\Form\Fields|null + */ + protected $fields; - /** - * All values of form - * - * @var array - */ - protected $values = []; + /** + * All values of form + * + * @var array + */ + protected $values = []; - /** - * Form constructor - * - * @param array $props - */ - public function __construct(array $props) - { - $fields = $props['fields'] ?? []; - $values = $props['values'] ?? []; - $input = $props['input'] ?? []; - $strict = $props['strict'] ?? false; - $inject = $props; + /** + * Form constructor + * + * @param array $props + */ + public function __construct(array $props) + { + $fields = $props['fields'] ?? []; + $values = $props['values'] ?? []; + $input = $props['input'] ?? []; + $strict = $props['strict'] ?? false; + $inject = $props; - // prepare field properties for multilang setups - $fields = static::prepareFieldsForLanguage( - $fields, - $props['language'] ?? null - ); + // prepare field properties for multilang setups + $fields = static::prepareFieldsForLanguage( + $fields, + $props['language'] ?? null + ); - // lowercase all value names - $values = array_change_key_case($values); - $input = array_change_key_case($input); + // lowercase all value names + $values = array_change_key_case($values); + $input = array_change_key_case($input); - unset($inject['fields'], $inject['values'], $inject['input']); + unset($inject['fields'], $inject['values'], $inject['input']); - $this->fields = new Fields(); - $this->values = []; + $this->fields = new Fields(); + $this->values = []; - foreach ($fields as $name => $props) { + foreach ($fields as $name => $props) { - // inject stuff from the form constructor (model, etc.) - $props = array_merge($inject, $props); + // inject stuff from the form constructor (model, etc.) + $props = array_merge($inject, $props); - // inject the name - $props['name'] = $name = strtolower($name); + // inject the name + $props['name'] = $name = strtolower($name); - // check if the field is disabled - $disabled = $props['disabled'] ?? false; + // check if the field is disabled + $disabled = $props['disabled'] ?? false; - // overwrite the field value if not set - if ($disabled === true) { - $props['value'] = $values[$name] ?? null; - } else { - $props['value'] = $input[$name] ?? $values[$name] ?? null; - } + // overwrite the field value if not set + if ($disabled === true) { + $props['value'] = $values[$name] ?? null; + } else { + $props['value'] = $input[$name] ?? $values[$name] ?? null; + } - try { - $field = Field::factory($props['type'], $props, $this->fields); - } catch (Throwable $e) { - $field = static::exceptionField($e, $props); - } + try { + $field = Field::factory($props['type'], $props, $this->fields); + } catch (Throwable $e) { + $field = static::exceptionField($e, $props); + } - if ($field->save() !== false) { - $this->values[$name] = $field->value(); - } + if ($field->save() !== false) { + $this->values[$name] = $field->value(); + } - $this->fields->append($name, $field); - } + $this->fields->append($name, $field); + } - if ($strict !== true) { + if ($strict !== true) { - // use all given values, no matter - // if there's a field or not. - $input = array_merge($values, $input); + // use all given values, no matter + // if there's a field or not. + $input = array_merge($values, $input); - foreach ($input as $key => $value) { - if (isset($this->values[$key]) === false) { - $this->values[$key] = $value; - } - } - } - } + foreach ($input as $key => $value) { + if (isset($this->values[$key]) === false) { + $this->values[$key] = $value; + } + } + } + } - /** - * 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 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; + /** + * 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; - foreach ($this->fields as $field) { - if ($field->save() === false || $field->unset() === true) { - if ($includeNulls === true) { - $data[$field->name()] = null; - } else { - unset($data[$field->name()]); - } - } else { - $data[$field->name()] = $field->data($defaults); - } - } + foreach ($this->fields as $field) { + if ($field->save() === false || $field->unset() === true) { + if ($includeNulls === true) { + $data[$field->name()] = null; + } else { + unset($data[$field->name()]); + } + } else { + $data[$field->name()] = $field->data($defaults); + } + } - return $data; - } + return $data; + } - /** - * An array of all found errors - * - * @return array - */ - public function errors(): array - { - if ($this->errors !== null) { - return $this->errors; - } + /** + * An array of all found errors + * + * @return array + */ + public function errors(): array + { + if ($this->errors !== null) { + return $this->errors; + } - $this->errors = []; + $this->errors = []; - foreach ($this->fields as $field) { - if (empty($field->errors()) === false) { - $this->errors[$field->name()] = [ - 'label' => $field->label(), - 'message' => $field->errors() - ]; - } - } + foreach ($this->fields as $field) { + if (empty($field->errors()) === false) { + $this->errors[$field->name()] = [ + 'label' => $field->label(), + 'message' => $field->errors() + ]; + } + } - return $this->errors; - } + 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 = []) - { - $message = $exception->getMessage(); + /** + * Shows the error with the field + * + * @param \Throwable $exception + * @param array $props + * @return \Kirby\Form\Field + */ + public static function exceptionField(Throwable $exception, array $props = []) + { + $message = $exception->getMessage(); - if (App::instance()->option('debug') === true) { - $message .= ' in file: ' . $exception->getFile() . ' line: ' . $exception->getLine(); - } + if (App::instance()->option('debug') === true) { + $message .= ' in file: ' . $exception->getFile() . ' line: ' . $exception->getLine(); + } - $props = array_merge($props, [ - 'label' => 'Error in "' . $props['name'] . '" field.', - 'theme' => 'negative', - 'text' => strip_tags($message), - ]); + $props = array_merge($props, [ + 'label' => 'Error in "' . $props['name'] . '" field.', + 'theme' => 'negative', + 'text' => strip_tags($message), + ]); - return Field::factory('info', $props); - } + return Field::factory('info', $props); + } - /** - * Get the field object by name - * and handle nested fields correctly - * - * @param string $name - * @throws \Kirby\Exception\NotFoundException - * @return \Kirby\Form\Field - */ - public function field(string $name) - { - $form = $this; - $fieldNames = Str::split($name, '+'); - $index = 0; - $count = count($fieldNames); - $field = null; + /** + * Get the field object by name + * and handle nested fields correctly + * + * @param string $name + * @throws \Kirby\Exception\NotFoundException + * @return \Kirby\Form\Field + */ + public function field(string $name) + { + $form = $this; + $fieldNames = Str::split($name, '+'); + $index = 0; + $count = count($fieldNames); + $field = null; - foreach ($fieldNames as $fieldName) { - $index++; + foreach ($fieldNames as $fieldName) { + $index++; - if ($field = $form->fields()->get($fieldName)) { - if ($count !== $index) { - $form = $field->form(); - } - } else { - throw new NotFoundException('The field "' . $fieldName . '" could not be found'); - } - } + if ($field = $form->fields()->get($fieldName)) { + if ($count !== $index) { + $form = $field->form(); + } + } else { + throw new NotFoundException('The field "' . $fieldName . '" could not be found'); + } + } - // it can get this error only if $name is an empty string as $name = '' - if ($field === null) { - throw new NotFoundException('No field could be loaded'); - } + // it can get this error only if $name is an empty string as $name = '' + if ($field === null) { + throw new NotFoundException('No field could be loaded'); + } - return $field; - } + return $field; + } - /** - * Returns form fields - * - * @return \Kirby\Form\Fields|null - */ - public function fields() - { - return $this->fields; - } + /** + * Returns form fields + * + * @return \Kirby\Form\Fields|null + */ + public function fields() + { + return $this->fields; + } - /** - * @param \Kirby\Cms\Model $model - * @param array $props - * @return static - */ - public static function for(Model $model, array $props = []) - { - // get the original model data - $original = $model->content($props['language'] ?? null)->toArray(); - $values = $props['values'] ?? []; + /** + * @param \Kirby\Cms\Model $model + * @param array $props + * @return static + */ + public static function for(Model $model, array $props = []) + { + // get the original model data + $original = $model->content($props['language'] ?? null)->toArray(); + $values = $props['values'] ?? []; - // convert closures to values - foreach ($values as $key => $value) { - if (is_a($value, 'Closure') === true) { - $values[$key] = $value($original[$key] ?? null); - } - } + // convert closures to values + foreach ($values as $key => $value) { + if (is_a($value, 'Closure') === true) { + $values[$key] = $value($original[$key] ?? null); + } + } - // set a few defaults - $props['values'] = array_merge($original, $values); - $props['fields'] ??= []; - $props['model'] = $model; + // set a few defaults + $props['values'] = array_merge($original, $values); + $props['fields'] ??= []; + $props['model'] = $model; - // search for the blueprint - if (method_exists($model, 'blueprint') === true && $blueprint = $model->blueprint()) { - $props['fields'] = $blueprint->fields(); - } + // search for the blueprint + if (method_exists($model, 'blueprint') === true && $blueprint = $model->blueprint()) { + $props['fields'] = $blueprint->fields(); + } - $ignoreDisabled = $props['ignoreDisabled'] ?? false; + $ignoreDisabled = $props['ignoreDisabled'] ?? false; - // REFACTOR: this could be more elegant - if ($ignoreDisabled === true) { - $props['fields'] = array_map(function ($field) { - $field['disabled'] = false; - return $field; - }, $props['fields']); - } + // REFACTOR: this could be more elegant + if ($ignoreDisabled === true) { + $props['fields'] = array_map(function ($field) { + $field['disabled'] = false; + return $field; + }, $props['fields']); + } - return new static($props); - } + return new static($props); + } - /** - * Checks if the form is invalid - * - * @return bool - */ - public function isInvalid(): bool - { - return empty($this->errors()) === false; - } + /** + * 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; - } + /** + * Checks if the form is valid + * + * @return bool + */ + public function isValid(): bool + { + return empty($this->errors()) === true; + } - /** - * Disables fields in secondary languages when - * they are configured to be untranslatable - * - * @param array $fields - * @param string|null $language - * @return array - */ - protected static function prepareFieldsForLanguage(array $fields, ?string $language = null): array - { - $kirby = App::instance(null, true); + /** + * Disables fields in secondary languages when + * they are configured to be untranslatable + * + * @param array $fields + * @param string|null $language + * @return array + */ + protected static function prepareFieldsForLanguage(array $fields, ?string $language = null): array + { + $kirby = App::instance(null, true); - // only modify the fields if we have a valid Kirby multilang instance - if (!$kirby || $kirby->multilang() === false) { - return $fields; - } + // only modify the fields if we have a valid Kirby multilang instance + if (!$kirby || $kirby->multilang() === false) { + return $fields; + } - if ($language === null) { - $language = $kirby->language()->code(); - } + if ($language === null) { + $language = $kirby->language()->code(); + } - if ($language !== $kirby->defaultLanguage()->code()) { - foreach ($fields as $fieldName => $fieldProps) { - // switch untranslatable fields to readonly - if (($fieldProps['translate'] ?? true) === false) { - $fields[$fieldName]['unset'] = true; - $fields[$fieldName]['disabled'] = true; - } - } - } + if ($language !== $kirby->defaultLanguage()->code()) { + foreach ($fields as $fieldName => $fieldProps) { + // switch untranslatable fields to readonly + if (($fieldProps['translate'] ?? true) === false) { + $fields[$fieldName]['unset'] = true; + $fields[$fieldName]['disabled'] = true; + } + } + } - return $fields; - } + return $fields; + } - /** - * Converts the data of fields to strings - * - * @param false $defaults - * @return array - */ - public function strings($defaults = false): array - { - $strings = []; + /** + * Converts the data of fields to strings + * + * @param false $defaults + * @return array + */ + public function strings($defaults = false): array + { + $strings = []; - foreach ($this->data($defaults) as $key => $value) { - if ($value === null) { - $strings[$key] = null; - } elseif (is_array($value) === true) { - $strings[$key] = Data::encode($value, 'yaml'); - } else { - $strings[$key] = $value; - } - } + foreach ($this->data($defaults) as $key => $value) { + if ($value === null) { + $strings[$key] = null; + } elseif (is_array($value) === true) { + $strings[$key] = Data::encode($value, 'yaml'); + } else { + $strings[$key] = $value; + } + } - return $strings; - } + return $strings; + } - /** - * Converts the form to a plain array - * - * @return array - */ - public function toArray(): array - { - $array = [ - 'errors' => $this->errors(), - 'fields' => $this->fields->toArray(fn ($item) => $item->toArray()), - 'invalid' => $this->isInvalid() - ]; + /** + * Converts the form to a plain array + * + * @return array + */ + public function toArray(): array + { + $array = [ + 'errors' => $this->errors(), + 'fields' => $this->fields->toArray(fn ($item) => $item->toArray()), + 'invalid' => $this->isInvalid() + ]; - return $array; - } + return $array; + } - /** - * Returns form values - * - * @return array - */ - public function values(): array - { - return $this->values; - } + /** + * Returns form values + * + * @return array + */ + public function values(): array + { + return $this->values; + } } diff --git a/kirby/src/Form/Mixin/EmptyState.php b/kirby/src/Form/Mixin/EmptyState.php index 14b2c36..782acaa 100755 --- a/kirby/src/Form/Mixin/EmptyState.php +++ b/kirby/src/Form/Mixin/EmptyState.php @@ -4,15 +4,15 @@ namespace Kirby\Form\Mixin; trait EmptyState { - protected $empty; + protected $empty; - protected function setEmpty($empty = null) - { - $this->empty = $this->i18n($empty); - } + protected function setEmpty($empty = null) + { + $this->empty = $this->i18n($empty); + } - public function empty(): ?string - { - return $this->stringTemplate($this->empty); - } + public function empty(): ?string + { + return $this->stringTemplate($this->empty); + } } diff --git a/kirby/src/Form/Mixin/Max.php b/kirby/src/Form/Mixin/Max.php index 42b9ffb..b02825e 100755 --- a/kirby/src/Form/Mixin/Max.php +++ b/kirby/src/Form/Mixin/Max.php @@ -4,15 +4,15 @@ namespace Kirby\Form\Mixin; trait Max { - protected $max; + protected $max; - public function max(): ?int - { - return $this->max; - } + public function max(): ?int + { + return $this->max; + } - protected function setMax(int $max = null) - { - $this->max = $max; - } + protected function setMax(int $max = null) + { + $this->max = $max; + } } diff --git a/kirby/src/Form/Mixin/Min.php b/kirby/src/Form/Mixin/Min.php index 7bf6585..46a8d87 100755 --- a/kirby/src/Form/Mixin/Min.php +++ b/kirby/src/Form/Mixin/Min.php @@ -4,15 +4,15 @@ namespace Kirby\Form\Mixin; trait Min { - protected $min; + protected $min; - public function min(): ?int - { - return $this->min; - } + public function min(): ?int + { + return $this->min; + } - protected function setMin(int $min = null) - { - $this->min = $min; - } + protected function setMin(int $min = null) + { + $this->min = $min; + } } diff --git a/kirby/src/Form/Options.php b/kirby/src/Form/Options.php index 1e61e0d..4873b88 100755 --- a/kirby/src/Form/Options.php +++ b/kirby/src/Form/Options.php @@ -19,192 +19,192 @@ use Kirby\Toolkit\I18n; */ class Options { - /** - * Returns the classes of predefined Kirby objects - * - * @return array - */ - protected static function aliases(): array - { - return [ - 'Kirby\Cms\File' => 'file', - 'Kirby\Toolkit\Obj' => 'arrayItem', - 'Kirby\Cms\Block' => 'block', - 'Kirby\Cms\Page' => 'page', - 'Kirby\Cms\StructureObject' => 'structureItem', - 'Kirby\Cms\User' => 'user', - ]; - } + /** + * Returns the classes of predefined Kirby objects + * + * @return array + */ + protected static function aliases(): array + { + return [ + 'Kirby\Cms\File' => 'file', + 'Kirby\Toolkit\Obj' => 'arrayItem', + 'Kirby\Cms\Block' => 'block', + 'Kirby\Cms\Page' => 'page', + 'Kirby\Cms\StructureObject' => 'structureItem', + 'Kirby\Cms\User' => 'user', + ]; + } - /** - * Brings options through api - * - * @param $api - * @param \Kirby\Cms\Model|null $model - * @return array - */ - public static function api($api, $model = null): array - { - $model ??= App::instance()->site(); - $fetch = null; - $text = null; - $value = null; + /** + * Brings options through api + * + * @param $api + * @param \Kirby\Cms\Model|null $model + * @return array + */ + public static function api($api, $model = null): array + { + $model ??= App::instance()->site(); + $fetch = null; + $text = null; + $value = null; - if (is_array($api) === true) { - $fetch = $api['fetch'] ?? null; - $text = $api['text'] ?? null; - $value = $api['value'] ?? null; - $url = $api['url'] ?? null; - } else { - $url = $api; - } + if (is_array($api) === true) { + $fetch = $api['fetch'] ?? null; + $text = $api['text'] ?? null; + $value = $api['value'] ?? null; + $url = $api['url'] ?? null; + } else { + $url = $api; + } - $optionsApi = new OptionsApi([ - 'data' => static::data($model), - 'fetch' => $fetch, - 'url' => $url, - 'text' => $text, - 'value' => $value - ]); + $optionsApi = new OptionsApi([ + 'data' => static::data($model), + 'fetch' => $fetch, + 'url' => $url, + 'text' => $text, + 'value' => $value + ]); - return $optionsApi->options(); - } + return $optionsApi->options(); + } - /** - * @param \Kirby\Cms\Model $model - * @return array - */ - protected static function data($model): array - { - $kirby = $model->kirby(); + /** + * @param \Kirby\Cms\Model $model + * @return array + */ + protected static function data($model): array + { + $kirby = $model->kirby(); - // default data setup - $data = [ - 'kirby' => $kirby, - 'site' => $kirby->site(), - 'users' => $kirby->users(), - ]; + // default data setup + $data = [ + 'kirby' => $kirby, + 'site' => $kirby->site(), + 'users' => $kirby->users(), + ]; - // add the model by the proper alias - foreach (static::aliases() as $className => $alias) { - if (is_a($model, $className) === true) { - $data[$alias] = $model; - } - } + // add the model by the proper alias + foreach (static::aliases() as $className => $alias) { + if (is_a($model, $className) === true) { + $data[$alias] = $model; + } + } - return $data; - } + return $data; + } - /** - * Brings options by supporting both api and query - * - * @param $options - * @param array $props - * @param \Kirby\Cms\Model|null $model - * @return array - */ - public static function factory($options, array $props = [], $model = null): array - { - switch ($options) { - case 'api': - $options = static::api($props['api'], $model); - break; - case 'query': - $options = static::query($props['query'], $model); - break; - case 'children': - case 'grandChildren': - case 'siblings': - case 'index': - case 'files': - case 'images': - case 'documents': - case 'videos': - case 'audio': - case 'code': - case 'archives': - $options = static::query('page.' . $options, $model); - break; - case 'pages': - $options = static::query('site.index', $model); - break; - } + /** + * Brings options by supporting both api and query + * + * @param $options + * @param array $props + * @param \Kirby\Cms\Model|null $model + * @return array + */ + public static function factory($options, array $props = [], $model = null): array + { + switch ($options) { + case 'api': + $options = static::api($props['api'], $model); + break; + case 'query': + $options = static::query($props['query'], $model); + break; + case 'children': + case 'grandChildren': + case 'siblings': + case 'index': + case 'files': + case 'images': + case 'documents': + case 'videos': + case 'audio': + case 'code': + case 'archives': + $options = static::query('page.' . $options, $model); + break; + case 'pages': + $options = static::query('site.index', $model); + break; + } - if (is_array($options) === false) { - return []; - } + if (is_array($options) === false) { + return []; + } - $result = []; + $result = []; - foreach ($options as $key => $option) { - if (is_array($option) === false || isset($option['value']) === false) { - $option = [ - 'value' => is_int($key) ? $option : $key, - 'text' => $option - ]; - } + foreach ($options as $key => $option) { + if (is_array($option) === false || isset($option['value']) === false) { + $option = [ + 'value' => is_int($key) ? $option : $key, + 'text' => $option + ]; + } - // fallback for the text - $option['text'] ??= $option['value']; + // fallback for the text + $option['text'] ??= $option['value']; - // translate the option text - if (is_array($option['text']) === true) { - $option['text'] = I18n::translate($option['text'], $option['text']); - } + // translate the option text + if (is_array($option['text']) === true) { + $option['text'] = I18n::translate($option['text'], $option['text']); + } - // add the option to the list - $result[] = $option; - } + // add the option to the list + $result[] = $option; + } - return $result; - } + return $result; + } - /** - * Brings options with query - * - * @param $query - * @param \Kirby\Cms\Model|null $model - * @return array - */ - public static function query($query, $model = null): array - { - $model ??= App::instance()->site(); + /** + * Brings options with query + * + * @param $query + * @param \Kirby\Cms\Model|null $model + * @return array + */ + public static function query($query, $model = null): array + { + $model ??= App::instance()->site(); - // default text setup - $text = [ - 'arrayItem' => '{{ arrayItem.value }}', - 'block' => '{{ block.type }}: {{ block.id }}', - 'file' => '{{ file.filename }}', - 'page' => '{{ page.title }}', - 'structureItem' => '{{ structureItem.title }}', - 'user' => '{{ user.username }}', - ]; + // default text setup + $text = [ + 'arrayItem' => '{{ arrayItem.value }}', + 'block' => '{{ block.type }}: {{ block.id }}', + 'file' => '{{ file.filename }}', + 'page' => '{{ page.title }}', + 'structureItem' => '{{ structureItem.title }}', + 'user' => '{{ user.username }}', + ]; - // default value setup - $value = [ - 'arrayItem' => '{{ arrayItem.value }}', - 'block' => '{{ block.id }}', - 'file' => '{{ file.id }}', - 'page' => '{{ page.id }}', - 'structureItem' => '{{ structureItem.id }}', - 'user' => '{{ user.email }}', - ]; + // default value setup + $value = [ + 'arrayItem' => '{{ arrayItem.value }}', + 'block' => '{{ block.id }}', + 'file' => '{{ file.id }}', + 'page' => '{{ page.id }}', + 'structureItem' => '{{ structureItem.id }}', + 'user' => '{{ user.email }}', + ]; - // resolve array query setup - if (is_array($query) === true) { - $text = $query['text'] ?? $text; - $value = $query['value'] ?? $value; - $query = $query['fetch'] ?? null; - } + // resolve array query setup + if (is_array($query) === true) { + $text = $query['text'] ?? $text; + $value = $query['value'] ?? $value; + $query = $query['fetch'] ?? null; + } - $optionsQuery = new OptionsQuery([ - 'aliases' => static::aliases(), - 'data' => static::data($model), - 'query' => $query, - 'text' => $text, - 'value' => $value - ]); + $optionsQuery = new OptionsQuery([ + 'aliases' => static::aliases(), + 'data' => static::data($model), + 'query' => $query, + 'text' => $text, + 'value' => $value + ]); - return $optionsQuery->options(); - } + return $optionsQuery->options(); + } } diff --git a/kirby/src/Form/OptionsApi.php b/kirby/src/Form/OptionsApi.php index 826e6f6..c4df0b4 100755 --- a/kirby/src/Form/OptionsApi.php +++ b/kirby/src/Form/OptionsApi.php @@ -23,220 +23,220 @@ use Kirby\Toolkit\Str; */ class OptionsApi { - use Properties; + use Properties; - /** - * @var array - */ - protected $data; + /** + * @var array + */ + protected $data; - /** - * @var string|null - */ - protected $fetch; + /** + * @var string|null + */ + protected $fetch; - /** - * @var array|string|null - */ - protected $options; + /** + * @var array|string|null + */ + protected $options; - /** - * @var string - */ - protected $text = '{{ item.value }}'; + /** + * @var string + */ + protected $text = '{{ item.value }}'; - /** - * @var string - */ - protected $url; + /** + * @var string + */ + protected $url; - /** - * @var string - */ - protected $value = '{{ item.key }}'; + /** + * @var string + */ + protected $value = '{{ item.key }}'; - /** - * OptionsApi constructor - * - * @param array $props - */ - public function __construct(array $props) - { - $this->setProperties($props); - } + /** + * OptionsApi constructor + * + * @param array $props + */ + public function __construct(array $props) + { + $this->setProperties($props); + } - /** - * @return array - */ - public function data(): array - { - return $this->data; - } + /** + * @return array + */ + public function data(): array + { + return $this->data; + } - /** - * @return mixed - */ - public function fetch() - { - return $this->fetch; - } + /** + * @return mixed + */ + public function fetch() + { + return $this->fetch; + } - /** - * @param string $field - * @param array $data - * @return string - */ - protected function field(string $field, array $data): string - { - $value = $this->$field(); - return Str::safeTemplate($value, $data); - } + /** + * @param string $field + * @param array $data + * @return string + */ + protected function field(string $field, array $data): string + { + $value = $this->$field(); + return Str::safeTemplate($value, $data); + } - /** - * @return array - * @throws \Exception - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function options(): array - { - if (is_array($this->options) === true) { - return $this->options; - } + /** + * @return array + * @throws \Exception + * @throws \Kirby\Exception\InvalidArgumentException + */ + public function options(): array + { + if (is_array($this->options) === true) { + return $this->options; + } - if (Url::isAbsolute($this->url()) === true) { - // URL, request via cURL - $data = Remote::get($this->url())->json(); - } else { - // local file, get contents locally + if (Url::isAbsolute($this->url()) === true) { + // URL, request via cURL + $data = Remote::get($this->url())->json(); + } else { + // local file, get contents locally - // ensure the file exists before trying to load it as the - // file_get_contents() warnings need to be suppressed - if (is_file($this->url()) !== true) { - throw new Exception('Local file ' . $this->url() . ' was not found'); - } + // ensure the file exists before trying to load it as the + // file_get_contents() warnings need to be suppressed + if (is_file($this->url()) !== true) { + throw new Exception('Local file ' . $this->url() . ' was not found'); + } - $content = @file_get_contents($this->url()); + $content = @file_get_contents($this->url()); - if (is_string($content) !== true) { - throw new Exception('Unexpected read error'); // @codeCoverageIgnore - } + if (is_string($content) !== true) { + throw new Exception('Unexpected read error'); // @codeCoverageIgnore + } - if (empty($content) === true) { - return []; - } + if (empty($content) === true) { + return []; + } - $data = json_decode($content, true); - } + $data = json_decode($content, true); + } - if (is_array($data) === false) { - throw new InvalidArgumentException('Invalid options format'); - } + if (is_array($data) === false) { + throw new InvalidArgumentException('Invalid options format'); + } - $result = (new Query($this->fetch(), Nest::create($data)))->result(); - $options = []; + $result = (new Query($this->fetch(), Nest::create($data)))->result(); + $options = []; - foreach ($result as $item) { - $data = array_merge($this->data(), ['item' => $item]); + foreach ($result as $item) { + $data = array_merge($this->data(), ['item' => $item]); - $options[] = [ - 'text' => $this->field('text', $data), - 'value' => $this->field('value', $data), - ]; - } + $options[] = [ + 'text' => $this->field('text', $data), + 'value' => $this->field('value', $data), + ]; + } - return $options; - } + return $options; + } - /** - * @param array $data - * @return $this - */ - protected function setData(array $data) - { - $this->data = $data; - return $this; - } + /** + * @param array $data + * @return $this + */ + protected function setData(array $data) + { + $this->data = $data; + return $this; + } - /** - * @param string|null $fetch - * @return $this - */ - protected function setFetch(?string $fetch = null) - { - $this->fetch = $fetch; - return $this; - } + /** + * @param string|null $fetch + * @return $this + */ + protected function setFetch(?string $fetch = null) + { + $this->fetch = $fetch; + return $this; + } - /** - * @param array|string|null $options - * @return $this - */ - protected function setOptions($options = null) - { - $this->options = $options; - return $this; - } + /** + * @param array|string|null $options + * @return $this + */ + protected function setOptions($options = null) + { + $this->options = $options; + return $this; + } - /** - * @param string $text - * @return $this - */ - protected function setText(?string $text = null) - { - $this->text = $text; - return $this; - } + /** + * @param string $text + * @return $this + */ + protected function setText(?string $text = null) + { + $this->text = $text; + return $this; + } - /** - * @param string $url - * @return $this - */ - protected function setUrl(string $url) - { - $this->url = $url; - return $this; - } + /** + * @param string $url + * @return $this + */ + protected function setUrl(string $url) + { + $this->url = $url; + return $this; + } - /** - * @param string|null $value - * @return $this - */ - protected function setValue(?string $value = null) - { - $this->value = $value; - return $this; - } + /** + * @param string|null $value + * @return $this + */ + protected function setValue(?string $value = null) + { + $this->value = $value; + return $this; + } - /** - * @return string - */ - public function text(): string - { - return $this->text; - } + /** + * @return string + */ + public function text(): string + { + return $this->text; + } - /** - * @return array - * @throws \Kirby\Exception\InvalidArgumentException - */ - public function toArray(): array - { - return $this->options(); - } + /** + * @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 url(): string + { + return Str::template($this->url, $this->data()); + } - /** - * @return string - */ - public function value(): string - { - return $this->value; - } + /** + * @return string + */ + public function value(): string + { + return $this->value; + } } diff --git a/kirby/src/Form/OptionsQuery.php b/kirby/src/Form/OptionsQuery.php index cc2a620..c91ac64 100755 --- a/kirby/src/Form/OptionsQuery.php +++ b/kirby/src/Form/OptionsQuery.php @@ -25,247 +25,247 @@ use Kirby\Toolkit\Str; */ class OptionsQuery { - use Properties; + use Properties; - /** - * @var array - */ - protected $aliases = []; + /** + * @var array + */ + protected $aliases = []; - /** - * @var array - */ - protected $data; + /** + * @var array + */ + protected $data; - /** - * @var array|string|null - */ - protected $options; + /** + * @var array|string|null + */ + protected $options; - /** - * @var string - */ - protected $query; + /** + * @var string + */ + protected $query; - /** - * @var mixed - */ - protected $text; + /** + * @var mixed + */ + protected $text; - /** - * @var mixed - */ - protected $value; + /** + * @var mixed + */ + protected $value; - /** - * OptionsQuery constructor - * - * @param array $props - */ - public function __construct(array $props) - { - $this->setProperties($props); - } + /** + * 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 aliases(): array + { + return $this->aliases; + } - /** - * @return array - */ - public function data(): array - { - return $this->data; - } + /** + * @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(); + /** + * @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(); - if (is_array($value) === true) { - if (isset($value[$object]) === false) { - throw new NotFoundException('Missing "' . $field . '" definition'); - } + if (is_array($value) === true) { + if (isset($value[$object]) === false) { + throw new NotFoundException('Missing "' . $field . '" definition'); + } - $value = $value[$object]; - } + $value = $value[$object]; + } - return Str::safeTemplate($value, $data); - } + return Str::safeTemplate($value, $data); + } - /** - * @return array - */ - public function options(): array - { - if (is_array($this->options) === true) { - return $this->options; - } + /** + * @return array + */ + public function options(): array + { + if (is_array($this->options) === true) { + return $this->options; + } - $data = $this->data(); - $query = new Query($this->query(), $data); - $result = $query->result(); - $result = $this->resultToCollection($result); - $options = []; + $data = $this->data(); + $query = new Query($this->query(), $data); + $result = $query->result(); + $result = $this->resultToCollection($result); + $options = []; - foreach ($result as $item) { - $alias = $this->resolve($item); - $data = array_merge($data, [$alias => $item]); + foreach ($result as $item) { + $alias = $this->resolve($item); + $data = array_merge($data, [$alias => $item]); - $options[] = [ - 'text' => $this->template($alias, 'text', $data), - 'value' => $this->template($alias, 'value', $data) - ]; - } + $options[] = [ + 'text' => $this->template($alias, 'text', $data), + 'value' => $this->template($alias, 'value', $data) + ]; + } - return $this->options = $options; - } + return $this->options = $options; + } - /** - * @return string - */ - public function query(): string - { - return $this->query; - } + /** + * @return string + */ + public function query(): string + { + return $this->query; + } - /** - * @param $object - * @return mixed|string|null - */ - public function resolve($object) - { - // fast access - if ($alias = ($this->aliases[get_class($object)] ?? null)) { - return $alias; - } + /** + * @param $object + * @return mixed|string|null + */ + public function resolve($object) + { + // fast access + if ($alias = ($this->aliases[get_class($object)] ?? null)) { + return $alias; + } - // slow but precise resolving - foreach ($this->aliases as $className => $alias) { - if (is_a($object, $className) === true) { - return $alias; - } - } + // slow but precise resolving + foreach ($this->aliases as $className => $alias) { + if (is_a($object, $className) === true) { + return $alias; + } + } - return 'item'; - } + return 'item'; + } - /** - * @param $result - * @throws \Kirby\Exception\InvalidArgumentException - */ - protected function resultToCollection($result) - { - if (is_array($result)) { - foreach ($result as $key => $item) { - if (is_scalar($item) === true) { - $result[$key] = new Obj([ - 'key' => new Field(null, 'key', $key), - 'value' => new Field(null, 'value', $item), - ]); - } - } + /** + * @param $result + * @throws \Kirby\Exception\InvalidArgumentException + */ + protected function resultToCollection($result) + { + if (is_array($result)) { + foreach ($result as $key => $item) { + if (is_scalar($item) === true) { + $result[$key] = new Obj([ + 'key' => new Field(null, 'key', $key), + 'value' => new Field(null, 'value', $item), + ]); + } + } - $result = new Collection($result); - } + $result = new Collection($result); + } - if (is_a($result, 'Kirby\Toolkit\Collection') === false) { - throw new InvalidArgumentException('Invalid query result data'); - } + if (is_a($result, 'Kirby\Toolkit\Collection') === false) { + throw new InvalidArgumentException('Invalid query result data'); + } - return $result; - } + return $result; + } - /** - * @param array|null $aliases - * @return $this - */ - protected function setAliases(?array $aliases = null) - { - $this->aliases = $aliases; - return $this; - } + /** + * @param array|null $aliases + * @return $this + */ + protected function setAliases(?array $aliases = null) + { + $this->aliases = $aliases; + return $this; + } - /** - * @param array $data - * @return $this - */ - protected function setData(array $data) - { - $this->data = $data; - return $this; - } + /** + * @param array $data + * @return $this + */ + protected function setData(array $data) + { + $this->data = $data; + return $this; + } - /** - * @param array|string|null $options - * @return $this - */ - protected function setOptions($options = null) - { - $this->options = $options; - return $this; - } + /** + * @param array|string|null $options + * @return $this + */ + protected function setOptions($options = null) + { + $this->options = $options; + return $this; + } - /** - * @param string $query - * @return $this - */ - protected function setQuery(string $query) - { - $this->query = $query; - return $this; - } + /** + * @param string $query + * @return $this + */ + protected function setQuery(string $query) + { + $this->query = $query; + return $this; + } - /** - * @param mixed $text - * @return $this - */ - protected function setText($text) - { - $this->text = $text; - return $this; - } + /** + * @param mixed $text + * @return $this + */ + protected function setText($text) + { + $this->text = $text; + return $this; + } - /** - * @param mixed $value - * @return $this - */ - protected function setValue($value) - { - $this->value = $value; - return $this; - } + /** + * @param mixed $value + * @return $this + */ + protected function setValue($value) + { + $this->value = $value; + return $this; + } - /** - * @return mixed - */ - public function text() - { - return $this->text; - } + /** + * @return mixed + */ + public function text() + { + return $this->text; + } - public function toArray(): array - { - return $this->options(); - } + public function toArray(): array + { + return $this->options(); + } - /** - * @return mixed - */ - public function value() - { - return $this->value; - } + /** + * @return mixed + */ + public function value() + { + return $this->value; + } } diff --git a/kirby/src/Form/Validations.php b/kirby/src/Form/Validations.php index c6c5053..5834624 100755 --- a/kirby/src/Form/Validations.php +++ b/kirby/src/Form/Validations.php @@ -16,279 +16,279 @@ use Kirby\Toolkit\V; */ class Validations { - /** - * Validates if the field value is boolean - * - * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field - * @param $value - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException - */ - public static function boolean($field, $value): bool - { - if ($field->isEmpty($value) === false) { - if (is_bool($value) === false) { - throw new InvalidArgumentException([ - 'key' => 'validation.boolean' - ]); - } - } + /** + * Validates if the field value is boolean + * + * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field + * @param $value + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException + */ + public static function boolean($field, $value): bool + { + if ($field->isEmpty($value) === false) { + if (is_bool($value) === false) { + throw new InvalidArgumentException([ + 'key' => 'validation.boolean' + ]); + } + } - return true; - } + return true; + } - /** - * Validates if the field value is valid date - * - * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field - * @param $value - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException - */ - public static function date($field, $value): bool - { - if ($field->isEmpty($value) === false) { - if (V::date($value) !== true) { - throw new InvalidArgumentException( - V::message('date', $value) - ); - } - } + /** + * Validates if the field value is valid date + * + * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field + * @param $value + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException + */ + public static function date($field, $value): bool + { + if ($field->isEmpty($value) === false) { + if (V::date($value) !== true) { + throw new InvalidArgumentException( + V::message('date', $value) + ); + } + } - return true; - } + return true; + } - /** - * Validates if the field value is valid email - * - * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field - * @param $value - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException - */ - public static function email($field, $value): bool - { - if ($field->isEmpty($value) === false) { - if (V::email($value) === false) { - throw new InvalidArgumentException( - V::message('email', $value) - ); - } - } + /** + * Validates if the field value is valid email + * + * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field + * @param $value + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException + */ + public static function email($field, $value): bool + { + if ($field->isEmpty($value) === false) { + if (V::email($value) === false) { + throw new InvalidArgumentException( + V::message('email', $value) + ); + } + } - return true; - } + return true; + } - /** - * Validates if the field value is maximum - * - * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field - * @param $value - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException - */ - public static function max($field, $value): bool - { - if ($field->isEmpty($value) === false && $field->max() !== null) { - if (V::max($value, $field->max()) === false) { - throw new InvalidArgumentException( - V::message('max', $value, $field->max()) - ); - } - } + /** + * Validates if the field value is maximum + * + * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field + * @param $value + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException + */ + public static function max($field, $value): bool + { + if ($field->isEmpty($value) === false && $field->max() !== null) { + if (V::max($value, $field->max()) === false) { + throw new InvalidArgumentException( + V::message('max', $value, $field->max()) + ); + } + } - return true; - } + return true; + } - /** - * Validates if the field value is max length - * - * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field - * @param $value - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException - */ - public static function maxlength($field, $value): bool - { - if ($field->isEmpty($value) === false && $field->maxlength() !== null) { - if (V::maxLength($value, $field->maxlength()) === false) { - throw new InvalidArgumentException( - V::message('maxlength', $value, $field->maxlength()) - ); - } - } + /** + * Validates if the field value is max length + * + * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field + * @param $value + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException + */ + public static function maxlength($field, $value): bool + { + if ($field->isEmpty($value) === false && $field->maxlength() !== null) { + if (V::maxLength($value, $field->maxlength()) === false) { + throw new InvalidArgumentException( + V::message('maxlength', $value, $field->maxlength()) + ); + } + } - return true; - } + return true; + } - /** - * Validates if the field value is minimum - * - * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field - * @param $value - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException - */ - public static function min($field, $value): bool - { - if ($field->isEmpty($value) === false && $field->min() !== null) { - if (V::min($value, $field->min()) === false) { - throw new InvalidArgumentException( - V::message('min', $value, $field->min()) - ); - } - } + /** + * Validates if the field value is minimum + * + * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field + * @param $value + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException + */ + public static function min($field, $value): bool + { + if ($field->isEmpty($value) === false && $field->min() !== null) { + if (V::min($value, $field->min()) === false) { + throw new InvalidArgumentException( + V::message('min', $value, $field->min()) + ); + } + } - return true; - } + return true; + } - /** - * Validates if the field value is min length - * - * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field - * @param $value - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException - */ - public static function minlength($field, $value): bool - { - if ($field->isEmpty($value) === false && $field->minlength() !== null) { - if (V::minLength($value, $field->minlength()) === false) { - throw new InvalidArgumentException( - V::message('minlength', $value, $field->minlength()) - ); - } - } + /** + * Validates if the field value is min length + * + * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field + * @param $value + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException + */ + public static function minlength($field, $value): bool + { + if ($field->isEmpty($value) === false && $field->minlength() !== null) { + if (V::minLength($value, $field->minlength()) === false) { + throw new InvalidArgumentException( + V::message('minlength', $value, $field->minlength()) + ); + } + } - return true; - } + return true; + } - /** - * Validates if the field value matches defined pattern - * - * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field - * @param $value - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException - */ - public static function pattern($field, $value): bool - { - if ($field->isEmpty($value) === false && $field->pattern() !== null) { - if (V::match($value, '/' . $field->pattern() . '/i') === false) { - throw new InvalidArgumentException( - V::message('match') - ); - } - } + /** + * Validates if the field value matches defined pattern + * + * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field + * @param $value + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException + */ + public static function pattern($field, $value): bool + { + if ($field->isEmpty($value) === false && $field->pattern() !== null) { + if (V::match($value, '/' . $field->pattern() . '/i') === false) { + throw new InvalidArgumentException( + V::message('match') + ); + } + } - return true; - } + return true; + } - /** - * Validates if the field value is required - * - * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field - * @param $value - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException - */ - public static function required($field, $value): bool - { - if ($field->isRequired() === true && $field->save() === true && $field->isEmpty($value) === true) { - throw new InvalidArgumentException([ - 'key' => 'validation.required' - ]); - } + /** + * Validates if the field value is required + * + * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field + * @param $value + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException + */ + public static function required($field, $value): bool + { + if ($field->isRequired() === true && $field->save() === true && $field->isEmpty($value) === true) { + throw new InvalidArgumentException([ + 'key' => 'validation.required' + ]); + } - return true; - } + return true; + } - /** - * Validates if the field value is in defined options - * - * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field - * @param $value - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException - */ - public static function option($field, $value): bool - { - if ($field->isEmpty($value) === false) { - $values = array_column($field->options(), 'value'); + /** + * Validates if the field value is in defined options + * + * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field + * @param $value + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException + */ + public static function option($field, $value): bool + { + if ($field->isEmpty($value) === false) { + $values = array_column($field->options(), 'value'); - if (in_array($value, $values, true) !== true) { - throw new InvalidArgumentException([ - 'key' => 'validation.option' - ]); - } - } + if (in_array($value, $values, true) !== true) { + throw new InvalidArgumentException([ + 'key' => 'validation.option' + ]); + } + } - return true; - } + return true; + } - /** - * Validates if the field values is in defined options - * - * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field - * @param $value - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException - */ - public static function options($field, $value): bool - { - if ($field->isEmpty($value) === false) { - $values = array_column($field->options(), 'value'); - foreach ($value as $val) { - if (in_array($val, $values, true) === false) { - throw new InvalidArgumentException([ - 'key' => 'validation.option' - ]); - } - } - } + /** + * Validates if the field values is in defined options + * + * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field + * @param $value + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException + */ + public static function options($field, $value): bool + { + if ($field->isEmpty($value) === false) { + $values = array_column($field->options(), 'value'); + foreach ($value as $val) { + if (in_array($val, $values, true) === false) { + throw new InvalidArgumentException([ + 'key' => 'validation.option' + ]); + } + } + } - return true; - } + return true; + } - /** - * Validates if the field value is valid time - * - * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field - * @param $value - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException - */ - public static function time($field, $value): bool - { - if ($field->isEmpty($value) === false) { - if (V::time($value) !== true) { - throw new InvalidArgumentException( - V::message('time', $value) - ); - } - } + /** + * Validates if the field value is valid time + * + * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field + * @param $value + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException + */ + public static function time($field, $value): bool + { + if ($field->isEmpty($value) === false) { + if (V::time($value) !== true) { + throw new InvalidArgumentException( + V::message('time', $value) + ); + } + } - return true; - } + return true; + } - /** - * Validates if the field value is valid url - * - * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field - * @param $value - * @return bool - * @throws \Kirby\Exception\InvalidArgumentException - */ - public static function url($field, $value): bool - { - if ($field->isEmpty($value) === false) { - if (V::url($value) === false) { - throw new InvalidArgumentException( - V::message('url', $value) - ); - } - } + /** + * Validates if the field value is valid url + * + * @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field + * @param $value + * @return bool + * @throws \Kirby\Exception\InvalidArgumentException + */ + public static function url($field, $value): bool + { + if ($field->isEmpty($value) === false) { + if (V::url($value) === false) { + throw new InvalidArgumentException( + V::message('url', $value) + ); + } + } - return true; - } + return true; + } } diff --git a/kirby/src/Http/Cookie.php b/kirby/src/Http/Cookie.php index 71843ee..b63c606 100755 --- a/kirby/src/Http/Cookie.php +++ b/kirby/src/Http/Cookie.php @@ -17,221 +17,221 @@ use Kirby\Toolkit\Str; */ class Cookie { - /** - * Key to use for cookie signing - * @var string - */ - public static $key = 'KirbyHttpCookieKey'; + /** + * Key to use for cookie signing + * @var string + */ + public static $key = 'KirbyHttpCookieKey'; - /** - * Set a new cookie - * - * - * - * cookie::set('mycookie', 'hello', ['lifetime' => 60]); - * // expires in 1 hour - * - * - * - * @param string $key The name of the cookie - * @param string $value The cookie content - * @param array $options Array of options: - * lifetime, path, domain, secure, httpOnly, sameSite - * @return bool true: cookie was created, - * false: cookie creation failed - */ - public static function set(string $key, string $value, array $options = []): bool - { - // modify CMS caching behavior - static::trackUsage($key); + /** + * Set a new cookie + * + * + * + * cookie::set('mycookie', 'hello', ['lifetime' => 60]); + * // expires in 1 hour + * + * + * + * @param string $key The name of the cookie + * @param string $value The cookie content + * @param array $options Array of options: + * lifetime, path, domain, secure, httpOnly, sameSite + * @return bool true: cookie was created, + * false: cookie creation failed + */ + public static function set(string $key, string $value, array $options = []): bool + { + // modify CMS caching behavior + static::trackUsage($key); - // extract options - $expires = static::lifetime($options['lifetime'] ?? 0); - $path = $options['path'] ?? '/'; - $domain = $options['domain'] ?? null; - $secure = $options['secure'] ?? false; - $httponly = $options['httpOnly'] ?? true; - $samesite = $options['sameSite'] ?? 'Lax'; + // extract options + $expires = static::lifetime($options['lifetime'] ?? 0); + $path = $options['path'] ?? '/'; + $domain = $options['domain'] ?? null; + $secure = $options['secure'] ?? false; + $httponly = $options['httpOnly'] ?? true; + $samesite = $options['sameSite'] ?? 'Lax'; - // add an HMAC signature of the value - $value = static::hmac($value) . '+' . $value; + // add an HMAC signature of the value + $value = static::hmac($value) . '+' . $value; - // store that thing in the cookie global - $_COOKIE[$key] = $value; + // store that thing in the cookie global + $_COOKIE[$key] = $value; - // store the cookie - $options = compact('expires', 'path', 'domain', 'secure', 'httponly', 'samesite'); - return setcookie($key, $value, $options); - } + // store the cookie + $options = compact('expires', 'path', 'domain', 'secure', 'httponly', 'samesite'); + return setcookie($key, $value, $options); + } - /** - * Calculates the lifetime for a cookie - * - * @param int $minutes Number of minutes or timestamp - * @return int - */ - public static function lifetime(int $minutes): int - { - if ($minutes > 1000000000) { - // absolute timestamp - return $minutes; - } elseif ($minutes > 0) { - // minutes from now - return time() + ($minutes * 60); - } else { - return 0; - } - } + /** + * Calculates the lifetime for a cookie + * + * @param int $minutes Number of minutes or timestamp + * @return int + */ + public static function lifetime(int $minutes): int + { + if ($minutes > 1000000000) { + // absolute timestamp + return $minutes; + } elseif ($minutes > 0) { + // minutes from now + return time() + ($minutes * 60); + } else { + return 0; + } + } - /** - * Stores a cookie forever - * - * - * - * cookie::forever('mycookie', 'hello'); - * // never expires - * - * - * - * @param string $key The name of the cookie - * @param string $value The cookie content - * @param array $options Array of options: - * path, domain, secure, httpOnly - * @return bool true: cookie was created, - * false: cookie creation failed - */ - public static function forever(string $key, string $value, array $options = []): bool - { - // 9999-12-31 if supported (lower on 32-bit servers) - $options['lifetime'] = min(253402214400, PHP_INT_MAX); - return static::set($key, $value, $options); - } + /** + * Stores a cookie forever + * + * + * + * cookie::forever('mycookie', 'hello'); + * // never expires + * + * + * + * @param string $key The name of the cookie + * @param string $value The cookie content + * @param array $options Array of options: + * path, domain, secure, httpOnly + * @return bool true: cookie was created, + * false: cookie creation failed + */ + public static function forever(string $key, string $value, array $options = []): bool + { + // 9999-12-31 if supported (lower on 32-bit servers) + $options['lifetime'] = min(253402214400, PHP_INT_MAX); + return static::set($key, $value, $options); + } - /** - * Get a cookie value - * - * - * - * cookie::get('mycookie', 'peter'); - * // sample output: 'hello' or if the cookie is not set 'peter' - * - * - * - * @param string|null $key The name of the cookie - * @param string|null $default The default value, which should be returned - * if the cookie has not been found - * @return mixed The found value - */ - public static function get(string $key = null, string $default = null) - { - if ($key === null) { - return $_COOKIE; - } + /** + * Get a cookie value + * + * + * + * cookie::get('mycookie', 'peter'); + * // sample output: 'hello' or if the cookie is not set 'peter' + * + * + * + * @param string|null $key The name of the cookie + * @param string|null $default The default value, which should be returned + * if the cookie has not been found + * @return mixed The found value + */ + public static function get(string $key = null, string $default = null) + { + if ($key === null) { + return $_COOKIE; + } - // modify CMS caching behavior - static::trackUsage($key); + // modify CMS caching behavior + static::trackUsage($key); - $value = $_COOKIE[$key] ?? null; - return empty($value) ? $default : static::parse($value); - } + $value = $_COOKIE[$key] ?? null; + return empty($value) ? $default : static::parse($value); + } - /** - * Checks if a cookie exists - * - * @param string $key - * @return bool - */ - public static function exists(string $key): bool - { - return static::get($key) !== null; - } + /** + * Checks if a cookie exists + * + * @param string $key + * @return bool + */ + public static function exists(string $key): bool + { + return static::get($key) !== null; + } - /** - * Creates a HMAC for the cookie value - * Used as a cookie signature to prevent easy tampering with cookie data - * - * @param string $value - * @return string - */ - protected static function hmac(string $value): string - { - return hash_hmac('sha1', $value, static::$key); - } + /** + * Creates a HMAC for the cookie value + * Used as a cookie signature to prevent easy tampering with cookie data + * + * @param string $value + * @return string + */ + protected static function hmac(string $value): string + { + return hash_hmac('sha1', $value, static::$key); + } - /** - * Parses the hashed value from a cookie - * and tries to extract the value - * - * @param string $string - * @return mixed - */ - protected static function parse(string $string) - { - // if no hash-value separator is present, we can't parse the value - if (strpos($string, '+') === false) { - return null; - } + /** + * Parses the hashed value from a cookie + * and tries to extract the value + * + * @param string $string + * @return mixed + */ + protected static function parse(string $string) + { + // if no hash-value separator is present, we can't parse the value + if (strpos($string, '+') === false) { + return null; + } - // extract hash and value - $hash = Str::before($string, '+'); - $value = Str::after($string, '+'); + // extract hash and value + $hash = Str::before($string, '+'); + $value = Str::after($string, '+'); - // if the hash or the value is missing at all return null - // $value can be an empty string, $hash can't be! - if (!is_string($hash) || $hash === '' || !is_string($value)) { - return null; - } + // if the hash or the value is missing at all return null + // $value can be an empty string, $hash can't be! + if (!is_string($hash) || $hash === '' || !is_string($value)) { + return null; + } - // compare the extracted hash with the hashed value - // don't accept value if the hash is invalid - if (hash_equals(static::hmac($value), $hash) !== true) { - return null; - } + // compare the extracted hash with the hashed value + // don't accept value if the hash is invalid + if (hash_equals(static::hmac($value), $hash) !== true) { + return null; + } - return $value; - } + return $value; + } - /** - * Remove a cookie - * - * - * - * cookie::remove('mycookie'); - * // mycookie is now gone - * - * - * - * @param string $key The name of the cookie - * @return bool true: the cookie has been removed, - * false: the cookie could not be removed - */ - public static function remove(string $key): bool - { - if (isset($_COOKIE[$key])) { - unset($_COOKIE[$key]); - return setcookie($key, '', 1, '/') && setcookie($key, false); - } + /** + * Remove a cookie + * + * + * + * cookie::remove('mycookie'); + * // mycookie is now gone + * + * + * + * @param string $key The name of the cookie + * @return bool true: the cookie has been removed, + * false: the cookie could not be removed + */ + public static function remove(string $key): bool + { + if (isset($_COOKIE[$key])) { + unset($_COOKIE[$key]); + return setcookie($key, '', 1, '/') && setcookie($key, false); + } - return false; - } + return false; + } - /** - * Tells the CMS responder that the response relies on a cookie and - * its value (even if the cookie isn't set in the current request); - * this ensures that the response is only cached for visitors who don't - * have this cookie set; - * https://github.com/getkirby/kirby/issues/4423#issuecomment-1166300526 - * - * @param string $key - * @return void - */ - protected static function trackUsage(string $key): void - { - // lazily request the instance for non-CMS use cases - $kirby = App::instance(null, true); + /** + * Tells the CMS responder that the response relies on a cookie and + * its value (even if the cookie isn't set in the current request); + * this ensures that the response is only cached for visitors who don't + * have this cookie set; + * https://github.com/getkirby/kirby/issues/4423#issuecomment-1166300526 + * + * @param string $key + * @return void + */ + protected static function trackUsage(string $key): void + { + // lazily request the instance for non-CMS use cases + $kirby = App::instance(null, true); - if ($kirby) { - $kirby->response()->usesCookie($key); - } - } + if ($kirby) { + $kirby->response()->usesCookie($key); + } + } } diff --git a/kirby/src/Http/Environment.php b/kirby/src/Http/Environment.php index 386e62a..68aedd4 100755 --- a/kirby/src/Http/Environment.php +++ b/kirby/src/Http/Environment.php @@ -24,1016 +24,1105 @@ use Kirby\Toolkit\Str; */ class Environment { - /** - * Full base URL object - * - * @var \Kirby\Http\Uri - */ - protected $baseUri; + /** + * Full base URL object + * + * @var \Kirby\Http\Uri + */ + protected $baseUri; - /** - * Full base URL - * - * @var string - */ - protected $baseUrl; + /** + * Full base URL + * + * @var string + */ + protected $baseUrl; - /** - * Whether the request is being served by the CLI - * - * @var bool - */ - protected $cli; + /** + * Whether the request is being served by the CLI + * + * @var bool + */ + protected $cli; - /** - * Current host name - * - * @var string - */ - protected $host; + /** + * Current host name + * + * @var string + */ + protected $host; - /** - * Whether the HTTPS protocol is used - * - * @var bool - */ - protected $https; + /** + * Whether the HTTPS protocol is used + * + * @var bool + */ + protected $https; - /** - * Sanitized `$_SERVER` data - * - * @var array - */ - protected $info; + /** + * Sanitized `$_SERVER` data + * + * @var array + */ + protected $info; - /** - * Current server's IP address - * - * @var string - */ - protected $ip; + /** + * Current server's IP address + * + * @var string + */ + protected $ip; - /** - * Whether the site is behind a reverse proxy; - * `null` if not known (fixed allowed URL setup) - * - * @var bool|null - */ - protected $isBehindProxy; + /** + * Whether the site is behind a reverse proxy; + * `null` if not known (fixed allowed URL setup) + * + * @var bool|null + */ + protected $isBehindProxy; - /** - * URI path to the base - * - * @var string - */ - protected $path; + /** + * URI path to the base + * + * @var string + */ + protected $path; - /** - * Port number in the site URL - * - * @var int|null - */ - protected $port; + /** + * Port number in the site URL + * + * @var int|null + */ + protected $port; - /** - * Intermediary value of the port - * extracted from the host name - * - * @var int|null - */ - protected $portInHost; + /** + * Intermediary value of the port + * extracted from the host name + * + * @var int|null + */ + protected $portInHost; - /** - * Uri object for the full request URI. - * It is a combination of the base URL and `REQUEST_URI` - * - * @var \Kirby\Http\Uri - */ - protected $requestUri; + /** + * Uri object for the full request URI. + * It is a combination of the base URL and `REQUEST_URI` + * + * @var \Kirby\Http\Uri + */ + protected $requestUri; - /** - * Full request URL - * - * @var string - */ - protected $requestUrl; + /** + * Full request URL + * + * @var string + */ + protected $requestUrl; - /** - * Path to the php script within the - * document root without the - * filename of the script - * - * @var string - */ - protected $scriptPath; + /** + * Path to the php script within the + * document root without the + * filename of the script + * + * @var string + */ + protected $scriptPath; - /** - * Class constructor - * - * @param array|null $options - * @param array|null $info Optional override for `$_SERVER` - */ - public function __construct(?array $options = null, ?array $info = null) - { - $this->detect($options, $info); - } + /** + * Class constructor + * + * @param array|null $options + * @param array|null $info Optional override for `$_SERVER` + */ + public function __construct(?array $options = null, ?array $info = null) + { + $this->detect($options, $info); + } - /** - * Returns the server's IP address - * - * @see static::ip - * @return string|null - */ - public function address(): ?string - { - return $this->ip(); - } + /** + * Returns the server's IP address + * + * @see static::ip + * @return string|null + */ + public function address(): ?string + { + return $this->ip(); + } - /** - * Returns the full base URL object - * - * @return \Kirby\Http\Uri - */ - public function baseUri() - { - return $this->baseUri; - } + /** + * Returns the full base URL object + * + * @return \Kirby\Http\Uri + */ + public function baseUri() + { + return $this->baseUri; + } - /** - * Returns the full base URL - * - * @return string - */ - public function baseUrl(): string - { - return $this->baseUrl; - } + /** + * Returns the full base URL + * + * @return string + */ + public function baseUrl(): string + { + return $this->baseUrl; + } - /** - * Checks if the request is being served by the CLI - * - * @return bool - */ - public function cli(): bool - { - return $this->cli; - } + /** + * Checks if the request is being served by the CLI + * + * @return bool + */ + public function cli(): bool + { + return $this->cli; + } - /** - * Sanitizes the server info and detects - * all relevant parts. This can be called - * again at a later point to overwrite all - * the stored information and re-detect the - * environment if necessary. - * - * @param array|null $options - * @param array|null $info Optional override for `$_SERVER` - * @return array - */ - public function detect(array $options = null, array $info = null): array - { - $info ??= $_SERVER; - $options = array_merge([ - 'cli' => null, - 'allowed' => null - ], $options ?? []); + /** + * Sanitizes the server info and detects + * all relevant parts. This can be called + * again at a later point to overwrite all + * the stored information and re-detect the + * environment if necessary. + * + * @param array|null $options + * @param array|null $info Optional override for `$_SERVER` + * @return array + */ + public function detect(array $options = null, array $info = null): array + { + $info ??= $_SERVER; + $options = array_merge([ + 'cli' => null, + 'allowed' => null + ], $options ?? []); - $this->info = static::sanitize($info); - $this->cli = $this->detectCli($options['cli']); - $this->ip = $this->detectIp(); - $this->host = null; - $this->https = false; - $this->isBehindProxy = null; - $this->scriptPath = $this->detectScriptPath($this->get('SCRIPT_NAME')); - $this->path = $this->detectPath($this->scriptPath); - $this->port = null; + $this->info = static::sanitize($info); + $this->cli = $this->detectCli($options['cli']); + $this->ip = $this->detectIp(); + $this->host = null; + $this->https = false; + $this->isBehindProxy = null; + $this->scriptPath = $this->detectScriptPath($this->get('SCRIPT_NAME')); + $this->path = $this->detectPath($this->scriptPath); + $this->port = null; - // keep Server flags compatible for now - // TODO: remove in 3.8.0 - // @codeCoverageIgnoreStart - if (is_int($options['allowed']) === true) { - Helpers::deprecated(' + // keep Server flags compatible for now + // TODO: remove in 3.8.0 + // @codeCoverageIgnoreStart + if (is_int($options['allowed']) === true) { + Helpers::deprecated(' Using `Server::` constants for the `allowed` option has been deprecated and support will be removed in 3.8.0. Use one of the following instead: a single fixed URL, an array of allowed URLs to match dynamically, `*` wildcard to match dynamically even from insecure headers, or `true` to match automtically from safe server variables. '); - $options['allowed'] = $this->detectAllowedFromFlag($options['allowed']); - } - // @codeCoverageIgnoreEnd - - // insecure auto-detection - if ($options['allowed'] === '*' || $options['allowed'] === ['*']) { - $this->detectAuto(true); - - // fixed environments - } elseif (empty($options['allowed']) === false) { - $this->detectAllowed($options['allowed']); - - // secure auto-detection - } else { - $this->detectAuto(); - } - - // build the URI based on the detected params - $this->detectBaseUri(); - - // build the request URI based on the detected URL - $this->detectRequestUri($this->get('REQUEST_URI')); - - // return the sanitized $_SERVER array - return $this->info; - } - - /** - * Sets the host name, port, path and protocol from the - * fixed list of allowed URLs - * - * @param array|string $allowed - * @return void - */ - protected function detectAllowed($allowed): void - { - $allowed = A::wrap($allowed); - - // with a single allowed URL, the entire - // environment will be based on that - if (count($allowed) === 1) { - $baseUrl = A::first($allowed); - - if (is_string($baseUrl) === false) { - throw new InvalidArgumentException('Invalid allow list setup for base URLs'); - } - - $uri = new Uri($baseUrl, ['slash' => false]); - - $this->host = $uri->host(); - $this->https = $uri->https(); - $this->port = $uri->port(); - $this->path = $uri->path()->toString(); - return; - } - - // run insecure auto detection to get - // host, port and https from the environment; - // security is achieved by checking against - // the fixed allowlist below - $this->detectAuto(true); - - // build the baseUrl based on the detected environment - // to compare it against what is allowed - $this->detectBaseUri(); - - foreach ($allowed as $url) { - // skip invalid URLs - if (is_string($url) === false) { - continue; - } - - $uri = new Uri($url, ['slash' => false]); - - if ($uri->toString() === $this->baseUrl) { - // the current environment is allowed, - // stop before the exception below is thrown - return; - } - } - - throw new InvalidArgumentException('The environment is not allowed'); - } - - /** - * The URL option receives a set of Server constant flags - * - * Server::HOST_FROM_SERVER - * Server::HOST_FROM_SERVER | Server::HOST_ALLOW_EMPTY - * Server::HOST_FROM_HEADER - * Server::HOST_FROM_HEADER | Server::HOST_ALLOW_EMPTY - * @todo Remove in 3.8.0 - * - * @param int $flags - * @return string|null - */ - protected function detectAllowedFromFlag(int $flags): ?string - { - // allow host detection from host headers - if ($flags & Server::HOST_FROM_HEADER) { - return '*'; - } - - // detect host only from server name - return null; - } - - /** - * Sets the host name, port and protocol without configuration - * - * @param bool $insecure Include the `Host` and `X-Forwarded-*` headers in the search - * @return void - */ - protected function detectAuto(bool $insecure = false): void - { - // proxy server setup - if ( - $insecure === true && - empty($this->info['HTTP_X_FORWARDED_HOST']) === false - ) { - $this->isBehindProxy = true; - - $this->host = $this->detectForwardedHost(); - $this->https = $this->detectForwardedHttps(); - $this->port = $this->detectForwardedPort(); - - return; - } - - // local server setup - $this->isBehindProxy = false; - - $this->host = $this->detectHost($insecure); - $this->https = $this->detectHttps(); - $this->port = $this->detectPort(); - } - - /** - * Builds the base URL based on the - * given environment params - * - * @return \Kirby\Http\Uri - */ - protected function detectBaseUri() - { - $this->baseUri = new Uri([ - 'host' => $this->host, - 'path' => $this->path, - 'port' => $this->port, - 'scheme' => $this->https ? 'https' : 'http', - ]); - - $this->baseUrl = $this->baseUri->toString(); - - return $this->baseUri; - } - - /** - * Detects if the request is served by the CLI - * - * @param bool|null $override Set to a boolean to override detection (for testing) - * @return bool - */ - protected function detectCli(?bool $override = null): bool - { - if (is_bool($override) === true) { - return $override; - } - - if (defined('STDIN') === true) { - return true; - } - - $term = getenv('TERM'); - - if (substr(PHP_SAPI, 0, 3) === 'cgi' && $term && $term !== 'unknown') { - return true; - } - - return false; - } - - /** - * Detects the host name of the reverse proxy - * - * @return string|null - */ - protected function detectForwardedHost(): ?string - { - $host = $this->get('HTTP_X_FORWARDED_HOST'); - $parts = $this->detectPortInHost($host); - - $this->portInHost = $parts['port']; - - return $parts['host']; - } - - /** - * Detects the protocol of the reverse proxy - * - * @return bool - */ - protected function detectForwardedHttps(): bool - { - if ($this->detectHttpsOn($this->get('HTTP_X_FORWARDED_SSL')) === true) { - return true; - } - - if ($this->detectHttpsProtocol($this->get('HTTP_X_FORWARDED_PROTO')) === true) { - return true; - } - - return false; - } - - /** - * Detects the port of the reverse proxy - * - * @return int|null - */ - protected function detectForwardedPort(): ?int - { - // based on forwarded port - $port = $this->get('HTTP_X_FORWARDED_PORT'); - - if (is_int($port) === true) { - return $port; - } - - // based on forwarded host - if (is_int($this->portInHost) === true) { - return $this->portInHost; - } - - // based on the detected https state - if ($this->https === true) { - return 443; - } - - return null; - } - - /** - * Detects the host name from various headers - * - * @param bool $insecure Include the `Host` header in the search - * @return string|null - */ - protected function detectHost(bool $insecure = false): ?string - { - if ($insecure === true) { - $hosts[] = $this->get('HTTP_HOST'); - } - - $hosts[] = $this->get('SERVER_NAME'); - $hosts[] = $this->get('SERVER_ADDR'); - - // use the first header that is not empty - $hosts = array_filter($hosts); - $host = A::first($hosts); - - $parts = $this->detectPortInHost($host); - - $this->portInHost = $parts['port']; - - return $parts['host']; - } - - /** - * Detects the HTTPS status - * - * @return bool - */ - protected function detectHttps(): bool - { - if ($this->detectHttpsOn($this->get('HTTPS')) === true) { - return true; - } - - return false; - } - - /** - * Normalizes the HTTPS status into a boolean - * - * @param string|bool|null|int $value - * @return bool - */ - protected function detectHttpsOn($value): bool - { - // off can mean many things :) - $off = ['off', null, '', 0, '0', false, 'false', -1, '-1']; - - return in_array($value, $off, true) === false; - } - - /** - * Detects the HTTPS status from a `X-Forwarded-Proto` string - * - * @param string|null $protocol - * @return bool - */ - protected function detectHttpsProtocol(?string $protocol = null): bool - { - if ($protocol === null) { - return false; - } - - return in_array(strtolower($protocol), ['https', 'https, http']) === true; - } - - /** - * Detects the server's IP address - * - * @return string|null - */ - protected function detectIp(): ?string - { - return $this->get('SERVER_ADDR'); - } - - /** - * Detects the URI path unless in CLI mode - * - * @param string|null $path - * @return string - */ - protected function detectPath(?string $path = null): string - { - if ($this->cli === true) { - return ''; - } - - return $path ?? ''; - } - - /** - * Detects the port from various sources - * - * @return int|null - */ - protected function detectPort(): ?int - { - // based on server port - $port = $this->get('SERVER_PORT'); - - if (is_int($port) === true) { - return $port; - } - - // based on the detected host - if (is_int($this->portInHost) === true) { - return $this->portInHost; - } - - // based on the detected https state - if ($this->https === true) { - return 443; - } - - return null; - } - - /** - * Splits a hostname:port string into its components - * - * @param string|null $host - * @return array - */ - protected function detectPortInHost(?string $host = null): array - { - if (empty($host) === true) { - return [ - 'host' => null, - 'port' => null - ]; - } - - $parts = Str::split($host, ':'); - - return [ - 'host' => $parts[0] ?? null, - 'port' => static::sanitizePort($parts[1] ?? null), - ]; - } - - /** - * Splits any URI into path and query - * - * @param string|null $requestUri - * @return \Kirby\Http\Uri - */ - protected function detectRequestUri(?string $requestUri = null) - { - // make sure the URL parser works properly when there's a - // colon in the request URI but the URI is relative - if (Url::isAbsolute($requestUri) === false) { - $requestUri = 'https://getkirby.com' . $requestUri; - } - - $uri = new Uri($requestUri); - - // create the URI object as a combination of base uri parts - // and the parts from REQUEST_URI - $this->requestUri = $this->baseUri()->clone([ - 'fragment' => $uri->fragment(), - 'params' => $uri->params(), - 'path' => $uri->path(), - 'query' => $uri->query() - ]); - - // build the full request URL - $this->requestUrl = $this->requestUri->toString(); - - return $this->requestUri; - } - - /** - * Returns the sanitized script path unless in CLI mode - * - * @param string|null $scriptPath - * @return string - */ - protected function detectScriptPath(?string $scriptPath = null): string - { - if ($this->cli === true) { - return ''; - } - - return $this->sanitizeScriptPath($scriptPath); - } - - /** - * Gets a value from the server environment array - * - * - * $server->get('document_root'); - * // sample output: /var/www/kirby - * - * $server->get(); - * // returns the whole server array - * - * - * @param string|false|null $key The key to look for. Pass `false` or `null` - * to return the entire server array. - * @param mixed $default Optional default value, which should be - * returned if no element has been found - * @return mixed - */ - public function get($key = null, $default = null) - { - if (is_string($key) === false) { - return $this->info; - } - - if (isset($this->info[$key]) === false) { - $key = strtoupper($key); - } - - return $this->info[$key] ?? static::sanitize($key, $default); - } - - /** - * Gets a value from the global server environment array - * of the current app instance; falls back to `$_SERVER` if - * no app instance is running - * - * @param string|false|null $key The key to look for. Pass `false` or `null` - * to return the entire server array. - * @param mixed $default Optional default value, which should be - * returned if no element has been found - * @return mixed - */ - public static function getGlobally($key = null, $default = null) - { - // first try the global `Environment` object if the CMS is running - $app = App::instance(null, true); - if ($app) { - return $app->environment()->get($key, $default); - } - - if (is_string($key) === false) { - return static::sanitize($_SERVER); - } - - if (isset($_SERVER[$key]) === false) { - $key = strtoupper($key); - } - - return static::sanitize($key, $_SERVER[$key] ?? $default); - } - - /** - * Returns the current host name - * - * @return string|null - */ - public function host(): ?string - { - return $this->host; - } - - /** - * Returns whether the HTTPS protocol is used - * - * @return bool - */ - public function https(): bool - { - return $this->https; - } - - /** - * Returns the sanitized `$_SERVER` array - * - * @return array - */ - public function info(): array - { - return $this->info; - } - - /** - * Returns the server's IP address - * - * @return string|null - */ - public function ip(): ?string - { - return $this->ip; - } - - /** - * Returns if the server is behind a - * reverse proxy server - * - * @return bool|null - */ - public function isBehindProxy(): ?bool - { - return $this->isBehindProxy; - } - - /** - * Checks if this is a local installation; - * returns `false` if in doubt - * - * @return bool - */ - public function isLocal(): bool - { - // check host - $host = $this->host(); - - if ($host === 'localhost') { - return true; - } - - if (Str::endsWith($host, '.local') === true) { - return true; - } - - if (Str::endsWith($host, '.test') === true) { - return true; - } - - // collect all possible visitor ips - $ips = [ - $this->get('REMOTE_ADDR'), - $this->get('HTTP_X_FORWARDED_FOR'), - $this->get('HTTP_CLIENT_IP') - ]; - - // remove duplicates and empty ips - $ips = array_unique(array_filter($ips)); - - // no known ip? Better not assume it's local - if (empty($ips) === true) { - return false; - } - - // stop as soon as a non-local ip is found - foreach ($ips as $ip) { - if (in_array($ip, ['::1', '127.0.0.1']) === false) { - return false; - } - } - - return true; - } - - /** - * Loads and returns options from environment-specific - * PHP files (by host name and server IP address) - * - * @param string $root Root directory to load configs from - * @return array - */ - public function options(string $root): array - { - $configHost = []; - $configAddr = []; - - $host = $this->host(); - $addr = $this->ip(); - - // load the config for the host - if (empty($host) === false) { - $configHost = F::load($root . '/config.' . $host . '.php', []); - } - - // load the config for the server IP - if (empty($addr) === false) { - $configAddr = F::load($root . '/config.' . $addr . '.php', []); - } - - return array_replace_recursive($configHost, $configAddr); - } - - /** - * Returns the detected path - * - * @return string|null - */ - public function path(): ?string - { - return $this->path; - } - - /** - * Returns the correct port number - * - * @return int|null - */ - public function port(): ?int - { - return $this->port; - } - - /** - * Returns an URI object for the requested URL - * - * @return \Kirby\Http\Uri - */ - public function requestUri() - { - return $this->requestUri; - } - - /** - * Returns the current URL, including the request path - * and query - * - * @return string - */ - public function requestUrl(): string - { - return $this->requestUrl; - } - - /** - * Sanitizes some `$_SERVER` keys - * - * @param string|array $key - * @param mixed $value - * @return mixed - */ - public static function sanitize($key, $value = null) - { - if (is_array($key) === true) { - foreach ($key as $k => $v) { - $key[$k] = static::sanitize($k, $v); - } - - return $key; - } - - switch ($key) { - case 'SERVER_ADDR': - case 'SERVER_NAME': - case 'HTTP_HOST': - case 'HTTP_X_FORWARDED_HOST': - return static::sanitizeHost($value); - case 'SERVER_PORT': - case 'HTTP_X_FORWARDED_PORT': - return static::sanitizePort($value); - default: - return $value; - } - } - - /** - * Sanitizes the given host name - * - * @param string|null $host - * @return string|null - */ - protected static function sanitizeHost(?string $host = null): ?string - { - if (empty($host) === true) { - return null; - } - - $host = Str::lower($host); - $host = strip_tags($host); - $host = basename($host); - $host = preg_replace('![^\w.:-]+!iu', '', $host); - $host = htmlspecialchars($host, ENT_COMPAT); - $host = trim($host, '-'); - $host = trim($host, '.'); - $host = trim($host); - - if ($host === '') { - return null; - } - - return $host; - } - - /** - * Sanitizes the given port number - * - * @param string|int|null $port - * @return int|null - */ - protected static function sanitizePort($port = null): ?int - { - // already fine - if (is_int($port) === true) { - return $port; - } - - // no port given - if ($port === null || $port === false || $port === '') { - return null; - } - - // remove any character that is not an integer - $port = preg_replace('![^0-9]+!', '', (string)($port ?? '')); - - // no port - if ($port === '') { - return null; - } - - // convert to integer - return (int)$port; - } - - /** - * Sanitizes the given script path - * - * @param string|null $scriptPath - * @return string - */ - protected function sanitizeScriptPath(?string $scriptPath = null): string - { - $scriptPath ??= ''; - $scriptPath = trim($scriptPath); - - // skip all the sanitizing steps if the path is empty - if ($scriptPath === '') { - return $scriptPath; - } - - // replace Windows backslashes - $scriptPath = str_replace('\\', '/', $scriptPath); - // remove the script - $scriptPath = dirname($scriptPath); - // replace those fucking backslashes again - $scriptPath = str_replace('\\', '/', $scriptPath); - // remove the leading and trailing slashes - $scriptPath = trim($scriptPath, '/'); - - // top-level scripts don't have a path - // and dirname() will return '.' - if ($scriptPath === '.') { - return ''; - } - - return $scriptPath; - } - - /** - * Returns the path to the php script - * within the document root without the - * filename of the script. - * - * i.e. /subfolder/index.php -> subfolder - * - * This can be used to build the base baseUrl - * for subfolder installations - * - * @return string - */ - public function scriptPath(): string - { - return $this->scriptPath; - } - - /** - * Returns all environment data as array - * - * @return array - */ - public function toArray(): array - { - return [ - 'baseUrl' => $this->baseUrl, - 'host' => $this->host, - 'https' => $this->https, - 'info' => $this->info, - 'ip' => $this->ip, - 'isBehindProxy' => $this->isBehindProxy, - 'path' => $this->path, - 'port' => $this->port, - 'requestUrl' => $this->requestUrl, - 'scriptPath' => $this->scriptPath, - ]; - } + $options['allowed'] = $this->detectAllowedFromFlag($options['allowed']); + } + // @codeCoverageIgnoreEnd + + // insecure auto-detection + if ($options['allowed'] === '*' || $options['allowed'] === ['*']) { + $this->detectAuto(true); + + // fixed environments + } elseif (empty($options['allowed']) === false) { + $this->detectAllowed($options['allowed']); + + // secure auto-detection + } else { + $this->detectAuto(); + } + + // build the URI based on the detected params + $this->detectBaseUri(); + + // build the request URI based on the detected URL + $this->detectRequestUri($this->get('REQUEST_URI')); + + // return the sanitized $_SERVER array + return $this->info; + } + + /** + * Sets the host name, port, path and protocol from the + * fixed list of allowed URLs + * + * @param array|string $allowed + * @return void + */ + protected function detectAllowed($allowed): void + { + $allowed = A::wrap($allowed); + + // with a single allowed URL, the entire + // environment will be based on that + if (count($allowed) === 1) { + $baseUrl = A::first($allowed); + + if (is_string($baseUrl) === false) { + throw new InvalidArgumentException('Invalid allow list setup for base URLs'); + } + + $uri = new Uri($baseUrl, ['slash' => false]); + + $this->host = $uri->host(); + $this->https = $uri->https(); + $this->port = $uri->port(); + $this->path = $uri->path()->toString(); + return; + } + + // run insecure auto detection to get + // host, port and https from the environment; + // security is achieved by checking against + // the fixed allowlist below + $this->detectAuto(true); + + // build the baseUrl based on the detected environment + // to compare it against what is allowed + $this->detectBaseUri(); + + foreach ($allowed as $url) { + // skip invalid URLs + if (is_string($url) === false) { + continue; + } + + $uri = new Uri($url, ['slash' => false]); + + if ($uri->toString() === $this->baseUrl) { + // the current environment is allowed, + // stop before the exception below is thrown + return; + } + } + + throw new InvalidArgumentException('The environment is not allowed'); + } + + /** + * The URL option receives a set of Server constant flags + * + * Server::HOST_FROM_SERVER + * Server::HOST_FROM_SERVER | Server::HOST_ALLOW_EMPTY + * Server::HOST_FROM_HEADER + * Server::HOST_FROM_HEADER | Server::HOST_ALLOW_EMPTY + * @todo Remove in 3.8.0 + * + * @param int $flags + * @return string|null + */ + protected function detectAllowedFromFlag(int $flags): ?string + { + // allow host detection from host headers + if ($flags & Server::HOST_FROM_HEADER) { + return '*'; + } + + // detect host only from server name + return null; + } + + /** + * Sets the host name, port and protocol without configuration + * + * @param bool $insecure Include the `Host`, `Forwarded` and `X-Forwarded-*` headers in the search + * @return void + */ + protected function detectAuto(bool $insecure = false): void + { + // proxy server setup + if ($insecure === true) { + $forwarded = $this->detectForwarded(); + + $host = $forwarded['host']; + $port = $forwarded['port']; + $https = $forwarded['https']; + + if ($host || $port || $https) { + $this->isBehindProxy = true; + + // if a port or scheme is defined but no host, assume + // that the host is the same as PHP's own hostname + // (which is often the case with reverse proxies) + $this->host = $host ?? $this->detectHost($insecure); + $this->port = $port; + $this->https = $https; + + return; + } + } + + // local server setup + $this->isBehindProxy = false; + + $this->host = $this->detectHost($insecure); + $this->https = $this->detectHttps(); + $this->port = $this->detectPort(); + } + + /** + * Builds the base URL based on the + * given environment params + * + * @return \Kirby\Http\Uri + */ + protected function detectBaseUri() + { + $this->baseUri = new Uri([ + 'host' => $this->host, + 'path' => $this->path, + 'port' => $this->port, + 'scheme' => $this->https ? 'https' : 'http', + ]); + + $this->baseUrl = $this->baseUri->toString(); + + return $this->baseUri; + } + + /** + * Detects if the request is served by the CLI + * + * @param bool|null $override Set to a boolean to override detection (for testing) + * @return bool + */ + protected function detectCli(?bool $override = null): bool + { + if (is_bool($override) === true) { + return $override; + } + + if (defined('STDIN') === true) { + return true; + } + + // @codeCoverageIgnoreStart + $term = getenv('TERM'); + + if (substr(PHP_SAPI, 0, 3) === 'cgi' && $term && $term !== 'unknown') { + return true; + } + + return false; + // @codeCoverageIgnoreEnd + } + + /** + * Detects the host, protocol, port and client IP + * from the `Forwarded` and `X-Forwarded-*` headers + * + * @return array + */ + protected function detectForwarded(): array + { + $data = [ + 'for' => null, + 'host' => null, + 'https' => false, + 'port' => null + ]; + + // prefer the standardized `Forwarded` header if defined + $forwarded = $this->get('HTTP_FORWARDED'); + if ($forwarded) { + // only use the first (outermost) proxy by using the first set of values + // before the first comma (but only a comma outside of quotes) + if (Str::contains($forwarded, ',') === true) { + $forwarded = preg_split('/"[^"]*"(*SKIP)(*F)|,/', $forwarded)[0]; + } + + // split into separate key=value;key=value fields by semicolon, + // but only split outside of quotes + $rawFields = preg_split('/"[^"]*"(*SKIP)(*F)|;/', $forwarded); + + // split key and value into an associative array + $fields = []; + foreach ($rawFields as $field) { + $key = Str::lower(Str::before($field, '=')); + $value = Str::after($field, '='); + + // trim the surrounding quotes + if (Str::substr($value, 0, 1) === '"') { + $value = Str::substr($value, 1, -1); + } + + $fields[$key] = $value; + } + + // assemble the normalized data + if (isset($fields['host']) === true) { + $parts = $this->detectPortInHost($fields['host']); + $data['host'] = $parts['host']; + $data['port'] = $parts['port']; + } + + if (isset($fields['proto']) === true) { + $data['https'] = $this->detectHttpsProtocol($fields['proto']); + } + + if ($data['port'] === null && $data['https'] === true) { + $data['port'] = 443; + } + + $data['for'] = $parts['for'] ?? null; + + return $data; + } + + // no success, try the `X-Forwarded-*` headers + $data['host'] = $this->detectForwardedHost(); + $data['https'] = $this->detectForwardedHttps(); + $data['port'] = $this->detectForwardedPort($data['https']); + $data['for'] = $this->get('HTTP_X_FORWARDED_FOR'); + + return $data; + } + + /** + * Detects the host name of the reverse proxy + * from the `X-Forwarded-Host` header + * + * @return string|null + */ + protected function detectForwardedHost(): ?string + { + $host = $this->get('HTTP_X_FORWARDED_HOST'); + $parts = $this->detectPortInHost($host); + + $this->portInHost = $parts['port']; + + return $parts['host']; + } + + /** + * Detects the protocol of the reverse proxy from the + * `X-Forwarded-SSL` or `X-Forwarded-Proto` header + * + * @return bool + */ + protected function detectForwardedHttps(): bool + { + if ($this->detectHttpsOn($this->get('HTTP_X_FORWARDED_SSL')) === true) { + return true; + } + + if ($this->detectHttpsProtocol($this->get('HTTP_X_FORWARDED_PROTO')) === true) { + return true; + } + + return false; + } + + /** + * Detects the port of the reverse proxy from the + * `X-Forwarded-Host` or `X-Forwarded-Port` header + * + * @param bool $https Whether HTTPS was detected + * @return int|null + */ + protected function detectForwardedPort(bool $https): ?int + { + // based on forwarded port + $port = $this->get('HTTP_X_FORWARDED_PORT'); + + if (is_int($port) === true) { + return $port; + } + + // based on forwarded host + if (is_int($this->portInHost) === true) { + return $this->portInHost; + } + + // based on the detected https state + if ($https === true) { + return 443; + } + + return null; + } + + /** + * Detects the host name from various headers + * + * @param bool $insecure Include the `Host` header in the search + * @return string|null + */ + protected function detectHost(bool $insecure = false): ?string + { + if ($insecure === true) { + $hosts[] = $this->get('HTTP_HOST'); + } + + $hosts[] = $this->get('SERVER_NAME'); + $hosts[] = $this->get('SERVER_ADDR'); + + // use the first header that is not empty + $hosts = array_filter($hosts); + $host = A::first($hosts); + + $parts = $this->detectPortInHost($host); + + $this->portInHost = $parts['port']; + + return $parts['host']; + } + + /** + * Detects the HTTPS status + * + * @return bool + */ + protected function detectHttps(): bool + { + if ($this->detectHttpsOn($this->get('HTTPS')) === true) { + return true; + } + + return false; + } + + /** + * Normalizes the HTTPS status into a boolean + * + * @param string|bool|null|int $value + * @return bool + */ + protected function detectHttpsOn($value): bool + { + // off can mean many things :) + $off = ['off', null, '', 0, '0', false, 'false', -1, '-1']; + + return in_array($value, $off, true) === false; + } + + /** + * Detects the HTTPS status from a `X-Forwarded-Proto` string + * + * @param string|null $protocol + * @return bool + */ + protected function detectHttpsProtocol(?string $protocol = null): bool + { + if ($protocol === null) { + return false; + } + + return in_array(strtolower($protocol), ['https', 'https, http']) === true; + } + + /** + * Detects the server's IP address + * + * @return string|null + */ + protected function detectIp(): ?string + { + return $this->get('SERVER_ADDR'); + } + + /** + * Detects the URI path unless in CLI mode + * + * @param string|null $path + * @return string + */ + protected function detectPath(?string $path = null): string + { + if ($this->cli === true) { + return ''; + } + + return $path ?? ''; + } + + /** + * Detects the port from various sources + * + * @return int|null + */ + protected function detectPort(): ?int + { + // based on server port + $port = $this->get('SERVER_PORT'); + + if (is_int($port) === true) { + return $port; + } + + // based on the detected host + if (is_int($this->portInHost) === true) { + return $this->portInHost; + } + + // based on the detected https state + if ($this->https === true) { + return 443; + } + + return null; + } + + /** + * Splits a hostname:port string into its components + * + * @param string|null $host + * @return array + */ + protected function detectPortInHost(?string $host = null): array + { + if (empty($host) === true) { + return [ + 'host' => null, + 'port' => null + ]; + } + + $parts = Str::split($host, ':'); + + return [ + 'host' => $parts[0] ?? null, + 'port' => static::sanitizePort($parts[1] ?? null), + ]; + } + + /** + * Splits any URI into path and query + * + * @param string|null $requestUri + * @return \Kirby\Http\Uri + */ + protected function detectRequestUri(?string $requestUri = null) + { + // make sure the URL parser works properly when there's a + // colon in the request URI but the URI is relative + if (Url::isAbsolute($requestUri) === false) { + $requestUri = 'https://getkirby.com' . $requestUri; + } + + $uri = new Uri($requestUri); + + // create the URI object as a combination of base uri parts + // and the parts from REQUEST_URI + $this->requestUri = $this->baseUri()->clone([ + 'fragment' => $uri->fragment(), + 'params' => $uri->params(), + 'path' => $uri->path(), + 'query' => $uri->query() + ]); + + // build the full request URL + $this->requestUrl = $this->requestUri->toString(); + + return $this->requestUri; + } + + /** + * Returns the sanitized script path unless in CLI mode + * + * @param string|null $scriptPath + * @return string + */ + protected function detectScriptPath(?string $scriptPath = null): string + { + if ($this->cli === true) { + return ''; + } + + return $this->sanitizeScriptPath($scriptPath); + } + + /** + * Gets a value from the server environment array + * + * + * $server->get('document_root'); + * // sample output: /var/www/kirby + * + * $server->get(); + * // returns the whole server array + * + * + * @param string|false|null $key The key to look for. Pass `false` or `null` + * to return the entire server array. + * @param mixed $default Optional default value, which should be + * returned if no element has been found + * @return mixed + */ + public function get($key = null, $default = null) + { + if (is_string($key) === false) { + return $this->info; + } + + if (isset($this->info[$key]) === false) { + $key = strtoupper($key); + } + + return $this->info[$key] ?? static::sanitize($key, $default); + } + + /** + * Gets a value from the global server environment array + * of the current app instance; falls back to `$_SERVER` if + * no app instance is running + * + * @param string|false|null $key The key to look for. Pass `false` or `null` + * to return the entire server array. + * @param mixed $default Optional default value, which should be + * returned if no element has been found + * @return mixed + */ + public static function getGlobally($key = null, $default = null) + { + // first try the global `Environment` object if the CMS is running + $app = App::instance(null, true); + if ($app) { + return $app->environment()->get($key, $default); + } + + if (is_string($key) === false) { + return static::sanitize($_SERVER); + } + + if (isset($_SERVER[$key]) === false) { + $key = strtoupper($key); + } + + return static::sanitize($key, $_SERVER[$key] ?? $default); + } + + /** + * Returns the current host name + * + * @return string|null + */ + public function host(): ?string + { + return $this->host; + } + + /** + * Returns whether the HTTPS protocol is used + * + * @return bool + */ + public function https(): bool + { + return $this->https; + } + + /** + * Returns the sanitized `$_SERVER` array + * + * @return array + */ + public function info(): array + { + return $this->info; + } + + /** + * Returns the server's IP address + * + * @return string|null + */ + public function ip(): ?string + { + return $this->ip; + } + + /** + * Returns if the server is behind a + * reverse proxy server + * + * @return bool|null + */ + public function isBehindProxy(): ?bool + { + return $this->isBehindProxy; + } + + /** + * Checks if this is a local installation; + * returns `false` if in doubt + * + * @return bool + */ + public function isLocal(): bool + { + // check host + $host = $this->host(); + + if ($host === 'localhost') { + return true; + } + + if (Str::endsWith($host, '.local') === true) { + return true; + } + + if (Str::endsWith($host, '.test') === true) { + return true; + } + + // collect all possible visitor ips + $ips = [ + $this->get('REMOTE_ADDR'), + $this->get('HTTP_X_FORWARDED_FOR'), + $this->get('HTTP_CLIENT_IP') + ]; + + if ($this->get('HTTP_FORWARDED')) { + $ips[] = $this->detectForwarded()['for']; + } + + // remove duplicates and empty ips + $ips = array_unique(array_filter($ips)); + + // no known ip? Better not assume it's local + if (empty($ips) === true) { + return false; + } + + // stop as soon as a non-local ip is found + foreach ($ips as $ip) { + if (in_array($ip, ['::1', '127.0.0.1']) === false) { + return false; + } + } + + return true; + } + + /** + * Loads and returns options from environment-specific + * PHP files (by host name and server IP address) + * + * @param string $root Root directory to load configs from + * @return array + */ + public function options(string $root): array + { + $configHost = []; + $configAddr = []; + + $host = $this->host(); + $addr = $this->ip(); + + // load the config for the host + if (empty($host) === false) { + $configHost = F::load($root . '/config.' . $host . '.php', []); + } + + // load the config for the server IP + if (empty($addr) === false) { + $configAddr = F::load($root . '/config.' . $addr . '.php', []); + } + + return array_replace_recursive($configHost, $configAddr); + } + + /** + * Returns the detected path + * + * @return string|null + */ + public function path(): ?string + { + return $this->path; + } + + /** + * Returns the correct port number + * + * @return int|null + */ + public function port(): ?int + { + return $this->port; + } + + /** + * Returns an URI object for the requested URL + * + * @return \Kirby\Http\Uri + */ + public function requestUri() + { + return $this->requestUri; + } + + /** + * Returns the current URL, including the request path + * and query + * + * @return string + */ + public function requestUrl(): string + { + return $this->requestUrl; + } + + /** + * Sanitizes some `$_SERVER` keys + * + * @param string|array $key + * @param mixed $value + * @return mixed + */ + public static function sanitize($key, $value = null) + { + if (is_array($key) === true) { + foreach ($key as $k => $v) { + $key[$k] = static::sanitize($k, $v); + } + + return $key; + } + + switch ($key) { + case 'SERVER_ADDR': + case 'SERVER_NAME': + case 'HTTP_HOST': + case 'HTTP_X_FORWARDED_HOST': + return static::sanitizeHost($value); + case 'SERVER_PORT': + case 'HTTP_X_FORWARDED_PORT': + return static::sanitizePort($value); + default: + return $value; + } + } + + /** + * Sanitizes the given host name + * + * @param string|null $host + * @return string|null + */ + protected static function sanitizeHost(?string $host = null): ?string + { + if (empty($host) === true) { + return null; + } + + $host = Str::lower($host); + $host = strip_tags($host); + $host = basename($host); + $host = preg_replace('![^\w.:-]+!iu', '', $host); + $host = htmlspecialchars($host, ENT_COMPAT); + $host = trim($host, '-'); + $host = trim($host, '.'); + $host = trim($host); + + if ($host === '') { + return null; + } + + return $host; + } + + /** + * Sanitizes the given port number + * + * @param string|int|null $port + * @return int|null + */ + protected static function sanitizePort($port = null): ?int + { + // already fine + if (is_int($port) === true) { + return $port; + } + + // no port given + if ($port === null || $port === false || $port === '') { + return null; + } + + // remove any character that is not an integer + $port = preg_replace('![^0-9]+!', '', (string)($port ?? '')); + + // no port + if ($port === '') { + return null; + } + + // convert to integer + return (int)$port; + } + + /** + * Sanitizes the given script path + * + * @param string|null $scriptPath + * @return string + */ + protected function sanitizeScriptPath(?string $scriptPath = null): string + { + $scriptPath ??= ''; + $scriptPath = trim($scriptPath); + + // skip all the sanitizing steps if the path is empty + if ($scriptPath === '') { + return $scriptPath; + } + + // replace Windows backslashes + $scriptPath = str_replace('\\', '/', $scriptPath); + // remove the script + $scriptPath = dirname($scriptPath); + // replace those fucking backslashes again + $scriptPath = str_replace('\\', '/', $scriptPath); + // remove the leading and trailing slashes + $scriptPath = trim($scriptPath, '/'); + + // top-level scripts don't have a path + // and dirname() will return '.' + if ($scriptPath === '.') { + return ''; + } + + return $scriptPath; + } + + /** + * Returns the path to the php script + * within the document root without the + * filename of the script. + * + * i.e. /subfolder/index.php -> subfolder + * + * This can be used to build the base baseUrl + * for subfolder installations + * + * @return string + */ + public function scriptPath(): string + { + return $this->scriptPath; + } + + /** + * Returns all environment data as array + * + * @return array + */ + public function toArray(): array + { + return [ + 'baseUrl' => $this->baseUrl, + 'host' => $this->host, + 'https' => $this->https, + 'info' => $this->info, + 'ip' => $this->ip, + 'isBehindProxy' => $this->isBehindProxy, + 'path' => $this->path, + 'port' => $this->port, + 'requestUrl' => $this->requestUrl, + 'scriptPath' => $this->scriptPath, + ]; + } } diff --git a/kirby/src/Http/Header.php b/kirby/src/Http/Header.php index 92aeb90..5f3b5ee 100755 --- a/kirby/src/Http/Header.php +++ b/kirby/src/Http/Header.php @@ -16,301 +16,301 @@ use Kirby\Filesystem\F; */ class Header { - // configuration - public static $codes = [ + // configuration + public static $codes = [ - // successful - '_200' => 'OK', - '_201' => 'Created', - '_202' => 'Accepted', + // successful + '_200' => 'OK', + '_201' => 'Created', + '_202' => 'Accepted', - // redirection - '_300' => 'Multiple Choices', - '_301' => 'Moved Permanently', - '_302' => 'Found', - '_303' => 'See Other', - '_304' => 'Not Modified', - '_307' => 'Temporary Redirect', - '_308' => 'Permanent Redirect', + // redirection + '_300' => 'Multiple Choices', + '_301' => 'Moved Permanently', + '_302' => 'Found', + '_303' => 'See Other', + '_304' => 'Not Modified', + '_307' => 'Temporary Redirect', + '_308' => 'Permanent Redirect', - // client error - '_400' => 'Bad Request', - '_401' => 'Unauthorized', - '_402' => 'Payment Required', - '_403' => 'Forbidden', - '_404' => 'Not Found', - '_405' => 'Method Not Allowed', - '_406' => 'Not Acceptable', - '_410' => 'Gone', - '_418' => 'I\'m a teapot', - '_451' => 'Unavailable For Legal Reasons', + // client error + '_400' => 'Bad Request', + '_401' => 'Unauthorized', + '_402' => 'Payment Required', + '_403' => 'Forbidden', + '_404' => 'Not Found', + '_405' => 'Method Not Allowed', + '_406' => 'Not Acceptable', + '_410' => 'Gone', + '_418' => 'I\'m a teapot', + '_451' => 'Unavailable For Legal Reasons', - // server error - '_500' => 'Internal Server Error', - '_501' => 'Not Implemented', - '_502' => 'Bad Gateway', - '_503' => 'Service Unavailable', - '_504' => 'Gateway Time-out' - ]; + // server error + '_500' => 'Internal Server Error', + '_501' => 'Not Implemented', + '_502' => 'Bad Gateway', + '_503' => 'Service Unavailable', + '_504' => 'Gateway Time-out' + ]; - /** - * Sends a content type header - * - * @param string $mime - * @param string $charset - * @param bool $send - * @return string|void - */ - public static function contentType(string $mime, string $charset = 'UTF-8', bool $send = true) - { - if ($found = F::extensionToMime($mime)) { - $mime = $found; - } + /** + * Sends a content type header + * + * @param string $mime + * @param string $charset + * @param bool $send + * @return string|void + */ + public static function contentType(string $mime, string $charset = 'UTF-8', bool $send = true) + { + if ($found = F::extensionToMime($mime)) { + $mime = $found; + } - $header = 'Content-type: ' . $mime; + $header = 'Content-type: ' . $mime; - if (empty($charset) === false) { - $header .= '; charset=' . $charset; - } + if (empty($charset) === false) { + $header .= '; charset=' . $charset; + } - if ($send === false) { - return $header; - } + if ($send === false) { + return $header; + } - header($header); - } + header($header); + } - /** - * Creates headers by key and value - * - * @param string|array $key - * @param string|null $value - * @return string - */ - public static function create($key, string $value = null): string - { - if (is_array($key) === true) { - $headers = []; + /** + * Creates headers by key and value + * + * @param string|array $key + * @param string|null $value + * @return string + */ + public static function create($key, string $value = null): string + { + if (is_array($key) === true) { + $headers = []; - foreach ($key as $k => $v) { - $headers[] = static::create($k, $v); - } + foreach ($key as $k => $v) { + $headers[] = static::create($k, $v); + } - return implode("\r\n", $headers); - } + return implode("\r\n", $headers); + } - // prevent header injection by stripping any newline characters from single headers - return str_replace(["\r", "\n"], '', $key . ': ' . $value); - } + // prevent header injection by stripping any newline characters from single headers + return str_replace(["\r", "\n"], '', $key . ': ' . $value); + } - /** - * Shortcut for static::contentType() - * - * @param string $mime - * @param string $charset - * @param bool $send - * @return string|void - */ - public static function type(string $mime, string $charset = 'UTF-8', bool $send = true) - { - return static::contentType($mime, $charset, $send); - } + /** + * Shortcut for static::contentType() + * + * @param string $mime + * @param string $charset + * @param bool $send + * @return string|void + */ + public static function type(string $mime, string $charset = 'UTF-8', bool $send = true) + { + return static::contentType($mime, $charset, $send); + } - /** - * Sends a status header - * - * Checks $code against a list of known status codes. To bypass this check - * and send a custom status code and message, use a $code string formatted - * as 3 digits followed by a space and a message, e.g. '999 Custom Status'. - * - * @param int|string $code The HTTP status code - * @param bool $send If set to false the header will be returned instead - * @return string|void - */ - public static function status($code = null, bool $send = true) - { - $codes = static::$codes; - $protocol = Environment::getGlobally('SERVER_PROTOCOL', 'HTTP/1.1'); + /** + * Sends a status header + * + * Checks $code against a list of known status codes. To bypass this check + * and send a custom status code and message, use a $code string formatted + * as 3 digits followed by a space and a message, e.g. '999 Custom Status'. + * + * @param int|string $code The HTTP status code + * @param bool $send If set to false the header will be returned instead + * @return string|void + */ + public static function status($code = null, bool $send = true) + { + $codes = static::$codes; + $protocol = Environment::getGlobally('SERVER_PROTOCOL', 'HTTP/1.1'); - // allow full control over code and message - if (is_string($code) === true && preg_match('/^\d{3} \w.+$/', $code) === 1) { - $message = substr(rtrim($code), 4); - $code = substr($code, 0, 3); - } else { - $code = array_key_exists('_' . $code, $codes) === false ? 500 : $code; - $message = $codes['_' . $code] ?? 'Something went wrong'; - } + // allow full control over code and message + if (is_string($code) === true && preg_match('/^\d{3} \w.+$/', $code) === 1) { + $message = substr(rtrim($code), 4); + $code = substr($code, 0, 3); + } else { + $code = array_key_exists('_' . $code, $codes) === false ? 500 : $code; + $message = $codes['_' . $code] ?? 'Something went wrong'; + } - $header = $protocol . ' ' . $code . ' ' . $message; + $header = $protocol . ' ' . $code . ' ' . $message; - if ($send === false) { - return $header; - } + if ($send === false) { + return $header; + } - // try to send the header - header($header); - } + // try to send the header + header($header); + } - /** - * Sends a 200 header - * - * @param bool $send - * @return string|void - */ - public static function success(bool $send = true) - { - return static::status(200, $send); - } + /** + * Sends a 200 header + * + * @param bool $send + * @return string|void + */ + public static function success(bool $send = true) + { + return static::status(200, $send); + } - /** - * Sends a 201 header - * - * @param bool $send - * @return string|void - */ - public static function created(bool $send = true) - { - return static::status(201, $send); - } + /** + * Sends a 201 header + * + * @param bool $send + * @return string|void + */ + public static function created(bool $send = true) + { + return static::status(201, $send); + } - /** - * Sends a 202 header - * - * @param bool $send - * @return string|void - */ - public static function accepted(bool $send = true) - { - return static::status(202, $send); - } + /** + * Sends a 202 header + * + * @param bool $send + * @return string|void + */ + public static function accepted(bool $send = true) + { + return static::status(202, $send); + } - /** - * Sends a 400 header - * - * @param bool $send - * @return string|void - */ - public static function error(bool $send = true) - { - return static::status(400, $send); - } + /** + * Sends a 400 header + * + * @param bool $send + * @return string|void + */ + public static function error(bool $send = true) + { + return static::status(400, $send); + } - /** - * Sends a 403 header - * - * @param bool $send - * @return string|void - */ - public static function forbidden(bool $send = true) - { - return static::status(403, $send); - } + /** + * Sends a 403 header + * + * @param bool $send + * @return string|void + */ + public static function forbidden(bool $send = true) + { + return static::status(403, $send); + } - /** - * Sends a 404 header - * - * @param bool $send - * @return string|void - */ - public static function notfound(bool $send = true) - { - return static::status(404, $send); - } + /** + * Sends a 404 header + * + * @param bool $send + * @return string|void + */ + public static function notfound(bool $send = true) + { + return static::status(404, $send); + } - /** - * Sends a 404 header - * - * @param bool $send - * @return string|void - */ - public static function missing(bool $send = true) - { - return static::status(404, $send); - } + /** + * Sends a 404 header + * + * @param bool $send + * @return string|void + */ + public static function missing(bool $send = true) + { + return static::status(404, $send); + } - /** - * Sends a 410 header - * - * @param bool $send - * @return string|void - */ - public static function gone(bool $send = true) - { - return static::status(410, $send); - } + /** + * Sends a 410 header + * + * @param bool $send + * @return string|void + */ + public static function gone(bool $send = true) + { + return static::status(410, $send); + } - /** - * Sends a 500 header - * - * @param bool $send - * @return string|void - */ - public static function panic(bool $send = true) - { - return static::status(500, $send); - } + /** + * Sends a 500 header + * + * @param bool $send + * @return string|void + */ + public static function panic(bool $send = true) + { + return static::status(500, $send); + } - /** - * Sends a 503 header - * - * @param bool $send - * @return string|void - */ - public static function unavailable(bool $send = true) - { - return static::status(503, $send); - } + /** + * Sends a 503 header + * + * @param bool $send + * @return string|void + */ + public static function unavailable(bool $send = true) + { + return static::status(503, $send); + } - /** - * Sends a redirect header - * - * @param string $url - * @param int $code - * @param bool $send - * @return string|void - */ - public static function redirect(string $url, int $code = 302, bool $send = true) - { - $status = static::status($code, false); - $location = 'Location:' . Url::unIdn($url); + /** + * Sends a redirect header + * + * @param string $url + * @param int $code + * @param bool $send + * @return string|void + */ + public static function redirect(string $url, int $code = 302, bool $send = true) + { + $status = static::status($code, false); + $location = 'Location:' . Url::unIdn($url); - if ($send !== true) { - return $status . "\r\n" . $location; - } + if ($send !== true) { + return $status . "\r\n" . $location; + } - header($status); - header($location); - exit(); - } + header($status); + header($location); + exit(); + } - /** - * Sends download headers for anything that is downloadable - * - * @param array $params Check out the defaults array for available parameters - */ - public static function download(array $params = []) - { - $defaults = [ - 'name' => 'download', - 'size' => false, - 'mime' => 'application/force-download', - 'modified' => time() - ]; + /** + * Sends download headers for anything that is downloadable + * + * @param array $params Check out the defaults array for available parameters + */ + public static function download(array $params = []) + { + $defaults = [ + 'name' => 'download', + 'size' => false, + 'mime' => 'application/force-download', + 'modified' => time() + ]; - $options = array_merge($defaults, $params); + $options = array_merge($defaults, $params); - header('Pragma: public'); - header('Cache-Control: no-cache, no-store, must-revalidate'); - header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $options['modified']) . ' GMT'); - header('Content-Disposition: attachment; filename="' . $options['name'] . '"'); - header('Content-Transfer-Encoding: binary'); + header('Pragma: public'); + header('Cache-Control: no-cache, no-store, must-revalidate'); + header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $options['modified']) . ' GMT'); + header('Content-Disposition: attachment; filename="' . $options['name'] . '"'); + header('Content-Transfer-Encoding: binary'); - static::contentType($options['mime']); + static::contentType($options['mime']); - if ($options['size']) { - header('Content-Length: ' . $options['size']); - } + if ($options['size']) { + header('Content-Length: ' . $options['size']); + } - header('Connection: close'); - } + header('Connection: close'); + } } diff --git a/kirby/src/Http/Idn.php b/kirby/src/Http/Idn.php index b8e1ff9..a9a538f 100755 --- a/kirby/src/Http/Idn.php +++ b/kirby/src/Http/Idn.php @@ -15,61 +15,61 @@ use Kirby\Toolkit\Str; */ class Idn { - /** - * Convert domain name from IDNA ASCII to Unicode - * - * @param string $domain - * @return string|false - */ - public static function decode(string $domain) - { - return idn_to_utf8($domain); - } + /** + * Convert domain name from IDNA ASCII to Unicode + * + * @param string $domain + * @return string|false + */ + public static function decode(string $domain) + { + return idn_to_utf8($domain); + } - /** - * Convert domain name to IDNA ASCII form - * - * @param string $domain - * @return string|false - */ - public static function encode(string $domain) - { - return idn_to_ascii($domain); - } + /** + * Convert domain name to IDNA ASCII form + * + * @param string $domain + * @return string|false + */ + public static function encode(string $domain) + { + return idn_to_ascii($domain); + } - /** - * Decodes a email address to the Unicode format - * - * @param string $email - * @return string - */ - public static function decodeEmail(string $email): string - { - if (Str::contains($email, 'xn--') === true) { - $parts = Str::split($email, '@'); - $address = $parts[0]; - $domain = Idn::decode($parts[1] ?? ''); - $email = $address . '@' . $domain; - } + /** + * Decodes a email address to the Unicode format + * + * @param string $email + * @return string + */ + public static function decodeEmail(string $email): string + { + if (Str::contains($email, 'xn--') === true) { + $parts = Str::split($email, '@'); + $address = $parts[0]; + $domain = Idn::decode($parts[1] ?? ''); + $email = $address . '@' . $domain; + } - return $email; - } + return $email; + } - /** - * Encodes a email address to the Punycode format - * - * @param string $email - * @return string - */ - public static function encodeEmail(string $email): string - { - if (mb_detect_encoding($email, 'ASCII', true) === false) { - $parts = Str::split($email, '@'); - $address = $parts[0]; - $domain = Idn::encode($parts[1] ?? ''); - $email = $address . '@' . $domain; - } + /** + * Encodes a email address to the Punycode format + * + * @param string $email + * @return string + */ + public static function encodeEmail(string $email): string + { + if (mb_detect_encoding($email, 'ASCII', true) === false) { + $parts = Str::split($email, '@'); + $address = $parts[0]; + $domain = Idn::encode($parts[1] ?? ''); + $email = $address . '@' . $domain; + } - return $email; - } + return $email; + } } diff --git a/kirby/src/Http/Params.php b/kirby/src/Http/Params.php index 5e0273d..0b927cb 100755 --- a/kirby/src/Http/Params.php +++ b/kirby/src/Http/Params.php @@ -17,142 +17,142 @@ use Kirby\Toolkit\Str; */ class Params extends Query { - /** - * @var null|string - */ - public static $separator; + /** + * @var null|string + */ + public static $separator; - /** - * Creates a new params object - * - * @param array|string $params - */ - public function __construct($params) - { - if (is_string($params) === true) { - $params = static::extract($params)['params']; - } + /** + * Creates a new params object + * + * @param array|string $params + */ + public function __construct($params) + { + if (is_string($params) === true) { + $params = static::extract($params)['params']; + } - parent::__construct($params ?? []); - } + parent::__construct($params ?? []); + } - /** - * Extract the params from a string or array - * - * @param string|array|null $path - * @return array - */ - public static function extract($path = null): array - { - if (empty($path) === true) { - return [ - 'path' => null, - 'params' => null, - 'slash' => false - ]; - } + /** + * Extract the params from a string or array + * + * @param string|array|null $path + * @return array + */ + public static function extract($path = null): array + { + if (empty($path) === true) { + return [ + 'path' => null, + 'params' => null, + 'slash' => false + ]; + } - $slash = false; + $slash = false; - if (is_string($path) === true) { - $slash = substr($path, -1, 1) === '/'; - $path = Str::split($path, '/'); - } + if (is_string($path) === true) { + $slash = substr($path, -1, 1) === '/'; + $path = Str::split($path, '/'); + } - if (is_array($path) === true) { - $params = []; - $separator = static::separator(); + if (is_array($path) === true) { + $params = []; + $separator = static::separator(); - foreach ($path as $index => $p) { - if (strpos($p, $separator) === false) { - continue; - } + foreach ($path as $index => $p) { + if (strpos($p, $separator) === false) { + continue; + } - $paramParts = Str::split($p, $separator); - $paramKey = $paramParts[0] ?? null; - $paramValue = $paramParts[1] ?? null; + $paramParts = Str::split($p, $separator); + $paramKey = $paramParts[0] ?? null; + $paramValue = $paramParts[1] ?? null; - if ($paramKey !== null) { - $params[$paramKey] = $paramValue; - } + if ($paramKey !== null) { + $params[$paramKey] = $paramValue; + } - unset($path[$index]); - } + unset($path[$index]); + } - return [ - 'path' => $path, - 'params' => $params, - 'slash' => $slash - ]; - } + return [ + 'path' => $path, + 'params' => $params, + 'slash' => $slash + ]; + } - return [ - 'path' => null, - 'params' => null, - 'slash' => false - ]; - } + return [ + 'path' => null, + 'params' => null, + 'slash' => false + ]; + } - /** - * Returns the param separator according - * to the operating system. - * - * Unix = ':' - * Windows = ';' - * - * @return string - */ - public static function separator(): string - { - if (static::$separator !== null) { - return static::$separator; - } + /** + * Returns the param separator according + * to the operating system. + * + * Unix = ':' + * Windows = ';' + * + * @return string + */ + public static function separator(): string + { + if (static::$separator !== null) { + return static::$separator; + } - if (DIRECTORY_SEPARATOR === '/') { - return static::$separator = ':'; - } else { - return static::$separator = ';'; - } - } + if (DIRECTORY_SEPARATOR === '/') { + return static::$separator = ':'; + } else { + return static::$separator = ';'; + } + } - /** - * Converts the params object to a params string - * which can then be used in the URL builder again - * - * @param bool $leadingSlash - * @param bool $trailingSlash - * @return string|null - * - * @todo The argument $leadingSlash is incompatible with - * Query::toString($questionMark = false); the Query class - * should be extracted into a common parent class for both - * Query and Params - * @psalm-suppress ParamNameMismatch - */ - public function toString($leadingSlash = false, $trailingSlash = false): string - { - if ($this->isEmpty() === true) { - return ''; - } + /** + * Converts the params object to a params string + * which can then be used in the URL builder again + * + * @param bool $leadingSlash + * @param bool $trailingSlash + * @return string|null + * + * @todo The argument $leadingSlash is incompatible with + * Query::toString($questionMark = false); the Query class + * should be extracted into a common parent class for both + * Query and Params + * @psalm-suppress ParamNameMismatch + */ + public function toString($leadingSlash = false, $trailingSlash = false): string + { + if ($this->isEmpty() === true) { + return ''; + } - $params = []; - $separator = static::separator(); + $params = []; + $separator = static::separator(); - foreach ($this as $key => $value) { - if ($value !== null && $value !== '') { - $params[] = $key . $separator . $value; - } - } + foreach ($this as $key => $value) { + if ($value !== null && $value !== '') { + $params[] = $key . $separator . $value; + } + } - if (empty($params) === true) { - return ''; - } + if (empty($params) === true) { + return ''; + } - $params = implode('/', $params); + $params = implode('/', $params); - $leadingSlash = $leadingSlash === true ? '/' : null; - $trailingSlash = $trailingSlash === true ? '/' : null; + $leadingSlash = $leadingSlash === true ? '/' : null; + $trailingSlash = $trailingSlash === true ? '/' : null; - return $leadingSlash . $params . $trailingSlash; - } + return $leadingSlash . $params . $trailingSlash; + } } diff --git a/kirby/src/Http/Path.php b/kirby/src/Http/Path.php index 321591b..ca4a77d 100755 --- a/kirby/src/Http/Path.php +++ b/kirby/src/Http/Path.php @@ -17,31 +17,31 @@ use Kirby\Toolkit\Str; */ class Path extends Collection { - public function __construct($items) - { - if (is_string($items) === true) { - $items = Str::split($items, '/'); - } + public function __construct($items) + { + if (is_string($items) === true) { + $items = Str::split($items, '/'); + } - parent::__construct($items ?? []); - } + parent::__construct($items ?? []); + } - public function __toString(): string - { - return $this->toString(); - } + public function __toString(): string + { + return $this->toString(); + } - public function toString(bool $leadingSlash = false, bool $trailingSlash = false): string - { - if (empty($this->data) === true) { - return ''; - } + public function toString(bool $leadingSlash = false, bool $trailingSlash = false): string + { + if (empty($this->data) === true) { + return ''; + } - $path = implode('/', $this->data); + $path = implode('/', $this->data); - $leadingSlash = $leadingSlash === true ? '/' : null; - $trailingSlash = $trailingSlash === true ? '/' : null; + $leadingSlash = $leadingSlash === true ? '/' : null; + $trailingSlash = $trailingSlash === true ? '/' : null; - return $leadingSlash . $path . $trailingSlash; - } + return $leadingSlash . $path . $trailingSlash; + } } diff --git a/kirby/src/Http/Query.php b/kirby/src/Http/Query.php index fe92b4b..89e7f50 100755 --- a/kirby/src/Http/Query.php +++ b/kirby/src/Http/Query.php @@ -17,42 +17,42 @@ use Kirby\Toolkit\Obj; */ class Query extends Obj { - public function __construct($query) - { - if (is_string($query) === true) { - parse_str(ltrim($query, '?'), $query); - } + public function __construct($query) + { + if (is_string($query) === true) { + parse_str(ltrim($query, '?'), $query); + } - parent::__construct($query ?? []); - } + parent::__construct($query ?? []); + } - public function isEmpty(): bool - { - return empty((array)$this) === true; - } + public function isEmpty(): bool + { + return empty((array)$this) === true; + } - public function isNotEmpty(): bool - { - return empty((array)$this) === false; - } + public function isNotEmpty(): bool + { + return empty((array)$this) === false; + } - public function __toString(): string - { - return $this->toString(); - } + public function __toString(): string + { + return $this->toString(); + } - public function toString($questionMark = false): string - { - $query = http_build_query($this, '', '&', PHP_QUERY_RFC3986); + public function toString($questionMark = false): string + { + $query = http_build_query($this, '', '&', PHP_QUERY_RFC3986); - if (empty($query) === true) { - return ''; - } + if (empty($query) === true) { + return ''; + } - if ($questionMark === true) { - $query = '?' . $query; - } + if ($questionMark === true) { + $query = '?' . $query; + } - return $query; - } + return $query; + } } diff --git a/kirby/src/Http/Remote.php b/kirby/src/Http/Remote.php index 612bd04..8325e33 100755 --- a/kirby/src/Http/Remote.php +++ b/kirby/src/Http/Remote.php @@ -20,392 +20,392 @@ use Kirby\Toolkit\Str; */ class Remote { - public const CA_INTERNAL = 1; - public const CA_SYSTEM = 2; + public const CA_INTERNAL = 1; + public const CA_SYSTEM = 2; - /** - * @var array - */ - public static $defaults = [ - 'agent' => null, - 'basicAuth' => null, - 'body' => true, - 'ca' => self::CA_INTERNAL, - 'data' => [], - 'encoding' => 'utf-8', - 'file' => null, - 'headers' => [], - 'method' => 'GET', - 'progress' => null, - 'test' => false, - 'timeout' => 10, - ]; + /** + * @var array + */ + public static $defaults = [ + 'agent' => null, + 'basicAuth' => null, + 'body' => true, + 'ca' => self::CA_INTERNAL, + 'data' => [], + 'encoding' => 'utf-8', + 'file' => null, + 'headers' => [], + 'method' => 'GET', + 'progress' => null, + 'test' => false, + 'timeout' => 10, + ]; - /** - * @var string - */ - public $content; + /** + * @var string + */ + public $content; - /** - * @var resource - */ - public $curl; + /** + * @var resource + */ + public $curl; - /** - * @var array - */ - public $curlopt = []; + /** + * @var array + */ + public $curlopt = []; - /** - * @var int - */ - public $errorCode; + /** + * @var int + */ + public $errorCode; - /** - * @var string - */ - public $errorMessage; + /** + * @var string + */ + public $errorMessage; - /** - * @var array - */ - public $headers = []; + /** + * @var array + */ + public $headers = []; - /** - * @var array - */ - public $info = []; + /** + * @var array + */ + public $info = []; - /** - * @var array - */ - public $options = []; + /** + * @var array + */ + public $options = []; - /** - * Magic getter for request info data - * - * @param string $method - * @param array $arguments - * @return mixed - */ - public function __call(string $method, array $arguments = []) - { - $method = str_replace('-', '_', Str::kebab($method)); - return $this->info[$method] ?? null; - } + /** + * Magic getter for request info data + * + * @param string $method + * @param array $arguments + * @return mixed + */ + public function __call(string $method, array $arguments = []) + { + $method = str_replace('-', '_', Str::kebab($method)); + return $this->info[$method] ?? null; + } - /** - * Constructor - * - * @param string $url - * @param array $options - */ - public function __construct(string $url, array $options = []) - { - $defaults = static::$defaults; + /** + * Constructor + * + * @param string $url + * @param array $options + */ + public function __construct(string $url, array $options = []) + { + $defaults = static::$defaults; - // use the system CA store by default if - // one has been configured in php.ini - $cainfo = ini_get('curl.cainfo'); - if (empty($cainfo) === false && is_file($cainfo) === true) { - $defaults['ca'] = self::CA_SYSTEM; - } + // use the system CA store by default if + // one has been configured in php.ini + $cainfo = ini_get('curl.cainfo'); + if (empty($cainfo) === false && is_file($cainfo) === true) { + $defaults['ca'] = self::CA_SYSTEM; + } - // update the defaults with App config if set; - // request the App instance lazily - $app = App::instance(null, true); - if ($app !== null) { - $defaults = array_merge($defaults, $app->option('remote', [])); - } + // update the defaults with App config if set; + // request the App instance lazily + $app = App::instance(null, true); + if ($app !== null) { + $defaults = array_merge($defaults, $app->option('remote', [])); + } - // set all options - $this->options = array_merge($defaults, $options); + // set all options + $this->options = array_merge($defaults, $options); - // add the url - $this->options['url'] = $url; + // add the url + $this->options['url'] = $url; - // send the request - $this->fetch(); - } + // send the request + $this->fetch(); + } - public static function __callStatic(string $method, array $arguments = []) - { - return new static($arguments[0], array_merge(['method' => strtoupper($method)], $arguments[1] ?? [])); - } + public static function __callStatic(string $method, array $arguments = []) + { + return new static($arguments[0], array_merge(['method' => strtoupper($method)], $arguments[1] ?? [])); + } - /** - * Returns the http status code - * - * @return int|null - */ - public function code(): ?int - { - return $this->info['http_code'] ?? null; - } + /** + * Returns the http status code + * + * @return int|null + */ + public function code(): ?int + { + return $this->info['http_code'] ?? null; + } - /** - * Returns the response content - * - * @return mixed - */ - public function content() - { - return $this->content; - } + /** + * Returns the response content + * + * @return mixed + */ + public function content() + { + return $this->content; + } - /** - * Sets up all curl options and sends the request - * - * @return $this - */ - public function fetch() - { - // curl options - $this->curlopt = [ - CURLOPT_URL => $this->options['url'], - CURLOPT_ENCODING => $this->options['encoding'], - CURLOPT_CONNECTTIMEOUT => $this->options['timeout'], - CURLOPT_TIMEOUT => $this->options['timeout'], - CURLOPT_AUTOREFERER => true, - CURLOPT_RETURNTRANSFER => $this->options['body'], - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 10, - CURLOPT_HEADER => false, - CURLOPT_HEADERFUNCTION => function ($curl, $header) { - $parts = Str::split($header, ':'); + /** + * Sets up all curl options and sends the request + * + * @return $this + */ + public function fetch() + { + // curl options + $this->curlopt = [ + CURLOPT_URL => $this->options['url'], + CURLOPT_ENCODING => $this->options['encoding'], + CURLOPT_CONNECTTIMEOUT => $this->options['timeout'], + CURLOPT_TIMEOUT => $this->options['timeout'], + CURLOPT_AUTOREFERER => true, + CURLOPT_RETURNTRANSFER => $this->options['body'], + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_MAXREDIRS => 10, + CURLOPT_HEADER => false, + CURLOPT_HEADERFUNCTION => function ($curl, $header) { + $parts = Str::split($header, ':'); - if (empty($parts[0]) === false && empty($parts[1]) === false) { - $key = array_shift($parts); - $this->headers[$key] = implode(':', $parts); - } + if (empty($parts[0]) === false && empty($parts[1]) === false) { + $key = array_shift($parts); + $this->headers[$key] = implode(':', $parts); + } - return strlen($header); - } - ]; + return strlen($header); + } + ]; - // determine the TLS CA to use - if ($this->options['ca'] === self::CA_INTERNAL) { - $this->curlopt[CURLOPT_SSL_VERIFYPEER] = true; - $this->curlopt[CURLOPT_CAINFO] = dirname(__DIR__, 2) . '/cacert.pem'; - } elseif ($this->options['ca'] === self::CA_SYSTEM) { - $this->curlopt[CURLOPT_SSL_VERIFYPEER] = true; - } elseif ($this->options['ca'] === false) { - $this->curlopt[CURLOPT_SSL_VERIFYPEER] = false; - } elseif ( - is_string($this->options['ca']) === true && - is_file($this->options['ca']) === true - ) { - $this->curlopt[CURLOPT_SSL_VERIFYPEER] = true; - $this->curlopt[CURLOPT_CAINFO] = $this->options['ca']; - } elseif ( - is_string($this->options['ca']) === true && - is_dir($this->options['ca']) === true - ) { - $this->curlopt[CURLOPT_SSL_VERIFYPEER] = true; - $this->curlopt[CURLOPT_CAPATH] = $this->options['ca']; - } else { - throw new InvalidArgumentException('Invalid "ca" option for the Remote class'); - } + // determine the TLS CA to use + if ($this->options['ca'] === self::CA_INTERNAL) { + $this->curlopt[CURLOPT_SSL_VERIFYPEER] = true; + $this->curlopt[CURLOPT_CAINFO] = dirname(__DIR__, 2) . '/cacert.pem'; + } elseif ($this->options['ca'] === self::CA_SYSTEM) { + $this->curlopt[CURLOPT_SSL_VERIFYPEER] = true; + } elseif ($this->options['ca'] === false) { + $this->curlopt[CURLOPT_SSL_VERIFYPEER] = false; + } elseif ( + is_string($this->options['ca']) === true && + is_file($this->options['ca']) === true + ) { + $this->curlopt[CURLOPT_SSL_VERIFYPEER] = true; + $this->curlopt[CURLOPT_CAINFO] = $this->options['ca']; + } elseif ( + is_string($this->options['ca']) === true && + is_dir($this->options['ca']) === true + ) { + $this->curlopt[CURLOPT_SSL_VERIFYPEER] = true; + $this->curlopt[CURLOPT_CAPATH] = $this->options['ca']; + } else { + throw new InvalidArgumentException('Invalid "ca" option for the Remote class'); + } - // add the progress - if (is_callable($this->options['progress']) === true) { - $this->curlopt[CURLOPT_NOPROGRESS] = false; - $this->curlopt[CURLOPT_PROGRESSFUNCTION] = $this->options['progress']; - } + // add the progress + if (is_callable($this->options['progress']) === true) { + $this->curlopt[CURLOPT_NOPROGRESS] = false; + $this->curlopt[CURLOPT_PROGRESSFUNCTION] = $this->options['progress']; + } - // add all headers - if (empty($this->options['headers']) === false) { - // convert associative arrays to strings - $headers = []; - foreach ($this->options['headers'] as $key => $value) { - if (is_string($key) === true) { - $headers[] = $key . ': ' . $value; - } else { - $headers[] = $value; - } - } + // add all headers + if (empty($this->options['headers']) === false) { + // convert associative arrays to strings + $headers = []; + foreach ($this->options['headers'] as $key => $value) { + if (is_string($key) === true) { + $headers[] = $key . ': ' . $value; + } else { + $headers[] = $value; + } + } - $this->curlopt[CURLOPT_HTTPHEADER] = $headers; - } + $this->curlopt[CURLOPT_HTTPHEADER] = $headers; + } - // add HTTP Basic authentication - if (empty($this->options['basicAuth']) === false) { - $this->curlopt[CURLOPT_USERPWD] = $this->options['basicAuth']; - } + // add HTTP Basic authentication + if (empty($this->options['basicAuth']) === false) { + $this->curlopt[CURLOPT_USERPWD] = $this->options['basicAuth']; + } - // add the user agent - if (empty($this->options['agent']) === false) { - $this->curlopt[CURLOPT_USERAGENT] = $this->options['agent']; - } + // add the user agent + if (empty($this->options['agent']) === false) { + $this->curlopt[CURLOPT_USERAGENT] = $this->options['agent']; + } - // do some request specific stuff - switch (strtoupper($this->options['method'])) { - case 'POST': - $this->curlopt[CURLOPT_POST] = true; - $this->curlopt[CURLOPT_CUSTOMREQUEST] = 'POST'; - $this->curlopt[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']); - break; - case 'PUT': - $this->curlopt[CURLOPT_CUSTOMREQUEST] = 'PUT'; - $this->curlopt[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']); + // do some request specific stuff + switch (strtoupper($this->options['method'])) { + case 'POST': + $this->curlopt[CURLOPT_POST] = true; + $this->curlopt[CURLOPT_CUSTOMREQUEST] = 'POST'; + $this->curlopt[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']); + break; + case 'PUT': + $this->curlopt[CURLOPT_CUSTOMREQUEST] = 'PUT'; + $this->curlopt[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']); - // put a file - if ($this->options['file']) { - $this->curlopt[CURLOPT_INFILE] = fopen($this->options['file'], 'r'); - $this->curlopt[CURLOPT_INFILESIZE] = F::size($this->options['file']); - } - break; - case 'PATCH': - $this->curlopt[CURLOPT_CUSTOMREQUEST] = 'PATCH'; - $this->curlopt[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']); - break; - case 'DELETE': - $this->curlopt[CURLOPT_CUSTOMREQUEST] = 'DELETE'; - $this->curlopt[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']); - break; - case 'HEAD': - $this->curlopt[CURLOPT_CUSTOMREQUEST] = 'HEAD'; - $this->curlopt[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']); - $this->curlopt[CURLOPT_NOBODY] = true; - break; - } + // put a file + if ($this->options['file']) { + $this->curlopt[CURLOPT_INFILE] = fopen($this->options['file'], 'r'); + $this->curlopt[CURLOPT_INFILESIZE] = F::size($this->options['file']); + } + break; + case 'PATCH': + $this->curlopt[CURLOPT_CUSTOMREQUEST] = 'PATCH'; + $this->curlopt[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']); + break; + case 'DELETE': + $this->curlopt[CURLOPT_CUSTOMREQUEST] = 'DELETE'; + $this->curlopt[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']); + break; + case 'HEAD': + $this->curlopt[CURLOPT_CUSTOMREQUEST] = 'HEAD'; + $this->curlopt[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']); + $this->curlopt[CURLOPT_NOBODY] = true; + break; + } - if ($this->options['test'] === true) { - return $this; - } + if ($this->options['test'] === true) { + return $this; + } - // start a curl request - $this->curl = curl_init(); + // start a curl request + $this->curl = curl_init(); - curl_setopt_array($this->curl, $this->curlopt); + curl_setopt_array($this->curl, $this->curlopt); - $this->content = curl_exec($this->curl); - $this->info = curl_getinfo($this->curl); - $this->errorCode = curl_errno($this->curl); - $this->errorMessage = curl_error($this->curl); + $this->content = curl_exec($this->curl); + $this->info = curl_getinfo($this->curl); + $this->errorCode = curl_errno($this->curl); + $this->errorMessage = curl_error($this->curl); - if ($this->errorCode) { - throw new Exception($this->errorMessage, $this->errorCode); - } + if ($this->errorCode) { + throw new Exception($this->errorMessage, $this->errorCode); + } - curl_close($this->curl); + curl_close($this->curl); - return $this; - } + return $this; + } - /** - * Static method to send a GET request - * - * @param string $url - * @param array $params - * @return static - */ - public static function get(string $url, array $params = []) - { - $defaults = [ - 'method' => 'GET', - 'data' => [], - ]; + /** + * Static method to send a GET request + * + * @param string $url + * @param array $params + * @return static + */ + public static function get(string $url, array $params = []) + { + $defaults = [ + 'method' => 'GET', + 'data' => [], + ]; - $options = array_merge($defaults, $params); - $query = http_build_query($options['data']); + $options = array_merge($defaults, $params); + $query = http_build_query($options['data']); - if (empty($query) === false) { - $url = Url::hasQuery($url) === true ? $url . '&' . $query : $url . '?' . $query; - } + if (empty($query) === false) { + $url = Url::hasQuery($url) === true ? $url . '&' . $query : $url . '?' . $query; + } - // remove the data array from the options - unset($options['data']); + // remove the data array from the options + unset($options['data']); - return new static($url, $options); - } + return new static($url, $options); + } - /** - * Returns all received headers - * - * @return array - */ - public function headers(): array - { - return $this->headers; - } + /** + * Returns all received headers + * + * @return array + */ + public function headers(): array + { + return $this->headers; + } - /** - * Returns the request info - * - * @return array - */ - public function info(): array - { - return $this->info; - } + /** + * Returns the request info + * + * @return array + */ + public function info(): array + { + return $this->info; + } - /** - * Decode the response content - * - * @param bool $array decode as array or object - * @return array|\stdClass - */ - public function json(bool $array = true) - { - return json_decode($this->content(), $array); - } + /** + * Decode the response content + * + * @param bool $array decode as array or object + * @return array|\stdClass + */ + public function json(bool $array = true) + { + return json_decode($this->content(), $array); + } - /** - * Returns the request method - * - * @return string - */ - public function method(): string - { - return $this->options['method']; - } + /** + * Returns the request method + * + * @return string + */ + public function method(): string + { + return $this->options['method']; + } - /** - * Returns all options which have been - * set for the current request - * - * @return array - */ - public function options(): array - { - return $this->options; - } + /** + * Returns all options which have been + * set for the current request + * + * @return array + */ + public function options(): array + { + return $this->options; + } - /** - * Internal method to handle post field data - * - * @param mixed $data - * @return mixed - */ - protected function postfields($data) - { - if (is_object($data) || is_array($data)) { - return http_build_query($data); - } else { - return $data; - } - } + /** + * Internal method to handle post field data + * + * @param mixed $data + * @return mixed + */ + protected function postfields($data) + { + if (is_object($data) || is_array($data)) { + return http_build_query($data); + } else { + return $data; + } + } - /** - * Static method to init this class and send a request - * - * @param string $url - * @param array $params - * @return static - */ - public static function request(string $url, array $params = []) - { - return new static($url, $params); - } + /** + * Static method to init this class and send a request + * + * @param string $url + * @param array $params + * @return static + */ + public static function request(string $url, array $params = []) + { + return new static($url, $params); + } - /** - * Returns the request Url - * - * @return string - */ - public function url(): string - { - return $this->options['url']; - } + /** + * Returns the request Url + * + * @return string + */ + public function url(): string + { + return $this->options['url']; + } } diff --git a/kirby/src/Http/Request.php b/kirby/src/Http/Request.php index 0772faa..0b6a897 100755 --- a/kirby/src/Http/Request.php +++ b/kirby/src/Http/Request.php @@ -22,425 +22,425 @@ use Kirby\Toolkit\Str; */ class Request { - public static $authTypes = [ - 'basic' => 'Kirby\Http\Request\Auth\BasicAuth', - 'bearer' => 'Kirby\Http\Request\Auth\BearerAuth', - 'session' => 'Kirby\Http\Request\Auth\SessionAuth', - ]; + public static $authTypes = [ + 'basic' => 'Kirby\Http\Request\Auth\BasicAuth', + 'bearer' => 'Kirby\Http\Request\Auth\BearerAuth', + 'session' => 'Kirby\Http\Request\Auth\SessionAuth', + ]; - /** - * The auth object if available - * - * @var \Kirby\Http\Request\Auth|false|null - */ - protected $auth; + /** + * The auth object if available + * + * @var \Kirby\Http\Request\Auth|false|null + */ + protected $auth; - /** - * The Body object is a wrapper around - * the request body, which parses the contents - * of the body and provides an API to fetch - * particular parts of the body - * - * Examples: - * - * `$request->body()->get('foo')` - * - * @var Body - */ - protected $body; + /** + * The Body object is a wrapper around + * the request body, which parses the contents + * of the body and provides an API to fetch + * particular parts of the body + * + * Examples: + * + * `$request->body()->get('foo')` + * + * @var Body + */ + protected $body; - /** - * The Files object is a wrapper around - * the $_FILES global. It sanitizes the - * $_FILES array and provides an API to fetch - * individual files by key - * - * Examples: - * - * `$request->files()->get('upload')['size']` - * `$request->file('upload')['size']` - * - * @var Files - */ - protected $files; + /** + * The Files object is a wrapper around + * the $_FILES global. It sanitizes the + * $_FILES array and provides an API to fetch + * individual files by key + * + * Examples: + * + * `$request->files()->get('upload')['size']` + * `$request->file('upload')['size']` + * + * @var Files + */ + protected $files; - /** - * The Method type - * - * @var string - */ - protected $method; + /** + * The Method type + * + * @var string + */ + protected $method; - /** - * All options that have been passed to - * the request in the constructor - * - * @var array - */ - protected $options; + /** + * All options that have been passed to + * the request in the constructor + * + * @var array + */ + protected $options; - /** - * The Query object is a wrapper around - * the URL query string, which parses the - * string and provides a clean API to fetch - * particular parts of the query - * - * Examples: - * - * `$request->query()->get('foo')` - * - * @var Query - */ - protected $query; + /** + * The Query object is a wrapper around + * the URL query string, which parses the + * string and provides a clean API to fetch + * particular parts of the query + * + * Examples: + * + * `$request->query()->get('foo')` + * + * @var Query + */ + protected $query; - /** - * Request URL object - * - * @var Uri - */ - protected $url; + /** + * Request URL object + * + * @var Uri + */ + protected $url; - /** - * Creates a new Request object - * You can either pass your own request - * data via the $options array or use - * the data from the incoming request. - * - * @param array $options - */ - public function __construct(array $options = []) - { - $this->options = $options; - $this->method = $this->detectRequestMethod($options['method'] ?? null); + /** + * Creates a new Request object + * You can either pass your own request + * data via the $options array or use + * the data from the incoming request. + * + * @param array $options + */ + public function __construct(array $options = []) + { + $this->options = $options; + $this->method = $this->detectRequestMethod($options['method'] ?? null); - if (isset($options['body']) === true) { - $this->body = is_a($options['body'], Body::class) ? $options['body'] : new Body($options['body']); - } + if (isset($options['body']) === true) { + $this->body = is_a($options['body'], Body::class) ? $options['body'] : new Body($options['body']); + } - if (isset($options['files']) === true) { - $this->files = is_a($options['files'], Files::class) ? $options['files'] : new Files($options['files']); - } + if (isset($options['files']) === true) { + $this->files = is_a($options['files'], Files::class) ? $options['files'] : new Files($options['files']); + } - if (isset($options['query']) === true) { - $this->query = is_a($options['query'], Query::class) === true ? $options['query'] : new Query($options['query']); - } + if (isset($options['query']) === true) { + $this->query = is_a($options['query'], Query::class) === true ? $options['query'] : new Query($options['query']); + } - if (isset($options['url']) === true) { - $this->url = is_a($options['url'], Uri::class) === true ? $options['url'] : new Uri($options['url']); - } - } + if (isset($options['url']) === true) { + $this->url = is_a($options['url'], Uri::class) === true ? $options['url'] : new Uri($options['url']); + } + } - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return [ - 'body' => $this->body(), - 'files' => $this->files(), - 'method' => $this->method(), - 'query' => $this->query(), - 'url' => $this->url()->toString() - ]; - } + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return [ + 'body' => $this->body(), + 'files' => $this->files(), + 'method' => $this->method(), + 'query' => $this->query(), + 'url' => $this->url()->toString() + ]; + } - /** - * Returns the Auth object if authentication is set - * - * @return \Kirby\Http\Request\Auth|null - */ - public function auth() - { - if ($this->auth !== null) { - return $this->auth; - } + /** + * Returns the Auth object if authentication is set + * + * @return \Kirby\Http\Request\Auth|null + */ + public function auth() + { + if ($this->auth !== null) { + return $this->auth; + } - // lazily request the instance for non-CMS use cases - $kirby = App::instance(null, true); + // lazily request the instance for non-CMS use cases + $kirby = App::instance(null, true); - // tell the CMS responder that the response relies on - // the `Authorization` header and its value (even if - // the header isn't set in the current request); - // this ensures that the response is only cached for - // unauthenticated visitors; - // https://github.com/getkirby/kirby/issues/4423#issuecomment-1166300526 - if ($kirby) { - $kirby->response()->usesAuth(true); - } + // tell the CMS responder that the response relies on + // the `Authorization` header and its value (even if + // the header isn't set in the current request); + // this ensures that the response is only cached for + // unauthenticated visitors; + // https://github.com/getkirby/kirby/issues/4423#issuecomment-1166300526 + if ($kirby) { + $kirby->response()->usesAuth(true); + } - if ($auth = $this->options['auth'] ?? $this->header('authorization')) { - $type = Str::lower(Str::before($auth, ' ')); - $data = Str::after($auth, ' '); + if ($auth = $this->options['auth'] ?? $this->header('authorization')) { + $type = Str::lower(Str::before($auth, ' ')); + $data = Str::after($auth, ' '); - $class = static::$authTypes[$type] ?? null; - if (!$class || class_exists($class) === false) { - return $this->auth = false; - } + $class = static::$authTypes[$type] ?? null; + if (!$class || class_exists($class) === false) { + return $this->auth = false; + } - $object = new $class($data); + $object = new $class($data); - return $this->auth = $object; - } + return $this->auth = $object; + } - return $this->auth = false; - } + return $this->auth = false; + } - /** - * Returns the Body object - * - * @return \Kirby\Http\Request\Body - */ - public function body() - { - return $this->body ??= new Body(); - } + /** + * Returns the Body object + * + * @return \Kirby\Http\Request\Body + */ + public function body() + { + return $this->body ??= new Body(); + } - /** - * Checks if the request has been made from the command line - * - * @return bool - */ - public function cli(): bool - { - return $this->options['cli'] ?? (new Environment())->cli(); - } + /** + * Checks if the request has been made from the command line + * + * @return bool + */ + public function cli(): bool + { + return $this->options['cli'] ?? (new Environment())->cli(); + } - /** - * Returns a CSRF token if stored in a header or the query - * - * @return string|null - */ - public function csrf(): ?string - { - return $this->header('x-csrf') ?? $this->query()->get('csrf'); - } + /** + * Returns a CSRF token if stored in a header or the query + * + * @return string|null + */ + public function csrf(): ?string + { + return $this->header('x-csrf') ?? $this->query()->get('csrf'); + } - /** - * Returns the request input as array - * - * @return array - */ - public function data(): array - { - return array_merge($this->body()->toArray(), $this->query()->toArray()); - } + /** + * Returns the request input as array + * + * @return array + */ + public function data(): array + { + return array_merge($this->body()->toArray(), $this->query()->toArray()); + } - /** - * Detect the request method from various - * options: given method, query string, server vars - * - * @param string $method - * @return string - */ - public function detectRequestMethod(string $method = null): string - { - // all possible methods - $methods = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH']; + /** + * Detect the request method from various + * options: given method, query string, server vars + * + * @param string $method + * @return string + */ + public function detectRequestMethod(string $method = null): string + { + // all possible methods + $methods = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH']; - // the request method can be overwritten with a header - $methodOverride = strtoupper(Environment::getGlobally('HTTP_X_HTTP_METHOD_OVERRIDE', '')); + // the request method can be overwritten with a header + $methodOverride = strtoupper(Environment::getGlobally('HTTP_X_HTTP_METHOD_OVERRIDE', '')); - if ($method === null && in_array($methodOverride, $methods) === true) { - $method = $methodOverride; - } + if ($method === null && in_array($methodOverride, $methods) === true) { + $method = $methodOverride; + } - // final chain of options to detect the method - $method = $method ?? Environment::getGlobally('REQUEST_METHOD', 'GET'); + // final chain of options to detect the method + $method = $method ?? Environment::getGlobally('REQUEST_METHOD', 'GET'); - // uppercase the shit out of it - $method = strtoupper($method); + // uppercase the shit out of it + $method = strtoupper($method); - // sanitize the method - if (in_array($method, $methods) === false) { - $method = 'GET'; - } + // sanitize the method + if (in_array($method, $methods) === false) { + $method = 'GET'; + } - return $method; - } + return $method; + } - /** - * Returns the domain - * - * @return string - */ - public function domain(): string - { - return $this->url()->domain(); - } + /** + * Returns the domain + * + * @return string + */ + public function domain(): string + { + return $this->url()->domain(); + } - /** - * Fetches a single file array - * from the Files object by key - * - * @param string $key - * @return array|null - */ - public function file(string $key) - { - return $this->files()->get($key); - } + /** + * Fetches a single file array + * from the Files object by key + * + * @param string $key + * @return array|null + */ + public function file(string $key) + { + return $this->files()->get($key); + } - /** - * Returns the Files object - * - * @return \Kirby\Cms\Files - */ - public function files() - { - return $this->files ??= new Files(); - } + /** + * Returns the Files object + * + * @return \Kirby\Cms\Files + */ + public function files() + { + return $this->files ??= new Files(); + } - /** - * Returns any data field from the request - * if it exists - * - * @param string|null|array $key - * @param mixed $fallback - * @return mixed - */ - public function get($key = null, $fallback = null) - { - return A::get($this->data(), $key, $fallback); - } + /** + * Returns any data field from the request + * if it exists + * + * @param string|null|array $key + * @param mixed $fallback + * @return mixed + */ + public function get($key = null, $fallback = null) + { + return A::get($this->data(), $key, $fallback); + } - /** - * Returns whether the request contains - * the `Authorization` header - * @since 3.7.0 - * - * @return bool - */ - public function hasAuth(): bool - { - $header = $this->options['auth'] ?? $this->header('authorization'); + /** + * Returns whether the request contains + * the `Authorization` header + * @since 3.7.0 + * + * @return bool + */ + public function hasAuth(): bool + { + $header = $this->options['auth'] ?? $this->header('authorization'); - return $header !== null; - } + return $header !== null; + } - /** - * Returns a header by key if it exists - * - * @param string $key - * @param mixed $fallback - * @return mixed - */ - public function header(string $key, $fallback = null) - { - $headers = array_change_key_case($this->headers()); - return $headers[strtolower($key)] ?? $fallback; - } + /** + * Returns a header by key if it exists + * + * @param string $key + * @param mixed $fallback + * @return mixed + */ + public function header(string $key, $fallback = null) + { + $headers = array_change_key_case($this->headers()); + return $headers[strtolower($key)] ?? $fallback; + } - /** - * Return all headers with polyfill for - * missing getallheaders function - * - * @return array - */ - public function headers(): array - { - $headers = []; + /** + * Return all headers with polyfill for + * missing getallheaders function + * + * @return array + */ + public function headers(): array + { + $headers = []; - foreach (Environment::getGlobally() as $key => $value) { - if (substr($key, 0, 5) !== 'HTTP_' && substr($key, 0, 14) !== 'REDIRECT_HTTP_') { - continue; - } + foreach (Environment::getGlobally() as $key => $value) { + if (substr($key, 0, 5) !== 'HTTP_' && substr($key, 0, 14) !== 'REDIRECT_HTTP_') { + continue; + } - // remove HTTP_ - $key = str_replace(['REDIRECT_HTTP_', 'HTTP_'], '', $key); + // remove HTTP_ + $key = str_replace(['REDIRECT_HTTP_', 'HTTP_'], '', $key); - // convert to lowercase - $key = strtolower($key); + // convert to lowercase + $key = strtolower($key); - // replace _ with spaces - $key = str_replace('_', ' ', $key); + // replace _ with spaces + $key = str_replace('_', ' ', $key); - // uppercase first char in each word - $key = ucwords($key); + // uppercase first char in each word + $key = ucwords($key); - // convert spaces to dashes - $key = str_replace(' ', '-', $key); + // convert spaces to dashes + $key = str_replace(' ', '-', $key); - $headers[$key] = $value; - } + $headers[$key] = $value; + } - return $headers; - } + return $headers; + } - /** - * Checks if the given method name - * matches the name of the request method. - * - * @param string $method - * @return bool - */ - public function is(string $method): bool - { - return strtoupper($this->method) === strtoupper($method); - } + /** + * Checks if the given method name + * matches the name of the request method. + * + * @param string $method + * @return bool + */ + public function is(string $method): bool + { + return strtoupper($this->method) === strtoupper($method); + } - /** - * Returns the request method - * - * @return string - */ - public function method(): string - { - return $this->method; - } + /** + * Returns the request method + * + * @return string + */ + public function method(): string + { + return $this->method; + } - /** - * Shortcut to the Params object - */ - public function params() - { - return $this->url()->params(); - } + /** + * Shortcut to the Params object + */ + public function params() + { + return $this->url()->params(); + } - /** - * Shortcut to the Path object - */ - public function path() - { - return $this->url()->path(); - } + /** + * Shortcut to the Path object + */ + public function path() + { + return $this->url()->path(); + } - /** - * Returns the Query object - * - * @return \Kirby\Http\Request\Query - */ - public function query() - { - return $this->query ??= new Query(); - } + /** + * Returns the Query object + * + * @return \Kirby\Http\Request\Query + */ + public function query() + { + return $this->query ??= new Query(); + } - /** - * Checks for a valid SSL connection - * - * @return bool - */ - public function ssl(): bool - { - return $this->url()->scheme() === 'https'; - } + /** + * Checks for a valid SSL connection + * + * @return bool + */ + public function ssl(): bool + { + return $this->url()->scheme() === 'https'; + } - /** - * Returns the current Uri object. - * If you pass props you can safely modify - * the Url with new parameters without destroying - * the original object. - * - * @param array $props - * @return \Kirby\Http\Uri - */ - public function url(array $props = null) - { - if ($props !== null) { - return $this->url()->clone($props); - } + /** + * Returns the current Uri object. + * If you pass props you can safely modify + * the Url with new parameters without destroying + * the original object. + * + * @param array $props + * @return \Kirby\Http\Uri + */ + public function url(array $props = null) + { + if ($props !== null) { + return $this->url()->clone($props); + } - return $this->url ??= Uri::current(); - } + return $this->url ??= Uri::current(); + } } diff --git a/kirby/src/Http/Request/Auth.php b/kirby/src/Http/Request/Auth.php index 62f4c68..032ca11 100755 --- a/kirby/src/Http/Request/Auth.php +++ b/kirby/src/Http/Request/Auth.php @@ -13,49 +13,49 @@ namespace Kirby\Http\Request; */ abstract class Auth { - /** - * Raw authentication data after the first space - * in the `Authorization` header - * - * @var string - */ - protected $data; + /** + * Raw authentication data after the first space + * in the `Authorization` header + * + * @var string + */ + protected $data; - /** - * Constructor - * - * @param string $data - */ - public function __construct(string $data) - { - $this->data = $data; - } + /** + * Constructor + * + * @param string $data + */ + public function __construct(string $data) + { + $this->data = $data; + } - /** - * Converts the object to a string - * - * @return string - */ - public function __toString(): string - { - return ucfirst($this->type()) . ' ' . $this->data(); - } + /** + * Converts the object to a string + * + * @return string + */ + public function __toString(): string + { + return ucfirst($this->type()) . ' ' . $this->data(); + } - /** - * Returns the raw authentication data after the - * first space in the `Authorization` header - * - * @return string - */ - public function data(): string - { - return $this->data; - } + /** + * Returns the raw authentication data after the + * first space in the `Authorization` header + * + * @return string + */ + public function data(): string + { + return $this->data; + } - /** - * Returns the name of the auth type (lowercase) - * - * @return string - */ - abstract public function type(): string; + /** + * Returns the name of the auth type (lowercase) + * + * @return string + */ + abstract public function type(): string; } diff --git a/kirby/src/Http/Request/Auth/BasicAuth.php b/kirby/src/Http/Request/Auth/BasicAuth.php index 0618e7a..3d6e70e 100755 --- a/kirby/src/Http/Request/Auth/BasicAuth.php +++ b/kirby/src/Http/Request/Auth/BasicAuth.php @@ -16,70 +16,70 @@ use Kirby\Toolkit\Str; */ class BasicAuth extends Auth { - /** - * @var string - */ - protected $credentials; + /** + * @var string + */ + protected $credentials; - /** - * @var string - */ - protected $password; + /** + * @var string + */ + protected $password; - /** - * @var string - */ - protected $username; + /** + * @var string + */ + protected $username; - /** - * @param string $token - */ - public function __construct(string $data) - { - parent::__construct($data); + /** + * @param string $token + */ + public function __construct(string $data) + { + parent::__construct($data); - $this->credentials = base64_decode($data); - $this->username = Str::before($this->credentials, ':'); - $this->password = Str::after($this->credentials, ':'); - } + $this->credentials = base64_decode($data); + $this->username = Str::before($this->credentials, ':'); + $this->password = Str::after($this->credentials, ':'); + } - /** - * Returns the entire unencoded credentials string - * - * @return string - */ - public function credentials(): string - { - return $this->credentials; - } + /** + * Returns the entire unencoded credentials string + * + * @return string + */ + public function credentials(): string + { + return $this->credentials; + } - /** - * Returns the password - * - * @return string|null - */ - public function password(): ?string - { - return $this->password; - } + /** + * Returns the password + * + * @return string|null + */ + public function password(): ?string + { + return $this->password; + } - /** - * Returns the authentication type - * - * @return string - */ - public function type(): string - { - return 'basic'; - } + /** + * Returns the authentication type + * + * @return string + */ + public function type(): string + { + return 'basic'; + } - /** - * Returns the username - * - * @return string|null - */ - public function username(): ?string - { - return $this->username; - } + /** + * Returns the username + * + * @return string|null + */ + public function username(): ?string + { + return $this->username; + } } diff --git a/kirby/src/Http/Request/Auth/BearerAuth.php b/kirby/src/Http/Request/Auth/BearerAuth.php index 860fdb1..e287606 100755 --- a/kirby/src/Http/Request/Auth/BearerAuth.php +++ b/kirby/src/Http/Request/Auth/BearerAuth.php @@ -15,23 +15,23 @@ use Kirby\Http\Request\Auth; */ class BearerAuth extends Auth { - /** - * Returns the authentication token - * - * @return string - */ - public function token(): string - { - return $this->data; - } + /** + * Returns the authentication token + * + * @return string + */ + public function token(): string + { + return $this->data; + } - /** - * Returns the auth type - * - * @return string - */ - public function type(): string - { - return 'bearer'; - } + /** + * Returns the auth type + * + * @return string + */ + public function type(): string + { + return 'bearer'; + } } diff --git a/kirby/src/Http/Request/Auth/SessionAuth.php b/kirby/src/Http/Request/Auth/SessionAuth.php index bf6fdcd..1ce29be 100755 --- a/kirby/src/Http/Request/Auth/SessionAuth.php +++ b/kirby/src/Http/Request/Auth/SessionAuth.php @@ -16,33 +16,33 @@ use Kirby\Http\Request\Auth; */ class SessionAuth extends Auth { - /** - * Tries to return the session object - * - * @return \Kirby\Session\Session - */ - public function session() - { - return App::instance()->sessionHandler()->getManually($this->data); - } + /** + * Tries to return the session object + * + * @return \Kirby\Session\Session + */ + public function session() + { + return App::instance()->sessionHandler()->getManually($this->data); + } - /** - * Returns the session token - * - * @return string - */ - public function token(): string - { - return $this->data; - } + /** + * Returns the session token + * + * @return string + */ + public function token(): string + { + return $this->data; + } - /** - * Returns the authentication type - * - * @return string - */ - public function type(): string - { - return 'session'; - } + /** + * Returns the authentication type + * + * @return string + */ + public function type(): string + { + return 'session'; + } } diff --git a/kirby/src/Http/Request/Body.php b/kirby/src/Http/Request/Body.php index 3ebecbc..df6f330 100755 --- a/kirby/src/Http/Request/Body.php +++ b/kirby/src/Http/Request/Body.php @@ -16,114 +16,114 @@ namespace Kirby\Http\Request; */ class Body { - use Data; + use Data; - /** - * The raw body content - * - * @var string|array - */ - protected $contents; + /** + * The raw body content + * + * @var string|array + */ + protected $contents; - /** - * The parsed content as array - * - * @var array - */ - protected $data; + /** + * The parsed content as array + * + * @var array + */ + protected $data; - /** - * Creates a new request body object. - * You can pass your own array or string. - * If null is being passed, the class will - * fetch the body either from the $_POST global - * or from php://input. - * - * @param array|string|null $contents - */ - public function __construct($contents = null) - { - $this->contents = $contents; - } + /** + * Creates a new request body object. + * You can pass your own array or string. + * If null is being passed, the class will + * fetch the body either from the $_POST global + * or from php://input. + * + * @param array|string|null $contents + */ + public function __construct($contents = null) + { + $this->contents = $contents; + } - /** - * Fetches the raw contents for the body - * or uses the passed contents. - * - * @return string|array - */ - public function contents() - { - if ($this->contents === null) { - if (empty($_POST) === false) { - $this->contents = $_POST; - } else { - $this->contents = file_get_contents('php://input'); - } - } + /** + * Fetches the raw contents for the body + * or uses the passed contents. + * + * @return string|array + */ + public function contents() + { + if ($this->contents === null) { + if (empty($_POST) === false) { + $this->contents = $_POST; + } else { + $this->contents = file_get_contents('php://input'); + } + } - return $this->contents; - } + return $this->contents; + } - /** - * Parses the raw contents once and caches - * the result. The parser will try to convert - * the body with the json decoder first and - * then run parse_str to get some results - * if the json decoder failed. - * - * @return array - */ - public function data(): array - { - if (is_array($this->data) === true) { - return $this->data; - } + /** + * Parses the raw contents once and caches + * the result. The parser will try to convert + * the body with the json decoder first and + * then run parse_str to get some results + * if the json decoder failed. + * + * @return array + */ + public function data(): array + { + if (is_array($this->data) === true) { + return $this->data; + } - $contents = $this->contents(); + $contents = $this->contents(); - // return content which is already in array form - if (is_array($contents) === true) { - return $this->data = $contents; - } + // return content which is already in array form + if (is_array($contents) === true) { + return $this->data = $contents; + } - // try to convert the body from json - $json = json_decode($contents, true); + // try to convert the body from json + $json = json_decode($contents, true); - if (is_array($json) === true) { - return $this->data = $json; - } + if (is_array($json) === true) { + return $this->data = $json; + } - if (strstr($contents, '=') !== false) { - // try to parse the body as query string - parse_str($contents, $parsed); + if (strstr($contents, '=') !== false) { + // try to parse the body as query string + parse_str($contents, $parsed); - if (is_array($parsed)) { - return $this->data = $parsed; - } - } + if (is_array($parsed)) { + return $this->data = $parsed; + } + } - return $this->data = []; - } + return $this->data = []; + } - /** - * Converts the data array back - * to a http query string - * - * @return string - */ - public function toString(): string - { - return http_build_query($this->data()); - } + /** + * Converts the data array back + * to a http query string + * + * @return string + */ + public function toString(): string + { + return http_build_query($this->data()); + } - /** - * Magic string converter - * - * @return string - */ - public function __toString(): string - { - return $this->toString(); - } + /** + * Magic string converter + * + * @return string + */ + public function __toString(): string + { + return $this->toString(); + } } diff --git a/kirby/src/Http/Request/Data.php b/kirby/src/Http/Request/Data.php index d9c4af8..8826c90 100755 --- a/kirby/src/Http/Request/Data.php +++ b/kirby/src/Http/Request/Data.php @@ -18,67 +18,67 @@ namespace Kirby\Http\Request; */ trait Data { - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return $this->toArray(); - } + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return $this->toArray(); + } - /** - * The data provider method has to be - * implemented by each class using this Trait - * and has to return an associative array - * for the get method - * - * @return array - */ - abstract public function data(): array; + /** + * The data provider method has to be + * implemented by each class using this Trait + * and has to return an associative array + * for the get method + * + * @return array + */ + abstract public function data(): array; - /** - * The get method is the heart and soul of this - * Trait. You can use it to fetch a single value - * of the data array by key or multiple values by - * passing an array of keys. - * - * @param string|array $key - * @param mixed|null $default - * @return mixed - */ - public function get($key, $default = null) - { - if (is_array($key) === true) { - $result = []; - foreach ($key as $k) { - $result[$k] = $this->get($k); - } - return $result; - } + /** + * The get method is the heart and soul of this + * Trait. You can use it to fetch a single value + * of the data array by key or multiple values by + * passing an array of keys. + * + * @param string|array $key + * @param mixed|null $default + * @return mixed + */ + public function get($key, $default = null) + { + if (is_array($key) === true) { + $result = []; + foreach ($key as $k) { + $result[$k] = $this->get($k); + } + return $result; + } - return $this->data()[$key] ?? $default; - } + return $this->data()[$key] ?? $default; + } - /** - * Returns the data array. - * This is basically an alias for Data::data() - * - * @return array - */ - public function toArray(): array - { - return $this->data(); - } + /** + * Returns the data array. + * This is basically an alias for Data::data() + * + * @return array + */ + public function toArray(): array + { + return $this->data(); + } - /** - * Converts the data array to json - * - * @return string - */ - public function toJson(): string - { - return json_encode($this->data()); - } + /** + * Converts the data array to json + * + * @return string + */ + public function toJson(): string + { + return json_encode($this->data()); + } } diff --git a/kirby/src/Http/Request/Files.php b/kirby/src/Http/Request/Files.php index 7a515c9..a23263a 100755 --- a/kirby/src/Http/Request/Files.php +++ b/kirby/src/Http/Request/Files.php @@ -17,57 +17,57 @@ namespace Kirby\Http\Request; */ class Files { - use Data; + use Data; - /** - * Sanitized array of all received files - * - * @var array - */ - protected $files; + /** + * Sanitized array of all received files + * + * @var array + */ + protected $files; - /** - * Creates a new Files object - * Pass your own array to mock - * uploads. - * - * @param array|null $files - */ - public function __construct($files = null) - { - if ($files === null) { - $files = $_FILES; - } + /** + * Creates a new Files object + * Pass your own array to mock + * uploads. + * + * @param array|null $files + */ + public function __construct($files = null) + { + if ($files === null) { + $files = $_FILES; + } - $this->files = []; + $this->files = []; - foreach ($files as $key => $file) { - if (is_array($file['name'])) { - foreach ($file['name'] as $i => $name) { - $this->files[$key][] = [ - 'name' => $file['name'][$i] ?? null, - 'type' => $file['type'][$i] ?? null, - 'tmp_name' => $file['tmp_name'][$i] ?? null, - 'error' => $file['error'][$i] ?? null, - 'size' => $file['size'][$i] ?? null, - ]; - } - } else { - $this->files[$key] = $file; - } - } - } + foreach ($files as $key => $file) { + if (is_array($file['name'])) { + foreach ($file['name'] as $i => $name) { + $this->files[$key][] = [ + 'name' => $file['name'][$i] ?? null, + 'type' => $file['type'][$i] ?? null, + 'tmp_name' => $file['tmp_name'][$i] ?? null, + 'error' => $file['error'][$i] ?? null, + 'size' => $file['size'][$i] ?? null, + ]; + } + } else { + $this->files[$key] = $file; + } + } + } - /** - * The data method returns the files - * array. This is only needed to make - * the Data trait work for the Files::get($key) - * method. - * - * @return array - */ - public function data(): array - { - return $this->files; - } + /** + * The data method returns the files + * array. This is only needed to make + * the Data trait work for the Files::get($key) + * method. + * + * @return array + */ + public function data(): array + { + return $this->files; + } } diff --git a/kirby/src/Http/Request/Query.php b/kirby/src/Http/Request/Query.php index 5e681e4..315a683 100755 --- a/kirby/src/Http/Request/Query.php +++ b/kirby/src/Http/Request/Query.php @@ -15,84 +15,84 @@ namespace Kirby\Http\Request; */ class Query { - use Data; + use Data; - /** - * The Query data array - * - * @var array|null - */ - protected $data; + /** + * The Query data array + * + * @var array|null + */ + protected $data; - /** - * Creates a new Query object. - * The passed data can be an array - * or a parsable query string. If - * null is passed, the current Query - * will be taken from $_GET - * - * @param array|string|null $data - */ - public function __construct($data = null) - { - if ($data === null) { - $this->data = $_GET; - } elseif (is_array($data)) { - $this->data = $data; - } else { - parse_str($data, $parsed); - $this->data = $parsed; - } - } + /** + * Creates a new Query object. + * The passed data can be an array + * or a parsable query string. If + * null is passed, the current Query + * will be taken from $_GET + * + * @param array|string|null $data + */ + public function __construct($data = null) + { + if ($data === null) { + $this->data = $_GET; + } elseif (is_array($data)) { + $this->data = $data; + } else { + parse_str($data, $parsed); + $this->data = $parsed; + } + } - /** - * Returns the Query data as array - * - * @return array - */ - public function data(): array - { - return $this->data; - } + /** + * Returns the Query data as array + * + * @return array + */ + public function data(): array + { + return $this->data; + } - /** - * Returns `true` if the request doesn't contain query variables - * - * @return bool - */ - public function isEmpty(): bool - { - return empty($this->data) === true; - } + /** + * Returns `true` if the request doesn't contain query variables + * + * @return bool + */ + public function isEmpty(): bool + { + return empty($this->data) === true; + } - /** - * Returns `true` if the request contains query variables - * - * @return bool - */ - public function isNotEmpty(): bool - { - return empty($this->data) === false; - } + /** + * Returns `true` if the request contains query variables + * + * @return bool + */ + public function isNotEmpty(): bool + { + return empty($this->data) === false; + } - /** - * Converts the query data array - * back to a query string - * - * @return string - */ - public function toString(): string - { - return http_build_query($this->data()); - } + /** + * Converts the query data array + * back to a query string + * + * @return string + */ + public function toString(): string + { + return http_build_query($this->data()); + } - /** - * Magic string converter - * - * @return string - */ - public function __toString(): string - { - return $this->toString(); - } + /** + * Magic string converter + * + * @return string + */ + public function __toString(): string + { + return $this->toString(); + } } diff --git a/kirby/src/Http/Response.php b/kirby/src/Http/Response.php index 4455b2b..6b1e487 100755 --- a/kirby/src/Http/Response.php +++ b/kirby/src/Http/Response.php @@ -19,316 +19,316 @@ use Throwable; */ class Response { - /** - * Store for all registered headers, - * which will be sent with the response - * - * @var array - */ - protected $headers = []; + /** + * Store for all registered headers, + * which will be sent with the response + * + * @var array + */ + protected $headers = []; - /** - * The response body - * - * @var string - */ - protected $body; + /** + * The response body + * + * @var string + */ + protected $body; - /** - * The HTTP response code - * - * @var int - */ - protected $code; + /** + * The HTTP response code + * + * @var int + */ + protected $code; - /** - * The content type for the response - * - * @var string - */ - protected $type; + /** + * The content type for the response + * + * @var string + */ + protected $type; - /** - * The content type charset - * - * @var string - */ - protected $charset = 'UTF-8'; + /** + * The content type charset + * + * @var string + */ + protected $charset = 'UTF-8'; - /** - * Creates a new response object - * - * @param string $body - * @param string $type - * @param int $code - * @param array $headers - * @param string $charset - */ - public function __construct($body = '', ?string $type = null, ?int $code = null, ?array $headers = null, ?string $charset = null) - { - // array construction - if (is_array($body) === true) { - $params = $body; - $body = $params['body'] ?? ''; - $type = $params['type'] ?? $type; - $code = $params['code'] ?? $code; - $headers = $params['headers'] ?? $headers; - $charset = $params['charset'] ?? $charset; - } + /** + * Creates a new response object + * + * @param string $body + * @param string $type + * @param int $code + * @param array $headers + * @param string $charset + */ + public function __construct($body = '', ?string $type = null, ?int $code = null, ?array $headers = null, ?string $charset = null) + { + // array construction + if (is_array($body) === true) { + $params = $body; + $body = $params['body'] ?? ''; + $type = $params['type'] ?? $type; + $code = $params['code'] ?? $code; + $headers = $params['headers'] ?? $headers; + $charset = $params['charset'] ?? $charset; + } - // regular construction - $this->body = $body; - $this->type = $type ?? 'text/html'; - $this->code = $code ?? 200; - $this->headers = $headers ?? []; - $this->charset = $charset ?? 'UTF-8'; + // regular construction + $this->body = $body; + $this->type = $type ?? 'text/html'; + $this->code = $code ?? 200; + $this->headers = $headers ?? []; + $this->charset = $charset ?? 'UTF-8'; - // automatic mime type detection - if (strpos($this->type, '/') === false) { - $this->type = F::extensionToMime($this->type) ?? 'text/html'; - } - } + // automatic mime type detection + if (strpos($this->type, '/') === false) { + $this->type = F::extensionToMime($this->type) ?? 'text/html'; + } + } - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return $this->toArray(); - } + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return $this->toArray(); + } - /** - * Makes it possible to convert the - * entire response object to a string - * to send the headers and print the body - * - * @return string - */ - public function __toString(): string - { - try { - return $this->send(); - } catch (Throwable $e) { - return ''; - } - } + /** + * Makes it possible to convert the + * entire response object to a string + * to send the headers and print the body + * + * @return string + */ + public function __toString(): string + { + try { + return $this->send(); + } catch (Throwable $e) { + return ''; + } + } - /** - * Getter for the body - * - * @return string - */ - public function body(): string - { - return $this->body; - } + /** + * Getter for the body + * + * @return string + */ + public function body(): string + { + return $this->body; + } - /** - * Getter for the content type charset - * - * @return string - */ - public function charset(): string - { - return $this->charset; - } + /** + * Getter for the content type charset + * + * @return string + */ + public function charset(): string + { + return $this->charset; + } - /** - * Getter for the HTTP status code - * - * @return int - */ - public function code(): int - { - return $this->code; - } + /** + * Getter for the HTTP status code + * + * @return int + */ + public function code(): int + { + return $this->code; + } - /** - * Creates a response that triggers - * a file download for the given file - * - * @param string $file - * @param string $filename - * @param array $props Custom overrides for response props (e.g. headers) - * @return static - */ - public static function download(string $file, string $filename = null, array $props = []) - { - if (file_exists($file) === false) { - throw new Exception('The file could not be found'); - } + /** + * Creates a response that triggers + * a file download for the given file + * + * @param string $file + * @param string $filename + * @param array $props Custom overrides for response props (e.g. headers) + * @return static + */ + public static function download(string $file, string $filename = null, array $props = []) + { + if (file_exists($file) === false) { + throw new Exception('The file could not be found'); + } - $filename ??= basename($file); - $modified = filemtime($file); - $body = file_get_contents($file); - $size = strlen($body); + $filename ??= basename($file); + $modified = filemtime($file); + $body = file_get_contents($file); + $size = strlen($body); - $props = array_replace_recursive([ - 'body' => $body, - 'type' => F::mime($file), - 'headers' => [ - 'Pragma' => 'public', - 'Cache-Control' => 'no-cache, no-store, must-revalidate', - 'Last-Modified' => gmdate('D, d M Y H:i:s', $modified) . ' GMT', - 'Content-Disposition' => 'attachment; filename="' . $filename . '"', - 'Content-Transfer-Encoding' => 'binary', - 'Content-Length' => $size, - 'Connection' => 'close' - ] - ], $props); + $props = array_replace_recursive([ + 'body' => $body, + 'type' => F::mime($file), + 'headers' => [ + 'Pragma' => 'public', + 'Cache-Control' => 'no-cache, no-store, must-revalidate', + 'Last-Modified' => gmdate('D, d M Y H:i:s', $modified) . ' GMT', + 'Content-Disposition' => 'attachment; filename="' . $filename . '"', + 'Content-Transfer-Encoding' => 'binary', + 'Content-Length' => $size, + 'Connection' => 'close' + ] + ], $props); - return new static($props); - } + return new static($props); + } - /** - * Creates a response for a file and - * sends the file content to the browser - * - * @param string $file - * @param array $props Custom overrides for response props (e.g. headers) - * @return static - */ - public static function file(string $file, array $props = []) - { - $props = array_merge([ - 'body' => F::read($file), - 'type' => F::extensionToMime(F::extension($file)) - ], $props); + /** + * Creates a response for a file and + * sends the file content to the browser + * + * @param string $file + * @param array $props Custom overrides for response props (e.g. headers) + * @return static + */ + public static function file(string $file, array $props = []) + { + $props = array_merge([ + 'body' => F::read($file), + 'type' => F::extensionToMime(F::extension($file)) + ], $props); - return new static($props); - } + return new static($props); + } - /** - * Redirects to the given Urls - * Urls can be relative or absolute. - * @since 3.7.0 - * - * @param string $url - * @param int $code - * @return void - * - * @codeCoverageIgnore - */ - public static function go(string $url = '/', int $code = 302) - { - die(static::redirect($url, $code)); - } + /** + * Redirects to the given Urls + * Urls can be relative or absolute. + * @since 3.7.0 + * + * @param string $url + * @param int $code + * @return void + * + * @codeCoverageIgnore + */ + public static function go(string $url = '/', int $code = 302) + { + die(static::redirect($url, $code)); + } - /** - * Getter for single headers - * - * @param string $key Name of the header - * @return string|null - */ - public function header(string $key): ?string - { - return $this->headers[$key] ?? null; - } + /** + * Getter for single headers + * + * @param string $key Name of the header + * @return string|null + */ + public function header(string $key): ?string + { + return $this->headers[$key] ?? null; + } - /** - * Getter for all headers - * - * @return array - */ - public function headers(): array - { - return $this->headers; - } + /** + * Getter for all headers + * + * @return array + */ + public function headers(): array + { + return $this->headers; + } - /** - * Creates a json response with appropriate - * header and automatic conversion of arrays. - * - * @param string|array $body - * @param int $code - * @param bool $pretty - * @param array $headers - * @return static - */ - public static function json($body = '', ?int $code = null, ?bool $pretty = null, array $headers = []) - { - if (is_array($body) === true) { - $body = json_encode($body, $pretty === true ? JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES : 0); - } + /** + * Creates a json response with appropriate + * header and automatic conversion of arrays. + * + * @param string|array $body + * @param int $code + * @param bool $pretty + * @param array $headers + * @return static + */ + public static function json($body = '', ?int $code = null, ?bool $pretty = null, array $headers = []) + { + if (is_array($body) === true) { + $body = json_encode($body, $pretty === true ? JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES : 0); + } - return new static([ - 'body' => $body, - 'code' => $code, - 'type' => 'application/json', - 'headers' => $headers - ]); - } + return new static([ + 'body' => $body, + 'code' => $code, + 'type' => 'application/json', + 'headers' => $headers + ]); + } - /** - * Creates a redirect response, - * which will send the visitor to the - * given location. - * - * @param string $location - * @param int $code - * @return static - */ - public static function redirect(string $location = '/', int $code = 302) - { - return new static([ - 'code' => $code, - 'headers' => [ - 'Location' => Url::unIdn($location) - ] - ]); - } + /** + * Creates a redirect response, + * which will send the visitor to the + * given location. + * + * @param string $location + * @param int $code + * @return static + */ + public static function redirect(string $location = '/', int $code = 302) + { + return new static([ + 'code' => $code, + 'headers' => [ + 'Location' => Url::unIdn($location) + ] + ]); + } - /** - * Sends all registered headers and - * returns the response body - * - * @return string - */ - public function send(): string - { - // send the status response code - http_response_code($this->code()); + /** + * Sends all registered headers and + * returns the response body + * + * @return string + */ + public function send(): string + { + // send the status response code + http_response_code($this->code()); - // send all custom headers - foreach ($this->headers() as $key => $value) { - header($key . ': ' . $value); - } + // send all custom headers + foreach ($this->headers() as $key => $value) { + header($key . ': ' . $value); + } - // send the content type header - header('Content-Type:' . $this->type() . '; charset=' . $this->charset()); + // send the content type header + header('Content-Type:' . $this->type() . '; charset=' . $this->charset()); - // print the response body - return $this->body(); - } + // print the response body + return $this->body(); + } - /** - * Converts all relevant response attributes - * to an associative array for debugging, - * testing or whatever. - * - * @return array - */ - public function toArray(): array - { - return [ - 'type' => $this->type(), - 'charset' => $this->charset(), - 'code' => $this->code(), - 'headers' => $this->headers(), - 'body' => $this->body() - ]; - } + /** + * Converts all relevant response attributes + * to an associative array for debugging, + * testing or whatever. + * + * @return array + */ + public function toArray(): array + { + return [ + 'type' => $this->type(), + 'charset' => $this->charset(), + 'code' => $this->code(), + 'headers' => $this->headers(), + 'body' => $this->body() + ]; + } - /** - * Getter for the content type - * - * @return string - */ - public function type(): string - { - return $this->type; - } + /** + * Getter for the content type + * + * @return string + */ + public function type(): string + { + return $this->type; + } } diff --git a/kirby/src/Http/Route.php b/kirby/src/Http/Route.php index bfad0c9..007e481 100755 --- a/kirby/src/Http/Route.php +++ b/kirby/src/Http/Route.php @@ -13,218 +13,218 @@ use Closure; */ class Route { - /** - * The callback action function - * - * @var Closure - */ - protected $action; + /** + * The callback action function + * + * @var Closure + */ + protected $action; - /** - * Listed of parsed arguments - * - * @var array - */ - protected $arguments = []; + /** + * Listed of parsed arguments + * + * @var array + */ + protected $arguments = []; - /** - * An array of all passed attributes - * - * @var array - */ - protected $attributes = []; + /** + * An array of all passed attributes + * + * @var array + */ + protected $attributes = []; - /** - * The registered request method - * - * @var string - */ - protected $method; + /** + * The registered request method + * + * @var string + */ + protected $method; - /** - * The registered pattern - * - * @var string - */ - protected $pattern; + /** + * The registered pattern + * + * @var string + */ + protected $pattern; - /** - * Wildcards, which can be used in - * Route patterns to make regular expressions - * a little more human - * - * @var array - */ - protected $wildcards = [ - 'required' => [ - '(:num)' => '(-?[0-9]+)', - '(:alpha)' => '([a-zA-Z]+)', - '(:alphanum)' => '([a-zA-Z0-9]+)', - '(:any)' => '([a-zA-Z0-9\.\-_%= \+\@\(\)]+)', - '(:all)' => '(.*)', - ], - 'optional' => [ - '/(:num?)' => '(?:/(-?[0-9]+)', - '/(:alpha?)' => '(?:/([a-zA-Z]+)', - '/(:alphanum?)' => '(?:/([a-zA-Z0-9]+)', - '/(:any?)' => '(?:/([a-zA-Z0-9\.\-_%= \+\@\(\)]+)', - '/(:all?)' => '(?:/(.*)', - ], - ]; + /** + * Wildcards, which can be used in + * Route patterns to make regular expressions + * a little more human + * + * @var array + */ + protected $wildcards = [ + 'required' => [ + '(:num)' => '(-?[0-9]+)', + '(:alpha)' => '([a-zA-Z]+)', + '(:alphanum)' => '([a-zA-Z0-9]+)', + '(:any)' => '([a-zA-Z0-9\.\-_%= \+\@\(\)]+)', + '(:all)' => '(.*)', + ], + 'optional' => [ + '/(:num?)' => '(?:/(-?[0-9]+)', + '/(:alpha?)' => '(?:/([a-zA-Z]+)', + '/(:alphanum?)' => '(?:/([a-zA-Z0-9]+)', + '/(:any?)' => '(?:/([a-zA-Z0-9\.\-_%= \+\@\(\)]+)', + '/(:all?)' => '(?:/(.*)', + ], + ]; - /** - * Magic getter for route attributes - * - * @param string $key - * @param array $arguments - * @return mixed - */ - public function __call(string $key, array $arguments = null) - { - return $this->attributes[$key] ?? null; - } + /** + * Magic getter for route attributes + * + * @param string $key + * @param array $arguments + * @return mixed + */ + public function __call(string $key, array $arguments = null) + { + return $this->attributes[$key] ?? null; + } - /** - * Creates a new Route object for the given - * pattern(s), method(s) and the callback action - * - * @param string|array $pattern - * @param string|array $method - * @param Closure $action - * @param array $attributes - */ - public function __construct($pattern, $method, Closure $action, array $attributes = []) - { - $this->action = $action; - $this->attributes = $attributes; - $this->method = $method; - $this->pattern = $this->regex(ltrim($pattern, '/')); - } + /** + * Creates a new Route object for the given + * pattern(s), method(s) and the callback action + * + * @param string|array $pattern + * @param string|array $method + * @param Closure $action + * @param array $attributes + */ + public function __construct($pattern, $method, Closure $action, array $attributes = []) + { + $this->action = $action; + $this->attributes = $attributes; + $this->method = $method; + $this->pattern = $this->regex(ltrim($pattern, '/')); + } - /** - * Getter for the action callback - * - * @return Closure - */ - public function action() - { - return $this->action; - } + /** + * Getter for the action callback + * + * @return Closure + */ + public function action() + { + return $this->action; + } - /** - * Returns all parsed arguments - * - * @return array - */ - public function arguments(): array - { - return $this->arguments; - } + /** + * Returns all parsed arguments + * + * @return array + */ + public function arguments(): array + { + return $this->arguments; + } - /** - * Getter for additional attributes - * - * @return array - */ - public function attributes(): array - { - return $this->attributes; - } + /** + * Getter for additional attributes + * + * @return array + */ + public function attributes(): array + { + return $this->attributes; + } - /** - * Getter for the method - * - * @return string - */ - public function method(): string - { - return $this->method; - } + /** + * Getter for the method + * + * @return string + */ + public function method(): string + { + return $this->method; + } - /** - * Returns the route name if set - * - * @return string|null - */ - public function name(): ?string - { - return $this->attributes['name'] ?? null; - } + /** + * Returns the route name if set + * + * @return string|null + */ + public function name(): ?string + { + return $this->attributes['name'] ?? null; + } - /** - * Throws a specific exception to tell - * the router to jump to the next route - * @since 3.0.3 - * - * @return void - */ - public static function next(): void - { - throw new Exceptions\NextRouteException('next'); - } + /** + * Throws a specific exception to tell + * the router to jump to the next route + * @since 3.0.3 + * + * @return void + */ + public static function next(): void + { + throw new Exceptions\NextRouteException('next'); + } - /** - * Getter for the pattern - * - * @return string - */ - public function pattern(): string - { - return $this->pattern; - } + /** + * Getter for the pattern + * + * @return string + */ + public function pattern(): string + { + return $this->pattern; + } - /** - * Converts the pattern into a full regular - * expression by replacing all the wildcards - * - * @param string $pattern - * @return string - */ - public function regex(string $pattern): string - { - $search = array_keys($this->wildcards['optional']); - $replace = array_values($this->wildcards['optional']); + /** + * Converts the pattern into a full regular + * expression by replacing all the wildcards + * + * @param string $pattern + * @return string + */ + public function regex(string $pattern): string + { + $search = array_keys($this->wildcards['optional']); + $replace = array_values($this->wildcards['optional']); - // For optional parameters, first translate the wildcards to their - // regex equivalent, sans the ")?" ending. We'll add the endings - // back on when we know the replacement count. - $pattern = str_replace($search, $replace, $pattern, $count); + // For optional parameters, first translate the wildcards to their + // regex equivalent, sans the ")?" ending. We'll add the endings + // back on when we know the replacement count. + $pattern = str_replace($search, $replace, $pattern, $count); - if ($count > 0) { - $pattern .= str_repeat(')?', $count); - } + if ($count > 0) { + $pattern .= str_repeat(')?', $count); + } - return strtr($pattern, $this->wildcards['required']); - } + return strtr($pattern, $this->wildcards['required']); + } - /** - * Tries to match the path with the regular expression and - * extracts all arguments for the Route action - * - * @param string $pattern - * @param string $path - * @return array|false - */ - public function parse(string $pattern, string $path) - { - // check for direct matches - if ($pattern === $path) { - return $this->arguments = []; - } + /** + * Tries to match the path with the regular expression and + * extracts all arguments for the Route action + * + * @param string $pattern + * @param string $path + * @return array|false + */ + public function parse(string $pattern, string $path) + { + // check for direct matches + if ($pattern === $path) { + return $this->arguments = []; + } - // We only need to check routes with regular expression since all others - // would have been able to be matched by the search for literal matches - // we just did before we started searching. - if (strpos($pattern, '(') === false) { - return false; - } + // We only need to check routes with regular expression since all others + // would have been able to be matched by the search for literal matches + // we just did before we started searching. + if (strpos($pattern, '(') === false) { + return false; + } - // If we have a match we'll return all results - // from the preg without the full first match. - if (preg_match('#^' . $this->regex($pattern) . '$#u', $path, $parameters)) { - return $this->arguments = array_slice($parameters, 1); - } + // If we have a match we'll return all results + // from the preg without the full first match. + if (preg_match('#^' . $this->regex($pattern) . '$#u', $path, $parameters)) { + return $this->arguments = array_slice($parameters, 1); + } - return false; - } + return false; + } } diff --git a/kirby/src/Http/Router.php b/kirby/src/Http/Router.php index 1928be7..aceb2b6 100755 --- a/kirby/src/Http/Router.php +++ b/kirby/src/Http/Router.php @@ -16,194 +16,194 @@ use Kirby\Toolkit\A; */ class Router { - /** - * Hook that is called after each route - * - * @var \Closure - */ - protected $afterEach; + /** + * Hook that is called after each route + * + * @var \Closure + */ + protected $afterEach; - /** - * Hook that is called before each route - * - * @var \Closure - */ - protected $beforeEach; + /** + * Hook that is called before each route + * + * @var \Closure + */ + protected $beforeEach; - /** - * Store for the current route, - * if one can be found - * - * @var \Kirby\Http\Route|null - */ - protected $route; + /** + * Store for the current route, + * if one can be found + * + * @var \Kirby\Http\Route|null + */ + protected $route; - /** - * All registered routes, sorted by - * their request method. This makes - * it faster to find the right route - * later. - * - * @var array - */ - protected $routes = [ - 'GET' => [], - 'HEAD' => [], - 'POST' => [], - 'PUT' => [], - 'DELETE' => [], - 'CONNECT' => [], - 'OPTIONS' => [], - 'TRACE' => [], - 'PATCH' => [], - ]; + /** + * All registered routes, sorted by + * their request method. This makes + * it faster to find the right route + * later. + * + * @var array + */ + protected $routes = [ + 'GET' => [], + 'HEAD' => [], + 'POST' => [], + 'PUT' => [], + 'DELETE' => [], + 'CONNECT' => [], + 'OPTIONS' => [], + 'TRACE' => [], + 'PATCH' => [], + ]; - /** - * Creates a new router object and - * registers all the given routes - * - * @param array $routes - * @param array $hooks Optional `beforeEach` and `afterEach` hooks - */ - public function __construct(array $routes = [], array $hooks = []) - { - $this->beforeEach = $hooks['beforeEach'] ?? null; - $this->afterEach = $hooks['afterEach'] ?? null; + /** + * Creates a new router object and + * registers all the given routes + * + * @param array $routes + * @param array $hooks Optional `beforeEach` and `afterEach` hooks + */ + public function __construct(array $routes = [], array $hooks = []) + { + $this->beforeEach = $hooks['beforeEach'] ?? null; + $this->afterEach = $hooks['afterEach'] ?? null; - foreach ($routes as $props) { - if (isset($props['pattern'], $props['action']) === false) { - throw new InvalidArgumentException('Invalid route parameters'); - } + foreach ($routes as $props) { + if (isset($props['pattern'], $props['action']) === false) { + throw new InvalidArgumentException('Invalid route parameters'); + } - $patterns = A::wrap($props['pattern']); - $methods = A::map( - explode('|', strtoupper($props['method'] ?? 'GET')), - 'trim' - ); + $patterns = A::wrap($props['pattern']); + $methods = A::map( + explode('|', strtoupper($props['method'] ?? 'GET')), + 'trim' + ); - if ($methods === ['ALL']) { - $methods = array_keys($this->routes); - } + if ($methods === ['ALL']) { + $methods = array_keys($this->routes); + } - foreach ($methods as $method) { - foreach ($patterns as $pattern) { - $this->routes[$method][] = new Route( - $pattern, - $method, - $props['action'], - $props - ); - } - } - } - } + foreach ($methods as $method) { + foreach ($patterns as $pattern) { + $this->routes[$method][] = new Route( + $pattern, + $method, + $props['action'], + $props + ); + } + } + } + } - /** - * Calls the Router by path and method. - * This will try to find a Route object - * and then call the Route action with - * the appropriate arguments and a Result - * object. - * - * @param string $path - * @param string $method - * @param Closure|null $callback - * @return mixed - */ - public function call(string $path = null, string $method = 'GET', Closure $callback = null) - { - $path ??= ''; - $ignore = []; - $result = null; - $loop = true; + /** + * Calls the Router by path and method. + * This will try to find a Route object + * and then call the Route action with + * the appropriate arguments and a Result + * object. + * + * @param string $path + * @param string $method + * @param Closure|null $callback + * @return mixed + */ + public function call(string $path = null, string $method = 'GET', Closure $callback = null) + { + $path ??= ''; + $ignore = []; + $result = null; + $loop = true; - while ($loop === true) { - $route = $this->find($path, $method, $ignore); + while ($loop === true) { + $route = $this->find($path, $method, $ignore); - if (is_a($this->beforeEach, 'Closure') === true) { - ($this->beforeEach)($route, $path, $method); - } + if (is_a($this->beforeEach, 'Closure') === true) { + ($this->beforeEach)($route, $path, $method); + } - try { - if ($callback) { - $result = $callback($route); - } else { - $result = $route->action()->call($route, ...$route->arguments()); - } + try { + if ($callback) { + $result = $callback($route); + } else { + $result = $route->action()->call($route, ...$route->arguments()); + } - $loop = false; - } catch (Exceptions\NextRouteException $e) { - $ignore[] = $route; - } + $loop = false; + } catch (Exceptions\NextRouteException $e) { + $ignore[] = $route; + } - if (is_a($this->afterEach, 'Closure') === true) { - $final = $loop === false; - $result = ($this->afterEach)($route, $path, $method, $result, $final); - } - } + if (is_a($this->afterEach, 'Closure') === true) { + $final = $loop === false; + $result = ($this->afterEach)($route, $path, $method, $result, $final); + } + } - return $result; - } + return $result; + } - /** - * Creates a micro-router and executes - * the routing action immediately - * @since 3.7.0 - * - * @param string|null $path - * @param string $method - * @param array $routes - * @param \Closure|null $callback - * @return mixed - */ - public static function execute(?string $path = null, string $method = 'GET', array $routes = [], ?Closure $callback = null) - { - return (new static($routes))->call($path, $method, $callback); - } + /** + * Creates a micro-router and executes + * the routing action immediately + * @since 3.7.0 + * + * @param string|null $path + * @param string $method + * @param array $routes + * @param \Closure|null $callback + * @return mixed + */ + public static function execute(?string $path = null, string $method = 'GET', array $routes = [], ?Closure $callback = null) + { + return (new static($routes))->call($path, $method, $callback); + } - /** - * Finds a Route object by path and method - * The Route's arguments method is used to - * find matches and return all the found - * arguments in the path. - * - * @param string $path - * @param string $method - * @param array $ignore - * @return \Kirby\Http\Route|null - */ - public function find(string $path, string $method, array $ignore = null) - { - if (isset($this->routes[$method]) === false) { - throw new InvalidArgumentException('Invalid routing method: ' . $method, 400); - } + /** + * Finds a Route object by path and method + * The Route's arguments method is used to + * find matches and return all the found + * arguments in the path. + * + * @param string $path + * @param string $method + * @param array $ignore + * @return \Kirby\Http\Route|null + */ + public function find(string $path, string $method, array $ignore = null) + { + if (isset($this->routes[$method]) === false) { + throw new InvalidArgumentException('Invalid routing method: ' . $method, 400); + } - // remove leading and trailing slashes - $path = trim($path, '/'); + // remove leading and trailing slashes + $path = trim($path, '/'); - foreach ($this->routes[$method] as $route) { - $arguments = $route->parse($route->pattern(), $path); + foreach ($this->routes[$method] as $route) { + $arguments = $route->parse($route->pattern(), $path); - if ($arguments !== false) { - if (empty($ignore) === true || in_array($route, $ignore) === false) { - return $this->route = $route; - } - } - } + if ($arguments !== false) { + if (empty($ignore) === true || in_array($route, $ignore) === false) { + return $this->route = $route; + } + } + } - throw new Exception('No route found for path: "' . $path . '" and request method: "' . $method . '"', 404); - } + throw new Exception('No route found for path: "' . $path . '" and request method: "' . $method . '"', 404); + } - /** - * Returns the current route. - * This will only return something, - * once Router::find() has been called - * and only if a route was found. - * - * @return \Kirby\Http\Route|null - */ - public function route() - { - return $this->route; - } + /** + * Returns the current route. + * This will only return something, + * once Router::find() has been called + * and only if a route was found. + * + * @return \Kirby\Http\Route|null + */ + public function route() + { + return $this->route; + } } diff --git a/kirby/src/Http/Server.php b/kirby/src/Http/Server.php index 7a69c41..d16118f 100755 --- a/kirby/src/Http/Server.php +++ b/kirby/src/Http/Server.php @@ -18,21 +18,21 @@ use Kirby\Toolkit\Facade; */ class Server extends Facade { - public const HOST_FROM_SERVER = 1; - public const HOST_FROM_HEADER = 2; - public const HOST_ALLOW_EMPTY = 4; + public const HOST_FROM_SERVER = 1; + public const HOST_FROM_HEADER = 2; + public const HOST_ALLOW_EMPTY = 4; - public static $cli; - public static $hosts; + public static $cli; + public static $hosts; - /** - * @return \Kirby\Http\Environment - */ - public static function instance() - { - return new Environment([ - 'cli' => static::$cli, - 'allowed' => static::$hosts - ]); - } + /** + * @return \Kirby\Http\Environment + */ + public static function instance() + { + return new Environment([ + 'cli' => static::$cli, + 'allowed' => static::$hosts + ]); + } } diff --git a/kirby/src/Http/Uri.php b/kirby/src/Http/Uri.php index ebfb50b..9f07bc1 100755 --- a/kirby/src/Http/Uri.php +++ b/kirby/src/Http/Uri.php @@ -18,562 +18,563 @@ use Throwable; */ class Uri { - use Properties; - - /** - * Cache for the current Uri object - * - * @var Uri|null - */ - public static $current; - - /** - * The fragment after the hash - * - * @var string|false - */ - protected $fragment; - - /** - * The host address - * - * @var string - */ - protected $host; - - /** - * The optional password for basic authentication - * - * @var string|false - */ - protected $password; - - /** - * The optional list of params - * - * @var Params - */ - protected $params; - - /** - * The optional path - * - * @var Path - */ - protected $path; - - /** - * The optional port number - * - * @var int|false - */ - protected $port; - - /** - * All original properties - * - * @var array - */ - protected $props; - - /** - * The optional query string without leading ? - * - * @var Query - */ - protected $query; - - /** - * https or http - * - * @var string - */ - protected $scheme = 'http'; - - /** - * @var bool - */ - protected $slash = false; - - /** - * The optional username for basic authentication - * - * @var string|false - */ - protected $username; - - /** - * Magic caller to access all properties - * - * @param string $property - * @param array $arguments - * @return mixed - */ - public function __call(string $property, array $arguments = []) - { - return $this->$property ?? null; - } - - /** - * Make sure that cloning also clones - * the path and query objects - * - * @return void - */ - public function __clone() - { - $this->path = clone $this->path; - $this->query = clone $this->query; - $this->params = clone $this->params; - } - - /** - * Creates a new URI object - * - * @param array|string $props - * @param array $inject Additional props to inject if a URL string is passed - */ - public function __construct($props = [], array $inject = []) - { - if (is_string($props) === true) { - $props = parse_url($props); - $props['username'] = $props['user'] ?? null; - $props['password'] = $props['pass'] ?? null; - - $props = array_merge($props, $inject); - } - - // parse the path and extract params - if (empty($props['path']) === false) { - $props = static::parsePath($props); - } - - $this->setProperties($this->props = $props); - } - - /** - * Magic getter - * - * @param string $property - * @return mixed - */ - public function __get(string $property) - { - return $this->$property ?? null; - } - - /** - * Magic setter - * - * @param string $property - * @param mixed $value - */ - public function __set(string $property, $value) - { - if (method_exists($this, 'set' . $property) === true) { - $this->{'set' . $property}($value); - } - } - - /** - * Converts the URL object to string - * - * @return string - */ - public function __toString(): string - { - try { - return $this->toString(); - } catch (Throwable $e) { - return ''; - } - } - - /** - * Returns the auth details (username:password) - * - * @return string|null - */ - public function auth(): ?string - { - $auth = trim($this->username . ':' . $this->password); - return $auth !== ':' ? $auth : null; - } - - /** - * Returns the base url (scheme + host) - * without trailing slash - * - * @return string|null - */ - public function base(): ?string - { - if ($domain = $this->domain()) { - return $this->scheme ? $this->scheme . '://' . $domain : $domain; - } - - return null; - } - - /** - * Clones the Uri object and applies optional - * new props. - * - * @param array $props - * @return static - */ - public function clone(array $props = []) - { - $clone = clone $this; - - foreach ($props as $key => $value) { - $clone->__set($key, $value); - } - - return $clone; - } - - /** - * @param array $props - * @return static - */ - public static function current(array $props = []) - { - if (static::$current !== null) { - return static::$current; - } - - if ($app = App::instance(null, true)) { - $environment = $app->environment(); - } else { - $environment = new Environment(); - } - - return new static($environment->requestUrl(), $props); - } - - /** - * Returns the domain without scheme, path or query - * - * @return string|null - */ - public function domain(): ?string - { - if (empty($this->host) === true || $this->host === '/') { - return null; - } - - $auth = $this->auth(); - $domain = ''; - - if ($auth !== null) { - $domain .= $auth . '@'; - } - - $domain .= $this->host; - - if ($this->port !== null && in_array($this->port, [80, 443]) === false) { - $domain .= ':' . $this->port; - } - - return $domain; - } - - /** - * @return bool - */ - public function hasFragment(): bool - { - return empty($this->fragment) === false; - } - - /** - * @return bool - */ - public function hasPath(): bool - { - return $this->path()->isNotEmpty(); - } - - /** - * @return bool - */ - public function hasQuery(): bool - { - return $this->query()->isNotEmpty(); - } - - /** - * @return bool - */ - public function https(): bool - { - return $this->scheme() === 'https'; - } - - /** - * Tries to convert the internationalized host - * name to the human-readable UTF8 representation - * - * @return $this - */ - public function idn() - { - if (empty($this->host) === false) { - $this->setHost(Idn::decode($this->host)); - } - return $this; - } - - /** - * Creates an Uri object for the URL to the index.php - * or any other executed script. - * - * @param array $props - * @return static - */ - public static function index(array $props = []) - { - if ($app = App::instance(null, true)) { - $url = $app->url('index'); - } else { - $url = (new Environment())->baseUrl(); - } - - return new static($url, $props); - } - - /** - * Checks if the host exists - * - * @return bool - */ - public function isAbsolute(): bool - { - return empty($this->host) === false; - } - - /** - * @param string|null $fragment - * @return $this - */ - public function setFragment(string $fragment = null) - { - $this->fragment = $fragment ? ltrim($fragment, '#') : null; - return $this; - } - - /** - * @param string $host - * @return $this - */ - public function setHost(string $host = null) - { - $this->host = $host; - return $this; - } - - /** - * @param \Kirby\Http\Params|string|array|false|null $params - * @return $this - */ - public function setParams($params = null) - { - // ensure that the special constructor value of `false` - // is never passed through as it's not supported by `Params` - if ($params === false) { - $params = []; - } - - $this->params = is_a($params, 'Kirby\Http\Params') === true ? $params : new Params($params); - return $this; - } - - /** - * @param string|null $password - * @return $this - */ - public function setPassword(string $password = null) - { - $this->password = $password; - return $this; - } - - /** - * @param \Kirby\Http\Path|string|array|null $path - * @return $this - */ - public function setPath($path = null) - { - $this->path = is_a($path, 'Kirby\Http\Path') === true ? $path : new Path($path); - return $this; - } - - /** - * @param int|null $port - * @return $this - */ - public function setPort(int $port = null) - { - if ($port === 0) { - $port = null; - } - - if ($port !== null) { - if ($port < 1 || $port > 65535) { - throw new InvalidArgumentException('Invalid port format: ' . $port); - } - } - - $this->port = $port; - return $this; - } - - /** - * @param \Kirby\Http\Query|string|array|null $query - * @return $this - */ - public function setQuery($query = null) - { - $this->query = is_a($query, 'Kirby\Http\Query') === true ? $query : new Query($query); - return $this; - } - - /** - * @param string $scheme - * @return $this - */ - public function setScheme(string $scheme = null) - { - if ($scheme !== null && in_array($scheme, ['http', 'https', 'ftp']) === false) { - throw new InvalidArgumentException('Invalid URL scheme: ' . $scheme); - } - - $this->scheme = $scheme; - return $this; - } - - /** - * Set if a trailing slash should be added to - * the path when the URI is being built - * - * @param bool $slash - * @return $this - */ - public function setSlash(bool $slash = false) - { - $this->slash = $slash; - return $this; - } - - /** - * @param string|null $username - * @return $this - */ - public function setUsername(string $username = null) - { - $this->username = $username; - return $this; - } - - /** - * Converts the Url object to an array - * - * @return array - */ - public function toArray(): array - { - $array = []; - - foreach ($this->propertyData as $key => $value) { - $value = $this->$key; - - if (is_object($value) === true) { - $value = $value->toArray(); - } - - $array[$key] = $value; - } - - return $array; - } - - public function toJson(...$arguments): string - { - return json_encode($this->toArray(), ...$arguments); - } - - /** - * Returns the full URL as string - * - * @return string - */ - public function toString(): string - { - $url = $this->base(); - $slash = true; - - if (empty($url) === true) { - $url = '/'; - $slash = false; - } - - $path = $this->path->toString($slash) . $this->params->toString(true); - - if ($this->slash && $slash === true) { - $path .= '/'; - } - - $url .= $path; - $url .= $this->query->toString(true); - - if (empty($this->fragment) === false) { - $url .= '#' . $this->fragment; - } - - return $url; - } - - /** - * Tries to convert a URL with an internationalized host - * name to the machine-readable Punycode representation - * - * @return $this - */ - public function unIdn() - { - if (empty($this->host) === false) { - $this->setHost(Idn::encode($this->host)); - } - return $this; - } - - /** - * Parses the path inside the props and extracts - * the params unless disabled - * - * @param array $props - * @return array Modified props array - */ - protected static function parsePath(array $props): array - { - // extract params, the rest is the path; - // only do this if not explicitly disabled (set to `false`) - if (isset($props['params']) === false || $props['params'] !== false) { - $extract = Params::extract($props['path']); - $props['params'] ??= $extract['params']; - $props['path'] = $extract['path']; - $props['slash'] ??= $extract['slash']; - - return $props; - } - - // use the full path; - // automatically detect the trailing slash from it if possible - if (is_string($props['path']) === true) { - $props['slash'] = substr($props['path'], -1, 1) === '/'; - } - - return $props; - } + use Properties; + + /** + * Cache for the current Uri object + * + * @var Uri|null + */ + public static $current; + + /** + * The fragment after the hash + * + * @var string|false + */ + protected $fragment; + + /** + * The host address + * + * @var string + */ + protected $host; + + /** + * The optional password for basic authentication + * + * @var string|false + */ + protected $password; + + /** + * The optional list of params + * + * @var Params + */ + protected $params; + + /** + * The optional path + * + * @var Path + */ + protected $path; + + /** + * The optional port number + * + * @var int|false + */ + protected $port; + + /** + * All original properties + * + * @var array + */ + protected $props; + + /** + * The optional query string without leading ? + * + * @var Query + */ + protected $query; + + /** + * https or http + * + * @var string + */ + protected $scheme = 'http'; + + /** + * @var bool + */ + protected $slash = false; + + /** + * The optional username for basic authentication + * + * @var string|false + */ + protected $username; + + /** + * Magic caller to access all properties + * + * @param string $property + * @param array $arguments + * @return mixed + */ + public function __call(string $property, array $arguments = []) + { + return $this->$property ?? null; + } + + /** + * Make sure that cloning also clones + * the path and query objects + * + * @return void + */ + public function __clone() + { + $this->path = clone $this->path; + $this->query = clone $this->query; + $this->params = clone $this->params; + } + + /** + * Creates a new URI object + * + * @param array|string $props + * @param array $inject Additional props to inject if a URL string is passed + */ + public function __construct($props = [], array $inject = []) + { + if (is_string($props) === true) { + $props = parse_url($props); + $props['username'] = $props['user'] ?? null; + $props['password'] = $props['pass'] ?? null; + + $props = array_merge($props, $inject); + } + + // parse the path and extract params + if (empty($props['path']) === false) { + $props = static::parsePath($props); + } + + $this->setProperties($this->props = $props); + } + + /** + * Magic getter + * + * @param string $property + * @return mixed + */ + public function __get(string $property) + { + return $this->$property ?? null; + } + + /** + * Magic setter + * + * @param string $property + * @param mixed $value + * @return void + */ + public function __set(string $property, $value): void + { + if (method_exists($this, 'set' . $property) === true) { + $this->{'set' . $property}($value); + } + } + + /** + * Converts the URL object to string + * + * @return string + */ + public function __toString(): string + { + try { + return $this->toString(); + } catch (Throwable $e) { + return ''; + } + } + + /** + * Returns the auth details (username:password) + * + * @return string|null + */ + public function auth(): ?string + { + $auth = trim($this->username . ':' . $this->password); + return $auth !== ':' ? $auth : null; + } + + /** + * Returns the base url (scheme + host) + * without trailing slash + * + * @return string|null + */ + public function base(): ?string + { + if ($domain = $this->domain()) { + return $this->scheme ? $this->scheme . '://' . $domain : $domain; + } + + return null; + } + + /** + * Clones the Uri object and applies optional + * new props. + * + * @param array $props + * @return static + */ + public function clone(array $props = []) + { + $clone = clone $this; + + foreach ($props as $key => $value) { + $clone->__set($key, $value); + } + + return $clone; + } + + /** + * @param array $props + * @return static + */ + public static function current(array $props = []) + { + if (static::$current !== null) { + return static::$current; + } + + if ($app = App::instance(null, true)) { + $environment = $app->environment(); + } else { + $environment = new Environment(); + } + + return new static($environment->requestUrl(), $props); + } + + /** + * Returns the domain without scheme, path or query + * + * @return string|null + */ + public function domain(): ?string + { + if (empty($this->host) === true || $this->host === '/') { + return null; + } + + $auth = $this->auth(); + $domain = ''; + + if ($auth !== null) { + $domain .= $auth . '@'; + } + + $domain .= $this->host; + + if ($this->port !== null && in_array($this->port, [80, 443]) === false) { + $domain .= ':' . $this->port; + } + + return $domain; + } + + /** + * @return bool + */ + public function hasFragment(): bool + { + return empty($this->fragment) === false; + } + + /** + * @return bool + */ + public function hasPath(): bool + { + return $this->path()->isNotEmpty(); + } + + /** + * @return bool + */ + public function hasQuery(): bool + { + return $this->query()->isNotEmpty(); + } + + /** + * @return bool + */ + public function https(): bool + { + return $this->scheme() === 'https'; + } + + /** + * Tries to convert the internationalized host + * name to the human-readable UTF8 representation + * + * @return $this + */ + public function idn() + { + if (empty($this->host) === false) { + $this->setHost(Idn::decode($this->host)); + } + return $this; + } + + /** + * Creates an Uri object for the URL to the index.php + * or any other executed script. + * + * @param array $props + * @return static + */ + public static function index(array $props = []) + { + if ($app = App::instance(null, true)) { + $url = $app->url('index'); + } else { + $url = (new Environment())->baseUrl(); + } + + return new static($url, $props); + } + + /** + * Checks if the host exists + * + * @return bool + */ + public function isAbsolute(): bool + { + return empty($this->host) === false; + } + + /** + * @param string|null $fragment + * @return $this + */ + public function setFragment(string $fragment = null) + { + $this->fragment = $fragment ? ltrim($fragment, '#') : null; + return $this; + } + + /** + * @param string $host + * @return $this + */ + public function setHost(string $host = null) + { + $this->host = $host; + return $this; + } + + /** + * @param \Kirby\Http\Params|string|array|false|null $params + * @return $this + */ + public function setParams($params = null) + { + // ensure that the special constructor value of `false` + // is never passed through as it's not supported by `Params` + if ($params === false) { + $params = []; + } + + $this->params = is_a($params, 'Kirby\Http\Params') === true ? $params : new Params($params); + return $this; + } + + /** + * @param string|null $password + * @return $this + */ + public function setPassword(string $password = null) + { + $this->password = $password; + return $this; + } + + /** + * @param \Kirby\Http\Path|string|array|null $path + * @return $this + */ + public function setPath($path = null) + { + $this->path = is_a($path, 'Kirby\Http\Path') === true ? $path : new Path($path); + return $this; + } + + /** + * @param int|null $port + * @return $this + */ + public function setPort(int $port = null) + { + if ($port === 0) { + $port = null; + } + + if ($port !== null) { + if ($port < 1 || $port > 65535) { + throw new InvalidArgumentException('Invalid port format: ' . $port); + } + } + + $this->port = $port; + return $this; + } + + /** + * @param \Kirby\Http\Query|string|array|null $query + * @return $this + */ + public function setQuery($query = null) + { + $this->query = is_a($query, 'Kirby\Http\Query') === true ? $query : new Query($query); + return $this; + } + + /** + * @param string $scheme + * @return $this + */ + public function setScheme(string $scheme = null) + { + if ($scheme !== null && in_array($scheme, ['http', 'https', 'ftp']) === false) { + throw new InvalidArgumentException('Invalid URL scheme: ' . $scheme); + } + + $this->scheme = $scheme; + return $this; + } + + /** + * Set if a trailing slash should be added to + * the path when the URI is being built + * + * @param bool $slash + * @return $this + */ + public function setSlash(bool $slash = false) + { + $this->slash = $slash; + return $this; + } + + /** + * @param string|null $username + * @return $this + */ + public function setUsername(string $username = null) + { + $this->username = $username; + return $this; + } + + /** + * Converts the Url object to an array + * + * @return array + */ + public function toArray(): array + { + $array = []; + + foreach ($this->propertyData as $key => $value) { + $value = $this->$key; + + if (is_object($value) === true) { + $value = $value->toArray(); + } + + $array[$key] = $value; + } + + return $array; + } + + public function toJson(...$arguments): string + { + return json_encode($this->toArray(), ...$arguments); + } + + /** + * Returns the full URL as string + * + * @return string + */ + public function toString(): string + { + $url = $this->base(); + $slash = true; + + if (empty($url) === true) { + $url = '/'; + $slash = false; + } + + $path = $this->path->toString($slash) . $this->params->toString(true); + + if ($this->slash && $slash === true) { + $path .= '/'; + } + + $url .= $path; + $url .= $this->query->toString(true); + + if (empty($this->fragment) === false) { + $url .= '#' . $this->fragment; + } + + return $url; + } + + /** + * Tries to convert a URL with an internationalized host + * name to the machine-readable Punycode representation + * + * @return $this + */ + public function unIdn() + { + if (empty($this->host) === false) { + $this->setHost(Idn::encode($this->host)); + } + return $this; + } + + /** + * Parses the path inside the props and extracts + * the params unless disabled + * + * @param array $props + * @return array Modified props array + */ + protected static function parsePath(array $props): array + { + // extract params, the rest is the path; + // only do this if not explicitly disabled (set to `false`) + if (isset($props['params']) === false || $props['params'] !== false) { + $extract = Params::extract($props['path']); + $props['params'] ??= $extract['params']; + $props['path'] = $extract['path']; + $props['slash'] ??= $extract['slash']; + + return $props; + } + + // use the full path; + // automatically detect the trailing slash from it if possible + if (is_string($props['path']) === true) { + $props['slash'] = substr($props['path'], -1, 1) === '/'; + } + + return $props; + } } diff --git a/kirby/src/Http/Url.php b/kirby/src/Http/Url.php index c36e618..e0c3cdf 100755 --- a/kirby/src/Http/Url.php +++ b/kirby/src/Http/Url.php @@ -15,275 +15,275 @@ use Kirby\Toolkit\Str; */ class Url { - /** - * The base Url to build absolute Urls from - * - * @var string - */ - public static $home = '/'; + /** + * The base Url to build absolute Urls from + * + * @var string + */ + public static $home = '/'; - /** - * The current Uri object - * - * @var Uri - */ - public static $current = null; + /** + * The current Uri object + * + * @var Uri + */ + public static $current = null; - /** - * Facade for all Uri object methods - * - * @param string $method - * @param array $arguments - * @return mixed - */ - public static function __callStatic(string $method, $arguments) - { - return (new Uri($arguments[0] ?? static::current()))->$method(...array_slice($arguments, 1)); - } + /** + * Facade for all Uri object methods + * + * @param string $method + * @param array $arguments + * @return mixed + */ + public static function __callStatic(string $method, $arguments) + { + return (new Uri($arguments[0] ?? static::current()))->$method(...array_slice($arguments, 1)); + } - /** - * Url Builder - * Actually just a factory for `new Uri($parts)` - * - * @param array $parts - * @param string|null $url - * @return string - */ - public static function build(array $parts = [], string $url = null): string - { - return (string)(new Uri($url ?? static::current()))->clone($parts); - } + /** + * Url Builder + * Actually just a factory for `new Uri($parts)` + * + * @param array $parts + * @param string|null $url + * @return string + */ + public static function build(array $parts = [], string $url = null): string + { + return (string)(new Uri($url ?? static::current()))->clone($parts); + } - /** - * Returns the current url with all bells and whistles - * - * @return string - */ - public static function current(): string - { - return static::$current = static::$current ?? static::toObject()->toString(); - } + /** + * Returns the current url with all bells and whistles + * + * @return string + */ + public static function current(): string + { + return static::$current = static::$current ?? static::toObject()->toString(); + } - /** - * Returns the url for the current directory - * - * @return string - */ - public static function currentDir(): string - { - return dirname(static::current()); - } + /** + * Returns the url for the current directory + * + * @return string + */ + public static function currentDir(): string + { + return dirname(static::current()); + } - /** - * Tries to fix a broken url without protocol - * - * @param string|null $url - * @return string - */ - public static function fix(string $url = null): string - { - // make sure to not touch absolute urls - return (!preg_match('!^(https|http|ftp)\:\/\/!i', $url ?? '')) ? 'http://' . $url : $url; - } + /** + * Tries to fix a broken url without protocol + * + * @param string|null $url + * @return string + */ + public static function fix(string $url = null): string + { + // make sure to not touch absolute urls + return (!preg_match('!^(https|http|ftp)\:\/\/!i', $url ?? '')) ? 'http://' . $url : $url; + } - /** - * Returns the home url if defined - * - * @return string - */ - public static function home(): string - { - return static::$home; - } + /** + * Returns the home url if defined + * + * @return string + */ + public static function home(): string + { + return static::$home; + } - /** - * Returns the url to the executed script - * - * @param array $props - * @return string - */ - public static function index(array $props = []): string - { - return Uri::index($props)->toString(); - } + /** + * Returns the url to the executed script + * + * @param array $props + * @return string + */ + public static function index(array $props = []): string + { + return Uri::index($props)->toString(); + } - /** - * Checks if an URL is absolute - * - * @param string|null $url - * @return bool - */ - public static function isAbsolute(string $url = null): bool - { - // matches the following groups of URLs: - // //example.com/uri - // http://example.com/uri, https://example.com/uri, ftp://example.com/uri - // mailto:example@example.com, geo:49.0158,8.3239?z=11 - return $url !== null && preg_match('!^(//|[a-z0-9+-.]+://|mailto:|tel:|geo:)!i', $url) === 1; - } + /** + * Checks if an URL is absolute + * + * @param string|null $url + * @return bool + */ + public static function isAbsolute(string $url = null): bool + { + // matches the following groups of URLs: + // //example.com/uri + // http://example.com/uri, https://example.com/uri, ftp://example.com/uri + // mailto:example@example.com, geo:49.0158,8.3239?z=11 + return $url !== null && preg_match('!^(//|[a-z0-9+-.]+://|mailto:|tel:|geo:)!i', $url) === 1; + } - /** - * Convert a relative path into an absolute URL - * - * @param string|null $path - * @param string|null $home - * @return string - */ - public static function makeAbsolute(string $path = null, string $home = null): string - { - if ($path === '' || $path === '/' || $path === null) { - return $home ?? static::home(); - } + /** + * Convert a relative path into an absolute URL + * + * @param string|null $path + * @param string|null $home + * @return string + */ + public static function makeAbsolute(string $path = null, string $home = null): string + { + if ($path === '' || $path === '/' || $path === null) { + return $home ?? static::home(); + } - if (substr($path, 0, 1) === '#') { - return $path; - } + if (substr($path, 0, 1) === '#') { + return $path; + } - if (static::isAbsolute($path)) { - return $path; - } + if (static::isAbsolute($path)) { + return $path; + } - // build the full url - $path = ltrim($path, '/'); - $home ??= static::home(); + // build the full url + $path = ltrim($path, '/'); + $home ??= static::home(); - if (empty($path) === true) { - return $home; - } + if (empty($path) === true) { + return $home; + } - return $home === '/' ? '/' . $path : $home . '/' . $path; - } + return $home === '/' ? '/' . $path : $home . '/' . $path; + } - /** - * Returns the path for the given url - * - * @param string|array|null $url - * @param bool $leadingSlash - * @param bool $trailingSlash - * @return string - */ - public static function path($url = null, bool $leadingSlash = false, bool $trailingSlash = false): string - { - return Url::toObject($url)->path()->toString($leadingSlash, $trailingSlash); - } + /** + * Returns the path for the given url + * + * @param string|array|null $url + * @param bool $leadingSlash + * @param bool $trailingSlash + * @return string + */ + public static function path($url = null, bool $leadingSlash = false, bool $trailingSlash = false): string + { + return Url::toObject($url)->path()->toString($leadingSlash, $trailingSlash); + } - /** - * Returns the query for the given url - * - * @param string|array|null $url - * @return string - */ - public static function query($url = null): string - { - return Url::toObject($url)->query()->toString(); - } + /** + * Returns the query for the given url + * + * @param string|array|null $url + * @return string + */ + public static function query($url = null): string + { + return Url::toObject($url)->query()->toString(); + } - /** - * Return the last url the user has been on if detectable - * - * @return string - */ - public static function last(): string - { - return Environment::getGlobally('HTTP_REFERER', ''); - } + /** + * Return the last url the user has been on if detectable + * + * @return string + */ + public static function last(): string + { + return Environment::getGlobally('HTTP_REFERER', ''); + } - /** - * Shortens the Url by removing all unnecessary parts - * - * @param string $url - * @param int $length - * @param bool $base - * @param string $rep - * @return string - */ - public static function short($url = null, int $length = 0, bool $base = false, string $rep = '…'): string - { - $uri = static::toObject($url); + /** + * Shortens the Url by removing all unnecessary parts + * + * @param string $url + * @param int $length + * @param bool $base + * @param string $rep + * @return string + */ + public static function short($url = null, int $length = 0, bool $base = false, string $rep = '…'): string + { + $uri = static::toObject($url); - $uri->fragment = null; - $uri->query = null; - $uri->password = null; - $uri->port = null; - $uri->scheme = null; - $uri->username = null; + $uri->fragment = null; + $uri->query = null; + $uri->password = null; + $uri->port = null; + $uri->scheme = null; + $uri->username = null; - // remove the trailing slash from the path - $uri->slash = false; + // remove the trailing slash from the path + $uri->slash = false; - $url = $base ? $uri->base() : $uri->toString(); - $url = str_replace('www.', '', $url); + $url = $base ? $uri->base() : $uri->toString(); + $url = str_replace('www.', '', $url); - return Str::short($url, $length, $rep); - } + return Str::short($url, $length, $rep); + } - /** - * Removes the path from the Url - * - * @param string $url - * @return string - */ - public static function stripPath($url = null): string - { - return static::toObject($url)->setPath(null)->toString(); - } + /** + * Removes the path from the Url + * + * @param string $url + * @return string + */ + public static function stripPath($url = null): string + { + return static::toObject($url)->setPath(null)->toString(); + } - /** - * Removes the query string from the Url - * - * @param string $url - * @return string - */ - public static function stripQuery($url = null): string - { - return static::toObject($url)->setQuery(null)->toString(); - } + /** + * Removes the query string from the Url + * + * @param string $url + * @return string + */ + public static function stripQuery($url = null): string + { + return static::toObject($url)->setQuery(null)->toString(); + } - /** - * Removes the fragment (hash) from the Url - * - * @param string $url - * @return string - */ - public static function stripFragment($url = null): string - { - return static::toObject($url)->setFragment(null)->toString(); - } + /** + * Removes the fragment (hash) from the Url + * + * @param string $url + * @return string + */ + public static function stripFragment($url = null): string + { + return static::toObject($url)->setFragment(null)->toString(); + } - /** - * Smart resolver for internal and external urls - * - * @param string $path - * @param mixed $options - * @return string - */ - public static function to(string $path = null, $options = null): string - { - // make sure $path is string - $path ??= ''; + /** + * Smart resolver for internal and external urls + * + * @param string $path + * @param mixed $options + * @return string + */ + public static function to(string $path = null, $options = null): string + { + // make sure $path is string + $path ??= ''; - // keep relative urls - if (substr($path, 0, 2) === './' || substr($path, 0, 3) === '../') { - return $path; - } + // keep relative urls + if (substr($path, 0, 2) === './' || substr($path, 0, 3) === '../') { + return $path; + } - $url = static::makeAbsolute($path); + $url = static::makeAbsolute($path); - if ($options === null) { - return $url; - } + if ($options === null) { + return $url; + } - return (new Uri($url, $options))->toString(); - } + return (new Uri($url, $options))->toString(); + } - /** - * Converts the Url to a Uri object - * - * @param string $url - * @return \Kirby\Http\Uri - */ - public static function toObject($url = null) - { - return $url === null ? Uri::current() : new Uri($url); - } + /** + * Converts the Url to a Uri object + * + * @param string $url + * @return \Kirby\Http\Uri + */ + public static function toObject($url = null) + { + return $url === null ? Uri::current() : new Uri($url); + } } diff --git a/kirby/src/Http/Visitor.php b/kirby/src/Http/Visitor.php index 255bf9e..6c1b2ac 100755 --- a/kirby/src/Http/Visitor.php +++ b/kirby/src/Http/Visitor.php @@ -20,233 +20,233 @@ use Kirby\Toolkit\Str; */ class Visitor { - /** - * IP address - * @var string|null - */ - protected $ip; + /** + * IP address + * @var string|null + */ + protected $ip; - /** - * user agent - * @var string|null - */ - protected $userAgent; + /** + * user agent + * @var string|null + */ + protected $userAgent; - /** - * accepted language - * @var string|null - */ - protected $acceptedLanguage; + /** + * accepted language + * @var string|null + */ + protected $acceptedLanguage; - /** - * accepted mime type - * @var string|null - */ - protected $acceptedMimeType; + /** + * accepted mime type + * @var string|null + */ + protected $acceptedMimeType; - /** - * Creates a new visitor object. - * Optional arguments can be passed to - * modify the information about the visitor. - * - * By default everything is pulled from $_SERVER - * - * @param array $arguments - */ - public function __construct(array $arguments = []) - { - $this->ip($arguments['ip'] ?? Environment::getGlobally('REMOTE_ADDR', '')); - $this->userAgent($arguments['userAgent'] ?? Environment::getGlobally('HTTP_USER_AGENT', '')); - $this->acceptedLanguage($arguments['acceptedLanguage'] ?? Environment::getGlobally('HTTP_ACCEPT_LANGUAGE', '')); - $this->acceptedMimeType($arguments['acceptedMimeType'] ?? Environment::getGlobally('HTTP_ACCEPT', '')); - } + /** + * Creates a new visitor object. + * Optional arguments can be passed to + * modify the information about the visitor. + * + * By default everything is pulled from $_SERVER + * + * @param array $arguments + */ + public function __construct(array $arguments = []) + { + $this->ip($arguments['ip'] ?? Environment::getGlobally('REMOTE_ADDR', '')); + $this->userAgent($arguments['userAgent'] ?? Environment::getGlobally('HTTP_USER_AGENT', '')); + $this->acceptedLanguage($arguments['acceptedLanguage'] ?? Environment::getGlobally('HTTP_ACCEPT_LANGUAGE', '')); + $this->acceptedMimeType($arguments['acceptedMimeType'] ?? Environment::getGlobally('HTTP_ACCEPT', '')); + } - /** - * Sets the accepted language if - * provided or returns the user's - * accepted language otherwise - * - * @param string|null $acceptedLanguage - * @return \Kirby\Toolkit\Obj|\Kirby\Http\Visitor|null - */ - public function acceptedLanguage(string $acceptedLanguage = null) - { - if ($acceptedLanguage === null) { - return $this->acceptedLanguages()->first(); - } + /** + * Sets the accepted language if + * provided or returns the user's + * accepted language otherwise + * + * @param string|null $acceptedLanguage + * @return \Kirby\Toolkit\Obj|\Kirby\Http\Visitor|null + */ + public function acceptedLanguage(string $acceptedLanguage = null) + { + if ($acceptedLanguage === null) { + return $this->acceptedLanguages()->first(); + } - $this->acceptedLanguage = $acceptedLanguage; - return $this; - } + $this->acceptedLanguage = $acceptedLanguage; + return $this; + } - /** - * Returns an array of all accepted languages - * including their quality and locale - * - * @return \Kirby\Toolkit\Collection - */ - public function acceptedLanguages() - { - $accepted = Str::accepted($this->acceptedLanguage); - $languages = []; + /** + * Returns an array of all accepted languages + * including their quality and locale + * + * @return \Kirby\Toolkit\Collection + */ + public function acceptedLanguages() + { + $accepted = Str::accepted($this->acceptedLanguage); + $languages = []; - foreach ($accepted as $language) { - $value = $language['value']; - $parts = Str::split($value, '-'); - $code = isset($parts[0]) ? Str::lower($parts[0]) : null; - $region = isset($parts[1]) ? Str::upper($parts[1]) : null; - $locale = $region ? $code . '_' . $region : $code; + foreach ($accepted as $language) { + $value = $language['value']; + $parts = Str::split($value, '-'); + $code = isset($parts[0]) ? Str::lower($parts[0]) : null; + $region = isset($parts[1]) ? Str::upper($parts[1]) : null; + $locale = $region ? $code . '_' . $region : $code; - $languages[$locale] = new Obj([ - 'code' => $code, - 'locale' => $locale, - 'original' => $value, - 'quality' => $language['quality'], - 'region' => $region, - ]); - } + $languages[$locale] = new Obj([ + 'code' => $code, + 'locale' => $locale, + 'original' => $value, + 'quality' => $language['quality'], + 'region' => $region, + ]); + } - return new Collection($languages); - } + return new Collection($languages); + } - /** - * Checks if the user accepts the given language - * - * @param string $code - * @return bool - */ - public function acceptsLanguage(string $code): bool - { - $mode = Str::contains($code, '_') === true ? 'locale' : 'code'; + /** + * Checks if the user accepts the given language + * + * @param string $code + * @return bool + */ + public function acceptsLanguage(string $code): bool + { + $mode = Str::contains($code, '_') === true ? 'locale' : 'code'; - foreach ($this->acceptedLanguages() as $language) { - if ($language->$mode() === $code) { - return true; - } - } + foreach ($this->acceptedLanguages() as $language) { + if ($language->$mode() === $code) { + return true; + } + } - return false; - } + return false; + } - /** - * Sets the accepted mime type if - * provided or returns the user's - * accepted mime type otherwise - * - * @param string|null $acceptedMimeType - * @return \Kirby\Toolkit\Obj|\Kirby\Http\Visitor - */ - public function acceptedMimeType(string $acceptedMimeType = null) - { - if ($acceptedMimeType === null) { - return $this->acceptedMimeTypes()->first(); - } + /** + * Sets the accepted mime type if + * provided or returns the user's + * accepted mime type otherwise + * + * @param string|null $acceptedMimeType + * @return \Kirby\Toolkit\Obj|\Kirby\Http\Visitor + */ + public function acceptedMimeType(string $acceptedMimeType = null) + { + if ($acceptedMimeType === null) { + return $this->acceptedMimeTypes()->first(); + } - $this->acceptedMimeType = $acceptedMimeType; - return $this; - } + $this->acceptedMimeType = $acceptedMimeType; + return $this; + } - /** - * Returns a collection of all accepted mime types - * - * @return \Kirby\Toolkit\Collection - */ - public function acceptedMimeTypes() - { - $accepted = Str::accepted($this->acceptedMimeType); - $mimes = []; + /** + * Returns a collection of all accepted mime types + * + * @return \Kirby\Toolkit\Collection + */ + public function acceptedMimeTypes() + { + $accepted = Str::accepted($this->acceptedMimeType); + $mimes = []; - foreach ($accepted as $mime) { - $mimes[$mime['value']] = new Obj([ - 'type' => $mime['value'], - 'quality' => $mime['quality'], - ]); - } + foreach ($accepted as $mime) { + $mimes[$mime['value']] = new Obj([ + 'type' => $mime['value'], + 'quality' => $mime['quality'], + ]); + } - return new Collection($mimes); - } + return new Collection($mimes); + } - /** - * Checks if the user accepts the given mime type - * - * @param string $mimeType - * @return bool - */ - public function acceptsMimeType(string $mimeType): bool - { - return Mime::isAccepted($mimeType, $this->acceptedMimeType); - } + /** + * Checks if the user accepts the given mime type + * + * @param string $mimeType + * @return bool + */ + public function acceptsMimeType(string $mimeType): bool + { + return Mime::isAccepted($mimeType, $this->acceptedMimeType); + } - /** - * Returns the MIME type from the provided list that - * is most accepted (= preferred) by the visitor - * @since 3.3.0 - * - * @param string ...$mimeTypes MIME types to query for - * @return string|null Preferred MIME type - */ - public function preferredMimeType(string ...$mimeTypes): ?string - { - foreach ($this->acceptedMimeTypes() as $acceptedMime) { - // look for direct matches - if (in_array($acceptedMime->type(), $mimeTypes)) { - return $acceptedMime->type(); - } + /** + * Returns the MIME type from the provided list that + * is most accepted (= preferred) by the visitor + * @since 3.3.0 + * + * @param string ...$mimeTypes MIME types to query for + * @return string|null Preferred MIME type + */ + public function preferredMimeType(string ...$mimeTypes): ?string + { + foreach ($this->acceptedMimeTypes() as $acceptedMime) { + // look for direct matches + if (in_array($acceptedMime->type(), $mimeTypes)) { + return $acceptedMime->type(); + } - // test each option against wildcard `Accept` values - foreach ($mimeTypes as $expectedMime) { - if (Mime::matches($expectedMime, $acceptedMime->type()) === true) { - return $expectedMime; - } - } - } + // test each option against wildcard `Accept` values + foreach ($mimeTypes as $expectedMime) { + if (Mime::matches($expectedMime, $acceptedMime->type()) === true) { + return $expectedMime; + } + } + } - return null; - } + return null; + } - /** - * Returns true if the visitor prefers a JSON response over - * an HTML response based on the `Accept` request header - * @since 3.3.0 - * - * @return bool - */ - public function prefersJson(): bool - { - return $this->preferredMimeType('application/json', 'text/html') === 'application/json'; - } + /** + * Returns true if the visitor prefers a JSON response over + * an HTML response based on the `Accept` request header + * @since 3.3.0 + * + * @return bool + */ + public function prefersJson(): bool + { + return $this->preferredMimeType('application/json', 'text/html') === 'application/json'; + } - /** - * Sets the ip address if provided - * or returns the ip of the current - * visitor otherwise - * - * @param string|null $ip - * @return string|Visitor|null - */ - public function ip(string $ip = null) - { - if ($ip === null) { - return $this->ip; - } - $this->ip = $ip; - return $this; - } + /** + * Sets the ip address if provided + * or returns the ip of the current + * visitor otherwise + * + * @param string|null $ip + * @return string|Visitor|null + */ + public function ip(string $ip = null) + { + if ($ip === null) { + return $this->ip; + } + $this->ip = $ip; + return $this; + } - /** - * Sets the user agent if provided - * or returns the user agent string of - * the current visitor otherwise - * - * @param string|null $userAgent - * @return string|Visitor|null - */ - public function userAgent(string $userAgent = null) - { - if ($userAgent === null) { - return $this->userAgent; - } - $this->userAgent = $userAgent; - return $this; - } + /** + * Sets the user agent if provided + * or returns the user agent string of + * the current visitor otherwise + * + * @param string|null $userAgent + * @return string|Visitor|null + */ + public function userAgent(string $userAgent = null) + { + if ($userAgent === null) { + return $this->userAgent; + } + $this->userAgent = $userAgent; + return $this; + } } diff --git a/kirby/src/Image/Camera.php b/kirby/src/Image/Camera.php index 135bd3c..3cfb793 100755 --- a/kirby/src/Image/Camera.php +++ b/kirby/src/Image/Camera.php @@ -13,81 +13,81 @@ namespace Kirby\Image; */ class Camera { - /** - * Make exif data - * - * @var string|null - */ - protected $make; + /** + * Make exif data + * + * @var string|null + */ + protected $make; - /** - * Model exif data - * - * @var string|null - */ - protected $model; + /** + * Model exif data + * + * @var string|null + */ + protected $model; - /** - * Constructor - * - * @param array $exif - */ - public function __construct(array $exif) - { - $this->make = $exif['Make'] ?? null; - $this->model = $exif['Model'] ?? null; - } + /** + * Constructor + * + * @param array $exif + */ + public function __construct(array $exif) + { + $this->make = $exif['Make'] ?? null; + $this->model = $exif['Model'] ?? null; + } - /** - * Returns the make of the camera - * - * @return string - */ - public function make(): ?string - { - return $this->make; - } + /** + * Returns the make of the camera + * + * @return string + */ + public function make(): ?string + { + return $this->make; + } - /** - * Returns the camera model - * - * @return string - */ - public function model(): ?string - { - return $this->model; - } + /** + * Returns the camera model + * + * @return string + */ + public function model(): ?string + { + return $this->model; + } - /** - * Converts the object into a nicely readable array - * - * @return array - */ - public function toArray(): array - { - return [ - 'make' => $this->make, - 'model' => $this->model - ]; - } + /** + * Converts the object into a nicely readable array + * + * @return array + */ + public function toArray(): array + { + return [ + 'make' => $this->make, + 'model' => $this->model + ]; + } - /** - * Returns the full make + model name - * - * @return string - */ - public function __toString(): string - { - return trim($this->make . ' ' . $this->model); - } + /** + * Returns the full make + model name + * + * @return string + */ + public function __toString(): string + { + return trim($this->make . ' ' . $this->model); + } - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return $this->toArray(); - } + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return $this->toArray(); + } } diff --git a/kirby/src/Image/Darkroom.php b/kirby/src/Image/Darkroom.php index abcc41a..642273a 100755 --- a/kirby/src/Image/Darkroom.php +++ b/kirby/src/Image/Darkroom.php @@ -16,145 +16,145 @@ use Exception; */ class Darkroom { - public static $types = [ - 'gd' => 'Kirby\Image\Darkroom\GdLib', - 'im' => 'Kirby\Image\Darkroom\ImageMagick' - ]; + public static $types = [ + 'gd' => 'Kirby\Image\Darkroom\GdLib', + 'im' => 'Kirby\Image\Darkroom\ImageMagick' + ]; - /** - * @var array - */ - protected $settings = []; + /** + * @var array + */ + protected $settings = []; - /** - * Darkroom constructor - * - * @param array $settings - */ - public function __construct(array $settings = []) - { - $this->settings = array_merge($this->defaults(), $settings); - } + /** + * Darkroom constructor + * + * @param array $settings + */ + public function __construct(array $settings = []) + { + $this->settings = array_merge($this->defaults(), $settings); + } - /** - * Creates a new Darkroom instance for the given - * type/driver - * - * @param string $type - * @param array $settings - * @return mixed - * @throws \Exception - */ - public static function factory(string $type, array $settings = []) - { - if (isset(static::$types[$type]) === false) { - throw new Exception('Invalid Darkroom type'); - } + /** + * Creates a new Darkroom instance for the given + * type/driver + * + * @param string $type + * @param array $settings + * @return mixed + * @throws \Exception + */ + public static function factory(string $type, array $settings = []) + { + if (isset(static::$types[$type]) === false) { + throw new Exception('Invalid Darkroom type'); + } - $class = static::$types[$type]; - return new $class($settings); - } + $class = static::$types[$type]; + return new $class($settings); + } - /** - * Returns the default thumb settings - * - * @return array - */ - protected function defaults(): array - { - return [ - 'autoOrient' => true, - 'blur' => false, - 'crop' => false, - 'format' => null, - 'grayscale' => false, - 'height' => null, - 'quality' => 90, - 'scaleHeight' => null, - 'scaleWidth' => null, - 'width' => null, - ]; - } + /** + * Returns the default thumb settings + * + * @return array + */ + protected function defaults(): array + { + return [ + 'autoOrient' => true, + 'blur' => false, + 'crop' => false, + 'format' => null, + 'grayscale' => false, + 'height' => null, + 'quality' => 90, + 'scaleHeight' => null, + 'scaleWidth' => null, + 'width' => null, + ]; + } - /** - * Normalizes all thumb options - * - * @param array $options - * @return array - */ - protected function options(array $options = []): array - { - $options = array_merge($this->settings, $options); + /** + * Normalizes all thumb options + * + * @param array $options + * @return array + */ + protected function options(array $options = []): array + { + $options = array_merge($this->settings, $options); - // normalize the crop option - if ($options['crop'] === true) { - $options['crop'] = 'center'; - } + // normalize the crop option + if ($options['crop'] === true) { + $options['crop'] = 'center'; + } - // normalize the blur option - if ($options['blur'] === true) { - $options['blur'] = 10; - } + // normalize the blur option + if ($options['blur'] === true) { + $options['blur'] = 10; + } - // normalize the greyscale option - if (isset($options['greyscale']) === true) { - $options['grayscale'] = $options['greyscale']; - unset($options['greyscale']); - } + // normalize the greyscale option + if (isset($options['greyscale']) === true) { + $options['grayscale'] = $options['greyscale']; + unset($options['greyscale']); + } - // normalize the bw option - if (isset($options['bw']) === true) { - $options['grayscale'] = $options['bw']; - unset($options['bw']); - } + // normalize the bw option + if (isset($options['bw']) === true) { + $options['grayscale'] = $options['bw']; + unset($options['bw']); + } - if ($options['quality'] === null) { - $options['quality'] = $this->settings['quality']; - } + if ($options['quality'] === null) { + $options['quality'] = $this->settings['quality']; + } - return $options; - } + return $options; + } - /** - * Calculates the dimensions of the final thumb based - * on the given options and returns a full array with - * all the final options to be used for the image generator - * - * @param string $file - * @param array $options - * @return array - */ - public function preprocess(string $file, array $options = []) - { - $options = $this->options($options); - $image = new Image($file); + /** + * Calculates the dimensions of the final thumb based + * on the given options and returns a full array with + * all the final options to be used for the image generator + * + * @param string $file + * @param array $options + * @return array + */ + public function preprocess(string $file, array $options = []) + { + $options = $this->options($options); + $image = new Image($file); - $dimensions = $image->dimensions(); - $thumbDimensions = $dimensions->thumb($options); + $dimensions = $image->dimensions(); + $thumbDimensions = $dimensions->thumb($options); - $sourceWidth = $image->width(); - $sourceHeight = $image->height(); + $sourceWidth = $image->width(); + $sourceHeight = $image->height(); - $options['width'] = $thumbDimensions->width(); - $options['height'] = $thumbDimensions->height(); + $options['width'] = $thumbDimensions->width(); + $options['height'] = $thumbDimensions->height(); - // scale ratio compared to the source dimensions - $options['scaleWidth'] = $sourceWidth ? $options['width'] / $sourceWidth : null; - $options['scaleHeight'] = $sourceHeight ? $options['height'] / $sourceHeight : null; + // scale ratio compared to the source dimensions + $options['scaleWidth'] = $sourceWidth ? $options['width'] / $sourceWidth : null; + $options['scaleHeight'] = $sourceHeight ? $options['height'] / $sourceHeight : null; - return $options; - } + return $options; + } - /** - * This method must be replaced by the driver to run the - * actual image processing job. - * - * @param string $file - * @param array $options - * @return array - */ - public function process(string $file, array $options = []): array - { - return $this->preprocess($file, $options); - } + /** + * This method must be replaced by the driver to run the + * actual image processing job. + * + * @param string $file + * @param array $options + * @return array + */ + public function process(string $file, array $options = []): array + { + return $this->preprocess($file, $options); + } } diff --git a/kirby/src/Image/Darkroom/GdLib.php b/kirby/src/Image/Darkroom/GdLib.php index 971cbb7..bc381e6 100755 --- a/kirby/src/Image/Darkroom/GdLib.php +++ b/kirby/src/Image/Darkroom/GdLib.php @@ -17,108 +17,108 @@ use Kirby\Image\Darkroom; */ class GdLib extends Darkroom { - /** - * Processes the image with the SimpleImage library - * - * @param string $file - * @param array $options - * @return array - */ - public function process(string $file, array $options = []): array - { - $options = $this->preprocess($file, $options); - $mime = $this->mime($options); + /** + * Processes the image with the SimpleImage library + * + * @param string $file + * @param array $options + * @return array + */ + public function process(string $file, array $options = []): array + { + $options = $this->preprocess($file, $options); + $mime = $this->mime($options); - $image = new SimpleImage(); - $image->fromFile($file); + $image = new SimpleImage(); + $image->fromFile($file); - $image = $this->resize($image, $options); - $image = $this->autoOrient($image, $options); - $image = $this->blur($image, $options); - $image = $this->grayscale($image, $options); + $image = $this->resize($image, $options); + $image = $this->autoOrient($image, $options); + $image = $this->blur($image, $options); + $image = $this->grayscale($image, $options); - $image->toFile($file, $mime, $options['quality']); + $image->toFile($file, $mime, $options['quality']); - return $options; - } + return $options; + } - /** - * Activates the autoOrient option in SimpleImage - * unless this is deactivated - * - * @param \claviska\SimpleImage $image - * @param $options - * @return \claviska\SimpleImage - */ - protected function autoOrient(SimpleImage $image, $options) - { - if ($options['autoOrient'] === false) { - return $image; - } + /** + * Activates the autoOrient option in SimpleImage + * unless this is deactivated + * + * @param \claviska\SimpleImage $image + * @param $options + * @return \claviska\SimpleImage + */ + protected function autoOrient(SimpleImage $image, $options) + { + if ($options['autoOrient'] === false) { + return $image; + } - return $image->autoOrient(); - } + return $image->autoOrient(); + } - /** - * Wrapper around SimpleImage's resize and crop methods - * - * @param \claviska\SimpleImage $image - * @param array $options - * @return \claviska\SimpleImage - */ - protected function resize(SimpleImage $image, array $options) - { - if ($options['crop'] === false) { - return $image->resize($options['width'], $options['height']); - } + /** + * Wrapper around SimpleImage's resize and crop methods + * + * @param \claviska\SimpleImage $image + * @param array $options + * @return \claviska\SimpleImage + */ + protected function resize(SimpleImage $image, array $options) + { + if ($options['crop'] === false) { + return $image->resize($options['width'], $options['height']); + } - return $image->thumbnail($options['width'], $options['height'] ?? $options['width'], $options['crop']); - } + return $image->thumbnail($options['width'], $options['height'] ?? $options['width'], $options['crop']); + } - /** - * Applies the correct blur settings for SimpleImage - * - * @param \claviska\SimpleImage $image - * @param array $options - * @return \claviska\SimpleImage - */ - protected function blur(SimpleImage $image, array $options) - { - if ($options['blur'] === false) { - return $image; - } + /** + * Applies the correct blur settings for SimpleImage + * + * @param \claviska\SimpleImage $image + * @param array $options + * @return \claviska\SimpleImage + */ + protected function blur(SimpleImage $image, array $options) + { + if ($options['blur'] === false) { + return $image; + } - return $image->blur('gaussian', (int)$options['blur']); - } + return $image->blur('gaussian', (int)$options['blur']); + } - /** - * Applies grayscale conversion if activated in the options. - * - * @param \claviska\SimpleImage $image - * @param array $options - * @return \claviska\SimpleImage - */ - protected function grayscale(SimpleImage $image, array $options) - { - if ($options['grayscale'] === false) { - return $image; - } + /** + * Applies grayscale conversion if activated in the options. + * + * @param \claviska\SimpleImage $image + * @param array $options + * @return \claviska\SimpleImage + */ + protected function grayscale(SimpleImage $image, array $options) + { + if ($options['grayscale'] === false) { + return $image; + } - return $image->desaturate(); - } + return $image->desaturate(); + } - /** - * Returns mime type based on `format` option - * - * @param array $options - * @return string|null - */ - protected function mime(array $options): ?string - { - if ($options['format'] === null) { - return null; - } + /** + * Returns mime type based on `format` option + * + * @param array $options + * @return string|null + */ + protected function mime(array $options): ?string + { + if ($options['format'] === null) { + return null; + } - return Mime::fromExtension($options['format']); - } + return Mime::fromExtension($options['format']); + } } diff --git a/kirby/src/Image/Darkroom/ImageMagick.php b/kirby/src/Image/Darkroom/ImageMagick.php index 2e13cbc..33e33aa 100755 --- a/kirby/src/Image/Darkroom/ImageMagick.php +++ b/kirby/src/Image/Darkroom/ImageMagick.php @@ -17,238 +17,238 @@ use Kirby\Image\Darkroom; */ class ImageMagick extends Darkroom { - /** - * Activates imagemagick's auto-orient feature unless - * it is deactivated via the options - * - * @param string $file - * @param array $options - * @return string - */ - protected function autoOrient(string $file, array $options) - { - if ($options['autoOrient'] === true) { - return '-auto-orient'; - } - } + /** + * Activates imagemagick's auto-orient feature unless + * it is deactivated via the options + * + * @param string $file + * @param array $options + * @return string + */ + protected function autoOrient(string $file, array $options) + { + if ($options['autoOrient'] === true) { + return '-auto-orient'; + } + } - /** - * Applies the blur settings - * - * @param string $file - * @param array $options - * @return string - */ - protected function blur(string $file, array $options) - { - if ($options['blur'] !== false) { - return '-blur ' . escapeshellarg('0x' . $options['blur']); - } - } + /** + * Applies the blur settings + * + * @param string $file + * @param array $options + * @return string + */ + protected function blur(string $file, array $options) + { + if ($options['blur'] !== false) { + return '-blur ' . escapeshellarg('0x' . $options['blur']); + } + } - /** - * Keep animated gifs - * - * @param string $file - * @param array $options - * @return string - */ - protected function coalesce(string $file, array $options) - { - if (F::extension($file) === 'gif') { - return '-coalesce'; - } - } + /** + * Keep animated gifs + * + * @param string $file + * @param array $options + * @return string + */ + protected function coalesce(string $file, array $options) + { + if (F::extension($file) === 'gif') { + return '-coalesce'; + } + } - /** - * Creates the convert command with the right path to the binary file - * - * @param string $file - * @param array $options - * @return string - */ - protected function convert(string $file, array $options): string - { - $command = escapeshellarg($options['bin']); + /** + * Creates the convert command with the right path to the binary file + * + * @param string $file + * @param array $options + * @return string + */ + protected function convert(string $file, array $options): string + { + $command = escapeshellarg($options['bin']); - // limit to single-threading to keep CPU usage sane - $command .= ' -limit thread 1'; + // limit to single-threading to keep CPU usage sane + $command .= ' -limit thread 1'; - // add JPEG size hint to optimize CPU and memory usage - if (F::mime($file) === 'image/jpeg') { - // add hint only when downscaling - if ($options['scaleWidth'] < 1 && $options['scaleHeight'] < 1) { - $command .= ' -define ' . escapeshellarg(sprintf('jpeg:size=%dx%d', $options['width'], $options['height'])); - } - } + // add JPEG size hint to optimize CPU and memory usage + if (F::mime($file) === 'image/jpeg') { + // add hint only when downscaling + if ($options['scaleWidth'] < 1 && $options['scaleHeight'] < 1) { + $command .= ' -define ' . escapeshellarg(sprintf('jpeg:size=%dx%d', $options['width'], $options['height'])); + } + } - // append input file - return $command . ' ' . escapeshellarg($file); - } + // append input file + return $command . ' ' . escapeshellarg($file); + } - /** - * Returns additional default parameters for imagemagick - * - * @return array - */ - protected function defaults(): array - { - return parent::defaults() + [ - 'bin' => 'convert', - 'interlace' => false, - ]; - } + /** + * Returns additional default parameters for imagemagick + * + * @return array + */ + protected function defaults(): array + { + return parent::defaults() + [ + 'bin' => 'convert', + 'interlace' => false, + ]; + } - /** - * Applies the correct settings for grayscale images - * - * @param string $file - * @param array $options - * @return string - */ - protected function grayscale(string $file, array $options) - { - if ($options['grayscale'] === true) { - return '-colorspace gray'; - } - } + /** + * Applies the correct settings for grayscale images + * + * @param string $file + * @param array $options + * @return string + */ + protected function grayscale(string $file, array $options) + { + if ($options['grayscale'] === true) { + return '-colorspace gray'; + } + } - /** - * Applies the correct settings for interlaced JPEGs if - * activated via options - * - * @param string $file - * @param array $options - * @return string - */ - protected function interlace(string $file, array $options) - { - if ($options['interlace'] === true) { - return '-interlace line'; - } - } + /** + * Applies the correct settings for interlaced JPEGs if + * activated via options + * + * @param string $file + * @param array $options + * @return string + */ + protected function interlace(string $file, array $options) + { + if ($options['interlace'] === true) { + return '-interlace line'; + } + } - /** - * Creates and runs the full imagemagick command - * to process the image - * - * @param string $file - * @param array $options - * @return array - * @throws \Exception - */ - public function process(string $file, array $options = []): array - { - $options = $this->preprocess($file, $options); - $command = []; + /** + * Creates and runs the full imagemagick command + * to process the image + * + * @param string $file + * @param array $options + * @return array + * @throws \Exception + */ + public function process(string $file, array $options = []): array + { + $options = $this->preprocess($file, $options); + $command = []; - $command[] = $this->convert($file, $options); - $command[] = $this->strip($file, $options); - $command[] = $this->interlace($file, $options); - $command[] = $this->coalesce($file, $options); - $command[] = $this->grayscale($file, $options); - $command[] = $this->autoOrient($file, $options); - $command[] = $this->resize($file, $options); - $command[] = $this->quality($file, $options); - $command[] = $this->blur($file, $options); - $command[] = $this->save($file, $options); + $command[] = $this->convert($file, $options); + $command[] = $this->strip($file, $options); + $command[] = $this->interlace($file, $options); + $command[] = $this->coalesce($file, $options); + $command[] = $this->grayscale($file, $options); + $command[] = $this->autoOrient($file, $options); + $command[] = $this->resize($file, $options); + $command[] = $this->quality($file, $options); + $command[] = $this->blur($file, $options); + $command[] = $this->save($file, $options); - // remove all null values and join the parts - $command = implode(' ', array_filter($command)); + // remove all null values and join the parts + $command = implode(' ', array_filter($command)); - // try to execute the command - exec($command, $output, $return); + // try to execute the command + exec($command, $output, $return); - // log broken commands - if ($return !== 0) { - throw new Exception('The imagemagick convert command could not be executed: ' . $command); - } + // log broken commands + if ($return !== 0) { + throw new Exception('The imagemagick convert command could not be executed: ' . $command); + } - return $options; - } + return $options; + } - /** - * Applies the correct JPEG compression quality settings - * - * @param string $file - * @param array $options - * @return string - */ - protected function quality(string $file, array $options): string - { - return '-quality ' . escapeshellarg($options['quality']); - } + /** + * Applies the correct JPEG compression quality settings + * + * @param string $file + * @param array $options + * @return string + */ + protected function quality(string $file, array $options): string + { + return '-quality ' . escapeshellarg($options['quality']); + } - /** - * Creates the correct options to crop or resize the image - * and translates the crop positions for imagemagick - * - * @param string $file - * @param array $options - * @return string - */ - protected function resize(string $file, array $options): string - { - // simple resize - if ($options['crop'] === false) { - return '-thumbnail ' . escapeshellarg(sprintf('%sx%s!', $options['width'], $options['height'])); - } + /** + * Creates the correct options to crop or resize the image + * and translates the crop positions for imagemagick + * + * @param string $file + * @param array $options + * @return string + */ + protected function resize(string $file, array $options): string + { + // simple resize + if ($options['crop'] === false) { + return '-thumbnail ' . escapeshellarg(sprintf('%sx%s!', $options['width'], $options['height'])); + } - $gravities = [ - 'top left' => 'NorthWest', - 'top' => 'North', - 'top right' => 'NorthEast', - 'left' => 'West', - 'center' => 'Center', - 'right' => 'East', - 'bottom left' => 'SouthWest', - 'bottom' => 'South', - 'bottom right' => 'SouthEast' - ]; + $gravities = [ + 'top left' => 'NorthWest', + 'top' => 'North', + 'top right' => 'NorthEast', + 'left' => 'West', + 'center' => 'Center', + 'right' => 'East', + 'bottom left' => 'SouthWest', + 'bottom' => 'South', + 'bottom right' => 'SouthEast' + ]; - // translate the gravity option into something imagemagick understands - $gravity = $gravities[$options['crop']] ?? 'Center'; + // translate the gravity option into something imagemagick understands + $gravity = $gravities[$options['crop']] ?? 'Center'; - $command = '-thumbnail ' . escapeshellarg(sprintf('%sx%s^', $options['width'], $options['height'])); - $command .= ' -gravity ' . escapeshellarg($gravity); - $command .= ' -crop ' . escapeshellarg(sprintf('%sx%s+0+0', $options['width'], $options['height'])); + $command = '-thumbnail ' . escapeshellarg(sprintf('%sx%s^', $options['width'], $options['height'])); + $command .= ' -gravity ' . escapeshellarg($gravity); + $command .= ' -crop ' . escapeshellarg(sprintf('%sx%s+0+0', $options['width'], $options['height'])); - return $command; - } + return $command; + } - /** - * Creates the option for the output file - * - * @param string $file - * @param array $options - * @return string - */ - protected function save(string $file, array $options): string - { - if ($options['format'] !== null) { - $file = pathinfo($file, PATHINFO_DIRNAME) . '/' . pathinfo($file, PATHINFO_FILENAME) . '.' . $options['format']; - } + /** + * Creates the option for the output file + * + * @param string $file + * @param array $options + * @return string + */ + protected function save(string $file, array $options): string + { + if ($options['format'] !== null) { + $file = pathinfo($file, PATHINFO_DIRNAME) . '/' . pathinfo($file, PATHINFO_FILENAME) . '.' . $options['format']; + } - return escapeshellarg($file); - } + return escapeshellarg($file); + } - /** - * Removes all metadata from the image - * - * @param string $file - * @param array $options - * @return string - */ - protected function strip(string $file, array $options): string - { - if (F::extension($file) === 'png') { - // ImageMagick does not support keeping ICC profiles while - // stripping other privacy- and security-related information, - // such as GPS data; so discard all color profiles for PNG files - // (tested with ImageMagick 7.0.11-14 Q16 x86_64 2021-05-31) - return '-strip'; - } + /** + * Removes all metadata from the image + * + * @param string $file + * @param array $options + * @return string + */ + protected function strip(string $file, array $options): string + { + if (F::extension($file) === 'png') { + // ImageMagick does not support keeping ICC profiles while + // stripping other privacy- and security-related information, + // such as GPS data; so discard all color profiles for PNG files + // (tested with ImageMagick 7.0.11-14 Q16 x86_64 2021-05-31) + return '-strip'; + } - return ''; - } + return ''; + } } diff --git a/kirby/src/Image/Dimensions.php b/kirby/src/Image/Dimensions.php index 23f9d40..30931c6 100755 --- a/kirby/src/Image/Dimensions.php +++ b/kirby/src/Image/Dimensions.php @@ -16,415 +16,415 @@ namespace Kirby\Image; */ class Dimensions { - /** - * the height of the parent object - * - * @var int - */ - public $height = 0; + /** + * the height of the parent object + * + * @var int + */ + public $height = 0; - /** - * the width of the parent object - * - * @var int - */ - public $width = 0; + /** + * the width of the parent object + * + * @var int + */ + public $width = 0; - /** - * Constructor - * - * @param int $width - * @param int $height - */ - public function __construct(int $width, int $height) - { - $this->width = $width; - $this->height = $height; - } + /** + * Constructor + * + * @param int $width + * @param int $height + */ + public function __construct(int $width, int $height) + { + $this->width = $width; + $this->height = $height; + } - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return $this->toArray(); - } + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return $this->toArray(); + } - /** - * Echos the dimensions as width × height - * - * @return string - */ - public function __toString(): string - { - return $this->width . ' × ' . $this->height; - } + /** + * Echos the dimensions as width × height + * + * @return string + */ + public function __toString(): string + { + return $this->width . ' × ' . $this->height; + } - /** - * Crops the dimensions by width and height - * - * @param int $width - * @param int|null $height - * @return $this - */ - public function crop(int $width, int $height = null) - { - $this->width = $width; - $this->height = $width; + /** + * Crops the dimensions by width and height + * + * @param int $width + * @param int|null $height + * @return $this + */ + public function crop(int $width, int $height = null) + { + $this->width = $width; + $this->height = $width; - if ($height !== 0 && $height !== null) { - $this->height = $height; - } + if ($height !== 0 && $height !== null) { + $this->height = $height; + } - return $this; - } + return $this; + } - /** - * Returns the height - * - * @return int - */ - public function height() - { - return $this->height; - } + /** + * Returns the height + * + * @return int + */ + public function height() + { + return $this->height; + } - /** - * Recalculates the width and height to fit into the given box. - * - * - * - * $dimensions = new Dimensions(1200, 768); - * $dimensions->fit(500); - * - * echo $dimensions->width(); - * // output: 500 - * - * echo $dimensions->height(); - * // output: 320 - * - * - * - * @param int $box the max width and/or height - * @param bool $force If true, the dimensions will be - * upscaled to fit the box if smaller - * @return $this object with recalculated dimensions - */ - public function fit(int $box, bool $force = false) - { - if ($this->width === 0 || $this->height === 0) { - $this->width = $box; - $this->height = $box; - return $this; - } + /** + * Recalculates the width and height to fit into the given box. + * + * + * + * $dimensions = new Dimensions(1200, 768); + * $dimensions->fit(500); + * + * echo $dimensions->width(); + * // output: 500 + * + * echo $dimensions->height(); + * // output: 320 + * + * + * + * @param int $box the max width and/or height + * @param bool $force If true, the dimensions will be + * upscaled to fit the box if smaller + * @return $this object with recalculated dimensions + */ + public function fit(int $box, bool $force = false) + { + if ($this->width === 0 || $this->height === 0) { + $this->width = $box; + $this->height = $box; + return $this; + } - $ratio = $this->ratio(); + $ratio = $this->ratio(); - if ($this->width > $this->height) { - // wider than tall - if ($this->width > $box || $force === true) { - $this->width = $box; - } - $this->height = (int)round($this->width / $ratio); - } elseif ($this->height > $this->width) { - // taller than wide - if ($this->height > $box || $force === true) { - $this->height = $box; - } - $this->width = (int)round($this->height * $ratio); - } elseif ($this->width > $box) { - // width = height but bigger than box - $this->width = $box; - $this->height = $box; - } + if ($this->width > $this->height) { + // wider than tall + if ($this->width > $box || $force === true) { + $this->width = $box; + } + $this->height = (int)round($this->width / $ratio); + } elseif ($this->height > $this->width) { + // taller than wide + if ($this->height > $box || $force === true) { + $this->height = $box; + } + $this->width = (int)round($this->height * $ratio); + } elseif ($this->width > $box) { + // width = height but bigger than box + $this->width = $box; + $this->height = $box; + } - return $this; - } + return $this; + } - /** - * Recalculates the width and height to fit the given height - * - * - * - * $dimensions = new Dimensions(1200, 768); - * $dimensions->fitHeight(500); - * - * echo $dimensions->width(); - * // output: 781 - * - * echo $dimensions->height(); - * // output: 500 - * - * - * - * @param int|null $fit the max height - * @param bool $force If true, the dimensions will be - * upscaled to fit the box if smaller - * @return $this object with recalculated dimensions - */ - public function fitHeight(int $fit = null, bool $force = false) - { - return $this->fitSize('height', $fit, $force); - } + /** + * Recalculates the width and height to fit the given height + * + * + * + * $dimensions = new Dimensions(1200, 768); + * $dimensions->fitHeight(500); + * + * echo $dimensions->width(); + * // output: 781 + * + * echo $dimensions->height(); + * // output: 500 + * + * + * + * @param int|null $fit the max height + * @param bool $force If true, the dimensions will be + * upscaled to fit the box if smaller + * @return $this object with recalculated dimensions + */ + public function fitHeight(int $fit = null, bool $force = false) + { + return $this->fitSize('height', $fit, $force); + } - /** - * Helper for fitWidth and fitHeight methods - * - * @param string $ref reference (width or height) - * @param int|null $fit the max width - * @param bool $force If true, the dimensions will be - * upscaled to fit the box if smaller - * @return $this object with recalculated dimensions - */ - protected function fitSize(string $ref, int $fit = null, bool $force = false) - { - if ($fit === 0 || $fit === null) { - return $this; - } + /** + * Helper for fitWidth and fitHeight methods + * + * @param string $ref reference (width or height) + * @param int|null $fit the max width + * @param bool $force If true, the dimensions will be + * upscaled to fit the box if smaller + * @return $this object with recalculated dimensions + */ + protected function fitSize(string $ref, int $fit = null, bool $force = false) + { + if ($fit === 0 || $fit === null) { + return $this; + } - if ($this->$ref <= $fit && !$force) { - return $this; - } + if ($this->$ref <= $fit && !$force) { + return $this; + } - $ratio = $this->ratio(); - $mode = $ref === 'width'; - $this->width = $mode ? $fit : (int)round($fit * $ratio); - $this->height = !$mode ? $fit : (int)round($fit / $ratio); + $ratio = $this->ratio(); + $mode = $ref === 'width'; + $this->width = $mode ? $fit : (int)round($fit * $ratio); + $this->height = !$mode ? $fit : (int)round($fit / $ratio); - return $this; - } + return $this; + } - /** - * Recalculates the width and height to fit the given width - * - * - * - * $dimensions = new Dimensions(1200, 768); - * $dimensions->fitWidth(500); - * - * echo $dimensions->width(); - * // output: 500 - * - * echo $dimensions->height(); - * // output: 320 - * - * - * - * @param int|null $fit the max width - * @param bool $force If true, the dimensions will be - * upscaled to fit the box if smaller - * @return $this object with recalculated dimensions - */ - public function fitWidth(int $fit = null, bool $force = false) - { - return $this->fitSize('width', $fit, $force); - } + /** + * Recalculates the width and height to fit the given width + * + * + * + * $dimensions = new Dimensions(1200, 768); + * $dimensions->fitWidth(500); + * + * echo $dimensions->width(); + * // output: 500 + * + * echo $dimensions->height(); + * // output: 320 + * + * + * + * @param int|null $fit the max width + * @param bool $force If true, the dimensions will be + * upscaled to fit the box if smaller + * @return $this object with recalculated dimensions + */ + public function fitWidth(int $fit = null, bool $force = false) + { + return $this->fitSize('width', $fit, $force); + } - /** - * Recalculates the dimensions by the width and height - * - * @param int|null $width the max height - * @param int|null $height the max width - * @param bool $force - * @return $this - */ - public function fitWidthAndHeight(int $width = null, int $height = null, bool $force = false) - { - if ($this->width > $this->height) { - $this->fitWidth($width, $force); + /** + * Recalculates the dimensions by the width and height + * + * @param int|null $width the max height + * @param int|null $height the max width + * @param bool $force + * @return $this + */ + public function fitWidthAndHeight(int $width = null, int $height = null, bool $force = false) + { + if ($this->width > $this->height) { + $this->fitWidth($width, $force); - // do another check for the max height - if ($this->height > $height) { - $this->fitHeight($height); - } - } else { - $this->fitHeight($height, $force); + // do another check for the max height + if ($this->height > $height) { + $this->fitHeight($height); + } + } else { + $this->fitHeight($height, $force); - // do another check for the max width - if ($this->width > $width) { - $this->fitWidth($width); - } - } + // do another check for the max width + if ($this->width > $width) { + $this->fitWidth($width); + } + } - return $this; - } + return $this; + } - /** - * Detect the dimensions for an image file - * - * @param string $root - * @return static - */ - public static function forImage(string $root) - { - if (file_exists($root) === false) { - return new static(0, 0); - } + /** + * Detect the dimensions for an image file + * + * @param string $root + * @return static + */ + public static function forImage(string $root) + { + if (file_exists($root) === false) { + return new static(0, 0); + } - $size = getimagesize($root); - return new static($size[0] ?? 0, $size[1] ?? 1); - } + $size = getimagesize($root); + return new static($size[0] ?? 0, $size[1] ?? 1); + } - /** - * Detect the dimensions for a svg file - * - * @param string $root - * @return static - */ - public static function forSvg(string $root) - { - // avoid xml errors - libxml_use_internal_errors(true); + /** + * Detect the dimensions for a svg file + * + * @param string $root + * @return static + */ + public static function forSvg(string $root) + { + // avoid xml errors + libxml_use_internal_errors(true); - $content = file_get_contents($root); - $height = 0; - $width = 0; - $xml = simplexml_load_string($content); + $content = file_get_contents($root); + $height = 0; + $width = 0; + $xml = simplexml_load_string($content); - if ($xml !== false) { - $attr = $xml->attributes(); - $width = (int)($attr->width); - $height = (int)($attr->height); - if (($width === 0 || $height === 0) && empty($attr->viewBox) === false) { - $box = explode(' ', $attr->viewBox); - $width = (int)($box[2] ?? 0); - $height = (int)($box[3] ?? 0); - } - } + if ($xml !== false) { + $attr = $xml->attributes(); + $width = (int)($attr->width); + $height = (int)($attr->height); + if (($width === 0 || $height === 0) && empty($attr->viewBox) === false) { + $box = explode(' ', $attr->viewBox); + $width = (int)($box[2] ?? 0); + $height = (int)($box[3] ?? 0); + } + } - return new static($width, $height); - } + return new static($width, $height); + } - /** - * Checks if the dimensions are landscape - * - * @return bool - */ - public function landscape(): bool - { - return $this->width > $this->height; - } + /** + * Checks if the dimensions are landscape + * + * @return bool + */ + public function landscape(): bool + { + return $this->width > $this->height; + } - /** - * Returns a string representation of the orientation - * - * @return string|false - */ - public function orientation() - { - if (!$this->ratio()) { - return false; - } + /** + * Returns a string representation of the orientation + * + * @return string|false + */ + public function orientation() + { + if (!$this->ratio()) { + return false; + } - if ($this->portrait()) { - return 'portrait'; - } + if ($this->portrait()) { + return 'portrait'; + } - if ($this->landscape()) { - return 'landscape'; - } + if ($this->landscape()) { + return 'landscape'; + } - return 'square'; - } + return 'square'; + } - /** - * Checks if the dimensions are portrait - * - * @return bool - */ - public function portrait(): bool - { - return $this->height > $this->width; - } + /** + * Checks if the dimensions are portrait + * + * @return bool + */ + public function portrait(): bool + { + return $this->height > $this->width; + } - /** - * Calculates and returns the ratio - * - * - * - * $dimensions = new Dimensions(1200, 768); - * echo $dimensions->ratio(); - * // output: 1.5625 - * - * - * - * @return float - */ - public function ratio(): float - { - if ($this->width !== 0 && $this->height !== 0) { - return $this->width / $this->height; - } + /** + * Calculates and returns the ratio + * + * + * + * $dimensions = new Dimensions(1200, 768); + * echo $dimensions->ratio(); + * // output: 1.5625 + * + * + * + * @return float + */ + public function ratio(): float + { + if ($this->width !== 0 && $this->height !== 0) { + return $this->width / $this->height; + } - return 0; - } + return 0; + } - /** - * @param int|null $width - * @param int|null $height - * @param bool $force - * @return $this - */ - public function resize(int $width = null, int $height = null, bool $force = false) - { - return $this->fitWidthAndHeight($width, $height, $force); - } + /** + * @param int|null $width + * @param int|null $height + * @param bool $force + * @return $this + */ + public function resize(int $width = null, int $height = null, bool $force = false) + { + return $this->fitWidthAndHeight($width, $height, $force); + } - /** - * Checks if the dimensions are square - * - * @return bool - */ - public function square(): bool - { - return $this->width === $this->height; - } + /** + * Checks if the dimensions are square + * + * @return bool + */ + public function square(): bool + { + return $this->width === $this->height; + } - /** - * Resize and crop - * - * @param array $options - * @return $this - */ - public function thumb(array $options = []) - { - $width = $options['width'] ?? null; - $height = $options['height'] ?? null; - $crop = $options['crop'] ?? false; - $method = $crop !== false ? 'crop' : 'resize'; + /** + * Resize and crop + * + * @param array $options + * @return $this + */ + public function thumb(array $options = []) + { + $width = $options['width'] ?? null; + $height = $options['height'] ?? null; + $crop = $options['crop'] ?? false; + $method = $crop !== false ? 'crop' : 'resize'; - if ($width === null && $height === null) { - return $this; - } + if ($width === null && $height === null) { + return $this; + } - return $this->$method($width, $height); - } + return $this->$method($width, $height); + } - /** - * Converts the dimensions object - * to a plain PHP array - * - * @return array - */ - public function toArray(): array - { - return [ - 'width' => $this->width(), - 'height' => $this->height(), - 'ratio' => $this->ratio(), - 'orientation' => $this->orientation(), - ]; - } + /** + * Converts the dimensions object + * to a plain PHP array + * + * @return array + */ + public function toArray(): array + { + return [ + 'width' => $this->width(), + 'height' => $this->height(), + 'ratio' => $this->ratio(), + 'orientation' => $this->orientation(), + ]; + } - /** - * Returns the width - * - * @return int - */ - public function width(): int - { - return $this->width; - } + /** + * Returns the width + * + * @return int + */ + public function width(): int + { + return $this->width; + } } diff --git a/kirby/src/Image/Exif.php b/kirby/src/Image/Exif.php index 2dd120e..9405271 100755 --- a/kirby/src/Image/Exif.php +++ b/kirby/src/Image/Exif.php @@ -15,284 +15,284 @@ use Kirby\Toolkit\V; */ class Exif { - /** - * the parent image object - * @var \Kirby\Image\Image - */ - protected $image; + /** + * the parent image object + * @var \Kirby\Image\Image + */ + protected $image; - /** - * the raw exif array - * @var array - */ - protected $data = []; + /** + * the raw exif array + * @var array + */ + protected $data = []; - /** - * the camera object with model and make - * @var Camera - */ - protected $camera; + /** + * the camera object with model and make + * @var Camera + */ + protected $camera; - /** - * the location object - * @var Location - */ - protected $location; + /** + * the location object + * @var Location + */ + protected $location; - /** - * the timestamp - * - * @var string - */ - protected $timestamp; + /** + * the timestamp + * + * @var string + */ + protected $timestamp; - /** - * the exposure value - * - * @var string - */ - protected $exposure; + /** + * the exposure value + * + * @var string + */ + protected $exposure; - /** - * the aperture value - * - * @var string - */ - protected $aperture; + /** + * the aperture value + * + * @var string + */ + protected $aperture; - /** - * iso value - * - * @var string - */ - protected $iso; + /** + * iso value + * + * @var string + */ + protected $iso; - /** - * focal length - * - * @var string - */ - protected $focalLength; + /** + * focal length + * + * @var string + */ + protected $focalLength; - /** - * color or black/white - * @var bool - */ - protected $isColor; + /** + * color or black/white + * @var bool + */ + protected $isColor; - /** - * Constructor - * - * @param \Kirby\Image\Image $image - */ - public function __construct(Image $image) - { - $this->image = $image; - $this->data = $this->read(); - $this->parse(); - } + /** + * Constructor + * + * @param \Kirby\Image\Image $image + */ + public function __construct(Image $image) + { + $this->image = $image; + $this->data = $this->read(); + $this->parse(); + } - /** - * Returns the raw data array from the parser - * - * @return array - */ - public function data(): array - { - return $this->data; - } + /** + * Returns the raw data array from the parser + * + * @return array + */ + public function data(): array + { + return $this->data; + } - /** - * Returns the Camera object - * - * @return \Kirby\Image\Camera|null - */ - public function camera() - { - if ($this->camera !== null) { - return $this->camera; - } + /** + * Returns the Camera object + * + * @return \Kirby\Image\Camera|null + */ + public function camera() + { + if ($this->camera !== null) { + return $this->camera; + } - return $this->camera = new Camera($this->data); - } + return $this->camera = new Camera($this->data); + } - /** - * Returns the location object - * - * @return \Kirby\Image\Location|null - */ - public function location() - { - if ($this->location !== null) { - return $this->location; - } + /** + * Returns the location object + * + * @return \Kirby\Image\Location|null + */ + public function location() + { + if ($this->location !== null) { + return $this->location; + } - return $this->location = new Location($this->data); - } + return $this->location = new Location($this->data); + } - /** - * Returns the timestamp - * - * @return string|null - */ - public function timestamp() - { - return $this->timestamp; - } + /** + * Returns the timestamp + * + * @return string|null + */ + public function timestamp() + { + return $this->timestamp; + } - /** - * Returns the exposure - * - * @return string|null - */ - public function exposure() - { - return $this->exposure; - } + /** + * Returns the exposure + * + * @return string|null + */ + public function exposure() + { + return $this->exposure; + } - /** - * Returns the aperture - * - * @return string|null - */ - public function aperture() - { - return $this->aperture; - } + /** + * Returns the aperture + * + * @return string|null + */ + public function aperture() + { + return $this->aperture; + } - /** - * Returns the iso value - * - * @return int|null - */ - public function iso() - { - return $this->iso; - } + /** + * Returns the iso value + * + * @return int|null + */ + public function iso() + { + return $this->iso; + } - /** - * Checks if this is a color picture - * - * @return bool|null - */ - public function isColor() - { - return $this->isColor; - } + /** + * Checks if this is a color picture + * + * @return bool|null + */ + public function isColor() + { + return $this->isColor; + } - /** - * Checks if this is a bw picture - * - * @return bool|null - */ - public function isBW(): ?bool - { - return ($this->isColor !== null) ? $this->isColor === false : null; - } + /** + * Checks if this is a bw picture + * + * @return bool|null + */ + public function isBW(): ?bool + { + return ($this->isColor !== null) ? $this->isColor === false : null; + } - /** - * Returns the focal length - * - * @return string|null - */ - public function focalLength() - { - return $this->focalLength; - } + /** + * Returns the focal length + * + * @return string|null + */ + public function focalLength() + { + return $this->focalLength; + } - /** - * Read the exif data of the image object if possible - * - * @return mixed - */ - protected function read(): array - { - // @codeCoverageIgnoreStart - if (function_exists('exif_read_data') === false) { - return []; - } - // @codeCoverageIgnoreEnd + /** + * Read the exif data of the image object if possible + * + * @return mixed + */ + protected function read(): array + { + // @codeCoverageIgnoreStart + if (function_exists('exif_read_data') === false) { + return []; + } + // @codeCoverageIgnoreEnd - $data = @exif_read_data($this->image->root()); - return is_array($data) ? $data : []; - } + $data = @exif_read_data($this->image->root()); + return is_array($data) ? $data : []; + } - /** - * Get all computed data - * - * @return array - */ - protected function computed(): array - { - return $this->data['COMPUTED'] ?? []; - } + /** + * Get all computed data + * + * @return array + */ + protected function computed(): array + { + return $this->data['COMPUTED'] ?? []; + } - /** - * Pareses and stores all relevant exif data - */ - protected function parse() - { - $this->timestamp = $this->parseTimestamp(); - $this->exposure = $this->data['ExposureTime'] ?? null; - $this->iso = $this->data['ISOSpeedRatings'] ?? null; - $this->focalLength = $this->parseFocalLength(); - $this->aperture = $this->computed()['ApertureFNumber'] ?? null; - $this->isColor = V::accepted($this->computed()['IsColor'] ?? null); - } + /** + * Pareses and stores all relevant exif data + */ + protected function parse() + { + $this->timestamp = $this->parseTimestamp(); + $this->exposure = $this->data['ExposureTime'] ?? null; + $this->iso = $this->data['ISOSpeedRatings'] ?? null; + $this->focalLength = $this->parseFocalLength(); + $this->aperture = $this->computed()['ApertureFNumber'] ?? null; + $this->isColor = V::accepted($this->computed()['IsColor'] ?? null); + } - /** - * Return the timestamp when the picture has been taken - * - * @return string|int - */ - protected function parseTimestamp() - { - if (isset($this->data['DateTimeOriginal']) === true) { - return strtotime($this->data['DateTimeOriginal']); - } + /** + * Return the timestamp when the picture has been taken + * + * @return string|int + */ + protected function parseTimestamp() + { + if (isset($this->data['DateTimeOriginal']) === true) { + return strtotime($this->data['DateTimeOriginal']); + } - return $this->data['FileDateTime'] ?? $this->image->modified(); - } + return $this->data['FileDateTime'] ?? $this->image->modified(); + } - /** - * Return the focal length - * - * @return string|null - */ - protected function parseFocalLength() - { - return $this->data['FocalLength'] ?? $this->data['FocalLengthIn35mmFilm'] ?? null; - } + /** + * Return the focal length + * + * @return string|null + */ + protected function parseFocalLength() + { + return $this->data['FocalLength'] ?? $this->data['FocalLengthIn35mmFilm'] ?? null; + } - /** - * Converts the object into a nicely readable array - * - * @return array - */ - public function toArray(): array - { - return [ - 'camera' => $this->camera() ? $this->camera()->toArray() : null, - 'location' => $this->location() ? $this->location()->toArray() : null, - 'timestamp' => $this->timestamp(), - 'exposure' => $this->exposure(), - 'aperture' => $this->aperture(), - 'iso' => $this->iso(), - 'focalLength' => $this->focalLength(), - 'isColor' => $this->isColor() - ]; - } + /** + * Converts the object into a nicely readable array + * + * @return array + */ + public function toArray(): array + { + return [ + 'camera' => $this->camera() ? $this->camera()->toArray() : null, + 'location' => $this->location() ? $this->location()->toArray() : null, + 'timestamp' => $this->timestamp(), + 'exposure' => $this->exposure(), + 'aperture' => $this->aperture(), + 'iso' => $this->iso(), + 'focalLength' => $this->focalLength(), + 'isColor' => $this->isColor() + ]; + } - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return array_merge($this->toArray(), [ - 'camera' => $this->camera(), - 'location' => $this->location() - ]); - } + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return array_merge($this->toArray(), [ + 'camera' => $this->camera(), + 'location' => $this->location() + ]); + } } diff --git a/kirby/src/Image/Image.php b/kirby/src/Image/Image.php index f50471f..b505a9a 100755 --- a/kirby/src/Image/Image.php +++ b/kirby/src/Image/Image.php @@ -22,230 +22,230 @@ use Kirby\Toolkit\Html; */ class Image extends File { - /** - * @var \Kirby\Image\Exif|null - */ - protected $exif; + /** + * @var \Kirby\Image\Exif|null + */ + protected $exif; - /** - * @var \Kirby\Image\Dimensions|null - */ - protected $dimensions; + /** + * @var \Kirby\Image\Dimensions|null + */ + protected $dimensions; - /** - * @var array - */ - public static $resizableTypes = [ - 'jpg', - 'jpeg', - 'gif', - 'png', - 'webp' - ]; + /** + * @var array + */ + public static $resizableTypes = [ + 'jpg', + 'jpeg', + 'gif', + 'png', + 'webp' + ]; - /** - * @var array - */ - public static $viewableTypes = [ - 'avif', - 'jpg', - 'jpeg', - 'gif', - 'png', - 'svg', - 'webp' - ]; + /** + * @var array + */ + public static $viewableTypes = [ + 'avif', + 'jpg', + 'jpeg', + 'gif', + 'png', + 'svg', + 'webp' + ]; - /** - * Validation rules to be used for `::match()` - * - * @var array - */ - public static $validations = [ - 'maxsize' => ['size', 'max'], - 'minsize' => ['size', 'min'], - 'maxwidth' => ['width', 'max'], - 'minwidth' => ['width', 'min'], - 'maxheight' => ['height', 'max'], - 'minheight' => ['height', 'min'], - 'orientation' => ['orientation', 'same'] - ]; + /** + * Validation rules to be used for `::match()` + * + * @var array + */ + public static $validations = [ + 'maxsize' => ['size', 'max'], + 'minsize' => ['size', 'min'], + 'maxwidth' => ['width', 'max'], + 'minwidth' => ['width', 'min'], + 'maxheight' => ['height', 'max'], + 'minheight' => ['height', 'min'], + 'orientation' => ['orientation', 'same'] + ]; - /** - * Returns the `` tag for the image object - * - * @return string - */ - public function __toString(): string - { - return $this->html(); - } + /** + * Returns the `` tag for the image object + * + * @return string + */ + public function __toString(): string + { + return $this->html(); + } - /** - * Returns the dimensions of the file if possible - * - * @return \Kirby\Image\Dimensions - */ - public function dimensions() - { - if ($this->dimensions !== null) { - return $this->dimensions; - } + /** + * Returns the dimensions of the file if possible + * + * @return \Kirby\Image\Dimensions + */ + public function dimensions() + { + if ($this->dimensions !== null) { + return $this->dimensions; + } - if (in_array($this->mime(), [ - 'image/jpeg', - 'image/jp2', - 'image/png', - 'image/gif', - 'image/webp' - ])) { - return $this->dimensions = Dimensions::forImage($this->root); - } + if (in_array($this->mime(), [ + 'image/jpeg', + 'image/jp2', + 'image/png', + 'image/gif', + 'image/webp' + ])) { + return $this->dimensions = Dimensions::forImage($this->root); + } - if ($this->extension() === 'svg') { - return $this->dimensions = Dimensions::forSvg($this->root); - } + if ($this->extension() === 'svg') { + return $this->dimensions = Dimensions::forSvg($this->root); + } - return $this->dimensions = new Dimensions(0, 0); - } + return $this->dimensions = new Dimensions(0, 0); + } - /** - * Returns the exif object for this file (if image) - * - * @return \Kirby\Image\Exif - */ - public function exif() - { - return $this->exif ??= new Exif($this); - } + /** + * Returns the exif object for this file (if image) + * + * @return \Kirby\Image\Exif + */ + public function exif() + { + return $this->exif ??= new Exif($this); + } - /** - * Returns the height of the asset - * - * @return int - */ - public function height(): int - { - return $this->dimensions()->height(); - } + /** + * Returns the height of the asset + * + * @return int + */ + public function height(): int + { + return $this->dimensions()->height(); + } - /** - * Converts the file to html - * - * @param array $attr - * @return string - */ - public function html(array $attr = []): string - { - return Html::img($this->url(), $attr); - } + /** + * Converts the file to html + * + * @param array $attr + * @return string + */ + public function html(array $attr = []): string + { + return Html::img($this->url(), $attr); + } - /** - * Returns the PHP imagesize array - * - * @return array - */ - public function imagesize(): array - { - return getimagesize($this->root); - } + /** + * Returns the PHP imagesize array + * + * @return array + */ + public function imagesize(): array + { + return getimagesize($this->root); + } - /** - * Checks if the dimensions of the asset are portrait - * - * @return bool - */ - public function isPortrait(): bool - { - return $this->dimensions()->portrait(); - } + /** + * Checks if the dimensions of the asset are portrait + * + * @return bool + */ + public function isPortrait(): bool + { + return $this->dimensions()->portrait(); + } - /** - * Checks if the dimensions of the asset are landscape - * - * @return bool - */ - public function isLandscape(): bool - { - return $this->dimensions()->landscape(); - } + /** + * Checks if the dimensions of the asset are landscape + * + * @return bool + */ + public function isLandscape(): bool + { + return $this->dimensions()->landscape(); + } - /** - * Checks if the dimensions of the asset are square - * - * @return bool - */ - public function isSquare(): bool - { - return $this->dimensions()->square(); - } + /** + * Checks if the dimensions of the asset are square + * + * @return bool + */ + public function isSquare(): bool + { + return $this->dimensions()->square(); + } - /** - * Checks if the file is a resizable image - * - * @return bool - */ - public function isResizable(): bool - { - return in_array($this->extension(), static::$resizableTypes) === true; - } + /** + * Checks if the file is a resizable image + * + * @return bool + */ + public function isResizable(): bool + { + return in_array($this->extension(), static::$resizableTypes) === true; + } - /** - * Checks if a preview can be displayed for the file - * in the Panel or in the frontend - * - * @return bool - */ - public function isViewable(): bool - { - return in_array($this->extension(), static::$viewableTypes) === true; - } + /** + * Checks if a preview can be displayed for the file + * in the Panel or in the frontend + * + * @return bool + */ + public function isViewable(): bool + { + return in_array($this->extension(), static::$viewableTypes) === true; + } - /** - * Returns the ratio of the asset - * - * @return float - */ - public function ratio(): float - { - return $this->dimensions()->ratio(); - } + /** + * Returns the ratio of the asset + * + * @return float + */ + public function ratio(): float + { + return $this->dimensions()->ratio(); + } - /** - * Returns the orientation as string - * landscape | portrait | square - * - * @return string - */ - public function orientation(): string - { - return $this->dimensions()->orientation(); - } + /** + * Returns the orientation as string + * landscape | portrait | square + * + * @return string + */ + public function orientation(): string + { + return $this->dimensions()->orientation(); + } - /** - * Converts the object to an array - * - * @return array - */ - public function toArray(): array - { - $array = array_merge(parent::toArray(), [ - 'dimensions' => $this->dimensions()->toArray(), - 'exif' => $this->exif()->toArray(), - ]); + /** + * Converts the object to an array + * + * @return array + */ + public function toArray(): array + { + $array = array_merge(parent::toArray(), [ + 'dimensions' => $this->dimensions()->toArray(), + 'exif' => $this->exif()->toArray(), + ]); - ksort($array); + ksort($array); - return $array; - } + return $array; + } - /** - * Returns the width of the asset - * - * @return int - */ - public function width(): int - { - return $this->dimensions()->width(); - } + /** + * Returns the width of the asset + * + * @return int + */ + public function width(): int + { + return $this->dimensions()->width(); + } } diff --git a/kirby/src/Image/Location.php b/kirby/src/Image/Location.php index b038ca2..00b65c4 100755 --- a/kirby/src/Image/Location.php +++ b/kirby/src/Image/Location.php @@ -14,123 +14,123 @@ namespace Kirby\Image; */ class Location { - /** - * latitude - * - * @var float|null - */ - protected $lat; + /** + * latitude + * + * @var float|null + */ + protected $lat; - /** - * longitude - * - * @var float|null - */ - protected $lng; + /** + * longitude + * + * @var float|null + */ + protected $lng; - /** - * Constructor - * - * @param array $exif The entire exif array - */ - public function __construct(array $exif) - { - if (isset($exif['GPSLatitude']) === true && - isset($exif['GPSLatitudeRef']) === true && - isset($exif['GPSLongitude']) === true && - isset($exif['GPSLongitudeRef']) === true - ) { - $this->lat = $this->gps($exif['GPSLatitude'], $exif['GPSLatitudeRef']); - $this->lng = $this->gps($exif['GPSLongitude'], $exif['GPSLongitudeRef']); - } - } + /** + * Constructor + * + * @param array $exif The entire exif array + */ + public function __construct(array $exif) + { + if (isset($exif['GPSLatitude']) === true && + isset($exif['GPSLatitudeRef']) === true && + isset($exif['GPSLongitude']) === true && + isset($exif['GPSLongitudeRef']) === true + ) { + $this->lat = $this->gps($exif['GPSLatitude'], $exif['GPSLatitudeRef']); + $this->lng = $this->gps($exif['GPSLongitude'], $exif['GPSLongitudeRef']); + } + } - /** - * Returns the latitude - * - * @return float|null - */ - public function lat() - { - return $this->lat; - } + /** + * Returns the latitude + * + * @return float|null + */ + public function lat() + { + return $this->lat; + } - /** - * Returns the longitude - * - * @return float|null - */ - public function lng() - { - return $this->lng; - } + /** + * Returns the longitude + * + * @return float|null + */ + public function lng() + { + return $this->lng; + } - /** - * Converts the gps coordinates - * - * @param string|array $coord - * @param string $hemi - * @return float - */ - protected function gps($coord, string $hemi): float - { - $degrees = count($coord) > 0 ? $this->num($coord[0]) : 0; - $minutes = count($coord) > 1 ? $this->num($coord[1]) : 0; - $seconds = count($coord) > 2 ? $this->num($coord[2]) : 0; + /** + * Converts the gps coordinates + * + * @param string|array $coord + * @param string $hemi + * @return float + */ + protected function gps($coord, string $hemi): float + { + $degrees = count($coord) > 0 ? $this->num($coord[0]) : 0; + $minutes = count($coord) > 1 ? $this->num($coord[1]) : 0; + $seconds = count($coord) > 2 ? $this->num($coord[2]) : 0; - $hemi = strtoupper($hemi); - $flip = ($hemi === 'W' || $hemi === 'S') ? -1 : 1; + $hemi = strtoupper($hemi); + $flip = ($hemi === 'W' || $hemi === 'S') ? -1 : 1; - return $flip * ($degrees + $minutes / 60 + $seconds / 3600); - } + return $flip * ($degrees + $minutes / 60 + $seconds / 3600); + } - /** - * Converts coordinates to floats - * - * @param string $part - * @return float - */ - protected function num(string $part): float - { - $parts = explode('/', $part); + /** + * Converts coordinates to floats + * + * @param string $part + * @return float + */ + protected function num(string $part): float + { + $parts = explode('/', $part); - if (count($parts) === 1) { - return (float)$parts[0]; - } + if (count($parts) === 1) { + return (float)$parts[0]; + } - return (float)($parts[0]) / (float)($parts[1]); - } + return (float)($parts[0]) / (float)($parts[1]); + } - /** - * Converts the object into a nicely readable array - * - * @return array - */ - public function toArray(): array - { - return [ - 'lat' => $this->lat(), - 'lng' => $this->lng() - ]; - } + /** + * Converts the object into a nicely readable array + * + * @return array + */ + public function toArray(): array + { + return [ + 'lat' => $this->lat(), + 'lng' => $this->lng() + ]; + } - /** - * Echos the entire location as lat, lng - * - * @return string - */ - public function __toString(): string - { - return trim(trim($this->lat() . ', ' . $this->lng(), ',')); - } + /** + * Echos the entire location as lat, lng + * + * @return string + */ + public function __toString(): string + { + return trim(trim($this->lat() . ', ' . $this->lng(), ',')); + } - /** - * Improved `var_dump` output - * - * @return array - */ - public function __debugInfo(): array - { - return $this->toArray(); - } + /** + * Improved `var_dump` output + * + * @return array + */ + public function __debugInfo(): array + { + return $this->toArray(); + } } diff --git a/kirby/src/Panel/Dialog.php b/kirby/src/Panel/Dialog.php index cdee07f..a7825e9 100755 --- a/kirby/src/Panel/Dialog.php +++ b/kirby/src/Panel/Dialog.php @@ -16,24 +16,24 @@ namespace Kirby\Panel; */ class Dialog extends Json { - protected static $key = '$dialog'; + protected static $key = '$dialog'; - /** - * Renders dialogs - * - * @param mixed $data - * @param array $options - * @return \Kirby\Http\Response - */ - public static function response($data, array $options = []) - { - // interpret true as success - if ($data === true) { - $data = [ - 'code' => 200 - ]; - } + /** + * Renders dialogs + * + * @param mixed $data + * @param array $options + * @return \Kirby\Http\Response + */ + public static function response($data, array $options = []) + { + // interpret true as success + if ($data === true) { + $data = [ + 'code' => 200 + ]; + } - return parent::response($data, $options); - } + return parent::response($data, $options); + } } diff --git a/kirby/src/Panel/Document.php b/kirby/src/Panel/Document.php index 00fcf58..f506a11 100755 --- a/kirby/src/Panel/Document.php +++ b/kirby/src/Panel/Document.php @@ -28,276 +28,276 @@ use Throwable; */ class Document { - /** - * Generates an array with all assets - * that need to be loaded for the panel (js, css, icons) - * - * @return array - */ - public static function assets(): array - { - $kirby = App::instance(); - $nonce = $kirby->nonce(); + /** + * Generates an array with all assets + * that need to be loaded for the panel (js, css, icons) + * + * @return array + */ + public static function assets(): array + { + $kirby = App::instance(); + $nonce = $kirby->nonce(); - // get the assets from the Vite dev server in dev mode; - // dev mode = explicitly enabled in the config AND Vite is running - $dev = $kirby->option('panel.dev', false); - $isDev = $dev !== false && is_file($kirby->roots()->panel() . '/.vite-running') === true; + // get the assets from the Vite dev server in dev mode; + // dev mode = explicitly enabled in the config AND Vite is running + $dev = $kirby->option('panel.dev', false); + $isDev = $dev !== false && is_file($kirby->roots()->panel() . '/.vite-running') === true; - if ($isDev === true) { - // vite on explicitly configured base URL or port 3000 - // of the current Kirby request - if (is_string($dev) === true) { - $url = $dev; - } else { - $url = rtrim($kirby->request()->url([ - 'port' => 3000, - 'path' => null, - 'params' => null, - 'query' => null - ])->toString(), '/'); - } - } else { - // vite is not running, use production assets - $url = $kirby->url('media') . '/panel/' . $kirby->versionHash(); - } + if ($isDev === true) { + // vite on explicitly configured base URL or port 3000 + // of the current Kirby request + if (is_string($dev) === true) { + $url = $dev; + } else { + $url = rtrim($kirby->request()->url([ + 'port' => 3000, + 'path' => null, + 'params' => null, + 'query' => null + ])->toString(), '/'); + } + } else { + // vite is not running, use production assets + $url = $kirby->url('media') . '/panel/' . $kirby->versionHash(); + } - // fetch all plugins - $plugins = new Plugins(); + // fetch all plugins + $plugins = new Plugins(); - $assets = [ - 'css' => [ - 'index' => $url . '/css/style.css', - 'plugins' => $plugins->url('css'), - 'custom' => static::customAsset('panel.css'), - ], - 'icons' => static::favicon($url), - 'js' => [ - 'vendor' => [ - 'nonce' => $nonce, - 'src' => $url . '/js/vendor.js', - 'type' => 'module' - ], - 'pluginloader' => [ - 'nonce' => $nonce, - 'src' => $url . '/js/plugins.js', - 'type' => 'module' - ], - 'plugins' => [ - 'nonce' => $nonce, - 'src' => $plugins->url('js'), - 'defer' => true - ], - 'custom' => [ - 'nonce' => $nonce, - 'src' => static::customAsset('panel.js'), - 'type' => 'module' - ], - 'index' => [ - 'nonce' => $nonce, - 'src' => $url . '/js/index.js', - 'type' => 'module' - ], - ] - ]; + $assets = [ + 'css' => [ + 'index' => $url . '/css/style.css', + 'plugins' => $plugins->url('css'), + 'custom' => static::customAsset('panel.css'), + ], + 'icons' => static::favicon($url), + 'js' => [ + 'vendor' => [ + 'nonce' => $nonce, + 'src' => $url . '/js/vendor.js', + 'type' => 'module' + ], + 'pluginloader' => [ + 'nonce' => $nonce, + 'src' => $url . '/js/plugins.js', + 'type' => 'module' + ], + 'plugins' => [ + 'nonce' => $nonce, + 'src' => $plugins->url('js'), + 'defer' => true + ], + 'custom' => [ + 'nonce' => $nonce, + 'src' => static::customAsset('panel.js'), + 'type' => 'module' + ], + 'index' => [ + 'nonce' => $nonce, + 'src' => $url . '/js/index.js', + 'type' => 'module' + ], + ] + ]; - // during dev mode, add vite client and adapt - // path to `index.js` - vendor and stylesheet - // don't need to be loaded in dev mode - if ($isDev === true) { - $assets['js']['vite'] = [ - 'nonce' => $nonce, - 'src' => $url . '/@vite/client', - 'type' => 'module' - ]; - $assets['js']['index'] = [ - 'nonce' => $nonce, - 'src' => $url . '/src/index.js', - 'type' => 'module' - ]; + // during dev mode, add vite client and adapt + // path to `index.js` - vendor and stylesheet + // don't need to be loaded in dev mode + if ($isDev === true) { + $assets['js']['vite'] = [ + 'nonce' => $nonce, + 'src' => $url . '/@vite/client', + 'type' => 'module' + ]; + $assets['js']['index'] = [ + 'nonce' => $nonce, + 'src' => $url . '/src/index.js', + 'type' => 'module' + ]; - unset($assets['css']['index'], $assets['js']['vendor']); - } + unset($assets['css']['index'], $assets['js']['vendor']); + } - // remove missing files - $assets['css'] = array_filter($assets['css']); - $assets['js'] = array_filter( - $assets['js'], - fn ($js) => empty($js['src']) === false - ); + // remove missing files + $assets['css'] = array_filter($assets['css']); + $assets['js'] = array_filter( + $assets['js'], + fn ($js) => empty($js['src']) === false + ); - return $assets; - } + return $assets; + } - /** - * Check for a custom asset file from the - * config (e.g. panel.css or panel.js) - * @since 3.7.0 - * - * @param string $option asset option name - * @return string|null - */ - public static function customAsset(string $option): ?string - { - if ($path = App::instance()->option($option)) { - $asset = new Asset($path); + /** + * Check for a custom asset file from the + * config (e.g. panel.css or panel.js) + * @since 3.7.0 + * + * @param string $option asset option name + * @return string|null + */ + public static function customAsset(string $option): ?string + { + if ($path = App::instance()->option($option)) { + $asset = new Asset($path); - if ($asset->exists() === true) { - return $asset->url() . '?' . $asset->modified(); - } - } + if ($asset->exists() === true) { + return $asset->url() . '?' . $asset->modified(); + } + } - return null; - } + return null; + } - /** - * @deprecated 3.7.0 Use `Document::customAsset('panel.css)` instead - * @todo remove in 3.8.0 - * @codeCoverageIgnore - */ - public static function customCss(): ?string - { - Helpers::deprecated('Panel\Document::customCss() has been deprecated and will be removed in Kirby 3.8.0. Use Panel\Document::customAsset(\'panel.css\') instead.'); - return static::customAsset('panel.css'); - } + /** + * @deprecated 3.7.0 Use `Document::customAsset('panel.css)` instead + * @todo remove in 3.8.0 + * @codeCoverageIgnore + */ + public static function customCss(): ?string + { + Helpers::deprecated('Panel\Document::customCss() has been deprecated and will be removed in Kirby 3.8.0. Use Panel\Document::customAsset(\'panel.css\') instead.'); + return static::customAsset('panel.css'); + } - /** - * @deprecated 3.7.0 Use `Document::customAsset('panel.js)` instead - * @todo remove in 3.8.0 - * @codeCoverageIgnore - */ - public static function customJs(): ?string - { - Helpers::deprecated('Panel\Document::customJs() has been deprecated and will be removed in Kirby 3.8.0. Use Panel\Document::customAsset(\'panel.js\') instead.'); - return static::customAsset('panel.js'); - } + /** + * @deprecated 3.7.0 Use `Document::customAsset('panel.js)` instead + * @todo remove in 3.8.0 + * @codeCoverageIgnore + */ + public static function customJs(): ?string + { + Helpers::deprecated('Panel\Document::customJs() has been deprecated and will be removed in Kirby 3.8.0. Use Panel\Document::customAsset(\'panel.js\') instead.'); + return static::customAsset('panel.js'); + } - /** - * Returns array of favion icons - * based on config option - * @since 3.7.0 - * - * @param string $url URL prefix for default icons - * @return array - */ - public static function favicon(string $url = ''): array - { - $kirby = App::instance(); - $icons = $kirby->option('panel.favicon', [ - 'apple-touch-icon' => [ - 'type' => 'image/png', - 'url' => $url . '/apple-touch-icon.png', - ], - 'shortcut icon' => [ - 'type' => 'image/svg+xml', - 'url' => $url . '/favicon.svg', - ], - 'alternate icon' => [ - 'type' => 'image/png', - 'url' => $url . '/favicon.png', - ] - ]); + /** + * Returns array of favion icons + * based on config option + * @since 3.7.0 + * + * @param string $url URL prefix for default icons + * @return array + */ + public static function favicon(string $url = ''): array + { + $kirby = App::instance(); + $icons = $kirby->option('panel.favicon', [ + 'apple-touch-icon' => [ + 'type' => 'image/png', + 'url' => $url . '/apple-touch-icon.png', + ], + 'shortcut icon' => [ + 'type' => 'image/svg+xml', + 'url' => $url . '/favicon.svg', + ], + 'alternate icon' => [ + 'type' => 'image/png', + 'url' => $url . '/favicon.png', + ] + ]); - if (is_array($icons) === true) { - return $icons; - } + if (is_array($icons) === true) { + return $icons; + } - // make sure to convert favicon string to array - if (is_string($icons) === true) { - return [ - 'shortcut icon' => [ - 'type' => F::mime($icons), - 'url' => $icons, - ] - ]; - } + // make sure to convert favicon string to array + if (is_string($icons) === true) { + return [ + 'shortcut icon' => [ + 'type' => F::mime($icons), + 'url' => $icons, + ] + ]; + } - throw new InvalidArgumentException('Invalid panel.favicon option'); - } + throw new InvalidArgumentException('Invalid panel.favicon option'); + } - /** - * Load the SVG icon sprite - * This will be injected in the - * initial HTML document for the Panel - * - * @return string - */ - public static function icons(): string - { - return F::read(App::instance()->root('kirby') . '/panel/dist/img/icons.svg'); - } + /** + * Load the SVG icon sprite + * This will be injected in the + * initial HTML document for the Panel + * + * @return string + */ + public static function icons(): string + { + return F::read(App::instance()->root('kirby') . '/panel/dist/img/icons.svg'); + } - /** - * Links all dist files in the media folder - * and returns the link to the requested asset - * - * @return bool - * @throws \Kirby\Exception\Exception If Panel assets could not be moved to the public directory - */ - public static function link(): bool - { - $kirby = App::instance(); - $mediaRoot = $kirby->root('media') . '/panel'; - $panelRoot = $kirby->root('panel') . '/dist'; - $versionHash = $kirby->versionHash(); - $versionRoot = $mediaRoot . '/' . $versionHash; + /** + * Links all dist files in the media folder + * and returns the link to the requested asset + * + * @return bool + * @throws \Kirby\Exception\Exception If Panel assets could not be moved to the public directory + */ + public static function link(): bool + { + $kirby = App::instance(); + $mediaRoot = $kirby->root('media') . '/panel'; + $panelRoot = $kirby->root('panel') . '/dist'; + $versionHash = $kirby->versionHash(); + $versionRoot = $mediaRoot . '/' . $versionHash; - // check if the version already exists - if (is_dir($versionRoot) === true) { - return false; - } + // check if the version already exists + if (is_dir($versionRoot) === true) { + return false; + } - // delete the panel folder and all previous versions - Dir::remove($mediaRoot); + // delete the panel folder and all previous versions + Dir::remove($mediaRoot); - // recreate the panel folder - Dir::make($mediaRoot, true); + // recreate the panel folder + Dir::make($mediaRoot, true); - // copy assets to the dist folder - if (Dir::copy($panelRoot, $versionRoot) !== true) { - throw new Exception('Panel assets could not be linked'); - } + // copy assets to the dist folder + if (Dir::copy($panelRoot, $versionRoot) !== true) { + throw new Exception('Panel assets could not be linked'); + } - return true; - } + return true; + } - /** - * Renders the panel document - * - * @param array $fiber - * @return \Kirby\Http\Response - */ - public static function response(array $fiber) - { - $kirby = App::instance(); + /** + * Renders the panel document + * + * @param array $fiber + * @return \Kirby\Http\Response + */ + public static function response(array $fiber) + { + $kirby = App::instance(); - // Full HTML response - // @codeCoverageIgnoreStart - try { - if (static::link() === true) { - usleep(1); - Response::go($kirby->url('index') . '/' . $kirby->path()); - } - } catch (Throwable $e) { - die('The Panel assets cannot be installed properly. ' . $e->getMessage()); - } - // @codeCoverageIgnoreEnd + // Full HTML response + // @codeCoverageIgnoreStart + try { + if (static::link() === true) { + usleep(1); + Response::go($kirby->url('index') . '/' . $kirby->path()); + } + } catch (Throwable $e) { + die('The Panel assets cannot be installed properly. ' . $e->getMessage()); + } + // @codeCoverageIgnoreEnd - // get the uri object for the panel url - $uri = new Uri($url = $kirby->url('panel')); + // get the uri object for the panel url + $uri = new Uri($url = $kirby->url('panel')); - // proper response code - $code = $fiber['$view']['code'] ?? 200; + // proper response code + $code = $fiber['$view']['code'] ?? 200; - // load the main Panel view template - $body = Tpl::load($kirby->root('kirby') . '/views/panel.php', [ - 'assets' => static::assets(), - 'icons' => static::icons(), - 'nonce' => $kirby->nonce(), - 'fiber' => $fiber, - 'panelUrl' => $uri->path()->toString(true) . '/', - ]); + // load the main Panel view template + $body = Tpl::load($kirby->root('kirby') . '/views/panel.php', [ + 'assets' => static::assets(), + 'icons' => static::icons(), + 'nonce' => $kirby->nonce(), + 'fiber' => $fiber, + 'panelUrl' => $uri->path()->toString(true) . '/', + ]); - return new Response($body, 'text/html', $code); - } + return new Response($body, 'text/html', $code); + } } diff --git a/kirby/src/Panel/Dropdown.php b/kirby/src/Panel/Dropdown.php index abb5685..42bdd91 100755 --- a/kirby/src/Panel/Dropdown.php +++ b/kirby/src/Panel/Dropdown.php @@ -23,68 +23,68 @@ use Throwable; */ class Dropdown extends Json { - protected static $key = '$dropdown'; + protected static $key = '$dropdown'; - /** - * Returns the options for the changes dropdown - * - * @return array - */ - public static function changes(): array - { - $kirby = App::instance(); - $multilang = $kirby->multilang(); - $ids = Str::split($kirby->request()->get('ids')); - $options = []; + /** + * Returns the options for the changes dropdown + * + * @return array + */ + public static function changes(): array + { + $kirby = App::instance(); + $multilang = $kirby->multilang(); + $ids = Str::split($kirby->request()->get('ids')); + $options = []; - foreach ($ids as $id) { - try { - // parse the given ID to extract - // the path and an optional query - $uri = new Uri($id); - $path = $uri->path()->toString(); - $query = $uri->query(); - $option = Find::parent($path)->panel()->dropdownOption(); + foreach ($ids as $id) { + try { + // parse the given ID to extract + // the path and an optional query + $uri = new Uri($id); + $path = $uri->path()->toString(); + $query = $uri->query(); + $option = Find::parent($path)->panel()->dropdownOption(); - // add the language to each option, if it is included in the query - // of the given ID and the language actually exists - if ($multilang && $query->language && $language = $kirby->language($query->language)) { - $option['text'] .= ' (' . $language->code() . ')'; - $option['link'] .= '?language=' . $language->code(); - } + // add the language to each option, if it is included in the query + // of the given ID and the language actually exists + if ($multilang && $query->language && $language = $kirby->language($query->language)) { + $option['text'] .= ' (' . $language->code() . ')'; + $option['link'] .= '?language=' . $language->code(); + } - $options[] = $option; - } catch (Throwable $e) { - continue; - } - } + $options[] = $option; + } catch (Throwable $e) { + continue; + } + } - // the given set of ids does not match any - // real models. This means that the stored ids - // in local storage are not correct and the changes - // store needs to be cleared - if (empty($options) === true) { - throw new LogicException('No changes for given models'); - } + // the given set of ids does not match any + // real models. This means that the stored ids + // in local storage are not correct and the changes + // store needs to be cleared + if (empty($options) === true) { + throw new LogicException('No changes for given models'); + } - return $options; - } + return $options; + } - /** - * Renders dropdowns - * - * @param mixed $data - * @param array $options - * @return \Kirby\Http\Response - */ - public static function response($data, array $options = []) - { - if (is_array($data) === true) { - $data = [ - 'options' => array_values($data) - ]; - } + /** + * Renders dropdowns + * + * @param mixed $data + * @param array $options + * @return \Kirby\Http\Response + */ + public static function response($data, array $options = []) + { + if (is_array($data) === true) { + $data = [ + 'options' => array_values($data) + ]; + } - return parent::response($data, $options); - } + return parent::response($data, $options); + } } diff --git a/kirby/src/Panel/Field.php b/kirby/src/Panel/Field.php index 3b1ab9c..3d02d21 100755 --- a/kirby/src/Panel/Field.php +++ b/kirby/src/Panel/Field.php @@ -20,255 +20,255 @@ use Kirby\Toolkit\I18n; */ class Field { - /** - * A standard email field - * - * @param array $props - * @return array - */ - public static function email(array $props = []): array - { - return array_merge([ - 'label' => I18n::translate('email'), - 'type' => 'email', - 'counter' => false, - ], $props); - } + /** + * A standard email field + * + * @param array $props + * @return array + */ + public static function email(array $props = []): array + { + return array_merge([ + 'label' => I18n::translate('email'), + 'type' => 'email', + 'counter' => false, + ], $props); + } - /** - * File position - * - * @param \Kirby\Cms\File - * @param array $props - * @return array - */ - public static function filePosition(File $file, array $props = []): array - { - $index = 0; - $options = []; + /** + * File position + * + * @param \Kirby\Cms\File + * @param array $props + * @return array + */ + public static function filePosition(File $file, array $props = []): array + { + $index = 0; + $options = []; - foreach ($file->siblings(false)->sorted() as $sibling) { - $index++; + foreach ($file->siblings(false)->sorted() as $sibling) { + $index++; - $options[] = [ - 'value' => $index, - 'text' => $index - ]; + $options[] = [ + 'value' => $index, + 'text' => $index + ]; - $options[] = [ - 'value' => $sibling->id(), - 'text' => $sibling->filename(), - 'disabled' => true - ]; - } + $options[] = [ + 'value' => $sibling->id(), + 'text' => $sibling->filename(), + 'disabled' => true + ]; + } - $index++; + $index++; - $options[] = [ - 'value' => $index, - 'text' => $index - ]; + $options[] = [ + 'value' => $index, + 'text' => $index + ]; - return array_merge([ - 'label' => I18n::translate('file.sort'), - 'type' => 'select', - 'empty' => false, - 'options' => $options - ], $props); - } + return array_merge([ + 'label' => I18n::translate('file.sort'), + 'type' => 'select', + 'empty' => false, + 'options' => $options + ], $props); + } - /** - * @return array - */ - public static function hidden(): array - { - return ['type' => 'hidden']; - } + /** + * @return array + */ + public static function hidden(): array + { + return ['type' => 'hidden']; + } - /** - * Page position - * - * @param \Kirby\Cms\Page - * @param array $props - * @return array - */ - public static function pagePosition(Page $page, array $props = []): array - { - $index = 0; - $options = []; - $siblings = $page->parentModel()->children()->listed()->not($page); + /** + * Page position + * + * @param \Kirby\Cms\Page + * @param array $props + * @return array + */ + public static function pagePosition(Page $page, array $props = []): array + { + $index = 0; + $options = []; + $siblings = $page->parentModel()->children()->listed()->not($page); - foreach ($siblings as $sibling) { - $index++; + foreach ($siblings as $sibling) { + $index++; - $options[] = [ - 'value' => $index, - 'text' => $index - ]; + $options[] = [ + 'value' => $index, + 'text' => $index + ]; - $options[] = [ - 'value' => $sibling->id(), - 'text' => $sibling->title()->value(), - 'disabled' => true - ]; - } + $options[] = [ + 'value' => $sibling->id(), + 'text' => $sibling->title()->value(), + 'disabled' => true + ]; + } - $index++; + $index++; - $options[] = [ - 'value' => $index, - 'text' => $index - ]; + $options[] = [ + 'value' => $index, + 'text' => $index + ]; - // if only one available option, - // hide field when not in debug mode - if (count($options) < 2) { - return static::hidden(); - } + // if only one available option, + // hide field when not in debug mode + if (count($options) < 2) { + return static::hidden(); + } - return array_merge([ - 'label' => I18n::translate('page.changeStatus.position'), - 'type' => 'select', - 'empty' => false, - 'options' => $options, - ], $props); - } + return array_merge([ + 'label' => I18n::translate('page.changeStatus.position'), + 'type' => 'select', + 'empty' => false, + 'options' => $options, + ], $props); + } - /** - * A regular password field - * - * @param array $props - * @return array - */ - public static function password(array $props = []): array - { - return array_merge([ - 'label' => I18n::translate('password'), - 'type' => 'password' - ], $props); - } + /** + * A regular password field + * + * @param array $props + * @return array + */ + public static function password(array $props = []): array + { + return array_merge([ + 'label' => I18n::translate('password'), + 'type' => 'password' + ], $props); + } - /** - * User role radio buttons - * - * @param array $props - * @return array - */ - public static function role(array $props = []): array - { - $kirby = App::instance(); - $user = $kirby->user(); - $isAdmin = $user && $user->isAdmin(); - $roles = []; + /** + * User role radio buttons + * + * @param array $props + * @return array + */ + public static function role(array $props = []): array + { + $kirby = App::instance(); + $user = $kirby->user(); + $isAdmin = $user && $user->isAdmin(); + $roles = []; - foreach ($kirby->roles() as $role) { - // exclude the admin role, if the user - // is not allowed to change role to admin - if ($role->name() === 'admin' && $isAdmin === false) { - continue; - } + foreach ($kirby->roles() as $role) { + // exclude the admin role, if the user + // is not allowed to change role to admin + if ($role->name() === 'admin' && $isAdmin === false) { + continue; + } - $roles[] = [ - 'text' => $role->title(), - 'info' => $role->description() ?? I18n::translate('role.description.placeholder'), - 'value' => $role->name() - ]; - } + $roles[] = [ + 'text' => $role->title(), + 'info' => $role->description() ?? I18n::translate('role.description.placeholder'), + 'value' => $role->name() + ]; + } - return array_merge([ - 'label' => I18n::translate('role'), - 'type' => count($roles) <= 1 ? 'hidden' : 'radio', - 'options' => $roles - ], $props); - } + return array_merge([ + 'label' => I18n::translate('role'), + 'type' => count($roles) <= 1 ? 'hidden' : 'radio', + 'options' => $roles + ], $props); + } - /** - * @param array $props - * @return array - */ - public static function slug(array $props = []): array - { - return array_merge([ - 'label' => I18n::translate('slug'), - 'type' => 'slug', - ], $props); - } + /** + * @param array $props + * @return array + */ + public static function slug(array $props = []): array + { + return array_merge([ + 'label' => I18n::translate('slug'), + 'type' => 'slug', + ], $props); + } - /** - * @param array $blueprints - * @param array $props - * @return array - */ - public static function template(?array $blueprints = [], ?array $props = []): array - { - $options = []; + /** + * @param array $blueprints + * @param array $props + * @return array + */ + public static function template(?array $blueprints = [], ?array $props = []): array + { + $options = []; - foreach ($blueprints as $blueprint) { - $options[] = [ - 'text' => $blueprint['title'] ?? $blueprint['text'] ?? null, - 'value' => $blueprint['name'] ?? $blueprint['value'] ?? null, - ]; - } + foreach ($blueprints as $blueprint) { + $options[] = [ + 'text' => $blueprint['title'] ?? $blueprint['text'] ?? null, + 'value' => $blueprint['name'] ?? $blueprint['value'] ?? null, + ]; + } - return array_merge([ - 'label' => I18n::translate('template'), - 'type' => 'select', - 'empty' => false, - 'options' => $options, - 'icon' => 'template', - 'disabled' => count($options) <= 1 - ], $props); - } + return array_merge([ + 'label' => I18n::translate('template'), + 'type' => 'select', + 'empty' => false, + 'options' => $options, + 'icon' => 'template', + 'disabled' => count($options) <= 1 + ], $props); + } - /** - * @param array $props - * @return array - */ - public static function title(array $props = []): array - { - return array_merge([ - 'label' => I18n::translate('title'), - 'type' => 'text', - 'icon' => 'title', - ], $props); - } + /** + * @param array $props + * @return array + */ + public static function title(array $props = []): array + { + return array_merge([ + 'label' => I18n::translate('title'), + 'type' => 'text', + 'icon' => 'title', + ], $props); + } - /** - * Panel translation select box - * - * @param array $props - * @return array - */ - public static function translation(array $props = []): array - { - $translations = []; - foreach (App::instance()->translations() as $translation) { - $translations[] = [ - 'text' => $translation->name(), - 'value' => $translation->code() - ]; - } + /** + * Panel translation select box + * + * @param array $props + * @return array + */ + public static function translation(array $props = []): array + { + $translations = []; + foreach (App::instance()->translations() as $translation) { + $translations[] = [ + 'text' => $translation->name(), + 'value' => $translation->code() + ]; + } - return array_merge([ - 'label' => I18n::translate('language'), - 'type' => 'select', - 'icon' => 'globe', - 'options' => $translations, - 'empty' => false - ], $props); - } + return array_merge([ + 'label' => I18n::translate('language'), + 'type' => 'select', + 'icon' => 'globe', + 'options' => $translations, + 'empty' => false + ], $props); + } - /** - * @param array $props - * @return array - */ - public static function username(array $props = []): array - { - return array_merge([ - 'icon' => 'user', - 'label' => I18n::translate('name'), - 'type' => 'text', - ], $props); - } + /** + * @param array $props + * @return array + */ + public static function username(array $props = []): array + { + return array_merge([ + 'icon' => 'user', + 'label' => I18n::translate('name'), + 'type' => 'text', + ], $props); + } } diff --git a/kirby/src/Panel/File.php b/kirby/src/Panel/File.php index eee102d..c78fa7e 100755 --- a/kirby/src/Panel/File.php +++ b/kirby/src/Panel/File.php @@ -17,454 +17,454 @@ use Throwable; */ class File extends Model { - /** - * @var \Kirby\Cms\File - */ - protected $model; + /** + * @var \Kirby\Cms\File + */ + protected $model; - /** - * Breadcrumb array - * - * @return array - */ - public function breadcrumb(): array - { - $breadcrumb = []; - $parent = $this->model->parent(); + /** + * Breadcrumb array + * + * @return array + */ + public function breadcrumb(): array + { + $breadcrumb = []; + $parent = $this->model->parent(); - switch ($parent::CLASS_ALIAS) { - case 'user': - // The breadcrumb is not necessary - // on the account view - if ($parent->isLoggedIn() === false) { - $breadcrumb[] = [ - 'label' => $parent->username(), - 'link' => $parent->panel()->url(true) - ]; - } - break; - case 'page': - $breadcrumb = $this->model->parents()->flip()->values(fn ($parent) => [ - 'label' => $parent->title()->toString(), - 'link' => $parent->panel()->url(true), - ]); - } + switch ($parent::CLASS_ALIAS) { + case 'user': + // The breadcrumb is not necessary + // on the account view + if ($parent->isLoggedIn() === false) { + $breadcrumb[] = [ + 'label' => $parent->username(), + 'link' => $parent->panel()->url(true) + ]; + } + break; + case 'page': + $breadcrumb = $this->model->parents()->flip()->values(fn ($parent) => [ + 'label' => $parent->title()->toString(), + 'link' => $parent->panel()->url(true), + ]); + } - // add the file - $breadcrumb[] = [ - 'label' => $this->model->filename(), - 'link' => $this->url(true), - ]; + // add the file + $breadcrumb[] = [ + 'label' => $this->model->filename(), + 'link' => $this->url(true), + ]; - return $breadcrumb; - } + return $breadcrumb; + } - /** - * Provides a kirbytag or markdown - * tag for the file, which will be - * used in the panel, when the file - * gets dragged onto a textarea - * - * @internal - * @param string|null $type (`auto`|`kirbytext`|`markdown`) - * @param bool $absolute - * @return string - */ - public function dragText(string $type = null, bool $absolute = false): string - { - $type = $this->dragTextType($type); - $url = $absolute ? $this->model->id() : $this->model->filename(); + /** + * Provides a kirbytag or markdown + * tag for the file, which will be + * used in the panel, when the file + * gets dragged onto a textarea + * + * @internal + * @param string|null $type (`auto`|`kirbytext`|`markdown`) + * @param bool $absolute + * @return string + */ + public function dragText(string $type = null, bool $absolute = false): string + { + $type = $this->dragTextType($type); + $url = $absolute ? $this->model->id() : $this->model->filename(); - if ($dragTextFromCallback = $this->dragTextFromCallback($type, $url)) { - return $dragTextFromCallback; - } + if ($dragTextFromCallback = $this->dragTextFromCallback($type, $url)) { + return $dragTextFromCallback; + } - if ($type === 'markdown') { - if ($this->model->type() === 'image') { - return '![' . $this->model->alt() . '](' . $url . ')'; - } + if ($type === 'markdown') { + if ($this->model->type() === 'image') { + return '![' . $this->model->alt() . '](' . $url . ')'; + } - return '[' . $this->model->filename() . '](' . $url . ')'; - } + return '[' . $this->model->filename() . '](' . $url . ')'; + } - if ($this->model->type() === 'image') { - return '(image: ' . $url . ')'; - } - if ($this->model->type() === 'video') { - return '(video: ' . $url . ')'; - } + if ($this->model->type() === 'image') { + return '(image: ' . $url . ')'; + } + if ($this->model->type() === 'video') { + return '(video: ' . $url . ')'; + } - return '(file: ' . $url . ')'; - } + return '(file: ' . $url . ')'; + } - /** - * Provides options for the file dropdown - * - * @param array $options - * @return array - */ - public function dropdown(array $options = []): array - { - $file = $this->model; + /** + * Provides options for the file dropdown + * + * @param array $options + * @return array + */ + public function dropdown(array $options = []): array + { + $file = $this->model; - $defaults = $file->kirby()->request()->get(['view', 'update', 'delete']); - $options = array_merge($defaults, $options); + $defaults = $file->kirby()->request()->get(['view', 'update', 'delete']); + $options = array_merge($defaults, $options); - $permissions = $this->options(['preview']); - $view = $options['view'] ?? 'view'; - $url = $this->url(true); - $result = []; + $permissions = $this->options(['preview']); + $view = $options['view'] ?? 'view'; + $url = $this->url(true); + $result = []; - if ($view === 'list') { - $result[] = [ - 'link' => $file->previewUrl(), - 'target' => '_blank', - 'icon' => 'open', - 'text' => I18n::translate('open') - ]; - $result[] = '-'; - } + if ($view === 'list') { + $result[] = [ + 'link' => $file->previewUrl(), + 'target' => '_blank', + 'icon' => 'open', + 'text' => I18n::translate('open') + ]; + $result[] = '-'; + } - $result[] = [ - 'dialog' => $url . '/changeName', - 'icon' => 'title', - 'text' => I18n::translate('rename'), - 'disabled' => $this->isDisabledDropdownOption('changeName', $options, $permissions) - ]; + $result[] = [ + 'dialog' => $url . '/changeName', + 'icon' => 'title', + 'text' => I18n::translate('rename'), + 'disabled' => $this->isDisabledDropdownOption('changeName', $options, $permissions) + ]; - $result[] = [ - 'click' => 'replace', - 'icon' => 'upload', - 'text' => I18n::translate('replace'), - 'disabled' => $this->isDisabledDropdownOption('replace', $options, $permissions) - ]; + $result[] = [ + 'click' => 'replace', + 'icon' => 'upload', + 'text' => I18n::translate('replace'), + 'disabled' => $this->isDisabledDropdownOption('replace', $options, $permissions) + ]; - if ($view === 'list') { - $result[] = '-'; - $result[] = [ - 'dialog' => $url . '/changeSort', - 'icon' => 'sort', - 'text' => I18n::translate('file.sort'), - 'disabled' => $this->isDisabledDropdownOption('update', $options, $permissions) - ]; - } + if ($view === 'list') { + $result[] = '-'; + $result[] = [ + 'dialog' => $url . '/changeSort', + 'icon' => 'sort', + 'text' => I18n::translate('file.sort'), + 'disabled' => $this->isDisabledDropdownOption('update', $options, $permissions) + ]; + } - $result[] = '-'; - $result[] = [ - 'dialog' => $url . '/delete', - 'icon' => 'trash', - 'text' => I18n::translate('delete'), - 'disabled' => $this->isDisabledDropdownOption('delete', $options, $permissions) - ]; + $result[] = '-'; + $result[] = [ + 'dialog' => $url . '/delete', + 'icon' => 'trash', + 'text' => I18n::translate('delete'), + 'disabled' => $this->isDisabledDropdownOption('delete', $options, $permissions) + ]; - return $result; - } + return $result; + } - /** - * Returns the setup for a dropdown option - * which is used in the changes dropdown - * for example. - * - * @return array - */ - public function dropdownOption(): array - { - return [ - 'icon' => 'image', - 'text' => $this->model->filename(), - ] + parent::dropdownOption(); - } + /** + * Returns the setup for a dropdown option + * which is used in the changes dropdown + * for example. + * + * @return array + */ + public function dropdownOption(): array + { + return [ + 'icon' => 'image', + 'text' => $this->model->filename(), + ] + parent::dropdownOption(); + } - /** - * Returns the Panel icon color - * - * @return string - */ - protected function imageColor(): string - { - $types = [ - 'image' => 'orange-400', - 'video' => 'yellow-400', - 'document' => 'red-400', - 'audio' => 'aqua-400', - 'code' => 'blue-400', - 'archive' => 'gray-500' - ]; + /** + * Returns the Panel icon color + * + * @return string + */ + protected function imageColor(): string + { + $types = [ + 'image' => 'orange-400', + 'video' => 'yellow-400', + 'document' => 'red-400', + 'audio' => 'aqua-400', + 'code' => 'blue-400', + 'archive' => 'gray-500' + ]; - $extensions = [ - 'indd' => 'purple-400', - 'xls' => 'green-400', - 'xlsx' => 'green-400', - 'csv' => 'green-400', - 'docx' => 'blue-400', - 'doc' => 'blue-400', - 'rtf' => 'blue-400' - ]; + $extensions = [ + 'indd' => 'purple-400', + 'xls' => 'green-400', + 'xlsx' => 'green-400', + 'csv' => 'green-400', + 'docx' => 'blue-400', + 'doc' => 'blue-400', + 'rtf' => 'blue-400' + ]; - return $extensions[$this->model->extension()] ?? - $types[$this->model->type()] ?? - parent::imageDefaults()['color']; - } + return $extensions[$this->model->extension()] ?? + $types[$this->model->type()] ?? + parent::imageDefaults()['color']; + } - /** - * Default settings for the file's Panel image - * - * @return array - */ - protected function imageDefaults(): array - { - return array_merge(parent::imageDefaults(), [ - 'color' => $this->imageColor(), - 'icon' => $this->imageIcon(), - ]); - } + /** + * Default settings for the file's Panel image + * + * @return array + */ + protected function imageDefaults(): array + { + return array_merge(parent::imageDefaults(), [ + 'color' => $this->imageColor(), + 'icon' => $this->imageIcon(), + ]); + } - /** - * Returns the Panel icon type - * - * @return string - */ - protected function imageIcon(): string - { - $types = [ - 'image' => 'image', - 'video' => 'video', - 'document' => 'document', - 'audio' => 'audio', - 'code' => 'code', - 'archive' => 'archive' - ]; + /** + * Returns the Panel icon type + * + * @return string + */ + protected function imageIcon(): string + { + $types = [ + 'image' => 'image', + 'video' => 'video', + 'document' => 'document', + 'audio' => 'audio', + 'code' => 'code', + 'archive' => 'archive' + ]; - $extensions = [ - 'xls' => 'table', - 'xlsx' => 'table', - 'csv' => 'table', - 'docx' => 'pen', - 'doc' => 'pen', - 'rtf' => 'pen', - 'mdown' => 'markdown', - 'md' => 'markdown' - ]; + $extensions = [ + 'xls' => 'table', + 'xlsx' => 'table', + 'csv' => 'table', + 'docx' => 'pen', + 'doc' => 'pen', + 'rtf' => 'pen', + 'mdown' => 'markdown', + 'md' => 'markdown' + ]; - return $extensions[$this->model->extension()] ?? - $types[$this->model->type()] ?? - 'file'; - } + return $extensions[$this->model->extension()] ?? + $types[$this->model->type()] ?? + 'file'; + } - /** - * Returns the image file object based on provided query - * - * @internal - * @param string|null $query - * @return \Kirby\Cms\File|\Kirby\Filesystem\Asset|null - */ - protected function imageSource(string $query = null) - { - if ($query === null && $this->model->isViewable()) { - return $this->model; - } + /** + * Returns the image file object based on provided query + * + * @internal + * @param string|null $query + * @return \Kirby\Cms\File|\Kirby\Filesystem\Asset|null + */ + protected function imageSource(string $query = null) + { + if ($query === null && $this->model->isViewable()) { + return $this->model; + } - return parent::imageSource($query); - } + return parent::imageSource($query); + } - /** - * Returns an array of all actions - * that can be performed in the Panel - * - * @param array $unlock An array of options that will be force-unlocked - * @return array - */ - public function options(array $unlock = []): array - { - $options = parent::options($unlock); + /** + * Returns an array of all actions + * that can be performed in the Panel + * + * @param array $unlock An array of options that will be force-unlocked + * @return array + */ + public function options(array $unlock = []): array + { + $options = parent::options($unlock); - try { - // check if the file type is allowed at all, - // otherwise it cannot be replaced - $this->model->match($this->model->blueprint()->accept()); - } catch (Throwable $e) { - $options['replace'] = false; - } + try { + // check if the file type is allowed at all, + // otherwise it cannot be replaced + $this->model->match($this->model->blueprint()->accept()); + } catch (Throwable $e) { + $options['replace'] = false; + } - return $options; - } + return $options; + } - /** - * Returns the full path without leading slash - * - * @return string - */ - public function path(): string - { - return 'files/' . $this->model->filename(); - } + /** + * Returns the full path without leading slash + * + * @return string + */ + public function path(): string + { + return 'files/' . $this->model->filename(); + } - /** - * Prepares the response data for file pickers - * and file fields - * - * @param array|null $params - * @return array - */ - public function pickerData(array $params = []): array - { - $id = $this->model->id(); - $name = $this->model->filename(); + /** + * Prepares the response data for file pickers + * and file fields + * + * @param array|null $params + * @return array + */ + public function pickerData(array $params = []): array + { + $id = $this->model->id(); + $name = $this->model->filename(); - if (empty($params['model']) === false) { - $parent = $this->model->parent(); - $uuid = $parent === $params['model'] ? $name : $id; - $absolute = $parent !== $params['model']; - } + if (empty($params['model']) === false) { + $parent = $this->model->parent(); + $uuid = $parent === $params['model'] ? $name : $id; + $absolute = $parent !== $params['model']; + } - $params['text'] ??= '{{ file.filename }}'; + $params['text'] ??= '{{ file.filename }}'; - return array_merge(parent::pickerData($params), [ - 'filename' => $name, - 'dragText' => $this->dragText('auto', $absolute ?? false), - 'type' => $this->model->type(), - 'url' => $this->model->url(), - 'uuid' => $uuid ?? $id, - ]); - } + return array_merge(parent::pickerData($params), [ + 'filename' => $name, + 'dragText' => $this->dragText('auto', $absolute ?? false), + 'type' => $this->model->type(), + 'url' => $this->model->url(), + 'uuid' => $uuid ?? $id, + ]); + } - /** - * Returns the data array for the - * view's component props - * - * @internal - * - * @return array - */ - public function props(): array - { - $file = $this->model; - $dimensions = $file->dimensions(); - $siblings = $file->templateSiblings()->sortBy( - 'sort', - 'asc', - 'filename', - 'asc' - ); + /** + * Returns the data array for the + * view's component props + * + * @internal + * + * @return array + */ + public function props(): array + { + $file = $this->model; + $dimensions = $file->dimensions(); + $siblings = $file->templateSiblings()->sortBy( + 'sort', + 'asc', + 'filename', + 'asc' + ); - return array_merge( - parent::props(), - $this->prevNext(), - [ - 'blueprint' => $this->model->template() ?? 'default', - 'model' => [ - 'content' => $this->content(), - 'dimensions' => $dimensions->toArray(), - 'extension' => $file->extension(), - 'filename' => $file->filename(), - 'link' => $this->url(true), - 'mime' => $file->mime(), - 'niceSize' => $file->niceSize(), - 'id' => $id = $file->id(), - 'parent' => $file->parent()->panel()->path(), - 'template' => $file->template(), - 'type' => $file->type(), - 'url' => $file->url(), - ], - 'preview' => [ - 'image' => $this->image([ - 'back' => 'transparent', - 'ratio' => '1/1' - ], 'cards'), - 'url' => $url = $file->previewUrl(), - 'details' => [ - [ - 'title' => I18n::translate('template'), - 'text' => $file->template() ?? '—' - ], - [ - 'title' => I18n::translate('mime'), - 'text' => $file->mime() - ], - [ - 'title' => I18n::translate('url'), - 'text' => $id, - 'link' => $url - ], - [ - 'title' => I18n::translate('size'), - 'text' => $file->niceSize() - ], - [ - 'title' => I18n::translate('dimensions'), - 'text' => $file->type() === 'image' ? $file->dimensions() . ' ' . I18n::translate('pixel') : '—' - ], - [ - 'title' => I18n::translate('orientation'), - 'text' => $file->type() === 'image' ? I18n::translate('orientation.' . $dimensions->orientation()) : '—' - ], - ] - ] - ] - ); - } + return array_merge( + parent::props(), + $this->prevNext(), + [ + 'blueprint' => $this->model->template() ?? 'default', + 'model' => [ + 'content' => $this->content(), + 'dimensions' => $dimensions->toArray(), + 'extension' => $file->extension(), + 'filename' => $file->filename(), + 'link' => $this->url(true), + 'mime' => $file->mime(), + 'niceSize' => $file->niceSize(), + 'id' => $id = $file->id(), + 'parent' => $file->parent()->panel()->path(), + 'template' => $file->template(), + 'type' => $file->type(), + 'url' => $file->url(), + ], + 'preview' => [ + 'image' => $this->image([ + 'back' => 'transparent', + 'ratio' => '1/1' + ], 'cards'), + 'url' => $url = $file->previewUrl(), + 'details' => [ + [ + 'title' => I18n::translate('template'), + 'text' => $file->template() ?? '—' + ], + [ + 'title' => I18n::translate('mime'), + 'text' => $file->mime() + ], + [ + 'title' => I18n::translate('url'), + 'text' => $id, + 'link' => $url + ], + [ + 'title' => I18n::translate('size'), + 'text' => $file->niceSize() + ], + [ + 'title' => I18n::translate('dimensions'), + 'text' => $file->type() === 'image' ? $file->dimensions() . ' ' . I18n::translate('pixel') : '—' + ], + [ + 'title' => I18n::translate('orientation'), + 'text' => $file->type() === 'image' ? I18n::translate('orientation.' . $dimensions->orientation()) : '—' + ], + ] + ] + ] + ); + } - /** - * Returns navigation array with - * previous and next file - * - * @internal - * - * @return array - */ - public function prevNext(): array - { - $file = $this->model; - $siblings = $file->templateSiblings()->sortBy( - 'sort', - 'asc', - 'filename', - 'asc' - ); + /** + * Returns navigation array with + * previous and next file + * + * @internal + * + * @return array + */ + public function prevNext(): array + { + $file = $this->model; + $siblings = $file->templateSiblings()->sortBy( + 'sort', + 'asc', + 'filename', + 'asc' + ); - return [ - 'next' => function () use ($file, $siblings): ?array { - $next = $siblings->nth($siblings->indexOf($file) + 1); - return $this->toPrevNextLink($next, 'filename'); - }, - 'prev' => function () use ($file, $siblings): ?array { - $prev = $siblings->nth($siblings->indexOf($file) - 1); - return $this->toPrevNextLink($prev, 'filename'); - } - ]; - } - /** - * Returns the url to the editing view - * in the panel - * - * @param bool $relative - * @return string - */ - public function url(bool $relative = false): string - { - $parent = $this->model->parent()->panel()->url($relative); - return $parent . '/' . $this->path(); - } + return [ + 'next' => function () use ($file, $siblings): ?array { + $next = $siblings->nth($siblings->indexOf($file) + 1); + return $this->toPrevNextLink($next, 'filename'); + }, + 'prev' => function () use ($file, $siblings): ?array { + $prev = $siblings->nth($siblings->indexOf($file) - 1); + return $this->toPrevNextLink($prev, 'filename'); + } + ]; + } + /** + * Returns the url to the editing view + * in the panel + * + * @param bool $relative + * @return string + */ + public function url(bool $relative = false): string + { + $parent = $this->model->parent()->panel()->url($relative); + return $parent . '/' . $this->path(); + } - /** - * Returns the data array for - * this model's Panel view - * - * @internal - * - * @return array - */ - public function view(): array - { - $file = $this->model; + /** + * Returns the data array for + * this model's Panel view + * + * @internal + * + * @return array + */ + public function view(): array + { + $file = $this->model; - return [ - 'breadcrumb' => fn (): array => $file->panel()->breadcrumb(), - 'component' => 'k-file-view', - 'props' => $this->props(), - 'search' => 'files', - 'title' => $file->filename(), - ]; - } + return [ + 'breadcrumb' => fn (): array => $file->panel()->breadcrumb(), + 'component' => 'k-file-view', + 'props' => $this->props(), + 'search' => 'files', + 'title' => $file->filename(), + ]; + } } diff --git a/kirby/src/Panel/Home.php b/kirby/src/Panel/Home.php index 655893e..434673c 100755 --- a/kirby/src/Panel/Home.php +++ b/kirby/src/Panel/Home.php @@ -31,234 +31,234 @@ use Throwable; */ class Home { - /** - * Returns an alternative URL if access - * to the first choice is blocked. - * - * It will go through the entire menu and - * take the first area which is not disabled - * or locked in other ways - * - * @param \Kirby\Cms\User $user - * @return string - */ - public static function alternative(User $user): string - { - $permissions = $user->role()->permissions(); + /** + * Returns an alternative URL if access + * to the first choice is blocked. + * + * It will go through the entire menu and + * take the first area which is not disabled + * or locked in other ways + * + * @param \Kirby\Cms\User $user + * @return string + */ + public static function alternative(User $user): string + { + $permissions = $user->role()->permissions(); - // no access to the panel? The only good alternative is the main url - if ($permissions->for('access', 'panel') === false) { - return App::instance()->site()->url(); - } + // no access to the panel? The only good alternative is the main url + if ($permissions->for('access', 'panel') === false) { + return App::instance()->site()->url(); + } - // needed to create a proper menu - $areas = Panel::areas(); - $menu = View::menu($areas, $permissions->toArray()); + // needed to create a proper menu + $areas = Panel::areas(); + $menu = View::menu($areas, $permissions->toArray()); - // go through the menu and search for the first - // available view we can go to - foreach ($menu as $menuItem) { - // skip separators - if ($menuItem === '-') { - continue; - } + // go through the menu and search for the first + // available view we can go to + foreach ($menu as $menuItem) { + // skip separators + if ($menuItem === '-') { + continue; + } - // skip disabled items - if (($menuItem['disabled'] ?? false) === true) { - continue; - } + // skip disabled items + if (($menuItem['disabled'] ?? false) === true) { + continue; + } - // skip the logout button - if ($menuItem['id'] === 'logout') { - continue; - } + // skip the logout button + if ($menuItem['id'] === 'logout') { + continue; + } - return Panel::url($menuItem['link']); - } + return Panel::url($menuItem['link']); + } - throw new NotFoundException('There’s no available Panel page to redirect to'); - } + throw new NotFoundException('There’s no available Panel page to redirect to'); + } - /** - * Checks if the user has access to the given - * panel path. This is quite tricky, because we - * need to call a trimmed down router to check - * for available routes and their firewall status. - * - * @param \Kirby\Cms\User - * @param string $path - * @return bool - */ - public static function hasAccess(User $user, string $path): bool - { - $areas = Panel::areas(); - $routes = Panel::routes($areas); + /** + * Checks if the user has access to the given + * panel path. This is quite tricky, because we + * need to call a trimmed down router to check + * for available routes and their firewall status. + * + * @param \Kirby\Cms\User + * @param string $path + * @return bool + */ + public static function hasAccess(User $user, string $path): bool + { + $areas = Panel::areas(); + $routes = Panel::routes($areas); - // Remove fallback routes. Otherwise a route - // would be found even if the view does - // not exist at all. - foreach ($routes as $index => $route) { - if ($route['pattern'] === '(:all)') { - unset($routes[$index]); - } - } + // Remove fallback routes. Otherwise a route + // would be found even if the view does + // not exist at all. + foreach ($routes as $index => $route) { + if ($route['pattern'] === '(:all)') { + unset($routes[$index]); + } + } - // create a dummy router to check if we can access this route at all - try { - return Router::execute($path, 'GET', $routes, function ($route) use ($user) { - $auth = $route->attributes()['auth'] ?? true; - $areaId = $route->attributes()['area'] ?? null; - $type = $route->attributes()['type'] ?? 'view'; + // create a dummy router to check if we can access this route at all + try { + return Router::execute($path, 'GET', $routes, function ($route) use ($user) { + $auth = $route->attributes()['auth'] ?? true; + $areaId = $route->attributes()['area'] ?? null; + $type = $route->attributes()['type'] ?? 'view'; - // only allow redirects to views - if ($type !== 'view') { - return false; - } + // only allow redirects to views + if ($type !== 'view') { + return false; + } - // if auth is not required the redirect is allowed - if ($auth === false) { - return true; - } + // if auth is not required the redirect is allowed + if ($auth === false) { + return true; + } - // check the firewall - return Panel::hasAccess($user, $areaId); - }); - } catch (Throwable $e) { - return false; - } - } + // check the firewall + return Panel::hasAccess($user, $areaId); + }); + } catch (Throwable $e) { + return false; + } + } - /** - * Checks if the given Uri has the same domain - * as the index URL of the Kirby installation. - * This is used to block external URLs to third-party - * domains as redirect options. - * - * @param \Kirby\Http\Uri $uri - * @return bool - */ - public static function hasValidDomain(Uri $uri): bool - { - $rootUrl = App::instance()->site()->url(); - return $uri->domain() === (new Uri($rootUrl))->domain(); - } + /** + * Checks if the given Uri has the same domain + * as the index URL of the Kirby installation. + * This is used to block external URLs to third-party + * domains as redirect options. + * + * @param \Kirby\Http\Uri $uri + * @return bool + */ + public static function hasValidDomain(Uri $uri): bool + { + $rootUrl = App::instance()->site()->url(); + return $uri->domain() === (new Uri($rootUrl))->domain(); + } - /** - * Checks if the given URL is a Panel Url. - * - * @param string $url - * @return bool - */ - public static function isPanelUrl(string $url): bool - { - return Str::startsWith($url, App::instance()->url('panel')); - } + /** + * Checks if the given URL is a Panel Url. + * + * @param string $url + * @return bool + */ + public static function isPanelUrl(string $url): bool + { + return Str::startsWith($url, App::instance()->url('panel')); + } - /** - * Returns the path after /panel/ which can then - * be used in the router or to find a matching view - * - * @param string $url - * @return string|null - */ - public static function panelPath(string $url): ?string - { - $after = Str::after($url, App::instance()->url('panel')); - return trim($after, '/'); - } + /** + * Returns the path after /panel/ which can then + * be used in the router or to find a matching view + * + * @param string $url + * @return string|null + */ + public static function panelPath(string $url): ?string + { + $after = Str::after($url, App::instance()->url('panel')); + return trim($after, '/'); + } - /** - * Returns the Url that has been stored in the session - * before the last logout. We take this Url if possible - * to redirect the user back to the last point where they - * left before they got logged out. - * - * @return string|null - */ - public static function remembered(): ?string - { - // check for a stored path after login - $remembered = App::instance()->session()->pull('panel.path'); + /** + * Returns the Url that has been stored in the session + * before the last logout. We take this Url if possible + * to redirect the user back to the last point where they + * left before they got logged out. + * + * @return string|null + */ + public static function remembered(): ?string + { + // check for a stored path after login + $remembered = App::instance()->session()->pull('panel.path'); - // convert the result to an absolute URL if available - return $remembered ? Panel::url($remembered) : null; - } + // convert the result to an absolute URL if available + return $remembered ? Panel::url($remembered) : null; + } - /** - * Tries to find the best possible Url to redirect - * the user to after the login. - * - * When the user got logged out, we try to send them back - * to the point where they left. - * - * If they have a custom redirect Url defined in their blueprint - * via the `home` option, we send them there if no Url is stored - * in the session. - * - * If none of the options above find any result, we try to send - * them to the site view. - * - * Before the redirect happens, the final Url is sanitized, the query - * and params are removed to avoid any attacks and the domain is compared - * to avoid redirects to external Urls. - * - * Afterwards, we also check for permissions before the redirect happens - * to avoid redirects to inaccessible Panel views. In such a case - * the next best accessible view is picked from the menu. - * - * @return string - */ - public static function url(): string - { - $user = App::instance()->user(); + /** + * Tries to find the best possible Url to redirect + * the user to after the login. + * + * When the user got logged out, we try to send them back + * to the point where they left. + * + * If they have a custom redirect Url defined in their blueprint + * via the `home` option, we send them there if no Url is stored + * in the session. + * + * If none of the options above find any result, we try to send + * them to the site view. + * + * Before the redirect happens, the final Url is sanitized, the query + * and params are removed to avoid any attacks and the domain is compared + * to avoid redirects to external Urls. + * + * Afterwards, we also check for permissions before the redirect happens + * to avoid redirects to inaccessible Panel views. In such a case + * the next best accessible view is picked from the menu. + * + * @return string + */ + public static function url(): string + { + $user = App::instance()->user(); - // if there's no authenticated user, all internal - // redirects will be blocked and the user is redirected - // to the login instead - if (!$user) { - return Panel::url('login'); - } + // if there's no authenticated user, all internal + // redirects will be blocked and the user is redirected + // to the login instead + if (!$user) { + return Panel::url('login'); + } - // get the last visited url from the session or the custom home - $url = static::remembered() ?? $user->panel()->home(); + // get the last visited url from the session or the custom home + $url = static::remembered() ?? $user->panel()->home(); - // inspect the given URL - $uri = new Uri($url); + // inspect the given URL + $uri = new Uri($url); - // compare domains to avoid external redirects - if (static::hasValidDomain($uri) !== true) { - throw new InvalidArgumentException('External URLs are not allowed for Panel redirects'); - } + // compare domains to avoid external redirects + if (static::hasValidDomain($uri) !== true) { + throw new InvalidArgumentException('External URLs are not allowed for Panel redirects'); + } - // remove all params to avoid - // possible attack vectors - $uri->params = ''; - $uri->query = ''; + // remove all params to avoid + // possible attack vectors + $uri->params = ''; + $uri->query = ''; - // get a clean version of the URL - $url = $uri->toString(); + // get a clean version of the URL + $url = $uri->toString(); - // Don't further inspect URLs outside of the Panel - if (static::isPanelUrl($url) === false) { - return $url; - } + // Don't further inspect URLs outside of the Panel + if (static::isPanelUrl($url) === false) { + return $url; + } - // get the plain panel path - $path = static::panelPath($url); + // get the plain panel path + $path = static::panelPath($url); - // a redirect to login, logout or installation - // views would lead to an infinite redirect loop - if (in_array($path, ['', 'login', 'logout', 'installation'], true) === true) { - $path = 'site'; - } + // a redirect to login, logout or installation + // views would lead to an infinite redirect loop + if (in_array($path, ['', 'login', 'logout', 'installation'], true) === true) { + $path = 'site'; + } - // Check if the user can access the URL - if (static::hasAccess($user, $path) === true) { - return Panel::url($path); - } + // Check if the user can access the URL + if (static::hasAccess($user, $path) === true) { + return Panel::url($path); + } - // Try to find an alternative - return static::alternative($user); - } + // Try to find an alternative + return static::alternative($user); + } } diff --git a/kirby/src/Panel/Json.php b/kirby/src/Panel/Json.php index e1c9c8d..926046e 100755 --- a/kirby/src/Panel/Json.php +++ b/kirby/src/Panel/Json.php @@ -17,61 +17,61 @@ namespace Kirby\Panel; */ abstract class Json { - protected static $key = '$response'; + protected static $key = '$response'; - /** - * Renders the error response with the provided message - * - * @param string $message - * @param int $code - * @return array - */ - public static function error(string $message, int $code = 404) - { - return [ - 'code' => $code, - 'error' => $message - ]; - } + /** + * Renders the error response with the provided message + * + * @param string $message + * @param int $code + * @return array + */ + public static function error(string $message, int $code = 404) + { + return [ + 'code' => $code, + 'error' => $message + ]; + } - /** - * Prepares the JSON response for the Panel - * - * @param mixed $data - * @param array $options - * @return mixed - */ - public static function response($data, array $options = []) - { - // handle redirects - if (is_a($data, 'Kirby\Panel\Redirect') === true) { - $data = [ - 'redirect' => $data->location(), - 'code' => $data->code() - ]; + /** + * Prepares the JSON response for the Panel + * + * @param mixed $data + * @param array $options + * @return mixed + */ + public static function response($data, array $options = []) + { + // handle redirects + if (is_a($data, 'Kirby\Panel\Redirect') === true) { + $data = [ + 'redirect' => $data->location(), + 'code' => $data->code() + ]; - // handle Kirby exceptions - } elseif (is_a($data, 'Kirby\Exception\Exception') === true) { - $data = static::error($data->getMessage(), $data->getHttpCode()); + // handle Kirby exceptions + } elseif (is_a($data, 'Kirby\Exception\Exception') === true) { + $data = static::error($data->getMessage(), $data->getHttpCode()); - // handle exceptions - } elseif (is_a($data, 'Throwable') === true) { - $data = static::error($data->getMessage(), 500); + // handle exceptions + } elseif (is_a($data, 'Throwable') === true) { + $data = static::error($data->getMessage(), 500); - // only expect arrays from here on - } elseif (is_array($data) === false) { - $data = static::error('Invalid response', 500); - } + // only expect arrays from here on + } elseif (is_array($data) === false) { + $data = static::error('Invalid response', 500); + } - if (empty($data) === true) { - $data = static::error('The response is empty', 404); - } + if (empty($data) === true) { + $data = static::error('The response is empty', 404); + } - // always inject the response code - $data['code'] ??= 200; - $data['path'] = $options['path'] ?? null; - $data['referrer'] = Panel::referrer(); + // always inject the response code + $data['code'] ??= 200; + $data['path'] = $options['path'] ?? null; + $data['referrer'] = Panel::referrer(); - return Panel::json([static::$key => $data], $data['code']); - } + return Panel::json([static::$key => $data], $data['code']); + } } diff --git a/kirby/src/Panel/Model.php b/kirby/src/Panel/Model.php index 275a7d0..6fc7675 100755 --- a/kirby/src/Panel/Model.php +++ b/kirby/src/Panel/Model.php @@ -18,433 +18,433 @@ use Kirby\Toolkit\A; */ abstract class Model { - /** - * @var \Kirby\Cms\ModelWithContent - */ - protected $model; + /** + * @var \Kirby\Cms\ModelWithContent + */ + protected $model; - /** - * @param \Kirby\Cms\ModelWithContent $model - */ - public function __construct($model) - { - $this->model = $model; - } + /** + * @param \Kirby\Cms\ModelWithContent $model + */ + public function __construct($model) + { + $this->model = $model; + } - /** - * Get the content values for the model - * - * @return array - */ - public function content(): array - { - return Form::for($this->model)->values(); - } + /** + * Get the content values for the model + * + * @return array + */ + public function content(): array + { + return Form::for($this->model)->values(); + } - /** - * Returns the drag text from a custom callback - * if the callback is defined in the config - * @internal - * - * @param string $type markdown or kirbytext - * @param mixed ...$args - * @return string|null - */ - public function dragTextFromCallback(string $type, ...$args): ?string - { - $option = 'panel.' . $type . '.' . $this->model::CLASS_ALIAS . 'DragText'; - $callback = $this->model->kirby()->option($option); + /** + * Returns the drag text from a custom callback + * if the callback is defined in the config + * @internal + * + * @param string $type markdown or kirbytext + * @param mixed ...$args + * @return string|null + */ + public function dragTextFromCallback(string $type, ...$args): ?string + { + $option = 'panel.' . $type . '.' . $this->model::CLASS_ALIAS . 'DragText'; + $callback = $this->model->kirby()->option($option); - if ( - empty($callback) === false && - is_a($callback, 'Closure') === true && - ($dragText = $callback($this->model, ...$args)) !== null - ) { - return $dragText; - } + if ( + empty($callback) === false && + is_a($callback, 'Closure') === true && + ($dragText = $callback($this->model, ...$args)) !== null + ) { + return $dragText; + } - return null; - } + return null; + } - /** - * Returns the correct drag text type - * depending on the given type or the - * configuration - * - * @internal - * - * @param string|null $type (`auto`|`kirbytext`|`markdown`) - * @return string - */ - public function dragTextType(string $type = null): string - { - $type ??= 'auto'; + /** + * Returns the correct drag text type + * depending on the given type or the + * configuration + * + * @internal + * + * @param string|null $type (`auto`|`kirbytext`|`markdown`) + * @return string + */ + public function dragTextType(string $type = null): string + { + $type ??= 'auto'; - if ($type === 'auto') { - $kirby = $this->model->kirby(); - $type = $kirby->option('panel.kirbytext', true) ? 'kirbytext' : 'markdown'; - } + if ($type === 'auto') { + $kirby = $this->model->kirby(); + $type = $kirby->option('panel.kirbytext', true) ? 'kirbytext' : 'markdown'; + } - return $type === 'markdown' ? 'markdown' : 'kirbytext'; - } + return $type === 'markdown' ? 'markdown' : 'kirbytext'; + } - /** - * Returns the setup for a dropdown option - * which is used in the changes dropdown - * for example. - * - * @return array - */ - public function dropdownOption(): array - { - return [ - 'icon' => 'page', - 'link' => $this->url(), - 'text' => $this->model->id(), - ]; - } + /** + * Returns the setup for a dropdown option + * which is used in the changes dropdown + * for example. + * + * @return array + */ + public function dropdownOption(): array + { + return [ + 'icon' => 'page', + 'link' => $this->url(), + 'text' => $this->model->id(), + ]; + } - /** - * Returns the Panel image definition - * - * @internal - * - * @param string|array|false|null $settings - * @return array|null - */ - public function image($settings = [], string $layout = 'list'): ?array - { - // completely switched off - if ($settings === false) { - return null; - } + /** + * Returns the Panel image definition + * + * @internal + * + * @param string|array|false|null $settings + * @return array|null + */ + public function image($settings = [], string $layout = 'list'): ?array + { + // completely switched off + if ($settings === false) { + return null; + } - // skip image thumbnail if option - // is explicitly set to show the icon - if ($settings === 'icon') { - $settings = [ - 'query' => false - ]; - } elseif (is_string($settings) === true) { - // convert string settings to proper array - $settings = [ - 'query' => $settings - ]; - } + // skip image thumbnail if option + // is explicitly set to show the icon + if ($settings === 'icon') { + $settings = [ + 'query' => false + ]; + } elseif (is_string($settings) === true) { + // convert string settings to proper array + $settings = [ + 'query' => $settings + ]; + } - // merge with defaults and blueprint option - $settings = array_merge( - $this->imageDefaults(), - $settings ?? [], - $this->model->blueprint()->image() ?? [], - ); + // merge with defaults and blueprint option + $settings = array_merge( + $this->imageDefaults(), + $settings ?? [], + $this->model->blueprint()->image() ?? [], + ); - if ($image = $this->imageSource($settings['query'] ?? null)) { - // main url - $settings['url'] = $image->url(); + if ($image = $this->imageSource($settings['query'] ?? null)) { + // main url + $settings['url'] = $image->url(); - // only create srcsets for resizable files - if ($image->isResizable() === true) { - $settings['src'] = static::imagePlaceholder(); + // only create srcsets for resizable files + if ($image->isResizable() === true) { + $settings['src'] = static::imagePlaceholder(); - switch ($layout) { - case 'cards': - $sizes = [352, 864, 1408]; - break; - case 'cardlets': - $sizes = [96, 192]; - break; - case 'list': - default: - $sizes = [38, 76]; - break; - } + switch ($layout) { + case 'cards': + $sizes = [352, 864, 1408]; + break; + case 'cardlets': + $sizes = [96, 192]; + break; + case 'list': + default: + $sizes = [38, 76]; + break; + } - if (($settings['cover'] ?? false) === false || $layout === 'cards') { - $settings['srcset'] = $image->srcset($sizes); - } else { - $settings['srcset'] = $image->srcset([ - '1x' => [ - 'width' => $sizes[0], - 'height' => $sizes[0], - 'crop' => 'center' - ], - '2x' => [ - 'width' => $sizes[1], - 'height' => $sizes[1], - 'crop' => 'center' - ] - ]); - } - } elseif ($image->isViewable() === true) { - $settings['src'] = $image->url(); - } - } + if (($settings['cover'] ?? false) === false || $layout === 'cards') { + $settings['srcset'] = $image->srcset($sizes); + } else { + $settings['srcset'] = $image->srcset([ + '1x' => [ + 'width' => $sizes[0], + 'height' => $sizes[0], + 'crop' => 'center' + ], + '2x' => [ + 'width' => $sizes[1], + 'height' => $sizes[1], + 'crop' => 'center' + ] + ]); + } + } elseif ($image->isViewable() === true) { + $settings['src'] = $image->url(); + } + } - if (isset($settings['query']) === true) { - unset($settings['query']); - } + if (isset($settings['query']) === true) { + unset($settings['query']); + } - // resolve remaining options defined as query - return A::map($settings, function ($option) { - if (is_string($option) === false) { - return $option; - } + // resolve remaining options defined as query + return A::map($settings, function ($option) { + if (is_string($option) === false) { + return $option; + } - return $this->model->toString($option); - }); - } + return $this->model->toString($option); + }); + } - /** - * Default settings for Panel image - * - * @return array - */ - protected function imageDefaults(): array - { - return [ - 'back' => 'pattern', - 'color' => 'gray-500', - 'cover' => false, - 'icon' => 'page', - 'ratio' => '3/2', - ]; - } + /** + * Default settings for Panel image + * + * @return array + */ + protected function imageDefaults(): array + { + return [ + 'back' => 'pattern', + 'color' => 'gray-500', + 'cover' => false, + 'icon' => 'page', + 'ratio' => '3/2', + ]; + } - /** - * Data URI placeholder string for Panel image - * - * @internal - * - * @return string - */ - public static function imagePlaceholder(): string - { - return 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw'; - } + /** + * Data URI placeholder string for Panel image + * + * @internal + * + * @return string + */ + public static function imagePlaceholder(): string + { + return 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw'; + } - /** - * Returns the image file object based on provided query - * - * @internal - * - * @param string|null $query - * @return \Kirby\Cms\File|\Kirby\Filesystem\Asset|null - */ - protected function imageSource(?string $query = null) - { - $image = $this->model->query($query ?? null); + /** + * Returns the image file object based on provided query + * + * @internal + * + * @param string|null $query + * @return \Kirby\Cms\File|\Kirby\Filesystem\Asset|null + */ + protected function imageSource(?string $query = null) + { + $image = $this->model->query($query ?? null); - // validate the query result - if ( - is_a($image, 'Kirby\Cms\File') === true || - is_a($image, 'Kirby\Filesystem\Asset') === true - ) { - return $image; - } + // validate the query result + if ( + is_a($image, 'Kirby\Cms\File') === true || + is_a($image, 'Kirby\Filesystem\Asset') === true + ) { + return $image; + } - return null; - } + return null; + } - /** - * Checks for disabled dropdown options according - * to the given permissions - * - * @param string $action - * @param array $options - * @param array $permissions - * @return bool - */ - public function isDisabledDropdownOption(string $action, array $options, array $permissions): bool - { - $option = $options[$action] ?? true; - return $permissions[$action] === false || $option === false || $option === 'false'; - } + /** + * Checks for disabled dropdown options according + * to the given permissions + * + * @param string $action + * @param array $options + * @param array $permissions + * @return bool + */ + public function isDisabledDropdownOption(string $action, array $options, array $permissions): bool + { + $option = $options[$action] ?? true; + return $permissions[$action] === false || $option === false || $option === 'false'; + } - /** - * Returns lock info for the Panel - * - * @return array|false array with lock info, - * false if locking is not supported - */ - public function lock() - { - if ($lock = $this->model->lock()) { - if ($lock->isUnlocked() === true) { - return ['state' => 'unlock']; - } + /** + * Returns lock info for the Panel + * + * @return array|false array with lock info, + * false if locking is not supported + */ + public function lock() + { + if ($lock = $this->model->lock()) { + if ($lock->isUnlocked() === true) { + return ['state' => 'unlock']; + } - if ($lock->isLocked() === true) { - return [ - 'state' => 'lock', - 'data' => $lock->get() - ]; - } + if ($lock->isLocked() === true) { + return [ + 'state' => 'lock', + 'data' => $lock->get() + ]; + } - return ['state' => null]; - } + return ['state' => null]; + } - return false; - } + return false; + } - /** - * Returns an array of all actions - * that can be performed in the Panel - * This also checks for the lock status - * - * @param array $unlock An array of options that will be force-unlocked - * @return array - */ - public function options(array $unlock = []): array - { - $options = $this->model->permissions()->toArray(); + /** + * Returns an array of all actions + * that can be performed in the Panel + * This also checks for the lock status + * + * @param array $unlock An array of options that will be force-unlocked + * @return array + */ + public function options(array $unlock = []): array + { + $options = $this->model->permissions()->toArray(); - if ($this->model->isLocked()) { - foreach ($options as $key => $value) { - if (in_array($key, $unlock)) { - continue; - } + if ($this->model->isLocked()) { + foreach ($options as $key => $value) { + if (in_array($key, $unlock)) { + continue; + } - $options[$key] = false; - } - } + $options[$key] = false; + } + } - return $options; - } + return $options; + } - /** - * Returns the full path without leading slash - * - * @return string - */ - abstract public function path(): string; + /** + * Returns the full path without leading slash + * + * @return string + */ + abstract public function path(): string; - /** - * Prepares the response data for page pickers - * and page fields - * - * @param array|null $params - * @return array - */ - public function pickerData(array $params = []): array - { - return [ - 'id' => $this->model->id(), - 'image' => $this->image( - $params['image'] ?? [], - $params['layout'] ?? 'list' - ), - 'info' => $this->model->toSafeString($params['info'] ?? false), - 'link' => $this->url(true), - 'sortable' => true, - 'text' => $this->model->toSafeString($params['text'] ?? false), - ]; - } + /** + * Prepares the response data for page pickers + * and page fields + * + * @param array|null $params + * @return array + */ + public function pickerData(array $params = []): array + { + return [ + 'id' => $this->model->id(), + 'image' => $this->image( + $params['image'] ?? [], + $params['layout'] ?? 'list' + ), + 'info' => $this->model->toSafeString($params['info'] ?? false), + 'link' => $this->url(true), + 'sortable' => true, + 'text' => $this->model->toSafeString($params['text'] ?? false), + ]; + } - /** - * Returns the data array for the - * view's component props - * - * @internal - * - * @return array - */ - public function props(): array - { - $blueprint = $this->model->blueprint(); - $request = $this->model->kirby()->request(); - $tabs = $blueprint->tabs(); - $tab = $blueprint->tab($request->get('tab')) ?? $tabs[0] ?? null; + /** + * Returns the data array for the + * view's component props + * + * @internal + * + * @return array + */ + public function props(): array + { + $blueprint = $this->model->blueprint(); + $request = $this->model->kirby()->request(); + $tabs = $blueprint->tabs(); + $tab = $blueprint->tab($request->get('tab')) ?? $tabs[0] ?? null; - $props = [ - 'lock' => $this->lock(), - 'permissions' => $this->model->permissions()->toArray(), - 'tabs' => $tabs, - ]; + $props = [ + 'lock' => $this->lock(), + 'permissions' => $this->model->permissions()->toArray(), + 'tabs' => $tabs, + ]; - // only send the tab if it exists - // this will let the vue component define - // a proper default value - if ($tab) { - $props['tab'] = $tab; - } + // only send the tab if it exists + // this will let the vue component define + // a proper default value + if ($tab) { + $props['tab'] = $tab; + } - return $props; - } + return $props; + } - /** - * Returns link url and tooltip - * for model (e.g. used for prev/next - * navigation) - * - * @internal - * - * @param string $tooltip - * @return array - */ - public function toLink(string $tooltip = 'title'): array - { - return [ - 'link' => $this->url(true), - 'tooltip' => (string)$this->model->{$tooltip}() - ]; - } + /** + * Returns link url and tooltip + * for model (e.g. used for prev/next + * navigation) + * + * @internal + * + * @param string $tooltip + * @return array + */ + public function toLink(string $tooltip = 'title'): array + { + return [ + 'link' => $this->url(true), + 'tooltip' => (string)$this->model->{$tooltip}() + ]; + } - /** - * Returns link url and tooltip - * for optional sibling model and - * preserves tab selection - * - * @internal - * - * @param \Kirby\Cms\ModelWithContent|null $model - * @param string $tooltip - * @return array - */ - protected function toPrevNextLink($model = null, string $tooltip = 'title'): ?array - { - if ($model === null) { - return null; - } + /** + * Returns link url and tooltip + * for optional sibling model and + * preserves tab selection + * + * @internal + * + * @param \Kirby\Cms\ModelWithContent|null $model + * @param string $tooltip + * @return array + */ + protected function toPrevNextLink($model = null, string $tooltip = 'title'): ?array + { + if ($model === null) { + return null; + } - $data = $model->panel()->toLink($tooltip); + $data = $model->panel()->toLink($tooltip); - if ($tab = $model->kirby()->request()->get('tab')) { - $uri = new Uri($data['link'], [ - 'query' => ['tab' => $tab] - ]); + if ($tab = $model->kirby()->request()->get('tab')) { + $uri = new Uri($data['link'], [ + 'query' => ['tab' => $tab] + ]); - $data['link'] = $uri->toString(); - } + $data['link'] = $uri->toString(); + } - return $data; - } + return $data; + } - /** - * Returns the url to the editing view - * in the Panel - * - * @internal - * - * @param bool $relative - * @return string - */ - public function url(bool $relative = false): string - { - if ($relative === true) { - return '/' . $this->path(); - } + /** + * Returns the url to the editing view + * in the Panel + * + * @internal + * + * @param bool $relative + * @return string + */ + public function url(bool $relative = false): string + { + if ($relative === true) { + return '/' . $this->path(); + } - return $this->model->kirby()->url('panel') . '/' . $this->path(); - } + return $this->model->kirby()->url('panel') . '/' . $this->path(); + } - /** - * Returns the data array for - * this model's Panel view - * - * @internal - * - * @return array - */ - abstract public function view(): array; + /** + * Returns the data array for + * this model's Panel view + * + * @internal + * + * @return array + */ + abstract public function view(): array; } diff --git a/kirby/src/Panel/Page.php b/kirby/src/Panel/Page.php index 784187c..9d73016 100755 --- a/kirby/src/Panel/Page.php +++ b/kirby/src/Panel/Page.php @@ -16,360 +16,360 @@ use Kirby\Toolkit\I18n; */ class Page extends Model { - /** - * @var \Kirby\Cms\Page - */ - protected $model; + /** + * @var \Kirby\Cms\Page + */ + protected $model; - /** - * Breadcrumb array - * - * @return array - */ - public function breadcrumb(): array - { - $parents = $this->model->parents()->flip()->merge($this->model); - return $parents->values(fn ($parent) => [ - 'label' => $parent->title()->toString(), - 'link' => $parent->panel()->url(true), - ]); - } + /** + * Breadcrumb array + * + * @return array + */ + public function breadcrumb(): array + { + $parents = $this->model->parents()->flip()->merge($this->model); + return $parents->values(fn ($parent) => [ + 'label' => $parent->title()->toString(), + 'link' => $parent->panel()->url(true), + ]); + } - /** - * Provides a kirbytag or markdown - * tag for the page, which will be - * used in the panel, when the page - * gets dragged onto a textarea - * - * @internal - * @param string|null $type (`auto`|`kirbytext`|`markdown`) - * @return string - */ - public function dragText(string $type = null): string - { - $type = $this->dragTextType($type); + /** + * Provides a kirbytag or markdown + * tag for the page, which will be + * used in the panel, when the page + * gets dragged onto a textarea + * + * @internal + * @param string|null $type (`auto`|`kirbytext`|`markdown`) + * @return string + */ + public function dragText(string $type = null): string + { + $type = $this->dragTextType($type); - if ($callback = $this->dragTextFromCallback($type)) { - return $callback; - } + if ($callback = $this->dragTextFromCallback($type)) { + return $callback; + } - if ($type === 'markdown') { - return '[' . $this->model->title() . '](' . $this->model->url() . ')'; - } + if ($type === 'markdown') { + return '[' . $this->model->title() . '](' . $this->model->url() . ')'; + } - return '(link: ' . $this->model->id() . ' text: ' . $this->model->title() . ')'; - } + return '(link: ' . $this->model->id() . ' text: ' . $this->model->title() . ')'; + } - /** - * Provides options for the page dropdown - * - * @param array $options - * @return array - */ - public function dropdown(array $options = []): array - { - $page = $this->model; + /** + * Provides options for the page dropdown + * + * @param array $options + * @return array + */ + public function dropdown(array $options = []): array + { + $page = $this->model; - $defaults = $page->kirby()->request()->get(['view', 'sort', 'delete']); - $options = array_merge($defaults, $options); + $defaults = $page->kirby()->request()->get(['view', 'sort', 'delete']); + $options = array_merge($defaults, $options); - $permissions = $this->options(['preview']); - $view = $options['view'] ?? 'view'; - $url = $this->url(true); - $result = []; + $permissions = $this->options(['preview']); + $view = $options['view'] ?? 'view'; + $url = $this->url(true); + $result = []; - if ($view === 'list') { - $result['preview'] = [ - 'link' => $page->previewUrl(), - 'target' => '_blank', - 'icon' => 'open', - 'text' => I18n::translate('open'), - 'disabled' => $this->isDisabledDropdownOption('preview', $options, $permissions) - ]; - $result[] = '-'; - } + if ($view === 'list') { + $result['preview'] = [ + 'link' => $page->previewUrl(), + 'target' => '_blank', + 'icon' => 'open', + 'text' => I18n::translate('open'), + 'disabled' => $this->isDisabledDropdownOption('preview', $options, $permissions) + ]; + $result[] = '-'; + } - $result['changeTitle'] = [ - 'dialog' => [ - 'url' => $url . '/changeTitle', - 'query' => [ - 'select' => 'title' - ] - ], - 'icon' => 'title', - 'text' => I18n::translate('rename'), - 'disabled' => $this->isDisabledDropdownOption('changeTitle', $options, $permissions) - ]; + $result['changeTitle'] = [ + 'dialog' => [ + 'url' => $url . '/changeTitle', + 'query' => [ + 'select' => 'title' + ] + ], + 'icon' => 'title', + 'text' => I18n::translate('rename'), + 'disabled' => $this->isDisabledDropdownOption('changeTitle', $options, $permissions) + ]; - $result['duplicate'] = [ - 'dialog' => $url . '/duplicate', - 'icon' => 'copy', - 'text' => I18n::translate('duplicate'), - 'disabled' => $this->isDisabledDropdownOption('duplicate', $options, $permissions) - ]; + $result['duplicate'] = [ + 'dialog' => $url . '/duplicate', + 'icon' => 'copy', + 'text' => I18n::translate('duplicate'), + 'disabled' => $this->isDisabledDropdownOption('duplicate', $options, $permissions) + ]; - $result[] = '-'; + $result[] = '-'; - $result['changeSlug'] = [ - 'dialog' => [ - 'url' => $url . '/changeTitle', - 'query' => [ - 'select' => 'slug' - ] - ], - 'icon' => 'url', - 'text' => I18n::translate('page.changeSlug'), - 'disabled' => $this->isDisabledDropdownOption('changeSlug', $options, $permissions) - ]; + $result['changeSlug'] = [ + 'dialog' => [ + 'url' => $url . '/changeTitle', + 'query' => [ + 'select' => 'slug' + ] + ], + 'icon' => 'url', + 'text' => I18n::translate('page.changeSlug'), + 'disabled' => $this->isDisabledDropdownOption('changeSlug', $options, $permissions) + ]; - $result['changeStatus'] = [ - 'dialog' => $url . '/changeStatus', - 'icon' => 'preview', - 'text' => I18n::translate('page.changeStatus'), - 'disabled' => $this->isDisabledDropdownOption('changeStatus', $options, $permissions) - ]; + $result['changeStatus'] = [ + 'dialog' => $url . '/changeStatus', + 'icon' => 'preview', + 'text' => I18n::translate('page.changeStatus'), + 'disabled' => $this->isDisabledDropdownOption('changeStatus', $options, $permissions) + ]; - $siblings = $page->parentModel()->children()->listed()->not($page); + $siblings = $page->parentModel()->children()->listed()->not($page); - $result['changeSort'] = [ - 'dialog' => $url . '/changeSort', - 'icon' => 'sort', - 'text' => I18n::translate('page.sort'), - 'disabled' => $siblings->count() === 0 || $this->isDisabledDropdownOption('sort', $options, $permissions) - ]; + $result['changeSort'] = [ + 'dialog' => $url . '/changeSort', + 'icon' => 'sort', + 'text' => I18n::translate('page.sort'), + 'disabled' => $siblings->count() === 0 || $this->isDisabledDropdownOption('sort', $options, $permissions) + ]; - $result['changeTemplate'] = [ - 'dialog' => $url . '/changeTemplate', - 'icon' => 'template', - 'text' => I18n::translate('page.changeTemplate'), - 'disabled' => $this->isDisabledDropdownOption('changeTemplate', $options, $permissions) - ]; + $result['changeTemplate'] = [ + 'dialog' => $url . '/changeTemplate', + 'icon' => 'template', + 'text' => I18n::translate('page.changeTemplate'), + 'disabled' => $this->isDisabledDropdownOption('changeTemplate', $options, $permissions) + ]; - $result[] = '-'; - $result['delete'] = [ - 'dialog' => $url . '/delete', - 'icon' => 'trash', - 'text' => I18n::translate('delete'), - 'disabled' => $this->isDisabledDropdownOption('delete', $options, $permissions) - ]; + $result[] = '-'; + $result['delete'] = [ + 'dialog' => $url . '/delete', + 'icon' => 'trash', + 'text' => I18n::translate('delete'), + 'disabled' => $this->isDisabledDropdownOption('delete', $options, $permissions) + ]; - return $result; - } + return $result; + } - /** - * Returns the setup for a dropdown option - * which is used in the changes dropdown - * for example. - * - * @return array - */ - public function dropdownOption(): array - { - return [ - 'text' => $this->model->title()->value(), - ] + parent::dropdownOption(); - } + /** + * Returns the setup for a dropdown option + * which is used in the changes dropdown + * for example. + * + * @return array + */ + public function dropdownOption(): array + { + return [ + 'text' => $this->model->title()->value(), + ] + parent::dropdownOption(); + } - /** - * Returns the escaped Id, which is - * used in the panel to make routing work properly - * - * @return string - */ - public function id(): string - { - return str_replace('/', '+', $this->model->id()); - } + /** + * Returns the escaped Id, which is + * used in the panel to make routing work properly + * + * @return string + */ + public function id(): string + { + return str_replace('/', '+', $this->model->id()); + } - /** - * Default settings for the page's Panel image - * - * @return array - */ - protected function imageDefaults(): array - { - $defaults = []; + /** + * Default settings for the page's Panel image + * + * @return array + */ + protected function imageDefaults(): array + { + $defaults = []; - if ($icon = $this->model->blueprint()->icon()) { - $defaults['icon'] = $icon; - } + if ($icon = $this->model->blueprint()->icon()) { + $defaults['icon'] = $icon; + } - return array_merge(parent::imageDefaults(), $defaults); - } + return array_merge(parent::imageDefaults(), $defaults); + } - /** - * Returns the image file object based on provided query - * - * @internal - * @param string|null $query - * @return \Kirby\Cms\File|\Kirby\Filesystem\Asset|null - */ - protected function imageSource(string $query = null) - { - if ($query === null) { - $query = 'page.image'; - } + /** + * Returns the image file object based on provided query + * + * @internal + * @param string|null $query + * @return \Kirby\Cms\File|\Kirby\Filesystem\Asset|null + */ + protected function imageSource(string $query = null) + { + if ($query === null) { + $query = 'page.image'; + } - return parent::imageSource($query); - } + return parent::imageSource($query); + } - /** - * Returns the full path without leading slash - * - * @internal - * @return string - */ - public function path(): string - { - return 'pages/' . $this->id(); - } + /** + * Returns the full path without leading slash + * + * @internal + * @return string + */ + public function path(): string + { + return 'pages/' . $this->id(); + } - /** - * Prepares the response data for page pickers - * and page fields - * - * @param array|null $params - * @return array - */ - public function pickerData(array $params = []): array - { - $params['text'] ??= '{{ page.title }}'; + /** + * Prepares the response data for page pickers + * and page fields + * + * @param array|null $params + * @return array + */ + public function pickerData(array $params = []): array + { + $params['text'] ??= '{{ page.title }}'; - return array_merge(parent::pickerData($params), [ - 'dragText' => $this->dragText(), - 'hasChildren' => $this->model->hasChildren(), - 'url' => $this->model->url() - ]); - } + return array_merge(parent::pickerData($params), [ + 'dragText' => $this->dragText(), + 'hasChildren' => $this->model->hasChildren(), + 'url' => $this->model->url() + ]); + } - /** - * The best applicable position for - * the position/status dialog - * - * @return int - */ - public function position(): int - { - return $this->model->num() ?? $this->model->parentModel()->children()->listed()->not($this->model)->count() + 1; - } + /** + * The best applicable position for + * the position/status dialog + * + * @return int + */ + public function position(): int + { + return $this->model->num() ?? $this->model->parentModel()->children()->listed()->not($this->model)->count() + 1; + } - /** - * Returns navigation array with - * previous and next page - * based on blueprint definition - * - * @internal - * - * @return array - */ - public function prevNext(): array - { - $page = $this->model; + /** + * Returns navigation array with + * previous and next page + * based on blueprint definition + * + * @internal + * + * @return array + */ + public function prevNext(): array + { + $page = $this->model; - // create siblings collection based on - // blueprint navigation - $siblings = function (string $direction) use ($page) { - $navigation = $page->blueprint()->navigation(); - $sortBy = $navigation['sortBy'] ?? null; - $status = $navigation['status'] ?? null; - $template = $navigation['template'] ?? null; - $direction = $direction === 'prev' ? 'prev' : 'next'; + // create siblings collection based on + // blueprint navigation + $siblings = function (string $direction) use ($page) { + $navigation = $page->blueprint()->navigation(); + $sortBy = $navigation['sortBy'] ?? null; + $status = $navigation['status'] ?? null; + $template = $navigation['template'] ?? null; + $direction = $direction === 'prev' ? 'prev' : 'next'; - // if status is defined in navigation, - // all items in the collection are used - // (drafts, listed and unlisted) otherwise - // it depends on the status of the page - $siblings = $status !== null ? $page->parentModel()->childrenAndDrafts() : $page->siblings(); + // if status is defined in navigation, + // all items in the collection are used + // (drafts, listed and unlisted) otherwise + // it depends on the status of the page + $siblings = $status !== null ? $page->parentModel()->childrenAndDrafts() : $page->siblings(); - // sort the collection if custom sortBy - // defined in navigation otherwise - // default sorting will apply - if ($sortBy !== null) { - $siblings = $siblings->sort(...$siblings::sortArgs($sortBy)); - } + // sort the collection if custom sortBy + // defined in navigation otherwise + // default sorting will apply + if ($sortBy !== null) { + $siblings = $siblings->sort(...$siblings::sortArgs($sortBy)); + } - $siblings = $page->{$direction . 'All'}($siblings); + $siblings = $page->{$direction . 'All'}($siblings); - if (empty($navigation) === false) { - $statuses = (array)($status ?? $page->status()); - $templates = (array)($template ?? $page->intendedTemplate()); + if (empty($navigation) === false) { + $statuses = (array)($status ?? $page->status()); + $templates = (array)($template ?? $page->intendedTemplate()); - // do not filter if template navigation is all - if (in_array('all', $templates) === false) { - $siblings = $siblings->filter('intendedTemplate', 'in', $templates); - } + // do not filter if template navigation is all + if (in_array('all', $templates) === false) { + $siblings = $siblings->filter('intendedTemplate', 'in', $templates); + } - // do not filter if status navigation is all - if (in_array('all', $statuses) === false) { - $siblings = $siblings->filter('status', 'in', $statuses); - } - } else { - $siblings = $siblings - ->filter('intendedTemplate', $page->intendedTemplate()) - ->filter('status', $page->status()); - } + // do not filter if status navigation is all + if (in_array('all', $statuses) === false) { + $siblings = $siblings->filter('status', 'in', $statuses); + } + } else { + $siblings = $siblings + ->filter('intendedTemplate', $page->intendedTemplate()) + ->filter('status', $page->status()); + } - return $siblings->filter('isReadable', true); - }; + return $siblings->filter('isReadable', true); + }; - return [ - 'next' => fn () => $this->toPrevNextLink($siblings('next')->first()), - 'prev' => fn () => $this->toPrevNextLink($siblings('prev')->last()) - ]; - } + return [ + 'next' => fn () => $this->toPrevNextLink($siblings('next')->first()), + 'prev' => fn () => $this->toPrevNextLink($siblings('prev')->last()) + ]; + } - /** - * Returns the data array for the - * view's component props - * - * @internal - * - * @return array - */ - public function props(): array - { - $page = $this->model; + /** + * Returns the data array for the + * view's component props + * + * @internal + * + * @return array + */ + public function props(): array + { + $page = $this->model; - return array_merge( - parent::props(), - $this->prevNext(), - [ - 'blueprint' => $this->model->intendedTemplate()->name(), - 'model' => [ - 'content' => $this->content(), - 'id' => $page->id(), - 'link' => $this->url(true), - 'parent' => $page->parentModel()->panel()->url(true), - 'previewUrl' => $page->previewUrl(), - 'status' => $page->status(), - 'title' => $page->title()->toString(), - ], - 'status' => function () use ($page) { - if ($status = $page->status()) { - return $page->blueprint()->status()[$status] ?? null; - } - }, - ] - ); - } + return array_merge( + parent::props(), + $this->prevNext(), + [ + 'blueprint' => $this->model->intendedTemplate()->name(), + 'model' => [ + 'content' => $this->content(), + 'id' => $page->id(), + 'link' => $this->url(true), + 'parent' => $page->parentModel()->panel()->url(true), + 'previewUrl' => $page->previewUrl(), + 'status' => $page->status(), + 'title' => $page->title()->toString(), + ], + 'status' => function () use ($page) { + if ($status = $page->status()) { + return $page->blueprint()->status()[$status] ?? null; + } + }, + ] + ); + } - /** - * Returns the data array for - * this model's Panel view - * - * @internal - * - * @return array - */ - public function view(): array - { - $page = $this->model; + /** + * Returns the data array for + * this model's Panel view + * + * @internal + * + * @return array + */ + public function view(): array + { + $page = $this->model; - return [ - 'breadcrumb' => $page->panel()->breadcrumb(), - 'component' => 'k-page-view', - 'props' => $this->props(), - 'title' => $page->title()->toString(), - ]; - } + return [ + 'breadcrumb' => $page->panel()->breadcrumb(), + 'component' => 'k-page-view', + 'props' => $this->props(), + 'title' => $page->title()->toString(), + ]; + } } diff --git a/kirby/src/Panel/Panel.php b/kirby/src/Panel/Panel.php index f3b6bba..9fb63eb 100755 --- a/kirby/src/Panel/Panel.php +++ b/kirby/src/Panel/Panel.php @@ -30,591 +30,591 @@ use Throwable; */ class Panel { - /** - * Normalize a panel area - * - * @param string $id - * @param array|string $area - * @return array - */ - public static function area(string $id, $area): array - { - $area['id'] = $id; - $area['label'] ??= $id; - $area['breadcrumb'] ??= []; - $area['breadcrumbLabel'] ??= $area['label']; - $area['title'] = $area['label']; - $area['menu'] ??= false; - $area['link'] ??= $id; - $area['search'] ??= null; - - return $area; - } - - /** - * Collect all registered areas - * - * @return array - */ - public static function areas(): array - { - $kirby = App::instance(); - $system = $kirby->system(); - $user = $kirby->user(); - $areas = $kirby->load()->areas(); - - // the system is not ready - if ($system->isOk() === false || $system->isInstalled() === false) { - return [ - 'installation' => static::area('installation', $areas['installation']), - ]; - } - - // not yet authenticated - if (!$user) { - return [ - 'login' => static::area('login', $areas['login']), - ]; - } - - unset($areas['installation'], $areas['login']); - - // Disable the language area for single-language installations - // This does not check for installed languages. Otherwise you'd - // not be able to add the first language through the view - if (!$kirby->option('languages')) { - unset($areas['languages']); - } - - $menu = $kirby->option('panel.menu', [ - 'site', - 'languages', - 'users', - 'system', - ]); - - $result = []; - - // add the sorted areas - foreach ($menu as $id) { - if ($area = ($areas[$id] ?? null)) { - $result[$id] = static::area($id, $area); - unset($areas[$id]); - } - } - - // add the remaining areas - foreach ($areas as $id => $area) { - $result[$id] = static::area($id, $area); - } - - return $result; - } - - /** - * Check for access permissions - * - * @param \Kirby\Cms\User|null $user - * @param string|null $areaId - * @return bool - */ - public static function firewall(?User $user = null, ?string $areaId = null): bool - { - // a user has to be logged in - if ($user === null) { - throw new PermissionException(['key' => 'access.panel']); - } - - // get all access permissions for the user role - $permissions = $user->role()->permissions()->toArray()['access']; - - // check for general panel access - if (($permissions['panel'] ?? true) !== true) { - throw new PermissionException(['key' => 'access.panel']); - } - - // don't check if the area is not defined - if (empty($areaId) === true) { - return true; - } - - // undefined area permissions means access - if (isset($permissions[$areaId]) === false) { - return true; - } - - // no access - if ($permissions[$areaId] !== true) { - throw new PermissionException(['key' => 'access.view']); - } - - return true; - } - - - /** - * Redirect to a Panel url - * - * @param string|null $path - * @param int $code - * @throws \Kirby\Panel\Redirect - * @return void - * @codeCoverageIgnore - */ - public static function go(?string $url = null, int $code = 302): void - { - throw new Redirect(static::url($url), $code); - } - - /** - * Check if the given user has access to the panel - * or to a given area - * - * @param \Kirby\Cms\User|null $user - * @param string|null $area - * @return bool - */ - public static function hasAccess(?User $user = null, string $area = null): bool - { - try { - static::firewall($user, $area); - return true; - } catch (Throwable $e) { - return false; - } - } - - /** - * Checks for a Fiber request - * via get parameters or headers - * - * @return bool - */ - public static function isFiberRequest(): bool - { - $request = App::instance()->request(); - - if ($request->method() === 'GET') { - return (bool)($request->get('_json') ?? $request->header('X-Fiber')); - } - - return false; - } - - /** - * Returns a JSON response - * for Fiber calls - * - * @param array $data - * @param int $code - * @return \Kirby\Http\Response - */ - public static function json(array $data, int $code = 200) - { - $request = App::instance()->request(); - - return Response::json($data, $code, $request->get('_pretty'), [ - 'X-Fiber' => 'true', - 'Cache-Control' => 'no-store, private' - ]); - } - - /** - * Checks for a multilanguage installation - * - * @return bool - */ - public static function multilang(): bool - { - // multilang setup check - $kirby = App::instance(); - return $kirby->option('languages') || $kirby->multilang(); - } - - /** - * Returns the referrer path if present - * - * @return string - */ - public static function referrer(): string - { - $request = App::instance()->request(); - - $referrer = $request->header('X-Fiber-Referrer') - ?? $request->get('_referrer') - ?? ''; - - return '/' . trim($referrer, '/'); - } - - /** - * Creates a Response object from the result of - * a Panel route call - * - * @params mixed $result - * @params array $options - * @return \Kirby\Http\Response - */ - public static function response($result, array $options = []) - { - // pass responses directly down to the Kirby router - if (is_a($result, 'Kirby\Http\Response') === true) { - return $result; - } - - // interpret missing/empty results as not found - if ($result === null || $result === false) { - $result = new NotFoundException('The data could not be found'); - - // interpret strings as errors - } elseif (is_string($result) === true) { - $result = new Exception($result); - } - - // handle different response types (view, dialog, ...) - switch ($options['type'] ?? null) { - case 'dialog': - return Dialog::response($result, $options); - case 'dropdown': - return Dropdown::response($result, $options); - case 'search': - return Search::response($result, $options); - default: - return View::response($result, $options); - } - } - - /** - * Router for the Panel views - * - * @param string $path - * @return \Kirby\Http\Response|false - */ - public static function router(string $path = null) - { - $kirby = App::instance(); - - if ($kirby->option('panel') === false) { - return null; - } - - // set the translation for Panel UI before - // gathering areas and routes, so that the - // `t()` helper can already be used - static::setTranslation(); - - // set the language in multi-lang installations - static::setLanguage(); - - $areas = static::areas(); - $routes = static::routes($areas); - - // create a micro-router for the Panel - return Router::execute($path, $method = $kirby->request()->method(), $routes, function ($route) use ($areas, $kirby, $method, $path) { - - // route needs authentication? - $auth = $route->attributes()['auth'] ?? true; - $areaId = $route->attributes()['area'] ?? null; - $type = $route->attributes()['type'] ?? 'view'; - $area = $areas[$areaId] ?? null; - - // call the route action to check the result - try { - // trigger hook - $route = $kirby->apply('panel.route:before', compact('route', 'path', 'method'), 'route'); - - // check for access before executing area routes - if ($auth !== false) { - static::firewall($kirby->user(), $areaId); - } - - $result = $route->action()->call($route, ...$route->arguments()); - } catch (Throwable $e) { - $result = $e; - } - - $response = static::response($result, [ - 'area' => $area, - 'areas' => $areas, - 'path' => $path, - 'type' => $type - ]); - - return $kirby->apply('panel.route:after', compact('route', 'path', 'method', 'response'), 'response'); - }); - } - - /** - * Extract the routes from the given array - * of active areas. - * - * @return array - */ - public static function routes(array $areas): array - { - $kirby = App::instance(); - - // the browser incompatibility - // warning is always needed - $routes = [ - [ - 'pattern' => 'browser', - 'auth' => false, - 'action' => fn () => new Response( - Tpl::load($kirby->root('kirby') . '/views/browser.php') - ), - ] - ]; - - // register all routes from areas - foreach ($areas as $areaId => $area) { - $routes = array_merge( - $routes, - static::routesForViews($areaId, $area), - static::routesForSearches($areaId, $area), - static::routesForDialogs($areaId, $area), - static::routesForDropdowns($areaId, $area), - ); - } - - // if the Panel is already installed and/or the - // user is authenticated, those areas won't be - // included, which is why we add redirect routes - // to main Panel view as fallbacks - $routes[] = [ - 'pattern' => [ - '/', - 'installation', - 'login', - ], - 'action' => fn () => Panel::go(Home::url()), - 'auth' => false - ]; - - // catch all route - $routes[] = [ - 'pattern' => '(:all)', - 'action' => fn () => 'The view could not be found' - ]; - - return $routes; - } - - /** - * Extract all routes from an area - * - * @param string $areaId - * @param array $area - * @return array - */ - public static function routesForDialogs(string $areaId, array $area): array - { - $dialogs = $area['dialogs'] ?? []; - $routes = []; - - foreach ($dialogs as $key => $dialog) { - - // create the full pattern with dialogs prefix - $pattern = 'dialogs/' . trim(($dialog['pattern'] ?? $key), '/'); - - // load event - $routes[] = [ - 'pattern' => $pattern, - 'type' => 'dialog', - 'area' => $areaId, - 'action' => $dialog['load'] ?? fn () => 'The load handler for your dialog is missing' - ]; - - // submit event - $routes[] = [ - 'pattern' => $pattern, - 'type' => 'dialog', - 'area' => $areaId, - 'method' => 'POST', - 'action' => $dialog['submit'] ?? fn () => 'Your dialog does not define a submit handler' - ]; - } - - return $routes; - } - - /** - * Extract all routes for dropdowns - * - * @param string $areaId - * @param array $area - * @return array - */ - public static function routesForDropdowns(string $areaId, array $area): array - { - $dropdowns = $area['dropdowns'] ?? []; - $routes = []; - - foreach ($dropdowns as $name => $dropdown) { - // Handle shortcuts for dropdowns. The name is the pattern - // and options are defined in a Closure - if (is_a($dropdown, 'Closure') === true) { - $dropdown = [ - 'pattern' => $name, - 'action' => $dropdown - ]; - } - - // create the full pattern with dropdowns prefix - $pattern = 'dropdowns/' . trim(($dropdown['pattern'] ?? $name), '/'); - - // load event - $routes[] = [ - 'pattern' => $pattern, - 'type' => 'dropdown', - 'area' => $areaId, - 'method' => 'GET|POST', - 'action' => $dropdown['options'] ?? $dropdown['action'] - ]; - } - - return $routes; - } - - /** - * Extract all routes for searches - * - * @param string $areaId - * @param array $area - * @return array - */ - public static function routesForSearches(string $areaId, array $area): array - { - $searches = $area['searches'] ?? []; - $routes = []; - - foreach ($searches as $name => $params) { - - // create the full routing pattern - $pattern = 'search/' . $name; - - // load event - $routes[] = [ - 'pattern' => $pattern, - 'type' => 'search', - 'area' => $areaId, - 'action' => function () use ($params) { - $request = App::instance()->request(); - - return $params['query']($request->get('query')); - } - ]; - } - - return $routes; - } - - /** - * Extract all views from an area - * - * @param string $areaId - * @param array $area - * @return array - */ - public static function routesForViews(string $areaId, array $area): array - { - $views = $area['views'] ?? []; - $routes = []; - - foreach ($views as $view) { - $view['area'] = $areaId; - $view['type'] = 'view'; - $routes[] = $view; - } - - return $routes; - } - - /** - * Set the current language in multi-lang - * installations based on the session or the - * query language query parameter - * - * @return string|null - */ - public static function setLanguage(): ?string - { - $kirby = App::instance(); - - // language switcher - if (static::multilang()) { - $fallback = 'en'; - - if ($defaultLanguage = $kirby->defaultLanguage()) { - $fallback = $defaultLanguage->code(); - } - - $session = $kirby->session(); - $sessionLanguage = $session->get('panel.language', $fallback); - $language = $kirby->request()->get('language') ?? $sessionLanguage; - - // keep the language for the next visit - if ($language !== $sessionLanguage) { - $session->set('panel.language', $language); - } - - // activate the current language in Kirby - $kirby->setCurrentLanguage($language); - - return $language; - } - - return null; - } - - /** - * Set the currently active Panel translation - * based on the current user or config - * - * @return string - */ - public static function setTranslation(): string - { - $kirby = App::instance(); - - if ($user = $kirby->user()) { - // use the user language for the default translation - $translation = $user->language(); - } else { - // fall back to the language from the config - $translation = $kirby->panelLanguage(); - } - - $kirby->setCurrentTranslation($translation); - - return $translation; - } - - /** - * Creates an absolute Panel URL - * independent of the Panel slug config - * - * @param string|null $url - * @return string - */ - public static function url(?string $url = null): string - { - $slug = App::instance()->option('panel.slug', 'panel'); - - // only touch relative paths - if (Url::isAbsolute($url) === false) { - $path = trim($url, '/'); - - // add the panel slug prefix if it it's not - // included in the path yet - if (Str::startsWith($path, $slug . '/') === false) { - $path = $slug . '/' . $path; - } - - // create an absolute URL - $url = CmsUrl::to($path); - } - - return $url; - } + /** + * Normalize a panel area + * + * @param string $id + * @param array|string $area + * @return array + */ + public static function area(string $id, $area): array + { + $area['id'] = $id; + $area['label'] ??= $id; + $area['breadcrumb'] ??= []; + $area['breadcrumbLabel'] ??= $area['label']; + $area['title'] = $area['label']; + $area['menu'] ??= false; + $area['link'] ??= $id; + $area['search'] ??= null; + + return $area; + } + + /** + * Collect all registered areas + * + * @return array + */ + public static function areas(): array + { + $kirby = App::instance(); + $system = $kirby->system(); + $user = $kirby->user(); + $areas = $kirby->load()->areas(); + + // the system is not ready + if ($system->isOk() === false || $system->isInstalled() === false) { + return [ + 'installation' => static::area('installation', $areas['installation']), + ]; + } + + // not yet authenticated + if (!$user) { + return [ + 'login' => static::area('login', $areas['login']), + ]; + } + + unset($areas['installation'], $areas['login']); + + // Disable the language area for single-language installations + // This does not check for installed languages. Otherwise you'd + // not be able to add the first language through the view + if (!$kirby->option('languages')) { + unset($areas['languages']); + } + + $menu = $kirby->option('panel.menu', [ + 'site', + 'languages', + 'users', + 'system', + ]); + + $result = []; + + // add the sorted areas + foreach ($menu as $id) { + if ($area = ($areas[$id] ?? null)) { + $result[$id] = static::area($id, $area); + unset($areas[$id]); + } + } + + // add the remaining areas + foreach ($areas as $id => $area) { + $result[$id] = static::area($id, $area); + } + + return $result; + } + + /** + * Check for access permissions + * + * @param \Kirby\Cms\User|null $user + * @param string|null $areaId + * @return bool + */ + public static function firewall(?User $user = null, ?string $areaId = null): bool + { + // a user has to be logged in + if ($user === null) { + throw new PermissionException(['key' => 'access.panel']); + } + + // get all access permissions for the user role + $permissions = $user->role()->permissions()->toArray()['access']; + + // check for general panel access + if (($permissions['panel'] ?? true) !== true) { + throw new PermissionException(['key' => 'access.panel']); + } + + // don't check if the area is not defined + if (empty($areaId) === true) { + return true; + } + + // undefined area permissions means access + if (isset($permissions[$areaId]) === false) { + return true; + } + + // no access + if ($permissions[$areaId] !== true) { + throw new PermissionException(['key' => 'access.view']); + } + + return true; + } + + + /** + * Redirect to a Panel url + * + * @param string|null $path + * @param int $code + * @throws \Kirby\Panel\Redirect + * @return void + * @codeCoverageIgnore + */ + public static function go(?string $url = null, int $code = 302): void + { + throw new Redirect(static::url($url), $code); + } + + /** + * Check if the given user has access to the panel + * or to a given area + * + * @param \Kirby\Cms\User|null $user + * @param string|null $area + * @return bool + */ + public static function hasAccess(?User $user = null, string $area = null): bool + { + try { + static::firewall($user, $area); + return true; + } catch (Throwable $e) { + return false; + } + } + + /** + * Checks for a Fiber request + * via get parameters or headers + * + * @return bool + */ + public static function isFiberRequest(): bool + { + $request = App::instance()->request(); + + if ($request->method() === 'GET') { + return (bool)($request->get('_json') ?? $request->header('X-Fiber')); + } + + return false; + } + + /** + * Returns a JSON response + * for Fiber calls + * + * @param array $data + * @param int $code + * @return \Kirby\Http\Response + */ + public static function json(array $data, int $code = 200) + { + $request = App::instance()->request(); + + return Response::json($data, $code, $request->get('_pretty'), [ + 'X-Fiber' => 'true', + 'Cache-Control' => 'no-store, private' + ]); + } + + /** + * Checks for a multilanguage installation + * + * @return bool + */ + public static function multilang(): bool + { + // multilang setup check + $kirby = App::instance(); + return $kirby->option('languages') || $kirby->multilang(); + } + + /** + * Returns the referrer path if present + * + * @return string + */ + public static function referrer(): string + { + $request = App::instance()->request(); + + $referrer = $request->header('X-Fiber-Referrer') + ?? $request->get('_referrer') + ?? ''; + + return '/' . trim($referrer, '/'); + } + + /** + * Creates a Response object from the result of + * a Panel route call + * + * @params mixed $result + * @params array $options + * @return \Kirby\Http\Response + */ + public static function response($result, array $options = []) + { + // pass responses directly down to the Kirby router + if (is_a($result, 'Kirby\Http\Response') === true) { + return $result; + } + + // interpret missing/empty results as not found + if ($result === null || $result === false) { + $result = new NotFoundException('The data could not be found'); + + // interpret strings as errors + } elseif (is_string($result) === true) { + $result = new Exception($result); + } + + // handle different response types (view, dialog, ...) + switch ($options['type'] ?? null) { + case 'dialog': + return Dialog::response($result, $options); + case 'dropdown': + return Dropdown::response($result, $options); + case 'search': + return Search::response($result, $options); + default: + return View::response($result, $options); + } + } + + /** + * Router for the Panel views + * + * @param string $path + * @return \Kirby\Http\Response|false + */ + public static function router(string $path = null) + { + $kirby = App::instance(); + + if ($kirby->option('panel') === false) { + return null; + } + + // set the translation for Panel UI before + // gathering areas and routes, so that the + // `t()` helper can already be used + static::setTranslation(); + + // set the language in multi-lang installations + static::setLanguage(); + + $areas = static::areas(); + $routes = static::routes($areas); + + // create a micro-router for the Panel + return Router::execute($path, $method = $kirby->request()->method(), $routes, function ($route) use ($areas, $kirby, $method, $path) { + + // route needs authentication? + $auth = $route->attributes()['auth'] ?? true; + $areaId = $route->attributes()['area'] ?? null; + $type = $route->attributes()['type'] ?? 'view'; + $area = $areas[$areaId] ?? null; + + // call the route action to check the result + try { + // trigger hook + $route = $kirby->apply('panel.route:before', compact('route', 'path', 'method'), 'route'); + + // check for access before executing area routes + if ($auth !== false) { + static::firewall($kirby->user(), $areaId); + } + + $result = $route->action()->call($route, ...$route->arguments()); + } catch (Throwable $e) { + $result = $e; + } + + $response = static::response($result, [ + 'area' => $area, + 'areas' => $areas, + 'path' => $path, + 'type' => $type + ]); + + return $kirby->apply('panel.route:after', compact('route', 'path', 'method', 'response'), 'response'); + }); + } + + /** + * Extract the routes from the given array + * of active areas. + * + * @return array + */ + public static function routes(array $areas): array + { + $kirby = App::instance(); + + // the browser incompatibility + // warning is always needed + $routes = [ + [ + 'pattern' => 'browser', + 'auth' => false, + 'action' => fn () => new Response( + Tpl::load($kirby->root('kirby') . '/views/browser.php') + ), + ] + ]; + + // register all routes from areas + foreach ($areas as $areaId => $area) { + $routes = array_merge( + $routes, + static::routesForViews($areaId, $area), + static::routesForSearches($areaId, $area), + static::routesForDialogs($areaId, $area), + static::routesForDropdowns($areaId, $area), + ); + } + + // if the Panel is already installed and/or the + // user is authenticated, those areas won't be + // included, which is why we add redirect routes + // to main Panel view as fallbacks + $routes[] = [ + 'pattern' => [ + '/', + 'installation', + 'login', + ], + 'action' => fn () => Panel::go(Home::url()), + 'auth' => false + ]; + + // catch all route + $routes[] = [ + 'pattern' => '(:all)', + 'action' => fn () => 'The view could not be found' + ]; + + return $routes; + } + + /** + * Extract all routes from an area + * + * @param string $areaId + * @param array $area + * @return array + */ + public static function routesForDialogs(string $areaId, array $area): array + { + $dialogs = $area['dialogs'] ?? []; + $routes = []; + + foreach ($dialogs as $key => $dialog) { + + // create the full pattern with dialogs prefix + $pattern = 'dialogs/' . trim(($dialog['pattern'] ?? $key), '/'); + + // load event + $routes[] = [ + 'pattern' => $pattern, + 'type' => 'dialog', + 'area' => $areaId, + 'action' => $dialog['load'] ?? fn () => 'The load handler for your dialog is missing' + ]; + + // submit event + $routes[] = [ + 'pattern' => $pattern, + 'type' => 'dialog', + 'area' => $areaId, + 'method' => 'POST', + 'action' => $dialog['submit'] ?? fn () => 'Your dialog does not define a submit handler' + ]; + } + + return $routes; + } + + /** + * Extract all routes for dropdowns + * + * @param string $areaId + * @param array $area + * @return array + */ + public static function routesForDropdowns(string $areaId, array $area): array + { + $dropdowns = $area['dropdowns'] ?? []; + $routes = []; + + foreach ($dropdowns as $name => $dropdown) { + // Handle shortcuts for dropdowns. The name is the pattern + // and options are defined in a Closure + if (is_a($dropdown, 'Closure') === true) { + $dropdown = [ + 'pattern' => $name, + 'action' => $dropdown + ]; + } + + // create the full pattern with dropdowns prefix + $pattern = 'dropdowns/' . trim(($dropdown['pattern'] ?? $name), '/'); + + // load event + $routes[] = [ + 'pattern' => $pattern, + 'type' => 'dropdown', + 'area' => $areaId, + 'method' => 'GET|POST', + 'action' => $dropdown['options'] ?? $dropdown['action'] + ]; + } + + return $routes; + } + + /** + * Extract all routes for searches + * + * @param string $areaId + * @param array $area + * @return array + */ + public static function routesForSearches(string $areaId, array $area): array + { + $searches = $area['searches'] ?? []; + $routes = []; + + foreach ($searches as $name => $params) { + + // create the full routing pattern + $pattern = 'search/' . $name; + + // load event + $routes[] = [ + 'pattern' => $pattern, + 'type' => 'search', + 'area' => $areaId, + 'action' => function () use ($params) { + $request = App::instance()->request(); + + return $params['query']($request->get('query')); + } + ]; + } + + return $routes; + } + + /** + * Extract all views from an area + * + * @param string $areaId + * @param array $area + * @return array + */ + public static function routesForViews(string $areaId, array $area): array + { + $views = $area['views'] ?? []; + $routes = []; + + foreach ($views as $view) { + $view['area'] = $areaId; + $view['type'] = 'view'; + $routes[] = $view; + } + + return $routes; + } + + /** + * Set the current language in multi-lang + * installations based on the session or the + * query language query parameter + * + * @return string|null + */ + public static function setLanguage(): ?string + { + $kirby = App::instance(); + + // language switcher + if (static::multilang()) { + $fallback = 'en'; + + if ($defaultLanguage = $kirby->defaultLanguage()) { + $fallback = $defaultLanguage->code(); + } + + $session = $kirby->session(); + $sessionLanguage = $session->get('panel.language', $fallback); + $language = $kirby->request()->get('language') ?? $sessionLanguage; + + // keep the language for the next visit + if ($language !== $sessionLanguage) { + $session->set('panel.language', $language); + } + + // activate the current language in Kirby + $kirby->setCurrentLanguage($language); + + return $language; + } + + return null; + } + + /** + * Set the currently active Panel translation + * based on the current user or config + * + * @return string + */ + public static function setTranslation(): string + { + $kirby = App::instance(); + + if ($user = $kirby->user()) { + // use the user language for the default translation + $translation = $user->language(); + } else { + // fall back to the language from the config + $translation = $kirby->panelLanguage(); + } + + $kirby->setCurrentTranslation($translation); + + return $translation; + } + + /** + * Creates an absolute Panel URL + * independent of the Panel slug config + * + * @param string|null $url + * @return string + */ + public static function url(?string $url = null): string + { + $slug = App::instance()->option('panel.slug', 'panel'); + + // only touch relative paths + if (Url::isAbsolute($url) === false) { + $path = trim($url, '/'); + + // add the panel slug prefix if it it's not + // included in the path yet + if (Str::startsWith($path, $slug . '/') === false) { + $path = $slug . '/' . $path; + } + + // create an absolute URL + $url = CmsUrl::to($path); + } + + return $url; + } } diff --git a/kirby/src/Panel/Plugins.php b/kirby/src/Panel/Plugins.php index 1869099..768148b 100755 --- a/kirby/src/Panel/Plugins.php +++ b/kirby/src/Panel/Plugins.php @@ -19,91 +19,91 @@ use Kirby\Toolkit\Str; */ class Plugins { - /** - * Cache of all collected plugin files - * - * @var array - */ - public $files; + /** + * Cache of all collected plugin files + * + * @var array + */ + public $files; - /** - * Collects and returns the plugin files for all plugins - * - * @return array - */ - public function files(): array - { - if ($this->files !== null) { - return $this->files; - } + /** + * Collects and returns the plugin files for all plugins + * + * @return array + */ + public function files(): array + { + if ($this->files !== null) { + return $this->files; + } - $this->files = []; + $this->files = []; - foreach (App::instance()->plugins() as $plugin) { - $this->files[] = $plugin->root() . '/index.css'; - $this->files[] = $plugin->root() . '/index.js'; - } + foreach (App::instance()->plugins() as $plugin) { + $this->files[] = $plugin->root() . '/index.css'; + $this->files[] = $plugin->root() . '/index.js'; + } - return $this->files; - } + return $this->files; + } - /** - * Returns the last modification - * of the collected plugin files - * - * @return int - */ - public function modified(): int - { - $files = $this->files(); - $modified = [0]; + /** + * Returns the last modification + * of the collected plugin files + * + * @return int + */ + public function modified(): int + { + $files = $this->files(); + $modified = [0]; - foreach ($files as $file) { - $modified[] = F::modified($file); - } + foreach ($files as $file) { + $modified[] = F::modified($file); + } - return max($modified); - } + return max($modified); + } - /** - * Read the files from all plugins and concatenate them - * - * @param string $type - * @return string - */ - public function read(string $type): string - { - $dist = []; + /** + * Read the files from all plugins and concatenate them + * + * @param string $type + * @return string + */ + public function read(string $type): string + { + $dist = []; - foreach ($this->files() as $file) { - if (F::extension($file) === $type) { - if ($content = F::read($file)) { - if ($type === 'js') { - $content = trim($content); + foreach ($this->files() as $file) { + if (F::extension($file) === $type) { + if ($content = F::read($file)) { + if ($type === 'js') { + $content = trim($content); - // make sure that each plugin is ended correctly - if (Str::endsWith($content, ';') === false) { - $content .= ';'; - } - } + // make sure that each plugin is ended correctly + if (Str::endsWith($content, ';') === false) { + $content .= ';'; + } + } - $dist[] = $content; - } - } - } + $dist[] = $content; + } + } + } - return implode(PHP_EOL . PHP_EOL, $dist); - } + return implode(PHP_EOL . PHP_EOL, $dist); + } - /** - * Absolute url to the cache file - * This is used by the panel to link the plugins - * - * @param string $type - * @return string - */ - public function url(string $type): string - { - return App::instance()->url('media') . '/plugins/index.' . $type . '?' . $this->modified(); - } + /** + * Absolute url to the cache file + * This is used by the panel to link the plugins + * + * @param string $type + * @return string + */ + public function url(string $type): string + { + return App::instance()->url('media') . '/plugins/index.' . $type . '?' . $this->modified(); + } } diff --git a/kirby/src/Panel/Redirect.php b/kirby/src/Panel/Redirect.php index 929caad..0c63a2e 100755 --- a/kirby/src/Panel/Redirect.php +++ b/kirby/src/Panel/Redirect.php @@ -18,29 +18,29 @@ use Exception; */ class Redirect extends Exception { - /** - * Returns the HTTP code for the redirect - * - * @return int - */ - public function code(): int - { - $codes = [301, 302, 303, 307, 308]; + /** + * Returns the HTTP code for the redirect + * + * @return int + */ + public function code(): int + { + $codes = [301, 302, 303, 307, 308]; - if (in_array($this->getCode(), $codes) === true) { - return $this->getCode(); - } + if (in_array($this->getCode(), $codes) === true) { + return $this->getCode(); + } - return 302; - } + return 302; + } - /** - * Returns the URL for the redirect - * - * @return string - */ - public function location(): string - { - return $this->getMessage(); - } + /** + * Returns the URL for the redirect + * + * @return string + */ + public function location(): string + { + return $this->getMessage(); + } } diff --git a/kirby/src/Panel/Search.php b/kirby/src/Panel/Search.php index ab700ad..20e75ae 100755 --- a/kirby/src/Panel/Search.php +++ b/kirby/src/Panel/Search.php @@ -16,21 +16,21 @@ namespace Kirby\Panel; */ class Search extends Json { - protected static $key = '$search'; + protected static $key = '$search'; - /** - * @param mixed $data - * @param array $options - * @return \Kirby\Http\Response - */ - public static function response($data, array $options = []) - { - if (is_array($data) === true) { - $data = [ - 'results' => $data - ]; - } + /** + * @param mixed $data + * @param array $options + * @return \Kirby\Http\Response + */ + public static function response($data, array $options = []) + { + if (is_array($data) === true) { + $data = [ + 'results' => $data + ]; + } - return parent::response($data, $options); - } + return parent::response($data, $options); + } } diff --git a/kirby/src/Panel/Site.php b/kirby/src/Panel/Site.php index 8c21aef..92f5178 100755 --- a/kirby/src/Panel/Site.php +++ b/kirby/src/Panel/Site.php @@ -14,86 +14,86 @@ namespace Kirby\Panel; */ class Site extends Model { - /** - * @var \Kirby\Cms\Site - */ - protected $model; + /** + * @var \Kirby\Cms\Site + */ + protected $model; - /** - * Returns the setup for a dropdown option - * which is used in the changes dropdown - * for example. - * - * @return array - */ - public function dropdownOption(): array - { - return [ - 'icon' => 'home', - 'text' => $this->model->title()->value(), - ] + parent::dropdownOption(); - } + /** + * Returns the setup for a dropdown option + * which is used in the changes dropdown + * for example. + * + * @return array + */ + public function dropdownOption(): array + { + return [ + 'icon' => 'home', + 'text' => $this->model->title()->value(), + ] + parent::dropdownOption(); + } - /** - * Returns the image file object based on provided query - * - * @internal - * @param string|null $query - * @return \Kirby\Cms\File|\Kirby\Filesystem\Asset|null - */ - protected function imageSource(string $query = null) - { - if ($query === null) { - $query = 'site.image'; - } + /** + * Returns the image file object based on provided query + * + * @internal + * @param string|null $query + * @return \Kirby\Cms\File|\Kirby\Filesystem\Asset|null + */ + protected function imageSource(string $query = null) + { + if ($query === null) { + $query = 'site.image'; + } - return parent::imageSource($query); - } + return parent::imageSource($query); + } - /** - * Returns the full path without leading slash - * - * @return string - */ - public function path(): string - { - return 'site'; - } + /** + * Returns the full path without leading slash + * + * @return string + */ + public function path(): string + { + return 'site'; + } - /** - * Returns the data array for the - * view's component props - * - * @internal - * - * @return array - */ - public function props(): array - { - return array_merge(parent::props(), [ - 'blueprint' => 'site', - 'model' => [ - 'content' => $this->content(), - 'link' => $this->url(true), - 'previewUrl' => $this->model->previewUrl(), - 'title' => $this->model->title()->toString(), - ] - ]); - } + /** + * Returns the data array for the + * view's component props + * + * @internal + * + * @return array + */ + public function props(): array + { + return array_merge(parent::props(), [ + 'blueprint' => 'site', + 'model' => [ + 'content' => $this->content(), + 'link' => $this->url(true), + 'previewUrl' => $this->model->previewUrl(), + 'title' => $this->model->title()->toString(), + ] + ]); + } - /** - * Returns the data array for - * this model's Panel view - * - * @internal - * - * @return array - */ - public function view(): array - { - return [ - 'component' => 'k-site-view', - 'props' => $this->props() - ]; - } + /** + * Returns the data array for + * this model's Panel view + * + * @internal + * + * @return array + */ + public function view(): array + { + return [ + 'component' => 'k-site-view', + 'props' => $this->props() + ]; + } } diff --git a/kirby/src/Panel/User.php b/kirby/src/Panel/User.php index e839675..69275ef 100755 --- a/kirby/src/Panel/User.php +++ b/kirby/src/Panel/User.php @@ -17,258 +17,258 @@ use Kirby\Toolkit\I18n; */ class User extends Model { - /** - * @var \Kirby\Cms\User - */ - protected $model; + /** + * @var \Kirby\Cms\User + */ + protected $model; - /** - * Breadcrumb array - * - * @return array - */ - public function breadcrumb(): array - { - return [ - [ - 'label' => $this->model->username(), - 'link' => $this->url(true), - ] - ]; - } + /** + * Breadcrumb array + * + * @return array + */ + public function breadcrumb(): array + { + return [ + [ + 'label' => $this->model->username(), + 'link' => $this->url(true), + ] + ]; + } - /** - * Provides options for the user dropdown - * - * @param array $options - * @return array - */ - public function dropdown(array $options = []): array - { - $account = $this->model->isLoggedIn(); - $i18nPrefix = $account ? 'account' : 'user'; - $permissions = $this->options(['preview']); - $url = $this->url(true); - $result = []; + /** + * Provides options for the user dropdown + * + * @param array $options + * @return array + */ + public function dropdown(array $options = []): array + { + $account = $this->model->isLoggedIn(); + $i18nPrefix = $account ? 'account' : 'user'; + $permissions = $this->options(['preview']); + $url = $this->url(true); + $result = []; - $result[] = [ - 'dialog' => $url . '/changeName', - 'icon' => 'title', - 'text' => I18n::translate($i18nPrefix . '.changeName'), - 'disabled' => $this->isDisabledDropdownOption('changeName', $options, $permissions) - ]; + $result[] = [ + 'dialog' => $url . '/changeName', + 'icon' => 'title', + 'text' => I18n::translate($i18nPrefix . '.changeName'), + 'disabled' => $this->isDisabledDropdownOption('changeName', $options, $permissions) + ]; - $result[] = '-'; + $result[] = '-'; - $result[] = [ - 'dialog' => $url . '/changeEmail', - 'icon' => 'email', - 'text' => I18n::translate('user.changeEmail'), - 'disabled' => $this->isDisabledDropdownOption('changeEmail', $options, $permissions) - ]; + $result[] = [ + 'dialog' => $url . '/changeEmail', + 'icon' => 'email', + 'text' => I18n::translate('user.changeEmail'), + 'disabled' => $this->isDisabledDropdownOption('changeEmail', $options, $permissions) + ]; - $result[] = [ - 'dialog' => $url . '/changeRole', - 'icon' => 'bolt', - 'text' => I18n::translate('user.changeRole'), - 'disabled' => $this->isDisabledDropdownOption('changeRole', $options, $permissions) - ]; + $result[] = [ + 'dialog' => $url . '/changeRole', + 'icon' => 'bolt', + 'text' => I18n::translate('user.changeRole'), + 'disabled' => $this->isDisabledDropdownOption('changeRole', $options, $permissions) + ]; - $result[] = [ - 'dialog' => $url . '/changePassword', - 'icon' => 'key', - 'text' => I18n::translate('user.changePassword'), - 'disabled' => $this->isDisabledDropdownOption('changePassword', $options, $permissions) - ]; + $result[] = [ + 'dialog' => $url . '/changePassword', + 'icon' => 'key', + 'text' => I18n::translate('user.changePassword'), + 'disabled' => $this->isDisabledDropdownOption('changePassword', $options, $permissions) + ]; - $result[] = [ - 'dialog' => $url . '/changeLanguage', - 'icon' => 'globe', - 'text' => I18n::translate('user.changeLanguage'), - 'disabled' => $this->isDisabledDropdownOption('changeLanguage', $options, $permissions) - ]; + $result[] = [ + 'dialog' => $url . '/changeLanguage', + 'icon' => 'globe', + 'text' => I18n::translate('user.changeLanguage'), + 'disabled' => $this->isDisabledDropdownOption('changeLanguage', $options, $permissions) + ]; - $result[] = '-'; + $result[] = '-'; - $result[] = [ - 'dialog' => $url . '/delete', - 'icon' => 'trash', - 'text' => I18n::translate($i18nPrefix . '.delete'), - 'disabled' => $this->isDisabledDropdownOption('delete', $options, $permissions) - ]; + $result[] = [ + 'dialog' => $url . '/delete', + 'icon' => 'trash', + 'text' => I18n::translate($i18nPrefix . '.delete'), + 'disabled' => $this->isDisabledDropdownOption('delete', $options, $permissions) + ]; - return $result; - } + return $result; + } - /** - * Returns the setup for a dropdown option - * which is used in the changes dropdown - * for example. - * - * @return array - */ - public function dropdownOption(): array - { - return [ - 'icon' => 'user', - 'text' => $this->model->username(), - ] + parent::dropdownOption(); - } + /** + * Returns the setup for a dropdown option + * which is used in the changes dropdown + * for example. + * + * @return array + */ + public function dropdownOption(): array + { + return [ + 'icon' => 'user', + 'text' => $this->model->username(), + ] + parent::dropdownOption(); + } - /** - * @return string|null - */ - public function home(): ?string - { - if ($home = ($this->model->blueprint()->home() ?? null)) { - $url = $this->model->toString($home); - return Url::to($url); - } + /** + * @return string|null + */ + public function home(): ?string + { + if ($home = ($this->model->blueprint()->home() ?? null)) { + $url = $this->model->toString($home); + return Url::to($url); + } - return Panel::url('site'); - } + return Panel::url('site'); + } - /** - * Default settings for the user's Panel image - * - * @return array - */ - protected function imageDefaults(): array - { - return array_merge(parent::imageDefaults(), [ - 'back' => 'black', - 'icon' => 'user', - 'ratio' => '1/1', - ]); - } + /** + * Default settings for the user's Panel image + * + * @return array + */ + protected function imageDefaults(): array + { + return array_merge(parent::imageDefaults(), [ + 'back' => 'black', + 'icon' => 'user', + 'ratio' => '1/1', + ]); + } - /** - * Returns the image file object based on provided query - * - * @param string|null $query - * @return \Kirby\Cms\File|\Kirby\Filesystem\Asset|null - */ - protected function imageSource(string $query = null) - { - if ($query === null) { - return $this->model->avatar(); - } + /** + * Returns the image file object based on provided query + * + * @param string|null $query + * @return \Kirby\Cms\File|\Kirby\Filesystem\Asset|null + */ + protected function imageSource(string $query = null) + { + if ($query === null) { + return $this->model->avatar(); + } - return parent::imageSource($query); - } + return parent::imageSource($query); + } - /** - * Returns the full path without leading slash - * - * @return string - */ - public function path(): string - { - // path to your own account - if ($this->model->isLoggedIn() === true) { - return 'account'; - } + /** + * Returns the full path without leading slash + * + * @return string + */ + public function path(): string + { + // path to your own account + if ($this->model->isLoggedIn() === true) { + return 'account'; + } - return 'users/' . $this->model->id(); - } + return 'users/' . $this->model->id(); + } - /** - * Returns prepared data for the panel user picker - * - * @param array|null $params - * @return array - */ - public function pickerData(array $params = null): array - { - $params['text'] ??= '{{ user.username }}'; + /** + * Returns prepared data for the panel user picker + * + * @param array|null $params + * @return array + */ + public function pickerData(array $params = null): array + { + $params['text'] ??= '{{ user.username }}'; - return array_merge(parent::pickerData($params), [ - 'email' => $this->model->email(), - 'username' => $this->model->username(), - ]); - } + return array_merge(parent::pickerData($params), [ + 'email' => $this->model->email(), + 'username' => $this->model->username(), + ]); + } - /** - * Returns navigation array with - * previous and next user - * - * @internal - * - * @return array - */ - public function prevNext(): array - { - $user = $this->model; + /** + * Returns navigation array with + * previous and next user + * + * @internal + * + * @return array + */ + public function prevNext(): array + { + $user = $this->model; - return [ - 'next' => fn () => $this->toPrevNextLink($user->next(), 'username'), - 'prev' => fn () => $this->toPrevNextLink($user->prev(), 'username') - ]; - } + return [ + 'next' => fn () => $this->toPrevNextLink($user->next(), 'username'), + 'prev' => fn () => $this->toPrevNextLink($user->prev(), 'username') + ]; + } - /** - * Returns the data array for the - * view's component props - * - * @internal - * - * @return array - */ - public function props(): array - { - $user = $this->model; - $account = $user->isLoggedIn(); - $avatar = $user->avatar(); + /** + * Returns the data array for the + * view's component props + * + * @internal + * + * @return array + */ + public function props(): array + { + $user = $this->model; + $account = $user->isLoggedIn(); + $avatar = $user->avatar(); - return array_merge( - parent::props(), - $account ? [] : $this->prevNext(), - [ - 'blueprint' => $this->model->role()->name(), - 'model' => [ - 'account' => $account, - 'avatar' => $avatar ? $avatar->url() : null, - 'content' => $this->content(), - 'email' => $user->email(), - 'id' => $user->id(), - 'language' => $this->translation()->name(), - 'link' => $this->url(true), - 'name' => $user->name()->toString(), - 'role' => $user->role()->title(), - 'username' => $user->username(), - ] - ] - ); - } + return array_merge( + parent::props(), + $account ? [] : $this->prevNext(), + [ + 'blueprint' => $this->model->role()->name(), + 'model' => [ + 'account' => $account, + 'avatar' => $avatar ? $avatar->url() : null, + 'content' => $this->content(), + 'email' => $user->email(), + 'id' => $user->id(), + 'language' => $this->translation()->name(), + 'link' => $this->url(true), + 'name' => $user->name()->toString(), + 'role' => $user->role()->title(), + 'username' => $user->username(), + ] + ] + ); + } - /** - * Returns the Translation object - * for the selected Panel language - * - * @return \Kirby\Cms\Translation - */ - public function translation() - { - $kirby = $this->model->kirby(); - $lang = $this->model->language(); - return $kirby->translation($lang); - } + /** + * Returns the Translation object + * for the selected Panel language + * + * @return \Kirby\Cms\Translation + */ + public function translation() + { + $kirby = $this->model->kirby(); + $lang = $this->model->language(); + return $kirby->translation($lang); + } - /** - * Returns the data array for - * this model's Panel view - * - * @internal - * - * @return array - */ - public function view(): array - { - return [ - 'breadcrumb' => $this->breadcrumb(), - 'component' => 'k-user-view', - 'props' => $this->props(), - 'title' => $this->model->username(), - ]; - } + /** + * Returns the data array for + * this model's Panel view + * + * @internal + * + * @return array + */ + public function view(): array + { + return [ + 'breadcrumb' => $this->breadcrumb(), + 'component' => 'k-user-view', + 'props' => $this->props(), + 'title' => $this->model->username(), + ]; + } } diff --git a/kirby/src/Panel/View.php b/kirby/src/Panel/View.php index da5fa1f..6d24094 100755 --- a/kirby/src/Panel/View.php +++ b/kirby/src/Panel/View.php @@ -22,435 +22,435 @@ use Kirby\Toolkit\Str; */ class View { - /** - * Filters the data array based on headers or - * query parameters. Requests can return only - * certain data fields that way or globals can - * be injected on demand. - * - * @param array $data - * @return array - */ - public static function apply(array $data): array - { - $request = App::instance()->request(); - $only = $request->header('X-Fiber-Only') ?? $request->get('_only'); + /** + * Filters the data array based on headers or + * query parameters. Requests can return only + * certain data fields that way or globals can + * be injected on demand. + * + * @param array $data + * @return array + */ + public static function apply(array $data): array + { + $request = App::instance()->request(); + $only = $request->header('X-Fiber-Only') ?? $request->get('_only'); - if (empty($only) === false) { - return static::applyOnly($data, $only); - } + if (empty($only) === false) { + return static::applyOnly($data, $only); + } - $globals = $request->header('X-Fiber-Globals') ?? $request->get('_globals'); + $globals = $request->header('X-Fiber-Globals') ?? $request->get('_globals'); - if (empty($globals) === false) { - return static::applyGlobals($data, $globals); - } + if (empty($globals) === false) { + return static::applyGlobals($data, $globals); + } - return A::apply($data); - } + return A::apply($data); + } - /** - * Checks if globals should be included in a JSON Fiber request. They are normally - * only loaded with the full document request, but sometimes need to be updated. - * - * A global request can be activated with the `X-Fiber-Globals` header or the - * `_globals` query parameter. - * - * @param array $data - * @param string|null $globals - * @return array - */ - public static function applyGlobals(array $data, ?string $globals = null): array - { - // split globals string into an array of fields - $globalKeys = Str::split($globals, ','); + /** + * Checks if globals should be included in a JSON Fiber request. They are normally + * only loaded with the full document request, but sometimes need to be updated. + * + * A global request can be activated with the `X-Fiber-Globals` header or the + * `_globals` query parameter. + * + * @param array $data + * @param string|null $globals + * @return array + */ + public static function applyGlobals(array $data, ?string $globals = null): array + { + // split globals string into an array of fields + $globalKeys = Str::split($globals, ','); - // add requested globals - if (empty($globalKeys) === true) { - return $data; - } + // add requested globals + if (empty($globalKeys) === true) { + return $data; + } - $globals = static::globals(); + $globals = static::globals(); - foreach ($globalKeys as $globalKey) { - if (isset($globals[$globalKey]) === true) { - $data[$globalKey] = $globals[$globalKey]; - } - } + foreach ($globalKeys as $globalKey) { + if (isset($globals[$globalKey]) === true) { + $data[$globalKey] = $globals[$globalKey]; + } + } - // merge with shared data - return A::apply($data); - } + // merge with shared data + return A::apply($data); + } - /** - * Checks if the request should only return a limited - * set of data. This can be activated with the `X-Fiber-Only` - * header or the `_only` query parameter in a request. - * - * Such requests can fetch shared data or globals. - * Globals will be loaded on demand. - * - * @param array $data - * @param string|null $only - * @return array - */ - public static function applyOnly(array $data, ?string $only = null): array - { - // split include string into an array of fields - $onlyKeys = Str::split($only, ','); + /** + * Checks if the request should only return a limited + * set of data. This can be activated with the `X-Fiber-Only` + * header or the `_only` query parameter in a request. + * + * Such requests can fetch shared data or globals. + * Globals will be loaded on demand. + * + * @param array $data + * @param string|null $only + * @return array + */ + public static function applyOnly(array $data, ?string $only = null): array + { + // split include string into an array of fields + $onlyKeys = Str::split($only, ','); - // if a full request is made, return all data - if (empty($onlyKeys) === true) { - return $data; - } + // if a full request is made, return all data + if (empty($onlyKeys) === true) { + return $data; + } - // otherwise filter data based on - // dot notation, e.g. `$props.tab.columns` - $result = []; + // otherwise filter data based on + // dot notation, e.g. `$props.tab.columns` + $result = []; - // check if globals are requested and need to be merged - if (Str::contains($only, '$')) { - $data = array_merge_recursive(static::globals(), $data); - } + // check if globals are requested and need to be merged + if (Str::contains($only, '$')) { + $data = array_merge_recursive(static::globals(), $data); + } - // make sure the data is already resolved to make - // nested data fetching work - $data = A::apply($data); + // make sure the data is already resolved to make + // nested data fetching work + $data = A::apply($data); - // build a new array with all requested data - foreach ($onlyKeys as $onlyKey) { - $result[$onlyKey] = A::get($data, $onlyKey); - } + // build a new array with all requested data + foreach ($onlyKeys as $onlyKey) { + $result[$onlyKey] = A::get($data, $onlyKey); + } - // Nest dotted keys in array but ignore $translation - return A::nest($result, [ - '$translation' - ]); - } + // Nest dotted keys in array but ignore $translation + return A::nest($result, [ + '$translation' + ]); + } - /** - * Creates the shared data array for the individual views - * The full shared data is always sent on every JSON and - * full document request unless the `X-Fiber-Only` header or - * the `_only` query parameter is set. - * - * @param array $view - * @param array $options - * @return array - */ - public static function data(array $view = [], array $options = []): array - { - $kirby = App::instance(); + /** + * Creates the shared data array for the individual views + * The full shared data is always sent on every JSON and + * full document request unless the `X-Fiber-Only` header or + * the `_only` query parameter is set. + * + * @param array $view + * @param array $options + * @return array + */ + public static function data(array $view = [], array $options = []): array + { + $kirby = App::instance(); - // multilang setup check - $multilang = Panel::multilang(); + // multilang setup check + $multilang = Panel::multilang(); - // get the authenticated user - $user = $kirby->user(); + // get the authenticated user + $user = $kirby->user(); - // user permissions - $permissions = $user ? $user->role()->permissions()->toArray() : []; + // user permissions + $permissions = $user ? $user->role()->permissions()->toArray() : []; - // current content language - $language = $kirby->language(); + // current content language + $language = $kirby->language(); - // shared data for all requests - return [ - '$direction' => function () use ($kirby, $multilang, $language, $user) { - if ($multilang === true && $language && $user) { - $isDefault = $language->direction() === $kirby->defaultLanguage()->direction(); - $isFromUser = $language->code() === $user->language(); + // shared data for all requests + return [ + '$direction' => function () use ($kirby, $multilang, $language, $user) { + if ($multilang === true && $language && $user) { + $isDefault = $language->direction() === $kirby->defaultLanguage()->direction(); + $isFromUser = $language->code() === $user->language(); - if ($isDefault === false && $isFromUser === false) { - return $language->direction(); - } - } - }, - '$language' => function () use ($kirby, $multilang, $language) { - if ($multilang === true && $language) { - return [ - 'code' => $language->code(), - 'default' => $language->isDefault(), - 'direction' => $language->direction(), - 'name' => $language->name(), - 'rules' => $language->rules(), - ]; - } - }, - '$languages' => function () use ($kirby, $multilang): array { - if ($multilang === true) { - return $kirby->languages()->values(fn ($language) => [ - 'code' => $language->code(), - 'default' => $language->isDefault(), - 'direction' => $language->direction(), - 'name' => $language->name(), - 'rules' => $language->rules(), - ]); - } + if ($isDefault === false && $isFromUser === false) { + return $language->direction(); + } + } + }, + '$language' => function () use ($kirby, $multilang, $language) { + if ($multilang === true && $language) { + return [ + 'code' => $language->code(), + 'default' => $language->isDefault(), + 'direction' => $language->direction(), + 'name' => $language->name(), + 'rules' => $language->rules(), + ]; + } + }, + '$languages' => function () use ($kirby, $multilang): array { + if ($multilang === true) { + return $kirby->languages()->values(fn ($language) => [ + 'code' => $language->code(), + 'default' => $language->isDefault(), + 'direction' => $language->direction(), + 'name' => $language->name(), + 'rules' => $language->rules(), + ]); + } - return []; - }, - '$menu' => function () use ($options, $permissions) { - return static::menu($options['areas'] ?? [], $permissions, $options['area']['id'] ?? null); - }, - '$permissions' => $permissions, - '$license' => (bool)$kirby->system()->license(), - '$multilang' => $multilang, - '$searches' => static::searches($options['areas'] ?? [], $permissions), - '$url' => $kirby->request()->url()->toString(), - '$user' => function () use ($user) { - if ($user) { - return [ - 'email' => $user->email(), - 'id' => $user->id(), - 'language' => $user->language(), - 'role' => $user->role()->id(), - 'username' => $user->username(), - ]; - } + return []; + }, + '$menu' => function () use ($options, $permissions) { + return static::menu($options['areas'] ?? [], $permissions, $options['area']['id'] ?? null); + }, + '$permissions' => $permissions, + '$license' => (bool)$kirby->system()->license(), + '$multilang' => $multilang, + '$searches' => static::searches($options['areas'] ?? [], $permissions), + '$url' => $kirby->request()->url()->toString(), + '$user' => function () use ($user) { + if ($user) { + return [ + 'email' => $user->email(), + 'id' => $user->id(), + 'language' => $user->language(), + 'role' => $user->role()->id(), + 'username' => $user->username(), + ]; + } - return null; - }, - '$view' => function () use ($kirby, $options, $view) { - $defaults = [ - 'breadcrumb' => [], - 'code' => 200, - 'path' => Str::after($kirby->path(), '/'), - 'timestamp' => (int)(microtime(true) * 1000), - 'props' => [], - 'search' => $kirby->option('panel.search.type', 'pages') - ]; + return null; + }, + '$view' => function () use ($kirby, $options, $view) { + $defaults = [ + 'breadcrumb' => [], + 'code' => 200, + 'path' => Str::after($kirby->path(), '/'), + 'timestamp' => (int)(microtime(true) * 1000), + 'props' => [], + 'search' => $kirby->option('panel.search.type', 'pages') + ]; - $view = array_replace_recursive($defaults, $options['area'] ?? [], $view); + $view = array_replace_recursive($defaults, $options['area'] ?? [], $view); - // make sure that views and dialogs are gone - unset( - $view['dialogs'], - $view['dropdowns'], - $view['searches'], - $view['views'] - ); + // make sure that views and dialogs are gone + unset( + $view['dialogs'], + $view['dropdowns'], + $view['searches'], + $view['views'] + ); - // resolve all callbacks in the view array - return A::apply($view); - } - ]; - } + // resolve all callbacks in the view array + return A::apply($view); + } + ]; + } - /** - * Renders the error view with provided message - * - * @param string $message - * @param int $code - * @return array - */ - public static function error(string $message, int $code = 404) - { - return [ - 'code' => $code, - 'component' => 'k-error-view', - 'error' => $message, - 'props' => [ - 'error' => $message, - 'layout' => Panel::hasAccess(App::instance()->user()) ? 'inside' : 'outside' - ], - 'title' => 'Error' - ]; - } + /** + * Renders the error view with provided message + * + * @param string $message + * @param int $code + * @return array + */ + public static function error(string $message, int $code = 404) + { + return [ + 'code' => $code, + 'component' => 'k-error-view', + 'error' => $message, + 'props' => [ + 'error' => $message, + 'layout' => Panel::hasAccess(App::instance()->user()) ? 'inside' : 'outside' + ], + 'title' => 'Error' + ]; + } - /** - * Creates global data for the Panel. - * This will be injected in the full Panel - * view via the script tag. Global data - * is only requested once on the first page load. - * It can be loaded partially later if needed, - * but is otherwise not included in Fiber calls. - * - * @return array - */ - public static function globals(): array - { - $kirby = App::instance(); + /** + * Creates global data for the Panel. + * This will be injected in the full Panel + * view via the script tag. Global data + * is only requested once on the first page load. + * It can be loaded partially later if needed, + * but is otherwise not included in Fiber calls. + * + * @return array + */ + public static function globals(): array + { + $kirby = App::instance(); - return [ - '$config' => function () use ($kirby) { - return [ - 'debug' => $kirby->option('debug', false), - 'kirbytext' => $kirby->option('panel.kirbytext', true), - 'search' => [ - 'limit' => $kirby->option('panel.search.limit', 10), - 'type' => $kirby->option('panel.search.type', 'pages') - ], - 'translation' => $kirby->option('panel.language', 'en'), - ]; - }, - '$system' => function () use ($kirby) { - $locales = []; + return [ + '$config' => function () use ($kirby) { + return [ + 'debug' => $kirby->option('debug', false), + 'kirbytext' => $kirby->option('panel.kirbytext', true), + 'search' => [ + 'limit' => $kirby->option('panel.search.limit', 10), + 'type' => $kirby->option('panel.search.type', 'pages') + ], + 'translation' => $kirby->option('panel.language', 'en'), + ]; + }, + '$system' => function () use ($kirby) { + $locales = []; - foreach ($kirby->translations() as $translation) { - $locales[$translation->code()] = $translation->locale(); - } + foreach ($kirby->translations() as $translation) { + $locales[$translation->code()] = $translation->locale(); + } - return [ - 'ascii' => Str::$ascii, - 'csrf' => $kirby->auth()->csrfFromSession(), - 'isLocal' => $kirby->system()->isLocal(), - 'locales' => $locales, - 'slugs' => Str::$language, - 'title' => $kirby->site()->title()->or('Kirby Panel')->toString() - ]; - }, - '$translation' => function () use ($kirby) { - if ($user = $kirby->user()) { - $translation = $kirby->translation($user->language()); - } else { - $translation = $kirby->translation($kirby->panelLanguage()); - } + return [ + 'ascii' => Str::$ascii, + 'csrf' => $kirby->auth()->csrfFromSession(), + 'isLocal' => $kirby->system()->isLocal(), + 'locales' => $locales, + 'slugs' => Str::$language, + 'title' => $kirby->site()->title()->or('Kirby Panel')->toString() + ]; + }, + '$translation' => function () use ($kirby) { + if ($user = $kirby->user()) { + $translation = $kirby->translation($user->language()); + } else { + $translation = $kirby->translation($kirby->panelLanguage()); + } - return [ - 'code' => $translation->code(), - 'data' => $translation->dataWithFallback(), - 'direction' => $translation->direction(), - 'name' => $translation->name(), - ]; - }, - '$urls' => fn () => [ - 'api' => $kirby->url('api'), - 'site' => $kirby->url('index') - ] - ]; - } + return [ + 'code' => $translation->code(), + 'data' => $translation->dataWithFallback(), + 'direction' => $translation->direction(), + 'name' => $translation->name(), + ]; + }, + '$urls' => fn () => [ + 'api' => $kirby->url('api'), + 'site' => $kirby->url('index') + ] + ]; + } - /** - * Creates the menu for the topbar - * - * @param array $areas - * @param array $permissions - * @param string|null $current - * @return array - */ - public static function menu(?array $areas = [], ?array $permissions = [], ?string $current = null): array - { - $menu = []; + /** + * Creates the menu for the topbar + * + * @param array $areas + * @param array $permissions + * @param string|null $current + * @return array + */ + public static function menu(?array $areas = [], ?array $permissions = [], ?string $current = null): array + { + $menu = []; - // areas - foreach ($areas as $areaId => $area) { - $access = $permissions['access'][$areaId] ?? true; + // areas + foreach ($areas as $areaId => $area) { + $access = $permissions['access'][$areaId] ?? true; - // areas without access permissions get skipped entirely - if ($access === false) { - continue; - } + // areas without access permissions get skipped entirely + if ($access === false) { + continue; + } - // fetch custom menu settings from the area definition - $menuSetting = $area['menu'] ?? false; + // fetch custom menu settings from the area definition + $menuSetting = $area['menu'] ?? false; - // menu settings can be a callback that can return true, false or disabled - if (is_a($menuSetting, 'Closure') === true) { - $menuSetting = $menuSetting($areas, $permissions, $current); - } + // menu settings can be a callback that can return true, false or disabled + if (is_a($menuSetting, 'Closure') === true) { + $menuSetting = $menuSetting($areas, $permissions, $current); + } - // false will remove the area entirely just like with - // disabled permissions - if ($menuSetting === false) { - continue; - } + // false will remove the area entirely just like with + // disabled permissions + if ($menuSetting === false) { + continue; + } - $menu[] = [ - 'current' => $areaId === $current, - 'disabled' => $menuSetting === 'disabled', - 'icon' => $area['icon'], - 'id' => $areaId, - 'link' => $area['link'], - 'text' => $area['label'], - ]; - } + $menu[] = [ + 'current' => $areaId === $current, + 'disabled' => $menuSetting === 'disabled', + 'icon' => $area['icon'], + 'id' => $areaId, + 'link' => $area['link'], + 'text' => $area['label'], + ]; + } - $menu[] = '-'; - $menu[] = [ - 'current' => $current === 'account', - 'icon' => 'account', - 'id' => 'account', - 'link' => 'account', - 'disabled' => ($permissions['access']['account'] ?? false) === false, - 'text' => I18n::translate('view.account'), - ]; - $menu[] = '-'; + $menu[] = '-'; + $menu[] = [ + 'current' => $current === 'account', + 'icon' => 'account', + 'id' => 'account', + 'link' => 'account', + 'disabled' => ($permissions['access']['account'] ?? false) === false, + 'text' => I18n::translate('view.account'), + ]; + $menu[] = '-'; - // logout - $menu[] = [ - 'icon' => 'logout', - 'id' => 'logout', - 'link' => 'logout', - 'text' => I18n::translate('logout') - ]; - return $menu; - } + // logout + $menu[] = [ + 'icon' => 'logout', + 'id' => 'logout', + 'link' => 'logout', + 'text' => I18n::translate('logout') + ]; + return $menu; + } - /** - * Renders the main panel view either as - * JSON response or full HTML document based - * on the request header or query params - * - * @param mixed $data - * @param array $options - * @return \Kirby\Http\Response - */ - public static function response($data, array $options = []) - { - // handle redirects - if (is_a($data, 'Kirby\Panel\Redirect') === true) { - return Response::redirect($data->location(), $data->code()); + /** + * Renders the main panel view either as + * JSON response or full HTML document based + * on the request header or query params + * + * @param mixed $data + * @param array $options + * @return \Kirby\Http\Response + */ + public static function response($data, array $options = []) + { + // handle redirects + if (is_a($data, 'Kirby\Panel\Redirect') === true) { + return Response::redirect($data->location(), $data->code()); - // handle Kirby exceptions - } elseif (is_a($data, 'Kirby\Exception\Exception') === true) { - $data = static::error($data->getMessage(), $data->getHttpCode()); + // handle Kirby exceptions + } elseif (is_a($data, 'Kirby\Exception\Exception') === true) { + $data = static::error($data->getMessage(), $data->getHttpCode()); - // handle regular exceptions - } elseif (is_a($data, 'Throwable') === true) { - $data = static::error($data->getMessage(), 500); + // handle regular exceptions + } elseif (is_a($data, 'Throwable') === true) { + $data = static::error($data->getMessage(), 500); - // only expect arrays from here on - } elseif (is_array($data) === false) { - $data = static::error('Invalid Panel response', 500); - } + // only expect arrays from here on + } elseif (is_array($data) === false) { + $data = static::error('Invalid Panel response', 500); + } - // get all data for the request - $fiber = static::data($data, $options); + // get all data for the request + $fiber = static::data($data, $options); - // if requested, send $fiber data as JSON - if (Panel::isFiberRequest() === true) { + // if requested, send $fiber data as JSON + if (Panel::isFiberRequest() === true) { - // filter data, if only or globals headers or - // query parameters are set - $fiber = static::apply($fiber); + // filter data, if only or globals headers or + // query parameters are set + $fiber = static::apply($fiber); - return Panel::json($fiber, $fiber['$view']['code'] ?? 200); - } + return Panel::json($fiber, $fiber['$view']['code'] ?? 200); + } - // load globals for the full document response - $globals = static::globals(); + // load globals for the full document response + $globals = static::globals(); - // resolve and merge globals and shared data - $fiber = array_merge_recursive(A::apply($globals), A::apply($fiber)); + // resolve and merge globals and shared data + $fiber = array_merge_recursive(A::apply($globals), A::apply($fiber)); - // render the full HTML document - return Document::response($fiber); - } + // render the full HTML document + return Document::response($fiber); + } - public static function searches(array $areas, array $permissions) - { - $searches = []; + public static function searches(array $areas, array $permissions) + { + $searches = []; - foreach ($areas as $area) { - foreach ($area['searches'] ?? [] as $id => $params) { - $searches[$id] = [ - 'icon' => $params['icon'] ?? 'search', - 'label' => $params['label'] ?? Str::ucfirst($id), - 'id' => $id - ]; - } - } - return $searches; - } + foreach ($areas as $area) { + foreach ($area['searches'] ?? [] as $id => $params) { + $searches[$id] = [ + 'icon' => $params['icon'] ?? 'search', + 'label' => $params['label'] ?? Str::ucfirst($id), + 'id' => $id + ]; + } + } + return $searches; + } } diff --git a/kirby/src/Parsley/Element.php b/kirby/src/Parsley/Element.php index 519b442..292a55a 100755 --- a/kirby/src/Parsley/Element.php +++ b/kirby/src/Parsley/Element.php @@ -21,179 +21,179 @@ use Kirby\Toolkit\Str; */ class Element { - /** - * @var array - */ - protected $marks; + /** + * @var array + */ + protected $marks; - /** - * @var \DOMElement - */ - protected $node; + /** + * @var \DOMElement + */ + protected $node; - /** - * @param \DOMElement $node - * @param array $marks - */ - public function __construct(DOMElement $node, array $marks = []) - { - $this->marks = $marks; - $this->node = $node; - } + /** + * @param \DOMElement $node + * @param array $marks + */ + public function __construct(DOMElement $node, array $marks = []) + { + $this->marks = $marks; + $this->node = $node; + } - /** - * The returns the attribute value or - * the given fallback if the attribute does not exist - * - * @param string $attr - * @param string|null $fallback - * @return string|null - */ - public function attr(string $attr, string $fallback = null): ?string - { - if ($this->node->hasAttribute($attr)) { - return $this->node->getAttribute($attr) ?? $fallback; - } + /** + * The returns the attribute value or + * the given fallback if the attribute does not exist + * + * @param string $attr + * @param string|null $fallback + * @return string|null + */ + public function attr(string $attr, string $fallback = null): ?string + { + if ($this->node->hasAttribute($attr)) { + return $this->node->getAttribute($attr) ?? $fallback; + } - return $fallback; - } + return $fallback; + } - /** - * Returns a list of all child elements - * - * @return \DOMNodeList - */ - public function children(): DOMNodeList - { - return $this->node->childNodes; - } + /** + * Returns a list of all child elements + * + * @return \DOMNodeList + */ + public function children(): DOMNodeList + { + return $this->node->childNodes; + } - /** - * Returns an array with all class names - * - * @return array - */ - public function classList(): array - { - return Str::split($this->className(), ' '); - } + /** + * Returns an array with all class names + * + * @return array + */ + public function classList(): array + { + return Str::split($this->className(), ' '); + } - /** - * Returns the value of the class attribute - * - * @return string|null - */ - public function className(): ?string - { - return $this->attr('class'); - } + /** + * Returns the value of the class attribute + * + * @return string|null + */ + public function className(): ?string + { + return $this->attr('class'); + } - /** - * Returns the original dom element - * - * @return \DOMElement - */ - public function element() - { - return $this->node; - } + /** + * Returns the original dom element + * + * @return \DOMElement + */ + public function element() + { + return $this->node; + } - /** - * Returns an array with all nested elements - * that could be found for the given query - * - * @param string $query - * @return array - */ - public function filter(string $query): array - { - $result = []; + /** + * Returns an array with all nested elements + * that could be found for the given query + * + * @param string $query + * @return array + */ + public function filter(string $query): array + { + $result = []; - if ($queryResult = $this->query($query)) { - foreach ($queryResult as $node) { - $result[] = new static($node); - } - } + if ($queryResult = $this->query($query)) { + foreach ($queryResult as $node) { + $result[] = new static($node); + } + } - return $result; - } + return $result; + } - /** - * Tries to find a single nested element by - * query and otherwise returns null - * - * @param string $query - * @return \Kirby\Parsley\Element|null - */ - public function find(string $query) - { - if ($result = $this->query($query)[0]) { - return new static($result); - } + /** + * Tries to find a single nested element by + * query and otherwise returns null + * + * @param string $query + * @return \Kirby\Parsley\Element|null + */ + public function find(string $query) + { + if ($result = $this->query($query)[0]) { + return new static($result); + } - return null; - } + return null; + } - /** - * Returns the inner HTML of the element - * - * @param array|null $marks List of allowed marks - * @return string - */ - public function innerHtml(array $marks = null): string - { - return (new Inline($this->node, $marks ?? $this->marks))->innerHtml(); - } + /** + * Returns the inner HTML of the element + * + * @param array|null $marks List of allowed marks + * @return string + */ + public function innerHtml(array $marks = null): string + { + return (new Inline($this->node, $marks ?? $this->marks))->innerHtml(); + } - /** - * Returns the contents as plain text - * - * @return string - */ - public function innerText(): string - { - return trim($this->node->textContent); - } + /** + * Returns the contents as plain text + * + * @return string + */ + public function innerText(): string + { + return trim($this->node->textContent); + } - /** - * Returns the full HTML for the element - * - * @param array|null $marks - * @return string - */ - public function outerHtml(array $marks = null): string - { - return $this->node->ownerDocument->saveHtml($this->node); - } + /** + * Returns the full HTML for the element + * + * @param array|null $marks + * @return string + */ + public function outerHtml(array $marks = null): string + { + return $this->node->ownerDocument->saveHtml($this->node); + } - /** - * Searches nested elements - * - * @param string $query - * @return DOMNodeList|null - */ - public function query(string $query) - { - return (new DOMXPath($this->node->ownerDocument))->query($query, $this->node); - } + /** + * Searches nested elements + * + * @param string $query + * @return DOMNodeList|null + */ + public function query(string $query) + { + return (new DOMXPath($this->node->ownerDocument))->query($query, $this->node); + } - /** - * Removes the element from the DOM - * - * @return void - */ - public function remove() - { - $this->node->parentNode->removeChild($this->node); - } + /** + * Removes the element from the DOM + * + * @return void + */ + public function remove() + { + $this->node->parentNode->removeChild($this->node); + } - /** - * Returns the name of the element - * - * @return string - */ - public function tagName(): string - { - return $this->node->tagName; - } + /** + * Returns the name of the element + * + * @return string + */ + public function tagName(): string + { + return $this->node->tagName; + } } diff --git a/kirby/src/Parsley/Inline.php b/kirby/src/Parsley/Inline.php index 3c58d14..3b3ede1 100755 --- a/kirby/src/Parsley/Inline.php +++ b/kirby/src/Parsley/Inline.php @@ -20,156 +20,156 @@ use Kirby\Toolkit\Html; */ class Inline { - /** - * @var string - */ - protected $html = ''; + /** + * @var string + */ + protected $html = ''; - /** - * @var array - */ - protected $marks = []; + /** + * @var array + */ + protected $marks = []; - /** - * @param \DOMNode $node - * @param array $marks - */ - public function __construct(DOMNode $node, array $marks = []) - { - $this->createMarkRules($marks); - $this->html = trim(static::parseNode($node, $this->marks)); - } + /** + * @param \DOMNode $node + * @param array $marks + */ + public function __construct(DOMNode $node, array $marks = []) + { + $this->createMarkRules($marks); + $this->html = trim(static::parseNode($node, $this->marks)); + } - /** - * Loads all mark rules - * - * @param array $marks - * @return array - */ - protected function createMarkRules(array $marks) - { - foreach ($marks as $mark) { - $this->marks[$mark['tag']] = $mark; - } + /** + * Loads all mark rules + * + * @param array $marks + * @return array + */ + protected function createMarkRules(array $marks) + { + foreach ($marks as $mark) { + $this->marks[$mark['tag']] = $mark; + } - return $this->marks; - } + return $this->marks; + } - /** - * Get all allowed attributes for a DOMNode - * as clean array - * - * @param DOMNode $node - * @param array $marks - * @return array - */ - public static function parseAttrs(DOMNode $node, array $marks = []): array - { - $attrs = []; - $mark = $marks[$node->tagName]; - $defaults = $mark['defaults'] ?? []; + /** + * Get all allowed attributes for a DOMNode + * as clean array + * + * @param DOMNode $node + * @param array $marks + * @return array + */ + public static function parseAttrs(DOMNode $node, array $marks = []): array + { + $attrs = []; + $mark = $marks[$node->tagName]; + $defaults = $mark['defaults'] ?? []; - foreach ($mark['attrs'] ?? [] as $attr) { - if ($node->hasAttribute($attr)) { - $attrs[$attr] = $node->getAttribute($attr); - } else { - $attrs[$attr] = $defaults[$attr] ?? null; - } - } + foreach ($mark['attrs'] ?? [] as $attr) { + if ($node->hasAttribute($attr)) { + $attrs[$attr] = $node->getAttribute($attr); + } else { + $attrs[$attr] = $defaults[$attr] ?? null; + } + } - return $attrs; - } + return $attrs; + } - /** - * Parses all children and creates clean HTML - * for each of them. - * - * @param \DOMNodeList $children - * @param array $marks - * @return string - */ - public static function parseChildren(DOMNodeList $children, array $marks): string - { - $html = ''; - foreach ($children as $child) { - $html .= static::parseNode($child, $marks); - } - return $html; - } + /** + * Parses all children and creates clean HTML + * for each of them. + * + * @param \DOMNodeList $children + * @param array $marks + * @return string + */ + public static function parseChildren(DOMNodeList $children, array $marks): string + { + $html = ''; + foreach ($children as $child) { + $html .= static::parseNode($child, $marks); + } + return $html; + } - /** - * Go through all child elements and create - * clean inner HTML for them - * - * @param DOMNode $node - * @return string|null - */ - public static function parseInnerHtml(DOMNode $node, array $marks = []): ?string - { - $html = static::parseChildren($node->childNodes, $marks); + /** + * Go through all child elements and create + * clean inner HTML for them + * + * @param DOMNode $node + * @return string|null + */ + public static function parseInnerHtml(DOMNode $node, array $marks = []): ?string + { + $html = static::parseChildren($node->childNodes, $marks); - // trim the inner HTML for paragraphs - if ($node->tagName === 'p') { - $html = trim($html); - } + // trim the inner HTML for paragraphs + if ($node->tagName === 'p') { + $html = trim($html); + } - // return null for empty inner HTML - if ($html === '') { - return null; - } + // return null for empty inner HTML + if ($html === '') { + return null; + } - return $html; - } + return $html; + } - /** - * Converts the given node to clean HTML - * - * @param \DOMNode $node - * @param array $marks - * @return string|null - */ - public static function parseNode(DOMNode $node, array $marks = []): ?string - { - if (is_a($node, 'DOMText') === true) { - return Html::encode($node->textContent); - } + /** + * Converts the given node to clean HTML + * + * @param \DOMNode $node + * @param array $marks + * @return string|null + */ + public static function parseNode(DOMNode $node, array $marks = []): ?string + { + if (is_a($node, 'DOMText') === true) { + return Html::encode($node->textContent); + } - // ignore comments - if (is_a($node, 'DOMComment') === true) { - return null; - } + // ignore comments + if (is_a($node, 'DOMComment') === true) { + return null; + } - // unknown marks - if (array_key_exists($node->tagName, $marks) === false) { - return static::parseChildren($node->childNodes, $marks); - } + // unknown marks + if (array_key_exists($node->tagName, $marks) === false) { + return static::parseChildren($node->childNodes, $marks); + } - // collect all allowed attributes - $attrs = static::parseAttrs($node, $marks); + // collect all allowed attributes + $attrs = static::parseAttrs($node, $marks); - // close self-closing elements - if (Html::isVoid($node->tagName) === true) { - return '<' . $node->tagName . Html::attr($attrs, null, ' ') . ' />'; - } + // close self-closing elements + if (Html::isVoid($node->tagName) === true) { + return '<' . $node->tagName . Html::attr($attrs, null, ' ') . ' />'; + } - $innerHtml = static::parseInnerHtml($node, $marks); + $innerHtml = static::parseInnerHtml($node, $marks); - // skip empty paragraphs - if ($innerHtml === null && $node->tagName === 'p') { - return null; - } + // skip empty paragraphs + if ($innerHtml === null && $node->tagName === 'p') { + return null; + } - // create the outer html for the element - return '<' . $node->tagName . Html::attr($attrs, null, ' ') . '>' . $innerHtml . 'tagName . '>'; - } + // create the outer html for the element + return '<' . $node->tagName . Html::attr($attrs, null, ' ') . '>' . $innerHtml . 'tagName . '>'; + } - /** - * Returns the HTML contents of the element - * - * @return string - */ - public function innerHtml(): string - { - return $this->html; - } + /** + * Returns the HTML contents of the element + * + * @return string + */ + public function innerHtml(): string + { + return $this->html; + } } diff --git a/kirby/src/Parsley/Parsley.php b/kirby/src/Parsley/Parsley.php index 62a1e50..d99d45e 100755 --- a/kirby/src/Parsley/Parsley.php +++ b/kirby/src/Parsley/Parsley.php @@ -20,334 +20,334 @@ use Kirby\Toolkit\Dom; */ class Parsley { - /** - * @var array - */ - protected $blocks = []; + /** + * @var array + */ + protected $blocks = []; - /** - * @var \DOMDocument - */ - protected $doc; + /** + * @var \DOMDocument + */ + protected $doc; - /** - * @var \Kirby\Toolkit\Dom - */ - protected $dom; + /** + * @var \Kirby\Toolkit\Dom + */ + protected $dom; - /** - * @var array - */ - protected $inline = []; + /** + * @var array + */ + protected $inline = []; - /** - * @var array - */ - protected $marks = []; + /** + * @var array + */ + protected $marks = []; - /** - * @var array - */ - protected $nodes = []; + /** + * @var array + */ + protected $nodes = []; - /** - * @var \Kirby\Parsley\Schema - */ - protected $schema; + /** + * @var \Kirby\Parsley\Schema + */ + protected $schema; - /** - * @var array - */ - protected $skip = []; + /** + * @var array + */ + protected $skip = []; - /** - * @var bool - */ - public static $useXmlExtension = true; + /** + * @var bool + */ + public static $useXmlExtension = true; - /** - * @param string $html - * @param \Kirby\Parsley\Schema|null $schema - */ - public function __construct(string $html, Schema $schema = null) - { - // fail gracefully if the XML extension is not installed - // or should be skipped - if ($this->useXmlExtension() === false) { - $this->blocks[] = [ - 'type' => 'markdown', - 'content' => [ - 'text' => $html, - ] - ]; - return; - } + /** + * @param string $html + * @param \Kirby\Parsley\Schema|null $schema + */ + public function __construct(string $html, Schema $schema = null) + { + // fail gracefully if the XML extension is not installed + // or should be skipped + if ($this->useXmlExtension() === false) { + $this->blocks[] = [ + 'type' => 'markdown', + 'content' => [ + 'text' => $html, + ] + ]; + return; + } - if (!preg_match('//', $html)) { - $html = '
' . $html . '
'; - } + if (!preg_match('//', $html)) { + $html = '
' . $html . '
'; + } - $this->dom = new Dom($html); - $this->doc = $this->dom->document(); - $this->schema = $schema ?? new Plain(); - $this->skip = $this->schema->skip(); - $this->marks = $this->schema->marks(); - $this->inline = []; + $this->dom = new Dom($html); + $this->doc = $this->dom->document(); + $this->schema = $schema ?? new Plain(); + $this->skip = $this->schema->skip(); + $this->marks = $this->schema->marks(); + $this->inline = []; - // load all allowed nodes from the schema - $this->createNodeRules($this->schema->nodes()); + // load all allowed nodes from the schema + $this->createNodeRules($this->schema->nodes()); - // start parsing at the top level and go through - // all children of the document - foreach ($this->doc->childNodes as $childNode) { - $this->parseNode($childNode); - } + // start parsing at the top level and go through + // all children of the document + foreach ($this->doc->childNodes as $childNode) { + $this->parseNode($childNode); + } - // needs to be called at last to fetch remaining - // inline elements after parsing has ended - $this->endInlineBlock(); - } + // needs to be called at last to fetch remaining + // inline elements after parsing has ended + $this->endInlineBlock(); + } - /** - * Returns all detected blocks - * - * @return array - */ - public function blocks(): array - { - return $this->blocks; - } + /** + * Returns all detected blocks + * + * @return array + */ + public function blocks(): array + { + return $this->blocks; + } - /** - * Load all node rules from the schema - * - * @param array $nodes - * @return array - */ - public function createNodeRules(array $nodes): array - { - foreach ($nodes as $node) { - $this->nodes[$node['tag']] = $node; - } + /** + * Load all node rules from the schema + * + * @param array $nodes + * @return array + */ + public function createNodeRules(array $nodes): array + { + foreach ($nodes as $node) { + $this->nodes[$node['tag']] = $node; + } - return $this->nodes; - } + return $this->nodes; + } - /** - * Checks if the given element contains - * any other block level elements - * - * @param \DOMNode $element - * @return bool - */ - public function containsBlock(DOMNode $element): bool - { - if ($element->hasChildNodes() === false) { - return false; - } + /** + * Checks if the given element contains + * any other block level elements + * + * @param \DOMNode $element + * @return bool + */ + public function containsBlock(DOMNode $element): bool + { + if ($element->hasChildNodes() === false) { + return false; + } - foreach ($element->childNodes as $childNode) { - if ($this->isBlock($childNode) === true || $this->containsBlock($childNode)) { - return true; - } - } + foreach ($element->childNodes as $childNode) { + if ($this->isBlock($childNode) === true || $this->containsBlock($childNode)) { + return true; + } + } - return false; - } + return false; + } - /** - * Takes all inline elements in the inline cache - * and combines them in a final block. The block - * will either be merged with the previous block - * if the type matches, or will be appended. - * - * The inline cache will be reset afterwards - * - * @return void - */ - public function endInlineBlock() - { - if (empty($this->inline) === true) { - return; - } + /** + * Takes all inline elements in the inline cache + * and combines them in a final block. The block + * will either be merged with the previous block + * if the type matches, or will be appended. + * + * The inline cache will be reset afterwards + * + * @return void + */ + public function endInlineBlock() + { + if (empty($this->inline) === true) { + return; + } - $html = []; + $html = []; - foreach ($this->inline as $inline) { - $node = new Inline($inline, $this->marks); - $html[] = $node->innerHTML(); - } + foreach ($this->inline as $inline) { + $node = new Inline($inline, $this->marks); + $html[] = $node->innerHTML(); + } - $innerHTML = implode(' ', $html); + $innerHTML = implode(' ', $html); - if ($fallback = $this->fallback($innerHTML)) { - $this->mergeOrAppend($fallback); - } + if ($fallback = $this->fallback($innerHTML)) { + $this->mergeOrAppend($fallback); + } - $this->inline = []; - } + $this->inline = []; + } - /** - * Creates a fallback block type for the given - * element. The element can either be a element object - * or a simple HTML/plain text string - * - * @param \Kirby\Parsley\Element|string $element - * @return array|null - */ - public function fallback($element): ?array - { - if ($fallback = $this->schema->fallback($element)) { - return $fallback; - } + /** + * Creates a fallback block type for the given + * element. The element can either be a element object + * or a simple HTML/plain text string + * + * @param \Kirby\Parsley\Element|string $element + * @return array|null + */ + public function fallback($element): ?array + { + if ($fallback = $this->schema->fallback($element)) { + return $fallback; + } - return null; - } + return null; + } - /** - * Checks if the given DOMNode is a block element - * - * @param DOMNode $element - * @return bool - */ - public function isBlock(DOMNode $element): bool - { - if (is_a($element, 'DOMElement') === false) { - return false; - } + /** + * Checks if the given DOMNode is a block element + * + * @param DOMNode $element + * @return bool + */ + public function isBlock(DOMNode $element): bool + { + if (is_a($element, 'DOMElement') === false) { + return false; + } - return array_key_exists($element->tagName, $this->nodes) === true; - } + return array_key_exists($element->tagName, $this->nodes) === true; + } - /** - * Checks if the given DOMNode is an inline element - * - * @param \DOMNode $element - * @return bool - */ - public function isInline(DOMNode $element): bool - { - if (is_a($element, 'DOMText') === true) { - return true; - } + /** + * Checks if the given DOMNode is an inline element + * + * @param \DOMNode $element + * @return bool + */ + public function isInline(DOMNode $element): bool + { + if (is_a($element, 'DOMText') === true) { + return true; + } - if (is_a($element, 'DOMElement') === true) { - // all spans will be treated as inline elements - if ($element->tagName === 'span') { - return true; - } + if (is_a($element, 'DOMElement') === true) { + // all spans will be treated as inline elements + if ($element->tagName === 'span') { + return true; + } - if ($this->containsBlock($element) === true) { - return false; - } + if ($this->containsBlock($element) === true) { + return false; + } - if ($element->tagName === 'p') { - return false; - } + if ($element->tagName === 'p') { + return false; + } - $marks = array_column($this->marks, 'tag'); - return in_array($element->tagName, $marks); - } + $marks = array_column($this->marks, 'tag'); + return in_array($element->tagName, $marks); + } - return false; - } + return false; + } - /** - * @param array $block - * @return void - */ - public function mergeOrAppend(array $block) - { - $lastIndex = count($this->blocks) - 1; - $lastItem = $this->blocks[$lastIndex] ?? null; + /** + * @param array $block + * @return void + */ + public function mergeOrAppend(array $block) + { + $lastIndex = count($this->blocks) - 1; + $lastItem = $this->blocks[$lastIndex] ?? null; - // merge with previous block - if ($block['type'] === 'text' && $lastItem && $lastItem['type'] === 'text') { - $this->blocks[$lastIndex]['content']['text'] .= ' ' . $block['content']['text']; + // merge with previous block + if ($block['type'] === 'text' && $lastItem && $lastItem['type'] === 'text') { + $this->blocks[$lastIndex]['content']['text'] .= ' ' . $block['content']['text']; - // append - } else { - $this->blocks[] = $block; - } - } + // append + } else { + $this->blocks[] = $block; + } + } - /** - * Parses the given DOM node and tries to - * convert it to a block or a list of blocks - * - * @param \DOMNode $element - * @return void - */ - public function parseNode(DOMNode $element): bool - { - $skip = ['DOMComment', 'DOMDocumentType']; + /** + * Parses the given DOM node and tries to + * convert it to a block or a list of blocks + * + * @param \DOMNode $element + * @return void + */ + public function parseNode(DOMNode $element): bool + { + $skip = ['DOMComment', 'DOMDocumentType']; - // unwanted element types - if (in_array(get_class($element), $skip) === true) { - return false; - } + // unwanted element types + if (in_array(get_class($element), $skip) === true) { + return false; + } - // inline context - if ($this->isInline($element)) { - $this->inline[] = $element; - return true; - } else { - $this->endInlineBlock(); - } + // inline context + if ($this->isInline($element)) { + $this->inline[] = $element; + return true; + } else { + $this->endInlineBlock(); + } - // known block nodes - if ($this->isBlock($element) === true) { - if ($parser = ($this->nodes[$element->tagName]['parse'] ?? null)) { - if ($result = $parser(new Element($element, $this->marks))) { - $this->blocks[] = $result; - } - } - return true; - } + // known block nodes + if ($this->isBlock($element) === true) { + if ($parser = ($this->nodes[$element->tagName]['parse'] ?? null)) { + if ($result = $parser(new Element($element, $this->marks))) { + $this->blocks[] = $result; + } + } + return true; + } - // has only unknown children (div, etc.) - if ($this->containsBlock($element) === false) { - if (in_array($element->tagName, $this->skip) === true) { - return false; - } + // has only unknown children (div, etc.) + if ($this->containsBlock($element) === false) { + if (in_array($element->tagName, $this->skip) === true) { + return false; + } - $wrappers = [ - 'body', - 'head', - 'html', - ]; + $wrappers = [ + 'body', + 'head', + 'html', + ]; - // wrapper elements should never be converted - // to a simple fallback block. Their children - // have to be parsed individually. - if (in_array($element->tagName, $wrappers) === false) { - $node = new Element($element, $this->marks); + // wrapper elements should never be converted + // to a simple fallback block. Their children + // have to be parsed individually. + if (in_array($element->tagName, $wrappers) === false) { + $node = new Element($element, $this->marks); - if ($block = $this->fallback($node)) { - $this->mergeOrAppend($block); - } + if ($block = $this->fallback($node)) { + $this->mergeOrAppend($block); + } - return true; - } - } + return true; + } + } - // parse all children - foreach ($element->childNodes as $childNode) { - $this->parseNode($childNode); - } + // parse all children + foreach ($element->childNodes as $childNode) { + $this->parseNode($childNode); + } - return true; - } + return true; + } - /** - * @return bool - */ - public function useXmlExtension(): bool - { - if (static::$useXmlExtension !== true) { - return false; - } + /** + * @return bool + */ + public function useXmlExtension(): bool + { + if (static::$useXmlExtension !== true) { + return false; + } - return Dom::isSupported(); - } + return Dom::isSupported(); + } } diff --git a/kirby/src/Parsley/Schema.php b/kirby/src/Parsley/Schema.php index 4f90b31..b9c1232 100755 --- a/kirby/src/Parsley/Schema.php +++ b/kirby/src/Parsley/Schema.php @@ -15,48 +15,48 @@ namespace Kirby\Parsley; */ class Schema { - /** - * Returns the fallback block when no - * other block type can be detected - * - * @param \Kirby\Parsley\Element|string $element - * @return array|null - */ - public function fallback($element): ?array - { - return null; - } + /** + * Returns the fallback block when no + * other block type can be detected + * + * @param \Kirby\Parsley\Element|string $element + * @return array|null + */ + public function fallback($element): ?array + { + return null; + } - /** - * Returns a list of allowed inline marks - * and their parsing rules - * - * @return array - */ - public function marks(): array - { - return []; - } + /** + * Returns a list of allowed inline marks + * and their parsing rules + * + * @return array + */ + public function marks(): array + { + return []; + } - /** - * Returns a list of allowed nodes and - * their parsing rules - * - * @return array - */ - public function nodes(): array - { - return []; - } + /** + * Returns a list of allowed nodes and + * their parsing rules + * + * @return array + */ + public function nodes(): array + { + return []; + } - /** - * Returns a list of all elements that should be - * skipped and not be parsed at all - * - * @return array - */ - public function skip(): array - { - return []; - } + /** + * Returns a list of all elements that should be + * skipped and not be parsed at all + * + * @return array + */ + public function skip(): array + { + return []; + } } diff --git a/kirby/src/Parsley/Schema/Blocks.php b/kirby/src/Parsley/Schema/Blocks.php index 676d43c..d825a0e 100755 --- a/kirby/src/Parsley/Schema/Blocks.php +++ b/kirby/src/Parsley/Schema/Blocks.php @@ -19,419 +19,419 @@ use Kirby\Toolkit\Str; */ class Blocks extends Plain { - /** - * @param \Kirby\Parsley\Element $node - * @return array - */ - public function blockquote(Element $node): array - { - $citation = null; - $text = []; + /** + * @param \Kirby\Parsley\Element $node + * @return array + */ + public function blockquote(Element $node): array + { + $citation = null; + $text = []; - // get all the text for the quote - foreach ($node->children() as $child) { - if (is_a($child, 'DOMText') === true) { - $text[] = trim($child->textContent); - } - if (is_a($child, 'DOMElement') === true && $child->tagName !== 'footer') { - $text[] = (new Element($child))->innerHTML($this->marks()); - } - } + // get all the text for the quote + foreach ($node->children() as $child) { + if (is_a($child, 'DOMText') === true) { + $text[] = trim($child->textContent); + } + if (is_a($child, 'DOMElement') === true && $child->tagName !== 'footer') { + $text[] = (new Element($child))->innerHTML($this->marks()); + } + } - // filter empty blocks and separate text blocks with breaks - $text = implode('', array_filter($text)); + // filter empty blocks and separate text blocks with breaks + $text = implode('', array_filter($text)); - // get the citation from the footer - if ($footer = $node->find('footer')) { - $citation = $footer->innerHTML($this->marks()); - } + // get the citation from the footer + if ($footer = $node->find('footer')) { + $citation = $footer->innerHTML($this->marks()); + } - return [ - 'content' => [ - 'citation' => $citation, - 'text' => $text - ], - 'type' => 'quote', - ]; - } + return [ + 'content' => [ + 'citation' => $citation, + 'text' => $text + ], + 'type' => 'quote', + ]; + } - /** - * Creates the fallback block type - * if no other block can be found - * - * @param \Kirby\Parsley\Element|string $element - * @return array|null - */ - public function fallback($element): ?array - { - if (is_a($element, Element::class) === true) { - $html = $element->innerHtml(); + /** + * Creates the fallback block type + * if no other block can be found + * + * @param \Kirby\Parsley\Element|string $element + * @return array|null + */ + public function fallback($element): ?array + { + if (is_a($element, Element::class) === true) { + $html = $element->innerHtml(); - // wrap the inner HTML in a p tag if it doesn't - // contain one yet. - if (Str::contains($html, '

') === false) { - $html = '

' . $html . '

'; - } - } elseif (is_string($element) === true) { - $html = trim($element); + // wrap the inner HTML in a p tag if it doesn't + // contain one yet. + if (Str::contains($html, '

') === false) { + $html = '

' . $html . '

'; + } + } elseif (is_string($element) === true) { + $html = trim($element); - if (Str::length($html) === 0) { - return null; - } + if (Str::length($html) === 0) { + return null; + } - $html = '

' . $html . '

'; - } else { - return null; - } + $html = '

' . $html . '

'; + } else { + return null; + } - return [ - 'content' => [ - 'text' => $html, - ], - 'type' => 'text', - ]; - } + return [ + 'content' => [ + 'text' => $html, + ], + 'type' => 'text', + ]; + } - /** - * Converts a heading element to a heading block - * - * @param \Kirby\Parsley\Element $node - * @return array - */ - public function heading(Element $node): array - { - $content = [ - 'level' => strtolower($node->tagName()), - 'text' => $node->innerHTML() - ]; + /** + * Converts a heading element to a heading block + * + * @param \Kirby\Parsley\Element $node + * @return array + */ + public function heading(Element $node): array + { + $content = [ + 'level' => strtolower($node->tagName()), + 'text' => $node->innerHTML() + ]; - if ($id = $node->attr('id')) { - $content['id'] = $id; - } + if ($id = $node->attr('id')) { + $content['id'] = $id; + } - ksort($content); + ksort($content); - return [ - 'content' => $content, - 'type' => 'heading', - ]; - } + return [ + 'content' => $content, + 'type' => 'heading', + ]; + } - /** - * @param \Kirby\Parsley\Element $node - * @return array - */ - public function iframe(Element $node): array - { - $caption = null; - $src = $node->attr('src'); + /** + * @param \Kirby\Parsley\Element $node + * @return array + */ + public function iframe(Element $node): array + { + $caption = null; + $src = $node->attr('src'); - if ($figcaption = $node->find('ancestor::figure[1]//figcaption')) { - $caption = $figcaption->innerHTML($this->marks()); + if ($figcaption = $node->find('ancestor::figure[1]//figcaption')) { + $caption = $figcaption->innerHTML($this->marks()); - // avoid parsing the caption twice - $figcaption->remove(); - } + // avoid parsing the caption twice + $figcaption->remove(); + } - // reverse engineer video URLs - if (preg_match('!player.vimeo.com\/video\/([0-9]+)!i', $src, $array) === 1) { - $src = 'https://vimeo.com/' . $array[1]; - } elseif (preg_match('!youtube.com\/embed\/([a-zA-Z0-9_-]+)!', $src, $array) === 1) { - $src = 'https://youtube.com/watch?v=' . $array[1]; - } elseif (preg_match('!youtube-nocookie.com\/embed\/([a-zA-Z0-9_-]+)!', $src, $array) === 1) { - $src = 'https://youtube.com/watch?v=' . $array[1]; - } else { - $src = false; - } + // reverse engineer video URLs + if (preg_match('!player.vimeo.com\/video\/([0-9]+)!i', $src, $array) === 1) { + $src = 'https://vimeo.com/' . $array[1]; + } elseif (preg_match('!youtube.com\/embed\/([a-zA-Z0-9_-]+)!', $src, $array) === 1) { + $src = 'https://youtube.com/watch?v=' . $array[1]; + } elseif (preg_match('!youtube-nocookie.com\/embed\/([a-zA-Z0-9_-]+)!', $src, $array) === 1) { + $src = 'https://youtube.com/watch?v=' . $array[1]; + } else { + $src = false; + } - // correct video URL - if ($src) { - return [ - 'content' => [ - 'caption' => $caption, - 'url' => $src - ], - 'type' => 'video', - ]; - } + // correct video URL + if ($src) { + return [ + 'content' => [ + 'caption' => $caption, + 'url' => $src + ], + 'type' => 'video', + ]; + } - return [ - 'content' => [ - 'text' => $node->outerHTML() - ], - 'type' => 'markdown', - ]; - } + return [ + 'content' => [ + 'text' => $node->outerHTML() + ], + 'type' => 'markdown', + ]; + } - /** - * @param \Kirby\Parsley\Element $node - * @return array - */ - public function img(Element $node): array - { - $caption = null; - $link = null; + /** + * @param \Kirby\Parsley\Element $node + * @return array + */ + public function img(Element $node): array + { + $caption = null; + $link = null; - if ($figcaption = $node->find('ancestor::figure[1]//figcaption')) { - $caption = $figcaption->innerHTML($this->marks()); + if ($figcaption = $node->find('ancestor::figure[1]//figcaption')) { + $caption = $figcaption->innerHTML($this->marks()); - // avoid parsing the caption twice - $figcaption->remove(); - } + // avoid parsing the caption twice + $figcaption->remove(); + } - if ($a = $node->find('ancestor::a')) { - $link = $a->attr('href'); - } + if ($a = $node->find('ancestor::a')) { + $link = $a->attr('href'); + } - return [ - 'content' => [ - 'alt' => $node->attr('alt'), - 'caption' => $caption, - 'link' => $link, - 'location' => 'web', - 'src' => $node->attr('src'), - ], - 'type' => 'image', - ]; - } + return [ + 'content' => [ + 'alt' => $node->attr('alt'), + 'caption' => $caption, + 'link' => $link, + 'location' => 'web', + 'src' => $node->attr('src'), + ], + 'type' => 'image', + ]; + } - /** - * Converts a list element to HTML - * - * @param \Kirby\Parsley\Element $node - * @return string - */ - public function list(Element $node): string - { - $html = []; + /** + * Converts a list element to HTML + * + * @param \Kirby\Parsley\Element $node + * @return string + */ + public function list(Element $node): string + { + $html = []; - foreach ($node->filter('li') as $li) { - $innerHtml = ''; + foreach ($node->filter('li') as $li) { + $innerHtml = ''; - foreach ($li->children() as $child) { - if (is_a($child, 'DOMText') === true) { - $innerHtml .= $child->textContent; - } elseif (is_a($child, 'DOMElement') === true) { - $child = new Element($child); + foreach ($li->children() as $child) { + if (is_a($child, 'DOMText') === true) { + $innerHtml .= $child->textContent; + } elseif (is_a($child, 'DOMElement') === true) { + $child = new Element($child); - if (in_array($child->tagName(), ['ul', 'ol']) === true) { - $innerHtml .= $this->list($child); - } else { - $innerHtml .= $child->innerHTML($this->marks()); - } - } - } + if (in_array($child->tagName(), ['ul', 'ol']) === true) { + $innerHtml .= $this->list($child); + } else { + $innerHtml .= $child->innerHTML($this->marks()); + } + } + } - $html[] = '
  • ' . trim($innerHtml) . '
  • '; - } + $html[] = '
  • ' . trim($innerHtml) . '
  • '; + } - return '<' . $node->tagName() . '>' . implode($html) . 'tagName() . '>'; - } + return '<' . $node->tagName() . '>' . implode($html) . 'tagName() . '>'; + } - /** - * Returns a list of allowed inline marks - * and their parsing rules - * - * @return array - */ - public function marks(): array - { - return [ - [ - 'tag' => 'a', - 'attrs' => ['href', 'rel', 'target', 'title'], - 'defaults' => [ - 'rel' => 'noopener noreferrer' - ] - ], - [ - 'tag' => 'abbr', - ], - [ - 'tag' => 'b' - ], - [ - 'tag' => 'br', - ], - [ - 'tag' => 'code' - ], - [ - 'tag' => 'del', - ], - [ - 'tag' => 'em', - ], - [ - 'tag' => 'i', - ], - [ - 'tag' => 'p', - ], - [ - 'tag' => 'strike', - ], - [ - 'tag' => 'sub', - ], - [ - 'tag' => 'sup', - ], - [ - 'tag' => 'strong', - ], - [ - 'tag' => 'u', - ], - ]; - } + /** + * Returns a list of allowed inline marks + * and their parsing rules + * + * @return array + */ + public function marks(): array + { + return [ + [ + 'tag' => 'a', + 'attrs' => ['href', 'rel', 'target', 'title'], + 'defaults' => [ + 'rel' => 'noopener noreferrer' + ] + ], + [ + 'tag' => 'abbr', + ], + [ + 'tag' => 'b' + ], + [ + 'tag' => 'br', + ], + [ + 'tag' => 'code' + ], + [ + 'tag' => 'del', + ], + [ + 'tag' => 'em', + ], + [ + 'tag' => 'i', + ], + [ + 'tag' => 'p', + ], + [ + 'tag' => 'strike', + ], + [ + 'tag' => 'sub', + ], + [ + 'tag' => 'sup', + ], + [ + 'tag' => 'strong', + ], + [ + 'tag' => 'u', + ], + ]; + } - /** - * Returns a list of allowed nodes and - * their parsing rules - * - * @codeCoverageIgnore - * @return array - */ - public function nodes(): array - { - return [ - [ - 'tag' => 'blockquote', - 'parse' => function (Element $node) { - return $this->blockquote($node); - } - ], - [ - 'tag' => 'h1', - 'parse' => function (Element $node) { - return $this->heading($node); - } - ], - [ - 'tag' => 'h2', - 'parse' => function (Element $node) { - return $this->heading($node); - } - ], - [ - 'tag' => 'h3', - 'parse' => function (Element $node) { - return $this->heading($node); - } - ], - [ - 'tag' => 'h4', - 'parse' => function (Element $node) { - return $this->heading($node); - } - ], - [ - 'tag' => 'h5', - 'parse' => function (Element $node) { - return $this->heading($node); - } - ], - [ - 'tag' => 'h6', - 'parse' => function (Element $node) { - return $this->heading($node); - } - ], - [ - 'tag' => 'hr', - 'parse' => function (Element $node) { - return [ - 'type' => 'line' - ]; - } - ], - [ - 'tag' => 'iframe', - 'parse' => function (Element $node) { - return $this->iframe($node); - } - ], - [ - 'tag' => 'img', - 'parse' => function (Element $node) { - return $this->img($node); - } - ], - [ - 'tag' => 'ol', - 'parse' => function (Element $node) { - return [ - 'content' => [ - 'text' => $this->list($node) - ], - 'type' => 'list', - ]; - } - ], - [ - 'tag' => 'pre', - 'parse' => function (Element $node) { - return $this->pre($node); - } - ], - [ - 'tag' => 'table', - 'parse' => function (Element $node) { - return $this->table($node); - } - ], - [ - 'tag' => 'ul', - 'parse' => function (Element $node) { - return [ - 'content' => [ - 'text' => $this->list($node) - ], - 'type' => 'list', - ]; - } - ], - ]; - } + /** + * Returns a list of allowed nodes and + * their parsing rules + * + * @codeCoverageIgnore + * @return array + */ + public function nodes(): array + { + return [ + [ + 'tag' => 'blockquote', + 'parse' => function (Element $node) { + return $this->blockquote($node); + } + ], + [ + 'tag' => 'h1', + 'parse' => function (Element $node) { + return $this->heading($node); + } + ], + [ + 'tag' => 'h2', + 'parse' => function (Element $node) { + return $this->heading($node); + } + ], + [ + 'tag' => 'h3', + 'parse' => function (Element $node) { + return $this->heading($node); + } + ], + [ + 'tag' => 'h4', + 'parse' => function (Element $node) { + return $this->heading($node); + } + ], + [ + 'tag' => 'h5', + 'parse' => function (Element $node) { + return $this->heading($node); + } + ], + [ + 'tag' => 'h6', + 'parse' => function (Element $node) { + return $this->heading($node); + } + ], + [ + 'tag' => 'hr', + 'parse' => function (Element $node) { + return [ + 'type' => 'line' + ]; + } + ], + [ + 'tag' => 'iframe', + 'parse' => function (Element $node) { + return $this->iframe($node); + } + ], + [ + 'tag' => 'img', + 'parse' => function (Element $node) { + return $this->img($node); + } + ], + [ + 'tag' => 'ol', + 'parse' => function (Element $node) { + return [ + 'content' => [ + 'text' => $this->list($node) + ], + 'type' => 'list', + ]; + } + ], + [ + 'tag' => 'pre', + 'parse' => function (Element $node) { + return $this->pre($node); + } + ], + [ + 'tag' => 'table', + 'parse' => function (Element $node) { + return $this->table($node); + } + ], + [ + 'tag' => 'ul', + 'parse' => function (Element $node) { + return [ + 'content' => [ + 'text' => $this->list($node) + ], + 'type' => 'list', + ]; + } + ], + ]; + } - /** - * @param \Kirby\Parsley\Element $node - * @return array - */ - public function pre(Element $node): array - { - $language = 'text'; + /** + * @param \Kirby\Parsley\Element $node + * @return array + */ + public function pre(Element $node): array + { + $language = 'text'; - if ($code = $node->find('//code')) { - foreach ($code->classList() as $className) { - if (preg_match('!language-(.*?)!', $className)) { - $language = str_replace('language-', '', $className); - break; - } - } - } + if ($code = $node->find('//code')) { + foreach ($code->classList() as $className) { + if (preg_match('!language-(.*?)!', $className)) { + $language = str_replace('language-', '', $className); + break; + } + } + } - return [ - 'content' => [ - 'code' => $node->innerText(), - 'language' => $language - ], - 'type' => 'code', - ]; - } + return [ + 'content' => [ + 'code' => $node->innerText(), + 'language' => $language + ], + 'type' => 'code', + ]; + } - /** - * @param \Kirby\Parsley\Element $node - * @return array - */ - public function table(Element $node): array - { - return [ - 'content' => [ - 'text' => $node->outerHTML(), - ], - 'type' => 'markdown', - ]; - } + /** + * @param \Kirby\Parsley\Element $node + * @return array + */ + public function table(Element $node): array + { + return [ + 'content' => [ + 'text' => $node->outerHTML(), + ], + 'type' => 'markdown', + ]; + } } diff --git a/kirby/src/Parsley/Schema/Plain.php b/kirby/src/Parsley/Schema/Plain.php index 32ad856..96e976a 100755 --- a/kirby/src/Parsley/Schema/Plain.php +++ b/kirby/src/Parsley/Schema/Plain.php @@ -20,50 +20,50 @@ use Kirby\Toolkit\Str; */ class Plain extends Schema { - /** - * Creates the fallback block type - * if no other block can be found - * - * @param \Kirby\Parsley\Element|string $element - * @return array|null - */ - public function fallback($element): ?array - { - if (is_a($element, Element::class) === true) { - $text = $element->innerText(); - } elseif (is_string($element) === true) { - $text = trim($element); + /** + * Creates the fallback block type + * if no other block can be found + * + * @param \Kirby\Parsley\Element|string $element + * @return array|null + */ + public function fallback($element): ?array + { + if (is_a($element, Element::class) === true) { + $text = $element->innerText(); + } elseif (is_string($element) === true) { + $text = trim($element); - if (Str::length($text) === 0) { - return null; - } - } else { - return null; - } + if (Str::length($text) === 0) { + return null; + } + } else { + return null; + } - return [ - 'content' => [ - 'text' => $text - ], - 'type' => 'text', - ]; - } + return [ + 'content' => [ + 'text' => $text + ], + 'type' => 'text', + ]; + } - /** - * Returns a list of all elements that - * should be skipped during parsing - * - * @return array - */ - public function skip(): array - { - return [ - 'base', - 'link', - 'meta', - 'script', - 'style', - 'title' - ]; - } + /** + * Returns a list of all elements that + * should be skipped during parsing + * + * @return array + */ + public function skip(): array + { + return [ + 'base', + 'link', + 'meta', + 'script', + 'style', + 'title' + ]; + } } diff --git a/kirby/src/Sane/DomHandler.php b/kirby/src/Sane/DomHandler.php index e615f78..810a1ce 100755 --- a/kirby/src/Sane/DomHandler.php +++ b/kirby/src/Sane/DomHandler.php @@ -19,147 +19,147 @@ use Kirby\Toolkit\Dom; */ class DomHandler extends Handler { - /** - * List of all MIME types that may - * be used in data URIs - * - * @var array - */ - public static $allowedDataUris = [ - 'data:image/png', - 'data:image/gif', - 'data:image/jpg', - 'data:image/jpe', - 'data:image/pjp', - 'data:img/png', - 'data:img/gif', - 'data:img/jpg', - 'data:img/jpe', - 'data:img/pjp', - ]; + /** + * List of all MIME types that may + * be used in data URIs + * + * @var array + */ + public static $allowedDataUris = [ + 'data:image/png', + 'data:image/gif', + 'data:image/jpg', + 'data:image/jpe', + 'data:image/pjp', + 'data:img/png', + 'data:img/gif', + 'data:img/jpg', + 'data:img/jpe', + 'data:img/pjp', + ]; - /** - * Allowed hostnames for HTTP(S) URLs - * - * @var array - */ - public static $allowedDomains = []; + /** + * Allowed hostnames for HTTP(S) URLs + * + * @var array + */ + public static $allowedDomains = []; - /** - * Names of allowed XML processing instructions - * - * @var array - */ - public static $allowedPIs = []; + /** + * Names of allowed XML processing instructions + * + * @var array + */ + public static $allowedPIs = []; - /** - * The document type (`'HTML'` or `'XML'`) - * (to be set in child classes) - * - * @var string - */ - protected static $type = 'XML'; + /** + * The document type (`'HTML'` or `'XML'`) + * (to be set in child classes) + * + * @var string + */ + protected static $type = 'XML'; - /** - * Sanitizes the given string - * - * @param string $string - * @return string - * - * @throws \Kirby\Exception\InvalidArgumentException If the file couldn't be parsed - */ - public static function sanitize(string $string): string - { - $dom = static::parse($string); - $dom->sanitize(static::options()); - return $dom->toString(); - } + /** + * Sanitizes the given string + * + * @param string $string + * @return string + * + * @throws \Kirby\Exception\InvalidArgumentException If the file couldn't be parsed + */ + public static function sanitize(string $string): string + { + $dom = static::parse($string); + $dom->sanitize(static::options()); + return $dom->toString(); + } - /** - * Validates file contents - * - * @param string $string - * @return void - * - * @throws \Kirby\Exception\InvalidArgumentException If the file couldn't be parsed - * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation - */ - public static function validate(string $string): void - { - $dom = static::parse($string); - $errors = $dom->sanitize(static::options()); - if (count($errors) > 0) { - // there may be multiple errors, we can only throw one of them at a time - throw $errors[0]; - } - } + /** + * Validates file contents + * + * @param string $string + * @return void + * + * @throws \Kirby\Exception\InvalidArgumentException If the file couldn't be parsed + * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation + */ + public static function validate(string $string): void + { + $dom = static::parse($string); + $errors = $dom->sanitize(static::options()); + if (count($errors) > 0) { + // there may be multiple errors, we can only throw one of them at a time + throw $errors[0]; + } + } - /** - * Custom callback for additional attribute sanitization - * @internal - * - * @param \DOMAttr $attr - * @return array Array with exception objects for each modification - */ - public static function sanitizeAttr(DOMAttr $attr): array - { - // to be extended in child classes - return []; - } + /** + * Custom callback for additional attribute sanitization + * @internal + * + * @param \DOMAttr $attr + * @return array Array with exception objects for each modification + */ + public static function sanitizeAttr(DOMAttr $attr): array + { + // to be extended in child classes + return []; + } - /** - * Custom callback for additional element sanitization - * @internal - * - * @param \DOMElement $element - * @return array Array with exception objects for each modification - */ - public static function sanitizeElement(DOMElement $element): array - { - // to be extended in child classes - return []; - } + /** + * Custom callback for additional element sanitization + * @internal + * + * @param \DOMElement $element + * @return array Array with exception objects for each modification + */ + public static function sanitizeElement(DOMElement $element): array + { + // to be extended in child classes + return []; + } - /** - * Custom callback for additional doctype validation - * @internal - * - * @param \DOMDocumentType $doctype - * @return void - */ - public static function validateDoctype(DOMDocumentType $doctype): void - { - // to be extended in child classes - } + /** + * Custom callback for additional doctype validation + * @internal + * + * @param \DOMDocumentType $doctype + * @return void + */ + public static function validateDoctype(DOMDocumentType $doctype): void + { + // to be extended in child classes + } - /** - * Returns the sanitization options for the handler - * (to be extended in child classes) - * - * @return array - */ - protected static function options(): array - { - return [ - 'allowedDataUris' => static::$allowedDataUris, - 'allowedDomains' => static::$allowedDomains, - 'allowedPIs' => static::$allowedPIs, - 'attrCallback' => [static::class, 'sanitizeAttr'], - 'doctypeCallback' => [static::class, 'validateDoctype'], - 'elementCallback' => [static::class, 'sanitizeElement'], - ]; - } + /** + * Returns the sanitization options for the handler + * (to be extended in child classes) + * + * @return array + */ + protected static function options(): array + { + return [ + 'allowedDataUris' => static::$allowedDataUris, + 'allowedDomains' => static::$allowedDomains, + 'allowedPIs' => static::$allowedPIs, + 'attrCallback' => [static::class, 'sanitizeAttr'], + 'doctypeCallback' => [static::class, 'validateDoctype'], + 'elementCallback' => [static::class, 'sanitizeElement'], + ]; + } - /** - * Parses the given string into a `Toolkit\Dom` object - * - * @param string $string - * @return \Kirby\Toolkit\Dom - * - * @throws \Kirby\Exception\InvalidArgumentException If the file couldn't be parsed - */ - protected static function parse(string $string) - { - return new Dom($string, static::$type); - } + /** + * Parses the given string into a `Toolkit\Dom` object + * + * @param string $string + * @return \Kirby\Toolkit\Dom + * + * @throws \Kirby\Exception\InvalidArgumentException If the file couldn't be parsed + */ + protected static function parse(string $string) + { + return new Dom($string, static::$type); + } } diff --git a/kirby/src/Sane/Handler.php b/kirby/src/Sane/Handler.php index 5fc6e4f..c66bc98 100755 --- a/kirby/src/Sane/Handler.php +++ b/kirby/src/Sane/Handler.php @@ -19,73 +19,73 @@ use Kirby\Filesystem\F; */ abstract class Handler { - /** - * Sanitizes the given string - * - * @param string $string - * @return string - */ - abstract public static function sanitize(string $string): string; + /** + * Sanitizes the given string + * + * @param string $string + * @return string + */ + abstract public static function sanitize(string $string): string; - /** - * Sanitizes the contents of a file by overwriting - * the file with the sanitized version - * - * @param string $file - * @return void - * - * @throws \Kirby\Exception\Exception If the file does not exist - * @throws \Kirby\Exception\Exception On other errors - */ - public static function sanitizeFile(string $file): void - { - $sanitized = static::sanitize(static::readFile($file)); - F::write($file, $sanitized); - } + /** + * Sanitizes the contents of a file by overwriting + * the file with the sanitized version + * + * @param string $file + * @return void + * + * @throws \Kirby\Exception\Exception If the file does not exist + * @throws \Kirby\Exception\Exception On other errors + */ + public static function sanitizeFile(string $file): void + { + $sanitized = static::sanitize(static::readFile($file)); + F::write($file, $sanitized); + } - /** - * Validates file contents - * - * @param string $string - * @return void - * - * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation - * @throws \Kirby\Exception\Exception On other errors - */ - abstract public static function validate(string $string): void; + /** + * Validates file contents + * + * @param string $string + * @return void + * + * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation + * @throws \Kirby\Exception\Exception On other errors + */ + abstract public static function validate(string $string): void; - /** - * Validates the contents of a file - * - * @param string $file - * @return void - * - * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation - * @throws \Kirby\Exception\Exception If the file does not exist - * @throws \Kirby\Exception\Exception On other errors - */ - public static function validateFile(string $file): void - { - static::validate(static::readFile($file)); - } + /** + * Validates the contents of a file + * + * @param string $file + * @return void + * + * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation + * @throws \Kirby\Exception\Exception If the file does not exist + * @throws \Kirby\Exception\Exception On other errors + */ + public static function validateFile(string $file): void + { + static::validate(static::readFile($file)); + } - /** - * Reads the contents of a file - * for sanitization or validation - * - * @param string $file - * @return string - * - * @throws \Kirby\Exception\Exception If the file does not exist - */ - protected static function readFile(string $file): string - { - $contents = F::read($file); + /** + * Reads the contents of a file + * for sanitization or validation + * + * @param string $file + * @return string + * + * @throws \Kirby\Exception\Exception If the file does not exist + */ + protected static function readFile(string $file): string + { + $contents = F::read($file); - if ($contents === false) { - throw new Exception('The file "' . $file . '" does not exist'); - } + if ($contents === false) { + throw new Exception('The file "' . $file . '" does not exist'); + } - return $contents; - } + return $contents; + } } diff --git a/kirby/src/Sane/Html.php b/kirby/src/Sane/Html.php index 56ff50b..99823e5 100755 --- a/kirby/src/Sane/Html.php +++ b/kirby/src/Sane/Html.php @@ -15,130 +15,130 @@ namespace Kirby\Sane; */ class Html extends DomHandler { - /** - * Global list of allowed attribute prefixes - * - * @var array - */ - public static $allowedAttrPrefixes = [ - 'aria-', - 'data-', - ]; + /** + * Global list of allowed attribute prefixes + * + * @var array + */ + public static $allowedAttrPrefixes = [ + 'aria-', + 'data-', + ]; - /** - * Global list of allowed attributes - * - * @var array - */ - public static $allowedAttrs = [ - 'class', - 'id', - ]; + /** + * Global list of allowed attributes + * + * @var array + */ + public static $allowedAttrs = [ + 'class', + 'id', + ]; - /** - * Allowed hostnames for HTTP(S) URLs - * - * @var array - */ - public static $allowedDomains = true; + /** + * Allowed hostnames for HTTP(S) URLs + * + * @var array + */ + public static $allowedDomains = true; - /** - * Associative array of all allowed tag names with the value - * of either an array with the list of all allowed attributes - * for this tag, `true` to allow any attribute from the - * `allowedAttrs` list or `false` to allow the tag without - * any attributes - * - * @var array - */ - public static $allowedTags = [ - 'a' => ['href', 'rel', 'title', 'target'], - 'abbr' => ['title'], - 'b' => true, - 'body' => true, - 'blockquote' => true, - 'br' => true, - 'code' => true, - 'dl' => true, - 'dd' => true, - 'del' => true, - 'div' => true, - 'dt' => true, - 'em' => true, - 'footer' => true, - 'h1' => true, - 'h2' => true, - 'h3' => true, - 'h4' => true, - 'h5' => true, - 'h6' => true, - 'hr' => true, - 'html' => true, - 'i' => true, - 'ins' => true, - 'li' => true, - 'small' => true, - 'span' => true, - 'strong' => true, - 'sub' => true, - 'sup' => true, - 'ol' => true, - 'p' => true, - 'pre' => true, - 's' => true, - 'u' => true, - 'ul' => true, - ]; + /** + * Associative array of all allowed tag names with the value + * of either an array with the list of all allowed attributes + * for this tag, `true` to allow any attribute from the + * `allowedAttrs` list or `false` to allow the tag without + * any attributes + * + * @var array + */ + public static $allowedTags = [ + 'a' => ['href', 'rel', 'title', 'target'], + 'abbr' => ['title'], + 'b' => true, + 'body' => true, + 'blockquote' => true, + 'br' => true, + 'code' => true, + 'dl' => true, + 'dd' => true, + 'del' => true, + 'div' => true, + 'dt' => true, + 'em' => true, + 'footer' => true, + 'h1' => true, + 'h2' => true, + 'h3' => true, + 'h4' => true, + 'h5' => true, + 'h6' => true, + 'hr' => true, + 'html' => true, + 'i' => true, + 'ins' => true, + 'li' => true, + 'small' => true, + 'span' => true, + 'strong' => true, + 'sub' => true, + 'sup' => true, + 'ol' => true, + 'p' => true, + 'pre' => true, + 's' => true, + 'u' => true, + 'ul' => true, + ]; - /** - * Array of explicitly disallowed tags - * - * IMPORTANT: Use lower-case names here because - * of the case-insensitive matching - * - * @var array - */ - public static $disallowedTags = [ - 'iframe', - 'meta', - 'object', - 'script', - 'style', - ]; + /** + * Array of explicitly disallowed tags + * + * IMPORTANT: Use lower-case names here because + * of the case-insensitive matching + * + * @var array + */ + public static $disallowedTags = [ + 'iframe', + 'meta', + 'object', + 'script', + 'style', + ]; - /** - * List of attributes that may contain URLs - * - * @var array - */ - public static $urlAttrs = [ - 'href', - 'src', - 'xlink:href', - ]; + /** + * List of attributes that may contain URLs + * + * @var array + */ + public static $urlAttrs = [ + 'href', + 'src', + 'xlink:href', + ]; - /** - * The document type (`'HTML'` or `'XML'`) - * - * @var string - */ - protected static $type = 'HTML'; + /** + * The document type (`'HTML'` or `'XML'`) + * + * @var string + */ + protected static $type = 'HTML'; - /** - * Returns the sanitization options for the handler - * - * @return array - */ - protected static function options(): array - { - return array_merge(parent::options(), [ - 'allowedAttrPrefixes' => static::$allowedAttrPrefixes, - 'allowedAttrs' => static::$allowedAttrs, - 'allowedNamespaces' => [], - 'allowedPIs' => [], - 'allowedTags' => static::$allowedTags, - 'disallowedTags' => static::$disallowedTags, - 'urlAttrs' => static::$urlAttrs, - ]); - } + /** + * Returns the sanitization options for the handler + * + * @return array + */ + protected static function options(): array + { + return array_merge(parent::options(), [ + 'allowedAttrPrefixes' => static::$allowedAttrPrefixes, + 'allowedAttrs' => static::$allowedAttrs, + 'allowedNamespaces' => [], + 'allowedPIs' => [], + 'allowedTags' => static::$allowedTags, + 'disallowedTags' => static::$disallowedTags, + 'urlAttrs' => static::$urlAttrs, + ]); + } } diff --git a/kirby/src/Sane/Sane.php b/kirby/src/Sane/Sane.php index 140a2d9..5a55ae0 100755 --- a/kirby/src/Sane/Sane.php +++ b/kirby/src/Sane/Sane.php @@ -21,189 +21,189 @@ use Kirby\Filesystem\F; */ class Sane { - /** - * Handler Type Aliases - * - * @var array - */ - public static $aliases = [ - 'application/xml' => 'xml', - 'image/svg' => 'svg', - 'image/svg+xml' => 'svg', - 'text/html' => 'html', - 'text/xml' => 'xml', - ]; + /** + * Handler Type Aliases + * + * @var array + */ + public static $aliases = [ + 'application/xml' => 'xml', + 'image/svg' => 'svg', + 'image/svg+xml' => 'svg', + 'text/html' => 'html', + 'text/xml' => 'xml', + ]; - /** - * All registered handlers - * - * @var array - */ - public static $handlers = [ - 'html' => 'Kirby\Sane\Html', - 'svg' => 'Kirby\Sane\Svg', - 'svgz' => 'Kirby\Sane\Svgz', - 'xml' => 'Kirby\Sane\Xml', - ]; + /** + * All registered handlers + * + * @var array + */ + public static $handlers = [ + 'html' => 'Kirby\Sane\Html', + 'svg' => 'Kirby\Sane\Svg', + 'svgz' => 'Kirby\Sane\Svgz', + 'xml' => 'Kirby\Sane\Xml', + ]; - /** - * Handler getter - * - * @param string $type - * @param bool $lazy If set to `true`, `null` is returned for undefined handlers - * @return \Kirby\Sane\Handler|null - * - * @throws \Kirby\Exception\NotFoundException If no handler was found and `$lazy` was set to `false` - */ - public static function handler(string $type, bool $lazy = false) - { - // normalize the type - $type = mb_strtolower($type); + /** + * Handler getter + * + * @param string $type + * @param bool $lazy If set to `true`, `null` is returned for undefined handlers + * @return \Kirby\Sane\Handler|null + * + * @throws \Kirby\Exception\NotFoundException If no handler was found and `$lazy` was set to `false` + */ + public static function handler(string $type, bool $lazy = false) + { + // normalize the type + $type = mb_strtolower($type); - // find a handler or alias - $handler = static::$handlers[$type] ?? - static::$handlers[static::$aliases[$type] ?? null] ?? - null; + // find a handler or alias + $handler = static::$handlers[$type] ?? + static::$handlers[static::$aliases[$type] ?? null] ?? + null; - if (empty($handler) === false && class_exists($handler) === true) { - return new $handler(); - } + if (empty($handler) === false && class_exists($handler) === true) { + return new $handler(); + } - if ($lazy === true) { - return null; - } + if ($lazy === true) { + return null; + } - throw new NotFoundException('Missing handler for type: "' . $type . '"'); - } + throw new NotFoundException('Missing handler for type: "' . $type . '"'); + } - /** - * Sanitizes the given string with the specified handler - * @since 3.6.0 - * - * @param string $string - * @param string $type - * @return string - */ - public static function sanitize(string $string, string $type): string - { - return static::handler($type)->sanitize($string); - } + /** + * Sanitizes the given string with the specified handler + * @since 3.6.0 + * + * @param string $string + * @param string $type + * @return string + */ + public static function sanitize(string $string, string $type): string + { + return static::handler($type)->sanitize($string); + } - /** - * Sanitizes the contents of a file by overwriting - * the file with the sanitized version; - * the sane handlers are automatically chosen by - * the extension and MIME type if not specified - * @since 3.6.0 - * - * @param string $file - * @param string|bool $typeLazy Explicit handler type string, - * `true` for lazy autodetection or - * `false` for normal autodetection - * @return void - * - * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation - * @throws \Kirby\Exception\LogicException If more than one handler applies - * @throws \Kirby\Exception\NotFoundException If the handler was not found - * @throws \Kirby\Exception\Exception On other errors - */ - public static function sanitizeFile(string $file, $typeLazy = false): void - { - if (is_string($typeLazy) === true) { - static::handler($typeLazy)->sanitizeFile($file); - return; - } + /** + * Sanitizes the contents of a file by overwriting + * the file with the sanitized version; + * the sane handlers are automatically chosen by + * the extension and MIME type if not specified + * @since 3.6.0 + * + * @param string $file + * @param string|bool $typeLazy Explicit handler type string, + * `true` for lazy autodetection or + * `false` for normal autodetection + * @return void + * + * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation + * @throws \Kirby\Exception\LogicException If more than one handler applies + * @throws \Kirby\Exception\NotFoundException If the handler was not found + * @throws \Kirby\Exception\Exception On other errors + */ + public static function sanitizeFile(string $file, $typeLazy = false): void + { + if (is_string($typeLazy) === true) { + static::handler($typeLazy)->sanitizeFile($file); + return; + } - // try to find exactly one matching handler - $handlers = static::handlersForFile($file, $typeLazy === true); - switch (count($handlers)) { - case 0: - // lazy autodetection didn't find a handler - break; - case 1: - $handlers[0]->sanitizeFile($file); - break; - default: - // more than one matching handler; - // sanitizing with all handlers will not leave much in the output - $handlerNames = array_map('get_class', $handlers); - throw new LogicException( - 'Cannot sanitize file as more than one handler applies: ' . - implode(', ', $handlerNames) - ); - } - } + // try to find exactly one matching handler + $handlers = static::handlersForFile($file, $typeLazy === true); + switch (count($handlers)) { + case 0: + // lazy autodetection didn't find a handler + break; + case 1: + $handlers[0]->sanitizeFile($file); + break; + default: + // more than one matching handler; + // sanitizing with all handlers will not leave much in the output + $handlerNames = array_map('get_class', $handlers); + throw new LogicException( + 'Cannot sanitize file as more than one handler applies: ' . + implode(', ', $handlerNames) + ); + } + } - /** - * Validates file contents with the specified handler - * - * @param string $string - * @param string $type - * @return void - * - * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation - * @throws \Kirby\Exception\NotFoundException If the handler was not found - * @throws \Kirby\Exception\Exception On other errors - */ - public static function validate(string $string, string $type): void - { - static::handler($type)->validate($string); - } + /** + * Validates file contents with the specified handler + * + * @param string $string + * @param string $type + * @return void + * + * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation + * @throws \Kirby\Exception\NotFoundException If the handler was not found + * @throws \Kirby\Exception\Exception On other errors + */ + public static function validate(string $string, string $type): void + { + static::handler($type)->validate($string); + } - /** - * Validates the contents of a file; - * the sane handlers are automatically chosen by - * the extension and MIME type if not specified - * - * @param string $file - * @param string|bool $typeLazy Explicit handler type string, - * `true` for lazy autodetection or - * `false` for normal autodetection - * @return void - * - * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation - * @throws \Kirby\Exception\NotFoundException If the handler was not found - * @throws \Kirby\Exception\Exception On other errors - */ - public static function validateFile(string $file, $typeLazy = false): void - { - if (is_string($typeLazy) === true) { - static::handler($typeLazy)->validateFile($file); - return; - } + /** + * Validates the contents of a file; + * the sane handlers are automatically chosen by + * the extension and MIME type if not specified + * + * @param string $file + * @param string|bool $typeLazy Explicit handler type string, + * `true` for lazy autodetection or + * `false` for normal autodetection + * @return void + * + * @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation + * @throws \Kirby\Exception\NotFoundException If the handler was not found + * @throws \Kirby\Exception\Exception On other errors + */ + public static function validateFile(string $file, $typeLazy = false): void + { + if (is_string($typeLazy) === true) { + static::handler($typeLazy)->validateFile($file); + return; + } - foreach (static::handlersForFile($file, $typeLazy === true) as $handler) { - $handler->validateFile($file); - } - } + foreach (static::handlersForFile($file, $typeLazy === true) as $handler) { + $handler->validateFile($file); + } + } - /** - * Returns all handler objects that apply to the given file based on - * file extension and MIME type - * - * @param string $file - * @param bool $lazy If set to `true`, undefined handlers are skipped - * @return array<\Kirby\Sane\Handler> - */ - protected static function handlersForFile(string $file, bool $lazy = false): array - { - $handlers = $handlerClasses = []; + /** + * Returns all handler objects that apply to the given file based on + * file extension and MIME type + * + * @param string $file + * @param bool $lazy If set to `true`, undefined handlers are skipped + * @return array<\Kirby\Sane\Handler> + */ + protected static function handlersForFile(string $file, bool $lazy = false): array + { + $handlers = $handlerClasses = []; - // all values that can be used for the handler search; - // filter out all empty options - $options = array_filter([F::extension($file), F::mime($file)]); + // all values that can be used for the handler search; + // filter out all empty options + $options = array_filter([F::extension($file), F::mime($file)]); - foreach ($options as $option) { - $handler = static::handler($option, $lazy); - $handlerClass = $handler ? get_class($handler) : null; + foreach ($options as $option) { + $handler = static::handler($option, $lazy); + $handlerClass = $handler ? get_class($handler) : null; - // ensure that each handler class is only returned once - if ($handler && in_array($handlerClass, $handlerClasses) === false) { - $handlers[] = $handler; - $handlerClasses[] = $handlerClass; - } - } + // ensure that each handler class is only returned once + if ($handler && in_array($handlerClass, $handlerClasses) === false) { + $handlers[] = $handler; + $handlerClasses[] = $handlerClass; + } + } - return $handlers; - } + return $handlers; + } } diff --git a/kirby/src/Sane/Svg.php b/kirby/src/Sane/Svg.php index c0772b3..d8d8604 100755 --- a/kirby/src/Sane/Svg.php +++ b/kirby/src/Sane/Svg.php @@ -23,487 +23,487 @@ use Kirby\Toolkit\Str; */ class Svg extends Xml { - /** - * Allow and block lists are inspired by DOMPurify - * - * @link https://github.com/cure53/DOMPurify - * @copyright 2015 Mario Heiderich - * @license https://www.apache.org/licenses/LICENSE-2.0 - */ + /** + * Allow and block lists are inspired by DOMPurify + * + * @link https://github.com/cure53/DOMPurify + * @copyright 2015 Mario Heiderich + * @license https://www.apache.org/licenses/LICENSE-2.0 + */ - /** - * Global list of allowed attribute prefixes - * - * @var array - */ - public static $allowedAttrPrefixes = [ - 'aria-', - 'data-', - ]; + /** + * Global list of allowed attribute prefixes + * + * @var array + */ + public static $allowedAttrPrefixes = [ + 'aria-', + 'data-', + ]; - /** - * Global list of allowed attributes - * - * @var array - */ - public static $allowedAttrs = [ - // core attributes - 'id', - 'lang', - 'tabindex', - 'xml:id', - 'xml:lang', - 'xml:space', + /** + * Global list of allowed attributes + * + * @var array + */ + public static $allowedAttrs = [ + // core attributes + 'id', + 'lang', + 'tabindex', + 'xml:id', + 'xml:lang', + 'xml:space', - // styling attributes - 'class', - 'style', + // styling attributes + 'class', + 'style', - // conditional processing attributes - 'systemLanguage', + // conditional processing attributes + 'systemLanguage', - // presentation attributes - 'alignment-baseline', - 'baseline-shift', - 'clip', - 'clip-path', - 'clip-rule', - 'color', - 'color-interpolation', - 'color-interpolation-filters', - 'color-profile', - 'color-rendering', - 'd', - 'direction', - 'display', - 'dominant-baseline', - 'enable-background', - 'fill', - 'fill-opacity', - 'fill-rule', - 'filter', - 'flood-color', - 'flood-opacity', - 'font-family', - 'font-size', - 'font-size-adjust', - 'font-stretch', - 'font-style', - 'font-variant', - 'font-weight', - 'image-rendering', - 'kerning', - 'letter-spacing', - 'lighting-color', - 'marker-end', - 'marker-mid', - 'marker-start', - 'mask', - 'opacity', - 'overflow', - 'paint-order', - 'shape-rendering', - 'stop-color', - 'stop-opacity', - 'stroke', - 'stroke-dasharray', - 'stroke-dashoffset', - 'stroke-linecap', - 'stroke-linejoin', - 'stroke-miterlimit', - 'stroke-opacity', - 'stroke-width', - 'text-anchor', - 'text-decoration', - 'text-rendering', - 'transform', - 'visibility', - 'word-spacing', - 'writing-mode', + // presentation attributes + 'alignment-baseline', + 'baseline-shift', + 'clip', + 'clip-path', + 'clip-rule', + 'color', + 'color-interpolation', + 'color-interpolation-filters', + 'color-profile', + 'color-rendering', + 'd', + 'direction', + 'display', + 'dominant-baseline', + 'enable-background', + 'fill', + 'fill-opacity', + 'fill-rule', + 'filter', + 'flood-color', + 'flood-opacity', + 'font-family', + 'font-size', + 'font-size-adjust', + 'font-stretch', + 'font-style', + 'font-variant', + 'font-weight', + 'image-rendering', + 'kerning', + 'letter-spacing', + 'lighting-color', + 'marker-end', + 'marker-mid', + 'marker-start', + 'mask', + 'opacity', + 'overflow', + 'paint-order', + 'shape-rendering', + 'stop-color', + 'stop-opacity', + 'stroke', + 'stroke-dasharray', + 'stroke-dashoffset', + 'stroke-linecap', + 'stroke-linejoin', + 'stroke-miterlimit', + 'stroke-opacity', + 'stroke-width', + 'text-anchor', + 'text-decoration', + 'text-rendering', + 'transform', + 'visibility', + 'word-spacing', + 'writing-mode', - // animation attribute target attributes - 'attributeName', - 'attributeType', + // animation attribute target attributes + 'attributeName', + 'attributeType', - // animation timing attributes - 'begin', - 'dur', - 'end', - 'max', - 'min', - 'repeatCount', - 'repeatDur', - 'restart', + // animation timing attributes + 'begin', + 'dur', + 'end', + 'max', + 'min', + 'repeatCount', + 'repeatDur', + 'restart', - // animation value attributes - 'by', - 'from', - 'keySplines', - 'keyTimes', - 'to', - 'values', + // animation value attributes + 'by', + 'from', + 'keySplines', + 'keyTimes', + 'to', + 'values', - // animation addition attributes - 'accumulate', - 'additive', + // animation addition attributes + 'accumulate', + 'additive', - // filter primitive attributes - 'height', - 'result', - 'width', - 'x', - 'y', + // filter primitive attributes + 'height', + 'result', + 'width', + 'x', + 'y', - // transfer function attributes - 'amplitude', - 'exponent', - 'intercept', - 'offset', - 'slope', - 'tableValues', - 'type', + // transfer function attributes + 'amplitude', + 'exponent', + 'intercept', + 'offset', + 'slope', + 'tableValues', + 'type', - // other attributes specific to one or multiple elements - 'azimuth', - 'baseFrequency', - 'bias', - 'clipPathUnits', - 'cx', - 'cy', - 'diffuseConstant', - 'divisor', - 'dx', - 'dy', - 'edgeMode', - 'elevation', - 'filterUnits', - 'fr', - 'fx', - 'fy', - 'g1', - 'g2', - 'glyph-name', - 'glyphRef', - 'gradientTransform', - 'gradientUnits', - 'href', - 'hreflang', - 'in', - 'in2', - 'k', - 'k1', - 'k2', - 'k3', - 'k4', - 'kernelMatrix', - 'kernelUnitLength', - 'keyPoints', - 'lengthAdjust', - 'limitingConeAngle', - 'markerHeight', - 'markerUnits', - 'markerWidth', - 'maskContentUnits', - 'maskUnits', - 'media', - 'method', - 'mode', - 'numOctaves', - 'operator', - 'order', - 'orient', - 'orientation', - 'path', - 'pathLength', - 'patternContentUnits', - 'patternTransform', - 'patternUnits', - 'points', - 'pointsAtX', - 'pointsAtY', - 'pointsAtZ', - 'preserveAlpha', - 'preserveAspectRatio', - 'primitiveUnits', - 'r', - 'radius', - 'refX', - 'refY', - 'rotate', - 'rx', - 'ry', - 'scale', - 'seed', - 'side', - 'spacing', - 'specularConstant', - 'specularExponent', - 'spreadMethod', - 'startOffset', - 'stdDeviation', - 'stitchTiles', - 'surfaceScale', - 'targetX', - 'targetY', - 'textLength', - 'u1', - 'u2', - 'unicode', - 'version', - 'vert-adv-y', - 'vert-origin-x', - 'vert-origin-y', - 'viewBox', - 'x1', - 'x2', - 'xChannelSelector', - 'xlink:href', - 'xlink:title', - 'y1', - 'y2', - 'yChannelSelector', - 'z', - 'zoomAndPan', - ]; + // other attributes specific to one or multiple elements + 'azimuth', + 'baseFrequency', + 'bias', + 'clipPathUnits', + 'cx', + 'cy', + 'diffuseConstant', + 'divisor', + 'dx', + 'dy', + 'edgeMode', + 'elevation', + 'filterUnits', + 'fr', + 'fx', + 'fy', + 'g1', + 'g2', + 'glyph-name', + 'glyphRef', + 'gradientTransform', + 'gradientUnits', + 'href', + 'hreflang', + 'in', + 'in2', + 'k', + 'k1', + 'k2', + 'k3', + 'k4', + 'kernelMatrix', + 'kernelUnitLength', + 'keyPoints', + 'lengthAdjust', + 'limitingConeAngle', + 'markerHeight', + 'markerUnits', + 'markerWidth', + 'maskContentUnits', + 'maskUnits', + 'media', + 'method', + 'mode', + 'numOctaves', + 'operator', + 'order', + 'orient', + 'orientation', + 'path', + 'pathLength', + 'patternContentUnits', + 'patternTransform', + 'patternUnits', + 'points', + 'pointsAtX', + 'pointsAtY', + 'pointsAtZ', + 'preserveAlpha', + 'preserveAspectRatio', + 'primitiveUnits', + 'r', + 'radius', + 'refX', + 'refY', + 'rotate', + 'rx', + 'ry', + 'scale', + 'seed', + 'side', + 'spacing', + 'specularConstant', + 'specularExponent', + 'spreadMethod', + 'startOffset', + 'stdDeviation', + 'stitchTiles', + 'surfaceScale', + 'targetX', + 'targetY', + 'textLength', + 'u1', + 'u2', + 'unicode', + 'version', + 'vert-adv-y', + 'vert-origin-x', + 'vert-origin-y', + 'viewBox', + 'x1', + 'x2', + 'xChannelSelector', + 'xlink:href', + 'xlink:title', + 'y1', + 'y2', + 'yChannelSelector', + 'z', + 'zoomAndPan', + ]; - /** - * Associative array of all allowed namespace URIs - * - * @var array - */ - public static $allowedNamespaces = [ - '' => 'http://www.w3.org/2000/svg', - 'xlink' => 'http://www.w3.org/1999/xlink' - ]; + /** + * Associative array of all allowed namespace URIs + * + * @var array + */ + public static $allowedNamespaces = [ + '' => 'http://www.w3.org/2000/svg', + 'xlink' => 'http://www.w3.org/1999/xlink' + ]; - /** - * Associative array of all allowed tag names with the value - * of either an array with the list of all allowed attributes - * for this tag, `true` to allow any attribute from the - * `allowedAttrs` list or `false` to allow the tag without - * any attributes - * - * @var array - */ - public static $allowedTags = [ - 'a' => true, - 'altGlyph' => true, - 'altGlyphDef' => true, - 'altGlyphItem' => true, - 'animateColor' => true, - 'animateMotion' => true, - 'animateTransform' => true, - 'circle' => true, - 'clipPath' => true, - 'defs' => true, - 'desc' => true, - 'ellipse' => true, - 'feBlend' => true, - 'feColorMatrix' => true, - 'feComponentTransfer' => true, - 'feComposite' => true, - 'feConvolveMatrix' => true, - 'feDiffuseLighting' => true, - 'feDisplacementMap' => true, - 'feDistantLight' => true, - 'feFlood' => true, - 'feFuncA' => true, - 'feFuncB' => true, - 'feFuncG' => true, - 'feFuncR' => true, - 'feGaussianBlur' => true, - 'feMerge' => true, - 'feMergeNode' => true, - 'feMorphology' => true, - 'feOffset' => true, - 'fePointLight' => true, - 'feSpecularLighting' => true, - 'feSpotLight' => true, - 'feTile' => true, - 'feTurbulence' => true, - 'filter' => true, - 'font' => true, - 'g' => true, - 'glyph' => true, - 'glyphRef' => true, - 'hkern' => true, - 'image' => true, - 'line' => true, - 'linearGradient' => true, - 'marker' => true, - 'mask' => true, - 'metadata' => true, - 'mpath' => true, - 'path' => true, - 'pattern' => true, - 'polygon' => true, - 'polyline' => true, - 'radialGradient' => true, - 'rect' => true, - 'stop' => true, - 'style' => true, - 'svg' => true, - 'switch' => true, - 'symbol' => true, - 'text' => true, - 'textPath' => true, - 'title' => true, - 'tref' => true, - 'tspan' => true, - 'use' => true, - 'view' => true, - 'vkern' => true, - ]; + /** + * Associative array of all allowed tag names with the value + * of either an array with the list of all allowed attributes + * for this tag, `true` to allow any attribute from the + * `allowedAttrs` list or `false` to allow the tag without + * any attributes + * + * @var array + */ + public static $allowedTags = [ + 'a' => true, + 'altGlyph' => true, + 'altGlyphDef' => true, + 'altGlyphItem' => true, + 'animateColor' => true, + 'animateMotion' => true, + 'animateTransform' => true, + 'circle' => true, + 'clipPath' => true, + 'defs' => true, + 'desc' => true, + 'ellipse' => true, + 'feBlend' => true, + 'feColorMatrix' => true, + 'feComponentTransfer' => true, + 'feComposite' => true, + 'feConvolveMatrix' => true, + 'feDiffuseLighting' => true, + 'feDisplacementMap' => true, + 'feDistantLight' => true, + 'feFlood' => true, + 'feFuncA' => true, + 'feFuncB' => true, + 'feFuncG' => true, + 'feFuncR' => true, + 'feGaussianBlur' => true, + 'feMerge' => true, + 'feMergeNode' => true, + 'feMorphology' => true, + 'feOffset' => true, + 'fePointLight' => true, + 'feSpecularLighting' => true, + 'feSpotLight' => true, + 'feTile' => true, + 'feTurbulence' => true, + 'filter' => true, + 'font' => true, + 'g' => true, + 'glyph' => true, + 'glyphRef' => true, + 'hkern' => true, + 'image' => true, + 'line' => true, + 'linearGradient' => true, + 'marker' => true, + 'mask' => true, + 'metadata' => true, + 'mpath' => true, + 'path' => true, + 'pattern' => true, + 'polygon' => true, + 'polyline' => true, + 'radialGradient' => true, + 'rect' => true, + 'stop' => true, + 'style' => true, + 'svg' => true, + 'switch' => true, + 'symbol' => true, + 'text' => true, + 'textPath' => true, + 'title' => true, + 'tref' => true, + 'tspan' => true, + 'use' => true, + 'view' => true, + 'vkern' => true, + ]; - /** - * Array of explicitly disallowed tags - * - * IMPORTANT: Use lower-case names here because - * of the case-insensitive matching - * - * @var array - */ - public static $disallowedTags = [ - 'animate', - 'color-profile', - 'cursor', - 'discard', - 'fedropshadow', - 'feimage', - 'font-face', - 'font-face-format', - 'font-face-name', - 'font-face-src', - 'font-face-uri', - 'foreignobject', - 'hatch', - 'hatchpath', - 'mesh', - 'meshgradient', - 'meshpatch', - 'meshrow', - 'missing-glyph', - 'script', - 'set', - 'solidcolor', - 'unknown', - ]; + /** + * Array of explicitly disallowed tags + * + * IMPORTANT: Use lower-case names here because + * of the case-insensitive matching + * + * @var array + */ + public static $disallowedTags = [ + 'animate', + 'color-profile', + 'cursor', + 'discard', + 'fedropshadow', + 'feimage', + 'font-face', + 'font-face-format', + 'font-face-name', + 'font-face-src', + 'font-face-uri', + 'foreignobject', + 'hatch', + 'hatchpath', + 'mesh', + 'meshgradient', + 'meshpatch', + 'meshrow', + 'missing-glyph', + 'script', + 'set', + 'solidcolor', + 'unknown', + ]; - /** - * Custom callback for additional attribute sanitization - * @internal - * - * @param \DOMAttr $attr - * @return array Array with exception objects for each modification - */ - public static function sanitizeAttr(DOMAttr $attr): array - { - $element = $attr->ownerElement; - $name = $attr->name; - $value = $attr->value; - $errors = []; + /** + * Custom callback for additional attribute sanitization + * @internal + * + * @param \DOMAttr $attr + * @return array Array with exception objects for each modification + */ + public static function sanitizeAttr(DOMAttr $attr): array + { + $element = $attr->ownerElement; + $name = $attr->name; + $value = $attr->value; + $errors = []; - // block nested elements ("Billion Laughs" DoS attack) - if ( - $element->localName === 'use' && - Str::contains($name, 'href') !== false && - Str::startsWith($value, '#') === true - ) { - // find the target (used element) - $id = str_replace('"', '', mb_substr($value, 1)); - $target = (new DOMXPath($attr->ownerDocument))->query('//*[@id="' . $id . '"]')->item(0); + // block nested elements ("Billion Laughs" DoS attack) + if ( + $element->localName === 'use' && + Str::contains($name, 'href') !== false && + Str::startsWith($value, '#') === true + ) { + // find the target (used element) + $id = str_replace('"', '', mb_substr($value, 1)); + $target = (new DOMXPath($attr->ownerDocument))->query('//*[@id="' . $id . '"]')->item(0); - // the target must not contain any other elements - if ( - is_a($target, 'DOMElement') === true && - $target->getElementsByTagName('use')->count() > 0 - ) { - $errors[] = new InvalidArgumentException( - 'Nested "use" elements are not allowed' . - ' (used in line ' . $element->getLineNo() . ')' - ); - $element->removeAttributeNode($attr); - } - } + // the target must not contain any other elements + if ( + is_a($target, 'DOMElement') === true && + $target->getElementsByTagName('use')->count() > 0 + ) { + $errors[] = new InvalidArgumentException( + 'Nested "use" elements are not allowed' . + ' (used in line ' . $element->getLineNo() . ')' + ); + $element->removeAttributeNode($attr); + } + } - return $errors; - } + return $errors; + } - /** - * Custom callback for additional element sanitization - * @internal - * - * @param \DOMElement $element - * @return array Array with exception objects for each modification - */ - public static function sanitizeElement(DOMElement $element): array - { - $errors = []; + /** + * Custom callback for additional element sanitization + * @internal + * + * @param \DOMElement $element + * @return array Array with exception objects for each modification + */ + public static function sanitizeElement(DOMElement $element): array + { + $errors = []; - // check for URLs inside - * - * text - * - * @param string $string - * @return string - */ - public static function css($string) - { - return static::escaper()->escapeCss($string); - } + /** + * Escape HTML style property values + * + * This can be used to put untrusted data into a stylesheet or a style tag. + * + * Stay away from putting untrusted data into complex properties like url, + * behavior, and custom (-moz-binding). You should also not put untrusted data + * into IE’s expression property value which allows JavaScript. + * + * + * + * text + * + * @param string $string + * @return string + */ + public static function css($string) + { + return static::escaper()->escapeCss($string); + } - /** - * Get the escaper instance (and create if needed) - * - * @return \Laminas\Escaper\Escaper - */ - protected static function escaper() - { - return static::$escaper ??= new Escaper('utf-8'); - } + /** + * Get the escaper instance (and create if needed) + * + * @return \Laminas\Escaper\Escaper + */ + protected static function escaper() + { + return static::$escaper ??= new Escaper('utf-8'); + } - /** - * Escape HTML element content - * - * This can be used to put untrusted data directly into the HTML body somewhere. - * This includes inside normal tags like div, p, b, td, etc. - * - * Escapes &, <, >, ", and ' with HTML entity encoding to prevent switching - * into any execution context, such as script, style, or event handlers. - * - * ...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE... - *
    ...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...
    - * - * @param string $string - * @return string - */ - public static function html($string) - { - return static::escaper()->escapeHtml($string); - } + /** + * Escape HTML element content + * + * This can be used to put untrusted data directly into the HTML body somewhere. + * This includes inside normal tags like div, p, b, td, etc. + * + * Escapes &, <, >, ", and ' with HTML entity encoding to prevent switching + * into any execution context, such as script, style, or event handlers. + * + * ...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE... + *
    ...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...
    + * + * @param string $string + * @return string + */ + public static function html($string) + { + return static::escaper()->escapeHtml($string); + } - /** - * Escape JavaScript data values - * - * This can be used to put dynamically generated JavaScript code - * into both script blocks and event-handler attributes. - * - * - * - *
    - * - * @param string $string - * @return string - */ - public static function js($string) - { - return static::escaper()->escapeJs($string); - } + /** + * Escape JavaScript data values + * + * This can be used to put dynamically generated JavaScript code + * into both script blocks and event-handler attributes. + * + * + * + *
    + * + * @param string $string + * @return string + */ + public static function js($string) + { + return static::escaper()->escapeJs($string); + } - /** - * Escape URL parameter values - * - * This can be used to put untrusted data into HTTP GET parameter values. - * This should not be used to escape an entire URI. - * - * link - * - * @param string $string - * @return string - */ - public static function url($string) - { - return rawurlencode($string); - } + /** + * Escape URL parameter values + * + * This can be used to put untrusted data into HTTP GET parameter values. + * This should not be used to escape an entire URI. + * + * link + * + * @param string $string + * @return string + */ + public static function url($string) + { + return rawurlencode($string); + } - /** - * Escape XML element content - * - * Removes offending characters that could be wrongfully interpreted as XML markup. - * - * The following characters are reserved in XML and will be replaced with their - * corresponding XML entities: - * - * ' is replaced with ' - * " is replaced with " - * & is replaced with & - * < is replaced with < - * > is replaced with > - * - * @param string $string - * @return string - */ - public static function xml($string) - { - return htmlspecialchars($string, ENT_QUOTES | ENT_XML1, 'UTF-8'); - } + /** + * Escape XML element content + * + * Removes offending characters that could be wrongfully interpreted as XML markup. + * + * The following characters are reserved in XML and will be replaced with their + * corresponding XML entities: + * + * ' is replaced with ' + * " is replaced with " + * & is replaced with & + * < is replaced with < + * > is replaced with > + * + * @param string $string + * @return string + */ + public static function xml($string) + { + return htmlspecialchars($string, ENT_QUOTES | ENT_XML1, 'UTF-8'); + } } diff --git a/kirby/src/Toolkit/Facade.php b/kirby/src/Toolkit/Facade.php index 6b3b10c..bf72974 100755 --- a/kirby/src/Toolkit/Facade.php +++ b/kirby/src/Toolkit/Facade.php @@ -14,23 +14,23 @@ namespace Kirby\Toolkit; */ abstract class Facade { - /** - * Returns the instance that should be - * available statically - * - * @return mixed - */ - abstract public static function instance(); + /** + * Returns the instance that should be + * available statically + * + * @return mixed + */ + abstract public static function instance(); - /** - * Proxy for all public instance calls - * - * @param string $method - * @param array $args - * @return mixed - */ - public static function __callStatic(string $method, array $args = null) - { - return static::instance()->$method(...$args); - } + /** + * Proxy for all public instance calls + * + * @param string $method + * @param array $args + * @return mixed + */ + public static function __callStatic(string $method, array $args = null) + { + return static::instance()->$method(...$args); + } } diff --git a/kirby/src/Toolkit/Html.php b/kirby/src/Toolkit/Html.php index 057d0f6..b334216 100755 --- a/kirby/src/Toolkit/Html.php +++ b/kirby/src/Toolkit/Html.php @@ -17,621 +17,621 @@ use Kirby\Http\Url; */ class Html extends Xml { - /** - * An internal store for an HTML entities translation table - * - * @var array - */ - public static $entities; - - /** - * List of HTML tags that can be used inline - * - * @var array - */ - public static $inlineList = [ - 'b', - 'i', - 'small', - 'abbr', - 'cite', - 'code', - 'dfn', - 'em', - 'kbd', - 'strong', - 'samp', - 'var', - 'a', - 'bdo', - 'br', - 'img', - 'q', - 'span', - 'sub', - 'sup' - ]; - - /** - * Closing string for void tags; - * can be used to switch to trailing slashes if required - * - * ```php - * Html::$void = ' />' - * ``` - * - * @var string - */ - public static $void = '>'; - - /** - * List of HTML tags that are considered to be self-closing - * - * @var array - */ - public static $voidList = [ - 'area', - 'base', - 'br', - 'col', - 'command', - 'embed', - 'hr', - 'img', - 'input', - 'keygen', - 'link', - 'meta', - 'param', - 'source', - 'track', - 'wbr' - ]; - - /** - * Generic HTML tag generator - * Can be called like `Html::p('A paragraph', ['class' => 'text'])` - * - * @param string $tag Tag name - * @param array $arguments Further arguments for the Html::tag() method - * @return string - */ - public static function __callStatic(string $tag, array $arguments = []): string - { - if (static::isVoid($tag) === true) { - return static::tag($tag, null, ...$arguments); - } - - return static::tag($tag, ...$arguments); - } - - /** - * Generates an `` tag; automatically supports mailto: and tel: links - * - * @param string $href The URL for the `` tag - * @param string|array|null $text The optional text; if `null`, the URL will be used as text - * @param array $attr Additional attributes for the tag - * @return string The generated HTML - */ - public static function a(string $href, $text = null, array $attr = []): string - { - if (Str::startsWith($href, 'mailto:')) { - return static::email(substr($href, 7), $text, $attr); - } - - if (Str::startsWith($href, 'tel:')) { - return static::tel(substr($href, 4), $text, $attr); - } - - return static::link($href, $text, $attr); - } - - /** - * Generates a single attribute or a list of attributes - * - * @param string|array $name String: A single attribute with that name will be generated. - * Key-value array: A list of attributes will be generated. Don't pass a second argument in that case. - * @param mixed $value If used with a `$name` string, pass the value of the attribute here. - * If used with a `$name` array, this can be set to `false` to disable attribute sorting. - * @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 The generated HTML attributes string - */ - public static function attr($name, $value = null, ?string $before = null, ?string $after = null): ?string - { - // HTML supports boolean attributes without values - if (is_array($name) === false && is_bool($value) === true) { - return $value === true ? strtolower($name) : null; - } - - // all other cases can share the XML variant - $attr = parent::attr($name, $value); - - if ($attr === null) { - return null; - } - - // HTML supports named entities - $entities = parent::entities(); - $html = array_keys($entities); - $xml = array_values($entities); - $attr = str_replace($xml, $html, $attr); - - if ($attr) { - return $before . $attr . $after; - } - - return null; - } - - /** - * Converts lines in a string into HTML breaks - * - * @param string $string - * @return string - */ - public static function breaks(string $string): string - { - return nl2br($string); - } - - /** - * Generates an `` tag with `mailto:` - * - * @param string $email The email address - * @param string|array|null $text The optional text; if `null`, the email address will be used as text - * @param array $attr Additional attributes for the tag - * @return string The generated HTML - */ - public static function email(string $email, $text = null, array $attr = []): string - { - if (empty($email) === true) { - return ''; - } - - if (empty($text) === true) { - // show only the email address without additional parameters - $address = Str::contains($email, '?') ? Str::before($email, '?') : $email; - - $text = [Str::encode($address)]; - } - - $email = Str::encode($email); - $attr = array_merge([ - 'href' => [ - 'value' => 'mailto:' . $email, - 'escape' => false - ] - ], $attr); - - // add rel=noopener to target blank links to improve security - $attr['rel'] = static::rel($attr['rel'] ?? null, $attr['target'] ?? null); - - return static::tag('a', $text, $attr); - } - - /** - * Converts a string to an HTML-safe string - * - * @param string|null $string - * @param bool $keepTags If true, existing tags won't be escaped - * @return string The HTML string - * - * @psalm-suppress ParamNameMismatch - */ - public static function encode(?string $string, bool $keepTags = false): string - { - if ($string === null) { - return ''; - } - - if ($keepTags === true) { - $list = static::entities(); - unset($list['"'], $list['<'], $list['>'], $list['&']); - - $search = array_keys($list); - $values = array_values($list); - - return str_replace($search, $values, $string); - } - - return htmlentities($string, ENT_QUOTES, 'utf-8'); - } - - /** - * Returns the entity translation table - * - * @return array - */ - public static function entities(): array - { - return self::$entities ??= get_html_translation_table(HTML_ENTITIES); - } - - /** - * Creates a `
    ` tag with optional caption - * - * @param string|array $content Contents of the `
    ` tag - * @param string|array $caption Optional `
    ` text to use - * @param array $attr Additional attributes for the `
    ` tag - * @return string The generated HTML - */ - public static function figure($content, $caption = '', array $attr = []): string - { - if ($caption) { - $figcaption = static::tag('figcaption', $caption); - - if (is_string($content) === true) { - $content = [static::encode($content, false)]; - } - - $content[] = $figcaption; - } - - return static::tag('figure', $content, $attr); - } - - /** - * Embeds a GitHub Gist - * - * @param string $url Gist URL - * @param string|null $file Optional specific file to embed - * @param array $attr Additional attributes for the `