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