Improvements and fixes on index and itemrecord
This commit is contained in:
263
index.php
263
index.php
@@ -1,28 +1,78 @@
|
||||
<?php
|
||||
// Enable error reporting for development (remove in production)
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
// Include settings
|
||||
include_once "settings.php";
|
||||
|
||||
// Set up Calibre database connection
|
||||
$db = new SQLite3('metadata.sqlite');
|
||||
// Initialize variables
|
||||
$feature = null;
|
||||
$types = null;
|
||||
$db = null;
|
||||
|
||||
$feature = $db->query("SELECT
|
||||
books.id AS id,
|
||||
books.title AS title,
|
||||
authors.name AS author
|
||||
FROM books
|
||||
INNER JOIN books_authors_link ON books.id = books_authors_link.book
|
||||
INNER JOIN authors on authors.id = books_authors_link.author
|
||||
ORDER BY books.id DESC
|
||||
LIMIT 4");
|
||||
try {
|
||||
// Set up Calibre database connection with error handling
|
||||
if (!file_exists('metadata.sqlite')) {
|
||||
throw new Exception('Database file not found');
|
||||
}
|
||||
|
||||
$db = new SQLite3('metadata.sqlite');
|
||||
if (!$db) {
|
||||
throw new Exception('Unable to open database');
|
||||
}
|
||||
|
||||
// Set timeout to prevent locks
|
||||
$db->busyTimeout(5000);
|
||||
|
||||
// Get featured items (latest 4 by timestamp, not ID)
|
||||
$feature = $db->query("
|
||||
SELECT
|
||||
books.id AS id,
|
||||
books.title AS title,
|
||||
authors.name AS author
|
||||
FROM books
|
||||
INNER JOIN books_authors_link ON books.id = books_authors_link.book
|
||||
INNER JOIN authors ON authors.id = books_authors_link.author
|
||||
ORDER BY books.timestamp DESC
|
||||
LIMIT 4
|
||||
");
|
||||
|
||||
if (!$feature) {
|
||||
throw new Exception('Failed to fetch featured items');
|
||||
}
|
||||
|
||||
// Get types for menu
|
||||
$types = $db->query("
|
||||
SELECT value
|
||||
FROM custom_column_1
|
||||
ORDER BY value ASC
|
||||
");
|
||||
|
||||
if (!$types) {
|
||||
throw new Exception('Failed to fetch types');
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log('Database error in index.php: ' . $e->getMessage());
|
||||
// Display user-friendly error
|
||||
$error_message = 'Unable to load content. Please try again later.';
|
||||
}
|
||||
|
||||
$types = $db->query("SELECT
|
||||
value
|
||||
FROM custom_column_1
|
||||
ORDER BY value ASC");
|
||||
/**
|
||||
* Safely escape output for HTML
|
||||
*/
|
||||
function esc_html($text) {
|
||||
return htmlspecialchars($text ?? '', ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely escape output for HTML attributes
|
||||
*/
|
||||
function esc_attr($text) {
|
||||
return htmlspecialchars($text ?? '', ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
|
||||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
|
||||
@@ -31,68 +81,49 @@ ORDER BY value ASC");
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title><?php echo $SiteName.': '.$SubName;?></title>
|
||||
<title><?php echo esc_html($SiteName . ': ' . $SubName); ?></title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content=<?php echo '"'.$SiteName.' - '.$SubName.'"/>';?>
|
||||
<meta name="keywords" content="free software, open source, bibliography, cyberpunk, books, media, movies, video games" />
|
||||
<meta name="author" content="Daniel Messer" />
|
||||
<meta name="description" content="<?php echo esc_attr($SiteName . ' - ' . $SubName); ?>">
|
||||
<meta name="keywords" content="free software, open source, bibliography, cyberpunk, books, media, movies, video games">
|
||||
<meta name="author" content="Daniel Messer">
|
||||
|
||||
<!--
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
FREE HTML5 TEMPLATE
|
||||
DESIGNED & DEVELOPED by FREEHTML5.CO
|
||||
|
||||
Website: http://freehtml5.co/
|
||||
Email: info@freehtml5.co
|
||||
Twitter: http://twitter.com/fh5co
|
||||
Facebook: https://www.facebook.com/fh5co
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
-->
|
||||
|
||||
<!-- Facebook and Twitter integration -->
|
||||
<meta property="og:title" content=<?php echo '"'.$SiteName.'" />';?>
|
||||
|
||||
<meta property="og:image" content=<?php echo '"'.$SiteURL.'/images/og-site-avatar.jpg" />';?>
|
||||
|
||||
<meta property="og:url" content=<?php echo '"'.$SiteURL.'" />';?>
|
||||
|
||||
<meta property="og:site_name" content=<?php echo '"'.$SiteName.' - '.$SubName.'" />';?>
|
||||
|
||||
<meta property="og:description" content=<?php echo '"'.$SubName.'" />';?>
|
||||
|
||||
<meta name="twitter:title" content=<?php echo '"'.$SiteName.' - '.$SubName.'" />';?>
|
||||
|
||||
<meta name="twitter:image" content=<?php echo '"'.$SiteURL.'/images/og-site-avatar.jpg" />';?>
|
||||
|
||||
<meta name="twitter:url" content=<?php echo '"'.$SiteURL.'" />';?>
|
||||
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<!-- Facebook and Twitter integration -->
|
||||
<meta property="og:title" content="<?php echo esc_attr($SiteName); ?>">
|
||||
<meta property="og:image" content="<?php echo esc_attr($SiteURL . '/images/og-site-avatar.jpg'); ?>">
|
||||
<meta property="og:url" content="<?php echo esc_attr($SiteURL); ?>">
|
||||
<meta property="og:site_name" content="<?php echo esc_attr($SiteName . ' - ' . $SubName); ?>">
|
||||
<meta property="og:description" content="<?php echo esc_attr($SubName); ?>">
|
||||
<meta name="twitter:title" content="<?php echo esc_attr($SiteName . ' - ' . $SubName); ?>">
|
||||
<meta name="twitter:image" content="<?php echo esc_attr($SiteURL . '/images/og-site-avatar.jpg'); ?>">
|
||||
<meta name="twitter:url" content="<?php echo esc_attr($SiteURL); ?>">
|
||||
<meta name="twitter:card" content="summary">
|
||||
|
||||
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
|
||||
<link rel="shortcut icon" href="favicon.ico">
|
||||
<!-- Google Fonts -->
|
||||
<link href='http://fonts.googleapis.com/css?family=Playfair+Display:400,700,400italic|Roboto:400,300,700' rel='stylesheet' type='text/css'>
|
||||
<!-- Animate -->
|
||||
|
||||
<!-- Google Fonts - Updated to HTTPS -->
|
||||
<link href='https://fonts.googleapis.com/css?family=Playfair+Display:400,700,400italic|Roboto:400,300,700' rel='stylesheet' type='text/css'>
|
||||
|
||||
<!-- Stylesheets -->
|
||||
<link rel="stylesheet" href="css/animate.css">
|
||||
<!-- Icomoon -->
|
||||
<link rel="stylesheet" href="css/icomoon.css">
|
||||
<!-- Bootstrap -->
|
||||
<link rel="stylesheet" href="css/bootstrap.css">
|
||||
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
|
||||
|
||||
<!-- Modernizr JS -->
|
||||
<script src="js/modernizr-2.6.2.min.js"></script>
|
||||
<!-- FOR IE9 below -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="js/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php if (isset($error_message)): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php echo esc_html($error_message); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div id="fh5co-offcanvas">
|
||||
<a href="#" class="fh5co-close-offcanvas js-fh5co-close-offcanvas"><span><i class="icon-cross3"></i> <span>Close</span></span></a>
|
||||
<div class="fh5co-bio">
|
||||
@@ -101,22 +132,17 @@ ORDER BY value ASC");
|
||||
</figure>
|
||||
<h3 class="heading">About the Project</h3>
|
||||
<a href="index.php"><h2>Infopump</h2></a>
|
||||
<p>A bibliographic management and display system.<br /><a href="about.php">More info</a></p>
|
||||
<p>A bibliographic management and display system.<br><a href="about.php">More info</a></p>
|
||||
<hr>
|
||||
<p>A free, open source project from:<br />
|
||||
<a href="https://rss.com/podcasts/l0wl1f3podcast/">The L0WL1F3 Podcast</a><br />
|
||||
<a href="https://www.neondystopia.com/">Neon Dystopia</a><br />
|
||||
<p>A free, open source project from:<br>
|
||||
<a href="https://rss.com/podcasts/l0wl1f3podcast/">The L0WL1F3 Podcast</a><br>
|
||||
<a href="https://www.neondystopia.com/">Neon Dystopia</a><br>
|
||||
<a href="https://cyberpunklibrarian.com">Cyberpunk Librarian</a>
|
||||
</p>
|
||||
<hr>
|
||||
<p>
|
||||
<a href="https://cyberpunklibrarian.nohost.me/gitlab/code/infopump">GitLab</a>
|
||||
</p>
|
||||
<ul class="fh5co-social">
|
||||
<!--<li><a href="#"><i class="icon-twitter"></i></a></li>
|
||||
<li><a href="#"><i class="icon-facebook"></i></a></li>
|
||||
<li><a href="#"><i class="icon-instagram"></i></a></li>-->
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="fh5co-menu">
|
||||
@@ -124,81 +150,85 @@ ORDER BY value ASC");
|
||||
<h3 class="heading">Recent Additions</h3>
|
||||
<ul>
|
||||
<?php
|
||||
while ($row = $types->fetchArray()) {
|
||||
$row_value = $row['value'];
|
||||
$row_titlecase = mb_convert_case($row_value, MB_CASE_TITLE, "UTF-8");
|
||||
echo '<li><a href="recent.php?ty='.$row_value.'">'.$row_titlecase.'</a></li>';
|
||||
//echo '<li>'.$row_value.'</li>';
|
||||
|
||||
if ($types) {
|
||||
while ($row = $types->fetchArray()) {
|
||||
$row_value = $row['value'];
|
||||
$row_titlecase = mb_convert_case($row_value, MB_CASE_TITLE, "UTF-8");
|
||||
echo '<li><a href="recent.php?ty=' . urlencode($row_value) . '">'
|
||||
. esc_html($row_titlecase) . '</a></li>';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
<div class="fh5co-box">
|
||||
<h3 class="heading">Search</h3>
|
||||
<form action="results.php" method="get">
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control" name="kw" placeholder="Keyword search">
|
||||
<input type="text" class="form-control" name="kw" placeholder="Keyword search" required>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END #fh5co-offcanvas -->
|
||||
|
||||
<header id="fh5co-header">
|
||||
|
||||
<div class="container-fluid">
|
||||
|
||||
<div class="row">
|
||||
<a href="#" class="js-fh5co-nav-toggle fh5co-nav-toggle"><i></i></a>
|
||||
<ul class="fh5co-social">
|
||||
<!--<li><a href="#"><i class="icon-twitter"></i></a></li>
|
||||
<li><a href="#"><i class="icon-facebook"></i></a></li>
|
||||
<li><a href="#"><i class="icon-instagram"></i></a></li>-->
|
||||
</ul>
|
||||
<div class="col-lg-12 col-md-12 text-center">
|
||||
<h1 id="fh5co-logo"><a href="index.php">Infopump - Cyberpunk Culture Database</a></h1>
|
||||
<h3>Latest Additions</h3>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</header>
|
||||
<!-- END #fh5co-header -->
|
||||
|
||||
<!-- BEGIN Featured Covers -->
|
||||
<div class="container-fluid">
|
||||
<div class="row fh5co-post-entry">
|
||||
|
||||
<?php
|
||||
while ($row = $feature->fetchArray()) {
|
||||
$row_id = $row['id'];
|
||||
$row_title = $row['title'];
|
||||
$row_author = $row['author'];
|
||||
<!-- BEGIN Featured Covers -->
|
||||
<div class="container-fluid">
|
||||
<div class="row fh5co-post-entry">
|
||||
<?php
|
||||
if ($feature) {
|
||||
while ($row = $feature->fetchArray()) {
|
||||
$row_id = (int)$row['id'];
|
||||
$row_title = $row['title'];
|
||||
$row_author = $row['author'];
|
||||
|
||||
// Check if image exists, otherwise use placeholder
|
||||
$image_path = "images/{$row_id}.jpg";
|
||||
if (!file_exists($image_path)) {
|
||||
$image_path = "images/placeholder.jpg";
|
||||
}
|
||||
|
||||
echo '<article class="col-lg-3 col-md-3 col-sm-3 col-xs-6 col-xxs-12 animate-box">';
|
||||
echo '<figure>';
|
||||
echo '<a href="itemrecord.php?itemid='.$row_id.'"><img src="images/'.$row_id.'.jpg" title="'.$row_title.'" class="img-responsive"></a>';
|
||||
echo '</figure>';
|
||||
echo '<h2 class="fh5co-article-title"><a href="single.html">'.$row_title.'</a></h2>';
|
||||
echo '<span class="fh5co-meta fh5co-date">'.$row_author.'</span>';
|
||||
echo '</article>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END Featured Covers -->
|
||||
echo '<article class="col-lg-3 col-md-3 col-sm-3 col-xs-6 col-xxs-12 animate-box">';
|
||||
echo ' <figure>';
|
||||
echo ' <a href="itemrecord.php?itemid=' . $row_id . '">';
|
||||
echo ' <img src="' . esc_attr($image_path) . '" ';
|
||||
echo ' alt="' . esc_attr($row_title) . '" ';
|
||||
echo ' title="' . esc_attr($row_title) . '" ';
|
||||
echo ' class="img-responsive">';
|
||||
echo ' </a>';
|
||||
echo ' </figure>';
|
||||
echo ' <h2 class="fh5co-article-title">';
|
||||
echo ' <a href="itemrecord.php?itemid=' . $row_id . '">' . esc_html($row_title) . '</a>';
|
||||
echo ' </h2>';
|
||||
echo ' <span class="fh5co-meta fh5co-date">' . esc_html($row_author) . '</span>';
|
||||
echo '</article>';
|
||||
}
|
||||
} else {
|
||||
echo '<div class="col-lg-12"><p class="text-center">No items found.</p></div>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END Featured Covers -->
|
||||
|
||||
<footer id="fh5co-footer">
|
||||
<p><small>© Creative Commons By-NC-SA<br> Design by <a href="http://freehtml5.co" target="_blank">FREEHTML5.co</a></small></p>
|
||||
</footer>
|
||||
|
||||
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="js/jquery.min.js"></script>
|
||||
<!-- jQuery Easing -->
|
||||
@@ -212,4 +242,9 @@ ORDER BY value ASC");
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php
|
||||
// Clean up database connection
|
||||
if ($db) {
|
||||
$db->close();
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user