ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
OLE Class Reference
+ Inheritance diagram for OLE:
+ Collaboration diagram for OLE:

Public Member Functions

 OLE ()
 Creates a new OLE object public. More...
 
 _OLE ()
 Destructor (using PEAR) Just closes the file handle on the OLE file. More...
 
 read ($file)
 Reads an OLE container from the contents of the file given. More...
 
 _getBlockOffset ($blockId)
 
 getStream ($blockIdOrPps)
 Returns a stream for use with fread() etc. More...
 
 _readInt1 ($fh)
 Reads a signed char. More...
 
 _readInt2 ($fh)
 Reads an unsigned short (2 octets). More...
 
 _readInt4 ($fh)
 Reads an unsigned long (4 octets). More...
 
 _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. More...
 
 _ppsTreeComplete ($index)
 It checks whether the PPS tree is complete (all PPS's read) starting with the given PPS (not necessarily root) More...
 
 isFile ($index)
 Checks whether a PPS is a File PPS or not. More...
 
 isRoot ($index)
 Checks whether a PPS is a Root PPS or not. More...
 
 ppsTotal ()
 Gives the total number of PPS's found in the OLE container. More...
 
 getData ($index, $position, $length)
 Gets data from a PPS If there is no PPS for the index given, it will return an empty string. More...
 
 getDataLength ($index)
 Gets the data length from a PPS If there is no PPS for the index given, it will return 0. More...
 
- Public Member Functions inherited from PEAR
 PEAR ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). More...
 
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. More...
 
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes. More...
 
 isError ($data, $code=null)
 Tell whether a value is a PEAR error. More...
 
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. More...
 
 expectError ($code=' *')
 This method is used to tell which errors you expect to get. More...
 
 popExpect ()
 This method pops one element off the expected error codes stack. More...
 
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available. More...
 
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack. More...
 
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. More...
 
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options. More...
 
 staticPushErrorHandling ($mode, $options=null)
 
 staticPopErrorHandling ()
 
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack. More...
 
 popErrorHandling ()
 Pop the last error handler used. More...
 
 loadExtension ($ext)
 OS independant PHP extension load. More...
 

Static Public Member Functions

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

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

◆ _getBlockOffset()

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().

213  {
214  return 512 + $blockId * $this->bigBlockSize;
215  }
$bigBlockSize
Definition: OLE.php:87
+ Here is the caller graph for this function:

◆ _OLE()

OLE::_OLE ( )

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

private

Definition at line 110 of file OLE.php.

111  {
112  fclose($this->_file_handle);
113  }

◆ _ppsTreeComplete()

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().

373  {
374  return isset($this->_list[$index]) &&
375  ($pps = $this->_list[$index]) &&
376  ($pps->PrevPps == -1 ||
377  $this->_ppsTreeComplete($pps->PrevPps)) &&
378  ($pps->NextPps == -1 ||
379  $this->_ppsTreeComplete($pps->NextPps)) &&
380  ($pps->DirPps == -1 ||
381  $this->_ppsTreeComplete($pps->DirPps));
382  }
+ Here is the caller graph for this function:

◆ _readInt1()

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().

256  {
257  list(, $tmp) = unpack("c", fread($fh, 1));
258  return $tmp;
259  }
+ Here is the caller graph for this function:

◆ _readInt2()

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().

268  {
269  list(, $tmp) = unpack("v", fread($fh, 2));
270  return $tmp;
271  }
+ Here is the caller graph for this function:

◆ _readInt4()

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().

280  {
281  list(, $tmp) = unpack("V", fread($fh, 4));
282  return $tmp;
283  }
+ Here is the caller graph for this function:

◆ _readPpsWks()

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().

