Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00040 include_once "./classes/class.ilXmlWriter.php";
00041
00042
00043 class ilFileXMLWriter extends ilXmlWriter
00044 {
00045 static $CONTENT_ATTACH_NO = 0;
00046 static $CONTENT_ATTACH_ENCODED = 1;
00047 static $CONTENT_ATTACH_ZLIB_ENCODED = 2;
00048 static $CONTENT_ATTACH_GZIP_ENCODED = 3;
00054 var $attachFileContents;
00055
00061 var $file;
00062
00070 function ilFileXMLWriter()
00071 {
00072 parent::ilXmlWriter();
00073 $this->attachFileContents = ilFileXMLWriter::$CONTENT_ATTACH_NO;
00074 }
00075
00076
00077 function setFile(ilObjFile $file)
00078 {
00079 $this->file = & $file;
00080 }
00081
00082
00083
00084
00091 function setAttachFileContents($attachFileContents)
00092 {
00093 if ($attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && !function_exists("gzencode"))
00094 {
00095 throw new ilFileException ("Inflating with gzip is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
00096 }
00097 if ($attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && !function_exists("gzcompress"))
00098 {
00099 throw new ilFileException ("Inflating with zlib (compress/uncompress) is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
00100 }
00101 $this->attachFileContents = $attachFileContents;
00102 }
00103
00104
00105 function start()
00106 {
00107 $this->__buildHeader();
00108
00109 $attribs =array (
00110 "obj_id" => "il_".IL_INST_ID."_file_".$this->file->getId(),
00111 "version" => $this->file->getVersion(),
00112 "size" => $this->file->getFileSize(),
00113 "type" => $this->file->getFileType()
00114 );
00115
00116 $this->xmlStartTag("File", $attribs);
00117 $this->xmlElement("Filename",null,$this->file->getFileName());
00118
00119 $this->xmlElement("Title", null,$this->file->getTitle());
00120 $this->xmlElement("Description", null,$this->file->getDescription());
00121
00122
00123 if ($this->attachFileContents)
00124 {
00125 $filename = $this->file->getDirectory($this->file->getVersion())."/".$this->file->getFileName();
00126 if (@is_file($filename))
00127 {
00128 $content = @file_get_contents($filename);
00129 $attribs = array("mode" =>"PLAIN");
00130 if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED)
00131 {
00132 $attribs ["mode"] ="ZLIB";
00133 $content = @gzcompress($content, 9);
00134 }elseif ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED)
00135 {
00136 $attribs ["mode"] ="GZIP";
00137 $content = @gzencode($content, 9);
00138 }
00139 $content = base64_encode($content);
00140 $this->xmlElement("Content",$attribs, $content);
00141 }
00142
00143 }
00144
00145 include_once("classes/class.ilHistory.php");
00146
00147 $versions = ilHistory::_getEntriesForObject($this->file->getId(), $this->file->getType());
00148
00149 if (count($versions)) {
00150 $this->xmlStartTag("Versions");
00151 foreach ($versions as $version) {
00152 $info_params = $version["info_params"];
00153 list($filename,$history_id) = split(",",$info_params);
00154 $attribs = array (
00155 "id" => $history_id,
00156 "date" => ilUtil::date_mysql2time($version["date"]),
00157 "usr_id" => "il_".IL_INST_ID."_usr_".$version["user_id"]
00158 );
00159 $this->xmlElement("Version", $attribs);
00160 }
00161 $this->xmlEndTag("Versions");
00162
00163 }
00164
00165 $this->xmlEndTag("File");
00166
00167 $this->__buildFooter();
00168
00169 return true;
00170 }
00171
00172 function getXML()
00173 {
00174 return $this->xmlDumpMem(FALSE);
00175 }
00176
00177
00178 function __buildHeader()
00179 {
00180 $this->xmlSetDtdDef("<!DOCTYPE Exercise PUBLIC \"-//ILIAS//DTD FileAdministration//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_file_3_8.dtd\">");
00181 $this->xmlSetGenCmt("Exercise Object");
00182 $this->xmlHeader();
00183
00184 return true;
00185 }
00186
00187 function __buildFooter()
00188 {
00189
00190 }
00191
00192 }
00193
00194
00195 ?>