-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
62 lines (55 loc) · 2.34 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
<?php
$DayOfYear = date('z') + 1;
$Year = date("Y");
if(strpos( $_SERVER['HTTP_ACCEPT'], 'image/avif' ) !== false){
$fileExtension = ".avif"; // The file extension of the images with leading dot.
$fileMimeType = "image/avif"; // The mime type of the image files, look here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
} else {
$fileExtension = ".jpg"; // The file extension of the images with leading dot.
$fileMimeType = "image/jpg"; // The mime type of the image files, look here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
}
$baseURL = "https://verse.awesomebible.de/img/"; # URL that points to the root of the image directory, with a trailing slash.
$cacheRef = "cacheFile.txt"; // Edit this to the exact file path for your install of verse + "cacheFile.txt"
$cachedImage = "cachedImage"; // Edit this to the exact file path for your install of verse + "cachedImage"
function cacheStale(){
global $Year;
global $DayOfYear;
global $cacheRef;
global $baseURL;
global $cachedImage;
global $fileExtension;
global $fileMimeType;
// If cache is stale
if(file_exists($cachedImage.$fileExtension)){unlink($cachedImage.$fileExtension);};
if(file_exists($cacheRef)){unlink($cacheRef);};
copy($baseURL.$Year."/".$DayOfYear.$fileExtension, $cachedImage.$fileExtension);
header('Content-type: '.$fileMimeType.';');
echo file_get_contents($cachedImage.$fileExtension);
$CacheFileW = fopen($cacheRef, "w") or die("Unable to open file!");
$txt = "".$DayOfYear."\n";
fwrite($CacheFileW, $txt);
fclose($CacheFileW);
die;
};
function cacheFresh(){
global $cachedImage;
global $fileMimeType;
// If cache is fresh
header('Content-type: '.$fileMimeType.';');
if(file_exists($cachedImage.$fileExtension)){
echo file_get_contents($cachedImage.$fileExtension);
die;
}else{
cacheStale();
};
};
if(file_get_contents($cacheRef) == $DayOfYear && file_exists($cachedImage.$fileExtension)){
cacheFresh();
}else{
cacheStale();
}
echo "Oops, something went wrong. :(";
echo "<br>";
echo "Please contact ";
die();
?>