diff --git a/app/Http/Controllers/Admin/ClipController.php b/app/Http/Controllers/Admin/ClipController.php index 1a09eec..2236fc9 100644 --- a/app/Http/Controllers/Admin/ClipController.php +++ b/app/Http/Controllers/Admin/ClipController.php @@ -9,6 +9,10 @@ use App\Models\Access; use App\Models\Clip; use Illuminate\Http\Request; use App\Helper; +use Spatie\Image\Enums\AlignPosition; +use Spatie\Image\Enums\Fit; +use Spatie\Image\Enums\Unit; +use Spatie\Image\Image; use function App\Helpers\hasCreateRoute; class ClipController extends XController @@ -67,7 +71,28 @@ class ClipController extends XController // } if ($request->has('cover')){ $clip->cover = $this->storeFile('cover',$clip, 'clips'); + + $key = 'cover'; + $format = $request->file($key)->guessExtension(); + if (strtolower($format) == 'png'){ + $format = 'webp'; + } + $i = Image::load($request->file($key)->getPathname()) + ->optimize() +// ->nonQueued() + ->format($format); + if (getSetting('watermark2')) { + $i->watermark(public_path('upload/images/logo.png'), + AlignPosition::BottomLeft, 5, 5, Unit::Percent, + config('app.media.watermark_size'), Unit::Percent, + config('app.media.watermark_size'), Unit::Percent, Fit::Contain, + config('app.media.watermark_opacity')); + } + $i->save(storage_path() . '/app/public/cover/optimized-'. $clip->$key); } + + + if ($request->has('clip')){ $clip->file = $this->storeFile('clip',$clip, 'clips'); } diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index d7a111c..16f0628 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Models\Attachment; use App\Models\Comment; use App\Models\Customer; use App\Models\Gallery; @@ -27,6 +28,10 @@ class ClientController extends Controller public function post(Post $post) { + + if ($post->status = 0 && !auth()->check()){ + return abort(403); + } $area = 'post'; $title = $post->title; $subtitle = $post->subtitle; @@ -35,6 +40,9 @@ class ClientController extends Controller } public function gallery(Gallery $gallery) { + if ($gallery->status = 0 && !auth()->check()){ + return abort(403); + } $area = 'gallery'; $title = $gallery->title; $subtitle = \Str::limit(strip_tags($gallery->description),15); @@ -120,4 +128,12 @@ class ClientController extends Controller $posts = $group->posts()->orderByDesc('id')->paginate($this->paginate); return view('client.group', compact('area', 'posts', 'title', 'subtitle','group')); } + + public function attachDl(Attachment $attachment){ + $attachment->increment('downloads'); + $file = (storage_path().'/app/public/attachments/'. $attachment->file); + if (file_exists($file)) { + return response()->download($file); + } + } } diff --git a/app/Http/Requests/AttachmentSaveRequest.php b/app/Http/Requests/AttachmentSaveRequest.php index 987f38b..c010501 100644 --- a/app/Http/Requests/AttachmentSaveRequest.php +++ b/app/Http/Requests/AttachmentSaveRequest.php @@ -26,7 +26,7 @@ class AttachmentSaveRequest extends FormRequest 'title' => ['required','string','min:2'], 'body' => ['nullable','string'], 'subtitle' => ['nullable','string'], - 'file' => ['nullable','mimes:png,jpg,svg,mp4,pdf,docx,zip,rar','max:'.getMaxUploadSize()] + 'file' => ['nullable','mimes:png,jpg,svg,mp4,pdf,docx,zip,rar,mp3','max:'.getMaxUploadSize()] ]; } } diff --git a/app/Models/Attachment.php b/app/Models/Attachment.php index 25f4ad7..9f72df6 100644 --- a/app/Models/Attachment.php +++ b/app/Models/Attachment.php @@ -31,10 +31,14 @@ class Attachment extends Model public function tempUrl() // WIP { + if ($this->file == null) { return asset('/assets/upload/logo.svg'); } + return \URL::temporarySignedRoute( + 'client.attach-dl', now()->addMinutes(60), [$this->slug] + ); return \Storage::url('attachments/' . $this->file); } diff --git a/app/Models/Clip.php b/app/Models/Clip.php index 23d33fc..ac86e27 100644 --- a/app/Models/Clip.php +++ b/app/Models/Clip.php @@ -25,6 +25,14 @@ class Clip extends Model return asset('assets/upload/logo.svg');; } + return \Storage::url('clips/optimized-' . $this->cover); + } + public function imgOriginalUrl() + { + if ($this->cover == null) { + return asset('assets/upload/logo.svg');; + } + return \Storage::url('clips/' . $this->cover); } diff --git a/database/seeders/AreaSeeder.php b/database/seeders/AreaSeeder.php index 6d9cbaa..32d6acc 100644 --- a/database/seeders/AreaSeeder.php +++ b/database/seeders/AreaSeeder.php @@ -37,7 +37,7 @@ class AreaSeeder extends Seeder 'name' => 'index', 'valid_segments' => json_encode( ["top", "slider", "header", "footer", "menu", - "parallax", "other", "posts", "products", "attachments" + "parallax", "other", "posts", "products" , "groups", "categories", "category", "group", "index", "ads", "galleries"] ), 'max' => 10, @@ -48,7 +48,7 @@ class AreaSeeder extends Seeder 'name' => 'post', 'valid_segments' => json_encode( ["top", "header", "footer", "menu", - "parallax", "other", "post", "comments", "ads"] + "parallax", "other", "post", "comments", "ads" , "attachments"] ), 'max' => 6, 'preview' => 'client.post', @@ -68,7 +68,7 @@ class AreaSeeder extends Seeder 'name' => 'clip', 'valid_segments' => json_encode( ["top", "header", "footer", "menu", - "parallax", "other", "clip", "comments", "ads"] + "parallax", "other", "clip", "comments", "ads", "attachments"] ), 'max' => 6, 'preview' => 'client.clip', @@ -88,7 +88,7 @@ class AreaSeeder extends Seeder 'name' => 'gallery', 'valid_segments' => json_encode( ["top", "header", "footer", "menu", - "parallax", "other", "gallery", "comments", "ads"] + "parallax", "other", "gallery", "comments", "ads", "attachments"] ), 'max' => 6, 'preview' => 'client.gallery', @@ -108,7 +108,7 @@ class AreaSeeder extends Seeder 'name' => 'product', 'valid_segments' => json_encode( ["top", "header", "footer", "menu", - "parallax", "other", "product", "comments", "ads"] + "parallax", "other", "product", "comments", "ads", "attachments"] ), 'max' => 6, 'preview' => 'client.product', @@ -148,7 +148,7 @@ class AreaSeeder extends Seeder 'name' => 'category', 'valid_segments' => json_encode( ["top", "header", "footer", "menu", - "parallax", "other", "category", "ads", "products_page"] + "parallax", "other", "category", "ads", "products_page", "attachments"] ), 'max' => 6, 'preview' => 'client.attachment', @@ -168,7 +168,7 @@ class AreaSeeder extends Seeder 'name' => 'group', 'valid_segments' => json_encode( ["top", "header", "footer", "menu", - "parallax", "other", "group", "ads", 'posts_page'] + "parallax", "other", "group", "ads", 'posts_page', "attachments"] ), 'max' => 6, 'preview' => 'client.group', diff --git a/resources/views/admin/attachments/attachment-form.blade.php b/resources/views/admin/attachments/attachment-form.blade.php index e6f73cc..5ad6810 100644 --- a/resources/views/admin/attachments/attachment-form.blade.php +++ b/resources/views/admin/attachments/attachment-form.blade.php @@ -137,7 +137,7 @@ + accept=".png,.jpg,.svg,.mp4,.pdf,.docx,.zip,.rar,.mp3"/>
diff --git a/resources/views/segments/attachments/SimpleAttachmentList/SimpleAttachmentList.blade.php b/resources/views/segments/attachments/SimpleAttachmentList/SimpleAttachmentList.blade.php new file mode 100644 index 0000000..2827c38 --- /dev/null +++ b/resources/views/segments/attachments/SimpleAttachmentList/SimpleAttachmentList.blade.php @@ -0,0 +1,43 @@ +
+
+ @if(count($data['attachs']) > 0) +

