ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
PHPExcel_Shared_OLE Class Reference
+ Collaboration diagram for PHPExcel_Shared_OLE:

Public Member Functions

 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...
 
 _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...
 

Static Public Member Functions

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

Data Fields

const OLE_PPS_TYPE_ROOT = 5
 
const OLE_PPS_TYPE_DIR = 1
 
const OLE_PPS_TYPE_FILE = 2
 
const OLE_DATA_SIZE_SMALL = 0x1000
 
const OLE_LONG_INT_SIZE = 4
 
const OLE_PPS_SIZE = 0x80
 
 $_file_handle
 
 $_list = array()
 
 $root
 
 $bbat
 
 $sbat
 
 $bigBlockSize
 
 $smallBlockSize
 

Static Private Member Functions

static _readInt1 ($fh)
 Reads a signed char. More...
 
static _readInt2 ($fh)
 Reads an unsigned short (2 octets). More...
 
static _readInt4 ($fh)
 Reads an unsigned long (4 octets). More...
 

Detailed Description

Definition at line 38 of file OLE.php.

Member Function Documentation

◆ _getBlockOffset()

PHPExcel_Shared_OLE::_getBlockOffset (   $blockId)
Parameters
intblock id
intbyte offset from beginning of file public

Definition at line 186 of file OLE.php.

References $bigBlockSize.

Referenced by read().

187  {
188  return 512 + $blockId * $this->bigBlockSize;
189  }
+ Here is the caller graph for this function:

◆ _ppsTreeComplete()

PHPExcel_Shared_OLE::_ppsTreeComplete (   $index)

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

public

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 343 of file OLE.php.

Referenced by _readPpsWks().

344  {
345  return isset($this->_list[$index]) &&
346  ($pps = $this->_list[$index]) &&
347  ($pps->PrevPps == -1 ||
348  $this->_ppsTreeComplete($pps->PrevPps)) &&
349  ($pps->NextPps == -1 ||
350  $this->_ppsTreeComplete($pps->NextPps)) &&
351  ($pps->DirPps == -1 ||
352  $this->_ppsTreeComplete($pps->DirPps));
353  }
+ Here is the caller graph for this function:

◆ _readInt1()

static PHPExcel_Shared_OLE::_readInt1 (   $fh)
staticprivate

Reads a signed char.

Parameters
resourcefile handle
Returns
int public

Definition at line 228 of file OLE.php.

References $fh.

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

◆ _readInt2()

static PHPExcel_Shared_OLE::_readInt2 (   $fh)
staticprivate

Reads an unsigned short (2 octets).

Parameters
resourcefile handle
Returns
int public

Definition at line 240 of file OLE.php.

References $fh.

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

◆ _readInt4()

static PHPExcel_Shared_OLE::_readInt4 (   $fh)
staticprivate

Reads an unsigned long (4 octets).

Parameters
resourcefile handle
Returns
int public

Definition at line 252 of file OLE.php.

References $fh.

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

◆ _readPpsWks()

PHPExcel_Shared_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.

public

Parameters
integerthe block id of the first block
Returns
mixed true on success, PEAR_Error on failure

Definition at line 266 of file OLE.php.

References $fh, _ppsTreeComplete(), array, and getStream().

Referenced by read().

