Transposh WordPress Translation - Version 0.6.3

Version Description

Support .po/.mo files

Download this release

Release Info

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

Code changes from version 0.6.2 to 0.6.3

core/constants.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
 
3
  /*
4
- * Transposh v0.6.2
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
12
  */
13
 
14
  //Language indicator in URL. i.e. lang=en
@@ -17,14 +17,22 @@ define('LANG_PARAM', 'lang');
17
  //Edit mode indicator in URL. i.e. lang=en&edit=true
18
  define('EDIT_PARAM', 'edit');
19
 
20
- //Enable apc usage
21
- define('ENABLE_APC', TRUE);
 
 
22
 
23
  //Class marking a section not be translated.
24
  define('NO_TRANSLATE_CLASS', 'no_translate');
25
  define('NO_TRANSLATE_CLASS_GOOGLE', 'notranslate');
26
  define('ONLY_THISLANGUAGE_CLASS', 'only_thislanguage');
27
 
 
 
 
 
 
 
28
  /**
29
  * Holds our arrays staticly to reduce chance of namespace collision
30
  */
@@ -33,64 +41,64 @@ class transposh_consts {
33
  //Supported languages, new languages can be added here
34
  //the array directs from language code to - English Name, Native name, flag
35
  public static $languages = array(
36
- 'en' => 'English,English,us',
37
- 'af' => 'Afrikaans,Afrikaans,za',
38
- 'sq' => 'Albanian,Shqip,al',
39
- 'ar' => 'Arabic,العربية,sa',
40
- 'hy' => 'Armenian,Հայերեն,am',
41
- 'az' => 'Azerbaijani,azərbaycan dili,az',
42
- 'eu' => 'Basque,euskara,basque',
43
- 'be' => 'Belarusian,Беларуская,by',
44
- 'bg' => 'Bulgarian,Български,bg',
45
- 'ca' => 'Catalan,Català,catalonia',
46
- 'zh' => 'Chinese (Simplified),中文(简体),cn',
47
- 'zh-tw' => 'Chinese (Traditional),中文(漢字),tw',
48
- 'hr' => 'Croatian,Hrvatski,hr',
49
- 'cs' => 'Czech,čeština,cz',
50
- 'da' => 'Danish,dansk,dk',
51
- 'nl' => 'Dutch,Nederlands,nl',
52
- 'et' => 'Estonian,Eesti keel,ee',
53
- 'fi' => 'Finnish,Suomi,fi',
54
- 'fr' => 'French,Français,fr',
55
- 'gl' => 'Galician,Galego,galicia',
56
- 'ka' => 'Georgian,ქართული,ge',
57
- 'de' => 'German,Deutsch,de',
58
- 'el' => 'Greek,Ελληνικά,gr',
59
- 'ht' => 'Haitian,Kreyòl ayisyen,ht',
60
- 'he' => 'Hebrew,עברית,il',
61
- 'hi' => 'Hindi,हिन्दी; हिंदी,in',
62
- 'hu' => 'Hungarian,magyar,hu',
63
- 'is' => 'Icelandic,íslenska,is',
64
- 'id' => 'Indonesian,Bahasa Indonesia,id',
65
- 'ga' => 'Irish,Gaeilge,ie',
66
- 'it' => 'Italian,Italiano,it',
67
- 'ja' => 'Japanese,日本語,jp',
68
- 'ko' => 'Korean,우리말,kr',
69
- 'lv' => 'Latvian,latviešu valoda,lv',
70
- 'lt' => 'Lithuanian,lietuvių kalba,lt',
71
- 'mk' => 'Macedonian,македонски јазик,mk',
72
- 'ms' => 'Malay,bahasa Melayu,my',
73
- 'mt' => 'Maltese,Malti,mt',
74
- 'no' => 'Norwegian,Norsk,no',
75
- 'fa' => 'Persian,فارسی,ir',
76
- 'pl' => 'Polish,Polski,pl',
77
- 'pt' => 'Portuguese,Português,pt',
78
- 'ro' => 'Romanian,Română,ro',
79
- 'ru' => 'Russian,Русский,ru',
80
- 'sr' => 'Serbian,српски језик,rs',
81
- 'sk' => 'Slovak,slovenčina,sk',
82
- 'sl' => 'Slovene,slovenščina,sl', //slovenian
83
- 'es' => 'Spanish,Español,es',
84
- 'sw' => 'Swahili,Kiswahili,ke',
85
- 'sv' => 'Swedish,svenska,se',
86
- 'tl' => 'Tagalog,Tagalog,ph', // fhilipino
87
- 'th' => 'Thai,ภาษาไทย,th',
88
- 'tr' => 'Turkish,Türkçe,tr',
89
- 'uk' => 'Ukrainian,Українська,ua',
90
- 'ur' => 'Urdu,اردو,pk',
91
- 'vi' => 'Vietnamese,Tiếng Việt,vn',
92
- 'cy' => 'Welsh,Cymraeg,wales',
93
- 'yi' => 'Yiddish,ייִדיש,europeanunion'
94
  );
95
  //Language which are read from right to left (rtl)
96
  public static $rtl_languages = array('ar', 'he', 'fa', 'ur', 'yi');
@@ -112,7 +120,7 @@ class transposh_consts {
112
  define('TRANSLATOR', 'translator');
113
 
114
  //Define for transposh plugin version
115
- define('TRANSPOSH_PLUGIN_VER', '0.6.2');
116
 
117
  //Define segment id prefix, will be included in span tag. also used as class identifier
118
  define('SPAN_PREFIX', 'tr_');
@@ -318,4 +326,42 @@ define('TRANSPOSH_DIR_WIDGETS', 'widgets');
318
  zu Zulu isiZulu
319
 
320
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  ?>
1
  <?php
2
 
3
  /*
4
+ * Transposh v0.6.3
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
12
  */
13
 
14
  //Language indicator in URL. i.e. lang=en
17
  //Edit mode indicator in URL. i.e. lang=en&edit=true
18
  define('EDIT_PARAM', 'edit');
19
 
20
+ //Enable in memory cache usage, APC, xcache
21
+ define('TP_ENABLE_CACHE', TRUE);
22
+ //What is the cache items TTL
23
+ define('TP_CACHE_TTL', 3600);
24
 
25
  //Class marking a section not be translated.
26
  define('NO_TRANSLATE_CLASS', 'no_translate');
27
  define('NO_TRANSLATE_CLASS_GOOGLE', 'notranslate');
28
  define('ONLY_THISLANGUAGE_CLASS', 'only_thislanguage');
29
 
30
+ //Get text breakers
31
+ define('TP_GTXT_BRK', chr(1)); // Gettext breaker
32
+ define('TP_GTXT_IBRK', chr(2)); // Gettext inner breaker (around %s)
33
+ define('TP_GTXT_BRK_CLOSER', chr(3)); // Gettext breaker closer
34
+ define('TP_GTXT_IBRK_CLOSER', chr(4)); // Gettext inner breaker closer
35
+
36
  /**
37
  * Holds our arrays staticly to reduce chance of namespace collision
38
  */
41
  //Supported languages, new languages can be added here
42
  //the array directs from language code to - English Name, Native name, flag
43
  public static $languages = array(
44
+ 'en' => 'English,English,us,en_US',
45
+ 'af' => 'Afrikaans,Afrikaans,za,',
46
+ 'sq' => 'Albanian,Shqip,al,',
47
+ 'ar' => 'Arabic,العربية,sa,',
48
+ 'hy' => 'Armenian,Հայերեն,am,',
49
+ 'az' => 'Azerbaijani,azərbaycan dili,az,',
50
+ 'eu' => 'Basque,euskara,basque,',
51
+ 'be' => 'Belarusian,Беларуская,by,',
52
+ 'bg' => 'Bulgarian,Български,bg,bg_BG',
53
+ 'ca' => 'Catalan,Català,catalonia,',
54
+ 'zh' => 'Chinese (Simplified),中文(简体),cn,zh_CN',
55
+ 'zh-tw' => 'Chinese (Traditional),中文(漢字),tw,zh_TW',
56
+ 'hr' => 'Croatian,Hrvatski,hr,',
57
+ 'cs' => 'Czech,čeština,cz,cs_CZ',
58
+ 'da' => 'Danish,dansk,dk,da_DK',
59
+ 'nl' => 'Dutch,Nederlands,nl,',
60
+ 'et' => 'Estonian,Eesti keel,ee,',
61
+ 'fi' => 'Finnish,Suomi,fi,',
62
+ 'fr' => 'French,Français,fr,fr_FR',
63
+ 'gl' => 'Galician,Galego,galicia,gl_ES',
64
+ 'ka' => 'Georgian,ქართული,ge,ka_GE',
65
+ 'de' => 'German,Deutsch,de,de_DE',
66
+ 'el' => 'Greek,Ελληνικά,gr,',
67
+ 'ht' => 'Haitian,Kreyòl ayisyen,ht,',
68
+ 'he' => 'Hebrew,עברית,il,he_IL',
69
+ 'hi' => 'Hindi,हिन्दी; हिंदी,in,hi_IN',
70
+ 'hu' => 'Hungarian,magyar,hu,hu_HU',
71
+ 'is' => 'Icelandic,íslenska,is,',
72
+ 'id' => 'Indonesian,Bahasa Indonesia,id,id_ID',
73
+ 'ga' => 'Irish,Gaeilge,ie,',
74
+ 'it' => 'Italian,Italiano,it,it_IT',
75
+ 'ja' => 'Japanese,日本語,jp,',
76
+ 'ko' => 'Korean,우리말,kr,ko_KR',
77
+ 'lv' => 'Latvian,latviešu valoda,lv,',
78
+ 'lt' => 'Lithuanian,lietuvių kalba,lt,',
79
+ 'mk' => 'Macedonian,македонски јазик,mk,mk_MK',
80
+ 'ms' => 'Malay,bahasa Melayu,my,ms_MY',
81
+ 'mt' => 'Maltese,Malti,mt,',
82
+ 'no' => 'Norwegian,Norsk,no,nb_NO',
83
+ 'fa' => 'Persian,فارسی,ir,fa_IR',
84
+ 'pl' => 'Polish,Polski,pl,pl_PL',
85
+ 'pt' => 'Portuguese,Português,pt,pt_PT',
86
+ 'ro' => 'Romanian,Română,ro,ro_RO',
87
+ 'ru' => 'Russian,Русский,ru,ru_RU',
88
+ 'sr' => 'Serbian,српски језик,rs,sr_RS',
89
+ 'sk' => 'Slovak,slovenčina,sk,sk_SK',
90
+ 'sl' => 'Slovene,slovenščina,sl,sl_SI', //slovenian
91
+ 'es' => 'Spanish,Español,es,es_ES',
92
+ 'sw' => 'Swahili,Kiswahili,ke,',
93
+ 'sv' => 'Swedish,svenska,se,sv_SE',
94
+ 'tl' => 'Tagalog,Tagalog,ph,', // fhilipino
95
+ 'th' => 'Thai,ภาษาไทย,th,',
96
+ 'tr' => 'Turkish,Türkçe,tr,tr_TR',
97
+ 'uk' => 'Ukrainian,Українська,ua,',
98
+ 'ur' => 'Urdu,اردو,pk,',
99
+ 'vi' => 'Vietnamese,Tiếng Việt,vn,',
100
+ 'cy' => 'Welsh,Cymraeg,wales,',
101
+ 'yi' => 'Yiddish,ייִדיש,europeanunion,'
102
  );
103
  //Language which are read from right to left (rtl)
104
  public static $rtl_languages = array('ar', 'he', 'fa', 'ur', 'yi');
120
  define('TRANSLATOR', 'translator');
121
 
122
  //Define for transposh plugin version
123
+ define('TRANSPOSH_PLUGIN_VER', '0.6.3');
124
 
125
  //Define segment id prefix, will be included in span tag. also used as class identifier
126
  define('SPAN_PREFIX', 'tr_');
326
  zu Zulu isiZulu
327
 
328
  */
329
+
330
+ /* List of unused wordpress locales (27-Aug-2010)
331
+ # bn_BD/ Bengali
332
+ # bs_BA/ Bosnian
333
+ # ckb/ Kurdish
334
+ # cpp/ ??
335
+ # el/
336
+ # eo/ esperanto
337
+ # es_CL/
338
+ # es_PE/
339
+ # es_VE/
340
+ # fo/ foroese
341
+ # fr_BE/
342
+ # fy/
343
+ # jv_ID/
344
+ # /
345
+ # kea/ ??
346
+ # kn/
347
+ # /
348
+ # ky_KY/
349
+ # ml_IN/
350
+ # mn/
351
+ # my_MM/
352
+ # nb_NO/ ? good Question, popped into Norway
353
+ # ne_NP/
354
+ # nn_NO/ ? same question
355
+ # pa_IN/
356
+ # pt_BR/
357
+ # ru_UA/
358
+ # sd_PK/
359
+ # si_LK/
360
+ # su_ID/
361
+ # ta_IN/
362
+ # ug_CN/
363
+ # uz_UZ/
364
+ # zh_HK/
365
+ */
366
+
367
  ?>
core/parser.php CHANGED
@@ -1,19 +1,20 @@
1
  <?php
2
 
3
  /*
4
- * Transposh v0.6.2
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
12
  */
13
 
14
  require_once("shd/simple_html_dom.php");
15
  require_once("constants.php");
16
 
 
17
 
18
  /**
19
  * parserstats class - holds parser statistics
@@ -88,7 +89,8 @@ class parser {
88
  public $url_rewrite_func = null;
89
  public $fetch_translate_func = null;
90
  public $prefetch_translate_func = null;
91
- private $segment_id = 0;
 
92
  /** @var simple_html_dom_node Contains the current node */
93
  private $currentnode;
94
  /** @var simple_html_dom Contains the document dom model */
@@ -111,6 +113,10 @@ class parser {
111
  protected $ignore_tags = array('script' => 1, 'style' => 1, 'code' => 1, 'wfw:commentrss' => 1, 'comments' => 1, 'guid' => 1);
112
  /** @var parserstats Contains parsing statistics */
113
  private $stats;
 
 
 
 
114
 
115
  /**
116
  * Determine if the current position in buffer is a white space.
@@ -261,7 +267,7 @@ class parser {
261
  return 3;
262
  //·
263
  if (ord($char) == 194 && ord($nextchar) == 183) return 2;
264
- return (strpos(',?()[]"!:|;', $char) !== false) ? 1 : 0; // TODO: might need to add < and > here
265
  }
266
 
267
  /**
@@ -269,7 +275,7 @@ class parser {
269
  * @return int length of number.
270
  */
271
  function is_number($page, $position) {
272
- return strspn($page, '0123456789-+$%,.\\/', $position);
273
  }
274
 
275
  /**
@@ -279,6 +285,13 @@ class parser {
279
  */
280
  function tag_phrase($string, $start, $end) {
281
  $phrase = trim(substr($string, $start, $end - $start));
 
 
 
 
 
 
 
282
  if ($phrase) {
283
 
284
  $node = new simple_html_dom_node($this->html);
@@ -287,6 +300,8 @@ class parser {
287
  $this->currentnode->nodes[] = $node;
288
  $node->_[HDOM_INFO_OUTER] = '';
289
  $node->phrase = $phrase;
 
 
290
  if ($this->inbody) $node->inbody = $this->inbody;
291
  if ($this->inselect) $node->inselect = true;
292
  }
@@ -328,9 +343,32 @@ class parser {
328
  $pos++;
329
  $pos++;
330
  $start = $pos;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
  }
332
  // will break translation unit when there's a breaker ",.[]()..."
333
  elseif ($senb_len = $this->is_sentence_breaker($string[$pos], $string[$pos + 1], $string[$pos + 2])) {
 
334
  $this->tag_phrase($string, $start, $pos);
335
  $pos += $senb_len;
336
  $start = $pos;
@@ -338,23 +376,31 @@ class parser {
338
  // Numbers also break, if they are followed by whitespace (or a sentence breaker) (don't break 42nd) // TODO: probably by breaking entities too...
339
  // also prefixed by whitespace?
340
  elseif ($num_len = $this->is_number($string, $pos)) {
 
341
  // this is the case of B2 or B2,
342
  if (($this->is_white_space($string[$pos - 1]) || ($start == $pos)
343
  || ($this->is_sentence_breaker($string[$pos + $num_len - 1], $string[$pos + $num_len], $string[$pos + $num_len + 1]))) &&
344
  ($this->is_white_space($string[$pos + $num_len]) || $this->is_sentence_breaker($string[$pos + $num_len], $string[$pos + $num_len + 1], $string[$pos + $num_len + 2]))) {
345
  // we will now compensate on the number followed by breaker case, if we need to
 
346
  if (!($this->is_white_space($string[$pos - 1]) || ($start == $pos))) {
 
347
  if ($this->is_sentence_breaker($string[$pos + $num_len - 1], $string[$pos + $num_len], $string[$pos + $num_len + 1])) {
 
348
  $num_len--; //this makes the added number shorter by one, and the pos will be at a sentence breaker next so we don't have to compensate
349
  }
350
  $pos += $num_len;
351
  $num_len = 0; // we have already added this
352
  }
353
  $this->tag_phrase($string, $start, $pos);
354
- $start = $pos + $num_len + 1;
355
  }
356
- $pos += $num_len + 1;
 
357
  } else {
 
 
 
358
  $pos++;
359
  }
360
  }
@@ -475,7 +521,7 @@ class parser {
475
  function create_edit_span($original_text, $translated_text, $source, $for_hidden_element = false) {
476
  // Use base64 encoding to make that when the page is translated (i.e. update_translation) we
477
  // get back exactlly the same string without having the client decode/encode it in anyway.
478
- $span = '<span class ="' . SPAN_PREFIX . '" id="' . SPAN_PREFIX . $this->segment_id . '" data-token="' . transposh_utils::base64_url_encode($original_text) . '" data-source="' . $source . '"';
479
  // those are needed for on the fly image creation / hidden elements translations
480
  if ($this->is_edit_mode || $for_hidden_element) {
481
  $span .= ' data-orig="' . $original_text . '"';
@@ -488,7 +534,12 @@ class parser {
488
  }
489
  }
490
  $span .= '>';
491
- ++$this->segment_id;
 
 
 
 
 
492
  return $span;
493
  }
494
 
@@ -519,6 +570,7 @@ class parser {
519
  // create our dom
520
  $this->html = str_get_html($string);
521
  // mark translateable elements
 
522
  $this->translate_tagging($this->html->root);
523
 
524
  // first fix the html tag itself - we might need to to the same for all such attributes with flipping
@@ -570,19 +622,19 @@ class parser {
570
  if ($this->prefetch_translate_func != null) {
571
  foreach ($this->html->find('text') as $e) {
572
  foreach ($e->nodes as $ep) {
573
- $originals[] = $ep->phrase;
574
  }
575
  }
576
  foreach (array('title', 'value') as $title) {
577
  foreach ($this->html->find('[' . $title . ']') as $e) {
578
  foreach ($e->nodes as $ep) {
579
- $originals[] = $ep->phrase;
580
  }
581
  }
582
  }
583
  foreach ($this->html->find('[content]') as $e) {
584
  foreach ($e->nodes as $ep) {
585
- $originals[] = $ep->phrase;
586
  }
587
  }
588
  call_user_func_array($this->prefetch_translate_func, array($originals, $this->lang));
@@ -591,10 +643,9 @@ class parser {
591
  // actually translate tags
592
  // texts are first
593
  foreach ($this->html->find('text') as $e) {
594
- $right = '';
595
- $newtext = '';
596
  foreach ($e->nodes as $ep) {
597
- list ($translated_text, $source) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang));
598
  //stats
599
  $this->stats->total_phrases++;
600
  if ($translated_text) {
@@ -602,32 +653,23 @@ class parser {
602
  if ($source == 0) $this->stats->human_translated_phrases++;
603
  }
604
  if (($this->is_edit_mode || ($this->is_auto_translate && $translated_text == null))/* && $ep->inbody */) {
605
- $spanend = '</span>';
606
  if ($ep->inselect || !$ep->inbody) {
607
- $savedspan .= $this->create_edit_span($ep->phrase, $translated_text, $source, true) . $spanend;
608
- $span = '';
609
- $spanend = '';
610
  } else {
611
- $span = $this->create_edit_span($ep->phrase, $translated_text, $source);
612
- if ($translated_text == null)
613
- $translated_text = $ep->phrase;
614
  }
615
  }
616
- else {
617
- $span = '';
618
- $spanend = '';
619
- }
620
  if ($translated_text) {
621
- list ($left, $right) = explode($ep->phrase, $e->outertext, 2);
622
- $newtext .= $left . $span . $translated_text . $spanend;
623
- $e->outertext = $right;
624
  }
625
  }
626
- if ($newtext) {
627
- $e->outertext = $newtext . $right;
628
-
629
  }
630
- // hmm?
 
631
  if (!$ep->inselect && $savedspan && $ep->inbody) {
632
  $e->outertext = $savedspan . $e->outertext;
633
  $savedspan = '';
@@ -635,13 +677,11 @@ class parser {
635
  }
636
 
637
  // now we handle the title attributes (and the value of submit buttons)
 
638
  foreach (array('title', 'value') as $title) {
639
- $hidden_phrases = array();
640
  foreach ($this->html->find('[' . $title . ']') as $e) {
 
641
  $span = '';
642
- $spanend = '';
643
- $right = '';
644
- $newtext = '';
645
  // when we already have a parent outertext we'll have to update it directly
646
  if ($e->parent->_[HDOM_INFO_OUTER]) {
647
  $saved_outertext = $e->outertext;
@@ -649,7 +689,7 @@ class parser {
649
 
650
  foreach ($e->nodes as $ep) {
651
  if ($ep->tag == 'phrase') {
652
- list ($translated_text, $source) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang));
653
  // more stats
654
  $this->stats->total_phrases++;
655
  if ($ep->inbody) $this->stats->hidden_phrases++; else
@@ -668,22 +708,21 @@ class parser {
668
  //no need to translate span the same hidden phrase more than once
669
  if (!in_array($ep->phrase, $hidden_phrases)) {
670
  $this->stats->hidden_translateable_phrases++;
671
- $span .= $this->create_edit_span($ep->phrase, $translated_text, $source, true) . '</span>';
672
  //
673
  $hidden_phrases[] = $ep->phrase;
674
  }
675
  }
676
  }
 
677
  if ($translated_text) {
678
- list ($left, $right) = explode($ep->phrase, $e->$title, 2);
679
- $newtext .= $left . $translated_text;
680
- $e->$title = $right;
681
  }
682
  }
683
  }
684
- if ($newtext) {
685
- $e->$title = $newtext . $right;
686
-
687
  }
688
 
689
  $e->outertext .= $span;
@@ -705,7 +744,7 @@ class parser {
705
  // even more stats
706
  $this->stats->total_phrases++;
707
  $this->stats->meta_phrases++;
708
- list ($translated_text, $source) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang));
709
  if ($translated_text) {
710
  $this->stats->translated_phrases++;
711
  $this->stats->meta_translated_phrases++;
@@ -732,9 +771,11 @@ class parser {
732
  if ($head != null)
733
  $head->lastChild()->outertext .= "\n<meta name=\"translation-stats\" content='" . json_encode($this->stats) . "'/>";
734
 
 
 
735
  // Changed because of places where tostring failed
736
  //return $this->html;
737
- return $this->html->outertext;
738
  }
739
 
740
  /**
@@ -758,4 +799,5 @@ class parser {
758
  }
759
 
760
  }
 
761
  ?>
1
  <?php
2
 
3
  /*
4
+ * Transposh v0.6.3
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
12
  */
13
 
14
  require_once("shd/simple_html_dom.php");
15
  require_once("constants.php");
16
 
17
+ require_once("utils.php");
18
 
19
  /**
20
  * parserstats class - holds parser statistics
89
  public $url_rewrite_func = null;
90
  public $fetch_translate_func = null;
91
  public $prefetch_translate_func = null;
92
+ /** @var int stores the number of the last used span_id */
93
+ private $span_id = 0;
94
  /** @var simple_html_dom_node Contains the current node */
95
  private $currentnode;
96
  /** @var simple_html_dom Contains the document dom model */
113
  protected $ignore_tags = array('script' => 1, 'style' => 1, 'code' => 1, 'wfw:commentrss' => 1, 'comments' => 1, 'guid' => 1);
114
  /** @var parserstats Contains parsing statistics */
115
  private $stats;
116
+ /** @var boolean Are we inside a translated gettext */
117
+ private $in_get_text = false;
118
+ /** @var boolean Are we inside an inner text %s in gettext */
119
+ private $in_get_text_inner = false;
120
 
121
  /**
122
  * Determine if the current position in buffer is a white space.
267
  return 3;
268
  //·
269
  if (ord($char) == 194 && ord($nextchar) == 183) return 2;
270
+ return (strpos(',?()[]"!:|;'.TP_GTXT_BRK.TP_GTXT_BRK_CLOSER.TP_GTXT_IBRK.TP_GTXT_IBRK_CLOSER, $char) !== false) ? 1 : 0; // TODO: might need to add < and > here
271
  }
272
 
273
  /**
275
  * @return int length of number.
276
  */
277
  function is_number($page, $position) {
278
+ return strspn($page, '0123456789-+$%#*,.\\/', $position);
279
  }
280
 
281
  /**
285
  */
286
  function tag_phrase($string, $start, $end) {
287
  $phrase = trim(substr($string, $start, $end - $start));
288
+ // $logstr = str_replace(array(chr(1),chr(2),chr(3),chr(4)), array('[1]','[2]','[3]','[4]'), $string);
289
+ //
290
+ //
291
+ if ($this->in_get_text > $this->in_get_text_inner) {
292
+
293
+ return;
294
+ }
295
  if ($phrase) {
296
 
297
  $node = new simple_html_dom_node($this->html);
300
  $this->currentnode->nodes[] = $node;
301
  $node->_[HDOM_INFO_OUTER] = '';
302
  $node->phrase = $phrase;
303
+ $node->start = $start;
304
+ $node->len = strlen($phrase);
305
  if ($this->inbody) $node->inbody = $this->inbody;
306
  if ($this->inselect) $node->inselect = true;
307
  }
343
  $pos++;
344
  $pos++;
345
  $start = $pos;
346
+ } elseif ($string[$pos] == TP_GTXT_BRK || $string[$pos] == TP_GTXT_BRK_CLOSER) {
347
+ // $logstr = str_replace(array(chr(1),chr(2),chr(3),chr(4)), array('[1]','[2]','[3]','[4]'), $string);
348
+ // $closers = ($string[$pos] == TP_GTXT_BRK) ? '': 'closer';
349
+ //
350
+ $this->tag_phrase($string, $start, $pos);
351
+ ($string[$pos] == TP_GTXT_BRK) ? $this->in_get_text += 1: $this->in_get_text -= 1;
352
+ $pos++;
353
+ $start = $pos;
354
+ // reset state based on string start, no need to flip
355
+ //$this->in_get_text = ($pos == 1);
356
+ //if (!$this->in_get_text) $this->in_get_text_inner = false;
357
+ } elseif ($string[$pos] == TP_GTXT_IBRK || $string[$pos] == TP_GTXT_IBRK_CLOSER ) {
358
+ // $logstr = str_replace(array(chr(1),chr(2),chr(3),chr(4)), array('[1]','[2]','[3]','[4]'), $string);
359
+ // $closers = ($string[$pos] == TP_GTXT_IBRK) ? '': 'closer';
360
+ //
361
+ //
362
+ $this->tag_phrase($string, $start, $pos);
363
+ if ($this->in_get_text)
364
+ ($string[$pos] == TP_GTXT_IBRK) ? $this->in_get_text_inner += 1 : $this->in_get_text_inner -=1;
365
+ $pos++;
366
+ $start = $pos;
367
+ //$this->in_get_text_inner = !$this->in_get_text_inner;
368
  }
369
  // will break translation unit when there's a breaker ",.[]()..."
370
  elseif ($senb_len = $this->is_sentence_breaker($string[$pos], $string[$pos + 1], $string[$pos + 2])) {
371
+ //
372
  $this->tag_phrase($string, $start, $pos);
373
  $pos += $senb_len;
374
  $start = $pos;
376
  // Numbers also break, if they are followed by whitespace (or a sentence breaker) (don't break 42nd) // TODO: probably by breaking entities too...
377
  // also prefixed by whitespace?
378
  elseif ($num_len = $this->is_number($string, $pos)) {
379
+ //
380
  // this is the case of B2 or B2,
381
  if (($this->is_white_space($string[$pos - 1]) || ($start == $pos)
382
  || ($this->is_sentence_breaker($string[$pos + $num_len - 1], $string[$pos + $num_len], $string[$pos + $num_len + 1]))) &&
383
  ($this->is_white_space($string[$pos + $num_len]) || $this->is_sentence_breaker($string[$pos + $num_len], $string[$pos + $num_len + 1], $string[$pos + $num_len + 2]))) {
384
  // we will now compensate on the number followed by breaker case, if we need to
385
+ //
386
  if (!($this->is_white_space($string[$pos - 1]) || ($start == $pos))) {
387
+ //
388
  if ($this->is_sentence_breaker($string[$pos + $num_len - 1], $string[$pos + $num_len], $string[$pos + $num_len + 1])) {
389
+ //
390
  $num_len--; //this makes the added number shorter by one, and the pos will be at a sentence breaker next so we don't have to compensate
391
  }
392
  $pos += $num_len;
393
  $num_len = 0; // we have already added this
394
  }
395
  $this->tag_phrase($string, $start, $pos);
396
+ $start = $pos + $num_len /*+1*/;
397
  }
398
+ $pos += $num_len/* + 1*/;
399
+ //
400
  } else {
401
+ // smarter marking of start location
402
+ if ($start == $pos && $this->is_white_space($string[$pos]))
403
+ $start++;
404
  $pos++;
405
  }
406
  }
521
  function create_edit_span($original_text, $translated_text, $source, $for_hidden_element = false) {
522
  // Use base64 encoding to make that when the page is translated (i.e. update_translation) we
523
  // get back exactlly the same string without having the client decode/encode it in anyway.
524
+ $span = '<span class ="' . SPAN_PREFIX . '" id="' . SPAN_PREFIX . $this->span_id . '" data-token="' . transposh_utils::base64_url_encode($original_text) . '" data-source="' . $source . '"';
525
  // those are needed for on the fly image creation / hidden elements translations
526
  if ($this->is_edit_mode || $for_hidden_element) {
527
  $span .= ' data-orig="' . $original_text . '"';
534
  }
535
  }
536
  $span .= '>';
537
+ if (!$for_hidden_element) {
538
+ if ($translated_text) $span .= $translated_text;
539
+ else $span .= $original_text;
540
+ }
541
+ $span .= '</span>';
542
+ ++$this->span_id;
543
  return $span;
544
  }
545
 
570
  // create our dom
571
  $this->html = str_get_html($string);
572
  // mark translateable elements
573
+ $this->html->find('html', 0)->lang = ''; // Document defined lang may be preset to correct lang, but should be ignored TODO: Better?
574
  $this->translate_tagging($this->html->root);
575
 
576
  // first fix the html tag itself - we might need to to the same for all such attributes with flipping
622
  if ($this->prefetch_translate_func != null) {
623
  foreach ($this->html->find('text') as $e) {
624
  foreach ($e->nodes as $ep) {
625
+ if ($ep->phrase) $originals[$ep->phrase] = true;
626
  }
627
  }
628
  foreach (array('title', 'value') as $title) {
629
  foreach ($this->html->find('[' . $title . ']') as $e) {
630
  foreach ($e->nodes as $ep) {
631
+ if ($ep->phrase) $originals[$ep->phrase] = true;
632
  }
633
  }
634
  }
635
  foreach ($this->html->find('[content]') as $e) {
636
  foreach ($e->nodes as $ep) {
637
+ if ($ep->phrase) $originals[$ep->phrase] = true;
638
  }
639
  }
640
  call_user_func_array($this->prefetch_translate_func, array($originals, $this->lang));
643
  // actually translate tags
644
  // texts are first
645
  foreach ($this->html->find('text') as $e) {
646
+ $replace = array();
 
647
  foreach ($e->nodes as $ep) {
648
+ list ($source, $translated_text) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang));
649
  //stats
650
  $this->stats->total_phrases++;
651
  if ($translated_text) {
653
  if ($source == 0) $this->stats->human_translated_phrases++;
654
  }
655
  if (($this->is_edit_mode || ($this->is_auto_translate && $translated_text == null))/* && $ep->inbody */) {
 
656
  if ($ep->inselect || !$ep->inbody) {
657
+ $savedspan .= $this->create_edit_span($ep->phrase, $translated_text, $source, true);
 
 
658
  } else {
659
+ $translated_text = $this->create_edit_span($ep->phrase, $translated_text, $source);
 
 
660
  }
661
  }
662
+ // store replacements
 
 
 
663
  if ($translated_text) {
664
+ $replace[$translated_text] = $ep;
 
 
665
  }
666
  }
667
+ // do replacements in reverse
668
+ foreach (array_reverse($replace, true) as $replace => $epg) {
669
+ $e->outertext = substr_replace($e->outertext, $replace, $epg->start, $epg->len);
670
  }
671
+
672
+ // this adds saved spans to the first not in select element which is in the body
673
  if (!$ep->inselect && $savedspan && $ep->inbody) {
674
  $e->outertext = $savedspan . $e->outertext;
675
  $savedspan = '';
677
  }
678
 
679
  // now we handle the title attributes (and the value of submit buttons)
680
+ $hidden_phrases = array();
681
  foreach (array('title', 'value') as $title) {
 
682
  foreach ($this->html->find('[' . $title . ']') as $e) {
683
+ $replace = array();
684
  $span = '';
 
 
 
685
  // when we already have a parent outertext we'll have to update it directly
686
  if ($e->parent->_[HDOM_INFO_OUTER]) {
687
  $saved_outertext = $e->outertext;
689
 
690
  foreach ($e->nodes as $ep) {
691
  if ($ep->tag == 'phrase') {
692
+ list ($source, $translated_text) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang));
693
  // more stats
694
  $this->stats->total_phrases++;
695
  if ($ep->inbody) $this->stats->hidden_phrases++; else
708
  //no need to translate span the same hidden phrase more than once
709
  if (!in_array($ep->phrase, $hidden_phrases)) {
710
  $this->stats->hidden_translateable_phrases++;
711
+ $span .= $this->create_edit_span($ep->phrase, $translated_text, $source, true);
712
  //
713
  $hidden_phrases[] = $ep->phrase;
714
  }
715
  }
716
  }
717
+ // if we need to replace, we store this
718
  if ($translated_text) {
719
+ $replace[$translated_text] = $ep;
 
 
720
  }
721
  }
722
  }
723
+ // and later replace
724
+ foreach (array_reverse($replace, true) as $replace => $epg) {
725
+ $e->title = substr_replace($e->title, $replace, $epg->start, $epg->len);
726
  }
727
 
728
  $e->outertext .= $span;
744
  // even more stats
745
  $this->stats->total_phrases++;
746
  $this->stats->meta_phrases++;
747
+ list ($source, $translated_text) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang));
748
  if ($translated_text) {
749
  $this->stats->translated_phrases++;
750
  $this->stats->meta_translated_phrases++;
771
  if ($head != null)
772
  $head->lastChild()->outertext .= "\n<meta name=\"translation-stats\" content='" . json_encode($this->stats) . "'/>";
773
 
774
+ // we make sure that the result is clear from our shananigans
775
+ return str_replace(array(TP_GTXT_BRK, TP_GTXT_IBRK, TP_GTXT_BRK_CLOSER, TP_GTXT_IBRK_CLOSER), '', $this->html->outertext);
776
  // Changed because of places where tostring failed
777
  //return $this->html;
778
+ //return $this->html->outertext;
779
  }
780
 
781
  /**
799
  }
800
 
801
  }
802
+
803
  ?>
core/utils.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
 
3
  /*
4
- * Transposh v0.6.2
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
12
  */
13
 
14
  /**
@@ -46,6 +46,7 @@ class transposh_utils {
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
  $home_path = rtrim(parse_url($home_url, PHP_URL_PATH), "/");
@@ -108,6 +109,7 @@ class transposh_utils {
108
  unset($parsedurl['query']);
109
 
110
  // remove the language from the url permalink (if in start of path, and is a defined language)
 
111
  $home_path = rtrim(parse_url($home_url, PHP_URL_PATH), "/");
112
 
113
  if ($home_path && strpos($parsedurl['path'], $home_path) === 0) {
@@ -132,7 +134,7 @@ class transposh_utils {
132
 
133
  //$params ="";
134
  if ($is_edit) {
135
- $params[edit] = EDIT_PARAM . '=1';
136
  }
137
 
138
  if ($use_params_only && $lang) {
@@ -250,6 +252,8 @@ class transposh_utils {
250
  * @return string translated url permalink
251
  */
252
  public static function translate_url($href, $home_url, $target_language, $fetch_translation_func) {
 
 
253
  // todo - check query part... sanitize
254
  if (strpos($href, '?') !== false) {
255
  list ($href, $querypart) = explode('?', $href);
@@ -259,12 +263,12 @@ class transposh_utils {
259
  $parts = explode('/', $href);
260
  foreach ($parts as $part) {
261
  if (!$part) continue;
262
- list($translated_text, $old_source) = call_user_func_array($fetch_translation_func, array($part, $target_language));
263
  if ($translated_text)
264
  $url .= '/' . str_replace(' ', '-', $translated_text);
265
  else {
266
  // now the same attempt with '-' replaced to ' '
267
- list($translated_text, $old_source) = call_user_func_array($fetch_translation_func, array(str_replace('-', ' ', $part), $target_language));
268
  //
269
  if ($translated_text)
270
  $url .= '/' . str_replace(' ', '-', $translated_text);
@@ -287,6 +291,7 @@ class transposh_utils {
287
  $href = substr($href, strlen($home_url));
288
  $url = urldecode($href);
289
  $url = (($pos = strpos($url, '?')) ? substr($url, 0, $pos) : $url);
 
290
  $parts = explode('/', $url);
291
  foreach ($parts as $part) {
292
  if (!$part) continue;
1
  <?php
2
 
3
  /*
4
+ * Transposh v0.6.3
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
12
  */
13
 
14
  /**
46
  $parsedurl['query'] = implode('&', $params);
47
  }
48
 
49
+ $gluebackhome = false;
50
  //cleanup lang identifier in permalinks
51
  //remove the language from the url permalink (if in start of path, and is a defined language)
52
  $home_path = rtrim(parse_url($home_url, PHP_URL_PATH), "/");
109
  unset($parsedurl['query']);
110
 
111
  // remove the language from the url permalink (if in start of path, and is a defined language)
112
+ $gluebackhome = false;
113
  $home_path = rtrim(parse_url($home_url, PHP_URL_PATH), "/");
114
 
115
  if ($home_path && strpos($parsedurl['path'], $home_path) === 0) {
134
 
135
  //$params ="";
136
  if ($is_edit) {
137
+ $params['edit'] = EDIT_PARAM . '=1';
138
  }
139
 
140
  if ($use_params_only && $lang) {
252
  * @return string translated url permalink
253
  */
254
  public static function translate_url($href, $home_url, $target_language, $fetch_translation_func) {
255
+ $url='';
256
+ $querypart='';
257
  // todo - check query part... sanitize
258
  if (strpos($href, '?') !== false) {
259
  list ($href, $querypart) = explode('?', $href);
263
  $parts = explode('/', $href);
264
  foreach ($parts as $part) {
265
  if (!$part) continue;
266
+ list($source, $translated_text) = call_user_func_array($fetch_translation_func, array($part, $target_language));
267
  if ($translated_text)
268
  $url .= '/' . str_replace(' ', '-', $translated_text);
269
  else {
270
  // now the same attempt with '-' replaced to ' '
271
+ list($source, $translated_text) = call_user_func_array($fetch_translation_func, array(str_replace('-', ' ', $part), $target_language));
272
  //
273
  if ($translated_text)
274
  $url .= '/' . str_replace(' ', '-', $translated_text);
291
  $href = substr($href, strlen($home_url));
292
  $url = urldecode($href);
293
  $url = (($pos = strpos($url, '?')) ? substr($url, 0, $pos) : $url);
294
+ $url2 ='';
295
  $parts = explode('/', $url);
296
  foreach ($parts as $part) {
297
  if (!$part) continue;
js/lazy.js CHANGED
@@ -1,12 +1,12 @@
1
  /*
2
- * Transposh v0.6.2
3
  * http://transposh.org/
4
  *
5
  * Copyright 2010, Team Transposh
6
  * Licensed under the GPL Version 2 or higher.
7
  * http://transposh.org/license
8
  *
9
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
10
  */
11
  (function(b){function s(){function h(a,c){t[a](c,function(d){d=="error"?i.push(c):k.push(c)&&g.each(c);o()},"lazy-loaded-"+(g.name?g.name:(new Date).getTime()))}function j(a){g.complete(a,k,i);g[a](a=="error"?i:k);clearTimeout(p);clearTimeout(u)}function o(){if(k.length==l.length)j("success");else k.length+i.length==l.length&&j("error")}function q(){i.push(this.src);o()}var t=this,g,k=[],i=[],p,u,n,l=[];this.init=function(a){if(a){g=b.extend({},b.xLazyLoader.defaults,a);n={js:g.js,css:g.css,img:g.img};
12
  b.each(n,function(c,d){if(typeof d=="string")d=d.split(",");l=l.concat(d)});if(l.length){if(g.timeout)p=setTimeout(function(){var c=k.concat(i);b.each(l,function(d,f){b.inArray(f,c)==-1&&i.push(f)});j("error")},g.timeout);b.each(n,function(c,d){if(b.isArray(d))b.each(d,function(f,e){h(c,e)});else typeof d=="string"&&h(c,d)})}else j("error")}};this.js=function(a,c,d){var f=b('script[src*="'+a+'"]');if(f.length)f.attr("pending")?f.bind("scriptload",c):c();else{var e=document.createElement("script");
1
  /*
2
+ * Transposh v0.6.3
3
  * http://transposh.org/
4
  *
5
  * Copyright 2010, Team Transposh
6
  * Licensed under the GPL Version 2 or higher.
7
  * http://transposh.org/license
8
  *
9
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
10
  */
11
  (function(b){function s(){function h(a,c){t[a](c,function(d){d=="error"?i.push(c):k.push(c)&&g.each(c);o()},"lazy-loaded-"+(g.name?g.name:(new Date).getTime()))}function j(a){g.complete(a,k,i);g[a](a=="error"?i:k);clearTimeout(p);clearTimeout(u)}function o(){if(k.length==l.length)j("success");else k.length+i.length==l.length&&j("error")}function q(){i.push(this.src);o()}var t=this,g,k=[],i=[],p,u,n,l=[];this.init=function(a){if(a){g=b.extend({},b.xLazyLoader.defaults,a);n={js:g.js,css:g.css,img:g.img};
12
  b.each(n,function(c,d){if(typeof d=="string")d=d.split(",");l=l.concat(d)});if(l.length){if(g.timeout)p=setTimeout(function(){var c=k.concat(i);b.each(l,function(d,f){b.inArray(f,c)==-1&&i.push(f)});j("error")},g.timeout);b.each(n,function(c,d){if(b.isArray(d))b.each(d,function(f,e){h(c,e)});else typeof d=="string"&&h(c,d)})}else j("error")}};this.js=function(a,c,d){var f=b('script[src*="'+a+'"]');if(f.length)f.attr("pending")?f.bind("scriptload",c):c();else{var e=document.createElement("script");
js/transposh.js CHANGED
@@ -1,16 +1,16 @@
1
  /*
2
- * Transposh v0.6.2
3
  * http://transposh.org/
4
  *
5
  * Copyright 2010, Team Transposh
6
  * Licensed under the GPL Version 2 or higher.
7
  * http://transposh.org/license
8
  *
9
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
10
  */
11
  (function(a){function u(c,d){if(a.trim(d).length!==0){var b=function(){var e=a(this).attr("id").substr(a(this).attr("id").lastIndexOf("_")+1),i=a("#"+f+"img_"+e);a("#"+f+e).attr("data-source",1);i.removeClass("tr-icon-yellow").removeClass("tr-icon-green").addClass("tr-icon-yellow")};a("*[data-token='"+c+"'][data-hidden!='y']").html(d).each(b);a("*[data-token='"+c+"'][data-hidden='y']").attr("data-trans",d).each(b)}}function v(c,d){clearTimeout(o);h.push(c);n.push(d);u(c,d);o=setTimeout(function(){var b=
12
- {ln0:t_jp.lang,sr0:p,translation_posted:"2",items:h.length},e;for(e=0;e<h.length;e+=1){b["tk"+e]=h[e];b["tr"+e]=n[e];q+=a("*[data-token='"+h[e]+"']").size()}a.ajax({type:"POST",url:t_jp.post_url,data:b,success:function(){var i=q/j*100;t_jp.progress&&a("#"+k).progressbar("value",i)}});n=[];h=[]},200)}function l(c,d){v(c,a("<div>"+d+"</div>").text());var b=(j-a("."+f+'[data-source=""]').size())/j*100;t_jp.progress&&a("#"+m).progressbar("value",b)}function w(c,d){var b="";a(c).each(function(e){b+="&q="+
13
- encodeURIComponent(c[e])});a.ajax({url:"http://ajax.googleapis.com/ajax/services/language/translate?v=1.0"+b+"&langpair=%7C"+t_jp.lang,dataType:"jsonp",success:d})}function x(c,d){w(d,function(b){if(b.responseStatus>=200&&b.responseStatus<300)b.responseData.translatedText!==undefined?l(c[0],b.responseData.translatedText):a(b.responseData).each(function(e){this.responseStatus===200&&l(c[e],this.responseData.translatedText)})})}function y(c,d){var b="[";a(c).each(function(e){b+='"'+encodeURIComponent(c[e])+
14
  '",'});b=b.slice(0,-1)+"]";a.ajax({url:"http://api.microsofttranslator.com/V2/Ajax.svc/TranslateArray?appId="+t_jp.MSN_APPID+"&to="+t_jp.binglang+"&texts="+b,dataType:"jsonp",jsonp:"oncomplete",success:d})}function z(c,d){p=2;y(d,function(b){a(b).each(function(e){l(c[e],this.TranslatedText)})})}function A(c,d){a.getJSON(t_jp.post_url+"?tgp="+d+"&tgl="+t_jp.lang,function(b){b.sentences!==undefined&&b.sentences[0].trans&&l(c,b.sentences[0].trans)})}function r(c,d){if(t_jp.msn&&t_jp.preferred==="2")z(c,
15
  d);else if(t_jp.tgp)d[0]&&A(c[0],d[0]);else x(c,d)}function s(){var c=[],d=0,b=[],e=[];if(t_jp.tgp)t=0;a("."+f+'[data-source=""]').each(function(){var i=a(this).attr("data-token"),g=a(this).attr("data-orig");if(g===undefined)g=a(this).html();if(c[g]!==1){c[g]=1;if(d+g.length>t){r(e,b);d=0;b=[];e=[]}d+=g.length;e.push(i);b.push(g)}});r(e,b)}var t=128,j,f=t_jp.prefix,m=f+"pbar",k=m+"_s",p=1,q=0,o,h=[],n=[];t_jp.MSN_APPID="FACA8E2DF8DCCECE0DC311C6E57DA98EFEFA9BC6";a(document).ready(function(){if(t_jp.msn){t_jp.binglang=
16
  t_jp.lang;if(t_jp.binglang==="zh")t_jp.binglang="zh-chs";else if(t_jp.binglang==="zh-tw")t_jp.binglang="zh-cht"}a("#"+f+"setdeflang").click(function(){a.get(t_jp.post_url+"?tr_cookie="+Math.random());a(this).hide("slow");return false});j=a("."+f+'[data-source=""]').size();a.ajaxSetup({cache:true});if(j&&!t_jp.noauto&&(t_jp.google||t_jp.msn||t_jp.tgp))if(t_jp.progress){var c=function(){a.xLazyLoader({js:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js",css:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/ui-lightness/jquery-ui.css",
1
  /*
2
+ * Transposh v0.6.3
3
  * http://transposh.org/
4
  *
5
  * Copyright 2010, Team Transposh
6
  * Licensed under the GPL Version 2 or higher.
7
  * http://transposh.org/license
8
  *
9
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
10
  */
11
  (function(a){function u(c,d){if(a.trim(d).length!==0){var b=function(){var e=a(this).attr("id").substr(a(this).attr("id").lastIndexOf("_")+1),i=a("#"+f+"img_"+e);a("#"+f+e).attr("data-source",1);i.removeClass("tr-icon-yellow").removeClass("tr-icon-green").addClass("tr-icon-yellow")};a("*[data-token='"+c+"'][data-hidden!='y']").html(d).each(b);a("*[data-token='"+c+"'][data-hidden='y']").attr("data-trans",d).each(b)}}function v(c,d){clearTimeout(o);h.push(c);n.push(d);u(c,d);o=setTimeout(function(){var b=
12
+ {ln0:t_jp.lang,sr0:p,translation_posted:"2",items:h.length},e;for(e=0;e<h.length;e+=1){b["tk"+e]=h[e];b["tr"+e]=n[e];q+=a("*[data-token='"+h[e]+"']").size()}a.ajax({type:"POST",url:t_jp.post_url,data:b,success:function(){var i=q/j*100;t_jp.progress&&a("#"+k).progressbar("value",i)}});n=[];h=[]},200)}function l(c,d){v(c,a("<div>"+a.trim(d)+"</div>").text());var b=(j-a("."+f+'[data-source=""]').size())/j*100;t_jp.progress&&a("#"+m).progressbar("value",b)}function w(c,d){var b="";a(c).each(function(e){b+=
13
+ "&q="+encodeURIComponent(c[e])});a.ajax({url:"http://ajax.googleapis.com/ajax/services/language/translate?v=1.0"+b+"&langpair=%7C"+t_jp.lang,dataType:"jsonp",success:d})}function x(c,d){w(d,function(b){if(b.responseStatus>=200&&b.responseStatus<300)b.responseData.translatedText!==undefined?l(c[0],b.responseData.translatedText):a(b.responseData).each(function(e){this.responseStatus===200&&l(c[e],this.responseData.translatedText)})})}function y(c,d){var b="[";a(c).each(function(e){b+='"'+encodeURIComponent(c[e])+
14
  '",'});b=b.slice(0,-1)+"]";a.ajax({url:"http://api.microsofttranslator.com/V2/Ajax.svc/TranslateArray?appId="+t_jp.MSN_APPID+"&to="+t_jp.binglang+"&texts="+b,dataType:"jsonp",jsonp:"oncomplete",success:d})}function z(c,d){p=2;y(d,function(b){a(b).each(function(e){l(c[e],this.TranslatedText)})})}function A(c,d){a.getJSON(t_jp.post_url+"?tgp="+d+"&tgl="+t_jp.lang,function(b){b.sentences!==undefined&&b.sentences[0].trans&&l(c,b.sentences[0].trans)})}function r(c,d){if(t_jp.msn&&t_jp.preferred==="2")z(c,
15
  d);else if(t_jp.tgp)d[0]&&A(c[0],d[0]);else x(c,d)}function s(){var c=[],d=0,b=[],e=[];if(t_jp.tgp)t=0;a("."+f+'[data-source=""]').each(function(){var i=a(this).attr("data-token"),g=a(this).attr("data-orig");if(g===undefined)g=a(this).html();if(c[g]!==1){c[g]=1;if(d+g.length>t){r(e,b);d=0;b=[];e=[]}d+=g.length;e.push(i);b.push(g)}});r(e,b)}var t=128,j,f=t_jp.prefix,m=f+"pbar",k=m+"_s",p=1,q=0,o,h=[],n=[];t_jp.MSN_APPID="FACA8E2DF8DCCECE0DC311C6E57DA98EFEFA9BC6";a(document).ready(function(){if(t_jp.msn){t_jp.binglang=
16
  t_jp.lang;if(t_jp.binglang==="zh")t_jp.binglang="zh-chs";else if(t_jp.binglang==="zh-tw")t_jp.binglang="zh-cht"}a("#"+f+"setdeflang").click(function(){a.get(t_jp.post_url+"?tr_cookie="+Math.random());a(this).hide("slow");return false});j=a("."+f+'[data-source=""]').size();a.ajaxSetup({cache:true});if(j&&!t_jp.noauto&&(t_jp.google||t_jp.msn||t_jp.tgp))if(t_jp.progress){var c=function(){a.xLazyLoader({js:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js",css:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/ui-lightness/jquery-ui.css",
js/transposhadmin.js CHANGED
@@ -1,15 +1,15 @@
1
  /*
2
- * Transposh v0.6.2
3
  * http://transposh.org/
4
  *
5
  * Copyright 2010, Team Transposh
6
  * Licensed under the GPL Version 2 or higher.
7
  * http://transposh.org/license
8
  *
9
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
10
  */
11
  var timer,items=0,translations=[],tokens=[],langs=[],sources=[],BATCH_SIZE=128,pair_count=0,curr_pair=0;t_jp.MSN_APPID="FACA8E2DF8DCCECE0DC311C6E57DA98EFEFA9BC6";function make_progress(e,b){curr_pair+=1;jQuery("#progress_bar").progressbar("value",curr_pair/pair_count*100);jQuery("#p").text("("+b+") "+e);curr_pair===pair_count&&jQuery("#tr_loading").data("done",true)}
12
- function ajax_translate_me(e,b,c,d){b=jQuery("<div>"+b+"</div>").text();make_progress(b,c);clearTimeout(timer);items+=1;tokens.push(e);translations.push(b);langs.push(c);sources.push(d);timer=setTimeout(function(){var f={translation_posted:"2",items:items},a;for(a=0;a<items;a+=1){if(tokens[a]!==tokens[a-1])f["tk"+a]=tokens[a];if(langs[a]!==langs[a-1])f["ln"+a]=langs[a];if(translations[a]!==translations[a-1])f["tr"+a]=translations[a];if(sources[a]!==sources[a-1])f["sr"+a]=sources[a]}jQuery.ajax({type:"POST",
13
  url:t_jp.post_url,data:f,success:function(){},error:function(){}});items=0;translations=[];tokens=[];langs=[];sources=[]},200)}function do_mass_ms_translate(e,b){var c="[";jQuery(e).each(function(d){c+='"'+encodeURIComponent(e[d])+'",'});c=c.slice(0,-1)+"]";jQuery.ajax({url:"http://api.microsofttranslator.com/V2/Ajax.svc/TranslateArray?appId="+t_jp.MSN_APPID+"&to="+t_jp.binglang+"&texts="+c,dataType:"jsonp",jsonp:"oncomplete",success:b})}
14
  function do_mass_ms_invoker(e,b,c){t_jp.binglang=c;if(t_jp.binglang==="zh")t_jp.binglang="zh-chs";else if(t_jp.binglang==="zh-tw")t_jp.binglang="zh-cht";do_mass_ms_translate(b,function(d){jQuery(d).each(function(f){ajax_translate_me(e[f],this.TranslatedText,c,2)})})}function do_mass_google_translate_l(e,b,c){var d="",f;for(f in b)d+="&langpair=%7C"+b[f];jQuery.ajax({url:"http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q="+encodeURIComponent(e)+d,dataType:"jsonp",success:c})}
15
  function do_mass_google_invoker_l(e,b,c){do_mass_google_translate_l(b,c,function(d){if(d.responseStatus===200)d.responseData.translatedText!==undefined?ajax_translate_me(e,d.responseData.translatedText,c[0],1):jQuery(d.responseData).each(function(f){this.responseStatus===200&&ajax_translate_me(e,this.responseData.translatedText,c[f],1)})})}
1
  /*
2
+ * Transposh v0.6.3
3
  * http://transposh.org/
4
  *
5
  * Copyright 2010, Team Transposh
6
  * Licensed under the GPL Version 2 or higher.
7
  * http://transposh.org/license
8
  *
9
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
10
  */
11
  var timer,items=0,translations=[],tokens=[],langs=[],sources=[],BATCH_SIZE=128,pair_count=0,curr_pair=0;t_jp.MSN_APPID="FACA8E2DF8DCCECE0DC311C6E57DA98EFEFA9BC6";function make_progress(e,b){curr_pair+=1;jQuery("#progress_bar").progressbar("value",curr_pair/pair_count*100);jQuery("#p").text("("+b+") "+e);curr_pair===pair_count&&jQuery("#tr_loading").data("done",true)}
12
+ function ajax_translate_me(e,b,c,d){b=jQuery("<div>"+jQuery.trim(b)+"</div>").text();make_progress(b,c);clearTimeout(timer);items+=1;tokens.push(e);translations.push(b);langs.push(c);sources.push(d);timer=setTimeout(function(){var f={translation_posted:"2",items:items},a;for(a=0;a<items;a+=1){if(tokens[a]!==tokens[a-1])f["tk"+a]=tokens[a];if(langs[a]!==langs[a-1])f["ln"+a]=langs[a];if(translations[a]!==translations[a-1])f["tr"+a]=translations[a];if(sources[a]!==sources[a-1])f["sr"+a]=sources[a]}jQuery.ajax({type:"POST",
13
  url:t_jp.post_url,data:f,success:function(){},error:function(){}});items=0;translations=[];tokens=[];langs=[];sources=[]},200)}function do_mass_ms_translate(e,b){var c="[";jQuery(e).each(function(d){c+='"'+encodeURIComponent(e[d])+'",'});c=c.slice(0,-1)+"]";jQuery.ajax({url:"http://api.microsofttranslator.com/V2/Ajax.svc/TranslateArray?appId="+t_jp.MSN_APPID+"&to="+t_jp.binglang+"&texts="+c,dataType:"jsonp",jsonp:"oncomplete",success:b})}
14
  function do_mass_ms_invoker(e,b,c){t_jp.binglang=c;if(t_jp.binglang==="zh")t_jp.binglang="zh-chs";else if(t_jp.binglang==="zh-tw")t_jp.binglang="zh-cht";do_mass_ms_translate(b,function(d){jQuery(d).each(function(f){ajax_translate_me(e[f],this.TranslatedText,c,2)})})}function do_mass_google_translate_l(e,b,c){var d="",f;for(f in b)d+="&langpair=%7C"+b[f];jQuery.ajax({url:"http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q="+encodeURIComponent(e)+d,dataType:"jsonp",success:c})}
15
  function do_mass_google_invoker_l(e,b,c){do_mass_google_translate_l(b,c,function(d){if(d.responseStatus===200)d.responseData.translatedText!==undefined?ajax_translate_me(e,d.responseData.translatedText,c[0],1):jQuery(d.responseData).each(function(f){this.responseStatus===200&&ajax_translate_me(e,this.responseData.translatedText,c[f],1)})})}
js/transposhcontrol.js CHANGED
@@ -1,12 +1,12 @@
1
  /*
2
- * Transposh v0.6.2
3
  * http://transposh.org/
4
  *
5
  * Copyright 2010, Team Transposh
6
  * Licensed under the GPL Version 2 or higher.
7
  * http://transposh.org/license
8
  *
9
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
10
  */
11
  jQuery(function(){jQuery("#tr_anon").click(function(){if(jQuery("#tr_anon").attr("checked")){jQuery(".translateable").addClass("active").removeClass("translateable");jQuery("#sortable .active").each(function(){jQuery("input",this).val(jQuery(this).attr("id")+",v,t")})}jQuery("#yellowcolor").toggleClass("hidden")});jQuery("#sortable").sortable({placeholder:"highlight",update:function(b,a){a.item.unbind("click");a.item.one("click",function(c){c.stopImmediatePropagation();jQuery(this).click(clickfunction)})}});
12
  jQuery("#sortable").disableSelection();jQuery("#changename").click(function(){jQuery(".langname").toggleClass("hidden");return false});jQuery("#selectall").click(function(){jQuery("#sortable .languages").addClass("active").removeClass("translateable");jQuery("#sortable .active").each(function(){jQuery("input",this).val(jQuery(this).attr("id")+",v,t")});return false});clickfunction=function(){if(jQuery(this).attr("id")!=jQuery("#default_list li").attr("id")){if(jQuery("#tr_anon").attr("checked"))jQuery(this).toggleClass("active");
1
  /*
2
+ * Transposh v0.6.3
3
  * http://transposh.org/
4
  *
5
  * Copyright 2010, Team Transposh
6
  * Licensed under the GPL Version 2 or higher.
7
  * http://transposh.org/license
8
  *
9
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
10
  */
11
  jQuery(function(){jQuery("#tr_anon").click(function(){if(jQuery("#tr_anon").attr("checked")){jQuery(".translateable").addClass("active").removeClass("translateable");jQuery("#sortable .active").each(function(){jQuery("input",this).val(jQuery(this).attr("id")+",v,t")})}jQuery("#yellowcolor").toggleClass("hidden")});jQuery("#sortable").sortable({placeholder:"highlight",update:function(b,a){a.item.unbind("click");a.item.one("click",function(c){c.stopImmediatePropagation();jQuery(this).click(clickfunction)})}});
12
  jQuery("#sortable").disableSelection();jQuery("#changename").click(function(){jQuery(".langname").toggleClass("hidden");return false});jQuery("#selectall").click(function(){jQuery("#sortable .languages").addClass("active").removeClass("translateable");jQuery("#sortable .active").each(function(){jQuery("input",this).val(jQuery(this).attr("id")+",v,t")});return false});clickfunction=function(){if(jQuery(this).attr("id")!=jQuery("#default_list li").attr("id")){if(jQuery("#tr_anon").attr("checked"))jQuery(this).toggleClass("active");
js/transposhedit.js CHANGED
@@ -1,17 +1,17 @@
1
  /*
2
- * Transposh v0.6.2
3
  * http://transposh.org/
4
  *
5
  * Copyright 2010, Team Transposh
6
  * Licensed under the GPL Version 2 or higher.
7
  * http://transposh.org/license
8
  *
9
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
10
  */
11
  (function(a){function h(b,c){if(a.trim(c).length===0)c=a("[data-token='"+b+"']").attr("data-orig");var e=function(){var f=a(this).attr("id").substr(a(this).attr("id").lastIndexOf("_")+1),d=a("#"+t_jp.prefix+"img_"+f);a("#"+t_jp.prefix+f).attr("data-source",0);d.removeClass("tr-icon-yellow").removeClass("tr-icon-green").addClass("tr-icon-green")};a("*[data-token='"+b+"'][data-hidden!='y']").html(c).each(e);a("*[data-token='"+b+"'][data-hidden='y']").attr("data-trans",c).each(e)}function i(b,c){h(b,
12
  c);a.ajax({type:"POST",url:t_jp.post_url,data:{ln0:t_jp.lang,sr0:0,translation_posted:"2",items:1,tk0:b,tr0:c},success:function(){},error:function(e){alert("Error !!! failed to translate.\n\nServer's message: "+e.statusText)}})}function j(b,c){a.ajax({url:"http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q="+encodeURIComponent(b)+"&langpair=%7C"+t_jp.lang,dataType:"jsonp",success:c})}function k(){a(":button:contains('Suggest - Google')").attr("disabled","disabled").addClass("ui-state-disabled");
13
- a(":button:contains('Suggest - Bing')").attr("disabled","").removeClass("ui-state-disabled");j(a("#"+t_jp.prefix+"original").val(),function(b){b.responseStatus===200&&a("#"+t_jp.prefix+"translation").val(a("<div>"+b.responseData.translatedText+"</div>").text()).keyup()})}function l(b,c){a.ajax({url:"http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId="+t_jp.MSN_APPID+"&to="+t_jp.binglang+"&text="+encodeURIComponent(b),dataType:"jsonp",jsonp:"oncomplete",success:c})}function m(){a(":button:contains('Suggest - Bing')").attr("disabled",
14
- "disabled").addClass("ui-state-disabled");a(":button:contains('Suggest - Google')").attr("disabled","").removeClass("ui-state-disabled");l(a("#"+t_jp.prefix+"original").val(),function(b){a("#"+t_jp.prefix+"translation").val(a("<div>"+b+"</div>").text()).keyup()})}function n(){a('<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,
15
  resizable:false,height:140,modal:true,overlay:{backgroundColor:"#000",opacity:0.5},buttons:{Discard:function(){a("#"+t_jp.prefix+"translation").data("edit",{changed:false});a(this).dialog("close");a("#"+t_jp.prefix+"d-tabs").dialog("close")},Cancel:function(){a(this).dialog("close")}}})}function g(b){var c={},e={};if(t_jp.msn)c["Suggest - Bing"]=function(){m()};if(t_jp.google)c["Suggest - Google"]=function(){k()};c.Ok=function(){var f=a("#"+t_jp.prefix+"translation").val(),d=a("#"+t_jp.prefix+b).attr("data-token");
16
  if(a("#"+t_jp.prefix+"translation").data("edit").changed){i(d,f);a("#"+t_jp.prefix+"translation").data("edit",{changed:false})}a(this).dialog("close")};e={Close:function(){a(this).dialog("close")}};a("#"+t_jp.prefix+"d-tabs").remove();a('<div id="'+t_jp.prefix+'d-tabs" title="Edit Translation"/>').appendTo("body");a("#"+t_jp.prefix+"d-tabs").append("<ul/>").tabs({cache:true}).tabs("add","#"+t_jp.prefix+"d-tabs-1","Translate").tabs("add",t_jp.post_url+"?tr_token_hist="+a("#"+t_jp.prefix+b).attr("data-token")+
17
  "&lang="+t_jp.lang,"History").css("text-align","left").css("padding",0).bind("tabsload",function(f,d){a("table",d.panel).addClass("ui-widget ui-widget-content").css({width:"95%",padding:"0"});a("table thead tr",d.panel).addClass("ui-widget-header");a("table tbody td[source='2']",d.panel).append('<span title="computer" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-gear"></span>');a("table tbody td[source='1']",d.panel).append('<span title="computer" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-gear"></span>');
1
  /*
2
+ * Transposh v0.6.3
3
  * http://transposh.org/
4
  *
5
  * Copyright 2010, Team Transposh
6
  * Licensed under the GPL Version 2 or higher.
7
  * http://transposh.org/license
8
  *
9
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
10
  */
11
  (function(a){function h(b,c){if(a.trim(c).length===0)c=a("[data-token='"+b+"']").attr("data-orig");var e=function(){var f=a(this).attr("id").substr(a(this).attr("id").lastIndexOf("_")+1),d=a("#"+t_jp.prefix+"img_"+f);a("#"+t_jp.prefix+f).attr("data-source",0);d.removeClass("tr-icon-yellow").removeClass("tr-icon-green").addClass("tr-icon-green")};a("*[data-token='"+b+"'][data-hidden!='y']").html(c).each(e);a("*[data-token='"+b+"'][data-hidden='y']").attr("data-trans",c).each(e)}function i(b,c){h(b,
12
  c);a.ajax({type:"POST",url:t_jp.post_url,data:{ln0:t_jp.lang,sr0:0,translation_posted:"2",items:1,tk0:b,tr0:c},success:function(){},error:function(e){alert("Error !!! failed to translate.\n\nServer's message: "+e.statusText)}})}function j(b,c){a.ajax({url:"http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q="+encodeURIComponent(b)+"&langpair=%7C"+t_jp.lang,dataType:"jsonp",success:c})}function k(){a(":button:contains('Suggest - Google')").attr("disabled","disabled").addClass("ui-state-disabled");
13
+ a(":button:contains('Suggest - Bing')").attr("disabled","").removeClass("ui-state-disabled");j(a("#"+t_jp.prefix+"original").val(),function(b){b.responseStatus===200&&a("#"+t_jp.prefix+"translation").val(a("<div>"+a.trim(b.responseData.translatedText)+"</div>").text()).keyup()})}function l(b,c){a.ajax({url:"http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId="+t_jp.MSN_APPID+"&to="+t_jp.binglang+"&text="+encodeURIComponent(b),dataType:"jsonp",jsonp:"oncomplete",success:c})}function m(){a(":button:contains('Suggest - Bing')").attr("disabled",
14
+ "disabled").addClass("ui-state-disabled");a(":button:contains('Suggest - Google')").attr("disabled","").removeClass("ui-state-disabled");l(a("#"+t_jp.prefix+"original").val(),function(b){a("#"+t_jp.prefix+"translation").val(a("<div>"+a.trim(b)+"</div>").text()).keyup()})}function n(){a('<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,
15
  resizable:false,height:140,modal:true,overlay:{backgroundColor:"#000",opacity:0.5},buttons:{Discard:function(){a("#"+t_jp.prefix+"translation").data("edit",{changed:false});a(this).dialog("close");a("#"+t_jp.prefix+"d-tabs").dialog("close")},Cancel:function(){a(this).dialog("close")}}})}function g(b){var c={},e={};if(t_jp.msn)c["Suggest - Bing"]=function(){m()};if(t_jp.google)c["Suggest - Google"]=function(){k()};c.Ok=function(){var f=a("#"+t_jp.prefix+"translation").val(),d=a("#"+t_jp.prefix+b).attr("data-token");
16
  if(a("#"+t_jp.prefix+"translation").data("edit").changed){i(d,f);a("#"+t_jp.prefix+"translation").data("edit",{changed:false})}a(this).dialog("close")};e={Close:function(){a(this).dialog("close")}};a("#"+t_jp.prefix+"d-tabs").remove();a('<div id="'+t_jp.prefix+'d-tabs" title="Edit Translation"/>').appendTo("body");a("#"+t_jp.prefix+"d-tabs").append("<ul/>").tabs({cache:true}).tabs("add","#"+t_jp.prefix+"d-tabs-1","Translate").tabs("add",t_jp.post_url+"?tr_token_hist="+a("#"+t_jp.prefix+b).attr("data-token")+
17
  "&lang="+t_jp.lang,"History").css("text-align","left").css("padding",0).bind("tabsload",function(f,d){a("table",d.panel).addClass("ui-widget ui-widget-content").css({width:"95%",padding:"0"});a("table thead tr",d.panel).addClass("ui-widget-header");a("table tbody td[source='2']",d.panel).append('<span title="computer" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-gear"></span>');a("table tbody td[source='1']",d.panel).append('<span title="computer" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-gear"></span>');
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://transposh.org/donate/
4
  Tags: translation, widget, filter, buddypress, bilingual, multilingual, transposh, translate, language, crowdsourcing, context, wiki, RTL, Hebrew, Spanish, French, Russian, English, Arabic, Portuguese
5
  Requires at least: 2.8
6
  Tested up to: 3.0.1
7
- Stable tag: 0.6.2
8
 
9
  Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
10
 
@@ -165,6 +165,8 @@ images based on the current language
165
  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.
166
 
167
  == Upgrade Notice ==
 
 
168
  = 0.6.0 =
169
  Much improved translation interface engine
170
  = 0.5.7 =
@@ -191,6 +193,14 @@ This version provides integration with google-sitemaps-xml and wp-super-cache
191
  This version allows sorting of languages within the widget
192
 
193
  == Changelog ==
 
 
 
 
 
 
 
 
194
  = 2010/08/09 - 0.6.2 =
195
  * Allow marking of complete posts in different languages (see FAQ)
196
  * Fixed typo in buddypress stream (thanks revonorway)
4
  Tags: translation, widget, filter, buddypress, bilingual, multilingual, transposh, translate, language, crowdsourcing, context, wiki, RTL, Hebrew, Spanish, French, Russian, English, Arabic, Portuguese
5
  Requires at least: 2.8
6
  Tested up to: 3.0.1
7
+ Stable tag: 0.6.3
8
 
9
  Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
10
 
165
  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.
166
 
167
  == Upgrade Notice ==
168
+ = 0.6.3 =
169
+ Support .po/.mo files
170
  = 0.6.0 =
171
  Much improved translation interface engine
172
  = 0.5.7 =
193
  This version allows sorting of languages within the widget
194
 
195
  == Changelog ==
196
+ = 2010/09/01 - 0.6.3 =
197
+ * Support for gettext files (.po/.mo) files - see http://trac.transposh.org/wiki/UsingGetText
198
+ * Support backend memory caching with xcache and eaccelarator in addition to apc
199
+ * Improved caching to save resources (43% on APC) better overall performance with negative caching that is actually working
200
+ * Tags from the tag cloud will now be translated with mass translate
201
+ * Fix for the sneaky "not a valid plugin header" issue
202
+ * Fix for MS translate tendency to add an extra space
203
+ * Fixed bug with list with flags css widget preventing the view of flags
204
  = 2010/08/09 - 0.6.2 =
205
  * Allow marking of complete posts in different languages (see FAQ)
206
  * Fixed typo in buddypress stream (thanks revonorway)
transposh.php CHANGED
@@ -5,20 +5,20 @@
5
  Plugin URI: http://transposh.org/
6
  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>.
7
  Author: Team Transposh
8
- Version: 0.6.2
9
  Author URI: http://transposh.org/
10
  License: GPL (http://www.gnu.org/licenses/gpl.txt)
11
  */
12
 
13
  /*
14
- * Transposh v0.6.2
15
  * http://transposh.org/
16
  *
17
  * Copyright 2010, Team Transposh
18
  * Licensed under the GPL Version 2 or higher.
19
  * http://transposh.org/license
20
  *
21
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
22
  */
23
 
24
  //avoid direct calls to this file where wp core files not present
@@ -59,7 +59,6 @@ class transposh_plugin {
59
  public $postpublish;
60
  /** @var transposh_3rdparty Happens after editing */
61
  private $third_party;
62
-
63
  // list of properties
64
  /** @var string The site url */
65
  public $home_url;
@@ -71,8 +70,10 @@ class transposh_plugin {
71
  public $transposh_plugin_dir;
72
  /** @var boolean Enable rewriting of URLs */
73
  public $enable_permalinks_rewrite;
74
- /** @var string The language to translate the page to */
75
  public $target_language;
 
 
76
  /** @var boolean Are we currently editing the page? */
77
  public $edit_mode;
78
  /** @var string Error message displayed for the admin in case of failure */
@@ -131,20 +132,24 @@ class transposh_plugin {
131
  // add_action('wp_head', array(&$this,'add_transposh_async'));
132
  add_action('transposh_backup_event', array(&$this, 'run_backup'));
133
  add_action('comment_post', array(&$this, 'add_comment_meta_settings'), 1);
134
-
135
  // full post wrapping (should happen late)
136
  add_filter('the_content', array(&$this, 'post_content_wrap'), 9999);
137
  add_filter('the_title', array(&$this, 'post_wrap'), 9999, 2);
138
  // allow to mark the language?
139
  // add_action('admin_menu', array(&$this, 'transposh_post_language'));
140
  // add_action('save_post', array(&$this, 'transposh_save_post_language'));
141
-
142
  //TODO add_action('manage_comments_nav', array(&$this,'manage_comments_nav'));
143
  //TODO comment_row_actions (filter)
144
- // toying around the mo/po stuff
145
- add_filter('gettext', array(&$this, 'transposh_gettext_filter'), 10, 3);
 
 
 
146
  add_filter('locale', array(&$this, 'transposh_locale_filter'));
147
 
 
 
148
 
149
  register_activation_hook(__FILE__, array(&$this, 'plugin_activate'));
150
  register_deactivation_hook(__FILE__, array(&$this, 'plugin_deactivate'));
@@ -158,6 +163,7 @@ class transposh_plugin {
158
  function is_special_page($url) {
159
  return ( stripos($url, '/wp-login.php') !== FALSE ||
160
  stripos($url, '/wp-admin/') !== FALSE ||
 
161
  stripos($url, '/xmlrpc.php') !== FALSE);
162
  }
163
 
@@ -173,42 +179,42 @@ class transposh_plugin {
173
  // Refrain from touching the administrative interface and important pages
174
  if ($this->is_special_page($_SERVER['REQUEST_URI'])) {
175
 
176
- return $buffer;
177
  }
178
 
179
  // This one fixed a bug transposh created with other pages (xml generator for other plugins - such as the nextgen gallery)
180
  // TODO: need to further investigate (will it be needed?)
181
- if ($this->target_language == '') return $buffer;
182
- // Don't translate the default language unless specifically allowed to...
183
- if ($this->options->is_default_language($this->target_language) && !$this->options->get_enable_default_translate()) {
184
 
185
- return $buffer;
186
  }
 
 
 
 
 
187
 
188
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
 
190
- //translate the entire page
191
- $parse = new parser();
192
- $parse->fetch_translate_func = array(&$this->database, 'fetch_translation');
193
- $parse->prefetch_translate_func = array(&$this->database, 'prefetch_translations');
194
- $parse->url_rewrite_func = array(&$this, 'rewrite_url');
195
- $parse->dir_rtl = (in_array($this->target_language, transposh_consts::$rtl_languages));
196
- $parse->lang = $this->target_language;
197
- $parse->default_lang = $this->options->is_default_language($this->target_language);
198
- $parse->is_edit_mode = $this->edit_mode;
199
- $parse->is_auto_translate = $this->is_auto_translate_permitted();
200
- $parse->allow_ad = $this->options->get_widget_remove_logo();
201
- // TODO - check this!
202
- if (stripos($_SERVER['REQUEST_URI'], '/feed/') !== FALSE) {
203
 
204
- $parse->is_auto_translate = false;
205
- $parse->is_edit_mode = false;
206
- $parse->feed_fix = true;
207
  }
208
- $buffer = $parse->fix_html($buffer);
209
-
210
- $end_time = microtime(TRUE);
211
-
212
 
213
  return $buffer;
214
  }
@@ -243,7 +249,7 @@ class transposh_plugin {
243
  * Page generation completed - flush buffer.
244
  */
245
  function on_shutdown() {
246
- ob_flush();
247
  }
248
 
249
  /**
@@ -320,11 +326,17 @@ class transposh_plugin {
320
  if ($this->target_language) return;
321
 
322
  // first we get the target language
323
- $this->target_language = $wp->query_vars[LANG_PARAM];
 
 
 
 
 
324
  if (!$this->target_language)
325
  $this->target_language = $this->options->get_default_language();
326
 
327
 
 
328
  // make themes that support rtl - go rtl http://wordpress.tv/2010/05/01/yoav-farhi-right-to-left-themes-sf10
329
  if (in_array($this->target_language, transposh_consts::$rtl_languages)) {
330
  global $wp_locale;
@@ -418,6 +430,10 @@ class transposh_plugin {
418
  add_filter('rewrite_rules_array', array(&$this, 'update_rewrite_rules'));
419
  $GLOBALS['wp_rewrite']->flush_rules();
420
 
 
 
 
 
421
 
422
 
423
 
@@ -601,6 +617,8 @@ class transposh_plugin {
601
  function rewrite_url($href) {
602
  $use_params = FALSE;
603
 
 
 
604
 
605
  // Ignore urls not from this site
606
  if (stripos($href, $this->home_url) === FALSE) {
@@ -675,6 +693,7 @@ class transposh_plugin {
675
  }
676
  $n = !empty($q['exact']) ? '' : '%';
677
  $searchand = '';
 
678
  foreach ((array) $q['search_terms'] as $term) {
679
  // now we'll get possible translations for this term
680
  $possible_original_terms = $this->database->get_orignal_phrases_for_search_term($term, $this->target_language);
@@ -819,13 +838,49 @@ class transposh_plugin {
819
  return $query;
820
  }
821
 
822
- function transposh_gettext_filter($a, $orig, $domain) {
823
- //
824
- return $a;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
825
  }
826
 
827
  function transposh_locale_filter($locale) {
828
- //
 
 
 
 
 
 
 
829
  return $locale;
830
  }
831
 
5
  Plugin URI: http://transposh.org/
6
  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>.
7
  Author: Team Transposh
8
+ Version: 0.6.3
9
  Author URI: http://transposh.org/
10
  License: GPL (http://www.gnu.org/licenses/gpl.txt)
11
  */
12
 
13
  /*
14
+ * Transposh v0.6.3
15
  * http://transposh.org/
16
  *
17
  * Copyright 2010, Team Transposh
18
  * Licensed under the GPL Version 2 or higher.
19
  * http://transposh.org/license
20
  *
21
+ * Date: Thu, 02 Sep 2010 00:39:59 +0300
22
  */
23
 
24
  //avoid direct calls to this file where wp core files not present
59
  public $postpublish;
60
  /** @var transposh_3rdparty Happens after editing */
61
  private $third_party;
 
62
  // list of properties
63
  /** @var string The site url */
64
  public $home_url;
70
  public $transposh_plugin_dir;
71
  /** @var boolean Enable rewriting of URLs */
72
  public $enable_permalinks_rewrite;
73
+ /** @var string The language to translate the page to, from params */
74
  public $target_language;
75
+ /** @var string The language extracted from the url */
76
+ public $tgl;
77
  /** @var boolean Are we currently editing the page? */
78
  public $edit_mode;
79
  /** @var string Error message displayed for the admin in case of failure */
132
  // add_action('wp_head', array(&$this,'add_transposh_async'));
133
  add_action('transposh_backup_event', array(&$this, 'run_backup'));
134
  add_action('comment_post', array(&$this, 'add_comment_meta_settings'), 1);
135
+ // comment_moderation_text - future filter TODO
136
  // full post wrapping (should happen late)
137
  add_filter('the_content', array(&$this, 'post_content_wrap'), 9999);
138
  add_filter('the_title', array(&$this, 'post_wrap'), 9999, 2);
139
  // allow to mark the language?
140
  // add_action('admin_menu', array(&$this, 'transposh_post_language'));
141
  // add_action('save_post', array(&$this, 'transposh_save_post_language'));
 
142
  //TODO add_action('manage_comments_nav', array(&$this,'manage_comments_nav'));
143
  //TODO comment_row_actions (filter)
144
+ // Intergrating with the gettext interface
145
+ add_filter('gettext', array(&$this, 'transposh_gettext_filter'), 10, 2);
146
+ add_filter('gettext_with_context', array(&$this, 'transposh_gettext_filter'), 10, 2);
147
+ add_filter('ngettext', array(&$this, 'transposh_ngettext_filter'), 10, 3);
148
+ add_filter('ngettext_with_context', array(&$this, 'transposh_ngettext_filter'), 10, 3);
149
  add_filter('locale', array(&$this, 'transposh_locale_filter'));
150
 
151
+ //CHECK TODO!!!!!!!!!!!!
152
+ $this->tgl = transposh_utils::get_language_from_url($_SERVER['REQUEST_URI'], $this->home_url);
153
 
154
  register_activation_hook(__FILE__, array(&$this, 'plugin_activate'));
155
  register_deactivation_hook(__FILE__, array(&$this, 'plugin_deactivate'));
163
  function is_special_page($url) {
164
  return ( stripos($url, '/wp-login.php') !== FALSE ||
165
  stripos($url, '/wp-admin/') !== FALSE ||
166
+ stripos($url, '/wp-comments-post') !== FALSE ||
167
  stripos($url, '/xmlrpc.php') !== FALSE);
168
  }
169
 
179
  // Refrain from touching the administrative interface and important pages
180
  if ($this->is_special_page($_SERVER['REQUEST_URI'])) {
181
 
 
182
  }
183
 
184
  // This one fixed a bug transposh created with other pages (xml generator for other plugins - such as the nextgen gallery)
185
  // TODO: need to further investigate (will it be needed?)
186
+ elseif ($this->target_language == '') {
 
 
187
 
 
188
  }
189
+ // Don't translate the default language unless specifically allowed to...
190
+ elseif ($this->options->is_default_language($this->target_language) && !$this->options->get_enable_default_translate()) {
191
+
192
+ } else {
193
+
194
 
195
+ //translate the entire page
196
+ $parse = new parser();
197
+ $parse->fetch_translate_func = array(&$this->database, 'fetch_translation');
198
+ $parse->prefetch_translate_func = array(&$this->database, 'prefetch_translations');
199
+ $parse->url_rewrite_func = array(&$this, 'rewrite_url');
200
+ $parse->dir_rtl = (in_array($this->target_language, transposh_consts::$rtl_languages));
201
+ $parse->lang = $this->target_language;
202
+ $parse->default_lang = $this->options->is_default_language($this->target_language);
203
+ $parse->is_edit_mode = $this->edit_mode;
204
+ $parse->is_auto_translate = $this->is_auto_translate_permitted();
205
+ $parse->allow_ad = $this->options->get_widget_remove_logo();
206
+ // TODO - check this!
207
+ if (stripos($_SERVER['REQUEST_URI'], '/feed/') !== FALSE) {
208
+
209
+ $parse->is_auto_translate = false;
210
+ $parse->is_edit_mode = false;
211
+ $parse->feed_fix = true;
212
+ }
213
+ $buffer = $parse->fix_html($buffer);
214
 
215
+ $end_time = microtime(TRUE);
 
 
 
 
 
 
 
 
 
 
 
 
216
 
 
 
 
217
  }
 
 
 
 
218
 
219
  return $buffer;
220
  }
249
  * Page generation completed - flush buffer.
250
  */
251
  function on_shutdown() {
252
+ //TODO !!!!!!!!!!!! ob_flush();
253
  }
254
 
255
  /**
326
  if ($this->target_language) return;
327
 
328
  // first we get the target language
329
+ /* $this->target_language = (isset($wp->query_vars[LANG_PARAM])) ? $wp->query_vars[LANG_PARAM] : '';
330
+ if (!$this->target_language)
331
+ $this->target_language = $this->options->get_default_language();
332
+ */
333
+ // TODO TOCHECK!!!!!!!!!!!!!!!!!!!!!!!!!!1
334
+ $this->target_language = $this->tgl;
335
  if (!$this->target_language)
336
  $this->target_language = $this->options->get_default_language();
337
 
338
 
339
+
340
  // make themes that support rtl - go rtl http://wordpress.tv/2010/05/01/yoav-farhi-right-to-left-themes-sf10
341
  if (in_array($this->target_language, transposh_consts::$rtl_languages)) {
342
  global $wp_locale;
430
  add_filter('rewrite_rules_array', array(&$this, 'update_rewrite_rules'));
431
  $GLOBALS['wp_rewrite']->flush_rules();
432
 
433
+ // attempt to remove old files
434
+ @unlink($this->transposh_plugin_dir . 'widgets/tpw_default.php');
435
+ @unlink($this->transposh_plugin_dir . 'core/globals.php');
436
+
437
 
438
 
439
 
617
  function rewrite_url($href) {
618
  $use_params = FALSE;
619
 
620
+ // fix what might be messed up
621
+ $href = str_replace(array(TP_GTXT_BRK, TP_GTXT_IBRK, TP_GTXT_BRK_CLOSER, TP_GTXT_IBRK_CLOSER), '', $href);
622
 
623
  // Ignore urls not from this site
624
  if (stripos($href, $this->home_url) === FALSE) {
693
  }
694
  $n = !empty($q['exact']) ? '' : '%';
695
  $searchand = '';
696
+ $search = '';
697
  foreach ((array) $q['search_terms'] as $term) {
698
  // now we'll get possible translations for this term
699
  $possible_original_terms = $this->database->get_orignal_phrases_for_search_term($term, $this->target_language);
838
  return $query;
839
  }
840
 
841
+ /**
842
+ * This function adds our markings around gettext results
843
+ * @param string $translation
844
+ * @param string $orig
845
+ * @return string
846
+ */
847
+ function transposh_gettext_filter($translation, $orig) {
848
+ if ($this->is_special_page($_SERVER['REQUEST_URI']) || ($this->options->is_default_language($this->tgl) && !$this->options->get_enable_default_translate())) {
849
+ return $translation;
850
+ }
851
+ if ($translation != $orig) {
852
+ $translation = TP_GTXT_BRK . $translation . TP_GTXT_BRK_CLOSER;
853
+ }
854
+ $translation = str_replace(array('%s', '%1$s', '%2$s', '%3$s', '%4$s', '%5$s'), array(TP_GTXT_IBRK . '%s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%1$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%2$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%3$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%4$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%5$s' . TP_GTXT_IBRK_CLOSER), $translation);
855
+ return $translation;
856
+ }
857
+
858
+ /**
859
+ * This function adds our markings around ngettext results
860
+ * @param string $translation
861
+ * @param string $single
862
+ * @param string $plural
863
+ * @return string
864
+ */
865
+ function transposh_ngettext_filter($translation, $single, $plural) {
866
+ if ($this->is_special_page($_SERVER['REQUEST_URI']) || ($this->options->is_default_language($this->tgl) && !$this->options->get_enable_default_translate()))
867
+ return $translation;
868
+ if ($translation != $single && $translation != $plural) {
869
+ $translation = TP_GTXT_BRK . $translation . TP_GTXT_BRK_CLOSER;
870
+ }
871
+ $translation = str_replace(array('%s', '%1$s', '%2$s', '%3$s', '%4$s', '%5$s'), array(TP_GTXT_IBRK . '%s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%1$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%2$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%3$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%4$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%5$s' . TP_GTXT_IBRK_CLOSER), $translation);
872
+ return $translation;
873
  }
874
 
875
  function transposh_locale_filter($locale) {
876
+ $lang = transposh_utils::get_language_from_url($_SERVER['REQUEST_URI'], $this->home_url);
877
+ if (!$lang) return $locale;
878
+ list ($l, $n, $f, $locale) = explode(',', transposh_consts::$languages[$lang]);
879
+ if ($locale) {
880
+ return $locale;
881
+ } else {
882
+ return $lang;
883
+ }
884
  return $locale;
885
  }
886
 
widgets/{tpw_default.php → default/tpw_default.php} RENAMED
@@ -11,14 +11,14 @@
11
  */
12
 
13
  /*
14
- * Transposh v0.6.2
15
  * http://transposh.org/
16
  *
17
  * Copyright 2010, Team Transposh
18
  * Licensed under the GPL Version 2 or higher.
19
  * http://transposh.org/license
20
  *
21
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
22
  */
23
 
24
  /*
11
  */
12
 
13
  /*
14
+ * Transposh v0.6.3
15
  * http://transposh.org/
16
  *
17
  * Copyright 2010, Team Transposh
18
  * Licensed under the GPL Version 2 or higher.
19
  * http://transposh.org/license
20
  *
21
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
22
  */
23
 
24
  /*
widgets/dropdown/tpw_image_dropdown.php CHANGED
@@ -11,14 +11,14 @@
11
  */
12
 
13
  /*
14
- * Transposh v0.6.2
15
  * http://transposh.org/
16
  *
17
  * Copyright 2010, Team Transposh
18
  * Licensed under the GPL Version 2 or higher.
19
  * http://transposh.org/license
20
  *
21
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
22
  */
23
 
24
  /**
11
  */
12
 
13
  /*
14
+ * Transposh v0.6.3
15
  * http://transposh.org/
16
  *
17
  * Copyright 2010, Team Transposh
18
  * Licensed under the GPL Version 2 or higher.
19
  * http://transposh.org/license
20
  *
21
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
22
  */
23
 
24
  /**
widgets/flags/tpw_flags.php CHANGED
@@ -11,14 +11,14 @@
11
  */
12
 
13
  /*
14
- * Transposh v0.6.2
15
  * http://transposh.org/
16
  *
17
  * Copyright 2010, Team Transposh
18
  * Licensed under the GPL Version 2 or higher.
19
  * http://transposh.org/license
20
  *
21
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
22
  */
23
 
24
  /**
11
  */
12
 
13
  /*
14
+ * Transposh v0.6.3
15
  * http://transposh.org/
16
  *
17
  * Copyright 2010, Team Transposh
18
  * Licensed under the GPL Version 2 or higher.
19
  * http://transposh.org/license
20
  *
21
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
22
  */
23
 
24
  /**
widgets/flags/tpw_flags_css.php CHANGED
@@ -11,14 +11,14 @@
11
  */
12
 
13
  /*
14
- * Transposh v0.6.2
15
  * http://transposh.org/
16
  *
17
  * Copyright 2010, Team Transposh
18
  * Licensed under the GPL Version 2 or higher.
19
  * http://transposh.org/license
20
  *
21
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
22
  */
23
 
24
  /**
11
  */
12
 
13
  /*
14
+ * Transposh v0.6.3
15
  * http://transposh.org/
16
  *
17
  * Copyright 2010, Team Transposh
18
  * Licensed under the GPL Version 2 or higher.
19
  * http://transposh.org/license
20
  *
21
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
22
  */
23
 
24
  /**
widgets/flagslist/tpw_list_with_flags.php CHANGED
@@ -11,14 +11,14 @@
11
  */
12
 
13
  /*
14
- * Transposh v0.6.2
15
  * http://transposh.org/
16
  *
17
  * Copyright 2010, Team Transposh
18
  * Licensed under the GPL Version 2 or higher.
19
  * http://transposh.org/license
20
  *
21
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
22
  */
23
 
24
  /**
11
  */
12
 
13
  /*
14
+ * Transposh v0.6.3
15
  * http://transposh.org/
16
  *
17
  * Copyright 2010, Team Transposh
18
  * Licensed under the GPL Version 2 or higher.
19
  * http://transposh.org/license
20
  *
21
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
22
  */
23
 
24
  /**
widgets/flagslist/tpw_list_with_flags_css.php CHANGED
@@ -1,24 +1,24 @@
1
  <?php
2
 
3
  /*
4
- Plugin Name: List with flags (css)
5
  Plugin URI: http://transposh.org/
6
  Description: Widget with flags links (using css sprites) followed by language name
7
  Author: Team Transposh
8
- Version: 1.0
9
  Author URI: http://transposh.org/
10
  License: GPL (http://www.gnu.org/licenses/gpl.txt)
11
  */
12
 
13
  /*
14
- * Transposh v0.6.2
15
  * http://transposh.org/
16
  *
17
  * Copyright 2010, Team Transposh
18
  * Licensed under the GPL Version 2 or higher.
19
  * http://transposh.org/license
20
  *
21
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
22
  */
23
 
24
  /**
@@ -47,7 +47,7 @@ function tp_widget_do($args) {
47
  echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
48
  foreach ($args as $langrecord) {
49
  echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' .
50
- transposh_utils::display_flag('', $langrecord['flag'], $langrecord['langorig'], false) . '</a>';
51
  echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . "{$langrecord['langorig']}</a><br/>";
52
  }
53
  echo "</div>";
1
  <?php
2
 
3
  /*
4
+ Plugin Name: List with flags (CSS)
5
  Plugin URI: http://transposh.org/
6
  Description: Widget with flags links (using css sprites) followed by language name
7
  Author: Team Transposh
8
+ Version: 1.0.1
9
  Author URI: http://transposh.org/
10
  License: GPL (http://www.gnu.org/licenses/gpl.txt)
11
  */
12
 
13
  /*
14
+ * Transposh v0.6.3
15
  * http://transposh.org/
16
  *
17
  * Copyright 2010, Team Transposh
18
  * Licensed under the GPL Version 2 or higher.
19
  * http://transposh.org/license
20
  *
21
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
22
  */
23
 
24
  /**
47
  echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
48
  foreach ($args as $langrecord) {
49
  echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' .
50
+ transposh_utils::display_flag('', $langrecord['flag'], $langrecord['langorig'], true) . '</a>';
51
  echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . "{$langrecord['langorig']}</a><br/>";
52
  }
53
  echo "</div>";
wp/transposh_3rdparty.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
 
3
  /*
4
- * Transposh v0.6.2
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
12
  */
13
 
14
  /*
1
  <?php
2
 
3
  /*
4
+ * Transposh v0.6.3
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
12
  */
13
 
14
  /*
wp/transposh_admin.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
 
3
  /*
4
- * Transposh v0.6.2
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
12
  */
13
 
14
  /*
@@ -285,37 +285,8 @@ class transposh_plugin_admin {
285
  }
286
 
287
  function on_sidebox_news_content($data) {
288
- require_once(ABSPATH . WPINC . '/rss.php');
289
-
290
- // ugly hack copy of RSS because of Unicode chars misprinting
291
- function wp_rss2($url, $num_items = -1) {
292
- if ($rss = fetch_rss($url)) {
293
- echo '<ul>';
294
-
295
- if ($num_items !== -1) {
296
- $rss->items = array_slice($rss->items, 0, $num_items);
297
- }
298
-
299
- foreach ((array) $rss->items as $item) {
300
- printf(
301
- '<li><a href="%1$s" title="%2$s">%3$s</a></li>',
302
- //esc_url( $item['link'] ),
303
- //esc_attr( strip_tags( $item['description'] ) ),
304
- // TODO - check Switched to 2.7 compatability functions
305
- clean_url($item['link']),
306
- attribute_escape(strip_tags($item['description'])),
307
- htmlentities($item['title'], ENT_COMPAT, 'UTF-8')
308
- );
309
- }
310
-
311
- echo '</ul>';
312
- } else {
313
- _e('An error has occurred, which probably means the feed is down. Try again later.');
314
- }
315
- }
316
-
317
  echo '<div style="margin:6px">';
318
- wp_rss2('http://feeds2.feedburner.com/transposh', 5);
319
  echo '</div>';
320
  }
321
 
1
  <?php
2
 
3
  /*
4
+ * Transposh v0.6.3
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
12
  */
13
 
14
  /*
285
  }
286
 
287
  function on_sidebox_news_content($data) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
  echo '<div style="margin:6px">';
289
+ wp_widget_rss_output('http://feeds2.feedburner.com/transposh',array('items' => 5));
290
  echo '</div>';
291
  }
292
 
wp/transposh_ajax.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
 
3
  /*
4
- * Transposh v0.6.2
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
12
  */
13
 
14
  /*
@@ -70,6 +70,8 @@ elseif (isset($_GET['translate_all'])) {
70
  $page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE (post_type='page' OR post_type='post') AND (post_status='publish' OR post_status='private') ORDER BY ID DESC");
71
  // only high capabilities users can...
72
  if (!current_user_can('edit_post', $page_ids[0])) return;
 
 
73
  echo json_encode($page_ids);
74
  }
75
  // Proxyed translation for google translate
1
  <?php
2
 
3
  /*
4
+ * Transposh v0.6.3
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
12
  */
13
 
14
  /*
70
  $page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE (post_type='page' OR post_type='post') AND (post_status='publish' OR post_status='private') ORDER BY ID DESC");
71
  // only high capabilities users can...
72
  if (!current_user_can('edit_post', $page_ids[0])) return;
73
+ // add a fake post to translate things such as tags
74
+ $page_ids[] = "-555";
75
  echo json_encode($page_ids);
76
  }
77
  // Proxyed translation for google translate
wp/transposh_backup.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
 
3
  /*
4
- * Transposh v0.6.2
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
12
  */
13
 
14
  /*
@@ -103,8 +103,7 @@ class transposh_backup {
103
  $this->transposh->database->restore_translation($trans[0], $trans[1], $trans[2], $trans[3], $trans[4]);
104
  }
105
  // clean up cache so that results will actually show
106
- if (ENABLE_APC && function_exists('apc_clear_cache'))
107
- apc_clear_cache('user');
108
  exit;
109
  }
110
 
1
  <?php
2
 
3
  /*
4
+ * Transposh v0.6.3
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
12
  */
13
 
14
  /*
103
  $this->transposh->database->restore_translation($trans[0], $trans[1], $trans[2], $trans[3], $trans[4]);
104
  }
105
  // clean up cache so that results will actually show
106
+ $this->transposh->database->cache_clean();
 
107
  exit;
108
  }
109
 
wp/transposh_db.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
 
3
  /*
4
- * Transposh v0.6.2
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
12
  */
13
 
14
  /**
@@ -33,40 +33,136 @@ class transposh_database {
33
 
34
  /** @var transposh_plugin father class */
35
  private $transposh;
 
36
  private $translations;
 
 
 
 
37
 
38
  /**
39
  * constructor of class, PHP4 compatible construction for backward compatibility
40
  */
41
  function transposh_database(&$transposh) {
42
  $this->transposh = &$transposh;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  }
44
 
45
  /**
46
  * Allow fetching of multiple translation requests from the database with a single query
47
- * @param array $originals
48
  * @param string $lang
49
  */
50
  function prefetch_translations($originals, $lang) {
51
  if (!$originals) return;
52
- foreach ($originals as $original) {
 
53
  $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
54
- if (ENABLE_APC && function_exists('apc_fetch')) {
55
- $cached = apc_fetch($original . '___' . $lang, $rc);
56
- if ($rc === TRUE) {
57
-
58
- continue;
59
- }
60
  }
61
  $where .= ( ($where) ? ' OR ' : '') . "original = '$original'";
62
  }
 
63
  if (!$where) return;
64
- $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
65
- $query = "SELECT original, translated, source FROM $table_name WHERE ($where) and lang = '$lang' ";
66
  $rows = $GLOBALS['wpdb']->get_results($query, ARRAY_A);
67
  if (empty($rows)) return;
 
68
  foreach ($rows as $row) {
69
- $this->translations[$row['original']] = array(stripslashes($row['translated']), $row['source']);
70
  }
71
 
72
  }
@@ -77,55 +173,36 @@ class transposh_database {
77
  * Will return NULL if no translation is available.
78
  * @param string $original
79
  * @param string $lang
80
- * @return array list(translation,source)
81
  */
82
  function fetch_translation($original, $lang) {
83
- $translated = NULL;
84
 
85
-
86
  //The original is saved in db in its escaped form
87
  $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
88
-
89
- if (ENABLE_APC && function_exists('apc_fetch')) {
90
- $cached = apc_fetch($original . '___' . $lang, $rc);
91
- if ($rc === TRUE) {
92
-
93
- return $cached;
94
- }
95
  }
96
-
97
  if ($this->translations[$original]) {
98
  $translated = $this->translations[$original];
99
 
100
  } else {
101
-
102
- $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
103
- $query = "SELECT * FROM $table_name WHERE original = '$original' and lang = '$lang' ";
104
  $row = $GLOBALS['wpdb']->get_row($query);
105
 
106
- if ($row !== FALSE) {
107
  $translated_text = stripslashes($row->translated);
108
- $translated = array($translated_text, $row->source);
109
-
110
 
111
  }
112
  }
 
 
113
 
114
- if (ENABLE_APC && function_exists('apc_store')) {
115
- //If we don't have translation still we want to have it in cache
116
- $cache_entry = $translated;
117
- if ($cache_entry == NULL) {
118
- $cache_entry = "";
119
- }
120
-
121
- //update cache
122
- $rc = apc_store($original . '___' . $lang, $cache_entry, 3600);
123
- if ($rc === TRUE) {
124
-
125
- }
126
- }
127
-
128
-
129
  return $translated;
130
  }
131
 
@@ -138,48 +215,33 @@ class transposh_database {
138
  * @return array list(translation,source)
139
  */
140
  function fetch_original($translation, $lang) {
141
- $original = NULL;
142
 
143
 
144
- //The original is saved in db in its escaped form
145
  $translation = $GLOBALS['wpdb']->escape(html_entity_decode($translation, ENT_NOQUOTES, 'UTF-8'));
146
-
147
- if (ENABLE_APC && function_exists('apc_fetch')) {
148
- $cached = apc_fetch($translation . '_r_r_' . $lang, $rc);
149
- if ($rc === TRUE) {
150
-
151
- return $cached;
152
- }
153
  }
154
-
155
  if ($this->translations[$translation]) {
156
  $original = $this->translations[$translation];
157
 
158
  } else {
159
-
160
- $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
161
- $query = "SELECT * FROM $table_name WHERE translated = '$translation' and lang = '$lang' ";
162
  $row = $GLOBALS['wpdb']->get_row($query);
163
 
164
- if ($row !== FALSE) {
165
  $original = stripslashes($row->original);
166
 
167
  }
168
  }
169
 
170
- if (ENABLE_APC && function_exists('apc_store')) {
171
- //If we don't have translation still we want to have it in cache
172
- $cache_entry = $original;
173
- if ($cache_entry == NULL) {
174
- $cache_entry = "";
175
- }
176
-
177
- //update cache
178
- $rc = apc_store($translation . '_r_r_' . $lang, $cache_entry, 3600);
179
- if ($rc === TRUE) {
180
-
181
- }
182
- }
183
 
184
 
185
  return $original;
@@ -217,7 +279,6 @@ class transposh_database {
217
  }
218
  }
219
  }
220
-
221
  if (!($all_editable &&
222
  ($this->transposh->is_translator() || ($source == 1 && $this->transposh->options->get_enable_auto_translate())))) {
223
 
@@ -228,7 +289,7 @@ class transposh_database {
228
  //add our own custom header - so we will know that we got here
229
  header("Transposh: v-" . TRANSPOSH_PLUGIN_VER . " db_version-" . DB_VERSION);
230
 
231
- // transaction log stuff
232
  global $user_ID;
233
  get_currentuserinfo();
234
 
@@ -238,18 +299,18 @@ class transposh_database {
238
  } else {
239
  $loguser = $user_ID;
240
  }
241
- // end tl
242
- // We are now passing all posted items
243
  for ($i = 0; $i < $items; $i++) {
244
  if (isset($_POST["tk$i"])) {
245
  $original = transposh_utils::base64_url_decode($_POST["tk$i"]);
246
- //The original content is encoded as base64 before it is sent (i.e. token), after we
247
- //decode it should just the same after it was parsed.
248
  $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
249
  }
250
  if (isset($_POST["tr$i"])) {
251
  $translation = $_POST["tr$i"];
252
- //Decode & remove already escaped character to avoid double escaping
253
  $translation = $GLOBALS['wpdb']->escape(htmlspecialchars(stripslashes(urldecode($translation))));
254
  }
255
  if (isset($_POST["ln$i"])) {
@@ -258,7 +319,8 @@ class transposh_database {
258
  if (isset($_POST["sr$i"])) {
259
  $source = $_POST["sr$i"];
260
  }
261
- // should we backup?
 
262
  if ($source == 0) $backup_immidiate_possible = true;
263
 
264
  //Here we check we are not redoing stuff
@@ -282,31 +344,29 @@ class transposh_database {
282
  $logvalues .= "('" . $original . "','" . $translation . "','" . $lang . "','" . $loguser . "','" . $source . "')" . (($items != $i + 1) ? ', ' : '');
283
 
284
  // If we have caching - we remove previous entry from cache
285
- if (ENABLE_APC && function_exists('apc_delete')) {
286
- apc_delete($original . '___' . $lang);
287
- }
288
  }
289
 
290
- // avoid empty work
291
  if (!$values) return;
292
  // perform insertion to the database, with one query :)
293
- // since we have no primary key, replace made no sense
294
  /* $update = "REPLACE INTO ".$GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE." (original, translated, lang, source)
295
  VALUES $values"; */
296
  //so we'll delete all values and insert them...
297
- $update = "DELETE FROM " . $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE . " WHERE $delvalues";
298
 
299
  $result = $GLOBALS['wpdb']->query($update);
300
- $update = "INSERT INTO " . $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE . " (original, translated, lang, source) VALUES $values";
301
 
302
  $result = $GLOBALS['wpdb']->query($update);
303
 
 
304
  if ($result !== FALSE) {
305
- // update the transaction log too
306
- $log = "INSERT INTO " . $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG . " (original, translated, lang, translated_by, source) " .
307
  "VALUES $logvalues";
308
  $result = $GLOBALS['wpdb']->query($log);
309
-
310
 
311
  } else {
312
 
@@ -314,7 +374,9 @@ class transposh_database {
314
  header("HTTP/1.0 404 Failed to update language database " . mysql_error());
315
  }
316
 
317
- if ($source == 0) { // if its a human translation
 
 
318
  do_action('transposh_human_translation', $translation, $original, $lang);
319
  }
320
 
@@ -345,8 +407,8 @@ class transposh_database {
345
  }
346
 
347
 
348
- //Check permissions, first the lanugage must be on the edit list. Then either the user
349
- //is a translator or automatic translation if it is enabled.
350
  if (!($this->transposh->options->is_editable_language($lang) && $this->transposh->is_translator())) {
351
 
352
  header('HTTP/1.0 401 Unauthorized history');
@@ -354,25 +416,23 @@ class transposh_database {
354
  }
355
 
356
 
357
- $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG;
358
-
359
-
360
- //The original content is encoded as base64 before it is sent (i.e. token), after we
361
- //decode it should just the same after it was parsed.
362
  $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
363
 
364
- //add our own custom header - so we will know that we got here
365
  header('Transposh: v-' . TRANSPOSH_PLUGIN_VER . ' db_version-' . DB_VERSION);
366
 
367
  $query = "SELECT translated, translated_by, timestamp, source, user_login " .
368
- "FROM $table_name " .
369
  "LEFT JOIN {$GLOBALS['wpdb']->prefix}users ON translated_by = {$GLOBALS['wpdb']->prefix}users.id " .
370
  "WHERE original='$original' AND lang='$lang' " .
371
  "ORDER BY timestamp DESC";
372
 
373
 
374
  $rows = $GLOBALS['wpdb']->get_results($query);
375
- // trying
 
376
  //header("Content-type: text/javascript");
377
  //echo json_encode($rows);
378
  if ($rows !== FALSE) {
@@ -400,18 +460,11 @@ class transposh_database {
400
  * @return array List of rows
401
  */
402
  function get_all_human_translation_history($date ="null", $limit = "") {
403
-
404
- $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG;
405
-
406
-
407
- //add our own custom header - so we will know that we got here
408
- // header("Transposh: v-".TRANSPOSH_PLUGIN_VER." db_version-". DB_VERSION);
409
-
410
  if ($date != "null")
411
  $dateterm = "and UNIX_TIMESTAMP(timestamp) > $date";
412
  if ($limit) $limitterm = "LIMIT $limit";
413
  $query = "SELECT original, lang, translated, translated_by, UNIX_TIMESTAMP(timestamp) as timestamp " .
414
- "FROM $table_name " .
415
  "WHERE source= 0 $dateterm " .
416
  "ORDER BY timestamp ASC $limitterm";
417
 
@@ -431,32 +484,24 @@ class transposh_database {
431
  $installed_ver = get_option(TRANSPOSH_DB_VERSION);
432
 
433
  if ($installed_ver != DB_VERSION) {
434
- $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
435
-
436
 
437
  // notice - keep every field on a new line or dbdelta fails
438
  $GLOBALS['wpdb']->query("ALTER TABLE $table_name DROP PRIMARY KEY");
439
- $sql = "CREATE TABLE $table_name (
440
  original TEXT NOT NULL,
441
  lang CHAR(5) NOT NULL,
442
  translated TEXT,
443
  source TINYINT NOT NULL,
444
  KEY original (original(6),lang)
445
  ) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
446
- /* $sql = "CREATE TABLE $table_name (original VARCHAR(255) NOT NULL,".
447
- "lang CHAR(5) NOT NULL,".
448
- "translated VARCHAR(255),".
449
- "source TINYINT NOT NULL,".
450
- "PRIMARY KEY (original, lang)) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci"; */
451
 
452
  dbDelta($sql);
453
 
454
- $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG;
455
-
456
 
457
  // notice - keep every field on a new line or dbdelta fails
 
458
  $GLOBALS['wpdb']->query("ALTER TABLE $table_name DROP PRIMARY KEY");
459
- $sql = "CREATE TABLE $table_name (
460
  original text NOT NULL,
461
  lang CHAR(5) NOT NULL,
462
  translated text,
@@ -465,13 +510,6 @@ class transposh_database {
465
  timestamp TIMESTAMP,
466
  KEY original (original(6),lang,timestamp)
467
  ) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
468
- /* $sql = "CREATE TABLE $table_name (original VARCHAR(255) NOT NULL,".
469
- "lang CHAR(5) NOT NULL,".
470
- "translated VARCHAR(255),".
471
- "translated_by VARCHAR(15),".
472
- "source TINYINT NOT NULL,".
473
- "timestamp TIMESTAMP,".
474
- "PRIMARY KEY (original, lang, timestamp)) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci"; */
475
 
476
  dbDelta($sql);
477
  update_option(TRANSPOSH_DB_VERSION, DB_VERSION);
@@ -485,16 +523,14 @@ class transposh_database {
485
  */
486
  function db_stats() {
487
  echo "<h4>Database stats</h4>";
488
- $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
489
- $log_table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG;
490
- $query = "SELECT count(*) as count FROM `$table_name`";
491
  $rows = $GLOBALS['wpdb']->get_results($query);
492
  foreach ($rows as $row) {
493
  if ($row->count)
494
  echo "<p>Total of <strong style=\"color:red\">{$row->count}</strong> translated phrases.</p>";
495
  }
496
 
497
- $query = "SELECT count(*) as count,lang FROM `$table_name` WHERE source='0' GROUP BY `lang` ORDER BY `count` DESC LIMIT 3";
498
  $rows = $GLOBALS['wpdb']->get_results($query);
499
  foreach ($rows as $row) {
500
  if ($row->count)
@@ -502,11 +538,10 @@ class transposh_database {
502
  }
503
 
504
  echo "<h4>Recent activity</h4>";
505
- $query = "SELECT * FROM `$log_table_name` WHERE source='0' ORDER BY `timestamp` DESC LIMIT 3";
506
  $rows = $GLOBALS['wpdb']->get_results($query);
507
  foreach ($rows as $row) {
508
  $td = mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $row->timestamp);
509
- //the_date();
510
  echo "<p>On <strong>{$td}</strong><br/>user <strong>{$row->translated_by}</strong> translated<br/>" .
511
  "\"<strong>{$row->original}</strong>\"<br/>to " .
512
  "<strong style=\"color:red\">{$row->lang}</strong><br/>\"<strong>{$row->translated}</strong>\"</p>";
@@ -520,13 +555,12 @@ class transposh_database {
520
  * @return array Original phrases in which $term appears
521
  */
522
  function get_orignal_phrases_for_search_term($term, $language) {
523
- $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
524
  $n = '%';
525
  $term = addslashes_gpc($term);
526
- $query = "SELECT original
527
- FROM `$table_name`
528
- WHERE `lang` LIKE '$language'
529
- AND `translated` LIKE '{$n}{$term}{$n}'";
530
  //TODO wait for feedbacks to see if we should put a limit here.
531
 
532
 
@@ -560,18 +594,17 @@ class transposh_database {
560
  */
561
  function cleanup($days = 0) {
562
  $days = intval($days); // some security
563
- $cleanup = 'DELETE ' . $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE . ' ,' . $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG .
564
- ' FROM ' . $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE .
565
- ' INNER JOIN ' . $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG .
566
- ' ON ' . $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE . '.original = ' . $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG . '.original' .
567
- ' AND ' . $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE . '.lang = ' . $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG . '.lang' .
568
- ' WHERE ' . $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE . '.source > 0' .
569
  " AND timestamp < SUBDATE(NOW(),$days)";
570
- // clean up cache so that results will actually show
571
- if (ENABLE_APC && function_exists('apc_clear_cache'))
572
- apc_clear_cache('user');
573
-
574
  $result = $GLOBALS['wpdb']->query($cleanup);
 
 
 
575
  exit;
576
  }
577
 
@@ -580,6 +613,9 @@ class transposh_database {
580
  // if there is a newer human translation, just ignore this
581
  // if there is a newer auto translation, remove it
582
  // update it
 
 
 
583
  $source = 0;
584
  // for now - just update it...
585
  $values .= "('" . $original . "','" . $translation . "','" . $lang . "','" . $source . "')";
@@ -587,16 +623,16 @@ class transposh_database {
587
  // Setting the transaction log records
588
  $logvalues .= "('" . $original . "','" . $translation . "','" . $lang . "','" . $by . "',FROM_UNIXTIME(" . $timestamp . "),'" . $source . "')";
589
 
590
- $update = "DELETE FROM " . $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE . " WHERE $delvalues";
591
 
592
  $result = $GLOBALS['wpdb']->query($update);
593
- $update = "INSERT INTO " . $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE . " (original, translated, lang, source) VALUES $values";
594
 
595
  $result = $GLOBALS['wpdb']->query($update);
596
 
597
  if ($result !== FALSE) {
598
  // update the transaction log too
599
- $log = "INSERT INTO " . $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG . " (original, translated, lang, translated_by, timestamp, source) " .
600
  "VALUES $logvalues";
601
 
602
  $result = $GLOBALS['wpdb']->query($log);
@@ -608,4 +644,5 @@ class transposh_database {
608
  }
609
 
610
  }
 
611
  ?>
1
  <?php
2
 
3
  /*
4
+ * Transposh v0.6.3
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
+ * Date: Thu, 02 Sep 2010 00:39:59 +0300
12
  */
13
 
14
  /**
33
 
34
  /** @var transposh_plugin father class */
35
  private $transposh;
36
+ /** @var array holds prefetched translations */
37
  private $translations;
38
+ /** @var string translation table name */
39
+ private $translation_table;
40
+ /** @var string translation log table name */
41
+ private $translation_log_table;
42
 
43
  /**
44
  * constructor of class, PHP4 compatible construction for backward compatibility
45
  */
46
  function transposh_database(&$transposh) {
47
  $this->transposh = &$transposh;
48
+ $this->translation_table = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
49
+ $this->translation_log_table = $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG;
50
+ }
51
+
52
+ /**
53
+ * Function to return a value from memory cache
54
+ * @param string $original string we want translated
55
+ * @param string $lang language we want it translated to
56
+ * @return mixed array with translation or false on cache miss
57
+ */
58
+ function cache_fetch($original, $lang) {
59
+ if (!TP_ENABLE_CACHE) return false;
60
+ $cached = false;
61
+ $key = $lang . '_' . $original;
62
+ if (function_exists('apc_fetch')) {
63
+ $cached = apc_fetch($key, $rc);
64
+ if ($rc === false) return false;
65
+
66
+ } elseif (function_exists('xcache_get')) {
67
+ $rc = xcache_isset($key);
68
+ if ($rc === false) return false;
69
+ $cached = xcache_get($key);
70
+
71
+ } elseif (function_exists('eaccelerator_get')) {
72
+ $cached = eaccelerator_get($key);
73
+ if ($cached === null) return false;
74
+ //TODO - unfortunantly null storing does not work here..
75
+
76
+ }
77
+
78
+ if ($cached !== null && $cached !== false)
79
+ $cached = explode('_', $cached, 2);
80
+ return $cached;
81
+ }
82
+
83
+ /**
84
+ * Function to store translation in memory cache
85
+ * @param string $original
86
+ * @param string $lang
87
+ * @param array $translated
88
+ * @param int $ttl time to live in the cache
89
+ * @return boolean true if stored successfully
90
+ */
91
+ function cache_store($original, $lang, $translated, $ttl) {
92
+ if (!TP_ENABLE_CACHE) return false;
93
+ $key = $lang . '_' . $original;
94
+ if ($translated !== null) $translated = implode('_', $translated);
95
+ if (function_exists('apc_store')) {
96
+ $rc = apc_store($key, $translated, $ttl);
97
+ } elseif (function_exists('xcache_set')) {
98
+ $rc = xcache_set($key, $translated, $ttl);
99
+ } elseif (function_exists('eaccelerator_put')) {
100
+ $rc = eaccelerator_put($key, $translated, $ttl);
101
+ }
102
+
103
+ if ($rc) {
104
+
105
+ } else {
106
+
107
+ }
108
+ return $rc;
109
+ }
110
+
111
+ /**
112
+ * Remove a value from memory cache
113
+ * @param string $original
114
+ * @param string $lang
115
+ */
116
+ function cache_delete($original, $lang) {
117
+ if (!TP_ENABLE_CACHE) return;
118
+ $key = $lang . '_' . $original;
119
+ if (function_exists('apc_delete')) {
120
+ apc_delete($key);
121
+ } elseif (function_exists('xcache_unset')) {
122
+ xcache_unset($key);
123
+ } elseif (function_exists('eaccelerator_rm')) {
124
+ eaccelerator_rm($key);
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Clean the memory cache
130
+ */
131
+ function cache_clean() {
132
+ if (!TP_ENABLE_CACHE) return;
133
+ if (function_exists('apc_clear_cache')) {
134
+ apc_clear_cache('user');
135
+ } elseif (function_exists('xcache_unset_by_prefix')) {
136
+ xcache_unset_by_prefix();
137
+ }
138
+ //TODO - clean on eaccelerator is not so clean...
139
  }
140
 
141
  /**
142
  * Allow fetching of multiple translation requests from the database with a single query
143
+ * @param array $originals keys hold the strings...
144
  * @param string $lang
145
  */
146
  function prefetch_translations($originals, $lang) {
147
  if (!$originals) return;
148
+
149
+ foreach ($originals as $original => $truth) {
150
  $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
151
+ $cached = $this->cache_fetch($original, $lang);
152
+ // if $cached is not false, there is something in the cache, so no need to prefetch
153
+ if ($cached !== false) {
154
+ continue;
 
 
155
  }
156
  $where .= ( ($where) ? ' OR ' : '') . "original = '$original'";
157
  }
158
+ // If we have nothing, we will do nothing
159
  if (!$where) return;
160
+ $query = "SELECT original, translated, source FROM {$this->translation_table} WHERE ($where) and lang = '$lang' ";
 
161
  $rows = $GLOBALS['wpdb']->get_results($query, ARRAY_A);
162
  if (empty($rows)) return;
163
+ // we are saving in the array and not directly to cache, because cache might not exist...
164
  foreach ($rows as $row) {
165
+ $this->translations[$row['original']] = array($row['source'], stripslashes($row['translated']));
166
  }
167
 
168
  }
173
  * Will return NULL if no translation is available.
174
  * @param string $original
175
  * @param string $lang
176
+ * @return array list(source,translation)
177
  */
178
  function fetch_translation($original, $lang) {
179
+ $translated = null;
180
 
 
181
  //The original is saved in db in its escaped form
182
  $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
183
+ // first we look in the cache
184
+ $cached = $this->cache_fetch($original, $lang);
185
+ if ($cached !== false) {
186
+
187
+ return $cached;
 
 
188
  }
189
+ // then we look for a prefetch
190
  if ($this->translations[$original]) {
191
  $translated = $this->translations[$original];
192
 
193
  } else {
194
+ $query = "SELECT * FROM {$this->translation_table} WHERE original = '$original' and lang = '$lang' ";
 
 
195
  $row = $GLOBALS['wpdb']->get_row($query);
196
 
197
+ if ($row !== null) {
198
  $translated_text = stripslashes($row->translated);
199
+ $translated = array($row->source, $translated_text);
 
200
 
201
  }
202
  }
203
+ // we can store the result in the cache (or the fact we don't have one)
204
+ $this->cache_store($original, $lang, $translated, TP_CACHE_TTL);
205
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  return $translated;
207
  }
208
 
215
  * @return array list(translation,source)
216
  */
217
  function fetch_original($translation, $lang) {
218
+ $original = null;
219
 
220
 
221
+ // The translation is saved in db in its escaped form
222
  $translation = $GLOBALS['wpdb']->escape(html_entity_decode($translation, ENT_NOQUOTES, 'UTF-8'));
223
+ // The translation might be cached (notice the additional postfix)
224
+ list($rev, $cached) = $this->cache_fetch('R_' . $translation, $lang);
225
+ if ($rev == 'r') {
226
+
227
+ return $cached;
 
 
228
  }
229
+ // FIXME - no prefetching for originals yet...
230
  if ($this->translations[$translation]) {
231
  $original = $this->translations[$translation];
232
 
233
  } else {
234
+ $query = "SELECT * FROM {$this->translation_table} WHERE translated = '$translation' and lang = '$lang' ";
 
 
235
  $row = $GLOBALS['wpdb']->get_row($query);
236
 
237
+ if ($row !== null) {
238
  $original = stripslashes($row->original);
239
 
240
  }
241
  }
242
 
243
+ // we can store the result in the cache (or the fact we don't have one)
244
+ $this->cache_store('R_' . $translation, $lang, array('r', $original), TP_CACHE_TTL);
 
 
 
 
 
 
 
 
 
 
 
245
 
246
 
247
  return $original;
279
  }
280
  }
281
  }
 
282
  if (!($all_editable &&
283
  ($this->transposh->is_translator() || ($source == 1 && $this->transposh->options->get_enable_auto_translate())))) {
284
 
289
  //add our own custom header - so we will know that we got here
290
  header("Transposh: v-" . TRANSPOSH_PLUGIN_VER . " db_version-" . DB_VERSION);
291
 
292
+ // translation log stuff
293
  global $user_ID;
294
  get_currentuserinfo();
295
 
299
  } else {
300
  $loguser = $user_ID;
301
  }
302
+
303
+ // We are now processing all posted items
304
  for ($i = 0; $i < $items; $i++) {
305
  if (isset($_POST["tk$i"])) {
306
  $original = transposh_utils::base64_url_decode($_POST["tk$i"]);
307
+ // The original content is encoded as base64 before it is sent (i.e. token), after we
308
+ // decode it should just the same after it was parsed.
309
  $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
310
  }
311
  if (isset($_POST["tr$i"])) {
312
  $translation = $_POST["tr$i"];
313
+ // Decode & remove already escaped character to avoid double escaping
314
  $translation = $GLOBALS['wpdb']->escape(htmlspecialchars(stripslashes(urldecode($translation))));
315
  }
316
  if (isset($_POST["ln$i"])) {
319
  if (isset($_POST["sr$i"])) {
320
  $source = $_POST["sr$i"];
321
  }
322
+
323
+ // should we backup? - yes on any human translation
324
  if ($source == 0) $backup_immidiate_possible = true;
325
 
326
  //Here we check we are not redoing stuff
344
  $logvalues .= "('" . $original . "','" . $translation . "','" . $lang . "','" . $loguser . "','" . $source . "')" . (($items != $i + 1) ? ', ' : '');
345
 
346
  // If we have caching - we remove previous entry from cache
347
+ $this->cache_delete($original, $lang);
348
+ // TODO - maybe store value here?
 
349
  }
350
 
351
+ // avoid empty database work
352
  if (!$values) return;
353
  // perform insertion to the database, with one query :)
354
+ // since we no longer have a primary key, replacement made no sense
355
  /* $update = "REPLACE INTO ".$GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE." (original, translated, lang, source)
356
  VALUES $values"; */
357
  //so we'll delete all values and insert them...
358
+ $update = "DELETE FROM " . $this->translation_table . " WHERE $delvalues";
359
 
360
  $result = $GLOBALS['wpdb']->query($update);
361
+ $update = "INSERT INTO " . $this->translation_table . " (original, translated, lang, source) VALUES $values";
362
 
363
  $result = $GLOBALS['wpdb']->query($update);
364
 
365
+ // if the insertion worked, we will update the transaction log
366
  if ($result !== FALSE) {
367
+ $log = "INSERT INTO " . $this->translation_log_table . " (original, translated, lang, translated_by, source) " .
 
368
  "VALUES $logvalues";
369
  $result = $GLOBALS['wpdb']->query($log);
 
370
 
371
  } else {
372
 
374
  header("HTTP/1.0 404 Failed to update language database " . mysql_error());
375
  }
376
 
377
+ // if its a human translation we will call the action, this takes the assumption of a single human translation in
378
+ // a function call, which should probably be verified (FIXME move up?)
379
+ if ($source == 0) {
380
  do_action('transposh_human_translation', $translation, $original, $lang);
381
  }
382
 
407
  }
408
 
409
 
410
+ // Check permissions, first the lanugage must be on the edit list. Then either the user
411
+ // is a translator or automatic translation if it is enabled.
412
  if (!($this->transposh->options->is_editable_language($lang) && $this->transposh->is_translator())) {
413
 
414
  header('HTTP/1.0 401 Unauthorized history');
416
  }
417
 
418
 
419
+ // The original content is encoded as base64 before it is sent (i.e. token), after we
420
+ // decode it should just the same after it was parsed.
 
 
 
421
  $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
422
 
423
+ // add our own custom header - so we will know that we got here
424
  header('Transposh: v-' . TRANSPOSH_PLUGIN_VER . ' db_version-' . DB_VERSION);
425
 
426
  $query = "SELECT translated, translated_by, timestamp, source, user_login " .
427
+ "FROM {$this->translation_log_table} " .
428
  "LEFT JOIN {$GLOBALS['wpdb']->prefix}users ON translated_by = {$GLOBALS['wpdb']->prefix}users.id " .
429
  "WHERE original='$original' AND lang='$lang' " .
430
  "ORDER BY timestamp DESC";
431
 
432
 
433
  $rows = $GLOBALS['wpdb']->get_results($query);
434
+
435
+ // TODO: work with json
436
  //header("Content-type: text/javascript");
437
  //echo json_encode($rows);
438
  if ($rows !== FALSE) {
460
  * @return array List of rows
461
  */
462
  function get_all_human_translation_history($date ="null", $limit = "") {
 
 
 
 
 
 
 
463
  if ($date != "null")
464
  $dateterm = "and UNIX_TIMESTAMP(timestamp) > $date";
465
  if ($limit) $limitterm = "LIMIT $limit";
466
  $query = "SELECT original, lang, translated, translated_by, UNIX_TIMESTAMP(timestamp) as timestamp " .
467
+ "FROM {$this->translation_log_table} " .
468
  "WHERE source= 0 $dateterm " .
469
  "ORDER BY timestamp ASC $limitterm";
470
 
484
  $installed_ver = get_option(TRANSPOSH_DB_VERSION);
485
 
486
  if ($installed_ver != DB_VERSION) {
 
 
487
 
488
  // notice - keep every field on a new line or dbdelta fails
489
  $GLOBALS['wpdb']->query("ALTER TABLE $table_name DROP PRIMARY KEY");
490
+ $sql = "CREATE TABLE {$this->translation_table} (
491
  original TEXT NOT NULL,
492
  lang CHAR(5) NOT NULL,
493
  translated TEXT,
494
  source TINYINT NOT NULL,
495
  KEY original (original(6),lang)
496
  ) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
 
 
 
 
 
497
 
498
  dbDelta($sql);
499
 
 
 
500
 
501
  // notice - keep every field on a new line or dbdelta fails
502
+ // this should be removed in a far future...
503
  $GLOBALS['wpdb']->query("ALTER TABLE $table_name DROP PRIMARY KEY");
504
+ $sql = "CREATE TABLE {$this->translation_log_table} (
505
  original text NOT NULL,
506
  lang CHAR(5) NOT NULL,
507
  translated text,
510
  timestamp TIMESTAMP,
511
  KEY original (original(6),lang,timestamp)
512
  ) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
 
 
 
 
 
 
 
513
 
514
  dbDelta($sql);
515
  update_option(TRANSPOSH_DB_VERSION, DB_VERSION);
523
  */
524
  function db_stats() {
525
  echo "<h4>Database stats</h4>";
526
+ $query = "SELECT count(*) as count FROM `{$this->translation_table}`";
 
 
527
  $rows = $GLOBALS['wpdb']->get_results($query);
528
  foreach ($rows as $row) {
529
  if ($row->count)
530
  echo "<p>Total of <strong style=\"color:red\">{$row->count}</strong> translated phrases.</p>";
531
  }
532
 
533
+ $query = "SELECT count(*) as count,lang FROM `{$this->translation_table}` WHERE source='0' GROUP BY `lang` ORDER BY `count` DESC LIMIT 3";
534
  $rows = $GLOBALS['wpdb']->get_results($query);
535
  foreach ($rows as $row) {
536
  if ($row->count)
538
  }
539
 
540
  echo "<h4>Recent activity</h4>";
541
+ $query = "SELECT * FROM `{$this->translation_log_table}` WHERE source='0' ORDER BY `timestamp` DESC LIMIT 3";
542
  $rows = $GLOBALS['wpdb']->get_results($query);
543
  foreach ($rows as $row) {
544
  $td = mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $row->timestamp);
 
545
  echo "<p>On <strong>{$td}</strong><br/>user <strong>{$row->translated_by}</strong> translated<br/>" .
546
  "\"<strong>{$row->original}</strong>\"<br/>to " .
547
  "<strong style=\"color:red\">{$row->lang}</strong><br/>\"<strong>{$row->translated}</strong>\"</p>";
555
  * @return array Original phrases in which $term appears
556
  */
557
  function get_orignal_phrases_for_search_term($term, $language) {
 
558
  $n = '%';
559
  $term = addslashes_gpc($term);
560
+ $query = "SELECT original" .
561
+ " FROM `{$this->translation_table}`" .
562
+ " WHERE `lang` LIKE '$language'" .
563
+ " AND `translated` LIKE '{$n}{$term}{$n}'";
564
  //TODO wait for feedbacks to see if we should put a limit here.
565
 
566
 
594
  */
595
  function cleanup($days = 0) {
596
  $days = intval($days); // some security
597
+ $cleanup = 'DELETE ' . $this->translation_table . ' ,' . $this->translation_log_table .
598
+ ' FROM ' . $this->translation_table .
599
+ ' INNER JOIN ' . $this->translation_log_table .
600
+ ' ON ' . $this->translation_table . '.original = ' . $this->translation_log_table . '.original' .
601
+ ' AND ' . $this->translation_table . '.lang = ' . $this->translation_log_table . '.lang' .
602
+ ' WHERE ' . $this->translation_table . '.source > 0' .
603
  " AND timestamp < SUBDATE(NOW(),$days)";
 
 
 
 
604
  $result = $GLOBALS['wpdb']->query($cleanup);
605
+
606
+ // clean up cache so that results will actually show
607
+ $this->cache_clean();
608
  exit;
609
  }
610
 
613
  // if there is a newer human translation, just ignore this
614
  // if there is a newer auto translation, remove it
615
  // update it
616
+ // TODO - change this part to use the update_translation function
617
+ $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
618
+ $translation = $GLOBALS['wpdb']->escape(html_entity_decode($translation, ENT_NOQUOTES, 'UTF-8'));
619
  $source = 0;
620
  // for now - just update it...
621
  $values .= "('" . $original . "','" . $translation . "','" . $lang . "','" . $source . "')";
623
  // Setting the transaction log records
624
  $logvalues .= "('" . $original . "','" . $translation . "','" . $lang . "','" . $by . "',FROM_UNIXTIME(" . $timestamp . "),'" . $source . "')";
625
 
626
+ $update = "DELETE FROM " . $this->translation_table . " WHERE $delvalues";
627
 
628
  $result = $GLOBALS['wpdb']->query($update);
629
+ $update = "INSERT INTO " . $this->translation_table . " (original, translated, lang, source) VALUES $values";
630
 
631
  $result = $GLOBALS['wpdb']->query($update);
632
 
633
  if ($result !== FALSE) {
634
  // update the transaction log too
635
+ $log = "INSERT INTO " . $this->translation_log_table . " (original, translated, lang, translated_by, timestamp, source) " .
636
  "VALUES $logvalues";
637
 
638
  $result = $GLOBALS['wpdb']->query($log);
644
  }
645
 
646
  }
647
+
648
  ?>
wp/transposh_options.php CHANGED
@@ -1,71 +1,71 @@
1
  <?php
2
 
3
  /*
4
- * Transposh v0.6.2
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
12
  */
13
 
14
  // OLD Options - To be removed
15
  // removed real old options support, no migration from 0.3.9 anymore
16
  // @since 0.5.6
17
  //Option defining transposh widget appearance
18
- define("OLD_WIDGET_STYLE", "widget_style");
19
  //Use CSS sprites for flags if available
20
- define("OLD_WIDGET_CSS_FLAGS", "widget_css_flags");
21
  //Wrap widget elements in an unordered list per #63 @since 0.3.7
22
- define("OLD_WIDGET_IN_LIST", "widget_in_list");
23
  //Option to enable/disable msn translation
24
- define("OLD_ENABLE_MSN_TRANSLATE", "enable_msntranslate");
25
  //Option to store the msn API key
26
- define("OLD_MSN_TRANSLATE_KEY", "msn_key");
27
 
28
  //defines are used to avoid typos
29
  //Option defining whether anonymous translation is allowed.
30
- define("ANONYMOUS_TRANSLATION", "allow_anonymous_translation");
31
  //Option defining the list of currentlly viewable languages
32
- define("VIEWABLE_LANGS", "viewable_languages");
33
  //Option defining the list of currentlly editable languages
34
- define("EDITABLE_LANGS", "editable_languages");
35
  //Option defining the ordered list of languages @since 0.3.9
36
- define("SORTED_LANGS", "sorted_languages");
37
  //Option to enable/disable auto translation
38
- define("ENABLE_AUTO_TRANSLATE", "enable_autotranslate");
39
  //Option to enable/disable auto translation
40
- define("ENABLE_AUTO_POST_TRANSLATE", "enable_autoposttranslate");
41
  //Option to store translator preference @since 0.4.2
42
- define("PREFERRED_TRANSLATOR", "preferred_translator");
43
  //Option to enable/disable default language translation
44
- define("ENABLE_DEFAULT_TRANSLATE", "enable_default_translate");
45
  //Option to enable/disable default language translation @since 0.3.6
46
- define("ENABLE_SEARCH_TRANSLATE", "enable_search_translate");
47
  //Option to enable/disable url translation @since 0.5.3
48
- define("ENABLE_URL_TRANSLATE", "enable_url_translate");
49
  //Option to enable/disable rewrite of permalinks
50
- define("ENABLE_PERMALINKS", "enable_permalinks");
51
  //Option to enable/disable footer scripts (2.8 and up)
52
- define("ENABLE_FOOTER_SCRIPTS", "enable_footer_scripts");
53
  //Option to enable detect and redirect language @since 0.3.8
54
- define("ENABLE_DETECT_LANG_AND_REDIRECT", "enable_detect_redirect");
55
  //Option defining the default language
56
- define("DEFAULT_LANG", "default_language");
57
  //Option defining transposh widget file used @since 0.5.6
58
- define("WIDGET_FILE", "widget_file");
59
  //Option allowing progress bar display
60
- define("WIDGET_PROGRESSBAR", "widget_progressbar");
61
  //Allows user to set his default language per #63 @since 0.3.8
62
- define("WIDGET_ALLOW_SET_DEFLANG", "widget_allow_set_deflang");
63
  //Allows removing of transposh logo in exchange for an ad @since 0.6.0
64
- define("WIDGET_REMOVE_LOGO_FOR_AD", "widget_remove_logo");
65
  //Stores the site key to transposh services (backup @since 0.5.0)
66
- define("TRANSPOSH_KEY", "transposh_key");
67
  //Stores the site key to transposh services (backup @since 0.5.0)
68
- define("TRANSPOSH_BACKUP_SCHEDULE", "transposh_backup_schedule");
69
 
70
  class transposh_plugin_options {
71
  //constructor of class, PHP4 compatible construction for backward compatibility
@@ -75,10 +75,35 @@ class transposh_plugin_options {
75
  /** @var boolean set to true if any option was changed */
76
  private $changed = false;
77
 
 
 
 
 
78
  function transposh_plugin_options() {
79
 
80
  // load them here
81
  $this->options = get_option(TRANSPOSH_OPTIONS);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  $this->migrate_old_config();
83
 
84
  }
@@ -86,7 +111,7 @@ class transposh_plugin_options {
86
  // TODO: remove this function in a few versions (fix css, db version..., css flag
87
  private function migrate_old_config() {
88
 
89
- if ($this->options[OLD_WIDGET_STYLE]) {
90
  if ($this->options[OLD_WIDGET_STYLE] == 1 && $this->options[OLD_WIDGET_CSS_FLAGS] == 0) {
91
  $this->set_widget_file('flags/tpw_flags.php');
92
  }
@@ -110,9 +135,7 @@ class transposh_plugin_options {
110
  }
111
 
112
  function get_anonymous_translation() {
113
- if (!isset($this->options[ANONYMOUS_TRANSLATION]))
114
- return 1; // default is true
115
- return $this->options[ANONYMOUS_TRANSLATION];
116
  }
117
 
118
  function get_viewable_langs() {
@@ -172,8 +195,6 @@ class transposh_plugin_options {
172
  }
173
 
174
  function get_enable_search_translate() {
175
- // default is true
176
- if (!isset($this->options[ENABLE_SEARCH_TRANSLATE])) return 1;
177
  return $this->options[ENABLE_SEARCH_TRANSLATE];
178
  }
179
 
@@ -183,7 +204,6 @@ class transposh_plugin_options {
183
 
184
  function get_enable_auto_translate() {
185
  // default is true
186
- if (!isset($this->options[ENABLE_AUTO_TRANSLATE])) return 1;
187
  return $this->options[ENABLE_AUTO_TRANSLATE];
188
  }
189
 
@@ -193,7 +213,6 @@ class transposh_plugin_options {
193
 
194
  function get_preferred_translator() {
195
  // default is google(1) (2 is msn)
196
- if (!isset($this->options[PREFERRED_TRANSLATOR])) return 1;
197
  return $this->options[PREFERRED_TRANSLATOR];
198
  }
199
 
@@ -203,8 +222,8 @@ class transposh_plugin_options {
203
  */
204
  function get_default_language() {
205
  $default = $this->options[DEFAULT_LANG];
206
- if (!transposh_consts::$languages[$default]) {
207
- if (defined('WPLANG') && transposh_consts::$languages[WPLANG]) {
208
  $default = WPLANG;
209
  } else {
210
  $default = "en";
@@ -356,7 +375,7 @@ class transposh_plugin_options {
356
  * @return boolean Is this the default language?
357
  */
358
  function is_default_language($language) {
359
- return ($this->get_default_language() == $language);
360
  }
361
 
362
  /**
1
  <?php
2
 
3
  /*
4
+ * Transposh v0.6.3
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
12
  */
13
 
14
  // OLD Options - To be removed
15
  // removed real old options support, no migration from 0.3.9 anymore
16
  // @since 0.5.6
17
  //Option defining transposh widget appearance
18
+ define('OLD_WIDGET_STYLE', 'widget_style');
19
  //Use CSS sprites for flags if available
20
+ define('OLD_WIDGET_CSS_FLAGS', 'widget_css_flags');
21
  //Wrap widget elements in an unordered list per #63 @since 0.3.7
22
+ define('OLD_WIDGET_IN_LIST', 'widget_in_list');
23
  //Option to enable/disable msn translation
24
+ define('OLD_ENABLE_MSN_TRANSLATE', 'enable_msntranslate');
25
  //Option to store the msn API key
26
+ define('OLD_MSN_TRANSLATE_KEY', 'msn_key');
27
 
28
  //defines are used to avoid typos
29
  //Option defining whether anonymous translation is allowed.
30
+ define('ANONYMOUS_TRANSLATION', 'allow_anonymous_translation');
31
  //Option defining the list of currentlly viewable languages
32
+ define('VIEWABLE_LANGS', 'viewable_languages');
33
  //Option defining the list of currentlly editable languages
34
+ define('EDITABLE_LANGS', 'editable_languages');
35
  //Option defining the ordered list of languages @since 0.3.9
36
+ define('SORTED_LANGS', 'sorted_languages');
37
  //Option to enable/disable auto translation
38
+ define('ENABLE_AUTO_TRANSLATE', 'enable_autotranslate');
39
  //Option to enable/disable auto translation
40
+ define('ENABLE_AUTO_POST_TRANSLATE', 'enable_autoposttranslate');
41
  //Option to store translator preference @since 0.4.2
42
+ define('PREFERRED_TRANSLATOR', 'preferred_translator');
43
  //Option to enable/disable default language translation
44
+ define('ENABLE_DEFAULT_TRANSLATE', 'enable_default_translate');
45
  //Option to enable/disable default language translation @since 0.3.6
46
+ define('ENABLE_SEARCH_TRANSLATE', 'enable_search_translate');
47
  //Option to enable/disable url translation @since 0.5.3
48
+ define('ENABLE_URL_TRANSLATE', 'enable_url_translate');
49
  //Option to enable/disable rewrite of permalinks
50
+ define('ENABLE_PERMALINKS', 'enable_permalinks');
51
  //Option to enable/disable footer scripts (2.8 and up)
52
+ define('ENABLE_FOOTER_SCRIPTS', 'enable_footer_scripts');
53
  //Option to enable detect and redirect language @since 0.3.8
54
+ define('ENABLE_DETECT_LANG_AND_REDIRECT', 'enable_detect_redirect');
55
  //Option defining the default language
56
+ define('DEFAULT_LANG', 'default_language');
57
  //Option defining transposh widget file used @since 0.5.6
58
+ define('WIDGET_FILE', 'widget_file');
59
  //Option allowing progress bar display
60
+ define('WIDGET_PROGRESSBAR', 'widget_progressbar');
61
  //Allows user to set his default language per #63 @since 0.3.8
62
+ define('WIDGET_ALLOW_SET_DEFLANG', 'widget_allow_set_deflang');
63
  //Allows removing of transposh logo in exchange for an ad @since 0.6.0
64
+ define('WIDGET_REMOVE_LOGO_FOR_AD', 'widget_remove_logo');
65
  //Stores the site key to transposh services (backup @since 0.5.0)
66
+ define('TRANSPOSH_KEY', 'transposh_key');
67
  //Stores the site key to transposh services (backup @since 0.5.0)
68
+ define('TRANSPOSH_BACKUP_SCHEDULE', 'transposh_backup_schedule');
69
 
70
  class transposh_plugin_options {
71
  //constructor of class, PHP4 compatible construction for backward compatibility
75
  /** @var boolean set to true if any option was changed */
76
  private $changed = false;
77
 
78
+ function set_default_option_value($option, $value = '') {
79
+ if (!isset($this->options[$option])) $this->options[$option] = $value;
80
+ }
81
+
82
  function transposh_plugin_options() {
83
 
84
  // load them here
85
  $this->options = get_option(TRANSPOSH_OPTIONS);
86
+ $this->set_default_option_value(ANONYMOUS_TRANSLATION, 1);
87
+ $this->set_default_option_value(ENABLE_SEARCH_TRANSLATE, 1);
88
+ $this->set_default_option_value(ENABLE_AUTO_TRANSLATE, 1);
89
+ $this->set_default_option_value(PREFERRED_TRANSLATOR, 1);
90
+ $this->set_default_option_value(VIEWABLE_LANGS);
91
+ $this->set_default_option_value(EDITABLE_LANGS);
92
+ //$this->set_default_option_value(SORTED_LANGS);
93
+ $this->set_default_option_value(ENABLE_AUTO_POST_TRANSLATE);
94
+ $this->set_default_option_value(ENABLE_DEFAULT_TRANSLATE);
95
+ $this->set_default_option_value(ENABLE_SEARCH_TRANSLATE);
96
+ $this->set_default_option_value(ENABLE_URL_TRANSLATE);
97
+ $this->set_default_option_value(ENABLE_PERMALINKS);
98
+ $this->set_default_option_value(ENABLE_FOOTER_SCRIPTS);
99
+ $this->set_default_option_value(ENABLE_DETECT_LANG_AND_REDIRECT);
100
+ $this->set_default_option_value(DEFAULT_LANG);
101
+ $this->set_default_option_value(WIDGET_FILE);
102
+ $this->set_default_option_value(WIDGET_PROGRESSBAR);
103
+ $this->set_default_option_value(WIDGET_ALLOW_SET_DEFLANG);
104
+ $this->set_default_option_value(WIDGET_REMOVE_LOGO_FOR_AD);
105
+ $this->set_default_option_value(TRANSPOSH_KEY);
106
+ $this->set_default_option_value(TRANSPOSH_BACKUP_SCHEDULE);
107
  $this->migrate_old_config();
108
 
109
  }
111
  // TODO: remove this function in a few versions (fix css, db version..., css flag
112
  private function migrate_old_config() {
113
 
114
+ if (isset($this->options[OLD_WIDGET_STYLE])) {
115
  if ($this->options[OLD_WIDGET_STYLE] == 1 && $this->options[OLD_WIDGET_CSS_FLAGS] == 0) {
116
  $this->set_widget_file('flags/tpw_flags.php');
117
  }
135
  }
136
 
137
  function get_anonymous_translation() {
138
+ return $this->options[ANONYMOUS_TRANSLATION];
 
 
139
  }
140
 
141
  function get_viewable_langs() {
195
  }
196
 
197
  function get_enable_search_translate() {
 
 
198
  return $this->options[ENABLE_SEARCH_TRANSLATE];
199
  }
200
 
204
 
205
  function get_enable_auto_translate() {
206
  // default is true
 
207
  return $this->options[ENABLE_AUTO_TRANSLATE];
208
  }
209
 
213
 
214
  function get_preferred_translator() {
215
  // default is google(1) (2 is msn)
 
216
  return $this->options[PREFERRED_TRANSLATOR];
217
  }
218
 
222
  */
223
  function get_default_language() {
224
  $default = $this->options[DEFAULT_LANG];
225
+ if (!isset(transposh_consts::$languages[$default])) {
226
+ if (defined('WPLANG') && isset(transposh_consts::$languages[WPLANG])) {
227
  $default = WPLANG;
228
  } else {
229
  $default = "en";
375
  * @return boolean Is this the default language?
376
  */
377
  function is_default_language($language) {
378
+ return ($this->get_default_language() == $language || '' == $language);
379
  }
380
 
381
  /**
wp/transposh_postpublish.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
 
3
  /*
4
- * Transposh v0.6.2
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
12
  */
13
 
14
  /*
@@ -71,6 +71,19 @@ class transposh_postpublish {
71
  }
72
  }
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  /**
75
  * Loop through all the post phrases and return them in json formatted script
76
  * @param int $postID
@@ -78,34 +91,41 @@ class transposh_postpublish {
78
  function get_post_phrases($postID) {
79
  // Some security, to avoid others from seeing private posts
80
  if (!current_user_can('edit_post', $postID)) return;
81
- $post = get_post($postID);
82
- // Display filters
83
- $title = apply_filters('the_title', $post->post_title);
84
- $content = apply_filters('the_content', $post->post_content);
85
- // TODO - grab phrases from rss excerpt
86
- //$output = get_the_excerpt();
87
- // echo apply_filters('the_excerpt_rss', $output);
88
- //TODO - get comments text
89
-
90
- $parser = new parser();
91
- $phrases = $parser->get_phrases_list($content);
92
- $phrases2 = $parser->get_phrases_list($title);
93
-
94
- // Merge the two arrays for traversing
95
- $phrases = array_merge($phrases, $phrases2);
96
-
97
- // Add phrases from permalink
98
- if ($this->transposh->options->get_enable_url_translate()) {
99
- $permalink = get_permalink($postID);
100
- $permalink = substr($permalink, strlen($this->transposh->home_url) + 1);
101
- $parts = explode('/', $permalink);
102
- foreach ($parts as $part) {
103
- if (!$part || is_numeric($part)) continue;
104
- $part = str_replace('-', ' ', $part);
105
- $phrases[] = urldecode($part);
 
 
 
 
 
 
 
 
106
  }
107
  }
108
-
109
  foreach ($phrases as $key) {
110
  foreach (explode(',', $this->transposh->options->get_editable_langs()) as $lang) {
111
  // if this isn't the default language or we specifically allow default language translation, we will seek this out...
1
  <?php
2
 
3
  /*
4
+ * Transposh v0.6.3
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
12
  */
13
 
14
  /*
71
  }
72
  }
73
 
74
+ /**
75
+ * Function to allow mass translate of tags
76
+ * @return array list of tags
77
+ */
78
+ function get_tags() {
79
+ $tags = get_terms('post_tag'); // Always query top tags
80
+ $phrases = array();
81
+ foreach ($tags as $tag) {
82
+ $phrases[] = $tag->name;
83
+ }
84
+ return $phrases;
85
+ }
86
+
87
  /**
88
  * Loop through all the post phrases and return them in json formatted script
89
  * @param int $postID
91
  function get_post_phrases($postID) {
92
  // Some security, to avoid others from seeing private posts
93
  if (!current_user_can('edit_post', $postID)) return;
94
+ // fake post for tags
95
+ if ($postID == -555) {
96
+ $phrases = $this->get_tags();
97
+ $title = "tags";
98
+ }
99
+ // a normal post
100
+ else {
101
+ $post = get_post($postID);
102
+ // Display filters
103
+ $title = apply_filters('the_title', $post->post_title);
104
+ $content = apply_filters('the_content', $post->post_content);
105
+ // TODO - grab phrases from rss excerpt
106
+ //$output = get_the_excerpt();
107
+ // echo apply_filters('the_excerpt_rss', $output);
108
+ //TODO - get comments text
109
+
110
+ $parser = new parser();
111
+ $phrases = $parser->get_phrases_list($content);
112
+ $phrases2 = $parser->get_phrases_list($title);
113
+
114
+ // Merge the two arrays for traversing
115
+ $phrases = array_merge($phrases, $phrases2);
116
+
117
+ // Add phrases from permalink
118
+ if ($this->transposh->options->get_enable_url_translate()) {
119
+ $permalink = get_permalink($postID);
120
+ $permalink = substr($permalink, strlen($this->transposh->home_url) + 1);
121
+ $parts = explode('/', $permalink);
122
+ foreach ($parts as $part) {
123
+ if (!$part || is_numeric($part)) continue;
124
+ $part = str_replace('-', ' ', $part);
125
+ $phrases[] = urldecode($part);
126
+ }
127
  }
128
  }
 
129
  foreach ($phrases as $key) {
130
  foreach (explode(',', $this->transposh->options->get_editable_langs()) as $lang) {
131
  // if this isn't the default language or we specifically allow default language translation, we will seek this out...
wp/transposh_widget.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
 
3
  /*
4
- * Transposh v0.6.2
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
- * Date: Mon, 09 Aug 2010 14:58:29 +0300
12
  */
13
 
14
  /*
@@ -85,10 +85,10 @@ class transposh_plugin_widget {
85
  }
86
 
87
  // Register widget
88
- register_sidebar_widget(array('Transposh', 'widgets'), array(&$this, 'transposh_widget'));
89
 
90
  // Register widget control
91
- register_widget_control("Transposh", array(&$this, 'transposh_widget_control'));
92
 
93
  // Register callback for widget's css and js
94
  add_action('wp_print_styles', array(&$this, 'add_transposh_widget_css'));
@@ -107,7 +107,7 @@ class transposh_plugin_widget {
107
  if ($file && file_exists($widget_src)) {
108
  include_once $widget_src;
109
  } else {
110
- $file = 'tpw_default.php';
111
  include_once $this->transposh->transposh_plugin_dir . TRANSPOSH_DIR_WIDGETS . '/' . $file;
112
  }
113
  $this->base_widget_file_name = substr($file, 0, -4);
@@ -119,7 +119,7 @@ class transposh_plugin_widget {
119
  function add_transposh_widget_css() { //TODO ! goway
120
  $this->load_widget();
121
 
122
- if (function_exists(tp_widget_css)) {
123
  tp_widget_css();
124
  } else {
125
  $widget_css = TRANSPOSH_DIR_WIDGETS . '/' . $this->base_widget_file_name . ".css";
@@ -137,7 +137,7 @@ class transposh_plugin_widget {
137
  function add_transposh_widget_js() { //TODO ! goway
138
  $this->load_widget();
139
 
140
- if (function_exists(tp_widget_js)) {
141
  tp_widget_js();
142
  } else {
143
  $widget_js = TRANSPOSH_DIR_WIDGETS . '/' . $this->base_widget_file_name . ".js";
@@ -157,7 +157,7 @@ class transposh_plugin_widget {
157
 
158
  // hmmm, this should actually prepare all vars needed, include the correct widget and send the vars to that function,
159
  $calc_url = false; // By default, avoid calculating the urls
160
- if (function_exists(tp_widget_needs_post_url))
161
  $calc_url = tp_widget_needs_post_url();
162
 
163
  $widget_args = array();
1
  <?php
2
 
3
  /*
4
+ * Transposh v0.6.3
5
  * http://transposh.org/
6
  *
7
  * Copyright 2010, Team Transposh
8
  * Licensed under the GPL Version 2 or higher.
9
  * http://transposh.org/license
10
  *
11
+ * Date: Wed, 01 Sep 2010 13:15:09 +0300
12
  */
13
 
14
  /*
85
  }
86
 
87
  // Register widget
88
+ wp_register_sidebar_widget('Transposh','Transposh', array(&$this, 'transposh_widget'), array( 'description' => __('Transposh language selection widget') ));
89
 
90
  // Register widget control
91
+ wp_register_widget_control('Transposh','Transposh', array(&$this, 'transposh_widget_control'));
92
 
93
  // Register callback for widget's css and js
94
  add_action('wp_print_styles', array(&$this, 'add_transposh_widget_css'));
107
  if ($file && file_exists($widget_src)) {
108
  include_once $widget_src;
109
  } else {
110
+ $file = 'default/tpw_default.php';
111
  include_once $this->transposh->transposh_plugin_dir . TRANSPOSH_DIR_WIDGETS . '/' . $file;
112
  }
113
  $this->base_widget_file_name = substr($file, 0, -4);
119
  function add_transposh_widget_css() { //TODO ! goway
120
  $this->load_widget();
121
 
122
+ if (function_exists('tp_widget_css')) {
123
  tp_widget_css();
124
  } else {
125
  $widget_css = TRANSPOSH_DIR_WIDGETS . '/' . $this->base_widget_file_name . ".css";
137
  function add_transposh_widget_js() { //TODO ! goway
138
  $this->load_widget();
139
 
140
+ if (function_exists('tp_widget_js')) {
141
  tp_widget_js();
142
  } else {
143
  $widget_js = TRANSPOSH_DIR_WIDGETS . '/' . $this->base_widget_file_name . ".js";
157
 
158
  // hmmm, this should actually prepare all vars needed, include the correct widget and send the vars to that function,
159
  $calc_url = false; // By default, avoid calculating the urls
160
+ if (function_exists('tp_widget_needs_post_url'))
161
  $calc_url = tp_widget_needs_post_url();
162
 
163
  $widget_args = array();