Transposh WordPress Translation - Version 0.5.3

Version Description

Support URL translation

Download this release

Release Info

Developer oferwald
Plugin Icon 128x128 Transposh WordPress Translation
Version 0.5.3
Comparing to
See all releases

Code changes from version 0.5.2 to 0.5.3

core/constants.php CHANGED
@@ -99,7 +99,7 @@ $bing_languages = array("en", "ar", "bg", "zh", "zh-tw", "cs", "da", "nl", "ht",
99
  //Define the new capability that will be assigned to roles - translator
100
  define("TRANSLATOR", 'translator');
101
 
102
- define("TRANSPOSH_PLUGIN_VER",'0.5.2');
103
 
104
  //Define segment id prefix, will be included in span tag. also used as class identifier
105
  define("SPAN_PREFIX", "tr_");
99
  //Define the new capability that will be assigned to roles - translator
100
  define("TRANSLATOR", 'translator');
101
 
102
+ define("TRANSPOSH_PLUGIN_VER",'0.5.3');
103
 
104
  //Define segment id prefix, will be included in span tag. also used as class identifier
105
  define("SPAN_PREFIX", "tr_");
core/utils.php CHANGED
@@ -83,6 +83,7 @@ function cleanup_url($url, $home_url, $remove_host = false) {
83
  * @param boolean $use_params_only - only use paramaters and avoid permalinks
84
  */
85
  // Should send a transposh interface to here TODO - enable permalinks rewrite
 
86
  function rewrite_url_lang_param($url,$home_url, $enable_permalinks_rewrite, $lang, $is_edit, $use_params_only=FALSE) {
87
 
88
 
@@ -134,12 +135,14 @@ function rewrite_url_lang_param($url,$home_url, $enable_permalinks_rewrite, $lan
134
  $params[edit] = EDIT_PARAM . '=1';
135
  }
136
 
137
- if($use_params_only) {
138
  $params['lang'] = LANG_PARAM . "=$lang";
139
  }
140
  else {
141
- if (!$parsedurl['path']) $parsedurl['path'] = "/";
142
- $parsedurl['path'] = "/".$lang.$parsedurl['path'];
 
 
143
  }
144
  if ($gluebackhome) $parsedurl['path'] = $home_path.$parsedurl['path'];
145
 
@@ -239,6 +242,87 @@ function base64_url_decode($input) {
239
  return base64_decode(strtr($input, '-_,', '+/='));
240
  }
241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  /**
243
  * Function to display a flag
244
  * @param string $path path to flag images
83
  * @param boolean $use_params_only - only use paramaters and avoid permalinks
84
  */
85
  // Should send a transposh interface to here TODO - enable permalinks rewrite
86
+ // TODO - Should be able to not write default language for url (done with empty lang?)
87
  function rewrite_url_lang_param($url,$home_url, $enable_permalinks_rewrite, $lang, $is_edit, $use_params_only=FALSE) {
88
 
89
 
135
  $params[edit] = EDIT_PARAM . '=1';
136
  }
137
 
138
+ if($use_params_only && $lang) {
139
  $params['lang'] = LANG_PARAM . "=$lang";
140
  }
141
  else {
142
+ if ($lang) {
143
+ if (!$parsedurl['path']) $parsedurl['path'] = "/";
144
+ $parsedurl['path'] = "/".$lang.$parsedurl['path'];
145
+ }
146
  }
147
  if ($gluebackhome) $parsedurl['path'] = $home_path.$parsedurl['path'];
148
 
242
  return base64_decode(strtr($input, '-_,', '+/='));
243
  }
244
 
245
+ /**
246
+ * Function to translate a given url permalink to a target language
247
+ * TODO - check params
248
+ * @param string $href
249
+ * @param string $home_url
250
+ * @param string $target_language
251
+ * @param function $fetch_translation_func
252
+ * @return string translated url permalink
253
+ */
254
+ function translate_url($href, $home_url, $target_language,$fetch_translation_func) {
255
+ // todo - check query part... sanitize
256
+ if (strpos($href,'?') !== false) {
257
+ list ($href,$querypart) = explode('?', $href);
258
+ $querypart = '?'.$querypart;
259
+ }
260
+ $href = substr($href,strlen($home_url)+1);
261
+ $parts = explode('/', $href);
262
+ foreach ($parts as $part) {
263
+ if (!$part) continue;
264
+ list($translated_text, $old_source) = call_user_func_array($fetch_translation_func, array($part, $target_language));
265
+ if ($translated_text)
266
+ $url .= '/'.str_replace(' ', '-',$translated_text);
267
+ else {
268
+ // now the same attempt with '-' replaced to ' '
269
+ list($translated_text, $old_source) = call_user_func_array($fetch_translation_func, array(str_replace('-', ' ', $part), $target_language));
270
+ //
271
+ if ($translated_text)
272
+ $url .= '/'.str_replace(' ', '-',$translated_text);
273
+ else
274
+ $url .= '/'.$part;
275
+ }
276
+ }
277
+ if (substr($href,strlen($href)-1) == '/')
278
+ $url.='/';
279
+ return $home_url.$url.$querypart;
280
+ }
281
+
282
+ /**
283
+ * From a given translated url, tries to get the original URL
284
+ * @param string $href
285
+ * @param string $home_url
286
+ * @param string $target_language
287
+ * @param function $fetch_translation_func
288
+ * @return string
289
+ */
290
+ function get_original_url($href, $home_url, $target_language,$fetch_translation_func) {
291
+ $href = substr($href,strlen($home_url)+1);
292
+ $url = urldecode($href);
293
+ $url = (($pos=strpos($url, '?')) ? substr($url, 0, $pos) : $url);
294
+ $parts = explode('/', $url);
295
+ foreach ($parts as $part) {
296
+ if (!$part) continue;
297
+ // don't attempt for lang or numbers
298
+ if ($part == $target_language || is_numeric($part)) {
299
+ $url2 .= '/'.$part;
300
+ continue;
301
+ }
302
+
303
+ $original_text = call_user_func_array($fetch_translation_func, array($part, $target_language));
304
+ if ($original_text)
305
+ $url2 .= '/'.strtolower(str_replace(' ', '-',$original_text)); //? CHECK
306
+ else {
307
+ $original_text = call_user_func_array($fetch_translation_func, array(str_replace('-', ' ', $part), $target_language));
308
+ if ($original_text)
309
+ $url2 .= '/'.strtolower(str_replace(' ', '-',$original_text)); //? CHECK
310
+ else
311
+ $url2 .= '/'.$part;
312
+ }
313
+ }
314
+ // TODO: Consider sanitize_title_with_dashes
315
+ // TODO : need to handle params....
316
+ //
317
+ //if (substr($url,strlen($url)-1) == '/') $url2 .= '/';
318
+ //$url2 = rtrim($url2,'/');
319
+ //
320
+ //$href = $this->home_url.$url2;
321
+ if (substr($href,strlen($href)-1) == '/')
322
+ $url2.='/';
323
+ return $home_url.$url2;
324
+ }
325
+
326
  /**
327
  * Function to display a flag
328
  * @param string $path path to flag images
js/transposh.js CHANGED
@@ -2,5 +2,5 @@
2
  h.push(d);m.push(c);w(d,c);r=setTimeout(function(){var f={ln0:t_jp.lang,sr0:s,translation_posted:"2",items:h.length},b;for(b=0;b<h.length;b+=1){f["tk"+b]=h[b];f["tr"+b]=m[b];t+=a("*[data-token='"+h[b]+"']").size()}a.ajax({type:"POST",url:t_jp.post_url,data:f,success:function(){l(j,t/g*100)}});m=[];h=[]},200)}function x(){a("#"+e+"credit").css({overflow:"auto"}).append('<div style="float: left;width: 90%;height: 10px" id="'+i+'"/><div style="margin-bottom:10px;float:left;width: 90%;height: 10px" id="'+
3
  j+'"/>');a("#"+i).progressbar({value:0});a("#"+j).progressbar({value:0});a("#"+j+" > div").css({background:"#28F828",border:"#08A908 1px solid"})}function u(){var d=[],c=t_jp.lang;a("."+e+'[data-source=""]').each(function(){var f=a(this).attr("data-token"),b=a(this).attr("data-orig");if(b===undefined)b=a(this).html();if(d[b]!==1){d[b]=1;if(typeof Microsoft!=="undefined"){if(c==="zh")c="zh-chs";else if(c==="zh-tw")c="zh-cht";try{Microsoft.Translator.translate(b,"",c,function(k){q(f,a("<div>"+k+"</div>").text());
4
  l(i,(g-a("."+e+'[data-source=""]').size())/g*100)})}catch(p){}}else google.language.translate(b,"",t_jp.lang,function(k){if(!k.error){q(f,a("<div>"+k.translation+"</div>").text());l(i,(g-a("."+e+'[data-source=""]').size())/g*100)}})}})}var n,v,o,g,e=t_jp.prefix,i=e+"pbar",j=i+"_s",s=1,t=0,r,h=[],m=[];v=function(){google.load("language","1",{callback:n})};a(document).ready(function(){a("#"+e+"setdeflang").click(function(){a.get(t_jp.post_url+"?tr_cookie="+Math.random());a(this).hide("slow");return false});
5
- var d;g=a("."+e+'[data-source=""]').size();d=new Date;a.ajaxSetup({cache:true});if((g>5||d.getHours()===4&&g>0)&&(t_jp.google||t_jp.msn)){n=function(){if(t_jp.progress){var c=function(){a.xLazyLoader({js:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js",css:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css",success:function(){x();u()}})};typeof a.xLazyLoader==="function"?c():a.getScript(t_jp.plugin_url+"/js/lazy.js",c)}else u()};if(t_jp.msn&&
6
  t_jp.preferred===2||!t_jp.google){s=2;o=function(){a.getScript("http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId="+t_jp.msnkey,n)};t_jp.edit&&t_jp.progress?a.getScript(t_jp.plugin_url+"/js/lazy.js",o):o()}else a.getScript("http://www.google.com/jsapi",v)}t_jp.edit&&a.getScript(t_jp.plugin_url+"/js/transposhedit.js")})})(jQuery);
2
  h.push(d);m.push(c);w(d,c);r=setTimeout(function(){var f={ln0:t_jp.lang,sr0:s,translation_posted:"2",items:h.length},b;for(b=0;b<h.length;b+=1){f["tk"+b]=h[b];f["tr"+b]=m[b];t+=a("*[data-token='"+h[b]+"']").size()}a.ajax({type:"POST",url:t_jp.post_url,data:f,success:function(){l(j,t/g*100)}});m=[];h=[]},200)}function x(){a("#"+e+"credit").css({overflow:"auto"}).append('<div style="float: left;width: 90%;height: 10px" id="'+i+'"/><div style="margin-bottom:10px;float:left;width: 90%;height: 10px" id="'+
3
  j+'"/>');a("#"+i).progressbar({value:0});a("#"+j).progressbar({value:0});a("#"+j+" > div").css({background:"#28F828",border:"#08A908 1px solid"})}function u(){var d=[],c=t_jp.lang;a("."+e+'[data-source=""]').each(function(){var f=a(this).attr("data-token"),b=a(this).attr("data-orig");if(b===undefined)b=a(this).html();if(d[b]!==1){d[b]=1;if(typeof Microsoft!=="undefined"){if(c==="zh")c="zh-chs";else if(c==="zh-tw")c="zh-cht";try{Microsoft.Translator.translate(b,"",c,function(k){q(f,a("<div>"+k+"</div>").text());
4
  l(i,(g-a("."+e+'[data-source=""]').size())/g*100)})}catch(p){}}else google.language.translate(b,"",t_jp.lang,function(k){if(!k.error){q(f,a("<div>"+k.translation+"</div>").text());l(i,(g-a("."+e+'[data-source=""]').size())/g*100)}})}})}var n,v,o,g,e=t_jp.prefix,i=e+"pbar",j=i+"_s",s=1,t=0,r,h=[],m=[];v=function(){google.load("language","1",{callback:n})};a(document).ready(function(){a("#"+e+"setdeflang").click(function(){a.get(t_jp.post_url+"?tr_cookie="+Math.random());a(this).hide("slow");return false});
5
+ var d;g=a("."+e+'[data-source=""]').size();d=new Date;a.ajaxSetup({cache:true});if((g>5||d.getHours()===4&&g>0)&&(t_jp.google||t_jp.msn)){n=function(){if(t_jp.progress){var c=function(){a.xLazyLoader({js:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.3/jquery-ui.min.js",css:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.3/themes/ui-lightness/jquery-ui.css",success:function(){x();u()}})};typeof a.xLazyLoader==="function"?c():a.getScript(t_jp.plugin_url+"/js/lazy.js",c)}else u()};if(t_jp.msn&&
6
  t_jp.preferred===2||!t_jp.google){s=2;o=function(){a.getScript("http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId="+t_jp.msnkey,n)};t_jp.edit&&t_jp.progress?a.getScript(t_jp.plugin_url+"/js/lazy.js",o):o()}else a.getScript("http://www.google.com/jsapi",v)}t_jp.edit&&a.getScript(t_jp.plugin_url+"/js/transposhedit.js")})})(jQuery);
js/transposhedit.js CHANGED
@@ -9,5 +9,5 @@ a("table tbody td[source='0']",d.panel).append('<span title="human" style="displ
9
  "none").css("list-style-position","outside");a("#"+t_jp.prefix+"d-tabs-1").css("padding","1px").append('<form id="'+t_jp.prefix+'form"><fieldset><label for="original">Original Text</label><textarea cols="80" row="3" name="original" id="'+t_jp.prefix+'original" class="text ui-widget-content ui-corner-all" readonly="y"/><label for="translation">Translate To</label><textarea cols="80" row="3" name="translation" id="'+t_jp.prefix+'translation" value="" class="text ui-widget-content ui-corner-all"/></fieldset></form>');
10
  a("#"+t_jp.prefix+"d-tabs-1 label").css("display","block");a("#"+t_jp.prefix+"d-tabs-1 textarea.text").css({"margin-bottom":"12px",width:"95%",padding:".4em"});a("#"+t_jp.prefix+"original").val(a("#"+t_jp.prefix+b).attr("data-orig"));a("#"+t_jp.prefix+"translation").val(a("#"+t_jp.prefix+b).html());a("#"+t_jp.prefix+b).attr("data-trans")&&a("#"+t_jp.prefix+"translation").val(a("#"+t_jp.prefix+b).attr("data-trans"));a("#"+t_jp.prefix+"translation").data("edit",{changed:false});a("#"+t_jp.prefix+"translation").keyup(function(){if(a("#"+
11
  t_jp.prefix+b).text()!==a(this).val()){a(this).css("background","yellow");a(this).data("edit",{changed:true})}else{a(this).css("background","");a(this).data("edit",{changed:false})}});a("#"+t_jp.prefix+"d-tabs").dialog({bgiframe:true,modal:true,width:500,buttons:c})}var h,i;a("."+t_jp.prefix).each(function(){var b=a(this).attr("id").substr(a(this).attr("id").lastIndexOf("_")+1),c;a(this).after('<span id="'+t_jp.prefix+"img_"+b+'" class="tr-icon" title="'+a(this).attr("data-orig")+'"></span>');c=a("#"+
12
- t_jp.prefix+"img_"+b);c.click(function(){if(typeof a.fn.tabs!=="function"){a.ajaxSetup({cache:true});a.getScript(t_jp.plugin_url+"/js/lazy.js",function(){a.xLazyLoader({js:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js",css:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css",success:function(){k(b)}})})}else k(b);return false}).css({border:"0px",margin:"1px",padding:"0px"});if(a(this).attr("data-source")==="0")c.addClass("tr-icon-green");
13
  else a(this).attr("data-source")&&c.addClass("tr-icon-yellow");a(this).attr("data-hidden")==="y"&&c.css({opacity:"0.6"})})})(jQuery);
9
  "none").css("list-style-position","outside");a("#"+t_jp.prefix+"d-tabs-1").css("padding","1px").append('<form id="'+t_jp.prefix+'form"><fieldset><label for="original">Original Text</label><textarea cols="80" row="3" name="original" id="'+t_jp.prefix+'original" class="text ui-widget-content ui-corner-all" readonly="y"/><label for="translation">Translate To</label><textarea cols="80" row="3" name="translation" id="'+t_jp.prefix+'translation" value="" class="text ui-widget-content ui-corner-all"/></fieldset></form>');
10
  a("#"+t_jp.prefix+"d-tabs-1 label").css("display","block");a("#"+t_jp.prefix+"d-tabs-1 textarea.text").css({"margin-bottom":"12px",width:"95%",padding:".4em"});a("#"+t_jp.prefix+"original").val(a("#"+t_jp.prefix+b).attr("data-orig"));a("#"+t_jp.prefix+"translation").val(a("#"+t_jp.prefix+b).html());a("#"+t_jp.prefix+b).attr("data-trans")&&a("#"+t_jp.prefix+"translation").val(a("#"+t_jp.prefix+b).attr("data-trans"));a("#"+t_jp.prefix+"translation").data("edit",{changed:false});a("#"+t_jp.prefix+"translation").keyup(function(){if(a("#"+
11
  t_jp.prefix+b).text()!==a(this).val()){a(this).css("background","yellow");a(this).data("edit",{changed:true})}else{a(this).css("background","");a(this).data("edit",{changed:false})}});a("#"+t_jp.prefix+"d-tabs").dialog({bgiframe:true,modal:true,width:500,buttons:c})}var h,i;a("."+t_jp.prefix).each(function(){var b=a(this).attr("id").substr(a(this).attr("id").lastIndexOf("_")+1),c;a(this).after('<span id="'+t_jp.prefix+"img_"+b+'" class="tr-icon" title="'+a(this).attr("data-orig")+'"></span>');c=a("#"+
12
+ t_jp.prefix+"img_"+b);c.click(function(){if(typeof a.fn.tabs!=="function"){a.ajaxSetup({cache:true});a.getScript(t_jp.plugin_url+"/js/lazy.js",function(){a.xLazyLoader({js:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.3/jquery-ui.min.js",css:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.3/themes/ui-lightness/jquery-ui.css",success:function(){k(b)}})})}else k(b);return false}).css({border:"0px",margin:"1px",padding:"0px"});if(a(this).attr("data-source")==="0")c.addClass("tr-icon-green");
13
  else a(this).attr("data-source")&&c.addClass("tr-icon-yellow");a(this).attr("data-hidden")==="y"&&c.css({opacity:"0.6"})})})(jQuery);
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: oferwald
3
  Donate link: http://transposh.org/donate/
4
  Tags: translation, widget, filter, bilingual, multilingual, transposh, translate, language, crowdsourcing, context, wiki, RTL, Hebrew, Spanish, French, Russian, English, Arabic, Portuguese
5
  Requires at least: 2.7
6
- Tested up to: 3.0 beta-1
7
- Stable tag: 0.5.2
8
 
9
  Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
10
 
@@ -159,6 +159,8 @@ images based on the current language
159
  5. Widget style selection box, with three basic appearances, flags below (in Hebrew), language selection on the top right and language list on the bottom right.
160
 
161
  == Upgrade Notice ==
 
 
162
  = 0.5.2 =
163
  Improved lang attribute support, changed default language translation option
164
  = 0.5.1 =
@@ -175,6 +177,12 @@ This version provides integration with google-sitemaps-xml and wp-super-cache
175
  This version allows sorting of languages within the widget
176
 
177
  == Changelog ==
 
 
 
 
 
 
178
  = 2010/04/11 - 0.5.2 =
179
  * support the google notranslate class notation (as an addition to no_translate)
180
  * support for lang tagging on paragraphs
3
  Donate link: http://transposh.org/donate/
4
  Tags: translation, widget, filter, bilingual, multilingual, transposh, translate, language, crowdsourcing, context, wiki, RTL, Hebrew, Spanish, French, Russian, English, Arabic, Portuguese
5
  Requires at least: 2.7
6
+ Tested up to: 3.0 rc-1
7
+ Stable tag: 0.5.3
8
 
9
  Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
10
 
159
  5. Widget style selection box, with three basic appearances, flags below (in Hebrew), language selection on the top right and language list on the bottom right.
160
 
161
  == Upgrade Notice ==
162
+ = 0.5.3 =
163
+ Support URL translation
164
  = 0.5.2 =
165
  Improved lang attribute support, changed default language translation option
166
  = 0.5.1 =
177
  This version allows sorting of languages within the widget
178
 
179
  == Changelog ==
180
+ = 2010.05.30 - 0.5.3 =
181
+ * Support translation of URLs
182
+ * Mark language used to comment
183
+ * Improved wp-super-cache integration
184
+ * Fixed issues with widget generating urls containing default language
185
+ * Upgrade jQueryUI to 1.7.3
186
  = 2010/04/11 - 0.5.2 =
187
  * support the google notranslate class notation (as an addition to no_translate)
188
  * support for lang tagging on paragraphs
transposh.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin URI: http://transposh.org/
5
  Description: Translation filter for WordPress, After enabling please set languages at the <a href="options-general.php?page=transposh">the options page</a> Want to help? visit our development site at <a href="http://trac.transposh.org/">trac.transposh.org</a>.
6
  Author: Team Transposh
7
- Version: 0.5.2
8
  Author URI: http://transposh.org/
9
  License: GPL (http://www.gnu.org/licenses/gpl.txt)
10
  */
@@ -110,6 +110,10 @@ class transposh_plugin {
110
  add_filter('plugin_action_links_' .preg_replace( '|^' . preg_quote(WP_PLUGIN_DIR, '|') . '/|', '', __FILE__ ), array(&$this,'plugin_action_links'));
111
  add_filter('query_vars', array(&$this,'parameter_queryvars' ));
112
  add_filter('rewrite_rules_array', array(&$this,'update_rewrite_rules'));
 
 
 
 
113
  add_action('init', array(&$this,'on_init'),0); // really high priority
114
  add_action('parse_request', array(&$this,'on_parse_request'));
115
  add_action('plugins_loaded', array(&$this,'plugin_loaded'));
@@ -119,6 +123,7 @@ class transposh_plugin {
119
  // add_action('wp_head', array(&$this,'add_transposh_async'));
120
  add_action("sm_addurl",array(&$this,'add_sm_transposh_urls'));
121
  add_action('transposh_backup_event', array(&$this,'run_backup'));
 
122
 
123
  register_activation_hook(__FILE__, array(&$this,'plugin_activate'));
124
  register_deactivation_hook(__FILE__,array(&$this,'plugin_deactivate'));
@@ -281,6 +286,9 @@ class transposh_plugin {
281
 
282
 
283
 
 
 
 
284
  // first we get the target language
285
  $this->target_language = $wp->query_vars[LANG_PARAM];
286
  if (!$this->target_language)
@@ -519,7 +527,7 @@ class transposh_plugin {
519
  * @return nothing
520
  */
521
  // lost in compatability
522
- /* function add_transposh_async() {
523
  if (!$this->edit_mode && !$this->is_auto_translate_permitted()) {
524
  return;
525
  }
@@ -602,6 +610,11 @@ class transposh_plugin {
602
  }
603
  $use_params = !$this->enable_permalinks_rewrite;
604
 
 
 
 
 
 
605
  $href = rewrite_url_lang_param($href,$this->home_url,$this->enable_permalinks_rewrite, $this->target_language, $this->edit_mode, $use_params);
606
 
607
  return $href;
@@ -697,9 +710,14 @@ class transposh_plugin {
697
  $sm_page->SetProprity(max($sm_page->GetPriority() - 0.2, 0));
698
 
699
  $viewable_langs = explode(",",$this->options->get_viewable_langs());
 
700
  foreach ($viewable_langs as $lang) {
701
  if (!$this->options->is_default_language($lang)) {
702
- $newloc = rewrite_url_lang_param($sm_page->GetUrl(), $this->home_url, $this->enable_permalinks_rewrite, $lang, false);
 
 
 
 
703
  $sm_page->SetUrl($newloc);
704
  $generatorObject->AddElement($sm_page);
705
  }
@@ -714,6 +732,54 @@ class transposh_plugin {
714
  $my_transposh_backup = new transposh_backup($this);
715
  $my_transposh_backup->do_backup();
716
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
717
  }
718
 
719
  $my_transposh_plugin = new transposh_plugin();
4
  Plugin URI: http://transposh.org/
5
  Description: Translation filter for WordPress, After enabling please set languages at the <a href="options-general.php?page=transposh">the options page</a> Want to help? visit our development site at <a href="http://trac.transposh.org/">trac.transposh.org</a>.
6
  Author: Team Transposh
7
+ Version: 0.5.3
8
  Author URI: http://transposh.org/
9
  License: GPL (http://www.gnu.org/licenses/gpl.txt)
10
  */
110
  add_filter('plugin_action_links_' .preg_replace( '|^' . preg_quote(WP_PLUGIN_DIR, '|') . '/|', '', __FILE__ ), array(&$this,'plugin_action_links'));
111
  add_filter('query_vars', array(&$this,'parameter_queryvars' ));
112
  add_filter('rewrite_rules_array', array(&$this,'update_rewrite_rules'));
113
+ if ($this->options->get_enable_url_translate()) {
114
+ add_filter('request', array(&$this,'request_filter'));
115
+ }
116
+ add_filter('comment_text', array(&$this,'comment_text_wrap'),9999); // this is a late filter...
117
  add_action('init', array(&$this,'on_init'),0); // really high priority
118
  add_action('parse_request', array(&$this,'on_parse_request'));
119
  add_action('plugins_loaded', array(&$this,'plugin_loaded'));
123
  // add_action('wp_head', array(&$this,'add_transposh_async'));
124
  add_action("sm_addurl",array(&$this,'add_sm_transposh_urls'));
125
  add_action('transposh_backup_event', array(&$this,'run_backup'));
126
+ add_action('comment_post', array(&$this,'add_comment_meta_settings'), 1);
127
 
128
  register_activation_hook(__FILE__, array(&$this,'plugin_activate'));
129
  register_deactivation_hook(__FILE__,array(&$this,'plugin_deactivate'));
286
 
287
 
288
 
289
+ // fix for custom-permalink (and others that might be double parsing?)
290
+ if ($this->target_language) return;
291
+
292
  // first we get the target language
293
  $this->target_language = $wp->query_vars[LANG_PARAM];
294
  if (!$this->target_language)
527
  * @return nothing
528
  */
529
  // lost in compatability
530
+ /* function add_transposh_async() {
531
  if (!$this->edit_mode && !$this->is_auto_translate_permitted()) {
532
  return;
533
  }
610
  }
611
  $use_params = !$this->enable_permalinks_rewrite;
612
 
613
+ // some hackery needed for url translations
614
+ // first cut home
615
+ if ($this->options->get_enable_url_translate()) {
616
+ $href = translate_url($href, $this->home_url,$this->target_language,array(&$this->database,'fetch_translation'));
617
+ }
618
  $href = rewrite_url_lang_param($href,$this->home_url,$this->enable_permalinks_rewrite, $this->target_language, $this->edit_mode, $use_params);
619
 
620
  return $href;
710
  $sm_page->SetProprity(max($sm_page->GetPriority() - 0.2, 0));
711
 
712
  $viewable_langs = explode(",",$this->options->get_viewable_langs());
713
+ $orig_url = $sm_page->GetUrl();
714
  foreach ($viewable_langs as $lang) {
715
  if (!$this->options->is_default_language($lang)) {
716
+ $newloc = $orig_url;
717
+ if ($this->options->get_enable_url_translate()) {
718
+ $newloc = translate_url($newloc, $this->home_url,$lang,array(&$this->database,'fetch_translation'));
719
+ }
720
+ $newloc = rewrite_url_lang_param($newloc, $this->home_url, $this->enable_permalinks_rewrite, $lang, false);
721
  $sm_page->SetUrl($newloc);
722
  $generatorObject->AddElement($sm_page);
723
  }
732
  $my_transposh_backup = new transposh_backup($this);
733
  $my_transposh_backup->do_backup();
734
  }
735
+
736
+ /**
737
+ * Adding the comment meta language, for later use in display
738
+ * TODO: can use the language detection feature of some translation engines
739
+ * @param int $post_id
740
+ */
741
+ function add_comment_meta_settings($post_id) {
742
+ if (get_language_from_url($_SERVER['HTTP_REFERER'],$this->home_url))
743
+ add_comment_meta($post_id, 'tp_language', get_language_from_url($_SERVER['HTTP_REFERER'],$this->home_url), true);
744
+ }
745
+
746
+ /**
747
+ * Modify comments to include the relevant language span
748
+ * @param string $text
749
+ * @return string
750
+ */
751
+ function comment_text_wrap($text) {
752
+ $comment_lang = get_comment_meta(get_comment_ID(), 'tp_language', true);
753
+ if ($comment_lang) {
754
+ $text = "<span lang =\"$comment_lang\">".$text."</span>";
755
+ }
756
+
757
+ return $text;
758
+ }
759
+
760
+ /**
761
+ * This function enables the correct parsing of translated URLs
762
+ * @global <type> $wp
763
+ * @param <type> $query
764
+ * @return <type>
765
+ */
766
+ function request_filter($query) {
767
+ //no need to handle non-lang
768
+ if (!$query['lang']) return $query;
769
+
770
+ // the trick is to replace the URI and put it back afterwards
771
+ $oldRequestUri = $_SERVER['REQUEST_URI'];
772
+ $_SERVER['REQUEST_URI'] = get_original_url($_SERVER['REQUEST_URI'],'', $query['lang'], array($this->database,'fetch_original'));
773
+ remove_filter('request', array(&$this,'request_filter'));
774
+ global $wp;
775
+ $wp->parse_request();
776
+ $query = $wp->query_vars;
777
+
778
+ $_SERVER['REQUEST_URI'] = $oldRequestUri;
779
+
780
+ return $query;
781
+ }
782
+
783
  }
784
 
785
  $my_transposh_plugin = new transposh_plugin();
wp/transposh_admin.php CHANGED
@@ -115,6 +115,7 @@ class transposh_plugin_admin {
115
  $this->transposh->options->set_enable_auto_post_translate($_POST[ENABLE_AUTO_POST_TRANSLATE]);
116
  $this->transposh->options->set_enable_default_translate($_POST[ENABLE_DEFAULT_TRANSLATE]);
117
  $this->transposh->options->set_enable_search_translate($_POST[ENABLE_SEARCH_TRANSLATE]);
 
118
  $this->transposh->options->set_enable_msn_translate($_POST[ENABLE_MSN_TRANSLATE]);
119
  $this->transposh->options->set_preferred_translator($_POST[PREFERRED_TRANSLATOR]);
120
  $this->transposh->options->set_msn_key($_POST[MSN_TRANSLATE_KEY]);
@@ -463,6 +464,15 @@ class transposh_plugin_admin {
463
  echo '<input type="checkbox" value="1" name="'.ENABLE_SEARCH_TRANSLATE.'" '.$this->checked ($this->transposh->options->get_enable_search_translate()).'/> '.
464
  'Allow search of translated languages, in those languages (and the original language)';
465
 
 
 
 
 
 
 
 
 
 
466
  }
467
 
468
  function on_contentbox_auto_translation_content($data) {
115
  $this->transposh->options->set_enable_auto_post_translate($_POST[ENABLE_AUTO_POST_TRANSLATE]);
116
  $this->transposh->options->set_enable_default_translate($_POST[ENABLE_DEFAULT_TRANSLATE]);
117
  $this->transposh->options->set_enable_search_translate($_POST[ENABLE_SEARCH_TRANSLATE]);
118
+ $this->transposh->options->set_enable_url_translate($_POST[ENABLE_URL_TRANSLATE]);
119
  $this->transposh->options->set_enable_msn_translate($_POST[ENABLE_MSN_TRANSLATE]);
120
  $this->transposh->options->set_preferred_translator($_POST[PREFERRED_TRANSLATOR]);
121
  $this->transposh->options->set_msn_key($_POST[MSN_TRANSLATE_KEY]);
464
  echo '<input type="checkbox" value="1" name="'.ENABLE_SEARCH_TRANSLATE.'" '.$this->checked ($this->transposh->options->get_enable_search_translate()).'/> '.
465
  'Allow search of translated languages, in those languages (and the original language)';
466
 
467
+ /**
468
+ * Insert the option to enable translation of urls
469
+ * Disbaled by default.
470
+ * @since 0.5.3
471
+ */
472
+ echo '<h4>Enable url translation (expirimental)</h4>';
473
+ echo '<input type="checkbox" value="1" name="'.ENABLE_URL_TRANSLATE.'" '.$this->checked ($this->transposh->options->get_enable_url_translate()).'/> '.
474
+ 'Allow translation of permalinks and urls';
475
+
476
  }
477
 
478
  function on_contentbox_auto_translation_content($data) {
wp/transposh_ajax.php CHANGED
@@ -31,9 +31,13 @@ if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') {
31
  }
32
 
33
  // we need wordpress and us...
34
- require_once('../../../../wp-load.php');
35
-
36
- // the case of posted translation
 
 
 
 
37
  if (isset($_POST['translation_posted'])) {
38
  // supercache invalidation of pages - first lets find if supercache is here
39
  if (function_exists('wp_super_cache_init')) {
@@ -42,6 +46,15 @@ if (isset($_POST['translation_posted'])) {
42
  $GLOBALS['wp_cache_request_uri'] = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', $GLOBALS['wp_cache_request_uri'] ) ) ) );
43
  // get some supercache variables
44
  extract(wp_super_cache_init());
 
 
 
 
 
 
 
 
 
45
  $dir = get_current_url_supercache_dir();
46
  // delete possible files that we can figure out, not deleting files for other cookies for example, but will do the trick in most cases
47
  $cache_fname = "{$dir}index.html";
@@ -52,6 +65,18 @@ if (isset($_POST['translation_posted'])) {
52
  @unlink( $cache_fname);
53
 
54
  @unlink($cache_file);
 
 
 
 
 
 
 
 
 
 
 
 
55
  }
56
 
57
  if ($_POST['translation_posted'] == 2) {
31
  }
32
 
33
  // we need wordpress and us...
34
+ //require_once('../../../../wp-load.php');
35
+ $root = $_SERVER["DOCUMENT_ROOT"];
36
+ $self = $_SERVER["SCRIPT_NAME"];
37
+ // go down 4 dirs...
38
+ for ($i = 0;$i<5;$i++) $self = substr($self,0,-strlen(strrchr($self,"/")));
39
+ require_once $root.$self.'/wp-load.php';
40
+ //the case of posted translation
41
  if (isset($_POST['translation_posted'])) {
42
  // supercache invalidation of pages - first lets find if supercache is here
43
  if (function_exists('wp_super_cache_init')) {
46
  $GLOBALS['wp_cache_request_uri'] = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', $GLOBALS['wp_cache_request_uri'] ) ) ) );
47
  // get some supercache variables
48
  extract(wp_super_cache_init());
49
+
50
+ // this is hackery for logged in users, a cookie is added to the request somehow and gzip is not correctly set, so we forcefully fix this
51
+ if (!$cache_file) {
52
+ $GLOBALS['wp_cache_gzip_encoding'] = gzip_accepted();
53
+ unset($_COOKIE[key($_COOKIE)]);
54
+ extract(wp_super_cache_init());
55
+
56
+ }
57
+
58
  $dir = get_current_url_supercache_dir();
59
  // delete possible files that we can figure out, not deleting files for other cookies for example, but will do the trick in most cases
60
  $cache_fname = "{$dir}index.html";
65
  @unlink( $cache_fname);
66
 
67
  @unlink($cache_file);
68
+
69
+ @unlink($meta_pathname);
70
+
71
+ // go at edit pages too
72
+ $GLOBALS['wp_cache_request_uri'] .="?edit=1";
73
+ extract(wp_super_cache_init());
74
+
75
+
76
+ @unlink($cache_file);
77
+
78
+ @unlink($meta_pathname);
79
+
80
  }
81
 
82
  if ($_POST['translation_posted'] == 2) {
wp/transposh_db.php CHANGED
@@ -46,6 +46,11 @@ class transposh_database {
46
  $this->transposh = &$transposh;
47
  }
48
 
 
 
 
 
 
49
  function prefetch_translations($originals, $lang) {
50
  if (!$originals) return;
51
  foreach ($originals as $original) {
@@ -69,6 +74,7 @@ class transposh_database {
69
  }
70
 
71
  }
 
72
  /**
73
  * Fetch translation from db or cache.
74
  * Returns An array that contains the translated string and it source.
@@ -127,6 +133,63 @@ class transposh_database {
127
  return $translated;
128
  }
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  /**
131
  * A new translation has been posted, update the translation database.
132
  * This has changed since we now accept multiple translations at once
46
  $this->transposh = &$transposh;
47
  }
48
 
49
+ /**
50
+ * Allow fetching of multiple translation requests from the database with a single query
51
+ * @param array $originals
52
+ * @param string $lang
53
+ */
54
  function prefetch_translations($originals, $lang) {
55
  if (!$originals) return;
56
  foreach ($originals as $original) {
74
  }
75
 
76
  }
77
+
78
  /**
79
  * Fetch translation from db or cache.
80
  * Returns An array that contains the translated string and it source.
133
  return $translated;
134
  }
135
 
136
+ /**
137
+ * Fetch original from db or cache.
138
+ * Returns the original for a given translation.
139
+ * Will return NULL if no translation is available.
140
+ * @param string $original
141
+ * @param string $lang
142
+ * @return array list(translation,source)
143
+ */
144
+ function fetch_original($translation, $lang) {
145
+ $original = NULL;
146
+
147
+
148
+ //The original is saved in db in its escaped form
149
+ $translation = $GLOBALS['wpdb']->escape(html_entity_decode($translation, ENT_NOQUOTES, 'UTF-8'));
150
+
151
+ if(ENABLE_APC && function_exists('apc_fetch')) {
152
+ $cached = apc_fetch($translation .'_r_r_'. $lang, $rc);
153
+ if($rc === TRUE) {
154
+
155
+ return $cached;
156
+ }
157
+ }
158
+
159
+ if ($this->translations[$translation]) {
160
+ $original = $this->translations[$translation];
161
+
162
+ } else {
163
+
164
+ $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
165
+ $query = "SELECT * FROM $table_name WHERE translated = '$translation' and lang = '$lang' ";
166
+ $row = $GLOBALS['wpdb']->get_row($query);
167
+
168
+ if($row !== FALSE) {
169
+ $original = stripslashes($row->original);
170
+ //$translated = array($translated_text, $row->source);
171
+
172
+ }
173
+ }
174
+
175
+ if(ENABLE_APC && function_exists('apc_store')) {
176
+ //If we don't have translation still we want to have it in cache
177
+ $cache_entry = $original;
178
+ if($cache_entry == NULL) {
179
+ $cache_entry = "";
180
+ }
181
+
182
+ //update cache
183
+ $rc = apc_store($translation .'_r_r_'. $lang, $cache_entry, 3600);
184
+ if($rc === TRUE) {
185
+
186
+ }
187
+ }
188
+
189
+
190
+ return $original;
191
+ }
192
+
193
  /**
194
  * A new translation has been posted, update the translation database.
195
  * This has changed since we now accept multiple translations at once
wp/transposh_options.php CHANGED
@@ -66,6 +66,8 @@ define("PREFERRED_TRANSLATOR", "preferred_translator");
66
  define("ENABLE_DEFAULT_TRANSLATE", "enable_default_translate");
67
  //Option to enable/disable default language translation @since 0.3.6
68
  define("ENABLE_SEARCH_TRANSLATE", "enable_search_translate");
 
 
69
  //Option to enable/disable rewrite of permalinks
70
  define("ENABLE_PERMALINKS", "enable_permalinks");
71
  //Option to enable/disable footer scripts (2.8 and up)
@@ -164,7 +166,7 @@ class transposh_plugin_options {
164
  /**
165
  * Get a user sorted language list
166
  * @since 0.3.9
167
- * @return array sorted list of languages, pointing to names and flags
168
  */
169
  function get_sorted_langs() {
170
  if (isset($this->options[SORTED_LANGS]))
@@ -217,6 +219,10 @@ class transposh_plugin_options {
217
  return $this->options[ENABLE_SEARCH_TRANSLATE];
218
  }
219
 
 
 
 
 
220
  function get_enable_auto_translate() {
221
  if (!isset($this->options[ENABLE_AUTO_TRANSLATE])) return 1; // default is true
222
  return $this->options[ENABLE_AUTO_TRANSLATE];
@@ -342,6 +348,11 @@ class transposh_plugin_options {
342
  $this->set_value($val, $this->options[ENABLE_SEARCH_TRANSLATE]);
343
  }
344
 
 
 
 
 
 
345
  function set_enable_auto_translate($val) {
346
  $val = ($val) ? 1 : 0;
347
  $this->set_value($val, $this->options[ENABLE_AUTO_TRANSLATE]);
66
  define("ENABLE_DEFAULT_TRANSLATE", "enable_default_translate");
67
  //Option to enable/disable default language translation @since 0.3.6
68
  define("ENABLE_SEARCH_TRANSLATE", "enable_search_translate");
69
+ //Option to enable/disable url translation @since 0.5.3
70
+ define("ENABLE_URL_TRANSLATE", "enable_url_translate");
71
  //Option to enable/disable rewrite of permalinks
72
  define("ENABLE_PERMALINKS", "enable_permalinks");
73
  //Option to enable/disable footer scripts (2.8 and up)
166
  /**
167
  * Get a user sorted language list
168
  * @since 0.3.9
169
+ * @return array sorted list of languages, pointing to names and flags
170
  */
171
  function get_sorted_langs() {
172
  if (isset($this->options[SORTED_LANGS]))
219
  return $this->options[ENABLE_SEARCH_TRANSLATE];
220
  }
221
 
222
+ function get_enable_url_translate() {
223
+ return $this->options[ENABLE_URL_TRANSLATE];
224
+ }
225
+
226
  function get_enable_auto_translate() {
227
  if (!isset($this->options[ENABLE_AUTO_TRANSLATE])) return 1; // default is true
228
  return $this->options[ENABLE_AUTO_TRANSLATE];
348
  $this->set_value($val, $this->options[ENABLE_SEARCH_TRANSLATE]);
349
  }
350
 
351
+ function set_enable_url_translate($val) {
352
+ $val = ($val) ? 1 : 0;
353
+ $this->set_value($val, $this->options[ENABLE_URL_TRANSLATE]);
354
+ }
355
+
356
  function set_enable_auto_translate($val) {
357
  $val = ($val) ? 1 : 0;
358
  $this->set_value($val, $this->options[ENABLE_AUTO_TRANSLATE]);
wp/transposh_postpublish.php CHANGED
@@ -48,7 +48,7 @@ class transposh_postpublish {
48
  * Admin menu created action, where we create our metaboxes
49
  */
50
  function on_admin_menu() {
51
- //add our metabox to the post and pubish pages
52
 
53
  add_meta_box( 'transposh_postpublish','Transposh', array(&$this, "transposh_postpublish_box"), 'post', 'side', 'core');
54
  add_meta_box( 'transposh_postpublish','Transposh', array(&$this, "transposh_postpublish_box"), 'page', 'side', 'core');
@@ -74,7 +74,7 @@ class transposh_postpublish {
74
  ));
75
  wp_enqueue_style("jquery","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css",array(),'1.0');
76
  wp_enqueue_script("jqueryui","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js",array("jquery"),'1.7.2',true);
77
- /* if ($this->transposh->options->get_enable_msn_translate() && $this->transposh->options->get_msn_key()) {
78
  wp_enqueue_script("mstranslate","http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId=".$this->transposh->options->get_msn_key(),array(),'1',true);
79
  }*/
80
  }
@@ -96,7 +96,7 @@ class transposh_postpublish {
96
  //$output = get_the_excerpt();
97
  // echo apply_filters('the_excerpt_rss', $output);
98
  //TODO - get comments text
99
-
100
  $parser = new parser();
101
  $phrases = $parser->get_phrases_list($content);
102
  $phrases2 = $parser->get_phrases_list($title);
@@ -104,6 +104,18 @@ class transposh_postpublish {
104
  // Merge the two arrays for traversing
105
  $phrases = array_merge($phrases, $phrases2);
106
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  foreach ($phrases as $key) {
108
  foreach (explode(',',$this->transposh->options->get_editable_langs()) as $lang) {
109
  // if this isn't the default language or we specifically allow default language translation, we will seek this out...
@@ -127,9 +139,9 @@ class transposh_postpublish {
127
  }
128
 
129
  // add the title
130
- // if ($json['length'])
131
- $json['posttitle'] = $title;
132
-
133
  // the header helps with debugging
134
  header("Content-type: text/javascript");
135
  echo json_encode($json);
48
  * Admin menu created action, where we create our metaboxes
49
  */
50
  function on_admin_menu() {
51
+ //add our metabox to the post and pubish pages
52
 
53
  add_meta_box( 'transposh_postpublish','Transposh', array(&$this, "transposh_postpublish_box"), 'post', 'side', 'core');
54
  add_meta_box( 'transposh_postpublish','Transposh', array(&$this, "transposh_postpublish_box"), 'page', 'side', 'core');
74
  ));
75
  wp_enqueue_style("jquery","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css",array(),'1.0');
76
  wp_enqueue_script("jqueryui","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js",array("jquery"),'1.7.2',true);
77
+ /* if ($this->transposh->options->get_enable_msn_translate() && $this->transposh->options->get_msn_key()) {
78
  wp_enqueue_script("mstranslate","http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId=".$this->transposh->options->get_msn_key(),array(),'1',true);
79
  }*/
80
  }
96
  //$output = get_the_excerpt();
97
  // echo apply_filters('the_excerpt_rss', $output);
98
  //TODO - get comments text
99
+
100
  $parser = new parser();
101
  $phrases = $parser->get_phrases_list($content);
102
  $phrases2 = $parser->get_phrases_list($title);
104
  // Merge the two arrays for traversing
105
  $phrases = array_merge($phrases, $phrases2);
106
 
107
+ // Add pharses from permalink
108
+ if ($this->transposh->options->get_enable_url_translate()) {
109
+ $permalink = get_permalink($postID);
110
+ $permalink = substr($permalink,strlen($this->transposh->home_url)+1);
111
+ $parts = explode('/', $permalink);
112
+ foreach ($parts as $part) {
113
+ if (!$part || is_numeric($part)) continue;
114
+ $part = str_replace('-', ' ',$part);
115
+ $phrases[] = $part;
116
+ }
117
+ }
118
+
119
  foreach ($phrases as $key) {
120
  foreach (explode(',',$this->transposh->options->get_editable_langs()) as $lang) {
121
  // if this isn't the default language or we specifically allow default language translation, we will seek this out...
139
  }
140
 
141
  // add the title
142
+ // if ($json['length'])
143
+ $json['posttitle'] = $title;
144
+
145
  // the header helps with debugging
146
  header("Content-type: text/javascript");
147
  echo json_encode($json);
wp/transposh_widget.php CHANGED
@@ -34,26 +34,36 @@ class transposh_plugin_widget {
34
  add_action('widgets_init', array(&$this,'transposh_widget_init'));
35
  }
36
 
37
- /*
38
- * Intercept init calls to see if it was posted by the widget.
39
- */
40
  function init_transposh() {
41
  if (isset ($_POST['transposh_widget_posted'])) {
42
 
43
- // FIX! yes, this is needed (not with peiorty!
44
  //transposh_plugin::init_global_vars();
45
  //$this->transposh->init_global_vars();
46
 
47
  $ref=getenv('HTTP_REFERER');
48
  $lang = $_POST[LANG_PARAM];
 
49
 
50
 
 
 
 
 
 
51
  //remove existing language settings.
52
  $ref = cleanup_url($ref,$this->transposh->home_url);
53
 
54
 
55
- if($lang != "none") {
56
- $ref = rewrite_url_lang_param($ref,$this->transposh->home_url,$this->transposh->enable_permalinks_rewrite, $lang, $_POST[EDIT_PARAM]);
 
 
 
 
57
 
58
 
59
  //ref is generated with html entities encoded, needs to be
@@ -100,7 +110,7 @@ class transposh_plugin_widget {
100
  wp_enqueue_style("transposh_widget", "{$this->transposh->transposh_plugin_url}/css/transposh_flags.css",array(),TRANSPOSH_PLUGIN_VER);
101
  if (file_exists("{$this->transposh->transposh_plugin_url}/css/transposh_flags_u.css"))
102
  wp_deregister_style("transposh_widget");
103
- wp_enqueue_style("transposh_widget", "{$this->transposh->transposh_plugin_url}/css/transposh_flags_u.css",array(),TRANSPOSH_PLUGIN_VER);
104
  }
105
  }
106
 
@@ -126,6 +136,9 @@ class transposh_plugin_widget {
126
 
127
  //remove any language identifier
128
  $clean_page_url = cleanup_url($page_url,$this->transposh->home_url, true);
 
 
 
129
 
130
 
131
  switch ($this->transposh->options->get_widget_style()) {
@@ -143,10 +156,14 @@ class transposh_plugin_widget {
143
  ($this->transposh->options->is_editable_language($code) && $this->transposh->is_translator()) ||
144
  ($this->transposh->options->is_default_language($code))) {
145
 
146
- $page_url = rewrite_url_lang_param($clean_page_url,$this->transposh->home_url,$this->transposh->enable_permalinks_rewrite, $code, $this->transposh->edit_mode);
147
- if ($this->transposh->options->is_default_language($code)) {
 
148
  $page_url = $clean_page_url;
149
  }
 
 
 
150
 
151
 
152
  if ($this->transposh->options->get_widget_in_list()) echo "<li>";
@@ -279,4 +296,5 @@ class transposh_plugin_widget {
279
  function transposh_widget($args = array()) {
280
  $GLOBALS['my_transposh_plugin']->widget->transposh_widget($args);
281
  }
 
282
  ?>
34
  add_action('widgets_init', array(&$this,'transposh_widget_init'));
35
  }
36
 
37
+ /**
38
+ * Intercept init calls to see if it was posted by the widget.
39
+ */
40
  function init_transposh() {
41
  if (isset ($_POST['transposh_widget_posted'])) {
42
 
43
+ // FIX! yes, this is needed (not with priorty!
44
  //transposh_plugin::init_global_vars();
45
  //$this->transposh->init_global_vars();
46
 
47
  $ref=getenv('HTTP_REFERER');
48
  $lang = $_POST[LANG_PARAM];
49
+ if ($lang == $this->transposh->options->get_default_language() || $lang == "none") $lang = "";
50
 
51
 
52
+ // first, we might need to get the original url back
53
+ if ($this->transposh->options->get_enable_url_translate()) {
54
+ $ref = get_original_url($ref,$this->transposh->home_url,get_language_from_url($ref,$this->transposh->home_url),array($this->transposh->database,'fetch_original'));
55
+ }
56
+
57
  //remove existing language settings.
58
  $ref = cleanup_url($ref,$this->transposh->home_url);
59
 
60
 
61
+ $ref = rewrite_url_lang_param($ref,$this->transposh->home_url,$this->transposh->enable_permalinks_rewrite, $lang, $_POST[EDIT_PARAM]);
62
+
63
+ if($lang && $this->transposh->options->get_enable_url_translate()) {
64
+ // and then, we might have to translate it
65
+ $ref = translate_url($ref, $this->transposh->home_url,$lang,array(&$this->transposh->database,'fetch_translation'));
66
+ $ref = str_replace(array('%2F','%3A','%3B','%3F','%3D','%26'),array('/',':',';','?','=','&'),urlencode($ref));
67
 
68
 
69
  //ref is generated with html entities encoded, needs to be
110
  wp_enqueue_style("transposh_widget", "{$this->transposh->transposh_plugin_url}/css/transposh_flags.css",array(),TRANSPOSH_PLUGIN_VER);
111
  if (file_exists("{$this->transposh->transposh_plugin_url}/css/transposh_flags_u.css"))
112
  wp_deregister_style("transposh_widget");
113
+ wp_enqueue_style("transposh_widget", "{$this->transposh->transposh_plugin_url}/css/transposh_flags_u.css",array(),TRANSPOSH_PLUGIN_VER);
114
  }
115
  }
116
 
136
 
137
  //remove any language identifier
138
  $clean_page_url = cleanup_url($page_url,$this->transposh->home_url, true);
139
+ if ($this->transposh->options->get_enable_url_translate()) {
140
+ $clean_page_url = get_original_url($clean_page_url,'',$this->transposh->target_language,array($this->transposh->database,'fetch_original'));
141
+ }
142
 
143
 
144
  switch ($this->transposh->options->get_widget_style()) {
156
  ($this->transposh->options->is_editable_language($code) && $this->transposh->is_translator()) ||
157
  ($this->transposh->options->is_default_language($code))) {
158
 
159
+ if ($this->transposh->options->get_enable_url_translate()) {
160
+ $page_url = translate_url($clean_page_url, '',$code,array(&$this->transposh->database,'fetch_translation'));
161
+ } else {
162
  $page_url = $clean_page_url;
163
  }
164
+ // clean $code in default lanaguge
165
+ if ($code == $this->transposh->options->get_default_language()) $code = "";
166
+ $page_url = rewrite_url_lang_param($page_url,$this->transposh->home_url,$this->transposh->enable_permalinks_rewrite, $code, $this->transposh->edit_mode);
167
 
168
 
169
  if ($this->transposh->options->get_widget_in_list()) echo "<li>";
296
  function transposh_widget($args = array()) {
297
  $GLOBALS['my_transposh_plugin']->widget->transposh_widget($args);
298
  }
299
+
300
  ?>