Example #1
0
 public function vote($isGood = false)
 {
     $vote = $this->myVote;
     if (empty($vote)) {
         $vote = new CommentVote(['commentID' => $this->id]);
     }
     $vote->operation = $isGood ? CommentVote::OPERATION_GOOD : CommentVote::OPERATION_BAD;
     $vote->save(false);
     return $vote->operation;
 }
Example #2
0
 public function dislikeCommentPost()
 {
     $id = Input::get('id');
     $oppositeVote = CommentVote::where('type', 'like')->where('user_id', Auth::id())->where('comment_id', $id)->first();
     if (!empty($oppositeVote)) {
         $oppositeVote->delete();
     }
     $vote = new CommentVote();
     $vote->user_id = Auth::id();
     $vote->comment_id = $id;
     $vote->type = 'dislike';
     $vote->save();
     return 'success';
 }
Example #3
0
					@else
						<h5>{{ Lang::get('lang.add_a_comment') }}</h5>
						<img src="{{ Config::get('site.uploads_dir') }}/avatars/{{ Auth::user()->avatar }}" class="user-avatar-small img-rounded" style="width:8.5%; margin-right:1.5%" /><textarea placeholder="{{ Lang::get('lang.write_comment_here') }}" class="form-control" style="border-width:2px; width:90%;" id="comment"></textarea>
						<div class="btn pull-right btn-color" style="margin-top:15px;" id="comment-submit">{{ Lang::get('lang.post_comment_btn') }}</div><div style="clear:both"></div>
						<input type="hidden" name="media_id" id="media_id" value="{{ $media->id }}" />
					@endif
				</div>
				<div style="clear:both"></div><br />
				<div class="comment-loop">
				@foreach($media->comments()->orderBy('created_at', 'desc')->get() as $comment)

					<div class="comment comment-{{ $comment->id }}">
						
						@if(!Auth::guest())
							<?php 
$user_vote = CommentVote::where('user_id', '=', Auth::user()->id)->where('comment_id', '=', $comment->id)->first();
?>
						@endif

						<div class="comment_vote pull-left">
							<i class="fa fa-chevron-up vote-up @if(isset($user_vote->up) && $user_vote->up) active @endif" data-commentid="{{ $comment->id }}"></i>
							<p>{{ $comment->totalVotes() }}</p>
							<i class="fa fa-chevron-down vote-down @if(isset($user_vote->down) && $user_vote->down == 1) active @endif" data-commentid="{{ $comment->id }}"></i>
						</div>

						@if(!Auth::guest())
							
							<div class="flag_edit_delete_comment">
								<a class="flag_comment" data-id="{{ $comment->id }}"><i class="fa fa-flag"></i> + <span class="num_flags">{{ $comment->totalFlags() }}</span></a>@if(Auth::user()->id == $comment->user_id  || Auth::user()->admin == 1)<a class="edit_comment" data-id="{{ $comment->id }}"><i class="fa fa-edit"></i></a><a class="delete_comment" data-id="{{ $comment->id }}"><i class="fa fa-trash-o"></i></a>@endif
							</div>
Example #4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function delete($id)
 {
     $media = Media::find($id);
     if ($media->user_id == Auth::user()->id || Auth::user()->admin == 1) {
         $media_flags = MediaFlag::where('media_id', '=', $id)->get();
         foreach ($media_flags as $media_flag) {
             $media_flag->delete();
         }
         $media_likes = MediaLike::where('media_id', '=', $id)->get();
         foreach ($media_likes as $media_like) {
             $media_like->delete();
         }
         $comments = Comment::where('media_id', '=', $id)->get();
         foreach ($comments as $comment) {
             $comment_votes = CommentVote::where('comment_id', '=', $comment->id)->get();
             foreach ($comment_votes as $comment_vote) {
                 $comment_vote->delete();
             }
             $comment_flags = CommentFlag::where('comment_id', '=', $comment->id)->get();
             foreach ($comment_flags as $comment_flag) {
                 $comment_flag->delete();
             }
             $comment->delete();
         }
         // if the media type is a gif we need to remove the animation file too.
         if (strpos($media->pic_url, '.gif') > 0) {
             if (file_exists(Config::get('site.uploads_dir') . 'images/' . str_replace(".gif", "-animation.gif", $media->pic_url))) {
                 unlink(Config::get('site.uploads_dir') . 'images/' . str_replace(".gif", "-animation.gif", $media->pic_url));
             }
         }
         // remove the image
         if (file_exists(Config::get('site.uploads_dir') . 'images/' . $media->pic_url)) {
             unlink(Config::get('site.uploads_dir') . 'images/' . $media->pic_url);
         }
         $media->delete();
     }
     return Redirect::to('admin?section=media')->with(array('note' => Lang::get('lang.delete_success'), 'note_type' => 'success'));
 }
