comment_helper.rb
3.46 KB
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
module CommentHelper
def article_title(article, args = {})
title = article.display_title if article.kind_of?(UploadedFile) && article.image?
title = article.title if title.blank?
title = content_tag('h1', h(title), :class => 'title')
if article.belongs_to_blog?
unless args[:no_link]
title = content_tag('h1', link_to(article.name, article.url), :class => 'title')
end
comments = ''
unless args[:no_comments] || !article.accept_comments
comments = (" - %s") % link_to_comments(article)
end
title << content_tag('span',
content_tag('span', show_date(article.published_at), :class => 'date') +
content_tag('span', [_(", by %s") % link_to(article.author_name, article.author_url)], :class => 'author') +
content_tag('span', comments, :class => 'comments'),
:class => 'created-at'
)
end
title
end
def comment_actions(comment)
url = url_for(:profile => profile.identifier, :controller => :comment, :action => :check_actions, :id => comment.id)
links = links_for_comment_actions(comment)
content_tag(:li, link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{links.to_json}); return false", :class => 'menu-submenu-trigger comment-trigger', :url => url), :class=> 'vcard') unless links.empty?
end
private
def links_for_comment_actions(comment)
actions = [link_for_report_abuse(comment), link_for_spam(comment), link_for_edit(comment), link_for_remove(comment)]
@plugins.dispatch(:comment_actions, comment).collect do |action|
actions << (action.kind_of?(Proc) ? self.instance_eval(&action) : action)
end
actions.flatten.compact
end
def link_for_report_abuse(comment)
if comment.author
report_abuse_link = report_abuse(comment.author, :comment_link, comment)
{:link => report_abuse_link} if report_abuse_link
end
end
def link_for_spam(comment)
if comment.spam?
{:link => link_to_function(_('Mark as NOT SPAM'), 'remove_comment(this, %s); return false;' % url_for(:profile => profile.identifier, :mark_comment_as_ham => comment.id).to_json, :class => 'comment-footer comment-footer-link comment-footer-hide')}
elsif (logged_in? && (user == profile || user.has_permission?(:moderate_comments, profile)))
{:link => link_to_function(_('Mark as SPAM'), 'remove_comment(this, %s, %s); return false;' % [url_for(:profile => profile.identifier, :controller => 'comment', :action => :mark_as_spam, :id => comment.id).to_json, _('Are you sure you want to mark this comment as SPAM?').to_json], :class => 'comment-footer comment-footer-link comment-footer-hide')}
end
end
def link_for_edit(comment)
if comment.author && comment.author == user
{:link => expirable_comment_link(comment, :edit, _('Edit'), url_for(:profile => profile.identifier, :controller => :comment, :action => :edit, :id => comment.id),:class => 'colorbox')}
end
end
def link_for_remove(comment)
if logged_in? && (user == profile || user == comment.author || user.has_permission?(:moderate_comments, profile))
{:link => link_to_function(_('Remove'), 'remove_comment(this, %s, %s); return false ;' % [url_for(:profile => profile.identifier, :controller => 'comment', :action => :destroy, :id => comment.id).to_json, _('Are you sure you want to remove this comment and all its replies?').to_json], :class => 'comment-footer comment-footer-link comment-footer-hide remove-children')}
end
end
end