Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 96 lines (79 sloc) 3.643 kb
1eea36f Importing comments extension to Git
Ryan Heneise authored
1 require_dependency 'application'
2
3 class CommentsExtension < Radiant::Extension
a641c52 @ntalbott Did a bit of cleanup.
ntalbott authored
4 version "0.0.5"
1eea36f Importing comments extension to Git
Ryan Heneise authored
5 description "Adds blog-like comments and comment functionality to pages."
a641c52 @ntalbott Did a bit of cleanup.
ntalbott authored
6 url "http://github.com/ntalbott/radiant-comments/tree/master"
1eea36f Importing comments extension to Git
Ryan Heneise authored
7
7a799d3 fix restrict route so that remove/update still works
Michael Hale authored
8 define_routes do |map|
1eea36f Importing comments extension to Git
Ryan Heneise authored
9 map.with_options(:controller => 'admin/comments') do |comments|
9d145e9 @saturnflyer link to destroy unapproved
saturnflyer authored
10 comments.destroy_unapproved_comments '/admin/comments/unapproved/destroy', :action => 'destroy_unapproved', :conditions => {:method => :delete}
7a799d3 fix restrict route so that remove/update still works
Michael Hale authored
11 comments.connect 'admin/comments/:status', :status => /all|approved|unapproved/, :conditions => { :method => :get }
d1945f6 nicer urls for csv downloads
Michael Hale authored
12 comments.connect 'admin/comments/:status.:format'
13 comments.connect 'admin/pages/:page_id/comments/:status.:format'
14 comments.connect 'admin/pages/:page_id/comments/all.:format'
15
3bccd41 @ntalbott Fixed comments admin.
ntalbott authored
16 comments.resources :comments, :path_prefix => "/admin", :name_prefix => "admin_", :member => {:approve => :get, :unapprove => :get}
17 comments.admin_page_comments 'admin/pages/:page_id/comments/:action'
18 comments.admin_page_comment 'admin/pages/:page_id/comments/:id/:action'
1eea36f Importing comments extension to Git
Ryan Heneise authored
19 end
3bccd41 @ntalbott Fixed comments admin.
ntalbott authored
20 # This needs to be last, otherwise it hoses the admin routes.
21 map.resources :comments, :name_prefix => "page_", :path_prefix => "*url", :controller => "comments"
1eea36f Importing comments extension to Git
Ryan Heneise authored
22 end
23
24 def activate
b037ce8 don't activate if bootstraping
Michael Hale authored
25 return if Radiant.bootstraping?
1eea36f Importing comments extension to Git
Ryan Heneise authored
26 Page.send :include, CommentTags
27 Comment
28
29 Page.class_eval do
c8a1ada @jonleighton Notify the user about whether their comment has gone into the moderation...
jonleighton authored
30 has_many :comments, :dependent => :destroy, :order => "created_at ASC"
31 has_many :approved_comments, :class_name => "Comment", :conditions => "comments.approved_at IS NOT NULL", :order => "created_at ASC"
32 has_many :unapproved_comments, :class_name => "Comment", :conditions => "comments.approved_at IS NULL", :order => "created_at ASC"
0beda57 @ntalbott Added validation support.
ntalbott authored
33 attr_accessor :last_comment
c8a1ada @jonleighton Notify the user about whether their comment has gone into the moderation...
jonleighton authored
34 attr_accessor :selected_comment
b404ad6 @ntalbott Selected comment should show even if it is the only comment.
ntalbott authored
35
36 def has_visible_comments?
37 !(approved_comments.empty? && selected_comment.nil?)
38 end
1eea36f Importing comments extension to Git
Ryan Heneise authored
39 end
40
41 if admin.respond_to? :page
42 admin.page.edit.add :parts_bottom, "edit_comments_enabled", :before => "edit_timestamp"
c89a61b @ntalbott Initial cleanup and update to work with Radiant 0.6.7
ntalbott authored
43 admin.page.index.add :sitemap_head, "index_head_view_comments"
44 admin.page.index.add :node, "index_view_comments"
1eea36f Importing comments extension to Git
Ryan Heneise authored
45 end
46
7ead331 download csv of comments
Michael Hale authored
47 admin.tabs.add "Comments", "/admin/comments/unapproved", :visibility => [:all]
c89a61b @ntalbott Initial cleanup and update to work with Radiant 0.6.7
ntalbott authored
48
49 { 'notification' => 'false',
50 'notification_from' => '',
51 'notification_to' => '',
ca9d295 @ntalbott Fixed up notifications.
ntalbott authored
52 'notification_site_name' => '',
b469609 @saturnflyer add ability to notify creators and updaters
saturnflyer authored
53 'notify_creator' => 'true',
54 'notify_updater' => 'false',
c89a61b @ntalbott Initial cleanup and update to work with Radiant 0.6.7
ntalbott authored
55 'akismet_key' => '',
56 'akismet_url' => '',
2c0b340 @franklouwers first attempt of Mollom antispam integration (next to Akismet). Basic fu...
franklouwers authored
57 'mollom_privatekey' => '',
58 'mollom_publickey' => '',
1b7aec4 @ntalbott Allow disabling of input filters.
ntalbott authored
59 'filters_enabled' => 'true',
c89a61b @ntalbott Initial cleanup and update to work with Radiant 0.6.7
ntalbott authored
60 }.each{|k,v| Radiant::Config.create(:key => "comments.#{k}", :value => v) unless Radiant::Config["comments.#{k}"]}
7ead331 download csv of comments
Michael Hale authored
61
62 require "fastercsv"
63
64 ActiveRecord::Base.class_eval do
65 def self.to_csv(*args)
66 find(:all).to_csv(*args)
67 end
68
69 def export_columns(format = nil)
70 self.class.content_columns.map(&:name) - ['created_at', 'updated_at']
71 end
72
73 def to_row(format = nil)
74 export_columns(format).map { |c| self.send(c) }
75 end
76 end
77
78 Array.class_eval do
79 def to_csv(options = {})
80 return "" if first.nil?
81 if all? { |e| e.respond_to?(:to_row) }
82 header_row = first.export_columns(options[:format]).to_csv
83 content_rows = map { |e| e.to_row(options[:format]) }.map(&:to_csv)
84 ([header_row] + content_rows).join
85 else
86 FasterCSV.generate_line(self, options)
87 end
88 end
89 end
1eea36f Importing comments extension to Git
Ryan Heneise authored
90 end
91
92 def deactivate
93 end
94
660c979 @jacius Fixed the bug where an extra 'comments enabled?' checkbox was being inse...
jacius authored
95 end
Something went wrong with that request. Please try again.