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