ab771bd9c97954282d2989b87f249a87edbf42bd.svn-base 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. if (!defined('DATE_W3C')) {
  28. define('DATE_W3C', 'Y-m-d\TH:i:sP');
  29. }
  30. if (!defined('DEBUGMODE_ENABLED')) {
  31. define('DEBUGMODE_ENABLED', false);
  32. }
  33. /**
  34. * PHPExcel_Shared_XMLWriter
  35. *
  36. * @category PHPExcel
  37. * @package PHPExcel_Shared
  38. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  39. */
  40. class PHPExcel_Shared_XMLWriter extends XMLWriter {
  41. /** Temporary storage method */
  42. const STORAGE_MEMORY = 1;
  43. const STORAGE_DISK = 2;
  44. /**
  45. * Temporary filename
  46. *
  47. * @var string
  48. */
  49. private $_tempFileName = '';
  50. /**
  51. * Create a new PHPExcel_Shared_XMLWriter instance
  52. *
  53. * @param int $pTemporaryStorage Temporary storage location
  54. * @param string $pTemporaryStorageFolder Temporary storage folder
  55. */
  56. public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = NULL) {
  57. // Open temporary storage
  58. if ($pTemporaryStorage == self::STORAGE_MEMORY) {
  59. $this->openMemory();
  60. } else {
  61. // Create temporary filename
  62. if ($pTemporaryStorageFolder === NULL)
  63. $pTemporaryStorageFolder = PHPExcel_Shared_File::sys_get_temp_dir();
  64. $this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
  65. // Open storage
  66. if ($this->openUri($this->_tempFileName) === false) {
  67. // Fallback to memory...
  68. $this->openMemory();
  69. }
  70. }
  71. // Set default values
  72. if (DEBUGMODE_ENABLED) {
  73. $this->setIndent(true);
  74. }
  75. }
  76. /**
  77. * Destructor
  78. */
  79. public function __destruct() {
  80. // Unlink temporary files
  81. if ($this->_tempFileName != '') {
  82. @unlink($this->_tempFileName);
  83. }
  84. }
  85. /**
  86. * Get written data
  87. *
  88. * @return $data
  89. */
  90. public function getData() {
  91. if ($this->_tempFileName == '') {
  92. return $this->outputMemory(true);
  93. } else {
  94. $this->flush();
  95. return file_get_contents($this->_tempFileName);
  96. }
  97. }
  98. /**
  99. * Fallback method for writeRaw, introduced in PHP 5.2
  100. *
  101. * @param string $text
  102. * @return string
  103. */
  104. public function writeRawData($text)
  105. {
  106. if (is_array($text)) {
  107. $text = implode("\n",$text);
  108. }
  109. if (method_exists($this, 'writeRaw')) {
  110. return $this->writeRaw(htmlspecialchars($text));
  111. }
  112. return $this->text($text);
  113. }
  114. }