Blame view

frontend/widgets/MicroDataWidget.php 2.97 KB
1e22f07d   Anastasia   - microdata
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  <?php
      /**
       * Created by PhpStorm.
       * User: stes
       * Date: 04.07.18
       * Time: 15:33
       */
      
      namespace frontend\widgets;
      
      use artbox\core\helpers\ImageHelper;
      use frontend\helpers\Url;
      use yii\base\Widget;
      use yii\helpers\Json;
      
      class MicroDataWidget extends Widget
      {
          public $model = null;
          
          public $seo;
          
          public $logoUrl;
          
          public $type = 'Organization';
          
          public $width;
          
          public $height;
          
          public function run()
          {
              $this->seo = \Yii::$app->get('seo');
              $data = [];
              $this->logoUrl = \Yii::$app->request->hostInfo . '/storage/logo/logo.png';
              if ($this->type == 'NewsArticle'){
                  $data = [
                      '@context'         => "http://schema.org",
                      '@type'            => $this->type,
                      "mainEntityOfPage" => [
                          "@type" => "WebPage",
                          "@id"   => \Yii::$app->request->absoluteUrl,
                      ],
                      'headline'         => ( !empty($this->seo->h1) ) ? $this->seo->h1 : $this->model->language->title,
                      'image'            => [
                          \Yii::$app->request->hostInfo . ImageHelper::set((!empty($this->model->image)) ? $this->model->image->getUrl() : null)
                                                                                 ->render(),
                      ],
                      'datePublished'    => date('c', $this->model->created_at),
                      'dateModified'     => date('c', $this->model->updated_at),
                      'author'           => [
                          '@type' => 'Person',
69077fa9   Anastasia   - bug fix
52
                          'name'  => 'admin',
1e22f07d   Anastasia   - microdata
53
54
55
                      ],
                      'publisher'        => [
                          '@type' => 'Organization',
69077fa9   Anastasia   - bug fix
56
                          'name'  => 'admin',
1e22f07d   Anastasia   - microdata
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
                          'logo'  => [
                              '@type'  => "ImageObject",
                              'url'    => $this->logoUrl,
                          ],
                      ],
                      'description'      => $this->seo->desc,
                  ];
              }elseif ($this->type == 'Organization'){
                    $data = [
                         '@context' => 'http://schema.org',
                         "@type"=> $this->type,
                         'url' => \Yii::$app->request->absoluteUrl,
                         'logo' => $this->logoUrl,
                         'contactPoint' => [
                             "@type" => "ContactPoint",
                              "url" => Url::home(true),
                              "contactType" => "customer service",
                         ]
                    ];
              }
             
              
              return $this->render(
                  'microdata',
                  [
                      'data' => Json::encode($data),
                  ]
              );
          }
      }