-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·73 lines (59 loc) · 2.54 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
<?php
Kirby::plugin('splorp/paperback-export', [
'snippets' => [
'paperback-export/content' => __DIR__ . '/snippets/content.php',
],
'routes' => [
[
'pattern' => 'export/paperback',
'action' => function () {
$prefix = option('splorp.paperback-export.prefix', '');
$fields = option('splorp.paperback-export.fields', []);
$includeUnlisted = option('splorp.paperback-export.includeUnlisted', true);
$includeChildren = option('splorp.paperback-export.includeChildren', []);
$excludeTemplate = option('splorp.paperback-export.excludeTemplate', []);
$includeDatestamp = option('splorp.paperback-export.includeDatestamp', false);
if (! is_string($prefix)) {
throw new Exception('The option “splorp.paperback-export.prefix” must be a string.');
}
if (! is_array($fields)) {
throw new Exception('The option “splorp.paperback-export.fields” must be an array.');
}
if (! is_bool($includeUnlisted)) {
throw new Exception('The option “splorp.paperback-export.includeUnlisted” must be a boolean.');
}
if (! is_array($includeChildren)) {
throw new Exception('The option “splorp.paperback-export.includeChildren” must be an array.');
}
if (! is_array($excludeTemplate)) {
throw new Exception('The option “splorp.paperback-export.excludeTemplate” must be an array.');
}
if (! is_bool($includeDatestamp)) {
throw new Exception('The option “splorp.paperback-export.includeDatestamp” must be a boolean.');
}
$languages = site()->languages();
$pages = site()->index();
$title = site()->title();
$description = site()->description();
$version = site()->version();
$filename = str::slug($title);
/* Check whether to include unlisted pages */
if (! $includeUnlisted) {
$pages = $pages->listed();
}
/* Include only the children of specified pages */
if ($includeChildren) {
$pages = $pages->find($includeChildren)->children();
}
/* Exclude pages using specified templates */
$pages = $pages->filterBy('intendedTemplate', 'not in', $excludeTemplate);
/* Check whether to include a datestamp */
if ($includeDatestamp) { $datestamp = date('Y-M-d'); } else { $datestamp = ''; }
/* Define template and variables */
$template = __DIR__ . '/snippets/export.php';
$paperback = tpl::load($template, compact('languages', 'pages', 'title', 'description', 'prefix', 'fields', 'version', 'datestamp', 'filename'));
return new response($paperback, 'txt');
}
]
]
]);