% 'dimension variables dim rsKeywords, sqlKeywords, intKeywordsCount, arrKeywordsData, rsSearch, sqlSearch, intSearchCount, arrSearchData, sqlCategories, intCategoriesCount, arrCategoriesData dim strKeywords, strAddress, strSearch, strSearchBox, strConstraints dim intSearch, intPageCount, intPageCurrent, intPages, intPageStart, intPageStop, intLevel, intKeywordsLoop, intSearchLoop, intPageLoop, intCategoriesLoop dim booSpam 'load and check variables if request.querystring("Search") <> "" and isnumeric(request.querystring("Search")) = true then intSearch = int(request.querystring("Search")) else intSearch = "" end if if request.querystring("Page") <> "" and isnumeric(request.querystring("Page")) = true then intPageCurrent = int(request.querystring("Page")) else intPageCurrent = 1 end if if session("FB_UserLevel") <> "" then intLevel = int(session("FB_UserLevel")) else intLevel = 0 end if if request.servervariables("HTTP_X_FORWARDED_FOR") = "" then strAddress = request.servervariables("REMOTE_ADDR") else strAddress = request.servervariables("HTTP_X_FORWARDED_FOR") end If 'check whether a valid search has been specified if intSearch <> "" then 'grab keywords for specified search set rsKeywords = server.createobject("adodb.recordset") sqlKeywords = "SELECT Search_Keywords FROM FB_Search WHERE Search_ID = "& intSearch &";" rsKeywords.open sqlKeywords, adoConn if not (rsKeywords.bof or rsKeywords.eof) then strKeywords = rsKeywords("Search_Keywords") end if rsKeywords.close set rsKeywords = nothing 'increment query count intQuery = intQuery + 1 else 'check if user has submitted a search request if request.form <> "" then 'check if user has performed a search within the search spam limit set rsSearch = server.createobject("adodb.recordset") sqlSearch = "SELECT * FROM FB_Search WHERE Search_Address = '"& strAddress &"' AND Search_Date > '"& search_time("s", -intBlogLinkLimit) &"';" rsSearch.cursorlocation = 3 rsSearch.open sqlSearch, adoConn if not (rsSearch.bof or rsSearch.eof) then booSpam = true else booSpam = false end if rsSearch.close set rsSearch = nothing 'redirect if user has already commented if booSpam = true then response.redirect(strBlogLocation &"error.asp?Type=Search&Error=Spam&Redirect=Search/default.asp") end if end if end if if strKeywords = "" then strSearchBox = request.form("keywords") else strSearchBox = strKeywords end if 'display search header response.write("

"& ids("Search") &"

 

") 'display search message response.write("

") response.write(ids("Search_")) response.write("

") response.write("

") response.write(ids("SearchRelevence")) response.write("

") 'build form container response.write("
") 'build search form response.write("
") response.write("

") response.write("") 'grab all categories sqlCategories = "SELECT Category_ID, Category_Title FROM FB_Categories ORDER BY Category_Order ASC;" arrCategoriesData = get_array("Categories",sqlCategories) if isArray(arrCategoriesData) then intCategoriesCount = ubound(arrCategoriesData,2) + 1 else intCategoriesCount = 0 end if 'check if there is more than on category if intCategoriesCount > 1 then 'display categories selection response.write(" ") end if 'display date selection response.write(" ") response.write(" ") response.write("

