ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getid3_write_id3v2 Class Reference
+ Collaboration diagram for getid3_write_id3v2:

Public Member Functions

 getid3_write_id3v2 ()
 
 WriteID3v2 ()
 
 RemoveID3v2 ()
 
 GenerateID3v2TagFlags ($flags)
 
 GenerateID3v2FrameFlags ($TagAlter=false, $FileAlter=false, $ReadOnly=false, $Compression=false, $Encryption=false, $GroupingIdentity=false, $Unsynchronisation=false, $DataLengthIndicator=false)
 
 GenerateID3v2FrameData ($frame_name, $source_data_array)
 
 ID3v2FrameIsAllowed ($frame_name, $source_data_array)
 
 GenerateID3v2Tag ($noerrorsonly=true)
 
 ID3v2IsValidPriceString ($pricestring)
 
 ID3v2FrameFlagsLookupTagAlter ($framename)
 
 ID3v2FrameFlagsLookupFileAlter ($framename)
 
 ID3v2IsValidETCOevent ($eventid)
 
 ID3v2IsValidSYLTtype ($contenttype)
 
 ID3v2IsValidRVA2channeltype ($channeltype)
 
 ID3v2IsValidAPICpicturetype ($picturetype)
 
 ID3v2IsValidAPICimageformat ($imageformat)
 
 ID3v2IsValidCOMRreceivedAs ($receivedas)
 
 ID3v2IsValidRGADname ($RGADname)
 
 ID3v2IsValidRGADoriginator ($RGADoriginator)
 
 ID3v2IsValidTextEncoding ($textencodingbyte)
 
 Unsynchronise ($data)
 
 is_hash ($var)
 
 array_join_merge ($arr1, $arr2)
 
 IsValidMIMEstring ($mimestring)
 
 IsWithinBitRange ($number, $maxbits, $signed=false)
 
 safe_parse_url ($url)
 
 IsValidURL ($url, $allowUserPass=false)
 
 ID3v2ShortFrameNameLookup ($majorversion, $long_description)
 
 getid3_write_id3v2 ()
 
 WriteID3v2 ()
 
 RemoveID3v2 ()
 
 GenerateID3v2TagFlags ($flags)
 
 GenerateID3v2FrameFlags ($TagAlter=false, $FileAlter=false, $ReadOnly=false, $Compression=false, $Encryption=false, $GroupingIdentity=false, $Unsynchronisation=false, $DataLengthIndicator=false)
 
 GenerateID3v2FrameData ($frame_name, $source_data_array)
 
 ID3v2FrameIsAllowed ($frame_name, $source_data_array)
 
 GenerateID3v2Tag ($noerrorsonly=true)
 
 ID3v2IsValidPriceString ($pricestring)
 
 ID3v2FrameFlagsLookupTagAlter ($framename)
 
 ID3v2FrameFlagsLookupFileAlter ($framename)
 
 ID3v2IsValidETCOevent ($eventid)
 
 ID3v2IsValidSYLTtype ($contenttype)
 
 ID3v2IsValidRVA2channeltype ($channeltype)
 
 ID3v2IsValidAPICpicturetype ($picturetype)
 
 ID3v2IsValidAPICimageformat ($imageformat)
 
 ID3v2IsValidCOMRreceivedAs ($receivedas)
 
 ID3v2IsValidRGADname ($RGADname)
 
 ID3v2IsValidRGADoriginator ($RGADoriginator)
 
 ID3v2IsValidTextEncoding ($textencodingbyte)
 
 Unsynchronise ($data)
 
 is_hash ($var)
 
 array_join_merge ($arr1, $arr2)
 
 IsValidMIMEstring ($mimestring)
 
 IsWithinBitRange ($number, $maxbits, $signed=false)
 
 safe_parse_url ($url)
 
 IsValidURL ($url, $allowUserPass=false)
 

Static Public Member Functions

static ID3v2ShortFrameNameLookup ($majorversion, $long_description)
 

Data Fields

 $filename
 
 $tag_data
 
 $paddedlength = 4096
 
 $majorversion = 3
 
 $minorversion = 0
 
 $merge_existing_data = false
 
 $id3v2_default_encodingid = 0
 
 $id3v2_use_unsynchronisation = false
 
 $warnings = array()
 
 $errors = array()
 
 $fread_buffer_size = 32768
 

Detailed Description

Definition at line 18 of file write.id3v2.php.

Member Function Documentation

◆ array_join_merge() [1/2]

getid3_write_id3v2::array_join_merge (   $arr1,
  $arr2 
)

Definition at line 1800 of file write.id3v2.php.

References is_hash().

Referenced by array_join_merge(), and WriteID3v2().

1800  {
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  }
array_join_merge($arr1, $arr2)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ array_join_merge() [2/2]

getid3_write_id3v2::array_join_merge (   $arr1,
  $arr2 
)

Definition at line 1814 of file write.id3v2.php.

References array_join_merge(), and is_hash().

1814  {
1815  // written by dev-nullØchristophe*vg
1816  // taken from http://www.php.net/manual/en/function.array-merge-recursive.php
1817  if (is_array($arr1) && is_array($arr2)) {
1818  // the same -> merge
1819  $new_array = array();
1820 
1821  if ($this->is_hash($arr1) && $this->is_hash($arr2)) {
1822  // hashes -> merge based on keys
1823  $keys = array_merge(array_keys($arr1), array_keys($arr2));
1824  foreach ($keys as $key) {
1825  $new_array[$key] = $this->array_join_merge((isset($arr1[$key]) ? $arr1[$key] : ''), (isset($arr2[$key]) ? $arr2[$key] : ''));
1826  }
1827  } else {
1828  // two real arrays -> merge
1829  $new_array = array_reverse(array_unique(array_reverse(array_merge($arr1, $arr2))));
1830  }
1831  return $new_array;
1832  } else {
1833  // not the same ... take new one if defined, else the old one stays
1834  return $arr2 ? $arr2 : $arr1;
1835  }
1836  }
array_join_merge($arr1, $arr2)
+ Here is the call graph for this function:

◆ GenerateID3v2FrameData() [1/2]

getid3_write_id3v2::GenerateID3v2FrameData (   $frame_name,
  $source_data_array 
)

Definition at line 296 of file write.id3v2.php.

References $id3v2_default_encodingid, $majorversion, getid3_lib\BigEndian2String(), getid3_lib\Dec2Bin(), getid3_lib\Float2String(), ID3v2IsValidAPICimageformat(), ID3v2IsValidAPICpicturetype(), ID3v2IsValidCOMRreceivedAs(), ID3v2IsValidETCOevent(), ID3v2IsValidPriceString(), ID3v2IsValidRGADname(), ID3v2IsValidRGADoriginator(), ID3v2IsValidSYLTtype(), ID3v2IsValidTextEncoding(), getid3_id3v2\IsValidID3v2FrameName(), IsValidMIMEstring(), IsValidURL(), IsWithinBitRange(), getid3_id3v2\LanguageLookup(), and getid3_lib\RGADgainString().

Referenced by GenerateID3v2Tag().

296  {
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  }
ID3v2IsValidSYLTtype($contenttype)
RGADgainString($namecode, $originatorcode, $replaygain)
LanguageLookup($languagecode, $casesensitive=false)
ID3v2IsValidRGADname($RGADname)
ID3v2IsValidCOMRreceivedAs($receivedas)
ID3v2IsValidETCOevent($eventid)
IsWithinBitRange($number, $maxbits, $signed=false)
BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false)
Definition: getid3.lib.php:281
ID3v2IsValidTextEncoding($textencodingbyte)
IsValidURL($url, $allowUserPass=false)
ID3v2IsValidPriceString($pricestring)
IsValidID3v2FrameName($framename, $id3v2majorversion)
Dec2Bin($number)
Definition: getid3.lib.php:302
ID3v2IsValidRGADoriginator($RGADoriginator)
ID3v2IsValidAPICpicturetype($picturetype)
IsValidMIMEstring($mimestring)
ID3v2IsValidAPICimageformat($imageformat)
Float2String($floatvalue, $bits)
Definition: getid3.lib.php:123
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenerateID3v2FrameData() [2/2]

getid3_write_id3v2::GenerateID3v2FrameData (   $frame_name,
  $source_data_array 
)

Definition at line 303 of file write.id3v2.php.

References $id3v2_default_encodingid, $majorversion, getid3_lib\BigEndian2String(), getid3_lib\Dec2Bin(), getid3_lib\Float2String(), ID3v2IsValidAPICimageformat(), ID3v2IsValidAPICpicturetype(), ID3v2IsValidCOMRreceivedAs(), ID3v2IsValidETCOevent(), ID3v2IsValidPriceString(), ID3v2IsValidRGADname(), ID3v2IsValidRGADoriginator(), ID3v2IsValidSYLTtype(), ID3v2IsValidTextEncoding(), getid3_id3v2\IsValidID3v2FrameName(), IsValidMIMEstring(), IsValidURL(), IsWithinBitRange(), getid3_id3v2\LanguageLookup(), getid3_lib\RGADgainString(), and getid3_id3v2\TextEncodingTerminatorLookup().

