radiant-comments-extension 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -1
- data/CHANGELOG +6 -0
- data/Gemfile +4 -0
- data/README.rdoc +9 -0
- data/Rakefile +0 -16
- data/TODO +0 -1
- data/app/controllers/admin/comments_controller.rb +1 -5
- data/app/controllers/comments_controller.rb +46 -4
- data/app/models/akismet_spam_filter.rb +1 -1
- data/app/models/comment.rb +7 -1
- data/app/models/mollom_spam_filter.rb +17 -7
- data/app/models/spam_filter.rb +1 -0
- data/app/views/admin/comments/_comment.html.haml +26 -0
- data/app/views/admin/comments/_form.html.haml +37 -0
- data/app/views/admin/comments/edit.html.haml +4 -0
- data/app/views/admin/comments/index.html.haml +57 -0
- data/app/views/admin/pages/{_comments.rhtml → _comments.html.haml} +0 -0
- data/app/views/admin/pages/_edit_comments_enabled.html.haml +7 -0
- data/app/views/admin/pages/_index_head_view_comments.html.haml +1 -0
- data/app/views/admin/pages/_index_view_comments.html.haml +7 -0
- data/comments_extension.rb +11 -27
- data/config/locales/en.yml +26 -0
- data/config/locales/nl.yml +26 -0
- data/config/routes.rb +16 -0
- data/db/migrate/002_create_snippets.rb +4 -4
- data/lib/comment_page_extensions.rb +15 -2
- data/lib/comment_tags.rb +55 -0
- data/lib/radiant-comments-extension.rb +2 -0
- data/lib/radiant-comments-extension/version.rb +3 -0
- data/public/stylesheets/admin/comments.css +21 -29
- data/radiant-comments-extension.gemspec +8 -117
- data/spec/controllers/page_postback_spec.rb +2 -1
- data/spec/models/comment_spec.rb +7 -23
- data/spec/models/mollom_spam_filter_spec.rb +5 -0
- metadata +30 -32
- data/VERSION +0 -1
- data/app/views/admin/comments/_comment.rhtml +0 -34
- data/app/views/admin/comments/_form.rhtml +0 -36
- data/app/views/admin/comments/edit.rhtml +0 -5
- data/app/views/admin/comments/index.rhtml +0 -55
- data/app/views/admin/pages/_edit_comments_enabled.rhtml +0 -8
- data/app/views/admin/pages/_index_head_view_comments.rhtml +0 -1
- data/app/views/admin/pages/_index_view_comments.rhtml +0 -11
- data/app/views/comments/_comment.rhtml +0 -1
- data/app/views/comments/_form.rhtml +0 -23
- data/app/views/comments/_new.rhtml +0 -5
- data/lib/mollom.rb +0 -246
@@ -65,6 +65,11 @@ describe MollomSpamFilter do
|
|
65
65
|
MollomSpamFilter.should be_approved(@comment)
|
66
66
|
end
|
67
67
|
|
68
|
+
it "should not be approved when the API is unreachable" do
|
69
|
+
@mollom.stub!(:check_content).and_raise(TimeoutError)
|
70
|
+
MollomSpamFilter.should_not be_approved(@comment)
|
71
|
+
end
|
72
|
+
|
68
73
|
it "should cache the Mollom server list after a successful response" do
|
69
74
|
Rails.cache.should_receive(:write).with('MOLLOM_SERVER_CACHE', anything())
|
70
75
|
MollomSpamFilter.should be_approved(@comment)
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiant-comments-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Jim Gay
|
@@ -28,21 +29,10 @@ autorequire:
|
|
28
29
|
bindir: bin
|
29
30
|
cert_chain: []
|
30
31
|
|
31
|
-
date: 2010-
|
32
|
+
date: 2010-10-11 00:00:00 -04:00
|
32
33
|
default_executable:
|
33
|
-
dependencies:
|
34
|
-
|
35
|
-
name: radiant
|
36
|
-
prerelease: false
|
37
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 0
|
43
|
-
version: "0"
|
44
|
-
type: :development
|
45
|
-
version_requirements: *id001
|
34
|
+
dependencies: []
|
35
|
+
|
46
36
|
description: Adds blog-like comment functionality to Radiant.
|
47
37
|
email: jim@saturnflyer.com
|
48
38
|
executables: []
|
@@ -55,13 +45,13 @@ extra_rdoc_files:
|
|
55
45
|
files:
|
56
46
|
- .gitignore
|
57
47
|
- CHANGELOG
|
48
|
+
- Gemfile
|
58
49
|
- HELP_admin.markdown
|
59
50
|
- HELP_designer.markdown
|
60
51
|
- MIT-LICENSE
|
61
52
|
- README.rdoc
|
62
53
|
- Rakefile
|
63
54
|
- TODO
|
64
|
-
- VERSION
|
65
55
|
- app/controllers/admin/comments_controller.rb
|
66
56
|
- app/controllers/comments_controller.rb
|
67
57
|
- app/helpers/admin/comments_helper.rb
|
@@ -71,20 +61,20 @@ files:
|
|
71
61
|
- app/models/mollom_spam_filter.rb
|
72
62
|
- app/models/simple_spam_filter.rb
|
73
63
|
- app/models/spam_filter.rb
|
74
|
-
- app/views/admin/comments/_comment.
|
75
|
-
- app/views/admin/comments/_form.
|
76
|
-
- app/views/admin/comments/edit.
|
77
|
-
- app/views/admin/comments/index.
|
78
|
-
- app/views/admin/pages/_comments.
|
79
|
-
- app/views/admin/pages/_edit_comments_enabled.
|
80
|
-
- app/views/admin/pages/_index_head_view_comments.
|
81
|
-
- app/views/admin/pages/_index_view_comments.
|
64
|
+
- app/views/admin/comments/_comment.html.haml
|
65
|
+
- app/views/admin/comments/_form.html.haml
|
66
|
+
- app/views/admin/comments/edit.html.haml
|
67
|
+
- app/views/admin/comments/index.html.haml
|
68
|
+
- app/views/admin/pages/_comments.html.haml
|
69
|
+
- app/views/admin/pages/_edit_comments_enabled.html.haml
|
70
|
+
- app/views/admin/pages/_index_head_view_comments.html.haml
|
71
|
+
- app/views/admin/pages/_index_view_comments.html.haml
|
82
72
|
- app/views/comment_mailer/comment_notification.rhtml
|
83
|
-
- app/views/comments/_comment.rhtml
|
84
|
-
- app/views/comments/_form.rhtml
|
85
|
-
- app/views/comments/_new.rhtml
|
86
73
|
- autotest/discover.rb
|
87
74
|
- comments_extension.rb
|
75
|
+
- config/locales/en.yml
|
76
|
+
- config/locales/nl.yml
|
77
|
+
- config/routes.rb
|
88
78
|
- cucumber.yml
|
89
79
|
- db/migrate/001_create_comments.rb
|
90
80
|
- db/migrate/002_create_snippets.rb
|
@@ -98,8 +88,8 @@ files:
|
|
98
88
|
- lib/akismet.rb
|
99
89
|
- lib/comment_page_extensions.rb
|
100
90
|
- lib/comment_tags.rb
|
101
|
-
- lib/mollom.rb
|
102
91
|
- lib/radiant-comments-extension.rb
|
92
|
+
- lib/radiant-comments-extension/version.rb
|
103
93
|
- lib/tasks/comments_extension_tasks.rake
|
104
94
|
- public/images/admin/accept.png
|
105
95
|
- public/images/admin/comment_edit.png
|
@@ -140,23 +130,29 @@ rdoc_options:
|
|
140
130
|
require_paths:
|
141
131
|
- lib
|
142
132
|
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
143
134
|
requirements:
|
144
135
|
- - ">="
|
145
136
|
- !ruby/object:Gem::Version
|
137
|
+
hash: 3
|
146
138
|
segments:
|
147
139
|
- 0
|
148
140
|
version: "0"
|
149
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
none: false
|
150
143
|
requirements:
|
151
144
|
- - ">="
|
152
145
|
- !ruby/object:Gem::Version
|
146
|
+
hash: 23
|
153
147
|
segments:
|
154
|
-
-
|
155
|
-
|
148
|
+
- 1
|
149
|
+
- 3
|
150
|
+
- 6
|
151
|
+
version: 1.3.6
|
156
152
|
requirements: []
|
157
153
|
|
158
154
|
rubyforge_project:
|
159
|
-
rubygems_version: 1.3.
|
155
|
+
rubygems_version: 1.3.7
|
160
156
|
signing_key:
|
161
157
|
specification_version: 3
|
162
158
|
summary: Comments Extension for Radiant CMS
|
@@ -171,7 +167,9 @@ test_files:
|
|
171
167
|
- spec/models/mollom_spam_filter_spec.rb
|
172
168
|
- spec/models/simple_spam_filter_spec.rb
|
173
169
|
- spec/models/spam_filter_spec.rb
|
170
|
+
- spec/spec.opts
|
174
171
|
- spec/spec_helper.rb
|
172
|
+
- test/fixtures/users.yml
|
175
173
|
- test/integration/comment_enabling_test.rb
|
176
174
|
- test/test_helper.rb
|
177
175
|
- test/unit/comment_test.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.6
|
@@ -1,34 +0,0 @@
|
|
1
|
-
<tr id="<%= dom_id(comment) %>" class="comment<%= " approved" if comment.approved? %>">
|
2
|
-
<td class="content" <% if comment.content.size >= 70 -%>title="Click to toggle complete text"<% end-%>>
|
3
|
-
<blockquote class="short"><%= escape_once(truncate(comment.content, :length => 70)) %></blockquote>
|
4
|
-
<% if comment.content.size >= 70 %>
|
5
|
-
<blockquote class="expanded" style="display:none"><%= escape_once(comment.content) %></blockquote>
|
6
|
-
<% end %>
|
7
|
-
</td>
|
8
|
-
<td class="date">
|
9
|
-
<%= comment.created_at.strftime("%b %e, %Y at %I:%M%p") %>
|
10
|
-
</td>
|
11
|
-
<td class="author">
|
12
|
-
by <%= escape_once(comment.author) %>
|
13
|
-
<% unless comment.author_email.blank? %><%= mail_to(comment.author_email, image_tag("admin/email.png"))%><% end %>
|
14
|
-
<% unless comment.author_url.blank? %><%= link_to(image_tag("admin/link.png"), comment.author_url) %><% end %>
|
15
|
-
</td>
|
16
|
-
<% unless @page %>
|
17
|
-
<td class="page">
|
18
|
-
on
|
19
|
-
<%= link_to truncate(comment.page.title, :length => 40), comment.page.url, :class => 'view-page' %>
|
20
|
-
<%= link_to image_tag("admin/page_white_edit.png"),
|
21
|
-
edit_admin_page_path(comment.page), :title => "Edit page" %>
|
22
|
-
</td>
|
23
|
-
<% end %>
|
24
|
-
<td class="controls">
|
25
|
-
<%= link_to(image_tag('admin/accept.png'), approve_admin_comment_path(comment),
|
26
|
-
:title => "Approve comment", :method => :put) unless comment.approved? %>
|
27
|
-
<%= link_to(image_tag('admin/error.png'), unapprove_admin_comment_path(comment),
|
28
|
-
:method => :put, :title => "Unapprove comment") if comment.approved? %>
|
29
|
-
<%= link_to image_tag("admin/delete.png"), admin_comment_path(comment),
|
30
|
-
:method => :delete, :confirm => "Are you sure you want to delete this comment?", :title => "Delete comment" %>
|
31
|
-
<%= link_to image_tag("admin/comment_edit.png"), edit_admin_comment_path(comment),
|
32
|
-
:title => "Edit comment" %>
|
33
|
-
</td>
|
34
|
-
</tr>
|
@@ -1,36 +0,0 @@
|
|
1
|
-
<% if Comment.spam_filter == SimpleSpamFilter %>
|
2
|
-
<div style="display:none">
|
3
|
-
<%= f.hidden_field :spam_answer, :value => "hemidemisemiquaver" %>
|
4
|
-
<%= f.hidden_field :valid_spam_answer, :value => Digest::MD5.hexdigest("hemidemisemiquaver") %>
|
5
|
-
</div>
|
6
|
-
<% end %>
|
7
|
-
<div id="comment_form_container" class="form-area">
|
8
|
-
<div class="row">
|
9
|
-
<p>
|
10
|
-
<label for="comment_author">Author</label><br/>
|
11
|
-
<%= f.text_field :author %>
|
12
|
-
</p>
|
13
|
-
<p>
|
14
|
-
<label for="comment_author_url">URL</label><br/>
|
15
|
-
<%= f.text_field :author_url %>
|
16
|
-
</p>
|
17
|
-
</div>
|
18
|
-
<br style="clear: both" />
|
19
|
-
<p>
|
20
|
-
<label for="comment_author_email">Email</label><br/>
|
21
|
-
<%= f.text_field :author_email %>
|
22
|
-
</p>
|
23
|
-
<p>
|
24
|
-
<label for="comment_content">Comment</label><br />
|
25
|
-
<%= f.text_area :content, :rows => 10, :cols => 72, :class => "textarea"%>
|
26
|
-
</p>
|
27
|
-
<p>
|
28
|
-
<label for="comment_filter_id">Filter</label>
|
29
|
-
<%= f.select :filter_id, [['<none>', '']] + TextFilter.descendants.map { |s| s.filter_name }.sort %>
|
30
|
-
</p>
|
31
|
-
</div>
|
32
|
-
<p class="buttons">
|
33
|
-
<%= save_model_button(@comment) %>
|
34
|
-
or
|
35
|
-
<%= link_to "Cancel", :back %>
|
36
|
-
</p>
|
@@ -1,55 +0,0 @@
|
|
1
|
-
<% content_for :page_scripts do -%>
|
2
|
-
document.observe('dom:loaded', function(){
|
3
|
-
Event.addBehavior({
|
4
|
-
'tr.comment td.content': function(event){
|
5
|
-
$(this).observe('click', function(event){
|
6
|
-
if($(this).down('blockquote.expanded')){
|
7
|
-
$(this).down('blockquote.expanded').toggle();
|
8
|
-
$(this).down('blockquote.short').toggle();
|
9
|
-
}
|
10
|
-
event.stop();
|
11
|
-
});
|
12
|
-
}
|
13
|
-
});
|
14
|
-
});
|
15
|
-
<% end %>
|
16
|
-
<%- include_stylesheet 'admin/comments' %>
|
17
|
-
<h1>
|
18
|
-
<% if @page -%>
|
19
|
-
<%= @page.comments.count %> <%= "#{params[:status].titleize} " if params[:status] %><%= pluralize(@page.comments.count, 'Comment') %> on <%= link_to @page.title, edit_admin_page_path(@page) %>
|
20
|
-
<% else -%>
|
21
|
-
<%= params[:status].titleize if params[:status] %> Comments
|
22
|
-
<% end -%>
|
23
|
-
</h1>
|
24
|
-
|
25
|
-
<ul id="comment-nav">
|
26
|
-
<li class="all"><%= link_or_span_unless_current("All", :status => 'all', :page_id => params[:page_id]) %></li>
|
27
|
-
<li class="approved"><%= link_or_span_unless_current("Approved", :status => "approved", :page_id => params[:page_id]) %></li>
|
28
|
-
<li class="unapproved"><%= link_or_span_unless_current("Unapproved", :status => "unapproved", :page_id => params[:page_id]) %></li>
|
29
|
-
<li class="csv"><%= link_to "Download CSV", :format => :csv %></li>
|
30
|
-
</ul>
|
31
|
-
|
32
|
-
<%= will_paginate @comments %>
|
33
|
-
|
34
|
-
<table id="comments" class="index" border="0" cellspacing="0" cellpadding="0">
|
35
|
-
<thead>
|
36
|
-
<tr>
|
37
|
-
<th>Content</th>
|
38
|
-
<th>Date</th>
|
39
|
-
<th>Author</th>
|
40
|
-
<% unless @page %><th>Page</th><% end %>
|
41
|
-
<th>Actions</th>
|
42
|
-
</tr>
|
43
|
-
</thead>
|
44
|
-
<tbody>
|
45
|
-
<%= render(:partial => "comment", :collection => @comments) || %Q[<tr><td class="note" colspan="#{@page ? 4 : 5}">No comments</td></tr>] %>
|
46
|
-
</tbody>
|
47
|
-
</table>
|
48
|
-
|
49
|
-
<%= will_paginate @comments %>
|
50
|
-
|
51
|
-
<% form_tag destroy_unapproved_admin_comments_url, :method => :delete do %>
|
52
|
-
<p><button type="submit" class="delete-unapproved"><%= image_tag("admin/comments_delete.png") %> Delete All Unapproved</button></p>
|
53
|
-
<% end %>
|
54
|
-
|
55
|
-
<p><small class="notice"><%= Comment.spam_filter.message %></small></p>
|
@@ -1,8 +0,0 @@
|
|
1
|
-
<p style="clear:left">
|
2
|
-
<label for="page_enable_comments">Allow Comments on this page?</label>
|
3
|
-
<%= check_box "page", "enable_comments" %>
|
4
|
-
|
5
|
-
<small>
|
6
|
-
<%= link_to "Currently #{@page.comments_count} — View comments", admin_page_comments_path(:page_id => @page.id) unless @page.new_record? or @page.comments_count < 1 %>
|
7
|
-
</small>
|
8
|
-
</p>
|
@@ -1 +0,0 @@
|
|
1
|
-
<th class="comments">Comments</th>
|
@@ -1,11 +0,0 @@
|
|
1
|
-
<td class="comment_link">
|
2
|
-
<% if page.respond_to?('enable_comments') %>
|
3
|
-
<small>
|
4
|
-
<% if page.enable_comments %>
|
5
|
-
<%= link_to "#{page.comments_count} comments", admin_page_comments_path(:page_id => page.id) %>
|
6
|
-
<% else %>
|
7
|
-
<%= link_to "Enable", admin_page_enable_comments_path(:page_id => page.id), :method => :put %>
|
8
|
-
<% end %>
|
9
|
-
</small>
|
10
|
-
<% end %>
|
11
|
-
</td>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= comment.inspect %>
|
@@ -1,23 +0,0 @@
|
|
1
|
-
<h1>Comment Form</h1>
|
2
|
-
|
3
|
-
<div id="comment_form_container">
|
4
|
-
|
5
|
-
<fieldset class="comment_form">
|
6
|
-
|
7
|
-
<a name="comment_form"></a>
|
8
|
-
|
9
|
-
<%= f.text_field :author, :label => "Your Name (as you'd like it to appear on this comment)", :class => "regular" %>
|
10
|
-
|
11
|
-
<%= f.text_field :author_url %>
|
12
|
-
|
13
|
-
<%= f.text_field :author_email %>
|
14
|
-
|
15
|
-
<%= f.text_area :content, :label => "Your comment", :rows => 5, :class => "regular" %>
|
16
|
-
|
17
|
-
<%= submit_tag("Save comment", :class => "button", :id => "comment_submit_button") %>
|
18
|
-
|
19
|
-
<%= f.hidden_field :page_id %>
|
20
|
-
|
21
|
-
</fieldset>
|
22
|
-
|
23
|
-
</div>
|
data/lib/mollom.rb
DELETED
@@ -1,246 +0,0 @@
|
|
1
|
-
require 'xmlrpc/client'
|
2
|
-
require 'openssl'
|
3
|
-
require 'base64'
|
4
|
-
|
5
|
-
# Mollom API requires this to change, but this gives a warning!
|
6
|
-
# XMLRPC::Client::USER_AGENT = "Ruby Mollom/0.1"
|
7
|
-
|
8
|
-
class Mollom
|
9
|
-
API_VERSION = '1.0'
|
10
|
-
STATIC_SERVER_LIST = [{:proto => 'http', :host => 'xmlrpc3.mollom.com'},
|
11
|
-
{:proto => 'http', :host => 'xmlrpc2.mollom.com'},
|
12
|
-
{:proto => 'http', :host => 'xmlrpc1.mollom.com'}].freeze
|
13
|
-
|
14
|
-
module Errors
|
15
|
-
Standard = 1000
|
16
|
-
Refresh = 1100
|
17
|
-
TooBusy = 1200
|
18
|
-
end
|
19
|
-
|
20
|
-
attr_accessor :private_key, :public_key
|
21
|
-
|
22
|
-
# Creates a new Mollom object. Takes +private_key+ and +public_key+ as keys.
|
23
|
-
#
|
24
|
-
# Mollom.new(:private_key => 'qopzalnzanzajlazjna', :public_key => 'aksakzaddazidzaodjaz')
|
25
|
-
# # => #<Mollom:0x5b6454 @public_key="aksakzaddazidzaodjaz", @private_key="qopzalnzanzajlazjna">
|
26
|
-
|
27
|
-
def initialize(options = {})
|
28
|
-
@private_key = options[:private_key]
|
29
|
-
@public_key = options[:public_key]
|
30
|
-
end
|
31
|
-
|
32
|
-
# Checks the content whether it is spam, ham (not spam), or undecided, and gives a quality assessment of the content.
|
33
|
-
# Possible content keys are:
|
34
|
-
# session_id # => If you allready have a session_id
|
35
|
-
# post_title # => The title
|
36
|
-
# post_body # => The main content of the post.
|
37
|
-
# author_name # => The name of the post author
|
38
|
-
# author_url # => The url the author enters
|
39
|
-
# author_mail # => The author's email address
|
40
|
-
# author_ip # => The author's IP address
|
41
|
-
# author_openid # => The author's OpenID
|
42
|
-
# author_id # => The author's ID
|
43
|
-
#
|
44
|
-
# Only the +post_body+ key is required, all other keys are optional.
|
45
|
-
# This function returns a ContentResponse object.
|
46
|
-
#
|
47
|
-
# response = mollom.check_content :post_title => 'Mollom rules!',
|
48
|
-
# :post_body => 'I think that mollom is so cool!',
|
49
|
-
# :author_name => 'Jan De Poorter',
|
50
|
-
# :author_url => 'http://www.openminds.be'
|
51
|
-
# response.spam? # => false
|
52
|
-
# response.ham? # => true
|
53
|
-
def check_content(content = {})
|
54
|
-
return ContentResponse.new(send_command('mollom.checkContent', content))
|
55
|
-
end
|
56
|
-
|
57
|
-
# Requests an Image captcha from Mollom. It takes the optional <tt>session_id</tt> and <tt>author_ip</tt> keys, if you allready have a session.
|
58
|
-
# It returns a hash with the URL where the captcha can be found, and the session_id, to keep track of the current session (Needed later in <tt>Mollom#check_captcha</tt>)
|
59
|
-
#
|
60
|
-
# captcha = mollom.image_captcha :author_ip => '172.16.0.1'
|
61
|
-
# captcha['url'] # => http://xmlrpc1.mollom.com:80/a9616e6b4cd6a81ecdd509fa624d895d.png
|
62
|
-
# captcha['session_id'] # => a9616e6b4cd6a81ecdd509fa624d895d
|
63
|
-
def image_captcha(info = {})
|
64
|
-
return send_command('mollom.getImageCaptcha', info)
|
65
|
-
end
|
66
|
-
|
67
|
-
# Requests an Audio captcha from Mollom. It takes the optional +session_id+ and +author_ip+ keys, if you allready have a session.
|
68
|
-
# It returns a hash with the URL where the captcha can be found, and the session_id, to keep track of the current session (Needed later in <tt>Mollom#check_captcha</tt>)
|
69
|
-
#
|
70
|
-
# captcha = mollom.audio_captcha :author_ip => '172.16.0.2', :session_id => 'a9616e6b4cd6a81ecdd509fa624d895d'
|
71
|
-
# captcha['url'] # => http://xmlrpc1.mollom.com:80/a9616e6b4cd6a81ecdd509fa624d895d.mp3
|
72
|
-
# captcha['session_id'] # => a9616e6b4cd6a81ecdd509fa624d895d
|
73
|
-
def audio_captcha(info = {})
|
74
|
-
return send_command('mollom.getAudioCaptcha', info)
|
75
|
-
end
|
76
|
-
|
77
|
-
# Checks with mollom if the given captcha (by the user) is correct. Takes +session_id+ and +solution+ keys. Both keys are required.
|
78
|
-
# Returns true if the captcha is valid, false if it is incorrect
|
79
|
-
#
|
80
|
-
# captcha = mollom.image_captcha :author_ip => '172.16.0.1'
|
81
|
-
# # show to user... input from user
|
82
|
-
# return = mollom.valid_captcha? :session_id => captcha['session_id'], :solution => 'abcDe9'
|
83
|
-
# return # => true
|
84
|
-
def valid_captcha?(info = {})
|
85
|
-
return send_command('mollom.checkCaptcha', info)
|
86
|
-
end
|
87
|
-
|
88
|
-
# Standard check to see if your public/private keypair are recognized. Takes no options
|
89
|
-
def key_ok?
|
90
|
-
return send_command('mollom.verifyKey')
|
91
|
-
rescue
|
92
|
-
return false
|
93
|
-
end
|
94
|
-
|
95
|
-
# Gets some statistics from Mollom about your site.
|
96
|
-
#
|
97
|
-
# The type has to be passed. Possible types:
|
98
|
-
# total_days
|
99
|
-
# total_accepted
|
100
|
-
# total_rejected
|
101
|
-
# yesterday_accepted
|
102
|
-
# yesterday_rejected
|
103
|
-
# today_accepted
|
104
|
-
# today_rejected
|
105
|
-
#
|
106
|
-
# mollom.statistics :type => 'total_accepted' # => 123
|
107
|
-
def statistics(options = {})
|
108
|
-
return send_command('mollom.getStatistics', options)
|
109
|
-
end
|
110
|
-
|
111
|
-
# Send feedback to Mollom about a certain content. Required keys are +session_id+ and +feedback+.
|
112
|
-
#
|
113
|
-
# Feedback can be any of
|
114
|
-
# spam
|
115
|
-
# profanity
|
116
|
-
# low-quality
|
117
|
-
# unwanted
|
118
|
-
#
|
119
|
-
# mollom.send_feedback :session_id => 'a9616e6b4cd6a81ecdd509fa624d895d', :feedback => 'unwanted'
|
120
|
-
def send_feedback(feedback = {})
|
121
|
-
return send_command('mollom.sendFeedback', feedback)
|
122
|
-
end
|
123
|
-
|
124
|
-
# Gets a list of servers from Mollom. You should cache this information in your application in a temporary file or in a database. You can set this with Mollom#server_list=
|
125
|
-
#
|
126
|
-
# Takes an optional parameter +refresh+, which resets the cached value.
|
127
|
-
#
|
128
|
-
# mollom.server_list
|
129
|
-
# # => [{:proto=>"http", :host=>"88.151.243.81"}, {:proto=>"http", :host=>"82.103.131.136"}]
|
130
|
-
def server_list(refresh = false)
|
131
|
-
return @server_list if @server_list && !refresh
|
132
|
-
STATIC_SERVER_LIST.each do |static_server|
|
133
|
-
@server_list = get_server_list_from(static_server)
|
134
|
-
return @server_list if @server_list
|
135
|
-
end
|
136
|
-
# Should have returned a server_list here..
|
137
|
-
raise(Error.new("Can't get mollom server-list"))
|
138
|
-
end
|
139
|
-
|
140
|
-
# Sets the server list used to contact Mollom. This should be used to set the list of cached servers.
|
141
|
-
#
|
142
|
-
# If you try to set a faulty server list, the function will silently fail, so we can get the server-list from Mollom.
|
143
|
-
def server_list=(list)
|
144
|
-
# Check if we get an actual serverlist-array
|
145
|
-
if list.is_a?(Array) && list.all? {|hash| hash.has_key?(:host) && hash.has_key?(:proto) }
|
146
|
-
@server_list = list
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
private
|
151
|
-
def get_server_list_from(server)
|
152
|
-
XMLRPC::Client.new(server[:host], "/#{API_VERSION}").call('mollom.getServerList', authentication_hash).collect do |server|
|
153
|
-
proto, ip = server.split('://')
|
154
|
-
{:proto => proto, :host => ip}
|
155
|
-
end
|
156
|
-
rescue
|
157
|
-
nil
|
158
|
-
end
|
159
|
-
|
160
|
-
def send_command(command, data = {})
|
161
|
-
server_list.each do |server|
|
162
|
-
begin
|
163
|
-
return XMLRPC::Client.new(server[:host], "/#{API_VERSION}").call(command, data.merge(authentication_hash))
|
164
|
-
# TODO: Rescue more stuff (Connection Timeout and such)
|
165
|
-
rescue XMLRPC::FaultException => error
|
166
|
-
case error.faultCode
|
167
|
-
when Errors::Standard
|
168
|
-
raise Error.new(error.faultString)
|
169
|
-
when Errors::Refresh # Refresh server list please!
|
170
|
-
# we take this one out of our loop
|
171
|
-
raise
|
172
|
-
when Errors::TooBusy # Server is too busy, take the next one
|
173
|
-
next
|
174
|
-
else
|
175
|
-
next
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
raise Mollom::NoAvailableServers
|
180
|
-
rescue XMLRPC::FaultException
|
181
|
-
# We know it is Errors::Refresh
|
182
|
-
server_list(true)
|
183
|
-
retry
|
184
|
-
end
|
185
|
-
|
186
|
-
# Creates a HMAC-SHA1 Hash with the current timestamp, a nonce, and your private key.
|
187
|
-
def authentication_hash
|
188
|
-
now = Time.now.gmtime.strftime('%Y-%m-%dT%H:%M:%S.000+0000')
|
189
|
-
nonce = Kernel.rand(2**31) # Random signed int
|
190
|
-
|
191
|
-
hash = Base64.encode64(
|
192
|
-
OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, @private_key, "#{now}:#{nonce}:#{@private_key}")
|
193
|
-
).chomp
|
194
|
-
|
195
|
-
return :public_key=> @public_key, :time => now, :hash => hash, :nonce => nonce
|
196
|
-
end
|
197
|
-
|
198
|
-
class ContentResponse
|
199
|
-
attr_reader :session_id, :quality
|
200
|
-
|
201
|
-
Unknown = 0
|
202
|
-
Ham = 1
|
203
|
-
Unsure = 2
|
204
|
-
Spam = 3
|
205
|
-
|
206
|
-
# This class should only be initialized from within the +check_content+ command.
|
207
|
-
def initialize(hash)
|
208
|
-
@spam_response = hash["spam"]
|
209
|
-
@session_id = hash["session_id"]
|
210
|
-
@quality = hash["quality"]
|
211
|
-
end
|
212
|
-
|
213
|
-
# Is the content Spam?
|
214
|
-
def spam?
|
215
|
-
@spam_response == Spam
|
216
|
-
end
|
217
|
-
|
218
|
-
# Is the content Ham?
|
219
|
-
def ham?
|
220
|
-
@spam_response == Ham
|
221
|
-
end
|
222
|
-
|
223
|
-
# is Mollom unsure about the content?
|
224
|
-
def unsure?
|
225
|
-
@spam_response == Unsure
|
226
|
-
end
|
227
|
-
|
228
|
-
# is the content unknown?
|
229
|
-
def unknown?
|
230
|
-
@spam_response == Unknown
|
231
|
-
end
|
232
|
-
|
233
|
-
# Returns 'unknown', 'ham', 'unsure' or 'spam', depending on what the content is.
|
234
|
-
def to_s
|
235
|
-
case @spam_response
|
236
|
-
when Unknown: 'unknown'
|
237
|
-
when Ham: 'ham'
|
238
|
-
when Unsure: 'unsure'
|
239
|
-
when Spam: 'spam'
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
class Error < StandardError; end
|
245
|
-
class NoAvailableServers < Error; end
|
246
|
-
end
|