diff --git a/archive/settings-old.php b/archive/settings-old.php new file mode 100644 index 0000000..70150a9 --- /dev/null +++ b/archive/settings-old.php @@ -0,0 +1,24 @@ +query('SELECT description FROM site WHERE id = 1'); + +while ($row = $getName->fetchArray()) { + $SiteName = $row['description']; +} + +$getSubName = $sitesettings->query('SELECT description FROM site WHERE id = 2'); + +while ($row = $getSubName->fetchArray()) { + $SubName = $row['description']; +} + +$getURL = $sitesettings->query('SELECT description FROM site WHERE id = 3'); + +while ($row = $getURL->fetchArray()) { + $SiteURL = $row['description']; +} + + +?> \ No newline at end of file diff --git a/recent.php b/recent.php index 21d2908..ca4cde3 100644 --- a/recent.php +++ b/recent.php @@ -2,80 +2,131 @@ include_once "settings.php"; -// Get and use a basic title search for pulling records. -$keywordsearch = htmlspecialchars($_GET["kw"]); -$authorsearch = htmlspecialchars($_GET["au"]); -$typesearch = htmlspecialchars($_GET["ty"]); +// Initialize variables +$keywordsearch = ''; +$authorsearch = ''; +$typesearch = ''; +$searchtopic = ''; +$searchtype = ''; -$socialkw = mb_convert_case($keywordsearch, MB_CASE_TITLE, "UTF-8"); -$socialau = mb_convert_case($authorsearch, MB_CASE_TITLE, "UTF-8"); -$socialty = mb_convert_case($typesearch, MB_CASE_TITLE, "UTF-8"); - -if (!empty($keywordsearch)) { - $searchtopic = 'Keyword: '.$socialkw; -} elseif (!empty($authorsearch)) { - $searchtopic = 'Author: '.$socialau; -} else { - $searchtopic = 'Type: '.$socialty; +// Sanitize and validate input +if (!empty($_GET["kw"])) { + $keywordsearch = trim($_GET["kw"]); + $searchtopic = 'Keyword: ' . htmlspecialchars($keywordsearch, ENT_QUOTES, 'UTF-8'); + $searchtype = 'keyword'; +} elseif (!empty($_GET["au"])) { + $authorsearch = trim($_GET["au"]); + $searchtopic = 'Author: ' . htmlspecialchars($authorsearch, ENT_QUOTES, 'UTF-8'); + $searchtype = 'author'; +} elseif (!empty($_GET["ty"])) { + $typesearch = trim($_GET["ty"]); + $searchtopic = 'Type: ' . htmlspecialchars(mb_convert_case($typesearch, MB_CASE_TITLE, "UTF-8"), ENT_QUOTES, 'UTF-8'); + $searchtype = 'type'; } +// If no valid search parameter, redirect to index +if (empty($searchtype)) { + header('Location: index.php'); + exit; +} // -------------------- BEGIN DATABASE QUERIES -------------------- -// Establish atabase connection -$db = new SQLite3('metadata.sqlite'); +// Establish database connection +try { + $db = new SQLite3('metadata.sqlite'); + $db->enableExceptions(true); +} catch (Exception $e) { + error_log("Database connection error: " . $e->getMessage()); + die("Database connection failed"); +} -$keywordquery = $db->query("SELECT -DISTINCT books.id AS id, -books.title AS title, -SUBSTR(comments.text,0,120) AS excerpt -FROM books -INNER JOIN -comments ON comments.book = books.id -INNER JOIN -books_tags_link ON books_tags_link.book = books.id -INNER JOIN -tags ON tags.id = books_tags_link.tag -WHERE books.title LIKE '%$keywordsearch%' -OR books.author_sort LIKE '%$keywordsearch%' -OR comments.text LIKE '%$keywordsearch%' -OR tags.name LIKE '%$keywordsearch%' -ORDER BY books.timestamp DESC"); +// Prepare the appropriate query based on search type +$results = null; -$authorquery = $db->query("SELECT -DISTINCT books.id AS id, -books.title AS title, -SUBSTR(comments.text,0,120) AS excerpt -FROM books -INNER JOIN -comments ON comments.book = books.id -INNER JOIN -books_tags_link ON books_tags_link.book = books.id -WHERE books.author_sort LIKE '%$authorsearch%' -ORDER BY books.timestamp DESC"); +switch ($searchtype) { + case 'keyword': + $searchPattern = '%' . $keywordsearch . '%'; + $stmt = $db->prepare("SELECT + DISTINCT books.id AS id, + books.title AS title, + SUBSTR(comments.text, 0, 120) AS excerpt + FROM books + INNER JOIN comments ON comments.book = books.id + INNER JOIN books_tags_link ON books_tags_link.book = books.id + INNER JOIN tags ON tags.id = books_tags_link.tag + WHERE books.title LIKE :search + OR books.author_sort LIKE :search + OR comments.text LIKE :search + OR tags.name LIKE :search + ORDER BY books.timestamp DESC + LIMIT 100"); + $stmt->bindValue(':search', $searchPattern, SQLITE3_TEXT); + break; + + case 'author': + $searchPattern = '%' . $authorsearch . '%'; + $stmt = $db->prepare("SELECT + DISTINCT books.id AS id, + books.title AS title, + SUBSTR(comments.text, 0, 120) AS excerpt + FROM books + INNER JOIN comments ON comments.book = books.id + INNER JOIN books_tags_link ON books_tags_link.book = books.id + WHERE books.author_sort LIKE :search + ORDER BY books.timestamp DESC + LIMIT 100"); + $stmt->bindValue(':search', $searchPattern, SQLITE3_TEXT); + break; + + case 'type': + $stmt = $db->prepare("SELECT + DISTINCT books.id AS id, + books.title AS title, + SUBSTR(comments.text, 0, 120) AS excerpt + FROM books + INNER JOIN comments ON comments.book = books.id + INNER JOIN books_custom_column_1_link ON books_custom_column_1_link.book = books.id + INNER JOIN custom_column_1 ON custom_column_1.id = books_custom_column_1_link.value + WHERE custom_column_1.value = :search + ORDER BY books.timestamp DESC + LIMIT 100"); + $stmt->bindValue(':search', $typesearch, SQLITE3_TEXT); + break; +} -$typequery = $db->query("SELECT -DISTINCT books.id AS id, -books.title AS title, -SUBSTR(comments.text,0,120) AS excerpt -FROM books -INNER JOIN -comments ON comments.book = books.id -INNER JOIN -books_custom_column_1_link ON books_custom_column_1_link.book = books.id -INNER JOIN -custom_column_1 ON custom_column_1.id = books_custom_column_1_link.value -WHERE -custom_column_1.value = '$typesearch' -ORDER BY books.timestamp DESC"); +// Execute query and handle errors +try { + $results = $stmt->execute(); +} catch (Exception $e) { + error_log("Query execution error: " . $e->getMessage()); + $results = null; +} + +// Get types for menu +try { + $types = $db->query("SELECT value FROM custom_column_1 ORDER BY value ASC"); +} catch (Exception $e) { + error_log("Types query error: " . $e->getMessage()); + $types = null; +} + +// Build social media URLs safely +$socialUrl = ''; +switch ($searchtype) { + case 'keyword': + $socialUrl = $SiteURL . '/recent.php?kw=' . urlencode($keywordsearch); + break; + case 'author': + $socialUrl = $SiteURL . '/recent.php?au=' . urlencode($authorsearch); + break; + case 'type': + $socialUrl = $SiteURL . '/recent.php?ty=' . urlencode($typesearch); + break; +} -$types = $db->query("SELECT -value -FROM custom_column_1 -ORDER BY value ASC"); ?> - @@ -84,9 +135,9 @@ ORDER BY value ASC");
-A bibliographic management and display system.
+A bibliographic management and display system.
More info
A free, open source project from:
The L0WL1F3 Podcast
@@ -173,8 +203,8 @@ ORDER BY value ASC");
Cyberpunk Librarian
'.$row_title.' : '.strip_tags($row_excerpt).'...
';
+ echo '
';
+ echo '' . $row_title . ' : ';
+ echo $row_excerpt . '...
No recent items found.
'; + } + } else { + echo 'An error occurred while retrieving recent items. Please try again.
'; } - } elseif ($typesearch != '') { - while ($row = $typequery->fetchArray()) { - $row_id = $row['id']; - $row_title = $row['title']; - $row_excerpt = $row['excerpt']; - - echo '
'.$row_title.' : '.strip_tags($row_excerpt).'...
'.$row_title.' : '.strip_tags($row_excerpt).'...