Added feature #10725: Integrate possibility to determine maximum of multiple values...
authorOliver Hader <oliver.hader@typo3.org>
Thu, 16 Apr 2009 21:23:22 +0000 (21:23 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Thu, 16 Apr 2009 21:23:22 +0000 (21:23 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@5324 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/cms/tslib/class.tslib_gifbuilder.php

index 7fa9294..8906c6d 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-04-16  Oliver Hader  <oliver@typo3.org>
+
+       * Added feature #10725: Integrate possibility to determine maximum of multiple values in GIFBUILDER
+
 2009-04-16  Steffen Kamper  <info@sk-typo3.de>
 
        * Fixed bug #10735: Wrong returnUrl with clipboard actions
index 6f144ce..fb58cb0 100644 (file)
@@ -569,7 +569,7 @@ class tslib_gifBuilder extends t3lib_stdGraphic {
         */
        function calcOffset($string)    {
                $value = array();
-               $numbers = t3lib_div::trimExplode(',', $string);
+               $numbers = t3lib_div::trimExplode(',', $this->calculateFunctions($string));
 
                foreach ($numbers as $key => $val) {
                        if ((string)$val == (string)intval($val)) {
@@ -703,6 +703,41 @@ class tslib_gifBuilder extends t3lib_stdGraphic {
 
                return $calculatedValue;
        }
+
+       /**
+        * Calculates special functions:
+        * + max([10.h], [20.h])        -> gets the maximum of the given values
+        *
+        * @param       string          $string: The raw string with functions to be calculated
+        * @return      string          The calculated values
+        */
+       protected function calculateFunctions($string) {
+               if (preg_match_all('#max\(([^)]+)\)#', $string, $matches)) {
+                       foreach ($matches[1] as $index => $maxExpression) {
+                               $string = str_replace(
+                                       $matches[0][$index],
+                                       $this->calculateMaximum(
+                                               $maxExpression
+                                       ),
+                                       $string
+                               );
+                       }
+               }
+
+               return $string;
+       }
+
+       /**
+        * Calculates the maximum of a set of values defined like "[10.h],[20.h],1000"
+        *
+        * @param       string          $string: The string to be used to calculate the maximum (e.g. "[10.h],[20.h],1000")
+        * @return      integer         The maxium value of the given comma separated and calculated values
+        */
+       protected function calculateMaximum($string) {
+               $parts = t3lib_div::trimExplode(',', $this->calcOffset($string), true);
+               $maximum = (count($parts) ? max($parts) : 0);
+               return $maximum;
+       }
 }