You are here

function globallink_interface_get_translated_items in GlobalLink Connect for Drupal 7.6

Same name and namespace in other branches
  1. 7.7 globallink_interface/globallink_interface.inc \globallink_interface_get_translated_items()

Gets translated interfaces from XML data.

Parameters

object $xml: XML representation of interfaces.

Return value

array Array of interfaces.

3 calls to globallink_interface_get_translated_items()
globallink_interface_get_translated in globallink_interface/globallink_interface.inc
Gets number of translated interfaces.
globallink_interface_get_translations_for_row_id in globallink_interface/globallink_interface_receive.inc
Gets interface translations by row ID.
globallink_interface_receive_form in globallink_interface/globallink_interface_receive.inc
Builds form to receive an interface submission.

File

globallink_interface/globallink_interface.inc, line 611

Code

function globallink_interface_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');
  $lid = '';
  foreach ($contents as $content) {
    if (!is_null($content->attributes)) {
      foreach ($content->attributes as $attr_name => $attr_node) {
        if ($attr_name == 'lid') {
          $lid = $attr_node->value;
        }
      }
    }
  }
  if ($lid == '') {
    return array();
  }
  $interface_arr = array();
  $interface_arr['lid'] = $lid;
  $interfaces = $dom
    ->getElementsByTagName('interface');
  foreach ($interfaces as $interface) {
    if (!is_null($interface->attributes)) {
      $i_arr = array();
      foreach ($interface->attributes as $attr_name => $attr_node) {
        $i_arr[$attr_name] = $attr_node->value;
      }
      $i_arr['translation'] = $interface->nodeValue;
      $interface_arr[$i_arr['name']] = $i_arr;
    }
  }
  return $interface_arr;
}