Passed
Push — master ( 9f15d2...3a106b )
by Darko
10:30
created

NfoController::showNfo()   A

Complexity

Conditions 5
Paths 7

Size

Total Lines 40
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 24
c 0
b 0
f 0
dl 0
loc 40
rs 9.2248
cc 5
nc 7
nop 2
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Release;
6
use App\Models\ReleaseNfo;
7
use Blacklight\utility\Utility;
8
use Illuminate\Http\Request;
9
10
class NfoController extends BasePageController
11
{
12
    /**
13
     * @throws \Exception
14
     */
15
    public function showNfo(Request $request, string $id = '')
16
    {
17
        if ($id) {
18
            $rel = Release::getByGuid($id);
19
20
            if (! $rel) {
21
                abort(404, 'Release does not exist');
22
            }
23
24
            $nfo = ReleaseNfo::getReleaseNfo($rel['id']);
25
26
            if ($nfo !== null) {
27
                $nfo['nfoUTF'] = Utility::cp437toUTF($nfo['nfo']);
28
29
                $modal = $request->has('modal');
30
31
                if ($modal) {
32
                    // Return just the NFO content for modal display
33
                    return view('nfo.view', [
34
                        'rel' => $rel,
35
                        'nfo' => $nfo,
36
                        'modal' => true,
37
                    ]);
38
                } else {
39
                    // Return full page view
40
                    return view('nfo.view', [
41
                        'rel' => $rel,
42
                        'nfo' => $nfo,
43
                        'modal' => false,
44
                        'meta_title' => 'View NFO - '.$rel['searchname'],
45
                        'meta_keywords' => 'view,nzb,nfo,description,details',
46
                        'meta_description' => 'View NFO File for '.$rel['searchname'],
47
                    ]);
48
                }
49
            } else {
50
                abort(404, 'NFO does not exist');
51
            }
52
        }
53
54
        abort(404, 'Invalid request');
55
    }
56
}
57