/branches/v2.6-greffoir/jrest/lib/PHPExcel/Classes/PHPExcel/Shared/OLE/PPS/File.php |
---|
New file |
0,0 → 1,84 |
<?php |
/* vim: set expandtab tabstop=4 shiftwidth=4: */ |
// +----------------------------------------------------------------------+ |
// | PHP Version 4 | |
// +----------------------------------------------------------------------+ |
// | Copyright (c) 1997-2002 The PHP Group | |
// +----------------------------------------------------------------------+ |
// | This source file is subject to version 2.02 of the PHP license, | |
// | that is bundled with this package in the file LICENSE, and is | |
// | available at through the world-wide-web at | |
// | http://www.php.net/license/2_02.txt. | |
// | If you did not receive a copy of the PHP license and are unable to | |
// | obtain it through the world-wide-web, please send a note to | |
// | license@php.net so we can mail you a copy immediately. | |
// +----------------------------------------------------------------------+ |
// | Author: Xavier Noguer <xnoguer@php.net> | |
// | Based on OLE::Storage_Lite by Kawai, Takanori | |
// +----------------------------------------------------------------------+ |
// |
// $Id: File.php,v 1.11 2007/02/13 21:00:42 schmidt Exp $ |
/** |
* Class for creating File PPS's for OLE containers |
* |
* @author Xavier Noguer <xnoguer@php.net> |
* @category PHPExcel |
* @package PHPExcel_Shared_OLE |
*/ |
class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS |
{ |
/** |
* The constructor |
* |
* @access public |
* @param string $name The name of the file (in Unicode) |
* @see OLE::Asc2Ucs() |
*/ |
public function __construct($name) |
{ |
parent::__construct( |
null, |
$name, |
PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE, |
null, |
null, |
null, |
null, |
null, |
'', |
array()); |
} |
/** |
* Initialization method. Has to be called right after OLE_PPS_File(). |
* |
* @access public |
* @return mixed true on success |
*/ |
public function init() |
{ |
return true; |
} |
/** |
* Append data to PPS |
* |
* @access public |
* @param string $data The data to append |
*/ |
public function append($data) |
{ |
$this->_data .= $data; |
} |
/** |
* Returns a stream for reading this file using fread() etc. |
* @return resource a read-only stream |
*/ |
public function getStream() |
{ |
$this->ole->getStream($this); |
} |
} |
/branches/v2.6-greffoir/jrest/lib/PHPExcel/Classes/PHPExcel/Shared/OLE/PPS/Root.php |
---|
New file |
0,0 → 1,467 |
<?php |
/* vim: set expandtab tabstop=4 shiftwidth=4: */ |
// +----------------------------------------------------------------------+ |
// | PHP Version 4 | |
// +----------------------------------------------------------------------+ |
// | Copyright (c) 1997-2002 The PHP Group | |
// +----------------------------------------------------------------------+ |
// | This source file is subject to version 2.02 of the PHP license, | |
// | that is bundled with this package in the file LICENSE, and is | |
// | available at through the world-wide-web at | |
// | http://www.php.net/license/2_02.txt. | |
// | If you did not receive a copy of the PHP license and are unable to | |
// | obtain it through the world-wide-web, please send a note to | |
// | license@php.net so we can mail you a copy immediately. | |
// +----------------------------------------------------------------------+ |
// | Author: Xavier Noguer <xnoguer@php.net> | |
// | Based on OLE::Storage_Lite by Kawai, Takanori | |
// +----------------------------------------------------------------------+ |
// |
// $Id: Root.php,v 1.9 2005/04/23 21:53:49 dufuz Exp $ |
/** |
* Class for creating Root PPS's for OLE containers |
* |
* @author Xavier Noguer <xnoguer@php.net> |
* @category PHPExcel |
* @package PHPExcel_Shared_OLE |
*/ |
class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS |
{ |
/** |
* Directory for temporary files |
* @var string |
*/ |
protected $_tmp_dir = NULL; |
/** |
* @param integer $time_1st A timestamp |
* @param integer $time_2nd A timestamp |
*/ |
public function __construct($time_1st, $time_2nd, $raChild) |
{ |
$this->_tempDir = PHPExcel_Shared_File::sys_get_temp_dir(); |
parent::__construct( |
null, |
PHPExcel_Shared_OLE::Asc2Ucs('Root Entry'), |
PHPExcel_Shared_OLE::OLE_PPS_TYPE_ROOT, |
null, |
null, |
null, |
$time_1st, |
$time_2nd, |
null, |
$raChild); |
} |
/** |
* Method for saving the whole OLE container (including files). |
* In fact, if called with an empty argument (or '-'), it saves to a |
* temporary file and then outputs it's contents to stdout. |
* If a resource pointer to a stream created by fopen() is passed |
* it will be used, but you have to close such stream by yourself. |
* |
* @param string|resource $filename The name of the file or stream where to save the OLE container. |
* @access public |
* @return mixed true on success |
*/ |
public function save($filename) |
{ |
// Initial Setting for saving |
$this->_BIG_BLOCK_SIZE = pow(2, |
((isset($this->_BIG_BLOCK_SIZE))? self::_adjust2($this->_BIG_BLOCK_SIZE) : 9)); |
$this->_SMALL_BLOCK_SIZE= pow(2, |
((isset($this->_SMALL_BLOCK_SIZE))? self::_adjust2($this->_SMALL_BLOCK_SIZE): 6)); |
if (is_resource($filename)) { |
$this->_FILEH_ = $filename; |
} else if ($filename == '-' || $filename == '') { |
if ($this->_tmp_dir === NULL) |
$this->_tmp_dir = PHPExcel_Shared_File::sys_get_temp_dir(); |
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root"); |
$this->_FILEH_ = fopen($this->_tmp_filename,"w+b"); |
if ($this->_FILEH_ == false) { |
throw new PHPExcel_Writer_Exception("Can't create temporary file."); |
} |
} else { |
$this->_FILEH_ = fopen($filename, "wb"); |
} |
if ($this->_FILEH_ == false) { |
throw new PHPExcel_Writer_Exception("Can't open $filename. It may be in use or protected."); |
} |
// Make an array of PPS's (for Save) |
$aList = array(); |
PHPExcel_Shared_OLE_PPS::_savePpsSetPnt($aList, array($this)); |
// calculate values for header |
list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->_calcSize($aList); //, $rhInfo); |
// Save Header |
$this->_saveHeader($iSBDcnt, $iBBcnt, $iPPScnt); |
// Make Small Data string (write SBD) |
$this->_data = $this->_makeSmallData($aList); |
// Write BB |
$this->_saveBigData($iSBDcnt, $aList); |
// Write PPS |
$this->_savePps($aList); |
// Write Big Block Depot and BDList and Adding Header informations |
$this->_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt); |
if (!is_resource($filename)) { |
fclose($this->_FILEH_); |
} |
return true; |
} |
/** |
* Calculate some numbers |
* |
* @access public |
* @param array $raList Reference to an array of PPS's |
* @return array The array of numbers |
*/ |
public function _calcSize(&$raList) |
{ |
// Calculate Basic Setting |
list($iSBDcnt, $iBBcnt, $iPPScnt) = array(0,0,0); |
$iSmallLen = 0; |
$iSBcnt = 0; |
$iCount = count($raList); |
for ($i = 0; $i < $iCount; ++$i) { |
if ($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE) { |
$raList[$i]->Size = $raList[$i]->_DataLen(); |
if ($raList[$i]->Size < PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL) { |
$iSBcnt += floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE) |
+ (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0); |
} else { |
$iBBcnt += (floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) + |
(($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0)); |
} |
} |
} |
$iSmallLen = $iSBcnt * $this->_SMALL_BLOCK_SIZE; |
$iSlCnt = floor($this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE); |
$iSBDcnt = floor($iSBcnt / $iSlCnt) + (($iSBcnt % $iSlCnt)? 1:0); |
$iBBcnt += (floor($iSmallLen / $this->_BIG_BLOCK_SIZE) + |
(( $iSmallLen % $this->_BIG_BLOCK_SIZE)? 1: 0)); |
$iCnt = count($raList); |
$iBdCnt = $this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_PPS_SIZE; |
$iPPScnt = (floor($iCnt/$iBdCnt) + (($iCnt % $iBdCnt)? 1: 0)); |
return array($iSBDcnt, $iBBcnt, $iPPScnt); |
} |
/** |
* Helper function for caculating a magic value for block sizes |
* |
* @access public |
* @param integer $i2 The argument |
* @see save() |
* @return integer |
*/ |
private static function _adjust2($i2) |
{ |
$iWk = log($i2)/log(2); |
return ($iWk > floor($iWk))? floor($iWk)+1:$iWk; |
} |
/** |
* Save OLE header |
* |
* @access public |
* @param integer $iSBDcnt |
* @param integer $iBBcnt |
* @param integer $iPPScnt |
*/ |
public function _saveHeader($iSBDcnt, $iBBcnt, $iPPScnt) |
{ |
$FILE = $this->_FILEH_; |
// Calculate Basic Setting |
$iBlCnt = $this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE; |
$i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE; |
$iBdExL = 0; |
$iAll = $iBBcnt + $iPPScnt + $iSBDcnt; |
$iAllW = $iAll; |
$iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0); |
$iBdCnt = floor(($iAll + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0); |
// Calculate BD count |
if ($iBdCnt > $i1stBdL) { |
while (1) { |
++$iBdExL; |
++$iAllW; |
$iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0); |
$iBdCnt = floor(($iAllW + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0); |
if ($iBdCnt <= ($iBdExL*$iBlCnt+ $i1stBdL)) { |
break; |
} |
} |
} |
// Save Header |
fwrite($FILE, |
"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" |
. "\x00\x00\x00\x00" |
. "\x00\x00\x00\x00" |
. "\x00\x00\x00\x00" |
. "\x00\x00\x00\x00" |
. pack("v", 0x3b) |
. pack("v", 0x03) |
. pack("v", -2) |
. pack("v", 9) |
. pack("v", 6) |
. pack("v", 0) |
. "\x00\x00\x00\x00" |
. "\x00\x00\x00\x00" |
. pack("V", $iBdCnt) |
. pack("V", $iBBcnt+$iSBDcnt) //ROOT START |
. pack("V", 0) |
. pack("V", 0x1000) |
. pack("V", $iSBDcnt ? 0 : -2) //Small Block Depot |
. pack("V", $iSBDcnt) |
); |
// Extra BDList Start, Count |
if ($iBdCnt < $i1stBdL) { |
fwrite($FILE, |
pack("V", -2) // Extra BDList Start |
. pack("V", 0) // Extra BDList Count |
); |
} else { |
fwrite($FILE, pack("V", $iAll+$iBdCnt) . pack("V", $iBdExL)); |
} |
// BDList |
for ($i = 0; $i < $i1stBdL && $i < $iBdCnt; ++$i) { |
fwrite($FILE, pack("V", $iAll+$i)); |
} |
if ($i < $i1stBdL) { |
$jB = $i1stBdL - $i; |
for ($j = 0; $j < $jB; ++$j) { |
fwrite($FILE, (pack("V", -1))); |
} |
} |
} |
/** |
* Saving big data (PPS's with data bigger than PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL) |
* |
* @access public |
* @param integer $iStBlk |
* @param array &$raList Reference to array of PPS's |
*/ |
public function _saveBigData($iStBlk, &$raList) |
{ |
$FILE = $this->_FILEH_; |
// cycle through PPS's |
$iCount = count($raList); |
for ($i = 0; $i < $iCount; ++$i) { |
if ($raList[$i]->Type != PHPExcel_Shared_OLE::OLE_PPS_TYPE_DIR) { |
$raList[$i]->Size = $raList[$i]->_DataLen(); |
if (($raList[$i]->Size >= PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL) || |
(($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_ROOT) && isset($raList[$i]->_data))) |
{ |
// Write Data |
//if (isset($raList[$i]->_PPS_FILE)) { |
// $iLen = 0; |
// fseek($raList[$i]->_PPS_FILE, 0); // To The Top |
// while($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) { |
// $iLen += strlen($sBuff); |
// fwrite($FILE, $sBuff); |
// } |
//} else { |
fwrite($FILE, $raList[$i]->_data); |
//} |
if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE) { |
fwrite($FILE, str_repeat("\x00", $this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE))); |
} |
// Set For PPS |
$raList[$i]->_StartBlock = $iStBlk; |
$iStBlk += |
(floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) + |
(($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0)); |
} |
// Close file for each PPS, and unlink it |
//if (isset($raList[$i]->_PPS_FILE)) { |
// fclose($raList[$i]->_PPS_FILE); |
// $raList[$i]->_PPS_FILE = null; |
// unlink($raList[$i]->_tmp_filename); |
//} |
} |
} |
} |
/** |
* get small data (PPS's with data smaller than PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL) |
* |
* @access public |
* @param array &$raList Reference to array of PPS's |
*/ |
public function _makeSmallData(&$raList) |
{ |
$sRes = ''; |
$FILE = $this->_FILEH_; |
$iSmBlk = 0; |
$iCount = count($raList); |
for ($i = 0; $i < $iCount; ++$i) { |
// Make SBD, small data string |
if ($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE) { |
if ($raList[$i]->Size <= 0) { |
continue; |
} |
if ($raList[$i]->Size < PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL) { |
$iSmbCnt = floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE) |
+ (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0); |
// Add to SBD |
$jB = $iSmbCnt - 1; |
for ($j = 0; $j < $jB; ++$j) { |
fwrite($FILE, pack("V", $j+$iSmBlk+1)); |
} |
fwrite($FILE, pack("V", -2)); |
//// Add to Data String(this will be written for RootEntry) |
//if ($raList[$i]->_PPS_FILE) { |
// fseek($raList[$i]->_PPS_FILE, 0); // To The Top |
// while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) { |
// $sRes .= $sBuff; |
// } |
//} else { |
$sRes .= $raList[$i]->_data; |
//} |
if ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) { |
$sRes .= str_repeat("\x00",$this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)); |
} |
// Set for PPS |
$raList[$i]->_StartBlock = $iSmBlk; |
$iSmBlk += $iSmbCnt; |
} |
} |
} |
$iSbCnt = floor($this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE); |
if ($iSmBlk % $iSbCnt) { |
$iB = $iSbCnt - ($iSmBlk % $iSbCnt); |
for ($i = 0; $i < $iB; ++$i) { |
fwrite($FILE, pack("V", -1)); |
} |
} |
return $sRes; |
} |
/** |
* Saves all the PPS's WKs |
* |
* @access public |
* @param array $raList Reference to an array with all PPS's |
*/ |
public function _savePps(&$raList) |
{ |
// Save each PPS WK |
$iC = count($raList); |
for ($i = 0; $i < $iC; ++$i) { |
fwrite($this->_FILEH_, $raList[$i]->_getPpsWk()); |
} |
// Adjust for Block |
$iCnt = count($raList); |
$iBCnt = $this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_PPS_SIZE; |
if ($iCnt % $iBCnt) { |
fwrite($this->_FILEH_, str_repeat("\x00",($iBCnt - ($iCnt % $iBCnt)) * PHPExcel_Shared_OLE::OLE_PPS_SIZE)); |
} |
} |
/** |
* Saving Big Block Depot |
* |
* @access public |
* @param integer $iSbdSize |
* @param integer $iBsize |
* @param integer $iPpsCnt |
*/ |
public function _saveBbd($iSbdSize, $iBsize, $iPpsCnt) |
{ |
$FILE = $this->_FILEH_; |
// Calculate Basic Setting |
$iBbCnt = $this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE; |
$i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE; |
$iBdExL = 0; |
$iAll = $iBsize + $iPpsCnt + $iSbdSize; |
$iAllW = $iAll; |
$iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0); |
$iBdCnt = floor(($iAll + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0); |
// Calculate BD count |
if ($iBdCnt >$i1stBdL) { |
while (1) { |
++$iBdExL; |
++$iAllW; |
$iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0); |
$iBdCnt = floor(($iAllW + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0); |
if ($iBdCnt <= ($iBdExL*$iBbCnt+ $i1stBdL)) { |
break; |
} |
} |
} |
// Making BD |
// Set for SBD |
if ($iSbdSize > 0) { |
for ($i = 0; $i < ($iSbdSize - 1); ++$i) { |
fwrite($FILE, pack("V", $i+1)); |
} |
fwrite($FILE, pack("V", -2)); |
} |
// Set for B |
for ($i = 0; $i < ($iBsize - 1); ++$i) { |
fwrite($FILE, pack("V", $i+$iSbdSize+1)); |
} |
fwrite($FILE, pack("V", -2)); |
// Set for PPS |
for ($i = 0; $i < ($iPpsCnt - 1); ++$i) { |
fwrite($FILE, pack("V", $i+$iSbdSize+$iBsize+1)); |
} |
fwrite($FILE, pack("V", -2)); |
// Set for BBD itself ( 0xFFFFFFFD : BBD) |
for ($i = 0; $i < $iBdCnt; ++$i) { |
fwrite($FILE, pack("V", 0xFFFFFFFD)); |
} |
// Set for ExtraBDList |
for ($i = 0; $i < $iBdExL; ++$i) { |
fwrite($FILE, pack("V", 0xFFFFFFFC)); |
} |
// Adjust for Block |
if (($iAllW + $iBdCnt) % $iBbCnt) { |
$iBlock = ($iBbCnt - (($iAllW + $iBdCnt) % $iBbCnt)); |
for ($i = 0; $i < $iBlock; ++$i) { |
fwrite($FILE, pack("V", -1)); |
} |
} |
// Extra BDList |
if ($iBdCnt > $i1stBdL) { |
$iN=0; |
$iNb=0; |
for ($i = $i1stBdL;$i < $iBdCnt; $i++, ++$iN) { |
if ($iN >= ($iBbCnt - 1)) { |
$iN = 0; |
++$iNb; |
fwrite($FILE, pack("V", $iAll+$iBdCnt+$iNb)); |
} |
fwrite($FILE, pack("V", $iBsize+$iSbdSize+$iPpsCnt+$i)); |
} |
if (($iBdCnt-$i1stBdL) % ($iBbCnt-1)) { |
$iB = ($iBbCnt - 1) - (($iBdCnt - $i1stBdL) % ($iBbCnt - 1)); |
for ($i = 0; $i < $iB; ++$i) { |
fwrite($FILE, pack("V", -1)); |
} |
} |
fwrite($FILE, pack("V", -2)); |
} |
} |
} |
/branches/v2.6-greffoir/jrest/lib/PHPExcel/Classes/PHPExcel/Shared/OLE/ChainedBlockStream.php |
---|
New file |
0,0 → 1,229 |
<?php |
/** |
* PHPExcel |
* |
* Copyright (C) 2006 - 2013 PHPExcel |
* |
* This library is free software; you can redistribute it and/or |
* modify it under the terms of the GNU Lesser General Public |
* License as published by the Free Software Foundation; either |
* version 2.1 of the License, or (at your option) any later version. |
* |
* This library is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
* Lesser General Public License for more details. |
* |
* You should have received a copy of the GNU Lesser General Public |
* License along with this library; if not, write to the Free Software |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
* |
* @category PHPExcel |
* @package PHPExcel_Shared_OLE |
* @copyright Copyright (c) 2006 - 2007 Christian Schmidt |
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
* @version ##VERSION##, ##DATE## |
*/ |
/** |
* PHPExcel_Shared_OLE_ChainedBlockStream |
* |
* Stream wrapper for reading data stored in an OLE file. Implements methods |
* for PHP's stream_wrapper_register(). For creating streams using this |
* wrapper, use PHPExcel_Shared_OLE_PPS_File::getStream(). |
* |
* @category PHPExcel |
* @package PHPExcel_Shared_OLE |
*/ |
class PHPExcel_Shared_OLE_ChainedBlockStream |
{ |
/** |
* The OLE container of the file that is being read. |
* @var OLE |
*/ |
public $ole; |
/** |
* Parameters specified by fopen(). |
* @var array |
*/ |
public $params; |
/** |
* The binary data of the file. |
* @var string |
*/ |
public $data; |
/** |
* The file pointer. |
* @var int byte offset |
*/ |
public $pos; |
/** |
* Implements support for fopen(). |
* For creating streams using this wrapper, use OLE_PPS_File::getStream(). |
* |
* @param string $path resource name including scheme, e.g. |
* ole-chainedblockstream://oleInstanceId=1 |
* @param string $mode only "r" is supported |
* @param int $options mask of STREAM_REPORT_ERRORS and STREAM_USE_PATH |
* @param string &$openedPath absolute path of the opened stream (out parameter) |
* @return bool true on success |
*/ |
public function stream_open($path, $mode, $options, &$openedPath) |
{ |
if ($mode != 'r') { |
if ($options & STREAM_REPORT_ERRORS) { |
trigger_error('Only reading is supported', E_USER_WARNING); |
} |
return false; |
} |
// 25 is length of "ole-chainedblockstream://" |
parse_str(substr($path, 25), $this->params); |
if (!isset($this->params['oleInstanceId'], |
$this->params['blockId'], |
$GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']])) { |
if ($options & STREAM_REPORT_ERRORS) { |
trigger_error('OLE stream not found', E_USER_WARNING); |
} |
return false; |
} |
$this->ole = $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']]; |
$blockId = $this->params['blockId']; |
$this->data = ''; |
if (isset($this->params['size']) && |
$this->params['size'] < $this->ole->bigBlockThreshold && |
$blockId != $this->ole->root->_StartBlock) { |
// Block id refers to small blocks |
$rootPos = $this->ole->_getBlockOffset($this->ole->root->_StartBlock); |
while ($blockId != -2) { |
$pos = $rootPos + $blockId * $this->ole->bigBlockSize; |
$blockId = $this->ole->sbat[$blockId]; |
fseek($this->ole->_file_handle, $pos); |
$this->data .= fread($this->ole->_file_handle, $this->ole->bigBlockSize); |
} |
} else { |
// Block id refers to big blocks |
while ($blockId != -2) { |
$pos = $this->ole->_getBlockOffset($blockId); |
fseek($this->ole->_file_handle, $pos); |
$this->data .= fread($this->ole->_file_handle, $this->ole->bigBlockSize); |
$blockId = $this->ole->bbat[$blockId]; |
} |
} |
if (isset($this->params['size'])) { |
$this->data = substr($this->data, 0, $this->params['size']); |
} |
if ($options & STREAM_USE_PATH) { |
$openedPath = $path; |
} |
return true; |
} |
/** |
* Implements support for fclose(). |
* |
*/ |
public function stream_close() |
{ |
$this->ole = null; |
unset($GLOBALS['_OLE_INSTANCES']); |
} |
/** |
* Implements support for fread(), fgets() etc. |
* |
* @param int $count maximum number of bytes to read |
* @return string |
*/ |
public function stream_read($count) |
{ |
if ($this->stream_eof()) { |
return false; |
} |
$s = substr($this->data, $this->pos, $count); |
$this->pos += $count; |
return $s; |
} |
/** |
* Implements support for feof(). |
* |
* @return bool TRUE if the file pointer is at EOF; otherwise FALSE |
*/ |
public function stream_eof() |
{ |
$eof = $this->pos >= strlen($this->data); |
// Workaround for bug in PHP 5.0.x: http://bugs.php.net/27508 |
if (version_compare(PHP_VERSION, '5.0', '>=') && |
version_compare(PHP_VERSION, '5.1', '<')) { |
$eof = !$eof; |
} |
return $eof; |
} |
/** |
* Returns the position of the file pointer, i.e. its offset into the file |
* stream. Implements support for ftell(). |
* |
* @return int |
*/ |
public function stream_tell() |
{ |
return $this->pos; |
} |
/** |
* Implements support for fseek(). |
* |
* @param int $offset byte offset |
* @param int $whence SEEK_SET, SEEK_CUR or SEEK_END |
* @return bool |
*/ |
public function stream_seek($offset, $whence) |
{ |
if ($whence == SEEK_SET && $offset >= 0) { |
$this->pos = $offset; |
} elseif ($whence == SEEK_CUR && -$offset <= $this->pos) { |
$this->pos += $offset; |
} elseif ($whence == SEEK_END && -$offset <= sizeof($this->data)) { |
$this->pos = strlen($this->data) + $offset; |
} else { |
return false; |
} |
return true; |
} |
/** |
* Implements support for fstat(). Currently the only supported field is |
* "size". |
* @return array |
*/ |
public function stream_stat() |
{ |
return array( |
'size' => strlen($this->data), |
); |
} |
// Methods used by stream_wrapper_register() that are not implemented: |
// bool stream_flush ( void ) |
// int stream_write ( string data ) |
// bool rename ( string path_from, string path_to ) |
// bool mkdir ( string path, int mode, int options ) |
// bool rmdir ( string path, int options ) |
// bool dir_opendir ( string path, int options ) |
// array url_stat ( string path, int flags ) |
// string dir_readdir ( void ) |
// bool dir_rewinddir ( void ) |
// bool dir_closedir ( void ) |
} |
/branches/v2.6-greffoir/jrest/lib/PHPExcel/Classes/PHPExcel/Shared/OLE/PPS.php |
---|
New file |
0,0 → 1,230 |
<?php |
/* vim: set expandtab tabstop=4 shiftwidth=4: */ |
// +----------------------------------------------------------------------+ |
// | PHP Version 4 | |
// +----------------------------------------------------------------------+ |
// | Copyright (c) 1997-2002 The PHP Group | |
// +----------------------------------------------------------------------+ |
// | This source file is subject to version 2.02 of the PHP license, | |
// | that is bundled with this package in the file LICENSE, and is | |
// | available at through the world-wide-web at | |
// | http://www.php.net/license/2_02.txt. | |
// | If you did not receive a copy of the PHP license and are unable to | |
// | obtain it through the world-wide-web, please send a note to | |
// | license@php.net so we can mail you a copy immediately. | |
// +----------------------------------------------------------------------+ |
// | Author: Xavier Noguer <xnoguer@php.net> | |
// | Based on OLE::Storage_Lite by Kawai, Takanori | |
// +----------------------------------------------------------------------+ |
// |
// $Id: PPS.php,v 1.7 2007/02/13 21:00:42 schmidt Exp $ |
/** |
* Class for creating PPS's for OLE containers |
* |
* @author Xavier Noguer <xnoguer@php.net> |
* @category PHPExcel |
* @package PHPExcel_Shared_OLE |
*/ |
class PHPExcel_Shared_OLE_PPS |
{ |
/** |
* The PPS index |
* @var integer |
*/ |
public $No; |
/** |
* The PPS name (in Unicode) |
* @var string |
*/ |
public $Name; |
/** |
* The PPS type. Dir, Root or File |
* @var integer |
*/ |
public $Type; |
/** |
* The index of the previous PPS |
* @var integer |
*/ |
public $PrevPps; |
/** |
* The index of the next PPS |
* @var integer |
*/ |
public $NextPps; |
/** |
* The index of it's first child if this is a Dir or Root PPS |
* @var integer |
*/ |
public $DirPps; |
/** |
* A timestamp |
* @var integer |
*/ |
public $Time1st; |
/** |
* A timestamp |
* @var integer |
*/ |
public $Time2nd; |
/** |
* Starting block (small or big) for this PPS's data inside the container |
* @var integer |
*/ |
public $_StartBlock; |
/** |
* The size of the PPS's data (in bytes) |
* @var integer |
*/ |
public $Size; |
/** |
* The PPS's data (only used if it's not using a temporary file) |
* @var string |
*/ |
public $_data; |
/** |
* Array of child PPS's (only used by Root and Dir PPS's) |
* @var array |
*/ |
public $children = array(); |
/** |
* Pointer to OLE container |
* @var OLE |
*/ |
public $ole; |
/** |
* The constructor |
* |
* @access public |
* @param integer $No The PPS index |
* @param string $name The PPS name |
* @param integer $type The PPS type. Dir, Root or File |
* @param integer $prev The index of the previous PPS |
* @param integer $next The index of the next PPS |
* @param integer $dir The index of it's first child if this is a Dir or Root PPS |
* @param integer $time_1st A timestamp |
* @param integer $time_2nd A timestamp |
* @param string $data The (usually binary) source data of the PPS |
* @param array $children Array containing children PPS for this PPS |
*/ |
public function __construct($No, $name, $type, $prev, $next, $dir, $time_1st, $time_2nd, $data, $children) |
{ |
$this->No = $No; |
$this->Name = $name; |
$this->Type = $type; |
$this->PrevPps = $prev; |
$this->NextPps = $next; |
$this->DirPps = $dir; |
$this->Time1st = $time_1st; |
$this->Time2nd = $time_2nd; |
$this->_data = $data; |
$this->children = $children; |
if ($data != '') { |
$this->Size = strlen($data); |
} else { |
$this->Size = 0; |
} |
} |
/** |
* Returns the amount of data saved for this PPS |
* |
* @access public |
* @return integer The amount of data (in bytes) |
*/ |
public function _DataLen() |
{ |
if (!isset($this->_data)) { |
return 0; |
} |
//if (isset($this->_PPS_FILE)) { |
// fseek($this->_PPS_FILE, 0); |
// $stats = fstat($this->_PPS_FILE); |
// return $stats[7]; |
//} else { |
return strlen($this->_data); |
//} |
} |
/** |
* Returns a string with the PPS's WK (What is a WK?) |
* |
* @access public |
* @return string The binary string |
*/ |
public function _getPpsWk() |
{ |
$ret = str_pad($this->Name,64,"\x00"); |
$ret .= pack("v", strlen($this->Name) + 2) // 66 |
. pack("c", $this->Type) // 67 |
. pack("c", 0x00) //UK // 68 |
. pack("V", $this->PrevPps) //Prev // 72 |
. pack("V", $this->NextPps) //Next // 76 |
. pack("V", $this->DirPps) //Dir // 80 |
. "\x00\x09\x02\x00" // 84 |
. "\x00\x00\x00\x00" // 88 |
. "\xc0\x00\x00\x00" // 92 |
. "\x00\x00\x00\x46" // 96 // Seems to be ok only for Root |
. "\x00\x00\x00\x00" // 100 |
. PHPExcel_Shared_OLE::LocalDate2OLE($this->Time1st) // 108 |
. PHPExcel_Shared_OLE::LocalDate2OLE($this->Time2nd) // 116 |
. pack("V", isset($this->_StartBlock)? |
$this->_StartBlock:0) // 120 |
. pack("V", $this->Size) // 124 |
. pack("V", 0); // 128 |
return $ret; |
} |
/** |
* Updates index and pointers to previous, next and children PPS's for this |
* PPS. I don't think it'll work with Dir PPS's. |
* |
* @access public |
* @param array &$raList Reference to the array of PPS's for the whole OLE |
* container |
* @return integer The index for this PPS |
*/ |
public static function _savePpsSetPnt(&$raList, $to_save, $depth = 0) |
{ |
if ( !is_array($to_save) || (empty($to_save)) ) { |
return 0xFFFFFFFF; |
} elseif( count($to_save) == 1 ) { |
$cnt = count($raList); |
// If the first entry, it's the root... Don't clone it! |
$raList[$cnt] = ( $depth == 0 ) ? $to_save[0] : clone $to_save[0]; |
$raList[$cnt]->No = $cnt; |
$raList[$cnt]->PrevPps = 0xFFFFFFFF; |
$raList[$cnt]->NextPps = 0xFFFFFFFF; |
$raList[$cnt]->DirPps = self::_savePpsSetPnt($raList, @$raList[$cnt]->children, $depth++); |
} else { |
$iPos = floor(count($to_save) / 2); |
$aPrev = array_slice($to_save, 0, $iPos); |
$aNext = array_slice($to_save, $iPos + 1); |
$cnt = count($raList); |
// If the first entry, it's the root... Don't clone it! |
$raList[$cnt] = ( $depth == 0 ) ? $to_save[$iPos] : clone $to_save[$iPos]; |
$raList[$cnt]->No = $cnt; |
$raList[$cnt]->PrevPps = self::_savePpsSetPnt($raList, $aPrev, $depth++); |
$raList[$cnt]->NextPps = self::_savePpsSetPnt($raList, $aNext, $depth++); |
$raList[$cnt]->DirPps = self::_savePpsSetPnt($raList, @$raList[$cnt]->children, $depth++); |
} |
return $cnt; |
} |
} |