Commit 0d0c080c7346da88dd8af3d0e84c1ceef6300251

Authored by Dmytry Fedorchuk
1 parent be02a25c

seo module filter meta robot

backend/views/seo/_form.php
... ... @@ -17,6 +17,8 @@ use mihaildev\elfinder\ElFinder;
17 17  
18 18 <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
19 19  
  20 + <?= $form->field($model, 'meta')->textInput(['maxlength' => true]) ?>
  21 +
20 22 <?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?>
21 23  
22 24 <?= $form->field($model, 'h1')->textInput(['maxlength' => true]) ?>
... ...
backend/views/seo/_search.php
... ... @@ -19,7 +19,9 @@ use yii\widgets\ActiveForm;
19 19  
20 20 <?= $form->field($model, 'url') ?>
21 21  
22   - <?= $form->field($model, 'title') ?>
  22 + <?= $form->field($model, 'meta') ?>
  23 +
  24 + <?= $form->field($model, 'title') ?>
23 25  
24 26 <?= $form->field($model, 'description') ?>
25 27  
... ...
backend/views/seo/index.php
... ... @@ -26,6 +26,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
26 26  
27 27 'seo_id',
28 28 'url:url',
  29 + 'meta',
29 30 'title',
30 31 'description',
31 32 'h1',
... ...
backend/views/seo/view.php
... ... @@ -31,6 +31,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
31 31 'seo_id',
32 32 'url:url',
33 33 'title',
  34 + 'meta',
34 35 'description',
35 36 'h1',
36 37 'seo_text:ntext',
... ...
common/models/Seo.php
... ... @@ -10,6 +10,7 @@ use Yii;
10 10 * @property integer $seo_id
11 11 * @property string $url
12 12 * @property string $title
  13 + * @property string $meta
13 14 * @property string $description
14 15 * @property string $h1
15 16 * @property string $seo_text
... ... @@ -32,7 +33,7 @@ class Seo extends \yii\db\ActiveRecord
32 33 return [
33 34 [['url'], 'required'],
34 35 [['seo_text'], 'string'],
35   - [['url', 'title', 'description', 'h1'], 'string', 'max' => 255],
  36 + [['url', 'title', 'meta', 'description', 'h1'], 'string', 'max' => 255],
36 37 ];
37 38 }
38 39  
... ... @@ -45,6 +46,7 @@ class Seo extends \yii\db\ActiveRecord
45 46 'seo_id' => Yii::t('app', 'seo_id'),
46 47 'url' => Yii::t('app', 'url'),
47 48 'title' => Yii::t('app', 'title'),
  49 + 'meta' => Yii::t('app', 'meta_title'),
48 50 'description' => Yii::t('app', 'description'),
49 51 'h1' => Yii::t('app', 'h1'),
50 52 'seo_text' => Yii::t('app', 'seo_text'),
... ...
common/models/SeoSearch.php
... ... @@ -19,7 +19,7 @@ class SeoSearch extends Seo
19 19 {
20 20 return [
21 21 [['seo_id'], 'integer'],
22   - [['url', 'title', 'description', 'h1', 'seo_text'], 'safe'],
  22 + [['url', 'title', 'meta', 'description', 'h1', 'seo_text'], 'safe'],
23 23 ];
24 24 }
25 25  
... ... @@ -64,6 +64,7 @@ class SeoSearch extends Seo
64 64  
65 65 $query->andFilterWhere(['like', 'url', $this->url])
66 66 ->andFilterWhere(['like', 'title', $this->title])
  67 + ->andFilterWhere(['like', 'meta', $this->meta])
67 68 ->andFilterWhere(['like', 'description', $this->description])
68 69 ->andFilterWhere(['like', 'h1', $this->h1])
69 70 ->andFilterWhere(['like', 'seo_text', $this->seo_text]);
... ...
frontend/views/catalog/product.php
... ... @@ -2,7 +2,7 @@
2 2 use yii\widgets\Breadcrumbs;
3 3 use yii\web\View;
4 4 use yii\helpers\Url;
5   -$this->params['seo']['title'] = $product->fullname ;
  5 +$this->params['seo']['title'] = $product->fullname;
