PageRenderTime 36ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/phpexcel/PHPExcel/Shared/XMLWriter.php

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