francois / mephisto forked from halorgium/mephisto

A refactored Mephisto that has multiple spam detection engines.

This URL has Read+Write access

francois (author)
Mon Mar 17 19:02:47 -0700 2008
commit  cf11753a6d59fbbfcbd0e063706395ff31600059
tree    99cad4a4e7cbdd79c3c9781008d0ee9d0cbc4451
parent  f1068ff008b7da9263fd9037d1a37b3813e70991
mephisto / app / models / comment.rb
db4fc393 » technoweenie 2006-09-08 better comment validation a... 1 require 'uri'
2
79b5ee31 » technoweenie 2006-02-12 renamed articles table to c... 3 class Comment < Content
db4fc393 » technoweenie 2006-09-08 better comment validation a... 4 validates_presence_of :author, :author_ip, :article_id, :body
7dec6b4b » technoweenie 2006-09-17 add password resetting [Geo... 5 validates_format_of :author_email, :with => Format::EMAIL
db4fc393 » technoweenie 2006-09-08 better comment validation a... 6 before_validation :clean_up_author_email
7 before_validation :clean_up_author_url
3853a03e » technoweenie 2006-09-24 cache title/permalink/publi... 8 after_validation_on_create :snag_article_attributes
23e9525b » technoweenie 2006-06-30 comment blocking stuff, (bi... 9 before_create :check_comment_expiration
6f644bee » technoweenie 2007-03-30 sanitize comment attributes... 10 before_create :sanitize_attributes
b5017e05 » technoweenie 2006-07-03 decrement article comments ... 11 before_save :update_counter_cache
77112638 » technoweenie 2006-06-06 only create comment events ... 12 before_destroy :decrement_counter_cache
13 belongs_to :article
c8e60da8 » technoweenie 2006-08-28 delete the associated event... 14 has_one :event, :dependent => :destroy
b0fadcd7 » technoweenie 2008-02-04 host of fixes and added sup... 15 before_create :check_if_previewing
182ae2f5 » technoweenie 2006-01-01 add users 16
b0fadcd7 » technoweenie 2008-02-04 host of fixes and added sup... 17 attr_accessible :article, :article_id, :user_id, :user, :excerpt, :body, :author, :author_url, :author_email, :author_ip, :updater_id, :updater, :comment_age, :user_agent, :referrer, :preview
18 attr_accessor :preview
19 class Previewing < StandardError; end
20
21 # If the view sends the "preview" accessor, we raise this
22 # error so the controller can simply rescue
23 def check_if_previewing
24 raise Comment::Previewing if preview
25 end
26
def5a4d0 » technoweenie 2006-09-24 Add liquid drop/filters for... 27 def self.find_all_by_section(section, options = {})
a2678925 » technoweenie 2006-09-24 add extra comment feeds 28 find :all, options.update(:conditions => ['contents.approved = ? and assigned_sections.section_id = ?', true, section.id],
def5a4d0 » technoweenie 2006-09-24 Add liquid drop/filters for... 29 :select => 'contents.*', :joins => 'INNER JOIN assigned_sections ON assigned_sections.article_id = contents.article_id',
30 :order => 'contents.created_at DESC')
31 end
32
182ae2f5 » technoweenie 2006-01-01 add users 33 def to_liquid
f868a1b6 » technoweenie 2006-09-17 restructure liquid drops/fi... 34 CommentDrop.new self
c58ffca3 » technoweenie 2006-01-08 add vars for articles and c... 35 end
77112638 » technoweenie 2006-06-06 only create comment events ... 36
37 def approved=(value)
38 @old_approved ||= approved? ? :true : :false
39 write_attribute :approved, value
40 end
dc765311 » technoweenie 2006-06-13 expire caches after comment... 41
db4fc393 » technoweenie 2006-09-08 better comment validation a... 42 def clean_up_author_email
43 if value = read_attribute(:author_email) then
44 write_attribute :author_email, value.strip
45 end
46 end
47
48 def clean_up_author_url
49 if value = read_attribute(:author_url) then
50 value.strip!
7dec6b4b » technoweenie 2006-09-17 add password resetting [Geo... 51 value = 'http://' + value unless value.blank? || value[0..0] == '/' || URI::parse(value).scheme
db4fc393 » technoweenie 2006-09-08 better comment validation a... 52 write_attribute :author_url, value
53 end
c5de0628 » technoweenie 2006-10-02 store referrer and user_age... 54 rescue URI::InvalidURIError
55 write_attribute :author_url, nil
db4fc393 » technoweenie 2006-09-08 better comment validation a... 56 end
57
c7ab20fe » technoweenie 2006-09-24 test that posting a comment... 58 def article_referenced_cache_key
59 "[#{article_id}:Article]"
60 end
61
429ecf29 » francois 2008-03-07 Get ready to tell Defensio ... 62 def check_approval(site, request, options={})
63 options.reverse_merge!(:authenticated => false)
64 self.approved = site.approve_comments? || spam_engine(site).ham?(article.permalink_url(site, request), self, :authenticated => options[:authenticated])
c5de0628 » technoweenie 2006-10-02 store referrer and user_age... 65 end
66
67 def mark_as_spam(site, request)
73408ff3 » francois 2008-03-03 Normalized the parameters t... 68 spam_engine(site).mark_as_spam(article.permalink_url(site, request), self)
c5de0628 » technoweenie 2006-10-02 store referrer and user_age... 69 end
70
71 def mark_as_ham(site, request)
73408ff3 » francois 2008-03-03 Normalized the parameters t... 72 spam_engine(site).mark_as_ham(article.permalink_url(site, request), self)
c5de0628 » technoweenie 2006-10-02 store referrer and user_age... 73 end
74
87a0ff1d » francois 2008-03-04 In the overview and admin/c... 75 def spam_engine_info
76 spam_engine(site).info(self)
77 end
78
bf56e897 » francois 2008-03-03 The Admin::Comments page st... 79 def spam_engine_classes
80 spam_engine(self.site).classes(self)
81 end
82
77112638 » technoweenie 2006-06-06 only create comment events ... 83 protected
f822664c » francois 2008-02-29 Ripped out the Akismet-spec... 84 def spam_engine(site)
85 site.spam_engine
86 end
87
6f644bee » technoweenie 2007-03-30 sanitize comment attributes... 88 def sanitize_attributes
89 [:author, :author_url, :author_email, :author_ip, :user_agent, :referrer].each do |a|
90 self.send("#{a}=", CGI::escapeHTML(self.send(a).to_s))
91 end
92 end
93
3853a03e » technoweenie 2006-09-24 cache title/permalink/publi... 94 def snag_article_attributes
2f47be0a » technoweenie 2006-12-25 allow comments to set a fil... 95 self.filter ||= article.site.filter
6f644bee » technoweenie 2007-03-30 sanitize comment attributes... 96 [:site, :title, :published_at, :permalink].each { |a| self.send("#{a}=", article.send(a)) }
4a65486b » technoweenie 2006-08-18 Store filters as a single s... 97 end
98
23e9525b » technoweenie 2006-06-30 comment blocking stuff, (bi... 99 def check_comment_expiration
b0fadcd7 » technoweenie 2008-02-04 host of fixes and added sup... 100 raise Article::CommentNotAllowed, "#{article.status} does not allow comments" unless article.accept_comments?
23e9525b » technoweenie 2006-06-30 comment blocking stuff, (bi... 101 end
102
b5017e05 » technoweenie 2006-07-03 decrement article comments ... 103 def update_counter_cache
7dec6b4b » technoweenie 2006-09-17 add password resetting [Geo... 104 Article.increment_counter 'comments_count', article_id if approved? && @old_approved == :false
b5017e05 » technoweenie 2006-07-03 decrement article comments ... 105 Article.decrement_counter 'comments_count', article_id if !approved? && @old_approved == :true
77112638 » technoweenie 2006-06-06 only create comment events ... 106 end
107
108 def decrement_counter_cache
48da051d » technoweenie 2006-06-06 filter comments in admin 109 Article.decrement_counter 'comments_count', article_id if approved?
77112638 » technoweenie 2006-06-06 only create comment events ... 110 end
b5017e05 » technoweenie 2006-07-03 decrement article comments ... 111 end