예제 #1
0
 public function getAction()
 {
     // at first we will try to find content by id
     if (($containerId = intval(filter_var($this->_request->getParam('id'), FILTER_SANITIZE_NUMBER_INT))) == 0) {
         $containerId = filter_var($this->_request->getParam('name'), FILTER_SANITIZE_STRING);
     }
     $pageId = $this->_request->getParam('pid', null);
     // return only content for the containers
     $contentOnly = $this->_request->getParam('co', false);
     $mapper = Application_Model_Mappers_ContainerMapper::getInstance();
     $parser = new Tools_Content_Parser(null, array(), array('websiteUrl' => Zend_Controller_Action_HelperBroker::getStaticHelper('website')->getUrl()));
     // querying all containers
     if (!$containerId) {
         $containers = $mapper->fetchAll();
         if (empty($containers)) {
             return $this->_error('404 Containers not found.', self::REST_STATUS_NOT_FOUND);
         }
         return array_map(function ($container) use($contentOnly, $parser, $pageId) {
             $container = $container->toArray();
             $page = $pageId ? Application_Model_Mappers_PageMapper::getInstance()->find($pageId) : null;
             $parser->setPageData($page instanceof Application_Model_Models_Page ? $page->toArray() : array());
             $container['content'] = $parser->setContent($container['content'])->parseSimple();
             return $contentOnly ? array($container['name'] => $container['content']) : $container;
         }, $containers);
     }
     $type = $this->_request->getParam('type', Application_Model_Models_Container::TYPE_REGULARCONTENT);
     $pageId = $this->_request->getParam('pid', null);
     if ((int) $type == Application_Model_Models_Container::TYPE_STATICCONTENT) {
         $pageId = null;
     }
     $container = is_integer($containerId) ? $mapper->find($containerId) : $mapper->findByName($containerId, $pageId, $type);
     $pageId = $this->_request->getParam('pid', null);
     if (!$container instanceof Application_Model_Models_Container) {
         $container = new Application_Model_Models_Container(array('containerType' => $type, 'name' => $containerId));
     } else {
         if (!$pageId) {
             $pageId = $container->getPageId();
         }
         $page = $pageId ? Application_Model_Mappers_PageMapper::getInstance()->find($pageId) : null;
         $parser->setPageData($page instanceof Application_Model_Models_Page ? $page->toArray() : array())->setContent($container->getContent());
         $container->setContent($parser->parseSimple());
     }
     return $contentOnly ? array($container->getName() => $container->getContent()) : $container->toArray();
 }
예제 #2
0
 private function _processContent()
 {
     if ($this->_contentForm->isValid($this->getRequest()->getParams())) {
         $containerData = $this->_contentForm->getValues();
         $pageId = $containerData['containerType'] == Application_Model_Models_Container::TYPE_STATICCONTENT || $containerData['containerType'] == Application_Model_Models_Container::TYPE_STATICHEADER || $containerData['containerType'] == Application_Model_Models_Container::TYPE_PREPOPSTATIC ? null : $containerData['pageId'];
         $containerId = $containerData['containerId'] ? $containerData['containerId'] : null;
         $container = new Application_Model_Models_Container();
         $container->registerObserver(new Tools_Seo_Watchdog());
         $container->registerObserver(new Tools_Search_Watchdog());
         $container->registerObserver(new Tools_Content_GarbageCollector(array('action' => Tools_System_GarbageCollector::CLEAN_ONUPDATE)));
         $container->setId($containerId)->setName($containerData['containerName'])->setContainerType($containerData['containerType'])->setPageId($pageId)->setContent($containerData['content']);
         $published = $container->getContainerType() == Application_Model_Models_Container::TYPE_REGULARCONTENT || $container->getContainerType() == Application_Model_Models_Container::TYPE_STATICCONTENT ? $this->getRequest()->getParam('published') : true;
         $container->setPublished($published);
         if (!$published) {
             $publishOn = $this->getRequest()->getParam('publishOn');
             if ($publishOn) {
                 $container->setPublishingDate($publishOn);
             }
         } else {
             $container->setPublishingDate('');
         }
         $cacheTag = preg_replace('/[^\\w\\d_]/', '', $container->getName() . '_' . $container->getContainerType() . '_pid_' . $container->getPageId());
         $this->_helper->cache->clean(null, null, array($cacheTag));
         $saveResult = Application_Model_Mappers_ContainerMapper::getInstance()->save($container);
         if (!$container->getId()) {
             $container->setId($saveResult);
         }
         try {
             $container->notifyObservers();
         } catch (Exceptions_SeotoasterWidgetException $twe) {
             $this->_helper->response->fail($twe->getMessage());
         }
         $this->_helper->response->success($saveResult);
         exit;
     }
     return false;
 }