1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-12-11 07:16:10 +01:00

Give purge() the ability to clear CloudFlare cache, fixes caching issues in ?/flags and ?/assets

This commit is contained in:
Fredrick Brennan 2015-05-06 21:37:18 +08:00
parent e8a1b23e10
commit d45852c3dd
3 changed files with 45 additions and 6 deletions

View File

@ -224,7 +224,7 @@
}
copy($upload, "$dir/$id.$extension");
purge("$dir/$id.$extension");
purge("$dir/$id.$extension", true);
$config['user_flags'][$id] = utf8tohtml($description);
file_write($b.'/flags.ser', serialize($config['user_flags']));
}
@ -327,7 +327,6 @@ FLAGS;
if (isset($_FILES['deleted_file']) && !empty($_FILES['deleted_file']['tmp_name'])){
$upload = $_FILES['deleted_file']['tmp_name'];
$extension = strtolower(mb_substr($_FILES['deleted_file']['name'], mb_strrpos($_FILES['deleted_file']['name'], '.') + 1));
var_dump($_FILES);
if (!is_readable($upload)) {
error($config['error']['nomove']);
@ -351,7 +350,7 @@ FLAGS;
unlink("$dir/deleted.png");
copy($upload, "$dir/deleted.png");
purge("$dir/deleted.png");
purge("$dir/deleted.png", true);
}
// Spoiler file
@ -382,7 +381,7 @@ FLAGS;
unlink("$dir/spoiler.png");
copy($upload, "$dir/spoiler.png");
purge("$dir/spoiler.png");
purge("$dir/spoiler.png", true);
}
// No file
@ -412,7 +411,7 @@ FLAGS;
unlink("$dir/no-file.png");
copy($upload, "$dir/no-file.png");
purge("$dir/no-file.png");
purge("$dir/no-file.png", true);
}
mod_page(_('Edit board assets'), 'mod/assets.html', array('board'=>$board,'token'=>make_secure_link_token('assets/'.$board['uri'])));

View File

@ -1787,3 +1787,10 @@
// Use custom assets? (spoiler file, etc; this is used by ?/settings and ?/assets)
$config['custom_assets'] = false;
// If you use CloudFlare set these for some features to work correctly.
$config['cloudflare'] = array();
$config['cloudflare']['enabled'] = false;
$config['cloudflare']['token'] = 'token';
$config['cloudflare']['email'] = 'email';
$config['cloudflare']['domain'] = 'example.com';

View File

@ -589,9 +589,42 @@ function boardTitle($uri) {
return false;
}
function purge($uri) {
function cloudflare_purge($uri) {
global $config;
if (!$config['cloudflare']['enabled']) return;
$fields = array(
'a' => 'zone_file_purge',
'tkn' => $config['cloudflare']['token'],
'email' => $config['cloudflare']['email'],
'z' => $config['cloudflare']['domain'],
'url' => 'https://' . $config['cloudflare']['domain'] . '/' . $uri
);
$fields_string = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.cloudflare.com/api_json.html');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function purge($uri, $cloudflare = false) {
global $config, $debug;
if ($cloudflare) {
cloudflare_purge($uri);
}
if (!isset($config['purge'])) return;
// Fix for Unicode