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