/**
  * Get translation alternatives for some translation.
  * @param string $token
  */
 function get_translation_alt($token)
 {
     //$ref = getenv('HTTP_REFERER');
     $original = transposh_utils::base64_url_decode($token);
     tp_logger("Inside alt for {$original} ({$token})", 4);
     if (!isset($original)) {
         exit;
     }
     // Check permissions
     if (!$this->transposh->is_translator()) {
         tp_logger("Unauthorized alt request " . $_SERVER['REMOTE_ADDR'], 1);
         header('HTTP/1.0 401 Unauthorized alt request');
         exit;
     }
     tp_logger('Passed check for editable and translator', 4);
     // The original content is encoded as base64 before it is sent (i.e. token), after we
     // decode it should just the same after it was parsed.
     // TODO - check if needed later
     $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
     // add our own custom header - so we will know that we got here
     // TODO - move to ajax file?
     header('Transposh: v-' . TRANSPOSH_PLUGIN_VER . ' db_version-' . DB_VERSION);
     $query = "SELECT translated, lang " . "FROM {$this->translation_table} " . "WHERE original='{$original}' AND source=0 " . "ORDER BY lang";
     tp_logger("query is {$query}");
     $rows = $GLOBALS['wpdb']->get_results($query);
     echo json_encode($rows);
     exit;
 }
Пример #2
0
 function woo_uri_filter($url)
 {
     $lang = transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->transposh->home_url);
     tp_logger('altering woo url to:' . transposh_utils::rewrite_url_lang_param($url, $this->transposh->home_url, $this->transposh->options->enable_permalinks, $lang, $this->transposh->edit_mode));
     return transposh_utils::rewrite_url_lang_param($url, $this->transposh->home_url, $this->transposh->options->enable_permalinks, $lang, $this->transposh->edit_mode);
 }
