ASPによる掲示板作成
ASPを使って簡単な掲示板を作成してみたのでメモしておきます。
記事の作成、削除機能はありません。記事はTXT,PDF,html形式で作成しておき、記事一覧から記事を参照できるだけのものです。
◆環境
・LANDISK(Windows Server)でWebDAVとASPを有効にする
VBSによるASPが実行できる環境ならば実行可能です
◆掲示板の仕様
・記事をTXT,PDF,html形式で作成し、list.aspと同一フォルダに保存する
・記事を作成する際は、ファイル名の先頭に日付をセットする (yyyymmdd形式)
・記事一覧を表示する際に、ファイルの拡張子は非表示する
・本年、昨年、一昨年、全てのリンクから対象記事を抽出できる
・検索機能で全記事対象にファイル名を検索出来る
・検索する際に英数字は半角・全角を意識することなくヒットさせる
全角を半角に変換する処理は下記のサイトの物を利用させていただきました。
「VBScriptで半角全角変換を担当するクラスを作ってみた」より転載
http://blog.livedoor.jp/midorityo/archives/51064633.html
◆掲示板のイメージ
◆ファイルの格納イメージ
◆起動方法
http://(サイト名フォルダ名)/list.asp
◆掲示板ASPソース
list.asp
<%@LANGUAGE=VBScript%> <html> <head> <title>お知らせ掲示板</title> <meta http-equiv="content-type" content="text/html;charset=shift_jis"> <style> body { margin:20px;} a {text-decoration: none } h2 a:link {color: deeppink } h2 a:visited {color: deeppink } h2 a:hover {color: #00008b; background-color:#ffffff } h2 a:active {color: deeppink } h2 a.nasi:hover {background-color:transparent } a:link {color: #ff0000 } a:visited {color: #00008b } a:hover {color: #4169e1;background-color:#7fffd4 } a:active {color: #4169e1 } a.nasi:hover {background-color:transparent } div.boxA { /* 親ボックス */ width:1000px; height: 30px; position: absolute; } div.box1 { /* ボックス1 */ width: 500px; height: 20px; position: absolute; top: -2px; left: 5px; } div.box2 { /* ボックス2 */ width: 500px; height: 20px; position: absolute; top: -5px; left: 300px; } div.box3 { /* ボックス3 */ width: 1000px; } </style> </head> <body> <h2 style="color: deeppink;"><a href=list.asp>■お知らせ掲示板</a></h2> <div class="boxA"> <div class="box1"> <a href=list.asp>本年</a> <a href="list.asp?ID=1">昨年</a> <a href="list.asp?ID=2">一昨年</a> <a href="list.asp?ID=3">全て</a> </div> <div class="box2"> <FORM ACTION="list.asp" METHOD="POST"> <input type="text" name="keyword" value="<% Response.Write Request.Form("keyword") %>" size="30"> <input type="submit" value="検索"> </form> </div> </div> <br> <hr size="1" color="lightsteelblue" noshade"></br> <div class="box3"> <% myInclude "CharWideNarrow.vbs" Set objFS = Server.CreateObject("Scripting.FileSystemObject") strFDIRNAME = Server.MapPath(".") Set objDIR = objFS.GetFolder(strFDIRNAME) dim array_file(10000), i, j i=0 For Each objFILE In objDIR.Files strFNAME = objFILE.Name array_file(i) = strFNAME i = i + 1 Next dim yy Select Case Request.QueryString("ID") Case "" yy = left(date(),4) Case "1" yy = left(date(),4) - 1 Case "2" yy = left(date(),4) - 2 Case "3" yy = "" End Select if Request.Form("keyword")<>"" then yy = "" End if dim c set c = New CharWideNarrow dim cnt cnt = 0 For j=i to 0 step-1 strFNAME = array_file(j) if yy = "" then If Right(strFNAME, 4) = ".htm" or Right(strFNAME, 4) = ".txt" or Right(strFNAME, 4) = ".pdf"Then if Request.Form("keyword")="" then Response.Write "<a href='" & strFNAME & "' target=blank><b>" Response.Write Replace(Replace(Replace(strFNAME,".htm",""),".txt",""),".pdf","") & "</b></a></br></br>" & vbCRLF cnt=cnt+1 else '検索の際に、小文字及び半角に変換してから判定。 半角に変換する処理は標準では無い為、下記のURLから転載した ' http://blog.livedoor.jp/midorityo/archives/51064633.html if InStr(c.ToNarrowAll(LCase(strFNAME)),c.ToNarrowAll(LCase(Request.Form("keyword"))))<>0 then Response.Write "<a href='" & strFNAME & "' target=blank><b>" Response.Write Replace(Replace(Replace(strFNAME,".htm",""),".txt",""),".pdf","") & "</b></a></br></br>" & vbCRLF cnt=cnt+1 End if End if End If else if left(strFNAME, 4) = yy & "" then If Right(strFNAME, 4) = ".htm" or Right(strFNAME, 4) = ".txt" or Right(strFNAME, 4) = ".pdf"Then Response.Write "<a href='" & strFNAME & "' target=blank><b>" Response.Write Replace(Replace(Replace(strFNAME,".htm",""),".txt",""),".pdf","") & "</b></a></br></br>" & vbCRLF cnt=cnt+1 End If End if End if Next Response.Write "表示 : " & cnt & " 件" %> </div> </body> </html> <% Sub myInclude(ByVal strFile) Dim objFSO , objStream , strDir Set objFSO = Server.CreateObject("Scripting.FileSystemObject") strDir = Server.MapPath(".") Set objStream = objFSO.OpenTextFile(strDir & "\" & strFile, 1) ExecuteGlobal objStream.ReadAll() objStream.Close Set objStream = Nothing Set objFSO = Nothing End Sub %>
CharWideNarrow.vbs
省略 (ファイルを見てね)
◆ファイル