/** * Return the relation ID for the given blog ID and term taxonomy ID. * * @param int $site_id Blog ID. * @param int $term_taxonomy_id Term taxonomy ID. * * @return string */ public function get_relation_id($site_id, $term_taxonomy_id) { $translation_ids = $this->content_relations->get_existing_translation_ids($site_id, 0, $term_taxonomy_id, 0, 'term'); if (!$translation_ids) { return ''; } $relation = reset($translation_ids); return $relation['ml_source_blogid'] . '-' . $relation['ml_source_elementid']; }
/** * @param int $site_id * @param int $term_id // currently edited term * @return int */ public function get_current_term($site_id, $term_id) { if (!isset($this->site_terms[$term_id])) { $this->site_terms[$term_id] = $this->content_relations->get_relations($this->current_site_id, $term_id, 'term'); } if (empty($this->site_terms[$term_id][$site_id])) { return 0; } return $this->site_terms[$term_id][$site_id]; }
/** * @param array $existing * @param int $source_term_taxonomy_id * @param int $target_site_id * @param int $target_term_taxonomy_id * * @return bool */ private function update_terms(array $existing, $source_term_taxonomy_id, $target_site_id, $target_term_taxonomy_id) { if (isset($existing[$target_site_id]) && $existing[$target_site_id] === $target_term_taxonomy_id) { return TRUE; } if (0 !== $target_term_taxonomy_id) { return $this->content_relations->set_relation($this->current_site_id, $target_site_id, $source_term_taxonomy_id, $target_term_taxonomy_id, 'term'); } $translation_ids = $this->content_relations->get_translation_ids($this->current_site_id, $target_site_id, $source_term_taxonomy_id, $target_term_taxonomy_id, 'term'); return $this->content_relations->delete_relation($translation_ids['ml_source_blogid'], $target_site_id, $translation_ids['ml_source_elementid'], 0, 'term'); }
/** * Gets the relevant multisite post id from singlesite post. * * @param $post * @param $blog * * @return int */ public function get_multisite_id($post, $blog) { $rel = $this->content_relations->get_relations(Wpml2mlp_Helper::get_default_blog(), Wpml2mlp_Helper::get_default_post_ID($post), $post->post_type); $blog_id = (int) $blog['blog_id']; $multisite_id = -1; foreach ($rel as $key => $value) { if ($key == $blog_id) { $multisite_id = $value; break; } } return $multisite_id; }
/** * @param array $existing * @param int $source_term_taxonomy_id * @param int $target_site_id * @param int $target_term_taxonomy_id * * @return bool */ private function update_terms(array $existing, $source_term_taxonomy_id, $target_site_id, $target_term_taxonomy_id) { // There's nothing to do here if (-1 === $target_term_taxonomy_id) { return TRUE; } if (isset($existing[$target_site_id]) && $existing[$target_site_id] === $target_term_taxonomy_id) { return TRUE; } $translation_ids = $this->content_relations->get_translation_ids($this->current_site_id, $target_site_id, $source_term_taxonomy_id, $target_term_taxonomy_id, 'term'); if ($translation_ids['ml_source_blogid'] !== $this->current_site_id) { $target_site_id = $this->current_site_id; if (0 !== $target_term_taxonomy_id) { $target_term_taxonomy_id = $source_term_taxonomy_id; } } // Delete a relation if (0 === $target_term_taxonomy_id) { return $this->content_relations->delete_relation($translation_ids['ml_source_blogid'], $target_site_id, $translation_ids['ml_source_elementid'], 0, 'term'); } return $this->content_relations->set_relation($translation_ids['ml_source_blogid'], $target_site_id, $translation_ids['ml_source_elementid'], $target_term_taxonomy_id, 'term'); }
/** * Returns an array with site ID as keys and content ID as values. * * @param int $site_id * @param int $content_id * @param string $type * @return array */ public function get_related_content_ids($site_id, $content_id, $type) { return $this->content_relations->get_relations($site_id, $content_id, $type); }
/** * set the source id of the element * * @param int $source_content_id ID of current element * @param int $remote_site_id ID of remote site * @param int $remote_content_id ID of remote content * @return void */ public function set_linked_element($source_content_id, $remote_site_id, $remote_content_id) { $this->content_relations->set_relation($this->source_site_id, $remote_site_id, $source_content_id, $remote_content_id, 'post'); }