Initial commit

This commit is contained in:
Porawit Dongwang
2026-09-16 23:20:08 +07:00
commit 0041668dbb
32577 changed files with 3687927 additions and 0 deletions
@@ -0,0 +1,66 @@
<?php
header('Content-Type: application/json; charset=utf-8');
$year = isset($_GET['year']) ? (int)$_GET['year'] : date('Y');
$holidays = [];
function getThaiHolidayName($title) {
$title = strtolower($title);
if (strpos($title, "new year's day") !== false) return "วันขึ้นปีใหม่";
if (strpos($title, "makha bucha") !== false) return "วันมาฆบูชา";
if (strpos($title, "chakri") !== false) return "วันจักรี";
if (strpos($title, "songkran") !== false) return "เทศกาลสงกรานต์";
if (strpos($title, "labour") !== false || strpos($title, "labor") !== false) return "วันแรงงานแห่งชาติ";
if (strpos($title, "coronation") !== false) return "วันฉัตรมงคล";
if (strpos($title, "visakha bucha") !== false) return "วันวิสาขบูชา";
if (strpos($title, "queen suthida") !== false) return "วันเฉลิมพระชนมพรรษา สมเด็จพระนางเจ้าฯ พระบรมราชินี";
if (strpos($title, "maha vajiralongkorn") !== false) return "วันเฉลิมพระชนมพรรษา พระบาทสมเด็จพระเจ้าอยู่หัว";
if (strpos($title, "asanha bucha") !== false) return "วันอาสาฬหบูชา";
if (strpos($title, "buddhist lent") !== false || strpos($title, "khao phansa") !== false) return "วันเข้าพรรษา";
if (strpos($title, "queen sirikit") !== false || strpos($title, "mother's day") !== false) return "วันเฉลิมพระชนมพรรษา สมเด็จพระบรมราชชนนีพันปีหลวง และวันแม่แห่งชาติ";
if (strpos($title, "bhumibol adulyadej the great memorial") !== false || strpos($title, "navamindra") !== false) return "วันนวมินทรมหาราช";
if (strpos($title, "chulalongkorn") !== false) return "วันปิยมหาราช";
if (strpos($title, "bhumibol adulyadej's birthday") !== false || strpos($title, "father's day") !== false) return "วันคล้ายวันพระบรมราชสมภพ ร.9 และวันพ่อแห่งชาติ";
if (strpos($title, "constitution") !== false) return "วันรัฐธรรมนูญ";
if (strpos($title, "new year's eve") !== false) return "วันสิ้นปี";
if (strpos($title, "royal ploughing") !== false) return "วันพืชมงคล";
if (strpos($title, "special") !== false) return "วันหยุดพิเศษ";
return $title; // fallback
}
try {
$apiUrl = "https://thailandformats.com/api/v1/holidays/" . $year;
$ctx = stream_context_create(array('http' => array('timeout' => 5)));
$holidayJson = @file_get_contents($apiUrl, false, $ctx);
if ($holidayJson) {
$holidayData = json_decode($holidayJson, true);
if (isset($holidayData['holidays'])) {
foreach ($holidayData['holidays'] as $h) {
$startDate = new DateTime($h['start_date']);
$endDate = new DateTime($h['end_date']);
$titleEn = $h['title'];
$isSub = (stripos($titleEn, 'substitution') !== false || stripos($titleEn, 'observed') !== false);
$name = getThaiHolidayName($titleEn);
if ($isSub) {
$name = 'ชดเชย' . str_replace('ชดเชย', '', $name);
}
for ($d = $startDate; $d <= $endDate; $d->modify('+1 day')) {
$dateStr = $d->format('Y-m-d');
$holidays[$dateStr] = $name;
}
}
}
}
echo json_encode(['status' => 'success', 'data' => $holidays]);
} catch (Exception $e) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
?>