Example #1
0
 public function actionIndex($slug)
 {
     $page = PageService::findBySlug($slug);
     if (isset($page)) {
         // Find Template
         $content = $page->content;
         $template = $content->template;
         // Page using Template
         if (isset($template)) {
             $layout = $template->layout;
             $view = $template->viewPath . "/{$template->frontendView}";
             $this->layout = "//{$layout}";
             // Render using Template
             if (isset($layout) && isset($view)) {
                 return $this->render($view, ['page' => $page, 'author' => $page->createdBy, 'content' => $content, 'banner' => $content->banner]);
             } else {
                 return $this->render('index', [CoreGlobal::FLASH_GENERIC => Yii::$app->cmgCmsMessage->getMessage(CmsGlobal::ERROR_NO_VIEW)]);
             }
         } else {
             return $this->redirect('site/' . $page->slug);
         }
     }
     // Page not found
     throw new NotFoundHttpException(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_FOUND));
 }
Example #2
0
 /**
  * It returns page full content to be used in page blocks on other pages.
  * @return string - page content
  */
 public static function getPageContent($config = [])
 {
     if (isset($config['slug'])) {
         $slug = $config['slug'];
         $page = PageService::findBySlug($slug);
     }
     if (isset($config['page'])) {
         $page = $config['page'];
     }
     if (isset($page)) {
         $content = $page->content;
         $content = $content->content;
         $content .= "<div class='page-content'>{$content}</div>";
         return $content;
     }
     return '';
 }
 public function renderItems()
 {
     $user = Yii::$app->user->getIdentity();
     $menu = MenuService::findBySlug($this->slug);
     $pageSlug = Yii::$app->request->get('slug');
     if (isset($menu) && $menu->active) {
         $pageLinks = MenuService::getPageLinks($menu, true);
         $pageLinks = array_keys($pageLinks);
         $pages = PageService::getMenuPages($pageLinks, true);
         $menuItems = $menu->generateObjectFromJson(true);
         $menuItems = $menuItems->links;
         $absoluteUrl = Yii::$app->request->absoluteUrl;
         foreach ($menuItems as $menuItem) {
             if (strcmp($menuItem['type'], CmsGlobal::TYPE_PAGE) == 0) {
                 $link = new PageLink($menuItem);
                 $item = null;
                 $address = null;
                 if (isset($pages[$link->pageId])) {
                     $page = $pages[$link->pageId];
                     if ($page->isPublic() || isset($user)) {
                         if (strcmp($page->slug, 'home') == 0) {
                             $address = Url::toRoute(["/"]);
                         } else {
                             $address = Url::toRoute(["/{$page->slug}"]);
                         }
                         $item = ['url' => $address, 'label' => $page->name, 'icon' => $page->icon];
                         if (isset($link->options)) {
                             $item['options'] = json_decode($link->options);
                         }
                         if (isset($pageSlug) && strcmp($pageSlug, $page->slug) == 0) {
                             $item['options'] = ['class' => 'active'];
                         }
                         $this->items[] = $item;
                     }
                 }
             } else {
                 if (strcmp($menuItem['type'], CmsGlobal::TYPE_LINK) == 0) {
                     $link = new Link($menuItem);
                     $item = null;
                     $address = null;
                     if (strlen($link->label) > 0) {
                         if ($link->isPublic() || isset($user)) {
                             if ($link->relative) {
                                 // Clean URL if first character is slash
                                 if (substr($link->address, 0, 1) == "/") {
                                     $link->address = substr($link->address, 1);
                                 }
                                 $address = Url::toRoute(["/{$link->address}"], true);
                             } else {
                                 $address = $link->address;
                             }
                             $item = ['url' => $address, 'label' => $link->label, 'icon' => $link->icon];
                             if (isset($link->options)) {
                                 $item['options'] = json_decode($link->options);
                             }
                             if (strcmp($address, $absoluteUrl) == 0) {
                                 $item['options'] = ['class' => 'active'];
                             }
                             $this->items[] = $item;
                         }
                     }
                 }
             }
         }
     }
     return parent::renderItems();
 }