PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/blog/wp-content/plugins/podpress/getid3/write.id3v2.php

https://bitbucket.org/sergiohzlz/reportaprod
PHP | 2054 lines | 1580 code | 162 blank | 312 comment | 427 complexity | cb711b042af8c2809db0c6ff567ee9fc MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  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. /////////////////////////////////////////////////////////////////
  7. // See readme.txt for more details //
  8. /////////////////////////////////////////////////////////////////
  9. /// //
  10. // write.id3v2.php //
  11. // module for writing ID3v2 tags //
  12. // dependencies: module.tag.id3v2.php //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
  16. class getid3_write_id3v2
  17. {
  18. var $filename;
  19. var $tag_data;
  20. var $paddedlength = 4096; // minimum length of ID3v2 tag in bytes
  21. var $majorversion = 3; // ID3v2 major version (2, 3 (recommended), 4)
  22. var $minorversion = 0; // ID3v2 minor version - always 0
  23. var $merge_existing_data = false; // if true, merge new data with existing tags; if false, delete old tag data and only write new tags
  24. var $id3v2_default_encodingid = 0; // default text encoding (ISO-8859-1) if not explicitly passed
  25. var $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.
  26. var $warnings = array(); // any non-critical errors will be stored here
  27. var $errors = array(); // any critical errors will be stored here
  28. function getid3_write_id3v2() {
  29. return true;
  30. }
  31. function WriteID3v2() {
  32. // File MUST be writeable - CHMOD(646) at least. It's best if the
  33. // directory is also writeable, because that method is both faster and less susceptible to errors.
  34. if (is_writeable($this->filename) || (!file_exists($this->filename) && is_writeable(dirname($this->filename)))) {
  35. // Initialize getID3 engine
  36. $getID3 = new getID3;
  37. $OldThisFileInfo = $getID3->analyze($this->filename);
  38. if ($OldThisFileInfo['filesize'] >= pow(2, 31)) {
  39. $this->errors[] = 'Unable to write ID3v2 because file is larger than 2GB';
  40. fclose($fp_source);
  41. return false;
  42. }
  43. if ($this->merge_existing_data) {
  44. // merge with existing data
  45. if (!empty($OldThisFileInfo['id3v2'])) {
  46. $this->tag_data = $this->array_join_merge($OldThisFileInfo['id3v2'], $this->tag_data);
  47. }
  48. }
  49. $this->paddedlength = max(@$OldThisFileInfo['id3v2']['headerlength'], $this->paddedlength);
  50. if ($NewID3v2Tag = $this->GenerateID3v2Tag()) {
  51. if (file_exists($this->filename) && is_writeable($this->filename) && isset($OldThisFileInfo['id3v2']['headerlength']) && ($OldThisFileInfo['id3v2']['headerlength'] == strlen($NewID3v2Tag))) {
  52. // best and fastest method - insert-overwrite existing tag (padded to length of old tag if neccesary)
  53. if (file_exists($this->filename)) {
  54. ob_start();
  55. if ($fp = fopen($this->filename, 'r+b')) {
  56. rewind($fp);
  57. fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag));
  58. fclose($fp);
  59. } else {
  60. $this->errors[] = 'Could not open '.$this->filename.' mode "r+b" - '.strip_tags(ob_get_contents());
  61. }
  62. ob_end_clean();
  63. } else {
  64. ob_start();
  65. if ($fp = fopen($this->filename, 'wb')) {
  66. rewind($fp);
  67. fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag));
  68. fclose($fp);
  69. } else {
  70. $this->errors[] = 'Could not open '.$this->filename.' mode "wb" - '.strip_tags(ob_get_contents());
  71. }
  72. ob_end_clean();
  73. }
  74. } else {
  75. if ($tempfilename = tempnam((function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : ini_get('upload_tmp_dir')), 'getID3')) {
  76. ob_start();
  77. if ($fp_source = fopen($this->filename, 'rb')) {
  78. if ($fp_temp = fopen($tempfilename, 'wb')) {
  79. fwrite($fp_temp, $NewID3v2Tag, strlen($NewID3v2Tag));
  80. rewind($fp_source);
  81. if (!empty($OldThisFileInfo['avdataoffset'])) {
  82. fseek($fp_source, $OldThisFileInfo['avdataoffset'], SEEK_SET);
  83. }
  84. while ($buffer = fread($fp_source, GETID3_FREAD_BUFFER_SIZE)) {
  85. fwrite($fp_temp, $buffer, strlen($buffer));
  86. }
  87. fclose($fp_temp);
  88. fclose($fp_source);
  89. copy($tempfilename, $this->filename);
  90. unlink($tempfilename);
  91. ob_end_clean();
  92. return true;
  93. } else {
  94. $this->errors[] = 'Could not open '.$tempfilename.' mode "wb" - '.strip_tags(ob_get_contents());
  95. }
  96. fclose($fp_source);
  97. } else {
  98. $this->errors[] = 'Could not open '.$this->filename.' mode "rb" - '.strip_tags(ob_get_contents());
  99. }
  100. ob_end_clean();
  101. }
  102. return false;
  103. }
  104. } else {
  105. $this->errors[] = '$this->GenerateID3v2Tag() failed';
  106. }
  107. if (!empty($this->errors)) {
  108. return false;
  109. }
  110. return true;
  111. } else {
  112. $this->errors[] = '!is_writeable('.$this->filename.')';
  113. }
  114. return false;
  115. }
  116. function RemoveID3v2() {
  117. // File MUST be writeable - CHMOD(646) at least. It's best if the
  118. // directory is also writeable, because that method is both faster and less susceptible to errors.
  119. if (is_writeable(dirname($this->filename))) {
  120. // preferred method - only one copying operation, minimal chance of corrupting
  121. // original file if script is interrupted, but required directory to be writeable
  122. if ($fp_source = @fopen($this->filename, 'rb')) {
  123. // Initialize getID3 engine
  124. $getID3 = new getID3;
  125. $OldThisFileInfo = $getID3->analyze($this->filename);
  126. if ($OldThisFileInfo['filesize'] >= pow(2, 31)) {
  127. $this->errors[] = 'Unable to remove ID3v2 because file is larger than 2GB';
  128. fclose($fp_source);
  129. return false;
  130. }
  131. rewind($fp_source);
  132. if ($OldThisFileInfo['avdataoffset'] !== false) {
  133. fseek($fp_source, $OldThisFileInfo['avdataoffset'], SEEK_SET);
  134. }
  135. if ($fp_temp = @fopen($this->filename.'getid3tmp', 'w+b')) {
  136. while ($buffer = fread($fp_source, GETID3_FREAD_BUFFER_SIZE)) {
  137. fwrite($fp_temp, $buffer, strlen($buffer));
  138. }
  139. fclose($fp_temp);
  140. } else {
  141. $this->errors[] = 'Could not open '.$this->filename.'getid3tmp mode "w+b"';
  142. }
  143. fclose($fp_source);
  144. } else {
  145. $this->errors[] = 'Could not open '.$this->filename.' mode "rb"';
  146. }
  147. if (file_exists($this->filename)) {
  148. unlink($this->filename);
  149. }
  150. rename($this->filename.'getid3tmp', $this->filename);
  151. } elseif (is_writable($this->filename)) {
  152. // less desirable alternate method - double-copies the file, overwrites original file
  153. // and could corrupt source file if the script is interrupted or an error occurs.
  154. if ($fp_source = @fopen($this->filename, 'rb')) {
  155. // Initialize getID3 engine
  156. $getID3 = new getID3;
  157. $OldThisFileInfo = $getID3->analyze($this->filename);
  158. if ($OldThisFileInfo['filesize'] >= pow(2, 31)) {
  159. $this->errors[] = 'Unable to remove ID3v2 because file is larger than 2GB';
  160. fclose($fp_source);
  161. return false;
  162. }
  163. rewind($fp_source);
  164. if ($OldThisFileInfo['avdataoffset'] !== false) {
  165. fseek($fp_source, $OldThisFileInfo['avdataoffset'], SEEK_SET);
  166. }
  167. if ($fp_temp = tmpfile()) {
  168. while ($buffer = fread($fp_source, GETID3_FREAD_BUFFER_SIZE)) {
  169. fwrite($fp_temp, $buffer, strlen($buffer));
  170. }
  171. fclose($fp_source);
  172. if ($fp_source = @fopen($this->filename, 'wb')) {
  173. rewind($fp_temp);
  174. while ($buffer = fread($fp_temp, GETID3_FREAD_BUFFER_SIZE)) {
  175. fwrite($fp_source, $buffer, strlen($buffer));
  176. }
  177. fseek($fp_temp, -128, SEEK_END);
  178. fclose($fp_source);
  179. } else {
  180. $this->errors[] = 'Could not open '.$this->filename.' mode "wb"';
  181. }
  182. fclose($fp_temp);
  183. } else {
  184. $this->errors[] = 'Could not create tmpfile()';
  185. }
  186. } else {
  187. $this->errors[] = 'Could not open '.$this->filename.' mode "rb"';
  188. }
  189. } else {
  190. $this->errors[] = 'Directory and file both not writeable';
  191. }
  192. if (!empty($this->errors)) {
  193. return false;
  194. }
  195. return true;
  196. }
  197. function GenerateID3v2TagFlags($flags) {
  198. switch ($this->majorversion) {
  199. case 4:
  200. // %abcd0000
  201. $flag = (@$flags['unsynchronisation'] ? '1' : '0'); // a - Unsynchronisation
  202. $flag .= (@$flags['extendedheader'] ? '1' : '0'); // b - Extended header
  203. $flag .= (@$flags['experimental'] ? '1' : '0'); // c - Experimental indicator
  204. $flag .= (@$flags['footer'] ? '1' : '0'); // d - Footer present
  205. $flag .= '0000';
  206. break;
  207. case 3:
  208. // %abc00000
  209. $flag = (@$flags['unsynchronisation'] ? '1' : '0'); // a - Unsynchronisation
  210. $flag .= (@$flags['extendedheader'] ? '1' : '0'); // b - Extended header
  211. $flag .= (@$flags['experimental'] ? '1' : '0'); // c - Experimental indicator
  212. $flag .= '00000';
  213. break;
  214. case 2:
  215. // %ab000000
  216. $flag = (@$flags['unsynchronisation'] ? '1' : '0'); // a - Unsynchronisation
  217. $flag .= (@$flags['compression'] ? '1' : '0'); // b - Compression
  218. $flag .= '000000';
  219. break;
  220. default:
  221. return false;
  222. break;
  223. }
  224. return chr(bindec($flag));
  225. }
  226. function GenerateID3v2FrameFlags($TagAlter=false, $FileAlter=false, $ReadOnly=false, $Compression=false, $Encryption=false, $GroupingIdentity=false, $Unsynchronisation=false, $DataLengthIndicator=false) {
  227. switch ($this->majorversion) {
  228. case 4:
  229. // %0abc0000 %0h00kmnp
  230. $flag1 = '0';
  231. $flag1 .= $TagAlter ? '1' : '0'; // a - Tag alter preservation (true == discard)
  232. $flag1 .= $FileAlter ? '1' : '0'; // b - File alter preservation (true == discard)
  233. $flag1 .= $ReadOnly ? '1' : '0'; // c - Read only (true == read only)
  234. $flag1 .= '0000';
  235. $flag2 = '0';
  236. $flag2 .= $GroupingIdentity ? '1' : '0'; // h - Grouping identity (true == contains group information)
  237. $flag2 .= '00';
  238. $flag2 .= $Compression ? '1' : '0'; // k - Compression (true == compressed)
  239. $flag2 .= $Encryption ? '1' : '0'; // m - Encryption (true == encrypted)
  240. $flag2 .= $Unsynchronisation ? '1' : '0'; // n - Unsynchronisation (true == unsynchronised)
  241. $flag2 .= $DataLengthIndicator ? '1' : '0'; // p - Data length indicator (true == data length indicator added)
  242. break;
  243. case 3:
  244. // %abc00000 %ijk00000
  245. $flag1 = $TagAlter ? '1' : '0'; // a - Tag alter preservation (true == discard)
  246. $flag1 .= $FileAlter ? '1' : '0'; // b - File alter preservation (true == discard)
  247. $flag1 .= $ReadOnly ? '1' : '0'; // c - Read only (true == read only)
  248. $flag1 .= '00000';
  249. $flag2 = $Compression ? '1' : '0'; // i - Compression (true == compressed)
  250. $flag2 .= $Encryption ? '1' : '0'; // j - Encryption (true == encrypted)
  251. $flag2 .= $GroupingIdentity ? '1' : '0'; // k - Grouping identity (true == contains group information)
  252. $flag2 .= '00000';
  253. break;
  254. default:
  255. return false;
  256. break;
  257. }
  258. return chr(bindec($flag1)).chr(bindec($flag2));
  259. }
  260. function GenerateID3v2FrameData($frame_name, $source_data_array) {
  261. if (!getid3_id3v2::IsValidID3v2FrameName($frame_name, $this->majorversion)) {
  262. return false;
  263. }
  264. $framedata = '';
  265. if (($this->majorversion < 3) || ($this->majorversion > 4)) {
  266. $this->errors[] = 'Only ID3v2.3 and ID3v2.4 are supported in GenerateID3v2FrameData()';
  267. } else { // $this->majorversion 3 or 4
  268. switch ($frame_name) {
  269. case 'UFID':
  270. // 4.1 UFID Unique file identifier
  271. // Owner identifier <text string> $00
  272. // Identifier <up to 64 bytes binary data>
  273. if (strlen($source_data_array['data']) > 64) {
  274. $this->errors[] = 'Identifier not allowed to be longer than 64 bytes in '.$frame_name.' (supplied data was '.strlen($source_data_array['data']).' bytes long)';
  275. } else {
  276. $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
  277. $framedata .= substr($source_data_array['data'], 0, 64); // max 64 bytes - truncate anything longer
  278. }
  279. break;
  280. case 'TXXX':
  281. // 4.2.2 TXXX User defined text information frame
  282. // Text encoding $xx
  283. // Description <text string according to encoding> $00 (00)
  284. // Value <text string according to encoding>
  285. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  286. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) {
  287. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  288. } else {
  289. $framedata .= chr($source_data_array['encodingid']);
  290. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  291. $framedata .= $source_data_array['data'];
  292. }
  293. break;
  294. case 'WXXX':
  295. // 4.3.2 WXXX User defined URL link frame
  296. // Text encoding $xx
  297. // Description <text string according to encoding> $00 (00)
  298. // URL <text string>
  299. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  300. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) {
  301. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  302. } elseif (!isset($source_data_array['data']) || !$this->IsValidURL($source_data_array['data'], false, false)) {
  303. //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  304. // probably should be an error, need to rewrite IsValidURL() to handle other encodings
  305. $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  306. } else {
  307. $framedata .= chr($source_data_array['encodingid']);
  308. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  309. $framedata .= $source_data_array['data'];
  310. }
  311. break;
  312. case 'IPLS':
  313. // 4.4 IPLS Involved people list (ID3v2.3 only)
  314. // Text encoding $xx
  315. // People list strings <textstrings>
  316. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  317. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) {
  318. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  319. } else {
  320. $framedata .= chr($source_data_array['encodingid']);
  321. $framedata .= $source_data_array['data'];
  322. }
  323. break;
  324. case 'MCDI':
  325. // 4.4 MCDI Music CD identifier
  326. // CD TOC <binary data>
  327. $framedata .= $source_data_array['data'];
  328. break;
  329. case 'ETCO':
  330. // 4.5 ETCO Event timing codes
  331. // Time stamp format $xx
  332. // Where time stamp format is:
  333. // $01 (32-bit value) MPEG frames from beginning of file
  334. // $02 (32-bit value) milliseconds from beginning of file
  335. // Followed by a list of key events in the following format:
  336. // Type of event $xx
  337. // Time stamp $xx (xx ...)
  338. // The 'Time stamp' is set to zero if directly at the beginning of the sound
  339. // or after the previous event. All events MUST be sorted in chronological order.
  340. if (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) {
  341. $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
  342. } else {
  343. $framedata .= chr($source_data_array['timestampformat']);
  344. foreach ($source_data_array as $key => $val) {
  345. if (!$this->ID3v2IsValidETCOevent($val['typeid'])) {
  346. $this->errors[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')';
  347. } elseif (($key != 'timestampformat') && ($key != 'flags')) {
  348. if (($val['timestamp'] > 0) && ($previousETCOtimestamp >= $val['timestamp'])) {
  349. // The 'Time stamp' is set to zero if directly at the beginning of the sound
  350. // or after the previous event. All events MUST be sorted in chronological order.
  351. $this->errors[] = 'Out-of-order timestamp in '.$frame_name.' ('.$val['timestamp'].') for Event Type ('.$val['typeid'].')';
  352. } else {
  353. $framedata .= chr($val['typeid']);
  354. $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false);
  355. }
  356. }
  357. }
  358. }
  359. break;
  360. case 'MLLT':
  361. // 4.6 MLLT MPEG location lookup table
  362. // MPEG frames between reference $xx xx
  363. // Bytes between reference $xx xx xx
  364. // Milliseconds between reference $xx xx xx
  365. // Bits for bytes deviation $xx
  366. // Bits for milliseconds dev. $xx
  367. // Then for every reference the following data is included;
  368. // Deviation in bytes %xxx....
  369. // Deviation in milliseconds %xxx....
  370. if (($source_data_array['framesbetweenreferences'] > 0) && ($source_data_array['framesbetweenreferences'] <= 65535)) {
  371. $framedata .= getid3_lib::BigEndian2String($source_data_array['framesbetweenreferences'], 2, false);
  372. } else {
  373. $this->errors[] = 'Invalid MPEG Frames Between References in '.$frame_name.' ('.$source_data_array['framesbetweenreferences'].')';
  374. }
  375. if (($source_data_array['bytesbetweenreferences'] > 0) && ($source_data_array['bytesbetweenreferences'] <= 16777215)) {
  376. $framedata .= getid3_lib::BigEndian2String($source_data_array['bytesbetweenreferences'], 3, false);
  377. } else {
  378. $this->errors[] = 'Invalid bytes Between References in '.$frame_name.' ('.$source_data_array['bytesbetweenreferences'].')';
  379. }
  380. if (($source_data_array['msbetweenreferences'] > 0) && ($source_data_array['msbetweenreferences'] <= 16777215)) {
  381. $framedata .= getid3_lib::BigEndian2String($source_data_array['msbetweenreferences'], 3, false);
  382. } else {
  383. $this->errors[] = 'Invalid Milliseconds Between References in '.$frame_name.' ('.$source_data_array['msbetweenreferences'].')';
  384. }
  385. if (!$this->IsWithinBitRange($source_data_array['bitsforbytesdeviation'], 8, false)) {
  386. if (($source_data_array['bitsforbytesdeviation'] % 4) == 0) {
  387. $framedata .= chr($source_data_array['bitsforbytesdeviation']);
  388. } else {
  389. $this->errors[] = 'Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.';
  390. }
  391. } else {
  392. $this->errors[] = 'Invalid Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].')';
  393. }
  394. if (!$this->IsWithinBitRange($source_data_array['bitsformsdeviation'], 8, false)) {
  395. if (($source_data_array['bitsformsdeviation'] % 4) == 0) {
  396. $framedata .= chr($source_data_array['bitsformsdeviation']);
  397. } else {
  398. $this->errors[] = 'Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.';
  399. }
  400. } else {
  401. $this->errors[] = 'Invalid Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsformsdeviation'].')';
  402. }
  403. foreach ($source_data_array as $key => $val) {
  404. if (($key != 'framesbetweenreferences') && ($key != 'bytesbetweenreferences') && ($key != 'msbetweenreferences') && ($key != 'bitsforbytesdeviation') && ($key != 'bitsformsdeviation') && ($key != 'flags')) {
  405. $unwrittenbitstream .= str_pad(getid3_lib::Dec2Bin($val['bytedeviation']), $source_data_array['bitsforbytesdeviation'], '0', STR_PAD_LEFT);
  406. $unwrittenbitstream .= str_pad(getid3_lib::Dec2Bin($val['msdeviation']), $source_data_array['bitsformsdeviation'], '0', STR_PAD_LEFT);
  407. }
  408. }
  409. for ($i = 0; $i < strlen($unwrittenbitstream); $i += 8) {
  410. $highnibble = bindec(substr($unwrittenbitstream, $i, 4)) << 4;
  411. $lownibble = bindec(substr($unwrittenbitstream, $i + 4, 4));
  412. $framedata .= chr($highnibble & $lownibble);
  413. }
  414. break;
  415. case 'SYTC':
  416. // 4.7 SYTC Synchronised tempo codes
  417. // Time stamp format $xx
  418. // Tempo data <binary data>
  419. // Where time stamp format is:
  420. // $01 (32-bit value) MPEG frames from beginning of file
  421. // $02 (32-bit value) milliseconds from beginning of file
  422. if (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) {
  423. $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
  424. } else {
  425. $framedata .= chr($source_data_array['timestampformat']);
  426. foreach ($source_data_array as $key => $val) {
  427. if (!$this->ID3v2IsValidETCOevent($val['typeid'])) {
  428. $this->errors[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')';
  429. } elseif (($key != 'timestampformat') && ($key != 'flags')) {
  430. if (($val['tempo'] < 0) || ($val['tempo'] > 510)) {
  431. $this->errors[] = 'Invalid Tempo (max = 510) in '.$frame_name.' ('.$val['tempo'].') at timestamp ('.$val['timestamp'].')';
  432. } else {
  433. if ($val['tempo'] > 255) {
  434. $framedata .= chr(255);
  435. $val['tempo'] -= 255;
  436. }
  437. $framedata .= chr($val['tempo']);
  438. $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false);
  439. }
  440. }
  441. }
  442. }
  443. break;
  444. case 'USLT':
  445. // 4.8 USLT Unsynchronised lyric/text transcription
  446. // Text encoding $xx
  447. // Language $xx xx xx
  448. // Content descriptor <text string according to encoding> $00 (00)
  449. // Lyrics/text <full text string according to encoding>
  450. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  451. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  452. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  453. } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
  454. $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
  455. } else {
  456. $framedata .= chr($source_data_array['encodingid']);
  457. $framedata .= strtolower($source_data_array['language']);
  458. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  459. $framedata .= $source_data_array['data'];
  460. }
  461. break;
  462. case 'SYLT':
  463. // 4.9 SYLT Synchronised lyric/text
  464. // Text encoding $xx
  465. // Language $xx xx xx
  466. // Time stamp format $xx
  467. // $01 (32-bit value) MPEG frames from beginning of file
  468. // $02 (32-bit value) milliseconds from beginning of file
  469. // Content type $xx
  470. // Content descriptor <text string according to encoding> $00 (00)
  471. // Terminated text to be synced (typically a syllable)
  472. // Sync identifier (terminator to above string) $00 (00)
  473. // Time stamp $xx (xx ...)
  474. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  475. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  476. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  477. } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
  478. $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
  479. } elseif (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) {
  480. $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
  481. } elseif (!$this->ID3v2IsValidSYLTtype($source_data_array['contenttypeid'])) {
  482. $this->errors[] = 'Invalid Content Type byte in '.$frame_name.' ('.$source_data_array['contenttypeid'].')';
  483. } elseif (!is_array($source_data_array['data'])) {
  484. $this->errors[] = 'Invalid Lyric/Timestamp data in '.$frame_name.' (must be an array)';
  485. } else {
  486. $framedata .= chr($source_data_array['encodingid']);
  487. $framedata .= strtolower($source_data_array['language']);
  488. $framedata .= chr($source_data_array['timestampformat']);
  489. $framedata .= chr($source_data_array['contenttypeid']);
  490. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  491. ksort($source_data_array['data']);
  492. foreach ($source_data_array['data'] as $key => $val) {
  493. $framedata .= $val['data'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  494. $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false);
  495. }
  496. }
  497. break;
  498. case 'COMM':
  499. // 4.10 COMM Comments
  500. // Text encoding $xx
  501. // Language $xx xx xx
  502. // Short content descrip. <text string according to encoding> $00 (00)
  503. // The actual text <full text string according to encoding>
  504. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  505. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  506. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  507. } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
  508. $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
  509. } else {
  510. $framedata .= chr($source_data_array['encodingid']);
  511. $framedata .= strtolower($source_data_array['language']);
  512. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  513. $framedata .= $source_data_array['data'];
  514. }
  515. break;
  516. case 'RVA2':
  517. // 4.11 RVA2 Relative volume adjustment (2) (ID3v2.4+ only)
  518. // Identification <text string> $00
  519. // The 'identification' string is used to identify the situation and/or
  520. // device where this adjustment should apply. The following is then
  521. // repeated for every channel:
  522. // Type of channel $xx
  523. // Volume adjustment $xx xx
  524. // Bits representing peak $xx
  525. // Peak volume $xx (xx ...)
  526. $framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00";
  527. foreach ($source_data_array as $key => $val) {
  528. if ($key != 'description') {
  529. $framedata .= chr($val['channeltypeid']);
  530. $framedata .= getid3_lib::BigEndian2String($val['volumeadjust'], 2, false, true); // signed 16-bit
  531. if (!$this->IsWithinBitRange($source_data_array['bitspeakvolume'], 8, false)) {
  532. $framedata .= chr($val['bitspeakvolume']);
  533. if ($val['bitspeakvolume'] > 0) {
  534. $framedata .= getid3_lib::BigEndian2String($val['peakvolume'], ceil($val['bitspeakvolume'] / 8), false, false);
  535. }
  536. } else {
  537. $this->errors[] = 'Invalid Bits Representing Peak Volume in '.$frame_name.' ('.$val['bitspeakvolume'].') (range = 0 to 255)';
  538. }
  539. }
  540. }
  541. break;
  542. case 'RVAD':
  543. // 4.12 RVAD Relative volume adjustment (ID3v2.3 only)
  544. // Increment/decrement %00fedcba
  545. // Bits used for volume descr. $xx
  546. // Relative volume change, right $xx xx (xx ...) // a
  547. // Relative volume change, left $xx xx (xx ...) // b
  548. // Peak volume right $xx xx (xx ...)
  549. // Peak volume left $xx xx (xx ...)
  550. // Relative volume change, right back $xx xx (xx ...) // c
  551. // Relative volume change, left back $xx xx (xx ...) // d
  552. // Peak volume right back $xx xx (xx ...)
  553. // Peak volume left back $xx xx (xx ...)
  554. // Relative volume change, center $xx xx (xx ...) // e
  555. // Peak volume center $xx xx (xx ...)
  556. // Relative volume change, bass $xx xx (xx ...) // f
  557. // Peak volume bass $xx xx (xx ...)
  558. if (!$this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) {
  559. $this->errors[] = 'Invalid Bits For Volume Description byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)';
  560. } else {
  561. $incdecflag .= '00';
  562. $incdecflag .= $source_data_array['incdec']['right'] ? '1' : '0'; // a - Relative volume change, right
  563. $incdecflag .= $source_data_array['incdec']['left'] ? '1' : '0'; // b - Relative volume change, left
  564. $incdecflag .= $source_data_array['incdec']['rightrear'] ? '1' : '0'; // c - Relative volume change, right back
  565. $incdecflag .= $source_data_array['incdec']['leftrear'] ? '1' : '0'; // d - Relative volume change, left back
  566. $incdecflag .= $source_data_array['incdec']['center'] ? '1' : '0'; // e - Relative volume change, center
  567. $incdecflag .= $source_data_array['incdec']['bass'] ? '1' : '0'; // f - Relative volume change, bass
  568. $framedata .= chr(bindec($incdecflag));
  569. $framedata .= chr($source_data_array['bitsvolume']);
  570. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['right'], ceil($source_data_array['bitsvolume'] / 8), false);
  571. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['left'], ceil($source_data_array['bitsvolume'] / 8), false);
  572. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['right'], ceil($source_data_array['bitsvolume'] / 8), false);
  573. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['left'], ceil($source_data_array['bitsvolume'] / 8), false);
  574. if ($source_data_array['volumechange']['rightrear'] || $source_data_array['volumechange']['leftrear'] ||
  575. $source_data_array['peakvolume']['rightrear'] || $source_data_array['peakvolume']['leftrear'] ||
  576. $source_data_array['volumechange']['center'] || $source_data_array['peakvolume']['center'] ||
  577. $source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) {
  578. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['rightrear'], ceil($source_data_array['bitsvolume']/8), false);
  579. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['leftrear'], ceil($source_data_array['bitsvolume']/8), false);
  580. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['rightrear'], ceil($source_data_array['bitsvolume']/8), false);
  581. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['leftrear'], ceil($source_data_array['bitsvolume']/8), false);
  582. }
  583. if ($source_data_array['volumechange']['center'] || $source_data_array['peakvolume']['center'] ||
  584. $source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) {
  585. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['center'], ceil($source_data_array['bitsvolume']/8), false);
  586. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['center'], ceil($source_data_array['bitsvolume']/8), false);
  587. }
  588. if ($source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) {
  589. $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['bass'], ceil($source_data_array['bitsvolume']/8), false);
  590. $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['bass'], ceil($source_data_array['bitsvolume']/8), false);
  591. }
  592. }
  593. break;
  594. case 'EQU2':
  595. // 4.12 EQU2 Equalisation (2) (ID3v2.4+ only)
  596. // Interpolation method $xx
  597. // $00 Band
  598. // $01 Linear
  599. // Identification <text string> $00
  600. // The following is then repeated for every adjustment point
  601. // Frequency $xx xx
  602. // Volume adjustment $xx xx
  603. if (($source_data_array['interpolationmethod'] < 0) || ($source_data_array['interpolationmethod'] > 1)) {
  604. $this->errors[] = 'Invalid Interpolation Method byte in '.$frame_name.' ('.$source_data_array['interpolationmethod'].') (valid = 0 or 1)';
  605. } else {
  606. $framedata .= chr($source_data_array['interpolationmethod']);
  607. $framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00";
  608. foreach ($source_data_array['data'] as $key => $val) {
  609. $framedata .= getid3_lib::BigEndian2String(intval(round($key * 2)), 2, false);
  610. $framedata .= getid3_lib::BigEndian2String($val, 2, false, true); // signed 16-bit
  611. }
  612. }
  613. break;
  614. case 'EQUA':
  615. // 4.12 EQUA Equalisation (ID3v2.3 only)
  616. // Adjustment bits $xx
  617. // This is followed by 2 bytes + ('adjustment bits' rounded up to the
  618. // nearest byte) for every equalisation band in the following format,
  619. // giving a frequency range of 0 - 32767Hz:
  620. // Increment/decrement %x (MSB of the Frequency)
  621. // Frequency (lower 15 bits)
  622. // Adjustment $xx (xx ...)
  623. if (!$this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) {
  624. $this->errors[] = 'Invalid Adjustment Bits byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)';
  625. } else {
  626. $framedata .= chr($source_data_array['adjustmentbits']);
  627. foreach ($source_data_array as $key => $val) {
  628. if ($key != 'bitsvolume') {
  629. if (($key > 32767) || ($key < 0)) {
  630. $this->errors[] = 'Invalid Frequency in '.$frame_name.' ('.$key.') (range = 0 to 32767)';
  631. } else {
  632. if ($val >= 0) {
  633. // put MSB of frequency to 1 if increment, 0 if decrement
  634. $key |= 0x8000;
  635. }
  636. $framedata .= getid3_lib::BigEndian2String($key, 2, false);
  637. $framedata .= getid3_lib::BigEndian2String($val, ceil($source_data_array['adjustmentbits'] / 8), false);
  638. }
  639. }
  640. }
  641. }
  642. break;
  643. case 'RVRB':
  644. // 4.13 RVRB Reverb
  645. // Reverb left (ms) $xx xx
  646. // Reverb right (ms) $xx xx
  647. // Reverb bounces, left $xx
  648. // Reverb bounces, right $xx
  649. // Reverb feedback, left to left $xx
  650. // Reverb feedback, left to right $xx
  651. // Reverb feedback, right to right $xx
  652. // Reverb feedback, right to left $xx
  653. // Premix left to right $xx
  654. // Premix right to left $xx
  655. if (!$this->IsWithinBitRange($source_data_array['left'], 16, false)) {
  656. $this->errors[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['left'].') (range = 0 to 65535)';
  657. } elseif (!$this->IsWithinBitRange($source_data_array['right'], 16, false)) {
  658. $this->errors[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['right'].') (range = 0 to 65535)';
  659. } elseif (!$this->IsWithinBitRange($source_data_array['bouncesL'], 8, false)) {
  660. $this->errors[] = 'Invalid Reverb Bounces, Left in '.$frame_name.' ('.$source_data_array['bouncesL'].') (range = 0 to 255)';
  661. } elseif (!$this->IsWithinBitRange($source_data_array['bouncesR'], 8, false)) {
  662. $this->errors[] = 'Invalid Reverb Bounces, Right in '.$frame_name.' ('.$source_data_array['bouncesR'].') (range = 0 to 255)';
  663. } elseif (!$this->IsWithinBitRange($source_data_array['feedbackLL'], 8, false)) {
  664. $this->errors[] = 'Invalid Reverb Feedback, Left-To-Left in '.$frame_name.' ('.$source_data_array['feedbackLL'].') (range = 0 to 255)';
  665. } elseif (!$this->IsWithinBitRange($source_data_array['feedbackLR'], 8, false)) {
  666. $this->errors[] = 'Invalid Reverb Feedback, Left-To-Right in '.$frame_name.' ('.$source_data_array['feedbackLR'].') (range = 0 to 255)';
  667. } elseif (!$this->IsWithinBitRange($source_data_array['feedbackRR'], 8, false)) {
  668. $this->errors[] = 'Invalid Reverb Feedback, Right-To-Right in '.$frame_name.' ('.$source_data_array['feedbackRR'].') (range = 0 to 255)';
  669. } elseif (!$this->IsWithinBitRange($source_data_array['feedbackRL'], 8, false)) {
  670. $this->errors[] = 'Invalid Reverb Feedback, Right-To-Left in '.$frame_name.' ('.$source_data_array['feedbackRL'].') (range = 0 to 255)';
  671. } elseif (!$this->IsWithinBitRange($source_data_array['premixLR'], 8, false)) {
  672. $this->errors[] = 'Invalid Premix, Left-To-Right in '.$frame_name.' ('.$source_data_array['premixLR'].') (range = 0 to 255)';
  673. } elseif (!$this->IsWithinBitRange($source_data_array['premixRL'], 8, false)) {
  674. $this->errors[] = 'Invalid Premix, Right-To-Left in '.$frame_name.' ('.$source_data_array['premixRL'].') (range = 0 to 255)';
  675. } else {
  676. $framedata .= getid3_lib::BigEndian2String($source_data_array['left'], 2, false);
  677. $framedata .= getid3_lib::BigEndian2String($source_data_array['right'], 2, false);
  678. $framedata .= chr($source_data_array['bouncesL']);
  679. $framedata .= chr($source_data_array['bouncesR']);
  680. $framedata .= chr($source_data_array['feedbackLL']);
  681. $framedata .= chr($source_data_array['feedbackLR']);
  682. $framedata .= chr($source_data_array['feedbackRR']);
  683. $framedata .= chr($source_data_array['feedbackRL']);
  684. $framedata .= chr($source_data_array['premixLR']);
  685. $framedata .= chr($source_data_array['premixRL']);
  686. }
  687. break;
  688. case 'APIC':
  689. // 4.14 APIC Attached picture
  690. // Text encoding $xx
  691. // MIME type <text string> $00
  692. // Picture type $xx
  693. // Description <text string according to encoding> $00 (00)
  694. // Picture data <binary data>
  695. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  696. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  697. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  698. } elseif (!$this->ID3v2IsValidAPICpicturetype($source_data_array['picturetypeid'])) {
  699. $this->errors[] = 'Invalid Picture Type byte in '.$frame_name.' ('.$source_data_array['picturetypeid'].') for ID3v2.'.$this->majorversion;
  700. } elseif (($this->majorversion >= 3) && (!$this->ID3v2IsValidAPICimageformat($source_data_array['mime']))) {
  701. $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].') for ID3v2.'.$this->majorversion;
  702. } elseif (($source_data_array['mime'] == '-->') && (!$this->IsValidURL($source_data_array['data'], false, false))) {
  703. //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  704. // probably should be an error, need to rewrite IsValidURL() to handle other encodings
  705. $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  706. } else {
  707. $framedata .= chr($source_data_array['encodingid']);
  708. $framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00";
  709. $framedata .= chr($source_data_array['picturetypeid']);
  710. $framedata .= @$source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  711. $framedata .= $source_data_array['data'];
  712. }
  713. break;
  714. case 'GEOB':
  715. // 4.15 GEOB General encapsulated object
  716. // Text encoding $xx
  717. // MIME type <text string> $00
  718. // Filename <text string according to encoding> $00 (00)
  719. // Content description <text string according to encoding> $00 (00)
  720. // Encapsulated object <binary data>
  721. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  722. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  723. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
  724. } elseif (!$this->IsValidMIMEstring($source_data_array['mime'])) {
  725. $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].')';
  726. } elseif (!$source_data_array['description']) {
  727. $this->errors[] = 'Missing Description in '.$frame_name;
  728. } else {
  729. $framedata .= chr($source_data_array['encodingid']);
  730. $framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00";
  731. $framedata .= $source_data_array['filename'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  732. $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
  733. $framedata .= $source_data_array['data'];
  734. }
  735. break;
  736. case 'PCNT':
  737. // 4.16 PCNT Play counter
  738. // When the counter reaches all one's, one byte is inserted in
  739. // front of the counter thus making the counter eight bits bigger
  740. // Counter $xx xx xx xx (xx ...)
  741. $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false);
  742. break;
  743. case 'POPM':
  744. // 4.17 POPM Popularimeter
  745. // When the counter reaches all one's, one byte is inserted in
  746. // front of the counter thus making the counter eight bits bigger
  747. // Email to user <text string> $00
  748. // Rating $xx
  749. // Counter $xx xx xx xx (xx ...)
  750. if (!$this->IsWithinBitRange($source_data_array['rating'], 8, false)) {
  751. $this->errors[] = 'Invalid Rating byte in '.$frame_name.' ('.$source_data_array['rating'].') (range = 0 to 255)';
  752. } elseif (!IsValidEmail($source_data_array['email'])) {
  753. $this->errors[] = 'Invalid Email in '.$frame_name.' ('.$source_data_array['email'].')';
  754. } else {
  755. $framedata .= str_replace("\x00", '', $source_data_array['email'])."\x00";
  756. $framedata .= chr($source_data_array['rating']);
  757. $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false);
  758. }
  759. break;
  760. case 'RBUF':
  761. // 4.18 RBUF Recommended buffer size
  762. // Buffer size $xx xx xx
  763. // Embedded info flag %0000000x
  764. // Offset to next tag $xx xx xx xx
  765. if (!$this->IsWithinBitRange($source_data_array['buffersize'], 24, false)) {
  766. $this->errors[] = 'Invalid Buffer Size in '.$frame_name;
  767. } elseif (!$this->IsWithinBitRange($source_data_array['nexttagoffset'], 32, false)) {
  768. $this->errors[] = 'Invalid Offset To Next Tag in '.$frame_name;
  769. } else {
  770. $framedata .= getid3_lib::BigEndian2String($source_data_array['buffersize'], 3, false);
  771. $flag .= '0000000';
  772. $flag .= $source_data_array['flags']['embededinfo'] ? '1' : '0';
  773. $framedata .= chr(bindec($flag));
  774. $framedata .= getid3_lib::BigEndian2String($source_data_array['nexttagoffset'], 4, false);
  775. }
  776. break;
  777. case 'AENC':
  778. // 4.19 AENC Audio encryption
  779. // Owner identifier <text string> $00
  780. // Preview start $xx xx
  781. // Preview length $xx xx
  782. // Encryption info <binary data>
  783. if (!$this->IsWithinBitRange($source_data_array['previewstart'], 16, false)) {
  784. $this->errors[] = 'Invalid Preview Start in '.$frame_name.' ('.$source_data_array['previewstart'].')';
  785. } elseif (!$this->IsWithinBitRange($source_data_array['previewlength'], 16, false)) {
  786. $this->errors[] = 'Invalid Preview Length in '.$frame_name.' ('.$source_data_array['previewlength'].')';
  787. } else {
  788. $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
  789. $framedata .= getid3_lib::BigEndian2String($source_data_array['previewstart'], 2, false);
  790. $framedata .= getid3_lib::BigEndian2String($source_data_array['previewlength'], 2, false);
  791. $framedata .= $source_data_array['encryptioninfo'];
  792. }
  793. break;
  794. case 'LINK':
  795. // 4.20 LINK Linked information
  796. // Frame identifier $xx xx xx xx
  797. // URL <text string> $00
  798. // ID and additional data <text string(s)>
  799. if (!getid3_id3v2::IsValidID3v2FrameName($source_data_array['frameid'], $this->majorversion)) {
  800. $this->errors[] = 'Invalid Frame Identifier in '.$frame_name.' ('.$source_data_array['frameid'].')';
  801. } elseif (!$this->IsValidURL($source_data_array['data'], true, false)) {
  802. //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  803. // probably should be an error, need to rewrite IsValidURL() to handle other encodings
  804. $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
  805. } 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'] == '')) {
  806. $this->errors[] = 'Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
  807. } elseif (($source_data_array['frameid'] == 'USER') && (getid3_id3v2::LanguageLookup($source_data_array['additionaldata'], true) == '')) {
  808. $this->errors[] = 'Language must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
  809. } elseif (($source_data_array['frameid'] == 'PRIV') && ($source_data_array['additionaldata'] == '')) {
  810. $this->errors[] = 'Owner Identifier must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
  811. } 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) == ''))) {
  812. $this->errors[] = 'Language followed by Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
  813. } else {
  814. $framedata .= $source_data_array['frameid'];
  815. $framedata .= str_replace("\x00", '', $source_data_array['data'])."\x00";
  816. switch ($source_data_array['frameid']) {
  817. case 'COMM':
  818. case 'SYLT':
  819. case 'USLT':
  820. case 'PRIV':
  821. case 'USER':
  822. case 'AENC':
  823. case 'APIC':
  824. case 'GEOB':
  825. case 'TXXX':
  826. $framedata .= $source_data_array['additionaldata'];
  827. break;
  828. case 'ASPI':
  829. case 'ETCO':
  830. case 'EQU2':
  831. case 'MCID':
  832. case 'MLLT':
  833. case 'OWNE':
  834. case 'RVA2':
  835. case 'RVRB':
  836. case 'SYTC':
  837. case 'IPLS':
  838. case 'RVAD':
  839. case 'EQUA':
  840. // no additional data required
  841. break;
  842. case 'RBUF':
  843. if ($this->majorversion == 3) {
  844. // no additional data required
  845. } else {
  846. $this->errors[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion.')';
  847. }
  848. default:
  849. if ((substr($source_data_array['frameid'], 0, 1) == 'T') || (substr($source_data_array['frameid'], 0, 1) == 'W')) {
  850. // no additional data required
  851. } else {
  852. $this->errors[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion.')';
  853. }
  854. break;
  855. }
  856. }
  857. break;
  858. case 'POSS':
  859. // 4.21 POSS Position synchronisation frame (ID3v2.3+ only)
  860. // Time stamp format $xx
  861. // Position $xx (xx ...)
  862. if (($source_data_array['timestampformat'] < 1) || ($source_data_array['timestampformat'] > 2)) {
  863. $this->errors[] = 'Invalid Time Stamp Format in '.$frame_name.' ('.$source_data_array['timestampformat'].') (valid = 1 or 2)';
  864. } elseif (!$this->IsWithinBitRange($source_data_array['position'], 32, false)) {
  865. $this->errors[] = 'Invalid Position in '.$frame_name.' ('.$source_data_array['position'].') (range = 0 to 4294967295)';
  866. } else {
  867. $framedata .= chr($source_data_array['timestampformat']);
  868. $framedata .= getid3_lib::BigEndian2String($source_data_array['position'], 4, false);
  869. }
  870. break;
  871. case 'USER':
  872. // 4.22 USER Terms of use (ID3v2.3+ only)
  873. // Text encoding $xx
  874. // Language $xx xx xx
  875. // The actual text <text string according to encoding>
  876. $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
  877. if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
  878. $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')';
  879. } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
  880. $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source

Large files files are truncated, but you can click here to view the full file