3133 - Отключение sitemap.xml страниц на анг.

parent 55db82a8
......@@ -14,4 +14,5 @@ return [
'UrlCat' => 'Ссылка на страницу категории',
'Category ID' => 'Принадлежность страницы к категории',
'Active' => 'Активность',
'Hide page version' => 'Скрыть версию страницы'
];
\ No newline at end of file
......@@ -10,4 +10,5 @@ return [
'Url' => 'Ссылка',
'Category ID' => 'Категория',
'Active' => 'Активность',
'Hide page version' => 'Скрыть версию страницы'
];
\ No newline at end of file
......@@ -122,9 +122,12 @@ class Post extends \common\components\ActiveRecordModel
],
'sitemap' => [
'class' => SitemapBehavior::className(),
'langIds' => function ($model) {
return PostLang::find()->select(['lang_id'])->asArray()->andWhere(['hidden' => 0, 'post_id' => $model['id']])->column();
},
'scope' => function ($model) {
/** @var \yii\db\ActiveQuery $model */
$model->select(['url', 'updated_at']);
$model->select(['id', 'url', 'updated_at']);
$model->andWhere(['active' => 1]);
},
'dataClosure' => function ($model) {
......
......@@ -15,6 +15,7 @@ use common\modules\blog\models\Post;
* @property integer $lang_id
* @property string $title
* @property string $text
* @property integer $hidden
* @property integer $created_at
* @property integer $updated_at
*
......@@ -45,6 +46,7 @@ class PostLang extends \common\components\ActiveRecordModel
[['post_id', 'lang_id'], 'required'],
[['post_id', 'lang_id', 'created_at', 'updated_at'], 'integer'],
[['text'], 'string'],
[['hidden'], 'boolean'],
[['title'], 'string', 'max' => 255],
[['post_id'], 'exist', 'skipOnError' => true, 'targetClass' => Post::className(), 'targetAttribute' => ['post_id' => 'id']],
[['lang_id'], 'exist', 'skipOnError' => true, 'targetClass' => Languages::className(), 'targetAttribute' => ['lang_id' => 'id']],
......@@ -62,6 +64,7 @@ class PostLang extends \common\components\ActiveRecordModel
'lang_id' => 'Язык',
'title' => 'Заголовок',
'text' => 'Контент',
'hidden' => Yii::t('content', 'Hide page version'),
'created_at' => 'Дата добавления',
'updated_at' => 'Дата обновления',
];
......
......@@ -86,6 +86,10 @@ use common\modules\content\widgets\MetaTagsWidget;
<?= $form->field($content, '['.$lang_id.']text')->textArea()->hint('Для указания размера изображения нужно в редакторе в поле "Расширенные" указать "width: 176px; height: 260px;", где числа - необходимые размеры изображения.'); ?>
<?php if(!$content->lang->default) : ?>
<?= $form->field($content, '['.$lang_id.']hidden')->checkbox() ?>
<?php endif; ?>
<?= MetaTagsWidget::widget([
'model' => $model->meta[$lang_id],
'form' => $form,
......
......@@ -59,6 +59,9 @@ class CaseContent extends CoContent
],
'sitemap' => [
'class' => SitemapBehavior::className(),
'langIds' => function ($model) {
return CoContentLang::find()->select(['lang_id'])->asArray()->andWhere(['hidden' => 0, 'content_id' => $model['id']])->column();
},
'scope' => function ($model) {
/** @var \yii\db\ActiveQuery $model */
$model->select(['url', 'updated_at', 'priority']);
......
......@@ -4,6 +4,7 @@ namespace common\modules\content\controllers;
use common\modules\users\models\User;
use common\modules\content\models\CoContent;
use yii\web\NotFoundHttpException;
class PageController extends \common\components\BaseController
{
......@@ -43,7 +44,10 @@ class PageController extends \common\components\BaseController
}
}
$content = $model->lang->getFinishedContent();
if(!($lang = $model->lang) || $lang->hidden) {
throw new NotFoundHttpException('Page not found!');
}
$content = $lang->getFinishedContent();
$this->meta_title = $model->metaTag->title;
$this->meta_description = $model->metaTag->description;
$this->meta_keywords = $model->metaTag->keywords;
......
<?php
use yii\db\Migration;
/**
* Class m190408_145828_add_active_lang
*/
class m190408_145828_add_active_lang extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('co_content_lang', 'hidden', $this->smallInteger(1)->notNull()->defaultValue(0));
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('co_content_lang', 'hidden');
}
}
......@@ -91,9 +91,12 @@ class CoContent extends \common\components\ActiveRecordModel
],
'sitemap' => [
'class' => SitemapBehavior::className(),
'langIds' => function ($model) {
return CoContentLang::find()->select(['lang_id'])->asArray()->andWhere(['hidden' => 0, 'content_id' => $model['id']])->column();
},
'scope' => function ($model) {
/** @var \yii\db\ActiveQuery $model */
$model->select(['url', 'updated_at', 'priority']);
$model->select(['id', 'url', 'updated_at', 'priority']);
$model->andWhere(['active' => 1]);
$model->andWhere(['>', 'priority', 0]);
},
......
......@@ -18,6 +18,7 @@ use common\modules\content\models\CoBlocks;
* @property string $title
* @property string $text
* @property string $subtitle
* @property integer $hidden
*
* @property CoContent $content
* @property Languages $lang
......@@ -40,6 +41,7 @@ class CoContentLang extends \common\components\ActiveRecordModel
return [
[['content_id', 'lang_id', 'name', 'title'], 'required'],
[['content_id', 'lang_id'], 'integer'],
[['hidden'], 'boolean'],
[['text'], 'string'],
[['name', 'title', 'subtitle'], 'string', 'max' => 250],
[['content_id'], 'exist', 'skipOnError' => true, 'targetClass' => CoContent::className(), 'targetAttribute' => ['content_id' => 'id']],
......@@ -52,8 +54,7 @@ class CoContentLang extends \common\components\ActiveRecordModel
*/
public function behaviors()
{
return [
];
return [];
}
/**
......@@ -70,19 +71,13 @@ class CoContentLang extends \common\components\ActiveRecordModel
public function attributeLabels()
{
return [
'id' => 'id',
'name' => 'name',
'image' => 'image',
'title' => 'title',
'text' => 'text',
'id' => Yii::t('content', 'ID'),
'name' => Yii::t('content', 'Name'),
'image' => 'Превью',
'title' => Yii::t('content', 'Title'),
'text' => Yii::t('content', 'Content'),
'hidden' => Yii::t('content', 'Hide page version')
];
// return [
// 'id' => Yii::t('content', 'ID'),
// 'name' => Yii::t('content', 'Name'),
// 'image' => 'Превью',
// 'title' => Yii::t('content', 'Title'),
// 'text' => Yii::t('content', 'Content'),
// ];
}
public function beforeSave($insert)
......
......@@ -73,6 +73,10 @@ $blocks = \common\modules\content\models\CoBlocks::find()->all();
<?= $form->field($content, '['.$lang_id.']text')->textArea() ?>
<?php if(!$content->lang->default) : ?>
<?= $form->field($content, '['.$lang_id.']hidden')->checkbox() ?>
<?php endif; ?>
<?= MetaTagsWidget::widget([
'model' => $model->meta[$lang_id],
'form' => $form,
......
......@@ -51,9 +51,12 @@ class DocContent extends \yii\db\ActiveRecord
],
'sitemap' => [
'class' => SitemapBehavior::className(),
'langIds' => function ($model) {
return DocContentLang::find()->select(['lang_id'])->asArray()->andWhere(['hidden' => 0, 'content_id' => $model['id']])->column();
},
'scope' => function ($model) {
/** @var \yii\db\ActiveQuery $model */
$model->select(['url', 'updated_at', 'priority']);
$model->select(['id', 'url', 'updated_at', 'priority']);
},
'dataClosure' => function ($model) {
return [
......
......@@ -14,6 +14,7 @@ use common\modules\languages\models\Languages;
* @property string $name
* @property string $markdown
* @property string $html
* @property integer $hidden
*
* @property DocContent $content
* @property Languages $lang
......@@ -38,6 +39,7 @@ class DocContentLang extends \yii\db\ActiveRecord
[['content_id', 'lang_id'], 'required'],
[['content_id', 'lang_id'], 'integer'],
[['markdown', 'html'], 'string'],
[['hidden'], 'boolean'],
[['name'], 'string', 'max' => 255],
[['content_id'], 'exist', 'skipOnError' => true, 'targetClass' => DocContent::className(), 'targetAttribute' => ['content_id' => 'id']],
[['lang_id'], 'exist', 'skipOnError' => true, 'targetClass' => Languages::className(), 'targetAttribute' => ['lang_id' => 'id']],
......@@ -56,6 +58,7 @@ class DocContentLang extends \yii\db\ActiveRecord
'name' => 'Заголовок',
'markdown' => 'Markdown',
'html' => 'Html',
'hidden' => Yii::t('content', 'Hide page version')
];
}
......
......@@ -66,6 +66,11 @@ $defaultUrl = (
<?php echo $form->field($documentation, '[' . $lang_id . ']markdown')->textArea(['class' => 'no_editor']) ?>
<?php echo $form->field($documentation, '[' . $lang_id . ']html')->textArea(['class' => 'no_editor']) ?>
</div>
<?php if(!$documentation->lang->default) : ?>
<?= $form->field($documentation, '['.$lang_id.']hidden')->checkbox() ?>
<?php endif; ?>
<?=
MetaTagsWidget::widget([
'model' => $model->meta[$lang_id],
......
......@@ -19,6 +19,7 @@ use common\modules\sessions\models\SessionUrl;
* @property integer $id
* @property string $url
* @property integer $active
*
* @property integer $created_at
* @property integer $updated_at
*
......@@ -97,9 +98,12 @@ class Faq extends \common\components\ActiveRecordModel
],
'sitemap' => [
'class' => SitemapBehavior::className(),
'langIds' => function ($model) {
return FaqContentLang::find()->select(['lang_id'])->asArray()->andWhere(['hidden' => 0, 'faq_id' => $model['id']])->column();
},
'scope' => function ($model) {
/** @var \yii\db\ActiveQuery $model */
$model->select(['url', 'updated_at']);
$model->select(['id', 'url', 'updated_at']);
$model->andWhere(['active' => 1]);
},
'dataClosure' => function ($model) {
......
......@@ -15,6 +15,7 @@ use common\modules\blog\models\Post;
* @property integer $lang_id
* @property string $title
* @property string $text
* @property integer $hidden
* @property integer $created_at
* @property integer $updated_at
*
......@@ -45,6 +46,7 @@ class FaqContentLang extends \common\components\ActiveRecordModel
[['faq_id', 'lang_id'], 'required'],
[['faq_id', 'lang_id', 'created_at', 'updated_at'], 'integer'],
[['text'], 'string'],
[['hidden'], 'boolean'],
[['title'], 'string', 'max' => 255],
[['faq_id'], 'exist', 'skipOnError' => true, 'targetClass' => Faq::className(), 'targetAttribute' => ['faq_id' => 'id']],
[['lang_id'], 'exist', 'skipOnError' => true, 'targetClass' => Languages::className(), 'targetAttribute' => ['lang_id' => 'id']],
......@@ -62,6 +64,7 @@ class FaqContentLang extends \common\components\ActiveRecordModel
'lang_id' => 'Язык',
'title' => 'Заголовок',
'text' => 'Контент',
'hidden' => Yii::t('content', 'Hide page version'),
'created_at' => 'Дата добавления',
'updated_at' => 'Дата обновления',
];
......
......@@ -61,6 +61,10 @@ AdminGeneratorAsset::register($this);
<?= $form->field($content, '['.$lang_id.']text')->textArea() ?>
<?php if(!$content->lang->default) : ?>
<?= $form->field($content, '['.$lang_id.']hidden')->checkbox() ?>
<?php endif; ?>
<?= MetaTagsWidget::widget([
'model' => $model->meta[$lang_id],
'form' => $form,
......
<?php
use yii\db\Migration;
/**
* Class m190408_160855_add_active_lang
*/
class m190408_160855_add_active_lang extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('posts_lang', 'hidden', $this->smallInteger(1)->notNull()->defaultValue(0)->after('text'));
$this->addColumn('faq_content_lang', 'hidden', $this->smallInteger(1)->notNull()->defaultValue(0)->after('text'));
$this->addColumn('doc_content_lang', 'hidden', $this->smallInteger(1)->notNull()->defaultValue(0));
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('posts_lang', 'hidden');
$this->dropColumn('faq_content_lang', 'hidden');
$this->dropColumn('doc_content_lang', 'hidden');
}
}
......@@ -12,6 +12,7 @@ use common\models\LoginForm;
use common\modules\users\models\User;
use common\modules\eauth\components\GoogleOAuth2Service;
use common\modules\eauth\models\UserEAuth;
use yii\web\NotFoundHttpException;
/**
* Site controller
......@@ -88,7 +89,10 @@ class SiteController extends FrontendController
{
$model = \common\modules\content\models\CoContent::findOne(['url' => 'site/error']);
$content = $model->lang->getFinishedContent();
if(!($lang = $model->lang) || $lang->hidden) {
throw new NotFoundHttpException('Page not found!');
}
$content = $lang->getFinishedContent();
$this->meta_title = $model->metaTag->title;
$this->meta_description = $model->metaTag->description;
$this->meta_keywords = $model->metaTag->keywords;
......
......@@ -65,6 +65,8 @@ class SitemapBehavior extends Behavior
/** @var callable */
public $scope;
/** @var callable|array */
public $langIds;
public function init()
{
......@@ -114,6 +116,12 @@ class SitemapBehavior extends Behavior
$result[$n]['images'] = $urlData['images'];
}
if (is_callable($this->langIds)) {
$result[$n]['langIds'] = call_user_func($this->langIds, $model);
} elseif(is_array($this->langIds)) {
$result[$n]['langIds'] = $this->langIds;
}
++$n;
}
return $result;
......
......@@ -18,7 +18,8 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
<loc><?= yii\helpers\Url::to($url['loc'], true) ?></loc>
<?php if($google && $langs) :
foreach ($langs as $lang) : ?>
foreach ($langs as $lang) :
if(isset($url['langIds']) && !in_array($lang->id, $url['langIds'])) continue; ?>
<xhtml:link rel="alternate" hreflang="<?=$lang->url?>" href="<?= yii\helpers\Url::to((!$lang->default?'/'.$lang->url:'').($url['loc']=='/'?'':'/'.$url['loc']), true) ?>"/>
<?php endforeach;
endif; ?>
......@@ -77,6 +78,7 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
<?php if(!$google && $langs) :
foreach ($langs as $lang) :
if(isset($url['langIds']) && !in_array($lang->id, $url['langIds'])) continue;
if(!$lang->default) : ?>
<url>
<loc><?= yii\helpers\Url::to('/'.$lang->url.($url['loc']=='/'?'':'/'.$url['loc']), true) ?></loc>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment