Add a closecomic callback to clear out the comfile session variable when a shown comic is closed

This commit is contained in:
Junior 2026-02-16 12:59:27 -05:00
parent b3c86ac931
commit 078ea8d4fa
2 changed files with 46 additions and 1 deletions

23
ajax/closecomic.php Normal file
View File

@ -0,0 +1,23 @@
<?php
require '../header.php';
$validated = require_login(NOREDIRECT);
$data = array();
$data["error"] = false;
$data["message"] = "";
$data["validated"] = $validated;
if ( !$validated ) {
$data["error"] = true;
$data["message"] = "Clients must validate accounts";
header('Content-Type: application/json');
echo json_encode($data);
exit();
}
$_SESSION['comfile'] = "";
header('Content-Type: application/json');
echo json_encode($data);
exit();

View File

@ -190,6 +190,27 @@ function updateCurrentPage() {
}); });
} }
//
// This function hits the closecomic endpoint to clear out
// the current comic in the session.
//
function closeComic() {
$.ajax({
url : 'ajax/closecomic.php',
dataType : 'json',
success : function(data, stat, jqo) {
if ( !data.validated ) {
redirectToLogin();
return;
}
},
error : function(xhr, stat, err) {
console.log(xhr.status);
console.log(err);
}
});
}
// //
// This JS function is called when a user clicks on a comic. // This JS function is called when a user clicks on a comic.
// "showcomic.php" is called with the comic to view as a parameter. // "showcomic.php" is called with the comic to view as a parameter.
@ -211,7 +232,8 @@ function showComic(comic, name) {
items: data.images, items: data.images,
captions: data.captions, captions: data.captions,
startAt: data.startindex, startAt: data.startindex,
beforeSetContent: updateCurrentPage beforeSetContent: updateCurrentPage,
beforeClose: closeComic
}); });
}, },
error : function(xhr, stat, err) { error : function(xhr, stat, err) {