Example #5
0
    public function ajaxloadcomment()
    {
        $type = Input::get('type');
        $counter = Input::get('count');
        $postid = Input::get('postid');
        $post = Post::find($postid);
        $skip = $counter * 3;
        $nextskip = ($counter + 1) * 3;
        switch ($type) {
            case 'all':
                $comments = Comment::where('post_id', $postid)->where('parent_comment_id', 0)->orderBy('created_at', 'desc')->take(3)->skip($skip)->get();
                $nextcomments = Comment::where('post_id', $postid)->where('parent_comment_id', 0)->orderBy('created_at', 'desc')->take(3)->skip($nextskip)->count();
                break;
            case 'attack':
                $comments = Comment::where('post_id', $postid)->where('type', 'attack')->where('parent_comment_id', 0)->orderBy('created_at', 'desc')->take(3)->skip($skip)->get();
                $nextcomments = Comment::where('post_id', $postid)->where('type', 'attack')->where('parent_comment_id', 0)->orderBy('created_at', 'desc')->take(3)->skip($nextskip)->count();
                break;
            case 'assist':
                $comments = Comment::where('post_id', $postid)->where('type', 'assist')->where('parent_comment_id', 0)->orderBy('created_at', 'desc')->take(3)->skip($skip)->get();
                $nextcomments = Comment::where('post_id', $postid)->where('type', 'assist')->where('parent_comment_id', 0)->orderBy('created_at', 'desc')->take(3)->skip($nextskip)->count();
                break;
            case 'defense':
                $comments = Comment::where('post_id', $postid)->where('type', 'defense')->where('parent_comment_id', 0)->orderBy('created_at', 'desc')->take(3)->skip($skip)->get();
                $nextcomments = Comment::where('post_id', $postid)->where('type', 'defense')->where('parent_comment_id', 0)->orderBy('created_at', 'desc')->take(3)->skip($nextskip)->count();
                break;
        }
        $result = '';
        if (!empty($comments)) {
            foreach ($comments as $comment) {
                $commentVotesLike = CommentVote::where('type', 'like')->where('comment_id', $comment->id)->count();
                $commentVotesDislike = CommentVote::where('type', 'dislike')->where('comment_id', $comment->id)->count();
                if (!empty($comment->image)) {
                    $commenttype = '<br><br><img src="' . asset('images/icon_' . $comment->type . '.jpg') . '" width="10"> ' . ucfirst($comment->type) . '&nbsp;&nbsp;';
                } else {
                    $commenttype = '';
                }
                if (Auth::user()) {
                    $comment->load(array('votes' => function ($query) {
                        $query->where('user_id', Auth::id());
                    }));
                    if (!empty($comment->votes->first()) && $comment->votes->first()->type == 'like') {
                        $likeButtonClass = 'btn-success disabledlike';
                    } else {
                        $likeButtonClass = 'btn-default clike';
                    }
                    if (!empty($comment->votes->first()) && $comment->votes->first()->type == 'dislike') {
                        $dislikeButtonClass = 'btn-danger disabledlike';
                    } else {
                        $dislikeButtonClass = 'btn-default cdislike';
                    }
                    $likeButton = '<button class="btn ' . $likeButtonClass . '" data-id="' . $comment->id . '"><i class="glyphicon glyphicon-thumbs-up"></i></button>
                        <button class="btn ' . $dislikeButtonClass . '" data-id="' . $comment->id . '"><i class="glyphicon glyphicon-thumbs-down"></i></button>';
                    $buttonReplyComment = '<div class="col-sm-12">
                      <p class="mt10"><button class="btn btn-default reply-comment">Reply this comment</button></p>
                    </div>';
                } else {
                    $likeButton = '<button class="btn disabledlike" data-toggle="modal" data-target="#modalSignin"><i class="glyphicon glyphicon-thumbs-up"></i></button>
                        <button class="btn disabledlike" data-toggle="modal" data-target="#modalSignin"><i class="glyphicon glyphicon-thumbs-down"></i></button>';
                    $buttonReplyComment = '';
                }
                if (!empty($comment->image)) {
                    $image = '<img src="' . asset('comments/' . $postid . '/' . $comment->image) . '">';
                } else {
                    $image = '';
                }
                if (!empty($comment->user->profile_pic)) {
                    $pp = '<a href="' . url('profile/' . $comment->user->username) . '"><img src="' . asset('usr/pp/' . $comment->user->profile_pic) . '"></a>';
                } else {
                    $pp = '<a href="' . url('profile/' . $comment->user->username) . '"><img src="' . asset('images/user.jpg') . '"></a>';
                }
                $delcomment = '';
                if (Auth::id() && Auth::user()->status == 'management') {
                    $delcomment = '<div class="pull-right"><a class="btn btn-default delcomment" data-id="' . $comment->id . '"><i class="fa fa-close"></i></a></div>';
                } else {
                    if (Auth::id() == $comment->user_id) {
                        $delcomment = '<div class="pull-right"><a class="btn btn-default delcomment" data-id="' . $comment->id . '"><i class="fa fa-close"></i></a></div>';
                    }
                }
                if (empty($comment->deleted_at)) {
                    $content = '<a href="' . url('profile/' . $comment->user->username) . '"><b>' . $comment->user->username . '</b></a>
                          
                          <br><font color="#888">' . $commentVotesLike . ' likes, ' . $commentVotesDislike . ' dislikes</font> , <small class="text-muted">posted at ' . date('d F Y,H:i', strtotime($comment->created_at)) . '</small>
                          ' . $commenttype . ' ' . $likeButton . '
	                       ' . $delcomment . '   
	                    
	                  <br><br>
	                  <p>' . $comment->text . '</p>
	                  	' . $image . '
	                  	<div class="row">
	                  	' . $buttonReplyComment . '
	                  	<div class="col-sm-12 hidden">
                       <span class="btn btn-default fileinput-button">
                           <i class="glyphicon glyphicon-plus"></i>
                           <span>Add image...</span>
                           <!-- The file input field used as target for the file upload widget -->
                           <input class="commentupload" data-id="' . $comment->id . '" data-type="' . $type . '" type="file" name="files">
                       </span>
                       <br><br>
                       <!-- The global progress bar -->
                       <div id="progress' . $comment->id . '-' . $type . '" class="progress">
                           <div class="progress-bar progress-bar-success"></div>
                       </div>
                       <!-- The container for the uploaded files -->
                       <div id="files' . $comment->id . '-' . $type . '" class="files"></div>

                       <form role="form" class="form-reply-comment" action="' . url('insertcomment') . '">
                       <div class="errormsg"></div>
                       <div class="form-group">
                         <input type="hidden" name="post_id" value="' . $postid . '">
                         <input type="hidden" name="comment_id" value="' . $comment->id . '">
                         <input type="hidden" name="img" id="imgurl' . $comment->id . '-' . $type . '">
                         <textarea name="text" class="comment-textarea form-control mb10" rows="3"></textarea>
                       </div>
                       <span class="commentspinner" style="display:none"><center><i class="fa fa-spinner"></i><br>
        loading</center></span>
                       <div class="pull-right"><button type="submit" class="btn btn-info">Submit</button></div>
                       </form>
                       </div>
                   </div>';
                } else {
                    $content = 'This comment has been deleted by user';
                }
                $result .= '<div class="userComment  mt30 row">
                        <div class="col-xs-3 imgWrap">
                            ' . $pp . '
                        </div>
                        <div class="col-xs-9 col-sm-9 detailPost">
                          ' . $content . '
                     
                        ';
                // $result.= '<div class="row commentbox">
                //   <div class="col-sm-3">
                //     '.$pp.'
                //   </div>
                //   <div class="col-sm-9">
                //     <div class="row">
                //       <div class="col-sm-6">
                //         <b>'.$comment->user->username.'</b> &nbsp;&nbsp;
                //         <br><font color="#888">'.$commentVotesLike.' likes, '.$commentVotesDislike.' dislikes</font>
                //         <br><small class="text-muted">posted at '.date('d F Y,H:i',strtotime($comment->created_at)).'</small>
                //       </div>
                //       <div class="col-sm-6">
                //         <div class="pull-right">
                //           '.$commenttype.'
                //           '.$likeButton.'
                //         </div>
                //       </div>
                //     </div>
                //     <br><br>
                //     <p>'.$comment->text.'</p>
                //     '.$image.'
                //     <div class="row">
                //      '.$buttonReplyComment.'
                //       <div class="col-sm-12 hidden">
                //         <span class="btn btn-success fileinput-button">
                //             <i class="glyphicon glyphicon-plus"></i>
                //             <span>Add image...</span>
                //             <!-- The file input field used as target for the file upload widget -->
                //             <input class="commentupload" data-id="'.$comment->id.'" data-type="'.$type.'" type="file" name="files">
                //         </span>
                //         <br><br>
                //         <!-- The global progress bar -->
                //         <div id="progress'.$comment->id.'-'.$type.'" class="progress">
                //             <div class="progress-bar progress-bar-success"></div>
                //         </div>
                //         <!-- The container for the uploaded files -->
                //         <div id="files'.$comment->id.'-'.$type.'" class="files"></div>
                //         <form role="form" class="form-reply-comment" action="'.url('insertcomment').'">
                //         <div class="errormsg"></div>
                //         <div class="form-group">
                //           <input type="hidden" name="post_id" value="'.$postid.'">
                //           <input type="hidden" name="comment_id" value="'.$comment->id.'">
                //           <input type="hidden" name="img" id="imgurl'.$comment->id.'-'.$type.'">
                //           <textarea name="text" class="comment-textarea"></textarea>
                //         </div>
                //         <div class="pull-right"><button type="submit" class="btn btn-info">Submit</button></div>
                //         </form>
                //       </div>
                //     </div>';
                $childs = Comment::withTrashed()->where('parent_comment_id', $comment->id)->get();
                if ($childs) {
                    foreach ($childs as $cmt) {
                        if (!empty($cmt->user->profile_pic)) {
                            $pp = '<a href="' . url('profile/' . $cmt->user->username) . '"><img src="' . asset('usr/pp/' . $cmt->user->profile_pic) . '" width="50"></a>';
                        } else {
                            $pp = '<a href="' . url('profile/' . $cmt->user->username) . '"><img src="' . asset('images/user.jpg') . '" width="50"></a>';
                        }
                        if ($cmt->image) {
                            $commentImage = '<img src="' . asset('comments/' . $postid . '/' . $cmt->image) . '">';
                        } else {
                            $commentImage = '';
                        }
                        $delcomment = '';
                        if (Auth::id() && Auth::user()->status == 'management') {
                            $delcomment = '<div class="pull-right"><a class="btn btn-default delcomment" data-id="' . $cmt->id . '"><i class="fa fa-close"></i></a></div>';
                        } else {
                            if (Auth::id() == $cmt->user_id) {
                                $delcomment = '<div class="pull-right"><a class="btn btn-default delcomment" data-id="' . $cmt->id . '"><i class="fa fa-close"></i></a></div>';
                            }
                        }
                        if (!empty($cmt->deleted_at)) {
                            $content = 'This comment has been deleted by user';
                        } else {
                            $content = $delcomment . '
		                      <p><b><a href="' . url('profile/' . $cmt->user->username) . '">' . $cmt->user->username . '</a> commented :</b>
		                      <br>
                        <img src="' . asset('images/icon_' . $cmt->type . '.jpg') . '" width="10"> ' . ucfirst($cmt->type) . '&nbsp;&nbsp;
		                      <br> ' . $cmt->text . '</p>
		                      ' . $commentImage;
                        }
                        $result .= '<div class="row mb10 mt30">
		                    <div class="col-sm-3">
		                      ' . $pp . '
		                    </div>
		                    <div class="col-sm-9">
		                      ' . $content . '
		                    </div>
		                  </div>';
                    }
                }
                if ($nextcomments < 3) {
                    $isEnd = '<end></end>';
                } else {
                    $isEnd = '';
                }
                $result .= "</div></div>\n                  \t\t\t\t" . $isEnd . "\n                  \t\t\t\t<script>\n                  \t\t\t\t\$('.commentupload').fileupload({\n\t\t\t\t\t\t\t        url: url,\n\t\t\t\t\t\t\t        dataType: 'json',\n\t\t\t\t\t\t\t        autoUpload: false,\n\t\t\t\t\t\t\t        acceptFileTypes: /(\\.|\\/)(gif|jpe?g|png)\$/i,\n\t\t\t\t\t\t\t        maxFileSize: 999000,\n\t\t\t\t\t\t\t        // Enable image resizing, except for Android and Opera,\n\t\t\t\t\t\t\t        // which actually support image resizing, but fail to\n\t\t\t\t\t\t\t        // send Blob objects via XHR requests:\n\t\t\t\t\t\t\t        disableImageResize: /Android(?!.*Chrome)|Opera/\n\t\t\t\t\t\t\t            .test(window.navigator.userAgent),\n\t\t\t\t\t\t\t        previewMaxWidth: 100,\n\t\t\t\t\t\t\t        previewMaxHeight: 100,\n\t\t\t\t\t\t\t        previewCrop: true\n\t\t\t\t\t\t\t    });\n                  \t\t\t\t</script>\n                  \t\t\t";
            }
            //endforeach
            return $result;
        } else {
            return 'null';
        }
    }
 public function delete_comment($id)
 {
     $comment = Comment::find($id);
     if (Auth::user()->id == $comment->user_id || Auth::user()->admin == 1) {
         $comment_votes = CommentVote::where('comment_id', '=', $id)->get();
         foreach ($comment_votes as $votes) {
             $votes->delete();
         }
         $comment_flags = CommentFlag::where('comment_id', '=', $id)->get();
         foreach ($comment_flags as $flag) {
             $flag->delete();
         }
         $comment->delete();
         return 1;
     } else {
         return 0;
     }
 }
