aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/blog/posts_controller.rb12
-rw-r--r--app/mailers/blog/comment_mailer.rb11
-rw-r--r--app/models/blog/comment_mailer.rb1
-rw-r--r--app/models/blog_comment.rb38
-rw-r--r--app/views/blog/comment_mailer/notification.html.erb17
5 files changed, 65 insertions, 14 deletions
diff --git a/app/controllers/blog/posts_controller.rb b/app/controllers/blog/posts_controller.rb
index ee707ed..1d8a0b5 100644
--- a/app/controllers/blog/posts_controller.rb
+++ b/app/controllers/blog/posts_controller.rb
@@ -17,6 +17,18 @@ class Blog::PostsController < BlogController
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])
diff --git a/app/mailers/blog/comment_mailer.rb b/app/mailers/blog/comment_mailer.rb
new file mode 100644
index 0000000..3e4c76d
--- /dev/null
+++ b/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
diff --git a/app/models/blog/comment_mailer.rb b/app/models/blog/comment_mailer.rb
new file mode 100644
index 0000000..dac526d
--- /dev/null
+++ b/app/models/blog/comment_mailer.rb
@@ -0,0 +1 @@
+require File.expand_path('../../../mailers/blog/comment_mailer', __FILE__) \ No newline at end of file
diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb
index 201f75c..b888e35 100644
--- a/app/models/blog_comment.rb
+++ b/app/models/blog_comment.rb
@@ -46,7 +46,7 @@ class BlogComment < ActiveRecord::Base
before_create do |comment|
unless BlogComment::Moderation.enabled?
- comment.state = comment.spam? ? 'rejected' : 'approved'
+ comment.state = comment.ham? ? 'approved' : 'rejected'
end
end
@@ -55,8 +55,7 @@ class BlogComment < ActiveRecord::Base
def enabled?
RefinerySetting.find_or_set(:comment_moderation, true, {
:scoping => :blog,
- :restricted => false,
- :callback_proc_as_string => nil
+ :restricted => false
})
end
@@ -64,8 +63,7 @@ class BlogComment < ActiveRecord::Base
RefinerySetting[:comment_moderation] = {
:value => !self.enabled?,
:scoping => :blog,
- :restricted => false,
- :callback_proc_as_string => nil
+ :restricted => false
}
end
end
@@ -74,21 +72,33 @@ class BlogComment < ActiveRecord::Base
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
diff --git a/app/views/blog/comment_mailer/notification.html.erb b/app/views/blog/comment_mailer/notification.html.erb
new file mode 100644
index 0000000..b75020d
--- /dev/null
+++ b/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') %>