public function getPage($createIfNotExist = false) { if (!isset($this->page)) { $this->page = \Rebond\Cms\Page\Data::loadById($this->pageId, $createIfNotExist); } return $this->page; }
public static function readCmsRequest($uri = '') { if (stripos($uri, '?') !== false) { $uri = strstr($uri, '?', true); } $request = explode('/', $uri, 2); $action = count($request) >= 2 && $request[1] != '' ? $request[1] : null; if (!isset($action)) { $page = \Rebond\Cms\Page\Data::loadById(1); if (!isset($page)) { Error::kill(Error::PAGE_NOT_FOUND, 'id: 1', __FILE__, __LINE__); } $action = $page->getFriendlyUrl(); } // return cleaned friendly url return '/' . rtrim(strtolower($action), '/'); }
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'); }
public static function renderBreadcrumb($pageId) { $render = false; $html = ''; $title = Util\Converter::string('title'); if (isset($title)) { $html = '<li class="active">' . $title . '</li>'; } while ($pageId != 0) { $page = Data::loadById($pageId); $pageId = $page->getParentId(); if (!$page->getInBreadcrumb()) { continue; } if ($html == '') { $html = '<li class="active">' . $page->getTitle() . '</li>' . $html; } else { if ($page->getRedirect() != '') { $isLink = 1; } else { $options = []; $options['where'][] = ['gadget.page_id = ?', $page->getId()]; $options['where'][] = 'gadget.status = 1'; $isLink = \Rebond\Cms\Gadget\Data::count($options); } if ($isLink > 0) { $render = true; $html = '<li><a href="' . $page->getFullUrl() . '">' . $page->getTitle() . '</a></li>' . $html; } else { $render = true; $html = '<li><span>' . $page->getTitle() . '</span></li>' . $html; } } } if ($render) { return '<ul id="r-breadcrumb">' . $html . '</ul>'; } return ''; }
public function updatePage() { if (!$this->hasPrivilege('admin.page.edit')) { return $this->noPrivilege('admin.page.edit'); } $json = []; $json['result'] = ResultType::ERROR; // check $id = Converter::int('id', 'post'); $pid = Converter::int('pid', 'post', 1); if (!isset($id)) { $json['message'] = Lang::lang('errorInvalidParameters'); return json_encode($json); } // Check item $page = \Rebond\Cms\Page\Data::loadById($id); if (!isset($page)) { $json['message'] = 'invalid page of id: ' . $id; return json_encode($json); } // Save item $page->setParentId($pid); $fuh = \Rebond\Cms\Page\Data::fullFriendlyUrl($pid); $page->setFriendlyUrlPath($fuh); $isSaved = $page->save(); if ($isSaved == ResultType::ERROR) { $json['message'] = 'an error occured'; return json_encode($json); } else { if ($isSaved == ResultType::NO_CHANGE) { $json['result'] = ResultType::SUCCESS; $json['message'] = 'no change'; return json_encode($json); } } // Update children \Rebond\Cms\Page\Data::updateChildrenFriendlyUrl($page->getId(), $page->getFriendlyUrlPath(), $page->getFriendlyUrl()); // Success $json['result'] = ResultType::SUCCESS; $json['message'] = 'page saved'; return json_encode($json); }