303  {
304  if (!getid3_id3v2::IsValidID3v2FrameName($frame_name, $this->majorversion)) {
305  return false;
306  }
307  $framedata = '';
308 
309  if (($this->majorversion < 3) || ($this->majorversion > 4)) {
310 
311  $this->errors[] = 'Only ID3v2.3 and ID3v2.4 are supported in GenerateID3v2FrameData()';
312 
313  } else { // $this->majorversion 3 or 4
314 
315  switch ($frame_name) {
316  case 'UFID':
317  // 4.1 UFID Unique file identifier
318  // Owner identifier <text string> $00
319  // Identifier <up to 64 bytes binary data>
320  if (strlen($source_data_array['data']) > 64) {
321  $this->errors[] = 'Identifier not allowed to be longer than 64 bytes in '.$frame_name.' (supplied data was '.strlen($source_data_array['data']).' bytes long)';
322  } else {
323  $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
324  $framedata .= substr($source_data_array['data'], 0, 64); // max 64 bytes - truncate anything longer
325  }
326  break;
327 
328  case 'TXXX':
329  // 4.2.2 TXXX User defined text information frame
330  // Text encoding $xx
331  // Description <text string according to encoding> $00 (00)
332  // Value <text string according to encoding>
333  $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
334  if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) {
335  $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
336  } else {
337  $framedata .= chr($source_data_array['encodingid']);
338  $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
339  $framedata .= $source_data_array['data'];
340  }
341  break;
342 
343  case 'WXXX':
344  // 4.3.2 WXXX User defined URL link frame
345  // Text encoding $xx
346  // Description <text string according to encoding> $00 (00)
347  // URL <text string>
348  $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
349  if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) {
350  $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
351  } elseif (!isset($source_data_array['data']) || !$this->IsValidURL($source_data_array['data'], false, false)) {
352  //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
353  // probably should be an error, need to rewrite IsValidURL() to handle other encodings
354  $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
355  } else {
356  $framedata .= chr($source_data_array['encodingid']);
357  $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
358  $framedata .= $source_data_array['data'];
359  }
360  break;
361 
362  case 'IPLS':
363  // 4.4 IPLS Involved people list (ID3v2.3 only)
364  // Text encoding $xx
365  // People list strings <textstrings>
366  $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
367  if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) {
368  $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
369  } else {
370  $framedata .= chr($source_data_array['encodingid']);
371  $framedata .= $source_data_array['data'];
372  }
373  break;
374 
375  case 'MCDI':
376  // 4.4 MCDI Music CD identifier
377  // CD TOC <binary data>
378  $framedata .= $source_data_array['data'];
379  break;
380 
381  case 'ETCO':
382  // 4.5 ETCO Event timing codes
383  // Time stamp format $xx
384  // Where time stamp format is:
385  // $01 (32-bit value) MPEG frames from beginning of file
386  // $02 (32-bit value) milliseconds from beginning of file
387  // Followed by a list of key events in the following format:
388  // Type of event $xx
389  // Time stamp $xx (xx ...)
390  // The 'Time stamp' is set to zero if directly at the beginning of the sound
391  // or after the previous event. All events MUST be sorted in chronological order.
392  if (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) {
393  $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
394  } else {
395  $framedata .= chr($source_data_array['timestampformat']);
396  foreach ($source_data_array as $key => $val) {
397  if (!$this->ID3v2IsValidETCOevent($val['typeid'])) {
398  $this->errors[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')';
399  } elseif (($key != 'timestampformat') && ($key != 'flags')) {
400  if (($val['timestamp'] > 0) && ($previousETCOtimestamp >= $val['timestamp'])) {
401  // The 'Time stamp' is set to zero if directly at the beginning of the sound
402  // or after the previous event. All events MUST be sorted in chronological order.
403  $this->errors[] = 'Out-of-order timestamp in '.$frame_name.' ('.$val['timestamp'].') for Event Type ('.$val['typeid'].')';
404  } else {
405  $framedata .= chr($val['typeid']);
406  $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false);
407  }
408  }
409  }
410  }
411  break;
412 
413  case 'MLLT':
414  // 4.6 MLLT MPEG location lookup table
415  // MPEG frames between reference $xx xx
416  // Bytes between reference $xx xx xx
417  // Milliseconds between reference $xx xx xx
418  // Bits for bytes deviation $xx
419  // Bits for milliseconds dev. $xx
420  // Then for every reference the following data is included;
421  // Deviation in bytes %xxx....
422  // Deviation in milliseconds %xxx....
423  if (($source_data_array['framesbetweenreferences'] > 0) && ($source_data_array['framesbetweenreferences'] <= 65535)) {
424  $framedata .= getid3_lib::BigEndian2String($source_data_array['framesbetweenreferences'], 2, false);
425  } else {
426  $this->errors[] = 'Invalid MPEG Frames Between References in '.$frame_name.' ('.$source_data_array['framesbetweenreferences'].')';
427  }
428  if (($source_data_array['bytesbetweenreferences'] > 0) && ($source_data_array['bytesbetweenreferences'] <= 16777215)) {
429  $framedata .= getid3_lib::BigEndian2String($source_data_array['bytesbetweenreferences'], 3, false);
430  } else {
431  $this->errors[] = 'Invalid bytes Between References in '.$frame_name.' ('.$source_data_array['bytesbetweenreferences'].')';
432  }
433  if (($source_data_array['msbetweenreferences'] > 0) && ($source_data_array['msbetweenreferences'] <= 16777215)) {
434  $framedata .= getid3_lib::BigEndian2String($source_data_array['msbetweenreferences'], 3, false);
435  } else {
436  $this->errors[] = 'Invalid Milliseconds Between References in '.$frame_name.' ('.$source_data_array['msbetweenreferences'].')';
437  }
438  if (!$this->IsWithinBitRange($source_data_array['bitsforbytesdeviation'], 8, false)) {
439  if (($source_data_array['bitsforbytesdeviation'] % 4) == 0) {
440  $framedata .= chr($source_data_array['bitsforbytesdeviation']);
441  } else {
442  $this->errors[] = 'Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.';
443  }
444  } else {
445  $this->errors[] = 'Invalid Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].')';
446  }
447  if (!$this->IsWithinBitRange($source_data_array['bitsformsdeviation'], 8, false)) {
448  if (($source_data_array['bitsformsdeviation'] % 4) == 0) {
449  $framedata .= chr($source_data_array['bitsformsdeviation']);
450  } else {
451  $this->errors[] = 'Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.';
452  }
453  } else {
454  $this->errors[] = 'Invalid Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsformsdeviation'].')';
455  }
456  foreach ($source_data_array as $key => $val) {
457  if (($key != 'framesbetweenreferences') && ($key != 'bytesbetweenreferences') && ($key != 'msbetweenreferences') && ($key != 'bitsforbytesdeviation') && ($key != 'bitsformsdeviation') && ($key != 'flags')) {
458  $unwrittenbitstream .= str_pad(getid3_lib::Dec2Bin($val['bytedeviation']), $source_data_array['bitsforbytesdeviation'], '0', STR_PAD_LEFT);
459  $unwrittenbitstream .= str_pad(getid3_lib::Dec2Bin($val['msdeviation']), $source_data_array['bitsformsdeviation'], '0', STR_PAD_LEFT);
460  }
461  }
462  for ($i = 0; $i < strlen($unwrittenbitstream); $i += 8) {
463  $highnibble = bindec(substr($unwrittenbitstream, $i, 4)) << 4;
464  $lownibble = bindec(substr($unwrittenbitstream, $i + 4, 4));
465  $framedata .= chr($highnibble & $lownibble);
466  }
467  break;
468 
469  case 'SYTC':
470  // 4.7 SYTC Synchronised tempo codes
471  // Time stamp format $xx
472  // Tempo data <binary data>
473  // Where time stamp format is:
474  // $01 (32-bit value) MPEG frames from beginning of file
475  // $02 (32-bit value) milliseconds from beginning of file
476  if (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) {
477  $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
478  } else {
479  $framedata .= chr($source_data_array['timestampformat']);
480  foreach ($source_data_array as $key => $val) {
481  if (!$this->ID3v2IsValidETCOevent($val['typeid'])) {
482  $this->errors[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')';
483  } elseif (($key != 'timestampformat') && ($key != 'flags')) {
484  if (($val['tempo'] < 0) || ($val['tempo'] > 510)) {
485  $this->errors[] = 'Invalid Tempo (max = 510) in '.$frame_name.' ('.$val['tempo'].') at timestamp ('.$val['timestamp'].')';
486  } else {
487  if ($val['tempo'] > 255) {
488  $framedata .= chr(255);
489  $val['tempo'] -= 255;
490  }
491  $framedata .= chr($val['tempo']);
492  $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false);
493  }
494  }
495  }
496  }
497  break;
498 
499  case 'USLT':
500  // 4.8 USLT Unsynchronised lyric/text transcription
501  // Text encoding $xx
502  // Language $xx xx xx
503  // Content descriptor <text string according to encoding> $00 (00)
504  // Lyrics/text <full text string according to encoding>
505  $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
506  if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
507  $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
508  } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
509  $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
510  } else {
511  $framedata .= chr($source_data_array['encodingid']);
512  $framedata .= strtolower($source_data_array['language']);
513  $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
514  $framedata .= $source_data_array['data'];
515  }
516  break;
517 
518  case 'SYLT':
519  // 4.9 SYLT Synchronised lyric/text
520  // Text encoding $xx
521  // Language $xx xx xx
522  // Time stamp format $xx
523  // $01 (32-bit value) MPEG frames from beginning of file
524  // $02 (32-bit value) milliseconds from beginning of file
525  // Content type $xx
526  // Content descriptor <text string according to encoding> $00 (00)
527  // Terminated text to be synced (typically a syllable)
528  // Sync identifier (terminator to above string) $00 (00)
529  // Time stamp $xx (xx ...)
530  $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
531  if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
532  $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
533  } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
534  $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
535  } elseif (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) {
536  $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
537  } elseif (!$this->ID3v2IsValidSYLTtype($source_data_array['contenttypeid'])) {
538  $this->errors[] = 'Invalid Content Type byte in '.$frame_name.' ('.$source_data_array['contenttypeid'].')';
539  } elseif (!is_array($source_data_array['data'])) {
540  $this->errors[] = 'Invalid Lyric/Timestamp data in '.$frame_name.' (must be an array)';
541  } else {
542  $framedata .= chr($source_data_array['encodingid']);
543  $framedata .= strtolower($source_data_array['language']);
544  $framedata .= chr($source_data_array['timestampformat']);
545  $framedata .= chr($source_data_array['contenttypeid']);
546  $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
547  ksort($source_data_array['data']);
548  foreach ($source_data_array['data'] as $key => $val) {
549  $framedata .= $val['data'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
550  $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false);
551  }
552  }
553  break;
554 
555  case 'COMM':
556  // 4.10 COMM Comments
557  // Text encoding $xx
558  // Language $xx xx xx
559  // Short content descrip. <text string according to encoding> $00 (00)
560  // The actual text <full text string according to encoding>
561  $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
562  if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
563  $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
564  } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
565  $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
566  } else {
567  $framedata .= chr($source_data_array['encodingid']);
568  $framedata .= strtolower($source_data_array['language']);
569  $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
570  $framedata .= $source_data_array['data'];
571  }
572  break;
573 
574  case 'RVA2':
575  // 4.11 RVA2 Relative volume adjustment (2) (ID3v2.4+ only)
576  // Identification <text string> $00
577  // The 'identification' string is used to identify the situation and/or
578  // device where this adjustment should apply. The following is then
579  // repeated for every channel:
580  // Type of channel $xx
581  // Volume adjustment $xx xx
582  // Bits representing peak $xx
583  // Peak volume $xx (xx ...)
584  $framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00";
585  foreach ($source_data_array as $key => $val) {
586  if ($key != 'description') {
587  $framedata .= chr($val['channeltypeid']);
588  $framedata .= getid3_lib::BigEndian2String($val['volumeadjust'], 2, false, true); // signed 16-bit
589  if (!$this->IsWithinBitRange($source_data_array['bitspeakvolume'], 8, false)) {
590  $framedata .= chr($val['bitspeakvolume']);
591  if ($val['bitspeakvolume'] > 0) {
592  $framedata .= getid3_lib::BigEndian2String($val['peakvolume'], ceil($val['bitspeakvolume'] / 8), false, false);
593  }
594  } else {
595  $this->errors[] = 'Invalid Bits Representing Peak Volume in '.$frame_name.' ('.$val['bitspeakvolume'].') (range = 0 to 255)';
596  }
597  }
598  }
599  break;
600 
601  case 'RVAD':
602  // 4.12 RVAD Relative volume adjustment (ID3v2.3 only)
603  // Increment/decrement %00fedcba
604  // Bits used for volume descr. $xx
605  // Relative volume change, right $xx xx (xx ...) // a
606  // Relative volume change, left $xx xx (xx ...) // b
607  // Peak volume right $xx xx (xx ...)
608  // Peak volume left $xx xx (xx ...)
609  // Relative volume change, right back $xx xx (xx ...) // c
610  // Relative volume change, left back $xx xx (xx ...) // d
611  // Peak volume right back $xx xx (xx ...)
612  // Peak volume left back $xx xx (xx ...)
613  // Relative volume change, center $xx xx (xx ...) // e
614  // Peak volume center $xx xx (xx ...)
615  // Relative volume change, bass $xx xx (xx ...) // f
616  // Peak volume bass $xx xx (xx ...)
617  if (!$this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) {
618  $this->errors[] = 'Invalid Bits For Volume Description byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)';
619  } else {
620  $incdecflag .= '00';
621  $incdecflag .= $source_data_array['incdec']['right'] ? '1' : '0'; // a - Relative volume change, right
622  $incdecflag .= $source_data_array['incdec']['left'] ? '1' : '0'; // b - Relative volume change, left
623  $incdecflag .= $source_data_array['incdec']['rightrear'] ? '1' : '0'; // c - Relative volume change, right back
624  $incdecflag .= $source_data_array['incdec']['leftrear'] ? '1' : '0'; // d - Relative volume change, left back
625  $incdecflag .= $source_data_array['incdec']['center'] ? '1' : '0'; // e - Relative volume change, center
626  $incdecflag .= $source_data_array['incdec']['bass'] ? '1' : '0'; // f - Relative volume change, bass
627  $framedata .= chr(bindec($incdecflag));
628  $framedata .= chr($source_data_array['bitsvolume']);
629  $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['right'], ceil($source_data_array['bitsvolume'] / 8), false);
630  $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['left'], ceil($source_data_array['bitsvolume'] / 8), false);
631  $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['right'], ceil($source_data_array['bitsvolume'] / 8), false);
632  $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['left'], ceil($source_data_array['bitsvolume'] / 8), false);
633  if ($source_data_array['volumechange']['rightrear'] || $source_data_array['volumechange']['leftrear'] ||
634  $source_data_array['peakvolume']['rightrear'] || $source_data_array['peakvolume']['leftrear'] ||
635  $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']['rightrear'], ceil($source_data_array['bitsvolume']/8), false);
638  $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['leftrear'], ceil($source_data_array['bitsvolume']/8), false);
639  $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['rightrear'], ceil($source_data_array['bitsvolume']/8), false);
640  $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['leftrear'], ceil($source_data_array['bitsvolume']/8), false);
641  }
642  if ($source_data_array['volumechange']['center'] || $source_data_array['peakvolume']['center'] ||
643  $source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) {
644  $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['center'], ceil($source_data_array['bitsvolume']/8), false);
645  $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['center'], ceil($source_data_array['bitsvolume']/8), false);
646  }
647  if ($source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) {
648  $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['bass'], ceil($source_data_array['bitsvolume']/8), false);
649  $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['bass'], ceil($source_data_array['bitsvolume']/8), false);
650  }
651  }
652  break;
653 
654  case 'EQU2':
655  // 4.12 EQU2 Equalisation (2) (ID3v2.4+ only)
656  // Interpolation method $xx
657  // $00 Band
658  // $01 Linear
659  // Identification <text string> $00
660  // The following is then repeated for every adjustment point
661  // Frequency $xx xx
662  // Volume adjustment $xx xx
663  if (($source_data_array['interpolationmethod'] < 0) || ($source_data_array['interpolationmethod'] > 1)) {
664  $this->errors[] = 'Invalid Interpolation Method byte in '.$frame_name.' ('.$source_data_array['interpolationmethod'].') (valid = 0 or 1)';
665  } else {
666  $framedata .= chr($source_data_array['interpolationmethod']);
667  $framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00";
668  foreach ($source_data_array['data'] as $key => $val) {
669  $framedata .= getid3_lib::BigEndian2String(intval(round($key * 2)), 2, false);
670  $framedata .= getid3_lib::BigEndian2String($val, 2, false, true); // signed 16-bit
671  }
672  }
673  break;
674 
675  case 'EQUA':
676  // 4.12 EQUA Equalisation (ID3v2.3 only)
677  // Adjustment bits $xx
678  // This is followed by 2 bytes + ('adjustment bits' rounded up to the
679  // nearest byte) for every equalisation band in the following format,
680  // giving a frequency range of 0 - 32767Hz:
681  // Increment/decrement %x (MSB of the Frequency)
682  // Frequency (lower 15 bits)
683  // Adjustment $xx (xx ...)
684  if (!$this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) {
685  $this->errors[] = 'Invalid Adjustment Bits byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)';
686  } else {
687  $framedata .= chr($source_data_array['adjustmentbits']);
688  foreach ($source_data_array as $key => $val) {
689  if ($key != 'bitsvolume') {
690  if (($key > 32767) || ($key < 0)) {
691  $this->errors[] = 'Invalid Frequency in '.$frame_name.' ('.$key.') (range = 0 to 32767)';
692  } else {
693  if ($val >= 0) {
694  // put MSB of frequency to 1 if increment, 0 if decrement
695  $key |= 0x8000;
696  }
697  $framedata .= getid3_lib::BigEndian2String($key, 2, false);
698  $framedata .= getid3_lib::BigEndian2String($val, ceil($source_data_array['adjustmentbits'] / 8), false);
699  }
700  }
701  }
702  }
703  break;
704 
705  case 'RVRB':
706  // 4.13 RVRB Reverb
707  // Reverb left (ms) $xx xx
708  // Reverb right (ms) $xx xx
709  // Reverb bounces, left $xx
710  // Reverb bounces, right $xx
711  // Reverb feedback, left to left $xx
712  // Reverb feedback, left to right $xx
713  // Reverb feedback, right to right $xx
714  // Reverb feedback, right to left $xx
715  // Premix left to right $xx
716  // Premix right to left $xx
717  if (!$this->IsWithinBitRange($source_data_array['left'], 16, false)) {
718  $this->errors[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['left'].') (range = 0 to 65535)';
719  } elseif (!$this->IsWithinBitRange($source_data_array['right'], 16, false)) {
720  $this->errors[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['right'].') (range = 0 to 65535)';
721  } elseif (!$this->IsWithinBitRange($source_data_array['bouncesL'], 8, false)) {
722  $this->errors[] = 'Invalid Reverb Bounces, Left in '.$frame_name.' ('.$source_data_array['bouncesL'].') (range = 0 to 255)';
723  } elseif (!$this->IsWithinBitRange($source_data_array['bouncesR'], 8, false)) {
724  $this->errors[] = 'Invalid Reverb Bounces, Right in '.$frame_name.' ('.$source_data_array['bouncesR'].') (range = 0 to 255)';
725  } elseif (!$this->IsWithinBitRange($source_data_array['feedbackLL'], 8, false)) {
726  $this->errors[] = 'Invalid Reverb Feedback, Left-To-Left in '.$frame_name.' ('.$source_data_array['feedbackLL'].') (range = 0 to 255)';
727  } elseif (!$this->IsWithinBitRange($source_data_array['feedbackLR'], 8, false)) {
728  $this->errors[] = 'Invalid Reverb Feedback, Left-To-Right in '.$frame_name.' ('.$source_data_array['feedbackLR'].') (range = 0 to 255)';
729  } elseif (!$this->IsWithinBitRange($source_data_array['feedbackRR'], 8, false)) {
730  $this->errors[] = 'Invalid Reverb Feedback, Right-To-Right in '.$frame_name.' ('.$source_data_array['feedbackRR'].') (range = 0 to 255)';
731  } elseif (!$this->IsWithinBitRange($source_data_array['feedbackRL'], 8, false)) {
732  $this->errors[] = 'Invalid Reverb Feedback, Right-To-Left in '.$frame_name.' ('.$source_data_array['feedbackRL'].') (range = 0 to 255)';
733  } elseif (!$this->IsWithinBitRange($source_data_array['premixLR'], 8, false)) {
734  $this->errors[] = 'Invalid Premix, Left-To-Right in '.$frame_name.' ('.$source_data_array['premixLR'].') (range = 0 to 255)';
735  } elseif (!$this->IsWithinBitRange($source_data_array['premixRL'], 8, false)) {
736  $this->errors[] = 'Invalid Premix, Right-To-Left in '.$frame_name.' ('.$source_data_array['premixRL'].') (range = 0 to 255)';
737  } else {
738  $framedata .= getid3_lib::BigEndian2String($source_data_array['left'], 2, false);
739  $framedata .= getid3_lib::BigEndian2String($source_data_array['right'], 2, false);
740  $framedata .= chr($source_data_array['bouncesL']);
741  $framedata .= chr($source_data_array['bouncesR']);
742  $framedata .= chr($source_data_array['feedbackLL']);
743  $framedata .= chr($source_data_array['feedbackLR']);
744  $framedata .= chr($source_data_array['feedbackRR']);
745  $framedata .= chr($source_data_array['feedbackRL']);
746  $framedata .= chr($source_data_array['premixLR']);
747  $framedata .= chr($source_data_array['premixRL']);
748  }
749  break;
750 
751  case 'APIC':
752  // 4.14 APIC Attached picture
753  // Text encoding $xx
754  // MIME type <text string> $00
755  // Picture type $xx
756  // Description <text string according to encoding> $00 (00)
757  // Picture data <binary data>
758  $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
759  if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
760  $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
761  } elseif (!$this->ID3v2IsValidAPICpicturetype($source_data_array['picturetypeid'])) {
762  $this->errors[] = 'Invalid Picture Type byte in '.$frame_name.' ('.$source_data_array['picturetypeid'].') for ID3v2.'.$this->majorversion;
763  } elseif (($this->majorversion >= 3) && (!$this->ID3v2IsValidAPICimageformat($source_data_array['mime']))) {
764  $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].') for ID3v2.'.$this->majorversion;
765  } elseif (($source_data_array['mime'] == '-->') && (!$this->IsValidURL($source_data_array['data'], false, false))) {
766  //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
767  // probably should be an error, need to rewrite IsValidURL() to handle other encodings
768  $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
769  } else {
770  $framedata .= chr($source_data_array['encodingid']);
771  $framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00";
772  $framedata .= chr($source_data_array['picturetypeid']);
773  $framedata .= (!empty($source_data_array['description']) ? $source_data_array['description'] : '').getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
774  $framedata .= $source_data_array['data'];
775  }
776  break;
777 
778  case 'GEOB':
779  // 4.15 GEOB General encapsulated object
780  // Text encoding $xx
781  // MIME type <text string> $00
782  // Filename <text string according to encoding> $00 (00)
783  // Content description <text string according to encoding> $00 (00)
784  // Encapsulated object <binary data>
785  $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
786  if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
787  $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
788  } elseif (!$this->IsValidMIMEstring($source_data_array['mime'])) {
789  $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].')';
790  } elseif (!$source_data_array['description']) {
791  $this->errors[] = 'Missing Description in '.$frame_name;
792  } else {
793  $framedata .= chr($source_data_array['encodingid']);
794  $framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00";
795  $framedata .= $source_data_array['filename'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
796  $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
797  $framedata .= $source_data_array['data'];
798  }
799  break;
800 
801  case 'PCNT':
802  // 4.16 PCNT Play counter
803  // When the counter reaches all one's, one byte is inserted in
804  // front of the counter thus making the counter eight bits bigger
805  // Counter $xx xx xx xx (xx ...)
806  $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false);
807  break;
808 
809  case 'POPM':
810  // 4.17 POPM Popularimeter
811  // When the counter reaches all one's, one byte is inserted in
812  // front of the counter thus making the counter eight bits bigger
813  // Email to user <text string> $00
814  // Rating $xx
815  // Counter $xx xx xx xx (xx ...)
816  if (!$this->IsWithinBitRange($source_data_array['rating'], 8, false)) {
817  $this->errors[] = 'Invalid Rating byte in '.$frame_name.' ('.$source_data_array['rating'].') (range = 0 to 255)';
818  } elseif (!IsValidEmail($source_data_array['email'])) {
819  $this->errors[] = 'Invalid Email in '.$frame_name.' ('.$source_data_array['email'].')';
820  } else {
821  $framedata .= str_replace("\x00", '', $source_data_array['email'])."\x00";
822  $framedata .= chr($source_data_array['rating']);
823  $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false);
824  }
825  break;
826 
827  case 'RBUF':
828  // 4.18 RBUF Recommended buffer size
829  // Buffer size $xx xx xx
830  // Embedded info flag %0000000x
831  // Offset to next tag $xx xx xx xx
832  if (!$this->IsWithinBitRange($source_data_array['buffersize'], 24, false)) {
833  $this->errors[] = 'Invalid Buffer Size in '.$frame_name;
834  } elseif (!$this->IsWithinBitRange($source_data_array['nexttagoffset'], 32, false)) {
835  $this->errors[] = 'Invalid Offset To Next Tag in '.$frame_name;
836  } else {
837  $framedata .= getid3_lib::BigEndian2String($source_data_array['buffersize'], 3, false);
838  $flag .= '0000000';
839  $flag .= $source_data_array['flags']['embededinfo'] ? '1' : '0';
840  $framedata .= chr(bindec($flag));
841  $framedata .= getid3_lib::BigEndian2String($source_data_array['nexttagoffset'], 4, false);
842  }
843  break;
844 
845  case 'AENC':
846  // 4.19 AENC Audio encryption
847  // Owner identifier <text string> $00
848  // Preview start $xx xx
849  // Preview length $xx xx
850  // Encryption info <binary data>
851  if (!$this->IsWithinBitRange($source_data_array['previewstart'], 16, false)) {
852  $this->errors[] = 'Invalid Preview Start in '.$frame_name.' ('.$source_data_array['previewstart'].')';
853  } elseif (!$this->IsWithinBitRange($source_data_array['previewlength'], 16, false)) {
854  $this->errors[] = 'Invalid Preview Length in '.$frame_name.' ('.$source_data_array['previewlength'].')';
855  } else {
856  $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
857  $framedata .= getid3_lib::BigEndian2String($source_data_array['previewstart'], 2, false);
858  $framedata .= getid3_lib::BigEndian2String($source_data_array['previewlength'], 2, false);
859  $framedata .= $source_data_array['encryptioninfo'];
860  }
861  break;
862 
863  case 'LINK':
864  // 4.20 LINK Linked information
865  // Frame identifier $xx xx xx xx
866  // URL <text string> $00
867  // ID and additional data <text string(s)>
868  if (!getid3_id3v2::IsValidID3v2FrameName($source_data_array['frameid'], $this->majorversion)) {
869  $this->errors[] = 'Invalid Frame Identifier in '.$frame_name.' ('.$source_data_array['frameid'].')';
870  } elseif (!$this->IsValidURL($source_data_array['data'], true, false)) {
871  //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
872  // probably should be an error, need to rewrite IsValidURL() to handle other encodings
873  $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
874  } 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'] == '')) {
875  $this->errors[] = 'Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
876  } elseif (($source_data_array['frameid'] == 'USER') && (getid3_id3v2::LanguageLookup($source_data_array['additionaldata'], true) == '')) {
877  $this->errors[] = 'Language must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
878  } elseif (($source_data_array['frameid'] == 'PRIV') && ($source_data_array['additionaldata'] == '')) {
879  $this->errors[] = 'Owner Identifier must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
880  } 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) == ''))) {
881  $this->errors[] = 'Language followed by Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
882  } else {
883  $framedata .= $source_data_array['frameid'];
884  $framedata .= str_replace("\x00", '', $source_data_array['data'])."\x00";
885  switch ($source_data_array['frameid']) {
886  case 'COMM':
887  case 'SYLT':
888  case 'USLT':
889  case 'PRIV':
890  case 'USER':
891  case 'AENC':
892  case 'APIC':
893  case 'GEOB':
894  case 'TXXX':
895  $framedata .= $source_data_array['additionaldata'];
896  break;
897  case 'ASPI':
898  case 'ETCO':
899  case 'EQU2':
900  case 'MCID':
901  case 'MLLT':
902  case 'OWNE':
903  case 'RVA2':
904  case 'RVRB':
905  case 'SYTC':
906  case 'IPLS':
907  case 'RVAD':
908  case 'EQUA':
909  // no additional data required
910  break;
911  case 'RBUF':
912  if ($this->majorversion == 3) {
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 
918  default:
919  if ((substr($source_data_array['frameid'], 0, 1) == 'T') || (substr($source_data_array['frameid'], 0, 1) == 'W')) {
920  // no additional data required
921  } else {
922  $this->errors[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion.')';
923  }
924  break;
925  }
926  }
927  break;
928 
929  case 'POSS':
930  // 4.21 POSS Position synchronisation frame (ID3v2.3+ only)
931  // Time stamp format $xx
932  // Position $xx (xx ...)
933  if (($source_data_array['timestampformat'] < 1) || ($source_data_array['timestampformat'] > 2)) {
934  $this->errors[] = 'Invalid Time Stamp Format in '.$frame_name.' ('.$source_data_array['timestampformat'].') (valid = 1 or 2)';
935  } elseif (!$this->IsWithinBitRange($source_data_array['position'], 32, false)) {
936  $this->errors[] = 'Invalid Position in '.$frame_name.' ('.$source_data_array['position'].') (range = 0 to 4294967295)';
937  } else {
938  $framedata .= chr($source_data_array['timestampformat']);
939  $framedata .= getid3_lib::BigEndian2String($source_data_array['position'], 4, false);
940  }
941  break;
942 
943  case 'USER':
944  // 4.22 USER Terms of use (ID3v2.3+ only)
945  // Text encoding $xx
946  // Language $xx xx xx
947  // The actual text <text string according to encoding>
948  $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
949  if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
950  $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')';
951  } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
952  $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
953  } else {
954  $framedata .= chr($source_data_array['encodingid']);
955  $framedata .= strtolower($source_data_array['language']);
956  $framedata .= $source_data_array['data'];
957  }
958  break;
959 
960  case 'OWNE':
961  // 4.23 OWNE Ownership frame (ID3v2.3+ only)
962  // Text encoding $xx
963  // Price paid <text string> $00
964  // Date of purch. <text string>
965  // Seller <text string according to encoding>
966  $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
967  if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
968  $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')';
969  } elseif (!$this->IsANumber($source_data_array['pricepaid']['value'], false)) {
970  $this->errors[] = 'Invalid Price Paid in '.$frame_name.' ('.$source_data_array['pricepaid']['value'].')';
971  } elseif (!$this->IsValidDateStampString($source_data_array['purchasedate'])) {
972  $this->errors[] = 'Invalid Date Of Purchase in '.$frame_name.' ('.$source_data_array['purchasedate'].') (format = YYYYMMDD)';
973  } else {
974  $framedata .= chr($source_data_array['encodingid']);
975  $framedata .= str_replace("\x00", '', $source_data_array['pricepaid']['value'])."\x00";
976  $framedata .= $source_data_array['purchasedate'];
977  $framedata .= $source_data_array['seller'];
978  }
979  break;
980 
981  case 'COMR':
982  // 4.24 COMR Commercial frame (ID3v2.3+ only)
983  // Text encoding $xx
984  // Price string <text string> $00
985  // Valid until <text string>
986  // Contact URL <text string> $00
987  // Received as $xx
988  // Name of seller <text string according to encoding> $00 (00)
989  // Description <text string according to encoding> $00 (00)
990  // Picture MIME type <string> $00
991  // Seller logo <binary data>
992  $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
993  if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
994  $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')';
995  } elseif (!$this->IsValidDateStampString($source_data_array['pricevaliduntil'])) {
996  $this->errors[] = 'Invalid Valid Until date in '.$frame_name.' ('.$source_data_array['pricevaliduntil'].') (format = YYYYMMDD)';
997  } elseif (!$this->IsValidURL($source_data_array['contacturl'], false, true)) {
998  $this->errors[] = 'Invalid Contact URL in '.$frame_name.' ('.$source_data_array['contacturl'].') (allowed schemes: http, https, ftp, mailto)';
999  } elseif (!$this->ID3v2IsValidCOMRreceivedAs($source_data_array['receivedasid'])) {
1000  $this->errors[] = 'Invalid Received As byte in '.$frame_name.' ('.$source_data_array['contacturl'].') (range = 0 to 8)';
1001  } elseif (!$this->IsValidMIMEstring($source_data_array['mime'])) {
1002  $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].')';
1003  } else {
1004  $framedata .= chr($source_data_array['encodingid']);
1005  unset($pricestring);
1006  foreach ($source_data_array['price'] as $key => $val) {
1007  if ($this->ID3v2IsValidPriceString($key.$val['value'])) {
1008  $pricestrings[] = $key.$val['value'];
1009  } else {
1010  $this->errors[] = 'Invalid Price String in '.$frame_name.' ('.$key.$val['value'].')';
1011  }
1012  }
1013  $framedata .= implode('/', $pricestrings);
1014  $framedata .= $source_data_array['pricevaliduntil'];
1015  $framedata .= str_replace("\x00", '', $source_data_array['contacturl'])."\x00";
1016  $framedata .= chr($source_data_array['receivedasid']);
1017  $framedata .= $source_data_array['sellername'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
1018  $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
1019  $framedata .= $source_data_array['mime']."\x00";
1020  $framedata .= $source_data_array['logo'];
1021  }
1022  break;
1023 
1024  case 'ENCR':
1025  // 4.25 ENCR Encryption method registration (ID3v2.3+ only)
1026  // Owner identifier <text string> $00
1027  // Method symbol $xx
1028  // Encryption data <binary data>
1029  if (!$this->IsWithinBitRange($source_data_array['methodsymbol'], 8, false)) {
1030  $this->errors[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['methodsymbol'].') (range = 0 to 255)';
1031  } else {
1032  $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
1033  $framedata .= ord($source_data_array['methodsymbol']);
1034  $framedata .= $source_data_array['data'];
1035  }
1036  break;
1037 
1038  case 'GRID':
1039  // 4.26 GRID Group identification registration (ID3v2.3+ only)
1040  // Owner identifier <text string> $00
1041  // Group symbol $xx
1042  // Group dependent data <binary data>
1043  if (!$this->IsWithinBitRange($source_data_array['groupsymbol'], 8, false)) {
1044  $this->errors[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['groupsymbol'].') (range = 0 to 255)';
1045  } else {
1046  $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
1047  $framedata .= ord($source_data_array['groupsymbol']);
1048  $framedata .= $source_data_array['data'];
1049  }
1050  break;
1051 
1052  case 'PRIV':
1053  // 4.27 PRIV Private frame (ID3v2.3+ only)
1054  // Owner identifier <text string> $00
1055  // The private data <binary data>
1056  $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
1057  $framedata .= $source_data_array['data'];
1058  break;
1059 
1060  case 'SIGN':
1061  // 4.28 SIGN Signature frame (ID3v2.4+ only)
1062  // Group symbol $xx
1063  // Signature <binary data>
1064  if (!$this->IsWithinBitRange($source_data_array['groupsymbol'], 8, false)) {
1065  $this->errors[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['groupsymbol'].') (range = 0 to 255)';
1066  } else {
1067  $framedata .= ord($source_data_array['groupsymbol']);
1068  $framedata .= $source_data_array['data'];
1069  }
1070  break;
1071 
1072  case 'SEEK':
1073  // 4.29 SEEK Seek frame (ID3v2.4+ only)
1074  // Minimum offset to next tag $xx xx xx xx
1075  if (!$this->IsWithinBitRange($source_data_array['data'], 32, false)) {
1076  $this->errors[] = 'Invalid Minimum Offset in '.$frame_name.' ('.$source_data_array['data'].') (range = 0 to 4294967295)';
1077  } else {
1078  $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false);
1079  }
1080  break;
1081 
1082  case 'ASPI':
1083  // 4.30 ASPI Audio seek point index (ID3v2.4+ only)
1084  // Indexed data start (S) $xx xx xx xx
1085  // Indexed data length (L) $xx xx xx xx
1086  // Number of index points (N) $xx xx
1087  // Bits per index point (b) $xx
1088  // Then for every index point the following data is included:
1089  // Fraction at index (Fi) $xx (xx)
1090  if (!$this->IsWithinBitRange($source_data_array['datastart'], 32, false)) {
1091  $this->errors[] = 'Invalid Indexed Data Start in '.$frame_name.' ('.$source_data_array['datastart'].') (range = 0 to 4294967295)';
1092  } elseif (!$this->IsWithinBitRange($source_data_array['datalength'], 32, false)) {
1093  $this->errors[] = 'Invalid Indexed Data Length in '.$frame_name.' ('.$source_data_array['datalength'].') (range = 0 to 4294967295)';
1094  } elseif (!$this->IsWithinBitRange($source_data_array['indexpoints'], 16, false)) {
1095  $this->errors[] = 'Invalid Number Of Index Points in '.$frame_name.' ('.$source_data_array['indexpoints'].') (range = 0 to 65535)';
1096  } elseif (!$this->IsWithinBitRange($source_data_array['bitsperpoint'], 8, false)) {
1097  $this->errors[] = 'Invalid Bits Per Index Point in '.$frame_name.' ('.$source_data_array['bitsperpoint'].') (range = 0 to 255)';
1098  } elseif ($source_data_array['indexpoints'] != count($source_data_array['indexes'])) {
1099  $this->errors[] = 'Number Of Index Points does not match actual supplied data in '.$frame_name;
1100  } else {
1101  $framedata .= getid3_lib::BigEndian2String($source_data_array['datastart'], 4, false);
1102  $framedata .= getid3_lib::BigEndian2String($source_data_array['datalength'], 4, false);
1103  $framedata .= getid3_lib::BigEndian2String($source_data_array['indexpoints'], 2, false);
1104  $framedata .= getid3_lib::BigEndian2String($source_data_array['bitsperpoint'], 1, false);
1105  foreach ($source_data_array['indexes'] as $key => $val) {
1106  $framedata .= getid3_lib::BigEndian2String($val, ceil($source_data_array['bitsperpoint'] / 8), false);
1107  }
1108  }
1109  break;
1110 
1111  case 'RGAD':
1112  // RGAD Replay Gain Adjustment
1113  // http://privatewww.essex.ac.uk/~djmrob/replaygain/
1114  // Peak Amplitude $xx $xx $xx $xx
1115  // Radio Replay Gain Adjustment %aaabbbcd %dddddddd
1116  // Audiophile Replay Gain Adjustment %aaabbbcd %dddddddd
1117  // a - name code
1118  // b - originator code
1119  // c - sign bit
1120  // d - replay gain adjustment
1121 
1122  if (($source_data_array['track_adjustment'] > 51) || ($source_data_array['track_adjustment'] < -51)) {
1123  $this->errors[] = 'Invalid Track Adjustment in '.$frame_name.' ('.$source_data_array['track_adjustment'].') (range = -51.0 to +51.0)';
1124  } elseif (($source_data_array['album_adjustment'] > 51) || ($source_data_array['album_adjustment'] < -51)) {
1125  $this->errors[] = 'Invalid Album Adjustment in '.$frame_name.' ('.$source_data_array['album_adjustment'].') (range = -51.0 to +51.0)';
1126  } elseif (!$this->ID3v2IsValidRGADname($source_data_array['raw']['track_name'])) {
1127  $this->errors[] = 'Invalid Track Name Code in '.$frame_name.' ('.$source_data_array['raw']['track_name'].') (range = 0 to 2)';
1128  } elseif (!$this->ID3v2IsValidRGADname($source_data_array['raw']['album_name'])) {
1129  $this->errors[] = 'Invalid Album Name Code in '.$frame_name.' ('.$source_data_array['raw']['album_name'].') (range = 0 to 2)';
1130  } elseif (!$this->ID3v2IsValidRGADoriginator($source_data_array['raw']['track_originator'])) {
1131  $this->errors[] = 'Invalid Track Originator Code in '.$frame_name.' ('.$source_data_array['raw']['track_originator'].') (range = 0 to 3)';
1132  } elseif (!$this->ID3v2IsValidRGADoriginator($source_data_array['raw']['album_originator'])) {
1133  $this->errors[] = 'Invalid Album Originator Code in '.$frame_name.' ('.$source_data_array['raw']['album_originator'].') (range = 0 to 3)';
1134  } else {
1135  $framedata .= getid3_lib::Float2String($source_data_array['peakamplitude'], 32);
1136  $framedata .= getid3_lib::RGADgainString($source_data_array['raw']['track_name'], $source_data_array['raw']['track_originator'], $source_data_array['track_adjustment']);
1137  $framedata .= getid3_lib::RGADgainString($source_data_array['raw']['album_name'], $source_data_array['raw']['album_originator'], $source_data_array['album_adjustment']);
1138  }
1139  break;
1140 
1141  default:
1142  if ((($this->majorversion == 2) && (strlen($frame_name) != 3)) || (($this->majorversion > 2) && (strlen($frame_name) != 4))) {
1143  $this->errors[] = 'Invalid frame name "'.$frame_name.'" for ID3v2.'.$this->majorversion;
1144  } elseif ($frame_name{0} == 'T') {
1145  // 4.2. T??? Text information frames
1146  // Text encoding $xx
1147  // Information <text string(s) according to encoding>
1148  $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
1149  if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
1150  $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
1151  } else {
1152  $framedata .= chr($source_data_array['encodingid']);
1153  $framedata .= $source_data_array['data'];
1154  }
1155  } elseif ($frame_name{0} == 'W') {
1156  // 4.3. W??? URL link frames
1157  // URL <text string>
1158  if (!$this->IsValidURL($source_data_array['data'], false, false)) {
1159  //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
1160  // probably should be an error, need to rewrite IsValidURL() to handle other encodings
1161  $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
1162  } else {
1163  $framedata .= $source_data_array['data'];
1164  }
1165  } else {
1166  $this->errors[] = $frame_name.' not yet supported in $this->GenerateID3v2FrameData()';
1167  }
1168  break;
1169  }
1170  }
1171  if (!empty($this->errors)) {
1172  return false;
1173  }
1174  return $framedata;
1175  }
ID3v2IsValidSYLTtype($contenttype)
RGADgainString($namecode, $originatorcode, $replaygain)
LanguageLookup($languagecode, $casesensitive=false)
ID3v2IsValidRGADname($RGADname)
ID3v2IsValidCOMRreceivedAs($receivedas)
ID3v2IsValidETCOevent($eventid)
IsWithinBitRange($number, $maxbits, $signed=false)
BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false)
Definition: getid3.lib.php:281
ID3v2IsValidTextEncoding($textencodingbyte)
IsValidURL($url, $allowUserPass=false)
ID3v2IsValidPriceString($pricestring)
TextEncodingTerminatorLookup($encoding)
IsValidID3v2FrameName($framename, $id3v2majorversion)
Dec2Bin($number)
Definition: getid3.lib.php:302
ID3v2IsValidRGADoriginator($RGADoriginator)
ID3v2IsValidAPICpicturetype($picturetype)
IsValidMIMEstring($mimestring)
ID3v2IsValidAPICimageformat($imageformat)
Float2String($floatvalue, $bits)
Definition: getid3.lib.php:123
+ Here is the call graph for this function:

