function globallink_generate_xml_document in GlobalLink Connect for Drupal 7.7
Same name and namespace in other branches
- 7.5 globallink_node.inc \globallink_generate_xml_document()
- 7.6 globallink_node.inc \globallink_generate_xml_document()
Builds XML document with translation data.
Parameters
object $node: The node data.
string $target_arr: Array of locales node is being translated into.
int $tnid: The node id for existing translations.
int $tvid: The node vid for existing translations.
string $name: The xml document name.
bool $for_display: Indicate for display purposes only.
Return value
string The translation XML data.
2 calls to globallink_generate_xml_document()
- globallink_get_xml in ./
globallink_node.inc - Retrieves translation XML data.
- globallink_preview_content in ./
globallink_send_translations.inc
File
- ./
globallink_node.inc, line 1184
Code
function globallink_generate_xml_document($node, $target_arr, $tnid = NULL, $tvid = NULL, $for_display = FALSE) {
$is_hook_enabled = variable_get('globallink_implementation_type', 0);
try {
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = TRUE;
$root = $dom
->createElement('content');
$nid = $dom
->createAttribute('nid');
if ($tnid != NULL) {
$nid->value = $tnid;
}
else {
$nid->value = $node->nid;
}
$root
->appendChild($nid);
$vid = $dom
->createAttribute('vid');
if ($tvid != NULL) {
$vid->value = $tvid;
}
else {
$vid->value = $node->vid;
}
$root
->appendChild($vid);
$url = $dom
->createAttribute('pageUrl');
if (isset($node->path) && isset($node->path['source'])) {
$url->value = url($node->path['source'], array(
'absolute' => TRUE,
));
}
else {
$url->value = url('node/' . $node->nid, array(
'absolute' => TRUE,
));
}
$root
->appendChild($url);
$dom
->appendChild($root);
if ($for_display) {
globallink_insert_child_element($dom, $root, 'title', $node->title);
}
elseif (globallink_is_field_configured_for_translation(GLOBALLINK_ENTITY_TYPE_NODE, $node->type, 'title', $node->type) && $is_hook_enabled == 0) {
globallink_insert_child_element($dom, $root, 'title', $node->title);
}
elseif ($is_hook_enabled == 1) {
if (globallink_is_field_translatable($node, 'title', $target_arr)) {
globallink_insert_child_element($dom, $root, 'title', $node->title);
}
}
$path = path_load('node/' . $node->nid);
if (!empty($path)) {
globallink_insert_child_element($dom, $root, 'path', $path['alias']);
}
$field_arr = field_info_instances(GLOBALLINK_ENTITY_TYPE_NODE, $node->type);
$keys = array_keys($field_arr);
foreach ($keys as $field) {
$field_def = field_read_field($field);
$langcode = field_language(GLOBALLINK_ENTITY_TYPE_NODE, $node, $field, NULL);
$items = field_get_items(GLOBALLINK_ENTITY_TYPE_NODE, $node, $field, $langcode);
if ($items) {
$parent_fc = '';
if ($field_def['type'] == 'field_collection') {
$parent_fc = $field;
if (isset($items[0]['revision_id'])) {
$field_collection_item_entity = entity_load('field_collection_item', array(
$items[0]['value'],
), array(
'revision_id' => $items[0]['revision_id'],
));
}
}
globallink_traverse_fields_and_field_collections(GLOBALLINK_ENTITY_TYPE_NODE, $node->type, $parent_fc, $node->type, $node->nid, $items, $field, $dom, $root, $node, $target_arr, $is_hook_enabled, $langcode);
}
}
if (module_exists('metatag')) {
if (isset($node->metatags)) {
$ignore_metatags = [
'geo.position',
'icbm',
'rating',
'referrer',
'revisit-after',
'content-language',
];
if ($for_display) {
if (!empty($node->metatags[$node->language])) {
// Langage of the node to access the metatags.
$metatags = $node->metatags[$node->language];
foreach ($metatags as $name => $value) {
if (isset($value['value']) && !is_array($value['value'])) {
if (in_array($name, $ignore_metatags)) {
continue;
}
globallink_insert_child_element($dom, $root, 'metatag', $value['value'], array(
'entity_type' => GLOBALLINK_ENTITY_TYPE_NODE,
'name' => $name,
'label' => 'Metatag - ' . ucwords($name),
));
}
}
}
}
elseif (globallink_is_field_configured_for_translation(GLOBALLINK_ENTITY_TYPE_NODE, $node->type, 'metatags', $node->type)) {
if (!empty($node->metatags[$node->language])) {
// Langage of the node to access the metatags.
$metatags = $node->metatags[$node->language];
foreach ($metatags as $name => $value) {
if (isset($value['value']) && !is_array($value['value'])) {
if (in_array($name, $ignore_metatags)) {
continue;
}
globallink_insert_child_element($dom, $root, 'metatag', $value['value'], array(
'entity_type' => GLOBALLINK_ENTITY_TYPE_NODE,
'name' => $name,
'label' => 'Metatag - ' . ucwords($name),
));
}
}
}
}
}
}
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
throw $e;
}
$root_element = $dom
->getElementsByTagName('content')
->item(0);
if (!$root_element
->hasChildNodes()) {
return FALSE;
}
return $dom
->saveXML();
}