Merge pull request #735 from openclassify/dia

#2342 [seo-module] Create
This commit is contained in:
Fatih Alp 2020-10-21 19:13:02 +03:00 committed by GitHub
commit 95c126e7fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 36 deletions

View File

@ -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)

View File

@ -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');
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 = '';
$catText = '';
if (!$allCats) {
if (count($mainCats) == 1 || count($mainCats) == 2) {
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));
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', "<link rel='canonical' href='$canonUrl'/>");
}
$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)
@ -658,8 +667,7 @@ class AdvsController extends PublicController
CategoryRepositoryInterface $categoryRepository,
Dispatcher $events,
AdvModel $advModel,
AdressRepositoryInterface $address,
CategoryModel $categoryModel
AdressRepositoryInterface $address
)
{
if (!Auth::user()) {
@ -684,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']);
}
}
}

View File

@ -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)