From 9fa9adf7948489cc2e4d6736ee22715ef9296710 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 31 Oct 2016 19:13:31 +0200 Subject: [PATCH] 14.09.16 --- frontend/widgets/Seo.php | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 118 insertions(+), 28 deletions(-) diff --git a/frontend/widgets/Seo.php b/frontend/widgets/Seo.php index 889a944..64b42ec 100755 --- a/frontend/widgets/Seo.php +++ b/frontend/widgets/Seo.php @@ -56,7 +56,7 @@ class Seo extends Widget foreach ($seoData as $key => $value) { $this->$key = $value; } - + switch ($this->row) { case self::SEO_TEXT: @@ -124,7 +124,7 @@ class Seo extends Widget } else if (isset($filter["naznacenie"]) && count($filter["naznacenie"]) == 1) { - $model = TaxOption::find()->where(['alias' => $filter["naznacenie"]])->one(); + $model = TaxOption::find()->where(['alias' => $filter["naznacenie"]])->one(); if(!$model instanceof TaxOption){ \Yii::$app->response->redirect(['/site/error'],404); @@ -145,7 +145,7 @@ class Seo extends Widget } else { return $this->selectSeoData(self::H1); } - break; + break; case self::TITLE: $filter = \Yii::$app->request->get('filters', []); @@ -220,6 +220,18 @@ 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; @@ -227,31 +239,20 @@ 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)) { - $this->getView()->registerMetaTag([ - 'name' => 'robots', - 'content' => $meta - ]); - - } - else if ($widgetData instanceof \common\models\Seo) { + if (!empty($meta) && empty($sort) && empty($paginate) && !isset($filter['prices']) ) { $this->getView()->registerMetaTag([ 'name' => 'robots', - 'content' =>'index,follow' + 'content' => $meta ]); - } - - else if(!empty($filter['special'])){ + } else if(!empty($filter['special'])){ $this->getView()->registerMetaTag([ 'name' => 'robots', @@ -259,24 +260,24 @@ class Seo extends Widget ]); } else if ( - isset($filter['brands']) && count($filter['brands']) > 1 || isset($filter) && $this->checkFilter($filter) + isset($filter['brands']) && count($filter['brands']) > 1 + || isset($filter) && $this->checkFilter($filter)|| !empty($sort) || !empty($paginate) || isset($filter['prices']) ) { + + $this->getView()->registerMetaTag([ 'name' => 'robots', 'content' => 'noindex,nofollow' ]); - } 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']) - ) { + } else if ( isset($filter) && count($filter, COUNT_RECURSIVE) > 4) { $this->getView()->registerMetaTag([ 'name' => 'robots', 'content' => 'noindex,follow' ]); - } else { + } + else { $this->getView()->registerMetaTag([ 'name' => 'robots', @@ -363,18 +364,18 @@ class Seo extends Widget $result = ''; $widgetData = static::findSeoByUrl($this->url); - + if ($widgetData instanceof \common\models\Seo) { $result = $widgetData->$param; } else if (!empty($this->$param)) { $result = $this->$param; - + } else { $widgetData = $this->findSeoByDynamic(); - + if ($widgetData instanceof SeoDynamic) { $result = $widgetData->$param; @@ -401,11 +402,100 @@ class Seo extends Widget return false; } - + public function my_mb_ucfirst($str) { $str = strtolower($str); $fc = mb_strtoupper(mb_substr($str, 0, 1)); 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 .= " по самой лучшей цене с гарантией от производителя - Ruzkachok.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