ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
4include_once("./Services/Export/classes/class.ilXmlImporter.php");
5
14{
15 function init()
16 {
17
18 }
19
20 function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
21 {
22 // see ilStyleExporter::getXmlRepresentation()
23 if(preg_match("/<StyleSheetExport><ImagePath>(.+)<\/ImagePath>/", $a_xml, $hits))
24 {
25 $path = $hits[1];
26 $a_xml = str_replace($hits[0], "", $a_xml);
27 $a_xml = str_replace("</StyleSheetExport>", "", $a_xml);
28 }
29
30 // temp xml-file
31 $tmp_file = $this->getImportDirectory()."/sty_".$a_id.".xml";
32 file_put_contents($tmp_file, $a_xml);
33
34 include_once "./Services/Style/classes/class.ilObjStyleSheet.php";
35 $style = new ilObjStyleSheet();
36 $style->createFromXMLFile($tmp_file);
37 $new_id = $style->getId();
38
39 unlink($tmp_file);
40
41 // images
42 if($path)
43 {
44 $source = $this->getImportDirectory()."/".$path;
45 if(is_dir($source))
46 {
47 $target = $style->getImagesDirectory();
48 if(!is_dir($target))
49 {
50 ilUtil::makeDirParents($target);
51 }
52 ilUtil::rCopy($source, $target);
53 }
54 }
55
56 $a_mapping->addMapping("Services/Style", "sty", $a_id, $new_id);
57 }
58}
Class ilObjStyleSheet.
Importer class for style.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import xml representation.
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
Xml importer class.
getImportDirectory()
Get import directory.
$path
Definition: index.php:22