Permalink
Browse files

Initial cleanup and update to work with Radiant 0.6.7

  • Loading branch information...
1 parent 1eea36f commit c89a61b05225dd90294ee31a8f3f145ea1822533 @ntalbott ntalbott committed May 23, 2008
View
15 README
@@ -1,9 +1,5 @@
= Radiant Comments Extension
-== WARNING
-
-This extension is incompatible with the latest version of the Shards extension. Use at your own risk. If you get it working, PLEASE SUBMIT A PATCH!
-
Adds blog-like comment functionality to Radiant.
== Patches
@@ -12,8 +8,7 @@ This software "works for me", but it may not work for you, depending on your par
== Dependencies
-* Requires Radiant 0.6.1 or greater.
-* Requires the Shards extension (http://dev.radiantcms.org/svn/radiant/trunk/extensions/shards)
+* Requires Radiant 0.6.7 or greater.
* Requires will_paginate Rails plugin (svn://errtheblog.com/svn/plugins/will_paginate)
== Usage
@@ -22,13 +17,7 @@ Remember to run the migration. This _WILL_ delete any snippets named 'comment',
rake radiant:extensions:comments:migrate
-The Shards extension must be loaded before Comments. To do this, add the following line to config/environment.rb:
-
- config.extensions = [ :shards, :all ]
-
-To enable spam protection, you will need to add your Akismet key to app/models/comments.rb:
-
- @akismet = Akismet.new('enter-your-key-here', 'enter-your-domain-here')
+To enable spam protection, you will need to set your Akismet key and url in the Radiant config.
=== In your layout:
View
2 TODO
@@ -1,7 +1,6 @@
= TODO:
* Write Tests.
-* Email administrator when a comment is posted.
* Handle validation messages.
* Add user notification message when a comment is posted.
@@ -10,4 +9,3 @@
* Add text filter to comment body.
* Remove scaffolding and improve admin interface.
* Implement Akismet filter.
-* Validate inputs and -handle error messages-.
@@ -45,7 +45,7 @@ def update
def enable
@page = Page.find(params[:page_id])
@page.enable_comments = 1
- @page.update
+ @page.save!
flash[:notice] = "Comments has been enabled for #{@page.title}"
redirect_to page_index_path
end
@@ -1,2 +0,0 @@
-class Admin::PageController < ApplicationController
-end
@@ -1,2 +0,0 @@
-class ApplicationController < ActionController::Base
-end
@@ -1,29 +1,22 @@
class CommentsController < ApplicationController
no_login_required
-
+ skip_before_filter :verify_authenticity_token
+
def create
@page = Page.find(params[:page_id])
-
- @comment = Comment.new do |c|
- c.page = @page
- c.author = params[:comment][:author]
- c.author_email = params[:comment][:author_email]
- c.author_url = params[:comment][:author_url]
- c.content = params[:comment][:content]
- c.filter_id = params[:comment][:filter_id]
- c.request = request
- end
+ @comment = @page.comments.build(params[:comment])
+ @comment.request = request
TextFilter.descendants.each do |filter|
@comment.content_html = filter.filter(@comment.content) if filter.filter_name == @comment.filter_id
end
if !@comment.is_spam?
@comment.save
- # ResponseCache.instance.clear #expire_response(page.url)
- CommentMailer.deliver_comment_notification
+ ResponseCache.instance.clear
+ CommentMailer.deliver_comment_notification if Radiant::Config['comments.notification'] == "true"
end
redirect_to "#{@page.url}#comment_#{@comment.id}" and return
View
@@ -14,23 +14,23 @@ def request=(request)
# Akismet Spam Filter
# Marks a content item as spam unless it checks out with Akismet
- def is_spam?
- # You'll need to get your own Akismet API key from www.akismet.com
- @akismet = Akismet.new('123456789', 'http://yourblog.wordpress.com')
- return nil unless @akismet.verifyAPIKey
-
- return true if @akismet.commentCheck(
- self.author_ip, # remote IP
- self.user_agent, # user agent
- self.referrer, # http referer
- self.page.url, # permalink
- 'comment', # comment type
- self.author, # author name
- self.author_email, # author email
- self.author_url, # author url
- self.content, # comment text
- {}) # other
- return false
+ def is_spam?
+ akismet = Akismet.new(Radiant::Config['comments.akismet_key'], Radiant::Config['comments.akismet_url'])
+ if akismet.valid?
+ akismet.commentCheck(
+ self.author_ip, # remote IP
+ self.user_agent, # user agent
+ self.referrer, # http referer
+ self.page.url, # permalink
+ 'comment', # comment type
+ self.author, # author name
+ self.author_email, # author email
+ self.author_url, # author url
+ self.content, # comment text
+ {}) # other
+ else
+ nil
+ end
end
def approved?
@@ -1,11 +1,9 @@
- <td class="comment_link"><small>
-
- <% if page.enable_comments %>
- <%= link_to "#{page.comments_count} comments", admin_page_comments_path(:page_id => page.id) %>
-
- <% else %>
- <%= link_to "Enable", admin_page_comments_path(:page_id => page.id, :action => :enable) %>
- <% end %>
-
-
- </small></td>
+<td class="comment_link">
+ <small>
+ <% if page.enable_comments %>
+ <%= link_to "#{page.comments_count} comments", admin_page_comments_path(:page_id => page.id) %>
+ <% else %>
+ <%= link_to "Enable", admin_page_comments_path(:page_id => page.id, :action => :enable) %>
+ <% end %>
+ </small>
+</td>
View
@@ -10,8 +10,8 @@ class CommentsExtension < Radiant::Extension
map.resources :comments, :path_prefix => "/pages/:page_id", :controller => "comments" # Regular routes for comments
map.with_options(:controller => 'admin/comments') do |comments|
comments.resources :comments, :path_prefix => "/admin", :name_prefix => "admin_", :member => {:approve => :get, :unapprove => :get} # Admin routes for comments
- comments.admin_page_comments 'admin/pages/:page_id/comments;:action' # This route allows us to nicely pull up comments for a particular page
- comments.admin_page_comment 'admin/pages/:page_id/comments/:id;:action' # This route pulls up a particular comment for a particular page
+ comments.admin_page_comments 'admin/pages/:page_id/comments/:action' # This route allows us to nicely pull up comments for a particular page
+ comments.admin_page_comment 'admin/pages/:page_id/comments/:id/:action' # This route pulls up a particular comment for a particular page
end
end
@@ -27,11 +27,18 @@ def activate
if admin.respond_to? :page
admin.page.edit.add :parts_bottom, "edit_comments_enabled", :before => "edit_timestamp"
- # admin.page.index.add :sitemap_head, "index_head_view_comments"
- # admin.page.index.add :node_row, "index_view_comments"
+ admin.page.index.add :sitemap_head, "index_head_view_comments"
+ admin.page.index.add :node, "index_view_comments"
end
admin.tabs.add "Comments", "/admin/comments?status=unapproved", :visibility => [:all]
+
+ { 'notification' => 'false',
+ 'notification_from' => '',
+ 'notification_to' => '',
+ 'akismet_key' => '',
+ 'akismet_url' => '',
+ }.each{|k,v| Radiant::Config.create(:key => "comments.#{k}", :value => v) unless Radiant::Config["comments.#{k}"]}
end
def deactivate
View
@@ -17,13 +17,6 @@ class Akismet
'Content-Type' => 'application/x-www-form-urlencoded'
}
- # Instance variables
- @apiKey
- @blog
- @verifiedKey
- @proxyPort = nil
- @proxyHost = nil
-
# Create a new instance of the Akismet class
#
# apiKey
@@ -33,7 +26,6 @@ class Akismet
def initialize(apiKey, blog)
@apiKey = apiKey
@blog = blog
- @verifiedKey = false
end
# Set proxy information
@@ -46,23 +38,22 @@ def setProxy(proxyHost, proxyPort)
@proxyPort = proxyPort
@proxyHost = proxyHost
end
+
+ def valid?
+ (!@apiKey.blank? && !@blog.blank? && verifyAPIKey)
+ end
- # Call to check and verify your API key. You may then call the #hasVerifiedKey method to see if your key has been validated.
+ # Call to check and verify your API key.
def verifyAPIKey
http = Net::HTTP.new('rest.akismet.com', 80, @proxyHost, @proxyPort)
path = '/1.1/verify-key'
data="key=#{@apiKey}&blog=#{@blog}"
resp, data = http.post(path, data, STANDARD_HEADERS)
- @verifiedKey = (data == "valid")
+ (data == "valid")
end
- # Returns <tt>true</tt> if the API key has been verified, <tt>false</tt> otherwise
- def hasVerifiedKey()
- return @verifiedKey
- end
-
# Internal call to Akismet. Prepares the data for posting to the Akismet service.
#
# akismet_function

0 comments on commit c89a61b

Please sign in to comment.