Fixed SQL statement (missing quotes) reported by Martin Erichsen.
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_parsehtml_proc.php
index b30ca11..6722c8f 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *  
-*  (c) 1999-2003 Kasper Skaarhoj (kasper@typo3.com)
+*  (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -271,7 +271,7 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                if (is_array($entry_HTMLparser))        {
                        $value = $this->HTMLcleaner($value,$entry_HTMLparser[0],$entry_HTMLparser[1],$entry_HTMLparser[2],$entry_HTMLparser[3]);
                }
-               
+
                        // Traverse modes:
                foreach($modes as $cmd) {
                                // ->DB
@@ -385,9 +385,9 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                        // Init
                                $attribArray=$this->get_tag_attributes_classic($v,1);
                                $siteUrl = $this->siteUrl();
-                               $absRef = trim($attribArray['src']);
-                               
-                                       // External image from another URL?
+                               $absRef = trim($attribArray['src']);            // It's always a absolute URL coming from the RTE into the Database.
+
+                                       // External image from another URL? In that case, fetch image (unless disabled feature).
                                if (!t3lib_div::isFirstPartOfStr($absRef,$siteUrl) && !$this->procOptions['dontFetchExtPictures'])      {
                                        $externalFile = $this->getUrl($absRef); // Get it
                                        if ($externalFile)      {
@@ -405,20 +405,22 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                                        $absRef = $siteUrl.$this->rteImageStorageDir().'RTEmagicC_'.$filename.'.'.$pI['extension'];
                                                
                                                        $attribArray['src']=$absRef;
-                                                       if (!isset($attribArray['alt']))        $attribArray['alt']='';
                                                        $params = t3lib_div::implodeParams($attribArray,1);
                                                        $imgSplit[$k]='<img '.$params.' />';
                                                }
                                        }
                                }
-                                       // Check image as local file
+                                       // Check image as local file (siteURL equals the one of the image)
                                if (t3lib_div::isFirstPartOfStr($absRef,$siteUrl))      {
-                                       $path = substr($absRef,strlen($siteUrl));
-                                       $pathPre=$this->rteImageStorageDir().'RTEmagicC_';
+                                       $path = rawurldecode(substr($absRef,strlen($siteUrl))); // Rel-path, rawurldecoded for special characters.
+                                       $filepath = t3lib_div::getFileAbsFileName($path);               // Abs filepath, locked to relative path of this project.
+
+                                               // Check file existence (in relative dir to this installation!)
+                                       if ($filepath && @is_file($filepath))   {
                                        
-                                       if (t3lib_div::isFirstPartOfStr($path,$pathPre))        {
-                                               $filepath = PATH_site.$path;
-                                               if (@is_file($filepath))        {
+                                                       // If "magic image":
+                                               $pathPre=$this->rteImageStorageDir().'RTEmagicC_';
+                                               if (t3lib_div::isFirstPartOfStr($path,$pathPre))        {
                                                        // Find original file:
                                                        $pI=pathinfo(substr($path,strlen($pathPre)));
                                                        $filename = substr($pI['basename'],0,-strlen('.'.$pI['extension']));
@@ -445,23 +447,59 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                                                                $attribArray['width']=$imgI[0];
                                                                                $attribArray['height']=$imgI[1];
                                                                                if (!$attribArray['border'])    $attribArray['border']=0;
-                                                                               if (!isset($attribArray['alt']))        $attribArray['alt']='';
                                                                                $params = t3lib_div::implodeParams($attribArray,1);
                                                                                $imgSplit[$k]='<img '.$params.' />';
                                                                        }
                                                                }
                                                        }
+
+                                               } elseif ($this->procOptions['plainImageMode']) {       // If "plain image" has been configured:
+
+                                                               // Image dimensions as set in the image tag
+                                                       $curWH = $this->getWHFromAttribs($attribArray); 
+                                                       $attribArray['width'] = $curWH[0];
+                                                       $attribArray['height'] = $curWH[1];
+                                                       
+                                                               // Forcing values for style and border:
+                                                       unset($attribArray['style']);
+                                                       if (!$attribArray['border'])    $attribArray['border']=0;
+                                                       
+                                                               // Finding dimensions of image file:
+                                                       $fI = @getimagesize($filepath);
+
+                                                               // Perform corrections to aspect ratio based on configuration:
+                                                       switch((string)$this->procOptions['plainImageMode'])    {
+                                                               case 'lockDimensions':
+                                                                       $attribArray['width']=$fI[0];
+                                                                       $attribArray['height']=$fI[1];
+                                                               break;
+                                                               case 'lockRatioWhenSmaller':    // If the ratio has to be smaller, then first set the width...:
+                                                                       if ($attribArray['width']>$fI[0])       $attribArray['width'] = $fI[0];
+                                                               case 'lockRatio':
+                                                                       if ($fI[0]>0)   {
+                                                                               $attribArray['height']=round($attribArray['width']*($fI[1]/$fI[0]));
+                                                                       }
+                                                               break;
+                                                       }
+                                                       
+                                                               // Compile the image tag again:
+                                                       $params = t3lib_div::implodeParams($attribArray,1);
+                                                       $imgSplit[$k]='<img '.$params.' />';
                                                }
+                                       } else {        // Remove image if it was not found in a proper position on the server!
+                                               $imgSplit[$k]='';
                                        }
                                }
 
                                        // Convert abs to rel url
-                               $attribArray=$this->get_tag_attributes_classic($imgSplit[$k],1);
-                               $absRef = trim($attribArray['src']);
-                               if (t3lib_div::isFirstPartOfStr($absRef,$siteUrl))      {
-                                       $attribArray['src'] = $this->relBackPath.substr($absRef,strlen($siteUrl));
-                                       if (!isset($attribArray['alt']))        $attribArray['alt']='image';            // Must have value, otherwise the attribute is stripped by implodeParams()
-                                       $imgSplit[$k]='<img '.t3lib_div::implodeParams($attribArray,1).' />';
+                               if ($imgSplit[$k])      {
+                                       $attribArray=$this->get_tag_attributes_classic($imgSplit[$k],1);
+                                       $absRef = trim($attribArray['src']);
+                                       if (t3lib_div::isFirstPartOfStr($absRef,$siteUrl))      {
+                                               $attribArray['src'] = $this->relBackPath.substr($absRef,strlen($siteUrl));
+                                               if (!isset($attribArray['alt']))        $attribArray['alt']='';         // Must have alt-attribute for XHTML compliance.
+                                               $imgSplit[$k]='<img '.t3lib_div::implodeParams($attribArray,1,1).' />';
+                                       }
                                }
                        }
                }               
@@ -1054,7 +1092,7 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
        }
                 
        /**
-        * 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).
+        * 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).
         * This point is to resolve the HTML-code returned from RTE into ordinary lines so it's 'human-readable'
         * The function ->setDivTags does the opposite.
         * This function processes content to go into the database.
@@ -1110,7 +1148,7 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                                
                                                        // Get first tag, attributes etc:
                                                $fTag = $this->getFirstTag($divSplit[$k]);
-                                               $tagName=$this->getFirstTagName($divSplit[$k]);
+                                               $tagName=strtolower($this->getFirstTagName($divSplit[$k]));
                                                $attribs=$this->get_tag_attributes($fTag);
                                                
                                                        // Keep attributes (lowercase)