Example #7
0
 /**
  * Adds one point(either like or dislike) for the current model.
  * @param int $comment_id of the comment
  * @param int $vote wether like or dislike
  * @param int $user_id the user id
  * @return Array with the success(boolean indicating success or not), comment_id, likes and dislikes count
  */
 public function add_vote($comment_id, $vote, $user_id)
 {
     $model = Comment::model()->findByPk((int) $comment_id);
     if ($model === null) {
         return array('success' => false, 'message' => Yii::t('comment', 'The comment_id was not found.'));
     }
     $likes = $model->likes;
     $dislikes = $model->dislikes;
     $model2 = new CommentVote();
     $model2->comment_id = $comment_id;
     $model2->user_id = $user_id;
     $model2->vote = $vote == "like" ? 1 : 0;
     $model2->time = SiteLibrary::utc_time();
     if (!$model2->save()) {
         return array('success' => false, 'message' => Yii::t('comment', 'Only one vote per user allowed.'));
     }
     if ($vote == "like") {
         $model->likes = $model->likes + 1;
         $likes = $model->likes;
     } else {
         $model->dislikes = $model->dislikes + 1;
         $dislikes = $model->dislikes;
     }
     $model->save();
     //Update Live comments table if needed(if record doesnt exists, it simply wont update anything)
     Yii::app()->db->createCommand()->update('live_comment', array('likes' => $likes, 'dislikes' => $dislikes), 'comment_id=:comment_id', array(':comment_id' => $comment_id));
     return array('success' => true, 'comment_id' => $comment_id, 'likes' => $likes, 'dislikes' => $dislikes);
 }
