diff --git a/addons/default/visiosoft/advs-module/resources/config/settings/sections.php b/addons/default/visiosoft/advs-module/resources/config/settings/sections.php index eb2e98add..ec5826d04 100644 --- a/addons/default/visiosoft/advs-module/resources/config/settings/sections.php +++ b/addons/default/visiosoft/advs-module/resources/config/settings/sections.php @@ -25,6 +25,10 @@ return [ 'default_published_time', 'default_adv_limit', 'default_GET', + 'thumbnail_width', + 'thumbnail_height', + 'picture_width', + 'picture_height', 'watermark_type', 'watermark_text', 'watermark_image', diff --git a/addons/default/visiosoft/advs-module/resources/config/settings/settings.php b/addons/default/visiosoft/advs-module/resources/config/settings/settings.php index 4b56fe2db..77628ef40 100644 --- a/addons/default/visiosoft/advs-module/resources/config/settings/settings.php +++ b/addons/default/visiosoft/advs-module/resources/config/settings/settings.php @@ -111,6 +111,30 @@ return [ 'default_value' => 0, ], ], + 'thumbnail_width' => [ + 'type' => 'anomaly.field_type.integer', + 'config' => [ + 'default_value' => 270, + ], + ], + 'thumbnail_height' => [ + 'type' => 'anomaly.field_type.integer', + 'config' => [ + 'default_value' => 180, + ], + ], + 'picture_width' => [ + 'type' => 'anomaly.field_type.integer', + 'config' => [ + 'default_value' => 900, + ], + ], + 'picture_height' => [ + 'type' => 'anomaly.field_type.integer', + 'config' => [ + 'default_value' => 600, + ], + ], 'watermark_type' => [ 'type' => 'anomaly.field_type.select', 'bind' => 'adv.watermark_type', diff --git a/addons/default/visiosoft/advs-module/resources/lang/en/setting.php b/addons/default/visiosoft/advs-module/resources/lang/en/setting.php index 3e8095be3..6c41b6a08 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/setting.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/setting.php @@ -82,6 +82,18 @@ return [ 'default_GET' => [ 'name' => 'Default Ad GET', ], + 'thumbnail_width' => [ + 'name' => 'Thumbnail Width', + ], + 'thumbnail_height' => [ + 'name' => 'Thumbnail Height', + ], + 'picture_width' => [ + 'name' => 'Picture Width', + ], + 'picture_height' => [ + 'name' => 'Picture Height', + ], 'twitter' => [ 'name' => 'Twitter', ], diff --git a/addons/default/visiosoft/advs-module/resources/views/ad-detail/partials/slider.twig b/addons/default/visiosoft/advs-module/resources/views/ad-detail/partials/slider.twig index ab0f4c025..b4758fd5a 100644 --- a/addons/default/visiosoft/advs-module/resources/views/ad-detail/partials/slider.twig +++ b/addons/default/visiosoft/advs-module/resources/views/ad-detail/partials/slider.twig @@ -11,7 +11,7 @@ {% else %} {% for image in adv.getViewPhotoUrl %} - + {% if loop.index == 1 %} {% set advPhoto = image %} {% endif %} diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvPresenter.php b/addons/default/visiosoft/advs-module/src/Adv/AdvPresenter.php index db31f6274..c10f1cdab 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvPresenter.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvPresenter.php @@ -19,6 +19,11 @@ class AdvPresenter extends EntryPresenter } + public function getMediumPhotoUrl($fullPhotoUrl) + { + $mediumPhotoUrl = pathinfo($fullPhotoUrl); + return $mediumPhotoUrl['dirname'] . '/md-' . $mediumPhotoUrl['basename']; + } public function isAdVideo() { diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php index 5d50576d3..f784925c7 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php @@ -1,14 +1,16 @@ model = $model; $this->settings = $settings; + $this->fileRepository = $fileRepository; + $this->folderRepository = $folderRepository; } /** @@ -291,8 +307,32 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface public function cover_image_update($adv) { if (count($adv->files) != 0) { - $file_url = 'files/images/' . $adv->files[0]->name; - $adv->update(['cover_photo' => $file_url]); + $fileName = 'tn-' . $adv->files[0]->name; + $folder = $this->folderRepository->findBySlug('images'); + $thumbnail = $this->fileRepository->findByNameAndFolder($fileName, $folder); + if (!$thumbnail) { + // Create thumbnail image + $image = Image::make($adv->files[0]->url()); + $image->resize( + setting_value('visiosoft.module.advs::thumbnail_width'), + setting_value('visiosoft.module.advs::thumbnail_height') + ); + $fileName = 'tn-' . $adv->files[0]->name; + $image->save(app_storage_path() . '/files-module/local/images/' . $fileName); + + // Create file entry for the image + $this->fileRepository->create([ + 'folder_id' => $folder->getId(), + 'name' => $fileName, + 'disk_id' => 1, + 'size' => $image->filesize(), + 'mime_type' => $image->mime, + 'extension' => $image->extension, + ]); + + $file_url = 'files/images/' . $fileName; + $adv->update(['cover_photo' => $file_url]); + } } } diff --git a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php index 6c399b939..4149e8be5 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php @@ -554,14 +554,14 @@ class AdvsController extends PublicController $parent_cat = $categoryModel->getParentCats($request->cat1, 'parent_id'); $packageModel = new PackageModel(); $package = $packageModel->reduceLimit($parent_cat, 'reduce'); - if ($package != null) + if ($package != null) { $this->messages->error(trans('visiosoft.module.advs::message.please_buy_package')); - - } else { + return redirect('/'); + } + } elseif ($adv->slug == '') { $this->messages->error(trans('visiosoft.module.advs::message.max_ad_limit.title')); + return redirect('/'); } - - return redirect('/'); } $adv->is_get_adv = $request->is_get_adv; diff --git a/addons/default/visiosoft/location-module/src/Http/Controller/AjaxController.php b/addons/default/visiosoft/location-module/src/Http/Controller/AjaxController.php index 88012e68f..ef1339dc6 100644 --- a/addons/default/visiosoft/location-module/src/Http/Controller/AjaxController.php +++ b/addons/default/visiosoft/location-module/src/Http/Controller/AjaxController.php @@ -6,6 +6,7 @@ use Visiosoft\LocationModule\Country\CountryModel; use Visiosoft\LocationModule\District\DistrictModel; use Visiosoft\LocationModule\Neighborhood\NeighborhoodModel; use Visiosoft\LocationModule\Village\VillageModel; +use Illuminate\Support\Str; class AjaxController extends PublicController { @@ -103,4 +104,19 @@ class AjaxController extends PublicController return $this->village_model->whereIn('parent_neighborhood_id', $id)->orderBy('order', 'ASC')->get(); } } + + /** + * @return mixed + */ + public function getCity() + { + if ($this->request->name) { + $slug = Str::slug($this->request->name, '_'); + if ($city = $this->city_model->newQuery()->where('slug', 'LIKE', $slug . '%')->first()) { + return ['success' => true, 'link' => route('visiosoft.module.advs::list') . '?city[]=' . $city->id]; + } else { + return ['success' => false]; + } + } + } } \ No newline at end of file diff --git a/addons/default/visiosoft/location-module/src/LocationModuleServiceProvider.php b/addons/default/visiosoft/location-module/src/LocationModuleServiceProvider.php index f7b3a8584..05667e097 100644 --- a/addons/default/visiosoft/location-module/src/LocationModuleServiceProvider.php +++ b/addons/default/visiosoft/location-module/src/LocationModuleServiceProvider.php @@ -84,6 +84,7 @@ class LocationModuleServiceProvider extends AddonServiceProvider 'as' => 'location::getCities', 'uses' => 'Visiosoft\LocationModule\Http\Controller\AjaxController@getCities' ], + 'ajax/get-city' => 'Visiosoft\LocationModule\Http\Controller\AjaxController@getCity', 'ajax/getDistricts' => [ 'as' => 'location::getDistricts', 'uses' => 'Visiosoft\LocationModule\Http\Controller\AjaxController@getDistricts' diff --git a/addons/default/visiosoft/media-field_type/src/Http/Controller/UploadController.php b/addons/default/visiosoft/media-field_type/src/Http/Controller/UploadController.php index cb8b821f9..72a7f2239 100644 --- a/addons/default/visiosoft/media-field_type/src/Http/Controller/UploadController.php +++ b/addons/default/visiosoft/media-field_type/src/Http/Controller/UploadController.php @@ -59,38 +59,63 @@ class UploadController extends AdminController $watermarktype = $settings->value('visiosoft.module.advs::watermark_type'); $position = $settings->value('visiosoft.module.advs::watermark_position'); - $img = WaterMark::make($this->request->file('upload')->getRealPath()) - ->resize(setting_value('visiosoft.field_type.media::imageResizeW', null), setting_value('visiosoft.field_type.media::imageResizeH', 600)) - ->resizeCanvas(setting_value('visiosoft.field_type.media::imageCanvasW', 800), setting_value('visiosoft.field_type.media::imageCanvasH', 600), 'center', false, 'fff'); - if ($watermarktype == 'image') { - - $watermarkimage_id = $settings->value('visiosoft.module.advs::watermark_image'); - $watermarkimage = $files->find($watermarkimage_id); - $w = $img->width(); - if ($watermarkimage != null) { - $watermark = WaterMark::make(app_storage_path() . '/files-module/local/' . $watermarkimage->path()); - $img->insert($watermark, $position); + $fullImg = WaterMark::make($this->request->file('upload')->getRealPath()) + ->resize( + setting_value('visiosoft.field_type.media::imageResizeW', null), + setting_value('visiosoft.field_type.media::imageResizeH', 600) + ) + ->resizeCanvas( + setting_value('visiosoft.field_type.media::imageCanvasW', 800), + setting_value('visiosoft.field_type.media::imageCanvasH', 600), + 'center', + false, + 'fff' + ); + $mdImg = WaterMark::make($this->request->file('upload')->getRealPath()) + ->resize( + setting_value('visiosoft.module.advs::picture_width'), + setting_value('visiosoft.module.advs::picture_height') + ); + foreach ([$fullImg, $mdImg] as $index => $image) { + if ($watermarktype == 'image') { + $watermarkimage_id = $settings->value('visiosoft.module.advs::watermark_image'); + $watermarkimage = $files->find($watermarkimage_id); + if ($watermarkimage != null) { + $watermark = WaterMark::make(app_storage_path() . '/files-module/local/' . $watermarkimage->path()); + $image->insert($watermark, $position); + } + } else { + $watermarktext = $settings->value('visiosoft.module.advs::watermark_text'); + $v = "top"; + $h = "center"; + $w = $image->width() / 2; + $h1 = $image->height() / 2; + $font_size = $w / 20; + $image->text($watermarktext, $w, $h1, function ($font) use ($v, $h, $font_size) { + $font->file(public_path('Antonio-Bold.ttf')); + $font->size($font_size); + $font->align($h); + $font->valign($v); + }); } + if ($index === 0) { + $fileName = $file->getAttributes()['name']; + } else { + $fileName = 'md-' . $file->getAttributes()['name']; - } else { - $watermarktext = $settings->value('visiosoft.module.advs::watermark_text'); - $v = "top"; - $h = "center"; - $w = $img->width() / 2; - $h1 = $img->height() / 2; - $font_size = $w / 20; - $img->text($watermarktext, $w, $h1, function ($font) use ($v, $h, $font_size) { - $font->file(public_path('Antonio-Bold.ttf')); - $font->size($font_size); - $font->align($h); - $font->valign($v); - }); - + $files->create([ + 'folder_id' => $this->request->get('folder'), + 'name' => $fileName, + 'disk_id' => 1, + 'size' => $image->filesize(), + 'mime_type' => $image->mime, + 'extension' => $image->extension, + ]); + } + $image->save(app_storage_path() . '/files-module/local/images/' . $fileName); } - $img->save(app_storage_path() . '/files-module/local/images/' . $file->getAttributes()['name']); return $this->response->json($file->getAttributes()); - } return $this->response->json(['error' => 'There was a problem uploading the file.'], 500);