Transposh WordPress Translation - Version 0.0.2

Version Description

Download this release

Release Info

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

Code changes from version 0.0.1 to 0.0.2

Files changed (8) hide show
  1. constants.php +10 -1
  2. js/transposh.js +66 -8
  3. parser.php +63 -19
  4. readme.txt +6 -2
  5. transposh.css +0 -3
  6. transposh.php +44 -17
  7. transposh_admin.php +39 -1
  8. transposh_widget.php +1 -0
constants.php CHANGED
@@ -72,7 +72,16 @@ define("EDITABLE_LANGS", "transposh_editable_languages");
72
  //Option defining the default language
73
  define("DEFAULT_LANG", "transposh_default_language");
74
 
 
 
 
 
 
 
75
  //Option defining transposh widget appearance
76
  define("WIDGET_TRANSPOSH", "widget_transposh");
77
 
78
- ?>
 
 
 
72
  //Option defining the default language
73
  define("DEFAULT_LANG", "transposh_default_language");
74
 
75
+ //Define segment id prefix, will be included in span tag.
76
+ define("SPAN_PREFIX", "tr_");
77
+
78
+ //Define segment id prefix, will be included in img tag.
79
+ define("IMG_PREFIX", "tr_img_");
80
+
81
  //Option defining transposh widget appearance
82
  define("WIDGET_TRANSPOSH", "widget_transposh");
83
 
84
+ //Option to enable/disable rewrite of permalinks
85
+ define("ENABLE_PERMALINKS_REWRITE", "transposh_enable_permalinks");
86
+
87
+ ?>
js/transposh.js CHANGED
@@ -46,21 +46,79 @@ function hint(original)
46
  }
47
 
48
  //Open translation dialog
49
- function translate_dialog(original, trans, lang, post_url)
50
  {
51
  caption='Edit Translation';
52
 
53
- //TODO accept the action url as a parameter
54
  var dialog = ''+
55
- ('<form name="transposh_edit_form" method="post" action="' + post_url + '"><div>') +
56
- '<p dir="ltr">Original text<br \/><textarea cols="60" rows="3" readonly="readyonly">' +
57
  original + '</textarea> <\/p>' +
58
- '<p>Translate to<br \/><input type="text" name="translation" size="80" value="'+ trans + '"' + 'onfocus="OLmEdit=1;" onblur="OLmEdit=0;"<\/p>' +
59
- '<input type="hidden" name="original" value="'+escape(original)+'">' +
60
- '<input type="hidden" name="lang" value="'+lang+'">' +
 
61
  '<input type="hidden" name="translation_posted" value= "1">' +
62
  '<p><input type="submit" value="Translate"><\/p>' +
63
  ('<\/div><\/form>');
64
 
65
  display_dialog(caption, dialog);
66
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  }
47
 
48
  //Open translation dialog
