Ejemplo n.º 1
0
 /**
  * export html package
  */
 function exportHTML($a_target_dir, $log, $a_zip_file = true, $a_export_format = "html", $a_lang = "")
 {
     global $tpl, $ilBench, $ilLocator, $ilUser, $ilObjDataCache, $ilias;
     $user_lang = $ilUser->getLanguage();
     if ($a_lang != "") {
         $ilUser->setLanguage($a_lang);
         $ilUser->setCurrentLanguage($a_lang);
         $ilObjDataCache->deleteCachedEntry($this->getId());
     }
     // initialize temporary target directory
     ilUtil::delDir($a_target_dir);
     ilUtil::makeDir($a_target_dir);
     $mob_dir = $a_target_dir . "/mobs";
     ilUtil::makeDir($mob_dir);
     $file_dir = $a_target_dir . "/files";
     ilUtil::makeDir($file_dir);
     $teximg_dir = $a_target_dir . "/teximg";
     ilUtil::makeDir($teximg_dir);
     $style_dir = $a_target_dir . "/style";
     ilUtil::makeDir($style_dir);
     $style_img_dir = $a_target_dir . "/style/images";
     ilUtil::makeDir($style_img_dir);
     $content_style_dir = $a_target_dir . "/content_style";
     ilUtil::makeDir($content_style_dir);
     $content_style_img_dir = $a_target_dir . "/content_style/images";
     ilUtil::makeDir($content_style_img_dir);
     $GLOBALS["teximgcnt"] = 0;
     // export system style sheet
     $location_stylesheet = ilUtil::getStyleSheetLocation("filesystem");
     $style_name = $ilUser->prefs["style"] . ".css";
     copy($location_stylesheet, $style_dir . "/" . $style_name);
     $fh = fopen($location_stylesheet, "r");
     $css = fread($fh, filesize($location_stylesheet));
     preg_match_all("/url\\(([^\\)]*)\\)/", $css, $files);
     foreach (array_unique($files[1]) as $fileref) {
         $css_fileref = str_replace(array("'", '"'), "", $fileref);
         $fileref = dirname($location_stylesheet) . "/" . $css_fileref;
         if (is_file($fileref)) {
             //echo "<br>make dir: ".dirname($style_dir."/".$css_fileref);
             ilUtil::makeDirParents(dirname($style_dir . "/" . $css_fileref));
             //echo "<br>copy: ".$fileref." TO ".$style_dir."/".$css_fileref;
             copy($fileref, $style_dir . "/" . $css_fileref);
         }
     }
     fclose($fh);
     $location_stylesheet = ilUtil::getStyleSheetLocation();
     // export content style sheet
     $ilBench->start("ExportHTML", "exportContentStyle");
     if ($this->getStyleSheetId() < 1) {
         $cont_stylesheet = "./Services/COPage/css/content.css";
         $css = fread(fopen($cont_stylesheet, 'r'), filesize($cont_stylesheet));
         preg_match_all("/url\\(([^\\)]*)\\)/", $css, $files);
         foreach (array_unique($files[1]) as $fileref) {
             if (is_file(str_replace("..", ".", $fileref))) {
                 copy(str_replace("..", ".", $fileref), $content_style_img_dir . "/" . basename($fileref));
             }
             $css = str_replace($fileref, "images/" . basename($fileref), $css);
         }
         fwrite(fopen($content_style_dir . "/content.css", 'w'), $css);
     } else {
         $style = new ilObjStyleSheet($this->getStyleSheetId());
         $style->writeCSSFile($content_style_dir . "/content.css", "images");
         $style->copyImagesToDir($content_style_img_dir);
     }
     $ilBench->stop("ExportHTML", "exportContentStyle");
     // export syntax highlighting style
     $syn_stylesheet = ilObjStyleSheet::getSyntaxStylePath();
     copy($syn_stylesheet, $a_target_dir . "/syntaxhighlight.css");
     // get learning module presentation gui class
     include_once "./Modules/LearningModule/classes/class.ilLMPresentationGUI.php";
     $_GET["cmd"] = "nop";
     $lm_gui =& new ilLMPresentationGUI();
     $lm_gui->setOfflineMode(true);
     $lm_gui->setOfflineDirectory($a_target_dir);
     $lm_gui->setExportFormat($a_export_format);
     $ot = ilObjectTranslation::getInstance($this->getId());
     if ($a_lang != "") {
         if ($a_lang == $ot->getMasterLanguage()) {
             $lm_gui->lang = "";
         } else {
             $lm_gui->lang = $a_lang;
         }
     }
     // export pages
     $ilBench->start("ExportHTML", "exportHTMLPages");
     $this->exportHTMLPages($lm_gui, $a_target_dir, $lm_gui->lang);
     $ilBench->stop("ExportHTML", "exportHTMLPages");
     // export glossary terms
     $ilBench->start("ExportHTML", "exportHTMLGlossaryTerms");
     $this->exportHTMLGlossaryTerms($lm_gui, $a_target_dir);
     $ilBench->stop("ExportHTML", "exportHTMLGlossaryTerms");
     // export all media objects
     $ilBench->start("ExportHTML", "exportHTMLMediaObjects");
     $linked_mobs = array();
     foreach ($this->offline_mobs as $mob) {
         if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob") {
             $this->exportHTMLMOB($a_target_dir, $lm_gui, $mob, "_blank", $linked_mobs);
         }
     }
     $linked_mobs2 = array();
     // mobs linked in link areas
     foreach ($linked_mobs as $mob) {
         if (ilObject::_exists($mob)) {
             $this->exportHTMLMOB($a_target_dir, $lm_gui, $mob, "_blank", $linked_mobs2);
         }
     }
     $_GET["obj_type"] = "MediaObject";
     $_GET["obj_id"] = $a_mob_id;
     $_GET["cmd"] = "";
     $ilBench->stop("ExportHTML", "exportHTMLMediaObjects");
     // export all file objects
     $ilBench->start("ExportHTML", "exportHTMLFileObjects");
     foreach ($this->offline_files as $file) {
         $this->exportHTMLFile($a_target_dir, $file);
     }
     $ilBench->stop("ExportHTML", "exportHTMLFileObjects");
     // export questions (images)
     if (count($this->q_ids) > 0) {
         foreach ($this->q_ids as $q_id) {
             ilUtil::makeDirParents($a_target_dir . "/assessment/0/" . $q_id . "/images");
             ilUtil::rCopy(ilUtil::getWebspaceDir() . "/assessment/0/" . $q_id . "/images", $a_target_dir . "/assessment/0/" . $q_id . "/images");
         }
     }
     // export table of contents
     $ilBench->start("ExportHTML", "exportHTMLTOC");
     $ilLocator->clearItems();
     if ($this->isActiveTOC()) {
         $tpl = new ilTemplate("tpl.main.html", true, true);
         //$tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
         $content =& $lm_gui->showTableOfContents();
         $file = $a_target_dir . "/table_of_contents.html";
         // open file
         if (!($fp = @fopen($file, "w+"))) {
             die("<b>Error</b>: Could not open \"" . $file . "\" for writing" . " in <b>" . __FILE__ . "</b> on line <b>" . __LINE__ . "</b><br />");
         }
         chmod($file, 0770);
         fwrite($fp, $content);
         fclose($fp);
     }
     $ilBench->stop("ExportHTML", "exportHTMLTOC");
     // export images
     $ilBench->start("ExportHTML", "exportHTMLImages");
     $image_dir = $a_target_dir . "/images";
     ilUtil::makeDir($image_dir);
     ilUtil::makeDir($image_dir . "/browser");
     copy(ilUtil::getImagePath("enlarge.svg", false, "filesystem"), $image_dir . "/enlarge.svg");
     copy(ilUtil::getImagePath("browser/blank.png", false, "filesystem"), $image_dir . "/browser/plus.png");
     copy(ilUtil::getImagePath("browser/blank.png", false, "filesystem"), $image_dir . "/browser/minus.png");
     copy(ilUtil::getImagePath("browser/blank.png", false, "filesystem"), $image_dir . "/browser/blank.png");
     copy(ilUtil::getImagePath("spacer.png", false, "filesystem"), $image_dir . "/spacer.png");
     copy(ilUtil::getImagePath("icon_st.svg", false, "filesystem"), $image_dir . "/icon_st.svg");
     copy(ilUtil::getImagePath("icon_pg.svg", false, "filesystem"), $image_dir . "/icon_pg.svg");
     copy(ilUtil::getImagePath("icon_lm.svg", false, "filesystem"), $image_dir . "/icon_lm.svg");
     copy(ilUtil::getImagePath("nav_arr_L.png", false, "filesystem"), $image_dir . "/nav_arr_L.png");
     copy(ilUtil::getImagePath("nav_arr_R.png", false, "filesystem"), $image_dir . "/nav_arr_R.png");
     $ilBench->stop("ExportHTML", "exportHTMLImages");
     // export flv/mp3 player
     $services_dir = $a_target_dir . "/Services";
     ilUtil::makeDir($services_dir);
     $media_service_dir = $services_dir . "/MediaObjects";
     ilUtil::makeDir($media_service_dir);
     include_once "./Services/MediaObjects/classes/class.ilPlayerUtil.php";
     $flv_dir = $a_target_dir . "/" . ilPlayerUtil::getFlashVideoPlayerDirectory();
     ilUtil::makeDir($flv_dir);
     $mp3_dir = $media_service_dir . "/flash_mp3_player";
     ilUtil::makeDir($mp3_dir);
     //		copy(ilPlayerUtil::getFlashVideoPlayerFilename(true),
     //			$flv_dir."/".ilPlayerUtil::getFlashVideoPlayerFilename());
     ilPlayerUtil::copyPlayerFilesToTargetDirectory($flv_dir);
     include_once "./Services/UIComponent/Explorer2/classes/class.ilExplorerBaseGUI.php";
     ilExplorerBaseGUI::createHTMLExportDirs($a_target_dir);
     ilPlayerUtil::copyPlayerFilesToTargetDirectory($flv_dir);
     // js files
     ilUtil::makeDir($a_target_dir . '/js');
     ilUtil::makeDir($a_target_dir . '/js/yahoo');
     ilUtil::makeDir($a_target_dir . '/css');
     include_once "./Services/YUI/classes/class.ilYuiUtil.php";
     foreach (self::getSupplyingExportFiles($a_target_dir) as $f) {
         if ($f["source"] != "") {
             copy($f["source"], $f["target"]);
         }
     }
     // template workaround: reset of template
     $tpl = new ilTemplate("tpl.main.html", true, true);
     $tpl->setVariable("LOCATION_STYLESHEET", $location_stylesheet);
     $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
     if ($a_lang != "") {
         $ilUser->setLanguage($user_lang);
         $ilUser->setCurrentLanguage($user_lang);
     }
     // zip everything
     if ($a_zip_file) {
         if ($a_lang == "") {
             $zip_target_dir = $this->getExportDirectory("html");
         } else {
             $zip_target_dir = $this->getExportDirectory("html_" . $a_lang);
             ilUtil::makeDir($zip_target_dir);
         }
         // zip it all
         $date = time();
         $zip_file = $zip_target_dir . "/" . $date . "__" . IL_INST_ID . "__" . $this->getType() . "_" . $this->getId() . ".zip";
         //echo "-".$a_target_dir."-".$zip_file."-"; exit;
         ilUtil::zip($a_target_dir, $zip_file);
         ilUtil::delDir($a_target_dir);
     }
 }