Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use comments_html content already generated by modules... #225

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
85 changes: 48 additions & 37 deletions getid3/getid3.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1535,53 +1535,64 @@ public static function ImageExtFromMime($mime_type) {
*/
public static function CopyTagsToComments(&$ThisFileInfo, $option_tags_html=true) {

$comment_arrays = array('comments');
if($option_tags_html) {
$comment_arrays[] = 'comments_html';
}
// Copy all entries from ['tags'] into common ['comments']
if (!empty($ThisFileInfo['tags'])) {
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;
foreach($comment_arrays as $comments) {
if ($comments != 'comments' && $key == '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;
}
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;
}
}
}

} elseif (!is_array($value)) {

$newvaluelength = strlen(trim($value));
foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
$oldvaluelength = strlen(trim($existingvalue));
if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
$ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);
//break 2;
break;

} elseif (!is_array($value)) {

$newvaluelength = strlen(trim($value));
foreach ($ThisFileInfo[$comments][$tagname] as $existingkey => $existingvalue) {
$oldvaluelength = strlen(trim($existingvalue));
if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
$ThisFileInfo[$comments][$tagname][$existingkey] = trim($value);
//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);
if (!is_int($key) && !ctype_digit($key)) {
$ThisFileInfo['comments'][$tagname][$key] = $value;
} else {
if (!isset($ThisFileInfo['comments'][$tagname])) {
$ThisFileInfo['comments'][$tagname] = array($value);
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 {
$ThisFileInfo['comments'][$tagname][] = $value;
if (!isset($ThisFileInfo[$comments][$tagname])) {
$ThisFileInfo[$comments][$tagname] = array($value);
} else {
$ThisFileInfo[$comments][$tagname][] = $value;
}
}
}
}
}
}
}
}
}
Expand All @@ -1599,7 +1610,7 @@ public static function CopyTagsToComments(&$ThisFileInfo, $option_tags_html=true
}

if ($option_tags_html) {
// Copy to ['comments_html']
// Copy to ['comments_html'], if not already present.
if (!empty($ThisFileInfo['comments'])) {
foreach ($ThisFileInfo['comments'] as $field => $values) {
if ($field == 'picture') {
Expand All @@ -1610,7 +1621,7 @@ public static function CopyTagsToComments(&$ThisFileInfo, $option_tags_html=true
foreach ($values as $index => $value) {
if (is_array($value)) {
$ThisFileInfo['comments_html'][$field][$index] = $value;
} else {
} elseif(empty($ThisFileInfo['comments_html'][$field][$index])) {
$ThisFileInfo['comments_html'][$field][$index] = str_replace('&#0;', '', self::MultiByteCharString2HTML($value, $ThisFileInfo['encoding']));
}
}
Expand Down