public function edit() { // auth Auth::isAdminAuthorized($this->signedUser, 'admin.page', true, '/page'); // check $id = Converter::int('id'); $pid = Converter::int('pid', 'get', 1); $page = \Rebond\Cms\Page\Data::loadById($id); if (!isset($page)) { $page = new \Rebond\Cms\Page\Model(); $title = Lang::lang('newPage'); } else { $title = Lang::lang('edit') . ' ' . $page->getTitle(); } if ($page->getId() != 1 && $page->getParentId() == 1) { $page->setParentId($pid); } $form = new \Rebond\Cms\Page\Form($page); // action $save = Converter::string('save', 'post'); if (isset($save)) { Auth::isAdminAuthorized($this->signedUser, 'admin.page.edit', true, '/page'); if ($form->setFromPost()->validate()->isValid()) { // set new friendly url hidden $page->setFriendlyUrl(strtolower($page->getFriendlyUrl())); $fuh = \Rebond\Cms\Page\Data::fullFriendlyUrl($page->getParentId()); $page->setFriendlyUrlPath($fuh); $page->save(); // update children pages \Rebond\Cms\Page\Data::updateChildrenFriendlyUrl($page->getId(), $page->getFriendlyUrlPath(), $page->getFriendlyUrl()); Session::adminSuccess('saved', '/page'); } else { Session::set('adminError', $form->getValidation()->getMessage()); } } // view $this->setTpl(); // main $tplMain = new Template(Template::MODULE, ['cms', 'page']); $tplMain->set('title', $title); $tplMain->set('siteUrl', 'http://' . \Rebond\Config::getPath('siteUrl')); $tplMain->set('item', $form); // layout if (Auth::isAdminAuthorized($this->signedUser, 'admin.page.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')); $this->tplMaster->set('jsLauncher', 'page'); return $this->tplMaster->render('tpl-default'); }
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); }