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

@ -1,5 +1,5 @@
<?php /* <?php /*
Copyright © 2021 Pk11 Copyright © 2022 Pk11
Permission is hereby granted, free of charge, to any person obtaining a Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the “Software”), 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"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head> </head>
<body> <body>
<?php $stop = $_GET['stop']; ?> <?php
$stop = $_GET['stop'];
$favAdd = $_GET['fav-add'];
$favRemove = $_GET['fav-remove'];
?>
<header> <header>
<nav class="navbar navbar-light bg-light"> <nav class="navbar navbar-light bg-light">
@ -61,10 +65,9 @@
</div> </div>
<?php <?php
if(empty($stop)) { if(!empty($stop)) {
echo '<h2 class="alert alert-info">以上で停留所の番号を入力してください。</h2>'; if(preg_match("/[^\\d]/", $stop)) {
} else if(preg_match("/[^\\d]/", $stop)) { echo "<h3 class=\"alert alert-danger\">{$stop}は無効な停留所です。</h3>";
echo "<h2 class=\"alert alert-danger\">{$stop}は無効な停留所です。</h2>";
} else { } else {
$directions = [ $directions = [
"NB" => "北行", "NB" => "北行",
@ -77,9 +80,9 @@
$json = json_decode($content); $json = json_decode($content);
if(!$json) { if(!$json) {
echo "<h2 class=\"alert alert-danger\">{$stop}は無効な停留所です。</h2>"; echo "<h3 class=\"alert alert-danger\">{$stop}は無効な停留所です。</h3>";
} else { } else {
echo "<h2 class=\"border-bottom\">停留所{$stop}のNexTrip情報</h2>"; echo "<h3 class=\"border-bottom\">停留所{$stop}のNexTrip情報</h3>";
echo '<div class="row row-cols-2 row-cols-md-4 row-cols-lg-6">'; echo '<div class="row row-cols-2 row-cols-md-4 row-cols-lg-6">';
foreach($json as $bus) { foreach($json as $bus) {
echo '<div class="col">'; echo '<div class="col">';
@ -88,6 +91,36 @@
echo '</div>'; echo '</div>';
} }
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 '</ul>';
} }
} }
?> ?>

Loading…
Cancel
Save