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