diff options
Diffstat (limited to 'modules')
79 files changed, 2433 insertions, 2433 deletions
diff --git a/modules/captcha/captcha.php b/modules/captcha/captcha.php index 4ecad8bc..c23be57e 100644 --- a/modules/captcha/captcha.php +++ b/modules/captcha/captcha.php @@ -24,26 +24,26 @@ This library operates CAPTCHA form submissions, to block spam bots and alike. It is easy to hook into existing web sites and scripts. It also tries to be "smart" and more user-friendly. - + While the operation logic and identifier processing are extremley safe, this is a "weak" implementation. Specifically targetted and tweaked OCR software could overcome the visual riddle. And if enabled, the textual or mathematical riddles are rather simple to overcome if attacked. Generic spambots are however blocked already with the default settings. - + PRINT captcha::form() emits the img and input fields for inclusion into your submit <form> - + IF (captcha::solved()) tests for a correctly entered solution on submit, returns true if ok - + Temporary files are created for tracking, verification and basic data storage, but will get automatically removed once a CAPTCHA was solved to prevent replay attacks. Additionally this library uses "AJAX" super powers *lol* to enhance usability. And a short-lasting session cookie is also added site-wide, so users may only have to solve the captcha once (can be disabled, because that's also just security by obscurity). - + Public Domain, available via http://freshmeat.net/p/captchaphp */ @@ -143,7 +143,7 @@ class easy_captcha { srand(microtime() + time()/2 - 21017); if ($this->id) { $this->prev[] = $this->id; } $this->id = $this->new_id(); - + #-- meta informations $this->created = time(); $this->{'created$'} = gmdate("r", $this->created); @@ -160,13 +160,13 @@ class easy_captcha { $this->failures = 0; $this->shortcut = array(); $this->grant = 0; // unchecked access - + #-- mk IMAGE/GRAPHIC $this->image = (CAPTCHA_IMAGE_TYPE <= 1) ? new easy_captcha_graphic_image_waved() : new easy_captcha_graphic_image_disturbed(); //$this->image = new easy_captcha_graphic_cute_ponys(); - + #-- mk MATH/TEXT riddle $this->text = (CAPTCHA_NOTEXT >= 1) ? new easy_captcha_text_disable() @@ -181,11 +181,11 @@ class easy_captcha { if (CAPTCHA_NEW_URLS) $this->shortcut[] = new easy_captcha_spamfree_no_new_urls(); - #-- store record + #-- store record $this->save(); } - - + + #-- examine if captcha data is fresh function is_valid() { return isset($this->id) && ($this->created) @@ -212,11 +212,11 @@ class easy_captcha { // log, this is either a frustrated user or a bot knocking $this->log("::solved", "INVALID", "tries exhausted ($this->tries) or expired(?) captcha"); } - + #-- test elseif ($this->sent) { $in = $_REQUEST[CAPTCHA_PARAM_INPUT]; // might be empty string - + #-- check individual modules $ok = $this->grant; foreach ($this->shortcut as $test) { @@ -225,12 +225,12 @@ class easy_captcha { $ok = $ok // either letters or math formula submitted || isset($this->image) && $this->image->solved($in) || isset($this->text) && $this->text->solved($in); - + #-- update state if ($ok) { $this->passed++; $this->log("::solved", "OKAY", "captcha passed ($in) for image({$this->image->solution}) and text({$this->text->solution})"); - + #-- set cookie on success if (CAPTCHA_PERSISTENT) { $this->shortcut[0/*FIXME*/]->grant(); @@ -255,15 +255,15 @@ class easy_captcha { #-- return result return($ok); } - - + + #-- combines ->image and ->text data into form fields function form($add_text="") { #-- store object data $this->sent++; $this->save(); - + #-- prepare output vars $p_id = CAPTCHA_PARAM_ID; $p_input = CAPTCHA_PARAM_INPUT; @@ -331,7 +331,7 @@ class easy_captcha { fclose($f); } } - + #-- remove $this data file function delete() { // delete current and all previous data files @@ -347,7 +347,7 @@ class easy_captcha { } return(FALSE); // far if-chaining in ->is_valid() } - + #-- clean-up or init temporary directory function straighten_temp_dir() { // create dir @@ -377,7 +377,7 @@ class easy_captcha { $pfix = (int) (time() / $length*CAPTCHA_TIMEOUT) + $dtime; return md5("captcha::$pfix:$text::".__FILE__.":$_SERVER[SERVER_NAME]:80"); } - + } @@ -493,7 +493,7 @@ class easy_captcha_graphic extends easy_captcha_fuzzy { class easy_captcha_graphic_image_waved extends easy_captcha_graphic { - /* returns jpeg file stream with unscannable letters encoded + /* returns jpeg file stream with unscannable letters encoded in front of colorful disturbing background */ function jpeg() { @@ -537,7 +537,7 @@ class easy_captcha_graphic_image_waved extends easy_captcha_graphic { imageline($this->img, 0, $x, 250, $x, 0x333333); } } - + #-- add lines function fog() { $num = rand(10,25); @@ -556,7 +556,7 @@ class easy_captcha_graphic_image_waved extends easy_captcha_graphic { imagesetthickness($this->img, 1); } - + #-- distortion: wave-transform function distort() { @@ -567,7 +567,7 @@ class easy_captcha_graphic_image_waved extends easy_captcha_graphic { $height = $this->height; $i = & $this->img; $dest = imagecreatetruecolor($width, $height); - + #-- URL param ?hires=1 influences used drawing scheme if (isset($_GET["hires"])) { $single_pixel = 0; @@ -584,7 +584,7 @@ class easy_captcha_graphic_image_waved extends easy_captcha_graphic { #-- pixel movement list($dx, $dy) = $wave->dxy($x, $y); // x- and y- sinus wave // list($qx, $qy) = $spike->dxy($x, $y); - + #-- get source pixel, paint dest if ($single_pixel) { // single source dot: one-to-one duplicate (unsmooth, hard edges) @@ -605,10 +605,10 @@ class easy_captcha_graphic_image_waved extends easy_captcha_graphic { } #-- simply overwrite ->img - imagedestroy($i); + imagedestroy($i); $this->img = $dest; } - + #-- get 4 pixels from source image, merges BLUE value simply function get_2x2_greyscale(&$i, $x, $y) { // this is pretty simplistic method, actually adds more artefacts @@ -627,7 +627,7 @@ class easy_captcha_graphic_image_waved extends easy_captcha_graphic { // get R,G,B values from 2x2 source area $c00 = $this->get_RGB($i, $x, $y); // +------+------+ $c01 = $this->get_RGB($i, $x, $y+1); // |dx,dy | x1,y0| - $c10 = $this->get_RGB($i, $x+1, $y); // | rx-> | | + $c10 = $this->get_RGB($i, $x+1, $y); // | rx-> | | $c11 = $this->get_RGB($i, $x+1, $y+1); // +----##+------+ // weighting by $dx/$dy fraction part // | ##|<-ry | $rx = $x - floor($x); $rx_ = 1 - $rx; // |x0,y1 | x1,y1| @@ -674,7 +674,7 @@ class easy_captcha_dxy_wave { $this->slow_x = $this->real_rand(7.5, 20.0); // =wave-width in pixel/3 $this->slow_y = $this->real_rand(7.5, 15.0); } - + #-- calculate source pixel position with overlapping sinus x/y-displacement function dxy($x, $y) { #-- adapting params @@ -686,7 +686,7 @@ class easy_captcha_dxy_wave { #-- result return array($dx, $dy); } - + #-- array of values with random start/end values function from_to_rand($max, $a, $b) { $BEG = $this->real_rand($a, $b); @@ -726,7 +726,7 @@ class easy_captcha_dxy_spike { class easy_captcha_graphic_image_disturbed extends easy_captcha_graphic { - /* returns jpeg file stream with unscannable letters encoded + /* returns jpeg file stream with unscannable letters encoded in front of colorful disturbing background */ function jpeg() { @@ -743,7 +743,7 @@ class easy_captcha_graphic_image_disturbed extends easy_captcha_graphic { function create() { $this->img = imagecreatetruecolor($this->width, $this->height); imagefilledrectangle($this->img, 0,0, $this->width,$this->height, $this->random_color(222, 255)); - + #-- encolour bg $wd = 20; $x = 0; @@ -752,7 +752,7 @@ class easy_captcha_graphic_image_disturbed extends easy_captcha_graphic { $wd += max(10, rand(0, 20) - 10); } } - + #-- make interesting background I, lines function background_lines() { @@ -777,8 +777,8 @@ class easy_captcha_graphic_image_disturbed extends easy_captcha_graphic { } } } - - + + #-- more disturbing II, random letters function background_letters() { $limit = rand(30,90); @@ -795,7 +795,7 @@ class easy_captcha_graphic_image_disturbed extends easy_captcha_graphic { imagettftext($this->img, $size, $rotation, $x, $y, $this->random_color(130, 240), $this->font(), $letter); } } - + #-- add the real text to it function text() { @@ -905,7 +905,7 @@ class easy_captcha_persistent_grant extends easy_captcha { function easy_captcha_persistent_grant() { } - + #-- give ok, if captach had already been solved recently function solved($ignore=0) { @@ -913,7 +913,7 @@ class easy_captcha_persistent_grant extends easy_captcha { return in_array($_COOKIE[$this->cookie()], array($this->validity_token(), $this->validity_token(-1))); } } - + #-- set captcha persistence cookie function grant() { if (!headers_sent()) { @@ -986,7 +986,7 @@ class easy_captcha_utility { #-- JS-RPC request, check entered solution on the fly if ($test = @$_REQUEST[CAPTCHA_PARAM_INPUT]) { - + #-- check if ($expired) { } @@ -1000,7 +1000,7 @@ class easy_captcha_utility { } #-- generate and send image file - else { + else { if ($expired) { $type = "image/png"; $bin = easy_captcha_utility::expired_png(); @@ -1043,7 +1043,7 @@ class easy_captcha_utility { /* easy_captcha utility code */ // global vars -captcha_url_rx = /(https?:\/\/\w[^\/,\]\[=#]+)/ig; // +captcha_url_rx = /(https?:\/\/\w[^\/,\]\[=#]+)/ig; // captcha_form_urls = new Array(); captcha_sol_cb = ""; captcha_rpc = 0; diff --git a/modules/emulator/gettext.php b/modules/emulator/gettext.php index f24aa190..e62cdcc6 100644 --- a/modules/emulator/gettext.php +++ b/modules/emulator/gettext.php @@ -89,12 +89,12 @@ if (!function_exists("gettext")) { #-- give out whatever we have return($msg); } - + #-- return plural form array index for algorithm type # (compacted from C expression string beforehand) function gettext___plural_guess(&$type, $n) { - + #-- guess from string with C expression and set integer shorthand if (is_string($type)) { if (($type == "nplurals=1;plural=0;") || !strlen($type)) { @@ -221,7 +221,7 @@ if (!function_exists("gettext")) { . @$_ENV['LC_MESSAGE'] .',' . @$_ENV['LANG'] . ',' . @$_GETTEXT['%locale'] . ',' . @$_SERVER['HTTP_ACCEPT_LANGUAGE'] . ',C,en'; - + #-- add shortened language codes (en_UK.UTF-8 -> + en_UK, en) foreach (explode(',', $langs) as $d) { $d = trim($d); @@ -258,7 +258,7 @@ if (!function_exists("gettext")) { } } }//foreach - + #-- extract headers if ($head = $_GETTEXT[$domain][""]) { foreach (explode("\n", $head) as $line) { @@ -266,7 +266,7 @@ if (!function_exists("gettext")) { $line = trim(strtok("\n")); $_GETTEXT[$domain]['%po-header'][strtolower($header)] = $line; } - + #-- plural-forms header if (function_exists("gettext___plural_guess") and ($h = @$_GETTEXT[$domain]['%po-header']["plural-forms"])) @@ -336,7 +336,7 @@ if (!function_exists("gettext")) { global $_GETTEXT; $c_esc = array("\\n"=>"\n", "\\r"=>"\r", "\\\\"=>"\\", "\\f"=>"\f", "\\t"=>"\t", "\\"=>""); - #-- read line-wise from text file + #-- read line-wise from text file do { $line = trim(fgets($f)); diff --git a/modules/flash/xspf_player.php b/modules/flash/xspf_player.php index a2598372..c6228fdb 100644 --- a/modules/flash/xspf_player.php +++ b/modules/flash/xspf_player.php @@ -23,7 +23,7 @@ require_once '../../lib/init.php'; // Switch on actions -switch ($_REQUEST['action']) { +switch ($_REQUEST['action']) { default: case 'tmp_playlist': // Set for hackage! diff --git a/modules/getid3/extension.cache.dbm.php b/modules/getid3/extension.cache.dbm.php index 03e4a9e8..aa5092e4 100644 --- a/modules/getid3/extension.cache.dbm.php +++ b/modules/getid3/extension.cache.dbm.php @@ -34,7 +34,7 @@ * require_once 'getid3/getid3.php'; * $getid3 = new getid3; * $getid3->encoding = 'UTF-8'; -* try { +* try { * $info1 = $getid3->Analyse('file1.flac'); * $info2 = $getid3->Analyse('file2.wv'); * .... diff --git a/modules/getid3/extension.cache.mysql.php b/modules/getid3/extension.cache.mysql.php index 1275c25e..f8dac5a2 100644 --- a/modules/getid3/extension.cache.mysql.php +++ b/modules/getid3/extension.cache.mysql.php @@ -34,7 +34,7 @@ * require_once 'getid3/getid3.php'; * $getid3 = new getid3; * $getid3->encoding = 'UTF-8'; -* try { +* try { * $info1 = $getid3->Analyse('file1.flac'); * $info2 = $getid3->Analyse('file2.wv'); * .... diff --git a/modules/getid3/module.archive.gzip.php b/modules/getid3/module.archive.gzip.php index ed03abf5..84fae9ef 100644 --- a/modules/getid3/module.archive.gzip.php +++ b/modules/getid3/module.archive.gzip.php @@ -24,15 +24,15 @@ // // $Id: module.archive.gzip.php,v 1.4 2006/12/04 16:00:35 ah Exp $ - - + + class getid3_gzip extends getid3_handler { // public: Optional file list - disable for speed. public $option_gzip_parse_contents = true; // decode gzipped files, if possible, and parse recursively (.tar.gz for example) - + // Reads the gzip-file function Analyze() { @@ -42,16 +42,16 @@ class getid3_gzip extends getid3_handler $start_length = 10; $unpack_header = 'a1id1/a1id2/a1cmethod/a1flags/a4mtime/a1xflags/a1os'; - + //+---+---+---+---+---+---+---+---+---+---+ //|ID1|ID2|CM |FLG| MTIME |XFL|OS | //+---+---+---+---+---+---+---+---+---+---+ - + @fseek($this->getid3->fp, 0); $buffer = @fread($this->getid3->fp, $info['filesize']); $arr_members = explode("\x1F\x8B\x08", $buffer); - + while (true) { $is_wrong_members = false; $num_members = intval(count($arr_members)); @@ -63,7 +63,7 @@ class getid3_gzip extends getid3_handler $attr = unpack($unpack_header, substr($buf, 0, $start_length)); if (!$this->get_os_type(ord($attr['os']))) { - + // Merge member with previous if wrong OS type $arr_members[$i - 1] .= $buf; $arr_members[$i] = ''; @@ -110,24 +110,24 @@ class getid3_gzip extends getid3_handler $fpointer = 10; $arr_xsubfield = array (); - + // bit 2 - FLG.FEXTRA //+---+---+=================================+ //| XLEN |...XLEN bytes of "extra field"...| //+---+---+=================================+ - + if ($info_gzip_member_header_idx['flags']['extra']) { $w_xlen = substr($buff, $fpointer, 2); $xlen = getid3_lib::LittleEndian2Int($w_xlen); $fpointer += 2; $info_gzip_member_header_idx['raw']['xfield'] = substr($buff, $fpointer, $xlen); - + // Extra SubFields //+---+---+---+---+==================================+ //|SI1|SI2| LEN |... LEN bytes of subfield data ...| //+---+---+---+---+==================================+ - + $idx = 0; while (true) { if ($idx >= $xlen) { @@ -147,13 +147,13 @@ class getid3_gzip extends getid3_handler } $fpointer += $xlen; } - + // bit 3 - FLG.FNAME //+=========================================+ //|...original file name, zero-terminated...| //+=========================================+ // GZIP files may have only one file, with no filename, so assume original filename is current filename without .gz - + $info_gzip_member_header_idx['filename'] = preg_replace('/.gz$/', '', @$info['filename']); if ($info_gzip_member_header_idx['flags']['filename']) { while (true) { @@ -165,12 +165,12 @@ class getid3_gzip extends getid3_handler $fpointer++; } } - + // bit 4 - FLG.FCOMMENT //+===================================+ //|...file comment, zero-terminated...| //+===================================+ - + if ($info_gzip_member_header_idx['flags']['comment']) { while (true) { if (ord($buff[$fpointer]) == 0) { @@ -181,18 +181,18 @@ class getid3_gzip extends getid3_handler $fpointer++; } } - + // bit 1 - FLG.FHCRC //+---+---+ //| CRC16 | //+---+---+ - + if ($info_gzip_member_header_idx['flags']['crc16']) { $w_crc = substr($buff, $fpointer, 2); $info_gzip_member_header_idx['crc16'] = getid3_lib::LittleEndian2Int($w_crc); $fpointer += 2; } - + // bit 0 - FLG.FTEXT //if ($info_gzip_member_header_idx['raw']['flags'] & 0x01) { // Ignored... @@ -205,7 +205,7 @@ class getid3_gzip extends getid3_handler if ($this->option_gzip_parse_contents) { // Try to inflate GZip - + if (!function_exists('gzinflate')) { $this->getid3->warning('PHP does not have zlib support - contents not parsed.'); return true; @@ -223,9 +223,9 @@ class getid3_gzip extends getid3_handler // Calculate CRC32 for inflated content $info_gzip_member_header_idx['crc32_valid'] = (bool) (sprintf('%u', crc32($inflated)) == $info_gzip_member_header_idx['crc32']); - + //// Analyse contents - + // write content to temp file if (($temp_file_name = tempnam('*', 'getID3')) === false) { throw new getid3_exception('Unable to create temporary file.'); @@ -234,7 +234,7 @@ class getid3_gzip extends getid3_handler if ($tmp = fopen($temp_file_name, 'wb')) { fwrite($tmp, $inflated); fclose($tmp); - + // clone getid3 - we want same settings $clone = clone $this->getid3; unset($clone->info); @@ -245,13 +245,13 @@ class getid3_gzip extends getid3_handler catch (getid3_exception $e) { // unable to parse contents } - + unlink($temp_file_name); } - - // Unknown/unhandled format + + // Unknown/unhandled format else { - + } } } @@ -291,7 +291,7 @@ class getid3_gzip extends getid3_handler ); return @$xflag_type[$key]; } - + } ?> diff --git a/modules/getid3/module.archive.szip.php b/modules/getid3/module.archive.szip.php index f8f71dba..c0beea25 100644 --- a/modules/getid3/module.archive.szip.php +++ b/modules/getid3/module.archive.szip.php @@ -22,20 +22,20 @@ //
// $Id: module.archive.szip.php,v 1.2 2006/11/02 10:48:00 ah Exp $ - - + + class getid3_szip extends getid3_handler { public function Analyze() { - + $getid3 = $this->getid3; fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $szip_rkau = fread($getid3->fp, 6); - + // Magic bytes: 'SZ'."\x0A\x04" - + $getid3->info['fileformat'] = 'szip'; $getid3->info['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($szip_rkau, 4, 1)); diff --git a/modules/getid3/module.archive.tar.php b/modules/getid3/module.archive.tar.php index cf106794..a629adeb 100644 --- a/modules/getid3/module.archive.tar.php +++ b/modules/getid3/module.archive.tar.php @@ -24,8 +24,8 @@ // // $Id: module.archive.tar.php,v 1.2 2006/11/02 10:48:00 ah Exp $ - - + + class getid3_tar extends getid3_handler { @@ -36,9 +36,9 @@ class getid3_tar extends getid3_handler $info['fileformat'] = 'tar'; $fp = $this->getid3->fp; - + fseek($fp, 0); - + $unpack_header = 'a100fname/a8mode/a8uid/a8gid/a12size/a12mtime/a8chksum/a1typflag/a100lnkname/a6magic/a2ver/a32uname/a32gname/a8devmaj/a8devmin/a155/prefix'; $null_512k = str_repeat("\0", 512); // end-of-file marker @@ -46,9 +46,9 @@ class getid3_tar extends getid3_handler $already_warned = false; while (!feof($fp)) { - + $buffer = fread($fp, 512); - + // check the block $checksum = 0; for ($i = 0; $i < 148; $i++) { @@ -93,24 +93,24 @@ class getid3_tar extends getid3_handler } } } - + if ($prefix) { $name = $prefix.'/'.$name; } if ((preg_match('#/$#', $name)) && !$name) { $typeflag = 5; } - + // If it's the end of the tar-file... if ($buffer == $null_512k) { break; } - + // Protect against tar-files with garbage at the end if ($name == '') { break; } - + $info['tar']['file_details'][$name] = array ( 'name' => $name, 'mode_raw' => $mode, @@ -129,7 +129,7 @@ class getid3_tar extends getid3_handler 'devmajor' => $devmaj, 'devminor' => $devmin ); - + // Skip the next chunk fseek($fp, $size, SEEK_CUR); @@ -137,7 +137,7 @@ class getid3_tar extends getid3_handler if ($size % 512) { fseek($fp, 512 - $diff, SEEK_CUR); } - + } return true; } @@ -226,7 +226,7 @@ class getid3_tar extends getid3_handler return @$flag_types[$typflag]; } - + } ?>
\ No newline at end of file diff --git a/modules/getid3/module.archive.zip.php b/modules/getid3/module.archive.zip.php index 72d94f41..adeb07b4 100644 --- a/modules/getid3/module.archive.zip.php +++ b/modules/getid3/module.archive.zip.php @@ -30,12 +30,12 @@ class getid3_zip extends getid3_handler public function Analyze() { $getid3 = $this->getid3; - + $getid3->info['zip'] = array (); $info_zip = &$getid3->info['zip']; - + $getid3->info['fileformat'] = 'zip'; - + $info_zip['encoding'] = 'ISO-8859-1'; $info_zip['files'] = array (); $info_zip['compressed_size'] = $info_zip['uncompressed_size'] = $info_zip['entries_count'] = 0; @@ -97,22 +97,22 @@ class getid3_zip extends getid3_handler } throw new getid3_exception('Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete'); } - + //throw new getid3_exception('Cannot find End Of Central Directory (truncated file?)'); } private function getZIPHeaderFilepointerTopDown() { - + // shortcut $getid3 = $this->getid3; - + $getid3->info['fileformat'] = 'zip'; - + $getid3->info['zip'] = array (); $info_zip['compressed_size'] = $info_zip['uncompressed_size'] = $info_zip['entries_count'] = 0; - + rewind($getid3->fp); while ($fileentry = $this->ZIPparseLocalFileHeader()) { $info_zip['entries'][] = $fileentry; @@ -149,10 +149,10 @@ class getid3_zip extends getid3_handler private function getZIPentriesFilepointer() { - + // shortcut $getid3 = $this->getid3; - + $getid3->info['zip'] = array (); $info_zip['compressed_size'] = $info_zip['uncompressed_size'] = $info_zip['entries_count'] = 0; @@ -173,36 +173,36 @@ class getid3_zip extends getid3_handler private function ZIPparseLocalFileHeader() { - + // shortcut $getid3 = $this->getid3; $local_file_header['offset'] = ftell($getid3->fp); - + $zip_local_file_header = fread($getid3->fp, 30); $local_file_header['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($zip_local_file_header, 0, 4)); - + // Invalid Local File Header Signature if ($local_file_header['raw']['signature'] != 0x04034B50) { fseek($getid3->fp, $local_file_header['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly return false; } - - getid3_lib::ReadSequence('LittleEndian2Int', $local_file_header['raw'], $zip_local_file_header, 4, + + getid3_lib::ReadSequence('LittleEndian2Int', $local_file_header['raw'], $zip_local_file_header, 4, array ( - 'extract_version' => 2, - 'general_flags' => 2, - 'compression_method' => 2, - 'last_mod_file_time' => 2, - 'last_mod_file_date' => 2, - 'crc_32' => 2, - 'compressed_size' => 2, - 'uncompressed_size' => 2, - 'filename_length' => 2, + 'extract_version' => 2, + 'general_flags' => 2, + 'compression_method' => 2, + 'last_mod_file_time' => 2, + 'last_mod_file_date' => 2, + 'crc_32' => 2, + 'compressed_size' => 2, + 'uncompressed_size' => 2, + 'filename_length' => 2, 'extra_field_length' => 2 ) - ); + ); $local_file_header['extract_version'] = sprintf('%1.1f', $local_file_header['raw']['extract_version'] / 10); $local_file_header['host_os'] = $this->ZIPversionOSLookup(($local_file_header['raw']['extract_version'] & 0xFF00) >> 8); @@ -229,12 +229,12 @@ class getid3_zip extends getid3_handler if ($local_file_header['flags']['data_descriptor_used']) { $data_descriptor = fread($getid3->fp, 12); - - getid3_lib::ReadSequence('LittleEndian2Int', $local_file_header['data_descriptor'], $data_descriptor, 0, + + getid3_lib::ReadSequence('LittleEndian2Int', $local_file_header['data_descriptor'], $data_descriptor, 0, array ( 'crc_32' => 4, 'compressed_size' => 4, - 'uncompressed_size' => 4 + 'uncompressed_size' => 4 ) ); } @@ -245,7 +245,7 @@ class getid3_zip extends getid3_handler private function ZIPparseCentralDirectory() { - + // shortcut $getid3 = $this->getid3; @@ -254,14 +254,14 @@ class getid3_zip extends getid3_handler $zip_central_directory = fread($getid3->fp, 46); $central_directory['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($zip_central_directory, 0, 4)); - + // invalid Central Directory Signature if ($central_directory['raw']['signature'] != 0x02014B50) { fseek($getid3->fp, $central_directory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly return false; } - - getid3_lib::ReadSequence('LittleEndian2Int', $central_directory['raw'], $zip_central_directory, 4, + + getid3_lib::ReadSequence('LittleEndian2Int', $central_directory['raw'], $zip_central_directory, 4, array ( 'create_version' => 2, 'extract_version' => 2, @@ -281,7 +281,7 @@ class getid3_zip extends getid3_handler 'local_header_offset' => 4 ) ); - + $central_directory['entry_offset'] = $central_directory['raw']['local_header_offset']; $central_directory['create_version'] = sprintf('%1.1f', $central_directory['raw']['create_version'] / 10); $central_directory['extract_version'] = sprintf('%1.1f', $central_directory['raw']['extract_version'] / 10); @@ -310,26 +310,26 @@ class getid3_zip extends getid3_handler return $central_directory; } - - + + private function ZIPparseEndOfCentralDirectory() { - - // shortcut + + // shortcut $getid3 = $this->getid3; - + $end_of_central_directory['offset'] = ftell($getid3->fp); $zip_end_of_central_directory = fread($getid3->fp, 22); $end_of_central_directory['signature'] = getid3_lib::LittleEndian2Int(substr($zip_end_of_central_directory, 0, 4)); - + // invalid End Of Central Directory Signature if ($end_of_central_directory['signature'] != 0x06054B50) { fseek($getid3->fp, $end_of_central_directory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly return false; } - - getid3_lib::ReadSequence('LittleEndian2Int', $end_of_central_directory, $zip_end_of_central_directory, 4, + + getid3_lib::ReadSequence('LittleEndian2Int', $end_of_central_directory, $zip_end_of_central_directory, 4, array ( 'disk_number_current' => 2, 'disk_number_start_directory' => 2, @@ -340,14 +340,14 @@ class getid3_zip extends getid3_handler 'comment_length' => 2 ) ); - + if ($end_of_central_directory['comment_length'] > 0) { $end_of_central_directory['comment'] = fread($getid3->fp, $end_of_central_directory['comment_length']); } return $end_of_central_directory; } - + public static function ZIPparseGeneralPurposeFlags($flag_bytes, $compression_method) { @@ -386,7 +386,7 @@ class getid3_zip extends getid3_handler public static function ZIPversionOSLookup($index) { - + static $lookup = array ( 0 => 'MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)', 1 => 'Amiga', @@ -461,18 +461,18 @@ class getid3_zip extends getid3_handler */ return gmmktime(($DOStime & 0xF800) >> 11, ($DOStime & 0x07E0) >> 5, ($DOStime & 0x001F) * 2, ($DOSdate & 0x01E0) >> 5, $DOSdate & 0x001F, (($DOSdate & 0xFE00) >> 9) + 1980); } - - - + + + public static function array_merge_clobber($array1, $array2) { // written by kcØhireability*com // taken from http://www.php.net/manual/en/function.array-merge-recursive.php - + if (!is_array($array1) || !is_array($array2)) { return false; } - + $newarray = $array1; foreach ($array2 as $key => $val) { if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { @@ -483,9 +483,9 @@ class getid3_zip extends getid3_handler } return $newarray; } - - - + + + public static function CreateDeepArray($array_path, $separator, $value) { // assigns $value to a nested array path: @@ -494,14 +494,14 @@ class getid3_zip extends getid3_handler // $foo = array ('path'=>array('to'=>'array('my'=>array('file.txt')))); // or // $foo['path']['to']['my'] = 'file.txt'; - + while ($array_path{0} == $separator) { $array_path = substr($array_path, 1); } if (($pos = strpos($array_path, $separator)) !== false) { return array (substr($array_path, 0, $pos) => getid3_zip::CreateDeepArray(substr($array_path, $pos + 1), $separator, $value)); } - + return array ($array_path => $value); } diff --git a/modules/getid3/module.audio-video.asf.php b/modules/getid3/module.audio-video.asf.php index 1ffc1142..ac71de48 100644 --- a/modules/getid3/module.audio-video.asf.php +++ b/modules/getid3/module.audio-video.asf.php @@ -22,8 +22,8 @@ // // $Id: module.audio-video.asf.php,v 1.7 2006/12/01 22:39:48 ah Exp $ - - + + class getid3_asf extends getid3_handler { @@ -139,13 +139,13 @@ class getid3_asf extends getid3_handler public function Analyze() { $getid3 = $this->getid3; - + $getid3->include_module('audio-video.riff'); !isset($getid3->info['audio']) and $getid3->info['audio'] = array (); !isset($getid3->info['video']) and $getid3->info['video'] = array (); $getid3->info['asf']['comments'] = $getid3->info['asf']['header_object'] = array (); - + $info_audio = &$getid3->info['audio']; $info_video = &$getid3->info['video']; $info_asf = &$getid3->info['asf']; @@ -178,11 +178,11 @@ class getid3_asf extends getid3_handler $header_object_data = fread($getid3->fp, 30); $info_asf_header_object['objectid_guid'] = getid3_asf::BytestringToGUID(substr($header_object_data, 0, 16)); - + if ($info_asf_header_object['objectid_guid'] != getid3_asf::Header_Object) { throw new getid3_exception('ASF header GUID {'.$info_asf_header_object['objectid_guid'].'} does not match expected "getid3_asf::Header_Object" GUID {'.getid3_asf::Header_Object.'}'); } - + getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_header_object, $header_object_data, 16, array ( 'objectsize' => 8, @@ -196,19 +196,19 @@ class getid3_asf extends getid3_handler $offset = 0; for ($header_objects_counter = 0; $header_objects_counter < $info_asf_header_object['headerobjects']; $header_objects_counter++) { - + $next_object_guid = substr($asf_header_data, $offset, 16); $offset += 16; - + $next_object_size = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 8)); $offset += 8; - + $next_object_guidtext = getid3_asf::BytestringToGUID($next_object_guid); - + switch ($next_object_guidtext) { case getid3_asf::File_Properties_Object: - + // File Properties Object: (mandatory, one only) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for file properties object - getid3_asf::File_Properties_Object @@ -233,7 +233,7 @@ class getid3_asf extends getid3_handler $info_asf_file_properties_object['objectid_guid'] = $next_object_guidtext; $info_asf_file_properties_object['objectsize'] = $next_object_size; - + $info_asf_file_properties_object['fileid_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16)); $offset += 16; @@ -251,9 +251,9 @@ class getid3_asf extends getid3_handler 'max_bitrate' => 4 ) ); - + $offset += 64 ; - + $info_asf_file_properties_object['creation_date_unix'] = getid3_asf::FiletimeToUNIXtime($info_asf_file_properties_object['creation_date']); $info_asf_file_properties_object['flags']['broadcast'] = (bool)($info_asf_file_properties_object['flags_raw'] & 0x0001); $info_asf_file_properties_object['flags']['seekable'] = (bool)($info_asf_file_properties_object['flags_raw'] & 0x0002); @@ -264,7 +264,7 @@ class getid3_asf extends getid3_handler case getid3_asf::Stream_Properties_Object: - + // Stream Properties Object: (mandatory, one per media stream) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for stream properties object - getid3_asf::Stream_Properties_Object @@ -288,7 +288,7 @@ class getid3_asf extends getid3_handler $stream_properties_object_data['objectid_guid'] = $next_object_guidtext; $stream_properties_object_data['objectsize'] = $next_object_size; - + getid3_lib::ReadSequence('LittleEndian2Int', $stream_properties_object_data, $asf_header_data, $offset, array ( 'stream_type' => -16, @@ -307,17 +307,17 @@ class getid3_asf extends getid3_handler $stream_properties_object_data['error_correct_guid'] = getid3_asf::BytestringToGUID($stream_properties_object_data['error_correct_type']); $offset += 54; // 50 bytes + 4 bytes reserved - DWORD - + $stream_properties_object_data['type_specific_data'] = substr($asf_header_data, $offset, $stream_properties_object_data['type_data_length']); $offset += $stream_properties_object_data['type_data_length']; - + $stream_properties_object_data['error_correct_data'] = substr($asf_header_data, $offset, $stream_properties_object_data['error_data_length']); $offset += $stream_properties_object_data['error_data_length']; switch ($stream_properties_object_data['stream_type_guid']) { case getid3_asf::Audio_Media: - + $info_audio['dataformat'] = (@$info_audio['dataformat'] ? $info_audio['dataformat'] : 'asf'); $info_audio['bitrate_mode'] = (@$info_audio['bitrate_mode'] ? $info_audio['bitrate_mode'] : 'cbr'); @@ -345,10 +345,10 @@ class getid3_asf extends getid3_handler $info_asf['stream_properties_object'][$stream_properties_stream_number] = $stream_properties_object_data; unset($stream_properties_object_data); // clear for next stream, if any break; - + case getid3_asf::Header_Extension_Object: - + // Header Extension Object: (mandatory, one only) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Header Extension object - getid3_asf::Header_Extension_Object @@ -365,30 +365,30 @@ class getid3_asf extends getid3_handler $info_asf_header_extension_object['objectsize'] = $next_object_size; $info_asf_header_extension_object['reserved_1_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16)); $offset += 16; - + if ($info_asf_header_extension_object['reserved_1_guid'] != getid3_asf::Reserved_1) { $getid3->warning('header_extension_object.reserved_1 GUID ('.$info_asf_header_extension_object['reserved_1_guid'].') does not match expected "getid3_asf::Reserved_1" GUID ('.getid3_asf::Reserved_1.')'); break; } - + $info_asf_header_extension_object['reserved_2'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; - + if ($info_asf_header_extension_object['reserved_2'] != 6) { $getid3->warning('header_extension_object.reserved_2 ('.getid3_lib::PrintHexBytes($info_asf_header_extension_object['reserved_2']).') does not match expected value of "6"'); break; } - + $info_asf_header_extension_object['extension_data_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4)); $offset += 4; - + $info_asf_header_extension_object['extension_data'] = substr($asf_header_data, $offset, $info_asf_header_extension_object['extension_data_size']); $offset += $info_asf_header_extension_object['extension_data_size']; break; - + case getid3_asf::Codec_List_Object: - + // Codec List Object: (optional, one only) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Codec List object - getid3_asf::Codec_List_Object @@ -409,48 +409,48 @@ class getid3_asf extends getid3_handler $info_asf_codec_list_object['objectid_guid'] = $next_object_guidtext; $info_asf_codec_list_object['objectsize'] = $next_object_size; - + $info_asf_codec_list_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16)); $offset += 16; - + if ($info_asf_codec_list_object['reserved_guid'] != '86D15241-311D-11D0-A3A4-00A0C90348F6') { $getid3->warning('codec_list_object.reserved GUID {'.$info_asf_codec_list_object['reserved_guid'].'} does not match expected "getid3_asf::Reserved_1" GUID {86D15241-311D-11D0-A3A4-00A0C90348F6}'); break; } - + $info_asf_codec_list_object['codec_entries_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4)); $offset += 4; - + for ($codec_entry_counter = 0; $codec_entry_counter < $info_asf_codec_list_object['codec_entries_count']; $codec_entry_counter++) { - + $info_asf_codec_list_object['codec_entries'][$codec_entry_counter] = array (); $info_asf_codec_list_object_codecentries_current = &$info_asf_codec_list_object['codec_entries'][$codec_entry_counter]; $info_asf_codec_list_object_codecentries_current['type_raw'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; - + $info_asf_codec_list_object_codecentries_current['type'] = getid3_asf::ASFCodecListObjectTypeLookup($info_asf_codec_list_object_codecentries_current['type_raw']); $codec_name_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2; // 2 bytes per character $offset += 2; - + $info_asf_codec_list_object_codecentries_current['name'] = substr($asf_header_data, $offset, $codec_name_length); $offset += $codec_name_length; $codec_description_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2; // 2 bytes per character $offset += 2; - + $info_asf_codec_list_object_codecentries_current['description'] = substr($asf_header_data, $offset, $codec_description_length); $offset += $codec_description_length; $codec_information_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; - + $info_asf_codec_list_object_codecentries_current['information'] = substr($asf_header_data, $offset, $codec_information_length); $offset += $codec_information_length; if ($info_asf_codec_list_object_codecentries_current['type_raw'] == 2) { - + // audio codec if (strpos($info_asf_codec_list_object_codecentries_current['description'], ',') === false) { throw new getid3_exception('[asf][codec_list_object][codec_entries]['.$codec_entry_counter.'][description] expected to contain comma-seperated list of parameters: "'.$info_asf_codec_list_object_codecentries_current['description'].'"'); @@ -465,7 +465,7 @@ class getid3_asf extends getid3_handler if (!isset($info_video['bitrate']) && isset($info_audio['bitrate']) && isset($info_asf['file_properties_object']['max_bitrate']) && ($info_asf_codec_list_object['codec_entries_count'] > 1)) { $info_video['bitrate'] = $info_asf['file_properties_object']['max_bitrate'] - $info_audio['bitrate']; } - + if (!@$info_video['bitrate'] && @$info_audio['bitrate'] && @$getid3->info['bitrate']) { $info_video['bitrate'] = $getid3->info['bitrate'] - $info_audio['bitrate']; } @@ -529,38 +529,38 @@ class getid3_asf extends getid3_handler $info_asf_script_command_object['objectsize'] = $next_object_size; $info_asf_script_command_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16)); $offset += 16; - + if ($info_asf_script_command_object['reserved_guid'] != '4B1ACBE3-100B-11D0-A39B-00A0C90348F6') { $getid3->warning('script_command_object.reserved GUID {'.$info_asf_script_command_object['reserved_guid'].'} does not match expected GUID {4B1ACBE3-100B-11D0-A39B-00A0C90348F6}'); break; } - + $info_asf_script_command_object['commands_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; - + $info_asf_script_command_object['command_types_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; - + for ($command_types_counter = 0; $command_types_counter < $info_asf_script_command_object['command_types_count']; $command_types_counter++) { - + $command_type_name_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2; // 2 bytes per character $offset += 2; - + $info_asf_script_command_object['command_types'][$command_types_counter]['name'] = substr($asf_header_data, $offset, $command_type_name_length); $offset += $command_type_name_length; } - + for ($commands_counter = 0; $commands_counter < $info_asf_script_command_object['commands_count']; $commands_counter++) { - + $info_asf_script_command_object['commands'][$commands_counter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4)); $offset += 4; - + $info_asf_script_command_object['commands'][$commands_counter]['type_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; $command_type_name_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2; // 2 bytes per character $offset += 2; - + $info_asf_script_command_object['commands'][$commands_counter]['name'] = substr($asf_header_data, $offset, $command_type_name_length); $offset += $command_type_name_length; } @@ -594,32 +594,32 @@ class getid3_asf extends getid3_handler $info_asf_marker_object['objectid_guid'] = $next_object_guidtext; $info_asf_marker_object['objectsize'] = $next_object_size; $info_asf_marker_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16)); - $offset += 16; - + $offset += 16; + if ($info_asf_marker_object['reserved_guid'] != '4CFEDB20-75F6-11CF-9C0F-00A0C90349CB') { $getid3->warning('marker_object.reserved GUID {'.$info_asf_marker_object['reserved_guid'].'} does not match expected GUID {4CFEDB20-75F6-11CF-9C0F-00A0C90349CB}'); break; } - + $info_asf_marker_object['markers_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4)); $offset += 4; - + $info_asf_marker_object['reserved_2'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; - + if ($info_asf_marker_object['reserved_2'] != 0) { $getid3->warning('marker_object.reserved_2 ('.getid3_lib::PrintHexBytes($info_asf_marker_object['reserved_2']).') does not match expected value of "0"'); break; } - + $info_asf_marker_object['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; - + $info_asf_marker_object['name'] = substr($asf_header_data, $offset, $info_asf_marker_object['name_length']); $offset += $info_asf_marker_object['name_length']; - + for ($markers_counter = 0; $markers_counter < $info_asf_marker_object['markers_count']; $markers_counter++) { - + getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_marker_object['markers'][$markers_counter], $asf_header_data, $offset, array ( 'offset' => 8, @@ -631,10 +631,10 @@ class getid3_asf extends getid3_handler ) ); $offset += 30; - + $info_asf_marker_object['markers'][$markers_counter]['marker_description'] = substr($asf_header_data, $offset, $info_asf_marker_object['markers'][$markers_counter]['marker_description_length']); $offset += $info_asf_marker_object['markers'][$markers_counter]['marker_description_length']; - + $padding_length = $info_asf_marker_object['markers'][$markers_counter]['entry_length'] - 4 - 4 - 4 - $info_asf_marker_object['markers'][$markers_counter]['marker_description_length']; if ($padding_length > 0) { $info_asf_marker_object['markers'][$markers_counter]['padding'] = substr($asf_header_data, $offset, $padding_length); @@ -642,10 +642,10 @@ class getid3_asf extends getid3_handler } } break; - + case getid3_asf::Bitrate_Mutual_Exclusion_Object: - + // Bitrate Mutual Exclusion Object: (optional) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Bitrate Mutual Exclusion object - getid3_asf::Bitrate_Mutual_Exclusion_Object @@ -662,15 +662,15 @@ class getid3_asf extends getid3_handler $info_asf_bitrate_mutual_exclusion_object['objectsize'] = $next_object_size; $info_asf_bitrate_mutual_exclusion_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16)); $offset += 16; - + if ($info_asf_bitrate_mutual_exclusion_object['reserved_guid'] != getid3_asf::Mutex_Bitrate && $info_asf_bitrate_mutual_exclusion_object['reserved_guid'] != getid3_asf::Mutex_Unknown) { $getid3->warning('bitrate_mutual_exclusion_object.reserved GUID {'.$info_asf_bitrate_mutual_exclusion_object['reserved_guid'].'} does not match expected "getid3_asf::Mutex_Bitrate" GUID {'.getid3_asf::Mutex_Bitrate.'} or "getid3_asf::Mutex_Unknown" GUID {'.getid3_asf::Mutex_Unknown.'}'); break; } - + $info_asf_bitrate_mutual_exclusion_object['stream_numbers_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; - + for ($stream_number_counter = 0; $stream_number_counter < $info_asf_bitrate_mutual_exclusion_object['stream_numbers_count']; $stream_number_counter++) { $info_asf_bitrate_mutual_exclusion_object['stream_numbers'][$stream_number_counter] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; @@ -695,15 +695,15 @@ class getid3_asf extends getid3_handler $info_asf_error_correction_object['objectsize'] = $next_object_size; $info_asf_error_correction_object['error_correction_type'] = substr($asf_header_data, $offset, 16); $offset += 16; - + $info_asf_error_correction_object['error_correction_guid'] = getid3_asf::BytestringToGUID($info_asf_error_correction_object['error_correction_type']); $info_asf_error_correction_object['error_correction_data_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4)); $offset += 4; - + switch ($info_asf_error_correction_object['error_correction_type_guid']) { - + case getid3_asf::No_Error_Correction: - + // should be no data, but just in case there is, skip to the end of the field $offset += $info_asf_error_correction_object['error_correction_data_length']; break; @@ -718,7 +718,7 @@ class getid3_asf extends getid3_handler // Silence Data Length WORD 16 // number of bytes in Silence Data field // Silence Data BYTESTREAM variable // hardcoded: 0x00 * (Silence Data Length) bytes - getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_error_correction_object, $asf_header_data, $offset, + getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_error_correction_object, $asf_header_data, $offset, array ( 'span' => 1, 'virtual_packet_length' => 2, @@ -727,7 +727,7 @@ class getid3_asf extends getid3_handler ) ); $offset += 7; - + $info_asf_error_correction_object['silence_data'] = substr($asf_header_data, $offset, $info_asf_error_correction_object['silence_data_length']); $offset += $info_asf_error_correction_object['silence_data_length']; break; @@ -762,8 +762,8 @@ class getid3_asf extends getid3_handler $info_asf_content_description_object['objectid_guid'] = $next_object_guidtext; $info_asf_content_description_object['objectsize'] = $next_object_size; - - getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_content_description_object, $asf_header_data, $offset, + + getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_content_description_object, $asf_header_data, $offset, array ( 'title_length' => 2, 'author_length' => 2, @@ -773,19 +773,19 @@ class getid3_asf extends getid3_handler ) ); $offset += 10; - + $info_asf_content_description_object['title'] = substr($asf_header_data, $offset, $info_asf_content_description_object['title_length']); $offset += $info_asf_content_description_object['title_length']; - + $info_asf_content_description_object['author'] = substr($asf_header_data, $offset, $info_asf_content_description_object['author_length']); $offset += $info_asf_content_description_object['author_length']; - + $info_asf_content_description_object['copyright'] = substr($asf_header_data, $offset, $info_asf_content_description_object['copyright_length']); $offset += $info_asf_content_description_object['copyright_length']; - + $info_asf_content_description_object['description'] = substr($asf_header_data, $offset, $info_asf_content_description_object['description_length']); $offset += $info_asf_content_description_object['description_length']; - + $info_asf_content_description_object['rating'] = substr($asf_header_data, $offset, $info_asf_content_description_object['rating_length']); $offset += $info_asf_content_description_object['rating_length']; @@ -824,30 +824,30 @@ class getid3_asf extends getid3_handler $info_asf_extended_content_description_object['objectsize'] = $next_object_size; $info_asf_extended_content_description_object['content_descriptors_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; - + for ($extended_content_descriptors_counter = 0; $extended_content_descriptors_counter < $info_asf_extended_content_description_object['content_descriptors_count']; $extended_content_descriptors_counter++) { - + $info_asf_extended_content_description_object['content_descriptors'][$extended_content_descriptors_counter] = array (); $info_asf_extended_content_description_object_content_descriptor_current = &$info_asf_extended_content_description_object['content_descriptors'][$extended_content_descriptors_counter]; $info_asf_extended_content_description_object_content_descriptor_current['base_offset'] = $offset + 30; $info_asf_extended_content_description_object_content_descriptor_current['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; - + $info_asf_extended_content_description_object_content_descriptor_current['name'] = substr($asf_header_data, $offset, $info_asf_extended_content_description_object_content_descriptor_current['name_length']); $offset += $info_asf_extended_content_description_object_content_descriptor_current['name_length']; - + $info_asf_extended_content_description_object_content_descriptor_current['value_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; - + $info_asf_extended_content_description_object_content_descriptor_current['value_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; - + $info_asf_extended_content_description_object_content_descriptor_current['value'] = substr($asf_header_data, $offset, $info_asf_extended_content_description_object_content_descriptor_current['value_length']); $offset += $info_asf_extended_content_description_object_content_descriptor_current['value_length']; - + switch ($info_asf_extended_content_description_object_content_descriptor_current['value_type']) { - + case 0x0000: // Unicode string break; @@ -869,7 +869,7 @@ class getid3_asf extends getid3_handler $getid3->warning('extended_content_description.content_descriptors.'.$extended_content_descriptors_counter.'.value_type is invalid ('.$info_asf_extended_content_description_object_content_descriptor_current['value_type'].')'); break; } - + switch ($this->TrimConvert(strtolower($info_asf_extended_content_description_object_content_descriptor_current['name']))) { case 'wm/albumartist': @@ -909,14 +909,14 @@ class getid3_asf extends getid3_handler case 'date': $info_asf_comments['year'] = array ( getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value'])); break; - - + + case 'wm/lyrics': case 'lyrics': $info_asf_comments['lyrics'] = array ( getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value'])); break; - - + + case 'isvbr': if ($info_asf_extended_content_description_object_content_descriptor_current['value']) { $info_audio['bitrate_mode'] = 'vbr'; @@ -926,17 +926,17 @@ class getid3_asf extends getid3_handler case 'id3': - + // id3v2 parsing might not be enabled if (class_exists('getid3_id3v2')) { - - // Clone getid3 + + // Clone getid3 $clone = clone $getid3; - + // Analyse clone by string $id3v2 = new getid3_id3v2($clone); $id3v2->AnalyzeString($info_asf_extended_content_description_object_content_descriptor_current['value']); - + // Import from clone and destroy $getid3->info['id3v2'] = $clone->info['id3v2']; $getid3->warnings($clone->warnings()); @@ -952,7 +952,7 @@ class getid3_asf extends getid3_handler case 'wm/picture': - + //typedef struct _WMPicture{ // LPWSTR pwszMIMEType; // BYTE bPictureType; @@ -965,9 +965,9 @@ class getid3_asf extends getid3_handler $info_asf_extended_content_description_object_content_descriptor_current['image_type'] = getid3_asf::WMpictureTypeLookup($info_asf_extended_content_description_object_content_descriptor_current['image_type_id']); $info_asf_extended_content_description_object_content_descriptor_current['image_size'] = getid3_lib::LittleEndian2Int(substr($info_asf_extended_content_description_object_content_descriptor_current['value'], 1, 4)); $info_asf_extended_content_description_object_content_descriptor_current['image_mime'] = ''; - + $wm_picture_offset = 5; - + do { $next_byte_pair = substr($info_asf_extended_content_description_object_content_descriptor_current['value'], $wm_picture_offset, 2); $wm_picture_offset += 2; @@ -975,7 +975,7 @@ class getid3_asf extends getid3_handler } while ($next_byte_pair !== "\x00\x00"); $info_asf_extended_content_description_object_content_descriptor_current['image_description'] = ''; - + do { $next_byte_pair = substr($info_asf_extended_content_description_object_content_descriptor_current['value'], $wm_picture_offset, 2); $wm_picture_offset += 2; @@ -1026,14 +1026,14 @@ class getid3_asf extends getid3_handler $info_asf_stream_bitrate_properties_object['objectsize'] = $next_object_size; $info_asf_stream_bitrate_properties_object['bitrate_records_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; - + for ($bitrate_records_counter = 0; $bitrate_records_counter < $info_asf_stream_bitrate_properties_object['bitrate_records_count']; $bitrate_records_counter++) { - + $info_asf_stream_bitrate_properties_object['bitrate_records'][$bitrate_records_counter]['flags_raw'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)); $offset += 2; - + $info_asf_stream_bitrate_properties_object['bitrate_records'][$bitrate_records_counter]['flags']['stream_number'] = $info_asf_stream_bitrate_properties_object['bitrate_records'][$bitrate_records_counter]['flags_raw'] & 0x007F; - + $info_asf_stream_bitrate_properties_object['bitrate_records'][$bitrate_records_counter]['bitrate'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4)); $offset += 4; } @@ -1080,7 +1080,7 @@ class getid3_asf extends getid3_handler break; } } - + if (isset($info_asf_stream_bitrate_properties['bitrate_records_count'])) { $asf_bitrate_audio = 0; $asf_bitrate_video = 0; @@ -1088,11 +1088,11 @@ class getid3_asf extends getid3_handler for ($bitrate_records_counter = 0; $bitrate_records_counter < $info_asf_stream_bitrate_properties['bitrate_records_count']; $bitrate_records_counter++) { if (isset($info_asf_codec_list_object['codec_entries'][$bitrate_records_counter])) { switch ($info_asf_codec_list_object['codec_entries'][$bitrate_records_counter]['type_raw']) { - + case 1: $asf_bitrate_video += $info_asf_stream_bitrate_properties['bitrate_records'][$bitrate_records_counter]['bitrate']; break; - + case 2: $asf_bitrate_audio += $info_asf_stream_bitrate_properties['bitrate_records'][$bitrate_records_counter]['bitrate']; break; @@ -1106,18 +1106,18 @@ class getid3_asf extends getid3_handler $info_video['bitrate'] = $asf_bitrate_video; } } - + if (isset($info_asf['stream_properties_object']) && is_array($info_asf['stream_properties_object'])) { - + $info_audio['bitrate'] = 0; $info_video['bitrate'] = 0; foreach ($info_asf['stream_properties_object'] as $stream_number => $stream_data) { - + switch ($stream_data['stream_type_guid']) { - + case getid3_asf::Audio_Media: - + // Field Name Field Type Size (bits) // Codec ID / Format Tag WORD 16 // unique ID of audio codec - defined as wFormatTag field of WAVEFORMATEX structure // Number of Channels WORD 16 // number of channels of audio - defined as nChannels field of WAVEFORMATEX structure @@ -1161,7 +1161,7 @@ class getid3_asf extends getid3_handler $info_audio['bitrate'] += $info_asf_audio_media_current_stream['bitrate']; } } - + $info_audio['streams'][$stream_number] = $info_asf_audio_media_current_stream; $info_audio['streams'][$stream_number]['wformattag'] = $info_asf_audio_media_current_stream['raw']['wFormatTag']; $info_audio['streams'][$stream_number]['lossless'] = $info_audio['lossless']; @@ -1170,7 +1170,7 @@ class getid3_asf extends getid3_handler $info_asf_audio_media_current_stream['codec_data_size'] = getid3_lib::LittleEndian2Int(substr($stream_data['type_specific_data'], $audio_media_offset, 2)); $audio_media_offset += 2; - + $info_asf_audio_media_current_stream['codec_data'] = substr($stream_data['type_specific_data'], $audio_media_offset, $info_asf_audio_media_current_stream['codec_data_size']); $audio_media_offset += $info_asf_audio_media_current_stream['codec_data_size']; break; @@ -1200,7 +1200,7 @@ class getid3_asf extends getid3_handler $info_asf['video_media'][$stream_number] = array (); $info_asf_video_media_current_stream = &$info_asf['video_media'][$stream_number]; - getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_video_media_current_stream, $stream_data['type_specific_data'], 0, + getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_video_media_current_stream, $stream_data['type_specific_data'], 0, array ( 'image_width' => 4, 'image_height' => 4, @@ -1208,8 +1208,8 @@ class getid3_asf extends getid3_handler 'format_data_size'=> 2 ) ); - - getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_video_media_current_stream['format_data'], $stream_data['type_specific_data'], 11, + + getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_video_media_current_stream['format_data'], $stream_data['type_specific_data'], 11, array ( 'format_data_size' => 4, 'image_width' => 4, @@ -1224,21 +1224,21 @@ class getid3_asf extends getid3_handler 'colors_important' => 4 ) ); - + $info_asf_video_media_current_stream['format_data']['codec_data'] = substr($stream_data['type_specific_data'], 51); - + if (!empty($info_asf['stream_bitrate_properties_object']['bitrate_records'])) { foreach ($info_asf['stream_bitrate_properties_object']['bitrate_records'] as $data_array) { if (@$data_array['flags']['stream_number'] == $stream_number) { $info_asf_video_media_current_stream['bitrate'] = $data_array['bitrate']; $info_video['streams'][$stream_number]['bitrate'] = $data_array['bitrate']; $info_video['bitrate'] += $data_array['bitrate']; - + break; } } } - + $info_asf_video_media_current_stream['format_data']['codec'] = getid3_riff::RIFFfourccLookup($info_asf_video_media_current_stream['format_data']['codec_fourcc']); $info_video['streams'][$stream_number]['fourcc'] = $info_asf_video_media_current_stream['format_data']['codec_fourcc']; @@ -1255,21 +1255,21 @@ class getid3_asf extends getid3_handler } while (ftell($getid3->fp) < $getid3->info['avdataend']) { - + $next_object_data_header = fread($getid3->fp, 24); $offset = 0; - + $next_object_guid = substr($next_object_data_header, 0, 16); $offset += 16; - + $next_object_guidtext = getid3_asf::BytestringToGUID($next_object_guid); $next_object_size = getid3_lib::LittleEndian2Int(substr($next_object_data_header, $offset, 8)); $offset += 8; switch ($next_object_guidtext) { - + case getid3_asf::Data_Object: - + // Data Object: (mandatory, one only) // Field Name Field Type Size (bits) // Object ID GUID 128 // GUID for Data object - getid3_asf::Data_Object @@ -1290,13 +1290,13 @@ class getid3_asf extends getid3_handler $info_asf_data_object['fileid_guid'] = getid3_asf::BytestringToGUID(substr($data_object_data, $offset, 16)); $offset += 16; - + $info_asf_data_object['total_data_packets'] = getid3_lib::LittleEndian2Int(substr($data_object_data, $offset, 8)); $offset += 8; - + $info_asf_data_object['reserved'] = getid3_lib::LittleEndian2Int(substr($data_object_data, $offset, 2)); $offset += 2; - + if ($info_asf_data_object['reserved'] != 0x0101) { $getid3->warning('data_object.reserved ('.getid3_lib::PrintHexBytes($info_asf_data_object['reserved']).') does not match expected value of "0x0101"'); break; @@ -1338,7 +1338,7 @@ class getid3_asf extends getid3_handler $info_asf_simple_index_object['objectsize'] = $next_object_size; $simple_index_object_data = $next_object_data_header.fread($getid3->fp, 56 - 24); - + $info_asf_simple_index_object['fileid_guid'] = getid3_asf::BytestringToGUID(substr($simple_index_object_data, 24, 16)); getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_simple_index_object, $simple_index_object_data, 40, @@ -1348,15 +1348,15 @@ class getid3_asf extends getid3_handler 'index_entries_count' => 4 ) ); - + $offset = 56; $index_entries_data = $simple_index_object_data.fread($getid3->fp, 6 * $info_asf_simple_index_object['index_entries_count']); for ($index_entries_counter = 0; $index_entries_counter < $info_asf_simple_index_object['index_entries_count']; $index_entries_counter++) { - + $info_asf_simple_index_object['index_entries'][$index_entries_counter]['packet_number'] = getid3_lib::LittleEndian2Int(substr($index_entries_data, $offset, 4)); $offset += 4; - + $info_asf_simple_index_object['index_entries'][$index_entries_counter]['packet_count'] = getid3_lib::LittleEndian2Int(substr($index_entries_data, $offset, 4)); $offset += 2; } @@ -1396,7 +1396,7 @@ class getid3_asf extends getid3_handler $info_asf_asf_index_object['objectid_guid'] = $next_object_guidtext; $info_asf_asf_index_object['objectsize'] = $next_object_size; - getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_asf_index_object, $asf_index_object_data, 24, + getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_asf_index_object, $asf_index_object_data, 24, array ( 'entry_time_interval' =>4, 'index_specifiers_count' =>2, @@ -1407,17 +1407,17 @@ class getid3_asf extends getid3_handler $offset = 34; $asf_index_object_data .= fread($getid3->fp, 4 * $info_asf_asf_index_object['index_specifiers_count']); - + for ($index_specifiers_counter = 0; $index_specifiers_counter < $info_asf_asf_index_object['index_specifiers_count']; $index_specifiers_counter++) { - + $index_specifier_stream_number = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 2)); $offset += 2; - + $info_asf_asf_index_object['index_specifiers'][$index_specifiers_counter]['stream_number'] = $index_specifier_stream_number; - + $info_asf_asf_index_object['index_specifiers'][$index_specifiers_counter]['index_type'] = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 2)); $offset += 2; - + $info_asf_asf_index_object['index_specifiers'][$index_specifiers_counter]['index_type_text'] = getid3_asf::ASFIndexObjectIndexTypeLookup($info_asf_asf_index_object['index_specifiers'][$index_specifiers_counter]['index_type']); } @@ -1426,14 +1426,14 @@ class getid3_asf extends getid3_handler $offset += 4; $asf_index_object_data .= fread($getid3->fp, 8 * $info_asf_asf_index_object['index_specifiers_count']); - + for ($index_specifiers_counter = 0; $index_specifiers_counter < $info_asf_asf_index_object['index_specifiers_count']; $index_specifiers_counter++) { $info_asf_asf_index_object['block_positions'][$index_specifiers_counter] = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 8)); $offset += 8; } $asf_index_object_data .= fread($getid3->fp, 4 * $info_asf_asf_index_object['index_specifiers_count'] * $info_asf_asf_index_object['index_entry_count']); - + for ($index_entry_counter = 0; $index_entry_counter < $info_asf_asf_index_object['index_entry_count']; $index_entry_counter++) { for ($index_specifiers_counter = 0; $index_specifiers_counter < $info_asf_asf_index_object['index_specifiers_count']; $index_specifiers_counter++) { $info_asf_asf_index_object['offsets'][$index_specifiers_counter][$index_entry_counter] = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 4)); @@ -1444,7 +1444,7 @@ class getid3_asf extends getid3_handler default: - + // Implementations shall ignore any standard or non-standard object that they do not know how to handle. if (getid3_asf::GUIDname($next_object_guidtext)) { $getid3->warning('unhandled GUID "'.getid3_asf::GUIDname($next_object_guidtext).'" {'.$next_object_guidtext.'} in ASF body at offset '.($offset - 16 - 8)); @@ -1467,7 +1467,7 @@ class getid3_asf extends getid3_handler case 'WMVA': case 'WVC1': case 'WMVP': - case 'WVP2': + case 'WVP2': $info_video['dataformat'] = 'wmv'; $getid3->info['mime_type'] = 'video/x-ms-wmv'; break; @@ -1541,31 +1541,31 @@ class getid3_asf extends getid3_handler $info_audio['lossless'] = (isset($info_audio['lossless']) ? $info_audio['lossless'] : false); $info_audio['dataformat'] = (!empty($info_audio['dataformat']) ? $info_audio['dataformat'] : 'asf'); } - + if (!empty($info_video['dataformat'])) { $info_video['lossless'] = (isset($info_audio['lossless']) ? $info_audio['lossless'] : false); $info_video['pixel_aspect_ratio'] = (isset($info_audio['pixel_aspect_ratio']) ? $info_audio['pixel_aspect_ratio'] : (float)1); $info_video['dataformat'] = (!empty($info_video['dataformat']) ? $info_video['dataformat'] : 'asf'); } - + $getid3->info['bitrate'] = @$info_audio['bitrate'] + @$info_video['bitrate']; - + if (empty($info_audio)) { unset($getid3->info['audio']); } - + if (empty($info_video)) { unset($getid3->info['video']); } - + return true; } - + // Remove terminator 00 00 and convert UNICODE to Latin-1 private function TrimConvert($string) { - + // remove terminator, only if present (it should be, but...) if (substr($string, strlen($string) - 2, 2) == "\x00\x00") { $string = substr($string, 0, strlen($string) - 2); @@ -1578,7 +1578,7 @@ class getid3_asf extends getid3_handler private function WMpictureTypeLookup($wm_picture_type) { - + static $lookup = array ( 0x03 => 'Front Cover', 0x04 => 'Back Cover', @@ -1599,14 +1599,14 @@ class getid3_asf extends getid3_handler 0x13 => 'Band Logotype', 0x14 => 'Publisher Logotype' ); - + return isset($lookup[$wm_picture_type]) ? $this->getid3->iconv('ISO-8859-1', 'UTF-16LE', $lookup[$wm_picture_type]) : ''; } public static function ASFCodecListObjectTypeLookup($codec_list_type) { - + static $lookup = array ( 0x0001 => 'Video Codec', 0x0002 => 'Audio Codec', @@ -1619,123 +1619,123 @@ class getid3_asf extends getid3_handler public static function GUIDname($guid_string) { - + static $lookup = array ( - getid3_asf::Extended_Stream_Properties_Object => 'Extended_Stream_Properties_Object', - getid3_asf::Padding_Object => 'Padding_Object', - getid3_asf::Payload_Ext_Syst_Pixel_Aspect_Ratio => 'Payload_Ext_Syst_Pixel_Aspect_Ratio', - getid3_asf::Script_Command_Object => 'Script_Command_Object', - getid3_asf::No_Error_Correction => 'No_Error_Correction', - getid3_asf::Content_Branding_Object => 'Content_Branding_Object', - getid3_asf::Content_Encryption_Object => 'Content_Encryption_Object', - getid3_asf::Digital_Signature_Object => 'Digital_Signature_Object', - getid3_asf::Extended_Content_Encryption_Object => 'Extended_Content_Encryption_Object', - getid3_asf::Simple_Index_Object => 'Simple_Index_Object', - getid3_asf::Degradable_JPEG_Media => 'Degradable_JPEG_Media', - getid3_asf::Payload_Extension_System_Timecode => 'Payload_Extension_System_Timecode', - getid3_asf::Binary_Media => 'Binary_Media', - getid3_asf::Timecode_Index_Object => 'Timecode_Index_Object', - getid3_asf::Metadata_Library_Object => 'Metadata_Library_Object', - getid3_asf::Reserved_3 => 'Reserved_3', - getid3_asf::Reserved_4 => 'Reserved_4', - getid3_asf::Command_Media => 'Command_Media', - getid3_asf::Header_Extension_Object => 'Header_Extension_Object', - getid3_asf::Media_Object_Index_Parameters_Obj => 'Media_Object_Index_Parameters_Obj', - getid3_asf::Header_Object => 'Header_Object', - getid3_asf::Content_Description_Object => 'Content_Description_Object', - getid3_asf::Error_Correction_Object => 'Error_Correction_Object', - getid3_asf::Data_Object => 'Data_Object', - getid3_asf::Web_Stream_Media_Subtype => 'Web_Stream_Media_Subtype', - getid3_asf::Stream_Bitrate_Properties_Object => 'Stream_Bitrate_Properties_Object', - getid3_asf::Language_List_Object => 'Language_List_Object', - getid3_asf::Codec_List_Object => 'Codec_List_Object', - getid3_asf::Reserved_2 => 'Reserved_2', - getid3_asf::File_Properties_Object => 'File_Properties_Object', - getid3_asf::File_Transfer_Media => 'File_Transfer_Media', - getid3_asf::Old_RTP_Extension_Data => 'Old_RTP_Extension_Data', - getid3_asf::Advanced_Mutual_Exclusion_Object => 'Advanced_Mutual_Exclusion_Object', - getid3_asf::Bandwidth_Sharing_Object => 'Bandwidth_Sharing_Object', - getid3_asf::Reserved_1 => 'Reserved_1', - getid3_asf::Bandwidth_Sharing_Exclusive => 'Bandwidth_Sharing_Exclusive', - getid3_asf::Bandwidth_Sharing_Partial => 'Bandwidth_Sharing_Partial', - getid3_asf::JFIF_Media => 'JFIF_Media', - getid3_asf::Stream_Properties_Object => 'Stream_Properties_Object', - getid3_asf::Video_Media => 'Video_Media', - getid3_asf::Audio_Spread => 'Audio_Spread', - getid3_asf::Metadata_Object => 'Metadata_Object', - getid3_asf::Payload_Ext_Syst_Sample_Duration => 'Payload_Ext_Syst_Sample_Duration', - getid3_asf::Group_Mutual_Exclusion_Object => 'Group_Mutual_Exclusion_Object', - getid3_asf::Extended_Content_Description_Object => 'Extended_Content_Description_Object', - getid3_asf::Stream_Prioritization_Object => 'Stream_Prioritization_Object', - getid3_asf::Payload_Ext_System_Content_Type => 'Payload_Ext_System_Content_Type', - getid3_asf::Old_File_Properties_Object => 'Old_File_Properties_Object', - getid3_asf::Old_ASF_Header_Object => 'Old_ASF_Header_Object', - getid3_asf::Old_ASF_Data_Object => 'Old_ASF_Data_Object', - getid3_asf::Index_Object => 'Index_Object', - getid3_asf::Old_Stream_Properties_Object => 'Old_Stream_Properties_Object', - getid3_asf::Old_Content_Description_Object => 'Old_Content_Description_Object', - getid3_asf::Old_Script_Command_Object => 'Old_Script_Command_Object', - getid3_asf::Old_Marker_Object => 'Old_Marker_Object', - getid3_asf::Old_Component_Download_Object => 'Old_Component_Download_Object', - getid3_asf::Old_Stream_Group_Object => 'Old_Stream_Group_Object', - getid3_asf::Old_Scalable_Object => 'Old_Scalable_Object', - getid3_asf::Old_Prioritization_Object => 'Old_Prioritization_Object', - getid3_asf::Bitrate_Mutual_Exclusion_Object => 'Bitrate_Mutual_Exclusion_Object', - getid3_asf::Old_Inter_Media_Dependency_Object => 'Old_Inter_Media_Dependency_Object', - getid3_asf::Old_Rating_Object => 'Old_Rating_Object', - getid3_asf::Index_Parameters_Object => 'Index_Parameters_Object', - getid3_asf::Old_Color_Table_Object => 'Old_Color_Table_Object', - getid3_asf::Old_Language_List_Object => 'Old_Language_List_Object', - getid3_asf::Old_Audio_Media => 'Old_Audio_Media', - getid3_asf::Old_Video_Media => 'Old_Video_Media', - getid3_asf::Old_Image_Media => 'Old_Image_Media', - getid3_asf::Old_Timecode_Media => 'Old_Timecode_Media', - getid3_asf::Old_Text_Media => 'Old_Text_Media', - getid3_asf::Old_MIDI_Media => 'Old_MIDI_Media', - getid3_asf::Old_Command_Media => 'Old_Command_Media', - getid3_asf::Old_No_Error_Concealment => 'Old_No_Error_Concealment', - getid3_asf::Old_Scrambled_Audio => 'Old_Scrambled_Audio', - getid3_asf::Old_No_Color_Table => 'Old_No_Color_Table', - getid3_asf::Old_SMPTE_Time => 'Old_SMPTE_Time', - getid3_asf::Old_ASCII_Text => 'Old_ASCII_Text', - getid3_asf::Old_Unicode_Text => 'Old_Unicode_Text', - getid3_asf::Old_HTML_Text => 'Old_HTML_Text', - getid3_asf::Old_URL_Command => 'Old_URL_Command', - getid3_asf::Old_Filename_Command => 'Old_Filename_Command', - getid3_asf::Old_ACM_Codec => 'Old_ACM_Codec', - getid3_asf::Old_VCM_Codec => 'Old_VCM_Codec', - getid3_asf::Old_QuickTime_Codec => 'Old_QuickTime_Codec', - getid3_asf::Old_DirectShow_Transform_Filter => 'Old_DirectShow_Transform_Filter', - getid3_asf::Old_DirectShow_Rendering_Filter => 'Old_DirectShow_Rendering_Filter', - getid3_asf::Old_No_Enhancement => 'Old_No_Enhancement', - getid3_asf::Old_Unknown_Enhancement_Type => 'Old_Unknown_Enhancement_Type', - getid3_asf::Old_Temporal_Enhancement => 'Old_Temporal_Enhancement', - getid3_asf::Old_Spatial_Enhancement => 'Old_Spatial_Enhancement', - getid3_asf::Old_Quality_Enhancement => 'Old_Quality_Enhancement', - getid3_asf::Old_Number_of_Channels_Enhancement => 'Old_Number_of_Channels_Enhancement', - getid3_asf::Old_Frequency_Response_Enhancement => 'Old_Frequency_Response_Enhancement', - getid3_asf::Old_Media_Object => 'Old_Media_Object', - getid3_asf::Mutex_Language => 'Mutex_Language', - getid3_asf::Mutex_Bitrate => 'Mutex_Bitrate', - getid3_asf::Mutex_Unknown => 'Mutex_Unknown', - getid3_asf::Old_ASF_Placeholder_Object => 'Old_ASF_Placeholder_Object', - getid3_asf::Old_Data_Unit_Extension_Object => 'Old_Data_Unit_Extension_Object', - getid3_asf::Web_Stream_Format => 'Web_Stream_Format', - getid3_asf::Payload_Ext_System_File_Name => 'Payload_Ext_System_File_Name', - getid3_asf::Marker_Object => 'Marker_Object', - getid3_asf::Timecode_Index_Parameters_Object => 'Timecode_Index_Parameters_Object', - getid3_asf::Audio_Media => 'Audio_Media', - getid3_asf::Media_Object_Index_Object => 'Media_Object_Index_Object', - getid3_asf::Alt_Extended_Content_Encryption_Obj => 'Alt_Extended_Content_Encryption_Obj' + getid3_asf::Extended_Stream_Properties_Object => 'Extended_Stream_Properties_Object', + getid3_asf::Padding_Object => 'Padding_Object', + getid3_asf::Payload_Ext_Syst_Pixel_Aspect_Ratio => 'Payload_Ext_Syst_Pixel_Aspect_Ratio', + getid3_asf::Script_Command_Object => 'Script_Command_Object', + getid3_asf::No_Error_Correction => 'No_Error_Correction', + getid3_asf::Content_Branding_Object => 'Content_Branding_Object', + getid3_asf::Content_Encryption_Object => 'Content_Encryption_Object', + getid3_asf::Digital_Signature_Object => 'Digital_Signature_Object', + getid3_asf::Extended_Content_Encryption_Object => 'Extended_Content_Encryption_Object', + getid3_asf::Simple_Index_Object => 'Simple_Index_Object', + getid3_asf::Degradable_JPEG_Media => 'Degradable_JPEG_Media', + getid3_asf::Payload_Extension_System_Timecode => 'Payload_Extension_System_Timecode', + getid3_asf::Binary_Media => 'Binary_Media', + getid3_asf::Timecode_Index_Object => 'Timecode_Index_Object', + getid3_asf::Metadata_Library_Object => 'Metadata_Library_Object', + getid3_asf::Reserved_3 => 'Reserved_3', + getid3_asf::Reserved_4 => 'Reserved_4', + getid3_asf::Command_Media => 'Command_Media', + getid3_asf::Header_Extension_Object => 'Header_Extension_Object', + getid3_asf::Media_Object_Index_Parameters_Obj => 'Media_Object_Index_Parameters_Obj', + getid3_asf::Header_Object => 'Header_Object', + getid3_asf::Content_Description_Object => 'Content_Description_Object', + getid3_asf::Error_Correction_Object => 'Error_Correction_Object', + getid3_asf::Data_Object => 'Data_Object', + getid3_asf::Web_Stream_Media_Subtype => 'Web_Stream_Media_Subtype', + getid3_asf::Stream_Bitrate_Properties_Object => 'Stream_Bitrate_Properties_Object', + getid3_asf::Language_List_Object => 'Language_List_Object', + getid3_asf::Codec_List_Object => 'Codec_List_Object', + getid3_asf::Reserved_2 => 'Reserved_2', + getid3_asf::File_Properties_Object => 'File_Properties_Object', + getid3_asf::File_Transfer_Media => 'File_Transfer_Media', + getid3_asf::Old_RTP_Extension_Data => 'Old_RTP_Extension_Data', + getid3_asf::Advanced_Mutual_Exclusion_Object => 'Advanced_Mutual_Exclusion_Object', + getid3_asf::Bandwidth_Sharing_Object => 'Bandwidth_Sharing_Object', + getid3_asf::Reserved_1 => 'Reserved_1', + getid3_asf::Bandwidth_Sharing_Exclusive => 'Bandwidth_Sharing_Exclusive', + getid3_asf::Bandwidth_Sharing_Partial => 'Bandwidth_Sharing_Partial', + getid3_asf::JFIF_Media => 'JFIF_Media', + getid3_asf::Stream_Properties_Object => 'Stream_Properties_Object', + getid3_asf::Video_Media => 'Video_Media', + getid3_asf::Audio_Spread => 'Audio_Spread', + getid3_asf::Metadata_Object => 'Metadata_Object', + getid3_asf::Payload_Ext_Syst_Sample_Duration => 'Payload_Ext_Syst_Sample_Duration', + getid3_asf::Group_Mutual_Exclusion_Object => 'Group_Mutual_Exclusion_Object', + getid3_asf::Extended_Content_Description_Object => 'Extended_Content_Description_Object', + getid3_asf::Stream_Prioritization_Object => 'Stream_Prioritization_Object', + getid3_asf::Payload_Ext_System_Content_Type => 'Payload_Ext_System_Content_Type', + getid3_asf::Old_File_Properties_Object => 'Old_File_Properties_Object', + getid3_asf::Old_ASF_Header_Object => 'Old_ASF_Header_Object', + getid3_asf::Old_ASF_Data_Object => 'Old_ASF_Data_Object', + getid3_asf::Index_Object => 'Index_Object', + getid3_asf::Old_Stream_Properties_Object => 'Old_Stream_Properties_Object', + getid3_asf::Old_Content_Description_Object => 'Old_Content_Description_Object', + getid3_asf::Old_Script_Command_Object => 'Old_Script_Command_Object', + getid3_asf::Old_Marker_Object => 'Old_Marker_Object', + getid3_asf::Old_Component_Download_Object => 'Old_Component_Download_Object', + getid3_asf::Old_Stream_Group_Object => 'Old_Stream_Group_Object', + getid3_asf::Old_Scalable_Object => 'Old_Scalable_Object', + getid3_asf::Old_Prioritization_Object => 'Old_Prioritization_Object', + getid3_asf::Bitrate_Mutual_Exclusion_Object => 'Bitrate_Mutual_Exclusion_Object', + getid3_asf::Old_Inter_Media_Dependency_Object => 'Old_Inter_Media_Dependency_Object', + getid3_asf::Old_Rating_Object => 'Old_Rating_Object', + getid3_asf::Index_Parameters_Object => 'Index_Parameters_Object', + getid3_asf::Old_Color_Table_Object => 'Old_Color_Table_Object', + getid3_asf::Old_Language_List_Object => 'Old_Language_List_Object', + getid3_asf::Old_Audio_Media => 'Old_Audio_Media', + getid3_asf::Old_Video_Media => 'Old_Video_Media', + getid3_asf::Old_Image_Media => 'Old_Image_Media', + getid3_asf::Old_Timecode_Media => 'Old_Timecode_Media', + getid3_asf::Old_Text_Media => 'Old_Text_Media', + getid3_asf::Old_MIDI_Media => 'Old_MIDI_Media', + getid3_asf::Old_Command_Media => 'Old_Command_Media', + getid3_asf::Old_No_Error_Concealment => 'Old_No_Error_Concealment', + getid3_asf::Old_Scrambled_Audio => 'Old_Scrambled_Audio', + getid3_asf::Old_No_Color_Table => 'Old_No_Color_Table', + getid3_asf::Old_SMPTE_Time => 'Old_SMPTE_Time', + getid3_asf::Old_ASCII_Text => 'Old_ASCII_Text', + getid3_asf::Old_Unicode_Text => 'Old_Unicode_Text', + getid3_asf::Old_HTML_Text => 'Old_HTML_Text', + getid3_asf::Old_URL_Command => 'Old_URL_Command', + getid3_asf::Old_Filename_Command => 'Old_Filename_Command', + getid3_asf::Old_ACM_Codec => 'Old_ACM_Codec', + getid3_asf::Old_VCM_Codec => 'Old_VCM_Codec', + getid3_asf::Old_QuickTime_Codec => 'Old_QuickTime_Codec', + getid3_asf::Old_DirectShow_Transform_Filter => 'Old_DirectShow_Transform_Filter', + getid3_asf::Old_DirectShow_Rendering_Filter => 'Old_DirectShow_Rendering_Filter', + getid3_asf::Old_No_Enhancement => 'Old_No_Enhancement', + getid3_asf::Old_Unknown_Enhancement_Type => 'Old_Unknown_Enhancement_Type', + getid3_asf::Old_Temporal_Enhancement => 'Old_Temporal_Enhancement', + getid3_asf::Old_Spatial_Enhancement => 'Old_Spatial_Enhancement', + getid3_asf::Old_Quality_Enhancement => 'Old_Quality_Enhancement', + getid3_asf::Old_Number_of_Channels_Enhancement => 'Old_Number_of_Channels_Enhancement', + getid3_asf::Old_Frequency_Response_Enhancement => 'Old_Frequency_Response_Enhancement', + getid3_asf::Old_Media_Object => 'Old_Media_Object', + getid3_asf::Mutex_Language => 'Mutex_Language', + getid3_asf::Mutex_Bitrate => 'Mutex_Bitrate', + getid3_asf::Mutex_Unknown => 'Mutex_Unknown', + getid3_asf::Old_ASF_Placeholder_Object => 'Old_ASF_Placeholder_Object', + getid3_asf::Old_Data_Unit_Extension_Object => 'Old_Data_Unit_Extension_Object', + getid3_asf::Web_Stream_Format => 'Web_Stream_Format', + getid3_asf::Payload_Ext_System_File_Name => 'Payload_Ext_System_File_Name', + getid3_asf::Marker_Object => 'Marker_Object', + getid3_asf::Timecode_Index_Parameters_Object => 'Timecode_Index_Parameters_Object', + getid3_asf::Audio_Media => 'Audio_Media', + getid3_asf::Media_Object_Index_Object => 'Media_Object_Index_Object', + getid3_asf::Alt_Extended_Content_Encryption_Obj => 'Alt_Extended_Content_Encryption_Obj' ); - + return @$lookup[$guid_string]; } public static function ASFIndexObjectIndexTypeLookup($id) { - + static $lookup = array ( 1 => 'Nearest Past Data Packet', 2 => 'Nearest Past Media Object', @@ -1748,7 +1748,7 @@ class getid3_asf extends getid3_handler public static function GUIDtoBytestring($guid_string) { - + // Microsoft defines these 16-byte (128-bit) GUIDs in the strangest way: // first 4 bytes are in little-endian order // next 2 bytes are appended in little-endian order @@ -1786,7 +1786,7 @@ class getid3_asf extends getid3_handler public static function BytestringToGUID($byte_string) { - + $guid_string = str_pad(dechex(ord($byte_string{3})), 2, '0', STR_PAD_LEFT); $guid_string .= str_pad(dechex(ord($byte_string{2})), 2, '0', STR_PAD_LEFT); $guid_string .= str_pad(dechex(ord($byte_string{1})), 2, '0', STR_PAD_LEFT); @@ -1814,18 +1814,18 @@ class getid3_asf extends getid3_handler public static function FiletimeToUNIXtime($file_time, $round=true) { - + // FILETIME is a 64-bit unsigned integer representing // the number of 100-nanosecond intervals since January 1, 1601 // UNIX timestamp is number of seconds since January 1, 1970 // 116444736000000000 = 10000000 * 60 * 60 * 24 * 365 * 369 + 89 leap days - + $time = ($file_time - 116444736000000000) / 10000000; - + if ($round) { return intval(round($time)); } - + return $time; } diff --git a/modules/getid3/module.audio-video.flv.php b/modules/getid3/module.audio-video.flv.php index fbf3887e..9249311e 100644 --- a/modules/getid3/module.audio-video.flv.php +++ b/modules/getid3/module.audio-video.flv.php @@ -44,7 +44,7 @@ class getid3_flv extends getid3_handler { - + const TAG_AUDIO = 8; const TAG_VIDEO = 9; const TAG_META = 18; @@ -53,14 +53,14 @@ class getid3_flv extends getid3_handler const VIDEO_SCREEN = 3; const VIDEO_VP6 = 4; - + public function Analyze() { $info = &$this->getid3->info; - + $info['flv'] = array (); $info_flv = &$info['flv']; - + fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET); $flv_data_length = $info['avdataend'] - $info['avdataoffset']; @@ -82,7 +82,7 @@ class getid3_flv extends getid3_handler $duration = 0; while ((ftell($this->getid3->fp) + 1) < $info['avdataend']) { - + $this_tag_header = fread($this->getid3->fp, 16); $previous_tag_length = getid3_lib::BigEndian2Int(substr($this_tag_header, 0, 4)); @@ -93,7 +93,7 @@ class getid3_flv extends getid3_handler $next_offset = ftell($this->getid3->fp) - 1 + $data_length; switch ($tag_type) { - + case getid3_flv::TAG_AUDIO: if (!isset($info_flv['audio']['audioFormat'])) { $info_flv['audio']['audioFormat'] = $last_header_byte & 0x07; @@ -115,7 +115,7 @@ class getid3_flv extends getid3_handler $picture_size_type = (getid3_lib::BigEndian2Int(substr($flv_video_header, 3, 2))) >> 7; $picture_size_type = $picture_size_type & 0x0007; $info_flv['header']['videoSizeType'] = $picture_size_type; - + switch ($picture_size_type) { case 0: $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 5, 2)); @@ -221,7 +221,7 @@ class getid3_flv extends getid3_handler public static function FLVaudioFormat($id) { - + static $lookup = array( 0 => 'uncompressed', 1 => 'ADPCM', @@ -234,7 +234,7 @@ class getid3_flv extends getid3_handler public static function FLVaudioRate($id) { - + static $lookup = array( 0 => 5500, 1 => 11025, @@ -246,7 +246,7 @@ class getid3_flv extends getid3_handler public static function FLVaudioBitDepth($id) { - + static $lookup = array( 0 => 8, 1 => 16, @@ -256,7 +256,7 @@ class getid3_flv extends getid3_handler public static function FLVvideoCodec($id) { - + static $lookup = array( getid3_flv::VIDEO_H263 => 'Sorenson H.263', getid3_flv::VIDEO_SCREEN => 'Screen video', @@ -268,52 +268,52 @@ class getid3_flv extends getid3_handler -class AMFStream +class AMFStream { public $bytes; public $pos; public function AMFStream($bytes) { - + $this->bytes = $bytes; $this->pos = 0; } public function readByte() { - + return getid3_lib::BigEndian2Int(substr($this->bytes, $this->pos++, 1)); } public function readInt() { - + return ($this->readByte() << 8) + $this->readByte(); } public function readLong() { - + return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte(); } public function readDouble() { - + return getid3_lib::BigEndian2Float($this->read(8)); } public function readUTF() { - + $length = $this->readInt(); return $this->read($length); } public function readLongUTF() { - + $length = $this->readLong(); return $this->read($length); } @@ -326,9 +326,9 @@ class AMFStream return $val; } - + public function peekByte() { - + $pos = $this->pos; $val = $this->readByte(); $this->pos = $pos; @@ -346,7 +346,7 @@ class AMFStream public function peekLong() { - + $pos = $this->pos; $val = $this->readLong(); $this->pos = $pos; @@ -354,8 +354,8 @@ class AMFStream } - public function peekDouble() { - + public function peekDouble() { + $pos = $this->pos; $val = $this->readDouble(); $this->pos = $pos; @@ -364,7 +364,7 @@ class AMFStream public function peekUTF() { - + $pos = $this->pos; $val = $this->readUTF(); $this->pos = $pos; @@ -373,7 +373,7 @@ class AMFStream public function peekLongUTF() { - + $pos = $this->pos; $val = $this->readLongUTF(); $this->pos = $pos; @@ -383,18 +383,18 @@ class AMFStream -class AMFReader +class AMFReader { public $stream; public function __construct($stream) { - + $this->stream = $stream; } public function readData() { - + $value = null; $type = $this->stream->readByte(); @@ -465,26 +465,26 @@ class AMFReader } - public function readDouble() { - + public function readDouble() { + return $this->stream->readDouble(); } public function readBoolean() { - + return $this->stream->readByte() == 1; } - - + + public function readString() { - + return $this->stream->readUTF(); } public function readObject() { - + // Get highest numerical index - ignored $highestIndex = $this->stream->readLong(); @@ -506,7 +506,7 @@ class AMFReader public function readMixedArray() { - + // Get highest numerical index - ignored $highestIndex = $this->stream->readLong(); @@ -532,7 +532,7 @@ class AMFReader public function readArray() { - + $length = $this->stream->readLong(); $data = array(); @@ -546,7 +546,7 @@ class AMFReader public function readDate() { - + $timestamp = $this->stream->readDouble(); $timezone = $this->stream->readInt(); return $timestamp; @@ -554,19 +554,19 @@ class AMFReader public function readLongString() { - + return $this->stream->readLongUTF(); } public function readXML() { - + return $this->stream->readLongUTF(); } - public function readTypedObject() { - + public function readTypedObject() { + $className = $this->stream->readUTF(); return $this->readObject(); } diff --git a/modules/getid3/module.audio-video.mpeg.php b/modules/getid3/module.audio-video.mpeg.php index a0d2cd61..0d62b0ac 100644 --- a/modules/getid3/module.audio-video.mpeg.php +++ b/modules/getid3/module.audio-video.mpeg.php @@ -22,8 +22,8 @@ // // $Id: module.audio-video.mpeg.php,v 1.3 2006/11/02 10:48:00 ah Exp $ - - + + class getid3_mpeg extends getid3_handler { @@ -35,21 +35,21 @@ class getid3_mpeg extends getid3_handler const VIDEO_SEQUENCE_END = "\x00\x00\x01\xB7"; const VIDEO_GROUP_START = "\x00\x00\x01\xB8"; const AUDIO_START = "\x00\x00\x01\xC0"; - + public function Analyze() { - + $getid3 = $this->getid3; - + $getid3->info['mpeg']['video']['raw'] = array (); $info_mpeg_video = &$getid3->info['mpeg']['video']; $info_mpeg_video_raw = &$info_mpeg_video['raw']; - + $getid3->info['video'] = array (); $info_video = &$getid3->info['video']; - + $getid3->include_module('audio.mp3'); - + if ($getid3->info['avdataend'] <= $getid3->info['avdataoffset']) { throw new getid3_exception('"avdataend" ('.$getid3->info['avdataend'].') is unexpectedly less-than-or-equal-to "avdataoffset" ('.$getid3->info['avdataoffset'].')'); } @@ -97,7 +97,7 @@ class getid3_mpeg extends getid3_handler $info_mpeg_video_raw['framesize_vertical'] = ($frame_size_dword & 0x000FFF); // 12 bits for vertical frame size $info_mpeg_video_raw['pixel_aspect_ratio'] = ($aspect_ratio_frame_rate_dword & 0xF0) >> 4; $info_mpeg_video_raw['frame_rate'] = ($aspect_ratio_frame_rate_dword & 0x0F); - + $info_mpeg_video['framesize_horizontal'] = $info_mpeg_video_raw['framesize_horizontal']; $info_mpeg_video['framesize_vertical'] = $info_mpeg_video_raw['framesize_vertical']; @@ -110,7 +110,7 @@ class getid3_mpeg extends getid3_handler $info_mpeg_video_raw['vbv_buffer_size'] = bindec(substr($assorted_information, 19, 10)); $info_mpeg_video_raw['constrained_param_flag'] = (bool)bindec($assorted_information{29}); $info_mpeg_video_raw['intra_quant_flag'] = (bool)bindec($assorted_information{30}); - + if ($info_mpeg_video_raw['intra_quant_flag']) { // read 512 bits @@ -182,7 +182,7 @@ class getid3_mpeg extends getid3_handler // clone getid3 - better safe than sorry $clone = clone $this->getid3; - + // check $mp3 = new getid3_mp3($clone); if ($mp3->decodeMPEGaudioHeader($getid3->fp, ($audio_chunk_offset + 3) + 8 + $i, $dummy, false)) { @@ -192,7 +192,7 @@ class getid3_mpeg extends getid3_handler $getid3->info['audio']['lossless'] = false; break 2; } - + // destroy copy unset($dummy); } @@ -227,7 +227,7 @@ class getid3_mpeg extends getid3_handler //} //$getid3->info['playtime_seconds'] *= $multiplier; //$getid3->warning('Interleaved MPEG audio/video playtime may be inaccurate. With current hack should be within a few seconds of accurate. Report to info@getid3.org if off by more than 10 seconds.'); - + if ($info_video['bitrate'] < 50000) { $getid3->warning('Interleaved MPEG audio/video playtime may be slightly inaccurate for video bitrates below 100kbps. Except in extreme low-bitrate situations, error should be less than 1%. Report to info@getid3.org if greater than this.'); } @@ -239,7 +239,7 @@ class getid3_mpeg extends getid3_handler public static function MPEGsystemNonOverheadPercentage($video_bitrate, $audio_bitrate) { - + $overhead_percentage = 0; $audio_bitrate = max(min($audio_bitrate / 1000, 384), 32); // limit to range of 32kbps - 384kbps (should be only legal bitrates, but maybe VBR?) @@ -264,7 +264,7 @@ class getid3_mpeg extends getid3_handler $bitrate_to_use_min = $bitrate_to_use_max = $previous_bitrate = 32; foreach ($overhead_multiplier_by_bitrate as $key => $value) { - + if ($audio_bitrate >= $previous_bitrate) { $bitrate_to_use_min = $previous_bitrate; } @@ -274,7 +274,7 @@ class getid3_mpeg extends getid3_handler } $previous_bitrate = $key; } - + $factor_a = ($bitrate_to_use_max - $audio_bitrate) / ($bitrate_to_use_max - $bitrate_to_use_min); $video_bitrate_log10 = log10($video_bitrate); @@ -295,27 +295,27 @@ class getid3_mpeg extends getid3_handler public static function MPEGvideoFramerateLookup($raw_frame_rate) { - + $lookup = array (0, 23.976, 24, 25, 29.97, 30, 50, 59.94, 60); - + return (float)(isset($lookup[$raw_frame_rate]) ? $lookup[$raw_frame_rate] : 0); } public static function MPEGvideoAspectRatioLookup($raw_aspect_ratio) { - + $lookup = array (0, 1, 0.6735, 0.7031, 0.7615, 0.8055, 0.8437, 0.8935, 0.9157, 0.9815, 1.0255, 1.0695, 1.0950, 1.1575, 1.2015, 0); - + return (float)(isset($lookup[$raw_aspect_ratio]) ? $lookup[$raw_aspect_ratio] : 0); } public static function MPEGvideoAspectRatioTextLookup($raw_aspect_ratio) { - + $lookup = array ('forbidden', 'square pixels', '0.6735', '16:9, 625 line, PAL', '0.7615', '0.8055', '16:9, 525 line, NTSC', '0.8935', '4:3, 625 line, PAL, CCIR601', '0.9815', '1.0255', '1.0695', '4:3, 525 line, NTSC, CCIR601', '1.1575', '1.2015', 'reserved'); - + return (isset($lookup[$raw_aspect_ratio]) ? $lookup[$raw_aspect_ratio] : ''); } diff --git a/modules/getid3/module.audio-video.nsv.php b/modules/getid3/module.audio-video.nsv.php index 3744dd42..a7c533c4 100644 --- a/modules/getid3/module.audio-video.nsv.php +++ b/modules/getid3/module.audio-video.nsv.php @@ -22,8 +22,8 @@ //
// $Id: module.audio-video.nsv.php,v 1.3 2006/11/02 10:48:00 ah Exp $ - - + + class getid3_nsv extends getid3_handler { @@ -41,7 +41,7 @@ class getid3_nsv extends getid3_handler $nsv_header = fread($getid3->fp, 4); switch ($nsv_header) { - + case 'NSVs': $this->getNSVsHeader(); break; @@ -67,9 +67,9 @@ class getid3_nsv extends getid3_handler private function getNSVsHeader($file_offset = 0) { - + $getid3 = $this->getid3; - + fseek($getid3->fp, $file_offset, SEEK_SET); $nsvs_header = fread($getid3->fp, 28); @@ -80,9 +80,9 @@ class getid3_nsv extends getid3_handler if ($info_nsv_NSVs['identifier'] != 'NSVs') { throw new getid3_exception('expected "NSVs" at offset ('.$file_offset.'), found "'.$info_nsv_NSVs['identifier'].'" instead'); } - + $info_nsv_NSVs['offset'] = $file_offset; - + getid3_lib::ReadSequence('LittleEndian2Int', $info_nsv_NSVs, $nsvs_header, 4, array ( 'video_codec' => -4, // string @@ -94,7 +94,7 @@ class getid3_nsv extends getid3_handler ); if ($info_nsv_NSVs['audio_codec'] == 'PCM ') { - + getid3_lib::ReadSequence('LittleEndian2Int', $info_nsv_NSVs, $nsvs_header, 24, array ( 'bits_channel' => 1, @@ -103,7 +103,7 @@ class getid3_nsv extends getid3_handler ) ); $getid3->info['audio']['sample_rate'] = $info_nsv_NSVs['sample_rate']; - + } $getid3->info['video']['resolution_x'] = $info_nsv_NSVs['resolution_x']; @@ -119,15 +119,15 @@ class getid3_nsv extends getid3_handler private function getNSVfHeader($file_offset = 0, $get_toc_offsets=false) { - + $getid3 = $this->getid3; - + fseek($getid3->fp, $file_offset, SEEK_SET); $nsvf_header = fread($getid3->fp, 28); - + $getid3->info['nsv']['NSVf'] = array (); $info_nsv_NSVf = &$getid3->info['nsv']['NSVf']; - + $info_nsv_NSVf['identifier'] = substr($nsvf_header, 0, 4); if ($info_nsv_NSVf['identifier'] != 'NSVf') { throw new getid3_exception('expected "NSVf" at offset ('.$file_offset.'), found "'.$info_nsv_NSVf['identifier'].'" instead'); @@ -145,11 +145,11 @@ class getid3_nsv extends getid3_handler 'TOC_entries_2' => 4 ) ); - + if ($info_nsv_NSVf['playtime_ms'] == 0) { throw new getid3_exception('Corrupt NSV file: NSVf.playtime_ms == zero'); } - + if ($info_nsv_NSVf['file_size'] > $getid3->info['avdataend']) { $getid3->warning('truncated file - NSVf header indicates '.$info_nsv_NSVf['file_size'].' bytes, file actually '.$getid3->info['avdataend'].' bytes'); } @@ -190,7 +190,7 @@ class getid3_nsv extends getid3_handler public static function NSVframerateLookup($frame_rate_index) { - + if ($frame_rate_index <= 127) { return (float)$frame_rate_index; } diff --git a/modules/getid3/module.audio-video.real.php b/modules/getid3/module.audio-video.real.php index 4fda21a1..c8688f72 100644 --- a/modules/getid3/module.audio-video.real.php +++ b/modules/getid3/module.audio-video.real.php @@ -22,15 +22,15 @@ // // $Id: module.audio-video.real.php,v 1.4 2006/11/02 10:48:00 ah Exp $ - - + + class getid3_real extends getid3_handler { public function Analyze() { - + $getid3 = $this->getid3; - + $getid3->include_module('audio-video.riff'); $getid3->info['fileformat'] = 'real'; @@ -41,16 +41,16 @@ class getid3_real extends getid3_handler $chunk_counter = 0; while (ftell($getid3->fp) < $getid3->info['avdataend']) { - + $chunk_data = fread($getid3->fp, 8); $chunk_name = substr($chunk_data, 0, 4); $chunk_size = getid3_lib::BigEndian2Int(substr($chunk_data, 4, 4)); if ($chunk_name == '.ra'."\xFD") { $chunk_data .= fread($getid3->fp, $chunk_size - 8); - + if ($this->ParseOldRAheader(substr($chunk_data, 0, 128), $getid3->info['real']['old_ra_header'])) { - + $getid3->info['audio']['dataformat'] = 'real'; $getid3->info['audio']['lossless'] = false; $getid3->info['audio']['sample_rate'] = $getid3->info['real']['old_ra_header']['sample_rate']; @@ -62,14 +62,14 @@ class getid3_real extends getid3_handler $getid3->info['audio']['codec'] = $this->RealAudioCodecFourCClookup($getid3->info['real']['old_ra_header']['fourcc'], $getid3->info['audio']['bitrate']); foreach ($getid3->info['real']['old_ra_header']['comments'] as $key => $value_array) { - + if (strlen(trim($value_array[0])) > 0) { $getid3->info['real']['comments'][$key][] = trim($value_array[0]); } } return true; } - + throw new getid3_exception('There was a problem parsing this RealAudio file. Please submit it for analysis to http://www.getid3.org/upload/ or info@getid3.org'); } @@ -79,7 +79,7 @@ class getid3_real extends getid3_handler $info_real_chunks_current_chunk['name'] = $chunk_name; $info_real_chunks_current_chunk['offset'] = ftell($getid3->fp) - 8; $info_real_chunks_current_chunk['length'] = $chunk_size; - + if (($info_real_chunks_current_chunk['offset'] + $info_real_chunks_current_chunk['length']) > $getid3->info['avdataend']) { $getid3->warning('Chunk "'.$info_real_chunks_current_chunk['name'].'" at offset '.$info_real_chunks_current_chunk['offset'].' claims to be '.$info_real_chunks_current_chunk['length'].' bytes long, which is beyond end of file'); return false; @@ -125,7 +125,7 @@ class getid3_real extends getid3_handler $offset += 2; if ($info_real_chunks_current_chunk['object_version'] == 0) { - + getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset, array ( 'max_bit_rate' => 4, @@ -147,7 +147,7 @@ class getid3_real extends getid3_handler if ($info_real_chunks_current_chunk['duration'] > 0) { $getid3->info['bitrate'] += $info_real_chunks_current_chunk['avg_bit_rate']; } - + $info_real_chunks_current_chunk['flags']['save_enabled'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0001); $info_real_chunks_current_chunk['flags']['perfect_play'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0002); $info_real_chunks_current_chunk['flags']['live_broadcast'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0004); @@ -176,25 +176,25 @@ class getid3_real extends getid3_handler ) ); $offset += 31; - + $info_real_chunks_current_chunk['stream_name'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['stream_name_size']); $offset += $info_real_chunks_current_chunk['stream_name_size']; - + $info_real_chunks_current_chunk['mime_type_size'] = getid3_lib::BigEndian2Int($chunk_data{$offset++}); - + $info_real_chunks_current_chunk['mime_type'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['mime_type_size']); $offset += $info_real_chunks_current_chunk['mime_type_size']; - + $info_real_chunks_current_chunk['type_specific_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4)); $offset += 4; - + $info_real_chunks_current_chunk['type_specific_data'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['type_specific_len']); $offset += $info_real_chunks_current_chunk['type_specific_len']; $info_real_chunks_current_chunk_typespecificdata = &$info_real_chunks_current_chunk['type_specific_data']; switch ($info_real_chunks_current_chunk['mime_type']) { - + case 'video/x-pn-realvideo': case 'video/x-pn-multirate-realvideo': // http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html @@ -266,14 +266,14 @@ class getid3_real extends getid3_handler if (empty($getid3->info['playtime_seconds'])) { $getid3->info['playtime_seconds'] = max($getid3->info['playtime_seconds'], ($info_real_chunks_current_chunk['duration'] + $info_real_chunks_current_chunk['start_time']) / 1000); } - + if ($info_real_chunks_current_chunk['duration'] > 0) { - + switch ($info_real_chunks_current_chunk['mime_type']) { - + case 'audio/x-pn-realaudio': case 'audio/x-pn-multirate-realaudio': - + $getid3->info['audio']['bitrate'] = (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate']; $getid3->info['audio']['codec'] = $this->RealAudioCodecFourCClookup($info_real_chunks_current_chunk['parsed_audio_data']['fourcc'], $getid3->info['audio']['bitrate']); $getid3->info['audio']['dataformat'] = 'real'; @@ -299,9 +299,9 @@ class getid3_real extends getid3_handler $getid3->info['audio']['dataformat'] = 'real'; $getid3->info['audio']['lossless'] = true; break; - + } - + $getid3->info['bitrate'] = (isset($getid3->info['video']['bitrate']) ? $getid3->info['video']['bitrate'] : 0) + (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0); } } @@ -361,7 +361,7 @@ class getid3_real extends getid3_handler if ($info_real_chunks_current_chunk['object_version'] == 0) { - getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset, + getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset, array ( 'num_indices' => 4, 'stream_number' => 2, @@ -389,9 +389,9 @@ class getid3_real extends getid3_handler } if (!empty($getid3->info['audio']['streams'])) { - + $getid3->info['audio']['bitrate'] = 0; - + foreach ($getid3->info['audio']['streams'] as $key => $value_array) { $getid3->info['audio']['bitrate'] += $value_array['bitrate']; } @@ -408,17 +408,17 @@ class getid3_real extends getid3_handler $parsed_array = array (); $parsed_array['magic'] = substr($old_ra_header_data, 0, 4); - + if ($parsed_array['magic'] != '.ra'."\xFD") { return false; } - + $parsed_array['version1'] = getid3_lib::BigEndian2Int(substr($old_ra_header_data, 4, 2)); if ($parsed_array['version1'] < 3) { return false; - } + } if ($parsed_array['version1'] == 3) { @@ -437,20 +437,20 @@ class getid3_real extends getid3_handler 'audio_bytes' => 4, ) ); - + $parsed_array['comments_raw'] = substr($old_ra_header_data, 22, $parsed_array['header_size'] - 22 + 1); // not including null terminator $comment_offset = 0; - + foreach (array ('title', 'artist', 'copyright') as $name) { $comment_length = getid3_lib::BigEndian2Int($parsed_array['comments_raw']{$comment_offset++}); $parsed_array['comments'][$name][]= substr($parsed_array['comments_raw'], $comment_offset, $comment_length); $comment_offset += $comment_length; } - + $comment_offset++; // final null terminator (?) $comment_offset++; // fourcc length (?) should be 4 - + $parsed_array['fourcc'] = substr($old_ra_header_data, 23 + $comment_offset, 4); @@ -478,7 +478,7 @@ class getid3_real extends getid3_handler switch ($parsed_array['version1']) { case 4: - + getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 48, array ( 'sample_rate' => 2, @@ -497,7 +497,7 @@ class getid3_real extends getid3_handler $parsed_array['comments_raw'] = substr($old_ra_header_data, 69, $parsed_array['header_size'] - 69 + 16); $comment_offset = 0; - + foreach (array ('title', 'artist', 'copyright') as $name) { $comment_length = getid3_lib::BigEndian2Int($parsed_array['comments_raw']{$comment_offset++}); $parsed_array['comments'][$name][]= substr($parsed_array['comments_raw'], $comment_offset, $comment_length); @@ -507,7 +507,7 @@ class getid3_real extends getid3_handler case 5: - + getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 48, array ( 'sample_rate' => 4, @@ -520,15 +520,15 @@ class getid3_real extends getid3_handler ); $parsed_array['comments'] = array (); break; - + } - + $parsed_array['fourcc'] = $parsed_array['fourcc3']; } foreach ($parsed_array['comments'] as $key => $value) { - + if ($parsed_array['comments'][$key][0] === false) { $parsed_array['comments'][$key][0] = ''; } @@ -541,11 +541,11 @@ class getid3_real extends getid3_handler public static function RealAudioCodecFourCClookup($fourcc, $bitrate) { - // http://www.its.msstate.edu/net/real/reports/config/tags.stats + // http://www.its.msstate.edu/net/real/reports/config/tags.stats // http://www.freelists.org/archives/matroska-devel/06-2003/fullthread18.html - + static $lookup; - + if (empty($lookup)) { $lookup['14_4'][8000] = 'RealAudio v2 (14.4kbps)'; $lookup['14.4'][8000] = 'RealAudio v2 (14.4kbps)'; @@ -572,17 +572,17 @@ class getid3_real extends getid3_handler $lookup['cook'][0] = 'RealAudio G2'; $lookup['atrc'][0] = 'RealAudio 8'; } - + $round_bitrate = intval(round($bitrate)); - + if (isset($lookup[$fourcc][$round_bitrate])) { return $lookup[$fourcc][$round_bitrate]; } - + if (isset($lookup[$fourcc][0])) { return $lookup[$fourcc][0]; } - + return $fourcc; } diff --git a/modules/getid3/module.audio-video.riff.php b/modules/getid3/module.audio-video.riff.php index 5cecd67c..6da6b3bf 100644 --- a/modules/getid3/module.audio-video.riff.php +++ b/modules/getid3/module.audio-video.riff.php @@ -26,8 +26,8 @@ // // $Id: module.audio-video.riff.php,v 1.10 2006/12/03 20:13:17 ah Exp $ - - + + class getid3_riff extends getid3_handler { @@ -35,7 +35,7 @@ class getid3_riff extends getid3_handler public function Analyze() { - + $getid3 = $this->getid3; $getid3->info['riff']['raw'] = array (); @@ -53,11 +53,11 @@ class getid3_riff extends getid3_handler $this->fseek($info_avdataoffset, SEEK_SET); $riff_header = $this->fread(12); - + $riff_sub_type = substr($riff_header, 8, 4); - + switch (substr($riff_header, 0, 4)) { - + case 'FORM': $getid3->info['fileformat'] = 'aiff'; $this->endian_function = 'BigEndian2Int'; @@ -89,18 +89,18 @@ class getid3_riff extends getid3_handler default: throw new getid3_exception('Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?) - expecting "FORM|RIFF|SDSS|RMP3" found "'.$riff_sub_type.'" instead'); } - + $endian_function = $this->endian_function; $stream_index = 0; switch ($riff_sub_type) { case 'WAVE': - + if (empty($info_audio['bitrate_mode'])) { $info_audio['bitrate_mode'] = 'cbr'; } - + if (empty($info_audio_dataformat)) { $info_audio_dataformat = 'wav'; } @@ -109,9 +109,9 @@ class getid3_riff extends getid3_handler $info_avdataoffset = $info_riff_wave['data'][0]['offset'] + 8; $info_avdataend = $info_avdataoffset + $info_riff_wave['data'][0]['size']; } - + if (isset($info_riff_wave['fmt '][0]['data'])) { - + $info_riff_audio[$stream_index] = getid3_riff::RIFFparseWAVEFORMATex($info_riff_wave['fmt '][0]['data']); $info_audio['wformattag'] = $info_riff_audio[$stream_index]['raw']['wFormatTag']; $info_riff_raw['fmt '] = $info_riff_audio[$stream_index]['raw']; @@ -125,11 +125,11 @@ class getid3_riff extends getid3_handler $info_audio['bitrate'] = $info_riff_audio[$stream_index]['bitrate']; $getid3->info['playtime_seconds'] = (float)((($info_avdataend - $info_avdataoffset) * 8) / $info_audio['bitrate']); - + $info_audio['lossless'] = false; if (isset($info_riff_wave['data'][0]['offset']) && isset($info_riff_raw['fmt ']['wFormatTag'])) { - + switch ($info_riff_raw['fmt ']['wFormatTag']) { case 0x0001: // PCM @@ -146,7 +146,7 @@ class getid3_riff extends getid3_handler } } - + $info_audio['streams'][$stream_index]['wformattag'] = $info_audio['wformattag']; $info_audio['streams'][$stream_index]['bitrate_mode'] = $info_audio['bitrate_mode']; $info_audio['streams'][$stream_index]['lossless'] = $info_audio['lossless']; @@ -169,7 +169,7 @@ class getid3_riff extends getid3_handler $n_track_rg_adjust_bit_string = str_pad(decbin($info_riff_raw_rgad['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT); $n_album_rg_adjust_bit_string = str_pad(decbin($info_riff_raw_rgad['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT); - + $info_riff_raw_rgad_track['name'] = bindec(substr($n_track_rg_adjust_bit_string, 0, 3)); $info_riff_raw_rgad_track['originator'] = bindec(substr($n_track_rg_adjust_bit_string, 3, 3)); $info_riff_raw_rgad_track['signbit'] = bindec($n_track_rg_adjust_bit_string[6]); @@ -185,7 +185,7 @@ class getid3_riff extends getid3_handler $info_riff['rgad']['track']['originator'] = getid3_lib_replaygain::OriginatorLookup($info_riff_raw_rgad_track['originator']); $info_riff['rgad']['track']['adjustment'] = getid3_lib_replaygain::AdjustmentLookup($info_riff_raw_rgad_track['adjustment'], $info_riff_raw_rgad_track['signbit']); } - + if (($info_riff_raw_rgad_album['name'] != 0) && ($info_riff_raw_rgad_album['originator'] != 0)) { $info_riff['rgad']['album']['name'] = getid3_lib_replaygain::NameLookup($info_riff_raw_rgad_album['name']); $info_riff['rgad']['album']['originator'] = getid3_lib_replaygain::OriginatorLookup($info_riff_raw_rgad_album['originator']); @@ -194,7 +194,7 @@ class getid3_riff extends getid3_handler } if (isset($info_riff_wave['fact'][0]['data'])) { - + $info_riff_raw['fact']['NumberOfSamples'] = getid3_lib::$endian_function(substr($info_riff_wave['fact'][0]['data'], 0, 4)); // This should be a good way of calculating exact playtime, but some sample files have had incorrect number of samples, so cannot use this method @@ -202,14 +202,14 @@ class getid3_riff extends getid3_handler // $getid3->info['playtime_seconds'] = (float)$info_riff_raw['fact']['NumberOfSamples'] / $info_riff_raw['fmt ']['nSamplesPerSec']; // } } - - + + if (!empty($info_riff_raw['fmt ']['nAvgBytesPerSec'])) { $info_audio['bitrate'] = (int)$info_riff_raw['fmt ']['nAvgBytesPerSec'] * 8; } if (isset($info_riff_wave['bext'][0]['data'])) { - + $info_riff_wave_bext_0 = &$info_riff_wave['bext'][0]; getid3_lib::ReadSequence('LittleEndian2Int', $info_riff_wave_bext_0, $info_riff_wave_bext_0['data'], 0, @@ -224,11 +224,11 @@ class getid3_riff extends getid3_handler 'reserved' => 254 ) ); - + foreach (array ('title', 'author', 'reference') as $key) { $info_riff_wave_bext_0[$key] = trim($info_riff_wave_bext_0[$key]); } - + $info_riff_wave_bext_0['coding_history'] = explode("\r\n", trim(substr($info_riff_wave_bext_0['data'], 601))); $info_riff_wave_bext_0['origin_date_unix'] = gmmktime(substr($info_riff_wave_bext_0['origin_time'], 0, 2), @@ -243,7 +243,7 @@ class getid3_riff extends getid3_handler } if (isset($info_riff_wave['MEXT'][0]['data'])) { - + $info_riff_wave_mext_0 = &$info_riff_wave['MEXT'][0]; $info_riff_wave_mext_0['raw']['sound_information'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_mext_0['data'], 0, 2)); @@ -263,7 +263,7 @@ class getid3_riff extends getid3_handler } if (isset($info_riff_wave['cart'][0]['data'])) { - + $info_riff_wave_cart_0 = &$info_riff_wave['cart'][0]; getid3_lib::ReadSequence('LittleEndian2Int', $info_riff_wave_cart_0, $info_riff_wave_cart_0['data'], 0, @@ -285,23 +285,23 @@ class getid3_riff extends getid3_handler 'user_defined_text' => -64, ) ); - + foreach (array ('artist', 'cut_id', 'client_id', 'category', 'classification', 'out_cue', 'start_date', 'start_time', 'end_date', 'end_time', 'producer_app_id', 'producer_app_version', 'user_defined_text') as $key) { $info_riff_wave_cart_0[$key] = trim($info_riff_wave_cart_0[$key]); } - + $info_riff_wave_cart_0['zero_db_reference'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_cart_0['data'], 680, 4), true); - + for ($i = 0; $i < 8; $i++) { $info_riff_wave_cart_0['post_time'][$i]['usage_fourcc'] = substr($info_riff_wave_cart_0['data'], 684 + ($i * 8), 4); $info_riff_wave_cart_0['post_time'][$i]['timer_value'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_cart_0['data'], 684 + ($i * 8) + 4, 4)); - } + } $info_riff_wave_cart_0['url'] = trim(substr($info_riff_wave_cart_0['data'], 748, 1024)); $info_riff_wave_cart_0['tag_text'] = explode("\r\n", trim(substr($info_riff_wave_cart_0['data'], 1772))); - + $info_riff['comments']['artist'][] = $info_riff_wave_cart_0['artist']; $info_riff['comments']['title'][] = $info_riff_wave_cart_0['title']; - } + } if (!isset($info_audio['bitrate']) && isset($info_riff_audio[$stream_index]['bitrate'])) { $info_audio['bitrate'] = $info_riff_audio[$stream_index]['bitrate']; @@ -309,28 +309,28 @@ class getid3_riff extends getid3_handler } if (@$getid3->info['wavpack']) { - + if (!$this->data_string_flag) { - + $info_audio_dataformat = 'wavpack'; $info_audio['bitrate_mode'] = 'vbr'; $info_audio['encoder'] = 'WavPack v'.$getid3->info['wavpack']['version']; - + // Reset to the way it was - RIFF parsing will have messed this up $info_avdataend = $original['avdataend']; $info_audio['bitrate'] = (($info_avdataend - $info_avdataoffset) * 8) / $getid3->info['playtime_seconds']; - + $this->fseek($info_avdataoffset - 44, SEEK_SET); $riff_data = $this->fread(44); $orignal_riff_header_size = getid3_lib::LittleEndian2Int(substr($riff_data, 4, 4)) + 8; $orignal_riff_data_size = getid3_lib::LittleEndian2Int(substr($riff_data, 40, 4)) + 44; - + if ($orignal_riff_header_size > $orignal_riff_data_size) { $info_avdataend -= ($orignal_riff_header_size - $orignal_riff_data_size); $this->fseek($info_avdataend, SEEK_SET); $riff_data .= $this->fread($orignal_riff_header_size - $orignal_riff_data_size); } - + // move the data chunk after all other chunks (if any) // so that the RIFF parser doesn't see EOF when trying // to skip over the data chunk @@ -339,18 +339,18 @@ class getid3_riff extends getid3_handler // Save audio info key $saved_info_audio = $info_audio; - // Analyze riff_data + // Analyze riff_data $this->AnalyzeString($riff_data); - + // Restore info key $info_audio = $saved_info_audio; } } if (isset($info_riff_raw['fmt ']['wFormatTag'])) { - + switch ($info_riff_raw['fmt ']['wFormatTag']) { - + case 0x08AE: // ClearJump LiteWave $info_audio['bitrate_mode'] = 'vbr'; $info_audio_dataformat = 'litewave'; @@ -436,7 +436,7 @@ class getid3_riff extends getid3_handler $getid3->warning('File should probably be padded to nearest WORD boundary, but it is not (expecting '.$info_riff[$riff_sub_type]['data'][0]['size'].' bytes of data, only found '.($getid3->info['filesize'] - $info_avdataoffset).' therefore short by '.($info_riff[$riff_sub_type]['data'][0]['size'] - ($getid3->info['filesize'] - $info_avdataoffset)).' bytes)'); $info_avdataend = $getid3->info['filesize']; break; - + } // Short by more than one byte, throw warning $getid3->warning('Probably truncated file - expecting '.$info_riff[$riff_sub_type]['data'][0]['size'].' bytes of data, only found '.($getid3->info['filesize'] - $info_avdataoffset).' (short by '.($info_riff[$riff_sub_type]['data'][0]['size'] - ($getid3->info['filesize'] - $info_avdataoffset)).' bytes)'); @@ -444,14 +444,14 @@ class getid3_riff extends getid3_handler break; } } - + if (!empty($getid3->info['mpeg']['audio']['LAME']['audio_bytes'])) { if ((($info_avdataend - $info_avdataoffset) - $getid3->info['mpeg']['audio']['LAME']['audio_bytes']) == 1) { $info_avdataend--; $getid3->warning('Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored'); } } - + if (@$info_audio_dataformat == 'ac3') { unset($info_audio['bits_per_sample']); if (!empty($getid3->info['ac3']['bitrate']) && ($getid3->info['ac3']['bitrate'] != $info_audio['bitrate'])) { @@ -480,8 +480,8 @@ class getid3_riff extends getid3_handler $info_riff_raw['avih'] = array (); $info_riff_raw_avih = &$info_riff_raw['avih']; - - getid3_lib::ReadSequence($this->endian_function, $info_riff_raw_avih, $avihData, 0, + + getid3_lib::ReadSequence($this->endian_function, $info_riff_raw_avih, $avihData, 0, array ( 'dwMicroSecPerFrame' => 4, // frame display rate (or 0L) 'dwMaxBytesPerSec' => 4, // max. transfer rate @@ -514,12 +514,12 @@ class getid3_riff extends getid3_handler $info_riff_video_current['frame_width'] = $info_riff_raw_avih['dwWidth']; $info_video['resolution_x'] = $info_riff_video_current['frame_width']; } - + if ($info_riff_raw_avih['dwHeight'] > 0) { $info_riff_video_current['frame_height'] = $info_riff_raw_avih['dwHeight']; $info_video['resolution_y'] = $info_riff_video_current['frame_height']; } - + if ($info_riff_raw_avih['dwTotalFrames'] > 0) { $info_riff_video_current['total_frames'] = $info_riff_raw_avih['dwTotalFrames']; $info_video['total_frames'] = $info_riff_video_current['total_frames']; @@ -528,7 +528,7 @@ class getid3_riff extends getid3_handler $info_riff_video_current['frame_rate'] = round(1000000 / $info_riff_raw_avih['dwMicroSecPerFrame'], 3); $info_video['frame_rate'] = $info_riff_video_current['frame_rate']; } - + if (isset($info_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) { if (is_array($info_riff['AVI ']['hdrl']['strl']['strh'])) { for ($i = 0; $i < count($info_riff['AVI ']['hdrl']['strl']['strh']); $i++) { @@ -571,7 +571,7 @@ class getid3_riff extends getid3_handler $info_audio['lossless'] = false; switch ($info_riff_raw_strf_strh_fcc_type_stream_index['wFormatTag']) { - + case 0x0001: // PCM $info_audio_dataformat = 'wav'; $info_audio['lossless'] = true; @@ -618,8 +618,8 @@ class getid3_riff extends getid3_handler // shortcut $info_riff_raw['strh'][$i] = array (); $info_riff_raw_strh_current = &$info_riff_raw['strh'][$i]; - - getid3_lib::ReadSequence($this->endian_function, $info_riff_raw_strh_current, $strh_data, 0, + + getid3_lib::ReadSequence($this->endian_function, $info_riff_raw_strh_current, $strh_data, 0, array ( 'fccType' => -4, // same as $strh_fcc_type; 'fccHandler' => -4, @@ -640,17 +640,17 @@ class getid3_riff extends getid3_handler $info_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($info_riff_raw_strh_current['fccHandler']); $info_video['fourcc'] = $info_riff_raw_strh_current['fccHandler']; - + if (!$info_riff_video_current['codec'] && isset($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']) && getid3_riff::RIFFfourccLookup($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc'])) { $info_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']); $info_video['fourcc'] = $info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']; } - + $info_video['codec'] = $info_riff_video_current['codec']; $info_video['pixel_aspect_ratio'] = (float)1; - + switch ($info_riff_raw_strh_current['fccHandler']) { - + case 'HFYU': // Huffman Lossless Codec case 'IRAW': // Intel YUV Uncompressed case 'YUY2': // Uncompressed YUV 4:2:2 @@ -663,7 +663,7 @@ class getid3_riff extends getid3_handler } switch ($strh_fcc_type) { - + case 'vids': getid3_lib::ReadSequence($this->endian_function, $info_riff_raw_strf_strh_fcc_type_stream_index, $strf_data, 0, array ( @@ -709,7 +709,7 @@ class getid3_riff extends getid3_handler $info_video['fourcc'] = $info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']; switch ($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']) { - + case 'HFYU': // Huffman Lossless Codec case 'IRAW': // Intel YUV Uncompressed case 'YUY2': // Uncompressed YUV 4:2:2 @@ -739,10 +739,10 @@ class getid3_riff extends getid3_handler $info_avdataoffset = 44; if (isset($info_riff['CDDA']['fmt '][0]['data'])) { - + $info_riff_cdda_fmt_0 = &$info_riff['CDDA']['fmt '][0]; - getid3_lib::ReadSequence($this->endian_function, $info_riff_cdda_fmt_0, $info_riff_cdda_fmt_0['data'], 0, + getid3_lib::ReadSequence($this->endian_function, $info_riff_cdda_fmt_0, $info_riff_cdda_fmt_0['data'], 0, array ( 'unknown1' => 2, 'track_num' => 2, @@ -804,9 +804,9 @@ class getid3_riff extends getid3_handler $info_riff_audio['codec_fourcc'] = substr($info_riff_RIFFsubtype_COMM_0_data, 18, 4); $codec_name_size = getid3_lib::BigEndian2Int(substr($info_riff_RIFFsubtype_COMM_0_data, 22, 1)); $info_riff_audio['codec_name'] = substr($info_riff_RIFFsubtype_COMM_0_data, 23, $codec_name_size); - + switch ($info_riff_audio['codec_name']) { - + case 'NONE': $info_audio['codec'] = 'Pulse Code Modulation (PCM)'; $info_audio['lossless'] = true; @@ -814,7 +814,7 @@ class getid3_riff extends getid3_handler case '': switch ($info_riff_audio['codec_fourcc']) { - + // http://developer.apple.com/qa/snd/snd07.html case 'sowt': $info_riff_audio['codec_name'] = 'Two\'s Compliment Little-Endian PCM'; @@ -839,31 +839,31 @@ class getid3_riff extends getid3_handler } $info_audio['channels'] = $info_riff_audio['channels']; - + if ($info_riff_audio['bits_per_sample'] > 0) { $info_audio['bits_per_sample'] = $info_riff_audio['bits_per_sample']; } - + $info_audio['sample_rate'] = $info_riff_audio['sample_rate']; $getid3->info['playtime_seconds'] = $info_riff_audio['total_samples'] / $info_audio['sample_rate']; } if (isset($info_riff[$riff_sub_type]['COMT'])) { - + $comment_count = getid3_lib::BigEndian2Int(substr($info_riff[$riff_sub_type]['COMT'][0]['data'], 0, 2)); $offset = 2; - + for ($i = 0; $i < $comment_count; $i++) { - + $getid3->info['comments_raw'][$i]['timestamp'] = getid3_lib::BigEndian2Int( substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, 4)); - $offset += 4; - + $offset += 4; + $getid3->info['comments_raw'][$i]['marker_id'] = getid3_lib::BigEndianSyncSafe2Int(substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, 2)); - $offset += 2; - + $offset += 2; + $comment_length = getid3_lib::BigEndian2Int( substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, 2)); - $offset += 2; - + $offset += 2; + $getid3->info['comments_raw'][$i]['comment'] = substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, $comment_length); $offset += $comment_length; @@ -899,7 +899,7 @@ class getid3_riff extends getid3_handler // shortcut $info_riff_riff_sub_type_vhdr_0 = &$info_riff[$riff_sub_type]['VHDR'][0]; - getid3_lib::ReadSequence('BigEndian2Int', $info_riff_riff_sub_type_vhdr_0, $info_riff_riff_sub_type_vhdr_0['data'], 0, + getid3_lib::ReadSequence('BigEndian2Int', $info_riff_riff_sub_type_vhdr_0, $info_riff_riff_sub_type_vhdr_0['data'], 0, array ( 'oneShotHiSamples' => 4, 'repeatHiSamples' => 4, @@ -910,7 +910,7 @@ class getid3_riff extends getid3_handler 'Volume' => -4 ) ); - + $info_riff_riff_sub_type_vhdr_0['Volume'] = getid3_riff::FixedPoint16_16($info_riff_riff_sub_type_vhdr_0['Volume']); $info_audio['sample_rate'] = $info_riff_riff_sub_type_vhdr_0['samplesPerSec']; @@ -967,25 +967,25 @@ class getid3_riff extends getid3_handler case 'CDXA': - + $getid3->info['mime_type'] = 'video/mpeg'; if (!empty($info_riff['CDXA']['data'][0]['size'])) { $GETID3_ERRORARRAY = &$getid3->info['warning']; - + if (!$getid3->include_module_optional('audio-video.mpeg')) { $getid3->warning('MPEG skipped because mpeg module is missing.'); } - + else { - + // Clone getid3 - messing with offsets - better safe than sorry $clone = clone $getid3; - + // Analyse $mpeg = new getid3_mpeg($clone); $mpeg->Analyze(); - // Import from clone and destroy + // Import from clone and destroy $getid3->info['audio'] = $clone->info['audio']; $getid3->info['video'] = $clone->info['video']; $getid3->info['mpeg'] = $clone->info['mpeg']; @@ -994,26 +994,26 @@ class getid3_riff extends getid3_handler unset($clone); } } - + break; default: throw new getid3_exception('Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA), found "'.$riff_sub_type.'" instead'); } - - + + if (@$info_riff_raw['fmt ']['wFormatTag'] == 1) { - + // http://www.mega-nerd.com/erikd/Blog/Windiots/dts.html $this->fseek($getid3->info['avdataoffset'], SEEK_SET); $bytes4 = $this->fread(4); - + // DTSWAV if (preg_match('/^\xFF\x1F\x00\xE8/s', $bytes4)) { $info_audio_dataformat = 'dts'; - } - + } + // DTS, but this probably shouldn't happen elseif (preg_match('/^\x7F\xFF\x80\x01/s', $bytes4)) { $info_audio_dataformat = 'dts'; @@ -1023,13 +1023,13 @@ class getid3_riff extends getid3_handler if (@is_array($info_riff_wave['DISP'])) { $info_riff['comments']['title'][] = trim(substr($info_riff_wave['DISP'][count($info_riff_wave['DISP']) - 1]['data'], 4)); } - + if (@is_array($info_riff_wave['INFO'])) { getid3_riff::RIFFCommentsParse($info_riff_wave['INFO'], $info_riff['comments']); } - + if (isset($info_riff_wave['INFO']) && is_array($info_riff_wave['INFO'])) { - + foreach (array ('IARL' => 'archivallocation', 'IART' => 'artist', 'ICDS' => 'costumedesigner', 'ICMS' => 'commissionedby', 'ICMT' => 'comment', 'ICNT' => 'country', 'ICOP' => 'copyright', 'ICRD' => 'creationdate', 'IDIM' => 'dimensions', 'IDIT' => 'digitizationdate', 'IDPI' => 'resolution', 'IDST' => 'distributor', 'IEDT' => 'editor', 'IENG' => 'engineers', 'IFRM' => 'accountofparts', 'IGNR' => 'genre', 'IKEY' => 'keywords', 'ILGT' => 'lightness', 'ILNG' => 'language', 'IMED' => 'orignalmedium', 'IMUS' => 'composer', 'INAM' => 'title', 'IPDS' => 'productiondesigner', 'IPLT' => 'palette', 'IPRD' => 'product', 'IPRO' => 'producer', 'IPRT' => 'part', 'IRTD' => 'rating', 'ISBJ' => 'subject', 'ISFT' => 'software', 'ISGN' => 'secondarygenre', 'ISHP' => 'sharpness', 'ISRC' => 'sourcesupplier', 'ISRF' => 'digitizationsource', 'ISTD' => 'productionstudio', 'ISTR' => 'starring', 'ITCH' => 'encoded_by', 'IWEB' => 'url', 'IWRI' => 'writer') as $key => $value) { if (isset($info_riff_wave['INFO'][$key])) { foreach ($info_riff_wave['INFO'][$key] as $comment_id => $comment_data) { @@ -1157,34 +1157,34 @@ class getid3_riff extends getid3_handler public function ParseRIFF($start_offset, $max_offset) { - + $getid3 = $this->getid3; - + $info = &$getid3->info; - + $endian_function = $this->endian_function; $max_offset = min($max_offset, $info['avdataend']); - + $riff_chunk = false; $this->fseek($start_offset, SEEK_SET); - + while ($this->ftell() < $max_offset) { - + $chunk_name = $this->fread(4); - + if (strlen($chunk_name) < 4) { throw new getid3_exception('Expecting chunk name at offset '.($this->ftell() - 4).' but found nothing. Aborting RIFF parsing.'); } - + $chunk_size = getid3_lib::$endian_function($this->fread(4)); - + if ($chunk_size == 0) { continue; throw new getid3_exception('Chunk size at offset '.($this->ftell() - 4).' is zero. Aborting RIFF parsing.'); } - + if (($chunk_size % 2) != 0) { // all structures are packed on word boundaries $chunk_size++; @@ -1194,16 +1194,16 @@ class getid3_riff extends getid3_handler case 'LIST': $list_name = $this->fread(4); - + switch ($list_name) { - + case 'movi': case 'rec ': $riff_chunk[$list_name]['offset'] = $this->ftell() - 4; $riff_chunk[$list_name]['size'] = $chunk_size; static $parsed_audio_stream = false; - + if (!$parsed_audio_stream) { $where_we_were = $this->ftell(); $audio_chunk_header = $this->fread(12); @@ -1214,62 +1214,62 @@ class getid3_riff extends getid3_handler if ($audio_chunk_stream_type == 'wb') { $first_four_bytes = substr($audio_chunk_header, 8, 4); - + //// MPEG - + if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', $first_four_bytes)) { if (!$getid3->include_module_optional('audio.mp3')) { $getid3->warning('MP3 skipped because mp3 module is missing.'); } - + elseif (getid3_mp3::MPEGaudioHeaderBytesValid($first_four_bytes)) { - + // Clone getid3 - messing with offsets - better safe than sorry $clone = clone $getid3; $clone->info['avdataoffset'] = $this->ftell() - 4; $clone->info['avdataend'] = $this->ftell() + $audio_chunk_size; - + $mp3 = new getid3_mp3($clone); $mp3->AnalyzeMPEGaudioInfo(); - + // Import from clone and destroy if (isset($clone->info['mpeg']['audio'])) { - + $info['mpeg']['audio'] = $clone->info['mpeg']['audio']; - + $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer']; $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; $info['audio']['channels'] = $info['mpeg']['audio']['channels']; $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); $info['bitrate'] = $info['audio']['bitrate']; - + $getid3->warning($clone->warnings()); unset($clone); } } - } - + } + //// AC3-WAVE - + elseif (preg_match('/^\x0B\x77/s', $first_four_bytes)) { if (!$getid3->include_module_optional('audio.ac3')) { $getid3->warning('AC3 skipped because ac3 module is missing.'); } - + else { - + // Clone getid3 - messing with offsets - better safe than sorry $clone = clone $getid3; - $clone->info['avdataoffset'] = $this->ftell() - 4; + $clone->info['avdataoffset'] = $this->ftell() - 4; $clone->info['avdataend'] = $this->ftell() + $audio_chunk_size; - + // Analyze clone by fp $ac3 = new getid3_ac3($clone); $ac3->Analyze(); - + // Import from clone and destroy $info['audio'] = $clone->info['audio']; $info['ac3'] = $clone->info['ac3']; @@ -1301,7 +1301,7 @@ class getid3_riff extends getid3_handler default: - + $this_index = 0; if (isset($riff_chunk[$chunk_name]) && is_array($riff_chunk[$chunk_name])) { $this_index = count($riff_chunk[$chunk_name]); @@ -1319,33 +1319,33 @@ class getid3_riff extends getid3_handler //// This is probably MP3 data if ((strlen($riff_data_chunk_contents_test) > 0) && preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', substr($riff_data_chunk_contents_test, 0, 4))) { - + try { - + if (!$getid3->include_module_optional('audio.mp3')) { $getid3->warning('MP3 skipped because mp3 module is missing.'); } - - + + // Clone getid3 - messing with offsets - better safe than sorry $clone = clone $getid3; - + if (getid3_mp3::MPEGaudioHeaderBytesValid(substr($riff_data_chunk_contents_test, 0, 4))) { - + $mp3 = new getid3_mp3($clone); $mp3->AnalyzeMPEGaudioInfo(); - + // Import from clone and destroy if (isset($clone->info['mpeg']['audio'])) { - + $info['mpeg']['audio'] = $clone->info['mpeg']['audio']; - + $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; $info['audio']['channels'] = $info['mpeg']['audio']['channels']; $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); $info['bitrate'] = $info['audio']['bitrate']; - + $getid3->warning($clone->warnings()); unset($clone); } @@ -1354,66 +1354,66 @@ class getid3_riff extends getid3_handler catch (Exception $e) { // do nothing - not MP3 data } - } - - + } + + //// This is probably AC-3 data - + elseif ((strlen($riff_data_chunk_contents_test) > 0) && (substr($riff_data_chunk_contents_test, 0, 2) == "\x0B\x77")) { if (!$getid3->include_module_optional('audio.ac3')) { $getid3->warning('AC3 skipped because ac3 module is missing.'); } - + else { // Clone getid3 - messing with offsets - better safe than sorry $clone = clone $getid3; $clone->info['avdataoffset'] = $riff_chunk[$chunk_name][$this_index]['offset']; $clone->info['avdataend'] = $clone->info['avdataoffset'] + $riff_chunk[$chunk_name][$this_index]['size']; - + // Analyze clone by fp $ac3 = new getid3_ac3($clone); $ac3->Analyze(); - + // Import from clone and destroy $info['audio'] = $clone->info['audio']; $info['ac3'] = $clone->info['ac3']; $getid3->warning($clone->warnings()); unset($clone); } - } - - + } + + // Dolby Digital WAV // AC-3 content, but not encoded in same format as normal AC-3 file // For one thing, byte order is swapped - + elseif ((strlen($riff_data_chunk_contents_test) > 0) && (substr($riff_data_chunk_contents_test, 8, 2) == "\x77\x0B")) { if (!$getid3->include_module_optional('audio.ac3')) { $getid3->warning('AC3 skipped because ac3 module is missing.'); } - + else { - + // Extract ac3 data to string - $ac3_data = ''; + $ac3_data = ''; for ($i = 0; $i < 28; $i += 2) { // swap byte order $ac3_data .= substr($riff_data_chunk_contents_test, 8 + $i + 1, 1); $ac3_data .= substr($riff_data_chunk_contents_test, 8 + $i + 0, 1); } - + // Clone getid3 - messing with offsets - better safe than sorry $clone = clone $getid3; $clone->info['avdataoffset'] = 0; $clone->info['avdataend'] = 20; - + // Analyse clone by string $ac3 = new getid3_ac3($clone); $ac3->AnalyzeString($ac3_data); - + // Import from clone and destroy $info['audio'] = $clone->info['audio']; $info['ac3'] = $clone->info['ac3']; @@ -1422,7 +1422,7 @@ class getid3_riff extends getid3_handler } } - + if ((strlen($riff_data_chunk_contents_test) > 0) && (substr($riff_data_chunk_contents_test, 0, 4) == 'wvpk')) { // This is WavPack data @@ -1481,7 +1481,7 @@ class getid3_riff extends getid3_handler private function RIFFparseWavPackHeader($wavpack3_chunk_data) { - + // typedef struct { // char ckID [4]; // long ckSize; @@ -1496,13 +1496,13 @@ class getid3_riff extends getid3_handler $info_wavpack = &$this->getid3->info['wavpack']; $info_wavpack['version'] = getid3_lib::LittleEndian2Int(substr($wavpack3_chunk_data, 0, 2)); - + if ($info_wavpack['version'] >= 2) { $info_wavpack['bits'] = getid3_lib::LittleEndian2Int(substr($wavpack3_chunk_data, 2, 2)); } - + if ($info_wavpack['version'] >= 3) { - + getid3_lib::ReadSequence('LittleEndian2Int', $info_wavpack, $wavpack3_chunk_data, 4, array ( 'flags_raw' => 2, @@ -1514,7 +1514,7 @@ class getid3_riff extends getid3_handler 'extra_bc' => 1 ) ); - + for ($i = 0; $i < 3; $i++) { $info_wavpack['extras'][] = getid3_lib::LittleEndian2Int($wavpack3_chunk_data{25 + $i}); } @@ -1546,27 +1546,27 @@ class getid3_riff extends getid3_handler return true; } - - - + + + public function AnalyzeString(&$string) { - + // Rewrite header_size in header $new_header_size = getid3_lib::LittleEndian2String(strlen($string), 4); for ($i = 0; $i < 4; $i++) { $string{$i + 4} = $new_header_size{$i}; } - + return parent::AnalyzeString($string); } - + public static function RIFFparseWAVEFORMATex($wave_format_ex_data) { - + $wave_format_ex['raw'] = array (); $wave_format_ex_raw = &$wave_format_ex['raw']; - + getid3_lib::ReadSequence('LittleEndian2Int', $wave_format_ex_raw, $wave_format_ex_data, 0, array ( 'wFormatTag' => 2, @@ -1577,7 +1577,7 @@ class getid3_riff extends getid3_handler 'wBitsPerSample' => 2 ) ); - + if (strlen($wave_format_ex_data) > 16) { $wave_format_ex_raw['cbSize'] = getid3_lib::LittleEndian2Int(substr($wave_format_ex_data, 16, 2)); } @@ -1756,7 +1756,7 @@ class getid3_riff extends getid3_handler 0xFFFE => 'WAVE_FORMAT_EXTENSIBLE', 0xFFFF => 'WAVE_FORMAT_DEVELOPMENT' ); - + return @$lookup[$w_format_tag]; } @@ -2144,14 +2144,14 @@ class getid3_riff extends getid3_handler 'ZLIB' => 'Lossless Codec Library zlib compression (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm)', 'ZPEG' => 'Metheus Video Zipper' ); - + return @$lookup[$four_cc]; } public static function RIFFcommentsParse(&$riff_info_aray, &$comments_target_array) { - + static $lookup = array( 'IARL' => 'archivallocation', 'IART' => 'artist', @@ -2193,7 +2193,7 @@ class getid3_riff extends getid3_handler 'IWEB' => 'url', 'IWRI' => 'writer' ); - + foreach ($lookup as $key => $value) { if (isset($riff_info_aray[$key])) { foreach ($riff_info_aray[$key] as $comment_id => $comment_data) { @@ -2205,9 +2205,9 @@ class getid3_riff extends getid3_handler } return true; } - - - + + + public static function array_merge_noclobber($array1, $array2) { if (!is_array($array1) || !is_array($array2)) { return false; @@ -2222,27 +2222,27 @@ class getid3_riff extends getid3_handler } return $new_array; } - - - + + + public static function DateMac2Unix($mac_date) { - + // Macintosh timestamp: seconds since 00:00h January 1, 1904 // UNIX timestamp: seconds since 00:00h January 1, 1970 return (int)($mac_date - 2082844800); } - - - + + + public static function FixedPoint16_16($raw_data) { - + return getid3_lib::BigEndian2Int(substr($raw_data, 0, 2)) + (float)(getid3_lib::BigEndian2Int(substr($raw_data, 2, 2)) / 65536); // pow(2, 16) = 65536 } - - - + + + function BigEndian2Float($byte_word) { - + // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic // http://www.psc.edu/general/software/packages/ieee/ieee.html // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html diff --git a/modules/getid3/module.audio-video.swf.php b/modules/getid3/module.audio-video.swf.php index 312a1a39..137dc85d 100644 --- a/modules/getid3/module.audio-video.swf.php +++ b/modules/getid3/module.audio-video.swf.php @@ -22,15 +22,15 @@ //
// $Id: module.audio-video.swf.php,v 1.2 2006/11/02 10:48:00 ah Exp $ - - + + class getid3_swf extends getid3_handler { public function Analyze() { - + $getid3 = $this->getid3; - + $getid3->info['fileformat'] = 'swf'; $getid3->info['video']['dataformat'] = 'swf'; @@ -42,7 +42,7 @@ class getid3_swf extends getid3_handler $getid3->info['swf']['header']['signature'] = substr($swf_file_data, 0, 3); switch ($getid3->info['swf']['header']['signature']) { - + case 'FWS': $getid3->info['swf']['header']['compressed'] = false; break; @@ -75,11 +75,11 @@ class getid3_swf extends getid3_handler $frame_size_bits_per_value = (ord(substr($swf_file_data, 8, 1)) & 0xF8) >> 3; $frame_size_data_length = ceil((5 + (4 * $frame_size_bits_per_value)) / 8); $frame_size_data_string = str_pad(decbin(ord($swf_file_data[8]) & 0x07), 3, '0', STR_PAD_LEFT); - + for ($i = 1; $i < $frame_size_data_length; $i++) { $frame_size_data_string .= str_pad(decbin(ord(substr($swf_file_data, 8 + $i, 1))), 8, '0', STR_PAD_LEFT); } - + list($x1, $x2, $y1, $y2) = explode("\n", wordwrap($frame_size_data_string, $frame_size_bits_per_value, "\n", 1)); $getid3->info['swf']['header']['frame_width'] = bindec($x2); $getid3->info['swf']['header']['frame_height'] = bindec($y2); @@ -126,7 +126,7 @@ class getid3_swf extends getid3_handler $tag_data['id'] = $tag_ID; $tag_data['data'] = substr($swf_file_data, $current_offset, $tag_length); switch ($tag_ID) { - + case 0: // end of movie break 2; diff --git a/modules/getid3/module.audio.aac_adif.php b/modules/getid3/module.audio.aac_adif.php index 8f1a6853..9b2f72b6 100644 --- a/modules/getid3/module.audio.aac_adif.php +++ b/modules/getid3/module.audio.aac_adif.php @@ -22,14 +22,14 @@ //
// $Id: module.audio.aac_adif.php,v 1.3 2006/11/02 10:48:00 ah Exp $ - - + + class getid3_aac_adif extends getid3_handler { public function Analyze() { - $getid3 = $this->getid3; + $getid3 = $this->getid3; // http://faac.sourceforge.net/wiki/index.php?page=ADIF // http://libmpeg.org/mpeg4/doc/w2203tfs.pdf @@ -49,19 +49,19 @@ class getid3_aac_adif extends getid3_handler // program_config_element() // } // } - + $getid3->info['fileformat'] = 'aac'; $getid3->info['audio']['dataformat'] = 'aac'; $getid3->info['audio']['lossless'] = false; - + $getid3->info['aac']['header'] = array () ; $info_aac = &$getid3->info['aac']; $info_aac_header = & $info_aac['header']; fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $aac_header_bitstream = getid3_lib::BigEndian2Bin(fread($getid3->fp, 1024)); - + $info_aac['header_type'] = 'ADIF'; $info_aac_header['mpeg_version'] = 4; $bit_offset = 32; @@ -71,7 +71,7 @@ class getid3_aac_adif extends getid3_handler $info_aac_header['copyright_id'] = getid3_aac_adif::Bin2String(substr($aac_header_bitstream, $bit_offset, 72)); $bit_offset += 72; } - + $info_aac_header['original_copy'] = $aac_header_bitstream{$bit_offset++} == '1'; $info_aac_header['home'] = $aac_header_bitstream{$bit_offset++} == '1'; $info_aac_header['is_vbr'] = $aac_header_bitstream{$bit_offset++} == '1'; @@ -80,14 +80,14 @@ class getid3_aac_adif extends getid3_handler $getid3->info['audio']['bitrate_mode'] = 'vbr'; $info_aac_header['bitrate_max'] = bindec(substr($aac_header_bitstream, $bit_offset, 23)); $bit_offset += 23; - } + } else { $getid3->info['audio']['bitrate_mode'] = 'cbr'; $info_aac_header['bitrate'] = bindec(substr($aac_header_bitstream, $bit_offset, 23)); $bit_offset += 23; $getid3->info['audio']['bitrate'] = $info_aac_header['bitrate']; } - + $info_aac_header['num_program_configs'] = 1 + bindec(substr($aac_header_bitstream, $bit_offset, 4)); $bit_offset += 4; @@ -140,7 +140,7 @@ class getid3_aac_adif extends getid3_handler // for (i = 0; i < comment_field_bytes; i++) { // comment_field_data[i] 8 // } - + $info_aac['program_configs'][$i] = array (); $info_aac_program_configs_i = &$info_aac['program_configs'][$i]; @@ -148,7 +148,7 @@ class getid3_aac_adif extends getid3_handler $info_aac_program_configs_i['buffer_fullness'] = bindec(substr($aac_header_bitstream, $bit_offset, 20)); $bit_offset += 20; } - + $info_aac_program_configs_i['element_instance_tag'] = bindec(substr($aac_header_bitstream, $bit_offset, 4)); $info_aac_program_configs_i['object_type'] = bindec(substr($aac_header_bitstream, $bit_offset + 4, 2)); $info_aac_program_configs_i['sampling_frequency_index'] = bindec(substr($aac_header_bitstream, $bit_offset + 6, 4)); @@ -159,26 +159,26 @@ class getid3_aac_adif extends getid3_handler $info_aac_program_configs_i['num_assoc_data_elements'] = bindec(substr($aac_header_bitstream, $bit_offset + 24, 3)); $info_aac_program_configs_i['num_valid_cc_elements'] = bindec(substr($aac_header_bitstream, $bit_offset + 27, 4)); $bit_offset += 31; - + $info_aac_program_configs_i['mono_mixdown_present'] = $aac_header_bitstream{$bit_offset++} == 1; if ($info_aac_program_configs_i['mono_mixdown_present']) { $info_aac_program_configs_i['mono_mixdown_element_number'] = bindec(substr($aac_header_bitstream, $bit_offset, 4)); $bit_offset += 4; } - + $info_aac_program_configs_i['stereo_mixdown_present'] = $aac_header_bitstream{$bit_offset++} == 1; if ($info_aac_program_configs_i['stereo_mixdown_present']) { $info_aac_program_configs_i['stereo_mixdown_element_number'] = bindec(substr($aac_header_bitstream, $bit_offset, 4)); $bit_offset += 4; } - + $info_aac_program_configs_i['matrix_mixdown_idx_present'] = $aac_header_bitstream{$bit_offset++} == 1; if ($info_aac_program_configs_i['matrix_mixdown_idx_present']) { $info_aac_program_configs_i['matrix_mixdown_idx'] = bindec(substr($aac_header_bitstream, $bit_offset, 2)); $bit_offset += 2; $info_aac_program_configs_i['pseudo_surround_enable'] = $aac_header_bitstream{$bit_offset++} == 1; } - + for ($j = 0; $j < $info_aac_program_configs_i['num_front_channel_elements']; $j++) { $info_aac_program_configs_i['front_element_is_cpe'][$j] = $aac_header_bitstream{$bit_offset++} == 1; $info_aac_program_configs_i['front_element_tag_select'][$j] = bindec(substr($aac_header_bitstream, $bit_offset, 4)); @@ -212,19 +212,19 @@ class getid3_aac_adif extends getid3_handler $info_aac_program_configs_i['comment_field_bytes'] = bindec(substr($aac_header_bitstream, $bit_offset, 8)); $bit_offset += 8; - + $info_aac_program_configs_i['comment_field'] = getid3_aac_adif::Bin2String(substr($aac_header_bitstream, $bit_offset, 8 * $info_aac_program_configs_i['comment_field_bytes'])); $bit_offset += 8 * $info_aac_program_configs_i['comment_field_bytes']; $info_aac_header['profile_text'] = getid3_aac_adif::AACprofileLookup($info_aac_program_configs_i['object_type'], $info_aac_header['mpeg_version']); $info_aac_program_configs_i['sampling_frequency'] = $getid3->info['audio']['sample_rate'] = getid3_aac_adif::AACsampleRateLookup($info_aac_program_configs_i['sampling_frequency_index']); $getid3->info['audio']['channels'] = getid3_aac_adif::AACchannelCountCalculate($info_aac_program_configs_i); - + if ($info_aac_program_configs_i['comment_field']) { $info_aac['comments'][] = $info_aac_program_configs_i['comment_field']; } } - + $getid3->info['playtime_seconds'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['audio']['bitrate']; $getid3->info['audio']['encoder_options'] = $info_aac['header_type'].' '.$info_aac_header['profile_text']; @@ -242,11 +242,11 @@ class getid3_aac_adif extends getid3_handler } return $string; } - - - + + + public static function AACsampleRateLookup($samplerate_id) { - + static $lookup = array ( 0 => 96000, 1 => 88200, @@ -271,14 +271,14 @@ class getid3_aac_adif extends getid3_handler public static function AACprofileLookup($profile_id, $mpeg_version) { - + static $lookup = array ( - 2 => array ( + 2 => array ( 0 => 'Main profile', 1 => 'Low Complexity profile (LC)', 2 => 'Scalable Sample Rate profile (SSR)', 3 => '(reserved)' - ), + ), 4 => array ( 0 => 'AAC_MAIN', 1 => 'AAC_LC', @@ -292,17 +292,17 @@ class getid3_aac_adif extends getid3_handler public static function AACchannelCountCalculate($program_configs) { - + $channels = 0; - + foreach (array ('front', 'side', 'back') as $placement) { for ($i = 0; $i < $program_configs['num_'.$placement.'_channel_elements']; $i++) { - + // Each element is channel pair (CPE = Channel Pair Element) $channels += 1 + ($program_configs[$placement.'_element_is_cpe'][$i] ? 1 : 0); } } - + return $channels + $program_configs['num_lfe_channel_elements']; } diff --git a/modules/getid3/module.audio.aac_adts.php b/modules/getid3/module.audio.aac_adts.php index 1b98c4c6..bf252997 100644 --- a/modules/getid3/module.audio.aac_adts.php +++ b/modules/getid3/module.audio.aac_adts.php @@ -22,43 +22,43 @@ // // $Id: module.audio.aac_adts.php,v 1.4 2006/11/02 10:48:01 ah Exp $ - - + + class getid3_aac_adts extends getid3_handler { public $option_max_frames_to_scan = 1000000; public $option_return_extended_info = false; - + private $decbin_cache; private $bitrate_cache; - + public function __construct(getID3 $getid3) { - + parent::__construct($getid3); - + // Populate bindec_cache for ($i = 0; $i < 256; $i++) { $this->decbin_cache[chr($i)] = str_pad(decbin($i), 8, '0', STR_PAD_LEFT); } - + // Init cache $this->bitrate_cache = array (); - + // Fast scanning? if (!$getid3->option_accurate_results) { $this->option_max_frames_to_scan = 200; $getid3->warning('option_accurate_results set to false - bitrate and playing time are not accurate.'); } } - - + + public function Analyze() { - + $getid3 = $this->getid3; // based loosely on code from AACfile by Jurgen Faul <jfaulØgmx.de> @@ -97,7 +97,7 @@ class getid3_aac_adts extends getid3_handler $byte_offset = $frame_number = 0; while (true) { - + // Breaks out when end-of-file encountered, or invalid data found, // or MaxFramesToScan frames have been scanned @@ -117,10 +117,10 @@ class getid3_aac_adts extends getid3_handler for ($i = 0; $i < 10; $i++) { $aac_header_bitstream .= $this->decbin_cache[$sub_string[$i]]; } - + $sync_test = bindec(substr($aac_header_bitstream, 0, 12)); $bit_offset = 12; - + if ($sync_test != 0x0FFF) { throw new getid3_exception('Synch pattern (0x0FFF) not found at offset '.(ftell($getid3->fp) - 10).' (found 0x0'.strtoupper(dechex($sync_test)).' instead)'); } @@ -130,8 +130,8 @@ class getid3_aac_adts extends getid3_handler // MPEG-4: 20, // MPEG-2: 18 $bit_offset += $aac_header_bitstream[$bit_offset] ? 18 : 20; - } - + } + // Gather info for first frame only - this takes time to do 1000 times! else { @@ -143,30 +143,30 @@ class getid3_aac_adts extends getid3_handler $info_aac_header['mpeg_version'] = $aac_header_bitstream{$bit_offset++} == '0' ? 4 : 2; $info_aac_header['layer'] = bindec(substr($aac_header_bitstream, $bit_offset, 2)); $bit_offset += 2; - + if ($info_aac_header['layer'] != 0) { throw new getid3_exception('Layer error - expected 0x00, found 0x'.dechex($info_aac_header['layer']).' instead'); } - + $info_aac_header['crc_present'] = $aac_header_bitstream{$bit_offset++} == '0' ? true : false; - + $info_aac_header['profile_id'] = bindec(substr($aac_header_bitstream, $bit_offset, 2)); $bit_offset += 2; - + $info_aac_header['profile_text'] = getid3_aac_adts::AACprofileLookup($info_aac_header['profile_id'], $info_aac_header['mpeg_version']); $info_aac_header['sample_frequency_index'] = bindec(substr($aac_header_bitstream, $bit_offset, 4)); $bit_offset += 4; - + $info_aac_header['sample_frequency'] = getid3_aac_adts::AACsampleRateLookup($info_aac_header['sample_frequency_index']); - + $getid3->info['audio']['sample_rate'] = $info_aac_header['sample_frequency']; $info_aac_header['private'] = $aac_header_bitstream{$bit_offset++} == 1; - + $info_aac_header['channel_configuration'] = $getid3->info['audio']['channels'] = bindec(substr($aac_header_bitstream, $bit_offset, 3)); $bit_offset += 3; - + $info_aac_header['original'] = $aac_header_bitstream{$bit_offset++} == 1; $info_aac_header['home'] = $aac_header_bitstream{$bit_offset++} == 1; @@ -194,12 +194,12 @@ class getid3_aac_adts extends getid3_handler $info_aac[$frame_number]['aac_frame_length'] = $frame_length; $bit_offset += 13; - + $info_aac[$frame_number]['adts_buffer_fullness'] = bindec(substr($aac_header_bitstream, $bit_offset, 11)); $bit_offset += 11; - + $getid3->info['audio']['bitrate_mode'] = ($info_aac[$frame_number]['adts_buffer_fullness'] == 0x07FF) ? 'vbr' : 'cbr'; - + $info_aac[$frame_number]['num_raw_data_blocks'] = bindec(substr($aac_header_bitstream, $bit_offset, 2)); $bit_offset += 2; @@ -230,10 +230,10 @@ class getid3_aac_adts extends getid3_handler } } - - + + public static function AACsampleRateLookup($samplerate_id) { - + static $lookup = array ( 0 => 96000, 1 => 88200, @@ -258,14 +258,14 @@ class getid3_aac_adts extends getid3_handler public static function AACprofileLookup($profile_id, $mpeg_version) { - + static $lookup = array ( - 2 => array ( + 2 => array ( 0 => 'Main profile', 1 => 'Low Complexity profile (LC)', 2 => 'Scalable Sample Rate profile (SSR)', 3 => '(reserved)' - ), + ), 4 => array ( 0 => 'AAC_MAIN', 1 => 'AAC_LC', diff --git a/modules/getid3/module.audio.ac3.php b/modules/getid3/module.audio.ac3.php index a50c5163..53c31c92 100644 --- a/modules/getid3/module.audio.ac3.php +++ b/modules/getid3/module.audio.ac3.php @@ -22,15 +22,15 @@ // // $Id: module.audio.ac3.php,v 1.3 2006/11/02 10:48:01 ah Exp $ - - + + class getid3_ac3 extends getid3_handler { public function Analyze() { $getid3 = $this->getid3; - + // http://www.atsc.org/standards/a_52a.pdf $getid3->info['fileformat'] = 'ac3'; @@ -61,7 +61,7 @@ class getid3_ac3 extends getid3_handler if ($info_ac3_raw['synchinfo']['synchword'] != "\x0B\x77") { throw new getid3_exception('Expecting "\x0B\x77" at offset '.$getid3->info['avdataoffset'].', found \x'.strtoupper(dechex($ac3_header['syncinfo']{0})).'\x'.strtoupper(dechex($ac3_header['syncinfo']{1})).' instead'); - } + } // syncinfo() { @@ -117,7 +117,7 @@ class getid3_ac3 extends getid3_handler break; } $getid3->info['audio']['channels'] = $info_ac3['num_channels']; - + $offset = 11; if ($info_ac3_raw_bsi['acmod'] & 0x01) { @@ -159,7 +159,7 @@ class getid3_ac3 extends getid3_handler if ($info_ac3_raw_bsi['compre_flag']) { $info_ac3_raw_bsi['compr'] = bindec(substr($ac3_header['bsi'], $offset, 8)); $offset += 8; - + $info_ac3['heavy_compression'] = getid3_ac3::AC3heavyCompression($info_ac3_raw_bsi['compr']); } @@ -173,7 +173,7 @@ class getid3_ac3 extends getid3_handler if ($info_ac3_raw_bsi['audprodie']) { $info_ac3_raw_bsi['mixlevel'] = bindec(substr($ac3_header['bsi'], $offset, 5)); $offset += 5; - + $info_ac3_raw_bsi['roomtyp'] = bindec(substr($ac3_header['bsi'], $offset, 2)); $offset += 2; @@ -191,14 +191,14 @@ class getid3_ac3 extends getid3_handler // The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent. $info_ac3_raw_bsi['dialnorm2'] = bindec(substr($ac3_header['bsi'], $offset, 5)); $offset += 5; - + $info_ac3['dialogue_normalization2'] = '-'.$info_ac3_raw_bsi['dialnorm2'].'dB'; $info_ac3_raw_bsi['compre_flag2'] = $ac3_header['bsi']{$offset++} == '1'; if ($info_ac3_raw_bsi['compre_flag2']) { $info_ac3_raw_bsi['compr2'] = bindec(substr($ac3_header['bsi'], $offset, 8)); $offset += 8; - + $info_ac3['heavy_compression2'] = getid3_ac3::AC3heavyCompression($info_ac3_raw_bsi['compr2']); } @@ -212,7 +212,7 @@ class getid3_ac3 extends getid3_handler if ($info_ac3_raw_bsi['audprodie2']) { $info_ac3_raw_bsi['mixlevel2'] = bindec(substr($ac3_header['bsi'], $offset, 5)); $offset += 5; - + $info_ac3_raw_bsi['roomtyp2'] = bindec(substr($ac3_header['bsi'], $offset, 2)); $offset += 2; @@ -278,11 +278,11 @@ class getid3_ac3 extends getid3_handler 6 => 'associated service: emergency (E)', 7 => 'main audio service: karaoke' ); - + if ($bsmod == 7 && $acmod == 1) { return 'associated service: voice over (VO)'; } - + return (isset($lookup[$bsmod]) ? $lookup[$bsmod] : false); } @@ -307,7 +307,7 @@ class getid3_ac3 extends getid3_handler public static function AC3centerMixLevelLookup($cmixlev) { - + static $lookup; if (!@$lookup) { $lookup = array ( @@ -323,7 +323,7 @@ class getid3_ac3 extends getid3_handler public static function AC3surroundMixLevelLookup($surmixlev) { - + static $lookup; if (!@$lookup) { $lookup = array ( @@ -348,11 +348,11 @@ class getid3_ac3 extends getid3_handler ); return (isset($lookup[$dsurmod]) ? $lookup[$dsurmod] : false); } - - + + public static function AC3channelsEnabledLookup($acmod, $lfeon) { - + return array ( 'ch1' => $acmod == 0, 'ch2' => $acmod == 0, @@ -422,7 +422,7 @@ class getid3_ac3 extends getid3_handler public static function AC3roomTypeLookup($roomtyp) { - + static $lookup = array ( 0 => 'not indicated', 1 => 'large room, X curve monitor', @@ -435,7 +435,7 @@ class getid3_ac3 extends getid3_handler public static function AC3frameSizeLookup($frmsizecod, $fscod) { - + $padding = (bool)($frmsizecod % 2); $frame_size_id = floor($frmsizecod / 2); @@ -470,7 +470,7 @@ class getid3_ac3 extends getid3_handler public static function AC3bitrateLookup($frmsizecod) { - + static $lookup = array ( 0 => 32000, 1 => 40000, diff --git a/modules/getid3/module.audio.au.php b/modules/getid3/module.audio.au.php index d4cd8444..2fbb3f17 100644 --- a/modules/getid3/module.audio.au.php +++ b/modules/getid3/module.audio.au.php @@ -22,15 +22,15 @@ //
// $Id: module.audio.au.php,v 1.2 2006/11/02 10:48:01 ah Exp $ - - + + class getid3_au extends getid3_handler { public function Analyze() { $getid3 = $this->getid3; - + fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $au_header = fread($getid3->fp, 8); @@ -48,7 +48,7 @@ class getid3_au extends getid3_handler $au_header .= fread($getid3->fp, $info_au['header_length'] - 8); $getid3->info['avdataoffset'] += $info_au['header_length']; - getid3_lib::ReadSequence('BigEndian2Int', $info_au, $au_header, 8, + getid3_lib::ReadSequence('BigEndian2Int', $info_au, $au_header, 8, array ( 'data_size' => 4, 'data_format_id'=> 4, @@ -82,7 +82,7 @@ class getid3_au extends getid3_handler public static function AUdataFormatNameLookup($id) { - + static $lookup = array ( 0 => 'unspecified format', 1 => '8-bit mu-law', @@ -113,14 +113,14 @@ class getid3_au extends getid3_handler 26 => 'CCITT g.723 5-bit ADPCM', 27 => 'A-Law 8-bit' ); - + return (isset($lookup[$id]) ? $lookup[$id] : false); } public static function AUdataFormatBitsPerSampleLookup($id) { - + static $lookup = array ( 1 => 8, 2 => 8, @@ -151,7 +151,7 @@ class getid3_au extends getid3_handler public static function AUdataFormatUsedBitsPerSampleLookup($id) { - + static $lookup = array ( 1 => 8, 2 => 8, diff --git a/modules/getid3/module.audio.avr.php b/modules/getid3/module.audio.avr.php index a3fb059f..69e8a154 100644 --- a/modules/getid3/module.audio.avr.php +++ b/modules/getid3/module.audio.avr.php @@ -22,15 +22,15 @@ //
// $Id: module.audio.avr.php,v 1.2 2006/11/02 10:48:01 ah Exp $ - - + + class getid3_avr extends getid3_handler { public function Analyze() { $getid3 = $this->getid3; - + // http://cui.unige.ch/OSG/info/AudioFormats/ap11.html // http://www.btinternet.com/~AnthonyJ/Atari/programming/avr_format.html // offset type length name comments @@ -76,7 +76,7 @@ class getid3_avr extends getid3_handler $getid3->info['avr'] = array (); $info_avr = &$getid3->info['avr']; - + $getid3->info['fileformat'] = 'avr'; $info_avr['raw']['magic'] = '2BIT'; @@ -86,7 +86,7 @@ class getid3_avr extends getid3_handler $getid3->info['avdataoffset'] += 128; $info_avr['sample_name'] = rtrim(substr($avr_header, 4, 8)); - + $info_avr['raw']['mono'] = getid3_lib::BigEndian2Int(substr($avr_header, 12, 2)); $info_avr['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($avr_header, 14, 2)); $info_avr['raw']['signed'] = getid3_lib::BigEndian2Int(substr($avr_header, 16, 2)); diff --git a/modules/getid3/module.audio.bonk.php b/modules/getid3/module.audio.bonk.php index 71f27723..e9cb79cd 100644 --- a/modules/getid3/module.audio.bonk.php +++ b/modules/getid3/module.audio.bonk.php @@ -22,22 +22,22 @@ //
// $Id: module.audio.bonk.php,v 1.3 2006/11/02 10:48:01 ah Exp $ - - + + class getid3_bonk extends getid3_handler { public function Analyze() { $getid3 = $this->getid3; - + $getid3->info['bonk'] = array (); $info_bonk = &$getid3->info['bonk']; $info_bonk['dataoffset'] = $getid3->info['avdataoffset']; $info_bonk['dataend'] = $getid3->info['avdataend']; - + // Scan-from-end method, for v0.6 and higher fseek($getid3->fp, $info_bonk['dataend'] - 8, SEEK_SET); $possible_bonk_tag = fread($getid3->fp, 8); @@ -54,7 +54,7 @@ class getid3_bonk extends getid3_handler $info_bonk[$bonk_tag_name]['size'] = $bonk_tag_size; $info_bonk[$bonk_tag_name]['offset'] = $bonk_tag_offset; $this->HandleBonkTags($bonk_tag_name); - + $next_tag_end_offset = $bonk_tag_offset - 8; if ($next_tag_end_offset < $info_bonk['dataoffset']) { if (empty($getid3->info['audio']['encoder'])) { @@ -119,7 +119,7 @@ class getid3_bonk extends getid3_handler } - + private function HandleBonkTags(&$bonk_tag_name) { // Shortcut to getid3 pointer @@ -127,14 +127,14 @@ class getid3_bonk extends getid3_handler $info_audio = &$getid3->info['audio']; switch ($bonk_tag_name) { - + case 'BONK': // shortcut $info_bonk_BONK = &$getid3->info['bonk']['BONK']; $bonk_data = "\x00".'BONK'.fread($getid3->fp, 17); - - getid3_lib::ReadSequence('LittleEndian2Int', $info_bonk_BONK, $bonk_data, 5, + + getid3_lib::ReadSequence('LittleEndian2Int', $info_bonk_BONK, $bonk_data, 5, array ( 'version' => 1, 'number_samples' => 4, @@ -147,7 +147,7 @@ class getid3_bonk extends getid3_handler 'samples_per_packet' => 2 ) ); - + $info_bonk_BONK['lossless'] = (bool)$info_bonk_BONK['lossless']; $info_bonk_BONK['joint_stereo'] = (bool)$info_bonk_BONK['joint_stereo']; @@ -208,7 +208,7 @@ class getid3_bonk extends getid3_handler // ID3v2 checking is optional if (class_exists('getid3_id3v2')) { - + $id3v2 = new getid3_id3v2($getid3); $id3v2->option_starting_offset = $getid3->info['bonk'][' ID3']['offset'] + 2; $getid3->info['bonk'][' ID3']['valid'] = $id3v2->Analyze(); @@ -223,10 +223,10 @@ class getid3_bonk extends getid3_handler } - + public static function BonkIsValidTagName($possible_bonk_tag, $ignore_case=false) { - - $ignore_case = $ignore_case ? 'i' : ''; + + $ignore_case = $ignore_case ? 'i' : ''; return preg_match('/^(BONK|INFO| ID3|META)$/'.$ignore_case, $possible_bonk_tag); } diff --git a/modules/getid3/module.audio.dts.php b/modules/getid3/module.audio.dts.php index 8de0a565..75e68ed0 100644 --- a/modules/getid3/module.audio.dts.php +++ b/modules/getid3/module.audio.dts.php @@ -22,19 +22,19 @@ // // $Id: module.audio.dts.php,v 1.2 2006/11/16 13:14:26 ah Exp $ - - + + // Specs taken from "DTS Coherent Acoustics;Core and Extensions, ETSI TS 102 114 V1.2.1 (2002-12)" // (http://pda.etsi.org/pda/queryform.asp) // With thanks to Gambit <macteam@users.sourceforge.net> http://mac.sourceforge.net/atl/ - + class getid3_dts extends getid3_handler { public function Analyze() { - + $getid3 = $this->getid3; - + $getid3->info['dts'] = array (); $info_dts = &$getid3->info['dts']; @@ -99,7 +99,7 @@ class getid3_dts extends getid3_handler public static function DTSbitrateLookup($index) { - + static $lookup = array ( 0 => 32000, 1 => 56000, @@ -137,9 +137,9 @@ class getid3_dts extends getid3_handler return @$lookup[$index]; } - + public static function DTSsampleRateLookup($index) { - + static $lookup = array ( 0 => 'invalid', 1 => 8000, @@ -161,9 +161,9 @@ class getid3_dts extends getid3_handler return @$lookup[$index]; } - + public static function DTSbitPerSampleLookup($index) { - + static $lookup = array ( 0 => 16, 1 => 20, @@ -173,38 +173,38 @@ class getid3_dts extends getid3_handler return @$lookup[$index]; } - + public static function DTSnumChannelsLookup($index) { - + switch ($index) { case 0: return 1; - + case 1: case 2: case 3: case 4: return 2; - + case 5: case 6: return 3; - + case 7: case 8: return 4; - + case 9: return 5; - + case 10: case 11: case 12: return 6; - + case 13: return 7; - + case 14: case 15: return 8; @@ -212,9 +212,9 @@ class getid3_dts extends getid3_handler return false; } - + public static function DTSchannelArrangementLookup($index) { - + static $lookup = array ( 0 => 'A', 1 => 'A + B (dual mono)', @@ -236,13 +236,13 @@ class getid3_dts extends getid3_handler return (@$lookup[$index] ? @$lookup[$index] : 'user-defined'); } - + public static function DTSdialogNormalization($index, $version) { - + switch ($version) { case 7: return 0 - $index; - + case 6: return 0 - 16 - $index; } diff --git a/modules/getid3/module.audio.la.php b/modules/getid3/module.audio.la.php index 6b54b018..f68071e1 100644 --- a/modules/getid3/module.audio.la.php +++ b/modules/getid3/module.audio.la.php @@ -22,20 +22,20 @@ //
// $Id: module.audio.la.php,v 1.2 2006/11/02 10:48:01 ah Exp $ - - + + class getid3_la extends getid3_handler { public function Analyze() { - + $getid3 = $this->getid3; - + $getid3->include_module('audio-video.riff'); - + fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $raw_data = fread($getid3->fp, getid3::FREAD_BUFFER_SIZE); - + $getid3->info['fileformat'] = 'la'; $getid3->info['audio']['dataformat'] = 'la'; $getid3->info['audio']['lossless'] = true; @@ -45,12 +45,12 @@ class getid3_la extends getid3_handler $getid3->info['la']['version'] = (float)$getid3->info['la']['version_major'] + ($getid3->info['la']['version_minor'] / 10); $getid3->info['la']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($raw_data, 4, 4)); - + $wave_chunk = substr($raw_data, 8, 4); if ($wave_chunk !== 'WAVE') { throw new getid3_exception('Expected "WAVE" ('.getid3_lib::PrintHexBytes('WAVE').') at offset 8, found "'.$wave_chunk.'" ('.getid3_lib::PrintHexBytes($wave_chunk).') instead.'); } - + $offset = 12; $getid3->info['la']['fmt_size'] = 24; @@ -71,13 +71,13 @@ class getid3_la extends getid3_handler throw new getid3_exception('Expected "fmt " ('.getid3_lib::PrintHexBytes('fmt ').') at offset '.$offset.', found "'.$fmt_chunk.'" ('.getid3_lib::PrintHexBytes($fmt_chunk).') instead.'); } $offset += 4; - + $fmt_size = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4)); $offset += 4; $getid3->info['la']['raw']['format'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 2)); $offset += 2; - + getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['la'], $raw_data, $offset, array ( 'channels' => 2, @@ -89,9 +89,9 @@ class getid3_la extends getid3_handler ) ); $offset += 18; - + $getid3->info['la']['raw']['flags'] = getid3_lib::LittleEndian2Int($raw_data{$offset++}); - + $getid3->info['la']['flags']['seekable'] = (bool)($getid3->info['la']['raw']['flags'] & 0x01); if ($getid3->info['la']['version'] >= 0.4) { $getid3->info['la']['flags']['high_compression'] = (bool)($getid3->info['la']['raw']['flags'] & 0x02); @@ -106,7 +106,7 @@ class getid3_la extends getid3_handler // samples, so 4 * int(totalSamples / (blockSize * seekEvery)) should // give the number of bytes used for the seekpoints. Of course, if seeking // is disabled, there are no seekpoints stored. - + if ($getid3->info['la']['version'] >= 0.4) { $getid3->info['la']['blocksize'] = 61440; $getid3->info['la']['seekevery'] = 19; @@ -130,7 +130,7 @@ class getid3_la extends getid3_handler // Following the main header information, the program outputs all of the // seekpoints. Following these is what I called the 'footer start', // i.e. the position immediately after the La audio data is finished. - + $getid3->info['la']['footerstart'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4)); $offset += 4; @@ -147,7 +147,7 @@ class getid3_la extends getid3_handler } if ($getid3->info['la']['footerstart'] < $getid3->info['avdataend']) { - + // Create riff header $riff_data = 'WAVE'; if ($getid3->info['la']['version'] == 0.2) { @@ -160,14 +160,14 @@ class getid3_la extends getid3_handler $riff_data .= fread($getid3->fp, $getid3->info['avdataend'] - $getid3->info['la']['footerstart']); } $riff_data = 'RIFF'.getid3_lib::LittleEndian2String(strlen($riff_data), 4, false).$riff_data; - + // Clone getid3 - messing with offsets - better safe than sorry $clone = clone $getid3; - + // Analyze clone by string $riff = new getid3_riff($clone); $riff->AnalyzeString($riff_data); - + // Import from clone and destroy $getid3->info['riff'] = $clone->info['riff']; $getid3->warnings($clone->warnings()); diff --git a/modules/getid3/module.audio.lpac.php b/modules/getid3/module.audio.lpac.php index b86ff064..d20a59eb 100644 --- a/modules/getid3/module.audio.lpac.php +++ b/modules/getid3/module.audio.lpac.php @@ -22,24 +22,24 @@ //
// $Id: module.audio.lpac.php,v 1.2 2006/11/02 10:48:01 ah Exp $ - - + + class getid3_lpac extends getid3_handler { public function Analyze() { - + $getid3 = $this->getid3; - + $getid3->include_module('audio-video.riff'); - + // Magic bytes - 'LPAC' - + fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $lpac_header = fread($getid3->fp, 14); - + $getid3->info['avdataoffset'] += 14; - + $getid3->info['lpac'] = array (); $info_lpac = &$getid3->info['lpac']; @@ -47,7 +47,7 @@ class getid3_lpac extends getid3_handler $getid3->info['audio']['dataformat'] = 'lpac'; $getid3->info['audio']['lossless'] = true; $getid3->info['audio']['bitrate_mode'] = 'vbr'; - + $info_lpac['file_version'] = getid3_lib::BigEndian2Int($lpac_header{4}); $flags['audio_type'] = getid3_lib::BigEndian2Int($lpac_header{5}); $info_lpac['total_samples'] = getid3_lib::BigEndian2Int(substr($lpac_header, 6, 4)); @@ -74,9 +74,9 @@ class getid3_lpac extends getid3_handler if ($info_lpac['flags']['fast_compress'] && ($info_lpac['max_prediction_order'] != 3)) { $getid3->warning('max_prediction_order expected to be "3" if fast_compress is true, actual value is "'.$info_lpac['max_prediction_order'].'"'); } - + switch ($info_lpac['file_version']) { - + case 6: if ($info_lpac['flags']['adaptive_quantization']) { $getid3->warning('adaptive_quantization expected to be false in LPAC file stucture v6, actually true'); @@ -86,7 +86,7 @@ class getid3_lpac extends getid3_handler } break; - + default: //$getid3->warning('This version of getID3() only supports LPAC file format version 6, this file is version '.$info_lpac['file_version'].' - please report to info@getid3.org'); break; @@ -94,11 +94,11 @@ class getid3_lpac extends getid3_handler // Clone getid3 - messing with something - better safe than sorry $clone = clone $getid3; - + // Analyze clone by fp $riff = new getid3_riff($clone); $riff->Analyze(); - + // Import from clone and destroy $getid3->info['avdataoffset'] = $clone->info['avdataoffset']; $getid3->info['riff'] = $clone->info['riff']; @@ -106,7 +106,7 @@ class getid3_lpac extends getid3_handler $getid3->info['audio']['sample_rate'] = $clone->info['audio']['sample_rate']; $getid3->warnings($clone->warnings()); unset($clone); - + $getid3->info['audio']['channels'] = ($info_lpac['flags']['stereo'] ? 2 : 1); if ($info_lpac['flags']['24_bit']) { diff --git a/modules/getid3/module.audio.midi.php b/modules/getid3/module.audio.midi.php index 59786f10..383c7e29 100644 --- a/modules/getid3/module.audio.midi.php +++ b/modules/getid3/module.audio.midi.php @@ -22,15 +22,15 @@ // // $Id: module.audio.midi.php,v 1.5 2006/11/02 10:48:01 ah Exp $ - - + + class getid3_midi extends getid3_handler { public function Analyze() { $getid3 = $this->getid3; - + $getid3->info['midi']['raw'] = array (); $info_midi = &$getid3->info['midi']; $info_midi_raw = &$info_midi['raw']; @@ -40,10 +40,10 @@ class getid3_midi extends getid3_handler fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $midi_data = fread($getid3->fp, getid3::FREAD_BUFFER_SIZE); - + // Magic bytes: 'MThd' - - getid3_lib::ReadSequence('BigEndian2Int', $info_midi_raw, $midi_data, 4, + + getid3_lib::ReadSequence('BigEndian2Int', $info_midi_raw, $midi_data, 4, array ( 'headersize' => 4, 'fileformat' => 2, @@ -51,25 +51,25 @@ class getid3_midi extends getid3_handler 'ticksperqnote' => 2 ) ); - + $offset = 14; for ($i = 0; $i < $info_midi_raw['tracks']; $i++) { - + if ((strlen($midi_data) - $offset) < 8) { $midi_data .= fread($getid3->fp, getid3::FREAD_BUFFER_SIZE); } - + $track_id = substr($midi_data, $offset, 4); $offset += 4; - + if ($track_id != 'MTrk') { throw new getid3_exception('Expecting "MTrk" at '.$offset.', found '.$track_id.' instead'); } - + $track_size = getid3_lib::BigEndian2Int(substr($midi_data, $offset, 4)); $offset += 4; - + $track_data_array[$i] = substr($midi_data, $offset, $track_size); $offset += $track_size; } @@ -78,7 +78,7 @@ class getid3_midi extends getid3_handler throw new getid3_exception('Cannot find MIDI track information'); } - + $info_midi['totalticks'] = 0; $getid3->info['playtime_seconds'] = 0; $current_ms_per_beat = 500000; // 120 beats per minute; 60,000,000 microseconds per minute -> 500,000 microseconds per beat @@ -88,9 +88,9 @@ class getid3_midi extends getid3_handler foreach ($track_data_array as $track_number => $track_data) { $events_offset = $last_issued_midi_command = $last_issued_midi_channel = $cumulative_delta_time = $ticks_at_current_bpm = 0; - + while ($events_offset < strlen($track_data)) { - + $event_id = 0; if (isset($midi_events[$track_number]) && is_array($midi_events[$track_number])) { $event_id = count($midi_events[$track_number]); @@ -105,30 +105,30 @@ class getid3_midi extends getid3_handler break; } } - + $cumulative_delta_time += $delta_time; $ticks_at_current_bpm += $delta_time; - + $midi_events[$track_number][$event_id]['deltatime'] = $delta_time; - + $midi_event_channel = ord($track_data{$events_offset++}); - + // OK, normal event - MIDI command has MSB set if ($midi_event_channel & 0x80) { $last_issued_midi_command = $midi_event_channel >> 4; $last_issued_midi_channel = $midi_event_channel & 0x0F; - } - + } + // Running event - assume last command else { $events_offset--; } - + $midi_events[$track_number][$event_id]['eventid'] = $last_issued_midi_command; $midi_events[$track_number][$event_id]['channel'] = $last_issued_midi_channel; - + switch ($midi_events[$track_number][$event_id]['eventid']) { - + case 0x8: // Note off (key is released) case 0x9: // Note on (key is pressed) case 0xA: // Key after-touch @@ -137,31 +137,31 @@ class getid3_midi extends getid3_handler //$velocity = ord($track_data{$events_offset++}); $events_offset += 2; break; - - + + case 0xB: // Control Change - + //$controllernum = ord($track_data{$events_offset++}); //$newvalue = ord($track_data{$events_offset++}); $events_offset += 2; break; - - + + case 0xC: // Program (patch) change - + $new_program_num = ord($track_data{$events_offset++}); $info_midi_raw['track'][$track_number]['instrumentid'] = $new_program_num; $info_midi_raw['track'][$track_number]['instrument'] = $track_number == 10 ? getid3_midi::GeneralMIDIpercussionLookup($new_program_num) : getid3_midi::GeneralMIDIinstrumentLookup($new_program_num); break; - - + + case 0xD: // Channel after-touch - + //$channelnumber = ord($track_data{$events_offset++}); break; - - + + case 0xE: // Pitch wheel change (2000H is normal or no change) //$changeLSB = ord($track_data{$events_offset++}); @@ -169,58 +169,58 @@ class getid3_midi extends getid3_handler //$pitchwheelchange = (($changeMSB & 0x7F) << 7) & ($changeLSB & 0x7F); $events_offset += 2; break; - - + + case 0xF: if ($midi_events[$track_number][$event_id]['channel'] == 0xF) { - + $meta_event_command = ord($track_data{$events_offset++}); $meta_event_length = ord($track_data{$events_offset++}); $meta_event_data = substr($track_data, $events_offset, $meta_event_length); $events_offset += $meta_event_length; - + switch ($meta_event_command) { - + case 0x00: // Set track sequence number - + //$track_sequence_number = getid3_lib::BigEndian2Int(substr($meta_event_data, 0, $meta_event_length)); //$info_midi_raw['events'][$track_number][$event_id]['seqno'] = $track_sequence_number; break; - - + + case 0x01: // Text: generic - + $text_generic = substr($meta_event_data, 0, $meta_event_length); //$info_midi_raw['events'][$track_number][$event_id]['text'] = $text_generic; $info_midi['comments']['comment'][] = $text_generic; break; - - + + case 0x02: // Text: copyright - + $text_copyright = substr($meta_event_data, 0, $meta_event_length); //$info_midi_raw['events'][$track_number][$event_id]['copyright'] = $text_copyright; $info_midi['comments']['copyright'][] = $text_copyright; break; - - + + case 0x03: // Text: track name - + $text_trackname = substr($meta_event_data, 0, $meta_event_length); $info_midi_raw['track'][$track_number]['name'] = $text_trackname; break; - - + + case 0x04: // Text: track instrument name - + //$text_instrument = substr($meta_event_data, 0, $meta_event_length); //$info_midi_raw['events'][$track_number][$event_id]['instrument'] = $text_instrument; break; - - + + case 0x05: // Text: lyrics - + $text_lyrics = substr($meta_event_data, 0, $meta_event_length); //$info_midi_raw['events'][$track_number][$event_id]['lyrics'] = $text_lyrics; if (!isset($info_midi['lyrics'])) { @@ -228,38 +228,38 @@ class getid3_midi extends getid3_handler } $info_midi['lyrics'] .= $text_lyrics . "\n"; break; - - + + case 0x06: // Text: marker - + //$text_marker = substr($meta_event_data, 0, $meta_event_length); //$info_midi_raw['events'][$track_number][$event_id]['marker'] = $text_marker; break; - - + + case 0x07: // Text: cue point //$text_cuepoint = substr($meta_event_data, 0, $meta_event_length); //$info_midi_raw['events'][$track_number][$event_id]['cuepoint'] = $text_cuepoint; break; - + case 0x2F: // End Of Track - + //$info_midi_raw['events'][$track_number][$event_id]['EOT'] = $cumulative_delta_time; break; - - + + case 0x51: // Tempo: microseconds / quarter note - + $current_ms_per_beat = getid3_lib::BigEndian2Int(substr($meta_event_data, 0, $meta_event_length)); $info_midi_raw['events'][$track_number][$cumulative_delta_time]['us_qnote'] = $current_ms_per_beat; $current_beats_per_min = (1000000 / $current_ms_per_beat) * 60; $ms_per_quarter_note_after[$cumulative_delta_time] = $current_ms_per_beat; $ticks_at_current_bpm = 0; break; - - + + case 0x58: // Time signature $timesig_numerator = getid3_lib::BigEndian2Int($meta_event_data[0]); $timesig_denominator = pow(2, getid3_lib::BigEndian2Int($meta_event_data[1])); // $02 -> x/4, $03 -> x/8, etc @@ -270,63 +270,63 @@ class getid3_midi extends getid3_handler //$info_midi_raw['events'][$track_number][$event_id]['timesig_text'] = $timesig_numerator.'/'.$timesig_denominator; $info_midi['timesignature'][] = $timesig_numerator.'/'.$timesig_denominator; break; - - + + case 0x59: // Keysignature - + $keysig_sharpsflats = getid3_lib::BigEndian2Int($meta_event_data{0}); if ($keysig_sharpsflats & 0x80) { // (-7 -> 7 flats, 0 ->key of C, 7 -> 7 sharps) $keysig_sharpsflats -= 256; } - + $keysig_majorminor = getid3_lib::BigEndian2Int($meta_event_data{1}); // 0 -> major, 1 -> minor $keysigs = array (-7=>'Cb', -6=>'Gb', -5=>'Db', -4=>'Ab', -3=>'Eb', -2=>'Bb', -1=>'F', 0=>'C', 1=>'G', 2=>'D', 3=>'A', 4=>'E', 5=>'B', 6=>'F#', 7=>'C#'); //$info_midi_raw['events'][$track_number][$event_id]['keysig_sharps'] = (($keysig_sharpsflats > 0) ? abs($keysig_sharpsflats) : 0); //$info_midi_raw['events'][$track_number][$event_id]['keysig_flats'] = (($keysig_sharpsflats < 0) ? abs($keysig_sharpsflats) : 0); //$info_midi_raw['events'][$track_number][$event_id]['keysig_minor'] = (bool)$keysig_majorminor; //$info_midi_raw['events'][$track_number][$event_id]['keysig_text'] = $keysigs[$keysig_sharpsflats].' '.($info_midi_raw['events'][$track_number][$event_id]['keysig_minor'] ? 'minor' : 'major'); - + // $keysigs[$keysig_sharpsflats] gets an int key (correct) - $keysigs["$keysig_sharpsflats"] gets a string key (incorrect) $info_midi['keysignature'][] = $keysigs[$keysig_sharpsflats].' '.((bool)$keysig_majorminor ? 'minor' : 'major'); break; - - + + case 0x7F: // Sequencer specific information - + $custom_data = substr($meta_event_data, 0, $meta_event_length); break; - - + + default: - + $getid3->warning('Unhandled META Event Command: '.$meta_event_command); } } break; - - - default: + + + default: $getid3->warning('Unhandled MIDI Event ID: '.$midi_events[$track_number][$event_id]['eventid']); } } - + if (($track_number > 0) || (count($track_data_array) == 1)) { $info_midi['totalticks'] = max($info_midi['totalticks'], $cumulative_delta_time); } } - + $previous_tick_offset = null; - ksort($ms_per_quarter_note_after); + ksort($ms_per_quarter_note_after); foreach ($ms_per_quarter_note_after as $tick_offset => $ms_per_beat) { - + if (is_null($previous_tick_offset)) { $prev_ms_per_beat = $ms_per_beat; $previous_tick_offset = $tick_offset; continue; } - + if ($info_midi['totalticks'] > $tick_offset) { $getid3->info['playtime_seconds'] += (($tick_offset - $previous_tick_offset) / $info_midi_raw['ticksperqnote']) * ($prev_ms_per_beat / 1000000); @@ -334,7 +334,7 @@ class getid3_midi extends getid3_handler $previous_tick_offset = $tick_offset; } } - + if ($info_midi['totalticks'] > $previous_tick_offset) { $getid3->info['playtime_seconds'] += (($info_midi['totalticks'] - $previous_tick_offset) / $info_midi_raw['ticksperqnote']) * ($ms_per_beat / 1000000); } @@ -351,11 +351,11 @@ class getid3_midi extends getid3_handler } - + public static function GeneralMIDIinstrumentLookup($instrument_id) { static $lookup = array ( - + 0 => 'Acoustic Grand', 1 => 'Bright Acoustic', 2 => 'Electric Grand', @@ -487,14 +487,14 @@ class getid3_midi extends getid3_handler ); return @$lookup[$instrument_id]; - } - - - + } + + + public static function GeneralMIDIpercussionLookup($instrument_id) { - + static $lookup = array ( - + 35 => 'Acoustic Bass Drum', 36 => 'Bass Drum 1', 37 => 'Side Stick', @@ -544,10 +544,10 @@ class getid3_midi extends getid3_handler ); return @$lookup[$instrument_id]; - } + } + + +} + - -} - - ?>
\ No newline at end of file diff --git a/modules/getid3/module.audio.monkey.php b/modules/getid3/module.audio.monkey.php index cb691fca..4ece9f59 100644 --- a/modules/getid3/module.audio.monkey.php +++ b/modules/getid3/module.audio.monkey.php @@ -22,8 +22,8 @@ //
// $Id: module.audio.monkey.php,v 1.2 2006/11/02 10:48:01 ah Exp $ - - + + class getid3_monkey extends getid3_handler { @@ -33,7 +33,7 @@ class getid3_monkey extends getid3_handler // based loosely on code from TMonkey by Jurgen Faul <jfaulØgmx*de> // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html - + $getid3->info['fileformat'] = 'mac'; $getid3->info['audio']['dataformat'] = 'mac'; $getid3->info['audio']['bitrate_mode'] = 'vbr'; @@ -51,10 +51,10 @@ class getid3_monkey extends getid3_handler // Read MAC version $info_monkeys_audio_raw['nVersion'] = getid3_lib::LittleEndian2Int(substr($mac_header_data, 4, 2)); // appears to be uint32 in 3.98+ - + // Parse MAC Header < v3980 if ($info_monkeys_audio_raw['nVersion'] < 3980) { - + getid3_lib::ReadSequence("LittleEndian2Int", $info_monkeys_audio_raw, $mac_header_data, 6, array (
'nCompressionLevel' => 2,
@@ -65,30 +65,30 @@ class getid3_monkey extends getid3_handler 'nWAVTerminatingBytes' => 4,
'nTotalFrames' => 4,
'nFinalFrameSamples' => 4,
- 'nPeakLevel' => 4, + 'nPeakLevel' => 4, 'IGNORE-1' => 2,
'nSeekElements' => 2 ) );
- } - + } + // Parse MAC Header >= v3980 else { - getid3_lib::ReadSequence("LittleEndian2Int", $info_monkeys_audio_raw, $mac_header_data, 8, + getid3_lib::ReadSequence("LittleEndian2Int", $info_monkeys_audio_raw, $mac_header_data, 8, array ( // APE_DESCRIPTOR 'nDescriptorBytes' => 4, - 'nHeaderBytes' => 4, - 'nSeekTableBytes' => 4, - 'nHeaderDataBytes' => 4, - 'nAPEFrameDataBytes' => 4, - 'nAPEFrameDataBytesHigh'=> 4, - 'nTerminatingDataBytes' => 4, - + 'nHeaderBytes' => 4, + 'nSeekTableBytes' => 4, + 'nHeaderDataBytes' => 4, + 'nAPEFrameDataBytes' => 4, + 'nAPEFrameDataBytesHigh'=> 4, + 'nTerminatingDataBytes' => 4, + // MD5 - string - 'cFileMD5' => -16, - + 'cFileMD5' => -16, + // APE_HEADER 'nCompressionLevel' => 2, 'nFormatFlags' => 2, @@ -101,7 +101,7 @@ class getid3_monkey extends getid3_handler ) ); } - + // Process data $info_monkeys_audio['flags']['8-bit'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0001); $info_monkeys_audio['flags']['crc-32'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0002); @@ -109,39 +109,39 @@ class getid3_monkey extends getid3_handler $info_monkeys_audio['flags']['24-bit'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0008); $info_monkeys_audio['flags']['seek_elements'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0010); $info_monkeys_audio['flags']['no_wav_header'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0020); - + $info_monkeys_audio['version'] = $info_monkeys_audio_raw['nVersion'] / 1000; - + $info_monkeys_audio['compression'] = getid3_monkey::MonkeyCompressionLevelNameLookup($info_monkeys_audio_raw['nCompressionLevel']); - + $info_monkeys_audio['bits_per_sample'] = ($info_monkeys_audio['flags']['24-bit'] ? 24 : ($info_monkeys_audio['flags']['8-bit'] ? 8 : 16)); - + $info_monkeys_audio['channels'] = $info_monkeys_audio_raw['nChannels']; - + $getid3->info['audio']['channels'] = $info_monkeys_audio['channels']; - + $info_monkeys_audio['sample_rate'] = $info_monkeys_audio_raw['nSampleRate']; - + $getid3->info['audio']['sample_rate'] = $info_monkeys_audio['sample_rate']; - + if ($info_monkeys_audio['flags']['peak_level']) { $info_monkeys_audio['peak_level'] = $info_monkeys_audio_raw['nPeakLevel']; $info_monkeys_audio['peak_ratio'] = $info_monkeys_audio['peak_level'] / pow(2, $info_monkeys_audio['bits_per_sample'] - 1); } - + // MAC >= v3980 if ($info_monkeys_audio_raw['nVersion'] >= 3980) { $info_monkeys_audio['samples'] = (($info_monkeys_audio_raw['nTotalFrames'] - 1) * $info_monkeys_audio_raw['nBlocksPerFrame']) + $info_monkeys_audio_raw['nFinalFrameBlocks']; - } - + } + // MAC < v3980 else { $info_monkeys_audio['samples_per_frame'] = getid3_monkey::MonkeySamplesPerFrame($info_monkeys_audio_raw['nVersion'], $info_monkeys_audio_raw['nCompressionLevel']); $info_monkeys_audio['samples'] = (($info_monkeys_audio_raw['nTotalFrames'] - 1) * $info_monkeys_audio['samples_per_frame']) + $info_monkeys_audio_raw['nFinalFrameSamples']; } - + $info_monkeys_audio['playtime'] = $info_monkeys_audio['samples'] / $info_monkeys_audio['sample_rate']; - + $getid3->info['playtime_seconds'] = $info_monkeys_audio['playtime']; $info_monkeys_audio['compressed_size'] = $getid3->info['avdataend'] - $getid3->info['avdataoffset']; @@ -150,17 +150,17 @@ class getid3_monkey extends getid3_handler $info_monkeys_audio['bitrate'] = (($info_monkeys_audio['samples'] * $info_monkeys_audio['channels'] * $info_monkeys_audio['bits_per_sample']) / $info_monkeys_audio['playtime']) * $info_monkeys_audio['compression_ratio']; $getid3->info['audio']['bitrate'] = $info_monkeys_audio['bitrate']; - + $getid3->info['audio']['bits_per_sample'] = $info_monkeys_audio['bits_per_sample']; $getid3->info['audio']['encoder'] = 'MAC v'.number_format($info_monkeys_audio['version'], 2); $getid3->info['audio']['encoder_options'] = ucfirst($info_monkeys_audio['compression']).' compression'; - + // MAC >= v3980 - get avdataoffsets from MAC header if ($info_monkeys_audio_raw['nVersion'] >= 3980) { $getid3->info['avdataoffset'] += $info_monkeys_audio_raw['nDescriptorBytes'] + $info_monkeys_audio_raw['nHeaderBytes'] + $info_monkeys_audio_raw['nSeekTableBytes'] + $info_monkeys_audio_raw['nHeaderDataBytes']; $getid3->info['avdataend'] -= $info_monkeys_audio_raw['nTerminatingDataBytes']; - } - + } + // MAC < v3980 Add size of MAC header to avdataoffset else { $getid3->info['avdataoffset'] += 8; @@ -179,15 +179,15 @@ class getid3_monkey extends getid3_handler } } } - + return true; } - - + + public static function MonkeyCompressionLevelNameLookup($compression_level) { - + static $lookup = array ( 0 => 'unknown', 1000 => 'fast', @@ -199,13 +199,13 @@ class getid3_monkey extends getid3_handler return (isset($lookup[$compression_level]) ? $lookup[$compression_level] : 'invalid'); } - - + + public static function MonkeySamplesPerFrame($version_id, $compression_level) { if ($version_id >= 3950) { return 73728 * 4; - } + } if (($version_id >= 3900) || (($version_id >= 3800) && ($compression_level == 4000))) { return 73728; } diff --git a/modules/getid3/module.audio.mpc_old.php b/modules/getid3/module.audio.mpc_old.php index 3a9adb9d..5e47b4b3 100644 --- a/modules/getid3/module.audio.mpc_old.php +++ b/modules/getid3/module.audio.mpc_old.php @@ -22,17 +22,17 @@ //
// $Id: module.audio.mpc_old.php,v 1.2 2006/11/02 10:48:01 ah Exp $ - - + + class getid3_mpc_old extends getid3_handler { public function Analyze() { $getid3 = $this->getid3; - + // http://www.uni-jena.de/~pfk/mpp/sv8/header.html - + $getid3->info['mpc']['header'] = array (); $info_mpc_header = &$getid3->info['mpc']['header']; @@ -46,10 +46,10 @@ class getid3_mpc_old extends getid3_handler $info_mpc_header['size'] = 8; $getid3->info['avdataoffset'] += $info_mpc_header['size']; - + $mpc_header_data = fread($getid3->fp, $info_mpc_header['size']); - - + + // Most of this code adapted from Jurgen Faul's MPEGplus source code - thanks Jurgen! :) $header_dword[0] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 0, 4)); $header_dword[1] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 4, 4)); @@ -69,7 +69,7 @@ class getid3_mpc_old extends getid3_handler $info_mpc_header['intensity_stereo'] = (bool)(($header_dword[0] & 0x00400000) >> 22); $info_mpc_header['mid-side_stereo'] = (bool)(($header_dword[0] & 0x00200000) >> 21); $info_mpc_header['stream_major_version'] = ($header_dword[0] & 0x001FF800) >> 11; - $info_mpc_header['stream_minor_version'] = 0; + $info_mpc_header['stream_minor_version'] = 0; $info_mpc_header['max_band'] = ($header_dword[0] & 0x000007C0) >> 6; // related to lowpass frequency, not sure how it translates exactly $info_mpc_header['block_size'] = ($header_dword[0] & 0x0000003F); @@ -98,10 +98,10 @@ class getid3_mpc_old extends getid3_handler $getid3->info['mpc']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 * 44100 / $info_mpc_header['frame_count'] / 1152; $getid3->info['audio']['bitrate'] = $getid3->info['mpc']['bitrate']; $getid3->info['audio']['encoder'] = 'SV'.$info_mpc_header['stream_major_version']; - + return true; } - + } diff --git a/modules/getid3/module.audio.optimfrog.php b/modules/getid3/module.audio.optimfrog.php index 9dde727b..3c667570 100644 --- a/modules/getid3/module.audio.optimfrog.php +++ b/modules/getid3/module.audio.optimfrog.php @@ -22,44 +22,44 @@ //
// $Id: module.audio.optimfrog.php,v 1.3 2006/11/02 10:48:01 ah Exp $ - - + + class getid3_optimfrog extends getid3_handler { public function Analyze() { - + $getid3 = $this->getid3; - + $getid3->include_module('audio-video.riff'); - + $getid3->info['audio']['dataformat'] = 'ofr'; $getid3->info['audio']['bitrate_mode'] = 'vbr'; $getid3->info['audio']['lossless'] = true; fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $ofr_header = fread($getid3->fp, 8); - + if (substr($ofr_header, 0, 5) == '*RIFF') { return $this->ParseOptimFROGheader42($getid3->fp, $getid3->info); } elseif (substr($ofr_header, 0, 3) == 'OFR') { return $this->ParseOptimFROGheader45($getid3->fp, $getid3->info); } - + throw new getid3_exception('Expecting "*RIFF" or "OFR " at offset '.$getid3->info['avdataoffset'].', found "'.$ofr_header.'"'); } private function ParseOptimFROGheader42() { - + $getid3 = $this->getid3; - + // for fileformat of v4.21 and older fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); - + $ofr_header_data = fread($getid3->fp, 45); $getid3->info['avdataoffset'] = 45; @@ -79,26 +79,26 @@ class getid3_optimfrog extends getid3_handler // move the data chunk after all other chunks (if any) // so that the RIFF parser doesn't see EOF when trying // to skip over the data chunk - + $riff_data = substr($riff_data, 0, 36).substr($riff_data, 44).substr($riff_data, 36, 8); - + // Save audio info key $saved_info_audio = $getid3->info['audio']; // Instantiate riff module and analyze string $riff = new getid3_riff($getid3); $riff->AnalyzeString($riff_data); - + // Restore info key $getid3->info['audio'] = $saved_info_audio; - + $getid3->info['audio']['encoder'] = 'OptimFROG '.$ofr_encoder_version_major.'.'.$ofr_encoder_version_minor; $getid3->info['audio']['channels'] = $getid3->info['riff']['audio'][0]['channels']; $getid3->info['audio']['sample_rate'] = $getid3->info['riff']['audio'][0]['sample_rate']; $getid3->info['audio']['bits_per_sample'] = $getid3->info['riff']['audio'][0]['bits_per_sample']; $getid3->info['playtime_seconds'] = $origna_riff_data_size / ($getid3->info['audio']['channels'] * $getid3->info['audio']['sample_rate'] * ($getid3->info['audio']['bits_per_sample'] / 8)); $getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds']; - + $getid3->info['fileformat'] = 'ofr'; return true; @@ -107,16 +107,16 @@ class getid3_optimfrog extends getid3_handler private function ParseOptimFROGheader45() { - + $getid3 = $this->getid3; - + // for fileformat of v4.50a and higher $riff_data = ''; fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); - + while (!feof($getid3->fp) && (ftell($getid3->fp) < $getid3->info['avdataend'])) { - + $block_offset = ftell($getid3->fp); $block_data = fread($getid3->fp, 8); $offset = 8; @@ -153,10 +153,10 @@ class getid3_optimfrog extends getid3_handler $info_ofr_this_block['total_samples'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 6)); $offset += 6; - + $info_ofr_this_block['raw']['sample_type'] = getid3_lib::LittleEndian2Int($block_data{$offset++}); $info_ofr_this_block['sample_type'] = $this->OptimFROGsampleTypeLookup($info_ofr_this_block['raw']['sample_type']); - + $info_ofr_this_block['channel_config'] = getid3_lib::LittleEndian2Int($block_data{$offset++}); $info_ofr_this_block['channels'] = $info_ofr_this_block['channel_config']; @@ -210,13 +210,13 @@ class getid3_optimfrog extends getid3_handler $comp_data['crc_32'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 4)); $offset += 4; - + $comp_data['sample_count'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 4)); $offset += 4; - + $comp_data['raw']['sample_type'] = getid3_lib::LittleEndian2Int($block_data{$offset++}); $comp_data['sample_type'] = $this->OptimFROGsampleTypeLookup($comp_data['raw']['sample_type']); - + $comp_data['raw']['channel_configuration'] = getid3_lib::LittleEndian2Int($block_data{$offset++}); $comp_data['channel_configuration'] = $this->OptimFROGchannelConfigurationLookup($comp_data['raw']['channel_configuration']); @@ -306,7 +306,7 @@ class getid3_optimfrog extends getid3_handler break; } } - + if (isset($getid3->info['ofr']['TAIL']['offset'])) { $getid3->info['avdataend'] = $getid3->info['ofr']['TAIL']['offset']; } @@ -317,19 +317,19 @@ class getid3_optimfrog extends getid3_handler // move the data chunk after all other chunks (if any) // so that the RIFF parser doesn't see EOF when trying // to skip over the data chunk - + $riff_data = substr($riff_data, 0, 36).substr($riff_data, 44).substr($riff_data, 36, 8); - + // Save audio info key $saved_info_audio = $getid3->info['audio']; // Instantiate riff module and analyze string $riff = new getid3_riff($getid3); $riff->AnalyzeString($riff_data); - + // Restore info key $getid3->info['audio'] = $saved_info_audio; - + $getid3->info['fileformat'] = 'ofr'; return true; @@ -338,7 +338,7 @@ class getid3_optimfrog extends getid3_handler public static function OptimFROGsampleTypeLookup($sample_type) { - + static $lookup = array ( 0 => 'unsigned int (8-bit)', 1 => 'signed int (8-bit)', @@ -352,7 +352,7 @@ class getid3_optimfrog extends getid3_handler 9 => 'float 16.8 (32-bit)', 10 => 'float 24.0 (32-bit)' ); - + return @$lookup[$sample_type]; } @@ -373,19 +373,19 @@ class getid3_optimfrog extends getid3_handler 9 => 32, 10 => 32 ); - + return @$lookup[$sample_type]; } public static function OptimFROGchannelConfigurationLookup($channel_configuration) { - + static $lookup = array ( 0 => 'mono', 1 => 'stereo' ); - + return @$lookup[$channel_configuration]; } @@ -397,7 +397,7 @@ class getid3_optimfrog extends getid3_handler 0 => 1, 1 => 2 ); - + return @$lookup[$channel_configuration]; } diff --git a/modules/getid3/module.audio.rkau.php b/modules/getid3/module.audio.rkau.php index 014c5272..35dc6253 100644 --- a/modules/getid3/module.audio.rkau.php +++ b/modules/getid3/module.audio.rkau.php @@ -22,28 +22,28 @@ //
// $Id: module.audio.rkau.php,v 1.2 2006/11/02 10:48:01 ah Exp $ - - + + class getid3_rkau extends getid3_handler { public function Analyze() { $getid3 = $this->getid3; - + fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $rkau_header = fread($getid3->fp, 20); - + // Magic bytes 'RKA' - + $getid3->info['fileformat'] = 'rkau'; $getid3->info['audio']['dataformat'] = 'rkau'; $getid3->info['audio']['bitrate_mode'] = 'vbr'; - + // Shortcut $getid3->info['rkau'] = array (); $info_rkau = &$getid3->info['rkau']; - + $info_rkau['raw']['version'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 3, 1)); $info_rkau['version'] = '1.'.str_pad($info_rkau['raw']['version'] & 0x0F, 2, '0', STR_PAD_LEFT); if (($info_rkau['version'] > 1.07) || ($info_rkau['version'] < 1.06)) { @@ -60,7 +60,7 @@ class getid3_rkau extends getid3_handler ); $info_rkau['raw']['quality'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 14, 1)); - + $quality = $info_rkau['raw']['quality'] & 0x0F; $info_rkau['lossless'] = (($quality == 0) ? true : false); @@ -68,7 +68,7 @@ class getid3_rkau extends getid3_handler if (!$info_rkau['lossless']) { $info_rkau['quality_setting'] = $quality; } - + $info_rkau['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 15, 1)); $info_rkau['flags']['joint_stereo'] = (bool)(!($info_rkau['raw']['flags'] & 0x01)); $info_rkau['flags']['streaming'] = (bool) ($info_rkau['raw']['flags'] & 0x02); @@ -77,7 +77,7 @@ class getid3_rkau extends getid3_handler if ($info_rkau['flags']['streaming']) { $getid3->info['avdataoffset'] += 20; $info_rkau['compressed_bytes'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 16, 4)); - } + } else { $getid3->info['avdataoffset'] += 16; $info_rkau['compressed_bytes'] = $getid3->info['avdataend'] - $getid3->info['avdataoffset'] - 1; diff --git a/modules/getid3/module.audio.shorten.php b/modules/getid3/module.audio.shorten.php index 8a45d5fe..0c610c7c 100644 --- a/modules/getid3/module.audio.shorten.php +++ b/modules/getid3/module.audio.shorten.php @@ -22,15 +22,15 @@ // // $Id: module.audio.shorten.php,v 1.5 2006/12/03 19:28:18 ah Exp $ - - + + class getid3_shorten extends getid3_handler { public function __construct(getID3 $getid3) { parent::__construct($getid3); - + if ((bool)ini_get('safe_mode')) { throw new getid3_exception('PHP running in Safe Mode - backtick operator not available, cannot analyze Shorten files.'); } @@ -38,7 +38,7 @@ class getid3_shorten extends getid3_handler if (!`head --version`) { throw new getid3_exception('head[.exe] binary not found in path. UNIX: typically /usr/bin. Windows: typically c:\windows\system32.'); } - + if (!`shorten -l`) { throw new getid3_exception('shorten[.exe] binary not found in path. UNIX: typically /usr/bin. Windows: typically c:\windows\system32.'); } @@ -46,7 +46,7 @@ class getid3_shorten extends getid3_handler public function Analyze() { - + $getid3 = $this->getid3; $getid3->include_module('audio-video.riff'); @@ -54,9 +54,9 @@ class getid3_shorten extends getid3_handler fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $shn_header = fread($getid3->fp, 8); - + // Magic bytes: "ajkg" - + $getid3->info['fileformat'] = 'shn'; $getid3->info['audio']['dataformat'] = 'shn'; $getid3->info['audio']['lossless'] = true; @@ -65,21 +65,21 @@ class getid3_shorten extends getid3_handler $getid3->info['shn']['version'] = getid3_lib::LittleEndian2Int($shn_header{4}); fseek($getid3->fp, $getid3->info['avdataend'] - 12, SEEK_SET); - + $seek_table_signature_test = fread($getid3->fp, 12); - + $getid3->info['shn']['seektable']['present'] = (bool)(substr($seek_table_signature_test, 4, 8) == 'SHNAMPSK'); if ($getid3->info['shn']['seektable']['present']) { - + $getid3->info['shn']['seektable']['length'] = getid3_lib::LittleEndian2Int(substr($seek_table_signature_test, 0, 4)); $getid3->info['shn']['seektable']['offset'] = $getid3->info['avdataend'] - $getid3->info['shn']['seektable']['length']; fseek($getid3->fp, $getid3->info['shn']['seektable']['offset'], SEEK_SET); $seek_table_magic = fread($getid3->fp, 4); - + if ($seek_table_magic != 'SEEK') { throw new getid3_exception('Expecting "SEEK" at offset '.$getid3->info['shn']['seektable']['offset'].', found "'.$seek_table_magic.'"'); - } + } $seek_table_data = fread($getid3->fp, $getid3->info['shn']['seektable']['length'] - 16); $getid3->info['shn']['seektable']['entry_count'] = floor(strlen($seek_table_data) / 80); @@ -92,7 +92,7 @@ class getid3_shorten extends getid3_handler $fmt_size = getid3_lib::LittleEndian2Int(substr($output, 16, 4)); $decoded_wav_format_ex = getid3_riff::RIFFparseWAVEFORMATex(substr($output, 20, $fmt_size)); - + $getid3->info['audio']['channels'] = $decoded_wav_format_ex['channels']; $getid3->info['audio']['bits_per_sample'] = $decoded_wav_format_ex['bits_per_sample']; $getid3->info['audio']['sample_rate'] = $decoded_wav_format_ex['sample_rate']; diff --git a/modules/getid3/module.audio.tta.php b/modules/getid3/module.audio.tta.php index 3561b577..ff0e1be8 100644 --- a/modules/getid3/module.audio.tta.php +++ b/modules/getid3/module.audio.tta.php @@ -22,15 +22,15 @@ //
// $Id: module.audio.tta.php,v 1.2 2006/11/02 10:48:01 ah Exp $ - - + + class getid3_tta extends getid3_handler { public function Analyze() { $getid3 = $this->getid3; - + $getid3->info['fileformat'] = 'tta'; $getid3->info['audio']['dataformat'] = 'tta'; $getid3->info['audio']['lossless'] = true; @@ -40,27 +40,27 @@ class getid3_tta extends getid3_handler $tta_header = fread($getid3->fp, 26); $getid3->info['tta']['magic'] = 'TTA'; // Magic bytes - + switch ($tta_header{3}) { - + case "\x01": // TTA v1.x case "\x02": // TTA v1.x case "\x03": // TTA v1.x - + // "It was the demo-version of the TTA encoder. There is no released format with such header. TTA encoder v1 is not supported about a year." $getid3->info['tta']['major_version'] = 1; $getid3->info['avdataoffset'] += 16; - - getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4, + + getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4, array ( 'channels' => 2, 'bits_per_sample' => 2, 'sample_rate' => 4, 'samples_per_channel' => 4 ) - ); + ); $getid3->info['tta']['compression_level'] = ord($tta_header{3}); - + $getid3->info['audio']['encoder_options'] = '-e'.$getid3->info['tta']['compression_level']; $getid3->info['playtime_seconds'] = $getid3->info['tta']['samples_per_channel'] / $getid3->info['tta']['sample_rate']; break; @@ -70,7 +70,7 @@ class getid3_tta extends getid3_handler $getid3->info['tta']['major_version'] = 2; $getid3->info['avdataoffset'] += 20; - getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4, + getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4, array ( 'compression_level' => 2, 'audio_format' => 2, @@ -79,8 +79,8 @@ class getid3_tta extends getid3_handler 'sample_rate' => 4, 'data_length' => 4 ) - ); - + ); + $getid3->info['audio']['encoder_options'] = '-e'.$getid3->info['tta']['compression_level']; $getid3->info['playtime_seconds'] = $getid3->info['tta']['data_length'] / $getid3->info['tta']['sample_rate']; break; @@ -90,7 +90,7 @@ class getid3_tta extends getid3_handler $getid3->info['tta']['major_version'] = 3; $getid3->info['avdataoffset'] += 26; - getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4, + getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4, array ( 'audio_format' => 2, 'channels' => 2, @@ -98,9 +98,9 @@ class getid3_tta extends getid3_handler 'sample_rate' => 4, 'data_length' => 4, 'crc32_footer' => -4, // string - 'seek_point' => 4 + 'seek_point' => 4 ) - ); + ); $getid3->info['playtime_seconds'] = $getid3->info['tta']['data_length'] / $getid3->info['tta']['sample_rate']; break; diff --git a/modules/getid3/module.audio.voc.php b/modules/getid3/module.audio.voc.php index 01e7fe28..d2992c60 100644 --- a/modules/getid3/module.audio.voc.php +++ b/modules/getid3/module.audio.voc.php @@ -22,17 +22,17 @@ //
// $Id: module.audio.voc.php,v 1.3 2006/11/02 10:48:02 ah Exp $ - - + + class getid3_voc extends getid3_handler { public function Analyze() { $getid3 = $this->getid3; - + $original_av_data_offset = $getid3->info['avdataoffset']; - + fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); $voc_header= fread($getid3->fp, 26); @@ -59,9 +59,9 @@ class getid3_voc extends getid3_handler getid3_lib::ReadSequence('LittleEndian2Int', $info_voc['header'], $voc_header, 20, array ( - 'datablock_offset' => 2, - 'minor_version' => 1, - 'major_version' => 1 + 'datablock_offset' => 2, + 'minor_version' => 1, + 'major_version' => 1 ) ); @@ -73,9 +73,9 @@ class getid3_voc extends getid3_handler $this_block = array (); @$info_voc['blocktypes'][$block_type]++; - + switch ($block_type) { - + case 0: // Terminator // do nothing, we'll break out of the loop down below break; @@ -123,13 +123,13 @@ class getid3_voc extends getid3_handler // Stereo: 65536 - (256000000 / (sample_rate * 2)) getid3_lib::ReadSequence('LittleEndian2Int', $this_block, $block_data, 4, array ( - 'time_constant' => 2, - 'pack_method' => 1, - 'stereo' => 1 + 'time_constant' => 2, + 'pack_method' => 1, + 'stereo' => 1 ) ); $this_block['stereo'] = (bool)$this_block['stereo']; - + $info_audio['channels'] = ($this_block['stereo'] ? 2 : 1); $info_audio['sample_rate'] = (int)floor((256000000 / (65536 - $this_block['time_constant'])) / $info_audio['channels']); break; @@ -145,11 +145,11 @@ class getid3_voc extends getid3_handler array ( 'sample_rate' => 4, 'bits_per_sample' => 1, - 'channels' => 1, - 'wFormat' => 2 + 'channels' => 1, + 'wFormat' => 2 ) ); - + $this_block['compression_name'] = getid3_voc::VOCwFormatLookup($this_block['wFormat']); if (getid3_voc::VOCwFormatActualBitsPerSampleLookup($this_block['wFormat'])) { $info_voc['compressed_bits_per_sample'] = getid3_voc::VOCwFormatActualBitsPerSampleLookup($this_block['wFormat']); @@ -191,7 +191,7 @@ class getid3_voc extends getid3_handler public static function VOCcompressionTypeLookup($index) { - + static $lookup = array ( 0 => '8-bit', 1 => '4-bit', @@ -204,7 +204,7 @@ class getid3_voc extends getid3_handler public static function VOCwFormatLookup($index) { - + static $lookup = array ( 0x0000 => '8-bit unsigned PCM', 0x0001 => 'Creative 8-bit to 4-bit ADPCM', @@ -221,7 +221,7 @@ class getid3_voc extends getid3_handler public static function VOCwFormatActualBitsPerSampleLookup($index) { - + static $lookup = array ( 0x0000 => 8, 0x0001 => 4, diff --git a/modules/getid3/module.audio.vqf.php b/modules/getid3/module.audio.vqf.php index 7f4fc783..eef53d2c 100644 --- a/modules/getid3/module.audio.vqf.php +++ b/modules/getid3/module.audio.vqf.php @@ -22,14 +22,14 @@ // // $Id: module.audio.vqf.php,v 1.3 2006/11/16 23:16:31 ah Exp $ - - + + class getid3_vqf extends getid3_handler { public function Analyze() { - - $getid3 = $this->getid3; + + $getid3 = $this->getid3; // based loosely on code from TTwinVQ by Jurgen Faul <jfaulØgmx*de> // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html @@ -51,18 +51,18 @@ class getid3_vqf extends getid3_handler $info_vqf_raw['header_tag'] = 'TWIN'; // Magic bytes $info_vqf_raw['version'] = substr($vqf_header_data, 4, 8); $info_vqf_raw['size'] = getid3_lib::BigEndian2Int(substr($vqf_header_data, 12, 4)); - + while (ftell($getid3->fp) < $getid3->info['avdataend']) { $chunk_base_offset = ftell($getid3->fp); $chunk_data = fread($getid3->fp, 8); $chunk_name = substr($chunk_data, 0, 4); - + if ($chunk_name == 'DATA') { $getid3->info['avdataoffset'] = $chunk_base_offset; break; } - + $chunk_size = getid3_lib::BigEndian2Int(substr($chunk_data, 4, 4)); if ($chunk_size > ($getid3->info['avdataend'] - ftell($getid3->fp))) { throw new getid3_exception('Invalid chunk size ('.$chunk_size.') for chunk "'.$chunk_name.'" at offset 8.'); @@ -72,10 +72,10 @@ class getid3_vqf extends getid3_handler } switch ($chunk_name) { - + case 'COMM': $info_vqf['COMM'] = array (); - getid3_lib::ReadSequence('BigEndian2Int', $info_vqf['COMM'], $chunk_data, 8, + getid3_lib::ReadSequence('BigEndian2Int', $info_vqf['COMM'], $chunk_data, 8, array ( 'channel_mode' => 4, 'bitrate' => 4, @@ -131,11 +131,11 @@ class getid3_vqf extends getid3_handler return true; } - + public static function VQFchannelFrequencyLookup($frequencyid) { - + static $lookup = array ( 11 => 11025, 22 => 22050, @@ -147,7 +147,7 @@ class getid3_vqf extends getid3_handler public static function VQFcommentNiceNameLookup($shortname) { - + static $lookup = array ( 'NAME' => 'title', 'AUTH' => 'artist', diff --git a/modules/getid3/module.audio.wavpack.php b/modules/getid3/module.audio.wavpack.php index 6a687a48..f1adf7bf 100644 --- a/modules/getid3/module.audio.wavpack.php +++ b/modules/getid3/module.audio.wavpack.php @@ -29,12 +29,12 @@ class getid3_wavpack extends getid3_handler public function Analyze() { $getid3 = $this->getid3; - + $getid3->include_module('audio-video.riff'); - + $getid3->info['wavpack'] = array (); $info_wavpack = &$getid3->info['wavpack']; - + fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); while (true) { @@ -62,7 +62,7 @@ class getid3_wavpack extends getid3_handler } if ((@$info_wavpack_blockheader['block_samples'] <= 0) || (@$info_wavpack_blockheader['total_samples'] <= 0)) { - + // Also, it is possible that the first block might not have // any samples (block_samples == 0) and in this case you should skip blocks // until you find one with samples because the other information (like @@ -99,7 +99,7 @@ class getid3_wavpack extends getid3_handler $info_wavpack_blockheader['track_number'] = ord($wavpack_header{10}); // unused $info_wavpack_blockheader['index_number'] = ord($wavpack_header{11}); // unused - + getid3_lib::ReadSequence('LittleEndian2Int', $info_wavpack_blockheader, $wavpack_header, 12, array ( 'total_samples' => 4, @@ -109,8 +109,8 @@ class getid3_wavpack extends getid3_handler 'crc' => 4 ) ); - - + + $info_wavpack_blockheader['flags']['bytes_per_sample'] = 1 + ($info_wavpack_blockheader['flags_raw'] & 0x00000003); $info_wavpack_blockheader['flags']['mono'] = (bool) ($info_wavpack_blockheader['flags_raw'] & 0x00000004); $info_wavpack_blockheader['flags']['hybrid'] = (bool) ($info_wavpack_blockheader['flags_raw'] & 0x00000008); @@ -146,7 +146,7 @@ class getid3_wavpack extends getid3_handler // then the decoder simply ignores the metadata, but if it is zero // then the decoder should quit because it means that an understanding // of the metadata is required to correctly decode the audio. - + $metablock['non_decoder'] = (bool) ($metablock['id'] & 0x20); $metablock['padded_data'] = (bool) ($metablock['id'] & 0x40); $metablock['large_block'] = (bool) ($metablock['id'] & 0x80); @@ -204,24 +204,24 @@ class getid3_wavpack extends getid3_handler switch ($metablock['function_id']) { case 0x21: // ID_RIFF_HEADER - + $original_wav_filesize = getid3_lib::LittleEndian2Int(substr($metablock['data'], 4, 4)); - - // Clone getid3 + + // Clone getid3 $clone = clone $getid3; - + // Analyze clone by string $riff = new getid3_riff($clone); $riff->AnalyzeString($metablock['data']); - + // Import from clone and destroy $metablock['riff'] = $clone->info['riff']; $getid3->warnings($clone->warnings()); unset($clone); - + // Save RIFF header - we may need it later for RIFF footer parsing $this->riff_header = $metablock['data']; - + $metablock['riff']['original_filesize'] = $original_wav_filesize; $info_wavpack['riff_trailer_size'] = $original_wav_filesize - $metablock['riff']['WAVE']['data'][0]['size'] - $metablock['riff']['header_size']; @@ -236,19 +236,19 @@ class getid3_wavpack extends getid3_handler case 0x22: // ID_RIFF_TRAILER $metablock_riff_footer = $metablock_riff_header.$metablock['data']; - + $start_offset = $metablock['offset'] + ($metablock['large_block'] ? 4 : 2); - + $ftell_old = ftell($getid3->fp); - - // Clone getid3 + + // Clone getid3 $clone = clone $getid3; - + // Call public method that really should be private $riff = new getid3_riff($clone); $metablock['riff'] = $riff->ParseRIFF($start_offset, $start_offset + $metablock['size']); unset($clone); - + fseek($getid3->fp, $ftell_old, SEEK_SET); if (!empty($metablock['riff']['INFO'])) { @@ -342,7 +342,7 @@ class getid3_wavpack extends getid3_handler } } - + if (!empty($metablock)) { $info_wavpack['metablocks'][] = $metablock; } @@ -390,7 +390,7 @@ class getid3_wavpack extends getid3_handler 0x25 => 'Config Block', 0x26 => 'MD5 Checksum', ); - + return (@$lookup[$id]); } diff --git a/modules/getid3/module.audio.xiph.php b/modules/getid3/module.audio.xiph.php index b9100e8a..daf15806 100644 --- a/modules/getid3/module.audio.xiph.php +++ b/modules/getid3/module.audio.xiph.php @@ -23,45 +23,45 @@ // // $Id: module.audio.xiph.php,v 1.5 2006/12/03 21:12:43 ah Exp $ - - + + class getid3_xiph extends getid3_handler { - + public function Analyze() { - + $getid3 = $this->getid3; - - if ($getid3->option_tags_images) { + + if ($getid3->option_tags_images) { $getid3->include_module('lib.image_size'); } - + fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); - + $magic = fread($getid3->fp, 4); - + if ($magic == 'OggS') { return $this->ParseOgg(); } - + if ($magic == 'fLaC') { return $this->ParseFLAC(); } - + } - - - + + + private function ParseOgg() { - + $getid3 = $this->getid3; - + fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); - + $getid3->info['audio'] = $getid3->info['ogg'] = array (); - $info_ogg = &$getid3->info['ogg']; + $info_ogg = &$getid3->info['ogg']; $info_audio = &$getid3->info['audio']; - + $getid3->info['fileformat'] = 'ogg'; @@ -85,9 +85,9 @@ class getid3_xiph extends getid3_handler $info_audio['bitrate_mode'] = 'vbr'; $info_audio['lossless'] = true; - } - - + } + + // Ogg Vorbis elseif (substr($file_data, 1, 6) == 'vorbis') { @@ -96,8 +96,8 @@ class getid3_xiph extends getid3_handler $info_ogg['pageheader'][$ogg_page_info['page_seqno']]['packet_type'] = getid3_lib::LittleEndian2Int($file_data[0]); $info_ogg['pageheader'][$ogg_page_info['page_seqno']]['stream_type'] = substr($file_data, 1, 6); // hard-coded to 'vorbis' - - getid3_lib::ReadSequence('LittleEndian2Int', $info_ogg, $file_data, 7, + + getid3_lib::ReadSequence('LittleEndian2Int', $info_ogg, $file_data, 7, array ( 'bitstreamversion' => 4, 'numberofchannels' => 1, @@ -107,12 +107,12 @@ class getid3_xiph extends getid3_handler 'bitrate_min' => 4 ) ); - + $n28 = getid3_lib::LittleEndian2Int($file_data{28}); $info_ogg['blocksize_small'] = pow(2, $n28 & 0x0F); $info_ogg['blocksize_large'] = pow(2, ($n28 & 0xF0) >> 4); $info_ogg['stop_bit'] = $n28; - + $info_audio['channels'] = $info_ogg['numberofchannels']; $info_audio['sample_rate'] = $info_ogg['samplerate']; @@ -122,17 +122,17 @@ class getid3_xiph extends getid3_handler unset($info_ogg['bitrate_max']); $info_audio['bitrate_mode'] = 'abr'; } - + if ($info_ogg['bitrate_nominal'] == 0xFFFFFFFF) { unset($info_ogg['bitrate_nominal']); } - + if ($info_ogg['bitrate_min'] == 0xFFFFFFFF) { unset($info_ogg['bitrate_min']); $info_audio['bitrate_mode'] = 'abr'; } } - + // Speex elseif (substr($file_data, 0, 8) == 'Speex ') { @@ -144,10 +144,10 @@ class getid3_xiph extends getid3_handler $info_audio['bitrate_mode'] = 'abr'; $info_audio['lossless'] = false; - getid3_lib::ReadSequence('LittleEndian2Int', $info_ogg['pageheader'][$ogg_page_info['page_seqno']], $file_data, 0, + getid3_lib::ReadSequence('LittleEndian2Int', $info_ogg['pageheader'][$ogg_page_info['page_seqno']], $file_data, 0, array ( 'speex_string' => -8, // hard-coded to 'Speex ' - 'speex_version' => -20, // string + 'speex_version' => -20, // string 'speex_version_id' => 4, 'header_size' => 4, 'rate' => 4, @@ -163,7 +163,7 @@ class getid3_xiph extends getid3_handler 'reserved2' => 4 ) ); - + $getid3->info['speex']['speex_version'] = trim($info_ogg['pageheader'][$ogg_page_info['page_seqno']]['speex_version']); $getid3->info['speex']['sample_rate'] = $info_ogg['pageheader'][$ogg_page_info['page_seqno']]['rate']; $getid3->info['speex']['channels'] = $info_ogg['pageheader'][$ogg_page_info['page_seqno']]['nb_channels']; @@ -172,7 +172,7 @@ class getid3_xiph extends getid3_handler $info_audio['sample_rate'] = $getid3->info['speex']['sample_rate']; $info_audio['channels'] = $getid3->info['speex']['channels']; - + if ($getid3->info['speex']['vbr']) { $info_audio['bitrate_mode'] = 'vbr'; } @@ -216,7 +216,7 @@ class getid3_xiph extends getid3_handler fseek($getid3->fp, max($getid3->info['avdataend'] - getid3::FREAD_BUFFER_SIZE, 0), SEEK_SET); $last_chunk_of_ogg = strrev(fread($getid3->fp, getid3::FREAD_BUFFER_SIZE)); - + if ($last_OggS_postion = strpos($last_chunk_of_ogg, 'SggO')) { fseek($getid3->fp, $getid3->info['avdataend'] - ($last_OggS_postion + strlen('SggO')), SEEK_SET); $getid3->info['avdataend'] = ftell($getid3->fp); @@ -268,15 +268,15 @@ class getid3_xiph extends getid3_handler private function ParseOggPageHeader() { - + $getid3 = $this->getid3; - + // http://xiph.org/ogg/vorbis/doc/framing.html $ogg_header['page_start_offset'] = ftell($getid3->fp); // where we started from in the file - + $file_data = fread($getid3->fp, getid3::FREAD_BUFFER_SIZE); $file_data_offset = 0; - + while ((substr($file_data, $file_data_offset++, 4) != 'OggS')) { if ((ftell($getid3->fp) - $ogg_header['page_start_offset']) >= getid3::FREAD_BUFFER_SIZE) { // should be found before here @@ -289,10 +289,10 @@ class getid3_xiph extends getid3_handler } } } - + $file_data_offset += 3; // page, delimited by 'OggS' - - getid3_lib::ReadSequence('LittleEndian2Int', $ogg_header, $file_data, $file_data_offset, + + getid3_lib::ReadSequence('LittleEndian2Int', $ogg_header, $file_data, $file_data_offset, array ( 'stream_structver' => 1, 'flags_raw' => 1, @@ -303,7 +303,7 @@ class getid3_xiph extends getid3_handler 'page_segments' => 1 ) ); - + $file_data_offset += 23; $ogg_header['flags']['fresh'] = (bool)($ogg_header['flags_raw'] & 0x01); // fresh packet @@ -323,9 +323,9 @@ class getid3_xiph extends getid3_handler } - + private function ParseVorbisCommentsFilepointer() { - + $getid3 = $this->getid3; $original_offset = ftell($getid3->fp); @@ -334,7 +334,7 @@ class getid3_xiph extends getid3_handler $vorbis_comment_page = 1; switch ($getid3->info['audio']['dataformat']) { - + case 'vorbis': $comment_start_offset = $getid3->info['ogg']['pageheader'][$vorbis_comment_page]['page_start_offset']; // Second Ogg page, after header block fseek($getid3->fp, $comment_start_offset, SEEK_SET); @@ -342,13 +342,13 @@ class getid3_xiph extends getid3_handler $comment_data = fread($getid3->fp, getid3_xiph::OggPageSegmentLength($getid3->info['ogg']['pageheader'][$vorbis_comment_page], 1) + $comment_data_offset); $comment_data_offset += (strlen('vorbis') + 1); break; - + case 'flac': fseek($getid3->fp, $getid3->info['flac']['VORBIS_COMMENT']['raw']['offset'] + 4, SEEK_SET); $comment_data = fread($getid3->fp, $getid3->info['flac']['VORBIS_COMMENT']['raw']['block_length']); break; - + case 'speex': $comment_start_offset = $getid3->info['ogg']['pageheader'][$vorbis_comment_page]['page_start_offset']; // Second Ogg page, after header block @@ -356,7 +356,7 @@ class getid3_xiph extends getid3_handler $comment_data_offset = 27 + $getid3->info['ogg']['pageheader'][$vorbis_comment_page]['page_segments']; $comment_data = fread($getid3->fp, getid3_xiph::OggPageSegmentLength($getid3->info['ogg']['pageheader'][$vorbis_comment_page], 1) + $comment_data_offset); break; - + default: return false; @@ -370,7 +370,7 @@ class getid3_xiph extends getid3_handler $comments_count = getid3_lib::LittleEndian2Int(substr($comment_data, $comment_data_offset, 4)); $comment_data_offset += 4; - + $getid3->info['avdataoffset'] = $comment_start_offset + $comment_data_offset; for ($i = 0; $i < $comments_count; $i++) { @@ -405,7 +405,7 @@ class getid3_xiph extends getid3_handler $comment_data_offset += 4; while ((strlen($comment_data) - $comment_data_offset) < $getid3->info['ogg']['comments_raw'][$i]['size']) { - + if (($getid3->info['ogg']['comments_raw'][$i]['size'] > $getid3->info['avdataend']) || ($getid3->info['ogg']['comments_raw'][$i]['size'] < 0)) { throw new getid3_exception('Invalid Ogg comment size (comment #'.$i.', claims to be '.number_format($getid3->info['ogg']['comments_raw'][$i]['size']).' bytes) - aborting reading comments'); } @@ -454,12 +454,12 @@ class getid3_xiph extends getid3_handler $image_chunk_check = getid3_lib_image_size::get($getid3->info['ogg']['comments_raw'][$i]['data']); $getid3->info['ogg']['comments_raw'][$i]['image_mime'] = image_type_to_mime_type($image_chunk_check[2]); } - + if (!@$getid3->info['ogg']['comments_raw'][$i]['image_mime'] || ($getid3->info['ogg']['comments_raw'][$i]['image_mime'] == 'application/octet-stream')) { unset($getid3->info['ogg']['comments_raw'][$i]['image_mime']); unset($getid3->info['ogg']['comments_raw'][$i]['data']); } - + } else { @@ -495,7 +495,7 @@ class getid3_xiph extends getid3_handler $getid3->info['replay_gain']['track']['peak'] = (float)$commentvalue[0]; unset($getid3->info['ogg']['comments'][$index]); break; - + case 'replaygain_reference_loudness': $getid3->info['replay_gain']['reference_volume'] = (float)$commentvalue[0]; unset($getid3->info['ogg']['comments'][$index]); @@ -512,9 +512,9 @@ class getid3_xiph extends getid3_handler private function ParseFLAC() { - + $getid3 = $this->getid3; - + // http://flac.sourceforge.net/format.html $getid3->info['fileformat'] = 'flac'; @@ -528,11 +528,11 @@ class getid3_xiph extends getid3_handler private function FLACparseMETAdata() { - + $getid3 = $this->getid3; do { - + $meta_data_block_offset = ftell($getid3->fp); $meta_data_block_header = fread($getid3->fp, 4); $meta_data_last_block_flag = (bool)(getid3_lib::BigEndian2Int($meta_data_block_header[0]) & 0x80); @@ -590,7 +590,7 @@ class getid3_xiph extends getid3_handler return false; } break; - + case 'PICTURE': if (!$this->FLACparsePICTURE($getid3->info['flac'][$meta_data_block_type_text]['raw']['block_data'])) { return false; @@ -648,9 +648,9 @@ class getid3_xiph extends getid3_handler private function FLACparseSTREAMINFO($meta_data_block_data) { - + $getid3 = $this->getid3; - + getid3_lib::ReadSequence('BigEndian2Int', $getid3->info['flac']['STREAMINFO'], $meta_data_block_data, 0, array ( 'min_block_size' => 2, @@ -661,7 +661,7 @@ class getid3_xiph extends getid3_handler ); $sample_rate_channels_sample_bits_stream_samples = getid3_lib::BigEndian2Bin(substr($meta_data_block_data, 10, 8)); - + $getid3->info['flac']['STREAMINFO']['sample_rate'] = bindec(substr($sample_rate_channels_sample_bits_stream_samples, 0, 20)); $getid3->info['flac']['STREAMINFO']['channels'] = bindec(substr($sample_rate_channels_sample_bits_stream_samples, 20, 3)) + 1; $getid3->info['flac']['STREAMINFO']['bits_per_sample'] = bindec(substr($sample_rate_channels_sample_bits_stream_samples, 23, 5)) + 1; @@ -681,7 +681,7 @@ class getid3_xiph extends getid3_handler throw new getid3_exception('Corrupt METAdata block: STREAMINFO'); } - + unset($getid3->info['flac']['STREAMINFO']['raw']); return true; @@ -690,14 +690,14 @@ class getid3_xiph extends getid3_handler private function FLACparseAPPLICATION($meta_data_block_data) { - + $getid3 = $this->getid3; - + $application_id = getid3_lib::BigEndian2Int(substr($meta_data_block_data, 0, 4)); - + $getid3->info['flac']['APPLICATION'][$application_id]['name'] = getid3_xiph::FLACapplicationIDLookup($application_id); $getid3->info['flac']['APPLICATION'][$application_id]['data'] = substr($meta_data_block_data, 4); - + unset($getid3->info['flac']['APPLICATION']['raw']); return true; @@ -706,9 +706,9 @@ class getid3_xiph extends getid3_handler private function FLACparseSEEKTABLE($meta_data_block_data) { - + $getid3 = $this->getid3; - + $offset = 0; $meta_data_block_length = strlen($meta_data_block_data); while ($offset < $meta_data_block_length) { @@ -723,36 +723,36 @@ class getid3_xiph extends getid3_handler } else { $sample_number = getid3_lib::BigEndian2Int($sample_number_string); - + $getid3->info['flac']['SEEKTABLE'][$sample_number]['offset'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 8)); $offset += 8; - + $getid3->info['flac']['SEEKTABLE'][$sample_number]['samples'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 2)); $offset += 2; } } - + unset($getid3->info['flac']['SEEKTABLE']['raw']); - + return true; } private function FLACparseCUESHEET($meta_data_block_data) { - + $getid3 = $this->getid3; - + $getid3->info['flac']['CUESHEET']['media_catalog_number'] = trim(substr($meta_data_block_data, 0, 128), "\0"); $getid3->info['flac']['CUESHEET']['lead_in_samples'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, 128, 8)); $getid3->info['flac']['CUESHEET']['flags']['is_cd'] = (bool)(getid3_lib::BigEndian2Int($meta_data_block_data[136]) & 0x80); $getid3->info['flac']['CUESHEET']['number_tracks'] = getid3_lib::BigEndian2Int($meta_data_block_data[395]); $offset = 396; - + for ($track = 0; $track < $getid3->info['flac']['CUESHEET']['number_tracks']; $track++) { - + $track_sample_offset = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 8)); $offset += 8; @@ -771,74 +771,74 @@ class getid3_xiph extends getid3_handler $getid3->info['flac']['CUESHEET']['tracks'][$track_number]['index_points'] = getid3_lib::BigEndian2Int($meta_data_block_data{$offset++}); for ($index = 0; $index < $getid3->info['flac']['CUESHEET']['tracks'][$track_number]['index_points']; $index++) { - + $index_sample_offset = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 8)); $offset += 8; - + $index_number = getid3_lib::BigEndian2Int($meta_data_block_data{$offset++}); $getid3->info['flac']['CUESHEET']['tracks'][$track_number]['indexes'][$index_number] = $index_sample_offset; - + $offset += 3; // reserved } } - + unset($getid3->info['flac']['CUESHEET']['raw']); - + return true; } - - - + + + private function FLACparsePICTURE($meta_data_block_data) { - + $getid3 = $this->getid3; - + $picture = &$getid3->info['flac']['PICTURE'][sizeof($getid3->info['flac']['PICTURE']) - 1]; - + $offset = 0; - + $picture['type'] = $this->FLACpictureTypeLookup(getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4))); $offset += 4; - + $length = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)); $offset += 4; - + $picture['mime_type'] = substr($meta_data_block_data, $offset, $length); $offset += $length; - + $length = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)); $offset += 4; - + $picture['description'] = substr($meta_data_block_data, $offset, $length); $offset += $length; - + $picture['width'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)); $offset += 4; - + $picture['height'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)); $offset += 4; - + $picture['color_depth'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)); $offset += 4; - + $picture['colors_indexed'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)); $offset += 4; - + $length = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)); $offset += 4; - + $picture['image_data'] = substr($meta_data_block_data, $offset, $length); $offset += $length; - + unset($getid3->info['flac']['PICTURE']['raw']); - + return true; } - - - + + + public static function SpeexBandModeLookup($mode) { - + static $lookup = array ( 0 => 'narrow', 1 => 'wide', @@ -851,8 +851,8 @@ class getid3_xiph extends getid3_handler public static function OggPageSegmentLength($ogg_info_array, $segment_number=1) { - if (!is_array($ogg_info_array['segment_table'])) { $ogg_info_array['segment_table'] = array(); } - + if (!is_array($ogg_info_array['segment_table'])) { $ogg_info_array['segment_table'] = array(); } + for ($i = 0; $i < $segment_number; $i++) { $segment_length = 0; foreach ($ogg_info_array['segment_table'] as $key => $value) { @@ -862,7 +862,7 @@ class getid3_xiph extends getid3_handler } } } - $segment_length = !$segment_length ? '1' : $segment_length; + $segment_length = !$segment_length ? '1' : $segment_length; return $segment_length; } @@ -888,11 +888,11 @@ class getid3_xiph extends getid3_handler } return round($qval, 1); // 5 or 4.9 } - - - + + + public static function FLACmetaBlockTypeLookup($block_type) { - + static $lookup = array ( 0 => 'STREAMINFO', 1 => 'PADDING', @@ -908,24 +908,24 @@ class getid3_xiph extends getid3_handler public static function FLACapplicationIDLookup($application_id) { - + // http://flac.sourceforge.net/id.html - + static $lookup = array ( 0x46746F6C => 'flac-tools', // 'Ftol' 0x46746F6C => 'Sound Font FLAC', // 'SFFL' 0x7065656D => 'Parseable Embedded Extensible Metadata (specification)', // 'peem' 0x786D6364 => 'xmcd' - + ); return (isset($lookup[$application_id]) ? $lookup[$application_id] : 'reserved'); } public static function FLACpictureTypeLookup($type_id) { - + static $lookup = array ( - + 0 => 'Other', 1 => "32x32 pixels 'file icon' (PNG only)", 2 => 'Other file icon', diff --git a/modules/getid3/module.graphic.bmp.php b/modules/getid3/module.graphic.bmp.php index 43dc9914..1769e849 100644 --- a/modules/getid3/module.graphic.bmp.php +++ b/modules/getid3/module.graphic.bmp.php @@ -22,8 +22,8 @@ // // $Id: module.graphic.bmp.php,v 1.4 2006/11/02 10:48:02 ah Exp $ - - + + class getid3_bmp extends getid3_handler { @@ -39,7 +39,7 @@ class getid3_bmp extends getid3_handler // WORD bfReserved1; // WORD bfReserved2; // DWORD bfOffBits; - + // shortcuts $getid3->info['bmp']['header']['raw'] = array (); $info_bmp = &$getid3->info['bmp']; @@ -51,7 +51,7 @@ class getid3_bmp extends getid3_handler // Magic bytes $info_bmp_header_raw['identifier'] = 'BM'; - + getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 2, array ( 'filesize' => 4, @@ -61,34 +61,34 @@ class getid3_bmp extends getid3_handler 'header_size' => 4 ) ); - + // Check if the hardcoded-to-1 "planes" is at offset 22 or 26 $planes22 = getid3_lib::LittleEndian2Int(substr($bmp_header, 22, 2)); $planes26 = getid3_lib::LittleEndian2Int(substr($bmp_header, 26, 2)); if (($planes22 == 1) && ($planes26 != 1)) { $info_bmp['type_os'] = 'OS/2'; $info_bmp['type_version'] = 1; - } + } elseif (($planes26 == 1) && ($planes22 != 1)) { $info_bmp['type_os'] = 'Windows'; $info_bmp['type_version'] = 1; - } + } elseif ($info_bmp_header_raw['header_size'] == 12) { $info_bmp['type_os'] = 'OS/2'; $info_bmp['type_version'] = 1; - } + } elseif ($info_bmp_header_raw['header_size'] == 40) { $info_bmp['type_os'] = 'Windows'; $info_bmp['type_version'] = 1; - } + } elseif ($info_bmp_header_raw['header_size'] == 84) { $info_bmp['type_os'] = 'Windows'; $info_bmp['type_version'] = 4; - } + } elseif ($info_bmp_header_raw['header_size'] == 100) { $info_bmp['type_os'] = 'Windows'; $info_bmp['type_version'] = 5; - } + } else { throw new getid3_exception('Unknown BMP subtype (or not a BMP file)'); } @@ -108,7 +108,7 @@ class getid3_bmp extends getid3_handler // DWORD Height; /* Bitmap height in pixel */ // WORD NumPlanes; /* Number of bit planes (color depth) */ // WORD BitsPerPixel; /* Number of bits per pixel per plane */ - + getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 18, array ( 'width' => 2, @@ -117,12 +117,12 @@ class getid3_bmp extends getid3_handler 'bits_per_pixel' => 2 ) ); - + $getid3->info['video']['resolution_x'] = $info_bmp_header_raw['width']; $getid3->info['video']['resolution_y'] = $info_bmp_header_raw['height']; $getid3->info['video']['codec'] = 'BI_RGB '.$info_bmp_header_raw['bits_per_pixel'].'-bit'; $getid3->info['video']['bits_per_sample'] = $info_bmp_header_raw['bits_per_pixel']; - + if ($info_bmp['type_version'] >= 2) { // DWORD Compression; /* Bitmap compression scheme */ // DWORD ImageDataSize; /* Size of bitmap data in bytes */ @@ -138,7 +138,7 @@ class getid3_bmp extends getid3_handler // DWORD Size2; /* Reserved for halftoning algorithm use */ // DWORD ColorEncoding; /* Color model used in bitmap */ // DWORD Identifier; /* Reserved for application use */ - + getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 26, array ( 'compression' => 4, @@ -161,11 +161,11 @@ class getid3_bmp extends getid3_handler $info_bmp_header['compression'] = getid3_bmp::BMPcompressionOS2Lookup($info_bmp_header_raw['compression']); $getid3->info['video']['codec'] = $info_bmp_header['compression'].' '.$info_bmp_header_raw['bits_per_pixel'].'-bit'; } - + return true; - } - - + } + + if ($info_bmp['type_os'] == 'Windows') { // Windows-format BMP @@ -201,7 +201,7 @@ class getid3_bmp extends getid3_handler foreach (array ('width', 'height', 'resolution_h', 'resolution_v') as $key) { $info_bmp_header_raw[$key] = getid3_lib::LittleEndian2Int($info_bmp_header_raw[$key], true); } - + $info_bmp_header['compression'] = getid3_bmp::BMPcompressionWindowsLookup($info_bmp_header_raw['compression']); $getid3->info['video']['resolution_x'] = $info_bmp_header_raw['width']; $getid3->info['video']['resolution_y'] = $info_bmp_header_raw['height']; @@ -210,8 +210,8 @@ class getid3_bmp extends getid3_handler // should only be v4+, but BMPs with type_version==1 and BI_BITFIELDS compression have been seen if (($info_bmp['type_version'] >= 4) || ($info_bmp_header_raw['compression'] == 3)) { - - + + $bmp_header .= fread($getid3->fp, 44); // BITMAPV4HEADER - [44 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_2k1e.asp @@ -225,7 +225,7 @@ class getid3_bmp extends getid3_handler // DWORD bV4GammaRed; // DWORD bV4GammaGreen; // DWORD bV4GammaBlue; - + getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 54, array ( 'red_mask' => 4, @@ -241,22 +241,22 @@ class getid3_bmp extends getid3_handler 'gamma_blue' => 4 ) ); - + $info_bmp_header['ciexyz_red'] = getid3_bmp::FixedPoint2_30(strrev($info_bmp_header_raw['ciexyz_red'])); $info_bmp_header['ciexyz_green'] = getid3_bmp::FixedPoint2_30(strrev($info_bmp_header_raw['ciexyz_green'])); $info_bmp_header['ciexyz_blue'] = getid3_bmp::FixedPoint2_30(strrev($info_bmp_header_raw['ciexyz_blue'])); - + if ($info_bmp['type_version'] >= 5) { $bmp_header .= fread($getid3->fp, 16); - + // BITMAPV5HEADER - [16 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_7c36.asp // Win98+, Win2000+ // DWORD bV5Intent; // DWORD bV5ProfileData; // DWORD bV5ProfileSize; // DWORD bV5Reserved; - + getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 98, array ( 'intent' => 4, @@ -265,16 +265,16 @@ class getid3_bmp extends getid3_handler 'reserved3' => 4 ) ); - + } } - + return true; } throw new getid3_exception('Unknown BMP format in header.'); - + } @@ -295,7 +295,7 @@ class getid3_bmp extends getid3_handler public static function BMPcompressionOS2Lookup($compression_id) { - + static $lookup = array ( 0 => 'BI_RGB', 1 => 'BI_RLE8', @@ -305,10 +305,10 @@ class getid3_bmp extends getid3_handler ); return (isset($lookup[$compression_id]) ? $lookup[$compression_id] : 'invalid'); } - - + + public static function FixedPoint2_30($raw_data) { - + $binary_string = getid3_lib::BigEndian2Bin($raw_data); return bindec(substr($binary_string, 0, 2)) + (float)(bindec(substr($binary_string, 2, 30)) / 1073741824); // pow(2, 30) = 1073741824 } diff --git a/modules/getid3/module.graphic.gif.php b/modules/getid3/module.graphic.gif.php index 67e39592..b0605f29 100644 --- a/modules/getid3/module.graphic.gif.php +++ b/modules/getid3/module.graphic.gif.php @@ -22,20 +22,20 @@ //
// $Id: module.graphic.gif.php,v 1.2 2006/11/02 10:48:02 ah Exp $ - - + + class getid3_gif extends getid3_handler { public function Analyze() { - + $getid3 = $this->getid3; $getid3->info['fileformat'] = 'gif'; $getid3->info['video']['dataformat'] = 'gif'; $getid3->info['video']['lossless'] = true; $getid3->info['video']['pixel_aspect_ratio'] = (float)1; - + $getid3->info['gif']['header'] = array (); $info_gif_header = &$getid3->info['gif']['header']; @@ -44,7 +44,7 @@ class getid3_gif extends getid3_handler // Magic bytes $info_gif_header['raw']['identifier'] = 'GIF'; - + getid3_lib::ReadSequence('LittleEndian2Int', $info_gif_header['raw'], $gif_header, 3, array ( 'version' => -3, // string @@ -59,16 +59,16 @@ class getid3_gif extends getid3_handler $getid3->info['video']['resolution_x'] = $info_gif_header['raw']['width']; $getid3->info['video']['resolution_y'] = $info_gif_header['raw']['height']; $getid3->info['gif']['version'] = $info_gif_header['raw']['version']; - + $info_gif_header['flags']['global_color_table'] = (bool)($info_gif_header['raw']['flags'] & 0x80); - + if ($info_gif_header['raw']['flags'] & 0x80) { // Number of bits per primary color available to the original image, minus 1 $info_gif_header['bits_per_pixel'] = 3 * ((($info_gif_header['raw']['flags'] & 0x70) >> 4) + 1); } else { $info_gif_header['bits_per_pixel'] = 0; } - + $info_gif_header['flags']['global_color_sorted'] = (bool)($info_gif_header['raw']['flags'] & 0x40); if ($info_gif_header['flags']['global_color_table']) { // the number of bytes contained in the Global Color Table. To determine that @@ -78,7 +78,7 @@ class getid3_gif extends getid3_handler } else { $info_gif_header['global_color_size'] = 0; } - + if ($info_gif_header['raw']['aspect_ratio'] != 0) { // Aspect Ratio = (Pixel Aspect Ratio + 15) / 64 $info_gif_header['aspect_ratio'] = ($info_gif_header['raw']['aspect_ratio'] + 15) / 64; diff --git a/modules/getid3/module.graphic.jpeg.php b/modules/getid3/module.graphic.jpeg.php index 2dea8bb3..b9ae489a 100644 --- a/modules/getid3/module.graphic.jpeg.php +++ b/modules/getid3/module.graphic.jpeg.php @@ -22,13 +22,13 @@ //
// $Id: module.graphic.jpeg.php,v 1.4 2006/11/02 10:48:02 ah Exp $ - - + + class getid3_jpeg extends getid3_handler { public function Analyze() { - + $getid3 = $this->getid3; $getid3->info['fileformat'] = 'jpg'; @@ -40,7 +40,7 @@ class getid3_jpeg extends getid3_handler fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); list($getid3->info['video']['resolution_x'], $getid3->info['video']['resolution_y'], $type) = getimagesize($getid3->filename); - + if ($type != 2) { throw new getid3_exception('File detected as JPEG, but is currupt.'); } diff --git a/modules/getid3/module.graphic.pcd.php b/modules/getid3/module.graphic.pcd.php index bf8288fe..c0c5dc5d 100644 --- a/modules/getid3/module.graphic.pcd.php +++ b/modules/getid3/module.graphic.pcd.php @@ -22,14 +22,14 @@ //
// $Id: module.graphic.pcd.php,v 1.2 2006/11/02 10:48:02 ah Exp $ - - + + class getid3_pcd extends getid3_handler { public function Analyze() { - + $getid3 = $this->getid3; $getid3->info['fileformat'] = 'pcd'; diff --git a/modules/getid3/module.graphic.png.php b/modules/getid3/module.graphic.png.php index e697e961..0593b98f 100644 --- a/modules/getid3/module.graphic.png.php +++ b/modules/getid3/module.graphic.png.php @@ -22,8 +22,8 @@ // // $Id: module.graphic.png.php,v 1.4 2006/11/02 10:48:02 ah Exp $ - - + + class getid3_png extends getid3_handler { @@ -46,20 +46,20 @@ class getid3_png extends getid3_handler $offset = 8; while (((ftell($getid3->fp) - (strlen($png_filedata) - $offset)) < $getid3->info['filesize'])) { - + $chunk['data_length'] = getid3_lib::BigEndian2Int(substr($png_filedata, $offset, 4)); $offset += 4; while (((strlen($png_filedata) - $offset) < ($chunk['data_length'] + 4)) && (ftell($getid3->fp) < $getid3->info['filesize'])) { $png_filedata .= fread($getid3->fp, getid3::FREAD_BUFFER_SIZE); } - + $chunk['type_text'] = substr($png_filedata, $offset, 4); $chunk['type_raw'] = getid3_lib::BigEndian2Int($chunk['type_text']); $offset += 4; - + $chunk['data'] = substr($png_filedata, $offset, $chunk['data_length']); $offset += $chunk['data_length']; - + $chunk['crc'] = getid3_lib::BigEndian2Int(substr($png_filedata, $offset, 4)); $offset += 4; @@ -78,8 +78,8 @@ class getid3_png extends getid3_handler $info_png_chunk_type_text['header'] = $chunk; $info_png_chunk_type_text['width'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4)); $info_png_chunk_type_text['height'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4)); - - getid3_lib::ReadSequence('BigEndian2Int', $info_png_chunk_type_text['raw'], $chunk['data'], 8, + + getid3_lib::ReadSequence('BigEndian2Int', $info_png_chunk_type_text['raw'], $chunk['data'], 8, array ( 'bit_depth' => 1, 'color_type' => 1, @@ -196,12 +196,12 @@ class getid3_png extends getid3_handler $info_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int(substr($otherdata, 0, 1)); $info_png_chunk_type_text['compressed_text'] = substr($otherdata, 1); $info_png_chunk_type_text['compression_method_text'] = getid3_png::PNGcompressionMethodLookup($info_png_chunk_type_text['compression_method']); - + if ($info_png_chunk_type_text['compression_method'] != 0) { // unknown compression method break; } - + if (function_exists('gzuncompress')) { $info_png_chunk_type_text['text'] = gzuncompress($info_png_chunk_type_text['compressed_text']); } @@ -211,7 +211,7 @@ class getid3_png extends getid3_handler } $this->zlib_warning = true; } - + if (isset($info_png_chunk_type_text['text'])) { $info_png['comments'][$info_png_chunk_type_text['keyword']][] = $info_png_chunk_type_text['text']; @@ -308,14 +308,14 @@ class getid3_png extends getid3_handler $info_png_chunk_type_text['significant_bits_red'] = getid3_lib::BigEndian2Int($chunk['data'][0]); $info_png_chunk_type_text['significant_bits_green'] = getid3_lib::BigEndian2Int($chunk['data'][1]); $info_png_chunk_type_text['significant_bits_blue'] = getid3_lib::BigEndian2Int($chunk['data'][2]); - break; - - case 4: + break; + + case 4: $info_png_chunk_type_text['significant_bits_gray'] = getid3_lib::BigEndian2Int($chunk['data'][0]); $info_png_chunk_type_text['significant_bits_alpha'] = getid3_lib::BigEndian2Int($chunk['data'][1]); - break; - - case 6: + break; + + case 6: $info_png_chunk_type_text['significant_bits_red'] = getid3_lib::BigEndian2Int($chunk['data'][0]); $info_png_chunk_type_text['significant_bits_green'] = getid3_lib::BigEndian2Int($chunk['data'][1]); $info_png_chunk_type_text['significant_bits_blue'] = getid3_lib::BigEndian2Int($chunk['data'][2]); @@ -330,32 +330,32 @@ class getid3_png extends getid3_handler case 'sPLT': // Suggested Palette $info_png_chunk_type_text['header'] = $chunk; - + list($palettename, $otherdata) = explode("\x00", $chunk['data'], 2); $info_png_chunk_type_text['palette_name'] = $palettename; - + $info_png_chunk_type_text['sample_depth_bits'] = getid3_lib::BigEndian2Int($otherdata[0]); $info_png_chunk_type_text['sample_depth_bytes'] = $info_png_chunk_type_text['sample_depth_bits'] / 8; - + $s_plt_offset = 1; $paletteCounter = 0; while ($s_plt_offset < strlen($otherdata)) { - + $info_png_chunk_type_text['red'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes'])); $s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes']; - + $info_png_chunk_type_text['green'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes'])); $s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes']; - + $info_png_chunk_type_text['blue'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes'])); $s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes']; - + $info_png_chunk_type_text['alpha'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes'])); $s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes']; - + $info_png_chunk_type_text['frequency'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, 2)); $s_plt_offset += 2; - + $paletteCounter++; } break; @@ -465,7 +465,7 @@ class getid3_png extends getid3_handler public static function PNGsRGBintentLookup($sRGB) { - + static $lookup = array ( 0 => 'Perceptual', 1 => 'Relative colorimetric', @@ -478,14 +478,14 @@ class getid3_png extends getid3_handler public static function PNGcompressionMethodLookup($compression_method) { - + return ($compression_method == 0 ? 'deflate/inflate' : 'invalid'); } - - + + public static function PNGpHYsUnitLookup($unit_id) { - + static $lookup = array ( 0 => 'unknown', 1 => 'meter' @@ -493,10 +493,10 @@ class getid3_png extends getid3_handler return (isset($lookup[$unit_id]) ? $lookup[$unit_id] : 'invalid'); } - - + + public static function PNGoFFsUnitLookup($unit_id) { - + static $lookup = array ( 0 => 'pixel', 1 => 'micrometer' @@ -504,10 +504,10 @@ class getid3_png extends getid3_handler return (isset($lookup[$unit_id]) ? $lookup[$unit_id] : 'invalid'); } - - + + public static function PNGpCALequationTypeLookup($equation_type) { - + static $lookup = array ( 0 => 'Linear mapping', 1 => 'Base-e exponential mapping', @@ -528,10 +528,10 @@ class getid3_png extends getid3_handler return (isset($lookup[$unit_id]) ? $lookup[$unit_id] : 'invalid'); } - - + + public static function IHDRcalculateBitsPerSample($color_type, $bit_depth) { - + switch ($color_type) { case 0: // Each pixel is a grayscale sample. return $bit_depth; diff --git a/modules/getid3/module.graphic.tiff.php b/modules/getid3/module.graphic.tiff.php index 45478cb8..75663777 100644 --- a/modules/getid3/module.graphic.tiff.php +++ b/modules/getid3/module.graphic.tiff.php @@ -22,13 +22,13 @@ //
// $Id: module.graphic.tiff.php,v 1.2 2006/11/02 10:48:02 ah Exp $ - - + + class getid3_tiff extends getid3_handler { public function Analyze() { - + $getid3 = $this->getid3; fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); @@ -36,7 +36,7 @@ class getid3_tiff extends getid3_handler $getid3->info['tiff']['byte_order'] = substr($tiff_header, 0, 2) == 'II' ? 'Intel' : 'Motorola'; $endian2int = substr($tiff_header, 0, 2) == 'II' ? 'LittleEndian2Int' : 'BigEndian2Int'; - + $getid3->info['fileformat'] = 'tiff'; $getid3->info['video']['dataformat'] = 'tiff'; $getid3->info['video']['lossless'] = true; @@ -55,11 +55,11 @@ class getid3_tiff extends getid3_handler $current_ifd['fieldcount'] = getid3_lib::$endian2int(fread($getid3->fp, 2)); for ($i = 0; $i < $current_ifd['fieldcount']; $i++) { - + // shortcut $current_ifd['fields'][$i] = array (); $current_ifd_fields_i = &$current_ifd['fields'][$i]; - + $current_ifd_fields_i['raw']['tag'] = getid3_lib::$endian2int(fread($getid3->fp, 2)); $current_ifd_fields_i['raw']['type'] = getid3_lib::$endian2int(fread($getid3->fp, 2)); $current_ifd_fields_i['raw']['length'] = getid3_lib::$endian2int(fread($getid3->fp, 4)); @@ -183,7 +183,7 @@ class getid3_tiff extends getid3_handler public static function TIFFcompressionMethod($id) { - + static $lookup = array ( 1 => 'Uncompressed', 2 => 'Huffman', @@ -197,7 +197,7 @@ class getid3_tiff extends getid3_handler public static function TIFFcommentName($id) { - + static $lookup = array ( 270 => 'imagedescription', 271 => 'make', diff --git a/modules/getid3/module.lib.data_hash.php b/modules/getid3/module.lib.data_hash.php index 4ec541c6..00032db8 100644 --- a/modules/getid3/module.lib.data_hash.php +++ b/modules/getid3/module.lib.data_hash.php @@ -26,23 +26,23 @@ class getid3_lib_data_hash { - + private $getid3; - - + + // constructer - calculate md5/sha1 data public function __construct(getID3 $getid3, $algorithm) { - + $this->getid3 = $getid3; - + // Check algorithm if (!preg_match('/^(md5|sha1)$/', $algorithm)) { throw new getid3_exception('Unsupported algorithm, "'.$algorithm.'", in GetHashdata()'); } - - + + //// Handle ogg vorbis files - + if ((@$getid3->info['fileformat'] == 'ogg') && (@$getid3->info['audio']['dataformat'] == 'vorbis')) { // We cannot get an identical md5_data value for Ogg files where the comments @@ -66,11 +66,11 @@ class getid3_lib_data_hash if ((bool)ini_get('safe_mode')) { throw new getid3_exception('PHP running in Safe Mode - cannot make system call to vorbiscomment[.exe] needed for '.$algorithm.'_data.'); } - + if (!preg_match('/^Vorbiscomment /', `vorbiscomment --version 2>&1`)) { throw new getid3_exception('vorbiscomment[.exe] binary not found in path. UNIX: typically /usr/bin. Windows: typically c:\windows\system32.'); } - + // Prevent user from aborting script $old_abort = ignore_user_abort(true); @@ -80,13 +80,13 @@ class getid3_lib_data_hash // Use vorbiscomment to make temp file without comments $temp = tempnam('*', 'getID3'); - + $command_line = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg(realpath($getid3->filename)).' '.escapeshellarg($temp).' 2>&1'; // Error from vorbiscomment if ($vorbis_comment_error = `$command_line`) { throw new getid3_exception('System call to vorbiscomment[.exe] failed.'); - } + } // Get hash of newly created file $hash_function = $algorithm . '_file'; @@ -98,16 +98,16 @@ class getid3_lib_data_hash // Reset abort setting ignore_user_abort($old_abort); - + // Return success return true; } //// Handle other file formats - + // Get hash from part of file if (@$getid3->info['avdataoffset'] || (@$getid3->info['avdataend'] && @$getid3->info['avdataend'] < $getid3->info['filesize'])) { - + if ((bool)ini_get('safe_mode')) { $getid3->warning('PHP running in Safe Mode - backtick operator not available, using slower non-system-call '.$algorithm.' algorithm.'); $hash_function = 'hash_file_partial_safe_mode'; @@ -115,52 +115,52 @@ class getid3_lib_data_hash else { $hash_function = 'hash_file_partial'; } - + $getid3->info[$algorithm.'_data'] = $this->$hash_function($getid3->filename, $getid3->info['avdataoffset'], $getid3->info['avdataend'], $algorithm); - } - + } + // Get hash from whole file - use built-in md5_file() and sha1_file() else { $hash_function = $algorithm . '_file'; $getid3->info[$algorithm.'_data'] = $hash_function($getid3->filename); } } - - - + + + // Return md5/sha1sum for a file from starting position to absolute end position // Using windows system call private function hash_file_partial($file, $offset, $end, $algorithm) { - + // It seems that sha1sum.exe for Windows only works on physical files, does not accept piped data // Fall back to create-temp-file method: if ($algorithm == 'sha1' && strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { return $this->hash_file_partial_safe_mode($file, $offset, $end, $algorithm); } - + // Check for presence of binaries and revert to safe mode if not found if (!`head --version`) { return $this->hash_file_partial_safe_mode($file, $offset, $end, $algorithm); } - + if (!`tail --version`) { return $this->hash_file_partial_safe_mode($file, $offset, $end, $algorithm); } - + if (!`${algorithm}sum --version`) { return $this->hash_file_partial_safe_mode($file, $offset, $end, $algorithm); - } - + } + $size = $end - $offset; $command_line = 'head -c'.$end.' '.escapeshellarg(realpath($file)).' | tail -c'.$size.' | '.$algorithm.'sum'; return substr(`$command_line`, 0, $algorithm == 'md5' ? 32 : 40); } - - + + // Return md5/sha1sum for a file from starting position to absolute end position // Using slow safe_mode temp file - private function hash_file_partial_safe_mode($file, $offset, $end, $algorithm) { + private function hash_file_partial_safe_mode($file, $offset, $end, $algorithm) { // Attempt to create a temporary file in the system temp directory - invalid dirname should force to system temp dir if (($data_filename = tempnam('*', 'getID3')) === false) { diff --git a/modules/getid3/module.lib.iconv_replacement.php b/modules/getid3/module.lib.iconv_replacement.php index 1c5b2fd0..997fe4ce 100644 --- a/modules/getid3/module.lib.iconv_replacement.php +++ b/modules/getid3/module.lib.iconv_replacement.php @@ -31,27 +31,27 @@ class getid3_iconv_replacement if ($in_charset == $out_charset) { return $string; } - + static $supported_charsets = array ( - 'ISO-8859-1' => 'iso88591', + 'ISO-8859-1' => 'iso88591', 'UTF-8' => 'utf8', - 'UTF-16BE' => 'utf16be', - 'UTF-16LE' => 'utf16le', + 'UTF-16BE' => 'utf16be', + 'UTF-16LE' => 'utf16le', 'UTF-16' => 'utf16' ); // Convert $function_name = 'iconv_' . @$supported_charsets[$in_charset] . '_' . @$supported_charsets[$out_charset]; - + if (is_callable(array('getid3_iconv_replacement', $function_name))) { return getid3_iconv_replacement::$function_name($string); } - + // Invalid charset used if (!@$supported_charsets[$in_charset]) { throw new getid3_exception('PHP does not have iconv() support - cannot use ' . $in_charset . ' charset.'); } - + if (!@$supported_charsets[$out_charset]) { throw new getid3_exception('PHP does not have iconv() support - cannot use ' . $out_charset . ' charset.'); } @@ -272,15 +272,15 @@ class getid3_iconv_replacement return $newcharstring; } - - + + // UTF-8 => UTF-16 public static function iconv_utf8_utf16($string) { return getid3_lib::iconv_utf8_utf16le($string, true); } - - + + // UTF-16BE => ISO-8859-1 public static function iconv_utf16be_iso88591($string) { if (substr($string, 0, 2) == "\xFE\xFF") { @@ -295,8 +295,8 @@ class getid3_iconv_replacement return $newcharstring; } - - + + // UTF-16BE => UTF-8 public static function iconv_utf16be_utf8($string) { if (substr($string, 0, 2) == "\xFE\xFF") { @@ -310,23 +310,23 @@ class getid3_iconv_replacement } return $newcharstring; } - - - + + + // UTF-16BE => UTF-16LE public static function iconv_utf16be_utf16le($string) { return getid3_iconv_replacement::iconv_utf8_utf16le(getid3_iconv_replacement::iconv_utf16be_utf8($string)); } - - - + + + // UTF-16BE => UTF-16 public static function iconv_utf16be_utf16($string) { return getid3_iconv_replacement::iconv_utf8_utf16(getid3_iconv_replacement::iconv_utf16be_utf8($string)); } - - - + + + // UTF-16LE => ISO-8859-1 public static function iconv_utf16le_iso88591($string) { if (substr($string, 0, 2) == "\xFF\xFE") { @@ -341,8 +341,8 @@ class getid3_iconv_replacement return $newcharstring; } - - + + // UTF-16LE => UTF-8 public static function iconv_utf16le_utf8($string) { if (substr($string, 0, 2) == "\xFF\xFE") { @@ -357,22 +357,22 @@ class getid3_iconv_replacement return $newcharstring; } - - + + // UTF-16LE => UTF-16BE public static function iconv_utf16le_utf16be($string) { return getid3_iconv_replacement::iconv_utf8_utf16be(getid3_iconv_replacement::iconv_utf16le_utf8($string)); } - - - + + + // UTF-16LE => UTF-16 public static function iconv_utf16le_utf16($string) { return getid3_iconv_replacement::iconv_utf8_utf16(getid3_iconv_replacement::iconv_utf16le_utf8($string)); } - - - + + + // UTF-16 => ISO-8859-1 public static function iconv_utf16_iso88591($string) { $bom = substr($string, 0, 2); @@ -384,8 +384,8 @@ class getid3_iconv_replacement return $string; } - - + + // UTF-16 => UTF-8 public static function iconv_utf16_utf8($string) { $bom = substr($string, 0, 2); @@ -396,16 +396,16 @@ class getid3_iconv_replacement } return $string; } - - - + + + // UTF-16 => UTF-16BE public static function iconv_utf16_utf16be($string) { return getid3_iconv_replacement::iconv_utf8_utf16be(getid3_iconv_replacement::iconv_utf16_utf8($string)); } - - - + + + // UTF-16 => UTF-16LE public static function iconv_utf16_utf16le($string) { return getid3_iconv_replacement::iconv_utf8_utf16le(getid3_iconv_replacement::iconv_utf16_utf8($string)); diff --git a/modules/getid3/module.lib.image_size.php b/modules/getid3/module.lib.image_size.php index 5d7e66f4..8a07e289 100644 --- a/modules/getid3/module.lib.image_size.php +++ b/modules/getid3/module.lib.image_size.php @@ -26,7 +26,7 @@ class getid3_lib_image_size { - + const GIF_SIG = "\x47\x49\x46"; // 'GIF' const PNG_SIG = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"; const JPG_SIG = "\xFF\xD8\xFF"; @@ -35,53 +35,53 @@ class getid3_lib_image_size const JPG_SOF1 = "\xC1"; // N indicates which compression process const JPG_SOF2 = "\xC2"; // Only SOF0-SOF2 are now in common use const JPG_SOF3 = "\xC3"; // NB: codes C4 and CC are *not* SOF markers - const JPG_SOF5 = "\xC5"; - const JPG_SOF6 = "\xC6"; - const JPG_SOF7 = "\xC7"; - const JPG_SOF9 = "\xC9"; - const JPG_SOF10 = "\xCA"; + const JPG_SOF5 = "\xC5"; + const JPG_SOF6 = "\xC6"; + const JPG_SOF7 = "\xC7"; + const JPG_SOF9 = "\xC9"; + const JPG_SOF10 = "\xCA"; const JPG_SOF11 = "\xCB"; // NB: codes C4 and CC are *not* SOF markers - const JPG_SOF13 = "\xCD"; - const JPG_SOF14 = "\xCE"; - const JPG_SOF15 = "\xCF"; + const JPG_SOF13 = "\xCD"; + const JPG_SOF14 = "\xCE"; + const JPG_SOF15 = "\xCF"; const JPG_EOI = "\xD9"; // End Of Image (end of datastream) static public function get($img_data) { $height = $width = $type = ''; - + if ((substr($img_data, 0, 3) == getid3_lib_image_size::GIF_SIG) && (strlen($img_data) > 10)) { - + $dim = unpack('v2dim', substr($img_data, 6, 4)); $width = $dim['dim1']; $height = $dim['dim2']; $type = 1; - + } elseif ((substr($img_data, 0, 8) == getid3_lib_image_size::PNG_SIG) && (strlen($img_data) > 24)) { - + $dim = unpack('N2dim', substr($img_data, 16, 8)); $width = $dim['dim1']; $height = $dim['dim2']; $type = 3; - + } elseif ((substr($img_data, 0, 3) == getid3_lib_image_size::JPG_SIG) && (strlen($img_data) > 4)) { - + ///////////////// JPG CHUNK SCAN //////////////////// $img_pos = $type = 2; $buffer = strlen($img_data) - 2; while ($img_pos < strlen($img_data)) { - + // synchronize to the marker 0xFF $img_pos = strpos($img_data, 0xFF, $img_pos) + 1; $marker = $img_data[$img_pos]; do { $marker = ord($img_data[$img_pos++]); } while ($marker == 255); - + // find dimensions of block switch (chr($marker)) { - + // Grab width/height from SOF segment (these are acceptable chunk types) case getid3_lib_image_size::JPG_SOF0: case getid3_lib_image_size::JPG_SOF1: @@ -100,23 +100,23 @@ class getid3_lib_image_size $height = $dim['dim1']; $width = $dim['dim2']; break 2; // found it so exit - + case getid3_lib_image_size::JPG_EOI: case getid3_lib_image_size::JPG_SOS: - return false; - + return false; + default: // We're not interested in other markers $skiplen = (ord($img_data[$img_pos++]) << 8) + ord($img_data[$img_pos++]) - 2; // if the skip is more than what we've read in, read more $buffer -= $skiplen; if ($buffer < 512) { // if the buffer of data is too low, read more file. - return false; + return false; } $img_pos += $skiplen; break; - } - } - } + } + } + } return array ($width, $height, $type); } // end function diff --git a/modules/getid3/module.misc.iso.php b/modules/getid3/module.misc.iso.php index 60478f09..83771ddf 100644 --- a/modules/getid3/module.misc.iso.php +++ b/modules/getid3/module.misc.iso.php @@ -28,9 +28,9 @@ class getid3_iso extends getid3_handler { public function Analyze() { - + $getid3 = $this->getid3; - + $getid3->info['fileformat'] = 'iso'; for ($i = 16; $i <= 19; $i++) { @@ -68,9 +68,9 @@ class getid3_iso extends getid3_handler private function ParsePrimaryVolumeDescriptor(&$iso_header) { - + $getid3 = $this->getid3; - + // ISO integer values are stored *BOTH* Little-Endian AND Big-Endian format!! // ie 12345 == 0x3039 is stored as $39 $30 $30 $39 in a 4-byte field @@ -83,8 +83,8 @@ class getid3_iso extends getid3_handler if ($info_iso_primaryVD_raw['standard_identifier'] != 'CD001') { throw new getid3_exception('Expected "CD001" at offset ('.($info_iso_primaryVD['offset'] + 1).'), found "'.$info_iso_primaryVD_raw['standard_identifier'].'" instead'); } - - getid3_lib::ReadSequence('LittleEndian2Int', $info_iso_primaryVD_raw, $iso_header, 6, + + getid3_lib::ReadSequence('LittleEndian2Int', $info_iso_primaryVD_raw, $iso_header, 6, array ( 'volume_descriptor_version' => 1, 'IGNORE-unused_1' => 1, @@ -137,7 +137,7 @@ class getid3_iso extends getid3_handler $info_iso_primaryVD['copyright_file_identifier'] = trim($info_iso_primaryVD_raw['copyright_file_identifier']); $info_iso_primaryVD['abstract_file_identifier'] = trim($info_iso_primaryVD_raw['abstract_file_identifier']); $info_iso_primaryVD['bibliographic_file_identifier'] = trim($info_iso_primaryVD_raw['bibliographic_file_identifier']); - + $info_iso_primaryVD['volume_creation_date_time'] = getid3_iso::ISOtimeText2UNIXtime($info_iso_primaryVD_raw['volume_creation_date_time']); $info_iso_primaryVD['volume_modification_date_time'] = getid3_iso::ISOtimeText2UNIXtime($info_iso_primaryVD_raw['volume_modification_date_time']); $info_iso_primaryVD['volume_expiration_date_time'] = getid3_iso::ISOtimeText2UNIXtime($info_iso_primaryVD_raw['volume_expiration_date_time']); @@ -153,9 +153,9 @@ class getid3_iso extends getid3_handler private function ParseSupplementaryVolumeDescriptor(&$iso_header) { - + $getid3 = $this->getid3; - + // ISO integer values are stored Both-Endian format!! // ie 12345 == 0x3039 is stored as $39 $30 $30 $39 in a 4-byte field @@ -169,7 +169,7 @@ class getid3_iso extends getid3_handler throw new getid3_exception('Expected "CD001" at offset ('.($info_iso_supplementaryVD['offset'] + 1).'), found "'.$info_iso_supplementaryVD_raw['standard_identifier'].'" instead'); } - getid3_lib::ReadSequence('LittleEndian2Int', $info_iso_supplementaryVD_raw, $iso_header, 6, + getid3_lib::ReadSequence('LittleEndian2Int', $info_iso_supplementaryVD_raw, $iso_header, 6, array ( 'volume_descriptor_version' => 1, 'IGNORE-unused_1' => -1, @@ -222,7 +222,7 @@ class getid3_iso extends getid3_handler $info_iso_supplementaryVD['copyright_file_identifier'] = trim($info_iso_supplementaryVD_raw['copyright_file_identifier']); $info_iso_supplementaryVD['abstract_file_identifier'] = trim($info_iso_supplementaryVD_raw['abstract_file_identifier']); $info_iso_supplementaryVD['bibliographic_file_identifier'] = trim($info_iso_supplementaryVD_raw['bibliographic_file_identifier']); - + $info_iso_supplementaryVD['volume_creation_date_time'] = getid3_iso::ISOtimeText2UNIXtime($info_iso_supplementaryVD_raw['volume_creation_date_time']); $info_iso_supplementaryVD['volume_modification_date_time'] = getid3_iso::ISOtimeText2UNIXtime($info_iso_supplementaryVD_raw['volume_modification_date_time']); $info_iso_supplementaryVD['volume_expiration_date_time'] = getid3_iso::ISOtimeText2UNIXtime($info_iso_supplementaryVD_raw['volume_expiration_date_time']); @@ -238,9 +238,9 @@ class getid3_iso extends getid3_handler private function ParsePathTable() { - + $getid3 = $this->getid3; - + if (!isset($getid3->info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location']) && !isset($getid3->info['iso']['primary_volume_descriptor']['raw']['path_table_l_location'])) { return false; } @@ -248,7 +248,7 @@ class getid3_iso extends getid3_handler $path_table_location = $getid3->info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location']; $path_table_size = $getid3->info['iso']['supplementary_volume_descriptor']['raw']['path_table_size']; $text_encoding = 'UTF-16BE'; // Big-Endian Unicode - } + } else { $path_table_location = $getid3->info['iso']['primary_volume_descriptor']['raw']['path_table_l_location']; $path_table_size = $getid3->info['iso']['primary_volume_descriptor']['raw']['path_table_size']; @@ -266,11 +266,11 @@ class getid3_iso extends getid3_handler $offset = 0; $pathcounter = 1; while ($offset < $path_table_size) { - + $getid3->info['iso']['path_table']['directories'][$pathcounter] = array (); $info_iso_pathtable_directories_current = &$getid3->info['iso']['path_table']['directories'][$pathcounter]; - getid3_lib::ReadSequence('LittleEndian2Int', $info_iso_pathtable_directories_current, $getid3->info['iso']['path_table']['raw'], $offset, + getid3_lib::ReadSequence('LittleEndian2Int', $info_iso_pathtable_directories_current, $getid3->info['iso']['path_table']['raw'], $offset, array ( 'length' => 1, 'extended_length' => 1, @@ -278,9 +278,9 @@ class getid3_iso extends getid3_handler 'parent_directory' => 2, ) ); - + $info_iso_pathtable_directories_current['name'] = substr($getid3->info['iso']['path_table']['raw'], $offset+8, $info_iso_pathtable_directories_current['length']); - + $offset += 8 + $info_iso_pathtable_directories_current['length'] + ($info_iso_pathtable_directories_current['length'] % 2); $info_iso_pathtable_directories_current['name_ascii'] = $getid3->iconv($text_encoding, $getid3->encoding, $info_iso_pathtable_directories_current['name'], true); @@ -303,23 +303,23 @@ class getid3_iso extends getid3_handler private function ParseDirectoryRecord($directory_data) { - + $getid3 = $this->getid3; - - $text_encoding = isset($getid3->info['iso']['supplementary_volume_descriptor']) ? 'UTF-16BE' : 'ISO-8859-1'; + + $text_encoding = isset($getid3->info['iso']['supplementary_volume_descriptor']) ? 'UTF-16BE' : 'ISO-8859-1'; fseek($getid3->fp, $directory_data['location_bytes'], SEEK_SET); $directory_record_data = fread($getid3->fp, 1); - + while (ord($directory_record_data{0}) > 33) { $directory_record_data .= fread($getid3->fp, ord($directory_record_data{0}) - 1); - + $this_directory_record = array (); $this_directory_record['raw'] = array (); $this_directory_record_raw = &$this_directory_record['raw']; - - getid3_lib::ReadSequence('LittleEndian2Int', $this_directory_record_raw, $directory_record_data, 0, + + getid3_lib::ReadSequence('LittleEndian2Int', $this_directory_record_raw, $directory_record_data, 0, array ( 'length' => 1, 'extended_attribute_length' => 1, @@ -338,7 +338,7 @@ class getid3_iso extends getid3_handler ); $this_directory_record_raw['file_identifier'] = substr($directory_record_data, 33, $this_directory_record_raw['file_identifier_length']); - + $this_directory_record['file_identifier_ascii'] = $getid3->iconv($text_encoding, $getid3->encoding, $this_directory_record_raw['file_identifier'], true); $this_directory_record['filesize'] = $this_directory_record_raw['filesize']; $this_directory_record['offset_bytes'] = $this_directory_record_raw['offset_logical'] * 2048; @@ -357,11 +357,11 @@ class getid3_iso extends getid3_handler $this_directory_record['filename'] = $directory_data['full_path'].getid3_iso::ISOstripFilenameVersion($this_directory_record['file_identifier_ascii']); $getid3->info['iso']['files'] = getid3_iso::array_merge_clobber($getid3->info['iso']['files'], getid3_iso::CreateDeepArray($this_directory_record['filename'], '/', $this_directory_record['filesize'])); } - + $directory_record[] = $this_directory_record; $directory_record_data = fread($getid3->fp, 1); } - + return $directory_record; } @@ -383,14 +383,14 @@ class getid3_iso extends getid3_handler if (!(int)substr($iso_time, 0, 4)) { return false; } - + return gmmktime((int)substr($iso_time, 8, 2), (int)substr($iso_time, 10, 2), (int)substr($iso_time, 12, 2), (int)substr($iso_time, 4, 2), (int)substr($iso_time, 6, 2), (int)substr($iso_time, 0, 4)); } - - + + public static function ISOtime2UNIXtime($iso_time) { - + // Represented by seven bytes: // 1: Number of years since 1900 // 2: Month of the year from 1 to 12 @@ -409,11 +409,11 @@ class getid3_iso extends getid3_handler // written by kcØhireability*com // taken from http://www.php.net/manual/en/function.array-merge-recursive.php - + if (!is_array($array1) || !is_array($array2)) { return false; } - + $newarray = $array1; foreach ($array2 as $key => $val) { if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { @@ -424,9 +424,9 @@ class getid3_iso extends getid3_handler } return $newarray; } - - - + + + public static function CreateDeepArray($array_path, $separator, $value) { // assigns $value to a nested array path: @@ -435,14 +435,14 @@ class getid3_iso extends getid3_handler // $foo = array ('path'=>array('to'=>'array('my'=>array('file.txt')))); // or // $foo['path']['to']['my'] = 'file.txt'; - + while ($array_path{0} == $separator) { $array_path = substr($array_path, 1); } if (($pos = strpos($array_path, $separator)) !== false) { return array (substr($array_path, 0, $pos) => getid3_iso::CreateDeepArray(substr($array_path, $pos + 1), $separator, $value)); } - + return array ($array_path => $value); } diff --git a/modules/getid3/module.tag.id3v1.php b/modules/getid3/module.tag.id3v1.php index 52f01405..15da6ce8 100644 --- a/modules/getid3/module.tag.id3v1.php +++ b/modules/getid3/module.tag.id3v1.php @@ -22,23 +22,23 @@ // // $Id: module.tag.id3v1.php,v 1.6 2006/11/16 16:19:52 ah Exp $ - - + + class getid3_id3v1 extends getid3_handler { public function Analyze() { $getid3 = $this->getid3; - + fseek($getid3->fp, -256, SEEK_END); $pre_id3v1 = fread($getid3->fp, 128); $id3v1_tag = fread($getid3->fp, 128); if (substr($id3v1_tag, 0, 3) == 'TAG') { - + $getid3->info['avdataend'] -= 128; - + // Shortcut $getid3->info['id3v1'] = array (); $info_id3v1 = &$getid3->info['id3v1']; @@ -71,8 +71,8 @@ class getid3_id3v1 extends getid3_handler $info_id3v1['tag_offset_end'] = filesize($getid3->filename); $info_id3v1['tag_offset_start'] = $info_id3v1['tag_offset_end'] - 128; - } - + } + if (substr($pre_id3v1, 0, 3) == 'TAG') { // The way iTunes handles tags is, well, brain-damaged. // It completely ignores v1 if ID3v2 is present. @@ -92,18 +92,18 @@ class getid3_id3v1 extends getid3_handler return true; } - - + + public static function cutfield($str) { - + return trim(substr($str, 0, strcspn($str, "\x00"))); } public static function ArrayOfGenres($allow_SCMPX_extended=false) { - + static $lookup = array ( 0 => 'Blues', 1 => 'Classic Rock', @@ -290,7 +290,7 @@ class getid3_id3v1 extends getid3_handler public static function LookupGenreName($genre_id, $allow_SCMPX_extended=true) { - + switch ($genre_id) { case 'RX': case 'CR': @@ -302,10 +302,10 @@ class getid3_id3v1 extends getid3_handler $lookup = getid3_id3v1::ArrayOfGenres($allow_SCMPX_extended); return (isset($lookup[$genre_id]) ? $lookup[$genre_id] : false); } - + public static function LookupGenreID($genre, $allow_SCMPX_extended=false) { - + $lookup = getid3_id3v1::ArrayOfGenres($allow_SCMPX_extended); $lower_case_no_space_search_term = strtolower(str_replace(' ', '', $genre)); foreach ($lookup as $key => $value) { diff --git a/modules/getid3/module.tag.lyrics3.php b/modules/getid3/module.tag.lyrics3.php index 4afe6d64..cb95e0ea 100644 --- a/modules/getid3/module.tag.lyrics3.php +++ b/modules/getid3/module.tag.lyrics3.php @@ -42,7 +42,7 @@ class getid3_lyrics3 extends getid3_handler $lyrics3_size = 5100; $lyrics3_offset = filesize($getid3->filename) - 128 - $lyrics3_size; $lyrics3_version = 1; - } + } // Lyrics3v2, ID3v1, no APE elseif ($lyrics3_end == 'LYRICS200') { @@ -51,8 +51,8 @@ class getid3_lyrics3 extends getid3_handler $lyrics3_size = $lyrics3_lsz + 6 + strlen('LYRICS200'); $lyrics3_offset = filesize($getid3->filename) - 128 - $lyrics3_size; $lyrics3_version = 2; - } - + } + // Lyrics3v1, no ID3v1, no APE elseif (substr(strrev($lyrics3_id3v1), 0, 9) == 'DNESCIRYL') { // strrev('LYRICSEND') = 'DNESCIRYL' @@ -60,23 +60,23 @@ class getid3_lyrics3 extends getid3_handler $lyrics3_offset = filesize($getid3->filename) - $lyrics3_size; $lyrics3_version = 1; $lyrics3_offset = filesize($getid3->filename) - $lyrics3_size; - } - + } + // Lyrics3v2, no ID3v1, no APE elseif (substr(strrev($lyrics3_id3v1), 0, 9) == '002SCIRYL') { // strrev('LYRICS200') = '002SCIRYL' $lyrics3_size = strrev(substr(strrev($lyrics3_id3v1), 9, 6)) + 15; // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200' // 15 = 6 + strlen('LYRICS200') $lyrics3_offset = filesize($getid3->filename) - $lyrics3_size; $lyrics3_version = 2; - } - + } + elseif (isset($getid3->info['ape']['tag_offset_start']) && ($getid3->info['ape']['tag_offset_start'] > 15)) { fseek($getid3->fp, $getid3->info['ape']['tag_offset_start'] - 15, SEEK_SET); $lyrics3_lsz = fread($getid3->fp, 6); $lyrics3_end = fread($getid3->fp, 9); - + // Lyrics3v1, APE, maybe ID3v1 if ($lyrics3_end == 'LYRICSEND') { @@ -85,9 +85,9 @@ class getid3_lyrics3 extends getid3_handler $getid3->info['avdataend'] = $lyrics3_offset; $lyrics3_version = 1; $getid3->warning('APE tag located after Lyrics3, will probably break Lyrics3 compatability'); - } - - + } + + // Lyrics3v2, APE, maybe ID3v1 elseif ($lyrics3_end == 'LYRICS200') { @@ -98,25 +98,25 @@ class getid3_lyrics3 extends getid3_handler } } - - + + //// GetLyrics3Data() - - + + if (isset($lyrics3_offset)) { - + $getid3->info['avdataend'] = $lyrics3_offset; - + if ($lyrics3_size <= 0) { return false; } fseek($getid3->fp, $lyrics3_offset, SEEK_SET); $raw_data = fread($getid3->fp, $lyrics3_size); - + if (substr($raw_data, 0, 11) != 'LYRICSBEGIN') { if (strpos($raw_data, 'LYRICSBEGIN') !== false) { - + $getid3->warning('"LYRICSBEGIN" expected at '.$lyrics3_offset.' but actually found at '.($lyrics3_offset + strpos($raw_data, 'LYRICSBEGIN')).' - this is invalid for Lyrics3 v'.$lyrics3_version); $getid3->info['avdataend'] = $lyrics3_offset + strpos($raw_data, 'LYRICSBEGIN'); $parsed_lyrics3['tag_offset_start'] = $getid3->info['avdataend']; @@ -126,16 +126,16 @@ class getid3_lyrics3 extends getid3_handler else { throw new getid3_exception('"LYRICSBEGIN" expected at '.$lyrics3_offset.' but found "'.substr($raw_data, 0, 11).'" instead.'); } - + } - + $parsed_lyrics3['raw']['lyrics3version'] = $lyrics3_version; $parsed_lyrics3['raw']['lyrics3tagsize'] = $lyrics3_size; $parsed_lyrics3['tag_offset_start'] = $lyrics3_offset; $parsed_lyrics3['tag_offset_end'] = $lyrics3_offset + $lyrics3_size; - + switch ($lyrics3_version) { - + case 1: if (substr($raw_data, strlen($raw_data) - 9, 9) == 'LYRICSEND') { $parsed_lyrics3['raw']['LYR'] = trim(substr($raw_data, 11, strlen($raw_data) - 11 - 9)); @@ -145,7 +145,7 @@ class getid3_lyrics3 extends getid3_handler throw new getid3_exception('"LYRICSEND" expected at '.(ftell($getid3->fp) - 11 + $lyrics3_size - 9).' but found "'.substr($raw_data, strlen($raw_data) - 9, 9).'" instead.'); } break; - + case 2: if (substr($raw_data, strlen($raw_data) - 9, 9) == 'LYRICS200') { $parsed_lyrics3['raw']['unparsed'] = substr($raw_data, 11, strlen($raw_data) - 11 - 9 - 6); // LYRICSBEGIN + LYRICS200 + LSZ @@ -156,7 +156,7 @@ class getid3_lyrics3 extends getid3_handler $parsed_lyrics3['raw'][$fieldname] = substr($raw_data, 8, $fieldsize); $raw_data = substr($raw_data, 3 + 5 + $fieldsize); } - + if (isset($parsed_lyrics3['raw']['IND'])) { $i = 0; foreach (array ('lyrics', 'timestamps', 'inhibitrandom') as $flagname) { @@ -165,13 +165,13 @@ class getid3_lyrics3 extends getid3_handler } } } - + foreach (array ('ETT'=>'title', 'EAR'=>'artist', 'EAL'=>'album', 'INF'=>'comment', 'AUT'=>'author') as $key => $value) { if (isset($parsed_lyrics3['raw'][$key])) { $parsed_lyrics3['comments'][$value][] = trim($parsed_lyrics3['raw'][$key]); } } - + if (isset($parsed_lyrics3['raw']['IMG'])) { foreach (explode("\r\n", $parsed_lyrics3['raw']['IMG']) as $key => $image_string) { if (strpos($image_string, '||') !== false) { @@ -182,7 +182,7 @@ class getid3_lyrics3 extends getid3_handler } } } - + if (isset($parsed_lyrics3['raw']['LYR'])) { getid3_lyrics3::Lyrics3LyricsTimestampParse($parsed_lyrics3); } @@ -191,19 +191,19 @@ class getid3_lyrics3 extends getid3_handler throw new getid3_exception('"LYRICS200" expected at '.(ftell($getid3->fp) - 11 + $lyrics3_size - 9).' but found "'.substr($raw_data, strlen($raw_data) - 9, 9).'" instead.'); } break; - + default: throw new getid3_exception('Cannot process Lyrics3 version '.$lyrics3_version.' (only v1 and v2)'); } - + if (isset($getid3->info['id3v1']['tag_offset_start']) && ($getid3->info['id3v1']['tag_offset_start'] < $parsed_lyrics3['tag_offset_end'])) { $getid3->warning('ID3v1 tag information ignored since it appears to be a false synch in Lyrics3 tag data'); unset($getid3->info['id3v1']); } - + $getid3->info['lyrics3'] = $parsed_lyrics3; - - + + // Check for APE tag after lyrics3 if (!@$getid3->info['ape'] && $getid3->option_tag_apetag && class_exists('getid3_apetag')) { $apetag = new getid3_apetag($getid3); @@ -214,10 +214,10 @@ class getid3_lyrics3 extends getid3_handler return true; } - - - + + + public static function Lyrics3Timestamp2Seconds($rawtimestamp) { if (preg_match('/^\\[([0-9]{2}):([0-9]{2})\\]$/', $rawtimestamp, $regs)) { return (int)(($regs[1] * 60) + $regs[2]); @@ -225,13 +225,13 @@ class getid3_lyrics3 extends getid3_handler return false; } - - + + public static function Lyrics3LyricsTimestampParse(&$lyrics3_data) { $lyrics_array = explode("\r\n", $lyrics3_data['raw']['LYR']); foreach ($lyrics_array as $key => $lyric_line) { - + while (preg_match('/^(\\[[0-9]{2}:[0-9]{2}\\])/', $lyric_line, $regs)) { $this_line_timestamps[] = getid3_lyrics3::Lyrics3Timestamp2Seconds($regs[0]); $lyric_line = str_replace($regs[0], '', $lyric_line); @@ -262,7 +262,7 @@ class getid3_lyrics3 extends getid3_handler public static function IntString2Bool($char) { - + return $char == '1' ? true : ($char == '0' ? false : null); } } diff --git a/modules/getid3/write.apetag.php b/modules/getid3/write.apetag.php index e154e814..32ba33b2 100644 --- a/modules/getid3/write.apetag.php +++ b/modules/getid3/write.apetag.php @@ -27,73 +27,73 @@ class getid3_write_apetag extends getid3_handler_write { - + public $comments; - + public function read() { - + $engine = new getid3; $engine->filename = $this->filename; $engine->fp = fopen($this->filename, 'rb'); $engine->include_module('tag.apetag'); - + $tag = new getid3_apetag($engine); $tag->Analyze(); if (!isset($engine->info['ape']['comments'])) { return; } - + $this->comments = $engine->info['ape']['comments']; - + // convert single element arrays to string foreach ($this->comments as $key => $value) { if (sizeof($value) == 1) { $this->comments[$key] = $value[0]; } } - + return true; } public function write() { - + // remove existing apetag $this->remove(); - + $engine = new getid3; $engine->filename = $this->filename; $engine->fp = fopen($this->filename, 'rb'); $engine->include_module('tag.id3v1'); $engine->include_module('tag.lyrics3'); - + $tag = new getid3_id3v1($engine); $tag->Analyze(); - + $tag = new getid3_lyrics3($engine); $tag->Analyze(); $apetag = $this->generate_tag(); - + if (!$fp = @fopen($this->filename, 'a+b')) { throw new getid3_exception('Could not open a+b: ' . $this->filename); } // init: audio ends at eof $post_audio_offset = filesize($this->filename); - + // lyrics3 tag present if (@$engine->info['lyrics3']['tag_offset_start']) { - + // audio ends before lyrics3 tag $post_audio_offset = @$engine->info['lyrics3']['tag_offset_start']; } // id3v1 tag present elseif (@$engine->info['id3v1']['tag_offset_start']) { - + // audio ends before id3v1 tag $post_audio_offset = $engine->info['id3v1']['tag_offset_start']; } @@ -110,24 +110,24 @@ class getid3_write_apetag extends getid3_handler_write // truncate file before start of new apetag fseek($fp, $post_audio_offset, SEEK_SET); ftruncate($fp, ftell($fp)); - + // write new apetag fwrite($fp, $apetag, strlen($apetag)); - - // rewrite data after audio + + // rewrite data after audio if (!empty($post_audio_data)) { fwrite($fp, $post_audio_data, strlen($post_audio_data)); } - + fclose($fp); clearstatcache(); - + return true; } public function remove() { - + $engine = new getid3; $engine->filename = $this->filename; $engine->fp = fopen($this->filename, 'rb'); @@ -137,7 +137,7 @@ class getid3_write_apetag extends getid3_handler_write $tag->Analyze(); if (isset($engine->info['ape']['tag_offset_start']) && isset($engine->info['ape']['tag_offset_end'])) { - + if (!$fp = @fopen($this->filename, 'a+b')) { throw new getid3_exception('Could not open a+b: ' . $this->filename); } @@ -148,7 +148,7 @@ class getid3_write_apetag extends getid3_handler_write $data_after_ape = fread($fp, filesize($this->filename) - $engine->info['ape']['tag_offset_end']); } - // truncate file before start of apetag + // truncate file before start of apetag ftruncate($fp, $engine->info['ape']['tag_offset_start']); // rewrite data after apetag @@ -156,36 +156,36 @@ class getid3_write_apetag extends getid3_handler_write fseek($fp, $engine->info['ape']['tag_offset_start'], SEEK_SET); fwrite($fp, $data_after_ape, strlen($data_after_ape)); } - + fclose($fp); clearstatcache(); } - - // success when removing non-existant tag + + // success when removing non-existant tag return true; } protected function generate_tag() { - + // NOTE: All data passed to this function must be UTF-8 format $items = array(); if (!is_array($this->comments)) { throw new getid3_exception('Cannot write empty tag, use remove() instead.'); } - + foreach ($this->comments as $key => $values) { - + // http://www.personal.uni-jena.de/~pfk/mpp/sv8/apekey.html - // A case-insensitive vobiscomment field name that may consist of ASCII 0x20 through 0x7E. + // A case-insensitive vobiscomment field name that may consist of ASCII 0x20 through 0x7E. // ASCII 0x41 through 0x5A inclusive (A-Z) is to be considered equivalent to ASCII 0x61 through 0x7A inclusive (a-z). if (preg_match("/[^\x20-\x7E]/", $key)) { throw new getid3_exception('Field name "' . $key . '" contains invalid character(s).'); } - + $key = strtolower($key); - + // convert single value comment to array if (!is_array($values)) { $values = array ($values); @@ -199,7 +199,7 @@ class getid3_write_apetag extends getid3_handler_write // length of the assigned value in bytes $tag_item = getid3_lib::LittleEndian2String(strlen($value_string), 4); - + $tag_item .= "\x00\x00\x00\x00" . $key . "\x00" . $value_string; $items[] = $tag_item; @@ -207,10 +207,10 @@ class getid3_write_apetag extends getid3_handler_write return $this->generate_header_footer($items, true) . implode('', $items) . $this->generate_header_footer($items, false); } - + protected function generate_header_footer(&$items, $is_header=false) { - + $comments_length = 0; foreach ($items as $item_data) { $comments_length += strlen($item_data); @@ -225,25 +225,25 @@ class getid3_write_apetag extends getid3_handler_write return $header; } - + protected function generate_flags($header=true, $footer=true, $is_header=false, $encoding_id=0, $read_only=false) { - + $flags = array_fill(0, 4, 0); - + // Tag contains a header if ($header) { - $flags[0] |= 0x80; + $flags[0] |= 0x80; } - + // Tag contains no footer if (!$footer) { - $flags[0] |= 0x40; + $flags[0] |= 0x40; } - + // This is the header, not the footer if ($is_header) { - $flags[0] |= 0x20; + $flags[0] |= 0x20; } // 0: Item contains text information coded in UTF-8 @@ -254,12 +254,12 @@ class getid3_write_apetag extends getid3_handler_write // Tag or Item is Read Only if ($read_only) { - $flags[3] |= 0x01; + $flags[3] |= 0x01; } return chr($flags[3]).chr($flags[2]).chr($flags[1]).chr($flags[0]); } - + } ?>
\ No newline at end of file diff --git a/modules/getid3/write.id3v1.php b/modules/getid3/write.id3v1.php index c6bd48c3..52bc1921 100644 --- a/modules/getid3/write.id3v1.php +++ b/modules/getid3/write.id3v1.php @@ -37,19 +37,19 @@ class getid3_write_id3v1 extends getid3_handler_write public function read() { - + $engine = new getid3; $engine->filename = $this->filename; $engine->fp = fopen($this->filename, 'rb'); $engine->include_module('tag.id3v1'); - + $tag = new getid3_id3v1($engine); $tag->Analyze(); - + if (!isset($engine->info['id3v1'])) { return; } - + $this->title = $engine->info['id3v1']['title']; $this->artist = $engine->info['id3v1']['artist']; $this->album = $engine->info['id3v1']['album']; @@ -58,69 +58,69 @@ class getid3_write_id3v1 extends getid3_handler_write $this->genre = $engine->info['id3v1']['genre']; $this->comment = $engine->info['id3v1']['comment']; $this->track = $engine->info['id3v1']['track']; - + return true; } - - + + public function write() { - + if (!$fp = @fopen($this->filename, 'r+b')) { throw new getid3_exception('Could not open r+b: ' . $this->filename); } - + // seek to end minus 128 bytes fseek($fp, -128, SEEK_END); - + // overwrite existing ID3v1 tag if (fread($fp, 3) == 'TAG') { - fseek($fp, -128, SEEK_END); - } - + fseek($fp, -128, SEEK_END); + } + // append new ID3v1 tag else { - fseek($fp, 0, SEEK_END); + fseek($fp, 0, SEEK_END); } fwrite($fp, $this->generate_tag(), 128); - + fclose($fp); clearstatcache(); - + return true; } protected function generate_tag() { - + $result = 'TAG'; $result .= str_pad(trim(substr($this->title, 0, 30)), 30, "\x00", STR_PAD_RIGHT); $result .= str_pad(trim(substr($this->artist, 0, 30)), 30, "\x00", STR_PAD_RIGHT); $result .= str_pad(trim(substr($this->album, 0, 30)), 30, "\x00", STR_PAD_RIGHT); $result .= str_pad(trim(substr($this->year, 0, 4)), 4, "\x00", STR_PAD_LEFT); - + if (!empty($this->track) && ($this->track > 0) && ($this->track <= 255)) { - + $result .= str_pad(trim(substr($this->comment, 0, 28)), 28, "\x00", STR_PAD_RIGHT); $result .= "\x00"; $result .= chr($this->track); - } + } else { $result .= str_pad(trim(substr($comment, 0, 30)), 30, "\x00", STR_PAD_RIGHT); } - + // both genre and genre_id set if ($this->genre && $this->genre_id) { if ($this->genre != getid3_id3v1::LookupGenreName($this->genre_id)) { throw new getid3_exception('Genre and genre_id does not match. Unset one and the other will be determined automatically.'); } } - + // only genre set elseif ($this->genre) { $this->genre_id = getid3_id3v1::LookupGenreID($this->genre); } - + // only genre_id set else { if ($this->genre_id < 0 || $this->genre_id > 147) { @@ -128,27 +128,27 @@ class getid3_write_id3v1 extends getid3_handler_write } $this->genre = getid3_id3v1::LookupGenreName($this->genre_id); } - + $result .= chr(intval($this->genre_id)); return $result; - } - - + } + + public function remove() { - + if (!$fp = @fopen($this->filename, 'r+b')) { throw new getid3_exception('Could not open r+b: ' . $filename); } - + fseek($fp, -128, SEEK_END); if (fread($fp, 3) == 'TAG') { ftruncate($fp, filesize($this->filename) - 128); fclose($fp); clearstatcache(); } - - // success when removing non-existant tag + + // success when removing non-existant tag return true; } diff --git a/modules/getid3/write.id3v2.php b/modules/getid3/write.id3v2.php index d3b6c3ca..d09c3548 100644 --- a/modules/getid3/write.id3v2.php +++ b/modules/getid3/write.id3v2.php @@ -26,13 +26,13 @@ class getid3_write_id3v2 extends getid3_handler_write { - // NOTE: This module ONLY writes tags in UTF-8. All strings must be UTF-8 encoded. - + // NOTE: This module ONLY writes tags in UTF-8. All strings must be UTF-8 encoded. + // For multiple values, specify "array of type" instead of type for all T??? and IPLS params except TXXX. /**2.4 // For multiple values, specify "array of type" instead of type for all T??? params except TXXX. */ - + // Identification frames public $content_group_description; // TIT1 string @@ -142,7 +142,7 @@ class getid3_write_id3v2 extends getid3_handler_write public $play_counter; // PCNT // Popularimeter - public $popularimeter; // POPM + public $popularimeter; // POPM // Recommended buffer size public $recommended_buffer_size; // RBUF @@ -291,7 +291,7 @@ class getid3_write_id3v2 extends getid3_handler_write public $play_counter; // PCNT // Popularimeter - public $popularimeter; // POPM + public $popularimeter; // POPM // Recommended buffer size public $recommended_buffer_size; // RBUF @@ -332,14 +332,14 @@ class getid3_write_id3v2 extends getid3_handler_write // Audio seek point index public $audio_seek_point_index; // ASPI */ - - + + // internal logic protected $padded_length = 4096; // minimum length of ID3v2 tag in bytes protected $previous_frames = array (); const major_version = 3; - + public function read() { @@ -450,25 +450,25 @@ class getid3_write_id3v2 extends getid3_handler_write protected function generate_tag() { $result = ''; - + $some_array = array ( 'content_group_description' => 'TIT1', 'title' => 'TIT2', 'subtitle' => 'TIT3', ); - + foreach ($some_array as $key => $frame_name) { - - + + if ($frame_data = $this->generate_frame_data($frame_name, $this->$key)) { - + $frame_length = $this->BigEndian2String(strlen($frame_data), 4, false); $frame_flags = $this->generate_frame_flags(); } - + $result .= $frame_name.$frame_length.$frame_flags.$frame_data; } - + // calc padded length of tag while ($this->padded_length < (strlen($result) + 10)) { @@ -479,7 +479,7 @@ class getid3_write_id3v2 extends getid3_handler_write if ($this->padded_length > (strlen($result) + 10)) { $result .= @str_repeat("\x00", $this->padded_length - strlen($result) - 10); } - + $header = 'ID3'; $header .= chr(getid3_id3v2_write::major_version); $header .= chr(0); @@ -504,7 +504,7 @@ class getid3_write_id3v2 extends getid3_handler_write $flag .= (@$flags['extendedheader'] ? '1' : '0'); // b - Extended header $flag .= (@$flags['experimental'] ? '1' : '0'); // c - Experimental indicator $flag .= (@$flags['footer'] ? '1' : '0'); // d - Footer present - $flag .= '0000'; + $flag .= '0000'; */ return chr(bindec($flag)); @@ -512,29 +512,29 @@ class getid3_write_id3v2 extends getid3_handler_write protected function generate_frame_flags($flags) { - + // %abc00000 %ijk00000 $flag1 = (@$flags['tag_alter'] ? '1' : '0'); // a - Tag alter preservation (true == discard) $flag1 .= (@$flags['file_alter'] ? '1' : '0'); // b - File alter preservation (true == discard) $flag1 .= (@$flags['read_only'] ? '1' : '0'); // c - Read only (true == read only) - $flag1 .= '00000'; - + $flag1 .= '00000'; + $flag2 = (@$flags['compression'] ? '1' : '0'); // i - Compression (true == compressed) $flag2 .= (@$flags['encryption'] ? '1' : '0'); // j - Encryption (true == encrypted) $flag2 .= (@$flags['grouping_identity'] ? '1' : '0'); // k - Grouping identity (true == contains group information) - $flag2 .= '00000'; - - /**2.4 - // %0abc0000 %0h00kmnp - $flag1 = '0'; + $flag2 .= '00000'; + + /**2.4 + // %0abc0000 %0h00kmnp + $flag1 = '0'; $flag1 = (@$flags['tag_alter'] ? '1' : '0'); // a - Tag alter preservation (true == discard) $flag1 .= (@$flags['file_alter'] ? '1' : '0'); // b - File alter preservation (true == discard) $flag1 .= (@$flags['read_only'] ? '1' : '0'); // c - Read only (true == read only) - $flag1 .= '0000'; - - $flag2 = '0'; + $flag1 .= '0000'; + + $flag2 = '0'; $flag2 .= (@$flags['grouping_identity'] ? '1' : '0'); // h - Grouping identity (true == contains group information) - $flag2 .= '00'; + $flag2 .= '00'; $flag2 = (@$flags['compression'] ? '1' : '0'); // k - Compression (true == compressed) $flag2 .= (@$flags['encryption'] ? '1' : '0'); // m - Encryption (true == encrypted) $flag2 .= (@$flags['unsynchronisation'] ? '1' : '0'); // n - Unsynchronisation (true == unsynchronised) @@ -1857,22 +1857,22 @@ class getid3_write_id3v2 extends getid3_handler_write public static function BigEndian2String($number, $min_bytes=1, $synch_safe=false, $signed=false) { - + if ($number < 0) { return false; } - + $maskbyte = (($synch_safe || $signed) ? 0x7F : 0xFF); - + $intstring = ''; - + if ($signed) { if ($min_bytes > 4) { die('INTERNAL ERROR: Cannot have signed integers larger than 32-bits in BigEndian2String()'); } $number = $number & (0x80 << (8 * ($min_bytes - 1))); } - + while ($number != 0) { $quotient = ($number / ($maskbyte + 1)); $intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)).$intstring; diff --git a/modules/getid3/write.lyrics3.php b/modules/getid3/write.lyrics3.php index eab0d8d6..4725a3c9 100644 --- a/modules/getid3/write.lyrics3.php +++ b/modules/getid3/write.lyrics3.php @@ -29,7 +29,7 @@ class getid3_write_lyrics3 extends getid3_handler_write { public $synched; public $random_inhibited; - + public $lyrics; public $comment; public $author; @@ -40,7 +40,7 @@ class getid3_write_lyrics3 extends getid3_handler_write public function read() { - + $engine = new getid3; $engine->filename = $this->filename; $engine->fp = fopen($this->filename, 'rb'); @@ -48,11 +48,11 @@ class getid3_write_lyrics3 extends getid3_handler_write $tag = new getid3_lyrics3($engine); $tag->Analyze(); - + if (!isset($engine->info['lyrics3']['tag_offset_start'])) { return; } - + $this->lyrics = @$engine->info['lyrics3']['raw']['LYR']; $this->comment = @$engine->info['lyrics3']['raw']['INF']; $this->author = @$engine->info['lyrics3']['raw']['AUT']; @@ -60,36 +60,36 @@ class getid3_write_lyrics3 extends getid3_handler_write $this->artist = @$engine->info['lyrics3']['raw']['EAR']; $this->album = @$engine->info['lyrics3']['raw']['EAL']; $this->images = @$engine->info['lyrics3']['raw']['IMG']; - + return true; } public function write() { - + // remove existing apetag $this->remove(); - + $engine = new getid3; $engine->filename = $this->filename; $engine->fp = fopen($this->filename, 'rb'); $engine->include_module('tag.id3v1'); - + $tag = new getid3_id3v1($engine); $tag->Analyze(); $apetag = $this->generate_tag(); - + if (!$fp = @fopen($this->filename, 'a+b')) { throw new getid3_exception('Could not open a+b: ' . $this->filename); } // init: audio ends at eof $post_audio_offset = filesize($this->filename); - + // id3v1 tag present if (@$engine->info['id3v1']['tag_offset_start']) { - + // audio ends before id3v1 tag $post_audio_offset = $engine->info['id3v1']['tag_offset_start']; } @@ -106,27 +106,27 @@ class getid3_write_lyrics3 extends getid3_handler_write // truncate file before start of new apetag fseek($fp, $post_audio_offset, SEEK_SET); ftruncate($fp, ftell($fp)); - + // write new apetag fwrite($fp, $apetag, strlen($apetag)); - - // rewrite data after audio + + // rewrite data after audio if (!empty($post_audio_data)) { fwrite($fp, $post_audio_data, strlen($post_audio_data)); } - + fclose($fp); clearstatcache(); - + return true; } - + protected function generate_tag() { - + // define fields static $fields = array ( - 'lyrics' => 'LYR', + 'lyrics' => 'LYR', 'comment' => 'INF', 'author' => 'AUT', 'title' => 'ETT', @@ -134,40 +134,40 @@ class getid3_write_lyrics3 extends getid3_handler_write 'album' => 'EAL', 'images' => 'IMG' ); - + // loop thru fields and add to frames $frames = ''; foreach ($fields as $field => $frame_name) { - + // field set? if ($this->$field) { $frames .= $frame_name . str_pad(strlen($this->$field), 5, '0', STR_PAD_LEFT) . $this->$field; } } - + if (!$frames) { throw new getid3_exception('Cannot write empty tag, use remove() instead.'); } - // header + // header $result = 'LYRICSBEGIN'; - + // indicator frame - $result .= 'IND00003' . ($this->lyrics ? '1' : '0') . ($this->synched ? '1' : '0') . ($this->random_inibited ? '1' : '0'); - + $result .= 'IND00003' . ($this->lyrics ? '1' : '0') . ($this->synched ? '1' : '0') . ($this->random_inibited ? '1' : '0'); + // other frames $result .= $frames; - + // footer $result .= str_pad(strlen($result), 6, '0', STR_PAD_LEFT); $result .= 'LYRICS200'; - + return $result; } - + public function remove() { - + $engine = new getid3; $engine->filename = $this->filename; $engine->fp = fopen($this->filename, 'rb'); @@ -175,9 +175,9 @@ class getid3_write_lyrics3 extends getid3_handler_write $tag = new getid3_lyrics3($engine); $tag->Analyze(); - + if (isset($engine->info['lyrics3']['tag_offset_start']) && isset($engine->info['lyrics3']['tag_offset_end'])) { - + if (!$fp = @fopen($this->filename, 'a+b')) { throw new getid3_exception('Could not open a+b: ' . $this->filename); } @@ -201,8 +201,8 @@ class getid3_write_lyrics3 extends getid3_handler_write fclose($fp); clearstatcache(); } - - // success when removing non-existant tag + + // success when removing non-existant tag return true; } } diff --git a/modules/getid3/write.vorbis.php b/modules/getid3/write.vorbis.php index 0e95636f..e1d4b19b 100644 --- a/modules/getid3/write.vorbis.php +++ b/modules/getid3/write.vorbis.php @@ -25,19 +25,19 @@ class getid3_write_vorbis extends getid3_handler_write { - + public $comments = array (); - - + + public function __construct($filename) { - + if (ini_get('safe_mode')) { throw new getid3_exception('PHP running in Safe Mode (backtick operator not available). Cannot call vorbiscomment binary.'); } - + static $initialized; if (!$initialized) { - + // check existance and version of vorbiscomment if (!preg_match('/^Vorbiscomment ([0-9]+\.[0-9]+\.[0-9]+)/', `vorbiscomment --version 2>&1`, $r)) { throw new getid3_exception('Fatal: vorbiscomment binary not available.'); @@ -51,20 +51,20 @@ class getid3_write_vorbis extends getid3_handler_write parent::__construct($filename); } - - + + public function read() { - + // read info with vorbiscomment if (!$info = trim(`vorbiscomment -l "$this->filename"`)) { return; } - + // process info foreach (explode("\n", $info) as $line) { - + $pos = strpos($line, '='); - + $key = strtolower(substr($line, 0, $pos)); $value = substr($line, $pos+1); @@ -77,13 +77,13 @@ class getid3_write_vorbis extends getid3_handler_write $this->comments[$key] = $value[0]; } } - + return true; } - - + + public function write() { - + // create temp file with new comments $temp_filename = tempnam('*', 'getID3'); if (!$fp = @fopen($temp_filename, 'wb')) { @@ -91,14 +91,14 @@ class getid3_write_vorbis extends getid3_handler_write } fwrite($fp, $this->generate_tag()); fclose($fp); - + // write comments $this->save_permissions(); if ($error = `vorbiscomment -w --raw -c "$temp_filename" "$this->filename" 2>&1`) { - throw new getid3_exception('Fatal: vorbiscomment returned error: ' . $error); + throw new getid3_exception('Fatal: vorbiscomment returned error: ' . $error); } $this->restore_permissions(); - + // success @unlink($temp_filename); return true; @@ -106,27 +106,27 @@ class getid3_write_vorbis extends getid3_handler_write protected function generate_tag() { - + if (!$this->comments) { throw new getid3_exception('Cannot write empty tag, use remove() instead.'); } $result = ''; - + foreach ($this->comments as $key => $values) { - - // A case-insensitive vobiscomment field name that may consist of ASCII 0x20 through 0x7D, 0x3D ('=') excluded. + + // A case-insensitive vobiscomment field name that may consist of ASCII 0x20 through 0x7D, 0x3D ('=') excluded. // ASCII 0x41 through 0x5A inclusive (A-Z) is to be considered equivalent to ASCII 0x61 through 0x7A inclusive (a-z). if (preg_match("/[^\x20-\x7D]|\x3D/", $key)) { throw new getid3_exception('Field name "' . $key . '" contains invalid character(s).'); } - + $key = strtolower($key); - + if (!is_array($values)) { $values = array ($values); } - + foreach ($values as $value) { if (strstr($value, "\n") || strstr($value, "\r")) { throw new getid3_exception('Multi-line comments not supported (value contains \n or \r)'); @@ -135,13 +135,13 @@ class getid3_write_vorbis extends getid3_handler_write } } - + return $result; - } - - + } + + public function remove() { - + // create temp file with new comments $temp_filename = tempnam('*', 'getID3'); if (!$fp = @fopen($temp_filename, 'wb')) { @@ -149,15 +149,15 @@ class getid3_write_vorbis extends getid3_handler_write } fwrite($fp, ''); fclose($fp); - + // write comments $this->save_permissions(); if ($error = `vorbiscomment -w --raw -c "$temp_filename" "$this->filename" 2>&1`) { - throw new getid3_exception('Fatal: vorbiscomment returned error: ' . $error); + throw new getid3_exception('Fatal: vorbiscomment returned error: ' . $error); } $this->restore_permissions(); - - // success when removing non-existant tag + + // success when removing non-existant tag @unlink($temp_filename); return true; } diff --git a/modules/infotools/Snoopy.class.php b/modules/infotools/Snoopy.class.php index 63198bbd..9c458797 100644 --- a/modules/infotools/Snoopy.class.php +++ b/modules/infotools/Snoopy.class.php @@ -33,7 +33,7 @@ http://snoopy.sourceforge.net/ class Snoopy { /**** Public variables ****/ - + /* user definable vars */ var $host = "www.php.net"; // host name we are connecting to @@ -42,7 +42,7 @@ class Snoopy var $proxy_port = ""; // proxy port to use var $proxy_user = ""; // proxy user to use var $proxy_pass = ""; // proxy password to use - + var $agent = "Snoopy v1.2.4"; // agent we masquerade as var $referer = ""; // referer info to pass var $cookies = array(); // array of cookies to pass @@ -60,15 +60,15 @@ class Snoopy var $passcookies = true; // pass set cookies back through redirects // NOTE: this currently does not respect // dates, domains or paths. - + var $user = ""; // user for http authentication var $pass = ""; // password for http authentication - + // http accept types var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; - + var $results = ""; // where the content is put - + var $error = ""; // error messages sent here var $response_code = ""; // response code returned from server var $headers = array(); // headers returned from server sent here @@ -94,11 +94,11 @@ class Snoopy // library functions built into php, // as these functions are not stable // as of this Snoopy release. - - /**** Private variables ****/ - + + /**** Private variables ****/ + var $_maxlinelen = 4096; // max line length (headers) - + var $_httpmethod = "GET"; // default http request method var $_httpversion = "HTTP/1.0"; // default http request version var $_submit_method = "POST"; // default submit method @@ -108,7 +108,7 @@ class Snoopy var $_redirectdepth = 0; // increments on an http redirect var $_frameurls = array(); // frame src urls var $_framedepth = 0; // increments on frame depth - + var $_isproxy = false; // set if using a proxy server var $_fp_timeout = 30; // timeout for socket connection @@ -123,7 +123,7 @@ class Snoopy function fetch($URI) { - + //preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS); $URI_PARTS = parse_url($URI); if (!empty($URI_PARTS["user"])) @@ -134,7 +134,7 @@ class Snoopy $URI_PARTS["query"] = ''; if (empty($URI_PARTS["path"])) $URI_PARTS["path"] = ''; - + switch(strtolower($URI_PARTS["scheme"])) { case "http": @@ -154,7 +154,7 @@ class Snoopy // no proxy, send only the path $this->_httprequest($path, $fp, $URI, $this->_httpmethod); } - + $this->_disconnect($fp); if($this->_redirectaddr) @@ -177,7 +177,7 @@ class Snoopy { $frameurls = $this->_frameurls; $this->_frameurls = array(); - + while(list(,$frameurl) = each($frameurls)) { if($this->_framedepth < $this->maxframes) @@ -188,13 +188,13 @@ class Snoopy else break; } - } + } } else { return false; } - return true; + return true; break; case "https": if(!$this->curl_path) @@ -248,15 +248,15 @@ class Snoopy else break; } - } - return true; + } + return true; break; default: // not a valid protocol $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; return false; break; - } + } return true; } @@ -274,9 +274,9 @@ class Snoopy function submit($URI, $formvars="", $formfiles="") { unset($postdata); - + $postdata = $this->_prepare_post_body($formvars, $formfiles); - + $URI_PARTS = parse_url($URI); if (!empty($URI_PARTS["user"])) $this->user = $URI_PARTS["user"]; @@ -306,17 +306,17 @@ class Snoopy // no proxy, send only the path $this->_httprequest($path, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata); } - + $this->_disconnect($fp); if($this->_redirectaddr) { /* url was redirected, check if we've hit the max depth */ if($this->maxredirs > $this->_redirectdepth) - { + { if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) - $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); - + $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); + // only follow redirect if it's on this site, or offsiteok is true if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) { @@ -335,9 +335,9 @@ class Snoopy { $frameurls = $this->_frameurls; $this->_frameurls = array(); - + while(list(,$frameurl) = each($frameurls)) - { + { if($this->_framedepth < $this->maxframes) { $this->fetch($frameurl); @@ -346,14 +346,14 @@ class Snoopy else break; } - } - + } + } else { return false; } - return true; + return true; break; case "https": if(!$this->curl_path) @@ -380,9 +380,9 @@ class Snoopy { /* url was redirected, check if we've hit the max depth */ if($this->maxredirs > $this->_redirectdepth) - { + { if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) - $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); + $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); // only follow redirect if it's on this site, or offsiteok is true if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) @@ -404,7 +404,7 @@ class Snoopy $this->_frameurls = array(); while(list(,$frameurl) = each($frameurls)) - { + { if($this->_framedepth < $this->maxframes) { $this->fetch($frameurl); @@ -413,16 +413,16 @@ class Snoopy else break; } - } - return true; + } + return true; break; - + default: // not a valid protocol $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; return false; break; - } + } return true; } @@ -436,7 +436,7 @@ class Snoopy function fetchlinks($URI) { if ($this->fetch($URI)) - { + { if($this->lastredirectaddr) $URI = $this->lastredirectaddr; if(is_array($this->results)) @@ -464,9 +464,9 @@ class Snoopy function fetchform($URI) { - + if ($this->fetch($URI)) - { + { if(is_array($this->results)) { @@ -475,14 +475,14 @@ class Snoopy } else $this->results = $this->_stripform($this->results); - + return true; } else return false; } - - + + /*======================================================================*\ Function: fetchtext Purpose: fetch the text from a web page, stripping the links @@ -493,7 +493,7 @@ class Snoopy function fetchtext($URI) { if($this->fetch($URI)) - { + { if(is_array($this->results)) { for($x=0;$x<count($this->results);$x++) @@ -517,7 +517,7 @@ class Snoopy function submitlinks($URI, $formvars="", $formfiles="") { if($this->submit($URI,$formvars, $formfiles)) - { + { if($this->lastredirectaddr) $URI = $this->lastredirectaddr; if(is_array($this->results)) @@ -551,7 +551,7 @@ class Snoopy function submittext($URI, $formvars = "", $formfiles = "") { if($this->submit($URI,$formvars, $formfiles)) - { + { if($this->lastredirectaddr) $URI = $this->lastredirectaddr; if(is_array($this->results)) @@ -575,7 +575,7 @@ class Snoopy return false; } - + /*======================================================================*\ Function: set_submit_multipart @@ -587,7 +587,7 @@ class Snoopy $this->_submit_type = "multipart/form-data"; } - + /*======================================================================*\ Function: set_submit_normal Purpose: Set the form submission content type to @@ -598,14 +598,14 @@ class Snoopy $this->_submit_type = "application/x-www-form-urlencoded"; } - - + + /*======================================================================*\ Private functions \*======================================================================*/ - - + + /*======================================================================*\ Function: _striplinks Purpose: strip the hyperlinks from an html document @@ -614,13 +614,13 @@ class Snoopy \*======================================================================*/ function _striplinks($document) - { + { preg_match_all("'<\s*a\s.*?href\s*=\s* # find <a href= ([\"\'])? # find single or double quote (?(1) (.*?)\\1 | ([^\s\>]+)) # if quote found, match up to next matching # quote, otherwise match up to next space 'isx",$document,$links); - + // catenate the non-empty matches from the conditional subpattern @@ -628,14 +628,14 @@ class Snoopy { if(!empty($val)) $match[] = $val; - } - + } + while(list($key,$val) = each($links[3])) { if(!empty($val)) $match[] = $val; - } - + } + // return the links return $match; } @@ -648,18 +648,18 @@ class Snoopy \*======================================================================*/ function _stripform($document) - { + { preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements); - + // catenate the matches $match = implode("\r\n",$elements[0]); - + // return the links return $match; } - - + + /*======================================================================*\ Function: _striptext Purpose: strip the text from an html document @@ -669,11 +669,11 @@ class Snoopy function _striptext($document) { - + // I didn't use preg eval (//e) since that is only available in PHP 4.0. // so, list your entities one by one here. I included some of the // more common ones. - + $search = array("'<script[^>]*?>.*?</script>'si", // strip out javascript "'<[\/\!]*?[^<>]*?>'si", // strip out html tags "'([\r\n])[\s]+'", // strip out white space @@ -722,9 +722,9 @@ class Snoopy "Ü", "ß", ); - + $text = preg_replace($search,$replace,$document); - + return $text; } @@ -738,7 +738,7 @@ class Snoopy function _expandlinks($links,$URI) { - + preg_match("/^[^\?]+/",$URI,$match); $match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]); @@ -746,21 +746,21 @@ class Snoopy $match_part = parse_url($match); $match_root = $match_part["scheme"]."://".$match_part["host"]; - + $search = array( "|^http://".preg_quote($this->host)."|i", "|^(\/)|i", "|^(?!http://)(?!mailto:)|i", "|/\./|", "|/[^\/]+/\.\./|" ); - + $replace = array( "", $match_root."/", $match."/", "/", "/" - ); - + ); + $expandedLinks = preg_replace($search,$replace,$links); return $expandedLinks; @@ -773,19 +773,19 @@ class Snoopy $fp the current open file pointer $URI the full URI $body body contents to send if any (POST) - Output: + Output: \*======================================================================*/ - + function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") { $cookie_headers = ''; if($this->passcookies && $this->_redirectaddr) $this->setcookies(); - + $URI_PARTS = parse_url($URI); if(empty($url)) $url = "/"; - $headers = $http_method." ".$url." ".$this->_httpversion."\r\n"; + $headers = $http_method." ".$url." ".$this->_httpversion."\r\n"; if(!empty($this->agent)) $headers .= "User-Agent: ".$this->agent."\r\n"; if(!empty($this->host) && !isset($this->rawheaders['Host'])) { @@ -799,10 +799,10 @@ class Snoopy if(!empty($this->referer)) $headers .= "Referer: ".$this->referer."\r\n"; if(!empty($this->cookies)) - { + { if(!is_array($this->cookies)) $this->cookies = (array)$this->cookies; - + reset($this->cookies); if ( count($this->cookies) > 0 ) { $cookie_headers .= 'Cookie: '; @@ -810,7 +810,7 @@ class Snoopy $cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; "; } $headers .= substr($cookie_headers,0,-2) . "\r\n"; - } + } } if(!empty($this->rawheaders)) { @@ -825,28 +825,28 @@ class Snoopy $headers .= "; boundary=".$this->_mime_boundary; $headers .= "\r\n"; } - if(!empty($body)) + if(!empty($body)) $headers .= "Content-length: ".strlen($body)."\r\n"; - if(!empty($this->user) || !empty($this->pass)) + if(!empty($this->user) || !empty($this->pass)) $headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n"; - + //add proxy auth headers - if(!empty($this->proxy_user)) + if(!empty($this->proxy_user)) $headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n"; $headers .= "\r\n"; - + // set the read timeout if needed if ($this->read_timeout > 0) socket_set_timeout($fp, $this->read_timeout); $this->timed_out = false; - + fwrite($fp,$headers.$body,strlen($headers.$body)); - + $this->_redirectaddr = false; unset($this->headers); - + while($currentHeader = fgets($fp,$this->_maxlinelen)) { if ($this->read_timeout > 0 && $this->_check_timeout($fp)) @@ -854,10 +854,10 @@ class Snoopy $this->status=-100; return false; } - + if($currentHeader == "\r\n") break; - + // if a header begins with Location: or URI:, set the redirect if(preg_match("/^(Location:|URI:)/i",$currentHeader)) { @@ -877,16 +877,16 @@ class Snoopy else $this->_redirectaddr = $matches[2]; } - + if(preg_match("|^HTTP/|",$currentHeader)) { if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status)) { $this->status= $status[1]; - } + } $this->response_code = $currentHeader; } - + $this->headers[] = $currentHeader; } @@ -904,13 +904,13 @@ class Snoopy $this->status=-100; return false; } - + // check if there is a a redirect meta tag - + if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) { - $this->_redirectaddr = $this->_expandlinks($match[1],$URI); + $this->_redirectaddr = $this->_expandlinks($match[1],$URI); } // have we hit our frame depth and is there frame src to fetch? @@ -926,7 +926,7 @@ class Snoopy // no framed content else $this->results = $results; - + return true; } @@ -936,21 +936,21 @@ class Snoopy Input: $url the url to fetch $URI the full URI $body body contents to send if any (POST) - Output: + Output: \*======================================================================*/ - + function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") - { + { if($this->passcookies && $this->_redirectaddr) $this->setcookies(); - $headers = array(); - + $headers = array(); + $URI_PARTS = parse_url($URI); if(empty($url)) $url = "/"; // GET ... header not needed for curl - //$headers[] = $http_method." ".$url." ".$this->_httpversion; + //$headers[] = $http_method." ".$url." ".$this->_httpversion; if(!empty($this->agent)) $headers[] = "User-Agent: ".$this->agent; if(!empty($this->host)) @@ -963,10 +963,10 @@ class Snoopy if(!empty($this->referer)) $headers[] = "Referer: ".$this->referer; if(!empty($this->cookies)) - { + { if(!is_array($this->cookies)) $this->cookies = (array)$this->cookies; - + reset($this->cookies); if ( count($this->cookies) > 0 ) { $cookie_str = 'Cookie: '; @@ -989,43 +989,43 @@ class Snoopy else $headers[] = "Content-type: $content_type"; } - if(!empty($body)) + if(!empty($body)) $headers[] = "Content-length: ".strlen($body); - if(!empty($this->user) || !empty($this->pass)) + if(!empty($this->user) || !empty($this->pass)) $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); - + for($curr_header = 0; $curr_header < count($headers); $curr_header++) { $safer_header = strtr( $headers[$curr_header], "\"", " " ); $cmdline_params .= " -H \"".$safer_header."\""; } - + if(!empty($body)) $cmdline_params .= " -d \"$body\""; - + if($this->read_timeout > 0) $cmdline_params .= " -m ".$this->read_timeout; - + $headerfile = tempnam($temp_dir, "sno"); exec($this->curl_path." -k -D \"$headerfile\"".$cmdline_params." \"".escapeshellcmd($URI)."\"",$results,$return); - + if($return) { $this->error = "Error: cURL could not retrieve the document, error $return."; return false; } - - + + $results = implode("\r\n",$results); - + $result_headers = file("$headerfile"); - + $this->_redirectaddr = false; unset($this->headers); - + for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++) { - + // if a header begins with Location: or URI:, set the redirect if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader])) { @@ -1045,7 +1045,7 @@ class Snoopy else $this->_redirectaddr = $matches[2]; } - + if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) $this->response_code = $result_headers[$currentHeader]; @@ -1053,10 +1053,10 @@ class Snoopy } // check if there is a a redirect meta tag - + if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) { - $this->_redirectaddr = $this->_expandlinks($match[1],$URI); + $this->_redirectaddr = $this->_expandlinks($match[1],$URI); } // have we hit our frame depth and is there frame src to fetch? @@ -1074,7 +1074,7 @@ class Snoopy $this->results = $results; unlink("$headerfile"); - + return true; } @@ -1082,7 +1082,7 @@ class Snoopy Function: setcookies() Purpose: set cookies for a redirection \*======================================================================*/ - + function setcookies() { for($x=0; $x<count($this->headers); $x++) @@ -1092,7 +1092,7 @@ class Snoopy } } - + /*======================================================================*\ Function: _check_timeout Purpose: checks whether timeout has occurred @@ -1116,13 +1116,13 @@ class Snoopy Purpose: make a socket connection Input: $fp file pointer \*======================================================================*/ - + function _connect(&$fp) { if(!empty($this->proxy_host) && !empty($this->proxy_port)) { $this->_isproxy = true; - + $host = $this->proxy_host; $port = $this->proxy_port; } @@ -1131,9 +1131,9 @@ class Snoopy $host = $this->host; $port = $this->port; } - + $this->status = 0; - + if($fp = fsockopen( $host, $port, @@ -1169,13 +1169,13 @@ class Snoopy Purpose: disconnect a socket connection Input: $fp file pointer \*======================================================================*/ - + function _disconnect($fp) { return(fclose($fp)); } - + /*======================================================================*\ Function: _prepare_post_body Purpose: Prepare post body according to encoding type @@ -1183,7 +1183,7 @@ class Snoopy $formfiles - form upload files Output: post body \*======================================================================*/ - + function _prepare_post_body($formvars, $formfiles) { settype($formvars, "array"); @@ -1192,7 +1192,7 @@ class Snoopy if (count($formvars) == 0 && count($formfiles) == 0) return; - + switch ($this->_submit_type) { case "application/x-www-form-urlencoded": reset($formvars); @@ -1208,7 +1208,7 @@ class Snoopy case "multipart/form-data": $this->_mime_boundary = "Snoopy".md5(uniqid(microtime())); - + reset($formvars); while(list($key,$val) = each($formvars)) { if (is_array($val) || is_object($val)) { @@ -1223,7 +1223,7 @@ class Snoopy $postdata .= "$val\r\n"; } } - + reset($formfiles); while (list($field_name, $file_names) = each($formfiles)) { settype($file_names, "array"); diff --git a/modules/infotools/jamendoSearch.class.php b/modules/infotools/jamendoSearch.class.php index 57d3c948..d234ae85 100644 --- a/modules/infotools/jamendoSearch.class.php +++ b/modules/infotools/jamendoSearch.class.php @@ -21,11 +21,11 @@ */ /** - * jamendoSearch - * This class does XML lookups against the jamendo website + * jamendoSearch + * This class does XML lookups against the jamendo website * and returns information */ -class jamendoSearch { +class jamendoSearch { @@ -36,29 +36,29 @@ class jamendoSearch { * Constructor * This function inits the searcher */ - function jamendoSearch() { + function jamendoSearch() { /* Load the XMLRPC client */ - $this->_client = new XML_RPC_Client('/xmlrpc/','www.jamendo.com',80); + $this->_client = new XML_RPC_Client('/xmlrpc/','www.jamendo.com',80); } // jamendoSearch /** * query - * This runs a XMLRPC query and returns decoded data + * This runs a XMLRPC query and returns decoded data */ - function query($command,$options) { - + function query($command,$options) { + $encoded_command = new XML_RPC_Value($command); $encoded_options = new XML_RPC_Value($options,'struct'); - $message = new XML_RPC_Message('jamendo.get',array($encoded_command,$encoded_options)); - $response = $this->_client->send($message,15); - $value = $response->value(); + $message = new XML_RPC_Message('jamendo.get',array($encoded_command,$encoded_options)); + $response = $this->_client->send($message,15); + $value = $response->value(); - return XML_RPC_Decode($value); + return XML_RPC_Decode($value); } // query -} // jamendoSearch +} // jamendoSearch ?> diff --git a/modules/mpd/mpd.class.php b/modules/mpd/mpd.class.php index b0c9c76c..588f0604 100644 --- a/modules/mpd/mpd.class.php +++ b/modules/mpd/mpd.class.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ + */ // Create common command definitions for MPD to use define("MPD_CMD_STATUS", "status"); @@ -98,14 +98,14 @@ class mpd { var $db_last_refreshed; var $num_songs_played; var $playlist_count; - + var $num_artists; var $num_albums; var $num_songs; - + var $playlist = array(); - // Misc Other Vars + // Misc Other Vars var $mpd_class_version = "1.2"; var $errStr = ""; // Used for maintaining information about the last error message @@ -115,19 +115,19 @@ class mpd { // =================== BEGIN OBJECT METHODS ================ /* mpd() : Constructor - * + * * Builds the MPD object, connects to the server, and refreshes all local object properties. */ public function __construct($srv,$port,$pwd = NULL) { $this->host = $srv; $this->port = $port; $this->password = $pwd; - + $resp = $this->Connect(); if ( is_null($resp) ) { $this->errStr = "Could not connect"; return; - } + } list ( $this->mpd_version ) = sscanf($resp, OK . " MPD %s\n"); @@ -137,7 +137,7 @@ class mpd { $this->errStr = "Password supplied is incorrect or Invalid Command"; return; // bad password or command } - + if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected! $this->connected = FALSE; $this->errStr = "Password supplied does not have read access"; @@ -148,32 +148,32 @@ class mpd { if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected! $this->connected = FALSE; $this->errStr = "Password required to access server"; - return; + return; } } - return true; + return true; } // constructor /* Connect() - * - * Connects to the MPD server. - * + * + * Connects to the MPD server. + * * NOTE: This is called automatically upon object instantiation; you should not need to call this directly. */ public function Connect() { debug_event('MPD',"mpd->Connect() / host: ".$this->host.", port: ".$this->port,'5'); $this->mpd_sock = fsockopen($this->host,$this->port,$errNo,$errStr,6); - /* Vollmerize this bizatch, if we've got php4.3+ we should + /* Vollmerize this bizatch, if we've got php4.3+ we should * have these functions and we need them */ - if (function_exists('stream_set_timeout')) { - + if (function_exists('stream_set_timeout')) { + /* Set the timeout on the connection */ stream_set_timeout($this->mpd_sock,6); - + /* We want blocking, cause otherwise it doesn't - * timeout, and feof just keeps on spinning + * timeout, and feof just keeps on spinning */ stream_set_blocking($this->mpd_sock,TRUE); $status = socket_get_status($this->mpd_sock); @@ -181,14 +181,14 @@ class mpd { if (!$this->mpd_sock) { $this->errStr = "Socket Error: $errStr ($errNo)"; return NULL; - } + } else { while(!feof($this->mpd_sock) && !$status['timed_out']) { $response = fgets($this->mpd_sock,1024); - if (function_exists('socket_get_status')) { + if (function_exists('socket_get_status')) { $status = socket_get_status($this->mpd_sock); } - if (strstr($response,"OK")) { + if (strstr($response,"OK")) { $this->connected = TRUE; return $response; break; @@ -198,7 +198,7 @@ class mpd { return NULL; } - + } // end while // Generic response $this->errStr = "Connection not available"; @@ -208,9 +208,9 @@ class mpd { } // connect /* SendCommand() - * - * Sends a generic command to the MPD server. Several command constants are pre-defined for - * use (see MPD_CMD_* constant definitions above). + * + * Sends a generic command to the MPD server. Several command constants are pre-defined for + * use (see MPD_CMD_* constant definitions above). */ function SendCommand($cmdStr,$arg1 = "",$arg2 = "") { debug_event('MPD',"mpd->SendCommand() / cmd: ".$cmdStr.", args: ".$arg1." ".$arg2,'5'); @@ -255,11 +255,11 @@ class mpd { return $respStr; } - /* QueueCommand() + /* QueueCommand() * - * Queues a generic command for later sending to the MPD server. The CommandQueue can hold - * as many commands as needed, and are sent all at once, in the order they are queued, using - * the SendCommandQueue() method. The syntax for queueing commands is identical to SendCommand(). + * Queues a generic command for later sending to the MPD server. The CommandQueue can hold + * as many commands as needed, and are sent all at once, in the order they are queued, using + * the SendCommandQueue() method. The syntax for queueing commands is identical to SendCommand(). */ function QueueCommand($cmdStr,$arg1 = "",$arg2 = "") { if ( $this->debugging ) echo "mpd->QueueCommand() / cmd: ".$cmdStr.", args: ".$arg1." ".$arg2."\n"; @@ -280,7 +280,7 @@ class mpd { return TRUE; } - /* SendCommandQueue() + /* SendCommandQueue() * * Sends all commands in the Command Queue to the MPD server. See also QueueCommand(). */ @@ -301,10 +301,10 @@ class mpd { return $respStr; } - /* AdjustVolume() + /* AdjustVolume() * * Adjusts the mixer volume on the MPD by <modifier>, which can be a positive (volume increase), - * or negative (volume decrease) value. + * or negative (volume decrease) value. */ function AdjustVolume($modifier) { if ( $this->debugging ) echo "mpd->AdjustVolume()\n"; @@ -321,7 +321,7 @@ class mpd { return $ret; } - /* SetVolume() + /* SetVolume() * * Sets the mixer volume to <newVol>, which should be between 1 - 100. */ @@ -353,11 +353,11 @@ class mpd { return $ret; } - /* GetDir() - * + /* GetDir() + * * Retrieves a database directory listing of the <dir> directory and places the results into - * a multidimensional array. If no directory is specified, the directory listing is at the - * base of the MPD music path. + * a multidimensional array. If no directory is specified, the directory listing is at the + * base of the MPD music path. */ function GetDir($dir = "") { if ( $this->debugging ) echo "mpd->GetDir()\n"; @@ -367,10 +367,10 @@ class mpd { return $dirlist; } - /* PLAdd() - * - * Adds each track listed in a single-dimensional <trackArray>, which contains filenames - * of tracks to add, to the end of the playlist. This is used to add many, many tracks to + /* PLAdd() + * + * Adds each track listed in a single-dimensional <trackArray>, which contains filenames + * of tracks to add, to the end of the playlist. This is used to add many, many tracks to * the playlist in one swoop. */ function PLAddBulk($trackArray) { @@ -385,9 +385,9 @@ class mpd { return $resp; } - /* PLAdd() - * - * Adds the file <file> to the end of the playlist. <file> must be a track in the MPD database. + /* PLAdd() + * + * Adds the file <file> to the end of the playlist. <file> must be a track in the MPD database. */ function PLAdd($fileName) { if ( $this->debugging ) echo "mpd->PLAdd()\n"; @@ -396,9 +396,9 @@ class mpd { return $resp; } - /* PLMoveTrack() - * - * Moves track number <origPos> to position <newPos> in the playlist. This is used to reorder + /* PLMoveTrack() + * + * Moves track number <origPos> to position <newPos> in the playlist. This is used to reorder * the songs in the playlist. */ function PLMoveTrack($origPos, $newPos) { @@ -406,21 +406,21 @@ class mpd { if ( ! is_numeric($origPos) ) { $this->errStr = "PLMoveTrack(): argument 1 must be numeric"; return NULL; - } + } if ( $origPos < 0 or $origPos > $this->playlist_count ) { $this->errStr = "PLMoveTrack(): argument 1 out of range"; return NULL; } if ( $newPos < 0 ) $newPos = 0; if ( $newPos > $this->playlist_count ) $newPos = $this->playlist_count; - + if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLMOVETRACK,$origPos,$newPos))) $this->RefreshInfo(); if ( $this->debugging ) echo "mpd->PLMoveTrack() / return\n"; return $resp; } - /* PLShuffle() - * + /* PLShuffle() + * * Randomly reorders the songs in the playlist. */ function PLShuffle() { @@ -430,9 +430,9 @@ class mpd { return $resp; } - /* PLLoad() - * - * Retrieves the playlist from <file>.m3u and loads it into the current playlist. + /* PLLoad() + * + * Retrieves the playlist from <file>.m3u and loads it into the current playlist. */ function PLLoad($file) { if ( $this->debugging ) echo "mpd->PLLoad()\n"; @@ -441,8 +441,8 @@ class mpd { return $resp; } - /* PLSave() - * + /* PLSave() + * * Saves the playlist to <file>.m3u for later retrieval. The file is saved in the MPD playlist * directory. */ @@ -453,8 +453,8 @@ class mpd { return $resp; } - /* PLClear() - * + /* PLClear() + * * Empties the playlist. */ function PLClear() { @@ -464,8 +464,8 @@ class mpd { return $resp; } - /* PLRemove() - * + /* PLRemove() + * * Removes track <id> from the playlist. */ public function PLRemove($id) { @@ -474,13 +474,13 @@ class mpd { return NULL; } if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLREMOVE,$id))) $this->RefreshInfo(); - debug_event('MPD',"mpd->PLRemove() / return",'5'); + debug_event('MPD',"mpd->PLRemove() / return",'5'); return $resp; } // PLRemove - /* SetRepeat() - * - * Enables 'loop' mode -- tells MPD continually loop the playlist. The <repVal> parameter + /* SetRepeat() + * + * Enables 'loop' mode -- tells MPD continually loop the playlist. The <repVal> parameter * is either 1 (on) or 0 (off). */ function SetRepeat($repVal) { @@ -491,8 +491,8 @@ class mpd { return $rpt; } - /* SetRandom() - * + /* SetRandom() + * * Enables 'randomize' mode -- tells MPD to play songs in the playlist in random order. The * <rndVal> parameter is either 1 (on) or 0 (off). */ @@ -504,10 +504,10 @@ class mpd { return $resp; } - /* Shutdown() - * - * Shuts down the MPD server (aka sends the KILL command). This closes the current connection, - * and prevents future communication with the server. + /* Shutdown() + * + * Shuts down the MPD server (aka sends the KILL command). This closes the current connection, + * and prevents future communication with the server. */ function Shutdown() { if ( $this->debugging ) echo "mpd->Shutdown()\n"; @@ -522,15 +522,15 @@ class mpd { return $resp; } - /* DBRefresh() - * - * Tells MPD to rescan the music directory for new tracks, and to refresh the Database. Tracks + /* DBRefresh() + * + * Tells MPD to rescan the music directory for new tracks, and to refresh the Database. Tracks * cannot be played unless they are in the MPD database. */ function DBRefresh() { if ( $this->debugging ) echo "mpd->DBRefresh()\n"; $resp = $this->SendCommand(MPD_CMD_REFRESH); - + // Update local variables $this->RefreshInfo(); @@ -538,9 +538,9 @@ class mpd { return $resp; } - /* Play() - * - * Begins playing the songs in the MPD playlist. + /* Play() + * + * Begins playing the songs in the MPD playlist. */ function Play() { if ( $this->debugging ) echo "mpd->Play()\n"; @@ -549,9 +549,9 @@ class mpd { return $rpt; } - /* Stop() - * - * Stops playing the MPD. + /* Stop() + * + * Stops playing the MPD. */ function Stop() { if ( $this->debugging ) echo "mpd->Stop()\n"; @@ -560,10 +560,10 @@ class mpd { return $rpt; } - /* Pause() - * + /* Pause() + * * Toggles pausing on the MPD. Calling it once will pause the player, calling it again - * will unpause. + * will unpause. */ function Pause() { if ( $this->debugging ) echo "mpd->Pause()\n"; @@ -571,12 +571,12 @@ class mpd { if ( $this->debugging ) echo "mpd->Pause() / return\n"; return $rpt; } - - /* SeekTo() - * - * Skips directly to the <idx> song in the MPD playlist. + + /* SeekTo() + * + * Skips directly to the <idx> song in the MPD playlist. */ - function SkipTo($idx) { + function SkipTo($idx) { if ( $this->debugging ) echo "mpd->SkipTo()\n"; if ( ! is_numeric($idx) ) { $this->errStr = "SkipTo() : argument 1 must be a numeric value"; @@ -587,13 +587,13 @@ class mpd { return $idx; } - /* SeekTo() - * + /* SeekTo() + * * Skips directly to a given position within a track in the MPD playlist. The <pos> argument, * given in seconds, is the track position to locate. The <track> argument, if supplied is * the track number in the playlist. If <track> is not specified, the current track is assumed. */ - function SeekTo($pos, $track = -1) { + function SeekTo($pos, $track = -1) { if ( $this->debugging ) echo "mpd->SeekTo()\n"; if ( ! is_numeric($pos) ) { $this->errStr = "SeekTo() : argument 1 must be a numeric value"; @@ -603,18 +603,18 @@ class mpd { $this->errStr = "SeekTo() : argument 2 must be a numeric value"; return NULL; } - if ( $track == -1 ) { + if ( $track == -1 ) { $track = $this->current_track_id; - } - + } + if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_SEEK,$track,$pos))) $this->RefreshInfo(); if ( $this->debugging ) echo "mpd->SeekTo() / return\n"; return $pos; } - /* Next() - * - * Skips to the next song in the MPD playlist. If not playing, returns an error. + /* Next() + * + * Skips to the next song in the MPD playlist. If not playing, returns an error. */ function Next() { if ( $this->debugging ) echo "mpd->Next()\n"; @@ -623,9 +623,9 @@ class mpd { return $rpt; } - /* Previous() - * - * Skips to the previous song in the MPD playlist. If not playing, returns an error. + /* Previous() + * + * Skips to the previous song in the MPD playlist. If not playing, returns an error. */ function Previous() { if ( $this->debugging ) echo "mpd->Previous()\n"; @@ -633,13 +633,13 @@ class mpd { if ( $this->debugging ) echo "mpd->Previous() / return\n"; return $rpt; } - - /* Search() - * - * Searches the MPD database. The search <type> should be one of the following: + + /* Search() + * + * Searches the MPD database. The search <type> should be one of the following: * MPD_SEARCH_ARTIST, MPD_SEARCH_TITLE, MPD_SEARCH_ALBUM - * The search <string> is a case-insensitive locator string. Anything that contains - * <string> will be returned in the results. + * The search <string> is a case-insensitive locator string. Anything that contains + * <string> will be returned in the results. */ function Search($type,$string) { if ( $this->debugging ) echo "mpd->Search()\n"; @@ -656,13 +656,13 @@ class mpd { return $searchlist; } - /* Find() - * - * Find() looks for exact matches in the MPD database. The find <type> should be one of - * the following: + /* Find() + * + * Find() looks for exact matches in the MPD database. The find <type> should be one of + * the following: * MPD_SEARCH_ARTIST, MPD_SEARCH_TITLE, MPD_SEARCH_ALBUM - * The find <string> is a case-insensitive locator string. Anything that exactly matches - * <string> will be returned in the results. + * The find <string> is a case-insensitive locator string. Anything that exactly matches + * <string> will be returned in the results. */ function Find($type,$string) { if ( $this->debugging ) echo "mpd->Find()\n"; @@ -679,8 +679,8 @@ class mpd { return $searchlist; } - /* Disconnect() - * + /* Disconnect() + * * Closes the connection to the MPD server. */ function Disconnect() { @@ -693,15 +693,15 @@ class mpd { unset($this->mpd_sock); } - /* GetArtists() - * + /* GetArtists() + * * Returns the list of artists in the database in an associative array. */ function GetArtists() { if ( $this->debugging ) echo "mpd->GetArtists()\n"; if ( is_null($resp = $this->SendCommand(MPD_CMD_TABLE, MPD_TBL_ARTIST))) return NULL; $arArray = array(); - + $arLine = strtok($resp,"\n"); $arName = ""; $arCounter = -1; @@ -719,8 +719,8 @@ class mpd { return $arArray; } - /* GetAlbums() - * + /* GetAlbums() + * * Returns the list of albums in the database in an associative array. Optional parameter * is an artist Name which will list all albums by a particular artist. */ @@ -760,9 +760,9 @@ class mpd { return ( 100 * $ver_maj ) + ( 10 * $ver_min ) + ( $ver_rel ); } - /* _checkCompatibility() - * - * Check MPD command compatibility against our internal table. If there is no version + /* _checkCompatibility() + * + * Check MPD command compatibility against our internal table. If there is no version * listed in the table, allow it by default. */ function _checkCompatibility($cmd) { @@ -794,8 +794,8 @@ class mpd { return TRUE; } - /* _parseFileListResponse() - * + /* _parseFileListResponse() + * * Builds a multidimensional array with MPD response lists. * * NOTE: This function is used internally within the class. It should not be used. @@ -819,13 +819,13 @@ class mpd { } $plistLine = strtok("\n"); - } + } } return $plistArray; } - /* RefreshInfo() - * + /* RefreshInfo() + * * Updates all class properties with the values from the MPD server. * * NOTE: This function is automatically called upon Connect() as of v1.1. @@ -842,7 +842,7 @@ class mpd { list ( $element, $value ) = explode(": ",$statLine); $stats[$element] = $value; $statLine = strtok("\n"); - } + } } // Get the Server Status @@ -894,8 +894,8 @@ class mpd { } /* ------------------ DEPRECATED METHODS -------------------*/ - /* GetStatistics() - * + /* GetStatistics() + * * Retrieves the 'statistics' variables from the server and tosses them into an array. * * NOTE: This function really should not be used. Instead, use $this->[variable]. The function @@ -913,14 +913,14 @@ class mpd { list ( $element, $value ) = explode(": ",$statsLine); $statsArray[$element] = $value; $statsLine = strtok("\n"); - } + } } if ( $this->debugging ) echo "mpd->GetStatistics() / return: " . print_r($statsArray) ."\n"; return $statsArray; } - /* GetStatus() - * + /* GetStatus() + * * Retrieves the 'status' variables from the server and tosses them into an array. * * NOTE: This function really should not be used. Instead, use $this->[variable]. The function @@ -944,8 +944,8 @@ class mpd { return $statusArray; } - /* GetVolume() - * + /* GetVolume() + * * Retrieves the mixer volume from the server. * * NOTE: This function really should not be used. Instead, use $this->volume. The function @@ -963,8 +963,8 @@ class mpd { return $vol; } - /* GetPlaylist() - * + /* GetPlaylist() + * * Retrieves the playlist from the server and tosses it into a multidimensional array. * * NOTE: This function really should not be used. Instead, use $this->playlist. The function @@ -989,7 +989,7 @@ class mpd { $this->RefreshInfo(); if ($resp = ($this->state == MPD_STATE_STOPPED)) { $this->PLClear(); - return true; + return true; } return false; diff --git a/modules/php_musicbrainz/mbArtist.php b/modules/php_musicbrainz/mbArtist.php index 7ba126b0..972ca311 100644 --- a/modules/php_musicbrainz/mbArtist.php +++ b/modules/php_musicbrainz/mbArtist.php @@ -14,7 +14,7 @@ private $releasesCount = 0; private $releasesOffset = 0; private $aliases = array(); - + function mbArtist( $id = '', $type = '', $name = '', $sortName = '' ) { parent::MusicBrainzEntity($id); $this->type = $type; @@ -102,7 +102,7 @@ if ( empty( $rresults ) ) return ""; - + $keys = array(); foreach ( $rresults as $key => $rr ) { $rr = $rr->getRelease(); diff --git a/modules/php_musicbrainz/mbArtistAlias.php b/modules/php_musicbrainz/mbArtistAlias.php index c7e7e95d..3b65fcb6 100644 --- a/modules/php_musicbrainz/mbArtistAlias.php +++ b/modules/php_musicbrainz/mbArtistAlias.php @@ -4,7 +4,7 @@ private $value; private $type; private $script; - + function mbAristAlias( $value='', $type='', $script='' ) { $this->value = $value; $this->type = $type; diff --git a/modules/php_musicbrainz/mbDisc.php b/modules/php_musicbrainz/mbDisc.php index 63087016..90dacc06 100644 --- a/modules/php_musicbrainz/mbDisc.php +++ b/modules/php_musicbrainz/mbDisc.php @@ -1,7 +1,7 @@ <?php /* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ class mbDiscError extends Exception { } - + class mbDisc { private $id; private $sectors = 0; @@ -22,7 +22,7 @@ function getLastTrackNum ( ) { return $this->lastTrackNum; } function setFirstTrackNum( $track ) { $this->firstTrackNum = $track; } function getFirstTrackNum( ) { return $this->firstTrackNum; } - + function &getTracks() { return $this->tracks; } @@ -46,7 +46,7 @@ foreach ( $disc->getTracks() as $track ) $toc .= '+' . $track[0]; - return "http://" . $netloc . "/bare/cdlookup.html?id=" . $disc->getId() . "&toc=" . $toc . + return "http://" . $netloc . "/bare/cdlookup.html?id=" . $disc->getId() . "&toc=" . $toc . "&tracks=" . $disc->getLastTrackNum(); } } diff --git a/modules/php_musicbrainz/mbEntity.php b/modules/php_musicbrainz/mbEntity.php index 47089279..86cfdc07 100644 --- a/modules/php_musicbrainz/mbEntity.php +++ b/modules/php_musicbrainz/mbEntity.php @@ -21,7 +21,7 @@ function &getRelations( $target_type='', $relation_type='' ) { if ( $target_type == '' && $relation_type == '' ) return $this->relations; - + $result = array(); if ( empty($target_type) ) { diff --git a/modules/php_musicbrainz/mbFilter.php b/modules/php_musicbrainz/mbFilter.php index 02ee41f7..a759fffa 100644 --- a/modules/php_musicbrainz/mbFilter.php +++ b/modules/php_musicbrainz/mbFilter.php @@ -6,11 +6,11 @@ class mbArtistFilter implements MusicBrainzFilter { private $parameterList = array(); - + function createParameters() { return $this->parameterList; } - + function name( $name ) { $this->parameterList['name'] = $name; return $this; @@ -46,14 +46,14 @@ function releaseType( $rtype ) { $type = extractFragment($rtype); - + if ( isset( $this->parameters['releasetypes'] ) ) { $this->parameters['releasetypes'] .= ' ' . $type; } else { $this->parameters['releasetypes'] = $type; } - + return $this; } @@ -71,12 +71,12 @@ $this->parameters['asin'] = $asin; return $this; } - + function limit( $limit ) { $this->parameters['limit'] = $limit; return $this; } - + function offset( $offset ) { $this->parameterList['offset'] = $offset; return $this; @@ -135,14 +135,14 @@ return $this; } } - + class mbUserFilter implements MusicBrainzFilter { private $parameters = array(); - + function createParameters() { return $this->parameters; } - + function name( $value ) { $this->parameters['name'] = $value; } diff --git a/modules/php_musicbrainz/mbLabel.php b/modules/php_musicbrainz/mbLabel.php index a94443f7..67e069ef 100644 --- a/modules/php_musicbrainz/mbLabel.php +++ b/modules/php_musicbrainz/mbLabel.php @@ -34,7 +34,7 @@ function getBeginDate() { return $this->beginDate; } function setEndDate( $endDate ) { $this->endDate = $endDate; } function getEndDate() { return $this->endDate; } - + function getUniqueName() { return empty($this->disambiguation) ? $this->name : $this->name . ' (' . $this->disambiguation . ')'; diff --git a/modules/php_musicbrainz/mbMetadata.php b/modules/php_musicbrainz/mbMetadata.php index 076bf6be..45453d6e 100644 --- a/modules/php_musicbrainz/mbMetadata.php +++ b/modules/php_musicbrainz/mbMetadata.php @@ -54,13 +54,13 @@ function &getArtistResults () { return $this->artistList; } function &getTrackResults () { return $this->trackList; } function &getReleaseResults() { return $this->releaseList; } - + function getUserList2( $remove ) { $ul = $this->userList; $this->userList = array(); return $ul; } - + function getArtistResults2( $remove ) { $al = $this->artistList; $this->artistList = array(); diff --git a/modules/php_musicbrainz/mbQuery.php b/modules/php_musicbrainz/mbQuery.php index 07afd771..df8aa4aa 100644 --- a/modules/php_musicbrainz/mbQuery.php +++ b/modules/php_musicbrainz/mbQuery.php @@ -1,9 +1,9 @@ <?php /* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ define ( 'NS_MMD_1', "http://musicbrainz.org/ns/mmd-1.0#" ); - + require_once( 'xml/xmlParser.php' ); - + require_once( 'mbUtil.php' ); require_once( 'mbRelation.php' ); require_once( 'mbEntity.php' ); @@ -39,21 +39,21 @@ $this->ws = new mbWebService(); $this->ownWs = true; } - + $this->clientId = $clientId; } function getUserByName( $name ) { $metadata = $this->getFromWebService( "user", "", null, mbUserFilter().name($name) ); $list = $metadata->getUserList(true); - + if ( count($list) > 0 ) { return $list[0]; } - + throw mbResponseError("response didn't contain user data"); } - + function getArtists( mbArtistFilter $artist_filters ) { $metadata = $this->getFromWebService( "artist", "", null, $artist_filters ); return $metadata->getArtistResults2(true); @@ -63,12 +63,12 @@ $metadata = $this->getFromWebService( "release", "", null, $release_filters ); return $metadata->getReleaseResults2(true); } - + function getTracks( mbTrackFilter $track_filters ) { $metadata = $this->getFromWebService( "track", "", null, $track_filters ); return $metadata->getTrackResults2(true); } - + function getArtistById( $aID, mbArtistIncludes $artist_includes ) { try { $id = extractUuid($aID); @@ -106,7 +106,7 @@ $includeList = $includes ? $includes->createIncludeTags() : null; $filterList = $filters ? $filters->createParameters() : null; $content = $this->ws->get( $entity, $id, $includeList, $filterList ); - + try { $parser = new mbXmlParser(); $parsed_content = $parser->parse($content); diff --git a/modules/php_musicbrainz/mbRelation.php b/modules/php_musicbrainz/mbRelation.php index a03efe18..398c950f 100644 --- a/modules/php_musicbrainz/mbRelation.php +++ b/modules/php_musicbrainz/mbRelation.php @@ -4,7 +4,7 @@ const DIR_BOTH = 0; const DIR_FORWARD = 1; const DIR_BACKWARD = 2; - + const TO_ARTIST = "http://musicbrainz.org/ns/mmd-1.0#Artist"; const TO_TRACK = "http://musicbrainz.org/ns/mmd-1.0#Track"; const TO_RELEASE = "http://musicbrainz.org/ns/mmd-1.0#Release"; @@ -76,7 +76,7 @@ function getEndDate() { return $this->endDate; } - + function getDirection() { return $this->direction; } diff --git a/modules/php_musicbrainz/mbRelease.php b/modules/php_musicbrainz/mbRelease.php index 9bcf4321..27afa4db 100644 --- a/modules/php_musicbrainz/mbRelease.php +++ b/modules/php_musicbrainz/mbRelease.php @@ -3,7 +3,7 @@ class mbRelease extends MusicBrainzEntity { // Types const TYPE_NONE = "http://musicbrainz.org/ns/mmd-1.0#None"; - + const TYPE_ALBUM = "http://musicbrainz.org/ns/mmd-1.0#Album"; const TYPE_SINGLE = "http://musicbrainz.org/ns/mmd-1.0#Single"; const TYPE_EP = "http://musicbrainz.org/ns/mmd-1.0#EP"; @@ -21,7 +21,7 @@ const TYPE_PROMOTION = "http://musicbrainz.org/ns/mmd-1.0#Promotion"; const TYPE_BOOTLEG = "http://musicbrainz.org/ns/mmd-1.0#Bootleg"; const TYPE_PSEUDO_RELEASE = "http://musicbrainz.org/ns/mmd-1.0#Pseudo-Release"; - + private $title; private $textLanguage; private $textScript; diff --git a/modules/php_musicbrainz/mbReleaseEvent.php b/modules/php_musicbrainz/mbReleaseEvent.php index a41fa95b..3131ea55 100644 --- a/modules/php_musicbrainz/mbReleaseEvent.php +++ b/modules/php_musicbrainz/mbReleaseEvent.php @@ -11,7 +11,7 @@ $this->country = $country; $this->dateStr = $dateStr; } - + function setCountry ( $country ) { $this->country = $country; } function getCountry ( ) { return $this->country; } function setCatalogNumber( $c_number ) { $this->catalogNumber = $c_number; } diff --git a/modules/php_musicbrainz/mbUser.php b/modules/php_musicbrainz/mbUser.php index 86e384f7..8317bebb 100644 --- a/modules/php_musicbrainz/mbUser.php +++ b/modules/php_musicbrainz/mbUser.php @@ -4,29 +4,29 @@ private $name; private $showNag = false; private $types = array(); - + function mbUser() { } - + function setName( $name ) { $this->name = $name; } function getName() { return $this->name; } - + function getShowNag() { return $this->showNag; } - + function setShowNag( $value ) { $this->setShowNag = $value; } - + function addType( $type ) { $this->types[] = $type; } - + function getNumTypes() { return count($this->types); } - + function getType( $i ) { return $this->types[$i]; } diff --git a/modules/php_musicbrainz/mbUtil.php b/modules/php_musicbrainz/mbUtil.php index eff5f34c..4ebdb33a 100644 --- a/modules/php_musicbrainz/mbUtil.php +++ b/modules/php_musicbrainz/mbUtil.php @@ -1,7 +1,7 @@ <?php /* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ class mbValueError extends Exception {} - + function extractFragment( $type ) { if ( ( $p = parse_url( $type ) ) == false ) { return $type; @@ -12,7 +12,7 @@ function extractUuid( $uid ) { if ( empty($uid) ) return $uid; - + $types = array( "artist/", "release/", "track/" ); for ( $i = 0; $i < 3; $i++ ) { if ( ($pos = strpos( $uid, $types[$i] )) !== false ) { @@ -52,7 +52,7 @@ return ""; } - + require_once( 'mbUtil_releasetypenames.php' ); function getReleaseTypeName( $id ) { if ( isset( $mbReleaseTypeNames[$id] ) ) diff --git a/modules/php_musicbrainz/mbUtil_countrynames.php b/modules/php_musicbrainz/mbUtil_countrynames.php index 6d0d87e6..c2fa37f8 100644 --- a/modules/php_musicbrainz/mbUtil_countrynames.php +++ b/modules/php_musicbrainz/mbUtil_countrynames.php @@ -1,6 +1,6 @@ <?php /* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ - $mbCountryNames = array( + $mbCountryNames = array( "BD" => "Bangladesh", "BE" => "Belgium", "BF" => "Burkina Faso", diff --git a/modules/php_musicbrainz/mbUtil_languagenames.php b/modules/php_musicbrainz/mbUtil_languagenames.php index 5006198d..3e56bf82 100644 --- a/modules/php_musicbrainz/mbUtil_languagenames.php +++ b/modules/php_musicbrainz/mbUtil_languagenames.php @@ -1,6 +1,6 @@ <?php /* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ - $mbLanguageNames = array( + $mbLanguageNames = array( "ART" => "Artificial (Other)", "ROH" => "Raeto-Romance", "SCO" => "Scots", diff --git a/modules/php_musicbrainz/mbUtil_releasetypenames.php b/modules/php_musicbrainz/mbUtil_releasetypenames.php index ad4f2bf0..a655dcdc 100644 --- a/modules/php_musicbrainz/mbUtil_releasetypenames.php +++ b/modules/php_musicbrainz/mbUtil_releasetypenames.php @@ -1,6 +1,6 @@ <?php /* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ - $mbReleaseTypeNames = array( + $mbReleaseTypeNames = array( "http://musicbrainz.org/ns/mmd-1.0#None" => "None", "http://musicbrainz.org/ns/mmd-1.0#Album" => "Album", "http://musicbrainz.org/ns/mmd-1.0#Single" => "Single", diff --git a/modules/php_musicbrainz/mbWebService.php b/modules/php_musicbrainz/mbWebService.php index 0b59da34..76aa0939 100644 --- a/modules/php_musicbrainz/mbWebService.php +++ b/modules/php_musicbrainz/mbWebService.php @@ -4,7 +4,7 @@ function get ( $entity, $id, $include, $filter, $version = '1' ); function post( $entity, $id, $data, $version = '1' ); } - + class mbWebService implements IWebService { private $host; private $port; @@ -31,7 +31,7 @@ return true; } - + function close() { if ( $this->fSock != -1 ) { fclose($this->fSock); @@ -47,7 +47,7 @@ function parseHeaders( $string ) { $lines = explode( "\n", $string ); $this->lastHeaders = array(); - + foreach ( $lines as $key => $line ) { // Status line if ( $key == 0 ) { @@ -81,7 +81,7 @@ $this->lastHeaders = array(); return false; } - + function getHeaders() { return $this->lastHeaders; } @@ -91,7 +91,7 @@ $this->lastError = "Trying to write to closed socket."; return false; } - + fwrite( $this->fSock, $string . "\r\n" ); fwrite( $this->fSock, "Host: " . $this->host . "\r\n" ); fwrite( $this->fSock, "Accept: */*\r\n" ); @@ -109,7 +109,7 @@ $this->lastError = "Trying to read from closed socket."; return false; } - + $buffer = ""; while ( !feof($this->fSock) ) @@ -120,7 +120,7 @@ return $this->parseHeaders($buffer); } - + function get( $entity, $uid, $includes, $filters, $version="1" ) { $params = array(); $params['type'] = "xml"; @@ -142,17 +142,17 @@ } $URI = $this->pathPrefix . "/" . $version . "/" . $entity . "/" . $uid . "?" . $this->build_query( $params ); - + if ( $this->fSock == -1 && !$this->connect() ) return false; - + $this->sendRequest( "GET $URI HTTP/1.1" ); $this->lastResponse = $this->getResponse(); $this->close(); if ( isset($this->lastHeaders['HTTP_status']) && $this->lastHeaders['HTTP_status'] != 200 ) return false; - + return $this->lastResponse; } @@ -170,11 +170,11 @@ return $this->lastResponse; } - + function build_query( $array ) { $first = true; $query_string = ""; - + if ( !is_array($array) || sizeof($array) == 0 ) return ""; diff --git a/modules/php_musicbrainz/mbXmlParser.php b/modules/php_musicbrainz/mbXmlParser.php index aaad0126..46d39e7c 100644 --- a/modules/php_musicbrainz/mbXmlParser.php +++ b/modules/php_musicbrainz/mbXmlParser.php @@ -5,19 +5,19 @@ class mbXmlParser { private $xml_parser; private $factory; - + function mbXmlParser() { $this->xml_parser = new xmlParser(); $this->factory = new mbDefaultFactory(); } - + private function parseList( XMLNode $node, array &$list, $func ) { for ( $i = 0; $i < $node->nChildNodes(); $i++ ) { $cnode = $node->getChildNode($i); $list[] = call_user_func( array( &$this, $func ), $cnode ); } } - + private function parseResults( XMLNode $node, array &$list, $func, $type ) { for ( $i = 0; $i < $node->nChildNodes(); $i++ ) { $cnode = $node->getChildNode($i); @@ -29,7 +29,7 @@ $list[] = $to_add; } } - + private function parseRelations( XMLNode $node, MusicBrainzEntity $entity ) { $targetType = $node->getAttribute("target-type"); if ( $targetType == '' ) @@ -44,14 +44,14 @@ } } } - + private function parseUserResults( XMLNode $node, array &$userList ) { for ( $i = 0; $i < $node->nChildNodes(); $i++ ) { $cnode = $node->getChildNode($i); $userList[] = $this->createUser( $cnode ); } } - + private function createUser( XMLNode $node ) { $user = $this->factory->newUser(); for ( $i = 0; $i < $node->nChildNodes(); $i++ ) { @@ -68,7 +68,7 @@ } return $user; } - + private function createArtistAlias( XMLNode $node ) { $aa = $this->factory->newArtistAlias(); $aa->setType($node->getAttribute("type")); @@ -77,14 +77,14 @@ return $aa; } - + private function createTag( XMLNode $node ) { $tag = $this->factory->newTag(); $tag->setCount($node->getAttribute("count")); $tag->setName($node->getText()); return $tag; } - + private function createLabelAlias( XML $node ) { $la = $this->factory->newLabelAlias(); $la->setType($node->getAttribute("type")); @@ -92,13 +92,13 @@ $la->setValue($node->getText()); return $la; } - + private function createDisc( XMLNode $node ) { $disc = $this->factory->newDisc(); $disc->setId($node->getAttribute("id")); return $disc; } - + private function createReleaseEvent( XMLNode $node ) { $relEvent = $this->factory->newReleaseEvent(); $relEvent->setCountry($node->getAttribute("country")); @@ -115,7 +115,7 @@ } return $relEvent; } - + private function createLabel( XMLNode $node ) { $label = $this->factory->newLabel(); $label->setId($node->getAttribute("id")); @@ -160,7 +160,7 @@ return $label; } - + private function createArtist( XMLNode $node ) { $artist = $this->factory->newArtist(); $artist->setId($node->getAttribute("id")); @@ -207,7 +207,7 @@ return $artist; } - + private function createTrack( XMLNode $node ) { $track = $this->factory->newTrack(); $track->setId($node->getAttribute("id")); @@ -238,10 +238,10 @@ break; } } - + return $track; } - + private function createRelease( XMLNode $node ) { $release = $this->factory->newRelease(); $release->setId($node->getAttribute("id")); @@ -294,13 +294,13 @@ return $release; } - + private function createRelation( XMLNode $node, $type ) { $relation = $this->factory->newRelation(); $relation->setType(extractFragment($node->getAttribute("type"))); // TODO: fixme $relation->setTargetType($type); $relation->setTargetId($node->getAttribute("target")); - + $dir = mbRelation::DIR_BOTH; switch( strtolower($node->getAttribute("direction")) ) { case "forward": @@ -340,7 +340,7 @@ return $relation; } - + function parse( $data ) { $nodes = $this->xml_parser->parse( $data ); @@ -349,7 +349,7 @@ $md = new mbMetadata(); - + for ( $i = 0; $i < $nodes->nChildNodes(); $i++ ) { $node = $nodes->getChildNode($i); $name = strtolower($node->getName()); diff --git a/modules/php_musicbrainz/xml/xmlParser.php b/modules/php_musicbrainz/xml/xmlParser.php index 1d0058da..7e3311cf 100644 --- a/modules/php_musicbrainz/xml/xmlParser.php +++ b/modules/php_musicbrainz/xml/xmlParser.php @@ -15,7 +15,7 @@ function getParentNode() { return $this->parentNode; } - + function nChildNodes() { return sizeof($this->childNodes); } @@ -46,7 +46,7 @@ return $this->attributes['TEXT']; } } - + class xmlParser { private $_parser; private $_root_node = null; @@ -69,7 +69,7 @@ public function lastError() { return $this->_last_error; } - + public function parse( $data ) { if ( !xml_parse( $this->_parser, $data ) ) { $this->_last_error = xml_get_current_line_number($this->_parser) . ": ". xml_error_string($this->_parser); @@ -77,7 +77,7 @@ } return $this->_root_node; } - + private function start_element_handler( $parser, $name, $attribs ) { if ( !$this->_root_node ) { $new_node = new XMLNode( $name, $attribs ); @@ -90,14 +90,14 @@ $old_node->setChildNode( $new_node ); $this->_curr_node = $new_node; } - + } private function text_handler( $parser, $text ) { if ( $this->_curr_node ) $this->_curr_node->setText( $text ); } - + private function end_element_handler( $parser, $name ) { if ( $this->_root_node ) { $this->_curr_node = $this->_curr_node->getParentNode(); diff --git a/modules/plugins/Lastfm.plugin.php b/modules/plugins/Lastfm.plugin.php index 99ac5fd7..24f9862f 100644 --- a/modules/plugins/Lastfm.plugin.php +++ b/modules/plugins/Lastfm.plugin.php @@ -20,31 +20,31 @@ */ -class AmpacheLastfm { +class AmpacheLastfm { - public $name ='Last.FM'; - public $description ='Records your played songs to your Last.FM Account'; + public $name ='Last.FM'; + public $description ='Records your played songs to your Last.FM Account'; public $url =''; public $version ='000003'; public $min_ampache ='340007'; public $max_ampache ='340008'; - // These are internal settings used by this class, run this->load to + // These are internal settings used by this class, run this->load to // fill em out - private $username; - private $password; + private $username; + private $password; private $hostname; - private $port; - private $path; + private $port; + private $path; private $challenge; /** * Constructor * This function does nothing... */ - public function __construct() { + public function __construct() { - return true; + return true; } // PluginLastfm @@ -53,19 +53,19 @@ class AmpacheLastfm { * This is a required plugin function it inserts the required preferences * into Ampache */ - public function install() { + public function install() { // Check and see if it's already installed (they've just hit refresh, those dorks) - if (Preference::exists('lastfm_user')) { return false; } + if (Preference::exists('lastfm_user')) { return false; } - Preference::insert('lastfm_user','Last.FM Username','','25','string','plugins'); - Preference::insert('lastfm_pass','Last.FM Password','','25','string','plugins'); - Preference::insert('lastfm_port','Last.FM Submit Port','','25','string','internal'); - Preference::insert('lastfm_host','Last.FM Submit Host','','25','string','internal'); - Preference::insert('lastfm_url','Last.FM Submit URL','','25','string','internal'); - Preference::insert('lastfm_challenge','Last.FM Submit Challenge','','25','string','internal'); + Preference::insert('lastfm_user','Last.FM Username','','25','string','plugins'); + Preference::insert('lastfm_pass','Last.FM Password','','25','string','plugins'); + Preference::insert('lastfm_port','Last.FM Submit Port','','25','string','internal'); + Preference::insert('lastfm_host','Last.FM Submit Host','','25','string','internal'); + Preference::insert('lastfm_url','Last.FM Submit URL','','25','string','internal'); + Preference::insert('lastfm_challenge','Last.FM Submit Challenge','','25','string','internal'); - return true; + return true; } // install @@ -74,14 +74,14 @@ class AmpacheLastfm { * This is a required plugin function it removes the required preferences from * the database returning it to its origional form */ - public function uninstall() { + public function uninstall() { - Preference::delete('lastfm_pass'); - Preference::delete('lastfm_user'); - Preference::delete('lastfm_url'); - Preference::delete('lastfm_host'); - Preference::delete('lastfm_port'); - Preference::delete('lastfm_challenge'); + Preference::delete('lastfm_pass'); + Preference::delete('lastfm_user'); + Preference::delete('lastfm_url'); + Preference::delete('lastfm_host'); + Preference::delete('lastfm_port'); + Preference::delete('lastfm_challenge'); } // uninstall @@ -90,76 +90,76 @@ class AmpacheLastfm { * This takes care of queueing and then submiting the tracks eventually this will make sure * that you've haven't */ - public function submit($song,$user_id) { + public function submit($song,$user_id) { // Before we start let's pull the last song submited by this user - $previous = Stats::get_last_song($user_id); + $previous = Stats::get_last_song($user_id); + + $diff = time() - $previous['date']; - $diff = time() - $previous['date']; - // Make sure it wasn't within the last min - if ($diff < 60) { - debug_event('LastFM','Last song played within ' . $diff . ' seconds, not recording stats','3'); - return false; - } + if ($diff < 60) { + debug_event('LastFM','Last song played within ' . $diff . ' seconds, not recording stats','3'); + return false; + } - if ($song->time < 30) { - debug_event('LastFM','Song less then 30 seconds not queueing','3'); - return false; - } + if ($song->time < 30) { + debug_event('LastFM','Song less then 30 seconds not queueing','3'); + return false; + } // Make sure there's actually a username and password before we keep going - if (!$this->username || !$this->password) { return false; } - + if (!$this->username || !$this->password) { return false; } + // Create our scrobbler with everything this time and then queue it - $scrobbler = new scrobbler($this->username,$this->password,$this->hostname,$this->port,$this->path,$this->challenge); + $scrobbler = new scrobbler($this->username,$this->password,$this->hostname,$this->port,$this->path,$this->challenge); // Check to see if the scrobbling works - if (!$scrobbler->queue_track($song->f_artist_full,$song->f_album_full,$song->title,time(),$song->time,$song->track)) { + if (!$scrobbler->queue_track($song->f_artist_full,$song->f_album_full,$song->title,time(),$song->time,$song->track)) { // Depending on the error we might need to do soemthing here - return false; - } - - // Go ahead and submit it now - if (!$scrobbler->submit_tracks()) { - debug_event('LastFM','Error Submit Failed: ' . $scrobbler->error_msg,'3'); - if ($scrobbler->reset_handshake) { + return false; + } + + // Go ahead and submit it now + if (!$scrobbler->submit_tracks()) { + debug_event('LastFM','Error Submit Failed: ' . $scrobbler->error_msg,'3'); + if ($scrobbler->reset_handshake) { debug_event('LastFM','Re-running Handshake due to error','3'); - $this->set_handshake($user_id); + $this->set_handshake($user_id); // Try try again - if ($scrobbler->submit_tracks()) { - return true; - } - } - return false; + if ($scrobbler->submit_tracks()) { + return true; + } + } + return false; } - debug_event('LastFM','Submission Successful','5'); - - return true; + debug_event('LastFM','Submission Successful','5'); + + return true; } // submit - /** + /** * set_handshake * This runs a handshake and properly updates the preferences as needed, it returns the data - * as an array so we don't have to requery the db. This requires a userid so it knows who's + * as an array so we don't have to requery the db. This requires a userid so it knows who's * crap to update */ - public function set_handshake($user_id) { - - $scrobbler = new scrobbler($this->username,$this->password); - $data = $scrobbler->handshake(); + public function set_handshake($user_id) { + + $scrobbler = new scrobbler($this->username,$this->password); + $data = $scrobbler->handshake(); - if (!$data) { - debug_event('LastFM','Handshake Failed: ' . $scrobbler->error_msg,'3'); - return false; - } + if (!$data) { + debug_event('LastFM','Handshake Failed: ' . $scrobbler->error_msg,'3'); + return false; + } - $this->hostname = $data['submit_host']; - $this->port = $data['submit_port']; - $this->path = $data['submit_url']; - $this->challenge = $data['challenge']; + $this->hostname = $data['submit_host']; + $this->port = $data['submit_port']; + $this->path = $data['submit_url']; + $this->challenge = $data['challenge']; // Update the preferences Preference::update('lastfm_port',$user_id,$data['submit_port']); @@ -167,7 +167,7 @@ class AmpacheLastfm { Preference::update('lastfm_url',$user_id,$data['submit_url']); Preference::update('lastfm_challenge',$user_id,$data['challenge']); - return true; + return true; } // set_handshake @@ -176,40 +176,40 @@ class AmpacheLastfm { * This loads up the data we need into this object, this stuff comes from the preferences * it's passed as a key'd array */ - public function load($data,$user_id) { - - if (strlen(trim($data['lastfm_user']))) { - $this->username = trim($data['lastfm_user']); - } - else { - debug_event('LastFM','No Username, not scrobbling','3'); - return false; - } - if (strlen(trim($data['lastfm_pass']))) { - $this->password = trim($data['lastfm_pass']); - } - else { - debug_event('LastFM','No Password, not scrobbling','3'); - return false; - } + public function load($data,$user_id) { + + if (strlen(trim($data['lastfm_user']))) { + $this->username = trim($data['lastfm_user']); + } + else { + debug_event('LastFM','No Username, not scrobbling','3'); + return false; + } + if (strlen(trim($data['lastfm_pass']))) { + $this->password = trim($data['lastfm_pass']); + } + else { + debug_event('LastFM','No Password, not scrobbling','3'); + return false; + } // If we don't have the other stuff try to get it before giving up - if (!$data['lastfm_host'] || !$data['lastfm_port'] || !$data['lastfm_url'] || !$data['lastfm_challenge']) { - debug_event('LastFM','Running Handshake, missing information','3'); - if (!$this->set_handshake($user_id)) { + if (!$data['lastfm_host'] || !$data['lastfm_port'] || !$data['lastfm_url'] || !$data['lastfm_challenge']) { + debug_event('LastFM','Running Handshake, missing information','3'); + if (!$this->set_handshake($user_id)) { debug_event('LastFM','Handshake failed, you lose','3'); - return false; - } - } - else { + return false; + } + } + else { $this->hostname = $data['lastfm_host']; $this->port = $data['lastfm_port']; $this->path = $data['lastfm_url']; $this->challenge = $data['lastfm_challenge']; - } - + } + - return true; + return true; } // load diff --git a/modules/plugins/Librefm.plugin.php b/modules/plugins/Librefm.plugin.php index 9b22b183..36d72603 100644 --- a/modules/plugins/Librefm.plugin.php +++ b/modules/plugins/Librefm.plugin.php @@ -20,31 +20,31 @@ */ -class Ampachelibrefm { +class Ampachelibrefm { - public $name ='Libre.FM'; - public $description ='Records your played songs to your Libre.FM Account'; + public $name ='Libre.FM'; + public $description ='Records your played songs to your Libre.FM Account'; public $url =''; public $version ='000001'; public $min_ampache ='350001'; public $max_ampache ='360008'; - // These are internal settings used by this class, run this->load to + // These are internal settings used by this class, run this->load to // fill em out - private $username; - private $password; + private $username; + private $password; private $hostname; - private $port; - private $path; + private $port; + private $path; private $challenge; /** * Constructor * This function does nothing... */ - public function __construct() { + public function __construct() { - return true; + return true; } // Pluginlibrefm @@ -53,19 +53,19 @@ class Ampachelibrefm { * This is a required plugin function it inserts the required preferences * into Ampache */ - public function install() { + public function install() { // Check and see if it's already installed (they've just hit refresh, those dorks) - if (Preference::exists('librefm_user')) { return false; } + if (Preference::exists('librefm_user')) { return false; } - Preference::insert('librefm_user','Libre.FM Username','','25','string','plugins'); - Preference::insert('librefm_pass','Libre.FM Password','','25','string','plugins'); - Preference::insert('librefm_port','Libre.FM Submit Port','','25','string','internal'); - Preference::insert('librefm_host','Libre.FM Submit Host','','25','string','internal'); - Preference::insert('librefm_url','Libre.FM Submit URL','','25','string','internal'); - Preference::insert('librefm_challenge','Libre.FM Submit Challenge','','25','string','internal'); + Preference::insert('librefm_user','Libre.FM Username','','25','string','plugins'); + Preference::insert('librefm_pass','Libre.FM Password','','25','string','plugins'); + Preference::insert('librefm_port','Libre.FM Submit Port','','25','string','internal'); + Preference::insert('librefm_host','Libre.FM Submit Host','','25','string','internal'); + Preference::insert('librefm_url','Libre.FM Submit URL','','25','string','internal'); + Preference::insert('librefm_challenge','Libre.FM Submit Challenge','','25','string','internal'); - return true; + return true; } // install @@ -74,14 +74,14 @@ class Ampachelibrefm { * This is a required plugin function it removes the required preferences from * the database returning it to its origional form */ - public function uninstall() { + public function uninstall() { - Preference::delete('librefm_pass'); - Preference::delete('librefm_user'); - Preference::delete('librefm_url'); - Preference::delete('librefm_host'); - Preference::delete('librefm_port'); - Preference::delete('librefm_challenge'); + Preference::delete('librefm_pass'); + Preference::delete('librefm_user'); + Preference::delete('librefm_url'); + Preference::delete('librefm_host'); + Preference::delete('librefm_port'); + Preference::delete('librefm_challenge'); } // uninstall @@ -90,76 +90,76 @@ class Ampachelibrefm { * This takes care of queueing and then submiting the tracks eventually this will make sure * that you've haven't */ - public function submit($song,$user_id) { + public function submit($song,$user_id) { // Before we start let's pull the last song submited by this user - $previous = Stats::get_last_song($user_id); + $previous = Stats::get_last_song($user_id); + + $diff = time() - $previous['date']; - $diff = time() - $previous['date']; - // Make sure it wasn't within the last min - if ($diff < 60) { - debug_event('librefm','Last song played within ' . $diff . ' seconds, not recording stats','3'); - return false; - } + if ($diff < 60) { + debug_event('librefm','Last song played within ' . $diff . ' seconds, not recording stats','3'); + return false; + } - if ($song->time < 30) { - debug_event('librefm','Song less then 30 seconds not queueing','3'); - return false; - } + if ($song->time < 30) { + debug_event('librefm','Song less then 30 seconds not queueing','3'); + return false; + } // Make sure there's actually a username and password before we keep going - if (!$this->username || !$this->password) { return false; } - + if (!$this->username || !$this->password) { return false; } + // Create our scrobbler with everything this time and then queue it - $scrobbler = new scrobbler($this->username,$this->password,$this->hostname,$this->port,$this->path,$this->challenge,'turtle.libre.fm'); + $scrobbler = new scrobbler($this->username,$this->password,$this->hostname,$this->port,$this->path,$this->challenge,'turtle.libre.fm'); // Check to see if the scrobbling works - if (!$scrobbler->queue_track($song->f_artist_full,$song->f_album_full,$song->title,time(),$song->time,$song->track)) { + if (!$scrobbler->queue_track($song->f_artist_full,$song->f_album_full,$song->title,time(),$song->time,$song->track)) { // Depending on the error we might need to do soemthing here - return false; - } - - // Go ahead and submit it now - if (!$scrobbler->submit_tracks()) { - debug_event('librefm','Error Submit Failed: ' . $scrobbler->error_msg,'3'); - if ($scrobbler->reset_handshake) { + return false; + } + + // Go ahead and submit it now + if (!$scrobbler->submit_tracks()) { + debug_event('librefm','Error Submit Failed: ' . $scrobbler->error_msg,'3'); + if ($scrobbler->reset_handshake) { debug_event('librefm','Re-running Handshake due to error','3'); - $this->set_handshake($user_id); + $this->set_handshake($user_id); // Try try again - if ($scrobbler->submit_tracks()) { - return true; - } - } - return false; + if ($scrobbler->submit_tracks()) { + return true; + } + } + return false; } - debug_event('librefm','Submission Successful','5'); - - return true; + debug_event('librefm','Submission Successful','5'); + + return true; } // submit - /** + /** * set_handshake * This runs a handshake and properly updates the preferences as needed, it returns the data - * as an array so we don't have to requery the db. This requires a userid so it knows who's + * as an array so we don't have to requery the db. This requires a userid so it knows who's * crap to update */ - public function set_handshake($user_id) { - - $scrobbler = new scrobbler($this->username,$this->password,'','','','','turtle.libre.fm'); - $data = $scrobbler->handshake(); + public function set_handshake($user_id) { + + $scrobbler = new scrobbler($this->username,$this->password,'','','','','turtle.libre.fm'); + $data = $scrobbler->handshake(); - if (!$data) { - debug_event('librefm','Handshake Failed: ' . $scrobbler->error_msg,'3'); - return false; - } + if (!$data) { + debug_event('librefm','Handshake Failed: ' . $scrobbler->error_msg,'3'); + return false; + } - $this->hostname = $data['submit_host']; - $this->port = $data['submit_port']; - $this->path = $data['submit_url']; - $this->challenge = $data['challenge']; + $this->hostname = $data['submit_host']; + $this->port = $data['submit_port']; + $this->path = $data['submit_url']; + $this->challenge = $data['challenge']; // Update the preferences Preference::update('librefm_port',$user_id,$data['submit_port']); @@ -167,7 +167,7 @@ class Ampachelibrefm { Preference::update('librefm_url',$user_id,$data['submit_url']); Preference::update('librefm_challenge',$user_id,$data['challenge']); - return true; + return true; } // set_handshake @@ -176,40 +176,40 @@ class Ampachelibrefm { * This loads up the data we need into this object, this stuff comes from the preferences * it's passed as a key'd array */ - public function load($data,$user_id) { - - if (strlen(trim($data['librefm_user']))) { - $this->username = trim($data['librefm_user']); - } - else { - debug_event('librefm','No Username, not scrobbling','3'); - return false; - } - if (strlen(trim($data['librefm_pass']))) { - $this->password = trim($data['librefm_pass']); - } - else { - debug_event('librefm','No Password, not scrobbling','3'); - return false; - } + public function load($data,$user_id) { + + if (strlen(trim($data['librefm_user']))) { + $this->username = trim($data['librefm_user']); + } + else { + debug_event('librefm','No Username, not scrobbling','3'); + return false; + } + if (strlen(trim($data['librefm_pass']))) { + $this->password = trim($data['librefm_pass']); + } + else { + debug_event('librefm','No Password, not scrobbling','3'); + return false; + } // If we don't have the other stuff try to get it before giving up - if (!$data['librefm_host'] || !$data['librefm_port'] || !$data['librefm_url'] || !$data['librefm_challenge']) { - debug_event('librefm','Running Handshake, missing information','3'); - if (!$this->set_handshake($user_id)) { + if (!$data['librefm_host'] || !$data['librefm_port'] || !$data['librefm_url'] || !$data['librefm_challenge']) { + debug_event('librefm','Running Handshake, missing information','3'); + if (!$this->set_handshake($user_id)) { debug_event('librefm','Handshake failed, you lose','3'); - return false; - } - } - else { + return false; + } + } + else { $this->hostname = $data['librefm_host']; $this->port = $data['librefm_port']; $this->path = $data['librefm_url']; $this->challenge = $data['librefm_challenge']; - } - + } + - return true; + return true; } // load diff --git a/modules/validatemail/validateEmail.php b/modules/validatemail/validateEmail.php index 3fc83026..78bbf5f6 100644 --- a/modules/validatemail/validateEmail.php +++ b/modules/validatemail/validateEmail.php @@ -26,7 +26,7 @@ Organization: webdev.berber.co.il Date: April 10th, 1999 Changes: - The script now handles all kinds of domains (not only @xxx.yyy) as before. - Added a debugging mode which also works as a verbose mode. - + By: Frank Vogel vogel@simec.com Organization: Simec Corp. (http://www.simec.com) Date: June 13th, 2000 @@ -65,10 +65,10 @@ Organization: KillerSoft < http://www.killersoft.com/ > with EHLO. - Added routines to listen for multi-line output from servers. - Fixed all commands ending in "\n" to end in "\r\n" as specified by accurate SMTP - communication. THIS FIXES THE "HANG" PROBLEM EXPERIENCED WITH MANY MAIL SERVERS, + communication. THIS FIXES THE "HANG" PROBLEM EXPERIENCED WITH MANY MAIL SERVERS, INCLUDING AOL.COM. (See Disclaimers about AOL.com connections, though ...) - Added support for Jeffrey E.F. Friedl's definitive email format regex, translated - from perl into PHP. Will reject email addresses with invalid formatting before + from perl into PHP. Will reject email addresses with invalid formatting before opening any server connections. - Changed initial "listening" routine to listen for one of two SMTP greeting responses (220 or 421) instead of just listening for anything. validateEmail is now well-behaved @@ -80,7 +80,7 @@ Organization: KillerSoft < http://www.killersoft.com/ > - Modified comments where Shane Gibson's were no longer needed or accurate (due to changes). Added the comments for features that didn't exist in Shane's version. - Incremented version number. - + Disclaimers: - All additions and modifications Copyright 2002 KillerSoft.com. - Program is free for any use as long as these notes & credits remain intact. - Yes, I know there is no foolproof way to validate an e-mail address. But this is better than @@ -100,7 +100,7 @@ Organization: KillerSoft < http://www.killersoft.com/ > through alternate means. So -- this script won't help you in validating AOL.com (and affiliated) e-mail addresses. BUT ... at least it won't choke/hang on them either, as previous versions of this script would. - + - Please send bugs, comments or suggestions to info@killersoft.com! */ @@ -144,7 +144,7 @@ function validateEmail ( $email, $verbose=0 ) { global $SERVER_NAME; // DEFINE PREFERENCES - + // Passed along with the HELO/EHLO statement. // Leave blank to use $SERVER_NAME. // Note that most modern MTAs will ignore (but require) whatever you say here ... @@ -161,30 +161,30 @@ function validateEmail ( $email, $verbose=0 ) { if (Config::get('mail_domain')) { $serverName = Config::get('mail_domain'); - } + } else { $serverName = "domain.tld"; } // MAIL FROM -- who's asking? // Good values: nobody, postmaster, info, buckwheat, gumby $from = "info"; - + // fsockopen() timeout - in seconds $socketTimeout = 15; - + // waitTimeout - how long we'll wait for a server to respond after // a successful connection. In seconds. // Recommended to keep this above 35 seconds - some servers are really slow. $waitTimeout = 50; - + // MX Server cutoff // Some hosts (like hotmail.com) have MANY MX hosts -- 12 or more. // Set this to a number where you'd like to say "I get the picture" // ... so you don't wind up having to hit EVERY MX host. $mxcutoff = 15; - + // END OF PREFERENCES - + /////////////////////////////////////////////////////////////////////////////// // DO NOT EDIT BELOW THIS LINE /////////////////////////////////////////////////////////////////////////////// @@ -195,16 +195,16 @@ function validateEmail ( $email, $verbose=0 ) { // Let's give good commands $CRLF = "\r\n"; - + // Make a few adjustments for verbose mode if ( $verbose ) { // Version $version = "validateEmail 2.0 - http://killersoft.com/contrib/"; - + // Start stopwatch list ( $msecStart, $secStart ) = explode ( " ", microtime() ); - + // Adjust verbose output format // for php.cgi or webserver interface $sapi_type = php_sapi_name(); @@ -231,29 +231,29 @@ function validateEmail ( $email, $verbose=0 ) { eval("echo \"Internal: $version - running as ".AddSlashes($sapi_type)."\"; $vNL"); } } - + // How we'll identify ourselves in SMTP HELO/EHLO argument if ( $serverName == "" ) $serverName = "$SERVER_NAME"; if ( $serverName == "" ) $serverName = "localhost"; - + // Initialize return values with default $return[0] = false; $return[1] = "Invalid email address (bad domain name)"; $return[2] = false; $return[3] = ""; - + // make sure that we're dealing with a valid email address format $isValid = true; // just in case validateEmailFormat is not available if ( function_exists('validateEmailFormat') ) $isValid = validateEmailFormat ( $email ); - + // abort if necessary if ( !$isValid ) { if ( $verbose ) eval("echo \"Internal: $email format is invalid! Quitting ...\"; $vNL"); return $return; - + } else { if ( $verbose ) eval("echo \"Internal: $email is a valid RFC 822 formatted address\"; $vNL"); - + // assign our user part and domain parts respectively to seperate // variables list ( $user, $domain ) = explode ( "@", $email ); @@ -261,20 +261,20 @@ function validateEmail ( $email, $verbose=0 ) { eval("echo \"Internal: user ..... $user\"; $vNL"); eval("echo \"Internal: domain ... $domain\"; $vNL"); } - + // split up the domain into sub-parts $arr = explode ( ".", $domain ); - + // figure out how many parts there are in the host/domain name portion $count = count ( $arr ); - + // flag to indicate success $bSuccess = false; - + // we try this for each qualification step of domain name // (from full qualified to TopLevel) for ( $i = 0; $i < $count - 1 && !$bSuccess; $i = $i + 1 ) { - + // create the domain name $domain = ""; for ( $j = $i; $j < $count; $j = $j + 1 ) { @@ -284,20 +284,20 @@ function validateEmail ( $email, $verbose=0 ) { $domain = $domain . "."; } if ( $verbose ) eval("echo \"Internal: checking DNS for $domain ... \"; $vNL"); - + // Strict Mail Check if($mail_check == "strict") { // check that an MX record exists for Top-Level domain // If it exists, start our email address checking - if (function_exists('checkdnsrr')) { + if (function_exists('checkdnsrr')) { if ( checkdnsrr ( $domain, "MX" ) ) { - + // Okay -- we've got a valid DNS reverse record. if ( $verbose ) eval("echo \"Internal: ... Check DNS RR OK!\"; $vNL"); // Test that MX record for host exists, // then fill 'mxhosts' and 'weight' arrays with correct info if ( getmxrr ( $domain, $mxhosts, $weight ) ) { - + // Now we've got MX records if ( $verbose ) { eval("echo \"Internal: MX LOOKUP RESULTS:\"; $vNL"); @@ -311,18 +311,18 @@ function validateEmail ( $email, $verbose=0 ) { // determine our MX host cutoff $mxstop = ($mxcount > $mxcutoff) ? $mxcutoff : $mxcount; for ( $i = 0; $i < $mxstop ; $i++ ) { - + // open socket on port 25 to mxhost, setting // returned socket pointer to $sp if( $verbose ) eval("echo \"Internal: attempting to open $mxhosts[$i] ...\"; $vNL"); $sp = fsockopen ( $mxhosts[$i], 25, $errno, $errstr, $socketTimeout); - + // Greeting Code default // Sets default greeting code to 421, just in case we // don't ever hear ANYTHING from this host. // If we hear nothing, we'll want to skip it. $greetCode = "421"; - + // if $sp connection is good, let's rock on if ( $sp ) { if ( $verbose ) { @@ -334,17 +334,17 @@ function validateEmail ( $email, $verbose=0 ) { $msec = 0; // milisec count $tsec = 0; // tensec count $out = ""; - + // set our created socket for $sp to // non-blocking mode so that our fgets() // calls will return with a quickness set_socket_blocking ( $sp, false ); - + // as long as our 'out' variable does not begin // with a valid SMTP greeting (220 or 421), // keep looping (do) until we get something do { - + // prepare for clean debug output if necessary // (puts a line break after the waitMarkers) if ( $verbose && $msec > 0 ) { @@ -354,7 +354,7 @@ function validateEmail ( $email, $verbose=0 ) { // output of the stream assigned to // 'out' variable $out = fgets ( $sp, 2500 ); - + // Check for multi-line output (###-) if ( preg_match ( "/^2..-/", $out ) ) { $end = false; @@ -369,9 +369,9 @@ function validateEmail ( $email, $verbose=0 ) { } } } - + if ( $verbose && $out != "" ) eval("$clean echo \"Server: ".AddSlashes($out)."\"; $vNL"); - + // if we get a "220" code (service ready), // we're ready to rock on if ( substr ( $out, 0, 3 ) == "220" ) { @@ -384,25 +384,25 @@ function validateEmail ( $email, $verbose=0 ) { } else { $send = "HELO"; } - + // Set Greeting Code $greetCode = "220"; - + } - + // else if ... // Perhaps we've gotten a 421 Temporarily Refused error else if ( substr ( $out, 0, 3 ) == "421" ) { - + //if ( $verbose ) echo " ... moving on\n"; if ( $verbose ) eval("echo \"Internal: $mxhosts[$i] temporarily rejected connection. (421 response)\"; $vNL"); $return[2] = false; // Set Greeting Code $greetCode = "421"; break; // get out of this loop - + } - + // increase our waitTimeout counters // if we still haven't heard anything ... // Note that the time looping isn't an exact science @@ -426,34 +426,34 @@ function validateEmail ( $email, $verbose=0 ) { } $msec = $msec + 0.25; usleep(250000); - + } elseif ( $msec == $waitTimeout ) { - + // let's get out of here. Toooo sloooooww ... if ( $verbose ) eval("$clean echo \"Internal: !! we've waited $waitTimeout seconds !!\nbreaking ...\"; $vNL"); break; } - - + + // end of 'do' loop } while ( substr ( $out, 0, 3 ) != "220" ); - + // Make sure we got a "220" greetCode // before we start shoveling requests // at this server. if ( $greetCode == "220" ) { - + // reset our file pointer to blocking mode, // so we can wait for communication to finish // before moving on ... set_socket_blocking ( $sp, true ); - + // talk to the MX mail server, attempt to validate // ourself. Use "HELO" or "EHLO", as determined above fputs ( $sp, "$send $serverName"."$CRLF" ); if ( $verbose ) eval("echo \"Client: $send $serverName\"; $vNL"); - + // get the mail server's reply, check it // $originalOutput = fgets ( $sp, 2500 ); @@ -472,12 +472,12 @@ function validateEmail ( $email, $verbose=0 ) { } } if ( $verbose ) eval("echo \"Server: ".AddSlashes($originalOutput)."\"; $vNL"); - - + + // if there's a HELP option, let's see it if ( $verbose ) { if( preg_match( "/250.HELP/m", $originalOutput ) && $verbose == true ) { - + eval("echo \"Internal: VERBOSE-MODE ONLY: Getting the HELP output\"; $vNL"); // Get the output of the HELP command fputs ( $sp, "HELP"."$CRLF" ); @@ -499,14 +499,14 @@ function validateEmail ( $email, $verbose=0 ) { } } if ( $verbose ) eval("echo \"Server: ".AddSlashes($output)."\"; $vNL"); - + } } - + // Give the MAIL FROM: header to the server fputs ( $sp, "MAIL FROM: <$from" . "@" . "$serverName" . ">"."$CRLF"); if ( $verbose ) eval("echo \"Client: MAIL FROM: $leftCarrot"."$from" . "@" . "$serverName" . "$rightCarrot\"; $vNL"); - + // Get output again $output = fgets ( $sp, 2500 ); // Check for multi-line positive output @@ -524,11 +524,11 @@ function validateEmail ( $email, $verbose=0 ) { } } if ( $verbose ) eval("echo \"Server: ".AddSlashes($output)."\"; $vNL"); - + // Give the RCPT TO: header for the email address we're testing fputs ( $sp, "RCPT TO: <$email>"."$CRLF" ); if ( $verbose ) eval("echo \"Client: RCPT TO: $leftCarrot"."$email"."$rightCarrot\"; $vNL"); - + // Get output again // This will be the one we check for validity $output = fgets ( $sp, 2500 ); @@ -547,19 +547,19 @@ function validateEmail ( $email, $verbose=0 ) { } } if ( $verbose ) eval("echo \"Server: ".AddSlashes($output)."\"; $vNL"); - + // test the last reply code from the mail server // for the 250 (okay) response if ( substr ( $output, 0, 3 ) == "250" ) { - + // set our true/false(ness) // array item for testing $return[0] = true; $return[1] = $output; if ( $verbose ) eval("echo \"Internal: Check for 250 ... Recipient OK\"; $vNL"); - + } else { - + // we didn't get a 250 // may be a bogus address if ( $verbose ) eval("echo \"Internal: Check for 250 ... Response did not begin with 250!\"; $vNL"); @@ -567,19 +567,19 @@ function validateEmail ( $email, $verbose=0 ) { // reply for user to test if they want $return[0] = false; $return[1] = $output; - + } - + // tell the mail server we're done fputs ( $sp, "QUIT"."$CRLF" ); if ( $verbose ) { eval("echo \"Client: QUIT\"; $vNL"); - eval("echo \"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\"; $vNL $vNL"); + eval("echo \"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\"; $vNL $vNL"); } - + // close the socket/file pointer fclose ( $sp ); - + // If we got a good response back on RCPT TO, // break here // Otherwise, keep trying MX servers until we @@ -588,36 +588,36 @@ function validateEmail ( $email, $verbose=0 ) { if ( $return[0] == true ) { if ( $verbose ) { eval("echo \"Internal: Recipient is OK - thanks, $mxhosts[$i]!\"; $vNL"); - eval("echo \"Internal: Stop checking MX hosts ...\"; $vNL"); + eval("echo \"Internal: Stop checking MX hosts ...\"; $vNL"); } $bSuccess = true; break; } - + } else { - + // greetCode wasn't "220" // we better skip this one and move on if ( $verbose ) eval("echo \"Internal: SKIPPING $mxhosts[$i] -- never got 220 welcome\"; $vNL"); // close out this connection fclose ( $sp ); - + } // end of greetCode check - + } else { // $sp socket pointer was false -- couldn't open it if ( $verbose ) { - eval("echo \"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\"; $vNL"); + eval("echo \"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\"; $vNL"); eval("echo \"Internal: could not open socket to $mxhosts[$i]!\"; $vNL"); eval("echo \"fsockopen error $errno: $errstr\"; $vNL"); - eval("echo \"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\"; $vNL $vNL"); + eval("echo \"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\"; $vNL $vNL"); } $return[0] = false; $return[1] = "fsockopen error $errno: $errstr"; } // end of $sp check - + } // end for $mxhosts - + } // getmxrr test else { // getmxrr failed @@ -625,7 +625,7 @@ function validateEmail ( $email, $verbose=0 ) { $return[0] = false; $return[1] = "554 No MX records found for $domain"; } // end getmxrr test - + } // continue checkdnsrr test else { if ( $verbose ) eval("echo \"Internal: No DNS Reverse Record available!\"; $vNL"); @@ -649,9 +649,9 @@ function validateEmail ( $email, $verbose=0 ) { } } // end walking through each domain possibility - + } // end isValid - + // output elapsed time if Verbose if ( $verbose ) { list ( $msecStop, $secStop ) = explode ( " ", microtime() ); @@ -660,7 +660,7 @@ function validateEmail ( $email, $verbose=0 ) { eval("echo \"Internal: VERBOSE-MODE execution time: $elapsedTime seconds (silent mode somewhat faster)\"; $vNL"); if ( $sapi_type != "cgi" ) echo "</pre>"; } - + // return the array for the user to test against return $return; diff --git a/modules/validatemail/validateEmailFormat.php b/modules/validatemail/validateEmailFormat.php index 94fde197..14ff9cff 100644 --- a/modules/validatemail/validateEmailFormat.php +++ b/modules/validatemail/validateEmailFormat.php @@ -87,7 +87,7 @@ function validateEmailFormat ( $email ) { // Impossible to do properly with a regex, I make do by allowing at most // one level of nesting. $ctext = " [^$esc$NonASCII$CRlist()] "; - + // $Cnested matches one non-nested comment. // It is unrolled, with normal of $ctext, special of $quoted_pair. $Cnested = ""; @@ -95,7 +95,7 @@ function validateEmailFormat ( $email ) { $Cnested .= "$ctext*"; // normal* $Cnested .= "(?: $quoted_pair $ctext* )*"; // (special normal*)* $Cnested .= "$CloseParen"; // ) - + // $comment allows one level of nested parentheses // It is unrolled, with normal of $ctext, special of ($quoted_pair|$Cnested) $comment = ""; @@ -106,29 +106,29 @@ function validateEmailFormat ( $email ) { $comment .= "$ctext*"; // normal* $comment .= ")*"; // )* $comment .= "$CloseParen"; // ) - + // ********************************************* // $X is optional whitespace/comments $X = ""; $X .= "[$space$tab]*"; // Nab whitespace $X .= "(?: $comment [$space$tab]* )*"; // If comment found, allow more spaces - - + + // Item 10: atom $atom_char = "[^($space)<>\@,;:\".$esc$OpenBR$CloseBR$ctrl$NonASCII]"; $atom = ""; $atom .= "$atom_char+"; // some number of atom characters ... $atom .= "(?!$atom_char)"; // ... not followed by something that // could be part of an atom - + // Item 11: doublequoted string, unrolled. $quoted_str = ""; $quoted_str .= "\""; // " $quoted_str .= "$qtext *"; // normal $quoted_str .= "(?: $quoted_pair $qtext * )*"; // ( special normal* )* $quoted_str .= "\""; // " - - + + // Item 7: word is an atom or quoted string $word = ""; $word .= "(?:"; @@ -136,10 +136,10 @@ function validateEmailFormat ( $email ) { $word .= "|"; // or $word .= "$quoted_str"; // Quoted string $word .= ")"; - + // Item 12: domain-ref is just an atom $domain_ref = $atom; - + // Item 13: domain-literal is like a quoted string, but [...] instead of "..." $domain_lit = ""; $domain_lit .= "$OpenBR"; // [ @@ -154,28 +154,28 @@ function validateEmailFormat ( $email ) { $sub_domain .= "$domain_lit"; $sub_domain .= ")"; $sub_domain .= "$X"; // optional trailing comments - + // Item 6: domain is a list of subdomains separated by dots $domain = ""; $domain .= "$sub_domain"; $domain .= "(?:"; $domain .= "$Period $X $sub_domain"; $domain .= ")*"; - + // Item 8: a route. A bunch of "@ $domain" separated by commas, followed by a colon. $route = ""; $route .= "\@ $X $domain"; $route .= "(?: , $X \@ $X $domain )*"; // additional domains $route .= ":"; $route .= "$X"; // optional trailing comments - + // Item 5: local-part is a bunch of $word separated by periods $local_part = ""; $local_part .= "$word $X"; $local_part .= "(?:"; $local_part .= "$Period $X $word $X"; // additional words $local_part .= ")*"; - + // Item 2: addr-spec is local@domain $addr_spec = "$local_part \@ $X $domain"; @@ -185,10 +185,10 @@ function validateEmailFormat ( $email ) { $route_addr .= "(?: $route )?"; // optional route $route_addr .= "$addr_spec"; // address spec $route_addr .= ">"; - + // Item 3: phrase........ $phrase_ctrl = '\000-\010\012-\037'; // like ctrl, but without tab - + // Like atom-char, but without listing space, and uses phrase_ctrl. // Since the class is negated, this matches the same as atom-char plus space and tab $phrase_char = "[^()<>\@,;:\".$esc$OpenBR$CloseBR$NonASCII$phrase_ctrl]"; @@ -214,7 +214,7 @@ function validateEmailFormat ( $email ) { // test it and return results $isValid = preg_match("/^$mailbox$/xS",$email); - + return($isValid); } // END validateEmailFormat ?> |