You are here

function globallink_block_get_translated_items in GlobalLink Connect for Drupal 7.6

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

Gets translated blocks.

Parameters

object $xml: XML representation of blocks.

Return value

array Array of blocks.

2 calls to globallink_block_get_translated_items()
globallink_block_get_translated_blocks in globallink_block/globallink_block.inc
Gets number of translated blocks.
globallink_block_receive_form in globallink_block/globallink_block_receive.inc
Builds form to receive a block submission.

File

globallink_block/globallink_block.inc, line 574

Code

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