49
+ function translate_dialog(original, trans, lang, post_url, segment_id)
50
  {
51
  caption='Edit Translation';
52
 
 
53
  var dialog = ''+
54
+ ('<form id="tr_form" name="transposh_edit_form" method="post" action="' + post_url + '"><div>') +
55
+ '<p dir="ltr">Original text<br \/><textarea id="tr_original_unescaped" cols="60" rows="3" readonly="readyonly">' +
56
  original + '</textarea> <\/p>' +
57
+ '<p>Translate to<br \/><input type="text" id="tr_translation" name="translation" size="80" value="'+ trans +
58
+ '"' + 'onfocus="OLmEdit=1;" onblur="OLmEdit=0;"<\/p>' +
59
+ '<input type="hidden" id="tr_original" name="original" value="' + escape(original) +'">' +
60
+ '<input type="hidden" id="tr_lang" name="lang" value="'+lang+'">' +
61
  '<input type="hidden" name="translation_posted" value= "1">' +
62
  '<p><input type="submit" value="Translate"><\/p>' +
63
  ('<\/div><\/form>');
64
 
65
  display_dialog(caption, dialog);
66
+
67
+ // attach handler to form's submit event
68
+ $('#tr_form').submit(function() {
69
+ var translation = $('#tr_translation').val();
70
+ var query = 'original=' + escape(original) +
71
+ '&translation=' + translation +
72
+ '&lang=' + $('#tr_lang').val() +
73
+ '&translation_posted=1';
74
+
75
+
76
+ $.ajax({
77
+ type: "POST",
78
+ url: post_url,
79
+ data: query,
80
+ success: function(req) {
81
+ //rewrite onclick function - in case of re-edit
82
+ $("#tr_img_" + segment_id).click(function () {
83
+ translate_dialog(original, translation, lang, post_url, segment_id);
84
+ });
85
+
86
+ //current img
87
+ var img = $("#tr_img_" + segment_id).attr('src');
88
+ var text_rewrite = translation;
89
+
90
+ if(jQuery.trim(translation).length == 0) {
91
+ //reset to the original content - the not escaped version
92
+ text_rewrite = original;
93
+
94
+ //switch to the edit img
95
+ img = img.replace(/translate_fix.png/, "translate.png");
96
+ }
97
+ else {
98
+ //switch to the fix img
99
+ img = img.replace(/translate.png/, "translate_fix.png");
100
+ }
101
+
102
+
103
+ //rewrite text
104
+ $("#tr_" + segment_id).html(text_rewrite);
105
+
106
+ //rewrite image
107
+ $("#tr_img_" + segment_id).attr('src', img);
108
+
109
+ //close dialog
110
+ cClick();
111
+ },
112
+
113
+ error: function(req) {
114
+ alert("Error !!! failed to translate.\n\nServer's message: " + req.statusText);
115
+ }
116
+
117
+
118
+ });
119
+
120
+ // return false to prevent normal browser submit and page navigation
121
+ return false;
122
+
123
+ });
124
+ }
parser.php CHANGED
@@ -23,6 +23,7 @@
23
  * to obtain WorkdPress specific capabilities, e.g. db access.
24
  */
25
 
 
26
  require_once("constants.php");
27
 
28
  //The language to which the current page will be translated to.
@@ -46,7 +47,11 @@ $tr_mark = 0;
46
  //Is the current use is in edit mode.
47
  $is_edit_mode = FALSE;
48
 
 
 
49
 
 
 
50
 
51
  /*
52
  * Parse the html page into tags, identify translateable string which
@@ -58,8 +63,9 @@ function process_html()
58
 
59
  global $page, $tr_page, $pos, $tags_list, $lang;
60
  $no_translate = 0;
 
61
 
62
- while($pos < strlen($page))
63
  {
64
  //find beginning of next tag
65
  $pos = strpos($page, '<', $pos);
@@ -189,6 +195,11 @@ function process_tag_init(&$element, $start, $end)
189
  case 'html':
190
  process_html_tag($start, $end);
191
  break;
 
 
 
 
 
192
 
193
  }
194
 
@@ -357,20 +368,20 @@ function get_attribute(&$start, &$end, $id)
357
  */
358
  function process_current_tag()
