ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Serialized.php
Go to the documentation of this file.
1 <?php
30 if (!defined('PHPEXCEL_ROOT')) {
34  define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35 }
36 
38 require_once PHPEXCEL_ROOT . 'PHPExcel.php';
39 
41 require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReader.php';
42 
44 require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/File.php';
45 
46 
55 {
62  public function canRead($pFilename)
63  {
64  // Check if file exists
65  if (!file_exists($pFilename)) {
66  throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
67  }
68 
69  return $this->fileSupportsUnserializePHPExcel($pFilename);
70  }
71 
79  public function load($pFilename)
80  {
81  // Check if file exists
82  if (!file_exists($pFilename)) {
83  throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
84  }
85 
86  // Unserialize... First make sure the file supports it!
87  if (!$this->fileSupportsUnserializePHPExcel($pFilename)) {
88  throw new Exception("Invalid file format for PHPExcel_Reader_Serialized: " . $pFilename . ".");
89  }
90 
91  return $this->_loadSerialized($pFilename);
92  }
93 
100  private function _loadSerialized($pFilename) {
101  $xmlData = simplexml_load_string(file_get_contents("zip://$pFilename#phpexcel.xml"));
102  $excel = unserialize(base64_decode((string)$xmlData->data));
103 
104  // Update media links
105  for ($i = 0; $i < $excel->getSheetCount(); ++$i) {
106  for ($j = 0; $j < $excel->getSheet($i)->getDrawingCollection()->count(); ++$j) {
107  if ($excel->getSheet($i)->getDrawingCollection()->offsetGet($j) instanceof PHPExcl_Worksheet_BaseDrawing) {
108  $imgTemp =& $excel->getSheet($i)->getDrawingCollection()->offsetGet($j);
109  $imgTemp->setPath('zip://' . $pFilename . '#media/' . $imgTemp->getFilename(), false);
110  }
111  }
112  }
113 
114  return $excel;
115  }
116 
124  public function fileSupportsUnserializePHPExcel($pFilename = '') {
125  // Check if file exists
126  if (!file_exists($pFilename)) {
127  throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
128  }
129 
130  // File exists, does it contain phpexcel.xml?
131  return PHPExcel_Shared_File::file_exists("zip://$pFilename#phpexcel.xml");
132  }
133 }