-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache-reload.php
78 lines (53 loc) · 1.65 KB
/
cache-reload.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
<?php
#######################################################
# What is it?
# This will clean your Kirby file cache folder and
# then rebuild it by checking all pages.
# How to use?
# Put this file in your Kirby website root
# and just go to yoursite.com/cache-reload.php
# You should rename this file for security reason.
# About:
# github.com/yoanmalie/kirby-cache-reload
# yoan-malie.fr
# twitter.com/yoanmalie
#######################################################
// Configs
define('DS', DIRECTORY_SEPARATOR);
$filename = DS . basename(__FILE__);
$urls = [];
$result = [];
// Load kirby
require(__DIR__ . DS . 'kirby' . DS . 'bootstrap.php');
// Clean current cache
$kirby = kirby();
$kirby->configure();
$kirby->cache()->flush();
// Search for all pages
foreach(site()->children() as $page):
$urls[] = str_replace($filename, '', $page->url());
if ($page->hasChildren()):
foreach ($page->children() as $child):
$urls[] = str_replace($filename, '', $child->url());
endforeach;
endif;
endforeach;
// Rebuild a new cache
foreach ($urls as $url) {
$ch = curl_init();
// URL to fetch
curl_setopt($ch, CURLOPT_URL, $url);
// User agent
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP Curl - Kirby cache reload');
// Include header in result?
// (true = yes, false = no)
curl_setopt($ch, CURLOPT_HEADER, true);
// Should cURL return or print out the data?
// (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Execute the given URL, and return output
$result[] = curl_exec($ch);
curl_close($ch);
}