Commit 14c89ea2d0a881a279adcb32648bd4c0519c277f

Authored by Anastasia
1 parent a90233d1

seo

common/config/main.php
1 <?php 1 <?php
2 use artbox\core\components\AliasCache; 2 use artbox\core\components\AliasCache;
3 - use artbox\core\components\SeoComponent; 3 + use frontend\components\SeoComponent;
4 use artbox\core\rating\Module; 4 use artbox\core\rating\Module;
5 5
6 return [ 6 return [
frontend/components/SeoComponent.php 0 → 100644
  1 +<?php
  2 + /**
  3 + * Created by PhpStorm.
  4 + * User: stes
  5 + * Date: 02.08.18
  6 + * Time: 12:41
  7 + */
  8 +
  9 + namespace frontend\components;
  10 +
  11 + class SeoComponent extends \artbox\core\components\SeoComponent
  12 + {
  13 + /**
  14 + * @todo Refactor later for sorting and pagination
  15 + * @return string
  16 + */
  17 + public $close = [
  18 + 'support',
  19 + 'author',
  20 + 'book/add',
  21 + 'book/success',
  22 + 'site/login',
  23 + 'site/register'
  24 + ];
  25 +
  26 + public function getRobots()
  27 + {
  28 + if (array_search(\Yii::$app->controller->id, $this->close)){
  29 + return 'noindex, nofollow';
  30 + }
  31 + if (array_search(\Yii::$app->request->pathInfo, $this->close)){
  32 + return 'noindex, nofollow';
  33 + }
  34 +
  35 + if (!empty($this->robots)) {
  36 + return $this->robots;
  37 + }
  38 +
  39 + if (!empty($this->alias) && !empty($this->alias->getRobots())) {
  40 + return $this->alias->getRobots();
  41 + }
  42 +
  43 + return 'index,follow';
  44 + }
  45 +
  46 + }
0 \ No newline at end of file 47 \ No newline at end of file
frontend/config/main.php
1 <?php 1 <?php
2 - use artbox\core\components\SeoComponent; 2 + use frontend\components\SeoComponent;
3 use frontend\components\UrlManager; 3 use frontend\components\UrlManager;
4 4
5 $params = array_merge( 5 $params = array_merge(
frontend/views/layouts/main.php
@@ -49,6 +49,13 @@ @@ -49,6 +49,13 @@
49 JS; 49 JS;
50 $this->registerJs($js, View::POS_READY); 50 $this->registerJs($js, View::POS_READY);
51 } 51 }
  52 +
  53 + $this->registerMetaTag(
  54 + [
  55 + 'name' => 'robots',
  56 + 'content' => $seo->robots,
  57 + ]
  58 + );
52 ?> 59 ?>
53 60
54 <?php $this->beginPage() ?> 61 <?php $this->beginPage() ?>
frontend/views/support/index.php
@@ -2,10 +2,15 @@ @@ -2,10 +2,15 @@
2 /** 2 /**
3 * @var \common\models\Book $book 3 * @var \common\models\Book $book
4 * @var \common\models\Support $model 4 * @var \common\models\Support $model
  5 + * @var \artbox\core\components\SeoComponent $seo
5 */ 6 */
6 - use yii\helpers\Html; 7 + use artbox\core\models\Alias;use yii\helpers\Html;
7 use yii\widgets\ActiveForm; 8 use yii\widgets\ActiveForm;
8 - 9 + $seo = \Yii::$app->get('seo');
  10 +
  11 + $seo->setAlias(new Alias([
  12 + 'title' => 'Підтримати книгу "'.$book->title.'"'
  13 + ]));
9 ?> 14 ?>
10 <section class="section-books-support"> 15 <section class="section-books-support">
11 <div class="container"> 16 <div class="container">