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"/>
+ {{__("Name")}} + | ++ {{__("File name")}} + | ++ {{__("Size")}} + | ++ - + | +
---|---|---|---|
+ {{$attach->title}} + | ++ {{$attach->title}} [ {{$attach->ext}} ] + | ++ {{formatFileSize($attach->size)}} + | ++ + + + | +