diff options
Diffstat (limited to 'app')
27 files changed, 385 insertions, 389 deletions
diff --git a/app/controllers/refinery/admin/blog/categories_controller.rb b/app/controllers/refinery/admin/blog/categories_controller.rb index 12f22ce..0fe4eec 100644 --- a/app/controllers/refinery/admin/blog/categories_controller.rb +++ b/app/controllers/refinery/admin/blog/categories_controller.rb @@ -3,7 +3,7 @@ module Refinery module Blog class CategoriesController < ::Refinery::AdminController - crudify :'refinery/blog_category', + crudify :'refinery/blog/category', :title_attribute => :title, :order => 'title ASC' diff --git a/app/controllers/refinery/admin/blog/comments_controller.rb b/app/controllers/refinery/admin/blog/comments_controller.rb index a3df235..6c1417e 100644 --- a/app/controllers/refinery/admin/blog/comments_controller.rb +++ b/app/controllers/refinery/admin/blog/comments_controller.rb @@ -5,23 +5,23 @@ module Refinery cache_sweeper Refinery::BlogSweeper - crudify :'refinery/blog_comment', + crudify :'refinery/blog/comment', :title_attribute => :name, :order => 'published_at DESC' def index - @blog_comments = Refinery::BlogComment.unmoderated.page(params[:page]) + @blog_comments = Refinery::Blog::Comment.unmoderated.page(params[:page]) render :action => 'index' end def approved unless params[:id].present? - @blog_comments = Refinery::BlogComment.approved.page(params[:page]) + @blog_comments = Refinery::Blog::Comment.approved.page(params[:page]) render :action => 'index' else - @blog_comment = Refinery::BlogComment.find(params[:id]) + @blog_comment = Refinery::Blog::Comment.find(params[:id]) @blog_comment.approve! flash[:notice] = t('approved', :scope => 'refinery.admin.blog.comments', :author => @blog_comment.name) @@ -31,11 +31,11 @@ module Refinery def rejected unless params[:id].present? - @blog_comments = Refinery::BlogComment.rejected.page(params[:page]) + @blog_comments = Refinery::Blog::Comment.rejected.page(params[:page]) render :action => 'index' else - @blog_comment = Refinery::BlogComment.find(params[:id]) + @blog_comment = Refinery::Blog::Comment.find(params[:id]) @blog_comment.reject! flash[:notice] = t('rejected', :scope => 'refinery.admin.blog.comments', :author => @blog_comment.name) diff --git a/app/controllers/refinery/admin/blog/posts_controller.rb b/app/controllers/refinery/admin/blog/posts_controller.rb index 62b6949..aa40c85 100644 --- a/app/controllers/refinery/admin/blog/posts_controller.rb +++ b/app/controllers/refinery/admin/blog/posts_controller.rb @@ -2,20 +2,21 @@ module Refinery module Admin module Blog class PostsController < ::Refinery::AdminController - + cache_sweeper Refinery::BlogSweeper - crudify :'refinery/blog_post', + crudify :'refinery/blog/post', :title_attribute => :title, - :order => 'published_at DESC' - + :order => 'published_at DESC', + :redirect_to_url => "main_app.refinery_admin_blog_posts_path" + before_filter :find_all_categories, :only => [:new, :edit, :create, :update] - before_filter :check_category_ids, :only => :update + before_filter :check_category_ids, :only => :update def uncategorized - @blog_posts = Refinery::BlogPost.uncategorized.page(params[:page]) + @blog_posts = Refinery::Blog::Post.uncategorized.page(params[:page]) end def tags @@ -31,7 +32,7 @@ module Refinery else '%' end - @tags = Refinery::BlogPost.tag_counts_on(:tags).where( + @tags = Refinery::Blog::Post.tag_counts_on(:tags).where( ["tags.name #{op} ?", "#{wildcard}#{params[:term].to_s.downcase}#{wildcard}"] ).map { |tag| {:id => tag.id, :value => tag.name}} render :json => @tags.flatten @@ -39,19 +40,19 @@ module Refinery def create # if the position field exists, set this object as last object, given the conditions of this class. - if Refinery::BlogPost.column_names.include?("position") + if Refinery::Blog::Post.column_names.include?("position") params[:blog_post].merge!({ - :position => ((Refinery::BlogPost.maximum(:position, :conditions => "")||-1) + 1) + :position => ((Refinery::Blog::Post.maximum(:position, :conditions => "")||-1) + 1) }) end - if Refinery::BlogPost.column_names.include?("user_id") + if Refinery::Blog::Post.column_names.include?("user_id") params[:blog_post].merge!({ :user_id => current_refinery_user.id }) end - if (@blog_post = Refinery::BlogPost.create(params[:blog_post])).valid? + if (@blog_post = Refinery::Blog::Post.create(params[:blog_post])).valid? (request.xhr? ? flash.now : flash).notice = t( 'refinery.crudify.created', :what => "'#{@blog_post.title}'" @@ -85,7 +86,7 @@ module Refinery protected def find_all_categories - @blog_categories = Refinery::BlogCategory.find(:all) + @blog_categories = Refinery::Blog::Category.find(:all) end def check_category_ids diff --git a/app/controllers/refinery/admin/blog/settings_controller.rb b/app/controllers/refinery/admin/blog/settings_controller.rb index 1894ac6..ee71393 100644 --- a/app/controllers/refinery/admin/blog/settings_controller.rb +++ b/app/controllers/refinery/admin/blog/settings_controller.rb @@ -4,12 +4,12 @@ module Refinery class SettingsController < ::Refinery::AdminController def notification_recipients - @recipients = Refinery::BlogComment::Notification.recipients + @recipients = Refinery::Blog::Comment::Notification.recipients if request.post? - Refinery::BlogComment::Notification.recipients = params[:recipients] + Refinery::Blog::Comment::Notification.recipients = params[:recipients] flash[:notice] = t('updated', :scope => 'admin.blog.settings.notification_recipients', - :recipients => Refinery::BlogComment::Notification.recipients) + :recipients => Refinery::Blog::Comment::Notification.recipients) unless request.xhr? or from_dialog? redirect_back_or_default(admin_blog_posts_path) else @@ -20,7 +20,7 @@ module Refinery end def moderation - enabled = Refinery::BlogComment::Moderation.toggle! + enabled = Refinery::Blog::Comment::Moderation.toggle! unless request.xhr? redirect_back_or_default(admin_blog_posts_path) else @@ -30,7 +30,7 @@ module Refinery end def comments - enabled = Refinery::BlogComment.toggle! + enabled = Refinery::Blog::Comment.toggle! unless request.xhr? redirect_back_or_default(admin_blog_posts_path) else @@ -40,7 +40,7 @@ module Refinery end def teasers - enabled = Refinery::BlogPost.teaser_enabled_toggle! + enabled = Refinery::Blog::Post.teaser_enabled_toggle! unless request.xhr? redirect_back_or_default(admin_blog_posts_path) else diff --git a/app/controllers/refinery/blog/base_controller.rb b/app/controllers/refinery/blog/base_controller.rb index 01892d1..919c180 100644 --- a/app/controllers/refinery/blog/base_controller.rb +++ b/app/controllers/refinery/blog/base_controller.rb @@ -4,7 +4,7 @@ module Refinery include ControllerHelper - helper :'refinery/blog_posts' + helper :'refinery/blog/posts' before_filter :find_page, :find_all_blog_categories protected diff --git a/app/controllers/refinery/blog/categories_controller.rb b/app/controllers/refinery/blog/categories_controller.rb index 80e54d9..60c8346 100644 --- a/app/controllers/refinery/blog/categories_controller.rb +++ b/app/controllers/refinery/blog/categories_controller.rb @@ -3,8 +3,8 @@ module Refinery class CategoriesController < BaseController def show - @category = Refinery::BlogCategory.find(params[:id]) - @blog_posts = @category.posts.live.includes(:comments, :categories).page(params[:page]) + @blog_category = Refinery::Blog::Category.find(params[:id]) + @blog_posts = @blog_category.posts.live.includes(:comments, :categories).page(params[:page]) end end diff --git a/app/controllers/refinery/blog/posts_controller.rb b/app/controllers/refinery/blog/posts_controller.rb index 7b09329..d3cd7a1 100644 --- a/app/controllers/refinery/blog/posts_controller.rb +++ b/app/controllers/refinery/blog/posts_controller.rb @@ -12,7 +12,7 @@ module Refinery def index # Rss feeders are greedy. Let's give them every blog post instead of paginating. - (@blog_posts = Refinery::BlogPost.live.includes(:comments, :categories).all) if request.format.rss? + (@blog_posts = Refinery::Blog::Post.live.includes(:comments, :categories).all) if request.format.rss? respond_with (@blog_posts) do |format| format.html format.rss @@ -20,7 +20,7 @@ module Refinery end def show - @blog_comment = Refinery::BlogComment.new + @blog_comment = Refinery::Blog::Comment.new respond_with (@blog_post) do |format| format.html { present(@blog_post) } @@ -30,7 +30,7 @@ module Refinery def comment if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid? - if Refinery::BlogComment::Moderation.enabled? or @blog_comment.ham? + if Refinery::Blog::Comment::Moderation.enabled? or @blog_comment.ham? begin Refinery::Blog::CommentMailer.notification(@blog_comment, request).deliver rescue @@ -38,7 +38,7 @@ module Refinery end end - if Refinery::BlogComment::Moderation.enabled? + if Refinery::Blog::Comment::Moderation.enabled? flash[:notice] = t('thank_you_moderated', :scope => 'refinery.blog.posts.comments') redirect_to main_app.blog_post_url(params[:id]) else @@ -56,12 +56,12 @@ module Refinery date = "#{params[:month]}/#{params[:year]}" @archive_date = Time.parse(date) @date_title = @archive_date.strftime('%B %Y') - @blog_posts = Refinery::BlogPost.live.by_archive(@archive_date).page(params[:page]) + @blog_posts = Refinery::Blog::Post.live.by_archive(@archive_date).page(params[:page]) else date = "01/#{params[:year]}" @archive_date = Time.parse(date) @date_title = @archive_date.strftime('%Y') - @blog_posts = Refinery::BlogPost.live.by_year(@archive_date).page(params[:page]) + @blog_posts = Refinery::Blog::Post.live.by_year(@archive_date).page(params[:page]) end respond_with (@blog_posts) end @@ -69,7 +69,7 @@ module Refinery def tagged @tag = ActsAsTaggableOn::Tag.find(params[:tag_id]) @tag_name = @tag.name - @blog_posts = Refinery::BlogPost.tagged_with(@tag_name).page(params[:page]) + @blog_posts = Refinery::Blog::Post.tagged_with(@tag_name).page(params[:page]) end end end diff --git a/app/helpers/refinery/blog/controller_helper.rb b/app/helpers/refinery/blog/controller_helper.rb index c1c2a6a..035275c 100644 --- a/app/helpers/refinery/blog/controller_helper.rb +++ b/app/helpers/refinery/blog/controller_helper.rb @@ -5,9 +5,9 @@ module Refinery protected def find_blog_post - unless (@blog_post = Refinery::BlogPost.find(params[:id])).try(:live?) + unless (@blog_post = Refinery::Blog::Post.find(params[:id])).try(:live?) if refinery_user? and current_refinery_user.authorized_plugins.include?("refinerycms_blog") - @blog_post = Refinery::BlogPost.find(params[:id]) + @blog_post = Refinery::Blog::Post.find(params[:id]) else error_404 end @@ -15,15 +15,15 @@ module Refinery end def find_all_blog_posts - @blog_posts = Refinery::BlogPost.live.includes(:comments, :categories).page(params[:page]) + @blog_posts = Refinery::Blog::Post.live.includes(:comments, :categories).page(params[:page]) end def find_tags - @tags = Refinery::BlogPost.tag_counts_on(:tags) + @tags = Refinery::Blog::Post.tag_counts_on(:tags) end def find_all_blog_categories - @blog_categories = Refinery::BlogCategory.all + @blog_categories = Refinery::Blog::Category.all end end end diff --git a/app/helpers/refinery/blog/posts_helper.rb b/app/helpers/refinery/blog/posts_helper.rb new file mode 100644 index 0000000..418f360 --- /dev/null +++ b/app/helpers/refinery/blog/posts_helper.rb @@ -0,0 +1,51 @@ +module Refinery + module Blog + module PostsHelper + def blog_archive_widget + posts = Refinery::Blog::Post.select('published_at').all_previous + return nil if posts.blank? + + render :partial => "/refinery/blog/widgets/blog_archive", :locals => { :posts => posts } + end + alias_method :blog_archive_list, :blog_archive_widget + + def next_or_previous?(post) + post.next.present? or post.prev.present? + end + + def blog_post_teaser_enabled? + Refinery::Blog::Post.teasers_enabled? + end + + def blog_post_teaser(post) + if post.respond_to?(:custom_teaser) && post.custom_teaser.present? + post.custom_teaser.html_safe + else + truncate(post.body, { + :length => Refinery::Setting.find_or_set(:blog_post_teaser_length, 250), + :preserve_html_tags => true + }).html_safe + end + end + + def archive_link(post) + if post.published_at >= Time.now.end_of_year.advance(:years => -3) + post_date = post.published_at.strftime('%m/%Y') + year = post_date.split('/')[1] + month = post_date.split('/')[0] + count = Blog::Post.by_archive(Time.parse(post_date)).size + text = t("date.month_names")[month.to_i] + " #{year} (#{count})" + + link_to(text, main_app.archive_blog_posts_path(:year => year, :month => month)) + else + post_date = post.published_at.strftime('01/%Y') + year = post_date.split('/')[1] + count = Refinery::Blog::Post.by_year(Time.parse(post_date)).size + text = "#{year} (#{count})" + + link_to(text, main_app.archive_blog_posts_path(:year => year)) + end + end + end + end +end
\ No newline at end of file diff --git a/app/helpers/refinery/blog_posts_helper.rb b/app/helpers/refinery/blog_posts_helper.rb deleted file mode 100644 index bfc3f40..0000000 --- a/app/helpers/refinery/blog_posts_helper.rb +++ /dev/null @@ -1,49 +0,0 @@ -module Refinery - module BlogPostsHelper - def blog_archive_widget - posts = Refinery::BlogPost.select('published_at').all_previous - return nil if posts.blank? - - render :partial => "/refinery/blog/widgets/blog_archive", :locals => { :posts => posts } - end - alias_method :blog_archive_list, :blog_archive_widget - - def next_or_previous?(post) - post.next.present? or post.prev.present? - end - - def blog_post_teaser_enabled? - Refinery::BlogPost.teasers_enabled? - end - - def blog_post_teaser(post) - if post.respond_to?(:custom_teaser) && post.custom_teaser.present? - post.custom_teaser.html_safe - else - truncate(post.body, { - :length => Refinery::Setting.find_or_set(:blog_post_teaser_length, 250), - :preserve_html_tags => true - }).html_safe - end - end - - def archive_link(post) - if post.published_at >= Time.now.end_of_year.advance(:years => -3) - post_date = post.published_at.strftime('%m/%Y') - year = post_date.split('/')[1] - month = post_date.split('/')[0] - count = BlogPost.by_archive(Time.parse(post_date)).size - text = t("date.month_names")[month.to_i] + " #{year} (#{count})" - - link_to(text, main_app.archive_blog_posts_path(:year => year, :month => month)) - else - post_date = post.published_at.strftime('01/%Y') - year = post_date.split('/')[1] - count = Refinery::BlogPost.by_year(Time.parse(post_date)).size - text = "#{year} (#{count})" - - link_to(text, main_app.archive_blog_posts_path(:year => year)) - end - end - end -end diff --git a/app/mailers/refinery/blog/comment_mailer.rb b/app/mailers/refinery/blog/comment_mailer.rb index f36ea29..dabc9e6 100644 --- a/app/mailers/refinery/blog/comment_mailer.rb +++ b/app/mailers/refinery/blog/comment_mailer.rb @@ -3,11 +3,11 @@ module Refinery class CommentMailer < ActionMailer::Base def notification(comment, request) - subject BlogComment::Notification.subject - recipients BlogComment::Notification.recipients + subject Blog::Comment::Notification.subject + recipients Blog::Comment::Notification.recipients from "\"#{RefinerySetting[:site_name]}\" <no-reply@#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}>" sent_on Time.now - @comment = comment + @blog_comment = comment end end diff --git a/app/models/refinery/blog/category.rb b/app/models/refinery/blog/category.rb new file mode 100644 index 0000000..dc85b50 --- /dev/null +++ b/app/models/refinery/blog/category.rb @@ -0,0 +1,26 @@ +module Refinery + module Blog + class Category < ActiveRecord::Base + + has_many :categorizations, :dependent => :destroy, :foreign_key => :blog_category_id + has_many :posts, :through => :categorizations, :source => :blog_post + + acts_as_indexed :fields => [:title] + + validates :title, :presence => true, :uniqueness => true + + has_friendly_id :title, :use_slug => true, + :default_locale => (::Refinery::I18n.default_frontend_locale rescue :en), + :approximate_ascii => Refinery::Setting.find_or_set(:approximate_ascii, false, :scoping => 'blog'), + :strip_non_ascii => Refinery::Setting.find_or_set(:strip_non_ascii, false, :scoping => 'blog') + + def post_count + posts.select(&:live?).count + end + + # how many items to show per page + self.per_page = Refinery::Setting.find_or_set(:blog_posts_per_page, 10) + + end + end +end
\ No newline at end of file diff --git a/app/models/refinery/blog/comment.rb b/app/models/refinery/blog/comment.rb new file mode 100644 index 0000000..55a67ba --- /dev/null +++ b/app/models/refinery/blog/comment.rb @@ -0,0 +1,125 @@ +module Refinery + module Blog + class Comment < ActiveRecord::Base + + attr_accessible :name, :email, :message + + filters_spam :author_field => :name, + :email_field => :email, + :message_field => :body + + belongs_to :post, :class_name => 'Refinery::Blog::Post', :foreign_key => 'blog_post_id' + + acts_as_indexed :fields => [:name, :email, :message] + + alias_attribute :message, :body + + validates :name, :message, :presence => true + validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i } + + scope :unmoderated, :conditions => {:state => nil} + scope :approved, :conditions => {:state => 'approved'} + scope :rejected, :conditions => {:state => 'rejected'} + + self.per_page = Refinery::Setting.find_or_set(:blog_comments_per_page, 10) + + def avatar_url(options = {}) + options = {:size => 60} + require 'digest/md5' + size = ("?s=#{options[:size]}" if options[:size]) + "http://gravatar.com/avatar/#{Digest::MD5.hexdigest(self.email.to_s.strip.downcase)}#{size}.jpg" + end + + def approve! + self.update_attribute(:state, 'approved') + end + + def reject! + self.update_attribute(:state, 'rejected') + end + + def rejected? + self.state == 'rejected' + end + + def approved? + self.state == 'approved' + end + + def unmoderated? + self.state.nil? + end + + def self.toggle! + currently = Refinery::Setting.find_or_set(:comments_allowed, true, { + :scoping => 'blog' + }) + Refinery::Setting.set(:comments_allowed, {:value => !currently, :scoping => 'blog'}) + end + + before_create do |comment| + unless Moderation.enabled? + comment.state = comment.ham? ? 'approved' : 'rejected' + end + end + + module Moderation + class << self + def enabled? + Refinery::Setting.find_or_set(:comment_moderation, true, { + :scoping => 'blog', + :restricted => false + }) + end + + def toggle! + new_value = { + :value => !Blog::Comment::Moderation.enabled?, + :scoping => 'blog', + :restricted => false + } + Refinery::Setting.set(:comment_moderation, new_value) + end + end + end + + module Notification + class << self + def recipients + Refinery::Setting.find_or_set(:comment_notification_recipients, (Refinery::Role[:refinery].users.first.email rescue ''), + { + :scoping => 'blog', + :restricted => false + }) + end + + def recipients=(emails) + new_value = { + :value => emails, + :scoping => 'blog', + :restricted => false + } + Refinery::Setting.set(:comment_notification_recipients, new_value) + end + + def subject + Refinery::Setting.find_or_set(:comment_notification_subject, "New inquiry from your website", { + :scoping => 'blog', + :restricted => false + }) + end + + def subject=(subject_line) + new_value = { + :value => subject_line, + :scoping => 'blog', + :restricted => false + } + Refinery::Setting.set(:comment_notification_subject, new_value) + end + end + end + + end + end +end
\ No newline at end of file diff --git a/app/models/refinery/blog/post.rb b/app/models/refinery/blog/post.rb new file mode 100644 index 0000000..883f4fc --- /dev/null +++ b/app/models/refinery/blog/post.rb @@ -0,0 +1,114 @@ +require 'acts-as-taggable-on' +require 'seo_meta' + +module Refinery + module Blog + class Post < ActiveRecord::Base + + is_seo_meta if self.table_exists? + + default_scope :order => 'published_at DESC' + #.first & .last will be reversed -- consider a with_exclusive_scope on these? + + belongs_to :author, :class_name => 'Refinery::User', :foreign_key => :user_id, :readonly => true + + has_many :comments, :class_name => 'Refinery::Blog::Comment', :dependent => :destroy, :foreign_key => :blog_post_id + acts_as_taggable + + has_many :categorizations, :dependent => :destroy, :foreign_key => :blog_post_id + has_many :categories, :through => :categorizations, :source => :blog_category + + acts_as_indexed :fields => [:title, :body] + + validates :title, :presence => true, :uniqueness => true + validates :body, :presence => true + + has_friendly_id :friendly_id_source, :use_slug => true, + :default_locale => (::Refinery::I18n.default_frontend_locale rescue :en), + :approximate_ascii => Refinery::Setting.find_or_set(:approximate_ascii, false, :scoping => 'blog'), + :strip_non_ascii => Refinery::Setting.find_or_set(:strip_non_ascii, false, :scoping => 'blog') + + scope :by_archive, lambda { |archive_date| + where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]) + } + + scope :by_year, lambda { |archive_year| + where(['published_at between ? and ?', archive_year.beginning_of_year, archive_year.end_of_year]) + } + + scope :all_previous, lambda { where(['published_at <= ?', Time.now.beginning_of_month]) } + + scope :live, lambda { where( "published_at <= ? and draft = ?", Time.now, false) } + + scope :previous, lambda { |i| where(["published_at < ? and draft = ?", i.published_at, false]).limit(1) } + + scope :uncategorized, lambda { + live.includes(:categories).where(:categories => { Refinery::Categorization.table_name => { :blog_category_id => nil } }) + } + + attr_accessible :title, :body, :custom_teaser, :tag_list, :draft, :published_at, :custom_url + attr_accessible :browser_title, :meta_keywords, :meta_description, :user_id, :category_ids + + self.per_page = Refinery::Setting.find_or_set(:blog_posts_per_page, 10) + + def next + self.class.next(self).first + end + + def prev + self.class.previous(self).first + end + + def live? + !draft and published_at <= Time.now + end + + def category_ids=(ids) + self.categories = ids.reject{|id| id.blank?}.collect {|c_id| + Refinery::Blog::Category.find(c_id.to_i) rescue nil + }.compact + end + + def friendly_id_source + custom_url.present? ? custom_url : title + end + + class << self + def next(current_record) + self.send(:with_exclusive_scope) do + where(["published_at > ? and draft = ?", current_record.published_at, false]).order("published_at ASC") + end + end + + def comments_allowed? + Refinery::Setting.find_or_set(:comments_allowed, true, :scoping => 'blog') + end + + def teasers_enabled? + Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'blog') + end + + def teaser_enabled_toggle! + currently = Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'blog') + Refinery::Setting.set(:teasers_enabled, :value => !currently, :scoping => 'blog') + end + end + + module ShareThis + DEFAULT_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + + class << self + def key + Refinery::Setting.find_or_set(:share_this_key, Blog::Post::ShareThis::DEFAULT_KEY, :scoping => 'blog') + end + + def enabled? + key = Blog::Post::ShareThis.key + key.present? and key != Blog::Post::ShareThis::DEFAULT_KEY + end + end + end + + end + end +end
\ No newline at end of file diff --git a/app/models/refinery/blog_category.rb b/app/models/refinery/blog_category.rb deleted file mode 100644 index 3f10d92..0000000 --- a/app/models/refinery/blog_category.rb +++ /dev/null @@ -1,24 +0,0 @@ -module Refinery - class BlogCategory < ActiveRecord::Base - - has_many :categorizations, :dependent => :destroy - has_many :posts, :through => :categorizations, :source => :blog_post - - acts_as_indexed :fields => [:title] - - validates :title, :presence => true, :uniqueness => true - - has_friendly_id :title, :use_slug => true, - :default_locale => (::Refinery::I18n.default_frontend_locale rescue :en), - :approximate_ascii => Refinery::Setting.find_or_set(:approximate_ascii, false, :scoping => 'blog'), - :strip_non_ascii => Refinery::Setting.find_or_set(:strip_non_ascii, false, :scoping => 'blog') - - def post_count - posts.select(&:live?).count - end - - # how many items to show per page - self.per_page = Refinery::Setting.find_or_set(:blog_posts_per_page, 10) - - end -end diff --git a/app/models/refinery/blog_comment.rb b/app/models/refinery/blog_comment.rb deleted file mode 100644 index f7c1c84..0000000 --- a/app/models/refinery/blog_comment.rb +++ /dev/null @@ -1,135 +0,0 @@ -module Refinery - class BlogComment < ActiveRecord::Base - - attr_accessible :name, :email, :message - - filters_spam :author_field => :name, - :email_field => :email, - :message_field => :body - - belongs_to :post, :class_name => 'Refinery::BlogPost', :foreign_key => 'blog_post_id' - - acts_as_indexed :fields => [:name, :email, :message] - - alias_attribute :message, :body - - validates :name, :message, :presence => true - validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i } - - scope :unmoderated, :conditions => {:state => nil} - scope :approved, :conditions => {:state => 'approved'} - scope :rejected, :conditions => {:state => 'rejected'} - - self.per_page = Setting.find_or_set(:blog_comments_per_page, 10) - - def avatar_url(options = {}) - options = {:size => 60} - require 'digest/md5' - size = ("?s=#{options[:size]}" if options[:size]) - "http://gravatar.com/avatar/#{Digest::MD5.hexdigest(self.email.to_s.strip.downcase)}#{size}.jpg" - end - - def approve! - self.update_attribute(:state, 'approved') - end - - def reject! - self.update_attribute(:state, 'rejected') - end - - def rejected? - self.state == 'rejected' - end - - def approved? - self.state == 'approved' - end - - def unmoderated? - self.state.nil? - end - - def self.toggle! - currently = Refinery::Setting.find_or_set(:comments_allowed, true, { - :scoping => 'blog' - }) - Refinery::Setting.set(:comments_allowed, {:value => !currently, :scoping => 'blog'}) - end - - before_create do |comment| - unless Moderation.enabled? - comment.state = comment.ham? ? 'approved' : 'rejected' - end - end - - module Moderation - class << self - def enabled? - Refinery::Setting.find_or_set(:comment_moderation, true, { - :scoping => 'blog', - :restricted => false - }) - end - - def toggle! - new_value = { - :value => !BlogComment::Moderation.enabled?, - :scoping => 'blog', - :restricted => false - } - if Refinery::Setting.respond_to?(:set) - Refinery::Setting.set(:comment_moderation, new_value) - else - Refinery::Setting[:comment_moderation] = new_value - end - end - end - end - - module Notification - class << self - def recipients - Refinery::Setting.find_or_set(:comment_notification_recipients, (Refinery::Role[:refinery].users.first.email rescue ''), - { - :scoping => 'blog', - :restricted => false - }) - end - - def recipients=(emails) - new_value = { - :value => emails, - :scoping => 'blog', - :restricted => false - } - if Refinery::Setting.respond_to?(:set) - Refinery::Setting.set(:comment_notification_recipients, new_value) - else - Refinery::Setting[:comment_notification_recipients] = new_value - end - end - - def subject - Refinery::Setting.find_or_set(:comment_notification_subject, "New inquiry from your website", { - :scoping => 'blog', - :restricted => false - }) - end - - def subject=(subject_line) - new_value = { - :value => subject_line, - :scoping => 'blog', - :restricted => false - } - if Refinery::Setting.respond_to?(:set) - Refinery::Setting.set(:comment_notification_subject, new_value) - else - Refinery::Setting[:comment_notification_subject] = new_value - end - end - end - end - - end -end
\ No newline at end of file diff --git a/app/models/refinery/blog_post.rb b/app/models/refinery/blog_post.rb deleted file mode 100644 index 8cd3dd9..0000000 --- a/app/models/refinery/blog_post.rb +++ /dev/null @@ -1,112 +0,0 @@ -require 'acts-as-taggable-on' -require 'seo_meta' - -module Refinery - class BlogPost < ActiveRecord::Base - - is_seo_meta if self.table_exists? - - default_scope :order => 'published_at DESC' - #.first & .last will be reversed -- consider a with_exclusive_scope on these? - - belongs_to :author, :class_name => 'Refinery::User', :foreign_key => :user_id, :readonly => true - - has_many :comments, :class_name => 'Refinery::BlogComment', :dependent => :destroy - acts_as_taggable - - has_many :categorizations, :dependent => :destroy - has_many :categories, :through => :categorizations, :source => :blog_category - - acts_as_indexed :fields => [:title, :body] - - validates :title, :presence => true, :uniqueness => true - validates :body, :presence => true - - has_friendly_id :friendly_id_source, :use_slug => true, - :default_locale => (::Refinery::I18n.default_frontend_locale rescue :en), - :approximate_ascii => Refinery::Setting.find_or_set(:approximate_ascii, false, :scoping => 'blog'), - :strip_non_ascii => Refinery::Setting.find_or_set(:strip_non_ascii, false, :scoping => 'blog') - - scope :by_archive, lambda { |archive_date| - where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]) - } - - scope :by_year, lambda { |archive_year| - where(['published_at between ? and ?', archive_year.beginning_of_year, archive_year.end_of_year]) - } - - scope :all_previous, lambda { where(['published_at <= ?', Time.now.beginning_of_month]) } - - scope :live, lambda { where( "published_at <= ? and draft = ?", Time.now, false) } - - scope :previous, lambda { |i| where(["published_at < ? and draft = ?", i.published_at, false]).limit(1) } - - scope :uncategorized, lambda { - live.includes(:categories).where(:categories => { Refinery::Categorization.table_name => { :blog_category_id => nil } }) - } - - attr_accessible :title, :body, :custom_teaser, :tag_list, :draft, :published_at, :custom_url - attr_accessible :browser_title, :meta_keywords, :meta_description, :user_id, :category_ids - - self.per_page = Refinery::Setting.find_or_set(:blog_posts_per_page, 10) - - def next - BlogPost.next(self).first - end - - def prev - BlogPost.previous(self).first - end - - def live? - !draft and published_at <= Time.now - end - - def category_ids=(ids) - self.categories = ids.reject{|id| id.blank?}.collect {|c_id| - Refinery::BlogCategory.find(c_id.to_i) rescue nil - }.compact - end - - def friendly_id_source - custom_url.present? ? custom_url : title - end - - class << self - def next(current_record) - self.send(:with_exclusive_scope) do - where(["published_at > ? and draft = ?", current_record.published_at, false]).order("published_at ASC") - end - end - - def comments_allowed? - Refinery::Setting.find_or_set(:comments_allowed, true, :scoping => 'blog') - end - - def teasers_enabled? - Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'blog') - end - - def teaser_enabled_toggle! - currently = Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'blog') - Refinery::Setting.set(:teasers_enabled, :value => !currently, :scoping => 'blog') - end - end - - module ShareThis - DEFAULT_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - - class << self - def key - Refinery::Setting.find_or_set(:share_this_key, BlogPost::ShareThis::DEFAULT_KEY, :scoping => 'blog') - end - - def enabled? - key = BlogPost::ShareThis.key - key.present? and key != BlogPost::ShareThis::DEFAULT_KEY - end - end - end - - end -end diff --git a/app/models/refinery/categorization.rb b/app/models/refinery/categorization.rb index c4feaec..97f0928 100644 --- a/app/models/refinery/categorization.rb +++ b/app/models/refinery/categorization.rb @@ -2,8 +2,8 @@ module Refinery class Categorization < ActiveRecord::Base set_table_name 'refinery_blog_categories_blog_posts' - belongs_to :blog_post - belongs_to :blog_category + belongs_to :blog_post, :class_name => 'Refinery::Blog::Post', :foreign_key => :blog_post_id + belongs_to :blog_category, :class_name => 'Refinery::Blog::Category', :foreign_key => :blog_category_id end end
\ No newline at end of file diff --git a/app/sweepers/refinery/blog_sweeper.rb b/app/sweepers/refinery/blog_sweeper.rb index ceed5fa..a58ac7e 100644 --- a/app/sweepers/refinery/blog_sweeper.rb +++ b/app/sweepers/refinery/blog_sweeper.rb @@ -1,26 +1,26 @@ module Refinery class BlogSweeper < ActionController::Caching::Sweeper - observe BlogPost, BlogComment - + observe Blog::Post, Blog::Comment + def after_create(record) expire_cache_for(record) end - + def after_update(record) expire_cache_for(record) end - + def after_destroy(record) expire_cache_for(record) end - + private - + def expire_cache_for(record) # TODO: Convert these to url helpers expire_page '/blog' expire_page '/blog/feed.rss' end - + end end diff --git a/app/views/refinery/admin/blog/_submenu.html.erb b/app/views/refinery/admin/blog/_submenu.html.erb index 799c101..2915610 100644 --- a/app/views/refinery/admin/blog/_submenu.html.erb +++ b/app/views/refinery/admin/blog/_submenu.html.erb @@ -26,11 +26,11 @@ :class => 'page_add_icon' %> </li> </ul> - <% if Refinery::BlogPost.comments_allowed? %> + <% if Refinery::Blog::Post.comments_allowed? %> <ul class='collapsible_menu'> <li class='not_a_link'> - <% if Refinery::BlogComment.unmoderated.any? %> - <% title = t('.comments.title_with_count', :new_count => Refinery::BlogComment.unmoderated.size) %> + <% if Refinery::Blog::Comment.unmoderated.any? %> + <% title = t('.comments.title_with_count', :new_count => Refinery::Blog::Comment.unmoderated.size) %> <% else %> <% title = t('.comments.title') %> <% end %> @@ -74,11 +74,11 @@ </li> <li> <%= link_to t('.settings.comments'), main_app.comments_refinery_admin_blog_settings_path, - :class => "#{Refinery::BlogPost.comments_allowed? ? 'success' : 'failure'}_icon" %> + :class => "#{Refinery::Blog::Post.comments_allowed? ? 'success' : 'failure'}_icon" %> </li> <li> <%= link_to t('.settings.moderation'), main_app.moderation_refinery_admin_blog_settings_path, - :class => "#{Refinery::BlogComment::Moderation.enabled? ? 'success' : 'failure'}_icon" %> + :class => "#{Refinery::Blog::Comment::Moderation.enabled? ? 'success' : 'failure'}_icon" %> </li> <li> <%= link_to t('.settings.update_notified'), @@ -87,7 +87,7 @@ </li> <li> <%= link_to t('.settings.teasers'), - main_app.teasers_refinery_admin_blog_settings_path, :class => "#{Refinery::BlogPost.teasers_enabled? ? 'success' : 'failure'}_icon" %> + main_app.teasers_refinery_admin_blog_settings_path, :class => "#{Refinery::Blog::Post.teasers_enabled? ? 'success' : 'failure'}_icon" %> </li> </ul> diff --git a/app/views/refinery/admin/blog/posts/_form.html.erb b/app/views/refinery/admin/blog/posts/_form.html.erb index 8a3b091..822ec8a 100644 --- a/app/views/refinery/admin/blog/posts/_form.html.erb +++ b/app/views/refinery/admin/blog/posts/_form.html.erb @@ -27,7 +27,6 @@ </ul> <div id='page_part_editors'> - <% part_index = -1 %> <%= render :partial => 'form_part', :locals => { diff --git a/app/views/refinery/blog/categories/show.html.erb b/app/views/refinery/blog/categories/show.html.erb index adcf1aa..00d9596 100644 --- a/app/views/refinery/blog/categories/show.html.erb +++ b/app/views/refinery/blog/categories/show.html.erb @@ -1,4 +1,4 @@ -<% content_for :body_content_title, @category.title %> +<% content_for :body_content_title, @blog_category.title %> <% content_for :body_content_left do %> <% if @blog_posts.any? %> diff --git a/app/views/refinery/blog/comment_mailer/notification.html.erb b/app/views/refinery/blog/comment_mailer/notification.html.erb index 800f12c..0c7dcd4 100644 --- a/app/views/refinery/blog/comment_mailer/notification.html.erb +++ b/app/views/refinery/blog/comment_mailer/notification.html.erb @@ -4,10 +4,10 @@ <%=raw t('.comment_starts') %> -<%=raw t('.from') %>: <%= @comment.name %> -<%=raw t('.email') %>: <%= @comment.email %> +<%=raw t('.from') %>: <%= @blog_comment.name %> +<%=raw t('.email') %>: <%= @blog_comment.email %> <%=raw t('.message') %>: -<%=simple_format strip_tags(@comment.body) %> +<%=simple_format strip_tags(@blog_comment.body) %> <%=raw t('.comment_ends') %> diff --git a/app/views/refinery/blog/posts/_post.html.erb b/app/views/refinery/blog/posts/_post.html.erb index f86f63a..cbecc5f 100644 --- a/app/views/refinery/blog/posts/_post.html.erb +++ b/app/views/refinery/blog/posts/_post.html.erb @@ -23,7 +23,7 @@ </header> <%= @blog_post.body.html_safe %> - <% if Refinery::BlogPost::ShareThis.enabled? %> + <% if Refinery::Blog::Post::ShareThis.enabled? %> <span class="st_sharethis" displayText="ShareThis"></span> <% end %> </article> diff --git a/app/views/refinery/blog/posts/show.html.erb b/app/views/refinery/blog/posts/show.html.erb index 020c964..2ca168e 100644 --- a/app/views/refinery/blog/posts/show.html.erb +++ b/app/views/refinery/blog/posts/show.html.erb @@ -3,7 +3,7 @@ <%= render 'post' %> </div> - <% if Refinery::BlogPost.comments_allowed? %> + <% if Refinery::Blog::Post.comments_allowed? %> <%= render 'comments'%> <% end %> <% end %> @@ -17,5 +17,5 @@ <%# enable AJAX'd post nav at your own risk until html5 history API implemented. %> <%#= javascript_include_tag('refinery/blog/frontend') %> <script src="http://w.sharethis.com/button/buttons.js"></script> - <script>stLight.options({publisher:'<%= BlogPost::ShareThis.key %>'});</script> -<% end if Refinery::BlogPost::ShareThis.enabled? %> + <script>stLight.options({publisher:'<%= Blog::Post::ShareThis.key %>'});</script> +<% end if Refinery::Blog::Post::ShareThis.enabled? %> diff --git a/app/views/refinery/blog/shared/_categories.html.erb b/app/views/refinery/blog/shared/_categories.html.erb index 295cae0..1280cd2 100644 --- a/app/views/refinery/blog/shared/_categories.html.erb +++ b/app/views/refinery/blog/shared/_categories.html.erb @@ -2,7 +2,7 @@ <h2><%= t('.title') %></h2> <ul id='categories'> <% @blog_categories.each do |category| %> - <li<%= " class='selected'" if @category.present? and @category.id == category.id %>> + <li<%= " class='selected'" if @blog_category.present? and @blog_category.id == category.id %>> <%= link_to "#{category.title} (#{category.post_count})", main_app.blog_category_path(category) %> </li> <% end %> diff --git a/app/views/refinery/blog/shared/_post.html.erb b/app/views/refinery/blog/shared/_post.html.erb index 18271ec..c384bcb 100644 --- a/app/views/refinery/blog/shared/_post.html.erb +++ b/app/views/refinery/blog/shared/_post.html.erb @@ -33,7 +33,7 @@ <%= link_to t('read_more', :scope => 'refinery.blog.shared.posts'), main_app.blog_post_path(post) if blog_post_teaser_enabled? %> </p> <aside class='comment_count'> - <% if Refinery::BlogPost.comments_allowed? %> + <% if Refinery::Blog::Post.comments_allowed? %> <% if post.comments.any? %> (<%= pluralize(post.comments.approved.count, t('singular', :scope => 'refinery.blog.shared.comments')) %>) <% else %> |