You are here

function globallink_menu_get_translated_items in GlobalLink Connect for Drupal 7.5

Same name and namespace in other branches
  1. 7.7 globallink_menu/globallink_menu.inc \globallink_menu_get_translated_items()
  2. 7.6 globallink_menu/globallink_menu.inc \globallink_menu_get_translated_items()

Gets translated menu items from XML data.

Parameters

object $xml: XML representation of menu items.

Return value

array Array of menu items.

2 calls to globallink_menu_get_translated_items()
globallink_menu_get_translated in globallink_menu/globallink_menu.inc
Gets number of translated menus.
globallink_menu_get_translations_for_row_id in globallink_menu/globallink_menu_receive.inc
Gets menu translations by row ID.

File

globallink_menu/globallink_menu.inc, line 682

Code

function globallink_menu_get_translated_items($xml) {
  if (is_null($xml) || !is_string($xml) || $xml == '') {
    return array();
  }
  $dom = new DomDocument();
  $dom->preserveWhiteSpace = FALSE;
  $dom
    ->loadXML($xml);
  $arr = array();
  $contents = $dom
    ->getElementsByTagName('content');
  $mlid = '';
  foreach ($contents as $content) {
    if (is_null($content->attributes)) {
      continue;
    }
    foreach ($content->attributes as $attr_name => $attr_node) {
      if ($attr_name == 'mlid') {
        $mlid = $attr_node->value;
      }
    }
  }
  if ($mlid == '') {
    return array();
  }
  $arr['mlid'] = $mlid;
  $menus = $dom
    ->getElementsByTagName('menu');
  foreach ($menus as $menu) {
    $type = '';
    foreach ($menu->attributes as $attr_name => $attr_node) {
      if ($attr_name == 'name') {
        $type = $attr_node->value;
      }
    }
    $arr[$type] = $menu->nodeValue;
  }
  return $arr;
}