Compare commits

..

6 Commits

3 changed files with 58 additions and 38 deletions

View File

@ -20,18 +20,16 @@ if ( !$validated ) {
# usort function for sorting by array's "mtime" # usort function for sorting by array's "mtime"
# Return 1 or -1 in reverse order so newest is first # Return 1 or -1 in reverse order so newest is first
function compareDates($a, $b) { function compareDates($a, $b) {
if ( $a["mtime"] == $b["mtime"] ) return 0; return $b["mtime"] <=> $a["mtime"];
return ($a["mtime"] < $b["mtime"]) ? 1 : -1;
} }
# usort function for sorting by array's "name" # usort function for sorting by array's "name"
# Does "natural" sorting so "28 Days Later" comes before "2099 Hulk" # Does "natural" sorting so "28 Days Later" comes before "2099 Hulk"
function compareNames($a, $b) { function compareNames($a, $b) {
if ( $a["name"] == $b["name"] ) return 0; if ( $a["name"] == $b["name"] ) return 0;
return strnatcmp($a["name"], $b["name"]); return strnatcasecmp($a["name"], $b["name"]);
} }
$adultcomics = getAdultComics();
$compath = $_SESSION['compath']; $compath = $_SESSION['compath'];
$fullcompath = COMICSDIR . $compath . (($compath == "/") ? "" : "/") . "/"; $fullcompath = COMICSDIR . $compath . (($compath == "/") ? "" : "/") . "/";
@ -52,9 +50,10 @@ $sth->execute();
$comics_read = array(); $comics_read = array();
$issues_read = array(); $issues_read = array();
while ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) { while ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) {
if ( !in_array($row['comic'], $comics_read) ) $comics_read[] = $row['comic']; $comics_read[$row['comic']] = true;
if ( !in_array($row['issue'], $issues_read) ) $issues_read[] = $row['issue']; $issues_read[$row['issue']] = true;
} }
$adultcomics = array_flip(getAdultComics());
$folders = array(); $folders = array();
$issues = array(); $issues = array();
@ -62,24 +61,24 @@ $entries = scandir($fullcompath);
$data["makethumb"] = array(); $data["makethumb"] = array();
foreach ( $entries as $entry ) { foreach ( $entries as $entry ) {
if ( ($entry == ".") || ($entry == "..") ) continue; if ( ($entry == ".") || ($entry == "..") ) continue;
if ( (ADULTMODE || !$_SESSION['adult']) && in_array($entry, $adultcomics) ) continue; if ( (ADULTMODE || !$_SESSION['adult']) && isset($adultcomics[$entry]) ) continue;
$info = array(); $info = array();
$info["name"] = $entry; $info["name"] = $entry;
$info["namesafe"] = htmlspecialchars($entry, ENT_QUOTES); $info["namesafe"] = htmlspecialchars($entry, ENT_QUOTES);
if ( is_dir($fullcompath . $entry) ) { if ( is_dir($fullcompath . $entry) ) {
$info["comname"] = (strpos($entry, " - ") !== false) ? str_replace(" - ", "<br />", $entry) : $entry; $info["comname"] = (strpos($entry, " - ") !== false) ? str_replace(" - ", "<br />", $entry) : $entry;
$info["newpath"] = $compath . (($compath == "/") ? "" : "/") . $entry; $info["newpath"] = $compath . (($compath == "/") ? "" : "/") . $entry;
$info["mtime"] = filemtime($fullcompath . $entry); if ( $_SESSION["sortorder"] == SORTBYDATE ) $info["mtime"] = filemtime($fullcompath . $entry);
//$info["thumburl"] = htmlentities(THUMBSDIR . $compath . (($compath == "/") ? "" : "/") . $entry, ENT_QUOTES) . ".jpg"; //$info["thumburl"] = htmlentities(THUMBSDIR . $compath . (($compath == "/") ? "" : "/") . $entry, ENT_QUOTES) . ".jpg";
$info["thumburl"] = THUMBSDIR . $compath . (($compath == "/") ? "" : "/") . $entry . ".jpg"; $info["thumburl"] = THUMBSDIR . $compath . (($compath == "/") ? "" : "/") . $entry . ".jpg";
if ( in_array($entry, $comics_read) ) { if ( isset($comics_read[$entry]) ) {
$info["read"] = true; $info["read"] = true;
$readclass = " readborder"; $readclass = " readborder";
} else { } else {
$info["read"] = false; $info["read"] = false;
$readclass = ""; $readclass = "";
} }
$info["div"] = "<div class='item folder{$readclass}' data-path=\"{$info["newpath"]}\" data-name=\"{$info["comname"]}\">"; $info["div"] = "<div class='item folder{$readclass}' data-path=\"{$info["newpath"]}\" >";
$info["div"] .= "<img class='thumbnail' src=\"{$info["thumburl"]}\"><br clear=all />{$info["comname"]}</div>"; $info["div"] .= "<img class='thumbnail' src=\"{$info["thumburl"]}\"><br clear=all />{$info["comname"]}</div>";
$folders[] = $info; $folders[] = $info;
} else { } else {
@ -96,9 +95,9 @@ foreach ( $entries as $entry ) {
} }
//$info["comname"] = substr(((strpos($entry, " - ") !== false) ? str_replace(" - ", "<br />", $entry) : $entry), 0, -4); //$info["comname"] = substr(((strpos($entry, " - ") !== false) ? str_replace(" - ", "<br />", $entry) : $entry), 0, -4);
$info["relcomic"] = base64_encode($compath . (($compath == "/") ? "" : "/") . $entry); $info["relcomic"] = base64_encode($compath . (($compath == "/") ? "" : "/") . $entry);
$info["mtime"] = filemtime($fullcompath . $entry); if ( $_SESSION["sortorder"] == SORTBYDATE ) $info["mtime"] = filemtime($fullcompath . $entry);
$info["thumburl"] = THUMBSDIR . $compath . (($compath == "/") ? "" : "/") . $withoutext . ".jpg"; $info["thumburl"] = THUMBSDIR . $compath . (($compath == "/") ? "" : "/") . $withoutext . ".jpg";
if ( in_array($entry, $issues_read) ) { if ( isset($issues_read[$entry]) ) {
$info["read"] = true; $info["read"] = true;
$readclass = " readborder"; $readclass = " readborder";
} else { } else {
@ -109,7 +108,7 @@ foreach ( $entries as $entry ) {
$info["div"] .= "<img class='issue thumbnail' data-relcomic=\"{$info["relcomic"]}\" data-comname=\"{$info["comname"]}\" border=0 src=\"{$info["thumburl"]}\">"; $info["div"] .= "<img class='issue thumbnail' data-relcomic=\"{$info["relcomic"]}\" data-comname=\"{$info["comname"]}\" border=0 src=\"{$info["thumburl"]}\">";
$info["div"] .= "<br clear=all /><a href=\"downloadcomic.php?comic={$info["relcomic"]}\">{$info["comname"]}</a></div>"; $info["div"] .= "<br clear=all /><a href=\"downloadcomic.php?comic={$info["relcomic"]}\">{$info["comname"]}</a></div>";
$issues[] = $info; $issues[] = $info;
$thumbfile = "../" . THUMBSDIR . $data['compath'] . "/" . $info['comname'] . ".jpg"; //$thumbfile = "../" . THUMBSDIR . $data['compath'] . "/" . $info['comname'] . ".jpg";
} }
} }
if ( isset($info["thumburl"]) && !file_exists("../" . $info["thumburl"]) ) { if ( isset($info["thumburl"]) && !file_exists("../" . $info["thumburl"]) ) {

View File

@ -19,7 +19,7 @@ if ( !$validated ) {
} }
if ( isset($_REQUEST['comic']) ) { if ( isset($_REQUEST['comic']) ) {
$comicfull = realpath(COMICSDIR . base64_decode(urldecode($_REQUEST['comic']))); $comicfull = realpath(COMICSDIR . base64_decode($_REQUEST['comic']));
$data["filename"] = basename($comicfull); $data["filename"] = basename($comicfull);
if ( $comicfull === false ) exit(); if ( $comicfull === false ) exit();
if ( substr($comicfull, 0, strlen(COMICSDIR)) != COMICSDIR ) exit(); if ( substr($comicfull, 0, strlen(COMICSDIR)) != COMICSDIR ) exit();
@ -62,12 +62,23 @@ if ( $extracted ) {
$files[] = basename($i); $files[] = basename($i);
} }
} else { } else {
if ( $ext == "cbz" ) { $magic = file_get_contents($comicfull, false, null, 0, 4);
if ( substr($magic, 0, 2) === "PK" ) {
$comtype = "cbz";
} elseif ( $magic === "Rar!" ) {
$comtype = "cbr";
}
if ( $comtype == "cbz" ) {
$zip = new ZipArchive(); $zip = new ZipArchive();
$opened = $zip->open($comicfull); $opened = $zip->open($comicfull);
if ( !$opened ) {
$data["error"] = true;
$data["message"] = "Error opening comic file";
} else {
for ( $i=0; $i<$zip->numFiles; $i++ ) { for ( $i=0; $i<$zip->numFiles; $i++ ) {
$imgname = basename($zip->getNameIndex($i)); $imgname = basename($zip->getNameIndex($i));
if ( ! isset(pathinfo($imgname)['extension']) ) continue; if ( ! isset(pathinfo($imgname)['extension']) ) continue;
if ( (substr($imgname, 0, 8) == "__MACOSX") || (substr($imgname, 0, 2) == "._") ) continue;
$myext = strtolower(pathinfo($imgname)['extension']); $myext = strtolower(pathinfo($imgname)['extension']);
if ( ! in_array($myext, VALIDIMAGETYPES) ) continue; if ( ! in_array($myext, VALIDIMAGETYPES) ) continue;
$imgname = str_replace("#", "", $imgname); $imgname = str_replace("#", "", $imgname);
@ -75,20 +86,30 @@ if ( $extracted ) {
$written = file_put_contents($comicoutputfull . $imgname, $imgcontents); $written = file_put_contents($comicoutputfull . $imgname, $imgcontents);
if ( $written ) $files[] = $imgname; if ( $written ) $files[] = $imgname;
} }
} elseif ( $ext == "cbr" ) { $zip->close();
}
} elseif ( $comtype == "cbr" ) {
$rar = RarArchive::open($comicfull); $rar = RarArchive::open($comicfull);
if ( $rar === false ) {
$data["error"] = true;
$data["message"] = "Error opening comic file";
} else {
$entries = $rar->getEntries(); $entries = $rar->getEntries();
foreach ( $entries as $entry ) { foreach ( $entries as $entry ) {
$outfile = str_replace("#", "", basename($entry->getName())); $outfile = str_replace("#", "", basename($entry->getName()));
if ( ! isset(pathinfo($outfile)['extension']) ) continue; if ( ! isset(pathinfo($outfile)['extension']) ) continue;
if ( (substr($outfile, 0, 8) == "__MACOSX") || (substr($outfile, 0, 2) == "._") ) continue;
$myext = strtolower(pathinfo($outfile)['extension']); $myext = strtolower(pathinfo($outfile)['extension']);
if ( ! in_array($myext, VALIDIMAGETYPES) ) continue; if ( ! in_array($myext, VALIDIMAGETYPES) ) continue;
$entry->extract(false, $comicoutputfull . $outfile); $entry->extract(false, $comicoutputfull . $outfile);
$files[] = basename($outfile); $files[] = basename($outfile);
} }
unset($entry); unset($entry);
$rar->close();
}
} else { } else {
exit(); $data["error"] = true;
$data["message"] = "Error invalid comic file format";
} }
} }

View File

@ -62,8 +62,8 @@ a, a:link, a:visited, a:active {
.item { .item {
cursor: pointer; cursor: pointer;
width: 25vw; width: 20vw;
height: calc(25vw * 1.5 + 2em); height: calc(20vw * 1.5 + 2em);
margin: 5px; margin: 5px;
border: 2px solid var(--foreground-color); border: 2px solid var(--foreground-color);
padding: 2px; padding: 2px;
@ -73,7 +73,7 @@ a, a:link, a:visited, a:active {
} }
.thumbnail { .thumbnail {
width: 95%; width: 98%;
} }
.readborder { .readborder {