getid3_lib::CopyTagsToComments()public staticWP 1.0

{} Это метод класса: getid3_lib{}

Хуков нет.

Возвращает

true|false.

Использование

$result = getid3_lib::CopyTagsToComments( $ThisFileInfo, $option_tags_html );
$ThisFileInfo(массив) (обязательный) (передается по ссылке — &)
-
$option_tags_html(true|false)
default true (just as in the main getID3 class)
По умолчанию: true

Код getid3_lib::CopyTagsToComments() WP 6.0.2

public static function CopyTagsToComments(&$ThisFileInfo, $option_tags_html=true) {
	// Copy all entries from ['tags'] into common ['comments']
	if (!empty($ThisFileInfo['tags'])) {

		// Some tag types can only support limited character sets and may contain data in non-standard encoding (usually ID3v1)
		// and/or poorly-transliterated tag values that are also in tag formats that do support full-range character sets
		// To make the output more user-friendly, process the potentially-problematic tag formats last to enhance the chance that
		// the first entries in [comments] are the most correct and the "bad" ones (if any) come later.
		// https://github.com/JamesHeinrich/getID3/issues/338
		$processLastTagTypes = array('id3v1','riff');
		foreach ($processLastTagTypes as $processLastTagType) {
			if (isset($ThisFileInfo['tags'][$processLastTagType])) {
				// bubble ID3v1 to the end, if present to aid in detecting bad ID3v1 encodings
				$temp = $ThisFileInfo['tags'][$processLastTagType];
				unset($ThisFileInfo['tags'][$processLastTagType]);
				$ThisFileInfo['tags'][$processLastTagType] = $temp;
				unset($temp);
			}
		}
		foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) {
			foreach ($tagarray as $tagname => $tagdata) {
				foreach ($tagdata as $key => $value) {
					if (!empty($value)) {
						if (empty($ThisFileInfo['comments'][$tagname])) {

							// fall through and append value

						} elseif ($tagtype == 'id3v1') {

							$newvaluelength = strlen(trim($value));
							foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
								$oldvaluelength = strlen(trim($existingvalue));
								if (($newvaluelength <= $oldvaluelength) && (substr($existingvalue, 0, $newvaluelength) == trim($value))) {
									// new value is identical but shorter-than (or equal-length to) one already in comments - skip
									break 2;
								}

								if (function_exists('mb_convert_encoding')) {
									if (trim($value) == trim(substr(mb_convert_encoding($existingvalue, $ThisFileInfo['id3v1']['encoding'], $ThisFileInfo['encoding']), 0, 30))) {
										// value stored in ID3v1 appears to be probably the multibyte value transliterated (badly) into ISO-8859-1 in ID3v1.
										// As an example, Foobar2000 will do this if you tag a file with Chinese or Arabic or Cyrillic or something that doesn't fit into ISO-8859-1 the ID3v1 will consist of mostly "?" characters, one per multibyte unrepresentable character
										break 2;
									}
								}
							}

						} elseif (!is_array($value)) {

							$newvaluelength   =    strlen(trim($value));
							$newvaluelengthMB = mb_strlen(trim($value));
							foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
								$oldvaluelength   =    strlen(trim($existingvalue));
								$oldvaluelengthMB = mb_strlen(trim($existingvalue));
								if (($newvaluelengthMB == $oldvaluelengthMB) && ($existingvalue == getid3_lib::iconv_fallback('UTF-8', 'ASCII', $value))) {
									// https://github.com/JamesHeinrich/getID3/issues/338
									// check for tags containing extended characters that may have been forced into limited-character storage (e.g. UTF8 values into ASCII)
									// which will usually display unrepresentable characters as "?"
									$ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);
									break;
								}
								if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
									$ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);
									break;
								}
							}

						}
						if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) {
							$value = (is_string($value) ? trim($value) : $value);
							if (!is_int($key) && !ctype_digit($key)) {
								$ThisFileInfo['comments'][$tagname][$key] = $value;
							} else {
								if (!isset($ThisFileInfo['comments'][$tagname])) {
									$ThisFileInfo['comments'][$tagname] = array($value);
								} else {
									$ThisFileInfo['comments'][$tagname][] = $value;
								}
							}
						}
					}
				}
			}
		}

		// attempt to standardize spelling of returned keys
		if (!empty($ThisFileInfo['comments'])) {
			$StandardizeFieldNames = array(
				'tracknumber' => 'track_number',
				'track'       => 'track_number',
			);
			foreach ($StandardizeFieldNames as $badkey => $goodkey) {
				if (array_key_exists($badkey, $ThisFileInfo['comments']) && !array_key_exists($goodkey, $ThisFileInfo['comments'])) {
					$ThisFileInfo['comments'][$goodkey] = $ThisFileInfo['comments'][$badkey];
					unset($ThisFileInfo['comments'][$badkey]);
				}
			}
		}

		if ($option_tags_html) {
			// Copy ['comments'] to ['comments_html']
			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;
}