◆ GenerateID3v2FrameFlags() [1/2]

getid3_write_id3v2::GenerateID3v2FrameFlags (   $TagAlter = false,
  $FileAlter = false,
  $ReadOnly = false,
  $Compression = false,
  $Encryption = false,
  $GroupingIdentity = false,
  $Unsynchronisation = false,
  $DataLengthIndicator = false 
)

Definition at line 256 of file write.id3v2.php.

Referenced by GenerateID3v2Tag().

256  {
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  }
+ Here is the caller graph for this function:

◆ GenerateID3v2FrameFlags() [2/2]

getid3_write_id3v2::GenerateID3v2FrameFlags (   $TagAlter = false,
  $FileAlter = false,
  $ReadOnly = false,
  $Compression = false,
  $Encryption = false,
  $GroupingIdentity = false,
  $Unsynchronisation = false,
  $DataLengthIndicator = false 
)

Definition at line 263 of file write.id3v2.php.

263  {
264  switch ($this->majorversion) {
265  case 4:
266  // %0abc0000 %0h00kmnp
267  $flag1 = '0';
268  $flag1 .= $TagAlter ? '1' : '0'; // a - Tag alter preservation (true == discard)
269  $flag1 .= $FileAlter ? '1' : '0'; // b - File alter preservation (true == discard)
270  $flag1 .= $ReadOnly ? '1' : '0'; // c - Read only (true == read only)
271  $flag1 .= '0000';
272 
273  $flag2 = '0';
274  $flag2 .= $GroupingIdentity ? '1' : '0'; // h - Grouping identity (true == contains group information)
275  $flag2 .= '00';
276  $flag2 .= $Compression ? '1' : '0'; // k - Compression (true == compressed)
277  $flag2 .= $Encryption ? '1' : '0'; // m - Encryption (true == encrypted)
278  $flag2 .= $Unsynchronisation ? '1' : '0'; // n - Unsynchronisation (true == unsynchronised)
279  $flag2 .= $DataLengthIndicator ? '1' : '0'; // p - Data length indicator (true == data length indicator added)
280  break;
281 
282  case 3:
283  // %abc00000 %ijk00000
284  $flag1 = $TagAlter ? '1' : '0'; // a - Tag alter preservation (true == discard)
285  $flag1 .= $FileAlter ? '1' : '0'; // b - File alter preservation (true == discard)
286  $flag1 .= $ReadOnly ? '1' : '0'; // c - Read only (true == read only)
287  $flag1 .= '00000';
288 
289  $flag2 = $Compression ? '1' : '0'; // i - Compression (true == compressed)
290  $flag2 .= $Encryption ? '1' : '0'; // j - Encryption (true == encrypted)
291  $flag2 .= $GroupingIdentity ? '1' : '0'; // k - Grouping identity (true == contains group information)
292  $flag2 .= '00000';
293  break;
294 
295  default:
296  return false;
297  break;
298 
299  }
300  return chr(bindec($flag1)).chr(bindec($flag2));
301  }

