ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ChainedBlockStream.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
8 {
14  public $ole;
15 
21  public $params;
22 
28  public $data;
29 
35  public $pos;
36 
49  public function stream_open($path, $mode, $options, &$openedPath) // @codingStandardsIgnoreLine
50  {
51  if ($mode != 'r') {
52  if ($options & STREAM_REPORT_ERRORS) {
53  trigger_error('Only reading is supported', E_USER_WARNING);
54  }
55 
56  return false;
57  }
58 
59  // 25 is length of "ole-chainedblockstream://"
60  parse_str(substr($path, 25), $this->params);
61  if (!isset($this->params['oleInstanceId'], $this->params['blockId'], $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']])) {
62  if ($options & STREAM_REPORT_ERRORS) {
63  trigger_error('OLE stream not found', E_USER_WARNING);
64  }
65 
66  return false;
67  }
68  $this->ole = $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']];
69 
70  $blockId = $this->params['blockId'];
71  $this->data = '';
72  if (isset($this->params['size']) && $this->params['size'] < $this->ole->bigBlockThreshold && $blockId != $this->ole->root->startBlock) {
73  // Block id refers to small blocks
74  $rootPos = $this->ole->getBlockOffset($this->ole->root->startBlock);
75  while ($blockId != -2) {
76  $pos = $rootPos + $blockId * $this->ole->bigBlockSize;
77  $blockId = $this->ole->sbat[$blockId];
78  fseek($this->ole->_file_handle, $pos);
79  $this->data .= fread($this->ole->_file_handle, $this->ole->bigBlockSize);
80  }
81  } else {
82  // Block id refers to big blocks
83  while ($blockId != -2) {
84  $pos = $this->ole->getBlockOffset($blockId);
85  fseek($this->ole->_file_handle, $pos);
86  $this->data .= fread($this->ole->_file_handle, $this->ole->bigBlockSize);
87  $blockId = $this->ole->bbat[$blockId];
88  }
89  }
90  if (isset($this->params['size'])) {
91  $this->data = substr($this->data, 0, $this->params['size']);
92  }
93 
94  if ($options & STREAM_USE_PATH) {
95  $openedPath = $path;
96  }
97 
98  return true;
99  }
100 
104  public function stream_close(): void // @codingStandardsIgnoreLine
105  {
106  $this->ole = null;
107  unset($GLOBALS['_OLE_INSTANCES']);
108  }
109 
117  public function stream_read($count) // @codingStandardsIgnoreLine
118  {
119  if ($this->stream_eof()) {
120  return false;
121  }
122  $s = substr($this->data, $this->pos, $count);
123  $this->pos += $count;
124 
125  return $s;
126  }
127 
133  public function stream_eof() // @codingStandardsIgnoreLine
134  {
135  return $this->pos >= strlen($this->data);
136  }
137 
144  public function stream_tell() // @codingStandardsIgnoreLine
145  {
146  return $this->pos;
147  }
148 
157  public function stream_seek($offset, $whence) // @codingStandardsIgnoreLine
158  {
159  if ($whence == SEEK_SET && $offset >= 0) {
160  $this->pos = $offset;
161  } elseif ($whence == SEEK_CUR && -$offset <= $this->pos) {
162  $this->pos += $offset;
163  } elseif ($whence == SEEK_END && -$offset <= count($this->data)) {
164  $this->pos = strlen($this->data) + $offset;
165  } else {
166  return false;
167  }
168 
169  return true;
170  }
171 
178  public function stream_stat() // @codingStandardsIgnoreLine
179  {
180  return [
181  'size' => strlen($this->data),
182  ];
183  }
184 
185  // Methods used by stream_wrapper_register() that are not implemented:
186  // bool stream_flush ( void )
187  // int stream_write ( string data )
188  // bool rename ( string path_from, string path_to )
189  // bool mkdir ( string path, int mode, int options )
190  // bool rmdir ( string path, int options )
191  // bool dir_opendir ( string path, int options )
192  // array url_stat ( string path, int flags )
193  // string dir_readdir ( void )
194  // bool dir_rewinddir ( void )
195  // bool dir_closedir ( void )
196 }
$path
Definition: aliased.php:25
$GLOBALS['_OLE_INSTANCES']
Definition: OLE.php:35
stream_read($count)
Implements support for fread(), fgets() etc.
stream_seek($offset, $whence)
Implements support for fseek().
$s
Definition: pwgen.php:45
stream_tell()
Returns the position of the file pointer, i.e.
stream_open($path, $mode, $options, &$openedPath)
Implements support for fopen().
$this data['403_header']