public
Description: This contains various plugins for Feather
Clone URL: git://github.com/eldiablo/feather-plugins.git
Search Repo:
Click here to lend your support to: feather-plugins and make a donation at www.pledgie.com !
added in comment settings, such as moderation, and some spam protection in 
the form of negative captcha (e-mail notification setting in, 
functionality to follow); also added caching expiration to the plugins 
that require it
eldiablo (author)
Wed Apr 16 14:18:03 -0700 2008
commit  51b0180d04a43a6eff48612749ef67c783caa934
tree    f6cc89d5edacfbb7f82954ed0323f352a89ee5de
parent  0277d4531788b4628cf570ccb5f6a9e854c05859
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
0
@@ -1 +1,25 @@
0
+module Admin
0
+ class CommentSettings < Base
0
+ include_plugin_views __FILE__
0
+
0
+ def show
0
+ @comment_setting = CommentSetting.current
0
+ display @comment_setting
0
+ end
0
+
0
+ def edit
0
+ @comment_setting = CommentSetting.current
0
+ display @comment_setting
0
+ end
0
+
0
+ def update(comment_setting)
0
+ @comment_setting = CommentSetting.current
0
+ if @comment_setting.update_attributes(comment_setting)
0
+ redirect url(:admin_comment_settings, @comment_setting)
0
+ else
0
+ render :edit
0
+ end
0
+ end
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
0
@@ -1 +1,37 @@
0
+module Admin
0
+ class Comments < Base
0
+ include_plugin_views __FILE__
0
+
0
+ before :find_comment, :only => %w(edit update delete show)
0
+
0
+ def index
0
+ @comments = Comment.all
0
+ display @comments
0
+ end
0
+
0
+ def update
0
+ @comment.published = (params[:published] == "true" ? true : false) if params[:published]
0
+ @comment.save
0
+ expire_index
0
+ expire_article(Article[@comment.article_id])
0
+ render_js
0
+ end
0
+
0
+ def delete
0
+ @comment.destroy!
0
+ expire_index
0
+ expire_article(Article[@comment.article_id])
0
+ redirect url(:admin_comments)
0
+ end
0
+
0
+ def show
0
+ display @comment
0
+ end
0
+
0
+ private
0
+ def find_comment
0
+ @comment = Comment[params[:id]]
0
+ end
0
+ end
0
+end
...
1
2
3
4
5
6
7
 
 
 
 
 
 
 
 
 
8
9
10
...
1
2
 
 
 
 
 
3
4
5
6
7
8
9
10
11
12
13
14
0
@@ -1,10 +1,14 @@
0
 class Comments < Application
0
   def create
0
- @comment = Comment.new(params[:comment])
0
- session[:comment_error] = @comment.errors if !@comment.save
0
- article = Article[@comment.article_id]
0
- expire_index
0
- expire_article(article)
0
+ if (!CommentSetting.current.negative_captcha || params[:comment][:notes].nil? || params[:comment][:notes] == "")
0
+ @comment = Comment.new(params[:comment])
0
+ @comment.ip_address = request.env["REMOTE_HOST"]
0
+ @comment.published = !CommentSetting.current.moderation
0
+ session[:comment_error] = @comment.errors if !@comment.save
0
+ article = Article[@comment.article_id]
0
+ expire_index
0
+ expire_article(article)
0
+ end
0
     redirect article.permalink
0
   end
0
 end
...
 
 
1
2
 
3
4
5
 
 
 
 
6
7
8
9
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
0
@@ -1,10 +1,19 @@
0
+require File.join(File.join(File.join(File.dirname(__FILE__), "controllers"), "admin"), "comments")
0
+require File.join(File.join(File.join(File.dirname(__FILE__), "controllers"), "admin"), "comment_settings")
0
 require File.join(File.join(File.dirname(__FILE__), "controllers"), "comments")
0
 require File.join(File.join(File.dirname(__FILE__), "models"), "comment")
0
+require File.join(File.join(File.dirname(__FILE__), "models"), "comment_setting")
0
 
