Back to index

php5  5.3.10
Static Public Member Functions | Public Attributes | Static Public Attributes
Extract_Phar Class Reference

List of all members.

Static Public Member Functions

static go ($return=false)
static tmpdir ()
static _unpack ($m)
static extractFile ($path, $entry, $fp)
static _removeTmpFiles ($temp, $origdir)

Public Attributes

const GZ = 0x1000
const BZ2 = 0x2000
const MASK = 0x3000
const START = 'index.php'
const LEN = XXXX

Static Public Attributes

static $temp
static $origdir

Detailed Description

Definition at line 103 of file shortarc.php.


Member Function Documentation

static Extract_Phar::_removeTmpFiles ( temp,
origdir 
) [static]

Definition at line 278 of file shortarc.php.

    {
        chdir($temp);

        foreach (glob('*') as $f) {
            if (file_exists($f)) {
                is_dir($f) ? @rmdir($f) : @unlink($f);
                if (file_exists($f) && is_dir($f)) {
                    self::_removeTmpFiles($f, getcwd());
                }
            }
        }

        @rmdir($temp);
        clearstatcache();
        chdir($origdir);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static Extract_Phar::_unpack ( m) [static]

Definition at line 213 of file shortarc.php.

    {
        $info = unpack('V', substr($m, 0, 4));
        // skip API version, phar flags, alias, metadata
        $l = unpack('V', substr($m, 10, 4));
        $m = substr($m, 14 + $l[1]);
        $s = unpack('V', substr($m, 0, 4));
        $o = 0;
        $start = 4 + $s[1];
        $ret['c'] = 0;

        for ($i = 0; $i < $info[1]; $i++) {
            // length of the file name
            $len = unpack('V', substr($m, $start, 4));
            $start += 4;
            // file name
            $savepath = substr($m, $start, $len[1]);
            $start += $len[1];
            // retrieve manifest data:
            // 0 = size, 1 = timestamp, 2 = compressed size, 3 = crc32, 4 = flags
            // 5 = metadata length
            $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
            $ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
                & 0xffffffff);
            $ret['m'][$savepath][7] = $o;
            $o += $ret['m'][$savepath][2];
            $start += 24 + $ret['m'][$savepath][5];
            $ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
        }
        return $ret;
    }

Here is the caller graph for this function:

static Extract_Phar::extractFile ( path,
entry,
fp 
) [static]

Definition at line 245 of file shortarc.php.

    {
        $data = '';
        $c = $entry[2];

        while ($c) {
            if ($c < 8192) {
                $data .= @fread($fp, $c);
                $c = 0;
            } else {
                $c -= 8192;
                $data .= @fread($fp, 8192);
            }
        }

        if ($entry[4] & self::GZ) {
            $data = gzinflate($data);
        } elseif ($entry[4] & self::BZ2) {
            $data = bzdecompress($data);
        }

        if (strlen($data) != $entry[0]) {
            die("Invalid internal .phar file (size error " . strlen($data) . " != " .
                $stat[7] . ")");
        }

        if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
            die("Invalid internal .phar file (checksum error)");
        }

        return $data;
    }
static Extract_Phar::go ( return = false) [static]

Definition at line 113 of file shortarc.php.

    {
        $fp = fopen(__FILE__, 'rb');
        fseek($fp, self::LEN);
        $L = unpack('V', $a = (binary)fread($fp, 4));
        $m = (binary)'';

        do {
            $read = 8192;
            if ($L[1] - strlen($m) < 8192) {
                $read = $L[1] - strlen($m);
            }
            $last = (binary)fread($fp, $read);
            $m .= $last;
        } while (strlen($last) && strlen($m) < $L[1]);

        if (strlen($m) < $L[1]) {
            die('ERROR: manifest length read was "' . 
                strlen($m) .'" should be "' .
                $L[1] . '"');
        }

        $info = self::_unpack($m);
        $f = $info['c'];

        if ($f & self::GZ) {
            if (!function_exists('gzinflate')) {
                die('Error: zlib extension is not enabled -' .
                    ' gzinflate() function needed for zlib-compressed .phars');
            }
        }

        if ($f & self::BZ2) {
            if (!function_exists('bzdecompress')) {
                die('Error: bzip2 extension is not enabled -' .
                    ' bzdecompress() function needed for bz2-compressed .phars');
            }
        }

        $temp = self::tmpdir();

        if (!$temp || !is_writable($temp)) {
            $sessionpath = session_save_path();
            if (strpos ($sessionpath, ";") !== false)
                $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
            if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
                die('Could not locate temporary directory to extract phar');
            }
            $temp = $sessionpath;
        }

        $temp .= '/pharextract/'.basename(__FILE__, '.phar');
        self::$temp = $temp;
        self::$origdir = getcwd();
        @mkdir($temp, 0777, true);
        $temp = realpath($temp);

        if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
            self::_removeTmpFiles($temp, getcwd());
            @mkdir($temp, 0777, true);
            @file_put_contents($temp . '/' . md5_file(__FILE__), '');

            foreach ($info['m'] as $path => $file) {
                $a = !file_exists(dirname($temp . '/' . $path));
                @mkdir(dirname($temp . '/' . $path), 0777, true);
                clearstatcache();

                if ($path[strlen($path) - 1] == '/') {
                    @mkdir($temp . '/' . $path, 0777);
                } else {
                    file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
                    @chmod($temp . '/' . $path, 0666);
                }
            }
        }

        chdir($temp);

        if (!$return) {
            include self::START;
        }
    }

Here is the call graph for this function:

static Extract_Phar::tmpdir ( ) [static]

Definition at line 196 of file shortarc.php.

    {
        if (strpos(PHP_OS, 'WIN') !== false) {
            if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
                return $var;
            }
            if (is_dir('/temp') || mkdir('/temp')) {
                return realpath('/temp');
            }
            return false;
        }
        if ($var = getenv('TMPDIR')) {
            return $var;
        }
        return realpath('/tmp');
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 106 of file shortarc.php.

Definition at line 105 of file shortarc.php.

const Extract_Phar::BZ2 = 0x2000

Definition at line 108 of file shortarc.php.

const Extract_Phar::GZ = 0x1000

Definition at line 107 of file shortarc.php.

const Extract_Phar::LEN = XXXX

Definition at line 111 of file shortarc.php.

const Extract_Phar::MASK = 0x3000

Definition at line 109 of file shortarc.php.

const Extract_Phar::START = 'index.php'

Definition at line 110 of file shortarc.php.


The documentation for this class was generated from the following file: