78 private readonly
ilObject $content_object,
80 private readonly
string $importdir
83 $lng = $DIC->language();
84 $tree = $DIC->repositoryTree();
90 $this->current_element = [];
91 $this->structure_objects = [];
92 $this->st_into_tree = [];
93 $this->pg_into_tree = [];
94 $this->pages_to_parse = [];
95 $this->mobs_with_int_links = [];
96 $this->mob_mapping = [];
97 $this->file_item_mapping = [];
98 $this->pg_mapping = [];
99 $this->link_targets = [];
102 $this->inside_code =
false;
103 $this->qst_mapping = [];
104 $this->content_type = $this->content_object->getType();
106 if ($this->content_type !==
'tst' && $this->content_type !==
'qpl') {
107 $this->lm_tree =
new ilLMTree($this->content_object->getId());
116 xml_set_element_handler($xml_parser, $this->handlerBeginTag(...), $this->
handlerEndTag(...));
127 $this->log->debug(
'start');
129 parent::startParsing();
142 foreach ($this->st_into_tree as $st) {
143 $this->lm_tree->insertNode($st[
'id'], $st[
'parent']);
144 if (is_array($this->pg_into_tree[$st[
'id']])) {
145 foreach ($this->pg_into_tree[$st[
'id']] as $pg) {
147 switch ($pg[
'type']) {
149 if ($this->pg_mapping[$pg[
'id']] ==
'') {
150 $ilLog->
write(
'LM Import: No PageObject for PageAlias ' .
151 $pg[
'id'] .
' found! (Please update export installation to ILIAS 3.3.0)');
156 $pg_id = $this->pg_mapping[$pg[
'id']];
163 if (!$this->lm_tree->isInTree($pg_id)) {
164 $this->lm_tree->insertNode($pg_id, $st[
'id']);
177 foreach ($this->pages_to_parse as $page_id) {
178 $page_arr = explode(
':', $page_id);
180 switch ($page_arr[0]) {
182 switch ($this->content_object->getType()) {
184 $page_obj =
new ilLMPage($page_arr[1]);
188 die(
'Unknown content type ' . $this->content_object->getType());
201 $page_obj->buildDom();
202 $page_obj->resolveIntLinks();
203 $page_obj->resolveIIMMediaAliases($this->mob_mapping);
204 if ($this->content_type ==
'lm') {
205 $page_obj->resolveQuestionReferences($this->qst_mapping);
207 $page_obj->update(
false);
209 if ($page_arr[0] ==
'term') {
211 $term->updateShortText();
217 foreach ($this->mobs_with_int_links as $mob_id) {
222 foreach ($this->link_targets as $link_target) {
224 if (!isset($parsed)) {
229 $parsed[
'target_type'],
230 $parsed[
'target_id'],
231 $parsed[
'target_inst']
233 foreach ($sources as $key => $source) {
234 if (in_array($key, $done)) {
237 $type_arr = explode(
':', $source[
'type']);
240 if ($type_arr[1] ==
'pg') {
251 if ($type_arr[0] ===
'qst') {
264 foreach ($this->file_item_mapping as $origin_id => $file_id) {
265 if (empty($origin_id)) {
268 $obj_dir = $origin_id;
269 $source_dir = $this->importdir . DIRECTORY_SEPARATOR .
'objects' . DIRECTORY_SEPARATOR . $obj_dir;
271 $file_obj =
new ilObjFile($file_id,
false);
272 if (is_dir($source_dir)) {
273 $files = scandir($source_dir, SCANDIR_SORT_DESCENDING);
274 if ($files !==
false && $files !== [] && is_file($source_dir .
'/' . $files[0])) {
275 $file = fopen($source_dir .
'/' . $files[0],
'rb');
276 $file_stream = Streams::ofResource($file);
277 $file_obj->appendStream($file_stream, $files[0]);
290 $this->qst_mapping = $a_map;
295 if (!isset($this->status[
'$a_name'])) {
296 $this->cnt[$a_name] = 1;
298 $this->cnt[$a_name]++;
300 $this->current_element[count($this->current_element)] = $a_name;
305 $this->cnt[$a_name]--;
306 unset($this->current_element[count($this->current_element) - 1]);
311 return ($this->current_element[count($this->current_element) - 1] ??
'');
316 if (isset($this->cnt[$a_name])) {
317 return $this->cnt[$a_name];
329 if ($type ==
'end') {
335 if (is_array($attr)) {
336 foreach ($attr as $k => $v) {
337 $tag .=
' ' . $k .
"='$v'";
346 public function handlerBeginTag($a_xml_parser,
string $a_name, array $a_attribs):
void 349 case 'ContentObject':
350 $this->current_object = $this->content_object;
351 if ($a_attribs[
'Type'] ==
'Glossary') {
352 $this->glossary_object = $this->content_object;
356 case 'StructureObject':
358 $lm = $this->content_object;
359 $this->structure_objects[count($this->structure_objects)]
361 $this->current_object = $this->structure_objects[count($this->structure_objects) - 1];
362 $this->current_object->setLMId($this->content_object->getId());
366 $this->current_object->create(
true);
370 $this->in_page_object =
true;
372 if ($this->content_type !==
'tst' && $this->content_type !==
'qpl') {
374 $lm = $this->content_object;
376 $this->page_object =
new ilLMPage();
377 $this->lm_page_object->setLMId($this->content_object->getId());
378 $this->lm_page_object->assignPageObject($this->page_object);
389 case 'InteractiveImage':
390 if ($a_name ==
'MediaObject') {
391 $this->in_media_object =
true;
394 $this->media_object->create(
false,
false);
398 $this->media_object->setAlias(
true);
399 $this->media_object->setImportId($a_attribs[
'OriginId']);
400 $this->mob_mapping[$this->media_object->getImportId()] = $this->media_object->getId();
401 if (is_object($this->page_object)) {
402 $this->page_object->needsImportParsing(
true);
407 case 'MediaAliasItem':
408 $this->in_media_item =
true;
410 $this->media_item->setPurpose($a_attribs[
'Purpose']);
414 if (is_object($this->media_object) && $this->in_media_object) {
415 $this->media_item->setWidth($a_attribs[
'Width'] ??
'');
416 $this->media_item->setHeight($a_attribs[
'Height'] ??
'');
417 $this->media_item->setHAlign($a_attribs[
'HorizontalAlign'] ??
'');
422 if (is_object($this->media_object) && $this->in_media_object) {
423 $this->media_item->setParameter($a_attribs[
'Name'], $a_attribs[
'Value']);
428 $this->in_map_area =
true;
430 $this->map_area->setShape($a_attribs[
'Shape']);
431 $this->map_area->setCoords($a_attribs[
'Coords']);
432 $this->map_area->setHighlightMode($a_attribs[
'HighlightMode']);
433 $this->map_area->setHighlightClass($a_attribs[
'HighlightClass']);
437 $this->in_glossary =
true;
438 if ($this->content_object->getType() !=
'glo') {
440 $this->glossary_object->setTitle(
'');
441 $this->glossary_object->setDescription(
'');
442 $this->glossary_object->create(
true);
443 $this->glossary_object->createReference();
444 $parent = $this->tree->getParentNodeData($this->content_object->getRefId());
445 $this->glossary_object->putInTree($parent[
'child']);
446 $this->glossary_object->setPermissions($parent[
'child']);
453 $this->glossary_term->setGlossaryId($this->glossary_object->getId());
454 $this->glossary_term->setLanguage($a_attribs[
'Language']);
455 $this->glossary_term->setImportId($a_attribs[
'Id']);
457 if (isset($parsed)) {
458 $this->link_targets[$a_attribs[
"Id"]] = $a_attribs[
'Id'];
463 $this->in_glossary_definition =
true;
465 $this->page_object->setParentId($this->glossary_term->getGlossaryId());
466 $this->glossary_term->assignPageObject($this->page_object);
470 $this->page_object->setXMLContent(
'');
474 $this->in_file_item =
true;
476 $this->file_item->setTitle(
'dummy');
477 $this->file_item->setMode(
'filelist');
478 if (is_object($this->page_object)) {
479 $this->page_object->needsImportParsing(
true);
484 if ($a_attribs[
'Characteristic'] ==
'Code') {
485 $this->inside_code =
true;
490 $this->in_properties =
true;
494 if ($this->content_object->getType() ==
'lm') {
495 switch ($a_attribs[
'Name']) {
497 $this->content_object->setLayout($a_attribs[
'Value']);
501 $this->content_object->setPageHeader($a_attribs[
'Value']);
505 $this->content_object->setTOCMode($a_attribs[
'Value']);
509 $this->content_object->setActiveLMMenu(
514 case 'ActiveNumbering':
515 $this->content_object->setActiveNumbering(
521 $this->content_object->setActiveTOC(
526 case 'ActivePrintView':
527 $this->content_object->setActivePrintView(
533 $this->content_object->setCleanFrames(
539 $this->content_object->setPublicNotes(
544 case 'HistoryUserComments':
545 $this->content_object->setHistoryUserComments(
551 $this->content_object->setRating(
557 $this->content_object->setRatingPages(
563 if ($a_attribs[
'Value'] !=
'') {
564 if ($this->pg_mapping[$a_attribs[
'Value']] > 0) {
565 $this->content_object->setHeaderPage(
566 $this->pg_mapping[$a_attribs[
'Value']]
573 if ($a_attribs[
'Value'] !=
'') {
574 if ($this->pg_mapping[$a_attribs[
'Value']] > 0) {
575 $this->content_object->setFooterPage(
576 $this->pg_mapping[$a_attribs[
'Value']]
582 case 'LayoutPerPage':
583 $this->content_object->setLayoutPerPage($a_attribs[
'Value']);
586 case 'ProgressIcons':
587 $this->content_object->setProgressIcons($a_attribs[
'Value']);
591 $this->content_object->setStoreTries($a_attribs[
'Value']);
594 case 'RestrictForwardNavigation':
595 $this->content_object->setRestrictForwardNavigation($a_attribs[
'Value']);
598 case 'DisableDefaultFeedback':
599 $this->content_object->setDisableDefaultFeedback($a_attribs[
'Value']);
607 if ($this->in_file_item) {
608 if (!isset($this->file_item_mapping[$a_attribs[
'Entry']])
609 || $this->file_item_mapping[$a_attribs[
'Entry']] ===
'') {
610 $this->file_item->create();
611 $this->file_item->setImportId($a_attribs[
'Entry']);
612 $this->file_item_mapping[$a_attribs[
'Entry']] = $this->file_item->getId();
615 if ($this->in_media_object) {
616 $mob_id = $this->mob_mapping[$a_attribs[
'Entry']];
625 $this->media_object->create(
false,
false);
626 $this->mob_mapping[$a_attribs[
'Entry']]
627 = $this->media_object->getId();
629 $this->media_object->setImportId($a_attribs[
'Entry']);
635 if (is_object($this->page_object)) {
636 $this->page_object->setContainsIntLink(
true);
638 if ($this->in_map_area) {
640 $this->map_area->setTarget($a_attribs[
'Target']);
641 $this->map_area->setType($a_attribs[
'Type']);
642 $this->map_area->setTargetFrame($a_attribs[
'TargetFrame']);
643 if (is_object($this->media_object)) {
644 $this->media_object->setContainsIntLink(
true);
651 if ($this->in_map_area) {
653 $this->map_area->setHref($a_attribs[
'Href']);
654 $this->map_area->setExtTitle($a_attribs[
'Title']);
660 $this->cur_qid = $a_attribs[
'QRef'];
661 $this->page_object->setContainsQuestion(
true);
665 $this->loc_type = $a_attribs[
'Type'];
671 if (($this->in_page_object || $this->in_glossary_definition)
672 && !$this->in_media_object) {
673 if ($a_name ==
'Definition') {
674 $app_name =
'PageObject';
678 $app_attribs = $a_attribs;
682 if ($this->in_file_item && $app_name ==
'Identifier') {
683 $app_attribs[
'Entry'] =
'il__file_' . $this->file_item_mapping[$a_attribs[
'Entry']];
686 $this->page_object->appendXMLContent($this->
buildTag(
'start', $app_name, $app_attribs));
694 if ($this->content_object->getType() ==
'glo' &&
695 $this->in_glossary && !$this->in_media_object
707 if (($this->in_page_object || $this->in_glossary_definition)
708 && !$this->in_media_object) {
709 $app_name = ($a_name ==
'Definition')
712 $this->page_object->appendXMLContent($this->
buildTag(
'end', $app_name));
716 case 'StructureObject':
717 unset($this->structure_objects[count($this->structure_objects) - 1]);
721 $this->in_page_object =
false;
722 if ($this->content_type !=
'tst' && $this->content_type !=
'qpl') {
724 $this->page_object->updateFromXML();
725 $this->pg_mapping[$this->lm_page_object->getImportId()]
726 = $this->lm_page_object->getId();
730 if ($import_id_parsed[
'type'] ==
'pg') {
731 $this->mapping->addMapping(
732 'components/ILIAS/LearningModule',
734 $import_id_parsed[
'id'],
735 $this->lm_page_object->getId()
741 if ($this->page_object->containsIntLink()) {
742 $this->pages_to_parse[
'lm:' . $this->page_object->getId()] =
'lm:' . $this->page_object->getId();
746 if ($this->page_object->needsImportParsing()) {
747 $this->pages_to_parse[
'lm:' . $this->page_object->getId()] =
'lm:' . $this->page_object->getId();
751 if ($this->page_object->getContainsQuestion()) {
752 $this->pages_to_parse[
'lm:' . $this->page_object->getId()] =
'lm:' . $this->page_object->getId();
756 $xml = $this->page_object->getXMLContent();
757 if ($this->cur_qid !=
'') {
758 $ids = $this->qst_mapping[
$this->cur_qid] ?? [
'pool' => 0,
'test' => 0];
759 if ($ids[
'pool'] > 0) {
762 $xmlcontent = str_replace(
764 'il__qst_' . $ids[
'pool'],
767 $page->setXMLContent($xmlcontent);
768 $page->updateFromXML();
769 if ($this->page_object->needsImportParsing()) {
770 $this->pages_to_parse[
'qpl:' . $page->getId()] =
'qpl:' . $page->getId();
774 if ($ids[
'test'] > 0) {
777 $xmlcontent = str_replace(
779 'il__qst_' . $ids[
'test'],
782 $page->setXMLContent($xmlcontent);
783 $page->updateFromXML();
784 if ($this->page_object->needsImportParsing()) {
785 $this->pages_to_parse[
'qpl:' . $page->getId()] =
'qpl:' . $page->getId();
793 $cnt = count($this->structure_objects);
795 $parent_id = $this->structure_objects[$cnt - 1]->getId();
796 $this->pg_into_tree[$parent_id][] = [
'type' =>
'pg',
'id' => $this->lm_page_object->getId()];
799 unset($this->page_object);
800 unset($this->lm_page_object);
801 unset($this->container[count($this->container) - 1]);
805 case 'InteractiveImage':
806 if ($a_name ==
'MediaObject') {
807 $this->in_media_object =
false;
810 if (empty($this->mob_mapping[$this->media_object->getImportId()])) {
814 $this->media_object->create(
false,
false);
817 if ($this->media_object->containsIntLink()) {
818 $this->mobs_with_int_links[] = $this->media_object->getId();
821 $this->mob_mapping[$this->media_object->getImportId()]
822 = $this->media_object->getId();
825 $this->media_object->setId($this->mob_mapping[$this->media_object->getImportId()]);
832 if (!$this->media_object->isAlias()) {
834 $this->media_object->update();
837 if ($this->media_object->containsIntLink()) {
838 $this->mobs_with_int_links[] = $this->media_object->getId();
844 if ($this->in_page_object || $this->in_glossary_definition) {
845 if ($a_name !=
'InteractiveImage') {
846 $this->page_object->appendXMLContent($this->media_object->getXML(
IL_MODE_ALIAS));
852 case 'MediaAliasItem':
853 $this->in_media_item =
false;
854 $this->media_object->addMediaItem($this->media_item);
857 $this->in_media_item =
false;
858 $import_dir = $this->importdir . DIRECTORY_SEPARATOR .
'objects' . DIRECTORY_SEPARATOR . $this->media_object->getImportId();
859 if (!file_exists($import_dir)
860 || !is_dir($import_dir)) {
861 $this->media_object->addMediaItem($this->media_item);
865 $dir_handle = opendir($import_dir);
866 while (($file = readdir($dir_handle)) !==
false) {
867 if ($file !== $this->media_item->getLocation()) {
871 $this->media_object->addMediaItemFromLocalFile(
872 $this->media_item->getPurpose(),
873 $import_dir . DIRECTORY_SEPARATOR . $file,
878 closedir($dir_handle);
882 $this->in_map_area =
false;
883 $this->media_item->addMapArea($this->map_area);
887 $this->in_properties =
false;
888 if ($this->content_object->getType() ==
'lm') {
889 $this->content_object->update();
894 $this->in_file_item =
false;
896 if ($this->file_item->getImportId()) {
897 $this->file_item->update();
903 unset($this->container[count($this->container) - 1]);
907 $this->in_glossary =
false;
911 $term = trim($this->chr_data);
912 $term = str_replace(
'<',
'<', $term);
913 $term = str_replace(
'>',
'>', $term);
914 $this->glossary_term->setTerm($term);
915 $this->glossary_term->create();
916 $iia = explode(
'_', $this->glossary_term->getImportId());
917 $this->glossary_term_map[(
int) $iia[count($iia) - 1]] = $this->glossary_term->getId();
921 $this->inside_code =
false;
925 $this->in_glossary_definition =
false;
926 $this->page_object->updateFromXML();
927 $this->page_object->buildDom();
928 $this->glossary_term->setShortText($this->page_object->getFirstParagraphText());
929 $this->glossary_term->update();
930 if ($this->page_object->containsIntLink()) {
931 $this->pages_to_parse[
'term:' . $this->page_object->getId()] =
'term:' . $this->page_object->getId();
933 if ($this->page_object->needsImportParsing()) {
934 $this->pages_to_parse[
'term:' . $this->page_object->getId()] =
'term:' . $this->page_object->getId();
939 if ($this->in_media_item) {
940 $this->media_item->setFormat(trim($this->chr_data));
945 if ($this->in_media_object) {
946 $this->media_object->setTitle(trim($this->chr_data));
955 if ($this->in_media_object) {
956 $this->media_item->setCaption(trim($this->chr_data));
960 case 'TextRepresentation':
961 if ($this->in_media_object) {
962 $this->media_item->setTextRepresentation(trim($this->chr_data));
969 if ($this->in_media_item) {
970 $this->media_item->setLocationType($this->loc_type);
971 if ($this->loc_type ==
'Reference') {
972 $this->media_item->setLocation(str_replace(
'&',
'&', trim($this->chr_data)));
974 $this->media_item->setLocation(trim($this->chr_data));
977 if ($this->in_file_item) {
979 $this->file_item->setFileName(trim($this->chr_data));
983 if ($this->file_item->getType() ==
'file' &&
984 is_int(strpos($this->chr_data,
'&')) &&
985 is_int(strpos($this->chr_data,
';'))) {
986 $source_dir = $this->importdir . DIRECTORY_SEPARATOR .
'objects' . DIRECTORY_SEPARATOR .
987 $this->file_item->getImportId();
990 if ($dir = opendir($source_dir)) {
991 while (
false !== ($file = readdir($dir))) {
992 if ($file !=
'.' && $file !=
'..') {
993 $this->file_item->setFileName($file);
1001 $this->file_item->setTitle(trim($this->chr_data));
1006 $this->chr_data =
'';
1015 $a_data = str_replace(
'<',
'<', $a_data);
1016 $a_data = str_replace(
'>',
'>', $a_data);
1020 $a_data = preg_replace(
'/\n/',
'', $a_data);
1021 if (!$this->inside_code) {
1022 $a_data = preg_replace(
'/\t+/',
'', $a_data);
1025 $this->chr_data .= $a_data;
1027 if (!empty($a_data) || $a_data ===
'0') {
1030 if (($this->in_page_object || $this->in_glossary_definition)
1031 && !$this->in_media_object) {
1032 $this->page_object->appendXMLContent($a_data);
1038 if ($this->in_map_area) {
1039 $this->map_area->appendTitle($a_data);
1061 $link_arr = explode(
'_', $identifier);
1063 if (count($link_arr) !== 4
1064 || $link_arr[0] !==
'il' 1065 || !is_numeric($link_arr[1])
1066 || !is_numeric($link_arr[3])
1072 'target_inst' => (
int) $link_arr[1],
1073 'target_type' => (
string) $link_arr[2],
1074 'target_id' => (
int) $link_arr[3]
processPagesToParse()
parse pages that contain files, mobs and/or internal links
getOpenCount(string $a_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildDom(bool $a_force=false)
static getLogger(string $a_component_id)
Get component logger.
static _getSourcesOfTarget(string $a_target_type, int $a_target_id, int $a_target_inst)
get all sources of a link target
buildTag(string $type, string $name, array $attr=[])
handlerEndTag($a_xml_parser, string $a_name)
write(string $message, $level=ilLogLevel::INFO, array $context=[])
write log message
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
update(bool $a_validate=true, bool $a_no_history=false)
update complete page content in db (dom xml content is used)
ilGlossaryTerm $glossary_term
endElement(string $a_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilPageObject $page_object
bool $in_glossary_definition
parseLinkTarget(string $identifier)
Parse a string the get the elements of a link target Return null if the string is not a link target...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static instantiateQuestion(int $question_id)
setQuestionMapping(array $a_map)
set question import ident to pool/test question id mapping
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
handlerCharacterData($a_xml_parser, string $a_data)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
Legacy Content Object Parser.
resolveIntLinks(?array $a_link_map=null)
Resolves all internal link targets of the page, if targets are available (after import) ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static parseImportId(string $a_import_id)
Parse an ilias import id Typically of type il_[IL_INST_ID]_[OBJ_TYPE]_[OBJ_ID] returns array( 'orig' ...
ilObjLearningModule $learning_module
copyFileItems()
copy files of file items
array $mobs_with_int_links
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
ilLMPageObject $lm_page_object
static yn2tf(string $a_yn)
setImportMapping(?ilImportMapping $mapping=null)
ilObjGlossary $glossary_object
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(private readonly ilObject $content_object, string $xml_file, private readonly string $importdir)
static getInstance(string $a_parent_type, int $a_id=0, int $a_old_nr=0, string $a_lang="-")
Get page object instance.
beginElement(string $a_name)
ilObjMediaObject $media_object
storeTree()
insert StructureObjects and PageObjects into tree