1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* rmarchiv.tk |
5
|
|
|
* (c) 2016-2017 by Marcel 'ryg' Hering |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace App\Http\Controllers; |
9
|
|
|
|
10
|
|
|
use App\Events\Obyx; |
11
|
|
|
use App\Models\Game; |
12
|
|
|
use App\Models\Screenshot; |
13
|
|
|
use Illuminate\Http\Request; |
14
|
|
|
use Illuminate\Http\UploadedFile; |
15
|
|
|
use Intervention\Image\Facades\Image; |
16
|
|
|
|
17
|
|
|
class ScreenshotController extends Controller |
18
|
|
|
{ |
19
|
|
|
public function show($gameid, $screenid, $full = null) |
20
|
|
|
{ |
21
|
|
|
$s = Screenshot::whereGameId($gameid)->where('screenshot_id', $screenid) |
22
|
|
|
->first(); |
23
|
|
|
|
24
|
|
|
//Prüfen ob Screenshots vorhanden sind |
25
|
|
|
if (!$s) {//Es sind keine Screenshots vorhanden |
26
|
|
|
$storagePath = public_path().'/assets/no_image.png'; |
27
|
|
|
} else {//Es sind Screenshots vorhanden |
28
|
|
|
$storagePath = \Storage::get($s->filename); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$img = \Image::make($storagePath); |
32
|
|
|
if (! $full) { |
33
|
|
|
$response = \Response::make($img->encode('jpg', 80)); |
34
|
|
|
$response->header('Content-Type', 'image/jpg'); |
35
|
|
|
} else { |
36
|
|
|
$response = \Response::make($img->encode('png')); |
37
|
|
|
$response->header('Content-Type', 'image/png'); |
38
|
|
|
} |
39
|
|
|
//$response->setMaxAge(604800); |
|
|
|
|
40
|
|
|
//$etag = md5($s->id.'-'.$s->updated_at); |
|
|
|
|
41
|
|
|
//$response->setEtag($etag); |
|
|
|
|
42
|
|
|
//$response->setLastModified($s->updated_at); |
|
|
|
|
43
|
|
|
$response->setPublic(); |
44
|
|
|
|
45
|
|
|
return $response; |
46
|
|
|
|
47
|
|
|
//return Image::make($storagePath)->response(); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
View Code Duplication |
public function create($gameid, $screenid) |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
if (\Auth::check()) { |
53
|
|
|
$game = Game::whereId($gameid)->first(); |
54
|
|
|
|
55
|
|
|
return view('screenshots.create', [ |
56
|
|
|
'gameid' => $gameid, |
57
|
|
|
'screenid' => $screenid, |
58
|
|
|
'game' => $game, |
59
|
|
|
]); |
60
|
|
|
} else { |
61
|
|
|
return redirect()->back(); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function upload(Request $request, $gameid, $screenid) |
66
|
|
|
{ |
67
|
|
|
if (\Auth::check()) { |
68
|
|
|
$this->validate($request, [ |
69
|
|
|
'file' => 'required|image|mimes:png|max:2048', |
70
|
|
|
]); |
71
|
|
|
|
72
|
|
|
$file = $request->file('file'); |
|
|
|
|
73
|
|
|
$extorig = $file->getExtension(); |
74
|
|
|
|
75
|
|
|
$imageName = \Storage::putFile('screenshots', new UploadedFile($file->path(), $file->getClientOriginalName())); |
76
|
|
|
//dd($file); |
77
|
|
|
|
78
|
|
|
//Löschen des vorhandenen DB Eintrages |
79
|
|
|
$old = Screenshot::whereGameId($gameid)->where('screenshot_id', '=', $screenid)->first(); |
80
|
|
|
if ($old) { |
81
|
|
|
$old->delete(); |
82
|
|
|
} else { |
83
|
|
|
event(new Obyx('screenshot-add', \Auth::id())); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
//Speichern des Screenshots |
87
|
|
|
$scr = new Screenshot(); |
|
|
|
|
88
|
|
|
$scr->game_id = $gameid; |
|
|
|
|
89
|
|
|
$scr->user_id = \Auth::id(); |
|
|
|
|
90
|
|
|
$scr->screenshot_id = $screenid; |
91
|
|
|
$scr->filename = str_replace($extorig, '', $imageName); |
|
|
|
|
92
|
|
|
$scr->save(); |
93
|
|
|
|
94
|
|
|
return redirect()->route('screenshot.upload.success', $gameid); |
95
|
|
|
} else { |
96
|
|
|
return redirect()->back(); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.