= $block->code()->html(false) ?>
3 |
--------------------------------------------------------------------------------
/kirby/config/blocks/code/code.yml:
--------------------------------------------------------------------------------
1 | name: field.blocks.code.name
2 | icon: code
3 | wysiwyg: true
4 | preview: code
5 | fields:
6 | code:
7 | label: field.blocks.code.name
8 | type: textarea
9 | placeholder: field.blocks.code.placeholder
10 | buttons: false
11 | font: monospace
12 | language:
13 | label: field.blocks.code.language
14 | type: select
15 | default: text
16 | options:
17 | bash: Bash
18 | basic: BASIC
19 | c: C
20 | clojure: Clojure
21 | cpp: C++
22 | csharp: C#
23 | css: CSS
24 | diff: Diff
25 | elixir: Elixir
26 | elm: Elm
27 | erlang: Erlang
28 | go: Go
29 | graphql: GraphQL
30 | haskell: Haskell
31 | html: HTML
32 | java: Java
33 | js: JavaScript
34 | json: JSON
35 | latext: LaTeX
36 | less: Less
37 | lisp: Lisp
38 | lua: Lua
39 | makefile: Makefile
40 | markdown: Markdown
41 | markup: Markup
42 | objectivec: Objective-C
43 | pascal: Pascal
44 | perl: Perl
45 | php: PHP
46 | text: Plain Text
47 | python: Python
48 | r: R
49 | ruby: Ruby
50 | rust: Rust
51 | sass: Sass
52 | scss: SCSS
53 | shell: Shell
54 | sql: SQL
55 | swift: Swift
56 | typescript: TypeScript
57 | vbnet: VB.net
58 | xml: XML
59 | yaml: YAML
60 |
--------------------------------------------------------------------------------
/kirby/config/blocks/gallery/gallery.php:
--------------------------------------------------------------------------------
1 |
2 | 3 | = $block->text() ?> 4 | citation()->isNotEmpty()): ?> 5 | 8 | 9 |10 | -------------------------------------------------------------------------------- /kirby/config/blocks/quote/quote.yml: -------------------------------------------------------------------------------- 1 | name: field.blocks.quote.name 2 | icon: quote 3 | wysiwyg: true 4 | preview: quote 5 | fields: 6 | text: 7 | label: field.blocks.quote.text.label 8 | placeholder: field.blocks.quote.text.placeholder 9 | type: writer 10 | inline: true 11 | icon: quote 12 | citation: 13 | label: field.blocks.quote.citation.label 14 | placeholder: field.blocks.quote.citation.placeholder 15 | type: writer 16 | inline: true 17 | icon: user 18 | -------------------------------------------------------------------------------- /kirby/config/blocks/table/table.yml: -------------------------------------------------------------------------------- 1 | name: Table 2 | icon: menu 3 | preview: table 4 | -------------------------------------------------------------------------------- /kirby/config/blocks/text/text.php: -------------------------------------------------------------------------------- 1 | 2 | = $block->text(); 3 | -------------------------------------------------------------------------------- /kirby/config/blocks/text/text.yml: -------------------------------------------------------------------------------- 1 | name: field.blocks.text.name 2 | icon: text 3 | wysiwyg: true 4 | preview: text 5 | fields: 6 | text: 7 | type: writer 8 | nodes: false 9 | placeholder: field.blocks.text.placeholder 10 | -------------------------------------------------------------------------------- /kirby/config/blocks/video/video.php: -------------------------------------------------------------------------------- 1 | 2 | url()->isNotEmpty()): ?> 3 |
21 | * // put an item in the cache for 15 minutes
22 | * $cache->set('value', 'my value', 15);
23 | *
24 | *
25 | * @param string $key
26 | * @param mixed $value
27 | * @param int $minutes
28 | * @return bool
29 | */
30 | public function set(string $key, $value, int $minutes = 0): bool
31 | {
32 | return true;
33 | }
34 |
35 | /**
36 | * Internal method to retrieve the raw cache value;
37 | * needs to return a Value object or null if not found
38 | *
39 | * @param string $key
40 | * @return \Kirby\Cache\Value|null
41 | */
42 | public function retrieve(string $key)
43 | {
44 | return null;
45 | }
46 |
47 | /**
48 | * Removes an item from the cache and returns
49 | * whether the operation was successful
50 | *
51 | * @param string $key
52 | * @return bool
53 | */
54 | public function remove(string $key): bool
55 | {
56 | return true;
57 | }
58 |
59 | /**
60 | * Flushes the entire cache and returns
61 | * whether the operation was successful
62 | *
63 | * @return bool
64 | */
65 | public function flush(): bool
66 | {
67 | return true;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/kirby/src/Cms/FilePermissions.php:
--------------------------------------------------------------------------------
1 |
10 | * @link https://getkirby.com
11 | * @copyright Bastian Allgeier GmbH
12 | * @license https://getkirby.com/license
13 | */
14 | class FilePermissions extends ModelPermissions
15 | {
16 | protected $category = 'files';
17 | }
18 |
--------------------------------------------------------------------------------
/kirby/src/Cms/Html.php:
--------------------------------------------------------------------------------
1 |
12 | * @link https://getkirby.com
13 | * @copyright Bastian Allgeier GmbH
14 | * @license https://getkirby.com/license
15 | */
16 | class Html extends \Kirby\Toolkit\Html
17 | {
18 | /**
19 | * Generates an `a` tag with an absolute Url
20 | *
21 | * @param string|null $href Relative or absolute Url
22 | * @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
23 | * @param array $attr Additional attributes for the a tag.
24 | * @return string
25 | */
26 | public static function link(string $href = null, $text = null, array $attr = []): string
27 | {
28 | return parent::link(Url::to($href), $text, $attr);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/kirby/src/Cms/KirbyTag.php:
--------------------------------------------------------------------------------
1 |
11 | * @link https://getkirby.com
12 | * @copyright Bastian Allgeier GmbH
13 | * @license https://getkirby.com/license
14 | */
15 | class KirbyTag extends \Kirby\Text\KirbyTag
16 | {
17 | /**
18 | * Finds a file for the given path.
19 | * The method first searches the file
20 | * in the current parent, if it's a page.
21 | * Afterwards it uses Kirby's global file finder.
22 | *
23 | * @param string $path
24 | * @return \Kirby\Cms\File|null
25 | */
26 | public function file(string $path)
27 | {
28 | $parent = $this->parent();
29 |
30 | if (
31 | is_object($parent) === true &&
32 | method_exists($parent, 'file') === true &&
33 | $file = $parent->file($path)
34 | ) {
35 | return $file;
36 | }
37 |
38 | if (is_a($parent, 'Kirby\Cms\File') === true && $file = $parent->page()->file($path)) {
39 | return $file;
40 | }
41 |
42 | return $this->kirby()->file($path, null, true);
43 | }
44 |
45 | /**
46 | * Returns the current Kirby instance
47 | *
48 | * @return \Kirby\Cms\App
49 | */
50 | public function kirby()
51 | {
52 | return $this->data['kirby'] ?? App::instance();
53 | }
54 |
55 | /**
56 | * Returns the parent model
57 | *
58 | * @return \Kirby\Cms\Model|null
59 | */
60 | public function parent()
61 | {
62 | return $this->data['parent'];
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/kirby/src/Cms/KirbyTags.php:
--------------------------------------------------------------------------------
1 |
11 | * @link https://getkirby.com
12 | * @copyright Bastian Allgeier GmbH
13 | * @license https://getkirby.com/license
14 | */
15 | class KirbyTags extends \Kirby\Text\KirbyTags
16 | {
17 | /**
18 | * The KirbyTag rendering class
19 | *
20 | * @var string
21 | */
22 | protected static $tagClass = 'Kirby\Cms\KirbyTag';
23 |
24 | /**
25 | * @param string|null $text
26 | * @param array $data
27 | * @param array $options
28 | * @param \Kirby\Cms\App|null $app
29 | * @return string
30 | */
31 | public static function parse(string $text = null, array $data = [], array $options = [], ?App $app = null): string
32 | {
33 | if ($app !== null) {
34 | $text = $app->apply('kirbytags:before', compact('text', 'data', 'options'), 'text');
35 | }
36 |
37 | $text = parent::parse($text, $data, $options);
38 |
39 | if ($app !== null) {
40 | $text = $app->apply('kirbytags:after', compact('text', 'data', 'options'), 'text');
41 | }
42 |
43 | return $text;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/kirby/src/Cms/LayoutColumns.php:
--------------------------------------------------------------------------------
1 |
11 | * @link https://getkirby.com
12 | * @copyright Bastian Allgeier GmbH
13 | * @license https://getkirby.com/license
14 | */
15 | class LayoutColumns extends Items
16 | {
17 | const ITEM_CLASS = '\Kirby\Cms\LayoutColumn';
18 | }
19 |
--------------------------------------------------------------------------------
/kirby/src/Cms/Layouts.php:
--------------------------------------------------------------------------------
1 |
14 | * @link https://getkirby.com
15 | * @copyright Bastian Allgeier GmbH
16 | * @license https://getkirby.com/license
17 | */
18 | class Layouts extends Items
19 | {
20 | const ITEM_CLASS = '\Kirby\Cms\Layout';
21 |
22 | public static function factory(array $items = null, array $params = [])
23 | {
24 | $first = $items[0] ?? [];
25 |
26 | // if there are no wrapping layouts for blocks yet …
27 | if (array_key_exists('content', $first) === true || array_key_exists('type', $first) === true) {
28 | $items = [
29 | [
30 | 'id' => uuid(),
31 | 'columns' => [
32 | [
33 | 'width' => '1/1',
34 | 'blocks' => $items
35 | ]
36 | ]
37 | ]
38 | ];
39 | }
40 |
41 | return parent::factory($items, $params);
42 | }
43 |
44 | /**
45 | * Parse layouts data
46 | *
47 | * @param array|string $input
48 | * @return array
49 | */
50 | public static function parse($input): array
51 | {
52 | if (empty($input) === false && is_array($input) === false) {
53 | try {
54 | $input = Data::decode($input, 'json');
55 | } catch (Throwable $e) {
56 | return [];
57 | }
58 | }
59 |
60 | if (empty($input) === true) {
61 | return [];
62 | }
63 |
64 | return $input;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/kirby/src/Cms/Nest.php:
--------------------------------------------------------------------------------
1 |
15 | * @link https://getkirby.com
16 | * @copyright Bastian Allgeier GmbH
17 | * @license https://getkirby.com/license
18 | */
19 | class Nest
20 | {
21 | /**
22 | * @param $data
23 | * @param null $parent
24 | * @return mixed
25 | */
26 | public static function create($data, $parent = null)
27 | {
28 | if (is_scalar($data) === true) {
29 | return new Field($parent, $data, $data);
30 | }
31 |
32 | $result = [];
33 |
34 | foreach ($data as $key => $value) {
35 | if (is_array($value) === true) {
36 | $result[$key] = static::create($value, $parent);
37 | } elseif (is_scalar($value) === true) {
38 | $result[$key] = new Field($parent, $key, $value);
39 | }
40 | }
41 |
42 | if (is_int(key($data))) {
43 | return new NestCollection($result);
44 | } else {
45 | return new NestObject($result);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/kirby/src/Cms/NestCollection.php:
--------------------------------------------------------------------------------
1 |
13 | * @link https://getkirby.com
14 | * @copyright Bastian Allgeier GmbH
15 | * @license https://getkirby.com/license
16 | */
17 | class NestCollection extends BaseCollection
18 | {
19 | /**
20 | * Converts all objects in the collection
21 | * to an array. This can also take a callback
22 | * function to further modify the array result.
23 | *
24 | * @param \Closure|null $map
25 | * @return array
26 | */
27 | public function toArray(Closure $map = null): array
28 | {
29 | return parent::toArray($map ?? function ($object) {
30 | return $object->toArray();
31 | });
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/kirby/src/Cms/NestObject.php:
--------------------------------------------------------------------------------
1 |
12 | * @link https://getkirby.com
13 | * @copyright Bastian Allgeier GmbH
14 | * @license https://getkirby.com/license
15 | */
16 | class NestObject extends Obj
17 | {
18 | /**
19 | * Converts the object to an array
20 | *
21 | * @return array
22 | */
23 | public function toArray(): array
24 | {
25 | $result = [];
26 |
27 | foreach ((array)$this as $key => $value) {
28 | if (is_a($value, 'Kirby\Cms\Field') === true) {
29 | $result[$key] = $value->value();
30 | continue;
31 | }
32 |
33 | if (is_object($value) === true && method_exists($value, 'toArray')) {
34 | $result[$key] = $value->toArray();
35 | continue;
36 | }
37 |
38 | $result[$key] = $value;
39 | }
40 |
41 | return $result;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/kirby/src/Cms/PagePermissions.php:
--------------------------------------------------------------------------------
1 |
10 | * @link https://getkirby.com
11 | * @copyright Bastian Allgeier GmbH
12 | * @license https://getkirby.com/license
13 | */
14 | class PagePermissions extends ModelPermissions
15 | {
16 | /**
17 | * @var string
18 | */
19 | protected $category = 'pages';
20 |
21 | /**
22 | * @return bool
23 | */
24 | protected function canChangeSlug(): bool
25 | {
26 | return $this->model->isHomeOrErrorPage() !== true;
27 | }
28 |
29 | /**
30 | * @return bool
31 | */
32 | protected function canChangeStatus(): bool
33 | {
34 | return $this->model->isErrorPage() !== true;
35 | }
36 |
37 | /**
38 | * @return bool
39 | */
40 | protected function canChangeTemplate(): bool
41 | {
42 | if ($this->model->isHomeOrErrorPage() === true) {
43 | return false;
44 | }
45 |
46 | if (count($this->model->blueprints()) <= 1) {
47 | return false;
48 | }
49 |
50 | return true;
51 | }
52 |
53 | /**
54 | * @return bool
55 | */
56 | protected function canDelete(): bool
57 | {
58 | return $this->model->isHomeOrErrorPage() !== true;
59 | }
60 |
61 | /**
62 | * @return bool
63 | */
64 | protected function canSort(): bool
65 | {
66 | if ($this->model->isErrorPage() === true) {
67 | return false;
68 | }
69 |
70 | if ($this->model->isListed() !== true) {
71 | return false;
72 | }
73 |
74 | if ($this->model->blueprint()->num() !== 'default') {
75 | return false;
76 | }
77 |
78 | return true;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/kirby/src/Cms/R.php:
--------------------------------------------------------------------------------
1 |
12 | * @link https://getkirby.com
13 | * @copyright Bastian Allgeier GmbH
14 | * @license https://getkirby.com/license
15 | */
16 | class R extends Facade
17 | {
18 | /**
19 | * @return \Kirby\Http\Request
20 | */
21 | public static function instance()
22 | {
23 | return App::instance()->request();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/kirby/src/Cms/Response.php:
--------------------------------------------------------------------------------
1 |
11 | * @link https://getkirby.com
12 | * @copyright Bastian Allgeier GmbH
13 | * @license https://getkirby.com/license
14 | */
15 | class Response extends \Kirby\Http\Response
16 | {
17 | /**
18 | * Adjusted redirect creation which
19 | * parses locations with the Url::to method
20 | * first.
21 | *
22 | * @param string $location
23 | * @param int $code
24 | * @return static
25 | */
26 | public static function redirect(string $location = '/', int $code = 302)
27 | {
28 | return parent::redirect(Url::to($location), $code);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/kirby/src/Cms/S.php:
--------------------------------------------------------------------------------
1 |
12 | * @link https://getkirby.com
13 | * @copyright Bastian Allgeier GmbH
14 | * @license https://getkirby.com/license
15 | */
16 | class S extends Facade
17 | {
18 | /**
19 | * @return \Kirby\Session\Session
20 | */
21 | public static function instance()
22 | {
23 | return App::instance()->session();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/kirby/src/Cms/Search.php:
--------------------------------------------------------------------------------
1 |
13 | * @link https://getkirby.com
14 | * @copyright Bastian Allgeier GmbH
15 | * @license https://getkirby.com/license
16 | */
17 | class Search
18 | {
19 | /**
20 | * @param string|null $query
21 | * @param array $params
22 | * @return \Kirby\Cms\Files
23 | */
24 | public static function files(string $query = null, $params = [])
25 | {
26 | return App::instance()->site()->index()->files()->search($query, $params);
27 | }
28 |
29 | /**
30 | * Native search method to search for anything within the collection
31 | *
32 | * @param \Kirby\Cms\Collection $collection
33 | * @param string|null $query
34 | * @param mixed $params
35 | * @return \Kirby\Cms\Collection|bool
36 | */
37 | public static function collection(Collection $collection, string $query = null, $params = [])
38 | {
39 | $kirby = App::instance();
40 | return ($kirby->component('search'))($kirby, $collection, $query, $params);
41 | }
42 |
43 | /**
44 | * @param string|null $query
45 | * @param array $params
46 | * @return \Kirby\Cms\Pages
47 | */
48 | public static function pages(string $query = null, $params = [])
49 | {
50 | return App::instance()->site()->index()->search($query, $params);
51 | }
52 |
53 | /**
54 | * @param string|null $query
55 | * @param array $params
56 | * @return \Kirby\Cms\Users
57 | */
58 | public static function users(string $query = null, $params = [])
59 | {
60 | return App::instance()->users()->search($query, $params);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/kirby/src/Cms/SiteBlueprint.php:
--------------------------------------------------------------------------------
1 |
11 | * @link https://getkirby.com
12 | * @copyright Bastian Allgeier GmbH
13 | * @license https://getkirby.com/license
14 | */
15 | class SiteBlueprint extends Blueprint
16 | {
17 | /**
18 | * Creates a new page blueprint object
19 | * with the given props
20 | *
21 | * @param array $props
22 | */
23 | public function __construct(array $props)
24 | {
25 | parent::__construct($props);
26 |
27 | // normalize all available page options
28 | $this->props['options'] = $this->normalizeOptions(
29 | $props['options'] ?? true,
30 | // defaults
31 | [
32 | 'changeTitle' => null,
33 | 'update' => null,
34 | ],
35 | // aliases
36 | [
37 | 'title' => 'changeTitle',
38 | ]
39 | );
40 | }
41 |
42 | /**
43 | * Returns the preview settings
44 | * The preview setting controls the "Open"
45 | * button in the panel and redirects it to a
46 | * different URL if necessary.
47 | *
48 | * @return string|bool
49 | */
50 | public function preview()
51 | {
52 | $preview = $this->props['options']['preview'] ?? true;
53 |
54 | if (is_string($preview) === true) {
55 | return $this->model->toString($preview);
56 | }
57 |
58 | return $preview;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/kirby/src/Cms/SitePermissions.php:
--------------------------------------------------------------------------------
1 |
10 | * @link https://getkirby.com
11 | * @copyright Bastian Allgeier GmbH
12 | * @license https://getkirby.com/license
13 | */
14 | class SitePermissions extends ModelPermissions
15 | {
16 | protected $category = 'site';
17 | }
18 |
--------------------------------------------------------------------------------
/kirby/src/Cms/SiteRules.php:
--------------------------------------------------------------------------------
1 |
14 | * @link https://getkirby.com
15 | * @copyright Bastian Allgeier GmbH
16 | * @license https://getkirby.com/license
17 | */
18 | class SiteRules
19 | {
20 | /**
21 | * Validates if the site title can be changed
22 | *
23 | * @param \Kirby\Cms\Site $site
24 | * @param string $title
25 | * @return bool
26 | * @throws \Kirby\Exception\InvalidArgumentException If the title is empty
27 | * @throws \Kirby\Exception\PermissionException If the user is not allowed to change the title
28 | */
29 | public static function changeTitle(Site $site, string $title): bool
30 | {
31 | if ($site->permissions()->changeTitle() !== true) {
32 | throw new PermissionException(['key' => 'site.changeTitle.permission']);
33 | }
34 |
35 | if (Str::length($title) === 0) {
36 | throw new InvalidArgumentException(['key' => 'site.changeTitle.empty']);
37 | }
38 |
39 | return true;
40 | }
41 |
42 | /**
43 | * Validates if the site can be updated
44 | *
45 | * @param \Kirby\Cms\Site $site
46 | * @param array $content
47 | * @return bool
48 | * @throws \Kirby\Exception\PermissionException If the user is not allowed to update the site
49 | */
50 | public static function update(Site $site, array $content = []): bool
51 | {
52 | if ($site->permissions()->update() !== true) {
53 | throw new PermissionException(['key' => 'site.update.permission']);
54 | }
55 |
56 | return true;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/kirby/src/Cms/UserBlueprint.php:
--------------------------------------------------------------------------------
1 |
11 | * @link https://getkirby.com
12 | * @copyright Bastian Allgeier GmbH
13 | * @license https://getkirby.com/license
14 | */
15 | class UserBlueprint extends Blueprint
16 | {
17 | /**
18 | * UserBlueprint constructor.
19 | *
20 | * @param array $props
21 | * @throws \Kirby\Exception\InvalidArgumentException
22 | */
23 | public function __construct(array $props)
24 | {
25 | // normalize and translate the description
26 | $props['description'] = $this->i18n($props['description'] ?? null);
27 |
28 | // register the other props
29 | parent::__construct($props);
30 |
31 | // normalize all available page options
32 | $this->props['options'] = $this->normalizeOptions(
33 | $props['options'] ?? true,
34 | // defaults
35 | [
36 | 'create' => null,
37 | 'changeEmail' => null,
38 | 'changeLanguage' => null,
39 | 'changeName' => null,
40 | 'changePassword' => null,
41 | 'changeRole' => null,
42 | 'delete' => null,
43 | 'update' => null,
44 | ]
45 | );
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/kirby/src/Cms/UserPermissions.php:
--------------------------------------------------------------------------------
1 |
10 | * @link https://getkirby.com
11 | * @copyright Bastian Allgeier GmbH
12 | * @license https://getkirby.com/license
13 | */
14 | class UserPermissions extends ModelPermissions
15 | {
16 | /**
17 | * @var string
18 | */
19 | protected $category = 'users';
20 |
21 | /**
22 | * UserPermissions constructor
23 | *
24 | * @param \Kirby\Cms\Model $model
25 | */
26 | public function __construct(Model $model)
27 | {
28 | parent::__construct($model);
29 |
30 | // change the scope of the permissions, when the current user is this user
31 | $this->category = $this->user && $this->user->is($model) ? 'user' : 'users';
32 | }
33 |
34 | /**
35 | * @return bool
36 | */
37 | protected function canChangeRole(): bool
38 | {
39 | return $this->model->roles()->count() > 1;
40 | }
41 |
42 | /**
43 | * @return bool
44 | */
45 | protected function canCreate(): bool
46 | {
47 | // the admin can always create new users
48 | if ($this->user->isAdmin() === true) {
49 | return true;
50 | }
51 |
52 | // users who are not admins cannot create admins
53 | if ($this->model->isAdmin() === true) {
54 | return false;
55 | }
56 |
57 | return true;
58 | }
59 |
60 | /**
61 | * @return bool
62 | */
63 | protected function canDelete(): bool
64 | {
65 | return $this->model->isLastAdmin() !== true;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/kirby/src/Cms/Visitor.php:
--------------------------------------------------------------------------------
1 |
12 | * @link https://getkirby.com
13 | * @copyright Bastian Allgeier GmbH
14 | * @license https://getkirby.com/license
15 | */
16 | class Visitor extends Facade
17 | {
18 | /**
19 | * @return \Kirby\Http\Visitor
20 | */
21 | public static function instance()
22 | {
23 | return App::instance()->visitor();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/kirby/src/Data/Handler.php:
--------------------------------------------------------------------------------
1 |
15 | * @link https://getkirby.com
16 | * @copyright Bastian Allgeier GmbH
17 | * @license https://opensource.org/licenses/MIT
18 | */
19 | abstract class Handler
20 | {
21 | /**
22 | * Parses an encoded string and returns a multi-dimensional array
23 | *
24 | * Needs to throw an Exception if the file can't be parsed.
25 | *
26 | * @param mixed $string
27 | * @return array
28 | */
29 | abstract public static function decode($string): array;
30 |
31 | /**
32 | * Converts an array to an encoded string
33 | *
34 | * @param mixed $data
35 | * @return string
36 | */
37 | abstract public static function encode($data): string;
38 |
39 | /**
40 | * Reads data from a file
41 | *
42 | * @param string $file
43 | * @return array
44 | */
45 | public static function read(string $file): array
46 | {
47 | $contents = F::read($file);
48 | if ($contents === false) {
49 | throw new Exception('The file "' . $file . '" does not exist');
50 | }
51 |
52 | return static::decode($contents);
53 | }
54 |
55 | /**
56 | * Writes data to a file
57 | *
58 | * @param string $file
59 | * @param mixed $data
60 | * @return bool
61 | */
62 | public static function write(string $file = null, $data = []): bool
63 | {
64 | return F::write($file, static::encode($data));
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/kirby/src/Data/Json.php:
--------------------------------------------------------------------------------
1 |
12 | * @link https://getkirby.com
13 | * @copyright Bastian Allgeier GmbH
14 | * @license https://opensource.org/licenses/MIT
15 | */
16 | class Json extends Handler
17 | {
18 | /**
19 | * Converts an array to an encoded JSON string
20 | *
21 | * @param mixed $data
22 | * @return string
23 | */
24 | public static function encode($data): string
25 | {
26 | return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
27 | }
28 |
29 | /**
30 | * Parses an encoded JSON string and returns a multi-dimensional array
31 | *
32 | * @param mixed $string
33 | * @return array
34 | */
35 | public static function decode($string): array
36 | {
37 | if ($string === null) {
38 | return [];
39 | }
40 |
41 | if (is_array($string) === true) {
42 | return $string;
43 | }
44 |
45 | if (is_string($string) === false) {
46 | throw new InvalidArgumentException('Invalid JSON data; please pass a string');
47 | }
48 |
49 | $result = json_decode($string, true);
50 |
51 | if (is_array($result) === true) {
52 | return $result;
53 | } else {
54 | throw new InvalidArgumentException('JSON string is invalid');
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/kirby/src/Data/Xml.php:
--------------------------------------------------------------------------------
1 |
13 | * @link https://getkirby.com
14 | * @copyright Bastian Allgeier GmbH
15 | * @license https://opensource.org/licenses/MIT
16 | */
17 | class Xml extends Handler
18 | {
19 | /**
20 | * Converts an array to an encoded XML string
21 | *
22 | * @param mixed $data
23 | * @return string
24 | */
25 | public static function encode($data): string
26 | {
27 | return XmlConverter::create($data, 'data');
28 | }
29 |
30 | /**
31 | * Parses an encoded XML string and returns a multi-dimensional array
32 | *
33 | * @param mixed $string
34 | * @return array
35 | */
36 | public static function decode($string): array
37 | {
38 | if ($string === null) {
39 | return [];
40 | }
41 |
42 | if (is_array($string) === true) {
43 | return $string;
44 | }
45 |
46 | if (is_string($string) === false) {
47 | throw new InvalidArgumentException('Invalid XML data; please pass a string');
48 | }
49 |
50 | $result = XmlConverter::parse($string);
51 |
52 | if (is_array($result) === true) {
53 | // remove the root's name if it is the default to ensure that
54 | // the decoded data is the same as the input to the encode() method
55 | if ($result['@name'] === 'data') {
56 | unset($result['@name']);
57 | }
58 |
59 | return $result;
60 | } else {
61 | throw new InvalidArgumentException('XML string is invalid');
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/kirby/src/Database/Sql/Mysql.php:
--------------------------------------------------------------------------------
1 |
12 | * @link https://getkirby.com
13 | * @copyright Bastian Allgeier GmbH
14 | * @license https://opensource.org/licenses/MIT
15 | */
16 | class Mysql extends Sql
17 | {
18 | /**
19 | * Returns a query to list the columns of a specified table;
20 | * the query needs to return rows with a column `name`
21 | *
22 | * @param string $table Table name
23 | * @return array
24 | */
25 | public function columns(string $table): array
26 | {
27 | $databaseBinding = $this->bindingName('database');
28 | $tableBinding = $this->bindingName('table');
29 |
30 | $query = 'SELECT COLUMN_NAME AS name FROM INFORMATION_SCHEMA.COLUMNS ';
31 | $query .= 'WHERE TABLE_SCHEMA = ' . $databaseBinding . ' AND TABLE_NAME = ' . $tableBinding;
32 |
33 | return [
34 | 'query' => $query,
35 | 'bindings' => [
36 | $databaseBinding => $this->database->name(),
37 | $tableBinding => $table,
38 | ]
39 | ];
40 | }
41 |
42 | /**
43 | * Returns a query to list the tables of the current database;
44 | * the query needs to return rows with a column `name`
45 | *
46 | * @return array
47 | */
48 | public function tables(): array
49 | {
50 | $binding = $this->bindingName('database');
51 |
52 | return [
53 | 'query' => 'SELECT TABLE_NAME AS name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ' . $binding,
54 | 'bindings' => [
55 | $binding => $this->database->name()
56 | ]
57 | ];
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/kirby/src/Email/Body.php:
--------------------------------------------------------------------------------
1 | ,
13 | * Nico Hoffmann 4 | This page is currently offline due to an unexpected error. We are very sorry for the inconvenience and will fix it as soon as possible. 5 |
6 |
7 | Advice for developers and administrators:
8 | Enable debug mode to get further information about the error.
9 |
4 | This page is currently offline. We are very sorry for the inconvenience and will fix it as soon as possible. 5 |
6 |
7 | Advice for developers and administrators:
8 | Change the PHP version to 7.3, 7.4 or 8.0 (PHP 7.4 is recommended)
9 |