You are here

function lingotek_download_document in Lingotek Translation 6

Same name and namespace in other branches
  1. 7.2 lingotek.api.inc \lingotek_download_document()
  2. 7.3 lingotek.api.inc \lingotek_download_document()
  3. 7.4 lingotek.api.inc \lingotek_download_document()
3 calls to lingotek_download_document()
lingotek_node_view in ./lingotek.module
lingotek_update in ./lingotek.page.inc
lingotek_update_nodes in ./lingotek.sync.inc

File

./lingotek.api.inc, line 34

Code

function lingotek_download_document($source_node, $target_node, $save = TRUE) {
  global $_lingotek_client, $_lingotek_locale;
  $document_id = lingotek_lingonode($source_node->nid, 'document_id');
  $target_language = $_lingotek_locale[$target_node->language];
  $params = array(
    'documentId' => $document_id,
    'targetLanguage' => $target_language,
    'useSource' => 'TRUE',
  );
  if (!isset($target_language) || !isset($document_id)) {
    lingotek_error('downloadDocument was not called because it was missing parameters', $params);
    return;
  }

  //Get the finished document
  $text = $_lingotek_client
    ->download("downloadDocument", $params);
  try {
    $xml = new SimpleXMLElement($text);
  } catch (Exception $e) {
    lingotek_error("downloadDocument FAILED", array(
      'xml' => $text,
      'error' => $e
        ->getMessage(),
    ));
  }

  //Update the Node details to show the translated document
  $titles = $xml
    ->xpath("title");
  $bodies = $xml
    ->xpath("body");
  $target_node->title = decode_entities(lingotek_xml_decode($titles[0]));
  $target_node->body = lingotek_xml_decode($bodies[0]);
  $target_node->teaser = node_teaser($target_node->body, $source_node->format);

  // Publish the node if the source was published
  $target_node->status = $source_node->status;
  $target_node->promote = $source_node->promote;
  $target_node->sticky = $source_node->sticky;
  $target_node->tnid = $source_node->nid;
  if ($save) {
    if (!isset($target_node->vid)) {
      $target_node->vid = $target_node->nid;
    }
    node_save($target_node);
  }
}