-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
87 lines (81 loc) · 3.58 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
<?php
load([
'Thathoff\\ClearCloudflareCache\\CloudflareCache' => 'src/CloudflareCache.php'
], __DIR__);
use Thathoff\ClearCloudflareCache\CloudflareCache;
Kirby::plugin('thathoff/clearcloudflarecache', [
'options' => [
'cloudflareZoneID' => null,
'cloudflareEmail' => null,
'cloudflareAPIKey' => null,
'dependantUrlsForPage' => function ($hook, $page, $oldPage = null) {
return $oldPage ? [$page->url(), $oldPage->url()] : $page->url();
},
'dependantUrlsForFile' => function ($hook, $file, $oldFile = null) {
$clearParentOnly = in_array($hook, [
'file.changeSort:after',
'file.create:after',
'file.update:after',
]);
$urls = $clearParentOnly ? [$file->parent()->url()] : [$file->url(), $file->parent()->url()];
if ($oldFile && !$clearParentOnly) {
$urls[] = $oldFile->url();
// Shouldn't need to add $oldFile->parent()->url() because the parent should be the same as the "new" file's parent.
}
return $urls;
},
'dependantUrlsForSite' => function ($hook, $site, $oldSite = null) {
return $site->url();
},
],
'hooks' => [
// Page
'page.changeNum:after' => function ($newPage) {
CloudflareCache::handlePageHook('page.changeNum:after', $newPage);
},
'page.changeSlug:after' => function ($newPage, $oldPage) {
CloudflareCache::handlePageHook('page.changeSlug:after', $newPage, $oldPage);
},
'page.changeStatus:after' => function ($newPage) {
CloudflareCache::handlePageHook('page.changeStatus:after', $newPage);
},
'page.changeTemplate:after' => function ($newPage) {
CloudflareCache::handlePageHook('page.changeTemplate:after', $newPage);
},
'page.changeTitle:after' => function ($newPage) {
CloudflareCache::handlePageHook('page.changeTitle:after', $newPage);
},
'page.create:after' => function ($page) {
CloudflareCache::handlePageHook('page.create:after', $page);
},
'page.delete:after' => function ($status, $page) {
CloudflareCache::handlePageHook('page.delete:after', $page);
},
'page.update:after' => function ($newPage, $oldPage) {
CloudflareCache::handlePageHook('page.changeSlug:after', $newPage, $oldPage);
},
// File
'file.changeName:after' => function ($newFile, $oldFile) {
CloudflareCache::handleFileHook('file.changeName:after', $newFile, $oldFile);
},
'file.changeSort:after' => function ($newFile, $oldFile) {
CloudflareCache::handleFileHook('file.changeSort:after', $newFile, $oldFile);
},
'file.create:after' => function ($file) {
CloudflareCache::handleFileHook('file.create:after', $file);
},
'file.delete:after' => function ($status, $file) {
CloudflareCache::handleFileHook('file.delete:after', $file);
},
'file.replace:after' => function ($newFile, $oldFile) {
CloudflareCache::handleFileHook('file.replace:after', $newFile, $oldFile);
},
'file.update:after' => function ($newFile, $oldFile) {
CloudflareCache::handleFileHook('file.update:after', $newFile, $oldFile);
},
// Site
'site.update:after' => function ($newSite, $oldSite) {
CloudflareCache::handleSiteHook('site.update:after', $newSite);
},
],
]);