◆ GenerateID3v2Tag() [1/2]

getid3_write_id3v2::GenerateID3v2Tag (   $noerrorsonly = true)

Definition at line 1525 of file write.id3v2.php.

References getid3_lib\BigEndian2String(), GenerateID3v2FrameData(), GenerateID3v2FrameFlags(), GenerateID3v2TagFlags(), ID3v2FrameFlagsLookupFileAlter(), ID3v2FrameFlagsLookupTagAlter(), ID3v2FrameIsAllowed(), getid3_id3v2\ID3v2HeaderLength(), getid3_id3v2\IsValidID3v2FrameName(), and Unsynchronise().

Referenced by WriteID3v2().

1525  {
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  }
ID3v2HeaderLength($majorversion)
BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false)
Definition: getid3.lib.php:281
ID3v2FrameFlagsLookupFileAlter($framename)
GenerateID3v2FrameFlags($TagAlter=false, $FileAlter=false, $ReadOnly=false, $Compression=false, $Encryption=false, $GroupingIdentity=false, $Unsynchronisation=false, $DataLengthIndicator=false)
IsValidID3v2FrameName($framename, $id3v2majorversion)
GenerateID3v2FrameData($frame_name, $source_data_array)
GenerateID3v2TagFlags($flags)
ID3v2FrameFlagsLookupTagAlter($framename)
ID3v2FrameIsAllowed($frame_name, $source_data_array)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenerateID3v2Tag() [2/2]

getid3_write_id3v2::GenerateID3v2Tag (   $noerrorsonly = true)

Definition at line 1534 of file write.id3v2.php.

References getid3_lib\BigEndian2String(), GenerateID3v2FrameData(), GenerateID3v2FrameFlags(), GenerateID3v2TagFlags(), getid3_lib\iconv_fallback(), ID3v2FrameFlagsLookupFileAlter(), ID3v2FrameFlagsLookupTagAlter(), ID3v2FrameIsAllowed(), getid3_id3v2\ID3v2HeaderLength(), getid3_id3v2\IsValidID3v2FrameName(), and Unsynchronise().

1534  {
1535  $this->ID3v2FrameIsAllowed(null, ''); // clear static array in case this isn't the first call to $this->GenerateID3v2Tag()
1536 
1537  $tagstring = '';
1538  if (is_array($this->tag_data)) {
1539  foreach ($this->tag_data as $frame_name => $frame_rawinputdata) {
1540  foreach ($frame_rawinputdata as $irrelevantindex => $source_data_array) {
1541  if (getid3_id3v2::IsValidID3v2FrameName($frame_name, $this->majorversion)) {
1542  unset($frame_length);
1543  unset($frame_flags);
1544  $frame_data = false;
1545  if ($this->ID3v2FrameIsAllowed($frame_name, $source_data_array)) {
1546  if(array_key_exists('description', $source_data_array) && array_key_exists('encodingid', $source_data_array) && array_key_exists('encoding', $this->tag_data)) {
1547  $source_data_array['description'] = getid3_lib::iconv_fallback($this->tag_data['encoding'], $source_data_array['encoding'], $source_data_array['description']);
1548  }
1549  if ($frame_data = $this->GenerateID3v2FrameData($frame_name, $source_data_array)) {
1550  $FrameUnsynchronisation = false;
1551  if ($this->majorversion >= 4) {
1552  // frame-level unsynchronisation
1553  $unsynchdata = $frame_data;
1554  if ($this->id3v2_use_unsynchronisation) {
1555  $unsynchdata = $this->Unsynchronise($frame_data);
1556  }
1557  if (strlen($unsynchdata) != strlen($frame_data)) {
1558  // unsynchronisation needed
1559  $FrameUnsynchronisation = true;
1560  $frame_data = $unsynchdata;
1561  if (isset($TagUnsynchronisation) && $TagUnsynchronisation === false) {
1562  // only set to true if ALL frames are unsynchronised
1563  } else {
1564  $TagUnsynchronisation = true;
1565  }
1566  } else {
1567  if (isset($TagUnsynchronisation)) {
1568  $TagUnsynchronisation = false;
1569  }
1570  }
1571  unset($unsynchdata);
1572 
1573  $frame_length = getid3_lib::BigEndian2String(strlen($frame_data), 4, true);
1574  } else {
1575  $frame_length = getid3_lib::BigEndian2String(strlen($frame_data), 4, false);
1576  }
1577  $frame_flags = $this->GenerateID3v2FrameFlags($this->ID3v2FrameFlagsLookupTagAlter($frame_name), $this->ID3v2FrameFlagsLookupFileAlter($frame_name), false, false, false, false, $FrameUnsynchronisation, false);
1578  }
1579  } else {
1580  $this->errors[] = 'Frame "'.$frame_name.'" is NOT allowed';
1581  }
1582  if ($frame_data === false) {
1583  $this->errors[] = '$this->GenerateID3v2FrameData() failed for "'.$frame_name.'"';
1584  if ($noerrorsonly) {
1585  return false;
1586  } else {
1587  unset($frame_name);
1588  }
1589  }
1590  } else {
1591  // ignore any invalid frame names, including 'title', 'header', etc
1592  $this->warnings[] = 'Ignoring invalid ID3v2 frame type: "'.$frame_name.'"';
1593  unset($frame_name);
1594  unset($frame_length);
1595  unset($frame_flags);
1596  unset($frame_data);
1597  }
1598  if (isset($frame_name) && isset($frame_length) && isset($frame_flags) && isset($frame_data)) {
1599  $tagstring .= $frame_name.$frame_length.$frame_flags.$frame_data;
1600  }
1601  }
1602  }
1603 
1604  if (!isset($TagUnsynchronisation)) {
1605  $TagUnsynchronisation = false;
1606  }
1607  if (($this->majorversion <= 3) && $this->id3v2_use_unsynchronisation) {
1608  // tag-level unsynchronisation
1609  $unsynchdata = $this->Unsynchronise($tagstring);
1610  if (strlen($unsynchdata) != strlen($tagstring)) {
1611  // unsynchronisation needed
1612  $TagUnsynchronisation = true;
1613  $tagstring = $unsynchdata;
1614  }
1615  }
1616 
1617  while ($this->paddedlength < (strlen($tagstring) + getid3_id3v2::ID3v2HeaderLength($this->majorversion))) {
1618  $this->paddedlength += 1024;
1619  }
1620 
1621  $footer = false; // ID3v2 footers not yet supported in getID3()
1622  if (!$footer && ($this->paddedlength > (strlen($tagstring) + getid3_id3v2::ID3v2HeaderLength($this->majorversion)))) {
1623  // pad up to $paddedlength bytes if unpadded tag is shorter than $paddedlength
1624  // "Furthermore it MUST NOT have any padding when a tag footer is added to the tag."
1625  if (($this->paddedlength - strlen($tagstring) - getid3_id3v2::ID3v2HeaderLength($this->majorversion)) > 0) {
1626  $tagstring .= str_repeat("\x00", $this->paddedlength - strlen($tagstring) - getid3_id3v2::ID3v2HeaderLength($this->majorversion));
1627  }
1628  }
1629  if ($this->id3v2_use_unsynchronisation && (substr($tagstring, strlen($tagstring) - 1, 1) == "\xFF")) {
1630  // special unsynchronisation case:
1631  // if last byte == $FF then appended a $00
1632  $TagUnsynchronisation = true;
1633  $tagstring .= "\x00";
1634  }
1635 
1636  $tagheader = 'ID3';
1637  $tagheader .= chr($this->majorversion);
1638  $tagheader .= chr($this->minorversion);
1639  $tagheader .= $this->GenerateID3v2TagFlags(array('unsynchronisation'=>$TagUnsynchronisation));
1640  $tagheader .= getid3_lib::BigEndian2String(strlen($tagstring), 4, true);
1641 
1642  return $tagheader.$tagstring;
1643  }
1644  $this->errors[] = 'tag_data is not an array in GenerateID3v2Tag()';
1645  return false;
1646  }
ID3v2HeaderLength($majorversion)
BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false)
Definition: getid3.lib.php:281
ID3v2FrameFlagsLookupFileAlter($framename)
GenerateID3v2FrameFlags($TagAlter=false, $FileAlter=false, $ReadOnly=false, $Compression=false, $Encryption=false, $GroupingIdentity=false, $Unsynchronisation=false, $DataLengthIndicator=false)
iconv_fallback($in_charset, $out_charset, $string)
Definition: getid3.lib.php:951
IsValidID3v2FrameName($framename, $id3v2majorversion)
GenerateID3v2FrameData($frame_name, $source_data_array)
GenerateID3v2TagFlags($flags)
ID3v2FrameFlagsLookupTagAlter($framename)
ID3v2FrameIsAllowed($frame_name, $source_data_array)
+ Here is the call graph for this function:

◆ GenerateID3v2TagFlags() [1/2]

getid3_write_id3v2::GenerateID3v2TagFlags (   $flags)

Definition at line 222 of file write.id3v2.php.

Referenced by GenerateID3v2Tag().

222  {
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  }
+ Here is the caller graph for this function:

◆ GenerateID3v2TagFlags() [2/2]

getid3_write_id3v2::GenerateID3v2TagFlags (   $flags)

Definition at line 229 of file write.id3v2.php.

229  {
230  switch ($this->majorversion) {
231  case 4:
232  // %abcd0000
233  $flag = (!empty($flags['unsynchronisation']) ? '1' : '0'); // a - Unsynchronisation
234  $flag .= (!empty($flags['extendedheader'] ) ? '1' : '0'); // b - Extended header
235  $flag .= (!empty($flags['experimental'] ) ? '1' : '0'); // c - Experimental indicator
236  $flag .= (!empty($flags['footer'] ) ? '1' : '0'); // d - Footer present
237  $flag .= '0000';
238  break;
239 
240  case 3:
241  // %abc00000
242  $flag = (!empty($flags['unsynchronisation']) ? '1' : '0'); // a - Unsynchronisation
243  $flag .= (!empty($flags['extendedheader'] ) ? '1' : '0'); // b - Extended header
244  $flag .= (!empty($flags['experimental'] ) ? '1' : '0'); // c - Experimental indicator
245  $flag .= '00000';
246  break;
247 
248  case 2:
249  // %ab000000
250  $flag = (!empty($flags['unsynchronisation']) ? '1' : '0'); // a - Unsynchronisation
251  $flag .= (!empty($flags['compression'] ) ? '1' : '0'); // b - Compression
252  $flag .= '000000';
253  break;
254 
255  default:
256  return false;
257  break;
258  }
259  return chr(bindec($flag));
260  }

◆ getid3_write_id3v2() [1/2]

getid3_write_id3v2::getid3_write_id3v2 ( )

Definition at line 31 of file write.id3v2.php.

31  {
32  return true;
33  }

◆ getid3_write_id3v2() [2/2]

getid3_write_id3v2::getid3_write_id3v2 ( )

Definition at line 33 of file write.id3v2.php.

33  {
34  return true;
35  }

◆ ID3v2FrameFlagsLookupFileAlter() [1/2]

getid3_write_id3v2::ID3v2FrameFlagsLookupFileAlter (   $framename)

Definition at line 1655 of file write.id3v2.php.

Referenced by GenerateID3v2Tag().

1655  {
1656  // unfinished
1657  switch ($framename) {
1658  case 'RGAD':
1659  return false;
1660  break;
1661 
1662  default:
1663  return false;
1664  break;
1665  }
1666  }
+ Here is the caller graph for this function:

◆ ID3v2FrameFlagsLookupFileAlter() [2/2]

getid3_write_id3v2::ID3v2FrameFlagsLookupFileAlter (   $framename)

Definition at line 1669 of file write.id3v2.php.

1669  {
1670  // unfinished
1671  switch ($framename) {
1672  case 'RGAD':
1673  return false;
1674  break;
1675 
1676  default:
1677  return false;
1678  break;
1679  }
1680  }

◆ ID3v2FrameFlagsLookupTagAlter() [1/2]

getid3_write_id3v2::ID3v2FrameFlagsLookupTagAlter (   $framename)

Definition at line 1643 of file write.id3v2.php.

Referenced by GenerateID3v2Tag().

1643  {
1644  // unfinished
1645  switch ($framename) {
1646  case 'RGAD':
1647  $allow = true;
1648  default:
1649  $allow = false;
1650  break;
1651  }
1652  return $allow;
1653  }
+ Here is the caller graph for this function:

◆ ID3v2FrameFlagsLookupTagAlter() [2/2]

getid3_write_id3v2::ID3v2FrameFlagsLookupTagAlter (   $framename)

Definition at line 1657 of file write.id3v2.php.

1657  {
1658  // unfinished
1659  switch ($framename) {
1660  case 'RGAD':
1661  $allow = true;
1662  default:
1663  $allow = false;
1664  break;
1665  }
1666  return $allow;
1667  }

◆ ID3v2FrameIsAllowed() [1/2]

getid3_write_id3v2::ID3v2FrameIsAllowed (   $frame_name,
  $source_data_array 
)

Definition at line 1168 of file write.id3v2.php.

Referenced by GenerateID3v2Tag().

1168  {
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  }
+ Here is the caller graph for this function:

◆ ID3v2FrameIsAllowed() [2/2]

getid3_write_id3v2::ID3v2FrameIsAllowed (   $frame_name,
  $source_data_array 
)

Definition at line 1177 of file write.id3v2.php.

1177  {
1178  static $PreviousFrames = array();
1179 
1180  if ($frame_name === null) {
1181  // if the writing functions are called multiple times, the static array needs to be
1182  // cleared - this can be done by calling $this->ID3v2FrameIsAllowed(null, '')
1183  $PreviousFrames = array();
1184  return true;
1185  }
1186 
1187  if ($this->majorversion == 4) {
1188  switch ($frame_name) {
1189  case 'UFID':
1190  case 'AENC':
1191  case 'ENCR':
1192  case 'GRID':
1193  if (!isset($source_data_array['ownerid'])) {
1194  $this->errors[] = '[ownerid] not specified for '.$frame_name;
1195  } elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) {
1196  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')';
1197  } else {
1198  $PreviousFrames[] = $frame_name.$source_data_array['ownerid'];
1199  }
1200  break;
1201 
1202  case 'TXXX':
1203  case 'WXXX':
1204  case 'RVA2':
1205  case 'EQU2':
1206  case 'APIC':
1207  case 'GEOB':
1208  if (!isset($source_data_array['description'])) {
1209  $this->errors[] = '[description] not specified for '.$frame_name;
1210  } elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) {
1211  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')';
1212  } else {
1213  $PreviousFrames[] = $frame_name.$source_data_array['description'];
1214  }
1215  break;
1216 
1217  case 'USER':
1218  if (!isset($source_data_array['language'])) {
1219  $this->errors[] = '[language] not specified for '.$frame_name;
1220  } elseif (in_array($frame_name.$source_data_array['language'], $PreviousFrames)) {
1221  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language ('.$source_data_array['language'].')';
1222  } else {
1223  $PreviousFrames[] = $frame_name.$source_data_array['language'];
1224  }
1225  break;
1226 
1227  case 'USLT':
1228  case 'SYLT':
1229  case 'COMM':
1230  if (!isset($source_data_array['language'])) {
1231  $this->errors[] = '[language] not specified for '.$frame_name;
1232  } elseif (!isset($source_data_array['description'])) {
1233  $this->errors[] = '[description] not specified for '.$frame_name;
1234  } elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) {
1235  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')';
1236  } else {
1237  $PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description'];
1238  }
1239  break;
1240 
1241  case 'POPM':
1242  if (!isset($source_data_array['email'])) {
1243  $this->errors[] = '[email] not specified for '.$frame_name;
1244  } elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) {
1245  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')';
1246  } else {
1247  $PreviousFrames[] = $frame_name.$source_data_array['email'];
1248  }
1249  break;
1250 
1251  case 'IPLS':
1252  case 'MCDI':
1253  case 'ETCO':
1254  case 'MLLT':
1255  case 'SYTC':
1256  case 'RVRB':
1257  case 'PCNT':
1258  case 'RBUF':
1259  case 'POSS':
1260  case 'OWNE':
1261  case 'SEEK':
1262  case 'ASPI':
1263  case 'RGAD':
1264  if (in_array($frame_name, $PreviousFrames)) {
1265  $this->errors[] = 'Only one '.$frame_name.' tag allowed';
1266  } else {
1267  $PreviousFrames[] = $frame_name;
1268  }
1269  break;
1270 
1271  case 'LINK':
1272  // this isn't implemented quite right (yet) - it should check the target frame data for compliance
1273  // but right now it just allows one linked frame of each type, to be safe.
1274  if (!isset($source_data_array['frameid'])) {
1275  $this->errors[] = '[frameid] not specified for '.$frame_name;
1276  } elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) {
1277  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')';
1278  } elseif (in_array($source_data_array['frameid'], $PreviousFrames)) {
1279  // no links to singleton tags
1280  $this->errors[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')';
1281  } else {
1282  $PreviousFrames[] = $frame_name.$source_data_array['frameid']; // only one linked tag of this type
1283  $PreviousFrames[] = $source_data_array['frameid']; // no non-linked singleton tags of this type
1284  }
1285  break;
1286 
1287  case 'COMR':
1288  // There may be more than one 'commercial frame' in a tag, but no two may be identical
1289  // Checking isn't implemented at all (yet) - just assumes that it's OK.
1290  break;
1291 
1292  case 'PRIV':
1293  case 'SIGN':
1294  if (!isset($source_data_array['ownerid'])) {
1295  $this->errors[] = '[ownerid] not specified for '.$frame_name;
1296  } elseif (!isset($source_data_array['data'])) {
1297  $this->errors[] = '[data] not specified for '.$frame_name;
1298  } elseif (in_array($frame_name.$source_data_array['ownerid'].$source_data_array['data'], $PreviousFrames)) {
1299  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID + Data ('.$source_data_array['ownerid'].' + '.$source_data_array['data'].')';
1300  } else {
1301  $PreviousFrames[] = $frame_name.$source_data_array['ownerid'].$source_data_array['data'];
1302  }
1303  break;
1304 
1305  default:
1306  if (($frame_name{0} != 'T') && ($frame_name{0} != 'W')) {
1307  $this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name;
1308  }
1309  break;
1310  }
1311 
1312  } elseif ($this->majorversion == 3) {
1313 
1314  switch ($frame_name) {
1315  case 'UFID':
1316  case 'AENC':
1317  case 'ENCR':
1318  case 'GRID':
1319  if (!isset($source_data_array['ownerid'])) {
1320  $this->errors[] = '[ownerid] not specified for '.$frame_name;
1321  } elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) {
1322  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')';
1323  } else {
1324  $PreviousFrames[] = $frame_name.$source_data_array['ownerid'];
1325  }
1326  break;
1327 
1328  case 'TXXX':
1329  case 'WXXX':
1330  case 'APIC':
1331  case 'GEOB':
1332  if (!isset($source_data_array['description'])) {
1333  $this->errors[] = '[description] not specified for '.$frame_name;
1334  } elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) {
1335  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')';
1336  } else {
1337  $PreviousFrames[] = $frame_name.$source_data_array['description'];
1338  }
1339  break;
1340 
1341  case 'USER':
1342  if (!isset($source_data_array['language'])) {
1343  $this->errors[] = '[language] not specified for '.$frame_name;
1344  } elseif (in_array($frame_name.$source_data_array['language'], $PreviousFrames)) {
1345  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language ('.$source_data_array['language'].')';
1346  } else {
1347  $PreviousFrames[] = $frame_name.$source_data_array['language'];
1348  }
1349  break;
1350 
1351  case 'USLT':
1352  case 'SYLT':
1353  case 'COMM':
1354  if (!isset($source_data_array['language'])) {
1355  $this->errors[] = '[language] not specified for '.$frame_name;
1356  } elseif (!isset($source_data_array['description'])) {
1357  $this->errors[] = '[description] not specified for '.$frame_name;
1358  } elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) {
1359  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')';
1360  } else {
1361  $PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description'];
1362  }
1363  break;
1364 
1365  case 'POPM':
1366  if (!isset($source_data_array['email'])) {
1367  $this->errors[] = '[email] not specified for '.$frame_name;
1368  } elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) {
1369  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')';
1370  } else {
1371  $PreviousFrames[] = $frame_name.$source_data_array['email'];
1372  }
1373  break;
1374 
1375  case 'IPLS':
1376  case 'MCDI':
1377  case 'ETCO':
1378  case 'MLLT':
1379  case 'SYTC':
1380  case 'RVAD':
1381  case 'EQUA':
1382  case 'RVRB':
1383  case 'PCNT':
1384  case 'RBUF':
1385  case 'POSS':
1386  case 'OWNE':
1387  case 'RGAD':
1388  if (in_array($frame_name, $PreviousFrames)) {
1389  $this->errors[] = 'Only one '.$frame_name.' tag allowed';
1390  } else {
1391  $PreviousFrames[] = $frame_name;
1392  }
1393  break;
1394 
1395  case 'LINK':
1396  // this isn't implemented quite right (yet) - it should check the target frame data for compliance
1397  // but right now it just allows one linked frame of each type, to be safe.
1398  if (!isset($source_data_array['frameid'])) {
1399  $this->errors[] = '[frameid] not specified for '.$frame_name;
1400  } elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) {
1401  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')';
1402  } elseif (in_array($source_data_array['frameid'], $PreviousFrames)) {
1403  // no links to singleton tags
1404  $this->errors[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')';
1405  } else {
1406  $PreviousFrames[] = $frame_name.$source_data_array['frameid']; // only one linked tag of this type
1407  $PreviousFrames[] = $source_data_array['frameid']; // no non-linked singleton tags of this type
1408  }
1409  break;
1410 
1411  case 'COMR':
1412  // There may be more than one 'commercial frame' in a tag, but no two may be identical
1413  // Checking isn't implemented at all (yet) - just assumes that it's OK.
1414  break;
1415 
1416  case 'PRIV':
1417  if (!isset($source_data_array['ownerid'])) {
1418  $this->errors[] = '[ownerid] not specified for '.$frame_name;
1419  } elseif (!isset($source_data_array['data'])) {
1420  $this->errors[] = '[data] not specified for '.$frame_name;
1421  } elseif (in_array($frame_name.$source_data_array['ownerid'].$source_data_array['data'], $PreviousFrames)) {
1422  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID + Data ('.$source_data_array['ownerid'].' + '.$source_data_array['data'].')';
1423  } else {
1424  $PreviousFrames[] = $frame_name.$source_data_array['ownerid'].$source_data_array['data'];
1425  }
1426  break;
1427 
1428  default:
1429  if (($frame_name{0} != 'T') && ($frame_name{0} != 'W')) {
1430  $this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name;
1431  }
1432  break;
1433  }
1434 
1435  } elseif ($this->majorversion == 2) {
1436 
1437  switch ($frame_name) {
1438  case 'UFI':
1439  case 'CRM':
1440  case 'CRA':
1441  if (!isset($source_data_array['ownerid'])) {
1442  $this->errors[] = '[ownerid] not specified for '.$frame_name;
1443  } elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) {
1444  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')';
1445  } else {
1446  $PreviousFrames[] = $frame_name.$source_data_array['ownerid'];
1447  }
1448  break;
1449 
1450  case 'TXX':
1451  case 'WXX':
1452  case 'PIC':
1453  case 'GEO':
1454  if (!isset($source_data_array['description'])) {
1455  $this->errors[] = '[description] not specified for '.$frame_name;
1456  } elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) {
1457  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')';
1458  } else {
1459  $PreviousFrames[] = $frame_name.$source_data_array['description'];
1460  }
1461  break;
1462 
1463  case 'ULT':
1464  case 'SLT':
1465  case 'COM':
1466  if (!isset($source_data_array['language'])) {
1467  $this->errors[] = '[language] not specified for '.$frame_name;
1468  } elseif (!isset($source_data_array['description'])) {
1469  $this->errors[] = '[description] not specified for '.$frame_name;
1470  } elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) {
1471  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')';
1472  } else {
1473  $PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description'];
1474  }
1475  break;
1476 
1477  case 'POP':
1478  if (!isset($source_data_array['email'])) {
1479  $this->errors[] = '[email] not specified for '.$frame_name;
1480  } elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) {
1481  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')';
1482  } else {
1483  $PreviousFrames[] = $frame_name.$source_data_array['email'];
1484  }
1485  break;
1486 
1487  case 'IPL':
1488  case 'MCI':
1489  case 'ETC':
1490  case 'MLL':
1491  case 'STC':
1492  case 'RVA':
1493  case 'EQU':
1494  case 'REV':
1495  case 'CNT':
1496  case 'BUF':
1497  if (in_array($frame_name, $PreviousFrames)) {
1498  $this->errors[] = 'Only one '.$frame_name.' tag allowed';
1499  } else {
1500  $PreviousFrames[] = $frame_name;
1501  }
1502  break;
1503 
1504  case 'LNK':
1505  // this isn't implemented quite right (yet) - it should check the target frame data for compliance
1506  // but right now it just allows one linked frame of each type, to be safe.
1507  if (!isset($source_data_array['frameid'])) {
1508  $this->errors[] = '[frameid] not specified for '.$frame_name;
1509  } elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) {
1510  $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')';
1511  } elseif (in_array($source_data_array['frameid'], $PreviousFrames)) {
1512  // no links to singleton tags
1513  $this->errors[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')';
1514  } else {
1515  $PreviousFrames[] = $frame_name.$source_data_array['frameid']; // only one linked tag of this type
1516  $PreviousFrames[] = $source_data_array['frameid']; // no non-linked singleton tags of this type
1517  }
1518  break;
1519 
1520  default:
1521  if (($frame_name{0} != 'T') && ($frame_name{0} != 'W')) {
1522  $this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name;
1523  }
1524  break;
1525  }
1526  }
1527 
1528  if (!empty($this->errors)) {
1529  return false;
1530  }
1531  return true;
1532  }

