ILIAS  Release_5_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 public.
 _OLE ()
 Destructor (using PEAR) Just closes the file handle on the OLE file.
 read ($file)
 Reads an OLE container from the contents of the file given.
 _getBlockOffset ($blockId)
 getStream ($blockIdOrPps)
 Returns a stream for use with fread() etc.
 _readInt1 ($fh)
 Reads a signed char.
 _readInt2 ($fh)
 Reads an unsigned short (2 octets).
 _readInt4 ($fh)
 Reads an unsigned long (4 octets).
 _readPpsWks ($blockId)
 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
 $root
 $bbat
 $sbat
 $bigBlockSize
 $smallBlockSize
- 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 50 of file OLE.php.

Member Function Documentation

OLE::_getBlockOffset (   $blockId)
Parameters
int$blockIdblock id
Returns
int byte offset from beginning of file private

Definition at line 212 of file OLE.php.

References $bigBlockSize.

Referenced by read().

{
return 512 + $blockId * $this->bigBlockSize;
}

+ Here is the caller graph for this function:

OLE::_OLE ( )

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

private

Definition at line 110 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 372 of file OLE.php.

Referenced by _readPpsWks().

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

+ Here is the caller graph for this function:

OLE::_readInt1 (   $fh)

Reads a signed char.

Parameters
resource$fhfile handle
Returns
int private

Definition at line 255 of file OLE.php.

Referenced by _readPpsWks().

{
list(, $tmp) = unpack("c", fread($fh, 1));
return $tmp;
}

+ Here is the caller graph for this function:

OLE::_readInt2 (   $fh)

Reads an unsigned short (2 octets).

Parameters
resource$fhfile handle
Returns
int private

Definition at line 267 of file OLE.php.

Referenced by _readPpsWks(), and read().

{
list(, $tmp) = unpack("v", fread($fh, 2));
return $tmp;
}

+ Here is the caller graph for this function:

OLE::_readInt4 (   $fh)

Reads an unsigned long (4 octets).

Parameters
resourcefile handle
Returns
int private

Definition at line 279 of file OLE.php.

Referenced by _readPpsWks(), and read().

{
list(, $tmp) = unpack("V", fread($fh, 4));
return $tmp;
}

+ Here is the caller graph for this function:

OLE::_readPpsWks (   $blockId)

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$blockIdthe block id of the first block
Returns
mixed true on success, PEAR_Error on failure

Definition at line 293 of file OLE.php.

References _ppsTreeComplete(), _readInt1(), _readInt2(), _readInt4(), getStream(), OLE2LocalDate(), OLE_PPS_TYPE_DIR, OLE_PPS_TYPE_FILE, and OLE_PPS_TYPE_ROOT.

Referenced by read().

{
$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) {
require_once 'OLE/PPS/Root.php';
$pps = new OLE_PPS_Root(null, null, array());
$this->root = $pps;
break;
$pps = new OLE_PPS(null, null, null, null, null,
null, null, null, null, array());
break;
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;
}

+ 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 473 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.

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 public
See Also
OLE_PPS_File::getStream()

Definition at line 435 of file OLE.php.

References getStream().

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

+ Here is the call graph for this function:

OLE::getDataLength (   $index)

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

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

Definition at line 457 of file OLE.php.

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

Returns a stream for use with fread() etc.

External callers should use OLE_PPS_File::getStream().

Parameters
int | PPS$blockIdOrPpsblock id or PPS
Returns
resource read-only stream

Definition at line 223 of file OLE.php.

References $GLOBALS, and $path.

Referenced by _readPpsWks(), getData(), and read().

{
include_once 'OLE/ChainedBlockStream.php';
static $isRegistered = false;
if (!$isRegistered) {
stream_wrapper_register('ole-chainedblockstream',
'OLE_ChainedBlockStream');
$isRegistered = true;
}
// Store current instance in global array, so that it can be accessed
// in OLE_ChainedBlockStream::stream_open().
// Object is removed from self::$instances in OLE_Stream::close().
$GLOBALS['_OLE_INSTANCES'][] = $this;
$instanceId = end(array_keys($GLOBALS['_OLE_INSTANCES']));
$path = 'ole-chainedblockstream://oleInstanceId=' . $instanceId;
if (is_a($blockIdOrPps, 'OLE_PPS')) {
$path .= '&blockId=' . $blockIdOrPps->_StartBlock;
$path .= '&size=' . $blockIdOrPps->Size;
} else {
$path .= '&blockId=' . $blockIdOrPps;
}
return fopen($path, 'r');
}

