PHPPowerPoint_Reader
[ class tree: PHPPowerPoint_Reader ] [ index: PHPPowerPoint_Reader ] [ all elements ]

Source for file Serialized.php

Documentation is available at Serialized.php

  1. <?php
  2. /**
  3.  * PHPPowerPoint
  4.  *
  5.  * Copyright (c) 2009 - 2010 PHPPowerPoint
  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   PHPPowerPoint
  22.  * @package    PHPPowerPoint_Reader
  23.  * @copyright  Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    0.1.0, 2009-04-27
  26.  */
  27.  
  28.  
  29. /** PHPPowerPoint */
  30. require_once 'PHPPowerPoint.php';
  31.  
  32. /** PHPPowerPoint_Reader_IReader */
  33. require_once 'PHPPowerPoint/Reader/IReader.php';
  34.  
  35. /** PHPPowerPoint_Shared_File */
  36. require_once 'PHPPowerPoint/Shared/File.php';
  37.  
  38.  
  39. /**
  40.  * PHPPowerPoint_Reader_Serialized
  41.  *
  42.  * @category   PHPPowerPoint
  43.  * @package    PHPPowerPoint_Reader
  44.  * @copyright  Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
  45.  */
  46. class PHPPowerPoint_Reader_Serialized implements PHPPowerPoint_Reader_IReader
  47. {
  48.     /**
  49.      * Can the current PHPPowerPoint_Reader_IReader read the file?
  50.      *
  51.      * @param     string         $pFileName 
  52.      * @return     boolean 
  53.      */    
  54.     public function canRead($pFilename
  55.     {
  56.         // Check if file exists
  57.         if (!file_exists($pFilename)) {
  58.             throw new Exception("Could not open " $pFilename " for reading! File does not exist.");
  59.         }
  60.         
  61.         return $this->fileSupportsUnserializePHPPowerPoint($pFilename);
  62.     }
  63.     
  64.     /**
  65.      * Loads PHPPowerPoint Serialized file
  66.      *
  67.      * @param     string         $pFilename 
  68.      * @return     PHPPowerPoint 
  69.      * @throws     Exception
  70.      */
  71.     public function load($pFilename)
  72.     {
  73.         // Check if file exists
  74.         if (!file_exists($pFilename)) {
  75.             throw new Exception("Could not open " $pFilename " for reading! File does not exist.");
  76.         }
  77.  
  78.         // Unserialize... First make sure the file supports it!
  79.         if (!$this->fileSupportsUnserializePHPPowerPoint($pFilename)) {
  80.             throw new Exception("Invalid file format for PHPPowerPoint_Reader_Serialized: " $pFilename ".");
  81.         }
  82.  
  83.         return $this->_loadSerialized($pFilename);
  84.     }
  85.  
  86.     /**
  87.      * Load PHPPowerPoint Serialized file
  88.      *
  89.      * @param     string         $pFilename 
  90.      * @return     PHPPowerPoint 
  91.      */
  92.     private function _loadSerialized($pFilename{
  93.         $xmlData simplexml_load_string(file_get_contents("zip://$pFilename#PHPPowerPoint.xml"));
  94.         $excel unserialize(base64_decode((string)$xmlData->data));
  95.  
  96.         // Update media links
  97.         for ($i 0$i $excel->getSlideCount()++$i{
  98.             for ($j 0$j $excel->getSlide($i)->getShapeCollection()->count()++$j{
  99.                 if ($excel->getSlide($i)->getShapeCollection()->offsetGet($jinstanceof PHPExcl_Shape_BaseDrawing{
  100.                     $imgTemp =$excel->getSlide($i)->getShapeCollection()->offsetGet($j);
  101.                     $imgTemp->setPath('zip://' $pFilename '#media/' $imgTemp->getFilename()false);
  102.                 }
  103.             }
  104.         }
  105.  
  106.         return $excel;
  107.     }
  108.  
  109.     /**
  110.      * Does a file support UnserializePHPPowerPoint ?
  111.      *
  112.      * @param     string         $pFilename 
  113.      * @throws     Exception
  114.      * @return     boolean 
  115.      */
  116.     public function fileSupportsUnserializePHPPowerPoint($pFilename ''{
  117.         // Check if file exists
  118.         if (!file_exists($pFilename)) {
  119.             throw new Exception("Could not open " $pFilename " for reading! File does not exist.");
  120.         }
  121.  
  122.         // File exists, does it contain PHPPowerPoint.xml?
  123.         return PHPPowerPoint_Shared_File::file_exists("zip://$pFilename#PHPPowerPoint.xml");
  124.     }
  125. }

Documentation generated on Sat, 25 Apr 2009 11:37:58 +0200 by phpDocumentor 1.4.1