##### フォーム投稿内容を処理するクラス ##### require 'kconv' class Article attr_reader :params def initialize( cgi_params ) @params = Hash.new() @params.default = "" cgi_params.each_key{|key| if cgi_params[key].first == nil @params[key] = "" else @params[key] = cgi_params[key].first end } end ### フォーム内容の取り出し ### def []( *args ) @params[*args] end ### 文字コード関係 ### def toeuc @params.each_key{|key| @params[key].toeuc } end def tojis @params.each_key{|key| @params[key].tojis } end def tosjis @params.each_key{|key| @params[key].tosjis } end def toeuc! @params.each_key{|key| @params[key] = @params[key].toeuc } end def tojis! @params.each_key{|key| @params[key] = @params[key].tojis } end def tosjis! @params.each_key{|key| @params[key] = @params[key].tosjis } end def escapeHTML! @params.each_key{|key| @params[key] = @params[key]. gsub(/&/, "&"). gsub(//, ">"). gsub(/\"/, """) } end def set_link( link = "", target = "" ) if target != "" @params[link]. gsub("<", "\000"). gsub(">", "\001"). gsub(""", "\002"). gsub(%r|http[s]{0,1}://[\(\)%#!/0-9a-zA-Z_$@.&+-,'"*=;?:~-]+|, '' + target + ''). gsub( %r|[0-9a-zA-Z_.-]+@[\(\)%!0-9a-zA-Z_$@.&+-,'"*-]+|, '' + target + '' ). gsub("\002", """). gsub("\001", ">"). gsub("\000", "<") else @params[link]. gsub("<", "\000"). gsub(">", "\001"). gsub(""", "\002"). gsub(%r|http[s]{0,1}://[\(\)%#!/0-9a-zA-Z_$@.&+-,'"*=;?:~-]+|, '\&'). gsub( %r|[0-9a-zA-Z_.-]+@[\(\)%!0-9a-zA-Z_$@.&+-,'"*-]+|, '\&' ). gsub("\002", """). gsub("\001", ">"). gsub("\000", "<") end end end class String def set_br self.gsub(/\n/, "
\n") end end