0
 Merb::Router.prepend do |r|
0
   r.resources :comments
0
+ r.namespace :admin do |admin|
0
+ admin.resources :comments
0
+ admin.resource :comment_settings
0
+ end
0
 end
0
 
0
 Hooks::View.register_partial_view "after_article", "comments"
0
 Hooks::View.register_partial_view "meta_section", "comments"
0
+
0
+Hooks::Menu.add_menu_item "Comments", "/admin/comments"
...
 
 
 
 
 
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
0
@@ -1,2 +1,22 @@
0
+begin
0
+ comments = Comment.all
0
+rescue
0
+ comments = []
0
+end
0
 Database::migrate(Comment)
0
+comments.each do |comment|
0
+ comment.instance_variable_set("@new_record", true)
0
+ comment.save
0
+end
0
+
0
+begin
0
+ comment_settings = CommentSetting.first
0
+rescue
0
+ comment_settings = nil
0
+end
0
+Database::migrate(CommentSetting)
0
+unless comment_settings.nil?
0
+ comment_settings.instance_variable_set("@new_record", true)
0
+ comment_settings.save
0
+end
...
11
12
13
 
 
 
 
14
15
16
 
17
18
 
 
 
 
 
 
 
 
 
 
 
 
19
20
21
...
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
0
@@ -11,11 +11,28 @@
0
         controllers:
0
             .:
0
                 - comments.rb
0
+ admin:
0
+ .:
0
+ - comment_settings.rb
0
+ - comments.rb
0
         models:
0
             .:
0
                 - comment.rb
0
+ - comment_setting.rb
0
         views:
0
             .:
0
+ admin:
0
+ .:
0
+ comment_settings:
0
+ .:
0
+ - edit.html.erb
0
+ - show.html.erb
0
+ comments:
0
+ .:
0
+ - _comment.html.erb
0
+ - index.html.erb
0
+ - show.html.erb
0
+ - update.js.erb
0
             after_post:
0
                 .:
0
                     - _comments.html.erb
...
6
7
8
 
 
9
10
11
12
13
 
 
14
15
 
16
17
 
 
 
 
 
18
...
6
7
8
9
10
11
12
13
14
15
16
17
18
 
19
20
21
22
23
24
25
26
27
0
@@ -6,14 +6,23 @@
0
   property :created_at, :datetime
0
   property :email_address, :string
0
   property :formatter, :string, :default => "default"
0
+ property :ip_address, :string, :default => "127.0.0.1"
0
+ property :published, :boolean, :default => true
0
   
0
   validates_presence_of :name, :comment, :article_id
0
   
0
   belongs_to :article
0
   
0
+ after_save :fire_after_comment_event
0
+
0
   def self.all_for_post(article_id, method = :all)
0
- self.send(method, {:article_id => article_id, :, :order => "created_at"})
0
+ self.send(method, {:article_id => article_id, :published => true, :order => "created_at"})
0
   end
0
 
0
+ ##
0
+ # This provides an event hook for other plugins to use (if they detect the comments plugin is installed), and they can then pick up on the comment being saved
0
+ def fire_after_comment_event
0
+ Hooks::Events.run_event(:after_comment, self)
0
+ end
0
 end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
