-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
comment.rb
75 lines (59 loc) · 1.76 KB
/
comment.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require_dependency 'spam_protection'
require 'sanitize'
class Comment < Content
include TypoGuid
content_fields :body
belongs_to :article, :counter_cache => true
belongs_to :user
validates_presence_of :author, :body
validates_against_spamdb :body, :url, :ip
validates_age_of :article_id
validate_on_create :check_article_is_open_to_comments
def self.default_order
'created_at ASC'
end
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
def location(anchor=:ignored, only_path=true)
blog.url_for(article, "comment-#{id}", only_path)
end
protected
def check_article_is_open_to_comments
return unless article
unless article.allow_comments?
errors.add(:article, "Article is not open to comments")
end
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
before_create :create_guid
before_save :correct_url, :make_nofollow
def correct_url
unless url.to_s.empty?
unless url =~ /^http\:\/\//
self.url = "http://#{url}"
end
end
end
def make_nofollow
self.author = author.nofollowify
self.body_html = body_html.to_s.nofollowify
end
end