From 821bcd4cc81621168df649c12c9778cf3c6a5944 Mon Sep 17 00:00:00 2001 From: Diatrex Date: Wed, 21 Oct 2020 15:40:50 +0300 Subject: [PATCH 1/3] #2342 [seo-module] Create --- .../src/Http/Controller/advsController.php | 69 +++++++++++-------- .../src/Category/CategoryRepository.php | 2 +- 2 files changed, 40 insertions(+), 31 deletions(-) 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 969f80a16..8c8a3b8a1 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php @@ -254,15 +254,6 @@ class AdvsController extends PublicController if ($categoryId) { - $seo_keywords = $this->category_model->getMeta_keywords($categoryId->id); - $seo_description = $this->category_model->getMeta_description($categoryId->id); - $seo_title = $this->category_model->getMeta_title($categoryId->id); - - $this->template->set('og_description', $seo_description); - $this->template->set('meta_description', $seo_description); - $this->template->set('meta_title', $seo_title); - $this->template->set('meta_keywords', implode(', ', $seo_keywords)); - $mainCats = $this->category_model->getMains($categoryId->id); $current_cat = $this->category_model->getCat($categoryId->id); $mainCats[] = [ @@ -369,13 +360,36 @@ class AdvsController extends PublicController $viewType = $this->requestHttp->cookie('viewType'); - $catText = ''; - if (!$allCats) { - if (count($mainCats) == 1 || count($mainCats) == 2) { + list('catText' => $catText, 'user' => $user) = $this->handleSeo($categoryId, $mainCats, $cityId); + + $compact = compact('advs', 'countries', 'mainCats', 'subCats', 'checkboxes', 'param', + 'user', 'featured_advs', 'viewType', 'topfields', 'selectDropdown', 'selectRange', 'selectImage', 'ranges', + 'seenList', 'radio', 'categoryId', 'cityId', 'allCats', 'catText', 'cFArray'); + + return $this->viewTypeBasedRedirect($viewType, $compact); + } + + private function handleSeo($category, $mainCats, $city) + { + $showTitle = true; + $metaTitle = ''; + + if ($category) { + $seo_keywords = $this->category_model->getMeta_keywords($category->id); + $seo_description = $this->category_model->getMeta_description($category->id); + $seo_title = $this->category_model->getMeta_title($category->id); + + $this->template->set('og_description', $seo_description); + $this->template->set('meta_description', $seo_description); + $this->template->set('meta_keywords', implode(', ', $seo_keywords)); + + $catText = ''; + if ($city) { + $catText = "$city->name $catText"; + } elseif (count($mainCats) == 1 || count($mainCats) == 2) { $catText = end($mainCats)['val']; } elseif (count($mainCats) > 2) { $catArray = array_slice($mainCats, 2); - $catText = ''; $loop = 0; foreach ($catArray as $cat) { $catText = !$loop ? $catText . $cat['val'] : $catText . ' ' . $cat['val']; @@ -383,34 +397,29 @@ class AdvsController extends PublicController } } - if ($cityId) { - $catText = "$cityId->name $catText"; - } - - $this->template->set('showTitle', false); - $this->template->set('meta_title', $catText); + $showTitle = false; + $metaTitle = $catText ?: $seo_title; } $user = null; - if (!empty($param['user'])) { - $user = $this->userRepository->find($param['user']); - $this->template->set('showTitle', false); - $this->template->set('meta_title', $user->name() . ' ' . trans('visiosoft.module.advs::field.ads')); + if (\request()->user) { + $user = $this->userRepository->find(\request()->user); + $showTitle = false; + $metaTitle = $user->name() . ' ' . trans('visiosoft.module.advs::field.ads'); } + $this->template->set('showTitle', $showTitle); + $this->template->set('meta_title', $metaTitle); + // Set rel="canonical" - if (array_key_exists('sort_by', $param) || array_key_exists('doping', $param)) { - $canonParam = $param; + if (\request()->sort_by || \request()->doping) { + $canonParam = \request()->all(); unset($canonParam['sort_by'], $canonParam['doping']); $canonUrl = fullLink($canonParam, \request()->url()); $this->template->set('additional_meta', ""); } - $compact = compact('advs', 'countries', 'mainCats', 'subCats', 'checkboxes', 'param', - 'user', 'featured_advs', 'viewType', 'topfields', 'selectDropdown', 'selectRange', 'selectImage', 'ranges', - 'seenList', 'radio', 'categoryId', 'cityId', 'allCats', 'catText', 'cFArray'); - - return $this->viewTypeBasedRedirect($viewType, $compact); + return compact('catText', 'user'); } public function viewTypeBasedRedirect($viewType, $compact) diff --git a/addons/default/visiosoft/cats-module/src/Category/CategoryRepository.php b/addons/default/visiosoft/cats-module/src/Category/CategoryRepository.php index 3f7995a8b..d92229ef1 100644 --- a/addons/default/visiosoft/cats-module/src/Category/CategoryRepository.php +++ b/addons/default/visiosoft/cats-module/src/Category/CategoryRepository.php @@ -35,7 +35,7 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn public function mainCats() { - return $this->model->where('parent_category_id', null)->where('deleted_at', null)->orderBy('sort_order')->get(); + return $this->model->where('parent_category_id', null)->orderBy('sort_order')->get(); } public function getItem($cat) From b60004ae1548574b03fd89b77ed05a51a3854225 Mon Sep 17 00:00:00 2001 From: Diatrex Date: Wed, 21 Oct 2020 18:01:21 +0300 Subject: [PATCH 2/3] =?UTF-8?q?#2436=20Ad=20post=20"L=C3=BCtfen=20Paket=20?= =?UTF-8?q?Sat=C4=B1n=20Al=C4=B1n!"=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/default/visiosoft/advs-module/src/Adv/AdvModel.php | 4 ++-- .../advs-module/src/Http/Controller/advsController.php | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php index bf879d2ad..e48dab82a 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php @@ -67,9 +67,9 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface return $query->where('advs_advs.slug', '!=', ""); } - public function userAdv($nullable_ad = false) + public function userAdv($nullable_ad = false, $checkRole = true) { - if (Auth::user()->hasRole('admin')) { + if (Auth::user()->hasRole('admin') && $checkRole) { return $this->getAdv(null, $nullable_ad); } else { return $this->getAdv(null, $nullable_ad) 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 710bbbbce..788713470 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php @@ -667,8 +667,7 @@ class AdvsController extends PublicController CategoryRepositoryInterface $categoryRepository, Dispatcher $events, AdvModel $advModel, - AdressRepositoryInterface $address, - CategoryModel $categoryModel + AdressRepositoryInterface $address ) { if (!Auth::user()) { @@ -693,10 +692,10 @@ class AdvsController extends PublicController if ($advModel->is_enabled('packages') and $adv->slug == "") { $cat = app('Visiosoft\PackagesModule\Http\Controller\PackageFEController')->AdLimitForNewAd($request); if (!is_null($cat)) { - if (is_array($cat) && array_key_exists('allowPendingAds', $cat)) { + if (array_key_exists('allowPendingAds', $cat)) { $allowPendingAdCreation = $cat['allowPendingAds']; } else { - return redirect('/'); + return redirect($cat['redirect']); } } } From ab1791f10a3fa42cde5b257441f475c31961a267 Mon Sep 17 00:00:00 2001 From: Diatrex Date: Wed, 21 Oct 2020 18:04:45 +0300 Subject: [PATCH 3/3] fix --- .../advs-module/src/Http/Controller/advsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 788713470..62c5af4da 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php @@ -373,6 +373,7 @@ class AdvsController extends PublicController { $showTitle = true; $metaTitle = ''; + $catText = ''; if ($category) { $seo_keywords = $this->category_model->getMeta_keywords($category->id); @@ -383,7 +384,6 @@ class AdvsController extends PublicController $this->template->set('meta_description', $seo_description); $this->template->set('meta_keywords', implode(', ', $seo_keywords)); - $catText = ''; if ($city) { $catText = "$city->name $catText"; } elseif (count($mainCats) == 1 || count($mainCats) == 2) {