*** empty log message ***
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_parsehtml_proc.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skaarhoj (kasper@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Functions for parsing HTML, specially for TYPO3 processing in relation to TCEmain and Rich Text Editor (RTE)
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
32 * Generally NOT XHTML compatible. Must be revised for XHTML compatibility later.
33 *
34 * @author Kasper Skaarhoj <kasper@typo3.com>
35 * @internal
36 */
37 /**
38 * [CLASS/FUNCTION INDEX of SCRIPT]
39 *
40 *
41 *
42 * 99: class t3lib_parsehtml_proc extends t3lib_parsehtml
43 * 126: function init($elRef='',$recPid=0)
44 * 137: function setRelPath($path)
45 * 158: function getURL($url)
46 * 176: function evalWriteFile($pArr,$currentRecord)
47 *
48 * SECTION: TRANSFORMATION functions for specific TYPO3 use
49 * 241: function HTMLcleaner_db($content,$tagList='')
50 * 263: function divideIntoLines($value,$count=5,$returnArray=0)
51 * 347: function internalizeFontTags($value)
52 * 384: function setDivTags($value,$dT='P')
53 * 411: function siteUrl()
54 * 422: function removeTables($value,$breakChar='<BR>')
55 * 451: function defaultTStagMapping($code,$direction='rte')
56 * 474: function getWHFromAttribs($attribArray)
57 * 500: function urlInfoForLinkTags($url)
58 * 557: function TS_images_db($value)
59 * 653: function TS_images_rte($value)
60 * 679: function TS_reglinks($value,$direction)
61 * 711: function TS_links_db($value)
62 * 752: function TS_AtagToAbs($value,$dontSetRTEKEEP=0)
63 * 779: function TS_links_rte($value)
64 * 852: function TS_preserve_db($value)
65 * 876: function TS_preserve_rte($value)
66 * 896: function TS_strip_db($value)
67 * 906: function getKeepTags($direction='rte',$tagList='')
68 * 986: function TS_transform_db($value,$css=0)
69 * 1074: function TS_transform_rte($value,$css=0)
70 * 1146: function TS_tmplParts_rte($value)
71 * 1189: function RTE_transform($value,$specConf,$direction='rte',$thisConfig='')
72 * 1301: function rteImageStorageDir()
73 *
74 * TOTAL FUNCTIONS: 28
75 * (This index is automatically created/updated by the extension "extdeveval")
76 *
77 */
78
79 require_once (PATH_t3lib.'class.t3lib_parsehtml.php');
80
81
82
83
84
85
86
87
88
89
90
91
92 /**
93 * Class for parsing HTML for the Rich Text Editor. (also called transformations)
94 *
95 * @author Kasper Skaarhoj <kasper@typo3.com>
96 * @package TYPO3
97 * @subpackage t3lib
98 */
99 class t3lib_parsehtml_proc extends t3lib_parsehtml {
100 var $recPid = 0; // Set this to the pid of the record manipulated by the class.
101 var $elRef = '';
102 var $procOptions = '';
103 var $headListTags = 'PRE,UL,OL,H1,H2,H3,H4,H5,H6';
104 var $preserveTags = '';
105
106 var $relPath='';
107 var $relBackPath='';
108 var $getKeepTags_cache=array();
109 var $allowedClasses=array();
110
111 // Internal
112 var $TS_transform_db_safecounter=100;
113 var $rte_p='';
114
115
116
117
118
119 /**
120 * Initialize, setting element reference and record PID
121 *
122 * @param [type] $elRef: ...
123 * @param [type] $recPid: ...
124 * @return [type] ...
125 */
126 function init($elRef='',$recPid=0) {
127 $this->recPid=$recPid;
128 $this->elRef=$elRef;
129 }
130
131 /**
132 * Setting the ->relPath and ->relBackPath to proper values so absolute references to links and images can be converted to relative dittos.
133 *
134 * @param [type] $path: ...
135 * @return [type] ...
136 */
137 function setRelPath($path) {
138 $path = trim($path);
139 $path = ereg_replace('^/','',$path);
140 $path = ereg_replace('/$','',$path);
141 if ($path) {
142 $this->relPath = $path;
143 $this->relBackPath = '';
144 $partsC=count(explode('/',$this->relPath));
145 for ($a=0;$a<$partsC;$a++) {
146 $this->relBackPath.='../';
147 }
148 $this->relPath.='/';
149 }
150 }
151
152 /**
153 * Reads the file or url $url and returns the content
154 *
155 * @param [type] $url: ...
156 * @return [type] ...
157 */
158 function getURL($url) {
159 if($fd = @fopen($url,'rb')) {
160 $content = '';
161 while (!feof($fd)) {
162 $content.=fread($fd, 5000);
163 }
164 fclose($fd);
165 return $content;
166 }
167 }
168
169 /**
170 * Evaluate the environment for editing a staticFileEdit file.
171 *
172 * @param [type] $pArr: ...
173 * @param [type] $currentRecord: ...
174 * @return mixed On success an array with various information is returned, otherwise a string with an error message
175 */
176 function evalWriteFile($pArr,$currentRecord) {
177 // Write file configuration:
178 if (is_array($pArr)) {
179 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath']
180 && substr($GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'],-1)=='/'
181 && @is_dir(PATH_site.$GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'])) {
182
183 $SW_p = $pArr['parameters'];
184 $SW_editFileField = trim($SW_p[0]);
185 $SW_editFile = $currentRecord[$SW_editFileField];
186 if ($SW_editFileField && $SW_editFile && t3lib_div::validPathStr($SW_editFile)) {
187 $SW_relpath = $GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'].$SW_editFile;
188 $SW_editFile = PATH_site.$SW_relpath;
189 if (@is_file($SW_editFile)) {
190 return array(
191 'editFile' => $SW_editFile,
192 'relEditFile' => $SW_relpath,
193 'contentField' => trim($SW_p[1]),
194 'markerField' => trim($SW_p[2]),
195 'loadFromFileField' => trim($SW_p[3]),
196 'statusField' => trim($SW_p[4])
197 );
198 } else return "ERROR: Editfile '".$SW_relpath."' did not exist";
199 } else return "ERROR: Edit file name could not be found or was bad.";
200 } else return "ERROR: staticFileEditPath was not set, not set correctly or did not exist!";
201 }
202 }
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228 /************************************
229 *
230 * TRANSFORMATION functions for specific TYPO3 use
231 *
232 *************************************/
233
234 /**
235 * Function for cleaning content going to the database.
236 *
237 * @param [type] $content: ...
238 * @param [type] $tagList: ...
239 * @return [type] ...
240 */
241 function HTMLcleaner_db($content,$tagList='') {
242 if (!$tagList) {
243 $keepTags = $this->getKeepTags('db');
244 } else {
245 $keepTags = $this->getKeepTags('db',$tagList);
246 }
247 $kUknown = $this->procOptions['dontRemoveUnknownTags_db'] ? 1 : 0; // Default: remove unknown tags.
248 $hSC = $this->procOptions['dontUndoHSC_db'] ? 0 : -1; // Default: re-convert literals to characters (that is &lt; to <)
249
250 return $this->HTMLcleaner($content,$keepTags,$kUknown,$hSC);
251 }
252
253 /**
254 * This resolves the $value into parts based on <div></div>-sections and <P>-sections and <BR>-tags. These are returned as lines separated by chr(10).
255 * This point is to resolve the HTML-code returned from RTE into ordinary lines so it's 'human-readable'
256 * The function ->setDivTags does the opposite.
257 *
258 * @param [type] $value: ...
259 * @param [type] $count: ...
260 * @param [type] $returnArray: ...
261 * @return [type] ...
262 */
263 function divideIntoLines($value,$count=5,$returnArray=0) {
264 if ($this->procOptions['internalizeFontTags']) {$value = $this->internalizeFontTags($value);}
265 $allowTagsOutside = t3lib_div::trimExplode(',',strtolower($this->procOptions['allowTagsOutside']?$this->procOptions['allowTagsOutside']:'img'),1);
266 $remapParagraphTag = strtoupper($this->procOptions['remapParagraphTag']);
267 $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...?
268
269 $keepAttribListArr = array();
270 if ($this->procOptions['keepPDIVattribs']) {
271 $keepAttribListArr = t3lib_div::trimExplode(',',strtolower($this->procOptions['keepPDIVattribs']),1);
272 }
273
274 // returns plainly the value if there was no div/p sections in it
275 if (count($divSplit)<=1 || $count<=0) {
276 return $value;
277 }
278
279 reset($divSplit);
280 while(list($k,$v)=each($divSplit)) {
281 if ($k%2) { // Inside
282 $v=$this->removeFirstAndLastTag($v);
283
284 // Fetching 'sub-lines' - which will explode any further p/div nesting...
285 $subLines = $this->divideIntoLines($v,$count-1,1);
286 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')
287
288 } else { //... but if NO subsection was found, we process it as a TRUE line without erronous content:
289 $subLines=array($subLines);
290 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...
291 $subLines = spliti('<BR[[:space:]]*>',$v);
292 }
293 reset($subLines);
294 while(list($sk)=each($subLines)) {
295 $subLines[$sk]=$this->HTMLcleaner_db($subLines[$sk]);
296
297 $fTag = $this->getFirstTag($divSplit[$k]);
298 $tagName=$this->getFirstTagName($divSplit[$k]);
299 $attribs=$this->get_tag_attributes($fTag);
300
301 $newAttribs=array();
302 // Keep attributes
303 if (count($keepAttribListArr)) {
304 reset($keepAttribListArr);
305 while(list(,$keepA)=each($keepAttribListArr)) {
306 if (isset($attribs[0][$keepA])) {$newAttribs[$keepA]=$attribs[0][$keepA];}
307 }
308 }
309 // ALIGN attribute:
310 if (!$this->procOptions['skipAlign'] && strcmp($attribs[0]['align'],'') && strtolower($attribs[0]['align'])!='left') { // Set to value, but not 'left'
311 $newAttribs['align']=$attribs[0]['align'];
312 }
313 // CLASS attribute:
314 if (!$this->procOptions['skipClass'] && strcmp($attribs[0]['class'],'')) { // Set to whatever value
315 if (!count($this->allowedClasses) || in_array(strtoupper($attribs[0]['class']),$this->allowedClasses)) {
316 $newAttribs['class']=$attribs[0]['class'];
317 }
318 }
319 $subLines[$sk]=ereg_replace(chr(10).'|'.chr(13),'',$subLines[$sk]);
320 if (count($newAttribs) && strcmp($remapParagraphTag,'1')) {
321 if ($remapParagraphTag=='P') $tagName='P';
322 if ($remapParagraphTag=='DIV') $tagName='DIV';
323 $subLines[$sk]='<'.trim($tagName.' '.$this->compileTagAttribs($newAttribs)).'>'.$subLines[$sk].'</'.$tagName.'>';
324 }
325 }
326 }
327 $divSplit[$k] = implode(chr(10),$subLines);
328 if (trim(strip_tags($divSplit[$k]))=='&nbsp;') $divSplit[$k]='';
329 } else { // outside div:
330 // Remove positions which are outside div/p tags and without content
331 $divSplit[$k]=trim(strip_tags($divSplit[$k],'<'.implode('><',$allowTagsOutside).'>'));
332 if (!$divSplit[$k]) unset($divSplit[$k]); // Remove part if it's
333 }
334 }
335 return $returnArray ? $divSplit : implode(chr(10),$divSplit);
336 }
337
338 /**
339 * This splits the $value in font-tag chunks.
340 * 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.
341 * This functions seems to be a good choice for pre-processing content if it has been pasted into the RTE from eg. star-office.
342 * In that case the font-tags is normally on the OUTSIDE of the sections.
343 *
344 * @param [type] $value: ...
345 * @return [type] ...
346 */
347 function internalizeFontTags($value) {
348 $fontSplit = $this->splitIntoBlock('font',$value);
349
350 reset($fontSplit);
351 while(list($k,$v)=each($fontSplit)) {
352 if ($k%2) { // Inside
353 $fTag = $this->getFirstTag($v); // Fint font-tag
354
355 $divSplit_sub = $this->splitIntoBlock('div,p',$this->removeFirstAndLastTag($v),1);
356 if (count($divSplit_sub)>1) { // If there were div/p sections inside the font-tag, do something about it...
357 // traverse those sections:
358 reset($divSplit_sub);
359 while(list($k2,$v2)=each($divSplit_sub)) {
360 if ($k2%2) { // Inside
361 $div_p = $this->getFirstTag($v2); // Fint font-tag
362 $div_p_tagname = $this->getFirstTagName($v2); // Fint font-tag
363 $v2=$this->removeFirstAndLastTag($v2); // ... and remove it from original.
364 $divSplit_sub[$k2]=$div_p.$fTag.$v2.'</FONT>'.'</'.$div_p_tagname.'>';
365 } elseif (trim(strip_tags($v2))) {
366 $divSplit_sub[$k2]=$fTag.$v2.'</FONT>';
367 }
368 }
369 $fontSplit[$k]=implode('',$divSplit_sub);
370 }
371 }
372 }
373
374 return implode('',$fontSplit);
375 }
376
377 /**
378 * Converts all lines into <div></div>-sections (unless the line is a div-section already
379 *
380 * @param [type] $value: ...
381 * @param [type] $dT: ...
382 * @return [type] ...
383 */
384 function setDivTags($value,$dT='P') {
385 $keepTags = $this->getKeepTags('rte');
386 $kUknown = $this->procOptions['dontProtectUnknownTags_rte'] ? 0 : 'protect'; // Default: remove unknown tags.
387 $hSC = $this->procOptions['dontHSC_rte'] ? 0 : 1; // Default: re-convert literals to characters (that is &lt; to <)
388 $convNBSP = !$this->procOptions['dontConvAmpInNBSP_rte']?1:0;
389
390 $parts = explode(chr(10),$value);
391 reset($parts);
392 while(list($k,$v)=each($parts)) {
393 $parts[$k]=$this->HTMLcleaner($parts[$k],$keepTags,$kUknown,$hSC);
394 if ($convNBSP) $parts[$k]=str_replace('&amp;nbsp;','&nbsp;',$parts[$k]);
395 if (!$v) $parts[$k]='&nbsp;';
396 if (substr(strtoupper(trim($parts[$k])),0,4)!='<DIV' || substr(strtoupper(trim($parts[$k])),-6)!='</DIV>') {
397 if (substr(strtoupper(trim($parts[$k])),0,2)!='<P' || substr(strtoupper(trim($parts[$k])),-4)!='</P>') {
398 // Only set p-tags if there is not already div or p tags:
399 $parts[$k]='<'.$dT.'>'.(trim($parts[$k])?$parts[$k]:'&nbsp;').'</'.$dT.'>';
400 }
401 }
402 }
403 return implode(chr(10),$parts);
404 }
405
406 /**
407 * Returns SiteURL based on thisScript.
408 *
409 * @return [type] ...
410 */
411 function siteUrl() {
412 return t3lib_div::getIndpEnv('TYPO3_SITE_URL');
413 }
414
415 /**
416 * Remove all tables from incoming code
417 *
418 * @param [type] $value: ...
419 * @param [type] $breakChar: ...
420 * @return [type] ...
421 */
422 function removeTables($value,$breakChar='<BR>') {
423 $tableSplit = $this->splitIntoBlock('table',$value);
424 reset($tableSplit);
425 while(list($k,$v)=each($tableSplit)) {
426 if ($k%2) {
427 $tableSplit[$k]='';
428 $rowSplit = $this->splitIntoBlock('tr',$v);
429 reset($rowSplit);
430 while(list($k2,$v2)=each($rowSplit)) {
431 if ($k2%2) {
432 $cellSplit = $this->getAllParts($this->splitIntoBlock('td',$v2),1,0);
433 reset($cellSplit);
434 while(list($k3,$v3)=each($cellSplit)) {
435 $tableSplit[$k].=$v3.$breakChar;
436 }
437 }
438 }
439 }
440 }
441 return implode($breakChar,$tableSplit);
442 }
443
444 /**
445 * Default tag mapping for TS
446 *
447 * @param [type] $code: ...
448 * @param [type] $direction: ...
449 * @return [type] ...
450 */
451 function defaultTStagMapping($code,$direction='rte') {
452 if ($direction=='db') {
453 $code=$this->mapTags($code,array( // Map tags
454 'STRONG' => 'B',
455 'EM' => 'I'
456 ));
457 }
458 if ($direction=='rte') {
459 $code=$this->mapTags($code,array( // Map tags
460 'B' => 'STRONG',
461 'I' => 'EM'
462 ));
463 }
464 return $code;
465 }
466
467 /**
468 * Finds width and height from attrib-array
469 * If the width and height is found in the style-attribute, use that!
470 *
471 * @param [type] $attribArray: ...
472 * @return [type] ...
473 */
474 function getWHFromAttribs($attribArray) {
475 $style =trim($attribArray['style']);
476 if ($style) {
477 $regex='[[:space:]]*:[[:space:]]*([0-9]*)[[:space:]]*px';
478 // Width
479 eregi('width'.$regex,$style,$reg);
480 $w = intval($reg[1]);
481 // Height
482 eregi('height'.$regex,$style,$reg);
483 $h = intval($reg[1]);
484 }
485 if (!$w) {
486 $w = $attribArray['width'];
487 }
488 if (!$h) {
489 $h = $attribArray['height'];
490 }
491 return array(intval($w),intval($h));
492 }
493
494 /**
495 * Parse <A>-tag href and return status of email,external,file or page
496 *
497 * @param [type] $url: ...
498 * @return [type] ...
499 */
500 function urlInfoForLinkTags($url) {
501 $url = trim($url);
502 if (substr(strtolower($url),0,7)=='mailto:') {
503 $info['url']=trim(substr($url,7));
504 $info['type']='email';
505 } else {
506 $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...
507 for($a=0;$a<strlen($url);$a++) {
508 if ($url[$a]!=$curURL[$a]) {
509 break;
510 }
511 }
512
513 $info['relScriptPath']=substr($curURL,$a);
514 $info['relUrl']=substr($url,$a);
515 $info['url']=$url;
516 $info['type']='ext';
517
518 $siteUrl_parts = parse_url($url);
519 $curUrl_parts = parse_url($curURL);
520
521 if ($siteUrl_parts['host']==$curUrl_parts['host'] // Hosts should match
522 && (!$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)
523
524 // New processing order 100502
525 $uP=parse_url($info['relUrl']);
526
527 if (!strcmp('#'.$siteUrl_parts['fragment'],$info['relUrl'])) {
528 $info['url']=$info['relUrl'];
529 $info['type']='anchor';
530 } elseif (!trim($uP['path']) || !strcmp($uP['path'],'index.php')) {
531 $pp = explode('id=',$uP['query']);
532 $id = trim($pp[1]);
533 if ($id) {
534 $info['pageid']=$id;
535 $info['cElement']=$uP['fragment'];
536 $info['url']=$id.($info['cElement']?'#'.$info['cElement']:'');
537 $info['type']='page';
538 }
539 } else {
540 $info['url']=$info['relUrl'];
541 $info['type']='file';
542 }
543 } else {
544 unset($info['relScriptPath']);
545 unset($info['relUrl']);
546 }
547 }
548 return $info;
549 }
550
551 /**
552 * Processing images inserted in the RTE.
553 *
554 * @param [type] $value: ...
555 * @return [type] ...
556 */
557 function TS_images_db($value) {
558 $imgSplit = $this->splitTags('img',$value);
559 reset($imgSplit);
560 while(list($k,$v)=each($imgSplit)) {
561 if ($k%2) { // image:
562 $attribArray=$this->get_tag_attributes_classic($v,1);
563 $siteUrl = $this->siteUrl();
564 $absRef = trim($attribArray['src']);
565
566 // External?
567 if (!t3lib_div::isFirstPartOfStr($absRef,$siteUrl) && !$this->procOptions['dontFetchExtPictures']) {
568 $externalFile = $this->getUrl($absRef); // Get it
569 if ($externalFile) {
570 $pU = parse_url($absRef);
571 $pI=pathinfo($pU['path']);
572
573 if (t3lib_div::inList('gif,png,jpeg,jpg',strtolower($pI['extension']))) {
574 $filename = t3lib_div::shortMD5($absRef).'.'.$pI['extension'];
575 $origFilePath = PATH_site.$this->rteImageStorageDir().'RTEmagicP_'.$filename;
576 $C_origFilePath = PATH_site.$this->rteImageStorageDir().'RTEmagicC_'.$filename.'.'.$pI['extension'];
577 if (!@is_file($origFilePath)) {
578 t3lib_div::writeFile($origFilePath,$externalFile);
579 t3lib_div::writeFile($C_origFilePath,$externalFile);
580 }
581 $absRef = $siteUrl.$this->rteImageStorageDir().'RTEmagicC_'.$filename.'.'.$pI['extension'];
582
583 $attribArray['src']=$absRef;
584 if (!isset($attribArray['alt'])) $attribArray['alt']='';
585 $params = t3lib_div::implodeParams($attribArray,1);
586 $imgSplit[$k]='<img '.$params.' />';
587 }
588 }
589 }
590 // Check file
591 if (t3lib_div::isFirstPartOfStr($absRef,$siteUrl)) {
592 $path = substr($absRef,strlen($siteUrl));
593 $pathPre=$this->rteImageStorageDir().'RTEmagicC_';
594
595 if (t3lib_div::isFirstPartOfStr($path,$pathPre)) {
596 $filepath = PATH_site.$path;
597 if (@is_file($filepath)) {
598 // Find original file:
599 $pI=pathinfo(substr($path,strlen($pathPre)));
600 $filename = substr($pI['basename'],0,-strlen('.'.$pI['extension']));
601 $origFilePath = PATH_site.$this->rteImageStorageDir().'RTEmagicP_'.$filename;
602 if (@is_file($origFilePath)) {
603 $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
604 $imgObj->init();
605 $imgObj->mayScaleUp=0;
606 $imgObj->tempPath=PATH_site.$imgObj->tempPath;
607
608 $curInfo = $imgObj->getImageDimensions($filepath); // Image dimensions of the current image
609 $curWH = $this->getWHFromAttribs($attribArray); // Image dimensions as set in the image tag
610 // Compare dimensions:
611 if ($curWH[0]!=$curInfo[0] || $curWH[1]!=$curInfo[1]) {
612 $origImgInfo = $imgObj->getImageDimensions($origFilePath); // Image dimensions of the current image
613 $cW = $curWH[0];
614 $cH = $curWH[1];
615 $cH = 1000; // Make the image based on the width solely...
616 $imgI = $imgObj->imageMagickConvert($origFilePath,$pI['extension'],$cW.'m',$cH.'m');
617 if ($imgI[3]) {
618 $fI=pathinfo($imgI[3]);
619 @copy($imgI[3],$filepath); // Override the child file
620 unset($attribArray['style']);
621 $attribArray['width']=$imgI[0];
622 $attribArray['height']=$imgI[1];
623 if (!$attribArray['border']) $attribArray['border']=0;
624 if (!isset($attribArray['alt'])) $attribArray['alt']='';
625 $params = t3lib_div::implodeParams($attribArray,1);
626 $imgSplit[$k]='<img '.$params.' />';
627 }
628 }
629 }
630 }
631 }
632 }
633
634 // Convert abs to rel url
635 $attribArray=$this->get_tag_attributes_classic($imgSplit[$k],1);
636 $absRef = trim($attribArray['src']);
637 if (t3lib_div::isFirstPartOfStr($absRef,$siteUrl)) {
638 $attribArray['src'] = $this->relBackPath.substr($absRef,strlen($siteUrl));
639 if (!isset($attribArray['alt'])) $attribArray['alt']='';
640 $imgSplit[$k]='<img '.t3lib_div::implodeParams($attribArray,1).' />';
641 }
642 }
643 }
644 return implode('',$imgSplit);
645 }
646
647 /**
648 * Processing images inserted in the RTE.
649 *
650 * @param [type] $value: ...
651 * @return [type] ...
652 */
653 function TS_images_rte($value) {
654 $imgSplit = $this->splitTags('img',$value);
655 reset($imgSplit);
656 while(list($k,$v)=each($imgSplit)) {
657 if ($k%2) { // image:
658 $attribArray=$this->get_tag_attributes_classic($v,1);
659 $siteUrl = $this->siteUrl();
660 $absRef = trim($attribArray['src']);
661 if (strtolower(substr($absRef,0,4))!='http') {
662 $attribArray['src'] = $siteUrl.substr($attribArray['src'],strlen($this->relBackPath));
663 if (!isset($attribArray['alt'])) $attribArray['alt']='';
664 $params = t3lib_div::implodeParams($attribArray);
665 $imgSplit[$k]='<img '.$params.' />';
666 }
667 }
668 }
669 return implode('',$imgSplit);
670 }
671
672 /**
673 * Converting <A>-tags to/from abs/rel
674 *
675 * @param [type] $value: ...
676 * @param [type] $direction: ...
677 * @return [type] ...
678 */
679 function TS_reglinks($value,$direction) {
680 switch($direction) {
681 case 'rte':
682 return $this->TS_AtagToAbs($value,1);
683 break;
684 case 'db':
685 $siteURL = $this->siteUrl();
686 $blockSplit = $this->splitIntoBlock('A',$value);
687 reset($blockSplit);
688 while(list($k,$v)=each($blockSplit)) {
689 if ($k%2) { // block:
690 $attribArray=$this->get_tag_attributes_classic($this->getFirstTag($v),1);
691 // If the url is local, remove url-prefix
692 if ($siteURL && substr($attribArray['href'],0,strlen($siteURL))==$siteURL) {
693 $attribArray['href']=$this->relBackPath.substr($attribArray['href'],strlen($siteURL));
694 }
695 $bTag='<a '.t3lib_div::implodeParams($attribArray,1).'>';
696 $eTag='</a>';
697 $blockSplit[$k] = $bTag.$this->TS_reglinks($this->removeFirstAndLastTag($blockSplit[$k]),$direction).$eTag;
698 }
699 }
700 return implode('',$blockSplit);
701 break;
702 }
703 }
704
705 /**
706 * Converting <A>-tags to <LINK tags>
707 *
708 * @param [type] $value: ...
709 * @return [type] ...
710 */
711 function TS_links_db($value) {
712 $blockSplit = $this->splitIntoBlock('A',$value);
713 reset($blockSplit);
714 while(list($k,$v)=each($blockSplit)) {
715 if ($k%2) { // block:
716 $attribArray=$this->get_tag_attributes_classic($this->getFirstTag($v),1);
717 $info = $this->urlInfoForLinkTags($attribArray['href']);
718
719 // Check options:
720 $attribArray_copy = $attribArray;
721 unset($attribArray_copy['href']);
722 unset($attribArray_copy['target']);
723 unset($attribArray_copy['class']);
724 if (!count($attribArray_copy)) { // Only if href, target and class are the only attributes, we can alter the link!
725 $bTag='<LINK '.$info['url'].($attribArray['target']?' '.$attribArray['target']:($attribArray['class']?' -':'')).($attribArray['class']?' '.$attribArray['class']:'').'>';
726 $eTag='</LINK>';
727 $blockSplit[$k] = $bTag.$this->TS_links_db($this->removeFirstAndLastTag($blockSplit[$k])).$eTag;
728 } else { // ... otherwise store the link as a-tag.
729 // Unsetting 'rtekeep' attribute if that had been set.
730 unset($attribArray['rtekeep']);
731 // If the url is local, remove url-prefix
732 $siteURL = $this->siteUrl();
733 if ($siteURL && substr($attribArray['href'],0,strlen($siteURL))==$siteURL) {
734 $attribArray['href']=$this->relBackPath.substr($attribArray['href'],strlen($siteURL));
735 }
736 $bTag='<a '.t3lib_div::implodeParams($attribArray,1).'>';
737 $eTag='</a>';
738 $blockSplit[$k] = $bTag.$this->TS_links_db($this->removeFirstAndLastTag($blockSplit[$k])).$eTag;
739 }
740 }
741 }
742 return implode('',$blockSplit);
743 }
744
745 /**
746 * Converting <A>-tags to absolute URLs (+ setting rtekeep attribute)
747 *
748 * @param [type] $value: ...
749 * @param [type] $dontSetRTEKEEP: ...
750 * @return [type] ...
751 */
752 function TS_AtagToAbs($value,$dontSetRTEKEEP=0) {
753 $blockSplit = $this->splitIntoBlock('A',$value);
754 reset($blockSplit);
755 while(list($k,$v)=each($blockSplit)) {
756 if ($k%2) { // block:
757 $attribArray=$this->get_tag_attributes_classic($this->getFirstTag($v),1);
758 // Checking if there is a scheme, and if not, prepend the current url.
759 $uP = parse_url(strtolower($attribArray['href']));
760 if (!$uP['scheme']) {
761 $attribArray['href']=$this->siteUrl().substr($attribArray['href'],strlen($this->relBackPath));
762 }
763 if (!$dontSetRTEKEEP) $attribArray['rtekeep']=1;
764
765 $bTag='<a '.t3lib_div::implodeParams($attribArray,1).'>';
766 $eTag='</a>';
767 $blockSplit[$k] = $bTag.$this->TS_AtagToAbs($this->removeFirstAndLastTag($blockSplit[$k])).$eTag;
768 }
769 }
770 return implode('',$blockSplit);
771 }
772
773 /**
774 * Converting <LINK tags> to <A>-tags
775 *
776 * @param [type] $value: ...
777 * @return [type] ...
778 */
779 function TS_links_rte($value) {
780 $value = $this->TS_AtagToAbs($value);
781
782 $blockSplit = $this->splitIntoBlock('link',$value,1);
783 reset($blockSplit);
784 while(list($k,$v)=each($blockSplit)) {
785 if ($k%2) { // block:
786 $tagCode = t3lib_div::trimExplode(' ',trim(substr($this->getFirstTag($v),0,-1)),1);
787 $link_param=$tagCode[1];
788 $href='';
789 $siteUrl = $this->siteUrl();
790 // Parsing the typolink data. This parsing is roughly done like in tslib_content->typolink()
791 if(strstr($link_param,'@')) { // mailadr
792 $href = 'mailto:'.eregi_replace('^mailto:','',$link_param);
793 } elseif (substr($link_param,0,1)=='#') { // check if anchor
794 $href = $siteUrl.$link_param;
795 } else {
796 $fileChar=intval(strpos($link_param, '/'));
797 $urlChar=intval(strpos($link_param, '.'));
798
799 // Detects if a file is found in site-root OR is a simulateStaticDocument.
800 list($rootFileDat) = explode('?',$link_param);
801 $rFD_fI = pathinfo($rootFileDat);
802 if (trim($rootFileDat) && !strstr($link_param,'/') && (@is_file(PATH_site.$rootFileDat) || t3lib_div::inList('php,html,htm',strtolower($rFD_fI['extension'])))) {
803 $href = $siteUrl.$link_param;
804 } elseif($urlChar && (strstr($link_param,'//') || !$fileChar || $urlChar<$fileChar)) { // url (external): If doubleSlash or if a '.' comes before a '/'.
805 if (!ereg('^[a-z]*://',trim(strtolower($link_param)))) {$scheme='http://';} else {$scheme='';}
806 $href = $scheme.$link_param;
807 } elseif($fileChar) { // file (internal)
808 $href = $siteUrl.$link_param;
809 } else { // integer or alias (alias is without slashes or periods or commas, that is 'nospace,alphanum_x,lower,unique' according to tables.php!!)
810 $link_params_parts=explode('#',$link_param);
811 $idPart = trim($link_params_parts[0]); // Link-data del
812 if (!strcmp($idPart,'')) {$idPart=$this->recPid;} // If no id or alias is given, set it to class record pid
813 if ($link_params_parts[1] && !$sectionMark) {
814 $sectionMark='#'.trim($link_params_parts[1]);
815 }
816 // Splitting the parameter by ',' and if the array counts more than 1 element it's a id/type/? pair
817 $pairParts = t3lib_div::trimExplode(',',$idPart);
818 if (count($pairParts)>1) {
819 $idPart = $pairParts[0];
820 // Type ? future support for?
821 }
822 // Checking if the id-parameter is an alias.
823 if (!t3lib_div::testInt($idPart)) {
824 list($idPartR) = t3lib_BEfunc::getRecordsByField('pages','alias',$idPart);
825 $idPart=intval($idPartR['uid']);
826 }
827 $page = t3lib_BEfunc::getRecord('pages',$idPart);
828 if (is_array($page)) { // Page must exist...
829 $href = $siteUrl.'?id='.$link_param;
830 } else {
831 $href='';
832 $error='no page: '.$idPart;
833 }
834 }
835 }
836
837 // Setting the A-tag:
838 $bTag='<A href="'.$href.'"'.($tagCode[2]&&$tagCode[2]!="-"?' target="'.$tagCode[2].'"':'').($tagCode[3]?' class="'.$tagCode[3].'"':'').'>';
839 $eTag='</A>';
840 $blockSplit[$k] = $bTag.$this->TS_links_rte($this->removeFirstAndLastTag($blockSplit[$k])).$eTag;
841 }
842 }
843 return implode('',$blockSplit);
844 }
845
846 /**
847 * Preserve special tags
848 *
849 * @param [type] $value: ...
850 * @return [type] ...
851 */
852 function TS_preserve_db($value) {
853 if (!$this->preserveTags) return $value;
854
855 $blockSplit = $this->splitIntoBlock('SPAN',$value);
856 reset($blockSplit);
857 while(list($k,$v)=each($blockSplit)) {
858 if ($k%2) { // block:
859 $attribArray=$this->get_tag_attributes_classic($this->getFirstTag($v));
860 if ($attribArray['specialtag']) {
861 $theTag = rawurldecode($attribArray['specialtag']);
862 $theTagName = $this->getFirstTagName($theTag);
863 $blockSplit[$k] = $theTag.$this->removeFirstAndLastTag($blockSplit[$k]).'</'.$theTagName.'>';
864 }
865 }
866 }
867 return implode('',$blockSplit);
868 }
869
870 /**
871 * Preserve special tags
872 *
873 * @param [type] $value: ...
874 * @return [type] ...
875 */
876 function TS_preserve_rte($value) {
877 if (!$this->preserveTags) return $value;
878
879 $blockSplit = $this->splitIntoBlock($this->preserveTags,$value);
880 reset($blockSplit);
881 while(list($k,$v)=each($blockSplit)) {
882 if ($k%2) { // block:
883 $blockSplit[$k] = '<SPAN specialtag="'.rawurlencode($this->getFirstTag($v)).'">'.$this->removeFirstAndLastTag($blockSplit[$k]).'</SPAN>';
884 }
885 }
886 return implode('',$blockSplit);
887 }
888
889 /**
890 * Removing all non-allowed tags
891 * DEPRECIATED!
892 *
893 * @param [type] $value: ...
894 * @return [type] ...
895 */
896 function TS_strip_db($value) {
897 $value = $this->stripTagsExcept($value,'b,i,u,a,img,br,div,center,pre,font,hr,sub,sup,p,strong,em,li,ul,ol,blockquote');
898 return $value;
899 }
900
901 /**
902 * @param [type] $direction: ...
903 * @param [type] $tagList: ...
904 * @return [type] ...
905 */
906 function getKeepTags($direction='rte',$tagList='') {
907 if (!is_array($this->getKeepTags_cache[$direction]) || $tagList) {
908 $typoScript_list = 'b,i,u,a,img,br,div,center,pre,font,hr,sub,sup,p,strong,em,li,ul,ol,blockquote,strike,span';
909 $keepTags = array_flip(t3lib_div::trimExplode(',',$typoScript_list.','.strtolower($this->procOptions['allowTags']),1));
910 $denyTags = t3lib_div::trimExplode(',',$this->procOptions['denyTags'],1);
911 reset($denyTags);
912 while(list(,$dKe)=each($denyTags)) {
913 unset($keepTags[$dKe]);
914 }
915
916 if (strcmp($tagList,'')) {
917 $keepTags = array_flip(t3lib_div::trimExplode(',',$tagList,1));
918 }
919
920 switch ($direction) {
921 case 'rte':
922 if (isset($keepTags['b'])) {$keepTags['b']=array('remap'=>'STRONG');}
923 if (isset($keepTags['i'])) {$keepTags['i']=array('remap'=>'EM');}
924 list($keepTags) = $this->HTMLparserConfig($this->procOptions['HTMLparser_rte.'],$keepTags);
925 break;
926 case 'db':
927 if (isset($keepTags['strong'])) {$keepTags['strong']=array('remap'=>'B');}
928 if (isset($keepTags['em'])) {$keepTags['em']=array('remap'=>'I');}
929 if (isset($keepTags['span'])) {
930 $classes=array_merge(array(''),$this->allowedClasses);
931 $keepTags['span']=array(
932 'allowedAttribs'=>'class',
933 'fixAttrib' => Array(
934 'class' => Array (
935 'list' => $classes,
936 'removeIfFalse' => 1
937 )
938 ),
939 'rmTagIfNoAttrib' => 1
940 );
941 if (!$this->procOptions['allowedClasses']) unset($keepTags['span']['fixAttrib']['class']['list']);
942 }
943 if (isset($keepTags['font'])) {
944 $colors=array_merge(array(''),t3lib_div::trimExplode(',',$this->procOptions['allowedFontColors'],1));
945 $keepTags['font']=array(
946 'allowedAttribs'=>'face,color,size',
947 'fixAttrib' => Array(
948 'face' => Array (
949 'removeIfFalse' => 1
950 ),
951 'color' => Array (
952 'removeIfFalse' => 1,
953 'list'=>$colors
954 ),
955 'size' => Array (
956 'removeIfFalse' => 1,
957 )
958 ),
959 'rmTagIfNoAttrib' => 1
960 );
961 if (!$this->procOptions['allowedFontColors']) unset($keepTags['font']['fixAttrib']['color']['list']);
962 }
963
964 $TSc = $this->procOptions['HTMLparser_db.'];
965 if (!$TSc['globalNesting']) $TSc['globalNesting']='b,i,u,a,center,font,sub,sup,strong,em,strike,span';
966 if (!$TSc['noAttrib']) $TSc['noAttrib']='b,i,u,br,center,hr,sub,sup,strong,em,li,ul,ol,blockquote,strike';
967 list($keepTags) = $this->HTMLparserConfig($TSc,$keepTags);
968 break;
969 }
970 if (!$tagList) {
971 $this->getKeepTags_cache[$direction] = $keepTags;
972 } else {
973 return $keepTags;
974 }
975 }
976 return $this->getKeepTags_cache[$direction];
977 }
978
979 /**
980 * Cleaning (->db) for standard content elements (ts)
981 *
982 * @param [type] $value: ...
983 * @param [type] $css: ...
984 * @return [type] ...
985 */
986 function TS_transform_db($value,$css=0) {
987 $this->TS_transform_db_safecounter--;
988 if ($this->TS_transform_db_safecounter<0) return $value; // safety... so forever loops are avoided (they should not occur, but an error would potentially do this...)
989 // Work on everything but these blocks.
990 $blockSplit = $this->splitIntoBlock('TABLE,BLOCKQUOTE,'.$this->headListTags,$value);
991
992 $cc=0;
993 $aC = count($blockSplit);
994 reset($blockSplit);
995 while(list($k,$v)=each($blockSplit)) {
996 $cc++;
997 $lastBR = $cc==$aC ? '' : chr(10);
998
999 if ($k%2) { // block:
1000 $tag=$this->getFirstTag($v);
1001 $tagName=$this->getFirstTagName($v);
1002 switch($tagName) {
1003 case 'BLOCKQUOTE': // Keep blockquotes, but clean the inside recursively in the same manner as the main code
1004 $blockSplit[$k]='<'.$tagName.'>'.$this->TS_transform_db($this->removeFirstAndLastTag($blockSplit[$k]),$css).'</'.$tagName.'>'.$lastBR;
1005 break;
1006 case 'OL':
1007 case 'UL': // Transform lists into <typolist>-tags:
1008 if (!$css) {
1009 if (!isset($this->procOptions['typolist']) || $this->procOptions['typolist']) {
1010 $parts = $this->getAllParts($this->splitIntoBlock('LI',$this->removeFirstAndLastTag($blockSplit[$k])),1,0);
1011 while(list($k2)=each($parts)) {
1012 $parts[$k2]=ereg_replace(chr(10).'|'.chr(13),'',$parts[$k2]); // remove all linesbreaks!
1013 $parts[$k2]=$this->defaultTStagMapping($parts[$k2],'db');
1014 $parts[$k2]=$this->cleanFontTags($parts[$k2],0,0,0);
1015 $parts[$k2] = $this->HTMLcleaner_db($parts[$k2],strtolower($this->procOptions['allowTagsInTypolists']?$this->procOptions['allowTagsInTypolists']:'br,font,b,i,u,a,img,span,strong,em'));
1016 }
1017 if ($tagName=='OL') {$params=' type="1"';}else{$params='';}
1018 $blockSplit[$k]='<typolist'.$params.'>'.chr(10).implode(chr(10),$parts).chr(10).'</typolist>'.$lastBR;
1019 }
1020 } else {
1021 $blockSplit[$k].=$lastBR;
1022 }
1023 break;
1024 case 'TABLE': // Tables are NOT allowed in any form.
1025 if (!$this->procOptions['preserveTables'] && !$css) {
1026 $blockSplit[$k]=$this->TS_transform_db($this->removeTables($blockSplit[$k]));
1027 } else {
1028 $blockSplit[$k]=str_replace(chr(10),'',$blockSplit[$k]).$lastBR;
1029 }
1030 break;
1031 case 'H1':
1032 case 'H2':
1033 case 'H3':
1034 case 'H4':
1035 case 'H5':
1036 case 'H6':
1037 if (!$css) {
1038 $attribArray=$this->get_tag_attributes_classic($tag);
1039 // Processing inner content here:
1040 $innerContent = $this->HTMLcleaner_db($this->removeFirstAndLastTag($blockSplit[$k]));
1041
1042 if (!isset($this->procOptions['typohead']) || $this->procOptions['typohead']) {
1043 $type = intval(substr($tagName,1));
1044 $blockSplit[$k]='<typohead'.($type!=6?' type='.$type:'').($attribArray['align']?' align='.$attribArray['align']:'').($attribArray['class']?' class='.$attribArray['class']:'').'>'.$innerContent.'</typohead>'.$lastBR;
1045 } else {
1046 $blockSplit[$k]='<'.$tagName.($attribArray['align']?' align='.$attribArray['align']:'').($attribArray['class']?' class='.$attribArray['class']:'').'>'.$innerContent.'</'.$tagName.'>'.$lastBR;
1047 }
1048 } else {
1049 $blockSplit[$k].=$lastBR;
1050 }
1051 break;
1052 default:
1053 $blockSplit[$k].=$lastBR;
1054 break;
1055 }
1056 } else { // NON-block:
1057 if (strcmp(trim($blockSplit[$k]),'')) {
1058 $blockSplit[$k]=$this->divideIntoLines($blockSplit[$k]).$lastBR;
1059 } else unset($blockSplit[$k]);
1060 }
1061 }
1062 $this->TS_transform_db_safecounter++;
1063
1064 return implode('',$blockSplit);
1065 }
1066
1067 /**
1068 * Set (->rte) for standard content elements (ts)
1069 *
1070 * @param [type] $value: ...
1071 * @param [type] $css: ...
1072 * @return [type] ...
1073 */
1074 function TS_transform_rte($value,$css=0) {
1075 // Work on everything but the blocks.
1076 $blockSplit = $this->splitIntoBlock('TABLE,BLOCKQUOTE,TYPOLIST,TYPOHEAD,'.$this->headListTags,$value);
1077 reset($blockSplit);
1078 while(list($k,$v)=each($blockSplit)) {
1079 //debug(t3lib_div::debug_ordvalue($blockSplit[$k]),1);
1080 }
1081
1082 reset($blockSplit);
1083 while(list($k,$v)=each($blockSplit)) {
1084 if ($k%2) { // block:
1085 $tag=$this->getFirstTag($v);
1086 $tagName=$this->getFirstTagName($v);
1087 $attribArray=$this->get_tag_attributes_classic($tag);
1088 switch($tagName) {
1089 case 'BLOCKQUOTE': // Keep blockquotes:
1090 $blockSplit[$k]=$tag.$this->TS_transform_rte($this->removeFirstAndLastTag($blockSplit[$k]),$css).'</'.$tagName.'>';
1091 break;
1092 case 'TYPOLIST': // Transform typolist blocks into OL/UL lists. Type 1 is expected to be numerical block
1093 if (!isset($this->procOptions['typolist']) || $this->procOptions['typolist']) {
1094 $tListContent = $this->removeFirstAndLastTag($blockSplit[$k]);
1095 $tListContent = ereg_replace('^[ ]*'.chr(10),'',$tListContent);
1096 $tListContent = ereg_replace(chr(10).'[ ]*$','',$tListContent);
1097 $lines=explode(chr(10),$tListContent);
1098 $typ= $attribArray['type']==1?'ol':'ul';
1099 $blockSplit[$k]='<'.$typ.'>'.chr(10).'<li>'.implode('</li>'.chr(10).'<li>',$lines).'</li></'.$typ.'>';
1100 }
1101 break;
1102 case 'TYPOHEAD': // Transform typohead into Hx tags.
1103 if (!isset($this->procOptions['typohead']) || $this->procOptions['typohead']) {
1104 $tC=$this->removeFirstAndLastTag($blockSplit[$k]);
1105 $typ=t3lib_div::intInRange($attribArray['type'],0,6);
1106 if (!$typ) $typ=6;
1107 $align = $attribArray['align']?' align='.$attribArray['align']: '';
1108 $class = $attribArray['class']?' class='.$attribArray['class']: '';
1109 $blockSplit[$k]='<h'.$typ.$align.$class.'>'.$tC.'</h'.$typ.'>';
1110 }
1111 break;
1112 }
1113 $blockSplit[$k+1]=ereg_replace('^[ ]*'.chr(10),'',$blockSplit[$k+1]); // Removing linebreak if typohead
1114 } else { // NON-block:
1115 $nextFTN = $this->getFirstTagName($blockSplit[$k+1]);
1116 $singleLineBreak = $blockSplit[$k]==chr(10);
1117 if (t3lib_div::inList('TABLE,BLOCKQUOTE,TYPOLIST,TYPOHEAD,'.$this->headListTags,$nextFTN)) { // Removing linebreak if typolist/typohead
1118 $blockSplit[$k]=ereg_replace(chr(10).'[ ]*$','',$blockSplit[$k]);
1119 }
1120 // If $blockSplit[$k] is blank then unset the line. UNLESS the line happend to be a single line break.
1121 if (!strcmp($blockSplit[$k],'') && !$singleLineBreak) {
1122 unset($blockSplit[$k]);
1123 } else {
1124 $blockSplit[$k]=$this->setDivTags($blockSplit[$k],($this->procOptions['useDIVasParagraphTagForRTE']?'DIV':'P'));
1125 }
1126 }
1127 }
1128 return implode(chr(10),$blockSplit);
1129 }
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140 /**
1141 * Tranform value for RTE based on specConf in the direction specified by $direction (rte/db)
1142 *
1143 * @param [type] $value: ...
1144 * @return [type] ...
1145 */
1146 function TS_tmplParts_rte($value) {
1147 $substMarkers=Array(
1148 '###POST_TIME###' => 'time',
1149 '###POST_AGE###' => 'age',
1150 '###POST_AUTHOR###' => 'name',
1151 '###POST_EMAIL###' => 'email',
1152 '###POST_WWW###' => 'url',
1153 '###POST_DATE###' => 'date',
1154 // '###POST_TITLE###' => 'Caeli ut dividant diem ac noctem!',
1155 // '###POST_CONTENT###' => 'Dixit autem Deus fiant luminaria in firmamento caeli ut dividant diem ac noctem et sint in signa<BR>et tempora et dies et annos ut luceant in firmamento caeli et inluminent terram et factum est ita fecitque Deus duo magna luminaria luminare maius ut praeesset diei et luminare minus ut praeesset nocti et stellas et posuit eas in firmamento caeli ut lucerent super terram.',
1156 );
1157
1158
1159 reset($substMarkers);
1160 while(list($key,$content)=each($substMarkers)) {
1161 $value=str_replace($key,
1162 '<img src="'.TYPO3_mainDir.'ext/rte/markers/'.$content.'.gif" align="absmiddle" alt="" />'
1163 ,$value);
1164 }
1165 return $value;
1166 }
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180 /**
1181 * Tranform value for RTE based on specConf in the direction specified by $direction (rte/db)
1182 *
1183 * @param [type] $value: ...
1184 * @param [type] $specConf: ...
1185 * @param [type] $direction: ...
1186 * @param [type] $thisConfig: ...
1187 * @return [type] ...
1188 */
1189 function RTE_transform($value,$specConf,$direction='rte',$thisConfig='') {
1190 $this->procOptions=$thisConfig['proc.'];
1191 $this->preserveTags = strtoupper(implode(',',t3lib_div::trimExplode(',',$this->procOptions['preserveTags'])));
1192
1193 // Get parameters for rte_transformation:
1194 $p = $this->rte_p = t3lib_BEfunc::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
1195
1196 if (strcmp($this->procOptions['overruleMode'],'')) {
1197 $modes=array_unique(t3lib_div::trimExplode(',',$this->procOptions['overruleMode']));
1198 } else {
1199 $modes=array_unique(t3lib_div::trimExplode('-',$p['mode']));
1200 }
1201
1202 $revmodes=array_flip($modes);
1203
1204 // Find special modes and extract them:
1205 if (isset($revmodes['ts'])) {
1206 $modes[$revmodes['ts']]='ts_transform,ts_preserve,ts_images,ts_links';
1207 }
1208 // Find special modes and extract them:
1209 if (isset($revmodes['ts_css'])) {
1210 $modes[$revmodes['ts_css']]='css_transform,ts_images,ts_links';
1211 }
1212 $modes = array_unique(t3lib_div::trimExplode(',',implode(',',$modes),1));
1213 if ($direction=='rte') {
1214 $modes=array_reverse($modes);
1215 }
1216
1217 $entry_HTMLparser = $this->procOptions['entryHTMLparser_'.$direction] ? $this->HTMLparserConfig($this->procOptions['entryHTMLparser_'.$direction.'.']) : '';
1218 $exit_HTMLparser = $this->procOptions['exitHTMLparser_'.$direction] ? $this->HTMLparserConfig($this->procOptions['exitHTMLparser_'.$direction.'.']) : '';
1219
1220 if (!$this->procOptions['disableUnifyLineBreaks']) {
1221 $value = str_replace(chr(13).chr(10),chr(10),$value);
1222 }
1223
1224 if (is_array($entry_HTMLparser)) {
1225 $value = $this->HTMLcleaner($value,$entry_HTMLparser[0],$entry_HTMLparser[1],$entry_HTMLparser[2]);
1226 }
1227 // Traverse modes:
1228 reset($modes);
1229 while(list(,$cmd)=each($modes)) {
1230 // ->DB
1231 if ($direction=='db') {
1232 switch($cmd) {
1233 case 'ts_transform':
1234 case 'css_transform':
1235 $value = str_replace(chr(13),'',$value); // Has a very disturbing effect, so just remove all '13' - depend on '10'
1236 $this->allowedClasses = t3lib_div::trimExplode(',',strtoupper($this->procOptions['allowedClasses']),1);
1237 $value=$this->TS_transform_db($value,$cmd=='css_transform');
1238 break;
1239 case 'ts_links':
1240 $value=$this->TS_links_db($value);
1241 break;
1242 case 'ts_reglinks':
1243 $value=$this->TS_reglinks($value,'db');
1244 break;
1245 case 'ts_preserve':
1246 $value=$this->TS_preserve_db($value);
1247 break;
1248 case 'ts_images':
1249 $value=$this->TS_images_db($value);
1250 break;
1251 case 'ts_strip':
1252 $value=$this->TS_strip_db($value);
1253 break;
1254 case 'dummy':
1255 break;
1256 }
1257 }
1258 // ->RTE
1259 if ($direction=='rte') {
1260 switch($cmd) {
1261 case 'ts_transform':
1262 case 'css_transform':
1263 $value = str_replace(chr(13),'',$value); // Has a very disturbing effect, so just remove all '13' - depend on '10'
1264 $value=$this->TS_transform_rte($value,$cmd=='css_transform');
1265 break;
1266 case 'ts_links':
1267 $value=$this->TS_links_rte($value);
1268 break;
1269 case 'ts_reglinks':
1270 $value=$this->TS_reglinks($value,'rte');
1271 break;
1272 case 'ts_preserve':
1273 $value=$this->TS_preserve_rte($value);
1274 break;
1275 case 'ts_images':
1276 $value=$this->TS_images_rte($value);
1277 break;
1278 case 'dummy':
1279 break;
1280 }
1281 }
1282 }
1283
1284 if (is_array($exit_HTMLparser)) {
1285 $value = $this->HTMLcleaner($value,$exit_HTMLparser[0],$exit_HTMLparser[1],$exit_HTMLparser[2]);
1286 }
1287
1288 if (!$this->procOptions['disableUnifyLineBreaks']) {
1289 $value = str_replace(chr(13).chr(10),chr(10),$value); // Make sure no \r\n sequences has entered in the meantime...
1290 $value = str_replace(chr(10),chr(13).chr(10),$value); // ... and then change all \n into \r\n
1291 }
1292
1293 return $value;
1294 }
1295
1296 /**
1297 * [Describe function...]
1298 *
1299 * @return [type] ...
1300 */
1301 function rteImageStorageDir() {
1302 return $this->rte_p['imgpath'] ? $this->rte_p['imgpath'] : $GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir'];
1303 }
1304 }
1305
1306
1307 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_parsehtml_proc.php']) {
1308 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_parsehtml_proc.php']);
1309 }
1310 ?>