Mercurial > judyates
view e2gallerypro/e2upload/Backend/Assets/getid3/module.archive.tar.php @ 11:ed6ee381b8fd judyates
[svn r12] compressed photos and assembled them into a working web gallery
author | rlm |
---|---|
date | Mon, 12 Apr 2010 02:31:43 -0400 |
parents | 3f6b44aa6b35 |
children |
line wrap: on
line source
1 <?php2 // +----------------------------------------------------------------------+3 // | PHP version 5 |4 // +----------------------------------------------------------------------+5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |6 // +----------------------------------------------------------------------+7 // | This source file is subject to version 2 of the GPL license, |8 // | that is bundled with this package in the file license.txt and is |9 // | available through the world-wide-web at the following url: |10 // | http://www.gnu.org/copyleft/gpl.html |11 // +----------------------------------------------------------------------+12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |13 // +----------------------------------------------------------------------+14 // | Authors: James Heinrich <infoØgetid3*org> |15 // | Allan Hansen <ahØartemis*dk> |16 // +----------------------------------------------------------------------+17 // | module.archive.tar.php |18 // | module for analyzing TAR files |19 // | dependencies: NONE |20 // +----------------------------------------------------------------------+21 // | Module originally written by Mike Mozolin <teddybearØmail*ru> |22 // +----------------------------------------------------------------------+23 //24 // $Id: module.archive.tar.php,v 1.2 2006/11/02 10:48:00 ah Exp $28 class getid3_tar extends getid3_handler29 {31 function Analyze() {33 $info = &$this->getid3->info;35 $info['fileformat'] = 'tar';37 $fp = $this->getid3->fp;39 fseek($fp, 0);41 $unpack_header = 'a100fname/a8mode/a8uid/a8gid/a12size/a12mtime/a8chksum/a1typflag/a100lnkname/a6magic/a2ver/a32uname/a32gname/a8devmaj/a8devmin/a155/prefix';43 $null_512k = str_repeat("\0", 512); // end-of-file marker45 $already_warned = false;47 while (!feof($fp)) {49 $buffer = fread($fp, 512);51 // check the block52 $checksum = 0;53 for ($i = 0; $i < 148; $i++) {54 $checksum += ord(substr($buffer, $i, 1));55 }56 for ($i = 148; $i < 156; $i++) {57 $checksum += ord(' ');58 }59 for ($i = 156; $i < 512; $i++) {60 $checksum += ord(substr($buffer, $i, 1));61 }62 $attr = unpack($unpack_header, $buffer);63 $name = trim(@$attr['fname']);64 $mode = octdec(trim(@$attr['mode']));65 $uid = octdec(trim(@$attr['uid']));66 $gid = octdec(trim(@$attr['gid']));67 $size = octdec(trim(@$attr['size']));68 $mtime = octdec(trim(@$attr['mtime']));69 $chksum = octdec(trim(@$attr['chksum']));70 $typflag = trim(@$attr['typflag']);71 $lnkname = trim(@$attr['lnkname']);72 $magic = trim(@$attr['magic']);73 $ver = trim(@$attr['ver']);74 $uname = trim(@$attr['uname']);75 $gname = trim(@$attr['gname']);76 $devmaj = octdec(trim(@$attr['devmaj']));77 $devmin = octdec(trim(@$attr['devmin']));78 $prefix = trim(@$attr['prefix']);80 // EOF Found81 if (($checksum == 256) && ($chksum == 0)) {82 break;83 }85 // Check if filename if 7bit as spec requires86 if (!$already_warned) {87 for ($i = 0; $i < strlen($name); $i++) {88 if ($name{$i} < chr(32) || $name{$i} > chr(127)) {89 $this->getid3->warning('Some filenames contains extended characters, which breaks the tar specifation. This is not uncommon, but you will have to handle the character encoding for filenames yourself.');90 $already_warned = true;91 break;92 }93 }94 }96 if ($prefix) {97 $name = $prefix.'/'.$name;98 }99 if ((preg_match('#/$#', $name)) && !$name) {100 $typeflag = 5;101 }103 // If it's the end of the tar-file...104 if ($buffer == $null_512k) {105 break;106 }108 // Protect against tar-files with garbage at the end109 if ($name == '') {110 break;111 }113 $info['tar']['file_details'][$name] = array (114 'name' => $name,115 'mode_raw' => $mode,116 'mode' => getid3_tar::display_perms($mode),117 'uid' => $uid,118 'gid' => $gid,119 'size' => $size,120 'mtime' => $mtime,121 'chksum' => $chksum,122 'typeflag' => getid3_tar::get_flag_type($typflag),123 'linkname' => $lnkname,124 'magic' => $magic,125 'version' => $ver,126 'uname' => $uname,127 'gname' => $gname,128 'devmajor' => $devmaj,129 'devminor' => $devmin130 );132 // Skip the next chunk133 fseek($fp, $size, SEEK_CUR);135 // Throw away padding136 if ($size % 512) {137 fseek($fp, 512 - $diff, SEEK_CUR);138 }140 }141 return true;142 }145 // Parses the file mode to file permissions146 public static function display_perms($mode) {148 // Determine Type149 if ($mode & 0x1000) {150 $type='p'; // FIFO pipe151 }152 elseif ($mode & 0x2000) {153 $type='c'; // Character special154 }155 elseif ($mode & 0x4000) {156 $type='d'; // Directory157 }158 elseif ($mode & 0x6000) {159 $type='b'; // Block special160 }161 elseif ($mode & 0x8000) {162 $type='-'; // Regular163 }164 elseif ($mode & 0xA000) {165 $type='l'; // Symbolic Link166 }167 elseif ($mode & 0xC000) {168 $type='s'; // Socket169 }170 else {171 $type='u'; // UNKNOWN172 }174 // Determine permissions175 $owner['read'] = (($mode & 00400) ? 'r' : '-');176 $owner['write'] = (($mode & 00200) ? 'w' : '-');177 $owner['execute'] = (($mode & 00100) ? 'x' : '-');178 $group['read'] = (($mode & 00040) ? 'r' : '-');179 $group['write'] = (($mode & 00020) ? 'w' : '-');180 $group['execute'] = (($mode & 00010) ? 'x' : '-');181 $world['read'] = (($mode & 00004) ? 'r' : '-');182 $world['write'] = (($mode & 00002) ? 'w' : '-');183 $world['execute'] = (($mode & 00001) ? 'x' : '-');185 // Adjust for SUID, SGID and sticky bit186 if ($mode & 0x800) {187 $owner['execute'] = ($owner['execute'] == 'x') ? 's' : 'S';188 }189 if ($mode & 0x400) {190 $group['execute'] = ($group['execute'] == 'x') ? 's' : 'S';191 }192 if ($mode & 0x200) {193 $world['execute'] = ($world['execute'] == 'x') ? 't' : 'T';194 }196 $s = sprintf('%1s', $type);197 $s .= sprintf('%1s%1s%1s', $owner['read'], $owner['write'], $owner['execute']);198 $s .= sprintf('%1s%1s%1s', $group['read'], $group['write'], $group['execute']);199 $s .= sprintf('%1s%1s%1s'."\n", $world['read'], $world['write'], $world['execute']);201 return $s;202 }205 // Converts the file type206 public static function get_flag_type($typflag) {208 static $flag_types = array (209 '0' => 'LF_NORMAL',210 '1' => 'LF_LINK',211 '2' => 'LF_SYNLINK',212 '3' => 'LF_CHR',213 '4' => 'LF_BLK',214 '5' => 'LF_DIR',215 '6' => 'LF_FIFO',216 '7' => 'LF_CONFIG',217 'D' => 'LF_DUMPDIR',218 'K' => 'LF_LONGLINK',219 'L' => 'LF_LONGNAME',220 'M' => 'LF_MULTIVOL',221 'N' => 'LF_NAMES',222 'S' => 'LF_SPARSE',223 'V' => 'LF_VOLHDR'224 );226 return @$flag_types[$typflag];227 }229 }231 ?>