ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilStyleImporter.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 include_once("./Services/Export/classes/class.ilXmlImporter.php");
5 
14 {
18  protected $log;
19 
20  function init()
21  {
22  $this->log = ilLoggerFactory::getLogger('styl');
23 
24  include_once("./Services/Style/classes/class.ilStyleDataSet.php");
25  $this->ds = new ilStyleDataSet();
26  $this->ds->setDSPrefix("ds");
27  $this->ds->setImportDirectory($this->getImportDirectory());
28 
29  $this->log->debug("initialized");
30  }
31 
32  function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
33  {
34  $this->log->debug("import xml ".$a_entity);
35 
36  if (true)
37  {
38  include_once("./Services/DataSet/classes/class.ilDataSetImportParser.php");
39  $parser = new ilDataSetImportParser($a_entity, $this->getSchemaVersion(),
40  $a_xml, $this->ds, $a_mapping);
41  return;
42  }
43 
44  // see ilStyleExporter::getXmlRepresentation()
45  if(preg_match("/<StyleSheetExport><ImagePath>(.+)<\/ImagePath>/", $a_xml, $hits))
46  {
47  $path = $hits[1];
48  $a_xml = str_replace($hits[0], "", $a_xml);
49  $a_xml = str_replace("</StyleSheetExport>", "", $a_xml);
50  }
51 
52  // temp xml-file
53  $tmp_file = $this->getImportDirectory()."/sty_".$a_id.".xml";
54  file_put_contents($tmp_file, $a_xml);
55 
56  include_once "./Services/Style/Content/classes/class.ilObjStyleSheet.php";
57  $style = new ilObjStyleSheet();
58  $style->createFromXMLFile($tmp_file);
59  $new_id = $style->getId();
60 
61  unlink($tmp_file);
62 
63  // images
64  if($path)
65  {
66  $source = $this->getImportDirectory()."/".$path;
67  if(is_dir($source))
68  {
69  $target = $style->getImagesDirectory();
70  if(!is_dir($target))
71  {
73  }
74  ilUtil::rCopy($source, $target);
75  }
76  }
77 
78  $a_mapping->addMapping("Services/Style", "sty", $a_id, $new_id);
79  }
80 }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$path
Definition: aliased.php:25
$style
Definition: example_012.php:70
getSchemaVersion()
Get schema version.
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
getImportDirectory()
Get import directory.
Manifest parser for ILIAS standard export files.
Importer class for style.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
$parser
Definition: BPMN2Parser.php:24
Style Data set class.
Class ilObjStyleSheet.
static getLogger($a_component_id)
Get component logger.
Xml importer class.