2006/07/29
超簡易掲示板
なんだこれーって感じの作ってみたよ
#!/usr/bin/ruby #require 'erb' require 'cgi' #=========================================================== # WwwBoardLike Ver 0.01 # Copyright (C) 2006 riaf # http://d.hatena.ne.jp/riaf/ #=========================================================== cgi = CGI.new print "Content-type: text/html?n?n" #=========================================================== # ここから設定 #=========================================================== # 記事保存数 max_msgs = 100 # ホームページ return_url = "http://d.hatena.ne.jp/riaf/" # ログファイル(chmod 666) log_file = "wbl.log" #=========================================================== # ここまで #=========================================================== # 保存用置換 def cln_str(str ,nl=0) str = str.strip str = CGI.escapeHTML(str) str = str.gsub(/?r?n/, "?n") str = str.gsub(/?r/, "?n") if nl == 1 then str = str.gsub(/?n/, '<br>') end str = str.gsub(/?n/, "") return str end # ログデータ読み込み log = [] i = 0 fp = open(log_file) fp.each {|l| log[i] = l i += 1 } fp.close # モード取得 mode = cgi.params['mode'][0] if mode == "submit" then name = cgi.params['name'][0] email = cgi.params['email'][0] body = cgi.params['body'][0] err = 0 if name.strip.empty? || email.strip.empty? || body.strip.empty? then err = 1 end if err == 0 then name = cln_str(name) email = cln_str(email) body = cln_str(body, 1) data = name + "<>" + email + "<>" + body log.unshift("#{data}?n") i = 0 fp = open(log_file, "w") log.each{|l| fp.print l i += 1 if i > max_msgs then break end } fp.close end end print '<html><head><title>BBS</title></head><body>' print '<h1>BBS</h1>' print "[<a href='#{return_url}'>HOME</a>]?n" print '<form action="" method="post">' print '<input type="hidden" name="mode" value="submit">' print 'name: <input type="text" name="name" size="40"><br>' print 'email: <input type="text" name="email" size="40"><br>' print '<textarea name="body"></textarea>' print '<input type="submit">' print '</form><hr>' log.each {|l| item = l.split(/<>/) print "<dl><dt><a href='mailto:#{item[1]}'>#{item[0]}</a></dt>?n" print "<dd>#{item[2]}</dd></dl>?n" } print '</body></html>'
5月からブログ始めたくせに、今日初めてrubyのコード書いた!
きもいきもい><
- 24 http://d.hatena.ne.jp/keyword/Ruby?kid=2847
- 8 http://anond.hatelabo.jp/20080326031824
- 6 http://d.hatena.ne.jp/keyworddiary/Ruby
- 4 http://www.google.co.jp/search?q=php+簡易掲示板&lr=lang_ja&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:ja:official&client=firefox-a
- 3 http://d.hatena.ne.jp/keyword/Ruby
- 3 http://www.google.co.jp/search?hl=ja&lr=&q=簡易掲示板&start=20&sa=N
- 2 http://d.hatena.ne.jp/keyword/Ubuntu
- 2 http://d.hatena.ne.jp/keywordmobile/Ruby?kid=2847
- 2 http://d.hatena.ne.jp/rubytips/20071030/1223544799
- 2 http://www.google.co.jp/search?hl=ja&lr=&q=掲示板 e-mail&start=90&sa=N