setTemplate('search', 'listings'); $this->setKey('search'); $this->withSeoSettings('search', 'listings')->titleH1()->seotext(); $this->setTitle(_t('@listings', 'Listings / Search')); $this->useBreadcrumbs(); if (! $this->filter) { $this->filter = FilterBlock::i(); } } /** * Handle request and route to page * @param string $category * @return mixed */ public static function handleRoute($category = '') { $category = trim($category, ' /\\'); $filter = FilterBlock::i([ 'categoryKeyword' => $category, ]); # Unknown category keyword if ($category && ! $filter->categoryId) { return Errors::error404(); } if ( Request::isGET() && $filter->categoryId && $filter->categoryData['numlevel'] == 1 && $filter->categoryData['settings']['subcats_view'] && ! $filter->anyGetFilters ) { return new CategoryPage([ 'filter' => $filter, ]); } if ($filter->categoryId) { return new SearchCategoryPage([ 'filter' => $filter, ]); } return new SearchPage([ 'filter' => $filter, ]); } public function data() { $data = parent::data(); $this->getList()->loadList(); # Banners + query if ($this->filter->hasSearchQuery()) { Banners::viewQuery($this->filter->query); } # Category crumbs $this->filter->categoryData['crumbs'] = Listings::categoryCrumbs($this->filter->categoryId, 'search'); $data['category'] = &$this->filter->categoryData; # Page number $data['page'] = $this->filter->page; return $data; } public function blocks() { $this->addBlock('filterBlock', $this->filter); $this->addBlock('sortBlock', function () { return $this->filter->getSortBlock(); }); $this->addBlock('listBlock', function () { $view = $this->app->filter('listings.search.list.view', [ ListFactory::LIST => ListBlock::class, ListFactory::GALLERY => GalleryListBlock::class, ListFactory::MAP => MapListBlock::class, ])[$this->getBlock('filterBlock')->listView ?: ListFactory::GALLERY]; return new $view(['filter' => $this->filter]); }); $this->addBlock('categoriesBlock', CategoriesBlock::class, function (CategoriesBlock $block) { $block->filter = $this->filter; $block->categoryId = $this->filter->categoryId; }); $this->addBlock('relinkBlock', RelinkBlock::class, function (RelinkBlock $block) { $block->filter = $this->filter; }); } /** * List block * @return ListBlock|mixed */ public function getList() { return $this->getBlock('listBlock'); } public function seo() { if ($this->isGET()) { $this->seoCorrectUrlEndSlash(); } $catID = $this->filter->categoryId; $catData = &$this->filter->categoryData; $region = $this->filter->region; $total = $this->filter->total; $this->seo->with([ 'page' => $this->filter->page, 'total' => $total, 'total.text' => tpl::declension($total, _t('listings', 'listing;listings;listings')), 'query' => $this->filter->query, ]); $geoData = $this->seoMacrosRegionsData($region); # Canonical Url $skipPrefix = ! $catID && $region && $this->config('listings.index.region.search.canonical', false); # TODO: sett? $this->seo->canonicalUrl( Listings::url('items.search', [ 'keyword' => $catData['keyword'], 'landing_url' => $catData['landing_url'], 'skip_prefix' => $skipPrefix, ], true), ['page' => $this->filter->page] ); # Breadcrumbs + macros data if (!$region && Geo::coveringType([Geo::COVERING_COUNTRY,Geo::COVERING_REGION])) { $region = Geo::coveringRegion(); # id $filterRegionCovering = true; } foreach ($catData['crumbs'] as &$crumb) { if ($crumb['id'] > 0) { $this->seo->with('category', $crumb['title']); } else { $crumb['mtemplate'] = 0; # skip seo general template } $this->seo->fieldPlaceholders('breadcrumb', [(!$region ? 'region' : ''),'city']); $this->seoApply($crumb, [ 'landing-skip' => ($crumb['id'] !== $catID), ]); } unset($crumb); # Fields placeholders settings $this->seo ->fieldPlaceholders('titleh1', [(!$region ? 'region' : ''),]) ->fieldPlaceholders('seotext', [(!empty($filterRegionCovering) ? 'region.key' : ''),]); # Wrap category seotext $this->data['seotext'] = &$catData['seotext']; # Noindex categories without listings if ($catID && ! $total && ! $this->config('listings.search.cats.empty.index', false, TYPE_BOOL)) { # Получаем кол-во объявлений в категории $catItemsCountFilter = ['cat_id' => $catID]; if ($region > 0) { $catItemsCountFilter['geo'] = $geoData; } if (! Listings::model()->itemsPublicatedCounter($catItemsCountFilter)) { $this->seo->index(false); } } # Apply $this->seoApply($catData); # H1 $this->data['titleh1'] = _t('search', 'Search Listings'); if (($catID || $this->seoLandingPage() !== false || ! $this->filter->hasSearchQuery()) && ! empty($catData['titleh1'])) { $this->data['titleh1'] = $catData['titleh1']; } elseif ($this->filter->hasSearchQuery()) { $this->data['titleh1'] = _t('search', 'Search results for query "[query]"', ['query' => $this->filter->query]); } # Breadcrumbs $this->breadcrumbs->fill($catData['crumbs'], function ($crumb) { return [ 'title' => $crumb['breadcrumb'], 'link' => $crumb['link'] ?? '', ]; }); } public function seoSettings() { $this->seo ->placeholder('total', _t('listings', 'Number of listings in the list')) ->placeholder('total.text', _t('listings', 'The number of listings in the list in the form - "N listings"')) ->list(); $this->seoMacrosRegions(); # + breadcrumb, titleh1, seotext } }