prepare($query);
$sth->bindValue(":username", $_SESSION['username'], PDO::PARAM_STR);
$sth->execute();
$comics_read = array();
$issues_read = array();
while ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) {
$comics_read[$row['comic']] = true;
$issues_read[$row['issue']] = true;
}
$adultcomics = array_flip(getAdultComics());
$folders = array();
$issues = array();
$entries = scandir($fullcompath);
$data["makethumb"] = array();
foreach ( $entries as $entry ) {
if ( ($entry == ".") || ($entry == "..") ) continue;
if ( (ADULTMODE || !$_SESSION['adult']) && isset($adultcomics[$entry]) ) continue;
$info = array();
$info["name"] = $entry;
$info["namesafe"] = htmlspecialchars($entry, ENT_QUOTES);
if ( is_dir($fullcompath . $entry) ) {
$info["comname"] = (strpos($entry, " - ") !== false) ? str_replace(" - ", "
", $entry) : $entry;
$info["newpath"] = $compath . (($compath == "/") ? "" : "/") . $entry;
if ( $_SESSION["sortorder"] == SORTBYDATE ) $info["mtime"] = filemtime($fullcompath . $entry);
//$info["thumburl"] = htmlentities(THUMBSDIR . $compath . (($compath == "/") ? "" : "/") . $entry, ENT_QUOTES) . ".jpg";
$info["thumburl"] = THUMBSDIR . $compath . (($compath == "/") ? "" : "/") . $entry . ".jpg";
if ( isset($comics_read[$entry]) ) {
$info["read"] = true;
$readclass = " readborder";
} else {
$info["read"] = false;
$readclass = "";
}
$info["div"] = "
";
$info["div"] .= "

{$info["comname"]}
";
$folders[] = $info;
} else {
if ( (substr($entry, -3) == "cbz") || (substr($entry, -3) == "cbr") ) {
$withoutext = substr($entry, 0, -4);
if ( strlen($withoutext) <= ISSUELENGTHCUTOFF ) {
$info["comname"] = str_replace(" - ", "
", $withoutext);
} else {
if ( strpos($withoutext, " - ") !== false ) {
$info["comname"] = substr($withoutext, strpos($withoutext, " - ") + 3);
} else {
$info["comname"] = $withoutext;
}
}
//$info["comname"] = substr(((strpos($entry, " - ") !== false) ? str_replace(" - ", "
", $entry) : $entry), 0, -4);
$info["relcomic"] = base64_encode($compath . (($compath == "/") ? "" : "/") . $entry);
if ( $_SESSION["sortorder"] == SORTBYDATE ) $info["mtime"] = filemtime($fullcompath . $entry);
$info["thumburl"] = THUMBSDIR . $compath . (($compath == "/") ? "" : "/") . $withoutext . ".jpg";
if ( isset($issues_read[$entry]) ) {
$info["read"] = true;
$readclass = " readborder";
} else {
$info["read"] = false;
$readclass = "";
}
$info["div"] = "";
$issues[] = $info;
$thumbfile = "../" . THUMBSDIR . $data['compath'] . "/" . $info['comname'] . ".jpg";
}
}
if ( isset($info["thumburl"]) && !file_exists("../" . $info["thumburl"]) ) {
$data["makethumb"][] = $info["thumburl"];
$havethumb = makeThumb($fullcompath . $entry);
}
}
// Sort folders based on current sort order
if ( $_SESSION["sortorder"] == SORTBYNAME ) {
usort($folders, "compareNames");
} else {
usort($folders, "compareDates");
}
// Always sort issues by name
usort($issues, "compareNames");
$data["contents"] = array_merge($folders, $issues);
header('Content-Type: application/json');
echo json_encode($data);
exit();
// vim: set ts=4 sw=4 et: