You are here

function globallink_taxonomy_get_translated_items in GlobalLink Connect for Drupal 7.7

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

Gets translated taxonomies from XML data.

Parameters

object $xml: XML representation of taxonomies.

Return value

array Array of taxonomies.

1 call to globallink_taxonomy_get_translated_items()
globallink_taxonomy_import in globallink_taxonomy/globallink_taxonomy.inc

File

globallink_taxonomy/globallink_taxonomy.inc, line 620

Code

function globallink_taxonomy_get_translated_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;
  $taxonomies = $dom
    ->getElementsByTagName(GLOBALLINK_ENTITY_TYPE_TAXONOMY);
  foreach ($taxonomies as $taxonomy) {
    if (!is_null($taxonomy->attributes)) {
      $b_arr = array();
      foreach ($taxonomy->attributes as $attr_name => $attr_node) {
        $b_arr[$attr_name] = $attr_node->value;
      }
      $b_arr['translation'] = $taxonomy->nodeValue;
      $taxonomy_arr[$b_arr['name']] = $b_arr;
    }
  }
  $fields = $dom
    ->getElementsByTagName('field');
  foreach ($fields as $field) {
    $field_object = new GLField();
    $field_object->type = 'field';
    $field_object->translatedContent = $field->nodeValue;
    if (!is_null($field->attributes)) {
      foreach ($field->attributes as $attr_name => $attr_node) {
        switch ($attr_name) {
          case 'field':
            $field_object->fieldName = $attr_node->value;
            continue 2;
          case 'delta':
            $field_object->delta = $attr_node->value;
            continue 2;
          case 'langcode':
            $field_object->langcode = $attr_node->value;
            continue 2;
        }
      }
      if (is_null($field_object->langcode)) {
        $field_object->langcode = LANGUAGE_NONE;
      }
      if (is_null($field_object->delta)) {
        $field_object->delta = '0';
      }
      $taxonomy_arr[$field_object->fieldName][$field_object->langcode][$field_object->delta] = $field_object;
    }
  }
  $metatags = $dom
    ->getElementsByTagName('metatag');
  foreach ($metatags as $metatag) {
    $metatag_object = new GLField();
    $metatag_object->type = 'metatag';
    $metatag_object->translatedContent = $metatag->nodeValue;
    if (!is_null($metatag->attributes)) {
      foreach ($metatag->attributes as $attr_name => $attr_node) {
        switch ($attr_name) {
          case 'field':
            $metatag_object->fieldName = $attr_node->value;
            continue 2;
          case 'delta':
            $metatag_object->delta = $attr_node->value;
            continue 2;
          case 'langcode':
            $metatag_object->langcode = $attr_node->value;
            continue 2;
          case 'label':
            $metatag_object->fieldLabel = $attr_node->value;
            continue 2;
        }
      }
      if (is_null($metatag_object->delta)) {
        $metatag_object->entityId = '0';
      }
      if (is_null($metatag_object->langcode)) {
        $metatag_object->langcode = LANGUAGE_NONE;
      }
    }
    $taxonomy_arr['metatags'][$metatag_object->fieldName][$metatag_object->langcode] = $metatag_object;
  }
  return $taxonomy_arr;
}