Пример #3
0
 /**
  * Main function - actually translates a given HTML
  * @param string $string containing HTML
  * @return string Translated content is here
  */
 function fix_html($string)
 {
     // ready our stats
     $this->stats = new parserstats();
     // handler for possible json (buddypress)
     if ($this->might_json) {
         if ($string[0] == '{') {
             $jsoner = json_decode($string);
             if ($jsoner != null) {
                 tp_logger("json detected (buddypress?)", 4);
                 // currently we only handle contents (which buddypress heavily use)
                 if ($jsoner->contents) {
                     $jsoner->contents = $this->fix_html($jsoner->contents);
                     return json_encode($jsoner);
                 }
             }
         }
     }
     // create our dom
     $string = str_replace(chr(0xc2) . chr(0xa0), ' ', $string);
     // annoying NBSPs?
     $this->html = str_get_html($string);
     // mark translateable elements
     if ($this->html->find('html', 0)) {
         $this->html->find('html', 0)->lang = '';
     }
     // Document defined lang may be preset to correct lang, but should be ignored TODO: Better?
     $this->translate_tagging($this->html->root);
     // first fix the html tag itself - we might need to to the same for all such attributes with flipping
     if ($this->html->find('html', 0)) {
         if ($this->dir_rtl) {
             $this->html->find('html', 0)->dir = 'rtl';
         } else {
             $this->html->find('html', 0)->dir = 'ltr';
         }
     }
     if ($this->lang) {
         if ($this->html->find('html', 0)) {
             $this->html->find('html', 0)->lang = $this->lang;
         }
         // add support for <meta name="language" content="<lang>">
         if ($this->html->find('meta[name=language]')) {
             $this->html->find('meta[name=language]')->content = $this->lang;
         }
     }
     // not much point in further processing if we don't have a function that does it
     if ($this->fetch_translate_func == null) {
         return $this->html;
     }
     // fix feed
     if ($this->feed_fix) {
         // fix urls on feed
         tp_logger('fixing rss feed', 3);
         foreach (array('link', 'wfw:commentrss', 'comments') as $tag) {
             foreach ($this->html->find($tag) as $e) {
                 $e->innertext = htmlspecialchars(call_user_func_array($this->url_rewrite_func, array($e->innertext)));
                 // no need to translate anything here
                 unset($e->nodes);
             }
         }
         // guid is not really a url -- in some future, we can check if permalink is true and probably falsify it
         foreach ($this->html->find('guid') as $e) {
             $e->innertext = $e->innertext . '-' . $this->lang;
             unset($e->nodes);
         }
         // fix feed language
         $this->html->find('language', 0)->innertext = $this->lang;
         unset($this->html->find('language', 0)->nodes);
     } else {
         // since this is not a feed, we might have references to such in the <link rel="alternate">
         foreach ($this->html->find('link') as $e) {
             if (strcasecmp($e->rel, 'alternate') == 0 || strcasecmp($e->rel, 'canonical') == 0) {
                 $e->href = call_user_func_array($this->url_rewrite_func, array($e->href));
             }
         }
     }
     // try some prefetching... (//todo - maybe move directly to the phrase create)
     $originals = array();
     if ($this->prefetch_translate_func != null) {
         foreach ($this->html->find('text') as $e) {
             foreach ($e->nodes as $ep) {
                 if ($ep->phrase) {
                     $originals[$ep->phrase] = true;
                 }
             }
         }
         foreach (array('title', 'value') as $title) {
             foreach ($this->html->find('[' . $title . ']') as $e) {
                 if (isset($e->nodes)) {
                     foreach ($e->nodes as $ep) {
                         if ($ep->phrase) {
                             $originals[$ep->phrase] = true;
                         }
                     }
                 }
             }
         }
         foreach ($this->html->find('[content]') as $e) {
             foreach ($e->nodes as $ep) {
                 if ($ep->phrase) {
                     $originals[$ep->phrase] = true;
                 }
             }
         }
         // if we should split, we will split some urls for translation prefetching
         if ($this->split_url_func != null) {
             foreach ($this->atags as $e) {
                 foreach (call_user_func_array($this->split_url_func, array($e->href)) as $part) {
                     $originals[$part] = true;
                 }
             }
             foreach ($this->otags as $e) {
                 foreach (call_user_func_array($this->split_url_func, array($e->value)) as $part) {
                     $originals[$part] = true;
                 }
             }
         }
         call_user_func_array($this->prefetch_translate_func, array($originals, $this->lang));
     }
     //fix urls more
     // WORK IN PROGRESS
     /* foreach ($this->atags as $e) {
        $hrefspans = '';
        foreach (call_user_func_array($this->split_url_func, array($e->href)) as $part) {
        // fix - not for dashes
        list ($source, $translated_text) = call_user_func_array($this->fetch_translate_func, array($part, $this->lang));
        $hrefspans .= $this->create_edit_span($part, $translated_text, $source, true);
        }
        $e->href = call_user_func_array($this->url_rewrite_func, array($e->href));
        $e->outertext .= $hrefspans;
        } */
     // fix urls...
     foreach ($this->atags as $e) {
         if ($e->href) {
             $e->href = call_user_func_array($this->url_rewrite_func, array($e->href));
         }
     }
     foreach ($this->otags as $e) {
         if ($e->value) {
             $e->value = call_user_func_array($this->url_rewrite_func, array($e->value));
         }
     }
     // this is used to reserve spans we cannot add directly (out of body, metas, etc)
     $hiddenspans = '';
     $savedspan = '';
     // actually translate tags
     // texts are first
     foreach ($this->html->find('text') as $e) {
         $replace = array();
         foreach ($e->nodes as $ep) {
             list($source, $translated_text) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang));
             //stats
             $this->stats->total_phrases++;
             if ($translated_text) {
                 $this->stats->translated_phrases++;
                 if ($source == 0) {
                     $this->stats->human_translated_phrases++;
                 }
             }
             if ($this->is_edit_mode || $this->is_auto_translate && $translated_text == null) {
                 if ($ep->inselect) {
                     $savedspan .= $this->create_edit_span($ep->phrase, $translated_text, $source, true, $ep->srclang);
                 } elseif (!$ep->inbody) {
                     $hiddenspans .= $this->create_edit_span($ep->phrase, $translated_text, $source, true, $ep->srclang);
                 } else {
                     $translated_text = $this->create_edit_span($ep->phrase, $translated_text, $source, false, $ep->srclang);
                 }
             }
             // store replacements
             if ($translated_text) {
                 $replace[] = array($translated_text, $ep);
             }
         }
         // do replacements in reverse
         foreach (array_reverse($replace) as $epag) {
             list($replacetext, $epg) = $epag;
             $e->outertext = substr_replace($e->outertext, $replacetext, $epg->start, $epg->len);
         }
         // this adds saved spans to the first not in select element which is in the body
         if ($e->nodes && !$ep->inselect && $savedspan && $ep->inbody) {
             // (TODO: might not be...?)
             $e->outertext = $savedspan . $e->outertext;
             $savedspan = '';
         }
     }
     // now we handle the title attributes (and the value of submit buttons)
     $hidden_phrases = array();
     foreach (array('title', 'value') as $title) {
         foreach ($this->html->find('[' . $title . ']') as $e) {
             $replace = array();
             $span = '';
             // when we already have a parent outertext we'll have to update it directly
             if (isset($e->parent->_[HDOM_INFO_OUTER])) {
                 $saved_outertext = $e->outertext;
             }
             tp_logger("{$title}-original: {$e}->{$title}}", 4);
             if (isset($e->nodes)) {
                 foreach ($e->nodes as $ep) {
                     if ($ep->tag == 'phrase') {
                         list($source, $translated_text) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang));
                         // more stats
                         $this->stats->total_phrases++;
                         if ($ep->inbody) {
                             $this->stats->hidden_phrases++;
                         } else {
                             $this->stats->meta_phrases++;
                         }
                         if ($translated_text) {
                             $this->stats->translated_phrases++;
                             if ($ep->inbody) {
                                 $this->stats->hidden_translated_phrases++;
                             } else {
                                 $this->stats->meta_translated_phrases++;
                             }
                             if ($source == 0) {
                                 $this->stats->human_translated_phrases++;
                             }
                         }
                         if (($this->is_edit_mode || $this->is_auto_translate && $translated_text == null) && $ep->inbody) {
                             // prevent duplicate translation (title = text)
                             if (strpos($e->innertext, transposh_utils::base64_url_encode($ep->phrase)) === false) {
                                 //no need to translate span the same hidden phrase more than once
                                 if (!in_array($ep->phrase, $hidden_phrases)) {
                                     $this->stats->hidden_translateable_phrases++;
                                     $span .= $this->create_edit_span($ep->phrase, $translated_text, $source, true, $ep->srclang);
                                     //    logger ($span);
                                     $hidden_phrases[] = $ep->phrase;
                                 }
                             }
                         }
                         // if we need to replace, we store this
                         if ($translated_text) {
                             $replace[$translated_text] = $ep;
                         }
                     }
                 }
             }
             // and later replace
             foreach (array_reverse($replace, true) as $replace => $epg) {
                 $e->title = substr_replace($e->title, $replace, $epg->start, $epg->len);
             }
             $e->outertext .= $span;
             // this is where we update in the outercase issue
             if (isset($e->parent->_[HDOM_INFO_OUTER])) {
                 $e->parent->outertext = implode($e->outertext, explode($saved_outertext, $e->parent->outertext, 2));
             }
         }
     }
     // now we handle the meta content - which is simpler because they can't be edited or auto-translated in place
     // we also don't expect any father modifications here
     // so we now add all those spans right before the <body> tag end
     foreach ($this->html->find('[content]') as $e) {
         $right = '';
         $newtext = '';
         foreach ($e->nodes as $ep) {
             if ($ep->tag == 'phrase') {
                 // even more stats
                 $this->stats->total_phrases++;
                 $this->stats->meta_phrases++;
                 list($source, $translated_text) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang));
                 if ($translated_text) {
                     $this->stats->translated_phrases++;
                     $this->stats->meta_translated_phrases++;
                     if ($source == 0) {
                         $this->stats->human_translated_phrases++;
                     }
                     list($left, $right) = explode($ep->phrase, $e->content, 2);
                     $newtext .= $left . $translated_text;
                     $e->content = $right;
                 }
                 if ($this->is_edit_mode) {
                     $hiddenspans .= $this->create_edit_span($ep->phrase, $translated_text, $source, true, $ep->srclang);
                 }
                 if (!$translated_text && $this->is_auto_translate && !$this->is_edit_mode) {
                     tp_logger('untranslated meta for ' . $ep->phrase . ' ' . $this->lang);
                     if ($this->is_edit_mode || $this->is_auto_translate) {
                         // FIX
                     }
                 }
             }
         }
         if ($newtext) {
             $e->content = $newtext . $right;
             tp_logger("content-phrase: {$newtext}", 4);
         }
     }
     if ($hiddenspans) {
         $body = $this->html->find('body', 0);
         if ($body != null) {
             $body->lastChild()->outertext .= $hiddenspans;
         }
     }
     // This adds a meta tag with our statistics json-encoded inside...
     $this->stats->stop_timing();
     $head = $this->html->find('head', 0);
     if ($this->edit_span_created) {
         if ($head != null) {
             $head->lastChild()->outertext .= $this->added_header;
         }
     }
     //exit;
     if ($head != null) {
         $head->lastChild()->outertext .= "\n<meta name=\"translation-stats\" content='" . json_encode($this->stats) . "'/>";
     }
     // we make sure that the result is clear from our shananigans
     return str_replace(array(TP_GTXT_BRK, TP_GTXT_IBRK, TP_GTXT_BRK_CLOSER, TP_GTXT_IBRK_CLOSER), '', $this->html->outertext);
     // Changed because of places where tostring failed
     //return $this->html;
     //return $this->html->outertext;
 }
