| 1 |
<?php |
| 2 |
/** |
| 3 |
* PHPExcel |
| 4 |
* |
| 5 |
* Copyright (c) 2006 - 2014 PHPExcel |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2.1 of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public |
| 18 |
* License along with this library; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
* |
| 21 |
* @category PHPExcel |
| 22 |
* @package PHPExcel_Shared |
| 23 |
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) |
| 24 |
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
| 25 |
* @version ##VERSION##, ##DATE## |
| 26 |
*/ |
| 27 |
|
| 28 |
if (!defined('DATE_W3C')) { |
| 29 |
define('DATE_W3C', 'Y-m-d\TH:i:sP'); |
| 30 |
} |
| 31 |
|
| 32 |
if (!defined('DEBUGMODE_ENABLED')) { |
| 33 |
define('DEBUGMODE_ENABLED', false); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
/** |
| 38 |
* PHPExcel_Shared_XMLWriter |
| 39 |
* |
| 40 |
* @category PHPExcel |
| 41 |
* @package PHPExcel_Shared |
| 42 |
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) |
| 43 |
*/ |
| 44 |
class PHPExcel_Shared_XMLWriter extends XMLWriter { |
| 45 |
/** Temporary storage method */ |
| 46 |
const STORAGE_MEMORY = 1; |
| 47 |
const STORAGE_DISK = 2; |
| 48 |
|
| 49 |
/** |
| 50 |
* Temporary filename |
| 51 |
* |
| 52 |
* @var string |
| 53 |
*/ |
| 54 |
private $_tempFileName = ''; |
| 55 |
|
| 56 |
/** |
| 57 |
* Create a new PHPExcel_Shared_XMLWriter instance |
| 58 |
* |
| 59 |
* @param int $pTemporaryStorage Temporary storage location |
| 60 |
* @param string $pTemporaryStorageFolder Temporary storage folder |
| 61 |
*/ |
| 62 |
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = NULL) { |
| 63 |
// Open temporary storage |
| 64 |
if ($pTemporaryStorage == self::STORAGE_MEMORY) { |
| 65 |
$this->openMemory(); |
| 66 |
} else { |
| 67 |
// Create temporary filename |
| 68 |
if ($pTemporaryStorageFolder === NULL) |
| 69 |
$pTemporaryStorageFolder = PHPExcel_Shared_File::sys_get_temp_dir(); |
| 70 |
$this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml'); |
| 71 |
|
| 72 |
// Open storage |
| 73 |
if ($this->openUri($this->_tempFileName) === false) { |
| 74 |
// Fallback to memory... |
| 75 |
$this->openMemory(); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
// Set default values |
| 80 |
if (DEBUGMODE_ENABLED) { |
| 81 |
$this->setIndent(true); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Destructor |
| 87 |
*/ |
| 88 |
public function __destruct() { |
| 89 |
// Unlink temporary files |
| 90 |
if ($this->_tempFileName != '') { |
| 91 |
@unlink($this->_tempFileName); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Get written data |
| 97 |
* |
| 98 |
* @return $data |
| 99 |
*/ |
| 100 |
public function getData() { |
| 101 |
if ($this->_tempFileName == '') { |
| 102 |
return $this->outputMemory(true); |
| 103 |
} else { |
| 104 |
$this->flush(); |
| 105 |
return file_get_contents($this->_tempFileName); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Fallback method for writeRaw, introduced in PHP 5.2 |
| 111 |
* |
| 112 |
* @param string $text |
| 113 |
* @return string |
| 114 |
*/ |
| 115 |
public function writeRawData($text) |
| 116 |
{ |
| 117 |
if (is_array($text)) { |
| 118 |
$text = implode("\n",$text); |
| 119 |
} |
| 120 |
|
| 121 |
if (method_exists($this, 'writeRaw')) { |
| 122 |
return $this->writeRaw(htmlspecialchars($text)); |
| 123 |
} |
| 124 |
|
| 125 |
return $this->text($text); |
| 126 |
} |
| 127 |
} |
| 128 |
|