[FEATURE] stdWrap for string-padding (like PHP-function str_pad)
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / ContentObjectRenderer.php
index 17b5ea3..772c99d 100644 (file)
@@ -92,6 +92,7 @@ class ContentObjectRenderer {
                'listNum.' => 'array',
                'trim' => 'boolean',
                'trim.' => 'array',
+               'strPad.' => 'array',
                'stdWrap' => 'stdWrap',
                'stdWrap.' => 'array',
                'stdWrapProcess' => 'hook',
@@ -2313,6 +2314,38 @@ class ContentObjectRenderer {
                return $content;
        }
 
+       /**
+        * strPad
+        * Will return a string padded left/right/on both sides, based on configuration given as stdWrap properties
+        *
+        * @param string $content Input value undergoing processing in this function.
+        * @param array $conf stdWrap properties for strPad.
+        * @return string The processed input value
+        */
+       public function stdWrap_strPad($content = '', $conf = array()) {
+               // Must specify a length in conf for this to make sense
+               $length = 0;
+               // Padding with space is PHP-default
+               $padWith = ' ';
+               // Padding on the right side is PHP-default
+               $padType = STR_PAD_RIGHT;
+               if (!empty($conf['strPad.']['length'])) {
+                       $length = intval($conf['strPad.']['length']);
+               }
+               if (!empty($conf['strPad.']['padWith'])) {
+                       $padWith = $conf['strPad.']['padWith'];
+               }
+               if (!empty($conf['strPad.']['type'])) {
+                       if (strtolower($conf['strPad.']['type']) === 'left') {
+                               $padType = STR_PAD_LEFT;
+                       } elseif (strtolower($conf['strPad.']['type']) === 'both') {
+                               $padType = STR_PAD_BOTH;
+                       }
+               }
+               $content = str_pad($content, $length, $padWith, $padType);
+               return $content;
+       }
+
        /**
         * stdWrap
         * A recursive call of the stdWrap function set