<?php



if (!defined('TUBEPRESS_MIN_PHP')) {
    define('TUBEPRESS_MIN_PHP', '8.2.0');
}

if (version_compare(PHP_VERSION, TUBEPRESS_MIN_PHP, '<')) {
    $min = TUBEPRESS_MIN_PHP;
    $cur = PHP_VERSION;
    $msg = 'TubePress requires PHP ' . $min . ' or newer. This server is running PHP ' . $cur . '.';

    if (PHP_SAPI === 'cli') {
        fwrite(defined('STDERR') ? STDERR : fopen('php://stderr', 'w'), $msg . "\n");
    } else {
        if (!headers_sent()) {
            http_response_code(500);
            header('Content-Type: text/html; charset=utf-8');
            header('Retry-After: 3600');
        }
        echo '<!doctype html><html lang="en"><head><meta charset="utf-8">'
           . '<meta name="viewport" content="width=device-width,initial-scale=1">'
           . '<title>PHP upgrade required</title></head><body style="margin:0;background:#0f172a;'
           . 'color:#e2e8f0;font:16px/1.6 -apple-system,Segoe UI,Roboto,Arial,sans-serif">'
           . '<div style="max-width:560px;margin:16vh auto;padding:0 24px">'
           . '<h1 style="font-size:21px;margin:0 0 10px">PHP upgrade required</h1>'
           . '<p style="color:#94a3b8;margin:0">' . htmlspecialchars($msg)
           . ' Please switch this site to PHP ' . htmlspecialchars($min)
           . ' or newer — most hosting control panels let you change the PHP version — then reload the page.</p>'
           . '</div></body></html>';
    }
    exit(1);
}
