public function _cleanEmptyContainer()
 {
     if (!$this->_object->getContent()) {
         $this->_object->removeObserver($this);
         Application_Model_Mappers_ContainerMapper::getInstance()->delete($this->_object);
     }
 }
Beispiel #2
0
 public static function addPageToIndex($page, $toasterSearchIndex = false)
 {
     if (!self::initIndex()) {
         return false;
     }
     if ($page instanceof Application_Model_Models_Page) {
         $page = $page->toArray();
         $containers = Application_Model_Mappers_ContainerMapper::getInstance()->findByPageId($page['id']);
         $page['content'] = '';
         if (!empty($containers)) {
             foreach ($containers as $container) {
                 $page['content'] .= $container->getContent();
             }
         }
     }
     $document = new Zend_Search_Lucene_Document();
     $document->addField(Zend_Search_Lucene_Field::keyword('pageId', $page['id']));
     $document->addField(Zend_Search_Lucene_Field::unStored('metaKeyWords', $page['metaKeywords'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::unStored('metaDescription', $page['metaDescription'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::unStored('headerTitle', $page['headerTitle'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::unStored('content', $page['content'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::text('draft', $page['draft'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::text('teaserText', $page['teaserText'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::text('url', $page['url'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::text('navName', $page['navName'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::text('h1', $page['h1'], 'UTF-8'));
     //		$document->addField(Zend_Search_Lucene_Field::text('previewImage', $page['previewImage']));
     self::$_index->addDocument($document);
 }
 private function _removeRelatedContainers()
 {
     $containerMapper = Application_Model_Mappers_ContainerMapper::getInstance();
     $containers = $containerMapper->findByPageId($this->_object->getId());
     if (!empty($containers)) {
         foreach ($containers as $container) {
             $containerMapper->delete($container);
         }
     }
 }
Beispiel #4
0
 /**
  * Checks if content published
  *
  * @return bool true if published
  */
 private function _checkPublished()
 {
     if ($this->_container === null) {
         return true;
     }
     if (!$this->_container->getPublished()) {
         if ($this->_container->getPublishingDate()) {
             $zDate = new Zend_Date();
             $result = $zDate->compare(strtotime($this->_container->getPublishingDate()));
             if ($result == 0 || $result == 1) {
                 $this->_container->setPublishingDate('')->setPublished(true);
                 Application_Model_Mappers_ContainerMapper::getInstance()->save($this->_container);
             }
         }
     }
     return (bool) $this->_container->getPublished();
 }
Beispiel #5
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();
 }
Beispiel #6
0
 protected function _load()
 {
     if (!isset($this->_options[0])) {
         throw new Exceptions_SeotoasterWidgetException('Not enough parameters for the widget <strong>prepop</strong>.');
     }
     $prepop = Application_Model_Mappers_ContainerMapper::getInstance()->findByName($this->_name, $this->_pageId, $this->_type);
     if ($prepop) {
         $this->_prepopContent = $prepop->getContent();
         $this->_prepopContainerId = $prepop->getId();
     }
     // User role should be a member or not only for reading at least to be able to edit
     if (!Tools_Security_Acl::isAllowed(Tools_Security_Acl::RESOURCE_CONTENT) || $this->_readonly) {
         if ($this->_options[0] == self::TYPE_CHECKBOX) {
             $translator = $this->_translator;
             $this->_prepopContent = implode('&nbsp;', array_map(function ($option) use($translator) {
                 return $translator->translate(ucfirst($option));
             }, array_filter(explode('~', $this->_prepopContent))));
         }
         if (array_search(self::OPTION_LINKS, $this->_options)) {
             $this->_view->prepopName = $this->_prepopName;
             $this->_view->prepopContent = $this->_prepopContent;
             return $this->_view->render('prepopLink.phtml');
         } elseif ($this->_readonly) {
             return $this->_prepopContent;
         } else {
             return '<span class="prepop-content" id="prepop-' . $this->_prepopName . '">' . $this->_prepopContent . '</span>';
         }
     }
     if (array_search(self::OPTION_LINKS, $this->_options)) {
         $optionKey = array_search(self::OPTION_LINKS, $this->_options);
         $this->_options[$optionKey] = '';
     }
     //assign common view vars for the prepop
     $this->_view->prepopContent = $this->_prepopContent;
     $this->_view->prepopConainerId = $this->_prepopContainerId;
     $this->_view->elementType = $this->_options[0];
     $rendererName = '_renderPrepop' . ucfirst(array_shift($this->_options));
     if (method_exists($this, $rendererName)) {
         return $this->{$rendererName}();
     }
     throw new Exceptions_SeotoasterWidgetException($this->_translator->translate('Wrong prepop type'));
 }
 private function _removeDeeplinkOccurrences()
 {
     if (!$this->_object instanceof Application_Model_Models_Deeplink) {
         throw new Exceptions_SeotoasterException('Wrong object given. Instance of Application_Model_Models_Deeplink expected.');
     }
     $websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Website');
     $linksContainerMap = Application_Model_Mappers_LinkContainerMapper::getInstance()->findByLink($this->_object->getType() == Application_Model_Models_Deeplink::TYPE_INTERNAL ? $websiteHelper->getUrl() . $this->_object->getUrl() : $this->_object->getUrl());
     if (!empty($linksContainerMap)) {
         $containerMapper = Application_Model_Mappers_ContainerMapper::getInstance();
         foreach ($linksContainerMap as $item) {
             $container = $containerMapper->find($item['id_container']);
             $container->registerObserver(new Tools_Content_GarbageCollector(array('action' => Tools_System_GarbageCollector::CLEAN_ONUPDATE)));
             //$deeplinkRemovalPattern = '~<a\s+.*\s+(title=".+")*\s*.*\s+href="' . $item['link'] . '"\s*(title=".*")*\s*>' . $this->_object->getName() . '</a>~usU';
             $deeplinkRemovalPattern = '~<a(\\s+|[^\\>]+\\s+)href="' . $item['link'] . '"\\s*[^\\>]*>' . $this->_object->getName() . '</a>~usU';
             if (preg_match($deeplinkRemovalPattern, $container->getContent(), $matches)) {
                 $containerMapper->save($container->setContent(str_replace($matches[0], $this->_object->getName(), $container->getContent())));
                 $container->notifyObservers();
             }
         }
     }
 }
Beispiel #8
0
 protected function _load()
 {
     if (!$this->_checkEnabled()) {
         return '';
     }
     if (!is_array($this->_options) || empty($this->_options) || !isset($this->_options[0]) || !$this->_options[0] || preg_match('~^\\s*$~', $this->_options[0])) {
         throw new Exceptions_SeotoasterException($this->_translator->translate('You should specify code container name.'));
     }
     $this->_container = Application_Model_Mappers_ContainerMapper::getInstance()->findByName($this->_name, $this->_pageId, $this->_type);
     $codeContent = null === $this->_container ? '' : $this->_container->getContent();
     if (!preg_match('~<script~', $codeContent)) {
         ob_start();
         $returned = eval($codeContent);
         $codeContent = ob_get_clean();
         ob_get_flush();
         $codeContent .= $returned;
     }
     if (Tools_Security_Acl::isAllowed($this)) {
         $codeContent .= $this->_generateAdminControl(964, 594);
     }
     return $codeContent;
 }
Beispiel #9
0
 public static function applyDeeplinkPerPage(Application_Model_Models_Deeplink $deeplink, Application_Model_Models_Page $page)
 {
     $containerMapper = Application_Model_Mappers_ContainerMapper::getInstance();
     //$containers      = $containerMapper->findByPageId($page->getId());
     $containers = $containerMapper->findContentContainersByPageId($page->getId());
     if (!empty($containers)) {
         foreach ($containers as $container) {
             $initialContentLength = strlen($container->getContent());
             if (Zend_Registry::isRegistered('applied') && Zend_Registry::get('applied') === true) {
                 Zend_Registry::set('applied', false);
                 return;
             }
             $container->setContent(self::applyDeeplink($deeplink, $container->getContent()));
             $container->registerObserver(new Tools_Seo_Watchdog(array('unwatch' => '_updateDeeplinks')));
             $gc = new Tools_Content_GarbageCollector(array('model' => $container));
             $gc->updateContentLinksRelatios();
             if ($initialContentLength != strlen($container->getContent())) {
                 $containerMapper->save($container);
                 $container->notifyObservers();
             }
         }
     }
 }
 private function _removePluginOccurences()
 {
     $pattern = '~{\\$plugin:' . $this->_object->getName() . '[^{}]*}~usU';
     //removing plugin occurences from content
     $containerMapper = Application_Model_Mappers_ContainerMapper::getInstance();
     $containers = $containerMapper->fetchAll();
     if (!empty($containers)) {
         array_walk($containers, function ($container, $key, $data) {
             $container->setContent(preg_replace($data['pattern'], '', $container->getContent()));
             $data['mapper']->save($container);
         }, array('pattern' => $pattern, 'mapper' => $containerMapper));
     }
     unset($containers);
     //removing plugin occurences from the templates
     $templateMapper = Application_Model_Mappers_TemplateMapper::getInstance();
     $templates = $templateMapper->fetchAll();
     if (!empty($templates)) {
         array_walk($templates, function ($template, $key, $data) {
             $template->setContent(preg_replace($data['pattern'], '', $template->getContent()));
             $data['mapper']->save($template);
         }, array('pattern' => $pattern, 'mapper' => $templateMapper));
     }
     unset($templates);
 }
Beispiel #11
0
 private function _renderSearchAdvanced()
 {
     $this->_cachePrefix .= 'advanced_';
     if (is_array($this->_options) && !empty($this->_options)) {
         $prepopWithQuantity = array();
         $prepopLabels = array();
         $prepopNames = explode('|', $this->_options[0]);
         foreach ($prepopNames as $key => $prepopName) {
             if (mb_strpos($prepopName, '(#)') !== false) {
                 $prepopWithQuantity[] = str_replace('(#)', '', $prepopName);
                 $prepopNames[$key] = str_replace('(#)', '', $prepopName);
             }
         }
         if (isset($this->_options[1]) && mb_strpos($this->_options[1], '|') !== false) {
             $prepopLabels = explode('|', $this->_options[1]);
         }
         if (count($prepopNames) == count($prepopLabels)) {
             $prepopLabels = array_combine($prepopNames, $prepopLabels);
         }
         if (end($this->_options) === 'select') {
             $cacheKey = str_replace('(#)', 'N', $this->_options[0]);
             if (null === ($prepopSearchData = $this->_cache->load($cacheKey, $this->_cachePrefix))) {
                 $prepopWithNameList = Application_Model_Mappers_ContainerMapper::getInstance()->findByContainerNames($prepopNames);
                 if (!empty($prepopWithNameList)) {
                     foreach ($prepopWithNameList as $prepopWithName) {
                         //adding cache tags
                         array_push($this->_cacheTags, $prepopWithName['name'] . '_' . $prepopWithName['container_type'] . '_pid_' . $prepopWithName['page_id']);
                         $searchArray[$prepopWithName['page_id']][$prepopWithName['name']] = $prepopWithName['content'];
                         $prepopNamePageIds[$prepopWithName['name']][$prepopWithName['content']][$prepopWithName['page_id']] = $prepopWithName['page_id'];
                         $prepopNameValues[$prepopWithName['name']][$prepopWithName['content']]['content'] = $prepopWithName['content'];
                         if (isset($prepopNameValues[$prepopWithName['name']][$prepopWithName['content']]['content']) && $prepopNameValues[$prepopWithName['name']][$prepopWithName['content']]['content'] == $prepopWithName['content']) {
                             if (!isset($prepopNameValues[$prepopWithName['name']][$prepopWithName['content']]['quantity'])) {
                                 $prepopNameValues[$prepopWithName['name']][$prepopWithName['content']]['quantity'] = 0;
                             }
                             $prepopNameValues[$prepopWithName['name']][$prepopWithName['content']]['quantity'] += 1;
                         }
                     }
                 }
                 $prepopSearchData = array('searchArray' => $searchArray, 'prepopNamePageIds' => $prepopNamePageIds, 'prepopNameValues' => $prepopNameValues);
                 //saving to cache
                 $this->_cache->save($cacheKey, $prepopSearchData, $this->_cachePrefix, array_unique($this->_cacheTags), Helpers_Action_Cache::CACHE_NORMAL);
             }
             $this->_view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');
             $this->_view->prepopNames = $prepopNames;
             $this->_view->prepopLabels = $prepopLabels;
             $this->_view->websiteUrl = $this->_toasterOptions['websiteUrl'];
             $this->_view->searchArray = json_encode($prepopSearchData['searchArray']);
             $this->_view->prepopNamePageIds = json_encode($prepopSearchData['prepopNamePageIds']);
             $this->_view->prepopWithQuantity = $prepopWithQuantity;
             $this->_view->prepopNameValues = array_reverse($prepopSearchData['prepopNameValues']);
             return $this->_view->render('advancedPrepopSearch.phtml');
         }
     }
 }
Beispiel #12
0
 private function _updateLinksTitles()
 {
     if ($this->_object instanceof Application_Model_Models_Container) {
         $websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Website');
         $links = array_unique(Tools_Content_Tools::findLinksInContent($this->_object->getContent(), true, Tools_Content_Tools::PATTERN_LINKWITHOUTTITLE));
         if (!empty($links)) {
             $pageMapper = Application_Model_Mappers_PageMapper::getInstance();
             $containerMapper = Application_Model_Mappers_ContainerMapper::getInstance();
             foreach ($links as $link) {
                 $page = $pageMapper->findByUrl(str_replace($websiteHelper->getUrl(), '', $link));
                 if ($page === null) {
                     continue;
                 }
                 $h1 = $page->getH1();
                 unset($page);
                 $withoutTitleUrlPattern = '~(<a\\s+[^\\s]*\\s*href="' . $link . ')("\\s*)(>.+</a>)~uUs';
                 $this->_object->setContent(preg_replace($withoutTitleUrlPattern, '$1$2 title="' . $h1 . '" $3', $this->_object->getContent()));
                 $containerMapper->save($this->_object);
             }
         }
     }
 }
 /**
  * Checks if file/image is linked in any content and return list of pages where it used
  * @param string $filename Name of file
  * @return array List of pages where file linked
  */
 private function _checkFileInContent($filename)
 {
     $containers = Application_Model_Mappers_ContainerMapper::getInstance()->findByContent($filename);
     // formatting list of pages where image used in
     $usedOnPages = array();
     if (!empty($containers)) {
         foreach ($containers as $container) {
             $page = Application_Model_Mappers_PageMapper::getInstance()->find($container->getPageId());
             if ($page !== null && !in_array($page->getUrl(), $usedOnPages)) {
                 array_push($usedOnPages, $page->getUrl());
             }
         }
     }
     return $usedOnPages;
 }
 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;
 }