/** * Recheck the selected links status * * @return null */ public function recheckSelectedLinks() { global $_ARRAYLANG; //Get the post values $selectedIds = isset($_POST['selected']) ? $_POST['selected'] : ''; $links = $this->linkRepository->getSelectedLinks($selectedIds); if (!$links) { $links = array(); } $pageLinks = array(); foreach ($links as $link) { $refererPath = $link->getRefererPath(); $requestPath = $link->getRequestedPath(); $subLinks = array(); $recheckPage = false; // Get the Links in the referer // Recheck the refer once (on first request of refer) if (array_key_exists($refererPath, $pageLinks)) { $subLinks = $pageLinks[$refererPath]; } else { $pageLinks[$refererPath] = $subLinks = $this->getController('LinkCrawler')->getPageLinks($refererPath); $recheckPage = true; } if ($recheckPage) { $this->recheckPage($link, $subLinks); } // Check whether the request path exists in the referer page // if not exists remove the link if (!array_key_exists($requestPath, $subLinks)) { $this->em->remove($link); } else { $urlStatus = $this->getUrlStatus($link->getRequestedPath()); $link->setLinkStatusCode($urlStatus); $link->setFlagStatus($urlStatus == 200 ? 1 : 0); $link->setLinkRecheck(true); } } //update the broken links count in crawler table foreach (\FWLanguage::getActiveFrontendLanguages() as $lang) { $lastRunByLang = $this->crawlerRepository->getLastRunByLang($lang['id']); $brokenLinkCnt = $this->linkRepository->brokenLinkCountByLang($lang['id']); if ($lastRunByLang) { $lastRunByLang->setTotalBrokenLinks($brokenLinkCnt); } } $this->em->flush(); \Message::ok($_ARRAYLANG['TXT_CORE_MODULE_LINKMANAGER_SUCCESS_MSG']); }
/** * Recheck the selected links status * * @global array $_ARRAYLANG * * @return null */ public function recheckSelectedLinks() { global $_ARRAYLANG; $selectedIds = isset($_POST['selected']) ? $_POST['selected'] : ''; $links = $this->linkRepository->getSelectedLinks($selectedIds); if (!$links) { $links = array(); } $request = new \HTTP_Request2(); $pageLinks = array(); foreach ($links as $link) { if (!in_array($link->getEntryTitle(), $pageLinks)) { $pageLinks[] = $link->getEntryTitle(); ${$link->getEntryTitle()} = array(); try { $request->setUrl($link->getRefererPath()); $request->setConfig(array('ssl_verify_peer' => false, 'ssl_verify_host' => false, 'follow_redirects' => true)); $response = $request->send(); $html = \str_get_html($response->getBody()); } catch (\Exception $e) { $html = false; } if (!$html) { continue; } else { //remove the navigation menu $objNavigation = $html->find('ul#navigation, ul.navigation', 0); $objNavigation->outertext = ''; $html = \str_get_html($html->outertext); // Find all images foreach ($html->find('img') as $element) { if (preg_match('#\\.(jpg|jpeg|gif|png)$# i', $element->src)) { $imgSrc = \Cx\Core_Modules\LinkManager\Controller\Url::checkPath($element->src, null); if (!empty($imgSrc)) { ${$link->getEntryTitle()}[$imgSrc] = $_ARRAYLANG['TXT_CORE_MODULE_LINKMANAGER_NO_IMAGE']; } } } // Find all links foreach ($html->find('a') as $element) { $aHref = \Cx\Core_Modules\LinkManager\Controller\Url::checkPath($element->href, $link->getRefererPath()); if (!empty($aHref)) { $linkText = $element->plaintext ? $element->plaintext : $_ARRAYLANG['TXT_CORE_MODULE_LINKMANAGER_NO_LINK']; ${$link->getEntryTitle()}[$aHref] = $linkText; } } } } if (!array_key_exists($link->getRequestedPath(), ${$link->getEntryTitle()})) { $linkInputValues = array('lang' => $link->getLang(), 'refererPath' => $link->getRefererPath(), 'leadPath' => $link->getLeadPath(), 'entryTitle' => $link->getEntryTitle(), 'detectedTime' => $link->getDetectedTime(), 'updatedBy' => 0); $this->recheckPage(${$link->getEntryTitle()}, $linkInputValues, $request); $this->em->remove($link); } else { try { $request->setUrl($link->getRequestedPath()); $response = $request->send(); $urlStatus = $response->getStatus(); } catch (\Exception $e) { $urlStatus = 0; } if ($urlStatus == '200') { $this->em->remove($link); } else { $link->setLinkStatusCode($urlStatus); $link->setLinkRecheck(true); } } $this->em->persist($link); $this->em->flush(); } //update the broken links count in crawler table foreach (\FWLanguage::getActiveFrontendLanguages() as $lang) { $lastRunByLang = $this->crawlerRepository->getLastRunByLang($lang['id']); $brokenLinkCnt = $this->linkRepository->brokenLinkCountByLang($lang['id']); if ($lastRunByLang) { $lastRunByLang->setTotalBrokenLinks($brokenLinkCnt); $this->em->persist($lastRunByLang); } } $this->em->flush(); \Message::ok($_ARRAYLANG['TXT_CORE_MODULE_LINKMANAGER_SUCCESS_MSG']); }