") response.write("
") response.write("
") response.write("
") 'check form has been submitted if request.form("keywords") <> "" or strKeywords <> "" then 'check if we have already retreived the search keywords if strKeywords = "" then 'assign keywords based on search form arrKeywordsData = split(trim(prepare_text(request.form("keywords"), true, false)), " ") intKeywordsCount = ubound(arrKeywordsData) + 1 else 'assign keywords based on retrieved keywords arrKeywordsData = split(trim(strKeywords), " ") intKeywordsCount = ubound(arrKeywordsData) + 1 end if 'create search string do until intKeywordsLoop = intKeywordsCount 'check length of the current keyword if len(arrKeywordsData(intKeywordsLoop)) >= 3 then 'build search query strSearch = strSearch &"(Article_Title LIKE '%"& arrKeywordsData(intKeywordsLoop) &"%' OR Article_Excerpt LIKE '%"& arrKeywordsData(intKeywordsLoop) &"%' OR Article_Content LIKE '%"& arrKeywordsData(intKeywordsLoop) &"%')" 'check whether we have included all keywords if intKeywordsLoop < intKeywordsCount - 1 then strSearch = strSearch &" OR " end if 'collect search terms for inserting to database strKeywords = strKeywords & arrKeywordsData(intKeywordsLoop) &" " end if 'increment counter intKeywordsLoop = intKeywordsLoop + 1 loop 'redirect if no valid search terms were specified if strSearch = "" then response.redirect(strBlogLocation &"error.asp?Type=Search&Error=Keywords&Redirect=Search/default.asp") end if 'check whether this is a new search if intSearch = "" then 'insert search keywords to the search database set rsKeywords = server.createobject("adodb.recordset") sqlKeywords = "INSERT INTO FB_Search (Search_Keywords, Search_Address, Search_Date) VALUES ('"& strKeywords &"', '"& strAddress &"', '"& db_time(intBlogTimeOffset) &"');" rsKeywords.cursortype = 2 rsKeywords.locktype = 3 rsKeywords.open sqlKeywords, adoConn set rsKeywords = nothing 'increment query count intQuery = intQuery + 1 'grab search id set rsKeywords = server.createobject("adodb.recordset") sqlKeywords = "SELECT @@IDENTITY AS iSearch FROM FB_Search;" rsKeywords.open sqlKeywords, adoConn intSearch = rsKeywords("iSearch") rsKeywords.close set rsKeywords = nothing 'increment query count intQuery = intQuery + 1 end if 'check for search constraints if request.form("category") <> 0 then strConstraints = "Articles.Article_Category_ID = "& int(request.form("category")) &" AND Articles.Article_Posted >= '"& request.form("date") &"'" else strConstraints = "Articles.Article_Posted >= '"& request.form("date") &"'" end if 'set query string based on database type select case strDatabase case "MSSQL", "ACCESS" sqlSearch = "SELECT Articles.Article_ID, Articles.Article_Title, Articles.Article_Excerpt, Articles.Article_Content, Articles.Article_Posted, Articles.Article_Comments, Articles.Article_Comments_Count, Articles.Article_Images, Categories.Category_ID, Categories.Category_Title, Users.User_ID, Users.User_Name, Articles.Article_Level FROM (FB_Categories Categories INNER JOIN FB_Articles Articles ON Categories.Category_ID = Articles.Article_Category_ID) INNER JOIN FB_Users Users ON Users.User_ID = Articles.Article_User_ID WHERE "& strSearch &" AND "& strConstraints &" AND Articles.Article_Level <= "& intLevel &" ORDER BY Article_Posted DESC" case "MySQL" sqlSearch = "SELECT Articles.Article_ID, Articles.Article_Title, Articles.Article_Excerpt, Articles.Article_Content, Articles.Article_Posted, Articles.Article_Comments, Articles.Article_Comments_Count, Articles.Article_Images, Categories.Category_ID, Categories.Category_Title, Users.User_ID, Users.User_Name, Articles.Article_Level FROM (FB_Categories Categories INNER JOIN FB_Articles Articles ON Categories.Category_ID = Articles.Article_Category_ID) INNER JOIN FB_Users Users ON Users.User_ID = Articles.Article_User_ID WHERE "& strSearch &" AND "& strConstraints &" AND Articles.Article_Level <= "& intLevel &" ORDER BY Article_Posted DESC" end select 'perform article search set rsSearch = server.createobject("adodb.recordset") rsSearch.cursorlocation = 3 rsSearch.pagesize = intBlogArticlePaging rsSearch.cachesize = intBlogArticlePaging rsSearch.open sqlSearch, adoConn if not (rsSearch.bof or rsSearch.eof) then intPageCount = rsSearch.pagecount if intPageCurrent > intPageCount then intPageCurrent = intPageCount end if if intPageCurrent < 1 then intPageCurrent = 1 end if rsSearch.absolutepage = intPageCurrent arrSearchData = rsSearch.getrows(intBlogArticlePaging) intSearchCount = ubound(arrSearchData, 2) + 1 else intSearchCount = 0 end if rsSearch.close set rsSearch= nothing 'increment query count intQuery = intQuery + 1 'check whether results have been returned if intSearchCount = 0 then 'draw article container response.write("
") response.write("

"& ids("SearchNoArticles") &"

 

") 'display empty archive message response.write("

") response.write(ids("SearchNoArticles_")) response.write("

") response.write("
") else 'initialise counter intSearchLoop = 0 'loop through current Search do until intSearchLoop = intSearchCount 'draw article container response.write("
") 'display article title response.write("

"& SQL_decode(arrSearchData(1, intSearchLoop)) &"

 

") 'check whether the article has an exceprt if arrSearchData(2, intSearchLoop) <> "" then 'display article exceprt response.write(SQL_decode(arrSearchData(2, intSearchLoop))) 'display full atricle link response.write("") else 'display full article response.write(SQL_decode(arrSearchData(3, intSearchLoop))) 'check for images and whether the gallery is enabled if (isnull(arrSearchData(7, intSearchLoop)) = false and arrSearchData(7, intSearchLoop) <> "") and intBlogGalleryEnabled = 1 then 'display thumbnail gallery call display_thumbs(SQL_decode(arrSearchData(7, intSearchLoop))) end if end if 'display article details response.write("

") response.write(""& ids("By") &" "& arrSearchData(11, intSearchLoop) &"") response.write(" "& ids("On") &" "& web_time(arrSearchData(4, intSearchLoop), strBlogTimeFormat, "Full") &" ") response.write(""& ids("In") &" "& SQL_decode(arrSearchData(9, intSearchLoop)) &" ") 'check comments are enabled if arrSearchData(5, intSearchLoop) = 1 and intBlogCommentEnabled = 1 then response.write(" "& ids("Comments") &" "& arrSearchData(6, intSearchLoop) &" ") end if response.write("


") response.write("
") 'increment counter intSearchLoop = intSearchLoop + 1 loop 'display paging controls if intPageCount > 1 then response.write("
") 'previous page controls if intPageCurrent > 1 then response.write("<< ") else response.write("<< ") end if 'determine page start and stop variables if intPageCurrent > 5 then intPageStart = (intPageCurrent - 3) else intPageStart = 1 end if if (intPageCount > 10) and ((intPageCurrent + 3) < intPageCount) then intPageStop = (intPageCurrent + 3) else intPageStop = intPageCount end if for intPageLoop = intPageStart to intPageStop if intPageLoop = intPageCurrent then response.write("["& intPageLoop &"] ") else response.write(""& intPageLoop &" ") end if next 'next page controls if intPageCurrent < intPageCount then response.write(" >>") else response.write(" >>") end if response.write("
") end if end if end if %>