* Modified typo3/sysext/cms/tslib/class.tslib_content.php:
authorRobert Lemke <robert.lemke@typo3.org>
Mon, 5 Apr 2004 09:40:15 +0000 (09:40 +0000)
committerRobert Lemke <robert.lemke@typo3.org>
Mon, 5 Apr 2004 09:40:15 +0000 (09:40 +0000)
* fixed bug: When providing an imgList for the IMGTEXT TLO, no spaces were accepted in the comma separated list. Now using t3lib_div::trimExplode for splitting.
* fixed bug: The alt and title parameters have not been set correctly when using IMGTEXT with the imgList property. Now everything works as expected: You may specify alt/title texts for the whole IMGTEXT, or for each imgObj independently

* Added support for automatically caching image dimensions instead of executing IM identify.  Original extension provided by Michael Stucki.
* Affected files: t3lib/class.t3lib_stdgraphic.php, typo3/sysext/cms/ext_tables.sql
* Tested by Ingmar, Michael and Robert

git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@189 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_stdgraphic.php
typo3/sysext/cms/ext_tables.sql
typo3/sysext/cms/tslib/class.tslib_content.php

index 3384dc1..cfa057a 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2004-04-05  Robert Lemke  <rl@robertlemke.de>
+
+       * Modified typo3/sysext/cms/tslib/class.tslib_content.php:
+               * fixed bug: When providing an imgList for the IMGTEXT TLO, no spaces were accepted in the comma separated list. Now using t3lib_div::trimExplode for splitting.
+               * fixed bug: The alt and title parameters have not been set correctly when using IMGTEXT with the imgList property. Now everything works as expected: You may specify alt/title texts for the whole IMGTEXT, or for each imgObj independently
+
+       * Added support for automatically caching image dimensions instead of executing IM identify.  Original extension provided by Michael Stucki.
+               * Affected files: t3lib/class.t3lib_stdgraphic.php, typo3/sysext/cms/ext_tables.sql
+               * Tested by Ingmar, Michael and Robert
+
 2004-04-01  Kasper Skårhøj,,,  <kasper@typo3.com>
 
        * Fixed problem with domain look-up when an extra "/" was added to eg. "typo3.com//" -> showing "typo3.org" instead
