$a["mtime"]; } # usort function for sorting by array's "name" # Does "natural" sorting so "28 Days Later" comes before "2099 Hulk" function compareNames($a, $b) { if ( $a["name"] == $b["name"] ) return 0; return strnatcasecmp($a["name"], $b["name"]); } $compath = $_SESSION['compath']; $fullcompath = COMICSDIR . $compath . (($compath == "/") ? "" : "/") . "/"; if ( !is_dir($fullcompath) ) { $compath = "/"; $fullcompath = COMICSDIR . $compath . (($compath == "/") ? "" : "/") . "/"; $_SESSION['compath'] = $compath; setcookie("compath", $compath, time()+31536000, "/", "jaj.com", true); } session_write_close(); // Build up a list of comics and issues which have been read in descending order by lastupdate $query = "SELECT comic, issue FROM pagetracker WHERE username=:username"; //$query = "SELECT comic, issue FROM pagetracker WHERE username=:username ORDER BY lastupdate DESC"; $sth = $globaldbh->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"] = (strlen($withoutext) >= ISSUELENGTHCUTOFF) ? substr($withoutext, strlen($compath)) : $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"] = "
"; $info["div"] .= ""; $info["div"] .= "
{$info["comname"]}
"; $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: