123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- <?php
- abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
- {
-
- protected $readDataOnly = false;
-
- protected $readEmptyCells = true;
-
- protected $includeCharts = false;
-
- protected $loadSheetsOnly;
-
- protected $readFilter;
- protected $fileHandle = null;
-
- public function getReadDataOnly()
- {
- return $this->readDataOnly;
- }
-
- public function setReadDataOnly($pValue = false)
- {
- $this->readDataOnly = $pValue;
- return $this;
- }
-
- public function getReadEmptyCells()
- {
- return $this->readEmptyCells;
- }
-
- public function setReadEmptyCells($pValue = true)
- {
- $this->readEmptyCells = $pValue;
- return $this;
- }
-
- public function getIncludeCharts()
- {
- return $this->includeCharts;
- }
-
- public function setIncludeCharts($pValue = false)
- {
- $this->includeCharts = (boolean) $pValue;
- return $this;
- }
-
- public function getLoadSheetsOnly()
- {
- return $this->loadSheetsOnly;
- }
-
- public function setLoadSheetsOnly($value = null)
- {
- if ($value === null) {
- return $this->setLoadAllSheets();
- }
- $this->loadSheetsOnly = is_array($value) ? $value : array($value);
- return $this;
- }
-
- public function setLoadAllSheets()
- {
- $this->loadSheetsOnly = null;
- return $this;
- }
-
- public function getReadFilter()
- {
- return $this->readFilter;
- }
-
- public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue)
- {
- $this->readFilter = $pValue;
- return $this;
- }
-
- protected function openFile($pFilename)
- {
-
- if (!file_exists($pFilename) || !is_readable($pFilename)) {
- throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
- }
-
- $this->fileHandle = fopen($pFilename, 'r');
- if ($this->fileHandle === false) {
- throw new PHPExcel_Reader_Exception("Could not open file " . $pFilename . " for reading.");
- }
- }
-
- public function canRead($pFilename)
- {
-
- try {
- $this->openFile($pFilename);
- } catch (Exception $e) {
- return false;
- }
- $readable = $this->isValidFormat();
- fclose($this->fileHandle);
- return $readable;
- }
-
- public function securityScan($xml)
- {
- $pattern = '/encoding="(.*?)"/';
- $result = preg_match($pattern, $xml, $matches);
- if ($result) {
- $charset = $matches[1];
- } else {
- $charset = 'UTF-8';
- }
- if ($charset !== 'UTF-8') {
- $xml = mb_convert_encoding($xml, 'UTF-8', $charset);
- }
- $pattern = '/\\0?' . implode('\\0?', str_split('<!DOCTYPE')) . '\\0?/';
- if (preg_match($pattern, $xml)) {
- throw new PHPExcel_Reader_Exception('Detected use of ENTITY in XML, spreadsheet file load() aborted to prevent XXE/XEE attacks');
- }
- return $xml;
- }
-
- public function securityScanFile($filestream)
- {
- return $this->securityScan(file_get_contents($filestream));
- }
- }
|