PluginProbe
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin / 6.5.1.7
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin v6.5.1.7
6.5.1.7 6.5.1.6 6.5.1.5 6.5.1.4 6.5.1.3 6.5.1.2 6.5.1.1 6.5.0.9 6.5.0.8 6.5.0.7 6.5.0.6 trunk 3.4.2.40 3.4.2.41 3.4.2.42 3.4.2.43 3.4.2.44 3.4.2.45 3.4.2.46 3.4.2.47 3.4.2.48 3.4.2.49 3.4.2.50 6.3.2 6.3.3.1 All 47 releases
wpdatatables / lib / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Shared / XMLWriter.php

XMLWriter.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin 6.5.1.7, at lib/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Shared/XMLWriter.php

105 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PhpOffice\PhpSpreadsheet\Shared;
4
5 use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
6
7 class XMLWriter extends \XMLWriter
8 {
9 /** @var bool */
10 public static $debugEnabled = false;
11
12 /** Temporary storage method */
13 const STORAGE_MEMORY = 1;
14 const STORAGE_DISK = 2;
15
16 /**
17 * Temporary filename.
18 *
19 * @var string
20 */
21 private $tempFileName = '';
22
23 /**
24 * Create a new XMLWriter instance.
25 *
26 * @param int $temporaryStorage Temporary storage location
27 * @param string $temporaryStorageFolder Temporary storage folder
28 */
29 public function __construct($temporaryStorage = self::STORAGE_MEMORY, $temporaryStorageFolder = null)
30 {
31 // Open temporary storage
32 if ($temporaryStorage == self::STORAGE_MEMORY) {
33 $this->openMemory();
34 } else {
35 // Create temporary filename
36 if ($temporaryStorageFolder === null) {
37 $temporaryStorageFolder = File::sysGetTempDir();
38 }
39 $this->tempFileName = (string) @tempnam($temporaryStorageFolder, 'xml');
40
41 // Open storage
42 if (empty($this->tempFileName) || $this->openUri($this->tempFileName) === false) {
43 // Fallback to memory...
44 $this->openMemory();
45 }
46 }
47
48 // Set default values
49 if (self::$debugEnabled) {
50 $this->setIndent(true);
51 }
52 }
53
54 /**
55 * Destructor.
56 */
57 public function __destruct()
58 {
59 // Unlink temporary files
60 // There is nothing reasonable to do if unlink fails.
61 if ($this->tempFileName != '') {
62 /** @scrutinizer ignore-unhandled */
63 @unlink($this->tempFileName);
64 }
65 }
66
67 public function __wakeup(): void
68 {
69 $this->tempFileName = '';
70
71 throw new SpreadsheetException('Unserialize not permitted');
72 }
73
74 /**
75 * Get written data.
76 *
77 * @return string
78 */
79 public function getData()
80 {
81 if ($this->tempFileName == '') {
82 return $this->outputMemory(true);
83 }
84 $this->flush();
85
86 return file_get_contents($this->tempFileName) ?: '';
87 }
88
89 /**
90 * Wrapper method for writeRaw.
91 *
92 * @param null|string|string[] $rawTextData
93 *
94 * @return bool
95 */
96 public function writeRawData($rawTextData)
97 {
98 if (is_array($rawTextData)) {
99 $rawTextData = implode("\n", $rawTextData);
100 }
101
102 return $this->writeRaw(htmlspecialchars($rawTextData ?? ''));
103 }
104 }
105