1<?php 2 3/* 4 * This file is part of the TYPO3 CMS project. 5 * 6 * It is free software; you can redistribute it and/or modify it under 7 * the terms of the GNU General Public License, either version 2 8 * of the License, or any later version. 9 * 10 * For the full copyright and license information, please read the 11 * LICENSE.txt file that was distributed with this source code. 12 * 13 * The TYPO3 project - inspiring people to share! 14 */ 15 16namespace TYPO3\CMS\Core\Database; 17 18use Psr\EventDispatcher\EventDispatcherInterface; 19use TYPO3\CMS\Core\DataHandling\SoftReference\SoftReferenceParserFactory; 20use TYPO3\CMS\Core\DataHandling\SoftReference\SoftReferenceParserResult; 21use TYPO3\CMS\Core\DataHandling\SoftReference\TypolinkSoftReferenceParser; 22use TYPO3\CMS\Core\SingletonInterface; 23 24/** 25 * Class for processing of the default soft reference types for CMS: 26 * 27 * - 'substitute' : A full field value targeted for manual substitution (for import /export features) 28 * - 'notify' : Just report if a value is found, nothing more. 29 * - 'typolink' : references to page id or file, possibly with anchor/target, possibly commaseparated list. 30 * - 'typolink_tag' : As typolink, but searching for <link> tag to encapsulate it. 31 * - 'email' : Email highlight 32 * - 'url' : URL highlights (with a scheme) 33 * @deprecated will be removed in TYPO3 v12.0 in favor of SoftReferenceParserInterface 34 */ 35class SoftReferenceIndex extends TypolinkSoftReferenceParser implements SingletonInterface 36{ 37 public string $tokenID_basePrefix; 38 protected SoftReferenceParserFactory $softReferenceParserFactory; 39 40 public function __construct( 41 EventDispatcherInterface $eventDispatcher, 42 SoftReferenceParserFactory $softReferenceParserFactory 43 ) { 44 parent::__construct($eventDispatcher); 45 $this->softReferenceParserFactory = $softReferenceParserFactory; 46 trigger_error( 47 'SoftReferenceIndex will be removed in TYPO3 v12.0, use appropriate TYPO3\CMS\Core\DataHandling\SoftReference\* class instead.', 48 E_USER_DEPRECATED 49 ); 50 } 51 52 /** 53 * @deprecated since v11, will be removed in v12 54 */ 55 public function findRef($table, $field, $uid, $content, $spKey, $spParams, $structurePath = '') 56 { 57 $this->parserKey = (string)$spKey; 58 $this->setTokenIdBasePrefix($table, (string)$uid, $field, $structurePath); 59 60 $softReferenceParser = $this->softReferenceParserFactory->getSoftReferenceParser($spKey); 61 $softReferenceParser->setParserKey($spKey, $spParams); 62 return $softReferenceParser->parse($table, $field, $uid, $content, $structurePath)->toNullableArray(); 63 } 64 65 public function parse(string $table, string $field, int $uid, string $content, string $structurePath = ''): SoftReferenceParserResult 66 { 67 // does nothing 68 return SoftReferenceParserResult::createWithoutMatches(); 69 } 70 71 public function setParserKey(string $parserKey, array $parameters): void 72 { 73 // does nothing 74 } 75 76 /** 77 * TypoLink value processing. 78 * Will process input value as a TypoLink value. 79 * 80 * @param string $content The input content to analyze 81 * @param array $spParams Parameters set for the softref parser key in TCA/columns. value "linkList" will split the string by comma before processing. 82 * @return array|null Result array on positive matches, see description above. Otherwise null 83 * @see \TYPO3\CMS\Frontend\ContentObject::typolink() 84 * @see getTypoLinkParts() 85 */ 86 public function findRef_typolink($content, $spParams) 87 { 88 $softReferenceParser = $this->softReferenceParserFactory->getSoftReferenceParser('typolink'); 89 $softReferenceParser->setParserKey('typolink', (array)$spParams); 90 return $softReferenceParser->parse('', '', '', $content)->toNullableArray(); 91 } 92 93 /** 94 * TypoLink tag processing. 95 * Will search for <link ...> and <a> tags in the content string and process any found. 96 * 97 * @param string $content The input content to analyze 98 * @return array|null Result array on positive matches, see description above. Otherwise null 99 * @see \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::typolink() 100 * @see getTypoLinkParts() 101 */ 102 public function findRef_typolink_tag($content) 103 { 104 $softReferenceParser = $this->softReferenceParserFactory->getSoftReferenceParser('typolink_tag'); 105 $softReferenceParser->setParserKey('typolink_tag', []); 106 return $softReferenceParser->parse('', '', '', $content)->toNullableArray(); 107 } 108 109 /** 110 * Finding email addresses in content and making them substitutable. 111 * 112 * @param string $content The input content to analyze 113 * @param array $spParams Parameters set for the softref parser key in TCA/columns 114 * @return array|null Result array on positive matches, see description above. Otherwise null 115 */ 116 public function findRef_email($content, $spParams) 117 { 118 $softReferenceParser = $this->softReferenceParserFactory->getSoftReferenceParser('email'); 119 $softReferenceParser->setParserKey('email', (array)$spParams); 120 return $softReferenceParser->parse('', '', '', $content)->toNullableArray(); 121 } 122 123 /** 124 * Finding URLs in content 125 * 126 * @param string $content The input content to analyze 127 * @param array $spParams Parameters set for the softref parser key in TCA/columns 128 * @return array|null Result array on positive matches, see description above. Otherwise null 129 */ 130 public function findRef_url($content, $spParams) 131 { 132 $softReferenceParser = $this->softReferenceParserFactory->getSoftReferenceParser('url'); 133 $softReferenceParser->setParserKey('url', (array)$spParams); 134 return $softReferenceParser->parse('', '', '', $content)->toNullableArray(); 135 } 136 137 /** 138 * Finding reference to files from extensions in content, but only to notify about their existence. No substitution 139 * 140 * @param string $content The input content to analyze 141 * @return array|null Result array on positive matches, see description above. Otherwise null 142 */ 143 public function findRef_extension_fileref($content) 144 { 145 $softReferenceParser = $this->softReferenceParserFactory->getSoftReferenceParser('ext_fileref'); 146 $softReferenceParser->setParserKey('ext_fileref', []); 147 return $softReferenceParser->parse('', '', '', $content)->toNullableArray(); 148 } 149} 150