Compare commits

..

13 Commits

8 changed files with 48 additions and 36 deletions

View File

@ -41,6 +41,7 @@ if ( !is_dir($fullcompath) ) {
$_SESSION['compath'] = $compath; $_SESSION['compath'] = $compath;
setcookie("compath", $compath, time()+31536000, "/", "jaj.com", true); 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 // 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";
@ -79,7 +80,7 @@ foreach ( $entries as $entry ) {
$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"]}\" data-name=\"{$info["comname"]}\">";
$info["div"] .= "<img 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 {
if ( (substr($entry, -3) == "cbz") || (substr($entry, -3) == "cbr") ) { if ( (substr($entry, -3) == "cbz") || (substr($entry, -3) == "cbr") ) {
@ -105,7 +106,7 @@ foreach ( $entries as $entry ) {
$readclass = ""; $readclass = "";
} }
$info["div"] = "<div class='item{$readclass}'>"; $info["div"] = "<div class='item{$readclass}'>";
$info["div"] .= "<img class='issue' 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";

View File

@ -1,11 +0,0 @@
<?php
require '../header.php';
require_login();
$data = $_SESSION;
header('Content-Type: application/json');
echo json_encode($data);
exit();

View File

@ -1,6 +1,7 @@
<?php <?php
require '../header.php'; require '../header.php';
session_write_close();
$validated = require_login(NOREDIRECT); $validated = require_login(NOREDIRECT);
$data = array(); $data = array();

View File

@ -21,7 +21,7 @@ if ( !$validated ) {
$newpath = urldecode($_REQUEST['path']); $newpath = urldecode($_REQUEST['path']);
$comicfull = realpath(COMICSDIR . $newpath); $comicfull = realpath(COMICSDIR . "/" . $newpath);
if ( ($newpath == "/") || ($comicfull === false) || (substr($comicfull, 0, strlen(COMICSDIR)) != COMICSDIR) ) { if ( ($newpath == "/") || ($comicfull === false) || (substr($comicfull, 0, strlen(COMICSDIR)) != COMICSDIR) ) {
$_SESSION['compath'] = "/"; $_SESSION['compath'] = "/";
} else { } else {

View File

@ -32,6 +32,7 @@ if ( isset($_REQUEST['comic']) ) {
$ext = strtolower(substr($comicfull, -3)); $ext = strtolower(substr($comicfull, -3));
$_SESSION['comfile'] = basename($comicfull); $_SESSION['comfile'] = basename($comicfull);
session_write_close();
// Get the current page for this comic or 0 (zero) if never opened // Get the current page for this comic or 0 (zero) if never opened
$query = "SELECT currentpage FROM pagetracker WHERE username=:username AND issue=:issue"; $query = "SELECT currentpage FROM pagetracker WHERE username=:username AND issue=:issue";

View File

@ -62,13 +62,18 @@ a, a:link, a:visited, a:active {
.item { .item {
cursor: pointer; cursor: pointer;
width: 330px; width: 25vw;
height: 495px; height: calc(25vw * 1.5 + 2em);
margin: 5px; margin: 5px;
border: 2px solid var(--foreground-color); border: 2px solid var(--foreground-color);
padding: 2px; padding: 2px;
display: inline-block; display: inline-block;
overflow: hidden; overflow: hidden;
font-size: 2vw;
}
.thumbnail {
width: 95%;
} }
.readborder { .readborder {

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=0.38, minimum-scale=0.25, maximum-scale=3.0, user-scalable=yes" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.25, maximum-scale=3.0, user-scalable=yes" />
<meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="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="128x128" href="img/comics_128.png" />

View File

@ -1,14 +1,22 @@
const NOREFRESH = false; let folderRequest = false;
let lightbox = null;
toastr.options.escapeHtml = true;
toastr.options.preventDuplicates = true;
// This function is executed after the page load completes on the client // This function is executed after the page load completes on the client
$(document).ready(function() { $(document).ready(function() {
$("#path").click(function() { changeFolder("/"); }); $("#path").click(function() { changeFolder("/"); });
$("#sortorder").on("click", cycleSortOrder); $("#sortorder").on("click", cycleSortOrder);
$("#list").on("click", ".folder", function() {
changeFolder($(this).data("path"));
});
$("#list").on("click", ".issue", function() {
$(this).parent().addClass("readborder");
showComic($(this).data("relcomic"), $(this).data("comname"));
});
getSortOrder(); getSortOrder();
}); });
var lightbox = null;
/** /**
* Redirects the user to the login page by replacing the current location with "index.php". * Redirects the user to the login page by replacing the current location with "index.php".
* Logs a message to the console before redirecting. * Logs a message to the console before redirecting.
@ -30,12 +38,12 @@ function getSortOrder(refresh = true) {
if ( !data.validated ) { if ( !data.validated ) {
redirectToLogin(); redirectToLogin();
return; return;
} else { }
$("#sortorder").html(data.order); $("#sortorder").html(data.order);
if ( refresh ) getFolderContents(); if ( refresh ) getFolderContents();
}
}, },
error : function(xhr, stat, err) { error : function(xhr, stat, err) {
toastr.error("There was an error retrieving the current sort order.", "API Error...", {timeOut: 15000});
console.log(xhr.status); console.log(xhr.status);
console.log(err); console.log(err);
} }
@ -50,17 +58,18 @@ function getSortOrder(refresh = true) {
function cycleSortOrder() { function cycleSortOrder() {
$.ajax({ $.ajax({
url : 'ajax/cyclesortorder.php', url : 'ajax/cyclesortorder.php',
type : 'POST',
dataType : 'json', dataType : 'json',
success : function(data, stat, jqo) { success : function(data, stat, jqo) {
if ( !data.validated ) { if ( !data.validated ) {
redirectToLogin(); redirectToLogin();
return; return;
} else { }
$("#sortorder").html(data.order); $("#sortorder").html(data.order);
getFolderContents(); getFolderContents();
}
}, },
error : function(xhr, stat, err) { error : function(xhr, stat, err) {
toastr.error("There was an error retrieving the cycling sort order.", "API Error...", {timeOut: 15000});
console.log(xhr.status); console.log(xhr.status);
console.log(err); console.log(err);
} }
@ -74,15 +83,15 @@ function cycleSortOrder() {
* - Shows a loading notification to the user. * - Shows a loading notification to the user.
* - Sends an AJAX request to retrieve folder contents as JSON. * - Sends an AJAX request to retrieve folder contents as JSON.
* - If the user is not validated, redirects to the login page. * - If the user is not validated, redirects to the login page.
* - Updates the current path and path navigator.
* - Appends each folder or issue entry to the list. * - Appends each folder or issue entry to the list.
* - Attaches click handlers to folder and issue elements for navigation and reading.
* - Removes the loading notification upon completion. * - Removes the loading notification upon completion.
* *
* @function * @function
* @returns {void} * @returns {void}
*/ */
function getFolderContents() { function getFolderContents() {
if ( folderRequest ) return;
folderRequest = true;
$("#list").html(""); $("#list").html("");
toastr.info("Loading folder contents. Comics containing a large number of issues, or issues with a large number of pages, that have not been opened recently may take some time to load. Thank you for your patience!", "Loading Contents...", {timeOut: 15000}); toastr.info("Loading folder contents. Comics containing a large number of issues, or issues with a large number of pages, that have not been opened recently may take some time to load. Thank you for your patience!", "Loading Contents...", {timeOut: 15000});
$.ajax({ $.ajax({
@ -93,16 +102,16 @@ function getFolderContents() {
redirectToLogin(); redirectToLogin();
return; return;
} }
data.contents.forEach(function(entry, index) { $("#list").html(data.contents.map(e => e.div).join(""));
$("#list").append(entry.div);
});
$(".folder").click(function() { changeFolder($(this).data("path")); });
$(".issue").click(function() { $(this).parent().addClass("readborder"); showComic($(this).data("relcomic"), $(this).data("comname")); });
toastr.remove(); toastr.remove();
}, },
error : function(xhr, stat, err) { error : function(xhr, stat, err) {
toastr.error("There was an error retrieving the current folder contents.", "API Error...", {timeOut: 15000});
console.log(xhr.status); console.log(xhr.status);
console.log(err); console.log(err);
},
complete : function(xhr, stat) {
folderRequest = false;
} }
}); });
} }
@ -111,12 +120,12 @@ function getFolderContents() {
* Changes the current folder by sending an AJAX request to update the path on the server. * Changes the current folder by sending an AJAX request to update the path on the server.
* Displays a notification to the user and updates global variables upon success. * Displays a notification to the user and updates global variables upon success.
* *
* @param {string} name - The display name of the folder to open.
* @param {string} path - The path of the folder to open. * @param {string} path - The path of the folder to open.
*/ */
function changeFolder(path) { function changeFolder(path) {
$.ajax({ $.ajax({
url : 'ajax/setpath.php', url : 'ajax/setpath.php',
type : 'POST',
data : {path: path}, data : {path: path},
dataType : 'json', dataType : 'json',
success : function(data, stat, jqo) { success : function(data, stat, jqo) {
@ -128,6 +137,7 @@ function changeFolder(path) {
getFolderContents(); getFolderContents();
}, },
error : function(xhr, stat, err) { error : function(xhr, stat, err) {
toastr.error("There was an error setting the current folder.", "API Error...", {timeOut: 15000});
console.log(xhr.status); console.log(xhr.status);
console.log(err); console.log(err);
} }
@ -144,9 +154,10 @@ function changeFolder(path) {
* @returns {void} * @returns {void}
*/ */
function updateCurrentPage() { function updateCurrentPage() {
var currentPage = lightbox.currentPosition; let currentPage = lightbox.currentPosition;
$.ajax({ $.ajax({
url : 'ajax/setpage.php', url : 'ajax/setpage.php',
type : 'POST',
data : {page: currentPage}, data : {page: currentPage},
dataType : 'json', dataType : 'json',
success : function(data, stat, jqo) { success : function(data, stat, jqo) {
@ -157,6 +168,7 @@ function updateCurrentPage() {
console.log(data.message); console.log(data.message);
}, },
error : function(xhr, stat, err) { error : function(xhr, stat, err) {
toastr.error("There was an error setting current page for comic.", "API Error...", {timeOut: 15000});
console.log(xhr.status); console.log(xhr.status);
console.log(err); console.log(err);
} }
@ -170,6 +182,7 @@ function updateCurrentPage() {
function closeComic() { function closeComic() {
$.ajax({ $.ajax({
url : 'ajax/closecomic.php', url : 'ajax/closecomic.php',
type : 'POST',
dataType : 'json', dataType : 'json',
success : function(data, stat, jqo) { success : function(data, stat, jqo) {
if ( !data.validated ) { if ( !data.validated ) {
@ -178,6 +191,7 @@ function closeComic() {
} }
}, },
error : function(xhr, stat, err) { error : function(xhr, stat, err) {
toastr.error("There was an error closing the current comic.", "API Error...", {timeOut: 15000});
console.log(xhr.status); console.log(xhr.status);
console.log(err); console.log(err);
} }
@ -202,7 +216,7 @@ function showComic(comic, name) {
return; return;
} }
toastr.remove(); toastr.remove();
if ( data.images.length == 0 ) { if ( data.images.length === 0 ) {
toastr.error("There doesn't seem to be any images in this comic. Please contact the admin!", "Comics is empty", {timeOut: 8000}); toastr.error("There doesn't seem to be any images in this comic. Please contact the admin!", "Comics is empty", {timeOut: 8000});
return; return;
} }
@ -215,6 +229,7 @@ function showComic(comic, name) {
}); });
}, },
error : function(xhr, stat, err) { error : function(xhr, stat, err) {
toastr.error("There was an error showing selected comic contents.", "API Error...", {timeOut: 15000});
console.log(xhr.status); console.log(xhr.status);
console.log(err); console.log(err);
} }