app/models/content.rb in typo-4.0.0 vs app/models/content.rb in typo-4.0.1

- old
+ new

@@ -16,19 +16,19 @@ :association_foreign_key => 'notify_user_id', :uniq => true has_many :triggers, :as => :pending_item, :dependent => :delete_all before_save :state_before_save - after_save :post_trigger + after_save :post_trigger, :state_after_save serialize :whiteboard @@content_fields = Hash.new @@html_map = Hash.new - def initialize(*args) - super(*args) + def initialize(*args, &block) + super(*args, &block) set_default_blog end def set_default_blog if self.blog_id == nil or self.blog_id == 0 @@ -110,13 +110,17 @@ end.join(' AND ') end end def state_before_save - self.state.before_save(self) + state.before_save(self) end + def state_after_save + state.after_save(self) + end + def html_map(field=nil); self.class.html_map(field); end def full_html unless blog.controller raise "full_html only works with an active controller" @@ -173,18 +177,27 @@ def blog self[:blog] ||= blog_id.to_i.zero? ? Blog.default : Blog.find(blog_id) end + def state=(newstate) + if state + state.exit_hook(self, newstate) + end + @state = newstate + self[:state] = newstate.memento + newstate.enter_hook(self) + @state + end + def publish! self.published = true self.save! end def withdraw - self.published = false - self.published_at = nil + state.withdraw(self) end def withdraw! self.withdraw self.save! @@ -201,14 +214,22 @@ def published_at self[:published_at] || self[:created_at] end + def published? + state.published?(self) + end + def just_published? state.just_published? end + def withdrawn? + state.withdrawn? + end + def publication_pending? state.publication_pending? end def post_trigger @@ -225,55 +246,12 @@ end def send_notifications(controller = nil) state.send_notifications(self, controller || blog.controller) end - - # is_spam? checks to see if this is spam. This really belongs in a 'feedback' class - # that is the parent of Comment and Trackback, but we aren't going to build one right - # now. - # - # options are passed on to Akismet. Recommended options (when available) are: - # - # :permalink => the article's URL - # :user_agent => the poster's UserAgent string - # :referer => the poster's Referer string - # - def is_spam?(options={}) - return false unless blog.sp_global +end - sp = SpamProtection.new(blog) - spam = false - - # Check fields against the blacklist. - spam_fields.each do |field| - spam ||= sp.is_spam? self[field] - end - - # Attempt to use Akismet. Timeout after 5 seconds if we can't contact them. - unless blog.sp_akismet_key.blank? - Timeout.timeout(5) do - akismet = Akismet.new(blog.sp_akismet_key,blog.canonical_server_url) - spam ||= akismet.commentCheck(akismet_options.merge(options)) - end - end - - spam == true +class Object + def to_text_filter + TextFilter.find_by_name(self.to_s) || TextFilter.find_by_name('none') end - - def set_spam(is_spam, options ={}) - unless blog.sp_akismet_key.blank? - Timeout.timeout(5) do - akismet = Akismet.new(blog.sp_akismet_key,blog.canonical_server_url) - if is_spam - STDERR.puts "** submitting spam for #{id}" - akismet.submitSpam(akismet_options.merge(options)) - else - STDERR.puts "** submitting ham for #{id}" - akismet.submitHam(akismet_options.merge(options)) - end - end - end - end end - -class Object; def to_text_filter; TextFilter.find_by_name(self.to_s); end; end