Commit 0d0c080c7346da88dd8af3d0e84c1ceef6300251
1 parent
be02a25c
seo module filter meta robot
Showing
9 changed files
with
74 additions
and
24 deletions
Show diff stats
backend/views/seo/_form.php
@@ -17,6 +17,8 @@ use mihaildev\elfinder\ElFinder; | @@ -17,6 +17,8 @@ use mihaildev\elfinder\ElFinder; | ||
17 | 17 | ||
18 | <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?> | 18 | <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?> |
19 | 19 | ||
20 | + <?= $form->field($model, 'meta')->textInput(['maxlength' => true]) ?> | ||
21 | + | ||
20 | <?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?> | 22 | <?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?> |
21 | 23 | ||
22 | <?= $form->field($model, 'h1')->textInput(['maxlength' => true]) ?> | 24 | <?= $form->field($model, 'h1')->textInput(['maxlength' => true]) ?> |
backend/views/seo/_search.php
@@ -19,7 +19,9 @@ use yii\widgets\ActiveForm; | @@ -19,7 +19,9 @@ use yii\widgets\ActiveForm; | ||
19 | 19 | ||
20 | <?= $form->field($model, 'url') ?> | 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 | <?= $form->field($model, 'description') ?> | 26 | <?= $form->field($model, 'description') ?> |
25 | 27 |
backend/views/seo/index.php
@@ -26,6 +26,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -26,6 +26,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
26 | 26 | ||
27 | 'seo_id', | 27 | 'seo_id', |
28 | 'url:url', | 28 | 'url:url', |
29 | + 'meta', | ||
29 | 'title', | 30 | 'title', |
30 | 'description', | 31 | 'description', |
31 | 'h1', | 32 | 'h1', |
backend/views/seo/view.php
@@ -31,6 +31,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -31,6 +31,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
31 | 'seo_id', | 31 | 'seo_id', |
32 | 'url:url', | 32 | 'url:url', |
33 | 'title', | 33 | 'title', |
34 | + 'meta', | ||
34 | 'description', | 35 | 'description', |
35 | 'h1', | 36 | 'h1', |
36 | 'seo_text:ntext', | 37 | 'seo_text:ntext', |
common/models/Seo.php
@@ -10,6 +10,7 @@ use Yii; | @@ -10,6 +10,7 @@ use Yii; | ||
10 | * @property integer $seo_id | 10 | * @property integer $seo_id |
11 | * @property string $url | 11 | * @property string $url |
12 | * @property string $title | 12 | * @property string $title |
13 | + * @property string $meta | ||
13 | * @property string $description | 14 | * @property string $description |
14 | * @property string $h1 | 15 | * @property string $h1 |
15 | * @property string $seo_text | 16 | * @property string $seo_text |
@@ -32,7 +33,7 @@ class Seo extends \yii\db\ActiveRecord | @@ -32,7 +33,7 @@ class Seo extends \yii\db\ActiveRecord | ||
32 | return [ | 33 | return [ |
33 | [['url'], 'required'], | 34 | [['url'], 'required'], |
34 | [['seo_text'], 'string'], | 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,6 +46,7 @@ class Seo extends \yii\db\ActiveRecord | ||
45 | 'seo_id' => Yii::t('app', 'seo_id'), | 46 | 'seo_id' => Yii::t('app', 'seo_id'), |
46 | 'url' => Yii::t('app', 'url'), | 47 | 'url' => Yii::t('app', 'url'), |
47 | 'title' => Yii::t('app', 'title'), | 48 | 'title' => Yii::t('app', 'title'), |
49 | + 'meta' => Yii::t('app', 'meta_title'), | ||
48 | 'description' => Yii::t('app', 'description'), | 50 | 'description' => Yii::t('app', 'description'), |
49 | 'h1' => Yii::t('app', 'h1'), | 51 | 'h1' => Yii::t('app', 'h1'), |
50 | 'seo_text' => Yii::t('app', 'seo_text'), | 52 | 'seo_text' => Yii::t('app', 'seo_text'), |
common/models/SeoSearch.php
@@ -19,7 +19,7 @@ class SeoSearch extends Seo | @@ -19,7 +19,7 @@ class SeoSearch extends Seo | ||
19 | { | 19 | { |
20 | return [ | 20 | return [ |
21 | [['seo_id'], 'integer'], | 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,6 +64,7 @@ class SeoSearch extends Seo | ||
64 | 64 | ||
65 | $query->andFilterWhere(['like', 'url', $this->url]) | 65 | $query->andFilterWhere(['like', 'url', $this->url]) |
66 | ->andFilterWhere(['like', 'title', $this->title]) | 66 | ->andFilterWhere(['like', 'title', $this->title]) |
67 | + ->andFilterWhere(['like', 'meta', $this->meta]) | ||
67 | ->andFilterWhere(['like', 'description', $this->description]) | 68 | ->andFilterWhere(['like', 'description', $this->description]) |
68 | ->andFilterWhere(['like', 'h1', $this->h1]) | 69 | ->andFilterWhere(['like', 'h1', $this->h1]) |
69 | ->andFilterWhere(['like', 'seo_text', $this->seo_text]); | 70 | ->andFilterWhere(['like', 'seo_text', $this->seo_text]); |
frontend/views/catalog/product.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | use yii\widgets\Breadcrumbs; | 2 | use yii\widgets\Breadcrumbs; |
3 | use yii\web\View; | 3 | use yii\web\View; |
4 | use yii\helpers\Url; | 4 | use yii\helpers\Url; |
5 | -$this->params['seo']['title'] = $product->fullname ; | 5 | +$this->params['seo']['title'] = $product->fullname; |
6 | $this->title = $product->fullname; | 6 | $this->title = $product->fullname; |
7 | //$this->title = (! empty($product->meta_title)) ? $product->meta_title : $product->fullname; | 7 | //$this->title = (! empty($product->meta_title)) ? $product->meta_title : $product->fullname; |
8 | //$this->registerMetaTag (['name' => 'description', 'content' => ((! empty($product->meta_description)) ? $product->meta_description : $product->fullname)]); | 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('send', 'pageview'); | @@ -85,6 +85,7 @@ ga('send', 'pageview'); | ||
85 | <?= Html::csrfMetaTags () ?> | 85 | <?= Html::csrfMetaTags () ?> |
86 | <title><?= Seo::widget([ 'row'=>'title'])?></title> | 86 | <title><?= Seo::widget([ 'row'=>'title'])?></title> |
87 | <?= Seo::widget([ 'row'=>'description'])?> | 87 | <?= Seo::widget([ 'row'=>'description'])?> |
88 | + <?= Seo::widget([ 'row'=>'meta'])?> | ||
88 | <link rel="shortcut icon" href="<?= Yii::$app->request->baseUrl ?>/img/favicon.ico" type="image/x-icon"/> | 89 | <link rel="shortcut icon" href="<?= Yii::$app->request->baseUrl ?>/img/favicon.ico" type="image/x-icon"/> |
89 | <?= HreflangWidget::widget ([]) ?> | 90 | <?= HreflangWidget::widget ([]) ?> |
90 | <?php $this->head () ?> | 91 | <?php $this->head () ?> |
frontend/widgets/Seo.php
@@ -12,6 +12,7 @@ class Seo extends Widget | @@ -12,6 +12,7 @@ class Seo extends Widget | ||
12 | public $fields; | 12 | public $fields; |
13 | public $description; | 13 | public $description; |
14 | public $title; | 14 | public $title; |
15 | + public $meta; | ||
15 | public $seo_text; | 16 | public $seo_text; |
16 | public $h1; | 17 | public $h1; |
17 | public $key; | 18 | public $key; |
@@ -22,6 +23,7 @@ class Seo extends Widget | @@ -22,6 +23,7 @@ class Seo extends Widget | ||
22 | 23 | ||
23 | const SEO_TEXT = 'seo_text'; | 24 | const SEO_TEXT = 'seo_text'; |
24 | const DESCRIPTION = 'description'; | 25 | const DESCRIPTION = 'description'; |
26 | + const META = 'meta'; | ||
25 | const H1 = 'h1'; | 27 | const H1 = 'h1'; |
26 | const TITLE = 'title'; | 28 | const TITLE = 'title'; |
27 | 29 | ||
@@ -52,27 +54,28 @@ class Seo extends Widget | @@ -52,27 +54,28 @@ class Seo extends Widget | ||
52 | break; | 54 | break; |
53 | case self::TITLE: | 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 | $title = $this->selectSeoData(self::TITLE); | 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 | return $title; | 79 | return $title; |
77 | } else { | 80 | } else { |
78 | return $this->project_name; | 81 | return $this->project_name; |
@@ -82,16 +85,54 @@ class Seo extends Widget | @@ -82,16 +85,54 @@ class Seo extends Widget | ||
82 | case self::DESCRIPTION: | 85 | case self::DESCRIPTION: |
83 | $description = $this->selectSeoData(self::DESCRIPTION); | 86 | $description = $this->selectSeoData(self::DESCRIPTION); |
84 | 87 | ||
85 | - if(!empty($description)){ | 88 | + if (!empty($description)) { |
86 | 89 | ||
87 | $this->getView()->registerMetaTag([ | 90 | $this->getView()->registerMetaTag([ |
88 | 'name' => 'description', | 91 | 'name' => 'description', |
89 | - 'content' => $description | 92 | + 'content' => $description |
90 | ]); | 93 | ]); |
91 | 94 | ||
92 | } | 95 | } |
93 | 96 | ||
94 | break; | 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,7 +186,6 @@ class Seo extends Widget | ||
145 | }else if(!empty($this->$param)){ | 186 | }else if(!empty($this->$param)){ |
146 | 187 | ||
147 | $result = $this->$param; | 188 | $result = $this->$param; |
148 | - | ||
149 | } else { | 189 | } else { |
150 | 190 | ||
151 | $widgetData = $this->findSeoByDynamic(); | 191 | $widgetData = $this->findSeoByDynamic(); |