diff --git a/inc/8chan-mod-pages.php b/inc/8chan-mod-pages.php index 67495517..8d4acb7d 100644 --- a/inc/8chan-mod-pages.php +++ b/inc/8chan-mod-pages.php @@ -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']))); diff --git a/inc/config.php b/inc/config.php index fb749ae4..1d85a544 100644 --- a/inc/config.php +++ b/inc/config.php @@ -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'; diff --git a/inc/functions.php b/inc/functions.php index ec32f1e7..3c8b2366 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -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