public static function runPageRankSculpting($siloId, $pageContent) { self::$_websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('website'); $silo = Application_Model_Mappers_SiloMapper::getInstance()->find($siloId); $sculptingReplacement = array(); $links = Tools_Content_Tools::findLinksInContent($pageContent); if (empty($links) || !isset($links[1])) { return $pageContent; } $hrefs = array_combine($links[0], $links[1]); $siloedPagesUrls = array_merge(array(self::$_websiteHelper->getUrl() . 'index.html', self::$_websiteHelper->getUrl() . 'index.htm'), array_map(array('self', '_callbackUrls'), $silo->getRelatedPages())); foreach ($hrefs as $key => $href) { if (in_array($href, $siloedPagesUrls)) { unset($hrefs[$key]); continue; } $page = Application_Model_Mappers_PageMapper::getInstance()->findByUrl(str_replace(self::$_websiteHelper->getUrl(), '', $href)); if ($page === null) { continue; } $pageContent = str_replace($key, '<span class="' . md5($key) . '">' . $page->getNavName() . '</span>', $pageContent); $sculptingReplacement[] = array('id' => md5($key), 'repl' => $key); unset($page); } Zend_Registry::set('sculptingReplacement', json_encode($sculptingReplacement)); return $pageContent; }
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 _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); } } } }