Skip to content

Commit 1a7770b

Browse files
Merge pull request #2182 from VikassWebkul214254/svg-senitize
SVG Sanitizer features added
2 parents 29a0090 + 47a9c72 commit 1a7770b

File tree

16 files changed

+280
-67
lines changed

16 files changed

+280
-67
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"barryvdh/laravel-dompdf": "^2.0.0",
1313
"diglactic/laravel-breadcrumbs": "^8.0",
1414
"doctrine/dbal": "^3.0",
15+
"enshrined/svg-sanitize": "^0.21.0",
1516
"guzzlehttp/guzzle": "^7.0.1",
1617
"khaled.alshamaa/ar-php": "^6.3",
1718
"konekt/concord": "^1.10",

composer.lock

Lines changed: 47 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/Webkul/Admin/src/Http/Controllers/TinyMCEController.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22

33
namespace Webkul\Admin\Http\Controllers;
44

5+
use Illuminate\Http\JsonResponse;
6+
use Illuminate\Http\UploadedFile;
57
use Illuminate\Support\Facades\Storage;
8+
use Webkul\Core\Traits\Sanitizer;
69

710
class TinyMCEController extends Controller
811
{
12+
use Sanitizer;
13+
914
/**
1015
* Storage folder path.
11-
*
12-
* @var string
1316
*/
14-
private $storagePath = 'tinymce';
17+
private string $storagePath = 'tinymce';
1518

1619
/**
1720
* Upload file from tinymce.
18-
*
19-
* @return void
2021
*/
21-
public function upload()
22+
public function upload(): JsonResponse
2223
{
2324
$media = $this->storeMedia();
2425

@@ -33,18 +34,28 @@ public function upload()
3334

3435
/**
3536
* Store media.
36-
*
37-
* @return array
3837
*/
39-
public function storeMedia()
38+
public function storeMedia(): array
4039
{
4140
if (! request()->hasFile('file')) {
4241
return [];
4342
}
4443

44+
$file = request()->file('file');
45+
46+
if (! $file instanceof UploadedFile) {
47+
return [];
48+
}
49+
50+
$filename = md5($file->getClientOriginalName().time()).'.'.$file->getClientOriginalExtension();
51+
52+
$path = $file->storeAs($this->storagePath, $filename);
53+
54+
$this->sanitizeSVG($path, $file);
55+
4556
return [
46-
'file' => $path = request()->file('file')->store($this->storagePath),
47-
'file_name' => request()->file('file')->getClientOriginalName(),
57+
'file' => $path,
58+
'file_name' => $file->getClientOriginalName(),
4859
'file_url' => Storage::url($path),
4960
];
5061
}

packages/Webkul/Admin/src/Resources/lang/ar/app.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,12 @@
417417
'warning' => 'تحذير',
418418
'info' => 'معلومات',
419419
],
420+
421+
'tiny-mce' => [
422+
'http-error' => 'خطأ في HTTP',
423+
'invalid-json' => 'استجابة JSON غير صالحة من الخادم.',
424+
'upload-failed' => 'فشل تحميل الملف. يرجى المحاولة مرة أخرى.',
425+
],
420426
],
421427

422428
'quotes' => [
@@ -2019,7 +2025,7 @@
20192025
'title' => 'حول الفرصة',
20202026
],
20212027

2022-
'quotes'=> [
2028+
'quotes' => [
20232029
'subject' => 'الموضوع',
20242030
'expired-at' => 'تنتهي في',
20252031
'sub-total' => 'المجموع الفرعي',

packages/Webkul/Admin/src/Resources/lang/en/app.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@
419419
'warning' => 'Warning',
420420
'info' => 'Info',
421421
],
422+
423+
'tiny-mce' => [
424+
'http-error' => 'HTTP Error',
425+
'invalid-json' => 'Invalid JSON response from the server.',
426+
'upload-failed' => 'File upload failed. Please try again.',
427+
],
422428
],
423429

