private function migrate_3_2($type, $old_admin_text_context, $new_admin_text_context, $key)
 {
     global $wpdb;
     $old_string_id = icl_st_is_registered_string('admin_texts_' . $type . '_' . $old_admin_text_context, $key);
     if ($old_string_id) {
         $new_string_id = icl_st_is_registered_string('admin_texts_' . $new_admin_text_context, $key);
         if ($new_string_id) {
             $wpdb->update($wpdb->prefix . 'icl_string_translations', array('string_id' => $new_string_id), array('string_id' => $old_string_id));
             $this->st_records->icl_strings_by_string_id($new_string_id)->update(array('status' => $this->st_records->icl_strings_by_string_id($old_string_id)->status()));
         }
     }
 }
 private function migrate_3_2($type, $old_admin_text_context, $new_admin_text_context, $key)
 {
     global $wpdb;
     $old_string_id = icl_st_is_registered_string('admin_texts_' . $type . '_' . $old_admin_text_context, $key);
     if ($old_string_id) {
         $new_string_id = icl_st_is_registered_string('admin_texts_' . $new_admin_text_context, $key);
         if ($new_string_id) {
             // make the old translations point to the new translations
             $wpdb->update($wpdb->prefix . 'icl_string_translations', array('string_id' => $new_string_id), array('string_id' => $old_string_id));
             // Copy the status.
             $status = $wpdb->get_var($wpdb->prepare("SELECT status FROM {$wpdb->prefix}icl_strings WHERE id = %d", $old_string_id));
             $wpdb->update($wpdb->prefix . 'icl_strings', array('status' => $status), array('id' => $new_string_id));
         }
     }
 }
 function icl_st_render_option_writes($option_name, $option_value, $option_key = '')
 {
     $sub_key = $option_key . '[' . $option_name . ']';
     if (is_array($option_value) || is_object($option_value)) {
         $output = '<h4><a class="icl_stow_toggler" href="#">+ ' . $option_name . '</a></h4><ul class="icl_st_option_writes" style="display: none">';
         foreach ($option_value as $key => $value) {
             $output .= '<li>' . $this->icl_st_render_option_writes($key, $value, $sub_key) . '</li>';
         }
         $output .= '</ul>';
     } elseif (is_string($option_value) || is_numeric($option_value)) {
         $fixed = $this->is_sub_key_fixed($sub_key);
         $string_name = $option_key . $option_name;
         $context = $this->get_context($option_key, $option_name);
         $checked = icl_st_is_registered_string($context, $string_name) ? ' checked="checked"' : '';
         $has_translations = !$fixed && $checked === '' && icl_st_string_has_translations($context, $string_name) ? ' class="icl_st_has_translations" ' : '';
         $input_val = ' value="' . htmlspecialchars($option_value) . '" ';
         $option_key_name = ' name="icl_admin_options' . $sub_key . ' ';
         $input_open = '<input' . ($fixed ? ' disabled="disabled"' : '');
         $read_only_input_open = '<input type="text" readonly="readonly"';
         $output = '<div class="icl_st_admin_string icl_st_' . (is_numeric($option_value) ? 'numeric' : 'string') . '">' . $input_open . ' type="hidden" ' . $option_key_name . ' value="" />' . $input_open . $has_translations . ' type="checkbox" ' . $option_key_name . $input_val . $checked . ' />' . $read_only_input_open . ' value="' . $option_name . '" size="32" />' . $read_only_input_open . $input_val . ' size="48" /></div><br clear="all" />';
     }
     return isset($output) ? $output : '';
 }
 function render_option_writes($name, $value, $key = '')
 {
     if (!defined('WPML_ST_FOLDER')) {
         return;
     }
     //Cache the previous option, when called recursively
     static $option = false;
     if (!$key) {
         $option = maybe_unserialize(get_option($name));
         if (is_object($option)) {
             $option = (array) $option;
         }
     }
     $admin_option_names = get_option('_icl_admin_option_names');
     // determine theme/plugin name (string context)
     $es_context = '';
     $context = '';
     $slug = '';
     foreach ($admin_option_names as $context => $element) {
         $found = false;
         foreach ((array) $element as $slug => $options) {
             $found = false;
             foreach ((array) $options as $option_key => $option_value) {
                 $found = false;
                 $es_context = '';
                 if ($option_key == $name) {
                     if (is_scalar($option_value)) {
                         $es_context = 'admin_texts_' . $context . '_' . $slug;
                         $found = true;
                     } elseif (is_array($option_value) && is_array($value) && $option_value == $value) {
                         $es_context = 'admin_texts_' . $context . '_' . $slug;
                         $found = true;
                     }
                 }
                 if ($found) {
                     break;
                 }
             }
             if ($found) {
                 break;
             }
         }
         if ($found) {
             break;
         }
     }
     echo '<ul class="icl_tm_admin_options">';
     echo '<li>';
     $context_html = '';
     if (!$key) {
         $context_html = '[' . $context . ': ' . $slug . '] ';
     }
     if (is_scalar($value)) {
         preg_match_all('#\\[([^\\]]+)\\]#', $key, $matches);
         if (count($matches[1]) > 1) {
             $o_value = $option;
             for ($i = 1; $i < count($matches[1]); $i++) {
                 $o_value = $o_value[$matches[1][$i]];
             }
             $o_value = $o_value[$name];
             $edit_link = '';
         } else {
             if (is_scalar($option)) {
                 $o_value = $option;
             } elseif (isset($option[$name])) {
                 $o_value = $option[$name];
             } else {
                 $o_value = '';
             }
             if (!$key) {
                 if (icl_st_is_registered_string($es_context, $name)) {
                     $edit_link = '[<a href="' . admin_url('admin.php?page=' . WPML_ST_FOLDER . '/menu/string-translation.php&context=' . $es_context) . '">' . __('translate', 'sitepress') . '</a>]';
                 } else {
                     $edit_link = '<div class="updated below-h2">' . __('string not registered', 'sitepress') . '</div>';
                 }
             } else {
                 $edit_link = '';
             }
         }
         if (false !== strpos($name, '*')) {
             $o_value = '<span style="color:#bbb">{{ ' . __('Multiple options', 'wpml-translation-management') . ' }}</span>';
         } else {
             $o_value = esc_html($o_value);
             if (strlen($o_value) > 200) {
                 $o_value = substr($o_value, 0, 200) . ' ...';
             }
         }
         echo '<li>' . $context_html . $name . ': <i>' . $o_value . '</i> ' . $edit_link . '</li>';
     } else {
         $edit_link = '[<a href="' . admin_url('admin.php?page=' . WPML_ST_FOLDER . '/menu/string-translation.php&context=' . $es_context) . '">' . __('translate', 'sitepress') . '</a>]';
         echo '<strong>' . $context_html . $name . '</strong> ' . $edit_link;
         if (!icl_st_is_registered_string($es_context, $name)) {
             $notice = '<div class="updated below-h2">' . __('some strings might be not registered', 'sitepress') . '</div>';
             echo $notice;
         }
         foreach ((array) $value as $o_key => $o_value) {
             $this->render_option_writes($o_key, $o_value, $o_key . '[' . $name . ']');
         }
         //Reset cached data
         $option = false;
     }
     echo '</li>';
     echo '</ul>';
 }
 function add_translated_document($translation_id, $request_id)
 {
     global $sitepress_settings, $wpdb, $sitepress;
     $iclq = new ICanLocalizeQuery($sitepress_settings['site_id'], $sitepress_settings['access_key']);
     $tinfo = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}icl_translations WHERE translation_id=%d", $translation_id));
     $_lang = $sitepress->get_language_details($tinfo->language_code);
     $translation = $iclq->cms_do_download($request_id, $this->server_languages_map($_lang['english_name']));
     $translation = apply_filters('icl_data_from_pro_translation', $translation);
     $ret = false;
     if (!empty($translation)) {
         $language_code = $wpdb->get_var($wpdb->prepare("\n                SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE translation_id=%d", $translation_id));
         $parts = explode('_', $translation['original_id']);
         if ($parts[0] == 'external') {
             // Translations are saved in the string table for 'external' types
             $id = array_pop($parts);
             unset($parts[0]);
             $type = implode('_', $parts);
             unset($translation['original_id']);
             foreach ($translation as $field => $value) {
                 if (function_exists('icl_st_is_registered_string')) {
                     $value = str_replace('&#0A;', "\n", $value);
                     $string_id = icl_st_is_registered_string($type, $id . '_' . $field);
                     if (!$string_id) {
                         icl_register_string($type, $id . '_' . $field, $value);
                         $string_id = icl_st_is_registered_string($type, $id . '_' . $field);
                     }
                     if ($string_id) {
                         icl_add_string_translation($string_id, $language_code, $value, ICL_STRING_TRANSLATION_COMPLETE);
                     }
                 }
             }
             $ret = true;
         } else {
             $ret = $this->save_post_translation($translation_id, $translation);
         }
         if ($ret) {
             $lang_details = $sitepress->get_language_details($language_code);
             $language_server = $this->server_languages_map($lang_details['english_name']);
             $iclq->cms_update_request_status($request_id, CMS_TARGET_LANGUAGE_DONE, $language_server);
             $translations = $sitepress->get_element_translations($tinfo->trid, $tinfo->element_type);
             if (isset($translations[$tinfo->language_code])) {
                 $iclq->report_back_permalink($request_id, $language_server, $translations[$tinfo->language_code]);
             }
         }
     }
     return $ret;
 }
