Changeset 667 for trunk


Ignore:
Timestamp:
11/20/2011 10:20:48 AM (6 months ago)
Author:
ofer
Message:

Attack of the paid APIs! This commit changes the ways Transposh handles MSN and Google translate, improving the google proxy and allowing use of external keys. Keys are OPTIONAL! We have also improved the translate all feature and changed the entire ajax workflow to the wordpress engine. Should prove less 500 error prune. And we want more money too!

Location:
trunk/WordPress/plugin/transposh
Files:
12 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/core/constants.php

    r663 r667  
    6161        'cs' => 'Czech,ČeÅ¡tina,cz,cs_CZ', 
    6262        'da' => 'Danish,Dansk,dk,da_DK', 
    63         'nl' => 'Dutch,Nederlands,nl,', 
     63        'nl' => 'Dutch,Nederlands,nl,nl_NL', 
    6464        'eo' => 'Esperanto,Esperanto,esperanto,', 
    6565        'et' => 'Estonian,Eesti keel,ee,', 
     
    116116    // (got using - var langs =''; jQuery.each(google.language.Languages,function(){if (google.language.isTranslatable(this)) {langs += this +'|'}}); console.log(langs); - fixed for our codes) 
    117117    // @updated 2010-Oct-01 (hy,az,eu,ka,la,ur) 
     118    // @updated 2011-Nov-04 
    118119    // $google_languages = array('en', 'af', 'sq', 'ar', 'hy', 'az', 'eu', 'be', 'bg', 'ca', 'zh', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'gl', 'ka', 'de', 'el', 'ht', 'he', 'hi', 'hu', 'id', 'it', 'is', 'ga', 'ja', 'ko', 'lv', 'lt', 'mk', 'ms', 'mt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'sl', 'es', 'sw', 'sv', 'tl', 'th', 'tr', 'uk', 'ur', 'vi', 'cy', 'yi'); 
    119     public static $google_languages = array('en', 'af', 'sq', 'ar', 'be', 'bg', 'ca', 'zh', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'gl', 'de', 'el', 'ht', 'he', 'hi', 'hu', 'id', 'it', 'is', 'ga', 'ja', 'ko', 'lv', 'lt', 'mk', 'ms', 'mt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'sl', 'es', 'sw', 'sv', 'tl', 'th', 'tr', 'uk', 'vi', 'cy', 'yi'); 
    120     public static $google_proxied_languages = array('hy', 'az', 'eu', 'ka', 'la', 'ur', 'ta', 'te', 'kn', 'bn', 'gu'); 
     120    public static $google_languages = array('en', 'af', 'sq', 'ar', 'be', 'bg', 'ca', 'zh', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'gl', 'de', 'el', 'ht', 'he', 'hi', 'hu', 'id', 'it', 'is', 'ga', 'ja', 'ko', 'lv', 'lt', 'mk', 'ms', 'mt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'sl', 'es', 'sw', 'sv', 'tl', 'th', 'tr', 'uk', 'vi', 'cy', 'yi', 'hy', 'az', 'eu', 'ka', 'la', 'ur', 'ta', 'te', 'kn', 'bn', 'gu'); 
     121//    public static $google_languages = array('en', 'af', 'sq', 'ar', 'be', 'bg', 'ca', 'zh', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'gl', 'de', 'el', 'ht', 'he', 'hi', 'hu', 'id', 'it', 'is', 'ga', 'ja', 'ko', 'lv', 'lt', 'mk', 'ms', 'mt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'sl', 'es', 'sw', 'sv', 'tl', 'th', 'tr', 'uk', 'vi', 'cy', 'yi'); 
     122//    public static $google_proxied_languages = array('hy', 'az', 'eu', 'ka', 'la', 'ur', 'ta', 'te', 'kn', 'bn', 'gu'); 
    121123    // Bing supported languages 
    122124    // (got this using Microsoft.Translator.GetLanguages() - fixed to match our codes) 
     
    137139//Define for transposh plugin version 
    138140define('TRANSPOSH_PLUGIN_VER', '%VERSION%'); 
     141 
     142define('JQUERYUI_VER', '1.8.16'); 
    139143 
    140144//Define segment id prefix, will be included in span tag. also used as class identifier 
  • trunk/WordPress/plugin/transposh/core/parser.php

    r665 r667  
    399399                // this is the case of B2 or B2, 
    400400                if (($start == $pos) || ($this->is_white_space($string[$pos - 1]) 
    401                         || ($this->is_sentence_breaker($string[$pos + $num_len - 1], $string[$pos + $num_len], $string[$pos + $num_len + 1]))) && 
     401                        || ($this->is_sentence_breaker(@$string[$pos + $num_len - 1], @$string[$pos + $num_len], @$string[$pos + $num_len + 1]))) && 
    402402                        ($this->is_white_space(@$string[$pos + $num_len]) || $this->is_sentence_breaker(@$string[$pos + $num_len], @$string[$pos + $num_len + 1], @$string[$pos + $num_len + 2]))) { 
    403403                    // we will now compensate on the number followed by breaker case, if we need to 
     
    865865            if ($body != null) $body->lastChild()->outertext .= $hiddenspans; 
    866866        } 
    867         // only in 5 out of 100 pages, with just translated pages, we might show an ad for transposh 
    868         if ($this->allow_ad && !$this->default_lang && mt_rand(1, 100) > 95) { 
     867        // we might show an ad for transposh in some cases 
     868        if (($this->allow_ad && !$this->default_lang && mt_rand(1, 100) > 95) || // 5 of 100 for translated non default language pages 
     869            ($this->allow_ad && $this->default_lang && mt_rand(1, 100) > 99) || // 1 of 100 for translated default languages pages 
     870            (!$this->allow_ad && mt_rand(1, 1000) > 999)) { // 1 of 1000 otherwise 
    869871            $this->do_ad_switch(); 
    870872        } 
  • trunk/WordPress/plugin/transposh/core/utils.php

    r659 r667  
    421421            } 
    422422            // if no direct hit, try the prefix only but decrease q-value by 10% (as http_negotiate_language does) 
    423             else if (in_array($languageprefix, $available_languages) && (($qvalue * 0.9) > $bestqval)) { 
    424                 $bestlang = $languageprefix; 
     423            else if (in_array($langprefix, $available_languages) && (($qvalue * 0.9) > $bestqval)) { // CHECK! 
     424                $bestlang = $langprefix; 
    425425                $bestqval = $qvalue * 0.9; 
    426426            } 
  • trunk/WordPress/plugin/transposh/js/transposh.js

    r664 r667  
    1 /*  Copyright © 2009-2010 Transposh Team (website : http://transposh.org) 
     1/*  Copyright © 2009-2011 Transposh Team (website : http://transposh.org) 
    22 * 
    33 *      This program is free software; you can redistribute it and/or modify 
     
    1616 */ 
    1717 
    18 /*global Date, Math, alert, escape, clearTimeout, document, jQuery, setTimeout, t_jp, window */ 
     18/*global Date, Math, alert, escape, clearTimeout, document, jQuery, setTimeout, t_jp, window, _mstConfig */ 
    1919(function ($) { // closure 
    2020    var 
    2121    // this is the size of strings to queue, we don't want too much there 
    22     BATCH_SIZE = 128, 
     22    BATCH_SIZE = 512, 
    2323    // number of phrases that might be translated 
    2424    possibly_translateable, 
     
    3030    source = 1, 
    3131    //Ajax translation 
    32     done_posted = 0, /*Timer for translation aggregation*/ timer, tokens = [], translations = [] 
     32    done_posted = 0, /*Timer for translation aggregation*/ timer, tokens = [], translations = [], 
     33    loadingmsn = 0 
    3334    ; 
    3435 
    35     // transposh app_id for msn translate, now global 
    36     t_jp.MSN_APPID = 'FACA8E2DF8DCCECE0DC311C6E57DA98EFEFA9BC6'; 
    37     if (t_jp.msn_key) { 
    38         t_jp.MSN_APPID = t_jp.msn_key; 
    39     } 
    4036    // set base uri for jQueryUI 
    4137    t_jp.jQueryUI = 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/'; 
     
    9187                ln0: t_jp.lang, // implicit 
    9288                sr0: source, // implicit auto translate... 1 if google, 2 if msn 
    93                 translation_posted: "2", 
     89                action: 'tp_translation', 
    9490                items: tokens.length // we can do this here because all tokens will be different 
    9591            }, i; 
     
    104100            $.ajax({ 
    105101                type: "POST", 
    106                 url: t_jp.post_url, 
     102                url: t_jp.ajaxurl, 
    107103                data: data, 
    108104                success: function () { 
     
    120116 
    121117    // function that creates the progress bar html 
    122     // TODO: change the id 
    123118    function create_progress_bar() { 
    124         // progress bar is for alteast 5 items 
     119        // progress bar is for at least 5 items 
    125120        $("#" + t_jp_prefix + "credit").css({ 
    126121            'overflow': 'auto' 
     
    145140    } 
    146141 
    147     function do_mass_google_translate(batchtrans, usedefault, callback) { 
    148         var q = '',ol = ''; 
    149         $(batchtrans).each(function (i) { 
    150             q += '&q=' + encodeURIComponent(batchtrans[i]); 
    151         }); 
    152         if (usedefault) ol = t_jp.olang; 
     142    // mass google translation - using proxy 
     143    function do_mass_google_translate(batchtrans, callback, lang) { 
     144        /*var sl = ''; 
     145        if (usedefault) { 
     146            sl = t_jp.olang; 
     147        }*/ 
    153148        $.ajax({ 
    154             url: 'http://ajax.googleapis.com/ajax/services/language/translate' + 
    155             '?v=1.0' + q + '&langpair=' + ol + '%7C' + t_jp.lang, 
     149            url: t_jp.ajaxurl, 
     150            dataType: "json", 
     151            data: { 
     152                action: 'tp_gp', 
     153                tl: lang, 
     154                // sl: sl, 
     155                q: batchtrans 
     156            }, 
     157            success: callback 
     158        }); 
     159    } 
     160    t_jp.dgpt = do_mass_google_translate; 
     161 
     162    function do_mass_google_invoker(tokens, trans) { 
     163        do_mass_google_translate(trans, function (result) { 
     164            $(result.results).each(function (i) { 
     165                auto_translate_success(tokens[i], this); 
     166            }); 
     167        }, t_jp.lang); 
     168    } 
     169 
     170    // mass google translation using an api key 
     171    function do_mass_google_api_translate(batchtrans, callback, lang) { 
     172        $.ajax({ 
     173            url: 'https://www.googleapis.com/language/translate/v2', 
    156174            dataType: "jsonp", 
    157             // can use (and test) 
    158             // data: {v: '1.0', langpair: ol+'|'+t_jp.lang,q: batchtrans} 
    159             // traditional: true 
     175            data: { 
     176                key: t_jp.google_key, 
     177                q: batchtrans, 
     178                target: lang, 
     179                source: t_jp.olang 
     180            }, 
     181            traditional: true, 
    160182            success: callback 
    161183        }); 
    162184    } 
    163  
    164     function do_mass_google_invoker(tokens, trans, usedefault) { 
    165         do_mass_google_translate(trans, usedefault, function (result) { 
    166             // we assume that 2xx answer should be good, 200 is good, 206 is partially good (some errors) 
    167             if (result.responseStatus >= 200 && result.responseStatus < 300) { 
    168                 // single items get handled differently 
    169                 if (result.responseData.translatedText !== undefined) { 
    170                     auto_translate_success(tokens[0], result.responseData.translatedText); 
    171                 } else { 
    172                     $(result.responseData).each(function (i) { 
    173                         if (this.responseStatus === 200) { 
    174                             auto_translate_success(tokens[i], this.responseData.translatedText); 
    175                         } 
    176                     }); 
    177                 } 
    178             // we will rerun with a source language if we failed (only once) 
    179             } else if (result.responseStatus >= 400 && !usedefault) { 
    180                 do_mass_google_invoker(tokens, trans, true); 
    181             } 
    182         }); 
    183     } 
    184  
    185     function do_mass_ms_translate(batchtrans, callback) { 
    186         var q = "["; 
    187         $(batchtrans).each(function (i) { 
    188             q += '"' + encodeURIComponent(batchtrans[i]) + '",'; 
    189         }); 
    190         q = q.slice(0, -1) + ']'; 
    191         $.ajax({ 
    192             url: 'http://api.microsofttranslator.com/V2/Ajax.svc/TranslateArray?appId=' + t_jp.MSN_APPID + '&to=' + t_jp.binglang + '&texts=' + q, 
    193             dataType: "jsonp", 
    194             jsonp: "oncomplete", 
    195             success: callback 
    196         }); 
    197     } 
    198  
     185    t_jp.dgt = do_mass_google_api_translate; 
     186        
     187    function do_mass_google_api_invoker(tokens, trans) { 
     188        do_mass_google_api_translate(trans, function (result) { 
     189            // if there was an error we will try the other invoker 
     190            if (typeof result.error !== 'undefined') { 
     191                do_mass_google_invoker(tokens, trans); 
     192            } else { 
     193                $(result.data.translations).each(function (i) { 
     194                    auto_translate_success(tokens[i], this.translatedText); 
     195                }); 
     196            } 
     197        }, t_jp.lang); 
     198    } 
     199     
     200    // mass bing translation 
     201    function do_mass_ms_translate(batchtrans, callback, lang) { 
     202        if(t_jp.msn_key) { 
     203            var q = "["; 
     204            $(batchtrans).each(function (i) { 
     205                q += '"' + encodeURIComponent(batchtrans[i]) + '",'; 
     206            }); 
     207            q = q.slice(0, -1) + ']'; 
     208            $.ajax({ 
     209                url: 'http://api.microsofttranslator.com/V2/Ajax.svc/TranslateArray?appId=' + t_jp.msn_key + '&to=' + lang + '&texts=' + q, 
     210                dataType: "jsonp", 
     211                jsonp: "oncomplete", 
     212                success: callback 
     213            }); 
     214        } else { 
     215            if (loadingmsn === 1) { 
     216                setTimeout(function() { 
     217                    do_mass_ms_translate(batchtrans, callback, lang); 
     218                }, 500); 
     219            } else { 
     220                loadingmsn = 1; 
     221                $.getScript('http://www.microsofttranslator.com/ajax/v2/toolkit.ashx?loc=en&toolbar=none', function() { 
     222                    t_jp.msn_key = _mstConfig.appId; 
     223                    do_mass_ms_translate(batchtrans, callback, lang); 
     224                }); 
     225            }        
     226        }             
     227    } 
     228 
     229    t_jp.dmt = do_mass_ms_translate; 
     230     
    199231    function do_mass_ms_invoker(tokens, trans) { 
    200232        source = 2; 
     
    203235                auto_translate_success(tokens[i], this.TranslatedText); 
    204236            }); 
    205         }); 
    206     } 
    207  
    208     function do_tgp_invoke (token, trans) { 
    209         $.getJSON(t_jp.post_url+'?tgp='+trans+'&tgl='+t_jp.lang, function(result) { 
    210             if (result.sentences !== undefined && result.sentences[0].trans) { 
    211                 auto_translate_success(token, result.sentences[0].trans); 
    212             } 
    213         }); 
     237        }, t_jp.binglang); 
    214238    } 
    215239 
    216240    // mass apertium translation 
    217     function do_mass_apertium_translate(batchtrans, callback) { 
    218         var q = ''; 
    219         $(batchtrans).each(function (i) { 
    220             q += '&q=' + encodeURIComponent(batchtrans[i]); 
    221         }); 
     241    function do_mass_apertium_translate(batchtrans, callback, lang) { 
    222242        $.ajax({ 
    223             url: 'http://api.apertium.org/json/translate' + 
    224             '?' + q + '&langpair=' + t_jp.olang + '%7C' + t_jp.lang + '&markUnknown=no', 
     243            url: 'http://api.apertium.org/json/translate', 
     244            data: { 
     245                q: batchtrans, 
     246                langpair: t_jp.olang + '|' + lang, 
     247                markUnknown: 'no' 
     248            }, 
    225249            dataType: "jsonp", 
     250            traditional: true, 
    226251            success: callback 
    227252        }); 
    228253    } 
     254 
     255    t_jp.dat = do_mass_apertium_translate; 
    229256 
    230257    function do_mass_apertium_invoker(tokens, trans) { 
     
    244271                } 
    245272            } 
    246         }); 
     273        }, t_jp.lang); 
     274    } 
     275 
     276    // helper function for lazy running 
     277    function lazyrun(func) { 
     278        if (typeof $.xLazyLoader === 'function') { 
     279            func(); 
     280        } else { 
     281            $.getScript(t_jp.plugin_url + '/js/lazy.js', func); 
     282        }         
    247283    } 
    248284 
     
    253289        } else if (t_jp.apertium && (t_jp.olang === 'en' || t_jp.olang === 'es')) { 
    254290            do_mass_apertium_invoker(batchtokens, batchtrans); 
    255         } else if (t_jp.tgp) { 
    256             if (batchtrans[0]) { 
    257                 do_tgp_invoke(batchtokens[0], batchtrans[0]); 
    258             } 
     291        } else if (t_jp.google_key) { 
     292            do_mass_google_api_invoker(batchtokens, batchtrans); 
    259293        } else { 
    260             do_mass_google_invoker(batchtokens, batchtrans, false); 
     294            do_mass_google_invoker(batchtokens, batchtrans); 
    261295        } 
    262296    } 
     
    267301        var auto_translated_phrases = [], batchlength = 0, batchtrans = [], batchtokens = []; 
    268302 
    269         if (t_jp.tgp) { 
    270             BATCH_SIZE = 0; 
    271         } // Transposh Google Proxy can't batch.. 
    272  
    273         $("." + t_jp_prefix + '[data-source=""]').each(function (i) { 
     303        $("." + t_jp_prefix + '[data-source=""]').each(function () { 
    274304            var token = $(this).attr('data-token'), 
    275305            // we only have orig if we have some translation? so it should probably not be here... ? (or maybe for future invalidations of cached auto translations) 
     
    294324        do_mass_invoke(batchtokens, batchtrans); 
    295325    } 
    296  
     326     
    297327    $(document).ready( 
    298328        function () { 
     
    310340            // attach a function to the set_default_language link if its there 
    311341            $('#' + t_jp_prefix + 'setdeflang').click(function () { 
    312                 $.get(t_jp.post_url + "?tr_cookie=" + Math.random()); 
     342                $.ajax({ 
     343                    url: t_jp.ajaxurl, 
     344                    data: { 
     345                        action: 'tp_cookie' 
     346                    }, 
     347                    cache: false 
     348                } );               
    313349                $(this).hide("slow"); 
    314350                return false; 
     
    326362            // we'll translate if there's any candidate...? 
    327363            if // ((possibly_translateable > 5 || (now.getHours() === 4 && possibly_translateable > 0)) && 
    328             (possibly_translateable && !t_jp.noauto && (t_jp.google || t_jp.msn || t_jp.apertium || t_jp.tgp)) { 
     364            (possibly_translateable && !t_jp.noauto && (t_jp.google || t_jp.msn || t_jp.apertium)) { 
    329365                // if we have a progress bar, we need to load the jqueryui before the auto translate, after the google was loaded, otherwise we can just go ahead 
    330366                if (t_jp.progress) { 
     
    339375                        }); 
    340376                    }; 
    341                     if (typeof $.xLazyLoader === 'function') { 
    342                         loaduiandtranslate(); 
    343                     } else { 
    344                         $.getScript(t_jp.plugin_url + '/js/lazy.js', loaduiandtranslate); 
    345                     } 
     377                    lazyrun(loaduiandtranslate); 
    346378                } else { 
    347379                    do_auto_translate(); 
  • trunk/WordPress/plugin/transposh/js/transposhbackend.js

    r527 r667  
    1616 */ 
    1717 
    18 /*global Date, Math, alert, escape, clearTimeout, document, jQuery, setTimeout, t_jp, window */ 
     18/*global Date, Math, alert, escape, clearTimeout, document, jQuery, setTimeout, t_jp, t_be, window */ 
    1919 
    2020var timer; 
     
    2424var langs = []; 
    2525var sources = []; 
    26 var BATCH_SIZE = 128; 
     26var BATCH_SIZE = 512; 
    2727var pair_count = 0; 
    2828var curr_pair = 0; 
    29 t_jp.MSN_APPID = 'FACA8E2DF8DCCECE0DC311C6E57DA98EFEFA9BC6'; 
    3029 
    3130// move the progress bar a bit 
     
    5453    timer = setTimeout(function () { 
    5554        var data = { 
    56             translation_posted: "2", 
     55            action: 'tp_translation', 
    5756            items: items 
    5857        }, i; 
     
    7473        jQuery.ajax({ 
    7574            type: "POST", 
    76             url: t_jp.post_url, 
     75            url: t_jp.ajaxurl, // FIX ALL! 
    7776            data: data, 
    7877            success: function () { 
     
    9190 
    9291// this is the mass translate for MS 
    93 function do_mass_ms_translate(batchtrans, callback) { 
     92/*function do_mass_ms_translate(batchtrans, callback) { 
    9493    var q = "["; 
    9594    jQuery(batchtrans).each(function (i) { 
     
    103102        success: callback 
    104103    }); 
    105 } 
     104}*/ 
    106105 
    107106// and the invoker 
    108107function do_mass_ms_invoker(tokens, trans, lang) { 
    109     t_jp.binglang = lang; 
     108    var binglang = lang; 
    110109    // fix this in ms mass... 
    111     if (t_jp.binglang === 'zh') { 
    112         t_jp.binglang = 'zh-chs'; 
    113     } else if (t_jp.binglang === 'zh-tw') { 
    114         t_jp.binglang = 'zh-cht'; 
    115     } 
    116     do_mass_ms_translate(trans, function (result) { 
     110    if (binglang === 'zh') { 
     111        binglang = 'zh-chs'; 
     112    } else if (binglang === 'zh-tw') { 
     113        binglang = 'zh-cht'; 
     114    } 
     115    t_jp.dmt(trans, function (result) { 
    117116        jQuery(result).each(function (i) { 
    118117            ajax_translate_me(tokens[i], this.TranslatedText, lang, 2); // notice the source 
    119118        }); 
    120     }); 
    121 } 
    122  
    123 // this is a mass translate of one string to many langs 
    124 function do_mass_google_translate_l(tran, langs,  callback) { 
    125     var langpairs = '', key; 
    126     //$(langs).each(function (i) { 
    127     for (key in langs) { 
    128         langpairs += '&langpair=%7C' + langs[key]; 
    129     } 
    130  
    131     jQuery.ajax({ 
    132         url: 'http://ajax.googleapis.com/ajax/services/language/translate' + 
    133         '?v=1.0&q=' + encodeURIComponent(tran) + langpairs, 
    134         dataType: "jsonp", 
    135         success: callback 
    136     }); 
    137 } 
    138  
    139 // the invoker 
    140 function do_mass_google_invoker_l(token, to_tran, langs) { 
    141     do_mass_google_translate_l(to_tran, langs, function (result) { 
    142         if (result.responseStatus === 200) { 
     119    }, binglang); 
     120} 
     121 
     122function do_mass_apertium_invoker(tokens, trans, lang) { 
     123    t_jp.dat(trans, function (result) { 
     124        // we assume that 2xx answer should be good, 200 is good, 206 is partially good (some errors) 
     125        if (result.responseStatus >= 200 && result.responseStatus < 300) { 
    143126            // single items get handled differently 
    144127            if (result.responseData.translatedText !== undefined) { 
    145                 ajax_translate_me(token, result.responseData.translatedText, langs[0], 1); // notice the source... 
     128                ajax_translate_me(tokens[0], result.responseData.translatedText); 
    146129            } else { 
    147130                jQuery(result.responseData).each(function (i) { 
    148131                    if (this.responseStatus === 200) { 
    149                         ajax_translate_me(token, this.responseData.translatedText, langs[i], 1); 
     132                        ajax_translate_me(tokens[i], this.responseData.translatedText, lang, 3); 
    150133                    } 
    151134                }); 
    152135            } 
    153136        } 
    154     }); 
     137    }, lang); 
     138} 
     139 
     140function do_mass_google_invoker(tokens, trans, lang) { 
     141    t_jp.dgpt(trans, function (result) { 
     142        jQuery(result.results).each(function (i) { 
     143            ajax_translate_me(tokens[i], this, lang, 1); 
     144        }); 
     145    }, lang); 
     146} 
     147 
     148function do_mass_google_api_invoker(tokens, trans, lang) { 
     149    t_jp.dgt(trans, function (result) { 
     150        // if there was an error we will try the other invoker 
     151        if (typeof result.error !== 'undefined') { 
     152            do_mass_google_invoker(tokens, trans, lang); 
     153        } else { 
     154            jQuery(result.data.translations).each(function (i) { 
     155                ajax_translate_me(tokens[i], this.translatedText, lang, 1); 
     156            }); 
     157        } 
     158    }, lang); 
     159} 
     160 
     161function do_invoker(batchtokens, batchtrans, currlang) { 
     162    if (t_be.m_langs.indexOf(currlang) !== -1 && t_jp.preferred === '2') { 
     163        do_mass_ms_invoker(batchtokens, batchtrans, currlang); 
     164    } else if (t_be.a_langs.indexOf(currlang) !== -1 && (t_jp.olang === 'en' || t_jp.olang === 'es')) { 
     165        do_mass_apertium_invoker(batchtokens, batchtrans, currlang); 
     166    } else if (t_jp.google_key) { 
     167        do_mass_google_api_invoker(batchtokens, batchtrans, currlang); 
     168    } else { 
     169        do_mass_google_invoker(batchtokens, batchtrans, currlang); 
     170    } 
    155171} 
    156172 
     
    167183 
    168184    jQuery("#tr_loading").data("done", false); 
    169     // get the post 
    170     jQuery.getJSON(t_jp.post_url + "?tr_phrases_post=y&post=" + postid + "&random=" + Math.random(), function (json) { // need to add random to avoid getting cached! 
    171         // if we got no results than seems like we have nothing to translate 
    172         jQuery("#tr_translate_title").html("Translating post: " + json.posttitle); 
    173         if (json.length === undefined) { 
    174             jQuery("#tr_loading").html('Nothing left to translate'); 
    175             jQuery("#tr_loading").data("done", true); 
    176             return; 
    177         } 
    178         // calculate # of pairs 
    179         pair_count = 0; 
    180         curr_pair = 0; 
    181         for (name in json.p) { 
    182             pair_count += json.p[name].l.length; 
    183         } 
    184  
    185         // create progress bars 
    186         jQuery("#tr_loading").html('<br/>Translation: <span id="p"></span><div id="progress_bar"/>'); 
    187         jQuery("#progress_bar").progressbar({ 
    188             value: 0 
    189         }); 
    190  
    191         // per language passing... 
    192         // this things happens when msn translate is default 
    193         if (t_jp.preferred === '2') { 
    194             // traverse on langs of msn 
    195             for (lang in t_jp.m_langs) { 
    196                 currlang = t_jp.m_langs[lang]; 
     185    // get the post // FIX 
     186    jQuery.ajax({ 
     187        url: ajaxurl, 
     188        dataType: 'json', 
     189        data: { 
     190            action: "tp_post_phrases", 
     191            post: postid 
     192        }, 
     193        cache: false, 
     194        success: function (json) { 
     195            // if we got no results than seems like we have nothing to translate 
     196            jQuery("#tr_translate_title").html("Translating post: " + json.posttitle); 
     197            if (json.length === undefined) { 
     198                jQuery("#tr_loading").html('Nothing left to translate'); 
     199                jQuery("#tr_loading").data("done", true); 
     200                return; 
     201            } 
     202            // calculate # of pairs 
     203            pair_count = 0; 
     204            curr_pair = 0; 
     205            for (name in json.p) { 
     206                pair_count += json.p[name].l.length; 
     207            } 
     208 
     209            // create progress bars 
     210            jQuery("#tr_loading").html('<br/>Translation: <span id="p"></span><div id="progress_bar"/>'); 
     211            jQuery("#progress_bar").progressbar({ 
     212                value: 0 
     213            }); 
     214 
     215            // per language passing... 
     216            // this things happens when msn translate is default 
     217            for (var lang in json.langs) { 
     218                currlang = json.langs[lang]; 
    197219                strings = []; 
    198220                tokens = []; 
     
    212234                    } 
    213235                } 
    214                 // we had some matches - now we batchify 
    215236                if (strings.length) { 
    216237                    for (str in strings) { 
    217238                        to_trans = strings[str]; 
    218239                        if (batchlength + to_trans.length > BATCH_SIZE) { 
    219                             do_mass_ms_invoker(batchtokens, batchtrans, currlang); 
     240                            do_invoker(batchtokens, batchtrans, currlang); 
    220241                            batchlength = 0; 
    221242                            batchtrans = []; 
     
    228249 
    229250                    // this invokation is for the remaining items 
    230                     do_mass_ms_invoker(batchtokens, batchtrans, currlang); 
     251                    do_invoker(batchtokens, batchtrans, currlang); 
    231252                } 
    232253            } 
    233         } 
    234  
    235         // in the google thingy we just batch by string, much simpler, maybe we should 
    236         // also batch if we have the same language for all (far future TODO) 
    237         for (name in json.p) { 
    238             val = json.p[name]; 
    239             do_mass_google_invoker_l(val.t, unescape(name), val.l); 
    240         } 
    241     // FIX??  ajax_translate_me(val.t,jQuery("<div>"+result.translation+"</div>").text(),lang); 
     254             
     255        } 
    242256    }); 
    243257} 
     
    246260// If we have a single post, we can just go through with it 
    247261jQuery(document).ready(function () { 
    248     if (t_jp.post) { 
    249         translate_post(t_jp.post); 
     262    if (t_be.post) { 
     263        translate_post(t_be.post); 
    250264    } 
    251265}); 
  • trunk/WordPress/plugin/transposh/js/transposhedit.js

    r646 r667  
    142142        // push translations 
    143143        // This is a change - as we fix the pages before we got actual confirmation (worked well for auto-translation) 
    144         fix_page_human(token, translation, 0); 
    145         var data = { 
    146             ln0: t_jp.lang, 
    147             sr0: 0, // implicit human 
    148             translation_posted: "2", 
    149             items: 1, 
    150             tk0: token, 
    151             tr0: translation 
    152         }; 
    153  
     144        fix_page_human(token, translation, 0);        
    154145        $.ajax({ 
    155146            type: "POST", 
    156             url: t_jp.post_url, 
    157             data: data, 
    158             // In the past we used this to make progress bar status, not really needed, but keeping for future reference 
    159             // success: function () {}, 
     147            url: t_jp.ajaxurl, // FIX! 
     148            data: { 
     149                action: 'tp_translation', 
     150                ln0: t_jp.lang, 
     151                sr0: 0, // implicit human 
     152                items: 1, 
     153                tk0: token, 
     154                tr0: translation 
     155            }, 
    160156            // TODO: This probably needs a revision! 
    161157            error: function (req) { 
    162                 alert("Error !!! failed to translate.\n\nServer's message: " + req.statusText); 
    163             } 
    164         }); 
    165     } 
    166  
    167     // perform google translate of single phrase via jsonp 
    168     function google_trans(to_trans, callback) { 
    169         $.ajax({ 
    170             url: 'http://ajax.googleapis.com/ajax/services/language/translate' + 
    171             '?v=1.0&q=' + encodeURIComponent(to_trans) + '&langpair=%7C' + t_jp.lang, 
    172             dataType: "jsonp", 
    173             success: callback 
     158                alert("Problem saving translation, contact support.\n\nServer's message: " + req.statusText); 
     159            } 
    174160        }); 
    175161    } 
     
    178164    function getgt() 
    179165    { 
    180         google_trans($(idprefix + "original").val(), function (result) { 
    181             if (result.responseStatus === 200) { 
    182                 $(idprefix + "translation").val($("<div>" + $.trim(result.responseData.translatedText) + "</div>").text()) 
     166        if (!t_jp.google_key) { 
     167            $.ajax({ 
     168                url: t_jp.ajaxurl, 
     169                dataType: "json", 
     170                data: { 
     171                    action: 'tp_gsp', 
     172                    tl: t_jp.lang, 
     173                    sl: $(idprefix + "original").data('srclang'), 
     174                    q: $(idprefix + "original").val() 
     175                }, 
     176                success: function (result) { 
     177                    console.log(result); 
     178                    $(idprefix + "translation").val($("<div>" + $.trim(result.result) + "</div>").text()) 
     179                    .keyup(); 
     180                } 
     181            }); 
     182        } else { 
     183            t_jp.dgt($(idprefix + "original").val(), function (result) { 
     184                $(idprefix + "translation").val($("<div>" + $.trim(result.data.translations[0].translatedText) + "</div>").text()) 
    183185                .keyup(); 
    184             } 
    185         }); 
    186     } 
    187  
    188     // perform ms translate of single phrase via jsonp 
    189     function ms_trans(to_trans, callback) { 
    190         $.ajax({ 
    191             url: 'http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=' + t_jp.MSN_APPID + '&to=' + t_jp.binglang + "&text=" + encodeURIComponent(to_trans), 
    192             dataType: "jsonp", 
    193             jsonp: "oncomplete", 
    194             success: callback 
    195         }); 
     186            }); 
     187        } 
    196188    } 
    197189 
     
    199191    function getbt() 
    200192    { 
    201         ms_trans($(idprefix + "original").val(), function (result) { 
    202             $(idprefix + "translation").val($("<div>" + $.trim(result) + "</div>").text()) 
     193        t_jp.dmt([$(idprefix + "original").val()], function (result) { 
     194            $(idprefix + "translation").val($("<div>" + $.trim(result[0].TranslatedText) + "</div>").text()) 
    203195            .keyup(); 
    204196        }); 
     
    312304        }         
    313305        $.ajax({ 
    314             url: t_jp.post_url, 
     306            url: t_jp.ajaxurl,  
    315307            data: { 
    316                 tr_token_hist: $(idprefix + segment_id).attr('data-token'), 
     308                action: 'tp_history', 
     309                token: $(idprefix + segment_id).attr('data-token'), 
    317310                lang: t_jp.lang 
    318311            }, 
     
    375368                    var row = $(this).parents('tr'); 
    376369                    $.ajax({ 
    377                         url: t_jp.post_url, 
     370                        url: t_jp.ajaxurl, 
    378371                        data: { 
    379                             tr_token_hist: $(idprefix + segment_id).attr('data-token'), 
     372                            action: 'tp_history', 
     373                            token: $(idprefix + segment_id).attr('data-token'), 
    380374                            timestamp: $(this).parents('tr').children(":last").text(), 
    381                             action: 'delete', 
    382375                            lang: t_jp.lang 
    383376                        }, 
     
    510503                    success: function () { 
    511504                        $.ajax({ 
    512                             url: t_jp.post_url, 
     505                            url: t_jp.ajaxurl, 
    513506                            data: { 
    514                                 tr_token_alt: $(idprefix + segment_id).attr('data-token') 
     507                                action: 'tp_trans_alts', 
     508                                token: $(idprefix + segment_id).attr('data-token') 
    515509                            }, 
    516510                            dataType: "json", 
     
    730724        if ($("html").attr("dir") === 'rtl') { 
    731725            fix_dialog_header_rtl(dialog); 
    732             var uicorner = 'ui-corner-'; 
    733             // to remove with jqueryui-1.8.14 
    734 //            $(idprefix + 'utlbar button:first').addClass(uicorner + left).removeClass(uicorner + right); 
    735 //            $(idprefix + 'utlbar button:last').addClass(uicorner + right).removeClass(uicorner + left); 
    736 //            $(idprefix + 'ltlbar button:first').addClass(uicorner + left).removeClass(uicorner + right); 
    737 //            $(idprefix + 'ltlbar button:last').addClass(uicorner + right).removeClass(uicorner + left); 
    738726        } 
    739727 
  • trunk/WordPress/plugin/transposh/js/transposhsettings.js

    r651 r667  
    130130            return false 
    131131        }).text("Backup In Progress"); 
    132         jQuery.get(t_jp.post_url + "?backup",function(data) { 
     132        jQuery.post(ajaxurl, { 
     133            action: 'tp_backup' 
     134        }, 
     135        function(data) { 
    133136            var color = 'red'; 
    134137            if (data[0] == '2') color = 'green'; 
     
    150153            return false 
    151154        }).text("Cleanup in progress"); 
    152         jQuery.get(t_jp.post_url + "?nonce="+button.attr('nonce')+"&days="+days+"&cleanup",function(data) { 
     155        jQuery.post(ajaxurl, { 
     156            action: 'tp_cleanup', 
     157            days: days 
     158        }, 
     159        function(data) { 
    153160            button.unbind('click').click(function() { 
    154161                cleanautoclick(days,button); 
     
    174181            return false 
    175182        }).text("Maintenance in progress"); 
    176         jQuery.get(t_jp.post_url + "?nonce="+button.attr('nonce')+"&maint",function(data) { 
     183        jQuery.post(ajaxurl, { 
     184            action: 'tp_maint' 
     185        }, 
     186        function(data) { 
    177187            button.unbind('click').click(function() { 
    178188                maintclick(button); 
     
    201211            cache: false 
    202212        }); 
    203         jQuery.getJSON(t_jp.post_url,{ 
    204             translate_all:"y" 
    205         }, function (data) { 
    206             dotimer = function(a) { 
    207                 clearTimeout(timer2); 
    208                 //console.log(a); 
    209                 //console.log(jQuery("#tr_loading").data("done")); 
    210                 if (jQuery("#tr_loading").data("done") || jQuery("#tr_loading").data("attempt")>4) { 
    211                     jQuery("#progress_bar_all").progressbar('value' , (a+1)/data.length*100); 
    212                     jQuery("#tr_loading").data("attempt",0); 
    213                     translate_post(data[a]); 
     213        jQuery.ajax({ 
     214            url: ajaxurl, 
     215            dataType: 'json', 
     216            data: { 
     217                action: "tp_translate_all" 
     218            }, 
     219            cache: false, 
     220            success: function (data) { 
     221                dotimer = function(a) { 
     222                    jQuery("#tr_allmsg").text(''); 
     223                    clearTimeout(timer2); 
     224                    //console.log(a); 
    214225                    //console.log(jQuery("#tr_loading").data("done")); 
    215                     //console.log("done translate" + a); 
    216                     if (data[a] && !stop_translate_var) { 
    217                         //console.log("trigger translation of " +a); 
     226                    if (jQuery("#tr_loading").data("done") || jQuery("#tr_loading").data("attempt")>4) { 
     227                        jQuery("#progress_bar_all").progressbar('value' , (a+1)/data.length*100); 
     228                        jQuery("#tr_loading").data("attempt",0); 
     229                        translate_post(data[a]); 
     230                        //console.log(jQuery("#tr_loading").data("done")); 
     231                        //console.log("done translate" + a); 
     232                        // we call the next translation here... 
     233                        if (typeof data[a+1] !== 'undefined' && !stop_translate_var) { 
     234                            //console.log("trigger translation of " +a); 
     235                            timer2 = setTimeout(function() { 
     236                                dotimer(a+1) 
     237                            },5000); 
     238                            jQuery("#tr_allmsg").text('Waiting 5 seconds...'); 
     239                        } 
     240                    } else { 
     241                        //console.log("waiting for translation to finish 60 seconds"); 
     242                        jQuery("#tr_loading").data("attempt",jQuery("#tr_loading").data("attempt")+1); 
    218243                        timer2 = setTimeout(function() { 
    219                             dotimer(a+1) 
    220                         },1000); 
     244                            dotimer(a) 
     245                        },15000); 
     246                        jQuery("#tr_allmsg").text('Translation incomplete - Waiting 15 seconds - attempt ' + jQuery("#tr_loading").data("attempt") + '/5'); 
    221247                    } 
    222                 } else { 
    223                     //console.log("waiting for translation to finish 60 seconds"); 
    224                     jQuery("#tr_loading").data("attempt",jQuery("#tr_loading").data("attempt")+1); 
    225                     timer2 = setTimeout(function() { 
    226                         dotimer(a) 
    227                     },60000); 
    228248                } 
     249                timer2 = setTimeout(function() { 
     250                    dotimer(0) 
     251                },0); 
    229252            } 
    230             timer2 = setTimeout(function() { 
    231                 dotimer(0) 
    232             },0); 
    233253        }); 
    234254        jQuery("#transposh-translate").text("Stop translate") 
     
    250270        jQuery(this).parent().hide(); 
    251271        jQuery.post(ajaxurl, { 
    252             action: 'closed_tpwarn', 
     272            action: 'tp_close_warning', 
    253273            id: jQuery(this).parent().attr('id') 
    254          }); 
     274        }); 
    255275    }) 
    256276 
  • trunk/WordPress/plugin/transposh/transposh.php

    r664 r667  
    5252    /** @var transposh_plugin_options An options object */ 
    5353    public $options; 
     54 
    5455    /** @var transposh_plugin_admin Admin page */ 
    5556    private $admin; 
     57 
    5658    /** @var transposh_plugin_widget Widget control */ 
    5759    public $widget; 
     60 
    5861    /** @var transposh_database The database class */ 
    5962    public $database; 
     63 
    6064    /** @var transposh_postpublish Happens after editing */ 
    6165    public $postpublish; 
     66 
    6267    /** @var transposh_3rdparty Happens after editing */ 
    6368    private $third_party; 
     
    6570    /** @var string The site url */ 
    6671    public $home_url; 
    67     /** @var string Where the javascript should post to */ 
    68     public $post_url; 
     72 
    6973    /** @var a url of the request, assuming there was no language */ 
    7074    private $clean_url; 
     75 
    7176    /** @var string The url to the plugin directory */ 
    7277    public $transposh_plugin_url; 
     78 
    7379    /** @var string The directory of the plugin */ 
    7480    public $transposh_plugin_dir; 
     81 
    7582    /** @var boolean Enable rewriting of URLs */ 
    7683    public $enable_permalinks_rewrite; 
     84 
    7785    /** @var string The language to translate the page to, from params */ 
    7886    public $target_language; 
     87 
    7988    /** @var string The language extracted from the url */ 
    8089    public $tgl; 
     90 
    8191    /** @var boolean Are we currently editing the page? */ 
    8292    public $edit_mode; 
     93 
    8394    /** @var string Error message displayed for the admin in case of failure */ 
    8495    private $admin_msg; 
     96 
    8597    /** @var string Saved search variables */ 
    8698    private $search_s; 
     99 
    87100    /** @var variable to make sure we only attempt to fix the url once, could have used remove_filter */ 
    88101    private $got_request = false; 
     102 
    89103    /** @var might be that page is json... */ 
    90104    private $attempt_json = false; 
     105 
    91106    /** @var boolean Is the wp_redirect being called by transposh? */ 
    92107    private $transposh_redirect = false; 
     
    116131 
    117132        $this->transposh_plugin_dir = plugin_dir_path(__FILE__); 
    118  
    119         $this->post_url = "{$this->transposh_plugin_url}/wp/transposh_ajax.php"; 
    120133 
    121134        logger('Object created: ' . $_SERVER['REQUEST_URI'], 3); 
     
    144157        add_action('transposh_backup_event', array(&$this, 'run_backup')); 
    145158        add_action('comment_post', array(&$this, 'add_comment_meta_settings'), 1); 
     159        // our translation proxy 
     160        add_action('wp_ajax_tp_gp', array(&$this, 'on_ajax_nopriv_tp_gp')); 
     161        add_action('wp_ajax_nopriv_tp_gp', array(&$this, 'on_ajax_nopriv_tp_gp')); 
     162        add_action('wp_ajax_tp_gsp', array(&$this, 'on_ajax_nopriv_tp_gsp')); 
     163        add_action('wp_ajax_nopriv_tp_gsp', array(&$this, 'on_ajax_nopriv_tp_gsp')); 
     164        // ajax actions in editor 
     165        // TODO - remove some for non translators 
     166        add_action('wp_ajax_tp_history', array(&$this, 'on_ajax_nopriv_tp_history')); 
     167        add_action('wp_ajax_nopriv_tp_history', array(&$this, 'on_ajax_nopriv_tp_history')); 
     168        add_action('wp_ajax_tp_translation', array(&$this, 'on_ajax_nopriv_tp_translation')); 
     169        add_action('wp_ajax_nopriv_tp_translation', array(&$this, 'on_ajax_nopriv_tp_translation')); 
     170        add_action('wp_ajax_tp_trans_alts', array(&$this, 'on_ajax_nopriv_tp_trans_alts')); 
     171        add_action('wp_ajax_nopriv_tp_trans_alts', array(&$this, 'on_ajax_nopriv_tp_trans_alts')); 
     172        add_action('wp_ajax_tp_cookie', array(&$this, 'on_ajax_nopriv_tp_cookie')); 
     173        add_action('wp_ajax_nopriv_tp_cookie', array(&$this, 'on_ajax_nopriv_tp_cookie')); 
     174        add_action('wp_ajax_tp_cookie_bck', array(&$this, 'on_ajax_nopriv_tp_cookie_bck')); 
     175        add_action('wp_ajax_nopriv_tp_cookie_bck', array(&$this, 'on_ajax_nopriv_tp_cookie_bck')); 
     176 
    146177        // comment_moderation_text - future filter TODO 
    147178        // full post wrapping (should happen late) 
     
    149180        add_filter('the_excerpt', array(&$this, 'post_content_wrap'), 9999); 
    150181        add_filter('the_title', array(&$this, 'post_wrap'), 9999, 2); 
     182 
    151183        // allow to mark the language? 
    152184//        add_action('admin_menu', array(&$this, 'transposh_post_language')); 
     
    261293    function is_special_page($url) { 
    262294        return ( stripos($url, '/wp-login.php') !== FALSE || 
    263         stripos($url, '/wp-admin/') !== FALSE || 
    264         stripos($url, '/wp-comments-post') !== FALSE || 
    265         stripos($url, '/xmlrpc.php') !== FALSE); 
     295                stripos($url, '/wp-admin/') !== FALSE || 
     296                stripos($url, '/wp-comments-post') !== FALSE || 
     297                stripos($url, '/xmlrpc.php') !== FALSE); 
    266298    } 
    267299 
     
    471503        // bots can skip this altogether 
    472504        if (($this->options->get_enable_detect_language() || $this->options->get_widget_allow_set_default_language()) && 
    473                 !($this->is_special_page($_SERVER['REQUEST_URI']) || strpos($_SERVER['HTTP_REFERER'], $this->home_url) !== false) && 
     505                !($this->is_special_page($_SERVER['REQUEST_URI']) || (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], $this->home_url) !== false)) && 
    474506                !(transposh_utils::is_bot())) { 
    475507            // we are starting a session if needed 
    476508            if (!session_id()) session_start(); 
    477509            // no redirections if we already redirected in this session or we suspect cyclic redirections 
    478             if (!$_SESSION['TR_REDIRECTED'] && !($_SERVER['HTTP_REFERER'] == $_SERVER['REQUEST_URI'])) { 
     510            if (!isset($_SESSION['TR_REDIRECTED']) && !(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == $_SERVER['REQUEST_URI'])) { 
    479511                logger('session redirection never happened (yet)'); 
    480512                // we redirect once per session 
     
    682714        // true -> 1, false -> nothing 
    683715        $script_params = array( 
    684             'post_url' => $this->post_url, 
     716            'ajaxurl' => admin_url('admin-ajax.php'), 
    685717            'plugin_url' => $this->transposh_plugin_url, 
    686718            'lang' => $this->target_language, 
     
    691723        ); 
    692724 
    693         if (in_array($this->target_language, transposh_consts::$bing_languages)) { 
    694                 $script_params['msn'] = 1; 
    695                 if ($this->options->get_msn_key()) { 
    696                     $script_params['msn_key'] = $this->options->get_msn_key(); 
    697                 } 
    698         } 
    699         if (in_array($this->target_language, transposh_consts::$google_languages)) { 
    700                 $script_params['google'] = 1; 
    701                 if ($this->options->get_google_key()) { 
    702                     $script_params['google_key'] = $this->options->get_google_key(); 
    703                 } 
     725        // FIX BACKEND 
     726        if (!$this->target_language || in_array($this->target_language, transposh_consts::$bing_languages)) { 
     727            $script_params['msn'] = 1; 
     728            if ($this->options->get_msn_key()) { 
     729                $script_params['msn_key'] = $this->options->get_msn_key(); 
     730            } 
     731        } 
     732        // FIX BACKEND 
     733        if (!$this->target_language || in_array($this->target_language, transposh_consts::$google_languages)) { 
     734            if ($this->options->get_google_key()) { 
     735                $script_params['google_key'] = $this->options->get_google_key(); 
     736            } 
     737            if ($this->options->get_google_key() || function_exists('curl_init')) 
     738                    $script_params['google'] = 1; 
    704739        } 
    705740        if (in_array($this->target_language, transposh_consts::$apertium_languages)) 
    706741                $script_params['apertium'] = 1; 
    707         if (function_exists('curl_init') && in_array($this->target_language, transposh_consts::$google_proxied_languages)) 
    708                 $script_params['tgp'] = 1; 
     742 
    709743        if ($this->options->get_widget_progressbar()) 
    710744                $script_params['progress'] = 1; 
     
    11611195    } 
    11621196 
     1197    // Proxyed google translate suggestions 
     1198    function on_ajax_nopriv_tp_gsp() { 
     1199        $i = 0; 
     1200        // we need curl for this proxy 
     1201        if (!function_exists('curl_init')) return; 
     1202        $tl = $_GET['tl']; 
     1203        // we want to avoid unneeded work or dos attacks on languages we don't support 
     1204        if (!in_array($tl, transposh_consts::$google_languages) || !$this->options->is_editable_language($tl)) 
     1205                return; 
     1206        $sl = 'auto'; 
     1207        if (isset($_GET['sl'])) $sl = $_GET['sl']; 
     1208        $q = '&q=' . urlencode($_GET['q']); 
     1209        $url = 'http://translate.google.com/translate_a/t?client=a' . $q . '&tl=' . $tl . '&sl=' . $sl; 
     1210        //var_dump($url); 
     1211        $ch = curl_init(); 
     1212        curl_setopt($ch, CURLOPT_URL, $url); 
     1213        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     1214        //must set agent for google to respond with utf-8 
     1215        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0'); 
     1216        $output = curl_exec($ch); 
     1217        if ($output === false) { 
     1218            echo 'Curl error: ' . curl_error($ch); 
     1219            die(); 
     1220        } 
     1221        curl_close($ch); 
     1222        //echo $output; 
     1223        $jsonarr = json_decode($output); 
     1224        if (!$jsonarr) { 
     1225            echo 'Not JSON'; 
     1226            die(); 
     1227        } 
     1228        if (!isset($jsonarr->results)) { 
     1229            $jsonarr2->results[] = $jsonarr; 
     1230            $jsonarr = $jsonarr2; 
     1231        } 
     1232        foreach ($jsonarr->results as $result) { 
     1233            unset($result->sentences[0]->orig); 
     1234            unset($result->sentences[0]->translit); 
     1235            unset($result->sentences[0]->src_translit); 
     1236            unset($result->src); 
     1237            unset($result->server_time); 
     1238        } 
     1239        $jsonout->result = $jsonarr->results[0]->sentences[0]->trans; 
     1240 
     1241        echo json_encode($jsonout); 
     1242        die(); 
     1243    } 
     1244 
     1245    // Proxyed translation for google translate 
     1246    function on_ajax_nopriv_tp_gp() { 
     1247        // we need curl for this proxy 
     1248        if (!function_exists('curl_init')) return; 
     1249        // target language 
     1250        $tl = $_GET['tl']; 
     1251        // we want to avoid unneeded work or dos attacks on languages we don't support 
     1252        if (!in_array($tl, transposh_consts::$google_languages) || !$this->options->is_editable_language($tl)) 
     1253                return; 
     1254        // source language 
     1255        $sl = 'auto'; 
     1256        if (isset($_GET['sl'])) $sl = $_GET['sl']; 
     1257        // item count 
     1258        $i = 0; 
     1259        $q = ''; 
     1260        foreach ($_GET['q'] as $p) { 
     1261            list($source, $trans) = $this->database->fetch_translation($p, $tl); 
     1262            if (!$trans) { 
     1263                $q .= '&q=' . urlencode($p); 
     1264            } else { 
     1265                // holds cached results 
     1266                $r[$i] = $trans; 
     1267            } 
     1268            $i++; 
     1269        } 
     1270        // we avoid curling we had all results prehand 
     1271        if ($q) { 
     1272            $url = 'http://translate.google.com/translate_a/t?client=a' . $q . '&tl=' . $tl . '&sl=' . $sl; 
     1273            //var_dump($url); 
     1274            $ch = curl_init(); 
     1275            curl_setopt($ch, CURLOPT_URL, $url); 
     1276            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     1277            //must set agent for google to respond with utf-8 
     1278            curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0'); 
     1279            $output = curl_exec($ch); 
     1280            if ($output === false) { 
     1281                echo 'Curl error: ' . curl_error($ch); 
     1282                die(); 
     1283            } 
     1284            curl_close($ch); 
     1285            //echo $output; 
     1286            $jsonarr = json_decode($output); 
     1287            if (!$jsonarr) { 
     1288                echo 'Not JSON'; 
     1289                die(); 
     1290            } 
     1291            if (!isset($jsonarr->results)) { 
     1292                $jsonarr2->results[] = $jsonarr; 
     1293                $jsonarr = $jsonarr2; 
     1294            } 
     1295            foreach ($jsonarr->results as $result) { 
     1296                unset($result->sentences[0]->orig); 
     1297                unset($result->sentences[0]->translit); 
     1298                unset($result->sentences[0]->src_translit); 
     1299                unset($result->src); 
     1300                unset($result->server_time); 
     1301            } 
     1302            //die(); 
     1303        } 
     1304        header('Content-type: text/html; charset=utf-8'); 
     1305 
     1306        // here we match online results with cached ones 
     1307        $k = 0; 
     1308        for ($j = 0; $j < $i; $j++) { 
     1309            if (isset($r[$j])) { 
     1310                $jsonout->results[] = $r[$j]; 
     1311            } else { 
     1312                if (isset($jsonarr->results[$k]->sentences[0]->trans)) { 
     1313                    $jsonout->results[] = $jsonarr->results[$k]->sentences[0]->trans; 
     1314                } else { 
     1315                    $jsonout->results[] = $_GET['q' . $j]; 
     1316                } 
     1317                $k++; 
     1318            } 
     1319        } 
     1320        echo json_encode($jsonout); 
     1321 
     1322        // do the db dance - a bit hackish way to insert downloaded translations directly to the db without having 
     1323        // to pass through the user and collect $200 
     1324        if ($k) { 
     1325            $_POST['items'] = $k; 
     1326            $_POST['ln0'] = $tl; 
     1327            $_POST['sr0'] = 1; // google, hmm hmm, 
     1328            $k = 0; 
     1329            for ($j = 0; $j < $i; $j++) { 
     1330                if (!isset($r[$j])) { 
     1331                    $_POST["tk$k"] = transposh_utils::base64_url_encode($_GET['q'][$j]); // stupid, but should work 
     1332                    $_POST["tr$k"] = $jsonout->results[$j]; 
     1333                    $k++; 
     1334                } 
     1335            } 
     1336            $this->database->update_translation(); 
     1337        } 
     1338 
     1339        die(); 
     1340    } 
     1341 
     1342    // getting translation history 
     1343    function on_ajax_nopriv_tp_history() { 
     1344        // deleting 
     1345        if (isset($_GET['timestamp'])) { 
     1346            $this->database->del_translation_history($_GET['token'], $_GET['lang'], $_GET['timestamp']); 
     1347        } 
     1348        $this->database->get_translation_history($_GET['token'], $_GET['lang']); 
     1349        die(); 
     1350    } 
     1351 
     1352    //  the case of posted translation 
     1353    function on_ajax_nopriv_tp_translation() { 
     1354        do_action('transposh_translation_posted'); 
     1355        $this->database->update_translation(); 
     1356        die(); 
     1357    } 
     1358 
     1359    // getting translation alternates 
     1360    function on_ajax_nopriv_tp_trans_alts() { 
     1361        $this->database->get_translation_alt($_GET['token']); 
     1362        die(); 
     1363    } 
     1364 
     1365    // set the cookie with ajax, no redirect needed 
     1366    function on_ajax_nopriv_tp_cookie() { 
     1367        setcookie('TR_LNG', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN); 
     1368        logger('Cookie ' . transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url)); 
     1369        die(); 
     1370    } 
     1371 
     1372    // Set our cookie and return (if no js works - or we are in the default language) 
     1373    function on_ajax_nopriv_tp_cookie_bck() { 
     1374        setcookie('TR_LNG', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN); 
     1375        if ($_SERVER['HTTP_REFERER']) { 
     1376            $this->tp_redirect($_SERVER['HTTP_REFERER']); 
     1377        } else { 
     1378            $this->tp_redirect($my_transposh_plugin->home_url); 
     1379        } 
     1380        die(); 
     1381    } 
     1382 
    11631383} 
    11641384 
  • trunk/WordPress/plugin/transposh/wp/transposh_admin.php

    r664 r667  
    2929    private $localeleft = 'left'; 
    3030 
    31 // constructor of class, PHP4 compatible construction for backward compatibility 
     31    // constructor of class, PHP4 compatible construction for backward compatibility 
    3232    function transposh_plugin_admin(&$transposh) { 
    3333        $this->transposh = &$transposh; 
     
    4040        // register the callback been used if options of page been submitted and needs to be processed 
    4141        add_action('admin_post_save_transposh', array(&$this, 'on_save_changes')); 
    42         // register a callback to allow admin removal of warnings 
    43         add_action('wp_ajax_closed_tpwarn', array(&$this, 'on_closed_tpwarn')); 
     42        // register ajax callbacks 
     43        add_action('wp_ajax_tp_close_warning', array(&$this, 'on_ajax_tp_close_warning')); 
     44        add_action('wp_ajax_tp_backup', array(&$this, 'on_ajax_tp_backup')); 
     45        add_action('wp_ajax_tp_restore', array(&$this, 'on_ajax_tp_restore')); 
     46        add_action('wp_ajax_tp_maint', array(&$this, 'on_ajax_tp_maint')); 
     47        add_action('wp_ajax_tp_cleanup', array(&$this, 'on_ajax_tp_cleanup')); 
     48        add_action('wp_ajax_tp_translate_all', array(&$this, 'on_ajax_tp_translate_all')); 
     49        add_action('wp_ajax_tp_post_phrases', array(&$this, 'on_ajax_tp_post_phrases')); 
    4450    } 
    4551 
     
    171177        //TODO - make up my mind on using .css flags here (currently no) 
    172178        //if ($this->transposh->options->get_widget_css_flags()) 
    173 //            wp_enqueue_style("transposh_flags",$this->transposh->transposh_plugin_url."/widgets/flags/tpw_flags.css",array(),TRANSPOSH_PLUGIN_VER); 
     179        //            wp_enqueue_style("transposh_flags",$this->transposh->transposh_plugin_url."/widgets/flags/tpw_flags.css",array(),TRANSPOSH_PLUGIN_VER); 
    174180        wp_enqueue_script('jquery-ui-droppable'); 
    175         wp_enqueue_script('transposh_control', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhcontrol.js', array(), TRANSPOSH_PLUGIN_VER, true); 
    176         wp_localize_script('transposh_control', 't_jp', array( 
    177             'post_url' => $this->transposh->post_url, 
    178             'preferred' => $this->transposh->options->get_preferred_translator(), 
    179             'l10n_print_after' => 't_jp.g_langs = ' . json_encode(transposh_consts::$google_languages) . '; t_jp.m_langs = ' . json_encode(transposh_consts::$bing_languages) . ';'/* 
    180                   /* , 
    181                   'plugin_url' => $this->transposh_plugin_url, 
    182                   'edit' => ($this->edit_mode? '1' : ''), 
    183                   //'rtl' => (in_array ($this->target_language, $GLOBALS['rtl_languages'])? 'true' : ''), 
    184                   'lang' => $this->target_language, 
    185                   // those two options show if the script can support said engines 
    186                   'prefix' => SPAN_PREFIX, 
    187                   'preferred'=> $this->options->get_preferred_translator(), 
    188                   'progress'=>$this->edit_mode || $this->options->get_widget_progressbar() ? '1' : '') */ 
    189 //      ,'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};' 
    190                 // need to do this because the way wordpress encodes stuff 
    191         )); 
    192         wp_enqueue_script('google', "http://www.google.com/jsapi", array(), '1', true); 
    193         wp_enqueue_script('transposh_admin', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhadmin.js', array(), TRANSPOSH_PLUGIN_VER, true); 
    194         wp_enqueue_style('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/ui-lightness/jquery-ui.css', array(), '1.8.2'); 
    195         wp_enqueue_script('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js', array('jquery'), '1.8.2', true); 
     181        wp_enqueue_script('transposh_settings', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhsettings.js', array(), TRANSPOSH_PLUGIN_VER, true); 
     182        // MAKESURE 3.3+ css 
     183        // wp_enqueue_script('jquery-ui-progressbar'); 
     184 
     185        wp_enqueue_style('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . JQUERYUI_VER . '/themes/ui-lightness/jquery-ui.css', array(), JQUERYUI_VER); 
     186        wp_enqueue_script('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . JQUERYUI_VER . '/jquery-ui.min.js', array('jquery'), JQUERYUI_VER, true); 
     187        wp_enqueue_script('transposh_backend', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhbackend.js', array(), TRANSPOSH_PLUGIN_VER, true); 
     188        $script_params = array( 
     189            'l10n_print_after' => 
     190            't_be.g_langs = ' . json_encode(transposh_consts::$google_languages) . ';' . 
     191            't_be.m_langs = ' . json_encode(transposh_consts::$bing_languages) . ';' . 
     192            't_be.a_langs = ' . json_encode(transposh_consts::$apertium_languages) . ';' 
     193        ); 
     194        wp_localize_script("transposh_backend", "t_be", $script_params); 
    196195 
    197196        //add several metaboxes now, all metaboxes registered during load page can be switched off/on at "Screen Options" automatically, nothing special to do therefore 
     
    322321        echo '<div id="progress_bar_all"></div><div id="tr_translate_title"></div>'; 
    323322        echo '<div id="tr_loading" style="margin: 0 0 10px 0">' . __('Translate by clicking the button below', TRANSPOSH_TEXT_DOMAIN) . '</div>'; 
    324         echo '<a id="transposh-translate" href="' . $this->transposh->post_url . '?translate_all&offset=1" onclick="return false;" class="button">' . __('Translate All Now', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>'; 
     323        echo '<div id="tr_allmsg" style="margin: 0 0 10px 0"></div>'; 
     324        echo '<a id="transposh-translate" href="#" onclick="return false;" class="button">' . __('Translate All Now', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>'; 
    325325        //get_posts 
    326326    } 
     
    503503         */ 
    504504        echo '<h4>' . __('MSN API key', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 
    505         echo __('API Key', TRANSPOSH_TEXT_DOMAIN).': <input type="text" size="35" class="regular-text" value="' . $this->transposh->options->get_msn_key() . '" id="'.MSN_TRANSLATE_KEY.'" name="'.MSN_TRANSLATE_KEY.'"/>'; 
    506  
    507           /** 
     505        echo __('API Key', TRANSPOSH_TEXT_DOMAIN) . ': <input type="text" size="35" class="regular-text" value="' . $this->transposh->options->get_msn_key() . '" id="' . MSN_TRANSLATE_KEY . '" name="' . MSN_TRANSLATE_KEY . '"/>'; 
     506 
     507        /** 
    508508         * Allow users to insert their own API keys 
    509509         */ 
    510510        echo '<h4>' . __('Google API key', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 
    511         echo __('API Key', TRANSPOSH_TEXT_DOMAIN).': <input type="text" size="35" class="regular-text" value="' . $this->transposh->options->get_google_key() . '" id="'.GOOGLE_TRANSLATE_KEY.'" name="'.GOOGLE_TRANSLATE_KEY.'"/>'; 
     511        echo __('API Key', TRANSPOSH_TEXT_DOMAIN) . ': <input type="text" size="35" class="regular-text" value="' . $this->transposh->options->get_google_key() . '" id="' . GOOGLE_TRANSLATE_KEY . '" name="' . GOOGLE_TRANSLATE_KEY . '"/>'; 
    512512 
    513513        /* 
     
    593593    } 
    594594 
    595     function on_closed_tpwarn() { 
     595    // ajax stuff! 
     596    function on_ajax_tp_close_warning() { 
    596597        $this->transposh->options->set_transposh_admin_hide_warning($_POST['id']); 
    597598        $this->transposh->options->update_options(); 
     
    599600    } 
    600601 
     602    function on_ajax_tp_backup() { 
     603        $this->transposh->run_backup(); 
     604        die(); 
     605    } 
     606 
     607    // Start restore on demand 
     608    function on_ajax_tp_restore() { 
     609        $this->transposh->run_restore(); 
     610        die(); 
     611    } 
     612 
     613    // Start cleanup on demand 
     614    function on_ajax_tp_cleanup() { 
     615        $this->transposh->database->cleanup($_POST['days']); 
     616        die(); 
     617    } 
     618 
     619    // Start maint 
     620    function on_ajax_tp_maint() { 
     621        $this->transposh->database->db_maint(); 
     622        die(); 
     623    } 
     624 
     625    // Start full translation 
     626    function on_ajax_tp_translate_all() { 
     627        // get all ids in need of translation 
     628        global $wpdb; 
     629        $page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE (post_type='page' OR post_type='post') AND (post_status='publish' OR post_status='private') ORDER BY ID DESC"); 
     630        // only high capabilities users can... 
     631        // add a fake post to translate things such as tags 
     632        if (!current_user_can('edit_post', $page_ids[0])) return; 
     633        $page_ids[] = "-555"; 
     634        echo json_encode($page_ids); 
     635        die(); 
     636    } 
     637 
     638    // getting phrases of a post (if we are in admin) 
     639    function on_ajax_tp_post_phrases() { 
     640        $this->transposh->postpublish->get_post_phrases($_GET['post']); 
     641        die(); 
     642    } 
     643 
    601644} 
    602645 
  • trunk/WordPress/plugin/transposh/wp/transposh_ajax.php

    r599 r667  
    1515 * This file handles various AJAX needs of our plugin 
    1616 */ 
    17 // The following headers allow for cross-domain posting here, which is useful for some weird sites 
    18 header('Access-Control-Allow-Origin: *'); 
    19 header('Access-Control-Allow-Methods: GET, POST, OPTIONS'); 
    20 header('Access-Control-Allow-Headers: X-Requested-With'); 
    21 header('Access-Control-Max-Age: 86400'); 
    2217 
    23 // Exit early so the page isn't fully loaded for options requests 
    24 if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') { 
    25     exit(); 
    26 } 
     18echo "This file was removed in 0.8.0 and is only kept for debugging"; 
    2719 
    28 // we need wordpress and us... 
    29 $root = $_SERVER["DOCUMENT_ROOT"]; 
    30 $self = $_SERVER["SCRIPT_NAME"]; 
    31 // go down 4 dirs... 
    32 for ($i = 0; $i < 5; $i++) 
    33     $self = substr($self, 0, -strlen(strrchr($self, '/'))); 
    34 if (file_exists($root . $self . '/wp-load.php')) { 
    35     require_once $root . $self . '/wp-load.php'; 
    36 } else { 
    37     // fallback plan 
    38     require_once('../../../../wp-load.php'); 
    39 } 
    40 //  the case of posted translation 
    41 if (isset($_POST['translation_posted'])) { 
    42     do_action('transposh_translation_posted'); 
    43     $my_transposh_plugin->database->update_translation(); 
    44 } 
    45 // getting translation history 
    46 elseif (isset($_GET['tr_token_hist'])) { 
    47     // deleting 
    48     if (isset($_GET['action']) && $_GET['action'] == 'delete') { 
    49         $my_transposh_plugin->database->del_translation_history($_GET['tr_token_hist'], $_GET['lang'], $_GET['timestamp']); 
    50     } 
    51     $my_transposh_plugin->database->get_translation_history($_GET['tr_token_hist'], $_GET['lang']); 
    52 } 
    53 // getting translation alternates 
    54 elseif (isset($_GET['tr_token_alt'])) { 
    55     $my_transposh_plugin->database->get_translation_alt($_GET['tr_token_alt']); 
    56 } 
    57 // getting phrases of a post (if we are in admin) 
    58 elseif (isset($_GET['tr_phrases_post'])) { 
    59     $my_transposh_plugin->postpublish->get_post_phrases($_GET['post']); 
    60 } 
    61 // set the cookie with ajax, no redirect needed 
    62 elseif (isset($_GET['tr_cookie'])) { 
    63     setcookie('TR_LNG', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN); 
    64     logger('Cookie ' . transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url)); 
    65 } 
    66 // Set our cookie and return (if no js works - or we are in the default language) 
    67 elseif (isset($_GET['tr_cookie_bck'])) { 
    68     setcookie('TR_LNG', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN); 
    69     if ($_SERVER['HTTP_REFERER']) { 
    70         $this->transposh->tp_redirect($_SERVER['HTTP_REFERER']); 
    71     } else { 
    72         $this->transposh->tp_redirect($my_transposh_plugin->home_url); 
    73     } 
    74 } 
    75 // Start full translation 
    76 elseif (isset($_GET['translate_all'])) { 
    77     // get all ids in need of translation 
    78     $page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE (post_type='page' OR post_type='post') AND (post_status='publish' OR post_status='private') ORDER BY ID DESC"); 
    79     // only high capabilities users can... 
    80     if (!current_user_can('edit_post', $page_ids[0])) return; 
    81     // add a fake post to translate things such as tags 
    82     $page_ids[] = "-555"; 
    83     echo json_encode($page_ids); 
    84 } 
    85 // Proxyed translation for google translate 
    86 elseif (isset($_GET['tgp'])) { 
    87     // we need curl for this proxy 
    88     if (!function_exists('curl_init')) return; 
    89     // we want to avoid unneeded work or dos attacks on languages we don't support 
    90     if (!in_array($_GET['tgl'], transposh_consts::$google_proxied_languages) || !$my_transposh_plugin->options->is_editable_language($_GET['tgl'])) 
    91             return; 
    92     $url = 'http://translate.google.com/translate_a/t?client=a&text=' . urlencode($_GET['tgp']) . '&tl=' . $_GET['tgl'] . '&sl=auto'; 
    93     $ch = curl_init(); 
    94     curl_setopt($ch, CURLOPT_URL, $url); 
    95     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    96     //must set agent for google to respond with utf-8 
    97     curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0'); 
    98     $output = curl_exec($ch); 
    99     curl_close($ch); 
    100     header('Content-type: text/html; charset=utf-8'); 
    101     echo $output; 
    102 } 
    103 // Start backup on demand 
    104 elseif (isset($_GET['backup'])) { 
    105     $my_transposh_plugin->run_backup(); 
    106 } 
    107 // Start restore on demand 
    108 elseif (isset($_GET['restore'])) { 
    109     $my_transposh_plugin->run_restore(); 
    110 } 
    111 // Start cleanup on demand 
    112 elseif (isset($_GET['cleanup'])) { 
    113     // just make sure the admin started this... recently enough 
    114     check_ajax_referer('transposh-clean', 'nonce'); 
    115     $my_transposh_plugin->database->cleanup($_GET['days']); 
    116 } 
    117 // Start maint 
    118 elseif (isset($_GET['maint'])) { 
    119     // just make sure the admin started this... recently enough 
    120     check_ajax_referer('transposh-clean', 'nonce'); 
    121     $my_transposh_plugin->database->db_maint(); 
    122 } 
    12320?> 
  • trunk/WordPress/plugin/transposh/wp/transposh_backup.php

    r506 r667  
    4747            return; 
    4848        } 
    49         if ($result['headers']['fail']) { 
     49        if (isset($result['headers']['fail'])) { 
    5050            echo '500 - ' . $result['headers']['fail']; 
    5151            return; 
     
    5757            $this->transposh->options->update_options(); 
    5858        } 
    59         if ($result['headers']['lastitem']) { 
     59        if (isset($result['headers']['lastitem'])) { 
    6060            $rowstosend = $this->transposh->database->get_all_human_translation_history($result['headers']['lastitem'], 500); 
    6161            while ($rowstosend) { 
     
    8282                    return; 
    8383                } 
    84                 if ($result['headers']['fail']) { 
     84                if (isset($result['headers']['fail'])) { 
    8585                    echo "500 - " . $result['headers']['fail']; 
    8686                    return; 
  • trunk/WordPress/plugin/transposh/wp/transposh_db.php

    r661 r667  
    6969          //@$this->memcache->connect(TP_MEMCACHED_SRV, TP_MEMCACHED_PORT) or $this->memcache_working = false; 
    7070          } */ 
    71         logger($this->memcache_working); 
     71        logger($this->memcache_working); // TODO!! make sure it does something 
    7272    } 
    7373 
     
    604604     */ 
    605605    function get_all_human_translation_history($date ="null", $limit = "") { 
     606        $limitterm = ''; 
     607        $dateterm = ''; 
    606608        if ($date != "null") 
    607609                $dateterm = "and UNIX_TIMESTAMP(timestamp) > $date"; 
  • trunk/WordPress/plugin/transposh/wp/transposh_postpublish.php

    r652 r667  
    2323    /** @var transposh_plugin Container class */ 
    2424    private $transposh; 
     25 
    2526    /** @var boolean Did we just edited/saved? */ 
    2627    private $just_published = false; 
     
    5354        if (!isset($_GET['post'])) return; 
    5455        if (get_post_meta($_GET['post'], 'transposh_can_translate', true)) { // do isdefined stuff 
    55             $this->just_published = true; // this is later used in the meta boxes 
    56             wp_enqueue_script("transposhadmin", $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhadmin.js', array('jquery'), TRANSPOSH_PLUGIN_VER, true); 
    57             wp_localize_script("transposhadmin", "t_jp", array( 
    58                 'post_url' => $this->transposh->post_url, 
     56            $this->just_published = true; // this is later used in the meta boxes //XXXXXXXXXXXXXXXXXXXXXXXXXXXX 
     57            wp_enqueue_script("transposh_backend", $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhbackend.js', array('jquery'), TRANSPOSH_PLUGIN_VER, true); 
     58            $script_params = array( 
    5959                'post' => $_GET['post'], 
    60                 'preferred' => $this->transposh->options->get_preferred_translator(), 
    61                 'l10n_print_after' => 't_jp.g_langs = ' . json_encode(transposh_consts::$google_languages) . '; t_jp.m_langs = ' . json_encode(transposh_consts::$bing_languages) . ';' 
    62             )); 
    63             wp_enqueue_style('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/ui-lightness/jquery-ui.css', array(), '1.8.14'); 
    64             wp_enqueue_script('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js', array('jquery'), '1.8.14', true); 
     60                'l10n_print_after' => 
     61                't_be.g_langs = ' . json_encode(transposh_consts::$google_languages) . ';' . 
     62                't_be.m_langs = ' . json_encode(transposh_consts::$bing_languages) . ';' . 
     63                't_be.a_langs = ' . json_encode(transposh_consts::$apertium_languages) . ';' 
     64            ); 
     65            wp_localize_script("transposh_backend", "t_be", $script_params); 
     66            // MAKESURE 3.3 
     67//        wp_enqueue_script('jquery-ui-progressbar'); 
     68 
     69            wp_enqueue_style('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . JQUERYUI_VER . '/themes/ui-lightness/jquery-ui.css', array(), JQUERYUI_VER); 
     70            wp_enqueue_script('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . JQUERYUI_VER . '/jquery-ui.min.js', array('jquery'), JQUERYUI_VER, true); 
     71 
    6572            delete_post_meta($_GET['post'], 'transposh_can_translate'); // as we have used the meta - it can go now, another option would have been to put this in the getphrases 
    6673        } 
     
    8693    function get_post_phrases($postID) { 
    8794        // Some security, to avoid others from seeing private posts 
    88         if (!current_user_can('edit_post', $postID)) return; 
    8995        // fake post for tags 
    9096        if ($postID == -555) { 
     
    94100        // a normal post 
    95101        else { 
     102            if (!current_user_can('edit_post', $postID)) return; 
     103            global $post; // thid is needed because some of the functions below expect it... 
    96104            $post = get_post($postID); 
    97105            // Display filters 
     
    127135            } 
    128136        } 
     137        // We provide the post title here 
     138        $json['posttitle'] = $title; 
     139        // and all languages we might want to target 
     140        $json['langs'] = array(); 
     141 
    129142        foreach ($phrases as $key) { 
    130143            foreach (explode(',', $this->transposh->options->get_editable_langs()) as $lang) { 
     
    133146                if (!$this->transposh->options->is_default_language($lang) || $this->transposh->options->get_enable_default_translate()) { 
    134147                    // There is no point in returning phrases, languages pairs that cannot be translated 
    135                     if (in_array($lang, transposh_consts::$bing_languages) || in_array($lang, transposh_consts::$google_languages)) { 
     148                    if (in_array($lang, transposh_consts::$bing_languages) || 
     149                            in_array($lang, transposh_consts::$google_languages) || 
     150                            in_array($lang, transposh_consts::$apertium_languages)) { 
    136151                        list($source, $translation) = $this->transposh->database->fetch_translation($key, $lang); 
    137152                        if (!$translation) { 
     
    141156                            } 
    142157                            array_push($json['p'][$key]['l'], $lang); 
     158                            if (!in_array($lang, $json['langs'])) { 
     159                                array_push($json['langs'], $lang); 
     160                            } 
    143161                        } 
    144162                    } 
     
    152170        } 
    153171 
    154         // add the title 
    155         //        if ($json['length']) 
    156         $json['posttitle'] = $title; 
    157172 
    158173        // the header helps with debugging 
  • trunk/WordPress/plugin/transposh/wp/transposh_widget.php

    r659 r667  
    223223            if ($this->transposh->options->get_widget_allow_set_default_language()) { 
    224224                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))) { 
    225                     echo '<a id="' . SPAN_PREFIX . 'setdeflang" onClick="return false;" href="' . $this->transposh->post_url . '?tr_cookie_bck">' . __('Set as default language', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>'; 
     225                    echo '<a id="' . 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/>'; 
    226226                } 
    227227            } 
Note: See TracChangeset for help on using the changeset viewer.