francois / mephisto forked from halorgium/mephisto
- Source
- Commits
- Network (36)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
multiengine
commit cf11753a6d59fbbfcbd0e063706395ff31600059
tree 99cad4a4e7cbdd79c3c9781008d0ee9d0cbc4451
parent f1068ff008b7da9263fd9037d1a37b3813e70991
tree 99cad4a4e7cbdd79c3c9781008d0ee9d0cbc4451
parent f1068ff008b7da9263fd9037d1a37b3813e70991
| db4fc393 » | technoweenie | 2006-09-08 | 1 | require 'uri' | |
| 2 | |||||
| 79b5ee31 » | technoweenie | 2006-02-12 | 3 | class Comment < Content | |
| db4fc393 » | technoweenie | 2006-09-08 | 4 | validates_presence_of :author, :author_ip, :article_id, :body | |
| 7dec6b4b » | technoweenie | 2006-09-17 | 5 | validates_format_of :author_email, :with => Format::EMAIL | |
| db4fc393 » | technoweenie | 2006-09-08 | 6 | before_validation :clean_up_author_email | |
| 7 | before_validation :clean_up_author_url | ||||
| 3853a03e » | technoweenie | 2006-09-24 | 8 | after_validation_on_create :snag_article_attributes | |
| 23e9525b » | technoweenie | 2006-06-30 | 9 | before_create :check_comment_expiration | |
| 6f644bee » | technoweenie | 2007-03-30 | 10 | before_create :sanitize_attributes | |
| b5017e05 » | technoweenie | 2006-07-03 | 11 | before_save :update_counter_cache | |
| 77112638 » | technoweenie | 2006-06-06 | 12 | before_destroy :decrement_counter_cache | |
| 13 | belongs_to :article | ||||
| c8e60da8 » | technoweenie | 2006-08-28 | 14 | has_one :event, :dependent => :destroy | |
| b0fadcd7 » | technoweenie | 2008-02-04 | 15 | before_create :check_if_previewing | |
| 182ae2f5 » | technoweenie | 2006-01-01 | 16 | ||
| b0fadcd7 » | technoweenie | 2008-02-04 | 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 | 27 | def self.find_all_by_section(section, options = {}) | |
| a2678925 » | technoweenie | 2006-09-24 | 28 | find :all, options.update(:conditions => ['contents.approved = ? and assigned_sections.section_id = ?', true, section.id], | |
| def5a4d0 » | technoweenie | 2006-09-24 | 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 | 33 | def to_liquid | |
| f868a1b6 » | technoweenie | 2006-09-17 | 34 | CommentDrop.new self | |
| c58ffca3 » | technoweenie | 2006-01-08 | 35 | end | |
| 77112638 » | technoweenie | 2006-06-06 | 36 | ||
| 37 | def approved=(value) | ||||
| 38 | @old_approved ||= approved? ? :true : :false | ||||
| 39 | write_attribute :approved, value | ||||
| 40 | end | ||||
| dc765311 » | technoweenie | 2006-06-13 | 41 | ||
| db4fc393 » | technoweenie | 2006-09-08 | 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 | 51 | value = 'http://' + value unless value.blank? || value[0..0] == '/' || URI::parse(value).scheme | |
| db4fc393 » | technoweenie | 2006-09-08 | 52 | write_attribute :author_url, value | |
| 53 | end | ||||
| c5de0628 » | technoweenie | 2006-10-02 | 54 | rescue URI::InvalidURIError | |
| 55 | write_attribute :author_url, nil | ||||
| db4fc393 » | technoweenie | 2006-09-08 | 56 | end | |
| 57 | |||||
| c7ab20fe » | technoweenie | 2006-09-24 | 58 | def article_referenced_cache_key | |
| 59 | "[#{article_id}:Article]" | ||||
| 60 | end | ||||
| 61 | |||||
| 429ecf29 » | francois | 2008-03-07 | 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 | 65 | end | |
| 66 | |||||
| 67 | def mark_as_spam(site, request) | ||||
| 73408ff3 » | francois | 2008-03-03 | 68 | spam_engine(site).mark_as_spam(article.permalink_url(site, request), self) | |
| c5de0628 » | technoweenie | 2006-10-02 | 69 | end | |
| 70 | |||||
| 71 | def mark_as_ham(site, request) | ||||
| 73408ff3 » | francois | 2008-03-03 | 72 | spam_engine(site).mark_as_ham(article.permalink_url(site, request), self) | |
| c5de0628 » | technoweenie | 2006-10-02 | 73 | end | |
| 74 | |||||
| 87a0ff1d » | francois | 2008-03-04 | 75 | def spam_engine_info | |
| 76 | spam_engine(site).info(self) | ||||
| 77 | end | ||||
| 78 | |||||
| bf56e897 » | francois | 2008-03-03 | 79 | def spam_engine_classes | |
| 80 | spam_engine(self.site).classes(self) | ||||
| 81 | end | ||||
| 82 | |||||
| 77112638 » | technoweenie | 2006-06-06 | 83 | protected | |
| f822664c » | francois | 2008-02-29 | 84 | def spam_engine(site) | |
| 85 | site.spam_engine | ||||
| 86 | end | ||||
| 87 | |||||
| 6f644bee » | technoweenie | 2007-03-30 | 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 | 94 | def snag_article_attributes | |
| 2f47be0a » | technoweenie | 2006-12-25 | 95 | self.filter ||= article.site.filter | |
| 6f644bee » | technoweenie | 2007-03-30 | 96 | [:site, :title, :published_at, :permalink].each { |a| self.send("#{a}=", article.send(a)) } | |
| 4a65486b » | technoweenie | 2006-08-18 | 97 | end | |
| 98 | |||||
| 23e9525b » | technoweenie | 2006-06-30 | 99 | def check_comment_expiration | |
| b0fadcd7 » | technoweenie | 2008-02-04 | 100 | raise Article::CommentNotAllowed, "#{article.status} does not allow comments" unless article.accept_comments? | |
| 23e9525b » | technoweenie | 2006-06-30 | 101 | end | |
| 102 | |||||
| b5017e05 » | technoweenie | 2006-07-03 | 103 | def update_counter_cache | |
| 7dec6b4b » | technoweenie | 2006-09-17 | 104 | Article.increment_counter 'comments_count', article_id if approved? && @old_approved == :false | |
| b5017e05 » | technoweenie | 2006-07-03 | 105 | Article.decrement_counter 'comments_count', article_id if !approved? && @old_approved == :true | |
| 77112638 » | technoweenie | 2006-06-06 | 106 | end | |
| 107 | |||||
| 108 | def decrement_counter_cache | ||||
| 48da051d » | technoweenie | 2006-06-06 | 109 | Article.decrement_counter 'comments_count', article_id if approved? | |
| 77112638 » | technoweenie | 2006-06-06 | 110 | end | |
| b5017e05 » | technoweenie | 2006-07-03 | 111 | end | |
