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