32 public $blockElementList =
'PRE,UL,OL,H1,H2,H3,H4,H5,H6,ADDRESS,DL,DD,HEADER,SECTION,FOOTER,NAV,ARTICLE,ASIDE';
123 $path = preg_replace(
'/^\\//',
'', $path);
124 $path = preg_replace(
'/\\/$/',
'', $path);
126 $this->relPath = $path;
127 $this->relBackPath =
'';
128 $partsC = count(explode(
'/', $this->relPath));
129 for ($a = 0; $a < $partsC; $a++) {
130 $this->relBackPath .=
'../';
132 $this->relPath .=
'/';
147 if (is_array($pArr)) {
148 if (
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'staticFileEditPath'] && substr(
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'staticFileEditPath'], -1) ==
'/' && @is_dir((PATH_site .
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'staticFileEditPath']))) {
149 $SW_p = $pArr[
'parameters'];
150 $SW_editFileField = trim($SW_p[0]);
151 $SW_editFile = $currentRecord[$SW_editFileField];
153 $SW_relpath = $GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'staticFileEditPath'] . $SW_editFile;
154 $SW_editFile = PATH_site . $SW_relpath;
155 if (@is_file($SW_editFile)) {
157 'editFile' => $SW_editFile,
158 'relEditFile' => $SW_relpath,
159 'contentField' => trim($SW_p[1]),
160 'markerField' => trim($SW_p[2]),
161 'loadFromFileField' => trim($SW_p[3]),
162 'statusField' => trim($SW_p[4])
165 return 'ERROR: Editfile \'' . $SW_relpath .
'\' did not exist
'; 168 return 'ERROR: Edit file name could not be found or was bad.
'; 171 return 'ERROR: staticFileEditPath was not
set, not
set correctly or did not exist!
'; 176 /********************************************** 180 **********************************************/ 192 public function RTE_transform($value, $specConf, $direction = 'rte
', $thisConfig = array()) { 194 $this->tsConfig = $thisConfig; 195 $this->procOptions = (array) $thisConfig['proc.
']; 196 $this->preserveTags = strtoupper(implode(',
', GeneralUtility::trimExplode(',
', $this->procOptions['preserveTags
']))); 197 // dynamic configuration of blockElementList 198 if ($this->procOptions['blockElementList
']) { 199 $this->blockElementList = $this->procOptions['blockElementList
']; 201 // Get parameters for rte_transformation: 202 $p = ($this->rte_p = BackendUtility::getSpecConfParametersFromArray($specConf['rte_transform
']['parameters
'])); 204 if ((string)$this->procOptions['overruleMode
'] !== '') { 205 $modes = array_unique(GeneralUtility::trimExplode(',
', $this->procOptions['overruleMode
'])); 207 $modes = array_unique(GeneralUtility::trimExplode('-
', $p['mode
'])); 209 $revmodes = array_flip($modes); 210 // Find special modes and extract them: 211 if (isset($revmodes['ts
'])) { 212 $modes[$revmodes['ts
']] = 'ts_transform,ts_preserve,ts_images,ts_links
'; 214 // Find special modes and extract them: 215 if (isset($revmodes['ts_css
'])) { 216 $modes[$revmodes['ts_css
']] = 'css_transform,ts_images,ts_links
'; 219 $modes = array_unique(GeneralUtility::trimExplode(',
', implode(',
', $modes), TRUE)); 220 // Reverse order if direction is "rte" 221 if ($direction == 'rte
') { 222 $modes = array_reverse($modes); 224 // Getting additional HTML cleaner configuration. These are applied either before or after the main transformation is done and is thus totally independant processing options you can set up: 225 $entry_HTMLparser = $this->procOptions['entryHTMLparser_
' . $direction] ? $this->HTMLparserConfig($this->procOptions['entryHTMLparser_
' . $direction . '.
']) : ''; 226 $exit_HTMLparser = $this->procOptions['exitHTMLparser_
' . $direction] ? $this->HTMLparserConfig($this->procOptions['exitHTMLparser_
' . $direction . '.
']) : ''; 227 // Line breaks of content is unified into char-10 only (removing char 13) 228 if (!$this->procOptions['disableUnifyLineBreaks
']) { 229 $value = str_replace(CRLF, LF, $value); 231 // In an entry-cleaner was configured, pass value through the HTMLcleaner with that: 232 if (is_array($entry_HTMLparser)) { 233 $value = $this->HTMLcleaner($value, $entry_HTMLparser[0], $entry_HTMLparser[1], $entry_HTMLparser[2], $entry_HTMLparser[3]); 236 foreach ($modes as $cmd) { 238 if ($direction == 'db
') { 239 // Checking for user defined transformation: 240 if ($_classRef = $GLOBALS['TYPO3_CONF_VARS
']['SC_OPTIONS
']['t3lib/
class.t3lib_parsehtml_proc.php
']['transformation
'][$cmd]) { 241 $_procObj = GeneralUtility::getUserObj($_classRef); 242 $_procObj->pObj = $this; 243 $_procObj->transformationKey = $cmd; 244 $value = $_procObj->transform_db($value, $this); 246 // ... else use defaults: 249 $value = $this->TS_images_db($value); 252 $value = $this->TS_reglinks($value, 'db
'); 255 $value = $this->TS_links_db($value); 258 $value = $this->TS_preserve_db($value); 262 case 'css_transform
': 263 $this->allowedClasses = GeneralUtility::trimExplode(',
', $this->procOptions['allowedClasses
'], TRUE); 264 // CR has a very disturbing effect, so just remove all CR and rely on LF 265 $value = str_replace(CR, '', $value); 266 // Transform empty paragraphs into spacing paragraphs 267 $value = str_replace('<p></p>
', '<p> </p>
', $value); 268 // Double any trailing spacing paragraph so that it does not get removed by divideIntoLines() 269 $value = preg_replace('/<p> <\/p>$/
', '<p> </p>
' . '<p> </p>
', $value); 270 $value = $this->TS_transform_db($value, $cmd == 'css_transform
'); 273 $value = $this->TS_strip_db($value); 281 if ($direction == 'rte
') { 282 // Checking for user defined transformation: 283 if ($_classRef = $GLOBALS['TYPO3_CONF_VARS
']['SC_OPTIONS
']['t3lib/
class.t3lib_parsehtml_proc.php
']['transformation
'][$cmd]) { 284 $_procObj = GeneralUtility::getUserObj($_classRef); 285 $_procObj->pObj = $this; 286 $value = $_procObj->transform_rte($value, $this); 288 // ... else use defaults: 291 $value = $this->TS_images_rte($value); 294 $value = $this->TS_reglinks($value, 'rte
'); 297 $value = $this->TS_links_rte($value); 300 $value = $this->TS_preserve_rte($value); 304 case 'css_transform
': 305 // Has a very disturbing effect, so just remove all '13
' - depend on '10
' 306 $value = str_replace(CR, '', $value); 307 $value = $this->TS_transform_rte($value, $cmd == 'css_transform
'); 315 // In an exit-cleaner was configured, pass value through the HTMLcleaner with that: 316 if (is_array($exit_HTMLparser)) { 317 $value = $this->HTMLcleaner($value, $exit_HTMLparser[0], $exit_HTMLparser[1], $exit_HTMLparser[2], $exit_HTMLparser[3]); 319 // Final clean up of linebreaks: 320 if (!$this->procOptions['disableUnifyLineBreaks
']) { 321 // Make sure no \r\n sequences has entered in the meantime... 322 $value = str_replace(CRLF, LF, $value); 323 // ... and then change all \n into \r\n 324 $value = str_replace(LF, CRLF, $value); 330 /************************************ 332 * Specific RTE TRANSFORMATION functions 334 *************************************/ 347 public function TS_images_db($value) { 348 // Split content by <img> tags and traverse the resulting array for processing: 349 $imgSplit = $this->splitTags('img
', $value); 350 if (count($imgSplit) > 1) { 351 $siteUrl = $this->siteUrl(); 352 $sitePath = str_replace(GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST
'), '', $siteUrl); 354 $resourceFactory = Resource\ResourceFactory::getInstance(); 356 $magicImageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Service\\MagicImageService
'); 357 $magicImageService->setMagicImageMaximumDimensions($this->tsConfig); 358 foreach ($imgSplit as $k => $v) { 359 // Image found, do processing: 362 $attribArray = $this->get_tag_attributes_classic($v, 1); 363 // It's always an absolute URL coming from the RTE into the Database.
364 $absoluteUrl = trim($attribArray[
'src']);
366 $pI = pathinfo($absoluteUrl);
369 $absoluteUrl = substr($absoluteUrl, strlen($sitePath));
370 $absoluteUrl = $siteUrl . $absoluteUrl;
374 if ($imgTagDimensions[0]) {
375 $attribArray[
'width'] = $imgTagDimensions[0];
377 if ($imgTagDimensions[1]) {
378 $attribArray[
'height'] = $imgTagDimensions[1];
380 $originalImageFile = NULL;
381 if ($attribArray[
'data-htmlarea-file-uid']) {
385 $originalImageFile = $resourceFactory->getFileObject(intval($attribArray[
'data-htmlarea-file-uid']));
386 }
catch (Resource\
Exception\FileDoesNotExistException $fileDoesNotExistException) {
388 $message = sprintf(
'Could not find file with uid "%s"', $attribArray[
'data-htmlarea-file-uid']);
389 $this->getLogger()->error($message);
392 if ($originalImageFile instanceof Resource\
File) {
394 if ($absoluteUrl == $originalImageFile->getPublicUrl() || $absoluteUrl == $siteUrl . $originalImageFile->getPublicUrl()) {
396 if ($this->procOptions[
'plainImageMode']) {
400 $originalImageFile->getProperty(
'width'),
401 $originalImageFile->getProperty(
'height')
403 if (!$imageInfo[0] || !$imageInfo[1]) {
404 $filePath = $originalImageFile->getForLocalProcessing(FALSE);
405 $imageInfo = @getimagesize($filePath);
411 $imageConfiguration = array(
412 'width' => $imgTagDimensions[0],
413 'height' => $imgTagDimensions[1]
415 $magicImage = $magicImageService->createMagicImage($originalImageFile, $imageConfiguration);
416 $attribArray[
'width'] = $magicImage->getProperty(
'width');
417 $attribArray[
'height'] = $magicImage->getProperty(
'height');
418 $attribArray[
'src'] = $magicImage->getPublicUrl();
423 $externalFile = $this->
getUrl($absoluteUrl);
425 $pU = parse_url($absoluteUrl);
426 $pI = pathinfo($pU[
'path']);
430 $folder = $GLOBALS[
'BE_USER']->getDefaultUploadFolder();
431 $fileObject = $folder->createFile($fileName)->setContents($externalFile);
432 $imageConfiguration = array(
433 'width' => $attribArray[
'width'],
434 'height' => $attribArray[
'height']
436 $magicImage = $magicImageService->createMagicImage($fileObject, $imageConfiguration);
437 $attribArray[
'width'] = $magicImage->getProperty(
'width');
438 $attribArray[
'height'] = $magicImage->getProperty(
'height');
439 $attribArray[
'data-htmlarea-file-uid'] = $fileObject->getUid();
440 $attribArray[
'data-htmlarea-file-table'] =
'sys_file';
441 $attribArray[
'src'] = $magicImage->getPublicUrl();
448 $path = rawurldecode(substr($absoluteUrl, strlen($siteUrl)));
452 if ($filepath && @is_file($filepath)) {
454 if ($this->procOptions[
'plainImageMode']) {
457 $imageInfo = @getimagesize($filepath);
462 $fileOrFolderObject = $resourceFactory->retrieveFileOrFolderObject($path);
464 $fileIdentifier = $fileOrFolderObject->getIdentifier();
465 $fileObject = $fileOrFolderObject->getStorage()->getFile($fileIdentifier);
467 $attribArray[
'data-htmlarea-file-uid'] = $fileObject->getUid();
468 $attribArray[
'data-htmlarea-file-table'] =
'sys_file';
476 $attribArray[
'style'] = preg_replace(
'/((?:^|)\\s*(?:width|height)\\s*:[^;]*(?:$|;))/si',
'', $attribArray[
'style']);
478 if (!isset($attribArray[
'alt'])) {
479 $attribArray[
'alt'] =
'';
483 $attribArray[
'src'] = $this->relBackPath . substr($attribArray[
'src'], strlen($siteUrl));
489 return implode(
'', $imgSplit);
502 $imgSplit = $this->
splitTags(
'img', $value);
503 if (count($imgSplit) > 1) {
506 foreach ($imgSplit as $k => $v) {
511 $absoluteUrl = trim($attribArray[
'src']);
513 if (strtolower(substr($absoluteUrl, 0, 4)) !==
'http') {
514 $attribArray[
'src'] = substr($attribArray[
'src'], strlen($this->relBackPath));
516 $attribArray[
'src'] = preg_replace(
'#^' . preg_quote($sitePath,
'#') .
'#',
'', $attribArray[
'src']);
517 $attribArray[
'src'] = $siteUrl . $attribArray[
'src'];
520 if (!isset($attribArray[
'alt'])) {
521 $attribArray[
'alt'] =
'';
528 return implode(
'', $imgSplit);
542 switch ($direction) {
549 foreach ($blockSplit as $k => $v) {
554 if ($siteURL && substr($attribArray[
'href'], 0, strlen($siteURL)) == $siteURL) {
555 $attribArray[
'href'] = $this->relBackPath . substr($attribArray[
'href'], strlen($siteURL));
562 $retVal = implode(
'', $blockSplit);
581 foreach ($blockSplit as $k => $v) {
587 $attribArray_copy = $attribArray;
588 unset($attribArray_copy[
'href']);
589 unset($attribArray_copy[
'target']);
590 unset($attribArray_copy[
'class']);
591 unset($attribArray_copy[
'title']);
592 unset($attribArray_copy[
'data-htmlarea-external']);
594 if ($attribArray_copy[
'rteerror']) {
595 unset($attribArray_copy[
'style']);
596 unset($attribArray_copy[
'rteerror']);
599 if (isset($GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_parsehtml_proc.php'][
'removeParams_PostProc']) && is_array($GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_parsehtml_proc.php'][
'removeParams_PostProc'])) {
602 'aTagParams' => &$attribArray_copy
604 foreach ($GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_parsehtml_proc.php'][
'removeParams_PostProc'] as $objRef) {
606 $attribArray_copy = $processor->removeParams(
$parameters, $this);
610 if (!count($attribArray_copy)) {
612 $attribArray[
'class'] = preg_match(
'/ /', $attribArray[
'class']) ?
'"' . $attribArray[
'class'] .
'"' : $attribArray[
'class'];
613 $attribArray[
'title'] = preg_match(
'/ /', $attribArray[
'title']) ?
'"' . $attribArray[
'title'] .
'"' : $attribArray[
'title'];
616 if ($attribArray[
'data-htmlarea-external']) {
617 $href = $attribArray[
'href'];
619 $href = $info[
'url'] . ($info[
'query'] ?
',0,' . $info[
'query'] :
'');
621 $bTag =
'<link ' . $href . ($attribArray[
'target'] ?
' ' . $attribArray[
'target'] : ($attribArray[
'class'] || $attribArray[
'title'] ?
' -' :
'')) . ($attribArray[
'class'] ?
' ' . $attribArray[
'class'] : ($attribArray[
'title'] ?
' -' :
'')) . ($attribArray[
'title'] ?
' ' . $attribArray[
'title'] :
'') .
'>';
624 if (isset($GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_parsehtml_proc.php'][
'modifyParams_LinksDb_PostProc']) && is_array($GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_parsehtml_proc.php'][
'modifyParams_LinksDb_PostProc'])) {
627 'currentBlock' => $v,
629 'attributes' => $attribArray
631 foreach ($GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_parsehtml_proc.php'][
'modifyParams_LinksDb_PostProc'] as $objRef) {
633 $blockSplit[$k] = $processor->modifyParamsLinksDb(
$parameters, $this);
641 unset($attribArray[
'rtekeep']);
642 if (!$attribArray[
'data-htmlarea-external']) {
645 if ($siteURL && substr($attribArray[
'href'], 0, strlen($siteURL)) == $siteURL) {
646 $attribArray[
'href'] = $this->relBackPath . substr($attribArray[
'href'], strlen($siteURL));
649 list($linkHandlerKeyword, $linkHandlerValue) = explode(
':', $attribArray[
'href'], 2);
650 if ($linkHandlerKeyword ===
'?file') {
653 if ($fileOrFolderObject instanceof \
TYPO3\CMS\Core\Resource\FileInterface || $fileOrFolderObject instanceof \
TYPO3\CMS\Core\Resource\
Folder) {
654 $attribArray[
'href'] = $fileOrFolderObject->getPublicUrl();
661 unset($attribArray[
'data-htmlarea-external']);
668 return implode(
'', $blockSplit);
686 foreach ($blockSplit as $k => $v) {
692 $link_param = $tagCode[1];
696 $pU = parse_url($link_param);
697 if (strstr($link_param,
'@') && (!$pU[
'scheme'] || $pU[
'scheme'] ==
'mailto')) {
699 $href =
'mailto:' . preg_replace(
'/^mailto:/i',
'', $link_param);
700 } elseif ($link_param[0] ===
'#') {
702 $href = $siteUrl . $link_param;
705 list($linkHandlerKeyword, $linkHandlerValue) = explode(
':', trim($link_param), 2);
707 $href = $siteUrl .
'?' . $linkHandlerKeyword .
':' . rawurlencode($linkHandlerValue);
709 $fileChar = (int)strpos($link_param,
'/');
710 $urlChar = (int)strpos($link_param,
'.');
712 list($rootFileDat) = explode(
'?', $link_param);
713 $rFD_fI = pathinfo($rootFileDat);
714 if (trim($rootFileDat) && !strstr($link_param,
'/') && (@is_file((PATH_site . $rootFileDat)) ||
GeneralUtility::inList(
'php,html,htm', strtolower($rFD_fI[
'extension'])))) {
715 $href = $siteUrl . $link_param;
719 && !isset($GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'tslib/class.tslib_content.php'][
'typolinkLinkHandler'][$pU[
'scheme']])
721 || $urlChar && (!$fileChar || $urlChar < $fileChar)
725 if (!$pU[
'scheme']) {
726 $href =
'http://' . $href;
729 } elseif ($fileChar) {
736 $fileOrFolderObject = NULL;
738 if ($fileOrFolderObject instanceof \
TYPO3\CMS\Core\Resource\
Folder) {
740 $folderIdentifier = $fileOrFolderObject->getIdentifier();
741 $href = $siteUrl .
'?file:' . rawurlencode($folderIdentifier);
742 } elseif ($fileOrFolderObject instanceof \
TYPO3\CMS\Core\Resource\FileInterface) {
744 $fileIdentifier = $fileOrFolderObject->getIdentifier();
745 $fileObject = $fileOrFolderObject->getStorage()->getFile($fileIdentifier);
746 $href = $siteUrl .
'?file:' . $fileObject->getUid();
748 $href = $siteUrl . $link_param;
754 $idPart = $pairParts[0];
755 $link_params_parts = explode(
'#', $idPart);
756 $idPart = trim($link_params_parts[0]);
757 $sectionMark = trim($link_params_parts[1]);
758 if ((
string)$idPart ===
'') {
765 $idPart = (int)$idPartR[
'uid'];
767 $page = BackendUtility::getRecord(
'pages', $idPart);
768 if (is_array($page)) {
770 $href = $siteUrl .
'?id=' . $idPart . ($pairParts[2] ? $pairParts[2] :
'') . ($sectionMark ?
'#' . $sectionMark :
'');
771 } elseif (isset($GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'tslib/class.tslib_content.php'][
'typolinkLinkHandler'][array_shift(explode(
':', $link_param))])) {
774 $href = $siteUrl .
'?id=' . $link_param;
775 $error =
'No page found: ' . $idPart;
781 $bTag =
'<a href="' . htmlspecialchars($href) .
'"' . ($tagCode[2] && $tagCode[2] !=
'-' ?
' target="' . htmlspecialchars($tagCode[2]) .
'"' :
'') . ($tagCode[3] && $tagCode[3] !=
'-' ?
' class="' . htmlspecialchars($tagCode[3]) .
'"' :
'') . ($tagCode[4] ?
' title="' . htmlspecialchars($tagCode[4]) .
'"' :
'') . ($external ?
' data-htmlarea-external="1"' :
'') . ($error ?
' rteerror="' . htmlspecialchars($error) .
'" style="background-color: yellow; border:2px red solid; color: black;"' :
'') .
'>';
784 if (isset($GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_parsehtml_proc.php'][
'modifyParams_LinksRte_PostProc']) && is_array($GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_parsehtml_proc.php'][
'modifyParams_LinksRte_PostProc'])) {
787 'currentBlock' => $v,
789 'tagCode' => $tagCode,
790 'external' => $external,
793 foreach ($GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_parsehtml_proc.php'][
'modifyParams_LinksRte_PostProc'] as $objRef) {
795 $blockSplit[$k] = $processor->modifyParamsLinksRte(
$parameters, $this);
803 return implode(
'', $blockSplit);
814 if (!$this->preserveTags) {
819 foreach ($blockSplit as $k => $v) {
823 if ($attribArray[
'specialtag']) {
824 $theTag = rawurldecode($attribArray[
'specialtag']);
826 $blockSplit[$k] = $theTag . $this->
removeFirstAndLastTag($blockSplit[$k]) .
'</' . $theTagName .
'>';
830 return implode(
'', $blockSplit);
841 if (!$this->preserveTags) {
845 foreach ($blockSplit as $k => $v) {
851 return implode(
'', $blockSplit);
866 $this->TS_transform_db_safecounter--;
867 if ($this->TS_transform_db_safecounter < 0) {
871 $blockSplit = $this->
splitIntoBlock(
'TABLE,BLOCKQUOTE,' . ($this->procOptions[
'preserveDIVSections'] ?
'DIV,' :
'') . $this->blockElementList, $value);
873 $aC = count($blockSplit);
875 while ($aC && trim($blockSplit[($aC - 1)]) ===
'') {
876 unset($blockSplit[$aC - 1]);
877 $aC = count($blockSplit);
880 foreach ($blockSplit as $k => $v) {
882 $lastBR = $cc == $aC ?
'' : LF;
914 if (!isset($this->procOptions[
'typolist']) || $this->procOptions[
'typolist']) {
916 foreach ($parts as $k2 => $value) {
917 $parts[$k2] = preg_replace(
'/[' . LF . CR .
']+/',
'', $parts[$k2]);
921 $parts[$k2] = $this->
HTMLcleaner_db($parts[$k2], strtolower($this->procOptions[
'allowTagsInTypolists'] ? $this->procOptions[
'allowTagsInTypolists'] :
'br,font,b,i,u,a,img,span,strong,em'));
923 if ($tagName ==
'ol') {
924 $params =
' type="1"';
928 $blockSplit[$k] =
'<typolist' . $params .
'>' . LF . implode(LF, $parts) . LF .
'</typolist>' . $lastBR;
931 $blockSplit[$k] = preg_replace((
'/[' . LF . CR .
']+/'),
' ', $this->
transformStyledATags($blockSplit[$k])) . $lastBR;
936 if (!$this->procOptions[
'preserveTables'] && !$css) {
939 $blockSplit[$k] = preg_replace((
'/[' . LF . CR .
']+/'),
' ', $this->
transformStyledATags($blockSplit[$k])) . $lastBR;
957 if (!isset($this->procOptions[
'typohead']) || $this->procOptions[
'typohead']) {
958 $type = (int)substr($tagName, 1);
959 $blockSplit[$k] =
'<typohead' . ($type != 6 ?
' type="' . $type .
'"' :
'') . ($attribArray[
'align'] ?
' align="' . $attribArray[
'align'] .
'"' :
'') . ($attribArray[
'class'] ?
' class="' . $attribArray[
'class'] .
'"' :
'') .
'>' . $innerContent .
'</typohead>' . $lastBR;
961 $blockSplit[$k] =
'<' . $tagName . ($attribArray[
'align'] ?
' align="' . htmlspecialchars($attribArray[
'align']) .
'"' :
'') . ($attribArray[
'class'] ?
' class="' . htmlspecialchars($attribArray[
'class']) .
'"' :
'') .
'>' . $innerContent .
'</' . $tagName .
'>' . $lastBR;
965 $blockSplit[$k] = preg_replace((
'/[' . LF . CR .
']+/'),
' ', $this->
transformStyledATags($blockSplit[$k])) . $lastBR;
970 $blockSplit[$k] = preg_replace((
'/[' . LF . CR .
']+/'),
' ', $this->
transformStyledATags($blockSplit[$k])) . $lastBR;
974 if (trim($blockSplit[$k]) !==
'') {
975 $blockSplit[$k] = preg_replace(
'/<hr\\/>/',
'<hr />', $blockSplit[$k]);
977 $blockSplit[$k] = preg_replace(
'/[' . LF . CR .
']+<(hr)(\\s[^>\\/]*)?[[:space:]]*\\/?>/',
'<$1$2/>', $blockSplit[$k]);
979 $blockSplit[$k] = preg_replace(
'/<(hr)(\\s[^>\\/]*)?[[:space:]]*\\/?>[' . LF . CR .
']+/',
'<$1$2/>', $blockSplit[$k]);
981 $blockSplit[$k] = preg_replace(
'/[' . LF . CR .
']+/',
' ', $blockSplit[$k]);
985 unset($blockSplit[$k]);
989 $this->TS_transform_db_safecounter++;
990 return implode(
'', $blockSplit);
1002 foreach ($blockSplit as $k => $v) {
1007 if ($attribArray[
'style'] && !$attribArray[
'rteerror']) {
1008 $attribArray_copy[
'style'] = $attribArray[
'style'];
1009 unset($attribArray[
'style']);
1011 $eTag =
'</a></span>';
1016 return implode(
'', $blockSplit);
1031 $blockElementList =
'TABLE,BLOCKQUOTE,TYPOLIST,TYPOHEAD,' . ($this->procOptions[
'preserveDIVSections'] ?
'DIV,' :
'') . $this->blockElementList;
1034 foreach ($blockSplit as $k => $v) {
1064 if (!isset($this->procOptions[
'typolist']) || $this->procOptions[
'typolist']) {
1066 $tListContent = preg_replace(
'/^[ ]*' . LF .
'/',
'', $tListContent);
1067 $tListContent = preg_replace(
'/' . LF .
'[ ]*$/',
'', $tListContent);
1068 $lines = explode(LF, $tListContent);
1069 $typ = $attribArray[
'type'] == 1 ?
'ol' :
'ul';
1070 $blockSplit[$k] =
'<' . $typ .
'>' . LF .
'<li>' . implode((
'</li>' . LF .
'<li>'), $lines) .
'</li>' .
'</' . $typ .
'>';
1075 if (!isset($this->procOptions[
'typohead']) || $this->procOptions[
'typohead']) {
1081 $align = $attribArray[
'align'] ?
' align="' . $attribArray[
'align'] .
'"' :
'';
1082 $class = $attribArray[
'class'] ?
' class="' . $attribArray[
'class'] .
'"' :
'';
1083 $blockSplit[$k] =
'<h' . $typ . $align . $class .
'>' . $tC .
'</h' . $typ .
'>';
1087 $blockSplit[$k + 1] = preg_replace(
'/^[ ]*' . LF .
'/',
'', $blockSplit[$k + 1]);
1091 $onlyLineBreaks = (preg_match(
'/^[ ]*' . LF .
'+[ ]*$/', $blockSplit[$k]) == 1);
1095 if (!$onlyLineBreaks) {
1096 $blockSplit[$k] = preg_replace(
'/(' . LF .
'*)' . LF .
'[ ]*$/',
'$1', $blockSplit[$k]);
1099 $blockSplit[$k] = preg_replace(
'/^[ ]*' . LF .
'/',
'', $blockSplit[$k]);
1103 if ((
string)$blockSplit[$k] ===
'' && !$onlyLineBreaks) {
1104 unset($blockSplit[$k]);
1106 $blockSplit[$k] = $this->
setDivTags($blockSplit[$k], $this->procOptions[
'useDIVasParagraphTagForRTE'] ?
'div' :
'p');
1110 return implode(LF, $blockSplit);
1122 $value = strip_tags($value,
'<' . implode(
'><', explode(
',',
'b,i,u,a,img,br,div,center,pre,font,hr,sub,sup,p,strong,em,li,ul,ol,blockquote')) .
'>');
1161 $kUknown = $this->procOptions[
'dontRemoveUnknownTags_db'] ? 1 : 0;
1163 $hSC = $this->procOptions[
'dontUndoHSC_db'] ? 0 : -1;
1165 $addConfig = array();
1166 if (is_array($this->procOptions[
'HTMLparser_db.']) && $this->procOptions[
'HTMLparser_db.'][
'xhtml_cleaning'] || is_array($this->procOptions[
'entryHTMLparser_db.']) && $this->procOptions[
'entryHTMLparser_db.'][
'xhtml_cleaning'] || is_array($this->procOptions[
'exitHTMLparser_db.']) && $this->procOptions[
'exitHTMLparser_db.'][
'xhtml_cleaning']) {
1167 $addConfig[
'xhtml'] = 1;
1169 return $this->HTMLcleaner($content, $keepTags, $kUknown, $hSC, $addConfig);
1183 if (!is_array($this->getKeepTags_cache[$direction]) || $tagList) {
1186 if ((
string)$tagList !==
'') {
1191 $typoScript_list =
'b,i,u,a,img,br,div,center,pre,font,hr,sub,sup,p,strong,em,li,ul,ol,blockquote,strike,span';
1192 $keepTags = array_flip(
GeneralUtility::trimExplode(
',', $typoScript_list .
',' . strtolower($this->procOptions[
'allowTags']), TRUE));
1195 foreach ($denyTags as $dKe) {
1196 unset($keepTags[$dKe]);
1200 switch ($direction) {
1202 if (!isset($this->procOptions[
'transformBoldAndItalicTags']) || $this->procOptions[
'transformBoldAndItalicTags']) {
1204 if (isset($keepTags[
'b'])) {
1205 $keepTags[
'b'] = array(
'remap' =>
'STRONG');
1207 if (isset($keepTags[
'i'])) {
1208 $keepTags[
'i'] = array(
'remap' =>
'EM');
1212 list($keepTags) = $this->
HTMLparserConfig($this->procOptions[
'HTMLparser_rte.'], $keepTags);
1215 if (!isset($this->procOptions[
'transformBoldAndItalicTags']) || $this->procOptions[
'transformBoldAndItalicTags']) {
1217 if (isset($keepTags[
'strong'])) {
1218 $keepTags[
'strong'] = array(
'remap' =>
'b');
1220 if (isset($keepTags[
'em'])) {
1221 $keepTags[
'em'] = array(
'remap' =>
'i');
1225 if (isset($keepTags[
'span'])) {
1226 $classes = array_merge(array(
''), $this->allowedClasses);
1227 $keepTags[
'span'] = array(
1228 'allowedAttribs' =>
'id,class,style,title,lang,xml:lang,dir,itemscope,itemtype,itemprop',
1229 'fixAttrib' => array(
1232 'removeIfFalse' => 1
1235 'rmTagIfNoAttrib' => 1
1237 if (!$this->procOptions[
'allowedClasses']) {
1238 unset($keepTags[
'span'][
'fixAttrib'][
'class'][
'list']);
1242 if (isset($keepTags[
'font'])) {
1244 $keepTags[
'font'] = array(
1245 'allowedAttribs' =>
'face,color,size',
1246 'fixAttrib' => array(
1248 'removeIfFalse' => 1
1251 'removeIfFalse' => 1,
1255 'removeIfFalse' => 1
1258 'rmTagIfNoAttrib' => 1
1260 if (!$this->procOptions[
'allowedFontColors']) {
1261 unset($keepTags[
'font'][
'fixAttrib'][
'color'][
'list']);
1265 $TSc = $this->procOptions[
'HTMLparser_db.'];
1266 if (!$TSc[
'globalNesting']) {
1267 $TSc[
'globalNesting'] =
'b,i,u,a,center,font,sub,sup,strong,em,strike,span';
1269 if (!$TSc[
'noAttrib']) {
1270 $TSc[
'noAttrib'] =
'b,i,u,br,center,hr,sub,sup,strong,em,li,ul,ol,blockquote,strike';
1278 $this->getKeepTags_cache[$direction] = $keepTags;
1284 return $this->getKeepTags_cache[$direction];
1302 if ($this->procOptions[
'internalizeFontTags']) {
1306 $allowTagsOutside =
GeneralUtility::trimExplode(
',', strtolower($this->procOptions[
'allowTagsOutside'] ?
'hr,' . $this->procOptions[
'allowTagsOutside'] :
'hr,img'), TRUE);
1307 $remapParagraphTag = strtoupper($this->procOptions[
'remapParagraphTag']);
1310 if ($this->procOptions[
'keepPDIVattribs']) {
1313 $keepAttribListArr = array();
1316 if (count($divSplit) <= 1 || $count <= 0) {
1318 $newValue = preg_replace(
'/<(hr)(\\s[^>\\/]*)?[[:space:]]*\\/?>/i', LF .
'<$1$2/>' . LF, $value);
1319 $newValue = preg_replace(
'/' . LF . LF .
'/i', LF, $newValue);
1320 $newValue = preg_replace(
'/(^' . LF .
')|(' . LF .
'$)/i',
'', $newValue);
1324 foreach ($divSplit as $k => $v) {
1331 if (is_array($subLines)) {
1335 $subLines = array($subLines);
1337 if (!$this->procOptions[
'dontConvBRtoParagraph']) {
1338 $subLines = preg_split(
'/<br[[:space:]]*[\\/]?>/i', $v);
1341 foreach ($subLines as $sk => $value) {
1349 $newAttribs = array();
1350 if (count($keepAttribListArr)) {
1351 foreach ($keepAttribListArr as $keepA) {
1352 if (isset($attribs[0][$keepA])) {
1353 $newAttribs[$keepA] = $attribs[0][$keepA];
1358 if (!$this->procOptions[
'skipAlign'] && trim($attribs[0][
'align']) !==
'' && strtolower($attribs[0][
'align']) !=
'left') {
1360 $newAttribs[
'align'] = strtolower($attribs[0][
'align']);
1364 if (!$this->procOptions[
'skipClass'] && trim($attribs[0][
'class']) !==
'') {
1365 if (!count($this->allowedClasses) || in_array($attribs[0][
'class'], $this->allowedClasses)) {
1366 $newAttribs[
'class'] = $attribs[0][
'class'];
1369 $newClasses = array();
1370 foreach ($classes as $class) {
1371 if (in_array($class, $this->allowedClasses)) {
1372 $newClasses[] = $class;
1375 if (count($newClasses)) {
1376 $newAttribs[
'class'] = implode(
' ', $newClasses);
1381 $subLines[$sk] = preg_replace(
'/' . LF .
'|' . CR .
'/',
'', $subLines[$sk]);
1383 if (count($newAttribs) && $remapParagraphTag !==
'1') {
1384 if ($remapParagraphTag ===
'P') {
1387 if ($remapParagraphTag ===
'DIV') {
1390 $subLines[$sk] =
'<' . trim(($tagName .
' ' . $this->
compileTagAttribs($newAttribs))) .
'>' . $subLines[$sk] .
'</' . $tagName .
'>';
1395 $divSplit[$k] = implode(LF, $subLines);
1399 if (trim(strip_tags($divSplit[$k])) ==
' ' && !preg_match(
'/\\<(img)(\\s[^>]*)?\\/?>/si', $divSplit[$k]) && !preg_match(
'/\\<([^>]*)?( align| class| style| id| title| dir| lang| xml:lang)([^>]*)?>/si', trim($divSplit[$k]))) {
1405 $divSplit[$k] = trim(strip_tags($divSplit[$k],
'<' . implode(
'><', $allowTagsOutside) .
'>'));
1407 $divSplit[$k] = preg_replace(
'/<(hr)(\\s[^>\\/]*)?[[:space:]]*\\/?>/i', LF .
'<$1$2/>' . LF, $divSplit[$k]);
1408 $divSplit[$k] = preg_replace(
'/' . LF . LF .
'/i', LF, $divSplit[$k]);
1409 $divSplit[$k] = preg_replace(
'/(^' . LF .
')|(' . LF .
'$)/i',
'', $divSplit[$k]);
1410 if ((
string)$divSplit[$k] ===
'') {
1411 unset($divSplit[$k]);
1416 return $returnArray ? $divSplit : implode(LF, $divSplit);
1433 $kUknown = $this->procOptions[
'dontProtectUnknownTags_rte'] ? 0 :
'protect';
1435 $hSC = $this->procOptions[
'dontHSC_rte'] ? 0 : 1;
1436 $convNBSP = !$this->procOptions[
'dontConvAmpInNBSP_rte'] ? 1 : 0;
1438 $parts = explode(LF, $value);
1439 foreach ($parts as $k => $v) {
1442 if (trim($parts[$k]) ===
'') {
1443 $parts[$k] =
' ';
1446 $parts[$k] = $this->HTMLcleaner($parts[$k], $keepTags, $kUknown, $hSC);
1448 $parts[$k] = str_replace(
'&nbsp;',
' ', $parts[$k]);
1452 if (!preg_match(
'/<(hr)(\\s[^>\\/]*)?[[:space:]]*\\/?>/i', $parts[$k])) {
1453 $testStr = strtolower(trim($parts[$k]));
1454 if (substr($testStr, 0, 4) !=
'<div' || substr($testStr, -6) !=
'</div>') {
1455 if (substr($testStr, 0, 2) !=
'<p' || substr($testStr, -4) !=
'</p>') {
1457 $parts[$k] =
'<' . $dT .
'>' . $parts[$k] .
'</' . $dT .
'>';
1463 return implode(LF, $parts);
1481 foreach ($fontSplit as $k => $v) {
1488 if (count($divSplit_sub) > 1) {
1490 foreach ($divSplit_sub as $k2 => $v2) {
1499 $divSplit_sub[$k2] = $div_p . $fTag . $v2 .
'</font>' .
'</' . $div_p_tagname .
'>';
1500 } elseif (trim(strip_tags($v2))) {
1501 $divSplit_sub[$k2] = $fTag . $v2 .
'</font>';
1504 $fontSplit[$k] = implode(
'', $divSplit_sub);
1508 return implode(
'', $fontSplit);
1530 return $this->rte_p[
'imgpath'] ? $this->rte_p[
'imgpath'] : $GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'RTE_imageStorageDir'];
1546 foreach ($tableSplit as $k => $v) {
1548 $tableSplit[$k] =
'';
1550 foreach ($rowSplit as $k2 => $v2) {
1553 foreach ($cellSplit as $k3 => $v3) {
1554 $tableSplit[$k] .= $v3 . $breakChar;
1561 return implode($breakChar, $tableSplit);
1573 if ($direction ==
'db') {
1574 $code = $this->
mapTags($code, array(
1580 if ($direction ==
'rte') {
1581 $code = $this->
mapTags($code, array(
1599 $style = trim($attribArray[
'style']);
1601 $regex =
'[[:space:]]*:[[:space:]]*([0-9]*)[[:space:]]*px';
1604 preg_match(
'/width' . $regex .
'/i', $style, $reg);
1607 preg_match(
'/height' . $regex .
'/i', $style, $reg);
1611 $w = $attribArray[
'width'];
1614 $h = $attribArray[
'height'];
1616 return array((
int)$w, (
int)$h);
1629 if (substr(strtolower($url), 0, 7) ==
'mailto:') {
1630 $info[
'url'] = trim(substr($url, 7));
1631 $info[
'type'] =
'email';
1632 } elseif (strpos($url,
'?file:') !== FALSE) {
1633 $info[
'type'] =
'file';
1634 $info[
'url'] = rawurldecode(substr($url, strpos($url,
'?file:') + 1));
1637 $urlLength = strlen($url);
1638 for ($a = 0; $a < $urlLength; $a++) {
1639 if ($url[$a] != $curURL[$a]) {
1643 $info[
'relScriptPath'] = substr($curURL, $a);
1644 $info[
'relUrl'] = substr($url, $a);
1645 $info[
'url'] = $url;
1646 $info[
'type'] =
'ext';
1647 $siteUrl_parts = parse_url($url);
1648 $curUrl_parts = parse_url($curURL);
1650 if ($siteUrl_parts[
'host'] == $curUrl_parts[
'host'] && (!$info[
'relScriptPath'] || defined(
'TYPO3_mainDir') && substr($info[
'relScriptPath'], 0, strlen(TYPO3_mainDir)) == TYPO3_mainDir)) {
1653 $uP = parse_url($info[
'relUrl']);
1654 if ($info[
'relUrl'] ===
'#' . $siteUrl_parts[
'fragment']) {
1655 $info[
'url'] = $info[
'relUrl'];
1656 $info[
'type'] =
'anchor';
1657 } elseif (!trim($uP[
'path']) || $uP[
'path'] ===
'index.php') {
1659 $pp = preg_split(
'/^id=/', $uP[
'query']);
1660 $pp[1] = preg_replace(
'/&id=[^&]*/',
'', $pp[1]);
1664 $info[
'pageid'] = $id;
1665 $info[
'cElement'] = $uP[
'fragment'];
1666 $info[
'url'] = $id . ($info[
'cElement'] ?
'#' . $info[
'cElement'] :
'');
1667 $info[
'type'] =
'page';
1671 $info[
'url'] = $info[
'relUrl'];
1672 $info[
'type'] =
'file';
1675 unset($info[
'relScriptPath']);
1676 unset($info[
'relUrl']);
1692 foreach ($blockSplit as $k => $v) {
1698 if (strlen($attribArray[
'href'])) {
1699 $uP = parse_url(strtolower($attribArray[
'href']));
1700 if (!$uP[
'scheme']) {
1701 $attribArray[
'href'] = $this->
siteUrl() . substr($attribArray[
'href'], strlen($this->relBackPath));
1702 } elseif ($uP[
'scheme'] !=
'mailto') {
1703 $attribArray[
'data-htmlarea-external'] = 1;
1706 $attribArray[
'rtekeep'] = 1;
1708 if (!$dontSetRTEKEEP) {
1709 $attribArray[
'rtekeep'] = 1;
1716 return implode(
'', $blockSplit);
1728 if ($this->procOptions[
'plainImageMode']) {
1730 switch ((
string) $this->procOptions[
'plainImageMode']) {
1731 case 'lockDimensions':
1732 $attribArray[
'width'] = $imageInfo[0];
1733 $attribArray[
'height'] = $imageInfo[1];
1735 case 'lockRatioWhenSmaller':
1736 if ($attribArray[
'width'] > $imageInfo[0]) {
1737 $attribArray[
'width'] = $imageInfo[0];
1740 if ($imageInfo[0] > 0) {
1741 $attribArray[
'height'] = round($attribArray[
'width'] * ($imageInfo[1] / $imageInfo[0]));
1746 return $attribArray;
1752 protected function getLogger() {
1757 return $logManager->getLogger(get_class($this));
getFirstTagName($str, $preserveCase=FALSE)
TS_AtagToAbs($value, $dontSetRTEKEEP=FALSE)
splitIntoBlock($tag, $content, $eliminateExtraEndTags=FALSE)
static implodeAttributes(array $arr, $xhtmlSafe=FALSE, $dontOmitBlankAttribs=FALSE)
TS_reglinks($value, $direction)
setDivTags($value, $dT='p')
removeFirstAndLastTag($str)
static getRecordsByField($theTable, $theField, $theValue, $whereClause='', $groupBy='', $orderBy='', $limit='', $useDeleteClause=TRUE)
HTMLcleaner_db($content, $tagList='')
static isFirstPartOfStr($str, $partStr)
static validPathStr($theFile)
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
removeTables($value, $breakChar='< br/>')
mapTags($value, $tags=array(), $ltChar='<', $ltChar2='<')
applyPlainImageModeSettings($imageInfo, $attribArray)
HTMLparserConfig($TSconfig, $keepTags=array())
static canBeInterpretedAsInteger($var)
static getIndpEnv($getEnvName)
static getUserObj($classRef, $checkPrefix='', $silent=FALSE)
static logDeprecatedFunction()
TS_transform_rte($value, $css=0)
getAllParts($parts, $tag_parts=TRUE, $include_tag=TRUE)
static makeInstance($className)
static shortMD5($input, $len=10)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
compileTagAttribs($tagAttrib, $meta=array(), $xhtmlClean=0)
get_tag_attributes($tag, $deHSC=0)
static unQuoteFilenames($parameters, $unQuote=FALSE)
splitTags($tag, $content)
getKeepTags($direction='rte', $tagList='')
defaultTStagMapping($code, $direction='rte')
static getUrl($url, $includeHeader=0, $requestHeaders=FALSE, &$report=NULL)
getWHFromAttribs($attribArray)
divideIntoLines($value, $count=5, $returnArray=FALSE)
init($elRef='', $recPid=0)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
cleanFontTags($value, $keepFace=0, $keepSize=0, $keepColor=0)
static inList($list, $item)
static getFileAbsFileName($filename, $onlyRelative=TRUE, $relToTYPO3_mainDir=FALSE)
$TS_transform_db_safecounter
TS_transform_db($value, $css=FALSE)
static evalWriteFile($pArr, $currentRecord)
transformStyledATags($value)
get_tag_attributes_classic($tag, $deHSC=0)
internalizeFontTags($value)