/**
  * 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;
     }
 }
 /**
  * recheck all the links in the page and update those links status code
  * 
  * @param array          $recheckLinks rechecking links
  * @param array          $inputArray   default input values
  * @param \HTTP_Request2 $request      http_request object
  */
 public function recheckPage($recheckLinks, $inputArray, \HTTP_Request2 $request)
 {
     if (is_array($recheckLinks) && $request) {
         foreach ($recheckLinks as $link => $text) {
             $linkAlreadyExist = $this->linkRepository->getLinkByPath($link);
             if (!$linkAlreadyExist) {
                 try {
                     $request->setUrl($link);
                     $request->setConfig(array('ssl_verify_peer' => false, 'ssl_verify_host' => false, 'follow_redirects' => true));
                     $response = $request->send();
                     $urlStatus = $response->getStatus();
                 } catch (\Exception $e) {
                     $urlStatus = preg_match('#^[mailto:|javascript:]# i', $link) ? 200 : 0;
                 }
                 $objFWUser = \FWUser::getFWUserObject();
                 $internalFlag = \Cx\Core_Modules\LinkManager\Controller\Url::isInternalUrl($link);
                 $flagStatus = $urlStatus == '200' ? 1 : 0;
                 $linkType = $internalFlag ? 'internal' : 'external';
                 $inputArray['requestedPath'] = contrexx_raw2db($link);
                 $inputArray['linkStatusCode'] = contrexx_raw2db($urlStatus);
                 $inputArray['flagStatus'] = contrexx_raw2db($flagStatus);
                 $inputArray['linkRecheck'] = 1;
                 $inputArray['requestedLinkType'] = contrexx_raw2db($linkType);
                 $inputArray['linkStatus'] = 1;
                 $inputArray['updatedBy'] = contrexx_raw2db($objFWUser->objUser->getId());
                 $inputArray['moduleName'] = '';
                 $inputArray['moduleAction'] = '';
                 $inputArray['moduleParams'] = '';
                 $inputArray['brokenLinkText'] = contrexx_raw2db($text);
                 $this->modifyLink($inputArray);
             }
         }
     }
 }