267  {
268  $fh = $this->getStream($blockId);
269  for ($pos = 0; ; $pos += 128) {
270  fseek($fh, $pos, SEEK_SET);
271  $nameUtf16 = fread($fh, 64);
272  $nameLength = self::_readInt2($fh);
273  $nameUtf16 = substr($nameUtf16, 0, $nameLength - 2);
274  // Simple conversion from UTF-16LE to ISO-8859-1
275  $name = str_replace("\x00", "", $nameUtf16);
276  $type = self::_readInt1($fh);
277  switch ($type) {
278  case self::OLE_PPS_TYPE_ROOT:
279  $pps = new PHPExcel_Shared_OLE_PPS_Root(null, null, array());
280  $this->root = $pps;
281  break;
282  case self::OLE_PPS_TYPE_DIR:
283  $pps = new PHPExcel_Shared_OLE_PPS(null, null, null, null, null,
284  null, null, null, null, array());
285  break;
286  case self::OLE_PPS_TYPE_FILE:
287  $pps = new PHPExcel_Shared_OLE_PPS_File($name);
288  break;
289  default:
290  continue;
291  }
292  fseek($fh, 1, SEEK_CUR);
293  $pps->Type = $type;
294  $pps->Name = $name;
295  $pps->PrevPps = self::_readInt4($fh);
296  $pps->NextPps = self::_readInt4($fh);
297  $pps->DirPps = self::_readInt4($fh);
298  fseek($fh, 20, SEEK_CUR);
299  $pps->Time1st = self::OLE2LocalDate(fread($fh, 8));
300  $pps->Time2nd = self::OLE2LocalDate(fread($fh, 8));
301  $pps->_StartBlock = self::_readInt4($fh);
302  $pps->Size = self::_readInt4($fh);
303  $pps->No = count($this->_list);
304  $this->_list[] = $pps;
305 
306  // check if the PPS tree (starting from root) is complete
307  if (isset($this->root) &&
308  $this->_ppsTreeComplete($this->root->No)) {
309 
310  break;
311  }
312  }
313  fclose($fh);
314 
315  // Initialize $pps->children on directories
316  foreach ($this->_list as $pps) {
317  if ($pps->Type == self::OLE_PPS_TYPE_DIR || $pps->Type == self::OLE_PPS_TYPE_ROOT) {
318  $nos = array($pps->DirPps);
319  $pps->children = array();
320  while ($nos) {
321  $no = array_pop($nos);
322  if ($no != -1) {
323  $childPps = $this->_list[$no];
324  $nos[] = $childPps->PrevPps;
325  $nos[] = $childPps->NextPps;
326  $pps->children[] = $childPps;
327  }
328  }
329  }
330  }
331 
332  return true;
333  }
_ppsTreeComplete($index)
It checks whether the PPS tree is complete (all PPS's read) starting with the given PPS (not necessar...
Definition: OLE.php:343
getStream($blockIdOrPps)
Returns a stream for use with fread() etc.
Definition: OLE.php:197
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Asc2Ucs()

static PHPExcel_Shared_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 446 of file OLE.php.

Referenced by PHPExcel_Shared_OLE_PPS_Root\__construct(), and PHPExcel_Writer_Excel5\save().

447  {
448  $rawname = '';
449  for ($i = 0; $i < strlen($ascii); ++$i) {
450  $rawname .= $ascii{$i} . "\x00";
451  }
452  return $rawname;
453  }
+ Here is the caller graph for this function:

◆ getData()

PHPExcel_Shared_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
See also
OLE_PPS_File::getStream()

Definition at line 410 of file OLE.php.

References $data, $fh, and getStream().

411  {
412  // if position is not valid return empty string
413  if (!isset($this->_list[$index]) || ($position >= $this->_list[$index]->Size) || ($position < 0)) {
414  return '';
415  }
416  $fh = $this->getStream($this->_list[$index]);
417  $data = stream_get_contents($fh, $length, $position);
418  fclose($fh);
419  return $data;
420  }
getStream($blockIdOrPps)
Returns a stream for use with fread() etc.
Definition: OLE.php:197
+ Here is the call graph for this function:

◆ getDataLength()

PHPExcel_Shared_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 430 of file OLE.php.

431  {
432  if (isset($this->_list[$index])) {
433  return $this->_list[$index]->Size;
434  }
435  return 0;
436  }

◆ getStream()

PHPExcel_Shared_OLE::getStream (   $blockIdOrPps)

Returns a stream for use with fread() etc.

External callers should use PHPExcel_Shared_OLE_PPS_File::getStream().

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

Definition at line 197 of file OLE.php.

References $GLOBALS, and $path.

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

198  {
199  static $isRegistered = false;
200  if (!$isRegistered) {
201  stream_wrapper_register('ole-chainedblockstream',
202  'PHPExcel_Shared_OLE_ChainedBlockStream');
203  $isRegistered = true;
204  }
205 
206  // Store current instance in global array, so that it can be accessed
207  // in OLE_ChainedBlockStream::stream_open().
208  // Object is removed from self::$instances in OLE_Stream::close().
209  $GLOBALS['_OLE_INSTANCES'][] = $this;
210  $instanceId = end(array_keys($GLOBALS['_OLE_INSTANCES']));
211 
212  $path = 'ole-chainedblockstream://oleInstanceId=' . $instanceId;
213  if ($blockIdOrPps instanceof PHPExcel_Shared_OLE_PPS) {
214  $path .= '&blockId=' . $blockIdOrPps->_StartBlock;
215  $path .= '&size=' . $blockIdOrPps->Size;
216  } else {
217  $path .= '&blockId=' . $blockIdOrPps;
218  }
219  return fopen($path, 'r');
220  }
$path
Definition: aliased.php:25
$GLOBALS['_OLE_INSTANCES']
Definition: OLE.php:28
+ Here is the caller graph for this function:

◆ isFile()

PHPExcel_Shared_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 363 of file OLE.php.

364  {
365  if (isset($this->_list[$index])) {
366  return ($this->_list[$index]->Type == self::OLE_PPS_TYPE_FILE);
367  }
368  return false;
369  }

◆ isRoot()

PHPExcel_Shared_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 379 of file OLE.php.

380  {
381  if (isset($this->_list[$index])) {
382  return ($this->_list[$index]->Type == self::OLE_PPS_TYPE_ROOT);
383  }
384  return false;
385  }

◆ LocalDate2OLE()

static PHPExcel_Shared_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 464 of file OLE.php.

References $res, and date.

Referenced by PHPExcel_Shared_OLE_PPS\_getPpsWk(), and PHPExcel_Writer_Excel5\_writeSummaryInformation().

465  {
466  if (!isset($date)) {
467  return "\x00\x00\x00\x00\x00\x00\x00\x00";
468  }
469 
470  // factor used for separating numbers into 4 bytes parts
471  $factor = pow(2, 32);
472 
473  // days from 1-1-1601 until the beggining of UNIX era
474  $days = 134774;
475  // calculate seconds
476  $big_date = $days*24*3600 + gmmktime(date("H",$date),date("i",$date),date("s",$date),
477  date("m",$date),date("d",$date),date("Y",$date));
478  // multiply just to make MS happy
479  $big_date *= 10000000;
480 
481  $high_part = floor($big_date / $factor);
482  // lower 4 bytes
483  $low_part = floor((($big_date / $factor) - $high_part) * $factor);
484 
485  // Make HEX string
486  $res = '';
487 
488  for ($i = 0; $i < 4; ++$i) {
489  $hex = $low_part % 0x100;
490  $res .= pack('c', $hex);
491  $low_part /= 0x100;
492  }
493  for ($i = 0; $i < 4; ++$i) {
494  $hex = $high_part % 0x100;
495  $res .= pack('c', $hex);
496  $high_part /= 0x100;
497  }
498  return $res;
499  }
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
+ Here is the caller graph for this function:

◆ OLE2LocalDate()

static PHPExcel_Shared_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 509 of file OLE.php.

Referenced by PHPExcel_Reader_Excel5\_readDocumentSummaryInformation(), and PHPExcel_Reader_Excel5\_readSummaryInformation().

510  {
511  if (strlen($string) != 8) {
512  return new PEAR_Error("Expecting 8 byte string");
513  }
514 
515  // factor used for separating numbers into 4 bytes parts
516  $factor = pow(2,32);
517  list(, $high_part) = unpack('V', substr($string, 4, 4));
518  list(, $low_part) = unpack('V', substr($string, 0, 4));
519 
520  $big_date = ($high_part * $factor) + $low_part;
521  // translate to seconds
522  $big_date /= 10000000;
523 
524  // days from 1-1-1601 until the beggining of UNIX era
525  $days = 134774;
526 
527  // translate to seconds from beggining of UNIX era
528  $big_date -= $days * 24 * 3600;
529  return floor($big_date);
530  }
+ Here is the caller graph for this function:

◆ ppsTotal()

PHPExcel_Shared_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 393 of file OLE.php.

394  {
395  return count($this->_list);
396  }

◆ read()

PHPExcel_Shared_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 96 of file OLE.php.

References $fh, $file, _getBlockOffset(), _readPpsWks(), array, and getStream().

97  {
98  $fh = fopen($file, "r");
99  if (!$fh) {
100  throw new PHPExcel_Reader_Exception("Can't open file $file");
101  }
102  $this->_file_handle = $fh;
103 
104  $signature = fread($fh, 8);
105  if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) {
106  throw new PHPExcel_Reader_Exception("File doesn't seem to be an OLE container.");
107  }
108  fseek($fh, 28);
109  if (fread($fh, 2) != "\xFE\xFF") {
110  // This shouldn't be a problem in practice
111  throw new PHPExcel_Reader_Exception("Only Little-Endian encoding is supported.");
112  }
113  // Size of blocks and short blocks in bytes
114  $this->bigBlockSize = pow(2, self::_readInt2($fh));
115  $this->smallBlockSize = pow(2, self::_readInt2($fh));
116 
117  // Skip UID, revision number and version number
118  fseek($fh, 44);
119  // Number of blocks in Big Block Allocation Table
120  $bbatBlockCount = self::_readInt4($fh);
121 
122  // Root chain 1st block
123  $directoryFirstBlockId = self::_readInt4($fh);
124 
125  // Skip unused bytes
126  fseek($fh, 56);
127  // Streams shorter than this are stored using small blocks
128  $this->bigBlockThreshold = self::_readInt4($fh);
129  // Block id of first sector in Short Block Allocation Table
130  $sbatFirstBlockId = self::_readInt4($fh);
131  // Number of blocks in Short Block Allocation Table
132  $sbbatBlockCount = self::_readInt4($fh);
133  // Block id of first sector in Master Block Allocation Table
134  $mbatFirstBlockId = self::_readInt4($fh);
135  // Number of blocks in Master Block Allocation Table
136  $mbbatBlockCount = self::_readInt4($fh);
137  $this->bbat = array();
138 
139  // Remaining 4 * 109 bytes of current block is beginning of Master
140  // Block Allocation Table
141  $mbatBlocks = array();
142  for ($i = 0; $i < 109; ++$i) {
143  $mbatBlocks[] = self::_readInt4($fh);
144  }
145 
146  // Read rest of Master Block Allocation Table (if any is left)
147  $pos = $this->_getBlockOffset($mbatFirstBlockId);
148  for ($i = 0; $i < $mbbatBlockCount; ++$i) {
149  fseek($fh, $pos);
150  for ($j = 0; $j < $this->bigBlockSize / 4 - 1; ++$j) {
151  $mbatBlocks[] = self::_readInt4($fh);
152  }
153  // Last block id in each block points to next block
154  $pos = $this->_getBlockOffset(self::_readInt4($fh));
155  }
156 
157  // Read Big Block Allocation Table according to chain specified by
158  // $mbatBlocks
159  for ($i = 0; $i < $bbatBlockCount; ++$i) {
160  $pos = $this->_getBlockOffset($mbatBlocks[$i]);
161  fseek($fh, $pos);
162  for ($j = 0 ; $j < $this->bigBlockSize / 4; ++$j) {
163  $this->bbat[] = self::_readInt4($fh);
164  }
165  }
166 
167  // Read short block allocation table (SBAT)
168  $this->sbat = array();
169  $shortBlockCount = $sbbatBlockCount * $this->bigBlockSize / 4;
170  $sbatFh = $this->getStream($sbatFirstBlockId);
171  for ($blockId = 0; $blockId < $shortBlockCount; ++$blockId) {
172  $this->sbat[$blockId] = self::_readInt4($sbatFh);
173  }
174  fclose($sbatFh);
175 
176  $this->_readPpsWks($directoryFirstBlockId);
177 
178  return true;
179  }
_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:266
_getBlockOffset($blockId)
Definition: OLE.php:186
getStream($blockIdOrPps)
Returns a stream for use with fread() etc.
Definition: OLE.php:197
Create styles array
The data for the language used.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:

