diff e2gallerypro/e2upload/Backend/Assets/getid3/module.archive.tar.php @ 3:3f6b44aa6b35 judyates

[svn r4] added ability to buy stuff, from a Prints page, but it doesn't work well with the css, and it also has not been fitted into the perl make system.
author rlm
date Mon, 22 Feb 2010 08:02:39 -0500
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/e2gallerypro/e2upload/Backend/Assets/getid3/module.archive.tar.php	Mon Feb 22 08:02:39 2010 -0500
     1.3 @@ -0,0 +1,231 @@
     1.4 +<?php
     1.5 +// +----------------------------------------------------------------------+
     1.6 +// | PHP version 5                                                        |
     1.7 +// +----------------------------------------------------------------------+
     1.8 +// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen                 |
     1.9 +// +----------------------------------------------------------------------+
    1.10 +// | This source file is subject to version 2 of the GPL license,         |
    1.11 +// | that is bundled with this package in the file license.txt and is     |
    1.12 +// | available through the world-wide-web at the following url:           |
    1.13 +// | http://www.gnu.org/copyleft/gpl.html                                 |
    1.14 +// +----------------------------------------------------------------------+
    1.15 +// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org    |
    1.16 +// +----------------------------------------------------------------------+
    1.17 +// | Authors: James Heinrich <infoØgetid3*org>                            |
    1.18 +// |          Allan Hansen <ahØartemis*dk>                                |
    1.19 +// +----------------------------------------------------------------------+
    1.20 +// | module.archive.tar.php                                               |
    1.21 +// | module for analyzing TAR files                                       |
    1.22 +// | dependencies: NONE                                                   |
    1.23 +// +----------------------------------------------------------------------+
    1.24 +// | Module originally written by Mike Mozolin <teddybearØmail*ru>        |
    1.25 +// +----------------------------------------------------------------------+
    1.26 +//
    1.27 +// $Id: module.archive.tar.php,v 1.2 2006/11/02 10:48:00 ah Exp $
    1.28 +
    1.29 +        
    1.30 +        
    1.31 +class getid3_tar extends getid3_handler
    1.32 +{
    1.33 +
    1.34 +    function Analyze() {
    1.35 +
    1.36 +        $info = &$this->getid3->info;
    1.37 +
    1.38 +        $info['fileformat'] = 'tar';
    1.39 +
    1.40 +        $fp = $this->getid3->fp;
    1.41 +        
    1.42 +        fseek($fp, 0);
    1.43 +        
    1.44 +        $unpack_header = 'a100fname/a8mode/a8uid/a8gid/a12size/a12mtime/a8chksum/a1typflag/a100lnkname/a6magic/a2ver/a32uname/a32gname/a8devmaj/a8devmin/a155/prefix';
    1.45 +
    1.46 +        $null_512k = str_repeat("\0", 512); // end-of-file marker
    1.47 +
    1.48 +        $already_warned = false;
    1.49 +
    1.50 +        while (!feof($fp)) {
    1.51 +            
    1.52 +            $buffer = fread($fp, 512);
    1.53 +            
    1.54 +            // check the block
    1.55 +            $checksum = 0;
    1.56 +            for ($i = 0; $i < 148; $i++) {
    1.57 +                $checksum += ord(substr($buffer, $i, 1));
    1.58 +            }
    1.59 +            for ($i = 148; $i < 156; $i++) {
    1.60 +                $checksum += ord(' ');
    1.61 +            }
    1.62 +            for ($i = 156; $i < 512; $i++) {
    1.63 +                $checksum += ord(substr($buffer, $i, 1));
    1.64 +            }
    1.65 +            $attr    = unpack($unpack_header, $buffer);
    1.66 +            $name    =        trim(@$attr['fname']);
    1.67 +            $mode    = octdec(trim(@$attr['mode']));
    1.68 +            $uid     = octdec(trim(@$attr['uid']));
    1.69 +            $gid     = octdec(trim(@$attr['gid']));
    1.70 +            $size    = octdec(trim(@$attr['size']));
    1.71 +            $mtime   = octdec(trim(@$attr['mtime']));
    1.72 +            $chksum  = octdec(trim(@$attr['chksum']));
    1.73 +            $typflag =        trim(@$attr['typflag']);
    1.74 +            $lnkname =        trim(@$attr['lnkname']);
    1.75 +            $magic   =        trim(@$attr['magic']);
    1.76 +            $ver     =        trim(@$attr['ver']);
    1.77 +            $uname   =        trim(@$attr['uname']);
    1.78 +            $gname   =        trim(@$attr['gname']);
    1.79 +            $devmaj  = octdec(trim(@$attr['devmaj']));
    1.80 +            $devmin  = octdec(trim(@$attr['devmin']));
    1.81 +            $prefix  =        trim(@$attr['prefix']);
    1.82 +
    1.83 +            // EOF Found
    1.84 +            if (($checksum == 256) && ($chksum == 0)) {
    1.85 +                break;
    1.86 +            }
    1.87 +
    1.88 +            // Check if filename if 7bit as spec requires
    1.89 +            if (!$already_warned) {
    1.90 +                for ($i = 0; $i < strlen($name); $i++) {
    1.91 +                    if ($name{$i} < chr(32) || $name{$i} > chr(127)) {
    1.92 +                        $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.');
    1.93 +                        $already_warned = true;
    1.94 +                        break;
    1.95 +                    }
    1.96 +                }
    1.97 +            }
    1.98 +            
    1.99 +            if ($prefix) {
   1.100 +                $name = $prefix.'/'.$name;
   1.101 +            }
   1.102 +            if ((preg_match('#/$#', $name)) && !$name) {
   1.103 +                $typeflag = 5;
   1.104 +            }
   1.105 +            
   1.106 +            // If it's the end of the tar-file...
   1.107 +            if ($buffer == $null_512k) {
   1.108 +                break;
   1.109 +            }
   1.110 +            
   1.111 +            // Protect against tar-files with garbage at the end
   1.112 +            if ($name == '') {
   1.113 +                break;
   1.114 +            }
   1.115 +            
   1.116 +            $info['tar']['file_details'][$name] = array (
   1.117 +                'name'     => $name,
   1.118 +                'mode_raw' => $mode,
   1.119 +                'mode'     => getid3_tar::display_perms($mode),
   1.120 +                'uid'      => $uid,
   1.121 +                'gid'      => $gid,
   1.122 +                'size'     => $size,
   1.123 +                'mtime'    => $mtime,
   1.124 +                'chksum'   => $chksum,
   1.125 +                'typeflag' => getid3_tar::get_flag_type($typflag),
   1.126 +                'linkname' => $lnkname,
   1.127 +                'magic'    => $magic,
   1.128 +                'version'  => $ver,
   1.129 +                'uname'    => $uname,
   1.130 +                'gname'    => $gname,
   1.131 +                'devmajor' => $devmaj,
   1.132 +                'devminor' => $devmin
   1.133 +            );
   1.134 +            
   1.135 +            // Skip the next chunk
   1.136 +            fseek($fp, $size, SEEK_CUR);
   1.137 +
   1.138 +            // Throw away padding
   1.139 +            if ($size % 512) {
   1.140 +                fseek($fp, 512 - $diff, SEEK_CUR);
   1.141 +            }
   1.142 +            
   1.143 +        }
   1.144 +        return true;
   1.145 +    }
   1.146 +
   1.147 +
   1.148 +    // Parses the file mode to file permissions
   1.149 +    public static function display_perms($mode) {
   1.150 +
   1.151 +        // Determine Type
   1.152 +        if ($mode & 0x1000) {
   1.153 +            $type='p'; // FIFO pipe
   1.154 +        }
   1.155 +        elseif ($mode & 0x2000) {
   1.156 +            $type='c'; // Character special
   1.157 +        }
   1.158 +        elseif ($mode & 0x4000) {
   1.159 +            $type='d'; // Directory
   1.160 +        }
   1.161 +        elseif ($mode & 0x6000) {
   1.162 +            $type='b'; // Block special
   1.163 +        }
   1.164 +        elseif ($mode & 0x8000) {
   1.165 +            $type='-'; // Regular
   1.166 +        }
   1.167 +        elseif ($mode & 0xA000) {
   1.168 +            $type='l'; // Symbolic Link
   1.169 +        }
   1.170 +        elseif ($mode & 0xC000) {
   1.171 +            $type='s'; // Socket
   1.172 +        }
   1.173 +        else {
   1.174 +            $type='u'; // UNKNOWN
   1.175 +        }
   1.176 +
   1.177 +        // Determine permissions
   1.178 +        $owner['read']    = (($mode & 00400) ? 'r' : '-');
   1.179 +        $owner['write']   = (($mode & 00200) ? 'w' : '-');
   1.180 +        $owner['execute'] = (($mode & 00100) ? 'x' : '-');
   1.181 +        $group['read']    = (($mode & 00040) ? 'r' : '-');
   1.182 +        $group['write']   = (($mode & 00020) ? 'w' : '-');
   1.183 +        $group['execute'] = (($mode & 00010) ? 'x' : '-');
   1.184 +        $world['read']    = (($mode & 00004) ? 'r' : '-');
   1.185 +        $world['write']   = (($mode & 00002) ? 'w' : '-');
   1.186 +        $world['execute'] = (($mode & 00001) ? 'x' : '-');
   1.187 +
   1.188 +        // Adjust for SUID, SGID and sticky bit
   1.189 +        if ($mode & 0x800) {
   1.190 +            $owner['execute'] = ($owner['execute'] == 'x') ? 's' : 'S';
   1.191 +        }
   1.192 +        if ($mode & 0x400) {
   1.193 +            $group['execute'] = ($group['execute'] == 'x') ? 's' : 'S';
   1.194 +        }
   1.195 +        if ($mode & 0x200) {
   1.196 +            $world['execute'] = ($world['execute'] == 'x') ? 't' : 'T';
   1.197 +        }
   1.198 +
   1.199 +        $s  = sprintf('%1s', $type);
   1.200 +        $s .= sprintf('%1s%1s%1s',      $owner['read'], $owner['write'], $owner['execute']);
   1.201 +        $s .= sprintf('%1s%1s%1s',      $group['read'], $group['write'], $group['execute']);
   1.202 +        $s .= sprintf('%1s%1s%1s'."\n", $world['read'], $world['write'], $world['execute']);
   1.203 +
   1.204 +        return $s;
   1.205 +    }
   1.206 +
   1.207 +
   1.208 +    // Converts the file type
   1.209 +    public static function get_flag_type($typflag) {
   1.210 +
   1.211 +        static $flag_types = array (
   1.212 +            '0' => 'LF_NORMAL',
   1.213 +            '1' => 'LF_LINK',
   1.214 +            '2' => 'LF_SYNLINK',
   1.215 +            '3' => 'LF_CHR',
   1.216 +            '4' => 'LF_BLK',
   1.217 +            '5' => 'LF_DIR',
   1.218 +            '6' => 'LF_FIFO',
   1.219 +            '7' => 'LF_CONFIG',
   1.220 +            'D' => 'LF_DUMPDIR',
   1.221 +            'K' => 'LF_LONGLINK',
   1.222 +            'L' => 'LF_LONGNAME',
   1.223 +            'M' => 'LF_MULTIVOL',
   1.224 +            'N' => 'LF_NAMES',
   1.225 +            'S' => 'LF_SPARSE',
   1.226 +            'V' => 'LF_VOLHDR'
   1.227 +        );
   1.228 +
   1.229 +        return @$flag_types[$typflag];
   1.230 +    }
   1.231 +    
   1.232 +}
   1.233 +
   1.234 +?>
   1.235 \ No newline at end of file