[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/phpexcel/PHPExcel/Reader/ -> Abstract.php (source)

   1  <?php
   2  
   3  /**
   4   * PHPExcel_Reader_Abstract
   5   *
   6   * Copyright (c) 2006 - 2015 PHPExcel
   7   *
   8   * This library is free software; you can redistribute it and/or
   9   * modify it under the terms of the GNU Lesser General Public
  10   * License as published by the Free Software Foundation; either
  11   * version 2.1 of the License, or (at your option) any later version.
  12   *
  13   * This library is distributed in the hope that it will be useful,
  14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16   * Lesser General Public License for more details.
  17   *
  18   * You should have received a copy of the GNU Lesser General Public
  19   * License along with this library; if not, write to the Free Software
  20   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  21   *
  22   * @category   PHPExcel
  23   * @package    PHPExcel_Reader
  24   * @copyright  Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  25   * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  26   * @version    ##VERSION##, ##DATE##
  27   */
  28  abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
  29  {
  30      /**
  31       * Read data only?
  32       * Identifies whether the Reader should only read data values for cells, and ignore any formatting information;
  33       *        or whether it should read both data and formatting
  34       *
  35       * @var    boolean
  36       */
  37      protected $readDataOnly = false;
  38  
  39      /**
  40       * Read charts that are defined in the workbook?
  41       * Identifies whether the Reader should read the definitions for any charts that exist in the workbook;
  42       *
  43       * @var    boolean
  44       */
  45      protected $includeCharts = false;
  46  
  47      /**
  48       * Restrict which sheets should be loaded?
  49       * This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded.
  50       *
  51       * @var array of string
  52       */
  53      protected $loadSheetsOnly;
  54  
  55      /**
  56       * PHPExcel_Reader_IReadFilter instance
  57       *
  58       * @var PHPExcel_Reader_IReadFilter
  59       */
  60      protected $readFilter;
  61  
  62      protected $fileHandle = null;
  63  
  64  
  65      /**
  66       * Read data only?
  67       *        If this is true, then the Reader will only read data values for cells, it will not read any formatting information.
  68       *        If false (the default) it will read data and formatting.
  69       *
  70       * @return    boolean
  71       */
  72      public function getReadDataOnly()
  73      {
  74          return $this->readDataOnly;
  75      }
  76  
  77      /**
  78       * Set read data only
  79       *        Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information.
  80       *        Set to false (the default) to advise the Reader to read both data and formatting for cells.
  81       *
  82       * @param    boolean    $pValue
  83       *
  84       * @return    PHPExcel_Reader_IReader
  85       */
  86      public function setReadDataOnly($pValue = false)
  87      {
  88          $this->readDataOnly = $pValue;
  89          return $this;
  90      }
  91  
  92      /**
  93       * Read charts in workbook?
  94       *        If this is true, then the Reader will include any charts that exist in the workbook.
  95       *      Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value.
  96       *        If false (the default) it will ignore any charts defined in the workbook file.
  97       *
  98       * @return    boolean
  99       */
 100      public function getIncludeCharts()
 101      {
 102          return $this->includeCharts;
 103      }
 104  
 105      /**
 106       * Set read charts in workbook
 107       *        Set to true, to advise the Reader to include any charts that exist in the workbook.
 108       *      Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value.
 109       *        Set to false (the default) to discard charts.
 110       *
 111       * @param    boolean    $pValue
 112       *
 113       * @return    PHPExcel_Reader_IReader
 114       */
 115      public function setIncludeCharts($pValue = false)
 116      {
 117          $this->includeCharts = (boolean) $pValue;
 118          return $this;
 119      }
 120  
 121      /**
 122       * Get which sheets to load
 123       * Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null
 124       *        indicating that all worksheets in the workbook should be loaded.
 125       *
 126       * @return mixed
 127       */
 128      public function getLoadSheetsOnly()
 129      {
 130          return $this->loadSheetsOnly;
 131      }
 132  
 133      /**
 134       * Set which sheets to load
 135       *
 136       * @param mixed $value
 137       *        This should be either an array of worksheet names to be loaded, or a string containing a single worksheet name.
 138       *        If NULL, then it tells the Reader to read all worksheets in the workbook
 139       *
 140       * @return PHPExcel_Reader_IReader
 141       */
 142      public function setLoadSheetsOnly($value = null)
 143      {
 144          if ($value === null) {
 145              return $this->setLoadAllSheets();
 146          }
 147  
 148          $this->loadSheetsOnly = is_array($value) ? $value : array($value);
 149          return $this;
 150      }
 151  
 152      /**
 153       * Set all sheets to load
 154       *        Tells the Reader to load all worksheets from the workbook.
 155       *
 156       * @return PHPExcel_Reader_IReader
 157       */
 158      public function setLoadAllSheets()
 159      {
 160          $this->loadSheetsOnly = null;
 161          return $this;
 162      }
 163  
 164      /**
 165       * Read filter
 166       *
 167       * @return PHPExcel_Reader_IReadFilter
 168       */
 169      public function getReadFilter()
 170      {
 171          return $this->readFilter;
 172      }
 173  
 174      /**
 175       * Set read filter
 176       *
 177       * @param PHPExcel_Reader_IReadFilter $pValue
 178       * @return PHPExcel_Reader_IReader
 179       */
 180      public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue)
 181      {
 182          $this->readFilter = $pValue;
 183          return $this;
 184      }
 185  
 186      /**
 187       * Open file for reading
 188       *
 189       * @param string $pFilename
 190       * @throws    PHPExcel_Reader_Exception
 191       * @return resource
 192       */
 193      protected function openFile($pFilename)
 194      {
 195          // Check if file exists
 196          if (!file_exists($pFilename) || !is_readable($pFilename)) {
 197              throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
 198          }
 199  
 200          // Open file
 201          $this->fileHandle = fopen($pFilename, 'r');
 202          if ($this->fileHandle === false) {
 203              throw new PHPExcel_Reader_Exception("Could not open file " . $pFilename . " for reading.");
 204          }
 205      }
 206  
 207      /**
 208       * Can the current PHPExcel_Reader_IReader read the file?
 209       *
 210       * @param     string         $pFilename
 211       * @return boolean
 212       * @throws PHPExcel_Reader_Exception
 213       */
 214      public function canRead($pFilename)
 215      {
 216          // Check if file exists
 217          try {
 218              $this->openFile($pFilename);
 219          } catch (Exception $e) {
 220              return false;
 221          }
 222  
 223          $readable = $this->isValidFormat();
 224          fclose($this->fileHandle);
 225          return $readable;
 226      }
 227  
 228      /**
 229       * Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks
 230       *
 231       * @param     string         $xml
 232       * @throws PHPExcel_Reader_Exception
 233       */
 234      public function securityScan($xml)
 235      {
 236          $pattern = '/\\0?' . implode('\\0?', str_split('<!DOCTYPE')) . '\\0?/';
 237          if (preg_match($pattern, $xml)) {
 238              throw new PHPExcel_Reader_Exception('Detected use of ENTITY in XML, spreadsheet file load() aborted to prevent XXE/XEE attacks');
 239          }
 240          return $xml;
 241      }
 242  
 243      /**
 244       * Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks
 245       *
 246       * @param     string         $filestream
 247       * @throws PHPExcel_Reader_Exception
 248       */
 249      public function securityScanFile($filestream)
 250      {
 251          return $this->securityScan(file_get_contents($filestream));
 252      }
 253  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1