← All changes
|
vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/HTML.php
+201
-216
3.1.1
→
3.0.3
View file →
| @@ -1,18 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!defined('PHPEXCEL_ROOT')) { | |
| 4 | - /** | |
| 5 | - * @ignore | |
| 6 | - */ | |
| 7 | - define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); | |
| 8 | - require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); | |
| 9 | -} | |
| 10 | - | |
| 11 | 3 | /** |
| 12 | - * PHPExcel_Reader_HTML | |
| 4 | + * PHPExcel | |
| 13 | 5 | * |
| 14 | - * Copyright (c) 2006 - 2015 PHPExcel | |
| 6 | + * Copyright (c) 2006 - 2014 PHPExcel | |
| 15 | 7 | * |
| 16 | 8 | * This library is free software; you can redistribute it and/or |
| 17 | 9 | * modify it under the terms of the GNU Lesser General Public |
| 18 | 10 | * License as published by the Free Software Foundation; either |
| @@ -28,13 +20,28 @@ | ||
| 28 | 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 29 | 21 | * |
| 30 | 22 | * @category PHPExcel |
| 31 | 23 | * @package PHPExcel_Reader |
| 32 | - * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 33 | - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL | |
| 24 | + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 25 | + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL | |
| 34 | 26 | * @version ##VERSION##, ##DATE## |
| 35 | 27 | */ |
| 36 | 28 | /** PHPExcel root directory */ |
| 29 | +if (!defined('PHPEXCEL_ROOT')) { | |
| 30 | + /** | |
| 31 | + * @ignore | |
| 32 | + */ | |
| 33 | + define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); | |
| 34 | + require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); | |
| 35 | +} | |
| 36 | + | |
| 37 | +/** | |
| 38 | + * PHPExcel_Reader_HTML | |
| 39 | + * | |
| 40 | + * @category PHPExcel | |
| 41 | + * @package PHPExcel_Reader | |
| 42 | + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 43 | + */ | |
| 37 | 44 | class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader |
| 38 | 45 | { |
| 39 | 46 | |
| 40 | 47 | /** |
| @@ -41,9 +48,9 @@ | ||
| 41 | 48 | * Input encoding |
| 42 | 49 | * |
| 43 | 50 | * @var string |
| 44 | 51 | */ |
| 45 | - protected $inputEncoding = 'ANSI'; | |
| 52 | + protected $_inputEncoding = 'ANSI'; | |
| 46 | 53 | |
| 47 | 54 | /** |
| 48 | 55 | * Sheet index to read |
| 49 | 56 | * |
| @@ -48,9 +55,9 @@ | ||
| 48 | 55 | * Sheet index to read |
| 49 | 56 | * |
| 50 | 57 | * @var int |
| 51 | 58 | */ |
| 52 | - protected $sheetIndex = 0; | |
| 59 | + protected $_sheetIndex = 0; | |
| 53 | 60 | |
| 54 | 61 | /** |
| 55 | 62 | * Formats |
| 56 | 63 | * |
| @@ -55,63 +62,44 @@ | ||
| 55 | 62 | * Formats |
| 56 | 63 | * |
| 57 | 64 | * @var array |
| 58 | 65 | */ |
| 59 | - protected $formats = array( | |
| 60 | - 'h1' => array( | |
| 61 | - 'font' => array( | |
| 62 | - 'bold' => true, | |
| 66 | + protected $_formats = array( | |
| 67 | + 'h1' => array('font' => array('bold' => true, | |
| 63 | 68 | 'size' => 24, |
| 64 | 69 | ), |
| 65 | - ), // Bold, 24pt | |
| 66 | - 'h2' => array( | |
| 67 | - 'font' => array( | |
| 68 | - 'bold' => true, | |
| 70 | + ), // Bold, 24pt | |
| 71 | + 'h2' => array('font' => array('bold' => true, | |
| 69 | 72 | 'size' => 18, |
| 70 | 73 | ), |
| 71 | - ), // Bold, 18pt | |
| 72 | - 'h3' => array( | |
| 73 | - 'font' => array( | |
| 74 | - 'bold' => true, | |
| 74 | + ), // Bold, 18pt | |
| 75 | + 'h3' => array('font' => array('bold' => true, | |
| 75 | 76 | 'size' => 13.5, |
| 76 | 77 | ), |
| 77 | - ), // Bold, 13.5pt | |
| 78 | - 'h4' => array( | |
| 79 | - 'font' => array( | |
| 80 | - 'bold' => true, | |
| 78 | + ), // Bold, 13.5pt | |
| 79 | + 'h4' => array('font' => array('bold' => true, | |
| 81 | 80 | 'size' => 12, |
| 82 | 81 | ), |
| 83 | - ), // Bold, 12pt | |
| 84 | - 'h5' => array( | |
| 85 | - 'font' => array( | |
| 86 | - 'bold' => true, | |
| 82 | + ), // Bold, 12pt | |
| 83 | + 'h5' => array('font' => array('bold' => true, | |
| 87 | 84 | 'size' => 10, |
| 88 | 85 | ), |
| 89 | - ), // Bold, 10pt | |
| 90 | - 'h6' => array( | |
| 91 | - 'font' => array( | |
| 92 | - 'bold' => true, | |
| 86 | + ), // Bold, 10pt | |
| 87 | + 'h6' => array('font' => array('bold' => true, | |
| 93 | 88 | 'size' => 7.5, |
| 94 | 89 | ), |
| 95 | - ), // Bold, 7.5pt | |
| 96 | - 'a' => array( | |
| 97 | - 'font' => array( | |
| 98 | - 'underline' => true, | |
| 99 | - 'color' => array( | |
| 100 | - 'argb' => PHPExcel_Style_Color::COLOR_BLUE, | |
| 90 | + ), // Bold, 7.5pt | |
| 91 | + 'a' => array('font' => array('underline' => true, | |
| 92 | + 'color' => array('argb' => PHPExcel_Style_Color::COLOR_BLUE, | |
| 101 | 93 | ), |
| 102 | 94 | ), |
| 103 | - ), // Blue underlined | |
| 104 | - 'hr' => array( | |
| 105 | - 'borders' => array( | |
| 106 | - 'bottom' => array( | |
| 107 | - 'style' => PHPExcel_Style_Border::BORDER_THIN, | |
| 108 | - 'color' => array( | |
| 109 | - PHPExcel_Style_Color::COLOR_BLACK, | |
| 95 | + ), // Blue underlined | |
| 96 | + 'hr' => array('borders' => array('bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN, | |
| 97 | + 'color' => array(\PHPExcel_Style_Color::COLOR_BLACK, | |
| 110 | 98 | ), |
| 111 | 99 | ), |
| 112 | 100 | ), |
| 113 | - ), // Bottom border | |
| 101 | + ), // Bottom border | |
| 114 | 102 | ); |
| 115 | 103 | |
| 116 | 104 | protected $rowspan = array(); |
| 117 | 105 | |
| @@ -119,9 +107,9 @@ | ||
| 119 | 107 | * Create a new PHPExcel_Reader_HTML |
| 120 | 108 | */ |
| 121 | 109 | public function __construct() |
| 122 | 110 | { |
| 123 | - $this->readFilter = new PHPExcel_Reader_DefaultReadFilter(); | |
| 111 | + $this->_readFilter = new PHPExcel_Reader_DefaultReadFilter(); | |
| 124 | 112 | } |
| 125 | 113 | |
| 126 | 114 | /** |
| 127 | 115 | * Validate that the current file is an HTML file |
| @@ -127,18 +115,18 @@ | ||
| 127 | 115 | * Validate that the current file is an HTML file |
| 128 | 116 | * |
| 129 | 117 | * @return boolean |
| 130 | 118 | */ |
| 131 | - protected function isValidFormat() | |
| 119 | + protected function _isValidFormat() | |
| 132 | 120 | { |
| 133 | - // Reading 2048 bytes should be enough to validate that the format is HTML | |
| 134 | - $data = fread($this->fileHandle, 2048); | |
| 135 | - if ((strpos($data, '<') !== false) && | |
| 121 | + // Reading 2048 bytes should be enough to validate that the format is HTML | |
| 122 | + $data = fread($this->_fileHandle, 2048); | |
| 123 | + if ((strpos($data, '<') !== FALSE) && | |
| 136 | 124 | (strlen($data) !== strlen(strip_tags($data)))) { |
| 137 | - return true; | |
| 125 | + return TRUE; | |
| 138 | 126 | } |
| 139 | 127 | |
| 140 | - return false; | |
| 128 | + return FALSE; | |
| 141 | 129 | } |
| 142 | 130 | |
| 143 | 131 | /** |
| 144 | 132 | * Loads PHPExcel from file |
| @@ -162,9 +150,9 @@ | ||
| 162 | 150 | * @param string $pValue Input encoding |
| 163 | 151 | */ |
| 164 | 152 | public function setInputEncoding($pValue = 'ANSI') |
| 165 | 153 | { |
| 166 | - $this->inputEncoding = $pValue; | |
| 154 | + $this->_inputEncoding = $pValue; | |
| 167 | 155 | |
| 168 | 156 | return $this; |
| 169 | 157 | } |
| 170 | 158 | |
| @@ -174,180 +162,176 @@ | ||
| 174 | 162 | * @return string |
| 175 | 163 | */ |
| 176 | 164 | public function getInputEncoding() |
| 177 | 165 | { |
| 178 | - return $this->inputEncoding; | |
| 166 | + return $this->_inputEncoding; | |
| 179 | 167 | } |
| 180 | 168 | |
| 181 | - // Data Array used for testing only, should write to PHPExcel object on completion of tests | |
| 182 | - protected $dataArray = array(); | |
| 183 | - protected $tableLevel = 0; | |
| 184 | - protected $nestedColumn = array('A'); | |
| 169 | + // Data Array used for testing only, should write to PHPExcel object on completion of tests | |
| 170 | + protected $_dataArray = array(); | |
| 171 | + protected $_tableLevel = 0; | |
| 172 | + protected $_nestedColumn = array('A'); | |
| 185 | 173 | |
| 186 | - protected function setTableStartColumn($column) | |
| 174 | + protected function _setTableStartColumn($column) | |
| 187 | 175 | { |
| 188 | - if ($this->tableLevel == 0) { | |
| 176 | + if ($this->_tableLevel == 0) | |
| 189 | 177 | $column = 'A'; |
| 190 | - } | |
| 191 | - ++$this->tableLevel; | |
| 192 | - $this->nestedColumn[$this->tableLevel] = $column; | |
| 178 | + ++$this->_tableLevel; | |
| 179 | + $this->_nestedColumn[$this->_tableLevel] = $column; | |
| 193 | 180 | |
| 194 | - return $this->nestedColumn[$this->tableLevel]; | |
| 181 | + return $this->_nestedColumn[$this->_tableLevel]; | |
| 195 | 182 | } |
| 196 | 183 | |
| 197 | - protected function getTableStartColumn() | |
| 184 | + protected function _getTableStartColumn() | |
| 198 | 185 | { |
| 199 | - return $this->nestedColumn[$this->tableLevel]; | |
| 186 | + return $this->_nestedColumn[$this->_tableLevel]; | |
| 200 | 187 | } |
| 201 | 188 | |
| 202 | - protected function releaseTableStartColumn() | |
| 189 | + protected function _releaseTableStartColumn() | |
| 203 | 190 | { |
| 204 | - --$this->tableLevel; | |
| 191 | + --$this->_tableLevel; | |
| 205 | 192 | |
| 206 | - return array_pop($this->nestedColumn); | |
| 193 | + return array_pop($this->_nestedColumn); | |
| 207 | 194 | } |
| 208 | 195 | |
| 209 | - protected function flushCell($sheet, $column, $row, &$cellContent) | |
| 196 | + protected function _flushCell($sheet, $column, $row, &$cellContent) | |
| 210 | 197 | { |
| 211 | 198 | if (is_string($cellContent)) { |
| 212 | - // Simple String content | |
| 199 | + // Simple String content | |
| 213 | 200 | if (trim($cellContent) > '') { |
| 214 | - // Only actually write it if there's content in the string | |
| 215 | -// echo 'FLUSH CELL: ' , $column , $row , ' => ' , $cellContent , '<br />'; | |
| 216 | - // Write to worksheet to be done here... | |
| 217 | - // ... we return the cell so we can mess about with styles more easily | |
| 201 | + // Only actually write it if there's content in the string | |
| 202 | +// echo 'FLUSH CELL: ' , $column , $row , ' => ' , $cellContent , '<br />'; | |
| 203 | + // Write to worksheet to be done here... | |
| 204 | + // ... we return the cell so we can mess about with styles more easily | |
| 218 | 205 | $sheet->setCellValue($column . $row, $cellContent, true); |
| 219 | - $this->dataArray[$row][$column] = $cellContent; | |
| 206 | + $this->_dataArray[$row][$column] = $cellContent; | |
| 220 | 207 | } |
| 221 | 208 | } else { |
| 222 | - // We have a Rich Text run | |
| 223 | - // TODO | |
| 224 | - $this->dataArray[$row][$column] = 'RICH TEXT: ' . $cellContent; | |
| 209 | + // We have a Rich Text run | |
| 210 | + // TODO | |
| 211 | + $this->_dataArray[$row][$column] = 'RICH TEXT: ' . $cellContent; | |
| 225 | 212 | } |
| 226 | 213 | $cellContent = (string) ''; |
| 227 | 214 | } |
| 228 | 215 | |
| 229 | - protected function processDomElement(DOMNode $element, $sheet, &$row, &$column, &$cellContent, $format = null) | |
| 216 | + protected function _processDomElement(DOMNode $element, $sheet, &$row, &$column, &$cellContent, $format = null) | |
| 230 | 217 | { |
| 231 | 218 | foreach ($element->childNodes as $child) { |
| 232 | 219 | if ($child instanceof DOMText) { |
| 233 | 220 | $domText = preg_replace('/\s+/u', ' ', trim($child->nodeValue)); |
| 234 | 221 | if (is_string($cellContent)) { |
| 235 | - // simply append the text if the cell content is a plain text string | |
| 222 | + // simply append the text if the cell content is a plain text string | |
| 236 | 223 | $cellContent .= $domText; |
| 237 | 224 | } else { |
| 238 | - // but if we have a rich text run instead, we need to append it correctly | |
| 239 | - // TODO | |
| 225 | + // but if we have a rich text run instead, we need to append it correctly | |
| 226 | + // TODO | |
| 240 | 227 | } |
| 241 | 228 | } elseif ($child instanceof DOMElement) { |
| 242 | -// echo '<b>DOM ELEMENT: </b>' , strtoupper($child->nodeName) , '<br />'; | |
| 229 | +// echo '<b>DOM ELEMENT: </b>' , strtoupper($child->nodeName) , '<br />'; | |
| 243 | 230 | |
| 244 | 231 | $attributeArray = array(); |
| 245 | 232 | foreach ($child->attributes as $attribute) { |
| 246 | -// echo '<b>ATTRIBUTE: </b>' , $attribute->name , ' => ' , $attribute->value , '<br />'; | |
| 233 | +// echo '<b>ATTRIBUTE: </b>' , $attribute->name , ' => ' , $attribute->value , '<br />'; | |
| 247 | 234 | $attributeArray[$attribute->name] = $attribute->value; |
| 248 | 235 | } |
| 249 | 236 | |
| 250 | 237 | switch ($child->nodeName) { |
| 251 | - case 'meta': | |
| 238 | + case 'meta' : | |
| 252 | 239 | foreach ($attributeArray as $attributeName => $attributeValue) { |
| 253 | 240 | switch ($attributeName) { |
| 254 | 241 | case 'content': |
| 255 | - // TODO | |
| 256 | - // Extract character set, so we can convert to UTF-8 if required | |
| 242 | + // TODO | |
| 243 | + // Extract character set, so we can convert to UTF-8 if required | |
| 257 | 244 | break; |
| 258 | 245 | } |
| 259 | 246 | } |
| 260 | - $this->processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 247 | + $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 261 | 248 | break; |
| 262 | - case 'title': | |
| 263 | - $this->processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 249 | + case 'title' : | |
| 250 | + $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 264 | 251 | $sheet->setTitle($cellContent); |
| 265 | 252 | $cellContent = ''; |
| 266 | 253 | break; |
| 267 | - case 'span': | |
| 268 | - case 'div': | |
| 269 | - case 'font': | |
| 270 | - case 'i': | |
| 271 | - case 'em': | |
| 254 | + case 'span' : | |
| 255 | + case 'div' : | |
| 256 | + case 'font' : | |
| 257 | + case 'i' : | |
| 258 | + case 'em' : | |
| 272 | 259 | case 'strong': |
| 273 | - case 'b': | |
| 274 | -// echo 'STYLING, SPAN OR DIV<br />'; | |
| 275 | - if ($cellContent > '') { | |
| 260 | + case 'b' : | |
| 261 | +// echo 'STYLING, SPAN OR DIV<br />'; | |
| 262 | + if ($cellContent > '') | |
| 276 | 263 | $cellContent .= ' '; |
| 277 | - } | |
| 278 | - $this->processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 279 | - if ($cellContent > '') { | |
| 264 | + $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 265 | + if ($cellContent > '') | |
| 280 | 266 | $cellContent .= ' '; |
| 281 | - } | |
| 282 | -// echo 'END OF STYLING, SPAN OR DIV<br />'; | |
| 267 | +// echo 'END OF STYLING, SPAN OR DIV<br />'; | |
| 283 | 268 | break; |
| 284 | - case 'hr': | |
| 285 | - $this->flushCell($sheet, $column, $row, $cellContent); | |
| 269 | + case 'hr' : | |
| 270 | + $this->_flushCell($sheet, $column, $row, $cellContent); | |
| 286 | 271 | ++$row; |
| 287 | - if (isset($this->formats[$child->nodeName])) { | |
| 288 | - $sheet->getStyle($column . $row)->applyFromArray($this->formats[$child->nodeName]); | |
| 272 | + if (isset($this->_formats[$child->nodeName])) { | |
| 273 | + $sheet->getStyle($column . $row)->applyFromArray($this->_formats[$child->nodeName]); | |
| 289 | 274 | } else { |
| 290 | 275 | $cellContent = '----------'; |
| 291 | - $this->flushCell($sheet, $column, $row, $cellContent); | |
| 276 | + $this->_flushCell($sheet, $column, $row, $cellContent); | |
| 292 | 277 | } |
| 293 | 278 | ++$row; |
| 294 | - // Add a break after a horizontal rule, simply by allowing the code to dropthru | |
| 295 | - case 'br': | |
| 296 | - if ($this->tableLevel > 0) { | |
| 297 | - // If we're inside a table, replace with a \n | |
| 279 | + case 'br' : | |
| 280 | + if ($this->_tableLevel > 0) { | |
| 281 | + // If we're inside a table, replace with a \n | |
| 298 | 282 | $cellContent .= "\n"; |
| 299 | 283 | } else { |
| 300 | - // Otherwise flush our existing content and move the row cursor on | |
| 301 | - $this->flushCell($sheet, $column, $row, $cellContent); | |
| 284 | + // Otherwise flush our existing content and move the row cursor on | |
| 285 | + $this->_flushCell($sheet, $column, $row, $cellContent); | |
| 302 | 286 | ++$row; |
| 303 | 287 | } |
| 304 | -// echo 'HARD LINE BREAK: ' , '<br />'; | |
| 288 | +// echo 'HARD LINE BREAK: ' , '<br />'; | |
| 305 | 289 | break; |
| 306 | - case 'a': | |
| 307 | -// echo 'START OF HYPERLINK: ' , '<br />'; | |
| 290 | + case 'a' : | |
| 291 | +// echo 'START OF HYPERLINK: ' , '<br />'; | |
| 308 | 292 | foreach ($attributeArray as $attributeName => $attributeValue) { |
| 309 | 293 | switch ($attributeName) { |
| 310 | 294 | case 'href': |
| 311 | -// echo 'Link to ' , $attributeValue , '<br />'; | |
| 295 | +// echo 'Link to ' , $attributeValue , '<br />'; | |
| 312 | 296 | $sheet->getCell($column . $row)->getHyperlink()->setUrl($attributeValue); |
| 313 | - if (isset($this->formats[$child->nodeName])) { | |
| 314 | - $sheet->getStyle($column . $row)->applyFromArray($this->formats[$child->nodeName]); | |
| 297 | + if (isset($this->_formats[$child->nodeName])) { | |
| 298 | + $sheet->getStyle($column . $row)->applyFromArray($this->_formats[$child->nodeName]); | |
| 315 | 299 | } |
| 316 | 300 | break; |
| 317 | 301 | } |
| 318 | 302 | } |
| 319 | 303 | $cellContent .= ' '; |
| 320 | - $this->processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 321 | -// echo 'END OF HYPERLINK:' , '<br />'; | |
| 304 | + $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 305 | +// echo 'END OF HYPERLINK:' , '<br />'; | |
| 322 | 306 | break; |
| 323 | - case 'h1': | |
| 324 | - case 'h2': | |
| 325 | - case 'h3': | |
| 326 | - case 'h4': | |
| 327 | - case 'h5': | |
| 328 | - case 'h6': | |
| 329 | - case 'ol': | |
| 330 | - case 'ul': | |
| 331 | - case 'p': | |
| 332 | - if ($this->tableLevel > 0) { | |
| 333 | - // If we're inside a table, replace with a \n | |
| 307 | + case 'h1' : | |
| 308 | + case 'h2' : | |
| 309 | + case 'h3' : | |
| 310 | + case 'h4' : | |
| 311 | + case 'h5' : | |
| 312 | + case 'h6' : | |
| 313 | + case 'ol' : | |
| 314 | + case 'ul' : | |
| 315 | + case 'p' : | |
| 316 | + if ($this->_tableLevel > 0) { | |
| 317 | + // If we're inside a table, replace with a \n | |
| 334 | 318 | $cellContent .= "\n"; |
| 335 | -// echo 'LIST ENTRY: ' , '<br />'; | |
| 336 | - $this->processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 337 | -// echo 'END OF LIST ENTRY:' , '<br />'; | |
| 319 | +// echo 'LIST ENTRY: ' , '<br />'; | |
| 320 | + $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 321 | +// echo 'END OF LIST ENTRY:' , '<br />'; | |
| 338 | 322 | } else { |
| 339 | 323 | if ($cellContent > '') { |
| 340 | - $this->flushCell($sheet, $column, $row, $cellContent); | |
| 324 | + $this->_flushCell($sheet, $column, $row, $cellContent); | |
| 341 | 325 | $row++; |
| 342 | 326 | } |
| 343 | -// echo 'START OF PARAGRAPH: ' , '<br />'; | |
| 344 | - $this->processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 345 | -// echo 'END OF PARAGRAPH:' , '<br />'; | |
| 346 | - $this->flushCell($sheet, $column, $row, $cellContent); | |
| 327 | +// echo 'START OF PARAGRAPH: ' , '<br />'; | |
| 328 | + $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 329 | +// echo 'END OF PARAGRAPH:' , '<br />'; | |
| 330 | + $this->_flushCell($sheet, $column, $row, $cellContent); | |
| 347 | 331 | |
| 348 | - if (isset($this->formats[$child->nodeName])) { | |
| 349 | - $sheet->getStyle($column . $row)->applyFromArray($this->formats[$child->nodeName]); | |
| 332 | + if (isset($this->_formats[$child->nodeName])) { | |
| 333 | + $sheet->getStyle($column . $row)->applyFromArray($this->_formats[$child->nodeName]); | |
| 350 | 334 | } |
| 351 | 335 | |
| 352 | 336 | $row++; |
| 353 | 337 | $column = 'A'; |
| @@ -352,66 +336,65 @@ | ||
| 352 | 336 | $row++; |
| 353 | 337 | $column = 'A'; |
| 354 | 338 | } |
| 355 | 339 | break; |
| 356 | - case 'li': | |
| 357 | - if ($this->tableLevel > 0) { | |
| 358 | - // If we're inside a table, replace with a \n | |
| 340 | + case 'li' : | |
| 341 | + if ($this->_tableLevel > 0) { | |
| 342 | + // If we're inside a table, replace with a \n | |
| 359 | 343 | $cellContent .= "\n"; |
| 360 | -// echo 'LIST ENTRY: ' , '<br />'; | |
| 361 | - $this->processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 362 | -// echo 'END OF LIST ENTRY:' , '<br />'; | |
| 344 | +// echo 'LIST ENTRY: ' , '<br />'; | |
| 345 | + $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 346 | +// echo 'END OF LIST ENTRY:' , '<br />'; | |
| 363 | 347 | } else { |
| 364 | 348 | if ($cellContent > '') { |
| 365 | - $this->flushCell($sheet, $column, $row, $cellContent); | |
| 349 | + $this->_flushCell($sheet, $column, $row, $cellContent); | |
| 366 | 350 | } |
| 367 | 351 | ++$row; |
| 368 | -// echo 'LIST ENTRY: ' , '<br />'; | |
| 369 | - $this->processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 370 | -// echo 'END OF LIST ENTRY:' , '<br />'; | |
| 371 | - $this->flushCell($sheet, $column, $row, $cellContent); | |
| 352 | +// echo 'LIST ENTRY: ' , '<br />'; | |
| 353 | + $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 354 | +// echo 'END OF LIST ENTRY:' , '<br />'; | |
| 355 | + $this->_flushCell($sheet, $column, $row, $cellContent); | |
| 372 | 356 | $column = 'A'; |
| 373 | 357 | } |
| 374 | 358 | break; |
| 375 | - case 'table': | |
| 376 | - $this->flushCell($sheet, $column, $row, $cellContent); | |
| 377 | - $column = $this->setTableStartColumn($column); | |
| 378 | -// echo 'START OF TABLE LEVEL ' , $this->tableLevel , '<br />'; | |
| 379 | - if ($this->tableLevel > 1) { | |
| 359 | + case 'table' : | |
| 360 | + $this->_flushCell($sheet, $column, $row, $cellContent); | |
| 361 | + $column = $this->_setTableStartColumn($column); | |
| 362 | +// echo 'START OF TABLE LEVEL ' , $this->_tableLevel , '<br />'; | |
| 363 | + if ($this->_tableLevel > 1) | |
| 380 | 364 | --$row; |
| 381 | - } | |
| 382 | - $this->processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 383 | -// echo 'END OF TABLE LEVEL ' , $this->tableLevel , '<br />'; | |
| 384 | - $column = $this->releaseTableStartColumn(); | |
| 385 | - if ($this->tableLevel > 1) { | |
| 365 | + $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 366 | +// echo 'END OF TABLE LEVEL ' , $this->_tableLevel , '<br />'; | |
| 367 | + $column = $this->_releaseTableStartColumn(); | |
| 368 | + if ($this->_tableLevel > 1) { | |
| 386 | 369 | ++$column; |
| 387 | 370 | } else { |
| 388 | 371 | ++$row; |
| 389 | 372 | } |
| 390 | 373 | break; |
| 391 | - case 'thead': | |
| 392 | - case 'tbody': | |
| 393 | - $this->processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 374 | + case 'thead' : | |
| 375 | + case 'tbody' : | |
| 376 | + $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 394 | 377 | break; |
| 395 | - case 'tr': | |
| 396 | - $column = $this->getTableStartColumn(); | |
| 378 | + case 'tr' : | |
| 379 | + $column = $this->_getTableStartColumn(); | |
| 397 | 380 | $cellContent = ''; |
| 398 | -// echo 'START OF TABLE ' , $this->tableLevel , ' ROW<br />'; | |
| 399 | - $this->processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 381 | +// echo 'START OF TABLE ' , $this->_tableLevel , ' ROW<br />'; | |
| 382 | + $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 400 | 383 | ++$row; |
| 401 | -// echo 'END OF TABLE ' , $this->tableLevel , ' ROW<br />'; | |
| 384 | +// echo 'END OF TABLE ' , $this->_tableLevel , ' ROW<br />'; | |
| 402 | 385 | break; |
| 403 | - case 'th': | |
| 404 | - case 'td': | |
| 405 | -// echo 'START OF TABLE ' , $this->tableLevel , ' CELL<br />'; | |
| 406 | - $this->processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 407 | -// echo 'END OF TABLE ' , $this->tableLevel , ' CELL<br />'; | |
| 386 | + case 'th' : | |
| 387 | + case 'td' : | |
| 388 | +// echo 'START OF TABLE ' , $this->_tableLevel , ' CELL<br />'; | |
| 389 | + $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 390 | +// echo 'END OF TABLE ' , $this->_tableLevel , ' CELL<br />'; | |
| 408 | 391 | |
| 409 | 392 | while (isset($this->rowspan[$column . $row])) { |
| 410 | 393 | ++$column; |
| 411 | 394 | } |
| 412 | 395 | |
| 413 | - $this->flushCell($sheet, $column, $row, $cellContent); | |
| 396 | + $this->_flushCell($sheet, $column, $row, $cellContent); | |
| 414 | 397 | |
| 415 | 398 | // if (isset($attributeArray['style']) && !empty($attributeArray['style'])) { |
| 416 | 399 | // $styleAry = $this->getPhpExcelStyleArray($attributeArray['style']); |
| 417 | 400 | // |
| @@ -449,17 +432,17 @@ | ||
| 449 | 432 | $column = $columnTo; |
| 450 | 433 | } |
| 451 | 434 | ++$column; |
| 452 | 435 | break; |
| 453 | - case 'body': | |
| 436 | + case 'body' : | |
| 454 | 437 | $row = 1; |
| 455 | 438 | $column = 'A'; |
| 456 | 439 | $content = ''; |
| 457 | - $this->tableLevel = 0; | |
| 458 | - $this->processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 440 | + $this->_tableLevel = 0; | |
| 441 | + $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 459 | 442 | break; |
| 460 | 443 | default: |
| 461 | - $this->processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 444 | + $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | |
| 462 | 445 | } |
| 463 | 446 | } |
| 464 | 447 | } |
| 465 | 448 | } |
| @@ -474,39 +457,39 @@ | ||
| 474 | 457 | */ |
| 475 | 458 | public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) |
| 476 | 459 | { |
| 477 | 460 | // Open file to validate |
| 478 | - $this->openFile($pFilename); | |
| 479 | - if (!$this->isValidFormat()) { | |
| 480 | - fclose($this->fileHandle); | |
| 461 | + $this->_openFile($pFilename); | |
| 462 | + if (!$this->_isValidFormat()) { | |
| 463 | + fclose($this->_fileHandle); | |
| 481 | 464 | throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid HTML file."); |
| 482 | 465 | } |
| 483 | - // Close after validating | |
| 484 | - fclose($this->fileHandle); | |
| 466 | + // Close after validating | |
| 467 | + fclose($this->_fileHandle); | |
| 485 | 468 | |
| 486 | 469 | // Create new PHPExcel |
| 487 | - while ($objPHPExcel->getSheetCount() <= $this->sheetIndex) { | |
| 470 | + while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) { | |
| 488 | 471 | $objPHPExcel->createSheet(); |
| 489 | 472 | } |
| 490 | - $objPHPExcel->setActiveSheetIndex($this->sheetIndex); | |
| 473 | + $objPHPExcel->setActiveSheetIndex($this->_sheetIndex); | |
| 491 | 474 | |
| 492 | - // Create a new DOM object | |
| 475 | + // Create a new DOM object | |
| 493 | 476 | $dom = new domDocument; |
| 494 | - // Reload the HTML file into the DOM object | |
| 495 | - $loaded = $dom->loadHTML(mb_convert_encoding($this->securityScanFile($pFilename), 'HTML-ENTITIES', 'UTF-8')); | |
| 496 | - if ($loaded === false) { | |
| 497 | - throw new PHPExcel_Reader_Exception('Failed to load ' . $pFilename . ' as a DOM Document'); | |
| 477 | + // Reload the HTML file into the DOM object | |
| 478 | + $loaded = $dom->loadHTML($this->securityScanFile($pFilename)); | |
| 479 | + if ($loaded === FALSE) { | |
| 480 | + throw new PHPExcel_Reader_Exception('Failed to load ', $pFilename, ' as a DOM Document'); | |
| 498 | 481 | } |
| 499 | 482 | |
| 500 | - // Discard white space | |
| 483 | + // Discard white space | |
| 501 | 484 | $dom->preserveWhiteSpace = false; |
| 502 | 485 | |
| 503 | 486 | $row = 0; |
| 504 | 487 | $column = 'A'; |
| 505 | 488 | $content = ''; |
| 506 | - $this->processDomElement($dom, $objPHPExcel->getActiveSheet(), $row, $column, $content); | |
| 489 | + $this->_processDomElement($dom, $objPHPExcel->getActiveSheet(), $row, $column, $content); | |
| 507 | 490 | |
| 508 | - // Return | |
| 491 | + // Return | |
| 509 | 492 | return $objPHPExcel; |
| 510 | 493 | } |
| 511 | 494 | |
| 512 | 495 | /** |
| @@ -515,9 +498,9 @@ | ||
| 515 | 498 | * @return int |
| 516 | 499 | */ |
| 517 | 500 | public function getSheetIndex() |
| 518 | 501 | { |
| 519 | - return $this->sheetIndex; | |
| 502 | + return $this->_sheetIndex; | |
| 520 | 503 | } |
| 521 | 504 | |
| 522 | 505 | /** |
| 523 | 506 | * Set sheet index |
| @@ -526,24 +509,26 @@ | ||
| 526 | 509 | * @return PHPExcel_Reader_HTML |
| 527 | 510 | */ |
| 528 | 511 | public function setSheetIndex($pValue = 0) |
| 529 | 512 | { |
| 530 | - $this->sheetIndex = $pValue; | |
| 513 | + $this->_sheetIndex = $pValue; | |
| 531 | 514 | |
| 532 | 515 | return $this; |
| 533 | 516 | } |
| 534 | 517 | |
| 535 | - /** | |
| 536 | - * Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks | |
| 537 | - * | |
| 538 | - * @param string $xml | |
| 539 | - * @throws PHPExcel_Reader_Exception | |
| 540 | - */ | |
| 541 | - public function securityScan($xml) | |
| 542 | - { | |
| 518 | + /** | |
| 519 | + * Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks | |
| 520 | + * | |
| 521 | + * @param string $xml | |
| 522 | + * @throws PHPExcel_Reader_Exception | |
| 523 | + */ | |
| 524 | + public function securityScan($xml) | |
| 525 | + { | |
| 543 | 526 | $pattern = '/\\0?' . implode('\\0?', str_split('<!ENTITY')) . '\\0?/'; |
| 544 | - if (preg_match($pattern, $xml)) { | |
| 527 | + if (preg_match($pattern, $xml)) { | |
| 545 | 528 | throw new PHPExcel_Reader_Exception('Detected use of ENTITY in XML, spreadsheet file load() aborted to prevent XXE/XEE attacks'); |
| 546 | 529 | } |
| 547 | 530 | return $xml; |
| 548 | 531 | } |
| 532 | + | |
| 549 | 533 | } |
| 534 | + | |