Example #1
0
 /**
  * Stores content as view script in cache and renders it
  * 
  * @param Cms_Model_Page $page
  */
 protected function _renderPageAsView(Cms_Model_Page $page)
 {
     $cacheId = HCMS_Controller_Action_Cms_Page::CMS_PAGE_CACHE_PRE . $page->get_id();
     $resources = Zend_Controller_Front::getInstance()->getParam("bootstrap")->getOption('resources');
     $cacheDir = $resources['cachemanager']['core']['backend']['options']['cache_dir'];
     $cacheFileName = 'zend_cache---' . $cacheId;
     // Create Zend_Cache_Core object
     $cache = HCMS_Cache::getInstance()->getCoreCache();
     // If no cache available for this content page
     if (!$cache->test($cacheId)) {
         $cache->save((string) $page->get_content(), $cacheId);
         //forcing raw string :(
         file_put_contents($cacheDir . "/" . $cacheFileName, $page->get_content());
     }
     $this->view->addScriptPath($cacheDir);
     return $this->view->render($cacheFileName);
 }
Example #2
0
 /**
  * Enable inline wysiwyg editor in front
  * 
  * @param string $content
  * @param Cms_Model_Page $page 
  */
 public function renderEditable($content, Cms_Model_Page $page)
 {
     if (!self::$enabled) {
         return $content;
     }
     //only for html format
     if ($page->get_format() != 'html') {
         return $content;
     }
     //more check TODO
     return '<div class="editable" data-id="' . $page->get_id() . '">' . $content . '</div>';
 }
Example #3
0
 /**
  * Populate feed entry data
  * 
  * @param Cms_Model_Page $page
  * @param Zend_Feed_Entry_Abstract $entry
  */
 protected function _populateFeedEntry(Cms_Model_Page $page, Zend_Feed_Writer_Entry $entry)
 {
     $entry->setTitle($page->get_title());
     $entry->setLink($this->view->serverUrl() . $this->view->url(array('module' => $this->getRequest()->getModuleName(), 'controller' => $this->getRequest()->getControllerName(), 'action' => 'index', 'url_id' => $page->get_url_id()), 'cms'));
     if (null != $page->get_user_name() && '' != $page->get_user_name()) {
         $entry->addAuthor(array('name' => $page->get_user_name()));
     }
     $entry->setDateModified(new Zend_Date($page->get_posted(), Zend_Date::ISO_8601));
     if (null != $page->get_teaser() && '' != $page->get_teaser()) {
         $entry->setDescription($page->get_teaser());
     }
     $entry->setContent($this->_fixRelImagePaths($page->get_content()));
 }
 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();
 }
 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();
 }
Example #6
0
 /**
  * Check if the page is in use in menus, routes...
  *
  * @param Cms_Model_Page $page
  * @return boolean
  */
 public function isInUse(Cms_Model_Page $page)
 {
     //check menu items
     $select = $this->_dbTable->select();
     $select->setIntegrityCheck(false)->from(array('mi' => 'cms_menu_item'), array('mi.id'))->where('mi.page_id = ?', $page->get_id());
     //echo $select->__toString();die();
     $resultSet = $this->_dbTable->fetchAll($select);
     if (count($resultSet)) {
         return true;
     }
     //check routes
     $select = $this->_dbTable->select();
     $select->setIntegrityCheck(false)->from(array('r' => 'cms_route'), array('r.id'))->where('r.page_id = ?', $page->get_id());
     //echo $select->__toString(); die();
     $resultSet = $this->_dbTable->fetchAll($select);
     if (count($resultSet)) {
         return true;
     }
     return false;
 }