View source
<?php
include_once 'lingotek.define.inc';
include_once 'lingotek.session.inc';
include_once 'lingotek.reference.inc';
include_once 'lingotek.util.inc';
include_once 'lingotek.api.inc';
include_once 'lingotek.sync.inc';
include_once 'lingotek.batch.inc';
function lingotek_auto_loader($class) {
$module_location = drupal_get_path('module', 'lingotek');
$paths = array(
$module_location,
$module_location . '/lib/Drupal/lingotek/',
);
foreach ($paths as $path) {
$filename = $path . $class . '.php';
if (file_exists($filename)) {
include $filename;
}
}
}
function lingotek_menu() {
$items = array();
$items['admin/settings/lingotek'] = array(
'title' => 'Lingotek',
'access arguments' => array(
'administration',
),
'description' => 'The Lingotek module helps you translate and keep your site translated',
'file' => 'lingotek.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'lingotek_admin_form',
),
);
if (LingotekAccount::instance()
->isEnterprise()) {
$items['node/%node/lingotek_pm'] = array(
'title' => 'Lingotek',
'access arguments' => array(
1,
'pm',
),
'access callback' => 'lingotek_access',
'file' => 'lingotek.page.inc',
'page arguments' => array(
1,
),
'page callback' => 'lingotek_pm',
'type' => MENU_LOCAL_TASK,
);
$items['node/%node/lingotek_dev'] = array(
'title' => 'Lingotek Developer Tools',
'access arguments' => array(
1,
'dev',
),
'access callback' => 'lingotek_access_dev_tools',
'description' => 'Developer Tools',
'file' => 'lingotek.dev.inc',
'page callback' => 'lingotek_dev_page',
'page arguments' => array(
1,
),
'type' => MENU_LOCAL_TASK,
);
}
else {
$items['admin/settings/lingotek'] = array_merge($items['admin/settings/lingotek'], array(
'file' => 'lingotek.dashboard.inc',
'page callback' => 'lingotek_dashboard',
'weight' => 1,
'type' => MENU_NORMAL_ITEM,
));
$items['admin/settings/lingotek/dashboard'] = array(
'title' => 'Dashboard',
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'lingotek.dashboard.inc',
'page callback' => 'lingotek_dashboard',
'weight' => 1,
'access arguments' => array(
'administration',
),
);
$items[LINGOTEK_BASE_URL . '/dashboard'] = $items['admin/settings/lingotek/dashboard'];
}
$items[LINGOTEK_BASE_URL] = $items['admin/settings/lingotek'];
$items['admin/settings/lingotek/settings'] = array(
'title' => 'Settings',
'type' => MENU_LOCAL_TASK,
'weight' => 5,
'access arguments' => array(
'administration',
),
'description' => 'Community Translation Settings',
'file' => 'lingotek.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'lingotek_admin_form',
),
);
$items[LINGOTEK_BASE_URL . '/settings'] = $items['admin/settings/lingotek/settings'];
$items[LINGOTEK_BASE_URL . '/cleanup-utility'] = array(
'title' => 'Lingotek Cleanup Utility',
'description' => 'This utility helps clean up any node settings that are awry.',
'access arguments' => array(
'access lingotek utilities',
),
'file' => 'lingotek.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'lingotek_form_cleanup_utility',
),
'type' => MENU_NORMAL_ITEM,
);
$items[LINGOTEK_NOTIFICATIONS_URL] = array(
'title' => 'Content Translation Notifications',
'type' => MENU_CALLBACK,
'access arguments' => array(
'access content',
),
'description' => 'When content translations are ready, this receives the notifications.',
'file' => 'lingotek.sync.inc',
'page callback' => 'lingotek_notifications',
);
$items['admin/settings/lingotek/notifications'] = $items[LINGOTEK_NOTIFICATIONS_URL];
$items['lingotek/target'] = array(
'type' => MENU_CALLBACK,
'access arguments' => array(
'administration',
),
'description' => 'Lingotek Command Router',
'file' => 'lingotek.dashboard.inc',
'page callback' => 'lingotek_dashboard_command_ajax',
);
$items['lingotek/get-account-status'] = array(
'title' => 'Check the Users Account Status',
'type' => MENU_CALLBACK,
'access arguments' => array(
'access content',
),
'description' => 'Check Account Status',
'file' => 'lingotek.admin.inc',
'page callback' => 'lingotek_get_account_status',
);
$items['lingotek/flush-cache'] = array(
'type' => MENU_CALLBACK,
'access arguments' => array(
'administration',
),
'file' => 'lingotek.admin.inc',
'page callback' => 'lingotek_flush_cache',
);
$items['lingotek/update'] = array(
'access arguments' => array(
'pm',
),
'file' => 'lingotek.page.inc',
'page callback' => 'lingotek_update',
'type' => MENU_CALLBACK,
);
$items['lingotek/sync/comment/%'] = array(
'access arguments' => array(
'administer comments',
),
'file' => 'lingotek.page.inc',
'page callback' => 'page_sync_comment_translations',
'page arguments' => array(
3,
),
'type' => MENU_CALLBACK,
);
$items['lingotek/mark-phases-complete/%node'] = array(
'access arguments' => array(
'access content',
),
'file' => 'includes/lingotek.ajax.inc',
'page callback' => 'lingotek_page_mark_phases_complete',
'page arguments' => array(
2,
),
'type' => MENU_CALLBACK,
);
$items['lingotek/sync'] = array(
'type' => MENU_CALLBACK,
'access arguments' => array(
'administration',
),
'description' => 'Lingotek Sync Endpoint',
'file' => 'lingotek.sync.inc',
'page callback' => 'lingotek_sync',
);
$items['lingotek/sync/report'] = array(
'type' => MENU_CALLBACK,
'access arguments' => array(
'administration',
),
'description' => 'Lingotek Sync Endpoint',
'file' => 'lingotek.sync.inc',
'page callback' => 'lingotek_sync_endpoint',
);
$items['lingotek/upload'] = array(
'title' => 'Upload Documents For Machine Translation',
'type' => MENU_CALLBACK,
'access arguments' => array(
'access content',
),
'file' => 'lingotek.dashboard.inc',
'page callback' => 'lingotek_dashboard_mt_upload',
);
$items[LINGOTEK_BASE_URL . '/mt-content-queued'] = array(
'title' => 'Content Queued for Translation',
'type' => MENU_CALLBACK,
'file' => 'lingotek.batch.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'lingotek_bulk_mt_upload_batch_complete',
),
'access arguments' => array(
'administration',
),
);
$items['lingotek/download'] = array(
'title' => 'Download Machine Translated Documents',
'type' => MENU_CALLBACK,
'access arguments' => array(
'access content',
),
'file' => 'lingotek.dashboard.inc',
'page callback' => 'lingotek_dashboard_mt_download',
);
$items[LINGOTEK_BASE_URL . '/mt-content-downloaded'] = array(
'title' => 'Download Translated Content',
'type' => MENU_CALLBACK,
'file' => 'lingotek.batch.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'lingotek_bulk_mt_download_batch_complete',
),
'access arguments' => array(
'administration',
),
);
$items[LINGOTEK_BASE_URL . '/identify-content'] = array(
'title' => 'Test',
'type' => MENU_CALLBACK,
'weight' => 30,
'file' => 'lib/Drupal/batch/lingotek.batch.inc',
'page callback' => 'lingotek_batch_identify_content',
'access arguments' => array(
'administration',
),
);
$items['admin/config/lingotek/setup'] = array(
'title' => 'Lingotek Setup Path Router',
'description' => 'Figures out the necessary setup path.',
'file' => 'lingotek.setup.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'lingotek_setup',
),
'type' => MENU_CALLBACK,
'access arguments' => array(
'administration',
),
);
$items['admin/config/lingotek/new-account'] = array(
'title' => 'Create a Lingotek Account',
'description' => 'Setup a new Lingotek account.',
'file' => 'lingotek.setup.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'lingotek_setup_new_account_form',
),
'type' => MENU_CALLBACK,
'access arguments' => array(
'administration',
),
);
$items['admin/config/lingotek/account-settings'] = array(
'title' => 'Lingotek Account Login',
'description' => 'Manage your Lingotek account settings.',
'file' => 'lingotek.setup.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'lingotek_setup_account_settings_form',
),
'type' => MENU_CALLBACK,
'access arguments' => array(
'administration',
),
);
$items['admin/config/lingotek/community-select'] = array(
'title' => 'Choose Your Community',
'description' => 'Select a community to use with this site.',
'file' => 'lingotek.setup.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'lingotek_community_select_form',
),
'type' => MENU_CALLBACK,
'access arguments' => array(
'administration',
),
);
$items['admin/config/lingotek/project-select'] = array(
'title' => 'Choose Your Project',
'description' => 'Select project to use.',
'file' => 'lingotek.setup.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'lingotek_project_select_form',
),
'type' => MENU_CALLBACK,
'access arguments' => array(
'administration',
),
);
$items['admin/config/lingotek/language-settings'] = array(
'title' => 'Choose Your Languages',
'description' => 'Manage your Lingotek language settings.',
'file' => 'lingotek.setup.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'lingotek_setup_language_settings_form',
),
'type' => MENU_CALLBACK,
'access arguments' => array(
'administration',
),
);
$items['admin/config/lingotek/node-translation-settings'] = array(
'title' => 'Enable Content Types',
'description' => 'Select the nodes and fields you want translated.',
'file' => 'lingotek.setup.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'lingotek_setup_node_translation_settings_form',
),
'type' => MENU_CALLBACK,
'access arguments' => array(
'administration',
),
);
$items['admin/config/lingotek/content-type-choose-fields-ajax/%'] = array(
'title' => 'Content Types Ajax',
'description' => 'Ajax functionality for content options.',
'file' => 'lingotek.setup.inc',
'page callback' => 'lingotek_content_type_choose_fields_callback',
'page arguments' => array(
4,
),
'type' => MENU_CALLBACK,
'access arguments' => array(
'administration',
),
);
$items['admin/config/lingotek/setup-complete'] = array(
'title' => 'Setup Complete',
'description' => 'Your Lingotek module has been configured and is now ready to use.',
'file' => 'lingotek.setup.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'lingotek_setup_complete_form',
),
'type' => MENU_CALLBACK,
'access arguments' => array(
'administration',
),
);
$items['admin/config/lingotek/node-updates'] = array(
'title' => 'Lingotek Node Updates',
'description' => 'Updates your nodes to support multiple languages.',
'file' => 'lingotek.setup.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'lingotek_setup_node_updates_form',
),
'type' => MENU_CALLBACK,
'access arguments' => array(
'administration',
),
);
return $items;
}
function lingotek_menu_alter(&$items) {
if (module_exists('entity_translation')) {
$translate_path = 'node/%node/translate';
$lingotek_access_callback = 'lingotek_entity_translation_node_tab_access';
if (isset($items[$translate_path])) {
$items[$translate_path]['title'] = 'Translate';
$items[$translate_path]['access callback'] = $lingotek_access_callback;
}
$menu_targets = array(
'node/%node/translate/add/%entity_translation_language/%entity_translation_language',
'node/%node/translate/delete/%entity_translation_language',
);
foreach ($menu_targets as $target) {
if (isset($items[$target])) {
$items[$target]['access callback'] = $lingotek_access_callback;
}
}
$edit_target = 'node/%node/translate/edit/%entity_translation_language';
if (isset($items[$edit_target])) {
$items[$edit_target]['access callback'] = 'lingotek_entity_translation_edit_access';
$items[$edit_target]['access arguments'][3] = $lingotek_access_callback;
}
}
}
function lingotek_module_implements_alter(&$implementations, $hook) {
switch ($hook) {
case 'menu_alter':
$group = $implementations['lingotek'];
unset($implementations['lingotek']);
$implementations['lingotek'] = $group;
break;
}
}
function lingotek_entity_translation_node_tab_access() {
$args = func_get_args();
$node = array_shift($args);
if ($node->language !== LANGUAGE_NONE) {
if (lingotek_supported_type($node->type)) {
$user_access = drupal_multilingual() && (user_access('translate any entity') || user_access("translate node entities"));
$translate_tab_access = lingotek_managed_by_entity_translation($node->type) && !lingotek_node_pushed($node) && $user_access;
return $translate_tab_access;
}
elseif (entity_translation_node_supported_type($node->type)) {
return entity_translation_tab_access('node', $node);
}
elseif (entity_translation_node('node', $node) && module_exists('translation')) {
return _translation_tab_access($node);
}
}
return FALSE;
}
function lingotek_access_dev_tools($node, $permission) {
$user_access = user_access($permission);
if (module_exists('entity_translation') && entity_translation_node_supported_type($node->type) && $user_access && !lingotek_node_pushed($node)) {
return FALSE;
}
return user_access($permission);
}
function lingotek_entity_translation_edit_access($entity_type, $entity, $langcode) {
$translations = entity_translation_get_handler($entity_type, $entity)
->getTranslations();
if (!isset($translations->data[$langcode])) {
return FALSE;
}
$args = func_get_args();
return call_user_func_array($args[3], array_slice($args, 4));
}
function lingotek_permission() {
return array(
'access lingotek utilities' => array(
'title' => t('Access Lingotek Utilities'),
'description' => t('Access admin-only utility pages.'),
),
'access per-item lingotek project selection' => array(
'title' => t('Per-item Project Selection'),
'description' => t('Access the Lingotek Project selector on content creation forms.'),
),
'access per-item lingotek vault selection' => array(
'title' => t('Per-item Vault Selection'),
'description' => t('Access the Lingotek TM Vault selector on content creation forms.'),
),
'administration' => array(
'title' => 'Administration Menu',
'description' => t('Access the administrative page for the module.'),
),
'pm' => array(
'title' => 'Project Management',
'description' => t('Access the Lingotek tab on content types (Must also have permission to edit the content type in question).'),
),
'translation' => array(
'title' => 'Translate',
'description' => t('Allow access to the workbench for translation (first) phases'),
),
'review' => array(
'title' => 'Review',
'description' => t('Allow access to the workbench for review (following) phases.'),
),
'phase_template' => array(
'title' => 'Phase Template (
)',
'description' => t('Allow node-level setting of the phase template on node creation. Can only be set once per node.'),
),
'use_source' => array(
'title' => 'Paste Source',
'description' => t('Allow node-level setting of showing the source when no translation is available yet'),
),
'sync_method' => array(
'title' => 'Synchronization Method',
'description' => t('Allow node-level setting of setting the synchronization method'),
),
'url_alias_translation' => array(
'title' => 'URL Alias Translation',
'description' => t('Allow node-level setting of setting the URL alias translation'),
),
'mt' => array(
'title' => 'Machine Translation',
'description' => t('Allow node-level setting of machine translation'),
),
'dev' => array(
'title' => 'Developer',
'description' => t('Access useful debugging features'),
),
);
}
function lingotek_form_node_form_alter(&$form, $form_state, $form_id) {
if (!isset($form['nid']['#value'])) {
if (lingotek_supported_type($form['type']['#value'])) {
$form['language']['#default_value'] = lingotek_get_source_language();
}
}
if (!lingotek_supported_type($form['#node']->type) || !user_access('pm')) {
return;
}
$node = lingotek_empty_node();
$document_id = FALSE;
if (isset($form['nid']['#value'])) {
$nid = $form['nid']['#value'];
$node = node_load($nid);
$document_id = lingotek_lingonode($nid, 'document_id');
}
global $language;
$drupal_language_code = $language->language;
if ($drupal_language_code != $node->language && lingotek_node_pushed($node)) {
$lingotek_locale = Lingotek::convertDrupal2Lingotek($drupal_language_code);
lingotek_set_target_sync_status($node->nid, $lingotek_locale, LINGOTEK_TARGET_SYNC_STATUS_PENDING);
$language_text = lingotek_language_field_lookup('native', $lingotek_locale) . " (" . $drupal_language_code . ")";
$translation_edit_link = lingotek_get_workbench_url($node, $lingotek_locale, t('Edit Translation: @language_text ', array(
'@language_text' => $language_text,
)));
$edit_translation_message = t('Editing the fields below will only change the content of the source language, not the translation.');
$edit_translation_message .= "<br/>" . $translation_edit_link;
drupal_set_message($edit_translation_message, 'warning', FALSE);
}
if (LingotekAccount::instance()
->isEnterprise() === FALSE) {
return;
}
drupal_add_css(drupal_get_path('module', 'lingotek') . '/style/form.css');
$title = t('Translation Management');
$form['lingotek'] = array(
'#title' => t('Translation Mangement'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'additional_settings',
'#attributes' => array(
'id' => array(
'lingotek_fieldset',
),
),
'#attached' => array(
'js' => array(
drupal_get_path('module', 'lingotek') . '/js/lingotek.form.js',
),
),
);
$form['lingotek']['et_content'] = array(
'#type' => 'container',
);
$form['lingotek']['et_content']['explanation'] = array(
'#title' => $title,
'#type' => 'item',
'#description' => t('Translation of this node is currently managed by the Entity Translation module. Click the "Enable Lingotek" button to begin using the Lingotek module to manage this node\'s translation. Upon saving the node, its content will be uploaded to Lingotek. You will not be able to switch back to using Entity Translation for this node.'),
);
$form['lingotek']['et_content']['is_et_node'] = array(
'#type' => 'hidden',
'#value' => lingotek_managed_by_entity_translation($form['#node']->type),
'#attributes' => array(
'id' => 'ltk-entity-translation-node',
),
);
$form['lingotek']['lingotek_push_once'] = array(
'#type' => 'checkbox',
'#default_value' => 0,
'#attributes' => array(
'id' => 'ltk-push-once',
'style' => 'display: none',
),
);
$form['lingotek']['et_content']['btn'] = array(
'#type' => 'button',
'#value' => 'Enable Lingotek',
'#attributes' => array(
'id' => 'ltk-enable-from-et',
'onclick' => 'return false;',
),
);
$form['lingotek']['note'] = array(
'#type' => 'item',
'#title' => $title,
'#description' => t('Please select a language for Lingotek to use as the source language. The source language cannot be language neutral.'),
);
$form['lingotek']['content'] = array(
'#type' => 'container',
);
$form['lingotek']['content']['note'] = array(
'#type' => 'item',
'#title' => $title,
'#description' => t("The Lingotek module was developed to aid you in getting your Drupal site translated. The module integrates the Lingotek translation management system directly into Drupal, so that your users can leverage the power of Lingotek's translation tools and services without ever having to leave the comfort of your Drupal environment."),
);
$form['lingotek']['content']['create_lingotek_document'] = array(
'#type' => 'checkbox',
'#title' => t('Upload Content Automatically'),
'#default_value' => lingotek_variable_get(lingotek_lingonode($node->nid, 'create_lingotek_document'), 'lingotek_create_documents_by_default', 0),
'#description' => t('When enabled, your Drupal content (including saved edits) will automatically be uploaded to Lingotek for translation.<br/>When disabled, you are required to manually upload your content by clicking the "Upload" button on the Lingteok tab.'),
);
$form['lingotek']['content']['syncMethod'] = array(
'#type' => 'checkbox',
'#title' => t('Download Translations Automatically'),
'#default_value' => lingotek_variable_get(lingotek_lingonode($node->nid, 'sync_method'), 'lingotek_sync', 1),
'#access' => user_access('sync_method'),
'#description' => t('When enabled, completed translatoins will automatically be downloaded from Lingotek.<br/>When disabled, you are required to manually download translations by clicking the "Download" button on the Lingotek tab.'),
);
$form['lingotek']['content']['lingotek_allow_community_translation'] = array(
'#type' => 'checkbox',
'#title' => t('Allow Community Translation'),
'#description' => t('When enabled, anonymous site visitors will be presented with a link allowing them to contribute translations for this node.'),
'#default_value' => lingotek_variable_get(lingotek_lingonode($node->nid, 'allow_community_translation'), 'lingotek_allow_community_translation', 0),
);
if (user_access('url_alias_translation')) {
$form['lingotek']['content']['urlAliasTranslation'] = array(
'#type' => 'select',
'#title' => t('URL Alias Translation'),
'#default_value' => lingotek_variable_get(lingotek_lingonode($node->nid, 'url_alias_translation'), 'lingotek_url_alias_translation', 1),
'#options' => lingotek_get_url_alias_translations(),
'#description' => t('Choose how you would like to translate the URL alias. The last option requires that you install both the Title and Pathauto modules, define a path pattern, and check "Enable Lingotek Translation" for the Title field.'),
);
}
if (!$document_id && class_exists('LingotekApi')) {
$api = LingotekApi::instance();
if ($projects = $api
->listProjects()) {
$form['lingotek']['content']['lingotek_project_id'] = array(
'#type' => 'select',
'#title' => 'Project',
'#description' => t('Select the translation project with which this item should be associated.'),
'#default_value' => variable_get('lingotek_project', ''),
'#options' => $projects,
'#access' => user_access('access per-item lingotek project selection'),
);
}
if ($workflows = $api
->listWorkflows()) {
$form['lingotek']['content']['lingotek_workflow_id'] = array(
'#type' => 'select',
'#title' => t('Workflow'),
'#description' => t('Choose the Workflow to associate with this content item.'),
'#default_value' => variable_get('lingotek_workflow', ''),
'#options' => $workflows,
'#access' => user_access('access per-item lingotek project selection'),
);
}
if ($vaults = $api
->listVaults()) {
$form['lingotek']['content']['lingotek_vault_id'] = array(
'#type' => 'select',
'#title' => t('TM Vault'),
'#description' => t('Choose the TM vault to associate with this content item.'),
'#default_value' => variable_get('lingotek_vault', ''),
'#options' => $vaults,
'#access' => user_access('access per-item lingotek vault selection'),
);
}
}
$form['lingotek']['developer'] = array(
'#type' => 'fieldset',
'#title' => t('Developer Settings (Advanced)'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'developer_settings',
'#access' => user_access('dev'),
);
if ($document_id === False) {
$document_id = '';
}
$form['lingotek']['developer']['document_id'] = array(
'#type' => 'textfield',
'#title' => t('Document Id'),
'#description' => t("Read/Overwrite the document ID associated with the document. This can break the translation process but can also be used to help figure out if something is wrong."),
'#default_value' => $document_id,
);
$values = t('None');
if (isset($nid)) {
$values = json_encode(lingotek_lingonode($nid));
}
$form['lingotek']['developer']['current_lingonode'] = array(
'#type' => 'item',
'#title' => t('Node Variables'),
'#description' => check_plain($values),
);
}
function lingotek_node_view($node, $view_mode) {
global $language, $first_load, $user;
$lingotek_document_id = lingotek_lingonode($node->nid, 'document_id');
$community_translation_allowed = lingotek_lingonode($node->nid, 'allow_community_translation');
if ($view_mode == 'full' && $community_translation_allowed && $lingotek_document_id && lingotek_supported_type($node->type) && lingotek_supported_language($node->language)) {
drupal_add_css(drupal_get_path('module', 'lingotek') . '/style/base.css');
lingotek_node_sync($node);
if ($language->language != $node->language) {
$link = lingotek_get_workbench_url($node, $language->lingotek_locale, t('Help make it better.'));
if ($link != '') {
$message = t('The translation of @title is still being worked on.', array(
'@title' => '"' . $node->title . '"',
)) . " ";
$message .= $link . ' ';
if (lingotek_access($node, 'pm')) {
$message .= '<span style="font-size: 80%">[' . l(t('progress'), 'node/' . $node->nid . '/lingotek_pm', array(
'html' => TRUE,
)) . ']</span>';
}
drupal_set_message($message, 'warning', FALSE);
}
}
}
}
function lingotek_node_presave($node) {
if (module_exists('title') && array_key_exists('title_field', $node)) {
if (isset($node->title_field[$node->language][0]['value'])) {
$node->title = $node->title_field[$node->language][0]['value'];
}
}
}
function lingotek_node_insert($node) {
lingotek_node_update($node);
}
function lingotek_node_delete($node) {
lingotek_lingonode_delete($node->nid);
}
function lingotek_node_update($node) {
$send_lingotek_document = NULL;
if (isset($node->create_lingotek_document)) {
lingotek_lingonode($node->nid, 'create_lingotek_document', $node->create_lingotek_document);
}
if (isset($node->lingotek_push_once) && $node->lingotek_push_once) {
$send_lingotek_document = 1;
}
else {
if (lingotek_managed_by_entity_translation($node->type) && !lingotek_node_pushed($node)) {
$send_lingotek_document = 0;
}
else {
if (isset($node->lingotek_upload_override)) {
$send_lingotek_document = $node->lingotek_upload_override == 1 ? 1 : 0;
}
else {
$send_lingotek_document = lingotek_lingonode($node->nid, 'create_lingotek_document');
if ($send_lingotek_document === FALSE) {
$send_lingotek_document = variable_get('lingotek_create_documents_by_default', $send_lingotek_document);
}
}
}
}
if (!lingotek_supported_type($node->type) || !lingotek_supported_language($node->language)) {
return;
}
$is_syncing = isset($node->skip_status_updates) && $node->skip_status_updates ? TRUE : FALSE;
$is_syncing = isset($_SESSION['lingotek_sync_in_progress']) ? $_SESSION['lingotek_sync_in_progress'] : $is_syncing;
if ($is_syncing === FALSE) {
lingotek_set_node_and_targets_sync_status($node->nid, LINGOTEK_NODE_SYNC_STATUS_EDITED, LINGOTEK_TARGET_SYNC_STATUS_EDITED);
}
if (user_access('dev') && isset($node->document_id) && is_numeric($node->document_id)) {
lingotek_lingonode($node->nid, 'document_id', $node->document_id);
}
if (isset($node->mtEngine)) {
lingotek_lingonode($node->nid, 'mt_engine', $node->mtEngine);
}
if (user_access('url_alias_translation') && isset($node->urlAliasTranslation)) {
lingotek_lingonode($node->nid, 'url_alias_translation', $node->urlAliasTranslation);
}
if (isset($node->mtTargets)) {
$node->mtTargets = array_filter($node->mtTargets, "lingotek_unselected");
lingotek_lingonode($node->nid, 'mt_targets', implode(",", $node->mtTargets));
}
if (lingotek_lingonode($node->nid, 'document_id') === FALSE) {
lingotek_trace('lingotek_node_update FIRST RUN ONLY', array(
"nid" => $node->nid,
"language" => $node->language,
));
$project_id = variable_get('lingotek_project', 0);
if (user_access('access per-item lingotek project selection') && !empty($node->lingotek_project_id)) {
$project_id = $node->lingotek_project_id;
}
lingotek_lingonode($node->nid, 'project_id', $project_id);
$vault_id = variable_get('lingotek_vault', '');
if (user_access('access per-item lingotek vault selection') && !empty($node->lingotek_vault_id)) {
$vault_id = $node->lingotek_vault_id;
}
lingotek_lingonode($node->nid, 'vault_id', $vault_id);
if (!empty($node->lingotek_workflow_id)) {
lingotek_lingonode($node->nid, 'workflow_id', $node->lingotek_workflow_id);
}
if ($send_lingotek_document) {
if (LingotekApi::instance()
->addContentDocument($node, TRUE)) {
drupal_set_message(t('<em>@node_title</em> sent to Lingotek successfully.', array(
'@node_title' => $node->title,
)));
}
else {
drupal_set_message(t('Unable to send <em>@node_title</em> to Lingotek.', array(
'@node_title' => $node->title,
)), 'error');
}
}
}
else {
$router_item = menu_get_item();
$skip_list = array(
'lingotek/update',
LINGOTEK_BASE_URL . '/notifications',
);
$path_match = array_search($router_item['path'], $skip_list);
$is_syncing = isset($_SESSION['lingotek_sync_in_progress']) ? $_SESSION['lingotek_sync_in_progress'] : FALSE;
if ($send_lingotek_document && $path_match === FALSE && $is_syncing === FALSE) {
LingotekApi::instance()
->updateContentDocument($node);
}
}
if (isset($node->lingotek_allow_community_translation)) {
lingotek_lingonode($node->nid, 'allow_community_translation', $node->lingotek_allow_community_translation);
}
if (user_access('sync_method') && isset($node->syncMethod)) {
lingotek_lingonode($node->nid, 'sync_method', $node->syncMethod);
}
if (user_access('use_source') && isset($node->useSource)) {
lingotek_lingonode($node->nid, 'use_source', $node->useSource);
}
}
function lingotek_form_node_type_form_alter(&$form, &$form_state) {
$type = $form['#node_type']->type;
$lingotek_option_label = t('Enabled, with Lingotek translation');
$lingotek_details = module_exists('entity_translation') ? t('If Lingotek translation (or field translation) is enabled, then it will be possible to use Lingotek\'s collaborative workbench to translate content.') : t('If Lingotek translation is enabled, then it will be possible to use Lingotek\'s collaborative workbench to translate content.');
$form['workflow']['language_content_type']['#options'][LINGOTEK_ENABLED] = $lingotek_option_label;
$form['workflow']['language_content_type']['#description'] .= ' ' . $lingotek_details;
}
function lingotek_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
if (!lingotek_supported_field_type($form['#field']['type'])) {
return $form;
}
$default = 0;
if (array_key_exists('lingotek_translatable', $form['#field'])) {
$default = $form['#field']['lingotek_translatable'];
}
$form['field']['lingotek_translatable'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Lingotek Translation'),
'#description' => t('This allows fields to be translatable using the Lingotek Collaborative Translations Platform.'),
'#default_value' => $default,
);
array_push($form['#submit'], 'lingotek_update_field');
return $form;
}
function lingotek_update_field($form, $form_state) {
$field_name = $form['#field']['field_name'];
$field = field_info_field($field_name);
$value = (int) $form['field']['lingotek_translatable']['#value'];
if ($value == 1) {
$field['translatable'] = TRUE;
field_update_field($field);
drupal_static_reset('field_available_languages');
}
}
function lingotek_help($path, $arg) {
switch ($path) {
case 'admin/help#lingotek':
return t('Please see our DevZone:') . ' ' . l(t('Drupal Integration'), 'http://lingotek.com/support/devzone/drupal-integration');
}
}
function lingotek_translatable_node_fields() {
$fields = field_info_fields();
$translatable_fields = array();
foreach ($fields as $field_id => $field) {
foreach ($field['bundles'] as $type => $instance) {
if (field_is_translatable($type, $field)) {
$translatable_fields[] = $field['field_name'];
}
}
}
return $translatable_fields;
}
function lingotek_advanced_parsing_update_node($nid, &$context) {
$process_node = node_load($nid);
if (!empty($process_node->nid)) {
$context['message'] = t('Sending advanced parsing data to Lingotek for node @node_id: @node_title', array(
'@node_id' => $process_node->nid,
'@node_title' => $process_node->title,
));
if (LingotekApi::instance()
->updateContentDocument(LingotekNode::load($process_node))) {
$context['results'][] = t('Updated node: @id', array(
'@id' => $process_node->nid,
));
}
else {
watchdog('lingotek', 'Unable to send advanced XML version of node to Lingotek: @node_id', array(
'@node_id' => $process_node->nid,
), WATCHDOG_ERROR);
}
}
}
function lingotek_advanced_parsing_update_finished($success, $results, $operations) {
if ($success) {
drupal_set_message(t('Advanced parsing updates complete.'));
}
else {
drupal_set_message(t('There were errors updating one or more existing Lingotek documents.'), 'error');
}
}
function lingotek_set_default_advanced_xml($force = FALSE) {
$filepath_stub = DRUPAL_ROOT . '/' . drupal_get_path('module', 'lingotek') . '/fprm/';
$config_file_primary = $filepath_stub . 'okf_xmlstream@drupal_filter.fprm';
$config_file_secondary = $filepath_stub . 'okf_html@drupal_subfilter.fprm';
$current_config = variable_get('lingotek_advanced_xml_config1', '');
$default_config = file_get_contents($config_file_primary);
if ($default_config) {
if (!strlen($current_config) || $force) {
variable_set('lingotek_advanced_xml_config1', $default_config);
}
}
else {
watchdog('lingotek', 'Unable to set default primary advanced XML configuration from: @config_file', array(
'@config_file' => $config_file_primary,
), WATCHDOG_ERROR);
}
$current_config2 = variable_get('lingotek_advanced_xml_config2', '');
$default_config2 = file_get_contents($config_file_secondary);
if ($default_config2) {
if (!strlen($current_config2) || $force) {
variable_set('lingotek_advanced_xml_config2', $default_config2);
}
}
else {
watchdog('lingotek', 'Unable to set default secondary advanced XML configuration from: @config_file', array(
'@config_file' => $config_file_secondary,
), WATCHDOG_ERROR);
}
}
function lingotek_is_module_setup() {
$setup_complete = variable_get('lingotek_setup_complete', 0);
if ($setup_complete != 1) {
drupal_goto('admin/config/lingotek/new-account');
}
}
function lingotek_is_config_missing() {
$required_variables = array(
'lingotek_community_identifier',
'lingotek_oauth_consumer_id',
'lingotek_oauth_consumer_secret',
'lingotek_login_id',
'lingotek_project',
);
foreach ($required_variables as $required_variable) {
$val = variable_get($required_variable, NULL);
if (empty($val)) {
return TRUE;
}
}
return FALSE;
}
function lingotek_content_push_form($form, $form_state, $node) {
$form = array();
$form['content_push'] = array(
'#type' => 'fieldset',
'#title' => t('Push Node Content to Lingotek'),
'#description' => t("Manually push this node's content to Lingotek"),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['content_push']['submit'] = array(
'#type' => 'submit',
'#value' => t('Push Content'),
);
$form['node_id'] = array(
'#type' => 'hidden',
'#value' => $node->nid,
);
return $form;
}
function lingotek_content_push_form_submit($form, $form_state) {
$node = node_load($form_state['values']['node_id']);
$api = LingotekApi::instance();
if ($existing_document = lingotek_lingonode($node->nid, 'document_id')) {
$api
->updateContentDocument(LingotekNode::load($node));
}
else {
$api
->addContentDocument($node, TRUE);
}
drupal_set_message(t('Pushed content for @node_title to Lingotek for translation.', array(
'@node_title' => $node->title,
)));
}
function lingotek_comment_insert($comment) {
lingotek_comment_update($comment);
}
function lingotek_comment_update($comment) {
$target_types = variable_get('lingotek_translate_comments_node_types', array());
$comment_node = node_load($comment->nid);
$valid_translation_target = !empty($comment_node->type) && isset($target_types[$comment_node->type]);
if (class_exists('LingotekComment') && variable_get('lingotek_translate_comments', FALSE) && $valid_translation_target) {
$lingotek_comment = LingotekComment::load($comment)
->contentUpdated();
}
}
function lingotek_comment_view($comment, $view_mode, $langcode) {
if (class_exists('LingotekComment') && user_access('administer comments')) {
$lingotek_comment = LingotekComment::load($comment);
$link_token = drupal_get_token();
if ($document_id = $lingotek_comment
->getMetadataValue('document_id')) {
$comment->content['links']['comment']['#links']['comment-lingotek-refresh'] = array(
'title' => t('refresh translations'),
'href' => 'lingotek/sync/comment/' . $comment->cid,
'html' => FALSE,
'query' => array_merge(array(
'token' => $link_token,
), drupal_get_destination()),
);
}
}
}
function lingotek_entity_info_alter(&$entity_info) {
if (variable_get('lingotek_translate_comments', FALSE)) {
$entity_info['comment']['translation']['lingotek'] = TRUE;
}
}
function lingotek_form_comment_form_alter(&$form, $form_state) {
if (variable_get('lingotek_translate_comments', FALSE)) {
$default_language = language_default('language');
$comment_language = $form['language']['#value'];
$comment_bundle = $form['#bundle'];
$comment_fields = array_keys(field_info_instances('comment', $comment_bundle));
if ($comment_language != $default_language) {
foreach ($comment_fields as $comment_field) {
if (isset($form['cid']['#value'])) {
$form['lingotek_language_notes'] = array(
'#weight' => -15,
'#markup' => '<div style="padding: 5px 0px;"><strong>Note:</strong> When editing a comment you are only allowed to edit the original.</div>',
);
if (!empty($form[$comment_field][$default_language])) {
$form[$comment_field][$comment_language] = $form[$comment_field][$default_language];
unset($form[$comment_field][$default_language]);
}
$original_field_text = $form[$comment_field][$comment_language][0]['#entity']->{$comment_field}[$comment_language][0]['value'];
if (isset($form[$comment_field][$comment_language][0]['value'])) {
$form[$comment_field][$comment_language][0]['value']['#default_value'] = $original_field_text;
}
else {
$form[$comment_field][$comment_language][0]['#default_value'] = $original_field_text;
}
$form[$comment_field]['#language'] = $comment_language;
$form[$comment_field][$comment_language]['#language'] = $comment_language;
$form[$comment_field][$comment_language][0]['#language'] = $comment_language;
}
else {
if (!empty($form[$comment_field][$default_language])) {
$form[$comment_field][$comment_language] = $form[$comment_field][$default_language];
unset($form[$comment_field][$default_language]);
}
}
}
}
}
}
function lingotek_field_language_alter(&$display_language, $context) {
foreach ($display_language as $field => $display_language_code) {
if (!isset($context['entity']->{$field}[$display_language_code])) {
$display_language[$field] = $context['entity']->language;
}
}
}