From 0b25add3d4137d83c9f906b30c3951bc78074ce9 Mon Sep 17 00:00:00 2001 From: Diatrex Date: Wed, 12 Feb 2020 16:06:19 +0300 Subject: [PATCH] #74 Improvements of SEO link structure like Vebze --- .../views/list/partials/list-filter.twig | 17 +++++- .../src/Adv/Command/appendRequestURL.php | 18 +++++- .../src/AdvsModuleServiceProvider.php | 4 ++ .../Http/Controller/CategoriesController.php | 3 +- .../src/Http/Controller/advsController.php | 59 ++++++++++++++++++- .../views/ads-list/partials/list-filter.twig | 46 ++++++++------- .../ads-list/partials/location-fields.twig | 4 +- 7 files changed, 120 insertions(+), 31 deletions(-) diff --git a/addons/default/visiosoft/advs-module/resources/views/list/partials/list-filter.twig b/addons/default/visiosoft/advs-module/resources/views/list/partials/list-filter.twig index 6185bc537..0af3c879b 100644 --- a/addons/default/visiosoft/advs-module/resources/views/list/partials/list-filter.twig +++ b/addons/default/visiosoft/advs-module/resources/views/list/partials/list-filter.twig @@ -1,4 +1,16 @@ -
+{% if 'cat' in param|keys %} + {% set catId = entries('cats', 'category').find(param['cat']) %} + {% set cityId = null %} + {% if 'city' in param|keys %} + {% set citiesArray = param['city'][0]|split(',') %} + {% if count(citiesArray) is same as(1) %} + {% set cityId = entries('location', 'cities').find(param['city'][0]) %} + {% endif %} + {% endif %} + +{% else %} + +{% endif %}
@@ -16,7 +28,8 @@ 'cities':cities, 'districts':districts, 'neighborhoods':neighborhoods, - 'villages':villages + 'villages':villages, + 'param':param })|raw }} diff --git a/addons/default/visiosoft/advs-module/src/Adv/Command/appendRequestURL.php b/addons/default/visiosoft/advs-module/src/Adv/Command/appendRequestURL.php index 03715dba0..af6962551 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Command/appendRequestURL.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Command/appendRequestURL.php @@ -28,9 +28,21 @@ class appendRequestURL */ public function handle() { - return $this->url - . (Str::contains($this->url, '?') ? '&' : '?') - . Arr::query($this->appends(array_merge($this->request, $this->new_parameters))); + if (count($this->new_parameters) === 0 && count($this->request) === 0) { + return $this->url; + } elseif (count($this->request) > 0) { + return $this->url + . (Str::contains($this->url, '?') ? '&' : '?') + . Arr::query($this->appends($this->request)); + } elseif (count($this->new_parameters) > 0) { + return $this->url + . (Str::contains($this->url, '?') ? '&' : '?') + . Arr::query($this->appends($this->new_parameters)); + } else { + return $this->url + . (Str::contains($this->url, '?') ? '&' : '?') + . Arr::query($this->appends(array_merge($this->request, $this->new_parameters))); + } } /** diff --git a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php index 39e7ddb1d..814e2cee3 100644 --- a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php +++ b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php @@ -132,6 +132,10 @@ class AdvsModuleServiceProvider extends AddonServiceProvider ], 'advs/categories' => 'Visiosoft\AdvsModule\Http\Controller\CategoriesController@index', 'advs/c/{cat}' => 'Visiosoft\AdvsModule\Http\Controller\CategoriesController@listByCat', + 'c/{category?}/{city?}' => [ + 'as' => 'adv_list_seo', + 'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@index' + ], 'advs/module_active' => 'Visiosoft\AdvsModule\Http\Controller\advsController@index', 'advs/create_adv' => [ 'as' => "advs::create_adv", diff --git a/addons/default/visiosoft/advs-module/src/Http/Controller/CategoriesController.php b/addons/default/visiosoft/advs-module/src/Http/Controller/CategoriesController.php index 05d8fba37..034e64b19 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/CategoriesController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/CategoriesController.php @@ -6,7 +6,8 @@ use Illuminate\Support\Facades\DB; class CategoriesController extends PublicController { - public function listByCat($cat) { + public function listByCat($cat) + { $advs = DB::table('advs_advs') ->where('cat1', $cat) ->orwhere('cat2', $cat) 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 7ed8f86bd..9fdc6f4ae 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php @@ -6,11 +6,13 @@ use Anomaly\Streams\Platform\Model\Advs\AdvsAdvsEntryModel; use Anomaly\Streams\Platform\Model\Advs\PurchasePurchaseEntryModel; use Anomaly\Streams\Platform\Model\Complaints\ComplaintsComplainTypesEntryModel; use Anomaly\Streams\Platform\Model\Options\OptionsAdvertisementEntryModel; +use Visiosoft\AdvsModule\Adv\Command\appendRequestURL; use Visiosoft\AdvsModule\Adv\Event\showAdPhone; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Cookie; use Illuminate\Support\Facades\DB; +use Visiosoft\LocationModule\City\CityRepository; use function PMA\Util\get; use Sunra\PhpSimple\HtmlDomParser; use Visiosoft\AdvsModule\Adv\AdvModel; @@ -61,6 +63,7 @@ class AdvsController extends PublicController private $country_repository; private $city_model; + private $cityRepository; private $district_model; @@ -85,6 +88,7 @@ class AdvsController extends PublicController CountryRepositoryInterface $country_repository, CityModel $city_model, + CityRepository $cityRepository, DistrictModel $district_model, @@ -111,6 +115,7 @@ class AdvsController extends PublicController $this->country_repository = $country_repository; $this->city_model = $city_model; + $this->cityRepository = $cityRepository; $this->district_model = $district_model; @@ -138,7 +143,7 @@ class AdvsController extends PublicController /** * @return \Illuminate\Contracts\View\View|mixed */ - public function index() + public function index($category = null, $city = null) { $customParameters = array(); $featured_advs = array(); @@ -146,11 +151,55 @@ class AdvsController extends PublicController $param = $this->requestHttp->toArray(); - $countries = $this->country_repository->viewAll(); $isActiveDopings = $this->adv_model->is_enabled('dopings'); + // Search by category slug + if ($category) { + $categoryId = $this->category_repository->findBy('slug', $category); + if ($categoryId) { + $param['cat'] = $categoryId->id; + } + } + + // Search by city slug + if (is_null($city) && isset($param['city'][0]) && !empty($param['city'][0]) && strpos($param['city'][0], ',') === false) { + $cityId = $this->cityRepository->find($param['city'][0]); + return redirect($this->fullLink( + $param, + route('adv_list_seo', [$categoryId->slug, $cityId->slug]), + array() + )); + } elseif (isset($param['city']) && !empty($param['city'][0]) && strpos($param['city'][0], ',') === false) { + $cityId = $this->cityRepository->find($param['city'][0]); + $param['city'] = [$cityId->id]; + if ($city !== $cityId->slug) { + return redirect($this->fullLink( + $param, + route('adv_list_seo', [$categoryId->slug, $cityId->slug]), + array() + )); + } + } elseif ($city && isset($param['city'][0]) && !empty($param['city'][0]) && strpos($param['city'][0], ',') !== false) { + return redirect($this->fullLink( + $param, + route('adv_list_seo', [$categoryId->slug]), + array() + )); + } elseif ($city) { + if (isset($param['city'][0]) && empty($param['city'][0])) { + return redirect($this->fullLink( + $param, + route('adv_list_seo', [$categoryId->slug]), + array() + )); + } else { + $cityId = $this->cityRepository->findBy('slug', $city); + $param['city'] = [$cityId->id]; + } + } + $isActiveCustomFields = $this->adv_model->is_enabled('customfields'); $advs = $this->adv_repository->searchAdvs('list', $param, $customParameters); $advs = $this->adv_repository->addAttributes($advs); @@ -218,7 +267,7 @@ class AdvsController extends PublicController $viewType = $this->requestHttp->cookie('viewType'); - $compact = compact('advs', 'countries', 'mainCats', 'subCats', 'checkboxes', 'request', + $compact = compact('advs', 'countries', 'mainCats', 'subCats', 'checkboxes', 'request', 'param', 'user', 'userProfile', 'featured_advs', 'viewType', 'topfields', 'ranges', 'seenList', 'searchedCountry', 'radio'); if (isset($viewType) and $viewType == 'table') @@ -231,6 +280,10 @@ class AdvsController extends PublicController return $this->view->make('visiosoft.module.advs::list/list', $compact); } + public function fullLink($request, $url, $newParameters) { + return $this->dispatch(new appendRequestURL($request, $url, $newParameters)); + } + public function viewType($type) { Cookie::queue(Cookie::make('viewType', $type, 84000)); diff --git a/addons/default/visiosoft/cats-module/resources/views/ads-list/partials/list-filter.twig b/addons/default/visiosoft/cats-module/resources/views/ads-list/partials/list-filter.twig index c81d14f5c..8961f7c04 100644 --- a/addons/default/visiosoft/cats-module/resources/views/ads-list/partials/list-filter.twig +++ b/addons/default/visiosoft/cats-module/resources/views/ads-list/partials/list-filter.twig @@ -17,33 +17,39 @@ {% set id = maincat['id'] %} {% set parent_category = true %} {% if app.request.get('cat') is null or app.request.get('cat') == "" %} - {% set name = maincat.name %} - {% set id = maincat.id %} - {% set parent_category = false %} + {% if params.param['cat'] is null or params.param['cat'] == "" %} + {% set name = maincat.name %} + {% set id = maincat.id %} + {% set parent_category = false %} + {% endif %} {% endif %} - + {% set catId = entries('cats', 'category').find(id) %} + {% set cityId = null %} + {% if 'city' in params.param|keys %} + {% set citiesArray = params.param['city'][0]|split(',') %} + {% if count(citiesArray) is same as(1) %} + {% set cityId = entries('location', 'cities').find(params.param['city'][0]) %} + {% endif %} + {% endif %} + {{ name }} {% for subcat in params.subCats %}
{% if subcat.parent_category_id == maincat['id'] %} - {{ subcat.name }} + {% set subCatId = entries('cats', 'category').find(subcat.id) %} + + {{ subcat.name }} + {% endif %}
{% endfor %} diff --git a/addons/default/visiosoft/location-module/resources/views/ads-list/partials/location-fields.twig b/addons/default/visiosoft/location-module/resources/views/ads-list/partials/location-fields.twig index 7156b88a7..f674df48a 100644 --- a/addons/default/visiosoft/location-module/resources/views/ads-list/partials/location-fields.twig +++ b/addons/default/visiosoft/location-module/resources/views/ads-list/partials/location-fields.twig @@ -18,7 +18,7 @@ {{ trans("visiosoft.module.location::field.city.name") }} - {% set selected_cities = app.request.get('city') %} + {% set selected_cities = params.param['city'] %} {% set selected_cities_name = [] %} {% for selected_city in selected_cities[0]|split(',') %} {% set selected_cities_name = selected_cities_name|merge([getCity(selected_city|trim(',')).name]) %} @@ -26,7 +26,7 @@
{{ selected_cities_name|join(',') }}
- +