Merge pull request #532 from openclassify/dia

[FIX] redirected to the home page even if you bought a package
This commit is contained in:
Ozcan Durak 2020-05-04 17:03:25 +03:00 committed by GitHub
commit 70917d216e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 164 additions and 37 deletions

View File

@ -25,6 +25,10 @@ return [
'default_published_time', 'default_published_time',
'default_adv_limit', 'default_adv_limit',
'default_GET', 'default_GET',
'thumbnail_width',
'thumbnail_height',
'picture_width',
'picture_height',
'watermark_type', 'watermark_type',
'watermark_text', 'watermark_text',
'watermark_image', 'watermark_image',

View File

@ -111,6 +111,30 @@ return [
'default_value' => 0, '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' => [ 'watermark_type' => [
'type' => 'anomaly.field_type.select', 'type' => 'anomaly.field_type.select',
'bind' => 'adv.watermark_type', 'bind' => 'adv.watermark_type',

View File

@ -82,6 +82,18 @@ return [
'default_GET' => [ 'default_GET' => [
'name' => 'Default Ad 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' => [ 'twitter' => [
'name' => 'Twitter', 'name' => 'Twitter',
], ],

View File

@ -11,7 +11,7 @@
<a href="{{ image }}"><img src="{{ img('visiosoft.theme.base::images/no-image.png').url }}"></a> <a href="{{ image }}"><img src="{{ img('visiosoft.theme.base::images/no-image.png').url }}"></a>
{% else %} {% else %}
{% for image in adv.getViewPhotoUrl %} {% for image in adv.getViewPhotoUrl %}
<a href="{{ image }}"><img src="{{ image }}"></a> <a href="{{ adv.getMediumPhotoUrl(image) }}"></a>
{% if loop.index == 1 %} {% if loop.index == 1 %}
{% set advPhoto = image %} {% set advPhoto = image %}
{% endif %} {% endif %}

View File

@ -19,6 +19,11 @@ class AdvPresenter extends EntryPresenter
} }
public function getMediumPhotoUrl($fullPhotoUrl)
{
$mediumPhotoUrl = pathinfo($fullPhotoUrl);
return $mediumPhotoUrl['dirname'] . '/md-' . $mediumPhotoUrl['basename'];
}
public function isAdVideo() public function isAdVideo()
{ {

View File

@ -1,14 +1,16 @@
<?php namespace Visiosoft\AdvsModule\Adv; <?php namespace Visiosoft\AdvsModule\Adv;
use Anomaly\FilesModule\File\Contract\FileRepositoryInterface;
use Anomaly\FilesModule\Folder\Contract\FolderRepositoryInterface;
use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface; use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface;
use Anomaly\Streams\Platform\Model\Advs\AdvsAdvsEntryModel; use Anomaly\Streams\Platform\Model\Advs\AdvsAdvsEntryModel;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Intervention\Image\Facades\Image;
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface; use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Anomaly\Streams\Platform\Entry\EntryRepository; use Anomaly\Streams\Platform\Entry\EntryRepository;
use Visiosoft\CatsModule\Category\CategoryModel; use Visiosoft\CatsModule\Category\CategoryModel;
use Visiosoft\AdvsModule\Category\Contract\CategoryRepositoryInterface; use Visiosoft\AdvsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\DopingsModule\Doping\DopingModel;
use Visiosoft\LocationModule\City\CityModel; use Visiosoft\LocationModule\City\CityModel;
use Visiosoft\LocationModule\Country\CountryModel; use Visiosoft\LocationModule\Country\CountryModel;
@ -22,6 +24,16 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
*/ */
protected $model; protected $model;
/**
* @var FileRepositoryInterface
*/
private $fileRepository;
/**
* @var FolderRepositoryInterface
*/
private $folderRepository;
/** /**
* Create a new AdvRepository instance. * Create a new AdvRepository instance.
* *
@ -29,11 +41,15 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
*/ */
public function __construct( public function __construct(
AdvModel $model, AdvModel $model,
SettingRepositoryInterface $settings SettingRepositoryInterface $settings,
FileRepositoryInterface $fileRepository,
FolderRepositoryInterface $folderRepository
) )
{ {
$this->model = $model; $this->model = $model;
$this->settings = $settings; $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) public function cover_image_update($adv)
{ {
if (count($adv->files) != 0) { if (count($adv->files) != 0) {
$file_url = 'files/images/' . $adv->files[0]->name; $fileName = 'tn-' . $adv->files[0]->name;
$adv->update(['cover_photo' => $file_url]); $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]);
}
} }
} }

View File

@ -554,14 +554,14 @@ class AdvsController extends PublicController
$parent_cat = $categoryModel->getParentCats($request->cat1, 'parent_id'); $parent_cat = $categoryModel->getParentCats($request->cat1, 'parent_id');
$packageModel = new PackageModel(); $packageModel = new PackageModel();
$package = $packageModel->reduceLimit($parent_cat, 'reduce'); $package = $packageModel->reduceLimit($parent_cat, 'reduce');
if ($package != null) if ($package != null) {
$this->messages->error(trans('visiosoft.module.advs::message.please_buy_package')); $this->messages->error(trans('visiosoft.module.advs::message.please_buy_package'));
return redirect('/');
} else { }
} elseif ($adv->slug == '') {
$this->messages->error(trans('visiosoft.module.advs::message.max_ad_limit.title')); $this->messages->error(trans('visiosoft.module.advs::message.max_ad_limit.title'));
return redirect('/');
} }
return redirect('/');
} }
$adv->is_get_adv = $request->is_get_adv; $adv->is_get_adv = $request->is_get_adv;

View File

@ -6,6 +6,7 @@ use Visiosoft\LocationModule\Country\CountryModel;
use Visiosoft\LocationModule\District\DistrictModel; use Visiosoft\LocationModule\District\DistrictModel;
use Visiosoft\LocationModule\Neighborhood\NeighborhoodModel; use Visiosoft\LocationModule\Neighborhood\NeighborhoodModel;
use Visiosoft\LocationModule\Village\VillageModel; use Visiosoft\LocationModule\Village\VillageModel;
use Illuminate\Support\Str;
class AjaxController extends PublicController 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 $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];
}
}
}
} }

