Exemple #1
0
     $iclq = new ICanLocalizeQuery($sitepress_settings['site_id'], $sitepress_settings['access_key']);
     $p = $wpdb->get_row("SELECT t.* FROM {$wpdb->prefix}icl_translations t JOIN {$wpdb->prefix}icl_translation_status s ON t.translation_id=s.translation_id\n                WHERE t.element_type LIKE 'post\\_%' AND t.source_language_code IS NOT NULL AND s.translation_service='icanlocalize' LIMIT {$_REQUEST['offset']}, 1");
     if (!empty($p)) {
         $original_id = $wpdb->get_var($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid=%d AND source_language_code IS NULL", $p->trid));
         if ($p->element_type == 'post_page') {
             $permalink = get_option('home') . '?page_id=' . $original_id;
         } else {
             $permalink = get_option('home') . '?p=' . $original_id;
         }
         $_lang_details = $sitepress->get_language_details($p->source_language_code);
         $from_language = ICL_Pro_Translation::server_languages_map($_lang_details['english_name']);
         $_lang_details = $sitepress->get_language_details($p->language_code);
         $to_language = ICL_Pro_Translation::server_languages_map($_lang_details['english_name']);
         $cms_id = sprintf('%s_%d_%s_%s', preg_replace('#^post_#', '', $p->element_type), $original_id, $p->source_language_code, $p->language_code);
         $ret = $iclq->update_cms_id(compact('permalink', 'from_language', 'to_language', 'cms_id'));
         if ($ret != $cms_id && $iclq->error()) {
             echo json_encode(array('errors' => 1, 'message' => $iclq->error(), 'cont' => 0));
         } else {
             echo json_encode(array('errors' => 0, 'message' => 'OK', 'cont' => 1));
         }
     } else {
         echo json_encode(array('errors' => 0, 'message' => __('Done', 'sitepress'), 'cont' => 0));
     }
     exit;
     //break;
 //break;
 case 'icl_cleanup':
     global $sitepress, $wpdb, $wp_post_types;
     $post_types = array_keys($wp_post_types);
     foreach ($post_types as $pt) {
         $types[] = 'post_' . $pt;
 /**
  * Sends the translation snapshot to ICanLocalize.
  * 
  * @param $array $params The parameters to be added when sending the snapshot
  */
 function send_translation_snapshot_to_icl($params)
 {
     global $sitepress, $sitepress_settings;
     $params['accesskey'] = $sitepress_settings['access_key'];
     $params['website_id'] = $sitepress_settings['site_id'];
     require_once ICL_PLUGIN_PATH . '/lib/Snoopy.class.php';
     require_once ICL_PLUGIN_PATH . '/lib/xml2array.php';
     require_once ICL_PLUGIN_PATH . '/lib/icl_api.php';
     $icl_query = new ICanLocalizeQuery();
     $request = ICL_API_ENDPOINT . "/translation_snapshots/create_by_cms.xml";
     $response = $icl_query->_request($request, 'POST', $params);
     if (!$response) {
         error_log('Translation Analytics: Could not send translation snapshot:\\n' . $icl_query->error());
     }
 }