0
@@ -1 +1,14 @@
0
+class CommentSetting < DataMapper::Base
0
+ property :moderation, :boolean, :default => false
0
+ property :negative_captcha, :boolean, :default => false
0
+ property :email_notification, :boolean, :default => false
0
+
0
+ ##
0
+ # This returns the current settings, creating them if they aren't found
0
+ def self.current
0
+ comment_settings = CommentSetting.first
0
+ comment_settings = CommentSetting.create(:moderation => false, :negative_captcha => false, :email_notification => false) if comment_settings.nil?
0
+ comment_settings
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
0
@@ -1 +1,45 @@
0
+<% throw_content :right do %>
0
+ <h4>Comment Settings</h4>
0
+ Update the comment settings for this blog.
0
+ <br />
0
+ <ul>
0
+ <li>
0
+ <strong>Moderation</strong>
0
+ <br />
0
+ With moderation turned on, no comments that are posted are published and visible until you manually set them to be.
0
+ </li>
0
+ <li>
0
+ <strong>Negative Captcha</strong>
0
+ <br />
0
+ With negative captcha turned on, an extra form field is added, but made invisible - a "honeypot". If this has any data set, it is most likely a spam bot making the request, and it is ignored.
0
+ </li>
0
+ <li>
0
+ <strong>E-mail Notification</strong>
0
+ <br />
0
+ With e-mail notification turned on, you will receive an e-mail notification each time a comment is posted to your blog.
0
+ </li>
0
+ </ul>
0
+<% end %>
0
+
0
+<%= error_messages_for @comment_setting %>
0
+<h1>Edit comment settings</h1>
0
+
0
+<% form_for :comment_setting, :action => url(:admin_comment_settings, @comment_setting), :method => :put do %>
0
+ <p>
0
+ <span class="mock_label">Moderation</span>
0
+ <%= checkbox_control :moderation, :value => @comment_setting.moderation %>
0
+ </p>
0
+
0
+ <p>
0
+ <span class="mock_label">Negative Captcha</span>
0
+ <%= checkbox_control :negative_captcha, :value => @comment_setting.negative_captcha %>
0
+ </p>
0
+
0
+ <p>
0
+ <span class="mock_label">E-mail Notification</span>
0
+ <%= checkbox_control :email_notification, :value => @comment_setting.email_notification %>
0
+ </p>
0
+
0
+ <%= submit_button 'Save Settings' %> or <%= link_to 'Cancel', url(:admin_comment_settings) %>
0
+<% end %>
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
0
@@ -1 +1,29 @@
0
+<% throw_content :right do %>
0
+ <h4>View Comment Settings</h4>
0
+ <p>
0
+ Here you can view comment settings.
0
+ <br />
0
+ <%= link_to "View comments", url(:admin_comments) %>
0
+ </p>
0
+<% end %>
0
+
0
+<h1>View Comment Settings</h1>
0
+
0
+<p>
0
+ Moderation:
0
+ <%= @comment_setting.moderation %>
0
+</p>
0
+
0
+<p>
0
+ Negative Captcha:
0
+ <%= @comment_setting.negative_captcha %>
0
+</p>
0
+
0
+<p>
0
+ E-mail Notification:
0
+ <%= @comment_setting.email_notification %>
0
+</p>
0
+
0
+<%= link_to "Edit comment settings", url(:edit_admin_comment_settings, @comment_setting) %> |
0
+<%= link_to "View comments", url(:admin_comments) %>
...
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
0
@@ -1 +1,8 @@
0
+<tr>
0
+ <td><%= link_to comment.name, url(:admin_comment, comment) %></td>
0
+ <td><%= comment.website %></td>
0
+ <td><%= comment.email_address %></td>
0
+ <td><%= comment.ip_address %></td>
0
+ <td><%= link_to 'Delete', url(:delete_admin_comment, comment), {:method => :delete, :onclick => "return confirm('Are you sure?')"} %></td>
0
+</tr>
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
0
@@ -1 +1,24 @@
0
+<% throw_content :right do %>
0
+ <h4>View Comments</h4>
0
+ <p>
0
+ Comments are left on your blog by visitors.
0
+ <br />
0
+ <%= link_to "View comment settings", url(:admin_comment_settings) %>
0
+ </p>
0
+<% end %>
0
+
0
+<h1>View Comments</h1>
0
+
0
+<table>
0
+ <tr>
0
+ <th>Name</th>
0
+ <th>Website</th>
0
+ <th>E-mail address</th>
0
+ <th>IP address</th>
0
+ <th>&nbsp;</th>
0
+ </tr>
0
+ <%= partial('admin/comments/comment', :with => @comments) %>
0
+</table>
0
+<br />
0
+<%= link_to "View comment settings", url(:admin_comment_settings) %>
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
0
@@ -1 +1,71 @@
0
+<% throw_content :right do %>
0
+ <h4>View Comment</h4>
0
+ <p>
0
+ Here you can view the details of an existing comment.
0
+ </p>
0
+<% end %>
0
+
0
+<script lang="text/javascript">
0
+var Comments = {
0
+ publish: function(id) {
0
+ new Ajax.Request("/admin/comments/" + id + "?published=true", {
0
+ asynchronous:'true',
0
+ evalScripts:'true',
0
+ method:'put',
0
+ onLoading: function() {
0
+ $('comment-published').hide();
0
+ $('comment-display').innerText = "Saving..."
0
+ },
0
+ onFailure: function() { alert('Something went wrong...') },
0
+ });
0
+ },
0
+
0
+ unpublish: function(id) {
0
+ new Ajax.Request("/admin/comments/" + id + "?published=false", {
0
+ asynchronous:'true',
0
+ evalScripts:'true',
0
+ method:'put',
0
+ onLoading: function() {
0
+ $('comment-unpublished').hide();
0
+ $('comment-display').innerText = "Saving..."
0
+ },
0
+ onFailure: function() { alert('Something went wrong...') },
0
+ });
0
+ }
0
+}
0
+</script>
0
+
0
+<h1>View Comment</h1>
0
+
0
+<p>
0
+ Name: <%= @comment.name %>
0
+</p>
0
+
0
+<p>
0
+ Website: <%= @comment.website %>
0
+</p>
0
+
0
+<p>
0
+ E-mail address: <%= @comment.email_address %>
0
+</p>
0
+
0
+<p>
0
+ Comment:
0
+ <br />
0
+ <%= render_text(@comment.formatter, @comment.comment) %>
0
+</p>
0
+
0
+<p>
0
+ <div id="comment_published" style="display: <%= @comment.published ? 'block' : 'none' %>;">
0
+ Published
0
+ <a href="#" id="comment_unpublish" onclick="Comments.unpublish(<%= @comment.id %>);">Click to unpublish</a>
0
+ </div>
0
+ <div id="comment_unpublished" style="display: <%= @comment.published ? 'none' : 'block' %>;">
0
+ Isn't published
0
+ <a href="#" id="comment_publish" onclick="Comments.publish(<%= @comment.id %>);">Click to publish</a>
0
+ </div>
0
+ <div id="comment_display"></div>
0
+</p>
0
+
0
+<%= link_to "Back to comments", url(:admin_comments) %>
...
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
0
@@ -1 +1,8 @@
0
+<% if @comment.published %>
0
+ $('comment_published').show();
0
+ $('comment_unpublished').hide();
0
+<% else %>
0
+ $('comment_published').hide();
0
+ $('comment_unpublished').show();
0
+<% end %>
...
29
30
31
 
 
 
 
 
 
32
33
34
...
29
30
31
32
33
34
35
36
37
38
39
40
0
@@ -29,6 +29,12 @@
0
     <fieldset>
