[TASK] Fix deprecation comment for t3lib_div::int_from_ver()
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_div.php
index 1df596f..fc48aef 100644 (file)
@@ -383,39 +383,14 @@ final class t3lib_div {
         * Breaks up a single line of text for emails
         *
         * @param string $str The string to break up
-        * @param string $implChar The string to implode the broken lines with (default/typically \n)
-        * @param integer $charWidth The line length
-        * @return string
+        * @param string $newlineChar The string to implode the broken lines with (default/typically \n)
+        * @param integer $lineWidth The line width
+        * @return string reformatted text
+        * @deprecated since TYPO3 4.6, will be removed in TYPO3 4.8 - Use t3lib_utility_Mail::breakLinesForPlainEmail()
         */
-       public static function breakLinesForEmail($str, $implChar = LF, $charWidth = 76) {
-               $lines = array();
-               $l = $charWidth;
-               $p = 0;
-               while (strlen($str) > $p) {
-                       $substr = substr($str, $p, $l);
-                       if (strlen($substr) == $l) {
-                               $count = count(explode(' ', trim(strrev($substr))));
-                               if ($count > 1) { // OK...
-                                       $parts = explode(' ', strrev($substr), 2);
-                                       $theLine = strrev($parts[1]);
-                               } else {
-                                       $afterParts = explode(' ', substr($str, $l + $p), 2);
-                                       $theLine = $substr . $afterParts[0];
-                               }
-                               if (!strlen($theLine)) {
-                                       break;
-                               } // Error, because this would keep us in an endless loop.
-                       } else {
-                               $theLine = $substr;
-                       }
-
-                       $lines[] = trim($theLine);
-                       $p += strlen($theLine);
-                       if (!trim(substr($str, $p, $l))) {
-                               break;
-                       } // added...
-               }
-               return implode($implChar, $lines);
+       public static function breakLinesForEmail($str, $newlineChar = LF, $lineWidth = 76) {
+               self::logDeprecatedFunction();
+               return t3lib_utility_Mail::breakLinesForPlainEmail($str, $newlineChar, $lineWidth);
        }
 
        /**
@@ -496,29 +471,38 @@ final class t3lib_div {
 
                $values = self::trimExplode(',', $list, 1);
                foreach ($values as $test) {
-                       list($test, $mask) = explode('/', $test);
+                       $testList = explode('/', $test);
+                       if (count($testList) == 2) {
+                               list($test, $mask) = $testList;
+                       } else {
+                               $mask = FALSE;
+                       }
+
                        if (self::validIPv6($test)) {
                                $test = self::normalizeIPv6($test);
-                               if (intval($mask)) {
-                                       switch ($mask) { // test on /48 /64
-                                               case '48':
-                                                       $testBin = substr(self::IPv6Hex2Bin($test), 0, 48);
-                                                       $baseIPBin = substr(self::IPv6Hex2Bin($baseIP), 0, 48);
-                                                       $success = strcmp($testBin, $baseIPBin) == 0 ? TRUE : FALSE;
-                                                       break;
-                                               case '64':
-                                                       $testBin = substr(self::IPv6Hex2Bin($test), 0, 64);
-                                                       $baseIPBin = substr(self::IPv6Hex2Bin($baseIP), 0, 64);
-                                                       $success = strcmp($testBin, $baseIPBin) == 0 ? TRUE : FALSE;
-                                                       break;
-                                               default:
-                                                       $success = FALSE;
-                                       }
+                               $maskInt = intval($mask) ? intval($mask) : 128;
+                               if ($mask === '0') { // special case; /0 is an allowed mask - equals a wildcard
+                                       $success = TRUE;
+                               } elseif ($maskInt == 128) {
+                                       $success = ($test === $baseIP);
                                } else {
-                                       if (self::validIPv6($test)) { // test on full ip address 128 bits
-                                               $testBin = self::IPv6Hex2Bin($test);
-                                               $baseIPBin = self::IPv6Hex2Bin($baseIP);
-                                               $success = strcmp($testBin, $baseIPBin) == 0 ? TRUE : FALSE;
+                                       $testBin = self::IPv6Hex2Bin($test);
+                                       $baseIPBin = self::IPv6Hex2Bin($baseIP);
+                                       $success = TRUE;
+
+                                       // modulo is 0 if this is a 8-bit-boundary
+                                       $maskIntModulo = $maskInt % 8;
+                                       $numFullCharactersUntilBoundary = intval($maskInt / 8);
+
+                                       if (substr($testBin, 0, $numFullCharactersUntilBoundary) !== substr($baseIPBin, 0, $numFullCharactersUntilBoundary)) {
+                                               $success = FALSE;
+                                       } elseif ($maskIntModulo > 0) {
+                                               // if not an 8-bit-boundary, check bits of last character
+                                               $testLastBits = str_pad(decbin(ord(substr($testBin, $numFullCharactersUntilBoundary, 1))), 8, '0', STR_PAD_LEFT);
+                                               $baseIPLastBits = str_pad(decbin(ord(substr($baseIPBin, $numFullCharactersUntilBoundary, 1))), 8, '0', STR_PAD_LEFT);
+                                               if (strncmp($testLastBits, $baseIPLastBits, $maskIntModulo) != 0) {
+                                                       $success = FALSE;
+                                               }
                                        }
                                }
                        }
@@ -530,17 +514,19 @@ final class t3lib_div {
        }
 
        /**
-        * Convert an IPv6 address to its binary representation
+        * Transform a regular IPv6 address from hex-representation into binary
         *
-        * @param string $hex IPv6 address in hexadecimal form
-        * @return integer
+        * @param string $hex IPv6 address in hex-presentation
+        * @return string Binary representation (16 characters, 128 characters)
+        * @see normalizeIPv6()
         */
        public static function IPv6Hex2Bin($hex) {
-               $bin = '';
-               $hex = str_replace(':', '', $hex); // Replace colon to nothing
-               for ($i = 0; $i < strlen($hex); $i = $i + 2) {
-                       $bin .= chr(hexdec(substr($hex, $i, 2)));
+               // normalized representation has 39 characters (0000:0000:0000:0000:0000:0000:0000:0000)
+               if (strlen($hex) < 39) {
+                       $hex = self::normalizeIPv6($hex);
                }
+               $hex = str_replace(':', '', $hex); // Replace colon to nothing
+               $bin = pack("H*" , $hex);
                return $bin;
        }
 
@@ -771,7 +757,7 @@ final class t3lib_div {
         *
         * @param string $verNumberStr Version number on format x.x.x
         * @return integer Integer version of version number (where each part can count to 999)
-        * @deprecated since TYPO3 4.6, will be removed in TYPO3 4.8 - Use t3lib_utility_Math::convertVersionNumberToInteger() instead
+        * @deprecated since TYPO3 4.6, will be removed in TYPO3 4.8 - Use t3lib_utility_VersionNumber::convertVersionNumberToInteger() instead
         */
        public static function int_from_ver($verNumberStr) {
                self::logDeprecatedFunction();
@@ -4693,8 +4679,8 @@ final class t3lib_div {
         * @return object the created instance
         */
        public static function makeInstance($className) {
-               if ($className === '') {
-                       throw new InvalidArgumentException('$classname must not be empty.', 1288965219);
+               if (!is_string($className) || empty($className)) {
+                       throw new InvalidArgumentException('$className must be a non empty string.', 1288965219);
                }
 
                        // Determine final class name which must be instantiated, this takes XCLASS handling
@@ -5581,4 +5567,4 @@ final class t3lib_div {
        }
 }
 
-?>
+?>
\ No newline at end of file