Пример #4
0
    /**
     * Insert supported languages section in admin page
     * @param string $data
     */
    function tp_langs()
    {
        // we need some styles
        global $wp_locale;
        if ($wp_locale->text_direction == 'rtl') {
            echo '<style type="text/css">
	#sortable li, #default_lang li { float: right !important;}
        .logoicon {
            float:left !important;
        }
        </style>';
        }
        // this is the default language location
        list($langname, $langorigname, $flag) = explode(",", transposh_consts::$languages[$this->transposh->options->default_language]);
        echo '<div id="default_lang" style="overflow:auto;padding-bottom:10px;">';
        $this->header(__('Default Language (drag another language here to make it default)', TRANSPOSH_TEXT_DOMAIN), 'languages');
        echo '<ul id="default_list"><li id="' . $this->transposh->options->default_language . '" class="languages">' . transposh_utils::display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, $langorigname, false) . '<input type="hidden" name="languages[]" value="' . $this->transposh->options->default_language . '" />' . '&nbsp;<span class="langname">' . $langorigname . '</span><span class="langname hidden">' . $langname . '</span></li>';
        echo '</ul></div>';
        // list of languages
        echo '<div style="overflow:auto; clear: both;">';
        $this->header(__('Available Languages (Click to toggle language state - Drag to sort in the widget)', TRANSPOSH_TEXT_DOMAIN));
        $this->header(__('Only first five will be saved! Upgrade to full free version by choosing the option at the settings', TRANSPOSH_TEXT_DOMAIN));
        echo '<ul id="sortable">';
        foreach ($this->transposh->options->get_sorted_langs() as $langcode => $langrecord) {
            tp_logger($langcode, 5);
            list($langname, $langorigname, $flag) = explode(",", $langrecord);
            echo '<li id="' . $langcode . '" class="languages ' . ($this->transposh->options->is_active_language($langcode) || $this->transposh->options->is_default_language($langcode) ? "lng_active" : "") . '"><div style="float:' . $this->localeleft . '">' . transposh_utils::display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, false) . '<input type="hidden" name="languages[]" value="' . $langcode . ($this->transposh->options->is_active_language($langcode) ? ",v" : ",") . '" />' . '&nbsp;<span class="langname">' . $langorigname . '</span><span class="langname hidden">' . $langname . '</span></div>';
            if (in_array($langcode, transposh_consts::$google_languages)) {
                echo '<img width="16" height="16" alt="g" class="logoicon" title="' . esc_attr__('Language supported by google translate', TRANSPOSH_TEXT_DOMAIN) . '" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/googleicon.png"/>';
            }
            if (in_array($langcode, transposh_consts::$bing_languages)) {
                echo '<img width="16" height="16" alt="b" class="logoicon" title="' . esc_attr__('Language supported by bing translate', TRANSPOSH_TEXT_DOMAIN) . '" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/bingicon.png"/>';
            }
            if (in_array($langcode, transposh_consts::$apertium_languages)) {
                echo '<img width="16" height="16" alt="a" class="logoicon" title="' . esc_attr__('Language supported by apertium translate', TRANSPOSH_TEXT_DOMAIN) . '" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/apertiumicon.png"/>';
            }
            if (in_array($langcode, transposh_consts::$oht_languages)) {
                echo '<img width="16" height="16" alt="a" class="logoicon" title="' . esc_attr__('Language supported by one hour translation', TRANSPOSH_TEXT_DOMAIN) . '" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/ohticon.png"/>';
            }
            if (in_array($langcode, transposh_consts::$rtl_languages)) {
                echo '<img width="16" height="16" alt="r" class="logoicon" title="' . esc_attr__('Language is written from right to left', TRANSPOSH_TEXT_DOMAIN) . '" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/rtlicon.png"/>';
            }
            echo '</li>';
        }
        echo "</ul></div>";
        // options to play with
        echo '<div style="clear: both;">' . __('Display options:', TRANSPOSH_TEXT_DOMAIN) . '<br/><ul style="list-style-type: disc; margin-' . $this->localeleft . ':20px;font-size:11px">';
        echo '<li><a href="#" id="changename">' . __('Toggle names of languages between English and Original', TRANSPOSH_TEXT_DOMAIN) . '</a></li>';
        echo '<li><a href="#" id="selectall">' . __('Make all languages active', TRANSPOSH_TEXT_DOMAIN) . '</a></li>';
        echo '<li><a href="#" id="sortname">' . __('Sort by language name', TRANSPOSH_TEXT_DOMAIN) . '</a></li>';
        echo '<li><a href="#" id="sortiso">' . __('Sort by lSO code', TRANSPOSH_TEXT_DOMAIN) . '</a></li></ul>';
        echo '</div>';
    }
