ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilFileXMLWriter.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once "./Services/Xml/classes/class.ilXmlWriter.php";
6 
22 {
23  static $CONTENT_ATTACH_NO = 0;
28 
29  // begin-patch fm
31  // end-patch fm
32 
39 
45  var $file;
46 
47  var $omit_header = false;
48 
56  function ilFileXMLWriter()
57  {
59  $this->attachFileContents = ilFileXMLWriter::$CONTENT_ATTACH_NO;
60  }
61 
62 
64  {
65  $this->file = & $file;
66  }
67 
68 
74  function setOmitHeader($a_val)
75  {
76  $this->omit_header = $a_val;
77  }
78 
84  function getOmitHeader()
85  {
86  return $this->omit_header;
87  }
88 
95  function setFileTargetDirectories($a_rel, $a_abs)
96  {
97  $this->target_dir_relative = $a_rel;
98  $this->target_dir_absolute = $a_abs;
99  }
100 
101 
109  {
110  if ($attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && !function_exists("gzencode"))
111  {
112  throw new ilFileException ("Inflating with gzip is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
113  }
114  if ($attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && !function_exists("gzcompress"))
115  {
116  throw new ilFileException ("Inflating with zlib (compress/uncompress) is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
117  }
118  $this->attachFileContents = $attachFileContents;
119  }
120 
121 
122  function start()
123  {
124  $this->__buildHeader();
125 
126  $attribs =array (
127  "obj_id" => "il_".IL_INST_ID."_file_".$this->file->getId(),
128  "version" => $this->file->getVersion(),
129  "size" => $this->file->getFileSize(),
130  "type" => $this->file->getFileType()
131  );
132 
133  $this->xmlStartTag("File", $attribs);
134  $this->xmlElement("Filename",null,$this->file->getFileName());
135 
136  $this->xmlElement("Title", null,$this->file->getTitle());
137  $this->xmlElement("Description", null,$this->file->getDescription());
138 
139 
140  if ($this->attachFileContents)
141  {
142  $filename = $this->file->getDirectory($this->file->getVersion())."/".$this->file->getFileName();
143  if (@is_file($filename))
144  {
145  if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_COPY)
146  {
147  $attribs = array("mode" =>"COPY");
148  copy($filename, $this->target_dir_absolute."/".$this->file->getFileName());
149  $content = $this->target_dir_relative."/".$this->file->getFileName();
150  $this->xmlElement("Content",$attribs, $content);
151  }
152  // begin-patch fm
153  elseif($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_REST)
154  {
155  $attribs = array('mode' => "REST");
156  include_once './Services/WebServices/Rest/classes/class.ilRestFileStorage.php';
157  $fs = new ilRestFileStorage();
158  $tmpname = $fs->storeFileForRest(base64_encode(@file_get_contents($filename)));
159  $this->xmlElement("Content",$attribs, $tmpname);
160  }
161  // end-patch fm
162  else
163  {
164  $content = @file_get_contents($filename);
165  $attribs = array("mode" =>"PLAIN");
166  if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED)
167  {
168  $attribs ["mode"] ="ZLIB";
169  $content = @gzcompress($content, 9);
170  }elseif ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED)
171  {
172  $attribs ["mode"] ="GZIP";
173  $content = @gzencode($content, 9);
174  }
175  $content = base64_encode($content);
176  $this->xmlElement("Content",$attribs, $content);
177  }
178  }
179 
180  }
181 
182  include_once("./Services/History/classes/class.ilHistory.php");
183 
184  $versions = ilHistory::_getEntriesForObject($this->file->getId(), $this->file->getType());
185 
186  if (count($versions)) {
187  $this->xmlStartTag("Versions");
188  foreach ($versions as $version) {
189  $info_params = $version["info_params"];
190  list($filename,$history_id) = split(",",$info_params);
191  $attribs = array (
192  "id" => $history_id,
193  "date" => ilUtil::date_mysql2time($version["date"]),
194  "usr_id" => "il_".IL_INST_ID."_usr_".$version["user_id"]
195  );
196  $this->xmlElement("Version", $attribs);
197  }
198  $this->xmlEndTag("Versions");
199 
200  }
201 
202  $this->xmlEndTag("File");
203 
204  $this->__buildFooter();
205 
206  return true;
207  }
208 
209  function getXML()
210  {
211  return $this->xmlDumpMem(false);
212  }
213 
214 
215  function __buildHeader()
216  {
217  if (!$this->getOmitHeader())
218  {
219  $this->xmlSetDtdDef("<!DOCTYPE File PUBLIC \"-//ILIAS//DTD FileAdministration//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_file_3_8.dtd\">");
220  $this->xmlSetGenCmt("Exercise Object");
221  $this->xmlHeader();
222  }
223 
224  return true;
225  }
226 
227  function __buildFooter()
228  {
229 
230  }
231 
232 }
233 
234 
235 ?>