◆ ID3v2IsValidAPICimageformat() [1/2]

getid3_write_id3v2::ID3v2IsValidAPICimageformat (   $imageformat)

Definition at line 1711 of file write.id3v2.php.

References IsValidMIMEstring().

Referenced by GenerateID3v2FrameData().

1711  {
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  }
IsValidMIMEstring($mimestring)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ID3v2IsValidAPICimageformat() [2/2]

getid3_write_id3v2::ID3v2IsValidAPICimageformat (   $imageformat)

Definition at line 1725 of file write.id3v2.php.

References IsValidMIMEstring().

1725  {
1726  if ($imageformat == '-->') {
1727  return true;
1728  } elseif ($this->majorversion == 2) {
1729  if ((strlen($imageformat) == 3) && ($imageformat == strtoupper($imageformat))) {
1730  return true;
1731  }
1732  } elseif (($this->majorversion == 3) || ($this->majorversion == 4)) {
1733  if ($this->IsValidMIMEstring($imageformat)) {
1734  return true;
1735  }
1736  }
1737  return false;
1738  }
IsValidMIMEstring($mimestring)
+ Here is the call graph for this function:

◆ ID3v2IsValidAPICpicturetype() [1/2]

getid3_write_id3v2::ID3v2IsValidAPICpicturetype (   $picturetype)

Definition at line 1704 of file write.id3v2.php.

Referenced by GenerateID3v2FrameData().

1704  {
1705  if (($picturetype >= 0) && ($picturetype <= 0x14) && ($this->majorversion >= 2) && ($this->majorversion <= 4)) {
1706  return true;
1707  }
1708  return false;
1709  }
+ Here is the caller graph for this function:

◆ ID3v2IsValidAPICpicturetype() [2/2]

getid3_write_id3v2::ID3v2IsValidAPICpicturetype (   $picturetype)

Definition at line 1718 of file write.id3v2.php.

1718  {
1719  if (($picturetype >= 0) && ($picturetype <= 0x14) && ($this->majorversion >= 2) && ($this->majorversion <= 4)) {
1720  return true;
1721  }
1722  return false;
1723  }

◆ ID3v2IsValidCOMRreceivedAs() [1/2]

getid3_write_id3v2::ID3v2IsValidCOMRreceivedAs (   $receivedas)

Definition at line 1726 of file write.id3v2.php.

Referenced by GenerateID3v2FrameData().

1726  {
1727  if (($this->majorversion >= 3) && ($receivedas >= 0) && ($receivedas <= 8)) {
1728  return true;
1729  }
1730  return false;
1731  }
+ Here is the caller graph for this function:

◆ ID3v2IsValidCOMRreceivedAs() [2/2]

getid3_write_id3v2::ID3v2IsValidCOMRreceivedAs (   $receivedas)

Definition at line 1740 of file write.id3v2.php.

1740  {
1741  if (($this->majorversion >= 3) && ($receivedas >= 0) && ($receivedas <= 8)) {
1742  return true;
1743  }
1744  return false;
1745  }

◆ ID3v2IsValidETCOevent() [1/2]

getid3_write_id3v2::ID3v2IsValidETCOevent (   $eventid)

Definition at line 1668 of file write.id3v2.php.

Referenced by GenerateID3v2FrameData().

1668  {
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  }
+ Here is the caller graph for this function:

◆ ID3v2IsValidETCOevent() [2/2]

getid3_write_id3v2::ID3v2IsValidETCOevent (   $eventid)

Definition at line 1682 of file write.id3v2.php.

1682  {
1683  if (($eventid < 0) || ($eventid > 0xFF)) {
1684  // outside range of 1 byte
1685  return false;
1686  } elseif (($eventid >= 0xF0) && ($eventid <= 0xFC)) {
1687  // reserved for future use
1688  return false;
1689  } elseif (($eventid >= 0x17) && ($eventid <= 0xDF)) {
1690  // reserved for future use
1691  return false;
1692  } elseif (($eventid >= 0x0E) && ($eventid <= 0x16) && ($this->majorversion == 2)) {
1693  // not defined in ID3v2.2
1694  return false;
1695  } elseif (($eventid >= 0x15) && ($eventid <= 0x16) && ($this->majorversion == 3)) {
1696  // not defined in ID3v2.3
1697  return false;
1698  }
1699  return true;
1700  }

◆ ID3v2IsValidPriceString() [1/2]

getid3_write_id3v2::ID3v2IsValidPriceString (   $pricestring)

Definition at line 1634 of file write.id3v2.php.

References getid3_id3v2\LanguageLookup().

Referenced by GenerateID3v2FrameData().

