Exemple #1
0
 public function buildLayout()
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Rebond\Cms\Layout\Data::getList(['id', 'title']);
     $models = \Rebond\Cms\Layout\Data::loadAll($options);
     return Util\Form::buildDropdownList('layoutId' . $this->unique, $models, 'id', 'title', $this->getModel()->getLayoutId(), $this->layoutValidator['foreignKey']);
 }
Exemple #2
0
 public function layout_edit()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.cms.layout', true, '/cms/layout');
     // check
     $id = Converter::int('id');
     $layout = \Rebond\Cms\Layout\Data::loadById($id, true);
     $form = new \Rebond\Cms\Layout\Form($layout);
     // action
     if (isset($_POST['save'])) {
         Auth::isAdminAuthorized($this->signedUser, 'admin.cms.layout', true, '/cms/layout-edit?id=' . $id);
         if ($form->setFromPost()->validate()->isValid()) {
             $layout->save();
             Session::adminSuccess('saved', '/cms/layout');
         } else {
             Session::set('adminError', $form->getValidation()->getMessage());
         }
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::MODULE, ['cms', 'layout']);
     $tplMain->set('item', $form);
     // layout
     if (Auth::isAdminAuthorized($this->signedUser, 'admin.cms.layout.edit', false)) {
         $this->tplLayout->set('column1', $tplMain->render('editor'));
     } else {
         $this->tplLayout->set('column1', $tplMain->render('view'));
     }
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     return $this->tplMaster->render('tpl-default');
 }
Exemple #3
0
 protected static function mapper(array $row, $alias = 'page')
 {
     $model = new \Rebond\Cms\Page\Model(false);
     if (isset($row[$alias . 'Id'])) {
         $model->setId($row[$alias . 'Id']);
     }
     if (isset($row[$alias . 'ParentId'])) {
         $model->setParentId($row[$alias . 'ParentId']);
         $model->setParent(\Rebond\Cms\Page\Data::join($row, $alias . '_parent'));
     }
     if (isset($row[$alias . 'TemplateId'])) {
         $model->setTemplateId($row[$alias . 'TemplateId']);
         $model->setTemplate(\Rebond\Cms\Template\Data::join($row, $alias . '_template'));
     }
     if (isset($row[$alias . 'LayoutId'])) {
         $model->setLayoutId($row[$alias . 'LayoutId']);
         $model->setLayout(\Rebond\Cms\Layout\Data::join($row, $alias . '_layout'));
     }
     if (isset($row[$alias . 'Title'])) {
         $model->setTitle($row[$alias . 'Title']);
     }
     if (isset($row[$alias . 'Css'])) {
         $model->setCss($row[$alias . 'Css']);
     }
     if (isset($row[$alias . 'Js'])) {
         $model->setJs($row[$alias . 'Js']);
     }
     if (isset($row[$alias . 'InNavHeader'])) {
         $model->setInNavHeader($row[$alias . 'InNavHeader']);
     }
     if (isset($row[$alias . 'InNavSide'])) {
         $model->setInNavSide($row[$alias . 'InNavSide']);
     }
     if (isset($row[$alias . 'InSitemap'])) {
         $model->setInSitemap($row[$alias . 'InSitemap']);
     }
     if (isset($row[$alias . 'InBreadcrumb'])) {
         $model->setInBreadcrumb($row[$alias . 'InBreadcrumb']);
     }
     if (isset($row[$alias . 'InNavFooter'])) {
         $model->setInNavFooter($row[$alias . 'InNavFooter']);
     }
     if (isset($row[$alias . 'FriendlyUrlPath'])) {
         $model->setFriendlyUrlPath($row[$alias . 'FriendlyUrlPath']);
     }
     if (isset($row[$alias . 'FriendlyUrl'])) {
         $model->setFriendlyUrl($row[$alias . 'FriendlyUrl']);
     }
     if (isset($row[$alias . 'Redirect'])) {
         $model->setRedirect($row[$alias . 'Redirect']);
     }
     if (isset($row[$alias . 'Class'])) {
         $model->setClass($row[$alias . 'Class']);
     }
     if (isset($row[$alias . 'Permission'])) {
         $model->setPermission($row[$alias . 'Permission']);
     }
     if (isset($row[$alias . 'DisplayOrder'])) {
         $model->setDisplayOrder($row[$alias . 'DisplayOrder']);
     }
     if (isset($row[$alias . 'Status'])) {
         $model->setStatus($row[$alias . 'Status']);
     }
     if (isset($row[$alias . 'CreatedDate'])) {
         $model->setCreatedDate($row[$alias . 'CreatedDate']);
     }
     if (isset($row[$alias . 'ModifiedDate'])) {
         $model->setModifiedDate($row[$alias . 'ModifiedDate']);
     }
     return $model;
 }
