307 lines
9.6 KiB
PHP
307 lines
9.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Report;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\JsonResponse;
|
|
use App\Http\Requests;
|
|
use App\Http\Controllers\Controller;
|
|
|
|
class ReportController extends Controller
|
|
{
|
|
|
|
private $fromMail = "bullshit@w0bm.com";
|
|
private $fromName = "w0bm";
|
|
private $toMail = "admin@w0bm.com";
|
|
private $toName = "w0bm";
|
|
private $subject = "webm reported";
|
|
private $baseURL = "https://w0bm.com/";
|
|
|
|
/**
|
|
* Made by klee
|
|
* Testing to make report crap
|
|
*
|
|
*/
|
|
public function report(Request $request)
|
|
{
|
|
if(is_array($request->input('reportReasons'))) {
|
|
$reportReasons = "<li>".implode("</li><li>", $request->input('reportReasons'));
|
|
} else {
|
|
$reportReasons = "<li>".$request->input('reportReasons')."</li>";
|
|
}
|
|
|
|
if($request->user()->username == "" || $request->user()->username == null) {
|
|
$username = "User is <b>anonymous</b> because he is not registered";
|
|
} else {
|
|
$username = $request->user()->username;
|
|
}
|
|
|
|
$data = array(
|
|
"videoURL" => $this->baseURL.$request->route('id'),
|
|
"reportReasons" => $reportReasons,
|
|
"reportText" => htmlspecialchars($request->input('reportText')),
|
|
"username" => $username,
|
|
"videoID" => $request->route('id'),
|
|
"message" => array(
|
|
"html" => 'html message',
|
|
"text" => 'text message',
|
|
"to" => array(
|
|
array("name" => 'admin@w0bm.com', "email" => 'admin@w0bm.com')
|
|
),
|
|
"from_email" => 'bullshit@w0bm.com',
|
|
"from_name" => 'from w0bm',
|
|
"subject" => 'the subject',
|
|
"track_opens" => true,
|
|
"track_clicks" => true
|
|
),
|
|
"async" => false,
|
|
"debugOutput" => print_r(get_class_methods($request), true).print_r($request->route()->parameters(), true)
|
|
);
|
|
//$postString = json_encode($data);
|
|
|
|
\Mail::send('emails.report', $data, function ($msg) {
|
|
$msg->from($this->fromMail, $this->fromName);
|
|
$msg->to($this->toMail, $this->toName);
|
|
$msg->subject($this->subject);
|
|
});
|
|
|
|
return redirect()->back()->with('success', 'Report successfully sent');;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
/*
|
|
if(!$request->has('username')) return JsonResponse::create('Not found', '304');
|
|
$user = User::whereUsername(urldecode($request->get('username')))->first();
|
|
if(!$user) return JsonResponse::create('Not found', '304');
|
|
return $user->comments()->orderBy('id', 'desc')->paginate(10);
|
|
*/
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(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'))) > 2000 ) 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();
|
|
|
|
$sent = [];
|
|
foreach($com->getMentioned() as $mentioned) {
|
|
Message::send($user->id, $mentioned->id, $user->username . ' mentioned you in a comment', view('messages.commentmention', ['video' => $video, 'user' => $user, 'comment' => $com]));
|
|
$sent[] = $mentioned;
|
|
}
|
|
|
|
foreach($com->answered() as $answered) {
|
|
if(array_search($answered, $sent) !== false)
|
|
continue;
|
|
Message::send($user->id, $answered->id, $user->username . ' answered on your comment', view('messages.commentanswer', ['video' => $video, 'user' => $user, 'comment' => $com]));
|
|
$sent[] = $answered;
|
|
}
|
|
|
|
if($user->id != $video->user->id)
|
|
if(array_search($video->user, $sent) === false)
|
|
Message::send($user->id, $video->user->id, $user->username . ' commented on your video', view('messages.videocomment', ['video' => $video, 'user' => $user, 'comment' => $com]));
|
|
|
|
return $xhr ? view('partials.comment', ['comment' => $com, 'mod' => $user->can('delete_comment')]) : redirect()->back()->with('success', 'Comment successfully saved');
|
|
*/
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
/*
|
|
$comment = Comment::whereId($id)->first();
|
|
if(!is_null($comment)) {
|
|
return JsonResponse::create(array(
|
|
'error' => 'null',
|
|
'comment' => Comment::whereId($id)->first()->content)
|
|
);
|
|
}
|
|
return JsonResponse::create(array(
|
|
'error' => 'comment_not_found'
|
|
));
|
|
*/
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
/*
|
|
if(!($request->has('comment')))
|
|
return JsonResponse::create(array('error' => 'invalid_request'));
|
|
|
|
$user = auth()->check() ? auth()->user() : null;
|
|
if(is_null($user))
|
|
return JsonResponse::create(array('error' => 'not_logged_in'));
|
|
|
|
if(!$user->can('edit_comment'))
|
|
return JsonResponse::create(array('error' => 'insufficient_permissions'));
|
|
|
|
if(is_null($comment = Comment::whereId($id)->first()))
|
|
return JsonResponse::create(array('error' => 'comment_not_found'));
|
|
|
|
$comment->content = trim($request->get('comment'));
|
|
$comment->save();
|
|
|
|
$log = new ModeratorLog();
|
|
$log->user()->associate($user);
|
|
$log->type = 'edit';
|
|
$log->target_type = 'comment';
|
|
$log->target_id = $id;
|
|
$log->save();
|
|
*/
|
|
|
|
return JsonResponse::create(array(
|
|
'error' => 'null',
|
|
'rendered_comment' => "test rendered comment"//Comment::simplemd($comment->content)
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(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::whereId($id)->first();
|
|
if(is_null($comment))
|
|
return 'comment_not_found';
|
|
|
|
$receiver = $comment->user;
|
|
$video = $comment->video;
|
|
Comment::destroy($id);
|
|
|
|
if($user->id != $receiver->id)
|
|
Message::send(1, $receiver->id, 'A moderator deleted your comment', view('messages.moderation.commentdelete', ['video' => $video, 'comment' => $comment, 'reason' => $reason]));
|
|
|
|
$log = new ModeratorLog();
|
|
$log->user()->associate($user);
|
|
$log->type = 'delete';
|
|
$log->target_type = 'comment';
|
|
$log->target_id = $id;
|
|
$log->reason = $reason;
|
|
$log->save();
|
|
*/
|
|
|
|
return 'success';
|
|
}
|
|
|
|
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';
|
|
}
|
|
}
|
|
|