PPS.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2002 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Author: Xavier Noguer <xnoguer@php.net> |
  17. // | Based on OLE::Storage_Lite by Kawai, Takanori |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: PPS.php,v 1.7 2007/02/13 21:00:42 schmidt Exp $
  21. require_once 'PEAR.php';
  22. require_once 'OLE.php';
  23. /**
  24. * Class for creating PPS's for OLE containers
  25. *
  26. * @author Xavier Noguer <xnoguer@php.net>
  27. * @category Structures
  28. * @package OLE
  29. */
  30. class OLE_PPS extends PEAR
  31. {
  32. /**
  33. * The PPS index
  34. * @var integer
  35. */
  36. var $No;
  37. /**
  38. * The PPS name (in Unicode)
  39. * @var string
  40. */
  41. var $Name;
  42. /**
  43. * The PPS type. Dir, Root or File
  44. * @var integer
  45. */
  46. var $Type;
  47. /**
  48. * The index of the previous PPS
  49. * @var integer
  50. */
  51. var $PrevPps;
  52. /**
  53. * The index of the next PPS
  54. * @var integer
  55. */
  56. var $NextPps;
  57. /**
  58. * The index of it's first child if this is a Dir or Root PPS
  59. * @var integer
  60. */
  61. var $DirPps;
  62. /**
  63. * A timestamp
  64. * @var integer
  65. */
  66. var $Time1st;
  67. /**
  68. * A timestamp
  69. * @var integer
  70. */
  71. var $Time2nd;
  72. /**
  73. * Starting block (small or big) for this PPS's data inside the container
  74. * @var integer
  75. */
  76. var $_StartBlock;
  77. /**
  78. * The size of the PPS's data (in bytes)
  79. * @var integer
  80. */
  81. var $Size;
  82. /**
  83. * The PPS's data (only used if it's not using a temporary file)
  84. * @var string
  85. */
  86. var $_data;
  87. /**
  88. * Array of child PPS's (only used by Root and Dir PPS's)
  89. * @var array
  90. */
  91. var $children = array();
  92. /**
  93. * Pointer to OLE container
  94. * @var OLE
  95. */
  96. var $ole;
  97. /**
  98. * The constructor
  99. *
  100. * @access public
  101. * @param integer $No The PPS index
  102. * @param string $name The PPS name
  103. * @param integer $type The PPS type. Dir, Root or File
  104. * @param integer $prev The index of the previous PPS
  105. * @param integer $next The index of the next PPS
  106. * @param integer $dir The index of it's first child if this is a Dir or Root PPS
  107. * @param integer $time_1st A timestamp
  108. * @param integer $time_2nd A timestamp
  109. * @param string $data The (usually binary) source data of the PPS
  110. * @param array $children Array containing children PPS for this PPS
  111. */
  112. function OLE_PPS($No, $name, $type, $prev, $next, $dir, $time_1st, $time_2nd, $data, $children)
  113. {
  114. $this->No = $No;
  115. $this->Name = $name;
  116. $this->Type = $type;
  117. $this->PrevPps = $prev;
  118. $this->NextPps = $next;
  119. $this->DirPps = $dir;
  120. $this->Time1st = $time_1st;
  121. $this->Time2nd = $time_2nd;
  122. $this->_data = $data;
  123. $this->children = $children;
  124. if ($data != '') {
  125. $this->Size = strlen($data);
  126. } else {
  127. $this->Size = 0;
  128. }
  129. }
  130. /**
  131. * Returns the amount of data saved for this PPS
  132. *
  133. * @access private
  134. * @return integer The amount of data (in bytes)
  135. */
  136. function _DataLen()
  137. {
  138. if (!isset($this->_data)) {
  139. return 0;
  140. }
  141. if (isset($this->_PPS_FILE)) {
  142. fseek($this->_PPS_FILE, 0);
  143. $stats = fstat($this->_PPS_FILE);
  144. return $stats[7];
  145. } else {
  146. return strlen($this->_data);
  147. }
  148. }
  149. /**
  150. * Returns a string with the PPS's WK (What is a WK?)
  151. *
  152. * @access private
  153. * @return string The binary string
  154. */
  155. function _getPpsWk()
  156. {
  157. $ret = $this->Name;
  158. for ($i = 0; $i < (64 - strlen($this->Name)); $i++) {
  159. $ret .= "\x00";
  160. }
  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. . OLE::LocalDate2OLE($this->Time1st) // 108
  173. . 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 private
  185. * @param array &$pps_array Reference to the array of PPS's for the whole OLE
  186. * container
  187. * @return integer The index for this PPS
  188. */
  189. function _savePpsSetPnt(&$pps_array)
  190. {
  191. $pps_array[count($pps_array)] = &$this;
  192. $this->No = count($pps_array) - 1;
  193. $this->PrevPps = 0xFFFFFFFF;
  194. $this->NextPps = 0xFFFFFFFF;
  195. if (count($this->children) > 0) {
  196. $this->DirPps = $this->children[0]->_savePpsSetPnt($pps_array);
  197. } else {
  198. $this->DirPps = 0xFFFFFFFF;
  199. }
  200. return $this->No;
  201. }
  202. }
  203. ?>