ILIAS  release_7 Revision v7.30-3-g800a261c036
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["source"] != "") {
388 if ($f["type"] == "js") {
389 $this->global_screen->layout()->meta()->addJs($f["source"]);
390 }
391 if ($f["type"] == "css") {
392 $this->global_screen->layout()->meta()->addCss($f["source"]);
393 }
394 }
395 }
396 }
397
398
405 protected function getSupplyingExportFiles($a_target_dir = ".")
406 {
407 $scripts = array(
408 array("source" => \ilYuiUtil::getLocalPath('yahoo/yahoo-min.js'),
409 "target" => $a_target_dir . '/js/yahoo/yahoo-min.js',
410 "type" => "js"),
411 array("source" => \ilYuiUtil::getLocalPath('yahoo-dom-event/yahoo-dom-event.js'),
412 "target" => $a_target_dir . '/js/yahoo/yahoo-dom-event.js',
413 "type" => "js"),
414 array("source" => \ilYuiUtil::getLocalPath('animation/animation-min.js'),
415 "target" => $a_target_dir . '/js/yahoo/animation-min.js',
416 "type" => "js"),
417 array("source" => './Services/Accordion/js/accordion.js',
418 "target" => $a_target_dir . '/js/accordion.js',
419 "type" => "js"),
420 array("source" => './Services/Accordion/css/accordion.css',
421 "target" => $a_target_dir . '/css/accordion.css',
422 "type" => "css"),
423 array("source" => './Modules/Scorm2004/scripts/questions/pure.js',
424 "target" => $a_target_dir . '/js/pure.js',
425 "type" => "js"),
426 array("source" => './Modules/Scorm2004/scripts/questions/question_handling.js',
427 "target" => $a_target_dir . '/js/question_handling.js',
428 "type" => "js"),
429 array("source" => './Modules/Scorm2004/templates/default/question_handling.css',
430 "target" => $a_target_dir . '/css/question_handling.css',
431 "type" => "css"),
432 array("source" => './Modules/TestQuestionPool/templates/default/test_javascript.css',
433 "target" => $a_target_dir . '/css/test_javascript.css',
434 "type" => "css"),
436 "target" => $a_target_dir . "/" . \ilExplorerBaseGUI::getLocalExplorerJsPath(),
437 "type" => "js"),
438 array("source" => \ilExplorerBaseGUI::getLocalJsTreeJsPath(),
439 "target" => $a_target_dir . "/" . \ilExplorerBaseGUI::getLocalJsTreeJsPath(),
440 "type" => "js"),
441 array("source" => \ilExplorerBaseGUI::getLocalJsTreeCssPath(),
442 "target" => $a_target_dir . "/" . \ilExplorerBaseGUI::getLocalJsTreeCssPath(),
443 "type" => "css"),
444 array("source" => './Modules/LearningModule/js/LearningModule.js',
445 "target" => $a_target_dir . '/js/LearningModule.js',
446 "type" => "js")
447 );
448
449 $mathJaxSetting = new \ilSetting("MathJax");
450 $use_mathjax = $mathJaxSetting->get("enable");
451 if ($use_mathjax) {
452 $scripts[] = array("source" => "",
453 "target" => $mathJaxSetting->get("path_to_mathjax"),
454 "type" => "js");
455 }
456
457 // auto linking js
458 foreach (\ilLinkifyUtil::getLocalJsPaths() as $p) {
459 if (is_int(strpos($p, "ExtLink"))) {
460 $scripts[] = array("source" => $p,
461 "target" => $a_target_dir . '/js/ilExtLink.js',
462 "type" => "js");
463 }
464 if (is_int(strpos($p, "linkify"))) {
465 $scripts[] = array("source" => $p,
466 "target" => $a_target_dir . '/js/linkify.js',
467 "type" => "js");
468 }
469 }
470
471 // check, why these do not come with the gs meta collector
472 $scripts[] = [
473 "source" => "src/UI/templates/js/MainControls/dist/mainbar.js",
474 "type" => "js"
475 ];
476 $scripts[] = [
477 "source" => "src/UI/templates/js/MainControls/metabar.js",
478 "type" => "js"
479 ];
480 $scripts[] = [
481 "source" => "src/UI/templates/js/MainControls/slate.js",
482 "type" => "js"
483 ];
484 $scripts[] = [
485 "source" => "src/UI/templates/js/Page/stdpage.js",
486 "type" => "js"
487 ];
488 $scripts[] = [
489 "source" => "src/GlobalScreen/Client/dist/GS.js",
490 "type" => "js"
491 ];
492
493 return $scripts;
494 }
495
496
497
501 public function exportHTMLPages()
502 {
503 $lm = $this->lm;
505 $lang = $lm_gui->lang;
506 $all_languages = ($this->lang == "all");
508
509 $ilLocator = $this->locator;
510
511 $pages = \ilLMPageObject::getPageList($lm->getId());
512
513 $lm_tree = $lm->getLMTree();
514 $first_page = $lm_tree->fetchSuccessorNode($lm_tree->getRootId(), "pg");
515 $first_page_id = $first_page["child"];
516
517 // iterate all learning module pages
518 $mobs = [];
519 $int_links = [];
520 $this->offline_files = [];
521
522 // get html export id mapping
523
524 $exp_id_map = array();
525
526 if ($lm_set->get("html_export_ids")) {
527 foreach ($pages as $page) {
528 $exp_id = \ilLMPageObject::getExportId($this->lm->getId(), $page["obj_id"]);
529 if (trim($exp_id) != "") {
530 $exp_id_map[$page["obj_id"]] = trim($exp_id);
531 }
532 }
533 }
534
535 if ($lang == "") {
536 $lang = "-";
537 }
538
539 reset($pages);
540 foreach ($pages as $page) {
541 if (\ilLMPage::_exists($this->lm->getType(), $page["obj_id"])) {
542 $ilLocator->clearItems();
543 $this->exportPageHTML($page["obj_id"], ($first_page_id == $page["obj_id"]), $lang, "", $exp_id_map);
544 $this->co_page_html_export->collectPageElements("lm:pg", $page["obj_id"], $lang);
545 }
546 }
547 }
548
549
555 {
556 global $DIC;
557
558 $tabs = $DIC->tabs();
559
560 $tabs->clearTargets();
561 $tabs->clearSubTabs();
562 $tpl = new \ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
563
564 $this->co_page_html_export->getPreparedMainTemplate($tpl);
565
566 return $tpl;
567 }
568
569
575 protected function initScreen(int $lm_page_id, string $frame)
576 {
577 $this->global_screen->layout()->meta()->reset();
578
579 // load style sheet depending on user's settings
580 $location_stylesheet = \ilUtil::getStyleSheetLocation();
581 $this->global_screen->layout()->meta()->addCss($location_stylesheet);
582
584
585 // template workaround: reset of template
586 $tpl = $this->getInitialisedTemplate();
588
589 $params = [
590 "obj_id" => $lm_page_id,
591 "ref_id" => $this->lm->getRefId(),
592 "frame" => $frame
593 ];
594
595 $this->lm_gui->initByRequest($params);
596
599
600 $this->lm_gui->injectTemplate($tpl);
601 }
602
603
607 public function exportPageHTML(
608 $lm_page_id,
609 $is_first = false,
610 $lang = "-",
611 $frame = "",
612 $exp_id_map = []
613 ) {
614 global $DIC;
615
616 $target_dir = $this->target_dir;
617
618 $lang_suffix = "";
619 if (!in_array($lang, ["-", ""]) && $this->lang == "all") {
620 $lang_suffix = "_" . $lang;
621 }
622
623 // Init template, lm_gui
624 $this->initScreen($lm_page_id, $frame);
625
626
627 if ($frame == "") {
628 if (is_array($exp_id_map) && isset($a_exp_id_map[$lm_page_id])) {
629 $file = $target_dir . "/lm_pg_" . $exp_id_map[$lm_page_id] . $lang_suffix . ".html";
630 } else {
631 $file = $target_dir . "/lm_pg_" . $lm_page_id . $lang_suffix . ".html";
632 }
633 } else {
634 if ($frame != "toc") {
635 $file = $target_dir . "/frame_" . $lm_page_id . "_" . $frame . $lang_suffix . ".html";
636 } else {
637 $file = $target_dir . "/frame_" . $frame . $lang_suffix . ".html";
638 }
639 }
640
641 // return if file is already existing
642 if (@is_file($file)) {
643 return;
644 }
645
646 $content = $this->lm_gui->layout("main.xml", false);
647
648 // write xml data into the file
649 $fp = @fopen($file, "w+");
650 fwrite($fp, $content);
651
652 // close file
653 fclose($fp);
654
655 if ($is_first && $frame == "") {
656 copy($file, $target_dir . "/index" . $lang_suffix . ".html");
657 }
658 }
659}
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.
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
$mobs
Definition: imgupload.php:54
if(strpos( $jquery_path, './')===0) elseif(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:54
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$lm_set
$data
Definition: storeScorm.php:23