94 $GLOBALS[
'LANG']->includeLLFile(
'EXT:linkvalidator/Resources/Private/Language/Module/locallang.xlf');
96 if (is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'linkvalidator'][
'checkLinks'])) {
97 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'linkvalidator'][
'checkLinks'] as $key => $classRef) {
110 public function init(array $searchField, $pid) {
111 $this->searchFields = $searchField;
112 $this->pidList = $pid;
124 $pidList = implode(
',', \
TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(
',', $this->pidList,
true));
125 if (count($checkOptions) > 0 && !empty(
$pidList)) {
126 $checkKeys = array_keys($checkOptions);
127 $checkLinkTypeCondition =
' AND link_type IN (\'' . implode(
'\',\
'', $checkKeys) .
'\')
'; 128 $GLOBALS['TYPO3_DB
']->exec_DELETEquery( 129 'tx_linkvalidator_link
', 130 '(record_pid IN (
' . $pidList . ')
' . 131 ' OR ( record_uid IN (
' . $pidList . ') AND table_name like \
'pages\'))' .
132 $checkLinkTypeCondition
135 foreach ($this->searchFields as $table => $fields) {
136 if ($table ===
'pages') {
137 $where =
'deleted = 0 AND uid IN (' .
$pidList .
')';
139 $where =
'deleted = 0 AND pid IN (' .
$pidList .
')';
141 if (!$considerHidden) {
146 if (!is_array(
$GLOBALS[
'TCA'][$table])) {
150 $selectFields =
'uid, pid';
151 $selectFields .=
', ' .
$GLOBALS[
'TCA'][$table][
'ctrl'][
'label'] .
', ' . implode(
', ', $fields);
153 $res =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery($selectFields, $table, $where);
155 while (($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($res)) !== FALSE) {
157 $this->analyzeRecord($results, $table, $fields, $row);
159 $GLOBALS[
'TYPO3_DB']->sql_free_result($res);
161 foreach ($this->hookObjectsArr as $key => $hookObj) {
162 if (is_array($results[$key]) && empty($checkOptions) || is_array($results[$key]) && $checkOptions[$key]) {
164 foreach ($results[$key] as $entryKey => $entryValue) {
165 $table = $entryValue[
'table'];
168 $record[
'record_pid'] = $entryValue[
'row'][
'pid'];
169 $record[
'record_uid'] = $entryValue[
'uid'];
170 $record[
'table_name'] = $table;
171 $record[
'link_title'] = $entryValue[
'link_title'];
172 $record[
'field'] = $entryValue[
'field'];
173 $record[
'last_check'] = time();
174 $this->recordReference = $entryValue[
'substr'][
'recordRef'];
175 $this->pageWithAnchor = $entryValue[
'pageAndAnchor'];
176 if (!empty($this->pageWithAnchor)) {
180 $url = $entryValue[
'substr'][
'tokenValue'];
182 $this->linkCounts[$table]++;
183 $checkUrl = $hookObj->checkLink($url, $entryValue, $this);
187 $response[
'valid'] = FALSE;
188 $response[
'errorParams'] = $hookObj->getErrorParams();
189 $this->brokenLinkCounts[$table]++;
190 $record[
'link_type'] = $key;
191 $record[
'url'] = $url;
192 $record[
'url_response'] = serialize($response);
193 $GLOBALS[
'TYPO3_DB']->exec_INSERTquery(
'tx_linkvalidator_link', $record);
194 } elseif (\
TYPO3\CMS\Core\Utility\GeneralUtility::_GP(
'showalllinks')) {
196 $response[
'valid'] = TRUE;
197 $this->brokenLinkCounts[$table]++;
198 $record[
'url'] = $url;
199 $record[
'link_type'] = $key;
200 $record[
'url_response'] = serialize($response);
201 $GLOBALS[
'TYPO3_DB']->exec_INSERTquery(
'tx_linkvalidator_link', $record);
218 public function analyzeRecord(array &$results, $table, array $fields, array $record) {
223 $idRecord = $record[
'uid'];
225 foreach ($fields as $field) {
226 $haystack .= $record[$field] .
' --- ';
227 $conf =
$GLOBALS[
'TCA'][$table][
'columns'][$field][
'config'];
228 $valueField = $record[$field];
230 if ($conf[
'softref'] && strlen($valueField)) {
233 if ($softRefs !== FALSE) {
235 foreach ($softRefs as $spKey => $spParams) {
239 if (is_object($softRefObj)) {
241 $resultArray = $softRefObj->findRef($table, $field, $idRecord, $valueField, $spKey, $spParams);
242 if (!empty($resultArray[
'elements'])) {
243 if ($spKey ==
'typolink_tag') {
244 $this->analyseTypoLinks($resultArray, $results, $htmlParser, $record, $field, $table);
246 $this->analyseLinks($resultArray, $results, $record, $field, $table);
266 protected function analyseLinks(array $resultArray, array &$results, array $record, $field, $table) {
267 foreach ($resultArray[
'elements'] as $element) {
268 $r = $element[
'subst'];
270 $idRecord = $record[
'uid'];
273 foreach ($this->hookObjectsArr as $keyArr => $hookObj) {
274 $type = $hookObj->fetchType($r, $type, $keyArr);
281 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $r[
'tokenID']][
'substr'] = $r;
282 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $r[
'tokenID']][
'row'] = $record;
283 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $r[
'tokenID']][
'table'] = $table;
284 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $r[
'tokenID']][
'field'] = $field;
285 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $r[
'tokenID']][
'uid'] = $idRecord;
301 protected function analyseTypoLinks(array $resultArray, array &$results, $htmlParser, array $record, $field, $table) {
303 $linkTags = $htmlParser->splitIntoBlock(
'link', $resultArray[
'content']);
304 $idRecord = $record[
'uid'];
307 for ($i = 1; $i < count($linkTags); $i += 2) {
308 $referencedRecordType =
'';
309 foreach ($resultArray[
'elements'] as $element) {
311 $r = $element[
'subst'];
312 if (!empty($r[
'tokenID'])) {
313 if (substr_count($linkTags[$i], $r[
'tokenID'])) {
315 if (strpos($r[
'recordRef'],
'pages') !== FALSE) {
318 $referencedRecordType = $r[
'tokenValue'];
320 } elseif (strpos($r[
'recordRef'],
'tt_content') !== FALSE && (isset($wasPage) && $wasPage === TRUE)) {
321 $referencedRecordType = $referencedRecordType .
'#c' . $r[
'tokenValue'];
326 $title = strip_tags($linkTags[$i]);
331 foreach ($this->hookObjectsArr as $keyArr => $hookObj) {
332 $type = $hookObj->fetchType($currentR, $type, $keyArr);
336 $currentR[
'type'] = $type;
339 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $currentR[
'tokenID']][
'substr'] = $currentR;
340 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $currentR[
'tokenID']][
'row'] = $record;
341 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $currentR[
'tokenID']][
'table'] = $table;
342 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $currentR[
'tokenID']][
'field'] = $field;
343 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $currentR[
'tokenID']][
'uid'] = $idRecord;
344 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $currentR[
'tokenID']][
'link_title'] = $title;
345 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $currentR[
'tokenID']][
'pageAndAnchor'] = $referencedRecordType;
356 $markerArray = array();
357 if (empty($this->pidList)) {
358 $this->pidList = $curPage;
360 $this->pidList = rtrim($this->pidList,
',');
361 if (($res =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
362 'count(uid) as nbBrokenLinks,link_type',
363 'tx_linkvalidator_link',
364 'record_pid in (' . $this->pidList .
')',
'link_type')
366 while (($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($res)) !== FALSE) {
367 $markerArray[$row[
'link_type']] = $row[
'nbBrokenLinks'];
368 $markerArray[
'brokenlinkCount'] += $row[
'nbBrokenLinks'];
371 $GLOBALS[
'TYPO3_DB']->sql_free_result($res);
390 public function extGetTreeList($id, $depth, $begin = 0, $permsClause, $considerHidden = FALSE) {
391 $depth = (int)$depth;
392 $begin = (int)$begin;
396 $res =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
397 'uid,title,hidden,extendToSubpages',
398 'pages',
'pid=' . $id .
' AND deleted=0 AND ' . $permsClause
400 while (($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($res)) !== FALSE) {
401 if ($begin <= 0 && ($row[
'hidden'] == 0 || $considerHidden == 1)) {
402 $theList .= $row[
'uid'] .
',';
403 $this->extPageInTreeInfo[] = array($row[
'uid'], htmlspecialchars($row[
'title'], $depth));
405 if ($depth > 1 && (!($row[
'hidden'] == 1 && $row[
'extendToSubpages'] == 1) || $considerHidden == 1)) {
406 $theList .= $this->
extGetTreeList($row[
'uid'], $depth - 1, $begin - 1, $permsClause, $considerHidden);
409 $GLOBALS[
'TYPO3_DB']->sql_free_result($res);
422 if ($pageInfo[
'extendToSubpages'] == 1 && $pageInfo[
'hidden'] == 1) {
425 if ($pageInfo[
'pid'] > 0) {
426 $res =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
'uid,title,hidden,extendToSubpages',
'pages',
'uid=' . $pageInfo[
'pid']);
427 while (($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($res)) !== FALSE) {
430 $GLOBALS[
'TYPO3_DB']->sql_free_result($res);
init(array $searchField, $pid)
static explodeSoftRefParserList($parserList)
static getUserObj($classRef, $checkPrefix='', $silent=FALSE)
static makeInstance($className)
static getRecordTitle($table, $row, $prep=FALSE, $forceResult=TRUE)
static & softRefParserObj($spKey)
extGetTreeList($id, $depth, $begin=0, $permsClause, $considerHidden=FALSE)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
getRootLineIsHidden(array $pageInfo)
getLinkStatistics($checkOptions=array(), $considerHidden=FALSE)
static BEenableFields($table, $inv=0)