You are here

function globallink_block_get_arr_items in GlobalLink Connect for Drupal 7.6

Same name and namespace in other branches
  1. 7.5 globallink_block/globallink_block.inc \globallink_block_get_arr_items()

Gets array of blocks from XML data.

Parameters

object $xml: The XML data.

Return value

array Array of blocks.

1 call to globallink_block_get_arr_items()
globallink_block_get_translations_for_row_id in globallink_block/globallink_block_receive.inc
Gets block translations by row ID.

File

globallink_block/globallink_block.inc, line 779

Code

function globallink_block_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();
  }
  $block_arr = array();
  $block_arr['bid'] = $bid;
  $blocks = $dom
    ->getElementsByTagName('block');
  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;
      }
      $block_arr[$b_arr['name']] = $block->nodeValue;
    }
  }
  return $block_arr;
}