24 if (!defined(
'PHPEXCEL_ROOT')) {
28 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/../../../');
31 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/OLE/OLE_PPS.php';
78 $this->_tmp_dir =
$dir;
96 $this->_BIG_BLOCK_SIZE = pow(2,
97 ((isset($this->_BIG_BLOCK_SIZE))? $this->
_adjust2($this->_BIG_BLOCK_SIZE) : 9));
98 $this->_SMALL_BLOCK_SIZE= pow(2,
99 ((isset($this->_SMALL_BLOCK_SIZE))? $this->
_adjust2($this->_SMALL_BLOCK_SIZE): 6));
103 $this->_tmp_filename = tempnam($this->_tmp_dir,
"OLE_PPS_Root");
104 $this->_FILEH_ = fopen($this->_tmp_filename,
"w+b");
105 if ($this->_FILEH_ ==
false) {
106 throw new Exception(
"Can't create temporary file.");
110 if ($this->_FILEH_ ==
false) {
111 throw new Exception(
"Can't open $filename. It may be in use or protected.");
118 list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->
_calcSize($aList);
130 $this->
_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt);
133 fseek($this->_FILEH_, 0);
134 fpassthru($this->_FILEH_);
135 fclose($this->_FILEH_);
137 unlink($this->_tmp_filename);
139 fclose($this->_FILEH_);
155 list($iSBDcnt, $iBBcnt, $iPPScnt) = array(0,0,0);
158 for ($i = 0; $i < count($raList); ++$i) {
160 $raList[$i]->Size = $raList[$i]->_DataLen();
162 $iSBcnt += floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
163 + (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
165 $iBBcnt += (floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
166 (($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
170 $iSmallLen = $iSBcnt * $this->_SMALL_BLOCK_SIZE;
172 $iSBDcnt = floor($iSBcnt / $iSlCnt) + (($iSBcnt % $iSlCnt)? 1:0);
173 $iBBcnt += (floor($iSmallLen / $this->_BIG_BLOCK_SIZE) +
174 (( $iSmallLen % $this->_BIG_BLOCK_SIZE)? 1: 0));
175 $iCnt = count($raList);
177 $iPPScnt = (floor($iCnt/$iBdCnt) + (($iCnt % $iBdCnt)? 1: 0));
179 return array($iSBDcnt, $iBBcnt, $iPPScnt);
192 $iWk = log($i2)/log(2);
193 return ($iWk > floor($iWk))? floor($iWk)+1:$iWk;
206 $FILE = $this->_FILEH_;
213 $iAll = $iBBcnt + $iPPScnt + $iSBDcnt;
215 $iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
216 $iBdCnt = floor(($iAll + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
219 if ($iBdCnt > $i1stBdL) {
223 $iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
224 $iBdCnt = floor(($iAllW + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
225 if ($iBdCnt <= ($iBdExL*$iBlCnt+ $i1stBdL)) {
233 "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
247 . pack(
"V", $iBBcnt+$iSBDcnt)
250 . pack(
"V", $iSBDcnt ? 0 : -2)
254 if ($iBdCnt < $i1stBdL) {
260 fwrite($FILE, pack(
"V", $iAll+$iBdCnt) . pack(
"V", $iBdExL));
264 for ($i = 0; $i < $i1stBdL && $i < $iBdCnt; ++$i) {
265 fwrite($FILE, pack(
"V", $iAll+$i));
268 for ($j = 0; $j < ($i1stBdL-$i); ++$j) {
269 fwrite($FILE, (pack(
"V", -1)));
283 $FILE = $this->_FILEH_;
286 for ($i = 0; $i < count($raList); ++$i) {
288 $raList[$i]->Size = $raList[$i]->_DataLen();
293 if (isset($raList[$i]->_PPS_FILE)) {
295 fseek($raList[$i]->_PPS_FILE, 0);
296 while($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
297 $iLen += strlen($sBuff);
298 fwrite($FILE, $sBuff);
301 fwrite($FILE, $raList[$i]->_data);
304 if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE) {
305 for ($j = 0; $j < ($this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)); ++$j) {
306 fwrite($FILE,
"\x00");
310 $raList[$i]->_StartBlock = $iStBlk;
312 (floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
313 (($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
316 if (isset($raList[$i]->_PPS_FILE)) {
317 fclose($raList[$i]->_PPS_FILE);
318 $raList[$i]->_PPS_FILE = null;
319 unlink($raList[$i]->_tmp_filename);
334 $FILE = $this->_FILEH_;
337 for ($i = 0; $i < count($raList); ++$i) {
340 if ($raList[$i]->Size <= 0) {
344 $iSmbCnt = floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
345 + (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
347 for ($j = 0; $j < ($iSmbCnt-1); ++$j) {
348 fwrite($FILE, pack(
"V", $j+$iSmBlk+1));
350 fwrite($FILE, pack(
"V", -2));
353 if ($raList[$i]->_PPS_FILE) {
354 fseek($raList[$i]->_PPS_FILE, 0);
355 while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
359 $sRes .= $raList[$i]->_data;
361 if ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) {
362 for ($j = 0; $j < ($this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)); ++$j) {
367 $raList[$i]->_StartBlock = $iSmBlk;
373 if ($iSmBlk % $iSbCnt) {
374 for ($i = 0; $i < ($iSbCnt - ($iSmBlk % $iSbCnt)); ++$i) {
375 fwrite($FILE, pack(
"V", -1));
390 for ($i = 0; $i < count($raList); ++$i) {
391 fwrite($this->_FILEH_, $raList[$i]->
_getPpsWk());
394 $iCnt = count($raList);
396 if ($iCnt % $iBCnt) {
398 fwrite($this->_FILEH_,
"\x00");
411 public function _saveBbd($iSbdSize, $iBsize, $iPpsCnt)
413 $FILE = $this->_FILEH_;
419 $iAll = $iBsize + $iPpsCnt + $iSbdSize;
421 $iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
422 $iBdCnt = floor(($iAll + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
424 if ($iBdCnt >$i1stBdL) {
428 $iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
429 $iBdCnt = floor(($iAllW + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
430 if ($iBdCnt <= ($iBdExL*$iBbCnt+ $i1stBdL)) {
439 for ($i = 0; $i < ($iSbdSize - 1); ++$i) {
440 fwrite($FILE, pack(
"V", $i+1));
442 fwrite($FILE, pack(
"V", -2));
445 for ($i = 0; $i < ($iBsize - 1); ++$i) {
446 fwrite($FILE, pack(
"V", $i+$iSbdSize+1));
448 fwrite($FILE, pack(
"V", -2));
451 for ($i = 0; $i < ($iPpsCnt - 1); ++$i) {
452 fwrite($FILE, pack(
"V", $i+$iSbdSize+$iBsize+1));
454 fwrite($FILE, pack(
"V", -2));
456 for ($i = 0; $i < $iBdCnt; ++$i) {
457 fwrite($FILE, pack(
"V", 0xFFFFFFFD));
460 for ($i = 0; $i < $iBdExL; ++$i) {
461 fwrite($FILE, pack(
"V", 0xFFFFFFFC));
464 if (($iAllW + $iBdCnt) % $iBbCnt) {
465 for ($i = 0; $i < ($iBbCnt - (($iAllW + $iBdCnt) % $iBbCnt)); ++$i) {
466 fwrite($FILE, pack(
"V", -1));
470 if ($iBdCnt > $i1stBdL) {
473 for ($i = $i1stBdL;$i < $iBdCnt; $i++, ++$iN) {
474 if ($iN >= ($iBbCnt - 1)) {
477 fwrite($FILE, pack(
"V", $iAll+$iBdCnt+$iNb));
479 fwrite($FILE, pack(
"V", $iBsize+$iSbdSize+$iPpsCnt+$i));
481 if (($iBdCnt-$i1stBdL) % ($iBbCnt-1)) {
482 for ($i = 0; $i < (($iBbCnt - 1) - (($iBdCnt - $i1stBdL) % ($iBbCnt - 1))); ++$i) {
483 fwrite($FILE, pack(
"V", -1));
486 fwrite($FILE, pack(
"V", -2));