本文整理汇总了PHP中TranslationManagement::decode_field_data方法的典型用法代码示例。如果您正苦于以下问题:PHP TranslationManagement::decode_field_data方法的具体用法?PHP TranslationManagement::decode_field_data怎么用?PHP TranslationManagement::decode_field_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TranslationManagement
的用法示例。
在下文中一共展示了TranslationManagement::decode_field_data方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render_current_element_diff
private function render_current_element_diff()
{
if (!$this->current_element->field_finished && !empty($this->job->prev_version)) {
$prev_value = '';
foreach ($this->job->prev_version->elements as $pel) {
if ($this->current_element->field_type == $pel->field_type) {
$prev_value = $this->tm_instance->decode_field_data($pel->field_data, $pel->field_format);
}
}
if ($this->current_element->field_format != 'csv_base64') {
$diff = wp_text_diff($prev_value, $this->tm_instance->decode_field_data($this->current_element->field_data, $this->current_element->field_format));
}
if (!empty($diff)) {
?>
<div class="wpml_diff_wrapper">
<p><a href="#" class="wpml_diff_toggle"><?php
_e('Show Changes', 'sitepress');
?>
</a></p>
<div class="wpml_diff">
<?php
echo $diff;
?>
</div>
</div>
<?php
}
}
}
示例2: icl_get_job_original_field_content
function icl_get_job_original_field_content()
{
global $iclTranslationManagement;
if (!wpml_is_action_authenticated('icl_get_job_original_field_content')) {
die('Wrong Nonce');
}
$job_id = filter_input(INPUT_POST, 'tm_editor_job_id', FILTER_SANITIZE_NUMBER_INT);
$field = filter_input(INPUT_POST, 'tm_editor_job_field');
$data = array();
$job = $job_id !== null && $field !== null ? $job = $iclTranslationManagement->get_translation_job($job_id) : null;
$elements = $job && isset($job->elements) ? $job->elements : array();
foreach ($elements as $element) {
$sanitized_type = sanitize_title($element->field_type);
if ($field === 'icl_all_fields' || $sanitized_type === $field) {
// if we find a field by that name we need to decode its contents according to its format
$field_contents = TranslationManagement::decode_field_data($element->field_data, $element->field_format);
if (is_scalar($field_contents)) {
$field_contents = strpos($field_contents, "\n") !== false ? wpautop($field_contents) : $field_contents;
$data[] = array('field_type' => $sanitized_type, 'field_data' => $field_contents);
}
}
}
if ((bool) $data !== false) {
wp_send_json_success($data);
} else {
wp_send_json_error(0);
}
}
示例3: icl_get_job_original_field_content
function icl_get_job_original_field_content()
{
global $iclTranslationManagement;
$error_msg = false;
$job_id = false;
$nonce = filter_input(INPUT_POST, 'tm_editor_copy_nonce');
if (!wp_verify_nonce($nonce, 'icl_copy_from_original_nonce')) {
die('Wrong Nonce');
}
$request_post_tm_editor_job_id = filter_input(INPUT_POST, 'tm_editor_job_id', FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE);
$request_post_tm_editor_field_id = filter_input(INPUT_POST, 'tm_editor_job_field');
if ($request_post_tm_editor_job_id) {
$job_id = $request_post_tm_editor_job_id;
} else {
$error_msg = "No job id provided.";
}
if (!$error_msg && $request_post_tm_editor_job_id) {
$field = $request_post_tm_editor_field_id;
} else {
$error_msg = "No field provided.";
}
if (!$error_msg && $job_id && isset($field)) {
$job = $iclTranslationManagement->get_translation_job($job_id);
if (isset($job->elements)) {
foreach ($job->elements as $element) {
if (sanitize_title($element->field_type) === $field) {
// if we find a field by that name we need to decode its contents according to its format
$field_contents = TranslationManagement::decode_field_data($element->field_data, $element->field_format);
wp_send_json_success($field_contents);
}
}
} elseif (!$job) {
$error_msg = __("No translation job found: it might have been just cancelled.", 'wpml-translation-management');
} else {
$error_msg = __("No fields found in this translation job.", 'wpml-translation-management');
}
}
if (!$error_msg) {
$error_msg = __("No such field found in the job.", 'wpml-translation-management');
}
wp_send_json_error($error_msg);
}
示例4: icl_get_job_original_field_content
function icl_get_job_original_field_content()
{
global $iclTranslationManagement;
$error_msg = false;
$job_id = false;
if (isset($_POST['tm_editor_job_id'])) {
$job_id = $_POST['tm_editor_job_id'];
} else {
$error_msg = "No job id provided.";
}
if (!$error_msg && isset($_POST['tm_editor_job_id'])) {
$field = $_POST['tm_editor_job_field'];
} else {
$error_msg = "No field provided.";
}
if (!$error_msg && $job_id && isset($field)) {
$job = $iclTranslationManagement->get_translation_job($job_id);
if (isset($job->elements)) {
foreach ($job->elements as $element) {
if (sanitize_title($element->field_type) == $field) {
// if we find a field by that name we need to decode its contents according to its format
$field_contents = TranslationManagement::decode_field_data($element->field_data, $element->field_format);
wp_send_json_success($field_contents);
}
}
} elseif (!$job) {
$error_msg = _("No translation job found: it might have been just cancelled.", 'wpml-translation-management');
} else {
$error_msg = _("No fields found in this translation job.", 'wpml-translation-management');
}
}
if (!$error_msg) {
$error_msg = _("No such field found in the job.", 'wpml-translation-management');
}
wp_send_json_error($error_msg);
}
示例5: foreach
?>
" />
<?php
if (!$element->field_finished && !empty($job->prev_version)) {
?>
<?php
$prev_value = '';
foreach ($job->prev_version->elements as $pel) {
if ($element->field_type == $pel->field_type) {
$prev_value = TranslationManagement::decode_field_data($pel->field_data, $pel->field_format);
}
}
if ($element->field_format != 'csv_base64') {
$diff = wp_text_diff($prev_value, TranslationManagement::decode_field_data($element->field_data, $element->field_format));
}
if (!empty($diff)) {
?>
<p><a href="#" onclick="jQuery(this).parent().next().slideToggle();return false;"><?php
_e('Show Changes', 'sitepress');
?>
</a></p>
<div class="icl_tm_diff">
<?php
echo $diff;
?>
</div>
<?php
}
?>
示例6: get_translation_word_count
/**
* Calculates the word count for each language pair according to the
* given jobs.
*
* @param array $jobs The $jobs used to count the number of words.
*
* @return array The word count, total and finished, for each language
* pair
*/
function get_translation_word_count($jobs)
{
global $sitepress;
$total_word_count = array();
foreach ($jobs as $job) {
$from = $job->source_language_name;
$to = $job->language_name;
// Initializes language pair word count
if (!isset($total_word_count['total'][$from][$to])) {
$total_word_count['total'][$from][$to] = 0;
$total_word_count['finished'][$from][$to] = 0;
}
foreach ($job->elements as $element) {
$icl_tm_original_content = TranslationManagement::decode_field_data($element->field_data, $element->field_format);
$translatable_taxonomies = $sitepress->get_translatable_taxonomies(false, $job->original_post_type);
if ($element->field_type == 'tags' || $element->field_type == 'categories' || in_array($element->field_type, $translatable_taxonomies)) {
foreach ($icl_tm_original_content as $k => $c) {
$word_count = $this->update_word_count($total_word_count, $from, $to, $icl_tm_original_content[$k], $element->field_finished);
//print $icl_tm_original_content[$k] . "($word_count words) <br>";
}
} else {
$word_count = $this->update_word_count($total_word_count, $from, $to, $icl_tm_original_content, $element->field_finished);
//print $icl_tm_original_content . "($word_count words) <br>";
}
}
}
return $total_word_count;
}
示例7: save_all_terms_from_job
/**
* @param $job_id
* @param $post_id
* @param bool $overwrite Sets whether existing translations are to be overwritten or new ones to be created.
* This is parameter is set by the sitepress setting tm_block_retranslating_terms
*
* @return array
*/
public static function save_all_terms_from_job($job_id, $post_id, $overwrite = true)
{
global $iclTranslationManagement, $sitepress;
remove_action('create_term', array($sitepress, 'create_term'), 1);
remove_action('edit_term', array($sitepress, 'create_term'), 1);
/* The first step is to get the new $post object well as the new $job */
/** @noinspection PhpUndefinedMethodInspection */
$job = $iclTranslationManagement->get_translation_job($job_id);
$post_object = get_post($post_id);
/*
* Now we need all taxonomies from which the job contains elements.
* We do only care about translated taxonomies.
* We treat hierarchical and non-hierarchical taxonomies differently.
*/
$taxonomies = get_object_taxonomies($post_object);
$translated_taxonomies = array();
foreach ($taxonomies as $taxonomy) {
if ($sitepress->is_translated_taxonomy($taxonomy)) {
$translated_taxonomies[] = $taxonomy;
}
}
$terms = array();
foreach ($job->elements as $field) {
$field_type = $field->field_type;
/* Naming convention adjustments */
if ($field_type == 'categories') {
$field_type = 'category';
} elseif ($field_type == 'tags') {
$field_type = 'post_tag';
}
if (in_array($field_type, $translated_taxonomies)) {
$terms[$field_type][] = $field;
}
}
/* Here begins the actual saving of the terms
* First the arguments pertaining to a possible scenarios of term saving are set.
*/
$term_save_args = array('lang_code' => $job->language_code, 'source_language' => $job->source_language_code, 'overwrite' => $overwrite);
$result = array();
foreach ($terms as $tax => $fields_array) {
foreach ($fields_array as $flat_terms_field) {
/* The term names are encoded in the job object and have to be decoded */
$translated_terms_array = TranslationManagement::decode_field_data($flat_terms_field->field_data_translated, $flat_terms_field->field_format);
$original_terms_array = TranslationManagement::decode_field_data($flat_terms_field->field_data, $flat_terms_field->field_format);
foreach ($translated_terms_array as $key => $translated_term) {
/* Each term has its own trid.
* We get it by first fetching the original term object by its name and then getting its original taxonomy id
*/
$original_term = $original_terms_array[$key];
//todo: handle this differently for hierarchical terms, otherwise we might run into problems here, generally try moving towards using term_ids
$original_term_object = get_term_by('name', $original_term, $tax);
$term_save_args['term'] = $translated_term;
$term_save_args['trid'] = $sitepress->get_element_trid($original_term_object->term_taxonomy_id, 'tax_' . $tax);
$term_save_args['taxonomy'] = $tax;
$saved_term = self::create_new_term($term_save_args);
$append_result = wp_set_object_terms($post_id, $saved_term['term_id'], $tax, true);
if (!isset($append_result[0]) || $append_result[0] != $saved_term['term_taxonomy_id']) {
$result[] = $flat_terms_field;
} else {
$result[] = $append_result;
}
}
}
self::sync_post_and_taxonomy_terms_language($post_id, $tax);
}
add_action('create_term', array($sitepress, 'create_term'), 1, 2);
add_action('edit_term', array($sitepress, 'create_term'), 1, 2);
return $result;
}
示例8: _e
_e('Click to toggle', 'sitepress');
?>
" class="handlediv">
<br />
</div>
<h3 class="hndle"><?php
echo $element->field_type;
?>
</h3>
<div class="inside">
<?php
/* TRANSLATED CONTENT */
?>
<?php
$icl_tm_original_content = TranslationManagement::decode_field_data($element->field_data, $element->field_format);
$icl_tm_translated_content = TranslationManagement::decode_field_data($element->field_data_translated, $element->field_format);
if ($element->field_type == 'tags' || $element->field_type == 'categories') {
$taxonomy = $element->field_type == 'tags' ? 'post_tag' : 'category';
$icl_tm_translated_taxs[$element->field_type] = TranslationManagement::determine_translated_taxonomies($icl_tm_original_content, $taxonomy, $job->language_code);
}
if (in_array($element->field_type, $sitepress->get_translatable_taxonomies(false, $job->original_post_type))) {
$taxonomy = $element->field_type;
$icl_tm_translated_taxs[$element->field_type] = TranslationManagement::determine_translated_taxonomies($icl_tm_original_content, $taxonomy, $job->language_code);
}
?>
<p><?php
_e('Translated content', 'sitepress');
echo ' - ' . $job->to_language;
?>
</p>
<?php
示例9: save_job_custom_fields
/**
* @param object $job
* @param int $post_id
* @param array $fields
*/
public function save_job_custom_fields($job, $post_id, $fields)
{
$field_names = array();
foreach ($fields as $field_name => $val) {
if ($val == 2) {
// should be translated
// find it in the translation
foreach ($job->elements as $el_data) {
if (strpos($el_data->field_data, (string) $field_name) === 0) {
if (preg_match("/field-(.*?)-name/", $el_data->field_type, $match)) {
$field_names[$field_name] = isset($field_names[$field_name]) ? $field_names[$field_name] : array();
$field_id_string = $match[1];
$explode = explode('-', $field_id_string);
$sub_id = $explode[count($explode) - 1];
$field_translation = false;
foreach ($job->elements as $v) {
if ($v->field_type === 'field-' . $field_id_string) {
$field_translation = TranslationManagement::decode_field_data($v->field_data_translated, $v->field_format);
}
if ($v->field_type == 'field-' . $field_id_string . '-type') {
$field_type = $v->field_data;
}
}
if ($field_translation !== false && isset($field_type) && $field_type === 'custom_field') {
$field_translation = str_replace('�A;', "\n", $field_translation);
// always decode html entities eg decode & to &
$field_translation = html_entity_decode($field_translation);
$contents[$sub_id] = $field_translation;
$field_names[$field_name][$sub_id] = $field_translation;
}
}
}
}
}
}
$this->save_custom_field_values($field_names, $post_id);
}