+ {{__("Attachments")}} +

+ + + + + + + + @foreach($data['attachs'] as $attach) + + + + + + + @endforeach +
+ {{__("Name")}} + + {{__("File name")}} + + {{__("Size")}} + + - +
+ {{$attach->title}} + + {{$attach->title}} [ {{$attach->ext}} ] + + {{formatFileSize($attach->size)}} + + + + +
+ @endif +
+
diff --git a/resources/views/segments/attachments/SimpleAttachmentList/SimpleAttachmentList.js b/resources/views/segments/attachments/SimpleAttachmentList/SimpleAttachmentList.js new file mode 100644 index 0000000..e69de29 diff --git a/resources/views/segments/attachments/SimpleAttachmentList/SimpleAttachmentList.json b/resources/views/segments/attachments/SimpleAttachmentList/SimpleAttachmentList.json new file mode 100644 index 0000000..713977f --- /dev/null +++ b/resources/views/segments/attachments/SimpleAttachmentList/SimpleAttachmentList.json @@ -0,0 +1,10 @@ +{ + "name": "SimpleAttachmentList", + "version": "1.0", + "author": "xStack", + "email": "xshop@xstack.ir", + "license": "GPL-3.0-or-later", + "url": "https:\/\/xstack.ir", + "author_url": "https:\/\/4xmen.ir", + "packages": [] +} \ No newline at end of file diff --git a/resources/views/segments/attachments/SimpleAttachmentList/SimpleAttachmentList.php b/resources/views/segments/attachments/SimpleAttachmentList/SimpleAttachmentList.php new file mode 100644 index 0000000..8d12969 --- /dev/null +++ b/resources/views/segments/attachments/SimpleAttachmentList/SimpleAttachmentList.php @@ -0,0 +1,27 @@ +attachs = $model->attachs; + return $part; + } +} diff --git a/resources/views/segments/attachments/SimpleAttachmentList/SimpleAttachmentList.scss b/resources/views/segments/attachments/SimpleAttachmentList/SimpleAttachmentList.scss new file mode 100644 index 0000000..ec061a6 --- /dev/null +++ b/resources/views/segments/attachments/SimpleAttachmentList/SimpleAttachmentList.scss @@ -0,0 +1,12 @@ +.SimpleAttachmentList { + // scss\ + padding: 2rem 0; + .attach-table { + border-radius: var(--xshop-border-radius); + overflow: hidden; + span{ + color: var(--xshop-secondary); + } + + } +} diff --git a/resources/views/segments/attachments/SimpleAttachmentList/screenshot.png b/resources/views/segments/attachments/SimpleAttachmentList/screenshot.png new file mode 100644 index 0000000..b85e767 Binary files /dev/null and b/resources/views/segments/attachments/SimpleAttachmentList/screenshot.png differ diff --git a/routes/web.php b/routes/web.php index cbe120c..479de81 100644 --- a/routes/web.php +++ b/routes/web.php @@ -364,6 +364,7 @@ Route::name('client.')->group(function (){ Route::get('/group/{group}', [\App\Http\Controllers\ClientController::class,'group'])->name('group'); Route::get('/gallery/{gallery}', [\App\Http\Controllers\ClientController::class,'gallery'])->name('gallery'); Route::get('/search', [\App\Http\Controllers\ClientController::class,'search'])->name('search'); + Route::get('attach/download/{attachment}', [\App\Http\Controllers\ClientController::class,'attachDl'])->name('attach-dl'); Route::get('/{post}', [\App\Http\Controllers\ClientController::class,'post'])->name('post');