-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.php
62 lines (56 loc) · 1.5 KB
/
image.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
// image Endpoint
// This endpoint loads a shared image into a webpage
function base64url_encode($data)
{
$b64 = base64_encode($data);
if ($b64 === false) {
return false;
}
$url = strtr($b64, '+/', '-_');
return rtrim($url, '=');
}
function is_valid_base64($str){
if (base64_decode($str, true) !== false){
return true;
} else {
return false;
}
}
$source = $_SERVER['QUERY_STRING'];
//handle Facebook
if (strpos($source, "&fbclid")) {
$source = str_replace("%3D", "=", $source);
$stripFB = explode("&fbclid", $source);
$source = $stripFB[0];
}
$link = "http://";
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')
$link = "https://";
$link .= $_SERVER['HTTP_HOST'];
$link .= $_SERVER['REQUEST_URI'];
$linkParts = explode("image.php", $link);
$link = $linkParts[0] . "download.php?" . $source;
?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#">
<head>
<title>Image Proxy</title>
<style>
body { background-color: white; color:black; }
</style>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta property="og:image" content="<?php echo $link ?>" />
</head>
<body>
<?php
if (is_valid_base64($source))
$isource = $source;
else
$isource = base64url_encode($source);
echo '<img src="i.php?'. $isource . '">';
?>
</body>
</html>