Field Documentation

◆ $_file_handle

PHPExcel_Shared_OLE::$_file_handle

Definition at line 51 of file OLE.php.

◆ $_list

PHPExcel_Shared_OLE::$_list = array()

Definition at line 57 of file OLE.php.

◆ $bbat

PHPExcel_Shared_OLE::$bbat

Definition at line 69 of file OLE.php.

◆ $bigBlockSize

PHPExcel_Shared_OLE::$bigBlockSize

Definition at line 81 of file OLE.php.

Referenced by _getBlockOffset().

◆ $root

PHPExcel_Shared_OLE::$root

Definition at line 63 of file OLE.php.

◆ $sbat

PHPExcel_Shared_OLE::$sbat

Definition at line 75 of file OLE.php.

◆ $smallBlockSize

PHPExcel_Shared_OLE::$smallBlockSize

Definition at line 87 of file OLE.php.

◆ OLE_DATA_SIZE_SMALL

const PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL = 0x1000

◆ OLE_LONG_INT_SIZE

◆ OLE_PPS_SIZE

const PHPExcel_Shared_OLE::OLE_PPS_SIZE = 0x80

◆ OLE_PPS_TYPE_DIR

const PHPExcel_Shared_OLE::OLE_PPS_TYPE_DIR = 1

Definition at line 41 of file OLE.php.

Referenced by PHPExcel_Shared_OLE_PPS_Root\_saveBigData().

◆ OLE_PPS_TYPE_FILE

const PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE = 2

◆ OLE_PPS_TYPE_ROOT

const PHPExcel_Shared_OLE::OLE_PPS_TYPE_ROOT = 5

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