Permalink
Browse files

Merge branch 'master' of http://github.com/unixcharles/refinerycms-blog

  • Loading branch information...
2 parents 641ba66 + 7a2b35d commit 78e5dea3185e33de53d08d64a3e41006a026c54b @joemsak joemsak committed Jul 23, 2010
Showing with 319 additions and 277 deletions.
  1. +8 −5 app/controllers/admin/blogs_controller.rb
  2. +4 −4 app/controllers/admin/comments_controller.rb
  3. +10 −22 app/controllers/blogs_controller.rb
  4. +42 −2 app/models/blog.rb
  5. +18 −5 app/models/blog_mailer.rb
  6. +1 −2 app/models/comment.rb
  7. +1 −1 app/views/admin/blog_settings/_blog_setting.html.erb
  8. +1 −7 app/views/admin/blog_settings/index.html.erb
  9. +2 −1 app/views/admin/blogs/_blog.html.erb
  10. +74 −46 app/views/admin/blogs/_form.html.erb
  11. +16 −0 app/views/admin/blogs/_side_bar.html.erb
  12. +15 −39 app/views/admin/blogs/index.html.erb
  13. +2 −2 app/views/admin/comments/_comment.html.erb
  14. +5 −14 app/views/admin/comments/index.html.erb
  15. +1 −2 app/views/admin/comments/show.html.erb
  16. +3 −5 app/views/blog_mailer/notification.html.erb
  17. +0 −3 app/views/blogs/_blog.html.erb
  18. +12 −0 app/views/blogs/_blog_post.html.erb
  19. +1 −2 app/views/blogs/_comments.html.erb
  20. +9 −8 app/views/blogs/_form.html.erb
  21. +4 −43 app/views/blogs/_side_body.html.erb
  22. +4 −15 app/views/blogs/index.html.erb
  23. +1 −1 app/views/blogs/index.rss.builder
  24. +7 −0 app/views/blogs/post/_authors.html.erb
  25. +7 −0 app/views/blogs/post/_categories.html.erb
  26. +7 −0 app/views/blogs/post/_tags.html.erb
  27. +20 −43 app/views/blogs/show.html.erb
  28. +10 −0 app/views/blogs/side_body/_authors.html.erb
  29. +10 −0 app/views/blogs/side_body/_categories.html.erb
  30. +10 −0 app/views/blogs/side_body/_recent_posts.html.erb
  31. +10 −0 app/views/blogs/side_body/_tags.html.erb
  32. +2 −2 config/routes.rb
  33. +1 −1 db/migrate/20100301212444_create_blogs.rb
  34. +1 −2 readme.md
