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. | |
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 |
Definition at line 43 of file OLE.php.
OLE::_OLE | ( | ) |
OLE::_ppsTreeComplete | ( | $ | index | ) |
It checks whether the PPS tree is complete (all PPS's read) starting with the given PPS (not necessarily root).
private
integer | $index The index of the PPS from which we are checking |
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; }
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
integer | $pps_wk_start Position inside the OLE file where PPS WK's start | |
integer | $big_block_size Size of big blobks in the OLE file |
Definition at line 143 of file OLE.php.
References $dir, $type, _ppsTreeComplete(), and OLE2LocalDate().
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 ($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; } }
OLE::Asc2Ucs | ( | $ | ascii | ) | [static] |
Utility function to transform ASCII text to Unicode.
public
string | $ascii The ASCII string to transform |
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; }
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
integer | $index The index for the PPS | |
integer | $position The position from which to start reading (relative to the PPS) | |
integer | $length The amount of bytes to read (at most) |
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
integer | $index The index for the PPS |
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
integer | $index The index for the PPS |
Definition at line 226 of file OLE.php.
{ 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
integer | $index The index for the PPS. |
Definition at line 242 of file OLE.php.
{ 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
integer | $date A timestamp |
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; }
OLE::OLE | ( | ) |
OLE::OLE2LocalDate | ( | $ | string | ) | [static] |
Returns a timestamp from an OLE container's date.
public
integer | $string A binary string with the encoded date |
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); }
OLE::ppsTotal | ( | ) |
OLE::read | ( | $ | file | ) |
Reads an OLE container from the contents of the file given.
public
string | $file |
Definition at line 74 of file OLE.php.
References $file, and _readPpsWks().
{ /* 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; }