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; } }
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'); }
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); } } } } }