mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Merging the updated Limesurvey 1.92+ branch of queXS to trunk
This commit is contained in:
@@ -1,412 +1,412 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Xavier Noguer <xnoguer@php.net> |
|
||||
// | Based on OLE::Storage_Lite by Kawai, Takanori |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: OLE.php,v 1.7 2003/08/21 15:15:40 xnoguer Exp $
|
||||
|
||||
|
||||
/**
|
||||
* Constants for OLE package
|
||||
*/
|
||||
define('OLE_PPS_TYPE_ROOT', 5);
|
||||
define('OLE_PPS_TYPE_DIR', 1);
|
||||
define('OLE_PPS_TYPE_FILE', 2);
|
||||
define('OLE_DATA_SIZE_SMALL', 0x1000);
|
||||
define('OLE_LONG_INT_SIZE', 4);
|
||||
define('OLE_PPS_SIZE', 0x80);
|
||||
|
||||
if (isset($_REQUEST['homedir'])) {die('You cannot start this script directly');}
|
||||
if (!isset($homedir)) die();
|
||||
require_once($homedir.'/classes/pear/PEAR.php');
|
||||
require_once $homedir.'/classes/pear/OLE/PPS.php';
|
||||
|
||||
/**
|
||||
* OLE package base class.
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@php.net>
|
||||
* @category Structures
|
||||
* @package OLE
|
||||
*/
|
||||
class OLE extends PEAR
|
||||
{
|
||||
/**
|
||||
* The file handle for reading an OLE container
|
||||
* @var resource
|
||||
*/
|
||||
var $_file_handle;
|
||||
|
||||
/**
|
||||
* Array of PPS's found on the OLE container
|
||||
* @var array
|
||||
*/
|
||||
var $_list;
|
||||
|
||||
/**
|
||||
* Creates a new OLE object
|
||||
* Remember to use ampersand when creating an OLE object ($my_ole =& new OLE();)
|
||||
* @access public
|
||||
*/
|
||||
function OLE()
|
||||
{
|
||||
$this->_list = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an OLE container from the contents of the file given.
|
||||
*
|
||||
* @acces public
|
||||
* @param string $file
|
||||
* @return mixed true on success, PEAR_Error on failure
|
||||
*/
|
||||
function read($file)
|
||||
{
|
||||
/* consider storing offsets as constants */
|
||||
$big_block_size_offset = 30;
|
||||
$iBdbCnt_offset = 44;
|
||||
$bd_start_offset = 68;
|
||||
|
||||
$fh = @fopen($file, "r");
|
||||
if ($fh == false) {
|
||||
return $this->raiseError("Can't open file $file");
|
||||
}
|
||||
$this->_file_handle = $fh;
|
||||
|
||||
/* begin reading OLE attributes */
|
||||
fseek($fh, 0);
|
||||
$signature = fread($fh, 8);
|
||||
if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) {
|
||||
return $this->raiseError("File doesn't seem to be an OLE container.");
|
||||
}
|
||||
fseek($fh, $big_block_size_offset);
|
||||
$packed_array = unpack("v", fread($fh, 2));
|
||||
$big_block_size = pow(2, $packed_array['']);
|
||||
|
||||
$packed_array = unpack("v", fread($fh, 2));
|
||||
$small_block_size = pow(2, $packed_array['']);
|
||||
$i1stBdL = ($big_block_size - 0x4C) / OLE_LONG_INT_SIZE;
|
||||
|
||||
fseek($fh, $iBdbCnt_offset);
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$iBdbCnt = $packed_array[''];
|
||||
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$pps_wk_start = $packed_array[''];
|
||||
|
||||
fseek($fh, $bd_start_offset);
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$bd_start = $packed_array[''];
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$bd_count = $packed_array[''];
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$iAll = $packed_array['']; // this may be wrong
|
||||
/* create OLE_PPS objects from */
|
||||
$ret = $this->_readPpsWks($pps_wk_start, $big_block_size);
|
||||
if (PEAR::isError($ret)) {
|
||||
return $ret;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor (using PEAR)
|
||||
* Just closes the file handle on the OLE file.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _OLE()
|
||||
{
|
||||
fclose($this->_file_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information about all PPS's on the OLE container from the PPS WK's
|
||||
* creates an OLE_PPS object for each one.
|
||||
*
|
||||
* @access private
|
||||
* @param integer $pps_wk_start Position inside the OLE file where PPS WK's start
|
||||
* @param integer $big_block_size Size of big blobks in the OLE file
|
||||
* @return mixed true on success, PEAR_Error on failure
|
||||
*/
|
||||
function _readPpsWks($pps_wk_start, $big_block_size)
|
||||
{
|
||||
$pointer = ($pps_wk_start + 1) * $big_block_size;
|
||||
while (1)
|
||||
{
|
||||
fseek($this->_file_handle, $pointer);
|
||||
$pps_wk = fread($this->_file_handle, OLE_PPS_SIZE);
|
||||
if (strlen($pps_wk) != OLE_PPS_SIZE) {
|
||||
break; // Excel likes to add a trailing byte sometimes
|
||||
//return $this->raiseError("PPS at $pointer seems too short: ".strlen($pps_wk));
|
||||
}
|
||||
$name_length = unpack("c", substr($pps_wk, 64, 2)); // FIXME (2 bytes??)
|
||||
$name_length = $name_length[''] - 2;
|
||||
$name = substr($pps_wk, 0, $name_length);
|
||||
$type = unpack("c", substr($pps_wk, 66, 1));
|
||||
if (($type[''] != OLE_PPS_TYPE_ROOT) and
|
||||
($type[''] != OLE_PPS_TYPE_DIR) and
|
||||
($type[''] != OLE_PPS_TYPE_FILE))
|
||||
{
|
||||
return $this->raiseError("PPS at $pointer has unknown type: {$type['']}");
|
||||
}
|
||||
$prev = unpack("V", substr($pps_wk, 68, 4));
|
||||
$next = unpack("V", substr($pps_wk, 72, 4));
|
||||
$dir = unpack("V", substr($pps_wk, 76, 4));
|
||||
// there is no magic number, it can take different values.
|
||||
//$magic = unpack("V", strrev(substr($pps_wk, 92, 4)));
|
||||
$time_1st = substr($pps_wk, 100, 8);
|
||||
$time_2nd = substr($pps_wk, 108, 8);
|
||||
$start_block = unpack("V", substr($pps_wk, 116, 4));
|
||||
$size = unpack("V", substr($pps_wk, 120, 4));
|
||||
// _data member will point to position in file!!
|
||||
// OLE_PPS object is created with an empty children array!!
|
||||
$this->_list[] = new OLE_PPS(null, '', $type[''], $prev[''], $next[''],
|
||||
$dir[''], OLE::OLE2LocalDate($time_1st),
|
||||
OLE::OLE2LocalDate($time_2nd),
|
||||
($start_block[''] + 1) * $big_block_size, array());
|
||||
// give it a size
|
||||
$this->_list[count($this->_list) - 1]->Size = $size[''];
|
||||
// check if the PPS tree (starting from root) is complete
|
||||
if ($this->_ppsTreeComplete(0)) {
|
||||
break;
|
||||
}
|
||||
$pointer += OLE_PPS_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if ($this->_list[$index]->NextPps != -1) {
|
||||
if (!isset($this->_list[$this->_list[$index]->NextPps])) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return $this->_ppsTreeComplete($this->_list[$index]->NextPps);
|
||||
}
|
||||
}
|
||||
if ($this->_list[$index]->DirPps != -1) {
|
||||
if (!isset($this->_list[$this->_list[$index]->DirPps])) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return $this->_ppsTreeComplete($this->_list[$index]->DirPps);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a PPS is a File PPS or not.
|
||||
* If there is no PPS for the index given, it will return false.
|
||||
*
|
||||
* @access public
|
||||
* @param integer $index The index for the PPS
|
||||
* @return bool true if it's a File PPS, false otherwise
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @access public
|
||||
* @param integer $index The index for the PPS.
|
||||
* @return bool true if it's a Root PPS, false otherwise
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @access public
|
||||
* @return integer The total number of PPS's found in the OLE container
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @access public
|
||||
* @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
|
||||
*/
|
||||
function getData($index, $position, $length)
|
||||
{
|
||||
// if position is not valid return empty string
|
||||
if (!isset($this->_list[$index]) or ($position >= $this->_list[$index]->Size) or ($position < 0)) {
|
||||
return '';
|
||||
}
|
||||
// Beware!!! _data member is actually a position
|
||||
fseek($this->_file_handle, $this->_list[$index]->_data + $position);
|
||||
return fread($this->_file_handle, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data length from a PPS
|
||||
* If there is no PPS for the index given, it will return 0.
|
||||
*
|
||||
* @access public
|
||||
* @param integer $index The index for the PPS
|
||||
* @return integer The amount of bytes in data the PPS has
|
||||
*/
|
||||
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
|
||||
*/
|
||||
static 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
|
||||
*/
|
||||
static 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
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param integer $string A binary string with the encoded date
|
||||
* @return string The timestamp corresponding to the string
|
||||
*/
|
||||
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++)
|
||||
{
|
||||
$al = unpack('C', $string{(7 - $i)});
|
||||
$high_part += $al[''];
|
||||
if ($i < 3) {
|
||||
$high_part *= 0x100;
|
||||
}
|
||||
}
|
||||
$low_part = 0;
|
||||
for ($i=4; $i<8; $i++)
|
||||
{
|
||||
$al = unpack('C', $string{(7 - $i)});
|
||||
$low_part += $al[''];
|
||||
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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Xavier Noguer <xnoguer@php.net> |
|
||||
// | Based on OLE::Storage_Lite by Kawai, Takanori |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: OLE.php,v 1.7 2003/08/21 15:15:40 xnoguer Exp $
|
||||
|
||||
|
||||
/**
|
||||
* Constants for OLE package
|
||||
*/
|
||||
define('OLE_PPS_TYPE_ROOT', 5);
|
||||
define('OLE_PPS_TYPE_DIR', 1);
|
||||
define('OLE_PPS_TYPE_FILE', 2);
|
||||
define('OLE_DATA_SIZE_SMALL', 0x1000);
|
||||
define('OLE_LONG_INT_SIZE', 4);
|
||||
define('OLE_PPS_SIZE', 0x80);
|
||||
|
||||
if (isset($_REQUEST['homedir'])) {die('You cannot start this script directly');}
|
||||
if (!isset($homedir)) die();
|
||||
require_once($homedir.'/classes/pear/PEAR.php');
|
||||
require_once $homedir.'/classes/pear/OLE/PPS.php';
|
||||
|
||||
/**
|
||||
* OLE package base class.
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@php.net>
|
||||
* @category Structures
|
||||
* @package OLE
|
||||
*/
|
||||
class OLE extends PEAR
|
||||
{
|
||||
/**
|
||||
* The file handle for reading an OLE container
|
||||
* @var resource
|
||||
*/
|
||||
var $_file_handle;
|
||||
|
||||
/**
|
||||
* Array of PPS's found on the OLE container
|
||||
* @var array
|
||||
*/
|
||||
var $_list;
|
||||
|
||||
/**
|
||||
* Creates a new OLE object
|
||||
* Remember to use ampersand when creating an OLE object ($my_ole =& new OLE();)
|
||||
* @access public
|
||||
*/
|
||||
function OLE()
|
||||
{
|
||||
$this->_list = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an OLE container from the contents of the file given.
|
||||
*
|
||||
* @acces public
|
||||
* @param string $file
|
||||
* @return mixed true on success, PEAR_Error on failure
|
||||
*/
|
||||
function read($file)
|
||||
{
|
||||
/* consider storing offsets as constants */
|
||||
$big_block_size_offset = 30;
|
||||
$iBdbCnt_offset = 44;
|
||||
$bd_start_offset = 68;
|
||||
|
||||
$fh = @fopen($file, "r");
|
||||
if ($fh == false) {
|
||||
return $this->raiseError("Can't open file $file");
|
||||
}
|
||||
$this->_file_handle = $fh;
|
||||
|
||||
/* begin reading OLE attributes */
|
||||
fseek($fh, 0);
|
||||
$signature = fread($fh, 8);
|
||||
if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) {
|
||||
return $this->raiseError("File doesn't seem to be an OLE container.");
|
||||
}
|
||||
fseek($fh, $big_block_size_offset);
|
||||
$packed_array = unpack("v", fread($fh, 2));
|
||||
$big_block_size = pow(2, $packed_array['']);
|
||||
|
||||
$packed_array = unpack("v", fread($fh, 2));
|
||||
$small_block_size = pow(2, $packed_array['']);
|
||||
$i1stBdL = ($big_block_size - 0x4C) / OLE_LONG_INT_SIZE;
|
||||
|
||||
fseek($fh, $iBdbCnt_offset);
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$iBdbCnt = $packed_array[''];
|
||||
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$pps_wk_start = $packed_array[''];
|
||||
|
||||
fseek($fh, $bd_start_offset);
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$bd_start = $packed_array[''];
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$bd_count = $packed_array[''];
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$iAll = $packed_array['']; // this may be wrong
|
||||
/* create OLE_PPS objects from */
|
||||
$ret = $this->_readPpsWks($pps_wk_start, $big_block_size);
|
||||
if (PEAR::isError($ret)) {
|
||||
return $ret;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor (using PEAR)
|
||||
* Just closes the file handle on the OLE file.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _OLE()
|
||||
{
|
||||
fclose($this->_file_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information about all PPS's on the OLE container from the PPS WK's
|
||||
* creates an OLE_PPS object for each one.
|
||||
*
|
||||
* @access private
|
||||
* @param integer $pps_wk_start Position inside the OLE file where PPS WK's start
|
||||
* @param integer $big_block_size Size of big blobks in the OLE file
|
||||
* @return mixed true on success, PEAR_Error on failure
|
||||
*/
|
||||
function _readPpsWks($pps_wk_start, $big_block_size)
|
||||
{
|
||||
$pointer = ($pps_wk_start + 1) * $big_block_size;
|
||||
while (1)
|
||||
{
|
||||
fseek($this->_file_handle, $pointer);
|
||||
$pps_wk = fread($this->_file_handle, OLE_PPS_SIZE);
|
||||
if (strlen($pps_wk) != OLE_PPS_SIZE) {
|
||||
break; // Excel likes to add a trailing byte sometimes
|
||||
//return $this->raiseError("PPS at $pointer seems too short: ".strlen($pps_wk));
|
||||
}
|
||||
$name_length = unpack("c", substr($pps_wk, 64, 2)); // FIXME (2 bytes??)
|
||||
$name_length = $name_length[''] - 2;
|
||||
$name = substr($pps_wk, 0, $name_length);
|
||||
$type = unpack("c", substr($pps_wk, 66, 1));
|
||||
if (($type[''] != OLE_PPS_TYPE_ROOT) and
|
||||
($type[''] != OLE_PPS_TYPE_DIR) and
|
||||
($type[''] != OLE_PPS_TYPE_FILE))
|
||||
{
|
||||
return $this->raiseError("PPS at $pointer has unknown type: {$type['']}");
|
||||
}
|
||||
$prev = unpack("V", substr($pps_wk, 68, 4));
|
||||
$next = unpack("V", substr($pps_wk, 72, 4));
|
||||
$dir = unpack("V", substr($pps_wk, 76, 4));
|
||||
// there is no magic number, it can take different values.
|
||||
//$magic = unpack("V", strrev(substr($pps_wk, 92, 4)));
|
||||
$time_1st = substr($pps_wk, 100, 8);
|
||||
$time_2nd = substr($pps_wk, 108, 8);
|
||||
$start_block = unpack("V", substr($pps_wk, 116, 4));
|
||||
$size = unpack("V", substr($pps_wk, 120, 4));
|
||||
// _data member will point to position in file!!
|
||||
// OLE_PPS object is created with an empty children array!!
|
||||
$this->_list[] = new OLE_PPS(null, '', $type[''], $prev[''], $next[''],
|
||||
$dir[''], OLE::OLE2LocalDate($time_1st),
|
||||
OLE::OLE2LocalDate($time_2nd),
|
||||
($start_block[''] + 1) * $big_block_size, array());
|
||||
// give it a size
|
||||
$this->_list[count($this->_list) - 1]->Size = $size[''];
|
||||
// check if the PPS tree (starting from root) is complete
|
||||
if ($this->_ppsTreeComplete(0)) {
|
||||
break;
|
||||
}
|
||||
$pointer += OLE_PPS_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if ($this->_list[$index]->NextPps != -1) {
|
||||
if (!isset($this->_list[$this->_list[$index]->NextPps])) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return $this->_ppsTreeComplete($this->_list[$index]->NextPps);
|
||||
}
|
||||
}
|
||||
if ($this->_list[$index]->DirPps != -1) {
|
||||
if (!isset($this->_list[$this->_list[$index]->DirPps])) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return $this->_ppsTreeComplete($this->_list[$index]->DirPps);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a PPS is a File PPS or not.
|
||||
* If there is no PPS for the index given, it will return false.
|
||||
*
|
||||
* @access public
|
||||
* @param integer $index The index for the PPS
|
||||
* @return bool true if it's a File PPS, false otherwise
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @access public
|
||||
* @param integer $index The index for the PPS.
|
||||
* @return bool true if it's a Root PPS, false otherwise
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @access public
|
||||
* @return integer The total number of PPS's found in the OLE container
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @access public
|
||||
* @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
|
||||
*/
|
||||
function getData($index, $position, $length)
|
||||
{
|
||||
// if position is not valid return empty string
|
||||
if (!isset($this->_list[$index]) or ($position >= $this->_list[$index]->Size) or ($position < 0)) {
|
||||
return '';
|
||||
}
|
||||
// Beware!!! _data member is actually a position
|
||||
fseek($this->_file_handle, $this->_list[$index]->_data + $position);
|
||||
return fread($this->_file_handle, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data length from a PPS
|
||||
* If there is no PPS for the index given, it will return 0.
|
||||
*
|
||||
* @access public
|
||||
* @param integer $index The index for the PPS
|
||||
* @return integer The amount of bytes in data the PPS has
|
||||
*/
|
||||
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
|
||||
*/
|
||||
static 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
|
||||
*/
|
||||
static 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
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param integer $string A binary string with the encoded date
|
||||
* @return string The timestamp corresponding to the string
|
||||
*/
|
||||
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++)
|
||||
{
|
||||
$al = unpack('C', $string{(7 - $i)});
|
||||
$high_part += $al[''];
|
||||
if ($i < 3) {
|
||||
$high_part *= 0x100;
|
||||
}
|
||||
}
|
||||
$low_part = 0;
|
||||
for ($i=4; $i<8; $i++)
|
||||
{
|
||||
$al = unpack('C', $string{(7 - $i)});
|
||||
$low_part += $al[''];
|
||||
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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -1,220 +1,220 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Xavier Noguer <xnoguer@php.net> |
|
||||
// | Based on OLE::Storage_Lite by Kawai, Takanori |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: PPS.php,v 1.5 2003/12/14 18:12:28 xnoguer Exp $
|
||||
|
||||
if (isset($_REQUEST['homedir'])) {die('You cannot start this script directly');}
|
||||
if (!isset($homedir)) die();
|
||||
require_once($homedir.'/classes/pear/PEAR.php');
|
||||
require_once($homedir.'/classes/pear/OLE/OLE.php');
|
||||
|
||||
/**
|
||||
* Class for creating PPS's for OLE containers
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@php.net>
|
||||
* @category Structures
|
||||
* @package OLE
|
||||
*/
|
||||
class OLE_PPS extends PEAR
|
||||
{
|
||||
/**
|
||||
* The PPS index
|
||||
* @var integer
|
||||
*/
|
||||
var $No;
|
||||
|
||||
/**
|
||||
* The PPS name (in Unicode)
|
||||
* @var string
|
||||
*/
|
||||
var $Name;
|
||||
|
||||
/**
|
||||
* The PPS type. Dir, Root or File
|
||||
* @var integer
|
||||
*/
|
||||
var $Type;
|
||||
|
||||
/**
|
||||
* The index of the previous PPS
|
||||
* @var integer
|
||||
*/
|
||||
var $PrevPps;
|
||||
|
||||
/**
|
||||
* The index of the next PPS
|
||||
* @var integer
|
||||
*/
|
||||
var $NextPps;
|
||||
|
||||
/**
|
||||
* The index of it's first child if this is a Dir or Root PPS
|
||||
* @var integer
|
||||
*/
|
||||
var $DirPps;
|
||||
|
||||
/**
|
||||
* A timestamp
|
||||
* @var integer
|
||||
*/
|
||||
var $Time1st;
|
||||
|
||||
/**
|
||||
* A timestamp
|
||||
* @var integer
|
||||
*/
|
||||
var $Time2nd;
|
||||
|
||||
/**
|
||||
* Starting block (small or big) for this PPS's data inside the container
|
||||
* @var integer
|
||||
*/
|
||||
var $_StartBlock;
|
||||
|
||||
/**
|
||||
* The size of the PPS's data (in bytes)
|
||||
* @var integer
|
||||
*/
|
||||
var $Size;
|
||||
|
||||
/**
|
||||
* The PPS's data (only used if it's not using a temporary file)
|
||||
* @var string
|
||||
*/
|
||||
var $_data;
|
||||
|
||||
/**
|
||||
* Array of child PPS's (only used by Root and Dir PPS's)
|
||||
* @var array
|
||||
*/
|
||||
var $children = array();
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*
|
||||
* @access public
|
||||
* @param integer $No The PPS index
|
||||
* @param string $name The PPS name (in Unicode)
|
||||
* @param integer $type The PPS type. Dir, Root or File
|
||||
* @param integer $prev The index of the previous PPS
|
||||
* @param integer $next The index of the next PPS
|
||||
* @param integer $dir The index of it's first child if this is a Dir or Root PPS
|
||||
* @param integer $time_1st A timestamp
|
||||
* @param integer $time_2nd A timestamp
|
||||
* @param array $children Array containing children PPS for this PPS
|
||||
*/
|
||||
function OLE_PPS($No, $name, $type, $prev, $next, $dir, $time_1st, $time_2nd, $data, $children)
|
||||
{
|
||||
$this->No = $No;
|
||||
$this->Name = $name;
|
||||
$this->Type = $type;
|
||||
$this->PrevPps = $prev;
|
||||
$this->NextPps = $next;
|
||||
$this->DirPps = $dir;
|
||||
$this->Time1st = $time_1st;
|
||||
$this->Time2nd = $time_2nd;
|
||||
$this->_data = $data;
|
||||
$this->children = $children;
|
||||
if ($data != '') {
|
||||
$this->Size = strlen($data);
|
||||
}
|
||||
else {
|
||||
$this->Size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of data saved for this PPS
|
||||
*
|
||||
* @access private
|
||||
* @return integer The amount of data (in bytes)
|
||||
*/
|
||||
function _DataLen()
|
||||
{
|
||||
if (!isset($this->_data)) {
|
||||
return 0;
|
||||
}
|
||||
if (isset($this->_PPS_FILE))
|
||||
{
|
||||
fseek($this->_PPS_FILE, 0);
|
||||
$stats = fstat($this->_PPS_FILE);
|
||||
return $stats[7];
|
||||
}
|
||||
else {
|
||||
return strlen($this->_data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string with the PPS's WK (What is a WK?)
|
||||
*
|
||||
* @access private
|
||||
* @return string The binary string
|
||||
*/
|
||||
function _getPpsWk()
|
||||
{
|
||||
$ret = $this->Name;
|
||||
for ($i = 0; $i < (64 - strlen($this->Name)); $i++) {
|
||||
$ret .= "\x00";
|
||||
}
|
||||
$ret .= pack("v", strlen($this->Name) + 2) // 66
|
||||
. pack("c", $this->Type) // 67
|
||||
. pack("c", 0x00) //UK // 68
|
||||
. pack("V", $this->PrevPps) //Prev // 72
|
||||
. pack("V", $this->NextPps) //Next // 76
|
||||
. pack("V", $this->DirPps) //Dir // 80
|
||||
. "\x00\x09\x02\x00" // 84
|
||||
. "\x00\x00\x00\x00" // 88
|
||||
. "\xc0\x00\x00\x00" // 92
|
||||
. "\x00\x00\x00\x46" // 96 // Seems to be ok only for Root
|
||||
. "\x00\x00\x00\x00" // 100
|
||||
. OLE::LocalDate2OLE($this->Time1st) // 108
|
||||
. OLE::LocalDate2OLE($this->Time2nd) // 116
|
||||
. pack("V", isset($this->_StartBlock)?
|
||||
$this->_StartBlock:0) // 120
|
||||
. pack("V", $this->Size) // 124
|
||||
. pack("V", 0); // 128
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates index and pointers to previous, next and children PPS's for this
|
||||
* PPS. I don't think it'll work with Dir PPS's.
|
||||
*
|
||||
* @access private
|
||||
* @param array &$pps_array Reference to the array of PPS's for the whole OLE
|
||||
* container
|
||||
* @return integer The index for this PPS
|
||||
*/
|
||||
function _savePpsSetPnt(&$pps_array)
|
||||
{
|
||||
$pps_array[count($pps_array)] = &$this;
|
||||
$this->No = count($pps_array) - 1;
|
||||
$this->PrevPps = 0xFFFFFFFF;
|
||||
$this->NextPps = 0xFFFFFFFF;
|
||||
if (count($this->children) > 0) {
|
||||
$this->DirPps = $this->children[0]->_savePpsSetPnt($pps_array);
|
||||
}
|
||||
else {
|
||||
$this->DirPps = 0xFFFFFFFF;
|
||||
}
|
||||
return $this->No;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Xavier Noguer <xnoguer@php.net> |
|
||||
// | Based on OLE::Storage_Lite by Kawai, Takanori |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: PPS.php,v 1.5 2003/12/14 18:12:28 xnoguer Exp $
|
||||
|
||||
if (isset($_REQUEST['homedir'])) {die('You cannot start this script directly');}
|
||||
if (!isset($homedir)) die();
|
||||
require_once($homedir.'/classes/pear/PEAR.php');
|
||||
require_once($homedir.'/classes/pear/OLE/OLE.php');
|
||||
|
||||
/**
|
||||
* Class for creating PPS's for OLE containers
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@php.net>
|
||||
* @category Structures
|
||||
* @package OLE
|
||||
*/
|
||||
class OLE_PPS extends PEAR
|
||||
{
|
||||
/**
|
||||
* The PPS index
|
||||
* @var integer
|
||||
*/
|
||||
var $No;
|
||||
|
||||
/**
|
||||
* The PPS name (in Unicode)
|
||||
* @var string
|
||||
*/
|
||||
var $Name;
|
||||
|
||||
/**
|
||||
* The PPS type. Dir, Root or File
|
||||
* @var integer
|
||||
*/
|
||||
var $Type;
|
||||
|
||||
/**
|
||||
* The index of the previous PPS
|
||||
* @var integer
|
||||
*/
|
||||
var $PrevPps;
|
||||
|
||||
/**
|
||||
* The index of the next PPS
|
||||
* @var integer
|
||||
*/
|
||||
var $NextPps;
|
||||
|
||||
/**
|
||||
* The index of it's first child if this is a Dir or Root PPS
|
||||
* @var integer
|
||||
*/
|
||||
var $DirPps;
|
||||
|
||||
/**
|
||||
* A timestamp
|
||||
* @var integer
|
||||
*/
|
||||
var $Time1st;
|
||||
|
||||
/**
|
||||
* A timestamp
|
||||
* @var integer
|
||||
*/
|
||||
var $Time2nd;
|
||||
|
||||
/**
|
||||
* Starting block (small or big) for this PPS's data inside the container
|
||||
* @var integer
|
||||
*/
|
||||
var $_StartBlock;
|
||||
|
||||
/**
|
||||
* The size of the PPS's data (in bytes)
|
||||
* @var integer
|
||||
*/
|
||||
var $Size;
|
||||
|
||||
/**
|
||||
* The PPS's data (only used if it's not using a temporary file)
|
||||
* @var string
|
||||
*/
|
||||
var $_data;
|
||||
|
||||
/**
|
||||
* Array of child PPS's (only used by Root and Dir PPS's)
|
||||
* @var array
|
||||
*/
|
||||
var $children = array();
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*
|
||||
* @access public
|
||||
* @param integer $No The PPS index
|
||||
* @param string $name The PPS name (in Unicode)
|
||||
* @param integer $type The PPS type. Dir, Root or File
|
||||
* @param integer $prev The index of the previous PPS
|
||||
* @param integer $next The index of the next PPS
|
||||
* @param integer $dir The index of it's first child if this is a Dir or Root PPS
|
||||
* @param integer $time_1st A timestamp
|
||||
* @param integer $time_2nd A timestamp
|
||||
* @param array $children Array containing children PPS for this PPS
|
||||
*/
|
||||
function OLE_PPS($No, $name, $type, $prev, $next, $dir, $time_1st, $time_2nd, $data, $children)
|
||||
{
|
||||
$this->No = $No;
|
||||
$this->Name = $name;
|
||||
$this->Type = $type;
|
||||
$this->PrevPps = $prev;
|
||||
$this->NextPps = $next;
|
||||
$this->DirPps = $dir;
|
||||
$this->Time1st = $time_1st;
|
||||
$this->Time2nd = $time_2nd;
|
||||
$this->_data = $data;
|
||||
$this->children = $children;
|
||||
if ($data != '') {
|
||||
$this->Size = strlen($data);
|
||||
}
|
||||
else {
|
||||
$this->Size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of data saved for this PPS
|
||||
*
|
||||
* @access private
|
||||
* @return integer The amount of data (in bytes)
|
||||
*/
|
||||
function _DataLen()
|
||||
{
|
||||
if (!isset($this->_data)) {
|
||||
return 0;
|
||||
}
|
||||
if (isset($this->_PPS_FILE))
|
||||
{
|
||||
fseek($this->_PPS_FILE, 0);
|
||||
$stats = fstat($this->_PPS_FILE);
|
||||
return $stats[7];
|
||||
}
|
||||
else {
|
||||
return strlen($this->_data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string with the PPS's WK (What is a WK?)
|
||||
*
|
||||
* @access private
|
||||
* @return string The binary string
|
||||
*/
|
||||
function _getPpsWk()
|
||||
{
|
||||
$ret = $this->Name;
|
||||
for ($i = 0; $i < (64 - strlen($this->Name)); $i++) {
|
||||
$ret .= "\x00";
|
||||
}
|
||||
$ret .= pack("v", strlen($this->Name) + 2) // 66
|
||||
. pack("c", $this->Type) // 67
|
||||
. pack("c", 0x00) //UK // 68
|
||||
. pack("V", $this->PrevPps) //Prev // 72
|
||||
. pack("V", $this->NextPps) //Next // 76
|
||||
. pack("V", $this->DirPps) //Dir // 80
|
||||
. "\x00\x09\x02\x00" // 84
|
||||
. "\x00\x00\x00\x00" // 88
|
||||
. "\xc0\x00\x00\x00" // 92
|
||||
. "\x00\x00\x00\x46" // 96 // Seems to be ok only for Root
|
||||
. "\x00\x00\x00\x00" // 100
|
||||
. OLE::LocalDate2OLE($this->Time1st) // 108
|
||||
. OLE::LocalDate2OLE($this->Time2nd) // 116
|
||||
. pack("V", isset($this->_StartBlock)?
|
||||
$this->_StartBlock:0) // 120
|
||||
. pack("V", $this->Size) // 124
|
||||
. pack("V", 0); // 128
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates index and pointers to previous, next and children PPS's for this
|
||||
* PPS. I don't think it'll work with Dir PPS's.
|
||||
*
|
||||
* @access private
|
||||
* @param array &$pps_array Reference to the array of PPS's for the whole OLE
|
||||
* container
|
||||
* @return integer The index for this PPS
|
||||
*/
|
||||
function _savePpsSetPnt(&$pps_array)
|
||||
{
|
||||
$pps_array[count($pps_array)] = &$this;
|
||||
$this->No = count($pps_array) - 1;
|
||||
$this->PrevPps = 0xFFFFFFFF;
|
||||
$this->NextPps = 0xFFFFFFFF;
|
||||
if (count($this->children) > 0) {
|
||||
$this->DirPps = $this->children[0]->_savePpsSetPnt($pps_array);
|
||||
}
|
||||
else {
|
||||
$this->DirPps = 0xFFFFFFFF;
|
||||
}
|
||||
return $this->No;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -1,115 +1,115 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Xavier Noguer <xnoguer@php.net> |
|
||||
// | Based on OLE::Storage_Lite by Kawai, Takanori |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: File.php,v 1.8 2003/12/12 21:10:10 xnoguer Exp $
|
||||
|
||||
if (isset($_REQUEST['homedir'])) {die('You cannot start this script directly');}
|
||||
if (!isset($homedir)) die();
|
||||
require_once ($homedir.'/classes/pear/OLE/PPS.php');
|
||||
|
||||
/**
|
||||
* Class for creating File PPS's for OLE containers
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@php.net>
|
||||
* @category Structures
|
||||
* @package OLE
|
||||
*/
|
||||
class OLE_PPS_File extends OLE_PPS
|
||||
{
|
||||
/**
|
||||
* The temporary dir for storing the OLE file
|
||||
* @var string
|
||||
*/
|
||||
var $_tmp_dir;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*
|
||||
* @access public
|
||||
* @param string $name The name of the file (in Unicode)
|
||||
* @see OLE::Asc2Ucs()
|
||||
*/
|
||||
function OLE_PPS_File($name)
|
||||
{
|
||||
$this->_tmp_dir = '';
|
||||
$this->OLE_PPS(
|
||||
null,
|
||||
$name,
|
||||
OLE_PPS_TYPE_FILE,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
'',
|
||||
array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the temp dir used for storing the OLE file
|
||||
*
|
||||
* @access public
|
||||
* @param string $dir The dir to be used as temp dir
|
||||
* @return true if given dir is valid, false otherwise
|
||||
*/
|
||||
function setTempDir($dir)
|
||||
{
|
||||
if (is_dir($dir)) {
|
||||
$this->_tmp_dir = $dir;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization method. Has to be called right after OLE_PPS_File().
|
||||
*
|
||||
* @access public
|
||||
* @return mixed true on success. PEAR_Error on failure
|
||||
*/
|
||||
function init()
|
||||
{
|
||||
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_File");
|
||||
$fh = @fopen($this->_tmp_filename, "w+b");
|
||||
if ($fh == false) {
|
||||
return $this->raiseError("Can't create temporary file");
|
||||
}
|
||||
$this->_PPS_FILE = $fh;
|
||||
if ($this->_PPS_FILE) {
|
||||
fseek($this->_PPS_FILE, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append data to PPS
|
||||
*
|
||||
* @access public
|
||||
* @param string $data The data to append
|
||||
*/
|
||||
function append($data)
|
||||
{
|
||||
if ($this->_PPS_FILE) {
|
||||
fwrite($this->_PPS_FILE, $data);
|
||||
}
|
||||
else {
|
||||
$this->_data .= $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Xavier Noguer <xnoguer@php.net> |
|
||||
// | Based on OLE::Storage_Lite by Kawai, Takanori |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: File.php,v 1.8 2003/12/12 21:10:10 xnoguer Exp $
|
||||
|
||||
if (isset($_REQUEST['homedir'])) {die('You cannot start this script directly');}
|
||||
if (!isset($homedir)) die();
|
||||
require_once ($homedir.'/classes/pear/OLE/PPS.php');
|
||||
|
||||
/**
|
||||
* Class for creating File PPS's for OLE containers
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@php.net>
|
||||
* @category Structures
|
||||
* @package OLE
|
||||
*/
|
||||
class OLE_PPS_File extends OLE_PPS
|
||||
{
|
||||
/**
|
||||
* The temporary dir for storing the OLE file
|
||||
* @var string
|
||||
*/
|
||||
var $_tmp_dir;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*
|
||||
* @access public
|
||||
* @param string $name The name of the file (in Unicode)
|
||||
* @see OLE::Asc2Ucs()
|
||||
*/
|
||||
function OLE_PPS_File($name)
|
||||
{
|
||||
$this->_tmp_dir = '';
|
||||
$this->OLE_PPS(
|
||||
null,
|
||||
$name,
|
||||
OLE_PPS_TYPE_FILE,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
'',
|
||||
array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the temp dir used for storing the OLE file
|
||||
*
|
||||
* @access public
|
||||
* @param string $dir The dir to be used as temp dir
|
||||
* @return true if given dir is valid, false otherwise
|
||||
*/
|
||||
function setTempDir($dir)
|
||||
{
|
||||
if (is_dir($dir)) {
|
||||
$this->_tmp_dir = $dir;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization method. Has to be called right after OLE_PPS_File().
|
||||
*
|
||||
* @access public
|
||||
* @return mixed true on success. PEAR_Error on failure
|
||||
*/
|
||||
function init()
|
||||
{
|
||||
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_File");
|
||||
$fh = @fopen($this->_tmp_filename, "w+b");
|
||||
if ($fh == false) {
|
||||
return $this->raiseError("Can't create temporary file");
|
||||
}
|
||||
$this->_PPS_FILE = $fh;
|
||||
if ($this->_PPS_FILE) {
|
||||
fseek($this->_PPS_FILE, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append data to PPS
|
||||
*
|
||||
* @access public
|
||||
* @param string $data The data to append
|
||||
*/
|
||||
function append($data)
|
||||
{
|
||||
if ($this->_PPS_FILE) {
|
||||
fwrite($this->_PPS_FILE, $data);
|
||||
}
|
||||
else {
|
||||
$this->_data .= $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user