/** * Store each crawl result to database * * @global array $_CONFIG * * @param \HTTP_Request2 $request http_request2() object * @param String $requestedUrl the requested url * @param String $refererUrl the lead url * @param Boolean $image the requested url is image or not * @param Integer $referPageId the lead url page id * @param String $requestedUrlText the requested url text * * @return null */ public function storeUrlInfos(\HTTP_Request2 $request, $requestedUrl, $refererUrl, $image, $referPageId, $requestedUrlText) { global $_CONFIG; try { $request->setUrl($requestedUrl); // ignore ssl issues // otherwise, contrexx does not activate 'https' when the server doesn't have an ssl certificate installed $request->setConfig(array('ssl_verify_peer' => false, 'ssl_verify_host' => false, 'follow_redirects' => true)); $response = $request->send(); $urlStatus = $response->getStatus(); } catch (\Exception $e) { $response = true; $urlStatus = preg_match('#^[mailto:|javascript:]# i', $requestedUrl) ? 200 : 0; } if ($response) { $internalFlag = \Cx\Core_Modules\LinkManager\Controller\Url::isInternalUrl($requestedUrl); $flagStatus = $urlStatus == '200' ? 1 : 0; $linkType = $internalFlag ? 'internal' : 'external'; //find the entry name, module name, action and parameter if ($linkType == 'internal') { list($entryTitle, $moduleName, $moduleAction, $moduleParams) = $this->getModuleDetails($requestedUrl, $refererUrl, $image); } else { $objRefererUrl = $this->isModulePage($refererUrl); if ($objRefererUrl) { $entryTitle = $objRefererUrl->getTitle(); } $moduleName = ''; $moduleAction = ''; $moduleParams = ''; } if (!empty($referPageId)) { $backendReferUrl = ASCMS_PROTOCOL . '://' . $_CONFIG['domainUrl'] . ASCMS_PATH_OFFSET . '/cadmin/index.php?cmd=ContentManager&page=' . $referPageId; } //save the link $linkInputValues = array('lang' => contrexx_raw2db($this->langId), 'requestedPath' => contrexx_raw2db($requestedUrl), 'refererPath' => contrexx_raw2db($refererUrl), 'leadPath' => contrexx_raw2db($backendReferUrl), 'linkStatusCode' => contrexx_raw2db($urlStatus), 'entryTitle' => contrexx_raw2db($entryTitle), 'moduleName' => contrexx_raw2db($moduleName), 'moduleAction' => contrexx_raw2db($moduleAction), 'moduleParams' => contrexx_raw2db($moduleParams), 'detectedTime' => new \DateTime('now'), 'flagStatus' => contrexx_raw2db($flagStatus), 'linkStatus' => 0, 'linkRecheck' => 0, 'updatedBy' => 0, 'requestedLinkType' => contrexx_raw2db($linkType), 'brokenLinkText' => contrexx_raw2db($requestedUrlText)); $linkAlreadyExist = $this->linkRepo->findOneBy(array('requestedPath' => $requestedUrl)); if ($linkAlreadyExist && $linkAlreadyExist->getRefererPath() == $refererUrl) { if ($linkAlreadyExist->getLinkStatusCode() != $urlStatus) { //move the modified link to history table $historyInputValues = array('lang' => $linkAlreadyExist->getLang(), 'requestedPath' => $linkAlreadyExist->getRequestedPath(), 'refererPath' => $linkAlreadyExist->getRefererPath(), 'leadPath' => $linkAlreadyExist->getLeadPath(), 'linkStatusCode' => $linkAlreadyExist->getLinkStatusCode(), 'entryTitle' => $linkAlreadyExist->getEntryTitle(), 'moduleName' => $linkAlreadyExist->getModuleName(), 'moduleAction' => $linkAlreadyExist->getModuleAction(), 'moduleParams' => $linkAlreadyExist->getModuleParams(), 'detectedTime' => $linkAlreadyExist->getDetectedTime(), 'flagStatus' => $linkAlreadyExist->getFlagStatus(), 'linkStatus' => $linkAlreadyExist->getLinkStatus(), 'linkRecheck' => $linkAlreadyExist->getLinkRecheck(), 'updatedBy' => $linkAlreadyExist->getUpdatedBy(), 'requestedLinkType' => $linkAlreadyExist->getRequestedLinkType(), 'brokenLinkText' => $linkAlreadyExist->getBrokenLinkText()); $this->modifyHistory($historyInputValues); } //add the modified link to the link table $this->modifyLink($linkInputValues, $linkAlreadyExist); } else { //add the link to link table $this->modifyLink($linkInputValues); } } else { return; } }
/** * Store each crawl result to database * * @param String $requestedUrl the requested url * @param String $refererUrl the lead url * @param Integer $referPageId the lead url page id * @param String $requestedUrlText the requested url text * * @return null */ public function storeUrlInfos($requestedUrl, $refererUrl, $referPageId, $requestedUrlText) { global $_CONFIG; $urlStatus = $this->getUrlStatus($requestedUrl); //Check the requested url is internal or not $isInternalLink = $this->getController('Url')->isInternalUrl($requestedUrl); //find the entry name, module name, action and parameter $moduleName = $moduleAction = $moduleParams = ''; if ($isInternalLink) { list($entryTitle, $moduleName, $moduleAction, $moduleParams) = $this->getModuleDetails($requestedUrl, $refererUrl); } else { $objRefererUrl = $this->getPageByUrl($refererUrl); $entryTitle = $objRefererUrl ? $objRefererUrl->getTitle() : ''; } //Get the backend referer url by referPageId if (!empty($referPageId)) { $backendReferUrl = ASCMS_PROTOCOL . '://' . $_CONFIG['domainUrl'] . ASCMS_PATH_OFFSET . '/cadmin/index.php?cmd=ContentManager&page=' . $referPageId; } $link = $this->linkRepo->findOneBy(array('requestedPath' => $requestedUrl)); if ($link && $link->getRefererPath() == $refererUrl && $link->getLinkStatusCode() != $urlStatus) { $this->copyLinkToHistory($link); } $persist = false; if (!$link) { $link = new \Cx\Core_Modules\LinkManager\Model\Entity\Link(); $persist = true; } $link->setLang($this->langId); $link->setBrokenLinkText($requestedUrlText); $link->setRefererPath($refererUrl); $link->setRequestedPath($requestedUrl); $link->setLeadPath($backendReferUrl); $link->setEntryTitle($entryTitle); $link->setDetectedTime(new \DateTime('now')); $link->setUpdatedBy(0); $link->setLinkStatusCode($urlStatus); $link->setFlagStatus($urlStatus == 200 ? 1 : 0); $link->setLinkRecheck(0); $link->setRequestedLinkType($isInternalLink ? 'internal' : 'external'); $link->setLinkStatus(0); if ($persist) { $this->em->persist($link); } $this->em->flush(); }
/** * Edit the link status(link resolved or not) * * @return array */ public function modifyLinkStatus() { //get post values $id = isset($_GET['id']) ? contrexx_input2raw($_GET['id']) : 0; $solvedLinkStat = isset($_GET['status']) ? $_GET['status'] : 0; $result = array(); $objUser = new \Cx\Core_Modules\LinkManager\Controller\User(); if ($objUser) { $user = $objUser->getUpdatedUserName(0, 1); } if (!empty($id)) { $linkStatus = $solvedLinkStat == 0 ? 1 : 0; $userId = $linkStatus ? $user['id'] : 0; $brokenLink = $this->linkRepo->findOneBy(array('id' => $id)); $brokenLink->setLinkStatus($linkStatus); $brokenLink->setUpdatedBy($userId); $this->em->persist($brokenLink); $this->em->flush(); $result['linkStatus'] = $linkStatus; $result['userName'] = $user['name']; } return $result; }