You are here

function globallink_taxonomy_get_arr_items in GlobalLink Connect for Drupal 7.5

Same name and namespace in other branches
  1. 7.6 globallink_taxonomy/globallink_taxonomy.inc \globallink_taxonomy_get_arr_items()

Gets array of taxonomies from XML data.

Parameters

object $xml: The XML data.

Return value

array Array of taxonomies.

1 call to globallink_taxonomy_get_arr_items()
globallink_taxonomy_get_translations_for_row_id in globallink_taxonomy/globallink_taxonomy_receive.inc
Gets taxonomy translations by row ID.

File

globallink_taxonomy/globallink_taxonomy.inc, line 1051

Code

function globallink_taxonomy_get_arr_items($xml) {
  if (is_null($xml) || !is_string($xml) || $xml == '') {
    return array();
  }
  $dom = new DomDocument();
  $dom->preserveWhiteSpace = FALSE;
  $dom
    ->loadXML($xml);
  $contents = $dom
    ->getElementsByTagName('content');
  $bid = '';
  foreach ($contents as $content) {
    if (!is_null($content->attributes)) {
      foreach ($content->attributes as $attr_name => $attr_node) {
        if ($attr_name == 'bid') {
          $bid = $attr_node->value;
        }
      }
    }
  }
  if ($bid == '') {
    return array();
  }
  $taxonomy_arr = array();
  $taxonomy_arr['bid'] = $bid;
  $blocks = $dom
    ->getElementsByTagName('taxonomy');
  foreach ($blocks as $block) {
    if (!is_null($block->attributes)) {
      $b_arr = array();
      foreach ($block->attributes as $attr_name => $attr_node) {
        $b_arr[$attr_name] = $attr_node->value;
      }
      $b_arr['translation'] = $block->nodeValue;
      $taxonomy_arr[$b_arr['name']] = $b_arr;
    }
  }
  $t_fields = $dom
    ->getElementsByTagName('field');
  foreach ($t_fields as $t_field) {
    $fieldObject = new GLField();
    $fieldObject->type = 'field';
    $fieldObject->translatedContent = $t_field->nodeValue;
    if (!is_null($t_field->attributes)) {
      foreach ($t_field->attributes as $attrName => $attrNode) {
        switch ($attrName) {
          case 'field':
            $fieldObject->fieldName = $attrNode->value;
            continue 2;
          case 'delta':
            $fieldObject->delta = $attrNode->value;
            continue 2;
          case 'langcode':
            $fieldObject->langcode = $attrNode->value;
            continue 2;
          case 'label':
            $fieldObject->fieldLabel = $attrNode->value;
            continue 2;
          case 'parent_fc':
            $fieldObject->parentFCName = $attrNode->value;
            continue 2;
          case 'bundle':
            $fieldObject->bundle = $attrNode->value;
            continue 2;
          case 'entity_id':
            $fieldObject->entityId = $attrNode->value;
            continue 2;
          case 'entity_type':
            $fieldObject->entityType = $attrNode->value;
            continue 2;
          case 'content_type':
            $fieldObject->contentType = $attrNode->value;
            continue 2;
        }
      }
      if (is_null($fieldObject->langcode)) {
        $fieldObject->langcode = LANGUAGE_NONE;
      }
      if (is_null($fieldObject->delta)) {
        $fieldObject->delta = '0';
      }
    }
    $taxonomy_arr[$fieldObject->fieldName][$fieldObject->langcode][$fieldObject->delta] = $fieldObject;
  }
  $t_metatags = $dom
    ->getElementsByTagName('metatag');
  foreach ($t_metatags as $t_metatag) {
    $fieldObject = new GLField();
    $fieldObject->type = 'metatag';
    $fieldObject->translatedContent = $t_metatag->nodeValue;
    if (!is_null($t_metatag->attributes)) {
      foreach ($t_metatag->attributes as $attrName => $attrNode) {
        switch ($attrName) {
          case 'field':
            $fieldObject->fieldName = $attrNode->value;
            continue 2;
          case 'delta':
            $fieldObject->delta = $attrNode->value;
            continue 2;
          case 'langcode':
            $fieldObject->langcode = $attrNode->value;
            continue 2;
          case 'label':
            $fieldObject->fieldLabel = $attrNode->value;
            continue 2;
        }
      }
      if (is_null($fieldObject->langcode)) {
        $fieldObject->langcode = LANGUAGE_NONE;
      }
      if (is_null($fieldObject->delta)) {
        $fieldObject->delta = '0';
      }
    }
    $taxonomy_arr['metatags'][$fieldObject->fieldName][$fieldObject->langcode] = $fieldObject;
  }
  return $taxonomy_arr;
}