From e57ad02f6f63ad94e9933a78961ee4b9e7abd653 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 31 Oct 2016 18:31:29 +0200 Subject: [PATCH] 14.09.16 --- frontend/widgets/Seo.php | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------ 1 file changed, 58 insertions(+), 120 deletions(-) diff --git a/frontend/widgets/Seo.php b/frontend/widgets/Seo.php index c25bb90..889a944 100755 --- a/frontend/widgets/Seo.php +++ b/frontend/widgets/Seo.php @@ -101,21 +101,49 @@ class Seo extends Widget $filter = \Yii::$app->request->get('filters', []); - $default = $this->selectSeoData(self::H1); - if ($default != $this->{self::H1}) { - return $default; + if (isset($filter['brands']) && count($filter['brands']) == 1) { + $model = Brand::find()->where(['alias' => $filter['brands'][0]])->one(); + if(!$model instanceof Brand){ - } else if(!empty($filter) && !$this->checkFilter($filter)){ + \Yii::$app->response->redirect(['/site/error'],404); + } else { + if($this->selectSeoData(self::H1) == $this->category_name) { - $array = $this->arrayBuilder($filter); - return $this->getNameString($array); - } - else { + return $this->selectSeoData(self::H1) . ' ' . $model->name ; + }else { + + return $this->selectSeoData(self::H1); + + } + } + + + + } else if (isset($filter["naznacenie"]) && count($filter["naznacenie"]) == 1) { + + $model = TaxOption::find()->where(['alias' => $filter["naznacenie"]])->one(); + if(!$model instanceof TaxOption){ + + \Yii::$app->response->redirect(['/site/error'],404); + } else { + if($this->selectSeoData(self::H1) == $this->category_name) { - return $default; + return $this->selectSeoData(self::H1) . ' ' . $model->value->value; + }else { + + return $this->selectSeoData(self::H1); + + } + + } + + + + } else { + return $this->selectSeoData(self::H1); } break; case self::TITLE: @@ -192,18 +220,6 @@ class Seo extends Widget 'content' => $description ]); - } else { - - $filter = \Yii::$app->request->get('filters', []); - - if(!empty($filter)){ - $array = $this->arrayBuilder($filter); - $this->getView()->registerMetaTag([ - 'name' => 'description', - 'content' => $this->getDescriptionString($array) - ]); - } - } break; @@ -211,20 +227,31 @@ class Seo extends Widget $meta = $this->selectSeoData(self::META); + $widgetData = static::findSeoByUrl($this->url); + $filter = \Yii::$app->request->get('filters', []); $sort = \Yii::$app->request->get('sort', []); $paginate = \Yii::$app->request->get('page', []); - - if (!empty($meta) && empty($sort) && empty($paginate) && !isset($filter['prices']) ) { + if (!empty($meta)) { $this->getView()->registerMetaTag([ 'name' => 'robots', 'content' => $meta ]); - } else if(!empty($filter['special'])){ + } + else if ($widgetData instanceof \common\models\Seo) { + + $this->getView()->registerMetaTag([ + 'name' => 'robots', + 'content' =>'index,follow' + ]); + + } + + else if(!empty($filter['special'])){ $this->getView()->registerMetaTag([ 'name' => 'robots', @@ -232,24 +259,24 @@ class Seo extends Widget ]); } else if ( - isset($filter['brands']) && count($filter['brands']) > 1 - || isset($filter) && $this->checkFilter($filter)|| !empty($sort) || !empty($paginate) || isset($filter['prices']) + isset($filter['brands']) && count($filter['brands']) > 1 || isset($filter) && $this->checkFilter($filter) ) { - - $this->getView()->registerMetaTag([ 'name' => 'robots', 'content' => 'noindex,nofollow' ]); - } else if ( isset($filter) && count($filter, COUNT_RECURSIVE) > 4) { + } else if ( + isset($filter['brands']) && count($filter['brands']) <= 1 && isset($filter) && count($filter, COUNT_RECURSIVE) >= 2 + || isset($filter) && count($filter, COUNT_RECURSIVE) >= 2 + || !empty($sort) || !empty($paginate) || isset($filter['prices']) + ) { $this->getView()->registerMetaTag([ 'name' => 'robots', 'content' => 'noindex,follow' ]); - } - else { + } else { $this->getView()->registerMetaTag([ 'name' => 'robots', @@ -381,93 +408,4 @@ class Seo extends Widget return $fc.mb_substr($str, 1); } - public function getDescriptionString($array){ - // "{Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. по самой лучшей цене с гарантией от производителя - Ruzkachok.com.ua"; - $row = ''; - foreach($array as $name => $field){ - - if($name == 'category' ){ - $row = $field.' '.$row; - } else { - $row .= $field['name'] .' '.$field['value'].' ' ; - } - - - - } - $row = substr($row, 0,-2 ); - $row .= " по самой лучшей цене с гарантией от производителя - Rukzachok.com.ua"; - return $row; - - } - - - public function getNameString($array){ - $row = ''; - foreach($array as $name => $field){ - - if($name == 'category' ){ - $row = $field.' '.$row; - } else { - $row .= $field['name'] .' '.$field['value'].' ' ; - } - - - - } - $row = substr($row, 0,-2 ); - return $row; - - } - - public function arrayBuilder($filter) - { - - $array = [ - 'category' => $this->category_name - ]; - - - if (isset($filter['brands']) && count($filter['brands']) == 1) { - $model = Brand::find()->where(['alias' => $filter['brands'][0]])->one(); - if (!$model instanceof Brand) { - - \Yii::$app->response->redirect(['/site/error'], 404); - } else { - $array['brand']['name'] = 'Бренд'; - $array['brand']['value'] = $model->name; - } - - } - - - $optionsList = ArrayHelper::map(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(), 'alias', 'name'); - - - foreach ($optionsList as $optionList => $name) { - - - if (isset($filter[$optionList]) && count($filter[$optionList]) == 1) { - - $model = TaxOption::find()->where(['alias' => $filter[$optionList]])->one(); - if (!$model instanceof TaxOption) { - - \Yii::$app->response->redirect(['site/error'], 404); - } else { - $array[$optionList]['value'] = $model->value; - $array[$optionList]['name'] = $name; - } - - - } - - - } - - return $array; - - } - - - } \ No newline at end of file -- libgit2 0.21.4