module CamaleonCms module CommentHelper # return common data to save a new comment # user_id, author, aothor_email, author_ip, approved, :agent def cama_comments_get_common_data comment_data = {} comment_data[:user_id] = cama_current_user.id comment_data[:author] = cama_current_user.the_name comment_data[:author_email] = cama_current_user.email comment_data[:author_IP] = request.remote_ip.to_s comment_data[:approved] = 'approved' comment_data[:agent] = request.user_agent.force_encoding('ISO-8859-1').encode('UTF-8') comment_data end # render as html content all comments recursively # comments: collection of comments def cama_comments_render_html(comments) res = '' labels = { 'approved' => 'success', 'pending' => 'warning', 'spam' => 'danger' } comments.decorate.each do |comment| author = comment.the_author res << "
#{image_tag author.the_avatar, class: 'media-object', style: 'width: 64px; height: 64px;'}

#{author.the_name} #{comment.the_created_at} #{t("camaleon_cms.admin.comments.message.#{comment.approved}")}

#{sanitize comment.content}
#{link_to raw(''), { action: :destroy, id: comment.id }, method: :delete, data: { confirm: t('camaleon_cms.admin.message.delete') }, class: 'btn btn-danger btn-xs cama_ajax_request', title: t('camaleon_cms.admin.comments.tooltip.delete_comment').to_s}

#{cama_comments_render_html comment.children}
" end res end end end