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"); - Infopump - Recently Added - <?php echo $searchtopic; ?> + Infopump - Recently Added - <?php echo htmlspecialchars($searchtopic, ENT_QUOTES, 'UTF-8'); ?> - + @@ -105,33 +156,14 @@ ORDER BY value ASC"); --> - ';?> - - ';?> - - '; - echo ''; - } elseif (!empty($authorsearch)) { - echo ''; - echo ''; - } else { - echo ''; - echo ''; - } - ?> - - ';?> - - ';?> - - ';?> - - ';?> - - - + + + + + + + + @@ -144,10 +176,8 @@ ORDER BY value ASC"); - - @@ -165,7 +195,7 @@ ORDER BY value ASC");

About the Project

Infopump

-

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

@@ -184,22 +214,22 @@ ORDER BY value ASC");

Recent Additions

+

Search

- +
@@ -219,7 +249,7 @@ ORDER BY value ASC");
  • -->
    -

    Recently Added

    +

    Recently Added

    @@ -235,31 +265,26 @@ ORDER BY value ASC");
    fetchArray()) { - $row_id = $row['id']; - $row_title = $row['title']; - $row_excerpt = $row['excerpt']; - - echo '

    '.$row_title.' : '.strip_tags($row_excerpt).'...

    '; + if ($results) { + $hasResults = false; + while ($row = $results->fetchArray(SQLITE3_ASSOC)) { + $hasResults = true; + $row_id = (int)$row['id']; + $row_title = htmlspecialchars($row['title'], ENT_QUOTES, 'UTF-8'); + $row_excerpt = htmlspecialchars(strip_tags($row['excerpt']), ENT_QUOTES, 'UTF-8'); + + echo '

    '; + echo '' . $row_title . ''; + echo '' . $row_title . ' : '; + echo $row_excerpt . '...

    '; + } + + if (!$hasResults) { + echo '

    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).'...

    '; - } - } else { - while ($row = $authorquery->fetchArray()) { - $row_id = $row['id']; - $row_title = $row['title']; - $row_excerpt = $row['excerpt']; - - echo '

    '.$row_title.' : '.strip_tags($row_excerpt).'...

    '; - } - } ?>
    @@ -270,7 +295,7 @@ ORDER BY value ASC"); @@ -287,3 +312,7 @@ ORDER BY value ASC"); +close(); +?> \ No newline at end of file diff --git a/settings.php b/settings.php index 70150a9..a2a843d 100644 --- a/settings.php +++ b/settings.php @@ -1,24 +1,68 @@ query('SELECT description FROM site WHERE id = 1'); +// Initialize default values +$SiteName = 'Infopump'; +$SubName = 'A bibliographic display system'; +$SiteURL = ''; -while ($row = $getName->fetchArray()) { - $SiteName = $row['description']; +try { + // Establish database connection + $sitesettings = new SQLite3('settings.sqlite', SQLITE3_OPEN_READONLY); + $sitesettings->enableExceptions(true); + + // Fetch all settings in a single query for efficiency + $stmt = $sitesettings->prepare('SELECT id, description FROM site WHERE id IN (1, 2, 3) ORDER BY id'); + $result = $stmt->execute(); + + // Process results + $settings = []; + while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + $settings[(int)$row['id']] = $row['description']; + } + + // Assign settings to variables with validation + if (isset($settings[1]) && !empty(trim($settings[1]))) { + $SiteName = htmlspecialchars(trim($settings[1]), ENT_QUOTES, 'UTF-8'); + } + + if (isset($settings[2]) && !empty(trim($settings[2]))) { + $SubName = htmlspecialchars(trim($settings[2]), ENT_QUOTES, 'UTF-8'); + } + + if (isset($settings[3]) && !empty(trim($settings[3]))) { + // Validate and sanitize URL + $url = trim($settings[3]); + // Remove trailing slash for consistency + $url = rtrim($url, '/'); + // Basic URL validation + if (filter_var($url, FILTER_VALIDATE_URL)) { + $SiteURL = htmlspecialchars($url, ENT_QUOTES, 'UTF-8'); + } else { + error_log("Invalid site URL in settings: " . $url); + } + } + + // Close database connection + $sitesettings->close(); + +} catch (Exception $e) { + // Log error but continue with default values + error_log("Settings database error: " . $e->getMessage()); + + // Ensure variables are set even if database fails + if (!isset($SiteName)) $SiteName = 'Infopump'; + if (!isset($SubName)) $SubName = 'A bibliographic display system'; + if (!isset($SiteURL)) $SiteURL = ''; } -$getSubName = $sitesettings->query('SELECT description FROM site WHERE id = 2'); - -while ($row = $getSubName->fetchArray()) { - $SubName = $row['description']; +// Verify all required settings are defined +if (empty($SiteName) || empty($SubName)) { + error_log("Critical site settings are missing or empty"); } -$getURL = $sitesettings->query('SELECT description FROM site WHERE id = 3'); - -while ($row = $getURL->fetchArray()) { - $SiteURL = $row['description']; -} - - ?> \ No newline at end of file