Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

write.id3v2.php 107KB

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