FoOlSlideX/public/chapter.php

82 lines
2.6 KiB
PHP
Raw Permalink Normal View History

2023-03-30 23:00:50 +02:00
<?php
require "../autoload.php";
if (!isset($_GET["id"]) || empty($_GET["id"])) header("Location: index.php") && die("No or empty ID.");
if (!is_numeric($_GET["id"])) header("Location: index.php") && die("Invalid ID.");
$id = cat($_GET["id"]);
$chapter = $db["chapters"]->findById($id);
2023-05-29 22:19:21 +02:00
$title = $db["titles"]->findById($chapter["title"]);
2023-03-30 23:00:50 +02:00
if (empty($title)) header("Location: titles.php") && die("Title not found.");
if (empty($chapter)) header("Location: title.php?id={$title["id"]}") && die("Chapter not found.");
2023-05-29 22:19:21 +02:00
$fct = formatChapterTitle($chapter["volume"], $chapter["number"], "full");
$smarty->assign("fullChapterTitle", $fct);
$chapters = $db["chapters"]->findBy(["title", "==", $title["id"]]);
$smarty->assign("chapters", $chapters);
$isNextChapter = false;
$isPrevChapter = false;
foreach ($chapters as $key => $ch) {
if ($ch["id"] == $id) {
if (!empty($chapters[($key + 1)])) $isNextChapter = $chapters[($key + 1)]["id"];
if (!empty($chapters[($key - 1)])) $isPrevChapter = $chapters[($key - 1)]["id"];
}
}
$smarty->assign("nextChapter", $isNextChapter);
$smarty->assign("prevChapter", $isPrevChapter);
2023-03-30 23:00:50 +02:00
$images = glob(ps(__DIR__ . "/data/chapters/{$id}/*.{jpg,png,jpeg,webp,gif}"), GLOB_BRACE);
natsort($images);
2023-05-29 22:19:21 +02:00
$comments = $db["chapterComments"]->findBy(["chapter.id", "==", $title["id"]], ["id" => "DESC"]);
2023-03-30 23:00:50 +02:00
chapterVisit($chapter);
2023-05-29 22:19:21 +02:00
$imgind = [];
$ic = 1;
foreach ($images as $ii) {
$ii = pathinfo($ii);
$imgind[$ic]["order"] = $ic;
$imgind[$ic]["name"] = $ii["filename"];
$imgind[$ic]["ext"] = $ii["extension"];
$ic++;
}
$smarty->assign("imgind", $imgind);
if ($readingmode == "single") {
if (!isset($_GET["page"]) || empty($_GET["page"]) || $_GET["page"] == "0") {
header("Location: chapter.php?id=" . $id . "&page=1");
}
$page = cat($_GET["page"]);
$isNextPage = true;
$isPrevPage = true;
$nextPage = $page + 1;
$prevPage = $page - 1;
$imgCount = count($images);
if ($nextPage >= $imgCount) $isNextPage = false;
if ($prevPage <= 0) $isPrevPage = false;
$smarty->assign("isNextPage", $isNextPage);
$smarty->assign("isPrevPage", $isPrevPage);
$smarty->assign("currentPage", $page);
}
2023-03-30 23:00:50 +02:00
$smarty->assign("commentsCount", count($comments));
$smarty->assign("title", $title);
$smarty->assign("chapter", $chapter);
$smarty->assign("images", $images);
2023-05-29 22:19:21 +02:00
$smarty->assign("pagetitle", "Read " . $title["title"] . " " . formatChapterTitle($chapter["volume"], $chapter["number"]) . " " . $config["divider"] . " " . $config["title"]);
2023-03-30 23:00:50 +02:00
$smarty->display("parts/header.tpl");
$smarty->display("pages/chapter.tpl");
$smarty->display("parts/footer.tpl");