You are here

function exif_custom_xml_recursion in EXIF Custom 7

Parameters

object $obj:

array $fields:

string name:

Return value

array

1 call to exif_custom_xml_recursion()
exif_custom_get_xmp in ./exif_custom.module

File

./exif_custom.module, line 462
Primary hook implementations for EXIF Custom.

Code

function exif_custom_xml_recursion($obj, array &$fields, $name) {
  $namespace = $obj
    ->getDocNamespaces(TRUE);
  $namespace[NULL] = NULL;
  $children = array();
  $attributes = array();
  $text = trim((string) $obj);
  if (strlen($text) === 0) {
    $text = NULL;
  }
  if (strtolower((string) $obj
    ->getName()) == "bag") {

    // @todo Add support for bags of objects other than just text?
    $childValues = array();
    $objChildren = $obj
      ->children("rdf", TRUE);
    foreach ($objChildren as $child) {
      $childValues[] = trim((string) $child);
    }
    if (count($childValues) > 0) {
      $fields[$name] = $childValues;
    }
  }
  else {
    $name = $name . ':' . strtolower((string) $obj
      ->getName());

    // Get info for all namespaces.
    if (is_object($obj)) {
      foreach ($namespace as $ns => $nsUrl) {

        // Attributes.
        $objAttributes = $obj
          ->attributes($ns, TRUE);
        foreach ($objAttributes as $attributeName => $attributeValue) {
          $attribName = strtolower(trim((string) $attributeName));
          $attribVal = trim((string) $attributeValue);
          if (!empty($ns)) {
            $attribName = $ns . ':' . $attribName;
          }
          $attributes[$attribName] = $attribVal;
        }

        // Children.
        $objChildren = $obj
          ->children($ns, TRUE);
        foreach ($objChildren as $childName => $child) {
          $childName = strtolower((string) $childName);
          if (!empty($ns)) {
            $childName = $ns . ':' . $childName;
          }
          $children[$childName][] = exif_custom_xml_recursion($child, $fields, $name);
        }
      }
    }
    if (!is_null($text)) {
      $fields[$name] = $text;
    }
  }
  return array(
    'name' => $name,
    'text' => html_entity_decode($text),
    'attributes' => $attributes,
    'children' => $children,
  );
}