diff --git a/models/SeoDynamicLang.php b/models/SeoDynamicLang.php index d1fe6b6..dbe61de 100755 --- a/models/SeoDynamicLang.php +++ b/models/SeoDynamicLang.php @@ -48,7 +48,6 @@ return [ [ [ - 'meta_title', 'meta_description', 'seo_text', ], @@ -101,8 +100,7 @@ return [ 'seo_dynamic_id' => Yii::t('app', 'seo_dynamic_id'), 'language_id' => Yii::t('app', 'language_id'), - 'title' => 'name', - 'meta_title' => 'title', + 'title' => 'title', 'h1' => 'h1', 'key' => 'key', 'meta' => 'meta', diff --git a/views/seo-dynamic/_form_language.php b/views/seo-dynamic/_form_language.php index 868665e..192fff6 100755 --- a/views/seo-dynamic/_form_language.php +++ b/views/seo-dynamic/_form_language.php @@ -17,9 +17,6 @@ field($model_lang, '[' . $language->id . ']title') ->textInput([ 'maxlength' => true ]); ?> -field($model_lang, '[' . $language->id . ']meta_title') - ->textInput(); ?> - field($model_lang, '[' . $language->id . ']meta_description')->textarea() ?> field($model_lang, '[' . $language->id . ']key') diff --git a/views/seo-dynamic/index.php b/views/seo-dynamic/index.php index a9455bf..6c06f2e 100755 --- a/views/seo-dynamic/index.php +++ b/views/seo-dynamic/index.php @@ -47,10 +47,6 @@ 'columns' => [ [ 'class' => 'yii\grid\SerialColumn' ], 'id', - [ - 'attribute' => 'title', - 'value' => 'lang.title', - ], 'action', 'fields', 'param', diff --git a/widgets/Seo.php b/widgets/Seo.php index 9eed985..0d166db 100755 --- a/widgets/Seo.php +++ b/widgets/Seo.php @@ -66,7 +66,7 @@ class Seo extends Widget if(empty($filter) && empty($sort) && empty($paginate) ){ - return $this->selectSeoData(self::SEO_TEXT); + return $this->prepareString($this->selectSeoData(self::SEO_TEXT)); } else { @@ -84,13 +84,13 @@ class Seo extends Widget if ($widgetData instanceof SeoDynamic) { - $result = $widgetData->{self::SEO_TEXT}; + $result = $widgetData->lang->{self::SEO_TEXT}; } } - return $this->replaceData($result); + return $this->prepareString($this->replaceData($result)); } @@ -103,18 +103,18 @@ class Seo extends Widget if ($default != $this->{self::H1}) { - return $default; + return $this->prepareString($default); } else if(!empty($filter) && !$this->checkFilter($filter)){ $array = $this->arrayBuilder($filter); - return $this->getNameString($array); + return $this->prepareString($this->getNameString($array,$default)); } else { - return $default; + return $this->prepareString($default); } - break; + break; case self::TITLE: $filter = \Yii::$app->request->get('filters', []); @@ -122,25 +122,23 @@ class Seo extends Widget $title = $this->selectSeoData(self::TITLE); - - if(!empty($filter) && $title == $this->title || !empty($filter) && empty($title)) { + if(!empty($filter) && $title == $this->{Seo::TITLE} || !empty($filter) && empty($this->{Seo::TITLE})) { $array = $this->arrayBuilder($filter); - $title_string = $this->getTitleString($array); + $title_string = $this->getTitleString($array, $title); if($title_string){ - return $title_string; + return $this->prepareString($title_string); } } if (!empty($title)) { - - return $title; + return $this->prepareString($title); } else { - return $this->project_name; + return $this->prepareString($this->project_name); } break; @@ -151,7 +149,7 @@ class Seo extends Widget $this->getView()->registerMetaTag([ 'name' => 'description', - 'content' => $description + 'content' => $this->prepareString($description) ]); } else { @@ -162,7 +160,7 @@ class Seo extends Widget $array = $this->arrayBuilder($filter); $this->getView()->registerMetaTag([ 'name' => 'description', - 'content' => $this->getDescriptionString($array) + 'content' => $this->prepareString($this->getDescriptionString($array,$description)) ]); } @@ -205,8 +203,8 @@ class Seo extends Widget ]); } else if ( - isset($filter['brands']) && count($filter['brands']) > 1 && isset($filter) && count($filter, COUNT_RECURSIVE) >= 4 - || isset($filter) && count($filter, COUNT_RECURSIVE) > 4 + 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']) ) { @@ -254,9 +252,7 @@ class Seo extends Widget protected function findSeoByDynamic() { -// print_r(\Yii::$app->controller->id); -// print_r(\Yii::$app->controller->action->id); -// die(); + if(!empty($this->key)){ $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id, 'key' => $this->key]); @@ -297,110 +293,71 @@ class Seo extends Widget $widgetData = static::findSeoByUrl($this->url); + $widgetDynamicData = $this->findSeoByDynamic(); + if ($widgetData instanceof \artweb\artbox\seo\models\Seo) { $result = $widgetData->$param; - } else if (!empty($this->$param)) { - $widgetData = $this->findSeoByDynamic(); - - if ($widgetData instanceof SeoDynamic) { + } else if ($widgetDynamicData instanceof SeoDynamic) { - $result = $widgetData->lang->$param; - - } - - } else { + $result = $widgetDynamicData->lang->$param; + } else if(!empty($this->$param)) { $result = $this->$param; - - - } return $this->replaceData($result); } - public function getTitleString($array){ - // "{Название раздела: Название блока фильтра | Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3} - купить в Киеве, Украине - интернет магазин Лінія Світла"; + public function getTitleString($array, $title){ + $row = ''; foreach($array as $name => $field){ + $row .= $field['name'] .' '.$field['value'].' ' ; + } - if($name == 'category' ){ - $row = $field.' | '.$row; - } else { - $row .= $field['name'] .' '.$field['value'].' | ' ; - } - - + $template = preg_replace('/{filter}/',$row,$title); - } - $row = substr($row, 0,-2 ); - $row .= " - купить в Киеве, Украине - интернет магазин Екстрим стайл"; - return $row; -// $template = SeoDynamic::find()->select('title')->where(['param' =>'filters'])->one(); -// if($template instanceof SeoDynamic){ -// foreach ($array as $field_name => $field_value) { -// $template->title = str_replace('{' . $field_name . '}', mb_strtolower($field_value), $template->title); -// } -// $template = preg_replace('/\{.[^\}]*\}\s/','',$template->title); -// return $template; -// } -// -// return false; + return $template; } - public function getDescriptionString($array){ - // "Лучшие цены на {Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. Лінія Світла"; - $row = 'Лучшие цены на '; - foreach($array as $name => $field){ - - if($name == 'category' ){ - $row = $field.' | '.$row; - } else { - $row .= $field['name'] .' '.$field['value'].' | ' ; - } + public function getDescriptionString($array, $description){ + $row = ''; + foreach($array as $name => $field){ + $row .= $field['name'] .' '.$field['value'].' ' ; + } + $template = preg_replace('/{filter}/',$row,$title); - } - $row = substr($row, 0,-2 ); - $row .= ". Екстрим стайл"; - return $row; + return $template; } - public function getNameString($array){ - // "Лучшие цены на {Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. Лінія Світла"; + public function getNameString($array, $h1){ + $row = ''; foreach($array as $name => $field){ + $row .= $field['name'] .' '.$field['value'].' ' ; + } - if($name == 'category' ){ - $row = $field.' | '.$row; - } else { - $row .= $field['name'] .' '.$field['value'].' | ' ; - } - + $template = preg_replace('/{filter}/',$row,$title); - - } - $row = substr($row, 0,-2 ); - return $row; + return $template; } + /** + * @param $filter + * @return mixed + */ public function arrayBuilder($filter) { - - $array = [ - 'category' => $this->category_name - ]; - - if (isset($filter['brands']) && count($filter['brands']) == 1) { $model = Brand::find()->joinWith('lang')->where(['alias' => $filter['brands'][0]])->one(); if (!$model instanceof Brand) { @@ -441,6 +398,10 @@ class Seo extends Widget } + /** + * @param $filter + * @return bool + */ protected function checkFilter($filter){ foreach(self::$optionsList as $optionList){ @@ -452,5 +413,11 @@ class Seo extends Widget return false; } + /** + * @param $string + */ + public function prepareString($string){ + return preg_replace('/\{.[^\}]*\}/','',$string); + } } \ No newline at end of file -- libgit2 0.21.4