private function _updateContentLinksRelatios() { if (!$this->_object instanceof Application_Model_Models_Container) { throw new Exceptions_SeotoasterException('Wrong object given. Instance of Application_Model_Models_Container expected.'); } $links = array(); $mapper = Application_Model_Mappers_LinkContainerMapper::getInstance(); $links[$this->_object->getId()] = Tools_Content_Tools::findLinksInContent($this->_object->getContent(), true); $containerId = $this->_object->getId(); $containerLinks = $mapper->fetchStructured($containerId); if (is_array($containerLinks) && isset($containerLinks[$containerId])) { $diff = array_diff($containerLinks[$containerId], $links[$containerId]); $mapper->delete($containerId, $diff); } return $mapper->saveStructured($links); }
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(); } } } }
/** * @todo improve/ optimize? */ private function _removePageUrlFromContent() { $websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Website'); $websiteUrl = $websiteHelper->getUrl(); unset($websiteHelper); $data = Application_Model_Mappers_LinkContainerMapper::getInstance()->findByLink($websiteUrl . $this->_object->getUrl()); if (is_array($data) && !empty($data)) { $containerMapper = Application_Model_Mappers_ContainerMapper::getInstance(); foreach ($data as $containerData) { $container = $containerMapper->find($containerData['id_container']); $container->registerObserver(new Tools_Content_GarbageCollector(array('action' => Tools_System_GarbageCollector::CLEAN_ONUPDATE))); if (!$container instanceof Application_Model_Models_Container) { continue; } $urlPattern = '~<a\\s+.*\\s*href="' . $containerData['link'] . '"\\s*.*\\s*>.*</a>~uUs'; $content = preg_replace($urlPattern, '', $container->getContent()); $container->setContent($content); $containerMapper->save($container); $container->notifyObservers(); } } }
private function _updateContainersUrls() { if (!$this->_object instanceof Application_Model_Models_Page) { throw new Exceptions_SeotoasterException('Wrong object given. Instance of Application_Model_Models_Page expected.'); } $sessionHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Session'); $websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Website'); if (!isset($sessionHelper->oldPageUrl) || !$sessionHelper->oldPageUrl) { return null; } $fullOldUrl = $websiteHelper->getUrl() . $sessionHelper->oldPageUrl; $containersToUpdate = Application_Model_Mappers_LinkContainerMapper::getInstance()->findByLink($fullOldUrl); if (!empty($containersToUpdate)) { $mapper = Application_Model_Mappers_ContainerMapper::getInstance(); foreach ($containersToUpdate as $containerData) { $container = $mapper->find($containerData['id_container']); $links = Tools_Content_Tools::findLinksInContent($container->getContent(), true); $container->registerObserver(new Tools_Content_GarbageCollector(array('action' => Tools_System_GarbageCollector::CLEAN_ONUPDATE))); if (in_array($fullOldUrl, $links)) { $fullNewUrl = $websiteHelper->getUrl() . $this->_object->getUrl(); $withoutTitleUrlPattern = '~(<a\\s+[^\\s]*\\s*href=")(' . $fullOldUrl . ')("\\s*)(>.+</a>)~u'; $container->setContent(preg_replace($withoutTitleUrlPattern, '$1' . $fullNewUrl . '$3 title="' . $this->_object->getH1() . '" $4', $container->getContent())); $container->setContent(str_replace('title="' . $sessionHelper->oldPageH1 . '"', 'title="' . $this->_object->getH1() . '"', $container->getContent())); $container->setContent(str_replace($fullOldUrl, $fullNewUrl, $container->getContent())); $mapper->save($container); $container->notifyObservers(); } } } unset($sessionHelper->oldPageH1); }