require 'digest/md5' class Post < ActiveRecord::Base belongs_to :discussion # belongs_to :parent, :class_name => "Post", :foreign_key => "parent" def to_html "
" + linkify(CGI.escapeHTML(content)).gsub(/\r?(\n\r?){2,}/, "
\n") + "
" end def linkify(str) urlprotocols = "http|https|ftp|news|nntp|irc|gopher" str.gsub(/((?:(?:#{urlprotocols}):[^\]\s\"<>]+))/) { "#{$&}" }.gsub(/[\w\d.+=-]+@[\w\d.-]+\.[\w\d]+/) { "#{$&}" } end def tripcode=(password) if author? && !password.empty? self[:tripcode] = Digest::MD5.new(author + SALT + password). to_s.to_i(16).to_s(36)[-6..-1] else self[:tripcode] = nil end end def self.last_post_id Integer(Post.find_by_sql("select max(id) as last_post from posts")[0]["last_post"]) end end