Compare Backup: topic_v20251109_1951_categories-fixed.asp

Against: Live Page: topic.asp

Unchanged Added in comparison file Removed from comparison file
<!--#include file="includes/backupHelper.asp" -->
<!--#include file="includes/ASPlib.asp" -->
<%
Response.Charset = "UTF-8"
' ==========================================================
' Variables
' ==========================================================
Dim fso, folderPath, folder, files, file
Dim topicStream, topicTitle, topicBody, topicDate, topicCategories
Dim topics(), topicCount, i, j, temp
Dim searchTerm, categoryFilter, sortBy
Dim categories, catFilePath, catStream, catContent, catLines, catLine
' ==========================================================
' Initialize
' ==========================================================
Set fso = Server.CreateObject("Scripting.FileSystemObject")
folderPath = Server.MapPath("topics")
Set folder = fso.GetFolder(folderPath)
topicCount = 0
searchTerm = LCase(Trim(Request("search")))
categoryFilter = LCase(Trim(Request("category")))
If categoryFilter = "" Then categoryFilter = "all"
sortBy = LCase(Trim(Request("sort")))
If sortBy = "" Then sortBy = "alpha"
If searchTerm <> "" Then searchTerm = Replace(searchTerm, "'", "''")
' ==========================================================
' Load Categories
' ==========================================================
Set categories = CreateObject("Scripting.Dictionary")
catFilePath = folderPath & "\categories.txt"
If fso.FileExists(catFilePath) Then
Set catStream = fso.OpenTextFile(catFilePath, 1, False)
catContent = catStream.ReadAll
catStream.Close
catLines = Split(catContent, vbCrLf)
For Each catLine In catLines
catLine = Trim(catLine)
If catLine <> "" Then categories.Add catLine, True
Next
End If
' ==========================================================
' Function: Linkify Bible References
' ==========================================================
Function LinkifyBibleRefs(ByVal text)
Dim regEx, pattern
pattern = "([1-3]?\s?[A-Za-z]+)\s+(\d+):(\d+(-\d+)?)"
Set regEx = New RegExp
regEx.Global = True
regEx.IgnoreCase = True
regEx.Pattern = pattern
LinkifyBibleRefs = regEx.Replace(text, "<a href='https://www.biblestudyworld.com/default.asp?st=$1%20$2:$3'>$1&nbsp;$2:$3</a>")
Set regEx = Nothing
End Function
' ==========================================================
' Function: Escape special characters for RegExp
' ==========================================================
Function EscapeRegex(str)
Dim charsToEscape, ch
charsToEscape = Array("\","^","$",".","|","?","*","+","(",")","[","]","{","}")
For Each ch In charsToEscape
str = Replace(str, ch, "\" & ch)
Next
EscapeRegex = str
End Function
' ==========================================================
' Load Topics
' ==========================================================
For Each file In folder.Files
If LCase(fso.GetExtensionName(file.Name)) = "txt" And LCase(file.Name) <> "categories.txt" Then
Set topicStream = fso.OpenTextFile(file.Path, 1, False)
topicTitle = ""
topicBody = ""
topicCategories = ""
topicDate = file.DateCreated
Do Until topicStream.AtEndOfStream
Dim line
line = topicStream.ReadLine
If LCase(Left(line, 6)) = "title:" Then
topicTitle = Trim(Mid(line, 7))
ElseIf LCase(Left(line, 11)) = "categories:" Then
topicCategories = Trim(Mid(line, 12))
Else
topicBody = topicBody & line & vbCrLf
End If
Loop
topicStream.Close
' ----------------------
' Apply Category Filter
' ----------------------
Dim includeTopic
includeTopic = True
If categoryFilter <> "all" Then
includeTopic = False
Dim topicCatArray, tCat
topicCatArray = Split(topicCategories, ",")
For Each tCat In topicCatArray
tCat = LCase(Trim(tCat)) ' Trim and lowercase
If tCat = categoryFilter Then
includeTopic = True
Exit For
End If
Next
End If
' ----------------------
' Apply Search Filter
' ----------------------
If includeTopic And searchTerm <> "" Then
If InStr(1, LCase(topicTitle & topicBody), searchTerm) = 0 Then includeTopic = False
End If
' ----------------------
' Add to Topics Array
' ----------------------
If includeTopic Then
ReDim Preserve topics(topicCount)
topics(topicCount) = Array(topicTitle, topicBody, file.Name, topicDate, topicCategories)
topicCount = topicCount + 1
End If
End If
Next
' ==========================================================
' Sort Topics
' ==========================================================
If topicCount > 1 Then
For i = 0 To topicCount - 2
For j = i + 1 To topicCount - 1
If sortBy = "alpha" Then
If UCase(topics(i)(0)) > UCase(topics(j)(0)) Then
temp = topics(i): topics(i) = topics(j): topics(j) = temp
End If
ElseIf sortBy = "date" Then
If topics(i)(3) < topics(j)(3) Then
temp = topics(i): topics(i) = topics(j): topics(j) = temp
End If
End If
Next
Next
End If
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Study Topics</title>
<style>
body { font-family:Arial,sans-serif; margin:0; padding:0; background:#f7f7f7; }
.header { display:flex; align-items:center; background:#2a4d9c; color:white; padding:10px; }
.header img { height:60px; width:auto; margin-right:10px; }
.header h1 { margin:0; font-size:24px; }
.buttons { display:flex; flex-wrap:wrap; padding:10px; gap:8px; }
button, select { padding:6px 12px; border-radius:5px; border:none; cursor:pointer; }
button { background:#004080; color:white; }
button:hover { background:#0059b3; }
select { background:#eee; }
.search-bar { padding:10px; text-align:center; }
.search-bar input[type="text"] { width:80%; padding:8px; border-radius:4px; border:1px solid #ccc; font-size:16px; }
.topic { background:white; margin:10px; padding:10px; border-radius:6px; box-shadow:0 1px 3px rgba(0,0,0,0.2); cursor:pointer; }
.topic h3 { margin:0; }
.highlight { background:#cce5ff; font-weight:bold; }
.admin-link { text-align:center; margin:20px; font-size:14px; color:#999; }
.admin-link a { color:#999; text-decoration:none; }
.admin-link a:hover { text-decoration:underline; }
</style>
<script>
function toggleBody(id){
var el = document.getElementById(id);
if(el.style.display==='block'){el.style.display='none';}
else{el.style.display='block';}
}
</script>
</head>
<body>
<div class="header">
<a href="default.asp"><img src="images/logo.jpg" alt="Logo"></a>
<h1>Study Topics</h1>
</div>
<div class="buttons">
<form method="get" style="display:inline;">
<button type="submit" name="sort" value="alpha">A–Z</button>
<button type="submit" name="sort" value="date">Newest</button>
<select name="category" onchange="this.form.submit()">
<%
' All option
If categoryFilter = "all" Then
Response.Write "<option value='All' selected>All</option>"
Else
Response.Write "<option value='All'>All</option>"
End If
' Other categories
Dim catKey, catValue
For Each catKey In categories.Keys
catValue = Trim(catKey)
If catValue <> "" Then
Response.Write "<option value='" & catValue & "'"
If LCase(catValue) = categoryFilter Then Response.Write " selected"
Response.Write ">" & catValue & "</option>"
End If
Next
%>
</select>
<input type="hidden" name="search" value="<%=Server.HTMLEncode(searchTerm)%>">
<input type="hidden" name="sort" value="<%=Server.HTMLEncode(sortBy)%>">
</form>
</div>
<div class="search-bar">
<form method="get">
<input type="text" name="search" placeholder="Search topics..." value="<%=Server.HTMLEncode(Request("search"))%>">
<input type="hidden" name="sort" value="<%=Server.HTMLEncode(sortBy)%>">
<input type="hidden" name="category" value="<%=Server.HTMLEncode(categoryFilter)%>">
<button type="submit">Search</button>
</form>
</div>
<%
If topicCount = 0 Then
Response.Write "<p style='text-align:center;'>No topics found.</p>"
Else
For i = 0 To topicCount - 1
Dim tTitle, tBody, bodyId
tTitle = topics(i)(0)
tBody = topics(i)(1)
bodyId = "body_" & i
' Highlight search terms safely
If searchTerm <> "" Then
Dim regex
Set regex = New RegExp
regex.IgnoreCase = True
regex.Global = True
regex.Pattern = "(" & EscapeRegex(searchTerm) & ")"
tTitle = regex.Replace(tTitle, "<span class='highlight'>$1</span>")
tBody = regex.Replace(tBody, "<span class='highlight'>$1</span>")
Set regex = Nothing
End If
' Linkify Bible references
tBody = LinkifyBibleRefs(tBody)
Response.Write "<div class='topic' onclick=""toggleBody('" & bodyId & "')"" style='cursor:pointer;'>"
Response.Write "<h3>" & tTitle & "</h3>"
Response.Write "<pre id='" & bodyId & "' style='display:none; white-space:pre-wrap;'>" & tBody & "</pre>"
Response.Write "</div>"
Next
End If
%>
<div class="admin-link">
<a href="admin.asp">Admin Login</a>
</div>
</body>
</html>