function globallink_get_file_entity_xml in GlobalLink Connect for Drupal 7.7
2 calls to globallink_get_file_entity_xml()
- globallink_file_entity_preview_content in globallink_file_entity/
globallink_file_entity_send.inc - Helper function
- globallink_send_file_entity_for_translations in globallink_file_entity/
globallink_file_entity.inc
File
- globallink_file_entity/
globallink_file_entity.inc, line 75
Code
function globallink_get_file_entity_xml($fid, $path = NULL) {
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = TRUE;
$root = $dom
->createElement('content');
$dom
->appendChild($root);
$id = $dom
->createAttribute('fid');
$id->value = $fid;
$root
->appendChild($id);
$file_entity = entity_load('file', FALSE, array(
'fid' => $fid,
));
if (module_exists('metatag')) {
$lang = entity_language('file', $file_entity[$fid]);
if (isset($file_entity[$fid]->metatags)) {
if (globallink_is_field_configured_for_translation('file', 'file:' . $file_entity[$fid]->type, 'metatags', 'file:' . $file_entity[$fid]->type)) {
if (!empty($file_entity[$fid]->metatags[$lang])) {
$metatags = $file_entity[$fid]->metatags[$lang];
foreach ($metatags as $name => $value) {
if (!empty($value['value']) && !is_array($value['value'])) {
globallink_insert_child_element($dom, $root, 'metatag', $value['value'], array(
'entity_type' => 'file',
'name' => $name,
'label' => 'Metatag - ' . ucwords($name),
));
}
}
}
}
}
}
$fields = globallink_file_entity_get_fields($file_entity[$fid]->type);
$configured_fields = globallink_get_configured_fields_for_file($file_entity[$fid]->type);
foreach ($fields as $field) {
if (empty($file_entity[$fid]->{$field})) {
continue;
}
if (array_key_exists($field, $configured_fields) && $configured_fields[$field]->translatable == 1) {
$field_values = field_get_items('file', $file_entity[$fid], $field);
$field_info = field_info_field($field);
if (is_array($field_values) && !empty($field_values)) {
foreach ($field_values as $delta => $values) {
if ($field_info['type'] == 'link_field') {
globallink_insert_child_element($dom, $root, 'field', $values['title'], array(
'field' => $field,
'delta' => $delta,
));
}
elseif ($field_info['type'] == 'image' && !module_exists('file_entity')) {
if (isset($values['alt'])) {
globallink_insert_child_element($dom, $root, 'field_image', $values['alt'], array(
'field_name' => $field,
'type' => 'alt',
'delta' => $delta,
));
}
if (isset($values['title'])) {
globallink_insert_child_element($dom, $root, 'field_image', $values['title'], array(
'field_name' => $field,
'type' => 'title',
'delta' => $delta,
));
}
}
elseif ($field_info['type'] == 'image' && module_exists('file_entity')) {
$parent_info = field_info_instance('file', $field, $file_entity->type);
$file_entity_info = field_info_field($field);
$file_fields = field_info_instances('file', $file_entity_info['type']);
foreach ($file_fields as $file_field) {
$f_value = field_get_items('file', (object) $values, $file_field['field_name']);
if (empty($f_value)) {
continue;
}
globallink_insert_child_element($dom, $root, 'field_image', $f_value[0]['value'], array(
'field_name' => $field,
'subfield' => $file_field['field_name'],
'delta' => $delta,
'label' => $parent_info['label'],
'subfield_label' => $file_field['label'],
));
}
}
elseif (!empty($values['value'])) {
globallink_insert_child_element($dom, $root, 'field', $values['value'], array(
'field' => $field,
'delta' => $delta,
));
}
}
}
elseif (!empty($field_values) && is_string($field_values)) {
globallink_insert_child_element($dom, $root, 'field', $field_values, array(
'field' => $field,
));
}
}
}
$xml = $dom
->saveXML();
return $xml;
}