+ Here is the caller graph for this function:

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.

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

Definition at line 391 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.

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

Definition at line 406 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 491 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 public.

Definition at line 99 of file OLE.php.

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

Returns a timestamp from an OLE container's date.

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

Definition at line 536 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++) {
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);
}

+ Here is the caller graph for this function:

OLE::ppsTotal ( )

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

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

Definition at line 419 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 122 of file OLE.php.

References $file, _getBlockOffset(), _readInt2(), _readInt4(), _readPpsWks(), getStream(), and PEAR\raiseError().

{
$fh = @fopen($file, "r");
if (!$fh) {
return $this->raiseError("Can't open file $file");
}
$this->_file_handle = $fh;
$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, 28);
if (fread($fh, 2) != "\xFE\xFF") {
// This shouldn't be a problem in practice
return $this->raiseError("Only Little-Endian encoding is supported.");
}
// Size of blocks and short blocks in bytes
$this->bigBlockSize = pow(2, $this->_readInt2($fh));
$this->smallBlockSize = pow(2, $this->_readInt2($fh));
// Skip UID, revision number and version number
fseek($fh, 44);
// Number of blocks in Big Block Allocation Table
$bbatBlockCount = $this->_readInt4($fh);
// Root chain 1st block
$directoryFirstBlockId = $this->_readInt4($fh);
// Skip unused bytes
fseek($fh, 56);
// Streams shorter than this are stored using small blocks
$this->bigBlockThreshold = $this->_readInt4($fh);
// Block id of first sector in Short Block Allocation Table
$sbatFirstBlockId = $this->_readInt4($fh);
// Number of blocks in Short Block Allocation Table
$sbbatBlockCount = $this->_readInt4($fh);
// Block id of first sector in Master Block Allocation Table
$mbatFirstBlockId = $this->_readInt4($fh);
// Number of blocks in Master Block Allocation Table
$mbbatBlockCount = $this->_readInt4($fh);
$this->bbat = array();
// Remaining 4 * 109 bytes of current block is beginning of Master
// Block Allocation Table
$mbatBlocks = array();
for ($i = 0; $i < 109; $i++) {
$mbatBlocks[] = $this->_readInt4($fh);
}
// Read rest of Master Block Allocation Table (if any is left)
$pos = $this->_getBlockOffset($mbatFirstBlockId);
for ($i = 0; $i < $mbbatBlockCount; $i++) {
fseek($fh, $pos);
for ($j = 0; $j < $this->bigBlockSize / 4 - 1; $j++) {
$mbatBlocks[] = $this->_readInt4($fh);
}
// Last block id in each block points to next block
$pos = $this->_getBlockOffset($this->_readInt4($fh));
}
// Read Big Block Allocation Table according to chain specified by
// $mbatBlocks
for ($i = 0; $i < $bbatBlockCount; $i++) {
$pos = $this->_getBlockOffset($mbatBlocks[$i]);
fseek($fh, $pos);
for ($j = 0 ; $j < $this->bigBlockSize / 4; $j++) {
$this->bbat[] = $this->_readInt4($fh);
}
}
// Read short block allocation table (SBAT)
$this->sbat = array();
$shortBlockCount = $sbbatBlockCount * $this->bigBlockSize / 4;
$sbatFh = $this->getStream($sbatFirstBlockId);
for ($blockId = 0; $blockId < $shortBlockCount; $blockId++) {
$this->sbat[$blockId] = $this->_readInt4($sbatFh);
}
fclose($sbatFh);
$this->_readPpsWks($directoryFirstBlockId);
return true;
}

+ Here is the call graph for this function:

Field Documentation

OLE::$_file_handle

Definition at line 57 of file OLE.php.

OLE::$_list

Definition at line 63 of file OLE.php.

OLE::$bbat

Definition at line 75 of file OLE.php.

OLE::$bigBlockSize

Definition at line 87 of file OLE.php.

Referenced by _getBlockOffset().

OLE::$root

Definition at line 69 of file OLE.php.

OLE::$sbat

Definition at line 81 of file OLE.php.

OLE::$smallBlockSize

Definition at line 93 of file OLE.php.


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