function _patterns_xmlparser_rearrange_data in Patterns 7.2
Same name and namespace in other branches
- 7 patterns_xmlparser/patterns_xmlparser.module \_patterns_xmlparser_rearrange_data()
2 calls to _patterns_xmlparser_rearrange_data()
- patterns_xmlparser_rearrange_data in patterns_xmlparser/
patterns_xmlparser.module - _patterns_xmlparser_process_action in patterns_xmlparser/
patterns_xmlparser.module
File
- patterns_xmlparser/
patterns_xmlparser.module, line 192
Code
function _patterns_xmlparser_rearrange_data($data, $parent = '') {
foreach ($data as $key => $value) {
if (isset($value['value'])) {
if ($value['value'] == 'false') {
$value['value'] = FALSE;
}
elseif ($value['value'] == 'true') {
$value['value'] = TRUE;
}
}
if (is_numeric($key) && is_array($value) && count($value) == 2 && isset($value['xml_tag']) && isset($value['value'])) {
unset($data[$key]);
if (isset($data[$value['xml_tag']])) {
if (!is_array($data[$value['xml_tag']])) {
$val = $data[$value['xml_tag']];
$data[$value['xml_tag']] = array();
$data[$value['xml_tag']][] = $val;
}
$data[$value['xml_tag']][] = $value['value'];
}
else {
$data[$value['xml_tag']] = $value['value'];
}
}
elseif (is_numeric($key)) {
$tag = $value['xml_tag'];
unset($value['xml_tag']);
$value = _patterns_xmlparser_rearrange_data($value, $tag);
if (isset($value['value'])) {
// debug($value);
// }
// else {
$data[$tag] = $value['value'];
}
unset($data[$key]);
}
}
foreach ($data as $key => $value) {
if (is_array($value) && count($value) == 1 && $value[0]) {
$data[$key] = $data[$key][0];
}
}
// This workaround enables us to define numeric keys in XML by
// prefixing the number with single character. E.g <n0>value</n0>
// will result in 0 => 'value' (first character of the key will be removed).
if (isset($data['_numeric_keys'])) {
unset($data['_numeric_keys']);
foreach ($data as $key => $value) {
$data[substr($key, 1)] = $value;
unset($data[$key]);
}
}
return $data;
}