Ejemplo n.º 1
0
 protected function savePage($row)
 {
     $titles = explode("\n", $this->data[$row]['Name']);
     if (isset($this->data[$row]['Meta Keywords'])) {
         $metaKeywords = explode("\n", $this->data[$row]['Meta Keywords']);
     }
     if (isset($this->data[$row]['Meta Description'])) {
         $metaDescriptions = explode("\n", $this->data[$row]['Meta Description']);
     }
     $page = new Cms_Model_Page();
     $page->set_application_id(1)->set_format('html')->set_status('published')->set_type_id(1)->set_user_id(1)->set_posted(HCMS_Utils_Time::timeTs2Mysql(time()));
     foreach ($this->languages as $langIndex => $lang) {
         $curRow = $row;
         $title = $this->getLangText($titles, $langIndex);
         if (isset($metaKeywords)) {
             $metaKeyword = $this->getMetaKeywords($metaKeywords, $langIndex);
         }
         if (isset($metaDescriptions)) {
             $metaDescription = $this->getMetaDescription($metaDescriptions, $langIndex);
         }
         $urlIdParts = array();
         while (isset($this->data[$curRow])) {
             $currTitles = explode("\n", $this->data[$curRow]['Name']);
             if (isset($metaKeyword) && isset($metaDescription)) {
                 $meta = array("keywords" => $metaKeyword, "description" => $metaDescription);
             } else {
                 $meta = array("keywords" => "", "description" => "");
             }
             if (isset($currTitles[$langIndex])) {
                 $urlIdParts[] = $this->seoFilter->filter($currTitles[$langIndex]);
             }
             if (!isset($this->data[$curRow]['parent'])) {
                 break;
             }
             $curRow = $this->data[$curRow]['parent'];
         }
         $urlIdParts = array_reverse($urlIdParts);
         $urlId = implode('-', $urlIdParts);
         $page->set_code('')->set_url_id($urlId)->set_content('<h1>' . $title . '</h1>')->set_title($title)->set_meta($meta);
         if (Cms_Model_PageMapper::getInstance()->findByUrlId($urlId, 1, $page)) {
             continue;
         }
         Cms_Model_PageMapper::getInstance()->save($page, $lang);
     }
     $this->data[$row]['page_id'] = $page->get_id();
 }
Ejemplo n.º 2
0
 public function pageEditAction()
 {
     $data = $this->getRequest()->getPost('data');
     $submit = $this->getRequest()->getPost('submit');
     $id = $this->_getParam('id');
     $typeId = $this->_getParam('type_id');
     $langFilter = $this->_getParam('langFilter');
     //check if cancel button is pressed
     if ($this->_formHelper->isCancel()) {
         //cancel form
         return $this->_formHelper->returnCancel($this->view->url(array('action' => 'page')), $this->translate('Action canceled'));
     }
     //create form object
     $form = new Cms_Form_Page($data, null, $langFilter);
     //postback - save?
     if ($this->_formHelper->isSave()) {
         //check if valid
         if ($form->isValid()) {
             $values = $form->getValues();
             //create entity object from submitted values, and save
             $page = new Cms_Model_Page($values);
             //new entity
             if (!isset($data['id']) || $data['id'] <= 0) {
                 $page->set_application_id($this->_applicationId)->set_user_id($this->_admin->get_id())->set_posted(HCMS_Utils_Time::timeTs2Mysql(time()));
             } else {
                 $existingPage = new Cms_Model_Page();
                 if (!Cms_Model_PageMapper::getInstance()->find($data['id'], $existingPage)) {
                     throw new Exception("Page not found");
                 }
                 if ((int) $existingPage->get_application_id() != $this->_applicationId) {
                     throw new Exception("Cannot edit this Page.");
                 }
             }
             Cms_Model_PageMapper::getInstance()->save($page, $langFilter);
             //save categories
             if (isset($data['categories'])) {
                 Cms_Model_PageMapper::getInstance()->saveCategories($page, $data['categories']);
             }
             //save done, return success
             return $this->_formHelper->returnSuccess($this->view->url(array('action' => 'page')), $this->translate('Page saved.'));
         } else {
             //we have errors - return json or continue
             $this->_formHelper->returnError($form->getMessages());
         }
     } elseif (!$this->_formHelper->getRequest()->isPost()) {
         //edit action
         if (isset($id) && $id > 0) {
             $page = new Cms_Model_Page();
             if (!Cms_Model_PageMapper::getInstance()->find($id, $page, $langFilter)) {
                 throw new Exception("Page not found");
             }
             //fetch data
             $data = $page->toArray();
             //populate form with data
             $form->setData($data);
         } else {
             $this->view->typeId = $typeId;
         }
     }
     $this->view->data = $data;
     $this->view->types = Cms_Model_PageTypeMapper::getInstance()->fetchAll();
     //custom elements
     $pageTypes = $this->_application->get_settings("page_types");
     $typeId = $this->_getParam('type_id') ? $this->_getParam('type_id') : $page->get_type_id();
     $this->view->customElements = isset($pageTypes) && isset($pageTypes[$typeId]['custom_elements']) ? $pageTypes[$typeId]['custom_elements'] : array();
 }