1 | <?php |
||
30 | class PowerPoint2007 extends AbstractWriter implements WriterInterface |
||
31 | { |
||
32 | /** |
||
33 | * Use disk caching where possible? |
||
34 | * |
||
35 | * @var boolean |
||
36 | */ |
||
37 | protected $useDiskCaching = false; |
||
38 | |||
39 | /** |
||
40 | * Disk caching directory |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $diskCachingDir; |
||
45 | |||
46 | /** |
||
47 | * Layout pack to use |
||
48 | * @deprecated 0.7 |
||
49 | * @var \PhpOffice\PhpPresentation\Writer\PowerPoint2007\LayoutPack\AbstractLayoutPack |
||
50 | */ |
||
51 | protected $layoutPack; |
||
52 | |||
53 | /** |
||
54 | * Create a new PowerPoint2007 file |
||
55 | * |
||
56 | * @param PhpPresentation $pPhpPresentation |
||
57 | */ |
||
58 | 125 | public function __construct(PhpPresentation $pPhpPresentation = null) |
|
74 | |||
75 | /** |
||
76 | * Save PhpPresentation to file |
||
77 | * |
||
78 | * @param string $pFilename |
||
79 | * @throws \Exception |
||
80 | */ |
||
81 | 119 | public function save($pFilename) |
|
82 | { |
||
83 | 119 | if (empty($pFilename)) { |
|
84 | 1 | throw new \Exception("Filename is empty"); |
|
85 | } |
||
86 | 118 | $oPresentation = $this->getPhpPresentation(); |
|
87 | |||
88 | // If $pFilename is php://output or php://stdout, make it a temporary file... |
||
89 | 117 | $originalFilename = $pFilename; |
|
90 | 117 | if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') { |
|
91 | $pFilename = @tempnam('./', 'phppttmp'); |
||
92 | if ($pFilename == '') { |
||
93 | $pFilename = $originalFilename; |
||
94 | } |
||
95 | } |
||
96 | |||
97 | // Create drawing dictionary |
||
98 | 117 | $this->getDrawingHashTable()->addFromSource($this->allDrawings()); |
|
99 | |||
100 | 117 | $oZip = $this->getZipAdapter(); |
|
101 | 117 | $oZip->open($pFilename); |
|
102 | |||
103 | 117 | $oDir = new DirectoryIterator(dirname(__FILE__).DIRECTORY_SEPARATOR.'PowerPoint2007'); |
|
104 | 117 | $arrayFiles = array(); |
|
105 | 117 | foreach ($oDir as $oFile) { |
|
106 | 117 | if (!$oFile->isFile()) { |
|
107 | 117 | continue; |
|
108 | } |
||
109 | |||
110 | 117 | $class = __NAMESPACE__ . '\\PowerPoint2007\\' . $oFile->getBasename('.php'); |
|
111 | 117 | $o = new \ReflectionClass($class); |
|
112 | |||
113 | 117 | if ($o->isAbstract() || !$o->isSubclassOf('PhpOffice\PhpPresentation\Writer\PowerPoint2007\AbstractDecoratorWriter')) { |
|
114 | 117 | continue; |
|
115 | } |
||
116 | 117 | $arrayFiles[$oFile->getBasename('.php')] = $o; |
|
117 | } |
||
118 | |||
119 | 117 | ksort($arrayFiles); |
|
120 | |||
121 | 117 | foreach ($arrayFiles as $o) { |
|
122 | 117 | $oService = $o->newInstance(); |
|
123 | 117 | $oService->setZip($oZip); |
|
124 | 117 | $oService->setPresentation($oPresentation); |
|
125 | 117 | $oService->setDrawingHashTable($this->getDrawingHashTable()); |
|
126 | 117 | $oZip = $oService->render(); |
|
127 | 117 | unset($oService); |
|
128 | } |
||
129 | |||
130 | // Close file |
||
131 | 114 | $oZip->close(); |
|
132 | |||
133 | // If a temporary file was used, copy it to the correct file stream |
||
134 | 114 | if ($originalFilename != $pFilename) { |
|
135 | if (copy($pFilename, $originalFilename) === false) { |
||
136 | throw new \Exception("Could not copy temporary zip file $pFilename to $originalFilename."); |
||
137 | } |
||
138 | if (@unlink($pFilename) === false) { |
||
139 | throw new \Exception('The file '.$pFilename.' could not be removed.'); |
||
140 | } |
||
141 | } |
||
142 | 114 | } |
|
143 | |||
144 | /** |
||
145 | * Get use disk caching where possible? |
||
146 | * |
||
147 | * @return boolean |
||
148 | */ |
||
149 | 1 | public function hasDiskCaching() |
|
153 | |||
154 | /** |
||
155 | * Set use disk caching where possible? |
||
156 | * |
||
157 | * @param boolean $pValue |
||
158 | * @param string $pDirectory Disk caching directory |
||
159 | * @throws \Exception |
||
160 | * @return \PhpOffice\PhpPresentation\Writer\PowerPoint2007 |
||
161 | */ |
||
162 | 2 | public function setUseDiskCaching($pValue = false, $pDirectory = null) |
|
163 | { |
||
164 | 2 | $this->useDiskCaching = $pValue; |
|
165 | |||
166 | 2 | if (!is_null($pDirectory)) { |
|
167 | 2 | if (!is_dir($pDirectory)) { |
|
168 | 1 | throw new \Exception("Directory does not exist: $pDirectory"); |
|
169 | } |
||
170 | 1 | $this->diskCachingDir = $pDirectory; |
|
171 | } |
||
172 | |||
173 | 1 | return $this; |
|
174 | } |
||
175 | |||
176 | /** |
||
177 | * Get disk caching directory |
||
178 | * |
||
179 | * @return string |
||
180 | */ |
||
181 | 2 | public function getDiskCachingDirectory() |
|
185 | |||
186 | /** |
||
187 | * Get layout pack to use |
||
188 | * |
||
189 | * @deprecated 0.7 |
||
190 | * @return \PhpOffice\PhpPresentation\Writer\PowerPoint2007\LayoutPack\AbstractLayoutPack |
||
191 | */ |
||
192 | 2 | public function getLayoutPack() |
|
196 | |||
197 | /** |
||
198 | * Set layout pack to use |
||
199 | * |
||
200 | * @deprecated 0.7 |
||
201 | * @param \PhpOffice\PhpPresentation\Writer\PowerPoint2007\LayoutPack\AbstractLayoutPack $pValue |
||
202 | * @return \PhpOffice\PhpPresentation\Writer\PowerPoint2007 |
||
203 | */ |
||
204 | 1 | public function setLayoutPack(AbstractLayoutPack $pValue = null) |
|
210 | } |
||
211 |
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.