0
       <legend>Comment</legend>
0
       <%= hidden_field :name => "comment[article_id]", :value => @article.id %>
0
+ <% if CommentSetting.current.negative_captcha %>
0
+ <%= text_field :name => "comment[notes]", :id => "comment_notes" %>
0
+ <script type="text/javascript">
0
+ document.getElementById('comment_notes').style.display = "none";
0
+ </script>
0
+ <% end %>
0
       <p>
0
         <label for="comment_name" class="text">Name:<label>
0
         <%= text_field :name => 'comment[name]', :size => 30, :id => 'comment_name' %>
...
5
6
7
 
 
8
9
10
...
5
6
7
8
9
10
11
12
0
@@ -5,6 +5,8 @@
0
 require File.join(File.join(File.dirname(__FILE__), "helpers"), "global_helpers")
0
 require File.join(File.join(File.dirname(__FILE__), "models"), "feed_setting")
0
 
0
+include Merb::GlobalHelpers
0
+
0
 Merb::Router.prepend do |r|
0
   r.match("/articles.rss").to(:controller => "Feeds", :action => "articles")
0
   r.match("/rss").to(:controller => "Feeds", :action => "articles")
...
17
18
19
 
20
21
22
...
29
30
31
 
32
33
34
...
37
38
39
 