Exemple #4
0
 public function gadget()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.page.gadget', true, '/page');
     // check
     $id = Converter::int('id');
     $save = Converter::int('save', 'post');
     $page = \Rebond\Cms\Page\Data::loadById($id);
     if (!isset($page)) {
         header('Location: /page');
         exit;
     }
     $gadget = new \Rebond\Cms\Gadget\Model();
     $gadget->setPageId($page->getId());
     $form = new \Rebond\Cms\Gadget\Form($gadget);
     // action
     if (isset($save)) {
         Auth::isAdminAuthorized($this->signedUser, 'admin.page.gadget.edit', true, '/page/gadget?id=' . $id);
         if ($form->setFromPost()->validate()->isValid()) {
             $gadget->save();
             Session::adminSuccess('saved', '/page/gadget?id=' . $id);
         } else {
             Session::set('adminError', $form->getValidation()->getMessage());
         }
     }
     // view
     $this->setTpl();
     // form
     $layout = \Rebond\Cms\Layout\Data::loadById($page->getLayoutId());
     $columns = $layout->getColumns();
     $columnOptions = [];
     for ($i = 1; $i <= $columns; $i++) {
         $columnOptions[$i] = Lang::lang('column') . ' ' . $i;
     }
     $tplForm = new Template(Template::MODULE, ['cms', 'gadget']);
     $tplForm->set('item', $form);
     $tplForm->set('title', Lang::lang('manageGadgetOf', [$page->getTitle()]));
     $tplForm->set('columnOptions', $columnOptions);
     $tplForm->set('selectedColumn', $gadget->getCol());
     // active listing
     $options = [];
     $options['join'][] = 'cms_page page ON page.id = gadget.page_id';
     $options['join'][] = 'cms_component component ON component.id = gadget.component_id';
     $options['join'][] = 'cms_module module ON module.id = component.module_id';
     $options['where'][] = ['page.id = ?', $page->getId()];
     $options['where'][] = 'module.status = 1';
     $options['where'][] = 'component.status = 1';
     $options['order'][] = 'gadget.col';
     $options['order'][] = 'gadget.display_order';
     $gadgets = \Rebond\Cms\Gadget\Data::loadAll($options);
     if ($gadgets) {
         foreach ($gadgets as $g) {
             $g->prepareFilter();
         }
     }
     // inactive listing
     $options = [];
     $options['join'][] = 'cms_page page ON page.id = gadget.page_id';
     $options['join'][] = 'cms_component component ON component.id = gadget.component_id';
     $options['join'][] = 'cms_module module ON module.id = component.module_id';
     $options['where'][] = ['page.id = ?', $page->getId()];
     $options['where'][] = 'module.status = 0 OR component.status = 0';
     $options['order'][] = 'gadget.col';
     $options['order'][] = 'gadget.display_order';
     $inactiveGadgets = \Rebond\Cms\Gadget\Data::loadAll($options);
     if ($inactiveGadgets) {
         foreach ($inactiveGadgets as $g) {
             $g->prepareFilter();
         }
     }
     $tplListing = new Template(Template::MODULE, ['cms', 'gadget']);
     $tplListing->set('items', $gadgets);
     $tplListing->set('inactiveItems', $inactiveGadgets);
     $tplListing->set('columnOptions', $columnOptions);
     // layout
     $this->tplLayout->add('column1', $tplForm->render('editor-selector'));
     $this->tplLayout->add('column2', $tplListing->render('listing'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-2-row'));
     $this->tplMaster->set('jsLauncher', 'pageGadget');
     return $this->tplMaster->render('tpl-default');
 }
Exemple #5
0
 public function getLayout($createIfNotExist = false)
 {
     if (!isset($this->layout)) {
         $this->layout = \Rebond\Cms\Layout\Data::loadById($this->layoutId, $createIfNotExist);
     }
     return $this->layout;
 }
Exemple #6
0
 public function run($app, $friendlyUrl)
 {
     // is site active
     if ($app->site()->getStatus() == 0) {
         $friendlyUrl = '/inactive';
     }
     // retrieve page
     $page = \Rebond\Cms\Page\Data::loadByUrl($friendlyUrl);
     // this should never occur
     if (!isset($page)) {
         Error::kill(Error::PAGE_NOT_FOUND, $friendlyUrl, __FILE__, __LINE__);
     }
     // redirection
     if ($page->getRedirect() != '' && $page->getRedirect() != $friendlyUrl) {
         $friendlyUrl = Nav::readCmsRequest($page->getRedirect());
         echo $this->run($app, $friendlyUrl);
         return;
     }
     // permission
     Auth::isAuthorized($app->user(), $page->getPermission(), true, $app->site()->getSignInUrl());
     $app->setUrl($friendlyUrl);
     // layout
     $layout = \Rebond\Cms\Layout\Data::loadById($page->getLayoutId());
     $tplLayout = new Template(Template::SITE, ['www']);
     // page components
     $options = [];
     $options['where'][] = 'gadget.status = 1';
     $options['order'][] = 'gadget.display_order';
     $gadgets = \Rebond\Cms\Gadget\Data::loadAllByPageId($page->getId(), $options);
     $cacheTime = $app->site()->getCacheTime();
     if ($gadgets) {
         $this->app = $app;
         $this->gadgets = [];
         foreach ($gadgets as $gadget) {
             if ($gadget->getComponent()->getId() == 0) {
                 Log::log(Error::COMPONENT_NOT_FOUND, 'title: ' . $gadget->getTitle() . ', componentId: ' . $gadget->getComponentId(), __FILE__, __LINE__);
                 continue;
             }
             $component = $gadget->getComponent();
             $appGadget = '\\Rebond\\App\\' . $component->getModule()->getTitle() . '\\Gadget';
             $appMethod = $component->getMethod();
             if (!method_exists($appGadget, $appMethod)) {
                 Log::log(Error::GADGET_NOT_FOUND, 'gadget: ' . $appGadget . ', method: ' . $appMethod, __FILE__, __LINE__);
                 continue;
             }
             if ($component->getStatus() !== StatusType::ACTIVE) {
                 continue;
             }
             if ($component->getModule()->getStatus() !== StatusType::ACTIVE) {
                 continue;
             }
             $name = $component->getModule()->getTitle() . '_' . $component->getMethod();
             // look for cache
             if ($cacheTime > 0) {
                 $html = Cache::getGadgetCache($name, $cacheTime);
                 if (isset($html)) {
                     $tplLayout->add('column' . $gadget->getCol(), $html);
                     continue;
                 }
             }
             $gadgetClass = $this->getGadget($appGadget);
             // get filter
             if ($component->getType() == ComponentType::SINGLE_ITEM || $component->getType() == ComponentType::FILTERED_LISTING) {
                 if ($gadget->getFilterId() == 0) {
                     Log::log(Error::EMPTY_FILTER, $name, __FILE__, __LINE__);
                     continue;
                 } else {
                     $render = $gadgetClass->{$appMethod}($gadget->getFilterId());
                 }
             } else {
                 if ($component->getType() == ComponentType::CUSTOM_LISTING) {
                     $render = $gadgetClass->{$appMethod}($gadget->getCustomFilter());
                 } else {
                     $render = $gadgetClass->{$appMethod}();
                 }
             }
             $tplLayout->add('column' . $gadget->getCol(), $render);
             // save cache
             if ($cacheTime > 0) {
                 Cache::saveGadgetCache($name, $cacheTime, $render);
             }
         }
     }
     // check for empty columns
     $columns = $layout->getColumns();
     $noComponent = '<div class="no-component">' . Lang::lang('noComponent') . '</div>';
     $emptyValue = $app->logLevel() == 0 ? $noComponent : '';
     for ($i = 1; $i <= $columns; $i++) {
         if ($tplLayout->varIsSet('column' . $i) === false) {
             $tplLayout->set('column' . $i, $emptyValue);
         }
     }
     // template
     $template = \Rebond\Cms\Template\Data::loadById($page->getTemplateId());
     $tplMaster = new Template(Template::SITE, ['www']);
     // navHeader
     $isMenuCached = false;
     if ($template->getMenu() != \Rebond\Cms\MenuType::NONE) {
         // Get cache
         if ($cacheTime > 0) {
             $navHeader = Cache::getCache('navHeader', $template->getMenu() . '_' . $template->getMenuLevel(), $cacheTime);
             if (isset($navHeader)) {
                 $isMenuCached = true;
             }
         }
         if (!$isMenuCached) {
             $navHeader = \Rebond\Cms\Page\Data::buildHeaderNav($template->getMenuLevel(), $template->getMenu());
             // Save cache
             if ($cacheTime > 0) {
                 Cache::saveCache('navHeader', $template->getMenu() . '_' . $template->getMenuLevel(), $cacheTime, $navHeader);
             }
         }
         $tpl = new Template(Template::SITE, ['www']);
         $tpl->set('title', $app->site()->getTitle());
         $tpl->set('nav', \Rebond\Cms\Page\Service::renderNav($navHeader, $page->getFullUrl()));
         $tplMaster->set('navHeader', $tpl->render('nav-header'));
     }
     // breacrumb
     $isMenuCached = false;
     if ($template->getInBreadcrumb()) {
         // Get cache
         if ($cacheTime > 0) {
             $breadcrumb = Cache::getCache('breadcrumb', $page->getId(), $cacheTime);
             if (isset($breadcrumb)) {
                 $isMenuCached = true;
             }
         }
         if (!$isMenuCached) {
             $breadcrumb = \Rebond\Cms\Page\Service::renderBreadcrumb($page->getId());
             // Save cache
             if ($cacheTime > 0) {
                 Cache::saveCache('breadcrumb', $page->getId(), $cacheTime, $breadcrumb);
             }
         }
         $tplMaster->set('breadcrumb', $breadcrumb);
     }
     // navSide
     $isMenuCached = false;
     if ($template->getSideNav() != \Rebond\Cms\SideNavType::NONE) {
         // Get cache
         if ($cacheTime > 0) {
             $navSide = Cache::getCache('navSide', $template->getSideNav() . '_' . $template->getSideNavLevel(), $cacheTime);
             if (isset($navSide)) {
                 $isMenuCached = true;
             }
         }
         if (!$isMenuCached) {
             switch ($template->getSideNav()) {
                 case \Rebond\Cms\SideNavType::PARENT_1:
                     $currentId = $page->getParentId();
                     break;
                 case \Rebond\Cms\SideNavType::CHILDREN:
                     $currentId = $page->getId();
                     break;
                 case \Rebond\Cms\SideNavType::HOME:
                     $currentId = 1;
                     break;
                 case \Rebond\Cms\SideNavType::PARENT_2:
                     $currentId = \Rebond\Cms\Page\Data::loadByParent($page->getParentId(), 1);
                     break;
                 case \Rebond\Cms\SideNavType::PARENT_3:
                     $currentId = \Rebond\Cms\Page\Data::loadByParent($page->getParentId(), 2);
                     break;
             }
             $navSide = \Rebond\Cms\Page\Data::buildSideNav($currentId, $template->getSideNavLevel());
             // Save cache
             if ($cacheTime > 0) {
                 Cache::saveCache('navSide', $template->getSideNav() . '_' . $template->getSideNavLevel(), $cacheTime, $navSide);
             }
         }
         $tpl = new Template(Template::SITE, ['www']);
         $tpl->set('nav', \Rebond\Cms\Page\Service::renderNav($navSide, $page->getFullUrl()));
         $tplMaster->set('navSide', $tpl->render('nav-side'));
     }
     // navFooter
     $isMenuCached = false;
     if ($template->getInFooter() != 0) {
         // Get cache
         if ($cacheTime > 0) {
             $navFooter = Cache::getCache('navFooter', $template->getFooterLevel(), $cacheTime);
             if (isset($navFooter)) {
                 $isMenuCached = true;
             }
         }
         if (!$isMenuCached) {
             $navFooter = \Rebond\Cms\Page\Data::buildFooterNav($template->getFooterLevel());
             // Save cache
             if ($cacheTime > 0) {
                 Cache::saveCache('navFooter', $template->getFooterLevel(), $cacheTime, $navFooter);
             }
         }
         $tpl = new Template(Template::SITE, ['www']);
         $tpl->set('nav', \Rebond\Cms\Page\Service::renderNav($navFooter, $page->getFullUrl()));
         $tplMaster->set('navFooter', $tpl->render('nav-footer'));
     }
     $tplMaster->set('layout', $tplLayout->render($layout->getFilename()));
     // master
     // head
     if ($app->site()->getKeywords() != '') {
         $tplMaster->addMeta('keywords', $app->site()->getKeywords());
     }
     if ($app->site()->getDescription() != '') {
         $tplMaster->addMeta('description', $app->site()->getDescription());
     }
     $tplMaster->set('title', $page->getTitle());
     $tplMaster->set('site', $app->site()->getTitle());
     $tplMaster->set('skin', $app->skin());
     $tplMaster->set('siteUrl', \Rebond\Config::getPath('siteUrl'));
     // bodyClass
     $tplMaster->set('bodyClass', $page->getClass());
     // footer
     $ga = \Rebond\Core\Site\Service::renderGoogleAnalytics($app->site()->getGoogleAnalytics());
     $tplMaster->set('footer', $ga);
     $tplMaster->addJs('//code.jquery.com/jquery-2.1.4.min.js');
     $tplMaster->addJs('/js/lang-' . $app->lang() . '.js');
     if ($app->site()->getJs() != '') {
         $jsList = explode(',', $app->site()->getJs());
         foreach ($jsList as $js) {
             $tplMaster->addJs($js);
         }
     }
     if ($page->getJs() != '') {
         $jsList = explode(',', $page->getJs());
         foreach ($jsList as $js) {
             $tplMaster->addJs($js);
         }
     }
     if ($app->env() == \Rebond\Config::ENV_PROD) {
         $tplMaster->addCss('/css/skin/' . $app->skin() . '/min.css');
         $tplMaster->addJs('/js/min.js');
     } else {
         $tplMaster->addCss('/css/normalize.css');
         $tplMaster->addCss('/css/skin/' . $app->skin() . '/rebond.css');
         $tplMaster->addCss('/css/skin/' . $app->skin() . '/custom.css');
         $tplMaster->addJs('/js/rebond.js');
         $tplMaster->addJs('/js/custom.js');
     }
     if ($app->site()->getCss() != '') {
         $cssList = explode(',', $app->site()->getCss());
         foreach ($cssList as $css) {
             $tplMaster->addCss($css);
         }
     }
     if ($page->getCss() != '') {
         $cssList = explode(',', $page->getCss());
         foreach ($cssList as $css) {
             $tplMaster->addCss($css);
         }
     }
     return $tplMaster->render($template->getFilename());
 }