PPS.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  8. // +----------------------------------------------------------------------+
  9. // | PHP Version 4 |
  10. // +----------------------------------------------------------------------+
  11. // | Copyright (c) 1997-2002 The PHP Group |
  12. // +----------------------------------------------------------------------+
  13. // | This source file is subject to version 2.02 of the PHP license, |
  14. // | that is bundled with this package in the file LICENSE, and is |
  15. // | available at through the world-wide-web at |
  16. // | http://www.php.net/license/2_02.txt. |
  17. // | If you did not receive a copy of the PHP license and are unable to |
  18. // | obtain it through the world-wide-web, please send a note to |
  19. // | license@php.net so we can mail you a copy immediately. |
  20. // +----------------------------------------------------------------------+
  21. // | Author: Xavier Noguer <xnoguer@php.net> |
  22. // | Based on OLE::Storage_Lite by Kawai, Takanori |
  23. // +----------------------------------------------------------------------+
  24. //
  25. // $Id: PPS.php,v 1.7 2007/02/13 21:00:42 schmidt Exp $
  26. /**
  27. * Class for creating PPS's for OLE containers
  28. *
  29. * @author Xavier Noguer <xnoguer@php.net>
  30. * @category PHPExcel
  31. * @package PHPExcel_Shared_OLE
  32. */
  33. class PHPExcel_Shared_OLE_PPS
  34. {
  35. /**
  36. * The PPS index
  37. * @var integer
  38. */
  39. public $No;
  40. /**
  41. * The PPS name (in Unicode)
  42. * @var string
  43. */
  44. public $Name;
  45. /**
  46. * The PPS type. Dir, Root or File
  47. * @var integer
  48. */
  49. public $Type;
  50. /**
  51. * The index of the previous PPS
  52. * @var integer
  53. */
  54. public $PrevPps;
  55. /**
  56. * The index of the next PPS
  57. * @var integer
  58. */
  59. public $NextPps;
  60. /**
  61. * The index of it's first child if this is a Dir or Root PPS
  62. * @var integer
  63. */
  64. public $DirPps;
  65. /**
  66. * A timestamp
  67. * @var integer
  68. */
  69. public $Time1st;
  70. /**
  71. * A timestamp
  72. * @var integer
  73. */
  74. public $Time2nd;
  75. /**
  76. * Starting block (small or big) for this PPS's data inside the container
  77. * @var integer
  78. */
  79. public $_StartBlock;
  80. /**
  81. * The size of the PPS's data (in bytes)
  82. * @var integer
  83. */
  84. public $Size;
  85. /**
  86. * The PPS's data (only used if it's not using a temporary file)
  87. * @var string
  88. */
  89. public $_data;
  90. /**
  91. * Array of child PPS's (only used by Root and Dir PPS's)
  92. * @var array
  93. */
  94. public $children = array();
  95. /**
  96. * Pointer to OLE container
  97. * @var OLE
  98. */
  99. public $ole;
  100. /**
  101. * The constructor
  102. *
  103. * @access public
  104. * @param integer $No The PPS index
  105. * @param string $name The PPS name
  106. * @param integer $type The PPS type. Dir, Root or File
  107. * @param integer $prev The index of the previous PPS
  108. * @param integer $next The index of the next PPS
  109. * @param integer $dir The index of it's first child if this is a Dir or Root PPS
  110. * @param integer $time_1st A timestamp
  111. * @param integer $time_2nd A timestamp
  112. * @param string $data The (usually binary) source data of the PPS
  113. * @param array $children Array containing children PPS for this PPS
  114. */
  115. public function __construct($No, $name, $type, $prev, $next, $dir, $time_1st, $time_2nd, $data, $children)
  116. {
  117. $this->No = $No;
  118. $this->Name = $name;
  119. $this->Type = $type;
  120. $this->PrevPps = $prev;
  121. $this->NextPps = $next;
  122. $this->DirPps = $dir;
  123. $this->Time1st = $time_1st;
  124. $this->Time2nd = $time_2nd;
  125. $this->_data = $data;
  126. $this->children = $children;
  127. if ($data != '') {
  128. $this->Size = strlen($data);
  129. } else {
  130. $this->Size = 0;
  131. }
  132. }
  133. /**
  134. * Returns the amount of data saved for this PPS
  135. *
  136. * @access public
  137. * @return integer The amount of data (in bytes)
  138. */
  139. public function _DataLen()
  140. {
  141. if (!isset($this->_data)) {
  142. return 0;
  143. }
  144. //if (isset($this->_PPS_FILE)) {
  145. // fseek($this->_PPS_FILE, 0);
  146. // $stats = fstat($this->_PPS_FILE);
  147. // return $stats[7];
  148. //} else {
  149. return strlen($this->_data);
  150. //}
  151. }
  152. /**
  153. * Returns a string with the PPS's WK (What is a WK?)
  154. *
  155. * @access public
  156. * @return string The binary string
  157. */
  158. public function _getPpsWk()
  159. {
  160. $ret = str_pad($this->Name, 64, "\x00");
  161. $ret .= pack("v", strlen($this->Name) + 2) // 66
  162. . pack("c", $this->Type) // 67
  163. . pack("c", 0x00) //UK // 68
  164. . pack("V", $this->PrevPps) //Prev // 72
  165. . pack("V", $this->NextPps) //Next // 76
  166. . pack("V", $this->DirPps) //Dir // 80
  167. . "\x00\x09\x02\x00" // 84
  168. . "\x00\x00\x00\x00" // 88
  169. . "\xc0\x00\x00\x00" // 92
  170. . "\x00\x00\x00\x46" // 96 // Seems to be ok only for Root
  171. . "\x00\x00\x00\x00" // 100
  172. . PHPExcel_Shared_OLE::LocalDate2OLE($this->Time1st) // 108
  173. . PHPExcel_Shared_OLE::LocalDate2OLE($this->Time2nd) // 116
  174. . pack("V", isset($this->_StartBlock)?
  175. $this->_StartBlock:0) // 120
  176. . pack("V", $this->Size) // 124
  177. . pack("V", 0); // 128
  178. return $ret;
  179. }
  180. /**
  181. * Updates index and pointers to previous, next and children PPS's for this
  182. * PPS. I don't think it'll work with Dir PPS's.
  183. *
  184. * @access public
  185. * @param array &$raList Reference to the array of PPS's for the whole OLE
  186. * container
  187. * @return integer The index for this PPS
  188. */
  189. public static function _savePpsSetPnt(&$raList, $to_save, $depth = 0)
  190. {
  191. if (!is_array($to_save) || (empty($to_save))) {
  192. return 0xFFFFFFFF;
  193. } elseif (count($to_save) == 1) {
  194. $cnt = count($raList);
  195. // If the first entry, it's the root... Don't clone it!
  196. $raList[$cnt] = ( $depth == 0 ) ? $to_save[0] : clone $to_save[0];
  197. $raList[$cnt]->No = $cnt;
  198. $raList[$cnt]->PrevPps = 0xFFFFFFFF;
  199. $raList[$cnt]->NextPps = 0xFFFFFFFF;
  200. $raList[$cnt]->DirPps = self::_savePpsSetPnt($raList, @$raList[$cnt]->children, $depth++);
  201. } else {
  202. $iPos = floor(count($to_save) / 2);
  203. $aPrev = array_slice($to_save, 0, $iPos);
  204. $aNext = array_slice($to_save, $iPos + 1);
  205. $cnt = count($raList);
  206. // If the first entry, it's the root... Don't clone it!
  207. $raList[$cnt] = ( $depth == 0 ) ? $to_save[$iPos] : clone $to_save[$iPos];
  208. $raList[$cnt]->No = $cnt;
  209. $raList[$cnt]->PrevPps = self::_savePpsSetPnt($raList, $aPrev, $depth++);
  210. $raList[$cnt]->NextPps = self::_savePpsSetPnt($raList, $aNext, $depth++);
  211. $raList[$cnt]->DirPps = self::_savePpsSetPnt($raList, @$raList[$cnt]->children, $depth++);
  212. }
  213. return $cnt;
  214. }
  215. }