| Conditions | 347 | 
| Paths | > 20000 | 
| Total Lines | 1630 | 
| Lines | 189 | 
| Ratio | 11.6 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php | ||
| 559 | 	public function ParseID3v2Frame(&$parsedFrame) { | ||
| 560 | |||
| 561 | // shortcuts | ||
| 562 | $info = &$this->getid3->info; | ||
| 563 | $id3v2_majorversion = $info['id3v2']['majorversion']; | ||
| 564 | |||
| 565 | $parsedFrame['framenamelong'] = $this->FrameNameLongLookup($parsedFrame['frame_name']); | ||
| 566 | 		if (empty($parsedFrame['framenamelong'])) { | ||
| 567 | unset($parsedFrame['framenamelong']); | ||
| 568 | } | ||
| 569 | $parsedFrame['framenameshort'] = $this->FrameNameShortLookup($parsedFrame['frame_name']); | ||
| 570 | 		if (empty($parsedFrame['framenameshort'])) { | ||
| 571 | unset($parsedFrame['framenameshort']); | ||
| 572 | } | ||
| 573 | |||
| 574 | 		if ($id3v2_majorversion >= 3) { // frame flags are not part of the ID3v2.2 standard | ||
| 575 | 			if ($id3v2_majorversion == 3) { | ||
| 576 | // Frame Header Flags | ||
| 577 | // %abc00000 %ijk00000 | ||
| 578 | $parsedFrame['flags']['TagAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x8000); // a - Tag alter preservation | ||
| 579 | $parsedFrame['flags']['FileAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x4000); // b - File alter preservation | ||
| 580 | $parsedFrame['flags']['ReadOnly'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x2000); // c - Read only | ||
| 581 | $parsedFrame['flags']['compression'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0080); // i - Compression | ||
| 582 | $parsedFrame['flags']['Encryption'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0040); // j - Encryption | ||
| 583 | $parsedFrame['flags']['GroupingIdentity'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0020); // k - Grouping identity | ||
| 584 | |||
| 585 | 			} elseif ($id3v2_majorversion == 4) { | ||
| 586 | // Frame Header Flags | ||
| 587 | // %0abc0000 %0h00kmnp | ||
| 588 | $parsedFrame['flags']['TagAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x4000); // a - Tag alter preservation | ||
| 589 | $parsedFrame['flags']['FileAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x2000); // b - File alter preservation | ||
| 590 | $parsedFrame['flags']['ReadOnly'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x1000); // c - Read only | ||
| 591 | $parsedFrame['flags']['GroupingIdentity'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0040); // h - Grouping identity | ||
| 592 | $parsedFrame['flags']['compression'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0008); // k - Compression | ||
| 593 | $parsedFrame['flags']['Encryption'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0004); // m - Encryption | ||
| 594 | $parsedFrame['flags']['Unsynchronisation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0002); // n - Unsynchronisation | ||
| 595 | $parsedFrame['flags']['DataLengthIndicator'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0001); // p - Data length indicator | ||
| 596 | |||
| 597 | // Frame-level de-unsynchronisation - ID3v2.4 | ||
| 598 | 				if ($parsedFrame['flags']['Unsynchronisation']) { | ||
| 599 | $parsedFrame['data'] = $this->DeUnsynchronise($parsedFrame['data']); | ||
| 600 | } | ||
| 601 | |||
| 602 | View Code Duplication | 				if ($parsedFrame['flags']['DataLengthIndicator']) { | |
| 603 | $parsedFrame['data_length_indicator'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 4), 1); | ||
| 604 | $parsedFrame['data'] = substr($parsedFrame['data'], 4); | ||
| 605 | } | ||
| 606 | } | ||
| 607 | |||
| 608 | // Frame-level de-compression | ||
| 609 | 			if ($parsedFrame['flags']['compression']) { | ||
| 610 | $parsedFrame['decompressed_size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 4)); | ||
| 611 | 				if (!function_exists('gzuncompress')) { | ||
| 612 | 					$this->warning('gzuncompress() support required to decompress ID3v2 frame "'.$parsedFrame['frame_name'].'"'); | ||
| 613 | 				} else { | ||
| 614 | 					if ($decompresseddata = @gzuncompress(substr($parsedFrame['data'], 4))) { | ||
| 615 | 					//if ($decompresseddata = @gzuncompress($parsedFrame['data'])) { | ||
| 616 | $parsedFrame['data'] = $decompresseddata; | ||
| 617 | unset($decompresseddata); | ||
| 618 | 					} else { | ||
| 619 | 						$this->warning('gzuncompress() failed on compressed contents of ID3v2 frame "'.$parsedFrame['frame_name'].'"'); | ||
| 620 | } | ||
| 621 | } | ||
| 622 | } | ||
| 623 | } | ||
| 624 | |||
| 625 | 		if (!empty($parsedFrame['flags']['DataLengthIndicator'])) { | ||
| 626 | 			if ($parsedFrame['data_length_indicator'] != strlen($parsedFrame['data'])) { | ||
| 627 | 				$this->warning('ID3v2 frame "'.$parsedFrame['frame_name'].'" should be '.$parsedFrame['data_length_indicator'].' bytes long according to DataLengthIndicator, but found '.strlen($parsedFrame['data']).' bytes of data'); | ||
| 628 | } | ||
| 629 | } | ||
| 630 | |||
| 631 | 		if (isset($parsedFrame['datalength']) && ($parsedFrame['datalength'] == 0)) { | ||
| 632 | |||
| 633 | $warning = 'Frame "'.$parsedFrame['frame_name'].'" at offset '.$parsedFrame['dataoffset'].' has no data portion'; | ||
| 634 | 			switch ($parsedFrame['frame_name']) { | ||
| 635 | case 'WCOM': | ||
| 636 | $warning .= ' (this is known to happen with files tagged by RioPort)'; | ||
| 637 | break; | ||
| 638 | |||
| 639 | default: | ||
| 640 | break; | ||
| 641 | } | ||
| 642 | $this->warning($warning); | ||
| 643 | |||
| 644 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'UFID')) || // 4.1 UFID Unique file identifier | ||
| 645 | 			(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'UFI'))) {  // 4.1   UFI  Unique file identifier | ||
| 646 | // There may be more than one 'UFID' frame in a tag, | ||
| 647 | // but only one with the same 'Owner identifier'. | ||
| 648 | // <Header for 'Unique file identifier', ID: 'UFID'> | ||
| 649 | // Owner identifier <text string> $00 | ||
| 650 | // Identifier <up to 64 bytes binary data> | ||
| 651 | 			$exploded = explode("\x00", $parsedFrame['data'], 2); | ||
| 652 | $parsedFrame['ownerid'] = (isset($exploded[0]) ? $exploded[0] : ''); | ||
| 653 | $parsedFrame['data'] = (isset($exploded[1]) ? $exploded[1] : ''); | ||
| 654 | |||
| 655 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'TXXX')) || // 4.2.2 TXXX User defined text information frame | ||
| 656 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'TXX'))) {    // 4.2.2 TXX  User defined text information frame | ||
| 657 | // There may be more than one 'TXXX' frame in each tag, | ||
| 658 | // but only one with the same description. | ||
| 659 | // <Header for 'User defined text information frame', ID: 'TXXX'> | ||
| 660 | // Text encoding $xx | ||
| 661 | // Description <text string according to encoding> $00 (00) | ||
| 662 | // Value <text string according to encoding> | ||
| 663 | |||
| 664 | $frame_offset = 0; | ||
| 665 | $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 666 | $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); | ||
| 667 | View Code Duplication | 			if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { | |
| 668 | 				$this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); | ||
| 669 | $frame_textencoding_terminator = "\x00"; | ||
| 670 | } | ||
| 671 | $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); | ||
| 672 | View Code Duplication | 			if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { | |
| 673 | $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 | ||
| 674 | } | ||
| 675 | $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 676 | $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); | ||
| 677 | $parsedFrame['encodingid'] = $frame_textencoding; | ||
| 678 | $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); | ||
| 679 | |||
| 680 | $parsedFrame['description'] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['description'])); | ||
| 681 | $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); | ||
| 682 | $parsedFrame['data'] = $this->RemoveStringTerminator($parsedFrame['data'], $frame_textencoding_terminator); | ||
| 683 | 			if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { | ||
| 684 | $commentkey = ($parsedFrame['description'] ? $parsedFrame['description'] : (isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) ? count($info['id3v2']['comments'][$parsedFrame['framenameshort']]) : 0)); | ||
| 685 | View Code Duplication | 				if (!isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) || !array_key_exists($commentkey, $info['id3v2']['comments'][$parsedFrame['framenameshort']])) { | |
| 686 | $info['id3v2']['comments'][$parsedFrame['framenameshort']][$commentkey] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data'])); | ||
| 687 | 				} else { | ||
| 688 | $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data'])); | ||
| 689 | } | ||
| 690 | } | ||
| 691 | //unset($parsedFrame['data']); do not unset, may be needed elsewhere, e.g. for replaygain | ||
| 692 | |||
| 693 | |||
| 694 | 		} elseif ($parsedFrame['frame_name'][0] == 'T') { // 4.2. T??[?] Text information frame | ||
| 695 | // There may only be one text information frame of its kind in an tag. | ||
| 696 | // <Header for 'Text information frame', ID: 'T000' - 'TZZZ', | ||
| 697 | // excluding 'TXXX' described in 4.2.6.> | ||
| 698 | // Text encoding $xx | ||
| 699 | // Information <text string(s) according to encoding> | ||
| 700 | |||
| 701 | $frame_offset = 0; | ||
| 702 | $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 703 | 			if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { | ||
| 704 | 				$this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); | ||
| 705 | } | ||
| 706 | |||
| 707 | $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); | ||
| 708 | $parsedFrame['data'] = $this->RemoveStringTerminator($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding)); | ||
| 709 | |||
| 710 | $parsedFrame['encodingid'] = $frame_textencoding; | ||
| 711 | $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); | ||
| 712 | 			if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { | ||
| 713 | // ID3v2.3 specs say that TPE1 (and others) can contain multiple artist values separated with / | ||
| 714 | // This of course breaks when an artist name contains slash character, e.g. "AC/DC" | ||
| 715 | // MP3tag (maybe others) implement alternative system where multiple artists are null-separated, which makes more sense | ||
| 716 | // getID3 will split null-separated artists into multiple artists and leave slash-separated ones to the user | ||
| 717 | 				switch ($parsedFrame['encoding']) { | ||
| 718 | case 'UTF-16': | ||
| 719 | case 'UTF-16BE': | ||
| 720 | case 'UTF-16LE': | ||
| 721 | $wordsize = 2; | ||
| 722 | break; | ||
| 723 | case 'ISO-8859-1': | ||
| 724 | case 'UTF-8': | ||
| 725 | default: | ||
| 726 | $wordsize = 1; | ||
| 727 | break; | ||
| 728 | } | ||
| 729 | $Txxx_elements = array(); | ||
| 730 | $Txxx_elements_start_offset = 0; | ||
| 731 | 				for ($i = 0; $i < strlen($parsedFrame['data']); $i += $wordsize) { | ||
| 732 | 					if (substr($parsedFrame['data'], $i, $wordsize) == str_repeat("\x00", $wordsize)) { | ||
| 733 | $Txxx_elements[] = substr($parsedFrame['data'], $Txxx_elements_start_offset, $i - $Txxx_elements_start_offset); | ||
| 734 | $Txxx_elements_start_offset = $i + $wordsize; | ||
| 735 | } | ||
| 736 | } | ||
| 737 | $Txxx_elements[] = substr($parsedFrame['data'], $Txxx_elements_start_offset, $i - $Txxx_elements_start_offset); | ||
| 738 | 				foreach ($Txxx_elements as $Txxx_element) { | ||
| 739 | $string = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $Txxx_element); | ||
| 740 | 					if (!empty($string)) { | ||
| 741 | $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $string; | ||
| 742 | } | ||
| 743 | } | ||
| 744 | unset($string, $wordsize, $i, $Txxx_elements, $Txxx_element, $Txxx_elements_start_offset); | ||
| 745 | } | ||
| 746 | |||
| 747 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'WXXX')) || // 4.3.2 WXXX User defined URL link frame | ||
| 748 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'WXX'))) {    // 4.3.2 WXX  User defined URL link frame | ||
| 749 | // There may be more than one 'WXXX' frame in each tag, | ||
| 750 | // but only one with the same description | ||
| 751 | // <Header for 'User defined URL link frame', ID: 'WXXX'> | ||
| 752 | // Text encoding $xx | ||
| 753 | // Description <text string according to encoding> $00 (00) | ||
| 754 | // URL <text string> | ||
| 755 | |||
| 756 | $frame_offset = 0; | ||
| 757 | $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 758 | $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); | ||
| 759 | View Code Duplication | 			if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { | |
| 760 | 				$this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); | ||
| 761 | $frame_textencoding_terminator = "\x00"; | ||
| 762 | } | ||
| 763 | $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); | ||
| 764 | View Code Duplication | 			if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { | |
| 765 | $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 | ||
| 766 | } | ||
| 767 | $parsedFrame['encodingid'] = $frame_textencoding; | ||
| 768 | $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); | ||
| 769 | $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); // according to the frame text encoding | ||
| 770 | $parsedFrame['url'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); // always ISO-8859-1 | ||
| 771 | $parsedFrame['description'] = $this->RemoveStringTerminator($parsedFrame['description'], $frame_textencoding_terminator); | ||
| 772 | $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); | ||
| 773 | |||
| 774 | View Code Duplication | 			if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { | |
| 775 | 				$info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback('ISO-8859-1', $info['id3v2']['encoding'], $parsedFrame['url']); | ||
| 776 | } | ||
| 777 | unset($parsedFrame['data']); | ||
| 778 | |||
| 779 | |||
| 780 | 		} elseif ($parsedFrame['frame_name'][0] == 'W') { // 4.3. W??? URL link frames | ||
| 781 | // There may only be one URL link frame of its kind in a tag, | ||
| 782 | // except when stated otherwise in the frame description | ||
| 783 | // <Header for 'URL link frame', ID: 'W000' - 'WZZZ', excluding 'WXXX' | ||
| 784 | // described in 4.3.2.> | ||
| 785 | // URL <text string> | ||
| 786 | |||
| 787 | $parsedFrame['url'] = trim($parsedFrame['data']); // always ISO-8859-1 | ||
| 788 | View Code Duplication | 			if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { | |
| 789 | 				$info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback('ISO-8859-1', $info['id3v2']['encoding'], $parsedFrame['url']); | ||
| 790 | } | ||
| 791 | unset($parsedFrame['data']); | ||
| 792 | |||
| 793 | |||
| 794 | } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'IPLS')) || // 4.4 IPLS Involved people list (ID3v2.3 only) | ||
| 795 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'IPL'))) {     // 4.4  IPL  Involved people list (ID3v2.2 only) | ||
| 796 | // http://id3.org/id3v2.3.0#sec4.4 | ||
| 797 | // There may only be one 'IPL' frame in each tag | ||
| 798 | // <Header for 'User defined URL link frame', ID: 'IPL'> | ||
| 799 | // Text encoding $xx | ||
| 800 | // People list strings <textstrings> | ||
| 801 | |||
| 802 | $frame_offset = 0; | ||
| 803 | $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 804 | 			if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { | ||
| 805 | 				$this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); | ||
| 806 | } | ||
| 807 | $parsedFrame['encodingid'] = $frame_textencoding; | ||
| 808 | $parsedFrame['encoding'] = $this->TextEncodingNameLookup($parsedFrame['encodingid']); | ||
| 809 | $parsedFrame['data_raw'] = (string) substr($parsedFrame['data'], $frame_offset); | ||
| 810 | |||
| 811 | // https://www.getid3.org/phpBB3/viewtopic.php?t=1369 | ||
| 812 | // "this tag typically contains null terminated strings, which are associated in pairs" | ||
| 813 | // "there are users that use the tag incorrectly" | ||
| 814 | $IPLS_parts = array(); | ||
| 815 | 			if (strpos($parsedFrame['data_raw'], "\x00") !== false) { | ||
| 816 | $IPLS_parts_unsorted = array(); | ||
| 817 | 				if (((strlen($parsedFrame['data_raw']) % 2) == 0) && ((substr($parsedFrame['data_raw'], 0, 2) == "\xFF\xFE") || (substr($parsedFrame['data_raw'], 0, 2) == "\xFE\xFF"))) { | ||
| 818 | // UTF-16, be careful looking for null bytes since most 2-byte characters may contain one; you need to find twin null bytes, and on even padding | ||
| 819 | $thisILPS = ''; | ||
| 820 | 					for ($i = 0; $i < strlen($parsedFrame['data_raw']); $i += 2) { | ||
| 821 | $twobytes = substr($parsedFrame['data_raw'], $i, 2); | ||
| 822 | 						if ($twobytes === "\x00\x00") { | ||
| 823 | $IPLS_parts_unsorted[] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $thisILPS); | ||
| 824 | $thisILPS = ''; | ||
| 825 | 						} else { | ||
| 826 | $thisILPS .= $twobytes; | ||
| 827 | } | ||
| 828 | } | ||
| 829 | 					if (strlen($thisILPS) > 2) { // 2-byte BOM | ||
| 830 | $IPLS_parts_unsorted[] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $thisILPS); | ||
| 831 | } | ||
| 832 | 				} else { | ||
| 833 | // ISO-8859-1 or UTF-8 or other single-byte-null character set | ||
| 834 | 					$IPLS_parts_unsorted = explode("\x00", $parsedFrame['data_raw']); | ||
| 835 | } | ||
| 836 | 				if (count($IPLS_parts_unsorted) == 1) { | ||
| 837 | // just a list of names, e.g. "Dino Baptiste, Jimmy Copley, John Gordon, Bernie Marsden, Sharon Watson" | ||
| 838 | 					foreach ($IPLS_parts_unsorted as $key => $value) { | ||
| 839 | 						$IPLS_parts_sorted = preg_split('#[;,\\r\\n\\t]#', $value); | ||
| 840 | $position = ''; | ||
| 841 | 						foreach ($IPLS_parts_sorted as $person) { | ||
| 842 | 							$IPLS_parts[] = array('position'=>$position, 'person'=>$person); | ||
| 843 | } | ||
| 844 | } | ||
| 845 | 				} elseif ((count($IPLS_parts_unsorted) % 2) == 0) { | ||
| 846 | $position = ''; | ||
| 847 | $person = ''; | ||
| 848 | 					foreach ($IPLS_parts_unsorted as $key => $value) { | ||
| 849 | 						if (($key % 2) == 0) { | ||
| 850 | $position = $value; | ||
| 851 | 						} else { | ||
| 852 | $person = $value; | ||
| 853 | 							$IPLS_parts[] = array('position'=>$position, 'person'=>$person); | ||
| 854 | $position = ''; | ||
| 855 | $person = ''; | ||
| 856 | } | ||
| 857 | } | ||
| 858 | 				} else { | ||
| 859 | 					foreach ($IPLS_parts_unsorted as $key => $value) { | ||
| 860 | $IPLS_parts[] = array($value); | ||
| 861 | } | ||
| 862 | } | ||
| 863 | |||
| 864 | 			} else { | ||
| 865 | 				$IPLS_parts = preg_split('#[;,\\r\\n\\t]#', $parsedFrame['data_raw']); | ||
| 866 | } | ||
| 867 | $parsedFrame['data'] = $IPLS_parts; | ||
| 868 | |||
| 869 | View Code Duplication | 			if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { | |
| 870 | $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['data']; | ||
| 871 | } | ||
| 872 | |||
| 873 | |||
| 874 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'MCDI')) || // 4.4 MCDI Music CD identifier | ||
| 875 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'MCI'))) {     // 4.5   MCI  Music CD identifier | ||
| 876 | // There may only be one 'MCDI' frame in each tag | ||
| 877 | // <Header for 'Music CD identifier', ID: 'MCDI'> | ||
| 878 | // CD TOC <binary data> | ||
| 879 | |||
| 880 | View Code Duplication | 			if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { | |
| 881 | $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['data']; | ||
| 882 | } | ||
| 883 | |||
| 884 | |||
| 885 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'ETCO')) || // 4.5 ETCO Event timing codes | ||
| 886 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'ETC'))) {     // 4.6   ETC  Event timing codes | ||
| 887 | // There may only be one 'ETCO' frame in each tag | ||
| 888 | // <Header for 'Event timing codes', ID: 'ETCO'> | ||
| 889 | // Time stamp format $xx | ||
| 890 | // Where time stamp format is: | ||
| 891 | // $01 (32-bit value) MPEG frames from beginning of file | ||
| 892 | // $02 (32-bit value) milliseconds from beginning of file | ||
| 893 | // Followed by a list of key events in the following format: | ||
| 894 | // Type of event $xx | ||
| 895 | // Time stamp $xx (xx ...) | ||
| 896 | // The 'Time stamp' is set to zero if directly at the beginning of the sound | ||
| 897 | // or after the previous event. All events MUST be sorted in chronological order. | ||
| 898 | |||
| 899 | $frame_offset = 0; | ||
| 900 | $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 901 | |||
| 902 | 			while ($frame_offset < strlen($parsedFrame['data'])) { | ||
| 903 | $parsedFrame['typeid'] = substr($parsedFrame['data'], $frame_offset++, 1); | ||
| 904 | $parsedFrame['type'] = $this->ETCOEventLookup($parsedFrame['typeid']); | ||
| 905 | $parsedFrame['timestamp'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); | ||
| 906 | $frame_offset += 4; | ||
| 907 | } | ||
| 908 | unset($parsedFrame['data']); | ||
| 909 | |||
| 910 | |||
| 911 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'MLLT')) || // 4.6 MLLT MPEG location lookup table | ||
| 912 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'MLL'))) {     // 4.7   MLL MPEG location lookup table | ||
| 913 | // There may only be one 'MLLT' frame in each tag | ||
| 914 | // <Header for 'Location lookup table', ID: 'MLLT'> | ||
| 915 | // MPEG frames between reference $xx xx | ||
| 916 | // Bytes between reference $xx xx xx | ||
| 917 | // Milliseconds between reference $xx xx xx | ||
| 918 | // Bits for bytes deviation $xx | ||
| 919 | // Bits for milliseconds dev. $xx | ||
| 920 | // Then for every reference the following data is included; | ||
| 921 | // Deviation in bytes %xxx.... | ||
| 922 | // Deviation in milliseconds %xxx.... | ||
| 923 | |||
| 924 | $frame_offset = 0; | ||
| 925 | $parsedFrame['framesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 2)); | ||
| 926 | $parsedFrame['bytesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 2, 3)); | ||
| 927 | $parsedFrame['msbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 5, 3)); | ||
| 928 | $parsedFrame['bitsforbytesdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 8, 1)); | ||
| 929 | $parsedFrame['bitsformsdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 9, 1)); | ||
| 930 | $parsedFrame['data'] = substr($parsedFrame['data'], 10); | ||
| 931 | $deviationbitstream = ''; | ||
| 932 | 			while ($frame_offset < strlen($parsedFrame['data'])) { | ||
| 933 | $deviationbitstream .= getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 934 | } | ||
| 935 | $reference_counter = 0; | ||
| 936 | 			while (strlen($deviationbitstream) > 0) { | ||
| 937 | $parsedFrame[$reference_counter]['bytedeviation'] = bindec(substr($deviationbitstream, 0, $parsedFrame['bitsforbytesdeviation'])); | ||
| 938 | $parsedFrame[$reference_counter]['msdeviation'] = bindec(substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'], $parsedFrame['bitsformsdeviation'])); | ||
| 939 | $deviationbitstream = substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'] + $parsedFrame['bitsformsdeviation']); | ||
| 940 | $reference_counter++; | ||
| 941 | } | ||
| 942 | unset($parsedFrame['data']); | ||
| 943 | |||
| 944 | |||
| 945 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'SYTC')) || // 4.7 SYTC Synchronised tempo codes | ||
| 946 | 				  (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'STC'))) {  // 4.8   STC  Synchronised tempo codes | ||
| 947 | // There may only be one 'SYTC' frame in each tag | ||
| 948 | // <Header for 'Synchronised tempo codes', ID: 'SYTC'> | ||
| 949 | // Time stamp format $xx | ||
| 950 | // Tempo data <binary data> | ||
| 951 | // Where time stamp format is: | ||
| 952 | // $01 (32-bit value) MPEG frames from beginning of file | ||
| 953 | // $02 (32-bit value) milliseconds from beginning of file | ||
| 954 | |||
| 955 | $frame_offset = 0; | ||
| 956 | $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 957 | $timestamp_counter = 0; | ||
| 958 | 			while ($frame_offset < strlen($parsedFrame['data'])) { | ||
| 959 | $parsedFrame[$timestamp_counter]['tempo'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 960 | 				if ($parsedFrame[$timestamp_counter]['tempo'] == 255) { | ||
| 961 | $parsedFrame[$timestamp_counter]['tempo'] += ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 962 | } | ||
| 963 | $parsedFrame[$timestamp_counter]['timestamp'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); | ||
| 964 | $frame_offset += 4; | ||
| 965 | $timestamp_counter++; | ||
| 966 | } | ||
| 967 | unset($parsedFrame['data']); | ||
| 968 | |||
| 969 | |||
| 970 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'USLT')) || // 4.8 USLT Unsynchronised lyric/text transcription | ||
| 971 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'ULT'))) {     // 4.9   ULT  Unsynchronised lyric/text transcription | ||
| 972 | // There may be more than one 'Unsynchronised lyrics/text transcription' frame | ||
| 973 | // in each tag, but only one with the same language and content descriptor. | ||
| 974 | // <Header for 'Unsynchronised lyrics/text transcription', ID: 'USLT'> | ||
| 975 | // Text encoding $xx | ||
| 976 | // Language $xx xx xx | ||
| 977 | // Content descriptor <text string according to encoding> $00 (00) | ||
| 978 | // Lyrics/text <full text string according to encoding> | ||
| 979 | |||
| 980 | $frame_offset = 0; | ||
| 981 | $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 982 | $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); | ||
| 983 | View Code Duplication | 			if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { | |
| 984 | 				$this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); | ||
| 985 | $frame_textencoding_terminator = "\x00"; | ||
| 986 | } | ||
| 987 | $frame_language = substr($parsedFrame['data'], $frame_offset, 3); | ||
| 988 | $frame_offset += 3; | ||
| 989 | $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); | ||
| 990 | View Code Duplication | 			if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { | |
| 991 | $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 | ||
| 992 | } | ||
| 993 | $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 994 | $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); | ||
| 995 | $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); | ||
| 996 | $parsedFrame['data'] = $this->RemoveStringTerminator($parsedFrame['data'], $frame_textencoding_terminator); | ||
| 997 | |||
| 998 | $parsedFrame['encodingid'] = $frame_textencoding; | ||
| 999 | $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); | ||
| 1000 | |||
| 1001 | $parsedFrame['language'] = $frame_language; | ||
| 1002 | $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); | ||
| 1003 | View Code Duplication | 			if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { | |
| 1004 | $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); | ||
| 1005 | } | ||
| 1006 | unset($parsedFrame['data']); | ||
| 1007 | |||
| 1008 | |||
| 1009 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'SYLT')) || // 4.9 SYLT Synchronised lyric/text | ||
| 1010 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'SLT'))) {     // 4.10  SLT  Synchronised lyric/text | ||
| 1011 | // There may be more than one 'SYLT' frame in each tag, | ||
| 1012 | // but only one with the same language and content descriptor. | ||
| 1013 | // <Header for 'Synchronised lyrics/text', ID: 'SYLT'> | ||
| 1014 | // Text encoding $xx | ||
| 1015 | // Language $xx xx xx | ||
| 1016 | // Time stamp format $xx | ||
| 1017 | // $01 (32-bit value) MPEG frames from beginning of file | ||
| 1018 | // $02 (32-bit value) milliseconds from beginning of file | ||
| 1019 | // Content type $xx | ||
| 1020 | // Content descriptor <text string according to encoding> $00 (00) | ||
| 1021 | // Terminated text to be synced (typically a syllable) | ||
| 1022 | // Sync identifier (terminator to above string) $00 (00) | ||
| 1023 | // Time stamp $xx (xx ...) | ||
| 1024 | |||
| 1025 | $frame_offset = 0; | ||
| 1026 | $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1027 | $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); | ||
| 1028 | View Code Duplication | 			if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { | |
| 1029 | 				$this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); | ||
| 1030 | $frame_textencoding_terminator = "\x00"; | ||
| 1031 | } | ||
| 1032 | $frame_language = substr($parsedFrame['data'], $frame_offset, 3); | ||
| 1033 | $frame_offset += 3; | ||
| 1034 | $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1035 | $parsedFrame['contenttypeid'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1036 | $parsedFrame['contenttype'] = $this->SYTLContentTypeLookup($parsedFrame['contenttypeid']); | ||
| 1037 | $parsedFrame['encodingid'] = $frame_textencoding; | ||
| 1038 | $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); | ||
| 1039 | |||
| 1040 | $parsedFrame['language'] = $frame_language; | ||
| 1041 | $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); | ||
| 1042 | |||
| 1043 | $timestampindex = 0; | ||
| 1044 | $frame_remainingdata = substr($parsedFrame['data'], $frame_offset); | ||
| 1045 | 			while (strlen($frame_remainingdata)) { | ||
| 1046 | $frame_offset = 0; | ||
| 1047 | $frame_terminatorpos = strpos($frame_remainingdata, $frame_textencoding_terminator); | ||
| 1048 | 				if ($frame_terminatorpos === false) { | ||
| 1049 | $frame_remainingdata = ''; | ||
| 1050 | 				} else { | ||
| 1051 | View Code Duplication | 					if (ord(substr($frame_remainingdata, $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { | |
| 1052 | $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 | ||
| 1053 | } | ||
| 1054 | $parsedFrame['lyrics'][$timestampindex]['data'] = substr($frame_remainingdata, $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1055 | |||
| 1056 | $frame_remainingdata = substr($frame_remainingdata, $frame_terminatorpos + strlen($frame_textencoding_terminator)); | ||
| 1057 | 					if (($timestampindex == 0) && (ord($frame_remainingdata[0]) != 0)) { | ||
| 1058 | // timestamp probably omitted for first data item | ||
| 1059 | 					} else { | ||
| 1060 | $parsedFrame['lyrics'][$timestampindex]['timestamp'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 0, 4)); | ||
| 1061 | $frame_remainingdata = substr($frame_remainingdata, 4); | ||
| 1062 | } | ||
| 1063 | $timestampindex++; | ||
| 1064 | } | ||
| 1065 | } | ||
| 1066 | unset($parsedFrame['data']); | ||
| 1067 | |||
| 1068 | |||
| 1069 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'COMM')) || // 4.10 COMM Comments | ||
| 1070 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'COM'))) {     // 4.11  COM  Comments | ||
| 1071 | // There may be more than one comment frame in each tag, | ||
| 1072 | // but only one with the same language and content descriptor. | ||
| 1073 | // <Header for 'Comment', ID: 'COMM'> | ||
| 1074 | // Text encoding $xx | ||
| 1075 | // Language $xx xx xx | ||
| 1076 | // Short content descrip. <text string according to encoding> $00 (00) | ||
| 1077 | // The actual text <full text string according to encoding> | ||
| 1078 | |||
| 1079 | 			if (strlen($parsedFrame['data']) < 5) { | ||
| 1080 | |||
| 1081 | 				$this->warning('Invalid data (too short) for "'.$parsedFrame['frame_name'].'" frame at offset '.$parsedFrame['dataoffset']); | ||
| 1082 | |||
| 1083 | 			} else { | ||
| 1084 | |||
| 1085 | $frame_offset = 0; | ||
| 1086 | $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1087 | $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); | ||
| 1088 | View Code Duplication | 				if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { | |
| 1089 | 					$this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); | ||
| 1090 | $frame_textencoding_terminator = "\x00"; | ||
| 1091 | } | ||
| 1092 | $frame_language = substr($parsedFrame['data'], $frame_offset, 3); | ||
| 1093 | $frame_offset += 3; | ||
| 1094 | $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); | ||
| 1095 | View Code Duplication | 				if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { | |
| 1096 | $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 | ||
| 1097 | } | ||
| 1098 | $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1099 | $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); | ||
| 1100 | $frame_text = (string) substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); | ||
| 1101 | $frame_text = $this->RemoveStringTerminator($frame_text, $frame_textencoding_terminator); | ||
| 1102 | |||
| 1103 | $parsedFrame['encodingid'] = $frame_textencoding; | ||
| 1104 | $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); | ||
| 1105 | |||
| 1106 | $parsedFrame['language'] = $frame_language; | ||
| 1107 | $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); | ||
| 1108 | $parsedFrame['data'] = $frame_text; | ||
| 1109 | 				if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { | ||
| 1110 | $commentkey = ($parsedFrame['description'] ? $parsedFrame['description'] : (!empty($info['id3v2']['comments'][$parsedFrame['framenameshort']]) ? count($info['id3v2']['comments'][$parsedFrame['framenameshort']]) : 0)); | ||
| 1111 | View Code Duplication | 					if (!isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) || !array_key_exists($commentkey, $info['id3v2']['comments'][$parsedFrame['framenameshort']])) { | |
| 1112 | $info['id3v2']['comments'][$parsedFrame['framenameshort']][$commentkey] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); | ||
| 1113 | 					} else { | ||
| 1114 | $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); | ||
| 1115 | } | ||
| 1116 | } | ||
| 1117 | |||
| 1118 | } | ||
| 1119 | |||
| 1120 | 		} elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'RVA2')) { // 4.11  RVA2 Relative volume adjustment (2) (ID3v2.4+ only) | ||
| 1121 | // There may be more than one 'RVA2' frame in each tag, | ||
| 1122 | // but only one with the same identification string | ||
| 1123 | // <Header for 'Relative volume adjustment (2)', ID: 'RVA2'> | ||
| 1124 | // Identification <text string> $00 | ||
| 1125 | // The 'identification' string is used to identify the situation and/or | ||
| 1126 | // device where this adjustment should apply. The following is then | ||
| 1127 | // repeated for every channel: | ||
| 1128 | // Type of channel $xx | ||
| 1129 | // Volume adjustment $xx xx | ||
| 1130 | // Bits representing peak $xx | ||
| 1131 | // Peak volume $xx (xx ...) | ||
| 1132 | |||
| 1133 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00"); | ||
| 1134 | $frame_idstring = substr($parsedFrame['data'], 0, $frame_terminatorpos); | ||
| 1135 | 			if (ord($frame_idstring) === 0) { | ||
| 1136 | $frame_idstring = ''; | ||
| 1137 | } | ||
| 1138 | 			$frame_remainingdata = substr($parsedFrame['data'], $frame_terminatorpos + strlen("\x00")); | ||
| 1139 | $parsedFrame['description'] = $frame_idstring; | ||
| 1140 | $RVA2channelcounter = 0; | ||
| 1141 | 			while (strlen($frame_remainingdata) >= 5) { | ||
| 1142 | $frame_offset = 0; | ||
| 1143 | $frame_channeltypeid = ord(substr($frame_remainingdata, $frame_offset++, 1)); | ||
| 1144 | $parsedFrame[$RVA2channelcounter]['channeltypeid'] = $frame_channeltypeid; | ||
| 1145 | $parsedFrame[$RVA2channelcounter]['channeltype'] = $this->RVA2ChannelTypeLookup($frame_channeltypeid); | ||
| 1146 | $parsedFrame[$RVA2channelcounter]['volumeadjust'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, $frame_offset, 2), false, true); // 16-bit signed | ||
| 1147 | $frame_offset += 2; | ||
| 1148 | $parsedFrame[$RVA2channelcounter]['bitspeakvolume'] = ord(substr($frame_remainingdata, $frame_offset++, 1)); | ||
| 1149 | 				if (($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] < 1) || ($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] > 4)) { | ||
| 1150 | 					$this->warning('ID3v2::RVA2 frame['.$RVA2channelcounter.'] contains invalid '.$parsedFrame[$RVA2channelcounter]['bitspeakvolume'].'-byte bits-representing-peak value'); | ||
| 1151 | break; | ||
| 1152 | } | ||
| 1153 | $frame_bytespeakvolume = ceil($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] / 8); | ||
| 1154 | $parsedFrame[$RVA2channelcounter]['peakvolume'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, $frame_offset, $frame_bytespeakvolume)); | ||
| 1155 | $frame_remainingdata = substr($frame_remainingdata, $frame_offset + $frame_bytespeakvolume); | ||
| 1156 | $RVA2channelcounter++; | ||
| 1157 | } | ||
| 1158 | unset($parsedFrame['data']); | ||
| 1159 | |||
| 1160 | |||
| 1161 | } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'RVAD')) || // 4.12 RVAD Relative volume adjustment (ID3v2.3 only) | ||
| 1162 | 				  (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'RVA'))) {  // 4.12  RVA  Relative volume adjustment (ID3v2.2 only) | ||
| 1163 | // There may only be one 'RVA' frame in each tag | ||
| 1164 | // <Header for 'Relative volume adjustment', ID: 'RVA'> | ||
| 1165 | // ID3v2.2 => Increment/decrement %000000ba | ||
| 1166 | // ID3v2.3 => Increment/decrement %00fedcba | ||
| 1167 | // Bits used for volume descr. $xx | ||
| 1168 | // Relative volume change, right $xx xx (xx ...) // a | ||
| 1169 | // Relative volume change, left $xx xx (xx ...) // b | ||
| 1170 | // Peak volume right $xx xx (xx ...) | ||
| 1171 | // Peak volume left $xx xx (xx ...) | ||
| 1172 | // ID3v2.3 only, optional (not present in ID3v2.2): | ||
| 1173 | // Relative volume change, right back $xx xx (xx ...) // c | ||
| 1174 | // Relative volume change, left back $xx xx (xx ...) // d | ||
| 1175 | // Peak volume right back $xx xx (xx ...) | ||
| 1176 | // Peak volume left back $xx xx (xx ...) | ||
| 1177 | // ID3v2.3 only, optional (not present in ID3v2.2): | ||
| 1178 | // Relative volume change, center $xx xx (xx ...) // e | ||
| 1179 | // Peak volume center $xx xx (xx ...) | ||
| 1180 | // ID3v2.3 only, optional (not present in ID3v2.2): | ||
| 1181 | // Relative volume change, bass $xx xx (xx ...) // f | ||
| 1182 | // Peak volume bass $xx xx (xx ...) | ||
| 1183 | |||
| 1184 | $frame_offset = 0; | ||
| 1185 | $frame_incrdecrflags = getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1186 | $parsedFrame['incdec']['right'] = (bool) substr($frame_incrdecrflags, 6, 1); | ||
| 1187 | $parsedFrame['incdec']['left'] = (bool) substr($frame_incrdecrflags, 7, 1); | ||
| 1188 | $parsedFrame['bitsvolume'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1189 | $frame_bytesvolume = ceil($parsedFrame['bitsvolume'] / 8); | ||
| 1190 | $parsedFrame['volumechange']['right'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); | ||
| 1191 | 			if ($parsedFrame['incdec']['right'] === false) { | ||
| 1192 | $parsedFrame['volumechange']['right'] *= -1; | ||
| 1193 | } | ||
| 1194 | $frame_offset += $frame_bytesvolume; | ||
| 1195 | $parsedFrame['volumechange']['left'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); | ||
| 1196 | 			if ($parsedFrame['incdec']['left'] === false) { | ||
| 1197 | $parsedFrame['volumechange']['left'] *= -1; | ||
| 1198 | } | ||
| 1199 | $frame_offset += $frame_bytesvolume; | ||
| 1200 | $parsedFrame['peakvolume']['right'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); | ||
| 1201 | $frame_offset += $frame_bytesvolume; | ||
| 1202 | $parsedFrame['peakvolume']['left'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); | ||
| 1203 | $frame_offset += $frame_bytesvolume; | ||
| 1204 | 			if ($id3v2_majorversion == 3) { | ||
| 1205 | $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset); | ||
| 1206 | 				if (strlen($parsedFrame['data']) > 0) { | ||
| 1207 | $parsedFrame['incdec']['rightrear'] = (bool) substr($frame_incrdecrflags, 4, 1); | ||
| 1208 | $parsedFrame['incdec']['leftrear'] = (bool) substr($frame_incrdecrflags, 5, 1); | ||
| 1209 | $parsedFrame['volumechange']['rightrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); | ||
| 1210 | 					if ($parsedFrame['incdec']['rightrear'] === false) { | ||
| 1211 | $parsedFrame['volumechange']['rightrear'] *= -1; | ||
| 1212 | } | ||
| 1213 | $frame_offset += $frame_bytesvolume; | ||
| 1214 | $parsedFrame['volumechange']['leftrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); | ||
| 1215 | 					if ($parsedFrame['incdec']['leftrear'] === false) { | ||
| 1216 | $parsedFrame['volumechange']['leftrear'] *= -1; | ||
| 1217 | } | ||
| 1218 | $frame_offset += $frame_bytesvolume; | ||
| 1219 | $parsedFrame['peakvolume']['rightrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); | ||
| 1220 | $frame_offset += $frame_bytesvolume; | ||
| 1221 | $parsedFrame['peakvolume']['leftrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); | ||
| 1222 | $frame_offset += $frame_bytesvolume; | ||
| 1223 | } | ||
| 1224 | $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset); | ||
| 1225 | View Code Duplication | 				if (strlen($parsedFrame['data']) > 0) { | |
| 1226 | $parsedFrame['incdec']['center'] = (bool) substr($frame_incrdecrflags, 3, 1); | ||
| 1227 | $parsedFrame['volumechange']['center'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); | ||
| 1228 | 					if ($parsedFrame['incdec']['center'] === false) { | ||
| 1229 | $parsedFrame['volumechange']['center'] *= -1; | ||
| 1230 | } | ||
| 1231 | $frame_offset += $frame_bytesvolume; | ||
| 1232 | $parsedFrame['peakvolume']['center'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); | ||
| 1233 | $frame_offset += $frame_bytesvolume; | ||
| 1234 | } | ||
| 1235 | $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset); | ||
| 1236 | View Code Duplication | 				if (strlen($parsedFrame['data']) > 0) { | |
| 1237 | $parsedFrame['incdec']['bass'] = (bool) substr($frame_incrdecrflags, 2, 1); | ||
| 1238 | $parsedFrame['volumechange']['bass'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); | ||
| 1239 | 					if ($parsedFrame['incdec']['bass'] === false) { | ||
| 1240 | $parsedFrame['volumechange']['bass'] *= -1; | ||
| 1241 | } | ||
| 1242 | $frame_offset += $frame_bytesvolume; | ||
| 1243 | $parsedFrame['peakvolume']['bass'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); | ||
| 1244 | $frame_offset += $frame_bytesvolume; | ||
| 1245 | } | ||
| 1246 | } | ||
| 1247 | unset($parsedFrame['data']); | ||
| 1248 | |||
| 1249 | |||
| 1250 | 		} elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'EQU2')) { // 4.12  EQU2 Equalisation (2) (ID3v2.4+ only) | ||
| 1251 | // There may be more than one 'EQU2' frame in each tag, | ||
| 1252 | // but only one with the same identification string | ||
| 1253 | // <Header of 'Equalisation (2)', ID: 'EQU2'> | ||
| 1254 | // Interpolation method $xx | ||
| 1255 | // $00 Band | ||
| 1256 | // $01 Linear | ||
| 1257 | // Identification <text string> $00 | ||
| 1258 | // The following is then repeated for every adjustment point | ||
| 1259 | // Frequency $xx xx | ||
| 1260 | // Volume adjustment $xx xx | ||
| 1261 | |||
| 1262 | $frame_offset = 0; | ||
| 1263 | $frame_interpolationmethod = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1264 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1265 | $frame_idstring = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1266 | 			if (ord($frame_idstring) === 0) { | ||
| 1267 | $frame_idstring = ''; | ||
| 1268 | } | ||
| 1269 | $parsedFrame['description'] = $frame_idstring; | ||
| 1270 | 			$frame_remainingdata = substr($parsedFrame['data'], $frame_terminatorpos + strlen("\x00")); | ||
| 1271 | 			while (strlen($frame_remainingdata)) { | ||
| 1272 | $frame_frequency = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 0, 2)) / 2; | ||
| 1273 | $parsedFrame['data'][$frame_frequency] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 2, 2), false, true); | ||
| 1274 | $frame_remainingdata = substr($frame_remainingdata, 4); | ||
| 1275 | } | ||
| 1276 | $parsedFrame['interpolationmethod'] = $frame_interpolationmethod; | ||
| 1277 | unset($parsedFrame['data']); | ||
| 1278 | |||
| 1279 | |||
| 1280 | } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'EQUA')) || // 4.12 EQUA Equalisation (ID3v2.3 only) | ||
| 1281 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'EQU'))) {     // 4.13  EQU  Equalisation (ID3v2.2 only) | ||
| 1282 | // There may only be one 'EQUA' frame in each tag | ||
| 1283 | // <Header for 'Relative volume adjustment', ID: 'EQU'> | ||
| 1284 | // Adjustment bits $xx | ||
| 1285 | 			//   This is followed by 2 bytes + ('adjustment bits' rounded up to the | ||
| 1286 | // nearest byte) for every equalisation band in the following format, | ||
| 1287 | // giving a frequency range of 0 - 32767Hz: | ||
| 1288 | // Increment/decrement %x (MSB of the Frequency) | ||
| 1289 | // Frequency (lower 15 bits) | ||
| 1290 | // Adjustment $xx (xx ...) | ||
| 1291 | |||
| 1292 | $frame_offset = 0; | ||
| 1293 | $parsedFrame['adjustmentbits'] = substr($parsedFrame['data'], $frame_offset++, 1); | ||
| 1294 | $frame_adjustmentbytes = ceil($parsedFrame['adjustmentbits'] / 8); | ||
| 1295 | |||
| 1296 | $frame_remainingdata = (string) substr($parsedFrame['data'], $frame_offset); | ||
| 1297 | 			while (strlen($frame_remainingdata) > 0) { | ||
| 1298 | $frame_frequencystr = getid3_lib::BigEndian2Bin(substr($frame_remainingdata, 0, 2)); | ||
| 1299 | $frame_incdec = (bool) substr($frame_frequencystr, 0, 1); | ||
| 1300 | $frame_frequency = bindec(substr($frame_frequencystr, 1, 15)); | ||
| 1301 | $parsedFrame[$frame_frequency]['incdec'] = $frame_incdec; | ||
| 1302 | $parsedFrame[$frame_frequency]['adjustment'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 2, $frame_adjustmentbytes)); | ||
| 1303 | 				if ($parsedFrame[$frame_frequency]['incdec'] === false) { | ||
| 1304 | $parsedFrame[$frame_frequency]['adjustment'] *= -1; | ||
| 1305 | } | ||
| 1306 | $frame_remainingdata = substr($frame_remainingdata, 2 + $frame_adjustmentbytes); | ||
| 1307 | } | ||
| 1308 | unset($parsedFrame['data']); | ||
| 1309 | |||
| 1310 | |||
| 1311 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'RVRB')) || // 4.13 RVRB Reverb | ||
| 1312 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'REV'))) {     // 4.14  REV  Reverb | ||
| 1313 | // There may only be one 'RVRB' frame in each tag. | ||
| 1314 | // <Header for 'Reverb', ID: 'RVRB'> | ||
| 1315 | // Reverb left (ms) $xx xx | ||
| 1316 | // Reverb right (ms) $xx xx | ||
| 1317 | // Reverb bounces, left $xx | ||
| 1318 | // Reverb bounces, right $xx | ||
| 1319 | // Reverb feedback, left to left $xx | ||
| 1320 | // Reverb feedback, left to right $xx | ||
| 1321 | // Reverb feedback, right to right $xx | ||
| 1322 | // Reverb feedback, right to left $xx | ||
| 1323 | // Premix left to right $xx | ||
| 1324 | // Premix right to left $xx | ||
| 1325 | |||
| 1326 | $frame_offset = 0; | ||
| 1327 | $parsedFrame['left'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); | ||
| 1328 | $frame_offset += 2; | ||
| 1329 | $parsedFrame['right'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); | ||
| 1330 | $frame_offset += 2; | ||
| 1331 | $parsedFrame['bouncesL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1332 | $parsedFrame['bouncesR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1333 | $parsedFrame['feedbackLL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1334 | $parsedFrame['feedbackLR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1335 | $parsedFrame['feedbackRR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1336 | $parsedFrame['feedbackRL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1337 | $parsedFrame['premixLR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1338 | $parsedFrame['premixRL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1339 | unset($parsedFrame['data']); | ||
| 1340 | |||
| 1341 | |||
| 1342 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'APIC')) || // 4.14 APIC Attached picture | ||
| 1343 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'PIC'))) {     // 4.15  PIC  Attached picture | ||
| 1344 | // There may be several pictures attached to one file, | ||
| 1345 | // each in their individual 'APIC' frame, but only one | ||
| 1346 | // with the same content descriptor | ||
| 1347 | // <Header for 'Attached picture', ID: 'APIC'> | ||
| 1348 | // Text encoding $xx | ||
| 1349 | // ID3v2.3+ => MIME type <text string> $00 | ||
| 1350 | // ID3v2.2 => Image format $xx xx xx | ||
| 1351 | // Picture type $xx | ||
| 1352 | // Description <text string according to encoding> $00 (00) | ||
| 1353 | // Picture data <binary data> | ||
| 1354 | |||
| 1355 | $frame_offset = 0; | ||
| 1356 | $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1357 | $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); | ||
| 1358 | View Code Duplication | 			if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { | |
| 1359 | 				$this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); | ||
| 1360 | $frame_textencoding_terminator = "\x00"; | ||
| 1361 | } | ||
| 1362 | |||
| 1363 | 			if ($id3v2_majorversion == 2 && strlen($parsedFrame['data']) > $frame_offset) { | ||
| 1364 | $frame_imagetype = substr($parsedFrame['data'], $frame_offset, 3); | ||
| 1365 | 				if (strtolower($frame_imagetype) == 'ima') { | ||
| 1366 | // complete hack for mp3Rage (www.chaoticsoftware.com) that puts ID3v2.3-formatted | ||
| 1367 | // MIME type instead of 3-char ID3v2.2-format image type (thanks xbhoffØpacbell*net) | ||
| 1368 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1369 | $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1370 | 					if (ord($frame_mimetype) === 0) { | ||
| 1371 | $frame_mimetype = ''; | ||
| 1372 | } | ||
| 1373 | 					$frame_imagetype = strtoupper(str_replace('image/', '', strtolower($frame_mimetype))); | ||
| 1374 | 					if ($frame_imagetype == 'JPEG') { | ||
| 1375 | $frame_imagetype = 'JPG'; | ||
| 1376 | } | ||
| 1377 | 					$frame_offset = $frame_terminatorpos + strlen("\x00"); | ||
| 1378 | 				} else { | ||
| 1379 | $frame_offset += 3; | ||
| 1380 | } | ||
| 1381 | } | ||
| 1382 | 			if ($id3v2_majorversion > 2 && strlen($parsedFrame['data']) > $frame_offset) { | ||
| 1383 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1384 | $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1385 | 				if (ord($frame_mimetype) === 0) { | ||
| 1386 | $frame_mimetype = ''; | ||
| 1387 | } | ||
| 1388 | 				$frame_offset = $frame_terminatorpos + strlen("\x00"); | ||
| 1389 | } | ||
| 1390 | |||
| 1391 | $frame_picturetype = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1392 | |||
| 1393 | 			if ($frame_offset >= $parsedFrame['datalength']) { | ||
| 1394 | 				$this->warning('data portion of APIC frame is missing at offset '.($parsedFrame['dataoffset'] + 8 + $frame_offset)); | ||
| 1395 | 			} else { | ||
| 1396 | $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); | ||
| 1397 | View Code Duplication | 				if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { | |
| 1398 | $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 | ||
| 1399 | } | ||
| 1400 | $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1401 | $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); | ||
| 1402 | $parsedFrame['encodingid'] = $frame_textencoding; | ||
| 1403 | $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); | ||
| 1404 | |||
| 1405 | 				if ($id3v2_majorversion == 2) { | ||
| 1406 | $parsedFrame['imagetype'] = isset($frame_imagetype) ? $frame_imagetype : null; | ||
| 1407 | 				} else { | ||
| 1408 | $parsedFrame['mime'] = isset($frame_mimetype) ? $frame_mimetype : null; | ||
| 1409 | } | ||
| 1410 | $parsedFrame['picturetypeid'] = $frame_picturetype; | ||
| 1411 | $parsedFrame['picturetype'] = $this->APICPictureTypeLookup($frame_picturetype); | ||
| 1412 | $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); | ||
| 1413 | $parsedFrame['datalength'] = strlen($parsedFrame['data']); | ||
| 1414 | |||
| 1415 | $parsedFrame['image_mime'] = ''; | ||
| 1416 | $imageinfo = array(); | ||
| 1417 | 				if ($imagechunkcheck = getid3_lib::GetDataImageSize($parsedFrame['data'], $imageinfo)) { | ||
| 1418 | 					if (($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) { | ||
| 1419 | $parsedFrame['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]); | ||
| 1420 | 						if ($imagechunkcheck[0]) { | ||
| 1421 | $parsedFrame['image_width'] = $imagechunkcheck[0]; | ||
| 1422 | } | ||
| 1423 | 						if ($imagechunkcheck[1]) { | ||
| 1424 | $parsedFrame['image_height'] = $imagechunkcheck[1]; | ||
| 1425 | } | ||
| 1426 | } | ||
| 1427 | } | ||
| 1428 | |||
| 1429 | 				do { | ||
| 1430 | 					if ($this->getid3->option_save_attachments === false) { | ||
| 1431 | // skip entirely | ||
| 1432 | unset($parsedFrame['data']); | ||
| 1433 | break; | ||
| 1434 | } | ||
| 1435 | $dir = ''; | ||
| 1436 | 					if ($this->getid3->option_save_attachments === true) { | ||
| 1437 | // great | ||
| 1438 | /* | ||
| 1439 | 					} elseif (is_int($this->getid3->option_save_attachments)) { | ||
| 1440 | 						if ($this->getid3->option_save_attachments < $parsedFrame['data_length']) { | ||
| 1441 | // too big, skip | ||
| 1442 | 							$this->warning('attachment at '.$frame_offset.' is too large to process inline ('.number_format($parsedFrame['data_length']).' bytes)'); | ||
| 1443 | unset($parsedFrame['data']); | ||
| 1444 | break; | ||
| 1445 | } | ||
| 1446 | */ | ||
| 1447 | 					} elseif (is_string($this->getid3->option_save_attachments)) { | ||
| 1448 | 						$dir = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->getid3->option_save_attachments), DIRECTORY_SEPARATOR); | ||
| 1449 | 						if (!is_dir($dir) || !getID3::is_writable($dir)) { | ||
| 1450 | // cannot write, skip | ||
| 1451 | 							$this->warning('attachment at '.$frame_offset.' cannot be saved to "'.$dir.'" (not writable)'); | ||
| 1452 | unset($parsedFrame['data']); | ||
| 1453 | break; | ||
| 1454 | } | ||
| 1455 | } | ||
| 1456 | // if we get this far, must be OK | ||
| 1457 | 					if (is_string($this->getid3->option_save_attachments)) { | ||
| 1458 | $destination_filename = $dir.DIRECTORY_SEPARATOR.md5($info['filenamepath']).'_'.$frame_offset; | ||
| 1459 | View Code Duplication | 						if (!file_exists($destination_filename) || getID3::is_writable($destination_filename)) { | |
| 1460 | file_put_contents($destination_filename, $parsedFrame['data']); | ||
| 1461 | 						} else { | ||
| 1462 | 							$this->warning('attachment at '.$frame_offset.' cannot be saved to "'.$destination_filename.'" (not writable)'); | ||
| 1463 | } | ||
| 1464 | $parsedFrame['data_filename'] = $destination_filename; | ||
| 1465 | unset($parsedFrame['data']); | ||
| 1466 | View Code Duplication | 					} else { | |
| 1467 | 						if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { | ||
| 1468 | 							if (!isset($info['id3v2']['comments']['picture'])) { | ||
| 1469 | $info['id3v2']['comments']['picture'] = array(); | ||
| 1470 | } | ||
| 1471 | $comments_picture_data = array(); | ||
| 1472 | 							foreach (array('data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength') as $picture_key) { | ||
| 1473 | 								if (isset($parsedFrame[$picture_key])) { | ||
| 1474 | $comments_picture_data[$picture_key] = $parsedFrame[$picture_key]; | ||
| 1475 | } | ||
| 1476 | } | ||
| 1477 | $info['id3v2']['comments']['picture'][] = $comments_picture_data; | ||
| 1478 | unset($comments_picture_data); | ||
| 1479 | } | ||
| 1480 | } | ||
| 1481 | } while (false); | ||
| 1482 | } | ||
| 1483 | |||
| 1484 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'GEOB')) || // 4.15 GEOB General encapsulated object | ||
| 1485 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'GEO'))) {     // 4.16  GEO  General encapsulated object | ||
| 1486 | // There may be more than one 'GEOB' frame in each tag, | ||
| 1487 | // but only one with the same content descriptor | ||
| 1488 | // <Header for 'General encapsulated object', ID: 'GEOB'> | ||
| 1489 | // Text encoding $xx | ||
| 1490 | // MIME type <text string> $00 | ||
| 1491 | // Filename <text string according to encoding> $00 (00) | ||
| 1492 | // Content description <text string according to encoding> $00 (00) | ||
| 1493 | // Encapsulated object <binary data> | ||
| 1494 | |||
| 1495 | $frame_offset = 0; | ||
| 1496 | $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1497 | $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); | ||
| 1498 | View Code Duplication | 			if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { | |
| 1499 | 				$this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); | ||
| 1500 | $frame_textencoding_terminator = "\x00"; | ||
| 1501 | } | ||
| 1502 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1503 | $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1504 | 			if (ord($frame_mimetype) === 0) { | ||
| 1505 | $frame_mimetype = ''; | ||
| 1506 | } | ||
| 1507 | 			$frame_offset = $frame_terminatorpos + strlen("\x00"); | ||
| 1508 | |||
| 1509 | $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); | ||
| 1510 | View Code Duplication | 			if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { | |
| 1511 | $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 | ||
| 1512 | } | ||
| 1513 | $frame_filename = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1514 | 			if (ord($frame_filename) === 0) { | ||
| 1515 | $frame_filename = ''; | ||
| 1516 | } | ||
| 1517 | $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); | ||
| 1518 | |||
| 1519 | $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); | ||
| 1520 | View Code Duplication | 			if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { | |
| 1521 | $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 | ||
| 1522 | } | ||
| 1523 | $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1524 | $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); | ||
| 1525 | $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); | ||
| 1526 | |||
| 1527 | $parsedFrame['objectdata'] = (string) substr($parsedFrame['data'], $frame_offset); | ||
| 1528 | $parsedFrame['encodingid'] = $frame_textencoding; | ||
| 1529 | $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); | ||
| 1530 | |||
| 1531 | $parsedFrame['mime'] = $frame_mimetype; | ||
| 1532 | $parsedFrame['filename'] = $frame_filename; | ||
| 1533 | unset($parsedFrame['data']); | ||
| 1534 | |||
| 1535 | |||
| 1536 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'PCNT')) || // 4.16 PCNT Play counter | ||
| 1537 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'CNT'))) {     // 4.17  CNT  Play counter | ||
| 1538 | // There may only be one 'PCNT' frame in each tag. | ||
| 1539 | // When the counter reaches all one's, one byte is inserted in | ||
| 1540 | // front of the counter thus making the counter eight bits bigger | ||
| 1541 | // <Header for 'Play counter', ID: 'PCNT'> | ||
| 1542 | // Counter $xx xx xx xx (xx ...) | ||
| 1543 | |||
| 1544 | $parsedFrame['data'] = getid3_lib::BigEndian2Int($parsedFrame['data']); | ||
| 1545 | |||
| 1546 | |||
| 1547 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'POPM')) || // 4.17 POPM Popularimeter | ||
| 1548 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'POP'))) {    // 4.18  POP  Popularimeter | ||
| 1549 | // There may be more than one 'POPM' frame in each tag, | ||
| 1550 | // but only one with the same email address | ||
| 1551 | // <Header for 'Popularimeter', ID: 'POPM'> | ||
| 1552 | // Email to user <text string> $00 | ||
| 1553 | // Rating $xx | ||
| 1554 | // Counter $xx xx xx xx (xx ...) | ||
| 1555 | |||
| 1556 | $frame_offset = 0; | ||
| 1557 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1558 | $frame_emailaddress = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1559 | 			if (ord($frame_emailaddress) === 0) { | ||
| 1560 | $frame_emailaddress = ''; | ||
| 1561 | } | ||
| 1562 | 			$frame_offset = $frame_terminatorpos + strlen("\x00"); | ||
| 1563 | $frame_rating = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1564 | $parsedFrame['counter'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset)); | ||
| 1565 | $parsedFrame['email'] = $frame_emailaddress; | ||
| 1566 | $parsedFrame['rating'] = $frame_rating; | ||
| 1567 | unset($parsedFrame['data']); | ||
| 1568 | |||
| 1569 | |||
| 1570 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'RBUF')) || // 4.18 RBUF Recommended buffer size | ||
| 1571 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'BUF'))) {     // 4.19  BUF  Recommended buffer size | ||
| 1572 | // There may only be one 'RBUF' frame in each tag | ||
| 1573 | // <Header for 'Recommended buffer size', ID: 'RBUF'> | ||
| 1574 | // Buffer size $xx xx xx | ||
| 1575 | // Embedded info flag %0000000x | ||
| 1576 | // Offset to next tag $xx xx xx xx | ||
| 1577 | |||
| 1578 | $frame_offset = 0; | ||
| 1579 | $parsedFrame['buffersize'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 3)); | ||
| 1580 | $frame_offset += 3; | ||
| 1581 | |||
| 1582 | $frame_embeddedinfoflags = getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1583 | $parsedFrame['flags']['embededinfo'] = (bool) substr($frame_embeddedinfoflags, 7, 1); | ||
| 1584 | $parsedFrame['nexttagoffset'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); | ||
| 1585 | unset($parsedFrame['data']); | ||
| 1586 | |||
| 1587 | |||
| 1588 | 		} elseif (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'CRM')) { // 4.20  Encrypted meta frame (ID3v2.2 only) | ||
| 1589 | // There may be more than one 'CRM' frame in a tag, | ||
| 1590 | // but only one with the same 'owner identifier' | ||
| 1591 | // <Header for 'Encrypted meta frame', ID: 'CRM'> | ||
| 1592 | // Owner identifier <textstring> $00 (00) | ||
| 1593 | // Content/explanation <textstring> $00 (00) | ||
| 1594 | // Encrypted datablock <binary data> | ||
| 1595 | |||
| 1596 | $frame_offset = 0; | ||
| 1597 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1598 | $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1599 | 			$frame_offset = $frame_terminatorpos + strlen("\x00"); | ||
| 1600 | |||
| 1601 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1602 | $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1603 | $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); | ||
| 1604 | 			$frame_offset = $frame_terminatorpos + strlen("\x00"); | ||
| 1605 | |||
| 1606 | $parsedFrame['ownerid'] = $frame_ownerid; | ||
| 1607 | $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); | ||
| 1608 | unset($parsedFrame['data']); | ||
| 1609 | |||
| 1610 | |||
| 1611 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'AENC')) || // 4.19 AENC Audio encryption | ||
| 1612 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'CRA'))) {     // 4.21  CRA  Audio encryption | ||
| 1613 | // There may be more than one 'AENC' frames in a tag, | ||
| 1614 | // but only one with the same 'Owner identifier' | ||
| 1615 | // <Header for 'Audio encryption', ID: 'AENC'> | ||
| 1616 | // Owner identifier <text string> $00 | ||
| 1617 | // Preview start $xx xx | ||
| 1618 | // Preview length $xx xx | ||
| 1619 | // Encryption info <binary data> | ||
| 1620 | |||
| 1621 | $frame_offset = 0; | ||
| 1622 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1623 | $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1624 | 			if (ord($frame_ownerid) === 0) { | ||
| 1625 | $frame_ownerid = ''; | ||
| 1626 | } | ||
| 1627 | 			$frame_offset = $frame_terminatorpos + strlen("\x00"); | ||
| 1628 | $parsedFrame['ownerid'] = $frame_ownerid; | ||
| 1629 | $parsedFrame['previewstart'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); | ||
| 1630 | $frame_offset += 2; | ||
| 1631 | $parsedFrame['previewlength'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); | ||
| 1632 | $frame_offset += 2; | ||
| 1633 | $parsedFrame['encryptioninfo'] = (string) substr($parsedFrame['data'], $frame_offset); | ||
| 1634 | unset($parsedFrame['data']); | ||
| 1635 | |||
| 1636 | |||
| 1637 | } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'LINK')) || // 4.20 LINK Linked information | ||
| 1638 | 				(($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'LNK'))) {    // 4.22  LNK  Linked information | ||
| 1639 | // There may be more than one 'LINK' frame in a tag, | ||
| 1640 | // but only one with the same contents | ||
| 1641 | // <Header for 'Linked information', ID: 'LINK'> | ||
| 1642 | // ID3v2.3+ => Frame identifier $xx xx xx xx | ||
| 1643 | // ID3v2.2 => Frame identifier $xx xx xx | ||
| 1644 | // URL <text string> $00 | ||
| 1645 | // ID and additional data <text string(s)> | ||
| 1646 | |||
| 1647 | $frame_offset = 0; | ||
| 1648 | 			if ($id3v2_majorversion == 2) { | ||
| 1649 | $parsedFrame['frameid'] = substr($parsedFrame['data'], $frame_offset, 3); | ||
| 1650 | $frame_offset += 3; | ||
| 1651 | 			} else { | ||
| 1652 | $parsedFrame['frameid'] = substr($parsedFrame['data'], $frame_offset, 4); | ||
| 1653 | $frame_offset += 4; | ||
| 1654 | } | ||
| 1655 | |||
| 1656 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1657 | $frame_url = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1658 | 			if (ord($frame_url) === 0) { | ||
| 1659 | $frame_url = ''; | ||
| 1660 | } | ||
| 1661 | 			$frame_offset = $frame_terminatorpos + strlen("\x00"); | ||
| 1662 | $parsedFrame['url'] = $frame_url; | ||
| 1663 | |||
| 1664 | $parsedFrame['additionaldata'] = (string) substr($parsedFrame['data'], $frame_offset); | ||
| 1665 | View Code Duplication | 			if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { | |
| 1666 | $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback_iso88591_utf8($parsedFrame['url']); | ||
| 1667 | } | ||
| 1668 | unset($parsedFrame['data']); | ||
| 1669 | |||
| 1670 | |||
| 1671 | 		} elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'POSS')) { // 4.21  POSS Position synchronisation frame (ID3v2.3+ only) | ||
| 1672 | // There may only be one 'POSS' frame in each tag | ||
| 1673 | // <Head for 'Position synchronisation', ID: 'POSS'> | ||
| 1674 | // Time stamp format $xx | ||
| 1675 | // Position $xx (xx ...) | ||
| 1676 | |||
| 1677 | $frame_offset = 0; | ||
| 1678 | $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1679 | $parsedFrame['position'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset)); | ||
| 1680 | unset($parsedFrame['data']); | ||
| 1681 | |||
| 1682 | |||
| 1683 | 		} elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'USER')) { // 4.22  USER Terms of use (ID3v2.3+ only) | ||
| 1684 | // There may be more than one 'Terms of use' frame in a tag, | ||
| 1685 | // but only one with the same 'Language' | ||
| 1686 | // <Header for 'Terms of use frame', ID: 'USER'> | ||
| 1687 | // Text encoding $xx | ||
| 1688 | // Language $xx xx xx | ||
| 1689 | // The actual text <text string according to encoding> | ||
| 1690 | |||
| 1691 | $frame_offset = 0; | ||
| 1692 | $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1693 | 			if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { | ||
| 1694 | 				$this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); | ||
| 1695 | } | ||
| 1696 | $frame_language = substr($parsedFrame['data'], $frame_offset, 3); | ||
| 1697 | $frame_offset += 3; | ||
| 1698 | $parsedFrame['language'] = $frame_language; | ||
| 1699 | $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); | ||
| 1700 | $parsedFrame['encodingid'] = $frame_textencoding; | ||
| 1701 | $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); | ||
| 1702 | |||
| 1703 | $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); | ||
| 1704 | $parsedFrame['data'] = $this->RemoveStringTerminator($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding)); | ||
| 1705 | View Code Duplication | 			if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { | |
| 1706 | $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); | ||
| 1707 | } | ||
| 1708 | unset($parsedFrame['data']); | ||
| 1709 | |||
| 1710 | |||
| 1711 | 		} elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'OWNE')) { // 4.23  OWNE Ownership frame (ID3v2.3+ only) | ||
| 1712 | // There may only be one 'OWNE' frame in a tag | ||
| 1713 | // <Header for 'Ownership frame', ID: 'OWNE'> | ||
| 1714 | // Text encoding $xx | ||
| 1715 | // Price paid <text string> $00 | ||
| 1716 | // Date of purch. <text string> | ||
| 1717 | // Seller <text string according to encoding> | ||
| 1718 | |||
| 1719 | $frame_offset = 0; | ||
| 1720 | $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1721 | 			if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { | ||
| 1722 | 				$this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); | ||
| 1723 | } | ||
| 1724 | $parsedFrame['encodingid'] = $frame_textencoding; | ||
| 1725 | $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); | ||
| 1726 | |||
| 1727 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1728 | $frame_pricepaid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1729 | 			$frame_offset = $frame_terminatorpos + strlen("\x00"); | ||
| 1730 | |||
| 1731 | $parsedFrame['pricepaid']['currencyid'] = substr($frame_pricepaid, 0, 3); | ||
| 1732 | $parsedFrame['pricepaid']['currency'] = $this->LookupCurrencyUnits($parsedFrame['pricepaid']['currencyid']); | ||
| 1733 | $parsedFrame['pricepaid']['value'] = substr($frame_pricepaid, 3); | ||
| 1734 | |||
| 1735 | $parsedFrame['purchasedate'] = substr($parsedFrame['data'], $frame_offset, 8); | ||
| 1736 | 			if ($this->IsValidDateStampString($parsedFrame['purchasedate'])) { | ||
| 1737 | $parsedFrame['purchasedateunix'] = mktime (0, 0, 0, substr($parsedFrame['purchasedate'], 4, 2), substr($parsedFrame['purchasedate'], 6, 2), substr($parsedFrame['purchasedate'], 0, 4)); | ||
| 1738 | } | ||
| 1739 | $frame_offset += 8; | ||
| 1740 | |||
| 1741 | $parsedFrame['seller'] = (string) substr($parsedFrame['data'], $frame_offset); | ||
| 1742 | $parsedFrame['seller'] = $this->RemoveStringTerminator($parsedFrame['seller'], $this->TextEncodingTerminatorLookup($frame_textencoding)); | ||
| 1743 | unset($parsedFrame['data']); | ||
| 1744 | |||
| 1745 | |||
| 1746 | 		} elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'COMR')) { // 4.24  COMR Commercial frame (ID3v2.3+ only) | ||
| 1747 | // There may be more than one 'commercial frame' in a tag, | ||
| 1748 | // but no two may be identical | ||
| 1749 | // <Header for 'Commercial frame', ID: 'COMR'> | ||
| 1750 | // Text encoding $xx | ||
| 1751 | // Price string <text string> $00 | ||
| 1752 | // Valid until <text string> | ||
| 1753 | // Contact URL <text string> $00 | ||
| 1754 | // Received as $xx | ||
| 1755 | // Name of seller <text string according to encoding> $00 (00) | ||
| 1756 | // Description <text string according to encoding> $00 (00) | ||
| 1757 | // Picture MIME type <string> $00 | ||
| 1758 | // Seller logo <binary data> | ||
| 1759 | |||
| 1760 | $frame_offset = 0; | ||
| 1761 | $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1762 | $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); | ||
| 1763 | View Code Duplication | 			if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { | |
| 1764 | 				$this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); | ||
| 1765 | $frame_textencoding_terminator = "\x00"; | ||
| 1766 | } | ||
| 1767 | |||
| 1768 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1769 | $frame_pricestring = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1770 | 			$frame_offset = $frame_terminatorpos + strlen("\x00"); | ||
| 1771 | 			$frame_rawpricearray = explode('/', $frame_pricestring); | ||
| 1772 | 			foreach ($frame_rawpricearray as $key => $val) { | ||
| 1773 | $frame_currencyid = substr($val, 0, 3); | ||
| 1774 | $parsedFrame['price'][$frame_currencyid]['currency'] = $this->LookupCurrencyUnits($frame_currencyid); | ||
| 1775 | $parsedFrame['price'][$frame_currencyid]['value'] = substr($val, 3); | ||
| 1776 | } | ||
| 1777 | |||
| 1778 | $frame_datestring = substr($parsedFrame['data'], $frame_offset, 8); | ||
| 1779 | $frame_offset += 8; | ||
| 1780 | |||
| 1781 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1782 | $frame_contacturl = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1783 | 			$frame_offset = $frame_terminatorpos + strlen("\x00"); | ||
| 1784 | |||
| 1785 | $frame_receivedasid = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1786 | |||
| 1787 | $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); | ||
| 1788 | View Code Duplication | 			if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { | |
| 1789 | $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 | ||
| 1790 | } | ||
| 1791 | $frame_sellername = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1792 | 			if (ord($frame_sellername) === 0) { | ||
| 1793 | $frame_sellername = ''; | ||
| 1794 | } | ||
| 1795 | $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); | ||
| 1796 | |||
| 1797 | $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); | ||
| 1798 | View Code Duplication | 			if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { | |
| 1799 | $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 | ||
| 1800 | } | ||
| 1801 | $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1802 | $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); | ||
| 1803 | $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); | ||
| 1804 | |||
| 1805 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1806 | $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1807 | 			$frame_offset = $frame_terminatorpos + strlen("\x00"); | ||
| 1808 | |||
| 1809 | $frame_sellerlogo = substr($parsedFrame['data'], $frame_offset); | ||
| 1810 | |||
| 1811 | $parsedFrame['encodingid'] = $frame_textencoding; | ||
| 1812 | $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); | ||
| 1813 | |||
| 1814 | $parsedFrame['pricevaliduntil'] = $frame_datestring; | ||
| 1815 | $parsedFrame['contacturl'] = $frame_contacturl; | ||
| 1816 | $parsedFrame['receivedasid'] = $frame_receivedasid; | ||
| 1817 | $parsedFrame['receivedas'] = $this->COMRReceivedAsLookup($frame_receivedasid); | ||
| 1818 | $parsedFrame['sellername'] = $frame_sellername; | ||
| 1819 | $parsedFrame['mime'] = $frame_mimetype; | ||
| 1820 | $parsedFrame['logo'] = $frame_sellerlogo; | ||
| 1821 | unset($parsedFrame['data']); | ||
| 1822 | |||
| 1823 | |||
| 1824 | 		} elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'ENCR')) { // 4.25  ENCR Encryption method registration (ID3v2.3+ only) | ||
| 1825 | // There may be several 'ENCR' frames in a tag, | ||
| 1826 | // but only one containing the same symbol | ||
| 1827 | // and only one containing the same owner identifier | ||
| 1828 | // <Header for 'Encryption method registration', ID: 'ENCR'> | ||
| 1829 | // Owner identifier <text string> $00 | ||
| 1830 | // Method symbol $xx | ||
| 1831 | // Encryption data <binary data> | ||
| 1832 | |||
| 1833 | $frame_offset = 0; | ||
| 1834 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1835 | $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1836 | 			if (ord($frame_ownerid) === 0) { | ||
| 1837 | $frame_ownerid = ''; | ||
| 1838 | } | ||
| 1839 | 			$frame_offset = $frame_terminatorpos + strlen("\x00"); | ||
| 1840 | |||
| 1841 | $parsedFrame['ownerid'] = $frame_ownerid; | ||
| 1842 | $parsedFrame['methodsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1843 | $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); | ||
| 1844 | |||
| 1845 | |||
| 1846 | 		} elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'GRID')) { // 4.26  GRID Group identification registration (ID3v2.3+ only) | ||
| 1847 | |||
| 1848 | // There may be several 'GRID' frames in a tag, | ||
| 1849 | // but only one containing the same symbol | ||
| 1850 | // and only one containing the same owner identifier | ||
| 1851 | // <Header for 'Group ID registration', ID: 'GRID'> | ||
| 1852 | // Owner identifier <text string> $00 | ||
| 1853 | // Group symbol $xx | ||
| 1854 | // Group dependent data <binary data> | ||
| 1855 | |||
| 1856 | $frame_offset = 0; | ||
| 1857 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1858 | $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1859 | 			if (ord($frame_ownerid) === 0) { | ||
| 1860 | $frame_ownerid = ''; | ||
| 1861 | } | ||
| 1862 | 			$frame_offset = $frame_terminatorpos + strlen("\x00"); | ||
| 1863 | |||
| 1864 | $parsedFrame['ownerid'] = $frame_ownerid; | ||
| 1865 | $parsedFrame['groupsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1866 | $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); | ||
| 1867 | |||
| 1868 | |||
| 1869 | 		} elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'PRIV')) { // 4.27  PRIV Private frame (ID3v2.3+ only) | ||
| 1870 | // The tag may contain more than one 'PRIV' frame | ||
| 1871 | // but only with different contents | ||
| 1872 | // <Header for 'Private frame', ID: 'PRIV'> | ||
| 1873 | // Owner identifier <text string> $00 | ||
| 1874 | // The private data <binary data> | ||
| 1875 | |||
| 1876 | $frame_offset = 0; | ||
| 1877 | $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 1878 | $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); | ||
| 1879 | 			if (ord($frame_ownerid) === 0) { | ||
| 1880 | $frame_ownerid = ''; | ||
| 1881 | } | ||
| 1882 | 			$frame_offset = $frame_terminatorpos + strlen("\x00"); | ||
| 1883 | |||
| 1884 | $parsedFrame['ownerid'] = $frame_ownerid; | ||
| 1885 | $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); | ||
| 1886 | |||
| 1887 | |||
| 1888 | 		} elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'SIGN')) { // 4.28  SIGN Signature frame (ID3v2.4+ only) | ||
| 1889 | // There may be more than one 'signature frame' in a tag, | ||
| 1890 | // but no two may be identical | ||
| 1891 | // <Header for 'Signature frame', ID: 'SIGN'> | ||
| 1892 | // Group symbol $xx | ||
| 1893 | // Signature <binary data> | ||
| 1894 | |||
| 1895 | $frame_offset = 0; | ||
| 1896 | $parsedFrame['groupsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1897 | $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); | ||
| 1898 | |||
| 1899 | |||
| 1900 | 		} elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'SEEK')) { // 4.29  SEEK Seek frame (ID3v2.4+ only) | ||
| 1901 | // There may only be one 'seek frame' in a tag | ||
| 1902 | // <Header for 'Seek frame', ID: 'SEEK'> | ||
| 1903 | // Minimum offset to next tag $xx xx xx xx | ||
| 1904 | |||
| 1905 | $frame_offset = 0; | ||
| 1906 | $parsedFrame['data'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); | ||
| 1907 | |||
| 1908 | |||
| 1909 | 		} elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'ASPI')) { // 4.30  ASPI Audio seek point index (ID3v2.4+ only) | ||
| 1910 | // There may only be one 'audio seek point index' frame in a tag | ||
| 1911 | // <Header for 'Seek Point Index', ID: 'ASPI'> | ||
| 1912 | // Indexed data start (S) $xx xx xx xx | ||
| 1913 | // Indexed data length (L) $xx xx xx xx | ||
| 1914 | // Number of index points (N) $xx xx | ||
| 1915 | // Bits per index point (b) $xx | ||
| 1916 | // Then for every index point the following data is included: | ||
| 1917 | // Fraction at index (Fi) $xx (xx) | ||
| 1918 | |||
| 1919 | $frame_offset = 0; | ||
| 1920 | $parsedFrame['datastart'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); | ||
| 1921 | $frame_offset += 4; | ||
| 1922 | $parsedFrame['indexeddatalength'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); | ||
| 1923 | $frame_offset += 4; | ||
| 1924 | $parsedFrame['indexpoints'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); | ||
| 1925 | $frame_offset += 2; | ||
| 1926 | $parsedFrame['bitsperpoint'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); | ||
| 1927 | $frame_bytesperpoint = ceil($parsedFrame['bitsperpoint'] / 8); | ||
| 1928 | 			for ($i = 0; $i < $parsedFrame['indexpoints']; $i++) { | ||
| 1929 | $parsedFrame['indexes'][$i] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesperpoint)); | ||
| 1930 | $frame_offset += $frame_bytesperpoint; | ||
| 1931 | } | ||
| 1932 | unset($parsedFrame['data']); | ||
| 1933 | |||
| 1934 | 		} elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'RGAD')) { // Replay Gain Adjustment | ||
| 1935 | // http://privatewww.essex.ac.uk/~djmrob/replaygain/file_format_id3v2.html | ||
| 1936 | // There may only be one 'RGAD' frame in a tag | ||
| 1937 | // <Header for 'Replay Gain Adjustment', ID: 'RGAD'> | ||
| 1938 | // Peak Amplitude $xx $xx $xx $xx | ||
| 1939 | // Radio Replay Gain Adjustment %aaabbbcd %dddddddd | ||
| 1940 | // Audiophile Replay Gain Adjustment %aaabbbcd %dddddddd | ||
| 1941 | // a - name code | ||
| 1942 | // b - originator code | ||
| 1943 | // c - sign bit | ||
| 1944 | // d - replay gain adjustment | ||
| 1945 | |||
| 1946 | $frame_offset = 0; | ||
| 1947 | $parsedFrame['peakamplitude'] = getid3_lib::BigEndian2Float(substr($parsedFrame['data'], $frame_offset, 4)); | ||
| 1948 | $frame_offset += 4; | ||
| 1949 | $rg_track_adjustment = getid3_lib::Dec2Bin(substr($parsedFrame['data'], $frame_offset, 2)); | ||
| 1950 | $frame_offset += 2; | ||
| 1951 | $rg_album_adjustment = getid3_lib::Dec2Bin(substr($parsedFrame['data'], $frame_offset, 2)); | ||
| 1952 | $frame_offset += 2; | ||
| 1953 | $parsedFrame['raw']['track']['name'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 0, 3)); | ||
| 1954 | $parsedFrame['raw']['track']['originator'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 3, 3)); | ||
| 1955 | $parsedFrame['raw']['track']['signbit'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 6, 1)); | ||
| 1956 | $parsedFrame['raw']['track']['adjustment'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 7, 9)); | ||
| 1957 | $parsedFrame['raw']['album']['name'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 0, 3)); | ||
| 1958 | $parsedFrame['raw']['album']['originator'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 3, 3)); | ||
| 1959 | $parsedFrame['raw']['album']['signbit'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 6, 1)); | ||
| 1960 | $parsedFrame['raw']['album']['adjustment'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 7, 9)); | ||
| 1961 | $parsedFrame['track']['name'] = getid3_lib::RGADnameLookup($parsedFrame['raw']['track']['name']); | ||
| 1962 | $parsedFrame['track']['originator'] = getid3_lib::RGADoriginatorLookup($parsedFrame['raw']['track']['originator']); | ||
| 1963 | $parsedFrame['track']['adjustment'] = getid3_lib::RGADadjustmentLookup($parsedFrame['raw']['track']['adjustment'], $parsedFrame['raw']['track']['signbit']); | ||
| 1964 | $parsedFrame['album']['name'] = getid3_lib::RGADnameLookup($parsedFrame['raw']['album']['name']); | ||
| 1965 | $parsedFrame['album']['originator'] = getid3_lib::RGADoriginatorLookup($parsedFrame['raw']['album']['originator']); | ||
| 1966 | $parsedFrame['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($parsedFrame['raw']['album']['adjustment'], $parsedFrame['raw']['album']['signbit']); | ||
| 1967 | |||
| 1968 | $info['replay_gain']['track']['peak'] = $parsedFrame['peakamplitude']; | ||
| 1969 | $info['replay_gain']['track']['originator'] = $parsedFrame['track']['originator']; | ||
| 1970 | $info['replay_gain']['track']['adjustment'] = $parsedFrame['track']['adjustment']; | ||
| 1971 | $info['replay_gain']['album']['originator'] = $parsedFrame['album']['originator']; | ||
| 1972 | $info['replay_gain']['album']['adjustment'] = $parsedFrame['album']['adjustment']; | ||
| 1973 | |||
| 1974 | unset($parsedFrame['data']); | ||
| 1975 | |||
| 1976 | 		} elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'CHAP')) { // CHAP Chapters frame (ID3v2.3+ only) | ||
| 1977 | // http://id3.org/id3v2-chapters-1.0 | ||
| 1978 | // <ID3v2.3 or ID3v2.4 frame header, ID: "CHAP"> (10 bytes) | ||
| 1979 | // Element ID <text string> $00 | ||
| 1980 | // Start time $xx xx xx xx | ||
| 1981 | // End time $xx xx xx xx | ||
| 1982 | // Start offset $xx xx xx xx | ||
| 1983 | // End offset $xx xx xx xx | ||
| 1984 | // <Optional embedded sub-frames> | ||
| 1985 | |||
| 1986 | $frame_offset = 0; | ||
| 1987 | 			@list($parsedFrame['element_id']) = explode("\x00", $parsedFrame['data'], 2); | ||
| 1988 | $frame_offset += strlen($parsedFrame['element_id']."\x00"); | ||
| 1989 | $parsedFrame['time_begin'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); | ||
| 1990 | $frame_offset += 4; | ||
| 1991 | $parsedFrame['time_end'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); | ||
| 1992 | $frame_offset += 4; | ||
| 1993 | View Code Duplication | 			if (substr($parsedFrame['data'], $frame_offset, 4) != "\xFF\xFF\xFF\xFF") { | |
| 1994 | // "If these bytes are all set to 0xFF then the value should be ignored and the start time value should be utilized." | ||
| 1995 | $parsedFrame['offset_begin'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); | ||
| 1996 | } | ||
| 1997 | $frame_offset += 4; | ||
| 1998 | View Code Duplication | 			if (substr($parsedFrame['data'], $frame_offset, 4) != "\xFF\xFF\xFF\xFF") { | |
| 1999 | // "If these bytes are all set to 0xFF then the value should be ignored and the start time value should be utilized." | ||
| 2000 | $parsedFrame['offset_end'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); | ||
| 2001 | } | ||
| 2002 | $frame_offset += 4; | ||
| 2003 | |||
| 2004 | 			if ($frame_offset < strlen($parsedFrame['data'])) { | ||
| 2005 | $parsedFrame['subframes'] = array(); | ||
| 2006 | 				while ($frame_offset < strlen($parsedFrame['data'])) { | ||
| 2007 | // <Optional embedded sub-frames> | ||
| 2008 | $subframe = array(); | ||
| 2009 | $subframe['name'] = substr($parsedFrame['data'], $frame_offset, 4); | ||
| 2010 | $frame_offset += 4; | ||
| 2011 | $subframe['size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); | ||
| 2012 | $frame_offset += 4; | ||
| 2013 | $subframe['flags_raw'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); | ||
| 2014 | $frame_offset += 2; | ||
| 2015 | View Code Duplication | 					if ($subframe['size'] > (strlen($parsedFrame['data']) - $frame_offset)) { | |
| 2016 | 						$this->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)'); | ||
| 2017 | break; | ||
| 2018 | } | ||
| 2019 | $subframe_rawdata = substr($parsedFrame['data'], $frame_offset, $subframe['size']); | ||
| 2020 | $frame_offset += $subframe['size']; | ||
| 2021 | |||
| 2022 | $subframe['encodingid'] = ord(substr($subframe_rawdata, 0, 1)); | ||
| 2023 | $subframe['text'] = substr($subframe_rawdata, 1); | ||
| 2024 | $subframe['encoding'] = $this->TextEncodingNameLookup($subframe['encodingid']); | ||
| 2025 | $encoding_converted_text = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe['text'])); | ||
| 2026 | View Code Duplication | 					switch (substr($encoding_converted_text, 0, 2)) { | |
| 2027 | case "\xFF\xFE": | ||
| 2028 | case "\xFE\xFF": | ||
| 2029 | 							switch (strtoupper($info['id3v2']['encoding'])) { | ||
| 2030 | case 'ISO-8859-1': | ||
| 2031 | case 'UTF-8': | ||
| 2032 | $encoding_converted_text = substr($encoding_converted_text, 2); | ||
| 2033 | // remove unwanted byte-order-marks | ||
| 2034 | break; | ||
| 2035 | default: | ||
| 2036 | // ignore | ||
| 2037 | break; | ||
| 2038 | } | ||
| 2039 | break; | ||
| 2040 | default: | ||
| 2041 | // do not remove BOM | ||
| 2042 | break; | ||
| 2043 | } | ||
| 2044 | |||
| 2045 | 					switch ($subframe['name']) { | ||
| 2046 | case 'TIT2': | ||
| 2047 | $parsedFrame['chapter_name'] = $encoding_converted_text; | ||
| 2048 | $parsedFrame['subframes'][] = $subframe; | ||
| 2049 | break; | ||
| 2050 | case 'TIT3': | ||
| 2051 | $parsedFrame['chapter_description'] = $encoding_converted_text; | ||
| 2052 | $parsedFrame['subframes'][] = $subframe; | ||
| 2053 | break; | ||
| 2054 | case 'WXXX': | ||
| 2055 | 							list($subframe['chapter_url_description'], $subframe['chapter_url']) = explode("\x00", $encoding_converted_text, 2); | ||
| 2056 | $parsedFrame['chapter_url'][$subframe['chapter_url_description']] = $subframe['chapter_url']; | ||
| 2057 | $parsedFrame['subframes'][] = $subframe; | ||
| 2058 | break; | ||
| 2059 | case 'APIC': | ||
| 2060 | 							if (preg_match('#^([^\\x00]+)*\\x00(.)([^\\x00]+)*\\x00(.+)$#s', $subframe['text'], $matches)) { | ||
| 2061 | list($dummy, $subframe_apic_mime, $subframe_apic_picturetype, $subframe_apic_description, $subframe_apic_picturedata) = $matches; | ||
| 2062 | $subframe['image_mime'] = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe_apic_mime)); | ||
| 2063 | $subframe['picture_type'] = $this->APICPictureTypeLookup($subframe_apic_picturetype); | ||
| 2064 | $subframe['description'] = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe_apic_description)); | ||
| 2065 | 								if (strlen($this->TextEncodingTerminatorLookup($subframe['encoding'])) == 2) { | ||
| 2066 | // the null terminator between "description" and "picture data" could be either 1 byte (ISO-8859-1, UTF-8) or two bytes (UTF-16) | ||
| 2067 | // the above regex assumes one byte, if it's actually two then strip the second one here | ||
| 2068 | $subframe_apic_picturedata = substr($subframe_apic_picturedata, 1); | ||
| 2069 | } | ||
| 2070 | $subframe['data'] = $subframe_apic_picturedata; | ||
| 2071 | unset($dummy, $subframe_apic_mime, $subframe_apic_picturetype, $subframe_apic_description, $subframe_apic_picturedata); | ||
| 2072 | unset($subframe['text'], $parsedFrame['text']); | ||
| 2073 | $parsedFrame['subframes'][] = $subframe; | ||
| 2074 | $parsedFrame['picture_present'] = true; | ||
| 2075 | 							} else { | ||
| 2076 | 								$this->warning('ID3v2.CHAP subframe #'.(count($parsedFrame['subframes']) + 1).' "'.$subframe['name'].'" not in expected format'); | ||
| 2077 | } | ||
| 2078 | break; | ||
| 2079 | default: | ||
| 2080 | 							$this->warning('ID3v2.CHAP subframe "'.$subframe['name'].'" not handled (supported: TIT2, TIT3, WXXX, APIC)'); | ||
| 2081 | break; | ||
| 2082 | } | ||
| 2083 | } | ||
| 2084 | unset($subframe_rawdata, $subframe, $encoding_converted_text); | ||
| 2085 | unset($parsedFrame['data']); // debatable whether this this be here, without it the returned structure may contain a large amount of duplicate data if chapters contain APIC | ||
| 2086 | } | ||
| 2087 | |||
| 2088 | $id3v2_chapter_entry = array(); | ||
| 2089 | 			foreach (array('id', 'time_begin', 'time_end', 'offset_begin', 'offset_end', 'chapter_name', 'chapter_description', 'chapter_url', 'picture_present') as $id3v2_chapter_key) { | ||
| 2090 | 				if (isset($parsedFrame[$id3v2_chapter_key])) { | ||
| 2091 | $id3v2_chapter_entry[$id3v2_chapter_key] = $parsedFrame[$id3v2_chapter_key]; | ||
| 2092 | } | ||
| 2093 | } | ||
| 2094 | 			if (!isset($info['id3v2']['chapters'])) { | ||
| 2095 | $info['id3v2']['chapters'] = array(); | ||
| 2096 | } | ||
| 2097 | $info['id3v2']['chapters'][] = $id3v2_chapter_entry; | ||
| 2098 | unset($id3v2_chapter_entry, $id3v2_chapter_key); | ||
| 2099 | |||
| 2100 | |||
| 2101 | 		} elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'CTOC')) { // CTOC Chapters Table Of Contents frame (ID3v2.3+ only) | ||
| 2102 | // http://id3.org/id3v2-chapters-1.0 | ||
| 2103 | // <ID3v2.3 or ID3v2.4 frame header, ID: "CTOC"> (10 bytes) | ||
| 2104 | // Element ID <text string> $00 | ||
| 2105 | // CTOC flags %xx | ||
| 2106 | // Entry count $xx | ||
| 2107 | // Child Element ID <string>$00 /* zero or more child CHAP or CTOC entries */ | ||
| 2108 | // <Optional embedded sub-frames> | ||
| 2109 | |||
| 2110 | $frame_offset = 0; | ||
| 2111 | 			@list($parsedFrame['element_id']) = explode("\x00", $parsedFrame['data'], 2); | ||
| 2112 | $frame_offset += strlen($parsedFrame['element_id']."\x00"); | ||
| 2113 | $ctoc_flags_raw = ord(substr($parsedFrame['data'], $frame_offset, 1)); | ||
| 2114 | $frame_offset += 1; | ||
| 2115 | $parsedFrame['entry_count'] = ord(substr($parsedFrame['data'], $frame_offset, 1)); | ||
| 2116 | $frame_offset += 1; | ||
| 2117 | |||
| 2118 | $terminator_position = null; | ||
| 2119 | 			for ($i = 0; $i < $parsedFrame['entry_count']; $i++) { | ||
| 2120 | $terminator_position = strpos($parsedFrame['data'], "\x00", $frame_offset); | ||
| 2121 | $parsedFrame['child_element_ids'][$i] = substr($parsedFrame['data'], $frame_offset, $terminator_position - $frame_offset); | ||
| 2122 | $frame_offset = $terminator_position + 1; | ||
| 2123 | } | ||
| 2124 | |||
| 2125 | $parsedFrame['ctoc_flags']['ordered'] = (bool) ($ctoc_flags_raw & 0x01); | ||
| 2126 | $parsedFrame['ctoc_flags']['top_level'] = (bool) ($ctoc_flags_raw & 0x03); | ||
| 2127 | |||
| 2128 | unset($ctoc_flags_raw, $terminator_position); | ||
| 2129 | |||
| 2130 | 			if ($frame_offset < strlen($parsedFrame['data'])) { | ||
| 2131 | $parsedFrame['subframes'] = array(); | ||
| 2132 | 				while ($frame_offset < strlen($parsedFrame['data'])) { | ||
| 2133 | // <Optional embedded sub-frames> | ||
| 2134 | $subframe = array(); | ||
| 2135 | $subframe['name'] = substr($parsedFrame['data'], $frame_offset, 4); | ||
| 2136 | $frame_offset += 4; | ||
| 2137 | $subframe['size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); | ||
| 2138 | $frame_offset += 4; | ||
| 2139 | $subframe['flags_raw'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); | ||
| 2140 | $frame_offset += 2; | ||
| 2141 | View Code Duplication | 					if ($subframe['size'] > (strlen($parsedFrame['data']) - $frame_offset)) { | |
| 2142 | 						$this->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)'); | ||
| 2143 | break; | ||
| 2144 | } | ||
| 2145 | $subframe_rawdata = substr($parsedFrame['data'], $frame_offset, $subframe['size']); | ||
| 2146 | $frame_offset += $subframe['size']; | ||
| 2147 | |||
| 2148 | $subframe['encodingid'] = ord(substr($subframe_rawdata, 0, 1)); | ||
| 2149 | $subframe['text'] = substr($subframe_rawdata, 1); | ||
| 2150 | $subframe['encoding'] = $this->TextEncodingNameLookup($subframe['encodingid']); | ||
| 2151 | $encoding_converted_text = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe['text']));; | ||
| 2152 | View Code Duplication | 					switch (substr($encoding_converted_text, 0, 2)) { | |
| 2153 | case "\xFF\xFE": | ||
| 2154 | case "\xFE\xFF": | ||
| 2155 | 							switch (strtoupper($info['id3v2']['encoding'])) { | ||
| 2156 | case 'ISO-8859-1': | ||
| 2157 | case 'UTF-8': | ||
| 2158 | $encoding_converted_text = substr($encoding_converted_text, 2); | ||
| 2159 | // remove unwanted byte-order-marks | ||
| 2160 | break; | ||
| 2161 | default: | ||
| 2162 | // ignore | ||
| 2163 | break; | ||
| 2164 | } | ||
| 2165 | break; | ||
| 2166 | default: | ||
| 2167 | // do not remove BOM | ||
| 2168 | break; | ||
| 2169 | } | ||
| 2170 | |||
| 2171 | 					if (($subframe['name'] == 'TIT2') || ($subframe['name'] == 'TIT3')) { | ||
| 2172 | 						if ($subframe['name'] == 'TIT2') { | ||
| 2173 | $parsedFrame['toc_name'] = $encoding_converted_text; | ||
| 2174 | 						} elseif ($subframe['name'] == 'TIT3') { | ||
| 2175 | $parsedFrame['toc_description'] = $encoding_converted_text; | ||
| 2176 | } | ||
| 2177 | $parsedFrame['subframes'][] = $subframe; | ||
| 2178 | 					} else { | ||
| 2179 | 						$this->warning('ID3v2.CTOC subframe "'.$subframe['name'].'" not handled (only TIT2 and TIT3)'); | ||
| 2180 | } | ||
| 2181 | } | ||
| 2182 | unset($subframe_rawdata, $subframe, $encoding_converted_text); | ||
| 2183 | } | ||
| 2184 | |||
| 2185 | } | ||
| 2186 | |||
| 2187 | return true; | ||
| 2188 | } | ||
| 2189 | |||
| 3890 | 
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: