Transposh WordPress Translation - Version 0.2.5

Version Description

Download this release

Release Info

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

Code changes from version 0.2.4 to 0.2.5

core/globals.php CHANGED
@@ -27,9 +27,6 @@
27
  //Home (root) url of the site/blog under which translation will take place.
28
  $home_url;
29
 
30
- //Home url of the blog - already quoted and ready for regex
31
- $home_url_quoted;
32
-
33
  //The url pointing to the base of the plugin. Used for generating urls to resources
34
  $tr_plugin_url;
35
 
27
  //Home (root) url of the site/blog under which translation will take place.
28
  $home_url;
29
 
 
 
 
30
  //The url pointing to the base of the plugin. Used for generating urls to resources
31
  $tr_plugin_url;
32
 
core/parser.php CHANGED
@@ -31,6 +31,7 @@ class parser {
31
  public $dir_rtl;
32
  public $lang;
33
  private $inbody = false;
 
34
  public $is_edit_mode;
35
  public $is_auto_translate;
36
  public $feed_fix;
@@ -207,6 +208,8 @@ class parser {
207
  $node->phrase = $phrase;
208
  if ($this->inbody)
209
  $node->inbody = $this->inbody;
 
 
210
  }
211
  }
212
 
@@ -261,12 +264,16 @@ class parser {
261
  * it currently also rewrites urls, and should consider if this is smart
262
  * @param <type> $node
263
  */
264
- function translate_tagging($node) {
265
  $this->currentnode = $node;
266
  // we don't want to translate non-translatable classes
267
  if (stripos($node->class,NO_TRANSLATE_CLASS) !== false) return;
 
 
 
 
268
  if (isset($this->ignore_tags[$node->tag])) return;
269
- elseif ($node->tag == 'text') {
270
  // this prevents translation of a link that just surrounds its address
271
  if ($node->parent->tag == 'a' && $node->parent->href == $node->outertext) {
272
  return;
@@ -291,6 +298,9 @@ class parser {
291
  elseif ($node->tag == 'body') {
292
  $this->inbody = true;
293
  }
 
 
 
294
 
295
  // titles are also good places to translate, exist in a, img, abbr, acronym
296
  if ($node->title) $this->parsetext($node->title);
@@ -300,7 +310,7 @@ class parser {
300
 
301
  // recurse
302
  foreach($node->nodes as $c) {
303
- $this->translate_tagging($c);
304
  }
305
  }
306
 
@@ -362,10 +372,16 @@ class parser {
362
  $newtext = '';
363
  foreach ($e->nodes as $ep) {
364
  list ($translated_text, $source) = call_user_func_array($this->fetch_translate_func,array($ep->phrase, $this->lang));
365
- if (($this->is_edit_mode || ($this->is_auto_translate && $translated_text == null)) && $ep->inbody) {
366
  $span = $this->create_edit_span($ep->phrase, $translated_text, $source);
367
  $spanend = "</span>";
368
- if ($translated_text == null) $translated_text = $ep->phrase;
 
 
 
 
 
 
369
  } else {
370
  $span = '';
371
  $spanend = '';
@@ -385,6 +401,12 @@ class parser {
385
  $e->outertext = $newtext.$right;
386
 
387
  }
 
 
 
 
 
 
388
  }
389
 
390
  // now we handle the title attributes
31
  public $dir_rtl;
32
  public $lang;
33
  private $inbody = false;
34
+ private $inselect;
35
  public $is_edit_mode;
36
  public $is_auto_translate;
37
  public $feed_fix;
208
  $node->phrase = $phrase;
209
  if ($this->inbody)
210
  $node->inbody = $this->inbody;
211
+ if ($this->inselect)
212
+ $node->inselect = true;
213
  }
214
  }
215
 
264
  * it currently also rewrites urls, and should consider if this is smart
265
  * @param <type> $node
266
  */
267
+ function translate_tagging($node, $level = 0) {
268
  $this->currentnode = $node;
269
  // we don't want to translate non-translatable classes
270
  if (stripos($node->class,NO_TRANSLATE_CLASS) !== false) return;
271
+
272
+ if (!($this->inselect && $level > $this->inselect))
273
+ $this->inselect = false;
274
+
275
  if (isset($this->ignore_tags[$node->tag])) return;
276
+ if ($node->tag == 'text') {
277
  // this prevents translation of a link that just surrounds its address
278
  if ($node->parent->tag == 'a' && $node->parent->href == $node->outertext) {
279
  return;
298
  elseif ($node->tag == 'body') {
299
  $this->inbody = true;
300
  }
301
+ elseif ($node->tag == 'select') {
302
+ $this->inselect = $level;
303
+ }
304
 
305
  // titles are also good places to translate, exist in a, img, abbr, acronym
306
  if ($node->title) $this->parsetext($node->title);
310
 
311
  // recurse
312
  foreach($node->nodes as $c) {
313
+ $this->translate_tagging($c, $level +1);
314
  }
315
  }
316
 
372
  $newtext = '';
373
  foreach ($e->nodes as $ep) {
374
  list ($translated_text, $source) = call_user_func_array($this->fetch_translate_func,array($ep->phrase, $this->lang));
375
+ if (($this->is_edit_mode || ($this->is_auto_translate && $translated_text == null))/* && $ep->inbody*/) {
376
  $span = $this->create_edit_span($ep->phrase, $translated_text, $source);
377
  $spanend = "</span>";
378
+ if ($ep->inselect || !$ep->inbody) {
379
+ $savedspan .= $this->create_edit_span($ep->phrase, $translated_text, $source,true).$spanend;
380
+ $span = '';
381
+ $spanend = '';
382
+ }
383
+ else
384
+ if ($translated_text == null) $translated_text = $ep->phrase;
385
  } else {
386
  $span = '';
387
  $spanend = '';
401
  $e->outertext = $newtext.$right;
402
 
403
  }
404
+ // hmm?
405
+ if (!$ep->inselect && $savedspan && $ep->inbody) {
406
+ $e->outertext = $savedspan.$e->outertext;
407
+ $savedspan = "";
408
+ }
409
+
410
  }
411
 
412
  // now we handle the title attributes
core/utils.php CHANGED
@@ -26,67 +26,146 @@ require_once("constants.php");
26
 
27
 
28
  /*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  * Update the given url to include language params.
30
- * param url - the original url to rewrite (expects full urls)
31
- * param lang - language code
32
- * param is_edit - is running in edit mode.
33
- * param use_params_only - use only parameters as modifiers, i.e. not permalinks
34
  */
35
  function rewrite_url_lang_param($url, $lang, $is_edit, $use_params_only=FALSE) {
36
- global $home_url, $home_url_quoted, $enable_permalinks_rewrite;
37
-
38
- //
39
- //
40
- //
41
-
42
- $url = html_entity_decode($url, ENT_NOQUOTES);
43
- $url = str_replace('&#038;', '&', $url);
44
-
45
 
46
- //remove prev lang and edit params?
47
- $url = preg_replace("/(" . LANG_PARAM . "|" . EDIT_PARAM . ")=[^&]*/i", "", $url);
48
 
49
- if(!$enable_permalinks_rewrite) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  //override the use only params - admin configured system to not touch permalinks
 
51
  $use_params_only = TRUE;
52
  }
53
 
54
- $params ="";
55
  if($is_edit) {
56
- $params = EDIT_PARAM . '=1&';
57
  }
58
 
59
  if($use_params_only) {
60
- $params .= LANG_PARAM . "=$lang&";
61
  }
62
  else {
63
- $url = preg_replace("/$home_url_quoted\/(..(-..)?\/)?\/?/",
64
- "$home_url/$lang/", $url);
65
  }
66
 
67
 
68
- if($params) {
69
  //insert params to url
70
- $url = preg_replace("/(.+\/[^\?\#]*[\?]?)/", '$1?' . $params, $url);
71
-
72
-
73
- //Cleanup extra &
74
- $url = preg_replace("/&&+/", "&", $url);
75
-
76
- //Cleanup extra ?
77
- $url = preg_replace("/\?\?+/", "?", $url);
78
  }
79
 
80
  // more cleanups
81
- $url = preg_replace("/&$/", "", $url);
82
- $url = preg_replace("/\?$/", "", $url);
83
 
84
- $url = htmlentities($url, ENT_NOQUOTES);
 
85
 
86
  return $url;
87
  }
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
 
 
 
 
 
 
 
 
 
 
90
  /**
91
  * Encode a string as base 64 while avoiding characters which should be avoided
92
  * in uri, e.g. + is interpeted as a space.
26
 
27
 
28
  /*
29
+ * Remove from url any language (or editing) params that were added for our use.
30
+ * Return the scrubed url
31
+ */
32
+ function cleanup_url($url, $remove_host = false) {
33
+ $parsedurl = parse_url($url);
34
+ //cleanup previous lang & edit parameter from url
35
+
36
+ if ($parsedurl['query']) {
37
+ $params = explode('&',$parsedurl['query']);
38
+ foreach ($params as $key => $param) {
39
+ if (stripos($param,LANG_PARAM) === 0) unset ($params[$key]);
40
+ if (stripos($param,EDIT_PARAM) === 0) unset ($params[$key]);
41
+ }
42
+ }
43
+ // clean the query
44
+ unset($parsedurl['query']);
45
+ if($params) {
46
+ $parsedurl['query'] = implode('&',$params);
47
+ }
48
+
49
+ //cleanup lang identifier in permalinks
50
+ //remove the language from the url permalink (if in start of path, and is a defined language)
51
+ if (strlen($parsedurl['path']) > 2) {
52
+ $secondslashpos = strpos($parsedurl['path'], "/",1);
53
+ if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']);
54
+ $prevlang = substr($parsedurl['path'],1,$secondslashpos-1);
55
+ if (isset ($languages[$prevlang])) {
56
+
57
+ $parsedurl['path'] = substr($parsedurl['path'],$secondslashpos);
58
+ }
59
+ }
60
+ if ($remove_host) {
61
+ unset ($parsedurl[scheme]);
62
+ unset ($parsedurl[host]);
63
+ }
64
+ $url = glue_url($parsedurl);
65
+ return $url;
66
+ }
67
+
68
+ /**
69
  * Update the given url to include language params.
70
+ * @param string $url - Original URL to rewrite
71
+ * @param string $lang - Target language code
72
+ * @param boolean $is_edit - should url indicate editing
73
+ * @param boolean $use_params_only - only use paramaters and avoid permalinks
74
  */
75
  function rewrite_url_lang_param($url, $lang, $is_edit, $use_params_only=FALSE) {
76
+ global $home_url, $enable_permalinks_rewrite, $languages;
 
 
 
 
 
 
 
 
77
 
 
 
78
 
79
+ $newurl = str_replace('&#038;', '&', $url);
80
+ $newurl = html_entity_decode($newurl, ENT_NOQUOTES);
81
+ $parsedurl = parse_url($newurl);
82
+
83
+ // if we are dealing with some other url, we won't touch it!
84
+ if ($parsedurl['host'] && !($parsedurl['host'] == parse_url($home_url,PHP_URL_HOST))) {
85
+ return $url;
86
+ }
87
+
88
+ //remove prev lang and edit params - from query string - reserve other params
89
+ if ($parsedurl['query']) {
90
+ $params = explode('&',$parsedurl['query']);
91
+ foreach ($params as $key => $param) {
92
+ if (stripos($param,LANG_PARAM) === 0) unset ($params[$key]);
93
+ if (stripos($param,EDIT_PARAM) === 0) unset ($params[$key]);
94
+ }
95
+ }
96
+ // clean the query
97
+ unset($parsedurl['query']);
98
+
99
+ //remove the language from the url permalink (if in start of path, and is a defined language)
100
+ if (strlen($parsedurl['path']) > 2) {
101
+ $secondslashpos = strpos($parsedurl['path'], "/",1);
102
+ if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']);
103
+ $prevlang = substr($parsedurl['path'],1,$secondslashpos-1);
104
+ if (isset ($languages[$prevlang])) {
105
+
106
+ $parsedurl['path'] = substr($parsedurl['path'],$secondslashpos);
107
+ }
108
+ }
109
+
110
  //override the use only params - admin configured system to not touch permalinks
111
+ if(!$enable_permalinks_rewrite) {
112
  $use_params_only = TRUE;
113
  }
114
 
115
+ //$params ="";
116
  if($is_edit) {
117
+ $params[edit] = EDIT_PARAM . '=1';
118
  }
119
 
120
  if($use_params_only) {
121
+ $params[lang] = LANG_PARAM . "=$lang";
122
  }
123
  else {
124
+ if (!$parsedurl['path']) $parsedurl['path'] = "/";
125
+ $parsedurl['path'] = "/".$lang.$parsedurl['path'];
126
  }
127
 
128
 
 
129
  //insert params to url
130
+ if($params) {
131
+ $parsedurl['query'] = implode('&',$params);
 
 
 
 
 
 
132
  }
133
 
134
  // more cleanups
135
+ //$url = preg_replace("/&$/", "", $url);
136
+ //$url = preg_replace("/\?$/", "", $url);
137
 
138
+ // $url = htmlentities($url, ENT_NOQUOTES);
139
+ $url = glue_url($parsedurl);
140
 
141
  return $url;
142
  }
143
 
144
+ /**
145
+ *
146
+ * @param <type> $parsed
147
+ * @return <type>
148
+ */
149
+ function glue_url($parsed) {
150
+ if (!is_array($parsed)) {
151
+ return false;
152
+ }
153
+
154
+ $uri = isset($parsed['scheme']) ? $parsed['scheme'].':'.((strtolower($parsed['scheme']) == 'mailto') ? '' : '//') : '';
155
+ $uri .= isset($parsed['user']) ? $parsed['user'].(isset($parsed['pass']) ? ':'.$parsed['pass'] : '').'@' : '';
156
+ $uri .= isset($parsed['host']) ? $parsed['host'] : '';
157
+ $uri .= isset($parsed['port']) ? ':'.$parsed['port'] : '';
158
 
159
+ if (isset($parsed['path'])) {
160
+ $uri .= (substr($parsed['path'], 0, 1) == '/') ?
161
+ $parsed['path'] : ((!empty($uri) ? '/' : '' ) . $parsed['path']);
162
+ }
163
+
164
+ $uri .= isset($parsed['query']) ? '?'.$parsed['query'] : '';
165
+ $uri .= isset($parsed['fragment']) ? '#'.$parsed['fragment'] : '';
166
+
167
+ return $uri;
168
+ }
169
  /**
170
  * Encode a string as base 64 while avoiding characters which should be avoided
171
  * in uri, e.g. + is interpeted as a space.
js/transposh.js CHANGED
@@ -1 +1 @@
1
- function getgt(){jQuery(":button:contains('Suggest - Google')").attr("disabled","disabled").addClass("ui-state-disabled");google.language.translate(jQuery("#"+transposh_params.prefix+"original").val(),"",transposh_params.lang,function(a){if(!a.error){jQuery("#"+transposh_params.prefix+"translation").val(jQuery("<div>"+a.translation+"</div>").text()).keyup()}})}var done_p=0;var togo=0;function ajax_translate(c,b,a){jQuery.ajax({type:"POST",url:transposh_params.post_url,data:{token:jQuery("#"+transposh_params.prefix+a).attr("token"),translation:c,lang:transposh_params.lang,source:b,translation_posted:"1"},success:function(e){fix_page(c,b,a);if(transposh_params.progress){var d=jQuery("#"+transposh_params.prefix+a).attr("token");done_p+=jQuery("*[token='"+d+"']").size();if(togo>4){jQuery("#progress_bar2").progressbar("value",done_p/togo*100)}}},error:function(d){if(b==0){alert("Error !!! failed to translate.\n\nServer's message: "+d.statusText)}}})}function fix_page(e,d,c){var b=jQuery("#"+transposh_params.prefix+c).attr("token");var a=e;if(jQuery.trim(e).length===0){a=jQuery("#"+transposh_params.prefix+c).attr("orig")}jQuery("*[token='"+b+"'][hidden!='y']").html(a).each(function(g){var h=jQuery(this).attr("id").substr(jQuery(this).attr("id").lastIndexOf("_")+1);jQuery("#"+transposh_params.prefix+h).attr("source",d);var f=jQuery("#"+transposh_params.prefix+"img_"+h);f.removeClass("tr-icon-yellow").removeClass("tr-icon-green");if(jQuery.trim(e).length!==0){if(d==1){f.addClass("tr-icon-yellow")}else{f.addClass("tr-icon-green")}}});jQuery("*[token='"+b+"'][hidden='y']").attr("trans",a).each(function(g){var h=jQuery(this).attr("id").substr(jQuery(this).attr("id").lastIndexOf("_")+1);jQuery("#"+transposh_params.prefix+h).attr("source",d);var f=jQuery("#"+transposh_params.prefix+"img_"+h);f.removeClass("tr-icon-yellow").removeClass("tr-icon-green");if(jQuery.trim(e).length!==0){if(d==1){f.addClass("tr-icon-yellow")}else{f.addClass("tr-icon-green")}}})}function do_auto_translate(){if(transposh_params.progress){togo=jQuery("."+transposh_params.prefix+'[source=""]').size();if(togo>4){jQuery("#"+transposh_params.prefix+"credit").append('<div style="float: left;width: 90%;height: 10px" id="progress_bar"/><div style="margin-bottom:10px;float:left;width: 90%;height: 10px" id="progress_bar2"/>');jQuery("#progress_bar").progressbar({value:0});jQuery("#progress_bar2").progressbar({value:0});jQuery("#progress_bar2 > div").css({background:"#28F828",border:"#08A908 1px solid"})}var a=0}var b=new Array();jQuery("."+transposh_params.prefix+'[source=""]').each(function(d){var c=jQuery(this).attr("id");var e=jQuery(this).attr("orig");if(e==undefined){e=jQuery(this).html()}if(!(b[e]==1)){b[e]=1;google.language.translate(e,"",transposh_params.lang,function(f){if(!f.error){var g=c.substr(c.lastIndexOf("_")+1);fix_page(jQuery("<div>"+f.translation+"</div>").text(),1,g);ajax_translate(jQuery("<div>"+f.translation+"</div>").text(),1,g);if(transposh_params.progress){a=togo-jQuery("."+transposh_params.prefix+'[source=""]').size();if(togo>4){jQuery("#progress_bar").progressbar("value",a/togo*100)}}}})}})}function confirm_close(){jQuery('<div id="dial" title="Close without saving?"><p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>You have made a change to the translation. Are you sure you want to discard it?</p></div>').appendTo("body").dialog({bgiframe:true,resizable:false,height:140,modal:true,overlay:{backgroundColor:"#000",opacity:0.5},buttons:{Discard:function(){jQuery("#"+transposh_params.prefix+"translation").data("edit",{changed:false});jQuery(this).dialog("close");jQuery("#"+transposh_params.prefix+"d-tabs").dialog("close")},Cancel:function(){jQuery(this).dialog("close")}}})}function translate_dialog(b){jQuery("#"+transposh_params.prefix+"d-tabs").remove();jQuery('<div id="'+transposh_params.prefix+'d-tabs" title="Edit Translation"/>').appendTo("body");jQuery("#"+transposh_params.prefix+"d-tabs").append("<ul/>").tabs({cache:true}).tabs("add","#"+transposh_params.prefix+"d-tabs-1","Translate").tabs("add",transposh_params.post_url+"?tr_token_hist="+jQuery("#"+transposh_params.prefix+b).attr("token")+"&lang="+transposh_params.lang,"History").css("text-align","left").css("padding",0).bind("tabsload",function(d,e){jQuery("table",e.panel).addClass("ui-widget ui-widget-content").css({width:"95%",padding:"0"});jQuery("table thead tr",e.panel).addClass("ui-widget-header");jQuery("table tbody td[source='1']",e.panel).append('<img size="16x16" src="'+transposh_params.post_url+'?tp_gif=y" title="computer" style="display: inline; margin-right: 0.3em;" class="ui-icon ui-icon-gear"/>');jQuery("table tbody td[source='0']",e.panel).append('<img size="16x16" src="'+transposh_params.post_url+'?tp_gif=y" title="human" style="display: inline; margin-right: 0.3em;" class="ui-icon ui-icon-person"/>')}).bind("tabsselect",function(d,e){if(jQuery(e.tab).text()=="Translate"){jQuery("#"+transposh_params.prefix+"d-tabs").dialog("option","buttons",a)}else{jQuery("#"+transposh_params.prefix+"d-tabs").dialog("option","buttons",c)}}).bind("dialogbeforeclose",function(d,e){if(jQuery("#"+transposh_params.prefix+"translation").data("edit").changed){confirm_close();return false}return true});jQuery("#"+transposh_params.prefix+"d-tabs li").css("list-style-type","none").css("list-style-position","outside");jQuery("#"+transposh_params.prefix+"d-tabs-1").append('<form id="'+transposh_params.prefix+'form"><fieldset><label for="original">Original Text</label><textarea cols="80" row="3" name="original" id="'+transposh_params.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="'+transposh_params.prefix+'translation" value="" class="text ui-widget-content ui-corner-all"/></fieldset></form>');jQuery("#"+transposh_params.prefix+"d-tabs-1 label").css("display","block");jQuery("#"+transposh_params.prefix+"d-tabs-1 textarea.text").css({"margin-bottom":"12px",width:"95%",padding:".4em"});jQuery("#"+transposh_params.prefix+"original").val(jQuery("#"+transposh_params.prefix+b).attr("orig"));jQuery("#"+transposh_params.prefix+"translation").val(jQuery("#"+transposh_params.prefix+b).html());if(jQuery("#"+transposh_params.prefix+b).attr("trans")){jQuery("#"+transposh_params.prefix+"translation").val(jQuery("#"+transposh_params.prefix+b).attr("trans"))}jQuery("#"+transposh_params.prefix+"translation").data("edit",{changed:false});jQuery("#"+transposh_params.prefix+"translation").keyup(function(d){if(jQuery("#"+transposh_params.prefix+b).text()!=jQuery(this).val()){jQuery(this).css("background","yellow");jQuery(this).data("edit",{changed:true})}else{jQuery(this).css("background","");jQuery(this).data("edit",{changed:false})}});var a;if(google.language.isTranslatable(transposh_params.lang)||"he|zh-tw|pt".indexOf(transposh_params.lang)>-1){a={"Suggest - Google":function(){getgt()},Ok:function(){var d=jQuery("#"+transposh_params.prefix+"translation").val();if(jQuery("#"+transposh_params.prefix+"translation").data("edit").changed){ajax_translate(d,0,b);jQuery("#"+transposh_params.prefix+"translation").data("edit",{changed:false})}jQuery(this).dialog("close")}}}else{a={Ok:function(){var d=jQuery("#"+transposh_params.prefix+"translation").val();if(jQuery("#"+transposh_params.prefix+"translation").data("edit").changed){ajax_translate(d,0,b);jQuery("#"+transposh_params.prefix+"translation").data("edit",{changed:false})}jQuery(this).dialog("close")}}}var c={Close:function(){jQuery(this).dialog("close")}};jQuery("#"+transposh_params.prefix+"d-tabs").dialog({bgiframe:true,modal:true,width:500,buttons:a})}jQuery.noConflict();var transposh_params=new Array();jQuery("script[src*='transposh.js']").each(function(a){var e=unescape(this.src.substring(this.src.indexOf("?")+1));var d=e.split("&");for(var c=0;c<d.length;c++){var g=d[c].indexOf("=");if(g>0){var b=d[c].substring(0,g);var f=d[c].substring(g+1);transposh_params[b]=f}}});google.load("language","1");jQuery(document).ready(function(){if(typeof(jQuery().progressbar)!="undefined"){transposh_params.progress=true}if(google.language.isTranslatable(transposh_params.lang)||"he|zh-tw|pt".indexOf(transposh_params.lang)>-1){do_auto_translate()}if(transposh_params.edit){jQuery("."+transposh_params.prefix).each(function(c){var a=jQuery(this).attr("id").substr(jQuery(this).attr("id").lastIndexOf("_")+1);jQuery(this).after('<img id="'+transposh_params.prefix+"img_"+a+'" class="tr-icon" size="12x12" title="'+jQuery(this).attr("orig")+'" src="'+transposh_params.post_url+'?tp_gif=y"/>');var b=jQuery("#"+transposh_params.prefix+"img_"+a);b.click(function(){translate_dialog(a);return false}).css({border:"0px",margin:"1px",padding:"0px"});if(jQuery(this).attr("source")=="1"){b.addClass("tr-icon-yellow")}else{if(jQuery(this).attr("source")=="0"){b.addClass("tr-icon-green")}}if(jQuery(this).attr("hidden")=="y"){b.css({opacity:"0.6"})}})}});
1
+ function getgt(){jQuery(":button:contains('Suggest - Google')").attr("disabled","disabled").addClass("ui-state-disabled");google.language.translate(jQuery("#"+transposh_params.prefix+"original").val(),"",transposh_params.lang,function(a){if(!a.error){jQuery("#"+transposh_params.prefix+"translation").val(jQuery("<div>"+a.translation+"</div>").text()).keyup()}})}var done_p=0;var togo=0;function ajax_translate(c,b,a){jQuery.ajax({type:"POST",url:transposh_params.post_url,data:{token:jQuery("#"+transposh_params.prefix+a).attr("token"),translation:c,lang:transposh_params.lang,source:b,translation_posted:"1"},success:function(e){fix_page(c,b,a);if(transposh_params.progress){var d=jQuery("#"+transposh_params.prefix+a).attr("token");done_p+=jQuery("*[token='"+d+"']").size();if(togo>4){jQuery("#progress_bar2").progressbar("value",done_p/togo*100)}}},error:function(d){if(b==0){alert("Error !!! failed to translate.\n\nServer's message: "+d.statusText)}}})}function fix_page(e,d,c){var b=jQuery("#"+transposh_params.prefix+c).attr("token");var a=e;if(jQuery.trim(e).length===0){a=jQuery("#"+transposh_params.prefix+c).attr("orig")}jQuery("*[token='"+b+"'][hidden!='y']").html(a).each(function(g){var h=jQuery(this).attr("id").substr(jQuery(this).attr("id").lastIndexOf("_")+1);jQuery("#"+transposh_params.prefix+h).attr("source",d);var f=jQuery("#"+transposh_params.prefix+"img_"+h);f.removeClass("tr-icon-yellow").removeClass("tr-icon-green");if(jQuery.trim(e).length!==0){if(d==1){f.addClass("tr-icon-yellow")}else{f.addClass("tr-icon-green")}}});jQuery("*[token='"+b+"'][hidden='y']").attr("trans",a).each(function(g){var h=jQuery(this).attr("id").substr(jQuery(this).attr("id").lastIndexOf("_")+1);jQuery("#"+transposh_params.prefix+h).attr("source",d);var f=jQuery("#"+transposh_params.prefix+"img_"+h);f.removeClass("tr-icon-yellow").removeClass("tr-icon-green");if(jQuery.trim(e).length!==0){if(d==1){f.addClass("tr-icon-yellow")}else{f.addClass("tr-icon-green")}}})}function do_auto_translate(){if(transposh_params.progress){togo=jQuery("."+transposh_params.prefix+'[source=""]').size();if(togo>4){jQuery("#"+transposh_params.prefix+"credit").append('<div style="float: left;width: 90%;height: 10px" id="progress_bar"/><div style="margin-bottom:10px;float:left;width: 90%;height: 10px" id="progress_bar2"/>');jQuery("#progress_bar").progressbar({value:0});jQuery("#progress_bar2").progressbar({value:0});jQuery("#progress_bar2 > div").css({background:"#28F828",border:"#08A908 1px solid"})}var a=0}var b=new Array();jQuery("."+transposh_params.prefix+'[source=""]').each(function(d){var c=jQuery(this).attr("id");var e=jQuery(this).attr("orig");if(e==undefined){e=jQuery(this).html()}if(!(b[e]==1)){b[e]=1;google.language.translate(e,"",transposh_params.lang,function(f){if(!f.error){var g=c.substr(c.lastIndexOf("_")+1);fix_page(jQuery("<div>"+f.translation+"</div>").text(),1,g);ajax_translate(jQuery("<div>"+f.translation+"</div>").text(),1,g);if(transposh_params.progress){a=togo-jQuery("."+transposh_params.prefix+'[source=""]').size();if(togo>4){jQuery("#progress_bar").progressbar("value",a/togo*100)}}}})}})}function confirm_close(){jQuery('<div id="dial" title="Close without saving?"><p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>You have made a change to the translation. Are you sure you want to discard it?</p></div>').appendTo("body").dialog({bgiframe:true,resizable:false,height:140,modal:true,overlay:{backgroundColor:"#000",opacity:0.5},buttons:{Discard:function(){jQuery("#"+transposh_params.prefix+"translation").data("edit",{changed:false});jQuery(this).dialog("close");jQuery("#"+transposh_params.prefix+"d-tabs").dialog("close")},Cancel:function(){jQuery(this).dialog("close")}}})}function translate_dialog(b){jQuery("#"+transposh_params.prefix+"d-tabs").remove();jQuery('<div id="'+transposh_params.prefix+'d-tabs" title="Edit Translation"/>').appendTo("body");jQuery("#"+transposh_params.prefix+"d-tabs").append("<ul/>").tabs({cache:true}).tabs("add","#"+transposh_params.prefix+"d-tabs-1","Translate").tabs("add",transposh_params.post_url+"?tr_token_hist="+jQuery("#"+transposh_params.prefix+b).attr("token")+"&lang="+transposh_params.lang,"History").css("text-align","left").css("padding",0).bind("tabsload",function(d,e){jQuery("table",e.panel).addClass("ui-widget ui-widget-content").css({width:"95%",padding:"0"});jQuery("table thead tr",e.panel).addClass("ui-widget-header");jQuery("table tbody td[source='1']",e.panel).append('<img size="16x16" src="'+transposh_params.blank+'" title="computer" style="display: inline; margin-right: 0.3em;" class="ui-icon ui-icon-gear"/>');jQuery("table tbody td[source='0']",e.panel).append('<img size="16x16" src="'+transposh_params.blank+'" title="human" style="display: inline; margin-right: 0.3em;" class="ui-icon ui-icon-person"/>')}).bind("tabsselect",function(d,e){if(jQuery(e.tab).text()=="Translate"){jQuery("#"+transposh_params.prefix+"d-tabs").dialog("option","buttons",a)}else{jQuery("#"+transposh_params.prefix+"d-tabs").dialog("option","buttons",c)}}).bind("dialogbeforeclose",function(d,e){if(jQuery("#"+transposh_params.prefix+"translation").data("edit").changed){confirm_close();return false}return true});jQuery("#"+transposh_params.prefix+"d-tabs li").css("list-style-type","none").css("list-style-position","outside");jQuery("#"+transposh_params.prefix+"d-tabs-1").append('<form id="'+transposh_params.prefix+'form"><fieldset><label for="original">Original Text</label><textarea cols="80" row="3" name="original" id="'+transposh_params.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="'+transposh_params.prefix+'translation" value="" class="text ui-widget-content ui-corner-all"/></fieldset></form>');jQuery("#"+transposh_params.prefix+"d-tabs-1 label").css("display","block");jQuery("#"+transposh_params.prefix+"d-tabs-1 textarea.text").css({"margin-bottom":"12px",width:"95%",padding:".4em"});jQuery("#"+transposh_params.prefix+"original").val(jQuery("#"+transposh_params.prefix+b).attr("orig"));jQuery("#"+transposh_params.prefix+"translation").val(jQuery("#"+transposh_params.prefix+b).html());if(jQuery("#"+transposh_params.prefix+b).attr("trans")){jQuery("#"+transposh_params.prefix+"translation").val(jQuery("#"+transposh_params.prefix+b).attr("trans"))}jQuery("#"+transposh_params.prefix+"translation").data("edit",{changed:false});jQuery("#"+transposh_params.prefix+"translation").keyup(function(d){if(jQuery("#"+transposh_params.prefix+b).text()!=jQuery(this).val()){jQuery(this).css("background","yellow");jQuery(this).data("edit",{changed:true})}else{jQuery(this).css("background","");jQuery(this).data("edit",{changed:false})}});var a;if(google.language.isTranslatable(transposh_params.lang)||"he|zh-tw|pt".indexOf(transposh_params.lang)>-1){a={"Suggest - Google":function(){getgt()},Ok:function(){var d=jQuery("#"+transposh_params.prefix+"translation").val();if(jQuery("#"+transposh_params.prefix+"translation").data("edit").changed){ajax_translate(d,0,b);jQuery("#"+transposh_params.prefix+"translation").data("edit",{changed:false})}jQuery(this).dialog("close")}}}else{a={Ok:function(){var d=jQuery("#"+transposh_params.prefix+"translation").val();if(jQuery("#"+transposh_params.prefix+"translation").data("edit").changed){ajax_translate(d,0,b);jQuery("#"+transposh_params.prefix+"translation").data("edit",{changed:false})}jQuery(this).dialog("close")}}}var c={Close:function(){jQuery(this).dialog("close")}};jQuery("#"+transposh_params.prefix+"d-tabs").dialog({bgiframe:true,modal:true,width:500,buttons:a})}jQuery.noConflict();var transposh_params=new Array();jQuery("script[src*='transposh.js']").each(function(a){var e=unescape(this.src.substring(this.src.indexOf("?")+1));var d=e.split("&");for(var c=0;c<d.length;c++){var g=d[c].indexOf("=");if(g>0){var b=d[c].substring(0,g);var f=d[c].substring(g+1);transposh_params[b]=f}}});transposh_params.blank="transposh_params.post_url+'?tp_gif=y";google.load("language","1");jQuery(document).ready(function(){if(typeof(jQuery().progressbar)!="undefined"){transposh_params.progress=true}if(google.language.isTranslatable(transposh_params.lang)||"he|zh-tw|pt".indexOf(transposh_params.lang)>-1){do_auto_translate()}if(transposh_params.edit){jQuery("."+transposh_params.prefix).each(function(c){var a=jQuery(this).attr("id").substr(jQuery(this).attr("id").lastIndexOf("_")+1);jQuery(this).after('<img id="'+transposh_params.prefix+"img_"+a+'" class="tr-icon" size="12x12" title="'+jQuery(this).attr("orig")+'" src="'+transposh_params.blank+'"/>');var b=jQuery("#"+transposh_params.prefix+"img_"+a);b.click(function(){translate_dialog(a);return false}).css({border:"0px",margin:"1px",padding:"0px"});if(jQuery(this).attr("source")=="1"){b.addClass("tr-icon-yellow")}else{if(jQuery(this).attr("source")=="0"){b.addClass("tr-icon-green")}}if(jQuery(this).attr("hidden")=="y"){b.css({opacity:"0.6"})}})}});
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://transposh.org/
4
  Tags: translation, widget, filter, bilingual, multilingual, transposh, language, crowdsourcing, context, wiki, RTL, Hebrew, Spanish, French, Russian, English, Arabic, Portuguese
5
  Requires at least: 2.7
6
  Tested up to: 2.8
7
- Stable tag: 0.2.4
8
 
9
  Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
10
 
@@ -97,6 +97,10 @@ Just add the following line to your template:
97
  5. Widget style selection
98
 
99
  == Release notes ==
 
 
 
 
100
  * 2009/06/09 - 0.2.4
101
  * Fixed bugs with database prefixes (thanks again [Mike](http://www.nostate.com/))
102
  * Translation of keywords and description meta tags (thanks again [Mike](http://www.nostate.com/))
4
  Tags: translation, widget, filter, bilingual, multilingual, transposh, language, crowdsourcing, context, wiki, RTL, Hebrew, Spanish, French, Russian, English, Arabic, Portuguese
5
  Requires at least: 2.7
6
  Tested up to: 2.8
7
+ Stable tag: 0.2.5
8
 
9
  Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
10
 
97
  5. Widget style selection
98
 
99
  == Release notes ==
100
+ * 2009/06/16 - 0.2.5
101
+ * Fixed url rewrite bug reported by ([Mike](http://www.nostate.com/))
102
+ * Allow translation of even more hidden elements such as keywords, descriptions and stuff inside select tags
103
+ * Updated to jQueryUI 1.7.2
104
  * 2009/06/09 - 0.2.4
105
  * Fixed bugs with database prefixes (thanks again [Mike](http://www.nostate.com/))
106
  * Translation of keywords and description meta tags (thanks again [Mike](http://www.nostate.com/))
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.2.4
8
  Author URI: http://transposh.org/
9
  License: GPL (http://www.gnu.org/licenses/gpl.txt)
10
  */
@@ -86,7 +86,7 @@ function process_page(&$buffer) {
86
  * which means that query parameters are not accessiable.
87
  */
88
  function init_global_vars() {
89
- global $home_url, $home_url_quoted, $tr_plugin_url, $enable_permalinks_rewrite, $wp_rewrite;
90
 
91
  $home_url = get_option('home');
92
  // Handle windows ('C:\wordpress')
@@ -95,8 +95,6 @@ function init_global_vars() {
95
  $local_dir = preg_replace("/.*\//", "", $local_dir);
96
  $tr_plugin_url= WP_PLUGIN_URL .'/'. $local_dir;
97
 
98
- $home_url_quoted = preg_quote($home_url);
99
- $home_url_quoted = preg_replace("/\//", "\\/", $home_url_quoted);
100
 
101
  if($wp_rewrite->using_permalinks() && get_option(ENABLE_PERMALINKS_REWRITE)) {
102
  $enable_permalinks_rewrite = TRUE;
@@ -351,7 +349,7 @@ function add_transposh_css() {
351
  return;
352
  }
353
  //include the transposh.css
354
- wp_enqueue_style("transposh","$tr_plugin_url/css/transposh.css",array(),'0.2.4');
355
  wp_enqueue_style("jquery","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/ui-lightness/jquery-ui.css",array(),'1.0');
356
 
357
  }
@@ -382,7 +380,7 @@ function add_transposh_js() {
382
  }
383
 
384
  if($GLOBALS['is_edit_mode'] || $options['progressbar']) {
385
- wp_enqueue_script("jqueryui","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js",array("jquery"),'1.7.1',get_option(ENABLE_FOOTER_SCRIPTS));
386
  }
387
 
388
  if($GLOBALS['is_edit_mode'] || $enable_auto_translate) {
@@ -390,7 +388,7 @@ function add_transposh_js() {
390
  wp_deregister_script('jquery');
391
  wp_enqueue_script("jquery","http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js",array(),'1.3.2', get_option(ENABLE_FOOTER_SCRIPTS));
392
  wp_enqueue_script("google","http://www.google.com/jsapi",array(),'1',get_option(ENABLE_FOOTER_SCRIPTS));
393
- wp_enqueue_script("transposh","$tr_plugin_url/js/transposh.js?post_url=$post_url{$edit_mode}&lang={$GLOBALS['lang']}&prefix=".SPAN_PREFIX,array("jquery"),'0.2.4',get_option(ENABLE_FOOTER_SCRIPTS));
394
  }
395
  }
396
 
@@ -456,7 +454,7 @@ function rewrite_url($href) {
456
  // don't fix links pointing to real files as it will cause that the
457
  // web server will not be able to locate them
458
  if(stripos($href, '/wp-admin') !== FALSE ||
459
- stripos($href, '/wp-content') !== FALSE ||
460
  stripos($href, '/wp-login') !== FALSE ||
461
  stripos($href, '/.php') !== FALSE) {
462
  return $href;
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.2.5
8
  Author URI: http://transposh.org/
9
  License: GPL (http://www.gnu.org/licenses/gpl.txt)
10
  */
86
  * which means that query parameters are not accessiable.
87
  */
88
  function init_global_vars() {
89
+ global $home_url, $tr_plugin_url, $enable_permalinks_rewrite, $wp_rewrite;
90
 
91
  $home_url = get_option('home');
92
  // Handle windows ('C:\wordpress')
95
  $local_dir = preg_replace("/.*\//", "", $local_dir);
96
  $tr_plugin_url= WP_PLUGIN_URL .'/'. $local_dir;
97
 
 
 
98
 
99
  if($wp_rewrite->using_permalinks() && get_option(ENABLE_PERMALINKS_REWRITE)) {
100
  $enable_permalinks_rewrite = TRUE;
349
  return;
350
  }
351
  //include the transposh.css
352
+ wp_enqueue_style("transposh","$tr_plugin_url/css/transposh.css",array(),'0.2.5');
353
  wp_enqueue_style("jquery","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/ui-lightness/jquery-ui.css",array(),'1.0');
354
 
355
  }
380
  }
381
 
382
  if($GLOBALS['is_edit_mode'] || $options['progressbar']) {
383
+ wp_enqueue_script("jqueryui","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js",array("jquery"),'1.7.2',get_option(ENABLE_FOOTER_SCRIPTS));
384
  }
385
 
386
  if($GLOBALS['is_edit_mode'] || $enable_auto_translate) {
388
  wp_deregister_script('jquery');
389
  wp_enqueue_script("jquery","http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js",array(),'1.3.2', get_option(ENABLE_FOOTER_SCRIPTS));
390
  wp_enqueue_script("google","http://www.google.com/jsapi",array(),'1',get_option(ENABLE_FOOTER_SCRIPTS));
391
+ wp_enqueue_script("transposh","$tr_plugin_url/js/transposh.js?post_url=$post_url{$edit_mode}&lang={$GLOBALS['lang']}&prefix=".SPAN_PREFIX,array("jquery"),'0.2.5',get_option(ENABLE_FOOTER_SCRIPTS));
392
  }
393
  }
394
 
454
  // don't fix links pointing to real files as it will cause that the
455
  // web server will not be able to locate them
456
  if(stripos($href, '/wp-admin') !== FALSE ||
457
+ stripos($href, WP_CONTENT_URL) !== FALSE ||
458
  stripos($href, '/wp-login') !== FALSE ||
459
  stripos($href, '/.php') !== FALSE) {
460
  return $href;
transposh_admin.php CHANGED
@@ -66,9 +66,8 @@ function insert_supported_langs() {
66
 
67
  foreach($languages as $code => $lang) {
68
  list ($language,$flag,$autot) = explode (",",$lang);
69
- if(!($i % $columns)) echo '<tr>';
70
  $i++;
71
-
72
  echo "<td><img src=\"$tr_plugin_url/img/flags/$flag.png\" alt=\"\"/>&nbsp;$language</td>";
73
  echo '<td align="center"><input type="checkbox" id="' . $code .'_view" name="' .
74
  $code . '_view" onchange="chbx_change(\'' . $code . '\')" ' . is_viewable($code) . '/></td>';
66
 
67
  foreach($languages as $code => $lang) {
68
  list ($language,$flag,$autot) = explode (",",$lang);
69
+ if(!($i % $columns)) echo '<tr'.(!($i/2 % $columns) ? ' class="alternate"':'').'>';
70
  $i++;
 
71
  echo "<td><img src=\"$tr_plugin_url/img/flags/$flag.png\" alt=\"\"/>&nbsp;$language</td>";
72
  echo '<td align="center"><input type="checkbox" id="' . $code .'_view" name="' .
73
  $code . '_view" onchange="chbx_change(\'' . $code . '\')" ' . is_viewable($code) . '/></td>';
transposh_db.php CHANGED
@@ -129,7 +129,7 @@ function update_translation() {
129
  $original = $wpdb->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
130
 
131
  //add our own custom header - so we will know that we got here
132
- header("Transposh: ver-0.2.4 db_version-". DB_VERSION);
133
 
134
  list($translated_text, $old_source) = fetch_translation($original, $lang);
135
  if ($translated_text) {
@@ -227,7 +227,7 @@ function get_translation_history($token, $lang) {
227
  $original = $wpdb->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
228
 
229
  //add our own custom header - so we will know that we got here
230
- header("Transposh: ver-0.2.4 db_version-". DB_VERSION);
231
 
232
  $query = "SELECT translated, translated_by, timestamp, source, user_login ".
233
  "FROM $table_name ".
129
  $original = $wpdb->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
130
 
131
  //add our own custom header - so we will know that we got here
132
+ header("Transposh: ver-0.2.5 db_version-". DB_VERSION);
133
 
134
  list($translated_text, $old_source) = fetch_translation($original, $lang);
135
  if ($translated_text) {
227
  $original = $wpdb->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
228
 
229
  //add our own custom header - so we will know that we got here
230
+ header("Transposh: ver-0.2.5 db_version-". DB_VERSION);
231
 
232
  $query = "SELECT translated, translated_by, timestamp, source, user_login ".
233
  "FROM $table_name ".
transposh_widget.php CHANGED
@@ -22,6 +22,7 @@
22
  */
23
 
24
  require_once("core/constants.php");
 
25
  require_once("transposh.php");
26
 
27
  /*
@@ -31,19 +32,23 @@ require_once("transposh.php");
31
  function init_transposh() {
32
  if (isset ($_POST['transposh_widget_posted'])) {
33
 
 
34
 
35
  $ref=getenv('HTTP_REFERER');
36
  $lang = $_POST[LANG_PARAM];
 
37
 
38
  //remove existing language settings.
39
  $ref = cleanup_url($ref);
 
40
 
41
  if($lang != "none") {
42
  $ref = rewrite_url_lang_param($ref, $lang, $_POST[EDIT_PARAM]);
 
43
 
44
- //ref is generated with html entities encoded, needs to be
45
- //decoded when used in the http header (i.e. 302 redirect)
46
- $ref = html_entity_decode($ref, ENT_NOQUOTES);
47
  }
48
 
49
 
@@ -79,7 +84,7 @@ function add_transposh_widget_css() {
79
  global $tr_plugin_url;
80
 
81
  //include the transposh_widget.css
82
- wp_enqueue_style("transposh_widget","$tr_plugin_url/css/transposh_widget.css",array(),'0.2.4');
83
 
84
  }
85
 
@@ -88,14 +93,10 @@ function add_transposh_widget_css() {
88
  */
89
  function transposh_widget($args) {
90
 
91
- global $languages, $wp_query, $tr_plugin_url;
92
  extract($args);
93
 
94
- //$page_url = "http://";
95
- $page_url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://') ;
96
- $page_url .= $_SERVER["SERVER_NAME"];
97
- $page_url .= ($_SERVER["SERVER_PORT"] != "80" ? ":" .$_SERVER["SERVER_PORT"] : "");
98
- $page_url .= $_SERVER["REQUEST_URI"];
99
 
100
 
101
  $options = get_option(WIDGET_TRANSPOSH);
@@ -109,85 +110,50 @@ function transposh_widget($args) {
109
 
110
  echo $before_widget . $before_title . __("Translation") . $after_title;
111
 
 
 
 
 
112
  switch ($options['style']) {
113
  case 1: // flags
 
114
  //keep the flags in the same direction regardless of the overall page direction
115
  echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
116
 
117
  foreach($languages as $code => $lang2) {
118
  list($language,$flag) = explode (",",$lang2);
119
 
120
- //remove any language identifier
121
-
122
- $page_url = cleanup_url($page_url);
123
-
124
-
125
  //Only show languages which are viewable or (editable and the user is a translator)
126
  if(strpos($viewable_langs, $code) !== FALSE || is_editable_lang($code) || (get_option(DEFAULT_LANG) == $code)) {
127
 
128
- $page_url2 = rewrite_url_lang_param($page_url, $code, $GLOBALS['is_edit_mode']);
129
  if (get_option(DEFAULT_LANG) == $code) {
130
- $page_url2 = $page_url;
131
  }
132
- //TODO: improve this hacky! shortening
133
- $urlpath = parse_url($page_url2, PHP_URL_PATH);
134
- if (trim(parse_url($page_url2, PHP_URL_QUERY)) != '')
135
- $urlpath .= '?'.parse_url($page_url2, PHP_URL_QUERY);
136
- if (trim(parse_url($page_url2, PHP_URL_FRAGMENT)) != '')
137
- $urlpath .= '#'.parse_url($page_url2, PHP_URL_FRAGMENT);
138
 
139
 
140
- echo "<a href=\"" . $urlpath . "\">".
141
- "<img src=\"$plugpath/img/flags/$flag.png\" title=\"$language\" alt=\"$language\"".
142
- " style=\"padding: 1px 3px;border: 0px\"/></a>";
143
- $is_showing_languages = TRUE;
144
- }
145
- }
146
- echo "</div>";
147
-
148
- // this is the form for the edit...
149
- echo "<form action=\"$page_url\" method=\"post\">";
150
- echo "<input type=\"hidden\" name=\"lang\" id=\"lang\" value=\"{$GLOBALS['lang']}\"/>";
151
- break;
152
- case 2: // language list
153
- //keep the flags in the same direction regardless of the overall page direction
154
- echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
155
-
156
- foreach($languages as $code => $lang2) {
157
- list($language,$flag) = explode (",",$lang2);
158
-
159
- //remove any language identifier
160
- $page_url = cleanup_url($page_url);
161
-
162
- //Only show languages which are viewable or (editable and the user is a translator)
163
- if(strpos($viewable_langs, $code) !== FALSE || is_editable_lang($code) || (get_option(DEFAULT_LANG) == $code)) {
164
- $page_url2 = rewrite_url_lang_param($page_url, $code, $GLOBALS['is_edit_mode']);
165
- if (get_option(DEFAULT_LANG) == $code) {
166
- $page_url2 = $page_url;
167
  }
168
- //TODO: improve this hacky! shortening
169
- $urlpath = parse_url($page_url2, PHP_URL_PATH);
170
- if (trim(parse_url($page_url2, PHP_URL_QUERY)) != '')
171
- $urlpath .= '?'.parse_url($page_url2, PHP_URL_QUERY);
172
- if (trim(parse_url($page_url2, PHP_URL_FRAGMENT)) != '')
173
- $urlpath .= '#'.parse_url($page_url2, PHP_URL_FRAGMENT);
174
-
175
-
176
- echo "<a href=\"" . $urlpath . "\">".
177
- "<img src=\"$plugpath/img/flags/$flag.png\" title=\"$language\" alt=\"$language\"".
178
- " style=\"padding: 1px 3px;border: 0px\"/></a>$language<br/>";
179
  $is_showing_languages = TRUE;
180
  }
181
  }
182
  echo "</div>";
183
 
184
  // this is the form for the edit...
185
- echo "<form action=\"$page_url\" method=\"post\">";
186
  echo "<input type=\"hidden\" name=\"lang\" id=\"lang\" value=\"{$GLOBALS['lang']}\"/>";
187
  break;
188
  default: // language selection
189
 
190
- echo "<form action=\"$page_url\" method=\"post\">";
191
  echo "<span class=\"" .NO_TRANSLATE_CLASS . "\" >";
192
  echo "<select name=\"lang\" id=\"lang\" onchange=\"Javascript:this.form.submit();\">";
193
  echo "<option value=\"none\">[Language]</option>";
@@ -206,7 +172,6 @@ function transposh_widget($args) {
206
  echo "</span>"; // the no_translate for the language list
207
  }
208
 
209
-
210
  //at least one language showing - add the edit box if applicable
211
  if($is_showing_languages) {
212
  //Add the edit checkbox only for translators on languages marked as editable
@@ -229,40 +194,6 @@ function transposh_widget($args) {
229
  echo $after_widget;
230
  }
231
 
232
- /*
233
- * Remove from url any language (or editing) params that were added for our use.
234
- * Return the scrubed url
235
- */
236
- function cleanup_url($url) {
237
- global $home_url, $home_url_quoted;
238
-
239
- //cleanup previous lang & edit parameter from url
240
- $url = preg_replace("/(" . LANG_PARAM . "|" . EDIT_PARAM . ")=[^&]*/i", "", $url);
241
-
242
-
243
- if(!$home_url) {
244
- //make sure required home urls are fetched - as they are need now
245
- init_global_vars();
246
- }
247
-
248
- //cleanup lang identifier in permalinks
249
- $url = preg_replace("/$home_url_quoted\/(..\/)/", "$home_url/", $url);
250
-
251
- //some more cleans
252
- $url = preg_replace("/&$/", "", $url);
253
- $url = preg_replace("/\?$/", "", $url);
254
-
255
- return $url;
256
- }
257
-
258
- /*
259
- * Mark the given text so it will not subject to translation.
260
- * Return the text with the required tags
261
- */
262
- function no_translate($text) {
263
- return "<span class=\"" . NO_TRANSLATE_CLASS . "\">$text</span>";
264
- }
265
-
266
  function transposh_widget_post() {
267
  $options = $newoptions = get_option(WIDGET_TRANSPOSH);
268
  $newoptions['style'] = $_POST['transposh-style'];
22
  */
23
 
24
  require_once("core/constants.php");
25
+ require_once("core/utils.php");
26
  require_once("transposh.php");
27
 
28
  /*
32
  function init_transposh() {
33
  if (isset ($_POST['transposh_widget_posted'])) {
34
 
35
+ init_global_vars();
36
 
37
  $ref=getenv('HTTP_REFERER');
38
  $lang = $_POST[LANG_PARAM];
39
+
40
 
41
  //remove existing language settings.
42
  $ref = cleanup_url($ref);
43
+
44
 
45
  if($lang != "none") {
46
  $ref = rewrite_url_lang_param($ref, $lang, $_POST[EDIT_PARAM]);
47
+
48
 
49
+ //ref is generated with html entities encoded, needs to be
50
+ //decoded when used in the http header (i.e. 302 redirect)
51
+ //$ref = html_entity_decode($ref, ENT_NOQUOTES);
52
  }
53
 
54
 
84
  global $tr_plugin_url;
85
 
86
  //include the transposh_widget.css
87
+ wp_enqueue_style("transposh_widget","$tr_plugin_url/css/transposh_widget.css",array(),'0.2.5');
88
 
89
  }
90
 
93
  */
94
  function transposh_widget($args) {
95
 
96
+ global $languages, $wp_query, $tr_plugin_url;
97
  extract($args);
98
 
99
+ $page_url = $_SERVER["REQUEST_URI"];
 
 
 
 
100
 
101
 
102
  $options = get_option(WIDGET_TRANSPOSH);
110
 
111
  echo $before_widget . $before_title . __("Translation") . $after_title;
112
 
113
+ //remove any language identifier
114
+ $clean_page_url = cleanup_url($page_url, true);
115
+
116
+
117
  switch ($options['style']) {
118
  case 1: // flags
119
+ case 2: // language list
120
  //keep the flags in the same direction regardless of the overall page direction
121
  echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
122
 
123
  foreach($languages as $code => $lang2) {
124
  list($language,$flag) = explode (",",$lang2);
125
 
 
 
 
 
 
126
  //Only show languages which are viewable or (editable and the user is a translator)
127
  if(strpos($viewable_langs, $code) !== FALSE || is_editable_lang($code) || (get_option(DEFAULT_LANG) == $code)) {
128
 
129
+ $page_url = rewrite_url_lang_param($clean_page_url, $code, $GLOBALS['is_edit_mode']);
130
  if (get_option(DEFAULT_LANG) == $code) {
131
+ $page_url = $clean_page_url;
132
  }
 
 
 
 
 
 
133
 
134
 
135
+ if ($options['style'] == 1) {
136
+ echo "<a href=\"" . $page_url . "\">".
137
+ "<img src=\"$plugpath/img/flags/$flag.png\" title=\"$language\" alt=\"$language\"".
138
+ " style=\"padding: 1px 3px;border: 0px\"/></a>";
139
+ }
140
+ else {
141
+ echo "<a href=\"" . $page_url . "\">".
142
+ "<img src=\"$plugpath/img/flags/$flag.png\" title=\"$language\" alt=\"$language\"".
143
+ " style=\"padding: 1px 3px;border: 0px\"/></a>$language<br/>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  }
 
 
 
 
 
 
 
 
 
 
 
145
  $is_showing_languages = TRUE;
146
  }
147
  }
148
  echo "</div>";
149
 
150
  // this is the form for the edit...
151
+ echo "<form action=\"$clean_page_url\" method=\"post\">";
152
  echo "<input type=\"hidden\" name=\"lang\" id=\"lang\" value=\"{$GLOBALS['lang']}\"/>";
153
  break;
154
  default: // language selection
155
 
156
+ echo "<form action=\"$clean_page_url\" method=\"post\">";
157
  echo "<span class=\"" .NO_TRANSLATE_CLASS . "\" >";
158
  echo "<select name=\"lang\" id=\"lang\" onchange=\"Javascript:this.form.submit();\">";
159
  echo "<option value=\"none\">[Language]</option>";
172
  echo "</span>"; // the no_translate for the language list
173
  }
174
 
 
175
  //at least one language showing - add the edit box if applicable
176
  if($is_showing_languages) {
177
  //Add the edit checkbox only for translators on languages marked as editable
194
  echo $after_widget;
195
  }
196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  function transposh_widget_post() {
198
  $options = $newoptions = get_option(WIDGET_TRANSPOSH);
199
  $newoptions['style'] = $_POST['transposh-style'];