ComicsViewer/index.php

194 lines
6.5 KiB
PHP

<?php
require 'header.php';
require_login();
if ( isset($_REQUEST['sortorder']) ) {
if ( ($_REQUEST['sortorder'] == SORTBYNAME) || ($_REQUEST['sortorder'] == SORTBYDATE) ) {
$_SESSION['sortorder'] = $_REQUEST['sortorder'];
}
}
$validext = array('cbr', 'cbz');
if ( $_SESSION['compath'] == "" ) $_SESSION['compath'] = "/";
if ( isset($_REQUEST['newpath']) ) {
$comicfull = realpath(COMICSDIR . urldecode($_REQUEST['newpath']));
if ( ($comicfull === false) || (substr($comicfull, 0, strlen(COMICSDIR)) != COMICSDIR) ) {
$_SESSION['compath'] = "/";
} else {
$_SESSION['compath'] = substr($comicfull, strlen(COMICSDIR));
}
}
$compath = $_SESSION['compath'];
$fullcompath = COMICSDIR . $compath;
$header = basename($compath);
if ( $header == "" ) { $header = "Comics"; }
$fltime = microtime_float();
$folders = array();
$files = array();
if ( $fh = opendir($fullcompath) ) {
while ( false !== ($entry = readdir($fh)) ) {
$mtime = filemtime($fullcompath . "/" . $entry);
if ( ($entry != ".") && ($entry != "..") && is_dir($fullcompath . "/" . $entry) ) {
$folders[$mtime] = $entry;
}
if ( is_file($fullcompath . "/" . $entry)
&& in_array(substr($entry, -3), $validext) ) {
$files[] = $entry;
}
}
closedir($fh);
if ( $_SESSION['sortorder'] == SORTBYNAME ) {
natsort($folders);
} else {
ksort($folders);
$folders = array_reverse($folders);
}
sort($files);
}
$items = array_merge($folders, $files);
$fltime = microtime_float() - $fltime;
$updir = dirname($compath);
$updirlink = urlencode($updir);
// build up a list of comics and issues which have been
$query = "SELECT comic, issue FROM pagetracker WHERE username=:username";
$fields = array();
$fields[":username"] = $_SESSION['username'];
$sth = $globaldbh->prepare($query);
$sth->execute($fields);
$comics = array();
$issues = array();
while ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) {
if ( !in_array($row['comic'], $comics) ) $comics[] = $row['comic'];
if ( !in_array($row['issue'], $issues) ) $issues[] = $row['issue'];
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=0.5" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<link rel="icon" sizes="128x128" href="img/comics_128.png">
<link rel="icon" sizes="196x196" href="img/comics_196.png">
<link rel="apple-touch-icon" sizes="76x76" href="img/comics_76.png">
<link rel="apple-touch-icon" sizes="120x120" href="img/comics_120.png">
<link rel="apple-touch-icon" sizes="152x152" href="img/comics_152.png">
<title>Comics Fancy</title>
<link rel='stylesheet' type='text/css' href='css/reset.css' media='screen' />
<link rel='stylesheet' type='text/css' href='css/comics.css' media='screen' />
<link rel="stylesheet" type="text/css" href="core/simpleLightbox.min.css" />
<!-- Toastr CSS -->
<link rel="stylesheet" type="text/css" href="core/toastr.min.css" />
<script type='text/javascript' src='core/jquery-3.6.0.min.js'></script>
<script type='text/javascript' src='js/comics.js'></script>
<script type='text/javascript' src='core/simpleLightbox.min.js'></script>
<script type='text/javascript' src='core/toastr.min.js'></script>
<style type='text/css'>
.fancybox-outer { background: #323231; }
.fancybox-title { font: normal 10px "Comic Sans MS"; }
.fancybox-title-over-wrap { color: #bbb; padding: 0px 4px 0px 4px; }
.mtest {
margin-top: 0px;
margin-bottom: 0px;
padding-top: 0px;
padding-bottom: 0px;
border: 1px solid red;
}
</style>
</head>
<body>
<div class='sorter'>Sort:
<?php
if ( $_SESSION['sortorder'] == SORTBYNAME ) {
echo "<a href='index.php?sortorder=", SORTBYDATE, "'>Name</a>";
} else {
echo "<a href='index.php?sortorder=", SORTBYNAME, "'>Date</a>";
}
?>
</div>
<div class='header' id='header'><?php
/*
if ( $compath != "/" ) {
echo "<a href='index.php?newpath=$updirlink'>$updir";
if ( dirname($compath) == "/" ) { echo "Comics"; }
echo "</a>/";
}
echo $header;
*/
?>&nbsp;</div>
<!-- <div class='name'><a href='logout.php'><?php echo htmlspecialchars($_SESSION['name']); ?></a></div> -->
<div class='name'><?php
if ( $compath != "/" ) {
echo "<a href='index.php?newpath=$updirlink'>$updir";
if ( dirname($compath) == "/" ) { echo "Comics"; }
echo "</a>/";
}
?></div>
<div class='list'>
<!-- <div class='listcontainer'> -->
<?php
$htime = microtime_float();
$thumbtime = 0;
$newthumbs = 0;
$thumbfiles = "";
$total = count($items);
for ( $i=1; $i<=$total; $i++ ) {
if ( $i <= count($folders) ) {
$np = urlencode((($compath == "/") ? "" : $compath) . "/" . $items[$i-1]);
$thumbfile = THUMBSDIR . $compath . "/" . $items[$i-1] . ".jpg";
} else {
$np = urlencode($compath . "/" . substr($items[$i-1], 0, -4) . ".jpg");
$thumbfile = THUMBSDIR . $compath . "/" . substr($items[$i-1], 0, -4) . ".jpg";
}
$thumbfile = str_replace("#", "", $thumbfile);
if ( !file_exists($thumbfile) ) {
$thumbfiles .= $thumbfile . "<br>";
$newthumbs++;
$st = microtime_float();
$havethumb = makeThumb($fullcompath . "/" . $items[$i-1]);
$thumbtime += microtime_float() - $st;
if ( !$havethumb ) {
$havethumb = true;
$thumb = "img/nothumb.png";
}
}
$thumb = "thumbs" . $compath . "/" .basename($thumbfile);
$comname = pathinfo($items[$i-1], PATHINFO_FILENAME);
if ( strpos($comname, " - ") !== false ) $comname = str_replace(" - ", "<br />", $comname);
$classmod = "";
if ( $i <= count($folders) ) {
if ( in_array($items[$i-1], $comics) ) $classmod=" readborder";
echo "<div class='item folder{$classmod}' ";
echo "data-path=\"{$np}\" ";
echo "data-name=\"{$comname}\">";
$thumburl = htmlentities($thumb, ENT_QUOTES);
echo "<img src='$thumburl'><br clear=all />{$comname}</div>\n";
} else {
if ( in_array($items[$i-1], $issues) ) $classmod=" readborder";
$relcomic = trim(base64_encode($compath . "/" . $items[$i-1]), "=");
$thumburl = htmlentities($thumb, ENT_QUOTES);
echo "<div class='item{$classmod}' id='", $relcomic, "'><a onClick='showComic(\"", $relcomic, "\", \"", htmlspecialchars($comname, ENT_QUOTES), "\");' ";
echo "href='javascript:;'><img border=0 src='$thumburl'></a><br clear=all />";
echo "<a href='downloadcomic.php?comic={$relcomic}'>{$comname}</a></div>\n";
}
}
$htime = microtime_float() - $htime;
?>
<!-- </div> -->
<div id='debug' class='debug'>
</div>
</body>
</html><?php
// vim: set ai et ts=3 sw=3: