function atomrdf_custom_copy in Feeds Atom 7
Same name and namespace in other branches
- 6 libraries/atomrdf_parser.inc \atomrdf_custom_copy()
1 call to atomrdf_custom_copy()
- atomrdf_parse in libraries/
atomrdf_parser.inc - Parse AtomRDF format - for example:
File
- libraries/
atomrdf_parser.inc, line 334 - Contains the atomrd parsing functions.
Code
function atomrdf_custom_copy($xml) {
$blob = array();
foreach ($xml
->children() as $xml_child) {
$key = $xml_child
->getName();
if ($key == "field") {
foreach ($xml_child
->children() as $language) {
$language_attributes = $language
->attributes();
if (!empty($language_attributes['name'])) {
// The name 'field-instance' has a dash in it! So we are trying to get it without referring to it.
// @todo This can easily be done with the xpath() method, or with $xml_child->{'field-instance'}
$i = 0;
$values = array();
// Each field instance is a value of possible multi values
foreach ($language
->children() as $field_instance) {
$values[$i] = array();
// each column makes up information for the value
foreach ($field_instance
->children() as $column) {
$attributes = $column
->attributes();
if (!empty($attributes['name'])) {
$name = (string) $attributes['name'];
$value = (string) $column;
if (!empty($attributes['serialize'])) {
$value = unserialize($value);
}
$values[$i][$name] = $value;
}
}
$i++;
}
$key = "{$xml_child['name']}";
$blob[$key][(string) $language_attributes['name']] = $values;
}
}
$blob[$key]['#attributes'] = array(
'type' => (string) $xml_child['type'],
);
}
elseif ($key == "properties") {
// Save properties from the properties block
foreach ($xml_child
->children() as $property) {
$key = "{$property->getName()}";
$value = "{$property}";
$blob[$key] = $value;
}
}
elseif ($key == 'taxonomy') {
foreach ($xml_child
->children() as $term) {
$values = array();
foreach ($term as $data_type => $value) {
$values[$data_type] = "{$value}";
}
$blob[$key][] = $values;
}
}
else {
// There are some 'naked' properties that are not inside of the properties or fields block - save those.
$value = "{$xml_child}";
$blob[$key] = $value;
}
}
// Invokes hook_feeds_atom_atomrdf_parser_alter().
drupal_alter('feeds_atom_atomrdf_parser', $blob, $xml);
return $blob;
}