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