function _patterns_parse_tag in Patterns 6
Same name and namespace in other branches
- 5 patterns.module \_patterns_parse_tag()
- 6.2 patterns.module \_patterns_parse_tag()
Recurse through the values of a parsed xml file to create a multi-dimensional representation of the data.
1 call to _patterns_parse_tag()
- patterns_from_source in ./
patterns.module - Create a pattern from an XML data source
File
- ./
patterns.module, line 1220 - Enables extremely simple adding/removing features to your site with minimal to no configuration
Code
function _patterns_parse_tag($data, &$index = 0) {
$pattern = array();
while (isset($data[$index]) && ($current = $data[$index])) {
$type = $current['type'];
if (!empty($current['attributes'])) {
foreach ((array) $current['attributes'] as $key => $value) {
$current[$key] = $value;
}
}
unset($current['type'], $current['level'], $current['attributes']);
if (isset($current['value']) && !trim($current['value']) && $current['value'] != "0") {
unset($current['value']);
}
switch ($type) {
case 'open':
$index++;
$current += _patterns_parse_tag($data, $index);
$pattern[] = $current;
break;
case 'close':
$index++;
return $pattern;
break;
case 'complete':
// In order to support more complex/non-standard features we can use serialized data
if (!empty($current['attributes']['serialized'])) {
$value = unserialize($current['value']);
if (isset($value)) {
$current['value'] = $value;
}
}
// If no value was specified, make sure an empty value is there
if (!isset($current['value'])) {
$current['value'] = '';
}
$pattern[] = $current;
break;
}
$index++;
}
return $pattern;
}