|
1
|
|
|
<?php |
|
2
|
|
|
namespace App\Http\Controllers; |
|
3
|
|
|
|
|
4
|
|
|
use Illuminate\Http\Request; |
|
5
|
|
|
use App\Models\LinkType; |
|
6
|
|
|
use App\Models\Link; |
|
7
|
|
|
use App\Models\Button; |
|
8
|
|
|
use Illuminate\Support\Facades\Route; |
|
9
|
|
|
|
|
10
|
|
|
class LinkTypeViewController extends Controller |
|
11
|
|
|
{ |
|
12
|
|
|
public function getParamForm($typename, $linkId = 0) |
|
13
|
|
|
{ |
|
14
|
|
|
$data = [ |
|
15
|
|
|
'title' => '', |
|
16
|
|
|
'link' => '', |
|
17
|
|
|
'button_id' => 0, |
|
18
|
|
|
'buttons' => [], |
|
19
|
|
|
]; |
|
20
|
|
|
|
|
21
|
|
|
if ($linkId) { |
|
22
|
|
|
$link = Link::find($linkId); |
|
23
|
|
|
$data['title'] = $link->title; |
|
24
|
|
|
$data['link'] = $link->link; |
|
25
|
|
|
if (Route::currentRouteName() != 'showButtons') { |
|
26
|
|
|
$data['button_id'] = $link->button_id; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
// Check if type_params is not empty and is a valid JSON string |
|
30
|
|
|
if (!empty($link->type_params) && is_string($link->type_params)) { |
|
31
|
|
|
// Decode the JSON string into an associative array |
|
32
|
|
|
$typeParams = json_decode($link->type_params, true); |
|
33
|
|
|
if (is_array($typeParams)) { |
|
34
|
|
|
// Merge the associative array into $data |
|
35
|
|
|
$data = array_merge($data, $typeParams); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
if ($typename === 'predefined') { |
|
40
|
|
|
$buttons = Button::select()->orderBy('name', 'asc')->get(); |
|
41
|
|
|
foreach ($buttons as $btn) { |
|
42
|
|
|
$data['buttons'][] = [ |
|
43
|
|
|
'name' => $btn->name, |
|
44
|
|
|
'title' => $btn->alt, |
|
45
|
|
|
'exclude' => $btn->exclude, |
|
46
|
|
|
'selected' => ($linkId && isset($link) && $link->button_id == $btn->id), |
|
47
|
|
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
return view('components.pageitems.predefined-form', $data); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return view($typename . '.form', $data); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function blockAsset(Request $request, $type) |
|
56
|
|
|
{ |
|
57
|
|
|
$asset = $request->query('asset'); |
|
58
|
|
|
|
|
59
|
|
|
// Prevent directory traversal in $type |
|
60
|
|
|
if (preg_match('/\.\.|\/|\\\\/', $type)) { |
|
61
|
|
|
abort(403, 'Unauthorized action.'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
// Define allowed file extensions |
|
65
|
|
|
$allowedExtensions = ['js', 'css', 'img', 'svg', 'gif', 'jpg', 'jpeg', 'png', 'mp4', 'mp3']; |
|
66
|
|
|
|
|
67
|
|
|
$extension = strtolower(pathinfo($asset, PATHINFO_EXTENSION)); |
|
|
|
|
|
|
68
|
|
|
if (!in_array($extension, $allowedExtensions)) { |
|
69
|
|
|
return response('File type not allowed', Response::HTTP_FORBIDDEN); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$basePath = realpath(base_path("blocks/$type")); |
|
73
|
|
|
|
|
74
|
|
|
$fullPath = realpath(base_path("blocks/$type/$asset")); |
|
75
|
|
|
|
|
76
|
|
|
if (!$fullPath || !file_exists($fullPath) || strpos($fullPath, $basePath) !== 0) { |
|
77
|
|
|
return response('File not found', Response::HTTP_NOT_FOUND); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return response()->file($fullPath); |
|
81
|
|
|
} |
|
82
|
|
|
} |