function globallink_beans_get_translated_array in GlobalLink Connect for Drupal 7.6
Same name and namespace in other branches
- 7.7 globallink_beans/globallink_beans.inc \globallink_beans_get_translated_array()
Gets array of translated beans.
Parameters
object $xml: XML representation of beans.
Return value
array Associative array of translated beans.
2 calls to globallink_beans_get_translated_array()
- globallink_beans_get_translated in globallink_beans/
globallink_beans.inc - Gets number of translated beans.
- globallink_beans_get_translations_for_row_id in globallink_beans/
globallink_beans_receive.inc - Gets beans translations by row ID.
File
- globallink_beans/
globallink_beans.inc, line 1237
Code
function globallink_beans_get_translated_array($xml) {
if (is_null($xml) || !is_string($xml) || $xml == '') {
return array();
}
$dom = new DomDocument();
$dom->preserveWhiteSpace = FALSE;
$dom
->loadXML($xml);
$arr = array();
$titles = $dom
->getElementsByTagName('title');
foreach ($titles as $title) {
$arr['title'] = $title->nodeValue;
}
$contents = $dom
->getElementsByTagName('content');
$bnid = '';
foreach ($contents as $content) {
if (!is_null($content->attributes)) {
foreach ($content->attributes as $attr_name => $attr_node) {
if ($attr_name == 'bid') {
$bnid = $attr_node->value;
}
}
}
}
if ($bnid == '') {
return array();
}
$arr['object_id'] = $bnid;
$field_image = $dom
->getElementsByTagName('field_image');
foreach ($field_image as $attr) {
$field_image_object = new GLFieldImage();
if (!is_null($attr->attributes)) {
foreach ($attr->attributes as $attr_name => $attr_node) {
switch ($attr_name) {
case 'type':
if ($attr_node->value == 'title') {
$field_image_object->title = $attr->nodeValue;
}
elseif ($attr_node->value == 'alt') {
$field_image_object->alt = $attr->nodeValue;
}
continue 2;
case 'delta':
$field_image_object->delta = $attr_node->value;
continue 2;
case 'field_name':
$field_image_object->field_name = $attr_node->value;
continue 2;
case 'subfield':
$field_image_object->subfield = $attr_node->value;
$field_image_object->{$field_image_object->subfield} = $attr->nodeValue;
$field_image_object->type = 'file_entity';
continue 2;
case 'langcode':
$field_image_object->langcode = $attr_node->value;
case 'label':
case 'subfield_label':
$field_image_object->{$attr_name} = $attr_node->value;
continue 2;
}
}
if (is_null($field_image_object->delta)) {
$field_image_object->delta = '0';
}
if (isset($field_image_object->field_name)) {
if (!isset($arr[$field_image_object->field_name][$field_image_object->langcode][$field_image_object->delta])) {
$arr[$field_image_object->field_name][$field_image_object->langcode][$field_image_object->delta] = new GLFieldImage();
}
if (isset($field_image_object->title)) {
$arr[$field_image_object->field_name][$field_image_object->langcode][$field_image_object->delta]->title = $field_image_object->title;
}
if (isset($field_image_object->alt)) {
$arr[$field_image_object->field_name][$field_image_object->langcode][$field_image_object->delta]->alt = $field_image_object->alt;
}
}
else {
$arr[$field_image_object->field_name][$field_image_object->langcode][$field_image_object->delta] = $field_image_object;
}
}
}
$fields = $dom
->getElementsByTagName('field');
foreach ($fields as $field) {
$field_obj = new GLField();
$field_obj->type = 'field';
$field_obj->translatedContent = $field->nodeValue;
if (is_null($field->attributes)) {
continue;
}
foreach ($field->attributes as $attr_name => $attr_node) {
switch ($attr_name) {
case 'field_name':
$field_obj->fieldName = $attr_node->value;
continue 2;
case 'delta':
$field_obj->delta = $attr_node->value;
continue 2;
case 'langcode':
$field_obj->langcode = $attr_node->value;
continue 2;
case 'parent_fc':
$field_obj->parentFCName = $attr_node->value;
continue 2;
case 'bundle':
$field_obj->bundle = $attr_node->value;
continue 2;
case 'entity_id':
$field_obj->entityId = $attr_node->value;
continue 2;
case 'entity_type':
$field_obj->entityType = $attr_node->value;
continue 2;
}
}
if (is_null($field_obj->langcode)) {
$field_obj->langcode = LANGUAGE_NONE;
}
if (is_null($field_obj->delta)) {
$field_obj->delta = '0';
}
if ($field_obj->entityType == 'field_collection_item') {
$arr['field_collection'][$field_obj->parentFCName][$field_obj->bundle][$field_obj->entityId][$field_obj->fieldName][$field_obj->langcode][$field_obj->delta] = $field_obj;
}
else {
$arr[$field_obj->fieldName][$field_obj->langcode][$field_obj->delta] = $field_obj;
}
}
$metatags = $dom
->getElementsByTagName('metatag');
foreach ($metatags as $metatag) {
$metatag_obj = new GLField();
$metatag_obj->type = 'metatag';
$metatag_obj->translatedContent = $metatag->nodeValue;
if (is_null($metatag->attributes)) {
continue;
}
foreach ($metatag->attributes as $attr_name => $attr_node) {
switch ($attr_name) {
case 'entity_type':
$metatag_obj->entityType = $attr_node->value;
continue 2;
case 'content_type':
$field_obj->contentType = $attr_node->value;
continue 2;
case 'bundle':
$field_obj->bundle = $attr_node->value;
continue 2;
case 'entity_id':
$metatag_obj->entityId = $attr_node->value;
continue 2;
case 'name':
$metatag_obj->fieldName = $attr_node->value;
continue 2;
case 'label':
$metatag_obj->fieldLabel = $attr_node->value;
continue 2;
}
}
if (is_null($metatag_obj->entityId)) {
$metatag_obj->entityId = '0';
}
if (is_null($metatag_obj->bundle)) {
$metatag_obj->bundle = $metatag_obj->fieldName;
}
$arr['metatag'][$metatag_obj->bundle][$metatag_obj->entityId] = $metatag_obj;
}
return $arr;
}