⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ole.php

📁 完美的在线教育系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
    * creates an OLE_PPS object for each one.    *    * @access private    * @param integer $blockId the block id of the first block    * @return mixed true on success, PEAR_Error on failure    */    function _readPpsWks($blockId)    {        $fh = $this->getStream($blockId);        for ($pos = 0; ; $pos += 128) {            fseek($fh, $pos, SEEK_SET);            $nameUtf16 = fread($fh, 64);            $nameLength = $this->_readInt2($fh);            $nameUtf16 = substr($nameUtf16, 0, $nameLength - 2);            // Simple conversion from UTF-16LE to ISO-8859-1            $name = str_replace("\x00", "", $nameUtf16);            $type = $this->_readInt1($fh);            switch ($type) {            case OLE_PPS_TYPE_ROOT:                require_once 'OLE/PPS/Root.php';                $pps = new OLE_PPS_Root(null, null, array());                $this->root = $pps;                break;            case OLE_PPS_TYPE_DIR:                $pps = new OLE_PPS(null, null, null, null, null,                                   null, null, null, null, array());                break;            case OLE_PPS_TYPE_FILE:                require_once 'OLE/PPS/File.php';                $pps = new OLE_PPS_File($name);                break;            default:                continue;            }            fseek($fh, 1, SEEK_CUR);            $pps->Type    = $type;            $pps->Name    = $name;            $pps->PrevPps = $this->_readInt4($fh);            $pps->NextPps = $this->_readInt4($fh);            $pps->DirPps  = $this->_readInt4($fh);            fseek($fh, 20, SEEK_CUR);            $pps->Time1st = OLE::OLE2LocalDate(fread($fh, 8));            $pps->Time2nd = OLE::OLE2LocalDate(fread($fh, 8));            $pps->_StartBlock = $this->_readInt4($fh);            $pps->Size = $this->_readInt4($fh);            $pps->No = count($this->_list);            $this->_list[] = $pps;            // check if the PPS tree (starting from root) is complete            if (isset($this->root) &&                $this->_ppsTreeComplete($this->root->No)) {                break;            }        }        fclose($fh);        // Initialize $pps->children on directories        foreach ($this->_list as $pps) {            if ($pps->Type == OLE_PPS_TYPE_DIR || $pps->Type == OLE_PPS_TYPE_ROOT) {                $nos = array($pps->DirPps);                $pps->children = array();                while ($nos) {                    $no = array_pop($nos);                    if ($no != -1) {                        $childPps = $this->_list[$no];                        $nos[] = $childPps->PrevPps;                        $nos[] = $childPps->NextPps;                        $pps->children[] = $childPps;                    }                }            }        }        return true;    }    /**    * It checks whether the PPS tree is complete (all PPS's read)    * starting with the given PPS (not necessarily root)    *    * @access private    * @param integer $index The index of the PPS from which we are checking    * @return boolean Whether the PPS tree for the given PPS is complete    */    function _ppsTreeComplete($index)    {        return isset($this->_list[$index]) &&               ($pps = $this->_list[$index]) &&               ($pps->PrevPps == -1 ||                $this->_ppsTreeComplete($pps->PrevPps)) &&               ($pps->NextPps == -1 ||                $this->_ppsTreeComplete($pps->NextPps)) &&               ($pps->DirPps == -1 ||                $this->_ppsTreeComplete($pps->DirPps));    }    /**     * Checks whether a PPS is a File PPS or not.    * If there is no PPS for the index given, it will return false.    * @param integer $index The index for the PPS    * @return bool true if it's a File PPS, false otherwise    * @access public    */    function isFile($index)    {        if (isset($this->_list[$index])) {            return ($this->_list[$index]->Type == OLE_PPS_TYPE_FILE);        }        return false;    }    /**     * Checks whether a PPS is a Root PPS or not.    * If there is no PPS for the index given, it will return false.    * @param integer $index The index for the PPS.    * @return bool true if it's a Root PPS, false otherwise    * @access public    */    function isRoot($index)    {        if (isset($this->_list[$index])) {            return ($this->_list[$index]->Type == OLE_PPS_TYPE_ROOT);        }        return false;    }    /**     * Gives the total number of PPS's found in the OLE container.    * @return integer The total number of PPS's found in the OLE container    * @access public    */    function ppsTotal()    {        return count($this->_list);    }    /**    * Gets data from a PPS    * If there is no PPS for the index given, it will return an empty string.    * @param integer $index    The index for the PPS    * @param integer $position The position from which to start reading    *                          (relative to the PPS)    * @param integer $length   The amount of bytes to read (at most)    * @return string The binary string containing the data requested    * @access public    * @see OLE_PPS_File::getStream()    */    function getData($index, $position, $length)    {        // if position is not valid return empty string        if (!isset($this->_list[$index]) ||            $position >= $this->_list[$index]->Size ||            $position < 0) {            return '';        }        $fh = $this->getStream($this->_list[$index]);        $data = stream_get_contents($fh, $length, $position);        fclose($fh);        return $data;    }    /**    * Gets the data length from a PPS    * If there is no PPS for the index given, it will return 0.    * @param integer $index The index for the PPS    * @return integer The amount of bytes in data the PPS has    * @access public    */    function getDataLength($index)    {        if (isset($this->_list[$index])) {            return $this->_list[$index]->Size;        }        return 0;    }    /**    * Utility function to transform ASCII text to Unicode    *    * @access public    * @static    * @param string $ascii The ASCII string to transform    * @return string The string in Unicode    */    function Asc2Ucs($ascii)    {        $rawname = '';        for ($i = 0; $i < strlen($ascii); $i++) {            $rawname .= $ascii{$i} . "\x00";        }        return $rawname;    }    /**    * Utility function    * Returns a string for the OLE container with the date given    *    * @access public    * @static    * @param integer $date A timestamp     * @return string The string for the OLE container    */    function LocalDate2OLE($date = null)    {        if (!isset($date)) {            return "\x00\x00\x00\x00\x00\x00\x00\x00";        }        // factor used for separating numbers into 4 bytes parts        $factor = pow(2, 32);        // days from 1-1-1601 until the beggining of UNIX era        $days = 134774;        // calculate seconds        $big_date = $days * 24 * 3600 +            gmmktime(date("H",$date),date("i",$date),date("s",$date),                     date("m",$date),date("d",$date),date("Y",$date));        // multiply just to make MS happy        $big_date *= 10000000;        $high_part = floor($big_date / $factor);        // lower 4 bytes        $low_part = floor((($big_date / $factor) - $high_part) * $factor);        // Make HEX string        $res = '';        for ($i = 0; $i < 4; $i++) {            $hex = $low_part % 0x100;            $res .= pack('c', $hex);            $low_part /= 0x100;        }        for ($i = 0; $i < 4; $i++) {            $hex = $high_part % 0x100;            $res .= pack('c', $hex);            $high_part /= 0x100;        }        return $res;    }    /**    * Returns a timestamp from an OLE container's date    * @param integer $string A binary string with the encoded date    * @return string The timestamp corresponding to the string    * @access public    * @static    */    function OLE2LocalDate($string)    {        if (strlen($string) != 8) {            return new PEAR_Error("Expecting 8 byte string");        }        // factor used for separating numbers into 4 bytes parts        $factor = pow(2,32);        $high_part = 0;        for ($i = 0; $i < 4; $i++) {            list(, $high_part) = unpack('C', $string{(7 - $i)});            if ($i < 3) {                $high_part *= 0x100;            }        }        $low_part = 0;        for ($i = 4; $i < 8; $i++) {            list(, $low_part) = unpack('C', $string{(7 - $i)});            if ($i < 7) {                $low_part *= 0x100;            }        }        $big_date = ($high_part * $factor) + $low_part;        // translate to seconds        $big_date /= 10000000;                // days from 1-1-1601 until the beggining of UNIX era        $days = 134774;                // translate to seconds from beggining of UNIX era        $big_date -= $days * 24 * 3600;        return floor($big_date);    }}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -