write.id3v2.php 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at http://getid3.sourceforge.net //
  5. // or http://www.getid3.org //
  6. // also https://github.com/JamesHeinrich/getID3 //
  7. /////////////////////////////////////////////////////////////////
  8. // See readme.txt for more details //
  9. /////////////////////////////////////////////////////////////////
  10. /// //
  11. // write.id3v2.php //
  12. // module for writing ID3v2 tags //
  13. // dependencies: module.tag.id3v2.php //
  14. // ///
  15. /////////////////////////////////////////////////////////////////
  16. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
  17. class getid3_write_id3v2
  18. {
  19. public $filename;
  20. public $tag_data;
  21. public $fread_buffer_size = 32768; // read buffer size in bytes
  22. public $paddedlength = 4096; // minimum length of ID3v2 tag in bytes
  23. public $majorversion = 3; // ID3v2 major version (2, 3 (recommended), 4)
  24. public $minorversion = 0; // ID3v2 minor version - always 0
  25. public $merge_existing_data = false; // if true, merge new data with existing tags; if false, delete old tag data and only write new tags
  26. public $id3v2_default_encodingid = 0; // default text encoding (ISO-8859-1) if not explicitly passed
  27. public $id3v2_use_unsynchronisation = false; // the specs say it should be TRUE, but most other ID3v2-aware programs are broken if unsynchronization is used, so by default don't use it.
  28. public $warnings = array(); // any non-critical errors will be stored here
  29. public $errors = array(); // any critical errors will be stored here
  30. public function __construct() {
  31. return true;
  32. }
  33. public function WriteID3v2() {
  34. // File MUST be writeable - CHMOD(646) at least. It's best if the
  35. // directory is also writeable, because that method is both faster and less susceptible to errors.
  36. if (!empty($this->filename) && (is_writeable($this->filename) || (!file_exists($this->filename) && is_writeable(dirname($this->filename))))) {
  37. // Initialize getID3 engine
  38. $getID3 = new getID3;
  39. $OldThisFileInfo = $getID3->analyze($this->filename);
  40. if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) {
  41. $this->errors[] = 'Unable to write ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
  42. fclose($fp_source);
  43. return false;
  44. }
  45. if ($this->merge_existing_data) {
  46. // merge with existing data
  47. if (!empty($OldThisFileInfo['id3v2'])) {
  48. $this->tag_data = $this->array_join_merge($OldThisFileInfo['id3v2'], $this->tag_data);
  49. }
  50. }
  51. $this->paddedlength = (isset($OldThisFileInfo['id3v2']['headerlength']) ? max($OldThisFileInfo['id3v2']['headerlength'], $this->paddedlength) : $this->paddedlength);
  52. if ($NewID3v2Tag = $this->GenerateID3v2Tag()) {
  53. if (file_exists($this->filename) && is_writeable($this->filename) && isset($OldThisFileInfo['id3v2']['headerlength']) && ($OldThisFileInfo['id3v2']['headerlength'] == strlen($NewID3v2Tag))) {
  54. // best and fastest method - insert-overwrite existing tag (padded to length of old tag if neccesary)
  55. if (file_exists($this->filename)) {
  56. if (is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'r+b'))) {
  57. rewind($fp);
  58. fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag));
  59. fclose($fp);
  60. } else {
  61. $this->errors[] = 'Could not fopen("'.$this->filename.'", "r+b")';
  62. }
  63. } else {
  64. if (is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'wb'))) {
  65. rewind($fp);
  66. fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag));
  67. fclose($fp);
  68. } else {
  69. $this->errors[] = 'Could not fopen("'.$this->filename.'", "wb")';
  70. }
  71. }
  72. } else {
  73. if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) {
  74. if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) {
  75. if (is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) {
  76. fwrite($fp_temp, $NewID3v2Tag, strlen($NewID3v2Tag));
  77. rewind($fp_source);
  78. if (!empty($OldThisFileInfo['avdataoffset'])) {
  79. fseek($fp_source, $OldThisFileInfo['avdataoffset']);
  80. }
  81. while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
  82. fwrite($fp_temp, $buffer, strlen($buffer));
  83. }
  84. fclose($fp_temp);
  85. fclose($fp_source);
  86. copy($tempfilename, $this->filename);
  87. unlink($tempfilename);
  88. return true;
  89. } else {
  90. $this->errors[] = 'Could not fopen("'.$tempfilename.'", "wb")';
  91. }
  92. fclose($fp_source);
  93. } else {
  94. $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")';
  95. }
  96. }
  97. return false;
  98. }
  99. } else {
  100. $this->errors[] = '$this->GenerateID3v2Tag() failed';
  101. }
  102. if (!empty($this->errors)) {
  103. return false;
  104. }
  105. return true;
  106. } else {
  107. $this->errors[] = 'WriteID3v2() failed: !is_writeable('.$this->filename.')';
  108. }
  109. return false;
  110. }
  111. public function RemoveID3v2() {
  112. // File MUST be writeable - CHMOD(646) at least. It's best if the
  113. // directory is also writeable, because that method is both faster and less susceptible to errors.
  114. if (is_writeable(dirname($this->filename))) {
  115. // preferred method - only one copying operation, minimal chance of corrupting
  116. // original file if script is interrupted, but required directory to be writeable
  117. if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) {
  118. // Initialize getID3 engine
  119. $getID3 = new getID3;
  120. $OldThisFileInfo = $getID3->analyze($this->filename);
  121. if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) {
  122. $this->errors[] = 'Unable to remove ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
  123. fclose($fp_source);
  124. return false;
  125. }
  126. rewind($fp_source);
  127. if ($OldThisFileInfo['avdataoffset'] !== false) {
  128. fseek($fp_source, $OldThisFileInfo['avdataoffset']);
  129. }
  130. if (is_writable($this->filename) && is_file($this->filename) && ($fp_temp = fopen($this->filename.'getid3tmp', 'w+b'))) {
  131. while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
  132. fwrite($fp_temp, $buffer, strlen($buffer));
  133. }
  134. fclose($fp_temp);
  135. } else {
  136. $this->errors[] = 'Could not fopen("'.$this->filename.'getid3tmp", "w+b")';
  137. }
  138. fclose($fp_source);
  139. } else {
  140. $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")';
  141. }
  142. if (file_exists($this->filename)) {
  143. unlink($this->filename);
  144. }
  145. rename($this->filename.'getid3tmp', $this->filename);
  146. } elseif (is_writable($this->filename)) {
  147. // less desirable alternate method - double-copies the file, overwrites original file
  148. // and could corrupt source file if the script is interrupted or an error occurs.
  149. if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) {
  150. // Initialize getID3 engine
  151. $getID3 = new getID3;
  152. $OldThisFileInfo = $getID3->analyze($this->filename);
  153. if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) {
  154. $this->errors[] = 'Unable to remove ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
  155. fclose($fp_source);
  156. return false;
  157. }
  158. rewind($fp_source);
  159. if ($OldThisFileInfo['avdataoffset'] !== false) {
  160. fseek($fp_source, $OldThisFileInfo['avdataoffset']);
  161. }
  162. if ($fp_temp = tmpfile()) {
  163. while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
  164. fwrite($fp_temp, $buffer, strlen($buffer));
  165. }
  166. fclose($fp_source);
  167. if (is_writable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'wb'))) {
  168. rewind($fp_temp);
  169. while ($buffer = fread($fp_temp, $this->fread_buffer_size)) {
  170. fwrite($fp_source, $buffer, strlen($buffer));
  171. }
  172. fseek($fp_temp, -128, SEEK_END);
  173. fclose($fp_source);
  174. } else {
  175. $this->errors[] = 'Could not fopen("'.$this->filename.'", "wb")';
  176. }
  177. fclose($fp_temp);
  178. } else {
  179. $this->errors[] = 'Could not create tmpfile()';
  180. }
  181. } else {
  182. $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")';
  183. }
  184. } else {
  185. $this->errors[] = 'Directory and file both not writeable';
  186. }
  187. if (!empty($this->errors)) {
  188. return false;
  189. }
  190. return true;
  191. }
  192. public function GenerateID3v2TagFlags($flags) {
  193. switch ($this->majorversion) {
  194. case 4:
  195. // %abcd0000
  196. $flag = (!empty($flags['unsynchronisation']) ? '1' : '0'); // a - Unsynchronisation
  197. $flag .= (!empty($flags['extendedheader'] ) ? '1' : '0'); // b - Extended header
  198. $flag .= (!empty($flags['experimental'] ) ? '1' : '0'); // c - Experimental indicator
  199. $flag .= (!empty($flags['footer'] ) ? '1' : '0'); // d - Footer present
  200. $flag .= '0000';
  201. break;
  202. case 3:
  203. // %abc00000
  204. $flag = (!empty($flags['unsynchronisation']) ? '1' : '0'); // a - Unsynchronisation
  205. $flag .= (!empty($flags['extendedheader'] ) ? '1' : '0'); // b - Extended header
  206. $flag .= (!empty($flags['experimental'] ) ? '1' : '0'); // c - Experimental indicator
  207. $flag .= '00000';
  208. break;
  209. case 2:
  210. // %ab000000
  211. $flag = (!empty($flags['unsynchronisation']) ? '1' : '0'); // a - Unsynchronisation
  212. $flag .= (!empty($flags['compression'] ) ? '1' : '0'); // b - Compression
  213. $flag .= '000000';
  214. break;
  215. default:
  216. return false;
  217. break;
  218. }
  219. return chr(bindec($flag));
  220. }
  221. public function GenerateID3v2FrameFlags($TagAlter=false, $FileAlter=false, $ReadOnly=false, $Compression=false, $Encryption=false, $GroupingIdentity=false, $Unsynchronisation=false, $DataLengthIndicator=false) {
  222. switch ($this->majorversion) {
  223. case 4:
  224. // %0abc0000 %0h00kmnp
  225. $flag1 = '0';
  226. $flag1 .= $TagAlter ? '1' : '0'; // a - Tag alter preservation (true == discard)
  227. $flag1 .= $FileAlter ? '1' : '0'; // b - File alter preservation (true == discard)
  228. $flag1 .= $ReadOnly ? '1' : '0'; // c - Read only (true == read only)
  229. $flag1 .= '0000';
  230. $flag2 = '0';
  231. $flag2 .= $GroupingIdentity ? '1' : '0'; // h - Grouping identity (true == contains group information)
  232. $flag2 .= '00';
  233. $flag2 .= $Compression ? '1' : '0'; // k - Compression (true == compressed)
  234. $flag2 .= $Encryption ? '1' : '0'; // m - Encryption (true == encrypted)
  235. $flag2 .= $Unsynchronisation ? '1' : '0'; // n - Unsynchronisation (true == unsynchronised)
  236. $flag2 .= $DataLengthIndicator ? '1' : '0'; // p - Data length indicator (true == data length indicator added)
  237. break;
  238. case 3:
  239. // %abc00000 %ijk00000
  240. $flag1 = $TagAlter ? '1' : '0'; // a - Tag alter preservation (true == discard)
  241. $flag1 .= $FileAlter ? '1' : '0'; // b - File alter preservation (true == discard)
  242. $flag1 .= $ReadOnly ? '1' : '0'; // c - Read only (true == read only)
  243. $flag1 .= '00000';
  244. $flag2 = $Compression ? '1' : '0'; // i - Compression (true == compressed)
  245. $flag2 .= $Encryption ? '1' : '0'; // j - Encryption (true == encrypted)
  246. $flag2 .= $GroupingIdentity ? '1' : '0'; // k - Grouping identity (true == contains group information)
  247. $flag2 .= '00000';
  248. break;
  249. default:
  250. return false;
  251. break;
  252. }
  253. return chr(bindec($flag1)).chr(bindec($flag2));
  254. }
  255. public function GenerateID3v2FrameData($frame_name, $source_data_array) {
  256. if (!getid3_id3v2::IsValidID3v2FrameName($frame_name, $this->majorversion)) {
  257. return false;
  258. }
  259. $framedata = '';
  260. if (($this->majorversion < 3) || ($this->majorversion > 4)) {
  261. $this->errors[] = 'Only ID3v2.3 and ID3v2.4 are supported in GenerateID3v2FrameData()';
  262. } else { // $this->majorversion 3 or 4
  263. switch ($frame_name) {
  264. case 'UFID':
  265. // 4.1 UFID Unique file identifier
  266. // Owner identifier <text string> $00
  267. // Identifier <up to 64 bytes binary data>
  268. if (strlen($source_data_array['data']) > 64) {
  269. $this->errors[] = 'Identifier not allowed to be longer than 64 bytes in '.$frame_name.' (supplied data was '.strlen($source_data_array['data']).' bytes long)';
  270. } else {
  271. $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
  272. $framedata .= substr($source_data_array['data'], 0, 64); // max 64 bytes - truncate anything longer
  273. }
  274. break;
  275. case 'TXXX':
  276. // 4.2.2 TXXX User defined text information frame
  277. // Text encoding $xx
  278. // Description <text string according to encoding> $00 (00)
  279. // Value <text string according to encoding>
  280. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  281. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) {
  282. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  283. } else {
  284. $framedata .= chr($source_data_array['encodingid']);
  285. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  286. $framedata .= $source_data_array['data'];
  287. }
  288. break;
  289. case 'WXXX':
  290. // 4.3.2 WXXX User defined URL link frame
  291. // Text encoding $xx
  292. // Description <text string according to encoding> $00 (00)
  293. // URL <text string>
  294. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  295. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) {
  296. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  297. } elseif (!isset($source_data_array['data']) || !$this->IsValidURL($source_data_array['data'], false, false)) {
  298. //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  299. // probably should be an error, need to rewrite IsValidURL() to handle other encodings
  300. $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  301. } else {
  302. $framedata .= chr($source_data_array['encodingid']);
  303. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  304. $framedata .= $source_data_array['data'];
  305. }
  306. break;
  307. case 'IPLS':
  308. // 4.4 IPLS Involved people list (ID3v2.3 only)
  309. // Text encoding $xx
  310. // People list strings <textstrings>
  311. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  312. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) {
  313. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  314. } else {
  315. $framedata .= chr($source_data_array['encodingid']);
  316. $framedata .= $source_data_array['data'];
  317. }
  318. break;
  319. case 'MCDI':
  320. // 4.4 MCDI Music CD identifier
  321. // CD TOC <binary data>
  322. $framedata .= $source_data_array['data'];
  323. break;
  324. case 'ETCO':
  325. // 4.5 ETCO Event timing codes
  326. // Time stamp format $xx
  327. // Where time stamp format is:
  328. // $01 (32-bit value) MPEG frames from beginning of file
  329. // $02 (32-bit value) milliseconds from beginning of file
  330. // Followed by a list of key events in the following format:
  331. // Type of event $xx
  332. // Time stamp $xx (xx ...)
  333. // The 'Time stamp' is set to zero if directly at the beginning of the sound
  334. // or after the previous event. All events MUST be sorted in chronological order.
  335. if (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) {
  336. $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
  337. } else {
  338. $framedata .= chr($source_data_array['timestampformat']);
  339. foreach ($source_data_array as $key => $val) {
  340. if (!$this->ID3v2IsValidETCOevent($val['typeid'])) {
  341. $this->errors[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')';
  342. } elseif (($key != 'timestampformat') && ($key != 'flags')) {
  343. if (($val['timestamp'] > 0) && ($previousETCOtimestamp >= $val['timestamp'])) {
  344. // The 'Time stamp' is set to zero if directly at the beginning of the sound
  345. // or after the previous event. All events MUST be sorted in chronological order.
  346. $this->errors[] = 'Out-of-order timestamp in '.$frame_name.' ('.$val['timestamp'].') for Event Type ('.$val['typeid'].')';
  347. } else {
  348. $framedata .= chr($val['typeid']);
  349. $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false);
  350. }
  351. }
  352. }
  353. }
  354. break;
  355. case 'MLLT':
  356. // 4.6 MLLT MPEG location lookup table
  357. // MPEG frames between reference $xx xx
  358. // Bytes between reference $xx xx xx
  359. // Milliseconds between reference $xx xx xx
  360. // Bits for bytes deviation $xx
  361. // Bits for milliseconds dev. $xx
  362. // Then for every reference the following data is included;
  363. // Deviation in bytes %xxx....
  364. // Deviation in milliseconds %xxx....
  365. if (($source_data_array['framesbetweenreferences'] > 0) && ($source_data_array['framesbetweenreferences'] <= 65535)) {
  366. $framedata .= getid3_lib::BigEndian2String($source_data_array['framesbetweenreferences'], 2, false);
  367. } else {
  368. $this->errors[] = 'Invalid MPEG Frames Between References in '.$frame_name.' ('.$source_data_array['framesbetweenreferences'].')';
  369. }
  370. if (($source_data_array['bytesbetweenreferences'] > 0) && ($source_data_array['bytesbetweenreferences'] <= 16777215)) {
  371. $framedata .= getid3_lib::BigEndian2String($source_data_array['bytesbetweenreferences'], 3, false);
  372. } else {
  373. $this->errors[] = 'Invalid bytes Between References in '.$frame_name.' ('.$source_data_array['bytesbetweenreferences'].')';
  374. }
  375. if (($source_data_array['msbetweenreferences'] > 0) && ($source_data_array['msbetweenreferences'] <= 16777215)) {
  376. $framedata .= getid3_lib::BigEndian2String($source_data_array['msbetweenreferences'], 3, false);
  377. } else {
  378. $this->errors[] = 'Invalid Milliseconds Between References in '.$frame_name.' ('.$source_data_array['msbetweenreferences'].')';
  379. }
  380. if (!$this->IsWithinBitRange($source_data_array['bitsforbytesdeviation'], 8, false)) {
  381. if (($source_data_array['bitsforbytesdeviation'] % 4) == 0) {
  382. $framedata .= chr($source_data_array['bitsforbytesdeviation']);
  383. } else {
  384. $this->errors[] = 'Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.';
  385. }
  386. } else {
  387. $this->errors[] = 'Invalid Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].')';
  388. }
  389. if (!$this->IsWithinBitRange($source_data_array['bitsformsdeviation'], 8, false)) {
  390. if (($source_data_array['bitsformsdeviation'] % 4) == 0) {
  391. $framedata .= chr($source_data_array['bitsformsdeviation']);
  392. } else {
  393. $this->errors[] = 'Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.';
  394. }
  395. } else {
  396. $this->errors[] = 'Invalid Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsformsdeviation'].')';
  397. }
  398. foreach ($source_data_array as $key => $val) {
  399. if (($key != 'framesbetweenreferences') && ($key != 'bytesbetweenreferences') && ($key != 'msbetweenreferences') && ($key != 'bitsforbytesdeviation') && ($key != 'bitsformsdeviation') && ($key != 'flags')) {
  400. $unwrittenbitstream .= str_pad(getid3_lib::Dec2Bin($val['bytedeviation']), $source_data_array['bitsforbytesdeviation'], '0', STR_PAD_LEFT);
  401. $unwrittenbitstream .= str_pad(getid3_lib::Dec2Bin($val['msdeviation']), $source_data_array['bitsformsdeviation'], '0', STR_PAD_LEFT);
  402. }
  403. }
  404. for ($i = 0; $i < strlen($unwrittenbitstream); $i += 8) {
  405. $highnibble = bindec(substr($unwrittenbitstream, $i, 4)) << 4;
  406. $lownibble = bindec(substr($unwrittenbitstream, $i + 4, 4));
  407. $framedata .= chr($highnibble & $lownibble);
  408. }
  409. break;
  410. case 'SYTC':
  411. // 4.7 SYTC Synchronised tempo codes
  412. // Time stamp format $xx
  413. // Tempo data <binary data>
  414. // Where time stamp format is:
  415. // $01 (32-bit value) MPEG frames from beginning of file
  416. // $02 (32-bit value) milliseconds from beginning of file
  417. if (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) {
  418. $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
  419. } else {
  420. $framedata .= chr($source_data_array['timestampformat']);
  421. foreach ($source_data_array as $key => $val) {
  422. if (!$this->ID3v2IsValidETCOevent($val['typeid'])) {
  423. $this->errors[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')';
  424. } elseif (($key != 'timestampformat') && ($key != 'flags')) {
  425. if (($val['tempo'] < 0) || ($val['tempo'] > 510)) {
  426. $this->errors[] = 'Invalid Tempo (max = 510) in '.$frame_name.' ('.$val['tempo'].') at timestamp ('.$val['timestamp'].')';
  427. } else {
  428. if ($val['tempo'] > 255) {
  429. $framedata .= chr(255);
  430. $val['tempo'] -= 255;
  431. }
  432. $framedata .= chr($val['tempo']);
  433. $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false);
  434. }
  435. }
  436. }
  437. }
  438. break;
  439. case 'USLT':
  440. // 4.8 USLT Unsynchronised lyric/text transcription
  441. // Text encoding $xx
  442. // Language $xx xx xx
  443. // Content descriptor <text string according to encoding> $00 (00)
  444. // Lyrics/text <full text string according to encoding>
  445. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  446. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  447. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  448. } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
  449. $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
  450. } else {
  451. $framedata .= chr($source_data_array['encodingid']);
  452. $framedata .= strtolower($source_data_array['language']);
  453. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  454. $framedata .= $source_data_array['data'];
  455. }
  456. break;
  457. case 'SYLT':
  458. // 4.9 SYLT Synchronised lyric/text
  459. // Text encoding $xx
  460. // Language $xx xx xx
  461. // Time stamp format $xx
  462. // $01 (32-bit value) MPEG frames from beginning of file
  463. // $02 (32-bit value) milliseconds from beginning of file
  464. // Content type $xx
  465. // Content descriptor <text string according to encoding> $00 (00)
  466. // Terminated text to be synced (typically a syllable)
  467. // Sync identifier (terminator to above string) $00 (00)
  468. // Time stamp $xx (xx ...)
  469. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  470. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  471. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  472. } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
  473. $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
  474. } elseif (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) {
  475. $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
  476. } elseif (!$this->ID3v2IsValidSYLTtype($source_data_array['contenttypeid'])) {
  477. $this->errors[] = 'Invalid Content Type byte in '.$frame_name.' ('.$source_data_array['contenttypeid'].')';
  478. } elseif (!is_array($source_data_array['data'])) {
  479. $this->errors[] = 'Invalid Lyric/Timestamp data in '.$frame_name.' (must be an array)';
  480. } else {
  481. $framedata .= chr($source_data_array['encodingid']);
  482. $framedata .= strtolower($source_data_array['language']);
  483. $framedata .= chr($source_data_array['timestampformat']);
  484. $framedata .= chr($source_data_array['contenttypeid']);
  485. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  486. ksort($source_data_array['data']);
  487. foreach ($source_data_array['data'] as $key => $val) {
  488. $framedata .= $val['data'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  489. $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false);
  490. }
  491. }
  492. break;
  493. case 'COMM':
  494. // 4.10 COMM Comments
  495. // Text encoding $xx
  496. // Language $xx xx xx
  497. // Short content descrip. <text string according to encoding> $00 (00)
  498. // The actual text <full text string according to encoding>
  499. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  500. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  501. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  502. } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
  503. $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
  504. } else {
  505. $framedata .= chr($source_data_array['encodingid']);
  506. $framedata .= strtolower($source_data_array['language']);
  507. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  508. $framedata .= $source_data_array['data'];
  509. }
  510. break;
  511. case 'RVA2':
  512. // 4.11 RVA2 Relative volume adjustment (2) (ID3v2.4+ only)
  513. // Identification <text string> $00
  514. // The 'identification' string is used to identify the situation and/or
  515. // device where this adjustment should apply. The following is then
  516. // repeated for every channel:
  517. // Type of channel $xx
  518. // Volume adjustment $xx xx
  519. // Bits representing peak $xx
  520. // Peak volume $xx (xx ...)
  521. $framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00";
  522. foreach ($source_data_array as $key => $val) {
  523. if ($key != 'description') {
  524. $framedata .= chr($val['channeltypeid']);
  525. $framedata .= getid3_lib::BigEndian2String($val['volumeadjust'], 2, false, true); // signed 16-bit
  526. if (!$this->IsWithinBitRange($source_data_array['bitspeakvolume'], 8, false)) {
  527. $framedata .= chr($val['bitspeakvolume']);
  528. if ($val['bitspeakvolume'] > 0) {
  529. $framedata .= getid3_lib::BigEndian2String($val['peakvolume'], ceil($val['bitspeakvolume'] / 8), false, false);
  530. }
  531. } else {
  532. $this->errors[] = 'Invalid Bits Representing Peak Volume in '.$frame_name.' ('.$val['bitspeakvolume'].') (range = 0 to 255)';
  533. }
  534. }
  535. }
  536. break;
  537. case 'RVAD':
  538. // 4.12 RVAD Relative volume adjustment (ID3v2.3 only)
  539. // Increment/decrement %00fedcba
  540. // Bits used for volume descr. $xx
  541. // Relative volume change, right $xx xx (xx ...) // a
  542. // Relative volume change, left $xx xx (xx ...) // b
  543. // Peak volume right $xx xx (xx ...)
  544. // Peak volume left $xx xx (xx ...)
  545. // Relative volume change, right back $xx xx (xx ...) // c
  546. // Relative volume change, left back $xx xx (xx ...) // d
  547. // Peak volume right back $xx xx (xx ...)
  548. // Peak volume left back $xx xx (xx ...)
  549. // Relative volume change, center $xx xx (xx ...) // e
  550. // Peak volume center $xx xx (xx ...)
  551. // Relative volume change, bass $xx xx (xx ...) // f
  552. // Peak volume bass $xx xx (xx ...)
  553. if (!$this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) {
  554. $this->errors[] = 'Invalid Bits For Volume Description byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)';
  555. } else {
  556. $incdecflag .= '00';
  557. $incdecflag .= $source_data_array['incdec']['right'] ? '1' : '0'; // a - Relative volume change, right
  558. $incdecflag .= $source_data_array['incdec']['left'] ? '1' : '0'; // b - Relative volume change, left
  559. $incdecflag .= $source_data_array['incdec']['rightrear'] ? '1' : '0'; // c - Relative volume change, right back
  560. $incdecflag .= $source_data_array['incdec']['leftrear'] ? '1' : '0'; // d - Relative volume change, left back
  561. $incdecflag .= $source_data_array['incdec']['center'] ? '1' : '0'; // e - Relative volume change, center
  562. $incdecflag .= $source_data_array['incdec']['bass'] ? '1' : '0'; // f - Relative volume change, bass
  563. $framedata .= chr(bindec($incdecflag));
  564. $framedata .= chr($source_data_array['bitsvolume']);
  565. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['right'], ceil($source_data_array['bitsvolume'] / 8), false);
  566. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['left'], ceil($source_data_array['bitsvolume'] / 8), false);
  567. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['right'], ceil($source_data_array['bitsvolume'] / 8), false);
  568. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['left'], ceil($source_data_array['bitsvolume'] / 8), false);
  569. if ($source_data_array['volumechange']['rightrear'] || $source_data_array['volumechange']['leftrear'] ||
  570. $source_data_array['peakvolume']['rightrear'] || $source_data_array['peakvolume']['leftrear'] ||
  571. $source_data_array['volumechange']['center'] || $source_data_array['peakvolume']['center'] ||
  572. $source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) {
  573. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['rightrear'], ceil($source_data_array['bitsvolume']/8), false);
  574. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['leftrear'], ceil($source_data_array['bitsvolume']/8), false);
  575. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['rightrear'], ceil($source_data_array['bitsvolume']/8), false);
  576. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['leftrear'], ceil($source_data_array['bitsvolume']/8), false);
  577. }
  578. if ($source_data_array['volumechange']['center'] || $source_data_array['peakvolume']['center'] ||
  579. $source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) {
  580. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['center'], ceil($source_data_array['bitsvolume']/8), false);
  581. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['center'], ceil($source_data_array['bitsvolume']/8), false);
  582. }
  583. if ($source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) {
  584. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['bass'], ceil($source_data_array['bitsvolume']/8), false);
  585. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['bass'], ceil($source_data_array['bitsvolume']/8), false);
  586. }
  587. }
  588. break;
  589. case 'EQU2':
  590. // 4.12 EQU2 Equalisation (2) (ID3v2.4+ only)
  591. // Interpolation method $xx
  592. // $00 Band
  593. // $01 Linear
  594. // Identification <text string> $00
  595. // The following is then repeated for every adjustment point
  596. // Frequency $xx xx
  597. // Volume adjustment $xx xx
  598. if (($source_data_array['interpolationmethod'] < 0) || ($source_data_array['interpolationmethod'] > 1)) {
  599. $this->errors[] = 'Invalid Interpolation Method byte in '.$frame_name.' ('.$source_data_array['interpolationmethod'].') (valid = 0 or 1)';
  600. } else {
  601. $framedata .= chr($source_data_array['interpolationmethod']);
  602. $framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00";
  603. foreach ($source_data_array['data'] as $key => $val) {
  604. $framedata .= getid3_lib::BigEndian2String(intval(round($key * 2)), 2, false);
  605. $framedata .= getid3_lib::BigEndian2String($val, 2, false, true); // signed 16-bit
  606. }
  607. }
  608. break;
  609. case 'EQUA':
  610. // 4.12 EQUA Equalisation (ID3v2.3 only)
  611. // Adjustment bits $xx
  612. // This is followed by 2 bytes + ('adjustment bits' rounded up to the
  613. // nearest byte) for every equalisation band in the following format,
  614. // giving a frequency range of 0 - 32767Hz:
  615. // Increment/decrement %x (MSB of the Frequency)
  616. // Frequency (lower 15 bits)
  617. // Adjustment $xx (xx ...)
  618. if (!$this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) {
  619. $this->errors[] = 'Invalid Adjustment Bits byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)';
  620. } else {
  621. $framedata .= chr($source_data_array['adjustmentbits']);
  622. foreach ($source_data_array as $key => $val) {
  623. if ($key != 'bitsvolume') {
  624. if (($key > 32767) || ($key < 0)) {
  625. $this->errors[] = 'Invalid Frequency in '.$frame_name.' ('.$key.') (range = 0 to 32767)';
  626. } else {
  627. if ($val >= 0) {
  628. // put MSB of frequency to 1 if increment, 0 if decrement
  629. $key |= 0x8000;
  630. }
  631. $framedata .= getid3_lib::BigEndian2String($key, 2, false);
  632. $framedata .= getid3_lib::BigEndian2String($val, ceil($source_data_array['adjustmentbits'] / 8), false);
  633. }
  634. }
  635. }
  636. }
  637. break;
  638. case 'RVRB':
  639. // 4.13 RVRB Reverb
  640. // Reverb left (ms) $xx xx
  641. // Reverb right (ms) $xx xx
  642. // Reverb bounces, left $xx
  643. // Reverb bounces, right $xx
  644. // Reverb feedback, left to left $xx
  645. // Reverb feedback, left to right $xx
  646. // Reverb feedback, right to right $xx
  647. // Reverb feedback, right to left $xx
  648. // Premix left to right $xx
  649. // Premix right to left $xx
  650. if (!$this->IsWithinBitRange($source_data_array['left'], 16, false)) {
  651. $this->errors[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['left'].') (range = 0 to 65535)';
  652. } elseif (!$this->IsWithinBitRange($source_data_array['right'], 16, false)) {
  653. $this->errors[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['right'].') (range = 0 to 65535)';
  654. } elseif (!$this->IsWithinBitRange($source_data_array['bouncesL'], 8, false)) {
  655. $this->errors[] = 'Invalid Reverb Bounces, Left in '.$frame_name.' ('.$source_data_array['bouncesL'].') (range = 0 to 255)';
  656. } elseif (!$this->IsWithinBitRange($source_data_array['bouncesR'], 8, false)) {
  657. $this->errors[] = 'Invalid Reverb Bounces, Right in '.$frame_name.' ('.$source_data_array['bouncesR'].') (range = 0 to 255)';
  658. } elseif (!$this->IsWithinBitRange($source_data_array['feedbackLL'], 8, false)) {
  659. $this->errors[] = 'Invalid Reverb Feedback, Left-To-Left in '.$frame_name.' ('.$source_data_array['feedbackLL'].') (range = 0 to 255)';
  660. } elseif (!$this->IsWithinBitRange($source_data_array['feedbackLR'], 8, false)) {
  661. $this->errors[] = 'Invalid Reverb Feedback, Left-To-Right in '.$frame_name.' ('.$source_data_array['feedbackLR'].') (range = 0 to 255)';
  662. } elseif (!$this->IsWithinBitRange($source_data_array['feedbackRR'], 8, false)) {
  663. $this->errors[] = 'Invalid Reverb Feedback, Right-To-Right in '.$frame_name.' ('.$source_data_array['feedbackRR'].') (range = 0 to 255)';
  664. } elseif (!$this->IsWithinBitRange($source_data_array['feedbackRL'], 8, false)) {
  665. $this->errors[] = 'Invalid Reverb Feedback, Right-To-Left in '.$frame_name.' ('.$source_data_array['feedbackRL'].') (range = 0 to 255)';
  666. } elseif (!$this->IsWithinBitRange($source_data_array['premixLR'], 8, false)) {
  667. $this->errors[] = 'Invalid Premix, Left-To-Right in '.$frame_name.' ('.$source_data_array['premixLR'].') (range = 0 to 255)';
  668. } elseif (!$this->IsWithinBitRange($source_data_array['premixRL'], 8, false)) {
  669. $this->errors[] = 'Invalid Premix, Right-To-Left in '.$frame_name.' ('.$source_data_array['premixRL'].') (range = 0 to 255)';
  670. } else {
  671. $framedata .= getid3_lib::BigEndian2String($source_data_array['left'], 2, false);
  672. $framedata .= getid3_lib::BigEndian2String($source_data_array['right'], 2, false);
  673. $framedata .= chr($source_data_array['bouncesL']);
  674. $framedata .= chr($source_data_array['bouncesR']);
  675. $framedata .= chr($source_data_array['feedbackLL']);
  676. $framedata .= chr($source_data_array['feedbackLR']);
  677. $framedata .= chr($source_data_array['feedbackRR']);
  678. $framedata .= chr($source_data_array['feedbackRL']);
  679. $framedata .= chr($source_data_array['premixLR']);
  680. $framedata .= chr($source_data_array['premixRL']);
  681. }
  682. break;
  683. case 'APIC':
  684. // 4.14 APIC Attached picture
  685. // Text encoding $xx
  686. // MIME type <text string> $00
  687. // Picture type $xx
  688. // Description <text string according to encoding> $00 (00)
  689. // Picture data <binary data>
  690. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  691. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  692. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  693. } elseif (!$this->ID3v2IsValidAPICpicturetype($source_data_array['picturetypeid'])) {
  694. $this->errors[] = 'Invalid Picture Type byte in '.$frame_name.' ('.$source_data_array['picturetypeid'].') for ID3v2.'.$this->majorversion;
  695. } elseif (($this->majorversion >= 3) && (!$this->ID3v2IsValidAPICimageformat($source_data_array['mime']))) {
  696. $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].') for ID3v2.'.$this->majorversion;
  697. } elseif (($source_data_array['mime'] == '-->') && (!$this->IsValidURL($source_data_array['data'], false, false))) {
  698. //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  699. // probably should be an error, need to rewrite IsValidURL() to handle other encodings
  700. $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  701. } else {
  702. $framedata .= chr($source_data_array['encodingid']);
  703. $framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00";
  704. $framedata .= chr($source_data_array['picturetypeid']);
  705. $framedata .= (!empty($source_data_array['description']) ? $source_data_array['description'] : '').getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  706. $framedata .= $source_data_array['data'];
  707. }
  708. break;
  709. case 'GEOB':
  710. // 4.15 GEOB General encapsulated object
  711. // Text encoding $xx
  712. // MIME type <text string> $00
  713. // Filename <text string according to encoding> $00 (00)
  714. // Content description <text string according to encoding> $00 (00)
  715. // Encapsulated object <binary data>
  716. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  717. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  718. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  719. } elseif (!$this->IsValidMIMEstring($source_data_array['mime'])) {
  720. $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].')';
  721. } elseif (!$source_data_array['description']) {
  722. $this->errors[] = 'Missing Description in '.$frame_name;
  723. } else {
  724. $framedata .= chr($source_data_array['encodingid']);
  725. $framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00";
  726. $framedata .= $source_data_array['filename'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  727. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  728. $framedata .= $source_data_array['data'];
  729. }
  730. break;
  731. case 'PCNT':
  732. // 4.16 PCNT Play counter
  733. // When the counter reaches all one's, one byte is inserted in
  734. // front of the counter thus making the counter eight bits bigger
  735. // Counter $xx xx xx xx (xx ...)
  736. $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false);
  737. break;
  738. case 'POPM':
  739. // 4.17 POPM Popularimeter
  740. // When the counter reaches all one's, one byte is inserted in
  741. // front of the counter thus making the counter eight bits bigger
  742. // Email to user <text string> $00
  743. // Rating $xx
  744. // Counter $xx xx xx xx (xx ...)
  745. if (!$this->IsWithinBitRange($source_data_array['rating'], 8, false)) {
  746. $this->errors[] = 'Invalid Rating byte in '.$frame_name.' ('.$source_data_array['rating'].') (range = 0 to 255)';
  747. } elseif (!IsValidEmail($source_data_array['email'])) {
  748. $this->errors[] = 'Invalid Email in '.$frame_name.' ('.$source_data_array['email'].')';
  749. } else {
  750. $framedata .= str_replace("\x00", '', $source_data_array['email'])."\x00";
  751. $framedata .= chr($source_data_array['rating']);
  752. $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false);
  753. }
  754. break;
  755. case 'RBUF':
  756. // 4.18 RBUF Recommended buffer size
  757. // Buffer size $xx xx xx
  758. // Embedded info flag %0000000x
  759. // Offset to next tag $xx xx xx xx
  760. if (!$this->IsWithinBitRange($source_data_array['buffersize'], 24, false)) {
  761. $this->errors[] = 'Invalid Buffer Size in '.$frame_name;
  762. } elseif (!$this->IsWithinBitRange($source_data_array['nexttagoffset'], 32, false)) {
  763. $this->errors[] = 'Invalid Offset To Next Tag in '.$frame_name;
  764. } else {
  765. $framedata .= getid3_lib::BigEndian2String($source_data_array['buffersize'], 3, false);
  766. $flag .= '0000000';
  767. $flag .= $source_data_array['flags']['embededinfo'] ? '1' : '0';
  768. $framedata .= chr(bindec($flag));
  769. $framedata .= getid3_lib::BigEndian2String($source_data_array['nexttagoffset'], 4, false);
  770. }
  771. break;
  772. case 'AENC':
  773. // 4.19 AENC Audio encryption
  774. // Owner identifier <text string> $00
  775. // Preview start $xx xx
  776. // Preview length $xx xx
  777. // Encryption info <binary data>
  778. if (!$this->IsWithinBitRange($source_data_array['previewstart'], 16, false)) {
  779. $this->errors[] = 'Invalid Preview Start in '.$frame_name.' ('.$source_data_array['previewstart'].')';
  780. } elseif (!$this->IsWithinBitRange($source_data_array['previewlength'], 16, false)) {
  781. $this->errors[] = 'Invalid Preview Length in '.$frame_name.' ('.$source_data_array['previewlength'].')';
  782. } else {
  783. $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
  784. $framedata .= getid3_lib::BigEndian2String($source_data_array['previewstart'], 2, false);
  785. $framedata .= getid3_lib::BigEndian2String($source_data_array['previewlength'], 2, false);
  786. $framedata .= $source_data_array['encryptioninfo'];
  787. }
  788. break;
  789. case 'LINK':
  790. // 4.20 LINK Linked information
  791. // Frame identifier $xx xx xx xx
  792. // URL <text string> $00
  793. // ID and additional data <text string(s)>
  794. if (!getid3_id3v2::IsValidID3v2FrameName($source_data_array['frameid'], $this->majorversion)) {
  795. $this->errors[] = 'Invalid Frame Identifier in '.$frame_name.' ('.$source_data_array['frameid'].')';
  796. } elseif (!$this->IsValidURL($source_data_array['data'], true, false)) {
  797. //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  798. // probably should be an error, need to rewrite IsValidURL() to handle other encodings
  799. $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  800. } elseif ((($source_data_array['frameid'] == 'AENC') || ($source_data_array['frameid'] == 'APIC') || ($source_data_array['frameid'] == 'GEOB') || ($source_data_array['frameid'] == 'TXXX')) && ($source_data_array['additionaldata'] == '')) {
  801. $this->errors[] = 'Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
  802. } elseif (($source_data_array['frameid'] == 'USER') && (getid3_id3v2::LanguageLookup($source_data_array['additionaldata'], true) == '')) {
  803. $this->errors[] = 'Language must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
  804. } elseif (($source_data_array['frameid'] == 'PRIV') && ($source_data_array['additionaldata'] == '')) {
  805. $this->errors[] = 'Owner Identifier must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
  806. } elseif ((($source_data_array['frameid'] == 'COMM') || ($source_data_array['frameid'] == 'SYLT') || ($source_data_array['frameid'] == 'USLT')) && ((getid3_id3v2::LanguageLookup(substr($source_data_array['additionaldata'], 0, 3), true) == '') || (substr($source_data_array['additionaldata'], 3) == ''))) {
  807. $this->errors[] = 'Language followed by Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
  808. } else {
  809. $framedata .= $source_data_array['frameid'];
  810. $framedata .= str_replace("\x00", '', $source_data_array['data'])."\x00";
  811. switch ($source_data_array['frameid']) {
  812. case 'COMM':
  813. case 'SYLT':
  814. case 'USLT':
  815. case 'PRIV':
  816. case 'USER':
  817. case 'AENC':
  818. case 'APIC':
  819. case 'GEOB':
  820. case 'TXXX':
  821. $framedata .= $source_data_array['additionaldata'];
  822. break;
  823. case 'ASPI':
  824. case 'ETCO':
  825. case 'EQU2':
  826. case 'MCID':
  827. case 'MLLT':
  828. case 'OWNE':
  829. case 'RVA2':
  830. case 'RVRB':
  831. case 'SYTC':
  832. case 'IPLS':
  833. case 'RVAD':
  834. case 'EQUA':
  835. // no additional data required
  836. break;
  837. case 'RBUF':
  838. if ($this->majorversion == 3) {
  839. // no additional data required
  840. } else {
  841. $this->errors[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion.')';
  842. }
  843. default:
  844. if ((substr($source_data_array['frameid'], 0, 1) == 'T') || (substr($source_data_array['frameid'], 0, 1) == 'W')) {
  845. // no additional data required
  846. } else {
  847. $this->errors[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion.')';
  848. }
  849. break;
  850. }
  851. }
  852. break;
  853. case 'POSS':
  854. // 4.21 POSS Position synchronisation frame (ID3v2.3+ only)
  855. // Time stamp format $xx
  856. // Position $xx (xx ...)
  857. if (($source_data_array['timestampformat'] < 1) || ($source_data_array['timestampformat'] > 2)) {
  858. $this->errors[] = 'Invalid Time Stamp Format in '.$frame_name.' ('.$source_data_array['timestampformat'].') (valid = 1 or 2)';
  859. } elseif (!$this->IsWithinBitRange($source_data_array['position'], 32, false)) {
  860. $this->errors[] = 'Invalid Position in '.$frame_name.' ('.$source_data_array['position'].') (range = 0 to 4294967295)';
  861. } else {
  862. $framedata .= chr($source_data_array['timestampformat']);
  863. $framedata .= getid3_lib::BigEndian2String($source_data_array['position'], 4, false);
  864. }
  865. break;
  866. case 'USER':
  867. // 4.22 USER Terms of use (ID3v2.3+ only)
  868. // Text encoding $xx
  869. // Language $xx xx xx
  870. // The actual text <text string according to encoding>
  871. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  872. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  873. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')';
  874. } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
  875. $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
  876. } else {
  877. $framedata .= chr($source_data_array['encodingid']);
  878. $framedata .= strtolower($source_data_array['language']);
  879. $framedata .= $source_data_array['data'];
  880. }
  881. break;
  882. case 'OWNE':
  883. // 4.23 OWNE Ownership frame (ID3v2.3+ only)
  884. // Text encoding $xx
  885. // Price paid <text string> $00
  886. // Date of purch. <text string>
  887. // Seller <text string according to encoding>
  888. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  889. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  890. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')';
  891. } elseif (!$this->IsANumber($source_data_array['pricepaid']['value'], false)) {
  892. $this->errors[] = 'Invalid Price Paid in '.$frame_name.' ('.$source_data_array['pricepaid']['value'].')';
  893. } elseif (!$this->IsValidDateStampString($source_data_array['purchasedate'])) {
  894. $this->errors[] = 'Invalid Date Of Purchase in '.$frame_name.' ('.$source_data_array['purchasedate'].') (format = YYYYMMDD)';
  895. } else {
  896. $framedata .= chr($source_data_array['encodingid']);
  897. $framedata .= str_replace("\x00", '', $source_data_array['pricepaid']['value'])."\x00";
  898. $framedata .= $source_data_array['purchasedate'];
  899. $framedata .= $source_data_array['seller'];
  900. }
  901. break;
  902. case 'COMR':
  903. // 4.24 COMR Commercial frame (ID3v2.3+ only)
  904. // Text encoding $xx
  905. // Price string <text string> $00
  906. // Valid until <text string>
  907. // Contact URL <text string> $00
  908. // Received as $xx
  909. // Name of seller <text string according to encoding> $00 (00)
  910. // Description <text string according to encoding> $00 (00)
  911. // Picture MIME type <string> $00
  912. // Seller logo <binary data>
  913. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  914. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  915. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')';
  916. } elseif (!$this->IsValidDateStampString($source_data_array['pricevaliduntil'])) {
  917. $this->errors[] = 'Invalid Valid Until date in '.$frame_name.' ('.$source_data_array['pricevaliduntil'].') (format = YYYYMMDD)';
  918. } elseif (!$this->IsValidURL($source_data_array['contacturl'], false, true)) {
  919. $this->errors[] = 'Invalid Contact URL in '.$frame_name.' ('.$source_data_array['contacturl'].') (allowed schemes: http, https, ftp, mailto)';
  920. } elseif (!$this->ID3v2IsValidCOMRreceivedAs($source_data_array['receivedasid'])) {
  921. $this->errors[] = 'Invalid Received As byte in '.$frame_name.' ('.$source_data_array['contacturl'].') (range = 0 to 8)';
  922. } elseif (!$this->IsValidMIMEstring($source_data_array['mime'])) {
  923. $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].')';
  924. } else {
  925. $framedata .= chr($source_data_array['encodingid']);
  926. unset($pricestring);
  927. foreach ($source_data_array['price'] as $key => $val) {
  928. if ($this->ID3v2IsValidPriceString($key.$val['value'])) {
  929. $pricestrings[] = $key.$val['value'];
  930. } else {
  931. $this->errors[] = 'Invalid Price String in '.$frame_name.' ('.$key.$val['value'].')';
  932. }
  933. }
  934. $framedata .= implode('/', $pricestrings);
  935. $framedata .= $source_data_array['pricevaliduntil'];
  936. $framedata .= str_replace("\x00", '', $source_data_array['contacturl'])."\x00";
  937. $framedata .= chr($source_data_array['receivedasid']);
  938. $framedata .= $source_data_array['sellername'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  939. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  940. $framedata .= $source_data_array['mime']."\x00";
  941. $framedata .= $source_data_array['logo'];
  942. }
  943. break;
  944. case 'ENCR':
  945. // 4.25 ENCR Encryption method registration (ID3v2.3+ only)
  946. // Owner identifier <text string> $00
  947. // Method symbol $xx
  948. // Encryption data <binary data>
  949. if (!$this->IsWithinBitRange($source_data_array['methodsymbol'], 8, false)) {
  950. $this->errors[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['methodsymbol'].') (range = 0 to 255)';
  951. } else {
  952. $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
  953. $framedata .= ord($source_data_array['methodsymbol']);
  954. $framedata .= $source_data_array['data'];
  955. }
  956. break;
  957. case 'GRID':
  958. // 4.26 GRID Group identification registration (ID3v2.3+ only)
  959. // Owner identifier <text string> $00
  960. // Group symbol $xx
  961. // Group dependent data <binary data>
  962. if (!$this->IsWithinBitRange($source_data_array['groupsymbol'], 8, false)) {
  963. $this->errors[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['groupsymbol'].') (range = 0 to 255)';
  964. } else {
  965. $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
  966. $framedata .= ord($source_data_array['groupsymbol']);
  967. $framedata .= $source_data_array['data'];
  968. }
  969. break;
  970. case 'PRIV':
  971. // 4.27 PRIV Private frame (ID3v2.3+ only)
  972. // Owner identifier <text string> $00
  973. // The private data <binary data>
  974. $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
  975. $framedata .= $source_data_array['data'];
  976. break;
  977. case 'SIGN':
  978. // 4.28 SIGN Signature frame (ID3v2.4+ only)
  979. // Group symbol $xx
  980. // Signature <binary data>
  981. if (!$this->IsWithinBitRange($source_data_array['groupsymbol'], 8, false)) {
  982. $this->errors[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['groupsymbol'].') (range = 0 to 255)';
  983. } else {
  984. $framedata .= ord($source_data_array['groupsymbol']);
  985. $framedata .= $source_data_array['data'];
  986. }
  987. break;
  988. case 'SEEK':
  989. // 4.29 SEEK Seek frame (ID3v2.4+ only)
  990. // Minimum offset to next tag $xx xx xx xx
  991. if (!$this->IsWithinBitRange($source_data_array['data'], 32, false)) {
  992. $this->errors[] = 'Invalid Minimum Offset in '.$frame_name.' ('.$source_data_array['data'].') (range = 0 to 4294967295)';
  993. } else {
  994. $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false);
  995. }
  996. break;
  997. case 'ASPI':
  998. // 4.30 ASPI Audio seek point index (ID3v2.4+ only)
  999. // Indexed data start (S) $xx xx xx xx
  1000. // Indexed data length (L) $xx xx xx xx
  1001. // Number of index points (N) $xx xx
  1002. // Bits per index point (b) $xx
  1003. // Then for every index point the following data is included:
  1004. // Fraction at index (Fi) $xx (xx)
  1005. if (!$this->IsWithinBitRange($source_data_array['datastart'], 32, false)) {
  1006. $this->errors[] = 'Invalid Indexed Data Start in '.$frame_name.' ('.$source_data_array['datastart'].') (range = 0 to 4294967295)';
  1007. } elseif (!$this->IsWithinBitRange($source_data_array['datalength'], 32, false)) {
  1008. $this->errors[] = 'Invalid Indexed Data Length in '.$frame_name.' ('.$source_data_array['datalength'].') (range = 0 to 4294967295)';
  1009. } elseif (!$this->IsWithinBitRange($source_data_array['indexpoints'], 16, false)) {
  1010. $this->errors[] = 'Invalid Number Of Index Points in '.$frame_name.' ('.$source_data_array['indexpoints'].') (range = 0 to 65535)';
  1011. } elseif (!$this->IsWithinBitRange($source_data_array['bitsperpoint'], 8, false)) {
  1012. $this->errors[] = 'Invalid Bits Per Index Point in '.$frame_name.' ('.$source_data_array['bitsperpoint'].') (range = 0 to 255)';
  1013. } elseif ($source_data_array['indexpoints'] != count($source_data_array['indexes'])) {
  1014. $this->errors[] = 'Number Of Index Points does not match actual supplied data in '.$frame_name;
  1015. } else {
  1016. $framedata .= getid3_lib::BigEndian2String($source_data_array['datastart'], 4, false);
  1017. $framedata .= getid3_lib::BigEndian2String($source_data_array['datalength'], 4, false);
  1018. $framedata .= getid3_lib::BigEndian2String($source_data_array['indexpoints'], 2, false);
  1019. $framedata .= getid3_lib::BigEndian2String($source_data_array['bitsperpoint'], 1, false);
  1020. foreach ($source_data_array['indexes'] as $key => $val) {
  1021. $framedata .= getid3_lib::BigEndian2String($val, ceil($source_data_array['bitsperpoint'] / 8), false);
  1022. }
  1023. }
  1024. break;
  1025. case 'RGAD':
  1026. // RGAD Replay Gain Adjustment
  1027. // http://privatewww.essex.ac.uk/~djmrob/replaygain/
  1028. // Peak Amplitude $xx $xx $xx $xx
  1029. // Radio Replay Gain Adjustment %aaabbbcd %dddddddd
  1030. // Audiophile Replay Gain Adjustment %aaabbbcd %dddddddd
  1031. // a - name code
  1032. // b - originator code
  1033. // c - sign bit
  1034. // d - replay gain adjustment
  1035. if (($source_data_array['track_adjustment'] > 51) || ($source_data_array['track_adjustment'] < -51)) {
  1036. $this->errors[] = 'Invalid Track Adjustment in '.$frame_name.' ('.$source_data_array['track_adjustment'].') (range = -51.0 to +51.0)';
  1037. } elseif (($source_data_array['album_adjustment'] > 51) || ($source_data_array['album_adjustment'] < -51)) {
  1038. $this->errors[] = 'Invalid Album Adjustment in '.$frame_name.' ('.$source_data_array['album_adjustment'].') (range = -51.0 to +51.0)';
  1039. } elseif (!$this->ID3v2IsValidRGADname($source_data_array['raw']['track_name'])) {
  1040. $this->errors[] = 'Invalid Track Name Code in '.$frame_name.' ('.$source_data_array['raw']['track_name'].') (range = 0 to 2)';
  1041. } elseif (!$this->ID3v2IsValidRGADname($source_data_array['raw']['album_name'])) {
  1042. $this->errors[] = 'Invalid Album Name Code in '.$frame_name.' ('.$source_data_array['raw']['album_name'].') (range = 0 to 2)';
  1043. } elseif (!$this->ID3v2IsValidRGADoriginator($source_data_array['raw']['track_originator'])) {
  1044. $this->errors[] = 'Invalid Track Originator Code in '.$frame_name.' ('.$source_data_array['raw']['track_originator'].') (range = 0 to 3)';
  1045. } elseif (!$this->ID3v2IsValidRGADoriginator($source_data_array['raw']['album_originator'])) {
  1046. $this->errors[] = 'Invalid Album Originator Code in '.$frame_name.' ('.$source_data_array['raw']['album_originator'].') (range = 0 to 3)';
  1047. } else {
  1048. $framedata .= getid3_lib::Float2String($source_data_array['peakamplitude'], 32);
  1049. $framedata .= getid3_lib::RGADgainString($source_data_array['raw']['track_name'], $source_data_array['raw']['track_originator'], $source_data_array['track_adjustment']);
  1050. $framedata .= getid3_lib::RGADgainString($source_data_array['raw']['album_name'], $source_data_array['raw']['album_originator'], $source_data_array['album_adjustment']);
  1051. }
  1052. break;
  1053. default:
  1054. if ((($this->majorversion == 2) && (strlen($frame_name) != 3)) || (($this->majorversion > 2) && (strlen($frame_name) != 4))) {
  1055. $this->errors[] = 'Invalid frame name "'.$frame_name.'" for ID3v2.'.$this->majorversion;
  1056. } elseif ($frame_name{0} == 'T') {
  1057. // 4.2. T??? Text information frames
  1058. // Text encoding $xx
  1059. // Information <text string(s) according to encoding>
  1060. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  1061. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  1062. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  1063. } else {
  1064. $framedata .= chr($source_data_array['encodingid']);
  1065. $framedata .= $source_data_array['data'];
  1066. }
  1067. } elseif ($frame_name{0} == 'W') {
  1068. // 4.3. W??? URL link frames
  1069. // URL <text string>
  1070. if (!$this->IsValidURL($source_data_array['data'], false, false)) {
  1071. //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  1072. // probably should be an error, need to rewrite IsValidURL() to handle other encodings
  1073. $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  1074. } else {
  1075. $framedata .= $source_data_array['data'];
  1076. }
  1077. } else {
  1078. $this->errors[] = $frame_name.' not yet supported in $this->GenerateID3v2FrameData()';
  1079. }
  1080. break;
  1081. }
  1082. }
  1083. if (!empty($this->errors)) {
  1084. return false;
  1085. }
  1086. return $framedata;
  1087. }
  1088. public function ID3v2FrameIsAllowed($frame_name, $source_data_array) {
  1089. static $PreviousFrames = array();
  1090. if ($frame_name === null) {
  1091. // if the writing functions are called multiple times, the static array needs to be
  1092. // cleared - this can be done by calling $this->ID3v2FrameIsAllowed(null, '')
  1093. $PreviousFrames = array();
  1094. return true;
  1095. }
  1096. if ($this->majorversion == 4) {
  1097. switch ($frame_name) {
  1098. case 'UFID':
  1099. case 'AENC':
  1100. case 'ENCR':
  1101. case 'GRID':
  1102. if (!isset($source_data_array['ownerid'])) {
  1103. $this->errors[] = '[ownerid] not specified for '.$frame_name;
  1104. } elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) {
  1105. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')';
  1106. } else {
  1107. $PreviousFrames[] = $frame_name.$source_data_array['ownerid'];
  1108. }
  1109. break;
  1110. case 'TXXX':
  1111. case 'WXXX':
  1112. case 'RVA2':
  1113. case 'EQU2':
  1114. case 'APIC':
  1115. case 'GEOB':
  1116. if (!isset($source_data_array['description'])) {
  1117. $this->errors[] = '[description] not specified for '.$frame_name;
  1118. } elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) {
  1119. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')';
  1120. } else {
  1121. $PreviousFrames[] = $frame_name.$source_data_array['description'];
  1122. }
  1123. break;
  1124. case 'USER':
  1125. if (!isset($source_data_array['language'])) {
  1126. $this->errors[] = '[language] not specified for '.$frame_name;
  1127. } elseif (in_array($frame_name.$source_data_array['language'], $PreviousFrames)) {
  1128. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language ('.$source_data_array['language'].')';
  1129. } else {
  1130. $PreviousFrames[] = $frame_name.$source_data_array['language'];
  1131. }
  1132. break;
  1133. case 'USLT':
  1134. case 'SYLT':
  1135. case 'COMM':
  1136. if (!isset($source_data_array['language'])) {
  1137. $this->errors[] = '[language] not specified for '.$frame_name;
  1138. } elseif (!isset($source_data_array['description'])) {
  1139. $this->errors[] = '[description] not specified for '.$frame_name;
  1140. } elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) {
  1141. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')';
  1142. } else {
  1143. $PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description'];
  1144. }
  1145. break;
  1146. case 'POPM':
  1147. if (!isset($source_data_array['email'])) {
  1148. $this->errors[] = '[email] not specified for '.$frame_name;
  1149. } elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) {
  1150. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')';
  1151. } else {
  1152. $PreviousFrames[] = $frame_name.$source_data_array['email'];
  1153. }
  1154. break;
  1155. case 'IPLS':
  1156. case 'MCDI':
  1157. case 'ETCO':
  1158. case 'MLLT':
  1159. case 'SYTC':
  1160. case 'RVRB':
  1161. case 'PCNT':
  1162. case 'RBUF':
  1163. case 'POSS':
  1164. case 'OWNE':
  1165. case 'SEEK':
  1166. case 'ASPI':
  1167. case 'RGAD':
  1168. if (in_array($frame_name, $PreviousFrames)) {
  1169. $this->errors[] = 'Only one '.$frame_name.' tag allowed';
  1170. } else {
  1171. $PreviousFrames[] = $frame_name;
  1172. }
  1173. break;
  1174. case 'LINK':
  1175. // this isn't implemented quite right (yet) - it should check the target frame data for compliance
  1176. // but right now it just allows one linked frame of each type, to be safe.
  1177. if (!isset($source_data_array['frameid'])) {
  1178. $this->errors[] = '[frameid] not specified for '.$frame_name;
  1179. } elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) {
  1180. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')';
  1181. } elseif (in_array($source_data_array['frameid'], $PreviousFrames)) {
  1182. // no links to singleton tags
  1183. $this->errors[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')';
  1184. } else {
  1185. $PreviousFrames[] = $frame_name.$source_data_array['frameid']; // only one linked tag of this type
  1186. $PreviousFrames[] = $source_data_array['frameid']; // no non-linked singleton tags of this type
  1187. }
  1188. break;
  1189. case 'COMR':
  1190. // There may be more than one 'commercial frame' in a tag, but no two may be identical
  1191. // Checking isn't implemented at all (yet) - just assumes that it's OK.
  1192. break;
  1193. case 'PRIV':
  1194. case 'SIGN':
  1195. if (!isset($source_data_array['ownerid'])) {
  1196. $this->errors[] = '[ownerid] not specified for '.$frame_name;
  1197. } elseif (!isset($source_data_array['data'])) {
  1198. $this->errors[] = '[data] not specified for '.$frame_name;
  1199. } elseif (in_array($frame_name.$source_data_array['ownerid'].$source_data_array['data'], $PreviousFrames)) {
  1200. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID + Data ('.$source_data_array['ownerid'].' + '.$source_data_array['data'].')';
  1201. } else {
  1202. $PreviousFrames[] = $frame_name.$source_data_array['ownerid'].$source_data_array['data'];
  1203. }
  1204. break;
  1205. default:
  1206. if (($frame_name{0} != 'T') && ($frame_name{0} != 'W')) {
  1207. $this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name;
  1208. }
  1209. break;
  1210. }
  1211. } elseif ($this->majorversion == 3) {
  1212. switch ($frame_name) {
  1213. case 'UFID':
  1214. case 'AENC':
  1215. case 'ENCR':
  1216. case 'GRID':
  1217. if (!isset($source_data_array['ownerid'])) {
  1218. $this->errors[] = '[ownerid] not specified for '.$frame_name;
  1219. } elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) {
  1220. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')';
  1221. } else {
  1222. $PreviousFrames[] = $frame_name.$source_data_array['ownerid'];
  1223. }
  1224. break;
  1225. case 'TXXX':
  1226. case 'WXXX':
  1227. case 'APIC':
  1228. case 'GEOB':
  1229. if (!isset($source_data_array['description'])) {
  1230. $this->errors[] = '[description] not specified for '.$frame_name;
  1231. } elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) {
  1232. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')';
  1233. } else {
  1234. $PreviousFrames[] = $frame_name.$source_data_array['description'];
  1235. }
  1236. break;
  1237. case 'USER':
  1238. if (!isset($source_data_array['language'])) {
  1239. $this->errors[] = '[language] not specified for '.$frame_name;
  1240. } elseif (in_array($frame_name.$source_data_array['language'], $PreviousFrames)) {
  1241. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language ('.$source_data_array['language'].')';
  1242. } else {
  1243. $PreviousFrames[] = $frame_name.$source_data_array['language'];
  1244. }
  1245. break;
  1246. case 'USLT':
  1247. case 'SYLT':
  1248. case 'COMM':
  1249. if (!isset($source_data_array['language'])) {
  1250. $this->errors[] = '[language] not specified for '.$frame_name;
  1251. } elseif (!isset($source_data_array['description'])) {
  1252. $this->errors[] = '[description] not specified for '.$frame_name;
  1253. } elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) {
  1254. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')';
  1255. } else {
  1256. $PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description'];
  1257. }
  1258. break;
  1259. case 'POPM':
  1260. if (!isset($source_data_array['email'])) {
  1261. $this->errors[] = '[email] not specified for '.$frame_name;
  1262. } elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) {
  1263. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')';
  1264. } else {
  1265. $PreviousFrames[] = $frame_name.$source_data_array['email'];
  1266. }
  1267. break;
  1268. case 'IPLS':
  1269. case 'MCDI':
  1270. case 'ETCO':
  1271. case 'MLLT':
  1272. case 'SYTC':
  1273. case 'RVAD':
  1274. case 'EQUA':
  1275. case 'RVRB':
  1276. case 'PCNT':
  1277. case 'RBUF':
  1278. case 'POSS':
  1279. case 'OWNE':
  1280. case 'RGAD':
  1281. if (in_array($frame_name, $PreviousFrames)) {
  1282. $this->errors[] = 'Only one '.$frame_name.' tag allowed';
  1283. } else {
  1284. $PreviousFrames[] = $frame_name;
  1285. }
  1286. break;
  1287. case 'LINK':
  1288. // this isn't implemented quite right (yet) - it should check the target frame data for compliance
  1289. // but right now it just allows one linked frame of each type, to be safe.
  1290. if (!isset($source_data_array['frameid'])) {
  1291. $this->errors[] = '[frameid] not specified for '.$frame_name;
  1292. } elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) {
  1293. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')';
  1294. } elseif (in_array($source_data_array['frameid'], $PreviousFrames)) {
  1295. // no links to singleton tags
  1296. $this->errors[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')';
  1297. } else {
  1298. $PreviousFrames[] = $frame_name.$source_data_array['frameid']; // only one linked tag of this type
  1299. $PreviousFrames[] = $source_data_array['frameid']; // no non-linked singleton tags of this type
  1300. }
  1301. break;
  1302. case 'COMR':
  1303. // There may be more than one 'commercial frame' in a tag, but no two may be identical
  1304. // Checking isn't implemented at all (yet) - just assumes that it's OK.
  1305. break;
  1306. case 'PRIV':
  1307. if (!isset($source_data_array['ownerid'])) {
  1308. $this->errors[] = '[ownerid] not specified for '.$frame_name;
  1309. } elseif (!isset($source_data_array['data'])) {
  1310. $this->errors[] = '[data] not specified for '.$frame_name;
  1311. } elseif (in_array($frame_name.$source_data_array['ownerid'].$source_data_array['data'], $PreviousFrames)) {
  1312. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID + Data ('.$source_data_array['ownerid'].' + '.$source_data_array['data'].')';
  1313. } else {
  1314. $PreviousFrames[] = $frame_name.$source_data_array['ownerid'].$source_data_array['data'];
  1315. }
  1316. break;
  1317. default:
  1318. if (($frame_name{0} != 'T') && ($frame_name{0} != 'W')) {
  1319. $this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name;
  1320. }
  1321. break;
  1322. }
  1323. } elseif ($this->majorversion == 2) {
  1324. switch ($frame_name) {
  1325. case 'UFI':
  1326. case 'CRM':
  1327. case 'CRA':
  1328. if (!isset($source_data_array['ownerid'])) {
  1329. $this->errors[] = '[ownerid] not specified for '.$frame_name;
  1330. } elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) {
  1331. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')';
  1332. } else {
  1333. $PreviousFrames[] = $frame_name.$source_data_array['ownerid'];
  1334. }
  1335. break;
  1336. case 'TXX':
  1337. case 'WXX':
  1338. case 'PIC':
  1339. case 'GEO':
  1340. if (!isset($source_data_array['description'])) {
  1341. $this->errors[] = '[description] not specified for '.$frame_name;
  1342. } elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) {
  1343. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')';
  1344. } else {
  1345. $PreviousFrames[] = $frame_name.$source_data_array['description'];
  1346. }
  1347. break;
  1348. case 'ULT':
  1349. case 'SLT':
  1350. case 'COM':
  1351. if (!isset($source_data_array['language'])) {
  1352. $this->errors[] = '[language] not specified for '.$frame_name;
  1353. } elseif (!isset($source_data_array['description'])) {
  1354. $this->errors[] = '[description] not specified for '.$frame_name;
  1355. } elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) {
  1356. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')';
  1357. } else {
  1358. $PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description'];
  1359. }
  1360. break;
  1361. case 'POP':
  1362. if (!isset($source_data_array['email'])) {
  1363. $this->errors[] = '[email] not specified for '.$frame_name;
  1364. } elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) {
  1365. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')';
  1366. } else {
  1367. $PreviousFrames[] = $frame_name.$source_data_array['email'];
  1368. }
  1369. break;
  1370. case 'IPL':
  1371. case 'MCI':
  1372. case 'ETC':
  1373. case 'MLL':
  1374. case 'STC':
  1375. case 'RVA':
  1376. case 'EQU':
  1377. case 'REV':
  1378. case 'CNT':
  1379. case 'BUF':
  1380. if (in_array($frame_name, $PreviousFrames)) {
  1381. $this->errors[] = 'Only one '.$frame_name.' tag allowed';
  1382. } else {
  1383. $PreviousFrames[] = $frame_name;
  1384. }
  1385. break;
  1386. case 'LNK':
  1387. // this isn't implemented quite right (yet) - it should check the target frame data for compliance
  1388. // but right now it just allows one linked frame of each type, to be safe.
  1389. if (!isset($source_data_array['frameid'])) {
  1390. $this->errors[] = '[frameid] not specified for '.$frame_name;
  1391. } elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) {
  1392. $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')';
  1393. } elseif (in_array($source_data_array['frameid'], $PreviousFrames)) {
  1394. // no links to singleton tags
  1395. $this->errors[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')';
  1396. } else {
  1397. $PreviousFrames[] = $frame_name.$source_data_array['frameid']; // only one linked tag of this type
  1398. $PreviousFrames[] = $source_data_array['frameid']; // no non-linked singleton tags of this type
  1399. }
  1400. break;
  1401. default:
  1402. if (($frame_name{0} != 'T') && ($frame_name{0} != 'W')) {
  1403. $this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name;
  1404. }
  1405. break;
  1406. }
  1407. }
  1408. if (!empty($this->errors)) {
  1409. return false;
  1410. }
  1411. return true;
  1412. }
  1413. public function GenerateID3v2Tag($noerrorsonly=true) {
  1414. $this->ID3v2FrameIsAllowed(null, ''); // clear static array in case this isn't the first call to $this->GenerateID3v2Tag()
  1415. $tagstring = '';
  1416. if (is_array($this->tag_data)) {
  1417. foreach ($this->tag_data as $frame_name => $frame_rawinputdata) {
  1418. foreach ($frame_rawinputdata as $irrelevantindex => $source_data_array) {
  1419. if (getid3_id3v2::IsValidID3v2FrameName($frame_name, $this->majorversion)) {
  1420. unset($frame_length);
  1421. unset($frame_flags);
  1422. $frame_data = false;
  1423. if ($this->ID3v2FrameIsAllowed($frame_name, $source_data_array)) {
  1424. if(array_key_exists('description', $source_data_array) && array_key_exists('encodingid', $source_data_array) && array_key_exists('encoding', $this->tag_data)) {
  1425. $source_data_array['description'] = getid3_lib::iconv_fallback($this->tag_data['encoding'], $source_data_array['encoding'], $source_data_array['description']);
  1426. }
  1427. if ($frame_data = $this->GenerateID3v2FrameData($frame_name, $source_data_array)) {
  1428. $FrameUnsynchronisation = false;
  1429. if ($this->majorversion >= 4) {
  1430. // frame-level unsynchronisation
  1431. $unsynchdata = $frame_data;
  1432. if ($this->id3v2_use_unsynchronisation) {
  1433. $unsynchdata = $this->Unsynchronise($frame_data);
  1434. }
  1435. if (strlen($unsynchdata) != strlen($frame_data)) {
  1436. // unsynchronisation needed
  1437. $FrameUnsynchronisation = true;
  1438. $frame_data = $unsynchdata;
  1439. if (isset($TagUnsynchronisation) && $TagUnsynchronisation === false) {
  1440. // only set to true if ALL frames are unsynchronised
  1441. } else {
  1442. $TagUnsynchronisation = true;
  1443. }
  1444. } else {
  1445. if (isset($TagUnsynchronisation)) {
  1446. $TagUnsynchronisation = false;
  1447. }
  1448. }
  1449. unset($unsynchdata);
  1450. $frame_length = getid3_lib::BigEndian2String(strlen($frame_data), 4, true);
  1451. } else {
  1452. $frame_length = getid3_lib::BigEndian2String(strlen($frame_data), 4, false);
  1453. }
  1454. $frame_flags = $this->GenerateID3v2FrameFlags($this->ID3v2FrameFlagsLookupTagAlter($frame_name), $this->ID3v2FrameFlagsLookupFileAlter($frame_name), false, false, false, false, $FrameUnsynchronisation, false);
  1455. }
  1456. } else {
  1457. $this->errors[] = 'Frame "'.$frame_name.'" is NOT allowed';
  1458. }
  1459. if ($frame_data === false) {
  1460. $this->errors[] = '$this->GenerateID3v2FrameData() failed for "'.$frame_name.'"';
  1461. if ($noerrorsonly) {
  1462. return false;
  1463. } else {
  1464. unset($frame_name);
  1465. }
  1466. }
  1467. } else {
  1468. // ignore any invalid frame names, including 'title', 'header', etc
  1469. $this->warnings[] = 'Ignoring invalid ID3v2 frame type: "'.$frame_name.'"';
  1470. unset($frame_name);
  1471. unset($frame_length);
  1472. unset($frame_flags);
  1473. unset($frame_data);
  1474. }
  1475. if (isset($frame_name) && isset($frame_length) && isset($frame_flags) && isset($frame_data)) {
  1476. $tagstring .= $frame_name.$frame_length.$frame_flags.$frame_data;
  1477. }
  1478. }
  1479. }
  1480. if (!isset($TagUnsynchronisation)) {
  1481. $TagUnsynchronisation = false;
  1482. }
  1483. if (($this->majorversion <= 3) && $this->id3v2_use_unsynchronisation) {
  1484. // tag-level unsynchronisation
  1485. $unsynchdata = $this->Unsynchronise($tagstring);
  1486. if (strlen($unsynchdata) != strlen($tagstring)) {
  1487. // unsynchronisation needed
  1488. $TagUnsynchronisation = true;
  1489. $tagstring = $unsynchdata;
  1490. }
  1491. }
  1492. while ($this->paddedlength < (strlen($tagstring) + getid3_id3v2::ID3v2HeaderLength($this->majorversion))) {
  1493. $this->paddedlength += 1024;
  1494. }
  1495. $footer = false; // ID3v2 footers not yet supported in getID3()
  1496. if (!$footer && ($this->paddedlength > (strlen($tagstring) + getid3_id3v2::ID3v2HeaderLength($this->majorversion)))) {
  1497. // pad up to $paddedlength bytes if unpadded tag is shorter than $paddedlength
  1498. // "Furthermore it MUST NOT have any padding when a tag footer is added to the tag."
  1499. if (($this->paddedlength - strlen($tagstring) - getid3_id3v2::ID3v2HeaderLength($this->majorversion)) > 0) {
  1500. $tagstring .= str_repeat("\x00", $this->paddedlength - strlen($tagstring) - getid3_id3v2::ID3v2HeaderLength($this->majorversion));
  1501. }
  1502. }
  1503. if ($this->id3v2_use_unsynchronisation && (substr($tagstring, strlen($tagstring) - 1, 1) == "\xFF")) {
  1504. // special unsynchronisation case:
  1505. // if last byte == $FF then appended a $00
  1506. $TagUnsynchronisation = true;
  1507. $tagstring .= "\x00";
  1508. }
  1509. $tagheader = 'ID3';
  1510. $tagheader .= chr($this->majorversion);
  1511. $tagheader .= chr($this->minorversion);
  1512. $tagheader .= $this->GenerateID3v2TagFlags(array('unsynchronisation'=>$TagUnsynchronisation));
  1513. $tagheader .= getid3_lib::BigEndian2String(strlen($tagstring), 4, true);
  1514. return $tagheader.$tagstring;
  1515. }
  1516. $this->errors[] = 'tag_data is not an array in GenerateID3v2Tag()';
  1517. return false;
  1518. }
  1519. public function ID3v2IsValidPriceString($pricestring) {
  1520. if (getid3_id3v2::LanguageLookup(substr($pricestring, 0, 3), true) == '') {
  1521. return false;
  1522. } elseif (!$this->IsANumber(substr($pricestring, 3), true)) {
  1523. return false;
  1524. }
  1525. return true;
  1526. }
  1527. public function ID3v2FrameFlagsLookupTagAlter($framename) {
  1528. // unfinished
  1529. switch ($framename) {
  1530. case 'RGAD':
  1531. $allow = true;
  1532. default:
  1533. $allow = false;
  1534. break;
  1535. }
  1536. return $allow;
  1537. }
  1538. public function ID3v2FrameFlagsLookupFileAlter($framename) {
  1539. // unfinished
  1540. switch ($framename) {
  1541. case 'RGAD':
  1542. return false;
  1543. break;
  1544. default:
  1545. return false;
  1546. break;
  1547. }
  1548. }
  1549. public function ID3v2IsValidETCOevent($eventid) {
  1550. if (($eventid < 0) || ($eventid > 0xFF)) {
  1551. // outside range of 1 byte
  1552. return false;
  1553. } elseif (($eventid >= 0xF0) && ($eventid <= 0xFC)) {
  1554. // reserved for future use
  1555. return false;
  1556. } elseif (($eventid >= 0x17) && ($eventid <= 0xDF)) {
  1557. // reserved for future use
  1558. return false;
  1559. } elseif (($eventid >= 0x0E) && ($eventid <= 0x16) && ($this->majorversion == 2)) {
  1560. // not defined in ID3v2.2
  1561. return false;
  1562. } elseif (($eventid >= 0x15) && ($eventid <= 0x16) && ($this->majorversion == 3)) {
  1563. // not defined in ID3v2.3
  1564. return false;
  1565. }
  1566. return true;
  1567. }
  1568. public function ID3v2IsValidSYLTtype($contenttype) {
  1569. if (($contenttype >= 0) && ($contenttype <= 8) && ($this->majorversion == 4)) {
  1570. return true;
  1571. } elseif (($contenttype >= 0) && ($contenttype <= 6) && ($this->majorversion == 3)) {
  1572. return true;
  1573. }
  1574. return false;
  1575. }
  1576. public function ID3v2IsValidRVA2channeltype($channeltype) {
  1577. if (($channeltype >= 0) && ($channeltype <= 8) && ($this->majorversion == 4)) {
  1578. return true;
  1579. }
  1580. return false;
  1581. }
  1582. public function ID3v2IsValidAPICpicturetype($picturetype) {
  1583. if (($picturetype >= 0) && ($picturetype <= 0x14) && ($this->majorversion >= 2) && ($this->majorversion <= 4)) {
  1584. return true;
  1585. }
  1586. return false;
  1587. }
  1588. public function ID3v2IsValidAPICimageformat($imageformat) {
  1589. if ($imageformat == '-->') {
  1590. return true;
  1591. } elseif ($this->majorversion == 2) {
  1592. if ((strlen($imageformat) == 3) && ($imageformat == strtoupper($imageformat))) {
  1593. return true;
  1594. }
  1595. } elseif (($this->majorversion == 3) || ($this->majorversion == 4)) {
  1596. if ($this->IsValidMIMEstring($imageformat)) {
  1597. return true;
  1598. }
  1599. }
  1600. return false;
  1601. }
  1602. public function ID3v2IsValidCOMRreceivedAs($receivedas) {
  1603. if (($this->majorversion >= 3) && ($receivedas >= 0) && ($receivedas <= 8)) {
  1604. return true;
  1605. }
  1606. return false;
  1607. }
  1608. public function ID3v2IsValidRGADname($RGADname) {
  1609. if (($RGADname >= 0) && ($RGADname <= 2)) {
  1610. return true;
  1611. }
  1612. return false;
  1613. }
  1614. public function ID3v2IsValidRGADoriginator($RGADoriginator) {
  1615. if (($RGADoriginator >= 0) && ($RGADoriginator <= 3)) {
  1616. return true;
  1617. }
  1618. return false;
  1619. }
  1620. public function ID3v2IsValidTextEncoding($textencodingbyte) {
  1621. // 0 = ISO-8859-1
  1622. // 1 = UTF-16 with BOM
  1623. // 2 = UTF-16BE without BOM
  1624. // 3 = UTF-8
  1625. static $ID3v2IsValidTextEncoding_cache = array(
  1626. 2 => array(true, true), // ID3v2.2 - allow 0=ISO-8859-1, 1=UTF-16
  1627. 3 => array(true, true), // ID3v2.3 - allow 0=ISO-8859-1, 1=UTF-16
  1628. 4 => array(true, true, true, true), // ID3v2.4 - allow 0=ISO-8859-1, 1=UTF-16, 2=UTF-16BE, 3=UTF-8
  1629. );
  1630. return isset($ID3v2IsValidTextEncoding_cache[$this->majorversion][$textencodingbyte]);
  1631. }
  1632. public function Unsynchronise($data) {
  1633. // Whenever a false synchronisation is found within the tag, one zeroed
  1634. // byte is inserted after the first false synchronisation byte. The
  1635. // format of a correct sync that should be altered by ID3 encoders is as
  1636. // follows:
  1637. // %11111111 111xxxxx
  1638. // And should be replaced with:
  1639. // %11111111 00000000 111xxxxx
  1640. // This has the side effect that all $FF 00 combinations have to be
  1641. // altered, so they won't be affected by the decoding process. Therefore
  1642. // all the $FF 00 combinations have to be replaced with the $FF 00 00
  1643. // combination during the unsynchronisation.
  1644. $data = str_replace("\xFF\x00", "\xFF\x00\x00", $data);
  1645. $unsyncheddata = '';
  1646. $datalength = strlen($data);
  1647. for ($i = 0; $i < $datalength; $i++) {
  1648. $thischar = $data{$i};
  1649. $unsyncheddata .= $thischar;
  1650. if ($thischar == "\xFF") {
  1651. $nextchar = ord($data{$i + 1});
  1652. if (($nextchar & 0xE0) == 0xE0) {
  1653. // previous byte = 11111111, this byte = 111?????
  1654. $unsyncheddata .= "\x00";
  1655. }
  1656. }
  1657. }
  1658. return $unsyncheddata;
  1659. }
  1660. public function is_hash($var) {
  1661. // written by dev-nullØchristophe*vg
  1662. // taken from http://www.php.net/manual/en/function.array-merge-recursive.php
  1663. if (is_array($var)) {
  1664. $keys = array_keys($var);
  1665. $all_num = true;
  1666. for ($i = 0; $i < count($keys); $i++) {
  1667. if (is_string($keys[$i])) {
  1668. return true;
  1669. }
  1670. }
  1671. }
  1672. return false;
  1673. }
  1674. public function array_join_merge($arr1, $arr2) {
  1675. // written by dev-nullØchristophe*vg
  1676. // taken from http://www.php.net/manual/en/function.array-merge-recursive.php
  1677. if (is_array($arr1) && is_array($arr2)) {
  1678. // the same -> merge
  1679. $new_array = array();
  1680. if ($this->is_hash($arr1) && $this->is_hash($arr2)) {
  1681. // hashes -> merge based on keys
  1682. $keys = array_merge(array_keys($arr1), array_keys($arr2));
  1683. foreach ($keys as $key) {
  1684. $new_array[$key] = $this->array_join_merge((isset($arr1[$key]) ? $arr1[$key] : ''), (isset($arr2[$key]) ? $arr2[$key] : ''));
  1685. }
  1686. } else {
  1687. // two real arrays -> merge
  1688. $new_array = array_reverse(array_unique(array_reverse(array_merge($arr1, $arr2))));
  1689. }
  1690. return $new_array;
  1691. } else {
  1692. // not the same ... take new one if defined, else the old one stays
  1693. return $arr2 ? $arr2 : $arr1;
  1694. }
  1695. }
  1696. public function IsValidMIMEstring($mimestring) {
  1697. if ((strlen($mimestring) >= 3) && (strpos($mimestring, '/') > 0) && (strpos($mimestring, '/') < (strlen($mimestring) - 1))) {
  1698. return true;
  1699. }
  1700. return false;
  1701. }
  1702. public function IsWithinBitRange($number, $maxbits, $signed=false) {
  1703. if ($signed) {
  1704. if (($number > (0 - pow(2, $maxbits - 1))) && ($number <= pow(2, $maxbits - 1))) {
  1705. return true;
  1706. }
  1707. } else {
  1708. if (($number >= 0) && ($number <= pow(2, $maxbits))) {
  1709. return true;
  1710. }
  1711. }
  1712. return false;
  1713. }
  1714. public function safe_parse_url($url) {
  1715. $parts = @parse_url($url);
  1716. $parts['scheme'] = (isset($parts['scheme']) ? $parts['scheme'] : '');
  1717. $parts['host'] = (isset($parts['host']) ? $parts['host'] : '');
  1718. $parts['user'] = (isset($parts['user']) ? $parts['user'] : '');
  1719. $parts['pass'] = (isset($parts['pass']) ? $parts['pass'] : '');
  1720. $parts['path'] = (isset($parts['path']) ? $parts['path'] : '');
  1721. $parts['query'] = (isset($parts['query']) ? $parts['query'] : '');
  1722. return $parts;
  1723. }
  1724. public function IsValidURL($url, $allowUserPass=false) {
  1725. if ($url == '') {
  1726. return false;
  1727. }
  1728. if ($allowUserPass !== true) {
  1729. if (strstr($url, '@')) {
  1730. // in the format http://user:pass@example.com or http://user@example.com
  1731. // but could easily be somebody incorrectly entering an email address in place of a URL
  1732. return false;
  1733. }
  1734. }
  1735. if ($parts = $this->safe_parse_url($url)) {
  1736. if (($parts['scheme'] != 'http') && ($parts['scheme'] != 'https') && ($parts['scheme'] != 'ftp') && ($parts['scheme'] != 'gopher')) {
  1737. return false;
  1738. } elseif (!preg_match('#^[[:alnum:]]([-.]?[0-9a-z])*\\.[a-z]{2,3}$#i', $parts['host'], $regs) && !preg_match('#^[0-9]{1,3}(\\.[0-9]{1,3}){3}$#', $parts['host'])) {
  1739. return false;
  1740. } elseif (!preg_match('#^([[:alnum:]-]|[\\_])*$#i', $parts['user'], $regs)) {
  1741. return false;
  1742. } elseif (!preg_match('#^([[:alnum:]-]|[\\_])*$#i', $parts['pass'], $regs)) {
  1743. return false;
  1744. } elseif (!preg_match('#^[[:alnum:]/_\\.@~-]*$#i', $parts['path'], $regs)) {
  1745. return false;
  1746. } elseif (!empty($parts['query']) && !preg_match('#^[[:alnum:]?&=+:;_()%\\#/,\\.-]*$#i', $parts['query'], $regs)) {
  1747. return false;
  1748. } else {
  1749. return true;
  1750. }
  1751. }
  1752. return false;
  1753. }
  1754. public static function ID3v2ShortFrameNameLookup($majorversion, $long_description) {
  1755. $long_description = str_replace(' ', '_', strtolower(trim($long_description)));
  1756. static $ID3v2ShortFrameNameLookup = array();
  1757. if (empty($ID3v2ShortFrameNameLookup)) {
  1758. // The following are unique to ID3v2.2
  1759. $ID3v2ShortFrameNameLookup[2]['comment'] = 'COM';
  1760. $ID3v2ShortFrameNameLookup[2]['album'] = 'TAL';
  1761. $ID3v2ShortFrameNameLookup[2]['beats_per_minute'] = 'TBP';
  1762. $ID3v2ShortFrameNameLookup[2]['bpm'] = 'TBP';
  1763. $ID3v2ShortFrameNameLookup[2]['composer'] = 'TCM';
  1764. $ID3v2ShortFrameNameLookup[2]['genre'] = 'TCO';
  1765. $ID3v2ShortFrameNameLookup[2]['itunescompilation'] = 'TCP';
  1766. $ID3v2ShortFrameNameLookup[2]['copyright'] = 'TCR';
  1767. $ID3v2ShortFrameNameLookup[2]['encoded_by'] = 'TEN';
  1768. $ID3v2ShortFrameNameLookup[2]['language'] = 'TLA';
  1769. $ID3v2ShortFrameNameLookup[2]['length'] = 'TLE';
  1770. $ID3v2ShortFrameNameLookup[2]['original_artist'] = 'TOA';
  1771. $ID3v2ShortFrameNameLookup[2]['original_filename'] = 'TOF';
  1772. $ID3v2ShortFrameNameLookup[2]['original_lyricist'] = 'TOL';
  1773. $ID3v2ShortFrameNameLookup[2]['original_album_title'] = 'TOT';
  1774. $ID3v2ShortFrameNameLookup[2]['artist'] = 'TP1';
  1775. $ID3v2ShortFrameNameLookup[2]['band'] = 'TP2';
  1776. $ID3v2ShortFrameNameLookup[2]['conductor'] = 'TP3';
  1777. $ID3v2ShortFrameNameLookup[2]['remixer'] = 'TP4';
  1778. $ID3v2ShortFrameNameLookup[2]['publisher'] = 'TPB';
  1779. $ID3v2ShortFrameNameLookup[2]['isrc'] = 'TRC';
  1780. $ID3v2ShortFrameNameLookup[2]['tracknumber'] = 'TRK';
  1781. $ID3v2ShortFrameNameLookup[2]['track_number'] = 'TRK';
  1782. $ID3v2ShortFrameNameLookup[2]['size'] = 'TSI';
  1783. $ID3v2ShortFrameNameLookup[2]['encoder_settings'] = 'TSS';
  1784. $ID3v2ShortFrameNameLookup[2]['description'] = 'TT1';
  1785. $ID3v2ShortFrameNameLookup[2]['title'] = 'TT2';
  1786. $ID3v2ShortFrameNameLookup[2]['subtitle'] = 'TT3';
  1787. $ID3v2ShortFrameNameLookup[2]['lyricist'] = 'TXT';
  1788. $ID3v2ShortFrameNameLookup[2]['user_text'] = 'TXX';
  1789. $ID3v2ShortFrameNameLookup[2]['year'] = 'TYE';
  1790. $ID3v2ShortFrameNameLookup[2]['unique_file_identifier'] = 'UFI';
  1791. $ID3v2ShortFrameNameLookup[2]['unsynchronised_lyrics'] = 'ULT';
  1792. $ID3v2ShortFrameNameLookup[2]['url_file'] = 'WAF';
  1793. $ID3v2ShortFrameNameLookup[2]['url_artist'] = 'WAR';
  1794. $ID3v2ShortFrameNameLookup[2]['url_source'] = 'WAS';
  1795. $ID3v2ShortFrameNameLookup[2]['copyright_information'] = 'WCP';
  1796. $ID3v2ShortFrameNameLookup[2]['url_publisher'] = 'WPB';
  1797. $ID3v2ShortFrameNameLookup[2]['url_user'] = 'WXX';
  1798. // The following are common to ID3v2.3 and ID3v2.4
  1799. $ID3v2ShortFrameNameLookup[3]['audio_encryption'] = 'AENC';
  1800. $ID3v2ShortFrameNameLookup[3]['attached_picture'] = 'APIC';
  1801. $ID3v2ShortFrameNameLookup[3]['picture'] = 'APIC';
  1802. $ID3v2ShortFrameNameLookup[3]['comment'] = 'COMM';
  1803. $ID3v2ShortFrameNameLookup[3]['commercial'] = 'COMR';
  1804. $ID3v2ShortFrameNameLookup[3]['encryption_method_registration'] = 'ENCR';
  1805. $ID3v2ShortFrameNameLookup[3]['event_timing_codes'] = 'ETCO';
  1806. $ID3v2ShortFrameNameLookup[3]['general_encapsulated_object'] = 'GEOB';
  1807. $ID3v2ShortFrameNameLookup[3]['group_identification_registration'] = 'GRID';
  1808. $ID3v2ShortFrameNameLookup[3]['linked_information'] = 'LINK';
  1809. $ID3v2ShortFrameNameLookup[3]['music_cd_identifier'] = 'MCDI';
  1810. $ID3v2ShortFrameNameLookup[3]['mpeg_location_lookup_table'] = 'MLLT';
  1811. $ID3v2ShortFrameNameLookup[3]['ownership'] = 'OWNE';
  1812. $ID3v2ShortFrameNameLookup[3]['play_counter'] = 'PCNT';
  1813. $ID3v2ShortFrameNameLookup[3]['popularimeter'] = 'POPM';
  1814. $ID3v2ShortFrameNameLookup[3]['position_synchronisation'] = 'POSS';
  1815. $ID3v2ShortFrameNameLookup[3]['private'] = 'PRIV';
  1816. $ID3v2ShortFrameNameLookup[3]['recommended_buffer_size'] = 'RBUF';
  1817. $ID3v2ShortFrameNameLookup[3]['reverb'] = 'RVRB';
  1818. $ID3v2ShortFrameNameLookup[3]['synchronised_lyrics'] = 'SYLT';
  1819. $ID3v2ShortFrameNameLookup[3]['synchronised_tempo_codes'] = 'SYTC';
  1820. $ID3v2ShortFrameNameLookup[3]['album'] = 'TALB';
  1821. $ID3v2ShortFrameNameLookup[3]['beats_per_minute'] = 'TBPM';
  1822. $ID3v2ShortFrameNameLookup[3]['bpm'] = 'TBPM';
  1823. $ID3v2ShortFrameNameLookup[3]['itunescompilation'] = 'TCMP';
  1824. $ID3v2ShortFrameNameLookup[3]['composer'] = 'TCOM';
  1825. $ID3v2ShortFrameNameLookup[3]['genre'] = 'TCON';
  1826. $ID3v2ShortFrameNameLookup[3]['copyright'] = 'TCOP';
  1827. $ID3v2ShortFrameNameLookup[3]['playlist_delay'] = 'TDLY';
  1828. $ID3v2ShortFrameNameLookup[3]['encoded_by'] = 'TENC';
  1829. $ID3v2ShortFrameNameLookup[3]['lyricist'] = 'TEXT';
  1830. $ID3v2ShortFrameNameLookup[3]['file_type'] = 'TFLT';
  1831. $ID3v2ShortFrameNameLookup[3]['content_group_description'] = 'TIT1';
  1832. $ID3v2ShortFrameNameLookup[3]['title'] = 'TIT2';
  1833. $ID3v2ShortFrameNameLookup[3]['subtitle'] = 'TIT3';
  1834. $ID3v2ShortFrameNameLookup[3]['initial_key'] = 'TKEY';
  1835. $ID3v2ShortFrameNameLookup[3]['language'] = 'TLAN';
  1836. $ID3v2ShortFrameNameLookup[3]['length'] = 'TLEN';
  1837. $ID3v2ShortFrameNameLookup[3]['media_type'] = 'TMED';
  1838. $ID3v2ShortFrameNameLookup[3]['original_album_title'] = 'TOAL';
  1839. $ID3v2ShortFrameNameLookup[3]['original_filename'] = 'TOFN';
  1840. $ID3v2ShortFrameNameLookup[3]['original_lyricist'] = 'TOLY';
  1841. $ID3v2ShortFrameNameLookup[3]['original_artist'] = 'TOPE';
  1842. $ID3v2ShortFrameNameLookup[3]['file_owner'] = 'TOWN';
  1843. $ID3v2ShortFrameNameLookup[3]['artist'] = 'TPE1';
  1844. $ID3v2ShortFrameNameLookup[3]['band'] = 'TPE2';
  1845. $ID3v2ShortFrameNameLookup[3]['conductor'] = 'TPE3';
  1846. $ID3v2ShortFrameNameLookup[3]['remixer'] = 'TPE4';
  1847. $ID3v2ShortFrameNameLookup[3]['part_of_a_set'] = 'TPOS';
  1848. $ID3v2ShortFrameNameLookup[3]['publisher'] = 'TPUB';
  1849. $ID3v2ShortFrameNameLookup[3]['tracknumber'] = 'TRCK';
  1850. $ID3v2ShortFrameNameLookup[3]['track_number'] = 'TRCK';
  1851. $ID3v2ShortFrameNameLookup[3]['internet_radio_station_name'] = 'TRSN';
  1852. $ID3v2ShortFrameNameLookup[3]['internet_radio_station_owner'] = 'TRSO';
  1853. $ID3v2ShortFrameNameLookup[3]['isrc'] = 'TSRC';
  1854. $ID3v2ShortFrameNameLookup[3]['encoder_settings'] = 'TSSE';
  1855. $ID3v2ShortFrameNameLookup[3]['user_text'] = 'TXXX';
  1856. $ID3v2ShortFrameNameLookup[3]['unique_file_identifier'] = 'UFID';
  1857. $ID3v2ShortFrameNameLookup[3]['terms_of_use'] = 'USER';
  1858. $ID3v2ShortFrameNameLookup[3]['unsynchronised_lyrics'] = 'USLT';
  1859. $ID3v2ShortFrameNameLookup[3]['commercial'] = 'WCOM';
  1860. $ID3v2ShortFrameNameLookup[3]['copyright_information'] = 'WCOP';
  1861. $ID3v2ShortFrameNameLookup[3]['url_file'] = 'WOAF';
  1862. $ID3v2ShortFrameNameLookup[3]['url_artist'] = 'WOAR';
  1863. $ID3v2ShortFrameNameLookup[3]['url_source'] = 'WOAS';
  1864. $ID3v2ShortFrameNameLookup[3]['url_station'] = 'WORS';
  1865. $ID3v2ShortFrameNameLookup[3]['payment'] = 'WPAY';
  1866. $ID3v2ShortFrameNameLookup[3]['url_publisher'] = 'WPUB';
  1867. $ID3v2ShortFrameNameLookup[3]['url_user'] = 'WXXX';
  1868. // The above are common to ID3v2.3 and ID3v2.4
  1869. // so copy them to ID3v2.4 before adding specifics for 2.3 and 2.4
  1870. $ID3v2ShortFrameNameLookup[4] = $ID3v2ShortFrameNameLookup[3];
  1871. // The following are unique to ID3v2.3
  1872. $ID3v2ShortFrameNameLookup[3]['equalisation'] = 'EQUA';
  1873. $ID3v2ShortFrameNameLookup[3]['involved_people_list'] = 'IPLS';
  1874. $ID3v2ShortFrameNameLookup[3]['relative_volume_adjustment'] = 'RVAD';
  1875. $ID3v2ShortFrameNameLookup[3]['date'] = 'TDAT';
  1876. $ID3v2ShortFrameNameLookup[3]['time'] = 'TIME';
  1877. $ID3v2ShortFrameNameLookup[3]['original_release_year'] = 'TORY';
  1878. $ID3v2ShortFrameNameLookup[3]['recording_dates'] = 'TRDA';
  1879. $ID3v2ShortFrameNameLookup[3]['size'] = 'TSIZ';
  1880. $ID3v2ShortFrameNameLookup[3]['year'] = 'TYER';
  1881. // The following are unique to ID3v2.4
  1882. $ID3v2ShortFrameNameLookup[4]['audio_seek_point_index'] = 'ASPI';
  1883. $ID3v2ShortFrameNameLookup[4]['equalisation'] = 'EQU2';
  1884. $ID3v2ShortFrameNameLookup[4]['relative_volume_adjustment'] = 'RVA2';
  1885. $ID3v2ShortFrameNameLookup[4]['seek'] = 'SEEK';
  1886. $ID3v2ShortFrameNameLookup[4]['signature'] = 'SIGN';
  1887. $ID3v2ShortFrameNameLookup[4]['encoding_time'] = 'TDEN';
  1888. $ID3v2ShortFrameNameLookup[4]['original_release_time'] = 'TDOR';
  1889. $ID3v2ShortFrameNameLookup[4]['recording_time'] = 'TDRC';
  1890. $ID3v2ShortFrameNameLookup[4]['release_time'] = 'TDRL';
  1891. $ID3v2ShortFrameNameLookup[4]['tagging_time'] = 'TDTG';
  1892. $ID3v2ShortFrameNameLookup[4]['involved_people_list'] = 'TIPL';
  1893. $ID3v2ShortFrameNameLookup[4]['musician_credits_list'] = 'TMCL';
  1894. $ID3v2ShortFrameNameLookup[4]['mood'] = 'TMOO';
  1895. $ID3v2ShortFrameNameLookup[4]['produced_notice'] = 'TPRO';
  1896. $ID3v2ShortFrameNameLookup[4]['album_sort_order'] = 'TSOA';
  1897. $ID3v2ShortFrameNameLookup[4]['performer_sort_order'] = 'TSOP';
  1898. $ID3v2ShortFrameNameLookup[4]['title_sort_order'] = 'TSOT';
  1899. $ID3v2ShortFrameNameLookup[4]['set_subtitle'] = 'TSST';
  1900. }
  1901. return (isset($ID3v2ShortFrameNameLookup[$majorversion][strtolower($long_description)]) ? $ID3v2ShortFrameNameLookup[$majorversion][strtolower($long_description)] : '');
  1902. }
  1903. }