Commit 4dbca9cd112e05edef8b898e3527bef4db260679
1 parent
f3bbe77c
-Short codes ready
Showing
2 changed files
with
38 additions
and
18 deletions
Show diff stats
frontend/controllers/PageController.php
| 1 | <?php | 1 | <?php |
| 2 | namespace frontend\controllers; | 2 | namespace frontend\controllers; |
| 3 | - | 3 | + |
| 4 | use artbox\core\components\SeoComponent; | 4 | use artbox\core\components\SeoComponent; |
| 5 | use artbox\core\models\Page; | 5 | use artbox\core\models\Page; |
| 6 | - use yii\helpers\Json; | ||
| 7 | - use yii\helpers\Url; | ||
| 8 | - use yii\helpers\VarDumper; | ||
| 9 | use yii\web\Controller; | 6 | use yii\web\Controller; |
| 10 | use yii\web\NotFoundHttpException; | 7 | use yii\web\NotFoundHttpException; |
| 11 | use Yii; | 8 | use Yii; |
| 12 | - | 9 | + |
| 13 | /** | 10 | /** |
| 14 | * Class PageController | 11 | * Class PageController |
| 15 | * | 12 | * |
| @@ -20,13 +17,22 @@ | @@ -20,13 +17,22 @@ | ||
| 20 | public function actionView($id) | 17 | public function actionView($id) |
| 21 | { | 18 | { |
| 22 | $model = $this->findModel($id); | 19 | $model = $this->findModel($id); |
| 23 | - | 20 | + |
| 24 | /** | 21 | /** |
| 25 | * @var SeoComponent $seo | 22 | * @var SeoComponent $seo |
| 26 | */ | 23 | */ |
| 27 | $seo = Yii::$app->get('seo'); | 24 | $seo = Yii::$app->get('seo'); |
| 28 | $seo->setModel($model->lang); | 25 | $seo->setModel($model->lang); |
| 29 | - | 26 | + |
| 27 | + if (strpos($model->lang->body, '[[gallery]]')) { | ||
| 28 | + $splited = explode('[[gallery]]', $model->lang->body); | ||
| 29 | + $body = array_shift($splited); | ||
| 30 | + $lefts = implode('', $splited); | ||
| 31 | + } else { | ||
| 32 | + $body = $model->lang->body; | ||
| 33 | + $lefts = null; | ||
| 34 | + } | ||
| 35 | + | ||
| 30 | $pages = Page::find() | 36 | $pages = Page::find() |
| 31 | ->with('lang') | 37 | ->with('lang') |
| 32 | ->where( | 38 | ->where( |
| @@ -41,13 +47,15 @@ | @@ -41,13 +47,15 @@ | ||
| 41 | return $this->render( | 47 | return $this->render( |
| 42 | 'view', | 48 | 'view', |
| 43 | [ | 49 | [ |
| 44 | - 'model' => $model, | ||
| 45 | - 'pages' => $pages, | 50 | + 'model' => $model, |
| 51 | + 'pages' => $pages, | ||
| 46 | 'images' => $model->getImages(), | 52 | 'images' => $model->getImages(), |
| 53 | + 'body' => $body, | ||
| 54 | + 'lefts' => $lefts, | ||
| 47 | ] | 55 | ] |
| 48 | ); | 56 | ); |
| 49 | } | 57 | } |
| 50 | - | 58 | + |
| 51 | protected function findModel($id) | 59 | protected function findModel($id) |
| 52 | { | 60 | { |
| 53 | /** | 61 | /** |
| @@ -61,8 +69,8 @@ | @@ -61,8 +69,8 @@ | ||
| 61 | ) | 69 | ) |
| 62 | ->with('lang') | 70 | ->with('lang') |
| 63 | ->one(); | 71 | ->one(); |
| 64 | - | ||
| 65 | - if (!empty( $model )) { | 72 | + |
| 73 | + if (!empty($model)) { | ||
| 66 | if ($model->lang->alias_id !== Yii::$app->seo->aliasId) { | 74 | if ($model->lang->alias_id !== Yii::$app->seo->aliasId) { |
| 67 | throw new NotFoundHttpException('Wrong language'); | 75 | throw new NotFoundHttpException('Wrong language'); |
| 68 | } | 76 | } |
frontend/views/page/view.php
| @@ -11,6 +11,8 @@ | @@ -11,6 +11,8 @@ | ||
| 11 | * @var Page[] $pages | 11 | * @var Page[] $pages |
| 12 | * @var SeoComponent $seo | 12 | * @var SeoComponent $seo |
| 13 | * @var Image[] $images | 13 | * @var Image[] $images |
| 14 | + * @var string $body | ||
| 15 | + * @var string $lefts | ||
| 14 | */ | 16 | */ |
| 15 | $seo = \Yii::$app->get('seo'); | 17 | $seo = \Yii::$app->get('seo'); |
| 16 | $this->params[ 'breadcrumbs' ][] = $seo->title; | 18 | $this->params[ 'breadcrumbs' ][] = $seo->title; |
| @@ -25,8 +27,16 @@ | @@ -25,8 +27,16 @@ | ||
| 25 | _________________________________________________________ --> | 27 | _________________________________________________________ --> |
| 26 | 28 | ||
| 27 | <div class="col-md-9 clearfix"> | 29 | <div class="col-md-9 clearfix"> |
| 30 | + | ||
| 31 | + <section> | ||
| 32 | + <div id="text-page"> | ||
| 33 | + | ||
| 34 | + <?= $body ?> | ||
| 28 | 35 | ||
| 29 | - <?php if (!empty($images)) { ?> | 36 | + </div> |
| 37 | + </section> | ||
| 38 | + | ||
| 39 | + <?php if (!empty($images) && !empty($lefts)) { ?> | ||
| 30 | <section> | 40 | <section> |
| 31 | <div class="project owl-carousel"> | 41 | <div class="project owl-carousel"> |
| 32 | 42 | ||
| @@ -40,15 +50,17 @@ _________________________________________________________ --> | @@ -40,15 +50,17 @@ _________________________________________________________ --> | ||
| 40 | <!-- /.project owl-slider --> | 50 | <!-- /.project owl-slider --> |
| 41 | </section> | 51 | </section> |
| 42 | <?php } ?> | 52 | <?php } ?> |
| 43 | - | 53 | + |
| 54 | + <?php if (!empty($lefts)) { ?> | ||
| 44 | <section> | 55 | <section> |
| 45 | <div id="text-page"> | 56 | <div id="text-page"> |
| 46 | - | ||
| 47 | - <?= $model->lang->body ?> | ||
| 48 | - | 57 | + |
| 58 | + <?= $lefts ?> | ||
| 59 | + | ||
| 49 | </div> | 60 | </div> |
| 50 | </section> | 61 | </section> |
| 51 | - | 62 | + <?php } ?> |
| 63 | + | ||
| 52 | </div> | 64 | </div> |
| 53 | <!-- /.col-md-9 --> | 65 | <!-- /.col-md-9 --> |
| 54 | 66 |