Skip to content

Commit aba9ae3

Browse files
countersContent выводится автоматически в шаблон, перед закрывающим тегом body
1 parent ef82092 commit aba9ae3

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
CHANGELOG
22
==============
33

4+
2.1.8
5+
-----------------
6+
* countersContent выводится автоматически в шаблон, перед закрывающим тегом body
7+
48
2.1.7
59
-----------------
610
* Canurl only for urlManager->enablePrettyUrl

src/CmsSeoComponent.php

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use yii\base\WidgetEvent;
2020
use yii\grid\GridView;
2121
use yii\helpers\ArrayHelper;
22+
use yii\helpers\Html;
2223
use yii\helpers\Url;
2324
use yii\web\Application;
2425
use yii\web\Controller;
@@ -35,26 +36,29 @@
3536
class CmsSeoComponent extends Component implements BootstrapInterface
3637
{
3738
/**
38-
* длина ключевых слов
39+
* Максимадбгая длина ключевых слов
3940
* @var int
4041
*/
4142
public $maxKeywordsLength = 1000;
43+
4244
/**
4345
* @var int минимальная длина слова которая попадет в списко ключевых слов
4446
*/
4547
public $minKeywordLenth = 8;
48+
4649
/**
47-
* @var array
50+
* @var array ключевые слова которые не должны попадать в ключевые
4851
*/
4952
public $keywordsStopWords = [];
53+
5054
/**
51-
* @var bool
55+
* @var bool включить автогенерацию ключевых слов
5256
*/
5357
public $enableKeywordsGenerator = true;
5458

5559

5660
/**
57-
* @var string
61+
* @var string если файла robots.txt нет физически, то он формируется динамически с этим содержимым
5862
*/
5963
public $robotsContent = "User-agent: *";
6064

@@ -84,6 +88,7 @@ class CmsSeoComponent extends Component implements BootstrapInterface
8488
* @var string
8589
*/
8690
public $contentIds = [];
91+
8792
/**
8893
* @var string
8994
*/
@@ -171,6 +176,7 @@ public function attributeLabels()
171176
public function attributeHints()
172177
{
173178
return ArrayHelper::merge(parent::attributeHints(), [
179+
'countersContent' => \Yii::t('skeeks/seo', 'В это поле вы можете поставить любые коды счетчиков и сторонних систем (yandex.metrics jivosite google.metrics и прочие). Они будут выведены внизу страницы, перед закрывающим тегом body'),
174180
'enableKeywordsGenerator' => \Yii::t('skeeks/seo', 'If the page is not specified keywords, they will generate is for her, according to certain rules automatically'),
175181
'minKeywordLenth' => \Yii::t('skeeks/seo', 'The minimum length of the keyword, which is listed by the key (automatic generation)'),
176182
'maxKeywordsLength' => \Yii::t('skeeks/seo', 'The maximum length of the string of keywords (automatic generation)'),
@@ -243,12 +249,26 @@ public function bootstrap($application)
243249
* Генерация SEO метатегов по контенту страницы
244250
*/
245251
$application->view->on(View::EVENT_END_BODY, function (Event $e) {
252+
253+
/**
254+
* @var $view View
255+
*/
256+
$view = $e->sender;
257+
246258
if ($this->enableKeywordsGenerator && !BackendComponent::getCurrent()) {
247259
if (!\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
248-
$this->_generateBeforeOutputPage($e->sender);
260+
$this->_autoGenerateKeywords($view);
249261
}
250262
}
251263

264+
if (!BackendComponent::getCurrent()) {
265+
if ($this->countersContent) {
266+
$content = ob_get_contents();
267+
if (strpos($content, $this->countersContent) === false) {
268+
echo Html::tag('div', $this->countersContent, ['style' => 'display: none;']);
269+
}
270+
}
271+
}
252272
});
253273

254274

@@ -294,7 +314,6 @@ public function bootstrap($application)
294314
}
295315
});
296316

297-
298317
$application->on(Application::EVENT_AFTER_REQUEST, function ($e) {
299318
if ($this->_isTrigerEventCanUrl()) {
300319
if ($this->canUrl) {
@@ -425,7 +444,10 @@ public function _isTrigerEventCanUrl()
425444
return false;
426445
}
427446

428-
protected function _generateBeforeOutputPage(\yii\web\View $view)
447+
/**
448+
* @param View $view
449+
*/
450+
protected function _autoGenerateKeywords(\yii\web\View $view)
429451
{
430452
$content = ob_get_contents();
431453

@@ -436,7 +458,7 @@ protected function _generateBeforeOutputPage(\yii\web\View $view)
436458
], 'keywords');
437459
}
438460

439-
\Yii::$app->response->content = $content;
461+
//\Yii::$app->response->content = $content;
440462
}
441463

442464
/**

0 commit comments

Comments
 (0)