424430
'quotes' => [

packages/Webkul/Admin/src/Resources/lang/es/app.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,12 @@
421421
'warning' => 'Advertencia',
422422
'info' => 'Información',
423423
],
424+
425+
'tiny-mce' => [
426+
'http-error' => 'Error HTTP',
427+
'invalid-json' => 'Respuesta JSON no válida del servidor.',
428+
'upload-failed' => 'Error al subir el archivo. Por favor, inténtelo de nuevo.',
429+
],
424430
],
425431

426432
'quotes' => [
@@ -2022,7 +2028,7 @@
20222028
'title' => 'Sobre el Lead',
20232029
],
20242030

2025-
'quotes'=> [
2031+
'quotes' => [
20262032
'subject' => 'Asunto',
20272033
'expired-at' => 'Expirado En',
20282034
'sub-total' => 'Subtotal',

packages/Webkul/Admin/src/Resources/lang/fa/app.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,12 @@
421421
'warning' => 'هشدار',
422422
'info' => 'اطلاعات',
423423
],
424+
425+
'tiny-mce' => [
426+
'http-error' => 'خطای HTTP',
427+
'invalid-json' => 'پاسخ JSON نامعتبر از سرور.',
428+
'upload-failed' => 'آپلود فایل ناموفق بود. لطفاً دوباره تلاش کنید.',
429+
],
424430
],
425431

426432
'quotes' => [
@@ -2023,7 +2029,7 @@
20232029
'title' => 'درباره سرنخ',
20242030
],
20252031

2026-
'quotes'=> [
2032+
'quotes' => [
20272033
'subject' => 'موضوع',
20282034
'expired-at' => 'تاریخ انقضا',
20292035
'sub-total' => 'جمع جزئی',

packages/Webkul/Admin/src/Resources/lang/pt_BR/app.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,12 @@
415415
'warning' => 'Aviso',
416416
'info' => 'Informação',
417417
],
418+
419+
'tiny-mce' => [
420+
'http-error' => 'Erro HTTP',
421+
'invalid-json' => 'Resposta JSON inválida do servidor.',
422+
'upload-failed' => 'Falha no upload do arquivo. Por favor, tente novamente.',
423+
],
418424
],
419425

420426
'quotes' => [
@@ -1908,7 +1914,7 @@
19081914
'title' => 'Sobre o Negócio',
19091915
],
19101916

1911-
'quotes'=> [
1917+
'quotes' => [
19121918
'subject' => 'Assunto',
19131919
'expired-at' => 'Expirado em',
19141920
'sub-total' => 'Subtotal',

packages/Webkul/Admin/src/Resources/lang/tr/app.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,12 @@
421421
'warning' => 'Uyarı',
422422
'info' => 'Bilgi',
423423
],
424+
425+
'tiny-mce' => [
426+
'http-error' => 'HTTP Hatası',
427+
'invalid-json' => 'Sunucudan geçersiz JSON yanıtı.',
428+
'upload-failed' => 'Dosya yüklemesi başarısız oldu. Lütfen tekrar deneyin.',
429+
],
424430
],
425431

426432
'quotes' => [

packages/Webkul/Admin/src/Resources/lang/vi/app.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,12 @@
418418
'warning' => 'Cảnh báo',
419419
'info' => 'Thông tin',
420420
],
421+
422+
'tiny-mce' => [
423+
'http-error' => 'Lỗi HTTP',
424+
'invalid-json' => 'Phản hồi JSON không hợp lệ từ máy chủ.',
425+
'upload-failed' => 'Tải tệp lên không thành công. Vui lòng thử lại.',
426+
],
421427
],
422428

423429
'quotes' => [
@@ -1916,7 +1922,7 @@
19161922
'title' => 'Về Khách Hàng Tiềm Năng',
19171923
],
19181924

1919-
'quotes'=> [
1925+
'quotes' => [
19201926
'subject' => 'Chủ Đề',
19211927
'expired-at' => 'Hết Hạn Vào',
19221928
'sub-total' => 'Tạm Tính',

0 commit comments

Comments
 (0)