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