[TASK] Refactor core usages of testInt, calcPriority, calcParenthesis
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_parsehtml_proc.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Functions for parsing HTML, specially for TYPO3 processing in relation to TCEmain and Rich Text Editor (RTE)
29 * Revised for TYPO3 3.6 December/2003 by Kasper Skårhøj
30 * XHTML compatible.
31 *
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
33 * @internal
34 */
35
36
37 /**
38 * Class for parsing HTML for the Rich Text Editor. (also called transformations)
39 *
40 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
41 * @package TYPO3
42 * @subpackage t3lib
43 */
44 class t3lib_parsehtml_proc extends t3lib_parsehtml {
45
46 // Static:
47 var $blockElementList = 'PRE,UL,OL,H1,H2,H3,H4,H5,H6,ADDRESS,DL,DD'; // List of tags for these elements
48
49 // Internal, static:
50 var $recPid = 0; // Set this to the pid of the record manipulated by the class.
51 var $elRef = ''; // Element reference [table]:[field], eg. "tt_content:bodytext"
52 var $relPath = ''; // Relative path
53 var $relBackPath = ''; // Relative back-path
54 public $tsConfig = array(); // Current Page TSConfig
55 var $procOptions = ''; // Set to the TSconfig options coming from Page TSconfig
56
57 // Internal, dynamic
58 var $TS_transform_db_safecounter = 100; // Run-away brake for recursive calls.
59 var $rte_p = ''; // Parameters from TCA types configuration related to the RTE
60 var $getKeepTags_cache = array(); // Data caching for processing function
61 var $allowedClasses = array(); // Storage of the allowed CSS class names in the RTE
62 var $preserveTags = ''; // Set to tags to preserve from Page TSconfig configuration
63
64
65 /**
66 * Initialize, setting element reference and record PID
67 *
68 * @param string Element reference, eg "tt_content:bodytext"
69 * @param integer PID of the record (page id)
70 * @return void
71 */
72 function init($elRef = '', $recPid = 0) {
73 $this->recPid = $recPid;
74 $this->elRef = $elRef;
75 }
76
77 /**
78 * Setting the ->relPath and ->relBackPath to proper values so absolute references to links and images can be converted to relative dittos.
79 * This is used when editing files with the RTE
80 *
81 * @param string The relative path from PATH_site to the place where the file being edited is. Eg. "fileadmin/static".
82 * @return void There is no output, it is set in internal variables. With the above example of "fileadmin/static" as input this will yield ->relPath to be "fileadmin/static/" and ->relBackPath to be "../../"
83 */
84 function setRelPath($path) {
85 $path = trim($path);
86 $path = preg_replace('/^\//', '', $path);
87 $path = preg_replace('/\/$/', '', $path);
88 if ($path) {
89 $this->relPath = $path;
90 $this->relBackPath = '';
91 $partsC = count(explode('/', $this->relPath));
92 for ($a = 0; $a < $partsC; $a++) {
93 $this->relBackPath .= '../';
94 }
95 $this->relPath .= '/';
96 }
97 }
98
99 /**
100 * Evaluate the environment for editing a staticFileEdit file.
101 * Called for almost all fields being saved in the database. Is called without an instance of the object: t3lib_parsehtml_proc::evalWriteFile()
102 *
103 * @param array Parameters for the current field as found in types-config
104 * @param array Current record we are editing.
105 * @return mixed On success an array with various information is returned, otherwise a string with an error message
106 * @see t3lib_TCEmain, t3lib_transferData
107 */
108 public static function evalWriteFile($pArr, $currentRecord) {
109
110 // Write file configuration:
111 if (is_array($pArr)) {
112 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath']
113 && substr($GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'], -1) == '/'
114 && @is_dir(PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'])) {
115
116 $SW_p = $pArr['parameters'];
117 $SW_editFileField = trim($SW_p[0]);
118 $SW_editFile = $currentRecord[$SW_editFileField];
119 if ($SW_editFileField && $SW_editFile && t3lib_div::validPathStr($SW_editFile)) {
120 $SW_relpath = $GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'] . $SW_editFile;
121 $SW_editFile = PATH_site . $SW_relpath;
122 if (@is_file($SW_editFile)) {
123 return array(
124 'editFile' => $SW_editFile,
125 'relEditFile' => $SW_relpath,
126 'contentField' => trim($SW_p[1]),
127 'markerField' => trim($SW_p[2]),
128 'loadFromFileField' => trim($SW_p[3]),
129 'statusField' => trim($SW_p[4])
130 );
131 } else {
132 return "ERROR: Editfile '" . $SW_relpath . "' did not exist";
133 }
134 } else {
135 return "ERROR: Edit file name could not be found or was bad.";
136 }
137 } else {
138 return "ERROR: staticFileEditPath was not set, not set correctly or did not exist!";
139 }
140 }
141 }
142
143
144 /**********************************************
145 *
146 * Main function
147 *
148 **********************************************/
149
150 /**
151 * Transform value for RTE based on specConf in the direction specified by $direction (rte/db)
152 * This is the main function called from tcemain and transfer data classes
153 *
154 * @param string Input value
155 * @param array Special configuration for a field; This is coming from the types-configuration of the field in the TCA. In the types-configuration you can setup features for the field rendering and in particular the RTE takes al its major configuration options from there!
156 * @param string Direction of the transformation. Two keywords are allowed; "db" or "rte". If "db" it means the transformation will clean up content coming from the Rich Text Editor and goes into the database. The other direction, "rte", is of course when content is coming from database and must be transformed to fit the RTE.
157 * @param array Parsed TypoScript content configuring the RTE, probably coming from Page TSconfig.
158 * @return string Output value
159 * @see t3lib_TCEmain::fillInFieldArray(), t3lib_transferData::renderRecord_typesProc()
160 */
161 function RTE_transform($value, $specConf, $direction = 'rte', $thisConfig = array()) {
162
163 // Init:
164 $this->tsConfig = $thisConfig;
165 $this->procOptions = $thisConfig['proc.'];
166 $this->preserveTags = strtoupper(implode(',', t3lib_div::trimExplode(',', $this->procOptions['preserveTags'])));
167
168 // dynamic configuration of blockElementList
169 if ($this->procOptions['blockElementList']) {
170 $this->blockElementList = $this->procOptions['blockElementList'];
171 }
172
173 // Get parameters for rte_transformation:
174 $p = $this->rte_p = t3lib_BEfunc::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
175
176 // Setting modes:
177 if (strcmp($this->procOptions['overruleMode'], '')) {
178 $modes = array_unique(t3lib_div::trimExplode(',', $this->procOptions['overruleMode']));
179 } else {
180 $modes = array_unique(t3lib_div::trimExplode('-', $p['mode']));
181 }
182 $revmodes = array_flip($modes);
183
184 // Find special modes and extract them:
185 if (isset($revmodes['ts'])) {
186 $modes[$revmodes['ts']] = 'ts_transform,ts_preserve,ts_images,ts_links';
187 }
188 // Find special modes and extract them:
189 if (isset($revmodes['ts_css'])) {
190 $modes[$revmodes['ts_css']] = 'css_transform,ts_images,ts_links';
191 }
192
193 // Make list unique
194 $modes = array_unique(t3lib_div::trimExplode(',', implode(',', $modes), 1));
195
196 // Reverse order if direction is "rte"
197 if ($direction == 'rte') {
198 $modes = array_reverse($modes);
199 }
200
201 // 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:
202 $entry_HTMLparser = $this->procOptions['entryHTMLparser_' . $direction] ? $this->HTMLparserConfig($this->procOptions['entryHTMLparser_' . $direction . '.']) : '';
203 $exit_HTMLparser = $this->procOptions['exitHTMLparser_' . $direction] ? $this->HTMLparserConfig($this->procOptions['exitHTMLparser_' . $direction . '.']) : '';
204
205 // Line breaks of content is unified into char-10 only (removing char 13)
206 if (!$this->procOptions['disableUnifyLineBreaks']) {
207 $value = str_replace(CRLF, LF, $value);
208 }
209
210 // In an entry-cleaner was configured, pass value through the HTMLcleaner with that:
211 if (is_array($entry_HTMLparser)) {
212 $value = $this->HTMLcleaner($value, $entry_HTMLparser[0], $entry_HTMLparser[1], $entry_HTMLparser[2], $entry_HTMLparser[3]);
213 }
214
215 // Traverse modes:
216 foreach ($modes as $cmd) {
217 // ->DB
218 if ($direction == 'db') {
219 // Checking for user defined transformation:
220 if ($_classRef = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['transformation'][$cmd]) {
221 $_procObj = t3lib_div::getUserObj($_classRef);
222 $_procObj->pObj = $this;
223 $_procObj->transformationKey = $cmd;
224 $value = $_procObj->transform_db($value, $this);
225 } else { // ... else use defaults:
226 switch ($cmd) {
227 case 'ts_images':
228 $value = $this->TS_images_db($value);
229 break;
230 case 'ts_reglinks':
231 $value = $this->TS_reglinks($value, 'db');
232 break;
233 case 'ts_links':
234 $value = $this->TS_links_db($value);
235 break;
236 case 'ts_preserve':
237 $value = $this->TS_preserve_db($value);
238 break;
239 case 'ts_transform':
240 case 'css_transform':
241 $value = str_replace(CR, '', $value); // Has a very disturbing effect, so just remove all '13' - depend on '10'
242 $this->allowedClasses = t3lib_div::trimExplode(',', $this->procOptions['allowedClasses'], 1);
243 $value = $this->TS_transform_db($value, $cmd == 'css_transform');
244 break;
245 case 'ts_strip':
246 $value = $this->TS_strip_db($value);
247 break;
248 default:
249 break;
250 }
251 }
252 }
253 // ->RTE
254 if ($direction == 'rte') {
255 // Checking for user defined transformation:
256 if ($_classRef = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['transformation'][$cmd]) {
257 $_procObj = t3lib_div::getUserObj($_classRef);
258 $_procObj->pObj = $this;
259 $value = $_procObj->transform_rte($value, $this);
260 } else { // ... else use defaults:
261 switch ($cmd) {
262 case 'ts_images':
263 $value = $this->TS_images_rte($value);
264 break;
265 case 'ts_reglinks':
266 $value = $this->TS_reglinks($value, 'rte');
267 break;
268 case 'ts_links':
269 $value = $this->TS_links_rte($value);
270 break;
271 case 'ts_preserve':
272 $value = $this->TS_preserve_rte($value);
273 break;
274 case 'ts_transform':
275 case 'css_transform':
276 $value = str_replace(CR, '', $value); // Has a very disturbing effect, so just remove all '13' - depend on '10'
277 $value = $this->TS_transform_rte($value, $cmd == 'css_transform');
278 break;
279 default:
280 break;
281 }
282 }
283 }
284 }
285
286 // In an exit-cleaner was configured, pass value through the HTMLcleaner with that:
287 if (is_array($exit_HTMLparser)) {
288 $value = $this->HTMLcleaner($value, $exit_HTMLparser[0], $exit_HTMLparser[1], $exit_HTMLparser[2], $exit_HTMLparser[3]);
289 }
290
291 // Final clean up of linebreaks:
292 if (!$this->procOptions['disableUnifyLineBreaks']) {
293 $value = str_replace(CRLF, LF, $value); // Make sure no \r\n sequences has entered in the meantime...
294 $value = str_replace(LF, CRLF, $value); // ... and then change all \n into \r\n
295 }
296
297 // Return value:
298 return $value;
299 }
300
301
302 /************************************
303 *
304 * Specific RTE TRANSFORMATION functions
305 *
306 *************************************/
307
308 /**
309 * Transformation handler: 'ts_images' / direction: "db"
310 * Processing images inserted in the RTE.
311 * This is used when content goes from the RTE to the database.
312 * Images inserted in the RTE has an absolute URL applied to the src attribute. This URL is converted to a relative URL
313 * If it turns out that the URL is from another website than the current the image is read from that external URL and moved to the local server.
314 * Also "magic" images are processed here.
315 *
316 * @param string The content from RTE going to Database
317 * @return string Processed content
318 */
319 function TS_images_db($value) {
320
321 // Split content by <img> tags and traverse the resulting array for processing:
322 $imgSplit = $this->splitTags('img', $value);
323 foreach ($imgSplit as $k => $v) {
324 if ($k % 2) { // image found, do processing:
325
326 // Init
327 $attribArray = $this->get_tag_attributes_classic($v, 1);
328 $siteUrl = $this->siteUrl();
329 $sitePath = str_replace(t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST'), '', $siteUrl);
330
331 $absRef = trim($attribArray['src']); // It's always a absolute URL coming from the RTE into the Database.
332
333 // make path absolute if it is relative and we have a site path wich is not '/'
334 $pI = pathinfo($absRef);
335 if ($sitePath AND !$pI['scheme'] && t3lib_div::isFirstPartOfStr($absRef, $sitePath)) {
336 // if site is in a subpath (eg. /~user_jim/) this path needs to be removed because it will be added with $siteUrl
337 $absRef = substr($absRef, strlen($sitePath));
338 $absRef = $siteUrl . $absRef;
339 }
340
341 // External image from another URL? In that case, fetch image (unless disabled feature).
342 if (!t3lib_div::isFirstPartOfStr($absRef, $siteUrl) && !$this->procOptions['dontFetchExtPictures']) {
343 $externalFile = $this->getUrl($absRef); // Get it
344 if ($externalFile) {
345 $pU = parse_url($absRef);
346 $pI = pathinfo($pU['path']);
347
348 if (t3lib_div::inList('gif,png,jpeg,jpg', strtolower($pI['extension']))) {
349 $filename = t3lib_div::shortMD5($absRef) . '.' . $pI['extension'];
350 $origFilePath = PATH_site . $this->rteImageStorageDir() . 'RTEmagicP_' . $filename;
351 $C_origFilePath = PATH_site . $this->rteImageStorageDir() . 'RTEmagicC_' . $filename . '.' . $pI['extension'];
352 if (!@is_file($origFilePath)) {
353 t3lib_div::writeFile($origFilePath, $externalFile);
354 t3lib_div::writeFile($C_origFilePath, $externalFile);
355 }
356 $absRef = $siteUrl . $this->rteImageStorageDir() . 'RTEmagicC_' . $filename . '.' . $pI['extension'];
357
358 $attribArray['src'] = $absRef;
359 $params = t3lib_div::implodeAttributes($attribArray, 1);
360 $imgSplit[$k] = '<img ' . $params . ' />';
361 }
362 }
363 }
364
365 // Check image as local file (siteURL equals the one of the image)
366 if (t3lib_div::isFirstPartOfStr($absRef, $siteUrl)) {
367 $path = rawurldecode(substr($absRef, strlen($siteUrl))); // Rel-path, rawurldecoded for special characters.
368 $filepath = t3lib_div::getFileAbsFileName($path); // Abs filepath, locked to relative path of this project.
369
370 // Check file existence (in relative dir to this installation!)
371 if ($filepath && @is_file($filepath)) {
372
373 // If "magic image":
374 $pathPre = $this->rteImageStorageDir() . 'RTEmagicC_';
375 if (t3lib_div::isFirstPartOfStr($path, $pathPre)) {
376 // Find original file:
377 $pI = pathinfo(substr($path, strlen($pathPre)));
378 $filename = substr($pI['basename'], 0, -strlen('.' . $pI['extension']));
379 $origFilePath = PATH_site . $this->rteImageStorageDir() . 'RTEmagicP_' . $filename;
380 if (@is_file($origFilePath)) {
381 $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
382 $imgObj->init();
383 $imgObj->mayScaleUp = 0;
384 $imgObj->tempPath = PATH_site . $imgObj->tempPath;
385
386 $curInfo = $imgObj->getImageDimensions($filepath); // Image dimensions of the current image
387 $curWH = $this->getWHFromAttribs($attribArray); // Image dimensions as set in the image tag
388 // Compare dimensions:
389 if ($curWH[0] != $curInfo[0] || $curWH[1] != $curInfo[1]) {
390 $origImgInfo = $imgObj->getImageDimensions($origFilePath); // Image dimensions of the current image
391 $cW = $curWH[0];
392 $cH = $curWH[1];
393 $cH = 1000; // Make the image based on the width solely...
394 $imgI = $imgObj->imageMagickConvert($origFilePath, $pI['extension'], $cW . 'm', $cH . 'm');
395 if ($imgI[3]) {
396 $fI = pathinfo($imgI[3]);
397 @copy($imgI[3], $filepath); // Override the child file
398 // Removing width and heigth form style attribute
399 $attribArray['style'] = preg_replace('/((?:^|)\s*(?:width|height)\s*:[^;]*(?:$|;))/si', '', $attribArray['style']);
400 $attribArray['width'] = $imgI[0];
401 $attribArray['height'] = $imgI[1];
402 $params = t3lib_div::implodeAttributes($attribArray, 1);
403 $imgSplit[$k] = '<img ' . $params . ' />';
404 }
405 }
406 }
407
408 } elseif ($this->procOptions['plainImageMode']) { // If "plain image" has been configured:
409
410 // Image dimensions as set in the image tag, if any
411 $curWH = $this->getWHFromAttribs($attribArray);
412 if ($curWH[0]) {
413 $attribArray['width'] = $curWH[0];
414 }
415 if ($curWH[1]) {
416 $attribArray['height'] = $curWH[1];
417 }
418
419 // Removing width and heigth form style attribute
420 $attribArray['style'] = preg_replace('/((?:^|)\s*(?:width|height)\s*:[^;]*(?:$|;))/si', '', $attribArray['style']);
421
422 // Finding dimensions of image file:
423 $fI = @getimagesize($filepath);
424
425 // Perform corrections to aspect ratio based on configuration:
426 switch ((string) $this->procOptions['plainImageMode']) {
427 case 'lockDimensions':
428 $attribArray['width'] = $fI[0];
429 $attribArray['height'] = $fI[1];
430 break;
431 case 'lockRatioWhenSmaller': // If the ratio has to be smaller, then first set the width...:
432 if ($attribArray['width'] > $fI[0]) {
433 $attribArray['width'] = $fI[0];
434 }
435 case 'lockRatio':
436 if ($fI[0] > 0) {
437 $attribArray['height'] = round($attribArray['width'] * ($fI[1] / $fI[0]));
438 }
439 break;
440 }
441
442 // Compile the image tag again:
443 $params = t3lib_div::implodeAttributes($attribArray, 1);
444 $imgSplit[$k] = '<img ' . $params . ' />';
445 }
446 } else { // Remove image if it was not found in a proper position on the server!
447
448 // Commented out; removing the image tag might not be that logical...
449 // $imgSplit[$k]='';
450 }
451 }
452
453 // Convert abs to rel url
454 if ($imgSplit[$k]) {
455 $attribArray = $this->get_tag_attributes_classic($imgSplit[$k], 1);
456 $absRef = trim($attribArray['src']);
457 if (t3lib_div::isFirstPartOfStr($absRef, $siteUrl)) {
458 $attribArray['src'] = $this->relBackPath . substr($absRef, strlen($siteUrl));
459 if (!isset($attribArray['alt'])) {
460 $attribArray['alt'] = '';
461 } // Must have alt-attribute for XHTML compliance.
462 $imgSplit[$k] = '<img ' . t3lib_div::implodeAttributes($attribArray, 1, 1) . ' />';
463 }
464 }
465 }
466 }
467 return implode('', $imgSplit);
468 }
469
470 /**
471 * Transformation handler: 'ts_images' / direction: "rte"
472 * Processing images from database content going into the RTE.
473 * Processing includes converting the src attribute to an absolute URL.
474 *
475 * @param string Content input
476 * @return string Content output
477 */
478 function TS_images_rte($value) {
479
480 $siteUrl = $this->siteUrl();
481 $sitePath = str_replace(t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST'), '', $siteUrl);
482
483 // Split content by <img> tags and traverse the resulting array for processing:
484 $imgSplit = $this->splitTags('img', $value);
485 foreach ($imgSplit as $k => $v) {
486 if ($k % 2) { // image found:
487
488 // Init
489 $attribArray = $this->get_tag_attributes_classic($v, 1);
490 $absRef = trim($attribArray['src']);
491
492 // Unless the src attribute is already pointing to an external URL:
493 if (strtolower(substr($absRef, 0, 4)) != 'http') {
494 $attribArray['src'] = substr($attribArray['src'], strlen($this->relBackPath));
495 // if site is in a subpath (eg. /~user_jim/) this path needs to be removed because it will be added with $siteUrl
496 $attribArray['src'] = preg_replace('#^' . preg_quote($sitePath, '#') . '#', '', $attribArray['src']);
497 $attribArray['src'] = $siteUrl . $attribArray['src'];
498 if (!isset($attribArray['alt'])) {
499 $attribArray['alt'] = '';
500 }
501 $params = t3lib_div::implodeAttributes($attribArray);
502 $imgSplit[$k] = '<img ' . $params . ' />';
503 }
504 }
505 }
506
507 // return processed content:
508 return implode('', $imgSplit);
509 }
510
511 /**
512 * Transformation handler: 'ts_reglinks' / direction: "db"+"rte" depending on $direction variable.
513 * Converting <A>-tags to/from abs/rel
514 *
515 * @param string Content input
516 * @param string Direction of conversion; "rte" (from database to RTE) or "db" (from RTE to database)
517 * @return string Content output
518 */
519 function TS_reglinks($value, $direction) {
520 $retVal = '';
521
522 switch ($direction) {
523 case 'rte':
524 $retVal = $this->TS_AtagToAbs($value, 1);
525 break;
526 case 'db':
527 $siteURL = $this->siteUrl();
528 $blockSplit = $this->splitIntoBlock('A', $value);
529 foreach ($blockSplit as $k => $v) {
530 if ($k % 2) { // block:
531 $attribArray = $this->get_tag_attributes_classic($this->getFirstTag($v), 1);
532 // If the url is local, remove url-prefix
533 if ($siteURL && substr($attribArray['href'], 0, strlen($siteURL)) == $siteURL) {
534 $attribArray['href'] = $this->relBackPath . substr($attribArray['href'], strlen($siteURL));
535 }
536 $bTag = '<a ' . t3lib_div::implodeAttributes($attribArray, 1) . '>';
537 $eTag = '</a>';
538 $blockSplit[$k] = $bTag . $this->TS_reglinks($this->removeFirstAndLastTag($blockSplit[$k]), $direction) . $eTag;
539 }
540 }
541 $retVal = implode('', $blockSplit);
542 break;
543 }
544 return $retVal;
545 }
546
547 /**
548 * Transformation handler: 'ts_links' / direction: "db"
549 * Converting <A>-tags to <link tags>
550 *
551 * @param string Content input
552 * @return string Content output
553 * @see TS_links_rte()
554 */
555 function TS_links_db($value) {
556
557 // Split content into <a> tag blocks and process:
558 $blockSplit = $this->splitIntoBlock('A', $value);
559 foreach ($blockSplit as $k => $v) {
560 if ($k % 2) { // If an A-tag was found:
561 $attribArray = $this->get_tag_attributes_classic($this->getFirstTag($v), 1);
562 $info = $this->urlInfoForLinkTags($attribArray['href']);
563
564 // Check options:
565 $attribArray_copy = $attribArray;
566 unset($attribArray_copy['href']);
567 unset($attribArray_copy['target']);
568 unset($attribArray_copy['class']);
569 unset($attribArray_copy['title']);
570 unset($attribArray_copy['external']);
571 if ($attribArray_copy['rteerror']) { // Unset "rteerror" and "style" attributes if "rteerror" is set!
572 unset($attribArray_copy['style']);
573 unset($attribArray_copy['rteerror']);
574 }
575 if (!count($attribArray_copy)) { // Only if href, target and class are the only attributes, we can alter the link!
576 // Quoting class and title attributes if they contain spaces
577 $attribArray['class'] = preg_match('/ /', $attribArray['class']) ? '"' . $attribArray['class'] . '"' : $attribArray['class'];
578 $attribArray['title'] = preg_match('/ /', $attribArray['title']) ? '"' . $attribArray['title'] . '"' : $attribArray['title'];
579 // Creating the TYPO3 pseudo-tag "<LINK>" for the link (includes href/url, target and class attributes):
580 // If external attribute is set, keep the href unchanged
581 $href = $attribArray['external'] ? $attribArray['href'] : $info['url'] . ($info['query'] ? ',0,' . $info['query'] : '');
582 $bTag = '<link ' . $href . ($attribArray['target'] ? ' ' . $attribArray['target'] : (($attribArray['class'] || $attribArray['title']) ? ' -' : '')) . ($attribArray['class'] ? ' ' . $attribArray['class'] : ($attribArray['title'] ? ' -' : '')) . ($attribArray['title'] ? ' ' . $attribArray['title'] : '') . '>';
583 $eTag = '</link>';
584 $blockSplit[$k] = $bTag . $this->TS_links_db($this->removeFirstAndLastTag($blockSplit[$k])) . $eTag;
585 } else { // ... otherwise store the link as a-tag.
586 // Unsetting 'rtekeep' attribute if that had been set.
587 unset($attribArray['rtekeep']);
588 if (!$attribArray['external']) {
589 // If the url is local, remove url-prefix
590 $siteURL = $this->siteUrl();
591 if ($siteURL && substr($attribArray['href'], 0, strlen($siteURL)) == $siteURL) {
592 $attribArray['href'] = $this->relBackPath . substr($attribArray['href'], strlen($siteURL));
593 }
594 }
595 unset($attribArray['external']);
596 $bTag = '<a ' . t3lib_div::implodeAttributes($attribArray, 1) . '>';
597 $eTag = '</a>';
598 $blockSplit[$k] = $bTag . $this->TS_links_db($this->removeFirstAndLastTag($blockSplit[$k])) . $eTag;
599 }
600 }
601 }
602 return implode('', $blockSplit);
603 }
604
605 /**
606 * Transformation handler: 'ts_links' / direction: "rte"
607 * Converting <link tags> to <A>-tags
608 *
609 * @param string Content input
610 * @return string Content output
611 * @see TS_links_rte()
612 */
613 function TS_links_rte($value) {
614 $value = $this->TS_AtagToAbs($value);
615
616 // Split content by the TYPO3 pseudo tag "<link>":
617 $blockSplit = $this->splitIntoBlock('link', $value, 1);
618 $siteUrl = $this->siteUrl();
619 foreach ($blockSplit as $k => $v) {
620 $error = '';
621 if ($k % 2) { // block:
622 $tagCode = t3lib_div::unQuoteFilenames(trim(substr($this->getFirstTag($v), 0, -1)), TRUE);
623 $link_param = $tagCode[1];
624 $href = '';
625 // Parsing the typolink data. This parsing is roughly done like in tslib_content->typolink()
626 if (strstr($link_param, '@')) { // mailadr
627 $href = 'mailto:' . preg_replace('/^mailto:/i', '', $link_param);
628 } elseif (substr($link_param, 0, 1) == '#') { // check if anchor
629 $href = $siteUrl . $link_param;
630 } else {
631 $fileChar = intval(strpos($link_param, '/'));
632 $urlChar = intval(strpos($link_param, '.'));
633 $external = FALSE;
634 // Parse URL:
635 $pU = parse_url($link_param);
636 // Detects if a file is found in site-root OR is a simulateStaticDocument.
637 list($rootFileDat) = explode('?', $link_param);
638 $rFD_fI = pathinfo($rootFileDat);
639 if (trim($rootFileDat) && !strstr($link_param, '/') && (@is_file(PATH_site . $rootFileDat) || t3lib_div::inList('php,html,htm', strtolower($rFD_fI['extension'])))) {
640 $href = $siteUrl . $link_param;
641 } elseif ($pU['scheme'] || ($urlChar && (!$fileChar || $urlChar < $fileChar))) {
642 // url (external): if has scheme or if a '.' comes before a '/'.
643 $href = $link_param;
644 if (!$pU['scheme']) {
645 $href = 'http://' . $href;
646 }
647 $external = TRUE;
648 } elseif ($fileChar) { // file (internal)
649 $href = $siteUrl . $link_param;
650 } else { // integer or alias (alias is without slashes or periods or commas, that is 'nospace,alphanum_x,lower,unique' according to tables.php!!)
651 // Splitting the parameter by ',' and if the array counts more than 1 element it's a id/type/parameters triplet
652 $pairParts = t3lib_div::trimExplode(',', $link_param, TRUE);
653 $idPart = $pairParts[0];
654 $link_params_parts = explode('#', $idPart);
655 $idPart = trim($link_params_parts[0]);
656 $sectionMark = trim($link_params_parts[1]);
657 if (!strcmp($idPart, '')) {
658 $idPart = $this->recPid;
659 } // If no id or alias is given, set it to class record pid
660 // Checking if the id-parameter is an alias.
661 if (!t3lib_utility_Math::canBeInterpretedAsInteger($idPart)) {
662 list($idPartR) = t3lib_BEfunc::getRecordsByField('pages', 'alias', $idPart);
663 $idPart = intval($idPartR['uid']);
664 }
665 $page = t3lib_BEfunc::getRecord('pages', $idPart);
666 if (is_array($page)) { // Page must exist...
667 $href = $siteUrl . '?id=' . $idPart . ($pairParts[2] ? $pairParts[2] : '') . ($sectionMark ? '#' . $sectionMark : '');
668 // linkHandler - allowing links to start with registerd linkHandler e.g.. "record:"
669 } elseif (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typolinkLinkHandler'][array_shift(explode(':', $link_param))])) {
670 $href = $link_param;
671 } else {
672 #$href = '';
673 $href = $siteUrl . '?id=' . $link_param;
674 $error = 'No page found: ' . $idPart;
675 }
676 }
677 }
678
679 // Setting the A-tag:
680 $bTag = '<a href="' . htmlspecialchars($href) . '"' .
681 ($tagCode[2] && $tagCode[2] != '-' ? ' target="' . htmlspecialchars($tagCode[2]) . '"' : '') .
682 ($tagCode[3] && $tagCode[3] != '-' ? ' class="' . htmlspecialchars($tagCode[3]) . '"' : '') .
683 ($tagCode[4] ? ' title="' . htmlspecialchars($tagCode[4]) . '"' : '') .
684 ($external ? ' external="1"' : '') .
685 ($error ? ' rteerror="' . htmlspecialchars($error) . '" style="background-color: yellow; border:2px red solid; color: black;"' : '') . // Should be OK to add the style; the transformation back to databsae will remove it...
686 '>';
687 $eTag = '</a>';
688 $blockSplit[$k] = $bTag . $this->TS_links_rte($this->removeFirstAndLastTag($blockSplit[$k])) . $eTag;
689 }
690 }
691
692 // Return content:
693 return implode('', $blockSplit);
694 }
695
696 /**
697 * Preserve special tags
698 *
699 * @param string Content input
700 * @return string Content output
701 */
702 function TS_preserve_db($value) {
703 if (!$this->preserveTags) {
704 return $value;
705 }
706
707 // Splitting into blocks for processing (span-tags are used for special tags)
708 $blockSplit = $this->splitIntoBlock('span', $value);
709 foreach ($blockSplit as $k => $v) {
710 if ($k % 2) { // block:
711 $attribArray = $this->get_tag_attributes_classic($this->getFirstTag($v));
712 if ($attribArray['specialtag']) {
713 $theTag = rawurldecode($attribArray['specialtag']);
714 $theTagName = $this->getFirstTagName($theTag);
715 $blockSplit[$k] = $theTag . $this->removeFirstAndLastTag($blockSplit[$k]) . '</' . $theTagName . '>';
716 }
717 }
718 }
719 return implode('', $blockSplit);
720 }
721
722 /**
723 * Preserve special tags
724 *
725 * @param string Content input
726 * @return string Content output
727 */
728 function TS_preserve_rte($value) {
729 if (!$this->preserveTags) {
730 return $value;
731 }
732
733 $blockSplit = $this->splitIntoBlock($this->preserveTags, $value);
734 foreach ($blockSplit as $k => $v) {
735 if ($k % 2) { // block:
736 $blockSplit[$k] = '<span specialtag="' . rawurlencode($this->getFirstTag($v)) . '">' . $this->removeFirstAndLastTag($blockSplit[$k]) . '</span>';
737 }
738 }
739 return implode('', $blockSplit);
740 }
741
742 /**
743 * Transformation handler: 'ts_transform' + 'css_transform' / direction: "db"
744 * Cleaning (->db) for standard content elements (ts)
745 *
746 * @param string Content input
747 * @param boolean If TRUE, the transformation was "css_transform", otherwise "ts_transform"
748 * @return string Content output
749 * @see TS_transform_rte()
750 */
751 function TS_transform_db($value, $css = FALSE) {
752
753 // safety... so forever loops are avoided (they should not occur, but an error would potentially do this...)
754 $this->TS_transform_db_safecounter--;
755 if ($this->TS_transform_db_safecounter < 0) {
756 return $value;
757 }
758
759 // Split the content from RTE by the occurence of these blocks:
760 $blockSplit = $this->splitIntoBlock('TABLE,BLOCKQUOTE,' . ($this->procOptions['preserveDIVSections'] ? 'DIV,' : '') . $this->blockElementList, $value);
761
762 $cc = 0;
763 $aC = count($blockSplit);
764
765 // Avoid superfluous linebreaks by transform_db after ending headListTag
766 while ($aC && !strcmp(trim($blockSplit[$aC - 1]), '')) {
767 unset($blockSplit[$aC - 1]);
768 $aC = count($blockSplit);
769 }
770
771 // Traverse the blocks
772 foreach ($blockSplit as $k => $v) {
773 $cc++;
774 $lastBR = $cc == $aC ? '' : LF;
775
776 if ($k % 2) { // Inside block:
777
778 // Init:
779 $tag = $this->getFirstTag($v);
780 $tagName = strtolower($this->getFirstTagName($v));
781
782 // Process based on the tag:
783 switch ($tagName) {
784 case 'blockquote': // Keep blockquotes, but clean the inside recursively in the same manner as the main code
785 case 'dd' : // Do the same on dd elements
786 case 'div': // Do the same on div sections, if they were splitted
787 $blockSplit[$k] = $tag . $this->TS_transform_db($this->removeFirstAndLastTag($blockSplit[$k]), $css) . '</' . $tagName . '>' . $lastBR;
788 break;
789 case 'ol':
790 case 'ul': // Transform lists into <typolist>-tags:
791 if (!$css) {
792 if (!isset($this->procOptions['typolist']) || $this->procOptions['typolist']) {
793 $parts = $this->getAllParts($this->splitIntoBlock('LI', $this->removeFirstAndLastTag($blockSplit[$k])), 1, 0);
794 foreach ($parts as $k2 => $value) {
795 $parts[$k2] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', '', $parts[$k2]); // remove all linesbreaks!
796 $parts[$k2] = $this->defaultTStagMapping($parts[$k2], 'db');
797 $parts[$k2] = $this->cleanFontTags($parts[$k2], 0, 0, 0);
798 $parts[$k2] = $this->HTMLcleaner_db($parts[$k2], strtolower($this->procOptions['allowTagsInTypolists'] ? $this->procOptions['allowTagsInTypolists'] : 'br,font,b,i,u,a,img,span,strong,em'));
799 }
800 if ($tagName == 'ol') {
801 $params = ' type="1"';
802 } else {
803 $params = '';
804 }
805 $blockSplit[$k] = '<typolist' . $params . '>' . LF . implode(LF, $parts) . LF . '</typolist>' . $lastBR;
806 }
807 } else {
808 $blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
809 }
810 break;
811 case 'table': // Tables are NOT allowed in any form (unless preserveTables is set or CSS is the mode)
812 if (!$this->procOptions['preserveTables'] && !$css) {
813 $blockSplit[$k] = $this->TS_transform_db($this->removeTables($blockSplit[$k]));
814 } else {
815 $blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
816 }
817 break;
818 case 'h1':
819 case 'h2':
820 case 'h3':
821 case 'h4':
822 case 'h5':
823 case 'h6':
824 if (!$css) {
825 $attribArray = $this->get_tag_attributes_classic($tag);
826 // Processing inner content here:
827 $innerContent = $this->HTMLcleaner_db($this->removeFirstAndLastTag($blockSplit[$k]));
828
829 if (!isset($this->procOptions['typohead']) || $this->procOptions['typohead']) {
830 $type = intval(substr($tagName, 1));
831 $blockSplit[$k] = '<typohead' .
832 ($type != 6 ? ' type="' . $type . '"' : '') .
833 ($attribArray['align'] ? ' align="' . $attribArray['align'] . '"' : '') .
834 ($attribArray['class'] ? ' class="' . $attribArray['class'] . '"' : '') .
835 '>' .
836 $innerContent .
837 '</typohead>' .
838 $lastBR;
839 } else {
840 $blockSplit[$k] = '<' . $tagName .
841 ($attribArray['align'] ? ' align="' . htmlspecialchars($attribArray['align']) . '"' : '') .
842 ($attribArray['class'] ? ' class="' . htmlspecialchars($attribArray['class']) . '"' : '') .
843 '>' .
844 $innerContent .
845 '</' . $tagName . '>' .
846 $lastBR;
847 }
848 } else {
849 // Eliminate true linebreaks inside Hx tags
850 $blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
851 }
852 break;
853 default:
854 // Eliminate true linebreaks inside other headlist tags
855 $blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
856 break;
857 }
858 } else { // NON-block:
859 if (strcmp(trim($blockSplit[$k]), '')) {
860 // Remove linebreaks following hr tags
861 $blockSplit[$k] = preg_replace('/<(hr)(\s[^>\/]*)?[[:space:]]*\/?>[' . preg_quote(LF . CR) . ']+/', '<$1$2 />', $blockSplit[$k]);
862 // Replace other linebreaks with space
863 $blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $blockSplit[$k]);
864 $blockSplit[$k] = $this->divideIntoLines($blockSplit[$k]) . $lastBR;
865 $blockSplit[$k] = $this->transformStyledATags($blockSplit[$k]);
866 } else {
867 unset($blockSplit[$k]);
868 }
869 }
870 }
871 $this->TS_transform_db_safecounter++;
872
873 return implode('', $blockSplit);
874 }
875
876 /**
877 * Wraps a-tags that contain a style attribute with a span-tag
878 *
879 * @param string Content input
880 * @return string Content output
881 */
882 function transformStyledATags($value) {
883 $blockSplit = $this->splitIntoBlock('A', $value);
884 foreach ($blockSplit as $k => $v) {
885 if ($k % 2) { // If an A-tag was found:
886 $attribArray = $this->get_tag_attributes_classic($this->getFirstTag($v), 1);
887 if ($attribArray['style']) { // If "style" attribute is set!
888 $attribArray_copy['style'] = $attribArray['style'];
889 unset($attribArray['style']);
890 $bTag = '<span ' . t3lib_div::implodeAttributes($attribArray_copy, 1) . '><a ' . t3lib_div::implodeAttributes($attribArray, 1) . '>';
891 $eTag = '</a></span>';
892 $blockSplit[$k] = $bTag . $this->removeFirstAndLastTag($blockSplit[$k]) . $eTag;
893 }
894 }
895 }
896 return implode('', $blockSplit);
897 }
898
899 /**
900 * Transformation handler: 'ts_transform' + 'css_transform' / direction: "rte"
901 * Set (->rte) for standard content elements (ts)
902 *
903 * @param string Content input
904 * @param boolean If TRUE, the transformation was "css_transform", otherwise "ts_transform"
905 * @return string Content output
906 * @see TS_transform_db()
907 */
908 function TS_transform_rte($value, $css = 0) {
909
910 // Split the content from Database by the occurence of these blocks:
911 $blockSplit = $this->splitIntoBlock('TABLE,BLOCKQUOTE,TYPOLIST,TYPOHEAD,' . ($this->procOptions['preserveDIVSections'] ? 'DIV,' : '') . $this->blockElementList, $value);
912
913 // Traverse the blocks
914 foreach ($blockSplit as $k => $v) {
915 if ($k % 2) { // Inside one of the blocks:
916
917 // Init:
918 $tag = $this->getFirstTag($v);
919 $tagName = strtolower($this->getFirstTagName($v));
920 $attribArray = $this->get_tag_attributes_classic($tag);
921
922 // Based on tagname, we do transformations:
923 switch ($tagName) {
924 case 'blockquote': // Keep blockquotes
925 case 'dd': // Keep definitions
926 case 'div': // Keep div sections, if they were splitted
927 $blockSplit[$k] = $tag .
928 $this->TS_transform_rte($this->removeFirstAndLastTag($blockSplit[$k]), $css) .
929 '</' . $tagName . '>';
930 break;
931 case 'typolist': // Transform typolist blocks into OL/UL lists. Type 1 is expected to be numerical block
932 if (!isset($this->procOptions['typolist']) || $this->procOptions['typolist']) {
933 $tListContent = $this->removeFirstAndLastTag($blockSplit[$k]);
934 $tListContent = preg_replace('/^[ ]*' . LF . '/', '', $tListContent);
935 $tListContent = preg_replace('/' . LF . '[ ]*$/', '', $tListContent);
936 $lines = explode(LF, $tListContent);
937 $typ = $attribArray['type'] == 1 ? 'ol' : 'ul';
938 $blockSplit[$k] = '<' . $typ . '>' . LF .
939 '<li>' . implode('</li>' . LF . '<li>', $lines) . '</li>' .
940 '</' . $typ . '>';
941 }
942 break;
943 case 'typohead': // Transform typohead into Hx tags.
944 if (!isset($this->procOptions['typohead']) || $this->procOptions['typohead']) {
945 $tC = $this->removeFirstAndLastTag($blockSplit[$k]);
946 $typ = t3lib_utility_Math::forceIntegerInRange($attribArray['type'], 0, 6);
947 if (!$typ) {
948 $typ = 6;
949 }
950 $align = $attribArray['align'] ? ' align="' . $attribArray['align'] . '"' : '';
951 $class = $attribArray['class'] ? ' class="' . $attribArray['class'] . '"' : '';
952 $blockSplit[$k] = '<h' . $typ . $align . $class . '>' .
953 $tC .
954 '</h' . $typ . '>';
955 }
956 break;
957 }
958 $blockSplit[$k + 1] = preg_replace('/^[ ]*' . LF . '/', '', $blockSplit[$k + 1]); // Removing linebreak if typohead
959 } else { // NON-block:
960 $nextFTN = $this->getFirstTagName($blockSplit[$k + 1]);
961 $singleLineBreak = $blockSplit[$k] == LF;
962 if (t3lib_div::inList('TABLE,BLOCKQUOTE,TYPOLIST,TYPOHEAD,' . ($this->procOptions['preserveDIVSections'] ? 'DIV,' : '') . $this->blockElementList, $nextFTN)) { // Removing linebreak if typolist/typohead
963 $blockSplit[$k] = preg_replace('/' . LF . '[ ]*$/', '', $blockSplit[$k]);
964 }
965 // If $blockSplit[$k] is blank then unset the line. UNLESS the line happend to be a single line break.
966 if (!strcmp($blockSplit[$k], '') && !$singleLineBreak) {
967 unset($blockSplit[$k]);
968 } else {
969 $blockSplit[$k] = $this->setDivTags($blockSplit[$k], ($this->procOptions['useDIVasParagraphTagForRTE'] ? 'div' : 'p'));
970 }
971 }
972 }
973 return implode(LF, $blockSplit);
974 }
975
976 /**
977 * Transformation handler: 'ts_strip' / direction: "db"
978 * Removing all non-allowed tags
979 *
980 * @param string Content input
981 * @return string Content output
982 */
983 function TS_strip_db($value) {
984 $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')) . '>');
985 return $value;
986 }
987
988
989 /***************************************************************
990 *
991 * Generic RTE transformation, analysis and helper functions
992 *
993 **************************************************************/
994
995 /**
996 * Reads the file or url $url and returns the content
997 *
998 * @param string Filepath/URL to read
999 * @return string The content from the resource given as input.
1000 * @see t3lib_div::getUrl()
1001 */
1002 function getUrl($url) {
1003 return t3lib_div::getUrl($url);
1004 }
1005
1006 /**
1007 * Function for cleaning content going into the database.
1008 * Content is cleaned eg. by removing unallowed HTML and ds-HSC content
1009 * It is basically calling HTMLcleaner from the parent class with some preset configuration specifically set up for cleaning content going from the RTE into the db
1010 *
1011 * @param string Content to clean up
1012 * @param string Comma list of tags to specifically allow. Default comes from getKeepTags and is ""
1013 * @return string Clean content
1014 * @see getKeepTags()
1015 */
1016 function HTMLcleaner_db($content, $tagList = '') {
1017 if (!$tagList) {
1018 $keepTags = $this->getKeepTags('db');
1019 } else {
1020 $keepTags = $this->getKeepTags('db', $tagList);
1021 }
1022 $kUknown = $this->procOptions['dontRemoveUnknownTags_db'] ? 1 : 0; // Default: remove unknown tags.
1023 $hSC = $this->procOptions['dontUndoHSC_db'] ? 0 : -1; // Default: re-convert literals to characters (that is &lt; to <)
1024
1025 // Create additional configuration in order to honor the setting RTE.default.proc.HTMLparser_db.xhtml_cleaning=1
1026 $addConfig = array();
1027 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'])) {
1028 $addConfig['xhtml'] = 1;
1029 }
1030
1031 return $this->HTMLcleaner($content, $keepTags, $kUknown, $hSC, $addConfig);
1032 }
1033
1034 /**
1035 * Creates an array of configuration for the HTMLcleaner function based on whether content go TO or FROM the Rich Text Editor ($direction)
1036 * Unless "tagList" is given, the function will cache the configuration for next time processing goes on. (In this class that is the case only if we are processing a bulletlist)
1037 *
1038 * @param string The direction of the content being processed by the output configuration; "db" (content going into the database FROM the rte) or "rte" (content going into the form)
1039 * @param string Comma list of tags to keep (overriding default which is to keep all + take notice of internal configuration)
1040 * @return array Configuration array
1041 * @see HTMLcleaner_db()
1042 */
1043 function getKeepTags($direction = 'rte', $tagList = '') {
1044 if (!is_array($this->getKeepTags_cache[$direction]) || $tagList) {
1045
1046 // Setting up allowed tags:
1047 if (strcmp($tagList, '')) { // If the $tagList input var is set, this will take precedence
1048 $keepTags = array_flip(t3lib_div::trimExplode(',', $tagList, 1));
1049 } else { // Default is to get allowed/denied tags from internal array of processing options:
1050 // Construct default list of tags to keep:
1051 $typoScript_list = 'b,i,u,a,img,br,div,center,pre,font,hr,sub,sup,p,strong,em,li,ul,ol,blockquote,strike,span';
1052 $keepTags = array_flip(t3lib_div::trimExplode(',', $typoScript_list . ',' . strtolower($this->procOptions['allowTags']), 1));
1053
1054 // For tags to deny, remove them from $keepTags array:
1055 $denyTags = t3lib_div::trimExplode(',', $this->procOptions['denyTags'], 1);
1056 foreach ($denyTags as $dKe) {
1057 unset($keepTags[$dKe]);
1058 }
1059 }
1060
1061 // Based on the direction of content, set further options:
1062 switch ($direction) {
1063
1064 // GOING from database to Rich Text Editor:
1065 case 'rte':
1066
1067 if (!isset($this->procOptions['transformBoldAndItalicTags']) || $this->procOptions['transformBoldAndItalicTags']) {
1068 // Transform bold/italics tags to strong/em
1069 if (isset($keepTags['b'])) {
1070 $keepTags['b'] = array('remap' => 'STRONG');
1071 }
1072 if (isset($keepTags['i'])) {
1073 $keepTags['i'] = array('remap' => 'EM');
1074 }
1075 }
1076
1077 // Transforming keepTags array so it can be understood by the HTMLcleaner function. This basically converts the format of the array from TypoScript (having .'s) to plain multi-dimensional array.
1078 list($keepTags) = $this->HTMLparserConfig($this->procOptions['HTMLparser_rte.'], $keepTags);
1079 break;
1080
1081 // GOING from RTE to database:
1082 case 'db':
1083
1084 if (!isset($this->procOptions['transformBoldAndItalicTags']) || $this->procOptions['transformBoldAndItalicTags']) {
1085 // Transform strong/em back to bold/italics:
1086 if (isset($keepTags['strong'])) {
1087 $keepTags['strong'] = array('remap' => 'b');
1088 }
1089 if (isset($keepTags['em'])) {
1090 $keepTags['em'] = array('remap' => 'i');
1091 }
1092 }
1093
1094 // Setting up span tags if they are allowed:
1095 if (isset($keepTags['span'])) {
1096 $classes = array_merge(array(''), $this->allowedClasses);
1097 $keepTags['span'] = array(
1098 'allowedAttribs' => 'id,class,style,title,lang,xml:lang,dir',
1099 'fixAttrib' => Array(
1100 'class' => Array(
1101 'list' => $classes,
1102 'removeIfFalse' => 1
1103 ),
1104 ),
1105 'rmTagIfNoAttrib' => 1
1106 );
1107 if (!$this->procOptions['allowedClasses']) {
1108 unset($keepTags['span']['fixAttrib']['class']['list']);
1109 }
1110 }
1111
1112 // Setting up font tags if they are allowed:
1113 if (isset($keepTags['font'])) {
1114 $colors = array_merge(array(''), t3lib_div::trimExplode(',', $this->procOptions['allowedFontColors'], 1));
1115 $keepTags['font'] = array(
1116 'allowedAttribs' => 'face,color,size',
1117 'fixAttrib' => Array(
1118 'face' => Array(
1119 'removeIfFalse' => 1
1120 ),
1121 'color' => Array(
1122 'removeIfFalse' => 1,
1123 'list' => $colors
1124 ),
1125 'size' => Array(
1126 'removeIfFalse' => 1,
1127 )
1128 ),
1129 'rmTagIfNoAttrib' => 1
1130 );
1131 if (!$this->procOptions['allowedFontColors']) {
1132 unset($keepTags['font']['fixAttrib']['color']['list']);
1133 }
1134 }
1135
1136 // Setting further options, getting them from the processiong options:
1137 $TSc = $this->procOptions['HTMLparser_db.'];
1138 if (!$TSc['globalNesting']) {
1139 $TSc['globalNesting'] = 'b,i,u,a,center,font,sub,sup,strong,em,strike,span';
1140 }
1141 if (!$TSc['noAttrib']) {
1142 $TSc['noAttrib'] = 'b,i,u,br,center,hr,sub,sup,strong,em,li,ul,ol,blockquote,strike';
1143 }
1144
1145 // Transforming the array from TypoScript to regular array:
1146 list($keepTags) = $this->HTMLparserConfig($TSc, $keepTags);
1147 break;
1148 }
1149
1150 // Caching (internally, in object memory) the result unless tagList is set:
1151 if (!$tagList) {
1152 $this->getKeepTags_cache[$direction] = $keepTags;
1153 } else {
1154 return $keepTags;
1155 }
1156 }
1157
1158 // Return result:
1159 return $this->getKeepTags_cache[$direction];
1160 }
1161
1162 /**
1163 * This resolves the $value into parts based on <div></div>-sections and <p>-sections and <br />-tags. These are returned as lines separated by LF.
1164 * This point is to resolve the HTML-code returned from RTE into ordinary lines so it's 'human-readable'
1165 * The function ->setDivTags does the opposite.
1166 * This function processes content to go into the database.
1167 *
1168 * @param string Value to process.
1169 * @param integer Recursion brake. Decremented on each recursion down to zero. Default is 5 (which equals the allowed nesting levels of p/div tags).
1170 * @param boolean If TRUE, an array with the lines is returned, otherwise a string of the processed input value.
1171 * @return string Processed input value.
1172 * @see setDivTags()
1173 */
1174 function divideIntoLines($value, $count = 5, $returnArray = FALSE) {
1175
1176 // Internalize font tags (move them from OUTSIDE p/div to inside it that is the case):
1177 if ($this->procOptions['internalizeFontTags']) {
1178 $value = $this->internalizeFontTags($value);
1179 }
1180
1181 // Setting configuration for processing:
1182 $allowTagsOutside = t3lib_div::trimExplode(',', strtolower($this->procOptions['allowTagsOutside'] ? 'hr,' . $this->procOptions['allowTagsOutside'] : 'hr,img'), 1);
1183 $remapParagraphTag = strtoupper($this->procOptions['remapParagraphTag']);
1184 $divSplit = $this->splitIntoBlock('div,p', $value, 1); // Setting the third param to 1 will eliminate false end-tags. Maybe this is a good thing to do...?
1185
1186 if ($this->procOptions['keepPDIVattribs']) {
1187 $keepAttribListArr = t3lib_div::trimExplode(',', strtolower($this->procOptions['keepPDIVattribs']), 1);
1188 } else {
1189 $keepAttribListArr = array();
1190 }
1191
1192 // Returns plainly the value if there was no div/p sections in it
1193 if (count($divSplit) <= 1 || $count <= 0) {
1194 // Wrap hr tags with LF's
1195 $newValue = preg_replace('/<(hr)(\s[^>\/]*)?[[:space:]]*\/?>/i', LF . '<$1$2 />' . LF, $value);
1196 $newValue = preg_replace('/' . preg_quote(LF . LF) . '/i', LF, $newValue);
1197 $newValue = preg_replace('/(^' . preg_quote(LF) . ')|(' . preg_quote(LF) . '$)/i', '', $newValue);
1198 return $newValue;
1199 }
1200
1201 // Traverse the splitted sections:
1202 foreach ($divSplit as $k => $v) {
1203 if ($k % 2) { // Inside
1204 $v = $this->removeFirstAndLastTag($v);
1205
1206 // Fetching 'sub-lines' - which will explode any further p/div nesting...
1207 $subLines = $this->divideIntoLines($v, $count - 1, 1);
1208 if (is_array($subLines)) { // So, if there happend to be sub-nesting of p/div, this is written directly as the new content of THIS section. (This would be considered 'an error')
1209 // No noting.
1210 } else { //... but if NO subsection was found, we process it as a TRUE line without erronous content:
1211 $subLines = array($subLines);
1212 if (!$this->procOptions['dontConvBRtoParagraph']) { // process break-tags, if configured for. Simply, the breaktags will here be treated like if each was a line of content...
1213 $subLines = preg_split('/<br[[:space:]]*[\/]?>/i', $v);
1214 }
1215
1216 // Traverse sublines (there is typically one, except if <br/> has been converted to lines as well!)
1217 foreach ($subLines as $sk => $value) {
1218
1219 // Clear up the subline for DB.
1220 $subLines[$sk] = $this->HTMLcleaner_db($subLines[$sk]);
1221
1222 // Get first tag, attributes etc:
1223 $fTag = $this->getFirstTag($divSplit[$k]);
1224 $tagName = strtolower($this->getFirstTagName($divSplit[$k]));
1225 $attribs = $this->get_tag_attributes($fTag);
1226
1227 // Keep attributes (lowercase)
1228 $newAttribs = array();
1229 if (count($keepAttribListArr)) {
1230 foreach ($keepAttribListArr as $keepA) {
1231 if (isset($attribs[0][$keepA])) {
1232 $newAttribs[$keepA] = $attribs[0][$keepA];
1233 }
1234 }
1235 }
1236
1237 // ALIGN attribute:
1238 if (!$this->procOptions['skipAlign'] && strcmp(trim($attribs[0]['align']), '') && strtolower($attribs[0]['align']) != 'left') { // Set to value, but not 'left'
1239 $newAttribs['align'] = strtolower($attribs[0]['align']);
1240 }
1241
1242 // CLASS attribute:
1243 if (!$this->procOptions['skipClass'] && strcmp(trim($attribs[0]['class']), '')) { // Set to whatever value
1244 if (!count($this->allowedClasses) || in_array($attribs[0]['class'], $this->allowedClasses)) {
1245 $newAttribs['class'] = $attribs[0]['class'];
1246 } else {
1247 $classes = t3lib_div::trimExplode(' ', $attribs[0]['class'], TRUE);
1248 $newClasses = array();
1249 foreach ($classes as $class) {
1250 if (in_array($class, $this->allowedClasses)) {
1251 $newClasses[] = $class;
1252 }
1253 }
1254 if (count($newClasses)) {
1255 $newAttribs['class'] = implode(' ', $newClasses);
1256 }
1257 }
1258 }
1259
1260 // Remove any line break char (10 or 13)
1261 $subLines[$sk] = preg_replace('/' . LF . '|' . CR . '/', '', $subLines[$sk]);
1262
1263 // If there are any attributes or if we are supposed to remap the tag, then do so:
1264 if (count($newAttribs) && strcmp($remapParagraphTag, '1')) {
1265 if ($remapParagraphTag == 'P') {
1266 $tagName = 'p';
1267 }
1268 if ($remapParagraphTag == 'DIV') {
1269 $tagName = 'div';
1270 }
1271 $subLines[$sk] = '<' . trim($tagName . ' ' . $this->compileTagAttribs($newAttribs)) . '>' . $subLines[$sk] . '</' . $tagName . '>';
1272 }
1273 }
1274 }
1275 // Add the processed line(s)
1276 $divSplit[$k] = implode(LF, $subLines);
1277
1278 // If it turns out the line is just blank (containing a &nbsp; possibly) then just make it pure blank.
1279 // But, prevent filtering of lines that are blank in sense above, but whose tags contain attributes.
1280 // Those attributes should have been filtered before; if they are still there they must be considered as possible content.
1281 if (trim(strip_tags($divSplit[$k])) == '&nbsp;' && !preg_match('/\<(img)(\s[^>]*)?\/?>/si', $divSplit[$k]) && !preg_match('/\<([^>]*)?( align| class| style| id| title| dir| lang| xml:lang)([^>]*)?>/si', trim($divSplit[$k]))) {
1282 $divSplit[$k] = '';
1283 }
1284 } else { // outside div:
1285 // Remove positions which are outside div/p tags and without content
1286 $divSplit[$k] = trim(strip_tags($divSplit[$k], '<' . implode('><', $allowTagsOutside) . '>'));
1287 // Wrap hr tags with LF's
1288 $divSplit[$k] = preg_replace('/<(hr)(\s[^>\/]*)?[[:space:]]*\/?>/i', LF . '<$1$2 />' . LF, $divSplit[$k]);
1289 $divSplit[$k] = preg_replace('/' . preg_quote(LF . LF) . '/i', LF, $divSplit[$k]);
1290 $divSplit[$k] = preg_replace('/(^' . preg_quote(LF) . ')|(' . preg_quote(LF) . '$)/i', '', $divSplit[$k]);
1291 if (!strcmp($divSplit[$k], '')) {
1292 unset($divSplit[$k]);
1293 } // Remove part if it's empty
1294 }
1295 }
1296
1297 // Return value:
1298 return $returnArray ? $divSplit : implode(LF, $divSplit);
1299 }
1300
1301 /**
1302 * Converts all lines into <div></div>/<p></p>-sections (unless the line is a div-section already)
1303 * For processing of content going FROM database TO RTE.
1304 *
1305 * @param string Value to convert
1306 * @param string Tag to wrap with. Either "p" or "div" should it be. Lowercase preferably.
1307 * @return string Processed value.
1308 * @see divideIntoLines()
1309 */
1310 function setDivTags($value, $dT = 'p') {
1311
1312 // First, setting configuration for the HTMLcleaner function. This will process each line between the <div>/<p> section on their way to the RTE
1313 $keepTags = $this->getKeepTags('rte');
1314 $kUknown = $this->procOptions['dontProtectUnknownTags_rte'] ? 0 : 'protect'; // Default: remove unknown tags.
1315 $hSC = $this->procOptions['dontHSC_rte'] ? 0 : 1; // Default: re-convert literals to characters (that is &lt; to <)
1316 $convNBSP = !$this->procOptions['dontConvAmpInNBSP_rte'] ? 1 : 0;
1317
1318 // Divide the content into lines, based on LF:
1319 $parts = explode(LF, $value);
1320 foreach ($parts as $k => $v) {
1321
1322 // Processing of line content:
1323 if (!strcmp(trim($parts[$k]), '')) { // If the line is blank, set it to &nbsp;
1324 $parts[$k] = '&nbsp;';
1325 } else { // Clean the line content:
1326 $parts[$k] = $this->HTMLcleaner($parts[$k], $keepTags, $kUknown, $hSC);
1327 if ($convNBSP) {
1328 $parts[$k] = str_replace('&amp;nbsp;', '&nbsp;', $parts[$k]);
1329 }
1330 }
1331
1332 // Wrapping the line in <$dT> if not already wrapped and does not contain an hr tag
1333 if (!preg_match('/<(hr)(\s[^>\/]*)?[[:space:]]*\/?>/i', $parts[$k])) {
1334 $testStr = strtolower(trim($parts[$k]));
1335 if (substr($testStr, 0, 4) != '<div' || substr($testStr, -6) != '</div>') {
1336 if (substr($testStr, 0, 2) != '<p' || substr($testStr, -4) != '</p>') {
1337 // Only set p-tags if there is not already div or p tags:
1338 $parts[$k] = '<' . $dT . '>' . $parts[$k] . '</' . $dT . '>';
1339 }
1340 }
1341 }
1342 }
1343
1344 // Implode result:
1345 return implode(LF, $parts);
1346 }
1347
1348 /**
1349 * This splits the $value in font-tag chunks.
1350 * If there are any <P>/<DIV> sections inside of them, the font-tag is wrapped AROUND the content INSIDE of the P/DIV sections and the outer font-tag is removed.
1351 * This functions seems to be a good choice for pre-processing content if it has been pasted into the RTE from eg. star-office.
1352 * In that case the font-tags are normally on the OUTSIDE of the sections.
1353 * This function is used by eg. divideIntoLines() if the procesing option 'internalizeFontTags' is set.
1354 *
1355 * @param string Input content
1356 * @return string Output content
1357 * @see divideIntoLines()
1358 */
1359 function internalizeFontTags($value) {
1360
1361 // Splitting into font tag blocks:
1362 $fontSplit = $this->splitIntoBlock('font', $value);
1363
1364 foreach ($fontSplit as $k => $v) {
1365 if ($k % 2) { // Inside
1366 $fTag = $this->getFirstTag($v); // Fint font-tag
1367
1368 $divSplit_sub = $this->splitIntoBlock('div,p', $this->removeFirstAndLastTag($v), 1);
1369 if (count($divSplit_sub) > 1) { // If there were div/p sections inside the font-tag, do something about it...
1370 // traverse those sections:
1371 foreach ($divSplit_sub as $k2 => $v2) {
1372 if ($k2 % 2) { // Inside
1373 $div_p = $this->getFirstTag($v2); // Fint font-tag
1374 $div_p_tagname = $this->getFirstTagName($v2); // Fint font-tag
1375 $v2 = $this->removeFirstAndLastTag($v2); // ... and remove it from original.
1376 $divSplit_sub[$k2] = $div_p . $fTag . $v2 . '</font>' . '</' . $div_p_tagname . '>';
1377 } elseif (trim(strip_tags($v2))) {
1378 $divSplit_sub[$k2] = $fTag . $v2 . '</font>';
1379 }
1380 }
1381 $fontSplit[$k] = implode('', $divSplit_sub);
1382 }
1383 }
1384 }
1385
1386 return implode('', $fontSplit);
1387 }
1388
1389 /**
1390 * Returns SiteURL based on thisScript.
1391 *
1392 * @return string Value of t3lib_div::getIndpEnv('TYPO3_SITE_URL');
1393 * @see t3lib_div::getIndpEnv()
1394 */
1395 function siteUrl() {
1396 return t3lib_div::getIndpEnv('TYPO3_SITE_URL');
1397 }
1398
1399 /**
1400 * Return the storage folder of RTE image files.
1401 * Default is $GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir'] unless something else is configured in the types configuration for the RTE.
1402 *
1403 * @return string
1404 */
1405 function rteImageStorageDir() {
1406 return $this->rte_p['imgpath'] ? $this->rte_p['imgpath'] : $GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir'];
1407 }
1408
1409 /**
1410 * Remove all tables from incoming code
1411 * The function is trying to to this is some more or less respectfull way. The approach is to resolve each table cells content and implode it all by <br /> chars. Thus at least the content is preserved in some way.
1412 *
1413 * @param string Input value
1414 * @param string Break character to use for linebreaks.
1415 * @return string Output value
1416 */
1417 function removeTables($value, $breakChar = '<br />') {
1418
1419 // Splitting value into table blocks:
1420 $tableSplit = $this->splitIntoBlock('table', $value);
1421
1422 // Traverse blocks of tables:
1423 foreach ($tableSplit as $k => $v) {
1424 if ($k % 2) {
1425 $tableSplit[$k] = '';
1426 $rowSplit = $this->splitIntoBlock('tr', $v);
1427 foreach ($rowSplit as $k2 => $v2) {
1428 if ($k2 % 2) {
1429 $cellSplit = $this->getAllParts($this->splitIntoBlock('td', $v2), 1, 0);
1430 foreach ($cellSplit as $k3 => $v3) {
1431 $tableSplit[$k] .= $v3 . $breakChar;
1432 }
1433 }
1434 }
1435 }
1436 }
1437
1438 // Implode it all again:
1439 return implode($breakChar, $tableSplit);
1440 }
1441
1442 /**
1443 * Default tag mapping for TS
1444 *
1445 * @param string Input code to process
1446 * @param string Direction To databsae (db) or from database to RTE (rte)
1447 * @return string Processed value
1448 */
1449 function defaultTStagMapping($code, $direction = 'rte') {
1450 if ($direction == 'db') {
1451 $code = $this->mapTags($code, array( // Map tags
1452 'strong' => 'b',
1453 'em' => 'i'
1454 ));
1455 }
1456 if ($direction == 'rte') {
1457 $code = $this->mapTags($code, array( // Map tags
1458 'b' => 'strong',
1459 'i' => 'em'
1460 ));
1461 }
1462 return $code;
1463 }
1464
1465 /**
1466 * Finds width and height from attrib-array
1467 * If the width and height is found in the style-attribute, use that!
1468 *
1469 * @param array Array of attributes from tag in which to search. More specifically the content of the key "style" is used to extract "width:xxx / height:xxx" information
1470 * @return array Integer w/h in key 0/1. Zero is returned if not found.
1471 */
1472 function getWHFromAttribs($attribArray) {
1473 $style = trim($attribArray['style']);
1474 if ($style) {
1475 $regex = '[[:space:]]*:[[:space:]]*([0-9]*)[[:space:]]*px';
1476 // Width
1477 $reg = array();
1478 preg_match('/width' . $regex . '/i', $style, $reg);
1479 $w = intval($reg[1]);
1480 // Height
1481 preg_match('/height' . $regex . '/i', $style, $reg);
1482 $h = intval($reg[1]);
1483 }
1484 if (!$w) {
1485 $w = $attribArray['width'];
1486 }
1487 if (!$h) {
1488 $h = $attribArray['height'];
1489 }
1490 return array(intval($w), intval($h));
1491 }
1492
1493 /**
1494 * Parse <A>-tag href and return status of email,external,file or page
1495 *
1496 * @param string URL to analyse.
1497 * @return array Information in an array about the URL
1498 */
1499 function urlInfoForLinkTags($url) {
1500 $info = array();
1501 $url = trim($url);
1502 if (substr(strtolower($url), 0, 7) == 'mailto:') {
1503 $info['url'] = trim(substr($url, 7));
1504 $info['type'] = 'email';
1505 } else {
1506 $curURL = $this->siteUrl(); // 100502, removed this: 'http://'.t3lib_div::getThisUrl(); Reason: The url returned had typo3/ in the end - should be only the site's url as far as I see...
1507 for ($a = 0; $a < strlen($url); $a++) {
1508 if ($url{$a} != $curURL{$a}) {
1509 break;
1510 }
1511 }
1512
1513 $info['relScriptPath'] = substr($curURL, $a);
1514 $info['relUrl'] = substr($url, $a);
1515 $info['url'] = $url;
1516 $info['type'] = 'ext';
1517
1518 $siteUrl_parts = parse_url($url);
1519 $curUrl_parts = parse_url($curURL);
1520
1521 if ($siteUrl_parts['host'] == $curUrl_parts['host'] // Hosts should match
1522 && (!$info['relScriptPath'] || (defined('TYPO3_mainDir') && substr($info['relScriptPath'], 0, strlen(TYPO3_mainDir)) == TYPO3_mainDir))) { // If the script path seems to match or is empty (FE-EDIT)
1523
1524 // New processing order 100502
1525 $uP = parse_url($info['relUrl']);
1526
1527 if (!strcmp('#' . $siteUrl_parts['fragment'], $info['relUrl'])) {
1528 $info['url'] = $info['relUrl'];
1529 $info['type'] = 'anchor';
1530 } elseif (!trim($uP['path']) || !strcmp($uP['path'], 'index.php')) {
1531 // URL is a page (id parameter)
1532 $pp = preg_split('/^id=/', $uP['query']);
1533 $pp[1] = preg_replace('/&id=[^&]*/', '', $pp[1]);
1534 $parameters = explode('&', $pp[1]);
1535 $id = array_shift($parameters);
1536 if ($id) {
1537 $info['pageid'] = $id;
1538 $info['cElement'] = $uP['fragment'];
1539 $info['url'] = $id . ($info['cElement'] ? '#' . $info['cElement'] : '');
1540 $info['type'] = 'page';
1541 $info['query'] = $parameters[0] ? '&' . implode('&', $parameters) : '';
1542 }
1543 } else {
1544 $info['url'] = $info['relUrl'];
1545 $info['type'] = 'file';
1546 }
1547 } else {
1548 unset($info['relScriptPath']);
1549 unset($info['relUrl']);
1550 }
1551 }
1552 return $info;
1553 }
1554
1555 /**
1556 * Converting <A>-tags to absolute URLs (+ setting rtekeep attribute)
1557 *
1558 * @param string Content input
1559 * @param boolean If TRUE, then the "rtekeep" attribute will not be set.
1560 * @return string Content output
1561 */
1562 function TS_AtagToAbs($value, $dontSetRTEKEEP = FALSE) {
1563 $blockSplit = $this->splitIntoBlock('A', $value);
1564 foreach ($blockSplit as $k => $v) {
1565 if ($k % 2) { // block:
1566 $attribArray = $this->get_tag_attributes_classic($this->getFirstTag($v), 1);
1567
1568 // Checking if there is a scheme, and if not, prepend the current url.
1569 if (strlen($attribArray['href'])) { // ONLY do this if href has content - the <a> tag COULD be an anchor and if so, it should be preserved...
1570 $uP = parse_url(strtolower($attribArray['href']));
1571 if (!$uP['scheme']) {
1572 $attribArray['href'] = $this->siteUrl() . substr($attribArray['href'], strlen($this->relBackPath));
1573 } elseif ($uP['scheme'] != 'mailto') {
1574 $attribArray['external'] = 1;
1575 }
1576 } else {
1577 $attribArray['rtekeep'] = 1;
1578 }
1579 if (!$dontSetRTEKEEP) {
1580 $attribArray['rtekeep'] = 1;
1581 }
1582
1583 $bTag = '<a ' . t3lib_div::implodeAttributes($attribArray, 1) . '>';
1584 $eTag = '</a>';
1585 $blockSplit[$k] = $bTag . $this->TS_AtagToAbs($this->removeFirstAndLastTag($blockSplit[$k])) . $eTag;
1586 }
1587 }
1588 return implode('', $blockSplit);
1589 }
1590 }
1591
1592
1593 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_parsehtml_proc.php'])) {
1594 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_parsehtml_proc.php']);
1595 }
1596
1597 ?>