function _patterns_rearrange_data in Patterns 6.2
Same name and namespace in other branches
- 5 patterns.module \_patterns_rearrange_data()
- 6 patterns.module \_patterns_rearrange_data()
1 call to _patterns_rearrange_data()
File
- ./
patterns.module, line 2041 - Enables extremely simple adding/removing features to your site with minimal to no configuration
Code
function _patterns_rearrange_data($data, $parent = '') {
$numeric = array();
$count = 0;
foreach ($data as $key => $value) {
if (isset($value['value'])) {
if ($value['value'] == 'false') {
$value['value'] = false;
}
else {
if ($value['value'] == 'true') {
$value['value'] = true;
}
}
}
if (is_numeric($key) && is_array($value) && count($value) == 2 && isset($value['tag']) && isset($value['value'])) {
unset($data[$key]);
if (isset($data[$value['tag']])) {
$numeric[] = $value['tag'];
$data[$count++] = $data[$value['tag']];
$data[$count++] = $value['value'];
unset($data[$value['tag']]);
}
else {
if (in_array($value['tag'], $numeric)) {
$data[$count++] = $value['value'];
}
else {
$data[$value['tag']] = $value['value'];
}
}
}
else {
if (is_numeric($key)) {
$tag = $value['tag'];
unset($value['tag']);
$data[$tag][] = _patterns_rearrange_data($value, $tag);
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;
}