comparison sites/all/libraries/ARC2/arc/serializers/ARC2_LegacyXMLSerializer.php @ 4:ce11bbd8f642

added modules
author danieleb <danielebarchiesi@me.com>
date Thu, 19 Sep 2013 10:38:44 +0100
parents
children
comparison
equal deleted inserted replaced
3:b28be78d8160 4:ce11bbd8f642
1 <?php
2 /*
3 homepage: http://arc.semsol.org/
4 license: http://arc.semsol.org/license
5
6 class: ARC2 Legacy XML Serializer
7 author: Benjamin Nowack
8 version: 2010-11-16
9 */
10
11 ARC2::inc('Class');
12
13 class ARC2_LegacyXMLSerializer extends ARC2_Class {
14
15 function __construct($a, &$caller) {
16 parent::__construct($a, $caller);
17 }
18
19 function __init() {
20 parent::__init();
21 $this->content_header = 'text/xml';
22 }
23
24 /* */
25
26 function getSerializedArray($struct, $root = 1, $ind = ' ') {
27 $n = "\n";
28 $r = '';
29 $is_flat = $this->isAssociativeArray($struct) ? 0 : 1;
30 foreach ($struct as $k => $v) {
31 $tag = $is_flat ? 'item' : preg_replace('/[\s]/s', '_', $k);
32 $tag = preg_replace('/^.*([a-z0-9\-\_]+)$/Uis', '\\1', $tag);
33 $r .= $n . $ind . '<' . $tag . '>' . (is_array($v) ? $this->getSerializedArray($v, 0, $ind . ' ') . $n . $ind : htmlspecialchars($v)) . '</' . $tag . '>';
34 }
35 if ($root) $r = $this->getHead() . $r . $this->getFooter();
36 return $r;
37 }
38
39 /* */
40
41 function getHead() {
42 $n = "\n";
43 $r = '<?xml version="1.0"?>';
44 $r .= $n . '<items>';
45 return $r;
46 }
47
48 function getFooter() {
49 $n = "\n";
50 $r = $n . '</items>';
51 return $r;
52 }
53
54 /* */
55
56 function isAssociativeArray($v) {
57 foreach (array_keys($v) as $k => $val) {
58 if ($k !== $val) return 1;
59 }
60 return 0;
61 }
62
63 /* */
64
65 }
66