2 namespace TYPO3\CMS\Linkvalidator;
102 $this->
getLanguageService()->includeLLFile(
'EXT:linkvalidator/Resources/Private/Language/Module/locallang.xlf');
104 if (is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'linkvalidator'][
'checkLinks'])) {
105 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'linkvalidator'][
'checkLinks'] as $key => $classRef) {
121 $this->searchFields = $searchField;
122 $this->pidList = $pid;
136 if (!empty($checkOptions)) {
137 $checkKeys = array_keys($checkOptions);
138 $checkLinkTypeCondition =
' AND link_type IN (\'' . implode(
'\',\
'', $checkKeys) .
'\')
';
139 $this->getDatabaseConnection()->exec_DELETEquery(
140 'tx_linkvalidator_link
',
141 '(record_pid IN (
' . $this->pidList . ')
' .
142 ' OR ( record_uid IN (
' . $this->pidList . ') AND table_name like \
'pages\'))' .
143 $checkLinkTypeCondition
146 foreach ($this->searchFields as $table => $fields) {
147 if ($table ===
'pages') {
148 $where =
'deleted = 0 AND uid IN (' . $this->pidList .
')';
150 $where =
'deleted = 0 AND pid IN (' . $this->pidList .
')';
152 if (!$considerHidden) {
157 if (!is_array(
$GLOBALS[
'TCA'][$table])) {
161 $selectFields =
'uid, pid';
162 $selectFields .=
', ' .
$GLOBALS[
'TCA'][$table][
'ctrl'][
'label'] .
', ' . implode(
', ', $fields);
167 foreach ($rows as $row) {
168 $this->analyzeRecord($results, $table, $fields, $row);
172 foreach ($this->hookObjectsArr as $key => $hookObj) {
173 if (is_array($results[$key]) && empty($checkOptions) || is_array($results[$key]) && $checkOptions[$key]) {
175 foreach ($results[$key] as $entryKey => $entryValue) {
176 $table = $entryValue[
'table'];
179 $record[
'record_pid'] = $entryValue[
'row'][
'pid'];
180 $record[
'record_uid'] = $entryValue[
'uid'];
181 $record[
'table_name'] = $table;
182 $record[
'link_title'] = $entryValue[
'link_title'];
183 $record[
'field'] = $entryValue[
'field'];
184 $record[
'last_check'] = time();
185 $this->recordReference = $entryValue[
'substr'][
'recordRef'];
186 $this->pageWithAnchor = $entryValue[
'pageAndAnchor'];
187 if (!empty($this->pageWithAnchor)) {
191 $url = $entryValue[
'substr'][
'tokenValue'];
193 $this->linkCounts[$table]++;
194 $checkUrl = $hookObj->checkLink(
$url, $entryValue, $this);
199 $response[
'errorParams'] = $hookObj->getErrorParams();
200 $this->brokenLinkCounts[$table]++;
201 $record[
'link_type'] = $key;
202 $record[
'url'] =
$url;
203 $record[
'url_response'] = serialize(
$response);
208 $this->brokenLinkCounts[$table]++;
209 $record[
'url'] =
$url;
210 $record[
'link_type'] = $key;
211 $record[
'url_response'] = serialize(
$response);
229 public function analyzeRecord(array &$results, $table, array $fields, array $record)
237 $idRecord = $record[
'uid'];
239 foreach ($fields as $field) {
240 $haystack .= $record[$field] .
' --- ';
241 $conf =
$GLOBALS[
'TCA'][$table][
'columns'][$field][
'config'];
242 $valueField = $record[$field];
244 if ($conf[
'softref'] && (
string)$valueField !==
'') {
247 if ($softRefs !==
false) {
249 foreach ($softRefs as $spKey => $spParams) {
253 if (is_object($softRefObj)) {
255 $resultArray = $softRefObj->findRef($table, $field, $idRecord, $valueField, $spKey, $spParams);
256 if (!empty($resultArray[
'elements'])) {
257 if ($spKey ==
'typolink_tag') {
258 $this->analyseTypoLinks($resultArray, $results, $htmlParser, $record, $field, $table);
260 $this->analyseLinks($resultArray, $results, $record, $field, $table);
293 protected function analyseLinks(array $resultArray, array &$results, array $record, $field, $table)
295 foreach ($resultArray[
'elements'] as $element) {
296 $r = $element[
'subst'];
298 $idRecord = $record[
'uid'];
301 foreach ($this->hookObjectsArr as $keyArr => $hookObj) {
302 $type = $hookObj->fetchType($r, $type, $keyArr);
309 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $r[
'tokenID']][
'substr'] = $r;
310 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $r[
'tokenID']][
'row'] = $record;
311 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $r[
'tokenID']][
'table'] = $table;
312 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $r[
'tokenID']][
'field'] = $field;
313 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $r[
'tokenID']][
'uid'] = $idRecord;
329 protected function analyseTypoLinks(array $resultArray, array &$results, $htmlParser, array $record, $field, $table)
332 $linkTags = $htmlParser->splitIntoBlock(
'link', $resultArray[
'content']);
333 $idRecord = $record[
'uid'];
336 $countLinkTags = count($linkTags);
337 for ($i = 1; $i < $countLinkTags; $i += 2) {
338 $referencedRecordType =
'';
339 foreach ($resultArray[
'elements'] as $element) {
341 $r = $element[
'subst'];
342 if (!empty($r[
'tokenID'])) {
343 if (substr_count($linkTags[$i], $r[
'tokenID'])) {
345 if (strpos($r[
'recordRef'],
'pages') !==
false) {
348 $referencedRecordType = $r[
'tokenValue'];
350 }
elseif (strpos($r[
'recordRef'],
'tt_content') !==
false && (isset($wasPage) && $wasPage ===
true)) {
351 $referencedRecordType = $referencedRecordType .
'#c' . $r[
'tokenValue'];
356 $title = strip_tags($linkTags[$i]);
361 foreach ($this->hookObjectsArr as $keyArr => $hookObj) {
362 $type = $hookObj->fetchType($currentR, $type, $keyArr);
366 $currentR[
'type'] = $type;
369 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $currentR[
'tokenID']][
'substr'] = $currentR;
370 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $currentR[
'tokenID']][
'row'] = $record;
371 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $currentR[
'tokenID']][
'table'] = $table;
372 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $currentR[
'tokenID']][
'field'] = $field;
373 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $currentR[
'tokenID']][
'uid'] = $idRecord;
374 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $currentR[
'tokenID']][
'link_title'] = $title;
375 $results[$type][$table .
':' . $field .
':' . $idRecord .
':' . $currentR[
'tokenID']][
'pageAndAnchor'] = $referencedRecordType;
387 $markerArray = array();
388 if (empty($this->pidList)) {
389 $this->pidList = $curPage;
391 $this->pidList = rtrim($this->pidList,
',');
394 'count(uid) as nbBrokenLinks,link_type',
395 'tx_linkvalidator_link',
396 'record_pid in (' . $this->pidList .
')',
400 foreach ($rows as $row) {
401 $markerArray[$row[
'link_type']] = $row[
'nbBrokenLinks'];
402 $markerArray[
'brokenlinkCount'] += $row[
'nbBrokenLinks'];
423 public function extGetTreeList($id, $depth, $begin = 0, $permsClause, $considerHidden =
false)
425 $depth = (int)$depth;
426 $begin = (int)$begin;
431 'uid,title,hidden,extendToSubpages',
433 'pid=' . $id .
' AND deleted=0 AND ' . $permsClause
436 foreach ($rows as $row) {
437 if ($begin <= 0 && ($row[
'hidden'] == 0 || $considerHidden)) {
438 $theList .= $row[
'uid'] .
',';
439 $this->extPageInTreeInfo[] = array($row[
'uid'], htmlspecialchars($row[
'title'], $depth));
441 if ($depth > 1 && (!($row[
'hidden'] == 1 && $row[
'extendToSubpages'] == 1) || $considerHidden)) {
442 $theList .= $this->
extGetTreeList($row[
'uid'], $depth - 1, $begin - 1, $permsClause, $considerHidden);
459 if ($pageInfo[
'extendToSubpages'] == 1 && $pageInfo[
'hidden'] == 1) {
462 if ($pageInfo[
'pid'] > 0) {
464 'uid,title,hidden,extendToSubpages',
466 'uid=' . $pageInfo[
'pid']
469 foreach ($rows as $row) {
491 'beforeAnalyzeRecord',
492 array($results, $record, $table, $fields, $this)
501 return $this->
getObjectManager()->get(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);