Skip to content

Commit

Permalink
Added comment notifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
parndt committed Nov 15, 2010
1 parent 426c0d9 commit 5b55dc2
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 18 deletions.
12 changes: 12 additions & 0 deletions app/controllers/blog/posts_controller.rb
Expand Up @@ -17,6 +17,18 @@ def show

def comment
if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid?
if BlogComment::Moderation.enabled? or @blog_comment.ham?
begin
if Rails.version < '3.0.0'
Blog::CommentMailer.deliver_notification(@blog_comment, request)
else
Blog::CommentMailer.notification(@blog_comment, request).deliver
end
rescue
logger.warn "There was an error delivering a blog comment notification.\n#{$!}\n"
end
end

if BlogComment::Moderation.enabled?
flash[:notice] = t('blog.posts.comments.thank_you_moderated')
redirect_to blog_post_url(params[:id])
Expand Down
11 changes: 11 additions & 0 deletions app/mailers/blog/comment_mailer.rb
@@ -0,0 +1,11 @@
class Blog::CommentMailer < ActionMailer::Base

def notification(comment, request)
subject BlogComment::Notification.subject
recipients BlogComment::Notification.recipients
from "\"#{RefinerySetting[:site_name]}\" <no-reply@#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}>"
sent_on Time.now
@comment = comment
end

end
1 change: 1 addition & 0 deletions app/models/blog/comment_mailer.rb
@@ -0,0 +1 @@
require File.expand_path('../../../mailers/blog/comment_mailer', __FILE__)
38 changes: 24 additions & 14 deletions app/models/blog_comment.rb
Expand Up @@ -46,7 +46,7 @@ def unmoderated?

before_create do |comment|
unless BlogComment::Moderation.enabled?
comment.state = comment.spam? ? 'rejected' : 'approved'
comment.state = comment.ham? ? 'approved' : 'rejected'
end
end

Expand All @@ -55,17 +55,15 @@ class << self
def enabled?
RefinerySetting.find_or_set(:comment_moderation, true, {
:scoping => :blog,
:restricted => false,
:callback_proc_as_string => nil
:restricted => false
})
end

def toggle!
RefinerySetting[:comment_moderation] = {
:value => !self.enabled?,
:scoping => :blog,
:restricted => false,
:callback_proc_as_string => nil
:restricted => false
}
end
end
Expand All @@ -74,21 +72,33 @@ def toggle!
module Notification
class << self
def recipients
RefinerySetting.find_or_set(:comment_notification_recipients,
(Role[:refinery].users.first.email rescue ''),
{
:scoping => :blog,
:restricted => false,
:callback_proc_as_string => nil
})
RefinerySetting.find_or_set(:comment_notification_recipients, (Role[:refinery].users.first.email rescue ''),
{
:scoping => :blog,
:restricted => false
})
end

def recipients=(emails)
RefinerySetting[:comment_notification_recipients] = {
:value => emails,
:scoping => :blog,
:restricted => false,
:callback_proc_as_string => nil
:restricted => false
}
end

def subject
RefinerySetting.find_or_set(:comment_notification_subject, "New inquiry from your website", {
:scoping => :blog,
:restricted => false
})
end

def subject=(subject_line)
RefinerySetting[:comment_notification_subject] = {
:value => subject_line,
:scoping => :blog,
:restricted => false
}
end
end
Expand Down
17 changes: 17 additions & 0 deletions app/views/blog/comment_mailer/notification.html.erb
@@ -0,0 +1,17 @@
<%= t('.greeting') %>,

<%= t('.you_recieved_new_comment') %>
<%= t('.comment_starts') %>
<%= t('.from') %>: <%= @comment.name %>
<%= t('.email') %>: <%= @comment.email %>
<%= t('.message') %>:
<%= @comment.body %>
<%= t('.comment_ends') %>
<%= t('.closing_line') %>,
<%= RefinerySetting[:site_name] %>
<%= t('.ps') %>
11 changes: 11 additions & 0 deletions config/locales/en.yml
Expand Up @@ -72,6 +72,17 @@ en:
moderation: Moderation
update_notified: Update who gets notified
blog:
comment_mailer:
notification:
greeting: Hi there
you_recieved_new_comment: You just received a new comment on your website.
comment_starts: --- comment starts ---
comment_ends: --- comment ends ---
from: From
email: Email
message: Message
closing_line: Kind Regards
ps: P.S. All your comments are stored in the "Blog" section of Refinery under the "Comments" submenu should you ever want to view it later there.
shared:
categories:
title: Categories
Expand Down
2 changes: 1 addition & 1 deletion lib/refinerycms-blog.rb
Expand Up @@ -42,7 +42,7 @@ def url

class << self
def version
%q{1.0.rc15}
%q{1.0.rc16}
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -11,7 +11,7 @@ Options:

Open up your ``Gemfile`` and add at the bottom this line

gem 'refinerycms-blog', '~> 1.0.rc15'
gem 'refinerycms-blog', '~> 1.0.rc16'

Now run ``bundle install``

Expand Down
11 changes: 9 additions & 2 deletions refinerycms-blog.gemspec
@@ -1,8 +1,8 @@
Gem::Specification.new do |s|
s.name = %q{refinerycms-blog}
s.version = %q{1.0.rc15}
s.version = %q{1.0.rc16}
s.description = %q{A really straightforward open source Ruby on Rails blog engine designed for integration with RefineryCMS.}
s.date = %q{2010-11-12}
s.date = %q{2010-11-15}
s.summary = %q{Ruby on Rails blogging engine for RefineryCMS.}
s.email = %q{info@refinerycms.com}
s.homepage = %q{http://refinerycms.com}
Expand All @@ -24,7 +24,12 @@ Gem::Specification.new do |s|
app/controllers/blog/categories_controller.rb
app/controllers/blog/posts_controller.rb
app/controllers/blog_controller.rb
app/mailers
app/mailers/blog
app/mailers/blog/comment_mailer.rb
app/models
app/models/blog
app/models/blog/comment_mailer.rb
app/models/blog_category.rb
app/models/blog_comment.rb
app/models/blog_post.rb
Expand Down Expand Up @@ -56,6 +61,8 @@ Gem::Specification.new do |s|
app/views/blog
app/views/blog/categories
app/views/blog/categories/show.html.erb
app/views/blog/comment_mailer
app/views/blog/comment_mailer/notification.html.erb
app/views/blog/posts
app/views/blog/posts/_comment.html.erb
app/views/blog/posts/index.html.erb
Expand Down

0 comments on commit 5b55dc2

Please sign in to comment.