View File

@ -84,6 +84,7 @@ class LocationModuleServiceProvider extends AddonServiceProvider
'as' => 'location::getCities', 'as' => 'location::getCities',
'uses' => 'Visiosoft\LocationModule\Http\Controller\AjaxController@getCities' 'uses' => 'Visiosoft\LocationModule\Http\Controller\AjaxController@getCities'
], ],
'ajax/get-city' => 'Visiosoft\LocationModule\Http\Controller\AjaxController@getCity',
'ajax/getDistricts' => [ 'ajax/getDistricts' => [
'as' => 'location::getDistricts', 'as' => 'location::getDistricts',
'uses' => 'Visiosoft\LocationModule\Http\Controller\AjaxController@getDistricts' 'uses' => 'Visiosoft\LocationModule\Http\Controller\AjaxController@getDistricts'

View File

@ -59,38 +59,63 @@ class UploadController extends AdminController
$watermarktype = $settings->value('visiosoft.module.advs::watermark_type'); $watermarktype = $settings->value('visiosoft.module.advs::watermark_type');
$position = $settings->value('visiosoft.module.advs::watermark_position'); $position = $settings->value('visiosoft.module.advs::watermark_position');
$img = WaterMark::make($this->request->file('upload')->getRealPath()) $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)) ->resize(
->resizeCanvas(setting_value('visiosoft.field_type.media::imageCanvasW', 800), setting_value('visiosoft.field_type.media::imageCanvasH', 600), 'center', false, 'fff'); setting_value('visiosoft.field_type.media::imageResizeW', null),
if ($watermarktype == 'image') { setting_value('visiosoft.field_type.media::imageResizeH', 600)
)
$watermarkimage_id = $settings->value('visiosoft.module.advs::watermark_image'); ->resizeCanvas(
$watermarkimage = $files->find($watermarkimage_id); setting_value('visiosoft.field_type.media::imageCanvasW', 800),
$w = $img->width(); setting_value('visiosoft.field_type.media::imageCanvasH', 600),
if ($watermarkimage != null) { 'center',
$watermark = WaterMark::make(app_storage_path() . '/files-module/local/' . $watermarkimage->path()); false,
$img->insert($watermark, $position); '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 { $files->create([
$watermarktext = $settings->value('visiosoft.module.advs::watermark_text'); 'folder_id' => $this->request->get('folder'),
$v = "top"; 'name' => $fileName,
$h = "center"; 'disk_id' => 1,
$w = $img->width() / 2; 'size' => $image->filesize(),
$h1 = $img->height() / 2; 'mime_type' => $image->mime,
$font_size = $w / 20; 'extension' => $image->extension,
$img->text($watermarktext, $w, $h1, function ($font) use ($v, $h, $font_size) { ]);
$font->file(public_path('Antonio-Bold.ttf')); }
$font->size($font_size); $image->save(app_storage_path() . '/files-module/local/images/' . $fileName);
$font->align($h);
$font->valign($v);
});
} }
$img->save(app_storage_path() . '/files-module/local/images/' . $file->getAttributes()['name']);
return $this->response->json($file->getAttributes()); return $this->response->json($file->getAttributes());
} }
return $this->response->json(['error' => 'There was a problem uploading the file.'], 500); return $this->response->json(['error' => 'There was a problem uploading the file.'], 500);