Sha256: bae19471b719fbd4b86c78d5890a708209517c546d662fb0da7f9f7dbd09241d

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

require_dependency 'spam_protection'
require 'sanitize'
require 'timeout'

class Comment < Feedback
  belongs_to :article

  content_fields :body

  belongs_to :user

  validates_presence_of :author, :body

  attr_accessor :user_agent
  attr_accessor :referrer
  attr_accessor :permalink

  def notify_user_via_email(controller, user)
    if user.notify_via_email?
      EmailNotify.send_comment(controller, self, user)
    end
  end

  def notify_user_via_jabber(controller, user)
    if user.notify_via_jabber?
      JabberNotify.send_message(user, "New comment", "A new comment was posted to '#{article.title}' on #{blog.blog_name} by #{author}: #{body}", self.body_html)
    end
  end

  def interested_users
    users = User.find_boolean(:all, :notify_on_comments)
    self.notify_users = users
    users
  end

  protected

  def article_allows_feedback?
    return true if article.allow_comments?
    errors.add(:article, "Article is not open to comments")
    false
  end

  def body_html_postprocess(value, controller)
    sanitize(controller.send(:auto_link, value),'a href, b, br, i, p, em, strong, pre, code, ol, ul, li')
  end

  def default_text_filter_config_key
    'comment_text_filter'
  end

  def make_nofollow
    self.author    = author.nofollowify
    self.body_html = body_html.to_s.nofollowify
  end

  def originator
    author
  end

  def additional_akismet_options
    { :user_agent => user_agent,
      :referrer   => referrer,
      :permalink  => permalink }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
typo-4.0.1 app/models/comment.rb
typo-4.0.2 app/models/comment.rb