/** * Checks a given URL for validity * * @param string $url Url to check * @param array $softRefEntry The soft reference entry which builds the context of that url * @param \TYPO3\CMS\Linkvalidator\LinkAnalyzer $reference Parent instance * @return bool TRUE on success or FALSE on error */ public function checkLink($url, $softRefEntry, $reference) { $response = TRUE; $errorType = ''; $errorParams = array(); $parts = explode(':', $url); if (count($parts) !== 3) { return $response; } list(, $tableName, $rowid) = $parts; $rowid = (int) $rowid; $row = NULL; $tsConfig = $reference->getTSConfig(); $reportHiddenRecords = (bool) $tsConfig['linkhandler.']['reportHiddenRecords']; // First check, if we find a non disabled record if the check // for hidden records is enabled. if ($reportHiddenRecords) { $row = $this->getRecordRow($tableName, $rowid, 'disabled'); if ($row === NULL) { $response = FALSE; $errorType = self::DISABLED; } } // If no enabled record was found or we did not check that see // if we can find a non deleted record. if ($row === NULL) { $row = $this->getRecordRow($tableName, $rowid, 'deleted'); if ($row === NULL) { $response = FALSE; $errorType = self::DELETED; } } // If we did not find a non deleted record, check if we find a // deleted one. if ($row === NULL) { $row = $this->getRecordRow($tableName, $rowid, 'all'); if ($row === NULL) { $response = FALSE; $errorType = ''; } } if (!$response) { $errorParams['errorType'] = $errorType; $errorParams['tablename'] = $tableName; $errorParams['uid'] = $rowid; $this->setErrorParams($errorParams); } return $response; }
/** * Displays the table of broken links or a note if there were no broken links * * @return string Content of the table or of the note */ protected function renderBrokenLinksTable() { $brokenLinkItems = ''; $brokenLinksTemplate = HtmlParser::getSubpart($this->doc->moduleTemplate, '###NOBROKENLINKS_CONTENT###'); $keyOpt = array(); if (is_array($this->checkOpt)) { $keyOpt = array_keys($this->checkOpt); } // Table header $brokenLinksMarker = $this->startTable(); $rootLineHidden = $this->linkAnalyzer->getRootLineIsHidden($this->pObj->pageinfo); if (!$rootLineHidden || (bool) $this->modTS['checkhidden']) { $pageList = $this->linkAnalyzer->extGetTreeList($this->pObj->id, $this->searchLevel, 0, $this->getBackendUser()->getPagePermsClause(1), $this->modTS['checkhidden']); // Always add the current page, because we are just displaying the results $pageList .= $this->pObj->id; $records = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'tx_linkvalidator_link', 'record_pid IN (' . $pageList . ') AND link_type IN (\'' . implode('\',\'', $keyOpt) . '\')', '', 'record_uid ASC, uid ASC'); if (!empty($records)) { // Display table with broken links $brokenLinksTemplate = HtmlParser::getSubpart($this->doc->moduleTemplate, '###BROKENLINKS_CONTENT###'); $brokenLinksItemTemplate = HtmlParser::getSubpart($this->doc->moduleTemplate, '###BROKENLINKS_ITEM###'); // Table rows containing the broken links $items = array(); foreach ($records as $record) { $items[] = $this->renderTableRow($record['table_name'], $record, $brokenLinksItemTemplate); } $brokenLinkItems = implode(LF, $items); } else { $brokenLinksMarker = $this->getNoBrokenLinkMessage($brokenLinksMarker); } } else { $brokenLinksMarker = $this->getNoBrokenLinkMessage($brokenLinksMarker); } $brokenLinksTemplate = HtmlParser::substituteMarkerArray($brokenLinksTemplate, $brokenLinksMarker, '###|###', TRUE); return HtmlParser::substituteSubpart($brokenLinksTemplate, '###BROKENLINKS_ITEM', $brokenLinkItems); }
/** * Checks a given URL for validity * * @param string $url Url to check * @param array $softRefEntry The soft reference entry which builds the context of that url * @param \TYPO3\CMS\Linkvalidator\LinkAnalyzer $reference Parent instance * @return boolean TRUE on success or FALSE on error */ public function checkLink($url, $softRefEntry, $reference) { $response = TRUE; $errorType = ''; $errorParams = array(); $this->initializeRequiredClasses(); $linkInfo = $this->tabHandlerFactory->getLinkInfoArrayFromMatchingHandler($url); if (empty($linkInfo)) { return TRUE; } $tableName = $linkInfo['recordTable']; $rowid = $linkInfo['recordUid']; $row = NULL; $tsConfig = $reference->getTSConfig(); $this->reportHiddenRecords = (bool) $tsConfig['tx_linkhandler.']['reportHiddenRecords']; // First check, if we find a non disabled record if the check // for hidden records is enabled. if ($this->reportHiddenRecords) { $row = $this->getRecordRow($tableName, $rowid, 'disabled'); if ($row === NULL) { $response = FALSE; $errorType = self::ERROR_TYPE_DISABLED; } } // If no enabled record was found or we did not check that see // if we can find a non deleted record. if ($row === NULL) { $row = $this->getRecordRow($tableName, $rowid, 'deleted'); if ($row === NULL) { $response = FALSE; $errorType = self::ERROR_TYPE_DELETED; } } // If we did not find a non deleted record, check if we find a // deleted one. if ($row === NULL) { $row = $this->getRecordRow($tableName, $rowid, 'all'); if ($row === NULL) { $response = FALSE; $errorType = ''; } } if (!$response) { $errorParams['errorType'] = $errorType; $errorParams['tablename'] = $tableName; $errorParams['uid'] = $rowid; $this->setErrorParams($errorParams); } return $response; }
/** * Displays the table of broken links or a note if there were no broken links * * @return string Content of the table or of the note */ protected function renderBrokenLinksTable() { $items = $brokenLinksMarker = array(); $brokenLinkItems = ''; $brokenLinksTemplate = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($this->doc->moduleTemplate, '###NOBROKENLINKS_CONTENT###'); $keyOpt = array(); if (is_array($this->checkOpt)) { $keyOpt = array_keys($this->checkOpt); } $rootLineHidden = $this->processor->getRootLineIsHidden($this->pObj->pageinfo); if (!$rootLineHidden || $this->modTS['checkhidden'] == 1) { $pageList = $this->processor->extGetTreeList($this->pObj->id, $this->searchLevel, 0, $GLOBALS['BE_USER']->getPagePermsClause(1), $this->modTS['checkhidden']); // Always add the current page, because we are just displaying the results $pageList .= $this->pObj->id; if ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_linkvalidator_link', 'record_pid in (' . $pageList . ') and link_type in (\'' . implode('\',\'', $keyOpt) . '\')', '', 'record_uid ASC, uid ASC')) { // Display table with broken links if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) { $brokenLinksTemplate = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($this->doc->moduleTemplate, '###BROKENLINKS_CONTENT###'); $brokenLinksItemTemplate = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($this->doc->moduleTemplate, '###BROKENLINKS_ITEM###'); // Table header $brokenLinksMarker = $this->startTable(); // Table rows containing the broken links while (($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) !== FALSE) { $items[] = $this->renderTableRow($row['table_name'], $row, $brokenLinksItemTemplate); } $brokenLinkItems = implode(chr(10), $items); } else { $brokenLinksMarker = $this->getNoBrokenLinkMessage($brokenLinksMarker); } $GLOBALS['TYPO3_DB']->sql_free_result($res); } } else { $brokenLinksMarker = $this->getNoBrokenLinkMessage($brokenLinksMarker); } $brokenLinksTemplate = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($brokenLinksTemplate, $brokenLinksMarker, '###|###', TRUE); $content = \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart($brokenLinksTemplate, '###BROKENLINKS_ITEM', $brokenLinkItems); return $content; }