Code Duplication    Length = 54-54 lines in 2 locations

src/wp-includes/ID3/module.tag.id3v2.php 2 locations

@@ 1997-2050 (lines=54) @@
1994
			}
1995
			$frame_offset += 4;
1996
1997
			if ($frame_offset < strlen($parsedFrame['data'])) {
1998
				$parsedFrame['subframes'] = array();
1999
				while ($frame_offset < strlen($parsedFrame['data'])) {
2000
					// <Optional embedded sub-frames>
2001
					$subframe = array();
2002
					$subframe['name']      =                           substr($parsedFrame['data'], $frame_offset, 4);
2003
					$frame_offset += 4;
2004
					$subframe['size']      = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
2005
					$frame_offset += 4;
2006
					$subframe['flags_raw'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2));
2007
					$frame_offset += 2;
2008
					if ($subframe['size'] > (strlen($parsedFrame['data']) - $frame_offset)) {
2009
						$info['warning'][] = 'CHAP subframe "'.$subframe['name'].'" at frame offset '.$frame_offset.' claims to be "'.$subframe['size'].'" bytes, which is more than the available data ('.(strlen($parsedFrame['data']) - $frame_offset).' bytes)';
2010
						break;
2011
					}
2012
					$subframe_rawdata = substr($parsedFrame['data'], $frame_offset, $subframe['size']);
2013
					$frame_offset += $subframe['size'];
2014
2015
					$subframe['encodingid'] = ord(substr($subframe_rawdata, 0, 1));
2016
					$subframe['text']       =     substr($subframe_rawdata, 1);
2017
					$subframe['encoding']   = $this->TextEncodingNameLookup($subframe['encodingid']);
2018
					$encoding_converted_text = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe['text']));;
2019
					switch (substr($encoding_converted_text, 0, 2)) {
2020
						case "\xFF\xFE":
2021
						case "\xFE\xFF":
2022
							switch (strtoupper($info['id3v2']['encoding'])) {
2023
								case 'ISO-8859-1':
2024
								case 'UTF-8':
2025
									$encoding_converted_text = substr($encoding_converted_text, 2);
2026
									// remove unwanted byte-order-marks
2027
									break;
2028
								default:
2029
									// ignore
2030
									break;
2031
							}
2032
							break;
2033
						default:
2034
							// do not remove BOM
2035
							break;
2036
					}
2037
2038
					if (($subframe['name'] == 'TIT2') || ($subframe['name'] == 'TIT3')) {
2039
						if ($subframe['name'] == 'TIT2') {
2040
							$parsedFrame['chapter_name']        = $encoding_converted_text;
2041
						} elseif ($subframe['name'] == 'TIT3') {
2042
							$parsedFrame['chapter_description'] = $encoding_converted_text;
2043
						}
2044
						$parsedFrame['subframes'][] = $subframe;
2045
					} else {
2046
						$info['warning'][] = 'ID3v2.CHAP subframe "'.$subframe['name'].'" not handled (only TIT2 and TIT3)';
2047
					}
2048
				}
2049
				unset($subframe_rawdata, $subframe, $encoding_converted_text);
2050
			}
2051
2052
			$id3v2_chapter_entry = array();
2053
			foreach (array('id', 'time_begin', 'time_end', 'offset_begin', 'offset_end', 'chapter_name', 'chapter_description') as $id3v2_chapter_key) {
@@ 2094-2147 (lines=54) @@
2091
2092
			unset($ctoc_flags_raw, $terminator_position);
2093
2094
			if ($frame_offset < strlen($parsedFrame['data'])) {
2095
				$parsedFrame['subframes'] = array();
2096
				while ($frame_offset < strlen($parsedFrame['data'])) {
2097
					// <Optional embedded sub-frames>
2098
					$subframe = array();
2099
					$subframe['name']      =                           substr($parsedFrame['data'], $frame_offset, 4);
2100
					$frame_offset += 4;
2101
					$subframe['size']      = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
2102
					$frame_offset += 4;
2103
					$subframe['flags_raw'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2));
2104
					$frame_offset += 2;
2105
					if ($subframe['size'] > (strlen($parsedFrame['data']) - $frame_offset)) {
2106
						$info['warning'][] = 'CTOS subframe "'.$subframe['name'].'" at frame offset '.$frame_offset.' claims to be "'.$subframe['size'].'" bytes, which is more than the available data ('.(strlen($parsedFrame['data']) - $frame_offset).' bytes)';
2107
						break;
2108
					}
2109
					$subframe_rawdata = substr($parsedFrame['data'], $frame_offset, $subframe['size']);
2110
					$frame_offset += $subframe['size'];
2111
2112
					$subframe['encodingid'] = ord(substr($subframe_rawdata, 0, 1));
2113
					$subframe['text']       =     substr($subframe_rawdata, 1);
2114
					$subframe['encoding']   = $this->TextEncodingNameLookup($subframe['encodingid']);
2115
					$encoding_converted_text = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe['text']));;
2116
					switch (substr($encoding_converted_text, 0, 2)) {
2117
						case "\xFF\xFE":
2118
						case "\xFE\xFF":
2119
							switch (strtoupper($info['id3v2']['encoding'])) {
2120
								case 'ISO-8859-1':
2121
								case 'UTF-8':
2122
									$encoding_converted_text = substr($encoding_converted_text, 2);
2123
									// remove unwanted byte-order-marks
2124
									break;
2125
								default:
2126
									// ignore
2127
									break;
2128
							}
2129
							break;
2130
						default:
2131
							// do not remove BOM
2132
							break;
2133
					}
2134
2135
					if (($subframe['name'] == 'TIT2') || ($subframe['name'] == 'TIT3')) {
2136
						if ($subframe['name'] == 'TIT2') {
2137
							$parsedFrame['toc_name']        = $encoding_converted_text;
2138
						} elseif ($subframe['name'] == 'TIT3') {
2139
							$parsedFrame['toc_description'] = $encoding_converted_text;
2140
						}
2141
						$parsedFrame['subframes'][] = $subframe;
2142
					} else {
2143
						$info['warning'][] = 'ID3v2.CTOC subframe "'.$subframe['name'].'" not handled (only TIT2 and TIT3)';
2144
					}
2145
				}
2146
				unset($subframe_rawdata, $subframe, $encoding_converted_text);
2147
			}
2148
2149
		}
2150