2015-01-24 16:54:18 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Name: Varnish Purger
|
|
|
|
* Author: Shish <webmaster@shishnet.org>
|
|
|
|
* License: GPLv2
|
|
|
|
* Visibility: admin
|
|
|
|
* Description: Sends PURGE requests when a /post/view is updated
|
|
|
|
*/
|
|
|
|
|
|
|
|
class VarnishPurger extends Extension {
|
|
|
|
private function curl_purge($path) {
|
2015-09-20 23:10:33 +01:00
|
|
|
// waiting for curl timeout adds ~5 minutes to unit tests
|
|
|
|
if(defined("UNITTEST")) return;
|
|
|
|
|
2015-01-24 16:54:18 +00:00
|
|
|
$url = make_http(make_link($path));
|
|
|
|
$ch = curl_init();
|
2015-09-20 16:46:49 +01:00
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
2015-01-24 16:54:18 +00:00
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PURGE");
|
2015-09-20 16:46:49 +01:00
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
2015-01-24 16:54:18 +00:00
|
|
|
$result = curl_exec($ch);
|
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
curl_close($ch);
|
2015-09-20 23:10:33 +01:00
|
|
|
//return $result;
|
2015-01-24 16:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function onCommentPosting(CommentPostingEvent $event) {
|
|
|
|
$this->curl_purge("post/view/{$event->image_id}");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onImageInfoSet(ImageInfoSetEvent $event) {
|
|
|
|
$this->curl_purge("post/view/{$event->image->id}");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onImageDeletion(ImageDeletionEvent $event) {
|
|
|
|
$this->curl_purge("post/view/{$event->image->id}");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
2017-09-19 18:55:43 +01:00
|
|
|
public function get_priority(): int {return 99;}
|
2015-01-24 16:54:18 +00:00
|
|
|
}
|