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