ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilFileXMLWriter.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  +-----------------------------------------------------------------------------+
5  | ILIAS open source |
6  +-----------------------------------------------------------------------------+
7  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
8  | |
9  | This program is free software; you can redistribute it and/or |
10  | modify it under the terms of the GNU General Public License |
11  | as published by the Free Software Foundation; either version 2 |
12  | of the License, or (at your option) any later version. |
13  | |
14  | This program is distributed in the hope that it will be useful, |
15  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17  | GNU General Public License for more details. |
18  | |
19  | You should have received a copy of the GNU General Public License |
20  | along with this program; if not, write to the Free Software |
21  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22  +-----------------------------------------------------------------------------+
23 */
24 
40 include_once "./classes/class.ilXmlWriter.php";
41 
42 
44 {
45  static $CONTENT_ATTACH_NO = 0;
55 
61  var $file;
62 
70  function ilFileXMLWriter()
71  {
73  $this->attachFileContents = ilFileXMLWriter::$CONTENT_ATTACH_NO;
74  }
75 
76 
78  {
79  $this->file = & $file;
80  }
81 
82 
83 
84 
92  {
93  if ($attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && !function_exists("gzencode"))
94  {
95  throw new ilFileException ("Inflating with gzip is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
96  }
97  if ($attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && !function_exists("gzcompress"))
98  {
99  throw new ilFileException ("Inflating with zlib (compress/uncompress) is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
100  }
101  $this->attachFileContents = $attachFileContents;
102  }
103 
104 
105  function start()
106  {
107  $this->__buildHeader();
108 
109  $attribs =array (
110  "obj_id" => "il_".IL_INST_ID."_file_".$this->file->getId(),
111  "version" => $this->file->getVersion(),
112  "size" => $this->file->getFileSize(),
113  "type" => $this->file->getFileType()
114  );
115 
116  $this->xmlStartTag("File", $attribs);
117  $this->xmlElement("Filename",null,$this->file->getFileName());
118 
119  $this->xmlElement("Title", null,$this->file->getTitle());
120  $this->xmlElement("Description", null,$this->file->getDescription());
121 
122 
123  if ($this->attachFileContents)
124  {
125  $filename = $this->file->getDirectory($this->file->getVersion())."/".$this->file->getFileName();
126  if (@is_file($filename))
127  {
128  $content = @file_get_contents($filename);
129  $attribs = array("mode" =>"PLAIN");
130  if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED)
131  {
132  $attribs ["mode"] ="ZLIB";
133  $content = @gzcompress($content, 9);
134  }elseif ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED)
135  {
136  $attribs ["mode"] ="GZIP";
137  $content = @gzencode($content, 9);
138  }
139  $content = base64_encode($content);
140  $this->xmlElement("Content",$attribs, $content);
141  }
142 
143  }
144 
145  include_once("classes/class.ilHistory.php");
146 
147  $versions = ilHistory::_getEntriesForObject($this->file->getId(), $this->file->getType());
148 
149  if (count($versions)) {
150  $this->xmlStartTag("Versions");
151  foreach ($versions as $version) {
152  $info_params = $version["info_params"];
153  list($filename,$history_id) = split(",",$info_params);
154  $attribs = array (
155  "id" => $history_id,
156  "date" => ilUtil::date_mysql2time($version["date"]),
157  "usr_id" => "il_".IL_INST_ID."_usr_".$version["user_id"]
158  );
159  $this->xmlElement("Version", $attribs);
160  }
161  $this->xmlEndTag("Versions");
162 
163  }
164 
165  $this->xmlEndTag("File");
166 
167  $this->__buildFooter();
168 
169  return true;
170  }
171 
172  function getXML()
173  {
174  return $this->xmlDumpMem(false);
175  }
176 
177 
178  function __buildHeader()
179  {
180  $this->xmlSetDtdDef("<!DOCTYPE File PUBLIC \"-//ILIAS//DTD FileAdministration//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_file_3_8.dtd\">");
181  $this->xmlSetGenCmt("Exercise Object");
182  $this->xmlHeader();
183 
184  return true;
185  }
186 
187  function __buildFooter()
188  {
189 
190  }
191 
192 }
193 
194 
195 ?>