Commit 1e22f07d6f50626dcb8cb1b76a28476c7b235a8e
1 parent
32162c17
- microdata
Showing
4 changed files
with
106 additions
and
3 deletions
Show diff stats
frontend/views/blog/view.php
| ... | ... | @@ -3,8 +3,8 @@ |
| 3 | 3 | use artbox\core\helpers\ImageHelper; |
| 4 | 4 | use common\models\blog\Article; |
| 5 | 5 | use common\models\blog\Tag; |
| 6 | - use frontend\widgets\BlogSearch; | |
| 7 | 6 | use artbox\core\helpers\Url; |
| 7 | + use frontend\widgets\MicroDataWidget; | |
| 8 | 8 | use yii\web\View; |
| 9 | 9 | |
| 10 | 10 | /** |
| ... | ... | @@ -45,9 +45,11 @@ |
| 45 | 45 | 'type' => 'hiddenInput', |
| 46 | 46 | 'options' => ['value' => ''], |
| 47 | 47 | ]]; |
| 48 | + | |
| 49 | + $this->params['blog'] = true; | |
| 48 | 50 | ?> |
| 49 | 51 | |
| 50 | -?> | |
| 52 | + | |
| 51 | 53 | |
| 52 | 54 | <section class="blog-view-section"> |
| 53 | 55 | <div class="container"> |
| ... | ... | @@ -156,4 +158,5 @@ |
| 156 | 158 | </div> |
| 157 | 159 | </section> |
| 158 | 160 | <!-- /#content --> |
| 161 | +<?=MicroDataWidget::widget(['model' => $model, 'type' => 'NewsArticle'])?> | |
| 159 | 162 | |
| 160 | 163 | \ No newline at end of file | ... | ... |
frontend/views/layouts/main.php
| ... | ... | @@ -17,6 +17,7 @@ |
| 17 | 17 | use artbox\core\seo\widgets\SeoBreadcrumbs; |
| 18 | 18 | use common\models\Settings; |
| 19 | 19 | use frontend\assets\AppAsset; |
| 20 | + use frontend\widgets\MicroDataWidget; | |
| 20 | 21 | use yii\bootstrap\Html; |
| 21 | 22 | use artbox\core\helpers\Url; |
| 22 | 23 | use yii\web\View; |
| ... | ... | @@ -141,7 +142,11 @@ JS; |
| 141 | 142 | <!-- end content --> |
| 142 | 143 | |
| 143 | 144 | </div> |
| 144 | - | |
| 145 | + <?php | |
| 146 | + if (!isset($this->params['blog'])){ | |
| 147 | + echo MicroDataWidget::widget(['type' => 'Organization']); | |
| 148 | + } | |
| 149 | + ?> | |
| 145 | 150 | <footer id="footer_" class="section-box-footer" > |
| 146 | 151 | <div class="container"> |
| 147 | 152 | <div class="row" style="position: relative"> | ... | ... |
| 1 | +<?php | |
| 2 | + /** | |
| 3 | + * Created by PhpStorm. | |
| 4 | + * User: stes | |
| 5 | + * Date: 04.07.18 | |
| 6 | + * Time: 15:33 | |
| 7 | + */ | |
| 8 | + | |
| 9 | + namespace frontend\widgets; | |
| 10 | + | |
| 11 | + use artbox\core\helpers\ImageHelper; | |
| 12 | + use frontend\helpers\Url; | |
| 13 | + use yii\base\Widget; | |
| 14 | + use yii\helpers\Json; | |
| 15 | + | |
| 16 | + class MicroDataWidget extends Widget | |
| 17 | + { | |
| 18 | + public $model = null; | |
| 19 | + | |
| 20 | + public $seo; | |
| 21 | + | |
| 22 | + public $logoUrl; | |
| 23 | + | |
| 24 | + public $type = 'Organization'; | |
| 25 | + | |
| 26 | + public $width; | |
| 27 | + | |
| 28 | + public $height; | |
| 29 | + | |
| 30 | + public function run() | |
| 31 | + { | |
| 32 | + $this->seo = \Yii::$app->get('seo'); | |
| 33 | + $data = []; | |
| 34 | + $this->logoUrl = \Yii::$app->request->hostInfo . '/storage/logo/logo.png'; | |
| 35 | + if ($this->type == 'NewsArticle'){ | |
| 36 | + $data = [ | |
| 37 | + '@context' => "http://schema.org", | |
| 38 | + '@type' => $this->type, | |
| 39 | + "mainEntityOfPage" => [ | |
| 40 | + "@type" => "WebPage", | |
| 41 | + "@id" => \Yii::$app->request->absoluteUrl, | |
| 42 | + ], | |
| 43 | + 'headline' => ( !empty($this->seo->h1) ) ? $this->seo->h1 : $this->model->language->title, | |
| 44 | + 'image' => [ | |
| 45 | + \Yii::$app->request->hostInfo . ImageHelper::set((!empty($this->model->image)) ? $this->model->image->getUrl() : null) | |
| 46 | + ->render(), | |
| 47 | + ], | |
| 48 | + 'datePublished' => date('c', $this->model->created_at), | |
| 49 | + 'dateModified' => date('c', $this->model->updated_at), | |
| 50 | + 'author' => [ | |
| 51 | + '@type' => 'Person', | |
| 52 | + 'name' => '', | |
| 53 | + ], | |
| 54 | + 'publisher' => [ | |
| 55 | + '@type' => 'Organization', | |
| 56 | + 'name' => '', | |
| 57 | + 'logo' => [ | |
| 58 | + '@type' => "ImageObject", | |
| 59 | + 'url' => $this->logoUrl, | |
| 60 | + ], | |
| 61 | + ], | |
| 62 | + 'description' => $this->seo->desc, | |
| 63 | + ]; | |
| 64 | + }elseif ($this->type == 'Organization'){ | |
| 65 | + $data = [ | |
| 66 | + '@context' => 'http://schema.org', | |
| 67 | + "@type"=> $this->type, | |
| 68 | + 'url' => \Yii::$app->request->absoluteUrl, | |
| 69 | + 'logo' => $this->logoUrl, | |
| 70 | + 'contactPoint' => [ | |
| 71 | + "@type" => "ContactPoint", | |
| 72 | + "url" => Url::home(true), | |
| 73 | + "contactType" => "customer service", | |
| 74 | + ] | |
| 75 | + ]; | |
| 76 | + } | |
| 77 | + | |
| 78 | + | |
| 79 | + return $this->render( | |
| 80 | + 'microdata', | |
| 81 | + [ | |
| 82 | + 'data' => Json::encode($data), | |
| 83 | + ] | |
| 84 | + ); | |
| 85 | + } | |
| 86 | + } | |
| 0 | 87 | \ No newline at end of file | ... | ... |