1634  {
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  }
LanguageLookup($languagecode, $casesensitive=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ID3v2IsValidPriceString() [2/2]

getid3_write_id3v2::ID3v2IsValidPriceString (   $pricestring)

Definition at line 1648 of file write.id3v2.php.

References getid3_id3v2\LanguageLookup().

1648  {
1649  if (getid3_id3v2::LanguageLookup(substr($pricestring, 0, 3), true) == '') {
1650  return false;
1651  } elseif (!$this->IsANumber(substr($pricestring, 3), true)) {
1652  return false;
1653  }
1654  return true;
1655  }
LanguageLookup($languagecode, $casesensitive=false)
+ Here is the call graph for this function:

◆ ID3v2IsValidRGADname() [1/2]

getid3_write_id3v2::ID3v2IsValidRGADname (   $RGADname)

Definition at line 1733 of file write.id3v2.php.

Referenced by GenerateID3v2FrameData().

1733  {
1734  if (($RGADname >= 0) && ($RGADname <= 2)) {
1735  return true;
1736  }
1737  return false;
1738  }
+ Here is the caller graph for this function:

◆ ID3v2IsValidRGADname() [2/2]

getid3_write_id3v2::ID3v2IsValidRGADname (   $RGADname)

Definition at line 1747 of file write.id3v2.php.

1747  {
1748  if (($RGADname >= 0) && ($RGADname <= 2)) {
1749  return true;
1750  }
1751  return false;
1752  }

◆ ID3v2IsValidRGADoriginator() [1/2]

getid3_write_id3v2::ID3v2IsValidRGADoriginator (   $RGADoriginator)

Definition at line 1740 of file write.id3v2.php.

Referenced by GenerateID3v2FrameData().

1740  {
1741  if (($RGADoriginator >= 0) && ($RGADoriginator <= 3)) {
1742  return true;
1743  }
1744  return false;
1745  }
+ Here is the caller graph for this function:

◆ ID3v2IsValidRGADoriginator() [2/2]

getid3_write_id3v2::ID3v2IsValidRGADoriginator (   $RGADoriginator)

Definition at line 1754 of file write.id3v2.php.

1754  {
1755  if (($RGADoriginator >= 0) && ($RGADoriginator <= 3)) {
1756  return true;
1757  }
1758  return false;
1759  }

◆ ID3v2IsValidRVA2channeltype() [1/2]

getid3_write_id3v2::ID3v2IsValidRVA2channeltype (   $channeltype)

Definition at line 1697 of file write.id3v2.php.

1697  {
1698  if (($channeltype >= 0) && ($channeltype <= 8) && ($this->majorversion == 4)) {
1699  return true;
1700  }
1701  return false;
1702  }

◆ ID3v2IsValidRVA2channeltype() [2/2]

getid3_write_id3v2::ID3v2IsValidRVA2channeltype (   $channeltype)

Definition at line 1711 of file write.id3v2.php.

1711  {
1712  if (($channeltype >= 0) && ($channeltype <= 8) && ($this->majorversion == 4)) {
1713  return true;
1714  }
1715  return false;
1716  }

◆ ID3v2IsValidSYLTtype() [1/2]

getid3_write_id3v2::ID3v2IsValidSYLTtype (   $contenttype)

Definition at line 1688 of file write.id3v2.php.

Referenced by GenerateID3v2FrameData().

1688  {
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  }
+ Here is the caller graph for this function:

◆ ID3v2IsValidSYLTtype() [2/2]

getid3_write_id3v2::ID3v2IsValidSYLTtype (   $contenttype)

Definition at line 1702 of file write.id3v2.php.

1702  {
1703  if (($contenttype >= 0) && ($contenttype <= 8) && ($this->majorversion == 4)) {
1704  return true;
1705  } elseif (($contenttype >= 0) && ($contenttype <= 6) && ($this->majorversion == 3)) {
1706  return true;
1707  }
1708  return false;
1709  }

◆ ID3v2IsValidTextEncoding() [1/2]

getid3_write_id3v2::ID3v2IsValidTextEncoding (   $textencodingbyte)

Definition at line 1747 of file write.id3v2.php.

Referenced by GenerateID3v2FrameData().

1747  {
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  }
+ Here is the caller graph for this function:

◆ ID3v2IsValidTextEncoding() [2/2]

getid3_write_id3v2::ID3v2IsValidTextEncoding (   $textencodingbyte)

Definition at line 1761 of file write.id3v2.php.

1761  {
1762  static $ID3v2IsValidTextEncoding_cache = array(
1763  2 => array(true, true),
1764  3 => array(true, true),
1765  4 => array(true, true, true, true));
1766  return isset($ID3v2IsValidTextEncoding_cache[$this->majorversion][$textencodingbyte]);
1767  }

◆ ID3v2ShortFrameNameLookup() [1/2]

getid3_write_id3v2::ID3v2ShortFrameNameLookup (   $majorversion,
  $long_description 
)

Definition at line 1886 of file write.id3v2.php.

References $majorversion.

Referenced by getid3_writetags\FormatDataForID3v2().

1886  {
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  }
+ Here is the caller graph for this function:

◆ ID3v2ShortFrameNameLookup() [2/2]

static getid3_write_id3v2::ID3v2ShortFrameNameLookup (   $majorversion,
  $long_description 
)
static

Definition at line 1900 of file write.id3v2.php.

References $majorversion.

1900  {
1901  $long_description = str_replace(' ', '_', strtolower(trim($long_description)));
1902  static $ID3v2ShortFrameNameLookup = array();
1903  if (empty($ID3v2ShortFrameNameLookup)) {
1904 
1905  // The following are unique to ID3v2.2
1906  $ID3v2ShortFrameNameLookup[2]['comment'] = 'COM';
1907  $ID3v2ShortFrameNameLookup[2]['album'] = 'TAL';
1908  $ID3v2ShortFrameNameLookup[2]['beats_per_minute'] = 'TBP';
1909  $ID3v2ShortFrameNameLookup[2]['composer'] = 'TCM';
1910  $ID3v2ShortFrameNameLookup[2]['genre'] = 'TCO';
1911  $ID3v2ShortFrameNameLookup[2]['itunescompilation'] = 'TCP';
1912  $ID3v2ShortFrameNameLookup[2]['copyright'] = 'TCR';
1913  $ID3v2ShortFrameNameLookup[2]['encoded_by'] = 'TEN';
1914  $ID3v2ShortFrameNameLookup[2]['language'] = 'TLA';
1915  $ID3v2ShortFrameNameLookup[2]['length'] = 'TLE';
1916  $ID3v2ShortFrameNameLookup[2]['original_artist'] = 'TOA';
1917  $ID3v2ShortFrameNameLookup[2]['original_filename'] = 'TOF';
1918  $ID3v2ShortFrameNameLookup[2]['original_lyricist'] = 'TOL';
1919  $ID3v2ShortFrameNameLookup[2]['original_album_title'] = 'TOT';
1920  $ID3v2ShortFrameNameLookup[2]['artist'] = 'TP1';
1921  $ID3v2ShortFrameNameLookup[2]['band'] = 'TP2';
1922  $ID3v2ShortFrameNameLookup[2]['conductor'] = 'TP3';
1923  $ID3v2ShortFrameNameLookup[2]['remixer'] = 'TP4';
1924  $ID3v2ShortFrameNameLookup[2]['publisher'] = 'TPB';
1925  $ID3v2ShortFrameNameLookup[2]['isrc'] = 'TRC';
1926  $ID3v2ShortFrameNameLookup[2]['tracknumber'] = 'TRK';
1927  $ID3v2ShortFrameNameLookup[2]['track_number'] = 'TRK';
1928  $ID3v2ShortFrameNameLookup[2]['size'] = 'TSI';
1929  $ID3v2ShortFrameNameLookup[2]['encoder_settings'] = 'TSS';
1930  $ID3v2ShortFrameNameLookup[2]['description'] = 'TT1';
1931  $ID3v2ShortFrameNameLookup[2]['title'] = 'TT2';
1932  $ID3v2ShortFrameNameLookup[2]['subtitle'] = 'TT3';
1933  $ID3v2ShortFrameNameLookup[2]['lyricist'] = 'TXT';
1934  $ID3v2ShortFrameNameLookup[2]['user_text'] = 'TXX';
1935  $ID3v2ShortFrameNameLookup[2]['year'] = 'TYE';
1936  $ID3v2ShortFrameNameLookup[2]['unique_file_identifier'] = 'UFI';
1937  $ID3v2ShortFrameNameLookup[2]['unsynchronised_lyrics'] = 'ULT';
1938  $ID3v2ShortFrameNameLookup[2]['url_file'] = 'WAF';
1939  $ID3v2ShortFrameNameLookup[2]['url_artist'] = 'WAR';
1940  $ID3v2ShortFrameNameLookup[2]['url_source'] = 'WAS';
1941  $ID3v2ShortFrameNameLookup[2]['copyright_information'] = 'WCP';
1942  $ID3v2ShortFrameNameLookup[2]['url_publisher'] = 'WPB';
1943  $ID3v2ShortFrameNameLookup[2]['url_user'] = 'WXX';
1944 
1945  // The following are common to ID3v2.3 and ID3v2.4
1946  $ID3v2ShortFrameNameLookup[3]['audio_encryption'] = 'AENC';
1947  $ID3v2ShortFrameNameLookup[3]['attached_picture'] = 'APIC';
1948  $ID3v2ShortFrameNameLookup[3]['picture'] = 'APIC';
1949  $ID3v2ShortFrameNameLookup[3]['comment'] = 'COMM';
1950  $ID3v2ShortFrameNameLookup[3]['commercial'] = 'COMR';
1951  $ID3v2ShortFrameNameLookup[3]['encryption_method_registration'] = 'ENCR';
1952  $ID3v2ShortFrameNameLookup[3]['event_timing_codes'] = 'ETCO';
1953  $ID3v2ShortFrameNameLookup[3]['general_encapsulated_object'] = 'GEOB';
1954  $ID3v2ShortFrameNameLookup[3]['group_identification_registration'] = 'GRID';
1955  $ID3v2ShortFrameNameLookup[3]['linked_information'] = 'LINK';
1956  $ID3v2ShortFrameNameLookup[3]['music_cd_identifier'] = 'MCDI';
1957  $ID3v2ShortFrameNameLookup[3]['mpeg_location_lookup_table'] = 'MLLT';
1958  $ID3v2ShortFrameNameLookup[3]['ownership'] = 'OWNE';
1959  $ID3v2ShortFrameNameLookup[3]['play_counter'] = 'PCNT';
1960  $ID3v2ShortFrameNameLookup[3]['popularimeter'] = 'POPM';
1961  $ID3v2ShortFrameNameLookup[3]['position_synchronisation'] = 'POSS';
1962  $ID3v2ShortFrameNameLookup[3]['private'] = 'PRIV';
1963  $ID3v2ShortFrameNameLookup[3]['recommended_buffer_size'] = 'RBUF';
1964  $ID3v2ShortFrameNameLookup[3]['reverb'] = 'RVRB';
1965  $ID3v2ShortFrameNameLookup[3]['synchronised_lyrics'] = 'SYLT';
1966  $ID3v2ShortFrameNameLookup[3]['synchronised_tempo_codes'] = 'SYTC';
1967  $ID3v2ShortFrameNameLookup[3]['album'] = 'TALB';
1968  $ID3v2ShortFrameNameLookup[3]['beats_per_minute'] = 'TBPM';
1969  $ID3v2ShortFrameNameLookup[3]['itunescompilation'] = 'TCMP';
1970  $ID3v2ShortFrameNameLookup[3]['composer'] = 'TCOM';
1971  $ID3v2ShortFrameNameLookup[3]['genre'] = 'TCON';
1972  $ID3v2ShortFrameNameLookup[3]['copyright'] = 'TCOP';
1973  $ID3v2ShortFrameNameLookup[3]['playlist_delay'] = 'TDLY';
1974  $ID3v2ShortFrameNameLookup[3]['encoded_by'] = 'TENC';
1975  $ID3v2ShortFrameNameLookup[3]['lyricist'] = 'TEXT';
1976  $ID3v2ShortFrameNameLookup[3]['file_type'] = 'TFLT';
1977  $ID3v2ShortFrameNameLookup[3]['content_group_description'] = 'TIT1';
1978  $ID3v2ShortFrameNameLookup[3]['title'] = 'TIT2';
1979  $ID3v2ShortFrameNameLookup[3]['subtitle'] = 'TIT3';
1980  $ID3v2ShortFrameNameLookup[3]['initial_key'] = 'TKEY';
1981  $ID3v2ShortFrameNameLookup[3]['language'] = 'TLAN';
1982  $ID3v2ShortFrameNameLookup[3]['length'] = 'TLEN';
1983  $ID3v2ShortFrameNameLookup[3]['media_type'] = 'TMED';
1984  $ID3v2ShortFrameNameLookup[3]['original_album_title'] = 'TOAL';
1985  $ID3v2ShortFrameNameLookup[3]['original_filename'] = 'TOFN';
1986  $ID3v2ShortFrameNameLookup[3]['original_lyricist'] = 'TOLY';
1987  $ID3v2ShortFrameNameLookup[3]['original_artist'] = 'TOPE';
1988  $ID3v2ShortFrameNameLookup[3]['file_owner'] = 'TOWN';
1989  $ID3v2ShortFrameNameLookup[3]['artist'] = 'TPE1';
1990  $ID3v2ShortFrameNameLookup[3]['band'] = 'TPE2';
1991  $ID3v2ShortFrameNameLookup[3]['conductor'] = 'TPE3';
1992  $ID3v2ShortFrameNameLookup[3]['remixer'] = 'TPE4';
1993  $ID3v2ShortFrameNameLookup[3]['part_of_a_set'] = 'TPOS';
1994  $ID3v2ShortFrameNameLookup[3]['publisher'] = 'TPUB';
1995  $ID3v2ShortFrameNameLookup[3]['tracknumber'] = 'TRCK';
1996  $ID3v2ShortFrameNameLookup[3]['track_number'] = 'TRCK';
1997  $ID3v2ShortFrameNameLookup[3]['internet_radio_station_name'] = 'TRSN';
1998  $ID3v2ShortFrameNameLookup[3]['internet_radio_station_owner'] = 'TRSO';
1999  $ID3v2ShortFrameNameLookup[3]['isrc'] = 'TSRC';
2000  $ID3v2ShortFrameNameLookup[3]['encoder_settings'] = 'TSSE';
2001  $ID3v2ShortFrameNameLookup[3]['user_text'] = 'TXXX';
2002  $ID3v2ShortFrameNameLookup[3]['unique_file_identifier'] = 'UFID';
2003  $ID3v2ShortFrameNameLookup[3]['terms_of_use'] = 'USER';
2004  $ID3v2ShortFrameNameLookup[3]['unsynchronised_lyrics'] = 'USLT';
2005  $ID3v2ShortFrameNameLookup[3]['commercial'] = 'WCOM';
2006  $ID3v2ShortFrameNameLookup[3]['copyright_information'] = 'WCOP';
2007  $ID3v2ShortFrameNameLookup[3]['url_file'] = 'WOAF';
2008  $ID3v2ShortFrameNameLookup[3]['url_artist'] = 'WOAR';
2009  $ID3v2ShortFrameNameLookup[3]['url_source'] = 'WOAS';
2010  $ID3v2ShortFrameNameLookup[3]['url_station'] = 'WORS';
2011  $ID3v2ShortFrameNameLookup[3]['payment'] = 'WPAY';
2012  $ID3v2ShortFrameNameLookup[3]['url_publisher'] = 'WPUB';
2013  $ID3v2ShortFrameNameLookup[3]['url_user'] = 'WXXX';
2014 
2015  // The above are common to ID3v2.3 and ID3v2.4
2016  // so copy them to ID3v2.4 before adding specifics for 2.3 and 2.4
2017  $ID3v2ShortFrameNameLookup[4] = $ID3v2ShortFrameNameLookup[3];
2018 
2019  // The following are unique to ID3v2.3
2020  $ID3v2ShortFrameNameLookup[3]['equalisation'] = 'EQUA';
2021  $ID3v2ShortFrameNameLookup[3]['involved_people_list'] = 'IPLS';
2022  $ID3v2ShortFrameNameLookup[3]['relative_volume_adjustment'] = 'RVAD';
2023  $ID3v2ShortFrameNameLookup[3]['date'] = 'TDAT';
2024  $ID3v2ShortFrameNameLookup[3]['time'] = 'TIME';
2025  $ID3v2ShortFrameNameLookup[3]['original_release_year'] = 'TORY';
2026  $ID3v2ShortFrameNameLookup[3]['recording_dates'] = 'TRDA';
2027  $ID3v2ShortFrameNameLookup[3]['size'] = 'TSIZ';
2028  $ID3v2ShortFrameNameLookup[3]['year'] = 'TYER';
2029 
2030 
2031  // The following are unique to ID3v2.4
2032  $ID3v2ShortFrameNameLookup[4]['audio_seek_point_index'] = 'ASPI';
2033  $ID3v2ShortFrameNameLookup[4]['equalisation'] = 'EQU2';
2034  $ID3v2ShortFrameNameLookup[4]['relative_volume_adjustment'] = 'RVA2';
2035  $ID3v2ShortFrameNameLookup[4]['seek'] = 'SEEK';
2036  $ID3v2ShortFrameNameLookup[4]['signature'] = 'SIGN';
2037  $ID3v2ShortFrameNameLookup[4]['encoding_time'] = 'TDEN';
2038  $ID3v2ShortFrameNameLookup[4]['original_release_time'] = 'TDOR';
2039  $ID3v2ShortFrameNameLookup[4]['recording_time'] = 'TDRC';
2040  $ID3v2ShortFrameNameLookup[4]['release_time'] = 'TDRL';
2041  $ID3v2ShortFrameNameLookup[4]['tagging_time'] = 'TDTG';
2042  $ID3v2ShortFrameNameLookup[4]['involved_people_list'] = 'TIPL';
2043  $ID3v2ShortFrameNameLookup[4]['musician_credits_list'] = 'TMCL';
2044  $ID3v2ShortFrameNameLookup[4]['mood'] = 'TMOO';
2045  $ID3v2ShortFrameNameLookup[4]['produced_notice'] = 'TPRO';
2046  $ID3v2ShortFrameNameLookup[4]['album_sort_order'] = 'TSOA';
2047  $ID3v2ShortFrameNameLookup[4]['performer_sort_order'] = 'TSOP';
2048  $ID3v2ShortFrameNameLookup[4]['title_sort_order'] = 'TSOT';
2049  $ID3v2ShortFrameNameLookup[4]['set_subtitle'] = 'TSST';
2050  }
2051  return (isset($ID3v2ShortFrameNameLookup[$majorversion][strtolower($long_description)]) ? $ID3v2ShortFrameNameLookup[$majorversion][strtolower($long_description)] : '');
2052 
2053  }

◆ is_hash() [1/2]

getid3_write_id3v2::is_hash (   $var)

Definition at line 1785 of file write.id3v2.php.

Referenced by array_join_merge().

1785  {
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  }
+ Here is the caller graph for this function:

◆ is_hash() [2/2]

getid3_write_id3v2::is_hash (   $var)

Definition at line 1799 of file write.id3v2.php.

1799  {
1800  // written by dev-nullØchristophe*vg
1801  // taken from http://www.php.net/manual/en/function.array-merge-recursive.php
1802  if (is_array($var)) {
1803  $keys = array_keys($var);
1804  $all_num = true;
1805  for ($i = 0; $i < count($keys); $i++) {
1806  if (is_string($keys[$i])) {
1807  return true;
1808  }
1809  }
1810  }
1811  return false;
1812  }

◆ IsValidMIMEstring() [1/2]

getid3_write_id3v2::IsValidMIMEstring (   $mimestring)

Definition at line 1824 of file write.id3v2.php.

Referenced by GenerateID3v2FrameData(), and ID3v2IsValidAPICimageformat().

1824  {
1825  if ((strlen($mimestring) >= 3) && (strpos($mimestring, '/') > 0) && (strpos($mimestring, '/') < (strlen($mimestring) - 1))) {
1826  return true;
1827  }
1828  return false;
1829  }
+ Here is the caller graph for this function:

◆ IsValidMIMEstring() [2/2]

getid3_write_id3v2::IsValidMIMEstring (   $mimestring)

Definition at line 1838 of file write.id3v2.php.

1838  {
1839  if ((strlen($mimestring) >= 3) && (strpos($mimestring, '/') > 0) && (strpos($mimestring, '/') < (strlen($mimestring) - 1))) {
1840  return true;
1841  }
1842  return false;
1843  }

◆ IsValidURL() [1/2]

getid3_write_id3v2::IsValidURL (   $url,
  $allowUserPass = false 
)

Definition at line 1855 of file write.id3v2.php.

References $url, and safe_parse_url().

Referenced by GenerateID3v2FrameData().

1855  {
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  }
$url
Definition: shib_logout.php:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsValidURL() [2/2]

getid3_write_id3v2::IsValidURL (   $url,
  $allowUserPass = false 
)

Definition at line 1869 of file write.id3v2.php.

References $url, and safe_parse_url().

1869  {
1870  if ($url == '') {
1871  return false;
1872  }
1873  if ($allowUserPass !== true) {
1874  if (strstr($url, '@')) {
1875  // in the format http://user:pass@example.com or http://user@example.com
1876  // but could easily be somebody incorrectly entering an email address in place of a URL
1877  return false;
1878  }
1879  }
1880  if ($parts = $this->safe_parse_url($url)) {
1881  if (($parts['scheme'] != 'http') && ($parts['scheme'] != 'https') && ($parts['scheme'] != 'ftp') && ($parts['scheme'] != 'gopher')) {
1882  return false;
1883  } elseif (!preg_match('#^[[:alnum:]]([-.]?[0-9a-z])*\\.[a-z]{2,3}$#i', $parts['host'], $regs) && !preg_match('#^[0-9]{1,3}(\\.[0-9]{1,3}){3}$#', $parts['host'])) {
1884  return false;
1885  } elseif (!preg_match('#^([[:alnum:]-]|[\\_])*$#i', $parts['user'], $regs)) {
1886  return false;
1887  } elseif (!preg_match('#^([[:alnum:]-]|[\\_])*$#i', $parts['pass'], $regs)) {
1888  return false;
1889  } elseif (!preg_match('#^[[:alnum:]/_\\.@~-]*$#i', $parts['path'], $regs)) {
1890  return false;
1891  } elseif (!empty($parts['query']) && !preg_match('#^[[:alnum:]?&=+:;_()%\\#/,\\.-]*$#i', $parts['query'], $regs)) {
1892  return false;
1893  } else {
1894  return true;
1895  }
1896  }
1897  return false;
1898  }
$url
Definition: shib_logout.php:72
+ Here is the call graph for this function:

◆ IsWithinBitRange() [1/2]

getid3_write_id3v2::IsWithinBitRange (   $number,
  $maxbits,
  $signed = false 
)

Definition at line 1831 of file write.id3v2.php.

Referenced by GenerateID3v2FrameData().

1831  {
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  }
+ Here is the caller graph for this function:

◆ IsWithinBitRange() [2/2]

getid3_write_id3v2::IsWithinBitRange (   $number,
  $maxbits,
  $signed = false 
)

Definition at line 1845 of file write.id3v2.php.

1845  {
1846  if ($signed) {
1847  if (($number > (0 - pow(2, $maxbits - 1))) && ($number <= pow(2, $maxbits - 1))) {
1848  return true;
1849  }
1850  } else {
1851  if (($number >= 0) && ($number <= pow(2, $maxbits))) {
1852  return true;
1853  }
1854  }
1855  return false;
1856  }

◆ RemoveID3v2() [1/2]

getid3_write_id3v2::RemoveID3v2 ( )

Definition at line 137 of file write.id3v2.php.

References getID3\analyze(), and getid3_lib\intValueSupported().

137  {
138  // File MUST be writeable - CHMOD(646) at least. It's best if the
139  // directory is also writeable, because that method is both faster and less susceptible to errors.
140  if (is_writeable(dirname($this->filename))) {
141 
142  // preferred method - only one copying operation, minimal chance of corrupting
143  // original file if script is interrupted, but required directory to be writeable
144  if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) {
145 
146  // Initialize getID3 engine
147  $getID3 = new getID3;
148  $OldThisFileInfo = $getID3->analyze($this->filename);
149  if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) {
150  $this->errors[] = 'Unable to remove ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
151  fclose($fp_source);
152  return false;
153  }
154  rewind($fp_source);
155  if ($OldThisFileInfo['avdataoffset'] !== false) {
156  fseek($fp_source, $OldThisFileInfo['avdataoffset']);
157  }
158  if (is_writable($this->filename) && is_file($this->filename) && ($fp_temp = fopen($this->filename.'getid3tmp', 'w+b'))) {
159  while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
160  fwrite($fp_temp, $buffer, strlen($buffer));
161  }
162  fclose($fp_temp);
163  } else {
164  $this->errors[] = 'Could not fopen("'.$this->filename.'getid3tmp", "w+b")';
165  }
166  fclose($fp_source);
167  } else {
168  $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")';
169  }
170  if (file_exists($this->filename)) {
171  unlink($this->filename);
172  }
173  rename($this->filename.'getid3tmp', $this->filename);
174 
175  } elseif (is_writable($this->filename)) {
176 
177  // less desirable alternate method - double-copies the file, overwrites original file
178  // and could corrupt source file if the script is interrupted or an error occurs.
179  if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) {
180 
181  // Initialize getID3 engine
182  $getID3 = new getID3;
183  $OldThisFileInfo = $getID3->analyze($this->filename);
184  if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) {
185  $this->errors[] = 'Unable to remove ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
186  fclose($fp_source);
187  return false;
188  }
189  rewind($fp_source);
190  if ($OldThisFileInfo['avdataoffset'] !== false) {
191  fseek($fp_source, $OldThisFileInfo['avdataoffset']);
192  }
193  if ($fp_temp = tmpfile()) {
194  while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
195  fwrite($fp_temp, $buffer, strlen($buffer));
196  }
197  fclose($fp_source);
198  if (is_writable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'wb'))) {
199  rewind($fp_temp);
200  while ($buffer = fread($fp_temp, $this->fread_buffer_size)) {
201  fwrite($fp_source, $buffer, strlen($buffer));
202  }
203  fseek($fp_temp, -128, SEEK_END);
204  fclose($fp_source);
205  } else {
206  $this->errors[] = 'Could not fopen("'.$this->filename.'", "wb")';
207  }
208  fclose($fp_temp);
209  } else {
210  $this->errors[] = 'Could not create tmpfile()';
211  }
212  } else {
213  $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")';
214  }
215 
216  } else {
217 
218  $this->errors[] = 'Directory and file both not writeable';
219 
220  }
221 
222  if (!empty($this->errors)) {
223  return false;
224  }
225  return true;
226  }
static intValueSupported($num)
Definition: getid3.lib.php:80
analyze($filename)
Definition: getid3.php:168
+ Here is the call graph for this function:

