Skip to content

Commit ead3470

Browse files
Доработка
1 parent 421b879 commit ead3470

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/CmsSeoComponent.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ class CmsSeoComponent extends Component implements BootstrapInterface
107107
*/
108108
public $is_sitemap_priority = false;
109109

110+
/**
111+
* @var bool Разрешить индексацию контента для взрослых? По умолчанию не индексируется.
112+
*/
113+
public $is_allow_index_adult_content = false;
114+
110115
/**
111116
* @var bool Делать картинки webp при ресайзе?
112117
*/
@@ -254,6 +259,7 @@ public function rules()
254259
[
255260
'enableKeywordsGenerator',
256261
'is_sitemap_priority',
262+
'is_allow_index_adult_content',
257263
'minKeywordLenth',
258264
'maxKeywordsLength',
259265
//'activeContentElem', 'activeTree'
@@ -292,6 +298,7 @@ public function attributeLabels()
292298
{
293299
return ArrayHelper::merge(parent::attributeLabels(), [
294300
'is_sitemap_priority' => \Yii::t('skeeks/seo', 'Добавлять priority в sitemap?'),
301+
'is_allow_index_adult_content' => \Yii::t('skeeks/seo', 'Разрешить индексацию контента для взрослых?'),
295302
'enableKeywordsGenerator' => \Yii::t('skeeks/seo', 'Automatic generation of keywords'),
296303
'minKeywordLenth' => \Yii::t('skeeks/seo', 'The minimum length of the keyword'),
297304
'maxKeywordsLength' => \Yii::t('skeeks/seo', 'Length keywords'),
@@ -332,6 +339,7 @@ public function attributeLabels()
332339
public function attributeHints()
333340
{
334341
return ArrayHelper::merge(parent::attributeHints(), [
342+
'is_allow_index_adult_content' => "Если эта опция не выбрана то контента отмеченный как для взрослых, не попадет в карту сайта и будет запрещен к индексации!",
335343
'header_content' => "Вставьте подвреждающие коды yandex webmaster и подобных систем. Этот код попадет между тегов head на странице.",
336344
'countersContent' => \Yii::t('skeeks/seo',
337345
'В это поле вы можете поставить любые коды счетчиков и сторонних систем (yandex.metrics jivosite google.metrics и прочие). Они будут выведены внизу страницы, перед закрывающим тегом body'),
@@ -394,9 +402,16 @@ public function getConfigFormFields()
394402
HTML
395403
,
396404
],
405+
406+
'is_allow_index_adult_content' => [
407+
'class' => BoolField::class,
408+
'allowNull' => false
409+
],
410+
397411
];
398412
} else {
399413
$indexing = [
414+
400415
'robotsContent' => [
401416
'class' => TextareaField::class,
402417
/*'on afterRender' => function(ViewRenderEvent $e) {
@@ -411,6 +426,12 @@ public function getConfigFormFields()
411426
'rows' => 15,
412427
],
413428
],
429+
430+
'is_allow_index_adult_content' => [
431+
'class' => BoolField::class,
432+
'allowNull' => false
433+
],
434+
414435
];
415436
}
416437

src/controllers/SitemapController.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ protected function _addTrees(&$data = [])
9494
'is_index' => 1,
9595
]);
9696

97+
//Разделы 18 + не добавлять!
98+
if (!\Yii::$app->seo->is_allow_index_adult_content) {
99+
$query->andWhere([
100+
'is_adult' => 0,
101+
]);
102+
}
103+
97104
if (\Yii::$app->seo->treeTypeIds) {
98105
$query->andWhere(['tree_type_id' => \Yii::$app->seo->treeTypeIds]);
99106
}
@@ -131,6 +138,14 @@ protected function _addTrees(&$data = [])
131138
protected function _addSavedFilters(&$data = [])
132139
{
133140
$query = CmsSavedFilter::find()->cmsSite();
141+
142+
//Разделы 18 + не добавлять!
143+
if (!\Yii::$app->seo->is_allow_index_adult_content) {
144+
$query->joinWith("cmsTree as cmsTree")->andWhere([
145+
'cmsTree.is_adult' => 0,
146+
]);
147+
}
148+
134149
$savedFilters = $query->all();
135150

136151
if ($savedFilters) {
@@ -253,6 +268,13 @@ protected function _addElements(&$data = [])
253268
$query->andWhere(['content_id' => \Yii::$app->seo->contentIds]);
254269
}
255270

271+
//Разделы 18 + не добавлять!
272+
if (!\Yii::$app->seo->is_allow_index_adult_content) {
273+
$query->andWhere([
274+
'is_adult' => 0,
275+
]);
276+
}
277+
256278
$elements = $query->orderBy(['updated_at' => SORT_DESC, 'priority' => SORT_ASC])->all();
257279

258280
//Добавление элементов в карту

0 commit comments

Comments
 (0)