[FEATURE] Add random functionality to listNum
authorMario Rimann <typo3-coding@rimann.org>
Mon, 6 Jun 2011 11:20:48 +0000 (13:20 +0200)
committerSteffen Gebert <steffen.gebert@typo3.org>
Fri, 24 Jun 2011 19:19:44 +0000 (21:19 +0200)
Add the ability to get a random item by setting listNum to "rand".

Change-Id: I55efef8ed714eaa1545f9f179e18260661407de7
Resolves: #16180
Reviewed-on: http://review.typo3.org/2538
Reviewed-by: Georg Ringer
Reviewed-by: Mario Rimann
Reviewed-by: Stefan Neufeind
Tested-by: Georg Ringer
Reviewed-by: Steffen Gebert
Tested-by: Steffen Gebert
typo3/sysext/cms/tslib/class.tslib_content.php

index 0c015e2..de4d944 100644 (file)
@@ -3289,6 +3289,10 @@ class tslib_cObj {
                }
                $temp = explode($char, $content);
                $last = '' . (count($temp) - 1);
+                       // take a random item if requested
+               if ($listNum === 'rand') {
+                       $listNum = rand(0, count($temp) - 1);
+               }
                $index = $this->calc(str_ireplace('last', $last, $listNum));
                return $temp[$index];
        }