◆ RemoveID3v2() [2/2]

getid3_write_id3v2::RemoveID3v2 ( )

Definition at line 141 of file write.id3v2.php.

References getID3\analyze(), and GETID3_FREAD_BUFFER_SIZE.

141  {
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  }
const GETID3_FREAD_BUFFER_SIZE
Definition: getid3.php:14
analyze($filename)
Definition: getid3.php:168
+ Here is the call graph for this function:

◆ safe_parse_url() [1/2]

getid3_write_id3v2::safe_parse_url (   $url)

Definition at line 1844 of file write.id3v2.php.

References $url.

Referenced by IsValidURL().

1844  {
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  }
$url
Definition: shib_logout.php:72
+ Here is the caller graph for this function:

◆ safe_parse_url() [2/2]

getid3_write_id3v2::safe_parse_url (   $url)

Definition at line 1858 of file write.id3v2.php.

References $url.

1858  {
1859  $parts = @parse_url($url);
1860  $parts['scheme'] = (isset($parts['scheme']) ? $parts['scheme'] : '');
1861  $parts['host'] = (isset($parts['host']) ? $parts['host'] : '');
1862  $parts['user'] = (isset($parts['user']) ? $parts['user'] : '');
1863  $parts['pass'] = (isset($parts['pass']) ? $parts['pass'] : '');
1864  $parts['path'] = (isset($parts['path']) ? $parts['path'] : '');
1865  $parts['query'] = (isset($parts['query']) ? $parts['query'] : '');
1866  return $parts;
1867  }
$url
Definition: shib_logout.php:72

◆ Unsynchronise() [1/2]

getid3_write_id3v2::Unsynchronise (   $data)

Definition at line 1755 of file write.id3v2.php.

References $data.

Referenced by GenerateID3v2Tag().

1755  {
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  }
$data
+ Here is the caller graph for this function:

◆ Unsynchronise() [2/2]

getid3_write_id3v2::Unsynchronise (   $data)

Definition at line 1769 of file write.id3v2.php.

References $data.

1769  {
1770  // Whenever a false synchronisation is found within the tag, one zeroed
1771  // byte is inserted after the first false synchronisation byte. The
1772  // format of a correct sync that should be altered by ID3 encoders is as
1773  // follows:
1774  // %11111111 111xxxxx
1775  // And should be replaced with:
1776  // %11111111 00000000 111xxxxx
1777  // This has the side effect that all $FF 00 combinations have to be
1778  // altered, so they won't be affected by the decoding process. Therefore
1779  // all the $FF 00 combinations have to be replaced with the $FF 00 00
1780  // combination during the unsynchronisation.
1781 
1782  $data = str_replace("\xFF\x00", "\xFF\x00\x00", $data);
1783  $unsyncheddata = '';
1784  $datalength = strlen($data);
1785  for ($i = 0; $i < $datalength; $i++) {
1786  $thischar = $data{$i};
1787  $unsyncheddata .= $thischar;
1788  if ($thischar == "\xFF") {
1789  $nextchar = ord($data{$i + 1});
1790  if (($nextchar & 0xE0) == 0xE0) {
1791  // previous byte = 11111111, this byte = 111?????
1792  $unsyncheddata .= "\x00";
1793  }
1794  }
1795  }
1796  return $unsyncheddata;
1797  }
$data

◆ WriteID3v2() [1/2]

getid3_write_id3v2::WriteID3v2 ( )

Definition at line 35 of file write.id3v2.php.

References getID3\analyze(), array_join_merge(), GenerateID3v2Tag(), and GETID3_FREAD_BUFFER_SIZE.

35  {
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  }
const GETID3_FREAD_BUFFER_SIZE
Definition: getid3.php:14
GenerateID3v2Tag($noerrorsonly=true)
array_join_merge($arr1, $arr2)
analyze($filename)
Definition: getid3.php:168
+ Here is the call graph for this function:

◆ WriteID3v2() [2/2]

getid3_write_id3v2::WriteID3v2 ( )

Definition at line 37 of file write.id3v2.php.

References $paddedlength, getID3\analyze(), array_join_merge(), GenerateID3v2Tag(), and getid3_lib\intValueSupported().

37  {
38  // File MUST be writeable - CHMOD(646) at least. It's best if the
39  // directory is also writeable, because that method is both faster and less susceptible to errors.
40 
41  if (!empty($this->filename) && (is_writeable($this->filename) || (!file_exists($this->filename) && is_writeable(dirname($this->filename))))) {
42  // Initialize getID3 engine
43  $getID3 = new getID3;
44  $OldThisFileInfo = $getID3->analyze($this->filename);
45  if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) {
46  $this->errors[] = 'Unable to write ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
47  fclose($fp_source);
48  return false;
49  }
50  if ($this->merge_existing_data) {
51  // merge with existing data
52  if (!empty($OldThisFileInfo['id3v2'])) {
53  $this->tag_data = $this->array_join_merge($OldThisFileInfo['id3v2'], $this->tag_data);
54  }
55  }
56  $this->paddedlength = (isset($OldThisFileInfo['id3v2']['headerlength']) ? max($OldThisFileInfo['id3v2']['headerlength'], $this->paddedlength) : $this->paddedlength);
57 
58  if ($NewID3v2Tag = $this->GenerateID3v2Tag()) {
59 
60  if (file_exists($this->filename) && is_writeable($this->filename) && isset($OldThisFileInfo['id3v2']['headerlength']) && ($OldThisFileInfo['id3v2']['headerlength'] == strlen($NewID3v2Tag))) {
61 
62  // best and fastest method - insert-overwrite existing tag (padded to length of old tag if neccesary)
63  if (file_exists($this->filename)) {
64 
65  if (is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'r+b'))) {
66  rewind($fp);
67  fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag));
68  fclose($fp);
69  } else {
70  $this->errors[] = 'Could not fopen("'.$this->filename.'", "r+b")';
71  }
72 
73  } else {
74 
75  if (is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'wb'))) {
76  rewind($fp);
77  fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag));
78  fclose($fp);
79  } else {
80  $this->errors[] = 'Could not fopen("'.$this->filename.'", "wb")';
81  }
82 
83  }
84 
85  } else {
86 
87  if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) {
88  if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) {
89  if (is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) {
90 
91  fwrite($fp_temp, $NewID3v2Tag, strlen($NewID3v2Tag));
92 
93  rewind($fp_source);
94  if (!empty($OldThisFileInfo['avdataoffset'])) {
95  fseek($fp_source, $OldThisFileInfo['avdataoffset']);
96  }
97 
98  while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
99  fwrite($fp_temp, $buffer, strlen($buffer));
100  }
101 
102  fclose($fp_temp);
103  fclose($fp_source);
104  copy($tempfilename, $this->filename);
105  unlink($tempfilename);
106  return true;
107 
108  } else {
109  $this->errors[] = 'Could not fopen("'.$tempfilename.'", "wb")';
110  }
111  fclose($fp_source);
112 
113  } else {
114  $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")';
115  }
116  }
117  return false;
118 
119  }
120 
121  } else {
122 
123  $this->errors[] = '$this->GenerateID3v2Tag() failed';
124 
125  }
126 
127  if (!empty($this->errors)) {
128  return false;
129  }
130  return true;
131  } else {
132  $this->errors[] = 'WriteID3v2() failed: !is_writeable('.$this->filename.')';
133  }
134  return false;
135  }
GenerateID3v2Tag($noerrorsonly=true)
static intValueSupported($num)
Definition: getid3.lib.php:80
array_join_merge($arr1, $arr2)
analyze($filename)
Definition: getid3.php:168
+ Here is the call graph for this function:

Field Documentation

◆ $errors

getid3_write_id3v2::$errors = array()

Definition at line 29 of file write.id3v2.php.

◆ $filename

getid3_write_id3v2::$filename

Definition at line 20 of file write.id3v2.php.

◆ $fread_buffer_size

getid3_write_id3v2::$fread_buffer_size = 32768

Definition at line 23 of file write.id3v2.php.

◆ $id3v2_default_encodingid

getid3_write_id3v2::$id3v2_default_encodingid = 0

Definition at line 26 of file write.id3v2.php.

Referenced by GenerateID3v2FrameData().

◆ $id3v2_use_unsynchronisation

getid3_write_id3v2::$id3v2_use_unsynchronisation = false

Definition at line 27 of file write.id3v2.php.

◆ $majorversion

getid3_write_id3v2::$majorversion = 3

Definition at line 23 of file write.id3v2.php.

Referenced by GenerateID3v2FrameData(), and ID3v2ShortFrameNameLookup().

◆ $merge_existing_data

getid3_write_id3v2::$merge_existing_data = false

Definition at line 25 of file write.id3v2.php.

◆ $minorversion

getid3_write_id3v2::$minorversion = 0

Definition at line 24 of file write.id3v2.php.

◆ $paddedlength

getid3_write_id3v2::$paddedlength = 4096

Definition at line 22 of file write.id3v2.php.

Referenced by WriteID3v2().

◆ $tag_data

getid3_write_id3v2::$tag_data

Definition at line 21 of file write.id3v2.php.

◆ $warnings

getid3_write_id3v2::$warnings = array()

Definition at line 28 of file write.id3v2.php.


The documentation for this class was generated from the following file: