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