6 6 $this->title = $product->fullname;
7 7 //$this->title = (! empty($product->meta_title)) ? $product->meta_title : $product->fullname;
8 8 //$this->registerMetaTag (['name' => 'description', 'content' => ((! empty($product->meta_description)) ? $product->meta_description : $product->fullname)]);
... ...
frontend/views/layouts/main.php
... ... @@ -85,6 +85,7 @@ ga(&#39;send&#39;, &#39;pageview&#39;);
85 85 <?= Html::csrfMetaTags () ?>
86 86 <title><?= Seo::widget([ 'row'=>'title'])?></title>
87 87 <?= Seo::widget([ 'row'=>'description'])?>
  88 + <?= Seo::widget([ 'row'=>'meta'])?>
88 89 <link rel="shortcut icon" href="<?= Yii::$app->request->baseUrl ?>/img/favicon.ico" type="image/x-icon"/>
89 90 <?= HreflangWidget::widget ([]) ?>
90 91 <?php $this->head () ?>
... ...
frontend/widgets/Seo.php
... ... @@ -12,6 +12,7 @@ class Seo extends Widget
12 12 public $fields;
13 13 public $description;
14 14 public $title;
  15 + public $meta;
15 16 public $seo_text;
16 17 public $h1;
17 18 public $key;
... ... @@ -22,6 +23,7 @@ class Seo extends Widget
22 23  
23 24 const SEO_TEXT = 'seo_text';
24 25 const DESCRIPTION = 'description';
  26 + const META = 'meta';
25 27 const H1 = 'h1';
26 28 const TITLE = 'title';
27 29  
... ... @@ -52,27 +54,28 @@ class Seo extends Widget
52 54 break;
53 55 case self::TITLE:
54 56  
55   - $filter = \Yii::$app->request->get('filter', []);
56   - if(!empty($filter)){
57   - $filter_row = '';
58   - foreach($filter as $sub_filter_name => $sub_filter_array){
59   - if($sub_filter_name=='options'){
60   - foreach($sub_filter_array as $f_name=>$f_values){
61   - $filter_row .= $f_name.':'.implode(',',$f_values).'|';
62   - }
63   - }
64   -
65   - }
66   - $this->fields['name'] = $filter_row;
67   - }
  57 + $filter = \Yii::$app->request->get('filter', []);
  58 + // var_dump($filter );die();
  59 +// if(!empty($filter)){
  60 +// $filter_row = '';
  61 +// foreach($filter as $sub_filter_name => $sub_filter_array){
  62 +// if($sub_filter_name=='options'){
  63 +// foreach($sub_filter_array as $f_name=>$f_values){
  64 +// $filter_row .= $f_name.':'.implode(',',$f_values).'|';
  65 +// }
  66 +// }
  67 +//
  68 +// }
  69 +// $this->fields['name'] = $filter_row;
  70 +// }
68 71  
69 72 $title = $this->selectSeoData(self::TITLE);
70 73  
71 74  
72   - if(!empty($filter_row)){
73   - return $filter_row;
74   - }
75   - if(!empty($title)){
  75 +// if(!empty($filter_row)){
  76 +// return $filter_row;
  77 +// }
  78 + if (!empty($title)) {
76 79 return $title;
77 80 } else {
78 81 return $this->project_name;
... ... @@ -82,16 +85,54 @@ class Seo extends Widget
82 85 case self::DESCRIPTION:
83 86 $description = $this->selectSeoData(self::DESCRIPTION);
84 87  
85   - if(!empty($description)){
  88 + if (!empty($description)) {
86 89  
87 90 $this->getView()->registerMetaTag([
88 91 'name' => 'description',
89   - 'content' => $description
  92 + 'content' => $description
90 93 ]);
91 94  
92 95 }
93 96  
94 97 break;
  98 + case self::META:
  99 + $meta = $this->selectSeoData(self::META);
  100 +
  101 + $filter = \Yii::$app->request->get('filter', []);
  102 +
  103 +
  104 +
  105 + if(!empty($meta)){
  106 +
  107 + $this->getView()->registerMetaTag([
  108 + 'name' => 'robots',
  109 + 'content' => $meta
  110 + ]);
  111 +
  112 + } else if (
  113 + isset($filter['brands']) && count($filter['brands']) > 1
  114 + || isset($filter['options']["pol"]) && count($filter['options']["pol"]) > 1
  115 + || isset($filter['options']["naznacenie"]) && count($filter['options']["naznacenie"]) > 1
  116 + || isset($filter['options']["god"]) && count($filter['options']["god"]) > 1
  117 + || isset($filter['brands']) && count($filter['brands']) <= 1 && isset($filter['options']) && count($filter['options'], COUNT_RECURSIVE) >= 4
  118 + || isset($filter['options']) && count($filter['options'], COUNT_RECURSIVE) > 4
  119 +
  120 + ){
  121 + $this->getView()->registerMetaTag([
  122 + 'name' => 'robots',
  123 + 'content' => 'noindex,follow'
  124 + ]);
  125 +
  126 + } else if($filter) {
  127 +
  128 + $this->getView()->registerMetaTag([
  129 + 'name' => 'robots',
  130 + 'content' => 'index,follow'
  131 + ]);
  132 + }
  133 +
  134 +
  135 + break;
95 136 }
96 137  
97 138  
... ... @@ -145,7 +186,6 @@ class Seo extends Widget
145 186 }else if(!empty($this->$param)){
146 187  
147 188 $result = $this->$param;
148   -
149 189 } else {
150 190  
151 191 $widgetData = $this->findSeoByDynamic();
... ...