Pk11 3 years ago committed by GitHub
parent 905a9147d3
commit 3ce76da0f8

@ -1,5 +1,5 @@
<?php /*
Copyright © 2021 Pk11
Copyright © 2022 Pk11
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the “Software”),
@ -31,7 +31,11 @@
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
<?php $stop = $_GET['stop']; ?>
<?php
$stop = $_GET['stop'];
$favAdd = $_GET['fav-add'];
$favRemove = $_GET['fav-remove'];
?>
<header>
<nav class="navbar navbar-light bg-light">
@ -61,33 +65,62 @@
</div>
<?php
if(empty($stop)) {
echo '<h2 class="alert alert-info">以上で停留所の番号を入力してください。</h2>';
} else if(preg_match("/[^\\d]/", $stop)) {
echo "<h2 class=\"alert alert-danger\">{$stop}は無効な停留所です。</h2>";
} else {
$directions = [
"NB" => "北行",
"EB" => "東行",
"SB" => "南行",
"WB" => "西行"
];
$content = file_get_contents("https://svc.metrotransit.org/NexTrip/$stop?format=json");
$json = json_decode($content);
if(!$json) {
echo "<h2 class=\"alert alert-danger\">{$stop}は無効な停留所です。</h2>";
if(!empty($stop)) {
if(preg_match("/[^\\d]/", $stop)) {
echo "<h3 class=\"alert alert-danger\">{$stop}は無効な停留所です。</h3>";
} else {
echo "<h2 class=\"border-bottom\">停留所{$stop}のNexTrip情報</h2>";
echo '<div class="row row-cols-2 row-cols-md-4 row-cols-lg-6">';
foreach($json as $bus) {
echo '<div class="col">';
echo "<p><span class=\"fw-bold\">$bus->Route{$bus->Terminal}番線({$directions[$bus->RouteDirection]}</span><br>";
echo "$bus->DepartureText</p>";
$directions = [
"NB" => "北行",
"EB" => "東行",
"SB" => "南行",
"WB" => "西行"
];
$content = file_get_contents("https://svc.metrotransit.org/NexTrip/$stop?format=json");
$json = json_decode($content);
if(!$json) {
echo "<h3 class=\"alert alert-danger\">{$stop}は無効な停留所です。</h3>";
} else {
echo "<h3 class=\"border-bottom\">停留所{$stop}のNexTrip情報</h3>";
echo '<div class="row row-cols-2 row-cols-md-4 row-cols-lg-6">';
foreach($json as $bus) {
echo '<div class="col">';
echo "<p><span class=\"fw-bold\">$bus->Route{$bus->Terminal}番線({$directions[$bus->RouteDirection]}</span><br>";
echo "$bus->DepartureText</p>";
echo '</div>';
}
echo '</div>';
echo "<a href=\"?fav-add=$stop\" class=\"btn btn-secondary\">お気に入りに追加</a>";
}
}
} else {
$favorites = json_decode($_COOKIE['favorites']);
if(!empty($favAdd)) {
if(!in_array($favAdd, $favorites)) {
$favorites[] = $favAdd;
setcookie("favorites", json_encode($favorites));
echo "<h3 class=\"alert alert-info\">{$favAdd}はお気に入りに追加しました。</h3>";
} else {
echo "<h3 class=\"alert alert-warning\">{$favAdd}は既にお気に入りにありました。</h3>";
}
} else if(!empty($favRemove)) {
$favorites = array_filter($favorites, function($v) { global $favRemove; return $v != $favRemove; });
setcookie("favorites", json_encode($favorites));
echo "<h3 class=\"alert alert-info\">{$favRemove}は削除しました。</h3>";
}
if(count($favorites) > 0) {
echo '<h2 class="border-bottom">お気に入り</h2>';
echo '<ul>';
foreach($favorites as $fav) {
echo '<li class="mb-1">';
echo "<a class=\"btn btn-sm btn-secondary\" href=\"?stop=$fav\">$fav</a> ";
echo "<a class=\"btn btn-sm btn-danger\" href=\"?fav-remove=$fav\" aria-label=\"Remove\">×</a>";
echo '</li>';
}
echo '</div>';
echo '</ul>';
}
}
?>

Loading…
Cancel
Save