Commit 8afa1bf26291cd96626b5cc722e7ce4c96c6e93c
1 parent
66aa1226
29.06.16
Showing
4 changed files
with
76 additions
and
56 deletions
Show diff stats
common/components/Request.php
1 | +<?php | |
2 | +namespace frontend\components; | |
3 | + | |
4 | + | |
5 | +use Yii; | |
6 | +use yii\base\BootstrapInterface; | |
7 | + | |
8 | +class SeoComponent implements BootstrapInterface | |
9 | +{ | |
10 | + | |
11 | + public function bootstrap($app) | |
12 | + { | |
13 | + \Yii::$app->on(\yii\base\Application::EVENT_BEFORE_REQUEST, function($event) { | |
14 | + $array = ['%21'=>'!','%22'=>'"','%23'=>'#','%24'=>'$','%25'=>'%','%26'=>'&','%27'=>'\'','%28'=>'(','%29'=>')','%2a'=>'*','%2b'=>'+','%2c'=>',','%2d'=>'-','%2e'=>'.','%2f'=>'/','%3a'=>':','%3b'=>';','%3c'=>'<','%3d'=>'=','%3e'=>'>','%3f'=>'?','%40'=>'@','%5b'=>'[','%5c'=>'\\','%5d'=>']','%5e'=>'^','%5f'=>'_','%60'=>'`','%7b'=>'{','%7c'=>'|','%7d'=>'}','%7e'=>'~']; | |
15 | + $url = mb_strtolower (\Yii::$app->request->url); | |
16 | + | |
17 | + $continue = true; | |
18 | + | |
19 | + foreach($array as $sym=>$sym_row){ | |
20 | + if(strpos($url, $sym)){ | |
21 | + $url = str_replace($sym, $sym_row, $url); | |
22 | + $continue = false; | |
23 | + | |
24 | + } | |
25 | + } | |
26 | + | |
27 | + if(!$continue){ | |
28 | + \Yii::$app->getResponse()->redirect($url); | |
29 | + } | |
30 | + | |
31 | + }); | |
32 | + return $app; | |
33 | + } | |
34 | + | |
35 | +} | |
0 | 36 | \ No newline at end of file | ... | ... |
frontend/config/main.php
... | ... | @@ -9,7 +9,10 @@ $params = array_merge( |
9 | 9 | return [ |
10 | 10 | 'id' => 'app-frontend', |
11 | 11 | 'basePath' => dirname(__DIR__), |
12 | - 'bootstrap' => ['log'], | |
12 | + 'bootstrap' => [ | |
13 | + | |
14 | + 'frontend\components\SeoComponent', | |
15 | + ], | |
13 | 16 | 'controllerNamespace' => 'frontend\controllers', |
14 | 17 | 'components' => [ |
15 | 18 | 'authManager' => [ | ... | ... |
frontend/widgets/Seo.php
... | ... | @@ -197,68 +197,49 @@ class Seo extends Widget |
197 | 197 | $sort = \Yii::$app->request->get('sort', []); |
198 | 198 | $paginate = \Yii::$app->request->get('page', []); |
199 | 199 | |
200 | - $array = ['%21','%22','%23','%24','%25','%26','%27','%28','%29','%2a','%2b','%2c','%2d','%2e','%2f','%3a','%3b','%3c','%3d','%3e','%3f','%40','%5b','%5c','%5d','%5e','%5f','%60','%7b','%7c','%7d','%7e',]; | |
201 | - $url = mb_strtolower (\Yii::$app->request->url); | |
202 | 200 | |
203 | - $continue = true; | |
204 | 201 | |
205 | - foreach($array as $sym){ | |
206 | - if(strpos($url, $sym)){ | |
207 | - $this->getView()->registerMetaTag([ | |
208 | - 'name' => 'robots', | |
209 | - 'content' => 'noindex,nofollow' | |
210 | - ]); | |
202 | + if (!empty($meta)) { | |
211 | 203 | |
212 | - $continue = false; | |
213 | - break; | |
204 | + $this->getView()->registerMetaTag([ | |
205 | + 'name' => 'robots', | |
206 | + 'content' => $meta | |
207 | + ]); | |
214 | 208 | |
215 | - } | |
216 | - } | |
209 | + } else if(!empty($filter['special'])){ | |
217 | 210 | |
211 | + $this->getView()->registerMetaTag([ | |
212 | + 'name' => 'robots', | |
213 | + 'content' => 'noindex,follow' | |
214 | + ]); | |
218 | 215 | |
219 | - if($continue){ | |
220 | - if (!empty($meta)) { | |
221 | - | |
222 | - $this->getView()->registerMetaTag([ | |
223 | - 'name' => 'robots', | |
224 | - 'content' => $meta | |
225 | - ]); | |
226 | - | |
227 | - } else if(!empty($filter['special'])){ | |
228 | - | |
229 | - $this->getView()->registerMetaTag([ | |
230 | - 'name' => 'robots', | |
231 | - 'content' => 'noindex,follow' | |
232 | - ]); | |
233 | - | |
234 | - } else if ( | |
235 | - isset($filter['brands']) && count($filter['brands']) > 1 | |
236 | - || isset($filter['options']["pol"]) && count($filter['options']["pol"]) > 1 | |
237 | - || isset($filter['options']["naznacenie"]) && count($filter['options']["naznacenie"]) > 1 | |
238 | - || isset($filter['options']["god"]) && count($filter['options']["god"]) > 1 | |
239 | - | |
240 | - ) { | |
241 | - $this->getView()->registerMetaTag([ | |
242 | - 'name' => 'robots', | |
243 | - 'content' => 'noindex,nofollow' | |
244 | - ]); | |
245 | - | |
246 | - } else if ( | |
247 | - isset($filter['brands']) && count($filter['brands']) <= 1 && isset($filter['options']) && count($filter['options'], COUNT_RECURSIVE) >= 4 | |
248 | - || isset($filter['options']) && count($filter['options'], COUNT_RECURSIVE) > 4 | |
249 | - || !empty($sort) || !empty($paginate) || isset($filter['prices']) | |
250 | - ) { | |
251 | - $this->getView()->registerMetaTag([ | |
252 | - 'name' => 'robots', | |
253 | - 'content' => 'noindex,follow' | |
254 | - ]); | |
255 | - } else { | |
216 | + } else if ( | |
217 | + isset($filter['brands']) && count($filter['brands']) > 1 | |
218 | + || isset($filter['options']["pol"]) && count($filter['options']["pol"]) > 1 | |
219 | + || isset($filter['options']["naznacenie"]) && count($filter['options']["naznacenie"]) > 1 | |
220 | + || isset($filter['options']["god"]) && count($filter['options']["god"]) > 1 | |
256 | 221 | |
257 | - $this->getView()->registerMetaTag([ | |
258 | - 'name' => 'robots', | |
259 | - 'content' => 'index,follow' | |
260 | - ]); | |
261 | - } | |
222 | + ) { | |
223 | + $this->getView()->registerMetaTag([ | |
224 | + 'name' => 'robots', | |
225 | + 'content' => 'noindex,nofollow' | |
226 | + ]); | |
227 | + | |
228 | + } else if ( | |
229 | + isset($filter['brands']) && count($filter['brands']) <= 1 && isset($filter['options']) && count($filter['options'], COUNT_RECURSIVE) >= 4 | |
230 | + || isset($filter['options']) && count($filter['options'], COUNT_RECURSIVE) > 4 | |
231 | + || !empty($sort) || !empty($paginate) || isset($filter['prices']) | |
232 | + ) { | |
233 | + $this->getView()->registerMetaTag([ | |
234 | + 'name' => 'robots', | |
235 | + 'content' => 'noindex,follow' | |
236 | + ]); | |
237 | + } else { | |
238 | + | |
239 | + $this->getView()->registerMetaTag([ | |
240 | + 'name' => 'robots', | |
241 | + 'content' => 'index,follow' | |
242 | + ]); | |
262 | 243 | } |
263 | 244 | |
264 | 245 | ... | ... |