Пример #5
0
 public static function rewrite_url_lang_param($url, $home_url, $enable_permalinks_rewrite, $lang, $is_edit, $use_params_only = FALSE)
 {
     tp_logger("rewrite old url: {$url}, permalinks: {$enable_permalinks_rewrite}, lang: {$lang}, is_edit: {$is_edit}, home_url: {$home_url}", 5);
     $newurl = str_replace('&#038;', '&', $url);
     $newurl = html_entity_decode($newurl, ENT_NOQUOTES);
     $parsedurl = @parse_url($newurl);
     // if we are dealing with some other url, we won't touch it!
     if (isset($parsedurl['host']) && !($parsedurl['host'] == @parse_url($home_url, PHP_URL_HOST))) {
         return $url;
     }
     //remove prev lang and edit params - from query string - reserve other params
     if (isset($parsedurl['query'])) {
         $params = explode('&', $parsedurl['query']);
         foreach ($params as $key => $param) {
             if (stripos($param, LANG_PARAM) === 0) {
                 unset($params[$key]);
             }
             if (stripos($param, EDIT_PARAM) === 0) {
                 unset($params[$key]);
             }
         }
     }
     // clean the query
     unset($parsedurl['query']);
     // remove the language from the url permalink (if in start of path, and is a defined language)
     $gluebackhome = false;
     $home_path = rtrim(@parse_url($home_url, PHP_URL_PATH), "/");
     tp_logger("home: {$home_path} " . $parsedurl['path'], 5);
     if ($home_path && strpos($parsedurl['path'], $home_path) === 0) {
         tp_logger("homein!: {$home_path}", 5);
         $parsedurl['path'] = substr($parsedurl['path'], strlen($home_path));
         $gluebackhome = true;
     }
     if (strlen($parsedurl['path']) > 2) {
         $secondslashpos = strpos($parsedurl['path'], "/", 1);
         if (!$secondslashpos) {
             $secondslashpos = strlen($parsedurl['path']);
         }
         $prevlang = substr($parsedurl['path'], 1, $secondslashpos - 1);
         if (isset(transposh_consts::$languages[$prevlang])) {
             tp_logger("prevlang: " . $prevlang, 4);
             $parsedurl['path'] = substr($parsedurl['path'], $secondslashpos);
         }
     }
     // override the use only params - admin configured system to not touch permalinks
     if (!$enable_permalinks_rewrite) {
         $use_params_only = TRUE;
     }
     //$params ="";
     if ($is_edit) {
         $params['edit'] = EDIT_PARAM . '=1';
     }
     if ($use_params_only && $lang) {
         $params['lang'] = LANG_PARAM . "={$lang}";
     } else {
         if ($lang) {
             if (!$parsedurl['path']) {
                 $parsedurl['path'] = "/";
             }
             $parsedurl['path'] = "/" . $lang . $parsedurl['path'];
         }
     }
     if ($gluebackhome) {
         $parsedurl['path'] = $home_path . $parsedurl['path'];
     }
     // insert params to url
     if (isset($params) && $params) {
         $parsedurl['query'] = implode('&', $params);
         tp_logger($params, 4);
     }
     // more cleanups
     //$url = preg_replace("/&$/", "", $url);
     //$url = preg_replace("/\?$/", "", $url);
     //    $url = htmlentities($url, ENT_NOQUOTES);
     $url = transposh_utils::glue_url($parsedurl);
     tp_logger("new url: {$url}", 5);
     return $url;
 }
