This repository has been archived by the owner on Feb 13, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
107 lines (101 loc) · 3.79 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
@include_once __DIR__ . '/vendor/autoload.php';
Kirby::plugin('bnomei/srcset', [
'options' => [
'lazy' => 'lazyload',
'prefix' => 'data-',
'autosizes' => 'auto',
'figure' => true,
'ratio' => 'lazysrcset-ratio',
'nonce' => function () {
$nonce = site()->nonce();
if (is_a($nonce, \Kirby\Cms\Field::class)) {
$nonce = $nonce->isNotEmpty() ? $nonce->value() : null;
}
return $nonce;
},
],
'snippets' => [
'editor/srcset' => __DIR__ . '/snippets/srcset.php',
],
'fileMethods' => [
'lazysrcset' => function ($options = []) {
if ($this === null) {
return \Kirby\Cms\Html::img('', ['alt' => 'lazysrcset can not create srcset from null in fileMethod']);
}
if (is_string($options)) {
$options = ['sizes' => $options];
}
$lazySrcset = new \Bnomei\Srcset($this, $options);
return $lazySrcset->html();
},
'lazySrcset' => function ($options = []) {
if ($this === null) {
return \Kirby\Cms\Html::img('', ['alt' => 'lazysrcset can not create srcset from null in fileMethod']);
}
if (is_string($options)) {
$options = ['sizes' => $options];
}
$lazySrcset = new \Bnomei\Srcset($this, $options);
return $lazySrcset->html();
},
],
'tags' => [
'lazysrcset' => [
'attr' => array_merge(
Kirby\Text\KirbyTag::$types['image']['attr'],
\Bnomei\Srcset::kirbytagAttrs()
),
'html' => function ($tag) {
if ($tag === null || \image($tag->value) === null) {
return \Kirby\Cms\Html::img('', ['alt' => 'lazysrcset can not create srcset from null in Kirbytag [' . print_r($tag, true) . ']']);
}
$srcsetTag = new \Bnomei\Srcset($tag);
return $srcsetTag->html();
},
],
],
'components' => [
'markdown' => function (Kirby $kirby, string $text = null, array $options = [], bool $inline = false) {
static $markdown;
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) {
$markdown = new \Kirby\Text\Markdown($options);
$config = $options;
}
$text = $markdown->parse($text, $inline);
if (strpos($text, "<srcsetplugin>") !== false) {
$text = preg_replace_callback("/\n\n<\/?srcsetplugin>\n\n/", function () {
return '';
}, $text);
}
return $text;
}
],
'api' => [
'routes' => [
[
'pattern' => 'bnomei/srcset/options',
'action' => function () {
return \Bnomei\Srcset::defaultOptions();
}
],
],
],
'translations' => [
'de' => require __DIR__ . '/i18n/de.php',
'en' => require __DIR__ . '/i18n/en.php',
'es' => require __DIR__ . '/i18n/es.php',
'fr' => require __DIR__ . '/i18n/fr.php',
'it' => require __DIR__ . '/i18n/it.php',
'lt' => require __DIR__ . '/i18n/lt.php',
'nl' => require __DIR__ . '/i18n/nl.php',
'pt_BR' => require __DIR__ . '/i18n/pt_BR.php',
'pt_PT' => require __DIR__ . '/i18n/pt_PT.php',
'ru' => require __DIR__ . '/i18n/ru.php',
'sv_SE' => require __DIR__ . '/i18n/sv_SE.php',
'tr' => require __DIR__ . '/i18n/tr.php',
],
]);