/** * Loop through all the post phrases and return them in json formatted script * @param int $postID */ function get_post_phrases($postID) { // Some security, to avoid others from seeing private posts // fake post for tags if ($postID == -555) { $phrases = $this->get_tags(); $title = "tags"; } else { if (!current_user_can('edit_post', $postID)) { return; } global $post; // thid is needed because some of the functions below expect it... $post = get_post($postID); // Display filters $title = apply_filters('the_title', $post->post_title); $content = apply_filters('the_content', $post->post_content); $the_content_feed = apply_filters('the_content_feed', $content); $excerpt = apply_filters('get_the_excerpt', $post->post_excerpt); $excerpt_rss = apply_filters('the_excerpt_rss', $excerpt); //TODO - get comments text $parser = new parser(); $phrases = $parser->get_phrases_list($content); $phrases2 = $parser->get_phrases_list($title); $phrases3 = $parser->get_phrases_list($the_content_feed); $phrases4 = $parser->get_phrases_list($excerpt); $phrases5 = $parser->get_phrases_list($excerpt_rss); // Merge the two arrays for traversing $phrases = array_merge($phrases, $phrases2, $phrases3, $phrases4, $phrases5); tp_logger($phrases, 4); // Add phrases from permalink if ($this->transposh->options->enable_url_translate) { $permalink = get_permalink($postID); $permalink = substr($permalink, strlen($this->transposh->home_url) + 1); $parts = explode('/', $permalink); foreach ($parts as $part) { if (!$part || is_numeric($part)) { continue; } $part = str_replace('-', ' ', $part); $phrases[] = urldecode($part); } } } // We provide the post title here $json['posttitle'] = $title; // and all languages we might want to target $json['langs'] = array(); foreach ($phrases as $key) { foreach (explode(',', $this->transposh->options->viewable_languages) as $lang) { // if this isn't the default language or we specifically allow default language translation, we will seek this out... // as we don't normally want to auto-translate the default language -FIX THIS to include only correct stuff, how? if (!$this->transposh->options->is_default_language($lang) || $this->transposh->options->enable_default_translate) { // There is no point in returning phrases, languages pairs that cannot be translated if (in_array($lang, transposh_consts::$bing_languages) || in_array($lang, transposh_consts::$google_languages) || in_array($lang, transposh_consts::$apertium_languages)) { list($source, $translation) = $this->transposh->database->fetch_translation($key, $lang); if (!$translation) { // p stands for phrases, l stands for languages, t is token if (!@is_array($json['p'][$key]['l'])) { $json['p'][$key]['l'] = array(); } array_push($json['p'][$key]['l'], $lang); if (!in_array($lang, $json['langs'])) { array_push($json['langs'], $lang); } } } } } // only if a languages list was created we'll need to translate this if (@is_array($json['p'][$key]['l'])) { $json['p'][$key]['t'] = transposh_utils::base64_url_encode($key); @$json['length']++; } } // the header helps with debugging header("Content-type: text/javascript"); echo json_encode($json); }