2015-10-24 15:34:43 +08:00
|
|
|
|
class BlogCommentsController < ApplicationController
|
|
|
|
|
include ApplicationHelper
|
|
|
|
|
before_filter :find_user
|
|
|
|
|
def index
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
def create
|
|
|
|
|
if User.current.logged?
|
|
|
|
|
@article = BlogComment.new
|
|
|
|
|
@article.author = User.current
|
|
|
|
|
@article.blog_id = params[:blog_id]
|
|
|
|
|
@article.safe_attributes = params[:blog_comment]
|
|
|
|
|
if request.post?
|
|
|
|
|
@article.save_attachments(params[:attachments])
|
|
|
|
|
if @article.save
|
|
|
|
|
# 更新kindeditor上传的图片资源所有者
|
|
|
|
|
# if params[:asset_id]
|
|
|
|
|
# ids = params[:asset_id].split(',')
|
|
|
|
|
# update_kindeditor_assets_owner ids,@article.id,OwnerTypeHelper::BLOGCOMMENT
|
|
|
|
|
# end
|
|
|
|
|
render_attachment_warning_if_needed(@article)
|
|
|
|
|
else
|
|
|
|
|
end
|
|
|
|
|
redirect_to user_blogs_path(:user_id=>params[:user_id])
|
|
|
|
|
else
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html {
|
|
|
|
|
render :layout => 'new_base_user'
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
redirect_to signin_path
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
def new
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html {render :layout=>'new_base_user'}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
def show
|
|
|
|
|
@article = BlogComment.find(params[:id])
|
2016-10-09 11:12:44 +08:00
|
|
|
|
all_comments = []
|
|
|
|
|
@replies = get_all_children(all_comments, @article)
|
|
|
|
|
@reply_count = @replies.count
|
|
|
|
|
@page = params[:page] ? params[:page].to_i + 1 : 0
|
|
|
|
|
@limit = 10
|
|
|
|
|
@replies = @replies[@page * @limit..@page * @limit + 9]
|
2015-10-24 15:34:43 +08:00
|
|
|
|
respond_to do |format|
|
2016-10-09 11:12:44 +08:00
|
|
|
|
format.js
|
2015-10-24 15:34:43 +08:00
|
|
|
|
format.html {render :layout=>'new_base_user'}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
def update
|
|
|
|
|
@article = BlogComment.find(params[:id])
|
|
|
|
|
@article.safe_attributes = params[:blog_comment]
|
|
|
|
|
@article.save_attachments(params[:attachments])
|
|
|
|
|
if @article.save
|
|
|
|
|
render_attachment_warning_if_needed(@article)
|
|
|
|
|
else
|
|
|
|
|
end
|
2016-01-21 16:11:06 +08:00
|
|
|
|
if params[:in_act]
|
|
|
|
|
redirect_to user_path(params[:user_id])
|
2016-01-08 16:16:57 +08:00
|
|
|
|
else
|
2016-01-26 10:35:54 +08:00
|
|
|
|
if @article.id.eql?(User.find(params[:user_id]).blog.homepage_id)
|
|
|
|
|
redirect_to user_path(params[:user_id])
|
2016-01-21 16:11:06 +08:00
|
|
|
|
else
|
|
|
|
|
redirect_to user_blog_blog_comment_path(:user_id=>params[:user_id],:blog_id=>params[:blog_id],:id=>params[:id])
|
|
|
|
|
end
|
2016-01-08 16:16:57 +08:00
|
|
|
|
end
|
2015-10-24 15:34:43 +08:00
|
|
|
|
end
|
|
|
|
|
def destroy
|
|
|
|
|
@article = BlogComment.find(params[:id])
|
2015-10-30 10:52:56 +08:00
|
|
|
|
if @article.parent_id.nil? #如果是文章被删,那么跳转到用户博客界面,如果带了course_id过来,那么就要跳转到课程首页
|
2015-10-30 14:22:11 +08:00
|
|
|
|
if params[:course_id] #如果带了课程id过来,说明这是课程大纲,不要删除,只需取消课程大纲就ok了
|
2015-10-30 10:52:56 +08:00
|
|
|
|
@course = Course.find(params[:course_id])
|
|
|
|
|
@course.outline = 0
|
|
|
|
|
@course.save
|
|
|
|
|
redirect_to course_path(:id=>params[:course_id])
|
2016-07-14 14:44:47 +08:00
|
|
|
|
elsif params[:user_activity_id]
|
|
|
|
|
@article.children.destroy
|
|
|
|
|
@article.destroy
|
|
|
|
|
redirect_to user_path(User.current.id)
|
2015-10-30 10:52:56 +08:00
|
|
|
|
else
|
2016-03-25 13:57:00 +08:00
|
|
|
|
@article.children.destroy
|
|
|
|
|
@article.destroy
|
2015-10-30 10:52:56 +08:00
|
|
|
|
redirect_to user_blogs_path(:user_id=>User.current)
|
|
|
|
|
end
|
|
|
|
|
|
2015-10-29 17:09:03 +08:00
|
|
|
|
else#如果是回复被删,
|
2015-10-30 10:52:56 +08:00
|
|
|
|
if params[:course_id] #如果带了course_id过来了,那么这是要跳到课程大纲去的
|
2016-03-25 13:57:00 +08:00
|
|
|
|
@article.destroy
|
2015-10-30 17:21:12 +08:00
|
|
|
|
redirect_to syllabus_course_path(:id=>params[:course_id])
|
2016-07-14 14:44:47 +08:00
|
|
|
|
elsif params[:user_activity_id]
|
|
|
|
|
if params[:homepage] && params[:homepage] == "1"
|
|
|
|
|
@in_user_homepage = true
|
|
|
|
|
end
|
|
|
|
|
@user_activity_id = params[:user_activity_id]
|
|
|
|
|
@blog_comment = @article.root
|
|
|
|
|
@article.destroy
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js
|
|
|
|
|
return
|
|
|
|
|
end
|
2015-10-29 17:09:03 +08:00
|
|
|
|
else
|
|
|
|
|
root = @article.root
|
2016-03-25 13:57:00 +08:00
|
|
|
|
@article.destroy
|
2015-10-29 17:09:03 +08:00
|
|
|
|
redirect_to user_blog_blog_comment_path(:user_id=>root.author_id,:blog_id=>root.blog_id,:id=>root.id)
|
|
|
|
|
end
|
|
|
|
|
|
2015-10-24 15:34:43 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def edit
|
|
|
|
|
@article = BlogComment.find(params[:id])
|
2016-03-16 10:00:21 +08:00
|
|
|
|
if User.current.admin? || User.current.id == @article.author_id
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html { render :layout => 'new_base_user' }
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
render_403
|
2015-10-24 15:34:43 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def quote
|
|
|
|
|
@blogComment = BlogComment.find(params[:id])
|
|
|
|
|
|
|
|
|
|
@temp = BlogComment.new
|
2015-10-29 17:09:03 +08:00
|
|
|
|
@course_id = params[:course_id]
|
2015-10-24 15:34:43 +08:00
|
|
|
|
respond_to do | format|
|
|
|
|
|
format.js
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#回复
|
|
|
|
|
def reply
|
2016-07-14 14:44:47 +08:00
|
|
|
|
if params[:homepage] && params[:homepage] == "1"
|
2016-07-07 10:42:51 +08:00
|
|
|
|
@in_user_homepage = true
|
|
|
|
|
end
|
2015-10-28 10:58:37 +08:00
|
|
|
|
if params[:in_user_center]
|
|
|
|
|
@in_user_center = true
|
|
|
|
|
end
|
2015-10-24 15:34:43 +08:00
|
|
|
|
@article = BlogComment.find(params[:id]).root
|
|
|
|
|
@blogComment = BlogComment.new
|
|
|
|
|
@blogComment.author = User.current
|
|
|
|
|
@blogComment.blog = Blog.find(params[:blog_id])
|
|
|
|
|
params[:blog_comment][:sticky] = params[:blog_comment][:sticky] || 0
|
|
|
|
|
params[:blog_comment][:locked] = params[:blog_comment][:locked] || 0
|
|
|
|
|
@blogComment.safe_attributes = params[:blog_comment]
|
|
|
|
|
@blogComment.title = "RE: #{@article.title}" unless params[:blog_comment][:title]
|
2016-07-14 14:44:47 +08:00
|
|
|
|
if params[:parent_id]
|
2016-07-13 15:20:39 +08:00
|
|
|
|
@blogComment.content = params[:blog_comment][:content]
|
|
|
|
|
parent = BlogComment.find params[:parent_id]
|
2016-07-20 17:00:18 +08:00
|
|
|
|
@blogComment.reply_id = params[:id]
|
2016-10-11 14:08:44 +08:00
|
|
|
|
@blogComment.root_id = parent.root_id.nil? ? parent.id : parent.root_id
|
2016-07-13 15:20:39 +08:00
|
|
|
|
parent.children << @blogComment
|
|
|
|
|
else
|
2016-07-14 14:44:47 +08:00
|
|
|
|
@quote = params[:quote][:quote] || ""
|
2016-07-13 15:20:39 +08:00
|
|
|
|
@blogComment.content = @quote + @blogComment.content
|
2016-10-11 14:08:44 +08:00
|
|
|
|
@blogComment.root_id = @article.id
|
2016-07-13 15:20:39 +08:00
|
|
|
|
@article.children << @blogComment
|
|
|
|
|
end
|
2015-12-17 10:19:43 +08:00
|
|
|
|
@article.save
|
2016-01-22 18:42:50 +08:00
|
|
|
|
# @article.update_attribute(:updated_on, @blogComment.updated_on)
|
2015-10-24 15:34:43 +08:00
|
|
|
|
@user_activity_id = params[:user_activity_id]
|
2015-10-28 11:13:59 +08:00
|
|
|
|
user_activity = UserActivity.where("act_type='BlogComment' and act_id =#{@article.id}").first
|
|
|
|
|
if user_activity
|
|
|
|
|
user_activity.updated_at = Time.now
|
|
|
|
|
user_activity.save
|
|
|
|
|
end
|
2015-10-24 15:34:43 +08:00
|
|
|
|
attachments = Attachment.attach_files(@blogComment, params[:attachments])
|
|
|
|
|
render_attachment_warning_if_needed(@blogComment)
|
|
|
|
|
#@article.save
|
|
|
|
|
# redirect_to user_blogs_path(:user_id=>params[:user_id])
|
|
|
|
|
respond_to do |format|
|
2015-10-29 17:09:03 +08:00
|
|
|
|
format.html {
|
|
|
|
|
if params[:course_id] #如果呆了course_id过来了,那么这是要跳到课程大纲去的
|
2015-10-30 17:21:12 +08:00
|
|
|
|
redirect_to syllabus_course_path(:id=>params[:course_id])
|
2015-10-29 17:09:03 +08:00
|
|
|
|
else
|
|
|
|
|
redirect_to user_blog_blog_comment_path(:user_id=>@article.author_id,:blog_id=>@article.blog_id,:id=>@article)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
}
|
2015-10-24 15:34:43 +08:00
|
|
|
|
format.js
|
|
|
|
|
end
|
|
|
|
|
rescue Exception => e #如果上面的代码执行发生异常就捕获
|
|
|
|
|
flash[:notice] = e.message
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
def find_user
|
|
|
|
|
@user = User.find(params[:user_id])
|
|
|
|
|
end
|
|
|
|
|
end
|