]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/ID3/getid3.lib.php
WordPress 4.1.4-scripts
[autoinstalls/wordpress.git] / wp-includes / ID3 / getid3.lib.php
index a7282c77c0652634ca52c123b14a054e018a9cab..0c92e060c3559e760a7884651a2ef3e33168c0e2 100644 (file)
@@ -3,6 +3,7 @@
 /// getID3() by James Heinrich <info@getid3.org>               //
 //  available at http://getid3.sourceforge.net                 //
 //            or http://www.getid3.org                         //
+//          also https://github.com/JamesHeinrich/getID3       //
 /////////////////////////////////////////////////////////////////
 //                                                             //
 // getid3.lib.php - part of getID3()                           //
@@ -282,7 +283,6 @@ class getid3_lib
                                }
                        } else {
                                throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits ('.strlen($byteword).') in self::BigEndian2Int()');
-                               break;
                        }
                }
                return self::CastAsInt($intvalue);
@@ -635,7 +635,7 @@ class getid3_lib
                }
                if (is_readable($filename_source) && is_file($filename_source) && ($fp_src = fopen($filename_source, 'rb'))) {
                        if (($fp_dest = fopen($filename_dest, 'wb'))) {
-                               if (fseek($fp_src, $offset, SEEK_SET) == 0) {
+                               if (fseek($fp_src, $offset) == 0) {
                                        $byteslefttowrite = $length;
                                        while (($byteslefttowrite > 0) && ($buffer = fread($fp_src, min($byteslefttowrite, getID3::FREAD_BUFFER_SIZE)))) {
                                                $byteswritten = fwrite($fp_dest, $buffer, $byteslefttowrite);
@@ -986,6 +986,19 @@ class getid3_lib
                throw new Exception('PHP does not have iconv() support - cannot convert from '.$in_charset.' to '.$out_charset);
        }
 
+       public static function recursiveMultiByteCharString2HTML($data, $charset='ISO-8859-1') {
+               if (is_string($data)) {
+                       return self::MultiByteCharString2HTML($data, $charset);
+               } elseif (is_array($data)) {
+                       $return_data = array();
+                       foreach ($data as $key => $value) {
+                               $return_data[$key] = self::recursiveMultiByteCharString2HTML($value, $charset);
+                       }
+                       return $return_data;
+               }
+               // integer, float, objects, resources, etc
+               return $data;
+       }
 
        public static function MultiByteCharString2HTML($string, $charset='ISO-8859-1') {
                $string = (string) $string; // in case trying to pass a numeric (float, int) string, would otherwise return an empty string
@@ -1210,16 +1223,21 @@ class getid3_lib
                                                                $newvaluelength = strlen(trim($value));
                                                                foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
                                                                        $oldvaluelength = strlen(trim($existingvalue));
-                                                                       if (($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
+                                                                       if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
                                                                                $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);
-                                                                               break 2;
+                                                                               //break 2;
+                                                                               break;
                                                                        }
                                                                }
 
                                                        }
                                                        if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) {
                                                                $value = (is_string($value) ? trim($value) : $value);
-                                                               $ThisFileInfo['comments'][$tagname][] = $value;
+                                                               if (!is_numeric($key)) {
+                                                                       $ThisFileInfo['comments'][$tagname][$key] = $value;
+                                                               } else {
+                                                                       $ThisFileInfo['comments'][$tagname][]     = $value;
+                                                               }
                                                        }
                                                }
                                        }
@@ -1227,20 +1245,23 @@ class getid3_lib
                        }
 
                        // Copy to ['comments_html']
-                       foreach ($ThisFileInfo['comments'] as $field => $values) {
-                               if ($field == 'picture') {
-                                       // pictures can take up a lot of space, and we don't need multiple copies of them
-                                       // let there be a single copy in [comments][picture], and not elsewhere
-                                       continue;
-                               }
-                               foreach ($values as $index => $value) {
-                                       if (is_array($value)) {
-                                               $ThisFileInfo['comments_html'][$field][$index] = $value;
-                                       } else {
-                                               $ThisFileInfo['comments_html'][$field][$index] = str_replace('&#0;', '', self::MultiByteCharString2HTML($value, $ThisFileInfo['encoding']));
+                       if (!empty($ThisFileInfo['comments'])) {
+                               foreach ($ThisFileInfo['comments'] as $field => $values) {
+                                       if ($field == 'picture') {
+                                               // pictures can take up a lot of space, and we don't need multiple copies of them
+                                               // let there be a single copy in [comments][picture], and not elsewhere
+                                               continue;
+                                       }
+                                       foreach ($values as $index => $value) {
+                                               if (is_array($value)) {
+                                                       $ThisFileInfo['comments_html'][$field][$index] = $value;
+                                               } else {
+                                                       $ThisFileInfo['comments_html'][$field][$index] = str_replace('&#0;', '', self::MultiByteCharString2HTML($value, $ThisFileInfo['encoding']));
+                                               }
                                        }
                                }
                        }
+
                }
                return true;
        }
@@ -1339,4 +1360,17 @@ class getid3_lib
                }
                return $filesize;
        }
+
+
+       /**
+       * Workaround for Bug #37268 (https://bugs.php.net/bug.php?id=37268)
+       * @param string $path A path.
+       * @param string $suffix If the name component ends in suffix this will also be cut off.
+       * @return string
+       */
+       public static function mb_basename($path, $suffix = null) {
+               $splited = preg_split('#/#', rtrim($path, '/ '));
+               return substr(basename('X'.$splited[count($splited) - 1], $suffix), 1);
+       }
+
 }
\ No newline at end of file