|
|
<?php /*
|
|
|
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”),
|
|
|
to deal in the Software without restriction, including without limitation
|
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
|
|
Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
DEALINGS IN THE SOFTWARE.
|
|
|
*/ ?>
|
|
|
|
|
|
<!DOCTYPE html>
|
|
|
<html lang="ja">
|
|
|
<head>
|
|
|
<meta charset="utf-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
|
|
|
<title>NexTrip停留所の情報</title>
|
|
|
|
|
|
<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'];
|
|
|
$favSet = $_GET['fav-set'];
|
|
|
$favRemove = $_GET['fav-remove'];
|
|
|
?>
|
|
|
|
|
|
<header>
|
|
|
<nav class="navbar navbar-light bg-light">
|
|
|
<div class="container-fluid">
|
|
|
<a class="navbar-brand" href="https://nextrip.xn--rdk.xn--tckwe/">NexTrip停留所の情報</a>
|
|
|
<ul class="navbar-nav">
|
|
|
<li class="nav-item">
|
|
|
<a class="nav-link" href="https://gist.github.com/Epicpkmn11/6e60adbf3475277b753b259ab02a53cd" target="_blank">ソース</a>
|
|
|
</li>
|
|
|
</ul>
|
|
|
</div>
|
|
|
</nav>
|
|
|
</header>
|
|
|
|
|
|
<main class="mt-3">
|
|
|
<div class="container-fluid">
|
|
|
<div class="row">
|
|
|
<div class="col-12">
|
|
|
<form>
|
|
|
<div class="input-group mb-3">
|
|
|
<label for="stop" class="input-group-text">停留所</label>
|
|
|
<input type="text" id="stop" name="stop" class="form-control" placeholder="12345" value="<?php echo $stop; ?>">
|
|
|
<input type="submit" class="btn btn-outline-secondary">
|
|
|
</div>
|
|
|
</form>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="row">
|
|
|
<div class="col-12">
|
|
|
<?php
|
|
|
if(isset($stop)) {
|
|
|
if(preg_match("/[^\\d]/", $stop)) {
|
|
|
echo "<h3 class=\"alert alert-danger\">{$stop}は無効な停留所です。</h3>";
|
|
|
} 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 "<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>';
|
|
|
|
|
|
$favDesc = json_decode($_COOKIE['favorites'], true)[$stop];
|
|
|
|
|
|
echo '<div class="row">';
|
|
|
echo '<div class="col-12">';
|
|
|
echo '<form>';
|
|
|
echo "<input type=\"hidden\" name=\"fav-set\" value=\"$stop\">";
|
|
|
echo '<div class="input-group mb-3">';
|
|
|
echo '<label for="desc" class="input-group-text">お気に入り</label>';
|
|
|
echo "<input type=\"text\" id=\"desc\" name=\"desc\" class=\"form-control\" placeholder=\"説明\" value=\"$favDesc\" required>";
|
|
|
if(isset($favDesc))
|
|
|
echo '<input type="submit" class="btn btn-outline-secondary" value="更新">';
|
|
|
else
|
|
|
echo '<input type="submit" class="btn btn-outline-secondary" value="追加">';
|
|
|
echo '</div>';
|
|
|
echo '</form>';
|
|
|
echo '</div>';
|
|
|
echo '</div>';
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
$favorites = isset($_COOKIE['favorites']) ? json_decode($_COOKIE['favorites'], true) : Array();
|
|
|
|
|
|
if(isset($favSet)) {
|
|
|
$desc = $_GET['desc'];
|
|
|
|
|
|
$favorites[$favSet] = $desc;
|
|
|
setcookie("favorites", json_encode($favorites));
|
|
|
echo "<h3 class=\"alert alert-info\">{$favSet}({$desc})は設定しました。</h3>";
|
|
|
} else if(isset($favRemove)) {
|
|
|
if(array_key_exists($favRemove, $favorites)) {
|
|
|
$desc = $favorites[$favRemove];
|
|
|
unset($favorites[$favRemove]);
|
|
|
setcookie("favorites", json_encode($favorites));
|
|
|
echo "<h3 class=\"alert alert-info\">{$favRemove}({$desc})は削除しました。</h3>";
|
|
|
} else {
|
|
|
echo "<h3 class=\"alert alert-warning\">{$favRemove}はお気に入りにありません。</h3>";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(count($favorites) > 0) {
|
|
|
echo '<h2 class="border-bottom">お気に入り</h2>';
|
|
|
echo '<ul>';
|
|
|
foreach($favorites as $favStop => $favDesc) {
|
|
|
echo '<li class="mb-1">';
|
|
|
echo "<a class=\"btn btn-sm btn-secondary\" href=\"?stop=$favStop\">$favStop ($favDesc)</a> ";
|
|
|
echo "<a class=\"btn btn-sm btn-danger\" href=\"?fav-remove=$favStop\" aria-label=\"Remove\">×</a>";
|
|
|
echo '</li>';
|
|
|
}
|
|
|
echo '</ul>';
|
|
|
}
|
|
|
}
|
|
|
?>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</main>
|
|
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
|
|
|
</body>
|
|
|
</html>
|