fileSupportsUnserializePhpPresentation($pFilename); } /** * Does a file support UnserializePhpPresentation ? * * @param string $pFilename * @throws \Exception * @return boolean */ public function fileSupportsUnserializePhpPresentation($pFilename = '') { // Check if file exists if (!file_exists($pFilename)) { throw new \Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // File exists, does it contain PhpPresentation.xml? return File::fileExists("zip://$pFilename#PhpPresentation.xml"); } /** * Loads PhpPresentation Serialized file * * @param string $pFilename * @return \PhpOffice\PhpPresentation\PhpPresentation * @throws \Exception */ public function load($pFilename) { // Check if file exists if (!file_exists($pFilename)) { throw new \Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // Unserialize... First make sure the file supports it! if (!$this->fileSupportsUnserializePhpPresentation($pFilename)) { throw new \Exception("Invalid file format for PhpOffice\PhpPresentation\Reader\Serialized: " . $pFilename . "."); } return $this->loadSerialized($pFilename); } /** * Load PhpPresentation Serialized file * * @param string $pFilename * @return \PhpOffice\PhpPresentation\PhpPresentation */ private function loadSerialized($pFilename) { $oArchive = new \ZipArchive(); if ($oArchive->open($pFilename) === true) { $xmlContent = $oArchive->getFromName('PhpPresentation.xml'); if (!empty($xmlContent)) { $xmlData = simplexml_load_string($xmlContent); $file = unserialize(base64_decode((string) $xmlData->data)); // Update media links for ($i = 0; $i < $file->getSlideCount(); ++$i) { for ($j = 0; $j < $file->getSlide($i)->getShapeCollection()->count(); ++$j) { if ($file->getSlide($i)->getShapeCollection()->offsetGet($j) instanceof AbstractDrawingAdapter) { $imgTemp = $file->getSlide($i)->getShapeCollection()->offsetGet($j); $imgTemp->setPath('zip://' . $pFilename . '#media/' . $imgTemp->getImageIndex() . '/' . pathinfo($imgTemp->getPath(), PATHINFO_BASENAME), false); } } } $oArchive->close(); return $file; } } return null; } }