ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilContObjParser.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
5 require_once("./Services/COPage/classes/class.ilPageObject.php");
6 require_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
7 require_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
8 require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
9 require_once("./Services/COPage/classes/class.ilPCParagraph.php");
10 require_once("./Services/COPage/classes/class.ilPCTable.php");
11 require_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
12 require_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
13 require_once("./Services/MediaObjects/classes/class.ilMapArea.php");
14 require_once("./Modules/LearningModule/classes/class.ilBibItem.php");
15 require_once("./Modules/Glossary/classes/class.ilObjGlossary.php");
16 require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
17 require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
18 require_once("./Services/COPage/classes/class.ilInternalLink.php");
19 require_once("./Modules/File/classes/class.ilObjFile.php");
20 
21 include_once("Services/MetaData/classes/class.ilMDSaxParser.php");
22 include_once("Services/MetaData/classes/class.ilMD.php");
23 
33 {
34  var $lng;
35  var $tree;
36  var $cnt; // counts open elements
37  var $current_element; // store current element type
38  var $learning_module; // current learning module
39  var $page_object; // current page object
41  var $structure_objects; // array of current structure objects
43  var $current_object; // at the time a LearningModule, PageObject or StructureObject
44  var $meta_data; // current meta data object
46  var $table;
47  var $lm_tree;
51  var $in_page_object; // are we currently within a PageObject? true/false
52  var $in_meta_data; // are we currently within MetaData? true/false
64  var $subdir;
65  var $media_item; // current media item
66  var $loc_type; // current location type
67  var $bib_item; // current bib item object
68  var $map_area; // current map area
69  var $in_bib_item; // are we currently within BibItem? true/false
70  var $link_targets; // stores all objects by import id
73  var $in_meta_meta_data = false;
74 
84  function ilContObjParser(&$a_content_object, $a_xml_file, $a_subdir)
85  {
86  global $lng, $tree;
87 
88  parent::ilMDSaxParser($a_xml_file);
89  $this->cnt = array();
90  $this->current_element = array();
91  $this->structure_objects = array();
92  $this->content_object =& $a_content_object;
93  //$this->lm_id = $a_lm_id;
94  $this->st_into_tree = array();
95  $this->pg_into_tree = array();
96  $this->pages_to_parse = array();
97  $this->mobs_with_int_links = array();
98  $this->mob_mapping = array();
99  $this->file_item_mapping = array();
100  $this->pg_mapping = array();
101  $this->link_targets = array();
102  $this->subdir = $a_subdir;
103  $this->lng =& $lng;
104  $this->tree =& $tree;
105  $this->inside_code = false;
106  $this->qst_mapping = array();
107  $this->coType = $this->content_object->getType();
108  $this->metadata_parsing_disabled = false;
109 
110  if (($this->coType != "tst") and ($this->coType != "qpl"))
111  {
112  $this->lm_tree = new ilTree($this->content_object->getId());
113  $this->lm_tree->setTreeTablePK("lm_id");
114  $this->lm_tree->setTableNames('lm_tree','lm_data');
115  }
116  //$this->lm_tree->addTree($a_lm_id, 1); happens in ilObjLearningModuleGUI
117 
118  }
119 
126  function setHandlers($a_xml_parser)
127  {
128  xml_set_object($a_xml_parser,$this);
129  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
130  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
131  }
132 
133 
137  function startParsing()
138  {
139 //echo "<b>start parsing</b><br>";
141 //echo "<b>storeTree</b><br>";
142  $this->storeTree();
143 //echo "<b>processPagesToParse</b><br>";
144  $this->processPagesToParse();
145 //echo "<b>copyMobFiles</b><br>";
146  $this->copyMobFiles();
147 //echo "<b>copyFileItems</b><br>";
148  $this->copyFileItems();
149  }
150 
151 
155  function storeTree()
156  {
157  global $ilLog;
158 
159 //echo "<b>Storing the tree</b><br>";
160  foreach($this->st_into_tree as $st)
161  {
162 //echo "insert st id: ".$st["id"].", parent:".$st["parent"]."<br>";
163  $this->lm_tree->insertNode($st["id"], $st["parent"]);
164 //echo "done<br>";
165  if (is_array($this->pg_into_tree[$st["id"]]))
166  {
167  foreach($this->pg_into_tree[$st["id"]] as $pg)
168  {
169  switch ($pg["type"])
170  {
171  case "pg_alias":
172  if ($this->pg_mapping[$pg["id"]] == "")
173  {
174  $ilLog->write("LM Import: No PageObject for PageAlias ".
175  $pg["id"]." found! (Please update export installation to ILIAS 3.3.0)");
176 
177  // Jump two levels up. First level is switch
178  continue 2;
179  }
180  $pg_id = $this->pg_mapping[$pg["id"]];
181  break;
182 
183  case "pg":
184  $pg_id = $pg["id"];
185  break;
186  }
187  if (!$this->lm_tree->isInTree($pg_id))
188  {
189  $this->lm_tree->insertNode($pg_id, $st["id"]);
190  }
191  }
192  }
193  }
194 //echo "<b>END: storing the tree</b>";
195  }
196 
197 
202  {
203  /*
204  $pg_mapping = array();
205  foreach($this->pg_mapping as $key => $value)
206  {
207  $pg_mapping[$key] = "il__pg_".$value;
208  }*/
209 //echo "<br><b>processIntLinks</b>"; flush();
210 
211  // outgoin internal links
212  foreach($this->pages_to_parse as $page_id)
213  {
214  $page_arr = explode(":", $page_id);
215 //echo "<br>resolve:".$this->content_object->getType().":".$page_id; flush();
216  switch($page_arr[0])
217  {
218  case "lm":
219  $page_obj =& new ilPageObject($this->content_object->getType(), $page_arr[1]);
220  break;
221 
222  case "gdf":
223  $page_obj =& new ilPageObject("gdf", $page_arr[1]);
224  break;
225  }
226  $page_obj->buildDom();
227  $page_obj->resolveIntLinks();
228  if (in_array($this->coType, array("lm", "dbk")))
229  {
230  $page_obj->resolveQuestionReferences($this->qst_mapping);
231  }
232  $page_obj->update(false);
233 
234  if ($page_arr[0] == "gdf")
235  {
236  $def =& new ilGlossaryDefinition($page_arr[1]);
237  $def->updateShortText();
238  }
239 
240  unset($page_obj);
241  }
242 
243 //echo "<br><b>map area internal links</b>"; flush();
244  // outgoins map area (mob) internal links
245  foreach($this->mobs_with_int_links as $mob_id)
246  {
248  }
249 
250 //echo "<br><b>incoming interna links</b>"; flush();
251  // incoming internal links
252  $done = array();
253  foreach ($this->link_targets as $link_target)
254  {
255 //echo "doin link target:".$link_target.":<br>";
256  $link_arr = explode("_", $link_target);
257  $target_inst = $link_arr[1];
258  $target_type = $link_arr[2];
259  $target_id = $link_arr[3];
261  foreach($sources as $key => $source)
262  {
263 //echo "got source:".$key.":<br>";
264  if(in_array($key, $done))
265  {
266  continue;
267  }
268  $type_arr = explode(":", $source["type"]);
269 
270  // content object pages
271  if ($type_arr[1] == "pg")
272  {
273  $page_object = new ilPageObject($type_arr[0], $source["id"]);
274  $page_object->buildDom();
275  $page_object->resolveIntLinks();
276  $page_object->update();
277  unset($page_object);
278  }
279  // eventually correct links in questions to learning modules
280  if ($type_arr[0] == "qst")
281  {
282  require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
283  assQuestion::_resolveIntLinks($source["id"]);
284  }
285  // eventually correct links in survey questions to learning modules
286  if ($type_arr[0] == "sqst")
287  {
288  require_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
289  SurveyQuestion::_resolveIntLinks($source["id"]);
290  }
291  $done[$key] = $key;
292  }
293  }
294  }
295 
296 
300  function copyMobFiles()
301  {
302  $imp_dir = $this->content_object->getImportDirectory();
303  foreach ($this->mob_mapping as $origin_id => $mob_id)
304  {
305  if(empty($origin_id))
306  {
307  continue;
308  }
309 
310  /*
311  $origin_arr = explode("_", $origin_id);
312  if ($origin_arr[2] == "el") // imagemap
313  {
314  $obj_dir = "imagemap".$origin_arr[3];
315  }
316  else // normal media object
317  {
318  $obj_dir = "mm".$origin_arr[3];
319  }*/
320 
321  $obj_dir = $origin_id;
322  $source_dir = $imp_dir."/".$this->subdir."/objects/".$obj_dir;
323  $target_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$mob_id;
324 
325 //echo "copy from $source_dir to $target_dir <br>";
326  if (@is_dir($source_dir))
327  {
328  // make target directory
329  ilUtil::makeDir($target_dir);
330  //@mkdir($target_dir);
331  //@chmod($target_dir, 0755);
332 
333  if (@is_dir($target_dir))
334  {
335  ilUtil::rCopy($source_dir, $target_dir);
336  }
337  }
338  }
339  }
340 
344  function copyFileItems()
345  {
346  $imp_dir = $this->content_object->getImportDirectory();
347  foreach ($this->file_item_mapping as $origin_id => $file_id)
348  {
349  if(empty($origin_id))
350  {
351  continue;
352  }
353  $obj_dir = $origin_id;
354  $source_dir = $imp_dir."/".$this->subdir."/objects/".$obj_dir;
355 
356  include_once("./Modules/File/classes/class.ilObjFile.php");
357  $file_obj = new ilObjFile($file_id, false);
358  //$target_dir = ilUtil::getDataDir()."/files/file_".$file_id;
359  $target_dir = $file_obj->getDirectory();
360  if (@is_dir($source_dir))
361  {
362  // make target directory
363  ilUtil::makeDir($target_dir);
364  //@mkdir($target_dir);
365  //@chmod($target_dir, 0755);
366 
367  if (@is_dir($target_dir))
368  {
369  ilUtil::rCopy($source_dir, $target_dir);
370  }
371  }
372  $test = $file_obj->determineFilesize();
373  $file_obj->update();
374  }
375  }
376 
380  function setQuestionMapping($a_map)
381  {
382  $this->qst_mapping = $a_map;
383  }
384 
385 
386  /*
387  * update parsing status for a element begin
388  */
389  function beginElement($a_name)
390  {
391  if(!isset($this->status["$a_name"]))
392  {
393  $this->cnt[$a_name] == 1;
394  }
395  else
396  {
397  $this->cnt[$a_name]++;
398  }
399  $this->current_element[count($this->current_element)] = $a_name;
400  }
401 
402  /*
403  * update parsing status for an element ending
404  *
405  * @param string $a_name element name
406  */
407  function endElement($a_name)
408  {
409  $this->cnt[$a_name]--;
410  unset ($this->current_element[count($this->current_element) - 1]);
411  }
412 
413  /*
414  * returns current element
415  */
416  function getCurrentElement()
417  {
418  return ($this->current_element[count($this->current_element) - 1]);
419  }
420 
421  /*
422  * returns number of current open elements of type $a_name
423  *
424  * @param string $a_name element name
425  */
426  function getOpenCount($a_name)
427  {
428  if (isset($this->cnt[$a_name]))
429  {
430  return $this->cnt[$a_name];
431  }
432  else
433  {
434  return 0;
435  }
436 
437  }
438 
446  function buildTag ($type, $name, $attr="")
447  {
448  $tag = "<";
449 
450  if ($type == "end")
451  $tag.= "/";
452 
453  $tag.= $name;
454 
455  if (is_array($attr))
456  {
457  while (list($k,$v) = each($attr))
458  $tag.= " ".$k."=\"$v\"";
459  }
460 
461  $tag.= ">";
462 
463  return $tag;
464  }
465 
473  function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
474  {
475 //echo "<b>BEGIN TAG: $a_name <br></b>"; flush();
476  switch($a_name)
477  {
478  case "ContentObject":
479  $this->current_object =& $this->content_object;
480 //echo "<br>Parser:CObjType:".$a_attribs["Type"];
481  if ($a_attribs["Type"] == "Glossary")
482  {
483  $this->glossary_object =& $this->content_object;
484  }
485  break;
486 
487  case "StructureObject":
488 //echo "<br><br>StructureOB-SET-".count($this->structure_objects)."<br>";
489  $this->structure_objects[count($this->structure_objects)]
490  =& new ilStructureObject($this->content_object);
491  $this->current_object =& $this->structure_objects[count($this->structure_objects) - 1];
492  $this->current_object->setLMId($this->content_object->getId());
493  // new meta data handling: we create the structure
494  // object already here, this should also create a
495  // md entry
496  $this->current_object->create(true);
497  break;
498 
499  case "PageObject":
500  $this->in_page_object = true;
501  $this->cur_qid = "";
502  if (($this->coType != "tst") and ($this->coType != "qpl"))
503  {
504  $this->lm_page_object =& new ilLMPageObject($this->content_object);
505  $this->page_object =& new ilPageObject($this->content_object->getType());
506  $this->lm_page_object->setLMId($this->content_object->getId());
507  $this->lm_page_object->assignPageObject($this->page_object);
508  $this->current_object =& $this->lm_page_object;
509  }
510  else
511  {
512  $this->page_object =& new ilPageObject("qpl");
513  }
514  break;
515 
516  case "PageAlias":
517  if (($this->coType != "tst") and ($this->coType != "qpl"))
518  {
519  $this->lm_page_object->setAlias(true);
520  $this->lm_page_object->setOriginID($a_attribs["OriginId"]);
521  }
522  break;
523 
524  case "MediaObject":
525  $this->in_media_object = true;
526  $this->media_meta_start = true;
527  $this->media_meta_cache = array();
528  $this->media_object =& new ilObjMediaObject();
529  break;
530 
531  case "MediaAlias":
532 //echo "<br>---NEW MEDIAALIAS---<br>";
533  $this->media_object->setAlias(true);
534  $this->media_object->setImportId($a_attribs["OriginId"]);
535  if (is_object($this->page_object))
536  {
537  $this->page_object->needsImportParsing(true);
538  }
539  break;
540 
541  case "MediaItem":
542  case "MediaAliasItem":
543  $this->in_media_item = true;
544  $this->media_item =& new ilMediaItem();
545  $this->media_item->setPurpose($a_attribs["Purpose"]);
546  break;
547 
548  case "Layout":
549  if (is_object($this->media_object) && $this->in_media_object)
550  {
551  $this->media_item->setWidth($a_attribs["Width"]);
552  $this->media_item->setHeight($a_attribs["Height"]);
553  $this->media_item->setHAlign($a_attribs["HorizontalAlign"]);
554  }
555  break;
556 
557  case "Parameter":
558  if (is_object($this->media_object) && $this->in_media_object)
559  {
560  $this->media_item->setParameter($a_attribs["Name"], $a_attribs["Value"]);
561  }
562  break;
563 
564  case "MapArea":
565  $this->in_map_area = true;
566  $this->map_area =& new ilMapArea();
567  $this->map_area->setShape($a_attribs["Shape"]);
568  $this->map_area->setCoords($a_attribs["Coords"]);
569  break;
570 
571  case "Glossary":
572  $this->in_glossary = true;
573  if ($this->content_object->getType() != "glo")
574  {
575  $this->glossary_object =& new ilObjGlossary();
576  $this->glossary_object->setTitle("");
577  $this->glossary_object->setDescription("");
578  $this->glossary_object->create(true);
579  $this->glossary_object->createReference();
580  $parent =& $this->tree->getParentNodeData($this->content_object->getRefId());
581  $this->glossary_object->putInTree($parent["child"]);
582  $this->glossary_object->setPermissions($parent["child"]);
583  $this->glossary_object->notify("new", $_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$this->glossary_object->getRefId());
584  }
585  $this->current_object =& $this->glossary_object;
586  break;
587 
588  case "GlossaryItem":
589  $this->glossary_term =& new ilGlossaryTerm();
590  $this->glossary_term->setGlossaryId($this->glossary_object->getId());
591  $this->glossary_term->setLanguage($a_attribs["Language"]);
592  $this->glossary_term->setImportId($a_attribs["Id"]);
593  $this->link_targets[$a_attribs["Id"]] = $a_attribs["Id"];
594  break;
595 
596  case "Definition":
597  $this->in_glossary_definition = true;
598  $this->glossary_definition =& new ilGlossaryDefinition();
599  $this->page_object =& new ilPageObject("gdf");
600  $this->page_object->setParentId($this->glossary_term->getGlossaryId());
601  $this->glossary_definition->setTermId($this->glossary_term->getId());
602  $this->glossary_definition->assignPageObject($this->page_object);
603  $this->current_object =& $this->glossary_definition;
604  $this->glossary_definition->create(true);
605  break;
606 
607  case "FileItem":
608  $this->in_file_item = true;
609  $this->file_item =& new ilObjFile();
610  $this->file_item->setTitle("dummy");
611  $this->file_item->setMode("filelist");
612  if (is_object($this->page_object))
613  {
614  $this->page_object->needsImportParsing(true);
615  }
616  break;
617 
618  case "Paragraph":
619  if ($a_attribs["Characteristic"] == "Code")
620  {
621  $this->inside_code = true;
622  }
623  break;
624 
625  case "Properties":
626  $this->in_properties = true;
627  break;
628 
629  case "Property":
630  if ($this->content_object->getType() == "lm"
631  || $this->content_object->getType() == "dbk")
632  {
633  switch($a_attribs["Name"])
634  {
635  case "Layout":
636  $this->content_object->setLayout($a_attribs["Value"]);
637  break;
638 
639  case "PageHeader":
640  $this->content_object->setPageHeader($a_attribs["Value"]);
641  break;
642 
643  case "TOCMode":
644  $this->content_object->setTOCMode($a_attribs["Value"]);
645  break;
646 
647  case "ActiveLMMenu":
648  $this->content_object->setActiveLMMenu(
649  ilUtil::yn2tf($a_attribs["Value"]));
650  break;
651 
652  case "ActiveNumbering":
653  $this->content_object->setActiveNumbering(
654  ilUtil::yn2tf($a_attribs["Value"]));
655  break;
656 
657  case "ActiveTOC":
658  $this->content_object->setActiveTOC(
659  ilUtil::yn2tf($a_attribs["Value"]));
660  break;
661 
662  case "ActivePrintView":
663  $this->content_object->setActivePrintView(
664  ilUtil::yn2tf($a_attribs["Value"]));
665  break;
666 
667  case "CleanFrames":
668  $this->content_object->setCleanFrames(
669  ilUtil::yn2tf($a_attribs["Value"]));
670  break;
671 
672  case "PublicNotes":
673  $this->content_object->setPublicNotes(
674  ilUtil::yn2tf($a_attribs["Value"]));
675  break;
676 
677  case "HistoryUserComments":
678  $this->content_object->setHistoryUserComments(
679  ilUtil::yn2tf($a_attribs["Value"]));
680  break;
681 
682  case "HeaderPage":
683  if ($a_attribs["Value"] != "")
684  {
685  if ($this->pg_mapping[$a_attribs["Value"]] > 0)
686  {
687  $this->content_object->setHeaderPage(
688  $this->pg_mapping[$a_attribs["Value"]]);
689  }
690  }
691  break;
692 
693  case "FooterPage":
694  if ($a_attribs["Value"] != "")
695  {
696  if ($this->pg_mapping[$a_attribs["Value"]] > 0)
697  {
698  $this->content_object->setFooterPage(
699  $this->pg_mapping[$a_attribs["Value"]]);
700  }
701  }
702  break;
703  }
704  //echo "<br>+".$a_attribs["Name"]."+";
705  }
706  break;
707 
711  case "MetaData":
712  $this->in_meta_data = true;
713 //echo "<br>begin meta data section -".$this->current_object->getType()."-";
714  // media obejct meta data handling
715  // is done in the "Identifier" begin tag processing
716  // the rest is done here
717  if(!$this->in_media_object)
718  {
719  if (($this->coType != "tst") and ($this->coType != "qpl"))
720  {
721  // type pg/st
722  if ($this->current_object->getType() == "st" ||
723  $this->current_object->getType() == "pg")
724  {
725  // late creation of page object
726  if ($this->current_object->getType() == "pg")
727  {
728  $this->lm_page_object->create(true);
729  }
730  $this->md =& new ilMD($this->content_object->getId() ,
731  $this->current_object->getId(),
732  $this->current_object->getType());
733  }
734  // type gdf
735  else if ($this->current_object->getType() == "gdf")
736  {
737  $this->md =& new ilMD($this->glossary_object->getId() ,
738  $this->current_object->getId(),
739  $this->current_object->getType());
740  }
741  // type lm, dbk, glo
742  else
743  {
744  if ($this->processMeta())
745  {
746  $this->md =& new ilMD($this->current_object->getId() ,
747  0,
748  $this->current_object->getType());
749  }
750  }
751  }
752  else
753  {
754  // type qpl or tst
755  $this->md =& new ilMD($this->content_object->getId() ,
756  0,
757  $this->current_object->getType()
758  );
759  if ($this->md->getGeneral() != false)
760  {
761  $this->metadata_parsing_disabled = true;
762  $this->enableMDParsing(false);
763  }
764  }
765  }
766  break;
767 
768  // Identifier
769  case "Identifier":
770 
771  // please note: Meta-Metadata and MetaData are different tags!
772  if (!$this->in_meta_meta_data)
773  {
774  if ($this->in_meta_data && !$this->in_glossary_definition)
775  {
776  if (!$this->in_media_object)
777  {
778  $this->current_object->setImportId($a_attribs["Entry"]);
779  }
780  $this->link_targets[$a_attribs["Entry"]] = $a_attribs["Entry"];
781  }
782  if ($this->in_file_item)
783  {
784  if ($this->file_item_mapping[$a_attribs["Entry"]] == "")
785  {
786  $this->file_item->create();
787  $this->file_item->setImportId($a_attribs["Entry"]);
788  $this->file_item_mapping[$a_attribs["Entry"]] = $this->file_item->getId();
789  }
790  }
791  if ($this->in_meta_data && $this->in_media_object)
792  {
793 //echo "looking for -".$a_attribs["Entry"]."-<br>";
794 
795  $mob_id = $this->mob_mapping[$a_attribs["Entry"]];
796 
797  // within learning module import, usually a media object
798  // has already been created with a media alias tag
799  if ($mob_id > 0)
800  {
801  $this->media_object = new ilObjMediaObject($mob_id);
802  }
803  else // in glossaries the media objects precede the definitions
804  // so we don't have an object already
805  {
806  $this->media_object = new ilObjMediaObject();
807  $this->media_object->create(true, false);
808  $this->mob_mapping[$a_attribs["Entry"]]
809  = $this->media_object->getId();
810  }
811  $this->media_object->setImportId($a_attribs["Entry"]);
812  $this->md =& new ilMD(0 ,
813  $this->media_object->getId(),
814  "mob");
815  $this->emptyMediaMetaCache($a_xml_parser);
816  }
817  }
818  break;
819 
820  case "Meta-Metadata":
821  $this->in_meta_meta_data = true;
822  break;
823 
824  // Internal Link
825  case "IntLink":
826  if (is_object($this->page_object))
827  {
828  $this->page_object->setContainsIntLink(true);
829  }
830  if ($this->in_map_area)
831  {
832 //echo "intlink:maparea:<br>";
833  $this->map_area->setLinkType(IL_INT_LINK);
834  $this->map_area->setTarget($a_attribs["Target"]);
835  $this->map_area->setType($a_attribs["Type"]);
836  $this->map_area->setTargetFrame($a_attribs["TargetFrame"]);
837  if (is_object($this->media_object))
838  {
839 //echo ":setContainsLink:<br>";
840  $this->media_object->setContainsIntLink(true);
841  }
842  }
843  break;
844 
845  // External Link
846  case "ExtLink":
847  if ($this->in_map_area)
848  {
849  $this->map_area->setLinkType(IL_EXT_LINK);
850  $this->map_area->setHref($a_attribs["Href"]);
851  $this->map_area->setExtTitle($a_attribs["Title"]);
852  }
853  break;
854 
855  // Question
856  case "Question":
857  $this->cur_qid = $a_attribs["QRef"];
858  $this->page_object->setContainsQuestion(true);
859  break;
860 
861  case "Location":
862  $this->loc_type = $a_attribs["Type"];
863  break;
864 
865  case "Bibliography":
866  $this->in_bib_item = true;
867 //echo "<br>---NEW BIBLIOGRAPHY---<br>";
868  $this->bib_item =& new ilBibItem();
869  break;
870 
871  }
872  $this->beginElement($a_name);
873 
874  // append content to page xml content
875  if(($this->in_page_object || $this->in_glossary_definition)
876  && !$this->in_meta_data && !$this->in_media_object)
877  {
878  if ($a_name == "Definition")
879  {
880  $app_name = "PageObject";
881  $app_attribs = array();
882  }
883  else
884  {
885  $app_name = $a_name;
886  $app_attribs = $a_attribs;
887  }
888 
889  // change identifier entry of file items to new local file id
890  if ($this->in_file_item && $app_name == "Identifier")
891  {
892  $app_attribs["Entry"] = "il__file_".$this->file_item_mapping[$a_attribs["Entry"]];
893  //$app_attribs["Entry"] = "il__file_".$this->file_item->getId();
894  }
895 
896  $this->page_object->appendXMLContent($this->buildTag("start", $app_name, $app_attribs));
897 //echo "&nbsp;&nbsp;after append, xml:".$this->page_object->getXMLContent().":<br>";
898  }
899 
900  // append content to bibitem xml content
901  if ($this->in_bib_item) // && !$this->in_page_object && !$this->in_media_object
902  {
903  $this->bib_item->appendXMLContent("\n".$this->buildTag("start", $a_name, $a_attribs));
904  }
905 
906  // call meta data handler
907  if ($this->in_meta_data && $this->processMeta())
908  {
909  // cache beginning of meta data within media object tags
910  // (we need to know the id at the begin of meta elements within
911  // media objects, after the "Identifier" tag has been processed
912  // we send the cached data to the meta xml handler)
913  if ($this->in_media_object && $this->media_meta_start)
914  {
915  $this->media_meta_cache[] =
916  array("type" => "handlerBeginTag", "par1" => $a_name, "par2" => $a_attribs);
917  }
918  else
919  {
920  if ($a_name == "Identifier")
921  {
922  if (!$this->in_media_object)
923  {
924  $a_attribs["Entry"] = "il__".$this->current_object->getType().
925  "_".$this->current_object->getId();
926  }
927  else
928  {
929  $a_attribs["Entry"] = "il__mob".
930  "_".$this->media_object->getId();
931  }
932  $a_attribs["Catalog"] = "ILIAS";
933  }
934 
935  parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
936  }
937  }
938  }
939 
943  function processMeta()
944  {
945  // do not process second meta block in (ilias3) glossaries
946  // which comes right after the "Glossary" tag
947  if ($this->content_object->getType() == "glo" &&
948  $this->in_glossary && !$this->in_media_object
949  && !$this->in_glossary_definition)
950  {
951  return false;
952  }
953 
954  return true;
955  }
956 
957 
964  function handlerEndTag($a_xml_parser,$a_name)
965  {
966  // call meta data handler
967  if ($this->in_meta_data && $this->processMeta())
968  {
969  // cache beginning of meta data within media object tags
970  // (we need to know the id, after that we send the cached data
971  // to the meta xml handler)
972  if ($this->in_media_object && $this->media_meta_start)
973  {
974  $this->media_meta_cache[] =
975  array("type" => "handlerEndTag", "par1" => $a_name);
976  }
977  else
978  {
979  parent::handlerEndTag($a_xml_parser,$a_name);
980  }
981  }
982 
983 //echo "<b>END TAG: $a_name <br></b>"; flush();
984  // append content to page xml content
985  if (($this->in_page_object || $this->in_glossary_definition)
986  && !$this->in_meta_data && !$this->in_media_object)
987  {
988  $app_name = ($a_name == "Definition")
989  ? "PageObject"
990  : $a_name;
991  $this->page_object->appendXMLContent($this->buildTag("end", $app_name));
992  }
993 
994  // append content to bibitemxml content
995  if ($this->in_bib_item) // && !$this->in_page_object && !$this->in_media_object
996  {
997  if($a_name == "BibItem")
998  {
999  $this->bib_item->appendXMLContent("\n".$this->buildTag("end", $a_name));
1000  }
1001  else
1002  {
1003  $this->bib_item->appendXMLContent($this->buildTag("end", $a_name));
1004  }
1005 
1006  }
1007 
1008  switch($a_name)
1009  {
1010  case "StructureObject":
1011  //unset($this->meta_data);
1012  unset($this->structure_objects[count($this->structure_objects) - 1]);
1013  break;
1014 
1015  case "PageObject":
1016 
1017  $this->in_page_object = false;
1018  if (($this->coType != "tst") and ($this->coType != "qpl"))
1019  {
1020  if (!$this->lm_page_object->isAlias())
1021  {
1022  //$this->page_object->createFromXML();
1023  $this->page_object->updateFromXML();
1024  $this->pg_mapping[$this->lm_page_object->getImportId()]
1025  = $this->lm_page_object->getId();
1026 
1027  // collect pages with internal links
1028  if ($this->page_object->containsIntLink())
1029  {
1030  $this->pages_to_parse["lm:".$this->page_object->getId()] = "lm:".$this->page_object->getId();
1031  }
1032 
1033  // collect pages with mobs or files
1034  if ($this->page_object->needsImportParsing())
1035  {
1036  $this->pages_to_parse["lm:".$this->page_object->getId()] = "lm:".$this->page_object->getId();
1037  }
1038 
1039  // collect pages with questions
1040  if ($this->page_object->getContainsQuestion())
1041  {
1042  $this->pages_to_parse["lm:".$this->page_object->getId()] = "lm:".$this->page_object->getId();
1043  }
1044 
1045  }
1046  }
1047  else
1048  {
1049  $xml = $this->page_object->getXMLContent();
1050  if ($this->cur_qid != "")
1051  {
1052  $ids = $this->qst_mapping[$this->cur_qid];
1053  if ($ids["pool"] > 0)
1054  {
1055  // question pool question
1056  $page = new ilPageObject("qpl", $ids["pool"]);
1057  $xmlcontent = str_replace($this->cur_qid,
1058  "il__qst_".$ids["pool"], $xml);
1059  $page->setXMLContent($xmlcontent);
1060  $page->saveMobUsage($xmlcontent);
1061  $page->updateFromXML();
1062  unset($page);
1063  }
1064  if ($ids["test"] > 0)
1065  {
1066  // test question
1067  $page = new ilPageObject("qpl", $ids["test"]);
1068  $xmlcontent = str_replace($this->cur_qid,
1069  "il__qst_".$ids["test"], $xml);
1070  $page->setXMLContent($xmlcontent);
1071  $page->saveMobUsage($xmlcontent);
1072  $page->updateFromXML();
1073  unset($page);
1074  }
1075  }
1076  }
1077 
1078  // if we are within a structure object: put page in tree
1079  $cnt = count($this->structure_objects);
1080  if ($cnt > 0)
1081  {
1082  $parent_id = $this->structure_objects[$cnt - 1]->getId();
1083  if ($this->lm_page_object->isAlias())
1084  {
1085  $this->pg_into_tree[$parent_id][] = array("type" => "pg_alias", "id" => $this->lm_page_object->getOriginId());
1086  }
1087  else
1088  {
1089  $this->pg_into_tree[$parent_id][] = array("type" => "pg", "id" => $this->lm_page_object->getId());
1090  }
1091  }
1092 
1093  unset($this->page_object);
1094  unset($this->lm_page_object);
1095  unset ($this->container[count($this->container) - 1]);
1096  break;
1097 
1098  case "MediaObject":
1099  $this->in_media_object = false;
1100 //echo "ENDMediaObject:ImportId:".$this->media_object->getImportId()."<br>";
1101  // create media object on first occurence of an Id
1102 
1103 
1104  if(empty($this->mob_mapping[$this->media_object->getImportId()]))
1105  {
1106 //echo "No mapping found --creating media object:title:".$this->media_object->getTitle().":<br>";
1107 
1108  // create media object
1109  // media items are saves for mobs outside of
1110  // pages only
1111  $this->media_object->create(true, false);
1112 
1113 //echo "<br>creating mob ".$this->media_object->getId().":".$this->media_object->getTitle().":";
1114 
1115  // collect mobs with internal links
1116  if ($this->media_object->containsIntLink())
1117  {
1118 //echo "got int link :".$this->media_object->getId().":<br>";
1119  $this->mobs_with_int_links[] = $this->media_object->getId();
1120  }
1121 
1122  $this->mob_mapping[$this->media_object->getImportId()]
1123  = $this->media_object->getId();
1124 //echo "create:import_id:".$this->media_object->getImportId().":ID:".$this->mob_mapping[$this->media_object->getImportId()]."<br>";
1125  }
1126  else
1127  {
1128 //echo "Mapping found<br>";
1129  // get the id from mapping
1130  $this->media_object->setId($this->mob_mapping[$this->media_object->getImportId()]);
1131 
1132  // update "real" (no alias) media object
1133  // (note: we overwrite any data from the media object
1134  // created by an MediaAlias, only the data of the real
1135  // object is stored in db separately; data of the
1136  // MediaAliases are within the page XML
1137  if (!$this->media_object->isAlias())
1138  {
1139  // now the media items are saved within the db
1140  $this->media_object->update();
1141 
1142 //echo "<br>update media object :".$this->media_object->getId().":";
1143 
1144  // collect mobs with internal links
1145  if ($this->media_object->containsIntLink())
1146  {
1147 //echo "got int link :".$this->media_object->getId().":<br>";
1148  $this->mobs_with_int_links[] = $this->media_object->getId();
1149  }
1150  }
1151  }
1152 
1153  // append media alias to page, if we are in a page
1154  if ($this->in_page_object || $this->in_glossary_definition)
1155  {
1156  $this->page_object->appendXMLContent($this->media_object->getXML(IL_MODE_ALIAS));
1157 //echo "Appending:".htmlentities($this->media_object->getXML(IL_MODE_ALIAS))."<br>";
1158  }
1159 
1160  break;
1161 
1162  case "MediaItem":
1163  case "MediaAliasItem":
1164  $this->in_media_item = false;
1165  $this->media_object->addMediaItem($this->media_item);
1166 //echo "adding media item -".$this->media_item->getId()."-".$this->media_item->getLocation()."- to object -".$this->media_object->getId()."-";
1167  break;
1168 
1169  case "MapArea":
1170  $this->in_map_area = false;
1171  $this->media_item->addMapArea($this->map_area);
1172  break;
1173 
1174  case "Properties":
1175  $this->in_properties = false;
1176  if ($this->content_object->getType() == "lm"
1177  || $this->content_object->getType() == "dbk")
1178  {
1179  $this->content_object->update();
1180  }
1181  break;
1182 
1183  case "MetaData":
1184  $this->in_meta_data = false;
1185  if(strtolower(get_class($this->current_object)) == "illmpageobject" && !$this->in_media_object)
1186  {
1187  // Metadaten eines PageObjects sichern in NestedSet
1188  if (is_object($this->lm_page_object))
1189  {
1190  // update title/description of page object
1191  $this->current_object->MDUpdateListener('General');
1192  ilLMObject::_writeImportId($this->current_object->getId(),
1193  $this->current_object->getImportId());
1194  }
1195  }
1196  else if((strtolower(get_class($this->current_object)) == "ilobjquestionpool" ||
1197  strtolower(get_class($this->current_object)) == "ilobjtest") &&
1199 // !$this->in_media_object && !$this->in_page_object)
1200 // changed for imports of ILIAS 2 Tests where PageObjects could have
1201 // Metadata sections (Helmut Schottmüller, 2005-12-02)
1202  {
1203  if ($this->metadata_parsing_disabled)
1204  {
1205  $this->enableMDParsing(true);
1206  }
1207  else
1208  {
1209  if ($this->in_page_object)
1210  {
1211  $this->page_object->MDUpdateListener('General');
1212  ilLMObject::_writeImportId($this->page_object->getId(),
1213  $this->page_object->getImportId());
1214  }
1215  else
1216  {
1217  $this->current_object->MDUpdateListener('General');
1218  ilLMObject::_writeImportId($this->current_object->getId(),
1219  $this->current_object->getImportId());
1220  }
1221  }
1222  }
1223  else if(strtolower(get_class($this->current_object)) == "ilstructureobject")
1224  { // save structure object at the end of its meta block
1225  // determine parent
1226  $cnt = count($this->structure_objects);
1227  if ($cnt > 1)
1228  {
1229  $parent_id = $this->structure_objects[$cnt - 2]->getId();
1230  }
1231  else
1232  {
1233  $parent_id = $this->lm_tree->getRootId();
1234  }
1235 
1236  // create structure object and put it in tree
1237  //$this->current_object->create(true); // now on top
1238  $this->st_into_tree[] = array ("id" => $this->current_object->getId(),
1239  "parent" => $parent_id);
1240 
1241  // update title/description of structure object
1242  $this->current_object->MDUpdateListener('General');
1243  ilLMObject::_writeImportId($this->current_object->getId(),
1244  $this->current_object->getImportId());
1245  }
1246  else if(strtolower(get_class($this->current_object)) == "ilobjdlbook" || strtolower(get_class($this->current_object)) == "ilobjlearningmodule" ||
1247  strtolower(get_class($this->current_object)) == "ilobjcontentobject" ||
1248  (strtolower(get_class($this->current_object)) == "ilobjglossary" && $this->in_glossary))
1249  {
1250  // todo: saving of md? getting title/descr and
1251  // set it for current object
1252  }
1253  else if(strtolower(get_class($this->current_object)) == "ilglossarydefinition" && !$this->in_media_object)
1254  {
1255  // now on top
1256  //$this->glossary_definition->create();
1257 
1258  $this->page_object->setId($this->glossary_definition->getId());
1259  $this->page_object->updateFromXML();
1260 
1261  // todo: saving of md? getting title/descr and
1262  // set it for current object
1263  }
1264 
1265 
1266  if(strtolower(get_class($this->current_object)) == "ilobjlearningmodule" ||
1267  strtolower(get_class($this->current_object)) == "ilobjdlbook" ||
1268  strtolower(get_class($this->current_object)) == "ilobjglossary")
1269  {
1270  if (strtolower(get_class($this->current_object)) == "ilobjglossary" &&
1271  $this->content_object->getType() != "glo")
1272  {
1273 //echo "<br><b>getting2: ".$this->content_object->getTitle()."</b>";
1274  $this->current_object->setTitle($this->content_object->getTitle()." - ".
1275  $this->lng->txt("glossary"));
1276  }
1277 
1278  $this->current_object->MDUpdateListener('General');
1279  /*
1280  if (!$this->in_media_object && $this->processMeta())
1281  {
1282  $this->current_object->update();
1283  }
1284  */
1285  }
1286 
1287  if ($this->in_media_object)
1288  {
1289 //echo "<br>call media object update listener";
1290  $this->media_object->MDUpdateListener('General');
1291  }
1292 
1293  if ($this->in_glossary_definition)
1294  {
1295  $this->glossary_definition->MDUpdateListener('General');
1296  }
1297 
1298  break;
1299 
1300  case "Meta-Metadata":
1301  $this->in_meta_meta_data = false;
1302  break;
1303 
1304  case "FileItem":
1305  $this->in_file_item = false;
1306  // only update new file items
1307  if ($this->file_item->getImportId($a_attribs["Entry"] != ""))
1308  {
1309  $this->file_item->update();
1310  }
1311  break;
1312 
1313  case "Bibliography":
1314 
1315  $this->in_bib_item = false;
1316 
1317  $nested = new ilNestedSetXML();
1318  $nested->import($this->bib_item->getXMLContent(),$this->content_object->getId(),"bib");
1319  break;
1320 
1321  case "Table":
1322  unset ($this->container[count($this->container) - 1]);
1323  break;
1324 
1325  case "Glossary":
1326  $this->in_glossary = false;
1327  break;
1328 
1329  case "GlossaryTerm":
1330  $this->glossary_term->setTerm(trim($this->chr_data));
1331  $this->glossary_term->create();
1332  break;
1333 
1334  case "Paragraph":
1335  $this->inside_code = false;
1336  break;
1337 
1338  case "Definition":
1339  $this->in_glossary_definition = false;
1340  $this->page_object->updateFromXML();
1341  $this->page_object->buildDom();
1342  $this->glossary_definition->setShortText($this->page_object->getFirstParagraphText());
1343  $this->glossary_definition->update();
1344  //$this->pg_mapping[$this->lm_page_object->getImportId()]
1345  // = $this->lm_page_object->getId();
1346  if ($this->page_object->containsIntLink())
1347  {
1348 //echo "<br>Definition contains Int Link:".$this->page_object->getId();
1349  $this->pages_to_parse["gdf:".$this->page_object->getId()] = "gdf:".$this->page_object->getId();
1350  }
1351  if ($this->page_object->needsImportParsing())
1352  {
1353  $this->pages_to_parse["gdf:".$this->page_object->getId()] = "gdf:".$this->page_object->getId();
1354  }
1355  break;
1356 
1357  case "Format":
1358  if ($this->in_media_item)
1359  {
1360  $this->media_item->setFormat(trim($this->chr_data));
1361  }
1362  if ($this->in_file_item)
1363  {
1364  $this->file_item->setFileType(trim($this->chr_data));
1365  }
1366  break;
1367 
1368  case "Title":
1369  if (!$this->in_media_object)
1370  {
1371  $this->current_object->setTitle(trim($this->chr_data));
1372  //$this->meta_data->setTitle(trim($this->chr_data));
1373  }
1374  else
1375  {
1376  $this->media_object->setTitle(trim($this->chr_data));
1377  //$this->meta_data->setTitle(trim($this->chr_data));
1378  }
1379  break;
1380 
1381  case "Language":
1382  /*
1383  if (is_object($this->meta_data))
1384  {
1385  $this->meta_data->setLanguage(trim($this->chr_data));
1386  }*/
1387 
1388  if (is_object($this->bib_item))
1389  {
1390  $this->bib_item->setLanguage(trim($this->chr_data));
1391  }
1392  break;
1393 
1394  case "Description":
1395  //$this->meta_data->setDescription(trim($this->chr_data));
1396  break;
1397 
1398  case "Caption":
1399  if ($this->in_media_object)
1400  {
1401  $this->media_item->setCaption(trim($this->chr_data));
1402  }
1403  break;
1404 
1405  case "TextRepresentation":
1406  if ($this->in_media_object)
1407  {
1408  $this->media_item->setTextRepresentation(trim($this->chr_data));
1409  }
1410  break;
1411 
1412  // Location
1413  case "Location":
1414  // TODO: adapt for files in "real" subdirectories
1415  if ($this->in_media_item)
1416  {
1417  $this->media_item->setLocationType($this->loc_type);
1418  if ($this->loc_type == "Reference")
1419  {
1420  $this->media_item->setLocation(str_replace("&", "&amp;", trim($this->chr_data)));
1421  }
1422  else
1423  {
1424  $this->media_item->setLocation(trim($this->chr_data));
1425  }
1426  //echo "-".$this->media_item->getLocation()."-";
1427  }
1428  if ($this->in_file_item)
1429  {
1430  // set file name from xml file
1431  $this->file_item->setFileName(trim($this->chr_data));
1432 
1433  // special handling for file names with special characters
1434  // (e.g. "&gt;")
1435  if ($this->file_item->getType() == "file" &&
1436  is_int(strpos($this->chr_data, "&")) &&
1437  is_int(strpos($this->chr_data, ";")))
1438  {
1439  $imp_dir = $this->content_object->getImportDirectory();
1440  $source_dir = $imp_dir."/".$this->subdir."/objects/".
1441  $this->file_item->getImportId();
1442 
1443  // read "physical" file name from directory
1444  if ($dir = opendir($source_dir))
1445  {
1446  while (false !== ($file = readdir($dir)))
1447  {
1448  if ($file != "." && $file != "..")
1449  {
1450  $this->file_item->setFileName($file);
1451  }
1452  }
1453  closedir($dir);
1454  }
1455  }
1456 
1457  // set file item title
1458  $this->file_item->setTitle(trim($this->chr_data));
1459  }
1460  break;
1461 
1462  }
1463  $this->endElement($a_name);
1464  $this->chr_data = "";
1465  }
1466 
1473  function handlerCharacterData($a_xml_parser,$a_data)
1474  {
1475  // call meta data handler
1476  if ($this->in_meta_data && $this->processMeta())
1477  {
1478  // cache beginning of meta data within media object tags
1479  // (we need to know the id, after that we send the cached data
1480  // to the meta xml handler)
1481  if ($this->in_media_object && $this->media_meta_start)
1482  {
1483  $this->media_meta_cache[] =
1484  array("type" => "handlerCharacterData", "par1" => $a_data);
1485  }
1486  else
1487  {
1488  parent::handlerCharacterData($a_xml_parser,$a_data);
1489  }
1490  }
1491 
1492  // the parser converts "&gt;" to ">" and "&lt;" to "<"
1493  // in character data, but we don't want that, because it's the
1494  // way we mask user html in our content, so we convert back...
1495 
1496  $a_data = str_replace("<","&lt;",$a_data);
1497  $a_data = str_replace(">","&gt;",$a_data);
1498 
1499 
1500  // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
1501  $a_data = preg_replace("/\n/","",$a_data);
1502  if (!$this->inside_code)
1503  {
1504  $a_data = preg_replace("/\t+/","",$a_data);
1505  }
1506 
1507  $this->chr_data .= $a_data;
1508 
1509  if(!empty($a_data) || $a_data === "0")
1510  {
1511  // append all data to page, if we are within PageObject,
1512  // but not within MetaData or MediaObject
1513  if (($this->in_page_object || $this->in_glossary_definition)
1514  && !$this->in_meta_data && !$this->in_media_object)
1515  {
1516  $this->page_object->appendXMLContent($a_data);
1517  }
1518 
1519  if ($this->in_meta_data)
1520  {
1521  //$this->meta_data->appendXMLContent($a_data);
1522 //echo "<br>".$a_data;
1523  }
1524 
1525  if ($this->in_bib_item )
1526  {
1527  $this->bib_item->appendXMLContent($a_data);
1528  }
1529 
1530  switch($this->getCurrentElement())
1531  {
1532 
1533  case "IntLink":
1534  case "ExtLink":
1535  if($this->in_map_area)
1536  {
1537  $this->map_area->appendTitle($a_data);
1538  }
1539  break;
1540 
1541  }
1542  }
1543 
1544  }
1545 
1546 
1551  function emptyMediaMetaCache(&$a_xml_parser)
1552  {
1553  foreach ($this->media_meta_cache as $cache_entry)
1554  {
1555  switch($cache_entry["type"])
1556  {
1557  case "handlerBeginTag":
1558  parent::handlerBeginTag($a_xml_parser,
1559  $cache_entry["par1"], $cache_entry["par2"]);
1560  break;
1561 
1562  case "handlerEndTag":
1563  parent::handlerEndTag($a_xml_parser,
1564  $cache_entry["par1"]);
1565  break;
1566 
1567  case "handlerCharacterData":
1568  parent::handlerCharacterData($a_xml_parser,
1569  $cache_entry["par1"]);
1570  break;
1571  }
1572  }
1573 
1574  $this->media_meta_start = false;
1575  $this->media_meta_cache[] = array();
1576  }
1577 
1578 
1579 }
1580 ?>