wp/wp-includes/ID3/getid3.lib.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
     1 <?php
     1 <?php
     2 /////////////////////////////////////////////////////////////////
     2 /////////////////////////////////////////////////////////////////
     3 /// getID3() by James Heinrich <info@getid3.org>               //
     3 /// getID3() by James Heinrich <info@getid3.org>               //
     4 //  available at http://getid3.sourceforge.net                 //
     4 //  available at http://getid3.sourceforge.net                 //
     5 //            or http://www.getid3.org                         //
     5 //            or http://www.getid3.org                         //
       
     6 //          also https://github.com/JamesHeinrich/getID3       //
     6 /////////////////////////////////////////////////////////////////
     7 /////////////////////////////////////////////////////////////////
     7 //                                                             //
     8 //                                                             //
     8 // getid3.lib.php - part of getID3()                           //
     9 // getid3.lib.php - part of getID3()                           //
     9 // See readme.txt for more details                             //
    10 // See readme.txt for more details                             //
    10 //                                                            ///
    11 //                                                            ///
   280 				if ($intvalue & $signMaskBit) {
   281 				if ($intvalue & $signMaskBit) {
   281 					$intvalue = 0 - ($intvalue & ($signMaskBit - 1));
   282 					$intvalue = 0 - ($intvalue & ($signMaskBit - 1));
   282 				}
   283 				}
   283 			} else {
   284 			} else {
   284 				throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits ('.strlen($byteword).') in self::BigEndian2Int()');
   285 				throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits ('.strlen($byteword).') in self::BigEndian2Int()');
   285 				break;
       
   286 			}
   286 			}
   287 		}
   287 		}
   288 		return self::CastAsInt($intvalue);
   288 		return self::CastAsInt($intvalue);
   289 	}
   289 	}
   290 
   290 
   517 		}
   517 		}
   518 		return ($returnkey ? $minkey : $minvalue);
   518 		return ($returnkey ? $minkey : $minvalue);
   519 	}
   519 	}
   520 
   520 
   521 	public static function XML2array($XMLstring) {
   521 	public static function XML2array($XMLstring) {
   522 		if (function_exists('simplexml_load_string')) {
   522 		if ( function_exists( 'simplexml_load_string' ) && function_exists( 'libxml_disable_entity_loader' ) ) {
   523 			if (function_exists('get_object_vars')) {
   523 			$loader = libxml_disable_entity_loader( true );
   524 				$XMLobject = simplexml_load_string($XMLstring);
   524 			$XMLobject = simplexml_load_string( $XMLstring, 'SimpleXMLElement', LIBXML_NOENT );
   525 				return self::SimpleXMLelement2array($XMLobject);
   525 			$return = self::SimpleXMLelement2array( $XMLobject );
   526 			}
   526 			libxml_disable_entity_loader( $loader );
       
   527 			return $return;
   527 		}
   528 		}
   528 		return false;
   529 		return false;
   529 	}
   530 	}
   530 
   531 
   531 	public static function SimpleXMLelement2array($XMLobject) {
   532 	public static function SimpleXMLelement2array($XMLobject) {
   632 		if (!self::intValueSupported($offset + $length)) {
   633 		if (!self::intValueSupported($offset + $length)) {
   633 			throw new Exception('cannot copy file portion, it extends beyond the '.round(PHP_INT_MAX / 1073741824).'GB limit');
   634 			throw new Exception('cannot copy file portion, it extends beyond the '.round(PHP_INT_MAX / 1073741824).'GB limit');
   634 		}
   635 		}
   635 		if (is_readable($filename_source) && is_file($filename_source) && ($fp_src = fopen($filename_source, 'rb'))) {
   636 		if (is_readable($filename_source) && is_file($filename_source) && ($fp_src = fopen($filename_source, 'rb'))) {
   636 			if (($fp_dest = fopen($filename_dest, 'wb'))) {
   637 			if (($fp_dest = fopen($filename_dest, 'wb'))) {
   637 				if (fseek($fp_src, $offset, SEEK_SET) == 0) {
   638 				if (fseek($fp_src, $offset) == 0) {
   638 					$byteslefttowrite = $length;
   639 					$byteslefttowrite = $length;
   639 					while (($byteslefttowrite > 0) && ($buffer = fread($fp_src, min($byteslefttowrite, getID3::FREAD_BUFFER_SIZE)))) {
   640 					while (($byteslefttowrite > 0) && ($buffer = fread($fp_src, min($byteslefttowrite, getID3::FREAD_BUFFER_SIZE)))) {
   640 						$byteswritten = fwrite($fp_dest, $buffer, $byteslefttowrite);
   641 						$byteswritten = fwrite($fp_dest, $buffer, $byteslefttowrite);
   641 						$byteslefttowrite -= $byteswritten;
   642 						$byteslefttowrite -= $byteswritten;
   642 					}
   643 					}
   983 			return self::$ConversionFunction($string);
   984 			return self::$ConversionFunction($string);
   984 		}
   985 		}
   985 		throw new Exception('PHP does not have iconv() support - cannot convert from '.$in_charset.' to '.$out_charset);
   986 		throw new Exception('PHP does not have iconv() support - cannot convert from '.$in_charset.' to '.$out_charset);
   986 	}
   987 	}
   987 
   988 
       
   989 	public static function recursiveMultiByteCharString2HTML($data, $charset='ISO-8859-1') {
       
   990 		if (is_string($data)) {
       
   991 			return self::MultiByteCharString2HTML($data, $charset);
       
   992 		} elseif (is_array($data)) {
       
   993 			$return_data = array();
       
   994 			foreach ($data as $key => $value) {
       
   995 				$return_data[$key] = self::recursiveMultiByteCharString2HTML($value, $charset);
       
   996 			}
       
   997 			return $return_data;
       
   998 		}
       
   999 		// integer, float, objects, resources, etc
       
  1000 		return $data;
       
  1001 	}
   988 
  1002 
   989 	public static function MultiByteCharString2HTML($string, $charset='ISO-8859-1') {
  1003 	public static function MultiByteCharString2HTML($string, $charset='ISO-8859-1') {
   990 		$string = (string) $string; // in case trying to pass a numeric (float, int) string, would otherwise return an empty string
  1004 		$string = (string) $string; // in case trying to pass a numeric (float, int) string, would otherwise return an empty string
   991 		$HTMLstring = '';
  1005 		$HTMLstring = '';
   992 
  1006 
  1207 							} elseif (!is_array($value)) {
  1221 							} elseif (!is_array($value)) {
  1208 
  1222 
  1209 								$newvaluelength = strlen(trim($value));
  1223 								$newvaluelength = strlen(trim($value));
  1210 								foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
  1224 								foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
  1211 									$oldvaluelength = strlen(trim($existingvalue));
  1225 									$oldvaluelength = strlen(trim($existingvalue));
  1212 									if (($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
  1226 									if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
  1213 										$ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);
  1227 										$ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);
  1214 										break 2;
  1228 										//break 2;
       
  1229 										break;
  1215 									}
  1230 									}
  1216 								}
  1231 								}
  1217 
  1232 
  1218 							}
  1233 							}
  1219 							if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) {
  1234 							if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) {
  1220 								$value = (is_string($value) ? trim($value) : $value);
  1235 								$value = (is_string($value) ? trim($value) : $value);
  1221 								$ThisFileInfo['comments'][$tagname][] = $value;
  1236 								if (!is_numeric($key)) {
       
  1237 									$ThisFileInfo['comments'][$tagname][$key] = $value;
       
  1238 								} else {
       
  1239 									$ThisFileInfo['comments'][$tagname][]     = $value;
       
  1240 								}
  1222 							}
  1241 							}
  1223 						}
  1242 						}
  1224 					}
  1243 					}
  1225 				}
  1244 				}
  1226 			}
  1245 			}
  1227 
  1246 
  1228 			// Copy to ['comments_html']
  1247 			// Copy to ['comments_html']
  1229 			foreach ($ThisFileInfo['comments'] as $field => $values) {
  1248 			if (!empty($ThisFileInfo['comments'])) {
  1230 				if ($field == 'picture') {
  1249 				foreach ($ThisFileInfo['comments'] as $field => $values) {
  1231 					// pictures can take up a lot of space, and we don't need multiple copies of them
  1250 					if ($field == 'picture') {
  1232 					// let there be a single copy in [comments][picture], and not elsewhere
  1251 						// pictures can take up a lot of space, and we don't need multiple copies of them
  1233 					continue;
  1252 						// let there be a single copy in [comments][picture], and not elsewhere
  1234 				}
  1253 						continue;
  1235 				foreach ($values as $index => $value) {
  1254 					}
  1236 					if (is_array($value)) {
  1255 					foreach ($values as $index => $value) {
  1237 						$ThisFileInfo['comments_html'][$field][$index] = $value;
  1256 						if (is_array($value)) {
  1238 					} else {
  1257 							$ThisFileInfo['comments_html'][$field][$index] = $value;
  1239 						$ThisFileInfo['comments_html'][$field][$index] = str_replace('&#0;', '', self::MultiByteCharString2HTML($value, $ThisFileInfo['encoding']));
  1258 						} else {
       
  1259 							$ThisFileInfo['comments_html'][$field][$index] = str_replace('&#0;', '', self::MultiByteCharString2HTML($value, $ThisFileInfo['encoding']));
       
  1260 						}
  1240 					}
  1261 					}
  1241 				}
  1262 				}
  1242 			}
  1263 			}
       
  1264 
  1243 		}
  1265 		}
  1244 		return true;
  1266 		return true;
  1245 	}
  1267 	}
  1246 
  1268 
  1247 
  1269 
  1336 				$filesize = (float) $output;
  1358 				$filesize = (float) $output;
  1337 			}
  1359 			}
  1338 		}
  1360 		}
  1339 		return $filesize;
  1361 		return $filesize;
  1340 	}
  1362 	}
       
  1363 
       
  1364 
       
  1365 	/**
       
  1366 	* Workaround for Bug #37268 (https://bugs.php.net/bug.php?id=37268)
       
  1367 	* @param string $path A path.
       
  1368 	* @param string $suffix If the name component ends in suffix this will also be cut off.
       
  1369 	* @return string
       
  1370 	*/
       
  1371 	public static function mb_basename($path, $suffix = null) {
       
  1372 		$splited = preg_split('#/#', rtrim($path, '/ '));
       
  1373 		return substr(basename('X'.$splited[count($splited) - 1], $suffix), 1);
       
  1374 	}
       
  1375 
  1341 }
  1376 }