all the website mainly done
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config.php';
|
||||
|
||||
/**
|
||||
* 88x31 buttons shown in the footer.
|
||||
* To add one, just append a line: ['href' => 'https://...', 'src' => 'https://.../banner.png', 'alt' => 'name'].
|
||||
* The image is fetched + cached server-side, so nothing hotlinks the remote host on every visit.
|
||||
*/
|
||||
const BUTTONS_88x31 = [
|
||||
['href' => 'https://patate.dev', 'src' => 'https://patate.dev/images/patate_dev_banner.jpeg', 'alt' => 'patate.dev'],
|
||||
['href' => 'https://blog.counter-strike.net/', 'src' => 'https://matdoes.dev/buttons/i/8678a5dfa58ce412f7d8f978b14e2f64.gif', 'alt' => 'https://blog.counter-strike.net/'],
|
||||
['href' => 'caddyserver.com', 'src' => 'https://caddyserver.com/resources/images/nostalgia/caddy.png', 'alt' => 'caddyserver.com'],
|
||||
['href' => '', 'src' => 'https://matdoes.dev/buttons/i/9025eae1851e8f32ff70f43f2c3393f0.png', 'alt' => 'ownpaws'],
|
||||
['href' => 'https://ssi.fyi/', 'src'=>'https://ssi.fyi/88x31.gif', 'alt'=>'https://ssi.fyi'],
|
||||
['href' => 'https://vmfunc.re/', 'src' => 'https://vmfunc.re/button.png', 'alt' => 'vmfunc.re'],
|
||||
['href' => 'https://0xa0.dev/', 'src' => '/img/0xa0.png', 'alt' => '0xA0.dev']
|
||||
];
|
||||
|
||||
const BUTTON_CACHE_TTL = 7 * 86400; // re-fetch each button at most once a week
|
||||
|
||||
/**
|
||||
* Fetch a remote image, cache it locally, and return it as a base64 data: URI.
|
||||
* Returns null on failure so the caller can fall back to hotlinking.
|
||||
*/
|
||||
function button_data_uri(string $url): ?string
|
||||
{
|
||||
$dir = DATA_DIR . '/buttons';
|
||||
@mkdir($dir, 0775, true);
|
||||
$file = $dir . '/' . md5($url); // stores "content-type\n<raw bytes>"
|
||||
|
||||
if (!is_file($file) || (time() - filemtime($file)) > BUTTON_CACHE_TTL) {
|
||||
$ctx = stream_context_create(['http' => [
|
||||
'timeout' => 5,
|
||||
'user_agent' => 'Mozilla/5.0 (0xa0.dev button fetcher)',
|
||||
]]);
|
||||
$bytes = @file_get_contents($url, false, $ctx);
|
||||
if ($bytes !== false && $bytes !== '') {
|
||||
$type = 'image/png';
|
||||
foreach ($http_response_header ?? [] as $h) {
|
||||
if (stripos($h, 'content-type:') === 0) {
|
||||
$type = trim(substr($h, strlen('content-type:')));
|
||||
break;
|
||||
}
|
||||
}
|
||||
file_put_contents($file, $type . "\n" . $bytes);
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_file($file)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$raw = (string) file_get_contents($file);
|
||||
$nl = strpos($raw, "\n");
|
||||
if ($nl === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$type = substr($raw, 0, $nl);
|
||||
$data = substr($raw, $nl + 1);
|
||||
return 'data:' . $type . ';base64,' . base64_encode($data);
|
||||
}
|
||||
|
||||
/** Render the whole 88x31 button row as HTML. */
|
||||
function render_buttons_88x31(): string
|
||||
{
|
||||
$html = '';
|
||||
foreach (BUTTONS_88x31 as $b) {
|
||||
$uri = button_data_uri($b['src']) ?? $b['src']; // fall back to hotlink if fetch failed
|
||||
$img = '<img src="' . htmlspecialchars($uri) . '" alt="' . htmlspecialchars($b['alt']) . '" width="88" height="31">';
|
||||
$href = $b['href'] ?? '';
|
||||
if ($href !== '') {
|
||||
$html .= '<a href="' . htmlspecialchars($href) . '" target="_blank" rel="noopener">' . $img . '</a>' . "\n";
|
||||
} else {
|
||||
$html .= $img . "\n"; // no href → just the image, not clickable
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
Reference in New Issue
Block a user