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