Skip to content

Commit 4d4c947

Browse files
committed
Update Block System
1 parent 25ce01a commit 4d4c947

File tree

23 files changed

+107
-77
lines changed

23 files changed

+107
-77
lines changed

app/Functions/functions.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,46 @@ function strip_tags_except_allowed_protocols($str) {
150150
}
151151

152152
return $str;
153+
}
154+
155+
if(!function_exists('setBlockAssetContext')) {
156+
function setBlockAssetContext($type = null) {
157+
static $currentType = null;
158+
if ($type !== null) {
159+
$currentType = $type;
160+
}
161+
return $currentType;
162+
}
163+
}
164+
165+
// Get custom block assets
166+
if(!function_exists('block_asset')) {
167+
function block_asset($file) {
168+
$type = setBlockAssetContext(); // Retrieve the current type context
169+
return url("block-asset/$type?asset=$file");
170+
}
171+
}
172+
173+
if(!function_exists('get_block_file_contents')) {
174+
function get_block_file_contents($file) {
175+
$type = setBlockAssetContext(); // Retrieve the current type context
176+
return file_get_contents(base_path("blocks/$type/$file"));
177+
}
178+
}
179+
180+
function block_text_translation_check($text) {
181+
if (empty($text)) {
182+
return false;
183+
}
184+
$translate = __("messages.$text");
185+
return $translate === "messages.$text" ? true : false;
186+
}
187+
188+
function block_text($text) {
189+
$translate = __("messages.$text");
190+
return $translate === "messages.$text" ? $text : $translate;
191+
}
192+
193+
function bt($text) {
194+
return block_text($text);
153195
}

app/Http/Controllers/LinkTypeViewController.php

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@ class LinkTypeViewController extends Controller
1212
public function getParamForm($typename, $linkId = 0)
1313
{
1414
$data = [
15-
'link_title' => '',
16-
'link_url' => '',
15+
'title' => '',
16+
'link' => '',
1717
'button_id' => 0,
1818
'buttons' => [],
1919
];
2020

2121
if ($linkId) {
2222
$link = Link::find($linkId);
23-
$typename = $link->type ?? 'predefined';
24-
$data['link_title'] = $link->title;
25-
$data['link_url'] = $link->link;
23+
$data['title'] = $link->title;
24+
$data['link'] = $link->link;
2625
if (Route::currentRouteName() != 'showButtons') {
2726
$data['button_id'] = $link->button_id;
2827
}
@@ -52,4 +51,32 @@ public function getParamForm($typename, $linkId = 0)
5251

5352
return view($typename . '.form', $data);
5453
}
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+
}
5582
}

app/Http/Controllers/UserController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function AddUpdateLink($id = 0)
176176
'title' => "Predefined Site",
177177
];
178178

179-
$data['typename'] = $link->type ?? 'predefined';
179+
$data['typename'] = $linkData->type ?? 'predefined';
180180

181181
return view('studio/edit-link', $data);
182182
}
@@ -209,6 +209,7 @@ public function saveLink(Request $request)
209209
if (file_exists($linkTypePath)) {
210210
include $linkTypePath;
211211
$linkData = handleLinkType($request, $linkType);
212+
$linkData['button_id'] = $linkData['button_id'] ?? 1; // Set 'button_id' unless overwritten by handleLinkType
212213
$linkData['type'] = $linkType->typename; // Ensure 'type' is included in $linkData
213214
} else {
214215
abort(404, "Link type logic not found.");
@@ -384,7 +385,7 @@ public function showLinks()
384385
$userId = Auth::user()->id;
385386
$data['pagePage'] = 10;
386387

387-
$data['links'] = Link::select('id', 'link', 'title', 'order', 'click_number', 'up_link', 'links.button_id')->where('user_id', $userId)->orderBy('up_link', 'asc')->orderBy('order', 'asc')->paginate(99999);
388+
$data['links'] = Link::select()->where('user_id', $userId)->orderBy('up_link', 'asc')->orderBy('order', 'asc')->paginate(99999);
388389
return view('studio/links', $data);
389390
}
390391

blocks/email/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
id: 6
22
typename: email
3-
title: "Custom Link"
43
icon: "bi bi-envelope-fill"
54
custom_html: false

blocks/email/form.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<select style="display:none" name="button" class="form-control"><option class="button button-default email" value="default email">{{__('messages.Default Email')}}</option></select>
44

55
<label for='title' class='form-label'>{{__('messages.Custom Title')}}</label>
6-
<input type='text' name='title' value='{{$link_title}}' class='form-control' />
6+
<input type='text' name='title' value='{{$title}}' class='form-control' />
77
<span class='small text-muted'>{{__('messages.Leave blank for default title')}}</span><br>
88

99
<label for='link' class='form-label'>{{__('messages.E-Mail address')}}</label>
10-
<input type='email' name='link' value='{{str_replace("mailto:", "", $link_url)}}' class='form-control' required />
10+
<input type='email' name='link' value='{{str_replace("mailto:", "", $link)}}' class='form-control' required />
1111
<span class='small text-muted'>{{__('messages.Enter your E-Mail')}}</span>
1212

1313
<script>

blocks/heading/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
id: 3
22
typename: heading
3-
title: "Custom Link"
43
icon: "bi bi-card-heading"
54
custom_html: true

blocks/heading/form.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<label for='title' class='form-label'>{{__('messages.Heading Text:')}}</label>
2-
<input type='text' name='title' value='{{$link_title}}' class='form-control' />
2+
<input type='text' name='title' value='{{$title}}' class='form-control' />

blocks/link/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
id: 2
22
typename: link
3-
title: "Custom Link"
43
icon: "bi bi-link"
54
custom_html: false

blocks/link/form.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<label for='title' class='form-label'>{{__('messages.Title')}}</label>
2-
<input type='text' name='title' value='{{$link_title}}' class='form-control' required />
2+
<input type='text' name='title' value='{{$title}}' class='form-control' required />
33

44
<label for='title' class='form-label'>{{__('messages.URL')}}</label>
5-
<input type='url' name='link' value='{{$link_url}}' class='form-control' required />
5+
<input type='url' name='link' value='{{$link}}' class='form-control' required />
66

77
<div class="custom-control custom-checkbox m-2">
88
<input type="checkbox" class="custom-control-input" value='1' {{((isset($params->GetSiteIcon) ? boolval($params->GetSiteIcon) : false) ? 'checked': '') }} name='GetSiteIcon' id="GetSiteIcon" @if($button_id == 2)checked @endif>

blocks/spacer/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
id: 4
22
typename: spacer
3-
title: "Custom Link"
43
icon: "bi bi-distribute-vertical"
54
custom_html: true

0 commit comments

Comments
 (0)