radiant-comments-extension 0.0.6
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 +3 -0
- data/CHANGELOG +40 -0
- data/HELP_admin.markdown +52 -0
- data/HELP_designer.markdown +36 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +53 -0
- data/Rakefile +133 -0
- data/TODO +6 -0
- data/VERSION +1 -0
- data/app/controllers/admin/comments_controller.rb +130 -0
- data/app/controllers/comments_controller.rb +59 -0
- data/app/helpers/admin/comments_helper.rb +7 -0
- data/app/models/akismet_spam_filter.rb +37 -0
- data/app/models/comment.rb +121 -0
- data/app/models/comment_mailer.rb +24 -0
- data/app/models/mollom_spam_filter.rb +52 -0
- data/app/models/simple_spam_filter.rb +38 -0
- data/app/models/spam_filter.rb +43 -0
- data/app/views/admin/comments/_comment.rhtml +34 -0
- data/app/views/admin/comments/_form.rhtml +36 -0
- data/app/views/admin/comments/edit.rhtml +5 -0
- data/app/views/admin/comments/index.rhtml +55 -0
- data/app/views/admin/pages/_comments.rhtml +0 -0
- data/app/views/admin/pages/_edit_comments_enabled.rhtml +8 -0
- data/app/views/admin/pages/_index_head_view_comments.rhtml +1 -0
- data/app/views/admin/pages/_index_view_comments.rhtml +11 -0
- data/app/views/comment_mailer/comment_notification.rhtml +21 -0
- data/app/views/comments/_comment.rhtml +1 -0
- data/app/views/comments/_form.rhtml +23 -0
- data/app/views/comments/_new.rhtml +5 -0
- data/autotest/discover.rb +3 -0
- data/comments_extension.rb +81 -0
- data/cucumber.yml +1 -0
- data/db/migrate/001_create_comments.rb +29 -0
- data/db/migrate/002_create_snippets.rb +115 -0
- data/db/migrate/003_change_filter_id_from_integer_to_string.rb +10 -0
- data/db/migrate/004_add_approval_columns.rb +13 -0
- data/db/migrate/005_add_mollomid_column.rb +11 -0
- data/db/migrate/006_move_config_to_migrations.rb +22 -0
- data/db/migrate/007_add_preference_for_simple_spamcheck.rb +12 -0
- data/features/support/env.rb +16 -0
- data/features/support/paths.rb +16 -0
- data/lib/akismet.rb +134 -0
- data/lib/comment_page_extensions.rb +41 -0
- data/lib/comment_tags.rb +338 -0
- data/lib/mollom.rb +246 -0
- data/lib/radiant-comments-extension.rb +0 -0
- data/lib/tasks/comments_extension_tasks.rake +68 -0
- data/public/images/admin/accept.png +0 -0
- data/public/images/admin/comment_edit.png +0 -0
- data/public/images/admin/comments.png +0 -0
- data/public/images/admin/comments_delete.png +0 -0
- data/public/images/admin/delete.png +0 -0
- data/public/images/admin/email.png +0 -0
- data/public/images/admin/error.png +0 -0
- data/public/images/admin/link.png +0 -0
- data/public/images/admin/page_white_edit.png +0 -0
- data/public/images/admin/table_save.png +0 -0
- data/public/images/admin/tick.png +0 -0
- data/public/stylesheets/admin/comments.css +41 -0
- data/radiant-comments-extension.gemspec +133 -0
- data/spec/controllers/admin/comments_controller_spec.rb +57 -0
- data/spec/controllers/admin/comments_routing_spec.rb +43 -0
- data/spec/controllers/page_postback_spec.rb +51 -0
- data/spec/datasets/comments_dataset.rb +7 -0
- data/spec/models/akismet_spam_filter_spec.rb +61 -0
- data/spec/models/comment_spec.rb +148 -0
- data/spec/models/comment_tags_spec.rb +55 -0
- data/spec/models/mollom_spam_filter_spec.rb +103 -0
- data/spec/models/simple_spam_filter_spec.rb +44 -0
- data/spec/models/spam_filter_spec.rb +38 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +36 -0
- data/test/fixtures/users.yml +6 -0
- data/test/integration/comment_enabling_test.rb +18 -0
- data/test/test_helper.rb +24 -0
- data/test/unit/comment_test.rb +52 -0
- metadata +177 -0
data/.gitignore
ADDED
data/CHANGELOG
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
= Git
|
2
|
+
|
3
|
+
= 0.0.6
|
4
|
+
|
5
|
+
* Added spam_answer_tag for simple spam protection or CAPTCHA
|
6
|
+
* Added comments.notify_creator and comments.notify_updater to send emails to the page creator/updater [Jim Gay]
|
7
|
+
* Added accept.png icon and rake task to copy it. [ryan@artofmission.com]
|
8
|
+
|
9
|
+
= 0.0.5
|
10
|
+
|
11
|
+
* Pluralized the `comments` tag so that it does not conflict with the standard Radiant `comment` tag. [nathaniel@terralien.com]
|
12
|
+
* Added posting confirmation support. [nathaniel@terralien.com]
|
13
|
+
* Added validation support. [nathaniel@terralien.com]
|
14
|
+
* Allow disabling of input filters. [nathaniel@terralien.com]
|
15
|
+
* Updated to work with Radiant 0.6.7. [nathaniel@terralien.com]
|
16
|
+
|
17
|
+
= 0.0.4
|
18
|
+
* Added additional options and formatting to admin interface [rch]
|
19
|
+
* Added comment approval options [rch]
|
20
|
+
* Comments must now be approved before they will show up [rch]
|
21
|
+
|
22
|
+
= 0.0.3
|
23
|
+
* Changed dependency from admin_parts to shards. [hcf]
|
24
|
+
* Added the snippets to a migration, so that the users no longer have to do this manually. [hcf]
|
25
|
+
* Changed filter_id from integer to string to make it similar to radiant core. [hcf]
|
26
|
+
* Removed the 'Comments' tab, and moved the functionality to the 'Pages' tab instead using shards. [hcf]
|
27
|
+
* Added support for filters in comments, through the comment:filter_box_tag tag. [hcf]
|
28
|
+
* Simplified the comment snippets. [hcf]
|
29
|
+
|
30
|
+
= 0.0.2
|
31
|
+
|
32
|
+
* Added Akismet support.
|
33
|
+
* Added admin tools for moderating comments.
|
34
|
+
* Added destroy dependency to Page#Comments association.
|
35
|
+
* Added no_login_required to CommentsController. Comment should no longer force login when posted.
|
36
|
+
|
37
|
+
= 0.0.1
|
38
|
+
|
39
|
+
* Basic comment functionality in place
|
40
|
+
|
data/HELP_admin.markdown
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
You have the capability to use 3 different methods of spam blocking with this extension.
|
2
|
+
|
3
|
+
1. Logic CAPTCHA (asking a question a spambot would not know)
|
4
|
+
2. [Akismet](http://akismet.com/)
|
5
|
+
3. [Mollom](http://mollom.com/)
|
6
|
+
|
7
|
+
## Spam Blocking
|
8
|
+
|
9
|
+
By default, you will have sample questions that you may ask of your visitors. These questions are difficult
|
10
|
+
to easily interpret by robots that may crawl your site looking to leave spam. See your Snippet
|
11
|
+
'comment\_spam\_block' for examples of this.
|
12
|
+
|
13
|
+
You will need to use the spam\_answer\_tag in your comment forms to present these questions to the user.
|
14
|
+
|
15
|
+
If you wish disable this simple spam protection mechanism, you can do so using the `require_simple_spam_filter`
|
16
|
+
config key, e.g. Radiant::Config['comments.require_simple_spam_filter'] = false
|
17
|
+
|
18
|
+
To enable the Akismet protection, get yourself an account at http://akismet.com/personal/ for your personal
|
19
|
+
blog or at http://akismet.com/commercial/ for your commercial sites. Then set your personal key and url
|
20
|
+
in the Radiant::Config.
|
21
|
+
|
22
|
+
For example:
|
23
|
+
|
24
|
+
Radiant::Config['comments.akismet_key'] = "6a009ca6ab4e"
|
25
|
+
Radiant::Config['comments.akismet_url'] = "yoursite.com"
|
26
|
+
|
27
|
+
To enable Mollom protection, get yourself an account at http://mollom.com/user/register, add your site and
|
28
|
+
set the public and private key pair in the Radiant::Config.
|
29
|
+
|
30
|
+
Radiant::Config['comments.mollom_privatekey'] = "deadbeef012345"
|
31
|
+
Radiant::Config['comments.mollom_publickey'] = "c00fee012345"
|
32
|
+
|
33
|
+
If both services are configured, this plugin will use the Akismet service. Unset the akismet_key if you
|
34
|
+
want to use Mollom.
|
35
|
+
|
36
|
+
## Exporting Data
|
37
|
+
|
38
|
+
To customize the CSV fields you can add an initializer like this:
|
39
|
+
|
40
|
+
Comment.class_eval do
|
41
|
+
def export_columns(format = nil)
|
42
|
+
%w[approved? author author_email content referrer]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
## Viewing comments
|
47
|
+
|
48
|
+
You may set the per page number of comments in the Radiant configuration options:
|
49
|
+
|
50
|
+
Radiant::Config['comments.per_page'] = 100
|
51
|
+
|
52
|
+
By default, the number of comments per page is 50.
|
@@ -0,0 +1,36 @@
|
|
1
|
+
## Spam-blocking Questions
|
2
|
+
|
3
|
+
By default you'll have a Snippet called 'comment\_spam\_block' which will provide a way to
|
4
|
+
ask your site commenters a simple question.
|
5
|
+
|
6
|
+
<r:random>
|
7
|
+
<r:error on="spam_answer"><p style="color:red">Answer <r:message /></p></r:error>
|
8
|
+
<r:option>
|
9
|
+
<p><label for="comment_spam_answer">What day of the week has the letter "h" in it's name?</label> (required)<br />
|
10
|
+
<r:spam_answer_tag answer="Thursday" /></p>
|
11
|
+
</r:option>
|
12
|
+
<r:option>
|
13
|
+
<p><label for="comment_spam_answer">Yellow and blue together make what color?</label> (required)<br />
|
14
|
+
<r:spam_answer_tag answer="green" /></p>
|
15
|
+
</r:option>
|
16
|
+
<r:option>
|
17
|
+
<p><label for="comment_spam_answer">What is SPAM spelled backwards?</label> (required)<br />
|
18
|
+
<r:spam_answer_tag answer="MAPS" /></p>
|
19
|
+
</r:option>
|
20
|
+
</r:random>
|
21
|
+
|
22
|
+
The snippet takes advantage of the built-in Radius tags `r:random` and `r:option` to provide a random
|
23
|
+
and less predictable selection of questions for commenters.
|
24
|
+
|
25
|
+
Be sure to alter this snippet for your site!
|
26
|
+
|
27
|
+
## Displaying comments and the comment form
|
28
|
+
|
29
|
+
In your site layout (or another appropriate place) use the following code to display your comment form:
|
30
|
+
|
31
|
+
<r:snippet name="comments" />
|
32
|
+
|
33
|
+
### After comments are posted...
|
34
|
+
|
35
|
+
Relative urls will *not* work on comment pages if they fail validation, since the page gets re-rendered
|
36
|
+
at a (probably) different level of the hierarchy. Always use absolute urls and you won't have any issues.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007 Ryan Heneise
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
= Radiant Comments Extension
|
2
|
+
|
3
|
+
Adds blog-like comment functionality to Radiant. Currently maintained by http://github.com/saturnflyer
|
4
|
+
|
5
|
+
== Patches
|
6
|
+
|
7
|
+
If you want to contribute features or fixes please write your specs and code and submit pull requests to these github.com users:
|
8
|
+
|
9
|
+
- saturnflyer
|
10
|
+
- artofmission
|
11
|
+
|
12
|
+
== Dependencies
|
13
|
+
|
14
|
+
* Requires Radiant 0.7.1 or greater.
|
15
|
+
* Requires will_paginate Rails plugin (http://github.com/mislav/will_paginate/tree/master)
|
16
|
+
* Requires fastercsv 1.2.3 or greater.
|
17
|
+
* Requires sanitize 1.0.8 or greater.
|
18
|
+
|
19
|
+
== Installation
|
20
|
+
|
21
|
+
To install Comments, run:
|
22
|
+
|
23
|
+
rake radiant:extensions:comments:install
|
24
|
+
|
25
|
+
This _WILL_ delete any snippets named 'comment', 'comments' and 'comment_form' if these exist.
|
26
|
+
|
27
|
+
== More Help
|
28
|
+
|
29
|
+
See the included HELP docs here or read them in your Radiant interface with the Help extension installed.
|
30
|
+
|
31
|
+
== Contributors
|
32
|
+
|
33
|
+
* John Muhl
|
34
|
+
* Sven Schwyn
|
35
|
+
* Gerrit Kaiser
|
36
|
+
* Stephen Lombardo
|
37
|
+
* Benny Degezelle
|
38
|
+
* Frank Louwers (thanks to Jan De Poorter for the Mollom ruby lib)
|
39
|
+
* Jim Gay of http://www.saturnflyer.com, sponsored by http://ignitesocialmedia.com/.
|
40
|
+
* Michael Hale of http://halethegeek.com/, sponsored by http://ignitesocialmedia.com/.
|
41
|
+
* Nathaniel Talbott of http://terralien.com/, sponsored by http://ignitesocialmedia.com/.
|
42
|
+
* John Croisant
|
43
|
+
* Jon Leighton
|
44
|
+
* Witter Cheng
|
45
|
+
* Keith Bingman
|
46
|
+
* Sean Cribbs, partly sponsored by http://opscode.com/
|
47
|
+
* Ryan Heneise
|
48
|
+
|
49
|
+
If you contribute, go ahead and add your name to the list!
|
50
|
+
|
51
|
+
== Credits
|
52
|
+
|
53
|
+
Included icons come from the FamFamFam Silk icon set. http://famfamfam.com
|
data/Rakefile
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gem|
|
4
|
+
gem.name = "radiant-comments-extension"
|
5
|
+
gem.summary = %Q{Comments Extension for Radiant CMS}
|
6
|
+
gem.description = %Q{Adds blog-like comment functionality to Radiant.}
|
7
|
+
gem.email = "jim@saturnflyer.com"
|
8
|
+
gem.homepage = "http://github.com/saturnflyer/radiant-comments-extension"
|
9
|
+
gem.authors = ['Jim Gay', 'Ryan Heneise', 'Sean Cribbs','John Muhl', 'Sven Schwyn', 'Gerrit Kaiser', 'Stephen Lombardo', 'Benny Degezelle', 'Frank Louwers', 'Michael Hale', 'Nathaniel Talbott', 'John Croisant', 'Jon Leighton', 'Witter Cheng', 'Keith Bingman']
|
10
|
+
gem.add_development_dependency "radiant"
|
11
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
puts "Jeweler (or a dependency) not available. This is only required if you plan to package dashboard as a gem."
|
15
|
+
end
|
16
|
+
|
17
|
+
# Determine where the RSpec plugin is by loading the boot
|
18
|
+
unless defined? RADIANT_ROOT
|
19
|
+
ENV["RAILS_ENV"] = "test"
|
20
|
+
case
|
21
|
+
when ENV["RADIANT_ENV_FILE"]
|
22
|
+
require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
|
23
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
24
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
|
25
|
+
else
|
26
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
require 'rake'
|
31
|
+
require 'rake/rdoctask'
|
32
|
+
require 'rake/testtask'
|
33
|
+
|
34
|
+
rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
|
35
|
+
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
|
36
|
+
require 'spec/rake/spectask'
|
37
|
+
require 'cucumber'
|
38
|
+
require 'cucumber/rake/task'
|
39
|
+
|
40
|
+
# Cleanup the RADIANT_ROOT constant so specs will load the environment
|
41
|
+
Object.send(:remove_const, :RADIANT_ROOT)
|
42
|
+
|
43
|
+
extension_root = File.expand_path(File.dirname(__FILE__))
|
44
|
+
|
45
|
+
task :default => :spec
|
46
|
+
task :stats => "spec:statsetup"
|
47
|
+
|
48
|
+
desc "Run all specs in spec directory"
|
49
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
50
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
51
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
52
|
+
end
|
53
|
+
|
54
|
+
task :features => 'spec:integration'
|
55
|
+
|
56
|
+
namespace :spec do
|
57
|
+
desc "Run all specs in spec directory with RCov"
|
58
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
59
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
60
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
61
|
+
t.rcov = true
|
62
|
+
t.rcov_opts = ['--exclude', 'spec', '--rails']
|
63
|
+
end
|
64
|
+
|
65
|
+
desc "Print Specdoc for all specs"
|
66
|
+
Spec::Rake::SpecTask.new(:doc) do |t|
|
67
|
+
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
68
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
69
|
+
end
|
70
|
+
|
71
|
+
[:models, :controllers, :views, :helpers].each do |sub|
|
72
|
+
desc "Run the specs under spec/#{sub}"
|
73
|
+
Spec::Rake::SpecTask.new(sub) do |t|
|
74
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
75
|
+
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
desc "Run the Cucumber features"
|
80
|
+
Cucumber::Rake::Task.new(:integration) do |t|
|
81
|
+
t.fork = true
|
82
|
+
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
|
83
|
+
# t.feature_pattern = "#{extension_root}/features/**/*.feature"
|
84
|
+
t.profile = "default"
|
85
|
+
end
|
86
|
+
|
87
|
+
# Setup specs for stats
|
88
|
+
task :statsetup do
|
89
|
+
require 'code_statistics'
|
90
|
+
::STATS_DIRECTORIES << %w(Model\ specs spec/models)
|
91
|
+
::STATS_DIRECTORIES << %w(View\ specs spec/views)
|
92
|
+
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
|
93
|
+
::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
|
94
|
+
::CodeStatistics::TEST_TYPES << "Model specs"
|
95
|
+
::CodeStatistics::TEST_TYPES << "View specs"
|
96
|
+
::CodeStatistics::TEST_TYPES << "Controller specs"
|
97
|
+
::CodeStatistics::TEST_TYPES << "Helper specs"
|
98
|
+
::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
|
99
|
+
end
|
100
|
+
|
101
|
+
namespace :db do
|
102
|
+
namespace :fixtures do
|
103
|
+
desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
|
104
|
+
task :load => :environment do
|
105
|
+
require 'active_record/fixtures'
|
106
|
+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
107
|
+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
|
108
|
+
Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
desc 'Generate documentation for the comments extension.'
|
116
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
117
|
+
rdoc.rdoc_dir = 'rdoc'
|
118
|
+
rdoc.title = 'CommentsExtension'
|
119
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
120
|
+
rdoc.rdoc_files.include('README')
|
121
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
122
|
+
end
|
123
|
+
|
124
|
+
# For extensions that are in transition
|
125
|
+
desc 'Test the comments extension.'
|
126
|
+
Rake::TestTask.new(:test) do |t|
|
127
|
+
t.libs << 'lib'
|
128
|
+
t.pattern = 'test/**/*_test.rb'
|
129
|
+
t.verbose = true
|
130
|
+
end
|
131
|
+
|
132
|
+
# Load any custom rakefiles for extension
|
133
|
+
Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
|
data/TODO
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.6
|
@@ -0,0 +1,130 @@
|
|
1
|
+
class Admin::CommentsController < ApplicationController
|
2
|
+
|
3
|
+
def index
|
4
|
+
@comments = load_comments
|
5
|
+
respond_to do |format|
|
6
|
+
format.html
|
7
|
+
format.csv { send_data @comments.to_csv, :filename => "#{File.basename(request.request_uri)}", :type => 'text/csv' }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def destroy
|
12
|
+
@comment = Comment.find(params[:id])
|
13
|
+
@comment.destroy
|
14
|
+
announce_comment_removed
|
15
|
+
clear_single_page_cache(@comment)
|
16
|
+
redirect_to :back
|
17
|
+
rescue ActiveRecord::RecordNotFound
|
18
|
+
redirect_to admin_comments_path
|
19
|
+
end
|
20
|
+
|
21
|
+
def destroy_unapproved
|
22
|
+
if Comment.unapproved.destroy_all
|
23
|
+
flash[:notice] = "You have removed all unapproved comments."
|
24
|
+
else
|
25
|
+
flash[:notice] = "I was unable to remove all unapproved comments."
|
26
|
+
end
|
27
|
+
redirect_to :back
|
28
|
+
end
|
29
|
+
|
30
|
+
def edit
|
31
|
+
@comment = Comment.find(params[:id])
|
32
|
+
rescue ActiveRecord::RecordNotFound
|
33
|
+
redirect_to admin_comments_path
|
34
|
+
end
|
35
|
+
|
36
|
+
def show
|
37
|
+
redirect_to edit_admin_comment_path(params[:id])
|
38
|
+
end
|
39
|
+
|
40
|
+
def update
|
41
|
+
@comment = Comment.find(params[:id])
|
42
|
+
begin
|
43
|
+
TextFilter.descendants.each do |filter|
|
44
|
+
@comment.content_html = filter.filter(@comment.content) if filter.filter_name == @comment.filter_id
|
45
|
+
end
|
46
|
+
@comment.update_attributes!(params[:comment])
|
47
|
+
clear_cache
|
48
|
+
flash[:notice] = "Comment Saved"
|
49
|
+
redirect_to :action => :index
|
50
|
+
rescue Exception => e
|
51
|
+
flash[:notice] = "There was an error saving the comment: #{e.message}"
|
52
|
+
render :action => :edit
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def enable
|
57
|
+
@page = Page.find(params[:page_id])
|
58
|
+
@page.enable_comments = true
|
59
|
+
@page.save!
|
60
|
+
clear_cache
|
61
|
+
flash[:notice] = "Comments have been enabled for #{@page.title}"
|
62
|
+
redirect_to admin_pages_url
|
63
|
+
end
|
64
|
+
|
65
|
+
def approve
|
66
|
+
@comment = Comment.find(params[:id])
|
67
|
+
begin
|
68
|
+
@comment.approve!
|
69
|
+
rescue Comment::AntispamWarning => e
|
70
|
+
antispamnotice = "The antispam engine gave a warning: #{e}<br />"
|
71
|
+
end
|
72
|
+
clear_single_page_cache(@comment)
|
73
|
+
flash[:notice] = "Comment was successfully approved on page #{@comment.page.title}" + (antispamnotice ? " (#{antispamnotice})" : "")
|
74
|
+
redirect_to :back
|
75
|
+
end
|
76
|
+
|
77
|
+
def unapprove
|
78
|
+
@comment = Comment.find(params[:id])
|
79
|
+
begin
|
80
|
+
@comment.unapprove!
|
81
|
+
rescue Comment::AntispamWarning => e
|
82
|
+
antispamnotice = "The antispam engine gave a warning: #{e}"
|
83
|
+
end
|
84
|
+
clear_single_page_cache(@comment)
|
85
|
+
flash[:notice] = "Comment was successfully unapproved on page #{@comment.page.title}" + (antispamnotice ? " (#{antispamnotice})" : "" )
|
86
|
+
redirect_to :back
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
protected
|
91
|
+
|
92
|
+
def load_comments
|
93
|
+
status_scope.paginate(:page => params[:page])
|
94
|
+
end
|
95
|
+
|
96
|
+
def status_scope
|
97
|
+
case params[:status]
|
98
|
+
when 'approved'
|
99
|
+
base_scope.approved
|
100
|
+
when 'unapproved'
|
101
|
+
base_scope.unapproved
|
102
|
+
else
|
103
|
+
base_scope
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def base_scope
|
108
|
+
@page = Page.find(params[:page_id]) if params[:page_id]
|
109
|
+
@page ? @page.comments : Comment.recent
|
110
|
+
end
|
111
|
+
|
112
|
+
def announce_comment_removed
|
113
|
+
flash[:notice] = "The comment was successfully removed from the site."
|
114
|
+
end
|
115
|
+
|
116
|
+
def clear_cache
|
117
|
+
if defined?(ResponseCache)
|
118
|
+
ResponseCache.instance.clear
|
119
|
+
else
|
120
|
+
Radiant::Cache.clear
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def clear_single_page_cache(comment)
|
125
|
+
if comment && comment.page
|
126
|
+
clear_cache
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|