index 66ced81..d32449c 100644 (file)
@@ -1825,20 +1825,93 @@ class t3lib_stdGraphic  {
 
        /**
         * Gets the input image dimensions.
-        *
+        * 
         * @param       string          The image filepath
         * @return      array           Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename.
         * @see imageMagickConvert(), tslib_cObj::getImgResource()
         */
-       function getImageDimensions($imagefile) {
-               ereg('([^\.]*)$',$imagefile,$reg);
-               if (@file_exists($imagefile) && t3lib_div::inList($this->imageFileExt,strtolower($reg[0])))     {
-                       if ($temp = @getImageSize($imagefile))  {
-                               return Array($temp[0], $temp[1], strtolower($reg[0]), $imagefile);
+       function getImageDimensions($imageFile) {
+               ereg('([^\.]*)$',$imageFile,$reg);
+               if (@file_exists($imageFile) && t3lib_div::inList($this->imageFileExt,strtolower($reg[0])))     {
+                       if ($returnArr = $this->getCachedImageDimensions($imageFile))   {
+                               return $returnArr;
                        } else {
-                               return $this->imageMagickIdentify($imagefile);
+                               if ($temp = @getImageSize($imageFile))  {
+                                       $returnArr = Array($temp[0], $temp[1], strtolower($reg[0]), $imageFile);
+                               } else {
+                                       $returnArr = $this->imageMagickIdentify($imageFile);
+                               }
+                               if($returnArr) {
+                                       $this->cacheImageDimensions($returnArr);
+                                       return $returnArr;
+                               }
+                       }
+               }
+               return false;
+       }
+
+       /**
+        * Cache the result of the getImageDimensions function into the database. Does not check if the
+        * file exists!
+        * 
+        * @param       array           $identifyResult: Result of the getImageDimensions function
+        * @return      boolean         True if operation was successful
+        * @author      Michael Stucki <mundaun@gmx.ch> / Robert Lemke <rl@robertlemke.de>
+        */
+       function cacheImageDimensions($identifyResult)  {
+               global $TYPO3_DB;
+                       // Create a md5 hash of the filename
+               if(function_exists('md5_file')) {
+                       $md5Hash = md5_file($identifyResult[3]);
+               } else {
+                       $md5Hash = md5 (implode('', file($fileName)));
+               }               
+               if($md5Hash) {
+                       $fieldArr = array (
+                               'md5hash' => $md5Hash,
+                               'md5filename' => md5($identifyResult[3]),
+                               'tstamp' => time(),
+                               'filename' => $identifyResult[3],
+                               'imagewidth' => $identifyResult[0],
+                               'imageheight' => $identifyResult[1],
+                       );
+                       $TYPO3_DB->exec_INSERTquery('cache_imagesizes', $fieldArr);
+                       if (!$err = $TYPO3_DB->sql_error())     {
+                               return true;
+                       }
+               }
+               return false;
+       }
+
+       /**
+        * Fetch the cached imageDimensions from the MySQL database. Does not check if the image file exists!
+        * 
+        * @param       string          The image filepath
+        * @return      array           Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename.
+        * @author      Michael Stucki <mundaun@gmx.ch> / Robert Lemke <rl@robertlemke.de>
+        */
+       function getCachedImageDimensions($imageFile)   {
+               global $TYPO3_DB;
+                       // Create a md5 hash of the filename
+               if(function_exists('md5_file')) {
+                       $md5Hash = md5_file($imageFile);
+               } else {
+                       $md5Hash = md5(implode('', file($imag)));
+               }
+               
+               ereg('([^\.]*)$',$imageFile,$reg);
+               $res = $TYPO3_DB->exec_SELECTquery ('md5hash, imagewidth, imageheight', 'cache_imagesizes', 'md5filename="'.md5($imageFile).'"');
+               if ($res) {
+                       if ($row = $TYPO3_DB->sql_fetch_assoc($res))    {
+                               if ($row['md5hash']!=$md5Hash) {
+                                               // file has changed, delete the row
+                                       $TYPO3_DB->exec_DELETEquery ('cache_imagesizes', 'md5hash="'.$TYPO3_DB->quoteStr($row['md5hash']).'"');
+                               } else {
+                                       return (array($row['imagewidth'], $row['imageheight'], strtolower($reg[0]), $imageFile));
+                               }
                        }
                }
+               return false;
        }
 
        /**
index 38cfb01..e35eeee 100755 (executable)
@@ -59,6 +59,20 @@ CREATE TABLE cache_md5params (
 
 
 #
+# Table structure for table 'cache_imagesizes'
+#
+CREATE TABLE cache_imagesizes (
+  md5hash varchar(32) DEFAULT '' NOT NULL,
+  md5filename varchar(32) DEFAULT '' NOT NULL,
+  tstamp int(11) DEFAULT '0' NOT NULL,
+  filename tinytext NOT NULL,
+  imagewidth mediumint(11) unsigned DEFAULT '0' NOT NULL,
+  imageheight mediumint(11) unsigned DEFAULT '0' NOT NULL,
+  PRIMARY KEY (md5filename)
+);
+
+
+#
 # Table structure for table 'fe_groups'
 #
 CREATE TABLE fe_groups (
index 2f94329..77d49a5 100755 (executable)
@@ -724,7 +724,7 @@ class tslib_cObj {
                }
                $imgList=trim($this->stdWrap($conf['imgList'],$conf['imgList.']));      // gets images
                if ($imgList)   {
-                       $imgs = explode(',',$imgList);
+                       $imgs = t3lib_div::trimExplode(',',$imgList);
                        $imgStart = intval($this->stdWrap($conf['imgStart'],$conf['imgStart.']));
        
                        $imgCount= count($imgs)-$imgStart;
@@ -839,8 +839,6 @@ class tslib_cObj {
                        $splitArr['imgObjNum']=$conf['imgObjNum'];
                        $splitArr = $GLOBALS['TSFE']->tmpl->splitConfArray($splitArr,$imgCount);
 
-                       $altP = $this->getAltParam($conf);
-                       
                                // EqualHeight
                        $equalHeight = intval($this->stdWrap($conf['equalH'],$conf['equalH.']));
                        if ($equalHeight)       {       // Initiate gifbuilder object in order to get dimensions AND calculate the imageWidth's
@@ -905,7 +903,6 @@ class tslib_cObj {
                                }
                                
                                if ($imgConf || $imgConf['file']) {
-                                       $imgConf['params'].=$altP;
                                        if ($this->image_effects[$image_effects])       {
                                                $imgConf['file.']['params'].= ' '.$this->image_effects[$image_effects];
                                        }
@@ -927,9 +924,11 @@ class tslib_cObj {
                                                        unset($imgConf['file.']['ext.']);
                                                }
                                        }
+                                       if (!isset ($imgConf['altText'])) $imgConf['altText'] = $conf['altText'];
+                                       if (!isset ($imgConf['titleText'])) $imgConf['titleText'] = $conf['titleText'];
                                        $imgsTag[$imgKey] = $this->IMAGE($imgConf);
                                } else {
-                                       $imgsTag[$imgKey] = $this->IMAGE(Array('params'=>$altP, 'file'=>$totalImagePath));      // currentValKey !!!
+                                       $imgsTag[$imgKey] = $this->IMAGE(Array('altText'=>$conf['altText'], 'titleText'=>$conf['titleText'], 'file'=>$totalImagePath));         // currentValKey !!!
                                }
                                        // Store the original filepath
                                $origImages[$imgKey]=$GLOBALS['TSFE']->lastImageInfo;
@@ -2498,7 +2497,7 @@ class tslib_cObj {
         * @see IMGTEXT(), cImage()
         */
        function getAltParam($conf)     {
-               $altText = $this->stdWrap($conf['altText'],$conf['altText.']);
+               $altText = $this->stdWrap($conf['altText'], $conf['altText.']);
                $altParam = ' alt="'.htmlspecialchars(strip_tags($altText)).'"';
 
                $titleText = $this->stdWrap($conf['titleText'],$conf['titleText.']);