1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314
<?php
if (!defined('GETID3_INCLUDEPATH')) {
exit;
}
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
class getid3_write_id3v2
{
public $filename;
public $tag_data;
public $fread_buffer_size = 32768;
public $paddedlength = 4096;
public $majorversion = 3;
public $minorversion = 0;
public $merge_existing_data = false;
public $id3v2_default_encodingid = 0;
public $id3v2_use_unsynchronisation = false;
public $warnings = array();
public $errors = array();
public function __construct() {
}
public function WriteID3v2() {
if (!empty($this->filename) && (getID3::is_writable($this->filename) || (!file_exists($this->filename) && getID3::is_writable(dirname($this->filename))))) {
$getID3 = new getID3;
$OldThisFileInfo = $getID3->analyze($this->filename);
if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) {
$this->errors[] = 'Unable to write ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
return false;
}
if ($this->merge_existing_data) {
if (!empty($OldThisFileInfo['id3v2'])) {
$this->tag_data = $this->array_join_merge($OldThisFileInfo['id3v2'], $this->tag_data);
}
}
$this->paddedlength = (isset($OldThisFileInfo['id3v2']['headerlength']) ? max($OldThisFileInfo['id3v2']['headerlength'], $this->paddedlength) : $this->paddedlength);
if ($NewID3v2Tag = $this->GenerateID3v2Tag()) {
if (file_exists($this->filename) && getID3::is_writable($this->filename) && isset($OldThisFileInfo['id3v2']['headerlength']) && ($OldThisFileInfo['id3v2']['headerlength'] == strlen($NewID3v2Tag))) {
if (is_readable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'r+b'))) {
rewind($fp);
fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag));
fclose($fp);
} else {
$this->errors[] = 'Could not fopen("'.$this->filename.'", "r+b")';
}
} else {
if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) {
if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) {
if (getID3::is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) {
fwrite($fp_temp, $NewID3v2Tag, strlen($NewID3v2Tag));
rewind($fp_source);
if (!empty($OldThisFileInfo['avdataoffset'])) {
fseek($fp_source, $OldThisFileInfo['avdataoffset']);
}
while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
fwrite($fp_temp, $buffer, strlen($buffer));
}
fclose($fp_temp);
fclose($fp_source);
copy($tempfilename, $this->filename);
unlink($tempfilename);
return true;
} else {
$this->errors[] = 'Could not fopen("'.$tempfilename.'", "wb")';
}
fclose($fp_source);
} else {
$this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")';
}
}
return false;
}
} else {
$this->errors[] = '$this->GenerateID3v2Tag() failed';
}
if (!empty($this->errors)) {
return false;
}
return true;
} else {
$this->errors[] = 'WriteID3v2() failed: !is_writeable('.$this->filename.')';
}
return false;
}
public function RemoveID3v2() {
if (getID3::is_writable(dirname($this->filename))) {
if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) {
$getID3 = new getID3;
$OldThisFileInfo = $getID3->analyze($this->filename);
if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) {
$this->errors[] = 'Unable to remove ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
fclose($fp_source);
return false;
}
rewind($fp_source);
if ($OldThisFileInfo['avdataoffset'] !== false) {
fseek($fp_source, $OldThisFileInfo['avdataoffset']);
}
if (getID3::is_writable($this->filename) && ($fp_temp = fopen($this->filename.'getid3tmp', 'w+b'))) {
while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
fwrite($fp_temp, $buffer, strlen($buffer));
}
fclose($fp_temp);
} else {
$this->errors[] = 'Could not fopen("'.$this->filename.'getid3tmp", "w+b")';
}
fclose($fp_source);
} else {
$this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")';
}
if (file_exists($this->filename)) {
unlink($this->filename);
}
rename($this->filename.'getid3tmp', $this->filename);
} elseif (getID3::is_writable($this->filename)) {
if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) {
$getID3 = new getID3;
$OldThisFileInfo = $getID3->analyze($this->filename);
if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) {
$this->errors[] = 'Unable to remove ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
fclose($fp_source);
return false;
}
rewind($fp_source);
if ($OldThisFileInfo['avdataoffset'] !== false) {
fseek($fp_source, $OldThisFileInfo['avdataoffset']);
}
if ($fp_temp = tmpfile()) {
while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
fwrite($fp_temp, $buffer, strlen($buffer));
}
fclose($fp_source);
if ($fp_source = fopen($this->filename, 'wb')) {
rewind($fp_temp);
while ($buffer = fread($fp_temp, $this->fread_buffer_size)) {
fwrite($fp_source, $buffer, strlen($buffer));
}
fseek($fp_temp, -128, SEEK_END);
fclose($fp_source);
} else {
$this->errors[] = 'Could not fopen("'.$this->filename.'", "wb")';
}
fclose($fp_temp);
} else {
$this->errors[] = 'Could not create tmpfile()';
}
} else {
$this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")';
}
} else {
$this->errors[] = 'Directory and file both not writeable';
}
if (!empty($this->errors)) {
return false;
}
return true;
}
public function GenerateID3v2TagFlags($flags) {
$flag = null;
switch ($this->majorversion) {
case 4:
$flag = (!empty($flags['unsynchronisation']) ? '1' : '0');
$flag .= (!empty($flags['extendedheader'] ) ? '1' : '0');
$flag .= (!empty($flags['experimental'] ) ? '1' : '0');
$flag .= (!empty($flags['footer'] ) ? '1' : '0');
$flag .= '0000';
break;
case 3:
$flag = (!empty($flags['unsynchronisation']) ? '1' : '0');
$flag .= (!empty($flags['extendedheader'] ) ? '1' : '0');
$flag .= (!empty($flags['experimental'] ) ? '1' : '0');
$flag .= '00000';
break;
case 2:
$flag = (!empty($flags['unsynchronisation']) ? '1' : '0');
$flag .= (!empty($flags['compression'] ) ? '1' : '0');
$flag .= '000000';
break;
default:
return false;
}
return chr(bindec($flag));
}
public function GenerateID3v2FrameFlags($TagAlter=false, $FileAlter=false, $ReadOnly=false, $Compression=false, $Encryption=false, $GroupingIdentity=false, $Unsynchronisation=false, $DataLengthIndicator=false) {
$flag1 = null;
$flag2 = null;
switch ($this->majorversion) {
case 4:
$flag1 = '0';
$flag1 .= $TagAlter ? '1' : '0';
$flag1 .= $FileAlter ? '1' : '0';
$flag1 .= $ReadOnly ? '1' : '0';
$flag1 .= '0000';
$flag2 = '0';
$flag2 .= $GroupingIdentity ? '1' : '0';
$flag2 .= '00';
$flag2 .= $Compression ? '1' : '0';
$flag2 .= $Encryption ? '1' : '0';
$flag2 .= $Unsynchronisation ? '1' : '0';
$flag2 .= $DataLengthIndicator ? '1' : '0';
break;
case 3:
$flag1 = $TagAlter ? '1' : '0';
$flag1 .= $FileAlter ? '1' : '0';
$flag1 .= $ReadOnly ? '1' : '0';
$flag1 .= '00000';
$flag2 = $Compression ? '1' : '0';
$flag2 .= $Encryption ? '1' : '0';
$flag2 .= $GroupingIdentity ? '1' : '0';
$flag2 .= '00000';
break;
default:
return false;
}
return chr(bindec($flag1)).chr(bindec($flag2));
}
public function GenerateID3v2FrameData($frame_name, $source_data_array) {
if (!getid3_id3v2::IsValidID3v2FrameName($frame_name, $this->majorversion)) {
return false;
}
$framedata = '';
if (($this->majorversion < 3) || ($this->majorversion > 4)) {
$this->errors[] = 'Only ID3v2.3 and ID3v2.4 are supported in GenerateID3v2FrameData()';
} else {
switch ($frame_name) {
case 'UFID':
if (strlen($source_data_array['data']) > 64) {
$this->errors[] = 'Identifier not allowed to be longer than 64 bytes in '.$frame_name.' (supplied data was '.strlen($source_data_array['data']).' bytes long)';
} else {
$framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
$framedata .= substr($source_data_array['data'], 0, 64);
}
break;
case 'TXXX':
$source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
$this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
} else {
$framedata .= chr($source_data_array['encodingid']);
$framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
$framedata .= $source_data_array['data'];
}
break;
case 'WXXX':
$source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
$this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
} elseif (!isset($source_data_array['data']) || !$this->IsValidURL($source_data_array['data'], false)) {
$this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
} else {
$framedata .= chr($source_data_array['encodingid']);
$framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
$framedata .= $source_data_array['data'];
}
break;
case 'IPLS':
$source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
$this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
} else {
$framedata .= chr($source_data_array['encodingid']);
$framedata .= $source_data_array['data'];
}
break;
case 'MCDI':
$framedata .= $source_data_array['data'];
break;
case 'ETCO':
if (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) {
$this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
} else {
$framedata .= chr($source_data_array['timestampformat']);
foreach ($source_data_array as $key => $val) {
if (!$this->ID3v2IsValidETCOevent($val['typeid'])) {
$this->errors[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')';
} elseif (($key != 'timestampformat') && ($key != 'flags')) {
if (($val['timestamp'] > 0) && isset($previousETCOtimestamp) && ($previousETCOtimestamp >= $val['timestamp'])) {
$this->errors[] = 'Out-of-order timestamp in '.$frame_name.' ('.$val['timestamp'].') for Event Type ('.$val['typeid'].')';
} else {
$framedata .= chr($val['typeid']);
$framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false);
$previousETCOtimestamp = $val['timestamp'];
}
}
}
}
break;
case 'MLLT':
if (($source_data_array['framesbetweenreferences'] > 0) && ($source_data_array['framesbetweenreferences'] <= 65535)) {
$framedata .= getid3_lib::BigEndian2String($source_data_array['framesbetweenreferences'], 2, false);
} else {
$this->errors[] = 'Invalid MPEG Frames Between References in '.$frame_name.' ('.$source_data_array['framesbetweenreferences'].')';
}
if (($source_data_array['bytesbetweenreferences'] > 0) && ($source_data_array['bytesbetweenreferences'] <= 16777215)) {
$framedata .= getid3_lib::BigEndian2String($source_data_array['bytesbetweenreferences'], 3, false);
} else {
$this->errors[] = 'Invalid bytes Between References in '.$frame_name.' ('.$source_data_array['bytesbetweenreferences'].')';
}
if (($source_data_array['msbetweenreferences'] > 0) && ($source_data_array['msbetweenreferences'] <= 16777215)) {
$framedata .= getid3_lib::BigEndian2String($source_data_array['msbetweenreferences'], 3, false);
} else {
$this->errors[] = 'Invalid Milliseconds Between References in '.$frame_name.' ('.$source_data_array['msbetweenreferences'].')';
}
if (!$this->IsWithinBitRange($source_data_array['bitsforbytesdeviation'], 8, false)) {
if (($source_data_array['bitsforbytesdeviation'] % 4) == 0) {
$framedata .= chr($source_data_array['bitsforbytesdeviation']);
} else {
$this->errors[] = 'Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.';
}
} else {
$this->errors[] = 'Invalid Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].')';
}
if (!$this->IsWithinBitRange($source_data_array['bitsformsdeviation'], 8, false)) {
if (($source_data_array['bitsformsdeviation'] % 4) == 0) {
$framedata .= chr($source_data_array['bitsformsdeviation']);
} else {
$this->errors[] = 'Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.';
}
} else {
$this->errors[] = 'Invalid Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsformsdeviation'].')';
}
$unwrittenbitstream = '';
foreach ($source_data_array as $key => $val) {
if (($key != 'framesbetweenreferences') && ($key != 'bytesbetweenreferences') && ($key != 'msbetweenreferences') && ($key != 'bitsforbytesdeviation') && ($key != 'bitsformsdeviation') && ($key != 'flags')) {
$unwrittenbitstream .= str_pad(getid3_lib::Dec2Bin($val['bytedeviation']), $source_data_array['bitsforbytesdeviation'], '0', STR_PAD_LEFT);
$unwrittenbitstream .= str_pad(getid3_lib::Dec2Bin($val['msdeviation']), $source_data_array['bitsformsdeviation'], '0', STR_PAD_LEFT);
}
}
for ($i = 0; $i < strlen($unwrittenbitstream); $i += 8) {
$highnibble = bindec(substr($unwrittenbitstream, $i, 4)) << 4;
$lownibble = bindec(substr($unwrittenbitstream, $i + 4, 4));
$framedata .= chr($highnibble & $lownibble);
}
break;
case 'SYTC':
if (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) {
$this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
} else {
$framedata .= chr($source_data_array['timestampformat']);
foreach ($source_data_array as $key => $val) {
if (!$this->ID3v2IsValidETCOevent($val['typeid'])) {
$this->errors[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')';
} elseif (($key != 'timestampformat') && ($key != 'flags')) {
if (($val['tempo'] < 0) || ($val['tempo'] > 510)) {
$this->errors[] = 'Invalid Tempo (max = 510) in '.$frame_name.' ('.$val['tempo'].') at timestamp ('.$val['timestamp'].')';
} else {
if ($val['tempo'] > 255) {
$framedata .= chr(255);
$val['tempo'] -= 255;
}
$framedata .= chr($val['tempo']);
$framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false);
}
}
}
}
break;
case 'USLT':
$source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
$this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
} elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
$this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
} else {
$framedata .= chr($source_data_array['encodingid']);
$framedata .= strtolower($source_data_array['language']);
$framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
$framedata .= $source_data_array['data'];
}
break;
case 'SYLT':
$source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
$this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
} elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
$this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
} elseif (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) {
$this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')';
} elseif (!$this->ID3v2IsValidSYLTtype($source_data_array['contenttypeid'])) {
$this->errors[] = 'Invalid Content Type byte in '.$frame_name.' ('.$source_data_array['contenttypeid'].')';
} elseif (!is_array($source_data_array['data'])) {
$this->errors[] = 'Invalid Lyric/Timestamp data in '.$frame_name.' (must be an array)';
} else {
$framedata .= chr($source_data_array['encodingid']);
$framedata .= strtolower($source_data_array['language']);
$framedata .= chr($source_data_array['timestampformat']);
$framedata .= chr($source_data_array['contenttypeid']);
$framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
ksort($source_data_array['data']);
foreach ($source_data_array['data'] as $key => $val) {
$framedata .= $val['data'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
$framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false);
}
}
break;
case 'COMM':
$source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
$this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
} elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
$this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
} else {
$framedata .= chr($source_data_array['encodingid']);
$framedata .= strtolower($source_data_array['language']);
$framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
$framedata .= $source_data_array['data'];
}
break;
case 'RVA2':
$framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00";
foreach ($source_data_array as $key => $val) {
if ($key != 'description') {
$framedata .= chr($val['channeltypeid']);
$framedata .= getid3_lib::BigEndian2String($val['volumeadjust'], 2, false, true);
if (!$this->IsWithinBitRange($source_data_array['bitspeakvolume'], 8, false)) {
$framedata .= chr($val['bitspeakvolume']);
if ($val['bitspeakvolume'] > 0) {
$framedata .= getid3_lib::BigEndian2String($val['peakvolume'], ceil($val['bitspeakvolume'] / 8), false, false);
}
} else {
$this->errors[] = 'Invalid Bits Representing Peak Volume in '.$frame_name.' ('.$val['bitspeakvolume'].') (range = 0 to 255)';
}
}
}
break;
case 'RVAD':
if (!$this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) {
$this->errors[] = 'Invalid Bits For Volume Description byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)';
} else {
$incdecflag = '00';
$incdecflag .= $source_data_array['incdec']['right'] ? '1' : '0';
$incdecflag .= $source_data_array['incdec']['left'] ? '1' : '0';
$incdecflag .= $source_data_array['incdec']['rightrear'] ? '1' : '0';
$incdecflag .= $source_data_array['incdec']['leftrear'] ? '1' : '0';
$incdecflag .= $source_data_array['incdec']['center'] ? '1' : '0';
$incdecflag .= $source_data_array['incdec']['bass'] ? '1' : '0';
$framedata .= chr(bindec($incdecflag));
$framedata .= chr($source_data_array['bitsvolume']);
$framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['right'], ceil($source_data_array['bitsvolume'] / 8), false);
$framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['left'], ceil($source_data_array['bitsvolume'] / 8), false);
$framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['right'], ceil($source_data_array['bitsvolume'] / 8), false);
$framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['left'], ceil($source_data_array['bitsvolume'] / 8), false);
if ($source_data_array['volumechange']['rightrear'] || $source_data_array['volumechange']['leftrear'] ||
$source_data_array['peakvolume']['rightrear'] || $source_data_array['peakvolume']['leftrear'] ||
$source_data_array['volumechange']['center'] || $source_data_array['peakvolume']['center'] ||
$source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) {
$framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['rightrear'], ceil($source_data_array['bitsvolume']/8), false);
$framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['leftrear'], ceil($source_data_array['bitsvolume']/8), false);
$framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['rightrear'], ceil($source_data_array['bitsvolume']/8), false);
$framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['leftrear'], ceil($source_data_array['bitsvolume']/8), false);
}
if ($source_data_array['volumechange']['center'] || $source_data_array['peakvolume']['center'] ||
$source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) {
$framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['center'], ceil($source_data_array['bitsvolume']/8), false);
$framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['center'], ceil($source_data_array['bitsvolume']/8), false);
}
if ($source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) {
$framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['bass'], ceil($source_data_array['bitsvolume']/8), false);
$framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['bass'], ceil($source_data_array['bitsvolume']/8), false);
}
}
break;
case 'EQU2':
if (($source_data_array['interpolationmethod'] < 0) || ($source_data_array['interpolationmethod'] > 1)) {
$this->errors[] = 'Invalid Interpolation Method byte in '.$frame_name.' ('.$source_data_array['interpolationmethod'].') (valid = 0 or 1)';
} else {
$framedata .= chr($source_data_array['interpolationmethod']);
$framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00";
foreach ($source_data_array['data'] as $key => $val) {
$framedata .= getid3_lib::BigEndian2String(intval(round($key * 2)), 2, false);
$framedata .= getid3_lib::BigEndian2String($val, 2, false, true);
}
}
break;
case 'EQUA':
if (!$this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) {
$this->errors[] = 'Invalid Adjustment Bits byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)';
} else {
$framedata .= chr($source_data_array['adjustmentbits']);
foreach ($source_data_array as $key => $val) {
if ($key != 'bitsvolume') {
if (($key > 32767) || ($key < 0)) {
$this->errors[] = 'Invalid Frequency in '.$frame_name.' ('.$key.') (range = 0 to 32767)';
} else {
if ($val >= 0) {
$key |= 0x8000;
}
$framedata .= getid3_lib::BigEndian2String($key, 2, false);
$framedata .= getid3_lib::BigEndian2String($val, ceil($source_data_array['adjustmentbits'] / 8), false);
}
}
}
}
break;
case 'RVRB':
if (!$this->IsWithinBitRange($source_data_array['left'], 16, false)) {
$this->errors[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['left'].') (range = 0 to 65535)';
} elseif (!$this->IsWithinBitRange($source_data_array['right'], 16, false)) {
$this->errors[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['right'].') (range = 0 to 65535)';
} elseif (!$this->IsWithinBitRange($source_data_array['bouncesL'], 8, false)) {
$this->errors[] = 'Invalid Reverb Bounces, Left in '.$frame_name.' ('.$source_data_array['bouncesL'].') (range = 0 to 255)';
} elseif (!$this->IsWithinBitRange($source_data_array['bouncesR'], 8, false)) {
$this->errors[] = 'Invalid Reverb Bounces, Right in '.$frame_name.' ('.$source_data_array['bouncesR'].') (range = 0 to 255)';
} elseif (!$this->IsWithinBitRange($source_data_array['feedbackLL'], 8, false)) {
$this->errors[] = 'Invalid Reverb Feedback, Left-To-Left in '.$frame_name.' ('.$source_data_array['feedbackLL'].') (range = 0 to 255)';
} elseif (!$this->IsWithinBitRange($source_data_array['feedbackLR'], 8, false)) {
$this->errors[] = 'Invalid Reverb Feedback, Left-To-Right in '.$frame_name.' ('.$source_data_array['feedbackLR'].') (range = 0 to 255)';
} elseif (!$this->IsWithinBitRange($source_data_array['feedbackRR'], 8, false)) {
$this->errors[] = 'Invalid Reverb Feedback, Right-To-Right in '.$frame_name.' ('.$source_data_array['feedbackRR'].') (range = 0 to 255)';
} elseif (!$this->IsWithinBitRange($source_data_array['feedbackRL'], 8, false)) {
$this->errors[] = 'Invalid Reverb Feedback, Right-To-Left in '.$frame_name.' ('.$source_data_array['feedbackRL'].') (range = 0 to 255)';
} elseif (!$this->IsWithinBitRange($source_data_array['premixLR'], 8, false)) {
$this->errors[] = 'Invalid Premix, Left-To-Right in '.$frame_name.' ('.$source_data_array['premixLR'].') (range = 0 to 255)';
} elseif (!$this->IsWithinBitRange($source_data_array['premixRL'], 8, false)) {
$this->errors[] = 'Invalid Premix, Right-To-Left in '.$frame_name.' ('.$source_data_array['premixRL'].') (range = 0 to 255)';
} else {
$framedata .= getid3_lib::BigEndian2String($source_data_array['left'], 2, false);
$framedata .= getid3_lib::BigEndian2String($source_data_array['right'], 2, false);
$framedata .= chr($source_data_array['bouncesL']);
$framedata .= chr($source_data_array['bouncesR']);
$framedata .= chr($source_data_array['feedbackLL']);
$framedata .= chr($source_data_array['feedbackLR']);
$framedata .= chr($source_data_array['feedbackRR']);
$framedata .= chr($source_data_array['feedbackRL']);
$framedata .= chr($source_data_array['premixLR']);
$framedata .= chr($source_data_array['premixRL']);
}
break;
case 'APIC':
$source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
$this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
} elseif (!$this->ID3v2IsValidAPICpicturetype($source_data_array['picturetypeid'])) {
$this->errors[] = 'Invalid Picture Type byte in '.$frame_name.' ('.$source_data_array['picturetypeid'].') for ID3v2.'.$this->majorversion;
} elseif ((!$this->ID3v2IsValidAPICimageformat($source_data_array['mime']))) {
$this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].') for ID3v2.'.$this->majorversion;
} elseif (($source_data_array['mime'] == '-->') && (!$this->IsValidURL($source_data_array['data'], false))) {
$this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
} else {
$framedata .= chr($source_data_array['encodingid']);
$framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00";
$framedata .= chr($source_data_array['picturetypeid']);
$framedata .= (!empty($source_data_array['description']) ? $source_data_array['description'] : '').getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
$framedata .= $source_data_array['data'];
}
break;
case 'GEOB':
$source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
$this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
} elseif (!$this->IsValidMIMEstring($source_data_array['mime'])) {
$this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].')';
} elseif (!$source_data_array['description']) {
$this->errors[] = 'Missing Description in '.$frame_name;
} else {
$framedata .= chr($source_data_array['encodingid']);
$framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00";
$framedata .= $source_data_array['filename'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
$framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
$framedata .= $source_data_array['data'];
}
break;
case 'PCNT':
$framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false);
break;
case 'POPM':
if (!$this->IsValidEmail($source_data_array['email'])) {
$this->warnings[] = 'Invalid Email in '.$frame_name.' ('.$source_data_array['email'].')';
}
if (!$this->IsWithinBitRange($source_data_array['rating'], 8, false)) {
$this->errors[] = 'Invalid Rating byte in '.$frame_name.' ('.$source_data_array['rating'].') (range = 0 to 255)';
} else {
$framedata .= str_replace("\x00", '', $source_data_array['email'])."\x00";
$framedata .= chr($source_data_array['rating']);
$framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false);
}
break;
case 'RBUF':
if (!$this->IsWithinBitRange($source_data_array['buffersize'], 24, false)) {
$this->errors[] = 'Invalid Buffer Size in '.$frame_name;
} elseif (!$this->IsWithinBitRange($source_data_array['nexttagoffset'], 32, false)) {
$this->errors[] = 'Invalid Offset To Next Tag in '.$frame_name;
} else {
$framedata .= getid3_lib::BigEndian2String($source_data_array['buffersize'], 3, false);
$flag = '0000000';
$flag .= $source_data_array['flags']['embededinfo'] ? '1' : '0';
$framedata .= chr(bindec($flag));
$framedata .= getid3_lib::BigEndian2String($source_data_array['nexttagoffset'], 4, false);
}
break;
case 'AENC':
if (!$this->IsWithinBitRange($source_data_array['previewstart'], 16, false)) {
$this->errors[] = 'Invalid Preview Start in '.$frame_name.' ('.$source_data_array['previewstart'].')';
} elseif (!$this->IsWithinBitRange($source_data_array['previewlength'], 16, false)) {
$this->errors[] = 'Invalid Preview Length in '.$frame_name.' ('.$source_data_array['previewlength'].')';
} else {
$framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
$framedata .= getid3_lib::BigEndian2String($source_data_array['previewstart'], 2, false);
$framedata .= getid3_lib::BigEndian2String($source_data_array['previewlength'], 2, false);
$framedata .= $source_data_array['encryptioninfo'];
}
break;
case 'LINK':
if (!getid3_id3v2::IsValidID3v2FrameName($source_data_array['frameid'], $this->majorversion)) {
$this->errors[] = 'Invalid Frame Identifier in '.$frame_name.' ('.$source_data_array['frameid'].')';
} elseif (!$this->IsValidURL($source_data_array['data'], true)) {
$this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
} 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'] == '')) {
$this->errors[] = 'Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
} elseif (($source_data_array['frameid'] == 'USER') && (getid3_id3v2::LanguageLookup($source_data_array['additionaldata'], true) == '')) {
$this->errors[] = 'Language must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
} elseif (($source_data_array['frameid'] == 'PRIV') && ($source_data_array['additionaldata'] == '')) {
$this->errors[] = 'Owner Identifier must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
} 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) == ''))) {
$this->errors[] = 'Language followed by Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name;
} else {
$framedata .= $source_data_array['frameid'];
$framedata .= str_replace("\x00", '', $source_data_array['data'])."\x00";
switch ($source_data_array['frameid']) {
case 'COMM':
case 'SYLT':
case 'USLT':
case 'PRIV':
case 'USER':
case 'AENC':
case 'APIC':
case 'GEOB':
case 'TXXX':
$framedata .= $source_data_array['additionaldata'];
break;
case 'ASPI':
case 'ETCO':
case 'EQU2':
case 'MCID':
case 'MLLT':
case 'OWNE':
case 'RVA2':
case 'RVRB':
case 'SYTC':
case 'IPLS':
case 'RVAD':
case 'EQUA':
break;
case 'RBUF':
if ($this->majorversion == 3) {
} else {
$this->errors[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion.')';
}
break;
default:
if ((substr($source_data_array['frameid'], 0, 1) == 'T') || (substr($source_data_array['frameid'], 0, 1) == 'W')) {
} else {
$this->errors[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion.')';
}
break;
}
}
break;
case 'POSS':
if (($source_data_array['timestampformat'] < 1) || ($source_data_array['timestampformat'] > 2)) {
$this->errors[] = 'Invalid Time Stamp Format in '.$frame_name.' ('.$source_data_array['timestampformat'].') (valid = 1 or 2)';
} elseif (!$this->IsWithinBitRange($source_data_array['position'], 32, false)) {
$this->errors[] = 'Invalid Position in '.$frame_name.' ('.$source_data_array['position'].') (range = 0 to 4294967295)';
} else {
$framedata .= chr($source_data_array['timestampformat']);
$framedata .= getid3_lib::BigEndian2String($source_data_array['position'], 4, false);
}
break;
case 'USER':
$source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
$this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')';
} elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') {
$this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')';
} else {
$framedata .= chr($source_data_array['encodingid']);
$framedata .= strtolower($source_data_array['language']);
$framedata .= $source_data_array['data'];
}
break;
case 'OWNE':
$source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
$this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')';
} elseif (!getid3_id3v2::IsANumber($source_data_array['pricepaid']['value'], false)) {
$this->errors[] = 'Invalid Price Paid in '.$frame_name.' ('.$source_data_array['pricepaid']['value'].')';
} elseif (!getid3_id3v2::IsValidDateStampString($source_data_array['purchasedate'])) {
$this->errors[] = 'Invalid Date Of Purchase in '.$frame_name.' ('.$source_data_array['purchasedate'].') (format = YYYYMMDD)';
} else {
$framedata .= chr($source_data_array['encodingid']);
$framedata .= str_replace("\x00", '', $source_data_array['pricepaid']['value'])."\x00";
$framedata .= $source_data_array['purchasedate'];
$framedata .= $source_data_array['seller'];
}
break;
case 'COMR':
$source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
$this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')';
} elseif (!getid3_id3v2::IsValidDateStampString($source_data_array['pricevaliduntil'])) {
$this->errors[] = 'Invalid Valid Until date in '.$frame_name.' ('.$source_data_array['pricevaliduntil'].') (format = YYYYMMDD)';
} elseif (!$this->IsValidURL($source_data_array['contacturl'], false)) {
$this->errors[] = 'Invalid Contact URL in '.$frame_name.' ('.$source_data_array['contacturl'].') (allowed schemes: http, https, ftp, mailto)';
} elseif (!$this->ID3v2IsValidCOMRreceivedAs($source_data_array['receivedasid'])) {
$this->errors[] = 'Invalid Received As byte in '.$frame_name.' ('.$source_data_array['contacturl'].') (range = 0 to 8)';
} elseif (!$this->IsValidMIMEstring($source_data_array['mime'])) {
$this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].')';
} else {
$framedata .= chr($source_data_array['encodingid']);
$pricestrings = array();
foreach ($source_data_array['price'] as $key => $val) {
if ($this->ID3v2IsValidPriceString($key.$val['value'])) {
$pricestrings[] = $key.$val['value'];
} else {
$this->errors[] = 'Invalid Price String in '.$frame_name.' ('.$key.$val['value'].')';
}
}
$framedata .= implode('/', $pricestrings);
$framedata .= $source_data_array['pricevaliduntil'];
$framedata .= str_replace("\x00", '', $source_data_array['contacturl'])."\x00";
$framedata .= chr($source_data_array['receivedasid']);
$framedata .= $source_data_array['sellername'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
$framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']);
$framedata .= $source_data_array['mime']."\x00";
$framedata .= $source_data_array['logo'];
}
break;
case 'ENCR':
if (!$this->IsWithinBitRange($source_data_array['methodsymbol'], 8, false)) {
$this->errors[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['methodsymbol'].') (range = 0 to 255)';
} else {
$framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
$framedata .= ord($source_data_array['methodsymbol']);
$framedata .= $source_data_array['data'];
}
break;
case 'GRID':
if (!$this->IsWithinBitRange($source_data_array['groupsymbol'], 8, false)) {
$this->errors[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['groupsymbol'].') (range = 0 to 255)';
} else {
$framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
$framedata .= ord($source_data_array['groupsymbol']);
$framedata .= $source_data_array['data'];
}
break;
case 'PRIV':
$framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00";
$framedata .= $source_data_array['data'];
break;
case 'SIGN':
if (!$this->IsWithinBitRange($source_data_array['groupsymbol'], 8, false)) {
$this->errors[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['groupsymbol'].') (range = 0 to 255)';
} else {
$framedata .= ord($source_data_array['groupsymbol']);
$framedata .= $source_data_array['data'];
}
break;
case 'SEEK':
if (!$this->IsWithinBitRange($source_data_array['data'], 32, false)) {
$this->errors[] = 'Invalid Minimum Offset in '.$frame_name.' ('.$source_data_array['data'].') (range = 0 to 4294967295)';
} else {
$framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false);
}
break;
case 'ASPI':
if (!$this->IsWithinBitRange($source_data_array['datastart'], 32, false)) {
$this->errors[] = 'Invalid Indexed Data Start in '.$frame_name.' ('.$source_data_array['datastart'].') (range = 0 to 4294967295)';
} elseif (!$this->IsWithinBitRange($source_data_array['datalength'], 32, false)) {
$this->errors[] = 'Invalid Indexed Data Length in '.$frame_name.' ('.$source_data_array['datalength'].') (range = 0 to 4294967295)';
} elseif (!$this->IsWithinBitRange($source_data_array['indexpoints'], 16, false)) {
$this->errors[] = 'Invalid Number Of Index Points in '.$frame_name.' ('.$source_data_array['indexpoints'].') (range = 0 to 65535)';
} elseif (!$this->IsWithinBitRange($source_data_array['bitsperpoint'], 8, false)) {
$this->errors[] = 'Invalid Bits Per Index Point in '.$frame_name.' ('.$source_data_array['bitsperpoint'].') (range = 0 to 255)';
} elseif ($source_data_array['indexpoints'] != count($source_data_array['indexes'])) {
$this->errors[] = 'Number Of Index Points does not match actual supplied data in '.$frame_name;
} else {
$framedata .= getid3_lib::BigEndian2String($source_data_array['datastart'], 4, false);
$framedata .= getid3_lib::BigEndian2String($source_data_array['datalength'], 4, false);
$framedata .= getid3_lib::BigEndian2String($source_data_array['indexpoints'], 2, false);
$framedata .= getid3_lib::BigEndian2String($source_data_array['bitsperpoint'], 1, false);
foreach ($source_data_array['indexes'] as $key => $val) {
$framedata .= getid3_lib::BigEndian2String($val, ceil($source_data_array['bitsperpoint'] / 8), false);
}
}
break;
case 'RGAD':
if (($source_data_array['track_adjustment'] > 51) || ($source_data_array['track_adjustment'] < -51)) {
$this->errors[] = 'Invalid Track Adjustment in '.$frame_name.' ('.$source_data_array['track_adjustment'].') (range = -51.0 to +51.0)';
} elseif (($source_data_array['album_adjustment'] > 51) || ($source_data_array['album_adjustment'] < -51)) {
$this->errors[] = 'Invalid Album Adjustment in '.$frame_name.' ('.$source_data_array['album_adjustment'].') (range = -51.0 to +51.0)';
} elseif (!$this->ID3v2IsValidRGADname($source_data_array['raw']['track_name'])) {
$this->errors[] = 'Invalid Track Name Code in '.$frame_name.' ('.$source_data_array['raw']['track_name'].') (range = 0 to 2)';
} elseif (!$this->ID3v2IsValidRGADname($source_data_array['raw']['album_name'])) {
$this->errors[] = 'Invalid Album Name Code in '.$frame_name.' ('.$source_data_array['raw']['album_name'].') (range = 0 to 2)';
} elseif (!$this->ID3v2IsValidRGADoriginator($source_data_array['raw']['track_originator'])) {
$this->errors[] = 'Invalid Track Originator Code in '.$frame_name.' ('.$source_data_array['raw']['track_originator'].') (range = 0 to 3)';
} elseif (!$this->ID3v2IsValidRGADoriginator($source_data_array['raw']['album_originator'])) {
$this->errors[] = 'Invalid Album Originator Code in '.$frame_name.' ('.$source_data_array['raw']['album_originator'].') (range = 0 to 3)';
} else {
$framedata .= getid3_lib::Float2String($source_data_array['peakamplitude'], 32);
$framedata .= getid3_lib::RGADgainString($source_data_array['raw']['track_name'], $source_data_array['raw']['track_originator'], $source_data_array['track_adjustment']);
$framedata .= getid3_lib::RGADgainString($source_data_array['raw']['album_name'], $source_data_array['raw']['album_originator'], $source_data_array['album_adjustment']);
}
break;
default:
if (strlen($frame_name) != 4) {
$this->errors[] = 'Invalid frame name "'.$frame_name.'" for ID3v2.'.$this->majorversion;
} elseif ($frame_name[0] == 'T') {
$source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid);
if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) {
$this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion;
} else {
$framedata .= chr($source_data_array['encodingid']);
$framedata .= $source_data_array['data'];
}
} elseif ($frame_name[0] == 'W') {
if (!$this->IsValidURL($source_data_array['data'], false)) {
$this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')';
} else {
$framedata .= $source_data_array['data'];
}
} else {
$this->errors[] = $frame_name.' not yet supported in $this->GenerateID3v2FrameData()';
}
break;
}
}
if (!empty($this->errors)) {
return false;
}
return $framedata;
}
public function ID3v2FrameIsAllowed($frame_name, $source_data_array) {
static $PreviousFrames = array();
if ($frame_name === null) {
$PreviousFrames = array();
return true;
}
if ($this->majorversion == 4) {
switch ($frame_name) {
case 'UFID':
case 'AENC':
case 'ENCR':
case 'GRID':
if (!isset($source_data_array['ownerid'])) {
$this->errors[] = '[ownerid] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['ownerid'];
}
break;
case 'TXXX':
case 'WXXX':
case 'RVA2':
case 'EQU2':
case 'APIC':
case 'GEOB':
if (!isset($source_data_array['description'])) {
$this->errors[] = '[description] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['description'];
}
break;
case 'USER':
if (!isset($source_data_array['language'])) {
$this->errors[] = '[language] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['language'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language ('.$source_data_array['language'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['language'];
}
break;
case 'USLT':
case 'SYLT':
case 'COMM':
if (!isset($source_data_array['language'])) {
$this->errors[] = '[language] not specified for '.$frame_name;
} elseif (!isset($source_data_array['description'])) {
$this->errors[] = '[description] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description'];
}
break;
case 'POPM':
if (!isset($source_data_array['email'])) {
$this->errors[] = '[email] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['email'];
}
break;
case 'IPLS':
case 'MCDI':
case 'ETCO':
case 'MLLT':
case 'SYTC':
case 'RVRB':
case 'PCNT':
case 'RBUF':
case 'POSS':
case 'OWNE':
case 'SEEK':
case 'ASPI':
case 'RGAD':
if (in_array($frame_name, $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed';
} else {
$PreviousFrames[] = $frame_name;
}
break;
case 'LINK':
if (!isset($source_data_array['frameid'])) {
$this->errors[] = '[frameid] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')';
} elseif (in_array($source_data_array['frameid'], $PreviousFrames)) {
$this->errors[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['frameid'];
$PreviousFrames[] = $source_data_array['frameid'];
}
break;
case 'COMR':
break;
case 'PRIV':
case 'SIGN':
if (!isset($source_data_array['ownerid'])) {
$this->errors[] = '[ownerid] not specified for '.$frame_name;
} elseif (!isset($source_data_array['data'])) {
$this->errors[] = '[data] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['ownerid'].$source_data_array['data'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID + Data ('.$source_data_array['ownerid'].' + '.$source_data_array['data'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['ownerid'].$source_data_array['data'];
}
break;
default:
if (($frame_name[0] != 'T') && ($frame_name[0] != 'W')) {
$this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name;
}
break;
}
} elseif ($this->majorversion == 3) {
switch ($frame_name) {
case 'UFID':
case 'AENC':
case 'ENCR':
case 'GRID':
if (!isset($source_data_array['ownerid'])) {
$this->errors[] = '[ownerid] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['ownerid'];
}
break;
case 'TXXX':
case 'WXXX':
case 'APIC':
case 'GEOB':
if (!isset($source_data_array['description'])) {
$this->errors[] = '[description] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['description'];
}
break;
case 'USER':
if (!isset($source_data_array['language'])) {
$this->errors[] = '[language] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['language'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language ('.$source_data_array['language'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['language'];
}
break;
case 'USLT':
case 'SYLT':
case 'COMM':
if (!isset($source_data_array['language'])) {
$this->errors[] = '[language] not specified for '.$frame_name;
} elseif (!isset($source_data_array['description'])) {
$this->errors[] = '[description] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description'];
}
break;
case 'POPM':
if (!isset($source_data_array['email'])) {
$this->errors[] = '[email] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['email'];
}
break;
case 'IPLS':
case 'MCDI':
case 'ETCO':
case 'MLLT':
case 'SYTC':
case 'RVAD':
case 'EQUA':
case 'RVRB':
case 'PCNT':
case 'RBUF':
case 'POSS':
case 'OWNE':
case 'RGAD':
if (in_array($frame_name, $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed';
} else {
$PreviousFrames[] = $frame_name;
}
break;
case 'LINK':
if (!isset($source_data_array['frameid'])) {
$this->errors[] = '[frameid] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')';
} elseif (in_array($source_data_array['frameid'], $PreviousFrames)) {
$this->errors[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['frameid'];
$PreviousFrames[] = $source_data_array['frameid'];
}
break;
case 'COMR':
break;
case 'PRIV':
if (!isset($source_data_array['ownerid'])) {
$this->errors[] = '[ownerid] not specified for '.$frame_name;
} elseif (!isset($source_data_array['data'])) {
$this->errors[] = '[data] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['ownerid'].$source_data_array['data'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID + Data ('.$source_data_array['ownerid'].' + '.$source_data_array['data'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['ownerid'].$source_data_array['data'];
}
break;
default:
if (($frame_name[0] != 'T') && ($frame_name[0] != 'W')) {
$this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name;
}
break;
}
} elseif ($this->majorversion == 2) {
switch ($frame_name) {
case 'UFI':
case 'CRM':
case 'CRA':
if (!isset($source_data_array['ownerid'])) {
$this->errors[] = '[ownerid] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['ownerid'];
}
break;
case 'TXX':
case 'WXX':
case 'PIC':
case 'GEO':
if (!isset($source_data_array['description'])) {
$this->errors[] = '[description] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['description'];
}
break;
case 'ULT':
case 'SLT':
case 'COM':
if (!isset($source_data_array['language'])) {
$this->errors[] = '[language] not specified for '.$frame_name;
} elseif (!isset($source_data_array['description'])) {
$this->errors[] = '[description] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description'];
}
break;
case 'POP':
if (!isset($source_data_array['email'])) {
$this->errors[] = '[email] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['email'];
}
break;
case 'IPL':
case 'MCI':
case 'ETC':
case 'MLL':
case 'STC':
case 'RVA':
case 'EQU':
case 'REV':
case 'CNT':
case 'BUF':
if (in_array($frame_name, $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed';
} else {
$PreviousFrames[] = $frame_name;
}
break;
case 'LNK':
if (!isset($source_data_array['frameid'])) {
$this->errors[] = '[frameid] not specified for '.$frame_name;
} elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) {
$this->errors[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')';
} elseif (in_array($source_data_array['frameid'], $PreviousFrames)) {
$this->errors[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')';
} else {
$PreviousFrames[] = $frame_name.$source_data_array['frameid'];
$PreviousFrames[] = $source_data_array['frameid'];
}
break;
default:
if (($frame_name[0] != 'T') && ($frame_name[0] != 'W')) {
$this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name;
}
break;
}
}
if (!empty($this->errors)) {
return false;
}
return true;
}
public function GenerateID3v2Tag($noerrorsonly=true) {
$this->ID3v2FrameIsAllowed(null, '');
$tagstring = '';
if (is_array($this->tag_data)) {
foreach ($this->tag_data as $frame_name => $frame_rawinputdata) {
foreach ($frame_rawinputdata as $irrelevantindex => $source_data_array) {
if (getid3_id3v2::IsValidID3v2FrameName($frame_name, $this->majorversion)) {
unset($frame_length);
unset($frame_flags);
$frame_data = false;
if ($this->ID3v2FrameIsAllowed($frame_name, $source_data_array)) {
if(array_key_exists('description', $source_data_array) && array_key_exists('encodingid', $source_data_array) && array_key_exists('encoding', $this->tag_data)) {
$source_data_array['description'] = getid3_lib::iconv_fallback($this->tag_data['encoding'], $source_data_array['encoding'], $source_data_array['description']);
}
if ($frame_data = $this->GenerateID3v2FrameData($frame_name, $source_data_array)) {
$FrameUnsynchronisation = false;
if ($this->majorversion >= 4) {
$unsynchdata = $frame_data;
if ($this->id3v2_use_unsynchronisation) {
$unsynchdata = $this->Unsynchronise($frame_data);
}
if (strlen($unsynchdata) != strlen($frame_data)) {
$FrameUnsynchronisation = true;
$frame_data = $unsynchdata;
if (isset($TagUnsynchronisation) && $TagUnsynchronisation === false) {
} else {
$TagUnsynchronisation = true;
}
} else {
if (isset($TagUnsynchronisation)) {
$TagUnsynchronisation = false;
}
}
unset($unsynchdata);
$frame_length = getid3_lib::BigEndian2String(strlen($frame_data), 4, true);
} else {
$frame_length = getid3_lib::BigEndian2String(strlen($frame_data), 4, false);
}
$frame_flags = $this->GenerateID3v2FrameFlags($this->ID3v2FrameFlagsLookupTagAlter($frame_name), $this->ID3v2FrameFlagsLookupFileAlter($frame_name), false, false, false, false, $FrameUnsynchronisation, false);
}
} else {
$this->errors[] = 'Frame "'.$frame_name.'" is NOT allowed';
}
if ($frame_data === false) {
$this->errors[] = '$this->GenerateID3v2FrameData() failed for "'.$frame_name.'"';
if ($noerrorsonly) {
return false;
} else {
$frame_name = null;
}
}
} else {
$this->warnings[] = 'Ignoring invalid ID3v2 frame type: "'.$frame_name.'"';
$frame_name = null;
unset($frame_length);
unset($frame_flags);
unset($frame_data);
}
if (null !== $frame_name && isset($frame_length) && isset($frame_flags) && isset($frame_data)) {
$tagstring .= $frame_name.$frame_length.$frame_flags.$frame_data;
}
}
}
if (!isset($TagUnsynchronisation)) {
$TagUnsynchronisation = false;
}
if (($this->majorversion <= 3) && $this->id3v2_use_unsynchronisation) {
$unsynchdata = $this->Unsynchronise($tagstring);
if (strlen($unsynchdata) != strlen($tagstring)) {
$TagUnsynchronisation = true;
$tagstring = $unsynchdata;
}
}
while ($this->paddedlength < (strlen($tagstring) + getid3_id3v2::ID3v2HeaderLength($this->majorversion))) {
$this->paddedlength += 1024;
}
$footer = false;
if (($this->paddedlength > (strlen($tagstring) + getid3_id3v2::ID3v2HeaderLength($this->majorversion)))) {
if (($this->paddedlength - strlen($tagstring) - getid3_id3v2::ID3v2HeaderLength($this->majorversion)) > 0) {
$tagstring .= str_repeat("\x00", $this->paddedlength - strlen($tagstring) - getid3_id3v2::ID3v2HeaderLength($this->majorversion));
}
}
if ($this->id3v2_use_unsynchronisation && (substr($tagstring, strlen($tagstring) - 1, 1) == "\xFF")) {
$TagUnsynchronisation = true;
$tagstring .= "\x00";
}
$tagheader = 'ID3';
$tagheader .= chr($this->majorversion);
$tagheader .= chr($this->minorversion);
$tagheader .= $this->GenerateID3v2TagFlags(array('unsynchronisation'=>$TagUnsynchronisation));
$tagheader .= getid3_lib::BigEndian2String(strlen($tagstring), 4, true);
return $tagheader.$tagstring;
}
$this->errors[] = 'tag_data is not an array in GenerateID3v2Tag()';
return false;
}
public function ID3v2IsValidPriceString($pricestring) {
if (getid3_id3v2::LanguageLookup(substr($pricestring, 0, 3), true) == '') {
return false;
} elseif (!getid3_id3v2::IsANumber(substr($pricestring, 3), true)) {
return false;
}
return true;
}
public function ID3v2FrameFlagsLookupTagAlter($framename) {
switch ($framename) {
case 'RGAD':
$allow = true;
break;
default:
$allow = false;
break;
}
return $allow;
}
public function ID3v2FrameFlagsLookupFileAlter($framename) {
switch ($framename) {
case 'RGAD':
return false;
default:
return false;
}
}
public function ID3v2IsValidETCOevent($eventid) {
if (($eventid < 0) || ($eventid > 0xFF)) {
return false;
} elseif (($eventid >= 0xF0) && ($eventid <= 0xFC)) {
return false;
} elseif (($eventid >= 0x17) && ($eventid <= 0xDF)) {
return false;
} elseif (($eventid >= 0x0E) && ($eventid <= 0x16) && ($this->majorversion == 2)) {
return false;
} elseif (($eventid >= 0x15) && ($eventid <= 0x16) && ($this->majorversion == 3)) {
return false;
}
return true;
}
public function ID3v2IsValidSYLTtype($contenttype) {
if (($contenttype >= 0) && ($contenttype <= 8) && ($this->majorversion == 4)) {
return true;
} elseif (($contenttype >= 0) && ($contenttype <= 6) && ($this->majorversion == 3)) {
return true;
}
return false;
}
public function ID3v2IsValidRVA2channeltype($channeltype) {
if (($channeltype >= 0) && ($channeltype <= 8) && ($this->majorversion == 4)) {
return true;
}
return false;
}
public function ID3v2IsValidAPICpicturetype($picturetype) {
if (($picturetype >= 0) && ($picturetype <= 0x14) && ($this->majorversion >= 2) && ($this->majorversion <= 4)) {
return true;
}
return false;
}
public function ID3v2IsValidAPICimageformat($imageformat) {
if ($imageformat == '-->') {
return true;
} elseif ($this->majorversion == 2) {
if ((strlen($imageformat) == 3) && ($imageformat == strtoupper($imageformat))) {
return true;
}
} elseif (($this->majorversion == 3) || ($this->majorversion == 4)) {
if ($this->IsValidMIMEstring($imageformat)) {
return true;
}
}
return false;
}
public function ID3v2IsValidCOMRreceivedAs($receivedas) {
if (($this->majorversion >= 3) && ($receivedas >= 0) && ($receivedas <= 8)) {
return true;
}
return false;
}
public static function ID3v2IsValidRGADname($RGADname) {
if (($RGADname >= 0) && ($RGADname <= 2)) {
return true;
}
return false;
}
public static function ID3v2IsValidRGADoriginator($RGADoriginator) {
if (($RGADoriginator >= 0) && ($RGADoriginator <= 3)) {
return true;
}
return false;
}
public function ID3v2IsValidTextEncoding($textencodingbyte) {
static $ID3v2IsValidTextEncoding_cache = array(
2 => array(true, true),
3 => array(true, true),
4 => array(true, true, true, true),
);
return isset($ID3v2IsValidTextEncoding_cache[$this->majorversion][$textencodingbyte]);
}
public static function Unsynchronise($data) {
$data = str_replace("\xFF\x00", "\xFF\x00\x00", $data);
$unsyncheddata = '';
$datalength = strlen($data);
for ($i = 0; $i < $datalength; $i++) {
$thischar = $data[$i];
$unsyncheddata .= $thischar;
if ($thischar == "\xFF") {
$nextchar = ord($data[$i + 1]);
if (($nextchar & 0xE0) == 0xE0) {
$unsyncheddata .= "\x00";
}
}
}
return $unsyncheddata;
}
public function is_hash($var) {
if (is_array($var)) {
$keys = array_keys($var);
$all_num = true;
foreach ($keys as $key) {
if (is_string($key)) {
return true;
}
}
}
return false;
}
public function array_join_merge($arr1, $arr2) {
if (is_array($arr1) && is_array($arr2)) {
$new_array = array();
if ($this->is_hash($arr1) && $this->is_hash($arr2)) {
$keys = array_merge(array_keys($arr1), array_keys($arr2));
foreach ($keys as $key) {
$new_array[$key] = $this->array_join_merge((isset($arr1[$key]) ? $arr1[$key] : ''), (isset($arr2[$key]) ? $arr2[$key] : ''));
}
} else {
$new_array = array_reverse(array_unique(array_reverse(array_merge($arr1, $arr2))));
}
return $new_array;
} else {
return $arr2 ? $arr2 : $arr1;
}
}
public static function IsValidMIMEstring($mimestring) {
return preg_match('#^.+/.+$#', $mimestring);
}
public static function IsWithinBitRange($number, $maxbits, $signed=false) {
if ($signed) {
if (($number > (0 - pow(2, $maxbits - 1))) && ($number <= pow(2, $maxbits - 1))) {
return true;
}
} else {
if (($number >= 0) && ($number <= pow(2, $maxbits))) {
return true;
}
}
return false;
}
public static function IsValidEmail($email) {
if (function_exists('filter_var')) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
return preg_match('#^[^ ]+@[a-z\\-\\.]+\\.[a-z]{2,}$#', $email);
}
public static function IsValidURL($url, $allowUserPass=false) {
if ($url == '') {
return false;
}
if ($allowUserPass !== true) {
if (strstr($url, '@')) {
return false;
}
}
return true;
}
public static function safe_parse_url($url) {
$parts = @parse_url($url);
$parts['scheme'] = (isset($parts['scheme']) ? $parts['scheme'] : '');
$parts['host'] = (isset($parts['host']) ? $parts['host'] : '');
$parts['user'] = (isset($parts['user']) ? $parts['user'] : '');
$parts['pass'] = (isset($parts['pass']) ? $parts['pass'] : '');
$parts['path'] = (isset($parts['path']) ? $parts['path'] : '');
$parts['query'] = (isset($parts['query']) ? $parts['query'] : '');
return $parts;
}
public static function ID3v2ShortFrameNameLookup($majorversion, $long_description) {
$long_description = str_replace(' ', '_', strtolower(trim($long_description)));
static $ID3v2ShortFrameNameLookup = array();
if (empty($ID3v2ShortFrameNameLookup)) {
$ID3v2ShortFrameNameLookup[2]['recommended_buffer_size'] = 'BUF';
$ID3v2ShortFrameNameLookup[2]['comment'] = 'COM';
$ID3v2ShortFrameNameLookup[2]['audio_encryption'] = 'CRA';
$ID3v2ShortFrameNameLookup[2]['encrypted_meta_frame'] = 'CRM';
$ID3v2ShortFrameNameLookup[2]['equalisation'] = 'EQU';
$ID3v2ShortFrameNameLookup[2]['event_timing_codes'] = 'ETC';
$ID3v2ShortFrameNameLookup[2]['general_encapsulated_object'] = 'GEO';
$ID3v2ShortFrameNameLookup[2]['involved_people_list'] = 'IPL';
$ID3v2ShortFrameNameLookup[2]['linked_information'] = 'LNK';
$ID3v2ShortFrameNameLookup[2]['music_cd_identifier'] = 'MCI';
$ID3v2ShortFrameNameLookup[2]['mpeg_location_lookup_table'] = 'MLL';
$ID3v2ShortFrameNameLookup[2]['attached_picture'] = 'PIC';
$ID3v2ShortFrameNameLookup[2]['popularimeter'] = 'POP';
$ID3v2ShortFrameNameLookup[2]['reverb'] = 'REV';
$ID3v2ShortFrameNameLookup[2]['relative_volume_adjustment'] = 'RVA';
$ID3v2ShortFrameNameLookup[2]['synchronised_lyric'] = 'SLT';
$ID3v2ShortFrameNameLookup[2]['synchronised_tempo_codes'] = 'STC';
$ID3v2ShortFrameNameLookup[2]['album'] = 'TAL';
$ID3v2ShortFrameNameLookup[2]['beats_per_minute'] = 'TBP';
$ID3v2ShortFrameNameLookup[2]['bpm'] = 'TBP';
$ID3v2ShortFrameNameLookup[2]['composer'] = 'TCM';
$ID3v2ShortFrameNameLookup[2]['genre'] = 'TCO';
$ID3v2ShortFrameNameLookup[2]['part_of_a_compilation'] = 'TCP';
$ID3v2ShortFrameNameLookup[2]['copyright_message'] = 'TCR';
$ID3v2ShortFrameNameLookup[2]['date'] = 'TDA';
$ID3v2ShortFrameNameLookup[2]['playlist_delay'] = 'TDY';
$ID3v2ShortFrameNameLookup[2]['encoded_by'] = 'TEN';
$ID3v2ShortFrameNameLookup[2]['file_type'] = 'TFT';
$ID3v2ShortFrameNameLookup[2]['time'] = 'TIM';
$ID3v2ShortFrameNameLookup[2]['initial_key'] = 'TKE';
$ID3v2ShortFrameNameLookup[2]['language'] = 'TLA';
$ID3v2ShortFrameNameLookup[2]['length'] = 'TLE';
$ID3v2ShortFrameNameLookup[2]['media_type'] = 'TMT';
$ID3v2ShortFrameNameLookup[2]['original_artist'] = 'TOA';
$ID3v2ShortFrameNameLookup[2]['original_filename'] = 'TOF';
$ID3v2ShortFrameNameLookup[2]['original_lyricist'] = 'TOL';
$ID3v2ShortFrameNameLookup[2]['original_year'] = 'TOR';
$ID3v2ShortFrameNameLookup[2]['original_album'] = 'TOT';
$ID3v2ShortFrameNameLookup[2]['artist'] = 'TP1';
$ID3v2ShortFrameNameLookup[2]['band'] = 'TP2';
$ID3v2ShortFrameNameLookup[2]['conductor'] = 'TP3';
$ID3v2ShortFrameNameLookup[2]['remixer'] = 'TP4';
$ID3v2ShortFrameNameLookup[2]['part_of_a_set'] = 'TPA';
$ID3v2ShortFrameNameLookup[2]['publisher'] = 'TPB';
$ID3v2ShortFrameNameLookup[2]['isrc'] = 'TRC';
$ID3v2ShortFrameNameLookup[2]['recording_dates'] = 'TRD';
$ID3v2ShortFrameNameLookup[2]['tracknumber'] = 'TRK';
$ID3v2ShortFrameNameLookup[2]['track_number'] = 'TRK';
$ID3v2ShortFrameNameLookup[2]['album_artist_sort_order'] = 'TS2';
$ID3v2ShortFrameNameLookup[2]['album_sort_order'] = 'TSA';
$ID3v2ShortFrameNameLookup[2]['composer_sort_order'] = 'TSC';
$ID3v2ShortFrameNameLookup[2]['size'] = 'TSI';
$ID3v2ShortFrameNameLookup[2]['performer_sort_order'] = 'TSP';
$ID3v2ShortFrameNameLookup[2]['encoder_settings'] = 'TSS';
$ID3v2ShortFrameNameLookup[2]['title_sort_order'] = 'TST';
$ID3v2ShortFrameNameLookup[2]['content_group_description'] = 'TT1';
$ID3v2ShortFrameNameLookup[2]['title'] = 'TT2';
$ID3v2ShortFrameNameLookup[2]['subtitle'] = 'TT3';
$ID3v2ShortFrameNameLookup[2]['lyricist'] = 'TXT';
$ID3v2ShortFrameNameLookup[2]['text'] = 'TXX';
$ID3v2ShortFrameNameLookup[2]['year'] = 'TYE';
$ID3v2ShortFrameNameLookup[2]['unique_file_identifier'] = 'UFI';
$ID3v2ShortFrameNameLookup[2]['unsynchronised_lyric'] = 'ULT';
$ID3v2ShortFrameNameLookup[2]['url_file'] = 'WAF';
$ID3v2ShortFrameNameLookup[2]['url_artist'] = 'WAR';
$ID3v2ShortFrameNameLookup[2]['url_source'] = 'WAS';
$ID3v2ShortFrameNameLookup[2]['commercial_information'] = 'WCM';
$ID3v2ShortFrameNameLookup[2]['copyright'] = 'WCP';
$ID3v2ShortFrameNameLookup[2]['url_publisher'] = 'WPB';
$ID3v2ShortFrameNameLookup[2]['url_user'] = 'WXX';
$ID3v2ShortFrameNameLookup[3]['audio_encryption'] = 'AENC';
$ID3v2ShortFrameNameLookup[3]['attached_picture'] = 'APIC';
$ID3v2ShortFrameNameLookup[3]['picture'] = 'APIC';
$ID3v2ShortFrameNameLookup[3]['comment'] = 'COMM';
$ID3v2ShortFrameNameLookup[3]['commercial_frame'] = 'COMR';
$ID3v2ShortFrameNameLookup[3]['encryption_method_registration'] = 'ENCR';
$ID3v2ShortFrameNameLookup[3]['event_timing_codes'] = 'ETCO';
$ID3v2ShortFrameNameLookup[3]['general_encapsulated_object'] = 'GEOB';
$ID3v2ShortFrameNameLookup[3]['group_identification_registration'] = 'GRID';
$ID3v2ShortFrameNameLookup[3]['linked_information'] = 'LINK';
$ID3v2ShortFrameNameLookup[3]['music_cd_identifier'] = 'MCDI';
$ID3v2ShortFrameNameLookup[3]['mpeg_location_lookup_table'] = 'MLLT';
$ID3v2ShortFrameNameLookup[3]['ownership_frame'] = 'OWNE';
$ID3v2ShortFrameNameLookup[3]['play_counter'] = 'PCNT';
$ID3v2ShortFrameNameLookup[3]['popularimeter'] = 'POPM';
$ID3v2ShortFrameNameLookup[3]['position_synchronisation_frame'] = 'POSS';
$ID3v2ShortFrameNameLookup[3]['private_frame'] = 'PRIV';
$ID3v2ShortFrameNameLookup[3]['recommended_buffer_size'] = 'RBUF';
$ID3v2ShortFrameNameLookup[3]['replay_gain_adjustment'] = 'RGAD';
$ID3v2ShortFrameNameLookup[3]['reverb'] = 'RVRB';
$ID3v2ShortFrameNameLookup[3]['synchronised_lyric'] = 'SYLT';
$ID3v2ShortFrameNameLookup[3]['synchronised_tempo_codes'] = 'SYTC';
$ID3v2ShortFrameNameLookup[3]['album'] = 'TALB';
$ID3v2ShortFrameNameLookup[3]['beats_per_minute'] = 'TBPM';
$ID3v2ShortFrameNameLookup[3]['bpm'] = 'TBPM';
$ID3v2ShortFrameNameLookup[3]['part_of_a_compilation'] = 'TCMP';
$ID3v2ShortFrameNameLookup[3]['composer'] = 'TCOM';
$ID3v2ShortFrameNameLookup[3]['genre'] = 'TCON';
$ID3v2ShortFrameNameLookup[3]['copyright_message'] = 'TCOP';
$ID3v2ShortFrameNameLookup[3]['playlist_delay'] = 'TDLY';
$ID3v2ShortFrameNameLookup[3]['encoded_by'] = 'TENC';
$ID3v2ShortFrameNameLookup[3]['lyricist'] = 'TEXT';
$ID3v2ShortFrameNameLookup[3]['file_type'] = 'TFLT';
$ID3v2ShortFrameNameLookup[3]['content_group_description'] = 'TIT1';
$ID3v2ShortFrameNameLookup[3]['title'] = 'TIT2';
$ID3v2ShortFrameNameLookup[3]['subtitle'] = 'TIT3';
$ID3v2ShortFrameNameLookup[3]['initial_key'] = 'TKEY';
$ID3v2ShortFrameNameLookup[3]['language'] = 'TLAN';
$ID3v2ShortFrameNameLookup[3]['length'] = 'TLEN';
$ID3v2ShortFrameNameLookup[3]['media_type'] = 'TMED';
$ID3v2ShortFrameNameLookup[3]['original_album'] = 'TOAL';
$ID3v2ShortFrameNameLookup[3]['original_filename'] = 'TOFN';
$ID3v2ShortFrameNameLookup[3]['original_lyricist'] = 'TOLY';
$ID3v2ShortFrameNameLookup[3]['original_artist'] = 'TOPE';
$ID3v2ShortFrameNameLookup[3]['file_owner'] = 'TOWN';
$ID3v2ShortFrameNameLookup[3]['artist'] = 'TPE1';
$ID3v2ShortFrameNameLookup[3]['band'] = 'TPE2';
$ID3v2ShortFrameNameLookup[3]['conductor'] = 'TPE3';
$ID3v2ShortFrameNameLookup[3]['remixer'] = 'TPE4';
$ID3v2ShortFrameNameLookup[3]['part_of_a_set'] = 'TPOS';
$ID3v2ShortFrameNameLookup[3]['publisher'] = 'TPUB';
$ID3v2ShortFrameNameLookup[3]['tracknumber'] = 'TRCK';
$ID3v2ShortFrameNameLookup[3]['track_number'] = 'TRCK';
$ID3v2ShortFrameNameLookup[3]['internet_radio_station_name'] = 'TRSN';
$ID3v2ShortFrameNameLookup[3]['internet_radio_station_owner'] = 'TRSO';
$ID3v2ShortFrameNameLookup[3]['album_artist_sort_order'] = 'TSO2';
$ID3v2ShortFrameNameLookup[3]['album_sort_order'] = 'TSOA';
$ID3v2ShortFrameNameLookup[3]['composer_sort_order'] = 'TSOC';
$ID3v2ShortFrameNameLookup[3]['performer_sort_order'] = 'TSOP';
$ID3v2ShortFrameNameLookup[3]['title_sort_order'] = 'TSOT';
$ID3v2ShortFrameNameLookup[3]['isrc'] = 'TSRC';
$ID3v2ShortFrameNameLookup[3]['encoder_settings'] = 'TSSE';
$ID3v2ShortFrameNameLookup[3]['text'] = 'TXXX';
$ID3v2ShortFrameNameLookup[3]['unique_file_identifier'] = 'UFID';
$ID3v2ShortFrameNameLookup[3]['terms_of_use'] = 'USER';
$ID3v2ShortFrameNameLookup[3]['unsynchronised_lyric'] = 'USLT';
$ID3v2ShortFrameNameLookup[3]['commercial_information'] = 'WCOM';
$ID3v2ShortFrameNameLookup[3]['copyright'] = 'WCOP';
$ID3v2ShortFrameNameLookup[3]['url_file'] = 'WOAF';
$ID3v2ShortFrameNameLookup[3]['url_artist'] = 'WOAR';
$ID3v2ShortFrameNameLookup[3]['url_source'] = 'WOAS';
$ID3v2ShortFrameNameLookup[3]['url_station'] = 'WORS';
$ID3v2ShortFrameNameLookup[3]['url_payment'] = 'WPAY';
$ID3v2ShortFrameNameLookup[3]['url_publisher'] = 'WPUB';
$ID3v2ShortFrameNameLookup[3]['url_user'] = 'WXXX';
$ID3v2ShortFrameNameLookup[4] = $ID3v2ShortFrameNameLookup[3];
$ID3v2ShortFrameNameLookup[3]['equalisation'] = 'EQUA';
$ID3v2ShortFrameNameLookup[3]['involved_people_list'] = 'IPLS';
$ID3v2ShortFrameNameLookup[3]['relative_volume_adjustment'] = 'RVAD';
$ID3v2ShortFrameNameLookup[3]['date'] = 'TDAT';
$ID3v2ShortFrameNameLookup[3]['time'] = 'TIME';
$ID3v2ShortFrameNameLookup[3]['original_year'] = 'TORY';
$ID3v2ShortFrameNameLookup[3]['recording_dates'] = 'TRDA';
$ID3v2ShortFrameNameLookup[3]['size'] = 'TSIZ';
$ID3v2ShortFrameNameLookup[3]['year'] = 'TYER';
$ID3v2ShortFrameNameLookup[4]['audio_seek_point_index'] = 'ASPI';
$ID3v2ShortFrameNameLookup[4]['equalisation'] = 'EQU2';
$ID3v2ShortFrameNameLookup[4]['relative_volume_adjustment'] = 'RVA2';
$ID3v2ShortFrameNameLookup[4]['seek_frame'] = 'SEEK';
$ID3v2ShortFrameNameLookup[4]['signature_frame'] = 'SIGN';
$ID3v2ShortFrameNameLookup[4]['encoding_time'] = 'TDEN';
$ID3v2ShortFrameNameLookup[4]['original_release_time'] = 'TDOR';
$ID3v2ShortFrameNameLookup[4]['recording_time'] = 'TDRC';
$ID3v2ShortFrameNameLookup[4]['release_time'] = 'TDRL';
$ID3v2ShortFrameNameLookup[4]['tagging_time'] = 'TDTG';
$ID3v2ShortFrameNameLookup[4]['involved_people_list'] = 'TIPL';
$ID3v2ShortFrameNameLookup[4]['musician_credits_list'] = 'TMCL';
$ID3v2ShortFrameNameLookup[4]['mood'] = 'TMOO';
$ID3v2ShortFrameNameLookup[4]['produced_notice'] = 'TPRO';
$ID3v2ShortFrameNameLookup[4]['album_sort_order'] = 'TSOA';
$ID3v2ShortFrameNameLookup[4]['performer_sort_order'] = 'TSOP';
$ID3v2ShortFrameNameLookup[4]['title_sort_order'] = 'TSOT';
$ID3v2ShortFrameNameLookup[4]['set_subtitle'] = 'TSST';
$ID3v2ShortFrameNameLookup[4]['year'] = 'TDRC';
}
return (isset($ID3v2ShortFrameNameLookup[$majorversion][strtolower($long_description)]) ? $ID3v2ShortFrameNameLookup[$majorversion][strtolower($long_description)] : '');
}
}