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 require_once("content/classes/class.ilObjContentObject.php");
00025
00036 class ilContObjectExport
00037 {
00038 var $err;
00039 var $db;
00040 var $ilias;
00041 var $cont_obj;
00042 var $inst_id;
00043 var $mode;
00044
00049 function ilContObjectExport(&$a_cont_obj, $a_mode = "xml")
00050 {
00051 global $ilErr, $ilDB, $ilias;
00052
00053 $this->cont_obj =& $a_cont_obj;
00054
00055 $this->err =& $ilErr;
00056 $this->ilias =& $ilias;
00057 $this->db =& $ilDB;
00058 $this->mode = $a_mode;
00059
00060 $settings = $this->ilias->getAllSettings();
00061
00062 $this->inst_id = IL_INST_ID;
00063
00064 $date = time();
00065 switch($this->mode)
00066 {
00067 case "html":
00068 $this->export_dir = $this->cont_obj->getExportDirectory("html");
00069 $this->subdir = $this->cont_obj->getType()."_".$this->cont_obj->getId();
00070 $this->filename = $this->subdir.".zip";
00071 break;
00072
00073 case "scorm":
00074 $this->export_dir = $this->cont_obj->getExportDirectory("scorm");
00075 $this->subdir = $this->cont_obj->getType()."_".$this->cont_obj->getId();
00076 $this->filename = $this->subdir.".zip";
00077 break;
00078
00079 case "pdf":
00080 $this->export_dir = $this->cont_obj->getOfflineDirectory();
00081 $this->subdir = $date."__".$this->inst_id."__".
00082 $this->cont_obj->getType()."_".$this->cont_obj->getId();
00083 $this->filename = $this->subdir.".fo";
00084 break;
00085
00086 default:
00087 $this->export_dir = $this->cont_obj->getExportDirectory();
00088 $this->subdir = $date."__".$this->inst_id."__".
00089 $this->cont_obj->getType()."_".$this->cont_obj->getId();
00090 $this->filename = $this->subdir.".xml";
00091 break;
00092 }
00093 }
00094
00095 function getInstId()
00096 {
00097 return $this->inst_id;
00098 }
00099
00109 function exportRekursiv($depth, $left, $right)
00110 {
00111
00112 $query = "SELECT *
00113 FROM lm_tree, lm_data
00114 WHERE lm_tree.lm_id = ".$this->cont_obj->getId()."
00115 AND lm_tree.child = lm_data.obj_id
00116 AND ( lm_data.type = 'st' OR lm_data.type = 'pg' )
00117 AND lm_tree.depth = $depth
00118 AND lm_tree.lft>$left and lm_tree.rgt<$right
00119 ORDER BY lm_tree.lft";
00120
00121 $result = $this->db->query($query);
00122
00123 while (is_array($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) )
00124 {
00125 if ($row["type"] == "st")
00126 {
00127 $xml .= "<StructureObject>";
00128
00129 $nested = new ilNestedSetXML();
00130 $xml .= $nested->export($row["obj_id"],"st");
00131 $xml .= "\n";
00132
00133 $xml .= $this->exportRekursiv($depth+1, $row["lft"], $row["rgt"]);
00134
00135 $xml .= "</StructureObject>";
00136 }
00137
00138 if ($row["type"] == "pg")
00139 {
00140
00141 $query = "SELECT * FROM page_object WHERE page_id='".$row["obj_id"]."' ";
00142 $result2 = $this->db->query($query);
00143
00144 $row2 = $result2->fetchRow(DB_FETCHMODE_ASSOC);
00145
00146 $PO = $row2["content"]."\n";
00147
00148 if (stristr($PO,"MediaObject"))
00149 {
00150
00151 $dom = domxml_open_mem($PO);
00152 $xpc = xpath_new_context($dom);
00153 $path = "//MediaObject/MediaAlias";
00154 $res =& xpath_eval($xpc, $path);
00155 for($i = 0; $i < count($res->nodeset); $i++)
00156 {
00157 $id_arr = explode("_", $res->nodeset[$i]->get_attribute("OriginId"));
00158 $mob_id = $id_arr[count($id_arr) - 1];
00159 $this->mob_ids[$mob_id] = true;
00160 }
00161 }
00162
00163 $nested = new ilNestedSetXML();
00164 $mdxml = $nested->export($row["obj_id"],"pg");
00165
00166 $PO = str_replace("<PageObject>","<PageObject>\n$mdxml\n",$PO);
00167
00168 $xml .= $PO;
00169
00170 }
00171 }
00172 return($xml);
00173 }
00174
00175
00182 function buildExportFile()
00183 {
00184 switch ($this->mode)
00185 {
00186 case "html":
00187 return $this->buildExportFileHTML();
00188 break;
00189
00190 case "scorm":
00191 return $this->buildExportFileSCORM();
00192 break;
00193
00194 case "pdf":
00195 return $this->buildExportFilePDF();
00196 break;
00197
00198 default:
00199 return $this->buildExportFileXML();
00200 break;
00201 }
00202 }
00203
00207 function buildExportFileXML()
00208 {
00209 global $ilBench;
00210
00211 $ilBench->start("ContentObjectExport", "buildExportFile");
00212
00213 require_once("classes/class.ilXmlWriter.php");
00214
00215 $this->xml = new ilXmlWriter;
00216
00217
00218 $this->xml->xmlSetDtdDef("<!DOCTYPE ContentObject SYSTEM \"http://www.ilias.de/download/dtd/ilias_co_3_7.dtd\">");
00219
00220
00221 $this->xml->xmlSetGenCmt("Export of ILIAS Content Module ".
00222 $this->cont_obj->getId()." of installation ".$this->inst.".");
00223
00224
00225 $this->xml->xmlHeader();
00226
00227
00228 $this->cont_obj->createExportDirectory();
00229 ilUtil::makeDir($this->export_dir."/".$this->subdir);
00230 ilUtil::makeDir($this->export_dir."/".$this->subdir."/objects");
00231
00232
00233 $expDir = $this->cont_obj->getExportDirectory();
00234 $expLog = new ilLog($expDir, "export.log");
00235 $expLog->delete();
00236 $expLog->setLogFormat("");
00237 $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
00238
00239
00240
00241 $ilBench->start("ContentObjectExport", "buildExportFile_getXML");
00242 $this->cont_obj->exportXML($this->xml, $this->inst_id,
00243 $this->export_dir."/".$this->subdir, $expLog);
00244 $ilBench->stop("ContentObjectExport", "buildExportFile_getXML");
00245
00246
00247 if ($this->cont_obj->getStyleSheetId() > 0)
00248 {
00249 include_once("classes/class.ilObjStyleSheet.php");
00250 $style_obj = new ilObjStyleSheet($this->cont_obj->getStyleSheetId(), false);
00251 $style_obj->exportXML($this->export_dir."/".$this->subdir);
00252 }
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 $ilBench->start("ContentObjectExport", "buildExportFile_dumpToFile");
00263 $this->xml->xmlDumpFile($this->export_dir."/".$this->subdir."/".$this->filename
00264 , false);
00265 $ilBench->stop("ContentObjectExport", "buildExportFile_dumpToFile");
00266
00267
00268 $ilBench->start("ContentObjectExport", "buildExportFile_zipFile");
00269
00270 ilUtil::zip($this->export_dir."/".$this->subdir,
00271 $this->export_dir."/".$this->subdir.".zip");
00272 $ilBench->stop("ContentObjectExport", "buildExportFile_zipFile");
00273
00274
00275 $this->xml->_XmlWriter;
00276
00277 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
00278 $ilBench->stop("ContentObjectExport", "buildExportFile");
00279
00280 return $this->export_dir."/".$this->subdir.".zip";
00281 }
00282
00286 function buildExportFilePDF()
00287 {
00288 global $ilBench;
00289
00290 $ilBench->start("ContentObjectExport", "buildPDFFile");
00291
00292 require_once("classes/class.ilXmlWriter.php");
00293
00294 $this->xml = new ilXmlWriter;
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 $this->xml->xmlHeader();
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 $ilBench->start("ContentObjectExport", "buildPDFFile_getFO");
00321 $this->cont_obj->exportFO($this->xml,
00322 $this->export_dir."/".$this->subdir, $expLog);
00323 $ilBench->stop("ContentObjectExport", "buildPDFFile_getFO");
00324
00325
00326
00327 $ilBench->start("ContentObjectExport", "buildPDFFile_dumpToFile");
00328
00329 $this->xml->xmlDumpFile($this->export_dir."/".$this->filename
00330 , false);
00331 $ilBench->stop("ContentObjectExport", "buildPDFFile_dumpToFile");
00332
00333
00334
00335 include_once("classes/class.ilFOPUtil.php");
00336 ilFOPUtil::makePDF($this->export_dir."/".$this->filename,
00337 $this->export_dir."/".$this->subdir.".pdf");
00338
00339
00340
00341 $this->xml->_XmlWriter;
00342
00343
00344 $ilBench->stop("ContentObjectExport", "buildPDFFile");
00345 }
00346
00350 function buildExportFileHTML()
00351 {
00352 global $ilBench;
00353
00354 $ilBench->start("ContentObjectExport", "buildHTMLPackage");
00355
00356
00357 $this->cont_obj->createExportDirectory("html");
00358
00359
00360 $ilBench->start("ContentObjectExport", "buildHTMLPackage_getHTML");
00361 $this->cont_obj->exportHTML($this->export_dir."/".$this->subdir, $expLog);
00362 $ilBench->stop("ContentObjectExport", "buildHTMLPackage_getHTML");
00363
00364
00365 $ilBench->stop("ContentObjectExport", "buildHTMLPackage");
00366 }
00367
00371 function buildExportFileSCORM()
00372 {
00373 global $ilBench;
00374
00375 $ilBench->start("ContentObjectExport", "buildSCORMPackage");
00376
00377
00378 $this->cont_obj->createExportDirectory("scorm");
00379
00380
00381 $ilBench->start("ContentObjectExport", "buildSCORMPackage_getSCORM");
00382 $this->cont_obj->exportSCORM($this->export_dir."/".$this->subdir, $expLog);
00383 $ilBench->stop("ContentObjectExport", "buildSCORMPackage_getSCORM");
00384
00385
00386 $ilBench->stop("ContentObjectExport", "buildSCORMPackage");
00387 }
00388
00389 }
00390
00391 ?>