Пример #6
0
 /**
  * Creates the widget html
  * @param array $args Contains such as $before_widget, $after_widget, $before_title, $after_title, etc
  */
 function widget($args, $instance, $extcall = false)
 {
     // extract args given by wordpress
     extract($args);
     tp_logger($args, 4);
     // we load the class needed and get its base name for later
     $class = $this->load_widget($instance['widget_file']);
     if (!class_exists($class)) {
         echo __('Transposh subwidget was not loaded correctly', TRANSPOSH_TEXT_DOMAIN) . ": {$class}";
     }
     $clean_page = $this->transposh->get_clean_url();
     tp_logger("WIDGET: clean page url: {$clean_page}", 4);
     $widget_args = $this->create_widget_args($clean_page);
     // at this point the widget args are ready
     tp_logger('Enter widget', 4);
     // widget default title
     //echo $before_widget . $before_title . __('Translation', TRANSPOSH_TEXT_DOMAIN) . $after_title; - hmm? po/mo?
     if (isset($before_widget)) {
         echo $before_widget;
     }
     if ($instance['title']) {
         /* TRANSLATORS: no need to translate this string */
         echo $before_title . __($instance['title'], TRANSPOSH_TEXT_DOMAIN) . $after_title;
     }
     // actually run the external widget code
     //if (version_compare(PHP_VERSION, '5.3.0','gt')) { (for the future)
     //   $class::tp_widget_do($widget_args);
     //} else {
     $tmpclass = new $class();
     $tmpclass->tp_widget_do($widget_args);
     if ($extcall) {
         $tmpclass->tp_widget_css($instance['widget_file'], $this->transposh->transposh_plugin_dir, $this->transposh->transposh_plugin_url);
         $tmpclass->tp_widget_js($instance['widget_file'], $this->transposh->transposh_plugin_dir, $this->transposh->transposh_plugin_url);
         // don't display edit and other things for shortcode embedding
         if (isset($after_widget)) {
             echo $after_widget;
         }
         // increase the number of calls for unique IDs
         self::$draw_calls++;
         return;
     }
     //}
     //at least one language showing - add the edit box if applicable
     if (!empty($widget_args)) {
         // this is the set default language line
         if ($this->transposh->options->widget_allow_set_deflang) {
             if (isset($_COOKIE['TR_LNG']) && $_COOKIE['TR_LNG'] != $this->transposh->target_language || !isset($_COOKIE['TR_LNG']) && !$this->transposh->options->is_default_language($this->transposh->target_language)) {
                 echo '<a id="' . SPAN_PREFIX . 'setdeflang' . self::$draw_calls . '" class="' . SPAN_PREFIX . 'setdeflang' . '" onClick="return false;" href="' . admin_url('admin-ajax.php') . '?action=tp_cookie_bck">' . __('Set as default language', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>';
             }
         }
         // add the edit checkbox only for translators for languages marked as editable
         if ($this->transposh->is_editing_permitted()) {
             $ref = transposh_utils::rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $this->transposh->options->is_default_language($this->transposh->target_language) ? "" : $this->transposh->target_language, !$this->transposh->edit_mode);
             echo '<input type="checkbox" name="' . EDIT_PARAM . '" value="1" ' . ($this->transposh->edit_mode ? 'checked="checked" ' : '') . ' onclick="document.location.href=\'' . $ref . '\';"/>&nbsp;Edit Translation';
         }
     } else {
         //no languages configured - error message
         echo '<p>No languages available for display. Check the Transposh settings (Admin).</p>';
     }
     // Now this is a comment for those wishing to remove our logo (tplogo.png) and link (transposh.org) from the widget
     // first - according to the gpl, you may do so - but since the code has changed - please make in available under the gpl
     // second - we did invest a lot of time and effort into this, and the link is a way to help us grow and show your appreciation, if it
     // upsets you, feel more than free to move this link somewhere else on your page, such as the footer etc.
     // third - feel free to write your own widget, the translation core will work
     // forth - you can ask for permission, with a good reason, if you contributed to the code - it's a good enough reason :)
     // fifth - if you just delete the following line, it means that you have little respect to the whole copyright thing, which as far as we
     // understand means that by doing so - you are giving everybody else the right to do the same and use your work without any attribution
     // last - you can now remove the logo in exchange to a few percentage of ad and affiliate revenues on your pages, isn't that better?
     $plugpath = parse_url($this->transposh->transposh_plugin_url, PHP_URL_PATH);
     echo '<div id="' . SPAN_PREFIX . 'credit' . self::$draw_calls . '">';
     echo '</div>';
     if (isset($after_widget)) {
         echo $after_widget;
     }
     // increase the number of calls for unique IDs
     self::$draw_calls++;
 }
Пример #7
0
 /**
  * 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);
 }
Пример #8
0
 function on_ajax_nopriv_tp_cookie_bck()
 {
     setcookie('TR_LNG', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN);
     if ($_SERVER['HTTP_REFERER']) {
         $this->tp_redirect($_SERVER['HTTP_REFERER']);
     } else {
         $this->tp_redirect($my_transposh_plugin->home_url);
     }
     die;
 }