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("./Modules/LearningModule/classes/class.ilLMPageObject.php");
00025 require_once("./Services/COPage/classes/class.ilPageObject.php");
00026 require_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
00027 require_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
00028 require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
00029 require_once("./Services/COPage/classes/class.ilPCParagraph.php");
00030 require_once("./Services/COPage/classes/class.ilPCTable.php");
00031 require_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
00032 require_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
00033 require_once("./Services/MediaObjects/classes/class.ilMapArea.php");
00034 require_once("./Modules/LearningModule/classes/class.ilBibItem.php");
00035 require_once("./Modules/Glossary/classes/class.ilObjGlossary.php");
00036 require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
00037 require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
00038 require_once("./Services/COPage/classes/class.ilInternalLink.php");
00039 require_once("./Modules/File/classes/class.ilObjFile.php");
00040
00041 include_once("Services/MetaData/classes/class.ilMDSaxParser.php");
00042 include_once("Services/MetaData/classes/class.ilMD.php");
00043
00052 class ilContObjParser extends ilMDSaxParser
00053 {
00054 var $lng;
00055 var $tree;
00056 var $cnt;
00057 var $current_element;
00058 var $learning_module;
00059 var $page_object;
00060 var $lm_page_object;
00061 var $structure_objects;
00062 var $media_object;
00063 var $current_object;
00064 var $meta_data;
00065 var $paragraph;
00066 var $table;
00067 var $lm_tree;
00068 var $pg_into_tree;
00069 var $st_into_tree;
00070 var $container;
00071 var $in_page_object;
00072 var $in_meta_data;
00073 var $in_media_object;
00074 var $in_file_item;
00075 var $in_glossary;
00076 var $in_map_area;
00077 var $content_object;
00078 var $glossary_object;
00079 var $file_item;
00080 var $keyword_language;
00081 var $pages_to_parse;
00082 var $mob_mapping;
00083 var $file_item_mapping;
00084 var $subdir;
00085 var $media_item;
00086 var $loc_type;
00087 var $bib_item;
00088 var $map_area;
00089 var $in_bib_item;
00090 var $link_targets;
00091 var $qst_mapping;
00092 var $metadata_parsing_disabled;
00093 var $in_meta_meta_data = false;
00094
00104 function ilContObjParser(&$a_content_object, $a_xml_file, $a_subdir)
00105 {
00106 global $lng, $tree;
00107
00108 parent::ilMDSaxParser($a_xml_file);
00109 $this->cnt = array();
00110 $this->current_element = array();
00111 $this->structure_objects = array();
00112 $this->content_object =& $a_content_object;
00113
00114 $this->st_into_tree = array();
00115 $this->pg_into_tree = array();
00116 $this->pages_to_parse = array();
00117 $this->mobs_with_int_links = array();
00118 $this->mob_mapping = array();
00119 $this->file_item_mapping = array();
00120 $this->pg_mapping = array();
00121 $this->link_targets = array();
00122 $this->subdir = $a_subdir;
00123 $this->lng =& $lng;
00124 $this->tree =& $tree;
00125 $this->inside_code = false;
00126 $this->qst_mapping = array();
00127 $this->coType = $this->content_object->getType();
00128 $this->metadata_parsing_disabled = false;
00129
00130 if (($this->coType != "tst") and ($this->coType != "qpl"))
00131 {
00132 $this->lm_tree = new ilTree($this->content_object->getId());
00133 $this->lm_tree->setTreeTablePK("lm_id");
00134 $this->lm_tree->setTableNames('lm_tree','lm_data');
00135 }
00136
00137
00138 }
00139
00146 function setHandlers($a_xml_parser)
00147 {
00148 xml_set_object($a_xml_parser,$this);
00149 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
00150 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
00151 }
00152
00153
00157 function startParsing()
00158 {
00159
00160 parent::startParsing();
00161
00162 $this->storeTree();
00163
00164 $this->processPagesToParse();
00165
00166 $this->copyMobFiles();
00167
00168 $this->copyFileItems();
00169 }
00170
00171
00175 function storeTree()
00176 {
00177 global $ilLog;
00178
00179
00180 foreach($this->st_into_tree as $st)
00181 {
00182
00183 $this->lm_tree->insertNode($st["id"], $st["parent"]);
00184
00185 if (is_array($this->pg_into_tree[$st["id"]]))
00186 {
00187 foreach($this->pg_into_tree[$st["id"]] as $pg)
00188 {
00189 switch ($pg["type"])
00190 {
00191 case "pg_alias":
00192 if ($this->pg_mapping[$pg["id"]] == "")
00193 {
00194 $ilLog->write("LM Import: No PageObject for PageAlias ".
00195 $pg["id"]." found! (Please update export installation to ILIAS 3.3.0)");
00196
00197
00198 continue 2;
00199 }
00200 $pg_id = $this->pg_mapping[$pg["id"]];
00201 break;
00202
00203 case "pg":
00204 $pg_id = $pg["id"];
00205 break;
00206 }
00207 if (!$this->lm_tree->isInTree($pg_id))
00208 {
00209 $this->lm_tree->insertNode($pg_id, $st["id"]);
00210 }
00211 }
00212 }
00213 }
00214
00215 }
00216
00217
00221 function processPagesToParse()
00222 {
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 foreach($this->pages_to_parse as $page_id)
00233 {
00234 $page_arr = explode(":", $page_id);
00235
00236 switch($page_arr[0])
00237 {
00238 case "lm":
00239 $page_obj =& new ilPageObject($this->content_object->getType(), $page_arr[1]);
00240 break;
00241
00242 case "gdf":
00243 $page_obj =& new ilPageObject("gdf", $page_arr[1]);
00244 break;
00245 }
00246 $page_obj->buildDom();
00247 $page_obj->resolveIntLinks();
00248 $page_obj->update(false);
00249
00250 if ($page_arr[0] == "gdf")
00251 {
00252 $def =& new ilGlossaryDefinition($page_arr[1]);
00253 $def->updateShortText();
00254 }
00255
00256 unset($page_obj);
00257 }
00258
00259
00260
00261 foreach($this->mobs_with_int_links as $mob_id)
00262 {
00263 ilMediaItem::_resolveMapAreaLinks($mob_id);
00264 }
00265
00266
00267
00268 $done = array();
00269 foreach ($this->link_targets as $link_target)
00270 {
00271
00272 $link_arr = explode("_", $link_target);
00273 $target_inst = $link_arr[1];
00274 $target_type = $link_arr[2];
00275 $target_id = $link_arr[3];
00276 $sources = ilInternalLink::_getSourcesOfTarget($target_type, $target_id, $target_inst);
00277 foreach($sources as $key => $source)
00278 {
00279
00280 if(in_array($key, $done))
00281 {
00282 continue;
00283 }
00284 $type_arr = explode(":", $source["type"]);
00285
00286
00287 if ($type_arr[1] == "pg")
00288 {
00289 $page_object = new ilPageObject($type_arr[0], $source["id"]);
00290 $page_object->buildDom();
00291 $page_object->resolveIntLinks();
00292 $page_object->update();
00293 unset($page_object);
00294 }
00295
00296 if ($type_arr[0] == "qst")
00297 {
00298 require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00299 assQuestion::_resolveIntLinks($source["id"]);
00300 }
00301
00302 if ($type_arr[0] == "sqst")
00303 {
00304 require_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00305 assQuestion::_resolveIntLinks($source["id"]);
00306 }
00307 $done[$key] = $key;
00308 }
00309 }
00310 }
00311
00312
00316 function copyMobFiles()
00317 {
00318 $imp_dir = $this->content_object->getImportDirectory();
00319 foreach ($this->mob_mapping as $origin_id => $mob_id)
00320 {
00321 if(empty($origin_id))
00322 {
00323 continue;
00324 }
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 $obj_dir = $origin_id;
00338 $source_dir = $imp_dir."/".$this->subdir."/objects/".$obj_dir;
00339 $target_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$mob_id;
00340
00341
00342 if (@is_dir($source_dir))
00343 {
00344
00345 ilUtil::makeDir($target_dir);
00346
00347
00348
00349 if (@is_dir($target_dir))
00350 {
00351 ilUtil::rCopy($source_dir, $target_dir);
00352 }
00353 }
00354 }
00355 }
00356
00360 function copyFileItems()
00361 {
00362 $imp_dir = $this->content_object->getImportDirectory();
00363 foreach ($this->file_item_mapping as $origin_id => $file_id)
00364 {
00365 if(empty($origin_id))
00366 {
00367 continue;
00368 }
00369 $obj_dir = $origin_id;
00370 $source_dir = $imp_dir."/".$this->subdir."/objects/".$obj_dir;
00371
00372 include_once("./Modules/File/classes/class.ilObjFile.php");
00373 $file_obj = new ilObjFile($file_id, false);
00374
00375 $target_dir = $file_obj->getDirectory();
00376 if (@is_dir($source_dir))
00377 {
00378
00379 ilUtil::makeDir($target_dir);
00380
00381
00382
00383 if (@is_dir($target_dir))
00384 {
00385 ilUtil::rCopy($source_dir, $target_dir);
00386 }
00387 }
00388 $test = $file_obj->determineFilesize();
00389 $file_obj->update();
00390 }
00391 }
00392
00396 function setQuestionMapping($a_map)
00397 {
00398 $this->qst_mapping = $a_map;
00399 }
00400
00401
00402
00403
00404
00405 function beginElement($a_name)
00406 {
00407 if(!isset($this->status["$a_name"]))
00408 {
00409 $this->cnt[$a_name] == 1;
00410 }
00411 else
00412 {
00413 $this->cnt[$a_name]++;
00414 }
00415 $this->current_element[count($this->current_element)] = $a_name;
00416 }
00417
00418
00419
00420
00421
00422
00423 function endElement($a_name)
00424 {
00425 $this->cnt[$a_name]--;
00426 unset ($this->current_element[count($this->current_element) - 1]);
00427 }
00428
00429
00430
00431
00432 function getCurrentElement()
00433 {
00434 return ($this->current_element[count($this->current_element) - 1]);
00435 }
00436
00437
00438
00439
00440
00441
00442 function getOpenCount($a_name)
00443 {
00444 if (isset($this->cnt[$a_name]))
00445 {
00446 return $this->cnt[$a_name];
00447 }
00448 else
00449 {
00450 return 0;
00451 }
00452
00453 }
00454
00462 function buildTag ($type, $name, $attr="")
00463 {
00464 $tag = "<";
00465
00466 if ($type == "end")
00467 $tag.= "/";
00468
00469 $tag.= $name;
00470
00471 if (is_array($attr))
00472 {
00473 while (list($k,$v) = each($attr))
00474 $tag.= " ".$k."=\"$v\"";
00475 }
00476
00477 $tag.= ">";
00478
00479 return $tag;
00480 }
00481
00489 function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
00490 {
00491
00492 switch($a_name)
00493 {
00494 case "ContentObject":
00495 $this->current_object =& $this->content_object;
00496
00497 if ($a_attribs["Type"] == "Glossary")
00498 {
00499 $this->glossary_object =& $this->content_object;
00500 }
00501 break;
00502
00503 case "StructureObject":
00504
00505 $this->structure_objects[count($this->structure_objects)]
00506 =& new ilStructureObject($this->content_object);
00507 $this->current_object =& $this->structure_objects[count($this->structure_objects) - 1];
00508 $this->current_object->setLMId($this->content_object->getId());
00509
00510
00511
00512 $this->current_object->create(true);
00513 break;
00514
00515 case "PageObject":
00516 $this->in_page_object = true;
00517 $this->cur_qid = "";
00518 if (($this->coType != "tst") and ($this->coType != "qpl"))
00519 {
00520 $this->lm_page_object =& new ilLMPageObject($this->content_object);
00521 $this->page_object =& new ilPageObject($this->content_object->getType());
00522 $this->lm_page_object->setLMId($this->content_object->getId());
00523 $this->lm_page_object->assignPageObject($this->page_object);
00524 $this->current_object =& $this->lm_page_object;
00525 }
00526 else
00527 {
00528 $this->page_object =& new ilPageObject("qpl");
00529 }
00530 break;
00531
00532 case "PageAlias":
00533 if (($this->coType != "tst") and ($this->coType != "qpl"))
00534 {
00535 $this->lm_page_object->setAlias(true);
00536 $this->lm_page_object->setOriginID($a_attribs["OriginId"]);
00537 }
00538 break;
00539
00540 case "MediaObject":
00541 $this->in_media_object = true;
00542 $this->media_meta_start = true;
00543 $this->media_meta_cache = array();
00544 $this->media_object =& new ilObjMediaObject();
00545 break;
00546
00547 case "MediaAlias":
00548
00549 $this->media_object->setAlias(true);
00550 $this->media_object->setImportId($a_attribs["OriginId"]);
00551 if (is_object($this->page_object))
00552 {
00553 $this->page_object->needsImportParsing(true);
00554 }
00555 break;
00556
00557 case "MediaItem":
00558 case "MediaAliasItem":
00559 $this->in_media_item = true;
00560 $this->media_item =& new ilMediaItem();
00561 $this->media_item->setPurpose($a_attribs["Purpose"]);
00562 break;
00563
00564 case "Layout":
00565 if (is_object($this->media_object) && $this->in_media_object)
00566 {
00567 $this->media_item->setWidth($a_attribs["Width"]);
00568 $this->media_item->setHeight($a_attribs["Height"]);
00569 $this->media_item->setHAlign($a_attribs["HorizontalAlign"]);
00570 }
00571 break;
00572
00573 case "Parameter":
00574 if (is_object($this->media_object) && $this->in_media_object)
00575 {
00576 $this->media_item->setParameter($a_attribs["Name"], $a_attribs["Value"]);
00577 }
00578 break;
00579
00580 case "MapArea":
00581 $this->in_map_area = true;
00582 $this->map_area =& new ilMapArea();
00583 $this->map_area->setShape($a_attribs["Shape"]);
00584 $this->map_area->setCoords($a_attribs["Coords"]);
00585 break;
00586
00587 case "Glossary":
00588 $this->in_glossary = true;
00589 if ($this->content_object->getType() != "glo")
00590 {
00591 $this->glossary_object =& new ilObjGlossary();
00592 $this->glossary_object->setTitle("");
00593 $this->glossary_object->setDescription("");
00594 $this->glossary_object->create(true);
00595 $this->glossary_object->createReference();
00596 $parent =& $this->tree->getParentNodeData($this->content_object->getRefId());
00597 $this->glossary_object->putInTree($parent["child"]);
00598 $this->glossary_object->setPermissions($parent["child"]);
00599 $this->glossary_object->notify("new", $_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$this->glossary_object->getRefId());
00600 }
00601 $this->current_object =& $this->glossary_object;
00602 break;
00603
00604 case "GlossaryItem":
00605 $this->glossary_term =& new ilGlossaryTerm();
00606 $this->glossary_term->setGlossaryId($this->glossary_object->getId());
00607 $this->glossary_term->setLanguage($a_attribs["Language"]);
00608 $this->glossary_term->setImportId($a_attribs["Id"]);
00609 $this->link_targets[$a_attribs["Id"]] = $a_attribs["Id"];
00610 break;
00611
00612 case "Definition":
00613 $this->in_glossary_definition = true;
00614 $this->glossary_definition =& new ilGlossaryDefinition();
00615 $this->page_object =& new ilPageObject("gdf");
00616 $this->page_object->setParentId($this->glossary_term->getGlossaryId());
00617 $this->glossary_definition->setTermId($this->glossary_term->getId());
00618 $this->glossary_definition->assignPageObject($this->page_object);
00619 $this->current_object =& $this->glossary_definition;
00620 $this->glossary_definition->create(true);
00621 break;
00622
00623 case "FileItem":
00624 $this->in_file_item = true;
00625 $this->file_item =& new ilObjFile();
00626 $this->file_item->setTitle("dummy");
00627 $this->file_item->setMode("filelist");
00628 if (is_object($this->page_object))
00629 {
00630 $this->page_object->needsImportParsing(true);
00631 }
00632 break;
00633
00634 case "Paragraph":
00635 if ($a_attribs["Characteristic"] == "Code")
00636 {
00637 $this->inside_code = true;
00638 }
00639 break;
00640
00641 case "Properties":
00642 $this->in_properties = true;
00643 break;
00644
00645 case "Property":
00646 if ($this->content_object->getType() == "lm"
00647 || $this->content_object->getType() == "dbk")
00648 {
00649 switch($a_attribs["Name"])
00650 {
00651 case "Layout":
00652 $this->content_object->setLayout($a_attribs["Value"]);
00653 break;
00654
00655 case "PageHeader":
00656 $this->content_object->setPageHeader($a_attribs["Value"]);
00657 break;
00658
00659 case "TOCMode":
00660 $this->content_object->setTOCMode($a_attribs["Value"]);
00661 break;
00662
00663 case "ActiveLMMenu":
00664 $this->content_object->setActiveLMMenu(
00665 ilUtil::yn2tf($a_attribs["Value"]));
00666 break;
00667
00668 case "ActiveNumbering":
00669 $this->content_object->setActiveNumbering(
00670 ilUtil::yn2tf($a_attribs["Value"]));
00671 break;
00672
00673 case "ActiveTOC":
00674 $this->content_object->setActiveTOC(
00675 ilUtil::yn2tf($a_attribs["Value"]));
00676 break;
00677
00678 case "ActivePrintView":
00679 $this->content_object->setActivePrintView(
00680 ilUtil::yn2tf($a_attribs["Value"]));
00681 break;
00682
00683 case "CleanFrames":
00684 $this->content_object->setCleanFrames(
00685 ilUtil::yn2tf($a_attribs["Value"]));
00686 break;
00687
00688 case "PublicNotes":
00689 $this->content_object->setPublicNotes(
00690 ilUtil::yn2tf($a_attribs["Value"]));
00691 break;
00692
00693 case "HistoryUserComments":
00694 $this->content_object->setHistoryUserComments(
00695 ilUtil::yn2tf($a_attribs["Value"]));
00696 break;
00697
00698 case "HeaderPage":
00699 if ($a_attribs["Value"] != "")
00700 {
00701 if ($this->pg_mapping[$a_attribs["Value"]] > 0)
00702 {
00703 $this->content_object->setHeaderPage(
00704 $this->pg_mapping[$a_attribs["Value"]]);
00705 }
00706 }
00707 break;
00708
00709 case "FooterPage":
00710 if ($a_attribs["Value"] != "")
00711 {
00712 if ($this->pg_mapping[$a_attribs["Value"]] > 0)
00713 {
00714 $this->content_object->setFooterPage(
00715 $this->pg_mapping[$a_attribs["Value"]]);
00716 }
00717 }
00718 break;
00719 }
00720
00721 }
00722 break;
00723
00727 case "MetaData":
00728 $this->in_meta_data = true;
00729
00730
00731
00732
00733 if(!$this->in_media_object)
00734 {
00735 if (($this->coType != "tst") and ($this->coType != "qpl"))
00736 {
00737
00738 if ($this->current_object->getType() == "st" ||
00739 $this->current_object->getType() == "pg")
00740 {
00741
00742 if ($this->current_object->getType() == "pg")
00743 {
00744 $this->lm_page_object->create(true);
00745 }
00746 $this->md =& new ilMD($this->content_object->getId() ,
00747 $this->current_object->getId(),
00748 $this->current_object->getType());
00749 }
00750
00751 else if ($this->current_object->getType() == "gdf")
00752 {
00753 $this->md =& new ilMD($this->glossary_object->getId() ,
00754 $this->current_object->getId(),
00755 $this->current_object->getType());
00756 }
00757
00758 else
00759 {
00760 if ($this->processMeta())
00761 {
00762 $this->md =& new ilMD($this->current_object->getId() ,
00763 0,
00764 $this->current_object->getType());
00765 }
00766 }
00767 }
00768 else
00769 {
00770
00771 $this->md =& new ilMD($this->content_object->getId() ,
00772 0,
00773 $this->current_object->getType()
00774 );
00775 if ($this->md->getGeneral() != false)
00776 {
00777 $this->metadata_parsing_disabled = true;
00778 $this->enableMDParsing(false);
00779 }
00780 }
00781 }
00782 break;
00783
00784
00785 case "Identifier":
00786
00787
00788 if (!$this->in_meta_meta_data)
00789 {
00790 if ($this->in_meta_data && !$this->in_glossary_definition)
00791 {
00792 if (!$this->in_media_object)
00793 {
00794 $this->current_object->setImportId($a_attribs["Entry"]);
00795 }
00796 $this->link_targets[$a_attribs["Entry"]] = $a_attribs["Entry"];
00797 }
00798 if ($this->in_file_item)
00799 {
00800 if ($this->file_item_mapping[$a_attribs["Entry"]] == "")
00801 {
00802 $this->file_item->create();
00803 $this->file_item->setImportId($a_attribs["Entry"]);
00804 $this->file_item_mapping[$a_attribs["Entry"]] = $this->file_item->getId();
00805 }
00806 }
00807 if ($this->in_meta_data && $this->in_media_object)
00808 {
00809
00810
00811 $mob_id = $this->mob_mapping[$a_attribs["Entry"]];
00812
00813
00814
00815 if ($mob_id > 0)
00816 {
00817 $this->media_object = new ilObjMediaObject($mob_id);
00818 }
00819 else
00820
00821 {
00822 $this->media_object = new ilObjMediaObject();
00823 $this->media_object->create(true, false);
00824 $this->mob_mapping[$a_attribs["Entry"]]
00825 = $this->media_object->getId();
00826 }
00827 $this->media_object->setImportId($a_attribs["Entry"]);
00828 $this->md =& new ilMD(0 ,
00829 $this->media_object->getId(),
00830 "mob");
00831 $this->emptyMediaMetaCache($a_xml_parser);
00832 }
00833 }
00834 break;
00835
00836 case "Meta-Metadata":
00837 $this->in_meta_meta_data = true;
00838 break;
00839
00840
00841 case "IntLink":
00842 if (is_object($this->page_object))
00843 {
00844 $this->page_object->setContainsIntLink(true);
00845 }
00846 if ($this->in_map_area)
00847 {
00848
00849 $this->map_area->setLinkType(IL_INT_LINK);
00850 $this->map_area->setTarget($a_attribs["Target"]);
00851 $this->map_area->setType($a_attribs["Type"]);
00852 $this->map_area->setTargetFrame($a_attribs["TargetFrame"]);
00853 if (is_object($this->media_object))
00854 {
00855
00856 $this->media_object->setContainsIntLink(true);
00857 }
00858 }
00859 break;
00860
00861
00862 case "ExtLink":
00863 if ($this->in_map_area)
00864 {
00865 $this->map_area->setLinkType(IL_EXT_LINK);
00866 $this->map_area->setHref($a_attribs["Href"]);
00867 $this->map_area->setExtTitle($a_attribs["Title"]);
00868 }
00869 break;
00870
00871
00872 case "Question":
00873 $this->cur_qid = $a_attribs["QRef"];
00874 break;
00875
00876 case "Location":
00877 $this->loc_type = $a_attribs["Type"];
00878 break;
00879
00880 case "Bibliography":
00881 $this->in_bib_item = true;
00882
00883 $this->bib_item =& new ilBibItem();
00884 break;
00885
00886 }
00887 $this->beginElement($a_name);
00888
00889
00890 if(($this->in_page_object || $this->in_glossary_definition)
00891 && !$this->in_meta_data && !$this->in_media_object)
00892 {
00893 if ($a_name == "Definition")
00894 {
00895 $app_name = "PageObject";
00896 $app_attribs = array();
00897 }
00898 else
00899 {
00900 $app_name = $a_name;
00901 $app_attribs = $a_attribs;
00902 }
00903
00904
00905 if ($this->in_file_item && $app_name == "Identifier")
00906 {
00907 $app_attribs["Entry"] = "il__file_".$this->file_item_mapping[$a_attribs["Entry"]];
00908
00909 }
00910
00911 $this->page_object->appendXMLContent($this->buildTag("start", $app_name, $app_attribs));
00912
00913 }
00914
00915
00916 if ($this->in_bib_item)
00917 {
00918 $this->bib_item->appendXMLContent("\n".$this->buildTag("start", $a_name, $a_attribs));
00919 }
00920
00921
00922 if ($this->in_meta_data && $this->processMeta())
00923 {
00924
00925
00926
00927
00928 if ($this->in_media_object && $this->media_meta_start)
00929 {
00930 $this->media_meta_cache[] =
00931 array("type" => "handlerBeginTag", "par1" => $a_name, "par2" => $a_attribs);
00932 }
00933 else
00934 {
00935 if ($a_name == "Identifier")
00936 {
00937 if (!$this->in_media_object)
00938 {
00939 $a_attribs["Entry"] = "il__".$this->current_object->getType().
00940 "_".$this->current_object->getId();
00941 }
00942 else
00943 {
00944 $a_attribs["Entry"] = "il__mob".
00945 "_".$this->media_object->getId();
00946 }
00947 $a_attribs["Catalog"] = "ILIAS";
00948 }
00949
00950 parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
00951 }
00952 }
00953 }
00954
00958 function processMeta()
00959 {
00960
00961
00962 if ($this->content_object->getType() == "glo" &&
00963 $this->in_glossary && !$this->in_media_object
00964 && !$this->in_glossary_definition)
00965 {
00966 return false;
00967 }
00968
00969 return true;
00970 }
00971
00972
00979 function handlerEndTag($a_xml_parser,$a_name)
00980 {
00981
00982 if ($this->in_meta_data && $this->processMeta())
00983 {
00984
00985
00986
00987 if ($this->in_media_object && $this->media_meta_start)
00988 {
00989 $this->media_meta_cache[] =
00990 array("type" => "handlerEndTag", "par1" => $a_name);
00991 }
00992 else
00993 {
00994 parent::handlerEndTag($a_xml_parser,$a_name);
00995 }
00996 }
00997
00998
00999
01000 if (($this->in_page_object || $this->in_glossary_definition)
01001 && !$this->in_meta_data && !$this->in_media_object)
01002 {
01003 $app_name = ($a_name == "Definition")
01004 ? "PageObject"
01005 : $a_name;
01006 $this->page_object->appendXMLContent($this->buildTag("end", $app_name));
01007 }
01008
01009
01010 if ($this->in_bib_item)
01011 {
01012 if($a_name == "BibItem")
01013 {
01014 $this->bib_item->appendXMLContent("\n".$this->buildTag("end", $a_name));
01015 }
01016 else
01017 {
01018 $this->bib_item->appendXMLContent($this->buildTag("end", $a_name));
01019 }
01020
01021 }
01022
01023 switch($a_name)
01024 {
01025 case "StructureObject":
01026
01027 unset($this->structure_objects[count($this->structure_objects) - 1]);
01028 break;
01029
01030 case "PageObject":
01031
01032 $this->in_page_object = false;
01033 if (($this->coType != "tst") and ($this->coType != "qpl"))
01034 {
01035 if (!$this->lm_page_object->isAlias())
01036 {
01037
01038 $this->page_object->updateFromXML();
01039 $this->pg_mapping[$this->lm_page_object->getImportId()]
01040 = $this->lm_page_object->getId();
01041
01042
01043 if ($this->page_object->containsIntLink())
01044 {
01045 $this->pages_to_parse["lm:".$this->page_object->getId()] = "lm:".$this->page_object->getId();
01046 }
01047
01048
01049 if ($this->page_object->needsImportParsing())
01050 {
01051 $this->pages_to_parse["lm:".$this->page_object->getId()] = "lm:".$this->page_object->getId();
01052 }
01053
01054 }
01055 }
01056 else
01057 {
01058 $xml = $this->page_object->getXMLContent();
01059 if ($this->cur_qid != "")
01060 {
01061 $ids = $this->qst_mapping[$this->cur_qid];
01062 if ($ids["pool"] > 0)
01063 {
01064
01065 $page = new ilPageObject("qpl", $ids["pool"]);
01066 $xmlcontent = str_replace($this->cur_qid,
01067 "il__qst_".$ids["pool"], $xml);
01068 $page->setXMLContent($xmlcontent);
01069 $page->saveMobUsage($xmlcontent);
01070 $page->updateFromXML();
01071 unset($page);
01072 }
01073 if ($ids["test"] > 0)
01074 {
01075
01076 $page = new ilPageObject("qpl", $ids["test"]);
01077 $xmlcontent = str_replace($this->cur_qid,
01078 "il__qst_".$ids["test"], $xml);
01079 $page->setXMLContent($xmlcontent);
01080 $page->saveMobUsage($xmlcontent);
01081 $page->updateFromXML();
01082 unset($page);
01083 }
01084 }
01085 }
01086
01087
01088 $cnt = count($this->structure_objects);
01089 if ($cnt > 0)
01090 {
01091 $parent_id = $this->structure_objects[$cnt - 1]->getId();
01092 if ($this->lm_page_object->isAlias())
01093 {
01094 $this->pg_into_tree[$parent_id][] = array("type" => "pg_alias", "id" => $this->lm_page_object->getOriginId());
01095 }
01096 else
01097 {
01098 $this->pg_into_tree[$parent_id][] = array("type" => "pg", "id" => $this->lm_page_object->getId());
01099 }
01100 }
01101
01102 unset($this->page_object);
01103 unset($this->lm_page_object);
01104 unset ($this->container[count($this->container) - 1]);
01105 break;
01106
01107 case "MediaObject":
01108 $this->in_media_object = false;
01109
01110
01111
01112
01113 if(empty($this->mob_mapping[$this->media_object->getImportId()]))
01114 {
01115
01116
01117
01118
01119
01120 $this->media_object->create(true, false);
01121
01122
01123
01124
01125 if ($this->media_object->containsIntLink())
01126 {
01127
01128 $this->mobs_with_int_links[] = $this->media_object->getId();
01129 }
01130
01131 $this->mob_mapping[$this->media_object->getImportId()]
01132 = $this->media_object->getId();
01133
01134 }
01135 else
01136 {
01137
01138
01139 $this->media_object->setId($this->mob_mapping[$this->media_object->getImportId()]);
01140
01141
01142
01143
01144
01145
01146 if (!$this->media_object->isAlias())
01147 {
01148
01149 $this->media_object->update();
01150
01151
01152
01153
01154 if ($this->media_object->containsIntLink())
01155 {
01156
01157 $this->mobs_with_int_links[] = $this->media_object->getId();
01158 }
01159 }
01160 }
01161
01162
01163 if ($this->in_page_object || $this->in_glossary_definition)
01164 {
01165 $this->page_object->appendXMLContent($this->media_object->getXML(IL_MODE_ALIAS));
01166
01167 }
01168
01169 break;
01170
01171 case "MediaItem":
01172 case "MediaAliasItem":
01173 $this->in_media_item = false;
01174 $this->media_object->addMediaItem($this->media_item);
01175
01176 break;
01177
01178 case "MapArea":
01179 $this->in_map_area = false;
01180 $this->media_item->addMapArea($this->map_area);
01181 break;
01182
01183 case "Properties":
01184 $this->in_properties = false;
01185 if ($this->content_object->getType() == "lm"
01186 || $this->content_object->getType() == "dbk")
01187 {
01188 $this->content_object->update();
01189 }
01190 break;
01191
01192 case "MetaData":
01193 $this->in_meta_data = false;
01194 if(strtolower(get_class($this->current_object)) == "illmpageobject" && !$this->in_media_object)
01195 {
01196
01197 if (is_object($this->lm_page_object))
01198 {
01199
01200 $this->current_object->MDUpdateListener('General');
01201 ilLMObject::_writeImportId($this->current_object->getId(),
01202 $this->current_object->getImportId());
01203 }
01204 }
01205 else if((strtolower(get_class($this->current_object)) == "ilobjquestionpool" ||
01206 strtolower(get_class($this->current_object)) == "ilobjtest") &&
01207 !$this->in_media_object)
01208
01209
01210
01211 {
01212 if ($this->metadata_parsing_disabled)
01213 {
01214 $this->enableMDParsing(true);
01215 }
01216 else
01217 {
01218 if ($this->in_page_object)
01219 {
01220 $this->page_object->MDUpdateListener('General');
01221 ilLMObject::_writeImportId($this->page_object->getId(),
01222 $this->page_object->getImportId());
01223 }
01224 else
01225 {
01226 $this->current_object->MDUpdateListener('General');
01227 ilLMObject::_writeImportId($this->current_object->getId(),
01228 $this->current_object->getImportId());
01229 }
01230 }
01231 }
01232 else if(strtolower(get_class($this->current_object)) == "ilstructureobject")
01233 {
01234
01235 $cnt = count($this->structure_objects);
01236 if ($cnt > 1)
01237 {
01238 $parent_id = $this->structure_objects[$cnt - 2]->getId();
01239 }
01240 else
01241 {
01242 $parent_id = $this->lm_tree->getRootId();
01243 }
01244
01245
01246
01247 $this->st_into_tree[] = array ("id" => $this->current_object->getId(),
01248 "parent" => $parent_id);
01249
01250
01251 $this->current_object->MDUpdateListener('General');
01252 ilLMObject::_writeImportId($this->current_object->getId(),
01253 $this->current_object->getImportId());
01254 }
01255 else if(strtolower(get_class($this->current_object)) == "ilobjdlbook" || strtolower(get_class($this->current_object)) == "ilobjlearningmodule" ||
01256 strtolower(get_class($this->current_object)) == "ilobjcontentobject" ||
01257 (strtolower(get_class($this->current_object)) == "ilobjglossary" && $this->in_glossary))
01258 {
01259
01260
01261 }
01262 else if(strtolower(get_class($this->current_object)) == "ilglossarydefinition" && !$this->in_media_object)
01263 {
01264
01265
01266
01267 $this->page_object->setId($this->glossary_definition->getId());
01268 $this->page_object->updateFromXML();
01269
01270
01271
01272 }
01273
01274
01275 if(strtolower(get_class($this->current_object)) == "ilobjlearningmodule" ||
01276 strtolower(get_class($this->current_object)) == "ilobjdlbook" ||
01277 strtolower(get_class($this->current_object)) == "ilobjglossary")
01278 {
01279 if (strtolower(get_class($this->current_object)) == "ilobjglossary" &&
01280 $this->content_object->getType() != "glo")
01281 {
01282
01283 $this->current_object->setTitle($this->content_object->getTitle()." - ".
01284 $this->lng->txt("glossary"));
01285 }
01286
01287 $this->current_object->MDUpdateListener('General');
01288
01289
01290
01291
01292
01293
01294 }
01295
01296 if ($this->in_media_object)
01297 {
01298
01299 $this->media_object->MDUpdateListener('General');
01300 }
01301
01302 if ($this->in_glossary_definition)
01303 {
01304 $this->glossary_definition->MDUpdateListener('General');
01305 }
01306
01307 break;
01308
01309 case "Meta-Metadata":
01310 $this->in_meta_meta_data = false;
01311 break;
01312
01313 case "FileItem":
01314 $this->in_file_item = false;
01315
01316 if ($this->file_item->getImportId($a_attribs["Entry"] != ""))
01317 {
01318 $this->file_item->update();
01319 }
01320 break;
01321
01322 case "Bibliography":
01323
01324 $this->in_bib_item = false;
01325
01326 $nested = new ilNestedSetXML();
01327 $nested->import($this->bib_item->getXMLContent(),$this->content_object->getId(),"bib");
01328 break;
01329
01330 case "Table":
01331 unset ($this->container[count($this->container) - 1]);
01332 break;
01333
01334 case "Glossary":
01335 $this->in_glossary = false;
01336 break;
01337
01338 case "GlossaryTerm":
01339 $this->glossary_term->setTerm(trim($this->chr_data));
01340 $this->glossary_term->create();
01341 break;
01342
01343 case "Paragraph":
01344 $this->inside_code = false;
01345 break;
01346
01347 case "Definition":
01348 $this->in_glossary_definition = false;
01349 $this->page_object->updateFromXML();
01350 $this->page_object->buildDom();
01351 $this->glossary_definition->setShortText($this->page_object->getFirstParagraphText());
01352 $this->glossary_definition->update();
01353
01354
01355 if ($this->page_object->containsIntLink())
01356 {
01357
01358 $this->pages_to_parse["gdf:".$this->page_object->getId()] = "gdf:".$this->page_object->getId();
01359 }
01360 if ($this->page_object->needsImportParsing())
01361 {
01362 $this->pages_to_parse["gdf:".$this->page_object->getId()] = "gdf:".$this->page_object->getId();
01363 }
01364 break;
01365
01366 case "Format":
01367 if ($this->in_media_item)
01368 {
01369 $this->media_item->setFormat(trim($this->chr_data));
01370 }
01371 if ($this->in_file_item)
01372 {
01373 $this->file_item->setFileType(trim($this->chr_data));
01374 }
01375 break;
01376
01377 case "Title":
01378 if (!$this->in_media_object)
01379 {
01380 $this->current_object->setTitle(trim($this->chr_data));
01381
01382 }
01383 else
01384 {
01385 $this->media_object->setTitle(trim($this->chr_data));
01386
01387 }
01388 break;
01389
01390 case "Language":
01391
01392
01393
01394
01395
01396
01397 if (is_object($this->bib_item))
01398 {
01399 $this->bib_item->setLanguage(trim($this->chr_data));
01400 }
01401 break;
01402
01403 case "Description":
01404
01405 break;
01406
01407 case "Caption":
01408 if ($this->in_media_object)
01409 {
01410 $this->media_item->setCaption(trim($this->chr_data));
01411 }
01412 break;
01413
01414
01415 case "Location":
01416
01417 if ($this->in_media_item)
01418 {
01419 $this->media_item->setLocationType($this->loc_type);
01420 if ($this->loc_type == "Reference")
01421 {
01422 $this->media_item->setLocation(str_replace("&", "&", trim($this->chr_data)));
01423 }
01424 else
01425 {
01426 $this->media_item->setLocation(trim($this->chr_data));
01427 }
01428
01429 }
01430 if ($this->in_file_item)
01431 {
01432
01433 $this->file_item->setFileName(trim($this->chr_data));
01434
01435
01436
01437 if ($this->file_item->getType() == "file" &&
01438 is_int(strpos($this->chr_data, "&")) &&
01439 is_int(strpos($this->chr_data, ";")))
01440 {
01441 $imp_dir = $this->content_object->getImportDirectory();
01442 $source_dir = $imp_dir."/".$this->subdir."/objects/".
01443 $this->file_item->getImportId();
01444
01445
01446 if ($dir = opendir($source_dir))
01447 {
01448 while (false !== ($file = readdir($dir)))
01449 {
01450 if ($file != "." && $file != "..")
01451 {
01452 $this->file_item->setFileName($file);
01453 }
01454 }
01455 closedir($dir);
01456 }
01457 }
01458
01459
01460 $this->file_item->setTitle(trim($this->chr_data));
01461 }
01462 break;
01463
01464 }
01465 $this->endElement($a_name);
01466 $this->chr_data = "";
01467 }
01468
01475 function handlerCharacterData($a_xml_parser,$a_data)
01476 {
01477
01478 if ($this->in_meta_data && $this->processMeta())
01479 {
01480
01481
01482
01483 if ($this->in_media_object && $this->media_meta_start)
01484 {
01485 $this->media_meta_cache[] =
01486 array("type" => "handlerCharacterData", "par1" => $a_data);
01487 }
01488 else
01489 {
01490 parent::handlerCharacterData($a_xml_parser,$a_data);
01491 }
01492 }
01493
01494
01495
01496
01497
01498 $a_data = str_replace("<","<",$a_data);
01499 $a_data = str_replace(">",">",$a_data);
01500
01501
01502
01503 $a_data = preg_replace("/\n/","",$a_data);
01504 if (!$this->inside_code)
01505 {
01506 $a_data = preg_replace("/\t+/","",$a_data);
01507 }
01508
01509 $this->chr_data .= $a_data;
01510
01511 if(!empty($a_data) || $a_data === "0")
01512 {
01513
01514
01515 if (($this->in_page_object || $this->in_glossary_definition)
01516 && !$this->in_meta_data && !$this->in_media_object)
01517 {
01518 $this->page_object->appendXMLContent($a_data);
01519 }
01520
01521 if ($this->in_meta_data)
01522 {
01523
01524
01525 }
01526
01527 if ($this->in_bib_item )
01528 {
01529 $this->bib_item->appendXMLContent($a_data);
01530 }
01531
01532 switch($this->getCurrentElement())
01533 {
01534
01535 case "IntLink":
01536 case "ExtLink":
01537 if($this->in_map_area)
01538 {
01539 $this->map_area->appendTitle($a_data);
01540 }
01541 break;
01542
01543 }
01544 }
01545
01546 }
01547
01548
01553 function emptyMediaMetaCache(&$a_xml_parser)
01554 {
01555 foreach ($this->media_meta_cache as $cache_entry)
01556 {
01557 switch($cache_entry["type"])
01558 {
01559 case "handlerBeginTag":
01560 parent::handlerBeginTag($a_xml_parser,
01561 $cache_entry["par1"], $cache_entry["par2"]);
01562 break;
01563
01564 case "handlerEndTag":
01565 parent::handlerEndTag($a_xml_parser,
01566 $cache_entry["par1"]);
01567 break;
01568
01569 case "handlerCharacterData":
01570 parent::handlerCharacterData($a_xml_parser,
01571 $cache_entry["par1"]);
01572 break;
01573 }
01574 }
01575
01576 $this->media_meta_start = false;
01577 $this->media_meta_cache[] = array();
01578 }
01579
01580
01581 }
01582 ?>