359
  {
360
- global $page, $pos, $tags_list;
361
 
362
  $current_tag = end($tags_list);
363
 
364
 
365
 
366
- //translate only specific elements - <a> or <div>
367
- if($current_tag == 'a' || $current_tag == 'title' ||
368
- array_search('div', $tags_list))
369
  {
370
  skip_white_space();
371
  $start = $pos;
 
372
 
373
- while($pos < strlen($page) && $page[$pos] != '<')
374
  {
375
  //will break translation unit when one of the following characters is reached: .,
376
  if(is_sentence_breaker($pos))
@@ -608,20 +619,57 @@ function translate_text($start)
608
  return;
609
  }
610
 
611
- $is_translated = FALSE;
612
  $translated_text = fetch_translation($original_text);
613
- if($translated_text != NULL)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
614
  {
615
-
616
- $translated_text = htmlspecialchars($translated_text);
617
- update_translated_page($start, $end, $translated_text);
618
- $is_translated = TRUE;
619
  }
620
-
621
- if($is_edit_mode)
622
  {
623
- $img = get_img_tag($original_text, $translated_text, $is_translated);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
624
  update_translated_page($end + 1, - 1, $img);
 
 
 
 
 
625
  }
626
 
627
 
@@ -645,10 +693,6 @@ function scrub_text(&$text)
645
  //replace multi space chars with a single space
646
  $text = preg_replace("/\s\s+/", " ", $text);
647
 
648
- //Make that the string is encoded in the same way as it will
649
- //decoded, when passed back for translation (i.e. post)
650
- $text = htmlspecialchars($text);
651
-
652
  return $text;
653
  }
654
 
23
  * to obtain WorkdPress specific capabilities, e.g. db access.
24
  */
25
 
26
+
27
  require_once("constants.php");
28
 
29
  //The language to which the current page will be translated to.
47
  //Is the current use is in edit mode.
48
  $is_edit_mode = FALSE;
49
 
50
+ //Segment identifier within tags (span/img) mainly for use by js code on the client
51
+ $segment_id = 0;
52
 
53
+ //Is current position within the body tag
54
+ $is_in_body = FALSE;
55
 
56
  /*
57
  * Parse the html page into tags, identify translateable string which
63
 
64
  global $page, $tr_page, $pos, $tags_list, $lang;
65
  $no_translate = 0;
66
+ $page_length = strlen($page);
67
 
68
+ while($pos < $page_length)
69
  {
70
  //find beginning of next tag
71
  $pos = strpos($page, '<', $pos);
195
  case 'html':
196
  process_html_tag($start, $end);
197
  break;
198
+ case 'body':
199
+ global $is_in_body;
200
+ $is_in_body = TRUE;
201
+ break;
202
+
203
 
204
  }
205
 
368
  */
369
  function process_current_tag()
370
  {
371
+ global $page, $pos, $tags_list, $is_in_body;
372
 
373
  $current_tag = end($tags_list);
374
 
375
 
376
 
377
+ //translate only elements within the body or title
378
+ if($is_in_body || $current_tag == 'title')
 
379
  {
380
  skip_white_space();
381
  $start = $pos;
382
+ $page_length = strlen($page);
383
 
384
+ while($pos < $page_length && $page[$pos] != '<')
385
  {
386
  //will break translation unit when one of the following characters is reached: .,
387
  if(is_sentence_breaker($pos))
619
  return;
620
  }
621
 
 
622
  $translated_text = fetch_translation($original_text);
623
+
624
+ insert_translation($original_text, $translated_text, $start, $end);
625
+ }
626
+
627
+ /*
628
+ * Update the translated page with the specified translation at the given position.
629
+ * param original_text Text in the original page. Will not be NULL.
630
+ * param translated_text The translated text, can be NULL in case no translation is available
631
+ * param start Marks the start position of the text to be replaced within the original page
632
+ * param end Marks the end position of the text to be replaced within the original page
633
+ */
634
+ function insert_translation(&$original_text, &$translated_text, $start, $end)
635
+ {
636
+ global $segment_id, $is_edit_mode, $tags_list;
637
+
638
+ $is_translated = FALSE;
639
+
640
+ if(!$is_edit_mode || !in_array('body', $tags_list))
641
  {
642
+ if($translated_text != NULL)
643
+ {
644
+ update_translated_page($start, $end, $translated_text);
645
+ }
646
  }
647
+ else
 
648
  {
649
+ $span = "<span id=\"" . SPAN_PREFIX . "$segment_id\">";
650
+
651
+ if($translated_text == NULL)
652
+ {
653
+ $span .= $original_text . '</span>';
654
+ }
655
+ else
656
+ {
657
+ $span .= $translated_text . "</span>";
658
+ $is_translated = TRUE;
659
+ }
660
+
661
+ //Insert text (either original or translated) marked by a <span>
662
+ update_translated_page($start, $end, $span);
663
+
664
+
665
+ //Insert image to allow editing this segment
666
+ $img = get_img_tag($original_text, $translated_text, $segment_id, $is_translated);
667
  update_translated_page($end + 1, - 1, $img);
668
+
669
+ //Increment only after both text and image are generated so they
670
+ //will be the same for each translated segement
671
+ $segment_id++;
672
+
673
  }
674
 
675
 
693
  //replace multi space chars with a single space
694
  $text = preg_replace("/\s\s+/", " ", $text);
695
 
 
 
 
 
696
  return $text;
697
  }
698
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://transposh.org/
4
  Tags: translation, widget, filter, bilingual, multilingual, transposh, language, RTL, Hebrew, Spanish, French, Russian, crowdsourcing, context, wiki
5
  Requires at least: 2.5
6
  Tested up to: 2.7.1
7
- Stable tag: 0.0.1
8
 
9
  Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
10
 
@@ -71,4 +71,8 @@ harnessed to get your message out to more people. Future versions will give more
71
 
72
  == Release notes ==
73
 
74
- 09/02/28 - 0.0.1 - Initial release
 
 
 
 
4
  Tags: translation, widget, filter, bilingual, multilingual, transposh, language, RTL, Hebrew, Spanish, French, Russian, crowdsourcing, context, wiki
5
  Requires at least: 2.5
6
  Tested up to: 2.7.1
7
+ Stable tag: 0.0.2
8
 
9
  Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
10
 
71
 
72
  == Release notes ==
73
 
74
+ * 09/03/01 - 0.0.2
75
+ * Fixed bug with hard coded plugin path (thanks [Atomboy](http://politicalnewsblogs.com/))
76
+ * Support for AJAX replacement of content using jQuery
77
+ * 09/02/28 - 0.0.1
78
+ * Initial release
transposh.css CHANGED
@@ -1,5 +1,3 @@
1
- <style type='text/css'>
2
-
3
  /*
4
  * Overlibmws library - For the dialog popups
5
  */
@@ -94,4 +92,3 @@ input.olinput {
94
  font-size:13px;
95
  color: #000000;}
96
 
97
- </style>
 
 
1
  /*
2
  * Overlibmws library - For the dialog popups
3
  */
92
  font-size:13px;
93
  color: #000000;}
94
 
 
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.0.1
8
  Author URI: http://transposh.org/
9
  License: GPL (http://www.gnu.org/licenses/gpl.txt)
10
  */
@@ -26,6 +26,7 @@
26
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
  */
28
 
 
29
  require_once("constants.php");
30
  require_once("parser.php");
31
  require_once("transposh_widget.php");
@@ -179,6 +180,12 @@ function rewrite_url_lang_param($url, $lang, $is_edit, $use_params_only)
179
  {
180
  global $home_url, $home_url_quoted;
181
 
 
 
 
 
 
 
182
  if($is_edit)
183
  {
184
  $params = EDIT_PARAM . '=1&';
@@ -243,8 +250,15 @@ function fetch_translation($original)
243
 
244
  if(ENABLE_APC && function_exists('apc_store'))
245
  {
 
 
 
 
 
 
 
246
  //update cache
247
- $rc = apc_store($original . $lang, $translated, 3600);
248
  if($rc === TRUE)
249
  {
250
 
@@ -262,7 +276,7 @@ function fetch_translation($original)
262
  */
263
  function insert_javascript_includes()
264
  {
265
- global $pos, $plugin_url;
266
 
267
  $overlib_dir = "$plugin_url/js/overlibmws";
268
 
@@ -274,6 +288,7 @@ function insert_javascript_includes()
274
  $js .= "\n<script type=\"text/javascript\" src=\"$overlib_dir/overlibmws_shadow.js\"></script>";
275
 
276
  $js .= "\n<script type=\"text/javascript\" src=\"$plugin_url/js/transposh.js\"></script>\n";
 
277
 
278
  echo $js;
279
  }
@@ -282,21 +297,28 @@ function insert_javascript_includes()
282
  /*
283
  * Return the img tag that will added to enable editing a translatable
284
  * item on the page.
285
- *
 
286
  */
287
- function get_img_tag($original, $translation, $is_translated = FALSE)
288
  {
289
- global $plugin_url, $lang;
290
-
 
291
  //For use in javascript, make the following changes:
292
  //1. Add slashes to escape the inner text
293
  //2. Convert the html special characters
294
  //The browser will take decode step 2 and pass it to the js engine which decode step 1 - a bit tricky
295
  $translation = htmlspecialchars(addslashes($translation));
 
296
 
297
- if ($is_translated) $add_img="_fix";
298
- $img = "<img src=\"$plugin_url/translate$add_img.png\" alt=\"translate\"
299
- onclick=\"translate_dialog('$original','$translation','$lang','$home_url'); return false;\"
 
 
 
 
300
  onmouseover=\"hint('$original'); return true;\"
301
  onmouseout=\"nd()\" />";
302
 
@@ -338,8 +360,9 @@ function init_global_vars()
338
  global $home_url, $home_url_quoted, $plugin_url, $table_name, $wpdb;
339
 
340
  $home_url = get_option('home');
 
341
 
342
- $plugin_url= $home_url . "/wp-content/plugins/transposh";
343
  $home_url_quoted = preg_quote($home_url);
344
  $home_url_quoted = preg_replace("/\//", "\\/", $home_url_quoted);
345
 
@@ -372,12 +395,10 @@ function update_translation()
372
  {
373
 
374
  }
375
-
376
- //encode text
377
- $original = $wpdb->escape(htmlspecialchars(urldecode($original)));
378
 
379
- //remove already escaped character to avoid double escaping
380
- $translation = $wpdb->escape(stripslashes(urldecode($translation)));
 
381
 
382
  $update = "REPLACE INTO $table_name (original, translated, lang)
383
  VALUES ('" . $original . "','" . $translation . "','" . $lang . "')";
@@ -398,9 +419,9 @@ function update_translation()
398
  else
399
  {
400
 
 
401
  }
402
 
403
- wp_redirect($ref);
404
  exit;
405
  }
406
 
@@ -493,6 +514,12 @@ function on_shutdown()
493
  function update_rewrite_rules($rules){
494
 
495
 
 
 
 
 
 
 
496
  $newRules = array();
497
  $lang_prefix="([a-z]{2,2}(\-[a-z]{2,2})?)/";
498
 
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.0.2
8
  Author URI: http://transposh.org/
9
  License: GPL (http://www.gnu.org/licenses/gpl.txt)
10
  */
26
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
  */
28
 
29
+
30
  require_once("constants.php");
31
  require_once("parser.php");
32
  require_once("transposh_widget.php");
180
  {
181
  global $home_url, $home_url_quoted;
182
 
183
+ if(!get_option(ENABLE_PERMALINKS_REWRITE))
184
+ {
185
+ //override the use only params - admin configured system to not touch permalinks
186
+ $use_params_only = TRUE;
187
+ }
188
+
189
  if($is_edit)
190
  {
191
  $params = EDIT_PARAM . '=1&';
250
 
251
  if(ENABLE_APC && function_exists('apc_store'))
252
  {
253
+ //If we don't have translation still we want to have it in cache
254
+ $cache_entry = $translated;
255
+ if($cache_entry == NULL)
256
+ {
257
+ $cache_entry = "";
258
+ }
259
+
260
  //update cache
261
+ $rc = apc_store($original . $lang, $cache_entry, 3600);
262
  if($rc === TRUE)
263
  {
264
 
276
  */
277
  function insert_javascript_includes()
278
  {
279
+ global $plugin_url;
280
 
281
  $overlib_dir = "$plugin_url/js/overlibmws";
282
 
288
  $js .= "\n<script type=\"text/javascript\" src=\"$overlib_dir/overlibmws_shadow.js\"></script>";
289
 
290
  $js .= "\n<script type=\"text/javascript\" src=\"$plugin_url/js/transposh.js\"></script>\n";
291
+ $js .= "\n<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js\"></script>\n";
292
 
293
  echo $js;
294
  }
297
  /*
298
  * Return the img tag that will added to enable editing a translatable
299
  * item on the page.
300
+ * param segement_id The id (number) identifying this segment. Needs to be
301
+ placed within the img tag for use on client side operation (jquery)
302
  */
303
+ function get_img_tag($original, $translation, $segment_id, $is_translated = FALSE)
304
  {
305
+ global $plugin_url, $lang, $home_url;
306
+ $url = $home_url . '/index.php';
307
+
308
  //For use in javascript, make the following changes:
309
  //1. Add slashes to escape the inner text
310
  //2. Convert the html special characters
311
  //The browser will take decode step 2 and pass it to the js engine which decode step 1 - a bit tricky
312
  $translation = htmlspecialchars(addslashes($translation));
313
+ $original = htmlspecialchars(addslashes($original));
314
 
315
+ if ($is_translated)
316
+ {
317
+ $add_img = "_fix";
318
+ }
319
+
320
+ $img = "<img src=\"$plugin_url/translate$add_img.png\" alt=\"translate\" id=\"" . IMG_PREFIX . "$segment_id\"
321
+ onclick=\"translate_dialog('$original','$translation','$lang','$url', '$segment_id'); return false;\"
322
  onmouseover=\"hint('$original'); return true;\"
323
  onmouseout=\"nd()\" />";
324
 
360
  global $home_url, $home_url_quoted, $plugin_url, $table_name, $wpdb;
361
 
362
  $home_url = get_option('home');
363
+ $local_dir = preg_replace("/.*\//", "", dirname(__FILE__));
364
 
365
+ $plugin_url= $home_url . "/wp-content/plugins/$local_dir";
366
  $home_url_quoted = preg_quote($home_url);
367
  $home_url_quoted = preg_replace("/\//", "\\/", $home_url_quoted);
368
 
395
  {
396
 
397
  }
 
 
 
398
 
399
+ //Decode & remove already escaped character to avoid double escaping
400
+ $original = $wpdb->escape(stripslashes(urldecode($original)));
401
+ $translation = $wpdb->escape(htmlspecialchars(stripslashes(urldecode($translation))));
402
 
403
  $update = "REPLACE INTO $table_name (original, translated, lang)
404
  VALUES ('" . $original . "','" . $translation . "','" . $lang . "')";
419
  else
420
  {
421
 
422
+ header("HTTP/1.0 404 Failed to update language database");
423
  }
424
 
 
425
  exit;
426
  }
427
 
514
  function update_rewrite_rules($rules){
515
 
516
 
517
+ if(!get_option(ENABLE_PERMALINKS_REWRITE))
518
+ {
519
+
520
+ return $rule;
521
+ }
522
+
523
  $newRules = array();
524
  $lang_prefix="([a-z]{2,2}(\-[a-z]{2,2})?)/";
525
 
transposh_admin.php CHANGED
@@ -22,6 +22,7 @@
22
  *
23
  */
24
 
 
25
  require_once("constants.php");
26
 
27
 
@@ -57,6 +58,9 @@ function transposh_admin_page()
57
  echo '<br/> <h3>Who can translate ?</h3>';
58
  insert_permissions();
59
 
 
 
 
60
  echo '<input type="hidden" name="transposh_admin_posted" value="1" />
61
  <p class="submit"><input type="submit" value="Save Changes" /></p>
62
  </form>
@@ -212,6 +216,27 @@ function insert_permissions()
212
  can_translate('anonymous') . '" /> Anonymous</input>';
213
  }
214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  /*
216
  * Indicates whether the given role can translate.
217
  * Return either "checked" or ""
@@ -247,7 +272,9 @@ function update_admin_options()
247
  {
248
 
249
  global $wp_roles, $languages;
250
-
 
 
251
  //update roles and capabilities
252
  foreach($wp_roles->get_names() as $role_name => $something)
253
  {
@@ -290,6 +317,17 @@ function update_admin_options()
290
  update_option(VIEWABLE_LANGS, implode(',', $viewable_langs));
291
  update_option(EDITABLE_LANGS, implode(',', $editable_langs));
292
  update_option(DEFAULT_LANG, $_POST['default_lang']);
 
 
 
 
 
 
 
 
 
 
 
293
 
294
  echo '<div id="message"class="updated fade">';
295
  echo ('<p> Changes saved</p>');
22
  *
23
  */
24
 
25
+
26
  require_once("constants.php");
27
 
28
 
58
  echo '<br/> <h3>Who can translate ?</h3>';
59
  insert_permissions();
60
 
61
+ echo '<br/> <h3>Rewrite URLs </h3>';
62
+ insert_permalink_rewrite_option();
63
+
64
  echo '<input type="hidden" name="transposh_admin_posted" value="1" />
65
  <p class="submit"><input type="submit" value="Save Changes" /></p>
66
  </form>
216
  can_translate('anonymous') . '" /> Anonymous</input>';
217
  }
218
 
219
+
220
+ /*
221
+ * Insert the option to enable/disable rewrite of perlmalinks.
222
+ * When disabled only parameters will be used to identify the current language.
223
+ *
224
+ */
225
+ function insert_permalink_rewrite_option()
226
+ {
227
+ $checked = "";
228
+ if(get_option(ENABLE_PERMALINKS_REWRITE))
229
+ {
230
+ $checked = 'checked';
231
+ }
232
+
233
+ echo '<input type="checkbox" value="1" name="enable_permalinks"' .
234
+ $checked . '" /> Rewrite URLs to be search engine friendly,
235
+ e.g. (http://wordpress.org/<strong> en</strong>).
236
+ Requires that permalinks will be enabled. </input>';
237
+ }
238
+
239
+
240
  /*
241
  * Indicates whether the given role can translate.
242
  * Return either "checked" or ""
272
  {
273
 
274
  global $wp_roles, $languages;
275
+ $viewable_langs = array();
276
+ $editable_langs = array();
277
+
278
  //update roles and capabilities
279
  foreach($wp_roles->get_names() as $role_name => $something)
280
  {
317
  update_option(VIEWABLE_LANGS, implode(',', $viewable_langs));
318
  update_option(EDITABLE_LANGS, implode(',', $editable_langs));
319
  update_option(DEFAULT_LANG, $_POST['default_lang']);
320
+
321
+ if(get_option(ENABLE_PERMALINKS_REWRITE) != $_POST['enable_permalinks'])
322
+ {
323
+ global $wp_rewrite;
324
+ update_option(ENABLE_PERMALINKS_REWRITE, $_POST['enable_permalinks']);
325
+
326
+ //rewrite rules
327
+ add_filter('rewrite_rules_array', 'update_rewrite_rules');
328
+ $wp_rewrite->flush_rules();
329
+ }
330
+
331
 
332
  echo '<div id="message"class="updated fade">';
333
  echo ('<p> Changes saved</p>');
transposh_widget.php CHANGED
@@ -20,6 +20,7 @@
20
  * Provides the sidebar widget for selecting a language and switching between edit/view
21
  * mode.
22
  */
 
23
  require_once("constants.php");
24
  require_once("transposh.php");
25
 
20
  * Provides the sidebar widget for selecting a language and switching between edit/view
21
  * mode.
22
  */
23
+
24
  require_once("constants.php");
25
  require_once("transposh.php");
26