This repository was archived by the owner on Feb 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
94 lines (81 loc) · 2.91 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
<?php
namespace Plugin\SecuredPage;
@include_once __DIR__ . '/vendor/autoload.php';
use Kirby;
use Kirby\Cms\Page;
load([
'Plugin\SecuredPage\RouterAfterHook' => 'src/RouterAfterHook.php'
], __DIR__);
Kirby::plugin('kerli81/securedpages', [
'options' => [
'logintype' => 'loginform', // [loginform, custom]
'custom.page' => '',
'loginform.username.name' => 'Username',
'loginform.username.error' => 'Please enter your username',
'loginform.password.name' => 'Password',
'loginform.password.error' => 'Please enter your password',
],
'hooks' => [
'route:after' => function ($route, $path, $method, $result) {
if ($route->env() == 'site') {
// Issue #2: Fixes multi-lang usage
if(!($result instanceof Page)) { $result = null; }
$hook = new RouterAfterHook();
$result = $hook->process($result, $this->user());
if (!$result) {
if (option('kerli81.securedpages.logintype') == 'custom') {
$url = option('kerli81.securedpages.custom.page');
} else {
$url = url('/no-permission', ['query' => ['prevloc' => $path]]);
}
go($url);
}
}
}
],
'routes' => [
[
'pattern' => 'no-permission',
'action' => function () {
if (option('kerli81.securedpages.logintype') == 'loginform') {
return new Page([
'slug' => 'no-permission',
'template' => 'loginform'
]);
}
},
'method' => 'GET|POST'
]
],
'blueprints' => [
'fields/kerli81.securedpages.pageconfiguration' => __DIR__ . '/blueprints/fields/pagesecurity.yml'
],
'snippets' => [
'kerli81.securedpages.loginform' => __DIR__ . '/src/loginform/LoginFormSnippet.php',
'kerli81.securedpages.loginform.css' => __DIR__ . '/src/loginform/loginform.css',
],
'controllers' => [
'loginform' => require __DIR__ . '/src/loginform/LoginFormCtrl.php'
],
'templates' => [
'loginform' => __DIR__ . '/src/loginform/LoginFormTmpl.php'
],
'collectionFilters' => [
'OnlyUserVisiblePages' => function ($collection, $field, $test, $split = false) {
if ($field != "kerli81-securedpages") {
return $collection;
}
$user = kirby()->user();
$hook = new RouterAfterHook();
$result = array();
foreach ($collection as $item) {
if($item instanceof Page) {
if ($hook->process($item, $user)) {
$result[] = $item;
}
}
}
return $result;
}
]
]);