Commit 6179ff51d919310efa30a14582e01974dc35feca
1 parent
cd3a2f7d
language markup for seo
Showing
8 changed files
with
176 additions
and
3 deletions
Show diff stats
frontend/controllers/BlogController.php
| @@ -33,6 +33,15 @@ | @@ -33,6 +33,15 @@ | ||
| 33 | ], | 33 | ], |
| 34 | ] | 34 | ] |
| 35 | ); | 35 | ); |
| 36 | + | ||
| 37 | + $aliasIdsForBlog = [89, 90, 91]; | ||
| 38 | + $this->view->params['aliases'] = \artbox\core\models\Alias::find() | ||
| 39 | + ->where( | ||
| 40 | + [ | ||
| 41 | + 'id' => $aliasIdsForBlog | ||
| 42 | + ] | ||
| 43 | + ) | ||
| 44 | + ->all(); | ||
| 36 | 45 | ||
| 37 | $this->view->params[ 'breadcrumbs' ][] = \Yii::t('app', 'Блог'); | 46 | $this->view->params[ 'breadcrumbs' ][] = \Yii::t('app', 'Блог'); |
| 38 | 47 | ||
| @@ -151,6 +160,8 @@ | @@ -151,6 +160,8 @@ | ||
| 151 | throw new NotFoundHttpException(); | 160 | throw new NotFoundHttpException(); |
| 152 | } | 161 | } |
| 153 | 162 | ||
| 163 | + $this->view->params['model'] = $article; | ||
| 164 | + | ||
| 154 | return $this->render( | 165 | return $this->render( |
| 155 | 'article', | 166 | 'article', |
| 156 | [ | 167 | [ |
frontend/controllers/PageController.php
frontend/controllers/PersoneController.php
| @@ -22,6 +22,15 @@ | @@ -22,6 +22,15 @@ | ||
| 22 | ->with('lang.alias') | 22 | ->with('lang.alias') |
| 23 | ->all(); | 23 | ->all(); |
| 24 | 24 | ||
| 25 | + $aliasIdsForBlog = [98, 99, 100]; | ||
| 26 | + $this->view->params['aliases'] = \artbox\core\models\Alias::find() | ||
| 27 | + ->where( | ||
| 28 | + [ | ||
| 29 | + 'id' => $aliasIdsForBlog | ||
| 30 | + ] | ||
| 31 | + ) | ||
| 32 | + ->all(); | ||
| 33 | + | ||
| 25 | return $this->render( | 34 | return $this->render( |
| 26 | 'index', | 35 | 'index', |
| 27 | [ | 36 | [ |
| @@ -39,6 +48,8 @@ | @@ -39,6 +48,8 @@ | ||
| 39 | { | 48 | { |
| 40 | $model = $this->findModel($id); | 49 | $model = $this->findModel($id); |
| 41 | 50 | ||
| 51 | + $this->view->params['model'] = $model; | ||
| 52 | + | ||
| 42 | return $this->render( | 53 | return $this->render( |
| 43 | 'view', | 54 | 'view', |
| 44 | [ | 55 | [ |
frontend/controllers/SiteController.php
| @@ -63,6 +63,16 @@ | @@ -63,6 +63,16 @@ | ||
| 63 | public function actionContact() | 63 | public function actionContact() |
| 64 | { | 64 | { |
| 65 | $contact = new Feedback(['scenario'=>Feedback::SCENARIO_WRITE_US]); | 65 | $contact = new Feedback(['scenario'=>Feedback::SCENARIO_WRITE_US]); |
| 66 | + | ||
| 67 | + $aliasIdsForBlog = [95, 96, 97]; | ||
| 68 | + $this->view->params['aliases'] = \artbox\core\models\Alias::find() | ||
| 69 | + ->where( | ||
| 70 | + [ | ||
| 71 | + 'id' => $aliasIdsForBlog | ||
| 72 | + ] | ||
| 73 | + ) | ||
| 74 | + ->all(); | ||
| 75 | + | ||
| 66 | return $this->render( | 76 | return $this->render( |
| 67 | 'contact', | 77 | 'contact', |
| 68 | [ | 78 | [ |
| @@ -199,6 +209,15 @@ | @@ -199,6 +209,15 @@ | ||
| 199 | ->with('lang') | 209 | ->with('lang') |
| 200 | ->where([ 'id' => 4 ]) | 210 | ->where([ 'id' => 4 ]) |
| 201 | ->one(); | 211 | ->one(); |
| 212 | + | ||
| 213 | + $aliasIdsForBlog = [92, 93, 94]; | ||
| 214 | + $this->view->params['aliases'] = \artbox\core\models\Alias::find() | ||
| 215 | + ->where( | ||
| 216 | + [ | ||
| 217 | + 'id' => $aliasIdsForBlog | ||
| 218 | + ] | ||
| 219 | + ) | ||
| 220 | + ->all(); | ||
| 202 | 221 | ||
| 203 | return $this->render( | 222 | return $this->render( |
| 204 | 'price', | 223 | 'price', |
| @@ -216,6 +235,15 @@ | @@ -216,6 +235,15 @@ | ||
| 216 | 'id' => 1, | 235 | 'id' => 1, |
| 217 | ] | 236 | ] |
| 218 | ); | 237 | ); |
| 238 | + | ||
| 239 | + $aliasIdsForBlog = [101, 102, 103]; | ||
| 240 | + $this->view->params['aliases'] = \artbox\core\models\Alias::find() | ||
| 241 | + ->where( | ||
| 242 | + [ | ||
| 243 | + 'id' => $aliasIdsForBlog | ||
| 244 | + ] | ||
| 245 | + ) | ||
| 246 | + ->all(); | ||
| 219 | 247 | ||
| 220 | return $this->render( | 248 | return $this->render( |
| 221 | 'comments', | 249 | 'comments', |
| @@ -228,6 +256,15 @@ | @@ -228,6 +256,15 @@ | ||
| 228 | public function actionGallery() | 256 | public function actionGallery() |
| 229 | { | 257 | { |
| 230 | $images = ( new Gallery() )->getImages(); | 258 | $images = ( new Gallery() )->getImages(); |
| 259 | + | ||
| 260 | + $aliasIdsForBlog = [86, 87, 88]; | ||
| 261 | + $this->view->params['aliases'] = \artbox\core\models\Alias::find() | ||
| 262 | + ->where( | ||
| 263 | + [ | ||
| 264 | + 'id' => $aliasIdsForBlog | ||
| 265 | + ] | ||
| 266 | + ) | ||
| 267 | + ->all(); | ||
| 231 | 268 | ||
| 232 | return $this->render( | 269 | return $this->render( |
| 233 | 'gallery', | 270 | 'gallery', |
frontend/views/blog/article.php
frontend/views/layouts/main.php
| @@ -81,6 +81,7 @@ | @@ -81,6 +81,7 @@ | ||
| 81 | $("#feedback-phone, #appointment-phone").mask("+38(999)999-99-99"); | 81 | $("#feedback-phone, #appointment-phone").mask("+38(999)999-99-99"); |
| 82 | JS; | 82 | JS; |
| 83 | $this->registerJs($js, View::POS_READY); | 83 | $this->registerJs($js, View::POS_READY); |
| 84 | + | ||
| 84 | ?> | 85 | ?> |
| 85 | 86 | ||
| 86 | <?php $this->beginPage() ?> | 87 | <?php $this->beginPage() ?> |
| @@ -95,7 +96,25 @@ JS; | @@ -95,7 +96,25 @@ JS; | ||
| 95 | <title><?= Html::encode($seo->title) ?></title> | 96 | <title><?= Html::encode($seo->title) ?></title> |
| 96 | <?php $this->head() ?> | 97 | <?php $this->head() ?> |
| 97 | 98 | ||
| 98 | - | 99 | + <?php |
| 100 | + if(isset($this->params['model'])){ | ||
| 101 | + echo \frontend\widgets\LanguageMarkupWidget::widget( | ||
| 102 | + [ | ||
| 103 | + 'languages' => ['ru', 'ua'], | ||
| 104 | + 'model' => $this->params['model'] | ||
| 105 | + ] | ||
| 106 | + ); | ||
| 107 | + } | ||
| 108 | + else if( isset($this->params['aliases']) ) { | ||
| 109 | + echo \frontend\widgets\LanguageMarkupWidget::widget( | ||
| 110 | + [ | ||
| 111 | + 'languages' => ['ru', 'ua'], | ||
| 112 | + 'aliases' => $this->params['aliases'] | ||
| 113 | + ] | ||
| 114 | + ); | ||
| 115 | + } | ||
| 116 | + ?> | ||
| 117 | + | ||
| 99 | <!-- Google Tag Manager --> | 118 | <!-- Google Tag Manager --> |
| 100 | <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': | 119 | <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': |
| 101 | new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], | 120 | new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], |
frontend/views/site/about.php
| @@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
| 8 | */ | 8 | */ |
| 9 | /** | 9 | /** |
| 10 | * @var SeoComponent $seo | 10 | * @var SeoComponent $seo |
| 11 | - * @var Page $page_stom | 11 | + * @var Page $page_about |
| 12 | */ | 12 | */ |
| 13 | $seo = \Yii::$app->get('seo'); | 13 | $seo = \Yii::$app->get('seo'); |
| 14 | $this->title = \Yii::t('app', 'О клинике'); | 14 | $this->title = \Yii::t('app', 'О клинике'); |
| 1 | +<?php | ||
| 2 | + /** | ||
| 3 | + * Created by PhpStorm. | ||
| 4 | + * User: timur | ||
| 5 | + * Date: 04.12.17 | ||
| 6 | + * Time: 14:52 | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | + namespace frontend\widgets; | ||
| 10 | + use artbox\core\models\Language; | ||
| 11 | + use yii\base\InvalidConfigException; | ||
| 12 | + use yii\base\Widget; | ||
| 13 | + use yii\helpers\VarDumper; | ||
| 14 | + | ||
| 15 | + class LanguageMarkupWidget extends Widget | ||
| 16 | + { | ||
| 17 | + /** | ||
| 18 | + * @var $model \artbox\core\models\Page | ||
| 19 | + */ | ||
| 20 | + public $model; | ||
| 21 | + /** | ||
| 22 | + * @var $aliases \artbox\core\models\Alias[] | ||
| 23 | + */ | ||
| 24 | + public $aliases; | ||
| 25 | + | ||
| 26 | + public $languages = ['en', 'ru', 'ua']; // use in all languages that we have | ||
| 27 | + | ||
| 28 | + private $renderLinks = []; | ||
| 29 | + | ||
| 30 | + public function init() | ||
| 31 | + { | ||
| 32 | + | ||
| 33 | + if (!isset($this->model)){ | ||
| 34 | + | ||
| 35 | + if ( !isset($this->aliases) ){ | ||
| 36 | + throw new InvalidConfigException("need model with lang or array of aliases to same page with different langs"); | ||
| 37 | + } | ||
| 38 | + else{ | ||
| 39 | + | ||
| 40 | + $languages = Language::find()->indexBy('id')->all(); | ||
| 41 | + //VarDumper::dump($languages[1]->url,10,1);die(); | ||
| 42 | + foreach ($this->aliases as $alias){ | ||
| 43 | + if ( in_array($languages[$alias->language_id]->url, $this->languages) ){ | ||
| 44 | + $this->languageMarkup($alias); | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + else{ | ||
| 50 | + foreach ($this->model->langs as $pageLang){ | ||
| 51 | + if (in_array($pageLang->language->url, $this->languages)){ | ||
| 52 | + $this->languageMarkup($pageLang->alias); | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * @param $alias \artbox\core\models\Alias | ||
| 61 | + */ | ||
| 62 | + private function languageMarkup($alias){ | ||
| 63 | + $route = json_decode($alias->route)->{'0'}; | ||
| 64 | + | ||
| 65 | + $url = \yii\helpers\Url::toRoute( | ||
| 66 | + [ | ||
| 67 | + $route, | ||
| 68 | + 'alias' => $alias, | ||
| 69 | + 'language_id' => $alias->language_id | ||
| 70 | + ] | ||
| 71 | + ); | ||
| 72 | + $locale = ''; | ||
| 73 | + if ( $alias->language_id === 2 ){ | ||
| 74 | + $locale = 'ru-UA'; | ||
| 75 | + } | ||
| 76 | + elseif ($alias->language_id === 3){ | ||
| 77 | + $locale = 'uk-UA'; | ||
| 78 | + } | ||
| 79 | + elseif ($alias->language_id === 1){ | ||
| 80 | + $locale = 'en-UA'; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + $this->renderLinks[] = "<link rel=\"alternate\" hreflang=\"$locale\" href=\"$url\" />"; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + public function run() | ||
| 87 | + { | ||
| 88 | + foreach ($this->renderLinks as $renderLink){ | ||
| 89 | + echo $renderLink; | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | + } | ||
| 93 | + | ||
| 0 | \ No newline at end of file | 94 | \ No newline at end of file |