Пример #6
0
function icl_st_render_option_writes($option_name, $option_value, $option_key = '')
{
    $has_translations = '';
    if (is_array($option_value) || is_object($option_value)) {
        echo '<h4><a class="icl_stow_toggler" href="#">- ' . $option_name . '</a></h4>';
        echo '<ul class="icl_st_option_writes">';
        foreach ($option_value as $key => $value) {
            echo '<li>';
            icl_st_render_option_writes($key, $value, $option_key . '[' . $option_name . ']');
            echo '</li>';
        }
        echo '</ul>';
    } elseif (is_string($option_value) || is_numeric($option_value)) {
        if (icl_st_is_registered_string('admin_texts_theme_' . get_option('template'), $option_key . $option_name)) {
            $checked = ' checked="checked"';
            if (icl_st_string_has_translations('admin_texts_theme_' . get_option('template'), $option_key . $option_name)) {
                $has_translations = ' class="icl_st_has_translations"';
            } else {
                $has_translations = '';
            }
        } else {
            $checked = '';
        }
        if (is_numeric($option_value)) {
            $class = 'icl_st_numeric';
        } else {
            $class = 'icl_st_string';
        }
        global $iclTranslationManagement;
        $int = preg_match_all('#\\[([^\\]]+)\\]#', $option_key . '[' . $option_name . ']', $matches);
        $_v = $iclTranslationManagement->admin_texts_to_translate;
        if ($int) {
            foreach ($matches[1] as $m) {
                if (isset($_v[$m])) {
                    $_v = $_v[$m];
                } else {
                    $_v = 0;
                    break;
                }
            }
        }
        if ($_v) {
            $disabled = ' disabled="disabled"';
        } else {
            $disabled = '';
        }
        echo '<div class="icl_st_admin_string ' . $class . '">';
        echo '<input' . $disabled . ' type="hidden" name="icl_admin_options' . $option_key . '[' . $option_name . ']" value=""  />';
        echo '<input' . $disabled . $has_translations . ' type="checkbox" name="icl_admin_options' . $option_key . '[' . $option_name . ']" value="' . htmlspecialchars($option_value) . '" 
            ' . $checked . ' />';
        echo '<input type="text" readonly="readonly" value="' . $option_name . '" size="32" />';
        echo '<input type="text" value="' . htmlspecialchars($option_value) . '" readonly="readonly" size="48" />';
        //echo '<br /><input type="text" size="100" value="icl_admin_options'.$option_key.'['.$option_name.']" />';
        echo '</div><br clear="all" />';
    }
}
 public static function save_labels_translation()
 {
     $errors = '';
     if (empty($_POST['singular']) || empty($_POST['general'])) {
         $errors .= __('Please fill in all fields!', 'sitepress') . '<br />';
     }
     $string_id = icl_st_is_registered_string('WordPress', 'taxonomy singular name: ' . $_POST['singular_original']);
     if (!$string_id) {
         $string_id = icl_register_string('WordPress', 'taxonomy singular name: ' . $_POST['singular_original'], $_POST['singular_original']);
     }
     icl_add_string_translation($string_id, $_POST['language'], $_POST['singular'], ICL_STRING_TRANSLATION_COMPLETE);
     $string_id = icl_st_is_registered_string('WordPress', 'taxonomy general name: ' . $_POST['general_original']);
     if (!$string_id) {
         $string_id = icl_register_string('WordPress', 'taxonomy general name: ' . $_POST['general_original'], $_POST['general_original']);
     }
     icl_add_string_translation($string_id, $_POST['language'], $_POST['general'], ICL_STRING_TRANSLATION_COMPLETE);
     $html = '';
     echo json_encode(array('html' => $html, 'errors' => $errors));
     exit;
 }
 function get_translatable_items($items, $type, $filter)
 {
     if (function_exists('icl_st_is_registered_string')) {
         // Only return items if string translation is available.
         global $sitepress, $wpdb;
         if ($type == 'gravity_form') {
             $default_lang = $sitepress->get_default_language();
             $languages = $sitepress->get_active_languages();
             global $wpdb;
             $g_forms = $wpdb->get_results($wpdb->prepare("\n                    SELECT *\n                    FROM {$wpdb->prefix}rg_form\n                "));
             foreach ($g_forms as $k => $v) {
                 $new_item = new stdClass();
                 $new_item->external_type = true;
                 $new_item->type = 'gravity_form';
                 $new_item->id = $v->id;
                 $new_item->post_type = 'gravity_form';
                 $new_item->post_id = 'external_' . $new_item->post_type . '_' . $v->id;
                 $new_item->post_date = $v->date_created;
                 $new_item->post_status = $v->is_active ? __('Active', 'gravity-forms-ml') : __('Inactive', 'gravity-forms-ml');
                 $new_item->post_title = $v->title;
                 $new_item->is_translation = false;
                 $new_item->string_data = $this->_get_form_strings($v->id);
                 // add to the translation table if required
                 $post_trid = $sitepress->get_element_trid($new_item->id, 'post_' . $new_item->post_type);
                 if (!$post_trid) {
                     $sitepress->set_element_language_details($new_item->id, 'post_' . $new_item->post_type, false, $default_lang, null, false);
                 }
                 // register the strings with WPML
                 if (function_exists('icl_st_is_registered_string')) {
                     foreach ($new_item->string_data as $key => $value) {
                         if (!icl_st_is_registered_string('gravity_form', $new_item->id . '_' . $key)) {
                             icl_register_string('gravity_form', $new_item->id . '_' . $key, $value);
                         }
                     }
                 }
                 $post_trid = $sitepress->get_element_trid($new_item->id, 'post_' . $new_item->post_type);
                 $post_translations = $sitepress->get_element_translations($post_trid, 'post_' . $new_item->post_type);
                 global $iclTranslationManagement;
                 $md5 = $iclTranslationManagement->post_md5($new_item);
                 foreach ($post_translations as $lang => $translation) {
                     $res = $wpdb->get_row("SELECT status, needs_update, md5 FROM {$wpdb->prefix}icl_translation_status WHERE translation_id={$translation->translation_id}");
                     if ($res) {
                         if (!$res->needs_update) {
                             // see if the md5 has changed.
                             if ($md5 != $res->md5) {
                                 $res->needs_update = 1;
                                 $wpdb->update($wpdb->prefix . 'icl_translation_status', array('needs_update' => 1), array('translation_id' => $translation->translation_id));
                             }
                         }
                         $_suffix = str_replace('-', '_', $lang);
                         $index = 'status_' . $_suffix;
                         $new_item->{$index} = $res->status;
                         $index = 'needs_update_' . $_suffix;
                         $new_item->{$index} = $res->needs_update;
                     }
                 }
                 $items[] = $new_item;
             }
         }
     }
     return $items;
 }
 /**
  * @param string $element_type_prefix
  * @param object $job
  * todo: Move to ST via an action to make this testable
  */
 private function save_external($element_type_prefix, $job)
 {
     // Translations are saved in the string table for 'external' types
     $element_type_prefix = apply_filters('wpml_get_package_type_prefix', $element_type_prefix, $job->original_doc_id);
     foreach ($job->elements as $field) {
         if ($field->field_translate) {
             if (function_exists('icl_st_is_registered_string')) {
                 $string_id = icl_st_is_registered_string($element_type_prefix, $field->field_type);
                 if (!$string_id) {
                     icl_register_string($element_type_prefix, $field->field_type, $this->decode_field_data($field->field_data, $field->field_format));
                     $string_id = icl_st_is_registered_string($element_type_prefix, $field->field_type);
                 }
                 if ($string_id) {
                     icl_add_string_translation($string_id, $job->language_code, $this->decode_field_data($field->field_data_translated, $field->field_format), ICL_TM_COMPLETE);
                 }
             }
         }
     }
 }
 protected function _scan_needed()
 {
     if ($groups = bp_xprofile_get_groups(array('fetch_fields' => true))) {
         foreach ($groups as $group) {
             $is_registered = icl_st_is_registered_string($this->_context, "{$this->_group_string_prefix}{$group->id} name");
             if (!$is_registered) {
                 return true;
             }
             if (!empty($group->fields) && is_array($group->fields)) {
                 foreach ($group->fields as $field) {
                     $is_registered = icl_st_is_registered_string($this->_context, "{$this->_field_string_prefix}{$field->id} name");
                     if (!$is_registered) {
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
 function save_translation($data)
 {
     global $wpdb, $sitepress, $sitepress_settings, $ICL_Pro_Translation;
     $is_incomplete = false;
     foreach ($data['fields'] as $field) {
         $this->_save_translation_field($field['tid'], $field);
         if (!isset($field['finished']) || !$field['finished']) {
             $is_incomplete = true;
         }
     }
     if (!empty($data['complete']) && !$is_incomplete) {
         $wpdb->update($wpdb->prefix . 'icl_translate_job', array('translated' => 1), array('job_id' => $data['job_id']));
         $rid = $wpdb->get_var($wpdb->prepare("SELECT rid FROM {$wpdb->prefix}icl_translate_job WHERE job_id=%d", $data['job_id']));
         $translation_id = $wpdb->get_var($wpdb->prepare("SELECT translation_id FROM {$wpdb->prefix}icl_translation_status WHERE rid=%d", $rid));
         $wpdb->update($wpdb->prefix . 'icl_translation_status', array('status' => ICL_TM_COMPLETE, 'needs_update' => 0), array('rid' => $rid));
         list($element_id, $trid) = $wpdb->get_row($wpdb->prepare("SELECT element_id, trid FROM {$wpdb->prefix}icl_translations WHERE translation_id=%d", $translation_id), ARRAY_N);
         $job = $this->get_translation_job($data['job_id'], true);
         $parts = explode('_', $job->original_doc_id);
         if ($parts[0] == 'external') {
             // Translations are saved in the string table for 'external' types
             $id = array_pop($parts);
             unset($parts[0]);
             $type = implode('_', $parts);
             foreach ($job->elements as $field) {
                 if ($field->field_translate) {
                     if (function_exists('icl_st_is_registered_string')) {
                         $string_id = icl_st_is_registered_string($type, $id . '_' . $field->field_type);
                         if (!$string_id) {
                             icl_register_string($type, $id . '_' . $field->field_type, $this->decode_field_data($field->field_data, $field->field_format));
                             $string_id = icl_st_is_registered_string($type, $id . '_' . $field->field_type);
                         }
                         if ($string_id) {
                             icl_add_string_translation($string_id, $job->language_code, $this->decode_field_data($field->field_data_translated, $field->field_format), ICL_STRING_TRANSLATION_COMPLETE);
                         }
                     }
                 }
             }
         } else {
             if (!is_null($element_id)) {
                 $postarr['ID'] = $_POST['post_ID'] = $element_id;
             }
             foreach ($job->elements as $field) {
                 switch ($field->field_type) {
                     case 'title':
                         $postarr['post_title'] = $this->decode_field_data($field->field_data_translated, $field->field_format);
                         break;
                     case 'body':
                         $postarr['post_content'] = $this->decode_field_data($field->field_data_translated, $field->field_format);
                         break;
                     case 'excerpt':
                         $postarr['post_excerpt'] = $this->decode_field_data($field->field_data_translated, $field->field_format);
                         break;
                     case 'URL':
                         $postarr['post_name'] = $this->decode_field_data($field->field_data_translated, $field->field_format);
                         break;
                     case 'tags':
                         $tags = $this->decode_field_data($field->field_data_translated, $field->field_format);
                         $original_tags = $this->decode_field_data($field->field_data, $field->field_format);
                         // create tags that don't exist
                         foreach ($tags as $k => $t) {
                             $thetag = $sitepress->get_term_by_name_and_lang($t, 'post_tag', $job->language_code);
                             $tags[$k] = $t;
                             // Save $t as we may have added @.lang to it
                             if (empty($thetag)) {
                                 $the_original_tag = $sitepress->get_term_by_name_and_lang($original_tags[$k], 'post_tag', $job->source_language_code);
                                 $tmp = wp_insert_term($t, 'post_tag');
                                 if (!is_wp_error($tmp) && isset($tmp['term_taxonomy_id'])) {
                                     $sitepress->set_term_translation($the_original_tag, $tmp['term_taxonomy_id'], 'post_tag', $job->language_code, $job->source_language_code);
                                 }
                             }
                         }
                         $postarr['tags_input'] = join(',', $tags);
                         $postarr['tax_input']['post_tag'] = $tags;
                         break;
                     case 'categories':
                         $cats = $this->decode_field_data($field->field_data_translated, $field->field_format);
                         $original_cats = $this->decode_field_data($field->field_data, $field->field_format);
                         $missing_parents = array();
                         foreach ($cats as $k => $c) {
                             $parent_missing = false;
                             $thecat = $sitepress->get_term_by_name_and_lang($c, 'category', $job->language_code);
                             $cat_id = 0;
                             if (empty($thecat)) {
                                 $the_original_cat = $sitepress->get_term_by_name_and_lang($original_cats[$k], 'category', $job->source_language_code);
                                 if ($the_original_cat) {
                                     $the_original_cat_parent = $wpdb->get_var("SELECT parent FROM {$wpdb->term_taxonomy} WHERE term_taxonomy_id=" . $the_original_cat->term_taxonomy_id);
                                 } else {
                                     $the_original_cat_parent = false;
                                 }
                                 if ($the_original_cat_parent) {
                                     $op_tr = icl_object_id($the_original_cat_parent, 'category', false, $job->language_code);
                                     if (!$op_tr) {
                                         // The parent is missing. Possibly because we haven't created a translation of it yet
                                         $parent_missing = true;
                                     }
                                 } else {
                                     $op_tr = 0;
                                 }
                                 $tmp = wp_insert_term($c, 'category', array('parent' => $op_tr));
                                 if (!is_wp_error($tmp) && isset($tmp['term_taxonomy_id'])) {
                                     $sitepress->set_term_translation($the_original_cat, $tmp['term_taxonomy_id'], 'category', $job->language_code, $job->source_language_code);
                                     $cat_id = $tmp['term_id'];
                                 }
                             } else {
                                 $cat_id = $thecat->term_id;
                             }
                             if ($cat_id) {
                                 $cat_ids[] = $cat_id;
                             }
                             if ($parent_missing) {
                                 $missing_parents[$cat_id] = $the_original_cat_parent;
                             }
                         }
                         // Double check missing parents as they might be available now.
                         foreach ($missing_parents as $cat_id => $the_original_cat_parent) {
                             $op_tr = icl_object_id($the_original_cat_parent, 'category', false, $job->language_code);
                             $cat_trid = $sitepress->get_element_trid($cat_id, 'tax_category');
                             wp_update_term($cat_id, 'category', array('parent' => $op_tr));
                             $wpdb->update($wpdb->prefix . 'icl_translations', array('language_code' => $job->language_code, 'trid' => $cat_trid, 'source_language_code' => $job->source_language_code), array('element_type' => 'tax_category', 'element_id' => $cat_id));
                         }
                         $postarr['post_category'] = $cat_ids;
                         break;
                     default:
                         if (in_array($field->field_type, $sitepress->get_translatable_taxonomies(false, $job->original_post_type))) {
                             $taxs = $this->decode_field_data($field->field_data_translated, $field->field_format);
                             $original_taxs = $this->decode_field_data($field->field_data, $field->field_format);
                             $taxonomy = $field->field_type;
                             $alltaxs = $tax_ids = array();
                             foreach ($taxs as $k => $c) {
                                 $thetax = $sitepress->get_term_by_name_and_lang($c, $taxonomy, $job->language_code);
                                 $taxs[$k] = $c;
                                 // Save $c as we may have added @.lang to it
                                 if (empty($thetax)) {
                                     $the_original_tax = $sitepress->get_term_by_name_and_lang($original_taxs[$k], $taxonomy, $job->source_language_code);
                                     $the_original_tax_parent = $wpdb->get_var("SELECT parent FROM {$wpdb->term_taxonomy} WHERE term_taxonomy_id=" . $the_original_tax->term_taxonomy_id);
                                     if ($the_original_tax_parent) {
                                         $op_tr = icl_object_id($the_original_tax_parent, $taxonomy, false, $job->language_code);
                                     } else {
                                         $op_tr = 0;
                                     }
                                     $tmp = wp_insert_term($c, $taxonomy, array('parent' => $op_tr));
                                     if (isset($tmp['term_taxonomy_id'])) {
                                         $sitepress->set_term_translation($the_original_tax, $tmp['term_taxonomy_id'], $taxonomy, $job->language_code, $job->source_language_code);
                                     }
                                     $tax_id = $tmp['term_id'];
                                 } else {
                                     $tax_id = $thetax->term_id;
                                 }
                                 $tax_ids[] = $tax_id;
                                 $alltaxs[] = $c;
                             }
                             $taxonomy_obj = get_taxonomy($taxonomy);
                             // array = hierarchical, string = non-hierarchical.
                             if ($taxonomy_obj->hierarchical) {
                                 $postarr['tax_input'][$taxonomy] = $tax_ids;
                             } else {
                                 $postarr['tax_input'][$taxonomy] = $taxs;
                             }
                         }
                 }
             }
             $original_post = get_post($job->original_doc_id);
             $postarr['post_author'] = $original_post->post_author;
             $postarr['post_type'] = $original_post->post_type;
             if ($sitepress_settings['sync_comment_status']) {
                 $postarr['comment_status'] = $original_post->comment_status;
             }
             if ($sitepress_settings['sync_ping_status']) {
                 $postarr['ping_status'] = $original_post->ping_status;
             }
             if ($sitepress_settings['sync_page_ordering']) {
                 $postarr['menu_order'] = $original_post->menu_order;
             }
             if ($sitepress_settings['sync_private_flag'] && $original_post->post_status == 'private') {
                 $postarr['post_status'] = 'private';
             }
             if ($sitepress_settings['sync_post_date']) {
                 $postarr['post_date'] = $original_post->post_date;
             }
             if (is_null($element_id)) {
                 $postarr['post_status'] = !$sitepress_settings['translated_document_status'] ? 'draft' : $original_post->post_status;
             } else {
                 // set post_status to the current post status.
                 $postarr['post_status'] = $wpdb->get_var("SELECT post_status FROM {$wpdb->prefix}posts WHERE ID = " . $element_id);
             }
             if ($original_post->post_parent) {
                 $post_parent_trid = $wpdb->get_var("SELECT trid FROM {$wpdb->prefix}icl_translations \r\n                        WHERE element_type='post_{$original_post->post_type}' AND element_id='{$original_post->post_parent}'");
                 if ($post_parent_trid) {
                     $parent_id = $wpdb->get_var("SELECT element_id FROM {$wpdb->prefix}icl_translations \r\n                            WHERE element_type='post_{$original_post->post_type}' AND trid='{$post_parent_trid}' AND language_code='{$job->language_code}'");
                 }
             }
             if (isset($parent_id) && $sitepress_settings['sync_page_parent']) {
                 $_POST['post_parent'] = $postarr['post_parent'] = $parent_id;
                 $_POST['parent_id'] = $postarr['parent_id'] = $parent_id;
             }
             $_POST['trid'] = $trid;
             $_POST['lang'] = $job->language_code;
             $_POST['skip_sitepress_actions'] = true;
             $postarr = apply_filters('icl_pre_save_pro_translation', $postarr);
             if (isset($element_id)) {
                 // it's an update so dont change the url
                 $postarr['post_name'] = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM {$wpdb->posts} WHERE ID=%d", $element_id));
             }
             if (isset($element_id)) {
                 // it's an update so dont change post date
                 $existing_post = get_post($element_id);
                 $postarr['post_date'] = $existing_post->post_date;
                 $postarr['post_date_gmt'] = $existing_post->post_date_gmt;
             }
             $new_post_id = wp_insert_post($postarr);
             // set taxonomies for users with limited caps
             if (!current_user_can('manage-categories') && !empty($postarr['tax_input'])) {
                 foreach ($postarr['tax_input'] as $taxonomy => $terms) {
                     wp_set_post_terms($new_post_id, $terms, $taxonomy, FALSE);
                     // true to append to existing tags | false to replace existing tags
                 }
             }
             do_action('icl_pro_translation_saved', $new_post_id, $data['fields']);
             // Allow identical slugs
             $post_name = sanitize_title($postarr['post_title']);
             $post_name_rewritten = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM {$wpdb->posts} WHERE ID=%d", $new_post_id));
             $post_name_base = $post_name;
             if ($post_name != $post_name_rewritten) {
                 $incr = 1;
                 do {
                     $exists = $wpdb->get_var($wpdb->prepare("\r\n                            SELECT p.ID FROM {$wpdb->posts} p\r\n                                JOIN {$wpdb->prefix}icl_translations t ON t.element_id = p.ID AND t.element_type=%s\r\n                            WHERE p.ID <> %d AND t.language_code = %s AND p.post_name=%s\r\n                        ", 'post_' . $postarr['post_type'], $new_post_id, $job->language_code, $post_name));
                     if ($exists) {
                         $incr++;
                     } else {
                         break;
                     }
                     $post_name = $post_name_base . '-' . $incr;
                 } while ($exists);
                 $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $new_post_id));
             }
             $ICL_Pro_Translation->_content_fix_links_to_translated_content($new_post_id, $job->language_code);
             // update body translation with the links fixed
             $new_post_content = $wpdb->get_var($wpdb->prepare("SELECT post_content FROM {$wpdb->posts} WHERE ID=%d", $new_post_id));
             foreach ($job->elements as $jel) {
                 if ($jel->field_type == 'body') {
                     $fields_data_translated = $this->encode_field_data($new_post_content, $jel->field_format);
                     break;
                 }
             }
             $wpdb->update($wpdb->prefix . 'icl_translate', array('field_data_translated' => $fields_data_translated), array('job_id' => $data['job_id'], 'field_type' => 'body'));
             // set stickiness
             //is the original post a sticky post?
             remove_filter('option_sticky_posts', array($sitepress, 'option_sticky_posts'));
             // remove filter used to get language relevant stickies. get them all
             $sticky_posts = get_option('sticky_posts');
             $is_original_sticky = $original_post->post_type == 'post' && in_array($original_post->ID, $sticky_posts);
             if ($is_original_sticky && $sitepress_settings['sync_sticky_flag']) {
                 stick_post($new_post_id);
             } else {
                 if ($original_post->post_type == 'post' && !is_null($element_id)) {
                     unstick_post($new_post_id);
                     //just in case - if this is an update and the original post stckiness has changed since the post was sent to translation
                 }
             }
             //sync plugins texts
             foreach ((array) $this->settings['custom_fields_translation'] as $cf => $op) {
                 if ($op == 1) {
                     update_post_meta($new_post_id, $cf, get_post_meta($original_post->ID, $cf, true));
                 }
             }
             // set specific custom fields
             $copied_custom_fields = array('_top_nav_excluded', '_cms_nav_minihome');
             foreach ($copied_custom_fields as $ccf) {
                 $val = get_post_meta($original_post->ID, $ccf, true);
                 update_post_meta($new_post_id, $ccf, $val);
             }
             // sync _wp_page_template
             if ($sitepress_settings['sync_page_template']) {
                 $_wp_page_template = get_post_meta($original_post->ID, '_wp_page_template', true);
                 if (!empty($_wp_page_template)) {
                     update_post_meta($new_post_id, '_wp_page_template', $_wp_page_template);
                 }
             }
             // set the translated custom fields if we have any.
             foreach ((array) $this->settings['custom_fields_translation'] as $field_name => $val) {
                 if ($val == 2) {
                     // should be translated
                     // find it in the translation
                     foreach ($job->elements as $name => $eldata) {
                         if ($eldata->field_data == $field_name) {
                             if (preg_match("/field-(.*?)-name/", $eldata->field_type, $match)) {
                                 $field_id = $match[1];
                                 foreach ($job->elements as $k => $v) {
                                     if ($v->field_type == 'field-' . $field_id) {
                                         $field_translation = $this->decode_field_data($v->field_data_translated, $v->field_format);
                                     }
                                     if ($v->field_type == 'field-' . $field_id . '-type') {
                                         $field_type = $v->field_data;
                                     }
                                 }
                                 if ($field_type == 'custom_field') {
                                     $field_translation = str_replace('&#0A;', "\n", $field_translation);
                                     // always decode html entities  eg decode &amp; to &
                                     $field_translation = html_entity_decode($field_translation);
                                     update_post_meta($new_post_id, $field_name, $field_translation);
                                 }
                             }
                         }
                     }
                 }
             }
             $link = get_edit_post_link($new_post_id);
             if ($link == '') {
                 // the current user can't edit so just include permalink
                 $link = get_permalink($new_post_id);
             }
             if (is_null($element_id)) {
                 $wpdb->update($wpdb->prefix . 'icl_translations', array('element_id' => $new_post_id), array('translation_id' => $translation_id));
                 $user_message = __('Translation added: ', 'sitepress') . '<a href="' . $link . '">' . $postarr['post_title'] . '</a>.';
             } else {
                 $user_message = __('Translation updated: ', 'sitepress') . '<a href="' . $link . '">' . $postarr['post_title'] . '</a>.';
             }
             // synchronize the page parent for translations
             if ($trid && $sitepress_settings['sync_page_parent']) {
                 $translations = $sitepress->get_element_translations($trid, 'post_' . $postarr['post_type']);
                 foreach ($translations as $target_lang => $target_details) {
                     if ($target_lang != $job->language_code) {
                         if ($target_details->element_id) {
                             $sitepress->fix_translated_parent($new_post_id, $target_details->element_id, $target_lang, $job->language_code);
                             // restore child-parent relationships
                             $children = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_parent={$target_details->element_id} AND post_type='page'");
                             foreach ($children as $ch) {
                                 $ch_trid = $sitepress->get_element_trid($ch, 'post_' . $postarr['post_type']);
                                 $ch_translations = $sitepress->get_element_translations($ch_trid, 'post_' . $postarr['post_type']);
                                 if (isset($ch_translations[$job->language_code])) {
                                     $wpdb->update($wpdb->posts, array('post_parent' => $new_post_id), array('ID' => $ch_translations[$job->language_code]->element_id));
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $this->messages[] = array('type' => 'updated', 'text' => $user_message);
         if ($this->settings['notification']['completed'] != ICL_TM_NOTIFICATION_NONE) {
             require_once ICL_PLUGIN_PATH . '/inc/translation-management/tm-notification.class.php';
             if ($data['job_id']) {
                 $tn_notification = new TM_Notification();
                 $tn_notification->work_complete($data['job_id'], !is_null($element_id));
             }
         }
         self::set_page_url($new_post_id);
         // redirect to jobs list
         wp_redirect(admin_url(sprintf('admin.php?page=%s&%s=%d', WPML_TM_FOLDER . '/menu/translations-queue.php', is_null($element_id) ? 'added' : 'updated', is_null($element_id) ? $new_post_id : $element_id)));
     } else {
         $this->messages[] = array('type' => 'updated', 'text' => __('Translation (incomplete) saved.', 'sitepress'));
     }
 }
function icl_st_render_option_writes($option_name, $option_value, $option_key = '')
{
    $output = '';
    $has_translations = '';
    if (icl_st_is_registered_string('admin_texts_theme_' . get_option('template'), $option_key . $option_name)) {
        $checked = ' checked="checked"';
        if (icl_st_string_has_translations('admin_texts_theme_' . get_option('template'), $option_key . $option_name)) {
            $has_translations = ' class="icl_st_has_translations"';
        } else {
            $has_translations = '';
        }
    } else {
        $checked = '';
    }
    if (is_numeric($option_value)) {
        $class = 'icl_st_numeric';
    } else {
        $class = 'icl_st_string';
    }
    global $iclTranslationManagement;
    $int = preg_match_all('#\\[([^\\]]+)\\]#', $option_key . '[' . $option_name . ']', $matches);
    $_v = $iclTranslationManagement->admin_texts_to_translate;
    if ($int) {
        foreach ($matches[1] as $m) {
            if (isset($_v[$m])) {
                $_v = $_v[$m];
            } else {
                $_v = 0;
                break;
            }
        }
    }
    if ($_v) {
        $disabled = ' disabled="disabled"';
    } else {
        $disabled = '';
    }
    $output .= '<div class="icl_st_admin_string ' . $class . '">';
    $output .= '<input' . $disabled . ' type="hidden" name="icl_admin_options' . $option_key . '[' . $option_name . ']" value=""  />';
    $output .= '<input' . $disabled . $has_translations . ' type="checkbox" name="icl_admin_options' . $option_key . '[' . $option_name . ']" value="' . esc_attr($option_value) . '"
            ' . $checked . ' />';
    $output .= '<input type="text" readonly="readonly" value="' . $option_name . '" size="32" />';
    $output .= '<input type="text" value="' . esc_attr($option_value) . '" readonly="readonly" size="48" />';
    $output .= '</div><br clear="all" />';
    return $output;
}
Пример #13
0
/**
 * Translates URL by Marketpress slug settings.
 * 
 * @global type $wpml_marketpress_old_settings
 * @global type $wpdb
 * @global type $sitepress
 * @global type $wp_query
 * @global type $icl_adjust_id_url_filter_off
 * @global type $icl_adjust_id_url_filter_off
 * @global type $icl_adjust_id_url_filter_off
 * @staticvar array $cache
 * @param type $url
 * @param type $language
 * @param type $page
 * @return array 
 */
function wpml_marketpress_translate_url($url, $language, $page = 'products')
{
    static $cache = array();
    if (isset($cache[$language][$page])) {
        return $cache[$language][$page];
    }
    global $wpml_marketpress_settings, $wpml_marketpress_old_settings, $wpdb, $sitepress, $wp_query;
    $old_settings = $wpml_marketpress_old_settings;
    $slugs = $wpml_marketpress_old_settings['slugs'];
    $slugs_current = $wpml_marketpress_settings['slugs'];
    $translated_slugs = array();
    if (!in_array($page, array('category', 'tag', 'products', 'cart', 'orderstatus', 'payment_return', 'product')) || !function_exists('icl_t')) {
        return $url;
    }
    foreach ($slugs as $key => $slug) {
        if ($key == 'store') {
            continue;
        }
        $string_id = icl_st_is_registered_string('plugin marketpress slugs', $key);
        $sql = "SELECT value FROM {$wpdb->prefix}icl_string_translations WHERE string_id=" . $string_id . " AND language='" . $language . "'";
        $translated_slug = $wpdb->get_var($sql);
        if (!empty($translated_slug)) {
            $translated_slug = strtolower(sanitize_title($translated_slug));
            $translated_slugs[$key] = $translated_slug;
        } else {
            $translated_slugs[$key] = $slug;
        }
    }
    $store_page_id = get_option('mp_store_page');
    $translated_store_page_id = icl_object_id($store_page_id, 'page', true, $language);
    $translated_store_page = get_post($translated_store_page_id);
    $translated_store_page = $translated_store_page->post_name;
    $translated_slugs['store'] = $translated_store_page;
    switch ($page) {
        case 'category':
            $category = '';
            if (!empty($wp_query->query_vars['product_category'])) {
                global $icl_adjust_id_url_filter_off;
                $icl_adjust_id_url_filter_off = true;
                $category = get_term_by('slug', $wp_query->query_vars['product_category'], 'product_category');
                $translated_id = icl_object_id($category->term_id, 'product_category', true, $language);
                $translated_category = get_term_by('id', $translated_id, 'product_category');
                if (!empty($translated_category)) {
                    $category = $translated_category->slug . '/';
                }
                $icl_adjust_id_url_filter_off = false;
            }
            $url = '/' . $translated_slugs['store'] . '/' . $translated_slugs['products'] . '/' . $translated_slugs['category'] . '/' . $category;
            break;
        case 'tag':
            $tag = '';
            if (!empty($wp_query->query_vars['product_tag'])) {
                global $icl_adjust_id_url_filter_off;
                $icl_adjust_id_url_filter_off = true;
                $tag = get_term_by('slug', $wp_query->query_vars['product_tag'], 'product_tag');
                $translated_id = icl_object_id($tag->term_id, 'product_tag', true, $language);
                $translated_tag = get_term_by('id', $translated_id, 'product_tag');
                if (!empty($translated_tag)) {
                    $tag = $translated_tag->slug . '/';
                }
                $icl_adjust_id_url_filter_off = false;
            }
            $url = '/' . $translated_slugs['store'] . '/' . $translated_slugs['products'] . '/' . $translated_slugs['tag'] . '/' . $tag;
            break;
        case 'products':
            $url = '/' . $translated_slugs['store'] . '/' . $translated_slugs['products'] . '/';
            break;
        case 'product':
            $product = '';
            if (!empty($wp_query->queried_object_id)) {
                global $icl_adjust_id_url_filter_off;
                $icl_adjust_id_url_filter_off = true;
                $translated_id = icl_object_id($wp_query->queried_object_id, 'product', true, $language);
                $translated_product = get_post($translated_id);
                if (!empty($translated_product)) {
                    $product = $translated_product->post_name . '/';
                }
                $icl_adjust_id_url_filter_off = false;
            }
            $url = '/' . $translated_slugs['store'] . '/' . $translated_slugs['products'] . '/' . $product;
            break;
        case 'cart':
            $add = '';
            $parts = array_values(explode($slugs_current['cart'], trim($_SERVER['REQUEST_URI'], '/')));
            if (!empty($parts[1])) {
                $parts = explode('?', trim($parts[1], '/'));
                $add = trim($parts[0], '/') . '/';
            }
            $url = '/' . $translated_slugs['store'] . '/' . $translated_slugs['cart'] . '/' . $add;
            break;
        case 'orderstatus':
            $add = '';
            $parts = array_values(explode('/', trim($_SERVER['REQUEST_URI'], '/')));
            $order = end($parts);
            if ($order != $slugs_current['orderstatus']) {
                $add = $order . '/';
            }
            $url = '/' . $translated_slugs['store'] . '/' . $translated_slugs['orderstatus'] . '/' . $add;
            break;
        case 'payment_return':
            $url = '/' . $translated_slugs['store'] . '/payment-return/';
            break;
    }
    $query_string = !empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '';
    $url = $sitepress->convert_url(site_url() . $url . $query_string, $language);
    $cache[$language][$page] = $url;
    return $url;
}
 /**
  * Updates the WPML string register for a single field.
  *
  * @since  2.0.9.7
  * @param  string $context
  * @param  string $field
  * @param  string $value
  * @param  bool $update_string If false then the translation will only be
  *                registered but not updated.
  */
 protected static function wpml_update_field($context, $field, $value, $update_string = true)
 {
     global $sitepress, $sitepress_settings;
     if (empty($sitepress) || empty($sitepress_settings)) {
         return false;
     }
     if (!function_exists('icl_t')) {
         return false;
     }
     if (!icl_st_is_registered_string($context, $field)) {
         // Register the field if it does not exist.
         icl_register_string($context, $field, $value, false);
         $active_languages = $sitepress->get_active_languages();
         foreach ($active_languages as $lang => $data) {
             icl_update_string_translation($field, $lang, $value, ICL_STRING_TRANSLATION_COMPLETE);
         }
         $default_language = !empty($sitepress_settings['st']['strings_language']) ? $sitepress_settings['st']['strings_language'] : $sitepress->get_default_language();
         icl_update_string_translation($field, $default_language, $value, ICL_STRING_TRANSLATION_COMPLETE);
     } else {
         if ($update_string) {
             // Add translation.
             if (defined('DOING_AJAX')) {
                 $current_language = $sitepress->get_language_cookie();
             } else {
                 $current_language = $sitepress->get_current_language();
             }
             icl_update_string_translation($field, $current_language, $value, ICL_STRING_TRANSLATION_COMPLETE);
         }
     }
 }
Пример #15
0
 public static function get_translatable_items($items, $type, $filter)
 {
     // Only return items if string translation is available, and if type is for formidable.
     if ($type != 'formidable') {
         return $items;
     }
     global $sitepress, $wpdb;
     $default_lang = $sitepress->get_default_language();
     $languages = $sitepress->get_active_languages();
     $frm_form = new FrmForm();
     if (isset($_GET) && isset($_GET['frm_action']) && $_GET['frm_action'] == 'translate' && isset($_GET['id']) && is_numeric($_GET['id'])) {
         $forms = $frm_form->getOne($_GET['id']);
         $forms = array($forms->id => $forms);
     } else {
         $forms = $frm_form->getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')", ' ORDER BY name');
     }
     unset($frm_form);
     foreach ($forms as $k => $v) {
         $new_item = new stdClass();
         $new_item->external_type = true;
         $new_item->type = 'formidable';
         $new_item->id = $v->id;
         $new_item->post_type = 'formidable';
         $new_item->post_id = 'external_' . $new_item->post_type . '_' . $v->id;
         $new_item->post_date = $v->created_at;
         $new_item->post_status = $v->status == 'draft' ? __('Inactive', 'formidable_wpml') : __('Active', 'formidable_wpml');
         $new_item->post_title = $v->name;
         $new_item->is_translation = false;
         $new_item->string_data = self::_get_form_strings($v->id);
         // add to the translation table if required
         $post_trid = $sitepress->get_element_trid($new_item->id, 'post_' . $new_item->post_type);
         if (!$post_trid) {
             $sitepress->set_element_language_details($new_item->id, 'post_' . $new_item->post_type, false, $default_lang, null, false);
         }
         // register the strings with WPML
         foreach ($new_item->string_data as $key => $value) {
             $key = function_exists('mb_substr') ? mb_substr($new_item->id . '_' . $key, 0, 160) : substr($new_item->id . '_' . $key, 0, 160);
             if (!icl_st_is_registered_string('formidable', $key)) {
                 icl_register_string('formidable', $key, $value);
             }
             unset($key);
             unset($value);
         }
         $post_trid = $sitepress->get_element_trid($new_item->id, 'post_' . $new_item->post_type);
         $post_translations = $sitepress->get_element_translations($post_trid, 'post_' . $new_item->post_type);
         global $iclTranslationManagement;
         $md5 = $iclTranslationManagement->post_md5($new_item);
         foreach ($post_translations as $lang => $translation) {
             $res = $wpdb->get_row("SELECT status, needs_update, md5 FROM {$wpdb->prefix}icl_translation_status WHERE translation_id={$translation->translation_id}");
             if ($res) {
                 if (!$res->needs_update) {
                     // see if the md5 has changed.
                     if ($md5 != $res->md5) {
                         $res->needs_update = 1;
                         $wpdb->update($wpdb->prefix . 'icl_translation_status', array('needs_update' => 1), array('translation_id' => $translation->translation_id));
                     }
                 }
                 $_suffix = str_replace('-', '_', $lang);
                 $index = 'status_' . $_suffix;
                 $new_item->{$index} = $res->status;
                 $index = 'needs_update_' . $_suffix;
                 $new_item->{$index} = $res->needs_update;
             }
         }
         $items[] = $new_item;
     }
     return $items;
 }