Fixed issue #17284: Formprotection persistToken method is called too often, causing...
[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 *
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,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
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 // Remove linebreaks following hr tags
908 $blockSplit[$k] = preg_replace('/<(hr)(\s[^>\/]*)?[[:space:]]*\/?>[' . preg_quote(LF . CR) . ']+/', '<$1$2 />', $blockSplit[$k]);
909 // Replace other linebreaks with space
910 $blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $blockSplit[$k]);
911 $blockSplit[$k] = $this->divideIntoLines($blockSplit[$k]) . $lastBR;
912 $blockSplit[$k] = $this->transformStyledATags($blockSplit[$k]);
913 } else {
914 unset($blockSplit[$k]);
915 }
916 }
917 }
918 $this->TS_transform_db_safecounter++;
919
920 return implode('', $blockSplit);
921 }
922
923 /**
924 * Wraps a-tags that contain a style attribute with a span-tag
925 *
926 * @param string Content input
927 * @return string Content output
928 */
929 function transformStyledATags($value) {
930 $blockSplit = $this->splitIntoBlock('A', $value);
931 foreach ($blockSplit as $k => $v) {
932 if ($k % 2) { // If an A-tag was found:
933 $attribArray = $this->get_tag_attributes_classic($this->getFirstTag($v), 1);
934 if ($attribArray['style']) { // If "style" attribute is set!
935 $attribArray_copy['style'] = $attribArray['style'];
936 unset($attribArray['style']);
937 $bTag = '<span ' . t3lib_div::implodeAttributes($attribArray_copy, 1) . '><a ' . t3lib_div::implodeAttributes($attribArray, 1) . '>';
938 $eTag = '</a></span>';
939 $blockSplit[$k] = $bTag . $this->removeFirstAndLastTag($blockSplit[$k]) . $eTag;
940 }
941 }
942 }
943 return implode('', $blockSplit);
944 }
945
946 /**
947 * Transformation handler: 'ts_transform' + 'css_transform' / direction: "rte"
948 * Set (->rte) for standard content elements (ts)
949 *
950 * @param string Content input
951 * @param boolean If true, the transformation was "css_transform", otherwise "ts_transform"
952 * @return string Content output
953 * @see TS_transform_db()
954 */
955 function TS_transform_rte($value, $css = 0) {
956
957 // Split the content from Database by the occurence of these blocks:
958 $blockSplit = $this->splitIntoBlock('TABLE,BLOCKQUOTE,TYPOLIST,TYPOHEAD,' . ($this->procOptions['preserveDIVSections'] ? 'DIV,' : '') . $this->blockElementList, $value);
959
960 // Traverse the blocks
961 foreach ($blockSplit as $k => $v) {
962 if ($k % 2) { // Inside one of the blocks:
963
964 // Init:
965 $tag = $this->getFirstTag($v);
966 $tagName = strtolower($this->getFirstTagName($v));
967 $attribArray = $this->get_tag_attributes_classic($tag);
968
969 // Based on tagname, we do transformations:
970 switch ($tagName) {
971 case 'blockquote': // Keep blockquotes
972 case 'dd': // Keep definitions
973 case 'div': // Keep div sections, if they were splitted
974 $blockSplit[$k] = $tag .
975 $this->TS_transform_rte($this->removeFirstAndLastTag($blockSplit[$k]), $css) .
976 '</' . $tagName . '>';
977 break;
978 case 'typolist': // Transform typolist blocks into OL/UL lists. Type 1 is expected to be numerical block
979 if (!isset($this->procOptions['typolist']) || $this->procOptions['typolist']) {
980 $tListContent = $this->removeFirstAndLastTag($blockSplit[$k]);
981 $tListContent = preg_replace('/^[ ]*' . LF . '/', '', $tListContent);
982 $tListContent = preg_replace('/' . LF . '[ ]*$/', '', $tListContent);
983 $lines = explode(LF, $tListContent);
984 $typ = $attribArray['type'] == 1 ? 'ol' : 'ul';
985 $blockSplit[$k] = '<' . $typ . '>' . LF .
986 '<li>' . implode('</li>' . LF . '<li>', $lines) . '</li>' .
987 '</' . $typ . '>';
988 }
989 break;
990 case 'typohead': // Transform typohead into Hx tags.
991 if (!isset($this->procOptions['typohead']) || $this->procOptions['typohead']) {
992 $tC = $this->removeFirstAndLastTag($blockSplit[$k]);
993 $typ = t3lib_div::intInRange($attribArray['type'], 0, 6);
994 if (!$typ) {
995 $typ = 6;
996 }
997 $align = $attribArray['align'] ? ' align="' . $attribArray['align'] . '"' : '';
998 $class = $attribArray['class'] ? ' class="' . $attribArray['class'] . '"' : '';
999 $blockSplit[$k] = '<h' . $typ . $align . $class . '>' .
1000 $tC .
1001 '</h' . $typ . '>';
1002 }
1003 break;
1004 }
1005 $blockSplit[$k + 1] = preg_replace('/^[ ]*' . LF . '/', '', $blockSplit[$k + 1]); // Removing linebreak if typohead
1006 } else { // NON-block:
1007 $nextFTN = $this->getFirstTagName($blockSplit[$k + 1]);
1008 $singleLineBreak = $blockSplit[$k] == LF;
1009 if (t3lib_div::inList('TABLE,BLOCKQUOTE,TYPOLIST,TYPOHEAD,' . ($this->procOptions['preserveDIVSections'] ? 'DIV,' : '') . $this->blockElementList, $nextFTN)) { // Removing linebreak if typolist/typohead
1010 $blockSplit[$k] = preg_replace('/' . LF . '[ ]*$/', '', $blockSplit[$k]);
1011 }
1012 // If $blockSplit[$k] is blank then unset the line. UNLESS the line happend to be a single line break.
1013 if (!strcmp($blockSplit[$k], '') && !$singleLineBreak) {
1014 unset($blockSplit[$k]);
1015 } else {
1016 $blockSplit[$k] = $this->setDivTags($blockSplit[$k], ($this->procOptions['useDIVasParagraphTagForRTE'] ? 'div' : 'p'));
1017 }
1018 }
1019 }
1020 return implode(LF, $blockSplit);
1021 }
1022
1023 /**
1024 * Transformation handler: 'ts_strip' / direction: "db"
1025 * Removing all non-allowed tags
1026 *
1027 * @param string Content input
1028 * @return string Content output
1029 */
1030 function TS_strip_db($value) {
1031 $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')) . '>');
1032 return $value;
1033 }
1034
1035
1036 /***************************************************************
1037 *
1038 * Generic RTE transformation, analysis and helper functions
1039 *
1040 **************************************************************/
1041
1042 /**
1043 * Reads the file or url $url and returns the content
1044 *
1045 * @param string Filepath/URL to read
1046 * @return string The content from the resource given as input.
1047 * @see t3lib_div::getURL()
1048 */
1049 function getURL($url) {
1050 return t3lib_div::getURL($url);
1051 }
1052
1053 /**
1054 * Function for cleaning content going into the database.
1055 * Content is cleaned eg. by removing unallowed HTML and ds-HSC content
1056 * 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
1057 *
1058 * @param string Content to clean up
1059 * @param string Comma list of tags to specifically allow. Default comes from getKeepTags and is ""
1060 * @return string Clean content
1061 * @see getKeepTags()
1062 */
1063 function HTMLcleaner_db($content, $tagList = '') {
1064 if (!$tagList) {
1065 $keepTags = $this->getKeepTags('db');
1066 } else {
1067 $keepTags = $this->getKeepTags('db', $tagList);
1068 }
1069 $kUknown = $this->procOptions['dontRemoveUnknownTags_db'] ? 1 : 0; // Default: remove unknown tags.
1070 $hSC = $this->procOptions['dontUndoHSC_db'] ? 0 : -1; // Default: re-convert literals to characters (that is &lt; to <)
1071
1072 // Create additional configuration in order to honor the setting RTE.default.proc.HTMLparser_db.xhtml_cleaning=1
1073 $addConfig = array();
1074 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'])) {
1075 $addConfig['xhtml'] = 1;
1076 }
1077
1078 return $this->HTMLcleaner($content, $keepTags, $kUknown, $hSC, $addConfig);
1079 }
1080
1081 /**
1082 * Creates an array of configuration for the HTMLcleaner function based on whether content go TO or FROM the Rich Text Editor ($direction)
1083 * 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)
1084 *
1085 * @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)
1086 * @param string Comma list of tags to keep (overriding default which is to keep all + take notice of internal configuration)
1087 * @return array Configuration array
1088 * @see HTMLcleaner_db()
1089 */
1090 function getKeepTags($direction = 'rte', $tagList = '') {
1091 if (!is_array($this->getKeepTags_cache[$direction]) || $tagList) {
1092
1093 // Setting up allowed tags:
1094 if (strcmp($tagList, '')) { // If the $tagList input var is set, this will take precedence
1095 $keepTags = array_flip(t3lib_div::trimExplode(',', $tagList, 1));
1096 } else { // Default is to get allowed/denied tags from internal array of processing options:
1097 // Construct default list of tags to keep:
1098 $typoScript_list = 'b,i,u,a,img,br,div,center,pre,font,hr,sub,sup,p,strong,em,li,ul,ol,blockquote,strike,span';
1099 $keepTags = array_flip(t3lib_div::trimExplode(',', $typoScript_list . ',' . strtolower($this->procOptions['allowTags']), 1));
1100
1101 // For tags to deny, remove them from $keepTags array:
1102 $denyTags = t3lib_div::trimExplode(',', $this->procOptions['denyTags'], 1);
1103 foreach ($denyTags as $dKe) {
1104 unset($keepTags[$dKe]);
1105 }
1106 }
1107
1108 // Based on the direction of content, set further options:
1109 switch ($direction) {
1110
1111 // GOING from database to Rich Text Editor:
1112 case 'rte':
1113
1114 if (!isset($this->procOptions['transformBoldAndItalicTags']) || $this->procOptions['transformBoldAndItalicTags']) {
1115 // Transform bold/italics tags to strong/em
1116 if (isset($keepTags['b'])) {
1117 $keepTags['b'] = array('remap' => 'STRONG');
1118 }
1119 if (isset($keepTags['i'])) {
1120 $keepTags['i'] = array('remap' => 'EM');
1121 }
1122 }
1123
1124 // 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.
1125 list($keepTags) = $this->HTMLparserConfig($this->procOptions['HTMLparser_rte.'], $keepTags);
1126 break;
1127
1128 // GOING from RTE to database:
1129 case 'db':
1130
1131 if (!isset($this->procOptions['transformBoldAndItalicTags']) || $this->procOptions['transformBoldAndItalicTags']) {
1132 // Transform strong/em back to bold/italics:
1133 if (isset($keepTags['strong'])) {
1134 $keepTags['strong'] = array('remap' => 'b');
1135 }
1136 if (isset($keepTags['em'])) {
1137 $keepTags['em'] = array('remap' => 'i');
1138 }
1139 }
1140
1141 // Setting up span tags if they are allowed:
1142 if (isset($keepTags['span'])) {
1143 $classes = array_merge(array(''), $this->allowedClasses);
1144 $keepTags['span'] = array(
1145 'allowedAttribs' => 'id,class,style,title,lang,xml:lang,dir',
1146 'fixAttrib' => Array(
1147 'class' => Array(
1148 'list' => $classes,
1149 'removeIfFalse' => 1
1150 ),
1151 ),
1152 'rmTagIfNoAttrib' => 1
1153 );
1154 if (!$this->procOptions['allowedClasses']) {
1155 unset($keepTags['span']['fixAttrib']['class']['list']);
1156 }
1157 }
1158
1159 // Setting up font tags if they are allowed:
1160 if (isset($keepTags['font'])) {
1161 $colors = array_merge(array(''), t3lib_div::trimExplode(',', $this->procOptions['allowedFontColors'], 1));
1162 $keepTags['font'] = array(
1163 'allowedAttribs' => 'face,color,size',
1164 'fixAttrib' => Array(
1165 'face' => Array(
1166 'removeIfFalse' => 1
1167 ),
1168 'color' => Array(
1169 'removeIfFalse' => 1,
1170 'list' => $colors
1171 ),
1172 'size' => Array(
1173 'removeIfFalse' => 1,
1174 )
1175 ),
1176 'rmTagIfNoAttrib' => 1
1177 );
1178 if (!$this->procOptions['allowedFontColors']) {
1179 unset($keepTags['font']['fixAttrib']['color']['list']);
1180 }
1181 }
1182
1183 // Setting further options, getting them from the processiong options:
1184 $TSc = $this->procOptions['HTMLparser_db.'];
1185 if (!$TSc['globalNesting']) {
1186 $TSc['globalNesting'] = 'b,i,u,a,center,font,sub,sup,strong,em,strike,span';
1187 }
1188 if (!$TSc['noAttrib']) {
1189 $TSc['noAttrib'] = 'b,i,u,br,center,hr,sub,sup,strong,em,li,ul,ol,blockquote,strike';
1190 }
1191
1192 // Transforming the array from TypoScript to regular array:
1193 list($keepTags) = $this->HTMLparserConfig($TSc, $keepTags);
1194 break;
1195 }
1196
1197 // Caching (internally, in object memory) the result unless tagList is set:
1198 if (!$tagList) {
1199 $this->getKeepTags_cache[$direction] = $keepTags;
1200 } else {
1201 return $keepTags;
1202 }
1203 }
1204
1205 // Return result:
1206 return $this->getKeepTags_cache[$direction];
1207 }
1208
1209 /**
1210 * 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.
1211 * This point is to resolve the HTML-code returned from RTE into ordinary lines so it's 'human-readable'
1212 * The function ->setDivTags does the opposite.
1213 * This function processes content to go into the database.
1214 *
1215 * @param string Value to process.
1216 * @param integer Recursion brake. Decremented on each recursion down to zero. Default is 5 (which equals the allowed nesting levels of p/div tags).
1217 * @param boolean If true, an array with the lines is returned, otherwise a string of the processed input value.
1218 * @return string Processed input value.
1219 * @see setDivTags()
1220 */
1221 function divideIntoLines($value, $count = 5, $returnArray = FALSE) {
1222
1223 // Internalize font tags (move them from OUTSIDE p/div to inside it that is the case):
1224 if ($this->procOptions['internalizeFontTags']) {
1225 $value = $this->internalizeFontTags($value);
1226 }
1227
1228 // Setting configuration for processing:
1229 $allowTagsOutside = t3lib_div::trimExplode(',', strtolower($this->procOptions['allowTagsOutside'] ? 'hr,' . $this->procOptions['allowTagsOutside'] : 'hr,img'), 1);
1230 $remapParagraphTag = strtoupper($this->procOptions['remapParagraphTag']);
1231 $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...?
1232
1233 if ($this->procOptions['keepPDIVattribs']) {
1234 $keepAttribListArr = t3lib_div::trimExplode(',', strtolower($this->procOptions['keepPDIVattribs']), 1);
1235 } else {
1236 $keepAttribListArr = array();
1237 }
1238
1239 // Returns plainly the value if there was no div/p sections in it
1240 if (count($divSplit) <= 1 || $count <= 0) {
1241 // Wrap hr tags with LF's
1242 $newValue = preg_replace('/<(hr)(\s[^>\/]*)?[[:space:]]*\/?>/i', LF . '<$1$2 />' . LF, $value);
1243 $newValue = preg_replace('/' . preg_quote(LF . LF) . '/i', LF, $newValue);
1244 $newValue = preg_replace('/(^' . preg_quote(LF) . ')|(' . preg_quote(LF) . '$)/i', '', $newValue);
1245 return $newValue;
1246 }
1247
1248 // Traverse the splitted sections:
1249 foreach ($divSplit as $k => $v) {
1250 if ($k % 2) { // Inside
1251 $v = $this->removeFirstAndLastTag($v);
1252
1253 // Fetching 'sub-lines' - which will explode any further p/div nesting...
1254 $subLines = $this->divideIntoLines($v, $count - 1, 1);
1255 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')
1256 // No noting.
1257 } else { //... but if NO subsection was found, we process it as a TRUE line without erronous content:
1258 $subLines = array($subLines);
1259 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...
1260 $subLines = preg_split('/<br[[:space:]]*[\/]?>/i', $v);
1261 }
1262
1263 // Traverse sublines (there is typically one, except if <br/> has been converted to lines as well!)
1264 foreach ($subLines as $sk => $value) {
1265
1266 // Clear up the subline for DB.
1267 $subLines[$sk] = $this->HTMLcleaner_db($subLines[$sk]);
1268
1269 // Get first tag, attributes etc:
1270 $fTag = $this->getFirstTag($divSplit[$k]);
1271 $tagName = strtolower($this->getFirstTagName($divSplit[$k]));
1272 $attribs = $this->get_tag_attributes($fTag);
1273
1274 // Keep attributes (lowercase)
1275 $newAttribs = array();
1276 if (count($keepAttribListArr)) {
1277 foreach ($keepAttribListArr as $keepA) {
1278 if (isset($attribs[0][$keepA])) {
1279 $newAttribs[$keepA] = $attribs[0][$keepA];
1280 }
1281 }
1282 }
1283
1284 // ALIGN attribute:
1285 if (!$this->procOptions['skipAlign'] && strcmp(trim($attribs[0]['align']), '') && strtolower($attribs[0]['align']) != 'left') { // Set to value, but not 'left'
1286 $newAttribs['align'] = strtolower($attribs[0]['align']);
1287 }
1288
1289 // CLASS attribute:
1290 if (!$this->procOptions['skipClass'] && strcmp(trim($attribs[0]['class']), '')) { // Set to whatever value
1291 if (!count($this->allowedClasses) || in_array($attribs[0]['class'], $this->allowedClasses)) {
1292 $newAttribs['class'] = $attribs[0]['class'];
1293 } else {
1294 $classes = t3lib_div::trimExplode(' ', $attribs[0]['class'], true);
1295 $newClasses = array();
1296 foreach ($classes as $class) {
1297 if (in_array($class, $this->allowedClasses)) {
1298 $newClasses[] = $class;
1299 }
1300 }
1301 if (count($newClasses)) {
1302 $newAttribs['class'] = implode(' ', $newClasses);
1303 }
1304 }
1305 }
1306
1307 // Remove any line break char (10 or 13)
1308 $subLines[$sk] = preg_replace('/' . LF . '|' . CR . '/', '', $subLines[$sk]);
1309
1310 // If there are any attributes or if we are supposed to remap the tag, then do so:
1311 if (count($newAttribs) && strcmp($remapParagraphTag, '1')) {
1312 if ($remapParagraphTag == 'P') {
1313 $tagName = 'p';
1314 }
1315 if ($remapParagraphTag == 'DIV') {
1316 $tagName = 'div';
1317 }
1318 $subLines[$sk] = '<' . trim($tagName . ' ' . $this->compileTagAttribs($newAttribs)) . '>' . $subLines[$sk] . '</' . $tagName . '>';
1319 }
1320 }
1321 }
1322 // Add the processed line(s)
1323 $divSplit[$k] = implode(LF, $subLines);
1324
1325 // If it turns out the line is just blank (containing a &nbsp; possibly) then just make it pure blank.
1326 // But, prevent filtering of lines that are blank in sense above, but whose tags contain attributes.
1327 // Those attributes should have been filtered before; if they are still there they must be considered as possible content.
1328 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]))) {
1329 $divSplit[$k] = '';
1330 }
1331 } else { // outside div:
1332 // Remove positions which are outside div/p tags and without content
1333 $divSplit[$k] = trim(strip_tags($divSplit[$k], '<' . implode('><', $allowTagsOutside) . '>'));
1334 // Wrap hr tags with LF's
1335 $divSplit[$k] = preg_replace('/<(hr)(\s[^>\/]*)?[[:space:]]*\/?>/i', LF . '<$1$2 />' . LF, $divSplit[$k]);
1336 $divSplit[$k] = preg_replace('/' . preg_quote(LF . LF) . '/i', LF, $divSplit[$k]);
1337 $divSplit[$k] = preg_replace('/(^' . preg_quote(LF) . ')|(' . preg_quote(LF) . '$)/i', '', $divSplit[$k]);
1338 if (!strcmp($divSplit[$k], '')) {
1339 unset($divSplit[$k]);
1340 } // Remove part if it's empty
1341 }
1342 }
1343
1344 // Return value:
1345 return $returnArray ? $divSplit : implode(LF, $divSplit);
1346 }
1347
1348 /**
1349 * Converts all lines into <div></div>/<p></p>-sections (unless the line is a div-section already)
1350 * For processing of content going FROM database TO RTE.
1351 *
1352 * @param string Value to convert
1353 * @param string Tag to wrap with. Either "p" or "div" should it be. Lowercase preferably.
1354 * @return string Processed value.
1355 * @see divideIntoLines()
1356 */
1357 function setDivTags($value, $dT = 'p') {
1358
1359 // First, setting configuration for the HTMLcleaner function. This will process each line between the <div>/<p> section on their way to the RTE
1360 $keepTags = $this->getKeepTags('rte');
1361 $kUknown = $this->procOptions['dontProtectUnknownTags_rte'] ? 0 : 'protect'; // Default: remove unknown tags.
1362 $hSC = $this->procOptions['dontHSC_rte'] ? 0 : 1; // Default: re-convert literals to characters (that is &lt; to <)
1363 $convNBSP = !$this->procOptions['dontConvAmpInNBSP_rte'] ? 1 : 0;
1364
1365 // Divide the content into lines, based on LF:
1366 $parts = explode(LF, $value);
1367 foreach ($parts as $k => $v) {
1368
1369 // Processing of line content:
1370 if (!strcmp(trim($parts[$k]), '')) { // If the line is blank, set it to &nbsp;
1371 $parts[$k] = '&nbsp;';
1372 } else { // Clean the line content:
1373 $parts[$k] = $this->HTMLcleaner($parts[$k], $keepTags, $kUknown, $hSC);
1374 if ($convNBSP) {
1375 $parts[$k] = str_replace('&amp;nbsp;', '&nbsp;', $parts[$k]);
1376 }
1377 }
1378
1379 // Wrapping the line in <$dT> if not already wrapped and does not contain an hr tag
1380 if (!preg_match('/<(hr)(\s[^>\/]*)?[[:space:]]*\/?>/i', $parts[$k])) {
1381 $testStr = strtolower(trim($parts[$k]));
1382 if (substr($testStr, 0, 4) != '<div' || substr($testStr, -6) != '</div>') {
1383 if (substr($testStr, 0, 2) != '<p' || substr($testStr, -4) != '</p>') {
1384 // Only set p-tags if there is not already div or p tags:
1385 $parts[$k] = '<' . $dT . '>' . $parts[$k] . '</' . $dT . '>';
1386 }
1387 }
1388 }
1389 }
1390
1391 // Implode result:
1392 return implode(LF, $parts);
1393 }
1394
1395 /**
1396 * This splits the $value in font-tag chunks.
1397 * 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.
1398 * This functions seems to be a good choice for pre-processing content if it has been pasted into the RTE from eg. star-office.
1399 * In that case the font-tags are normally on the OUTSIDE of the sections.
1400 * This function is used by eg. divideIntoLines() if the procesing option 'internalizeFontTags' is set.
1401 *
1402 * @param string Input content
1403 * @return string Output content
1404 * @see divideIntoLines()
1405 */
1406 function internalizeFontTags($value) {
1407
1408 // Splitting into font tag blocks:
1409 $fontSplit = $this->splitIntoBlock('font', $value);
1410
1411 foreach ($fontSplit as $k => $v) {
1412 if ($k % 2) { // Inside
1413 $fTag = $this->getFirstTag($v); // Fint font-tag
1414
1415 $divSplit_sub = $this->splitIntoBlock('div,p', $this->removeFirstAndLastTag($v), 1);
1416 if (count($divSplit_sub) > 1) { // If there were div/p sections inside the font-tag, do something about it...
1417 // traverse those sections:
1418 foreach ($divSplit_sub as $k2 => $v2) {
1419 if ($k2 % 2) { // Inside
1420 $div_p = $this->getFirstTag($v2); // Fint font-tag
1421 $div_p_tagname = $this->getFirstTagName($v2); // Fint font-tag
1422 $v2 = $this->removeFirstAndLastTag($v2); // ... and remove it from original.
1423 $divSplit_sub[$k2] = $div_p . $fTag . $v2 . '</font>' . '</' . $div_p_tagname . '>';
1424 } elseif (trim(strip_tags($v2))) {
1425 $divSplit_sub[$k2] = $fTag . $v2 . '</font>';
1426 }
1427 }
1428 $fontSplit[$k] = implode('', $divSplit_sub);
1429 }
1430 }
1431 }
1432
1433 return implode('', $fontSplit);
1434 }
1435
1436 /**
1437 * Returns SiteURL based on thisScript.
1438 *
1439 * @return string Value of t3lib_div::getIndpEnv('TYPO3_SITE_URL');
1440 * @see t3lib_div::getIndpEnv()
1441 */
1442 function siteUrl() {
1443 return t3lib_div::getIndpEnv('TYPO3_SITE_URL');
1444 }
1445
1446 /**
1447 * Return the storage folder of RTE image files.
1448 * Default is $GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir'] unless something else is configured in the types configuration for the RTE.
1449 *
1450 * @return string
1451 */
1452 function rteImageStorageDir() {
1453 return $this->rte_p['imgpath'] ? $this->rte_p['imgpath'] : $GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir'];
1454 }
1455
1456 /**
1457 * Remove all tables from incoming code
1458 * 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.
1459 *
1460 * @param string Input value
1461 * @param string Break character to use for linebreaks.
1462 * @return string Output value
1463 */
1464 function removeTables($value, $breakChar = '<br />') {
1465
1466 // Splitting value into table blocks:
1467 $tableSplit = $this->splitIntoBlock('table', $value);
1468
1469 // Traverse blocks of tables:
1470 foreach ($tableSplit as $k => $v) {
1471 if ($k % 2) {
1472 $tableSplit[$k] = '';
1473 $rowSplit = $this->splitIntoBlock('tr', $v);
1474 foreach ($rowSplit as $k2 => $v2) {
1475 if ($k2 % 2) {
1476 $cellSplit = $this->getAllParts($this->splitIntoBlock('td', $v2), 1, 0);
1477 foreach ($cellSplit as $k3 => $v3) {
1478 $tableSplit[$k] .= $v3 . $breakChar;
1479 }
1480 }
1481 }
1482 }
1483 }
1484
1485 // Implode it all again:
1486 return implode($breakChar, $tableSplit);
1487 }
1488
1489 /**
1490 * Default tag mapping for TS
1491 *
1492 * @param string Input code to process
1493 * @param string Direction To databsae (db) or from database to RTE (rte)
1494 * @return string Processed value
1495 */
1496 function defaultTStagMapping($code, $direction = 'rte') {
1497 if ($direction == 'db') {
1498 $code = $this->mapTags($code, array( // Map tags
1499 'strong' => 'b',
1500 'em' => 'i'
1501 ));
1502 }
1503 if ($direction == 'rte') {
1504 $code = $this->mapTags($code, array( // Map tags
1505 'b' => 'strong',
1506 'i' => 'em'
1507 ));
1508 }
1509 return $code;
1510 }
1511
1512 /**
1513 * Finds width and height from attrib-array
1514 * If the width and height is found in the style-attribute, use that!
1515 *
1516 * @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
1517 * @return array Integer w/h in key 0/1. Zero is returned if not found.
1518 */
1519 function getWHFromAttribs($attribArray) {
1520 $style = trim($attribArray['style']);
1521 if ($style) {
1522 $regex = '[[:space:]]*:[[:space:]]*([0-9]*)[[:space:]]*px';
1523 // Width
1524 $reg = array();
1525 preg_match('/width' . $regex . '/i', $style, $reg);
1526 $w = intval($reg[1]);
1527 // Height
1528 preg_match('/height' . $regex . '/i', $style, $reg);
1529 $h = intval($reg[1]);
1530 }
1531 if (!$w) {
1532 $w = $attribArray['width'];
1533 }
1534 if (!$h) {
1535 $h = $attribArray['height'];
1536 }
1537 return array(intval($w), intval($h));
1538 }
1539
1540 /**
1541 * Parse <A>-tag href and return status of email,external,file or page
1542 *
1543 * @param string URL to analyse.
1544 * @return array Information in an array about the URL
1545 */
1546 function urlInfoForLinkTags($url) {
1547 $info = array();
1548 $url = trim($url);
1549 if (substr(strtolower($url), 0, 7) == 'mailto:') {
1550 $info['url'] = trim(substr($url, 7));
1551 $info['type'] = 'email';
1552 } else {
1553 $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...
1554 for ($a = 0; $a < strlen($url); $a++) {
1555 if ($url{$a} != $curURL{$a}) {
1556 break;
1557 }
1558 }
1559
1560 $info['relScriptPath'] = substr($curURL, $a);
1561 $info['relUrl'] = substr($url, $a);
1562 $info['url'] = $url;
1563 $info['type'] = 'ext';
1564
1565 $siteUrl_parts = parse_url($url);
1566 $curUrl_parts = parse_url($curURL);
1567
1568 if ($siteUrl_parts['host'] == $curUrl_parts['host'] // Hosts should match
1569 && (!$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)
1570
1571 // New processing order 100502
1572 $uP = parse_url($info['relUrl']);
1573
1574 if (!strcmp('#' . $siteUrl_parts['fragment'], $info['relUrl'])) {
1575 $info['url'] = $info['relUrl'];
1576 $info['type'] = 'anchor';
1577 } elseif (!trim($uP['path']) || !strcmp($uP['path'], 'index.php')) {
1578 // URL is a page (id parameter)
1579 $pp = preg_split('/^id=/', $uP['query']);
1580 $pp[1] = preg_replace('/&id=[^&]*/', '', $pp[1]);
1581 $parameters = explode('&', $pp[1]);
1582 $id = array_shift($parameters);
1583 if ($id) {
1584 $info['pageid'] = $id;
1585 $info['cElement'] = $uP['fragment'];
1586 $info['url'] = $id . ($info['cElement'] ? '#' . $info['cElement'] : '');
1587 $info['type'] = 'page';
1588 $info['query'] = $parameters[0] ? '&' . implode('&', $parameters) : '';
1589 }
1590 } else {
1591 $info['url'] = $info['relUrl'];
1592 $info['type'] = 'file';
1593 }
1594 } else {
1595 unset($info['relScriptPath']);
1596 unset($info['relUrl']);
1597 }
1598 }
1599 return $info;
1600 }
1601
1602 /**
1603 * Converting <A>-tags to absolute URLs (+ setting rtekeep attribute)
1604 *
1605 * @param string Content input
1606 * @param boolean If true, then the "rtekeep" attribute will not be set.
1607 * @return string Content output
1608 */
1609 function TS_AtagToAbs($value, $dontSetRTEKEEP = FALSE) {
1610 $blockSplit = $this->splitIntoBlock('A', $value);
1611 foreach ($blockSplit as $k => $v) {
1612 if ($k % 2) { // block:
1613 $attribArray = $this->get_tag_attributes_classic($this->getFirstTag($v), 1);
1614
1615 // Checking if there is a scheme, and if not, prepend the current url.
1616 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...
1617 $uP = parse_url(strtolower($attribArray['href']));
1618 if (!$uP['scheme']) {
1619 $attribArray['href'] = $this->siteUrl() . substr($attribArray['href'], strlen($this->relBackPath));
1620 } elseif ($uP['scheme'] != 'mailto') {
1621 $attribArray['external'] = 1;
1622 }
1623 } else {
1624 $attribArray['rtekeep'] = 1;
1625 }
1626 if (!$dontSetRTEKEEP) {
1627 $attribArray['rtekeep'] = 1;
1628 }
1629
1630 $bTag = '<a ' . t3lib_div::implodeAttributes($attribArray, 1) . '>';
1631 $eTag = '</a>';
1632 $blockSplit[$k] = $bTag . $this->TS_AtagToAbs($this->removeFirstAndLastTag($blockSplit[$k])) . $eTag;
1633 }
1634 }
1635 return implode('', $blockSplit);
1636 }
1637 }
1638
1639
1640 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_parsehtml_proc.php'])) {
1641 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_parsehtml_proc.php']);
1642 }
1643
1644 ?>