ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
OLE Class Reference
+ Inheritance diagram for OLE:
+ Collaboration diagram for OLE:

Public Member Functions

 OLE ()
 Creates a new OLE object Remember to use ampersand when creating an OLE object ($my_ole =& new OLE();) public.
 read ($file)
 Reads an OLE container from the contents of the file given.
 _OLE ()
 Destructor (using PEAR) Just closes the file handle on the OLE file.
 _readPpsWks ($pps_wk_start, $big_block_size)
 Gets information about all PPS's on the OLE container from the PPS WK's creates an OLE_PPS object for each one.
 _ppsTreeComplete ($index)
 It checks whether the PPS tree is complete (all PPS's read) starting with the given PPS (not necessarily root)
 isFile ($index)
 Checks whether a PPS is a File PPS or not.
 isRoot ($index)
 Checks whether a PPS is a Root PPS or not.
 ppsTotal ()
 Gives the total number of PPS's found in the OLE container.
 getData ($index, $position, $length)
 Gets data from a PPS If there is no PPS for the index given, it will return an empty string.
 getDataLength ($index)
 Gets the data length from a PPS If there is no PPS for the index given, it will return 0.
- Public Member Functions inherited from PEAR
 PEAR ($error_class=null)
 Constructor.
 _PEAR ()
 Destructor (the emulated type of...).
getStaticProperty ($class, $var)
 If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them.
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes.
 isError ($data, $code=null)
 Tell whether a value is a PEAR error.
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled.
 expectError ($code= '*')
 This method is used to tell which errors you expect to get.
 popExpect ()
 This method pops one element off the expected error codes stack.
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available.
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack.
raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied.
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options.
 staticPushErrorHandling ($mode, $options=null)
 staticPopErrorHandling ()
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack.
 popErrorHandling ()
 Pop the last error handler used.
 loadExtension ($ext)
 OS independant PHP extension load.

Static Public Member Functions

 Asc2Ucs ($ascii)
 Utility function to transform ASCII text to Unicode.
 LocalDate2OLE ($date=null)
 Utility function Returns a string for the OLE container with the date given.
 OLE2LocalDate ($string)
 Returns a timestamp from an OLE container's date.

Data Fields

 $_file_handle
 $_list
- Data Fields inherited from PEAR
 $_debug = false
 $_default_error_mode = null
 $_default_error_options = null
 $_default_error_handler = ''
 $_error_class = 'PEAR_Error'
 $_expected_errors = array()

Detailed Description

Definition at line 43 of file OLE.php.

Member Function Documentation

OLE::_OLE ( )

Destructor (using PEAR) Just closes the file handle on the OLE file.

private

Definition at line 129 of file OLE.php.

{
fclose($this->_file_handle);
}
OLE::_ppsTreeComplete (   $index)

It checks whether the PPS tree is complete (all PPS's read) starting with the given PPS (not necessarily root)

private

Parameters
integer$indexThe index of the PPS from which we are checking
Returns
boolean Whether the PPS tree for the given PPS is complete

Definition at line 197 of file OLE.php.

Referenced by _readPpsWks().

{
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;
}

+ Here is the caller graph for this function:

OLE::_readPpsWks (   $pps_wk_start,
  $big_block_size 
)

Gets information about all PPS's on the OLE container from the PPS WK's creates an OLE_PPS object for each one.

private

Parameters
integer$pps_wk_startPosition inside the OLE file where PPS WK's start
integer$big_block_sizeSize of big blobks in the OLE file
Returns
mixed true on success, PEAR_Error on failure

Definition at line 143 of file OLE.php.

References $dir, $name, $size, $type, _ppsTreeComplete(), OLE2LocalDate(), OLE_PPS_SIZE, OLE_PPS_TYPE_DIR, OLE_PPS_TYPE_FILE, OLE_PPS_TYPE_ROOT, and PEAR\raiseError().

Referenced by read().

{
$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
{
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;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

OLE::Asc2Ucs (   $ascii)
static

Utility function to transform ASCII text to Unicode.

public

Parameters
string$asciiThe ASCII string to transform
Returns
string The string in Unicode

Definition at line 307 of file OLE.php.

Referenced by Spreadsheet_Excel_Writer_Workbook\_storeOLEFile(), and OLE_PPS_Root\OLE_PPS_Root().

{
$rawname = '';
for ($i = 0; $i < strlen($ascii); $i++) {
$rawname .= $ascii{$i}."\x00";
}
return $rawname;
}

+ Here is the caller graph for this function:

OLE::getData (   $index,
  $position,
  $length 
)

Gets data from a PPS If there is no PPS for the index given, it will return an empty string.

public

Parameters
integer$indexThe index for the PPS
integer$positionThe position from which to start reading (relative to the PPS)
integer$lengthThe amount of bytes to read (at most)
Returns
string The binary string containing the data requested

Definition at line 272 of file OLE.php.

{
// 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);
}
OLE::getDataLength (   $index)

Gets the data length from a PPS If there is no PPS for the index given, it will return 0.

public

Parameters
integer$indexThe index for the PPS
Returns
integer The amount of bytes in data the PPS has

Definition at line 291 of file OLE.php.

{
if (isset($this->_list[$index])) {
return $this->_list[$index]->Size;
}
return 0;
}
OLE::isFile (   $index)

Checks whether a PPS is a File PPS or not.

If there is no PPS for the index given, it will return false.

public

Parameters
integer$indexThe index for the PPS
Returns
bool true if it's a File PPS, false otherwise

Definition at line 226 of file OLE.php.

References OLE_PPS_TYPE_FILE.

{
if (isset($this->_list[$index])) {
return ($this->_list[$index]->Type == OLE_PPS_TYPE_FILE);
}
return false;
}
OLE::isRoot (   $index)

Checks whether a PPS is a Root PPS or not.

If there is no PPS for the index given, it will return false.

public

Parameters
integer$indexThe index for the PPS.
Returns
bool true if it's a Root PPS, false otherwise

Definition at line 242 of file OLE.php.

References OLE_PPS_TYPE_ROOT.

{
if (isset($this->_list[$index])) {
return ($this->_list[$index]->Type == OLE_PPS_TYPE_ROOT);
}
return false;
}
OLE::LocalDate2OLE (   $date = null)
static

Utility function Returns a string for the OLE container with the date given.

public

Parameters
integer$dateA timestamp
Returns
string The string for the OLE container

Definition at line 325 of file OLE.php.

References $res.

Referenced by OLE_PPS\_getPpsWk().

{
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;
}

+ Here is the caller graph for this function:

OLE::OLE ( )

Creates a new OLE object Remember to use ampersand when creating an OLE object ($my_ole =& new OLE();) public.

Definition at line 62 of file OLE.php.

{
$this->_list = array();
}
OLE::OLE2LocalDate (   $string)
static

Returns a timestamp from an OLE container's date.

public

Parameters
integer$stringA binary string with the encoded date
Returns
string The timestamp corresponding to the string

Definition at line 372 of file OLE.php.

Referenced by _readPpsWks().

{
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);
}

+ Here is the caller graph for this function:

OLE::ppsTotal ( )

Gives the total number of PPS's found in the OLE container.

public

Returns
integer The total number of PPS's found in the OLE container

Definition at line 256 of file OLE.php.

{
return count($this->_list);
}
OLE::read (   $file)

Reads an OLE container from the contents of the file given.

public

Parameters
string$file
Returns
mixed true on success, PEAR_Error on failure

Definition at line 74 of file OLE.php.

References $file, $ret, _readPpsWks(), PEAR\isError(), OLE_LONG_INT_SIZE, and PEAR\raiseError().

{
/* 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);
return $ret;
}
return true;
}

+ Here is the call graph for this function:

Field Documentation

OLE::$_file_handle

Definition at line 49 of file OLE.php.

OLE::$_list

Definition at line 55 of file OLE.php.


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