/** * After save update cache of blocks * @inheritdoc */ public function afterSave($insert, $changedAttributes) { $machineName = 'lastBlogPosts'; $cacheBlock = CacheBlock::find()->where(['machine_name' => $machineName])->one(); if (!isset($cacheBlock)) { $cacheBlock = new CacheBlock(); $cacheBlock->machine_name = $machineName; } $cacheBlock->content = SiteBlock::getBlogPosts(false); $cacheBlock->save(); return parent::afterSave($insert, $changedAttributes); }
</div> </header> <div id="wrapper"> <?php echo $content; ?> </div> <footer id="colophon" class="site-footer" role="contentinfo"> <div class="footer-wrapper"> <div class="bottom-banners-area"> <?php $bannerBlock = SiteBlock::getBanner(Banner::REGION_BOTTOM); if ($bannerBlock) { echo $this->render($bannerBlock['view'], isset($bannerBlock['data']) ? $bannerBlock['data'] : []); } ?> </div> <div class="footer-bottom"> <div class="block-top"> <a target="_blank" href="/rss.xml"> <div class="button rss"></div> <div class="text">RSS</div> </a> <a href="<?php echo Url::to('/information'); ?>
<?php use yii\helpers\Url; /** * @var $this yii\web\View * @var $model common\models\Question **/ $block = \common\models\SiteBlock::getQuestionBlockTitle($model); echo $this->render($block['view'], $block['data']);
break; case 'grid-main-column': $region = Banner::REGION_FIRST_COLUMN; $isSmall = false; break; default: $region = 0; break; } ?> <div class="grid-column <?php echo $classes; ?> "> <?php if ($classes == 'grid-column-2' || $classes == 'grid-sidebar-column') { echo $this->render('@frontend/views/site/alert'); } if ($region == Banner::REGION_THIRD_COLUMN) { $bannerBlock = SiteBlock::getBanner(Banner::REGION_TOP_THIRD_COLUMN); if ($bannerBlock) { echo $this->render($bannerBlock['view'], isset($bannerBlock['data']) ? $bannerBlock['data'] : []); } } foreach ($blocks as $block) { if ($block) { echo $this->render($block['view'], isset($block['data']) ? $block['data'] : []); } } ?> </div>
?> <div class="video-icon"></div> <?php } elseif ($post->with_photo) { ?> <div class="photo-icon"></div> <?php } ?> </div> </div> </div> </div> <?php if ($enableBanners && $count && $count % 10 == 0) { $bannerBlock = SiteBlock::getBanner(Banner::REGION_NEWS); if ($bannerBlock) { echo $this->render($bannerBlock['view'], isset($bannerBlock['data']) ? $bannerBlock['data'] : []); } } } ?> <div class="header no-border"> <a href="<?php echo Url::to('/news'); ?> "> <div class="link-to-all-icon"></div> <div class="link-to-all-text">Все новости:</div> </a> </div>
/** * Reset password */ public function actionReset($key) { /** @var \common\modules\user\models\User $user */ /** @var \common\modules\user\models\UserKey $userKey */ // check for valid userKey $userKey = Yii::$app->getModule("user")->model("UserKey"); $userKey = $userKey::findActiveByKey($key, $userKey::TYPE_PASSWORD_RESET); if (!$userKey) { return $this->render('reset', ["invalidKey" => true]); } // get user and set "reset" scenario $success = false; $user = Yii::$app->getModule("user")->model("User"); $user = $user::findOne($userKey->user_id); $user->setScenario("reset"); // load post data and reset user password if ($user->load(Yii::$app->request->post()) && $user->save()) { // consume userKey and set success = true $userKey->consume(); $success = true; } // render // return $this->render('reset', compact("user", "success")); return $this->render('@frontend/views/site/index', ['templateType' => 'col3', 'title' => Yii::t('user', 'Вход'), 'columnFirst' => ['top3News' => SiteBlock::getTop3News(), 'top6News' => SiteBlock::getTop6News(), 'subscribing' => SiteBlock::getSubscribingForm(), 'blog_column' => SiteBlock::getBlogPosts()], 'columnSecond' => ['forgot_block' => ['view' => 'reset', 'data' => compact('user', 'success')], 'short_news' => SiteBlock::getShortNews()], 'columnThird' => ['reviewNews' => SiteBlock::getPhotoVideoNews(), 'questionBlock' => SiteBlock::getQuestionBlock(), 'tournament' => SiteBlock::getTournamentTable()]]); }
/** * Url: /album/{$album_id}-{$slug}/{$photo_id} * @param int $album_id Album id * @param string $slug Album slug * @param $photo_id * @return mixed Content * @throws NotFoundHttpException */ public function actionPhoto($album_id, $slug, $photo_id) { $album = Album::find()->where(['id' => $album_id, 'is_public' => 1])->one(); if (!isset($album)) { throw new NotFoundHttpException('Страница не найдена.'); } $photo = Asset::find()->where(['id' => $photo_id, 'thumbnail' => Asset::THUMBNAIL_CONTENT])->one(); if (!isset($photo)) { $photo = Asset::find()->where(['id' => $photo_id])->one(); } if (!isset($photo)) { throw new NotFoundHttpException('Страница не найдена.'); } return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | Фотоальбом: ' . $album->title, 'columnFirst' => ['content' => ['view' => '@frontend/views/site/photo_single', 'data' => compact('album', 'photo')], 'comments' => Comment::getCommentsBlock($photo->id, Comment::COMMENTABLE_PHOTO)], 'columnSecond' => ['short_news' => SiteBlock::getshortNews(50)]]); }
/** * After save and before delete update cache of blocks */ public function updateCacheBlocks($changedAttributes) { $newsPosts50 = Post::find()->where(['is_public' => 1, 'content_category_id' => Post::CATEGORY_NEWS])->orderBy(['created_at' => SORT_DESC])->limit(50)->all(); $newsPosts20 = array_slice($newsPosts50, 0, 20); $cacheBlocksData = CacheBlock::find()->all(); $cacheBlocks = []; foreach ($cacheBlocksData as $block) { $cacheBlocks[$block->machine_name] = $block; } $cacheStatus = false; if (isset($changedAttributes['content_category_id']) && $changedAttributes['content_category_id'] == self::CATEGORY_NEWS && $this->content_category_id != self::CATEGORY_NEWS || $this->content_category_id == self::CATEGORY_NEWS) { $machineName = 'shortNews50'; $enableBanners = false; if (!isset($cacheBlocks[$machineName])) { $cacheBlock = new CacheBlock(); $cacheBlock->machine_name = $machineName; } else { $cacheBlock = $cacheBlocks[$machineName]; } $cacheBlock->content = SiteBlock::getShortNews(50, $enableBanners, $cacheStatus, $newsPosts50); $cacheBlock->save(); $machineName = 'shortNews50banners'; $enableBanners = true; SiteBlock::$postedBannerIds = []; if (!isset($cacheBlocks[$machineName])) { $cacheBlock = new CacheBlock(); $cacheBlock->machine_name = $machineName; } else { $cacheBlock = $cacheBlocks[$machineName]; } $cacheBlock->content = SiteBlock::getShortNews(50, $enableBanners, $cacheStatus, $newsPosts50); $cacheBlock->save(); } if (isset($changedAttributes['is_index']) && $this->is_index != $changedAttributes['is_index'] || isset($changedAttributes['is_top']) && $this->is_top != $changedAttributes['is_top'] || $this->is_top || $this->is_index) { $machineName = 'top3News'; if (!isset($cacheBlocks[$machineName])) { $cacheBlock = new CacheBlock(); $cacheBlock->machine_name = $machineName; } else { $cacheBlock = $cacheBlocks[$machineName]; } $cacheBlock->content = SiteBlock::getTop3News($cacheStatus); $cacheBlock->save(); $machineName = 'top6News'; if (!isset($cacheBlocks[$machineName])) { $cacheBlock = new CacheBlock(); $cacheBlock->machine_name = $machineName; } else { $cacheBlock = $cacheBlocks[$machineName]; } $cacheBlock->content = SiteBlock::getTop6News($cacheStatus); $cacheBlock->save(); } if ($this->content_category_id == self::CATEGORY_BLOG) { $machineName = 'lastBlogPosts'; if (!isset($cacheBlocks[$machineName])) { $cacheBlock = new CacheBlock(); $cacheBlock->machine_name = $machineName; } else { $cacheBlock = $cacheBlocks[$machineName]; } $cacheBlock->content = SiteBlock::getBlogPosts($cacheStatus); $cacheBlock->save(); $machineName = 'blogPostsByRating'; if (!isset($cacheBlocks[$machineName])) { $cacheBlock = new CacheBlock(); $cacheBlock->machine_name = $machineName; } else { $cacheBlock = $cacheBlocks[$machineName]; } $cacheBlock->content = SiteBlock::getBlogPostsByRating($cacheStatus); $cacheBlock->save(); } }