Commit d57c2c6265e7b3790fc188be27db487894af323e
1 parent
f703530f
sitemap controller fix noindex
Showing
1 changed file
with
14 additions
and
16 deletions
Show diff stats
console/controllers/SiteMapController.php
| @@ -28,7 +28,7 @@ class SiteMapController extends Controller | @@ -28,7 +28,7 @@ class SiteMapController extends Controller | ||
| 28 | private $count = 1; | 28 | private $count = 1; |
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | - public function checkFilter($category, $filter){ | 31 | + public function checkFilter($category, $filter) { |
| 32 | $productModel = new ProductFrontendSearch(); | 32 | $productModel = new ProductFrontendSearch(); |
| 33 | $productProvider = $productModel->search($category, $filter); | 33 | $productProvider = $productModel->search($category, $filter); |
| 34 | if(!empty($productProvider->models)){ | 34 | if(!empty($productProvider->models)){ |
| @@ -38,7 +38,7 @@ class SiteMapController extends Controller | @@ -38,7 +38,7 @@ class SiteMapController extends Controller | ||
| 38 | } | 38 | } |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | - public function getAddStatic(){ | 41 | + public function getAddStatic() { |
| 42 | return [ | 42 | return [ |
| 43 | 'http://www.rukzachok.com.ua', | 43 | 'http://www.rukzachok.com.ua', |
| 44 | 'http://www.rukzachok.com.ua/catalog' | 44 | 'http://www.rukzachok.com.ua/catalog' |
| @@ -52,22 +52,21 @@ class SiteMapController extends Controller | @@ -52,22 +52,21 @@ class SiteMapController extends Controller | ||
| 52 | 52 | ||
| 53 | public function getSeoLinks() { | 53 | public function getSeoLinks() { |
| 54 | return Seo::find()->where(['meta' => ''])->all(); | 54 | return Seo::find()->where(['meta' => ''])->all(); |
| 55 | - | ||
| 56 | } | 55 | } |
| 57 | 56 | ||
| 58 | - public function getStaticPages(){ | 57 | + public function getStaticPages() { |
| 59 | return Page::find()->all(); | 58 | return Page::find()->all(); |
| 60 | } | 59 | } |
| 61 | 60 | ||
| 62 | - public function getCategories(){ | ||
| 63 | - return Category::find()->all(); | 61 | + public function getCategories() { |
| 62 | + return Category::find()->where(['meta_robots' => ''])->all(); | ||
| 64 | } | 63 | } |
| 65 | 64 | ||
| 66 | - public function getArticles(){ | 65 | + public function getArticles() { |
| 67 | return Articles::find()->all(); | 66 | return Articles::find()->all(); |
| 68 | } | 67 | } |
| 69 | 68 | ||
| 70 | - public function getBrands($category){ | 69 | + public function getBrands($category) { |
| 71 | 70 | ||
| 72 | return $category->brands; | 71 | return $category->brands; |
| 73 | } | 72 | } |
| @@ -76,14 +75,13 @@ class SiteMapController extends Controller | @@ -76,14 +75,13 @@ class SiteMapController extends Controller | ||
| 76 | * @param $category Category; | 75 | * @param $category Category; |
| 77 | * @return mixed | 76 | * @return mixed |
| 78 | */ | 77 | */ |
| 79 | - | ||
| 80 | - public function getFilters($category){ | 78 | + public function getFilters($category) { |
| 81 | 79 | ||
| 82 | return $category->getActiveFilters()->all(); | 80 | return $category->getActiveFilters()->all(); |
| 83 | 81 | ||
| 84 | } | 82 | } |
| 85 | 83 | ||
| 86 | - public function checkUrl($url){ | 84 | + public function checkUrl($url) { |
| 87 | 85 | ||
| 88 | if (preg_match('/filters:[^=]+=[^=]+;[^=]+=[^=]+/', $url)) { | 86 | if (preg_match('/filters:[^=]+=[^=]+;[^=]+=[^=]+/', $url)) { |
| 89 | $reverse_url = preg_replace('/filters:([^=]+=[^=]+);([^=]+=[^=]+)/', 'filters:$2;$1', $url); | 87 | $reverse_url = preg_replace('/filters:([^=]+=[^=]+);([^=]+=[^=]+)/', 'filters:$2;$1', $url); |
| @@ -97,7 +95,7 @@ class SiteMapController extends Controller | @@ -97,7 +95,7 @@ class SiteMapController extends Controller | ||
| 97 | } | 95 | } |
| 98 | } | 96 | } |
| 99 | 97 | ||
| 100 | - public function createRow( $url, $priority, &$content ){ | 98 | + public function createRow( $url, $priority, &$content ) { |
| 101 | if($this->checkUrl($url)){ | 99 | if($this->checkUrl($url)){ |
| 102 | print $this->count++ . "\n"; | 100 | print $this->count++ . "\n"; |
| 103 | $content .= '<url>' . | 101 | $content .= '<url>' . |
| @@ -160,7 +158,7 @@ class SiteMapController extends Controller | @@ -160,7 +158,7 @@ class SiteMapController extends Controller | ||
| 160 | } | 158 | } |
| 161 | 159 | ||
| 162 | 160 | ||
| 163 | - foreach($this->getCategories() as $category){ | 161 | + foreach($this->getCategories() as $category) { |
| 164 | foreach ($this->getBrands($category) as $brand) { | 162 | foreach ($this->getBrands($category) as $brand) { |
| 165 | if($this->checkFilter($category, ['brands' => [$brand->brand_id]])){ | 163 | if($this->checkFilter($category, ['brands' => [$brand->brand_id]])){ |
| 166 | $url = Url::to(['catalog/category', 'category' => $category, 'filters' => ['brands' => [$brand->alias]]]) ; | 164 | $url = Url::to(['catalog/category', 'category' => $category, 'filters' => ['brands' => [$brand->alias]]]) ; |
| @@ -170,7 +168,7 @@ class SiteMapController extends Controller | @@ -170,7 +168,7 @@ class SiteMapController extends Controller | ||
| 170 | } | 168 | } |
| 171 | 169 | ||
| 172 | 170 | ||
| 173 | - foreach($this->getCategories() as $category){ | 171 | + foreach($this->getCategories() as $category) { |
| 174 | foreach ($this->getFilters($category) as $filter) { | 172 | foreach ($this->getFilters($category) as $filter) { |
| 175 | if($this->checkFilter($category, [$filter['group_alias'] => [$filter['option_alias']]])){ | 173 | if($this->checkFilter($category, [$filter['group_alias'] => [$filter['option_alias']]])){ |
| 176 | $url = Url::to(['catalog/category', 'category' => $category, 'filters' => [$filter['group_alias'] => [$filter['option_alias']]] ]); | 174 | $url = Url::to(['catalog/category', 'category' => $category, 'filters' => [$filter['group_alias'] => [$filter['option_alias']]] ]); |
| @@ -180,7 +178,7 @@ class SiteMapController extends Controller | @@ -180,7 +178,7 @@ class SiteMapController extends Controller | ||
| 180 | } | 178 | } |
| 181 | } | 179 | } |
| 182 | 180 | ||
| 183 | - foreach($this->getSeoLinks() as $link){ | 181 | + foreach($this->getSeoLinks() as $link) { |
| 184 | $url = Yii::$app->urlManager->baseUrl.$link->url; | 182 | $url = Yii::$app->urlManager->baseUrl.$link->url; |
| 185 | $this->createRow($url , 0.7, $content); | 183 | $this->createRow($url , 0.7, $content); |
| 186 | 184 | ||
| @@ -188,7 +186,7 @@ class SiteMapController extends Controller | @@ -188,7 +186,7 @@ class SiteMapController extends Controller | ||
| 188 | 186 | ||
| 189 | 187 | ||
| 190 | 188 | ||
| 191 | - foreach($this->getCategories() as $category){ | 189 | + foreach($this->getCategories() as $category) { |
| 192 | foreach ($this->getFilters($category) as $filter1) { | 190 | foreach ($this->getFilters($category) as $filter1) { |
| 193 | foreach ($this->getFilters($category) as $filter2) { | 191 | foreach ($this->getFilters($category) as $filter2) { |
| 194 | if($this->checkFilter($category, [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] )){ | 192 | if($this->checkFilter($category, [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] )){ |