Example #8
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function delete($id)
 {
     $media = Media::find($id);
     if ($media->user_id == Auth::user()->id || Auth::user()->admin == 1) {
         $media_flags = MediaFlag::where('media_id', '=', $id)->get();
         foreach ($media_flags as $media_flag) {
             $media_flag->delete();
         }
         $media_likes = MediaLike::where('media_id', '=', $id)->get();
         foreach ($media_likes as $media_like) {
             $media_like->delete();
         }
         $comments = Comment::where('media_id', '=', $id)->get();
         foreach ($comments as $comment) {
             $comment_votes = CommentVote::where('comment_id', '=', $comment->id)->get();
             foreach ($comment_votes as $comment_vote) {
                 $comment_vote->delete();
             }
             $comment_flags = CommentFlag::where('comment_id', '=', $comment->id)->get();
             foreach ($comment_flags as $comment_flag) {
                 $comment_flag->delete();
             }
             $comment->delete();
         }
         $arrayPicUrl = explode("/", $media->pic_url);
         // if the media type is a gif we need to remove the animation file too.
         if (strpos($media->pic_url, '.gif') > 0) {
             \Cloudinary\Uploader::destroy(Constant::FOLDER_CLOUDINARY . '/' . $arrayPicUrl[0] . '/' . pathinfo(str_replace(".gif", "-animation.gif", $media->pic_url), PATHINFO_FILENAME));
         }
         // remove the image
         \Cloudinary\Uploader::destroy(Constant::FOLDER_CLOUDINARY . '/' . $arrayPicUrl[0] . '/' . pathinfo($media->pic_url, PATHINFO_FILENAME));
         $media->delete();
     }
     return Redirect::to('admin?section=media')->with(array('note' => Lang::get('lang.delete_success'), 'note_type' => 'success'));
 }
