merge.php 1.46 KB
Newer Older
Orbmancer's avatar
Orbmancer committed
1
2
3
4
5
6
7
8
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

require_once 'model/Data.class.php';
require_once 'model/Tabs.class.php';

9
$td = $_POST['td'];
Orbmancer's avatar
Orbmancer committed
10
11
12

$levels = Data::loadXML($td);

Erwan Normand's avatar
Doc  
Erwan Normand committed
13
// Create the merged level
Erwan Normand's avatar
Erwan Normand committed
14
15
$finalTabs = new Tabs();
$finalTabs->fillBlank();
Orbmancer's avatar
Orbmancer committed
16
17
18

foreach($levels as $level){
    $myContent = new Tabs();
Orbmancer's avatar
Orbmancer committed
19
    $myContent->importXML($level['data']);
20
    $finalTabs->setTab($myContent->getTab(), $level['x'], $level['y']);
Orbmancer's avatar
Orbmancer committed
21
22
}

23
24
$rawExport = $finalTabs->toString();

Erwan Normand's avatar
Doc  
Erwan Normand committed
25
// Create the XML file
Erwan Normand's avatar
Erwan Normand committed
26
$finalFile = simplexml_load_file('data/level_layout.vvvvvv');
27
28
29
30
31
32
33
34
35
36
37
38
39
$finalFile->Data->contents = $rawExport['content'];


//$finalFile->Data->edEntities = $rawExport['edEntities']; //doesn't work

if(!empty($rawExport['edEntities']))
    foreach($rawExport['edEntities'] as $key => $value){
        $child = $finalFile->Data->edEntities->addChild('edentity', $value);

        foreach($value->attributes() as $k => $v){
            $child->addAttribute($k, $v);
        }
    }
Erwan Normand's avatar
Erwan Normand committed
40

Orbmancer's avatar
Orbmancer committed
41
42
43
44
45
46
47
48
49
50
$dom_sxe = dom_import_simplexml($finalFile);
if (!$dom_sxe) {
    echo 'Erreur lors de la conversion du XML';
    exit;
}

$dom = new DOMDocument('1.0');
$dom_sxe = $dom->importNode($dom_sxe, true);
$dom_sxe = $dom->appendChild($dom_sxe);

Erwan Normand's avatar
Doc  
Erwan Normand committed
51
// Download the XML file
Erwan Normand's avatar
Erwan Normand committed
52
header('Content-type: text/xml');
Orbmancer's avatar
Orbmancer committed
53
header('Content-Disposition: attachment; filename=VVVVVV_level_merged.vvvvvv');
Erwan Normand's avatar
Erwan Normand committed
54
55
56
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
Orbmancer's avatar
Orbmancer committed
57
print($dom->saveXML(null, LIBXML_NOEMPTYTAG));