40
41
42
...
17
18
19
20
21
22
23
...
30
31
32
33
34
35
36
...
39
40
41
42
43
44
45
0
@@ -17,6 +17,7 @@
0
     def create(snippet)
0
       @snippet = Snippet.new(snippet)
0
       if @snippet.save
0
+ expire_all_pages
0
         redirect url(:admin_snippet)
0
       else
0
         render :new
0
@@ -29,6 +30,7 @@
0
     
0
     def update(snippet)
0
       if @snippet.update_attributes(snippet)
0
+ expire_all_pages
0
         redirect url(:admin_snippet, @snippet)
0
       else
0
         render :edit
0
@@ -37,6 +39,7 @@
0
     
0
     def delete
0
       @snippet.destroy!
0
+ expire_all_pages
0
       redirect url(:admin_snippets)
0
     end
0
     
...
1
2
3
 
4
...
1
2
 
3
4
0
@@ -1,5 +1,5 @@
0
 <tr>
0
   <td><%= link_to snippet.location, url(:admin_snippet, snippet) %></td>
0
- <td <%= link_to "Edit", url(:edit_admin_snippet, snippet) %> | <%= link_to 'Delete', url(:delete_admin_snippet, snippet), {:method => :delete, :onclick => "return confirm('Are you sure?')"} %></td>
0
+ <td><%= link_to "Edit", url(:edit_admin_snippet, snippet) %> | <%= link_to 'Delete', url(:delete_admin_snippet, snippet), {:method => :delete, :onclick => "return confirm('Are you sure?')"} %></td>
0
 </tr>
...
17
18
19
 
20
21
22
...
29
30
31
 
32
33
34
...
37
38
39
 
40
41
42
...
17
18
19
20
21
22
23
...
30
31
32
33
34
35
36
...
39
40
41
42
43
44
45
0
@@ -17,6 +17,7 @@
0
     def create(style)
0
       @style = Style.new(style)
0
       if @style.save
0
+ expire_all_pages
0
         redirect url(:admin_style)
0
       else
0
         render :new
0
@@ -29,6 +30,7 @@
0
     
0
     def update(style)
0
       if @style.update_attributes(style)
0
+ expire_all_pages
0
         redirect url(:admin_style, @style)
0
       else
0
         render :edit
0
@@ -37,6 +39,7 @@
0
     
0
     def delete
0
       @style.destroy!
0
+ expire_all_pages
0
       redirect url(:admin_styles)
0
     end
0
     
...
1
2
3
 
4
...
1
2
 
3
4
0
@@ -1,5 +1,5 @@
0
 <tr>
0
   <td><%= link_to style.name, url(:admin_style, style) %></td>
0
- <td <%= link_to "Edit", url(:edit_admin_style, style) %> | <%= link_to 'Delete', url(:delete_admin_style, style), {:method => :delete, :onclick => "return confirm('Are you sure?')"} %></td>
0
+ <td><%= link_to "Edit", url(:edit_admin_style, style) %> | <%= link_to 'Delete', url(:delete_admin_style, style), {:method => :delete, :onclick => "return confirm('Are you sure?')"} %></td>
0
 </tr>
...
7
8
9
 
 
10
11
12
13
14
15
 
16
17
18
...
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
0
@@ -7,12 +7,15 @@
0
 # This reopens the global_helpers module, and adds the tag cloud stuff.
0
 require File.join(File.join(File.dirname(__FILE__), "lib"), "global_helpers")
0
 
0
+include Merb::Cache::ControllerInstanceMethods
0
+
0
 Merb::Router.prepend do |r|
0
   r.match('/tags/:id').to(:controller => 'tags', :action =>'show').name(:tag)
0
 end
0
 
0
 Hooks::Events.register_event(:after_save_article) do |args|
0
   args.first.create_tags
0
+ expire_all_pages
0
 end
0
 
0
 Hooks::View.register_partial_view "article_form_fields", "tag_field"

Comments

    No one has commented yet.