Example #9
0
function ajax_vote_comment()
{
    if (Auth::guest()) {
        exit;
    }
    $comment_id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
    $type = isset($_POST['type']) ? (int) $_POST['type'] : 0;
    $user_id = Auth::user()->id;
    if (!($comment = Comment::find($comment_id))) {
        json_message(trans('comments.404'), false);
    }
    $vote = CommentVote::where('comment_id', $comment_id)->where('user_id', $user_id)->first();
    // Remove upvote / downvote
    if ($type == 1 || $type == 2) {
        if ($vote) {
            if ($type == 1) {
                $comment->upvotes = absint($comment->upvotes - 1);
            } else {
                $comment->downvotes = absint($comment->downvotes - 1);
            }
            $vote->delete();
        }
    } elseif ($type == 3 || $type == 4) {
        if ($type == 3) {
            $comment->upvotes = $comment->upvotes + 1;
        } else {
            $comment->downvotes = $comment->downvotes + 1;
        }
        if ($vote) {
            if ($type == 3) {
                $comment->downvotes = absint($comment->downvotes - 1);
            } else {
                $comment->upvotes = absint($comment->upvotes - 1);
            }
            $vote->type = $type == 3 ? 1 : 2;
            $vote->save();
        } else {
            $type = $type == 3 ? 1 : 2;
            CommentVote::insert(compact('type', 'comment_id', 'user_id'));
        }
    } else {
        json_message('Invalid vote type.', false);
    }
    $comment->save();
    json_message(true);
}