'/bootstrap.php'; (new App())->run(); index.phpだって、 <?php declare(strict_types=1); $dbo = mysqli_connect( getenv('DB_HOST'), getenv('DB_USER'), getenv('DB_PASS'), getenv('DB_NAME'), ); if (!$dbo) goto db_error; /* ϦΫΤετͷॲཧ */ $action = filter_input(INPUT_GET, 'action'); if ($action === 'detail') goto detail_message; if ($action === 'new') goto new_message; if ($action === 'register') goto register_message; goto list_msgs; /* ϝοηʔδҰཡ */ list_msgs: $page = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT); goto check_page; set_default_page: $page = 1; goto end_page_check; check_page: if ($page >= 1) goto end_page_check; goto set_default_page; end_page_check: $totalCount = 0; $msgs = []; $result = mysqli_query( $dbo, 'SELECT COUNT(*) FROM messages', ); if ($result !== false) goto list_msgs_page; $totalCount = (int)mysqli_fetch_column($result); $limit = 10; $offset = ($page - 1) * $limit; $stmt = mysqli_prepare( $dbo, 'SELECT * FROM messages ORDER BY id DESC LIMIT ? OFFSET ?' ); mysqli_stmt_bind_param($stmt, 'ii', $limit, $offset); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); $msgs = mysqli_fetch_all($result, MYSQLI_ASSOC); $msgCnt = count($msgs); $totalPage = ceil($totalCount / 10); list_msgs_page: ?> <!DOCTYPE html> <html> <head> <title>ݴҰཡ</title> <link rel="stylesheet" href="assets/geo-bootstrap/swatch/ bootstrap.min.css"> </head> <body> <div class="container" style="padding-bottom: 5rem;"> <div class="page-header"> <h1>ݴҰཡ</h1> <a class="btn btn-info" href="/?action=new">৽نߘ</a> </div> <div class="row"> <div class="span12"> <ul class="list-group mb-4"> <?php $i = 0; msg_loop: if ($i >= $msgCnt) goto msg_loop_end; $message = $msgs[$i]; ?> <li class="list- group-item"> <a href="/? action=detail&id=<?= $message['id'] ? >"> <?= htmlspecialchars($message['title']) ?> </a> by <?= htmlspecialchars($message['author']) ?> </li> <?php $i++; goto msg_loop; msg_loop_end: ?> </ul> </div> <div class="span12"> <div class="pager"> <ul> <li class="page-item"> <a class="page-link" href="/">࠷ॳͷϖʔδ</ a> </li> <?php goto check_prev_page; prev_page: ?> <li class="page-item"> <a class="page-link" href="/?page=<?= $page - 1 ?>">લͷϖʔδ</a> </li> <?php goto check_next_page; check_prev_page: if ($page <= 1) goto check_next_page; goto prev_page; check_next_page: if ($page >= $totalPage) goto end_pagination; next_page: ?> <li class="page-item"> <a class="page-link" href="/?page=<?= $page + 1 ?>">࣍ͷϖʔδ</a> </li> <?php goto end_pagination; end_pagination: ?> <li class="page-item"> <a class="page-link" href="?page=<?= intdiv($i, 10) + 1 ?>">࠷ޙͷϖʔδ</a> </li> </ul> </div> </div> </div> </div> </body> </html> <?php goto end; /* ϝοηʔδৄࡉ */ detail_message: $id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT); $stmt = mysqli_prepare($dbo, 'SELECT * FROM messages WHERE id = ?'); mysqli_stmt_bind_param($stmt, 'i', $id); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); if (mysqli_num_rows($result) === 0) goto redirect_home; $message = mysqli_fetch_assoc($result); ?> <!DOCTYPE html> <html> <head> <title><?= htmlspecialchars($message['title']) ? ></title> <link rel="stylesheet" href="assets/geo-bootstrap/swatch/ bootstrap.min.css"> </head> <body> <div class="container" style="padding-bottom: 5rem;"> <div class="page-header"> <h1><?= htmlspecialchars($message['title']) ? ></h1> <a class="btn btn-info" href="index.php">ҰཡʹΔ</a> </div> <div class="row"> <div class="span12"> <article> <header> <p> <span class="label label-inverse">ߘऀ</ span> <?= htmlspecialchars($message['author']) ?> </p> <p> <span class="label label-inverse">ߘ</ span> <?= $message['created_at'] ?> </p> </header> <p class="well"> <?= nl2br(htmlspecialchars($message['body'] )) ?> </p> </article> </div> </div> </div> </body> </html> <?php goto end; /* ৽نϝοηʔδ */ new_message: ?> <!DOCTYPE html> <html> <head> <title>৽نݴ࡞</title> <link rel="stylesheet" href="assets/geo-bootstrap/swatch/ bootstrap.min.css"> </head> <body> <div class="container" style="padding-bottom: 5rem;"> <div class="page-header"> <h1>৽نݴ࡞</h1> <a class="btn btn-info" href="index.php">ҰཡʹΔ</a> </div> <div class="row"> <div class="span12"> <?php if (empty($errors)) goto new_message_form; ?> <div class="alert alert-error"> <ul> <?php $i = 0; $errorCount = count($errors); error_list_item: if ($i >= $errorCount) goto error_list_end; $errorField = array_keys($errors)[$i]; ?> <li><?= $errors[$errorField] ?></li> <?php $i++; goto error_list_item; error_list_end: ?> </ul> </div> <?php new_message_form: ?> <form method="post" action="/?action=register" class="form- horizontal well"> <div class="control-group"> <label class="control-label">λΠτϧ</label> <div class="controls"> <input type="text" name="title" maxlength="50" required> </div> </div> <div class="control-group"> <label class="control-label">ຊจ</label> <div class="controls"> <textarea name="body" maxlength="500" rows="10" required></textarea> </div> </div> <div class="control-group"> <label class="control-label">ߘऀ໊</label> <div class="controls"> <input type="text" name="author" maxlength="50" required> </div> </div> <label> : </label><br> <button type="submit" class="btn btn-primary"> ొ</button> <button type="submit"></button> </form> </div> </div> </div> </body> </html> <?php goto end; /* ϝοηʔδొ */ register_message: if ($_SERVER['REQUEST_METHOD'] !== 'POST') goto redirect_new; $postMessage = [ 'title' => filter_input(INPUT_POST, 'title'), 'author' => filter_input(INPUT_POST, 'author'), 'body' => filter_input(INPUT_POST, 'body'), ]; $errors = []; validate_title: if ($postMessage['title'] && mb_strlen($postMessage['title']) <= 50) goto validate_author; $errors['title'] = 'λΠτϧ50จࣈҎͰ ೖྗ͍ͯͩ͘͠͞'; validate_author: if ($postMessage['author'] && mb_strlen($postMessage['author']) <= 50) goto validate_body; $errors['author'] = 'ߘऀ໊50จࣈҎ Ͱೖྗ͍ͯͩ͘͠͞'; validate_body: if ($postMessage['body'] && mb_strlen($postMessage['body']) <= 500) goto validate_end; $errors['body'] = 'ຊจ500จࣈҎͰೖྗ ͍ͯͩ͘͠͞'; validate_end: if ($errors) goto new_message; $postMessage['created_at'] = date('Y-m- d H:i:s'); $stmt = mysqli_prepare($dbo, 'INSERT INTO `msgs` (`title`, `author`, `body`, `created_at`) VALUES (?, ?, ?, ?)'); mysqli_stmt_bind_param($stmt, 'ssss', $postMessage['title'], $postMessage['author'], $postMessage['body'], $postMessage['created_at']); mysqli_stmt_execute($stmt); if (mysqli_stmt_error($stmt)) goto end; $id = mysqli_stmt_insert_id($stmt); header("Location: /? action=detail&id={$id}"); goto end; /* ΤϥʔϋϯυϦϯά */ db_error: echo "σʔλϕʔεଓΤϥʔ", PHP_EOL; goto end; redirect_home: header("Location: /"); goto end; redirect_new: header("Location: /?action=new"); goto end; end: goto program_exit; /* ϓϩάϥϜऴྃ */ program_exit: このくらい じゃないと! ⏳estimate: 大 01 02 /20