@@ -1,8 +1,11 @@
class Admin::BlogsController < Admin::BaseController
- before_filter :get_count, :only => 'index'
+
+ before_filter :group_blogs_by_date, :only => 'index'
+
crudify :blog, :title_attribute => :title, :order => "publishing_date DESC"
-
- def get_count
- @unread_comments_count = Comment.unread.count
- end
+
+ def group_blogs_by_date
+ @grouped_blogs = Blog.grouped_by_date
+ end
+
end
@@ -1,7 +1,7 @@
class Admin::CommentsController < Admin::BaseController
crudify :comment, :title_attribute => "name", :order => "created_at DESC"
- before_filter :find_comment, :only => [:show, :toggle_status, :unread, :destroy]
+ before_filter :find_comment, :only => [:show, :toggle_status, :unmoderated, :destroy]
before_filter :find_all_comments, :only => [:index]
def toggle_status
@@ -12,9 +12,9 @@ def toggle_status
redirect_to :action => 'index'
end
- def unread
+ def unmoderated
if @comment.update_attribute(:approved, nil)
- flash[:notice] = "You sent a comment from '#{@comment.name}' back to unread comments"
+ flash[:notice] = "You sent a comment from '#{@comment.name}' back to unmoderated comments"
end
redirect_to :action => 'index'
@@ -23,6 +23,6 @@ def unread
def find_all_comments
@comments_history = Comment.history.paginate :page => params[:page]
- @unread_comments = Comment.unread
+ @unmoderated_comments = Comment.unmoderated
end
end
@@ -3,7 +3,6 @@ class BlogsController < ApplicationController
before_filter :find_blog, :only => [:comment, :show, :authorize]
before_filter :find_page, :except => [:captcha, :authorize]
before_filter :load_blogs, :except => [:captcha, :authorize, :tag, :category, :author, :show]
- before_filter :load_tags, :except => [:captcha, :authorize]
def index
present(@page)
@@ -47,8 +46,14 @@ def comment
if Raptcha.valid?(params) || BlogSetting.enable_captcha == false
@comment.approved = true unless BlogSetting.manual_moderation
if @comment.save
- flash[:notice] = "Comment was posted successfully! Waiting for approval!"
- @message = @page[:successful_comment]
+ if BlogSetting.manual_moderation
+ flash[:notice] = "Thank you for your comment. It will appear once it has been approved by our moderators."
+ elsif BlogSetting.enable_approve_comment_by_email
+ flash[:notice] = "Thank you for your comment. You have been emailed to approve this comment before it will appear."
+ else
+ flash[:notice] = @page[:successful_comment]
+ end
+
if BlogSetting.enable_email_notification
begin
BlogMailer.deliver_notification(@comment, request)
@@ -66,7 +71,8 @@ def comment
@comment = @blog.comments.new
end
else
- @message = @page[:invalid_comment]
+ @comment.valid?
+ @comment.errors.add_to_base "Captcha is incorrect"
end
present(@page)
@@ -90,10 +96,6 @@ def authorize
protected
def load_blogs
@blogs = Blog.published
-
- if BlogSetting.enable_recent_blogs
- @recent_blogs = Blog.published(:limit => 5)
- end
end
def find_blog
@@ -109,23 +111,9 @@ def find_blog
if BlogSetting.enable_related_authors
@related_authors_blogs = @blog.find_related_authors.reject {|blog| !blog.published? && !@blog }
end
-
- # in show action, the recent blog exclude the currently displayed blog
- if BlogSetting.enable_recent_blogs
- @recent_blogs = Blog.find(:all,
- :limit => 5,
- :conditions => ["id != ? and publishing_date < ? and draft != ?", @blog.id, Time.now, true],
- :order => "publishing_date DESC")
- end
end
end
- def load_tags
- @tags = Blog.published.tag_counts if BlogSetting.enable_tags
- @categories = Blog.published.category_counts if BlogSetting.enable_categories
- @authors = Blog.published.author_counts if BlogSetting.enable_authors
- end
-
def find_page
@page = Page.find_by_link_url("/blog")
end
View
@@ -1,5 +1,7 @@
class Blog < ActiveRecord::Base
+
acts_as_taggable_on :categories, :tags, :authors
+
has_many :comments
named_scope :published, lambda {{:conditions => ["publishing_date < '#{Time.now.to_formatted_s(:db)}' and draft != ?", true],
@@ -9,15 +11,53 @@ class Blog < ActiveRecord::Base
acts_as_indexed :fields => [:title, :permalink, :excerpt, :body],
:index_file => [Rails.root.to_s, "tmp", "index"]
- validates_presence_of :title, :permalink, :excerpt, :body
- validates_uniqueness_of :title, :permalink
+ validates_presence_of :excerpt, :body
+ validates_uniqueness_of :title, :permalink, :case_sensitive => true
validates_format_of :permalink, :with => /^(([-_]|[a-z]|\d){1,100})$/, :message => " is invalid, only lowercase alphanumeric character and _-"
validates_length_of :permalink, :within => 4..99
+ validates_length_of :title, :within => 2..95
+
+ NUM_RECENT_POSTS = 5
+
+ def before_validation
+ self.permalink = title.parameterize if permalink.blank?
+ end
def published?
# A blog post should be published? if:
# the publishing date is before now and it is not a draft blog post.
publishing_date <= Time.now && !draft
end
+
+ def approved_comment_count
+ comments.approved.size
+ end
+
+ def self.grouped_by_date
+ all.group_by { |blog| blog.publishing_date.to_date }.sort {|a,b| b[0] <=> a[0]}
+ end
+
+ def self.tags
+ Blog.published.tag_counts.collect(&:name)
+ end
+
+ def self.categories
+ Blog.published.category_counts.collect(&:name)
+ end
+
+ def self.authors
+ Blog.published.author_counts.collect(&:name)
+ end
+
+ def self.recent_posts
+ Blog.published.first(NUM_RECENT_POSTS)
+ end
+
+ def recent_posts
+ recent_posts = Blog.published(:limit => (NUM_RECENT_POSTS+1))
+ recent_posts.delete(self)
+ recent_posts.first(NUM_RECENT_POSTS)
+ end
+
end
View
@@ -3,20 +3,33 @@ class BlogMailer < ActionMailer::Base
def notification(comment, request)
subject "New comment on #{comment.blog.title}"
recipients BlogSetting.notification_email
- from "\"#{RefinerySetting[:site_name]}\" <no-reply@#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}>"
+ from from_address(request)
sent_on Time.now
body :comment => comment
end
def confirmation(comment, request)
- site_domain = request.domain(RefinerySetting.find_or_set(:tld_length, 1))
- subject "#{RefinerySetting[:site_name]} - comment confirmation"
+ subject "#{site_name} - comment confirmation"
recipients comment.email
- from "\"#{RefinerySetting[:site_name]}\" <no-reply@#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}>"
+ from from_address(request)
sent_on Time.now
content_type "text/html"
body :comment => comment,
- :site_domain => request.domain(RefinerySetting.find_or_set(:tld_length, 1))
+ :site_domain => site_domain(request)
+ end
+
+ protected
+
+ def from_address(request)
+ "\"#{site_name}\" <no-reply@#{site_domain(request)}>"
+ end
+
+ def site_domain(request)
+ @domain ||= request.domain(RefinerySetting.find_or_set(:tld_length, 1))
+ end
+
+ def site_name
+ RefinerySetting[:site_name]
end
end
View
@@ -1,15 +1,14 @@
class Comment < ActiveRecord::Base
belongs_to :blog
- named_scope :unread, :conditions => {:approved => nil}
+ named_scope :unmoderated, :conditions => { :approved => nil }
named_scope :history, :conditions => 'approved IS NOT NULL', :order => "created_at DESC"
named_scope :approved, :conditions => {:approved => true}
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i,
:message => 'must be valid'
- validates_presence_of :name, :email, :body, :title
validates_length_of :name, :email, :title, :within => 3..80
validates_length_of :body, :within => 3..1000
@@ -9,7 +9,7 @@
:title => 'Edit this blog setting' if blog_setting.value.nil? %>
</span>
<strong><%=h blog_setting.name %></strong>
- is set to <strong>"<%=h blog_setting.value.nil? ? blog_setting.entry : blog_setting.value %>"</strong>
+ <%= "is set to <strong>#{h blog_setting.entry}</strong>" if blog_setting.entry %>
<%= link_to '?', edit_admin_blog_setting_path(blog_setting), :title => blog_setting.description %>
<span class="preview">&nbsp;</span>
</span>
@@ -1,10 +1,4 @@
-<div id='actions'>
- <ul>
- <li>
- <%= link_to "Manage Blog", admin_blogs_url, :class => "back_icon" %>
- </li>
- </ul>
-</div>
+<%= render :partial => '/admin/blogs/side_bar' %>
<div id='records'>
<% if @blog_settings.present? and @blog_settings.any? %>
<%= will_paginate @blog_settings, :previous_label => '&laquo;', :next_label => '&raquo;' %>
@@ -10,6 +10,7 @@
:class => "cancel confirm-delete",
:title => 'Remove this blog post forever' %>
</span>
- <%=h truncate blog.title, :length => 60 %> <span class="preview">&nbsp;</span>
+ <%=h truncate blog.title, :length => 60 %>
+ <span class="preview"><%= pluralize blog.approved_comment_count, 'comment' %></span>
</span>
</li>
Oops, something went wrong.

0 comments on commit 78e5dea

Please sign in to comment.