294  {
295  $fh = $this->getStream($blockId);
296  for ($pos = 0; ; $pos += 128) {
297  fseek($fh, $pos, SEEK_SET);
298  $nameUtf16 = fread($fh, 64);
299  $nameLength = $this->_readInt2($fh);
300  $nameUtf16 = substr($nameUtf16, 0, $nameLength - 2);
301  // Simple conversion from UTF-16LE to ISO-8859-1
302  $name = str_replace("\x00", "", $nameUtf16);
303  $type = $this->_readInt1($fh);
304  switch ($type) {
305  case OLE_PPS_TYPE_ROOT:
306  require_once 'OLE/PPS/Root.php';
307  $pps = new OLE_PPS_Root(null, null, array());
308  $this->root = $pps;
309  break;
310  case OLE_PPS_TYPE_DIR:
311  $pps = new OLE_PPS(null, null, null, null, null,
312  null, null, null, null, array());
313  break;
314  case OLE_PPS_TYPE_FILE:
315  require_once 'OLE/PPS/File.php';
316  $pps = new OLE_PPS_File($name);
317  break;
318  default:
319  continue;
320  }
321  fseek($fh, 1, SEEK_CUR);
322  $pps->Type = $type;
323  $pps->Name = $name;
324  $pps->PrevPps = $this->_readInt4($fh);
325  $pps->NextPps = $this->_readInt4($fh);
326  $pps->DirPps = $this->_readInt4($fh);
327  fseek($fh, 20, SEEK_CUR);
328  $pps->Time1st = OLE::OLE2LocalDate(fread($fh, 8));
329  $pps->Time2nd = OLE::OLE2LocalDate(fread($fh, 8));
330  $pps->_StartBlock = $this->_readInt4($fh);
331  $pps->Size = $this->_readInt4($fh);
332  $pps->No = count($this->_list);
333  $this->_list[] = $pps;
334 
335  // check if the PPS tree (starting from root) is complete
336  if (isset($this->root) &&
337  $this->_ppsTreeComplete($this->root->No)) {
338 
339  break;
340  }
341  }
342  fclose($fh);
343 
344  // Initialize $pps->children on directories
345  foreach ($this->_list as $pps) {
346  if ($pps->Type == OLE_PPS_TYPE_DIR || $pps->Type == OLE_PPS_TYPE_ROOT) {
347  $nos = array($pps->DirPps);
348  $pps->children = array();
349  while ($nos) {
350  $no = array_pop($nos);
351  if ($no != -1) {
352  $childPps = $this->_list[$no];
353  $nos[] = $childPps->PrevPps;
354  $nos[] = $childPps->NextPps;
355  $pps->children[] = $childPps;
356  }
357  }
358  }
359  }
360 
361  return true;
362  }
OLE2LocalDate($string)
Returns a timestamp from an OLE container's date.
Definition: OLE.php:536
_readInt4($fh)
Reads an unsigned long (4 octets).
Definition: OLE.php:279
const OLE_PPS_TYPE_DIR
Definition: OLE.php:27
getStream($blockIdOrPps)
Returns a stream for use with fread() etc.
Definition: OLE.php:223
Definition: PPS.php:33
_readInt1($fh)
Reads a signed char.
Definition: OLE.php:255
const OLE_PPS_TYPE_FILE
Definition: OLE.php:28
const OLE_PPS_TYPE_ROOT
Constants for OLE package.
Definition: OLE.php:26
_ppsTreeComplete($index)
It checks whether the PPS tree is complete (all PPS's read) starting with the given PPS (not necessar...
Definition: OLE.php:372
_readInt2($fh)
Reads an unsigned short (2 octets).
Definition: OLE.php:267
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Asc2Ucs()

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().

474  {
475  $rawname = '';
476  for ($i = 0; $i < strlen($ascii); $i++) {
477  $rawname .= $ascii{$i} . "\x00";
478  }
479  return $rawname;
480  }
+ Here is the caller graph for this function:

◆ getData()

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 $data, and getStream().

436  {
437  // if position is not valid return empty string
438  if (!isset($this->_list[$index]) ||
439  $position >= $this->_list[$index]->Size ||
440  $position < 0) {
441 
442  return '';
443  }
444  $fh = $this->getStream($this->_list[$index]);
445  $data = stream_get_contents($fh, $length, $position);
446  fclose($fh);
447  return $data;
448  }
getStream($blockIdOrPps)
Returns a stream for use with fread() etc.
Definition: OLE.php:223
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
+ Here is the call graph for this function:

◆ getDataLength()

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.

458  {
459  if (isset($this->_list[$index])) {
460  return $this->_list[$index]->Size;
461  }
462  return 0;
463  }

◆ getStream()

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().

224  {
225  include_once 'OLE/ChainedBlockStream.php';
226  static $isRegistered = false;
227  if (!$isRegistered) {
228  stream_wrapper_register('ole-chainedblockstream',
229  'OLE_ChainedBlockStream');
230  $isRegistered = true;
231  }
232 
233  // Store current instance in global array, so that it can be accessed
234  // in OLE_ChainedBlockStream::stream_open().
235  // Object is removed from self::$instances in OLE_Stream::close().
236  $GLOBALS['_OLE_INSTANCES'][] = $this;
237  $instanceId = end(array_keys($GLOBALS['_OLE_INSTANCES']));
238 
239  $path = 'ole-chainedblockstream://oleInstanceId=' . $instanceId;
240  if (is_a($blockIdOrPps, 'OLE_PPS')) {
241  $path .= '&blockId=' . $blockIdOrPps->_StartBlock;
242  $path .= '&size=' . $blockIdOrPps->Size;
243  } else {
244  $path .= '&blockId=' . $blockIdOrPps;
245  }
246  return fopen($path, 'r');
247  }
$path
Definition: index.php:22
$GLOBALS['_OLE_INSTANCES']
Definition: OLE.php:40
+ Here is the caller graph for this function:

◆ isFile()

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.

392  {
393  if (isset($this->_list[$index])) {
394  return ($this->_list[$index]->Type == OLE_PPS_TYPE_FILE);
395  }
396  return false;
397  }
const OLE_PPS_TYPE_FILE
Definition: OLE.php:28

◆ isRoot()

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.

407  {
408  if (isset($this->_list[$index])) {
409  return ($this->_list[$index]->Type == OLE_PPS_TYPE_ROOT);
410  }
411  return false;
412  }
const OLE_PPS_TYPE_ROOT
Constants for OLE package.
Definition: OLE.php:26

◆ LocalDate2OLE()

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().

492  {
493  if (!isset($date)) {
494  return "\x00\x00\x00\x00\x00\x00\x00\x00";
495  }
496 
497  // factor used for separating numbers into 4 bytes parts
498  $factor = pow(2, 32);
499 
500  // days from 1-1-1601 until the beggining of UNIX era
501  $days = 134774;
502  // calculate seconds
503  $big_date = $days * 24 * 3600 +
504  gmmktime(date("H",$date),date("i",$date),date("s",$date),
505  date("m",$date),date("d",$date),date("Y",$date));
506  // multiply just to make MS happy
507  $big_date *= 10000000;
508 
509  $high_part = floor($big_date / $factor);
510  // lower 4 bytes
511  $low_part = floor((($big_date / $factor) - $high_part) * $factor);
512 
513  // Make HEX string
514  $res = '';
515 
516  for ($i = 0; $i < 4; $i++) {
517  $hex = $low_part % 0x100;
518  $res .= pack('c', $hex);
519  $low_part /= 0x100;
520  }
521  for ($i = 0; $i < 4; $i++) {
522  $hex = $high_part % 0x100;
523  $res .= pack('c', $hex);
524  $high_part /= 0x100;
525  }
526  return $res;
527  }
+ Here is the caller graph for this function:

◆ OLE()

OLE::OLE ( )

Creates a new OLE object public.

Definition at line 99 of file OLE.php.

100  {
101  $this->_list = array();
102  }

◆ OLE2LocalDate()

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().

537  {
538  if (strlen($string) != 8) {
539  return new PEAR_Error("Expecting 8 byte string");
540  }
541 
542  // factor used for separating numbers into 4 bytes parts
543  $factor = pow(2,32);
544  $high_part = 0;
545  for ($i = 0; $i < 4; $i++) {
546  list(, $high_part) = unpack('C', $string{(7 - $i)});
547  if ($i < 3) {
548  $high_part *= 0x100;
549  }
550  }
551  $low_part = 0;
552  for ($i = 4; $i < 8; $i++) {
553  list(, $low_part) = unpack('C', $string{(7 - $i)});
554  if ($i < 7) {
555  $low_part *= 0x100;
556  }
557  }
558  $big_date = ($high_part * $factor) + $low_part;
559  // translate to seconds
560  $big_date /= 10000000;
561 
562  // days from 1-1-1601 until the beggining of UNIX era
563  $days = 134774;
564 
565  // translate to seconds from beggining of UNIX era
566  $big_date -= $days * 24 * 3600;
567  return floor($big_date);
568  }
+ Here is the caller graph for this function:

◆ ppsTotal()

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.

420  {
421  return count($this->_list);
422  }

◆ read()

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().

123  {
124  $fh = @fopen($file, "r");
125  if (!$fh) {
126  return $this->raiseError("Can't open file $file");
127  }
128  $this->_file_handle = $fh;
129 
130  $signature = fread($fh, 8);
131  if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) {
132  return $this->raiseError("File doesn't seem to be an OLE container.");
133  }
134  fseek($fh, 28);
135  if (fread($fh, 2) != "\xFE\xFF") {
136  // This shouldn't be a problem in practice
137  return $this->raiseError("Only Little-Endian encoding is supported.");
138  }
139  // Size of blocks and short blocks in bytes
140  $this->bigBlockSize = pow(2, $this->_readInt2($fh));
141  $this->smallBlockSize = pow(2, $this->_readInt2($fh));
142 
143  // Skip UID, revision number and version number
144  fseek($fh, 44);
145  // Number of blocks in Big Block Allocation Table
146  $bbatBlockCount = $this->_readInt4($fh);
147 
148  // Root chain 1st block
149  $directoryFirstBlockId = $this->_readInt4($fh);
150 
151  // Skip unused bytes
152  fseek($fh, 56);
153  // Streams shorter than this are stored using small blocks
154  $this->bigBlockThreshold = $this->_readInt4($fh);
155  // Block id of first sector in Short Block Allocation Table
156  $sbatFirstBlockId = $this->_readInt4($fh);
157  // Number of blocks in Short Block Allocation Table
158  $sbbatBlockCount = $this->_readInt4($fh);
159  // Block id of first sector in Master Block Allocation Table
160  $mbatFirstBlockId = $this->_readInt4($fh);
161  // Number of blocks in Master Block Allocation Table
162  $mbbatBlockCount = $this->_readInt4($fh);
163  $this->bbat = array();
164 
165  // Remaining 4 * 109 bytes of current block is beginning of Master
166  // Block Allocation Table
167  $mbatBlocks = array();
168  for ($i = 0; $i < 109; $i++) {
169  $mbatBlocks[] = $this->_readInt4($fh);
170  }
171 
172  // Read rest of Master Block Allocation Table (if any is left)
173  $pos = $this->_getBlockOffset($mbatFirstBlockId);
174  for ($i = 0; $i < $mbbatBlockCount; $i++) {
175  fseek($fh, $pos);
176  for ($j = 0; $j < $this->bigBlockSize / 4 - 1; $j++) {
177  $mbatBlocks[] = $this->_readInt4($fh);
178  }
179  // Last block id in each block points to next block
180  $pos = $this->_getBlockOffset($this->_readInt4($fh));
181  }
182 
183  // Read Big Block Allocation Table according to chain specified by
184  // $mbatBlocks
185  for ($i = 0; $i < $bbatBlockCount; $i++) {
186  $pos = $this->_getBlockOffset($mbatBlocks[$i]);
187  fseek($fh, $pos);
188  for ($j = 0 ; $j < $this->bigBlockSize / 4; $j++) {
189  $this->bbat[] = $this->_readInt4($fh);
190  }
191  }
192 
193  // Read short block allocation table (SBAT)
194  $this->sbat = array();
195  $shortBlockCount = $sbbatBlockCount * $this->bigBlockSize / 4;
196  $sbatFh = $this->getStream($sbatFirstBlockId);
197  for ($blockId = 0; $blockId < $shortBlockCount; $blockId++) {
198  $this->sbat[$blockId] = $this->_readInt4($sbatFh);
199  }
200  fclose($sbatFh);
201 
202  $this->_readPpsWks($directoryFirstBlockId);
203 
204  return true;
205  }
print $file
_readInt4($fh)
Reads an unsigned long (4 octets).
Definition: OLE.php:279
getStream($blockIdOrPps)
Returns a stream for use with fread() etc.
Definition: OLE.php:223
_readPpsWks($blockId)
Gets information about all PPS&#39;s on the OLE container from the PPS WK&#39;s creates an OLE_PPS object for...
Definition: OLE.php:293
_getBlockOffset($blockId)
Definition: OLE.php:212
& 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&#39;s de...
Definition: PEAR.php:524
_readInt2($fh)
Reads an unsigned short (2 octets).
Definition: OLE.php:267
+ Here is the call graph for this function:

Field Documentation

◆ $_file_handle

OLE::$_file_handle

Definition at line 57 of file OLE.php.

◆ $_list

OLE::$_list

Definition at line 63 of file OLE.php.

◆ $bbat

OLE::$bbat

Definition at line 75 of file OLE.php.

◆ $bigBlockSize

OLE::$bigBlockSize

Definition at line 87 of file OLE.php.

Referenced by _getBlockOffset().

◆ $root

OLE::$root

Definition at line 69 of file OLE.php.

◆ $sbat

OLE::$sbat

Definition at line 81 of file OLE.php.

◆ $smallBlockSize

OLE::$smallBlockSize

Definition at line 93 of file OLE.php.


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