protected static function save_hash_on_upload($object_id) { $post = get_post($object_id); $document_id = 'lingotek_hash_' . $post->ID; $new_hash = md5(Lingotek_Group_Post::get_content($post)); wp_insert_term($document_id, 'lingotek_hash', array('description' => $new_hash)); wp_set_object_terms($post->ID, $document_id, 'lingotek_hash'); }
protected function post_hash_has_changed($post_after) { if ($post_after->post_status === 'trash') { return false; } $document_id = 'lingotek_hash_' . $post_after->ID; $new_hash = md5(Lingotek_Group_Post::get_content($post_after)); $old_term = $this->get_post_hash($post_after->ID); $old_hash = $old_term->description; // new or updated page if ($old_hash === null || strcmp($new_hash, $old_hash)) { if (empty($old_term)) { wp_insert_term($document_id, 'lingotek_hash', array('description' => $new_hash)); } else { wp_update_term((int) $old_term->term_id, 'lingotek_hash', array('description' => $new_hash)); } wp_set_object_terms($post_after->ID, $document_id, 'lingotek_hash'); return true; } else { return false; } }
public function upload_post($post_id) { $post = get_post($post_id); $language = $this->pllm->get_post_language($post_id); if (empty($post) || empty($language)) { return; } $profile = self::get_profile($post->post_type, $language, $post_id); if ('disabled' == $profile['profile']) { return; } $client = new Lingotek_API(); $external_url = add_query_arg(array('lingotek' => 1, 'document_id' => '{document_id}', 'locale' => '{locale}', 'type' => 'get'), site_url()); $params = array('title' => $post->post_title, 'content' => Lingotek_Group_Post::get_content($post), 'locale_code' => $language->lingotek_locale, 'project_id' => self::get_profile_option('project_id', $post->post_type, $language, false, $post_id), 'workflow_id' => self::get_profile_option('workflow_id', $post->post_type, $language, false, $post_id), 'external_url' => $external_url); $filter_ids = array(); if (self::get_profile_option('primary_filter_id', $post->post_type, $language, false, $post_id)) { $filter_ids['fprm_id'] = self::get_profile_option('primary_filter_id', $post->post_type, $language, false, $post_id); } if (self::get_profile_option('secondary_filter_id', $post->post_type, $language, false, $post_id)) { $filter_ids['fprm_subfilter_id'] = self::get_profile_option('secondary_filter_id', $post->post_type, $language, false, $post_id); } $params = array_merge($params, $filter_ids); if (($document = $this->get_group('post', $post_id)) && 'edited' == $document->status) { $document->patch($post->post_title, $post, $external_url, $filter_ids); } elseif (!Lingotek_Group::$creating_translation && !self::$copying_post) { $document_id = $client->upload_document($params, $post->ID); if ($document_id) { Lingotek_Group_Post::create($post->ID, $language, $document_id); // If a translation profile has targets set to copy then copy them $targets_to_copy = $this->targets_to_be_copied($profile); if (!empty($targets_to_copy)) { foreach ($targets_to_copy as $target) { $this->copy_post($post, $target); } } } } }
global $polylang; $items = array(); if (!empty($_POST)) { check_admin_referer('lingotek-custom-fields', '_wpnonce_lingotek-custom-fields'); if (!empty($_POST['submit'])) { $arr = empty($_POST['settings']) ? array() : $_POST['settings']; update_option('lingotek_custom_fields', $arr); add_settings_error('lingotek_custom_fields_save', 'custom_fields', __('Your <i>Custom Fields</i> were sucessfully saved.', 'wp-lingotek'), 'updated'); } if (!empty($_POST['refresh'])) { Lingotek_Group_Post::get_updated_meta_values(); add_settings_error('lingotek_custom_fields_refresh', 'custom_fields', __('Your <i>Custom Fields</i> were sucessfully identified.', 'wp-lingotek'), 'updated'); } settings_errors(); } $items = Lingotek_Group_Post::get_cached_meta_values(); ?> <h3><?php _e('Custom Field Configuration', 'wp-lingotek'); ?> </h3> <p class="description"><?php _e('Custom Fields can be translated, copied, or ignored. Click "Refresh Custom Fields" to identify and enable your custom fields.', 'wp-lingotek'); ?> </p> <form id="lingotek-custom-fields" method="post" action="admin.php?page=wp-lingotek_manage&sm=custom-fields" class="validate"><?php wp_nonce_field('lingotek-custom-fields', '_wpnonce_lingotek-custom-fields'); $table = new Lingotek_Custom_Fields_Table(); $table->prepare_items($items);
<?php global $polylang; foreach ($polylang->model->get_translated_post_types() as $post_type) { $post_type_object = get_post_type_object($post_type); $data[$post_type] = array('type' => $post_type, 'name' => $post_type_object->labels->name, 'fields' => array('label' => Lingotek_Group_Post::get_content_type_fields($post_type))); } foreach ($polylang->model->get_translated_taxonomies() as $tax) { $taxonomy = get_taxonomy($tax); $data[$tax] = array('type' => $tax, 'name' => $taxonomy->labels->name, 'fields' => array('label' => Lingotek_Group_Term::get_content_type_fields($tax))); } $data['string'] = array('type' => 'string', 'name' => __('Strings', 'wp-lingotek')); if (empty($_POST)) { $content_types = get_option('lingotek_content_type'); } else { check_admin_referer('lingotek-content-types', '_wpnonce_lingotek-content-types'); $profiles = array_keys(get_option('lingotek_profiles')); foreach ($data as $key => $item) { if (isset($data[$key]['name'])) { if (in_array($_POST[$key]['profile'], $profiles)) { $content_types[$key]['profile'] = $_POST[$key]['profile']; } foreach ($polylang->model->get_languages_list() as $language) { if (isset($_POST[$key]['sources'][$language->slug]) && in_array($_POST[$key]['sources'][$language->slug], $profiles)) { $content_types[$key]['sources'][$language->slug] = $_POST[$key]['sources'][$language->slug]; } } } if (isset($data[$key]['fields'])) { foreach ($data[$key]['fields']['label'] as $key1 => $arr) { if (is_array($arr)) {