public function restore(Request $request, $id) { if (!$request->has('reason')) { return 'invalid_request'; } $reason = trim($request->get('reason')); if ($reason == '') { return 'invalid_request'; } $user = auth()->check() ? auth()->user() : null; if (is_null($user)) { return 'not_logged_in'; } if (!$user->can('delete_comment')) { return 'insufficient_permissions'; } $comment = Comment::withTrashed()->whereId($id)->first(); if (is_null($comment)) { return 'comment_not_found'; } if (!$comment->trashed()) { return 'comment_not_deleted'; } $receiver = $comment->user; $video = $comment->video; $comment->restore(); if ($user->id != $receiver->id) { Message::send(1, $receiver->id, 'A moderator restored your comment', view('messages.moderation.commentrestore', ['video' => $video, 'comment' => $comment, 'reason' => $reason])); } $log = new ModeratorLog(); $log->user()->associate($user); $log->type = 'restore'; $log->target_type = 'comment'; $log->target_id = $id; $log->reason = $reason; $log->save(); return 'success'; }
/** * Remove the specified resource from storage. * * @param int $id * @return \Response */ public function destroy(Request $request, $id) { $user = auth()->check() ? auth()->user() : null; if (is_null($user)) { return new JsonResponse(['error' => 'not_logged_in']); } if (!$request->has('reason') || trim($request->get('reason')) == '') { return new JsonResponse(['error' => 'invalid_request']); } $reason = trim($request->get('reason')); if ($user->can('delete_video')) { $warnings = []; $vid = Video::find($id); if (!$vid) { return new JsonResponse(['error' => 'video_not_found']); } foreach ($vid->comments as $comment) { $comment->delete(); // delete associated comments } $vid->faved()->detach(); if (!\File::move(public_path() . '/b/' . $vid->file, storage_path() . '/deleted/' . $vid->file)) { $warnings[] = 'Could not move file'; } $vid->delete(); $receiver = $vid->user; if ($user->id != $receiver->id) { Message::send(1, $receiver->id, 'A moderator deleted your video', view('messages.moderation.videodelete', ['video' => $vid, 'reason' => $reason, 'videoinfo' => ['artist' => $vid->interpret, 'songtitle' => $vid->songtitle, 'video_source' => $vid->imgsource, 'category' => $vid->category->name]])); } $log = new ModeratorLog(); $log->user()->associate($user); $log->type = 'delete'; $log->target_type = 'video'; $log->target_id = $id; $log->reason = $reason; $log->save(); return new JsonResponse(['error' => 'null', 'warnings' => $warnings]); } return new JsonResponse(['error' => 'insufficient_permissions']); }
public function storeComment(Request $request, $id) { $user = auth()->check() ? auth()->user() : null; $xhr = $request->ajax(); if (is_null($user)) { return $xhr ? "Not logged in" : redirect()->back()->with('error', 'Not logged in'); } if (!$request->has('comment')) { return $xhr ? "You need to enter a comment" : redirect()->back()->with('error', 'You need to enter a comment'); } if (mb_strlen(trim($request->get('comment'))) > 1000) { return $xhr ? "Comment to long" : redirect()->back()->with('error', 'Comment to long'); } $video = Video::findOrFail($id); $com = new Comment(); $com->content = trim($request->get('comment')); $com->user()->associate($user); $com->video()->associate($video); $com->save(); foreach ($com->getMentioned() as $mentioned) { if (!Message::send($user->id, $mentioned->id, $user->username . ' mentioned you in a comment', view('messages.commentmention', ['video' => $video, 'user' => $user]))) { } } if (!Message::send($user->id, $video->user->id, $user->username . ' commented on your video', view('messages.videocomment', ['video' => $video, 'user' => $user]))) { } return $xhr ? view('partials.comment', ['comment' => $com, 'mod' => $user->can('delete_comment')]) : redirect()->back()->with('success', 'Comment successfully saved'); }