seo.php 1.74 KB
<?php
use yii\helpers\Html;
use frontend\themes\defaults\assets\AppAsset;

/**
 * @var $model \frontend\modules\news\models\Article
 * @var $params \thread\modules\sys\modules\configs\components\ConfigsParams
 * @var $meta \thread\modules\seo\components\MetaTag
 * @var $metaBaseInfo \thread\modules\seo\modules\info\components\MetaBaseInfo
 */
$bundle = AppAsset::register($this);
$meta = Yii::$app->metatag;
$metaBaseInfo = Yii::$app->metabaseinfo;
//
$image = $metaBaseInfo->getBaseUrl() . '/' . $model->getImageLink();
$imagePath = $model->getImagePath();
$link = $model->getUrl();
if ($image === null) {
    $image = $metaBaseInfo->getBaseUrl() . '/images/blog-1.jpg';
    $image = $imagePath;
}

list($width, $height, $type, $attr) = getimagesize($image);
//
$meta->set_image_url($image);
$metaBaseInfoLogo = $metaBaseInfo->getSiteLogo();
try {
    list($widthl, $heightl, $typel, $attrl) = getimagesize($metaBaseInfoLogo);
} catch (Exception $exception) {
    
}
?>
{
"@context": "http://schema.org",
"@type": "NewsArticle",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://google.com/article"
},
"headline": "<?= Html::encode($model['lang']['title']) ?>",
"image": {
"@type": "ImageObject",
"url": "<?= $image ?>",
"height": "<?= $height??0 ?>",
"width": "<?= $width??0 ?>"
},
"datePublished": "<?= $model->getPublishedTimeISO() ?>",
"dateModified": "<?= $model->getModifiedTimeISO() ?>",
"author": {
"@type": "Person",
"name": "<?= $params->getByName('shop_name') ?>"
},
"publisher": {
"@type": "Organization",
"name": "<?= $params->getByName('shop_name') ?>",
"logo": {
"@type": "ImageObject",
"width": "<?= $widthl??0 ?>",
"height": "<?= $heightl??0 ?>",
"url": "<?= $metaBaseInfoLogo ?>"
}
},
"description": "<?= Html::encode($model['lang']['description']) ?>"
}