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 | 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 | 46 | $this->view->params[ 'breadcrumbs' ][] = \Yii::t('app', 'Блог'); |
| 38 | 47 | |
| ... | ... | @@ -151,6 +160,8 @@ |
| 151 | 160 | throw new NotFoundHttpException(); |
| 152 | 161 | } |
| 153 | 162 | |
| 163 | + $this->view->params['model'] = $article; | |
| 164 | + | |
| 154 | 165 | return $this->render( |
| 155 | 166 | 'article', |
| 156 | 167 | [ | ... | ... |
frontend/controllers/PageController.php
frontend/controllers/PersoneController.php
| ... | ... | @@ -22,6 +22,15 @@ |
| 22 | 22 | ->with('lang.alias') |
| 23 | 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 | 34 | return $this->render( |
| 26 | 35 | 'index', |
| 27 | 36 | [ |
| ... | ... | @@ -39,6 +48,8 @@ |
| 39 | 48 | { |
| 40 | 49 | $model = $this->findModel($id); |
| 41 | 50 | |
| 51 | + $this->view->params['model'] = $model; | |
| 52 | + | |
| 42 | 53 | return $this->render( |
| 43 | 54 | 'view', |
| 44 | 55 | [ | ... | ... |
frontend/controllers/SiteController.php
| ... | ... | @@ -63,6 +63,16 @@ |
| 63 | 63 | public function actionContact() |
| 64 | 64 | { |
| 65 | 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 | 76 | return $this->render( |
| 67 | 77 | 'contact', |
| 68 | 78 | [ |
| ... | ... | @@ -199,6 +209,15 @@ |
| 199 | 209 | ->with('lang') |
| 200 | 210 | ->where([ 'id' => 4 ]) |
| 201 | 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 | 222 | return $this->render( |
| 204 | 223 | 'price', |
| ... | ... | @@ -216,6 +235,15 @@ |
| 216 | 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 | 248 | return $this->render( |
| 221 | 249 | 'comments', |
| ... | ... | @@ -228,6 +256,15 @@ |
| 228 | 256 | public function actionGallery() |
| 229 | 257 | { |
| 230 | 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 | 269 | return $this->render( |
| 233 | 270 | 'gallery', | ... | ... |
frontend/views/blog/article.php
frontend/views/layouts/main.php
| ... | ... | @@ -81,6 +81,7 @@ |
| 81 | 81 | $("#feedback-phone, #appointment-phone").mask("+38(999)999-99-99"); |
| 82 | 82 | JS; |
| 83 | 83 | $this->registerJs($js, View::POS_READY); |
| 84 | + | |
| 84 | 85 | ?> |
| 85 | 86 | |
| 86 | 87 | <?php $this->beginPage() ?> |
| ... | ... | @@ -95,7 +96,25 @@ JS; |
| 95 | 96 | <title><?= Html::encode($seo->title) ?></title> |
| 96 | 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 | 118 | <!-- Google Tag Manager --> |
| 100 | 119 | <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': |
| 101 | 120 | new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], | ... | ... |
frontend/views/site/about.php
| 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 | 94 | \ No newline at end of file | ... | ... |