keepItemsInArray() was not declared static
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_parsehtml_proc.php
index c3663af..0d8d5a0 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -103,13 +103,14 @@ require_once (PATH_t3lib.'class.t3lib_parsehtml.php');
 class t3lib_parsehtml_proc extends t3lib_parsehtml {
 
                // Static:
-       var $headListTags = 'PRE,UL,OL,H1,H2,H3,H4,H5,H6,HR,ADDRESS,DL';        // List of tags for these elements
+       var $blockElementList = 'PRE,UL,OL,H1,H2,H3,H4,H5,H6,HR,ADDRESS,DL,DD'; // List of tags for these elements
 
                // Internal, static:
        var $recPid = 0;                                // Set this to the pid of the record manipulated by the class.
        var $elRef = '';                                // Element reference [table]:[field], eg. "tt_content:bodytext"
        var $relPath='';                                // Relative path
        var $relBackPath='';                    // Relative back-path
+       public $tsConfig = array();             // Current Page TSConfig
        var $procOptions = '';                  // Set to the TSconfig options coming from Page TSconfig
 
                // Internal, dynamic
@@ -232,9 +233,15 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
        function RTE_transform($value,$specConf,$direction='rte',$thisConfig=array())   {
 
                        // Init:
+               $this->tsConfig = $thisConfig;
                $this->procOptions = $thisConfig['proc.'];
                $this->preserveTags = strtoupper(implode(',',t3lib_div::trimExplode(',',$this->procOptions['preserveTags'])));
 
+                       // dynamic configuration of blockElementList
+               if ($this->procOptions['blockElementList']) {
+                       $this->blockElementList = $this->procOptions['blockElementList'];
+               }
+
                        // Get parameters for rte_transformation:
                $p = $this->rte_p = t3lib_BEfunc::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
 
@@ -474,10 +481,10 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                                                        if ($imgI[3])   {
                                                                                $fI=pathinfo($imgI[3]);
                                                                                @copy($imgI[3],$filepath);      // Override the child file
-                                                                               unset($attribArray['style']);
+                                                                                       // Removing width and heigth form style attribute
+                                                                               $attribArray['style'] = preg_replace('/((?:^|)\s*(?:width|height)\s*:[^;]*(?:$|;))/si', '', $attribArray['style']);
                                                                                $attribArray['width']=$imgI[0];
                                                                                $attribArray['height']=$imgI[1];
-                                                                               if (!$attribArray['border'])    $attribArray['border']=0;
                                                                                $params = t3lib_div::implodeAttributes($attribArray,1);
                                                                                $imgSplit[$k]='<img '.$params.' />';
                                                                        }
@@ -486,14 +493,13 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
 
                                                } elseif ($this->procOptions['plainImageMode']) {       // If "plain image" has been configured:
 
-                                                               // Image dimensions as set in the image tag
+                                                               // Image dimensions as set in the image tag, if any
                                                        $curWH = $this->getWHFromAttribs($attribArray);
-                                                       $attribArray['width'] = $curWH[0];
-                                                       $attribArray['height'] = $curWH[1];
+                                                       if ($curWH[0]) $attribArray['width'] = $curWH[0];
+                                                       if ($curWH[1]) $attribArray['height'] = $curWH[1];
 
-                                                               // Forcing values for style and border:
-                                                       unset($attribArray['style']);
-                                                       if (!$attribArray['border'])    $attribArray['border'] = 0;
+                                                               // Removing width and heigth form style attribute
+                                                       $attribArray['style'] = preg_replace('/((?:^|)\s*(?:width|height)\s*:[^;]*(?:$|;))/si', '', $attribArray['style']);
 
                                                                // Finding dimensions of image file:
                                                        $fI = @getimagesize($filepath);
@@ -644,7 +650,7 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                }
                                if (!count($attribArray_copy))  {       // Only if href, target and class are the only attributes, we can alter the link!
                                                // Creating the TYPO3 pseudo-tag "<LINK>" for the link (includes href/url, target and class attributes):
-                                       $bTag='<link '.$info['url'].($attribArray['target']?' '.$attribArray['target']:(($attribArray['class'] || $attribArray['title'])?' -':'')).($attribArray['class']?' '.$attribArray['class']:($attribArray['title']?' -':'')).($attribArray['title']?' "'.$attribArray['title'].'"':'').'>';
+                                       $bTag='<link '.$info['url'].($info['query']?',0,'.$info['query']:'').($attribArray['target']?' '.$attribArray['target']:(($attribArray['class'] || $attribArray['title'])?' -':'')).($attribArray['class']?' '.$attribArray['class']:($attribArray['title']?' -':'')).($attribArray['title']?' "'.$attribArray['title'].'"':'').'>';
                                        $eTag='</link>';
                                        $blockSplit[$k] = $bTag.$this->TS_links_db($this->removeFirstAndLastTag($blockSplit[$k])).$eTag;
                                } else {        // ... otherwise store the link as a-tag.
@@ -726,7 +732,11 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                                }
                                                $page = t3lib_BEfunc::getRecord('pages', $idPart);
                                                if (is_array($page))    {       // Page must exist...
-                                                       $href = $siteUrl.'?id='.$link_param;
+                                                       $pairParts = t3lib_div::trimExplode(',',$link_param);
+                                                       $href = $siteUrl.'?id='.$pairParts[0].($pairParts[2]?$pairParts[2]:'');
+                                               } else if(strtolower(substr($link_param, 0, 7)) == 'record:') {
+                                                               // linkHandler - allowing links to start with "record:"
+                                                       $href = $link_param;
                                                } else {
                                                        #$href = '';
                                                        $href = $siteUrl.'?id='.$link_param;
@@ -809,7 +819,7 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                if ($this->TS_transform_db_safecounter<0)       return $value;
 
                        // Split the content from RTE by the occurence of these blocks:
-               $blockSplit = $this->splitIntoBlock('TABLE,BLOCKQUOTE,'.$this->headListTags,$value);
+               $blockSplit = $this->splitIntoBlock('TABLE,BLOCKQUOTE,'.($this->procOptions['preserveDIVSections']?'DIV,':'').$this->blockElementList,$value);
 
                $cc=0;
                $aC = count($blockSplit);
@@ -834,7 +844,9 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                        // Process based on the tag:
                                switch($tagName)        {
                                        case 'blockquote':      // Keep blockquotes, but clean the inside recursively in the same manner as the main code
-                                               $blockSplit[$k]='<'.$tagName.'>'.$this->TS_transform_db($this->removeFirstAndLastTag($blockSplit[$k]),$css).'</'.$tagName.'>'.$lastBR;
+                                       case 'dd' :             // Do the same on dd elements
+                                       case 'div':             // Do the same on div sections, if they were splitted
+                                               $blockSplit[$k]=$tag.$this->TS_transform_db($this->removeFirstAndLastTag($blockSplit[$k]),$css).'</'.$tagName.'>'.$lastBR;
                                        break;
                                        case 'ol':
                                        case 'ul':      // Transform lists into <typolist>-tags:
@@ -948,7 +960,7 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
        function TS_transform_rte($value,$css=0)        {
 
                        // Split the content from Database by the occurence of these blocks:
-               $blockSplit = $this->splitIntoBlock('TABLE,BLOCKQUOTE,TYPOLIST,TYPOHEAD,'.$this->headListTags,$value);
+               $blockSplit = $this->splitIntoBlock('TABLE,BLOCKQUOTE,TYPOLIST,TYPOHEAD,'.($this->procOptions['preserveDIVSections']?'DIV,':'').$this->blockElementList,$value);
 
                        // Traverse the blocks
                foreach($blockSplit as $k => $v)        {
@@ -961,10 +973,12 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
 
                                        // Based on tagname, we do transformations:
                                switch($tagName)        {
-                                       case 'blockquote':      // Keep blockquotes:
+                                       case 'blockquote':      // Keep blockquotes
+                                       case 'dd':              // Keep definitions
+                                       case 'div':             // Keep div sections, if they were splitted
                                                $blockSplit[$k] = $tag.
-                                                                                       $this->TS_transform_rte($this->removeFirstAndLastTag($blockSplit[$k]),$css).
-                                                                                       '</'.$tagName.'>';
+                                                                       $this->TS_transform_rte($this->removeFirstAndLastTag($blockSplit[$k]),$css).
+                                                                       '</'.$tagName.'>';
                                        break;
                                        case 'typolist':        // Transform typolist blocks into OL/UL lists. Type 1 is expected to be numerical block
                                                if (!isset($this->procOptions['typolist']) || $this->procOptions['typolist'])   {
@@ -995,7 +1009,7 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                        } else {        // NON-block:
                                $nextFTN = $this->getFirstTagName($blockSplit[$k+1]);
                                $singleLineBreak = $blockSplit[$k]==chr(10);
-                               if (t3lib_div::inList('TABLE,BLOCKQUOTE,TYPOLIST,TYPOHEAD,'.$this->headListTags,$nextFTN))      {       // Removing linebreak if typolist/typohead
+                               if (t3lib_div::inList('TABLE,BLOCKQUOTE,TYPOLIST,TYPOHEAD,'.($this->procOptions['preserveDIVSections']?'DIV,':'').$this->blockElementList,$nextFTN))    {       // Removing linebreak if typolist/typohead
                                        $blockSplit[$k] = ereg_replace(chr(10).'[ ]*$','',$blockSplit[$k]);
                                }
                                        // If $blockSplit[$k] is blank then unset the line. UNLESS the line happend to be a single line break.
@@ -1111,9 +1125,12 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
 
                                        // GOING from database to Rich Text Editor:
                                case 'rte':
-                                               // Transform bold/italics tags to strong/em
-                                       if (isset($keepTags['b']))      {$keepTags['b']=array('remap'=>'STRONG');}
-                                       if (isset($keepTags['i']))      {$keepTags['i']=array('remap'=>'EM');}
+
+                                       if (!isset($this->procOptions['transformBoldAndItalicTags']) || $this->procOptions['transformBoldAndItalicTags']) {
+                                                       // Transform bold/italics tags to strong/em
+                                               if (isset($keepTags['b']))      {$keepTags['b']=array('remap'=>'STRONG');}
+                                               if (isset($keepTags['i']))      {$keepTags['i']=array('remap'=>'EM');}
+                                       }
 
                                                // 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.
                                        list($keepTags) = $this->HTMLparserConfig($this->procOptions['HTMLparser_rte.'],$keepTags);
@@ -1121,20 +1138,23 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
 
                                        // GOING from RTE to database:
                                case 'db':
-                                               // Transform strong/em back to bold/italics:
-                                       if (isset($keepTags['strong'])) { $keepTags['strong']=array('remap'=>'b'); }
-                                       if (isset($keepTags['em']))             { $keepTags['em']=array('remap'=>'i'); }
+
+                                       if (!isset($this->procOptions['transformBoldAndItalicTags']) || $this->procOptions['transformBoldAndItalicTags']) {
+                                                       // Transform strong/em back to bold/italics:
+                                               if (isset($keepTags['strong'])) { $keepTags['strong']=array('remap'=>'b'); }
+                                               if (isset($keepTags['em']))     { $keepTags['em']=array('remap'=>'i'); }
+                                       }
 
                                                // Setting up span tags if they are allowed:
                                        if (isset($keepTags['span']))           {
                                                $classes=array_merge(array(''),$this->allowedClasses);
                                                $keepTags['span']=array(
-                                                       'allowedAttribs' => 'class,style,xml:lang',
+                                                       'allowedAttribs' => 'id,class,style,title,lang,xml:lang,dir',
                                                        'fixAttrib' => Array(
                                                                'class' => Array (
                                                                        'list' => $classes,
                                                                        'removeIfFalse' => 1
-                                                               )
+                                                               ),
                                                        ),
                                                        'rmTagIfNoAttrib' => 1
                                                );
@@ -1279,8 +1299,10 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                        // Add the processed line(s)
                                $divSplit[$k] = implode(chr(10),$subLines);
 
-                                       // If it turns out the line is just blank (containing a &nbsp; possibly) then just make it pure blank:
-                               if (trim(strip_tags($divSplit[$k]))=='&nbsp;' && !preg_match('/\<(img)(\s[^>]*)?\/?>/si', $divSplit[$k])) {
+                                       // If it turns out the line is just blank (containing a &nbsp; possibly) then just make it pure blank.
+                                       // But, prevent filtering of lines that are blank in sense above, but whose tags contain attributes.
+                                       // Those attributes should have been filtered before; if they are still there they must be considered as possible content.
+                               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]))) {
                                        $divSplit[$k]='';
                                }
                        } else {        // outside div:
@@ -1497,7 +1519,7 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                } else {
                        $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...
                        for($a=0;$a<strlen($url);$a++)  {
-                               if ($url[$a]!=$curURL[$a])      {
+                               if ($url{$a}!=$curURL{$a})      {
                                        break;
                                }
                        }
@@ -1521,12 +1543,14 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                        $info['type']='anchor';
                                } elseif (!trim($uP['path']) || !strcmp($uP['path'],'index.php'))       {
                                        $pp = explode('id=',$uP['query']);
-                                       $id = trim($pp[1]);
+                                       $parameters = explode('&', $pp[1]);
+                                       $id = array_shift($parameters);
                                        if ($id)        {
                                                $info['pageid']=$id;
                                                $info['cElement']=$uP['fragment'];
                                                $info['url']=$id.($info['cElement']?'#'.$info['cElement']:'');
                                                $info['type']='page';
+                                               $info['query'] = $parameters[0]?'&'.implode('&', $parameters):'';
                                        }
                                } else {
                                        $info['url']=$info['relUrl'];
@@ -1578,4 +1602,5 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_parsehtml_proc.php'])   {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_parsehtml_proc.php']);
 }
-?>
+
+?>
\ No newline at end of file