ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
LMHtmlExport.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
6
8
15{
19 protected $main_tpl;
20
24 protected $user;
25
29 protected $locator;
30
35
39 protected $export_format;
40
44 protected $lm_gui;
45
49 protected $obj_transl;
50
54 protected $lang;
55
59 protected $lm_settings;
60
64 protected $offline_files = [];
65
70
75
79 protected $global_screen;
80
84 public function __construct(
86 $export_dir,
87 $sub_dir,
88 $export_format = "html",
89 $lang = ""
90 ) {
91 global $DIC;
92
93 $this->locator = $DIC["ilLocator"];
94 $this->user = $DIC->user();
95 $this->lm = $lm;
96 $this->export_dir = $export_dir;
97 $this->sub_dir = $sub_dir;
98 $this->lang = $lang;
99 $this->target_dir = $export_dir . "/" . $sub_dir;
100 $this->co_page_html_export = new \ilCOPageHTMLExport($this->target_dir, $this->getLinker(), $lm->getRefId());
101 $this->co_page_html_export->setContentStyleId(\ilObjStyleSheet::getEffectiveContentStyleId(
102 $this->lm->getStyleSheetId(),
103 "lm"
104 ));
105 $this->export_format = $export_format;
106
107 // get learning module presentation gui class
108 $this->lm_gui = new \ilLMPresentationGUI($export_format, ($lang == "all"), $this->target_dir, false);
109 $this->obj_transl = \ilObjectTranslation::getInstance($lm->getId());
110
111 $this->lm_settings = new \ilSetting("lm");
112
113 $this->log = \ilLoggerFactory::getLogger("lm");
114
115 $this->initial_user_language = $this->user->getLanguage();
116 $this->initial_current_user_language = $this->user->getCurrentLanguage();
117
118 $this->global_screen = $DIC->globalScreen();
119 $this->export_util = new \ILIAS\Services\Export\HTML\Util($export_dir, $sub_dir);
120
122 }
123
130 protected function getLinker() : PageLinker
131 {
132 return new \ilLMPresentationLinker(
133 $this->lm,
134 new \ilLMTree($this->lm->getId()),
135 0,
136 $this->lm->getRefId(),
137 $this->lang,
138 "",
139 "",
140 true,
141 "html",
142 false
143 );
144 }
145
146
153 protected function setAdditionalContextData($key, $data)
154 {
155 $additional_data = $this->global_screen->tool()->context()->current()->getAdditionalData();
156 if ($additional_data->exists($key)) {
157 $additional_data->replace($key, $data);
158 } else {
159 $additional_data->add($key, $data);
160 }
161 }
162
163
167 protected function resetUserLanguage()
168 {
169 $this->user->setLanguage($this->initial_user_language);
170 $this->user->setCurrentLanguage($this->initial_current_user_language);
171 }
172
173
177 protected function initDirectories()
178 {
179 // initialize temporary target directory
180 \ilUtil::delDir($this->target_dir);
181 \ilUtil::makeDir($this->target_dir);
182 foreach (["mobs", "files", "textimg", "style",
183 "style/images", "content_style", "content_style", "content_style/images"] as $dir) {
184 \ilUtil::makeDir($this->target_dir . "/" . $dir);
185 }
186 }
187
188
195 protected function getLanguageIterator() : \Iterator
196 {
197 return new class($this->lang, $this->obj_transl) implements \Iterator {
201 private $position = 0;
202
206 private $langs = [];
207
212 public function __construct(string $lang, \ilObjectTranslation $obj_transl)
213 {
214 $this->position = 0;
215 if ($lang != "all") {
216 $this->langs = [$lang];
217 } else {
218 foreach ($obj_transl->getLanguages() as $otl) {
219 $this->langs[] = $otl["lang_code"];
220 }
221 }
222 }
223
224 public function rewind()
225 {
226 $this->position = 0;
227 }
228
229 public function current()
230 {
231 return $this->langs[$this->position];
232 }
233
234 public function key()
235 {
236 return $this->position;
237 }
238
239 public function next()
240 {
241 ++$this->position;
242 }
243
244 public function valid()
245 {
246 return isset($this->langs[$this->position]);
247 }
248 };
249 }
250
259 {
260 $user_lang = $user->getLanguage();
261
262 if ($lang != "") {
263 $user->setLanguage($lang);
264 $user->setCurrentLanguage($lang);
265 } else {
266 $user->setLanguage($user_lang);
267 $user->setCurrentLanguage($user_lang);
268 }
269
270 if ($lang != "") {
271 if ($lang == $this->obj_transl->getMasterLanguage()) {
272 $lm_gui->lang = "";
273 } else {
274 $lm_gui->lang = $lang;
275 }
276 }
277 }
278
282 protected function initGlobalScreen()
283 {
284 // set global
285 $this->global_screen->tool()->context()->current()->addAdditionalData(
287 true
288 );
289 }
290
291
296 public function exportHTML($zip = true)
297 {
298 $this->initGlobalScreen();
299 $this->initDirectories();
300
301 $this->export_util->exportSystemStyle();
302 $this->export_util->exportCOPageFiles($this->lm->getStyleSheetId(), "lm");
303
304 $lang_iterator = $this->getLanguageIterator();
305
306 // iterate all languages
307 foreach ($lang_iterator as $lang) {
308 $this->initLanguage($this->user, $this->lm_gui, $lang);
309 $this->exportHTMLPages();
310 }
311
312 // export flv/mp3 player
313 /*
314 $services_dir = $a_target_dir."/Services";
315 ilUtil::makeDir($services_dir);
316 $media_service_dir = $services_dir."/MediaObjects";
317 ilUtil::makeDir($media_service_dir);
318 $flv_dir = $a_target_dir."/".ilPlayerUtil::getFlashVideoPlayerDirectory();
319 ilUtil::makeDirParents($flv_dir);
320 $mp3_dir = $media_service_dir."/flash_mp3_player";
321 ilUtil::makeDir($mp3_dir);
322 ilPlayerUtil::copyPlayerFilesToTargetDirectory($flv_dir);
323 ilExplorerBaseGUI::createHTMLExportDirs($a_target_dir);
324 ilPlayerUtil::copyPlayerFilesToTargetDirectory($flv_dir);
325
326 // js files
327 ilUtil::makeDir($a_target_dir.'/js');
328 ilUtil::makeDir($a_target_dir.'/js/yahoo');
329 ilUtil::makeDir($a_target_dir.'/css');
330 foreach (self::getSupplyingExportFiles($a_target_dir) as $f)
331 {
332 if ($f["source"] != "")
333 {
334 ilUtil::makeDirParents(dirname($f["target"]));
335 copy($f["source"], $f["target"]);
336 }
337 }*/
338
339 // template workaround: reset of template
340 /*
341 $tpl = new ilGlobalTemplate("tpl.main.html", true, true);
342 $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
343 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
344 */
345
346 $this->resetUserLanguage();
347
349
350 $this->export_util->exportResourceFiles();
351
352 $this->co_page_html_export->exportPageElements();
353
354 // zip everything
355 if ($zip) {
356 $this->zipPackage();
357 }
358 }
359
363 protected function zipPackage()
364 {
365 if ($this->lang == "") {
366 $zip_target_dir = $this->lm->getExportDirectory("html");
367 } else {
368 $zip_target_dir = $this->lm->getExportDirectory("html_" . $this->lang);
369 \ilUtil::makeDir($zip_target_dir);
370 }
371
372 // zip it all
373 $date = time();
374 $zip_file = $zip_target_dir . "/" . $date . "__" . IL_INST_ID . "__" .
375 $this->lm->getType() . "_" . $this->lm->getId() . ".zip";
376 \ilUtil::zip($this->target_dir, $zip_file);
377 \ilUtil::delDir($this->target_dir);
378 }
379
380
384 protected function addSupplyingExportFiles()
385 {
386 foreach ($this->getSupplyingExportFiles() as $f) {
387 if ($f["type"] == "js") {
388 $this->global_screen->layout()->meta()->addJs($f["source"]);
389 }
390 if ($f["type"] == "css") {
391 $this->global_screen->layout()->meta()->addCss($f["source"]);
392 }
393 }
394 }
395
396
403 protected function getSupplyingExportFiles($a_target_dir = ".")
404 {
405 $scripts = array(
406 array("source" => \ilYuiUtil::getLocalPath('yahoo/yahoo-min.js'),
407 "target" => $a_target_dir . '/js/yahoo/yahoo-min.js',
408 "type" => "js"),
409 array("source" => \ilYuiUtil::getLocalPath('yahoo-dom-event/yahoo-dom-event.js'),
410 "target" => $a_target_dir . '/js/yahoo/yahoo-dom-event.js',
411 "type" => "js"),
412 array("source" => \ilYuiUtil::getLocalPath('animation/animation-min.js'),
413 "target" => $a_target_dir . '/js/yahoo/animation-min.js',
414 "type" => "js"),
415 array("source" => './Services/Accordion/js/accordion.js',
416 "target" => $a_target_dir . '/js/accordion.js',
417 "type" => "js"),
418 array("source" => './Services/Accordion/css/accordion.css',
419 "target" => $a_target_dir . '/css/accordion.css',
420 "type" => "css"),
421 array("source" => './Modules/Scorm2004/scripts/questions/pure.js',
422 "target" => $a_target_dir . '/js/pure.js',
423 "type" => "js"),
424 array("source" => './Modules/Scorm2004/scripts/questions/question_handling.js',
425 "target" => $a_target_dir . '/js/question_handling.js',
426 "type" => "js"),
427 array("source" => './Modules/Scorm2004/templates/default/question_handling.css',
428 "target" => $a_target_dir . '/css/question_handling.css',
429 "type" => "css"),
430 array("source" => './Modules/TestQuestionPool/templates/default/test_javascript.css',
431 "target" => $a_target_dir . '/css/test_javascript.css',
432 "type" => "css"),
434 "target" => $a_target_dir . "/" . \ilExplorerBaseGUI::getLocalExplorerJsPath(),
435 "type" => "js"),
436 array("source" => \ilExplorerBaseGUI::getLocalJsTreeJsPath(),
437 "target" => $a_target_dir . "/" . \ilExplorerBaseGUI::getLocalJsTreeJsPath(),
438 "type" => "js"),
439 array("source" => \ilExplorerBaseGUI::getLocalJsTreeCssPath(),
440 "target" => $a_target_dir . "/" . \ilExplorerBaseGUI::getLocalJsTreeCssPath(),
441 "type" => "css"),
442 array("source" => './Modules/LearningModule/js/LearningModule.js',
443 "target" => $a_target_dir . '/js/LearningModule.js',
444 "type" => "js")
445 );
446
447 $mathJaxSetting = new \ilSetting("MathJax");
448 $use_mathjax = $mathJaxSetting->get("enable");
449 if ($use_mathjax) {
450 $scripts[] = array("source" => "",
451 "target" => $mathJaxSetting->get("path_to_mathjax"),
452 "type" => "js");
453 }
454
455 // auto linking js
456 foreach (\ilLinkifyUtil::getLocalJsPaths() as $p) {
457 if (is_int(strpos($p, "ExtLink"))) {
458 $scripts[] = array("source" => $p,
459 "target" => $a_target_dir . '/js/ilExtLink.js',
460 "type" => "js");
461 }
462 if (is_int(strpos($p, "linkify"))) {
463 $scripts[] = array("source" => $p,
464 "target" => $a_target_dir . '/js/linkify.js',
465 "type" => "js");
466 }
467 }
468
469 // check, why these do not come with the gs meta collector
470 $scripts[] = [
471 "source" => "src/UI/templates/js/MainControls/mainbar.js",
472 "type" => "js"
473 ];
474 $scripts[] = [
475 "source" => "src/UI/templates/js/MainControls/metabar.js",
476 "type" => "js"
477 ];
478 $scripts[] = [
479 "source" => "src/UI/templates/js/MainControls/slate.js",
480 "type" => "js"
481 ];
482 $scripts[] = [
483 "source" => "src/UI/templates/js/Page/stdpage.js",
484 "type" => "js"
485 ];
486 $scripts[] = [
487 "source" => "src/GlobalScreen/Client/dist/GS.js",
488 "type" => "js"
489 ];
490
491 return $scripts;
492 }
493
494
495
499 public function exportHTMLPages()
500 {
501 $lm = $this->lm;
503 $lang = $lm_gui->lang;
504 $all_languages = ($this->lang == "all");
506
507 $ilLocator = $this->locator;
508
509 $pages = \ilLMPageObject::getPageList($lm->getId());
510
511 $lm_tree = $lm->getLMTree();
512 $first_page = $lm_tree->fetchSuccessorNode($lm_tree->getRootId(), "pg");
513 $first_page_id = $first_page["child"];
514
515 // iterate all learning module pages
516 $mobs = [];
517 $int_links = [];
518 $this->offline_files = [];
519
520 // get html export id mapping
521
522 $exp_id_map = array();
523
524 if ($lm_set->get("html_export_ids")) {
525 foreach ($pages as $page) {
526 $exp_id = \ilLMPageObject::getExportId($this->lm->getId(), $page["obj_id"]);
527 if (trim($exp_id) != "") {
528 $exp_id_map[$page["obj_id"]] = trim($exp_id);
529 }
530 }
531 }
532
533 if ($lang == "") {
534 $lang = "-";
535 }
536
537 reset($pages);
538 foreach ($pages as $page) {
539 if (\ilLMPage::_exists($this->lm->getType(), $page["obj_id"])) {
540 $ilLocator->clearItems();
541 $this->exportPageHTML($page["obj_id"], ($first_page_id == $page["obj_id"]), $lang, "", $exp_id_map);
542 $this->co_page_html_export->collectPageElements("lm:pg", $page["obj_id"], $lang);
543 }
544 }
545 }
546
547
553 {
554 global $DIC;
555
556 $tabs = $DIC->tabs();
557
558 $tabs->clearTargets();
559 $tabs->clearSubTabs();
560 $tpl = new \ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
561
562 $this->co_page_html_export->getPreparedMainTemplate($tpl);
563
564 return $tpl;
565 }
566
567
573 protected function initScreen(int $lm_page_id, string $frame)
574 {
575 $this->global_screen->layout()->meta()->reset();
576
577 // load style sheet depending on user's settings
578 $location_stylesheet = \ilUtil::getStyleSheetLocation();
579 $this->global_screen->layout()->meta()->addCss($location_stylesheet);
580
582
583 // template workaround: reset of template
584 $tpl = $this->getInitialisedTemplate();
586
587 $params = [
588 "obj_id" => $lm_page_id,
589 "ref_id" => $this->lm->getRefId(),
590 "frame" => $frame
591 ];
592
593 $this->lm_gui->initByRequest($params);
594
597
598 $this->lm_gui->injectTemplate($tpl);
599 }
600
601
605 public function exportPageHTML(
606 $lm_page_id,
607 $is_first = false,
608 $lang = "-",
609 $frame = "",
610 $exp_id_map = []
611 ) {
612 global $DIC;
613
614 $target_dir = $this->target_dir;
615
616 $lang_suffix = "";
617 if (!in_array($lang, ["-", ""]) && $this->lang == "all") {
618 $lang_suffix = "_" . $lang;
619 }
620
621 // Init template, lm_gui
622 $this->initScreen($lm_page_id, $frame);
623
624
625 if ($frame == "") {
626 if (is_array($exp_id_map) && isset($a_exp_id_map[$lm_page_id])) {
627 $file = $target_dir . "/lm_pg_" . $exp_id_map[$lm_page_id] . $lang_suffix . ".html";
628 } else {
629 $file = $target_dir . "/lm_pg_" . $lm_page_id . $lang_suffix . ".html";
630 }
631 } else {
632 if ($frame != "toc") {
633 $file = $target_dir . "/frame_" . $lm_page_id . "_" . $frame . $lang_suffix . ".html";
634 } else {
635 $file = $target_dir . "/frame_" . $frame . $lang_suffix . ".html";
636 }
637 }
638
639 // return if file is already existing
640 if (@is_file($file)) {
641 return;
642 }
643
644 $content = $this->lm_gui->layout("main.xml", false);
645
646 // write xml data into the file
647 $fp = @fopen($file, "w+");
648 fwrite($fp, $content);
649
650 // close file
651 fclose($fp);
652
653 if ($is_first && $frame == "") {
654 copy($file, $target_dir . "/index" . $lang_suffix . ".html");
655 }
656 }
657}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
addSupplyingExportFiles()
Add supplying export files.
exportHTMLPages()
export all pages of learning module to html file
initLanguage(\ilObjUser $user, \ilLMPresentationGUI $lm_gui, string $lang)
Init language.
setAdditionalContextData($key, $data)
Set additional context data.
__construct(\ilObjLearningModule $lm, $export_dir, $sub_dir, $export_format="html", $lang="")
Constructor.
initDirectories()
Initialize directories.
exportHTML($zip=true)
export html package
exportPageHTML( $lm_page_id, $is_first=false, $lang="-", $frame="", $exp_id_map=[])
export page html
initScreen(int $lm_page_id, string $frame)
Init page.
getInitialisedTemplate()
Get initialised template.
getSupplyingExportFiles($a_target_dir=".")
Get supplying export files.
static getLocalJsTreeCssPath()
Get local path of jsTree js.
static getLocalExplorerJsPath()
Get local path of explorer js.
static getLocalJsTreeJsPath()
Get local path of jsTree js.
Class ilGlobalPageTemplate.
static getExportId($a_lm_id, $a_lmobj_id, $a_type="pg")
Get export ID.
static getPageList($lm_id)
static
Class ilLMPresentationGUI.
static getLocalJsPaths()
Get paths of necessary js files.
static getLogger($a_component_id)
Get component logger.
Class ilObjLearningModule.
static getEffectiveContentStyleId($a_style_id, $a_type="")
Get effective Style Id.
Class handles translation mode for an object.
static getInstance($a_obj_id)
Get instance.
getRefId()
get reference id @access public
getId()
get object id @access public
static resetInitialState()
Reset initial state (for exports)
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static getLocalPath($a_name="")
Get local path of a YUI js file.
$lm_set
$data
Definition: storeScorm.php:23
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$mobs
if(strpos( $jquery_path, './')===0) elseif(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:32
$DIC
Definition: xapitoken.php:46